@caseparts-org/caseblocks 0.0.193 → 0.0.194

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.
@@ -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: ValidateToken;
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,32 +1,39 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
- import { Markdown as d } from "./Markdown.js";
3
- import { usePreprocessedMarkdown as m } from "./usePreprocessedMarkdown.js";
4
- function k({
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
- debug: n,
8
- className: t,
9
- children: p
7
+ batchValidate: n,
8
+ debug: t,
9
+ className: p,
10
+ children: s
10
11
  }) {
11
- const { output: s } = m(p ?? "", o, e, n);
12
+ const { output: a } = c(
13
+ s ?? "",
14
+ o,
15
+ e,
16
+ t,
17
+ n
18
+ );
12
19
  return /* @__PURE__ */ r(
13
- d,
20
+ m,
14
21
  {
15
- className: t,
22
+ className: p,
16
23
  components: {
17
- a: ({ node: c, ...a }) => /* @__PURE__ */ r(
24
+ a: ({ node: f, ...d }) => /* @__PURE__ */ r(
18
25
  "a",
19
26
  {
20
- ...a,
27
+ ...d,
21
28
  target: "_blank",
22
29
  rel: "noopener noreferrer"
23
30
  }
24
31
  )
25
32
  },
26
- children: s
33
+ children: a
27
34
  }
28
35
  );
29
36
  }
30
37
  export {
31
- k as PreprocessedMarkdown
38
+ l as PreprocessedMarkdown
32
39
  };
@@ -5,3 +5,4 @@ export default meta;
5
5
  type Story = StoryObj<typeof meta>;
6
6
  export declare const Playground: Story;
7
7
  export declare const ControlsOnly: Story;
8
+ export declare const BatchValidate: Story;
@@ -1,17 +1,17 @@
1
- import { jsx as o, jsxs as i } from "react/jsx-runtime";
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 a } from "./PreprocessedMarkdown.js";
4
- const n = `Preprocessed Markdown
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.`, s = async (e) => {
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
- }, l = (e) => `https://example.com/items/${encodeURIComponent(e)}`, g = {
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: a,
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 u(e) {
26
- const [t, r] = c(e.children ?? n);
25
+ function h(e) {
26
+ const [t, a] = c(e.children ?? o);
27
27
  return m(() => {
28
- r(e.children ?? n);
28
+ a(e.children ?? o);
29
29
  }, [e.children]), /* @__PURE__ */ i("div", { style: { display: "grid", gap: 12 }, children: [
30
- /* @__PURE__ */ o("label", { style: { fontWeight: 600 }, children: "Edit Markdown (live):" }),
31
- /* @__PURE__ */ o(
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) => r(d.target.value),
35
+ onChange: (d) => a(d.target.value),
36
36
  rows: 8,
37
37
  style: { width: "100%", fontFamily: "monospace" }
38
38
  }
39
39
  ),
40
- /* @__PURE__ */ o(a, { ...e, children: t })
40
+ /* @__PURE__ */ n(s, { ...e, children: t })
41
41
  ] });
42
42
  }
43
- const k = {
43
+ const f = {
44
44
  args: {
45
- children: n,
46
- url: l,
47
- validate: s,
45
+ children: o,
46
+ url: r,
47
+ validate: l,
48
48
  debug: !0
49
49
  },
50
- render: (e) => /* @__PURE__ */ o(u, { ...e })
51
- }, f = {
50
+ render: (e) => /* @__PURE__ */ n(h, { ...e })
51
+ }, x = {
52
52
  name: "With Controls",
53
53
  args: {
54
- children: n,
55
- url: l,
56
- validate: s,
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
- f as ControlsOnly,
62
- k as Playground,
63
- g as default
69
+ y as BatchValidate,
70
+ x as ControlsOnly,
71
+ f as Playground,
72
+ k as default
64
73
  };
@@ -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: ValidateToken, debug?: boolean): PreprocessedMarkdownResult;
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 w, useRef as S, useMemo as y, useEffect as P } from "react";
2
- function C(s, l, $, d = !1) {
3
- const [v, i] = w(s ?? ""), [A, u] = w(!1), n = S(/* @__PURE__ */ new Map()), M = S($), o = y(() => /\[(.+?)\](?!\()/g, []), a = y(() => {
4
- if (!s) return [];
5
- const c = Array.from(s.matchAll(o)).map((f) => f[1]);
6
- return Array.from(new Set(c));
7
- }, [s, o]), m = (c) => {
8
- const r = c.split(/\r?\n/);
9
- if (r.length === 0) return c;
10
- const f = r[0];
11
- return /^\s*#\s/.test(f) || (r[0] = `# ${f.trim()}`), r.join(`
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 P(() => {
15
- if (!s) {
16
- i(""), u(!1);
20
+ return v(() => {
21
+ if (!n) {
22
+ d(""), h(!1);
17
23
  return;
18
24
  }
19
- if (!a.length) {
20
- i(m(s)), u(!1);
25
+ if (!f.length) {
26
+ d($(n)), h(!1);
21
27
  return;
22
28
  }
23
- let c = !1;
24
- u(!0);
25
- const r = a.filter((h) => !n.current.has(h));
29
+ let o = !1;
30
+ h(!0);
31
+ const e = f.filter((g) => !r.current.has(g));
26
32
  return (async () => {
27
- r.length && (await Promise.allSettled(
28
- r.map(async (e) => {
33
+ if (e.length) {
34
+ const t = R.current, s = E.current;
35
+ if (t)
29
36
  try {
30
- await M.current(e), n.current.set(e, !0);
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
- n.current.set(e, !1);
42
+ e.forEach((c) => {
43
+ r.current.set(c, !1);
44
+ });
33
45
  }
34
- })
35
- )).forEach((e, H) => {
36
- const g = r[H];
37
- n.current.has(g) || n.current.set(g, e.status === "fulfilled");
38
- });
39
- const h = new Set(
40
- a.filter((t) => n.current.get(t) === !0)
41
- ), R = new Set(
42
- a.filter((t) => n.current.get(t) === !1)
43
- ), q = (t) => typeof l == "function" ? l(t) : l, p = s.replace(o, (t, e) => h.has(e) ? `**[${e}](${q(e)})**` : t), x = d ? p.replace(o, (t, e) => R.has(e) ? `[${e}]⚠️` : t) : p, E = m(x);
44
- c || (i(E), u(!1));
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
- c = !0;
68
+ o = !0;
47
69
  };
48
- }, [s, a, d, l, o]), { output: v, loading: A, tokens: a };
70
+ }, [n, f, y, i, u]), { output: H, loading: P, tokens: f };
49
71
  }
50
72
  export {
51
- C as usePreprocessedMarkdown
73
+ k as usePreprocessedMarkdown
52
74
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@caseparts-org/caseblocks",
3
3
  "private": false,
4
- "version": "0.0.193",
4
+ "version": "0.0.194",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",