@namroodinc/liquid-editorial 0.1.1 → 0.1.4

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 (55) hide show
  1. package/AGENTS.md +11 -0
  2. package/README.md +8 -0
  3. package/UPGRADING.md +56 -0
  4. package/dist/chunks/{EntryEditor-cjDk4vdH.cjs → EntryEditor-C32lKKnV.cjs} +2 -2
  5. package/dist/chunks/{EntryEditor-cjDk4vdH.cjs.map → EntryEditor-C32lKKnV.cjs.map} +1 -1
  6. package/dist/chunks/EntryEditor-xVuiqtFo.js +181 -0
  7. package/dist/chunks/{EntryEditor-BF808OZR.js.map → EntryEditor-xVuiqtFo.js.map} +1 -1
  8. package/dist/chunks/RichTextEditor-CSpjsL1z.js +357 -0
  9. package/dist/chunks/RichTextEditor-CSpjsL1z.js.map +1 -0
  10. package/dist/chunks/RichTextEditor-DC_0oN1s.cjs +2 -0
  11. package/dist/chunks/RichTextEditor-DC_0oN1s.cjs.map +1 -0
  12. package/dist/components/AssetGrid/index.js.map +1 -1
  13. package/dist/components/EntryEditor/index.cjs +1 -1
  14. package/dist/components/EntryEditor/index.js +3 -3
  15. package/dist/components/EntryPicker/index.cjs +1 -1
  16. package/dist/components/EntryPicker/index.cjs.map +1 -1
  17. package/dist/components/EntryPicker/index.js +4 -4
  18. package/dist/components/EntryPicker/index.js.map +1 -1
  19. package/dist/components/Field/index.js.map +1 -1
  20. package/dist/components/ImageCropper/index.js.map +1 -1
  21. package/dist/components/Modal/index.cjs +1 -1
  22. package/dist/components/Modal/index.cjs.map +1 -1
  23. package/dist/components/Modal/index.js +2 -2
  24. package/dist/components/Modal/index.js.map +1 -1
  25. package/dist/components/Modal/style.css +1 -0
  26. package/dist/components/RichTextEditor/index.cjs +1 -1
  27. package/dist/components/RichTextEditor/index.d.cts.map +1 -1
  28. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  29. package/dist/components/RichTextEditor/index.js +3 -1
  30. package/dist/components/SortableList/index.cjs +1 -1
  31. package/dist/components/SortableList/index.cjs.map +1 -1
  32. package/dist/components/SortableList/index.d.cts +4 -3
  33. package/dist/components/SortableList/index.d.cts.map +1 -1
  34. package/dist/components/SortableList/index.d.ts +4 -3
  35. package/dist/components/SortableList/index.d.ts.map +1 -1
  36. package/dist/components/SortableList/index.js +55 -48
  37. package/dist/components/SortableList/index.js.map +1 -1
  38. package/dist/components/Table/index.cjs +1 -1
  39. package/dist/components/Table/index.cjs.map +1 -1
  40. package/dist/components/Table/index.d.cts +5 -1
  41. package/dist/components/Table/index.d.cts.map +1 -1
  42. package/dist/components/Table/index.d.ts +5 -1
  43. package/dist/components/Table/index.d.ts.map +1 -1
  44. package/dist/components/Table/index.js +74 -55
  45. package/dist/components/Table/index.js.map +1 -1
  46. package/dist/components/Table/style.css +4 -0
  47. package/dist/components/Time/index.js.map +1 -1
  48. package/dist/index.cjs +1 -1
  49. package/dist/index.js +13 -13
  50. package/package.json +3 -1
  51. package/dist/chunks/EntryEditor-BF808OZR.js +0 -181
  52. package/dist/chunks/RichTextEditor-DRt-kibg.js +0 -248
  53. package/dist/chunks/RichTextEditor-DRt-kibg.js.map +0 -1
  54. package/dist/chunks/RichTextEditor-tFkISOvq.cjs +0 -2
  55. package/dist/chunks/RichTextEditor-tFkISOvq.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Icon","useState","useMemo","_Fragment","Badge","SortableList","SortableListItem","Button","Modal","SearchField","require_Icon","require_components_Button_index","require_components_Badge_index","require_components_Modal_index","require_components_SearchField_index","require_components_SortableList_index","react","react_jsx_runtime","cx","parts","matches","query","item","Thumb","EntryPicker","internal","setInternal","defaultValue","selected","value","isOpen","setOpen","setQuery","byId","items","results","atMax","mode","max","commit","isDisabled","next","onValueChange","toggle","id","chosen","canReorder","isReorderable","row","className","label","emptyLabel","addLabel","event","isSelected","isBlocked"],"sources":["../../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { Badge } from \"../Badge\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Modal } from \"../Modal\";\nimport { SearchField } from \"../SearchField\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface EntryItem {\n id: string;\n title: string;\n /** Second line — a content type, a path, a file size. */\n subtitle?: string;\n /** Main image: an asset thumbnail, or the entry's hero. */\n imageUrl?: string;\n /** Words the search matches on top of the title and subtitle. */\n keywords?: string[];\n isDisabled?: boolean;\n}\n\nexport type EntryPickerMode = \"single\" | \"multiple\";\n\nexport interface EntryPickerProps {\n items: EntryItem[];\n /** Selected ids, in the order they will be stored. */\n value?: string[];\n defaultValue?: string[];\n onValueChange?: (value: string[]) => void;\n mode?: EntryPickerMode;\n /** Cap a multiple selection. Reaching it disables the unpicked rows. */\n max?: number;\n label?: string;\n /** Copy shown when nothing is picked yet. */\n emptyLabel?: string;\n addLabel?: string;\n /** Multiple selections are reorderable by default — the stored order is the shown order. */\n isReorderable?: boolean;\n isDisabled?: boolean;\n className?: string;\n}\n\nfunction matches(item: EntryItem, query: string) {\n if (!query) return true;\n const haystack = [item.title, item.subtitle, ...(item.keywords ?? [])]\n .filter(Boolean)\n .join(\" \")\n .toLowerCase();\n return haystack.includes(query.toLowerCase());\n}\n\nfunction Thumb({ item }: { item: EntryItem }) {\n return (\n <span className=\"ds-entry__thumb\">\n {item.imageUrl ? (\n <img src={item.imageUrl} alt=\"\" loading=\"lazy\" />\n ) : (\n <Icon name=\"file-text\" size={20} />\n )}\n </span>\n );\n}\n\n/**\n * Pick entries or assets out of a list. Search narrows it, a row toggles,\n * and a multiple selection keeps — and reorders — the order you chose.\n */\nexport function EntryPicker({\n items,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n isReorderable = true,\n isDisabled = false,\n className,\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n\n const byId = useMemo(() => new Map(items.map((item) => [item.id, item])), [items]);\n const results = useMemo(() => items.filter((item) => matches(item, query)), [items, query]);\n const atMax = mode === \"multiple\" && max !== undefined && selected.length >= max;\n\n const commit = (next: string[]) => {\n if (isDisabled) return;\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n const toggle = (id: string) => {\n if (mode === \"single\") {\n commit(selected[0] === id ? [] : [id]);\n setOpen(false);\n return;\n }\n if (selected.includes(id)) commit(selected.filter((item) => item !== id));\n else if (!atMax) commit([...selected, id]);\n };\n\n const chosen = selected.map((id) => byId.get(id) ?? { id, title: id });\n const canReorder = !isDisabled && isReorderable && mode === \"multiple\" && chosen.length > 1;\n\n const row = (item: EntryItem): ReactNode => (\n <>\n <Thumb item={item} />\n <span className=\"ds-entry__body\">\n <span className=\"ds-entry__title\">{item.title}</span>\n {item.subtitle && <span className=\"ds-entry__subtitle\">{item.subtitle}</span>}\n </span>\n </>\n );\n\n return (\n <div className={cx(\"ds-entry-picker\", className)}>\n <div className=\"ds-entry-picker__head\">\n <span className=\"ds-entry-picker__label\">{label}</span>\n <Badge shape=\"count\">{selected.length}</Badge>\n </div>\n\n {chosen.length === 0 ? (\n <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>\n ) : canReorder ? (\n <SortableList\n items={selected}\n onReorder={commit}\n renderDragOverlay={(id) => {\n const item = byId.get(id);\n return item ? <div className=\"ds-entry\">{row(item)}</div> : null;\n }}\n >\n {chosen.map((item) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n action={\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n }\n >\n <div className=\"ds-entry\">{row(item)}</div>\n </SortableListItem>\n ))}\n </SortableList>\n ) : (\n <ul className=\"ds-entry-picker__list\">\n {chosen.map((item) => (\n <li key={item.id} className=\"ds-entry-picker__row\">\n <div className=\"ds-entry\">{row(item)}</div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n </li>\n ))}\n </ul>\n )}\n\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button variant=\"simple\" size=\"sm\" isDisabled={isDisabled} onClick={() => commit([])}>\n Clear\n </Button>\n )}\n </div>\n\n <Modal\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n title={addLabel}\n description={\n mode === \"single\"\n ? \"Choose one entry.\"\n : max !== undefined\n ? `Choose up to ${max} entries.`\n : \"Choose as many entries as you need.\"\n }\n footer={\n <Button variant=\"primary\" onClick={() => setOpen(false)}>\n Done\n </Button>\n }\n >\n <div className=\"ds-entry-picker__search\">\n <SearchField\n value={query}\n placeholder=\"Search entries\"\n onChange={(event) => setQuery(event.target.value)}\n onClear={() => setQuery(\"\")}\n />\n </div>\n <ul className=\"ds-entry-picker__results\">\n {results.map((item) => {\n const isSelected = selected.includes(item.id);\n const isBlocked = isDisabled || item.isDisabled || (!isSelected && atMax);\n return (\n <li key={item.id}>\n <button\n type=\"button\"\n className=\"ds-entry-picker__result\"\n aria-pressed={isSelected}\n disabled={isBlocked || undefined}\n onClick={() => toggle(item.id)}\n >\n <div className=\"ds-entry\">{row(item)}</div>\n {isSelected && <Icon name=\"check\" size={20} />}\n </button>\n </li>\n );\n })}\n {results.length === 0 && (\n <li className=\"ds-entry-picker__no-results\">No ent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,EAAK,YAAe,CAACgC,GAAclB,EACnE,OACE,EAAAnB,EAAA,IAAA,CAAC,KAAD,CAAA,UACE,EAAAA,EAAA,KAAA,CAAC,SAAD,CACE,KAAK,SACL,UAAU,0BACV,eAAcqC,EACd,SAAUC,GAAa,IAAA,GACvB,YAAeZ,EAAOrB,EAAK,EAAE,EAL/B,SAAA,EAOE,EAAAL,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,WAAY,SAAA+B,EAAI1B,CAAI,CAAO,CAAA,EACzCgC,IAAc,EAAArC,EAAA,IAAA,CAACjB,EAAAA,EAAD,CAAM,KAAK,QAAQ,KAAM,EAAK,CAAA,CACvC,CACN,CAAA,CAAA,EAXKsB,EAAK,EAWV,CAER,CAAC,EACAa,EAAQ,SAAW,IAClB,EAAAlB,EAAA,KAAA,CAAC,KAAD,CAAI,UAAU,8BAAd,SAAA,CAA4C,qBAAmBI,EAAM,IAAM,CAE3E,CAAA,CAAA,CACC,CAAA,CAAA,C,EACJ,C,EAET,C"}
