@takazudo/zudo-sg 0.4.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +59 -61
  3. package/dist/catalog/catalog-thumb.d.ts +1 -6
  4. package/dist/catalog/catalog-thumb.js +1 -2
  5. package/dist/catalog/component-thumb.d.ts +1 -6
  6. package/dist/catalog/component-thumb.js +8 -7
  7. package/dist/catalog/descriptor-thumb.d.ts +1 -6
  8. package/dist/catalog/descriptor-thumb.js +1 -2
  9. package/dist/chrome/_styleguide-layout.d.ts +8 -9
  10. package/dist/chrome/_styleguide-layout.js +3 -6
  11. package/dist/chrome/panel-scripts.d.ts +1 -3
  12. package/dist/chrome/panel-scripts.js +3 -3
  13. package/dist/cli/scaffold/component-scaffold.js +35 -16
  14. package/dist/code-panel/code-panel.d.ts +2 -8
  15. package/dist/code-panel/code-panel.js +34 -35
  16. package/dist/code-panel/copy-button.d.ts +1 -7
  17. package/dist/code-panel/copy-button.js +31 -48
  18. package/dist/code-panel/copy-text.d.ts +1 -0
  19. package/dist/code-panel/copy-text.js +26 -0
  20. package/dist/code-panel/editor-setup.d.ts +3 -0
  21. package/dist/code-panel/editor-setup.js +15 -3
  22. package/dist/code-panel/editor-theme.d.ts +2 -0
  23. package/dist/code-panel/editor-theme.js +54 -0
  24. package/dist/code-panel/source-editor.d.ts +10 -2
  25. package/dist/code-panel/source-editor.js +20 -19
  26. package/dist/config/index.d.ts +2 -0
  27. package/dist/config/index.js +6 -1
  28. package/dist/config/wind.d.ts +265 -0
  29. package/dist/config/wind.js +133 -0
  30. package/dist/plugins/preview-css.d.ts +9 -7
  31. package/dist/plugins/preview-css.js +58 -37
  32. package/dist/preview/detail-workbench.d.ts +2 -6
  33. package/dist/preview/detail-workbench.js +100 -65
  34. package/dist/preview/index.d.ts +4 -2
  35. package/dist/preview/index.js +7 -7
  36. package/dist/preview/preview-app.d.ts +2 -5
  37. package/dist/preview/preview-app.js +76 -46
  38. package/dist/preview/variant-frame-config.d.ts +47 -0
  39. package/dist/preview/variant-frame-config.js +50 -0
  40. package/dist/preview/variant-frame.d.ts +9 -53
  41. package/dist/preview/variant-frame.js +158 -149
  42. package/dist/preview-css/compile.d.ts +15 -29
  43. package/dist/preview-css/compile.js +183 -31
  44. package/dist/search/catalog-filter.d.ts +2 -6
  45. package/dist/search/catalog-filter.js +50 -42
  46. package/dist/stories/types.d.ts +5 -3
  47. package/dist/token-dashboard/create-token-dashboards.d.ts +3 -5
  48. package/dist/token-dashboard/create-token-dashboards.js +14 -44
  49. package/dist/token-dashboard/dashboard-inventory.d.ts +1 -1
  50. package/dist/token-dashboard/token-dashboard-adapter.d.ts +2 -0
  51. package/dist/token-dashboard/token-dashboard-adapter.js +9 -0
  52. package/dist/token-dashboard/token-dashboard-mount.d.ts +6 -0
  53. package/dist/token-dashboard/token-dashboard-mount.js +33 -0
  54. package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +1 -6
  55. package/dist/token-tweak/preview-token-panel-bootstrap.js +4 -2
  56. package/dist/token-tweak/preview-tokens-button.d.ts +1 -5
  57. package/dist/token-tweak/preview-tokens-button.js +5 -4
  58. package/dist/wind.json +119 -0
  59. package/package.json +16 -19
  60. package/routes-src/_chrome.tsx +1 -3
  61. package/routes-src/_preview-app.tsx +3 -8
  62. package/routes-src/components-index.tsx +5 -10
  63. package/routes-src/components-preview.tsx +3 -9
  64. package/routes-src/components-slug.tsx +21 -24
  65. package/routes-src/tokens.tsx +4 -9
  66. package/styles.css +36 -11
  67. package/dist/safelist.css +0 -2
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "preact/jsx-runtime";
3
- import { useId, useRef, useState } from "preact/hooks";
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
6
  import { injectCssToAllPreviews } from "./css-injection.js";
