@thedatagrid/docs-kit 0.2.2 → 0.4.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 +30 -0
- package/README.md +206 -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 +27 -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/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 +15 -1
- package/dist/fork/codesandbox.d.ts.map +1 -1
- package/dist/fork/codesandbox.js +30 -19
- package/dist/fork/codesandbox.js.map +1 -1
- package/dist/fork/index.d.ts +18 -0
- package/dist/fork/index.d.ts.map +1 -1
- package/dist/fork/index.js +18 -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 +6 -5
- 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/dist/showcase/AutomatedDemo.d.ts +46 -0
- package/dist/showcase/AutomatedDemo.d.ts.map +1 -0
- package/dist/showcase/AutomatedDemo.js +169 -0
- package/dist/showcase/AutomatedDemo.js.map +1 -0
- package/dist/showcase/LazyShowcase.d.ts +31 -0
- package/dist/showcase/LazyShowcase.d.ts.map +1 -0
- package/dist/showcase/LazyShowcase.js +51 -0
- package/dist/showcase/LazyShowcase.js.map +1 -0
- package/dist/showcase/hooks.d.ts +19 -0
- package/dist/showcase/hooks.d.ts.map +1 -0
- package/dist/showcase/hooks.js +63 -0
- package/dist/showcase/hooks.js.map +1 -0
- package/dist/showcase/index.d.ts +17 -0
- package/dist/showcase/index.d.ts.map +1 -0
- package/dist/showcase/index.js +15 -0
- package/dist/showcase/index.js.map +1 -0
- package/dist/showcase/scripted.d.ts +100 -0
- package/dist/showcase/scripted.d.ts.map +1 -0
- package/dist/showcase/scripted.js +381 -0
- package/dist/showcase/scripted.js.map +1 -0
- package/dist/showcase/styles.css +174 -0
- package/package.json +34 -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 +44 -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/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 +43 -21
- package/src/fork/index.ts +25 -0
- package/src/fork/stackblitz.ts +107 -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 +12 -5
- 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
- package/src/showcase/AutomatedDemo.tsx +266 -0
- package/src/showcase/LazyShowcase.tsx +111 -0
- package/src/showcase/hooks.ts +84 -0
- package/src/showcase/index.ts +23 -0
- package/src/showcase/scripted.ts +533 -0
- package/src/showcase/styles.css +174 -0
|
@@ -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;AAWF,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAA8B,EAAE,EAAE,CAC5D,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAoB,KAA+B;IAChF,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACtC,M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|
+
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,UAAU,cAAc,CAAoB,KAA8B;IAC9E,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAErD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,CAAC,KAAiB,EAAE,EAAE;YACpC,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;gBAAE,OAAO;YAC3D,M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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 @@
|
|
|
1
|
+
{"version":3,"file":"FrameworkSwitcher.js","sourceRoot":"","sources":["../../../src/frameworks/react/FrameworkSwitcher.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AAkBrC;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB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AI,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;oBAAE,OAAO;gBACvD,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,IAAI,CAAC,MAAM,IAAI,QAAQ,KAAK,IAAI;oBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnD,CAAC,CAAC;YACF,MAAM,MAAM,GAAG;gBACb,SAAS,EAAE,sBAAsB,MAAM,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC/E,gBAAgB,EAAE,EAAE;gBACpB,cAAc,EAAE,MAAM,CAAC,CAAC,CAAE,MAAgB,CAAC,CAAC,CAAC,SAAS;gBACtD,OAAO;aACR,CAAC;YACF,OAAO,IAAI,CAAC,CAAC,CAAC,CACZ,YAAY,IAAI,EAAE,IAAI,EAAQ,CAAC,uBAAuB,CAAC,EAAE,EAAE,KAAQ,MAAM,YACtE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,IADf,EAAE,CAEN,CACL,CAAC,CAAC,CAAC,CACF,iBAAiB,IAAI,EAAC,QAAQ,KAAK,MAAM,YACtC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,IADV,EAAE,CAEN,CACV,CAAC;QACJ,CAAC,CAAC,GACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createFrameworkContent, type FrameworkContentProps } from './FrameworkContent.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/use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
|
|
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,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AACnH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAA0B;IAE1B,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,QAAoB,EAAE,EAAE;QACvB,MAAM,SAAS,GAAG,CAAC,KAAmB,EAAE,EAAE;YACxC,IAAI,KAAK,CAAC,GAAG,I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AC;AAED,wFAAwF;AACxF,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,2FAA2F;AAC3F,MAAM,UAAU,YAAY,CAAC,KAAiG;IAC5H,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Frameworks, type HasPage } from './routing.ts';
|
|
2
|
+
/** A sidebar entry: anything with an optional `path` and nested `routes`. */
|
|
3
|
+
export type RouteNode = {
|
|
4
|
+
path?: string;
|
|
5
|
+
routes?: RouteNode[];
|
|
6
|
+
};
|
|
7
|
+
export type MapRouteTreeOptions<R extends RouteNode, Id extends string> = {
|
|
8
|
+
/**
|
|
9
|
+
* A page the framework doesn't have:
|
|
10
|
+
* - `fallback` (default): the entry stays and links to the framework that
|
|
11
|
+
* has it; `onFallback` can mark it (a badge).
|
|
12
|
+
* - `hide`: the entry is dropped, unless one of its children stays.
|
|
13
|
+
*/
|
|
14
|
+
missing?: 'fallback' | 'hide';
|
|
15
|
+
/** Returns the entry to show for a fallback. Default: adds `fallbackFramework`. */
|
|
16
|
+
onFallback?: (route: R, fallbackFramework: Id) => R;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A sidebar tree written with neutral paths, for one framework: every path
|
|
20
|
+
* goes to that framework's page. Entries outside the framework roots are
|
|
21
|
+
* kept as they are; entries whose page exists nowhere are dropped.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapRouteTree<R extends RouteNode, Id extends string>(frameworks: Frameworks<Id>, routes: readonly R[], framework: Id, hasPage: HasPage<Id>, options?: MapRouteTreeOptions<R, Id>): R[];
|
|
24
|
+
//# sourceMappingURL=routeTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeTree.d.ts","sourceRoot":"","sources":["../../src/frameworks/routeTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnF,6EAA6E;AAC7E,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,SAAS,EAAE,EAAE,SAAS,MAAM,IAAI;IACxE;;;;;OAKG;IACH,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAC9B,mFAAmF;IACnF,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,iBAAiB,EAAE,EAAE,KAAK,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,EAAE,SAAS,MAAM,EACjE,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,EAC1B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,SAAS,EAAE,EAAE,EACb,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,EACpB,OAAO,GAAE,mBAAmB,CAAC,CAAC,EAAE,EAAE,CAAM,GACvC,CAAC,EAAE,CAyBL"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { resolveFrameworkLink } from "./routing.js";
|
|
2
|
+
/**
|
|
3
|
+
* A sidebar tree written with neutral paths, for one framework: every path
|
|
4
|
+
* goes to that framework's page. Entries outside the framework roots are
|
|
5
|
+
* kept as they are; entries whose page exists nowhere are dropped.
|
|
6
|
+
*/
|
|
7
|
+
export function mapRouteTree(frameworks, routes, framework, hasPage, options = {}) {
|
|
8
|
+
const { missing = 'fallback' } = options;
|
|
9
|
+
const onFallback = options.onFallback ?? ((route, fallbackFramework) => ({ ...route, fallbackFramework }));
|
|
10
|
+
const mapRoute = (route) => {
|
|
11
|
+
const children = route.routes ? route.routes.map(mapRoute).filter((child) => !!child) : undefined;
|
|
12
|
+
const withChildren = (mapped) => (children ? { ...mapped, routes: children } : mapped);
|
|
13
|
+
if (route.path == null)
|
|
14
|
+
return children && !children.length && route.routes?.length ? null : withChildren(route);
|
|
15
|
+
const link = resolveFrameworkLink(frameworks, route.path, framework, hasPage);
|
|
16
|
+
switch (link.kind) {
|
|
17
|
+
case 'shared':
|
|
18
|
+
return withChildren(route);
|
|
19
|
+
case 'page':
|
|
20
|
+
return withChildren({ ...route, path: link.href });
|
|
21
|
+
case 'fallback':
|
|
22
|
+
if (missing === 'hide' && !children?.length)
|
|
23
|
+
return null;
|
|
24
|
+
return withChildren(onFallback({ ...route, path: link.href }, link.framework));
|
|
25
|
+
case 'missing':
|
|
26
|
+
return children?.length ? withChildren(route) : null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return routes.map(mapRoute).filter((route) => !!route);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=routeTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeTree.js","sourceRoot":"","sources":["../../src/frameworks/routeTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAiC,MAAM,cAAc,CAAC;AAiBnF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,UAA0B,EAC1B,MAAoB,EACpB,SAAa,EACb,OAAoB,EACpB,UAAsC,EAAE;IAExC,MAAM,EAAE,OAAO,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,UAAU,GACd,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,KAAQ,EAAE,iBAAqB,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,iBAAiB,EAAE,CAAM,CAAC,CAAC;IAEtG,MAAM,QAAQ,GAAG,CAAC,KAAQ,EAAY,EAAE;QACtC,MAAM,QAAQ,G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AC,CAAC,CAAC,IAAI,CAAC;QACzD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAc,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docs for more than one framework, one URL tree per framework.
|
|
3
|
+
*
|
|
4
|
+
* The default framework keeps its URLs (`/docs/...`); every other framework
|
|
5
|
+
* lives under a prefix (`/vue/docs/...`). Authors write the default form
|
|
6
|
+
* everywhere (the "neutral" path); the build maps it to the page's framework.
|
|
7
|
+
* Only paths under `roots` exist per framework, the rest of the site (blog,
|
|
8
|
+
* pricing) is shared.
|
|
9
|
+
*
|
|
10
|
+
* Pure logic: no React, no Node, no DOM. It runs in the build (remark plugin,
|
|
11
|
+
* sitemap) and in the browser (switcher, banner, link following).
|
|
12
|
+
*/
|
|
13
|
+
export type FrameworkDefinition = {
|
|
14
|
+
/** Shown in the switcher, the banner and notices. */
|
|
15
|
+
label: string;
|
|
16
|
+
/** URL prefix of this framework's tree: `''` for the default one, `/vue` otherwise. */
|
|
17
|
+
prefix: string;
|
|
18
|
+
};
|
|
19
|
+
export type FrameworksConfig<Id extends string = string> = {
|
|
20
|
+
/** The framework whose URLs carry no prefix. */
|
|
21
|
+
default: Id;
|
|
22
|
+
frameworks: Record<Id, FrameworkDefinition>;
|
|
23
|
+
/** Path prefixes that exist once per framework, e.g. `['/docs']`. */
|
|
24
|
+
roots: string[];
|
|
25
|
+
/** `localStorage` key of the visitor's choice. Default `docs-framework`. */
|
|
26
|
+
storageKey?: string;
|
|
27
|
+
};
|
|
28
|
+
/** Does `neutralPath` (no trailing slash, no hash) have a page in `framework`? */
|
|
29
|
+
export type HasPage<Id extends string = string> = (neutralPath: string, framework: Id) => boolean;
|
|
30
|
+
export type Frameworks<Id extends string = string> = {
|
|
31
|
+
config: FrameworksConfig<Id>;
|
|
32
|
+
/** Default framework first. */
|
|
33
|
+
ids: Id[];
|
|
34
|
+
default: Id;
|
|
35
|
+
label(framework: Id): string;
|
|
36
|
+
/** The framework a URL path belongs to; `null` outside every root (a shared page). */
|
|
37
|
+
frameworkOf(href: string): Id | null;
|
|
38
|
+
/** The default framework's form of a path: `/vue/docs/x#y` → `/docs/x#y`. Shared paths are returned as they are. */
|
|
39
|
+
neutralPath(href: string): string;
|
|
40
|
+
/** A neutral path in a framework's tree: `/docs/x#y`, `vue` → `/vue/docs/x#y`. */
|
|
41
|
+
pathFor(neutralHref: string, framework: Id): string;
|
|
42
|
+
};
|
|
43
|
+
/** `/docs/x/?a=1#b` → `['/docs/x', '?a=1#b']`. The path loses its trailing slash. */
|
|
44
|
+
export declare function splitHref(href: string): [path: string, suffix: string];
|
|
45
|
+
export declare function defineFrameworks<Id extends string>(config: FrameworksConfig<Id>): Frameworks<Id>;
|
|
46
|
+
/**
|
|
47
|
+
* `HasPage` from lists of neutral paths per framework. A framework without a
|
|
48
|
+
* list has every page (the usual case for the default framework).
|
|
49
|
+
*/
|
|
50
|
+
export declare function createHasPage<Id extends string>(pages: Partial<Record<Id, readonly string[]>>): HasPage<Id>;
|
|
51
|
+
export type ResolvedLink<Id extends string = string> =
|
|
52
|
+
/** Outside the framework roots: the same URL for everyone. */
|
|
53
|
+
{
|
|
54
|
+
kind: 'shared';
|
|
55
|
+
href: string;
|
|
56
|
+
}
|
|
57
|
+
/** The page exists in the wanted framework. */
|
|
58
|
+
| {
|
|
59
|
+
kind: 'page';
|
|
60
|
+
href: string;
|
|
61
|
+
framework: Id;
|
|
62
|
+
}
|
|
63
|
+
/** It doesn't; `framework` is the one whose page the link goes to instead. */
|
|
64
|
+
| {
|
|
65
|
+
kind: 'fallback';
|
|
66
|
+
href: string;
|
|
67
|
+
framework: Id;
|
|
68
|
+
}
|
|
69
|
+
/** No framework has this page. */
|
|
70
|
+
| {
|
|
71
|
+
kind: 'missing';
|
|
72
|
+
neutralPath: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Where a link written in the neutral form goes on a page of `framework`:
|
|
76
|
+
* that framework's page, else the default framework's, else any other's.
|
|
77
|
+
*/
|
|
78
|
+
export declare function resolveFrameworkLink<Id extends string>(frameworks: Frameworks<Id>, href: string, framework: Id, hasPage: HasPage<Id>): ResolvedLink<Id>;
|
|
79
|
+
/**
|
|
80
|
+
* Where the switcher goes from `pathname` when the visitor picks `target`:
|
|
81
|
+
* the same page, or the nearest parent that exists in that framework (`exact`
|
|
82
|
+
* is then false). `null` on shared pages and when the framework has no page
|
|
83
|
+
* on the way up: the switcher then only stores the preference.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveSwitchTarget<Id extends string>(frameworks: Frameworks<Id>, pathname: string, target: Id, hasPage: HasPage<Id>): {
|
|
86
|
+
href: string;
|
|
87
|
+
exact: boolean;
|
|
88
|
+
} | null;
|
|
89
|
+
/**
|
|
90
|
+
* Following the visitor's preference when they click a docs link. Returns the
|
|
91
|
+
* URL to go to instead, or `null` to leave the link alone.
|
|
92
|
+
*
|
|
93
|
+
* - With a stored preference, a link to another framework's page goes to the
|
|
94
|
+
* preferred framework when the page exists there.
|
|
95
|
+
* - Without one, a page of a non-default framework keeps the visitor in its
|
|
96
|
+
* tree: links in the default form (a shared header, a component that builds
|
|
97
|
+
* its own URL) go to that framework. Nothing else is rewritten.
|
|
98
|
+
*/
|
|
99
|
+
export declare function resolveNavigation<Id extends string>(frameworks: Frameworks<Id>, options: {
|
|
100
|
+
href: string;
|
|
101
|
+
pagePath: string;
|
|
102
|
+
preference: Id | null;
|
|
103
|
+
hasPage: HasPage<Id>;
|
|
104
|
+
}): string | null;
|
|
105
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/frameworks/routing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;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