@lapikit/repl 0.0.0-insiders.e221561 → 0.0.0-insiders.e242cea
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/dist/Repl.svelte +4 -0
- package/dist/components.d.ts +1 -0
- package/dist/components.js +2 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +71 -2
- package/package.json +6 -3
package/dist/Repl.svelte
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as KitCode } from './Repl.svelte';
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const components = ['code'];
|
|
2
|
+
function componentName(shortName) {
|
|
3
|
+
return 'Kit' + shortName.charAt(0).toUpperCase() + shortName.slice(1);
|
|
4
|
+
}
|
|
5
|
+
function replPreprocess() {
|
|
6
|
+
return {
|
|
7
|
+
markup({ content }) {
|
|
8
|
+
const hasComponent = components.some((comp) => content.includes(`<repl:${comp}`));
|
|
9
|
+
if (!hasComponent)
|
|
10
|
+
return;
|
|
11
|
+
let processedContent = content;
|
|
12
|
+
const importedComponents = new Set();
|
|
13
|
+
let hasChanges = true;
|
|
14
|
+
while (hasChanges) {
|
|
15
|
+
hasChanges = false;
|
|
16
|
+
for (const shortName of components) {
|
|
17
|
+
const componentNameStr = componentName(shortName);
|
|
18
|
+
const attrPattern = `(?:[^>"']|"[^"]*"|'[^']*')*?`;
|
|
19
|
+
const selfClosingRegex = new RegExp(`<repl:${shortName}(${attrPattern})\\s*/>`, 'g');
|
|
20
|
+
const pairRegex = new RegExp(`<repl:${shortName}(${attrPattern})>([\\s\\S]*?)<\\/repl:${shortName}\\s*>`, 'g');
|
|
21
|
+
let newContent = processedContent.replace(selfClosingRegex, (fullMatch, attrs) => {
|
|
22
|
+
hasChanges = true;
|
|
23
|
+
importedComponents.add(componentNameStr);
|
|
24
|
+
return `<${componentNameStr}${attrs} />`;
|
|
25
|
+
});
|
|
26
|
+
newContent = newContent.replace(pairRegex, (fullMatch, attrs, children) => {
|
|
27
|
+
hasChanges = true;
|
|
28
|
+
importedComponents.add(componentNameStr);
|
|
29
|
+
return `<${componentNameStr}${attrs}>${children}</${componentNameStr}>`;
|
|
30
|
+
});
|
|
31
|
+
if (newContent !== processedContent) {
|
|
32
|
+
processedContent = newContent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (processedContent === content)
|
|
37
|
+
return;
|
|
38
|
+
if (importedComponents.size > 0) {
|
|
39
|
+
const imports = Array.from(importedComponents).join(', ');
|
|
40
|
+
const scriptRegex = /<script(?![^>]*\bmodule\b)([^>]*)>/;
|
|
41
|
+
const scriptMatch = processedContent.match(scriptRegex);
|
|
42
|
+
if (scriptMatch && scriptMatch.index !== undefined) {
|
|
43
|
+
const insertPos = scriptMatch.index + scriptMatch[0].length;
|
|
44
|
+
processedContent =
|
|
45
|
+
processedContent.slice(0, insertPos) +
|
|
46
|
+
`\n\timport { ${imports} } from '@lapikit/repl/components';` +
|
|
47
|
+
processedContent.slice(insertPos);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const moduleScriptMatch = processedContent.match(/<script[^>]*\bmodule\b[^>]*>/);
|
|
51
|
+
if (moduleScriptMatch && moduleScriptMatch.index !== undefined) {
|
|
52
|
+
const moduleScriptEnd = processedContent.indexOf('</script>', moduleScriptMatch.index) + '</script>'.length;
|
|
53
|
+
processedContent =
|
|
54
|
+
processedContent.slice(0, moduleScriptEnd) +
|
|
55
|
+
`\n\n<script>\n\timport { ${imports} } from '@lapikit/repl/components';\n</script>` +
|
|
56
|
+
processedContent.slice(moduleScriptEnd);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
processedContent =
|
|
60
|
+
`<script>\n\timport { ${imports} } from '@lapikit/repl/components';\n</script>\n\n` +
|
|
61
|
+
processedContent;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
code: processedContent
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export { replPreprocess };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lapikit/repl",
|
|
3
|
-
"version": "0.0.0-insiders.
|
|
3
|
+
"version": "0.0.0-insiders.e242cea",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -39,8 +39,11 @@
|
|
|
39
39
|
"type": "module",
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
|
-
"
|
|
43
|
-
|
|
42
|
+
"default": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./components": {
|
|
45
|
+
"types": "./dist/components.d.ts",
|
|
46
|
+
"svelte": "./dist/components.js"
|
|
44
47
|
}
|
|
45
48
|
},
|
|
46
49
|
"peerDependencies": {
|