@node-projects/web-component-designer-widgets-wunderbaum 0.1.10 → 0.1.12

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.
@@ -6,6 +6,7 @@ export declare class PaletteTreeView extends BaseCustomWebComponentConstructorAp
6
6
  private _filter;
7
7
  static readonly style: CSSStyleSheet;
8
8
  static readonly template: HTMLTemplateElement;
9
+ private serviceContainer;
9
10
  constructor();
10
11
  loadControls(serviceContainer: ServiceContainer, elementsServices: IElementsService[]): Promise<void>;
11
12
  }
@@ -1,5 +1,5 @@
1
1
  import { css, html, BaseCustomWebComponentConstructorAppend, cssFromString } from '@node-projects/base-custom-webcomponent';
2
- import { dragDropFormatNameElementDefinition } from '@node-projects/web-component-designer';
2
+ import { NamedTools, dragDropFormatNameElementDefinition } from '@node-projects/web-component-designer';
3
3
  import { Wunderbaum } from 'wunderbaum';
4
4
  import { defaultOptions, defaultStyle } from '../WunderbaumOptions.js';
5
5
  //@ts-ignore
@@ -23,6 +23,7 @@ export class PaletteTreeView extends BaseCustomWebComponentConstructorAppend {
23
23
  <div id="treetable" class="wb-alternate" style="min-width: 100%;"></div>
24
24
  </div>
25
25
  </div>`;
26
+ serviceContainer;
26
27
  constructor() {
27
28
  super();
28
29
  this._restoreCachedInititalValues();
@@ -43,9 +44,21 @@ export class PaletteTreeView extends BaseCustomWebComponentConstructorAppend {
43
44
  mode: 'hide',
44
45
  highlight: true
45
46
  },
47
+ click: (e) => {
48
+ if (e.event) { // only for clicked items, not when elements selected via code.
49
+ let node = e.node;
50
+ let elDef = node.data.ref;
51
+ if (elDef) {
52
+ let tool = this.serviceContainer.designerTools.get(elDef.tool ?? NamedTools.DrawElementTool);
53
+ if (typeof tool == 'function')
54
+ tool = new tool(elDef);
55
+ this.serviceContainer.globalContext.tool = tool;
56
+ }
57
+ }
58
+ },
46
59
  dnd: {
47
60
  guessDropEffect: true,
48
- preventRecursion: true,
61
+ preventRecursion: true, // Prevent dropping nodes on own descendants
49
62
  preventVoidMoves: false,
50
63
  serializeClipboardData: false,
51
64
  dragStart: (e) => {
@@ -61,6 +74,7 @@ export class PaletteTreeView extends BaseCustomWebComponentConstructorAppend {
61
74
  });
62
75
  }
63
76
  async loadControls(serviceContainer, elementsServices) {
77
+ this.serviceContainer = serviceContainer;
64
78
  let rootNode = this._tree.root;
65
79
  rootNode.removeChildren();
66
80
  for (const s of elementsServices) {
@@ -70,11 +84,14 @@ export class PaletteTreeView extends BaseCustomWebComponentConstructorAppend {
70
84
  try {
71
85
  let elements = await s.getElements();
72
86
  for (let e of elements) {
73
- newNode.addChildren({
87
+ let node = {
74
88
  title: e.name ?? e.tag,
75
89
  //@ts-ignore
76
90
  ref: e
77
- });
91
+ };
92
+ if (e.icon)
93
+ node.icon = e.icon;
94
+ newNode.addChildren(node);
78
95
  }
79
96
  }
80
97
  catch (err) {
@@ -191,14 +191,14 @@ export class TreeViewExtended extends BaseCustomWebComponentConstructorAppend {
191
191
  }
192
192
  },
193
193
  filter: {
194
- autoApply: true,
195
- autoExpand: true,
196
- counter: true,
197
- fuzzy: true,
198
- hideExpandedCounter: true,
199
- hideExpanders: false,
200
- highlight: true,
201
- leavesOnly: false,
194
+ autoApply: true, // Re-apply last filter if lazy data is loaded
195
+ autoExpand: true, // Expand all branches that contain matches while filtered
196
+ counter: true, // Show a badge with number of matching child nodes near parent icons
197
+ fuzzy: true, // Match single characters in order, e.g. 'fb' will match 'FooBar'
198
+ hideExpandedCounter: true, // Hide counter badge if parent is expanded
199
+ hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
200
+ highlight: true, // Highlight matches by wrapping inside <mark> tags
201
+ leavesOnly: false, // Match end nodes only
202
202
  mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
203
203
  },
204
204
  render: (e) => {
@@ -275,10 +275,15 @@ export class TreeViewExtended extends BaseCustomWebComponentConstructorAppend {
275
275
  }
276
276
  }
277
277
  _highlight(activeElements) {
278
+ let scrolled = false;
278
279
  this._tree.runWithDeferredUpdate(() => {
279
280
  this._tree.visit((node) => {
280
281
  const flag = activeElements && activeElements.includes(node.data.ref);
281
282
  node.setSelected(flag);
283
+ if (flag && !scrolled) {
284
+ scrolled = true;
285
+ node.scrollIntoView();
286
+ }
282
287
  });
283
288
  });
284
289
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "web-component-designer addon: Widgets using wunderbaum",
3
3
  "name": "@node-projects/web-component-designer-widgets-wunderbaum",
4
- "version": "0.1.10",
4
+ "version": "0.1.12",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",