@node-projects/web-component-designer 0.1.100 → 0.1.102

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.
@@ -2,6 +2,7 @@ import { BaseCustomWebComponentLazyAppend, css, cssFromString, debounce, TypedEv
2
2
  import { DesignerTabControl } from './controls/DesignerTabControl.js';
3
3
  import { DesignerView } from './widgets/designerView/designerView.js';
4
4
  import { SimpleSplitView } from './controls/SimpleSplitView.js';
5
+ import { sleep } from "./helper/Helper.js";
5
6
  export class DocumentContainer extends BaseCustomWebComponentLazyAppend {
6
7
  designerView;
7
8
  codeView;
@@ -115,10 +116,11 @@ export class DocumentContainer extends BaseCustomWebComponentLazyAppend {
115
116
  if (this._tabControl.selectedIndex === 2) {
116
117
  let primarySelection = this.instanceServiceContainer.selectionService.primarySelection;
117
118
  if (primarySelection) {
118
- this._content = this.designerView.getHTML();
119
+ //this._content = this.designerView.getHTML();
119
120
  if (this.designerView.instanceServiceContainer.designItemDocumentPositionService) {
120
121
  this._selectionPosition = this.designerView.instanceServiceContainer.designItemDocumentPositionService.getPosition(primarySelection);
121
- this.codeView.setSelection(this._selectionPosition);
122
+ if (this._selectionPosition)
123
+ this.codeView.setSelection(this._selectionPosition);
122
124
  this._selectionPosition = null;
123
125
  }
124
126
  }
@@ -216,7 +218,11 @@ export class DocumentContainer extends BaseCustomWebComponentLazyAppend {
216
218
  this.codeView.update(this._content, this.designerView.instanceServiceContainer);
217
219
  if (this._selectionPosition) {
218
220
  this.codeView.setSelection(this._selectionPosition);
219
- this._selectionPosition = null;
221
+ sleep(20).then(x => {
222
+ if (this._selectionPosition)
223
+ this.codeView.setSelection(this._selectionPosition);
224
+ this._selectionPosition = null;
225
+ });
220
226
  }
221
227
  if (i.changedViaClick) {
222
228
  this.codeView.focusEditor();
@@ -102,6 +102,8 @@ export class HtmlWriterService extends AbstractHtmlWriterService {
102
102
  }
103
103
  }
104
104
  writeTextNode(indentedTextWriter, designItem, indentAndNewline, trim = true) {
105
+ let start = indentedTextWriter.position;
106
+ let end = indentedTextWriter.position;
105
107
  let content = DomConverter.normalizeContentValue(designItem.content);
106
108
  if (trim)
107
109
  content = content.trim();
@@ -112,5 +114,8 @@ export class HtmlWriterService extends AbstractHtmlWriterService {
112
114
  if (indentAndNewline)
113
115
  this._conditionalyWriteNewline(indentedTextWriter, designItem);
114
116
  }
117
+ end = indentedTextWriter.position;
118
+ for (const d of designItem.children())
119
+ designItem.instanceServiceContainer.designItemDocumentPositionService.setPosition(d, { start: start, length: end - start });
115
120
  }
116
121
  }
@@ -6,7 +6,7 @@ function findDesignItem(designItem, position) {
6
6
  for (let d of designItem.children()) {
7
7
  const nodePosition = designItem.instanceServiceContainer.designItemDocumentPositionService.getPosition(d);
8
8
  if (nodePosition) {
9
- if (nodePosition.start <= position)
9
+ if (nodePosition.start <= position && nodePosition.start + nodePosition.length >= position)
10
10
  usedItem = d;
11
11
  }
12
12
  }
@@ -195,9 +195,9 @@ export class DebugView extends BaseCustomWebComponentConstructorAppend {
195
195
  if (this._ready) {
196
196
  requestAnimationFrame(() => {
197
197
  let element = designItem?.element;
198
- if (element && element.nodeType != 8) {
199
- if (element.nodeType == 3)
200
- element = element.parentNode;
198
+ if (element?.nodeType == 3)
199
+ element = element.parentNode;
200
+ if (element && element.nodeType != 8 && element.nodeType != 11) {
201
201
  this.computedStyle = getComputedStyle(element);
202
202
  this.selectedElementOffsetParent = element.offsetParent;
203
203
  if (this.selectedElementOffsetParent == designItem.instanceServiceContainer.designerCanvas.rootDesignItem.element) {
@@ -122,4 +122,4 @@ export class PropertyGrid extends BaseCustomWebComponentLazyAppend {
122
122
  });
123
123
  }
124
124
  }
125
- customElements.define('node-projects-property-grid', PropertyGrid);
125
+ customElements.define('node-projects-web-component-designer-property-grid', PropertyGrid);
@@ -53,7 +53,7 @@ export class PropertyGridWithHeader extends BaseCustomWebComponentLazyAppend {
53
53
  <div title="textContent" id="contentRect" style="width: 7px; height: 7px; border: 1px solid white;"></div>
54
54
  <span class="desc">Content:</span><input type="text" id="content">
55
55
  </div>
56
- <node-projects-property-grid id="pg"></node-projects-property-grid>`;
56
+ <node-projects-web-component-designer-property-grid id="pg"></node-projects-web-component-designer-property-grid>`;
57
57
  _type;
58
58
  _id;
59
59
  _content;
@@ -167,4 +167,4 @@ export class PropertyGridWithHeader extends BaseCustomWebComponentLazyAppend {
167
167
  });
168
168
  }
169
169
  }
170
- customElements.define('node-projects-property-grid-with-header', PropertyGridWithHeader);
170
+ customElements.define('node-projects-web-component-designer-property-grid-with-header', PropertyGridWithHeader);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "A UI designer for Polymer apps",
3
3
  "name": "@node-projects/web-component-designer",
4
- "version": "0.1.100",
4
+ "version": "0.1.102",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -1,2 +0,0 @@
1
- declare function getProtoProperties(target: any): string[];
2
- declare function getAttributesIfCustomElement(target: any): any;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- function getProtoProperties(target) {
3
- // If this is a custom element, you need to go up the prototype
4
- // chain until you get proper HTMLElement, since everything under it
5
- // is generated prototypes and will have propeties that are dupes (like:
6
- // every observedAttribute is also mirrored as a property)
7
- const isCustomElement = target.tagName.indexOf('-') !== -1;
8
- let proto = target.__proto__;
9
- if (isCustomElement) {
10
- while (proto.constructor !== window.HTMLElement.prototype.constructor) {
11
- proto = proto.__proto__;
12
- }
13
- }
14
- let protoProps = {};
15
- // We literally want nothing other than 'href' and 'target' from HTMLAnchorElement.
16
- if (proto.constructor.name === 'HTMLAnchorElement') {
17
- protoProps['href'] = Object.getOwnPropertyDescriptors(proto).href;
18
- protoProps['target'] = Object.getOwnPropertyDescriptors(proto).target;
19
- proto = proto.__proto__;
20
- }
21
- while (proto.constructor.name !== 'Element') {
22
- Object.assign(protoProps, Object.getOwnPropertyDescriptors(proto));
23
- proto = proto.__proto__;
24
- }
25
- let propNames = Object.keys(protoProps).sort();
26
- // Skip some very specific Polymer/element properties.
27
- let blacklist = [
28
- // Polymer specific
29
- 'isAttached',
30
- 'constructor', 'created', 'ready', 'attached', 'detached',
31
- 'attributeChanged', 'is', 'listeners', 'observers', 'properties',
32
- // Native elements ones we don't care about
33
- 'validity', 'useMap', 'innerText', 'outerText', 'style', 'accessKey',
34
- 'draggable', 'lang', 'spellcheck', 'tabIndex', 'translate', 'align', 'dir',
35
- 'isMap', 'useMap', 'hspace', 'vspace', 'referrerPolicy', 'crossOrigin',
36
- 'lowsrc', 'longDesc',
37
- // Specific elements stuff
38
- 'receivedFocusFromKeyboard', 'pointerDown', 'valueAsNumber',
39
- 'selectionDirection', 'selectionStart', 'selectionEnd'
40
- ];
41
- let i = 0;
42
- while (i < propNames.length) {
43
- let name = propNames[i];
44
- // Skip everything that starts with a _ which is a Polymer private/protected
45
- // and you probably don't care about it.
46
- // Also anything in the blacklist. Or that starts with webkit.
47
- if (name.charAt(0) === '_' ||
48
- name === 'keyEventTarget' ||
49
- blacklist.indexOf(name) !== -1 ||
50
- name.indexOf('webkit') === 0 ||
51
- name.indexOf('on') === 0) {
52
- propNames.splice(i, 1);
53
- continue;
54
- }
55
- // Skip everything that doesn't have a setter.
56
- if (!protoProps[name].set) {
57
- propNames.splice(i, 1);
58
- continue;
59
- }
60
- i++;
61
- }
62
- return propNames || [];
63
- }
64
- function getAttributesIfCustomElement(target) {
65
- if (target.tagName.indexOf('-') !== -1) {
66
- return target.constructor.observedAttributes;
67
- }
68
- else {
69
- return [];
70
- }
71
- }
@@ -1,6 +0,0 @@
1
- import { BaseCustomWebComponentConstructorAppend } from '@node-projects/base-custom-webcomponent';
2
- export declare class DrawToolPopup extends BaseCustomWebComponentConstructorAppend {
3
- static style: CSSStyleSheet;
4
- static template: HTMLTemplateElement;
5
- constructor();
6
- }
@@ -1,102 +0,0 @@
1
- import { html, BaseCustomWebComponentConstructorAppend, css } from '@node-projects/base-custom-webcomponent';
2
- import { assetsPath } from "../../../../../../Constants.js";
3
- export class DrawToolPopup extends BaseCustomWebComponentConstructorAppend {
4
- static style = css `
5
- .container {
6
- width: 220px;
7
- min-height: 200px;
8
- color: white;
9
- background-color: rgb(64, 64, 64);
10
- border: 1px solid black;
11
- }
12
- header {
13
- text-align: center;
14
- }
15
- .tool {
16
- height: 32px;
17
- width: 32px;
18
- background-color: rgb(255, 255, 255);
19
- background-size: 65%;
20
- background-repeat: no-repeat;
21
- background-position: center center;
22
- flex-shrink: 0;
23
- border-bottom: 1px solid black;
24
- }
25
- .tools {
26
- display: flex;
27
- flex-wrap: wrap;
28
- margin-bottom: 5px;
29
- }
30
- .inputs{
31
- float: left;
32
- margin-top: 5px;
33
- align-items: center;
34
- }
35
- .input {
36
- display: flex;
37
- align-items: center;
38
- margin-top: 5px;
39
- }
40
- .text {
41
- margin-left: 5px;
42
- font-size: 14px;
43
- }
44
- .strokecolor{
45
- float: both;
46
- }
47
- .fillbrush{
48
- float: both;
49
- }
50
- .strokethickness{
51
- float: both;
52
- }
53
-
54
- `;
55
- static template = html `
56
- <div class="container">
57
- <header><h2 id="title" style="margin: 0;">Draw</h2></header>
58
- <main id="content-area">
59
- <div class="tools">
60
- <div class="tool" data-command="setTool" data-command-parameter="DrawLine" title="Draw Line" style="background-image: url('${assetsPath}images/layout/DrawLineTool.svg');"></div>
61
- <div class="tool" data-command="setTool" data-command-parameter="DrawPath" title="Pointer Tool" style="background-image: url('${assetsPath}images/layout/DrawPathTool.svg');"></div>
62
- <div class="tool" data-command="setTool" data-command-parameter="DrawRect" title="Draw Rectangle" style="background-image: url('${assetsPath}images/layout/DrawRectTool.svg');"></div>
63
- <div class="tool" data-command="setTool" data-command-parameter="DrawEllipsis" title="Draw Ellipsis" style="background-image: url('${assetsPath}images/layout/DrawEllipTool.svg');"></div>
64
- <div class="tool" data-command="setTool" data-command-parameter="PickColor" title="Pick Color" style="background-image: url('${assetsPath}images/layout/ColorPickerTool.svg');"></div>
65
- </div>
66
- <div class="inputs">
67
- <div class="input">
68
- <input id="strokecolor" class="strokecolor" type="color" title="stroke color" value="#000000" style="padding: 0; width:31px; height:31px;">
69
- <text class="text">Stroke Color</text>
70
- </div>
71
- <div class="input">
72
- <input id="fillbrush" class="fillbrush" type="color" title="fill brush" value="#ffffff" style="padding: 0; width:31px; height:31px;">
73
- <text class="text">Fill Brush</text>
74
- </div>
75
- <div class="input">
76
- <input id="strokethickness" class="strokethickness" type="range" title="stroke thickness" min="1" max="20" value="3" style="padding: 0; width:80px; height:20px; margin-right: 5px;">
77
- <text class="text">Stroke Thickness</text>
78
- </div>
79
- </div>
80
- </main>
81
- </div>`;
82
- constructor() {
83
- super();
84
- for (let e of [...this.shadowRoot.querySelectorAll("div.tool")]) {
85
- let div = e;
86
- div.onclick = () => this.getRootNode().host.setTool(div.dataset['commandParameter']);
87
- }
88
- if (this.shadowRoot.querySelector("input.strokecolor")) {
89
- let input = this._getDomElement("strokecolor");
90
- input.onchange = () => this.getRootNode().host.setStrokeColor(input.value);
91
- }
92
- if (this.shadowRoot.querySelector("input.fillbrush")) {
93
- let input = this._getDomElement("fillbrush");
94
- input.onchange = () => this.getRootNode().host.setFillBrush(input.value);
95
- }
96
- if (this.shadowRoot.querySelector("input.strokethickness")) {
97
- let input = this._getDomElement("strokethickness");
98
- input.onchange = () => this.getRootNode().host.setStrokeThickness(input.value);
99
- }
100
- }
101
- }
102
- customElements.define('node-projects-designer-drawtool-popup', DrawToolPopup);