optimize whole environment
This commit is contained in:
@@ -11,5 +11,4 @@ invariant(
|
||||
`Unsupported language: ${LANGUAGE}. Supported languages are: ${KintoneUserLanguages.join(', ')}`,
|
||||
);
|
||||
|
||||
export const DOCX_CONTENTTYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
||||
export const DOCX_EXTENSION = 'docx';
|
||||
export const DOCX_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
||||
|
@@ -65,7 +65,7 @@ const Settings: React.FC = () => {
|
||||
<KintonePluginTitle>
|
||||
Template<KintonePluginRequire>*</KintonePluginRequire>
|
||||
</KintonePluginTitle>
|
||||
<KintonePluginDesc>Select a file field that contains the WORD template file.</KintonePluginDesc>
|
||||
<KintonePluginDesc>Select a file field that contains the Word template file.</KintonePluginDesc>
|
||||
{fileFields.length === 0 ? (
|
||||
<KintonePluginAlert>
|
||||
No file fields found in the app. Please add a file field to use this plugin.
|
||||
|
45
src/declaration.d.ts
vendored
45
src/declaration.d.ts
vendored
@@ -1,45 +0,0 @@
|
||||
// CSS modules
|
||||
type CSSModuleClasses = { readonly [key: string]: string };
|
||||
|
||||
declare module '*.module.css' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.scss' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.sass' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.less' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.styl' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.stylus' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.pcss' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.sss' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
|
||||
// CSS
|
||||
declare module '*.css' {}
|
||||
declare module '*.scss' {}
|
||||
declare module '*.sass' {}
|
||||
declare module '*.less' {}
|
||||
declare module '*.styl' {}
|
||||
declare module '*.stylus' {}
|
||||
declare module '*.pcss' {}
|
||||
declare module '*.sss' {}
|
@@ -5,8 +5,6 @@ import ErrorFallback from '../common/ErrorFallback';
|
||||
import Loading from '../common/Loading';
|
||||
import MenuPanel from './MenuPanel';
|
||||
|
||||
import '@shin-chan/kypes';
|
||||
|
||||
interface DesktopAppProps {
|
||||
event: kintone.events.AppRecordDetailShowEvent | kintone.events.MobileAppRecordDetailShowEvent;
|
||||
}
|
||||
|
@@ -10,12 +10,10 @@ import { saveAs } from 'file-saver';
|
||||
import moize from 'moize';
|
||||
import PizZip from 'pizzip';
|
||||
import invariant from 'tiny-invariant';
|
||||
import { DOCX_CONTENTTYPE, LANGUAGE, PLUGIN_ID } from '../common/global';
|
||||
import { DOCX_CONTENT_TYPE, LANGUAGE, PLUGIN_ID } from '../common/global';
|
||||
import KintonePluginAlert from '../common/ui/KintonePluginAlert';
|
||||
import KintonePluginButton from '../common/ui/KintonePluginButton';
|
||||
|
||||
import '@shin-chan/kypes';
|
||||
|
||||
interface TemplateData {
|
||||
[key: string]: TemplateData | TemplateData[] | string | string[];
|
||||
}
|
||||
@@ -191,32 +189,32 @@ const MenuPanel: React.FC<MenuPanelProps> = (props) => {
|
||||
if (template === '') {
|
||||
return (
|
||||
<KintonePluginAlert>
|
||||
WORD output plugin: Template field is not set. Please configure the plugin.
|
||||
Word output plugin: Template field is not set. Please configure the plugin.
|
||||
</KintonePluginAlert>
|
||||
);
|
||||
}
|
||||
const record = event.record[template];
|
||||
if (record == null) {
|
||||
return <KintonePluginAlert>WORD output plugin: Template field is not available in this app.</KintonePluginAlert>;
|
||||
return <KintonePluginAlert>Word output plugin: Template field is not available in this app.</KintonePluginAlert>;
|
||||
}
|
||||
if (record.type !== 'FILE') {
|
||||
return <KintonePluginAlert>WORD output plugin: Template field must be a file field.</KintonePluginAlert>;
|
||||
return <KintonePluginAlert>Word output plugin: Template field must be a file field.</KintonePluginAlert>;
|
||||
}
|
||||
if (record.value.length === 0) {
|
||||
return <KintonePluginAlert>WORD output plugin: Template field does not contain any files.</KintonePluginAlert>;
|
||||
return <KintonePluginAlert>Word output plugin: Template field does not contain any files.</KintonePluginAlert>;
|
||||
}
|
||||
if (record.value.length > 1) {
|
||||
return (
|
||||
<KintonePluginAlert>
|
||||
WORD output plugin: Template field contains multiple files. Please ensure it contains only one file.
|
||||
Word output plugin: Template field contains multiple files. Please ensure it contains only one file.
|
||||
</KintonePluginAlert>
|
||||
);
|
||||
}
|
||||
const { fileKey, contentType } = record.value[0];
|
||||
if (contentType !== DOCX_CONTENTTYPE) {
|
||||
if (contentType !== DOCX_CONTENT_TYPE) {
|
||||
return (
|
||||
<KintonePluginAlert>
|
||||
WORD output plugin: The template file must be a DOCX file. The current file type is {contentType}.
|
||||
Word output plugin: The template file must be a DOCX file. The current file type is {contentType}.
|
||||
</KintonePluginAlert>
|
||||
);
|
||||
}
|
||||
@@ -233,18 +231,18 @@ const MenuPanel: React.FC<MenuPanelProps> = (props) => {
|
||||
parser: expressionParser,
|
||||
});
|
||||
doc.render(record2data(properties, event.record));
|
||||
const out = doc.getZip().generate({ type: 'blob', mimeType: DOCX_CONTENTTYPE });
|
||||
const out = doc.getZip().generate({ type: 'blob', mimeType: DOCX_CONTENT_TYPE });
|
||||
saveAs(out, 'output.docx');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error downloading file:', error);
|
||||
alert('Failed to download the WORD template file.');
|
||||
alert('Failed to download the Word template file.');
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<KintonePluginButton variant="normal" onClick={handleOnClickOutputButton}>
|
||||
WORD出力
|
||||
Word出力
|
||||
</KintonePluginButton>
|
||||
);
|
||||
};
|
||||
|
@@ -4,8 +4,6 @@ import ReactDOM from 'react-dom/client';
|
||||
import invariant from 'tiny-invariant';
|
||||
import DesktopApp from './DesktopApp';
|
||||
|
||||
import '@shin-chan/kypes';
|
||||
|
||||
import '../common/ui/51-modern-default.css';
|
||||
|
||||
kintone.events.on(
|
||||
|
17
src/kintone-env.d.ts
vendored
Normal file
17
src/kintone-env.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference types="@shin-chan/kypes" />
|
||||
|
||||
// CSS modules
|
||||
type CSSModuleClasses = { readonly [key: string]: string };
|
||||
|
||||
declare module '*.module.css' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
declare module '*.module.scss' {
|
||||
const classes: CSSModuleClasses;
|
||||
export default classes;
|
||||
}
|
||||
|
||||
// CSS
|
||||
declare module '*.css' {}
|
||||
declare module '*.scss' {}
|
Reference in New Issue
Block a user