1
+ {"version":3,"file":"index.cjs","names":["Icon","useState","useMemo","_Fragment","Badge","SortableList","SortableListItem","Button","Modal","SearchField","require_Icon","require_components_Button_index","require_components_Modal_index","require_components_Badge_index","require_components_SearchField_index","require_components_SortableList_index","react","react_jsx_runtime","cx","parts","matches","query","item","Thumb","EntryPicker","internal","setInternal","defaultValue","selected","value","isOpen","setOpen","setQuery","byId","items","results","atMax","mode","max","commit","isDisabled","next","onValueChange","toggle","id","chosen","canReorder","isReorderable","row","className","label","emptyLabel","addLabel","event","isSelected","isBlocked"],"sources":["../../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { Badge } from \"../Badge\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Modal } from \"../Modal\";\nimport { SearchField } from \"../SearchField\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface EntryItem {\n id: string;\n title: string;\n /** Second line — a content type, a path, a file size. */\n subtitle?: string;\n /** Main image: an asset thumbnail, or the entry's hero. */\n imageUrl?: string;\n /** Words the search matches on top of the title and subtitle. */\n keywords?: string[];\n isDisabled?: boolean;\n}\n\nexport type EntryPickerMode = \"single\" | \"multiple\";\n\nexport interface EntryPickerProps {\n items: EntryItem[];\n /** Selected ids, in the order they will be stored. */\n value?: string[];\n defaultValue?: string[];\n onValueChange?: (value: string[]) => void;\n mode?: EntryPickerMode;\n /** Cap a multiple selection. Reaching it disables the unpicked rows. */\n max?: number;\n label?: string;\n /** Copy shown when nothing is picked yet. */\n emptyLabel?: string;\n addLabel?: string;\n /** Multiple selections are reorderable by default — the stored order is the shown order. */\n isReorderable?: boolean;\n isDisabled?: boolean;\n className?: string;\n}\n\nfunction matches(item: EntryItem, query: string) {\n if (!query) return true;\n const haystack = [item.title, item.subtitle, ...(item.keywords ?? [])]\n .filter(Boolean)\n .join(\" \")\n .toLowerCase();\n return haystack.includes(query.toLowerCase());\n}\n\nfunction Thumb({ item }: { item: EntryItem }) {\n return (\n <span className=\"ds-entry__thumb\">\n {item.imageUrl ? (\n <img src={item.imageUrl} alt=\"\" loading=\"lazy\" />\n ) : (\n <Icon name=\"file-text\" size={20} />\n )}\n </span>\n );\n}\n\n/**\n * Pick entries or assets out of a list. Search narrows it, a row toggles,\n * and a multiple selection keeps — and reorders — the order you chose.\n */\nexport function EntryPicker({\n items,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n isReorderable = true,\n isDisabled = false,\n className,\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n\n const byId = useMemo(() => new Map(items.map((item) => [item.id, item])), [items]);\n const results = useMemo(() => items.filter((item) => matches(item, query)), [items, query]);\n const atMax = mode === \"multiple\" && max !== undefined && selected.length >= max;\n\n const commit = (next: string[]) => {\n if (isDisabled) return;\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n const toggle = (id: string) => {\n if (mode === \"single\") {\n commit(selected[0] === id ? [] : [id]);\n setOpen(false);\n return;\n }\n if (selected.includes(id)) commit(selected.filter((item) => item !== id));\n else if (!atMax) commit([...selected, id]);\n };\n\n const chosen = selected.map((id) => byId.get(id) ?? { id, title: id });\n const canReorder = !isDisabled && isReorderable && mode === \"multiple\" && chosen.length > 1;\n\n const row = (item: EntryItem): ReactNode => (\n <>\n <Thumb item={item} />\n <span className=\"ds-entry__body\">\n <span className=\"ds-entry__title\">{item.title}</span>\n {item.subtitle && <span className=\"ds-entry__subtitle\">{item.subtitle}</span>}\n </span>\n </>\n );\n\n return (\n <div className={cx(\"ds-entry-picker\", className)}>\n <div className=\"ds-entry-picker__head\">\n <span className=\"ds-entry-picker__label\">{label}</span>\n <Badge shape=\"count\">{selected.length}</Badge>\n </div>\n\n {chosen.length === 0 ? (\n <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>\n ) : canReorder ? (\n <SortableList\n items={selected}\n onReorder={commit}\n renderDragOverlay={(id) => {\n const item = byId.get(id);\n return item ? <div className=\"ds-entry\">{row(item)}</div> : null;\n }}\n >\n {chosen.map((item) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n action={\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n }\n >\n <div className=\"ds-entry\">{row(item)}</div>\n </SortableListItem>\n ))}\n </SortableList>\n ) : (\n <ul className=\"ds-entry-picker__list\">\n {chosen.map((item) => (\n <li key={item.id} className=\"ds-entry-picker__row\">\n <div className=\"ds-entry\">{row(item)}</div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n </li>\n ))}\n </ul>\n )}\n\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button variant=\"simple\" size=\"sm\" isDisabled={isDisabled} onClick={() => commit([])}>\n Clear\n </Button>\n )}\n </div>\n\n <Modal\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n title={addLabel}\n description={\n mode === \"single\"\n ? \"Choose one entry.\"\n : max !== undefined\n ? `Choose up to ${max} entries.`\n : \"Choose as many entries as you need.\"\n }\n footer={\n <Button variant=\"primary\" onClick={() => setOpen(false)}>\n Done\n </Button>\n }\n >\n <div className=\"ds-entry-picker__search\">\n <SearchField\n value={query}\n placeholder=\"Search entries\"\n onChange={(event) => setQuery(event.target.value)}\n onClear={() => setQuery(\"\")}\n />\n </div>\n <ul className=\"ds-entry-picker__results\">\n {results.map((item) => {\n const isSelected = selected.includes(item.id);\n const isBlocked = isDisabled || item.isDisabled || (!isSelected && atMax);\n return (\n <li key={item.id}>\n <button\n type=\"button\"\n className=\"ds-entry-picker__result\"\n aria-pressed={isSelected}\n disabled={isBlocked || undefined}\n onClick={() => toggle(item.id)}\n >\n <div className=\"ds-entry\">{row(item)}</div>\n {isSelected && <Icon name=\"check\" size={20} />}\n </button>\n </li>\n );\n })}\n {results.length === 0 && (\n <li className=\"ds-entry-picker__no-results\">No entries match “{query}”.</li>\n )}\n </ul>\n </Modal>\n </div>\n );\n}\n"],"mappings":"A,yVASA,SAASkB,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAmCA,SAASC,EAAQ,EAAiB,EAAe,CAM/C,MALA,CAAKC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EAL/B,SAAA,EAOE,EAAAL,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,WAAY,SAAA+B,EAAI1B,CAAI,CAAO,CAAA,EACzCgC,IAAc,EAAArC,EAAA,IAAA,CAACjB,EAAAA,EAAD,CAAM,KAAK,QAAQ,KAAM,EAAK,CAAA,CACvC,CACN,CAAA,CAAA,EAXKsB,EAAK,EAWV,CAER,CAAC,EACAa,EAAQ,SAAW,IAClB,EAAAlB,EAAA,KAAA,CAAC,KAAD,CAAI,UAAU,8BAAd,SAAA,CAA4C,qBAAmBI,EAAM,IAAM,CAE3E,CAAA,CAAA,CACC,CAAA,CAAA,C,EACJ,C,EAET,C"}
@@ -1,7 +1,7 @@
1
1
  import { t as e } from "../../chunks/Icon-CGY1FNXT.js";
2
2
  import { Button as t } from "../Button/index.js";
3
- import { Badge as n } from "../Badge/index.js";
4
- import { Modal as r } from "../Modal/index.js";
3
+ import { Modal as n } from "../Modal/index.js";
4
+ import { Badge as r } from "../Badge/index.js";
5
5
  import { SearchField as i } from "../SearchField/index.js";
6
6
  import { SortableList as a, SortableListItem as o } from "../SortableList/index.js";
7
7
  import { useMemo as s, useState as c } from "react";
@@ -56,7 +56,7 @@ function h({ items: h, value: g, defaultValue: _ = [], onValueChange: v, mode: y
56
56
  children: [/* @__PURE__ */ u("span", {
57
57
  className: "ds-entry-picker__label",
58
58
  children: x
59
- }), /* @__PURE__ */ u(n, {
59
+ }), /* @__PURE__ */ u(r, {
60
60
  shape: "count",
61
61
  children: k.length
62
62
  })]
@@ -126,7 +126,7 @@ function h({ items: h, value: g, defaultValue: _ = [], onValueChange: v, mode: y
126
126
  children: "Clear"
127
127
  })]
128
128
  }),
