@things-factory/modeller-ui 5.0.0-alpha.3 → 5.0.0-alpha.6

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 (29) hide show
  1. package/client/bootstrap.js +22 -26
  2. package/client/editors/things-editor-layout/things-card-layout.js +1 -1
  3. package/client/editors/things-editor-property.js +1 -546
  4. package/package.json +15 -14
  5. package/client/editors/paper-color-picker/paper-color-circle.js +0 -466
  6. package/client/editors/paper-color-picker/paper-color-input.js +0 -266
  7. package/client/editors/paper-color-picker/paper-color-picker.js +0 -584
  8. package/client/editors/things-editor-3dish.js +0 -164
  9. package/client/editors/things-editor-angle-input.js +0 -69
  10. package/client/editors/things-editor-attachment-selector.js +0 -110
  11. package/client/editors/things-editor-buttons-radio.js +0 -93
  12. package/client/editors/things-editor-code.js +0 -152
  13. package/client/editors/things-editor-color-stops.js +0 -499
  14. package/client/editors/things-editor-color-style.js +0 -345
  15. package/client/editors/things-editor-color.js +0 -313
  16. package/client/editors/things-editor-data.js +0 -152
  17. package/client/editors/things-editor-gradient.js +0 -335
  18. package/client/editors/things-editor-graphql.js +0 -173
  19. package/client/editors/things-editor-id.js +0 -85
  20. package/client/editors/things-editor-multiple-color.js +0 -132
  21. package/client/editors/things-editor-options.js +0 -155
  22. package/client/editors/things-editor-pattern.js +0 -161
  23. package/client/editors/things-editor-property-styles.js +0 -71
  24. package/client/editors/things-editor-range-input.js +0 -166
  25. package/client/editors/things-editor-script.js +0 -213
  26. package/client/editors/things-editor-stack.js +0 -107
  27. package/client/editors/things-editor-table.js +0 -376
  28. package/client/editors/things-editor-value-map.js +0 -290
  29. package/client/editors/things-editor-value-range.js +0 -292
