@caseparts-org/caseblocks 0.0.200 → 0.0.202
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/molecules/Markdown/Markdown.d.ts +3 -2
- package/dist/molecules/Markdown/Markdown.js +17 -15
- package/dist/molecules/Markdown/Markdown.stories.js +35 -32
- package/dist/molecules/Markdown/usePreprocessedMarkdown.d.ts +3 -3
- package/dist/molecules/Markdown/usePreprocessedMarkdown.js +63 -54
- package/package.json +1 -1
|
@@ -4,9 +4,10 @@ export type MarkdownProps = {
|
|
|
4
4
|
children?: string | null;
|
|
5
5
|
className?: string;
|
|
6
6
|
components?: Components;
|
|
7
|
-
|
|
7
|
+
partUrl?: LinkTarget;
|
|
8
|
+
relativePathUrl?: LinkTarget;
|
|
8
9
|
validate?: ValidateToken;
|
|
9
10
|
batchValidate?: BatchValidateTokens;
|
|
10
11
|
debug?: boolean;
|
|
11
12
|
};
|
|
12
|
-
export declare function Markdown({ children, className, components,
|
|
13
|
+
export declare function Markdown({ children, className, components, partUrl, relativePathUrl, validate, batchValidate, debug, }: MarkdownProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -8679,28 +8679,30 @@ function zf({
|
|
|
8679
8679
|
children: e,
|
|
8680
8680
|
className: t,
|
|
8681
8681
|
components: n,
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8682
|
+
partUrl: r,
|
|
8683
|
+
relativePathUrl: i,
|
|
8684
|
+
validate: o,
|
|
8685
|
+
batchValidate: l,
|
|
8686
|
+
debug: a = !1
|
|
8686
8687
|
}) {
|
|
8687
|
-
const
|
|
8688
|
-
|
|
8688
|
+
const u = e ?? "", { output: s } = Ti(
|
|
8689
|
+
u,
|
|
8689
8690
|
r,
|
|
8690
8691
|
i,
|
|
8691
|
-
|
|
8692
|
-
|
|
8692
|
+
o,
|
|
8693
|
+
a,
|
|
8694
|
+
l
|
|
8693
8695
|
);
|
|
8694
|
-
if (!
|
|
8695
|
-
const
|
|
8696
|
-
a: ({ node:
|
|
8697
|
-
} : {},
|
|
8698
|
-
return /* @__PURE__ */ je("div", { className:
|
|
8696
|
+
if (!u) return null;
|
|
8697
|
+
const f = r || i ? {
|
|
8698
|
+
a: ({ node: h, ...d }) => /* @__PURE__ */ je("a", { ...d, target: "_blank", rel: "noopener noreferrer" })
|
|
8699
|
+
} : {}, c = t ? `${or.markdown} ${t}` : or.markdown, p = { ...Ef, ...f, ...n };
|
|
8700
|
+
return /* @__PURE__ */ je("div", { className: c, children: /* @__PURE__ */ je(
|
|
8699
8701
|
os,
|
|
8700
8702
|
{
|
|
8701
8703
|
remarkPlugins: [xf, Sf, Ii],
|
|
8702
|
-
components:
|
|
8703
|
-
children:
|
|
8704
|
+
components: p,
|
|
8705
|
+
children: s
|
|
8704
8706
|
}
|
|
8705
8707
|
) });
|
|
8706
8708
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as a, jsxs as c } from "react/jsx-runtime";
|
|
2
2
|
import { useState as m, useEffect as p } from "react";
|
|
3
|
-
import { Markdown as
|
|
4
|
-
const
|
|
3
|
+
import { Markdown as l } from "./Markdown.js";
|
|
4
|
+
const w = {
|
|
5
5
|
title: "Case Parts/Molecules/Markdown",
|
|
6
|
-
component:
|
|
6
|
+
component: l,
|
|
7
7
|
parameters: { layout: "padded" },
|
|
8
8
|
tags: ["autodocs"]
|
|
9
9
|
}, r = `Kason 171 Latch
|
|
@@ -12,50 +12,51 @@ const f = {
|
|
|
12
12
|
Fits only selected revisions.
|
|
13
13
|
:::
|
|
14
14
|
|
|
15
|
-
This fits part [171]
|
|
15
|
+
This fits part [171], an invalid token [bad], and a help page at [FAQ](/faq).
|
|
16
16
|
Already linked should remain: [171](https://example.com/should-stay).
|
|
17
17
|
`;
|
|
18
|
-
function
|
|
19
|
-
const [
|
|
18
|
+
function h(e) {
|
|
19
|
+
const [i, o] = m(e.children ?? r);
|
|
20
20
|
return p(() => {
|
|
21
|
-
|
|
21
|
+
o(e.children ?? r);
|
|
22
22
|
}, [e.children]), /* @__PURE__ */ c("div", { style: { display: "grid", gap: 12 }, children: [
|
|
23
|
-
/* @__PURE__ */
|
|
24
|
-
/* @__PURE__ */
|
|
23
|
+
/* @__PURE__ */ a("label", { style: { fontWeight: 600 }, children: "Edit Markdown (preprocess + admonitions live):" }),
|
|
24
|
+
/* @__PURE__ */ a(
|
|
25
25
|
"textarea",
|
|
26
26
|
{
|
|
27
|
-
value:
|
|
28
|
-
onChange: (t) =>
|
|
27
|
+
value: i,
|
|
28
|
+
onChange: (t) => o(t.target.value),
|
|
29
29
|
rows: 14,
|
|
30
30
|
style: { width: "100%", fontFamily: "monospace" }
|
|
31
31
|
}
|
|
32
32
|
),
|
|
33
|
-
/* @__PURE__ */
|
|
34
|
-
|
|
33
|
+
/* @__PURE__ */ a(
|
|
34
|
+
l,
|
|
35
35
|
{
|
|
36
36
|
...e,
|
|
37
|
-
|
|
37
|
+
partUrl: (t) => `https://example.com/parts/${encodeURIComponent(t)}`,
|
|
38
|
+
relativePathUrl: "https://example.com",
|
|
38
39
|
validate: async (t) => {
|
|
39
|
-
if (await new Promise((
|
|
40
|
+
if (await new Promise((n) => setTimeout(n, 50)), /^\d+$/.test(t)) return !0;
|
|
40
41
|
throw new Error("invalid");
|
|
41
42
|
},
|
|
42
43
|
debug: !0,
|
|
43
|
-
children:
|
|
44
|
+
children: i
|
|
44
45
|
}
|
|
45
46
|
)
|
|
46
47
|
] });
|
|
47
48
|
}
|
|
48
|
-
const
|
|
49
|
+
const v = {
|
|
49
50
|
name: "Live Playground",
|
|
50
51
|
args: {
|
|
51
52
|
children: r
|
|
52
53
|
},
|
|
53
|
-
render: (e) => /* @__PURE__ */
|
|
54
|
-
},
|
|
54
|
+
render: (e) => /* @__PURE__ */ a(h, { ...e })
|
|
55
|
+
}, y = {
|
|
55
56
|
args: {
|
|
56
57
|
children: `# Heading 1
|
|
57
58
|
|
|
58
|
-
Paragraph with a [link](https://example.com).
|
|
59
|
+
Paragraph with a [link](https://example.com) and a relative help path [FAQ](/faq).
|
|
59
60
|
|
|
60
61
|
## Heading 2
|
|
61
62
|
|
|
@@ -86,25 +87,27 @@ export default greet;
|
|
|
86
87
|
|
|
87
88
|
| Col A | Col B |
|
|
88
89
|
|------:|:------|
|
|
89
|
-
| 123 | text
|
|
90
|
+
| 123 | text |`,
|
|
91
|
+
relativePathUrl: "https://example.com"
|
|
90
92
|
}
|
|
91
93
|
}, x = {
|
|
92
94
|
name: "Item Description Variant",
|
|
93
|
-
render: (e) => /* @__PURE__ */
|
|
94
|
-
|
|
95
|
+
render: (e) => /* @__PURE__ */ a(({ text: s }) => /* @__PURE__ */ a(
|
|
96
|
+
l,
|
|
95
97
|
{
|
|
96
98
|
...e,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
partUrl: (n) => `https://example.com/parts/${encodeURIComponent(n)}`,
|
|
100
|
+
relativePathUrl: "https://example.com",
|
|
101
|
+
validate: async (n) => {
|
|
102
|
+
if (await new Promise((d) => setTimeout(d, 50)), /^\d+$/.test(n)) return !0;
|
|
100
103
|
throw new Error("invalid");
|
|
101
104
|
},
|
|
102
105
|
debug: !0,
|
|
103
|
-
children:
|
|
106
|
+
children: s
|
|
104
107
|
}
|
|
105
108
|
), { text: `Kason 171 Latch
|
|
106
109
|
|
|
107
|
-
This fits part [171]
|
|
110
|
+
This fits part [171], an invalid token [bad], and the installation guide at [FAQ](/faq). Already linked should remain: [171](https://example.com/should-stay).
|
|
108
111
|
|
|
109
112
|
Another valid numeric: [172].` })
|
|
110
113
|
}, b = {
|
|
@@ -141,8 +144,8 @@ This block should not be transformed.
|
|
|
141
144
|
};
|
|
142
145
|
export {
|
|
143
146
|
b as Admonitions,
|
|
144
|
-
|
|
147
|
+
y as Basic,
|
|
145
148
|
x as ItemDescription,
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
v as Playground,
|
|
150
|
+
w as default
|
|
148
151
|
};
|
|
@@ -7,7 +7,7 @@ export type PreprocessedMarkdownResult = {
|
|
|
7
7
|
tokens: string[];
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Validates bare bracketed part tokens and rewrites relative markdown links using
|
|
11
|
+
* the configured URL targets.
|
|
12
12
|
*/
|
|
13
|
-
export declare function usePreprocessedMarkdown(input: string | null | undefined,
|
|
13
|
+
export declare function usePreprocessedMarkdown(input: string | null | undefined, partUrl?: LinkTarget, relativePathUrl?: LinkTarget, validate?: ValidateToken, debug?: boolean, batchValidate?: BatchValidateTokens): PreprocessedMarkdownResult;
|
|
@@ -1,86 +1,95 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
`, Math.max(0,
|
|
5
|
-
`,
|
|
6
|
-
return e.slice(
|
|
1
|
+
import { useState as N, useRef as L, useEffect as I, useMemo as x } from "react";
|
|
2
|
+
const H = /\[(.+?)\](?!\()/g, p = /\[([^\]]+?)\]\((\/[^)\s]*)\)/g, W = (e, n) => typeof e == "function" ? e(n) : e, X = (e, n) => typeof e == "function" ? e(n) : `${e}${n}`, E = (e, n) => {
|
|
3
|
+
const a = e.lastIndexOf(`
|
|
4
|
+
`, Math.max(0, n - 1)) + 1, l = e.indexOf(`
|
|
5
|
+
`, n), w = l === -1 ? e.length : l;
|
|
6
|
+
return e.slice(a, w).trimStart().startsWith(":::");
|
|
7
7
|
};
|
|
8
|
-
function
|
|
9
|
-
const [
|
|
10
|
-
|
|
8
|
+
function j(e, n, a, l, w = !1, y) {
|
|
9
|
+
const [q, S] = N(e ?? ""), [v, m] = N(!1), o = L(/* @__PURE__ */ new Map()), O = L(l), M = L(
|
|
10
|
+
y
|
|
11
11
|
);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, [
|
|
15
|
-
const
|
|
16
|
-
if (!e || !
|
|
17
|
-
const f = Array.from(e.matchAll(
|
|
18
|
-
(
|
|
19
|
-
).map((
|
|
12
|
+
I(() => {
|
|
13
|
+
O.current = l, M.current = y;
|
|
14
|
+
}, [l, y]);
|
|
15
|
+
const d = x(() => H, []), h = x(() => {
|
|
16
|
+
if (!e || !n) return [];
|
|
17
|
+
const f = Array.from(e.matchAll(d)).filter(
|
|
18
|
+
(u) => typeof u.index == "number" ? !E(e, u.index) : !0
|
|
19
|
+
).map((u) => u[1]);
|
|
20
20
|
return Array.from(new Set(f));
|
|
21
|
-
}, [e,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
}, [e, d, n]), T = x(() => {
|
|
22
|
+
if (!e || !a) return [];
|
|
23
|
+
const f = Array.from(e.matchAll(p)).filter(
|
|
24
|
+
(t) => typeof t.index == "number" ? !E(e, t.index) : !0
|
|
25
|
+
).map((t) => t[0]);
|
|
26
|
+
return Array.from(new Set(f));
|
|
27
|
+
}, [e, a]), _ = (f) => {
|
|
28
|
+
const t = f.split(/\r?\n/);
|
|
29
|
+
if (t.length === 0) return f;
|
|
30
|
+
const u = t[0];
|
|
31
|
+
return /^\s*#\s/.test(u) || (t[0] = `# ${u.trim()}`), t.join(`
|
|
26
32
|
`);
|
|
27
33
|
};
|
|
28
|
-
return
|
|
34
|
+
return I(() => {
|
|
29
35
|
if (!e) {
|
|
30
|
-
|
|
36
|
+
S(""), m(!1);
|
|
31
37
|
return;
|
|
32
38
|
}
|
|
33
|
-
if (!
|
|
34
|
-
|
|
39
|
+
if (!n && !a) {
|
|
40
|
+
S(e), m(!1);
|
|
35
41
|
return;
|
|
36
42
|
}
|
|
37
|
-
if (!
|
|
38
|
-
|
|
43
|
+
if (!h.length && !T.length) {
|
|
44
|
+
S(_(e)), m(!1);
|
|
39
45
|
return;
|
|
40
46
|
}
|
|
41
47
|
let f = !1;
|
|
42
48
|
m(!0);
|
|
43
|
-
const
|
|
49
|
+
const t = h.filter((g) => !o.current.has(g));
|
|
44
50
|
return (async () => {
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
51
|
+
if (t.length) {
|
|
52
|
+
const r = M.current, c = O.current;
|
|
53
|
+
if (r)
|
|
48
54
|
try {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const s = await r(t), i = s instanceof Set ? s : new Set(s);
|
|
56
|
+
t.forEach((R) => {
|
|
57
|
+
o.current.set(R, i.has(R));
|
|
52
58
|
});
|
|
53
59
|
} catch {
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
t.forEach((s) => {
|
|
61
|
+
o.current.set(s, !1);
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
|
-
else
|
|
59
|
-
|
|
64
|
+
else c ? (await Promise.allSettled(
|
|
65
|
+
t.map(async (i) => {
|
|
60
66
|
try {
|
|
61
|
-
await
|
|
67
|
+
await c(i), o.current.set(i, !0);
|
|
62
68
|
} catch {
|
|
63
|
-
|
|
69
|
+
o.current.set(i, !1);
|
|
64
70
|
}
|
|
65
71
|
})
|
|
66
|
-
)).forEach((i,
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
}) :
|
|
70
|
-
|
|
72
|
+
)).forEach((i, R) => {
|
|
73
|
+
const K = t[R];
|
|
74
|
+
o.current.has(K) || o.current.set(K, i.status === "fulfilled");
|
|
75
|
+
}) : t.forEach((s) => {
|
|
76
|
+
o.current.set(s, !0);
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
),
|
|
76
|
-
|
|
77
|
-
),
|
|
78
|
-
|
|
79
|
+
const g = new Set(
|
|
80
|
+
h.filter((r) => o.current.get(r) === !0)
|
|
81
|
+
), C = new Set(
|
|
82
|
+
h.filter((r) => o.current.get(r) === !1)
|
|
83
|
+
), A = e.replace(d, (r, c, s) => E(e, s) ? r : g.has(c) && n ? `**[${c}](${W(n, c)})**` : r), $ = a ? A.replace(
|
|
84
|
+
p,
|
|
85
|
+
(r, c, s, i) => E(A, i) ? r : `[${c}](${X(a, s)})`
|
|
86
|
+
) : A, D = w ? $.replace(d, (r, c, s) => E($, s) ? r : C.has(c) ? `[${c}]⚠️` : r) : $, G = _(D);
|
|
87
|
+
f || (S(G), m(!1));
|
|
79
88
|
})(), () => {
|
|
80
89
|
f = !0;
|
|
81
90
|
};
|
|
82
|
-
}, [e,
|
|
91
|
+
}, [e, h, T, w, n, a, d]), { output: q, loading: v, tokens: h };
|
|
83
92
|
}
|
|
84
93
|
export {
|
|
85
|
-
|
|
94
|
+
j as usePreprocessedMarkdown
|
|
86
95
|
};
|