@@ -15,20 +15,18 @@ function CodePanel({
15
15
  previewUrl,
16
16
  slug
17
17
  }) {
18
- const [activeVariant, setActiveVariant] = useState(
19
- variants[0]?.exportName ?? ""
20
- );
21
- const debounceRef = useRef(void 0);
22
- const reactId = useId();
23
- const tabsId = `sg-code-panel-${slug ?? reactId}`;
24
- const foundIndex = variants.findIndex((v) => v.exportName === activeVariant);
25
- const activeIndex = foundIndex >= 0 ? foundIndex : 0;
26
- const active = variants[activeIndex];
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
+ getScope().onActivate(() => () => window.clearTimeout(debounce));
24
+ const tabsId = `sg-code-panel-${slug ?? encodeURIComponent(storyTitle)}`;
27
25
  const tabId = (index) => `${tabsId}-tab-${index}`;
28
26
  const panelId = `${tabsId}-panel`;
29
27
  function handleCssChange(css) {
30
- window.clearTimeout(debounceRef.current);
31
- debounceRef.current = window.setTimeout(() => {
28
+ window.clearTimeout(debounce);
29
+ debounce = window.setTimeout(() => {
32
30
  injectCssToAllPreviews("live", css, previewUrl);
33
31
  }, 250);
34
32
  }
@@ -39,7 +37,7 @@ function CodePanel({
39
37
  variants.length,
40
38
  (next) => {
41
39
  const target = variants[next];
42
- if (target) setActiveVariant(target.exportName);
40
+ if (target) activeVariant.value = target.exportName;
43
41
  },
44
42
  (next) => {
45
43
  const tablist = e.currentTarget.parentElement;
@@ -50,17 +48,17 @@ function CodePanel({
50
48
  return /* @__PURE__ */ jsxs("div", { class: "flex h-full flex-col gap-vsp-md p-hsp-md", children: [
51
49
  /* @__PURE__ */ jsxs("div", { children: [
52
50
  /* @__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-[color:var(--sg-muted)]", children: "Source" }),
54
- active && /* @__PURE__ */ jsx(CopyButton, { text: active.source, label: "Copy source" })
51
+ /* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-sg-muted", children: "Source" }),
52
+ /* @__PURE__ */ jsx(For, { each: activeItems, by: (v) => v.exportName, children: (v) => /* @__PURE__ */ jsx(CopyButton, { text: v.value.source, label: "Copy source" }) })
55
53
  ] }),
56
54
  variants.length > 1 && /* @__PURE__ */ jsx(
57
55
  "div",
58
56
  {
59
57
  role: "tablist",
60
58
  "aria-label": "Source variant",
61
- class: "mt-vsp-2xs flex flex-wrap gap-hsp-3xs",
59
+ class: "mt-vsp-2xs flex flex-wrap gap-hsp-2xs",
62
60
  children: variants.map((v, index) => {
63
- const selected = index === activeIndex;
61
+ const selected = computed(() => index === activeIndex.value);
64
62
  return /* @__PURE__ */ jsx(
65
63
  "button",
66
64
  {
@@ -69,18 +67,21 @@ function CodePanel({
69
67
  role: "tab",
70
68
  "aria-selected": selected,
71
69
  "aria-controls": panelId,
72
- tabIndex: selected ? 0 : -1,
73
- onClick: () => setActiveVariant(v.exportName),
74
- onKeyDown: (e) => onTabKeyDown(e, index),
75
- class: "px-hsp-xs py-vsp-3xs text-xs rounded-sm border transition-colors " + (selected ? "border-[color:var(--sg-accent)] bg-[var(--sg-accent)] text-[color:var(--sg-on-accent)]" : "border-[color:var(--sg-border)] text-[color:var(--sg-muted)] hover:text-[color:var(--sg-fg)]"),
70
+ tabindex: computed(() => selected.value ? 0 : -1),
71
+ "on:click": () => {
72
+ activeVariant.value = v.exportName;
73
+ },
74
+ "on:keydown": (e) => onTabKeyDown(e, index),
75
+ class: computed(
76
+ () => "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")
77
+ ),
76
78
  children: v.name
77
- },
78
- v.exportName
79
+ }
79
80
  );
80
81
  })
81
82
  }
82
83
  ),
83
- active && /* @__PURE__ */ jsx(
84
+ variants.length > 0 && /* @__PURE__ */ jsx(
84
85
  "div",
85
86
  {
86
87
  class: "sg-code-source mt-vsp-xs",
@@ -88,24 +89,23 @@ function CodePanel({
88
89
  ...variants.length > 1 ? {
89
90
  id: panelId,
90
91
  role: "tabpanel",
91
- "aria-labelledby": tabId(activeIndex)
92
+ "aria-labelledby": computed(() => tabId(activeIndex.value))
92
93
  } : {},
93
- children: /* @__PURE__ */ jsx(
94
+ children: /* @__PURE__ */ jsx(For, { each: activeItems, by: (v) => v.exportName, children: (v) => /* @__PURE__ */ jsx(
94
95
  SourceEditor,
95
96
  {
96
- value: active.source,
97
+ value: v.value.source,
97
98
  language: "tsx",
98
99
  editable: false,
99
- label: `Source code for ${storyTitle}: ${active.name}`
100
- },
101
- active.exportName
102
- )
100
+ label: `Source code for ${storyTitle}: ${v.value.name}`
101
+ }
102
+ ) })
103
103
  }
104
104
  )
105
105
  ] }),
106
106
  /* @__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-[color:var(--sg-muted)]", children: "Live CSS" }),
108
- /* @__PURE__ */ jsxs("p", { class: "mt-vsp-3xs text-xs text-[color:var(--sg-muted)]", children: [
107
+ /* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-sg-muted", children: "Live CSS" }),
108
+ /* @__PURE__ */ jsxs("p", { class: "mt-vsp-3xs text-xs text-sg-muted", children: [
109
109
  "Injected into the previews above. ",
110
110
  storyTitle
111
111
  ] }),
@@ -122,7 +122,6 @@ function CodePanel({
122
122
  ] })
123
123
  ] });
124
124
  }
125
- CodePanel.displayName = "CodePanel";
126
125
  export {
127
126
  CodePanel as default
128
127
  };
@@ -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
- declare function CopyButton({ text, label, class: extraClass, }: CopyButtonProps): JSX.Element;
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 "preact/jsx-runtime";
3
- import { useState } from "preact/hooks";
4
- async function copyText(text) {
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 [copied, setCopied] = useState(false);
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
- setCopied(true);
36
- window.setTimeout(() => setCopied(false), 1400);
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
- onClick: () => void handleClick(),
44
- "aria-label": copied ? "Copied" : label,
45
- title: copied ? "Copied" : label,
46
- "data-copied": copied ? "true" : void 0,
47
- children: copied ? /* @__PURE__ */ jsxs(Fragment, { children: [
48
- /* @__PURE__ */ jsx(
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.5",
41
+ "stroke-width": "2",
57
42
  "stroke-linecap": "round",
58
43
  "stroke-linejoin": "round",
59
44
  "aria-hidden": "true",
60
- children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
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: "Copied" })
64
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
65
- /* @__PURE__ */ jsxs(
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: "Copy" })
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,4 +1,5 @@
1
1
  import { EditorView } from "@codemirror/view";
2
+ import { type Extension } from "@codemirror/state";
2
3
  export interface CreateEditorOptions {
3
4
  /** "css" enables the CSS language (live-injection buffer); else TS/JSX. */
4
5
  language: "css" | "tsx";
@@ -8,5 +9,7 @@ export interface CreateEditorOptions {
8
9
  label?: string;
9
10
  /** Fired on every document change with the full text. */
10
11
  onChange?: (value: string) => void;
12
+ /** Host extensions appended after the engine's; they win over its `Prec.low` theme. */
13
+ extensions?: Extension[];
11
14
  }
12
15
  export declare function createEditorView(doc: string, parent: HTMLElement, opts: CreateEditorOptions): EditorView;
@@ -1,9 +1,15 @@
1
- import { EditorView, lineNumbers, keymap } from "@codemirror/view";
1
+ import {
2
+ EditorView,
3
+ highlightActiveLine,
4
+ highlightActiveLineGutter,
5
+ lineNumbers,
6
+ keymap
7
+ } from "@codemirror/view";
2
8
  import { EditorState } from "@codemirror/state";
3
9
  import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
4
10
  import { javascript } from "@codemirror/lang-javascript";
5
11
  import { css } from "@codemirror/lang-css";
6
- import { oneDark } from "@codemirror/theme-one-dark";
12
+ import { engineTheme } from "./editor-theme.js";
7
13
  function createEditorView(doc, parent, opts) {
8
14
  const langExtension = opts.language === "css" ? css() : javascript({ jsx: true, typescript: true });
9
15
  const extensions = [
@@ -11,11 +17,14 @@ function createEditorView(doc, parent, opts) {
11
17
  history(),
12
18
  keymap.of([...defaultKeymap, ...historyKeymap]),
13
19
  langExtension,
14
- oneDark,
20
+ engineTheme,
15
21
  EditorView.lineWrapping,
16
22
  EditorState.readOnly.of(!opts.editable),
17
23
  EditorView.editable.of(opts.editable)
18
24
  ];
25
+ if (opts.editable) {
26
+ extensions.push(highlightActiveLine(), highlightActiveLineGutter());
27
+ }
19
28
  if (opts.label) {
20
29
  extensions.push(EditorView.contentAttributes.of({ "aria-label": opts.label }));
21
30
  }
@@ -26,6 +35,9 @@ function createEditorView(doc, parent, opts) {
26
35
  })
27
36
  );
28
37
  }
38
+ if (opts.extensions) {
39
+ extensions.push(...opts.extensions);
40
+ }
29
41
  return new EditorView({
30
42
  state: EditorState.create({ doc, extensions }),
31
43
  parent
@@ -0,0 +1,2 @@
1
+ import { type Extension } from "@codemirror/state";
2
+ export declare const engineTheme: Extension;
@@ -0,0 +1,54 @@
1
+ import { Prec } from "@codemirror/state";
2
+ import { EditorView } from "@codemirror/view";
3
+ import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
4
+ import { tags as t } from "@lezer/highlight";
5
+ const code = (name) => `var(--sg-code-${name})`;
6
+ const selectionBg = { backgroundColor: code("selection-bg") };
7
+ const engineEditorTheme = EditorView.theme({
8
+ "&": {
9
+ color: code("fg"),
10
+ backgroundColor: code("bg")
11
+ },
12
+ ".cm-content": {
13
+ caretColor: code("cursor")
14
+ },
15
+ ".cm-cursor, .cm-dropCursor": {
16
+ borderLeftColor: code("cursor")
17
+ },
18
+ "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": selectionBg,
19
+ ".cm-selectionBackground": selectionBg,
20
+ ".cm-content ::selection": selectionBg,
21
+ ".cm-gutters": {
22
+ color: code("gutter-fg"),
23
+ backgroundColor: code("gutter-bg"),
24
+ border: "none"
25
+ },
26
+ ".cm-activeLine": {
27
+ backgroundColor: code("active-line-bg")
28
+ },
29
+ ".cm-activeLineGutter": {
30
+ backgroundColor: code("active-line-bg")
31
+ }
32
+ });
33
+ const engineHighlightStyle = HighlightStyle.define([
34
+ { tag: t.keyword, color: code("keyword") },
35
+ { tag: [t.string, t.special(t.string), t.regexp, t.escape], color: code("string") },
36
+ { tag: [t.number, t.bool, t.null, t.atom, t.unit, t.color], color: code("number") },
37
+ { tag: t.comment, color: code("comment"), fontStyle: "italic" },
38
+ {
39
+ tag: [t.function(t.variableName), t.function(t.propertyName), t.macroName],
40
+ color: code("function")
41
+ },
42
+ { tag: [t.propertyName, t.definition(t.propertyName)], color: code("property") },
43
+ { tag: [t.typeName, t.className, t.namespace], color: code("type") },
44
+ { tag: t.tagName, color: code("tag") },
45
+ { tag: t.attributeName, color: code("attribute") },
46
+ { tag: t.invalid, color: code("keyword") }
47
+ ]);
48
+ const engineTheme = [
49
+ Prec.low(engineEditorTheme),
50
+ Prec.low(syntaxHighlighting(engineHighlightStyle))
51
+ ];
52
+ export {
53
+ engineTheme
54
+ };
@@ -1,4 +1,4 @@
1
- import type { JSX } from "preact";
1
+ import type { Extension } from "@codemirror/state";
2
2
  export interface SourceEditorProps {
3
3
  value: string;
4
4
  language: "css" | "tsx";
@@ -6,5 +6,13 @@ export interface SourceEditorProps {
6
6
  /** Accessible name for the editor (and its <pre> fallback before it mounts). */
7
7
  label?: string;
8
8
  onChange?: (value: string) => void;
9
+ /**
10
+ * Extra CodeMirror extensions (e.g. a host theme), applied after — and so
11
+ * overriding — the engine's own. For direct `SourceEditor` use only: they are
12
+ * not serializable across the `CodePanel` island boundary, so `CodePanel`
13
+ * does not accept them. Initial configuration only, like `value` — change
14
+ * them by remounting with a new `key`.
15
+ */
16
+ extensions?: Extension[];
9
17
  }
10
- export default function SourceEditor({ value, language, editable, label, onChange, }: SourceEditorProps): JSX.Element;
18
+ export default function SourceEditor({ value, language, editable, label, onChange, extensions, }: SourceEditorProps): import("@takazudo/zfb").Description;
@@ -1,46 +1,47 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "preact/jsx-runtime";
3
- import { useEffect, useRef, useState } from "preact/hooks";
2
+ import { jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
3
+ import { computed, getScope, signal, Show } from "@takazudo/zfb/zudo-react";
4
4
  function SourceEditor({
5
5
  value,
6
6
  language,
7
7
  editable = false,
8
8
  label,
9
- onChange
9
+ onChange,
10
+ extensions
10
11
  }) {
11
- const containerRef = useRef(null);
12
- const viewRef = useRef(null);
13
- const [loaded, setLoaded] = useState(false);
14
- const onChangeRef = useRef(onChange);
15
- onChangeRef.current = onChange;
16
- useEffect(() => {
12
+ const containerRef = { current: null };
13
+ let view = null;
14
+ const loaded = signal(false);
15
+ const scope = getScope();
16
+ scope.onActivate(() => {
17
17
  let disposed = false;
18
18
  void import("./editor-setup.js").then(({ createEditorView }) => {
19
19
  if (disposed || !containerRef.current) return;
20
- viewRef.current = createEditorView(value, containerRef.current, {
20
+ view = createEditorView(value, containerRef.current, {
21
21
  language,
22
22
  editable,
23
23
  label,
24
- onChange: (v) => onChangeRef.current?.(v)
24
+ onChange: (v) => onChange?.(v),
25
+ extensions
25
26
  });
26
- setLoaded(true);
27
+ loaded.value = true;
27
28
  });
28
29
  return () => {
29
30
  disposed = true;
30
- viewRef.current?.destroy();
31
- viewRef.current = null;
31
+ view?.destroy();
32
+ view = null;
32
33
  };
33
- }, []);
34
+ });
34
35
  return /* @__PURE__ */ jsxs("div", { class: "relative text-small", children: [
35
- !loaded && /* @__PURE__ */ jsx(
36
+ /* @__PURE__ */ jsx(Show, { when: computed(() => !loaded.value), children: () => /* @__PURE__ */ jsx(
36
37
  "pre",
37
38
  {
38
- class: "m-0 overflow-auto rounded-md bg-[var(--sg-surface-2)] p-hsp-sm text-xs text-[color:var(--sg-muted)]",
39
+ class: "m-0 overflow-auto rounded-md bg-sg-surface-2 p-hsp-sm text-xs text-sg-muted",
39
40
  "aria-label": label,
40
41
  children: /* @__PURE__ */ jsx("code", { children: value })
41
42
  }
42
- ),
43
- /* @__PURE__ */ jsx("div", { ref: containerRef, class: loaded ? "" : "hidden" })
43
+ ) }),
44
+ /* @__PURE__ */ jsx("div", { ref: containerRef, class: computed(() => loaded.value ? "" : "hidden") })
44
45
  ] });
45
46
  }
46
47
  export {
@@ -154,7 +154,9 @@ export declare function zudoSg(options: ZudoSgComposeOptions): ZudoSgFragment;
154
154
  export declare function withZudoSg<P extends {
155
155
  plugins?: ReadonlyArray<unknown>;
156
156
  collections?: ReadonlyArray<unknown>;
157
+ wind?: Record<string, unknown>;
157
158
  }>(presetFragment: P, options: ZudoSgComposeOptions): Omit<P, "plugins" | "collections"> & {
158
159
  plugins: Array<NonNullable<P["plugins"]>[number] | ZudoSgPluginDescriptor>;
159
160
  collections: Array<NonNullable<P["collections"]>[number] | ZudoSgCollection>;
161
+ wind: Record<string, unknown>;
160
162
  };
@@ -1,3 +1,4 @@
1
+ import { engineWindDefaults, mergeWind } from "./wind.js";
1
2
  import {
2
3
  COMPONENT_DOCS_COLLECTION,
3
4
  componentDocsCollectionName,
@@ -147,7 +148,7 @@ function zudoSg(options) {
147
148
  },
148
149
  {
149
150
  name: PREVIEW_CSS_PLUGIN_NAME,
150
- options: definedOnly({ previewStyles: options.previewStyles, previewCssUrl })
151
+ options: definedOnly({ previewStyles: options.previewStyles, previewCssUrl, componentsRoots: roots })
151
152
  },
152
153
  {
153
154
  name: ZDTP_APPLY_PROXY_PLUGIN_NAME,
@@ -163,6 +164,9 @@ function zudoSg(options) {
163
164
  }
164
165
  function withZudoSg(presetFragment, options) {
165
166
  const sg = zudoSg(options);
167
+ const wind = mergeWind(engineWindDefaults, presetFragment.wind ?? {});
168
+ wind.manifests = { ...wind.manifests ?? {}, "zudo-sg": { path: "@takazudo/zudo-sg/wind.json" } };
169
+ sg.plugins.find((p) => p.name === PREVIEW_CSS_PLUGIN_NAME).options.wind = wind;
166
170
  const presetPlugins = [...presetFragment.plugins ?? []];
167
171
  const registryMode = descriptorModuleOf(options.registry) === null ? "module" : "descriptor";
168
172
  const tokensEnabled = isTokensRouteEnabled({
@@ -182,6 +186,7 @@ function withZudoSg(presetFragment, options) {
182
186
  const pluginsWithTrigger = triggerEnabled ? pluginsWithChrome.map(withHeaderTokenTrigger) : pluginsWithChrome;
183
187
  return {
184
188
  ...presetFragment,
189
+ wind,
185
190
  plugins: [...pluginsWithTrigger, ...sg.plugins],
186
191
  collections: [...presetFragment.collections ?? [], ...sg.collections]
187
192
  };