@hatiolab/things-scene 3.0.0-beta.2 → 3.0.0-beta.3

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'
@@ -18,16 +25,48 @@ declare module '@hatiolab/things-scene' {
18
25
  type TRANSLATE = DIMENSION
19
26
  type POSITION = DIMENSION
20
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
+ }
21
51
 
22
- type LAYOUT = {
52
+ interface LAYOUT {
23
53
  reflow: (container: Container) => void
24
- capturables?: (container: Container) => boolean
25
- drawables?: (container: Container) => boolean
54
+ capturables?: (container: Container) => Component[]
55
+ drawables?: (container: Container) => Component[]
26
56
  isStuck?: (component: Container) => boolean
27
- keyNavigate?: (container: Container, component: Component, e: KeyboardEvent) => Component
57
+ keyNavigate?: (container: Container, component: Component, e: KeyboardEvent) => Component | undefined
28
58
  joinType?: boolean
29
59
  }
30
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
+
31
70
  const AbsoluteLayout: LAYOUT & { ABSOLUTE: boolean }
32
71
  const TableLayout: LAYOUT
33
72
  const CardLayout: LAYOUT
@@ -94,7 +133,7 @@ declare module '@hatiolab/things-scene' {
94
133
  class Model {
95
134
  static compile(model: Model, context?: any): Component
96
135
 
97
- type: string;
136
+ type?: string;
98
137
  [key: string]: any
99
138
  }
100
139
 
@@ -153,7 +192,7 @@ declare module '@hatiolab/things-scene' {
153
192
  on(name: string, callback: Function, context?: any): void
154
193
  off(name: string, callback: Function, context?: any): void
155
194
  once(name: string, callback: Function, context?: any): void
156
- trigger(name: string): void
195
+ trigger(name: string, ...others: any[]): void
157
196
  }
158
197
  } & TBase
159
198
 
@@ -162,9 +201,11 @@ declare module '@hatiolab/things-scene' {
162
201
  class Component extends MixinEvent(Object) {
163
202
  static register(type: string, Clazz: typeof Component): void
164
203
  static memoize(base: any, property: string, needClone: boolean): void
204
+ static drawStroke(context: CanvasRenderingContext2D, style: Style): void
165
205
 
166
206
  state: Properties
167
- bounds: { top: number; left: number; width: number; height: number }
207
+ bounds: BOUNDS
208
+ textBounds: BOUNDS
168
209
  root: RootContainer
169
210
  rootModel: ModelLayer
170
211
  parent: Container
@@ -173,6 +214,9 @@ declare module '@hatiolab/things-scene' {
173
214
  hierarchy: Model
174
215
  path: Array<DIMENSION>
175
216
  anchors: Array<Anchor>
217
+ hidden: boolean
218
+
219
+ get nature(): ComponentNature
176
220
 
177
221
  get data(): any
178
222
  set data(data: any)
@@ -183,6 +227,12 @@ declare module '@hatiolab/things-scene' {
183
227
  get controls(): Array<Control> | undefined
184
228
  get hasTextProperty(): boolean
185
229
 
230
+ isRootModel(): boolean
231
+ isContainer(): boolean
232
+ isLine(): boolean
233
+ isLayer(): boolean
234
+ is3dish(): boolean
235
+
186
236
  ready(): void
187
237
  dispose(): void
188
238
  getState(prop: string): any
@@ -191,6 +241,7 @@ declare module '@hatiolab/things-scene' {
191
241
  contains(x: number, y: number): boolean
192
242
  set(props: Properties | string, value?: any): void
193
243
  reposition(): void
244
+ clearCache(): void
194
245
 
195
246
  transcoordP2S(x: number, y: number): POSITION
196
247
  transcoordC2S(x: number, y: number, top?: RootContainer): POSITION
@@ -229,7 +280,8 @@ declare module '@hatiolab/things-scene' {
229
280
  addComponent(target: Component): void
230
281
  removeComponent(target: Component): void
231
282
  insertComponentAt(target: Component, idx: number): void
232
- findById(id: string): Component
283
+ findById(id: string): Component | undefined
284
+ getAt(at: number): Component | undefined
233
285
 
234
286
  add(components: Component[] | Component): Container
235
287
  remove(components: Component[] | Component): Container
@@ -237,11 +289,14 @@ declare module '@hatiolab/things-scene' {
237
289
  components: Component[]
238
290
  }
239
291
  class Container extends MixinHTMLElement(ContainerAbstract) {}
240
- class RootContainer extends Container {}
292
+ class RootContainer extends Container {
293
+ get selected(): Component[]
294
+ set selected(selected: Component[])
295
+ }
241
296
 
242
297
  class Layer extends ContainerAbstract {
243
- target: HTMLElement
244
- canvas: HTMLCanvasElement
298
+ target: HTMLElement | null
299
+ canvas: HTMLCanvasElement | null
245
300
 
246
301
  getContext(): CanvasRenderingContext2D
247
302
  }
@@ -273,7 +328,20 @@ declare module '@hatiolab/things-scene' {
273
328
  * @param boundsOrOffset {object} - x, y, cx, cy, ...
274
329
  * @param onto {string} - onto
275
330
  */
276
- 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
277
345
 
278
346
  /**
279
347
  * scene의 컴포넌트를 복제한다.
@@ -306,7 +374,7 @@ declare module '@hatiolab/things-scene' {
306
374
  */
307
375
  variable(id: string, value: any): any
308
376
 
309
- target: HTMLElement
377
+ target: HTMLElement | null
310
378
  scale: SCALE
311
379
  translate: TRANSLATE
312
380
 
@@ -315,6 +383,8 @@ declare module '@hatiolab/things-scene' {
315
383
  readonly PPI: number
316
384
  readonly DPPX: number
317
385
 
386
+ mode: SCENE_MODE
387
+
318
388
  /**
319
389
  * Scene 모델의 단위(unit)을 감안한 기본 Scale 값을 제공한다.
320
390
  * 통산 'mm', 'cm' 단위의 Scene은 각 값에 10배를 곱한 수치로 모델링된다.(값을 10으로 나눈값이 실제 단위와 일치한다.)
@@ -338,6 +408,7 @@ declare module '@hatiolab/things-scene' {
338
408
  */
339
409
  resize(): void
340
410
 
411
+ release(): void
341
412
  dispose(): void
342
413
 
343
414
  /* Selection Based API - Modeling APIs */
@@ -363,13 +434,13 @@ declare module '@hatiolab/things-scene' {
363
434
  * selector에 해당하는 모든 컴포넌트들을 찾는다.
364
435
  * @params selector {string}
365
436
  */
366
- findAll(selector: string): Array<Component>
437
+ findAll(selector: string, component?: Component): Array<Component>
367
438
 
368
439
  /*
369
440
  * selector에 해당하는 첫번째 컴포넌트를 찾는다.
370
441
  * @params selector {string}
371
442
  */
372
- findFirst(selector: string): Component
443
+ findFirst(selector: string, ...others: any[]): Component
373
444
 
374
445
  /*
375
446
  * id를 갖는 컴포넌트를 찾는다.
@@ -384,14 +455,34 @@ declare module '@hatiolab/things-scene' {
384
455
 
385
456
  on(event: string, listener: Function, context?: any): void
386
457
  once(event: string, listener: Function, context?: any): void
387
- off(event: string, listener: Function, context?: any): void
458
+ off(event: string, listener?: Function, context?: any): void
388
459
 
389
460
  toDataURL(): string
390
461
 
391
462
  fit(type: FITMODE): void
392
463
 
393
464
  readonly fitMode: FITMODE
394
- 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
395
486
 
396
487
  data: object
397
488