@takazudo/zudo-sg 0.4.1 → 0.5.1
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 +77 -0
- package/README.md +281 -61
- package/dist/catalog/catalog-thumb.d.ts +1 -6
- package/dist/catalog/catalog-thumb.js +1 -2
- package/dist/catalog/component-thumb.d.ts +1 -6
- package/dist/catalog/component-thumb.js +8 -7
- package/dist/catalog/descriptor-thumb.d.ts +1 -6
- package/dist/catalog/descriptor-thumb.js +1 -2
- package/dist/chrome/_styleguide-layout.d.ts +8 -9
- package/dist/chrome/_styleguide-layout.js +3 -6
- package/dist/chrome/panel-scripts.d.ts +1 -3
- package/dist/chrome/panel-scripts.js +3 -3
- package/dist/cli/scaffold/component-scaffold.js +35 -16
- package/dist/code-panel/code-panel.d.ts +2 -8
- package/dist/code-panel/code-panel.js +47 -38
- package/dist/code-panel/copy-button.d.ts +1 -7
- package/dist/code-panel/copy-button.js +31 -48
- package/dist/code-panel/copy-text.d.ts +1 -0
- package/dist/code-panel/copy-text.js +26 -0
- package/dist/code-panel/css-injection.d.ts +11 -5
- package/dist/code-panel/css-injection.js +179 -25
- package/dist/code-panel/source-editor.d.ts +1 -2
- package/dist/code-panel/source-editor.js +17 -18
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +6 -1
- package/dist/config/wind.d.ts +265 -0
- package/dist/config/wind.js +133 -0
- package/dist/plugins/preview-css.d.ts +9 -7
- package/dist/plugins/preview-css.js +58 -37
- package/dist/plugins/routes.d.ts +2 -0
- package/dist/plugins/routes.js +7 -3
- package/dist/preview/detail-workbench.d.ts +3 -6
- package/dist/preview/detail-workbench.js +103 -65
- package/dist/preview/external-runtime.d.ts +117 -0
- package/dist/preview/external-runtime.js +121 -0
- package/dist/preview/index.d.ts +4 -2
- package/dist/preview/index.js +7 -7
- package/dist/preview/preview-app.d.ts +2 -5
- package/dist/preview/preview-app.js +76 -46
- package/dist/preview/runtime-controller.d.ts +34 -0
- package/dist/preview/runtime-controller.js +302 -0
- package/dist/preview/variant-frame-config.d.ts +47 -0
- package/dist/preview/variant-frame-config.js +50 -0
- package/dist/preview/variant-frame.d.ts +12 -53
- package/dist/preview/variant-frame.js +313 -158
- package/dist/preview-css/compile.d.ts +15 -29
- package/dist/preview-css/compile.js +183 -31
- package/dist/registry/catalog.d.ts +2 -0
- package/dist/registry/catalog.js +2 -1
- package/dist/registry/descriptors.d.ts +3 -0
- package/dist/registry/descriptors.js +6 -1
- package/dist/registry/external-catalog-node.d.ts +65 -0
- package/dist/registry/external-catalog-node.js +220 -0
- package/dist/registry/external-catalog.d.ts +44 -0
- package/dist/registry/external-catalog.js +72 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.js +4 -0
- package/dist/search/catalog-filter.d.ts +2 -6
- package/dist/search/catalog-filter.js +50 -42
- package/dist/sg-context.d.ts +2 -0
- package/dist/stories/types.d.ts +5 -3
- package/dist/token-dashboard/create-token-dashboards.d.ts +3 -5
- package/dist/token-dashboard/create-token-dashboards.js +14 -44
- package/dist/token-dashboard/dashboard-inventory.d.ts +1 -1
- package/dist/token-dashboard/token-dashboard-adapter.d.ts +2 -0
- package/dist/token-dashboard/token-dashboard-adapter.js +9 -0
- package/dist/token-dashboard/token-dashboard-mount.d.ts +6 -0
- package/dist/token-dashboard/token-dashboard-mount.js +33 -0
- package/dist/token-tweak/iframe-css-vars-bridge.d.ts +14 -6
- package/dist/token-tweak/iframe-css-vars-bridge.js +46 -17
- package/dist/token-tweak/index.d.ts +1 -1
- package/dist/token-tweak/index.js +2 -0
- package/dist/token-tweak/preview-iframe-registry.d.ts +10 -1
- package/dist/token-tweak/preview-iframe-registry.js +48 -7
- package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +1 -6
- package/dist/token-tweak/preview-token-panel-bootstrap.js +4 -2
- package/dist/token-tweak/preview-tokens-button.d.ts +1 -5
- package/dist/token-tweak/preview-tokens-button.js +5 -4
- package/dist/wind.json +119 -0
- package/package.json +34 -22
- package/routes-src/_chrome.tsx +1 -3
- package/routes-src/_preview-app.tsx +3 -8
- package/routes-src/components-index.tsx +5 -10
- package/routes-src/components-preview.tsx +3 -9
- package/routes-src/components-slug.tsx +33 -33
- package/routes-src/tokens.tsx +4 -9
- package/styles.css +17 -11
- package/dist/safelist.css +0 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { ComponentChildren, JSX, VNode } from "preact";
|
|
1
|
+
import type { Child, Description } from "@takazudo/zfb/zudo-react";
|
|
2
|
+
import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
4
3
|
import type { NavNode } from "../registry/nav-nodes.js";
|
|
5
4
|
export interface StyleguideLayoutProps {
|
|
6
5
|
/**
|
|
@@ -21,19 +20,19 @@ export interface StyleguideLayoutProps {
|
|
|
21
20
|
/** Hide the component sidebar for standalone pages such as /tokens. */
|
|
22
21
|
hideSidebar?: boolean;
|
|
23
22
|
/** `<head>` content — the host passes its `HeadWithDefaults` output. */
|
|
24
|
-
head:
|
|
23
|
+
head: Child;
|
|
25
24
|
/** Header region — the host passes its `HeaderWithDefaults` output. */
|
|
26
|
-
header:
|
|
25
|
+
header: Child;
|
|
27
26
|
/** Footer region — the host passes its `FooterWithDefaults` output. */
|
|
28
|
-
footer:
|
|
27
|
+
footer: Child;
|
|
29
28
|
/** Body-end islands — the host passes its `BodyEndIslands` output. */
|
|
30
|
-
bodyEnd:
|
|
29
|
+
bodyEnd: Child;
|
|
31
30
|
/**
|
|
32
31
|
* Right-region code panel content (detail pages only, #49). When present the
|
|
33
32
|
* TOC slot hosts it; when absent the slot is empty and `hideToc` frees the
|
|
34
33
|
* width.
|
|
35
34
|
*/
|
|
36
|
-
codePanel?:
|
|
35
|
+
codePanel?: Description | null;
|
|
37
36
|
/**
|
|
38
37
|
* Opt the content band into the DocLayout **wide** layout — forwarded
|
|
39
38
|
* verbatim to `DocLayoutWithDefaults contentWide`. Defaults to `false`.
|
|
@@ -54,6 +53,6 @@ export interface StyleguideLayoutProps {
|
|
|
54
53
|
enableClientRouter: boolean;
|
|
55
54
|
/** Mirrors the host's `settings.noindex`. */
|
|
56
55
|
noindex: boolean;
|
|
57
|
-
children:
|
|
56
|
+
children: Child;
|
|
58
57
|
}
|
|
59
58
|
export declare function StyleguideLayout({ title, activeSlug, lang, hideSidebar, head, header, footer, bodyEnd, codePanel, contentWide, navNodes, sidebarToggle, enableClientRouter, noindex, children, }: StyleguideLayoutProps): JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fragment, jsx, jsxs } from "
|
|
1
|
+
import { Fragment, jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
2
2
|
import { Island } from "@takazudo/zfb";
|
|
3
3
|
import { DocLayoutWithDefaults } from "@takazudo/zudo-doc/doclayout";
|
|
4
4
|
import { SidebarTree } from "@takazudo/zudo-doc/sidebar-tree-island";
|
|
@@ -28,11 +28,8 @@ function StyleguideLayout({
|
|
|
28
28
|
const sidebarToggleSettings = { sidebarToggle };
|
|
29
29
|
const SidebarPrepaint = createSidebarPrepaint(sidebarToggleSettings);
|
|
30
30
|
const SidebarVisibilityPrepaint = createSidebarVisibilityPrepaint(sidebarToggleSettings);
|
|
31
|
-
const sidebarOverride = hideSidebar ? /* @__PURE__ */ jsx(Fragment, {}) : Island({
|
|
32
|
-
|
|
33
|
-
children: /* @__PURE__ */ jsx(SidebarTree, { nodes: navNodes, currentSlug: activeSlug })
|
|
34
|
-
});
|
|
35
|
-
const tocOverride = showCodePanel ? codePanel : /* @__PURE__ */ jsx(Fragment, {});
|
|
31
|
+
const sidebarOverride = hideSidebar ? /* @__PURE__ */ jsx(Fragment, {}) : /* @__PURE__ */ jsx(Island, { when: "load", children: /* @__PURE__ */ jsx(SidebarTree, { nodes: navNodes, ...activeSlug !== void 0 ? { currentSlug: activeSlug } : {} }) });
|
|
32
|
+
const tocOverride = codePanel ?? /* @__PURE__ */ jsx(Fragment, {});
|
|
36
33
|
const composedHead = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
37
34
|
head,
|
|
38
35
|
/* @__PURE__ */ jsx(SidebarVisibilityPrepaint, { hideSidebar }),
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/** @jsxImportSource preact */
|
|
3
|
-
import type { JSX } from "preact";
|
|
1
|
+
import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
4
2
|
export declare function PanelStateHeadScript(): JSX.Element;
|
|
5
3
|
export declare function PanelResizersInitScript(): JSX.Element;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsx } from "
|
|
1
|
+
import { jsx } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
2
2
|
import { RESIZER_SCRIPT, RESTORE_SCRIPT } from "./panel-scripts-source";
|
|
3
3
|
function PanelStateHeadScript() {
|
|
4
|
-
return /* @__PURE__ */ jsx("script", {
|
|
4
|
+
return /* @__PURE__ */ jsx("script", { rawHtml: RESTORE_SCRIPT });
|
|
5
5
|
}
|
|
6
6
|
function PanelResizersInitScript() {
|
|
7
|
-
return /* @__PURE__ */ jsx("script", {
|
|
7
|
+
return /* @__PURE__ */ jsx("script", { rawHtml: RESIZER_SCRIPT });
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
10
|
PanelResizersInitScript,
|
|
@@ -29,14 +29,15 @@ function toPascalCase(kebabName) {
|
|
|
29
29
|
}
|
|
30
30
|
function componentTemplate({ pascalName }) {
|
|
31
31
|
const lines = [
|
|
32
|
-
`import type {
|
|
32
|
+
`import type { Child } from "@takazudo/zfb/zudo-react";`,
|
|
33
|
+
`import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";`,
|
|
33
34
|
``,
|
|
34
35
|
`export type ${pascalName}Variant = "primary" | "secondary";`,
|
|
35
36
|
``,
|
|
36
37
|
`export type ${pascalName}Props = {`,
|
|
37
38
|
` variant?: ${pascalName}Variant;`,
|
|
38
39
|
` class?: string;`,
|
|
39
|
-
` children?:
|
|
40
|
+
` children?: Child;`,
|
|
40
41
|
`};`,
|
|
41
42
|
``,
|
|
42
43
|
`const base =`,
|
|
@@ -53,7 +54,7 @@ function componentTemplate({ pascalName }) {
|
|
|
53
54
|
`/**`,
|
|
54
55
|
` * TODO: describe ${pascalName} \u2014 what it renders and when to use it.`,
|
|
55
56
|
` */`,
|
|
56
|
-
`export function ${pascalName}({ variant = "primary", class: cls, children }: ${pascalName}Props) {`,
|
|
57
|
+
`export function ${pascalName}({ variant = "primary", class: cls, children }: ${pascalName}Props): JSX.Element {`,
|
|
57
58
|
` const className = [base, variants[variant], cls].filter(Boolean).join(" ");`,
|
|
58
59
|
` return <div class={className}>{children}</div>;`,
|
|
59
60
|
`}`
|
|
@@ -68,6 +69,7 @@ function storiesTemplate({
|
|
|
68
69
|
}) {
|
|
69
70
|
const usageImport = uiPackageName ?? `./${kebabName}`;
|
|
70
71
|
const lines = [
|
|
72
|
+
`import type { Child } from "@takazudo/zfb/zudo-react";`,
|
|
71
73
|
`import type { StoryMeta, Story } from "@takazudo/zudo-sg/stories";`,
|
|
72
74
|
`import { ${pascalName}, type ${pascalName}Props } from "./${kebabName}";`,
|
|
73
75
|
``,
|
|
@@ -100,7 +102,7 @@ function storiesTemplate({
|
|
|
100
102
|
` defaultValue: "Content",`,
|
|
101
103
|
` },`,
|
|
102
104
|
` ],`,
|
|
103
|
-
` render: (args = {}) => (`,
|
|
105
|
+
` render: (args = {}): Child => (`,
|
|
104
106
|
` <${pascalName} variant={args.variant}>{args.children}</${pascalName}>`,
|
|
105
107
|
` ),`,
|
|
106
108
|
`};`
|
|
@@ -109,26 +111,43 @@ function storiesTemplate({
|
|
|
109
111
|
}
|
|
110
112
|
function testTemplate({ pascalName, kebabName }) {
|
|
111
113
|
const lines = [
|
|
112
|
-
|
|
114
|
+
`// @vitest-environment happy-dom`,
|
|
115
|
+
`import { renderToString } from "@takazudo/zfb/zudo-react/server";`,
|
|
116
|
+
`import { createIslandTest } from "@takazudo/zfb/zudo-react/testing";`,
|
|
113
117
|
`import { describe, expect, it } from "vitest";`,
|
|
114
|
-
`import { ${pascalName} } from "../${kebabName}";`,
|
|
118
|
+
`import { ${pascalName}, type ${pascalName}Props } from "../${kebabName}";`,
|
|
119
|
+
``,
|
|
120
|
+
`function ${pascalName}Fixture({ variant }: Pick<${pascalName}Props, "variant">) {`,
|
|
121
|
+
` return <${pascalName} variant={variant}>Content</${pascalName}>;`,
|
|
122
|
+
`}`,
|
|
115
123
|
``,
|
|
116
124
|
`describe("${pascalName}", () => {`,
|
|
117
125
|
` it("renders its children", () => {`,
|
|
118
|
-
`
|
|
119
|
-
` expect(screen.getByText("Content")).toBeInTheDocument();`,
|
|
126
|
+
` expect(renderToString(<${pascalName}>Content</${pascalName}>)).toContain("Content");`,
|
|
120
127
|
` });`,
|
|
121
128
|
``,
|
|
122
|
-
` it("defaults to the primary variant", () => {`,
|
|
123
|
-
`
|
|
124
|
-
`
|
|
125
|
-
`
|
|
129
|
+
` it("defaults to the primary variant", async () => {`,
|
|
130
|
+
` const test = createIslandTest(${pascalName}Fixture, {}, { document });`,
|
|
131
|
+
` try {`,
|
|
132
|
+
` test.hydrate();`,
|
|
133
|
+
` await test.flush();`,
|
|
134
|
+
` expect(test.host.querySelector("div")?.classList.contains("bg-accent")).toBe(true);`,
|
|
135
|
+
` } finally {`,
|
|
136
|
+
` test.dispose();`,
|
|
137
|
+
` expect(test.diagnostics).toEqual([]);`,
|
|
138
|
+
` }`,
|
|
126
139
|
` });`,
|
|
127
140
|
``,
|
|
128
|
-
` it("applies the secondary variant classes", () => {`,
|
|
129
|
-
`
|
|
130
|
-
`
|
|
131
|
-
`
|
|
141
|
+
` it("applies the secondary variant classes", async () => {`,
|
|
142
|
+
` const test = createIslandTest(${pascalName}Fixture, { variant: "secondary" }, { document });`,
|
|
143
|
+
` try {`,
|
|
144
|
+
` test.hydrate();`,
|
|
145
|
+
` await test.flush();`,
|
|
146
|
+
` expect(test.host.querySelector("div")?.classList.contains("border-border")).toBe(true);`,
|
|
147
|
+
` } finally {`,
|
|
148
|
+
` test.dispose();`,
|
|
149
|
+
` expect(test.diagnostics).toEqual([]);`,
|
|
150
|
+
` }`,
|
|
132
151
|
` });`,
|
|
133
152
|
`});`
|
|
134
153
|
];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { JSX } from "preact";
|
|
2
1
|
export interface CodePanelVariant {
|
|
3
2
|
exportName: string;
|
|
4
3
|
name: string;
|
|
@@ -13,13 +12,8 @@ export interface CodePanelProps {
|
|
|
13
12
|
/**
|
|
14
13
|
* Story slug, used to build stable variant-tab/tabpanel ids that match
|
|
15
14
|
* SSR output (mirrors `DetailWorkbench`'s `tabsId`). Falls back to
|
|
16
|
-
*
|
|
17
|
-
* not stable across an SSR/hydration boundary.
|
|
15
|
+
* a deterministic title-derived id when the host does not pass one.
|
|
18
16
|
*/
|
|
19
17
|
slug?: string;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
declare namespace CodePanel {
|
|
23
|
-
var displayName: string;
|
|
24
|
-
}
|
|
25
|
-
export default CodePanel;
|
|
19
|
+
export default function CodePanel({ storyTitle, variants, previewUrl, slug, }: CodePanelProps): import("@takazudo/zfb").Description;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "
|
|
3
|
-
import {
|
|
2
|
+
import { jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
3
|
+
import { computed, For, getScope, signal } from "@takazudo/zfb/zudo-react";
|
|
4
4
|
import SourceEditor from "./source-editor.js";
|
|
5
5
|
import CopyButton from "./copy-button.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createPreviewCssOwner } from "./css-injection.js";
|
|
7
7
|
import { handleTablistKeyDown } from "../shared/tablist-keyboard.js";
|
|
8
8
|
const STARTER_CSS = `/* Live CSS \u2014 edits inject into every preview above.
|
|
9
9
|
Try overriding a component utility, e.g.:
|
|
@@ -15,22 +15,30 @@ function CodePanel({
|
|
|
15
15
|
previewUrl,
|
|
16
16
|
slug
|
|
17
17
|
}) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const activeVariant = signal(variants[0]?.exportName ?? "");
|
|
19
|
+
const activeIndex = computed(() => Math.max(0, variants.findIndex((v) => v.exportName === activeVariant.value)));
|
|
20
|
+
const active = computed(() => variants[activeIndex.value]);
|
|
21
|
+
const activeItems = computed(() => active.value ? [active.value] : []);
|
|
22
|
+
let debounce;
|
|
23
|
+
let cssOwner;
|
|
24
|
+
getScope().onActivate(() => {
|
|
25
|
+
const owner = createPreviewCssOwner(previewUrl);
|
|
26
|
+
cssOwner = owner;
|
|
27
|
+
return () => {
|
|
28
|
+
window.clearTimeout(debounce);
|
|
29
|
+
owner.dispose();
|
|
30
|
+
if (cssOwner === owner) cssOwner = void 0;
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
const tabsId = `sg-code-panel-${slug ?? encodeURIComponent(storyTitle)}`;
|
|
27
34
|
const tabId = (index) => `${tabsId}-tab-${index}`;
|
|
28
35
|
const panelId = `${tabsId}-panel`;
|
|
29
36
|
function handleCssChange(css) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const owner = cssOwner;
|
|
38
|
+
if (!owner) return;
|
|
39
|
+
owner.set("live", css);
|
|
40
|
+
window.clearTimeout(debounce);
|
|
41
|
+
debounce = window.setTimeout(() => owner.apply(), 250);
|
|
34
42
|
}
|
|
35
43
|
function onTabKeyDown(e, index) {
|
|
36
44
|
handleTablistKeyDown(
|
|
@@ -39,7 +47,7 @@ function CodePanel({
|
|
|
39
47
|
variants.length,
|
|
40
48
|
(next) => {
|
|
41
49
|
const target = variants[next];
|
|
42
|
-
if (target)
|
|
50
|
+
if (target) activeVariant.value = target.exportName;
|
|
43
51
|
},
|
|
44
52
|
(next) => {
|
|
45
53
|
const tablist = e.currentTarget.parentElement;
|
|
@@ -50,17 +58,17 @@ function CodePanel({
|
|
|
50
58
|
return /* @__PURE__ */ jsxs("div", { class: "flex h-full flex-col gap-vsp-md p-hsp-md", children: [
|
|
51
59
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
52
60
|
/* @__PURE__ */ jsxs("div", { class: "flex items-center justify-between gap-hsp-sm", children: [
|
|
53
|
-
/* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-
|
|
54
|
-
|
|
61
|
+
/* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-sg-muted", children: "Source" }),
|
|
62
|
+
/* @__PURE__ */ jsx(For, { each: activeItems, by: (v) => v.exportName, children: (v) => /* @__PURE__ */ jsx(CopyButton, { text: v.value.source, label: "Copy source" }) })
|
|
55
63
|
] }),
|
|
56
64
|
variants.length > 1 && /* @__PURE__ */ jsx(
|
|
57
65
|
"div",
|
|
58
66
|
{
|
|
59
67
|
role: "tablist",
|
|
60
68
|
"aria-label": "Source variant",
|
|
61
|
-
class: "mt-vsp-2xs flex flex-wrap gap-hsp-
|
|
69
|
+
class: "mt-vsp-2xs flex flex-wrap gap-hsp-2xs",
|
|
62
70
|
children: variants.map((v, index) => {
|
|
63
|
-
const selected = index === activeIndex;
|
|
71
|
+
const selected = computed(() => index === activeIndex.value);
|
|
64
72
|
return /* @__PURE__ */ jsx(
|
|
65
73
|
"button",
|
|
66
74
|
{
|
|
@@ -69,18 +77,21 @@ function CodePanel({
|
|
|
69
77
|
role: "tab",
|
|
70
78
|
"aria-selected": selected,
|
|
71
79
|
"aria-controls": panelId,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
tabindex: computed(() => selected.value ? 0 : -1),
|
|
81
|
+
"on:click": () => {
|
|
82
|
+
activeVariant.value = v.exportName;
|
|
83
|
+
},
|
|
84
|
+
"on:keydown": (e) => onTabKeyDown(e, index),
|
|
85
|
+
class: computed(
|
|
86
|
+
() => "px-hsp-xs py-vsp-3xs text-xs rounded-sm border transition-colors " + (selected.value ? "border-sg-accent bg-sg-accent text-sg-on-accent" : "border-sg-border text-sg-muted hover:text-sg-fg")
|
|
87
|
+
),
|
|
76
88
|
children: v.name
|
|
77
|
-
}
|
|
78
|
-
v.exportName
|
|
89
|
+
}
|
|
79
90
|
);
|
|
80
91
|
})
|
|
81
92
|
}
|
|
82
93
|
),
|
|
83
|
-
|
|
94
|
+
variants.length > 0 && /* @__PURE__ */ jsx(
|
|
84
95
|
"div",
|
|
85
96
|
{
|
|
86
97
|
class: "sg-code-source mt-vsp-xs",
|
|
@@ -88,24 +99,23 @@ function CodePanel({
|
|
|
88
99
|
...variants.length > 1 ? {
|
|
89
100
|
id: panelId,
|
|
90
101
|
role: "tabpanel",
|
|
91
|
-
"aria-labelledby": tabId(activeIndex)
|
|
102
|
+
"aria-labelledby": computed(() => tabId(activeIndex.value))
|
|
92
103
|
} : {},
|
|
93
|
-
children: /* @__PURE__ */ jsx(
|
|
104
|
+
children: /* @__PURE__ */ jsx(For, { each: activeItems, by: (v) => v.exportName, children: (v) => /* @__PURE__ */ jsx(
|
|
94
105
|
SourceEditor,
|
|
95
106
|
{
|
|
96
|
-
value:
|
|
107
|
+
value: v.value.source,
|
|
97
108
|
language: "tsx",
|
|
98
109
|
editable: false,
|
|
99
|
-
label: `Source code for ${storyTitle}: ${
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
)
|
|
110
|
+
label: `Source code for ${storyTitle}: ${v.value.name}`
|
|
111
|
+
}
|
|
112
|
+
) })
|
|
103
113
|
}
|
|
104
114
|
)
|
|
105
115
|
] }),
|
|
106
116
|
/* @__PURE__ */ jsxs("div", { class: "sg-code-live-css flex min-h-0 flex-1 flex-col", "data-sg-code-region": "live-css", children: [
|
|
107
|
-
/* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-
|
|
108
|
-
/* @__PURE__ */ jsxs("p", { class: "mt-vsp-3xs text-xs text-
|
|
117
|
+
/* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-sg-muted", children: "Live CSS" }),
|
|
118
|
+
/* @__PURE__ */ jsxs("p", { class: "mt-vsp-3xs text-xs text-sg-muted", children: [
|
|
109
119
|
"Injected into the previews above. ",
|
|
110
120
|
storyTitle
|
|
111
121
|
] }),
|
|
@@ -122,7 +132,6 @@ function CodePanel({
|
|
|
122
132
|
] })
|
|
123
133
|
] });
|
|
124
134
|
}
|
|
125
|
-
CodePanel.displayName = "CodePanel";
|
|
126
135
|
export {
|
|
127
136
|
CodePanel as default
|
|
128
137
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { JSX } from "preact";
|
|
2
|
-
export declare function copyText(text: string): Promise<boolean>;
|
|
3
1
|
export interface CopyButtonProps {
|
|
4
2
|
/** Verbatim text placed on the clipboard. */
|
|
5
3
|
text: string;
|
|
@@ -8,8 +6,4 @@ export interface CopyButtonProps {
|
|
|
8
6
|
/** Extra classes for layout (the visual style is fixed). */
|
|
9
7
|
class?: string;
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
declare namespace CopyButton {
|
|
13
|
-
var displayName: string;
|
|
14
|
-
}
|
|
15
|
-
export default CopyButton;
|
|
9
|
+
export default function CopyButton({ text, label, class: extraClass, }: CopyButtonProps): import("@takazudo/zfb").Description;
|
|
@@ -1,51 +1,36 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Fragment, jsx, jsxs } from "
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
|
|
7
|
-
await navigator.clipboard.writeText(text);
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
} catch {
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
const ta = document.createElement("textarea");
|
|
14
|
-
ta.value = text;
|
|
15
|
-
ta.style.position = "fixed";
|
|
16
|
-
ta.style.opacity = "0";
|
|
17
|
-
document.body.appendChild(ta);
|
|
18
|
-
ta.select();
|
|
19
|
-
const ok = document.execCommand("copy");
|
|
20
|
-
document.body.removeChild(ta);
|
|
21
|
-
return ok;
|
|
22
|
-
} catch {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
2
|
+
import { Fragment, jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
3
|
+
import { computed, getScope, signal, Show } from "@takazudo/zfb/zudo-react";
|
|
4
|
+
import { copyText } from "./copy-text.js";
|
|
26
5
|
function CopyButton({
|
|
27
6
|
text,
|
|
28
7
|
label = "Copy",
|
|
29
8
|
class: extraClass = ""
|
|
30
9
|
}) {
|
|
31
|
-
const
|
|
10
|
+
const copied = signal(false);
|
|
11
|
+
const scope = getScope();
|
|
12
|
+
let timer;
|
|
13
|
+
scope.onActivate(() => () => window.clearTimeout(timer));
|
|
32
14
|
async function handleClick() {
|
|
33
15
|
const ok = await copyText(text);
|
|
34
|
-
if (!ok) return;
|
|
35
|
-
|
|
36
|
-
window.
|
|
16
|
+
if (!ok || scope.abortSignal.aborted) return;
|
|
17
|
+
copied.value = true;
|
|
18
|
+
window.clearTimeout(timer);
|
|
19
|
+
timer = window.setTimeout(() => {
|
|
20
|
+
copied.value = false;
|
|
21
|
+
}, 1400);
|
|
37
22
|
}
|
|
38
23
|
return /* @__PURE__ */ jsx(
|
|
39
24
|
"button",
|
|
40
25
|
{
|
|
41
26
|
type: "button",
|
|
42
27
|
class: `sg-copy-btn ${extraClass}`,
|
|
43
|
-
|
|
44
|
-
"aria-label": copied ? "Copied" : label,
|
|
45
|
-
title: copied ? "Copied" : label,
|
|
46
|
-
"data-copied": copied ? "true" : void 0,
|
|
47
|
-
children: copied
|
|
48
|
-
/* @__PURE__ */
|
|
28
|
+
"on:click": () => void handleClick(),
|
|
29
|
+
"aria-label": computed(() => copied.value ? "Copied" : label),
|
|
30
|
+
title: computed(() => copied.value ? "Copied" : label),
|
|
31
|
+
"data-copied": computed(() => copied.value ? "true" : void 0),
|
|
32
|
+
children: /* @__PURE__ */ jsx(Show, { when: copied, fallback: () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
+
/* @__PURE__ */ jsxs(
|
|
49
34
|
"svg",
|
|
50
35
|
{
|
|
51
36
|
width: "14",
|
|
@@ -53,16 +38,19 @@ function CopyButton({
|
|
|
53
38
|
viewBox: "0 0 24 24",
|
|
54
39
|
fill: "none",
|
|
55
40
|
stroke: "currentColor",
|
|
56
|
-
"stroke-width": "2
|
|
41
|
+
"stroke-width": "2",
|
|
57
42
|
"stroke-linecap": "round",
|
|
58
43
|
"stroke-linejoin": "round",
|
|
59
44
|
"aria-hidden": "true",
|
|
60
|
-
children:
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
47
|
+
/* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
48
|
+
]
|
|
61
49
|
}
|
|
62
50
|
),
|
|
63
|
-
/* @__PURE__ */ jsx("span", { children: "
|
|
64
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
65
|
-
/* @__PURE__ */
|
|
51
|
+
/* @__PURE__ */ jsx("span", { children: "Copy" })
|
|
52
|
+
] }), children: () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
/* @__PURE__ */ jsx(
|
|
66
54
|
"svg",
|
|
67
55
|
{
|
|
68
56
|
width: "14",
|
|
@@ -70,23 +58,18 @@ function CopyButton({
|
|
|
70
58
|
viewBox: "0 0 24 24",
|
|
71
59
|
fill: "none",
|
|
72
60
|
stroke: "currentColor",
|
|
73
|
-
"stroke-width": "2",
|
|
61
|
+
"stroke-width": "2.5",
|
|
74
62
|
"stroke-linecap": "round",
|
|
75
63
|
"stroke-linejoin": "round",
|
|
76
64
|
"aria-hidden": "true",
|
|
77
|
-
children:
|
|
78
|
-
/* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
79
|
-
/* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
80
|
-
]
|
|
65
|
+
children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
81
66
|
}
|
|
82
67
|
),
|
|
83
|
-
/* @__PURE__ */ jsx("span", { children: "
|
|
84
|
-
] })
|
|
68
|
+
/* @__PURE__ */ jsx("span", { children: "Copied" })
|
|
69
|
+
] }) })
|
|
85
70
|
}
|
|
86
71
|
);
|
|
87
72
|
}
|
|
88
|
-
CopyButton.displayName = "CopyButton";
|
|
89
73
|
export {
|
|
90
|
-
copyText,
|
|
91
74
|
CopyButton as default
|
|
92
75
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyText(text: string): Promise<boolean>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
async function copyText(text) {
|
|
2
|
+
try {
|
|
3
|
+
if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
|
|
4
|
+
await navigator.clipboard.writeText(text);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
} catch {
|
|
8
|
+
}
|
|
9
|
+
let ta;
|
|
10
|
+
try {
|
|
11
|
+
ta = document.createElement("textarea");
|
|
12
|
+
ta.value = text;
|
|
13
|
+
ta.style.position = "fixed";
|
|
14
|
+
ta.style.opacity = "0";
|
|
15
|
+
document.body.appendChild(ta);
|
|
16
|
+
ta.select();
|
|
17
|
+
return document.execCommand("copy");
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
} finally {
|
|
21
|
+
ta?.remove();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
copyText
|
|
26
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
1
|
+
/** VariantFrame owns readiness; registering alone never styles an about:blank document. */
|
|
2
|
+
export declare function registerCssPreview(iframe: HTMLIFrameElement): () => void;
|
|
3
|
+
/** Call only after VariantFrame accepts ready; always reads the latest retained buffers. */
|
|
4
|
+
export declare function replayCssToPreview(iframe: HTMLIFrameElement): void;
|
|
5
|
+
/** Own a code panel's buffers. Retention is synchronous; only apply() should be debounced. */
|
|
6
|
+
export declare function createPreviewCssOwner(previewUrl?: string): {
|
|
7
|
+
set(cssKey: string, css: string): void;
|
|
8
|
+
apply(): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
};
|
|
11
|
+
/** Selector-compatible direct injection, with current-value replay on later loads. */
|
|
6
12
|
export declare function injectCssToAllPreviews(cssKey: string, css: string, previewUrl?: string): void;
|