@node-projects/web-component-designer 0.0.220 → 0.0.222

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.
@@ -0,0 +1,11 @@
1
+ import { InstanceServiceContainer } from '../InstanceServiceContainer.js';
2
+ import { ServiceContainer } from '../ServiceContainer.js';
3
+ import { IHtmlParserService } from './IHtmlParserService.js';
4
+ import { IDesignItem } from '../../item/IDesignItem.js';
5
+ export declare class BaseCustomWebcomponentParserService implements IHtmlParserService {
6
+ private htmlParser;
7
+ constructor(htmlParser: IHtmlParserService);
8
+ parse(code: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, parseSnippet: boolean): Promise<IDesignItem[]>;
9
+ writeBack(code: string, html: string, css: string, newLineCrLf: boolean): string;
10
+ private parseTypescriptFile;
11
+ }
@@ -0,0 +1,90 @@
1
+ function* findAllNodesOfKind(node, kind) {
2
+ if (node.kind == kind)
3
+ yield node;
4
+ for (const c of node.getChildren())
5
+ yield* findAllNodesOfKind(c, kind);
6
+ }
7
+ export class BaseCustomWebcomponentParserService {
8
+ htmlParser;
9
+ constructor(htmlParser) {
10
+ this.htmlParser = htmlParser;
11
+ }
12
+ async parse(code, serviceContainer, instanceServiceContainer, parseSnippet) {
13
+ const sourceFile = this.parseTypescriptFile(code);
14
+ let htmlCode = "";
15
+ let cssStyle = "";
16
+ //@ts-ignore
17
+ const nodes = findAllNodesOfKind(sourceFile, ts.SyntaxKind.TaggedTemplateExpression);
18
+ for (let nd of nodes) {
19
+ if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template")
20
+ htmlCode = nd.template.rawText;
21
+ if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style")
22
+ cssStyle = nd.template.rawText;
23
+ }
24
+ if (cssStyle)
25
+ instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
26
+ return this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet);
27
+ }
28
+ writeBack(code, html, css, newLineCrLf) {
29
+ const sourceFile = this.parseTypescriptFile(code);
30
+ const transformTemplateLiterals = (context) => (rootNode) => {
31
+ function visit(node) {
32
+ //@ts-ignore
33
+ if (ts.isTemplateLiteral(node) &&
34
+ //@ts-ignore
35
+ ts.isTaggedTemplateExpression(node.parent) &&
36
+ node.parent.tag.escapedText == 'html' &&
37
+ node.parent.parent.name.escapedText == "template") {
38
+ //@ts-ignore
39
+ return ts.factory.createNoSubstitutionTemplateLiteral(html.replaceAll('\n', '\r\n'), html.replaceAll('\n', '\r\n'));
40
+ }
41
+ else if (css &&
42
+ //@ts-ignore
43
+ ts.isTemplateLiteral(node) &&
44
+ //@ts-ignore
45
+ ts.isTaggedTemplateExpression(node.parent) &&
46
+ node.parent.tag.escapedText == 'css' &&
47
+ node.parent.parent.name.escapedText == "style") {
48
+ //@ts-ignore
49
+ return ts.factory.createNoSubstitutionTemplateLiteral(css.replaceAll('\n', '\r\n'), css.replaceAll('\n', '\r\n'));
50
+ }
51
+ //@ts-ignore
52
+ return ts.visitEachChild(node, visit, context);
53
+ }
54
+ //@ts-ignore
55
+ return ts.visitNode(rootNode, visit);
56
+ };
57
+ //@ts-ignore
58
+ let transformed = ts.transform(sourceFile, [transformTemplateLiterals]).transformed[0];
59
+ //@ts-ignore
60
+ const printer = ts.createPrinter({ newLine: newLineCrLf ? ts.NewLineKind.CarriageReturnLineFeed : ts.NewLineKind.LineFeed });
61
+ //@ts-ignore
62
+ const result = printer.printNode(ts.EmitHint.Unspecified, transformed, transformed);
63
+ return result;
64
+ }
65
+ parseTypescriptFile(code) {
66
+ const compilerHost = {
67
+ fileExists: () => true,
68
+ getCanonicalFileName: filename => filename,
69
+ getCurrentDirectory: () => '',
70
+ getDefaultLibFileName: () => 'lib.d.ts',
71
+ getNewLine: () => '\n',
72
+ getSourceFile: filename => {
73
+ //@ts-ignore
74
+ return ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true);
75
+ },
76
+ readFile: () => null,
77
+ useCaseSensitiveFileNames: () => true,
78
+ writeFile: () => null,
79
+ };
80
+ const filename = 'aa.ts';
81
+ //@ts-ignore
82
+ const program = ts.createProgram([filename], {
83
+ noResolve: true,
84
+ //@ts-ignore
85
+ target: ts.ScriptTarget.Latest,
86
+ }, compilerHost);
87
+ const sourceFile = program.getSourceFile(filename);
88
+ return sourceFile;
89
+ }
90
+ }
@@ -13,7 +13,8 @@ export class BaseCustomWebcomponentParserService {
13
13
  const sourceFile = this.parseTypescriptFile(code);
14
14
  let htmlCode = "";
15
15
  let cssStyle = "";
16
- const nodes = findAllNodesOfKind(sourceFile, 212);
16
+ //@ts-ignore
17
+ const nodes = findAllNodesOfKind(sourceFile, ts.SyntaxKind.TaggedTemplateExpression);
17
18
  for (let nd of nodes) {
18
19
  if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template")
19
20
  htmlCode = nd.template.rawText;
@@ -63,6 +63,8 @@ export class NodeHtmlParserService {
63
63
  }
64
64
  }
65
65
  }
