@hatiolab/things-scene 2.7.23 → 2.7.27

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/things-scene.d.ts CHANGED
@@ -1,7 +1,13 @@
1
+ import { property } from 'lodash'
2
+
1
3
  declare module '@hatiolab/things-scene' {
2
4
  type Constructor<T = {}> = new (...args: any[]) => T
3
5
  type Class = { new (...args: any[]): any }
4
6
  type Properties = { [key: string]: any }
7
+ type State = Properties
8
+ type Style = Properties
9
+
10
+ type ChangeFunction = (selector: string, value: any, self: any) => Component[]
5
11
 
6
12
  const MODE_VIEW = 0
7
13
  const MODE_EDIT = 1
@@ -9,7 +15,8 @@ declare module '@hatiolab/things-scene' {
9
15
 
10
16
  enum SCENE_MODE {
11
17
  VIEW = 0,
12
- EDIT = 1
18
+ EDIT = 1,
19
+ SHIFT = 2
13
20
  }
14
21
 
15
22
  type FITMODE = 'both' | 'ratio' | 'width' | 'height' | 'center' | 'none'
@@ -17,16 +24,49 @@ declare module '@hatiolab/things-scene' {
17
24
  type SCALE = DIMENSION
18
25
  type TRANSLATE = DIMENSION
19
26
  type POSITION = DIMENSION
27
+ type POINT = DIMENSION
28
+ type BOUNDS = { left: number; top: number; width: number; height: number }
29
+
30
+ type ComponentNature = {
31
+ mutable?: boolean
32
+ resizable?: boolean
33
+ rotatable?: boolean
34
+ properties?: {
35
+ type: string
36
+ label: string
37
+ name: string
38
+ placeholder?: string
39
+ observe?: (this: HTMLElement, value: any) => void
40
+ property?:
41
+ | {
42
+ options?: any
43
+ [key: string]: any
44
+ }
45
+ | string
46
+ }[]
47
+ 'value-property'?: string
48
+ valueProperty?: string
49
+ help?: string
50
+ }
20
51
 
21
- type LAYOUT = {
52
+ interface LAYOUT {
22
53
  reflow: (container: Container) => void
23
- capturables?: (container: Container) => boolean
24
- drawables?: (container: Container) => boolean
54
+ capturables?: (container: Container) => Component[]
55
+ drawables?: (container: Container) => Component[]
25
56
  isStuck?: (component: Container) => boolean
26
- keyNavigate?: (container: Container, component: Component, e: KeyboardEvent) => Component
57
+ keyNavigate?: (container: Container, component: Component, e: KeyboardEvent) => Component | undefined
27
58
  joinType?: boolean
28
59
  }
29
60
 
61
+ interface LayoutRegistry {
62
+ register(name: string, layout: LAYOUT): void
63
+ unregister(name: string): void
64
+ get(name: string): LAYOUT
65
+ list(): { [name: string]: LAYOUT }
66
+ }
67
+
68
+ const Layout: LayoutRegistry
69
+
30
70
  const AbsoluteLayout: LAYOUT & { ABSOLUTE: boolean }
31
71
  const TableLayout: LAYOUT
32
72
  const CardLayout: LAYOUT
@@ -93,7 +133,7 @@ declare module '@hatiolab/things-scene' {
93
133
  class Model {
94
134
  static compile(model: Model, context?: any): Component
95
135
 
96
- type: string;
136
+ type?: string;
97
137
  [key: string]: any
98
138
  }
99
139
 
@@ -152,7 +192,7 @@ declare module '@hatiolab/things-scene' {
152
192
  on(name: string, callback: Function, context?: any): void
153
193
  off(name: string, callback: Function, context?: any): void
154
194
  once(name: string, callback: Function, context?: any): void
155
- trigger(name: string): void
195
+ trigger(name: string, ...others: any[]): void
156
196
  }
157
197
  } & TBase
158
198
 
@@ -161,9 +201,11 @@ declare module '@hatiolab/things-scene' {
161
201
  class Component extends MixinEvent(Object) {
162
202
  static register(type: string, Clazz: typeof Component): void
163
203
  static memoize(base: any, property: string, needClone: boolean): void
204
+ static drawStroke(context: CanvasRenderingContext2D, style: Style): void
164
205
 
165
206
  state: Properties
166
- bounds: { top: number; left: number; width: number; height: number }
207
+ bounds: BOUNDS
208
+ textBounds: BOUNDS
167
209
  root: RootContainer
168
210
  rootModel: ModelLayer
169
211
  parent: Container
@@ -172,20 +214,42 @@ declare module '@hatiolab/things-scene' {
172
214
  hierarchy: Model
173
215
  path: Array<DIMENSION>
174
216
  anchors: Array<Anchor>
175
- data: any
217
+ hidden: boolean
218
+
219
+ get nature(): ComponentNature
220
+
221
+ get data(): any
222
+ set data(data: any)
223
+
224
+ get center(): POINT
225
+ set center(point: POINT)
176
226
 
177
227
  get controls(): Array<Control> | undefined
178
228
  get hasTextProperty(): boolean
179
229
 
230
+ isRootModel(): boolean
231
+ isContainer(): boolean
232
+ isLine(): boolean
233
+ isLayer(): boolean
234
+ is3dish(): boolean
235
+
180
236
  ready(): void
181
237
  dispose(): void
182
238
  getState(prop: string): any
183
239
  setState(props: Properties | any, value?: any): void
184
240
  get(prop: string): any
241
+ contains(x: number, y: number): boolean
185
242
  set(props: Properties | string, value?: any): void
186
243
  reposition(): void
244
+ clearCache(): void
245
+
187
246
  transcoordP2S(x: number, y: number): POSITION
247
+ transcoordC2S(x: number, y: number, top?: RootContainer): POSITION
248
+
249
+ prerender(context: CanvasRenderingContext2D): void
188
250
  render(context: CanvasRenderingContext2D): void
251
+ postrender(context: CanvasRenderingContext2D): void
252
+
189
253
  executeMappings(force?: boolean): void
190
254
  invalidate(): void
191
255
  animate(config: AnimationConfig): {
@@ -210,22 +274,29 @@ declare module '@hatiolab/things-scene' {
210
274
  ondblclick(e: MouseEvent): void
211
275
  }
212
276
 
213
- class ContainerAbstract extends MoveHandle(RectPath(Component)) {}
214
- class Container extends MixinHTMLElement(ContainerAbstract) {
277
+ class ContainerAbstract extends MoveHandle(RectPath(Component)) {
215
278
  indexOf(component: Component): number
279
+ size(): number
280
+ addComponent(target: Component): void
281
+ removeComponent(target: Component): void
216
282
  insertComponentAt(target: Component, idx: number): void
217
- findById(id: string): Component
283
+ findById(id: string): Component | undefined
284
+ getAt(at: number): Component | undefined
218
285
 
219
286
  add(components: Component[] | Component): Container
220
287
  remove(components: Component[] | Component): Container
221
288
 
222
289
  components: Component[]
223
290
  }
224
- class RootContainer extends Container {}
291
+ class Container extends MixinHTMLElement(ContainerAbstract) {}
292
+ class RootContainer extends Container {
293
+ get selected(): Component[]
294
+ set selected(selected: Component[])
295
+ }
225
296
 
226
297
  class Layer extends ContainerAbstract {
227
- target: HTMLElement
228
- canvas: HTMLCanvasElement
298
+ target: HTMLElement | null
299
+ canvas: HTMLCanvasElement | null
229
300
 
230
301
  getContext(): CanvasRenderingContext2D
231
302
  }
@@ -257,7 +328,20 @@ declare module '@hatiolab/things-scene' {
257
328
  * @param boundsOrOffset {object} - x, y, cx, cy, ...
258
329
  * @param onto {string} - onto
259
330
  */
260
- add({ models, boundsOrOffset, onto }: { models: object; boundsOrOffset: object; onto: string }): Component
331
+ add(
332
+ models: Model,
333
+ boundsOrOffset?: {
334
+ left?: number
335
+ top?: number
336
+ width?: number
337
+ height?: number
338
+ x?: number
339
+ y?: number
340
+ cx?: number
341
+ cy?: number
342
+ },
343
+ onto?: string
344
+ ): Component
261
345
 
262
346
  /**
263
347
  * scene의 컴포넌트를 복제한다.
@@ -290,7 +374,7 @@ declare module '@hatiolab/things-scene' {
290
374
  */
291
375
  variable(id: string, value: any): any
292
376
 
293
- target: HTMLElement
377
+ target: HTMLElement | null
294
378
  scale: SCALE
295
379
  translate: TRANSLATE
296
380
 
@@ -299,6 +383,8 @@ declare module '@hatiolab/things-scene' {
299
383
  readonly PPI: number
300
384
  readonly DPPX: number
301
385
 
386
+ mode: SCENE_MODE
387
+
302
388
  /**
303
389
  * Scene 모델의 단위(unit)을 감안한 기본 Scale 값을 제공한다.
304
390
  * 통산 'mm', 'cm' 단위의 Scene은 각 값에 10배를 곱한 수치로 모델링된다.(값을 10으로 나눈값이 실제 단위와 일치한다.)
@@ -322,6 +408,7 @@ declare module '@hatiolab/things-scene' {
322
408
  */
323
409
  resize(): void
324
410
 
411
+ release(): void
325
412
  dispose(): void
326
413
 
327
414
  /* Selection Based API - Modeling APIs */
@@ -347,13 +434,13 @@ declare module '@hatiolab/things-scene' {
347
434
  * selector에 해당하는 모든 컴포넌트들을 찾는다.
348
435
  * @params selector {string}
349
436
  */
350
- findAll(selector: string): Array<Component>
437
+ findAll(selector: string, component?: Component): Array<Component>
351
438
 
352
439
  /*
353
440
  * selector에 해당하는 첫번째 컴포넌트를 찾는다.
354
441
  * @params selector {string}
355
442
  */
356
- findFirst(selector: string): Component
443
+ findFirst(selector: string, ...others: any[]): Component
357
444
 
358
445
  /*
359
446
  * id를 갖는 컴포넌트를 찾는다.
@@ -368,14 +455,34 @@ declare module '@hatiolab/things-scene' {
368
455
 
369
456
  on(event: string, listener: Function, context?: any): void
370
457
  once(event: string, listener: Function, context?: any): void
371
- off(event: string, listener: Function, context?: any): void
458
+ off(event: string, listener?: Function, context?: any): void
372
459
 
373
460
  toDataURL(): string
374
461
 
375
462
  fit(type: FITMODE): void
376
463
 
377
464
  readonly fitMode: FITMODE
378
- readonly ids: string[]
465
+ readonly ids: { [id: string]: any }[]
466
+
467
+ copy(): string
468
+ cut(): string
469
+ redo(): void
470
+ undo(): void
471
+ move(component: Component, to_container: Container, to_index: number): void
472
+
473
+ select(selector: string | Function, ...others: (string | Function)[]): Component[]
474
+ paste(clipboard: string): void
475
+ align(type: 'left' | 'right' | 'center' | 'top' | 'bottom' | 'middle' | string): void
476
+ distribute(type: string): void
477
+ symmetryX(): void
478
+ symmetryY(): void
479
+
480
+ group(): void
481
+ ungroup(): void
482
+
483
+ change(f: ChangeFunction): void
484
+ undoableChange(f: () => void): void
485
+ zorder(type: 'forward' | 'backward' | 'front' | string): void
379
486
 
380
487
  data: object
381
488