@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.
- package/.editorconfig +29 -0
- package/.storybook/main.js +3 -0
- package/.storybook/server.mjs +8 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/demo/data-grist-test.html +456 -0
- package/demo/index.html +33 -0
- package/dist/src/code/code-editor.d.ts +6 -0
- package/dist/src/code/code-editor.js +50 -0
- package/dist/src/code/code-editor.js.map +1 -0
- package/dist/src/code/index.d.ts +1 -0
- package/dist/src/code/index.js +5 -0
- package/dist/src/code/index.js.map +1 -0
- package/dist/src/id/id-input.d.ts +19 -0
- package/dist/src/id/id-input.js +119 -0
- package/dist/src/id/id-input.js.map +1 -0
- package/dist/src/id/id-renderer.d.ts +2 -0
- package/dist/src/id/id-renderer.js +9 -0
- package/dist/src/id/id-renderer.js.map +1 -0
- package/dist/src/id/id-selector.d.ts +23 -0
- package/dist/src/id/id-selector.js +197 -0
- package/dist/src/id/id-selector.js.map +1 -0
- package/dist/src/id/index.d.ts +1 -0
- package/dist/src/id/index.js +7 -0
- package/dist/src/id/index.js.map +1 -0
- package/dist/src/index.d.ts +0 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/object/index.d.ts +1 -0
- package/dist/src/object/index.js +6 -0
- package/dist/src/object/index.js.map +1 -0
- package/dist/src/object/object-editor.d.ts +18 -0
- package/dist/src/object/object-editor.js +152 -0
- package/dist/src/object/object-editor.js.map +1 -0
- package/dist/src/object/object-selector.d.ts +38 -0
- package/dist/src/object/object-selector.js +338 -0
- package/dist/src/object/object-selector.js.map +1 -0
- package/dist/src/parameters/index.d.ts +1 -0
- package/dist/src/parameters/index.js +6 -0
- package/dist/src/parameters/index.js.map +1 -0
- package/dist/src/parameters/parameters-editor-builder.d.ts +4 -0
- package/dist/src/parameters/parameters-editor-builder.js +119 -0
- package/dist/src/parameters/parameters-editor-builder.js.map +1 -0
- package/dist/src/parameters/parameters-editor-popup.d.ts +13 -0
- package/dist/src/parameters/parameters-editor-popup.js +111 -0
- package/dist/src/parameters/parameters-editor-popup.js.map +1 -0
- package/dist/src/parameters/parameters-editor.d.ts +18 -0
- package/dist/src/parameters/parameters-editor.js +106 -0
- package/dist/src/parameters/parameters-editor.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +87 -0
- package/src/code/code-editor.ts +78 -0
- package/src/code/index.ts +6 -0
- package/src/id/id-input.ts +135 -0
- package/src/id/id-renderer.ts +12 -0
- package/src/id/id-selector.ts +189 -0
- package/src/id/index.ts +8 -0
- package/src/index.ts +0 -0
- package/src/object/index.ts +8 -0
- package/src/object/object-editor.ts +162 -0
- package/src/object/object-selector.ts +346 -0
- package/src/parameters/index.ts +8 -0
- package/src/parameters/parameters-editor-builder.ts +130 -0
- package/src/parameters/parameters-editor-popup.ts +106 -0
- package/src/parameters/parameters-editor.ts +112 -0
- package/tsconfig.json +23 -0
- package/web-dev-server.config.mjs +27 -0
- package/web-test-runner.config.mjs +41 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import '@operato/data-grist'
|
|
2
|
+
import '@operato/form/ox-search-form.js'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ColumnConfig,
|
|
6
|
+
DataGrist,
|
|
7
|
+
FetchHandler,
|
|
8
|
+
FetchOption,
|
|
9
|
+
GristData,
|
|
10
|
+
GristEventHandler,
|
|
11
|
+
GristRecord,
|
|
12
|
+
ZERO_DATA
|
|
13
|
+
} from '@operato/data-grist'
|
|
14
|
+
import { LitElement, css, html } from 'lit'
|
|
15
|
+
import { MultiColumnFormStyles, SearchForm } from '@operato/form'
|
|
16
|
+
import { buildArgs, client, gqlContext } from '@operato/graphql'
|
|
17
|
+
import { customElement, property, query } from 'lit/decorators.js'
|
|
18
|
+
|
|
19
|
+
import gql from 'graphql-tag'
|
|
20
|
+
import { i18next } from '@operato/i18n'
|
|
21
|
+
import { isMobileDevice } from '@operato/utils'
|
|
22
|
+
|
|
23
|
+
@customElement('ox-object-selector')
|
|
24
|
+
export class ObjectSelector extends LitElement {
|
|
25
|
+
static styles = [
|
|
26
|
+
MultiColumnFormStyles,
|
|
27
|
+
css`
|
|
28
|
+
:host {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
|
|
32
|
+
background-color: #fff;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
data-grist {
|
|
36
|
+
flex: 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.button-container {
|
|
40
|
+
display: flex;
|
|
41
|
+
margin-left: auto;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
form {
|
|
45
|
+
position: relative;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
[search] {
|
|
49
|
+
position: absolute;
|
|
50
|
+
right: 0;
|
|
51
|
+
}
|
|
52
|
+
`
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
@property({ type: String }) value?: string
|
|
56
|
+
@property({ type: Object }) config: any
|
|
57
|
+
@property({ type: Object }) data: GristData = ZERO_DATA
|
|
58
|
+
@property({ type: String }) queryName!: string
|
|
59
|
+
@property({ type: Object }) basicArgs: any
|
|
60
|
+
@property({ type: Object }) confirmCallback?: (record: GristRecord | undefined) => void
|
|
61
|
+
@property({ type: Array }) selectedRecords: GristRecord[] = []
|
|
62
|
+
|
|
63
|
+
@property({ type: Array }) searchFields: any
|
|
64
|
+
@property({ type: Array }) select: {
|
|
65
|
+
type: string
|
|
66
|
+
name: string
|
|
67
|
+
header: string
|
|
68
|
+
subFields?: string[]
|
|
69
|
+
hidden: boolean
|
|
70
|
+
ignoreCondition: boolean
|
|
71
|
+
queryName: string
|
|
72
|
+
width: number
|
|
73
|
+
}[] = []
|
|
74
|
+
@property({ type: Object }) list: any
|
|
75
|
+
@property({ type: String }) valueField: string | ((item: any) => any) = 'id'
|
|
76
|
+
|
|
77
|
+
@query('ox-grist') grist!: DataGrist
|
|
78
|
+
@query('ox-search-form') searchForm!: SearchForm
|
|
79
|
+
|
|
80
|
+
render() {
|
|
81
|
+
return html`
|
|
82
|
+
<ox-search-form
|
|
83
|
+
id="search-form"
|
|
84
|
+
@keypress=${(e: KeyboardEvent) => {
|
|
85
|
+
if (e.keyCode === 13) {
|
|
86
|
+
this.grist.fetch()
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
@submit=${(e: SubmitEvent) => this.grist.fetch()}
|
|
90
|
+
.fields=${this.searchFields}
|
|
91
|
+
></ox-search-form>
|
|
92
|
+
|
|
93
|
+
<ox-grist
|
|
94
|
+
.mode=${isMobileDevice() ? 'LIST' : 'GRID'}
|
|
95
|
+
.config=${this.config}
|
|
96
|
+
.data=${this.data}
|
|
97
|
+
.fetchHandler=${this.fetchHandler.bind(this)}
|
|
98
|
+
.selectedRecords=${this.selectedRecords}
|
|
99
|
+
></ox-grist>
|
|
100
|
+
|
|
101
|
+
<div class="button-container">
|
|
102
|
+
<mwc-button @click=${this.oncancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
|
|
103
|
+
<mwc-button @click=${this.onconfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
|
|
104
|
+
</div>
|
|
105
|
+
`
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
oncancel() {
|
|
109
|
+
history.back()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
onconfirm() {
|
|
113
|
+
this.confirmCallback && this.confirmCallback(this.selected)
|
|
114
|
+
history.back()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fetchHandler: FetchHandler = async ({ filters, page, limit, sorters = [] }) => {
|
|
118
|
+
const response = await client.query({
|
|
119
|
+
query: gql`
|
|
120
|
+
query {
|
|
121
|
+
fetch: ${this.queryName} (${buildArgs(await this._buildConditions({ filters, page, limit, sorters }))}) {
|
|
122
|
+
${this.getSelectFields()}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`,
|
|
126
|
+
context: gqlContext()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
if (!response.errors) {
|
|
130
|
+
const records = response.data.fetch.items.map((item: any) => {
|
|
131
|
+
let rowValue
|
|
132
|
+
|
|
133
|
+
if (this.valueField && typeof this.valueField === 'function') {
|
|
134
|
+
rowValue = this.valueField(item)
|
|
135
|
+
} else if (this.valueField) {
|
|
136
|
+
rowValue = item[this.valueField]
|
|
137
|
+
} else {
|
|
138
|
+
rowValue = item.id
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (this.value && this.value === rowValue) {
|
|
142
|
+
this.selectedRecords = [item]
|
|
143
|
+
item['__selected__'] = true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return item
|
|
147
|
+
})
|
|
148
|
+
const total = response.data.fetch.total
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
records,
|
|
152
|
+
total,
|
|
153
|
+
limit,
|
|
154
|
+
page
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async firstUpdated() {
|
|
160
|
+
this.config = {
|
|
161
|
+
columns: [
|
|
162
|
+
{
|
|
163
|
+
type: 'gutter',
|
|
164
|
+
gutterName: 'sequence'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
type: 'gutter',
|
|
168
|
+
gutterName: 'row-selector',
|
|
169
|
+
multiple: false
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
rows: {
|
|
173
|
+
selectable: {
|
|
174
|
+
multiple: false
|
|
175
|
+
},
|
|
176
|
+
handlers: {
|
|
177
|
+
click: 'select-row',
|
|
178
|
+
dblclick: ((columns, data, column, record, rowIndex, field) => {
|
|
179
|
+
this.onconfirm()
|
|
180
|
+
}) as GristEventHandler
|
|
181
|
+
},
|
|
182
|
+
appendable: false
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (this.select && this.select.length > 0) {
|
|
187
|
+
let _searchFields = this.select.filter(selectField => !selectField.hidden && !selectField.ignoreCondition)
|
|
188
|
+
if (this.list && this.list.fields && this.list.fields.length > 0) {
|
|
189
|
+
_searchFields = _searchFields.filter(searchField => this.list.fields.indexOf(searchField.name) >= 0)
|
|
190
|
+
} else {
|
|
191
|
+
_searchFields = _searchFields.slice(0, 4)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.searchFields = _searchFields.map(selectField => {
|
|
195
|
+
const fieldType = (selectField.type && selectField.type.toLowerCase()) || 'string'
|
|
196
|
+
const numberTypes = ['integer', 'float']
|
|
197
|
+
return {
|
|
198
|
+
label: selectField.header || i18next.t(`field.${selectField.name}`),
|
|
199
|
+
name: selectField.name,
|
|
200
|
+
type:
|
|
201
|
+
fieldType === 'string'
|
|
202
|
+
? 'text'
|
|
203
|
+
: numberTypes.indexOf(fieldType) >= 0
|
|
204
|
+
? 'number'
|
|
205
|
+
: fieldType === 'boolean'
|
|
206
|
+
? 'checkbox'
|
|
207
|
+
: fieldType,
|
|
208
|
+
queryName: selectField.queryName,
|
|
209
|
+
props:
|
|
210
|
+
fieldType === 'string'
|
|
211
|
+
? { searchOper: 'i_like' }
|
|
212
|
+
: fieldType === 'object'
|
|
213
|
+
? { searchOper: 'in' }
|
|
214
|
+
: { searchOper: 'eq' },
|
|
215
|
+
attrs: fieldType === 'boolean' ? ['indeterminated'] : []
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
this.config = {
|
|
219
|
+
...this.config,
|
|
220
|
+
columns: [
|
|
221
|
+
...this.config.columns,
|
|
222
|
+
...this.select.map(selectField => {
|
|
223
|
+
return {
|
|
224
|
+
...selectField,
|
|
225
|
+
type: selectField.type || 'string',
|
|
226
|
+
width: selectField.width || 160,
|
|
227
|
+
header: selectField.header || i18next.t(`field.${selectField.name}`)
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
this.searchFields = [
|
|
234
|
+
{
|
|
235
|
+
label: i18next.t('field.name'),
|
|
236
|
+
name: 'name',
|
|
237
|
+
type: 'text',
|
|
238
|
+
props: { searchOper: 'i_like' }
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
label: i18next.t('field.description'),
|
|
242
|
+
name: 'description',
|
|
243
|
+
type: 'text',
|
|
244
|
+
props: { searchOper: 'i_like' }
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
|
|
248
|
+
this.config = {
|
|
249
|
+
...this.config,
|
|
250
|
+
columns: [
|
|
251
|
+
...this.config.columns,
|
|
252
|
+
{
|
|
253
|
+
type: 'string',
|
|
254
|
+
name: 'id',
|
|
255
|
+
header: i18next.t('field.id'),
|
|
256
|
+
hidden: true
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'string',
|
|
260
|
+
name: 'name',
|
|
261
|
+
header: i18next.t('field.name'),
|
|
262
|
+
record: {
|
|
263
|
+
align: 'left'
|
|
264
|
+
},
|
|
265
|
+
sortable: true,
|
|
266
|
+
width: 160
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
type: 'string',
|
|
270
|
+
name: 'description',
|
|
271
|
+
header: i18next.t('field.description'),
|
|
272
|
+
record: {
|
|
273
|
+
align: 'left'
|
|
274
|
+
},
|
|
275
|
+
sortable: true,
|
|
276
|
+
width: 300
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this.config = {
|
|
283
|
+
...this.config,
|
|
284
|
+
list: {
|
|
285
|
+
...this.list,
|
|
286
|
+
fields:
|
|
287
|
+
this.list && this.list.fields && this.list.fields.length > 0
|
|
288
|
+
? this.list.fields
|
|
289
|
+
: (this.config.columns as ColumnConfig[])
|
|
290
|
+
.filter(column => column.type !== 'gutter')
|
|
291
|
+
.slice(0, 3)
|
|
292
|
+
.map(column => column.name)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
await this.updateComplete
|
|
297
|
+
this.grist && this.grist.focus()
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
getSelectFields() {
|
|
301
|
+
if (this.select && this.select.length > 0) {
|
|
302
|
+
return `items {
|
|
303
|
+
${this.select.map(selectField => {
|
|
304
|
+
return selectField.type === 'object'
|
|
305
|
+
? `${selectField.name} { ${
|
|
306
|
+
selectField.subFields && selectField.subFields.length > 0
|
|
307
|
+
? selectField.subFields.join(' ')
|
|
308
|
+
: `id name description`
|
|
309
|
+
} }`
|
|
310
|
+
: `${selectField.name}`
|
|
311
|
+
})}
|
|
312
|
+
}
|
|
313
|
+
total`
|
|
314
|
+
} else {
|
|
315
|
+
return `
|
|
316
|
+
items {
|
|
317
|
+
id
|
|
318
|
+
name
|
|
319
|
+
description
|
|
320
|
+
}
|
|
321
|
+
total
|
|
322
|
+
`
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async _buildConditions({ filters, page, limit, sorters }: FetchOption) {
|
|
327
|
+
const queryConditions = {
|
|
328
|
+
filters: [],
|
|
329
|
+
...this.basicArgs
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
queryConditions.filters = [...queryConditions.filters, ...(await this.searchForm.getQueryFilters())]
|
|
333
|
+
queryConditions.pagination = { page, limit }
|
|
334
|
+
queryConditions.sortings = sorters
|
|
335
|
+
|
|
336
|
+
return queryConditions
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
get selected() {
|
|
340
|
+
var grist = this.renderRoot.querySelector('ox-grist') as DataGrist
|
|
341
|
+
|
|
342
|
+
var selected = grist.selected
|
|
343
|
+
|
|
344
|
+
return selected && selected.length > 0 ? selected[0] : undefined
|
|
345
|
+
}
|
|
346
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { registerEditor, registerRenderer } from '@operato/data-grist'
|
|
2
|
+
|
|
3
|
+
import { ParametersEditor } from './parameters-editor.js'
|
|
4
|
+
|
|
5
|
+
/* register grist renderer/editor for id */
|
|
6
|
+
registerEditor('parameters', ParametersEditor)
|
|
7
|
+
|
|
8
|
+
// registerRenderer('id', IdRenderer)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import '@things-factory/modeller-ui'
|
|
6
|
+
|
|
7
|
+
import { LitElement, PropertyValues, html } from 'lit'
|
|
8
|
+
import { OxPropertyEditor, PropertySpec } from '@operato/property-editor'
|
|
9
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
10
|
+
|
|
11
|
+
import { connect } from 'pwa-helpers/connect-mixin'
|
|
12
|
+
import { store } from '@operato/shell'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
모든 에디터들은 change 이벤트를 지원해야 한다. 또한, 모든 에디터들은 value속성에 값을 가져야 한다.
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
|
|
19
|
+
<ox-parameters-editor-builder value="{{value}}">
|
|
20
|
+
<label>Center X</label>
|
|
21
|
+
<input type="number" .value="${value.cx}">
|
|
22
|
+
<label>Width</label>
|
|
23
|
+
<input type="number" .value="${value.width}">
|
|
24
|
+
</ox-parameters-editor-builder>
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const DEFAULT_VALUE = {
|
|
28
|
+
legend: '',
|
|
29
|
+
number: 0,
|
|
30
|
+
angle: 0,
|
|
31
|
+
string: '',
|
|
32
|
+
text: '',
|
|
33
|
+
textarea: '',
|
|
34
|
+
checkbox: false,
|
|
35
|
+
select: '',
|
|
36
|
+
color: '#000000',
|
|
37
|
+
'solidcolor-stops': null,
|
|
38
|
+
'gradientcolor-stops': null,
|
|
39
|
+
'gltf-selector': '',
|
|
40
|
+
'image-selector': '',
|
|
41
|
+
multiplecolor: null,
|
|
42
|
+
editortable: null,
|
|
43
|
+
imageselector: '',
|
|
44
|
+
options: null,
|
|
45
|
+
date: null
|
|
46
|
+
} as any
|
|
47
|
+
|
|
48
|
+
@customElement('ox-parameters-editor-builder')
|
|
49
|
+
class ParametersEditorBuilder extends connect(store)(LitElement) {
|
|
50
|
+
@property({ type: Object }) value: any
|
|
51
|
+
@property({ type: Array }) props?: PropertySpec[]
|
|
52
|
+
@property({ type: Object }) host: any
|
|
53
|
+
|
|
54
|
+
render() {
|
|
55
|
+
return html`<slot></slot>`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
firstUpdated() {
|
|
59
|
+
this.addEventListener('change', this._onValueChanged.bind(this))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
updated(changes: PropertyValues<this>) {
|
|
63
|
+
changes.has('props') && this._onPropsChanged(this.props)
|
|
64
|
+
changes.has('value') && this._setValues()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_onPropsChanged(props: PropertySpec[] | undefined) {
|
|
68
|
+
this.textContent = ''
|
|
69
|
+
;(props || []).forEach(prop => {
|
|
70
|
+
let elementType = OxPropertyEditor.getEditor(prop.type)
|
|
71
|
+
if (!elementType) {
|
|
72
|
+
console.warn('Property Editor not defined', prop.type)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
let element = document.createElement(elementType) as OxPropertyEditor
|
|
76
|
+
|
|
77
|
+
element.label = prop.label
|
|
78
|
+
element.type = prop.type
|
|
79
|
+
element.placeholder = prop.placeholder
|
|
80
|
+
element.host = this.host
|
|
81
|
+
// element.context = this.context
|
|
82
|
+
element.setAttribute('name', prop.name)
|
|
83
|
+
|
|
84
|
+
if (prop.observe) {
|
|
85
|
+
element.observe = prop.observe
|
|
86
|
+
}
|
|
87
|
+
element.property = prop.property
|
|
88
|
+
element.setAttribute('property-editor', '')
|
|
89
|
+
|
|
90
|
+
this.appendChild(element)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_setValues() {
|
|
95
|
+
var value = this.value || {}
|
|
96
|
+
Array.from(this.querySelectorAll('[name]')).forEach(propertyEditor => {
|
|
97
|
+
const editor = propertyEditor as OxPropertyEditor
|
|
98
|
+
let name = editor.getAttribute('name')
|
|
99
|
+
editor.value = value[name!] === undefined ? DEFAULT_VALUE[editor.type] : value[name!]
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_getValues() {
|
|
104
|
+
var value = {} as any
|
|
105
|
+
Array.from(this.querySelectorAll('[name]')).forEach(propertyEditor => {
|
|
106
|
+
const editor = propertyEditor as OxPropertyEditor
|
|
107
|
+
let name = editor.getAttribute('name')
|
|
108
|
+
value[name!] = editor.value === undefined ? DEFAULT_VALUE[editor.type] : editor.value
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
return value
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_onValueChanged(e: Event) {
|
|
115
|
+
e.stopPropagation()
|
|
116
|
+
var prop = e.target as HTMLElement
|
|
117
|
+
|
|
118
|
+
if (!prop || !prop.hasAttribute('property-editor')) {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.dispatchEvent(
|
|
123
|
+
new CustomEvent('property-change', {
|
|
124
|
+
bubbles: true,
|
|
125
|
+
composed: true,
|
|
126
|
+
detail: this._getValues()
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { LitElement, css, html } from 'lit'
|
|
2
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
|
|
4
|
+
import { ScrollbarStyles } from '@operato/styles'
|
|
5
|
+
import { i18next } from '@operato/i18n'
|
|
6
|
+
|
|
7
|
+
@customElement('ox-parameters-editor-popup')
|
|
8
|
+
export class ParametersEditorPopup extends LitElement {
|
|
9
|
+
static styles = [
|
|
10
|
+
ScrollbarStyles,
|
|
11
|
+
css`
|
|
12
|
+
:host {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
|
|
16
|
+
background-color: #fff;
|
|
17
|
+
|
|
18
|
+
width: var(--overlay-center-normal-width, 50%);
|
|
19
|
+
height: var(--overlay-center-normal-height, 50%);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ox-parameters-editor-builder {
|
|
23
|
+
flex: 1;
|
|
24
|
+
overflow-y: auto;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
span {
|
|
28
|
+
flex: 1;
|
|
29
|
+
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
|
|
34
|
+
color: var(--primary-color);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.button-container {
|
|
38
|
+
display: flex;
|
|
39
|
+
margin-left: auto;
|
|
40
|
+
}
|
|
41
|
+
`
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
@property({ type: Object }) value: any
|
|
45
|
+
@property({ type: Object }) props: any
|
|
46
|
+
@property({ type: Object }) host: any
|
|
47
|
+
@property({ type: Object }) context: any
|
|
48
|
+
@property({ type: Object }) confirmCallback!: (newval: any) => void
|
|
49
|
+
|
|
50
|
+
render() {
|
|
51
|
+
var props = this.props instanceof Array ? this.props : []
|
|
52
|
+
|
|
53
|
+
return html`
|
|
54
|
+
${props.length > 0
|
|
55
|
+
? html`
|
|
56
|
+
<ox-parameters-editor-builder
|
|
57
|
+
.value=${this.value}
|
|
58
|
+
.props=${props}
|
|
59
|
+
.host=${this.host}
|
|
60
|
+
.context=${this.context}
|
|
61
|
+
@property-change=${this.onChange.bind(this)}
|
|
62
|
+
>
|
|
63
|
+
</ox-parameters-editor-builder>
|
|
64
|
+
`
|
|
65
|
+
: html` <span><i18n-msg msgid="text.no properties to set"></i18n-msg></span> `}
|
|
66
|
+
|
|
67
|
+
<div class="button-container">
|
|
68
|
+
<mwc-button @click=${this.onCancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
|
|
69
|
+
<mwc-button @click=${this.onConfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
|
|
70
|
+
</div>
|
|
71
|
+
`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private onChange(e: CustomEvent) {
|
|
75
|
+
e.stopPropagation()
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
|
|
79
|
+
layout의 구성에 변화가 발생하면, 다시 render된다.
|
|
80
|
+
이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
|
|
81
|
+
이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
|
|
82
|
+
만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
|
|
83
|
+
따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
|
|
84
|
+
(이 팝업 클래스를 템플릿으로 사용한 곳의 코드를 참조하세요.)
|
|
85
|
+
=>
|
|
86
|
+
이런 이유로, Object.assign(...)을 사용하였다.
|
|
87
|
+
*/
|
|
88
|
+
if (!this.value) {
|
|
89
|
+
this.value = {}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (let key in this.value) {
|
|
93
|
+
delete this.value[key]
|
|
94
|
+
}
|
|
95
|
+
Object.assign(this.value, e.detail)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private onCancel(e: Event) {
|
|
99
|
+
history.back()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private onConfirm(e: Event) {
|
|
103
|
+
this.confirmCallback && this.confirmCallback(this.value)
|
|
104
|
+
history.back()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import './parameters-editor-builder.js'
|
|
6
|
+
import './parameters-editor-popup.js'
|
|
7
|
+
|
|
8
|
+
import { ColumnConfig, GristRecord, InputEditor } from '@operato/data-grist'
|
|
9
|
+
import { LitElement, css, html } from 'lit'
|
|
10
|
+
import { PopupHandle, openPopup } from '@operato/layout'
|
|
11
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
12
|
+
|
|
13
|
+
import { i18next } from '@operato/i18n'
|
|
14
|
+
|
|
15
|
+
@customElement('ox-parameters-editor')
|
|
16
|
+
export class ParametersEditor extends InputEditor {
|
|
17
|
+
static styles = css`
|
|
18
|
+
:host {
|
|
19
|
+
color: black;
|
|
20
|
+
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
text-overflow: ellipsis;
|
|
23
|
+
}
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
@property({ type: Object }) value: any
|
|
27
|
+
@property({ type: Object }) column!: ColumnConfig
|
|
28
|
+
@property({ type: Object }) record!: GristRecord
|
|
29
|
+
@property({ type: Number }) row!: number
|
|
30
|
+
@property({ type: Object }) field!: any
|
|
31
|
+
|
|
32
|
+
private popup?: PopupHandle
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
const value = typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
|
|
36
|
+
return html` ${value || ''} `
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async firstUpdated() {
|
|
40
|
+
await this.updateComplete
|
|
41
|
+
|
|
42
|
+
this.renderRoot.addEventListener('click', e => {
|
|
43
|
+
e.stopPropagation()
|
|
44
|
+
|
|
45
|
+
this.openSelector()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
this.openSelector()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async openSelector() {
|
|
52
|
+
if (this.popup) {
|
|
53
|
+
delete this.popup
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var { options } = this.column.record
|
|
57
|
+
|
|
58
|
+
if (typeof options === 'function') {
|
|
59
|
+
options = await options.call(this, this.value, this.column, this.record, this.row, this.field)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { name, help, spec, context, objectified = false } = options
|
|
63
|
+
|
|
64
|
+
const confirmCallback = (newval: any) => {
|
|
65
|
+
this.dispatchEvent(
|
|
66
|
+
new CustomEvent('field-change', {
|
|
67
|
+
bubbles: true,
|
|
68
|
+
composed: true,
|
|
69
|
+
detail: {
|
|
70
|
+
before: this.value,
|
|
71
|
+
after: !objectified ? JSON.stringify(newval) : newval,
|
|
72
|
+
record: this.record,
|
|
73
|
+
column: this.column,
|
|
74
|
+
row: this.row
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
var value: any = !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : this.value
|
|
82
|
+
} catch (e) {
|
|
83
|
+
var value: any = {}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
|
|
88
|
+
layout의 구성에 변화가 발생하면, 다시 render된다.
|
|
89
|
+
이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
|
|
90
|
+
이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
|
|
91
|
+
만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
|
|
92
|
+
따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
|
|
93
|
+
*/
|
|
94
|
+
var template = html`
|
|
95
|
+
<ox-parameters-editor-popup
|
|
96
|
+
.value=${value}
|
|
97
|
+
.props=${spec}
|
|
98
|
+
.host=${this.record}
|
|
99
|
+
.context=${context}
|
|
100
|
+
.confirmCallback=${confirmCallback}
|
|
101
|
+
>
|
|
102
|
+
</ox-parameters-editor-popup>
|
|
103
|
+
`
|
|
104
|
+
|
|
105
|
+
this.popup = openPopup(template, {
|
|
106
|
+
backdrop: true,
|
|
107
|
+
size: 'large',
|
|
108
|
+
title: `${name?.toUpperCase() || ''} ${i18next.t('field.params')}`,
|
|
109
|
+
help
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
}
|