@thedatagrid/docs-kit 0.3.0 → 0.5.0
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 +27 -0
- package/README.md +172 -4
- package/dist/code/demoFiles.d.ts.map +1 -1
- package/dist/code/demoFiles.js +2 -2
- package/dist/code/demoFiles.js.map +1 -1
- package/dist/code/index.d.ts +1 -0
- package/dist/code/index.d.ts.map +1 -1
- package/dist/code/index.js +1 -0
- package/dist/code/index.js.map +1 -1
- package/dist/code/regions.d.ts +2 -1
- package/dist/code/regions.d.ts.map +1 -1
- package/dist/code/regions.js +12 -8
- package/dist/code/regions.js.map +1 -1
- package/dist/code/vueBlocks.d.ts +3 -0
- package/dist/code/vueBlocks.d.ts.map +1 -0
- package/dist/code/vueBlocks.js +29 -0
- package/dist/code/vueBlocks.js.map +1 -0
- package/dist/demos/build.d.ts +5 -2
- package/dist/demos/build.d.ts.map +1 -1
- package/dist/demos/build.js +244 -85
- package/dist/demos/build.js.map +1 -1
- package/dist/demos/compile/core.d.ts +9 -1
- package/dist/demos/compile/core.d.ts.map +1 -1
- package/dist/demos/compile/core.js +19 -8
- package/dist/demos/compile/core.js.map +1 -1
- package/dist/demos/compile/vue.d.ts +107 -0
- package/dist/demos/compile/vue.d.ts.map +1 -0
- package/dist/demos/compile/vue.js +187 -0
- package/dist/demos/compile/vue.js.map +1 -0
- package/dist/demos/config.d.ts +41 -7
- package/dist/demos/config.d.ts.map +1 -1
- package/dist/demos/config.js.map +1 -1
- package/dist/demos/index.d.ts +3 -2
- package/dist/demos/index.d.ts.map +1 -1
- package/dist/demos/index.js +1 -0
- package/dist/demos/index.js.map +1 -1
- package/dist/demos/pages.d.ts +1 -1
- package/dist/demos/pages.d.ts.map +1 -1
- package/dist/demos/pages.js +4 -1
- package/dist/demos/pages.js.map +1 -1
- package/dist/demos/runtime/vue.d.ts +3 -0
- package/dist/demos/runtime/vue.d.ts.map +1 -0
- package/dist/demos/runtime/vue.js +15 -0
- package/dist/demos/runtime/vue.js.map +1 -0
- package/dist/demos/vendor.d.ts +5 -1
- package/dist/demos/vendor.d.ts.map +1 -1
- package/dist/demos/vendor.js +6 -2
- package/dist/demos/vendor.js.map +1 -1
- package/dist/demos/worker/compile.worker.js +3 -22
- package/dist/demos/worker/compile.worker.js.map +1 -1
- package/dist/demos/worker/compileVue.worker.d.ts +2 -0
- package/dist/demos/worker/compileVue.worker.d.ts.map +1 -0
- package/dist/demos/worker/compileVue.worker.js +11 -0
- package/dist/demos/worker/compileVue.worker.js.map +1 -0
- package/dist/demos/worker/start.d.ts +7 -0
- package/dist/demos/worker/start.d.ts.map +1 -0
- package/dist/demos/worker/start.js +27 -0
- package/dist/demos/worker/start.js.map +1 -0
- package/dist/fork/codesandbox.d.ts +19 -1
- package/dist/fork/codesandbox.d.ts.map +1 -1
- package/dist/fork/codesandbox.js +35 -22
- package/dist/fork/codesandbox.js.map +1 -1
- package/dist/fork/index.d.ts +30 -0
- package/dist/fork/index.d.ts.map +1 -1
- package/dist/fork/index.js +37 -0
- package/dist/fork/index.js.map +1 -1
- package/dist/fork/stackblitz.d.ts +18 -0
- package/dist/fork/stackblitz.d.ts.map +1 -0
- package/dist/fork/stackblitz.js +98 -0
- package/dist/fork/stackblitz.js.map +1 -0
- package/dist/frameworks/index.d.ts +4 -0
- package/dist/frameworks/index.d.ts.map +1 -0
- package/dist/frameworks/index.js +4 -0
- package/dist/frameworks/index.js.map +1 -0
- package/dist/frameworks/preference.d.ts +10 -0
- package/dist/frameworks/preference.d.ts.map +1 -0
- package/dist/frameworks/preference.js +34 -0
- package/dist/frameworks/preference.js.map +1 -0
- package/dist/frameworks/react/FrameworkBanner.d.ts +34 -0
- package/dist/frameworks/react/FrameworkBanner.d.ts.map +1 -0
- package/dist/frameworks/react/FrameworkBanner.js +50 -0
- package/dist/frameworks/react/FrameworkBanner.js.map +1 -0
- package/dist/frameworks/react/FrameworkContent.d.ts +21 -0
- package/dist/frameworks/react/FrameworkContent.d.ts.map +1 -0
- package/dist/frameworks/react/FrameworkContent.js +25 -0
- package/dist/frameworks/react/FrameworkContent.js.map +1 -0
- package/dist/frameworks/react/FrameworkLinks.d.ts +16 -0
- package/dist/frameworks/react/FrameworkLinks.d.ts.map +1 -0
- package/dist/frameworks/react/FrameworkLinks.js +50 -0
- package/dist/frameworks/react/FrameworkLinks.js.map +1 -0
- package/dist/frameworks/react/FrameworkSwitcher.d.ts +27 -0
- package/dist/frameworks/react/FrameworkSwitcher.d.ts.map +1 -0
- package/dist/frameworks/react/FrameworkSwitcher.js +42 -0
- package/dist/frameworks/react/FrameworkSwitcher.js.map +1 -0
- package/dist/frameworks/react/index.d.ts +6 -0
- package/dist/frameworks/react/index.d.ts.map +1 -0
- package/dist/frameworks/react/index.js +6 -0
- package/dist/frameworks/react/index.js.map +1 -0
- package/dist/frameworks/react/useFrameworkPreference.d.ts +32 -0
- package/dist/frameworks/react/useFrameworkPreference.d.ts.map +1 -0
- package/dist/frameworks/react/useFrameworkPreference.js +45 -0
- package/dist/frameworks/react/useFrameworkPreference.js.map +1 -0
- package/dist/frameworks/routeTree.d.ts +24 -0
- package/dist/frameworks/routeTree.d.ts.map +1 -0
- package/dist/frameworks/routeTree.js +31 -0
- package/dist/frameworks/routeTree.js.map +1 -0
- package/dist/frameworks/routing.d.ts +105 -0
- package/dist/frameworks/routing.d.ts.map +1 -0
- package/dist/frameworks/routing.js +142 -0
- package/dist/frameworks/routing.js.map +1 -0
- package/dist/frameworks/styles.css +104 -0
- package/dist/react/Demo.d.ts +12 -0
- package/dist/react/Demo.d.ts.map +1 -1
- package/dist/react/Demo.js +10 -4
- package/dist/react/Demo.js.map +1 -1
- package/dist/react/DemoShell.d.ts +5 -1
- package/dist/react/DemoShell.d.ts.map +1 -1
- package/dist/react/DemoShell.js +9 -6
- package/dist/react/DemoShell.js.map +1 -1
- package/dist/react/editor.d.ts.map +1 -1
- package/dist/react/editor.js +3 -0
- package/dist/react/editor.js.map +1 -1
- package/dist/react/fork.d.ts +4 -3
- package/dist/react/fork.d.ts.map +1 -1
- package/dist/react/fork.js +8 -6
- package/dist/react/fork.js.map +1 -1
- package/dist/react/styles.css +10 -0
- package/dist/remark/index.d.ts +2 -0
- package/dist/remark/index.d.ts.map +1 -1
- package/dist/remark/index.js +2 -0
- package/dist/remark/index.js.map +1 -1
- package/dist/remark/remarkDemoFences.d.ts +13 -0
- package/dist/remark/remarkDemoFences.d.ts.map +1 -1
- package/dist/remark/remarkDemoFences.js +48 -4
- package/dist/remark/remarkDemoFences.js.map +1 -1
- package/dist/remark/remarkFrameworkLinks.d.ts +36 -0
- package/dist/remark/remarkFrameworkLinks.d.ts.map +1 -0
- package/dist/remark/remarkFrameworkLinks.js +77 -0
- package/dist/remark/remarkFrameworkLinks.js.map +1 -0
- package/dist/remark/remarkFrameworkText.d.ts +16 -0
- package/dist/remark/remarkFrameworkText.d.ts.map +1 -0
- package/dist/remark/remarkFrameworkText.js +39 -0
- package/dist/remark/remarkFrameworkText.js.map +1 -0
- package/package.json +29 -4
- package/src/code/demoFiles.ts +2 -2
- package/src/code/index.ts +1 -0
- package/src/code/regions.ts +14 -8
- package/src/code/vueBlocks.ts +25 -0
- package/src/demos/build.ts +293 -99
- package/src/demos/compile/core.ts +27 -7
- package/src/demos/compile/vue.ts +259 -0
- package/src/demos/config.ts +59 -7
- package/src/demos/index.ts +13 -0
- package/src/demos/pages.ts +4 -2
- package/src/demos/runtime/vue.ts +17 -0
- package/src/demos/vendor.ts +6 -2
- package/src/demos/worker/compile.worker.ts +3 -30
- package/src/demos/worker/compileVue.worker.ts +13 -0
- package/src/demos/worker/start.ts +35 -0
- package/src/fork/codesandbox.ts +51 -24
- package/src/fork/index.ts +56 -0
- package/src/fork/stackblitz.ts +108 -0
- package/src/frameworks/index.ts +21 -0
- package/src/frameworks/preference.ts +35 -0
- package/src/frameworks/react/FrameworkBanner.tsx +112 -0
- package/src/frameworks/react/FrameworkContent.tsx +33 -0
- package/src/frameworks/react/FrameworkLinks.tsx +52 -0
- package/src/frameworks/react/FrameworkSwitcher.tsx +78 -0
- package/src/frameworks/react/index.ts +10 -0
- package/src/frameworks/react/useFrameworkPreference.ts +91 -0
- package/src/frameworks/routeTree.ts +54 -0
- package/src/frameworks/routing.ts +194 -0
- package/src/frameworks/styles.css +104 -0
- package/src/react/Demo.tsx +21 -2
- package/src/react/DemoShell.tsx +15 -7
- package/src/react/editor.ts +2 -0
- package/src/react/fork.ts +14 -6
- package/src/react/styles.css +10 -0
- package/src/remark/index.ts +6 -0
- package/src/remark/remarkDemoFences.ts +58 -3
- package/src/remark/remarkFrameworkLinks.ts +96 -0
- package/src/remark/remarkFrameworkText.ts +44 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { resolveFrameworkLink, splitHref } from "../frameworks/routing.js";
|
|
3
|
+
/** The attribute a fallback link carries: the framework it goes to instead. */
|
|
4
|
+
export const FALLBACK_LINK_ATTRIBUTE = 'data-framework-fallback';
|
|
5
|
+
/**
|
|
6
|
+
* Links in the docs are written once, in the default framework's form
|
|
7
|
+
* (`/docs/learn/sorting`). This plugin points them at the page's framework:
|
|
8
|
+
*
|
|
9
|
+
* - the page exists there: `/vue/docs/learn/sorting`;
|
|
10
|
+
* - it doesn't: the link goes to a framework that has it and is marked with
|
|
11
|
+
* `data-framework-fallback="react"`, so the site can show a badge
|
|
12
|
+
* ("React only for now");
|
|
13
|
+
* - no framework has it: the build fails.
|
|
14
|
+
*
|
|
15
|
+
* Covers markdown links, link definitions and the configured JSX attributes.
|
|
16
|
+
* External links and `#hash` links are left alone.
|
|
17
|
+
*/
|
|
18
|
+
export function remarkFrameworkLinks(options) {
|
|
19
|
+
const { frameworks, framework, hasPage, isValidSharedLink, jsxAttributes = {}, file } = options;
|
|
20
|
+
const where = file ? `, found in ${file}` : '';
|
|
21
|
+
/** The rewritten URL and, for a fallback, its framework. `null`: not an internal link. */
|
|
22
|
+
const resolve = (url) => {
|
|
23
|
+
if (typeof url !== 'string' || !url.startsWith('/') || url.startsWith('//'))
|
|
24
|
+
return null;
|
|
25
|
+
const link = resolveFrameworkLink(frameworks, url, framework, hasPage);
|
|
26
|
+
switch (link.kind) {
|
|
27
|
+
case 'shared':
|
|
28
|
+
if (isValidSharedLink && !isValidSharedLink(splitHref(url)[0])) {
|
|
29
|
+
throw new Error(`Link not valid: "${url}"${where}.`);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
case 'page':
|
|
33
|
+
return { url: link.href, fallback: null };
|
|
34
|
+
case 'fallback':
|
|
35
|
+
return { url: link.href, fallback: link.framework };
|
|
36
|
+
case 'missing':
|
|
37
|
+
throw new Error(`Link not valid: "${url}"${where}: no page at "${link.neutralPath}" in any framework ` +
|
|
38
|
+
`(${frameworks.ids.join(', ')}).`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return () => (tree) => {
|
|
42
|
+
visit(tree, (node) => {
|
|
43
|
+
if (node.type === 'link' || node.type === 'definition') {
|
|
44
|
+
const resolved = resolve(node.url);
|
|
45
|
+
if (!resolved)
|
|
46
|
+
return;
|
|
47
|
+
node.url = resolved.url;
|
|
48
|
+
if (resolved.fallback && node.type === 'link') {
|
|
49
|
+
node.data = {
|
|
50
|
+
...node.data,
|
|
51
|
+
hProperties: { ...node.data?.hProperties, [FALLBACK_LINK_ATTRIBUTE]: resolved.fallback },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (node.type !== 'mdxJsxFlowElement' && node.type !== 'mdxJsxTextElement')
|
|
57
|
+
return;
|
|
58
|
+
const names = node.name ? jsxAttributes[node.name] : undefined;
|
|
59
|
+
if (!names)
|
|
60
|
+
return;
|
|
61
|
+
let fallback = null;
|
|
62
|
+
for (const attribute of node.attributes ?? []) {
|
|
63
|
+
if (attribute.type !== 'mdxJsxAttribute' || !names.includes(attribute.name))
|
|
64
|
+
continue;
|
|
65
|
+
const resolved = resolve(attribute.value);
|
|
66
|
+
if (!resolved)
|
|
67
|
+
continue;
|
|
68
|
+
attribute.value = resolved.url;
|
|
69
|
+
fallback ??= resolved.fallback;
|
|
70
|
+
}
|
|
71
|
+
if (fallback && !node.attributes.some((attribute) => attribute.name === 'frameworkFallback')) {
|
|
72
|
+
node.attributes.push({ type: 'mdxJsxAttribute', name: 'frameworkFallback', value: fallback });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=remarkFrameworkLinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remarkFrameworkLinks.js","sourceRoot":"","sources":["../../src/remark/remarkFrameworkLinks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAiC,MAAM,0BAA0B,CAAC;AAqB1G,+EAA+E;AAC/E,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAAoB,OAAwC;IAC9F,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,aAAa,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAChG,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE/C,0FAA0F;IAC1F,MAAM,OAAO,GAAG,CAAC,GAAY,EAA+C,EAAE;QAC5E,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACzF,MAAM,IAAI,GAAG,oBAAoB,CAAC,UAAU,EAAE,GAAG,EAAE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AC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RemarkFrameworkTextOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* Literal replacements for a page rendered in another framework than it
|
|
4
|
+
* was written for, e.g. `{ '@acme/grid-react': '@acme/grid-vue' }`.
|
|
5
|
+
*/
|
|
6
|
+
replacements: Record<string, string>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Applies literal replacements to a page's prose: text, inline code, fenced
|
|
10
|
+
* code written in the page, and link URLs. The package name in
|
|
11
|
+
* `npm i @acme/grid-react` is right on the Vue page without a second copy of
|
|
12
|
+
* the sentence. Fences that show a file (`file="…"`) are left alone: their
|
|
13
|
+
* code comes from that file, or its sibling.
|
|
14
|
+
*/
|
|
15
|
+
export declare function remarkFrameworkText(options: RemarkFrameworkTextOptions): () => (tree: any) => void;
|
|
16
|
+
//# sourceMappingURL=remarkFrameworkText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remarkFrameworkText.d.ts","sourceRoot":"","sources":["../../src/remark/remarkFrameworkText.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,UAQvD,MAAM,GAAG,UAkBxB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
/**
|
|
3
|
+
* Applies literal replacements to a page's prose: text, inline code, fenced
|
|
4
|
+
* code written in the page, and link URLs. The package name in
|
|
5
|
+
* `npm i @acme/grid-react` is right on the Vue page without a second copy of
|
|
6
|
+
* the sentence. Fences that show a file (`file="…"`) are left alone: their
|
|
7
|
+
* code comes from that file, or its sibling.
|
|
8
|
+
*/
|
|
9
|
+
export function remarkFrameworkText(options) {
|
|
10
|
+
const pairs = Object.entries(options.replacements).filter(([search]) => search);
|
|
11
|
+
const replace = (value) => {
|
|
12
|
+
let result = value;
|
|
13
|
+
for (const [search, replacement] of pairs)
|
|
14
|
+
result = result.split(search).join(replacement);
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
return () => (tree) => {
|
|
18
|
+
if (!pairs.length)
|
|
19
|
+
return;
|
|
20
|
+
visit(tree, (node) => {
|
|
21
|
+
switch (node.type) {
|
|
22
|
+
case 'text':
|
|
23
|
+
case 'inlineCode':
|
|
24
|
+
node.value = replace(node.value);
|
|
25
|
+
break;
|
|
26
|
+
case 'code':
|
|
27
|
+
if (!/\bfile=/.test(node.meta ?? ''))
|
|
28
|
+
node.value = replace(node.value);
|
|
29
|
+
break;
|
|
30
|
+
case 'link':
|
|
31
|
+
case 'definition':
|
|
32
|
+
if (typeof node.url === 'string')
|
|
33
|
+
node.url = replace(node.url);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=remarkFrameworkText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remarkFrameworkText.js","sourceRoot":"","sources":["../../src/remark/remarkFrameworkText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAUzC;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmC;IACrE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAChF,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,EAAE;QAChC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,KAAK;YAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3F,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,GAAG,EAAE,CAAC,CAAC,IAAS,EAAE,EAAE;QACzB,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,OAAO;QAC1B,KAAK,CAAC,IAAI,EAAE,CAAC,IAAS,EAAE,EAAE;YACxB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,MAAM,CAAC;gBACZ,KAAK,YAAY;oBACf,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACjC,MAAM;gBACR,KAAK,MAAM;oBACT,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;wBAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACvE,MAAM;gBACR,KAAK,MAAM,CAAC;gBACZ,KAAK,YAAY;oBACf,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ;wBAAE,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAC/D,MAAM;YACV,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thedatagrid/docs-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Docs tooling: type-checked file snippets with regions and highlights, prebuilt and editable live demos, CodeSandbox forks, scripted showcase demos",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Docs tooling: type-checked file snippets with regions and highlights, prebuilt and editable live demos for React and Vue, CodeSandbox forks, docs per framework, scripted showcase demos",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "TheDataGrid",
|
|
@@ -45,6 +45,15 @@
|
|
|
45
45
|
"default": "./dist/showcase/index.js"
|
|
46
46
|
},
|
|
47
47
|
"./showcase/styles.css": "./dist/showcase/styles.css",
|
|
48
|
+
"./frameworks": {
|
|
49
|
+
"types": "./dist/frameworks/index.d.ts",
|
|
50
|
+
"default": "./dist/frameworks/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./frameworks/react": {
|
|
53
|
+
"types": "./dist/frameworks/react/index.d.ts",
|
|
54
|
+
"default": "./dist/frameworks/react/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./frameworks/styles.css": "./dist/frameworks/styles.css",
|
|
48
57
|
"./package.json": "./package.json"
|
|
49
58
|
},
|
|
50
59
|
"typesVersions": {
|
|
@@ -52,6 +61,9 @@
|
|
|
52
61
|
"demos/client": [
|
|
53
62
|
"dist/demos/client.d.ts"
|
|
54
63
|
],
|
|
64
|
+
"frameworks/react": [
|
|
65
|
+
"dist/frameworks/react/index.d.ts"
|
|
66
|
+
],
|
|
55
67
|
"*": [
|
|
56
68
|
"dist/*/index.d.ts"
|
|
57
69
|
]
|
|
@@ -78,6 +90,7 @@
|
|
|
78
90
|
"@codemirror/commands": "^6.11.1",
|
|
79
91
|
"@codemirror/lang-css": "^6.3.1",
|
|
80
92
|
"@codemirror/lang-javascript": "^6.2.5",
|
|
93
|
+
"@codemirror/lang-vue": "^0.1.3",
|
|
81
94
|
"@codemirror/language": "^6.13.1",
|
|
82
95
|
"@codemirror/search": "^6.6.0",
|
|
83
96
|
"@codemirror/state": "^6.7.6",
|
|
@@ -91,19 +104,31 @@
|
|
|
91
104
|
"unist-util-visit": "^5.2.0"
|
|
92
105
|
},
|
|
93
106
|
"peerDependencies": {
|
|
107
|
+
"@vue/compiler-sfc": ">=3.4",
|
|
94
108
|
"react": ">=18",
|
|
95
|
-
"react-dom": ">=18"
|
|
109
|
+
"react-dom": ">=18",
|
|
110
|
+
"vue": ">=3.4"
|
|
111
|
+
},
|
|
112
|
+
"peerDependenciesMeta": {
|
|
113
|
+
"@vue/compiler-sfc": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"vue": {
|
|
117
|
+
"optional": true
|
|
118
|
+
}
|
|
96
119
|
},
|
|
97
120
|
"devDependencies": {
|
|
98
121
|
"@mdx-js/mdx": "^3.1.1",
|
|
99
122
|
"@types/node": "^22.18.0",
|
|
100
123
|
"@types/react": "^19.2.2",
|
|
101
124
|
"@types/react-dom": "^19.2.1",
|
|
125
|
+
"@vue/compiler-sfc": "^3.5.45",
|
|
102
126
|
"playwright-core": "1.64.1",
|
|
103
127
|
"react": "^19.2.0",
|
|
104
128
|
"react-dom": "^19.2.0",
|
|
105
129
|
"remark-gfm": "^4.0.1",
|
|
106
|
-
"remark-mdx": "^3.1.1"
|
|
130
|
+
"remark-mdx": "^3.1.1",
|
|
131
|
+
"vue": "^3.5.45"
|
|
107
132
|
},
|
|
108
133
|
"engines": {
|
|
109
134
|
"node": ">=22.18.0"
|
package/src/code/demoFiles.ts
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
const IMPORT_RE =
|
|
5
5
|
/(?:import|export)\s[^'"]*?from\s+['"](\.\.?\/[^'"]+)['"]|import\s*\(?\s*['"](\.\.?\/[^'"]+)['"]/g;
|
|
6
6
|
|
|
7
|
-
export const RESOLVE_EXTENSIONS = ['', '.tsx', '.ts', '.jsx', '.js', '.mjs', '.css', '.json'];
|
|
7
|
+
export const RESOLVE_EXTENSIONS = ['', '.tsx', '.ts', '.jsx', '.js', '.mjs', '.vue', '.css', '.json'];
|
|
8
8
|
|
|
9
9
|
function resolveRelativeImport(fromDir: string, specifier: string): string | null {
|
|
10
10
|
const base = path.resolve(fromDir, specifier);
|
|
@@ -39,7 +39,7 @@ export function collectDemoFiles(entryFile: string): DemoSourceFile[] {
|
|
|
39
39
|
visited.add(filePath);
|
|
40
40
|
const source = fs.readFileSync(filePath, 'utf8');
|
|
41
41
|
ordered.push({ filePath, source });
|
|
42
|
-
if (!/\.(?:[cm]?[jt]sx
|
|
42
|
+
if (!/\.(?:[cm]?[jt]sx?|vue)$/.test(filePath)) return;
|
|
43
43
|
for (const match of source.matchAll(IMPORT_RE)) {
|
|
44
44
|
const specifier = match[1] ?? match[2];
|
|
45
45
|
const resolved = resolveRelativeImport(path.dirname(filePath), specifier);
|
package/src/code/index.ts
CHANGED
package/src/code/regions.ts
CHANGED
|
@@ -130,12 +130,17 @@ export function sliceRegion(source: string, spec: string, context: string): Slic
|
|
|
130
130
|
return extracted;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Whole-line `// #highlight label`, `/* #highlight label *\/`, `{/* #highlight label *\/}`
|
|
135
|
+
* or, in HTML and Vue templates, `<!-- #highlight label -->`.
|
|
136
|
+
*/
|
|
137
|
+
const HIGHLIGHT_START_RE =
|
|
138
|
+
/^\s*(?:\/\/\s*#highlight\b(.*)|\{?\/\*\s*#highlight\b(.*?)\*\/\}?|<!--\s*#highlight\b(.*?)-->)\s*$/;
|
|
139
|
+
const HIGHLIGHT_END_RE =
|
|
140
|
+
/^\s*(?:\/\/\s*#endhighlight\b.*|\{?\/\*\s*#endhighlight\b.*?\*\/\}?|<!--\s*#endhighlight\b.*?-->)\s*$/;
|
|
141
|
+
/** Trailing `code // #highlight label` (or a `/* … *\/`, `{/* … *\/}` or `<!-- … -->` comment) after code. */
|
|
137
142
|
const HIGHLIGHT_INLINE_RE =
|
|
138
|
-
/^(.*?\S)\s*(?:\/\/\s*#highlight\b(.*)|\{\/\*\s*#highlight\b(.*?)\*\/\}|\/\*\s*#highlight\b(.*?)
|
|
143
|
+
/^(.*?\S)\s*(?:\/\/\s*#highlight\b(.*)|\{\/\*\s*#highlight\b(.*?)\*\/\}|\/\*\s*#highlight\b(.*?)\*\/|<!--\s*#highlight\b(.*?)-->)\s*$/;
|
|
139
144
|
|
|
140
145
|
function isRegionMarker(line: string): boolean {
|
|
141
146
|
return REGION_MARKERS.some((re) => re.start.test(line) || re.end.test(line));
|
|
@@ -155,7 +160,8 @@ export type CodeWithMarkers = SlicedRange & {
|
|
|
155
160
|
* With a label, the opening marker becomes an empty highlighted line that
|
|
156
161
|
* shows the label; without one it is removed.
|
|
157
162
|
* - `code // #highlight label` highlights that single line.
|
|
158
|
-
* - `/* …
|
|
163
|
+
* - `/* … *\/`, `{/* … *\/}` (JSX children) and `<!-- … -->` (HTML, Vue templates)
|
|
164
|
+
* work for both forms.
|
|
159
165
|
* - `#region` / `#endregion` lines are dropped, so full-file views don't show them.
|
|
160
166
|
*
|
|
161
167
|
* `originalLines` (from `sliceRegion`) is kept in step with the removed lines.
|
|
@@ -198,7 +204,7 @@ export function extractCodeMarkers(
|
|
|
198
204
|
`${context}: the \`#highlight\` on line ${block.fileLine} has no code line before the \`#highlight\` on line ${fileLine}`,
|
|
199
205
|
);
|
|
200
206
|
}
|
|
201
|
-
const label = (start[1] ?? start[2] ?? '').trim();
|
|
207
|
+
const label = (start[1] ?? start[2] ?? start[3] ?? '').trim();
|
|
202
208
|
if (label) {
|
|
203
209
|
// the label row keeps the marker's indentation, so the label lines up with the block
|
|
204
210
|
kept.push(/^\s*/.exec(text)![0]);
|
|
@@ -223,7 +229,7 @@ export function extractCodeMarkers(
|
|
|
223
229
|
const inline = HIGHLIGHT_INLINE_RE.exec(text);
|
|
224
230
|
kept.push(inline ? inline[1] : text);
|
|
225
231
|
keptLines.push(fileLine);
|
|
226
|
-
if (inline) mark((inline[2] ?? inline[3] ?? inline[4] ?? '').trim());
|
|
232
|
+
if (inline) mark((inline[2] ?? inline[3] ?? inline[4] ?? inline[5] ?? '').trim());
|
|
227
233
|
if (block) {
|
|
228
234
|
mark('');
|
|
229
235
|
if (block.nextLineOnly && text.trim()) block = null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which block of a Vue single-file component a line belongs to, as a shiki
|
|
3
|
+
* language: a region sliced out of a `.vue` file is highlighted as what it
|
|
4
|
+
* is (script code, template markup or CSS), not as a whole component.
|
|
5
|
+
*/
|
|
6
|
+
const BLOCK_OPEN_RE = /^<(script|template|style)\b([^>]*)>/;
|
|
7
|
+
|
|
8
|
+
/** `line` is 1-based. Lines outside every block (or a whole-file view) are `vue`. */
|
|
9
|
+
export function vueBlockLang(source: string, line: number): string {
|
|
10
|
+
const lines = source.split('\n');
|
|
11
|
+
let current: { tag: string; attrs: string } | null = null;
|
|
12
|
+
for (let index = 0; index < Math.min(line, lines.length); index++) {
|
|
13
|
+
const open = BLOCK_OPEN_RE.exec(lines[index]);
|
|
14
|
+
if (open) {
|
|
15
|
+
current = { tag: open[1], attrs: open[2] };
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (current && lines[index].startsWith(`</${current.tag}>`)) current = null;
|
|
19
|
+
}
|
|
20
|
+
if (!current) return 'vue';
|
|
21
|
+
if (current.tag === 'template') return 'vue-html';
|
|
22
|
+
const lang = /\blang=["']([\w-]+)["']/.exec(current.attrs)?.[1];
|
|
23
|
+
if (current.tag === 'style') return lang ?? 'css';
|
|
24
|
+
return lang ?? 'js';
|
|
25
|
+
}
|