docblocks-react-ui 0.0.0-stage → 0.1.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 +100 -0
- package/LICENSE +21 -0
- package/README.md +585 -2
- package/dist/Editor-CiJY5R4v.mjs +26587 -0
- package/dist/Editor-DT7RkRXf.d.mts +32 -0
- package/dist/LoaderCircle-AGVFE4IP.mjs +19 -0
- package/dist/Skeleton-D922Ths5.mjs +13 -0
- package/dist/constants-D4FTL0ph.mjs +81 -0
- package/dist/fonts/OFL.txt +162 -0
- package/dist/fonts/inter-300-c.woff2 +0 -0
- package/dist/fonts/inter-300-l.woff2 +0 -0
- package/dist/fonts/inter-300i-c.woff2 +0 -0
- package/dist/fonts/inter-300i-l.woff2 +0 -0
- package/dist/fonts/inter-400-c.woff2 +0 -0
- package/dist/fonts/inter-400-l.woff2 +0 -0
- package/dist/fonts/inter-400i-c.woff2 +0 -0
- package/dist/fonts/inter-400i-l.woff2 +0 -0
- package/dist/fonts/inter-600-c.woff2 +0 -0
- package/dist/fonts/inter-600-l.woff2 +0 -0
- package/dist/fonts/inter-600i-c.woff2 +0 -0
- package/dist/fonts/inter-600i-l.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-300-c.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-300-l.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-300i-c.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-300i-l.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-400-c.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-400-l.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-400i-c.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-400i-l.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-600-c.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-600-l.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-600i-c.woff2 +0 -0
- package/dist/fonts/jetbrains-mono-600i-l.woff2 +0 -0
- package/dist/fonts/lora-400-c.woff2 +0 -0
- package/dist/fonts/lora-400-l.woff2 +0 -0
- package/dist/fonts/lora-400i-c.woff2 +0 -0
- package/dist/fonts/lora-400i-l.woff2 +0 -0
- package/dist/fonts/lora-600-c.woff2 +0 -0
- package/dist/fonts/lora-600-l.woff2 +0 -0
- package/dist/fonts/lora-600i-c.woff2 +0 -0
- package/dist/fonts/lora-600i-l.woff2 +0 -0
- package/dist/fonts/lora-700-c.woff2 +0 -0
- package/dist/fonts/lora-700-l.woff2 +0 -0
- package/dist/fonts/lora-700i-c.woff2 +0 -0
- package/dist/fonts/lora-700i-l.woff2 +0 -0
- package/dist/fonts/open-sans-300-c.woff2 +0 -0
- package/dist/fonts/open-sans-300-l.woff2 +0 -0
- package/dist/fonts/open-sans-300i-c.woff2 +0 -0
- package/dist/fonts/open-sans-300i-l.woff2 +0 -0
- package/dist/fonts/open-sans-400-c.woff2 +0 -0
- package/dist/fonts/open-sans-400-l.woff2 +0 -0
- package/dist/fonts/open-sans-400i-c.woff2 +0 -0
- package/dist/fonts/open-sans-400i-l.woff2 +0 -0
- package/dist/fonts/open-sans-600-c.woff2 +0 -0
- package/dist/fonts/open-sans-600-l.woff2 +0 -0
- package/dist/fonts/open-sans-600i-c.woff2 +0 -0
- package/dist/fonts/open-sans-600i-l.woff2 +0 -0
- package/dist/fonts/pt-sans-400-c.woff2 +0 -0
- package/dist/fonts/pt-sans-400-l.woff2 +0 -0
- package/dist/fonts/pt-sans-400i-c.woff2 +0 -0
- package/dist/fonts/pt-sans-400i-l.woff2 +0 -0
- package/dist/fonts/pt-sans-700-c.woff2 +0 -0
- package/dist/fonts/pt-sans-700-l.woff2 +0 -0
- package/dist/fonts/pt-sans-700i-c.woff2 +0 -0
- package/dist/fonts/pt-sans-700i-l.woff2 +0 -0
- package/dist/fonts/pt-serif-400-c.woff2 +0 -0
- package/dist/fonts/pt-serif-400-l.woff2 +0 -0
- package/dist/fonts/pt-serif-400i-c.woff2 +0 -0
- package/dist/fonts/pt-serif-400i-l.woff2 +0 -0
- package/dist/fonts/pt-serif-700-c.woff2 +0 -0
- package/dist/fonts/pt-serif-700-l.woff2 +0 -0
- package/dist/fonts/pt-serif-700i-c.woff2 +0 -0
- package/dist/fonts/pt-serif-700i-l.woff2 +0 -0
- package/dist/index-D6_ysSmQ.d.mts +1075 -0
- package/dist/index-YJcgf8Hh.d.mts +39 -0
- package/dist/index.d.mts +388 -0
- package/dist/index.mjs +641 -0
- package/dist/mermaid/index.d.mts +10 -0
- package/dist/mermaid/index.mjs +252 -0
- package/dist/motion/index.d.mts +8 -0
- package/dist/motion/index.mjs +1009 -0
- package/dist/pdf/index.d.mts +5 -0
- package/dist/pdf/index.mjs +164 -0
- package/dist/pdf/jbig2.wasm +0 -0
- package/dist/pdf/jbig2_nowasm_fallback.js +15 -0
- package/dist/pdf/pdf.worker.min.mjs +28 -0
- package/dist/styles.css +4562 -0
- package/package.json +99 -4
- package/theme.css +128 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Ht as AlertDescription, Nt as Eye, Pt as CodeXml, Ut as AlertTitle, Vt as Alert, c as CodeHeader, h as textOf, hn as INLINE_CODE_CLASS, k as useEditorContext, m as TextBlock, s as childrenSlot, z as SegmentSelector } from "../Editor-CiJY5R4v.mjs";
|
|
2
|
+
import { n as TriangleAlert } from "../constants-D4FTL0ph.mjs";
|
|
3
|
+
import { t as LoaderCircle } from "../LoaderCircle-AGVFE4IP.mjs";
|
|
4
|
+
import { t as Skeleton } from "../Skeleton-D922Ths5.mjs";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import mermaid from "mermaid";
|
|
8
|
+
//#region src/mermaid/mermaid-config.ts
|
|
9
|
+
/** The mermaid renderer's config stand (the v1 security + behavior stand —
|
|
10
|
+
* `securityLevel: "strict"` — the user's diagram source is sanitized and
|
|
11
|
+
* no click handlers or foreign scripts are bound — and
|
|
12
|
+
* `suppressErrorRendering: true`, so a rejected render removes its
|
|
13
|
+
* working container from the page before the parse error propagates —
|
|
14
|
+
* without it mermaid leaves a visible temp element in `body` per failed
|
|
15
|
+
* render; a looser mode is a consumer decision outside this package) +
|
|
16
|
+
* the theme setter (Mermaid 12 reads the config synchronously at the
|
|
17
|
+
* start of `render` (before its first await), so setting it in the same
|
|
18
|
+
* task as the render call is race-free across the page's instances — the
|
|
19
|
+
* global config is the only theme lever — `render` takes no per-render
|
|
20
|
+
* config) + the module-scope stand (the light default before the first
|
|
21
|
+
* mount) + the safe id (the block id with the characters that are not
|
|
22
|
+
* valid in a DOM id stripped). */
|
|
23
|
+
const MERMAID_CONFIG_STAND = {
|
|
24
|
+
startOnLoad: false,
|
|
25
|
+
securityLevel: "strict",
|
|
26
|
+
suppressErrorRendering: true
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Sets the global mermaid config for the editor's theme. Mermaid 12
|
|
30
|
+
* reads the config synchronously at the start of `render` (before its
|
|
31
|
+
* first await), so setting it in the same task as the render call is
|
|
32
|
+
* race-free across the page's instances (the global config is the only
|
|
33
|
+
* theme lever — `render` takes no per-render config).
|
|
34
|
+
*/
|
|
35
|
+
function configureMermaidTheme(theme) {
|
|
36
|
+
mermaid.initialize({
|
|
37
|
+
...MERMAID_CONFIG_STAND,
|
|
38
|
+
theme: theme === "dark" ? "dark" : "default"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
configureMermaidTheme("light");
|
|
42
|
+
/** The block id with the characters that are not valid in a DOM id stripped. */
|
|
43
|
+
function safeId(id) {
|
|
44
|
+
return id.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/mermaid/useContainerTheme.ts
|
|
48
|
+
/** The editor's theme for one ref'd element, reactive to a theme flip:
|
|
49
|
+
* a single MutationObserver watches the `class` attribute of the
|
|
50
|
+
* element's ancestor chain (collected on mount — the preview's branch
|
|
51
|
+
* swap keeps the same ancestors). A flip re-renders the diagram through
|
|
52
|
+
* the value change (a repeat of the current value is a React no-op). The
|
|
53
|
+
* editor's theme as seen from one element: the `dark` class on the
|
|
54
|
+
* element or any ancestor. */
|
|
55
|
+
/** The editor's theme as seen from one element: the `dark` class on the element or any ancestor. */
|
|
56
|
+
function detectEditorTheme(el) {
|
|
57
|
+
return el !== null && el.closest(".dark") !== null ? "dark" : "light";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The editor's theme for one ref'd element, reactive to a theme flip:
|
|
61
|
+
* a single MutationObserver watches the `class` attribute of the
|
|
62
|
+
* element's ancestor chain (collected on mount — the preview's branch
|
|
63
|
+
* swap keeps the same ancestors). A flip re-renders the diagram through
|
|
64
|
+
* the value change (a repeat of the current value is a React no-op).
|
|
65
|
+
*/
|
|
66
|
+
function useContainerTheme(ref) {
|
|
67
|
+
const [theme, setTheme] = useState(() => detectEditorTheme(ref.current));
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const apply = () => setTheme(detectEditorTheme(ref.current));
|
|
70
|
+
apply();
|
|
71
|
+
const targets = [];
|
|
72
|
+
for (let node = ref.current; node !== null; node = node.parentElement) targets.push(node);
|
|
73
|
+
if (targets.length === 0) return;
|
|
74
|
+
const observer = new MutationObserver(apply);
|
|
75
|
+
for (const target of targets) observer.observe(target, {
|
|
76
|
+
attributes: true,
|
|
77
|
+
attributeFilter: ["class"]
|
|
78
|
+
});
|
|
79
|
+
return () => observer.disconnect();
|
|
80
|
+
}, [ref]);
|
|
81
|
+
return theme;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/mermaid/MermaidDiagram.tsx
|
|
85
|
+
/** The live diagram preview of one mermaid code block: `mermaid.render`
|
|
86
|
+
* into a unique id per attempt, the svg injected into a container. The
|
|
87
|
+
* previous svg stays put while a (re-)render runs (no flicker while
|
|
88
|
+
* typing); a parse error drops the svg and shows the raw text with the
|
|
89
|
+
* error flag. The effect re-runs on every text change (the store-driven
|
|
90
|
+
* re-render passes a fresh block snapshot, so the text prop is the
|
|
91
|
+
* re-render trigger) and on an editor-theme flip (the theme is the
|
|
92
|
+
* global config's stand, set in the same task as the render call). */
|
|
93
|
+
/** A unique mermaid render id per attempt (mermaid requires one per render). */
|
|
94
|
+
let renderSeq = 0;
|
|
95
|
+
function MermaidDiagram({ id, text }) {
|
|
96
|
+
const containerRef = useRef(null);
|
|
97
|
+
const theme = useContainerTheme(containerRef);
|
|
98
|
+
const [state, setState] = useState({
|
|
99
|
+
svg: null,
|
|
100
|
+
error: null
|
|
101
|
+
});
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
renderSeq += 1;
|
|
104
|
+
const renderId = `mb-${renderSeq}-${safeId(id)}`;
|
|
105
|
+
let cancelled = false;
|
|
106
|
+
configureMermaidTheme(theme);
|
|
107
|
+
(async () => {
|
|
108
|
+
try {
|
|
109
|
+
const { svg } = await mermaid.render(renderId, text);
|
|
110
|
+
if (!cancelled) setState({
|
|
111
|
+
svg,
|
|
112
|
+
error: null
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!cancelled) setState({
|
|
116
|
+
svg: null,
|
|
117
|
+
error: error instanceof Error ? error.message : String(error)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
return () => {
|
|
122
|
+
cancelled = true;
|
|
123
|
+
};
|
|
124
|
+
}, [
|
|
125
|
+
id,
|
|
126
|
+
text,
|
|
127
|
+
theme
|
|
128
|
+
]);
|
|
129
|
+
if (state.error !== null) return /* @__PURE__ */ jsxs(Alert, {
|
|
130
|
+
ref: containerRef,
|
|
131
|
+
"data-slot": "docblocks/mermaid",
|
|
132
|
+
"data-state": "error",
|
|
133
|
+
variant: "destructive",
|
|
134
|
+
className: "mt-(--docblocks-block-spacing)",
|
|
135
|
+
children: [
|
|
136
|
+
/* @__PURE__ */ jsx(TriangleAlert, {}),
|
|
137
|
+
/* @__PURE__ */ jsx(AlertTitle, {
|
|
138
|
+
"data-slot": "docblocks/mermaid-error-message",
|
|
139
|
+
className: "line-clamp-none",
|
|
140
|
+
children: state.error
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsx(AlertDescription, { children: /* @__PURE__ */ jsx("code", {
|
|
143
|
+
"data-slot": "docblocks/mermaid-error",
|
|
144
|
+
className: INLINE_CODE_CLASS,
|
|
145
|
+
children: text
|
|
146
|
+
}) })
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
if (state.svg !== null) return /* @__PURE__ */ jsx("div", {
|
|
150
|
+
ref: containerRef,
|
|
151
|
+
"data-slot": "docblocks/mermaid",
|
|
152
|
+
"data-state": "diagram",
|
|
153
|
+
className: "mt-(--docblocks-block-spacing)",
|
|
154
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
155
|
+
"data-slot": "docblocks/mermaid-diagram",
|
|
156
|
+
dangerouslySetInnerHTML: { __html: state.svg }
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
160
|
+
ref: containerRef,
|
|
161
|
+
"data-slot": "docblocks/mermaid",
|
|
162
|
+
"data-state": "loading",
|
|
163
|
+
className: "relative mt-(--docblocks-block-spacing)",
|
|
164
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-24 w-full" }), /* @__PURE__ */ jsxs("div", {
|
|
165
|
+
className: "absolute inset-0 flex items-center justify-center gap-2",
|
|
166
|
+
children: [/* @__PURE__ */ jsx(LoaderCircle, { className: "size-4 animate-spin" }), /* @__PURE__ */ jsx("span", {
|
|
167
|
+
"data-slot": "docblocks/mermaid-loading",
|
|
168
|
+
children: "rendering…"
|
|
169
|
+
})]
|
|
170
|
+
})]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/mermaid/MermaidCodeRenderer.tsx
|
|
175
|
+
function MermaidModeSelector({ id, block }) {
|
|
176
|
+
const { doc } = useEditorContext();
|
|
177
|
+
const mode = block.attrs?.mermaidMode ?? "code";
|
|
178
|
+
const pick = (next) => {
|
|
179
|
+
if (next === mode) return;
|
|
180
|
+
doc.updateBlock(id, { mermaidMode: next });
|
|
181
|
+
};
|
|
182
|
+
return /* @__PURE__ */ jsx(SegmentSelector, {
|
|
183
|
+
options: [{
|
|
184
|
+
value: "code",
|
|
185
|
+
label: "Show the code",
|
|
186
|
+
icon: /* @__PURE__ */ jsx(CodeXml, { className: "size-4" })
|
|
187
|
+
}, {
|
|
188
|
+
value: "preview",
|
|
189
|
+
label: "Show the diagram preview",
|
|
190
|
+
icon: /* @__PURE__ */ jsx(Eye, { className: "size-4" })
|
|
191
|
+
}],
|
|
192
|
+
value: mode,
|
|
193
|
+
onChange: pick,
|
|
194
|
+
ariaLabel: "Mermaid display mode",
|
|
195
|
+
slot: "docblocks/mermaid-mode",
|
|
196
|
+
pillSlot: "docblocks/mermaid-mode-pill",
|
|
197
|
+
buttonAttrName: "mermaid-mode-button"
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* One code block with the diagram capability: a `language: "mermaid"`
|
|
202
|
+
* block renders per its `mermaidMode` (default "code") — the modes are
|
|
203
|
+
* exclusive: `code` renders the editable code only (the diagram stands
|
|
204
|
+
* hidden), `preview` renders the diagram only (the code body hidden —
|
|
205
|
+
* the editable stays mounted for the text sync); every other code block
|
|
206
|
+
* is the plain built-in code rendering.
|
|
207
|
+
*/
|
|
208
|
+
function MermaidCodeBlock({ id, block }) {
|
|
209
|
+
const nested = childrenSlot(id, block.children);
|
|
210
|
+
if (block.attrs?.language !== "mermaid") return /* @__PURE__ */ jsx(TextBlock, {
|
|
211
|
+
id,
|
|
212
|
+
block,
|
|
213
|
+
tag: "pre",
|
|
214
|
+
header: /* @__PURE__ */ jsx(CodeHeader, {
|
|
215
|
+
id,
|
|
216
|
+
block
|
|
217
|
+
}),
|
|
218
|
+
nested
|
|
219
|
+
});
|
|
220
|
+
const mode = block.attrs?.mermaidMode ?? "code";
|
|
221
|
+
return /* @__PURE__ */ jsx(TextBlock, {
|
|
222
|
+
id,
|
|
223
|
+
block,
|
|
224
|
+
tag: "pre",
|
|
225
|
+
header: /* @__PURE__ */ jsx(CodeHeader, {
|
|
226
|
+
id,
|
|
227
|
+
block,
|
|
228
|
+
center: /* @__PURE__ */ jsx(MermaidModeSelector, {
|
|
229
|
+
id,
|
|
230
|
+
block
|
|
231
|
+
})
|
|
232
|
+
}),
|
|
233
|
+
codeBodyHidden: mode === "preview",
|
|
234
|
+
nested: mode === "preview" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(MermaidDiagram, {
|
|
235
|
+
id,
|
|
236
|
+
text: textOf(block.content)
|
|
237
|
+
}), nested] }) : nested
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* A BlockRenderer for the `code` type. The registry dispatches by type:
|
|
242
|
+
* a renderer registered under "code" only receives code blocks (the union
|
|
243
|
+
* cannot express that narrowing at the call site).
|
|
244
|
+
*/
|
|
245
|
+
function MermaidCodeRenderer({ id, block }) {
|
|
246
|
+
return /* @__PURE__ */ jsx(MermaidCodeBlock, {
|
|
247
|
+
id,
|
|
248
|
+
block
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
export { MermaidCodeRenderer };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { n as EditorView } from "../Editor-DT7RkRXf.mjs";
|
|
2
|
+
//#region src/motion/MotionEditor.d.ts
|
|
3
|
+
declare function MotionEditor({ view, formatPalette }: {
|
|
4
|
+
view?: EditorView;
|
|
5
|
+
formatPalette?: readonly string[];
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MotionEditor };
|