@things-factory/pdf 10.1.131 → 10.1.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ import '@operato/list-state/ox-page-state.js';
2
+ import { PageView } from '@operato/shell';
3
+ declare const PDFTemplateEditor_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
4
+ /**
5
+ * One PDF template: its parts are Handlebars HTML, written here or loaded from a file, and printed to a PDF with
6
+ * sample data before it is used.
7
+ */
8
+ export declare class PDFTemplateEditor extends PDFTemplateEditor_base {
9
+ static styles: import("lit").CSSResult[];
10
+ private templateId;
11
+ private form;
12
+ private sample;
13
+ private preview;
14
+ private busy;
15
+ private failure;
16
+ get context(): {
17
+ title: string;
18
+ menu: string;
19
+ frame: string;
20
+ actions: {
21
+ title: string;
22
+ icon: string;
23
+ emphasis: {
24
+ raised: boolean;
25
+ };
26
+ action: () => Promise<void>;
27
+ }[];
28
+ };
29
+ pageUpdated(changes: any, lifecycle: any): void;
30
+ private read;
31
+ private run;
32
+ private save;
33
+ /** The saved template printed with the sample data — save first to see a change. */
34
+ private showPreview;
35
+ private load;
36
+ render(): import("lit-html").TemplateResult<1>;
37
+ }
38
+ export {};
@@ -0,0 +1,198 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@operato/list-state/ox-page-state.js';
3
+ import { client } from '@operato/graphql';
4
+ import { i18next, localize } from '@operato/i18n';
5
+ import { navigate, PageView } from '@operato/shell';
6
+ import { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles';
7
+ import gql from 'graphql-tag';
8
+ import { css, html, nothing } from 'lit';
9
+ import { customElement, state } from 'lit/decorators.js';
10
+ const FIELDS = 'id name description active state page_size watermark content_template header_template footer_template cover_template last_template';
11
+ const PAGE_SIZES = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid'];
12
+ const blank = () => ({ name: '', description: '', active: true, state: 'draft', page_size: 'A4', watermark: '', content_template: '', header_template: '', footer_template: '', cover_template: '', last_template: '' });
13
+ /**
14
+ * One PDF template: its parts are Handlebars HTML, written here or loaded from a file, and printed to a PDF with
15
+ * sample data before it is used.
16
+ */
17
+ let PDFTemplateEditor = class PDFTemplateEditor extends localize(i18next)(PageView) {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.templateId = '';
21
+ this.form = blank();
22
+ this.sample = '{}';
23
+ this.preview = '';
24
+ this.busy = false;
25
+ this.failure = '';
26
+ }
27
+ static { this.styles = [
28
+ DocumentPageStyles,
29
+ FormFieldStyles,
30
+ ButtonStyles,
31
+ css `
32
+ .form {
33
+ display: grid;
34
+ grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
35
+ gap: var(--spacing-large);
36
+ }
37
+ label {
38
+ display: flex;
39
+ flex-direction: column;
40
+ gap: var(--spacing-small);
41
+ }
42
+ label.wide {
43
+ grid-column: 1 / -1;
44
+ }
45
+ textarea {
46
+ font-family: monospace;
47
+ min-height: 12em;
48
+ }
49
+ textarea.content {
50
+ min-height: 40vh;
51
+ }
52
+ iframe {
53
+ width: 100%;
54
+ height: 80vh;
55
+ border: 1px solid var(--md-sys-color-outline-variant);
56
+ }
57
+ `
58
+ ]; }
59
+ get context() {
60
+ return {
61
+ title: i18next.t('title.pdf-template'),
62
+ menu: 'pdf-template-list-page',
63
+ frame: 'document',
64
+ actions: this.busy ? [] : [{ title: i18next.t('button.save'), icon: 'save', emphasis: { raised: true }, action: () => this.save() }]
65
+ };
66
+ }
67
+ pageUpdated(changes, lifecycle) {
68
+ if (!this.active || !(changes.active || changes.params))
69
+ return;
70
+ this.templateId = lifecycle?.params?.id ?? '';
71
+ this.form = blank();
72
+ this.preview = '';
73
+ if (this.templateId)
74
+ this.read();
75
+ }
76
+ async read() {
77
+ const response = await client.query({ query: gql(`query ($id: String!) { PDFTemplate(id: $id) { ${FIELDS} } }`), variables: { id: this.templateId }, fetchPolicy: 'no-cache' });
78
+ const { id, ...template } = response.data?.PDFTemplate ?? {};
79
+ if (id)
80
+ this.form = { ...blank(), ...Object.fromEntries(Object.entries(template).map(([key, value]) => [key, value ?? ''])) };
81
+ }
82
+ async run(work) {
83
+ if (this.busy)
84
+ return;
85
+ this.busy = true;
86
+ this.failure = '';
87
+ this.updateContext();
88
+ try {
89
+ await work();
90
+ }
91
+ catch (error) {
92
+ this.failure = error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error);
93
+ }
94
+ finally {
95
+ this.busy = false;
96
+ this.updateContext();
97
+ }
98
+ }
99
+ save() {
100
+ return this.run(async () => {
101
+ const id = this.templateId;
102
+ const response = await client.mutate({
103
+ mutation: gql(id
104
+ ? `mutation ($id: String!, $patch: PDFTemplatePatch!) { template: updatePDFTemplate(id: $id, patch: $patch) { id } }`
105
+ : `mutation ($template: NewPDFTemplate!) { template: createPDFTemplate(pdfTemplate: $template) { id } }`),
106
+ variables: id ? { id, patch: this.form } : { template: this.form }
107
+ });
108
+ if (response.errors?.length)
109
+ throw response;
110
+ if (!id)
111
+ navigate(`pdf-template-editor?id=${response.data.template.id}`);
112
+ });
113
+ }
114
+ /** The saved template printed with the sample data — save first to see a change. */
115
+ showPreview() {
116
+ if (this.preview) {
117
+ URL.revokeObjectURL(this.preview);
118
+ this.preview = '';
119
+ return;
120
+ }
121
+ return this.run(async () => {
122
+ const data = JSON.parse(this.sample || '{}');
123
+ const response = await client.query({ query: gql `query ($id: String!, $data: Object) { renderPDF(templateId: $id, data: $data) }`, variables: { id: this.templateId, data }, fetchPolicy: 'no-cache' });
124
+ if (response.errors?.length)
125
+ throw response;
126
+ const bytes = Uint8Array.from(atob(response.data.renderPDF), c => c.charCodeAt(0));
127
+ this.preview = URL.createObjectURL(new Blob([bytes], { type: 'application/pdf' }));
128
+ });
129
+ }
130
+ async load(key, e) {
131
+ const file = e.target.files?.[0];
132
+ if (file)
133
+ this.form = { ...this.form, [key]: await file.text() };
134
+ }
135
+ render() {
136
+ const patch = (key, value) => (this.form = { ...this.form, [key]: value });
137
+ const text = (key, label) => html `<label>${label}<input .value=${this.form[key] ?? ''} @input=${(e) => patch(key, e.target.value)} /></label>`;
138
+ const part = (key, label, wide = '') => html `<label class="wide"
139
+ >${label}
140
+ <textarea class=${wide} .value=${this.form[key] ?? ''} @input=${(e) => patch(key, e.target.value)}></textarea>
141
+ <input type="file" accept=".html,.htm,text/html" @change=${(e) => this.load(key, e)} />
142
+ </label>`;
143
+ return html `<div class="page">
144
+ ${this.failure ? html `<p class="notice crit" role="alert">${this.failure}</p>` : nothing}
145
+ <section class="page-section">
146
+ <div class="form">
147
+ ${text('name', i18next.t('field.name'))}${text('description', i18next.t('field.description'))}
148
+ <label
149
+ >${i18next.t('field.page_size')}
150
+ <select .value=${this.form.page_size} @change=${(e) => patch('page_size', e.target.value)}>
151
+ ${PAGE_SIZES.map(size => html `<option value=${size} ?selected=${size === this.form.page_size}>${size}</option>`)}
152
+ </select></label
153
+ >
154
+ ${text('watermark', i18next.t('field.watermark'))}
155
+ ${part('content_template', i18next.t('field.content_template'), 'content')}${part('header_template', i18next.t('field.header_template'))}${part('footer_template', i18next.t('field.footer_template'))}${part('cover_template', i18next.t('field.cover_template'))}${part('last_template', i18next.t('field.last_template'))}
156
+ </div>
157
+ </section>
158
+ ${this.templateId
159
+ ? html `<section class="page-section">
160
+ <div class="form">
161
+ <label class="wide">${i18next.t('field.pdf-sample-data')}<textarea .value=${this.sample} @input=${(e) => (this.sample = e.target.value)}></textarea></label>
162
+ </div>
163
+ <button ?disabled=${this.busy} @click=${() => this.showPreview()}>${i18next.t('button.pdf-preview')}</button>
164
+ ${this.preview ? html `<iframe title=${i18next.t('button.pdf-preview')} src=${this.preview}></iframe>` : nothing}
165
+ </section>`
166
+ : nothing}
167
+ </div>`;
168
+ }
169
+ };
170
+ __decorate([
171
+ state(),
172
+ __metadata("design:type", Object)
173
+ ], PDFTemplateEditor.prototype, "templateId", void 0);
174
+ __decorate([
175
+ state(),
176
+ __metadata("design:type", Object)
177
+ ], PDFTemplateEditor.prototype, "form", void 0);
178
+ __decorate([
179
+ state(),
180
+ __metadata("design:type", Object)
181
+ ], PDFTemplateEditor.prototype, "sample", void 0);
182
+ __decorate([
183
+ state(),
184
+ __metadata("design:type", Object)
185
+ ], PDFTemplateEditor.prototype, "preview", void 0);
186
+ __decorate([
187
+ state(),
188
+ __metadata("design:type", Object)
189
+ ], PDFTemplateEditor.prototype, "busy", void 0);
190
+ __decorate([
191
+ state(),
192
+ __metadata("design:type", Object)
193
+ ], PDFTemplateEditor.prototype, "failure", void 0);
194
+ PDFTemplateEditor = __decorate([
195
+ customElement('pdf-template-editor')
196
+ ], PDFTemplateEditor);
197
+ export { PDFTemplateEditor };
198
+ //# sourceMappingURL=pdf-template-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-template-editor.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-editor.ts"],"names":[],"mappings":";AAAA,OAAO,sCAAsC,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnF,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,MAAM,GAAG,oIAAoI,CAAA;AACnJ,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AACnE,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,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;IAAhB,KAAK,EAAE;;+CAAqB;AACZ;IAAhB,KAAK,EAAE;;kDAAqB;AAvClB,iBAAiB;IAD7B,aAAa,CAAC,qBAAqB,CAAC;GACxB,iBAAiB,CAsJ7B","sourcesContent":["import '@operato/list-state/ox-page-state.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles'\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, state } from 'lit/decorators.js'\n\nconst FIELDS = 'id name description active state page_size watermark content_template header_template footer_template cover_template last_template'\nconst PAGE_SIZES = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid']\nconst blank = () => ({ name: '', description: '', active: true, state: 'draft', page_size: 'A4', watermark: '', content_template: '', header_template: '', footer_template: '', cover_template: '', last_template: '' })\n\n/**\n * One PDF template: its parts are Handlebars HTML, written here or loaded from a file, and printed to a PDF with\n * sample data before it is used.\n */\n@customElement('pdf-template-editor')\nexport class PDFTemplateEditor extends localize(i18next)(PageView) {\n static styles = [\n DocumentPageStyles,\n FormFieldStyles,\n ButtonStyles,\n css`\n .form {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));\n gap: var(--spacing-large);\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-small);\n }\n label.wide {\n grid-column: 1 / -1;\n }\n textarea {\n font-family: monospace;\n min-height: 12em;\n }\n textarea.content {\n min-height: 40vh;\n }\n iframe {\n width: 100%;\n height: 80vh;\n border: 1px solid var(--md-sys-color-outline-variant);\n }\n `\n ]\n\n @state() private templateId = ''\n @state() private form: Record<string, any> = blank()\n @state() private sample = '{}'\n @state() private preview = ''\n @state() private busy = false\n @state() private failure = ''\n\n get context() {\n return {\n title: i18next.t('title.pdf-template'),\n menu: 'pdf-template-list-page',\n frame: 'document',\n actions: this.busy ? [] : [{ title: i18next.t('button.save'), icon: 'save', emphasis: { raised: true }, action: () => this.save() }]\n }\n }\n\n pageUpdated(changes: any, lifecycle: any) {\n if (!this.active || !(changes.active || changes.params)) return\n this.templateId = lifecycle?.params?.id ?? ''\n this.form = blank()\n this.preview = ''\n if (this.templateId) this.read()\n }\n\n private async read() {\n const response = await client.query({ query: gql(`query ($id: String!) { PDFTemplate(id: $id) { ${FIELDS} } }`), variables: { id: this.templateId }, fetchPolicy: 'no-cache' })\n const { id, ...template } = response.data?.PDFTemplate ?? {}\n if (id) this.form = { ...blank(), ...Object.fromEntries(Object.entries(template).map(([key, value]) => [key, value ?? ''])) }\n }\n\n private async run(work: () => Promise<void>) {\n if (this.busy) return\n this.busy = true\n this.failure = ''\n this.updateContext()\n try {\n await work()\n } catch (error: any) {\n this.failure = error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error)\n } finally {\n this.busy = false\n this.updateContext()\n }\n }\n\n private save() {\n return this.run(async () => {\n const id = this.templateId\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $patch: PDFTemplatePatch!) { template: updatePDFTemplate(id: $id, patch: $patch) { id } }`\n : `mutation ($template: NewPDFTemplate!) { template: createPDFTemplate(pdfTemplate: $template) { id } }`\n ),\n variables: id ? { id, patch: this.form } : { template: this.form }\n })\n if (response.errors?.length) throw response\n if (!id) navigate(`pdf-template-editor?id=${response.data.template.id}`)\n })\n }\n\n /** The saved template printed with the sample data — save first to see a change. */\n private showPreview() {\n if (this.preview) {\n URL.revokeObjectURL(this.preview)\n this.preview = ''\n return\n }\n return this.run(async () => {\n const data = JSON.parse(this.sample || '{}')\n const response = await client.query({ query: gql`query ($id: String!, $data: Object) { renderPDF(templateId: $id, data: $data) }`, variables: { id: this.templateId, data }, fetchPolicy: 'no-cache' })\n if (response.errors?.length) throw response\n const bytes = Uint8Array.from(atob(response.data.renderPDF), c => c.charCodeAt(0))\n this.preview = URL.createObjectURL(new Blob([bytes], { type: 'application/pdf' }))\n })\n }\n\n private async load(key: string, e: Event) {\n const file = (e.target as HTMLInputElement).files?.[0]\n if (file) this.form = { ...this.form, [key]: await file.text() }\n }\n\n render() {\n const patch = (key: string, value: any) => (this.form = { ...this.form, [key]: value })\n const text = (key: string, label: string) => html`<label>${label}<input .value=${this.form[key] ?? ''} @input=${(e: any) => patch(key, e.target.value)} /></label>`\n const part = (key: string, label: string, wide = '') => html`<label class=\"wide\"\n >${label}\n <textarea class=${wide} .value=${this.form[key] ?? ''} @input=${(e: any) => patch(key, e.target.value)}></textarea>\n <input type=\"file\" accept=\".html,.htm,text/html\" @change=${(e: Event) => this.load(key, e)} />\n </label>`\n return html`<div class=\"page\">\n ${this.failure ? html`<p class=\"notice crit\" role=\"alert\">${this.failure}</p>` : nothing}\n <section class=\"page-section\">\n <div class=\"form\">\n ${text('name', i18next.t('field.name'))}${text('description', i18next.t('field.description'))}\n <label\n >${i18next.t('field.page_size')}\n <select .value=${this.form.page_size} @change=${(e: any) => patch('page_size', e.target.value)}>\n ${PAGE_SIZES.map(size => html`<option value=${size} ?selected=${size === this.form.page_size}>${size}</option>`)}\n </select></label\n >\n ${text('watermark', i18next.t('field.watermark'))}\n ${part('content_template', i18next.t('field.content_template'), 'content')}${part('header_template', i18next.t('field.header_template'))}${part('footer_template', i18next.t('field.footer_template'))}${part('cover_template', i18next.t('field.cover_template'))}${part('last_template', i18next.t('field.last_template'))}\n </div>\n </section>\n ${this.templateId\n ? html`<section class=\"page-section\">\n <div class=\"form\">\n <label class=\"wide\">${i18next.t('field.pdf-sample-data')}<textarea .value=${this.sample} @input=${(e: any) => (this.sample = e.target.value)}></textarea></label>\n </div>\n <button ?disabled=${this.busy} @click=${() => this.showPreview()}>${i18next.t('button.pdf-preview')}</button>\n ${this.preview ? html`<iframe title=${i18next.t('button.pdf-preview')} src=${this.preview}></iframe>` : nothing}\n </section>`\n : nothing}\n </div>`\n }\n}\n"]}
@@ -5,7 +5,7 @@ import '@operato/data-grist/ox-grist.js';
5
5
  import '@operato/data-grist/ox-filters-form.js';
