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