wimui 0.42.0 → 0.44.0

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.
Files changed (53) hide show
  1. package/README.ja.md +3 -2
  2. package/README.md +3 -2
  3. package/dist/components/data-display/PivotTable/PivotTable.cjs +2 -0
  4. package/dist/components/data-display/PivotTable/PivotTable.d.ts +76 -0
  5. package/dist/components/data-display/PivotTable/PivotTable.js +104 -0
  6. package/dist/components/data-display/PivotTable/layoutPivot.cjs +2 -0
  7. package/dist/components/data-display/PivotTable/layoutPivot.d.ts +62 -0
  8. package/dist/components/data-display/PivotTable/layoutPivot.js +67 -0
  9. package/dist/components/data-display/PivotTable/pivot-table.module.cjs +2 -0
  10. package/dist/components/data-display/PivotTable/pivot-table.module.js +19 -0
  11. package/dist/components/feedback/Snackbar/snackbar.module.cjs +1 -1
  12. package/dist/components/feedback/Snackbar/snackbar.module.js +7 -7
  13. package/dist/components/form/ImageCropper/ImageCropper.cjs +1 -1
  14. package/dist/components/form/ImageCropper/ImageCropper.js +10 -10
  15. package/dist/components/form/RichTextEditor/RichTextEditor.cjs +1 -1
  16. package/dist/components/form/RichTextEditor/RichTextEditor.d.ts +36 -6
  17. package/dist/components/form/RichTextEditor/RichTextEditor.js +486 -307
  18. package/dist/components/form/RichTextEditor/markdown.cjs +3 -0
  19. package/dist/components/form/RichTextEditor/markdown.d.ts +19 -0
  20. package/dist/components/form/RichTextEditor/markdown.js +63 -0
  21. package/dist/components/form/RichTextEditor/rich-text-editor.module.cjs +1 -1
  22. package/dist/components/form/RichTextEditor/rich-text-editor.module.js +7 -3
  23. package/dist/components/form/RichTextEditor/safeUrl.cjs +2 -0
  24. package/dist/components/form/RichTextEditor/safeUrl.d.ts +4 -0
  25. package/dist/components/form/RichTextEditor/safeUrl.js +18 -0
  26. package/dist/data-display-core.d.ts +1 -0
  27. package/dist/data-display.cjs +1 -1
  28. package/dist/data-display.js +17 -16
  29. package/dist/form/rich-text-editor.cjs +2 -0
  30. package/dist/form/rich-text-editor.d.ts +1 -0
  31. package/dist/form/rich-text-editor.js +3 -0
  32. package/dist/form.cjs +1 -1
  33. package/dist/form.d.ts +0 -1
  34. package/dist/form.js +28 -29
  35. package/dist/i18n/generated/keys.d.ts +1 -1
  36. package/dist/i18n/generated/resources.cjs +1 -1
  37. package/dist/i18n/generated/resources.js +31 -4
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.js +85 -85
  40. package/dist/llms-full.txt +23 -5
  41. package/dist/llms.txt +2 -1
  42. package/dist/locales/en/components.json +13 -1
  43. package/dist/locales/ja/components.json +13 -1
  44. package/dist/locales/pt/components.json +13 -1
  45. package/dist/overlay.cjs +1 -1
  46. package/dist/overlay.js +3 -3
  47. package/dist/styles.css +1 -1
  48. package/dist/wimui.umd.css +1 -1
  49. package/dist/wimui.umd.js +5 -5
  50. package/package.json +66 -1
  51. package/dist/components/form/RichTextEditor/commands.cjs +0 -2
  52. package/dist/components/form/RichTextEditor/commands.d.ts +0 -49
  53. package/dist/components/form/RichTextEditor/commands.js +0 -244
package/README.ja.md CHANGED
@@ -298,15 +298,16 @@ import { Button } from "wimui/form"; // カテゴリ別サブパス
298
298
 
299
299
  以下のコンポーネントを使う場合のみ、対応するサブパスから import し、peer を追加してください。使わない場合は不要です。
300
300
 
301
- peer 依存コンポーネントは**コンポーネント別の専用サブパス**を持ち、名前で必要 peer が分かります。カテゴリバレル(`wimui/data-display` / `wimui/ai`)は peer-free です。
301
+ peer 依存コンポーネントは**コンポーネント別の専用サブパス**を持ち、名前で必要 peer が分かります。カテゴリバレル(`wimui/form` / `wimui/data-display` / `wimui/ai`)は peer-free です。
302
302
 
303
303
  | コンポーネント | import | 必要なパッケージ |
304
304
  |---|---|---|
305
+ | RichTextEditor | `wimui/form/rich-text-editor` | `@tiptap/core` `@tiptap/pm` `@tiptap/react` `@tiptap/starter-kit` `@tiptap/extensions` `@tiptap/extension-image` `@tiptap/markdown` (`^3`) `marked` (`^17`) |
305
306
  | AreaChart, BarChart 等 | `wimui/charts` | `recharts` |
306
307
  | Markdown | `wimui/data-display/markdown` | `react-markdown` `remark-gfm` |
307
308
  | QRCode | `wimui/data-display/qr-code` | `qrcode.react` |
308
309
  | NodeGraph | `wimui/data-display/node-graph` | `@xyflow/react` |
309
- | ScheduleView | `wimui/data-display/schedule-view` | `@fullcalendar/core` `@fullcalendar/react` `@fullcalendar/daygrid` `@fullcalendar/timegrid` `@fullcalendar/interaction` |
310
+ | ScheduleView | `wimui/data-display/schedule-view` | `@fullcalendar/core` `@fullcalendar/react` `@fullcalendar/daygrid` `@fullcalendar/timegrid` `@fullcalendar/interaction`(`^6`。@6 を付けて入れてください。FullCalendar 7 には対応しておらず、pnpm は版を指定しないと core と react の最新(7)を入れます) |
310
311
  | JsonDiffViewer | `wimui/data-display/json-diff-viewer` | `diff` |
311
312
  | StreamingText | `wimui/ai/streaming-text` | `react-markdown` `remark-gfm` |
312
313
  | MarkdownRenderer | `wimui/ai/markdown-renderer` | `react-markdown` `remark-gfm` |