66
+ if (!designItem.lockAtDesignTime && element.style)
67
+ element.style.pointerEvents = 'auto';
66
68
  element.draggable = false; //even if it should be true, for better designer exp.
67
69
  for (let c of item.childNodes) {
68
70
  let di = this._createDesignItemsRecursive(c, serviceContainer, instanceServiceContainer, element instanceof SVGElement ? 'http://www.w3.org/2000/svg' : null, snippet);
@@ -0,0 +1,9 @@
1
+ import { InstanceServiceContainer } from '../InstanceServiceContainer.js';
2
+ import { ServiceContainer } from '../ServiceContainer.js';
3
+ import { IHtmlParserService } from './IHtmlParserService.js';
4
+ import { IDesignItem } from '../../item/IDesignItem.js';
5
+ export declare class VueParserService implements IHtmlParserService {
6
+ private htmlParser;
7
+ constructor(htmlParser: IHtmlParserService);
8
+ parse(code: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, parseSnippet: boolean): Promise<IDesignItem[]>;
9
+ }
@@ -0,0 +1,10 @@
1
+ export class VueParserService {
2
+ htmlParser;
3
+ constructor(htmlParser) {
4
+ this.htmlParser = htmlParser;
5
+ }
6
+ async parse(code, serviceContainer, instanceServiceContainer, parseSnippet) {
7
+ const parsed = await this.htmlParser.parse(code, serviceContainer, instanceServiceContainer, parseSnippet);
8
+ return [parsed.find(x => x.name == 'template')];
9
+ }
10
+ }
@@ -11,6 +11,15 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
11
11
  elementsToPackages: Map<string, string>;
12
12
  code: string;
13
13
  onTextChanged: TypedEvent<string>;
14
+ language: string;
15
+ private _theme;
16
+ get theme(): string;
17
+ set theme(value: string);
18
+ static readonly properties: {
19
+ code: StringConstructor;
20
+ language: StringConstructor;
21
+ theme: StringConstructor;
22
+ };
14
23
  private _monacoEditor;
15
24
  private _editor;
16
25
  static readonly style: CSSStyleSheet;
@@ -18,6 +27,7 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
18
27
  executeCommand(command: IUiCommand): void;
19
28
  canExecuteCommand(command: IUiCommand): boolean;
20
29
  static initMonacoEditor(): Promise<void>;
30
+ constructor();
21
31
  ready(): Promise<void>;
22
32
  focusEditor(): void;
23
33
  activated(): void;
@@ -9,6 +9,21 @@ class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
9
9
  elementsToPackages;
10
10
  code;
11
11
  onTextChanged = new TypedEvent();
12
+ language = 'html';
13
+ _theme = 'webComponentDesignerTheme';
14
+ get theme() {
15
+ return this._theme;
16
+ }
17
+ set theme(value) {
18
+ this._theme = value;
19
+ //@ts-ignore
20
+ monaco.editor.setTheme(value);
21
+ }
22
+ static properties = {
23
+ code: String,
24
+ language: String,
25
+ theme: String
26
+ };
12
27
  //@ts-ignore
13
28
  _monacoEditor;
14
29
  _editor;
@@ -83,7 +98,12 @@ class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
83
98
  }
84
99
  });
85
100
  }
101
+ constructor() {
102
+ super();
103
+ this._restoreCachedInititalValues();
104
+ }
86
105
  async ready() {
106
+ this._parseAttributesToProperties();
87
107
  let style;
88
108
  //@ts-ignore
89
109
  if (window.importShim)
package/dist/index.d.ts CHANGED
@@ -61,6 +61,7 @@ export * from "./elements/services/htmlParserService/BaseCustomWebcomponentParse
61
61
  export * from "./elements/services/htmlParserService/DefaultHtmlParserService.js";
62
62
  export * from "./elements/services/htmlParserService/NodeHtmlParserService.js";
63
63
  export * from "./elements/services/htmlParserService/LitElementParserService.js";
64
+ export * from "./elements/services/htmlParserService/VueParserService.js";
64
65
  export type { IHtmlParserService } from "./elements/services/htmlParserService/IHtmlParserService.js";
65
66
  export type { IIntializationService } from "./elements/services/initializationService/IIntializationService.js";
66
67
  export * from "./elements/services/instanceService/DefaultInstanceService.js";
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ export * from "./elements/services/htmlParserService/BaseCustomWebcomponentParse
39
39
  export * from "./elements/services/htmlParserService/DefaultHtmlParserService.js";
40
40
  export * from "./elements/services/htmlParserService/NodeHtmlParserService.js";
41
41
  export * from "./elements/services/htmlParserService/LitElementParserService.js";
42
+ export * from "./elements/services/htmlParserService/VueParserService.js";
42
43
  export * from "./elements/services/instanceService/DefaultInstanceService.js";
43
44
  export * from "./elements/services/manifestParsers/WebcomponentManifestParserService.js";
44
45
  export * from "./elements/services/modelCommandService/DefaultModelCommandService.js";
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.0.220",
4
+ "version": "0.0.222",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",