129
- /* @__PURE__ */ d(r, {
129
+ /* @__PURE__ */ d(n, {
130
130
  isOpen: A,
131
131
  onClose: () => j(!1),
132
132
  title: C,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_Fragment","Icon","cx","parts","matches","query","item","Thumb","EntryPicker","internal","setInternal","useState","defaultValue","selected","value","isOpen","setOpen","setQuery","byId","useMemo","items","results","atMax","mode","max","commit","isDisabled","next","onValueChange","toggle","id","chosen","canReorder","isReorderable","row","Fragment","className","label","Badge","emptyLabel","SortableList","SortableListItem","Button","addLabel","Modal","SearchField","event","isSelected","isBlocked"],"sources":["../../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { Badge } from \"../Badge\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Modal } from \"../Modal\";\nimport { SearchField } from \"../SearchField\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface EntryItem {\n id: string;\n title: string;\n /** Second line — a content type, a path, a file size. */\n subtitle?: string;\n /** Main image: an asset thumbnail, or the entry's hero. */\n imageUrl?: string;\n /** Words the search matches on top of the title and subtitle. */\n keywords?: string[];\n isDisabled?: boolean;\n}\n\nexport type EntryPickerMode = \"single\" | \"multiple\";\n\nexport interface EntryPickerProps {\n items: EntryItem[];\n /** Selected ids, in the order they will be stored. */\n value?: string[];\n defaultValue?: string[];\n onValueChange?: (value: string[]) => void;\n mode?: EntryPickerMode;\n /** Cap a multiple selection. Reaching it disables the unpicked rows. */\n max?: number;\n label?: string;\n /** Copy shown when nothing is picked yet. */\n emptyLabel?: string;\n addLabel?: string;\n /** Multiple selections are reorderable by default — the stored order is the shown order. */\n isReorderable?: boolean;\n isDisabled?: boolean;\n className?: string;\n}\n\nfunction matches(item: EntryItem, query: string) {\n if (!query) return true;\n const haystack = [item.title, item.subtitle, ...(item.keywords ?? [])]\n .filter(Boolean)\n .join(\" \")\n .toLowerCase();\n return haystack.includes(query.toLowerCase());\n}\n\nfunction Thumb({ item }: { item: EntryItem }) {\n return (\n <span className=\"ds-entry__thumb\">\n {item.imageUrl ? (\n <img src={item.imageUrl} alt=\"\" loading=\"lazy\" />\n ) : (\n <Icon name=\"file-text\" size={20} />\n )}\n </span>\n );\n}\n\n/**\n * Pick entries or assets out of a list. Search narrows it, a row toggles,\n * and a multiple selection keeps — and reorders — the order you chose.\n */\nexport function EntryPicker({\n items,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n isReorderable = true,\n isDisabled = false,\n className,\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n\n const byId = useMemo(() => new Map(items.map((item) => [item.id, item])), [items]);\n const results = useMemo(() => items.filter((item) => matches(item, query)), [items, query]);\n const atMax = mode === \"multiple\" && max !== undefined && selected.length >= max;\n\n const commit = (next: string[]) => {\n if (isDisabled) return;\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n const toggle = (id: string) => {\n if (mode === \"single\") {\n commit(selected[0] === id ? [] : [id]);\n setOpen(false);\n return;\n }\n if (selected.includes(id)) commit(selected.filter((item) => item !== id));\n else if (!atMax) commit([...selected, id]);\n };\n\n const chosen = selected.map((id) => byId.get(id) ?? { id, title: id });\n const canReorder = !isDisabled && isReorderable && mode === \"multiple\" && chosen.length > 1;\n\n const row = (item: EntryItem): ReactNode => (\n <>\n <Thumb item={item} />\n <span className=\"ds-entry__body\">\n <span className=\"ds-entry__title\">{item.title}</span>\n {item.subtitle && <span className=\"ds-entry__subtitle\">{item.subtitle}</span>}\n </span>\n </>\n );\n\n return (\n <div className={cx(\"ds-entry-picker\", className)}>\n <div className=\"ds-entry-picker__head\">\n <span className=\"ds-entry-picker__label\">{label}</span>\n <Badge shape=\"count\">{selected.length}</Badge>\n </div>\n\n {chosen.length === 0 ? (\n <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>\n ) : canReorder ? (\n <SortableList\n items={selected}\n onReorder={commit}\n renderDragOverlay={(id) => {\n const item = byId.get(id);\n return item ? <div className=\"ds-entry\">{row(item)}</div> : null;\n }}\n >\n {chosen.map((item) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n action={\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n }\n >\n <div className=\"ds-entry\">{row(item)}</div>\n </SortableListItem>\n ))}\n </SortableList>\n ) : (\n <ul className=\"ds-entry-picker__list\">\n {chosen.map((item) => (\n <li key={item.id} className=\"ds-entry-picker__row\">\n <div className=\"ds-entry\">{row(item)}</div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n </li>\n ))}\n </ul>\n )}\n\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button variant=\"simple\" size=\"sm\" isDisabled={isDisabled} onClick={() => commit([])}>\n Clear\n </Button>\n )}\n </div>\n\n <Modal\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n title={addLabel}\n description={\n mode === \"single\"\n ? \"Choose one entry.\"\n : max !== undefined\n ? `Choose up to ${max} entries.`\n : \"Choose as many entries as you need.\"\n }\n footer={\n <Button variant=\"primary\" onClick={() => setOpen(false)}>\n Done\n </Button>\n }\n >\n <div className=\"ds-entry-picker__search\">\n <SearchField\n value={query}\n placeholder=\"Search entries\"\n onChange={(event) => setQuery(event.target.value)}\n onClear={() => setQuery(\"\")}\n />\n </div>\n <ul className=\"ds-entry-picker__results\">\n {results.map((item) => {\n const isSelected = selected.includes(item.id);\n const isBlocked = isDisabled || item.isDisabled || (!isSelected && atMax);\n return (\n <li key={item.id}>\n <button\n type=\"button\"\n className=\"ds-entry-picker__result\"\n aria-pressed={isSelected}\n disabled={isBlocked || undefined}\n onClick={() => toggle(item.id)}\n >\n <div className=\"ds-entry\">{row(item)}</div>\n {isSelected && <Icon name=\"check\" size={20} />}\n </button>\n </li>\n );\n })}\n {results.length === 0 && (\n <li className=\"ds-entry-picker__no-results\">No entries match “{query}”.</li>\n )}\n </ul>\n </Modal>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAASE,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAmCA,SAASC,EAAQ,GAAiB,GAAe;CAM/C,OALA,CAAKC,KACY;EAACC,EAAK;EAAOA,EAAK;EAAU,GAAIA,EAAK,YAAY,CAAC;CAAE,CAAC,CACnE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,CAAC,CACT,YACI,CAAA,CAAS,SAASD,EAAM,YAAY,CAAC;AAC9C;AAEA,SAASE,EAAM,EAAE,WAA6B;CAC5C,OACE,kBAAC,QAAD;EAAM,WAAU;EACb,UAAAD,EAAK,WACJ,kBAAC,OAAD;GAAK,KAAKA,EAAK;GAAU,KAAI;GAAG,SAAQ;EAAQ,CAAA,IAEhD,kBAACL,GAAD;GAAM,MAAK;GAAY,MAAM;EAAK,CAAA;CAEhC,CAAA;AAEV;AAMA,SAAgBO,EAAY,EAC1B,UACA,UACA,kBAAe,CAAC,GAChB,kBACA,UAAO,YACP,QACA,WAAQ,WACR,gBAAa,yBACb,cAAW,kBACX,mBAAgB,IAChB,gBAAa,IACb,gBACmB;CACnB,IAAM,CAACC,GAAUC,KAAeC,EAAmBC,CAAY,GACzDC,IAAWC,KAASL,GACpB,CAACM,GAAQC,KAAWL,EAAS,EAAK,GAClC,CAACN,GAAOY,KAAYN,EAAS,EAAE,GAE/BO,IAAOC,QAAc,IAAI,IAAIC,EAAM,KAAK,MAAS,CAACd,EAAK,IAAIA,C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IACC,CAAA,CAAA;;EACJ;;AAET"}
1
+ {"version":3,"file":"index.js","names":["_Fragment","Icon","Fragment$1","cx","parts","matches","query","item","Thumb","EntryPicker","internal","setInternal","useState","defaultValue","selected","value","isOpen","setOpen","setQuery","byId","useMemo","items","results","atMax","mode","max","commit","isDisabled","next","onValueChange","toggle","id","chosen","canReorder","isReorderable","row","className","label","Badge","emptyLabel","SortableList","SortableListItem","Button","addLabel","Modal","SearchField","event","isSelected","isBlocked"],"sources":["../../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { Badge } from \"../Badge\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Modal } from \"../Modal\";\nimport { SearchField } from \"../SearchField\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface EntryItem {\n id: string;\n title: string;\n /** Second line — a content type, a path, a file size. */\n subtitle?: string;\n /** Main image: an asset thumbnail, or the entry's hero. */\n imageUrl?: string;\n /** Words the search matches on top of the title and subtitle. */\n keywords?: string[];\n isDisabled?: boolean;\n}\n\nexport type EntryPickerMode = \"single\" | \"multiple\";\n\nexport interface EntryPickerProps {\n items: EntryItem[];\n /** Selected ids, in the order they will be stored. */\n value?: string[];\n defaultValue?: string[];\n onValueChange?: (value: string[]) => void;\n mode?: EntryPickerMode;\n /** Cap a multiple selection. Reaching it disables the unpicked rows. */\n max?: number;\n label?: string;\n /** Copy shown when nothing is picked yet. */\n emptyLabel?: string;\n addLabel?: string;\n /** Multiple selections are reorderable by default — the stored order is the shown order. */\n isReorderable?: boolean;\n isDisabled?: boolean;\n className?: string;\n}\n\nfunction matches(item: EntryItem, query: string) {\n if (!query) return true;\n const haystack = [item.title, item.subtitle, ...(item.keywords ?? [])]\n .filter(Boolean)\n .join(\" \")\n .toLowerCase();\n return haystack.includes(query.toLowerCase());\n}\n\nfunction Thumb({ item }: { item: EntryItem }) {\n return (\n <span className=\"ds-entry__thumb\">\n {item.imageUrl ? (\n <img src={item.imageUrl} alt=\"\" loading=\"lazy\" />\n ) : (\n <Icon name=\"file-text\" size={20} />\n )}\n </span>\n );\n}\n\n/**\n * Pick entries or assets out of a list. Search narrows it, a row toggles,\n * and a multiple selection keeps — and reorders — the order you chose.\n */\nexport function EntryPicker({\n items,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n isReorderable = true,\n isDisabled = false,\n className,\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n\n const byId = useMemo(() => new Map(items.map((item) => [item.id, item])), [items]);\n const results = useMemo(() => items.filter((item) => matches(item, query)), [items, query]);\n const atMax = mode === \"multiple\" && max !== undefined && selected.length >= max;\n\n const commit = (next: string[]) => {\n if (isDisabled) return;\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n const toggle = (id: string) => {\n if (mode === \"single\") {\n commit(selected[0] === id ? [] : [id]);\n setOpen(false);\n return;\n }\n if (selected.includes(id)) commit(selected.filter((item) => item !== id));\n else if (!atMax) commit([...selected, id]);\n };\n\n const chosen = selected.map((id) => byId.get(id) ?? { id, title: id });\n const canReorder = !isDisabled && isReorderable && mode === \"multiple\" && chosen.length > 1;\n\n const row = (item: EntryItem): ReactNode => (\n <>\n <Thumb item={item} />\n <span className=\"ds-entry__body\">\n <span className=\"ds-entry__title\">{item.title}</span>\n {item.subtitle && <span className=\"ds-entry__subtitle\">{item.subtitle}</span>}\n </span>\n </>\n );\n\n return (\n <div className={cx(\"ds-entry-picker\", className)}>\n <div className=\"ds-entry-picker__head\">\n <span className=\"ds-entry-picker__label\">{label}</span>\n <Badge shape=\"count\">{selected.length}</Badge>\n </div>\n\n {chosen.length === 0 ? (\n <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>\n ) : canReorder ? (\n <SortableList\n items={selected}\n onReorder={commit}\n renderDragOverlay={(id) => {\n const item = byId.get(id);\n return item ? <div className=\"ds-entry\">{row(item)}</div> : null;\n }}\n >\n {chosen.map((item) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n action={\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n }\n >\n <div className=\"ds-entry\">{row(item)}</div>\n </SortableListItem>\n ))}\n </SortableList>\n ) : (\n <ul className=\"ds-entry-picker__list\">\n {chosen.map((item) => (\n <li key={item.id} className=\"ds-entry-picker__row\">\n <div className=\"ds-entry\">{row(item)}</div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => commit(selected.filter((id) => id !== item.id))}\n />\n </li>\n ))}\n </ul>\n )}\n\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button variant=\"simple\" size=\"sm\" isDisabled={isDisabled} onClick={() => commit([])}>\n Clear\n </Button>\n )}\n </div>\n\n <Modal\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n title={addLabel}\n description={\n mode === \"single\"\n ? \"Choose one entry.\"\n : max !== undefined\n ? `Choose up to ${max} entries.`\n : \"Choose as many entries as you need.\"\n }\n footer={\n <Button variant=\"primary\" onClick={() => setOpen(false)}>\n Done\n </Button>\n }\n >\n <div className=\"ds-entry-picker__search\">\n <SearchField\n value={query}\n placeholder=\"Search entries\"\n onChange={(event) => setQuery(event.target.value)}\n onClear={() => setQuery(\"\")}\n />\n </div>\n <ul className=\"ds-entry-picker__results\">\n {results.map((item) => {\n const isSelected = selected.includes(item.id);\n const isBlocked = isDisabled || item.isDisabled || (!isSelected && atMax);\n return (\n <li key={item.id}>\n <button\n type=\"button\"\n className=\"ds-entry-picker__result\"\n aria-pressed={isSelected}\n disabled={isBlocked || undefined}\n onClick={() => toggle(item.id)}\n >\n <div className=\"ds-entry\">{row(item)}</div>\n {isSelected && <Icon name=\"check\" size={20} />}\n </button>\n </li>\n );\n })}\n {results.length === 0 && (\n <li className=\"ds-entry-picker__no-results\">No entries match “{query}”.</li>\n )}\n </ul>\n </Modal>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAASG,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAmCA,SAASC,EAAQ,GAAiB,GAAe;CAM/C,OALA,CAAKC,KACY;EAACC,EAAK;EAAOA,EAAK;EAAU,GAAIA,EAAK,YAAY,CAAC;CAAE,CAAC,CACnE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,CAAC,CACT,YACI,CAAA,CAAS,SAASD,EAAM,YAAY,CAAC;AAC9C;AAEA,SAASE,EAAM,EAAE,WAA6B;CAC5C,OACE,kBAAC,QAAD;EAAM,WAAU;EACb,UAAAD,EAAK,WACJ,kBAAC,OAAD;GAAK,KAAKA,EAAK;GAAU,KAAI;GAAG,SAAQ;EAAQ,CAAA,IAEhD,kBAACN,GAAD;GAAM,MAAK;GAAY,MAAM;EAAK,CAAA;CAEhC,CAAA;AAEV;AAMA,SAAgBQ,EAAY,EAC1B,UACA,UACA,kBAAe,CAAC,GAChB,kBACA,UAAO,YACP,QACA,WAAQ,WACR,gBAAa,yBACb,cAAW,kBACX,mBAAgB,IAChB,gBAAa,IACb,gBACmB;CACnB,IAAM,CAACC,GAAUC,KAAeC,EAAmBC,CAAY,GACzDC,IAAWC,KAASL,GACpB,CAACM,GAAQC,KAAWL,EAAS,E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AAC,GACAe,EAAQ,WAAW,KAClB,kBAAC,MAAD;MAAI,WAAU;MAAd,UAAA;OAA4C;OAAmBhB;OAAM;MAAM;KAE3E,CAAA,CAAA;IACC,CAAA,CAAA;;EACJ;;AAET"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_Fragment","Field","id","useId","hintId","errorId","describedBy","error","hint","labelId","Wrapper","isGroup","labelContent","Fragment","label","isRequired","children"],"sources":["../../../src/components/Field/index.tsx"],"sourcesContent":["import { useId, type ReactNode } from \"react\";\nimport \"../Field/style.css\";\n\nexport type FieldSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface FieldProps {\n label: string;\n hint?: string;\n /** Present means invalid: the message renders and the control is marked. */\n error?: string;\n isRequired?: boolean;\n /** Use a legend for a field containing a group of controls. */\n isGroup?: boolean;\n /** Receives the ids and invalid flag the control must carry. */\n children: (props: {\n id: string;\n \"aria-describedby\"?: string;\n \"aria-labelledby\": string;\n \"aria-invalid\"?: true;\n required?: boolean;\n }) => ReactNode;\n}\n\n/** Label, hint, error and required marker around any control wearing the field skin. */\nexport function Field({ label, hint, error, isRequired, isGroup = false, children }: FieldProps) {\n const id = useId();\n const hintId = `${id}-hint`;\n const errorId = `${id}-error`;\n const describedBy = error ? errorId : hint ? hintId : undefined;\n const labelId = `${id}-label`;\n const Wrapper = isGroup ? \"fieldset\" : \"div\";\n const labelContent = <>{label}{isRequired && <span className=\"ds-field__required\" aria-hidden=\"true\">*</span>}</>;\n\n return (\n <Wrapper className=\"ds-field\">\n {isGroup\n ? <legend id={labelId} className=\"ds-field__label\">{labelContent}</legend>\n : <label id={labelId} className=\"ds-field__label\" htmlFor={id}>{labelContent}</label>}\n {children({\n id,\n \"aria-describedby\": describedBy,\n \"aria-labelledby\": labelId,\n \"aria-invalid\": error ? true : undefined,\n required: isRequired,\n })}\n {hint && !error && (\n <span className=\"ds-field__hint\" id={hintId}>\n {hint}\n </span>\n )}\n {error && (\n <span className=\"ds-field__error\" id={errorId}>\n {error}\n </span>\n )}\n </Wrapper>\n );\n}\n"],"mappings":";;;;AAwBA,SAAgBC,EAAM,EAAE,UAAO,SAAM,UAAO,eAAY,aAAU,IAAO,eAAwB;CAC/F,IAAMC,IAAKC,EAAM,GACXC,IAAS,GAAGF,EAAG,QACfG,IAAU,GAAGH,EAAG,SAChBI,IAAcC,IAAQF,IAAUG,IAAOJ,IAAS,KAAA,GAChDK,IAAU,GAAGP,EAAG,SAChBQ,IAAUC,IAAU,aAAa,OACjCC,IAAe,kBAAAZ,GAAA,EAAA,UAAA,CAAGc,GAAOC,KAAc,kBAAC,QAAD;EAAM,WAAU;EAAqB,eAAY;EAAO,UAAA;CAAO,CAAA,CAAI,EAAA,CAAA;CAEhH,OACE,kBAACL,GAAD;EAAS,WAAU;EAAnB,UAAA;GACGC,IACG,kBAAC,UAAD;IAAQ,IAAIF;IAAS,WAAU;IAAmB,UAAAG;GAAqB,CAAA,IACvE,kBAAC,SAAD;IAAO,IAAIH;IAAS,WAAU;IAAkB,SAASP;IAAK,UAAAU;GAAoB,CAAA;GACrFI,EAAS;IACR;IACA,oBAAoBV;IACpB,mBAAmBG;IACnB,gBAAgBF,IAAQ,KAAO,KAAA;IAC/B,UAAUQ;GACZ,CAAC;GACAP,KAAQ,CAACD,KACR,kBAAC,QAAD;IAAM,WAAU;IAAiB,IAAIH;IAClC,UAAAI;GACG,CAAA;GAEPD,KACC,kBAAC,QAAD;IAAM,WAAU;IAAkB,IAAIF;IACnC,UAAAE;GACG,CAAA;EAED;;AAEb"}
1
+ {"version":3,"file":"index.js","names":["_Fragment","Fragment$1","Field","id","useId","hintId","errorId","describedBy","error","hint","labelId","Wrapper","isGroup","labelContent","label","isRequired","children"],"sources":["../../../src/components/Field/index.tsx"],"sourcesContent":["import { useId, type ReactNode } from \"react\";\nimport \"../Field/style.css\";\n\nexport type FieldSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface FieldProps {\n label: string;\n hint?: string;\n /** Present means invalid: the message renders and the control is marked. */\n error?: string;\n isRequired?: boolean;\n /** Use a legend for a field containing a group of controls. */\n isGroup?: boolean;\n /** Receives the ids and invalid flag the control must carry. */\n children: (props: {\n id: string;\n \"aria-describedby\"?: string;\n \"aria-labelledby\": string;\n \"aria-invalid\"?: true;\n required?: boolean;\n }) => ReactNode;\n}\n\n/** Label, hint, error and required marker around any control wearing the field skin. */\nexport function Field({ label, hint, error, isRequired, isGroup = false, children }: FieldProps) {\n const id = useId();\n const hintId = `${id}-hint`;\n const errorId = `${id}-error`;\n const describedBy = error ? errorId : hint ? hintId : undefined;\n const labelId = `${id}-label`;\n const Wrapper = isGroup ? \"fieldset\" : \"div\";\n const labelContent = <>{label}{isRequired && <span className=\"ds-field__required\" aria-hidden=\"true\">*</span>}</>;\n\n return (\n <Wrapper className=\"ds-field\">\n {isGroup\n ? <legend id={labelId} className=\"ds-field__label\">{labelContent}</legend>\n : <label id={labelId} className=\"ds-field__label\" htmlFor={id}>{labelContent}</label>}\n {children({\n id,\n \"aria-describedby\": describedBy,\n \"aria-labelledby\": labelId,\n \"aria-invalid\": error ? true : undefined,\n required: isRequired,\n })}\n {hint && !error && (\n <span className=\"ds-field__hint\" id={hintId}>\n {hint}\n </span>\n )}\n {error && (\n <span className=\"ds-field__error\" id={errorId}>\n {error}\n </span>\n )}\n </Wrapper>\n );\n}\n"],"mappings":";;;;AAwBA,SAAgBE,EAAM,EAAE,UAAO,SAAM,UAAO,eAAY,aAAU,IAAO,eAAwB;CAC/F,IAAMC,IAAKC,EAAM,GACXC,IAAS,GAAGF,EAAG,QACfG,IAAU,GAAGH,EAAG,SAChBI,IAAcC,IAAQF,IAAUG,IAAOJ,IAAS,KAAA,GAChDK,IAAU,GAAGP,EAAG,SAChBQ,IAAUC,IAAU,aAAa,OACjCC,IAAe,kBAAAb,GAAA,EAAA,UAAA,CAAGc,GAAOC,KAAc,kBAAC,QAAD;EAAM,WAAU;EAAqB,eAAY;EAAO,UAAA;CAAO,CAAA,CAAI,EAAA,CAAA;CAEhH,OACE,kBAACJ,GAAD;EAAS,WAAU;EAAnB,UAAA;GACGC,IACG,kBAAC,UAAD;IAAQ,IAAIF;IAAS,WAAU;IAAmB,UAAAG;GAAqB,CAAA,IACvE,kBAAC,SAAD;IAAO,IAAIH;IAAS,WAAU;IAAkB,SAASP;IAAK,UAAAU;GAAoB,CAAA;GACrFG,EAAS;IACR;IACA,oBAAoBT;IACpB,mBAAmBG;IACnB,gBAAgBF,IAAQ,KAAO,KAAA;IAC/B,UAAUO;GACZ,CAAC;GACAN,KAAQ,CAACD,KACR,kBAAC,QAAD;IAAM,WAAU;IAAiB,IAAIH;IAClC,UAAAI;GACG,CAAA;GAEPD,KACC,kBAAC,QAAD;IAAM,WAAU;IAAkB,IAAIF;IACnC,UAAAE;GACG,CAAA;EAED;;AAEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_Fragment","cropRatios","MIN_ZOOM","REST","ImageCropper","forwardRef","rest","frameRef","useRef","frame","setFrame","useState","natural","setNatural","state","setState","ratio","setRatio","aspect","dragRef","imageRef","prev","chooseRatio","next","onAspectChange","turn","by","adopt","useCallback","img","src","quarter","view","baseScale","scale","maxOffsetX","maxOffsetY","node","measure","observer","clamp","nextScale","limitX","limitY","maxZoom","width","height","onPointerDown","event","onPointerMove","drag","dx","dy","endDrag","nudge","className","ratios","ButtonGroup","Button","option","step","move","rotatable","Fragment","cropToBlob","image","rotation","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 useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { ButtonGroup } from \"../ButtonGroup\";\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. */\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}\n\n/** One offered output shape. `value` is width / height. */\nexport interface CropRatio {\n label: string;\n value: number;\n}\n\n/** The house set: square, portrait, landscape, wide. */\nexport const cropRatios: CropRatio[] = [\n { label: \"1:1\", value: 1 },\n { label: \"4:5\", value: 4 / 5 },\n { label: \"4:3\", value: 4 / 3 },\n { label: \"16:9\", value: 16 / 9 },\n];\n\nexport interface ImageCropperProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n src: string;\n /** Describes the picture for people who cannot see the stage. */\n alt?: string;\n /** Output shape, width / height. 1 for an avatar, 16 / 9 for a hero. */\n aspect?: number;\n /**\n * Offer the reader a choice of output shapes. Omit it — or pass one ratio —\n * when the shape is fixed by the slot the picture is going into.\n */\n ratios?: CropRatio[];\n /** Fires when the reader picks a different shape. */\n onAspectChange?: (aspect: number) => void;\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\nconst MIN_ZOOM = 1;\nconst REST: CropState = { offsetX: 0, offsetY: 0, zoom: 1, rotation: 0 };\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>(\n function ImageCropper(\n {\n src,\n alt = \"\",\n aspect = 1,\n ratios,\n onAspectChange,\n maxZoom = 3,\n rotatable = true,\n onChange,\n className,\n ...rest\n },\n ref,\n ) {\n const frameRef = useRef<HTMLDivElement | null>(null);\n const [frame, setFrame] = useState({ width: 0, height: 0 });\n const [natural, setNatural] = useState({ width: 0, height: 0 });\n const [state, setState] = useState<CropState>(REST);\n const [ratio, setRatio] = useState(aspect);\n const dragRef = useRef<{ pointerId: number; x: number; y: number } | null>(null);\n const imageRef = useRef<HTMLImageElement | null>(null);\n\n // The prop stays the source of truth when the caller drives the shape.\n useEffect(() => {\n setRatio(aspect);\n setState((prev) => ({ ...REST, rotation: prev.rotation }));\n }, [aspect]);\n\n const chooseRatio = (next: number) => {\n setRatio(next);\n setState((prev) => ({ ...REST, rotation: prev.rotation }));\n onAspectChange?.(next);\n };\n\n const turn = (by: number) =>\n setState((prev) => ({ ...REST, rotation: (prev.rotation + by + 360) % 360 }));\n\n /** Take the picture's own pixels and start from a centred, unzoomed view. */\n const adopt = useCallback((img: HTMLImageElement) => {\n if (!img.naturalWidth) return;\n setNatural({ width: img.naturalWidth, height: img.naturalHeight });\n setState(REST);\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) adopt(img);\n }, [adopt, src]);\n\n // After a quarter turn the picture presents its other side to the frame.\n const quarter = state.rotation % 180 !== 0;\n const view = {\n width: quarter ? natural.height : natural.width,\n height: quarter ? natural.width : natural.height,\n };\n\n // The scale at which the image exactly covers the frame; zoom multiplies it.\n const baseScale =\n view.width && frame.width\n ? Math.max(frame.width / view.width, frame.height / view.height)\n : 0;\n const scale = baseScale * state.zoom;\n const maxOffsetX = scale ? Math.max(0, (view.width * scale - frame.width) / 2) : 0;\n const maxOffsetY = scale ? Math.max(0, (view.height * scale - frame.height) / 2) : 0;\n\n useLayoutEffect(() => {\n const node = frameRef.current;\n if (!node) return;\n const measure = () =>\n setFrame({ width: node.clientWidth, height: node.clientHeight });\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n\n const clamp = useCallback(\n (next: CropState): CropState => {\n const nextScale = baseScale * next.zoom;\n const limitX = nextScale\n ? Math.max(0, (view.width * nextScale - frame.width) / 2)\n : 0;\n const limitY = nextScale\n ? Math.max(0, (view.height * nextScale - frame.height) / 2)\n : 0;\n return {\n rotation: next.rotation,\n zoom: Math.min(maxZoom, Math.max(MIN_ZOOM, next.zoom)),\n offsetX: Math.min(limitX, Math.max(-limitX, next.offsetX)),\n offsetY: Math.min(limitY, Math.max(-limitY, next.offsetY)),\n };\n },\n [baseScale, maxZoom, view.height, view.width, frame.height, frame.width],\n );\n\n useEffect(() => {\n if (!scale || !frame.width) return;\n const width = frame.width / scale;\n const height = frame.height / scale;\n onChange?.(\n {\n x: Math.round(view.width / 2 - state.offsetX / scale - width / 2),\n y: Math.round(view.height / 2 - state.offsetY / scale - height / 2),\n width: Math.round(width),\n height: Math.round(height),\n },\n state,\n );\n // onChange is intentionally not a dependency: callers pass inline handlers.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [scale, frame.width, frame.height, view.width, view.height, state]);\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) return;\n dragRef.current = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };\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) return;\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 setState((prev) => clamp({ ...prev, offsetX: prev.offsetX + dx, offsetY: prev.offsetY + dy }));\n };\n\n const endDrag = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) return;\n dragRef.current = null;\n event.currentTarget.releasePointerCapture?.(event.pointerId);\n };\n\n const nudge = (dx: number, dy: number) =>\n setState((prev) => clamp({ ...prev, offsetX: prev.offsetX + dx, offsetY: prev.offsetY + dy }));\n\n return (\n <div ref={ref} className={[\"ds-cropper\", className].filter(Boolean).join(\" \")} {...rest}>\n {ratios && ratios.length > 1 && (\n <ButtonGroup aria-label=\"Crop ratio\" className=\"ds-cropper__ratios\">\n {ratios.map((option) => (\n <Button\n key={option.label}\n size=\"sm\"\n variant={option.value === ratio ? \"active\" : \"neutral\"}\n aria-pressed={option.value === ratio}\n onClick={() => chooseRatio(option.value)}\n >\n {option.label}\n </Button>\n ))}\n </ButtonGroup>\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(ratio) } 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) return;\n event.preventDefault();\n nudge(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: natural.width * scale || undefined,\n blockSize: natural.height * scale || undefined,\n transform: `translate(calc(-50% + ${state.offsetX}px), calc(-50% + ${state.offsetY}px)) rotate(${state.rotation}deg)`,\n }}\n />\n {/* The window: everything outside it is veiled, not hidden. */}\n <div className=\"ds-cropper__frame\" ref={frameRef} aria-hidden=\"true\">\n <div className=\"ds-cropper__guides\" />\n </div>\n </div>\n\n <div className=\"ds-cropper__controls\">\n <label className=\"ds-cropper__zoom\">\n <span className=\"ds-cropper__zoom-label\">Zoom</span>\n <input\n type=\"range\"\n min={MIN_ZOOM}\n max={maxZoom}\n step={0.01}\n value={state.zoom}\n className=\"ds-cropper__slider\"\n onChange={(event) =>\n setState((prev) => clamp({ ...prev, zoom: Number(event.target.value) }))\n }\n />\n <span className=\"ds-cropper__value\">{state.zoom.toFixed(2)}×</span>\n </label>\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 size=\"sm\" onClick={() => setState(REST)}>\n Reset\n </Button>\n </ButtonGroup>\n </div>\n\n <p className=\"ds-cropper__hint\">\n 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 </p>\n </div>\n );\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) throw new Error(\"Canvas 2D context unavailable\");\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) throw new Error(\"Canvas 2D context unavailable\");\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":";;;;;AAyCA,IAAaC,IAA0B;CACrC;EAAE,OAAO;EAAO,OAAO;CAAE;CACzB;EAAE,OAAO;EAAO,OAAO,IAAI;CAAE;CAC7B;EAAE,OAAO;EAAO,OAAO,IAAI;CAAE;CAC7B;EAAE,OAAO;EAAQ,OAAO,KAAK;CAAE;AACjC,GAwBMC,IAAW,GACXC,IAAkB;CAAE,SAAS;CAAG,SAAS;CAAG,MAAM;CAAG,UAAU;AAAE,GAQ1DC,IAAeC,EAC1B,SACE,EACE,QACA,SAAM,IACN,YAAS,GACT,WACA,mBACA,aAAU,GACV,eAAY,IACZ,aACA,cACA,GAAGC,KAEL,GACA;CACA,IAAMC,IAAWC,EAA8B,IAAI,GAC7C,CAACC,GAAOC,KAAYC,EAAS;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAC,GACpD,CAACC,GAASC,KAAcF,EAAS;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAC,GACxD,CAACG,GAAOC,KAAYJ,EAAoBR,CAAI,GAC5C,CAACa,GAAOC,KAAYN,EAASO,CAAM,GACnCC,IAAUX,EAA2D,IAAI,GACzEY,IAAWZ,EAAgC,IAAI;CAGrD,QAAgB;EAEd,AADAS,EAASC,CAAM,GACfH,GAAU,OAAU;GAAE,GAAGZ;GAAM,UAAUkB,EAAK;EAAS,EAAE;CAC3D,GAAG,CAACH,CAAM,CAAC;CAEX,IAAMI,KAAe,MAAiB;EA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GACtD0B,IAAS,SAAS,cAAc,QAAQ;CAE9C,AADA,EAAO,QAAQ1B,GACf,EAAO,SAASC;CAChB,IAAM0B,IAAUD,EAAO,WAAW,IAAI;CACtC,IAAI,CAACC,GAAS,MAAU,MAAM,+BAA+B;CAG7D,OAFAA,EAAQ,UAAUL,GAAQG,EAAK,GAAGA,EAAK,GAAGA,EAAK,OAAOA,EAAK,QAAQ,GAAG,GAAGzB,GAAOC,CAAM,GAE/E,IAAI,SAAS,GAAS,MAAW;EACtC,EAAO,QACJ,MAAU2B,IAAOC,EAAQD,CAAI,IAAIE,EAAO,gBAAI,MAAM,2BAA2B,CAAC,GAC/EC,GACAC,CACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"index.js","names":["_Fragment","Fragment$1","cropRatios","MIN_ZOOM","REST","ImageCropper","forwardRef","rest","frameRef","useRef","frame","setFrame","useState","natural","setNatural","state","setState","ratio","setRatio","aspect","dragRef","imageRef","prev","chooseRatio","next","onAspectChange","turn","by","adopt","useCallback","img","src","quarter","view","baseScale","scale","maxOffsetX","maxOffsetY","node","measure","observer","clamp","nextScale","limitX","limitY","maxZoom","width","height","onPointerDown","event","onPointerMove","drag","dx","dy","endDrag","nudge","className","ratios","ButtonGroup","Button","option","step","move","rotatable","cropToBlob","image","rotation","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 useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { ButtonGroup } from \"../ButtonGroup\";\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. */\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}\n\n/** One offered output shape. `value` is width / height. */\nexport interface CropRatio {\n label: string;\n value: number;\n}\n\n/** The house set: square, portrait, landscape, wide. */\nexport const cropRatios: CropRatio[] = [\n { label: \"1:1\", value: 1 },\n { label: \"4:5\", value: 4 / 5 },\n { label: \"4:3\", value: 4 / 3 },\n { label: \"16:9\", value: 16 / 9 },\n];\n\nexport interface ImageCropperProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n src: string;\n /** Describes the picture for people who cannot see the stage. */\n alt?: string;\n /** Output shape, width / height. 1 for an avatar, 16 / 9 for a hero. */\n aspect?: number;\n /**\n * Offer the reader a choice of output shapes. Omit it — or pass one ratio —\n * when the shape is fixed by the slot the picture is going into.\n */\n ratios?: CropRatio[];\n /** Fires when the reader picks a different shape. */\n onAspectChange?: (aspect: number) => void;\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\nconst MIN_ZOOM = 1;\nconst REST: CropState = { offsetX: 0, offsetY: 0, zoom: 1, rotation: 0 };\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>(\n function ImageCropper(\n {\n src,\n alt = \"\",\n aspect = 1,\n ratios,\n onAspectChange,\n maxZoom = 3,\n rotatable = true,\n onChange,\n className,\n ...rest\n },\n ref,\n ) {\n const frameRef = useRef<HTMLDivElement | null>(null);\n const [frame, setFrame] = useState({ width: 0, height: 0 });\n const [natural, setNatural] = useState({ width: 0, height: 0 });\n const [state, setState] = useState<CropState>(REST);\n const [ratio, setRatio] = useState(aspect);\n const dragRef = useRef<{ pointerId: number; x: number; y: number } | null>(null);\n const imageRef = useRef<HTMLImageElement | null>(null);\n\n // The prop stays the source of truth when the caller drives the shape.\n useEffect(() => {\n setRatio(aspect);\n setState((prev) => ({ ...REST, rotation: prev.rotation }));\n }, [aspect]);\n\n const chooseRatio = (next: number) => {\n setRatio(next);\n setState((prev) => ({ ...REST, rotation: prev.rotation }));\n onAspectChange?.(next);\n };\n\n const turn = (by: number) =>\n setState((prev) => ({ ...REST, rotation: (prev.rotation + by + 360) % 360 }));\n\n /** Take the picture's own pixels and start from a centred, unzoomed view. */\n const adopt = useCallback((img: HTMLImageElement) => {\n if (!img.naturalWidth) return;\n setNatural({ width: img.naturalWidth, height: img.naturalHeight });\n setState(REST);\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) adopt(img);\n }, [adopt, src]);\n\n // After a quarter turn the picture presents its other side to the frame.\n const quarter = state.rotation % 180 !== 0;\n const view = {\n width: quarter ? natural.height : natural.width,\n height: quarter ? natural.width : natural.height,\n };\n\n // The scale at which the image exactly covers the frame; zoom multiplies it.\n const baseScale =\n view.width && frame.width\n ? Math.max(frame.width / view.width, frame.height / view.height)\n : 0;\n const scale = baseScale * state.zoom;\n const maxOffsetX = scale ? Math.max(0, (view.width * scale - frame.width) / 2) : 0;\n const maxOffsetY = scale ? Math.max(0, (view.height * scale - frame.height) / 2) : 0;\n\n useLayoutEffect(() => {\n const node = frameRef.current;\n if (!node) return;\n const measure = () =>\n setFrame({ width: node.clientWidth, height: node.clientHeight });\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n\n const clamp = useCallback(\n (next: CropState): CropState => {\n const nextScale = baseScale * next.zoom;\n const limitX = nextScale\n ? Math.max(0, (view.width * nextScale - frame.width) / 2)\n : 0;\n const limitY = nextScale\n ? Math.max(0, (view.height * nextScale - frame.height) / 2)\n : 0;\n return {\n rotation: next.rotation,\n zoom: Math.min(maxZoom, Math.max(MIN_ZOOM, next.zoom)),\n offsetX: Math.min(limitX, Math.max(-limitX, next.offsetX)),\n offsetY: Math.min(limitY, Math.max(-limitY, next.offsetY)),\n };\n },\n [baseScale, maxZoom, view.height, view.width, frame.height, frame.width],\n );\n\n useEffect(() => {\n if (!scale || !frame.width) return;\n const width = frame.width / scale;\n const height = frame.height / scale;\n onChange?.(\n {\n x: Math.round(view.width / 2 - state.offsetX / scale - width / 2),\n y: Math.round(view.height / 2 - state.offsetY / scale - height / 2),\n width: Math.round(width),\n height: Math.round(height),\n },\n state,\n );\n // onChange is intentionally not a dependency: callers pass inline handlers.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [scale, frame.width, frame.height, view.width, view.height, state]);\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) return;\n dragRef.current = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };\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) return;\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 setState((prev) => clamp({ ...prev, offsetX: prev.offsetX + dx, offsetY: prev.offsetY + dy }));\n };\n\n const endDrag = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) return;\n dragRef.current = null;\n event.currentTarget.releasePointerCapture?.(event.pointerId);\n };\n\n const nudge = (dx: number, dy: number) =>\n setState((prev) => clamp({ ...prev, offsetX: prev.offsetX + dx, offsetY: prev.offsetY + dy }));\n\n return (\n <div ref={ref} className={[\"ds-cropper\", className].filter(Boolean).join(\" \")} {...rest}>\n {ratios && ratios.length > 1 && (\n <ButtonGroup aria-label=\"Crop ratio\" className=\"ds-cropper__ratios\">\n {ratios.map((option) => (\n <Button\n key={option.label}\n size=\"sm\"\n variant={option.value === ratio ? \"active\" : \"neutral\"}\n aria-pressed={option.value === ratio}\n onClick={() => chooseRatio(option.value)}\n >\n {option.label}\n </Button>\n ))}\n </ButtonGroup>\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(ratio) } 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) return;\n event.preventDefault();\n nudge(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: natural.width * scale || undefined,\n blockSize: natural.height * scale || undefined,\n transform: `translate(calc(-50% + ${state.offsetX}px), calc(-50% + ${state.offsetY}px)) rotate(${state.rotation}deg)`,\n }}\n />\n {/* The window: everything outside it is veiled, not hidden. */}\n <div className=\"ds-cropper__frame\" ref={frameRef} aria-hidden=\"true\">\n <div className=\"ds-cropper__guides\" />\n </div>\n </div>\n\n <div className=\"ds-cropper__controls\">\n <label className=\"ds-cropper__zoom\">\n <span className=\"ds-cropper__zoom-label\">Zoom</span>\n <input\n type=\"range\"\n min={MIN_ZOOM}\n max={maxZoom}\n step={0.01}\n value={state.zoom}\n className=\"ds-cropper__slider\"\n onChange={(event) =>\n setState((prev) => clamp({ ...prev, zoom: Number(event.target.value) }))\n }\n />\n <span className=\"ds-cropper__value\">{state.zoom.toFixed(2)}×</span>\n </label>\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 size=\"sm\" onClick={() => setState(REST)}>\n Reset\n </Button>\n </ButtonGroup>\n </div>\n\n <p className=\"ds-cropper__hint\">\n 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 </p>\n </div>\n );\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) throw new Error(\"Canvas 2D context unavailable\");\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) throw new Error(\"Canvas 2D context unavailable\");\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":";;;;;AAyCA,IAAaE,IAA0B;CACrC;EAAE,OAAO;EAAO,OAAO;CAAE;CACzB;EAAE,OAAO;EAAO,OAAO,IAAI;CAAE;CAC7B;EAAE,OAAO;EAAO,OAAO,IAAI;CAAE;CAC7B;EAAE,OAAO;EAAQ,OAAO,KAAK;CAAE;AACjC,GAwBMC,IAAW,GACXC,IAAkB;CAAE,SAAS;CAAG,SAAS;CAAG,MAAM;CAAG,UAAU;AAAE,GAQ1DC,IAAeC,EAC1B,SACE,EACE,QACA,SAAM,IACN,YAAS,GACT,WACA,mBACA,aAAU,GACV,eAAY,IACZ,aACA,cACA,GAAGC,KAEL,GACA;CACA,IAAMC,IAAWC,EAA8B,IAAI,GAC7C,CAACC,GAAOC,KAAYC,EAAS;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAC,GACpD,CAACC,GAASC,KAAcF,EAAS;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAC,GACxD,CAACG,GAAOC,KAAYJ,EAAoBR,CAAI,GAC5C,CAACa,GAAOC,KAAYN,EAASO,CAAM,GACnCC,IAAUX,EAA2D,IAAI,GACzEY,IAAWZ,EAAgC,IAAI;CAGrD,QAAgB;EAEd,AADAS,EAASC,CAAM,GACfH,GAAU,OAAU;GAAE,GAAGZ;GAAM,UAAUkB,EAAK;EAAS,EAAE;CAC3D,GAAG,CAACH,CAAM,CAAC;CAEX,IAAMI,KAAe,MAAiB;EAGpC,AAFAL,EAASM,CAAI,GACbR,GAAU,OAAU;GAAE,GAAGZ;GAAM,UAAUkB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,SAASC;CAChB,IAAMyB,IAAUD,EAAO,WAAW,IAAI;CACtC,IAAI,CAACC,GAAS,MAAU,MAAM,+BAA+B;CAG7D,OAFAA,EAAQ,UAAUL,GAAQG,EAAK,GAAGA,EAAK,GAAGA,EAAK,OAAOA,EAAK,QAAQ,GAAG,GAAGxB,GAAOC,CAAM,GAE/E,IAAI,SAAS,GAAS,MAAW;EACtC,EAAO,QACJ,MAAU0B,IAAOC,EAAQD,CAAI,IAAIE,EAAO,gBAAI,MAAM,2BAA2B,CAAC,GAC/EC,GACAC,CACF;CACF,CAAC;AACH"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs");let t=require("react"),n=require("react/jsx-runtime"),r=require("react-dom");var i=(0,t.forwardRef)(function({isOpen:i,onClose:a,title:o,description:s,size:c=`md`,footer:l,className:u,children:d,...f},p){let m=(0,t.useRef)(null),h=(0,t.useRef)(a),g=(0,t.useId)(),_=(0,t.useId)();return(0,t.useEffect)(()=>{h.current=a},[a]),(0,t.useEffect)(()=>{if(!i)return;let e=document.activeElement;(m.current?.querySelector(`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])`)??m.current)?.focus();let t=e=>{if(e.key===`Escape`){h.current();return}if(e.key!==`Tab`)return;let t=Array.from(m.current?.querySelectorAll(`button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])`)??[]);if(t.length===0)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())};document.addEventListener(`keydown`,t);let n=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,t),document.body.style.overflow=n,e?.focus()}},[i]),!i||typeof document>`u`?null:(0,r.createPortal)((0,n.jsx)(`div`,{className:`ds-scrim`,onMouseDown:e=>e.target===e.currentTarget&&h.current(),children:(0,n.jsxs)(`div`,{...f,ref:e=>{m.current=e,typeof p==`function`?p(e):p&&(p.current=e)},role:`dialog`,"aria-modal":`true`,"aria-labelledby":g,"aria-describedby":s?_:void 0,tabIndex:-1,"data-size":c,className:[`ds-modal`,u].filter(Boolean).join(` `),children:[(0,n.jsxs)(`header`,{className:`ds-modal__head`,children:[(0,n.jsxs)(`div`,{className:`ds-modal__titles`,children:[(0,n.jsx)(`h2`,{id:g,className:`ds-modal__title`,children:o}),s&&(0,n.jsx)(`p`,{id:_,className:`ds-modal__description`,children:s})]}),(0,n.jsx)(e.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Close`,className:`ds-modal__close`,onClick:()=>h.current()})]}),(0,n.jsx)(`div`,{className:`ds-modal__body`,children:d}),l&&(0,n.jsx)(`footer`,{className:`ds-modal__footer`,children:l})]})}),document.body)});exports.Modal=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Button/index.cjs");let t=require("react"),n=require("react/jsx-runtime"),r=require("react-dom");var i=(0,t.forwardRef)(function({isOpen:i,onClose:a,title:o,description:s,size:c=`md`,footer:l,className:u,children:d,...f},p){let m=(0,t.useRef)(null),h=(0,t.useRef)(a),g=(0,t.useId)(),_=(0,t.useId)();return(0,t.useEffect)(()=>{h.current=a},[a]),(0,t.useEffect)(()=>{if(!i)return;let e=document.activeElement;(m.current?.querySelector(`:is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])`)??m.current)?.focus();let t=e=>{if(e.key===`Escape`){h.current();return}if(e.key!==`Tab`)return;let t=Array.from(m.current?.querySelectorAll(`:is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])`)??[]);if(t.length===0)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())};document.addEventListener(`keydown`,t);let n=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,t),document.body.style.overflow=n,e?.focus()}},[i]),!i||typeof document>`u`?null:(0,r.createPortal)((0,n.jsx)(`div`,{className:`ds-scrim`,onMouseDown:e=>e.target===e.currentTarget&&h.current(),children:(0,n.jsxs)(`div`,{...f,ref:e=>{m.current=e,typeof p==`function`?p(e):p&&(p.current=e)},role:`dialog`,"aria-modal":`true`,"aria-labelledby":g,"aria-describedby":s?_:void 0,tabIndex:-1,"data-size":c,className:[`ds-modal`,u].filter(Boolean).join(` `),children:[(0,n.jsxs)(`header`,{className:`ds-modal__head`,children:[(0,n.jsxs)(`div`,{className:`ds-modal__titles`,children:[(0,n.jsx)(`h2`,{id:g,className:`ds-modal__title`,children:o}),s&&(0,n.jsx)(`p`,{id:_,className:`ds-modal__description`,children:s})]}),(0,n.jsx)(e.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Close`,className:`ds-modal__close`,onClick:()=>h.current()})]}),(0,n.jsx)(`div`,{className:`ds-modal__body`,children:d}),l&&(0,n.jsx)(`footer`,{className:`ds-modal__footer`,children:l})]})}),document.body)});exports.Modal=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["forwardRef","useRef","useId","createPortal","Button","require_components_Button_index","react","react_jsx_runtime","react_dom","Modal","rest","panelRef","onCloseRef","onClose","titleId","descriptionId","isOpen","previous","onKeyDown","event","focusable","first","last","overflow","node","ref","description","size","className","title","footer"],"sources":["../../../src/components/Modal/index.tsx"],"sourcesContent":["import { forwardRef, useEffect, useId, useRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport \"./style.css\";\n\nexport type ModalSize = \"dialog\" | \"md\" | \"wide\";\n\nexport interface ModalProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: string;\n description?: string;\n size?: ModalSize;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\n/**\n * A focused task on top of the page. Heavy frame, hairline rules, a quiet\n * footer band — the collection frame, floated. Focus is trapped while open.\n */\nexport const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(\n { isOpen, onClose, title, description, size = \"md\", footer, className, children, ...rest },\n ref,\n) {\n const panelRef = useRef<HTMLDivElement | null>(null);\n const onCloseRef = useRef(onClose);\n const titleId = useId();\n const descriptionId = useId();\n\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n useEffect(() => {\n if (!isOpen) return;\n\n const previous = document.activeElement as HTMLElement | null;\n const initialFocus = panelRef.current?.querySelector<HTMLElement>(\n \"button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])\",\n );\n (initialFocus ?? panelRef.current)?.focus();\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onCloseRef.current();\n return;\n }\n if (event.key !== \"Tab\") return;\n const focusable = Array.from(\n panelRef.current?.querySelectorAll<HTMLElement>(\n \"button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])\",\n ) ?? [],\n );\n if (focusable.length === 0) return;\n const first = focusable[0]!;\n const last = focusable[focusable.length - 1]!;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", onKeyDown);\n const overflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n document.body.style.overflow = overflow;\n previous?.focus();\n };\n }, [isOpen]);\n\n if (!isOpen || typeof document === \"undefined\") return null;\n\n return createPortal(\n <div className=\"ds-scrim\" onMouseDown={(event) => event.target === event.currentTarget && onCloseRef.current()}>\n <div\n {...rest}\n ref={(node) => {\n panelRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={titleId}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n data-size={size}\n className={[\"ds-modal\", className].filter(Boolean).join(\" \")}\n >\n <header className=\"ds-modal__head\">\n <div className=\"ds-modal__titles\">\n <h2 id={titleId} className=\"ds-modal__title\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"ds-modal__description\">\n {description}\n </p>\n )}\n </div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label=\"Close\"\n className=\"ds-modal__close\"\n onClick={() => onCloseRef.current()}\n />\n </header>\n <div className=\"ds-modal__body\">{children}</div>\n {footer && <footer className=\"ds-modal__footer\">{footer}</footer>}\n </div>\n </div>,\n document.body,\n );\n});\n"],"mappings":"A,uLAuBA,IAAaS,GAAA,EAAQT,EAAAA,WAAAA,CAAuC,SAC1D,CAAE,SAAQ,UAAS,QAAO,cAAa,OAAO,KAAM,SAAQ,YAAW,WAAU,GAAGU,GACpF,EACA,CACA,IAAMC,GAAA,EAAWV,EAAAA,OAAAA,CAA8B,IAAI,EAC7CW,GAAA,EAAaX,EAAAA,OAAAA,CAAOY,CAAO,EAC3BC,GAAA,EAAUZ,EAAAA,MAAAA,CAAM,EAChBa,GAAA,EAAgBb,EAAAA,MAAAA,CAAM,EAmD5B,OAjDA,EAAAI,EAAA,UAAA,KAAgB,CACd,EAAW,QAAUO,CACvB,EAAG,CAACA,CAAO,CAAC,GAEZ,EAAAP,EAAA,UAAA,KAAgB,CACd,GAAI,CAACU,EAAQ,OAEb,IAAMC,EAAW,SAAS,eACLN,EAAS,SAAS,cACrC,sIACF,GACiBA,EAAS,QAAA,EAAU,MAAM,EAE1C,IAAMO,EAAa,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AQ,UAAU,iBAAlB,SAAA,EACE,EAAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,mBAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,KAAD,CAAI,GAAIO,EAAS,UAAU,kBACxB,SAAAe,CACC,CAAA,EACHH,IACC,EAAAnB,EAAA,IAAA,CAAC,IAAD,CAAG,GAAIQ,EAAe,UAAU,wBAC7B,SAAAW,CACA,CAAA,CAEF,CACL,CAAA,GAAA,EAAAnB,EAAA,IAAA,CAACH,EAAAA,OAAD,CACE,QAAQ,SACR,KAAK,KACL,WAAA,GACA,UAAU,IACV,aAAW,QACX,UAAU,kBACV,YAAeQ,EAAW,QAAQ,CACnC,CAAA,CACK,C,IACR,EAAAL,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,iBAAkB,UAAc,CAAA,EAC9CuB,IAAU,EAAAvB,EAAA,IAAA,CAAC,SAAD,CAAQ,UAAU,mBAAoB,SAAAuB,CAAe,CAAA,CAC7D,C,EACF,CAAA,EACL,SAAS,IACX,CACF,CAAC,E"}
1
+ {"version":3,"file":"index.cjs","names":["forwardRef","useRef","useId","createPortal","Button","require_components_Button_index","react","react_jsx_runtime","react_dom","Modal","rest","panelRef","onCloseRef","onClose","titleId","descriptionId","isOpen","previous","onKeyDown","event","focusable","first","last","overflow","node","ref","description","size","className","title","footer"],"sources":["../../../src/components/Modal/index.tsx"],"sourcesContent":["import { forwardRef, useEffect, useId, useRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport \"./style.css\";\n\nexport type ModalSize = \"dialog\" | \"md\" | \"wide\";\n\nexport interface ModalProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: string;\n description?: string;\n size?: ModalSize;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\n/**\n * A focused task on top of the page. Heavy frame, hairline rules, a quiet\n * footer band — the collection frame, floated. Focus is trapped while open.\n */\nexport const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(\n { isOpen, onClose, title, description, size = \"md\", footer, className, children, ...rest },\n ref,\n) {\n const panelRef = useRef<HTMLDivElement | null>(null);\n const onCloseRef = useRef(onClose);\n const titleId = useId();\n const descriptionId = useId();\n\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n useEffect(() => {\n if (!isOpen) return;\n\n const previous = document.activeElement as HTMLElement | null;\n const initialFocus = panelRef.current?.querySelector<HTMLElement>(\n \":is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])\",\n );\n (initialFocus ?? panelRef.current)?.focus();\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onCloseRef.current();\n return;\n }\n if (event.key !== \"Tab\") return;\n const focusable = Array.from(\n panelRef.current?.querySelectorAll<HTMLElement>(\n \":is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])\",\n ) ?? [],\n );\n if (focusable.length === 0) return;\n const first = focusable[0]!;\n const last = focusable[focusable.length - 1]!;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", onKeyDown);\n const overflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n document.body.style.overflow = overflow;\n previous?.focus();\n };\n }, [isOpen]);\n\n if (!isOpen || typeof document === \"undefined\") return null;\n\n return createPortal(\n <div className=\"ds-scrim\" onMouseDown={(event) => event.target === event.currentTarget && onCloseRef.current()}>\n <div\n {...rest}\n ref={(node) => {\n panelRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={titleId}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n data-size={size}\n className={[\"ds-modal\", className].filter(Boolean).join(\" \")}\n >\n <header className=\"ds-modal__head\">\n <div className=\"ds-modal__titles\">\n <h2 id={titleId} className=\"ds-modal__title\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"ds-modal__description\">\n {description}\n </p>\n )}\n </div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label=\"Close\"\n className=\"ds-modal__close\"\n onClick={() => onCloseRef.current()}\n />\n </header>\n <div className=\"ds-modal__body\">{children}</div>\n {footer && <footer className=\"ds-modal__footer\">{footer}</footer>}\n </div>\n </div>,\n document.body,\n );\n});\n"],"mappings":"A,uLAuBA,IAAaS,GAAA,EAAQT,EAAAA,WAAAA,CAAuC,SAC1D,CAAE,SAAQ,UAAS,QAAO,cAAa,OAAO,KAAM,SAAQ,YAAW,WAAU,GAAGU,GACpF,EACA,CACA,IAAMC,GAAA,EAAWV,EAAAA,OAAAA,CAA8B,IAAI,EAC7CW,GAAA,EAAaX,EAAAA,OAAAA,CAAOY,CAAO,EAC3BC,GAAA,EAAUZ,EAAAA,MAAAA,CAAM,EAChBa,GAAA,EAAgBb,EAAAA,MAAAA,CAAM,EAmD5B,OAjDA,EAAAI,EAAA,UAAA,KAAgB,CACd,EAAW,QAAUO,CACvB,EAAG,CAACA,CAAO,CAAC,GAEZ,EAAAP,EAAA,UAAA,KAAgB,CACd,GAAI,CAACU,EAAQ,OAEb,IAAMC,EAAW,SAAS,eACLN,EAAS,SAAS,cACrC,8FACF,GACiBA,EAAS,QAAA,EAAU,MAAM,EAE1C,IAAMO,EAAa,GAAyB,CAC1C,GAAIC,EAAM,MAAQ,SAAU,CAC1BP,EAAW,QAAQ,EACnB,MACF,CACA,GAAIO,EAAM,MAAQ,MAAO,OACzB,IAAMC,EAAY,MAAM,KACtBT,EAAS,SAAS,iBAChB,8FACF,GAAK,CAAC,CACR,EACA,GAA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AnB,EAAA,IAAA,CAAC,IAAD,CAAG,GAAIQ,EAAe,UAAU,wBAC7B,SAAAW,CACA,CAAA,CAEF,CACL,CAAA,GAAA,EAAAnB,EAAA,IAAA,CAACH,EAAAA,OAAD,CACE,QAAQ,SACR,KAAK,KACL,WAAA,GACA,UAAU,IACV,aAAW,QACX,UAAU,kBACV,YAAeQ,EAAW,QAAQ,CACnC,CAAA,CACK,C,IACR,EAAAL,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,iBAAkB,UAAc,CAAA,EAC9CuB,IAAU,EAAAvB,EAAA,IAAA,CAAC,SAAD,CAAQ,UAAU,mBAAoB,SAAAuB,CAAe,CAAA,CAC7D,C,EACF,CAAA,EACL,SAAS,IACX,CACF,CAAC,E"}
@@ -10,14 +10,14 @@ var c = t(function({ isOpen: t, onClose: c, title: l, description: u, size: d =
10
10
  }, [c]), n(() => {
11
11
  if (!t) return;
12
12
  let e = document.activeElement;
13
- (_.current?.querySelector("button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])") ?? _.current)?.focus();
13
+ (_.current?.querySelector(":is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])") ?? _.current)?.focus();
14
14
  let n = (e) => {
15
15
  if (e.key === "Escape") {
16
16
  v.current();
17
17
  return;
18
18
  }
19
19
  if (e.key !== "Tab") return;
20
- let t = Array.from(_.current?.querySelectorAll("button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])") ?? []);
20
+ let t = Array.from(_.current?.querySelectorAll(":is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])") ?? []);
21
21
  if (t.length === 0) return;
22
22
  let n = t[0], r = t[t.length - 1];
23
23
  e.shiftKey && document.activeElement === n ? (e.preventDefault(), r.focus()) : !e.shiftKey && document.activeElement === r && (e.preventDefault(), n.focus());
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Modal","forwardRef","rest","panelRef","useRef","onCloseRef","onClose","titleId","useId","descriptionId","useEffect","isOpen","previous","onKeyDown","event","focusable","first","last","overflow","createPortal","node","ref","description","size","className","title","Button","footer"],"sources":["../../../src/components/Modal/index.tsx"],"sourcesContent":["import { forwardRef, useEffect, useId, useRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport \"./style.css\";\n\nexport type ModalSize = \"dialog\" | \"md\" | \"wide\";\n\nexport interface ModalProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: string;\n description?: string;\n size?: ModalSize;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\n/**\n * A focused task on top of the page. Heavy frame, hairline rules, a quiet\n * footer band — the collection frame, floated. Focus is trapped while open.\n */\nexport const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(\n { isOpen, onClose, title, description, size = \"md\", footer, className, children, ...rest },\n ref,\n) {\n const panelRef = useRef<HTMLDivElement | null>(null);\n const onCloseRef = useRef(onClose);\n const titleId = useId();\n const descriptionId = useId();\n\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n useEffect(() => {\n if (!isOpen) return;\n\n const previous = document.activeElement as HTMLElement | null;\n const initialFocus = panelRef.current?.querySelector<HTMLElement>(\n \"button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])\",\n );\n (initialFocus ?? panelRef.current)?.focus();\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onCloseRef.current();\n return;\n }\n if (event.key !== \"Tab\") return;\n const focusable = Array.from(\n panelRef.current?.querySelectorAll<HTMLElement>(\n \"button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex='-1'])\",\n ) ?? [],\n );\n if (focusable.length === 0) return;\n const first = focusable[0]!;\n const last = focusable[focusable.length - 1]!;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", onKeyDown);\n const overflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n document.body.style.overflow = overflow;\n previous?.focus();\n };\n }, [isOpen]);\n\n if (!isOpen || typeof document === \"undefined\") return null;\n\n return createPortal(\n <div className=\"ds-scrim\" onMouseDown={(event) => event.target === event.currentTarget && onCloseRef.current()}>\n <div\n {...rest}\n ref={(node) => {\n panelRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={titleId}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n data-size={size}\n className={[\"ds-modal\", className].filter(Boolean).join(\" \")}\n >\n <header className=\"ds-modal__head\">\n <div className=\"ds-modal__titles\">\n <h2 id={titleId} className=\"ds-modal__title\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"ds-modal__description\">\n {description}\n </p>\n )}\n </div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label=\"Close\"\n className=\"ds-modal__close\"\n onClick={() => onCloseRef.current()}\n />\n </header>\n <div className=\"ds-modal__body\">{children}</div>\n {footer && <footer className=\"ds-modal__footer\">{footer}</footer>}\n </div>\n </div>,\n document.body,\n );\n});\n"],"mappings":";;;;;AAuBA,IAAaA,IAAQC,EAAuC,SAC1D,EAAE,WAAQ,YAAS,UAAO,gBAAa,UAAO,MAAM,WAAQ,cAAW,aAAU,GAAGC,KACpF,GACA;CACA,IAAMC,IAAWC,EAA8B,IAAI,GAC7CC,IAAaD,EAAOE,CAAO,GAC3BC,IAA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GACA,MAAK;GACL,cAAW;GACX,mBAAiBb;GACjB,oBAAkBe,IAAcb,IAAgB,KAAA;GAChD,UAAU;GACV,aAAWc;GACX,WAAW,CAAC,YAAYC,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;GAb7D,UAAA;IAeE,kBAAC,UAAD;KAAQ,WAAU;KAAlB,UAAA,CACE,kBAAC,OAAD;MAAK,WAAU;MAAf,UAAA,CACE,kBAAC,MAAD;OAAI,IAAIjB;OAAS,WAAU;OACxB,UAAAkB;MACC,CAAA,GACHH,KACC,kBAAC,KAAD;OAAG,IAAIb;OAAe,WAAU;OAC7B,UAAAa;MACA,CAAA,CAEF;KACL,CAAA,GAAA,kBAACI,GAAD;MACE,SAAQ;MACR,MAAK;MACL,YAAA;MACA,WAAU;MACV,cAAW;MACX,WAAU;MACV,eAAerB,EAAW,QAAQ;KACnC,CAAA,CACK;;IACR,kBAAC,OAAD;KAAK,WAAU;KAAkB;IAAc,CAAA;IAC9CsB,KAAU,kBAAC,UAAD;KAAQ,WAAU;KAAoB,UAAAA;IAAe,CAAA;GAC7D;;CACF,CAAA,GACL,SAAS,IACX;AACF,CAAC"}
1
+ {"version":3,"file":"index.js","names":["Modal","forwardRef","rest","panelRef","useRef","onCloseRef","onClose","titleId","useId","descriptionId","useEffect","isOpen","previous","onKeyDown","event","focusable","first","last","overflow","createPortal","node","ref","description","size","className","title","Button","footer"],"sources":["../../../src/components/Modal/index.tsx"],"sourcesContent":["import { forwardRef, useEffect, useId, useRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport \"./style.css\";\n\nexport type ModalSize = \"dialog\" | \"md\" | \"wide\";\n\nexport interface ModalProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: string;\n description?: string;\n size?: ModalSize;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\n/**\n * A focused task on top of the page. Heavy frame, hairline rules, a quiet\n * footer band — the collection frame, floated. Focus is trapped while open.\n */\nexport const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(\n { isOpen, onClose, title, description, size = \"md\", footer, className, children, ...rest },\n ref,\n) {\n const panelRef = useRef<HTMLDivElement | null>(null);\n const onCloseRef = useRef(onClose);\n const titleId = useId();\n const descriptionId = useId();\n\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n useEffect(() => {\n if (!isOpen) return;\n\n const previous = document.activeElement as HTMLElement | null;\n const initialFocus = panelRef.current?.querySelector<HTMLElement>(\n \":is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])\",\n );\n (initialFocus ?? panelRef.current)?.focus();\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onCloseRef.current();\n return;\n }\n if (event.key !== \"Tab\") return;\n const focusable = Array.from(\n panelRef.current?.querySelectorAll<HTMLElement>(\n \":is(button, [href], input, select, textarea, [tabindex]):not(:disabled):not([tabindex='-1'])\",\n ) ?? [],\n );\n if (focusable.length === 0) return;\n const first = focusable[0]!;\n const last = focusable[focusable.length - 1]!;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n document.addEventListener(\"keydown\", onKeyDown);\n const overflow = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n document.body.style.overflow = overflow;\n previous?.focus();\n };\n }, [isOpen]);\n\n if (!isOpen || typeof document === \"undefined\") return null;\n\n return createPortal(\n <div className=\"ds-scrim\" onMouseDown={(event) => event.target === event.currentTarget && onCloseRef.current()}>\n <div\n {...rest}\n ref={(node) => {\n panelRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={titleId}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n data-size={size}\n className={[\"ds-modal\", className].filter(Boolean).join(\" \")}\n >\n <header className=\"ds-modal__head\">\n <div className=\"ds-modal__titles\">\n <h2 id={titleId} className=\"ds-modal__title\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"ds-modal__description\">\n {description}\n </p>\n )}\n </div>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label=\"Close\"\n className=\"ds-modal__close\"\n onClick={() => onCloseRef.current()}\n />\n </header>\n <div className=\"ds-modal__body\">{children}</div>\n {footer && <footer className=\"ds-modal__footer\">{footer}</footer>}\n </div>\n </div>,\n document.body,\n );\n});\n"],"mappings":";;;;;AAuBA,IAAaA,IAAQC,EAAuC,SAC1D,EAAE,WAAQ,YAAS,UAAO,gBAAa,UAAO,MAAM,WAAQ,cAAW,aAAU,GAAGC,KACpF,GACA;CACA,IAAMC,IAAWC,EAA8B,IAAI,GAC7CC,IAAaD,EAAOE,CAAO,GAC3BC,IAAUC,EAAM,GAChBC,IAAgBD,EAAM;CAmD5B,OAjDAE,QAAgB;EACd,EAAW,UAAUJ;CACvB,GAAG,CAACA,CAAO,CAAC,GAEZI,QAAgB;EACd,IAAI,CAACC,GAAQ;EAEb,IAAMC,IAAW,SAAS;EAI1B,CAHqBT,EAAS,SAAS,cACrC,8FACF,KACiBA,EAAS,QAAA,EAAU,MAAM;EAE1C,IAAMU,KAAa,MAAyB;GAC1C,IAAIC,EAAM,QAAQ,UAAU;IAC1B,EAAW,QAAQ;IACnB;GACF;GACA,IAAIA,EAAM,QAAQ,OAAO;GACzB,IAAMC,IAAY,MAAM,KACtBZ,EAAS,SAAS,iBAChB,8FACF,KAAK,CAAC,CACR;GACA,IAAIY,EAAU,WAAW,GAAG;GAC5B,IAAMC,IAAQD,EAAU,IAClBE,IAAOF,EAAUA,EAAU,SA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eAAerB,EAAW,QAAQ;KACnC,CAAA,CACK;;IACR,kBAAC,OAAD;KAAK,WAAU;KAAkB;IAAc,CAAA;IAC9CsB,KAAU,kBAAC,UAAD;KAAQ,WAAU;KAAoB,UAAAA;IAAe,CAAA;GAC7D;;CACF,CAAA,GACL,SAAS,IACX;AACF,CAAC"}
@@ -23,6 +23,7 @@
23
23
  border-radius: var(--overlay-radius);
24
24
  box-shadow: var(--shadow-lg);
25
25
  animation: ds-modal-in var(--duration-panel) var(--ease-panel);
26
+ overflow: hidden;
26
27
  }
27
28
 
28
29
  .ds-modal[data-size="dialog"] {
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/RichTextEditor-tFkISOvq.cjs");exports.RichTextEditor=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../Field/index.cjs"),require("../TextField/index.cjs");const e=require("../../chunks/RichTextEditor-DC_0oN1s.cjs");exports.RichTextEditor=e.t;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAM1H,OAAO,EAAuE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACxH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,aAAa,CAAC;AAErB,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,UAAU,yBAAyB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM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AAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAAE,CACjI,CAAC;AA8JF;;;GAGG;AACH,eAAO,MAAM,cAAc,gHAiK1B,CAAC"}
@@ -1 +1,3 @@
1
- export { t as RichTextEditor } from "../../chunks/RichTextEditor-DRt-kibg.js";
1
+ import "../Field/index.js";
2
+ import "../TextField/index.js";
3
+ export { t as RichTextEditor } from "../../chunks/RichTextEditor-CSpjsL1z.js";
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-CWsA1W83.cjs");let t=require("react"),n=require("react/jsx-runtime"),r=require("@dnd-kit/core"),i=require("@dnd-kit/modifiers"),a=require("@dnd-kit/sortable"),o=require("@dnd-kit/utilities");var s=(0,t.forwardRef)(function({items:o,onReorder:s,renderDragOverlay:c,className:l,children:u,...d},f){let p=(0,t.useId)(),[m,h]=(0,t.useState)(null),g=(0,r.useSensors)((0,r.useSensor)(r.PointerSensor,{activationConstraint:{distance:4}}),(0,r.useSensor)(r.KeyboardSensor,{coordinateGetter:a.sortableKeyboardCoordinates})),_=(0,t.useCallback)(e=>{h(String(e.active.id))},[]),v=(0,t.useCallback)(e=>{h(null);let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=o.indexOf(String(t.id)),i=o.indexOf(String(n.id));r<0||i<0||s?.((0,a.arrayMove)(o,r,i))},[o,s]);return(0,n.jsxs)(r.DndContext,{id:`ds-sortable-list-${p}`,sensors:g,collisionDetection:r.closestCenter,modifiers:[i.restrictToVerticalAxis],onDragStart:_,onDragEnd:v,onDragCancel:()=>h(null),children:[(0,n.jsx)(a.SortableContext,{items:o,strategy:a.verticalListSortingStrategy,children:(0,n.jsx)(`ul`,{ref:f,className:[`ds-sortable-list`,l].filter(Boolean).join(` `),...d,children:u})}),(0,n.jsx)(r.DragOverlay,{children:m?(0,n.jsxs)(`div`,{className:`ds-sortable-item`,"data-overlay":!0,children:[(0,n.jsx)(`span`,{className:`ds-sortable-item__handle`,"aria-hidden":`true`,children:(0,n.jsx)(e.t,{name:`grip-vertical`})}),(0,n.jsx)(`div`,{className:`ds-sortable-item__content`,children:c?.(m)})]}):null})]})}),c=(0,t.forwardRef)(function({id:t,label:r,action:i,className:s,children:c,...l},u){let{attributes:d,listeners:f,setNodeRef:p,transform:m,transition:h,isDragging:g}=(0,a.useSortable)({id:t});return(0,n.jsxs)(`li`,{ref:e=>{p(e),typeof u==`function`?u(e):u&&(u.current=e)},style:{transform:o.CSS.Translate.toString(m),transition:h},className:[`ds-sortable-item`,s].filter(Boolean).join(` `),"data-dragging":g||void 0,...l,children:[(0,n.jsx)(`button`,{type:`button`,className:`ds-sortable-item__handle`,"aria-label":r?`Move ${r}`:`Move item`,...d,...f,children:(0,n.jsx)(e.t,{name:`grip-vertical`})}),(0,n.jsx)(`div`,{className:`ds-sortable-item__content`,children:c}),i&&(0,n.jsx)(`div`,{className:`ds-sortable-item__action`,children:i})]})});exports.SortableList=s,exports.SortableListItem=c;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-CWsA1W83.cjs");let t=require("react"),n=require("react/jsx-runtime"),r=require("@dnd-kit/core"),i=require("@dnd-kit/modifiers"),a=require("@dnd-kit/sortable"),o=require("@dnd-kit/utilities");function s(e){return(0,t.isValidElement)(e)&&typeof e.props.id==`string`}var c=(0,t.forwardRef)(function({items:o,onReorder:c,renderDragOverlay:l,className:u,children:d,...f},p){let m=(0,t.useId)(),[h,g]=(0,t.useState)(null),[_,v]=(0,t.useState)(o),[y,b]=(0,t.useState)(o);o!==y&&o.join(`\0`)!==y.join(`\0`)&&(b(o),v(o));let x=(0,r.useSensors)((0,r.useSensor)(r.PointerSensor,{activationConstraint:{distance:4}}),(0,r.useSensor)(r.KeyboardSensor,{coordinateGetter:a.sortableKeyboardCoordinates})),S=(0,t.useCallback)(e=>{g(String(e.active.id))},[]),C=(0,t.useCallback)(e=>{g(null);let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=_.indexOf(String(t.id)),i=_.indexOf(String(n.id));if(r<0||i<0)return;let o=(0,a.arrayMove)(_,r,i);v(o),c?.(o)},[_,c]),w=t.Children.toArray(d),T=new Map(w.filter(s).map(e=>[e.props.id,e])),E=[..._.flatMap(e=>T.get(e)??[]),...w.filter(e=>!s(e)||!_.includes(e.props.id))],D=h?T.get(h):void 0;return(0,n.jsxs)(r.DndContext,{id:`ds-sortable-list-${m}`,sensors:x,collisionDetection:r.closestCenter,modifiers:[i.restrictToVerticalAxis],onDragStart:S,onDragEnd:C,onDragCancel:()=>g(null),children:[(0,n.jsx)(a.SortableContext,{items:_,strategy:a.verticalListSortingStrategy,children:(0,n.jsx)(`ul`,{ref:p,className:[`ds-sortable-list`,u].filter(Boolean).join(` `),...f,children:E})}),(0,n.jsx)(r.DragOverlay,{children:h?(0,n.jsxs)(`div`,{className:`ds-sortable-item`,"data-overlay":!0,children:[(0,n.jsx)(`span`,{className:`ds-sortable-item__handle`,"aria-hidden":`true`,children:(0,n.jsx)(e.t,{name:`grip-vertical`})}),(0,n.jsx)(`div`,{className:`ds-sortable-item__content`,children:l?l(h):D?.props.children})]}):null})]})}),l=(0,t.forwardRef)(function({id:t,label:r,action:i,className:s,children:c,...l},u){let{attributes:d,listeners:f,setNodeRef:p,transform:m,transition:h,isDragging:g}=(0,a.useSortable)({id:t});return(0,n.jsxs)(`li`,{ref:e=>{p(e),typeof u==`function`?u(e):u&&(u.current=e)},style:{transform:o.CSS.Translate.toString(m),transition:h},className:[`ds-sortable-item`,s].filter(Boolean).join(` `),"data-dragging":g||void 0,...l,children:[(0,n.jsx)(`button`,{type:`button`,className:`ds-sortable-item__handle`,"aria-label":r?`Move ${r}`:`Move item`,...d,...f,children:(0,n.jsx)(e.t,{name:`grip-vertical`})}),(0,n.jsx)(`div`,{className:`ds-sortable-item__content`,children:c}),i&&(0,n.jsx)(`div`,{className:`ds-sortable-item__action`,children:i})]})});exports.SortableList=c,exports.SortableListItem=l;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["forwardRef","useId","useState","useSensors","useSensor","PointerSensor","KeyboardSensor","sortableKeyboardCoordinates","useCallback","arrayMove","DndContext","closestCenter","restrictToVerticalAxis","SortableContext","verticalListSortingStrategy","DragOverlay","Icon","useSortable","CSS","require_Icon","react","react_jsx_runtime","_dnd_kit_core","_dnd_kit_modifiers","_dnd_kit_sortable","_dnd_kit_utilities","SortableList","rest","dndId","activeId","setActiveId","sensors","handleStart","event","handleEnd","over","active","from","items","to","onReorder","className","renderDragOverlay","SortableListItem","setNodeRef","node","ref","transform","isDragging","label","attributes","listeners","action"],"sources":["../../../src/components/SortableList/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useId,\n useState,\n type HTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport {\n DndContext,\n DragOverlay,\n KeyboardSensor,\n PointerSensor,\n closestCenter,\n useSensor,\n useSensors,\n type DragEndEvent,\n type DragStartEvent,\n} from \"@dnd-kit/core\";\nimport { restrictToVerticalAxis } from \"@dnd-kit/modifiers\";\nimport {\n SortableContext,\n arrayMove,\n sortableKeyboardCoordinates,\n useSortable,\n verticalListSortingStrategy,\n} from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\nimport { Icon } from \"../Icon\";\nimport \"./style.css\";\n\nexport interface SortableListProps extends Omit<HTMLAttributes<HTMLUListElement>, \"onDragEnd\"> {\n /** Item ids in render order. */\n items: string[];\n /** Fired with the whole list in its new order. Apply it to your own state. */\n onReorder?: (items: string[]) => void;\n /** Rendered inside the drag overlay while a row is in the air. */\n renderDragOverlay?: (id: string) => ReactNode;\n children?: ReactNode;\n}\n\n/**\n * A single vertical list you can re-order — the board's mechanics without the\n * lanes. Each row carries a grip on the left; the list owns dragging only, the\n * data stays yours: react to `onReorder`.\n */\nexport const SortableList = forwardRef<HTMLUListElement, SortableListProps>(\n function SortableList({ items, onReorder, renderDragOverlay, className, children, ...rest }, ref) {\n const dndId = useId();\n const [activeId, setActiveId] = useState<string | null>(null);\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),\n useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),\n );\n\n const handleStart = useCallback((event: DragStartEvent) => {\n setActiveId(String(event.active.id));\n }, []);\n\n const handleEnd = useCallback(\n (event: DragEndEvent) => {\n setActiveId(null);\n const { active, over } = event;\n if (!over || active.id === over.id) return;\n const from = items.indexOf(String(active.id));\n const to = items.indexOf(String(over.id));\n if (from < 0 || to < 0) return;\n onReorder?.(arrayMove(items, from, to));\n },\n [items, onReorder],\n );\n\n return (\n <DndContext\n id={`ds-sortable-list-${dndId}`}\n sensors={sensors}\n collisionDetection={closestCenter}\n modifiers={[restrictToVerticalAxis]}\n onDragStart={handleStart}\n onDragEnd={handleEnd}\n onDragCancel={() => setActiveId(null)}\n >\n <SortableContext items={items} strategy={verticalListSortingStrategy}>\n <ul\n ref={ref}\n className={[\"ds-sortable-list\", className].filter(Boolean).join(\" \")}\n {...rest}\n >\n {children}\n </ul>\n </SortableContext>\n <DragOverlay>\n {activeId ? (\n <div className=\"ds-sortable-item\" data-overlay>\n <span className=\"ds-sortable-item__handle\" aria-hidden=\"true\">\n <Icon name=\"grip-vertical\" />\n </span>\n <div className=\"ds-sortable-item__content\">{renderDragOverlay?.(activeId)}</div>\n </div>\n ) : null}\n </DragOverlay>\n </DndContext>\n );\n },\n);\n\nexport interface SortableListItemProps extends HTMLAttributes<HTMLLIElement> {\n id: string;\n /** Accessible name announced when the row is picked up. */\n label?: string;\n /** A control at the end of the row, e.g. a menu or a delete button. */\n action?: ReactNode;\n children?: ReactNode;\n}\n\n/** One row of a `SortableList`. The grip on the left is the only handle. */\nexport const SortableListItem = forwardRef<HTMLLIElement, SortableListItemProps>(\n function SortableListItem({ id, label, action, className, children, ...rest }, ref) {\n const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({\n id,\n });\n\n return (\n <li\n ref={(node) => {\n setNodeRef(node);\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n style={{ transform: CSS.Translate.toString(transform), transition }}\n className={[\"ds-sortable-item\", className].filter(Boolean).join(\" \")}\n data-dragging={isDragging || undefined}\n {...rest}\n >\n <button\n type=\"button\"\n className=\"ds-sortable-item__handle\"\n aria-label={label ? `Move ${label}` : \"Move item\"}\n {...attributes}\n {...listeners}\n >\n <Icon name=\"grip-vertical\" />\n </button>\n <div className=\"ds-sortable-item__content\">{children}</div>\n {action && <div className=\"ds-sortable-item__action\">{action}</div>}\n </li>\n );\n },\n);\n"],"mappings":"A,qSA8CA,IAAa0B,GAAA,EAAe1B,EAAAA,WAAAA,CAC1B,SAAsB,CAAE,QAAO,YAAW,oBAAmB,YAAW,WAAU,GAAG2B,GAAQ,EAAK,CAChG,IAAMC,GAAA,EAAQ3B,EAAAA,MAAAA,CAAM,EACd,CAAC4B,EAAUC,IAAA,EAAe5B,EAAAA,SAAAA,CAAwB,IAAI,EACtD6B,GAAA,EAAU5B,EAAAA,WAAAA,EAAAA,EACdC,EAAAA,UAAAA,CAAUC,EAAAA,cAAe,CAAE,qBAAsB,CAAE,SAAU,CAAE,CAAE,CAAC,GAAA,EAClED,EAAAA,UAAAA,CAAUE,EAAAA,eAAgB,CAAE,iBAAkBC,EAAAA,2BAA4B,CAAC,CAC7E,EAEMyB,GAAA,EAAcxB,EAAAA,YAAAA,CAAa,GAA0B,CACzDsB,EAAY,OAAOG,EAAM,OAAO,EAAE,CAAC,CACrC,EAAG,CAAC,CAAC,EAECC,GAAA,EAAY1B,EAAAA,YAAAA,CACf,GAAwB,CACvBsB,EAAY,IAAI,EAChB,GAAM,CAAE,SAAQ,QAASG,EACzB,GAAI,CAACE,GAAQC,EAAO,KAAOD,EAAK,GAAI,OACpC,IAAME,EAAOC,EAAM,QAAQ,OAAOF,EAAO,EAAE,CAAC,EACtCG,EAAKD,EAAM,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C3F,IACF,CAAC,EAED,OACE,EAAAI,EAAA,KAAA,CAAC,KAAD,CACE,IAAM,GAAS,CACbuB,EAAWC,CAAI,EACX,OAAOC,GAAQ,WAAYA,EAAID,CAAI,EAC9BC,IAAK,EAAI,QAAUD,EAC9B,EACA,MAAO,CAAE,UAAW3B,EAAAA,IAAI,UAAU,SAAS6B,CAAS,EAAG,YAAW,EAClE,UAAW,CAAC,mBAAoBN,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EACnE,gBAAeO,GAAc,IAAA,GAC7B,GAAIrB,EATN,SAAA,EAWE,EAAAN,EAAA,IAAA,CAAC,SAAD,CACE,KAAK,SACL,UAAU,2BACV,aAAY4B,EAAQ,QAAQA,IAAU,YACtC,GAAIC,EACJ,GAAIC,EAEJ,UAAA,EAAA9B,EAAA,IAAA,CAACL,EAAAA,EAAD,CAAM,KAAK,eAAiB,CAAA,CACtB,CAAA,GACR,EAAAK,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,4BAA6B,UAAc,CAAA,EACzD+B,IAAU,EAAA/B,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,2BAA4B,SAAA+B,CAAY,CAAA,CAChE,C,EAER,CACF,E"}
1
+ {"version":3,"file":"index.cjs","names":["isValidElement","forwardRef","useId","useState","useSensors","useSensor","PointerSensor","KeyboardSensor","sortableKeyboardCoordinates","useCallback","arrayMove","Children","DndContext","closestCenter","restrictToVerticalAxis","SortableContext","verticalListSortingStrategy","DragOverlay","Icon","useSortable","CSS","require_Icon","react","react_jsx_runtime","_dnd_kit_core","_dnd_kit_modifiers","_dnd_kit_sortable","_dnd_kit_utilities","isItem","child","SortableList","rest","dndId","activeId","setActiveId","order","setOrder","items","prevItems","setPrevItems","sensors","handleStart","event","handleEnd","over","active","from","to","next","onReorder","childArray","children","rows","ordered","id","activeRow","className","renderDragOverlay","SortableListItem","setNodeRef","node","ref","transform","isDragging","label","attributes","listeners","action"],"sources":["../../../src/components/SortableList/index.tsx"],"sourcesContent":["import {\n Children,\n forwardRef,\n isValidElement,\n useCallback,\n useId,\n useState,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport {\n DndContext,\n DragOverlay,\n KeyboardSensor,\n PointerSensor,\n closestCenter,\n useSensor,\n useSensors,\n type DragEndEvent,\n type DragStartEvent,\n} from \"@dnd-kit/core\";\nimport { restrictToVerticalAxis } from \"@dnd-kit/modifiers\";\nimport {\n SortableContext,\n arrayMove,\n sortableKeyboardCoordinates,\n useSortable,\n verticalListSortingStrategy,\n} from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\nimport { Icon } from \"../Icon\";\nimport \"./style.css\";\n\nexport interface SortableListProps extends Omit<HTMLAttributes<HTMLUListElement>, \"onDragEnd\"> {\n /** Item ids in render order. */\n items: string[];\n /** Fired with the whole list in its new order. Apply it to your own state. */\n onReorder?: (items: string[]) => void;\n /** Rendered inside the drag overlay while a row is in the air. Defaults to the row's content. */\n renderDragOverlay?: (id: string) => ReactNode;\n children?: ReactNode;\n}\n\ntype ItemElement = ReactElement<SortableListItemProps>;\n\nfunction isItem(child: ReactNode): child is ItemElement {\n return isValidElement<SortableListItemProps>(child) && typeof child.props.id === \"string\";\n}\n\n/**\n * A single vertical list you can re-order — the board's mechanics without the\n * lanes. Each row carries a grip on the left. The list keeps the dropped order\n * itself, so it works on its own; pass `onReorder` to mirror it into your data.\n * A new `items` value from the parent always wins.\n */\nexport const SortableList = forwardRef<HTMLUListElement, SortableListProps>(\n function SortableList({ items, onReorder, renderDragOverlay, className, children, ...rest }, ref) {\n const dndId = useId();\n const [activeId, setActiveId] = useState<string | null>(null);\n const [order, setOrder] = useState(items);\n const [prevItems, setPrevItems] = useState(items);\n if (items !== prevItems && items.join(\"\\u0000\") !== prevItems.join(\"\\u0000\")) {\n setPrevItems(items);\n setOrder(items);\n }\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),\n useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),\n );\n\n const handleStart = useCallback((event: DragStartEvent) => {\n setActiveId(String(event.active.id));\n }, []);\n\n const handleEnd = useCallback(\n (event: DragEndEvent) => {\n setActiveId(null);\n const { active, over } = event;\n if (!over || active.id === over.id) return;\n const from = order.indexOf(String(active.id));\n const to = order.indexOf(String(over.id));\n if (from < 0 || to < 0) return;\n const next = arrayMove(order, from, to);\n setOrder(next);\n onReorder?.(next);\n },\n [order, onReorder],\n );\n\n // Rows follow the list's own order; anything that isn't a row keeps its place at the end.\n const childArray = Children.toArray(children);\n const rows = new Map(childArray.filter(isItem).map((child) => [child.props.id, child]));\n const ordered = [\n ...order.flatMap((id) => rows.get(id) ?? []),\n ...childArray.filter((child) => !isItem(child) || !order.includes(child.props.id)),\n ];\n const activeRow = activeId ? rows.get(activeId) : undefined;\n\n return (\n <DndContext\n id={`ds-sortable-list-${dndId}`}\n sensors={sensors}\n collisionDetection={closestCenter}\n modifiers={[restrictToVerticalAxis]}\n onDragStart={handleStart}\n onDragEnd={handleEnd}\n onDragCancel={() => setActiveId(null)}\n >\n <SortableContext items={order} strategy={verticalListSortingStrategy}>\n <ul\n ref={ref}\n className={[\"ds-sortable-list\", className].filter(Boolean).join(\" \")}\n {...rest}\n >\n {ordered}\n </ul>\n </SortableContext>\n <DragOverlay>\n {activeId ? (\n <div className=\"ds-sortable-item\" data-overlay>\n <span className=\"ds-sortable-item__handle\" aria-hidden=\"true\">\n <Icon name=\"grip-vertical\" />\n </span>\n <div className=\"ds-sortable-item__content\">\n {renderDragOverlay ? renderDragOverlay(activeId) : activeRow?.props.children}\n </div>\n </div>\n ) : null}\n </DragOverlay>\n </DndContext>\n );\n },\n);\n\nexport interface SortableListItemProps extends HTMLAttributes<HTMLLIElement> {\n id: string;\n /** Accessible name announced when the row is picked up. */\n label?: string;\n /** A control at the end of the row, e.g. a menu or a delete button. */\n action?: ReactNode;\n children?: ReactNode;\n}\n\n/** One row of a `SortableList`. The grip on the left is the only handle. */\nexport const SortableListItem = forwardRef<HTMLLIElement, SortableListItemProps>(\n function SortableListItem({ id, label, action, className, children, ...rest }, ref) {\n const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({\n id,\n });\n\n return (\n <li\n ref={(node) => {\n setNodeRef(node);\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n style={{ transform: CSS.Translate.toString(transform), transition }}\n className={[\"ds-sortable-item\", className].filter(Boolean).join(\" \")}\n data-dragging={isDragging || undefined}\n {...rest}\n >\n <button\n type=\"button\"\n className=\"ds-sortable-item__handle\"\n aria-label={label ? `Move ${label}` : \"Move item\"}\n {...attributes}\n {...listeners}\n >\n <Icon name=\"grip-vertical\" />\n </button>\n <div className=\"ds-sortable-item__content\">{children}</div>\n {action && <div className=\"ds-sortable-item__action\">{action}</div>}\n </li>\n );\n },\n);\n"],"mappings":"A,qSA8CA,SAAS4B,EAAO,EAAwC,CACtD,OAAA,EAAO5B,EAAAA,eAAAA,CAAsC6B,CAAK,GAAK,OAAOA,EAAM,MAAM,IAAO,QACnF,CAQA,IAAaC,GAAA,EAAe7B,EAAAA,WAAAA,CAC1B,SAAsB,CAAE,QAAO,YAAW,oBAAmB,YAAW,WAAU,GAAG8B,GAAQ,EAAK,CAChG,IAAMC,GAAA,EAAQ9B,EAAAA,MAAAA,CAAM,EACd,CAAC+B,EAAUC,IAAA,EAAe/B,EAAAA,SAAAA,CAAwB,IAAI,EACtD,CAACgC,EAAOC,IAAA,EAAYjC,EAAAA,SAAAA,CAASkC,CAAK,EAClC,CAACC,EAAWC,IAAA,EAAgBpC,EAAAA,SAAAA,CAASkC,CAAK,EAC5CA,IAAUC,GAAaD,EAAM,KAAK,IAAQ,IAAMC,EAAU,KAAK,IAAQ,IACzEC,EAAaF,CAAK,EAClBD,EAASC,CAAK,GAEhB,IAAMG,GAAA,EAAUpC,EAAAA,WAAAA,EAAAA,EACdC,EAAAA,UAAAA,CAAUC,EAAAA,cAAe,CAAE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E,UAAW,CAAC,mBAAoBN,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EACnE,gBAAeO,GAAc,IAAA,GAC7B,GAAIhC,EATN,SAAA,EAWE,EAAAR,EAAA,IAAA,CAAC,SAAD,CACE,KAAK,SACL,UAAU,2BACV,aAAYyC,EAAQ,QAAQA,IAAU,YACtC,GAAIC,EACJ,GAAIC,EAEJ,UAAA,EAAA3C,EAAA,IAAA,CAACL,EAAAA,EAAD,CAAM,KAAK,eAAiB,CAAA,CACtB,CAAA,GACR,EAAAK,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,4BAA6B,UAAc,CAAA,EACzD4C,IAAU,EAAA5C,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,2BAA4B,SAAA4C,CAAY,CAAA,CAChE,C,EAER,CACF,E"}
@@ -4,14 +4,15 @@ export interface SortableListProps extends Omit<HTMLAttributes<HTMLUListElement>
4
4
  items: string[];
5
5
  /** Fired with the whole list in its new order. Apply it to your own state. */
6
6
  onReorder?: (items: string[]) => void;
7
- /** Rendered inside the drag overlay while a row is in the air. */
7
+ /** Rendered inside the drag overlay while a row is in the air. Defaults to the row's content. */
8
8
  renderDragOverlay?: (id: string) => ReactNode;
9
9
  children?: ReactNode;
10
10
  }
11
11
  /**
12
12
  * A single vertical list you can re-order — the board's mechanics without the
13
- * lanes. Each row carries a grip on the left; the list owns dragging only, the
14
- * data stays yours: react to `onReorder`.
13
+ * lanes. Each row carries a grip on the left. The list keeps the dropped order
14
+ * itself, so it works on its own; pass `onReorder` to mirror it into your data.
15
+ * A new `items` value from the parent always wins.
15
16
  */
16
17
  export declare const SortableList: import("react").ForwardRefExoticComponent<SortableListProps & import("react").RefAttributes<HTMLUListElement>>;
17
18
  export interface SortableListItemProps extends HTMLAttributes<HTMLLIElement> {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/SortableList/index.tsx"],"names":[],"mappings":"AAAA,OAAO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CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAC;IAC9C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAQD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,gHA6ExB,CAAC;AAEF,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,aAAa,CAAC;IAC1E,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,iHAgC5B,CAAC"}
@@ -4,14 +4,15 @@ export interface SortableListProps extends Omit<HTMLAttributes<HTMLUListElement>
4
4
  items: string[];
5
5
  /** Fired with the whole list in its new order. Apply it to your own state. */
6
6
  onReorder?: (items: string[]) => void;
7
- /** Rendered inside the drag overlay while a row is in the air. */
7
+ /** Rendered inside the drag overlay while a row is in the air. Defaults to the row's content. */
8
8
  renderDragOverlay?: (id: string) => ReactNode;
9
9
  children?: ReactNode;
10
10
  }
11
11
  /**
12
12
  * A single vertical list you can re-order — the board's mechanics without the
13
- * lanes. Each row carries a grip on the left; the list owns dragging only, the
14
- * data stays yours: react to `onReorder`.
13
+ * lanes. Each row carries a grip on the left. The list keeps the dropped order
14
+ * itself, so it works on its own; pass `onReorder` to mirror it into your data.
15
+ * A new `items` value from the parent always wins.
15
16
  */
16
17
  export declare const SortableList: import("react").ForwardRefExoticComponent<SortableListProps & import("react").RefAttributes<HTMLUListElement>>;
17
18
  export interface SortableListItemProps extends HTMLAttributes<HTMLLIElement> {