package/README.md CHANGED
@@ -296,15 +296,16 @@ Only for intentional API changes, update the snapshot with `npm run check:api:up
296
296
 
297
297
  Only when you use the components below, import from the corresponding subpath and add the peer. If you don't use them, you don't need them.
298
298
 
299
- Each peer-dependent component has its **own subpath** whose name documents its peer, so the category barrels (`wimui/data-display`, `wimui/ai`) stay peer-free.
299
+ Each peer-dependent component has its **own subpath** whose name documents its peer, so the category barrels (`wimui/form`, `wimui/data-display`, `wimui/ai`) stay peer-free.
300
300
 
301
301
  | Component | import | Required packages |
302
302
  |---|---|---|
303
+ | RichTextEditor | `wimui/form/rich-text-editor` | `@tiptap/core` `@tiptap/pm` `@tiptap/react` `@tiptap/starter-kit` `@tiptap/extensions` `@tiptap/extension-image` `@tiptap/markdown` (`^3`) `marked` (`^17`) |
303
304
  | AreaChart, BarChart, etc. | `wimui/charts` | `recharts` |
304
305
  | Markdown | `wimui/data-display/markdown` | `react-markdown` `remark-gfm` |
305
306
  | QRCode | `wimui/data-display/qr-code` | `qrcode.react` |
306
307
  | NodeGraph | `wimui/data-display/node-graph` | `@xyflow/react` |
307
- | ScheduleView | `wimui/data-display/schedule-view` | `@fullcalendar/core` `@fullcalendar/react` `@fullcalendar/daygrid` `@fullcalendar/timegrid` `@fullcalendar/interaction` |
308
+ | ScheduleView | `wimui/data-display/schedule-view` | `@fullcalendar/core` `@fullcalendar/react` `@fullcalendar/daygrid` `@fullcalendar/timegrid` `@fullcalendar/interaction` (`^6`. Install them with @6: FullCalendar 7 is not supported, and pnpm installs the latest core and react (7) unless you pin them) |
308
309
  | JsonDiffViewer | `wimui/data-display/json-diff-viewer` | `diff` |
309
310
  | StreamingText | `wimui/ai/streaming-text` | `react-markdown` `remark-gfm` |
310
311
  | MarkdownRenderer | `wimui/ai/markdown-renderer` | `react-markdown` `remark-gfm` |
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../hooks/useMergedRef.cjs"),r=require("../Table/Table.cjs"),i=require("./layoutPivot.cjs"),a=require("./pivot-table.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("classnames");s=e.__toESM(s,1);let c=require("react/jsx-runtime");var l=o.default.forwardRef(({rows:e,columns:l,getValue:u,rowAxisLabel:d,caption:f,columnSubtotals:p=!1,totalRow:m=!1,totalColumn:h=!1,labels:g,className:_,...v},y)=>{let{t:b}=t.useWimTranslation(`components`),x=o.default.useId(),S=g?.total??b(`pivottable.total`),C=(0,o.useMemo)(()=>i.layoutPivotColumns(l,{subtotals:p,total:h}),[l,p,h]),w=(0,o.useMemo)(()=>i.layoutPivotRows(e),[e]),T=d!=null&&d!==!1,E=`${x}corner`,D=e=>`${x}c${e}`,O=e=>`${x}r${e}`,k=`${x}total`,A=(0,o.useMemo)(()=>C.columns.map(e=>e.headerIds.map(e=>`${x}c${e}`).join(` `)),[C,x]),j=o.default.useRef(null),M=o.default.useRef(null),[N,P]=o.default.useState(!1);o.default.useLayoutEffect(()=>{let e=j.current,t=M.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=()=>P(e.scrollWidth>e.clientWidth);n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[]);let F=n.useMergedRef(y,M),I=`${x}caption`,L=f?{"aria-labelledby":I}:v[`aria-label`]?{"aria-label":v[`aria-label`]}:v[`aria-labelledby`]?{"aria-labelledby":v[`aria-labelledby`]}:null;return(0,c.jsx)(`div`,{ref:j,className:a.default.scroller,tabIndex:N?0:void 0,...N&&L?{role:`region`,...L}:null,children:(0,c.jsxs)(`table`,{ref:F,className:(0,s.default)(`wim-pivot-table`,a.default.root,_),...v,children:[f&&(0,c.jsx)(`caption`,{id:I,className:a.default.caption,children:f}),(0,c.jsx)(`colgroup`,{}),C.groupSpans.map((e,t)=>(0,c.jsx)(`colgroup`,{span:e},t)),(0,c.jsx)(r.Table.Header,{children:C.headerRows.map((e,t)=>(0,c.jsxs)(`tr`,{children:[t===0&&(T?(0,c.jsx)(`th`,{id:E,scope:`col`,rowSpan:C.depth,className:(0,s.default)(a.default.columnHeader,a.default.corner,a.default.bottom),children:d}):(0,c.jsx)(`td`,{rowSpan:C.depth,className:(0,s.default)(a.default.columnHeader,a.default.bottom)})),e.map(e=>(0,c.jsx)(`th`,{id:D(e.id),scope:e.kind===`group`&&e.topLevel?`colgroup`:`col`,colSpan:e.colSpan>1?e.colSpan:void 0,rowSpan:e.rowSpan>1?e.rowSpan:void 0,className:(0,s.default)(a.default.columnHeader,e.kind===`group`&&a.default.group,e.reachesBottom&&a.default.bottom,e.startsGroup&&a.default.groupStart),children:e.kind===`group`||e.kind===`leaf`?e.node?.label:S},e.id))]},t))}),(0,c.jsx)(r.Table.Body,{children:w.map((e,t)=>{let n=[...e.ancestors.map(O),O(t)].join(` `),i=[...T?[E]:[],...e.ancestors.map(O)].join(` `);return(0,c.jsxs)(r.Table.Row,{className:(0,s.default)(e.hasChildren&&a.default.groupRow),children:[(0,c.jsx)(`th`,{id:O(t),scope:`row`,headers:i||void 0,className:a.default.rowHeader,style:{"--wim-pivot-table-depth":e.depth},children:e.node.label}),C.columns.map((t,i)=>(0,c.jsx)(r.Table.Cell,{headers:`${n} ${A[i]}`,className:(0,s.default)(a.default.value,t.kind!==`leaf`&&a.default.aggregate,t.startsGroup&&a.default.groupStart),children:u(e.key,t.key)},i))]},e.key)})}),m&&(0,c.jsx)(r.Table.Footer,{children:(0,c.jsxs)(r.Table.Row,{className:a.default.totalRow,children:[(0,c.jsx)(`th`,{id:k,scope:`row`,headers:T?E:void 0,className:a.default.rowHeader,children:S}),C.columns.map((e,t)=>(0,c.jsx)(r.Table.Cell,{headers:`${k} ${A[t]}`,className:(0,s.default)(a.default.value,e.startsGroup&&a.default.groupStart),children:u(null,e.key)},t))]})})]})})});l.displayName=`PivotTable`,exports.PivotTable=l;
@@ -0,0 +1,76 @@
1
+ import { default as React } from 'react';
2
+ export type PivotTableAxisNode = {
3
+ /** Unique within its axis. Passed back to `getValue`. */
4
+ key: string;
5
+ /** Heading shown for this row or column. */
6
+ label: React.ReactNode;
7
+ /** Nested headings. A node with children is a group; its own value is the subtotal. */
8
+ children?: PivotTableAxisNode[];
9
+ };
10
+ export type PivotTableLabels = {
11
+ /** Heading of the grand total row / column and of each subtotal column. */
12
+ total?: string;
13
+ };
14
+ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "children"> & {
15
+ /** The row axis as a tree. Groups are drawn as an outline: one indented row per node. */
16
+ rows: PivotTableAxisNode[];
17
+ /** The column axis as a tree. Groups become headings that span their columns. */
18
+ columns: PivotTableAxisNode[];
19
+ /**
20
+ * Returns the content of one cell. The component does not aggregate: a group key asks
21
+ * for that group's subtotal and `null` asks for the grand total of that axis. Return
22
+ * `null` or `undefined` for an empty cell.
23
+ */
24
+ getValue: (rowKey: string | null, columnKey: string | null) => React.ReactNode;
25
+ /** Heading of the row axis, shown in the top-left corner. */
26
+ rowAxisLabel?: React.ReactNode;
27
+ /** Visible title of the table, also its accessible name. */
28
+ caption?: React.ReactNode;
29
+ /** Adds a subtotal column after the columns of each column group. */
30
+ columnSubtotals?: boolean;
31
+ /** Adds a grand total row at the bottom. */
32
+ totalRow?: boolean;
33
+ /** Adds a grand total column at the right edge. */
34
+ totalColumn?: boolean;
35
+ /** Text of the total headings, for when the built-in translations do not fit. */
36
+ labels?: PivotTableLabels;
37
+ };
38
+ /**
39
+ * PivotTable — draws already aggregated data as a table with multi-level row and column
40
+ * headings, subtotals and grand totals. It only draws: grouping and summing stay with the
41
+ * caller, who answers `getValue(rowKey, columnKey)` for every cell.
42
+ *
43
+ * Every cell lists the headings it belongs to in its `headers` attribute, so a screen
44
+ * reader announces the full row path and column path of a value.
45
+ *
46
+ * The shell is its own (a sideways scroller and a plain `table`); rows and value cells are
47
+ * `Table.Row` / `Table.Cell`, so spacing and density follow `Table`.
48
+ *
49
+ * Composition Contract:
50
+ * - Managed by: App consumption
51
+ * - Scroll lock: No (the table scrolls sideways inside its own box when it is wider than it)
52
+ */
53
+ export declare const PivotTable: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, "ref">, "children"> & {
54
+ /** The row axis as a tree. Groups are drawn as an outline: one indented row per node. */
55
+ rows: PivotTableAxisNode[];
56
+ /** The column axis as a tree. Groups become headings that span their columns. */
57
+ columns: PivotTableAxisNode[];
58
+ /**
59
+ * Returns the content of one cell. The component does not aggregate: a group key asks
60
+ * for that group's subtotal and `null` asks for the grand total of that axis. Return
61
+ * `null` or `undefined` for an empty cell.
62
+ */
63
+ getValue: (rowKey: string | null, columnKey: string | null) => React.ReactNode;
64
+ /** Heading of the row axis, shown in the top-left corner. */
65
+ rowAxisLabel?: React.ReactNode;
66
+ /** Visible title of the table, also its accessible name. */
67
+ caption?: React.ReactNode;
68
+ /** Adds a subtotal column after the columns of each column group. */
69
+ columnSubtotals?: boolean;
70
+ /** Adds a grand total row at the bottom. */
71
+ totalRow?: boolean;
72
+ /** Adds a grand total column at the right edge. */
73
+ totalColumn?: boolean;
74
+ /** Text of the total headings, for when the built-in translations do not fit. */
75
+ labels?: PivotTableLabels;
76
+ } & React.RefAttributes<HTMLTableElement>>;
@@ -0,0 +1,104 @@
1
+ "use client";
2
+ import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
3
+ import { useMergedRef as t } from "../../../hooks/useMergedRef.js";
4
+ import { Table as n } from "../Table/Table.js";
5
+ import { layoutPivotColumns as r, layoutPivotRows as i } from "./layoutPivot.js";
6
+ import a from "./pivot-table.module.js";
7
+ import o, { useMemo as s } from "react";
8
+ import c from "classnames";
9
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
10
+ //#region src/components/data-display/PivotTable/PivotTable.tsx
11
+ var d = o.forwardRef(({ rows: d, columns: f, getValue: p, rowAxisLabel: m, caption: h, columnSubtotals: g = !1, totalRow: _ = !1, totalColumn: v = !1, labels: y, className: b, ...x }, S) => {
12
+ let { t: C } = e("components"), w = o.useId(), T = y?.total ?? C("pivottable.total"), E = s(() => r(f, {
13
+ subtotals: g,
14
+ total: v
15
+ }), [
16
+ f,
17
+ g,
18
+ v
19
+ ]), D = s(() => i(d), [d]), O = m != null && m !== !1, k = `${w}corner`, A = (e) => `${w}c${e}`, j = (e) => `${w}r${e}`, M = `${w}total`, N = s(() => E.columns.map((e) => e.headerIds.map((e) => `${w}c${e}`).join(" ")), [E, w]), P = o.useRef(null), F = o.useRef(null), [I, L] = o.useState(!1);
20
+ o.useLayoutEffect(() => {
21
+ let e = P.current, t = F.current;
22
+ if (!e || !t || typeof ResizeObserver > "u") return;
23
+ let n = () => L(e.scrollWidth > e.clientWidth);
24
+ n();
25
+ let r = new ResizeObserver(n);
26
+ return r.observe(e), r.observe(t), () => r.disconnect();
27
+ }, []);
28
+ let R = t(S, F), z = `${w}caption`, B = h ? { "aria-labelledby": z } : x["aria-label"] ? { "aria-label": x["aria-label"] } : x["aria-labelledby"] ? { "aria-labelledby": x["aria-labelledby"] } : null;
29
+ return /* @__PURE__ */ l("div", {
30
+ ref: P,
31
+ className: a.scroller,
32
+ tabIndex: I ? 0 : void 0,
33
+ ...I && B ? {
34
+ role: "region",
35
+ ...B
36
+ } : null,
37
+ children: /* @__PURE__ */ u("table", {
38
+ ref: R,
39
+ className: c("wim-pivot-table", a.root, b),
40
+ ...x,
41
+ children: [
42
+ h && /* @__PURE__ */ l("caption", {
43
+ id: z,
44
+ className: a.caption,
45
+ children: h
46
+ }),
47
+ /* @__PURE__ */ l("colgroup", {}),
48
+ E.groupSpans.map((e, t) => /* @__PURE__ */ l("colgroup", { span: e }, t)),
49
+ /* @__PURE__ */ l(n.Header, { children: E.headerRows.map((e, t) => /* @__PURE__ */ u("tr", { children: [t === 0 && (O ? /* @__PURE__ */ l("th", {
50
+ id: k,
51
+ scope: "col",
52
+ rowSpan: E.depth,
53
+ className: c(a.columnHeader, a.corner, a.bottom),
54
+ children: m
55
+ }) : /* @__PURE__ */ l("td", {
56
+ rowSpan: E.depth,
57
+ className: c(a.columnHeader, a.bottom)
58
+ })), e.map((e) => /* @__PURE__ */ l("th", {
59
+ id: A(e.id),
60
+ scope: e.kind === "group" && e.topLevel ? "colgroup" : "col",
61
+ colSpan: e.colSpan > 1 ? e.colSpan : void 0,
62
+ rowSpan: e.rowSpan > 1 ? e.rowSpan : void 0,
63
+ className: c(a.columnHeader, e.kind === "group" && a.group, e.reachesBottom && a.bottom, e.startsGroup && a.groupStart),
64
+ children: e.kind === "group" || e.kind === "leaf" ? e.node?.label : T
65
+ }, e.id))] }, t)) }),
66
+ /* @__PURE__ */ l(n.Body, { children: D.map((e, t) => {
67
+ let r = [...e.ancestors.map(j), j(t)].join(" "), i = [...O ? [k] : [], ...e.ancestors.map(j)].join(" ");
68
+ return /* @__PURE__ */ u(n.Row, {
69
+ className: c(e.hasChildren && a.groupRow),
70
+ children: [/* @__PURE__ */ l("th", {
71
+ id: j(t),
72
+ scope: "row",
73
+ headers: i || void 0,
74
+ className: a.rowHeader,
75
+ style: { "--wim-pivot-table-depth": e.depth },
76
+ children: e.node.label
77
+ }), E.columns.map((t, i) => /* @__PURE__ */ l(n.Cell, {
78
+ headers: `${r} ${N[i]}`,
79
+ className: c(a.value, t.kind !== "leaf" && a.aggregate, t.startsGroup && a.groupStart),
80
+ children: p(e.key, t.key)
81
+ }, i))]
82
+ }, e.key);
83
+ }) }),
84
+ _ && /* @__PURE__ */ l(n.Footer, { children: /* @__PURE__ */ u(n.Row, {
85
+ className: a.totalRow,
86
+ children: [/* @__PURE__ */ l("th", {
87
+ id: M,
88
+ scope: "row",
89
+ headers: O ? k : void 0,
90
+ className: a.rowHeader,
91
+ children: T
92
+ }), E.columns.map((e, t) => /* @__PURE__ */ l(n.Cell, {
93
+ headers: `${M} ${N[t]}`,
94
+ className: c(a.value, e.startsGroup && a.groupStart),
95
+ children: p(null, e.key)
96
+ }, t))]
97
+ }) })
98
+ ]
99
+ })
100
+ });
101
+ });
102
+ d.displayName = "PivotTable";
103
+ //#endregion
104
+ export { d as PivotTable };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var e=e=>!!e.children?.length,t=n=>n.reduce((n,r)=>Math.max(n,1+(e(r)?t(r.children):0)),0);function n(n,r={}){let i=Math.max(1,t(n)),a=Array.from({length:i},()=>[]),o=[],s=[],c=0,l=(e,t,n,r,s,l)=>{let u=c++,d=e?.key??null;a[n].push({id:u,key:d,node:e,kind:t,colSpan:1,rowSpan:i-n,reachesBottom:!0,startsGroup:l,topLevel:s}),o.push({key:d,kind:t,headerIds:[...r,u],startsGroup:l})},u=(t,n,i,o)=>{let s=n===0;if(!e(t))return l(t,`leaf`,n,i,s,o),1;let d={id:c++,key:t.key,node:t,kind:`group`,colSpan:0,rowSpan:1,reachesBottom:!1,startsGroup:o,topLevel:s};a[n].push(d);let f=[...i,d.id],p=0;return t.children.forEach((e,t)=>{p+=u(e,n+1,f,o&&t===0)}),r.subtotals&&(l(t,`subtotal`,n+1,f,!1,!1),p+=1),d.colSpan=p,p};for(let e of n)s.push(u(e,0,[],!0));return r.total&&(l(null,`total`,0,[],!0,!0),s.push(1)),{headerRows:a,columns:o,depth:i,groupSpans:s}}function r(t){let n=[],r=(t,i,a)=>{for(let o of t){let t=n.length,s=e(o);n.push({key:o.key,node:o,depth:i,hasChildren:s,ancestors:a}),s&&r(o.children,i+1,[...a,t])}};return r(t,0,[]),n}exports.layoutPivotColumns=n,exports.layoutPivotRows=r;
@@ -0,0 +1,62 @@
1
+ /** 軸の木の 1 節。ラベルなど、配置の計算に関係しない項目は型引数の側が持つ。 */
2
+ export type PivotAxisInput = {
3
+ key: string;
4
+ children?: PivotAxisInput[];
5
+ };
6
+ export type PivotHeaderKind = "group" | "leaf" | "subtotal" | "total";
7
+ /** 列見出しの 1 セル。`id` は軸の中で一意な連番で、`headers` 属性の組み立てに使う。 */
8
+ export type PivotHeaderCell<T extends PivotAxisInput = PivotAxisInput> = {
9
+ id: number;
10
+ /** 軸のキー。総計の列は `null`。小計の列は、まとめているグループのキー。 */
11
+ key: string | null;
12
+ /** 元の節。総計の列は `null`。小計の列は、まとめているグループの節。 */
13
+ node: T | null;
14
+ kind: PivotHeaderKind;
15
+ colSpan: number;
16
+ rowSpan: number;
17
+ /** 見出しの最下段に届いているか(本文との境界の帯を描くセル)。 */
18
+ reachesBottom: boolean;
19
+ /** 最上位の節の先頭の列から始まるか(グループの境目)。 */
20
+ startsGroup: boolean;
21
+ /** 最上位の節か。`colgroup` と 1 対 1 に対応するのはこの段だけ。 */
22
+ topLevel: boolean;
23
+ };
24
+ /** 値を持つ 1 列。 */
25
+ export type PivotColumn = {
26
+ /** `getValue` に渡す列のキー。総計の列は `null`。 */
27
+ key: string | null;
28
+ kind: Exclude<PivotHeaderKind, "group">;
29
+ /** この列に掛かる見出しのセルの `id`(上の段から順)。 */
30
+ headerIds: number[];
31
+ startsGroup: boolean;
32
+ };
33
+ export type PivotColumnLayout<T extends PivotAxisInput = PivotAxisInput> = {
34
+ /** 見出しの段ごとのセル(上の段から順・各段は左から順)。 */
35
+ headerRows: PivotHeaderCell<T>[][];
36
+ columns: PivotColumn[];
37
+ /** 見出しの段の数(列の軸が空でも 1)。 */
38
+ depth: number;
39
+ /** 最上位の節ごとの列の数。`colgroup` の `span` に使う。 */
40
+ groupSpans: number[];
41
+ };
42
+ export type PivotRow<T extends PivotAxisInput = PivotAxisInput> = {
43
+ key: string;
44
+ node: T;
45
+ depth: number;
46
+ hasChildren: boolean;
47
+ /** 祖先の行の番号(返り値の配列の中の位置。根から順)。 */
48
+ ancestors: number[];
49
+ };
50
+ /**
51
+ * 列の軸の木を、見出しの段(`colSpan` / `rowSpan` 付き)と値の列の並びにする。
52
+ *
53
+ * - 葉は、自分の段から最下段まで縦に伸びる(木の深さが揃っていなくても段がずれない)
54
+ * - `subtotals` を付けると、グループごとに子の後ろへ小計の列を 1 本足す
55
+ * - `total` を付けると、右端に総計の列を 1 本足す
56
+ */
57
+ export declare function layoutPivotColumns<T extends PivotAxisInput>(nodes: T[], options?: {
58
+ subtotals?: boolean;
59
+ total?: boolean;
60
+ }): PivotColumnLayout<T>;
61
+ /** 行の軸の木を、深さ優先で 1 行ずつに並べる(アウトライン形式: グループも 1 行を持つ)。 */
62
+ export declare function layoutPivotRows<T extends PivotAxisInput>(nodes: T[]): PivotRow<T>[];
@@ -0,0 +1,67 @@
1
+ "use client";
2
+ //#region src/components/data-display/PivotTable/layoutPivot.ts
3
+ var e = (e) => !!e.children?.length, t = (n) => n.reduce((n, r) => Math.max(n, 1 + (e(r) ? t(r.children) : 0)), 0);
4
+ function n(n, r = {}) {
5
+ let i = Math.max(1, t(n)), a = Array.from({ length: i }, () => []), o = [], s = [], c = 0, l = (e, t, n, r, s, l) => {
6
+ let u = c++, d = e?.key ?? null;
7
+ a[n].push({
8
+ id: u,
9
+ key: d,
10
+ node: e,
11
+ kind: t,
12
+ colSpan: 1,
13
+ rowSpan: i - n,
14
+ reachesBottom: !0,
15
+ startsGroup: l,
16
+ topLevel: s
17
+ }), o.push({
18
+ key: d,
19
+ kind: t,
20
+ headerIds: [...r, u],
21
+ startsGroup: l
22
+ });
23
+ }, u = (t, n, i, o) => {
24
+ let s = n === 0;
25
+ if (!e(t)) return l(t, "leaf", n, i, s, o), 1;
26
+ let d = {
27
+ id: c++,
28
+ key: t.key,
29
+ node: t,
30
+ kind: "group",
31
+ colSpan: 0,
32
+ rowSpan: 1,
33
+ reachesBottom: !1,
34
+ startsGroup: o,
35
+ topLevel: s
36
+ };
37
+ a[n].push(d);
38
+ let f = [...i, d.id], p = 0;
39
+ return t.children.forEach((e, t) => {
40
+ p += u(e, n + 1, f, o && t === 0);
41
+ }), r.subtotals && (l(t, "subtotal", n + 1, f, !1, !1), p += 1), d.colSpan = p, p;
42
+ };
43
+ for (let e of n) s.push(u(e, 0, [], !0));
44
+ return r.total && (l(null, "total", 0, [], !0, !0), s.push(1)), {
45
+ headerRows: a,
46
+ columns: o,
47
+ depth: i,
48
+ groupSpans: s
49
+ };
50
+ }
51
+ function r(t) {
52
+ let n = [], r = (t, i, a) => {
53
+ for (let o of t) {
54
+ let t = n.length, s = e(o);
55
+ n.push({
56
+ key: o.key,
57
+ node: o,
58
+ depth: i,
59
+ hasChildren: s,
60
+ ancestors: a
61
+ }), s && r(o.children, i + 1, [...a, t]);
62
+ }
63
+ };
64
+ return r(t, 0, []), n;
65
+ }
66
+ //#endregion
67
+ export { n as layoutPivotColumns, r as layoutPivotRows };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ var e=`_scroller_x2q1s_7`,t=`_root_x2q1s_20`,n=`_caption_x2q1s_27`,r=`_columnHeader_x2q1s_34`,i=`_group_x2q1s_48`,a=`_bottom_x2q1s_56`,o=`_corner_x2q1s_60`,s=`_rowHeader_x2q1s_63`,c=`_value_x2q1s_72`,l=`_groupRow_x2q1s_77`,u=`_aggregate_x2q1s_82`,d=`_groupStart_x2q1s_86`,f=`_totalRow_x2q1s_89`,p={scroller:e,root:t,caption:n,columnHeader:r,group:i,bottom:a,corner:o,rowHeader:s,value:c,groupRow:l,aggregate:u,groupStart:d,totalRow:f};exports.aggregate=u,exports.bottom=a,exports.caption=n,exports.columnHeader=r,exports.corner=o,exports.default=p,exports.group=i,exports.groupRow=l,exports.groupStart=d,exports.root=t,exports.rowHeader=s,exports.scroller=e,exports.totalRow=f,exports.value=c;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ //#region src/components/data-display/PivotTable/pivot-table.module.scss
3
+ var e = "_scroller_x2q1s_7", t = "_root_x2q1s_20", n = "_caption_x2q1s_27", r = "_columnHeader_x2q1s_34", i = "_group_x2q1s_48", a = "_bottom_x2q1s_56", o = "_corner_x2q1s_60", s = "_rowHeader_x2q1s_63", c = "_value_x2q1s_72", l = "_groupRow_x2q1s_77", u = "_aggregate_x2q1s_82", d = "_groupStart_x2q1s_86", f = "_totalRow_x2q1s_89", p = {
4
+ scroller: e,
5
+ root: t,
6
+ caption: n,
7
+ columnHeader: r,
8
+ group: i,
9
+ bottom: a,
10
+ corner: o,
11
+ rowHeader: s,
12
+ value: c,
13
+ groupRow: l,
14
+ aggregate: u,
15
+ groupStart: d,
16
+ totalRow: f
17
+ };
18
+ //#endregion
19
+ export { u as aggregate, a as bottom, n as caption, r as columnHeader, o as corner, p as default, i as group, l as groupRow, d as groupStart, t as root, s as rowHeader, e as scroller, f as totalRow, c as value };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var e=`_wrapper_102ll_3`,t=`_root_102ll_41`,n=`_hasCloseButton_102ll_58`,r=`_visible_102ll_72`,i=`_content_102ll_76`,a=`_icon_102ll_82`,o=`_message_102ll_90`,s=`_actions_102ll_95`,c=`_actionButton_102ll_101`,l=`_closeButton_102ll_105`,u=`_success_102ll_133`,d=`_danger_102ll_138`,f=`_warning_102ll_143`,p=`_info_102ll_149`,m={wrapper:e,"top-left":`_top-left_102ll_11`,"top-center":`_top-center_102ll_16`,"top-right":`_top-right_102ll_21`,"bottom-left":`_bottom-left_102ll_26`,"bottom-center":`_bottom-center_102ll_31`,"bottom-right":`_bottom-right_102ll_36`,root:t,hasCloseButton:n,visible:r,content:i,icon:a,message:o,actions:s,actionButton:c,closeButton:l,success:u,danger:d,warning:f,info:p};exports.actionButton=c,exports.actions=s,exports.closeButton=l,exports.content=i,exports.danger=d,exports.default=m,exports.hasCloseButton=n,exports.icon=a,exports.info=p,exports.message=o,exports.root=t,exports.success=u,exports.visible=r,exports.warning=f,exports.wrapper=e;
2
+ var e=`_wrapper_1rblr_3`,t=`_root_1rblr_41`,n=`_hasCloseButton_1rblr_58`,r=`_visible_1rblr_72`,i=`_content_1rblr_76`,a=`_icon_1rblr_82`,o=`_message_1rblr_90`,s=`_actions_1rblr_95`,c=`_actionButton_1rblr_101`,l=`_closeButton_1rblr_105`,u=`_success_1rblr_133`,d=`_danger_1rblr_138`,f=`_warning_1rblr_143`,p=`_info_1rblr_149`,m={wrapper:e,"top-left":`_top-left_1rblr_11`,"top-center":`_top-center_1rblr_16`,"top-right":`_top-right_1rblr_21`,"bottom-left":`_bottom-left_1rblr_26`,"bottom-center":`_bottom-center_1rblr_31`,"bottom-right":`_bottom-right_1rblr_36`,root:t,hasCloseButton:n,visible:r,content:i,icon:a,message:o,actions:s,actionButton:c,closeButton:l,success:u,danger:d,warning:f,info:p};exports.actionButton=c,exports.actions=s,exports.closeButton=l,exports.content=i,exports.danger=d,exports.default=m,exports.hasCloseButton=n,exports.icon=a,exports.info=p,exports.message=o,exports.root=t,exports.success=u,exports.visible=r,exports.warning=f,exports.wrapper=e;
@@ -1,13 +1,13 @@
1
1
  "use client";
2
2
  //#region src/components/feedback/Snackbar/snackbar.module.scss
3
- var e = "_wrapper_102ll_3", t = "_root_102ll_41", n = "_hasCloseButton_102ll_58", r = "_visible_102ll_72", i = "_content_102ll_76", a = "_icon_102ll_82", o = "_message_102ll_90", s = "_actions_102ll_95", c = "_actionButton_102ll_101", l = "_closeButton_102ll_105", u = "_success_102ll_133", d = "_danger_102ll_138", f = "_warning_102ll_143", p = "_info_102ll_149", m = {
3
+ var e = "_wrapper_1rblr_3", t = "_root_1rblr_41", n = "_hasCloseButton_1rblr_58", r = "_visible_1rblr_72", i = "_content_1rblr_76", a = "_icon_1rblr_82", o = "_message_1rblr_90", s = "_actions_1rblr_95", c = "_actionButton_1rblr_101", l = "_closeButton_1rblr_105", u = "_success_1rblr_133", d = "_danger_1rblr_138", f = "_warning_1rblr_143", p = "_info_1rblr_149", m = {
4
4
  wrapper: e,
5
- "top-left": "_top-left_102ll_11",
6
- "top-center": "_top-center_102ll_16",
7
- "top-right": "_top-right_102ll_21",
8
- "bottom-left": "_bottom-left_102ll_26",
9
- "bottom-center": "_bottom-center_102ll_31",
10
- "bottom-right": "_bottom-right_102ll_36",
5
+ "top-left": "_top-left_1rblr_11",
6
+ "top-center": "_top-center_1rblr_16",
7
+ "top-right": "_top-right_1rblr_21",
8
+ "bottom-left": "_bottom-left_1rblr_26",
9
+ "bottom-center": "_bottom-center_1rblr_31",
10
+ "bottom-right": "_bottom-right_1rblr_36",
11
11
  root: t,
12
12
  hasCloseButton: n,
13
13
  visible: r,
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../Button/Button.cjs"),r=require("../../overlay/Dialog/Dialog.cjs"),i=require("../Slider/Slider.cjs"),a=require("../IconButton/IconButton.cjs"),o=require("./image-cropper.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=s.default.forwardRef(({src:e,aspectRatio:u=1,circular:d=!1,onCrop:f,showRotation:p=!0,showZoom:m=!0,showApplyButton:h=!0,applyLabel:g,onApply:_,className:v,...y},b)=>{let{t:x}=t.useWimTranslation(`form`),[S,C]=(0,s.useState)(1),[w,T]=(0,s.useState)(0),[E,D]=(0,s.useState)({x:0,y:0}),[O,k]=(0,s.useState)(!1),[A,j]=(0,s.useState)({x:0,y:0}),[M,N]=(0,s.useState)(!1),P=(0,s.useRef)(null),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{D({x:0,y:0}),C(1),T(0)},[e]);let I=e=>{k(!0),j({x:e.clientX-E.x,y:e.clientY-E.y})},L=(0,s.useCallback)(e=>{O&&D({x:e.clientX-A.x,y:e.clientY-A.y})},[O,A]),R=(0,s.useCallback)(()=>{k(!1)},[]);(0,s.useEffect)(()=>(O?(window.addEventListener(`mousemove`,L),window.addEventListener(`mouseup`,R)):(window.removeEventListener(`mousemove`,L),window.removeEventListener(`mouseup`,R)),()=>{window.removeEventListener(`mousemove`,L),window.removeEventListener(`mouseup`,R)}),[O,L,R]);let z=()=>{T(e=>(e+90)%360)},B=()=>{N(!0)},V=()=>{let t=e||``;f?.(t),_?.(t),N(!1)};return e?(0,l.jsxs)(`div`,{ref:b,className:(0,c.default)(`wim-image-cropper`,o.default.root,v),...y,children:[(0,l.jsxs)(`div`,{ref:F,className:o.default.viewer,onMouseDown:I,role:`presentation`,children:[(0,l.jsx)(`div`,{className:o.default.imageContainer,children:(0,l.jsx)(`img`,{ref:P,src:e,alt:x(`a11y.crop_target`),className:o.default.image,style:{transform:`translate(${E.x}px, ${E.y}px) rotate(${w}deg) scale(${S})`},draggable:!1})}),(0,l.jsx)(`div`,{className:o.default.overlay,children:(0,l.jsx)(`div`,{className:(0,c.default)(o.default.cropArea,{[o.default.circular]:d}),style:{aspectRatio:u}})})]}),(0,l.jsxs)(`div`,{className:o.default.controls,children:[m&&(0,l.jsx)(`div`,{className:o.default.zoomControl,children:(0,l.jsx)(i.Slider,{min:1,max:3,step:.1,value:S,onChange:e=>C(e),label:x(`image_cropper.zoom`),styles:{root:o.default.zoomSlider}})}),p&&(0,l.jsx)(`div`,{className:o.default.rotationControl,children:(0,l.jsx)(a.IconButton,{iconName:`RefreshIcon`,onClick:z,"aria-label":x(`image_cropper.rotate`),variant:`outline`,size:`sm`})}),h&&(0,l.jsx)(`div`,{className:o.default.applyControl,children:(0,l.jsx)(n.Button,{onClick:B,size:`sm`,variant:`solid`,children:g||x(`image_cropper.apply`)})})]}),(0,l.jsx)(r.Dialog,{open:M,onOpenChange:N,children:(0,l.jsxs)(r.DialogContent,{children:[(0,l.jsx)(r.DialogHeader,{children:(0,l.jsx)(r.DialogTitle,{children:x(`image_cropper.confirm_title`)})}),(0,l.jsx)(r.DialogDescription,{children:x(`image_cropper.confirm_message`)}),(0,l.jsxs)(r.DialogFooter,{children:[(0,l.jsx)(r.DialogClose,{asChild:!0,children:(0,l.jsx)(n.Button,{variant:`ghost`,children:x(`image_cropper.cancel`)})}),(0,l.jsx)(n.Button,{onClick:V,variant:`solid`,children:x(`image_cropper.confirm`)})]})]})})]}):(0,l.jsx)(`div`,{ref:b,className:(0,c.default)(`wim-image-cropper`,o.default.root,o.default.empty,v),...y,children:(0,l.jsx)(`div`,{className:o.default.emptyContent,children:x(`image_cropper.no_image`)})})});u.displayName=`ImageCropper`,exports.ImageCropper=u;
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../Button/Button.cjs"),r=require("../Slider/Slider.cjs"),i=require("../IconButton/IconButton.cjs"),a=require("../../overlay/Dialog/Dialog.cjs"),o=require("./image-cropper.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=s.default.forwardRef(({src:e,aspectRatio:u=1,circular:d=!1,onCrop:f,showRotation:p=!0,showZoom:m=!0,showApplyButton:h=!0,applyLabel:g,onApply:_,className:v,...y},b)=>{let{t:x}=t.useWimTranslation(`form`),[S,C]=(0,s.useState)(1),[w,T]=(0,s.useState)(0),[E,D]=(0,s.useState)({x:0,y:0}),[O,k]=(0,s.useState)(!1),[A,j]=(0,s.useState)({x:0,y:0}),[M,N]=(0,s.useState)(!1),P=(0,s.useRef)(null),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{D({x:0,y:0}),C(1),T(0)},[e]);let I=e=>{k(!0),j({x:e.clientX-E.x,y:e.clientY-E.y})},L=(0,s.useCallback)(e=>{O&&D({x:e.clientX-A.x,y:e.clientY-A.y})},[O,A]),R=(0,s.useCallback)(()=>{k(!1)},[]);(0,s.useEffect)(()=>(O?(window.addEventListener(`mousemove`,L),window.addEventListener(`mouseup`,R)):(window.removeEventListener(`mousemove`,L),window.removeEventListener(`mouseup`,R)),()=>{window.removeEventListener(`mousemove`,L),window.removeEventListener(`mouseup`,R)}),[O,L,R]);let z=()=>{T(e=>(e+90)%360)},B=()=>{N(!0)},V=()=>{let t=e||``;f?.(t),_?.(t),N(!1)};return e?(0,l.jsxs)(`div`,{ref:b,className:(0,c.default)(`wim-image-cropper`,o.default.root,v),...y,children:[(0,l.jsxs)(`div`,{ref:F,className:o.default.viewer,onMouseDown:I,role:`presentation`,children:[(0,l.jsx)(`div`,{className:o.default.imageContainer,children:(0,l.jsx)(`img`,{ref:P,src:e,alt:x(`a11y.crop_target`),className:o.default.image,style:{transform:`translate(${E.x}px, ${E.y}px) rotate(${w}deg) scale(${S})`},draggable:!1})}),(0,l.jsx)(`div`,{className:o.default.overlay,children:(0,l.jsx)(`div`,{className:(0,c.default)(o.default.cropArea,{[o.default.circular]:d}),style:{aspectRatio:u}})})]}),(0,l.jsxs)(`div`,{className:o.default.controls,children:[m&&(0,l.jsx)(`div`,{className:o.default.zoomControl,children:(0,l.jsx)(r.Slider,{min:1,max:3,step:.1,value:S,onChange:e=>C(e),label:x(`image_cropper.zoom`),styles:{root:o.default.zoomSlider}})}),p&&(0,l.jsx)(`div`,{className:o.default.rotationControl,children:(0,l.jsx)(i.IconButton,{iconName:`RefreshIcon`,onClick:z,"aria-label":x(`image_cropper.rotate`),variant:`outline`,size:`sm`})}),h&&(0,l.jsx)(`div`,{className:o.default.applyControl,children:(0,l.jsx)(n.Button,{onClick:B,size:`sm`,variant:`solid`,children:g||x(`image_cropper.apply`)})})]}),(0,l.jsx)(a.Dialog,{open:M,onOpenChange:N,children:(0,l.jsxs)(a.DialogContent,{children:[(0,l.jsx)(a.DialogHeader,{children:(0,l.jsx)(a.DialogTitle,{children:x(`image_cropper.confirm_title`)})}),(0,l.jsx)(a.DialogDescription,{children:x(`image_cropper.confirm_message`)}),(0,l.jsxs)(a.DialogFooter,{children:[(0,l.jsx)(a.DialogClose,{asChild:!0,children:(0,l.jsx)(n.Button,{variant:`ghost`,children:x(`image_cropper.cancel`)})}),(0,l.jsx)(n.Button,{onClick:V,variant:`solid`,children:x(`image_cropper.confirm`)})]})]})})]}):(0,l.jsx)(`div`,{ref:b,className:(0,c.default)(`wim-image-cropper`,o.default.root,o.default.empty,v),...y,children:(0,l.jsx)(`div`,{className:o.default.emptyContent,children:x(`image_cropper.no_image`)})})});u.displayName=`ImageCropper`,exports.ImageCropper=u;
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
3
3
  import { Button as t } from "../Button/Button.js";
4
- import { Dialog as n, DialogClose as r, DialogContent as i, DialogDescription as a, DialogFooter as o, DialogHeader as s, DialogTitle as c } from "../../overlay/Dialog/Dialog.js";
5
- import { Slider as l } from "../Slider/Slider.js";
6
- import { IconButton as u } from "../IconButton/IconButton.js";
4
+ import { Slider as n } from "../Slider/Slider.js";
5
+ import { IconButton as r } from "../IconButton/IconButton.js";
6
+ import { Dialog as i, DialogClose as a, DialogContent as o, DialogDescription as s, DialogFooter as c, DialogHeader as l, DialogTitle as u } from "../../overlay/Dialog/Dialog.js";
7
7
  import d from "./image-cropper.module.js";
8
8
  import f, { useCallback as p, useEffect as m, useRef as h, useState as g } from "react";
9
9
  import _ from "classnames";
@@ -84,7 +84,7 @@ var b = f.forwardRef(({ src: f, aspectRatio: b = 1, circular: x = !1, onCrop: S,
84
84
  children: [
85
85
  w && /* @__PURE__ */ v("div", {
86
86
  className: d.zoomControl,
87
- children: /* @__PURE__ */ v(l, {
87
+ children: /* @__PURE__ */ v(n, {
88
88
  min: 1,
89
89
  max: 3,
90
90
  step: .1,
@@ -96,7 +96,7 @@ var b = f.forwardRef(({ src: f, aspectRatio: b = 1, circular: x = !1, onCrop: S,
96
96
  }),
97
97
  C && /* @__PURE__ */ v("div", {
98
98
  className: d.rotationControl,
99
- children: /* @__PURE__ */ v(u, {
99
+ children: /* @__PURE__ */ v(r, {
100
100
  iconName: "RefreshIcon",
101
101
  onClick: Y,
102
102
  "aria-label": j("image_cropper.rotate"),
@@ -115,13 +115,13 @@ var b = f.forwardRef(({ src: f, aspectRatio: b = 1, circular: x = !1, onCrop: S,
115
115
  })
116
116
  ]
117
117
  }),
118
- /* @__PURE__ */ v(n, {
118
+ /* @__PURE__ */ v(i, {
119
119
  open: H,
120
120
  onOpenChange: U,
121
- children: /* @__PURE__ */ y(i, { children: [
122
- /* @__PURE__ */ v(s, { children: /* @__PURE__ */ v(c, { children: j("image_cropper.confirm_title") }) }),
123
- /* @__PURE__ */ v(a, { children: j("image_cropper.confirm_message") }),
124
- /* @__PURE__ */ y(o, { children: [/* @__PURE__ */ v(r, {
121
+ children: /* @__PURE__ */ y(o, { children: [
122
+ /* @__PURE__ */ v(l, { children: /* @__PURE__ */ v(u, { children: j("image_cropper.confirm_title") }) }),
123
+ /* @__PURE__ */ v(s, { children: j("image_cropper.confirm_message") }),
124
+ /* @__PURE__ */ y(c, { children: [/* @__PURE__ */ v(a, {
125
125
  asChild: !0,
126
126
  children: /* @__PURE__ */ v(t, {
127
127
  variant: "ghost",
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../icon/bold.cjs"),r=require("../../../icon/eraser.cjs"),i=require("../../../icon/italic.cjs"),a=require("../../../icon/link.cjs"),ee=require("../../../icon/list-ordered.cjs"),te=require("../../../icon/list.cjs"),ne=require("../../../icon/strikethrough.cjs"),re=require("../../../icon/underline.cjs"),ie=require("../../../icon/unlink.cjs"),o=require("../../media/Icon/Icon.cjs"),s=require("../Button/Button.cjs"),ae=require("../FieldTemplate/FieldTemplate.cjs"),oe=require("../Input/Input.cjs"),c=require("../../overlay/Dialog/Dialog.cjs"),l=require("./commands.cjs"),u=require("./rich-text-editor.module.cjs");let d=require("react");d=e.__toESM(d,1);let f=require("classnames");f=e.__toESM(f,1);let p=require("react/jsx-runtime");var se=[`bold`,`italic`,`underline`,`strikethrough`,`separator`,`h1`,`h2`,`h3`,`separator`,`ul`,`ol`,`separator`,`link`,`unlink`,`separator`,`removeFormat`],m=d.default.memo(({onClick:e,active:t,disabled:n,title:r,children:i})=>(0,p.jsx)(`button`,{type:`button`,className:(0,f.default)(u.default.toolbarBtn,t&&u.default.active),onClick:e,disabled:n,title:r,"aria-label":r,"aria-pressed":t,tabIndex:-1,children:i}));m.displayName=`ToolbarButton`;var h=({value:e,defaultValue:h=``,onChange:g,placeholder:ce,disabled:le,intent:ue=`default`,variant:de=`outline`,fullWidth:_=!1,width:v,minHeight:y=200,label:b,error:x,required:S,layout:fe,className:pe,id:me,toolbar:he=se,labels:ge={},"aria-label":_e,"aria-labelledby":C})=>{let{t:w}=t.useWimTranslation(`components`),{bold:ve=w(`a11y.rte_bold`),italic:T=w(`a11y.rte_italic`),underline:E=w(`a11y.rte_underline`),strikethrough:ye=w(`a11y.rte_strikethrough`),h1:be=w(`a11y.rte_h1`),h2:xe=w(`a11y.rte_h2`),h3:Se=w(`a11y.rte_h3`),ul:Ce=w(`a11y.rte_ul`),ol:we=w(`a11y.rte_ol`),link:D=w(`a11y.rte_link`),unlink:Te=w(`a11y.rte_unlink`),removeFormat:O=w(`a11y.rte_remove_format`),toolbar:Ee=w(`a11y.rte_toolbar`),linkPrompt:De=w(`a11y.rte_link_prompt`),linkApply:Oe=w(`a11y.rte_link_apply`),linkCancel:ke=w(`a11y.rte_link_cancel`)}=ge,k=d.default.useRef(null),A=d.default.useRef(!1),j=d.default.useRef(e??h),[M,Ae]=d.default.useState(new Set),je=d.default.useId(),N=me||`wim-rte-${je}`,P=x?`${N}-error`:void 0,F=b?`${N}-label`:void 0,I=le,L=x?`danger`:ue,R=typeof v==`string`&&[`xs`,`sm`,`md`,`lg`,`xl`].includes(v),z=v!==void 0&&!R&&!_,B=R&&!_?v:void 0,Me=B?u.default[`width${B.charAt(0).toUpperCase()}${B.slice(1)}`]:void 0,V=d.default.useRef(e===void 0?h:e),H=d.default.useCallback(()=>{k.current&&Ae(l.getActiveFormats(k.current))},[]),U=d.default.useRef([]),W=d.default.useRef(-1),G=d.default.useRef(void 0),K=d.default.useCallback(e=>{let t=U.current,n=W.current;if(t[n]===e)return;let r=[...t.slice(0,n+1),e];r.length>100&&(r=r.slice(1)),U.current=r,W.current=r.length-1},[]),q=d.default.useCallback(()=>{G.current!==void 0&&(clearTimeout(G.current),G.current=void 0,K(j.current))},[K]),J=d.default.useCallback(e=>{q();let t=U.current,n=W.current+e;if(n<0||n>=t.length||!k.current)return;W.current=n;let r=t[n];k.current.innerHTML=r,j.current=r,g?.(r);let i=document.createRange();i.selectNodeContents(k.current),i.collapse(!1);let a=window.getSelection();a?.removeAllRanges(),a?.addRange(i),H()},[q,g,H]),Y=d.default.useCallback(e=>{if(I||!k.current)return;let t=k.current,n=l.getEditorRange(t)?.cloneRange()??null;if(t.focus(),n){let e=window.getSelection();e?.removeAllRanges(),e?.addRange(n)}q(),K(t.innerHTML),e(t),H();let r=t.innerHTML;j.current=r,K(r),g?.(r)},[I,q,K,g,H]),Ne=d.default.useCallback(()=>{Y(e=>l.removeAllFormatting(e))},[Y]),[Pe,X]=d.default.useState(!1),[Z,Fe]=d.default.useState(`https://`),Q=d.default.useRef(null),Ie=d.default.useCallback(()=>{if(I||!k.current)return;k.current.focus();let e=l.getEditorRange(k.current);Q.current=e?e.cloneRange():null;let t=e?.toString()??``;Fe(t.startsWith(`http`)?t:`https://`),X(!0)},[I]),Le=d.default.useCallback(()=>{let e=Z.trim();if(X(!1),!e||!k.current)return;let t=window.getSelection();if(t?.removeAllRanges(),Q.current)t?.addRange(Q.current);else{let e=document.createRange();e.selectNodeContents(k.current),e.collapse(!1),t?.addRange(e)}Y(t=>l.createLink(t,e))},[Z,Y]),$=d.default.useCallback(()=>{if(A.current)return;let e=k.current?.innerHTML??``;e!==j.current&&(j.current=e,g?.(e),G.current!==void 0&&clearTimeout(G.current),G.current=setTimeout(()=>{G.current=void 0,K(j.current)},400)),H()},[g,K,H]),Re=d.default.useCallback(e=>{let t=e.nativeEvent.inputType;t===`historyUndo`?(e.preventDefault(),J(-1)):t===`historyRedo`&&(e.preventDefault(),J(1))},[J]),ze=d.default.useCallback(e=>{if(!(e.ctrlKey||e.metaKey))return;let t=e.key.toLowerCase();t===`z`?(e.preventDefault(),J(e.shiftKey?1:-1)):t===`y`&&(e.preventDefault(),J(1))},[J]),Be=d.default.useCallback(()=>{H()},[H]),Ve=d.default.useCallback(()=>{H()},[H]),He=d.default.useCallback(()=>{A.current=!0},[]),Ue=d.default.useCallback(()=>{A.current=!1,$()},[$]),We=d.default.useCallback(e=>{e.preventDefault()},[]);d.default.useEffect(()=>{k.current&&(k.current.innerHTML=V.current,j.current=V.current,U.current=[V.current],W.current=0)},[]),d.default.useEffect(()=>{e!==void 0&&k.current&&k.current.innerHTML!==e&&(k.current.innerHTML=e,j.current=e)},[e]);let Ge=d.default.useCallback((e,t)=>{if(e===`separator`)return(0,p.jsx)(`span`,{className:u.default.toolbarSep,"aria-hidden":`true`},`sep-${t}`);let s={disabled:I,active:M.has(e)};switch(e){case`bold`:return(0,p.jsx)(m,{...s,title:ve,onClick:()=>Y(e=>l.toggleInline(e,`bold`)),children:(0,p.jsx)(o.Icon,{component:n.default,size:`sm`})},`bold`);case`italic`:return(0,p.jsx)(m,{...s,title:T,onClick:()=>Y(e=>l.toggleInline(e,`italic`)),children:(0,p.jsx)(o.Icon,{component:i.default,size:`sm`})},`italic`);case`underline`:return(0,p.jsx)(m,{...s,title:E,onClick:()=>Y(e=>l.toggleInline(e,`underline`)),children:(0,p.jsx)(o.Icon,{component:re.default,size:`sm`})},`underline`);case`strikethrough`:return(0,p.jsx)(m,{...s,title:ye,onClick:()=>Y(e=>l.toggleInline(e,`strikethrough`)),children:(0,p.jsx)(o.Icon,{component:ne.default,size:`sm`})},`strikethrough`);case`h1`:return(0,p.jsx)(m,{...s,active:M.has(`h1`),title:be,onClick:()=>Y(e=>l.setBlock(e,`h1`)),children:(0,p.jsx)(`span`,{"aria-hidden":`true`,children:`H1`})},`h1`);case`h2`:return(0,p.jsx)(m,{...s,active:M.has(`h2`),title:xe,onClick:()=>Y(e=>l.setBlock(e,`h2`)),children:(0,p.jsx)(`span`,{"aria-hidden":`true`,children:`H2`})},`h2`);case`h3`:return(0,p.jsx)(m,{...s,active:M.has(`h3`),title:Se,onClick:()=>Y(e=>l.setBlock(e,`h3`)),children:(0,p.jsx)(`span`,{"aria-hidden":`true`,children:`H3`})},`h3`);case`ul`:return(0,p.jsx)(m,{...s,title:Ce,onClick:()=>Y(e=>l.toggleList(e,`ul`)),children:(0,p.jsx)(o.Icon,{component:te.default,size:`sm`})},`ul`);case`ol`:return(0,p.jsx)(m,{...s,title:we,onClick:()=>Y(e=>l.toggleList(e,`ol`)),children:(0,p.jsx)(o.Icon,{component:ee.default,size:`sm`})},`ol`);case`link`:return(0,p.jsx)(m,{...s,title:D,onClick:Ie,children:(0,p.jsx)(o.Icon,{component:a.default,size:`sm`})},`link`);case`unlink`:return(0,p.jsx)(m,{...s,title:Te,onClick:()=>Y(e=>l.removeLink(e)),children:(0,p.jsx)(o.Icon,{component:ie.default,size:`sm`})},`unlink`);case`removeFormat`:return(0,p.jsx)(m,{...s,title:O,onClick:Ne,children:(0,p.jsx)(o.Icon,{component:r.default,size:`sm`})},`removeFormat`);default:return null}},[M,I,ve,T,E,ye,be,xe,Se,Ce,we,D,Te,O,Y,Ie,Ne]);return(0,p.jsx)(ae.FieldTemplate,{label:b,error:x,required:S,layout:fe,labelId:F,errorId:P,className:pe,children:(0,p.jsxs)(`div`,{className:(0,f.default)(`wim-rich-text-editor`,u.default.root,u.default[L],I&&u.default.disabled,u.default[de],_&&u.default.fullWidth,z&&u.default.hasCustomWidth,Me),style:z?{"--wim-input-width":typeof v==`number`?`${v}px`:v}:void 0,children:[(0,p.jsx)(`div`,{className:u.default.toolbar,role:`toolbar`,"aria-label":Ee,"aria-controls":N,onMouseDown:We,children:he.map((e,t)=>Ge(e,t))}),(0,p.jsx)(`div`,{ref:k,id:N,className:u.default.content,contentEditable:!I,suppressContentEditableWarning:!0,role:`textbox`,"aria-multiline":!0,"aria-label":_e??(b||C?void 0:w(`a11y.rte_editor`)),"aria-labelledby":C??(b?F:void 0),"aria-invalid":L===`danger`,"aria-describedby":P,"aria-required":S,"aria-disabled":I,"aria-placeholder":ce,"data-placeholder":ce,tabIndex:I?-1:0,style:{minHeight:typeof y==`number`?`${y}px`:y,outline:`none`},onInput:$,onBeforeInput:Re,onKeyDown:ze,onKeyUp:Be,onMouseUp:Ve,onCompositionStart:He,onCompositionEnd:Ue}),(0,p.jsx)(c.Dialog,{open:Pe,onOpenChange:X,children:(0,p.jsxs)(c.DialogContent,{children:[(0,p.jsx)(c.DialogHeader,{children:(0,p.jsx)(c.DialogTitle,{children:D})}),(0,p.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),Le()},children:[(0,p.jsx)(oe.Input,{label:De,type:`url`,value:Z,onChange:e=>Fe(e.target.value),fullWidth:!0}),(0,p.jsxs)(c.DialogFooter,{children:[(0,p.jsx)(c.DialogClose,{asChild:!0,children:(0,p.jsx)(s.Button,{variant:`ghost`,type:`button`,children:ke})}),(0,p.jsx)(s.Button,{variant:`solid`,type:`submit`,children:Oe})]})]})]})})]})})};h.displayName=`RichTextEditor`,exports.RichTextEditor=h;
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../icon/bold.cjs"),r=require("../../../icon/eraser.cjs"),i=require("../../../icon/image.cjs"),a=require("../../../icon/italic.cjs"),o=require("../../../icon/link.cjs"),ee=require("../../../icon/list-ordered.cjs"),te=require("../../../icon/list.cjs"),ne=require("../../../icon/strikethrough.cjs"),re=require("../../../icon/underline.cjs"),ie=require("../../../icon/unlink.cjs"),s=require("../../media/Icon/Icon.cjs"),c=require("../Button/Button.cjs"),ae=require("../FieldTemplate/FieldTemplate.cjs"),l=require("../Input/Input.cjs"),u=require("../../overlay/Dialog/Dialog.cjs"),d=require("./safeUrl.cjs"),f=require("./markdown.cjs"),p=require("./rich-text-editor.module.cjs");let m=require("react");m=e.__toESM(m,1);let h=require("classnames");h=e.__toESM(h,1);let g=require("react/jsx-runtime"),_=require("@tiptap/react"),oe=require("@tiptap/core"),v=require("@tiptap/starter-kit"),y=require("@tiptap/extensions"),se=require("@tiptap/extension-image");var ce=[`bold`,`italic`,`underline`,`strikethrough`,`separator`,`h1`,`h2`,`h3`,`separator`,`ul`,`ol`,`separator`,`link`,`unlink`,`separator`,`removeFormat`],le=se.Image.extend({parseHTML(){return[{tag:`img[src]`,getAttrs:e=>d.isSafeImageUrl(e.getAttribute(`src`))?null:!1}]}}),ue=(e,t,n)=>[v.StarterKit.configure({heading:{levels:[1,2,3]},blockquote:!1,code:!1,codeBlock:!1,horizontalRule:!1,trailingNode:!1,...t===`markdown`?{underline:!1}:{},link:{openOnClick:!1,autolink:!1,linkOnPaste:!1,isAllowedUri:e=>d.isSafeLinkUrl(e),HTMLAttributes:{target:null,rel:null}}}),le.configure({inline:!1,allowBase64:!1}),y.Placeholder.configure({placeholder:e}),...t===`markdown`?f.createMarkdownExtensions(n):[]],de=(e,t)=>e.isEmpty?``:t===`markdown`?e.getMarkdown():e.getHTML(),fe=(e,t,n)=>n===`markdown`?f.markdownToHtml(e,t):t,pe=m.default.memo(({onClick:e,active:t,disabled:n,title:r,tabIndex:i,onFocus:a,buttonRef:o,children:ee})=>(0,g.jsx)(`button`,{ref:o,type:`button`,className:(0,h.default)(p.default.toolbarBtn,t&&p.default.active),onClick:e,onFocus:a,disabled:n,title:r,"aria-label":r,"aria-pressed":t,tabIndex:i,children:ee}));pe.displayName=`ToolbarButton`;var me=({value:e,defaultValue:f=``,onChange:v,placeholder:y,disabled:se,intent:le=`default`,variant:me=`outline`,fullWidth:b=!1,width:x,minHeight:S=200,label:C,error:w,required:T,layout:he,className:ge,id:_e,toolbar:E=ce,labels:ve={},"aria-label":ye,"aria-labelledby":D,onImageUpload:O,format:be=`html`})=>{let{t:k}=t.useWimTranslation(`components`),{bold:xe=k(`a11y.rte_bold`),italic:Se=k(`a11y.rte_italic`),underline:Ce=k(`a11y.rte_underline`),strikethrough:we=k(`a11y.rte_strikethrough`),h1:Te=k(`a11y.rte_h1`),h2:Ee=k(`a11y.rte_h2`),h3:De=k(`a11y.rte_h3`),ul:Oe=k(`a11y.rte_ul`),ol:ke=k(`a11y.rte_ol`),link:Ae=k(`a11y.rte_link`),unlink:je=k(`a11y.rte_unlink`),removeFormat:Me=k(`a11y.rte_remove_format`),toolbar:Ne=k(`a11y.rte_toolbar`),linkPrompt:Pe=k(`a11y.rte_link_prompt`),linkApply:Fe=k(`a11y.rte_link_apply`),linkCancel:Ie=k(`a11y.rte_link_cancel`),linkInvalid:Le=k(`a11y.rte_link_invalid`),image:Re=k(`a11y.rte_image`),imageUrl:ze=k(`a11y.rte_image_url`),imageAlt:Be=k(`a11y.rte_image_alt`),imageAltHint:Ve=k(`a11y.rte_image_alt_hint`),imageUpload:He=k(`a11y.rte_image_upload`),imageUploadFailed:A=k(`a11y.rte_image_upload_failed`),imageInvalid:Ue=k(`a11y.rte_image_invalid`)}=ve,We=m.default.useId(),j=_e||`wim-rte-${We}`,M=w?`${j}-error`:void 0,N=C?`${j}-label`:void 0,P=!!se,F=w?`danger`:le,Ge=typeof x==`string`&&[`xs`,`sm`,`md`,`lg`,`xl`].includes(x),Ke=x!==void 0&&!Ge&&!b,qe=Ge&&!b?x:void 0,Je=qe?p.default[`width${qe.charAt(0).toUpperCase()}${qe.slice(1)}`]:void 0,I=m.default.useRef(e??f),Ye=m.default.useRef(v);m.default.useEffect(()=>{Ye.current=v},[v]);let Xe=m.default.useMemo(()=>{let e={id:j,class:p.default.content,role:`textbox`,"aria-multiline":`true`,style:`min-height: ${typeof S==`number`?`${S}px`:S}`,tabindex:P?`-1`:`0`},t=ye??(C||D?void 0:k(`a11y.rte_editor`)),n=D??(C?N:void 0);return t&&(e[`aria-label`]=t),n&&(e[`aria-labelledby`]=n),F===`danger`&&(e[`aria-invalid`]=`true`),M&&(e[`aria-describedby`]=M),T&&(e[`aria-required`]=`true`),P&&(e[`aria-disabled`]=`true`),y&&(e[`aria-placeholder`]=y),e},[j,S,P,ye,C,D,N,F,M,T,y,k]),L=m.default.useRef(O);m.default.useEffect(()=>{L.current=O},[O]);let[Ze,Qe]=m.default.useState(void 0),$e=m.default.useRef(A);m.default.useEffect(()=>{$e.current=A},[A]);let R=m.default.useCallback(async(e,t,n)=>{let r=L.current;if(r){Qe(void 0);for(let i of t)try{let t=await r(i);if(!d.isSafeImageUrl(t))throw Error(`URL not allowed`);if(e.isDestroyed)return;let a=e.chain().focus();(n===void 0?a:a.setTextSelection(n)).setImage({src:t,alt:``}).run()}catch{Qe($e.current)}}},[]),et=e=>Array.from(e??[]).filter(e=>e.type.startsWith(`image/`)),z=m.default.useRef({ed:null}),tt=m.default.useCallback((e,t)=>{let n=et(t.clipboardData?.files),r=z.current.ed;return!L.current||n.length===0||!r?!1:(t.preventDefault(),R(r,n),!0)},[R]),nt=m.default.useCallback((e,t,n,r)=>{let i=et(t.dataTransfer?.files),a=z.current.ed;if(r||!L.current||i.length===0||!a)return!1;t.preventDefault();let o=e.posAtCoords({left:t.clientX,top:t.clientY});return R(a,i,o?.pos),!0},[R]),B=m.default.useMemo(()=>({attributes:Xe,handlePaste:tt,handleDrop:nt}),[Xe,tt,nt]),[V]=m.default.useState(be),rt=e??f,H=(0,_.useEditor)({extensions:ue(y??``,V,V===`markdown`?rt:void 0),content:V===`markdown`?``:rt,editable:!P,immediatelyRender:!1,editorProps:B,onUpdate:({editor:e})=>{let t=de(e,V);t!==I.current&&(I.current=t,Ye.current?.(t))}});m.default.useEffect(()=>{H&&!H.isDestroyed&&H.setOptions({editorProps:B})},[H,B]),m.default.useEffect(()=>{z.current.ed=H},[H]),m.default.useEffect(()=>{H&&!H.isDestroyed&&H.setEditable(!P,!1)},[H,P]),m.default.useEffect(()=>{if(!H||H.isDestroyed)return;let e=H.extensionManager.extensions.find(e=>e.name===`placeholder`);e&&e.options.placeholder!==(y??``)&&(e.options.placeholder=y??``,H.view.dispatch(H.state.tr))},[H,y]),m.default.useEffect(()=>{if(!H||H.isDestroyed||e===void 0||e===I.current||e===de(H,V))return;I.current=e;let t=(0,oe.createDocument)(fe(H,e,V),H.schema);t.eq(H.state.doc)||H.commands.setContent(t.toJSON(),{emitUpdate:!1})},[H,e,V]);let it=(0,_.useEditorState)({editor:H,selector:({editor:e})=>({bold:!!e?.isActive(`bold`),italic:!!e?.isActive(`italic`),underline:!!e?.schema.marks.underline&&e.isActive(`underline`),strikethrough:!!e?.isActive(`strike`),h1:!!e?.isActive(`heading`,{level:1}),h2:!!e?.isActive(`heading`,{level:2}),h3:!!e?.isActive(`heading`,{level:3}),ul:!!e?.isActive(`bulletList`),ol:!!e?.isActive(`orderedList`),image:!!e?.isActive(`image`)})}),U=m.default.useCallback(e=>{!P&&H&&e(H)},[H,P]),at=m.default.useCallback(()=>{U(e=>{let{from:t,to:n,empty:r}=e.state.selection,i=e.chain().focus();r&&i.selectAll(),i.unsetBold().unsetItalic().unsetStrike().clearNodes(),e.schema.marks.underline&&i.unsetUnderline(),r&&i.setTextSelection({from:t,to:n}),i.run()})},[U]),[ot,W]=m.default.useState(!1),[G,st]=m.default.useState(`https://`),[ct,K]=m.default.useState(void 0),lt=m.default.useCallback(()=>{if(P||!H)return;let{from:e,to:t}=H.state.selection,n=H.state.doc.textBetween(e,t,` `),r=H.getAttributes(`link`).href;st(r??(n.startsWith(`http`)?n:`https://`)),K(void 0),W(!0)},[H,P]),ut=m.default.useCallback(()=>{let e=G.trim();if(!e){W(!1);return}if(!d.isSafeLinkUrl(e)){K(Le);return}W(!1),U(t=>{t.state.selection.empty&&!t.isActive(`link`)?t.chain().focus().insertContent({type:`text`,text:e,marks:[{type:`link`,attrs:{href:e}}]}).run():t.chain().focus().extendMarkRange(`link`).setLink({href:e}).run()})},[G,Le,U]),[dt,q]=m.default.useState(!1),[J,Y]=m.default.useState(``),[X,ft]=m.default.useState(``),[pt,Z]=m.default.useState(void 0),[mt,ht]=m.default.useState(!1),gt=m.default.useRef(null),_t=`${j}-image-alt-hint`,vt=m.default.useCallback(()=>{if(P||!H)return;let e=H.isActive(`image`)?H.getAttributes(`image`):{};Y(e.src??``),ft(e.alt??``),Z(void 0),q(!0)},[H,P]),yt=m.default.useCallback(()=>{let e=J.trim();if(!e){q(!1);return}if(!d.isSafeImageUrl(e)){Z(Ue);return}q(!1),U(t=>t.chain().focus().setImage({src:e,alt:X.trim()}).run())},[J,X,Ue,U]),bt=m.default.useCallback(async e=>{let t=e.target.files?.[0];if(e.target.value=``,t&&O){ht(!0),Z(void 0);try{let e=await O(t);if(!d.isSafeImageUrl(e))throw Error(`URL not allowed`);Y(e)}catch{Z(A)}finally{ht(!1)}}},[O,A]),xt=m.default.useRef([]),[Q,St]=m.default.useState(0),$=m.default.useMemo(()=>{let e=V===`markdown`?E.filter(e=>e!==`underline`):E;return e.filter((t,n)=>t!==`separator`||n>0&&n<e.length-1&&e[n-1]!==`separator`)},[E,V]),Ct=m.default.useMemo(()=>$.filter(e=>e!==`separator`),[$]),wt=m.default.useMemo(()=>$.map((e,t)=>e===`separator`?-1:$.slice(0,t).filter(e=>e!==`separator`).length),[$]),Tt=m.default.useCallback(e=>{let t=Ct.length;if(t===0)return;let n;e.key===`ArrowRight`?n=(Q+1)%t:e.key===`ArrowLeft`?n=(Q-1+t)%t:e.key===`Home`?n=0:e.key===`End`&&(n=t-1),n!==void 0&&(e.preventDefault(),St(n),xt.current[n]?.focus())},[Ct.length,Q]),Et=m.default.useCallback(e=>{e.preventDefault()},[]),Dt={bold:{title:xe,icon:(0,g.jsx)(s.Icon,{component:n.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().toggleBold().run())},italic:{title:Se,icon:(0,g.jsx)(s.Icon,{component:a.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().toggleItalic().run())},underline:{title:Ce,icon:(0,g.jsx)(s.Icon,{component:re.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().toggleUnderline().run())},strikethrough:{title:we,icon:(0,g.jsx)(s.Icon,{component:ne.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().toggleStrike().run())},h1:{title:Te,icon:(0,g.jsx)(`span`,{"aria-hidden":`true`,children:`H1`}),onClick:()=>U(e=>e.chain().focus().toggleHeading({level:1}).run())},h2:{title:Ee,icon:(0,g.jsx)(`span`,{"aria-hidden":`true`,children:`H2`}),onClick:()=>U(e=>e.chain().focus().toggleHeading({level:2}).run())},h3:{title:De,icon:(0,g.jsx)(`span`,{"aria-hidden":`true`,children:`H3`}),onClick:()=>U(e=>e.chain().focus().toggleHeading({level:3}).run())},ul:{title:Oe,icon:(0,g.jsx)(s.Icon,{component:te.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().toggleBulletList().run())},ol:{title:ke,icon:(0,g.jsx)(s.Icon,{component:ee.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().toggleOrderedList().run())},link:{title:Ae,icon:(0,g.jsx)(s.Icon,{component:o.default,size:`sm`}),onClick:lt},unlink:{title:je,icon:(0,g.jsx)(s.Icon,{component:ie.default,size:`sm`}),onClick:()=>U(e=>e.chain().focus().extendMarkRange(`link`).unsetLink().run())},image:{title:Re,icon:(0,g.jsx)(s.Icon,{component:i.default,size:`sm`}),onClick:vt},removeFormat:{title:Me,icon:(0,g.jsx)(s.Icon,{component:r.default,size:`sm`}),onClick:at}};return(0,g.jsx)(ae.FieldTemplate,{label:C,error:w,required:T,layout:he,labelId:N,errorId:M,className:ge,children:(0,g.jsxs)(`div`,{className:(0,h.default)(`wim-rich-text-editor`,p.default.root,p.default[F],P&&p.default.disabled,p.default[me],b&&p.default.fullWidth,Ke&&p.default.hasCustomWidth,Je),style:Ke?{"--wim-input-width":typeof x==`number`?`${x}px`:x}:void 0,children:[(0,g.jsx)(`div`,{className:p.default.toolbar,role:`toolbar`,"aria-label":Ne,"aria-controls":j,onMouseDown:Et,onKeyDown:Tt,children:$.map((e,t)=>{if(e===`separator`)return(0,g.jsx)(`span`,{className:p.default.toolbarSep,"aria-hidden":`true`},`sep-${t}`);let n=wt[t],r=Dt[e],i=e===`link`||e===`unlink`||e===`removeFormat`?void 0:it?.[e]??!1;return(0,g.jsx)(pe,{buttonRef:e=>{xt.current[n]=e},tabIndex:n===Math.min(Q,Ct.length-1)?0:-1,onFocus:()=>St(n),disabled:P,active:i,title:r.title,onClick:r.onClick,children:r.icon},`${e}-${t}`)})}),(0,g.jsx)(_.EditorContent,{editor:H,className:p.default.contentHost}),Ze&&(0,g.jsx)(`p`,{role:`alert`,className:p.default.uploadError,children:Ze}),(0,g.jsx)(u.Dialog,{open:ot,onOpenChange:W,children:(0,g.jsxs)(u.DialogContent,{children:[(0,g.jsx)(u.DialogHeader,{children:(0,g.jsx)(u.DialogTitle,{children:Ae})}),(0,g.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ut()},children:[(0,g.jsx)(l.Input,{label:Pe,type:`url`,value:G,error:ct,onChange:e=>{st(e.target.value),K(void 0)},fullWidth:!0}),(0,g.jsxs)(u.DialogFooter,{children:[(0,g.jsx)(u.DialogClose,{asChild:!0,children:(0,g.jsx)(c.Button,{variant:`ghost`,type:`button`,children:Ie})}),(0,g.jsx)(c.Button,{variant:`solid`,type:`submit`,children:Fe})]})]})]})}),(0,g.jsx)(u.Dialog,{open:dt,onOpenChange:q,children:(0,g.jsxs)(u.DialogContent,{children:[(0,g.jsx)(u.DialogHeader,{children:(0,g.jsx)(u.DialogTitle,{children:Re})}),(0,g.jsxs)(`form`,{className:p.default.imageForm,onSubmit:e=>{e.preventDefault(),yt()},children:[(0,g.jsx)(l.Input,{label:ze,type:`url`,value:J,error:pt,onChange:e=>{Y(e.target.value),Z(void 0)},fullWidth:!0}),O&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`input`,{ref:gt,type:`file`,accept:`image/*`,hidden:!0,onChange:bt}),(0,g.jsx)(c.Button,{type:`button`,variant:`outline`,loading:mt,onClick:()=>gt.current?.click(),children:He})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(l.Input,{label:Be,"aria-describedby":_t,value:X,onChange:e=>ft(e.target.value),fullWidth:!0}),(0,g.jsx)(`p`,{id:_t,className:p.default.imageHint,children:Ve})]}),(0,g.jsxs)(u.DialogFooter,{children:[(0,g.jsx)(u.DialogClose,{asChild:!0,children:(0,g.jsx)(c.Button,{variant:`ghost`,type:`button`,children:Ie})}),(0,g.jsx)(c.Button,{variant:`solid`,type:`submit`,disabled:mt,children:Fe})]})]})]})})]})})};me.displayName=`RichTextEditor`,exports.RichTextEditor=me;
@@ -1,6 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  import { FieldIntent, FieldVariant, FieldWidth } from '../../../types/tokens';
3
- export type RichTextEditorToolbarItem = "bold" | "italic" | "underline" | "strikethrough" | "h1" | "h2" | "h3" | "ul" | "ol" | "link" | "unlink" | "removeFormat" | "separator";
3
+ export type RichTextEditorToolbarItem = "bold" | "italic" | "underline" | "strikethrough" | "h1" | "h2" | "h3" | "ul" | "ol" | "link" | "unlink" | "image" | "removeFormat" | "separator";
4
4
  export type RichTextEditorLabels = {
5
5
  bold?: string;
6
6
  italic?: string;
@@ -18,14 +18,39 @@ export type RichTextEditorLabels = {
18
18
  linkPrompt?: string;
19
19
  linkApply?: string;
20
20
  linkCancel?: string;
21
+ /** Error shown in the link dialog when the URL is not allowed (only http, https, mailto and relative URLs are). */
22
+ linkInvalid?: string;
23
+ /** Title of the image button and the image dialog. */
24
+ image?: string;
25
+ /** Label of the image URL field. */
26
+ imageUrl?: string;
27
+ /** Label of the alternative text field. */
28
+ imageAlt?: string;
29
+ /** Hint under the alternative text field. */
30
+ imageAltHint?: string;
31
+ /** Label of the button that picks a file (shown only with onImageUpload). */
32
+ imageUpload?: string;
33
+ /** Error shown when onImageUpload rejects or returns a URL that is not allowed. */
34
+ imageUploadFailed?: string;
35
+ /** Error shown in the image dialog when the URL is not allowed (only http, https and relative URLs are). */
36
+ imageInvalid?: string;
21
37
  };
22
38
  export type RichTextEditorProps = {
23
- /** HTML content (controlled) */
39
+ /** Content (controlled), in the format given by `format`. An empty editor is reported as "". */
24
40
  value?: string;
25
- /** Initial HTML content (uncontrolled) */
41
+ /** Initial content (uncontrolled), in the format given by `format` */
26
42
  defaultValue?: string;
27
- /** Callback when the content changes */
43
+ /**
44
+ * Callback when the content changes, in the format given by `format`. The content only contains what the editor's schema
45
+ * allows, whichever format is used.
46
+ */
28
47
  onChange?: (value: string) => void;
48
+ /**
49
+ * Format of `value`, `defaultValue` and `onChange`. With `"markdown"`, the editor reads and writes Markdown and has no underline
50
+ * (Markdown has no syntax for it): the underline button is hidden and underlined input keeps only its text. Read when the
51
+ * editor is created; changing it later does not convert the content.
52
+ */
53
+ format?: "html" | "markdown";
29
54
  /** Placeholder shown when the editor is empty */
30
55
  placeholder?: string;
31
56
  /** Whether the editor is disabled */
@@ -60,11 +85,16 @@ export type RichTextEditorProps = {
60
85
  "aria-label"?: string;
61
86
  /** ID of the element that labels the editor */
62
87
  "aria-labelledby"?: string;
88
+ /**
89
+ * Uploads an image file and resolves to its URL (http, https or relative). When given, the image dialog offers a file picker
90
+ * and image files pasted or dropped into the editor are uploaded and inserted. The editor stores only the URL it gets back.
91
+ */
92
+ onImageUpload?: (file: File) => Promise<string>;
63
93
  };
64
94
  /**
65
- * WYSIWYG editor component for rich text input.
95
+ * WYSIWYG editor component for rich text input, built on Tiptap (import from `wimui/form/rich-text-editor`).
66
96
  */
67
97
  export declare const RichTextEditor: {
68
- ({ value, defaultValue, onChange, placeholder, disabled, intent, variant, fullWidth, width, minHeight, label, error, required, layout, className, id: customId, toolbar, labels, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, }: RichTextEditorProps): React.JSX.Element;
98
+ ({ value, defaultValue, onChange, placeholder, disabled, intent, variant, fullWidth, width, minHeight, label, error, required, layout, className, id: customId, toolbar: toolbarProp, labels, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, onImageUpload, format, }: RichTextEditorProps): React.JSX.Element;
69
99
  displayName: string;
70
100
  };