@operato/grist-editor 1.0.0-alpha.9

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.
Files changed (69) hide show
  1. package/.editorconfig +29 -0
  2. package/.storybook/main.js +3 -0
  3. package/.storybook/server.mjs +8 -0
  4. package/CHANGELOG.md +11 -0
  5. package/LICENSE +21 -0
  6. package/README.md +75 -0
  7. package/demo/data-grist-test.html +456 -0
  8. package/demo/index.html +33 -0
  9. package/dist/src/code/code-editor.d.ts +6 -0
  10. package/dist/src/code/code-editor.js +50 -0
  11. package/dist/src/code/code-editor.js.map +1 -0
  12. package/dist/src/code/index.d.ts +1 -0
  13. package/dist/src/code/index.js +5 -0
  14. package/dist/src/code/index.js.map +1 -0
  15. package/dist/src/id/id-input.d.ts +19 -0
  16. package/dist/src/id/id-input.js +119 -0
  17. package/dist/src/id/id-input.js.map +1 -0
  18. package/dist/src/id/id-renderer.d.ts +2 -0
  19. package/dist/src/id/id-renderer.js +9 -0
  20. package/dist/src/id/id-renderer.js.map +1 -0
  21. package/dist/src/id/id-selector.d.ts +23 -0
  22. package/dist/src/id/id-selector.js +197 -0
  23. package/dist/src/id/id-selector.js.map +1 -0
  24. package/dist/src/id/index.d.ts +1 -0
  25. package/dist/src/id/index.js +7 -0
  26. package/dist/src/id/index.js.map +1 -0
  27. package/dist/src/index.d.ts +0 -0
  28. package/dist/src/index.js +2 -0
  29. package/dist/src/index.js.map +1 -0
  30. package/dist/src/object/index.d.ts +1 -0
  31. package/dist/src/object/index.js +6 -0
  32. package/dist/src/object/index.js.map +1 -0
  33. package/dist/src/object/object-editor.d.ts +18 -0
  34. package/dist/src/object/object-editor.js +152 -0
  35. package/dist/src/object/object-editor.js.map +1 -0
  36. package/dist/src/object/object-selector.d.ts +38 -0
  37. package/dist/src/object/object-selector.js +338 -0
  38. package/dist/src/object/object-selector.js.map +1 -0
  39. package/dist/src/parameters/index.d.ts +1 -0
  40. package/dist/src/parameters/index.js +6 -0
  41. package/dist/src/parameters/index.js.map +1 -0
  42. package/dist/src/parameters/parameters-editor-builder.d.ts +4 -0
  43. package/dist/src/parameters/parameters-editor-builder.js +119 -0
  44. package/dist/src/parameters/parameters-editor-builder.js.map +1 -0
  45. package/dist/src/parameters/parameters-editor-popup.d.ts +13 -0
  46. package/dist/src/parameters/parameters-editor-popup.js +111 -0
  47. package/dist/src/parameters/parameters-editor-popup.js.map +1 -0
  48. package/dist/src/parameters/parameters-editor.d.ts +18 -0
  49. package/dist/src/parameters/parameters-editor.js +106 -0
  50. package/dist/src/parameters/parameters-editor.js.map +1 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -0
  52. package/package.json +87 -0
  53. package/src/code/code-editor.ts +78 -0
  54. package/src/code/index.ts +6 -0
  55. package/src/id/id-input.ts +135 -0
  56. package/src/id/id-renderer.ts +12 -0
  57. package/src/id/id-selector.ts +189 -0
  58. package/src/id/index.ts +8 -0
  59. package/src/index.ts +0 -0
  60. package/src/object/index.ts +8 -0
  61. package/src/object/object-editor.ts +162 -0
  62. package/src/object/object-selector.ts +346 -0
  63. package/src/parameters/index.ts +8 -0
  64. package/src/parameters/parameters-editor-builder.ts +130 -0
  65. package/src/parameters/parameters-editor-popup.ts +106 -0
  66. package/src/parameters/parameters-editor.ts +112 -0
  67. package/tsconfig.json +23 -0
  68. package/web-dev-server.config.mjs +27 -0
  69. package/web-test-runner.config.mjs +41 -0
