lapikit 0.3.4 → 0.3.6
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TextfieldProps } from './types.js';
|
|
2
|
-
declare const Textfield: import("svelte").Component<TextfieldProps, {}, "
|
|
2
|
+
declare const Textfield: import("svelte").Component<TextfieldProps, {}, "ref" | "value">;
|
|
3
3
|
type Textfield = ReturnType<typeof Textfield>;
|
|
4
4
|
export default Textfield;
|
package/dist/entry-bundler.d.ts
CHANGED
package/dist/entry-bundler.js
CHANGED
|
@@ -2,23 +2,58 @@ const components = ['btn'];
|
|
|
2
2
|
function componentName(shortName) {
|
|
3
3
|
return 'Kit' + shortName.charAt(0).toUpperCase() + shortName.slice(1);
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
// plugins lapikit
|
|
6
|
+
const lapikitPlugins = {
|
|
7
|
+
repl: {
|
|
8
|
+
components: ['repl'],
|
|
9
|
+
ref: '@lapikit/repl'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function lapikitPreprocess(options) {
|
|
6
13
|
return {
|
|
7
14
|
markup({ content }) {
|
|
8
|
-
const
|
|
15
|
+
const allComponents = [...components];
|
|
16
|
+
const componentToRef = new Map();
|
|
17
|
+
components.forEach((comp) => {
|
|
18
|
+
componentToRef.set(comp, 'lapikit/labs/components');
|
|
19
|
+
});
|
|
20
|
+
// plugins
|
|
21
|
+
if (options?.plugins) {
|
|
22
|
+
options.plugins.forEach((pluginKey) => {
|
|
23
|
+
const plugin = lapikitPlugins[pluginKey];
|
|
24
|
+
if (plugin) {
|
|
25
|
+
plugin.components.forEach((comp) => {
|
|
26
|
+
if (!allComponents.includes(comp)) {
|
|
27
|
+
allComponents.push(comp);
|
|
28
|
+
}
|
|
29
|
+
componentToRef.set(comp, plugin.ref);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const hasComponent = allComponents.some((comp) => content.includes(`<kit:${comp}`));
|
|
9
35
|
if (!hasComponent)
|
|
10
36
|
return;
|
|
11
37
|
let processedContent = content;
|
|
12
|
-
const importedComponents = new
|
|
38
|
+
const importedComponents = new Map();
|
|
13
39
|
let hasChanges = true;
|
|
14
40
|
while (hasChanges) {
|
|
15
41
|
hasChanges = false;
|
|
16
|
-
for (const shortName of
|
|
42
|
+
for (const shortName of allComponents) {
|
|
17
43
|
const componentNameStr = componentName(shortName);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
44
|
+
const attrPattern = `(?:[^>"']|"[^"]*"|'[^']*')*?`;
|
|
45
|
+
const selfClosingRegex = new RegExp(`<kit:${shortName}(${attrPattern})\\s*/>`, 'g');
|
|
46
|
+
const pairRegex = new RegExp(`<kit:${shortName}(${attrPattern})>([\\s\\S]*?)<\\/kit:${shortName}\\s*>`, 'g');
|
|
47
|
+
let newContent = processedContent.replace(selfClosingRegex, (fullMatch, attrs) => {
|
|
48
|
+
hasChanges = true;
|
|
49
|
+
const ref = componentToRef.get(shortName) || 'lapikit/labs/components';
|
|
50
|
+
importedComponents.set(componentNameStr, ref);
|
|
51
|
+
return `<${componentNameStr}${attrs} />`;
|
|
52
|
+
});
|
|
53
|
+
newContent = newContent.replace(pairRegex, (fullMatch, attrs, children) => {
|
|
20
54
|
hasChanges = true;
|
|
21
|
-
|
|
55
|
+
const ref = componentToRef.get(shortName) || 'lapikit/labs/components';
|
|
56
|
+
importedComponents.set(componentNameStr, ref);
|
|
22
57
|
return `<${componentNameStr}${attrs}>${children}</${componentNameStr}>`;
|
|
23
58
|
});
|
|
24
59
|
if (newContent !== processedContent) {
|
|
@@ -29,15 +64,25 @@ function lapikitPreprocess() {
|
|
|
29
64
|
if (processedContent === content)
|
|
30
65
|
return;
|
|
31
66
|
if (importedComponents.size > 0) {
|
|
32
|
-
const
|
|
67
|
+
const importsByRef = new Map();
|
|
68
|
+
importedComponents.forEach((ref, component) => {
|
|
69
|
+
if (!importsByRef.has(ref)) {
|
|
70
|
+
importsByRef.set(ref, []);
|
|
71
|
+
}
|
|
72
|
+
importsByRef.get(ref).push(component);
|
|
73
|
+
});
|
|
74
|
+
const importLines = Array.from(importsByRef.entries())
|
|
75
|
+
.map(([ref, components]) => {
|
|
76
|
+
const imports = components.join(', ');
|
|
77
|
+
return `\n\timport { ${imports} } from '${ref}';`;
|
|
78
|
+
})
|
|
79
|
+
.join('');
|
|
33
80
|
const scriptRegex = /<script(?![^>]*\bmodule\b)([^>]*)>/;
|
|
34
81
|
const scriptMatch = processedContent.match(scriptRegex);
|
|
35
82
|
if (scriptMatch && scriptMatch.index !== undefined) {
|
|
36
83
|
const insertPos = scriptMatch.index + scriptMatch[0].length;
|
|
37
84
|
processedContent =
|
|
38
|
-
processedContent.slice(0, insertPos) +
|
|
39
|
-
`\n\timport { ${imports} } from 'lapikit/labs/components';` +
|
|
40
|
-
processedContent.slice(insertPos);
|
|
85
|
+
processedContent.slice(0, insertPos) + importLines + processedContent.slice(insertPos);
|
|
41
86
|
}
|
|
42
87
|
else {
|
|
43
88
|
const moduleScriptMatch = processedContent.match(/<script[^>]*\bmodule\b[^>]*>/);
|
|
@@ -45,13 +90,11 @@ function lapikitPreprocess() {
|
|
|
45
90
|
const moduleScriptEnd = processedContent.indexOf('</script>', moduleScriptMatch.index) + '</script>'.length;
|
|
46
91
|
processedContent =
|
|
47
92
|
processedContent.slice(0, moduleScriptEnd) +
|
|
48
|
-
`\n\n<script
|
|
93
|
+
`\n\n<script>${importLines}\n</script>` +
|
|
49
94
|
processedContent.slice(moduleScriptEnd);
|
|
50
95
|
}
|
|
51
96
|
else {
|
|
52
|
-
processedContent =
|
|
53
|
-
`<script>\n\timport { ${imports} } from 'lapikit/labs/components';\n</script>\n\n` +
|
|
54
|
-
processedContent;
|
|
97
|
+
processedContent = `<script>${importLines}\n</script>\n\n` + processedContent;
|
|
55
98
|
}
|
|
56
99
|
}
|
|
57
100
|
}
|