@operato/board 1.0.25 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/board",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Webcomponent for board following open-wc recommendations",
5
5
  "author": "heartyoh",
6
6
  "license": "MIT",
@@ -116,5 +116,5 @@
116
116
  "prettier --write"
117
117
  ]
118
118
  },
119
- "gitHead": "cc9a66e8eff17dfa7b2d63bd927a5fbc0641e887"
119
+ "gitHead": "cba8531e3edd3c1d77772de8ae06d4be918f4466"
120
120
  }
@@ -410,11 +410,11 @@ export class EditToolbar extends LitElement {
410
410
  }
411
411
 
412
412
  onSceneChanged(after?: Scene, before?: Scene) {
413
- // if (before) {
414
- // before.off('execute', this.onExecute, this)
415
- // before.off('undo', this.onUndo, this)
416
- // before.off('redo', this.onRedo, this)
417
- // }
413
+ if (before) {
414
+ before.off('execute', this.onExecute, this)
415
+ before.off('undo', this.onUndo, this)
416
+ before.off('redo', this.onRedo, this)
417
+ }
418
418
 
419
419
  if (after) {
420
420
  after.on('execute', this.onExecute, this)
@@ -1,5 +1,7 @@
1
+ import '@operato/input/ox-input-search.js'
2
+
1
3
  import { css, html, LitElement, PropertyValues, TemplateResult } from 'lit'
2
- import { property } from 'lit/decorators.js'
4
+ import { property, state } from 'lit/decorators.js'
3
5
  import Sortable from 'sortablejs'
4
6
 
5
7
  import { Component, Container, Scene } from '@hatiolab/things-scene'
@@ -8,9 +10,21 @@ export class SceneInspector extends LitElement {
8
10
  static styles = [
9
11
  css`
10
12
  :host {
13
+ display: flex;
14
+ flex-direction: column;
15
+
11
16
  color: var(--scene-inspector-color);
12
17
  }
13
18
 
19
+ div[result] {
20
+ flex: 1;
21
+
22
+ display: flex;
23
+ flex-direction: column;
24
+
25
+ overflow-y: auto;
26
+ }
27
+
14
28
  .component {
15
29
  display: block;
16
30
  overflow: hidden;
@@ -90,63 +104,74 @@ export class SceneInspector extends LitElement {
90
104
 
91
105
  @property({ type: Object }) scene?: Scene
92
106
 
107
+ @state() private searchText: string = ''
108
+
93
109
  private _extendedMap: any
94
110
  private show: boolean = false
95
111
 
112
+ disconnectScene(scene?: Scene) {
113
+ if (scene) {
114
+ scene.off('selected', undefined, this)
115
+ scene.off('execute', undefined, this)
116
+ scene.off('undo', undefined, this)
117
+ scene.off('redo', undefined, this)
118
+ }
119
+ }
120
+
121
+ disconnectedCallback() {
122
+ super.disconnectedCallback()
123
+
124
+ this.disconnectScene(this.scene)
125
+ delete this._extendedMap
126
+ }
127
+
96
128
  render() {
97
- return html` ${!this.scene ? html`` : this.renderComponent(this.scene.root, 0)} `
129
+ return html`
130
+ <ox-input-search
131
+ @change=${(e: Event) => (this.searchText = (e.target as HTMLInputElement).value)}
132
+ ></ox-input-search>
133
+
134
+ <div result>${!this.scene ? html`` : this.renderComponent(this.scene.root, 0)}</div>
135
+ `
98
136
  }
99
137
 
100
138
  firstUpdated() {
101
139
  dispatchEvent(new Event('resize'))
140
+
102
141
  this.renderRoot.addEventListener('click', this._onclick.bind(this) as EventListener)
103
142
  this.renderRoot.addEventListener('dblclick', this._ondblclick.bind(this) as EventListener)
104
143
  }
105
144
 
145
+ refresh() {
146
+ let selected = this.scene?.selected || []
147
+
148
+ selected.forEach(component => {
149
+ let parent = component.parent
150
+ while (parent && !this.extendedMap.get(parent)) {
151
+ this.extendedMap.set(parent, true)
152
+ parent = parent.parent
153
+ }
154
+ })
155
+
156
+ this.requestUpdate()
157
+ }
158
+
106
159
  updated(change: PropertyValues<this>) {
107
160
  if (change.has('scene')) {
108
161
  let oldScene = change.get('scene') as Scene
109
162
 
110
163
  if (oldScene) {
111
- oldScene.off('selected')
112
- oldScene.off('execute')
113
- oldScene.off('undo')
114
- oldScene.off('redo')
115
-
164
+ this.disconnectScene(oldScene)
116
165
  delete this._extendedMap
117
166
  }
118
167
 
119
168
  if (this.scene && this.scene.root) {
120
- // root 는 기본상태가 extended 되도록 하기위해서임.
121
- this.extendedMap.set(this.scene.root, true)
122
-
123
- this.scene.on('selected', (after: Component[], before: Component[]) => {
124
- let selected = after
125
-
126
- selected.forEach(component => {
127
- let parent = component.parent
128
- while (parent && !this.extendedMap.get(parent)) {
129
- this.extendedMap.set(parent, true)
130
- parent = parent.parent
131
- }
132
- })
133
-
134
- this.requestUpdate()
135
- })
136
-
137
- this.scene.on('execute', () => {
138
- this.requestUpdate()
139
- })
140
-
141
- this.scene.on('undo', () => {
142
- this.extendedMap.set(this.scene!.root, true)
143
- this.requestUpdate()
144
- })
145
-
146
- this.scene.on('redo', () => {
147
- this.extendedMap.set(this.scene!.root, true)
148
- this.requestUpdate()
149
- })
169
+ this.scene.on('selected', this.refresh, this)
170
+ this.scene.on('execute', this.refresh, this)
171
+ this.scene.on('undo', this.refresh, this)
172
+ this.scene.on('redo', this.refresh, this)
173
+
174
+ this.refresh()
150
175
  }
151
176
  }
152
177
 
@@ -180,13 +205,6 @@ export class SceneInspector extends LitElement {
180
205
  })
181
206
  }
182
207
 
183
- disconnectedCallback() {
184
- super.disconnectedCallback()
185
-
186
- delete this.scene
187
- delete this._extendedMap
188
- }
189
-
190
208
  _onclick(e: MouseEvent) {
191
209
  e.stopPropagation()
192
210
 
@@ -289,13 +307,27 @@ export class SceneInspector extends LitElement {
289
307
  this.requestUpdate()
290
308
  }
291
309
 
310
+ shouldBeShown(component: Component): boolean {
311
+ const { type, name, id, tag } = component.state
312
+
313
+ return !!(
314
+ !this.searchText ||
315
+ `${type} ${name || ''} ${id || ''} ${tag || ''}`.search(this.searchText) > -1 ||
316
+ ((component as Container).components || []).find((child: Component) => this.shouldBeShown(child))
317
+ )
318
+ }
319
+
292
320
  renderComponent(component: Component, depth: number): TemplateResult {
293
321
  if (!component) {
294
322
  return html``
295
323
  }
296
324
 
325
+ if (!this.shouldBeShown(component)) {
326
+ return html``
327
+ }
328
+
297
329
  const children = (component.isContainer() && (component as Container).components) || []
298
- const extended = this.isExtended(component) ? children : []
330
+ const extended = this.isExtended(component) ? children.filter(child => this.shouldBeShown(child)) : []
299
331
  const { type, id, tag, class: clazz } = component.state
300
332
 
301
333
  const name = (id ? `#${id}` : '') + (tag ? `@${tag}` : '') + (clazz ? `.(${clazz})` : '')