@operato/scene-grist 7.3.14 → 7.3.19

Sign up to get free protection for your applications and to get access to all the features.
package/src/grist.ts DELETED
@@ -1,369 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import 'ses'
6
- import '@operato/data-grist/ox-grist.js'
7
- import '@operato/data-grist/ox-filters-form.js'
8
-
9
- import { Component, ComponentNature, error, HTMLOverlayElement, Properties } from '@hatiolab/things-scene'
10
- import { DataGrist, FetchResult } from '@operato/data-grist'
11
- import { i18next as _i18next } from '@operato/i18n'
12
- import { FetchOption } from '@operato/data-grist/dist/src/types'
13
-
14
- const NATURE: ComponentNature = {
15
- mutable: false,
16
- resizable: true,
17
- rotatable: true,
18
- properties: [
19
- {
20
- type: 'select',
21
- label: 'grist-mode',
22
- name: 'mode',
23
- property: {
24
- options: [
25
- {
26
- display: 'Grid',
27
- value: 'GRID'
28
- },
29
- {
30
- display: 'List',
31
- value: 'LIST'
32
- },
33
- {
34
- display: 'Card',
35
- value: 'CARD'
36
- },
37
- {
38
- display: 'Depends on device',
39
- value: 'DEVICE'
40
- }
41
- ]
42
- }
43
- },
44
- {
45
- type: 'textarea',
46
- label: 'config',
47
- name: 'config'
48
- },
49
- {
50
- type: 'checkbox',
51
- label: 'filterable',
52
- name: 'filterable'
53
- },
54
- {
55
- type: 'checkbox',
56
- label: 'appendable',
57
- name: 'appendable'
58
- },
59
- {
60
- type: 'checkbox',
61
- label: 'paginatable',
62
- name: 'paginatable'
63
- },
64
- {
65
- type: 'number',
66
- label: 'content-scale',
67
- name: 'contentScale',
68
- property: {
69
- step: 0.1,
70
- min: 0.1
71
- }
72
- },
73
- {
74
- type: 'number',
75
- label: 'row-padding',
76
- name: 'rowPadding',
77
- property: {
78
- step: 1,
79
- min: 2
80
- }
81
- },
82
- {
83
- type: 'select',
84
- label: 'bound-data',
85
- name: 'boundData',
86
- property: {
87
- options: [
88
- {
89
- display: '',
90
- value: ''
91
- },
92
- {
93
- display: 'Focused Row',
94
- value: 'focused-row'
95
- },
96
- {
97
- display: 'Selected Rows',
98
- value: 'selected-rows'
99
- }
100
- ]
101
- }
102
- }
103
- ],
104
- help: 'scene/component/grist'
105
- }
106
-
107
- const isMobileDevice = () => false
108
-
109
- export default class SceneGrist extends HTMLOverlayElement {
110
- public beforeFetchFuncs: any = {}
111
-
112
- private __value: any = {}
113
- private _listenTo?: any
114
- private _listener?: any
115
-
116
- public grist?: DataGrist
117
-
118
- get nature() {
119
- return NATURE
120
- }
121
-
122
- ready() {
123
- super.ready()
124
-
125
- if (this.rootModel) {
126
- this._listenTo = this.rootModel
127
- this._listener = function (this: SceneGrist, after: Properties) {
128
- after.scale && this.rescale()
129
- }.bind(this)
130
- this.rootModel.on('change', this._listener)
131
- }
132
- }
133
-
134
- removed() {
135
- if (this._listenTo) {
136
- this._listenTo.off('change', this._listener)
137
-
138
- delete this._listenTo
139
- delete this._listener
140
- }
141
- }
142
-
143
- createElement() {
144
- super.createElement()
145
-
146
- this.grist = document.createElement('ox-grist') as DataGrist
147
- this.element.appendChild(this.grist)
148
-
149
- this.rescale()
150
-
151
- const grist = this.grist
152
-
153
- this.setGristConfig(grist)
154
-
155
- grist.fetchHandler = async ({
156
- page,
157
- limit,
158
- sorters,
159
- sortings,
160
- filters,
161
- inherited,
162
- options
163
- }: FetchOption): Promise<FetchResult> => {
164
- Object.values(this.beforeFetchFuncs).forEach((func: any) =>
165
- func({ page, limit, sorters, sortings, filters, inherited, options })
166
- )
167
- var { total = 0, records = [] } = grist.data || {}
168
-
169
- return {
170
- page,
171
- limit,
172
- total,
173
- records
174
- }
175
- }
176
-
177
- grist.addEventListener('select-record-change', e => {
178
- if (this.state.boundData === 'selected-rows') {
179
- this.data = (e.target as DataGrist)?.selected || []
180
- }
181
- })
182
-
183
- grist.addEventListener('select-all-change', e => {
184
- if (this.state.boundData === 'selected-rows') {
185
- this.data = (e.target as DataGrist)?.selected || []
186
- }
187
- })
188
-
189
- grist.addEventListener('focus-change', (e: Event) => {
190
- if (this.state.boundData === 'focused-row') {
191
- this.data = ((e.target as DataGrist)?.data?.records || [])[(e as CustomEvent).detail.row]
192
- }
193
- })
194
- }
195
-
196
- get value() {
197
- return this.__value
198
- }
199
-
200
- set value(value) {
201
- this.__value = value
202
- if (!this.grist || typeof value !== 'object') return
203
-
204
- var { page, limit } = this.config.pagination || {}
205
-
206
- this.grist.data =
207
- value instanceof Array
208
- ? {
209
- page,
210
- limit,
211
- ...this.grist._data,
212
- total: value.length,
213
- records: Array.from(value)
214
- }
215
- : {
216
- page,
217
- limit,
218
- ...this.grist._data,
219
- ...value
220
- }
221
- }
222
-
223
- onchange(after: Properties, before: Properties) {
224
- super.onchange(after, before)
225
-
226
- if (
227
- 'mode' in after ||
228
- 'filterable' in after ||
229
- 'appendable' in after ||
230
- 'paginatable' in after ||
231
- 'config' in after
232
- ) {
233
- this.setGristConfig(this.grist)
234
- }
235
-
236
- this.rescale()
237
- }
238
-
239
- dispose() {
240
- super.dispose()
241
-
242
- delete this.grist
243
- }
244
-
245
- /*
246
- * 컴포넌트의 생성 또는 속성 변화 시에 호출되며,
247
- * 그에 따른 html element의 반영이 필요한 부분을 구현한다.
248
- *
249
- * ThingsComponent state => HTML element properties
250
- */
251
- setElementProperties(grist: DataGrist) {
252
- this.rescale()
253
- }
254
-
255
- setGristConfig(grist: DataGrist | undefined) {
256
- if (!grist) {
257
- return
258
- }
259
-
260
- var { mode, filterable } = this.state
261
-
262
- if (mode != 'DEVICE') {
263
- grist.mode = mode
264
- } else {
265
- grist.mode = isMobileDevice() ? 'LIST' : 'GRID'
266
- }
267
-
268
- grist.config = this.config
269
-
270
- grist.innerHTML = filterable
271
- ? `
272
- <div slot="headroom">
273
- <div style="padding: 9px 9px 0px 9px;">
274
- <ox-filters-form autofocus></ox-filters-form>
275
- </div>
276
- </div>
277
- `
278
- : ''
279
- }
280
-
281
- /*
282
- * 컴포넌트가 ready 상태가 되거나, 컴포넌트의 속성이 변화될 시 setElementProperties 뒤에 호출된다.
283
- * 변화에 따른 기본적인 html 속성이 super.reposition()에서 진행되고, 그 밖의 작업이 필요할 때, 오버라이드 한다.
284
- */
285
- reposition() {
286
- const { fillStyle, rowPadding } = this.state
287
-
288
- if (!fillStyle) {
289
- this.grist?.style.setProperty('--grist-background-color', 'var(--md-sys-color-surface, #f7f6f4)')
290
- } else {
291
- this.grist?.style.removeProperty('--grist-background-color')
292
- }
293
-
294
- if (rowPadding) {
295
- this.grist?.style.setProperty('--grid-record-padding', `${rowPadding}px var(--spacing-medium)`)
296
- } else {
297
- this.grist?.style.setProperty('--grid-record-padding', 'var(--spacing-small) var(--spacing-medium)')
298
- }
299
-
300
- super.reposition()
301
- }
302
-
303
- /*
304
- * grist는 부모의 스케일의 역으로 transform해서, scale을 1로 맞춘다.
305
- */
306
- rescale() {
307
- var grist = this.grist
308
- if (!grist) {
309
- return
310
- }
311
-
312
- const scale = this.getState('contentScale') || 1
313
-
314
- const sx = scale
315
- const sy = scale
316
-
317
- const transform = `scale(${sx}, ${sy})`
318
-
319
- ;['-webkit-', '-moz-', '-ms-', '-o-', ''].forEach((prefix: string) => {
320
- grist!.style.setProperty(prefix + 'transform', transform)
321
- grist!.style.setProperty(prefix + 'transform-origin', '0px 0px')
322
- })
323
-
324
- const { width, height } = this.state
325
- grist.style.width = Math.round(width / scale) + 'px'
326
- grist.style.height = Math.round(height / scale) + 'px'
327
- }
328
-
329
- get config() {
330
- var { config, appendable, paginatable } = this.state
331
-
332
- if (typeof config !== 'object') {
333
- try {
334
- const c = new Compartment({
335
- t: _i18next.t,
336
- i18next: _i18next
337
- })
338
-
339
- config = c.evaluate(`(${config})`)
340
- } catch (e) {
341
- error(e)
342
- }
343
- }
344
-
345
- if (paginatable) {
346
- if (config.pagination && !config.pagination.limit && config.pagination.pages && config.pagination.pages.length) {
347
- config.pagination.limit = config.pagination.pages[0]
348
- }
349
- }
350
-
351
- config.pagination = {
352
- ...config.pagination,
353
- infinite: !paginatable
354
- }
355
-
356
- config.rows = {
357
- ...config.rows,
358
- appendable: !!appendable
359
- }
360
-
361
- return config
362
- }
363
-
364
- get tagName() {
365
- return 'div'
366
- }
367
- }
368
-
369
- Component.register('grist', SceneGrist)
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import Grist from './grist'
2
- import GristAction from './grist-action'
3
-
4
- export default [Grist, GristAction]
@@ -1,20 +0,0 @@
1
- import { ACTIONS } from '../grist-action'
2
-
3
- const icon = new URL('../../icons/grist-action.png', import.meta.url).href
4
-
5
- export default {
6
- type: 'grist-action',
7
- description: 'grist-action',
8
- group: 'table',
9
- /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
10
- icon,
11
- model: {
12
- type: 'grist-action',
13
- left: 10,
14
- top: 10,
15
- width: 100,
16
- height: 100,
17
- strokeStyle: 'darkgray',
18
- action: ACTIONS.GET_SELECTED
19
- }
20
- }
@@ -1,98 +0,0 @@
1
- const icon = new URL('../../icons/grist.png', import.meta.url).href
2
-
3
- export default {
4
- type: 'grist',
5
- description: 'grist',
6
- group: 'table',
7
- /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
8
- icon,
9
- model: {
10
- type: 'grist',
11
- left: 10,
12
- top: 10,
13
- width: 400,
14
- height: 300,
15
- mode: 'GRID',
16
- config: `{
17
- columns: [
18
- {
19
- type: 'gutter',
20
- gutterName: 'dirty'
21
- },
22
- {
23
- type: 'gutter',
24
- gutterName: 'sequence'
25
- },
26
- {
27
- type: 'gutter',
28
- gutterName: 'row-selector',
29
- multiple: true
30
- },
31
- {
32
- type: 'string',
33
- name: 'id',
34
- hidden: true
35
- },
36
- {
37
- type: 'string',
38
- name: 'name',
39
- header: 'name',
40
- record: {
41
- editable: true
42
- },
43
- sortable: true,
44
- width: 120
45
- },
46
- {
47
- type: 'string',
48
- name: 'description',
49
- header: 'description',
50
- record: {
51
- align: 'left',
52
- editable: true
53
- },
54
- width: 200
55
- },
56
- {
57
- type: 'boolean',
58
- name: 'active',
59
- header: 'active',
60
- record: {
61
- editable: true
62
- },
63
- sortable: true,
64
- width: 60
65
- },
66
- {
67
- type: 'datetime',
68
- name: 'updatedAt',
69
- header: 'updated at',
70
- width: 180
71
- },
72
- {
73
- type: 'datetime',
74
- name: 'createdAt',
75
- header: 'created at',
76
- width: 180
77
- }
78
- ],
79
- rows: {
80
- selectable: {
81
- multiple: true
82
- },
83
- handlers: {
84
- click: 'select-row-toggle'
85
- }
86
- },
87
- sorters: [
88
- {
89
- name: 'name',
90
- desc: true
91
- }
92
- ],
93
- pagination: {
94
- pages: [20, 30, 50, 100, 200]
95
- }
96
- }`
97
- }
98
- }
@@ -1,4 +0,0 @@
1
- import grist from './grist'
2
- import gristAction from './grist-action'
3
-
4
- export default [grist, gristAction]
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
- "noEmitOnError": true,
7
- "lib": ["es2019", "dom"],
8
- "strict": true,
9
- "esModuleInterop": false,
10
- "allowJs": true,
11
- "allowSyntheticDefaultImports": true,
12
- "experimentalDecorators": true,
13
- "importHelpers": true,
14
- "outDir": "dist",
15
- "sourceMap": true,
16
- "inlineSources": true,
17
- "rootDir": "src",
18
- "declaration": true,
19
- "incremental": true,
20
- "skipLibCheck": true
21
- },
22
- "include": ["**/*.ts", "*.d.ts", "**/data-grist.d.ts"]
23
- }