package/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ stories: ['../dist/stories/**/*.stories.{js,md,mdx}'],
3
+ };
@@ -0,0 +1,8 @@
1
+ import { storybookPlugin } from '@web/dev-server-storybook';
2
+ import baseConfig from '../web-dev-server.config.mjs';
3
+
4
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
+ ...baseConfig,
6
+ open: '/',
7
+ plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
8
+ });
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [1.0.0-alpha.9](https://github.com/hatiolab/operato/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2022-03-12)
7
+
8
+
9
+ ### :rocket: New Features
10
+
11
+ * settled concept for input, property-editor, grist-editor, so on ([0c9e1d0](https://github.com/hatiolab/operato/commit/0c9e1d054c7aef5d965868242cf471667af7a3c3))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) hatiolab.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # \<mini-app>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i mini-app
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'mini-app/mini-app.js'
16
+ </script>
17
+
18
+ <mini-app></mini-app>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+ ## Demoing with Storybook
50
+
51
+ To run a local instance of Storybook for your component, run
52
+
53
+ ```bash
54
+ npm run storybook
55
+ ```
56
+
57
+ To build a production version of Storybook, run
58
+
59
+ ```bash
60
+ npm run storybook:build
61
+ ```
62
+
63
+ ## Tooling configs
64
+
65
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
66
+
67
+ If you customize the configuration a lot, you can consider moving them to individual files.
68
+
69
+ ## Local Demo with `web-dev-server`
70
+
71
+ ```bash
72
+ npm start
73
+ ```
74
+
75
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,456 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" />
6
+ <style>
7
+ body {
8
+ /* box-sizing: border-box; */
9
+ margin: 0;
10
+ padding: 0;
11
+ overflow: hidden;
12
+
13
+ /* This is a font-stack that tries to use the system-default sans-serifs first */
14
+ font-family: Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
15
+ line-height: 1.5;
16
+ -webkit-font-smoothing: antialiased;
17
+ }
18
+
19
+ #app {
20
+ width: 100vw;
21
+ height: 100vh;
22
+
23
+ display: flex;
24
+ flex-direction: column;
25
+ }
26
+
27
+ #demo {
28
+ flex: 1;
29
+
30
+ display: flex;
31
+ flex-direction: column;
32
+ overflow: hidden;
33
+ }
34
+
35
+ grist-demo {
36
+ flex: 1;
37
+ overflow: auto;
38
+ }
39
+ </style>
40
+ <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
41
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
42
+
43
+ <link href="/themes/app-theme.css" rel="stylesheet" />
44
+ <link href="/themes/oops-theme.css" rel="stylesheet" />
45
+ <link href="/themes/grist-theme.css" rel="stylesheet" />
46
+ </head>
47
+
48
+ <body>
49
+ <script type="module">
50
+ import { LitElement, html, css, render } from 'lit'
51
+ import '../dist/index.js'
52
+ import '../dist/src/filters/filters-form.js'
53
+ import '../dist/src/sorters/sorters-control.js'
54
+ import '../dist/src/record-view/record-creator.js'
55
+ import '@operato/popup/ox-popup-list.js'
56
+ import '@material/mwc-icon'
57
+ import { CommonGristStyles } from '@operato/styles'
58
+
59
+ const fetchHandler = async ({ page, limit, sorters = [] }) => {
60
+ var total = 120993
61
+ var start = (page - 1) * limit
62
+
63
+ await new Promise(resolve => setTimeout(resolve, 500))
64
+
65
+ return {
66
+ total,
67
+ records: Array(limit * page > total ? total % limit : limit)
68
+ .fill()
69
+ .map((item, idx) => {
70
+ return {
71
+ id: idx,
72
+ name: idx % 2 ? `shnam-${start + idx + 1}` : `heartyoh-${start + idx + 1}`,
73
+ description:
74
+ idx % 2 ? `hatiolabmanager${start + idx + 1}1234567890` : `hatiosea manager-${start + idx + 1}`,
75
+ email: idx % 2 ? `shnam-${start + idx + 1}@gmail.com` : `heartyoh-${start + idx + 1}@gmail.com`,
76
+ active: Math.round(Math.random() * 2) % 2 ? true : false,
77
+ barcode: idx % 2 ? `1234567890${start + idx + 1}` : `0987654321${start + idx + 1}`,
78
+ company:
79
+ idx % 2
80
+ ? {
81
+ id: '2',
82
+ name: 'HatioLAB',
83
+ description: `경기도 성남시-${start + idx + 1}`
84
+ }
85
+ : {
86
+ id: '3',
87
+ name: 'HatioSEA',
88
+ description: `말레이시아 세티아알람-${start + idx + 1}`
89
+ },
90
+ thumbnail:
91
+ idx % 4 === 0
92
+ ? '' /* no source */
93
+ : idx % 4 === 1
94
+ ? `http://www.hatiolab.com/assets/img/operato-biz3.png`
95
+ : idx % 4 === 2
96
+ ? `http://www.hatiolab.com/assets/img/thingsboard-30.png`
97
+ : `http://www.hatiolab.com/wrong-url.png` /* wrong source */,
98
+ role: ['admin', 'worker', 'tester'][idx % 3],
99
+ color: idx % 2 ? `#87f018` : `#180f87`,
100
+ rate: Math.round(Math.random() * 100),
101
+ dynamicType: ['text', 'email', 'checkbox', 'color', 'progress', 'barcode'][idx % 5],
102
+ dynamicValue: ['abcdefghijkl', 'heartyoh@hatiolab.com', 'true', 'orange', '50', '1234567890'][idx % 5],
103
+ homepage:
104
+ idx % 2
105
+ ? `http://hatiolab.com/${start + idx + 1}`
106
+ : `http://deadpool.hatiolab.com/${start + idx + 1}`,
107
+ json5: {
108
+ abc: 'abc',
109
+ value: 123
110
+ },
111
+ createdAt: Date.now(),
112
+ updatedAt: Date.now()
113
+ }
114
+ })
115
+ }
116
+ }
117
+
118
+ const config = {
119
+ list: {
120
+ thumbnail: 'thumbnail',
121
+ fields: ['name', 'description'],
122
+ details: ['role', 'email']
123
+ },
124
+ columns: [
125
+ {
126
+ type: 'gutter',
127
+ gutterName: 'dirty'
128
+ },
129
+ {
130
+ type: 'gutter',
131
+ gutterName: 'sequence'
132
+ },
133
+ {
134
+ type: 'gutter',
135
+ gutterName: 'row-selector',
136
+ multiple: true
137
+ },
138
+ {
139
+ type: 'gutter',
140
+ gutterName: 'button',
141
+ icon: 'edit',
142
+ handlers: {
143
+ click: function () {
144
+ console.log('clicked')
145
+ }
146
+ }
147
+ },
148
+ {
149
+ type: 'gutter',
150
+ gutterName: 'button',
151
+ icon: 'add',
152
+ handlers: {
153
+ click: 'record-copy'
154
+ }
155
+ },
156
+ {
157
+ type: 'gutter',
158
+ gutterName: 'button',
159
+ icon: 'arrow_downward',
160
+ handlers: {
161
+ click: 'move-down'
162
+ }
163
+ },
164
+ {
165
+ type: 'string',
166
+ name: 'id',
167
+ hidden: true
168
+ },
169
+ {
170
+ type: 'link',
171
+ name: 'name',
172
+ label: true,
173
+ header: 'name',
174
+ record: {
175
+ editable: true,
176
+ options: {
177
+ // href: 'http://hatiolab.com',
178
+ href: function (column, record, rowIndex) {
179
+ return record['homepage']
180
+ },
181
+ target: '_blank'
182
+ }
183
+ },
184
+ filter: 'search',
185
+ sortable: true,
186
+ width: 120
187
+ },
188
+ {
189
+ type: 'string',
190
+ name: 'description',
191
+ header: 'description',
192
+ filter: 'search',
193
+ record: {
194
+ editable: true,
195
+ align: 'left'
196
+ },
197
+ width: 200,
198
+ handlers: {
199
+ click: (columns, data, column, record, rowIndex, target) => {
200
+ alert(`${column.name} ${record[column.name]}, row : ${rowIndex}`)
201
+ }
202
+ }
203
+ },
204
+ {
205
+ type: 'email',
206
+ name: 'email',
207
+ label: true,
208
+ header: 'email',
209
+ record: {
210
+ editable: true
211
+ },
212
+ filter: 'search',
213
+ sortable: true,
214
+ width: 130,
215
+ validation: function (after, before, record, column) {
216
+ if (after.indexOf('@') == -1) {
217
+ document.dispatchEvent(
218
+ new CustomEvent('notify', {
219
+ detail: {
220
+ type: 'error',
221
+ message: `invalid value - ${after}`
222
+ }
223
+ })
224
+ )
225
+ return false
226
+ }
227
+ return true
228
+ }
229
+ },
230
+ {
231
+ type: 'boolean',
232
+ name: 'active',
233
+ header: 'active',
234
+ record: {
235
+ editable: true
236
+ },
237
+ filter: true,
238
+ handlers: {
239
+ dblclick: () => {
240
+ const grist = document.querySelector('ox-grist')
241
+ console.log(grist.dirtyRecords)
242
+ }
243
+ },
244
+ sortable: true,
245
+ width: 60
246
+ },
247
+ {
248
+ type: 'select',
249
+ name: 'role',
250
+ label: true,
251
+ header: 'role',
252
+ record: {
253
+ options: ['', 'admin', 'worker', 'tester'],
254
+ editable: true
255
+ },
256
+ filter: true,
257
+ sortable: true,
258
+ width: 120
259
+ },
260
+ {
261
+ type: 'color',
262
+ name: 'color',
263
+ header: 'color',
264
+ record: {
265
+ editable: true
266
+ },
267
+ sortable: true,
268
+ width: 50
269
+ },
270
+ {
271
+ type: 'float',
272
+ name: 'rate',
273
+ header: 'rate',
274
+ record: {
275
+ align: 'right',
276
+ editable: true
277
+ },
278
+ filter: 'between',
279
+ sortable: true,
280
+ width: 50
281
+ },
282
+ {
283
+ type: 'json5',
284
+ name: 'json5',
285
+ header: 'JSON5',
286
+ width: 200
287
+ },
288
+ {
289
+ type: 'image',
290
+ name: 'thumbnail',
291
+ header: 'thumbnail',
292
+ record: {
293
+ editable: true
294
+ }
295
+ },
296
+ {
297
+ type: 'datetime',
298
+ name: 'updatedAt',
299
+ header: 'updated at',
300
+ record: {
301
+ editable: true
302
+ },
303
+ filter: 'between',
304
+ sortable: true,
305
+ width: 180
306
+ },
307
+ {
308
+ type: 'datetime',
309
+ name: 'createdAt',
310
+ header: 'created at',
311
+ record: {
312
+ editable: false
313
+ },
314
+ sortable: true,
315
+ width: 180
316
+ }
317
+ ],
318
+ rows: {
319
+ selectable: {
320
+ multiple: true
321
+ },
322
+ handlers: {
323
+ click: 'select-row-toggle'
324
+ },
325
+ classifier: function (record, rowIndex) {
326
+ const rate = record['rate']
327
+ const emphasized =
328
+ rate < 10 ? ['black', 'white'] : rate < 25 ? ['yellow', 'blue'] : rate < 40 ? ['cyan', 'red'] : undefined
329
+ return {
330
+ emphasized
331
+ }
332
+ }
333
+ },
334
+ sorters: [
335
+ {
336
+ name: 'name',
337
+ desc: true
338
+ },
339
+ {
340
+ name: 'email'
341
+ }
342
+ ],
343
+ pagination: {
344
+ pages: [20, 30, 50, 100, 200]
345
+ }
346
+ }
347
+
348
+ class GristDemo extends LitElement {
349
+ static styles = [
350
+ CommonGristStyles,
351
+ css`
352
+ :host {
353
+ display: flex;
354
+ flex-direction: column;
355
+ }
356
+
357
+ #tailer {
358
+ display: flex;
359
+ flex-direction: row;
360
+ margin: 0 var(--margin-default);
361
+ }
362
+
363
+ #tailer a {
364
+ padding: 0 var(--padding-default) 0 var(--padding-default);
365
+ margin: 0 var(--margin-narrow);
366
+ border-right: 1px solid rgba(0, 0, 0, 0.1);
367
+ font-size: var(--fontsize-default);
368
+ color: var(--primary-color);
369
+ }
370
+ `
371
+ ]
372
+
373
+ static get properties() {
374
+ return {
375
+ mode: String
376
+ }
377
+ }
378
+
379
+ get grist() {
380
+ return this.renderRoot.querySelector('ox-grist')
381
+ }
382
+
383
+ render() {
384
+ const mode = this.mode || 'CARD'
385
+
386
+ return html`
387
+ <ox-grist .config=${config} .mode=${mode} auto-fetch .fetchHandler=${fetchHandler}>
388
+ <div id="filters" slot="headroom">
389
+ <ox-filters-form @filters-change=${e => console.log('changed', e.detail)}></ox-filters-form>
390
+ </div>
391
+
392
+ <div slot="headroom" id="headroom">
393
+ <div id="tailer">
394
+ <a href="./report-test.html">Report Test</a>
395
+ <a
396
+ href="#"
397
+ @click=${() => {
398
+ this.renderRoot.querySelector('ox-grist').reset()
399
+ }}
400
+ >Reset</a
401
+ >
402
+ <a
403
+ href="#"
404
+ @click=${() => {
405
+ this.renderRoot.querySelector('ox-grist').fetch(true)
406
+ }}
407
+ >Fetch</a
408
+ >
409
+ </div>
410
+
411
+ <div id="sorters">
412
+ Sort
413
+ <mwc-icon
414
+ @click=${e => {
415
+ const target = e.currentTarget
416
+ this.renderRoot.querySelector('#sorter-control').open({
417
+ right: 0,
418
+ top: target.offsetTop + target.offsetHeight
419
+ })
420
+ }}
421
+ >expand_more</mwc-icon
422
+ >
423
+ <ox-popup id="sorter-control">
424
+ <ox-sorters-control> </ox-sorters-control>
425
+ </ox-popup>
426
+ </div>
427
+
428
+ <div id="modes">
429
+ <mwc-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>view_list</mwc-icon>
430
+ <mwc-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>menu</mwc-icon>
431
+ <mwc-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</mwc-icon>
432
+ </div>
433
+
434
+ <ox-record-creator id="add" light-popup>
435
+ <button><mwc-icon>add</mwc-icon></button>
436
+ </ox-record-creator>
437
+
438
+ <button @click=${e => this.grist.cloneSelectedRecords()}><mwc-icon>add</mwc-icon></button>
439
+ </div>
440
+ </ox-grist>
441
+ `
442
+ }
443
+ }
444
+
445
+ customElements.define('grist-demo', GristDemo)
446
+
447
+ setTimeout(() => {
448
+ render(html` <grist-demo mode="LIST"></grist-demo> `, document.querySelector('#demo'))
449
+ })
450
+ </script>
451
+
452
+ <div id="app">
453
+ <div id="demo"></div>
454
+ </div>
455
+ </body>
456
+ </html>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <style>
6
+ body {
7
+ background: #fafafa;
8
+ --ox-checkbox-size: 12px;
9
+ }
10
+
11
+ #demo {
12
+ position: relative;
13
+ height: 300px;
14
+ background-color: lightgray;
15
+ vertical-align: middle;
16
+ }
17
+ </style>
18
+ <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
19
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
20
+ </head>
21
+ <body>
22
+ <div id="demo"></div>
23
+
24
+ <script type="module">
25
+ import { html, render } from 'lit'
26
+ import '@material/mwc-icon'
27
+
28
+ const parent = document.querySelector('#demo')
29
+
30
+ render(html``, parent)
31
+ </script>
32
+ </body>
33
+ </html>
@@ -0,0 +1,6 @@
1
+ import '@material/mwc-icon';
2
+ import { InputEditor } from '@operato/data-grist';
3
+ export declare class CodeEditor extends InputEditor {
4
+ firstUpdated(): Promise<void>;
5
+ get editorTemplate(): import("lit-html").TemplateResult<1>;
6
+ }
@@ -0,0 +1,50 @@
1
+ import '@material/mwc-icon';
2
+ import { InputEditor } from '@operato/data-grist';
3
+ import { client, gqlContext } from '@operato/graphql';
4
+ import gql from 'graphql-tag';
5
+ import { html } from 'lit';
6
+ const FETCH_COMMON_CODE_GQL = (codeName) => gql `
7
+ {
8
+ commonCode(name: "${codeName}") {
9
+ details {
10
+ name
11
+ description
12
+ rank
13
+ }
14
+ }
15
+ }
16
+ `;
17
+ export class CodeEditor extends InputEditor {
18
+ async firstUpdated() {
19
+ super.firstUpdated();
20
+ var { codeName, codes } = this.column.record || {};
21
+ if (!codes && codeName) {
22
+ /* codeName으로 fetch 해와서, this.column.record.codes에 보관한다. */
23
+ var response = await client.query({
24
+ query: FETCH_COMMON_CODE_GQL(codeName),
25
+ context: gqlContext()
26
+ });
27
+ var commonCode = response && response.data && response.data.commonCode;
28
+ if (commonCode) {
29
+ this.column.record.codes = [{ name: '', description: '' }].concat(commonCode.details.sort(function (a, b) {
30
+ return a.rank - b.rank;
31
+ }));
32
+ this.requestUpdate();
33
+ }
34
+ }
35
+ }
36
+ get editorTemplate() {
37
+ var { codes } = this.column.record || {};
38
+ return html `
39
+ <select>
40
+ ${(codes || ['']).map((code) => html `
41
+ <option ?selected=${code.name == this.value} value=${code.name}>
42
+ ${code.name}${code.description ? ` - ${code.description}` : ''}
43
+ </option>
44
+ `)}
45
+ </select>
46
+ `;
47
+ }
48
+ }
49
+ customElements.define('code-editor', CodeEditor);
50
+ //# sourceMappingURL=code-editor.js.map