@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,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StackBlitz fork payloads, for Vue demos: a Vite + Vue + TypeScript project,
|
|
3
|
+
* posted to StackBlitz's `run` endpoint and started in the browser
|
|
4
|
+
* (WebContainers), with no sign-in.
|
|
5
|
+
*
|
|
6
|
+
* Like the CodeSandbox payload, the demo's files keep their folder structure
|
|
7
|
+
* under `src/`, and `src/main.ts` imports the entry by its relative path.
|
|
8
|
+
*/
|
|
9
|
+
import { forkPrelude, forkStyles, indexHtmlHead, placeFiles, replaceAll, } from "./codesandbox.js";
|
|
10
|
+
export const STACKBLITZ_RUN_URL = 'https://stackblitz.com/run';
|
|
11
|
+
const INDEX_HTML = (title, head) => `<!DOCTYPE html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="UTF-8" />
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
16
|
+
<title>${title.replace(/</g, '<')}</title>
|
|
17
|
+
${indexHtmlHead(head)} </head>
|
|
18
|
+
<body>
|
|
19
|
+
<div id="root"></div>
|
|
20
|
+
<script type="module" src="/src/main.ts"></script>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
23
|
+
`;
|
|
24
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
25
|
+
/** The project's files (path → contents) for a Vue demo: Vite, `@vitejs/plugin-vue`, TypeScript. */
|
|
26
|
+
export function vueProjectFiles(files, options) {
|
|
27
|
+
const placed = placeFiles(files, options);
|
|
28
|
+
const project = {
|
|
29
|
+
'package.json': json({
|
|
30
|
+
name: 'docs-demo',
|
|
31
|
+
description: options.title,
|
|
32
|
+
private: true,
|
|
33
|
+
type: 'module',
|
|
34
|
+
scripts: { dev: 'vite', build: 'vite build' },
|
|
35
|
+
dependencies: {
|
|
36
|
+
...placed.imported,
|
|
37
|
+
vue: '^3.5.0',
|
|
38
|
+
...options.dependencies,
|
|
39
|
+
},
|
|
40
|
+
devDependencies: {
|
|
41
|
+
'@vitejs/plugin-vue': '^6.0.0',
|
|
42
|
+
typescript: '^5.4.0',
|
|
43
|
+
vite: '^8.0.0',
|
|
44
|
+
...options.devDependencies,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
'index.html': INDEX_HTML(options.title, options.indexHtmlHead),
|
|
48
|
+
'vite.config.ts': `import { defineConfig } from 'vite';
|
|
49
|
+
import vue from '@vitejs/plugin-vue';
|
|
50
|
+
|
|
51
|
+
export default defineConfig({ plugins: [vue()] });
|
|
52
|
+
`,
|
|
53
|
+
'tsconfig.json': json({
|
|
54
|
+
compilerOptions: {
|
|
55
|
+
target: 'ESNext',
|
|
56
|
+
module: 'ESNext',
|
|
57
|
+
moduleResolution: 'Bundler',
|
|
58
|
+
strict: true,
|
|
59
|
+
jsx: 'preserve',
|
|
60
|
+
jsxImportSource: 'vue',
|
|
61
|
+
skipLibCheck: true,
|
|
62
|
+
lib: ['ESNext', 'DOM', 'DOM.Iterable'],
|
|
63
|
+
},
|
|
64
|
+
include: ['src'],
|
|
65
|
+
}),
|
|
66
|
+
'src/vite-env.d.ts': '/// <reference types="vite/client" />\n',
|
|
67
|
+
'src/styles.css': forkStyles(options),
|
|
68
|
+
'src/main.ts': `import { createApp } from 'vue';
|
|
69
|
+
${forkPrelude(options)}
|
|
70
|
+
import './styles.css';
|
|
71
|
+
import App from ${JSON.stringify(placed.entryImport)};
|
|
72
|
+
|
|
73
|
+
createApp(App).mount('#root');
|
|
74
|
+
`,
|
|
75
|
+
};
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
const target = placed.inSrc(file.path);
|
|
78
|
+
if (project[target] != null)
|
|
79
|
+
throw new Error(`fork: "${target}" clashes with a template file`);
|
|
80
|
+
project[target] = replaceAll(file.content, options.sourceReplacements);
|
|
81
|
+
}
|
|
82
|
+
return project;
|
|
83
|
+
}
|
|
84
|
+
/** Form action and fields for a POST to StackBlitz; the entry file opens in the editor. */
|
|
85
|
+
export function stackBlitzForm(files, options) {
|
|
86
|
+
const project = vueProjectFiles(files, options);
|
|
87
|
+
const entry = placeFiles(files, options).inSrc(options.entry);
|
|
88
|
+
const fields = {
|
|
89
|
+
'project[title]': options.title,
|
|
90
|
+
'project[description]': options.title,
|
|
91
|
+
// WebContainers: `npm install`, then the `dev` script
|
|
92
|
+
'project[template]': 'node',
|
|
93
|
+
};
|
|
94
|
+
for (const [filePath, content] of Object.entries(project))
|
|
95
|
+
fields[`project[files][${filePath}]`] = content;
|
|
96
|
+
return { action: `${STACKBLITZ_RUN_URL}?file=${encodeURIComponent(entry)}`, fields };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=stackblitz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stackblitz.js","sourceRoot":"","sources":["../../src/fork/stackblitz.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,GAGX,MAAM,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,kBAAkB,GAAG,4BAA4B,CAAC;AAE/D,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,IAAa,EAAE,EAAE,CAAC;;;;;aAKxC,KAAK,CAAC,OAAO,CAAC,IAA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,kBAAkB,SAAS,kBAAkB,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createHasPage, defineFrameworks, resolveFrameworkLink, resolveNavigation, resolveSwitchTarget, splitHref, type FrameworkDefinition, type Frameworks, type FrameworksConfig, type HasPage, type ResolvedLink, } from './routing.ts';
|
|
2
|
+
export { mapRouteTree, type MapRouteTreeOptions, type RouteNode } from './routeTree.ts';
|
|
3
|
+
export { DEFAULT_FRAMEWORK_STORAGE_KEY, FRAMEWORK_CHANGE_EVENT, frameworkStorageKey, readFrameworkPreference, writeFrameworkPreference, } from './preference.ts';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/frameworks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createHasPage, defineFrameworks, resolveFrameworkLink, resolveNavigation, resolveSwitchTarget, splitHref, } from "./routing.js";
|
|
2
|
+
export { mapRouteTree } from "./routeTree.js";
|
|
3
|
+
export { DEFAULT_FRAMEWORK_STORAGE_KEY, FRAMEWORK_CHANGE_EVENT, frameworkStorageKey, readFrameworkPreference, writeFrameworkPreference, } from "./preference.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/frameworks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GAMV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAA4C,MAAM,gBAAgB,CAAC;AACxF,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Frameworks } from './routing.ts';
|
|
2
|
+
/** Fired on `window` when the stored framework changes in this tab. */
|
|
3
|
+
export declare const FRAMEWORK_CHANGE_EVENT = "docs-kit:framework";
|
|
4
|
+
export declare const DEFAULT_FRAMEWORK_STORAGE_KEY = "docs-framework";
|
|
5
|
+
export declare const frameworkStorageKey: (frameworks: Frameworks) => string;
|
|
6
|
+
/** The visitor's stored choice, or `null` (none, an unknown value, or storage is blocked). */
|
|
7
|
+
export declare function readFrameworkPreference<Id extends string>(frameworks: Frameworks<Id>): Id | null;
|
|
8
|
+
/** Stores the visitor's choice (`null` clears it) and tells the components on the page. */
|
|
9
|
+
export declare function writeFrameworkPreference<Id extends string>(frameworks: Frameworks<Id>, framework: Id | null): void;
|
|
10
|
+
//# sourceMappingURL=preference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preference.d.ts","sourceRoot":"","sources":["../../src/frameworks/preference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,uEAAuE;AACvE,eAAO,MAAM,sBAAsB,uBAAuB,CAAC;AAE3D,eAAO,MAAM,6BAA6B,mBAAmB,CAAC;AAE9D,eAAO,MAAM,mBAAmB,GAAI,YAAY,UAAU,WACK,CAAC;AAEhE,8FAA8F;AAC9F,wBAAgB,uBAAuB,CAAC,EAAE,SAAS,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAOhG;AAED,2FAA2F;AAC3F,wBAAgB,wBAAwB,CAAC,EAAE,SAAS,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,QAa3G"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Fired on `window` when the stored framework changes in this tab. */
|
|
2
|
+
export const FRAMEWORK_CHANGE_EVENT = 'docs-kit:framework';
|
|
3
|
+
export const DEFAULT_FRAMEWORK_STORAGE_KEY = 'docs-framework';
|
|
4
|
+
export const frameworkStorageKey = (frameworks) => frameworks.config.storageKey ?? DEFAULT_FRAMEWORK_STORAGE_KEY;
|
|
5
|
+
/** The visitor's stored choice, or `null` (none, an unknown value, or storage is blocked). */
|
|
6
|
+
export function readFrameworkPreference(frameworks) {
|
|
7
|
+
try {
|
|
8
|
+
const stored = localStorage.getItem(frameworkStorageKey(frameworks));
|
|
9
|
+
return stored != null && frameworks.ids.includes(stored) ? stored : null;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Stores the visitor's choice (`null` clears it) and tells the components on the page. */
|
|
16
|
+
export function writeFrameworkPreference(frameworks, framework) {
|
|
17
|
+
try {
|
|
18
|
+
const key = frameworkStorageKey(frameworks);
|
|
19
|
+
if (framework == null)
|
|
20
|
+
localStorage.removeItem(key);
|
|
21
|
+
else
|
|
22
|
+
localStorage.setItem(key, framework);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// storage blocked: the choice lasts for this page
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
window.dispatchEvent(new CustomEvent(FRAMEWORK_CHANGE_EVENT, { detail: framework }));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// not in a browser
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=preference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preference.js","sourceRoot":"","sources":["../../src/frameworks/preference.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAE3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,gBAAgB,CAAC;AAE9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAsB,EAAE,EAAE,CAC5D,UAAU,CAAC,MAAM,CAAC,UAAU,IAAI,6BAA6B,CAAC;AAEhE,8FAA8F;AAC9F,MAAM,UAAU,uBAAuB,CAAoB,UAA0B;IACnF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;QACrE,OAAO,MAAM,IAAI,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAY,CAAC,CAAC,CAAC,CAAE,MAAa,CAAC,CAAC,CAAC,IAAI,CAAC;IACzF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,wBAAwB,CAAoB,UAA0B,EAAE,SAAoB;IAC1G,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,SAAS,IAAI,IAAI;YAAE,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;;YAC/C,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,kDAAkD;IACpD,CAAC;IACD,IAAI,CAAC;QACH,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IAAC,MAAM,CAAC;QACP,mBAAmB;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type FrameworkProps } from './useFrameworkPreference.ts';
|
|
3
|
+
export type FrameworkBannerLabels = {
|
|
4
|
+
/** The page exists in the preferred framework. `{preferred}` and `{page}` are framework labels. */
|
|
5
|
+
available?: string;
|
|
6
|
+
/** The link to it. */
|
|
7
|
+
view?: string;
|
|
8
|
+
/** Keeps the page's framework from now on. */
|
|
9
|
+
keep?: string;
|
|
10
|
+
/** The page doesn't exist in the preferred framework. */
|
|
11
|
+
missing?: string;
|
|
12
|
+
dismiss?: string;
|
|
13
|
+
};
|
|
14
|
+
export type FrameworkBannerProps<Id extends string = string> = FrameworkProps<Id> & {
|
|
15
|
+
/** The page's path, from the site's router. Default: `location.pathname`. */
|
|
16
|
+
pathname?: string | null;
|
|
17
|
+
/** Client-side navigation (`router.push`). Default: a normal link. */
|
|
18
|
+
navigate?: (href: string) => void;
|
|
19
|
+
labels?: FrameworkBannerLabels;
|
|
20
|
+
className?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Shown on a docs page whose framework is not the one the visitor chose:
|
|
24
|
+
* a shared link, a search result, or a page their framework doesn't have yet.
|
|
25
|
+
* It never redirects, so links stay stable and crawlers see one page per URL.
|
|
26
|
+
*
|
|
27
|
+
* - The page exists in the preferred framework: a link to it, and a way to
|
|
28
|
+
* keep the page's framework from now on.
|
|
29
|
+
* - It doesn't: a notice ("React only for now").
|
|
30
|
+
*
|
|
31
|
+
* Renders nothing without a stored preference, and until hydration.
|
|
32
|
+
*/
|
|
33
|
+
export declare function FrameworkBanner<Id extends string>(props: FrameworkBannerProps<Id>): ReactNode;
|
|
34
|
+
//# sourceMappingURL=FrameworkBanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkBanner.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkBanner.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG7E,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,qBAAqB,GAAG;IAClC,mGAAmG;IACnG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAUF,MAAM,MAAM,oBAAoB,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC,GAAG;IAClF,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAKF;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,EAAE,oBAAoB,CAAC,EAAE,CAAC,GAAG,SAAS,CAsD7F"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { splitHref } from "../routing.js";
|
|
5
|
+
import { EXPLICIT_LINK_ATTRIBUTE, isPlainClick, useFrameworkPreference, useFrameworks, usePagePath, } from "./useFrameworkPreference.js";
|
|
6
|
+
const DEFAULT_LABELS = {
|
|
7
|
+
available: 'You are reading the {page} docs.',
|
|
8
|
+
view: 'View this page for {preferred}',
|
|
9
|
+
keep: 'Stay with {page}',
|
|
10
|
+
missing: '{page} only for now: this page is not available for {preferred} yet.',
|
|
11
|
+
dismiss: 'Dismiss',
|
|
12
|
+
};
|
|
13
|
+
const fill = (text, values) => text.replace(/\{(\w+)\}/g, (match, name) => values[name] ?? match);
|
|
14
|
+
/**
|
|
15
|
+
* Shown on a docs page whose framework is not the one the visitor chose:
|
|
16
|
+
* a shared link, a search result, or a page their framework doesn't have yet.
|
|
17
|
+
* It never redirects, so links stay stable and crawlers see one page per URL.
|
|
18
|
+
*
|
|
19
|
+
* - The page exists in the preferred framework: a link to it, and a way to
|
|
20
|
+
* keep the page's framework from now on.
|
|
21
|
+
* - It doesn't: a notice ("React only for now").
|
|
22
|
+
*
|
|
23
|
+
* Renders nothing without a stored preference, and until hydration.
|
|
24
|
+
*/
|
|
25
|
+
export function FrameworkBanner(props) {
|
|
26
|
+
const { navigate, className } = props;
|
|
27
|
+
const labels = { ...DEFAULT_LABELS, ...props.labels };
|
|
28
|
+
const { frameworks, hasPage } = useFrameworks(props);
|
|
29
|
+
const [preference, setPreference] = useFrameworkPreference(frameworks);
|
|
30
|
+
const pathname = usePagePath(props.pathname);
|
|
31
|
+
const [dismissedFor, setDismissedFor] = useState(null);
|
|
32
|
+
// a dismissal lasts until the next page
|
|
33
|
+
useEffect(() => setDismissedFor(null), [pathname]);
|
|
34
|
+
const pageFramework = pathname ? frameworks.frameworkOf(pathname) : null;
|
|
35
|
+
if (!pathname || !preference || !pageFramework || pageFramework === preference || dismissedFor === pathname) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const neutral = frameworks.neutralPath(pathname);
|
|
39
|
+
const available = hasPage(splitHref(neutral)[0], preference);
|
|
40
|
+
const href = frameworks.pathFor(neutral, preference);
|
|
41
|
+
const names = { preferred: frameworks.label(preference), page: frameworks.label(pageFramework) };
|
|
42
|
+
const onView = (event) => {
|
|
43
|
+
if (!navigate || !isPlainClick(event))
|
|
44
|
+
return;
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
navigate(href);
|
|
47
|
+
};
|
|
48
|
+
return (_jsxs("div", { className: `dk-framework-banner${className ? ` ${className}` : ''}`, role: "status", "data-framework": preference, "data-available": available ? 'true' : 'false', children: [_jsx("span", { className: "dk-framework-banner-text", children: fill(available ? labels.available : labels.missing, names) }), available ? (_jsxs(_Fragment, { children: [_jsx("a", { className: "dk-framework-banner-link", href: href, onClick: onView, [EXPLICIT_LINK_ATTRIBUTE]: '', children: fill(labels.view, names) }), _jsx("button", { type: "button", className: "dk-framework-banner-action", onClick: () => setPreference(pageFramework), children: fill(labels.keep, names) })] })) : null, _jsx("button", { type: "button", className: "dk-framework-banner-dismiss", "aria-label": labels.dismiss, title: labels.dismiss, onClick: () => setDismissedFor(pathname), children: "\u00D7" })] }));
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=FrameworkBanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkBanner.js","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkBanner.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAmC,MAAM,OAAO,CAAC;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AAcrC,MAAM,cAAc,GAAoC;IACtD,SAAS,EAAE,kCAAkC;IAC7C,IAAI,EAAE,gCAAgC;IACtC,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,sEAAsE;IAC/E,OAAO,EAAE,SAAS;CACnB,CAAC;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,GAClB,IACR,CACJ,CAAC,CAAC,CAAC,IAAI,EACR,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,6BAA6B,gBAC3B,MAAM,CAAC,OAAO,EAC1B,KAAK,EAAE,MAAM,CAAC,OAAO,EACrB,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,uBAGjC,IACL,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type FrameworkContentProps = {
|
|
3
|
+
/** Shown for this framework, or one of a comma-separated list: `framework="vue"`, `framework="react,vue"`. */
|
|
4
|
+
framework?: string | string[];
|
|
5
|
+
/** Shown for every framework but this one (or these). */
|
|
6
|
+
not?: string | string[];
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The MDX component for the parts of a page that differ per framework:
|
|
11
|
+
*
|
|
12
|
+
* <FrameworkContent framework="vue">
|
|
13
|
+
* Bind it with `v-model`.
|
|
14
|
+
* </FrameworkContent>
|
|
15
|
+
*
|
|
16
|
+
* Each framework has its own page, so this is decided when the page is
|
|
17
|
+
* built: the other frameworks' blocks aren't in the HTML at all. Create one
|
|
18
|
+
* per page with the framework it is rendered for.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createFrameworkContent(pageFramework: string): (props: FrameworkContentProps) => ReactNode;
|
|
21
|
+
//# sourceMappingURL=FrameworkContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkContent.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,qBAAqB,GAAG;IAClC,8GAA8G;IAC9G,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC;AAKF;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,IACzB,OAAO,qBAAqB,KAAG,SAAS,CAO1E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
const asList = (value) => (Array.isArray(value) ? value : (value ?? '').split(',')).map((item) => item.trim()).filter(Boolean);
|
|
3
|
+
/**
|
|
4
|
+
* The MDX component for the parts of a page that differ per framework:
|
|
5
|
+
*
|
|
6
|
+
* <FrameworkContent framework="vue">
|
|
7
|
+
* Bind it with `v-model`.
|
|
8
|
+
* </FrameworkContent>
|
|
9
|
+
*
|
|
10
|
+
* Each framework has its own page, so this is decided when the page is
|
|
11
|
+
* built: the other frameworks' blocks aren't in the HTML at all. Create one
|
|
12
|
+
* per page with the framework it is rendered for.
|
|
13
|
+
*/
|
|
14
|
+
export function createFrameworkContent(pageFramework) {
|
|
15
|
+
return function FrameworkContent(props) {
|
|
16
|
+
const only = asList(props.framework);
|
|
17
|
+
const except = asList(props.not);
|
|
18
|
+
if (only.length && !only.includes(pageFramework))
|
|
19
|
+
return null;
|
|
20
|
+
if (except.includes(pageFramework))
|
|
21
|
+
return null;
|
|
22
|
+
return _jsx(_Fragment, { children: props.children });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=FrameworkContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkContent.js","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkContent.tsx"],"names":[],"mappings":";AAUA,MAAM,MAAM,GAAG,CAAC,KAAoC,EAAE,EAAE,CACtD,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAEvG;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAAqB;IAC1D,OAAO,SAAS,gBAAgB,CAAC,KAA4B;QAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;YAAE,OAAO,IAAI,CAAC;QAC9D,IAAI,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC;YAAE,OAAO,IAAI,CAAC;QAChD,OAAO,4BAAG,KAAK,CAAC,QAAQ,GAAI,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type FrameworkProps } from './useFrameworkPreference.ts';
|
|
2
|
+
export type FrameworkLinksProps<Id extends string = string> = FrameworkProps<Id> & {
|
|
3
|
+
/** Client-side navigation (`router.push`). Default: `location.assign`. */
|
|
4
|
+
navigate?: (href: string) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Makes in-site navigation follow the visitor's framework: a click on a docs
|
|
8
|
+
* link of another framework goes to the same page in theirs, when it exists
|
|
9
|
+
* (see `resolveNavigation`). Mount it once, anywhere in the layout; it
|
|
10
|
+
* renders nothing.
|
|
11
|
+
*
|
|
12
|
+
* Only plain left clicks on same-origin links are taken over. Links marked
|
|
13
|
+
* with `data-framework-explicit` (the switcher, the banner) are left alone.
|
|
14
|
+
*/
|
|
15
|
+
export declare function FrameworkLinks<Id extends string>(props: FrameworkLinksProps<Id>): null;
|
|
16
|
+
//# sourceMappingURL=FrameworkLinks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkLinks.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkLinks.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAwD,KAAK,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAExH,MAAM,MAAM,mBAAmB,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC,GAAG;IACjF,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAAC,EAAE,CAAC,QA6B/E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { readFrameworkPreference } from "../preference.js";
|
|
4
|
+
import { resolveNavigation } from "../routing.js";
|
|
5
|
+
import { EXPLICIT_LINK_ATTRIBUTE, isPlainClick, useFrameworks } from "./useFrameworkPreference.js";
|
|
6
|
+
/**
|
|
7
|
+
* Makes in-site navigation follow the visitor's framework: a click on a docs
|
|
8
|
+
* link of another framework goes to the same page in theirs, when it exists
|
|
9
|
+
* (see `resolveNavigation`). Mount it once, anywhere in the layout; it
|
|
10
|
+
* renders nothing.
|
|
11
|
+
*
|
|
12
|
+
* Only plain left clicks on same-origin links are taken over. Links marked
|
|
13
|
+
* with `data-framework-explicit` (the switcher, the banner) are left alone.
|
|
14
|
+
*/
|
|
15
|
+
export function FrameworkLinks(props) {
|
|
16
|
+
const { navigate } = props;
|
|
17
|
+
const { frameworks, hasPage } = useFrameworks(props);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const onClick = (event) => {
|
|
20
|
+
if (event.defaultPrevented || !isPlainClick(event))
|
|
21
|
+
return;
|
|
22
|
+
const anchor = event.target?.closest?.('a[href]');
|
|
23
|
+
if (!anchor || anchor.hasAttribute(EXPLICIT_LINK_ATTRIBUTE) || anchor.hasAttribute('download'))
|
|
24
|
+
return;
|
|
25
|
+
if (anchor.target && anchor.target !== '_self')
|
|
26
|
+
return;
|
|
27
|
+
if (anchor.origin !== window.location.origin)
|
|
28
|
+
return;
|
|
29
|
+
const href = resolveNavigation(frameworks, {
|
|
30
|
+
href: `${anchor.pathname}${anchor.search}${anchor.hash}`,
|
|
31
|
+
pagePath: window.location.pathname,
|
|
32
|
+
preference: readFrameworkPreference(frameworks),
|
|
33
|
+
hasPage,
|
|
34
|
+
});
|
|
35
|
+
if (!href)
|
|
36
|
+
return;
|
|
37
|
+
// before the site's own link handling (a router's click handler on the same element)
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
event.stopPropagation();
|
|
40
|
+
if (navigate)
|
|
41
|
+
navigate(href);
|
|
42
|
+
else
|
|
43
|
+
window.location.assign(href);
|
|
44
|
+
};
|
|
45
|
+
document.addEventListener('click', onClick, true);
|
|
46
|
+
return () => document.removeEventListener('click', onClick, true);
|
|
47
|
+
}, [frameworks, hasPage, navigate]);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=FrameworkLinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkLinks.js","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkLinks.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,aAAa,EAAuB,MAAM,6BAA6B,CAAC;AAOxH;;;;;;;;GAQG;AACH,MAAM,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F,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAClD,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEpC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type FrameworkProps } from './useFrameworkPreference.ts';
|
|
2
|
+
export type FrameworkSwitcherProps<Id extends string = string> = FrameworkProps<Id> & {
|
|
3
|
+
/** The page's path, from the site's router. Default: `location.pathname`, after hydration. */
|
|
4
|
+
pathname?: string | null;
|
|
5
|
+
/** Client-side navigation (`router.push`). Default: a normal link. */
|
|
6
|
+
navigate?: (href: string) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Where a framework's option goes from a page outside the framework roots
|
|
9
|
+
* (blog, pricing), e.g. `{ react: '/docs', vue: '/vue' }`. Without it the
|
|
10
|
+
* option only stores the choice there.
|
|
11
|
+
*/
|
|
12
|
+
home?: Partial<Record<Id, string>>;
|
|
13
|
+
/** Accessible name of the group. Default `Framework`. */
|
|
14
|
+
label?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Picks the docs framework. Each option is a link to the same page in that
|
|
19
|
+
* framework (or the nearest parent that exists there), so it works without
|
|
20
|
+
* JavaScript and for crawlers; clicking it also stores the choice, which the
|
|
21
|
+
* rest of the site follows (`FrameworkLinks`, `FrameworkBanner`).
|
|
22
|
+
*
|
|
23
|
+
* Self-contained, with a minimal look (`frameworks/styles.css`): restyle
|
|
24
|
+
* `.dk-framework-switcher` / `.dk-framework-option`, or the `--dk-*` variables.
|
|
25
|
+
*/
|
|
26
|
+
export declare function FrameworkSwitcher<Id extends string>(props: FrameworkSwitcherProps<Id>): import("react").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=FrameworkSwitcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkSwitcher.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkSwitcher.tsx"],"names":[],"mappings":"AAKA,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,sBAAsB,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC,GAAG;IACpF,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACnC,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,EAAE,CAAC,+BAsCrF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { resolveSwitchTarget } from "../routing.js";
|
|
4
|
+
import { EXPLICIT_LINK_ATTRIBUTE, isPlainClick, useFrameworkPreference, useFrameworks, usePagePath, } from "./useFrameworkPreference.js";
|
|
5
|
+
/**
|
|
6
|
+
* Picks the docs framework. Each option is a link to the same page in that
|
|
7
|
+
* framework (or the nearest parent that exists there), so it works without
|
|
8
|
+
* JavaScript and for crawlers; clicking it also stores the choice, which the
|
|
9
|
+
* rest of the site follows (`FrameworkLinks`, `FrameworkBanner`).
|
|
10
|
+
*
|
|
11
|
+
* Self-contained, with a minimal look (`frameworks/styles.css`): restyle
|
|
12
|
+
* `.dk-framework-switcher` / `.dk-framework-option`, or the `--dk-*` variables.
|
|
13
|
+
*/
|
|
14
|
+
export function FrameworkSwitcher(props) {
|
|
15
|
+
const { navigate, home, label = 'Framework', className } = props;
|
|
16
|
+
const { frameworks, hasPage } = useFrameworks(props);
|
|
17
|
+
const [preference, setPreference] = useFrameworkPreference(frameworks);
|
|
18
|
+
const pathname = usePagePath(props.pathname);
|
|
19
|
+
// on a docs page the URL says which framework is shown; elsewhere the stored choice does
|
|
20
|
+
const current = (pathname ? frameworks.frameworkOf(pathname) : null) ?? preference ?? frameworks.default;
|
|
21
|
+
return (_jsx("div", { className: `dk-framework-switcher${className ? ` ${className}` : ''}`, role: "group", "aria-label": label, children: frameworks.ids.map((id) => {
|
|
22
|
+
const target = pathname ? resolveSwitchTarget(frameworks, pathname, id, hasPage) : null;
|
|
23
|
+
const href = target?.href ?? (pathname && frameworks.frameworkOf(pathname) == null ? home?.[id] : undefined);
|
|
24
|
+
const active = id === current;
|
|
25
|
+
const onClick = (event) => {
|
|
26
|
+
setPreference(id);
|
|
27
|
+
if (!href || !navigate || !isPlainClick(event))
|
|
28
|
+
return;
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
if (!active || pathname !== href)
|
|
31
|
+
navigate(href);
|
|
32
|
+
};
|
|
33
|
+
const shared = {
|
|
34
|
+
className: `dk-framework-option${active ? ' dk-framework-option--active' : ''}`,
|
|
35
|
+
'data-framework': id,
|
|
36
|
+
'aria-current': active ? 'true' : undefined,
|
|
37
|
+
onClick,
|
|
38
|
+
};
|
|
39
|
+
return href ? (_jsx("a", { href: href, [EXPLICIT_LINK_ATTRIBUTE]: '', ...shared, children: frameworks.label(id) }, id)) : (_jsx("button", { type: "button", ...shared, children: frameworks.label(id) }, id));
|
|
40
|
+
}) }));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=FrameworkSwitcher.js.map
|
|
@@ -0,0 +1 @@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tsx';
|
|
2
|
+
export { FrameworkBanner, type FrameworkBannerLabels, type FrameworkBannerProps } from './FrameworkBanner.tsx';
|
|
3
|
+
export { FrameworkLinks, type FrameworkLinksProps } from './FrameworkLinks.tsx';
|
|
4
|
+
export { FrameworkSwitcher, type FrameworkSwitcherProps } from './FrameworkSwitcher.tsx';
|
|
5
|
+
export { EXPLICIT_LINK_ATTRIBUTE, useFrameworkPreference, useFrameworks, type FrameworkProps, } from './useFrameworkPreference.ts';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,aAAa,EACb,KAAK,cAAc,GACpB,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createFrameworkContent } from "./FrameworkContent.js";
|
|
2
|
+
export { FrameworkBanner } from "./FrameworkBanner.js";
|
|
3
|
+
export { FrameworkLinks } from "./FrameworkLinks.js";
|
|
4
|
+
export { FrameworkSwitcher } from "./FrameworkSwitcher.js";
|
|
5
|
+
export { EXPLICIT_LINK_ATTRIBUTE, useFrameworkPreference, useFrameworks, } from "./useFrameworkPreference.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frameworks/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAA8B,MAAM,uBAAwB,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAyD,MAAM,sBAAuB,CAAC;AAC/G,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAsB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAA+B,MAAM,wBAAyB,CAAC;AACzF,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,aAAa,GAEd,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Frameworks, type FrameworksConfig, type HasPage } from '../routing.ts';
|
|
2
|
+
/** What every framework component needs; plain data, so a server component can pass it down. */
|
|
3
|
+
export type FrameworkProps<Id extends string = string> = {
|
|
4
|
+
config: FrameworksConfig<Id>;
|
|
5
|
+
/**
|
|
6
|
+
* Neutral paths of the pages each framework has. A framework without a
|
|
7
|
+
* list has every page (usually the default one).
|
|
8
|
+
*/
|
|
9
|
+
pages: Partial<Record<Id, readonly string[]>>;
|
|
10
|
+
};
|
|
11
|
+
export declare function useFrameworks<Id extends string>(props: FrameworkProps<Id>): {
|
|
12
|
+
frameworks: Frameworks<Id>;
|
|
13
|
+
hasPage: HasPage<Id>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The visitor's stored framework and a setter. `null` during server
|
|
17
|
+
* rendering and hydration, and when nothing is stored.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useFrameworkPreference<Id extends string>(frameworks: Frameworks<Id>): [preference: Id | null, setPreference: (framework: Id | null) => void];
|
|
20
|
+
/** The page's path: the prop when given (routers know it during server rendering), else `location.pathname`. */
|
|
21
|
+
export declare function usePagePath(pathname: string | null | undefined): string | null;
|
|
22
|
+
/** Marks links the visitor's preference must not rewrite (the switcher, the banner). */
|
|
23
|
+
export declare const EXPLICIT_LINK_ATTRIBUTE = "data-framework-explicit";
|
|
24
|
+
/** A plain left click, without modifier keys: the only clicks the components take over. */
|
|
25
|
+
export declare function isPlainClick(event: {
|
|
26
|
+
button: number;
|
|
27
|
+
metaKey: boolean;
|
|
28
|
+
ctrlKey: boolean;
|
|
29
|
+
shiftKey: boolean;
|
|
30
|
+
altKey: boolean;
|
|
31
|
+
}): boolean;
|
|
32
|
+
//# sourceMappingURL=useFrameworkPreference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFrameworkPreference.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/useFrameworkPreference.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACb,MAAM,eAAe,CAAC;AAEvB,gGAAgG;AAChG,MAAM,MAAM,cAAc,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,IAAI;IACvD,MAAM,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC7B;;;OAGG;IACH,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,EAAE,CAAC,GAAG;IAC3E,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;CACtB,CAGA;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,SAAS,MAAM,EACtD,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,GACzB,CAAC,UAAU,EAAE,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,CAAC,SAAS,EAAE,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC,CAyBxE;AAED,gHAAgH;AAChH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAO9E;AAOD,wFAAwF;AACxF,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,WAE7H"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useMemo, useSyncExternalStore } from 'react';
|
|
3
|
+
import { FRAMEWORK_CHANGE_EVENT, frameworkStorageKey, readFrameworkPreference, writeFrameworkPreference, } from "../preference.js";
|
|
4
|
+
import { createHasPage, defineFrameworks, } from "../routing.js";
|
|
5
|
+
export function useFrameworks(props) {
|
|
6
|
+
const { config, pages } = props;
|
|
7
|
+
return useMemo(() => ({ frameworks: defineFrameworks(config), hasPage: createHasPage(pages) }), [config, pages]);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The visitor's stored framework and a setter. `null` during server
|
|
11
|
+
* rendering and hydration, and when nothing is stored.
|
|
12
|
+
*/
|
|
13
|
+
export function useFrameworkPreference(frameworks) {
|
|
14
|
+
const subscribe = useCallback((onChange) => {
|
|
15
|
+
const onStorage = (event) => {
|
|
16
|
+
if (event.key == null || event.key === frameworkStorageKey(frameworks))
|
|
17
|
+
onChange();
|
|
18
|
+
};
|
|
19
|
+
window.addEventListener('storage', onStorage);
|
|
20
|
+
window.addEventListener(FRAMEWORK_CHANGE_EVENT, onChange);
|
|
21
|
+
return () => {
|
|
22
|
+
window.removeEventListener('storage', onStorage);
|
|
23
|
+
window.removeEventListener(FRAMEWORK_CHANGE_EVENT, onChange);
|
|
24
|
+
};
|
|
25
|
+
}, [frameworks]);
|
|
26
|
+
const preference = useSyncExternalStore(subscribe, () => readFrameworkPreference(frameworks), () => null);
|
|
27
|
+
const setPreference = useCallback((framework) => writeFrameworkPreference(frameworks, framework), [frameworks]);
|
|
28
|
+
return [preference, setPreference];
|
|
29
|
+
}
|
|
30
|
+
/** The page's path: the prop when given (routers know it during server rendering), else `location.pathname`. */
|
|
31
|
+
export function usePagePath(pathname) {
|
|
32
|
+
const fromLocation = useSyncExternalStore(subscribeToLocation, () => window.location.pathname, () => null);
|
|
33
|
+
return pathname ?? fromLocation;
|
|
34
|
+
}
|
|
35
|
+
function subscribeToLocation(onChange) {
|
|
36
|
+
window.addEventListener('popstate', onChange);
|
|
37
|
+
return () => window.removeEventListener('popstate', onChange);
|
|
38
|
+
}
|
|
39
|
+
/** Marks links the visitor's preference must not rewrite (the switcher, the banner). */
|
|
40
|
+
export const EXPLICIT_LINK_ATTRIBUTE = 'data-framework-explicit';
|
|
41
|
+
/** A plain left click, without modifier keys: the only clicks the components take over. */
|
|
42
|
+
export function isPlainClick(event) {
|
|
43
|
+
return event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=useFrameworkPreference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFrameworkPreference.js","sourceRoot":"","sources":["../../../src/frameworks/react/useFrameworkPreference.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,gBAAgB,GAIjB,MAAM,eAAe,CAAC;AAYvB,MAAM,UAAU,aAAa,CAAoB,KAAyB;IAIxE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAChC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,gBAAgB,CAA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