@caseparts-org/caseblocks 0.0.200 → 0.0.201

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.
@@ -4,9 +4,10 @@ export type MarkdownProps = {
4
4
  children?: string | null;
5
5
  className?: string;
6
6
  components?: Components;
7
- url?: LinkTarget;
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, url, validate, batchValidate, debug, }: MarkdownProps): import("react/jsx-runtime").JSX.Element | null;
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
- url: r,
8683
- validate: i,
8684
- batchValidate: o,
8685
- debug: l = !1
8682
+ partUrl: r,
8683
+ relativePathUrl: i,
8684
+ validate: o,
8685
+ batchValidate: l,
8686
+ debug: a = !1
8686
8687
  }) {
8687
- const a = e ?? "", { output: u } = Ti(
8688
- a,
8688
+ const u = e ?? "", { output: s } = Ti(
8689
+ u,
8689
8690
  r,
8690
8691
  i,
8691
- l,
8692
- o
8692
+ o,
8693
+ a,
8694
+ l
8693
8695
  );
8694
- if (!a) return null;
8695
- const s = r ? {
8696
- a: ({ node: p, ...h }) => /* @__PURE__ */ je("a", { ...h, target: "_blank", rel: "noopener noreferrer" })
8697
- } : {}, f = t ? `${or.markdown} ${t}` : or.markdown, c = { ...Ef, ...s, ...n };
8698
- return /* @__PURE__ */ je("div", { className: f, children: /* @__PURE__ */ je(
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: c,
8703
- children: u
8704
+ components: p,
8705
+ children: s
8704
8706
  }
8705
8707
  ) });
8706
8708
  }
@@ -1,9 +1,9 @@
1
- import { jsx as n, jsxs as c } from "react/jsx-runtime";
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 s } from "./Markdown.js";
4
- const f = {
3
+ import { Markdown as l } from "./Markdown.js";
4
+ const w = {
5
5
  title: "Case Parts/Molecules/Markdown",
6
- component: s,
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] and an invalid token [bad].
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 u(e) {
19
- const [o, i] = m(e.children ?? r);
18
+ function h(e) {
19
+ const [i, o] = m(e.children ?? r);
20
20
  return p(() => {
21
- i(e.children ?? r);
21
+ o(e.children ?? r);
22
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(
23
+ /* @__PURE__ */ a("label", { style: { fontWeight: 600 }, children: "Edit Markdown (preprocess + admonitions live):" }),
24
+ /* @__PURE__ */ a(
25
25
  "textarea",
26
26
  {
27
- value: o,
28
- onChange: (t) => i(t.target.value),
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__ */ n(
34
- s,
33
+ /* @__PURE__ */ a(
34
+ l,
35
35
  {
36
36
  ...e,
37
- url: (t) => `https://example.com/parts/${encodeURIComponent(t)}`,
37
+ partUrl: (t) => `https://example.com/parts/${encodeURIComponent(t)}`,
38
+ relativePathUrl: "https://example.com",
38
39
  validate: async (t) => {
39
- if (await new Promise((a) => setTimeout(a, 50)), /^\d+$/.test(t)) return !0;
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: o
44
+ children: i
44
45
  }
45
46
  )
46
47
  ] });
47
48
  }
48
- const y = {
49
+ const v = {
49
50
  name: "Live Playground",
50
51
  args: {
51
52
  children: r
52
53
  },
53
- render: (e) => /* @__PURE__ */ n(u, { ...e })
54
- }, v = {
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__ */ n(({ text: l }) => /* @__PURE__ */ n(
94
- s,
95
+ render: (e) => /* @__PURE__ */ a(({ text: s }) => /* @__PURE__ */ a(
96
+ l,
95
97
  {
96
98
  ...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;
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: l
106
+ children: s
104
107
  }
105
108
  ), { text: `Kason 171 Latch
106
109
 
107
- This fits part [171] and an invalid token [bad]. Already linked should remain: [171](https://example.com/should-stay).
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
- v as Basic,
147
+ y as Basic,
145
148
  x as ItemDescription,
146
- y as Playground,
147
- f as default
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
- * Extracts bracketed tokens not already followed by parentheses, validates them, and
11
- * returns the input with validated tokens converted to markdown links.
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, url?: LinkTarget, validate?: ValidateToken, debug?: boolean, batchValidate?: BatchValidateTokens): PreprocessedMarkdownResult;
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 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(":::");
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 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
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
- 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]);
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, 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(`
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 v(() => {
34
+ return I(() => {
29
35
  if (!e) {
30
- w(""), m(!1);
36
+ S(""), m(!1);
31
37
  return;
32
38
  }
33
- if (!s) {
34
- w(e), m(!1);
39
+ if (!n && !a) {
40
+ S(e), m(!1);
35
41
  return;
36
42
  }
37
- if (!l.length) {
38
- w(R(e)), m(!1);
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 r = l.filter((y) => !c.current.has(y));
49
+ const t = h.filter((g) => !o.current.has(g));
44
50
  return (async () => {
45
- if (r.length) {
46
- const t = O.current, o = M.current;
47
- if (t)
51
+ if (t.length) {
52
+ const r = M.current, c = O.current;
53
+ if (r)
48
54
  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));
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
- r.forEach((n) => {
55
- c.current.set(n, !1);
60
+ t.forEach((s) => {
61
+ o.current.set(s, !1);
56
62
  });
57
63
  }
58
- else o ? (await Promise.allSettled(
59
- r.map(async (i) => {
64
+ else c ? (await Promise.allSettled(
65
+ t.map(async (i) => {
60
66
  try {
61
- await o(i), c.current.set(i, !0);
67
+ await c(i), o.current.set(i, !0);
62
68
  } catch {
63
- c.current.set(i, !1);
69
+ o.current.set(i, !1);
64
70
  }
65
71
  })
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);
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 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
+ 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, l, h, s, S]), { output: A, loading: L, tokens: l };
91
+ }, [e, h, T, w, n, a, d]), { output: q, loading: v, tokens: h };
83
92
  }
84
93
  export {
85
- N as usePreprocessedMarkdown
94
+ j as usePreprocessedMarkdown
86
95
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@caseparts-org/caseblocks",
3
3
  "private": false,
4
- "version": "0.0.200",
4
+ "version": "0.0.201",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",