@namroodinc/liquid-editorial 0.13.5 → 0.14.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.
- package/README.md +1 -1
- package/UPGRADING.md +47 -0
- package/dist/chunks/{Avatar-UjhjcHh5.js → Avatar-BToMaTdL.js} +2 -2
- package/dist/chunks/{Avatar-UjhjcHh5.js.map → Avatar-BToMaTdL.js.map} +1 -1
- package/dist/chunks/{Avatar-BY0dAItT.cjs → Avatar-Dw7EWd_-.cjs} +2 -2
- package/dist/chunks/{Avatar-BY0dAItT.cjs.map → Avatar-Dw7EWd_-.cjs.map} +1 -1
- package/dist/chunks/{Board-CQ1GTuRB.cjs → Board-DeXtaWNO.cjs} +2 -2
- package/dist/chunks/{Board-CQ1GTuRB.cjs.map → Board-DeXtaWNO.cjs.map} +1 -1
- package/dist/chunks/{Board-DUX76d2R.js → Board-XeDG9nWP.js} +2 -2
- package/dist/chunks/{Board-DUX76d2R.js.map → Board-XeDG9nWP.js.map} +1 -1
- package/dist/chunks/{CollectionView-JRNdXHti.js → CollectionView-C0_bTO2v.js} +2 -2
- package/dist/chunks/{CollectionView-JRNdXHti.js.map → CollectionView-C0_bTO2v.js.map} +1 -1
- package/dist/chunks/{CollectionView-CIJdNwcq.cjs → CollectionView-Dbg4d_tA.cjs} +2 -2
- package/dist/chunks/{CollectionView-CIJdNwcq.cjs.map → CollectionView-Dbg4d_tA.cjs.map} +1 -1
- package/dist/chunks/{ColourField-BG5oGj9f.js → ColourField-Bb8H87fg.js} +3 -3
- package/dist/chunks/{ColourField-BG5oGj9f.js.map → ColourField-Bb8H87fg.js.map} +1 -1
- package/dist/chunks/{ColourField-DFvRASVe.cjs → ColourField-DAFzOIOq.cjs} +2 -2
- package/dist/chunks/{ColourField-DFvRASVe.cjs.map → ColourField-DAFzOIOq.cjs.map} +1 -1
- package/dist/chunks/{DatePicker-LqaePc57.js → DatePicker-COm1giw8.js} +3 -3
- package/dist/chunks/{DatePicker-LqaePc57.js.map → DatePicker-COm1giw8.js.map} +1 -1
- package/dist/chunks/{DatePicker-ClOqS6oH.cjs → DatePicker-DOg3iQYy.cjs} +2 -2
- package/dist/chunks/{DatePicker-ClOqS6oH.cjs.map → DatePicker-DOg3iQYy.cjs.map} +1 -1
- package/dist/chunks/{Drawer-DdIH9jpe.cjs → Drawer-B2dcTh5l.cjs} +2 -2
- package/dist/chunks/{Drawer-DdIH9jpe.cjs.map → Drawer-B2dcTh5l.cjs.map} +1 -1
- package/dist/chunks/{Drawer-Ck5XKT_V.js → Drawer-nUTJtwX_.js} +3 -3
- package/dist/chunks/{Drawer-Ck5XKT_V.js.map → Drawer-nUTJtwX_.js.map} +1 -1
- package/dist/chunks/EntryPicker-BwEYRtQl.cjs +2 -0
- package/dist/chunks/EntryPicker-BwEYRtQl.cjs.map +1 -0
- package/dist/chunks/{use-picker-session-BSpOwnQ-.js → EntryPicker-Ie9T47hA.js} +367 -202
- package/dist/chunks/EntryPicker-Ie9T47hA.js.map +1 -0
- package/dist/chunks/FormEditor-D1HUnjMI.cjs +2 -0
- package/dist/chunks/FormEditor-D1HUnjMI.cjs.map +1 -0
- package/dist/chunks/FormEditor-DgDV5aeR.js +30 -0
- package/dist/chunks/FormEditor-DgDV5aeR.js.map +1 -0
- package/dist/chunks/Icon-Bxvp1-td.js +102 -0
- package/dist/chunks/Icon-Bxvp1-td.js.map +1 -0
- package/dist/chunks/{Icon-3ucBRgrd.cjs → Icon-CnnTrtNb.cjs} +2 -2
- package/dist/chunks/Icon-CnnTrtNb.cjs.map +1 -0
- package/dist/chunks/{Message-yhdaBpaz.cjs → Message-B0A5bz8V.cjs} +2 -2
- package/dist/chunks/{Message-yhdaBpaz.cjs.map → Message-B0A5bz8V.cjs.map} +1 -1
- package/dist/chunks/{Message-d6lqiMQ6.js → Message-VJTPhId7.js} +2 -2
- package/dist/chunks/{Message-d6lqiMQ6.js.map → Message-VJTPhId7.js.map} +1 -1
- package/dist/chunks/RichTextEditor-DPhEkDxi.js +2108 -0
- package/dist/chunks/RichTextEditor-DPhEkDxi.js.map +1 -0
- package/dist/chunks/RichTextEditor-DV7NZp_k.cjs +2 -0
- package/dist/chunks/RichTextEditor-DV7NZp_k.cjs.map +1 -0
- package/dist/chunks/{dialogLabel-DT7rCr3_.js → dialogLabel-C153NosD.js} +2 -2
- package/dist/chunks/{dialogLabel-DT7rCr3_.js.map → dialogLabel-C153NosD.js.map} +1 -1
- package/dist/chunks/{dialogLabel-_-MTckE_.cjs → dialogLabel-CNNQbtob.cjs} +2 -2
- package/dist/chunks/{dialogLabel-_-MTckE_.cjs.map → dialogLabel-CNNQbtob.cjs.map} +1 -1
- package/dist/chunks/overlayLayer-CtOTt1xB.cjs +2 -0
- package/dist/chunks/overlayLayer-CtOTt1xB.cjs.map +1 -0
- package/dist/chunks/{overlayLayer-lU4iWSjO.js → overlayLayer-Og07sIyl.js} +21 -3
- package/dist/chunks/overlayLayer-Og07sIyl.js.map +1 -0
- package/dist/chunks/{useTooltip-DnJEFBLg.js → useTooltip-Du8PutGX.js} +2 -2
- package/dist/chunks/{useTooltip-DnJEFBLg.js.map → useTooltip-Du8PutGX.js.map} +1 -1
- package/dist/chunks/{useTooltip-C7ON4nkV.cjs → useTooltip-ekdwMJFz.cjs} +2 -2
- package/dist/chunks/{useTooltip-C7ON4nkV.cjs.map → useTooltip-ekdwMJFz.cjs.map} +1 -1
- package/dist/components/AppShell/index.cjs +1 -1
- package/dist/components/AppShell/index.js +1 -1
- package/dist/components/AssetCard/index.cjs +1 -1
- package/dist/components/AssetCard/index.js +1 -1
- package/dist/components/AssetGrid/index.cjs +1 -1
- package/dist/components/AssetGrid/index.js +1 -1
- package/dist/components/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +1 -1
- package/dist/components/Banner/index.cjs +1 -1
- package/dist/components/Banner/index.js +1 -1
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.cjs.map +1 -1
- package/dist/components/Choice/index.js +5 -5
- package/dist/components/CollectionView/index.cjs +1 -1
- package/dist/components/CollectionView/index.js +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.js +1 -1
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.js +4 -4
- package/dist/components/EntryPicker/dialog.d.cts +11 -1
- package/dist/components/EntryPicker/dialog.d.cts.map +1 -1
- package/dist/components/EntryPicker/dialog.d.ts +11 -1
- package/dist/components/EntryPicker/dialog.d.ts.map +1 -1
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.js +1 -1
- package/dist/components/EntryPicker/use-picker-data.d.cts +1 -1
- package/dist/components/EntryPicker/use-picker-data.d.cts.map +1 -1
- package/dist/components/EntryPicker/use-picker-data.d.ts +1 -1
- package/dist/components/EntryPicker/use-picker-data.d.ts.map +1 -1
- package/dist/components/EntryPicker/use-picker-session.d.cts +4 -1
- package/dist/components/EntryPicker/use-picker-session.d.cts.map +1 -1
- package/dist/components/EntryPicker/use-picker-session.d.ts +4 -1
- package/dist/components/EntryPicker/use-picker-session.d.ts.map +1 -1
- package/dist/components/EntryPicker/use-selected-items.d.cts +2 -0
- package/dist/components/EntryPicker/use-selected-items.d.cts.map +1 -1
- package/dist/components/EntryPicker/use-selected-items.d.ts +2 -0
- package/dist/components/EntryPicker/use-selected-items.d.ts.map +1 -1
- package/dist/components/FormEditor/README.md +155 -24
- package/dist/components/FormEditor/control.d.cts +11 -2
- package/dist/components/FormEditor/control.d.cts.map +1 -1
- package/dist/components/FormEditor/control.d.ts +11 -2
- package/dist/components/FormEditor/control.d.ts.map +1 -1
- package/dist/components/FormEditor/form.d.cts +33 -0
- package/dist/components/FormEditor/form.d.cts.map +1 -0
- package/dist/components/FormEditor/form.d.ts +33 -0
- package/dist/components/FormEditor/form.d.ts.map +1 -0
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.d.cts +3 -27
- package/dist/components/FormEditor/index.d.cts.map +1 -1
- package/dist/components/FormEditor/index.d.ts +3 -27
- package/dist/components/FormEditor/index.d.ts.map +1 -1
- package/dist/components/FormEditor/index.js +3 -3
- package/dist/components/FormEditor/model.d.cts +2 -0
- package/dist/components/FormEditor/model.d.cts.map +1 -1
- package/dist/components/FormEditor/model.d.ts +2 -0
- package/dist/components/FormEditor/model.d.ts.map +1 -1
- package/dist/components/FormEditor/rich-text-control.d.cts +4 -0
- package/dist/components/FormEditor/rich-text-control.d.cts.map +1 -0
- package/dist/components/FormEditor/rich-text-control.d.ts +4 -0
- package/dist/components/FormEditor/rich-text-control.d.ts.map +1 -0
- package/dist/components/Icon/icons.d.cts +11 -0
- package/dist/components/Icon/icons.d.cts.map +1 -1
- package/dist/components/Icon/icons.d.ts +11 -0
- package/dist/components/Icon/icons.d.ts.map +1 -1
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +1 -1
- package/dist/components/ImageCropper/index.cjs +1 -1
- package/dist/components/ImageCropper/index.cjs.map +1 -1
- package/dist/components/ImageCropper/index.js +6 -6
- package/dist/components/Menu/index.cjs +1 -1
- package/dist/components/Menu/index.cjs.map +1 -1
- package/dist/components/Menu/index.d.cts +3 -2
- package/dist/components/Menu/index.d.cts.map +1 -1
- package/dist/components/Menu/index.d.ts +3 -2
- package/dist/components/Menu/index.d.ts.map +1 -1
- package/dist/components/Menu/index.js +64 -51
- package/dist/components/Menu/index.js.map +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.js +2 -2
- package/dist/components/Popover/index.cjs +1 -1
- package/dist/components/Popover/index.js +1 -1
- package/dist/components/RichTextEditor/document.d.cts +6 -2
- package/dist/components/RichTextEditor/document.d.cts.map +1 -1
- package/dist/components/RichTextEditor/document.d.ts +6 -2
- package/dist/components/RichTextEditor/document.d.ts.map +1 -1
- package/dist/components/RichTextEditor/embed-context.d.cts +5 -0
- package/dist/components/RichTextEditor/embed-context.d.cts.map +1 -1
- package/dist/components/RichTextEditor/embed-context.d.ts +5 -0
- package/dist/components/RichTextEditor/embed-context.d.ts.map +1 -1
- package/dist/components/RichTextEditor/embed-types.d.cts +6 -4
- package/dist/components/RichTextEditor/embed-types.d.cts.map +1 -1
- package/dist/components/RichTextEditor/embed-types.d.ts +6 -4
- package/dist/components/RichTextEditor/embed-types.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.d.cts +8 -0
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts +8 -0
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -2
- package/dist/components/RichTextEditor/storyblock-view.d.cts.map +1 -1
- package/dist/components/RichTextEditor/storyblock-view.d.ts.map +1 -1
- package/dist/components/RichTextEditor/style.css +44 -46
- package/dist/components/RichTextEditor/tables.d.cts +7 -0
- package/dist/components/RichTextEditor/tables.d.cts.map +1 -0
- package/dist/components/RichTextEditor/tables.d.ts +7 -0
- package/dist/components/RichTextEditor/tables.d.ts.map +1 -0
- package/dist/components/RichTextEditor/use-embeds.d.cts.map +1 -1
- package/dist/components/RichTextEditor/use-embeds.d.ts.map +1 -1
- package/dist/components/SearchField/index.cjs +1 -1
- package/dist/components/SearchField/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +2 -2
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.cjs.map +1 -1
- package/dist/components/SelectionCard/index.js +4 -4
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.js +1 -1
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.js +1 -1
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/SubNav/index.cjs +1 -1
- package/dist/components/SubNav/index.js +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TopNav/index.cjs +1 -1
- package/dist/components/TopNav/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +28 -28
- package/dist/internal/dialogFocus.d.cts +6 -1
- package/dist/internal/dialogFocus.d.cts.map +1 -1
- package/dist/internal/dialogFocus.d.ts +6 -1
- package/dist/internal/dialogFocus.d.ts.map +1 -1
- package/package.json +8 -6
- package/dist/chunks/EntryPicker-B4dAsObz.cjs +0 -2
- package/dist/chunks/EntryPicker-B4dAsObz.cjs.map +0 -1
- package/dist/chunks/EntryPicker-DDXHytMN.js +0 -160
- package/dist/chunks/EntryPicker-DDXHytMN.js.map +0 -1
- package/dist/chunks/FormEditor-BGzE-rqk.cjs +0 -2
- package/dist/chunks/FormEditor-BGzE-rqk.cjs.map +0 -1
- package/dist/chunks/FormEditor-ChH4e5sB.js +0 -693
- package/dist/chunks/FormEditor-ChH4e5sB.js.map +0 -1
- package/dist/chunks/Icon-3ucBRgrd.cjs.map +0 -1
- package/dist/chunks/Icon-dPXyBYe5.js +0 -91
- package/dist/chunks/Icon-dPXyBYe5.js.map +0 -1
- package/dist/chunks/RichTextEditor-BFblqw8m.js +0 -1144
- package/dist/chunks/RichTextEditor-BFblqw8m.js.map +0 -1
- package/dist/chunks/RichTextEditor-DU9CVeRD.cjs +0 -2
- package/dist/chunks/RichTextEditor-DU9CVeRD.cjs.map +0 -1
- package/dist/chunks/overlayLayer-iGhuAByk.cjs +0 -2
- package/dist/chunks/overlayLayer-iGhuAByk.cjs.map +0 -1
- package/dist/chunks/overlayLayer-lU4iWSjO.js.map +0 -1
- package/dist/chunks/use-picker-session-BSpOwnQ-.js.map +0 -1
- package/dist/chunks/use-picker-session-ouqHBmVA.cjs +0 -2
- package/dist/chunks/use-picker-session-ouqHBmVA.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-text-control.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/rich-text-control.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EACL,MAAM,EACN,MAAM,EACN,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,oBAAoB,+BAgBtB"}
|
|
@@ -71,6 +71,17 @@ export declare const icons: {
|
|
|
71
71
|
readonly trash: import("lucide-react").LucideIcon;
|
|
72
72
|
readonly upload: import("lucide-react").LucideIcon;
|
|
73
73
|
readonly user: import("lucide-react").LucideIcon;
|
|
74
|
+
readonly "columns-2-plus-left": import("lucide-react").LucideIcon;
|
|
75
|
+
readonly "columns-2-plus-right": import("lucide-react").LucideIcon;
|
|
76
|
+
readonly "grid-2x2-plus": import("lucide-react").LucideIcon;
|
|
77
|
+
readonly "grid-2x2-x": import("lucide-react").LucideIcon;
|
|
78
|
+
readonly "panel-top": import("lucide-react").LucideIcon;
|
|
79
|
+
readonly "rows-2-plus-bottom": import("lucide-react").LucideIcon;
|
|
80
|
+
readonly "rows-2-plus-top": import("lucide-react").LucideIcon;
|
|
81
|
+
readonly table: import("lucide-react").LucideIcon;
|
|
82
|
+
readonly "table-cells-merge": import("lucide-react").LucideIcon;
|
|
83
|
+
readonly "table-columns-split": import("lucide-react").LucideIcon;
|
|
84
|
+
readonly "table-rows-split": import("lucide-react").LucideIcon;
|
|
74
85
|
readonly x: import("lucide-react").LucideIcon;
|
|
75
86
|
};
|
|
76
87
|
export type IconName = keyof typeof icons;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icons.d.cts","sourceRoot":"","sources":["../../../src/components/Icon/icons.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"icons.d.cts","sourceRoot":"","sources":["../../../src/components/Icon/icons.ts"],"names":[],"mappings":"AAmFA;;;GAGG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiFR,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,KAAK,CAAC;AAE1C,eAAO,MAAM,SAAS,EAAyB,QAAQ,EAAE,CAAC"}
|
|
@@ -71,6 +71,17 @@ export declare const icons: {
|
|
|
71
71
|
readonly trash: import("lucide-react").LucideIcon;
|
|
72
72
|
readonly upload: import("lucide-react").LucideIcon;
|
|
73
73
|
readonly user: import("lucide-react").LucideIcon;
|
|
74
|
+
readonly "columns-2-plus-left": import("lucide-react").LucideIcon;
|
|
75
|
+
readonly "columns-2-plus-right": import("lucide-react").LucideIcon;
|
|
76
|
+
readonly "grid-2x2-plus": import("lucide-react").LucideIcon;
|
|
77
|
+
readonly "grid-2x2-x": import("lucide-react").LucideIcon;
|
|
78
|
+
readonly "panel-top": import("lucide-react").LucideIcon;
|
|
79
|
+
readonly "rows-2-plus-bottom": import("lucide-react").LucideIcon;
|
|
80
|
+
readonly "rows-2-plus-top": import("lucide-react").LucideIcon;
|
|
81
|
+
readonly table: import("lucide-react").LucideIcon;
|
|
82
|
+
readonly "table-cells-merge": import("lucide-react").LucideIcon;
|
|
83
|
+
readonly "table-columns-split": import("lucide-react").LucideIcon;
|
|
84
|
+
readonly "table-rows-split": import("lucide-react").LucideIcon;
|
|
74
85
|
readonly x: import("lucide-react").LucideIcon;
|
|
75
86
|
};
|
|
76
87
|
export type IconName = keyof typeof icons;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../../src/components/Icon/icons.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../../src/components/Icon/icons.ts"],"names":[],"mappings":"AAmFA;;;GAGG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiFR,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,KAAK,CAAC;AAE1C,eAAO,MAAM,SAAS,EAAyB,QAAQ,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-CnnTrtNb.cjs");exports.Icon=e.t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as Icon } from "../../chunks/Icon-
|
|
1
|
+
export { t as Icon } from "../../chunks/Icon-Bxvp1-td.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs"),t=require("../../chunks/useIsomorphicLayoutEffect-XM4Ot6x5.cjs"),n=require("../ButtonGroup/index.cjs"),r=require("../Field/index.cjs"),i=require("
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs"),t=require("../../chunks/useIsomorphicLayoutEffect-XM4Ot6x5.cjs"),n=require("../ButtonGroup/index.cjs"),r=require("../Field/index.cjs"),i=require("../Grid/index.cjs"),a=require("../../chunks/binding-tMjrUzkU.cjs"),o=require("../../chunks/Slider-BfvNPjRJ.cjs");let s=require("react"),c=require("react/jsx-runtime");var l=1,u={zoom:1,rotation:0,x:.5,y:.5};function d(e,t,n){let r=[e,t];for(let e=Math.round(n/90)%4;e>0;e--)r=[1-r[1],r[0]];return r}function f(e,t,n,r){let i=n%180!=0,a=i?e.height:e.width,o=i?e.width:e.height;return{width:a,height:o,scale:Math.max(t.width/a,t.height/o)*r}}function p(e){let t=(e,t)=>e!=null&&Number.isFinite(e)?e:t,n=e=>Math.min(1,Math.max(0,t(e,.5))),r=(Math.round(t(e?.rotation,0)/90)*90%360+360)%360,[i,a]=d(n(e?.cx),n(e?.cy),r);return{zoom:t(e?.zoom,1),rotation:r,x:i,y:a}}var m=(0,s.forwardRef)(function({src:m,alt:h=``,aspect:g,maxZoom:_=3,rotatable:v=!0,onChange:y,defaultState:b,className:x,...S},C){let w=(0,s.useRef)(null),T=(0,s.useRef)(null),E=(0,s.useRef)(null),[D,O]=(0,s.useState)({width:0,height:0}),[k,A]=(0,s.useState)(null),[j,M]=(0,s.useState)(()=>p(b)),[N,P]=(0,s.useState)({src:m,aspect:g});(N.src!==m||N.aspect!==g)&&(P({src:m,aspect:g}),M(e=>N.src===m?{...u,rotation:e.rotation}:p(b)));let F=(0,s.useCallback)(e=>{let{naturalWidth:t,naturalHeight:n}=e;t&&n&&A(e=>e?.src===m&&e.width===t&&e.height===n?e:{src:m,width:t,height:n})},[m]);(0,s.useEffect)(()=>{let e=T.current;e?.complete&&F(e)},[F]),t.t(()=>{let e=w.current;if(!e)return;let t=()=>{let t=e.clientWidth,n=e.clientHeight;O(e=>e.width===t&&e.height===n?e:{width:t,height:n})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[g]);let I=k?.src===m&&D.width>0&&D.height>0?k:null,L=(0,s.useCallback)(e=>{let t=Math.min(Math.max(l,_),Math.max(l,e.zoom)),{x:n,y:r}=e;if(I){let i=f(I,D,e.rotation,t),a=Math.min(.5,D.width/i.scale/i.width/2),o=Math.min(.5,D.height/i.scale/i.height/2);n=Math.min(1-a,Math.max(a,n)),r=Math.min(1-o,Math.max(o,r))}return t===e.zoom&&n===e.x&&r===e.y?e:{...e,zoom:t,x:n,y:r}},[D,_,I]),R=(0,s.useMemo)(()=>L(j),[L,j]);(0,s.useEffect)(()=>{M(R)},[R]);let z=(0,s.useMemo)(()=>I?f(I,D,R.rotation,R.zoom):null,[I,D,R.rotation,R.zoom]),B=z?.scale??0,V=z?(.5-R.x)*z.width*B:0,H=z?(.5-R.y)*z.height*B:0,U=z?Math.max(0,(z.width*B-D.width)/2):0,W=z?Math.max(0,(z.height*B-D.height)/2):0,G=`Drag the picture to reposition it. Nothing is written until you save — ${U===0&&W===0?`at this zoom the whole picture is in frame.`:`the veiled edges are what gets trimmed.`}`;(0,s.useEffect)(()=>{if(!z)return;let e=Math.min(z.width,Math.round(D.width/z.scale)),t=Math.min(z.height,Math.round(D.height/z.scale)),[n,r]=d(R.x,R.y,360-R.rotation);y?.({x:Math.max(0,Math.min(z.width-e,Math.round(R.x*z.width-D.width/z.scale/2))),y:Math.max(0,Math.min(z.height-t,Math.round(R.y*z.height-D.height/z.scale/2))),width:e,height:t},{offsetX:V,offsetY:H,zoom:R.zoom,rotation:R.rotation,cx:n,cy:r})},[z,R,D,V,H]);let K=(e,t)=>M(n=>{if(!I)return n;let{width:r,height:i,scale:a}=f(I,D,n.rotation,n.zoom);return L({...n,x:n.x-e/(r*a),y:n.y-t/(i*a)})}),q=e=>M(t=>({...u,rotation:(t.rotation+e+360)%360})),J=e=>{e.button===0&&(E.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY},e.currentTarget.setPointerCapture(e.pointerId))},Y=e=>{let t=E.current;if(!t||t.pointerId!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;E.current={...t,x:e.clientX,y:e.clientY},K(n,r)},X=e=>{E.current?.pointerId===e.pointerId&&(E.current=null,e.currentTarget.releasePointerCapture?.(e.pointerId))};return(0,c.jsxs)(i.Stack,{ref:C,className:[`ds-cropper`,x].filter(Boolean).join(` `),...a.n(S),children:[(0,c.jsxs)(`div`,{role:`application`,"aria-label":`Crop area — drag to reposition, arrow keys to nudge`,tabIndex:0,className:`ds-cropper__stage`,style:{"--cropper-aspect":String(g)},onPointerDown:J,onPointerMove:Y,onPointerUp:X,onPointerCancel:X,onKeyDown:e=>{let t=e.shiftKey?24:8,n={ArrowLeft:[-t,0],ArrowRight:[t,0],ArrowUp:[0,-t],ArrowDown:[0,t]}[e.key];n&&(e.preventDefault(),K(n[0],n[1]))},children:[(0,c.jsx)(`img`,{ref:T,src:m,alt:h,draggable:!1,className:`ds-cropper__image`,onLoad:e=>F(e.currentTarget),style:{inlineSize:I?I.width*B:void 0,blockSize:I?I.height*B:void 0,transform:`translate(calc(-50% + ${V}px), calc(-50% + ${H}px)) rotate(${R.rotation}deg)`}}),(0,c.jsx)(`div`,{className:`ds-cropper__frame`,ref:w,"aria-hidden":`true`,children:(0,c.jsx)(`div`,{className:`ds-cropper__guides`})})]}),(0,c.jsx)(r.Field,{label:`Zoom`,hint:G,children:t=>(0,c.jsxs)(i.Stack,{direction:`horizontal`,gap:`md`,align:`center`,wrap:!0,children:[(0,c.jsx)(i.Stack,{style:{flex:`1 1 50%`,minInlineSize:0},children:(0,c.jsx)(o.n,{...t,min:l,max:Math.max(l,_),step:.01,value:R.zoom,suffix:`×`,onValueChange:e=>M(t=>L({...t,zoom:e}))})}),(0,c.jsxs)(n.ButtonGroup,{"aria-label":`Crop actions`,children:[v&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(e.Button,{size:`sm`,iconStart:`rotate-ccw`,"aria-label":`Rotate left`,onClick:()=>q(-90)}),(0,c.jsx)(e.Button,{size:`sm`,iconStart:`rotate-cw`,"aria-label":`Rotate right`,onClick:()=>q(90)})]}),(0,c.jsx)(e.Button,{size:`sm`,onClick:()=>M(u),children:`Reset`})]})]})})]})});async function h(e,t,{outputWidth:n,rotation:r=0,type:i=`image/png`,quality:a=.92}={}){let o=new Image;o.crossOrigin=`anonymous`,o.src=e,await o.decode();let s=r%180!=0,c=document.createElement(`canvas`);c.width=s?o.naturalHeight:o.naturalWidth,c.height=s?o.naturalWidth:o.naturalHeight;let l=c.getContext(`2d`);if(!l)throw Error(`Canvas 2D context unavailable`);l.translate(c.width/2,c.height/2),l.rotate(r*Math.PI/180),l.drawImage(o,-o.naturalWidth/2,-o.naturalHeight/2);let u=n??t.width,d=Math.round(t.height/t.width*u),f=document.createElement(`canvas`);f.width=u,f.height=d;let p=f.getContext(`2d`);if(!p)throw Error(`Canvas 2D context unavailable`);return p.drawImage(c,t.x,t.y,t.width,t.height,0,0,u,d),new Promise((e,t)=>{f.toBlob(n=>n?e(n):t(Error(`Could not encode the crop`)),i,a)})}exports.ImageCropper=m,exports.cropToBlob=h;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","useRef","useState","useCallback","useMemo","Stack","omitRequired","Field","Slider","ButtonGroup","_Fragment","Button","require_components_Button_index","require_useIsomorphicLayoutEffect","require_components_ButtonGroup_index","require_components_Field_index","require_binding","require_components_Grid_index","require_Slider","react","react_jsx_runtime","MIN_ZOOM","CENTRED","turnPoint","point","x","y","turns","degrees","project","quarter","rotation","width","picture","height","frame","zoom","seed","finite","value","fallback","fraction","saved","ImageCropper","rest","frameRef","imageRef","dragRef","setFrame","natural","setNatural","framing","setFraming","defaultState","shown","setShown","src","aspect","prev","adopt","img","node","measure","observer","clamp","maxZoom","next","view","halfX","halfY","bounded","scale","offsetX","offsetY","maxOffsetX","maxOffsetY","hint","cx","cy","onChange","pan","at","dx","dy","turn","by","onPointerDown","event","onPointerMove","drag","endDrag","className","step","move","props","rotatable","cropToBlob","image","turned","turnedContext","outputWidth","crop","canvas","context","blob","resolve","reject","type","quality"],"sources":["../../../src/components/ImageCropper/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { useIsomorphicLayoutEffect } from \"../../internal/useIsomorphicLayoutEffect\";\nimport { Button } from \"../Button\";\nimport { ButtonGroup } from \"../ButtonGroup\";\nimport { Field } from \"../Field\";\nimport { omitRequired } from \"../Field/binding\";\nimport { Stack } from \"../Grid\";\nimport { Slider } from \"../Slider\";\nimport \"./style.css\";\n\nexport interface CropRect {\n /** Left edge of the crop, in the (rotated) image's own pixels. */\n x: number;\n /** Top edge of the crop, in the (rotated) image's own pixels. */\n y: number;\n width: number;\n height: number;\n}\n\nexport interface CropState {\n /** Pan, in stage pixels, from the centre. Follows the stage size, so save `cx`/`cy`. */\n offsetX: number;\n offsetY: number;\n /** 1 is \"cover the crop window exactly\". */\n zoom: number;\n /** Quarter turns applied to the picture, clockwise: 0, 90, 180 or 270. */\n rotation: number;\n /** Crop centre as fractions of the unrotated source image. */\n cx: number;\n cy: number;\n}\n\n/** A saved selection. Every emitted `CropState` is one, so it can be passed straight back. */\nexport interface ImageCropperDefaultState {\n /** Zoom at initialization; clamped to the supported range. */\n zoom: number;\n /** Crop centre as fractions of the unrotated source image. */\n cx: number;\n cy: number;\n /** Clockwise quarter turns, snapped to 0, 90, 180 or 270. Defaults to 0. */\n rotation?: number;\n}\n\nexport interface ImageCropperProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n src: string;\n /** Uncontrolled initial selection. Applied again whenever `src` changes. */\n defaultState?: ImageCropperDefaultState;\n /** Describes the picture for people who cannot see the stage. */\n alt?: string;\n /** Required output shape, width / height. Must be positive and finite. */\n aspect: number;\n /** Highest allowed zoom. Past 3 the result is mush on most uploads. */\n maxZoom?: number;\n /** Offer the quarter-turn controls. */\n rotatable?: boolean;\n /** Fires on every pan, zoom, turn and reset, with the crop in image pixels. */\n onChange?: (crop: CropRect, state: CropState) => void;\n}\n\ninterface Size {\n width: number;\n height: number;\n}\n\n/** The selection as the engine keeps it, independent of the stage's size. */\ninterface Framing {\n zoom: number;\n rotation: number;\n /** Frame centre as fractions of the picture as turned. */\n x: number;\n y: number;\n}\n\nconst MIN_ZOOM = 1;\nconst CENTRED: Framing = { zoom: 1, rotation: 0, x: 0.5, y: 0.5 };\n\n/** Carries a point, in fractions of a picture, through clockwise quarter turns of it. */\nfunction turnPoint(x: number, y: number, degrees: number): [number, number] {\n let point: [number, number] = [x, y];\n for (let turns = Math.round(degrees / 90) % 4; turns > 0; turns--) {\n point = [1 - point[1], point[0]];\n }\n return point;\n}\n\n/** The turned picture's size, and the stage scale at which it covers the frame at this zoom. */\nfunction project(picture: Size, frame: Size, rotation: number, zoom: number) {\n const quarter = rotation % 180 !== 0;\n const width = quarter ? picture.height : picture.width;\n const height = quarter ? picture.width : picture.height;\n return {\n width,\n height,\n scale: Math.max(frame.width / width, frame.height / height) * zoom,\n };\n}\n\n/** Reads a saved selection, falling back to the centre for anything unusable. */\nfunction seed(saved: ImageCropperDefaultState | undefined): Framing {\n const finite = (value: number | undefined, fallback: number) =>\n value != null && Number.isFinite(value) ? value : fallback;\n const fraction = (value: number | undefined) => Math.min(1, Math.max(0, finite(value, 0.5)));\n const rotation = (((Math.round(finite(saved?.rotation, 0) / 90) * 90) % 360) + 360) % 360;\n const [x, y] = turnPoint(fraction(saved?.cx), fraction(saved?.cy), rotation);\n return { zoom: finite(saved?.zoom, 1), rotation, x, y };\n}\n\n/**\n * Pan-and-zoom cropping over a fixed frame. The frame never moves — the\n * picture does — and the parts that fall outside it stay visible under a\n * veil, so the reader can see what they are trimming away.\n * Drag with a pointer, or focus the stage and use the arrow keys.\n */\nexport const ImageCropper = forwardRef<HTMLDivElement, ImageCropperProps>(function ImageCropper(\n {\n src,\n alt = \"\",\n aspect,\n maxZoom = 3,\n rotatable = true,\n onChange,\n defaultState,\n className,\n ...rest\n },\n ref,\n) {\n const frameRef = useRef<HTMLDivElement | null>(null);\n const imageRef = useRef<HTMLImageElement | null>(null);\n const dragRef = useRef<{ pointerId: number; x: number; y: number } | null>(null);\n const [frame, setFrame] = useState<Size>({ width: 0, height: 0 });\n const [natural, setNatural] = useState<(Size & { src: string }) | null>(null);\n const [framing, setFraming] = useState(() => seed(defaultState));\n const [shown, setShown] = useState({ src, aspect });\n\n // A new source starts again from the saved selection; a new shape starts\n // centred and keeps the turn. Adjusting while rendering means no commit\n // pairs the previous selection with the new picture or frame.\n if (shown.src !== src || shown.aspect !== aspect) {\n setShown({ src, aspect });\n setFraming((prev) =>\n shown.src !== src ? seed(defaultState) : { ...CENTRED, rotation: prev.rotation },\n );\n }\n\n /** Take the picture's own pixels. Repeated load events for it change nothing. */\n const adopt = useCallback(\n (img: HTMLImageElement) => {\n const { naturalWidth: width, naturalHeight: height } = img;\n if (!width || !height) {\n return;\n }\n setNatural((prev) =>\n prev?.src === src && prev.width === width && prev.height === height\n ? prev\n : { src, width, height },\n );\n },\n [src],\n );\n\n // A cached or server-rendered image can already be decoded before React\n // attaches onLoad, and then that event never fires.\n useEffect(() => {\n const img = imageRef.current;\n if (img?.complete) {\n adopt(img);\n }\n }, [adopt]);\n\n useIsomorphicLayoutEffect(() => {\n const node = frameRef.current;\n if (!node) {\n return;\n }\n const measure = () => {\n const width = node.clientWidth;\n const height = node.clientHeight;\n setFrame((prev) =>\n prev.width === width && prev.height === height ? prev : { width, height },\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, [aspect]);\n\n // Nothing is measured or reported until this source has loaded into a sized frame.\n const picture = natural?.src === src && frame.width > 0 && frame.height > 0 ? natural : null;\n\n const clamp = useCallback(\n (next: Framing): Framing => {\n const zoom = Math.min(Math.max(MIN_ZOOM, maxZoom), Math.max(MIN_ZOOM, next.zoom));\n let { x, y } = next;\n if (picture) {\n // The frame's half-width and half-height, as shares of the picture.\n const view = project(picture, frame, next.rotation, zoom);\n const halfX = Math.min(0.5, frame.width / view.scale / view.width / 2);\n const halfY = Math.min(0.5, frame.height / view.scale / view.height / 2);\n x = Math.min(1 - halfX, Math.max(halfX, x));\n y = Math.min(1 - halfY, Math.max(halfY, y));\n }\n if (zoom === next.zoom && x === next.x && y === next.y) {\n return next;\n }\n return { ...next, zoom, x, y };\n },\n [frame, maxZoom, picture],\n );\n\n // Keep the rendered transform bounded when the frame or zoom limit changes too.\n const bounded = useMemo(() => clamp(framing), [clamp, framing]);\n useEffect(() => {\n setFraming(bounded);\n }, [bounded]);\n\n const view = useMemo(\n () => (picture ? project(picture, frame, bounded.rotation, bounded.zoom) : null),\n [picture, frame, bounded.rotation, bounded.zoom],\n );\n const scale = view?.scale ?? 0;\n const offsetX = view ? (0.5 - bounded.x) * view.width * scale : 0;\n const offsetY = view ? (0.5 - bounded.y) * view.height * scale : 0;\n const maxOffsetX = view ? Math.max(0, (view.width * scale - frame.width) / 2) : 0;\n const maxOffsetY = view ? Math.max(0, (view.height * scale - frame.height) / 2) : 0;\n const hint = `Drag the picture to reposition it. Nothing is written until you save — ${\n maxOffsetX === 0 && maxOffsetY === 0\n ? \"at this zoom the whole picture is in frame.\"\n : \"the veiled edges are what gets trimmed.\"\n }`;\n\n // A passive effect, so a parent that re-renders on every report never\n // delays the frame that paints a drag.\n useEffect(() => {\n if (!view) {\n return;\n }\n const width = Math.min(view.width, Math.round(frame.width / view.scale));\n const height = Math.min(view.height, Math.round(frame.height / view.scale));\n const [cx, cy] = turnPoint(bounded.x, bounded.y, 360 - bounded.rotation);\n onChange?.(\n {\n x: Math.max(\n 0,\n Math.min(\n view.width - width,\n Math.round(bounded.x * view.width - frame.width / view.scale / 2),\n ),\n ),\n y: Math.max(\n 0,\n Math.min(\n view.height - height,\n Math.round(bounded.y * view.height - frame.height / view.scale / 2),\n ),\n ),\n width,\n height,\n },\n {\n offsetX,\n offsetY,\n zoom: bounded.zoom,\n rotation: bounded.rotation,\n cx,\n cy,\n },\n );\n // onChange is intentionally not a dependency: callers pass inline handlers.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [view, bounded, frame, offsetX, offsetY]);\n\n /** Move the picture by stage pixels; the frame centre travels the other way. */\n const pan = (dx: number, dy: number) =>\n setFraming((prev) => {\n if (!picture) {\n return prev;\n }\n const { width, height, scale: at } = project(picture, frame, prev.rotation, prev.zoom);\n return clamp({\n ...prev,\n x: prev.x - dx / (width * at),\n y: prev.y - dy / (height * at),\n });\n });\n\n const turn = (by: number) =>\n setFraming((prev) => ({\n ...CENTRED,\n rotation: (prev.rotation + by + 360) % 360,\n }));\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) {\n return;\n }\n dragRef.current = {\n pointerId: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n };\n event.currentTarget.setPointerCapture(event.pointerId);\n };\n\n const onPointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== event.pointerId) {\n return;\n }\n const dx = event.clientX - drag.x;\n const dy = event.clientY - drag.y;\n dragRef.current = { ...drag, x: event.clientX, y: event.clientY };\n pan(dx, dy);\n };\n\n const endDrag = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) {\n return;\n }\n dragRef.current = null;\n event.currentTarget.releasePointerCapture?.(event.pointerId);\n };\n\n return (\n <Stack\n ref={ref}\n className={[\"ds-cropper\", className].filter(Boolean).join(\" \")}\n {...omitRequired(rest)}\n >\n <div\n role=\"application\"\n aria-label=\"Crop area — drag to reposition, arrow keys to nudge\"\n tabIndex={0}\n className=\"ds-cropper__stage\"\n style={{ \"--cropper-aspect\": String(aspect) } as CSSProperties}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n onKeyDown={(event) => {\n const step = event.shiftKey ? 24 : 8;\n const moves: Record<string, [number, number]> = {\n ArrowLeft: [-step, 0],\n ArrowRight: [step, 0],\n ArrowUp: [0, -step],\n ArrowDown: [0, step],\n };\n const move = moves[event.key];\n if (!move) {\n return;\n }\n event.preventDefault();\n pan(move[0], move[1]);\n }}\n >\n <img\n ref={imageRef}\n src={src}\n alt={alt}\n draggable={false}\n className=\"ds-cropper__image\"\n onLoad={(event) => adopt(event.currentTarget)}\n style={{\n inlineSize: picture ? picture.width * scale : undefined,\n blockSize: picture ? picture.height * scale : undefined,\n transform: `translate(calc(-50% + ${offsetX}px), calc(-50% + ${offsetY}px)) rotate(${bounded.rotation}deg)`,\n }}\n />\n {/* The window: everything outside it is veiled, not hidden. */}\n <div\n className=\"ds-cropper__frame\"\n ref={frameRef}\n aria-hidden=\"true\"\n >\n <div className=\"ds-cropper__guides\" />\n </div>\n </div>\n\n <Field\n label=\"Zoom\"\n hint={hint}\n >\n {(props) => (\n <Stack\n direction=\"horizontal\"\n gap=\"md\"\n align=\"center\"\n wrap\n >\n <Stack style={{ flex: \"1 1 50%\", minInlineSize: 0 }}>\n <Slider\n {...props}\n min={MIN_ZOOM}\n max={Math.max(MIN_ZOOM, maxZoom)}\n step={0.01}\n value={bounded.zoom}\n suffix=\"×\"\n onValueChange={(zoom) => setFraming((prev) => clamp({ ...prev, zoom }))}\n />\n </Stack>\n <ButtonGroup aria-label=\"Crop actions\">\n {rotatable && (\n <>\n <Button\n size=\"sm\"\n iconStart=\"rotate-ccw\"\n aria-label=\"Rotate left\"\n onClick={() => turn(-90)}\n />\n <Button\n size=\"sm\"\n iconStart=\"rotate-cw\"\n aria-label=\"Rotate right\"\n onClick={() => turn(90)}\n />\n </>\n )}\n <Button\n size=\"sm\"\n onClick={() => setFraming(CENTRED)}\n >\n Reset\n </Button>\n </ButtonGroup>\n </Stack>\n )}\n </Field>\n </Stack>\n );\n});\n\nexport interface CropToBlobOptions {\n /** Width of the output in pixels; the height follows the crop's aspect. */\n outputWidth?: number;\n /** Quarter turns applied before cropping — pass `state.rotation`. */\n rotation?: number;\n type?: \"image/png\" | \"image/jpeg\" | \"image/webp\";\n quality?: number;\n}\n\n/**\n * Renders a `CropRect` to an image blob in the browser. Same-origin or\n * CORS-enabled sources only — a tainted canvas cannot be exported.\n */\nexport async function cropToBlob(\n src: string,\n crop: CropRect,\n { outputWidth, rotation = 0, type = \"image/png\", quality = 0.92 }: CropToBlobOptions = {},\n): Promise<Blob> {\n const image = new Image();\n image.crossOrigin = \"anonymous\";\n image.src = src;\n await image.decode();\n\n // The crop is expressed against the turned picture, so turn it first.\n const quarter = rotation % 180 !== 0;\n const turned = document.createElement(\"canvas\");\n turned.width = quarter ? image.naturalHeight : image.naturalWidth;\n turned.height = quarter ? image.naturalWidth : image.naturalHeight;\n const turnedContext = turned.getContext(\"2d\");\n if (!turnedContext) {\n throw new Error(\"Canvas 2D context unavailable\");\n }\n turnedContext.translate(turned.width / 2, turned.height / 2);\n turnedContext.rotate((rotation * Math.PI) / 180);\n turnedContext.drawImage(image, -image.naturalWidth / 2, -image.naturalHeight / 2);\n\n const width = outputWidth ?? crop.width;\n const height = Math.round((crop.height / crop.width) * width);\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n const context = canvas.getContext(\"2d\");\n if (!context) {\n throw new Error(\"Canvas 2D context unavailable\");\n }\n context.drawImage(turned, crop.x, crop.y, crop.width, crop.height, 0, 0, width, height);\n\n return new Promise((resolve, reject) => {\n canvas.toBlob(\n (blob) => (blob ? resolve(blob) : reject(new Error(\"Could not encode the crop\"))),\n type,\n quality,\n );\n });\n}\n"],"mappings":"A,maAmFA,IAAMqB,EAAW,EACXC,EAAmB,CAAE,KAAM,EAAG,SAAU,EAAG,EAAG,GAAK,EAAG,EAAI,EAGhE,SAASC,EAAU,EAAW,EAAW,EAAmC,CAC1E,IAAIC,EAA0B,CAACC,EAAGC,CAAC,EACnC,IAAK,IAAIC,EAAQ,KAAK,MAAMC,EAAU,EAAE,EAAI,EAAGD,EAAQ,EAAG,IACxD,EAAQ,CAAC,EAAIH,EAAM,GAAIA,EAAM,EAAE,EAEjC,OAAOA,CACT,CAGA,SAASK,EAAQ,EAAe,EAAa,EAAkB,EAAc,CAC3E,IAAMC,EAAUC,EAAW,KAAQ,EAC7BC,EAAQF,EAAUG,EAAQ,OAAS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A+B,EAIjD,OAFAA,EAAQ,UAAUL,EAAQG,EAAK,EAAGA,EAAK,EAAGA,EAAK,MAAOA,EAAK,OAAQ,EAAG,EAAGrE,EAAOE,CAAM,EAE/E,IAAI,SAAS,EAAS,IAAW,CACtCoE,EAAO,OACJ,GAAUE,EAAOC,EAAQD,CAAI,EAAIE,EAAW,MAAM,2BAA2B,CAAC,EAC/EC,EACAC,CACF,CACF,CAAC,CACH,C"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","useRef","useState","useCallback","useMemo","Stack","omitRequired","Field","Slider","ButtonGroup","_Fragment","Button","require_components_Button_index","require_useIsomorphicLayoutEffect","require_components_ButtonGroup_index","require_components_Field_index","require_components_Grid_index","require_binding","require_Slider","react","react_jsx_runtime","MIN_ZOOM","CENTRED","turnPoint","point","x","y","turns","degrees","project","quarter","rotation","width","picture","height","frame","zoom","seed","finite","value","fallback","fraction","saved","ImageCropper","rest","frameRef","imageRef","dragRef","setFrame","natural","setNatural","framing","setFraming","defaultState","shown","setShown","src","aspect","prev","adopt","img","node","measure","observer","clamp","maxZoom","next","view","halfX","halfY","bounded","scale","offsetX","offsetY","maxOffsetX","maxOffsetY","hint","cx","cy","onChange","pan","at","dx","dy","turn","by","onPointerDown","event","onPointerMove","drag","endDrag","className","step","move","props","rotatable","cropToBlob","image","turned","turnedContext","outputWidth","crop","canvas","context","blob","resolve","reject","type","quality"],"sources":["../../../src/components/ImageCropper/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { useIsomorphicLayoutEffect } from \"../../internal/useIsomorphicLayoutEffect\";\nimport { Button } from \"../Button\";\nimport { ButtonGroup } from \"../ButtonGroup\";\nimport { Field } from \"../Field\";\nimport { omitRequired } from \"../Field/binding\";\nimport { Stack } from \"../Grid\";\nimport { Slider } from \"../Slider\";\nimport \"./style.css\";\n\nexport interface CropRect {\n /** Left edge of the crop, in the (rotated) image's own pixels. */\n x: number;\n /** Top edge of the crop, in the (rotated) image's own pixels. */\n y: number;\n width: number;\n height: number;\n}\n\nexport interface CropState {\n /** Pan, in stage pixels, from the centre. Follows the stage size, so save `cx`/`cy`. */\n offsetX: number;\n offsetY: number;\n /** 1 is \"cover the crop window exactly\". */\n zoom: number;\n /** Quarter turns applied to the picture, clockwise: 0, 90, 180 or 270. */\n rotation: number;\n /** Crop centre as fractions of the unrotated source image. */\n cx: number;\n cy: number;\n}\n\n/** A saved selection. Every emitted `CropState` is one, so it can be passed straight back. */\nexport interface ImageCropperDefaultState {\n /** Zoom at initialization; clamped to the supported range. */\n zoom: number;\n /** Crop centre as fractions of the unrotated source image. */\n cx: number;\n cy: number;\n /** Clockwise quarter turns, snapped to 0, 90, 180 or 270. Defaults to 0. */\n rotation?: number;\n}\n\nexport interface ImageCropperProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n src: string;\n /** Uncontrolled initial selection. Applied again whenever `src` changes. */\n defaultState?: ImageCropperDefaultState;\n /** Describes the picture for people who cannot see the stage. */\n alt?: string;\n /** Required output shape, width / height. Must be positive and finite. */\n aspect: number;\n /** Highest allowed zoom. Past 3 the result is mush on most uploads. */\n maxZoom?: number;\n /** Offer the quarter-turn controls. */\n rotatable?: boolean;\n /** Fires on every pan, zoom, turn and reset, with the crop in image pixels. */\n onChange?: (crop: CropRect, state: CropState) => void;\n}\n\ninterface Size {\n width: number;\n height: number;\n}\n\n/** The selection as the engine keeps it, independent of the stage's size. */\ninterface Framing {\n zoom: number;\n rotation: number;\n /** Frame centre as fractions of the picture as turned. */\n x: number;\n y: number;\n}\n\nconst MIN_ZOOM = 1;\nconst CENTRED: Framing = { zoom: 1, rotation: 0, x: 0.5, y: 0.5 };\n\n/** Carries a point, in fractions of a picture, through clockwise quarter turns of it. */\nfunction turnPoint(x: number, y: number, degrees: number): [number, number] {\n let point: [number, number] = [x, y];\n for (let turns = Math.round(degrees / 90) % 4; turns > 0; turns--) {\n point = [1 - point[1], point[0]];\n }\n return point;\n}\n\n/** The turned picture's size, and the stage scale at which it covers the frame at this zoom. */\nfunction project(picture: Size, frame: Size, rotation: number, zoom: number) {\n const quarter = rotation % 180 !== 0;\n const width = quarter ? picture.height : picture.width;\n const height = quarter ? picture.width : picture.height;\n return {\n width,\n height,\n scale: Math.max(frame.width / width, frame.height / height) * zoom,\n };\n}\n\n/** Reads a saved selection, falling back to the centre for anything unusable. */\nfunction seed(saved: ImageCropperDefaultState | undefined): Framing {\n const finite = (value: number | undefined, fallback: number) =>\n value != null && Number.isFinite(value) ? value : fallback;\n const fraction = (value: number | undefined) => Math.min(1, Math.max(0, finite(value, 0.5)));\n const rotation = (((Math.round(finite(saved?.rotation, 0) / 90) * 90) % 360) + 360) % 360;\n const [x, y] = turnPoint(fraction(saved?.cx), fraction(saved?.cy), rotation);\n return { zoom: finite(saved?.zoom, 1), rotation, x, y };\n}\n\n/**\n * Pan-and-zoom cropping over a fixed frame. The frame never moves — the\n * picture does — and the parts that fall outside it stay visible under a\n * veil, so the reader can see what they are trimming away.\n * Drag with a pointer, or focus the stage and use the arrow keys.\n */\nexport const ImageCropper = forwardRef<HTMLDivElement, ImageCropperProps>(function ImageCropper(\n {\n src,\n alt = \"\",\n aspect,\n maxZoom = 3,\n rotatable = true,\n onChange,\n defaultState,\n className,\n ...rest\n },\n ref,\n) {\n const frameRef = useRef<HTMLDivElement | null>(null);\n const imageRef = useRef<HTMLImageElement | null>(null);\n const dragRef = useRef<{ pointerId: number; x: number; y: number } | null>(null);\n const [frame, setFrame] = useState<Size>({ width: 0, height: 0 });\n const [natural, setNatural] = useState<(Size & { src: string }) | null>(null);\n const [framing, setFraming] = useState(() => seed(defaultState));\n const [shown, setShown] = useState({ src, aspect });\n\n // A new source starts again from the saved selection; a new shape starts\n // centred and keeps the turn. Adjusting while rendering means no commit\n // pairs the previous selection with the new picture or frame.\n if (shown.src !== src || shown.aspect !== aspect) {\n setShown({ src, aspect });\n setFraming((prev) =>\n shown.src !== src ? seed(defaultState) : { ...CENTRED, rotation: prev.rotation },\n );\n }\n\n /** Take the picture's own pixels. Repeated load events for it change nothing. */\n const adopt = useCallback(\n (img: HTMLImageElement) => {\n const { naturalWidth: width, naturalHeight: height } = img;\n if (!width || !height) {\n return;\n }\n setNatural((prev) =>\n prev?.src === src && prev.width === width && prev.height === height\n ? prev\n : { src, width, height },\n );\n },\n [src],\n );\n\n // A cached or server-rendered image can already be decoded before React\n // attaches onLoad, and then that event never fires.\n useEffect(() => {\n const img = imageRef.current;\n if (img?.complete) {\n adopt(img);\n }\n }, [adopt]);\n\n useIsomorphicLayoutEffect(() => {\n const node = frameRef.current;\n if (!node) {\n return;\n }\n const measure = () => {\n const width = node.clientWidth;\n const height = node.clientHeight;\n setFrame((prev) =>\n prev.width === width && prev.height === height ? prev : { width, height },\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, [aspect]);\n\n // Nothing is measured or reported until this source has loaded into a sized frame.\n const picture = natural?.src === src && frame.width > 0 && frame.height > 0 ? natural : null;\n\n const clamp = useCallback(\n (next: Framing): Framing => {\n const zoom = Math.min(Math.max(MIN_ZOOM, maxZoom), Math.max(MIN_ZOOM, next.zoom));\n let { x, y } = next;\n if (picture) {\n // The frame's half-width and half-height, as shares of the picture.\n const view = project(picture, frame, next.rotation, zoom);\n const halfX = Math.min(0.5, frame.width / view.scale / view.width / 2);\n const halfY = Math.min(0.5, frame.height / view.scale / view.height / 2);\n x = Math.min(1 - halfX, Math.max(halfX, x));\n y = Math.min(1 - halfY, Math.max(halfY, y));\n }\n if (zoom === next.zoom && x === next.x && y === next.y) {\n return next;\n }\n return { ...next, zoom, x, y };\n },\n [frame, maxZoom, picture],\n );\n\n // Keep the rendered transform bounded when the frame or zoom limit changes too.\n const bounded = useMemo(() => clamp(framing), [clamp, framing]);\n useEffect(() => {\n setFraming(bounded);\n }, [bounded]);\n\n const view = useMemo(\n () => (picture ? project(picture, frame, bounded.rotation, bounded.zoom) : null),\n [picture, frame, bounded.rotation, bounded.zoom],\n );\n const scale = view?.scale ?? 0;\n const offsetX = view ? (0.5 - bounded.x) * view.width * scale : 0;\n const offsetY = view ? (0.5 - bounded.y) * view.height * scale : 0;\n const maxOffsetX = view ? Math.max(0, (view.width * scale - frame.width) / 2) : 0;\n const maxOffsetY = view ? Math.max(0, (view.height * scale - frame.height) / 2) : 0;\n const hint = `Drag the picture to reposition it. Nothing is written until you save — ${\n maxOffsetX === 0 && maxOffsetY === 0\n ? \"at this zoom the whole picture is in frame.\"\n : \"the veiled edges are what gets trimmed.\"\n }`;\n\n // A passive effect, so a parent that re-renders on every report never\n // delays the frame that paints a drag.\n useEffect(() => {\n if (!view) {\n return;\n }\n const width = Math.min(view.width, Math.round(frame.width / view.scale));\n const height = Math.min(view.height, Math.round(frame.height / view.scale));\n const [cx, cy] = turnPoint(bounded.x, bounded.y, 360 - bounded.rotation);\n onChange?.(\n {\n x: Math.max(\n 0,\n Math.min(\n view.width - width,\n Math.round(bounded.x * view.width - frame.width / view.scale / 2),\n ),\n ),\n y: Math.max(\n 0,\n Math.min(\n view.height - height,\n Math.round(bounded.y * view.height - frame.height / view.scale / 2),\n ),\n ),\n width,\n height,\n },\n {\n offsetX,\n offsetY,\n zoom: bounded.zoom,\n rotation: bounded.rotation,\n cx,\n cy,\n },\n );\n // onChange is intentionally not a dependency: callers pass inline handlers.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [view, bounded, frame, offsetX, offsetY]);\n\n /** Move the picture by stage pixels; the frame centre travels the other way. */\n const pan = (dx: number, dy: number) =>\n setFraming((prev) => {\n if (!picture) {\n return prev;\n }\n const { width, height, scale: at } = project(picture, frame, prev.rotation, prev.zoom);\n return clamp({\n ...prev,\n x: prev.x - dx / (width * at),\n y: prev.y - dy / (height * at),\n });\n });\n\n const turn = (by: number) =>\n setFraming((prev) => ({\n ...CENTRED,\n rotation: (prev.rotation + by + 360) % 360,\n }));\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) {\n return;\n }\n dragRef.current = {\n pointerId: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n };\n event.currentTarget.setPointerCapture(event.pointerId);\n };\n\n const onPointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n if (!drag || drag.pointerId !== event.pointerId) {\n return;\n }\n const dx = event.clientX - drag.x;\n const dy = event.clientY - drag.y;\n dragRef.current = { ...drag, x: event.clientX, y: event.clientY };\n pan(dx, dy);\n };\n\n const endDrag = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) {\n return;\n }\n dragRef.current = null;\n event.currentTarget.releasePointerCapture?.(event.pointerId);\n };\n\n return (\n <Stack\n ref={ref}\n className={[\"ds-cropper\", className].filter(Boolean).join(\" \")}\n {...omitRequired(rest)}\n >\n <div\n role=\"application\"\n aria-label=\"Crop area — drag to reposition, arrow keys to nudge\"\n tabIndex={0}\n className=\"ds-cropper__stage\"\n style={{ \"--cropper-aspect\": String(aspect) } as CSSProperties}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={endDrag}\n onPointerCancel={endDrag}\n onKeyDown={(event) => {\n const step = event.shiftKey ? 24 : 8;\n const moves: Record<string, [number, number]> = {\n ArrowLeft: [-step, 0],\n ArrowRight: [step, 0],\n ArrowUp: [0, -step],\n ArrowDown: [0, step],\n };\n const move = moves[event.key];\n if (!move) {\n return;\n }\n event.preventDefault();\n pan(move[0], move[1]);\n }}\n >\n <img\n ref={imageRef}\n src={src}\n alt={alt}\n draggable={false}\n className=\"ds-cropper__image\"\n onLoad={(event) => adopt(event.currentTarget)}\n style={{\n inlineSize: picture ? picture.width * scale : undefined,\n blockSize: picture ? picture.height * scale : undefined,\n transform: `translate(calc(-50% + ${offsetX}px), calc(-50% + ${offsetY}px)) rotate(${bounded.rotation}deg)`,\n }}\n />\n {/* The window: everything outside it is veiled, not hidden. */}\n <div\n className=\"ds-cropper__frame\"\n ref={frameRef}\n aria-hidden=\"true\"\n >\n <div className=\"ds-cropper__guides\" />\n </div>\n </div>\n\n <Field\n label=\"Zoom\"\n hint={hint}\n >\n {(props) => (\n <Stack\n direction=\"horizontal\"\n gap=\"md\"\n align=\"center\"\n wrap\n >\n <Stack style={{ flex: \"1 1 50%\", minInlineSize: 0 }}>\n <Slider\n {...props}\n min={MIN_ZOOM}\n max={Math.max(MIN_ZOOM, maxZoom)}\n step={0.01}\n value={bounded.zoom}\n suffix=\"×\"\n onValueChange={(zoom) => setFraming((prev) => clamp({ ...prev, zoom }))}\n />\n </Stack>\n <ButtonGroup aria-label=\"Crop actions\">\n {rotatable && (\n <>\n <Button\n size=\"sm\"\n iconStart=\"rotate-ccw\"\n aria-label=\"Rotate left\"\n onClick={() => turn(-90)}\n />\n <Button\n size=\"sm\"\n iconStart=\"rotate-cw\"\n aria-label=\"Rotate right\"\n onClick={() => turn(90)}\n />\n </>\n )}\n <Button\n size=\"sm\"\n onClick={() => setFraming(CENTRED)}\n >\n Reset\n </Button>\n </ButtonGroup>\n </Stack>\n )}\n </Field>\n </Stack>\n );\n});\n\nexport interface CropToBlobOptions {\n /** Width of the output in pixels; the height follows the crop's aspect. */\n outputWidth?: number;\n /** Quarter turns applied before cropping — pass `state.rotation`. */\n rotation?: number;\n type?: \"image/png\" | \"image/jpeg\" | \"image/webp\";\n quality?: number;\n}\n\n/**\n * Renders a `CropRect` to an image blob in the browser. Same-origin or\n * CORS-enabled sources only — a tainted canvas cannot be exported.\n */\nexport async function cropToBlob(\n src: string,\n crop: CropRect,\n { outputWidth, rotation = 0, type = \"image/png\", quality = 0.92 }: CropToBlobOptions = {},\n): Promise<Blob> {\n const image = new Image();\n image.crossOrigin = \"anonymous\";\n image.src = src;\n await image.decode();\n\n // The crop is expressed against the turned picture, so turn it first.\n const quarter = rotation % 180 !== 0;\n const turned = document.createElement(\"canvas\");\n turned.width = quarter ? image.naturalHeight : image.naturalWidth;\n turned.height = quarter ? image.naturalWidth : image.naturalHeight;\n const turnedContext = turned.getContext(\"2d\");\n if (!turnedContext) {\n throw new Error(\"Canvas 2D context unavailable\");\n }\n turnedContext.translate(turned.width / 2, turned.height / 2);\n turnedContext.rotate((rotation * Math.PI) / 180);\n turnedContext.drawImage(image, -image.naturalWidth / 2, -image.naturalHeight / 2);\n\n const width = outputWidth ?? crop.width;\n const height = Math.round((crop.height / crop.width) * width);\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n const context = canvas.getContext(\"2d\");\n if (!context) {\n throw new Error(\"Canvas 2D context unavailable\");\n }\n context.drawImage(turned, crop.x, crop.y, crop.width, crop.height, 0, 0, width, height);\n\n return new Promise((resolve, reject) => {\n canvas.toBlob(\n (blob) => (blob ? resolve(blob) : reject(new Error(\"Could not encode the crop\"))),\n type,\n quality,\n );\n });\n}\n"],"mappings":"A,maAmFA,IAAMqB,EAAW,EACXC,EAAmB,CAAE,KAAM,EAAG,SAAU,EAAG,EAAG,GAAK,EAAG,EAAI,EAGhE,SAASC,EAAU,EAAW,EAAW,EAAmC,CAC1E,IAAIC,EAA0B,CAACC,EAAGC,CAAC,EACnC,IAAK,IAAIC,EAAQ,KAAK,MAAMC,EAAU,EAAE,EAAI,EAAGD,EAAQ,EAAG,IACxD,EAAQ,CAAC,EAAIH,EAAM,GAAIA,EAAM,EAAE,EAEjC,OAAOA,CACT,CAGA,SAASK,EAAQ,EAAe,EAAa,EAAkB,EAAc,CAC3E,IAAMC,EAAUC,EAAW,KAAQ,EAC7BC,EAAQF,EAAUG,EAAQ,OAASA,EAAQ,MAC3CC,EAASJ,EAAUG,EAAQ,MAAQA,EAAQ,OACjD,MAAO,CACL,QACA,SACA,MAAO,KAAK,IAAIE,EAAM,MAAQH,EAAOG,EAAM,OAASD,CAAM,EAAIE,CAChE,CACF,CAGA,SAASC,EAAK,EAAsD,CAClE,IAAMC,GAAU,EAA2B,I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AAW,MAAM,2BAA2B,CAAC,EAC/EC,EACAC,CACF,CACF,CAAC,CACH,C"}
|
|
@@ -2,8 +2,8 @@ import { Button as e } from "../Button/index.js";
|
|
|
2
2
|
import { t } from "../../chunks/useIsomorphicLayoutEffect-Bc9hxFMc.js";
|
|
3
3
|
import { ButtonGroup as n } from "../ButtonGroup/index.js";
|
|
4
4
|
import { Field as r } from "../Field/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Stack as i } from "../Grid/index.js";
|
|
6
|
+
import { n as a } from "../../chunks/binding-Bshy43sG.js";
|
|
7
7
|
import { n as o } from "../../chunks/Slider-Cab6NqhK.js";
|
|
8
8
|
import { forwardRef as s, useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
9
9
|
import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
@@ -154,10 +154,10 @@ var x = s(function({ src: s, alt: x = "", aspect: S, maxZoom: C = 3, rotatable:
|
|
|
154
154
|
}, $ = (e) => {
|
|
155
155
|
M.current?.pointerId === e.pointerId && (M.current = null, e.currentTarget.releasePointerCapture?.(e.pointerId));
|
|
156
156
|
};
|
|
157
|
-
return /* @__PURE__ */ h(
|
|
157
|
+
return /* @__PURE__ */ h(i, {
|
|
158
158
|
ref: k,
|
|
159
159
|
className: ["ds-cropper", D].filter(Boolean).join(" "),
|
|
160
|
-
...
|
|
160
|
+
...a(O),
|
|
161
161
|
children: [/* @__PURE__ */ h("div", {
|
|
162
162
|
role: "application",
|
|
163
163
|
"aria-label": "Crop area — drag to reposition, arrow keys to nudge",
|
|
@@ -198,12 +198,12 @@ var x = s(function({ src: s, alt: x = "", aspect: S, maxZoom: C = 3, rotatable:
|
|
|
198
198
|
}), /* @__PURE__ */ m(r, {
|
|
199
199
|
label: "Zoom",
|
|
200
200
|
hint: X,
|
|
201
|
-
children: (t) => /* @__PURE__ */ h(
|
|
201
|
+
children: (t) => /* @__PURE__ */ h(i, {
|
|
202
202
|
direction: "horizontal",
|
|
203
203
|
gap: "md",
|
|
204
204
|
align: "center",
|
|
205
205
|
wrap: !0,
|
|
206
|
-
children: [/* @__PURE__ */ m(
|
|
206
|
+
children: [/* @__PURE__ */ m(i, {
|
|
207
207
|
style: {
|
|
208
208
|
flex: "1 1 50%",
|
|
209
209
|
minInlineSize: 0
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs"),t=require("../../chunks/overlayLayer-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs"),t=require("../../chunks/overlayLayer-CtOTt1xB.cjs"),n=require("../Popover/index.cjs");let r=require("react"),i=require("react/jsx-runtime");function a(...e){return e.filter(Boolean).join(` `)}var o=(0,r.forwardRef)(function({trigger:e,align:o=`start`,className:s,children:c,onClick:l,onKeyDown:u,"aria-label":d,"aria-labelledby":f,...p},m){let[h,g]=(0,r.useState)(!1),_=t.o(h),v=(0,r.useRef)(null),y=(0,r.useRef)(null),b=(0,r.useRef)(null),x=(0,r.useId)(),S=(0,r.useCallback)(()=>g(!1),[]),C=(0,r.useCallback)(()=>{(y.current?.querySelector(`button, [href], [tabindex]`)??y.current)?.focus()},[]);(0,r.useEffect)(()=>{let e=_?b.current:null;typeof m==`function`?m(e):m&&(m.current=e)},[_,m]),(0,r.useEffect)(()=>{if(!_)return;let e=e=>{let t=e.target;!v.current?.contains(t)&&!b.current?.contains(t)&&S()},t=e=>{e.key===`Escape`&&(e.preventDefault(),S(),C())};document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t);let n=b.current;return(n?.querySelector(`[aria-checked="true"]:not(:disabled)`)??n?.querySelector(`button:not(:disabled)`))?.focus(),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_,S,C]);let w=e=>{if(e.key===`Tab`){e.preventDefault(),S(),e.shiftKey?C():v.current&&t.f(v.current);return}if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;e.preventDefault();let n=Array.from(b.current?.querySelectorAll(`button:not(:disabled)`)??[]);if(n.length===0)return;let r=n.indexOf(document.activeElement);(e.key===`ArrowDown`?n[(r+1)%n.length]:n[(r-1+n.length)%n.length])?.focus()};return(0,i.jsxs)(`div`,{className:`ds-menu-root`,ref:v,children:[(0,i.jsx)(`span`,{ref:y,className:`ds-menu-root`,children:e({"aria-haspopup":`menu`,"aria-expanded":_,"aria-controls":_?x:void 0,onClick:()=>g(e=>!e)})}),(0,i.jsx)(n.Popover,{anchorRef:y,isOpen:_,align:o,offset:8,id:x,role:`menu`,"aria-label":d,"aria-labelledby":f,className:a(`ds-surface-raised`,`ds-field-surface`,`ds-menu`,s),panelRef:b,children:(0,i.jsx)(`div`,{className:`ds-menu__list`,onKeyDown:e=>{u?.(e),e.defaultPrevented||w(e)},onClick:e=>{l?.(e);let n=e.target;if(e.defaultPrevented||!(n instanceof Element)||!n.closest(`button`))return;S();let r=document.activeElement;(t.d(r)||b.current?.contains(r))&&C()},...p,children:c})})]})}),s=(0,r.forwardRef)(function({icon:t,tone:n=`neutral`,shortcut:r,isDisabled:o=!1,className:s,children:c,...l},u){return(0,i.jsxs)(e.Button,{ref:u,variant:n===`danger`?`danger`:`simple`,size:`sm`,iconStart:t,role:`menuitem`,isDisabled:o,"data-tone":n===`danger`?`danger`:void 0,className:a(`ds-menu-item`,s),...l,children:[c,r&&(0,i.jsx)(`span`,{className:`ds-menu-item__shortcut`,children:r})]})});function c(){return(0,i.jsx)(`div`,{className:`ds-menu-separator`,role:`separator`})}function l({children:e}){return(0,i.jsx)(`div`,{className:`ds-menu-label`,children:e})}exports.Menu=o,exports.MenuItem=s,exports.MenuLabel=l,exports.MenuSeparator=c;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useOverlayOpen","useRef","useId","useCallback","Popover","Button","require_components_Button_index","require_overlayLayer","require_components_Popover_index","react","react_jsx_runtime","cx","parts","Menu","rest","open","setOpen","isOpen","rootRef","triggerRef","listRef","menuId","close","restoreTriggerFocus","node","ref","onPointerDown","target","event","onKeyDown","onListKeyDown","items","index","trigger","className","onClick","MenuItem","tone","icon","children","shortcut","MenuSeparator","MenuLabel"],"sources":["../../../src/components/Menu/index.tsx"],"sourcesContent":["import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { Popover } from \"../Popover\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport type MenuAlign = \"start\" | \"end\";\n\nexport interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Receives the props that open the menu — usually a `Button`. */\n trigger: (props: {\n \"aria-haspopup\": \"menu\";\n \"aria-expanded\": boolean;\n \"aria-controls\"?: string;\n onClick: () => void;\n }) => ReactElement;\n align?: MenuAlign;\n /** Menu items, labels and separators. */\n children: ReactNode;\n}\n\n/**\n * A short list of actions attached to a control. Closes on Escape, on outside\n * click and after any item is chosen; arrow keys walk the items.\n */\nexport const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(\n { trigger, align = \"start\", className, children, onClick, onKeyDown, ...rest },\n ref,\n) {\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const menuId = useId();\n\n const close = useCallback(() => setOpen(false), []);\n const restoreTriggerFocus = useCallback(() => {\n const focusTarget =\n triggerRef.current?.querySelector<HTMLElement>(\"button, [href], [tabindex]\") ??\n triggerRef.current;\n focusTarget?.focus();\n }, []);\n\n useEffect(() => {\n // A closing panel stays mounted, inert, for its fade-out; the forwarded ref\n // follows the open menu only, so it is null whenever the menu is closed.\n const node = isOpen ? listRef.current : null;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }, [isOpen, ref]);\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n close();\n }\n };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n close();\n restoreTriggerFocus();\n }\n };\n\n document.addEventListener(\"mousedown\", onPointerDown);\n document.addEventListener(\"keydown\", onKeyDown);\n listRef.current?.querySelector<HTMLButtonElement>(\"button:not(:disabled)\")?.focus();\n\n return () => {\n document.removeEventListener(\"mousedown\", onPointerDown);\n document.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [isOpen, close, restoreTriggerFocus]);\n\n const onListKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== \"ArrowDown\" && event.key !== \"ArrowUp\") {\n return;\n }\n event.preventDefault();\n const items = Array.from(\n listRef.current?.querySelectorAll<HTMLButtonElement>(\"button:not(:disabled)\") ?? [],\n );\n if (items.length === 0) {\n return;\n }\n const index = items.indexOf(document.activeElement as HTMLButtonElement);\n const next =\n event.key === \"ArrowDown\"\n ? items[(index + 1) % items.length]\n : items[(index - 1 + items.length) % items.length];\n next?.focus();\n };\n\n return (\n <div\n className=\"ds-menu-root\"\n ref={rootRef}\n >\n <span\n ref={triggerRef}\n className=\"ds-menu-root\"\n >\n {trigger({\n \"aria-haspopup\": \"menu\",\n \"aria-expanded\": isOpen,\n \"aria-controls\": isOpen ? menuId : undefined,\n onClick: () => setOpen((open) => !open),\n })}\n </span>\n <Popover\n anchorRef={triggerRef}\n isOpen={isOpen}\n align={align}\n offset={8}\n id={menuId}\n role=\"menu\"\n className={cx(\"ds-surface-raised\", \"ds-field-surface\", \"ds-menu\", className)}\n panelRef={listRef}\n >\n <div\n className=\"ds-menu__list\"\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n onListKeyDown(event);\n }\n }}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n close();\n restoreTriggerFocus();\n }\n }}\n {...rest}\n >\n {children}\n </div>\n </Popover>\n </div>\n );\n});\n\nexport type MenuItemTone = \"neutral\" | \"danger\";\n\nexport interface MenuItemProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"disabled\"> {\n icon?: IconName;\n tone?: MenuItemTone;\n /** Rendered right-aligned and muted, e.g. \"⌘K\". */\n shortcut?: string;\n isDisabled?: boolean;\n children?: ReactNode;\n}\n\nexport const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(function MenuItem(\n { icon, tone = \"neutral\", shortcut, isDisabled = false, className, children, ...rest },\n ref,\n) {\n return (\n <Button\n ref={ref}\n variant={tone === \"danger\" ? \"danger\" : \"simple\"}\n size=\"sm\"\n iconStart={icon}\n role=\"menuitem\"\n isDisabled={isDisabled}\n data-tone={tone === \"danger\" ? \"danger\" : undefined}\n className={cx(\"ds-menu-item\", className)}\n {...rest}\n >\n {children}\n {shortcut && <span className=\"ds-menu-item__shortcut\">{shortcut}</span>}\n </Button>\n );\n});\n\nexport function MenuSeparator() {\n return (\n <div\n className=\"ds-menu-separator\"\n role=\"separator\"\n />\n );\n}\n\nexport function MenuLabel({ children }: { children: ReactNode }) {\n return <div className=\"ds-menu-label\">{children}</div>;\n}\n"],"mappings":"A,sPAkBA,SAASa,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAqBA,IAAaC,GAAA,EAAOf,EAAAA,WAAAA,CAAsC,SACxD,CAAE,UAAS,QAAQ,QAAS,YAAW,WAAU,UAAS,YAAW,GAAGgB,GACxE,EAC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ACA,CACA,OACE,EAAAJ,EAAA,KAAA,CAACL,EAAAA,OAAD,CACO,MACL,QAASgC,IAAS,SAAW,SAAW,SACxC,KAAK,KACL,UAAWC,EACX,KAAK,WACO,aACZ,YAAWD,IAAS,SAAW,SAAW,IAAA,GAC1C,UAAW1B,EAAG,eAAgBuB,CAAS,EACvC,GAAIpB,EATN,SAAA,CAWGyB,EACAC,IAAY,EAAA9B,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,yBAA0B,SAAA8B,CAAe,CAAA,CAChE,C,EAEZ,CAAC,EAED,SAAgBC,GAAgB,CAC9B,OACE,EAAA/B,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,oBACV,KAAK,WACN,CAAA,CAEL,CAEA,SAAgBgC,EAAU,CAAE,YAAqC,CAC/D,OAAO,EAAAhC,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,gBAAiB,UAAc,CAAA,CACvD,C"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useOverlayOpen","useRef","useId","useCallback","Popover","cannotHoldFocus","Button","require_components_Button_index","require_overlayLayer","require_components_Popover_index","react","react_jsx_runtime","cx","parts","Menu","ariaLabel","labelledBy","rest","open","setOpen","isOpen","rootRef","triggerRef","listRef","menuId","close","restoreTriggerFocus","node","ref","onPointerDown","target","event","onKeyDown","list","onListKeyDown","items","index","trigger","className","onClick","active","MenuItem","tone","icon","children","shortcut","MenuSeparator","MenuLabel"],"sources":["../../../src/components/Menu/index.tsx"],"sourcesContent":["import { cannotHoldFocus, focusAfterField } from \"../../internal/dialogFocus\";\nimport { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { Popover } from \"../Popover\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport type MenuAlign = \"start\" | \"end\";\n\nexport interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Receives the props that open the menu — usually a `Button`. */\n trigger: (props: {\n \"aria-haspopup\": \"menu\";\n \"aria-expanded\": boolean;\n \"aria-controls\"?: string;\n onClick: () => void;\n }) => ReactElement;\n align?: MenuAlign;\n /** Menu items, labels and separators. */\n children: ReactNode;\n}\n\n/**\n * A short list of actions attached to a control. Opens on its checked item, if\n * any, else its first. Closes on Escape, on outside click, on Tab and after an\n * item is chosen; arrow keys walk the items. Its label names the menu.\n */\nexport const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(\n {\n trigger,\n align = \"start\",\n className,\n children,\n onClick,\n onKeyDown,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": labelledBy,\n ...rest\n },\n ref,\n) {\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const menuId = useId();\n\n const close = useCallback(() => setOpen(false), []);\n const restoreTriggerFocus = useCallback(() => {\n const focusTarget =\n triggerRef.current?.querySelector<HTMLElement>(\"button, [href], [tabindex]\") ??\n triggerRef.current;\n focusTarget?.focus();\n }, []);\n\n useEffect(() => {\n // A closing panel stays mounted, inert, for its fade-out; the forwarded ref\n // follows the open menu only, so it is null whenever the menu is closed.\n const node = isOpen ? listRef.current : null;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }, [isOpen, ref]);\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n close();\n }\n };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n close();\n restoreTriggerFocus();\n }\n };\n\n document.addEventListener(\"mousedown\", onPointerDown);\n document.addEventListener(\"keydown\", onKeyDown);\n // A checked item, such as the current choice among radio items, takes focus first.\n const list = listRef.current;\n (\n list?.querySelector<HTMLElement>('[aria-checked=\"true\"]:not(:disabled)') ??\n list?.querySelector<HTMLButtonElement>(\"button:not(:disabled)\")\n )?.focus();\n\n return () => {\n document.removeEventListener(\"mousedown\", onPointerDown);\n document.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [isOpen, close, restoreTriggerFocus]);\n\n const onListKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n // Tab leaves the menu as it would leave the trigger: onward past it, or back to it.\n if (event.key === \"Tab\") {\n event.preventDefault();\n close();\n if (event.shiftKey) {\n restoreTriggerFocus();\n } else if (rootRef.current) {\n focusAfterField(rootRef.current);\n }\n return;\n }\n if (event.key !== \"ArrowDown\" && event.key !== \"ArrowUp\") {\n return;\n }\n event.preventDefault();\n const items = Array.from(\n listRef.current?.querySelectorAll<HTMLButtonElement>(\"button:not(:disabled)\") ?? [],\n );\n if (items.length === 0) {\n return;\n }\n const index = items.indexOf(document.activeElement as HTMLButtonElement);\n const next =\n event.key === \"ArrowDown\"\n ? items[(index + 1) % items.length]\n : items[(index - 1 + items.length) % items.length];\n next?.focus();\n };\n\n return (\n <div\n className=\"ds-menu-root\"\n ref={rootRef}\n >\n <span\n ref={triggerRef}\n className=\"ds-menu-root\"\n >\n {trigger({\n \"aria-haspopup\": \"menu\",\n \"aria-expanded\": isOpen,\n \"aria-controls\": isOpen ? menuId : undefined,\n onClick: () => setOpen((open) => !open),\n })}\n </span>\n <Popover\n anchorRef={triggerRef}\n isOpen={isOpen}\n align={align}\n offset={8}\n id={menuId}\n role=\"menu\"\n aria-label={ariaLabel}\n aria-labelledby={labelledBy}\n className={cx(\"ds-surface-raised\", \"ds-field-surface\", \"ds-menu\", className)}\n panelRef={listRef}\n >\n <div\n className=\"ds-menu__list\"\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n onListKeyDown(event);\n }\n }}\n onClick={(event) => {\n onClick?.(event);\n // Only a chosen item closes the menu, not a click on a label, separator or gap.\n const target = event.target;\n if (\n event.defaultPrevented ||\n !(target instanceof Element) ||\n !target.closest(\"button\")\n ) {\n return;\n }\n close();\n // An item that moved focus, such as into the editor it changed, keeps it there.\n const active = document.activeElement;\n if (cannotHoldFocus(active) || listRef.current?.contains(active)) {\n restoreTriggerFocus();\n }\n }}\n {...rest}\n >\n {children}\n </div>\n </Popover>\n </div>\n );\n});\n\nexport type MenuItemTone = \"neutral\" | \"danger\";\n\nexport interface MenuItemProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"disabled\"> {\n icon?: IconName;\n tone?: MenuItemTone;\n /** Rendered right-aligned and muted, e.g. \"⌘K\". */\n shortcut?: string;\n isDisabled?: boolean;\n children?: ReactNode;\n}\n\nexport const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(function MenuItem(\n { icon, tone = \"neutral\", shortcut, isDisabled = false, className, children, ...rest },\n ref,\n) {\n return (\n <Button\n ref={ref}\n variant={tone === \"danger\" ? \"danger\" : \"simple\"}\n size=\"sm\"\n iconStart={icon}\n role=\"menuitem\"\n isDisabled={isDisabled}\n data-tone={tone === \"danger\" ? \"danger\" : undefined}\n className={cx(\"ds-menu-item\", className)}\n {...rest}\n >\n {children}\n {shortcut && <span className=\"ds-menu-item__shortcut\">{shortcut}</span>}\n </Button>\n );\n});\n\nexport function MenuSeparator() {\n return (\n <div\n className=\"ds-menu-separator\"\n role=\"separator\"\n />\n );\n}\n\nexport function MenuLabel({ children }: { children: ReactNode }) {\n return <div className=\"ds-menu-label\">{children}</div>;\n}\n"],"mappings":"A,sPAmBA,SAASc,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAsBA,IAAaC,GAAA,EAAOhB,EAAAA,WAAAA,CAAsC,SAC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AY,GAAU,CACpBqB,IAAYD,CAAK,EACZA,EAAM,kBACTG,EAAcH,CAAK,CAEvB,EACA,QAAU,GAAU,CAClBQ,IAAUR,CAAK,EAEf,IAAMD,EAASC,EAAM,OACrB,GACEA,EAAM,kBACN,EAAED,aAAkB,UACpB,CAACA,EAAO,QAAQ,QAAQ,EAExB,OAEFL,EAAM,EAEN,IAAMe,EAAS,SAAS,eACpBnC,EAAAA,EAAgBmC,CAAM,GAAKjB,EAAQ,SAAS,SAASiB,CAAM,IAC7Dd,EAAoB,CAExB,EACA,GAAIT,EAEH,UACE,CAAA,CACE,CAAA,CACN,C,EAET,CAAC,EAaYwB,GAAA,EAAW3C,EAAAA,WAAAA,CAA6C,SACnE,CAAE,OAAM,OAAO,UAAW,WAAU,aAAa,GAAO,YAAW,WAAU,GAAGmB,GAChF,EACA,CACA,OACE,EAAAN,EAAA,KAAA,CAACL,EAAAA,OAAD,CACO,MACL,QAASoC,IAAS,SAAW,SAAW,SACxC,KAAK,KACL,UAAWC,EACX,KAAK,WACO,aACZ,YAAWD,IAAS,SAAW,SAAW,IAAA,GAC1C,UAAW9B,EAAG,eAAgB0B,CAAS,EACvC,GAAIrB,EATN,SAAA,CAWG2B,EACAC,IAAY,EAAAlC,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,yBAA0B,SAAAkC,CAAe,CAAA,CAChE,C,EAEZ,CAAC,EAED,SAAgBC,GAAgB,CAC9B,OACE,EAAAnC,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,oBACV,KAAK,WACN,CAAA,CAEL,CAEA,SAAgBoC,EAAU,CAAE,YAAqC,CAC/D,OAAO,EAAApC,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,gBAAiB,UAAc,CAAA,CACvD,C"}
|
|
@@ -14,8 +14,9 @@ export interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, "childre
|
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* A short list of actions attached to a control.
|
|
18
|
-
*
|
|
17
|
+
* A short list of actions attached to a control. Opens on its checked item, if
|
|
18
|
+
* any, else its first. Closes on Escape, on outside click, on Tab and after an
|
|
19
|
+
* item is chosen; arrow keys walk the items. Its label names the menu.
|
|
19
20
|
*/
|
|
20
21
|
export declare const Menu: import("react").ForwardRefExoticComponent<MenuProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
21
22
|
export type MenuItemTone = "neutral" | "danger";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/Menu/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/Menu/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,aAAa,CAAC;AAMrB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;AAExC,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC;IACjF,kEAAkE;IAClE,OAAO,EAAE,CAAC,KAAK,EAAE;QACf,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB,KAAK,YAAY,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,yCAAyC;IACzC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,IAAI,sGAqKf,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEhD,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC9F,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,QAAQ,6GAoBnB,CAAC;AAEH,wBAAgB,aAAa,gCAO5B;AAED,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAE9D"}
|
|
@@ -14,8 +14,9 @@ export interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, "childre
|
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* A short list of actions attached to a control.
|
|
18
|
-
*
|
|
17
|
+
* A short list of actions attached to a control. Opens on its checked item, if
|
|
18
|
+
* any, else its first. Closes on Escape, on outside click, on Tab and after an
|
|
19
|
+
* item is chosen; arrow keys walk the items. Its label names the menu.
|
|
19
20
|
*/
|
|
20
21
|
export declare const Menu: import("react").ForwardRefExoticComponent<MenuProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
21
22
|
export type MenuItemTone = "neutral" | "danger";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,aAAa,CAAC;AAMrB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;AAExC,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC;IACjF,kEAAkE;IAClE,OAAO,EAAE,CAAC,KAAK,EAAE;QACf,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB,KAAK,YAAY,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,yCAAyC;IACzC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,IAAI,sGAqKf,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEhD,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC9F,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,QAAQ,6GAoBnB,CAAC;AAEH,wBAAgB,aAAa,gCAO5B;AAED,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAE9D"}
|
|
@@ -1,79 +1,92 @@
|
|
|
1
1
|
import { Button as e } from "../Button/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Popover as
|
|
4
|
-
import { forwardRef as
|
|
5
|
-
import { jsx as
|
|
2
|
+
import { d as t, f as n, o as r } from "../../chunks/overlayLayer-Og07sIyl.js";
|
|
3
|
+
import { Popover as i } from "../Popover/index.js";
|
|
4
|
+
import { forwardRef as a, useCallback as o, useEffect as s, useId as c, useRef as l, useState as u } from "react";
|
|
5
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
6
6
|
//#region src/components/Menu/index.tsx
|
|
7
|
-
function
|
|
7
|
+
function p(...e) {
|
|
8
8
|
return e.filter(Boolean).join(" ");
|
|
9
9
|
}
|
|
10
|
-
var
|
|
11
|
-
let [
|
|
12
|
-
(
|
|
10
|
+
var m = a(function({ trigger: e, align: a = "start", className: m, children: h, onClick: g, onKeyDown: _, "aria-label": v, "aria-labelledby": y, ...b }, x) {
|
|
11
|
+
let [S, C] = u(!1), w = r(S), T = l(null), E = l(null), D = l(null), O = c(), k = o(() => C(!1), []), A = o(() => {
|
|
12
|
+
(E.current?.querySelector("button, [href], [tabindex]") ?? E.current)?.focus();
|
|
13
13
|
}, []);
|
|
14
|
-
|
|
15
|
-
let e =
|
|
16
|
-
typeof
|
|
17
|
-
}, [
|
|
18
|
-
if (!
|
|
14
|
+
s(() => {
|
|
15
|
+
let e = w ? D.current : null;
|
|
16
|
+
typeof x == "function" ? x(e) : x && (x.current = e);
|
|
17
|
+
}, [w, x]), s(() => {
|
|
18
|
+
if (!w) return;
|
|
19
19
|
let e = (e) => {
|
|
20
20
|
let t = e.target;
|
|
21
|
-
!
|
|
21
|
+
!T.current?.contains(t) && !D.current?.contains(t) && k();
|
|
22
22
|
}, t = (e) => {
|
|
23
|
-
e.key === "Escape" && (e.preventDefault(),
|
|
23
|
+
e.key === "Escape" && (e.preventDefault(), k(), A());
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
document.addEventListener("mousedown", e), document.addEventListener("keydown", t);
|
|
26
|
+
let n = D.current;
|
|
27
|
+
return (n?.querySelector("[aria-checked=\"true\"]:not(:disabled)") ?? n?.querySelector("button:not(:disabled)"))?.focus(), () => {
|
|
26
28
|
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
|
|
27
29
|
};
|
|
28
30
|
}, [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
w,
|
|
32
|
+
k,
|
|
33
|
+
A
|
|
32
34
|
]);
|
|
33
|
-
let
|
|
35
|
+
let j = (e) => {
|
|
36
|
+
if (e.key === "Tab") {
|
|
37
|
+
e.preventDefault(), k(), e.shiftKey ? A() : T.current && n(T.current);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
34
40
|
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
|
|
35
41
|
e.preventDefault();
|
|
36
|
-
let t = Array.from(
|
|
42
|
+
let t = Array.from(D.current?.querySelectorAll("button:not(:disabled)") ?? []);
|
|
37
43
|
if (t.length === 0) return;
|
|
38
|
-
let
|
|
39
|
-
(e.key === "ArrowDown" ? t[(
|
|
44
|
+
let r = t.indexOf(document.activeElement);
|
|
45
|
+
(e.key === "ArrowDown" ? t[(r + 1) % t.length] : t[(r - 1 + t.length) % t.length])?.focus();
|
|
40
46
|
};
|
|
41
|
-
return /* @__PURE__ */
|
|
47
|
+
return /* @__PURE__ */ f("div", {
|
|
42
48
|
className: "ds-menu-root",
|
|
43
|
-
ref:
|
|
44
|
-
children: [/* @__PURE__ */
|
|
45
|
-
ref:
|
|
49
|
+
ref: T,
|
|
50
|
+
children: [/* @__PURE__ */ d("span", {
|
|
51
|
+
ref: E,
|
|
46
52
|
className: "ds-menu-root",
|
|
47
53
|
children: e({
|
|
48
54
|
"aria-haspopup": "menu",
|
|
49
|
-
"aria-expanded":
|
|
50
|
-
"aria-controls":
|
|
51
|
-
onClick: () =>
|
|
55
|
+
"aria-expanded": w,
|
|
56
|
+
"aria-controls": w ? O : void 0,
|
|
57
|
+
onClick: () => C((e) => !e)
|
|
52
58
|
})
|
|
53
|
-
}), /* @__PURE__ */
|
|
54
|
-
anchorRef:
|
|
55
|
-
isOpen:
|
|
56
|
-
align:
|
|
59
|
+
}), /* @__PURE__ */ d(i, {
|
|
60
|
+
anchorRef: E,
|
|
61
|
+
isOpen: w,
|
|
62
|
+
align: a,
|
|
57
63
|
offset: 8,
|
|
58
|
-
id:
|
|
64
|
+
id: O,
|
|
59
65
|
role: "menu",
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
"aria-label": v,
|
|
67
|
+
"aria-labelledby": y,
|
|
68
|
+
className: p("ds-surface-raised", "ds-field-surface", "ds-menu", m),
|
|
69
|
+
panelRef: D,
|
|
70
|
+
children: /* @__PURE__ */ d("div", {
|
|
63
71
|
className: "ds-menu__list",
|
|
64
72
|
onKeyDown: (e) => {
|
|
65
|
-
|
|
73
|
+
_?.(e), e.defaultPrevented || j(e);
|
|
66
74
|
},
|
|
67
75
|
onClick: (e) => {
|
|
68
|
-
|
|
76
|
+
g?.(e);
|
|
77
|
+
let n = e.target;
|
|
78
|
+
if (e.defaultPrevented || !(n instanceof Element) || !n.closest("button")) return;
|
|
79
|
+
k();
|
|
80
|
+
let r = document.activeElement;
|
|
81
|
+
(t(r) || D.current?.contains(r)) && A();
|
|
69
82
|
},
|
|
70
|
-
...
|
|
71
|
-
children:
|
|
83
|
+
...b,
|
|
84
|
+
children: h
|
|
72
85
|
})
|
|
73
86
|
})]
|
|
74
87
|
});
|
|
75
|
-
}),
|
|
76
|
-
return /* @__PURE__ */
|
|
88
|
+
}), h = a(function({ icon: t, tone: n = "neutral", shortcut: r, isDisabled: i = !1, className: a, children: o, ...s }, c) {
|
|
89
|
+
return /* @__PURE__ */ f(e, {
|
|
77
90
|
ref: c,
|
|
78
91
|
variant: n === "danger" ? "danger" : "simple",
|
|
79
92
|
size: "sm",
|
|
@@ -81,27 +94,27 @@ var f = r(function({ trigger: e, align: r = "start", className: f, children: p,
|
|
|
81
94
|
role: "menuitem",
|
|
82
95
|
isDisabled: i,
|
|
83
96
|
"data-tone": n === "danger" ? "danger" : void 0,
|
|
84
|
-
className:
|
|
97
|
+
className: p("ds-menu-item", a),
|
|
85
98
|
...s,
|
|
86
|
-
children: [o, r && /* @__PURE__ */
|
|
99
|
+
children: [o, r && /* @__PURE__ */ d("span", {
|
|
87
100
|
className: "ds-menu-item__shortcut",
|
|
88
101
|
children: r
|
|
89
102
|
})]
|
|
90
103
|
});
|
|
91
104
|
});
|
|
92
|
-
function
|
|
93
|
-
return /* @__PURE__ */
|
|
105
|
+
function g() {
|
|
106
|
+
return /* @__PURE__ */ d("div", {
|
|
94
107
|
className: "ds-menu-separator",
|
|
95
108
|
role: "separator"
|
|
96
109
|
});
|
|
97
110
|
}
|
|
98
|
-
function
|
|
99
|
-
return /* @__PURE__ */
|
|
111
|
+
function _({ children: e }) {
|
|
112
|
+
return /* @__PURE__ */ d("div", {
|
|
100
113
|
className: "ds-menu-label",
|
|
101
114
|
children: e
|
|
102
115
|
});
|
|
103
116
|
}
|
|
104
117
|
//#endregion
|
|
105
|
-
export {
|
|
118
|
+
export { m as Menu, h as MenuItem, _ as MenuLabel, g as MenuSeparator };
|
|
106
119
|
|
|
107
120
|
//# sourceMappingURL=index.js.map
|