@ui5/webcomponents-tools 0.0.0-e463d2345 → 0.0.0-e818f286e
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/CHANGELOG.md +263 -1
- package/README.md +5 -6
- package/assets-meta.js +153 -0
- package/bin/dev.js +12 -1
- package/components-package/nps.js +81 -44
- package/components-package/postcss.themes.js +6 -3
- package/components-package/vite.config.js +12 -0
- package/components-package/wdio.js +118 -65
- package/components-package/wdio.sync.js +360 -0
- package/icons-collection/nps.js +66 -28
- package/lib/copy-and-watch/index.js +145 -0
- package/lib/copy-list/index.js +28 -0
- package/lib/create-icons/index.js +82 -50
- package/lib/create-illustrations/index.js +161 -0
- package/lib/create-new-component/index.js +18 -6
- package/lib/dev-server/dev-server.js +66 -0
- package/lib/dev-server/virtual-index-html-plugin.js +52 -0
- package/lib/esm-abs-to-rel/index.js +58 -0
- package/lib/generate-json-imports/i18n.js +98 -47
- package/lib/generate-json-imports/themes.js +71 -16
- package/lib/hbs2lit/index.js +2 -4
- package/lib/hbs2lit/src/compiler.js +18 -8
- package/lib/hbs2lit/src/includesReplacer.js +23 -17
- package/lib/hbs2lit/src/litVisitor2.js +57 -11
- package/lib/hbs2lit/src/svgProcessor.js +3 -3
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +5 -5
- package/lib/hbs2ui5/index.js +52 -30
- package/lib/i18n/defaults.js +63 -52
- package/lib/i18n/toJSON.js +25 -13
- package/lib/jsdoc/config.json +1 -1
- package/lib/jsdoc/plugin.js +33 -4
- package/lib/jsdoc/template/publish.js +24 -4
- package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
- package/lib/postcss-css-to-esm/index.js +45 -21
- package/lib/postcss-css-to-json/index.js +38 -11
- package/lib/postcss-new-files/index.js +36 -0
- package/lib/postcss-p/postcss-p.mjs +14 -0
- package/lib/replace-global-core/index.js +25 -0
- package/lib/scoping/get-all-tags.js +44 -0
- package/lib/scoping/lint-src.js +31 -0
- package/lib/scoping/missing-dependencies.js +65 -0
- package/lib/scoping/report-tags-usage.js +28 -0
- package/lib/scoping/scope-test-pages.js +40 -0
- package/lib/test-runner/test-runner.js +63 -0
- package/package.json +46 -55
- package/bin/init-ui5-package.js +0 -3
- package/components-package/rollup.js +0 -134
- package/components-package/serve.json +0 -3
- package/lib/documentation/index.js +0 -143
- package/lib/documentation/templates/api-component-since.js +0 -3
- package/lib/documentation/templates/api-css-variables-section.js +0 -24
- package/lib/documentation/templates/api-events-section.js +0 -35
- package/lib/documentation/templates/api-methods-section.js +0 -26
- package/lib/documentation/templates/api-properties-section.js +0 -40
- package/lib/documentation/templates/api-slots-section.js +0 -28
- package/lib/documentation/templates/template.js +0 -38
- package/lib/init-package/index.js +0 -119
- package/lib/init-package/resources/.eslintignore +0 -3
- package/lib/init-package/resources/bundle.es5.js +0 -25
- package/lib/init-package/resources/bundle.esm.js +0 -34
- package/lib/init-package/resources/config/.eslintrc.js +0 -1
- package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
- package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
- package/lib/init-package/resources/config/rollup.config.js +0 -1
- package/lib/init-package/resources/config/wdio.conf.js +0 -1
- package/lib/init-package/resources/package-scripts.js +0 -11
- package/lib/init-package/resources/src/Assets.js +0 -6
- package/lib/init-package/resources/src/Demo.hbs +0 -1
- package/lib/init-package/resources/src/Demo.js +0 -57
- package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
- package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
- package/lib/init-package/resources/src/themes/Demo.css +0 -11
- package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
- package/lib/init-package/resources/test/pages/index.html +0 -51
- package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
@@ -0,0 +1,52 @@
|
|
1
|
+
let path = require("path");
|
2
|
+
|
3
|
+
const virtualIndexPlugin = async () => {
|
4
|
+
const { globby } = await import("globby");
|
5
|
+
const files = await globby(["test/pages/**/*.html", "packages/*/test/pages/**/*.html"]);
|
6
|
+
|
7
|
+
const pagesPerFolder = {};
|
8
|
+
files.forEach(file => {
|
9
|
+
let folder = pagesPerFolder[path.dirname(file)] = pagesPerFolder[path.dirname(file)] || [];
|
10
|
+
folder.push(path.basename(file));
|
11
|
+
});
|
12
|
+
|
13
|
+
const rollupInput = {};
|
14
|
+
|
15
|
+
files.forEach(file => {
|
16
|
+
rollupInput[file] = path.resolve(process.cwd(), file);
|
17
|
+
})
|
18
|
+
|
19
|
+
return {
|
20
|
+
name: 'virtual-index-html',
|
21
|
+
config() {
|
22
|
+
return {
|
23
|
+
build: {
|
24
|
+
rollupOptions: {
|
25
|
+
input: rollupInput
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
},
|
30
|
+
configureServer(server) {
|
31
|
+
server.middlewares.use((req, res, next) => {
|
32
|
+
if (req.url === "/") {
|
33
|
+
const folders = Object.keys(pagesPerFolder);
|
34
|
+
|
35
|
+
res.statusCode = 200;
|
36
|
+
res.end(`${folders.map(folder => {
|
37
|
+
const pages = pagesPerFolder[folder];
|
38
|
+
return `<h1>${folder}</h1>
|
39
|
+
${pages.map(page => {
|
40
|
+
return `<li><a href='${folder}/${page}'>${page}</a></li>`
|
41
|
+
}).join("")}
|
42
|
+
`
|
43
|
+
}).join("")}`);
|
44
|
+
} else {
|
45
|
+
next();
|
46
|
+
}
|
47
|
+
})
|
48
|
+
},
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
module.exports = virtualIndexPlugin;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
const esprima = require("esprima");
|
2
|
+
const escodegen = require("escodegen");
|
3
|
+
|
4
|
+
const fs = require("fs").promises;
|
5
|
+
const path = require("path");
|
6
|
+
const basePath = process.argv[2];
|
7
|
+
|
8
|
+
const convertImports = async (srcPath) => {
|
9
|
+
let changed = false;
|
10
|
+
// console.log("scanning imports of", srcPath);
|
11
|
+
let code = (await fs.readFile(srcPath)).toString();
|
12
|
+
const tree = esprima.parseModule(code);
|
13
|
+
const importer = srcPath.replace(basePath, "");
|
14
|
+
const importerDir = path.dirname(importer);
|
15
|
+
// console.log("-> ", importer);
|
16
|
+
tree.body.forEach(node => {
|
17
|
+
if (node.type === "ImportDeclaration") {
|
18
|
+
let importee = node.source.value;
|
19
|
+
if (importee.startsWith(".")) {
|
20
|
+
// add .js extension if missing
|
21
|
+
if (!importee.endsWith(".js")) {
|
22
|
+
node.source.value += ".js"
|
23
|
+
changed = true;
|
24
|
+
}
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
let importeeDir = path.dirname(importee);
|
28
|
+
let importeeFile = path.basename(importee);
|
29
|
+
let relativePath = path.relative(importerDir, importeeDir);
|
30
|
+
if (relativePath.length === 0) {
|
31
|
+
relativePath = "."
|
32
|
+
}
|
33
|
+
if (!relativePath.startsWith(".")) {
|
34
|
+
relativePath = "./" + relativePath;
|
35
|
+
}
|
36
|
+
|
37
|
+
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
|
38
|
+
let relativeImport = `${relativePath}/${importeeFile}.js`;
|
39
|
+
// console.log(importee + " --> " + relativeImport);
|
40
|
+
node.source.value = relativeImport;
|
41
|
+
changed = true;
|
42
|
+
}
|
43
|
+
});
|
44
|
+
|
45
|
+
if (changed) {
|
46
|
+
return fs.writeFile(srcPath, escodegen.generate(tree));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
const generate = async () => {
|
51
|
+
const { globby } = await import("globby");
|
52
|
+
const fileNames = await globby(basePath + "**/*.js");
|
53
|
+
return Promise.all(fileNames.map(convertImports).filter(x => !!x));
|
54
|
+
};
|
55
|
+
|
56
|
+
generate().then(() => {
|
57
|
+
console.log("Success: Converted absolute imports to relative for files in:", basePath);
|
58
|
+
});
|
@@ -1,47 +1,98 @@
|
|
1
|
-
const fs = require("fs");
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const
|
7
|
-
|
8
|
-
const
|
9
|
-
|
10
|
-
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
${
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require('path');
|
3
|
+
|
4
|
+
const generate = async () => {
|
5
|
+
|
6
|
+
const packageName = JSON.parse(await fs.readFile("package.json")).name;
|
7
|
+
|
8
|
+
const inputFolder = path.normalize(process.argv[2]);
|
9
|
+
const outputFile = path.normalize(`${process.argv[3]}/i18n-static.js`);
|
10
|
+
const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.js`);
|
11
|
+
|
12
|
+
// All languages present in the file system
|
13
|
+
const files = await fs.readdir(inputFolder);
|
14
|
+
const languages = files.map(file => {
|
15
|
+
const matches = file.match(/messagebundle_(.+?).json$/);
|
16
|
+
return matches ? matches[1] : undefined;
|
17
|
+
}).filter(key => !!key);
|
18
|
+
|
19
|
+
let contentStatic, contentDynamic;
|
20
|
+
|
21
|
+
// No i18n - just import dependencies, if any
|
22
|
+
if (languages.length === 0) {
|
23
|
+
contentStatic = "";
|
24
|
+
contentDynamic = "";
|
25
|
+
// There is i18n - generate the full file
|
26
|
+
} else {
|
27
|
+
// Keys for the array
|
28
|
+
const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
|
29
|
+
const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
|
30
|
+
|
31
|
+
// Actual imports for json assets
|
32
|
+
const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
|
33
|
+
|
34
|
+
// static imports
|
35
|
+
contentStatic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
|
36
|
+
|
37
|
+
${assetsImportsString}
|
38
|
+
|
39
|
+
const bundleMap = {
|
40
|
+
${languagesKeysString}
|
41
|
+
};
|
42
|
+
|
43
|
+
const fetchMessageBundle = async (localeId) => {
|
44
|
+
if (typeof bundleMap[localeId] === "object") {
|
45
|
+
// inlined from build
|
46
|
+
throw new Error("[i18n] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs")
|
47
|
+
}
|
48
|
+
return (await fetch(bundleMap[localeId])).json()
|
49
|
+
}
|
50
|
+
|
51
|
+
const localeIds = [${languagesKeysStringArray}];
|
52
|
+
|
53
|
+
localeIds.forEach(localeId => {
|
54
|
+
registerI18nLoader("${packageName}", localeId, fetchMessageBundle);
|
55
|
+
});
|
56
|
+
`;
|
57
|
+
|
58
|
+
// Actual imports for json assets
|
59
|
+
const dynamicImportsString = languages.map(key => ` case "${key}": return (await import("../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
|
60
|
+
|
61
|
+
// Resulting file content
|
62
|
+
contentDynamic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
|
63
|
+
|
64
|
+
const importMessageBundle = async (localeId) => {
|
65
|
+
switch (localeId) {
|
66
|
+
${dynamicImportsString}
|
67
|
+
default: throw "unknown locale"
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
const importAndCheck = async (localeId) => {
|
72
|
+
const data = await importMessageBundle(localeId);
|
73
|
+
if (typeof data === "string" && data.endsWith(".json")) {
|
74
|
+
throw new Error(\`[i18n] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build or use 'import ".../Assets-static.js"'. Check the \"Assets\" documentation for more information.\`);
|
75
|
+
}
|
76
|
+
return data;
|
77
|
+
}
|
78
|
+
|
79
|
+
const localeIds = [${languagesKeysStringArray}];
|
80
|
+
|
81
|
+
localeIds.forEach(localeId => {
|
82
|
+
registerI18nLoader("${packageName}", localeId, importAndCheck);
|
83
|
+
});
|
84
|
+
`;
|
85
|
+
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
await fs.mkdir(path.dirname(outputFile), { recursive: true });
|
90
|
+
return Promise.all([
|
91
|
+
fs.writeFile(outputFile, contentStatic),
|
92
|
+
fs.writeFile(outputFileDynamic, contentDynamic),
|
93
|
+
]);
|
94
|
+
}
|
95
|
+
|
96
|
+
generate().then(() => {
|
97
|
+
console.log("Generated i18n JSON imports.");
|
98
|
+
});
|
@@ -1,25 +1,80 @@
|
|
1
|
-
const fs = require("fs");
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require('path');
|
3
|
+
const assets = require("../../assets-meta.js");
|
2
4
|
|
3
|
-
const
|
5
|
+
const generate = async () => {
|
6
|
+
const inputFolder = path.normalize(process.argv[2]);
|
7
|
+
const outputFile = path.normalize(`${process.argv[3]}/Themes-static.js`);
|
8
|
+
const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.js`);
|
4
9
|
|
5
|
-
//
|
6
|
-
const
|
10
|
+
// All supported optional themes
|
11
|
+
const allThemes = assets.themes.all;
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
// All themes present in the file system
|
14
|
+
const dirs = await fs.readdir(inputFolder);
|
15
|
+
const themesOnFileSystem = dirs.map(dir => {
|
16
|
+
const matches = dir.match(/sap_.*$/);
|
17
|
+
return matches ? dir : undefined;
|
18
|
+
}).filter(key => !!key && allThemes.includes(key));
|
11
19
|
|
20
|
+
const packageName = JSON.parse(await fs.readFile("package.json")).name;
|
21
|
+
|
22
|
+
const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n");
|
23
|
+
const themeUrlsByName = "{\n" + themesOnFileSystem.join(",\n") + "\n}";
|
24
|
+
const availableThemesArray = `[${themesOnFileSystem.map(theme => `"${theme}"`).join(", ")}]`;
|
25
|
+
const dynamicImportLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await import("../assets/themes/${theme}/parameters-bundle.css.json")).default;`).join("\n");
|
26
|
+
|
27
|
+
|
28
|
+
// static imports file content
|
29
|
+
const contentStatic = `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
30
|
+
|
31
|
+
${importLines}
|
32
|
+
|
33
|
+
const themeUrlsByName = ${themeUrlsByName};
|
12
34
|
const isInlined = obj => typeof (obj) === "object";
|
13
35
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
36
|
+
const loadThemeProperties = async (themeName) => {
|
37
|
+
if (typeof themeUrlsByName[themeName] === "object") {
|
38
|
+
// inlined from build
|
39
|
+
throw new Error("[themes] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs");
|
40
|
+
}
|
41
|
+
return (await fetch(themeUrlsByName[themeName])).json();
|
42
|
+
};
|
43
|
+
|
44
|
+
${availableThemesArray}
|
45
|
+
.forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadThemeProperties));
|
46
|
+
`;
|
47
|
+
|
48
|
+
|
49
|
+
// dynamic imports file content
|
50
|
+
const contentDynamic = `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
19
51
|
|
20
|
-
|
21
|
-
|
22
|
-
|
52
|
+
const loadThemeProperties = async (themeName) => {
|
53
|
+
switch (themeName) {
|
54
|
+
${dynamicImportLines}
|
55
|
+
default: throw "unknown theme"
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
const loadAndCheck = async (themeName) => {
|
60
|
+
const data = await loadThemeProperties(themeName);
|
61
|
+
if (typeof data === "string" && data.endsWith(".json")) {
|
62
|
+
throw new Error(\`[themes] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build or use 'import ".../Assets-static.js"'. Check the \"Assets\" documentation for more information.\`);
|
63
|
+
}
|
64
|
+
return data;
|
65
|
+
};
|
66
|
+
|
67
|
+
${availableThemesArray}
|
68
|
+
.forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadAndCheck));
|
23
69
|
`;
|
24
70
|
|
25
|
-
fs.
|
71
|
+
await fs.mkdir(path.dirname(outputFile), { recursive: true });
|
72
|
+
return Promise.all([
|
73
|
+
fs.writeFile(outputFile, contentStatic),
|
74
|
+
fs.writeFile(outputFileDynamic, contentDynamic)
|
75
|
+
]);
|
76
|
+
};
|
77
|
+
|
78
|
+
generate().then(() => {
|
79
|
+
console.log("Generated themes JSON imports.");
|
80
|
+
});
|
package/lib/hbs2lit/index.js
CHANGED
@@ -5,13 +5,16 @@ const includesReplacer = require("./includesReplacer");
|
|
5
5
|
const svgProcessor = require("./svgProcessor");
|
6
6
|
|
7
7
|
const removeWhiteSpaces = (source) => {
|
8
|
-
return source
|
8
|
+
return source
|
9
|
+
.replace(/\s*\r*\n+\s*/g, " ") // Replace new lines and all whitespace between them with a space
|
10
|
+
.replace(/\s*<\s*/g, "<") // Strip whitespace round <
|
11
|
+
.replace(/\s*>\s*/g, ">") // Strip whitespace round >
|
12
|
+
.replace(/}}\s+{{/g, "}}{{"); // Remove whitespace between }} and {{
|
9
13
|
};
|
10
14
|
|
11
|
-
const
|
12
|
-
let sPreprocessed =
|
15
|
+
const hbs2lit = async (file) => {
|
16
|
+
let sPreprocessed = await includesReplacer.replace(file);
|
13
17
|
|
14
|
-
sPreprocessed = await includesReplacer.replace(sPreprocessed, config);
|
15
18
|
sPreprocessed = removeWhiteSpaces(sPreprocessed);
|
16
19
|
|
17
20
|
const ast = Handlebars.parse(sPreprocessed);
|
@@ -27,13 +30,20 @@ const compileString = async (sInput, config) => {
|
|
27
30
|
lv.accept(ast);
|
28
31
|
|
29
32
|
for (let key in lv.blocks) {
|
30
|
-
|
33
|
+
let block = lv.blocks[key];
|
34
|
+
|
35
|
+
if (block.match(/scopeTag/)) {
|
36
|
+
const matches = block.match(/^(.*?)( => )(.*?);$/);
|
37
|
+
const scopedCode = matches[3];
|
38
|
+
const normalCode = scopedCode.replace(/\${scopeTag\("/g, "").replace(/", tags, suffix\)}/g, "");
|
39
|
+
block = `${matches[1]}${matches[2]}suffix ? ${scopedCode} : ${normalCode};`;
|
40
|
+
}
|
41
|
+
|
42
|
+
result += block + "\n";
|
31
43
|
}
|
32
44
|
|
33
45
|
result = svgProcessor.process(result);
|
34
46
|
return result;
|
35
47
|
};
|
36
48
|
|
37
|
-
module.exports =
|
38
|
-
compileString
|
39
|
-
};
|
49
|
+
module.exports = hbs2lit;
|
@@ -1,25 +1,31 @@
|
|
1
1
|
const path = require("path");
|
2
|
-
const
|
3
|
-
const nativeFs = require("fs");
|
2
|
+
const fs = require("fs").promises;
|
4
3
|
|
5
|
-
|
6
|
-
const
|
7
|
-
|
8
|
-
const inclRegex = /{{>\s*include\s*["']([a-zA-Z.\/]+)["']}}/g;
|
9
|
-
|
10
|
-
async function replacer(match, p1) {
|
11
|
-
const includeContent = await readFile(path.join(config.templatesPath, p1), "utf-8");
|
12
|
-
hbs = hbs.replace(match, includeContent);
|
13
|
-
}
|
4
|
+
const replaceIncludes = async (file) => {
|
5
|
+
const filePath = path.dirname(file);
|
6
|
+
let fileContent = await fs.readFile(file, "utf-8");
|
14
7
|
|
8
|
+
const inclRegex = /{{>\s*include\s*["'](.+?)["']}}/g;
|
15
9
|
let match;
|
16
|
-
|
17
|
-
while
|
18
|
-
|
10
|
+
|
11
|
+
while((match = inclRegex.exec(fileContent)) !== null) {
|
12
|
+
inclRegex.lastIndex = 0;
|
13
|
+
|
14
|
+
let targetFile = match[1];
|
15
|
+
if (targetFile.startsWith(".")) {
|
16
|
+
// Relative path, f.e. {{>include "./Popup.hbs"}} or {{>include "../partials/Header.hbs"}}
|
17
|
+
targetFile = path.join(filePath, targetFile);
|
18
|
+
} else {
|
19
|
+
// Node module path, f.e. {{>include "@ui5/webcomponents/src/Popup.hbs"}}
|
20
|
+
targetFile = require.resolve(targetFile);
|
21
|
+
}
|
22
|
+
|
23
|
+
fileContent = fileContent.replace(match[0], await replaceIncludes(targetFile));
|
19
24
|
}
|
20
|
-
|
21
|
-
|
25
|
+
|
26
|
+
return fileContent;
|
27
|
+
};
|
22
28
|
|
23
29
|
module.exports = {
|
24
30
|
replace: replaceIncludes
|
25
|
-
};
|
31
|
+
};
|
@@ -2,6 +2,32 @@ const Handlebars = require("handlebars/dist/handlebars.min.js");
|
|
2
2
|
const path = require("path");
|
3
3
|
const Visitor = Handlebars.Visitor;
|
4
4
|
|
5
|
+
// skip ifDefined for event handlers and boolean attrs
|
6
|
+
let skipIfDefined = false;
|
7
|
+
|
8
|
+
// when true => an HTML node value, when false => an attribute value
|
9
|
+
let isNodeValue = false;
|
10
|
+
|
11
|
+
// when true => the current attribute is "style"
|
12
|
+
let isStyleAttribute = false;
|
13
|
+
|
14
|
+
// matches event handlers @click= and boolean attrs ?disabled=
|
15
|
+
const dynamicAttributeRgx = /\s(\?|@)([a-zA-Z|-]+)="?\s*$/;
|
16
|
+
|
17
|
+
if (!String.prototype.replaceAll) {
|
18
|
+
String.prototype.replaceAll = function(str, newStr){
|
19
|
+
|
20
|
+
// If a regex pattern
|
21
|
+
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
|
22
|
+
return this.replace(str, newStr);
|
23
|
+
}
|
24
|
+
|
25
|
+
// If a string
|
26
|
+
return this.replace(new RegExp(str, 'g'), newStr);
|
27
|
+
|
28
|
+
};
|
29
|
+
}
|
30
|
+
|
5
31
|
function HTMLLitVisitor(debug) {
|
6
32
|
this.blockCounter = 0;
|
7
33
|
this.keys = [];
|
@@ -9,7 +35,7 @@ function HTMLLitVisitor(debug) {
|
|
9
35
|
this.result = "";
|
10
36
|
this.mainBlock = "";
|
11
37
|
this.blockPath = "context";
|
12
|
-
this.blockParameters = ["context"];
|
38
|
+
this.blockParameters = ["context", "tags", "suffix"];
|
13
39
|
this.paths = []; //contains all normalized relative paths
|
14
40
|
this.debug = debug;
|
15
41
|
if (this.debug) {
|
@@ -25,7 +51,7 @@ HTMLLitVisitor.prototype.Program = function(program) {
|
|
25
51
|
this.keys.push(key);
|
26
52
|
this.debug && this.blockByNumber.push(key);
|
27
53
|
|
28
|
-
this.blocks[this.currentKey()] = "const " + this.currentKey() + " = (" + this.blockParameters.join(", ") + ") =>
|
54
|
+
this.blocks[this.currentKey()] = "const " + this.currentKey() + " = (" + this.blockParameters.join(", ") + ") => ";
|
29
55
|
|
30
56
|
if (this.keys.length > 1) { //it's a nested block
|
31
57
|
this.blocks[this.prevKey()] += this.currentKey() + "(" + this.blockParameters.join(", ") + ")";
|
@@ -36,7 +62,7 @@ HTMLLitVisitor.prototype.Program = function(program) {
|
|
36
62
|
|
37
63
|
this.blocks[this.currentKey()] += "html`";
|
38
64
|
Visitor.prototype.Program.call(this, program);
|
39
|
-
this.blocks[this.currentKey()] += "`;
|
65
|
+
this.blocks[this.currentKey()] += "`;";
|
40
66
|
|
41
67
|
this.keys.pop(key);
|
42
68
|
};
|
@@ -45,8 +71,25 @@ HTMLLitVisitor.prototype.ContentStatement = function(content) {
|
|
45
71
|
Visitor.prototype.ContentStatement.call(this, content);
|
46
72
|
// let content = content.orgiinal; // attribute="__ attribute = "__ attribute ="__
|
47
73
|
|
48
|
-
|
74
|
+
let contentStatement = content.original;
|
75
|
+
skipIfDefined = !!dynamicAttributeRgx.exec(contentStatement);
|
76
|
+
|
77
|
+
const closingIndex = contentStatement.lastIndexOf(">");
|
78
|
+
const openingIndex = contentStatement.lastIndexOf("<");
|
79
|
+
if (closingIndex !== -1 || openingIndex !== -1) { // Only change isNodeValue whenever < or > is found in the content statement
|
80
|
+
isNodeValue = closingIndex > openingIndex;
|
81
|
+
}
|
82
|
+
|
83
|
+
isStyleAttribute = !isNodeValue && contentStatement.match(/style *= *["']? *$/);
|
49
84
|
|
85
|
+
if (!isStyleAttribute && contentStatement.match(/style=/)) {
|
86
|
+
console.log("WARNING: style hard-coded", contentStatement);
|
87
|
+
}
|
88
|
+
|
89
|
+
// Scope custom element tags
|
90
|
+
contentStatement = contentStatement.replaceAll(/(<\/?\s*)([a-zA-Z0-9_]+-[a-zA-Z0-9_-]+)/g, "$1\${scopeTag(\"$2\", tags, suffix)}");
|
91
|
+
|
92
|
+
this.blocks[this.currentKey()] += contentStatement;
|
50
93
|
};
|
51
94
|
|
52
95
|
HTMLLitVisitor.prototype.MustacheStatement = function(mustache) {
|
@@ -57,14 +100,17 @@ HTMLLitVisitor.prototype.MustacheStatement = function(mustache) {
|
|
57
100
|
} else {
|
58
101
|
const path = normalizePath.call(this, mustache.path.original);
|
59
102
|
const hasCalculatingClasses = path.includes("context.classes");
|
60
|
-
|
61
|
-
|
103
|
+
|
62
104
|
let parsedCode = "";
|
63
105
|
|
64
|
-
if (
|
65
|
-
parsedCode = `\${
|
66
|
-
} else if (
|
67
|
-
parsedCode = `\${
|
106
|
+
if (isNodeValue && !mustache.escaped) {
|
107
|
+
parsedCode = `\${unsafeHTML(${path})}`;
|
108
|
+
} else if (hasCalculatingClasses) {
|
109
|
+
parsedCode = `\${classMap(${path})}`;
|
110
|
+
} else if (isStyleAttribute) {
|
111
|
+
parsedCode = `\${styleMap(${path})}`;
|
112
|
+
} else if (skipIfDefined){
|
113
|
+
parsedCode = `\${${path}}`;
|
68
114
|
} else {
|
69
115
|
parsedCode = `\${ifDefined(${path})}`;
|
70
116
|
}
|
@@ -125,7 +171,7 @@ function visitEachBlock(block) {
|
|
125
171
|
var bParamAdded = false;
|
126
172
|
visitSubExpression.call(this, block);
|
127
173
|
|
128
|
-
this.blocks[this.currentKey()] += "${ repeat(" + normalizePath.call(this, block.params[0].original) + ",
|
174
|
+
this.blocks[this.currentKey()] += "${ repeat(" + normalizePath.call(this, block.params[0].original) + ", (item, index) => item._id || index, (item, index) => ";
|
129
175
|
this.paths.push(normalizePath.call(this, block.params[0].original));
|
130
176
|
this.blockPath = "item";
|
131
177
|
|
@@ -46,8 +46,8 @@ function getSVGMatches(template) {
|
|
46
46
|
|
47
47
|
function getSVGBlock(input, blockCounter) {
|
48
48
|
return {
|
49
|
-
usage: `\${blockSVG${blockCounter}(context)}`,
|
50
|
-
definition: `\nconst blockSVG${blockCounter} = (context) =>
|
49
|
+
usage: `\${blockSVG${blockCounter}(context, tags, suffix)}`,
|
50
|
+
definition: `\nconst blockSVG${blockCounter} = (context, tags, suffix) => svg\`${input}\`;`,
|
51
51
|
};
|
52
52
|
}
|
53
53
|
|
@@ -55,7 +55,7 @@ function replaceInternalBlocks(template, svgContent) {
|
|
55
55
|
const internalBlocks = svgContent.match(blockrx) || [];
|
56
56
|
|
57
57
|
internalBlocks.forEach(blockName => {
|
58
|
-
const rx = new RegExp(`const ${blockName}.*(html\`)
|
58
|
+
const rx = new RegExp(`const ${blockName}.*(html\`).*;`);
|
59
59
|
template = template.replace(rx, (match, p1) => {
|
60
60
|
return match.replace(p1, "svg\`");
|
61
61
|
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
const buildRenderer = (controlName, litTemplate) => {
|
2
|
-
return
|
3
|
-
|
4
|
-
|
5
|
-
import { html, svg, repeat, classMap, styleMap } from '@ui5/webcomponents-base/dist/renderer/LitRenderer.js';
|
2
|
+
return `/* eslint no-unused-vars: 0 */
|
3
|
+
import { html, svg, repeat, classMap, styleMap, ifDefined, unsafeHTML, scopeTag } from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
|
4
|
+
|
6
5
|
${litTemplate}
|
7
|
-
|
6
|
+
|
7
|
+
export default block0;`;
|
8
8
|
};
|
9
9
|
|
10
10
|
module.exports = {
|