@caseparts-org/caseblocks 0.0.193 → 0.0.195
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/dist/assets/Admonition.css +1 -0
- package/dist/assets/MainNav.css +1 -1
- package/dist/assets/Markdown.css +1 -1
- package/dist/atoms/Markdown/Markdown.js +794 -776
- package/dist/atoms/Markdown/Markdown.stories.d.ts +2 -0
- package/dist/atoms/Markdown/Markdown.stories.js +88 -18
- package/dist/atoms/Markdown/PreprocessedMarkdown.d.ts +4 -3
- package/dist/atoms/Markdown/PreprocessedMarkdown.js +18 -11
- package/dist/atoms/Markdown/PreprocessedMarkdown.stories.d.ts +1 -0
- package/dist/atoms/Markdown/PreprocessedMarkdown.stories.js +34 -25
- package/dist/atoms/Markdown/remarkAdmonition.d.ts +15 -0
- package/dist/atoms/Markdown/remarkAdmonition.js +120 -0
- package/dist/atoms/Markdown/usePreprocessedMarkdown.d.ts +2 -1
- package/dist/atoms/Markdown/usePreprocessedMarkdown.js +59 -37
- package/dist/main-client.js +54 -52
- package/dist/main-server.d.ts +2 -0
- package/dist/main-server.js +16 -14
- package/dist/main.d.ts +2 -0
- package/dist/main.js +18 -16
- package/dist/molecules/Admonition/Admonition.d.ts +10 -0
- package/dist/molecules/Admonition/Admonition.js +46 -0
- package/dist/molecules/Admonition/Admonition.stories.d.ts +13 -0
- package/dist/molecules/Admonition/Admonition.stories.js +51 -0
- package/dist/organisms/MainNav/MainNav.js +77 -75
- package/package.json +1 -1
|
@@ -1,12 +1,43 @@
|
|
|
1
|
-
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { jsx as t, jsxs as p } from "react/jsx-runtime";
|
|
2
|
+
import { useState as u, useEffect as h } from "react";
|
|
3
|
+
import { Markdown as s } from "./Markdown.js";
|
|
4
|
+
import { usePreprocessedMarkdown as g } from "./usePreprocessedMarkdown.js";
|
|
5
|
+
const x = {
|
|
5
6
|
title: "Case Parts/Atoms/Markdown",
|
|
6
|
-
component:
|
|
7
|
+
component: s,
|
|
7
8
|
parameters: { layout: "padded" },
|
|
8
9
|
tags: ["autodocs"]
|
|
9
|
-
},
|
|
10
|
+
}, a = `# Admonitions
|
|
11
|
+
|
|
12
|
+
:::warning[Electrical Hazard]{icon="bolt"}
|
|
13
|
+
Disconnect power before servicing this unit.
|
|
14
|
+
:::
|
|
15
|
+
|
|
16
|
+
:::warning[Electrical Hazard]{icon="bolt"}
|
|
17
|
+
|
|
18
|
+
Disconnect power before servicing this unit.
|
|
19
|
+
|
|
20
|
+
:::
|
|
21
|
+
`;
|
|
22
|
+
function w(e) {
|
|
23
|
+
const [n, o] = u(e.children ?? a);
|
|
24
|
+
return h(() => {
|
|
25
|
+
o(e.children ?? a);
|
|
26
|
+
}, [e.children]), /* @__PURE__ */ p("div", { style: { display: "grid", gap: 12 }, children: [
|
|
27
|
+
/* @__PURE__ */ t("label", { style: { fontWeight: 600 }, children: "Edit Markdown (live):" }),
|
|
28
|
+
/* @__PURE__ */ t(
|
|
29
|
+
"textarea",
|
|
30
|
+
{
|
|
31
|
+
value: n,
|
|
32
|
+
onChange: (i) => o(i.target.value),
|
|
33
|
+
rows: 14,
|
|
34
|
+
style: { width: "100%", fontFamily: "monospace" }
|
|
35
|
+
}
|
|
36
|
+
),
|
|
37
|
+
/* @__PURE__ */ t(s, { ...e, children: n })
|
|
38
|
+
] });
|
|
39
|
+
}
|
|
40
|
+
const k = {
|
|
10
41
|
args: {
|
|
11
42
|
children: `# Heading 1
|
|
12
43
|
|
|
@@ -43,27 +74,66 @@ export default greet;
|
|
|
43
74
|
|------:|:------|
|
|
44
75
|
| 123 | text |`
|
|
45
76
|
}
|
|
46
|
-
},
|
|
77
|
+
}, C = {
|
|
47
78
|
name: "Item Description Variant",
|
|
48
|
-
render: (
|
|
49
|
-
const
|
|
50
|
-
if (await new Promise((
|
|
79
|
+
render: (e) => /* @__PURE__ */ t(({ text: i }) => {
|
|
80
|
+
const l = async (r) => {
|
|
81
|
+
if (await new Promise((m) => setTimeout(m, 50)), /^\d+$/.test(r)) return !0;
|
|
51
82
|
throw new Error("invalid");
|
|
52
|
-
}, { output:
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
83
|
+
}, { output: d, loading: c } = g(
|
|
84
|
+
i,
|
|
85
|
+
(r) => `https://example.com/parts/${encodeURIComponent(r)}`,
|
|
86
|
+
l,
|
|
56
87
|
!0
|
|
57
88
|
);
|
|
58
|
-
return /* @__PURE__ */ t(
|
|
89
|
+
return /* @__PURE__ */ t(s, { ...e, children: c ? "Validating…" : d });
|
|
59
90
|
}, { text: `Kason 171 Latch
|
|
60
91
|
|
|
61
92
|
This fits part [171] and an invalid token [bad]. Already linked should remain: [171](https://example.com/should-stay).
|
|
62
93
|
|
|
63
94
|
Another valid numeric: [172].` })
|
|
95
|
+
}, A = {
|
|
96
|
+
args: {
|
|
97
|
+
children: `# Admonitions
|
|
98
|
+
|
|
99
|
+
:::note
|
|
100
|
+
Confirm model and serial number before ordering.
|
|
101
|
+
:::
|
|
102
|
+
|
|
103
|
+
:::important[Compatibility]
|
|
104
|
+
Fits only selected revisions.
|
|
105
|
+
:::
|
|
106
|
+
|
|
107
|
+
:::warning[Electrical Hazard]{icon="fa-solid fa-bolt"}
|
|
108
|
+
Disconnect power before servicing this unit.
|
|
109
|
+
:::
|
|
110
|
+
|
|
111
|
+
:::tip[Screw Size]{icon="fa-solid fa-screwdriver-wrench"}
|
|
112
|
+
Uses (6) #12 Flat Head screws
|
|
113
|
+
:::
|
|
114
|
+
|
|
115
|
+
:::custom-alert{title="Compatibility Note"}
|
|
116
|
+
Unknown type is preserved and rendered with neutral styling.
|
|
117
|
+
:::
|
|
118
|
+
|
|
119
|
+
Malformed opening should remain plain markdown:
|
|
120
|
+
|
|
121
|
+
:::warning[Missing end title
|
|
122
|
+
This block should not be transformed.
|
|
123
|
+
:::
|
|
124
|
+
`
|
|
125
|
+
}
|
|
126
|
+
}, M = {
|
|
127
|
+
name: "Live Playground",
|
|
128
|
+
args: {
|
|
129
|
+
children: a
|
|
130
|
+
},
|
|
131
|
+
render: (e) => /* @__PURE__ */ t(w, { ...e })
|
|
64
132
|
};
|
|
65
133
|
export {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
134
|
+
A as Admonitions,
|
|
135
|
+
k as Basic,
|
|
136
|
+
C as ItemDescription,
|
|
137
|
+
M as Playground,
|
|
138
|
+
x as default
|
|
69
139
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { LinkTarget, ValidateToken } from './usePreprocessedMarkdown';
|
|
1
|
+
import { LinkTarget, ValidateToken, BatchValidateTokens } from './usePreprocessedMarkdown';
|
|
2
2
|
export type PreprocessedMarkdownProps = {
|
|
3
3
|
children?: string | null;
|
|
4
4
|
url: LinkTarget;
|
|
5
|
-
validate
|
|
5
|
+
validate?: ValidateToken;
|
|
6
|
+
batchValidate?: BatchValidateTokens;
|
|
6
7
|
className?: string;
|
|
7
8
|
debug?: boolean;
|
|
8
9
|
};
|
|
9
|
-
export declare function PreprocessedMarkdown({ url, validate, debug, className, children, }: PreprocessedMarkdownProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function PreprocessedMarkdown({ url, validate, batchValidate, debug, className, children, }: PreprocessedMarkdownProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { Markdown as
|
|
3
|
-
import { usePreprocessedMarkdown as
|
|
4
|
-
function
|
|
2
|
+
import { Markdown as m } from "./Markdown.js";
|
|
3
|
+
import { usePreprocessedMarkdown as c } from "./usePreprocessedMarkdown.js";
|
|
4
|
+
function l({
|
|
5
5
|
url: o,
|
|
6
6
|
validate: e,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
batchValidate: n,
|
|
8
|
+
debug: t,
|
|
9
|
+
className: p,
|
|
10
|
+
children: d
|
|
10
11
|
}) {
|
|
11
|
-
const { output: s } =
|
|
12
|
+
const { output: s } = c(
|
|
13
|
+
d ?? "",
|
|
14
|
+
o,
|
|
15
|
+
e,
|
|
16
|
+
t,
|
|
17
|
+
n
|
|
18
|
+
);
|
|
12
19
|
return /* @__PURE__ */ r(
|
|
13
|
-
|
|
20
|
+
m,
|
|
14
21
|
{
|
|
15
|
-
className:
|
|
22
|
+
className: p,
|
|
16
23
|
components: {
|
|
17
|
-
a: ({ node:
|
|
24
|
+
a: ({ node: f, ...a }) => /* @__PURE__ */ r(
|
|
18
25
|
"a",
|
|
19
26
|
{
|
|
20
27
|
...a,
|
|
@@ -28,5 +35,5 @@ function k({
|
|
|
28
35
|
);
|
|
29
36
|
}
|
|
30
37
|
export {
|
|
31
|
-
|
|
38
|
+
l as PreprocessedMarkdown
|
|
32
39
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as n, jsxs as i } from "react/jsx-runtime";
|
|
2
2
|
import { useState as c, useEffect as m } from "react";
|
|
3
|
-
import { PreprocessedMarkdown as
|
|
4
|
-
const
|
|
3
|
+
import { PreprocessedMarkdown as s } from "./PreprocessedMarkdown.js";
|
|
4
|
+
const o = `Preprocessed Markdown
|
|
5
5
|
|
|
6
6
|
- Valid token [171] will link
|
|
7
7
|
- Invalid token [ABC] shows a warning when debug is on
|
|
8
8
|
|
|
9
|
-
You can also add more [123] tokens here.`,
|
|
9
|
+
You can also add more [123] tokens here.`, l = async (e) => {
|
|
10
10
|
if (await new Promise((t) => setTimeout(t, 150)), /^\d+$/.test(e)) return !0;
|
|
11
11
|
throw new Error("Invalid token");
|
|
12
|
-
},
|
|
12
|
+
}, u = async (e) => (await new Promise((t) => setTimeout(t, 150)), new Set(e.filter((t) => /^\d+$/.test(t)))), r = (e) => `https://example.com/items/${encodeURIComponent(e)}`, k = {
|
|
13
13
|
title: "Case Parts/Atoms/Markdown/PreprocessedMarkdown",
|
|
14
|
-
component:
|
|
14
|
+
component: s,
|
|
15
15
|
tags: ["autodocs"],
|
|
16
16
|
parameters: {
|
|
17
17
|
controls: { expanded: !0 }
|
|
@@ -22,43 +22,52 @@ You can also add more [123] tokens here.`, s = async (e) => {
|
|
|
22
22
|
className: { control: "text" }
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
const [t,
|
|
25
|
+
function h(e) {
|
|
26
|
+
const [t, a] = c(e.children ?? o);
|
|
27
27
|
return m(() => {
|
|
28
|
-
|
|
28
|
+
a(e.children ?? o);
|
|
29
29
|
}, [e.children]), /* @__PURE__ */ i("div", { style: { display: "grid", gap: 12 }, children: [
|
|
30
|
-
/* @__PURE__ */
|
|
31
|
-
/* @__PURE__ */
|
|
30
|
+
/* @__PURE__ */ n("label", { style: { fontWeight: 600 }, children: "Edit Markdown (live):" }),
|
|
31
|
+
/* @__PURE__ */ n(
|
|
32
32
|
"textarea",
|
|
33
33
|
{
|
|
34
34
|
value: t,
|
|
35
|
-
onChange: (d) =>
|
|
35
|
+
onChange: (d) => a(d.target.value),
|
|
36
36
|
rows: 8,
|
|
37
37
|
style: { width: "100%", fontFamily: "monospace" }
|
|
38
38
|
}
|
|
39
39
|
),
|
|
40
|
-
/* @__PURE__ */
|
|
40
|
+
/* @__PURE__ */ n(s, { ...e, children: t })
|
|
41
41
|
] });
|
|
42
42
|
}
|
|
43
|
-
const
|
|
43
|
+
const f = {
|
|
44
44
|
args: {
|
|
45
|
-
children:
|
|
46
|
-
url:
|
|
47
|
-
validate:
|
|
45
|
+
children: o,
|
|
46
|
+
url: r,
|
|
47
|
+
validate: l,
|
|
48
48
|
debug: !0
|
|
49
49
|
},
|
|
50
|
-
render: (e) => /* @__PURE__ */
|
|
51
|
-
},
|
|
50
|
+
render: (e) => /* @__PURE__ */ n(h, { ...e })
|
|
51
|
+
}, x = {
|
|
52
52
|
name: "With Controls",
|
|
53
53
|
args: {
|
|
54
|
-
children:
|
|
55
|
-
url:
|
|
56
|
-
validate:
|
|
54
|
+
children: o,
|
|
55
|
+
url: r,
|
|
56
|
+
validate: l,
|
|
57
57
|
debug: !1
|
|
58
58
|
}
|
|
59
|
+
}, y = {
|
|
60
|
+
name: "Batch Validate",
|
|
61
|
+
args: {
|
|
62
|
+
children: o,
|
|
63
|
+
url: r,
|
|
64
|
+
batchValidate: u,
|
|
65
|
+
debug: !0
|
|
66
|
+
}
|
|
59
67
|
};
|
|
60
68
|
export {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
y as BatchValidate,
|
|
70
|
+
x as ControlsOnly,
|
|
71
|
+
f as Playground,
|
|
72
|
+
k as default
|
|
64
73
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type MarkdownNode = {
|
|
2
|
+
type: string;
|
|
3
|
+
value?: string;
|
|
4
|
+
children?: MarkdownNode[];
|
|
5
|
+
data?: {
|
|
6
|
+
hName?: string;
|
|
7
|
+
hProperties?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type MarkdownRoot = {
|
|
11
|
+
type: "root";
|
|
12
|
+
children: MarkdownNode[];
|
|
13
|
+
};
|
|
14
|
+
export declare function remarkAdmonition(): (tree: MarkdownRoot) => void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const g = /^[a-z][a-z0-9_-]*/, y = /^\s*(?:[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*"(?:[ \t]+[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*")*)?\s*$/, x = /([a-z][a-z0-9_-]*)="((?:[^"\\]|\\.)*)"/g, d = /^:::[ \t]*$/, b = /* @__PURE__ */ new Set(["note", "tip", "important", "caution", "warning"]), f = (n) => {
|
|
2
|
+
if (n.type !== "paragraph" || !n.children || n.children.length === 0) return null;
|
|
3
|
+
let t = "";
|
|
4
|
+
for (const e of n.children) {
|
|
5
|
+
if (e.type === "text" && typeof e.value == "string") {
|
|
6
|
+
t += e.value;
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
if (e.type === "break") {
|
|
10
|
+
t += `
|
|
11
|
+
`;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
}, T = (n) => ({
|
|
18
|
+
type: "paragraph",
|
|
19
|
+
children: [{ type: "text", value: n }]
|
|
20
|
+
}), _ = (n) => n.replace(/\\(.)/g, "$1"), v = (n) => {
|
|
21
|
+
if (!y.test(n)) return null;
|
|
22
|
+
const t = {};
|
|
23
|
+
for (const e of n.matchAll(x)) {
|
|
24
|
+
const i = e[1], o = _(e[2]);
|
|
25
|
+
(i === "icon" || i === "title") && (t[i] = o);
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
}, E = (n) => {
|
|
29
|
+
let t = !1, e = !1;
|
|
30
|
+
for (let i = 1; i < n.length; i += 1) {
|
|
31
|
+
const o = n[i];
|
|
32
|
+
if (e) {
|
|
33
|
+
e = !1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (o === "\\") {
|
|
37
|
+
e = !0;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (o === '"') {
|
|
41
|
+
t = !t;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (o === "}" && !t)
|
|
45
|
+
return i;
|
|
46
|
+
}
|
|
47
|
+
return -1;
|
|
48
|
+
}, I = (n) => {
|
|
49
|
+
if (!n.startsWith(":::")) return null;
|
|
50
|
+
let t = n.slice(3);
|
|
51
|
+
const e = t.match(g);
|
|
52
|
+
if (!e) return null;
|
|
53
|
+
const i = e[0];
|
|
54
|
+
t = t.slice(i.length);
|
|
55
|
+
let o;
|
|
56
|
+
if (t.startsWith("[")) {
|
|
57
|
+
const r = t.indexOf("]");
|
|
58
|
+
if (r < 0) return null;
|
|
59
|
+
o = t.slice(1, r), t = t.slice(r + 1);
|
|
60
|
+
}
|
|
61
|
+
let c = {};
|
|
62
|
+
if (t.startsWith("{")) {
|
|
63
|
+
const r = E(t);
|
|
64
|
+
if (r < 0) return null;
|
|
65
|
+
const a = v(t.slice(1, r));
|
|
66
|
+
if (!a) return null;
|
|
67
|
+
c = a, t = t.slice(r + 1);
|
|
68
|
+
}
|
|
69
|
+
return /^[ \t]*$/.test(t) ? { name: i, title: o, attributes: c } : null;
|
|
70
|
+
}, A = (n, t) => {
|
|
71
|
+
for (let e = t; e < n.length; e += 1) {
|
|
72
|
+
const i = f(n[e]);
|
|
73
|
+
if (i && d.test(i))
|
|
74
|
+
return e;
|
|
75
|
+
}
|
|
76
|
+
return -1;
|
|
77
|
+
}, N = (n) => {
|
|
78
|
+
const t = n.join(`
|
|
79
|
+
`);
|
|
80
|
+
return t.trim() ? t.split(/\n{2,}/).map((e) => e.trim()).filter(Boolean).map((e) => T(e)) : [];
|
|
81
|
+
};
|
|
82
|
+
function z() {
|
|
83
|
+
return (n) => {
|
|
84
|
+
if (!(!n || n.type !== "root" || !Array.isArray(n.children)))
|
|
85
|
+
for (let t = 0; t < n.children.length; t += 1) {
|
|
86
|
+
const e = f(n.children[t]);
|
|
87
|
+
if (!e) continue;
|
|
88
|
+
const i = e.split(/\r?\n/), o = I(i[0] ?? "");
|
|
89
|
+
if (!o) continue;
|
|
90
|
+
let c = [], r = 0;
|
|
91
|
+
if (i.length > 1) {
|
|
92
|
+
const l = i.findIndex((u, m) => m > 0 && d.test(u));
|
|
93
|
+
if (l < 0 || i.slice(l + 1).some((u) => u.trim().length > 0))
|
|
94
|
+
continue;
|
|
95
|
+
c = N(i.slice(1, l)), r = 1;
|
|
96
|
+
} else {
|
|
97
|
+
const l = A(n.children, t + 1);
|
|
98
|
+
if (l < 0) continue;
|
|
99
|
+
c = n.children.slice(t + 1, l), r = l - t + 1;
|
|
100
|
+
}
|
|
101
|
+
const a = o.title ?? o.attributes.title, h = b.has(o.name) ? o.name : "unknown", s = {
|
|
102
|
+
"data-admonition": o.name,
|
|
103
|
+
"data-admonition-variant": h
|
|
104
|
+
};
|
|
105
|
+
a !== void 0 && (s["data-admonition-title"] = a), o.attributes.icon !== void 0 && (s["data-admonition-icon"] = o.attributes.icon);
|
|
106
|
+
const p = {
|
|
107
|
+
type: "admonition",
|
|
108
|
+
data: {
|
|
109
|
+
hName: "aside",
|
|
110
|
+
hProperties: s
|
|
111
|
+
},
|
|
112
|
+
children: c
|
|
113
|
+
};
|
|
114
|
+
n.children.splice(t, r, p);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
z as remarkAdmonition
|
|
120
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type ValidateToken = (_token: string) => Promise<unknown>;
|
|
2
|
+
export type BatchValidateTokens = (_tokens: readonly string[]) => Promise<ReadonlySet<string> | readonly string[]>;
|
|
2
3
|
export type LinkTarget = string | ((_token: string) => string);
|
|
3
4
|
export type PreprocessedMarkdownResult = {
|
|
4
5
|
output: string;
|
|
@@ -9,4 +10,4 @@ export type PreprocessedMarkdownResult = {
|
|
|
9
10
|
* Extracts bracketed tokens not already followed by parentheses, validates them, and
|
|
10
11
|
* returns the input with validated tokens converted to markdown links.
|
|
11
12
|
*/
|
|
12
|
-
export declare function usePreprocessedMarkdown(input: string | null | undefined, url: LinkTarget, validate
|
|
13
|
+
export declare function usePreprocessedMarkdown(input: string | null | undefined, url: LinkTarget, validate?: ValidateToken, debug?: boolean, batchValidate?: BatchValidateTokens): PreprocessedMarkdownResult;
|
|
@@ -1,52 +1,74 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
function
|
|
3
|
-
const [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { useState as q, useRef as p, useEffect as v, useMemo as x } from "react";
|
|
2
|
+
function k(n, i, w, y = !1, S) {
|
|
3
|
+
const [H, d] = q(n ?? ""), [P, h] = q(!1), r = p(/* @__PURE__ */ new Map()), E = p(w), R = p(
|
|
4
|
+
S
|
|
5
|
+
);
|
|
6
|
+
v(() => {
|
|
7
|
+
E.current = w, R.current = S;
|
|
8
|
+
}, [w, S]);
|
|
9
|
+
const u = x(() => /\[(.+?)\](?!\()/g, []), f = x(() => {
|
|
10
|
+
if (!n) return [];
|
|
11
|
+
const o = Array.from(n.matchAll(u)).map((l) => l[1]);
|
|
12
|
+
return Array.from(new Set(o));
|
|
13
|
+
}, [n, u]), $ = (o) => {
|
|
14
|
+
const e = o.split(/\r?\n/);
|
|
15
|
+
if (e.length === 0) return o;
|
|
16
|
+
const l = e[0];
|
|
17
|
+
return /^\s*#\s/.test(l) || (e[0] = `# ${l.trim()}`), e.join(`
|
|
12
18
|
`);
|
|
13
19
|
};
|
|
14
|
-
return
|
|
15
|
-
if (!
|
|
16
|
-
|
|
20
|
+
return v(() => {
|
|
21
|
+
if (!n) {
|
|
22
|
+
d(""), h(!1);
|
|
17
23
|
return;
|
|
18
24
|
}
|
|
19
|
-
if (!
|
|
20
|
-
|
|
25
|
+
if (!f.length) {
|
|
26
|
+
d($(n)), h(!1);
|
|
21
27
|
return;
|
|
22
28
|
}
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
const
|
|
29
|
+
let o = !1;
|
|
30
|
+
h(!0);
|
|
31
|
+
const e = f.filter((g) => !r.current.has(g));
|
|
26
32
|
return (async () => {
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if (e.length) {
|
|
34
|
+
const t = R.current, s = E.current;
|
|
35
|
+
if (t)
|
|
29
36
|
try {
|
|
30
|
-
await
|
|
37
|
+
const c = await t(e), a = c instanceof Set ? c : new Set(c);
|
|
38
|
+
e.forEach((m) => {
|
|
39
|
+
r.current.set(m, a.has(m));
|
|
40
|
+
});
|
|
31
41
|
} catch {
|
|
32
|
-
|
|
42
|
+
e.forEach((c) => {
|
|
43
|
+
r.current.set(c, !1);
|
|
44
|
+
});
|
|
33
45
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
else s ? (await Promise.allSettled(
|
|
47
|
+
e.map(async (a) => {
|
|
48
|
+
try {
|
|
49
|
+
await s(a), r.current.set(a, !0);
|
|
50
|
+
} catch {
|
|
51
|
+
r.current.set(a, !1);
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
)).forEach((a, m) => {
|
|
55
|
+
const M = e[m];
|
|
56
|
+
r.current.has(M) || r.current.set(M, a.status === "fulfilled");
|
|
57
|
+
}) : e.forEach((c) => {
|
|
58
|
+
r.current.set(c, !0);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const g = new Set(
|
|
62
|
+
f.filter((t) => r.current.get(t) === !0)
|
|
63
|
+
), j = new Set(
|
|
64
|
+
f.filter((t) => r.current.get(t) === !1)
|
|
65
|
+
), C = (t) => typeof i == "function" ? i(t) : i, A = n.replace(u, (t, s) => g.has(s) ? `**[${s}](${C(s)})**` : t), L = y ? A.replace(u, (t, s) => j.has(s) ? `[${s}]⚠️` : t) : A, O = $(L);
|
|
66
|
+
o || (d(O), h(!1));
|
|
45
67
|
})(), () => {
|
|
46
|
-
|
|
68
|
+
o = !0;
|
|
47
69
|
};
|
|
48
|
-
}, [
|
|
70
|
+
}, [n, f, y, i, u]), { output: H, loading: P, tokens: f };
|
|
49
71
|
}
|
|
50
72
|
export {
|
|
51
|
-
|
|
73
|
+
k as usePreprocessedMarkdown
|
|
52
74
|
};
|