@@ -1,499 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { LitElement, html, css } from 'lit'
6
- import { deepEquals } from '@things-factory/utils'
7
-
8
- import './things-editor-color'
9
-
10
- /**
11
- 범위내에서 여러 컬러셋(포지션과 색깔) 배열을 편집하는 컴포넌트이다.
12
-
13
- 미리보기 Bar에서는 gradient나, solid 형태의 컬러셋을 보여준다.
14
-
15
- 새로운 컬러셋을 추가고자 할 때는 미리보기 Bar를 더블클릭한다.
16
- 컬러셋을 제거하고자 할 때는 컬러셋 마커를 아래방향으로 드래깅한다.
17
- 컬러셋의 위치를 옮기고자 할 때는, 컬러셋 마커를 좌우로 드래깅하여 이동시키거나,
18
- 옮기고자하는 컬러셋 마커를 마우스로 선택하고, 포지션 입력 에디터에서 직접 수정한다.
19
- 컬러셋의 색상을 바꾸고자 할 때는, 컬러셋 마커를 더블클릭하여 컬러파레트를 팝업시켜서 색상을 선택하거나, 색상 입력 에디터에서 직접 색상을 수정할 수 있다.
20
-
21
- Example:
22
-
23
- <things-editor-color-stops type="gradient"
24
- .value=${gradient.colorStops}>
25
- </things-editor-color-stops>
26
- */
27
-
28
- export default class ThingsEditorColorStops extends LitElement {
29
- // TODO 최초의 colorbar가 화면에 표시될 때의 사이즈에 따른 colorstop들의 위치 배정이 필요함.(IronResizableBehavior 대체.)
30
- constructor() {
31
- super()
32
-
33
- this.type = 'solid'
34
- this.min = 0
35
- this.max = 1
36
- this.value = []
37
- this.focused = null
38
- }
39
-
40
- static get is() {
41
- return 'things-editor-color-stops'
42
- }
43
-
44
- static get properties() {
45
- return {
46
- /**
47
- * `type`은 color-stop bar의 표시 방법을 의미한다.
48
- * - 'solid' : 컬러스톱위치에서 다음 컬러스톱까지 solid color로 채운다.
49
- * - 'gradient' : 컬러스톱위치에서 다음 컬러스톱까지 gradient color로 채운다.
50
- */
51
- type: String,
52
- /**
53
- * `min`은 color-stop bar의 위치값 범위의 최소값을 의미한다.
54
- */
55
- min: Number,
56
- /**
57
- * `max`은 color-stop bar의 위치값 범위의 최대값을 의미한다.
58
- */
59
- max: Number,
60
- /**
61
- * `value`은 color-stops에 의해 만들어진 color-stop 배열을 유지한다.
62
- */
63
- value: Array,
64
- focused: Object
65
- }
66
- }
67
-
68
- static get styles() {
69
- return [
70
- css`
71
- :host {
72
- display: grid;
73
- grid-template-columns: repeat(10, 1fr);
74
- grid-gap: 0;
75
- grid-auto-rows: minmax(0, auto);
76
- }
77
-
78
- #color-stops {
79
- grid-column: 1 / 11;
80
- grid-row: 1;
81
-
82
- clear: both;
83
- margin-bottom: -3px;
84
- }
85
-
86
- #colorbar {
87
- width: 95%;
88
- height: 12px;
89
- margin: auto;
90
- margin-bottom: 25px;
91
- border: 1px solid #ccc;
92
- }
93
-
94
- #markers {
95
- position: relative;
96
- top: 30px;
97
- }
98
-
99
- #markers div {
100
- width: 10px;
101
- height: 10px;
102
- margin-top: -15px;
103
- position: absolute;
104
- border: 2px solid #fff;
105
- cursor: pointer;
106
- -webkit-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
107
- -moz-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
108
- box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
109
- }
110
-
111
- #markers div::before {
112
- border-bottom: 6px solid #fff;
113
- border-left: 7px solid transparent;
114
- border-right: 7px solid transparent;
115
- content: '';
116
- width: 0;
117
- height: 0;
118
- left: -2px;
119
- position: absolute;
120
- top: -8px;
121
- }
122
-
123
- #markers div[focused] {
124
- border-color: var(--things-editor-colorbar-marker-focused-color, #585858);
125
- }
126
-
127
- #markers div[focused]:before {
128
- border-bottom: 7px solid var(--things-editor-colorbar-marker-focused-color, #585858);
129
- }
130
-
131
- .icon-only-label {
132
- background: url(/assets/images/icon-properties-label.png) no-repeat;
133
- width: 30px;
134
- height: 24px;
135
- }
136
-
137
- .icon-only-label.color {
138
- grid-column: 1 / 2;
139
- grid-row: 2;
140
-
141
- background-position: 70% -498px;
142
- float: left;
143
- margin-top: 0;
144
- }
145
-
146
- .icon-only-label.position {
147
- grid-column: 7 / 8;
148
- grid-row: 2;
149
-
150
- background-position: 70% -797px;
151
- float: left;
152
- margin-top: 0;
153
- }
154
-
155
- things-editor-color {
156
- grid-column: 2 / 7;
157
- grid-row: 2;
158
- }
159
-
160
- input[type='number'] {
161
- grid-column: 8 / 11;
162
- grid-row: 2;
163
- border: 1px solid rgba(0, 0, 0, 0.2);
164
- }
165
- `
166
- ]
167
- }
168
-
169
- connectedCallback() {
170
- super.connectedCallback()
171
-
172
- this._dragImage = new Image()
173
- this._dragImage.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
174
- }
175
-
176
- firstUpdated() {
177
- window.addEventListener('resize', () => {
178
- this.requestUpdate()
179
- })
180
- }
181
-
182
- updated(change) {
183
- var needRerenderColorBar = false
184
-
185
- if (change.has('value') && this.value instanceof Array) {
186
- var oldValue = change.get('value')
187
- if (
188
- this.focused &&
189
- (!oldValue ||
190
- this.value.findIndex(v => v.position == this.focused.position && v.color == this.focused.color) == -1)
191
- ) {
192
- /* 이전 값이 없었던 경우에 focused를 클리어시킨다.
193
- * 이전 값이 있던 경우에도, focused는 이 에디터 내부에서만 선택될 수 있으며, 수정될 수 있으므로 동일한 포지션을 갖는 value가 없으면, 새로운 에디터가 시작된 것으로 판단하여 focused를 클리어시킨다.
194
- */
195
- this.focused = null
196
- }
197
-
198
- if (!deepEquals(oldValue, this.value)) {
199
- needRerenderColorBar = true
200
- }
201
- }
202
-
203
- if (needRerenderColorBar || change.has('min') || change.has('max')) {
204
- this._renderColorBar(this.min, this.max, this.type)
205
- this.requestUpdate()
206
- }
207
- }
208
-
209
- render() {
210
- return html`
211
- <div id="color-stops">
212
- <div id="colorbar" @dblclick=${e => this._onDblClickColorbar(e)}>
213
- <div
214
- id="markers"
215
- @dblclick=${e => this._onDblClickMarkers(e)}
216
- @mousedown=${e => this._onMouseDown(e)}
217
- @dragstart=${e => this._onDragStart(e)}
218
- @drag=${this._throttled(100, this._onDrag.bind(this))}
219
- @dragend=${e => this._onDragEnd(e)}
220
- >
221
- ${this._refinedValue(this.value).map(
222
- (item, index) => html`
223
- <div
224
- .style="background-color:${item.color};margin-left:${this._calculatePosition(
225
- item.position,
226
- this.min,
227
- this.max
228
- )}px;"
229
- marker-index=${index}
230
- draggable="true"
231
- ></div>
232
- `
233
- )}
234
- </div>
235
- </div>
236
- </div>
237
-
238
- <label class="icon-only-label color"></label>
239
- <things-editor-color
240
- id="color-editor"
241
- .value=${this.focused && this.focused.color}
242
- @change=${e => this._onChangeSubComponent(e)}
243
- >
244
- </things-editor-color>
245
-
246
- <label class="icon-only-label position"></label>
247
- <input
248
- type="number"
249
- id="color-position"
250
- .value=${this.focused && this.focused.position}
251
- @change=${e => this._onChangeSubComponent(e)}
252
- step="0.01"
253
- />
254
- `
255
- }
256
-
257
- get colorbar() {
258
- return this.shadowRoot.querySelector('#colorbar')
259
- }
260
-
261
- get colorEditor() {
262
- return this.shadowRoot.querySelector('#color-editor')
263
- }
264
-
265
- _refinedValue(value) {
266
- return value instanceof Array ? value : []
267
- }
268
-
269
- _setFocused(index) {
270
- if (this.focused && this.focused.index === index) {
271
- return
272
- }
273
-
274
- var marker = this.shadowRoot.querySelector(`#markers div[marker-index='${index}']`)
275
- var olds = this.shadowRoot.querySelectorAll('#markers div[focused]')
276
- olds.length > 0 && olds.forEach(old => old.removeAttribute('focused'))
277
- marker && marker.setAttribute('focused', true)
278
-
279
- if (!marker) {
280
- this.focused = null
281
- return
282
- }
283
-
284
- var colorStop = this.value[index]
285
-
286
- this._changeFocused({
287
- index: index,
288
- color: colorStop.color,
289
- position: Math.max(this.min, Math.min(colorStop.position, this.max))
290
- })
291
- }
292
-
293
- _changeFocused(focused) {
294
- if (!focused) {
295
- this._setFocused(-1) // clear focused marker
296
-
297
- return
298
- }
299
-
300
- this.focused = focused
301
-
302
- this.value = this.value
303
- .map((colorStop, index) => {
304
- if (index != focused.index) return colorStop
305
-
306
- return {
307
- color: focused.color,
308
- position: focused.position
309
- }
310
- })
311
- .sort((a, b) => {
312
- return b.position < a.position
313
- })
314
-
315
- var colorStop = this.value[focused.index]
316
-
317
- if (focused.position != colorStop.position || focused.color != colorStop.color) {
318
- var index = -1
319
- for (var i = 0; i < this.value.length; i++) {
320
- colorStop = this.value[i]
321
- if (focused.position == colorStop.position && focused.color == colorStop.color) {
322
- index = i
323
- break
324
- }
325
- }
326
-
327
- this._setFocused(index)
328
- }
329
- }
330
-
331
- _renderColorBar(min, max, type) {
332
- var value = this._refinedValue(this.value)
333
- var gradient = ''
334
-
335
- if (value instanceof Array && value.length > 0) {
336
- if (this.type == 'gradient') {
337
- var stopsStrings = (value || []).map(function (stop) {
338
- var position = (stop.position - min) / (max - min)
339
- return `${stop.color} ${position * 100}%`
340
- })
341
- } else {
342
- var stops = value || []
343
- var last = null
344
- var last_position = 0
345
- var stopsStrings = stops.map(function (stop) {
346
- var stop_position = (stop.position - min) / (max - min)
347
- if (last) {
348
- last_position = (last.position - min) / (max - min)
349
- var step = `${stop.color} ${last_position * 100}%, ${stop.color} ${stop_position * 100}%`
350
- } else {
351
- var step = `${stop.color} ${stop_position * 100}%`
352
- }
353
- last = stop
354
- return step
355
- })
356
- if (last) {
357
- last_position = (last.position - min) / (max - min)
358
- stopsStrings.push(`${last.color} ${last_position * 100}%, white ${last_position * 100}%, white 100%`)
359
- }
360
- }
361
-
362
- gradient = stopsStrings.join(',')
363
- } else {
364
- gradient = 'black 0%, black 100%'
365
- }
366
-
367
- this.colorbar.style.background = `linear-gradient(to right, ${gradient})`
368
- /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
369
- }
370
-
371
- _onChangeSubComponent(e) {
372
- var element = e.target
373
- var id = element.id
374
-
375
- if (!this.focused) {
376
- return
377
- }
378
-
379
- switch (id) {
380
- case 'color-editor':
381
- this._changeFocused({
382
- ...this.focused,
383
- color: element.value
384
- })
385
- break
386
- case 'color-position':
387
- this._changeFocused({
388
- ...this.focused,
389
- position: Math.max(this.min, Math.min(element.value, this.max))
390
- })
391
- break
392
- }
393
-
394
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
395
- }
396
-
397
- _onDblClickColorbar(e) {
398
- /* 마커를 클릭한 경우를 걸러낸다. */
399
- if (e.target !== this.colorbar) return
400
-
401
- var width = this.colorbar.offsetWidth
402
- var position = this.min + (this.max - this.min) * (e.offsetX / width)
403
- var colorStops = this.value ? this.value.slice() : []
404
-
405
- for (var i = 0; i < colorStops.length; i++) {
406
- if (colorStops[i].position > position) break
407
- }
408
-
409
- colorStops.splice(i, 0, {
410
- position: position,
411
- color: '#fff'
412
- })
413
-
414
- this.value = colorStops
415
-
416
- this.focused = null
417
- this._setFocused(i)
418
-
419
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
420
- }
421
-
422
- _onDblClickMarkers(e) {
423
- this.colorEditor.showPicker()
424
- }
425
-
426
- _onMouseDown(e) {
427
- var marker = e.target
428
- var index = marker.getAttribute('marker-index')
429
-
430
- this._setFocused(index)
431
- }
432
-
433
- _onDragStart(e) {
434
- /* drag 시에 ghost image를 보이지 않게 하려고 함 */
435
- e.dataTransfer.setDragImage(this._dragImage, 0, 0)
436
-
437
- this.dragstart = {
438
- position: this.focused.position,
439
- x: e.clientX,
440
- y: e.clientY
441
- }
442
- }
443
-
444
- // TODO onDrag 이벤트가 계속 발생하므로 처리하는 성능 저하됨. 그래서 throttling 하도록 함
445
- _throttled(delay, fn) {
446
- let lastCall = 0
447
- return function (...args) {
448
- const now = new Date().getTime()
449
- if (now - lastCall < delay) {
450
- return
451
- }
452
- lastCall = now
453
- return fn(...args)
454
- }
455
- }
456
-
457
- _onDrag(e) {
458
- if (e.clientX <= 0) {
459
- return
460
- }
461
-
462
- var width = this.colorbar.offsetWidth
463
- var position = this.dragstart.position + ((e.clientX - this.dragstart.x) / width) * (this.max - this.min)
464
-
465
- if (position != this.focused.position) {
466
- this._changeFocused({
467
- ...this.focused,
468
- position: Math.max(this.min, Math.min(position, this.max))
469
- })
470
-
471
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
472
- }
473
- }
474
-
475
- _onDragEnd(e) {
476
- if (e.clientY - this.dragstart.y > 40) {
477
- this.value.splice(this.focused.index, 1)
478
- this.value = this.value.slice()
479
-
480
- this._setFocused(-1)
481
-
482
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
483
- }
484
- }
485
-
486
- _calculatePosition(position, min, max) {
487
- /* TODO 7 ==> 마커 폭의 절반으로 계산해야함. */
488
- var calculated = position
489
-
490
- if (calculated > this.max) calculated = this.max
491
- else if (calculated < this.min) calculated = this.min
492
-
493
- var width = (this.colorbar && this.colorbar.offsetWidth) || this._colorbar_size || 0
494
-
495
- return ((calculated - this.min) / (this.max - this.min)) * width - 7
496
- }
497
- }
498
-
499
- customElements.define(ThingsEditorColorStops.is, ThingsEditorColorStops)