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

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,4 +6,6 @@ export declare class BaseCustomWebcomponentParserService implements IHtmlParserS
6
6
  private htmlParser;
7
7
  constructor(htmlParser: IHtmlParserService);
8
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;
9
11
  }
@@ -10,6 +10,58 @@ export class BaseCustomWebcomponentParserService {
10
10
  this.htmlParser = htmlParser;
11
11
  }
12
12
  async parse(code, serviceContainer, instanceServiceContainer, parseSnippet) {
13
+ const sourceFile = this.parseTypescriptFile(code);
14
+ let htmlCode = "";
15
+ let cssStyle = "";
16
+ const nodes = findAllNodesOfKind(sourceFile, 212);
17
+ for (let nd of nodes) {
18
+ if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template")
19
+ htmlCode = nd.template.rawText;
20
+ if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style")
21
+ cssStyle = nd.template.rawText;
22
+ }
23
+ if (cssStyle)
24
+ instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
25
+ return this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet);
26
+ }
27
+ writeBack(code, html, css, newLineCrLf) {
28
+ const sourceFile = this.parseTypescriptFile(code);
29
+ const transformTemplateLiterals = (context) => (rootNode) => {
30
+ function visit(node) {
31
+ //@ts-ignore
32
+ if (ts.isTemplateLiteral(node) &&
33
+ //@ts-ignore
34
+ ts.isTaggedTemplateExpression(node.parent) &&
35
+ node.parent.tag.escapedText == 'html' &&
36
+ node.parent.parent.name.escapedText == "template") {
37
+ //@ts-ignore
38
+ return ts.factory.createNoSubstitutionTemplateLiteral(html.replaceAll('\n', '\r\n'), html.replaceAll('\n', '\r\n'));
39
+ }
40
+ else if (css &&
41
+ //@ts-ignore
42
+ ts.isTemplateLiteral(node) &&
43
+ //@ts-ignore
44
+ ts.isTaggedTemplateExpression(node.parent) &&
45
+ node.parent.tag.escapedText == 'css' &&
46
+ node.parent.parent.name.escapedText == "style") {
47
+ //@ts-ignore
48
+ return ts.factory.createNoSubstitutionTemplateLiteral(css.replaceAll('\n', '\r\n'), css.replaceAll('\n', '\r\n'));
49
+ }
50
+ //@ts-ignore
51
+ return ts.visitEachChild(node, visit, context);
52
+ }
53
+ //@ts-ignore
54
+ return ts.visitNode(rootNode, visit);
55
+ };
56
+ //@ts-ignore
57
+ let transformed = ts.transform(sourceFile, [transformTemplateLiterals]).transformed[0];
58
+ //@ts-ignore
59
+ const printer = ts.createPrinter({ newLine: newLineCrLf ? ts.NewLineKind.CarriageReturnLineFeed : ts.NewLineKind.LineFeed });
60
+ //@ts-ignore
61
+ const result = printer.printNode(ts.EmitHint.Unspecified, transformed, transformed);
62
+ return result;
63
+ }
64
+ parseTypescriptFile(code) {
13
65
  const compilerHost = {
14
66
  fileExists: () => true,
15
67
  getCanonicalFileName: filename => filename,
@@ -32,16 +84,6 @@ export class BaseCustomWebcomponentParserService {
32
84
  target: ts.ScriptTarget.Latest,
33
85
  }, compilerHost);
34
86
  const sourceFile = program.getSourceFile(filename);
35
- let htmlCode = "";
36
- let cssStyle = "";
37
- const nodes = findAllNodesOfKind(sourceFile, 212);
38
- for (let nd of nodes) {
39
- if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template")
40
- htmlCode = nd.template.rawText;
41
- if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style")
42
- cssStyle = nd.template.rawText;
43
- }
44
- instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
45
- return this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet);
87
+ return sourceFile;
46
88
  }
47
89
  }
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.219",
4
+ "version": "0.0.220",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",