6
6
  import '@operato/data-grist/ox-record-creator.js';
7
7
  import { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles';
8
- import { PageView } from '@operato/shell';
8
+ import { navigate, PageView } from '@operato/shell';
9
9
  import { css, html } from 'lit';
10
10
  import { customElement, property, query } from 'lit/decorators.js';
11
11
  import { ScopedElementsMixin } from '@open-wc/scoped-elements';
@@ -100,6 +100,8 @@ let PDFTemplateListPage = class PDFTemplateListPage extends localize(i18next)(Sc
100
100
  columns: [
101
101
  { type: 'gutter', gutterName: 'sequence' },
102
102
  { type: 'gutter', gutterName: 'row-selector', multiple: true },
103
+ /* The parts are HTML — written in the editor, with a file and a preview. */
104
+ { type: 'gutter', gutterName: 'button', icon: 'edit_note', handlers: { click: (_c, _d, _col, record) => record?.id && navigate(`pdf-template-editor?id=${record.id}`) } },
103
105
  { type: 'string',
104
106
  name: 'name',
105
107
  header: i18next.t('field.name'),
@@ -226,8 +228,7 @@ let PDFTemplateListPage = class PDFTemplateListPage extends localize(i18next)(Sc
226
228
  sorters: [
227
229
  { name: 'name'
228
230
  }
229
- ]
230
- };
231
+ ] };
231
232
  }
232
233
  async pageUpdated(changes, lifecycle) {
233
234
  if (this.active) { // do something here when this page just became as active
@@ -1 +1 @@
1
- {"version":3,"file":"pdf-template-list-page.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-list-page.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,yCAAyC,CAAA;AAChD,OAAO,iCAAiC,CAAA;AACxC,OAAO,wCAAwC,CAAA;AAC/C,OAAO,0CAA0C,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACnI,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,O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A2B,CAAC;SACnD,CACG,CAAA;QAED,KAAK,CAAC,QAAQ,GAAG,GAAG,EAAE;YAAS,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QACpD,CAAC,CAAA;IACD,CAAC;;AAjV4B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDAAiB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAoE;AAEpE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;kDAAA;AAxBjC,mBAAmB;IAD/B,aAAa,CAAC,wBAAwB,CAAC;GAC3B,mBAAmB,CAuW/B","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/button/elevated-button.js'\nimport '@operato/data-grist/ox-grist.js'\nimport '@operato/data-grist/ox-filters-form.js'\nimport '@operato/data-grist/ox-record-creator.js'\n\nimport { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles'\nimport { PageView } from '@operato/shell'\nimport { css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements'\nimport { ColumnConfig, DataGrist, FetchOption } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { OxPopup, OxPrompt } from '@operato/popup'\nimport { isMobileDevice } from '@operato/utils'\n\nimport gql from 'graphql-tag'\n\nimport { PDFTemplateImporter } from './pdf-template-importer'\n\n@customElement('pdf-template-list-page')\nexport class PDFTemplateListPage extends localize(i18next)(ScopedElementsMixin(PageView)) { static styles = [\n /* The work surface frame for a list screen (ADR-0060 decision 8). */\n WorkSurfacePageStyles,\n ScrollbarStyles,\n CommonGristStyles,\n CommonHeaderStyles,\n css`\n :host {\n --grid-record-emphasized-background-color: #8b0000;\n --grid-record-emphasized-color: #ff6b6b;\n }\n\n ox-filters-form { flex: 1;\n }\n `\n ]\n\n static get scopedElements() { return { 'pdf-template-importer': PDFTemplateImporter\n }\n }\n\n @property({ type: Object }) gristConfig: any\n @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'\n\n @query('ox-grist') private grist!: DataGrist\n\n get context() { return { title: i18next.t('title.pdf-template list'),\n search: { handler: (search: string) => { this.grist.searchText = search\n },\n value: this.grist.searchText\n },\n filter: { handler: () => { this.grist.toggleHeadroom()\n }\n },\n help: 'pdf/pdf-template',\n actions: [\n { title: i18next.t('button.save'),\n action: this._updatePDFTemplate.bind(this),\n ...CommonButtonStyles.save\n },\n { title: i18next.t('button.delete'),\n action: this._deletePDFTemplate.bind(this),\n ...CommonButtonStyles.delete\n }\n ],\n exportable: { name: i18next.t('title.pdf-template list'),\n data: this.exportHandler.bind(this)\n },\n importable: { handler: this.importHandler.bind(this)\n }\n }\n }\n\n render() { const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')\n\n return html`\n <ox-grist class=\"page-fill\" .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>\n <div slot=\"headroom\" class=\"header\">\n <div class=\"filters\">\n <ox-filters-form autofocus without-search></ox-filters-form>\n\n <div id=\"modes\">\n <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>\n <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>\n <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>\n </div>\n\n <ox-record-creator id=\"add\" .callback=${this.creationCallback.bind(this)}>\n <button>\n <md-icon>add</md-icon>\n </button>\n </ox-record-creator>\n </div>\n </div>\n </ox-grist>\n `\n }\n\n async pageInitialized(lifecycle: any) { this.gristConfig = { list: { fields: ['name', 'description'],\n details: ['active', 'updatedAt']\n },\n columns: [\n { type: 'gutter', gutterName: 'sequence' },\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n { type: 'string',\n name: 'name',\n header: i18next.t('field.name'),\n record: { editable: true\n },\n filter: 'search',\n sortable: true,\n width: 150\n },\n { type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: { editable: true\n },\n filter: 'search',\n width: 200\n },\n { type: 'checkbox',\n name: 'active',\n label: true,\n header: i18next.t('field.active'),\n record: { editable: true\n },\n filter: true,\n sortable: true,\n width: 60\n },\n { type: 'string',\n name: 'state',\n label: true,\n header: i18next.t('field.state'),\n record: { editable: true\n },\n width: 120\n },\n { type: 'template',\n name: 'content_template',\n label: true,\n header: i18next.t('field.content_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'header_template',\n label: true,\n header: i18next.t('field.header_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'footer_template',\n label: true,\n header: i18next.t('field.footer_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'cover_template',\n label: true,\n header: i18next.t('field.cover_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'last_template',\n label: true,\n header: i18next.t('field.last_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'select',\n name: 'page_size',\n label: true,\n header: i18next.t('field.page_size'),\n record: { editable: true,\n options: ['', 'A4', 'B4']\n },\n width: 120\n },\n { type: 'string',\n name: 'watermark',\n label: true,\n header: i18next.t('field.watermark'),\n record: { editable: true\n },\n width: 120\n },\n\n { type: 'resource-object',\n name: 'updater',\n header: i18next.t('field.updater'),\n record: { editable: false\n },\n sortable: true,\n width: 120\n },\n { type: 'datetime',\n name: 'updatedAt',\n header: i18next.t('field.updated_at'),\n record: { editable: false\n },\n sortable: true,\n width: 180\n }\n ],\n rows: { appendable: false,\n selectable: { multiple: true\n }\n },\n sorters: [\n { name: 'name'\n }\n ]\n }\n }\n\n async pageUpdated(changes: any, lifecycle: any) { if (this.active) { // do something here when this page just became as active\n }\n }\n\n async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) { const response = await client.query({ query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) { responses: PDFTemplates(filters: $filters, pagination: $pagination, sortings: $sortings) { items { id\n name\n description\n active\n state\n content_template\n header_template\n footer_template\n cover_template\n last_template\n page_size\n watermark\n updater { id\n name\n }\n updatedAt\n }\n total\n }\n }\n `,\n variables: { filters,\n pagination: { page, limit },\n sortings\n }\n })\n\n return { total: response.data.responses.total || 0,\n records: response.data.responses.items || []\n }\n }\n\n async _deletePDFTemplate() { if (\n await OxPrompt.open({ title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }),\n confirmButton: { text: i18next.t('button.confirm') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) { const ids = this.grist.selected.map(record => record.id)\n if (ids && ids.length > 0) { const response = await client.mutate({ mutation: gql`\n mutation ($ids: [String!]!) { deletePDFTemplates(ids: $ids)\n }\n `,\n variables: { ids\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n notify({ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })\n })\n }\n }\n }\n }\n\n async _updatePDFTemplate() { let patches = this.grist.dirtyRecords\n if (patches && patches.length) { patches = patches.map(patch => { let patchField: any = patch.id ? { id: patch.id } : {}\n const dirtyFields = patch.__dirtyfields__\n for (let key in dirtyFields) { patchField[key] = dirtyFields[key].after\n }\n patchField.cuFlag = patch.__dirty__\n\n return patchField\n })\n\n const response = await client.mutate({ mutation: gql`\n mutation ($patches: [PDFTemplatePatch!]!) { updateMultiplePDFTemplate(patches: $patches) { name\n }\n }\n `,\n variables: { patches\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n }\n }\n }\n\n async creationCallback(pdfTemplate) { try { const response = await client.query({ query: gql`\n mutation ($pdfTemplate: NewPDFTemplate!) { createPDFTemplate(pdfTemplate: $pdfTemplate) { id\n }\n }\n `,\n variables: { pdfTemplate\n },\n context: { hasUpload: true\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { message: i18next.t('text.data_created_successfully')\n }\n })\n )\n }\n\n return true\n } catch (ex) { console.error(ex)\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { type: 'error',\n message: i18next.t('text.error')\n }\n })\n )\n return false\n }\n }\n\n async exportHandler() { const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records\n const targetFieldSet = new Set(['id', 'name', 'description', 'active'])\n\n return exportTargets.map(pdfTemplate => { let tempObj = {}\n for (const field of targetFieldSet) { tempObj[field] = pdfTemplate[field]\n }\n\n return tempObj\n })\n }\n\n async importHandler(records) { const popup = openPopup(\n html`\n <pdf-template-importer\n .pdfTemplates=${records}\n @imported=${() => { history.back()\n this.grist.fetch()\n }}\n ></pdf-template-importer>\n `,\n { backdrop: true,\n size: 'large',\n title: i18next.t('title.import pdf-template')\n }\n )\n\n popup.onclosed = () => { this.grist.fetch()\n }\n }\n}\n"]}
1
+ {"version":3,"file":"pdf-template-list-page.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-list-page.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,yCAAyC,CAAA;AAChD,OAAO,iCAAiC,CAAA;AACxC,OAAO,wCAAwC,CAAA;AAC/C,OAAO,0CAA0C,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACnI,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EA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AAO,CAAC,IAAI,EAAE,CAAA;YAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAC7B,CAAC;;OAEK,EACD,EAAU,QAAQ,EAAE,IAAI;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;SACnD,CACG,CAAA;QAED,KAAK,CAAC,QAAQ,GAAG,GAAG,EAAE;YAAS,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QACpD,CAAC,CAAA;IACD,CAAC;;AAnV4B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDAAiB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAoE;AAEpE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;kDAAA;AAxBjC,mBAAmB;IAD/B,aAAa,CAAC,wBAAwB,CAAC;GAC3B,mBAAmB,CAyW/B","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/button/elevated-button.js'\nimport '@operato/data-grist/ox-grist.js'\nimport '@operato/data-grist/ox-filters-form.js'\nimport '@operato/data-grist/ox-record-creator.js'\n\nimport { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles'\nimport { navigate, PageView } from '@operato/shell'\nimport { css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements'\nimport { ColumnConfig, DataGrist, FetchOption } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { OxPopup, OxPrompt } from '@operato/popup'\nimport { isMobileDevice } from '@operato/utils'\n\nimport gql from 'graphql-tag'\n\nimport { PDFTemplateImporter } from './pdf-template-importer'\n\n@customElement('pdf-template-list-page')\nexport class PDFTemplateListPage extends localize(i18next)(ScopedElementsMixin(PageView)) { static styles = [\n /* The work surface frame for a list screen (ADR-0060 decision 8). */\n WorkSurfacePageStyles,\n ScrollbarStyles,\n CommonGristStyles,\n CommonHeaderStyles,\n css`\n :host {\n --grid-record-emphasized-background-color: #8b0000;\n --grid-record-emphasized-color: #ff6b6b;\n }\n\n ox-filters-form { flex: 1;\n }\n `\n ]\n\n static get scopedElements() { return { 'pdf-template-importer': PDFTemplateImporter\n }\n }\n\n @property({ type: Object }) gristConfig: any\n @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'\n\n @query('ox-grist') private grist!: DataGrist\n\n get context() { return { title: i18next.t('title.pdf-template list'),\n search: { handler: (search: string) => { this.grist.searchText = search\n },\n value: this.grist.searchText\n },\n filter: { handler: () => { this.grist.toggleHeadroom()\n }\n },\n help: 'pdf/pdf-template',\n actions: [\n { title: i18next.t('button.save'),\n action: this._updatePDFTemplate.bind(this),\n ...CommonButtonStyles.save\n },\n { title: i18next.t('button.delete'),\n action: this._deletePDFTemplate.bind(this),\n ...CommonButtonStyles.delete\n }\n ],\n exportable: { name: i18next.t('title.pdf-template list'),\n data: this.exportHandler.bind(this)\n },\n importable: { handler: this.importHandler.bind(this)\n }\n }\n }\n\n render() { const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')\n\n return html`\n <ox-grist class=\"page-fill\" .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>\n <div slot=\"headroom\" class=\"header\">\n <div class=\"filters\">\n <ox-filters-form autofocus without-search></ox-filters-form>\n\n <div id=\"modes\">\n <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>\n <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>\n <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>\n </div>\n\n <ox-record-creator id=\"add\" .callback=${this.creationCallback.bind(this)}>\n <button>\n <md-icon>add</md-icon>\n </button>\n </ox-record-creator>\n </div>\n </div>\n </ox-grist>\n `\n }\n\n async pageInitialized(lifecycle: any) { this.gristConfig = { list: { fields: ['name', 'description'],\n details: ['active', 'updatedAt']\n },\n columns: [\n { type: 'gutter', gutterName: 'sequence' },\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n /* The parts are HTML — written in the editor, with a file and a preview. */\n { type: 'gutter', gutterName: 'button', icon: 'edit_note', handlers: { click: (_c: any, _d: any, _col: any, record: any) => record?.id && navigate(`pdf-template-editor?id=${record.id}`) } },\n { type: 'string',\n name: 'name',\n header: i18next.t('field.name'),\n record: { editable: true\n },\n filter: 'search',\n sortable: true,\n width: 150\n },\n { type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: { editable: true\n },\n filter: 'search',\n width: 200\n },\n { type: 'checkbox',\n name: 'active',\n label: true,\n header: i18next.t('field.active'),\n record: { editable: true\n },\n filter: true,\n sortable: true,\n width: 60\n },\n { type: 'string',\n name: 'state',\n label: true,\n header: i18next.t('field.state'),\n record: { editable: true\n },\n width: 120\n },\n { type: 'template',\n name: 'content_template',\n label: true,\n header: i18next.t('field.content_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'header_template',\n label: true,\n header: i18next.t('field.header_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'footer_template',\n label: true,\n header: i18next.t('field.footer_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'cover_template',\n label: true,\n header: i18next.t('field.cover_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'last_template',\n label: true,\n header: i18next.t('field.last_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'select',\n name: 'page_size',\n label: true,\n header: i18next.t('field.page_size'),\n record: { editable: true,\n options: ['', 'A4', 'B4']\n },\n width: 120\n },\n { type: 'string',\n name: 'watermark',\n label: true,\n header: i18next.t('field.watermark'),\n record: { editable: true\n },\n width: 120\n },\n\n { type: 'resource-object',\n name: 'updater',\n header: i18next.t('field.updater'),\n record: { editable: false\n },\n sortable: true,\n width: 120\n },\n { type: 'datetime',\n name: 'updatedAt',\n header: i18next.t('field.updated_at'),\n record: { editable: false\n },\n sortable: true,\n width: 180\n }\n ],\n rows: { appendable: false,\n selectable: { multiple: true\n }\n },\n sorters: [\n { name: 'name'\n }\n ]\n }\n }\n\n async pageUpdated(changes: any, lifecycle: any) { if (this.active) { // do something here when this page just became as active\n }\n }\n\n async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) { const response = await client.query({ query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) { responses: PDFTemplates(filters: $filters, pagination: $pagination, sortings: $sortings) { items { id\n name\n description\n active\n state\n content_template\n header_template\n footer_template\n cover_template\n last_template\n page_size\n watermark\n updater { id\n name\n }\n updatedAt\n }\n total\n }\n }\n `,\n variables: { filters,\n pagination: { page, limit },\n sortings\n }\n })\n\n return { total: response.data.responses.total || 0,\n records: response.data.responses.items || []\n }\n }\n\n async _deletePDFTemplate() { if (\n await OxPrompt.open({ title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }),\n confirmButton: { text: i18next.t('button.confirm') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) { const ids = this.grist.selected.map(record => record.id)\n if (ids && ids.length > 0) { const response = await client.mutate({ mutation: gql`\n mutation ($ids: [String!]!) { deletePDFTemplates(ids: $ids)\n }\n `,\n variables: { ids\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n notify({ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })\n })\n }\n }\n }\n }\n\n async _updatePDFTemplate() { let patches = this.grist.dirtyRecords\n if (patches && patches.length) { patches = patches.map(patch => { let patchField: any = patch.id ? { id: patch.id } : {}\n const dirtyFields = patch.__dirtyfields__\n for (let key in dirtyFields) { patchField[key] = dirtyFields[key].after\n }\n patchField.cuFlag = patch.__dirty__\n\n return patchField\n })\n\n const response = await client.mutate({ mutation: gql`\n mutation ($patches: [PDFTemplatePatch!]!) { updateMultiplePDFTemplate(patches: $patches) { name\n }\n }\n `,\n variables: { patches\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n }\n }\n }\n\n async creationCallback(pdfTemplate) { try { const response = await client.query({ query: gql`\n mutation ($pdfTemplate: NewPDFTemplate!) { createPDFTemplate(pdfTemplate: $pdfTemplate) { id\n }\n }\n `,\n variables: { pdfTemplate\n },\n context: { hasUpload: true\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { message: i18next.t('text.data_created_successfully')\n }\n })\n )\n }\n\n return true\n } catch (ex) { console.error(ex)\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { type: 'error',\n message: i18next.t('text.error')\n }\n })\n )\n return false\n }\n }\n\n async exportHandler() { const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records\n const targetFieldSet = new Set(['id', 'name', 'description', 'active'])\n\n return exportTargets.map(pdfTemplate => { let tempObj = {}\n for (const field of targetFieldSet) { tempObj[field] = pdfTemplate[field]\n }\n\n return tempObj\n })\n }\n\n async importHandler(records) { const popup = openPopup(\n html`\n <pdf-template-importer\n .pdfTemplates=${records}\n @imported=${() => { history.back()\n this.grist.fetch()\n }}\n ></pdf-template-importer>\n `,\n { backdrop: true,\n size: 'large',\n title: i18next.t('title.import pdf-template')\n }\n )\n\n popup.onclosed = () => { this.grist.fetch()\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- export default function route(page: string): "pdf-template-list-page" | "pdf-release-list" | undefined;
1
+ export default function route(page: string): "pdf-template-list-page" | "pdf-template-editor" | "pdf-release-list" | undefined;
@@ -3,6 +3,9 @@ export default function route(page) {
3
3
  case 'pdf-template-list-page':
4
4
  import('./pages/pdf-template/pdf-template-list-page');
5
5
  return page;
6
+ case 'pdf-template-editor':
7
+ import('./pages/pdf-template/pdf-template-editor');
8
+ return page;
6
9
  case 'pdf-release-list':
7
10
  import('./pages/pdf-release/pdf-release-list-page');
8
11
  return page;
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../client/route.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,IAAY;IACxC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,wBAAwB;YAC3B,MAAM,CAAC,6CAA6C,CAAC,CAAA;YACrD,OAAO,IAAI,CAAA;QAEX,KAAK,kBAAkB;YACrB,MAAM,CAAC,2CAA2C,CAAC,CAAA;YACnD,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC","sourcesContent":["export default function route(page: string) {\n switch (page) {\n case 'pdf-template-list-page':\n import('./pages/pdf-template/pdf-template-list-page')\n return page\n \n case 'pdf-release-list':\n import('./pages/pdf-release/pdf-release-list-page')\n return page\n }\n }\n"]}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../client/route.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,IAAY;IACxC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,wBAAwB;YAC3B,MAAM,CAAC,6CAA6C,CAAC,CAAA;YACrD,OAAO,IAAI,CAAA;QAEb,KAAK,qBAAqB;YACxB,MAAM,CAAC,0CAA0C,CAAC,CAAA;YAClD,OAAO,IAAI,CAAA;QAEb,KAAK,kBAAkB;YACrB,MAAM,CAAC,2CAA2C,CAAC,CAAA;YACnD,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC","sourcesContent":["export default function route(page: string) {\n switch (page) {\n case 'pdf-template-list-page':\n import('./pages/pdf-template/pdf-template-list-page')\n return page\n\n case 'pdf-template-editor':\n import('./pages/pdf-template/pdf-template-editor')\n return page\n\n case 'pdf-release-list':\n import('./pages/pdf-release/pdf-release-list-page')\n return page\n }\n}\n"]}