@caseparts-org/caseblocks 0.0.127 → 0.0.128
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/Markdown.css +1 -1
- package/dist/atoms/Markdown/ItemDescriptionMarkdown.d.ts +8 -0
- package/dist/atoms/Markdown/ItemDescriptionMarkdown.js +10 -0
- package/dist/atoms/Markdown/Markdown.js +1 -1
- package/dist/atoms/Markdown/Markdown.stories.d.ts +1 -0
- package/dist/atoms/Markdown/Markdown.stories.js +26 -6
- package/dist/atoms/Markdown/useItemDescriptionMarkdown.d.ts +12 -0
- package/dist/atoms/Markdown/useItemDescriptionMarkdown.js +56 -0
- package/package.json +1 -1
package/dist/assets/Markdown.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._markdown_1ozv2_1{color:var(--text-text-primary);font-size:var(--font-size-sm);line-height:1.3}._markdown_1ozv2_1 h1,._markdown_1ozv2_1 h2,._markdown_1ozv2_1 h3,._markdown_1ozv2_1 h4,._markdown_1ozv2_1 h5,._markdown_1ozv2_1 h6{font-weight:var(--font-weight-semibold);line-height:1.3;margin:var(--spacing-spacing-sm) 0 var(--spacing-spacing-1xs)}._markdown_1ozv2_1 h1{font-size:var(--font-size-2xl)}._markdown_1ozv2_1 h2{font-size:var(--font-size-xl)}._markdown_1ozv2_1 h3{font-size:var(--font-size-lg)}._markdown_1ozv2_1 h4{font-size:var(--font-size-md)}._markdown_1ozv2_1 h5{font-size:var(--font-size-sm)}._markdown_1ozv2_1 h6{font-size:var(--font-size-xs)}._markdown_1ozv2_1 p{margin:var(--spacing-spacing-1xs) 0}._markdown_1ozv2_1 ul,._markdown_1ozv2_1 ol{margin:var(--spacing-spacing-1xs) 0 var(--spacing-spacing-1xs) var(--spacing-spacing-sm);padding:0}._markdown_1ozv2_1 li{margin:var(--spacing-spacing-3xs) 0}._markdown_1ozv2_1 a{color:var(--text-text-links);text-decoration:none}._markdown_1ozv2_1 a:hover,._markdown_1ozv2_1 a:focus{color:var(--text-text-links-hover-press)}._markdown_1ozv2_1 code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:.95em;background:var(--surface-surface-search-bar);padding:var(--spacing-spacing-4xs) var(--spacing-spacing-3xs);border-radius:var(--radius-radius-btn)}._markdown_1ozv2_1 pre{background:var(--surface-surface-search-bar);border-radius:var(--radius-radius-md);padding:var(--spacing-spacing-1xs);overflow:auto}._markdown_1ozv2_1 pre code{background:transparent;padding:0}._markdown_1ozv2_1 blockquote{margin:var(--spacing-spacing-1xs) 0;padding-left:var(--spacing-spacing-default);border-left:.1875rem solid var(--border-border-primary);color:var(--text-text-primary)}._markdown_1ozv2_1 hr{border:none;border-top:1px solid var(--border-border-primary);margin:var(--spacing-spacing-default) 0}._markdown_1ozv2_1 table{width:100%;border-collapse:collapse;margin:var(--spacing-spacing-1xs) 0}._markdown_1ozv2_1 th,._markdown_1ozv2_1 td{border:1px solid var(--border-border-primary);padding:var(--spacing-spacing-2xs);text-align:left}._markdown_1ozv2_1 thead th{background:var(--surface-surface-search-bar)}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LinkTarget, ValidateToken } from './useItemDescriptionMarkdown';
|
|
2
|
+
export type ValidatedMarkdownProps = {
|
|
3
|
+
children?: string | null;
|
|
4
|
+
url: LinkTarget;
|
|
5
|
+
validate: ValidateToken;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function ItemDescriptionMarkdown({ children, url, validate, className }: ValidatedMarkdownProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { Markdown as m } from "./Markdown.js";
|
|
3
|
+
import { useItemDescriptionMarkdown as p } from "./useItemDescriptionMarkdown.js";
|
|
4
|
+
function d({ children: o, url: r, validate: t, className: n }) {
|
|
5
|
+
const { output: i } = p(o ?? "", r, t);
|
|
6
|
+
return /* @__PURE__ */ e(m, { className: n, children: i });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
d as ItemDescriptionMarkdown
|
|
10
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { Markdown as a } from "./Markdown.js";
|
|
3
|
+
import { useItemDescriptionMarkdown as m } from "./useItemDescriptionMarkdown.js";
|
|
4
|
+
const g = {
|
|
3
5
|
title: "Case Parts/Atoms/Markdown",
|
|
4
|
-
component:
|
|
6
|
+
component: a,
|
|
5
7
|
parameters: { layout: "padded" },
|
|
6
8
|
tags: ["autodocs"]
|
|
7
|
-
},
|
|
9
|
+
}, x = {
|
|
8
10
|
args: {
|
|
9
11
|
children: `# Heading 1
|
|
10
12
|
|
|
@@ -41,8 +43,26 @@ export default greet;
|
|
|
41
43
|
|------:|:------|
|
|
42
44
|
| 123 | text |`
|
|
43
45
|
}
|
|
46
|
+
}, f = {
|
|
47
|
+
name: "Item Description Variant",
|
|
48
|
+
render: (o) => /* @__PURE__ */ t(({ text: n }) => {
|
|
49
|
+
const r = async (e) => {
|
|
50
|
+
if (await new Promise((l) => setTimeout(l, 50)), /^\d+$/.test(e)) return !0;
|
|
51
|
+
throw new Error("invalid");
|
|
52
|
+
}, { output: s, loading: i } = m(
|
|
53
|
+
n,
|
|
54
|
+
(e) => `https://example.com/parts/${encodeURIComponent(e)}`,
|
|
55
|
+
r
|
|
56
|
+
);
|
|
57
|
+
return /* @__PURE__ */ t(a, { ...o, children: i ? "Validating…" : s });
|
|
58
|
+
}, { text: `Kason 171 Latch
|
|
59
|
+
|
|
60
|
+
This fits part [171] and an invalid token [bad]. Already linked should remain: [171](https://example.com/should-stay).
|
|
61
|
+
|
|
62
|
+
Another valid numeric: [172].` })
|
|
44
63
|
};
|
|
45
64
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
x as Basic,
|
|
66
|
+
f as ItemDescription,
|
|
67
|
+
g as default
|
|
48
68
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ValidateToken = (_token: string) => Promise<unknown>;
|
|
2
|
+
export type LinkTarget = string | ((_token: string) => string);
|
|
3
|
+
export type UseValidatedLinksResult = {
|
|
4
|
+
output: string;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
tokens: string[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Extracts bracketed tokens not already followed by parentheses, validates them, and
|
|
10
|
+
* returns the input with validated tokens converted to markdown links.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useItemDescriptionMarkdown(input: string | null | undefined, url: LinkTarget, validate: ValidateToken): UseValidatedLinksResult;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState as p, useRef as H, useMemo as S, useEffect as q } from "react";
|
|
2
|
+
function E(r, o, $) {
|
|
3
|
+
const [A, d] = p(r ?? ""), [M, a] = p(!1), s = H(/* @__PURE__ */ new Map()), R = H($), u = S(() => /\[(.+?)\](?!\()/g, []), c = S(() => {
|
|
4
|
+
if (!r) return [];
|
|
5
|
+
const f = Array.from(r.matchAll(u)).map((w) => w[1]);
|
|
6
|
+
return Array.from(new Set(f));
|
|
7
|
+
}, [r, u]);
|
|
8
|
+
return q(() => {
|
|
9
|
+
if (!r) {
|
|
10
|
+
d(""), a(!1);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!c.length) {
|
|
14
|
+
d(((m) => {
|
|
15
|
+
const n = m.split(/\r?\n/);
|
|
16
|
+
if (n.length === 0) return m;
|
|
17
|
+
const g = n[0];
|
|
18
|
+
return /^\s*#\s/.test(g) || (n[0] = `# ${g.trim()}`), n.join(`
|
|
19
|
+
`);
|
|
20
|
+
})(r)), a(!1);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let f = !1;
|
|
24
|
+
a(!0);
|
|
25
|
+
const i = c.filter((l) => !s.current.has(l));
|
|
26
|
+
return (async () => {
|
|
27
|
+
i.length && (await Promise.allSettled(
|
|
28
|
+
i.map(async (e) => {
|
|
29
|
+
try {
|
|
30
|
+
await R.current(e), s.current.set(e, !0);
|
|
31
|
+
} catch {
|
|
32
|
+
s.current.set(e, !1);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
)).forEach((e, h) => {
|
|
36
|
+
const y = i[h];
|
|
37
|
+
s.current.has(y) || s.current.set(y, e.status === "fulfilled");
|
|
38
|
+
});
|
|
39
|
+
const l = new Set(
|
|
40
|
+
c.filter((t) => s.current.get(t) === !0)
|
|
41
|
+
), m = (t) => typeof o == "function" ? o(t) : o, n = r.replace(u, (t, e) => l.has(e) ? `[${e}](${m(e)})` : t), j = ((t) => {
|
|
42
|
+
const e = t.split(/\r?\n/);
|
|
43
|
+
if (e.length === 0) return t;
|
|
44
|
+
const h = e[0];
|
|
45
|
+
return /^\s*#\s/.test(h) || (e[0] = `# ${h.trim()}`), e.join(`
|
|
46
|
+
`);
|
|
47
|
+
})(n);
|
|
48
|
+
f || (d(j), a(!1));
|
|
49
|
+
})(), () => {
|
|
50
|
+
f = !0;
|
|
51
|
+
};
|
|
52
|
+
}, [r, c, o, u]), { output: A, loading: M, tokens: c };
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
E as useItemDescriptionMarkdown
|
|
56
|
+
};
|