@smwb/ui-react 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/assets/styles/less/components/confirmDialog/confirmDialog.entry.css +1 -0
  2. package/dist/assets/styles/less/components/fileDrop/fileDrop.entry.css +1 -0
  3. package/dist/assets/styles/less/components/fileInput/fileInput.entry.css +1 -0
  4. package/dist/assets/styles/less/components/floatingWindow/floatingWindow.entry.css +1 -0
  5. package/dist/components/dataDisplay/chat/chat.d.ts +1 -1
  6. package/dist/components/dataDisplay/chat/chat.js.map +1 -1
  7. package/dist/components/dataDisplay/chat/useChatFileUpload.d.ts +16 -4
  8. package/dist/components/dataDisplay/chat/useChatFileUpload.js +38 -29
  9. package/dist/components/dataDisplay/chat/useChatFileUpload.js.map +1 -1
  10. package/dist/components/feedBack/confirmDialog/confirmDialog.d.ts +27 -0
  11. package/dist/components/feedBack/confirmDialog/confirmDialog.js +49 -0
  12. package/dist/components/feedBack/confirmDialog/confirmDialog.js.map +1 -0
  13. package/dist/components/feedBack/confirmDialog/index.d.ts +2 -0
  14. package/dist/components/inputs/fileDrop/countPreview.js +15 -0
  15. package/dist/components/inputs/fileDrop/countPreview.js.map +1 -0
  16. package/dist/components/inputs/fileDrop/fileDrop.d.ts +1 -1
  17. package/dist/components/inputs/fileDrop/fileDrop.js +60 -0
  18. package/dist/components/inputs/fileDrop/fileDrop.js.map +1 -0
  19. package/dist/components/inputs/fileDrop/index.d.ts +9 -0
  20. package/dist/components/inputs/fileDrop/preview.js +41 -0
  21. package/dist/components/inputs/fileDrop/preview.js.map +1 -0
  22. package/dist/components/inputs/fileDrop/previewWrapper.js +27 -0
  23. package/dist/components/inputs/fileDrop/previewWrapper.js.map +1 -0
  24. package/dist/components/inputs/fileDrop/utils.js +7 -0
  25. package/dist/components/inputs/fileDrop/utils.js.map +1 -0
  26. package/dist/components/inputs/fileInput/fileInput.d.ts +1 -1
  27. package/dist/components/inputs/fileInput/fileInput.js +35 -0
  28. package/dist/components/inputs/fileInput/fileInput.js.map +1 -0
  29. package/dist/components/inputs/fileInput/index.d.ts +2 -0
  30. package/dist/components/layout/floatingWindow/floatingWindow.d.ts +92 -0
  31. package/dist/components/layout/floatingWindow/floatingWindow.js +311 -0
  32. package/dist/components/layout/floatingWindow/floatingWindow.js.map +1 -0
  33. package/dist/components/layout/floatingWindow/index.d.ts +2 -0
  34. package/dist/headless/components/dataDisplay/chat/chat.js.map +1 -1
  35. package/dist/headless/components/dataDisplay/chat/useChatFileUpload.js +38 -29
  36. package/dist/headless/components/dataDisplay/chat/useChatFileUpload.js.map +1 -1
  37. package/dist/headless/components/feedBack/confirmDialog/confirmDialog.js +48 -0
  38. package/dist/headless/components/feedBack/confirmDialog/confirmDialog.js.map +1 -0
  39. package/dist/headless/components/inputs/fileDrop/countPreview.js +15 -0
  40. package/dist/headless/components/inputs/fileDrop/countPreview.js.map +1 -0
  41. package/dist/headless/components/inputs/fileDrop/fileDrop.js +59 -0
  42. package/dist/headless/components/inputs/fileDrop/fileDrop.js.map +1 -0
  43. package/dist/headless/components/inputs/fileDrop/preview.js +41 -0
  44. package/dist/headless/components/inputs/fileDrop/preview.js.map +1 -0
  45. package/dist/headless/components/inputs/fileDrop/previewWrapper.js +27 -0
  46. package/dist/headless/components/inputs/fileDrop/previewWrapper.js.map +1 -0
  47. package/dist/headless/components/inputs/fileDrop/utils.js +7 -0
  48. package/dist/headless/components/inputs/fileDrop/utils.js.map +1 -0
  49. package/dist/headless/components/inputs/fileInput/fileInput.js +34 -0
  50. package/dist/headless/components/inputs/fileInput/fileInput.js.map +1 -0
  51. package/dist/headless/components/layout/floatingWindow/floatingWindow.js +310 -0
  52. package/dist/headless/components/layout/floatingWindow/floatingWindow.js.map +1 -0
  53. package/dist/headless/hooks/useDropzone.js +47 -0
  54. package/dist/headless/hooks/useDropzone.js.map +1 -0
  55. package/dist/headless/index.js +277 -259
  56. package/dist/headless/index.js.map +1 -1
  57. package/dist/hooks/useDropzone.d.ts +44 -0
  58. package/dist/hooks/useDropzone.js +47 -0
  59. package/dist/hooks/useDropzone.js.map +1 -0
  60. package/dist/index.cjs +2 -2
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.d.ts +10 -0
  63. package/dist/index.js +277 -259
  64. package/dist/index.js.map +1 -1
  65. package/package.json +2 -3
@@ -1 +1 @@
1
- {"version":3,"file":"useChatFileUpload.js","sources":["../../../../../src/components/dataDisplay/chat/useChatFileUpload.ts"],"sourcesContent":["import { useDropzone, type Accept } from \"react-dropzone\";\nimport { CHAT_DEFAULT_FILE_UPLOAD_MAX_FILES } from \"./types\";\n\nexport interface UseChatFileUploadOptions {\n enabled?: boolean;\n accept?: Accept;\n maxFiles?: number;\n onUploadFiles?: (files: File[]) => void | Promise<void>;\n disabled?: boolean;\n}\n\nexport function resolveChatFileUploadMaxFiles(maxFiles?: number): number {\n if (maxFiles == null) {\n return CHAT_DEFAULT_FILE_UPLOAD_MAX_FILES;\n }\n\n return Math.max(1, maxFiles);\n}\n\nexport function useChatFileUpload({\n enabled = false,\n accept,\n maxFiles,\n onUploadFiles,\n disabled = false,\n}: UseChatFileUploadOptions) {\n const resolvedMaxFiles = resolveChatFileUploadMaxFiles(maxFiles);\n const active = enabled && Boolean(onUploadFiles) && !disabled;\n\n const { getRootProps, getInputProps, open, isDragActive, inputRef } = useDropzone({\n accept,\n maxFiles: resolvedMaxFiles,\n multiple: resolvedMaxFiles > 1,\n disabled: !active,\n noClick: true,\n noKeyboard: true,\n useFsAccessApi: false,\n onDropAccepted: (files) => {\n if (onUploadFiles) {\n void onUploadFiles(files);\n }\n },\n });\n\n const openFilePicker = () => {\n open?.();\n };\n\n return {\n enabled: active,\n maxFiles: resolvedMaxFiles,\n getRootProps,\n getInputProps,\n open: openFilePicker,\n inputRef,\n isDragActive,\n };\n}\n\nexport default useChatFileUpload;\n"],"names":["resolveChatFileUploadMaxFiles","maxFiles","CHAT_DEFAULT_FILE_UPLOAD_MAX_FILES","useChatFileUpload","enabled","accept","onUploadFiles","disabled","resolvedMaxFiles","active","getRootProps","getInputProps","open","isDragActive","inputRef","useDropzone","files"],"mappings":";;AAWO,SAASA,EAA8BC,GAA2B;AACvE,SAAIA,KAAY,OACPC,IAGF,KAAK,IAAI,GAAGD,CAAQ;AAC7B;AAEO,SAASE,EAAkB;AAAA,EAChC,SAAAC,IAAU;AAAA,EACV,QAAAC;AAAA,EACA,UAAAJ;AAAA,EACA,eAAAK;AAAA,EACA,UAAAC,IAAW;AACb,GAA6B;AAC3B,QAAMC,IAAmBR,EAA8BC,CAAQ,GACzDQ,IAASL,KAAW,EAAQE,KAAkB,CAACC,GAE/C,EAAE,cAAAG,GAAc,eAAAC,GAAe,MAAAC,GAAM,cAAAC,GAAc,UAAAC,EAAA,IAAaC,EAAY;AAAA,IAChF,QAAAV;AAAA,IACA,UAAUG;AAAA,IACV,UAAUA,IAAmB;AAAA,IAC7B,UAAU,CAACC;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,gBAAgB,CAACO,MAAU;AACzB,MAAIV,KACGA,EAAcU,CAAK;AAAA,IAE5B;AAAA,EAAA,CACD;AAMD,SAAO;AAAA,IACL,SAASP;AAAA,IACT,UAAUD;AAAA,IACV,cAAAE;AAAA,IACA,eAAAC;AAAA,IACA,MATqB,MAAM;AAC3B,MAAAC,KAAA,QAAAA;AAAA,IACF;AAAA,IAQE,UAAAE;AAAA,IACA,cAAAD;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useChatFileUpload.js","sources":["../../../../../src/components/dataDisplay/chat/useChatFileUpload.ts"],"sourcesContent":["import React from \"react\";\nimport { type DropzoneAccept, type DropzoneInputProps, useDropzone } from \"../../../hooks/useDropzone\";\nimport { CHAT_DEFAULT_FILE_UPLOAD_MAX_FILES } from \"./types\";\n\n/** Kept as a named alias so `ChatProps.fileUploadAccept` reads the same as before. */\nexport type Accept = DropzoneAccept;\n\nexport interface UseChatFileUploadOptions {\n enabled?: boolean;\n accept?: Accept;\n maxFiles?: number;\n onUploadFiles?: (files: File[]) => void | Promise<void>;\n disabled?: boolean;\n}\n\nexport interface ChatFileUploadRootProps {\n onDragOver: (event: React.DragEvent<HTMLElement>) => void;\n onDragLeave: () => void;\n onDrop: (event: React.DragEvent<HTMLElement>) => void;\n}\n\nexport function resolveChatFileUploadMaxFiles(maxFiles?: number): number {\n if (maxFiles == null) {\n return CHAT_DEFAULT_FILE_UPLOAD_MAX_FILES;\n }\n\n return Math.max(1, maxFiles);\n}\n\nexport function useChatFileUpload({\n enabled = false,\n accept,\n maxFiles,\n onUploadFiles,\n disabled = false,\n}: UseChatFileUploadOptions) {\n const resolvedMaxFiles = resolveChatFileUploadMaxFiles(maxFiles);\n const active = enabled && Boolean(onUploadFiles) && !disabled;\n\n const {\n getRootProps: getDropzoneRootProps,\n getInputProps: getDropzoneInputProps,\n open,\n isDragActive,\n inputRef,\n } = useDropzone({\n accept,\n maxFiles: resolvedMaxFiles,\n multiple: resolvedMaxFiles > 1,\n disabled: !active,\n onDropAccepted: (files) => {\n if (onUploadFiles) {\n void onUploadFiles(files);\n }\n },\n });\n\n // Drag/drop root props WITHOUT a click handler — the `noClick` behaviour this hook used to\n // configure on react-dropzone. Clicking the chat surface must never open the file picker;\n // the attach button calls `open()` explicitly. Mirrors ui-solid's createChatFileUpload.\n const getRootProps = (): ChatFileUploadRootProps => {\n const { onClick: _onClick, ...rest } = getDropzoneRootProps();\n void _onClick;\n return rest;\n };\n\n const getInputProps = (extra?: { id?: string }): DropzoneInputProps & { id?: string } => ({\n ...getDropzoneInputProps(),\n ...(extra ?? {}),\n });\n\n const openFilePicker = () => {\n open();\n };\n\n return {\n enabled: active,\n maxFiles: resolvedMaxFiles,\n getRootProps,\n getInputProps,\n open: openFilePicker,\n inputRef,\n isDragActive,\n };\n}\n\nexport default useChatFileUpload;\n"],"names":["resolveChatFileUploadMaxFiles","maxFiles","CHAT_DEFAULT_FILE_UPLOAD_MAX_FILES","useChatFileUpload","enabled","accept","onUploadFiles","disabled","resolvedMaxFiles","active","getDropzoneRootProps","getDropzoneInputProps","open","isDragActive","inputRef","useDropzone","files","_onClick","rest","extra"],"mappings":";;AAqBO,SAASA,EAA8BC,GAA2B;AACvE,SAAIA,KAAY,OACPC,IAGF,KAAK,IAAI,GAAGD,CAAQ;AAC7B;AAEO,SAASE,EAAkB;AAAA,EAChC,SAAAC,IAAU;AAAA,EACV,QAAAC;AAAA,EACA,UAAAJ;AAAA,EACA,eAAAK;AAAA,EACA,UAAAC,IAAW;AACb,GAA6B;AAC3B,QAAMC,IAAmBR,EAA8BC,CAAQ,GACzDQ,IAASL,KAAW,EAAQE,KAAkB,CAACC,GAE/C;AAAA,IACJ,cAAcG;AAAA,IACd,eAAeC;AAAA,IACf,MAAAC;AAAA,IACA,cAAAC;AAAA,IACA,UAAAC;AAAA,EAAA,IACEC,EAAY;AAAA,IACd,QAAAV;AAAA,IACA,UAAUG;AAAA,IACV,UAAUA,IAAmB;AAAA,IAC7B,UAAU,CAACC;AAAA,IACX,gBAAgB,CAACO,MAAU;AACzB,MAAIV,KACGA,EAAcU,CAAK;AAAA,IAE5B;AAAA,EAAA,CACD;AAoBD,SAAO;AAAA,IACL,SAASP;AAAA,IACT,UAAUD;AAAA,IACV,cAlBmB,MAA+B;AAClD,YAAM,EAAE,SAASS,GAAU,GAAGC,EAAA,IAASR,EAAA;AAEvC,aAAOQ;AAAA,IACT;AAAA,IAeE,eAboB,CAACC,OAAmE;AAAA,MACxF,GAAGR,EAAA;AAAA,MACH,GAAIQ,KAAA,OAAAA,IAAS,CAAA;AAAA,IAAC;AAAA,IAYd,MATqB,MAAM;AAC3B,MAAAP,EAAA;AAAA,IACF;AAAA,IAQE,UAAAE;AAAA,IACA,cAAAD;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,48 @@
1
+ import { jsxs as a, jsx as o } from "react/jsx-runtime";
2
+ import { useId as p } from "react";
3
+ import j from "clsx";
4
+ import { Modal as r } from "../modal/modal.js";
5
+ import { Typography as b } from "../../dataDisplay/typography/typography.js";
6
+ import { Button as f } from "../../inputs/button/button.js";
7
+ function N(u) {
8
+ const { open: y, title: t, subject: n, message: i, confirmLabel: C, cancelLabel: l, danger: h, busy: e, onConfirm: g, onCancel: s, className: x } = u, c = p(), d = p(), m = [n ? c : "", i ? d : ""].filter(Boolean).join(" ");
9
+ return /* @__PURE__ */ a(
10
+ r,
11
+ {
12
+ open: y,
13
+ onClose: s,
14
+ size: "small",
15
+ role: "alertdialog",
16
+ backdrop: "dark",
17
+ closeOnEsc: !e,
18
+ closeOnOutsideClick: !e,
19
+ "aria-label": t,
20
+ ...m ? { "aria-describedby": m } : {},
21
+ children: [
22
+ /* @__PURE__ */ o(r.Header, { children: t }),
23
+ /* @__PURE__ */ o(r.Content, { children: /* @__PURE__ */ a("div", { className: j("smwb-confirm-dialog__body", x), children: [
24
+ n ? /* @__PURE__ */ o(b, { id: c, variant: "body2", color: "textPrimary", component: "span", children: n }) : null,
25
+ i ? /* @__PURE__ */ o(b, { id: d, variant: "caption", color: "textSecondary", component: "span", children: i }) : null
26
+ ] }) }),
27
+ /* @__PURE__ */ a(r.Footer, { children: [
28
+ /* @__PURE__ */ o(f, { variant: "text", size: "small", disabled: !!e, onClick: s, label: l != null ? l : "Cancel" }),
29
+ /* @__PURE__ */ o(
30
+ f,
31
+ {
32
+ variant: "contained",
33
+ size: "small",
34
+ color: h ? "error" : "primary",
35
+ disabled: !!e,
36
+ onClick: g,
37
+ label: C
38
+ }
39
+ )
40
+ ] })
41
+ ]
42
+ }
43
+ );
44
+ }
45
+ export {
46
+ N as ConfirmDialog
47
+ };
48
+ //# sourceMappingURL=confirmDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmDialog.js","sources":["../../../../../src/components/feedBack/confirmDialog/confirmDialog.tsx"],"sourcesContent":["import React, { useId } from \"react\";\nimport cn from \"clsx\";\nimport { Modal } from \"../modal\";\nimport { Button } from \"../../inputs/button\";\nimport { Typography } from \"../../dataDisplay/typography\";\n\nexport interface ConfirmDialogProps {\n open: boolean;\n title: string;\n /** The subject of the action, shown emphasised on its own line (e.g. the asset name). */\n subject?: string;\n /** A secondary explanatory line (e.g. \"can't be undone\"). */\n message?: string;\n confirmLabel: string;\n cancelLabel?: string;\n /** Style the confirm button as destructive (red). */\n danger?: boolean;\n /** Disable the actions + gate Esc/outside-click while a confirm is in flight. */\n busy?: boolean;\n onConfirm: () => void;\n onCancel: () => void;\n className?: string;\n}\n\n/**\n * An alert/confirm dialog built on {@link Modal}: a title, an optional emphasised subject + secondary\n * message, and Cancel / Confirm actions. `role=\"alertdialog\"` with the subject + message wired to\n * `aria-describedby` so a screen reader announces the consequence, not just the title. While `busy`,\n * Escape + outside-click are gated and the buttons disabled. Pure presentation — the caller owns the\n * open state and the confirm/cancel handlers (and supplies localised labels).\n */\nexport function ConfirmDialog(props: ConfirmDialogProps): React.ReactElement {\n const { open, title, subject, message, confirmLabel, cancelLabel, danger, busy, onConfirm, onCancel, className } =\n props;\n\n const subjectId = useId();\n const messageId = useId();\n // Only describe when there IS something to describe — an empty aria-describedby would point a\n // screen reader at nothing.\n const describedBy = [subject ? subjectId : \"\", message ? messageId : \"\"].filter(Boolean).join(\" \");\n\n return (\n <Modal\n open={open}\n onClose={onCancel}\n size=\"small\"\n role=\"alertdialog\"\n backdrop=\"dark\"\n closeOnEsc={!busy}\n closeOnOutsideClick={!busy}\n aria-label={title}\n {...(describedBy ? { \"aria-describedby\": describedBy } : {})}\n >\n <Modal.Header>{title}</Modal.Header>\n <Modal.Content>\n <div className={cn(\"smwb-confirm-dialog__body\", className)}>\n {subject ? (\n <Typography id={subjectId} variant=\"body2\" color=\"textPrimary\" component=\"span\">\n {subject}\n </Typography>\n ) : null}\n {message ? (\n <Typography id={messageId} variant=\"caption\" color=\"textSecondary\" component=\"span\">\n {message}\n </Typography>\n ) : null}\n </div>\n </Modal.Content>\n <Modal.Footer>\n <Button variant=\"text\" size=\"small\" disabled={!!busy} onClick={onCancel} label={cancelLabel ?? \"Cancel\"} />\n <Button\n variant=\"contained\"\n size=\"small\"\n color={danger ? \"error\" : \"primary\"}\n disabled={!!busy}\n onClick={onConfirm}\n label={confirmLabel}\n />\n </Modal.Footer>\n </Modal>\n );\n}\n\nexport default ConfirmDialog;\n"],"names":["ConfirmDialog","props","open","title","subject","message","confirmLabel","cancelLabel","danger","busy","onConfirm","onCancel","className","subjectId","useId","messageId","describedBy","jsxs","Modal","jsx","cn","Typography","Button"],"mappings":";;;;;;AA+BO,SAASA,EAAcC,GAA+C;AAC3E,QAAM,EAAE,MAAAC,GAAM,OAAAC,GAAO,SAAAC,GAAS,SAAAC,GAAS,cAAAC,GAAc,aAAAC,GAAa,QAAAC,GAAQ,MAAAC,GAAM,WAAAC,GAAW,UAAAC,GAAU,WAAAC,EAAA,IACnGX,GAEIY,IAAYC,EAAA,GACZC,IAAYD,EAAA,GAGZE,IAAc,CAACZ,IAAUS,IAAY,IAAIR,IAAUU,IAAY,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAEjG,SACE,gBAAAE;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,MAAAhB;AAAA,MACA,SAASS;AAAA,MACT,MAAK;AAAA,MACL,MAAK;AAAA,MACL,UAAS;AAAA,MACT,YAAY,CAACF;AAAA,MACb,qBAAqB,CAACA;AAAA,MACtB,cAAYN;AAAA,MACX,GAAIa,IAAc,EAAE,oBAAoBA,EAAA,IAAgB,CAAA;AAAA,MAEzD,UAAA;AAAA,QAAA,gBAAAG,EAACD,EAAM,QAAN,EAAc,UAAAf,EAAA,CAAM;AAAA,QACrB,gBAAAgB,EAACD,EAAM,SAAN,EACC,UAAA,gBAAAD,EAAC,SAAI,WAAWG,EAAG,6BAA6BR,CAAS,GACtD,UAAA;AAAA,UAAAR,IACC,gBAAAe,EAACE,GAAA,EAAW,IAAIR,GAAW,SAAQ,SAAQ,OAAM,eAAc,WAAU,QACtE,UAAAT,EAAA,CACH,IACE;AAAA,UACHC,IACC,gBAAAc,EAACE,GAAA,EAAW,IAAIN,GAAW,SAAQ,WAAU,OAAM,iBAAgB,WAAU,QAC1E,UAAAV,EAAA,CACH,IACE;AAAA,QAAA,EAAA,CACN,EAAA,CACF;AAAA,QACA,gBAAAY,EAACC,EAAM,QAAN,EACC,UAAA;AAAA,UAAA,gBAAAC,EAACG,GAAA,EAAO,SAAQ,QAAO,MAAK,SAAQ,UAAU,CAAC,CAACb,GAAM,SAASE,GAAU,OAAOJ,KAAA,OAAAA,IAAe,UAAU;AAAA,UACzG,gBAAAY;AAAA,YAACG;AAAA,YAAA;AAAA,cACC,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,OAAOd,IAAS,UAAU;AAAA,cAC1B,UAAU,CAAC,CAACC;AAAA,cACZ,SAASC;AAAA,cACT,OAAOJ;AAAA,YAAA;AAAA,UAAA;AAAA,QACT,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;"}
@@ -0,0 +1,15 @@
1
+ import { jsxs as l, jsx as e } from "react/jsx-runtime";
2
+ import m from "clsx";
3
+ import { FloatingButton as t } from "../floatingButton/floatingButton.js";
4
+ import { Icon as p } from "../../base/icon/icon.js";
5
+ function w({ handleRemoveAll: o, filesLength: r, previewClassName: s, text: i }) {
6
+ const n = m("smwb-file-drop__preview", s);
7
+ return /* @__PURE__ */ l("div", { className: n, children: [
8
+ /* @__PURE__ */ e(t, { onClick: o, className: "smwb-file-drop__preview-button", children: /* @__PURE__ */ e(p, { name: "delete", size: 28 }) }),
9
+ /* @__PURE__ */ e("div", { className: "smwb-file-drop__preview-count", children: `${i || "uploaded files:"} ${r}` })
10
+ ] });
11
+ }
12
+ export {
13
+ w as CountPreview
14
+ };
15
+ //# sourceMappingURL=countPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countPreview.js","sources":["../../../../../src/components/inputs/fileDrop/countPreview.tsx"],"sourcesContent":["import { FloatingButton } from \"../floatingButton\";\nimport { Icon } from \"../../base/icon\";\nimport React from \"react\";\nimport cn from \"clsx\";\n\nexport interface CountPreviewProps {\n previewClassName?: string;\n text?: string;\n filesLength: number;\n handleRemoveAll: () => void;\n}\n\nexport function CountPreview({ handleRemoveAll, filesLength, previewClassName, text }: CountPreviewProps) {\n const previewClasses = cn(\"smwb-file-drop__preview\", previewClassName);\n\n return (\n <div className={previewClasses}>\n <FloatingButton onClick={handleRemoveAll} className=\"smwb-file-drop__preview-button\">\n <Icon name=\"delete\" size={28} />\n </FloatingButton>\n <div className=\"smwb-file-drop__preview-count\">{`${text ? text : \"uploaded files:\"} ${filesLength}`}</div>\n </div>\n );\n}\n"],"names":["CountPreview","handleRemoveAll","filesLength","previewClassName","text","previewClasses","cn","jsxs","jsx","FloatingButton","Icon"],"mappings":";;;;AAYO,SAASA,EAAa,EAAE,iBAAAC,GAAiB,aAAAC,GAAa,kBAAAC,GAAkB,MAAAC,KAA2B;AACxG,QAAMC,IAAiBC,EAAG,2BAA2BH,CAAgB;AAErE,SACE,gBAAAI,EAAC,OAAA,EAAI,WAAWF,GACd,UAAA;AAAA,IAAA,gBAAAG,EAACC,GAAA,EAAe,SAASR,GAAiB,WAAU,kCAClD,UAAA,gBAAAO,EAACE,GAAA,EAAK,MAAK,UAAS,MAAM,GAAA,CAAI,GAChC;AAAA,IACA,gBAAAF,EAAC,OAAA,EAAI,WAAU,iCAAiC,UAAA,GAAGJ,KAAc,iBAAiB,IAAIF,CAAW,GAAA,CAAG;AAAA,EAAA,GACtG;AAEJ;"}
@@ -0,0 +1,59 @@
1
+ import { jsxs as a, jsx as r } from "react/jsx-runtime";
2
+ import g, { forwardRef as P } from "react";
3
+ import { useDropzone as R } from "../../../hooks/useDropzone.js";
4
+ import { PreviewWrapper as z } from "./previewWrapper.js";
5
+ import C from "clsx";
6
+ const O = P(function(p, n) {
7
+ const {
8
+ preview: d,
9
+ previewCols: m = 3,
10
+ galleryItemSize: c = 100,
11
+ onDrop: f,
12
+ label: s = "",
13
+ className: b,
14
+ previewClassName: w,
15
+ disabled: e,
16
+ error: o,
17
+ ...u
18
+ } = p, [l, i] = g.useState([]), v = (t) => {
19
+ i((x) => [...x, ...t]), f(t);
20
+ }, { getRootProps: h, getInputProps: D } = R({
21
+ onDrop: v,
22
+ disabled: e,
23
+ ...u
24
+ }), N = () => {
25
+ i([]);
26
+ }, _ = C("smwb-file-drop", { "smwb-disabled": e, "smwb-error": !!o }, b);
27
+ return /* @__PURE__ */ a("div", { ref: n, className: _, "data-testid": "file-drop", children: [
28
+ l.length > 0 ? /* @__PURE__ */ r(
29
+ z,
30
+ {
31
+ preview: d,
32
+ files: l,
33
+ handleRemoveAll: N,
34
+ previewCols: m,
35
+ galleryItemSize: c,
36
+ previewClassName: w
37
+ }
38
+ ) : /* @__PURE__ */ a(
39
+ "div",
40
+ {
41
+ className: "smwb-file-drop__input",
42
+ role: "button",
43
+ tabIndex: e ? -1 : 0,
44
+ "aria-disabled": e || void 0,
45
+ "aria-label": s || "Upload files",
46
+ ...h(),
47
+ children: [
48
+ /* @__PURE__ */ r("div", { className: "smwb-file-drop__input-text", children: s }),
49
+ /* @__PURE__ */ r("input", { ...D() })
50
+ ]
51
+ }
52
+ ),
53
+ o ? /* @__PURE__ */ r("span", { className: "smwb-file-drop__error", role: "alert", children: o }) : null
54
+ ] });
55
+ });
56
+ export {
57
+ O as FileDrop
58
+ };
59
+ //# sourceMappingURL=fileDrop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileDrop.js","sources":["../../../../../src/components/inputs/fileDrop/fileDrop.tsx"],"sourcesContent":["import React, { forwardRef } from \"react\";\nimport { type DropzoneOptions, useDropzone } from \"../../../hooks/useDropzone\";\nimport { PreviewWrapper } from \"./previewWrapper\";\nimport cn from \"clsx\";\n\nexport interface FileUploadProps extends DropzoneOptions {\n preview?: boolean;\n previewCols?: number;\n galleryItemSize?: number;\n onDrop: (files: File[]) => void;\n label?: string;\n className?: string;\n previewClassName?: string;\n disabled?: boolean;\n /** Validation message rendered below the drop zone. */\n error?: string;\n}\n\nexport const FileDrop = forwardRef<HTMLDivElement, FileUploadProps>(function FileDrop(props, ref) {\n const {\n preview,\n previewCols = 3,\n galleryItemSize = 100,\n onDrop: onDropProp,\n label = \"\",\n className,\n previewClassName,\n disabled,\n error,\n ...dropzoneOptions\n } = props;\n\n const [files, setFiles] = React.useState<File[]>([]);\n\n const onDrop = (acceptedFiles: File[]) => {\n setFiles((prev) => [...prev, ...acceptedFiles]);\n onDropProp(acceptedFiles);\n };\n\n const { getRootProps, getInputProps } = useDropzone({\n onDrop,\n disabled,\n ...dropzoneOptions,\n });\n\n const handleRemoveAll = () => {\n setFiles([]);\n };\n\n const wrapperClasses = cn(\"smwb-file-drop\", { \"smwb-disabled\": disabled, \"smwb-error\": !!error }, className);\n\n return (\n <div ref={ref} className={wrapperClasses} data-testid=\"file-drop\">\n {files.length > 0 ? (\n <PreviewWrapper\n preview={preview}\n files={files}\n handleRemoveAll={handleRemoveAll}\n previewCols={previewCols}\n galleryItemSize={galleryItemSize}\n previewClassName={previewClassName}\n />\n ) : (\n <div\n className=\"smwb-file-drop__input\"\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled || undefined}\n aria-label={label || \"Upload files\"}\n {...getRootProps()}\n >\n <div className=\"smwb-file-drop__input-text\">{label}</div>\n <input {...getInputProps()} />\n </div>\n )}\n {error ? (\n <span className=\"smwb-file-drop__error\" role=\"alert\">\n {error}\n </span>\n ) : null}\n </div>\n );\n});\n\nexport default FileDrop;\n"],"names":["FileDrop","forwardRef","props","ref","preview","previewCols","galleryItemSize","onDropProp","label","className","previewClassName","disabled","error","dropzoneOptions","files","setFiles","React","onDrop","acceptedFiles","prev","getRootProps","getInputProps","useDropzone","handleRemoveAll","wrapperClasses","cn","jsx","PreviewWrapper","jsxs"],"mappings":";;;;;AAkBO,MAAMA,IAAWC,EAA4C,SAAkBC,GAAOC,GAAK;AAChG,QAAM;AAAA,IACJ,SAAAC;AAAA,IACA,aAAAC,IAAc;AAAA,IACd,iBAAAC,IAAkB;AAAA,IAClB,QAAQC;AAAA,IACR,OAAAC,IAAQ;AAAA,IACR,WAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,IACDX,GAEE,CAACY,GAAOC,CAAQ,IAAIC,EAAM,SAAiB,CAAA,CAAE,GAE7CC,IAAS,CAACC,MAA0B;AACxC,IAAAH,EAAS,CAACI,MAAS,CAAC,GAAGA,GAAM,GAAGD,CAAa,CAAC,GAC9CX,EAAWW,CAAa;AAAA,EAC1B,GAEM,EAAE,cAAAE,GAAc,eAAAC,EAAA,IAAkBC,EAAY;AAAA,IAClD,QAAAL;AAAA,IACA,UAAAN;AAAA,IACA,GAAGE;AAAA,EAAA,CACJ,GAEKU,IAAkB,MAAM;AAC5B,IAAAR,EAAS,CAAA,CAAE;AAAA,EACb,GAEMS,IAAiBC,EAAG,kBAAkB,EAAE,iBAAiBd,GAAU,cAAc,CAAC,CAACC,EAAA,GAASH,CAAS;AAE3G,2BACG,OAAA,EAAI,KAAAN,GAAU,WAAWqB,GAAgB,eAAY,aACnD,UAAA;AAAA,IAAAV,EAAM,SAAS,IACd,gBAAAY;AAAA,MAACC;AAAA,MAAA;AAAA,QACC,SAAAvB;AAAA,QACA,OAAAU;AAAA,QACA,iBAAAS;AAAA,QACA,aAAAlB;AAAA,QACA,iBAAAC;AAAA,QACA,kBAAAI;AAAA,MAAA;AAAA,IAAA,IAGF,gBAAAkB;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACV,MAAK;AAAA,QACL,UAAUjB,IAAW,KAAK;AAAA,QAC1B,iBAAeA,KAAY;AAAA,QAC3B,cAAYH,KAAS;AAAA,QACpB,GAAGY,EAAA;AAAA,QAEJ,UAAA;AAAA,UAAA,gBAAAM,EAAC,OAAA,EAAI,WAAU,8BAA8B,UAAAlB,GAAM;AAAA,UACnD,gBAAAkB,EAAC,SAAA,EAAO,GAAGL,IAAc,CAAG;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,IAG/BT,sBACE,QAAA,EAAK,WAAU,yBAAwB,MAAK,SAC1C,aACH,IACE;AAAA,EAAA,GACN;AAEJ,CAAC;"}
@@ -0,0 +1,41 @@
1
+ import { jsxs as p, jsx as r } from "react/jsx-runtime";
2
+ import { isImageFile as c } from "./utils.js";
3
+ import w from "clsx";
4
+ import { FloatingButton as d } from "../floatingButton/floatingButton.js";
5
+ import { Icon as v } from "../../base/icon/icon.js";
6
+ import { ImagesList as f } from "../../dataDisplay/imagesList/imagesList.js";
7
+ import g from "../../dataDisplay/imagesList/imagesListItem/imagesListItem.js";
8
+ function C(i) {
9
+ const { files: o, handleRemoveAll: l, previewCols: t, galleryItemSize: s, previewClassName: a } = i, n = w("smwb-file-drop__preview", a);
10
+ return /* @__PURE__ */ p("div", { className: n, children: [
11
+ /* @__PURE__ */ r(d, { onClick: l, className: "smwb-file-drop__preview-button", children: /* @__PURE__ */ r(v, { name: "delete", size: 28 }) }),
12
+ /* @__PURE__ */ r(f, { className: "smwb-file-drop__preview-gallery", cols: t, rowsHeight: s, children: o.map((e) => {
13
+ const m = c(e) ? URL.createObjectURL(e) : null;
14
+ return m ? /* @__PURE__ */ r(
15
+ g,
16
+ {
17
+ className: "smwb-file-drop__preview-gallery-image",
18
+ src: m,
19
+ rows: 1,
20
+ cols: 1,
21
+ itemBarContent: e.name
22
+ },
23
+ e.name
24
+ ) : /* @__PURE__ */ r(
25
+ "div",
26
+ {
27
+ className: "smwb-file-drop__preview-gallery-file",
28
+ style: {
29
+ width: `${s - 4}px`
30
+ },
31
+ children: e.name
32
+ },
33
+ e.name
34
+ );
35
+ }) })
36
+ ] });
37
+ }
38
+ export {
39
+ C as Preview
40
+ };
41
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.js","sources":["../../../../../src/components/inputs/fileDrop/preview.tsx"],"sourcesContent":["import { FloatingButton } from \"../floatingButton\";\nimport { Icon } from \"../../base/icon\";\nimport { ImagesList, ImagesListItem } from \"../../dataDisplay/imagesList\";\nimport { isImageFile } from \"./utils\";\nimport React from \"react\";\nimport cn from \"clsx\";\n\nexport interface PreviewProps {\n previewCols?: number;\n galleryItemSize?: number;\n previewClassName?: string;\n files: File[];\n handleRemoveAll: () => void;\n}\n\nexport function Preview(props: PreviewProps) {\n const { files, handleRemoveAll, previewCols, galleryItemSize, previewClassName } = props;\n\n const previewClasses = cn(\"smwb-file-drop__preview\", previewClassName);\n\n return (\n <div className={previewClasses}>\n <FloatingButton onClick={handleRemoveAll} className=\"smwb-file-drop__preview-button\">\n <Icon name=\"delete\" size={28} />\n </FloatingButton>\n <ImagesList className=\"smwb-file-drop__preview-gallery\" cols={previewCols as number} rowsHeight={galleryItemSize}>\n {files.map((file: File) => {\n const src = isImageFile(file) ? URL.createObjectURL(file) : null;\n\n return src ? (\n <ImagesListItem\n className=\"smwb-file-drop__preview-gallery-image\"\n key={file.name}\n src={src}\n rows={1}\n cols={1}\n itemBarContent={file.name}\n />\n ) : (\n <div\n key={file.name}\n className=\"smwb-file-drop__preview-gallery-file\"\n style={{\n width: `${(galleryItemSize as number) - 4}px`,\n }}\n >\n {file.name}\n </div>\n );\n })}\n </ImagesList>\n </div>\n );\n}\n"],"names":["Preview","props","files","handleRemoveAll","previewCols","galleryItemSize","previewClassName","previewClasses","cn","jsxs","jsx","FloatingButton","Icon","ImagesList","file","src","isImageFile","ImagesListItem"],"mappings":";;;;;;;AAeO,SAASA,EAAQC,GAAqB;AAC3C,QAAM,EAAE,OAAAC,GAAO,iBAAAC,GAAiB,aAAAC,GAAa,iBAAAC,GAAiB,kBAAAC,MAAqBL,GAE7EM,IAAiBC,EAAG,2BAA2BF,CAAgB;AAErE,SACE,gBAAAG,EAAC,OAAA,EAAI,WAAWF,GACd,UAAA;AAAA,IAAA,gBAAAG,EAACC,GAAA,EAAe,SAASR,GAAiB,WAAU,kCAClD,UAAA,gBAAAO,EAACE,GAAA,EAAK,MAAK,UAAS,MAAM,GAAA,CAAI,GAChC;AAAA,IACA,gBAAAF,EAACG,GAAA,EAAW,WAAU,mCAAkC,MAAMT,GAAuB,YAAYC,GAC9F,UAAAH,EAAM,IAAI,CAACY,MAAe;AACzB,YAAMC,IAAMC,EAAYF,CAAI,IAAI,IAAI,gBAAgBA,CAAI,IAAI;AAE5D,aAAOC,IACL,gBAAAL;AAAA,QAACO;AAAA,QAAA;AAAA,UACC,WAAU;AAAA,UAEV,KAAAF;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN,gBAAgBD,EAAK;AAAA,QAAA;AAAA,QAJhBA,EAAK;AAAA,MAAA,IAOZ,gBAAAJ;AAAA,QAAC;AAAA,QAAA;AAAA,UAEC,WAAU;AAAA,UACV,OAAO;AAAA,YACL,OAAO,GAAIL,IAA6B,CAAC;AAAA,UAAA;AAAA,UAG1C,UAAAS,EAAK;AAAA,QAAA;AAAA,QANDA,EAAK;AAAA,MAAA;AAAA,IAShB,CAAC,EAAA,CACH;AAAA,EAAA,GACF;AAEJ;"}
@@ -0,0 +1,27 @@
1
+ import { jsx as e, Fragment as p } from "react/jsx-runtime";
2
+ import { Preview as s } from "./preview.js";
3
+ import { CountPreview as v } from "./countPreview.js";
4
+ function g(t) {
5
+ const { previewCols: l, preview: m, galleryItemSize: n, handleRemoveAll: r, files: i, previewClassName: o } = t;
6
+ return /* @__PURE__ */ e(p, { children: m ? /* @__PURE__ */ e(
7
+ s,
8
+ {
9
+ files: i,
10
+ handleRemoveAll: r,
11
+ previewCols: l,
12
+ galleryItemSize: n,
13
+ previewClassName: o
14
+ }
15
+ ) : /* @__PURE__ */ e(
16
+ v,
17
+ {
18
+ filesLength: i.length,
19
+ handleRemoveAll: r,
20
+ previewClassName: o
21
+ }
22
+ ) });
23
+ }
24
+ export {
25
+ g as PreviewWrapper
26
+ };
27
+ //# sourceMappingURL=previewWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"previewWrapper.js","sources":["../../../../../src/components/inputs/fileDrop/previewWrapper.tsx"],"sourcesContent":["import { Preview } from \"./preview\";\nimport { CountPreview } from \"./countPreview\";\nimport React from \"react\";\n\nexport interface PreviewWrapperProps {\n preview?: boolean;\n files: File[];\n handleRemoveAll: () => void;\n previewCols?: number;\n galleryItemSize?: number;\n previewClassName?: string;\n}\n\nexport function PreviewWrapper(props: PreviewWrapperProps) {\n const { previewCols, preview, galleryItemSize, handleRemoveAll, files, previewClassName } = props;\n\n return (\n <>\n {preview ? (\n <Preview\n files={files}\n handleRemoveAll={handleRemoveAll}\n previewCols={previewCols}\n galleryItemSize={galleryItemSize}\n previewClassName={previewClassName}\n />\n ) : (\n <CountPreview\n filesLength={files.length}\n handleRemoveAll={handleRemoveAll}\n previewClassName={previewClassName}\n />\n )}\n </>\n );\n}\n"],"names":["PreviewWrapper","props","previewCols","preview","galleryItemSize","handleRemoveAll","files","previewClassName","jsx","Preview","CountPreview"],"mappings":";;;AAaO,SAASA,EAAeC,GAA4B;AACzD,QAAM,EAAE,aAAAC,GAAa,SAAAC,GAAS,iBAAAC,GAAiB,iBAAAC,GAAiB,OAAAC,GAAO,kBAAAC,MAAqBN;AAE5F,gCAEK,UAAAE,IACC,gBAAAK;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,OAAAH;AAAA,MACA,iBAAAD;AAAA,MACA,aAAAH;AAAA,MACA,iBAAAE;AAAA,MACA,kBAAAG;AAAA,IAAA;AAAA,EAAA,IAGF,gBAAAC;AAAA,IAACE;AAAA,IAAA;AAAA,MACC,aAAaJ,EAAM;AAAA,MACnB,iBAAAD;AAAA,MACA,kBAAAE;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ;"}
@@ -0,0 +1,7 @@
1
+ function t(e) {
2
+ return /^image\/(png|jpeg)$/.test(e.type);
3
+ }
4
+ export {
5
+ t as isImageFile
6
+ };
7
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../../src/components/inputs/fileDrop/utils.ts"],"sourcesContent":["export function isImageFile(file: File): boolean {\n return /^image\\/(png|jpeg)$/.test(file.type);\n}\n"],"names":["isImageFile","file"],"mappings":"AAAO,SAASA,EAAYC,GAAqB;AAC/C,SAAO,sBAAsB,KAAKA,EAAK,IAAI;AAC7C;"}
@@ -0,0 +1,34 @@
1
+ import { jsxs as w, jsx as n } from "react/jsx-runtime";
2
+ import { forwardRef as x } from "react";
3
+ import { useDropzone as D } from "../../../hooks/useDropzone.js";
4
+ import a from "clsx";
5
+ const P = x(function(p, m) {
6
+ const { label: c, onClick: e, onFilesSelected: o, className: u, buttonClassName: d, disabled: s, error: l, ...t } = p, { getRootProps: f, getInputProps: b } = D({
7
+ ...t,
8
+ disabled: s,
9
+ onDropAccepted: (r, h) => {
10
+ var i;
11
+ o == null || o(r), (i = t.onDropAccepted) == null || i.call(t, r, h);
12
+ }
13
+ }), N = (r) => {
14
+ e == null || e(r);
15
+ };
16
+ return /* @__PURE__ */ w(
17
+ "div",
18
+ {
19
+ ref: m,
20
+ className: a("smwb-file-input", { "smwb-disabled": s }, u),
21
+ "data-testid": "file-input",
22
+ ...f(),
23
+ children: [
24
+ /* @__PURE__ */ n("button", { type: "button", className: a(d), disabled: s, onClick: N, children: c }),
25
+ /* @__PURE__ */ n("input", { ...b() }),
26
+ l ? /* @__PURE__ */ n("span", { className: "smwb-file-input__error", role: "alert", children: l }) : null
27
+ ]
28
+ }
29
+ );
30
+ });
31
+ export {
32
+ P as FileInput
33
+ };
34
+ //# sourceMappingURL=fileInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileInput.js","sources":["../../../../../src/components/inputs/fileInput/fileInput.tsx"],"sourcesContent":["import React, { forwardRef } from \"react\";\nimport { type DropzoneOptions, useDropzone } from \"../../../hooks/useDropzone\";\nimport cn from \"clsx\";\n\nexport interface FileInputProps extends DropzoneOptions {\n label?: string;\n className?: string;\n buttonClassName?: string;\n disabled?: boolean;\n /** Validation message shown below the control. */\n error?: string;\n /** Fired with the accepted files when the user picks them. */\n onFilesSelected?: (files: File[]) => void;\n /** @deprecated optional click passthrough on the trigger button. */\n onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;\n}\n\nexport const FileInput = forwardRef<HTMLDivElement, FileInputProps>(function FileInput(props, ref) {\n const { label, onClick, onFilesSelected, className, buttonClassName, disabled, error, ...dropzoneOptions } = props;\n\n const { getRootProps, getInputProps } = useDropzone({\n ...dropzoneOptions,\n disabled,\n onDropAccepted: (accepted, event) => {\n onFilesSelected?.(accepted);\n dropzoneOptions.onDropAccepted?.(accepted, event);\n },\n });\n\n const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n };\n\n return (\n <div\n ref={ref}\n className={cn(\"smwb-file-input\", { \"smwb-disabled\": disabled }, className)}\n data-testid=\"file-input\"\n {...getRootProps()}\n >\n <button type=\"button\" className={cn(buttonClassName)} disabled={disabled} onClick={handleClick}>\n {label}\n </button>\n <input {...getInputProps()} />\n {error ? (\n <span className=\"smwb-file-input__error\" role=\"alert\">\n {error}\n </span>\n ) : null}\n </div>\n );\n});\n\nexport default FileInput;\n"],"names":["FileInput","forwardRef","props","ref","label","onClick","onFilesSelected","className","buttonClassName","disabled","error","dropzoneOptions","getRootProps","getInputProps","useDropzone","accepted","event","_a","handleClick","e","jsxs","cn","jsx"],"mappings":";;;;AAiBO,MAAMA,IAAYC,EAA2C,SAAmBC,GAAOC,GAAK;AACjG,QAAM,EAAE,OAAAC,GAAO,SAAAC,GAAS,iBAAAC,GAAiB,WAAAC,GAAW,iBAAAC,GAAiB,UAAAC,GAAU,OAAAC,GAAO,GAAGC,EAAA,IAAoBT,GAEvG,EAAE,cAAAU,GAAc,eAAAC,EAAA,IAAkBC,EAAY;AAAA,IAClD,GAAGH;AAAA,IACH,UAAAF;AAAA,IACA,gBAAgB,CAACM,GAAUC,MAAU;;AACnC,MAAAV,KAAA,QAAAA,EAAkBS,KAClBE,IAAAN,EAAgB,mBAAhB,QAAAM,EAAA,KAAAN,GAAiCI,GAAUC;AAAA,IAC7C;AAAA,EAAA,CACD,GAEKE,IAAc,CAACC,MAA2C;AAC9D,IAAAd,KAAA,QAAAA,EAAUc;AAAA,EACZ;AAEA,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAAjB;AAAA,MACA,WAAWkB,EAAG,mBAAmB,EAAE,iBAAiBZ,EAAA,GAAYF,CAAS;AAAA,MACzE,eAAY;AAAA,MACX,GAAGK,EAAA;AAAA,MAEJ,UAAA;AAAA,QAAA,gBAAAU,EAAC,UAAA,EAAO,MAAK,UAAS,WAAWD,EAAGb,CAAe,GAAG,UAAAC,GAAoB,SAASS,GAChF,UAAAd,EAAA,CACH;AAAA,QACA,gBAAAkB,EAAC,SAAA,EAAO,GAAGT,EAAA,EAAc,CAAG;AAAA,QAC3BH,sBACE,QAAA,EAAK,WAAU,0BAAyB,MAAK,SAC3C,aACH,IACE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGV,CAAC;"}
@@ -0,0 +1,310 @@
1
+ import { jsx as s, Fragment as Tt, jsxs as N } from "react/jsx-runtime";
2
+ import { forwardRef as vt, useState as Kt, useRef as _, useId as Ot, useCallback as T, useEffect as Q } from "react";
3
+ import { createPortal as Ft } from "react-dom";
4
+ import { CSSTransition as Ht } from "react-transition-group";
5
+ import W from "clsx";
6
+ import { Icon as v } from "../../base/icon/icon.js";
7
+ import { useControllableState as K } from "../../../hooks/useControllableState.js";
8
+ import { useForkRef as Ut } from "../../../hooks/useForkRef.js";
9
+ import { useSafeLayoutEffect as $t } from "../../../hooks/useSafeLayoutEffect.js";
10
+ const Vt = {
11
+ n: { dx: 0, dy: 1, dw: 0, dh: -1 },
12
+ s: { dx: 0, dy: 0, dw: 0, dh: 1 },
13
+ e: { dx: 0, dy: 0, dw: 1, dh: 0 },
14
+ w: { dx: 1, dy: 0, dw: -1, dh: 0 },
15
+ ne: { dx: 0, dy: 1, dw: 1, dh: -1 },
16
+ nw: { dx: 1, dy: 1, dw: -1, dh: -1 },
17
+ se: { dx: 0, dy: 0, dw: 1, dh: 1 },
18
+ sw: { dx: 1, dy: 0, dw: -1, dh: 1 }
19
+ }, Xt = ["n", "s", "e", "w", "ne", "nw", "se", "sw"], y = () => typeof window == "undefined" ? { width: 0, height: 0 } : { width: window.innerWidth, height: window.innerHeight }, Yt = { x: 24, y: 24 }, Zt = { width: 360, height: 420 }, oe = vt(
20
+ function(tt, et) {
21
+ const {
22
+ open: x,
23
+ title: A,
24
+ headerActions: nt,
25
+ position: ot,
26
+ defaultPosition: it = Yt,
27
+ onPositionChange: rt,
28
+ onMoveEnd: h,
29
+ size: at,
30
+ defaultSize: st = Zt,
31
+ onResize: dt,
32
+ onResizeEnd: u,
33
+ minWidth: b = 200,
34
+ minHeight: D = 120,
35
+ maxWidth: a,
36
+ maxHeight: d,
37
+ keepVisible: O = 56,
38
+ moveStep: lt = 24,
39
+ resizeStep: I = 24,
40
+ zIndex: F,
41
+ onActivate: R,
42
+ collapsed: ct,
43
+ defaultCollapsed: wt = !1,
44
+ onCollapsedChange: ht,
45
+ collapsible: ut = !0,
46
+ movable: ft = !0,
47
+ resizable: pt = !0,
48
+ closeOnEsc: H = !1,
49
+ onClose: P,
50
+ moveHandleAriaLabel: mt = "Move window",
51
+ resizeHandleAriaLabel: gt = "Resize window",
52
+ closeAriaLabel: yt = "Close window",
53
+ collapseAriaLabel: xt = "Collapse window",
54
+ expandAriaLabel: bt = "Expand window",
55
+ className: Pt,
56
+ style: E,
57
+ children: _t,
58
+ ...Dt
59
+ } = tt, [U, Rt] = Kt(), C = _(null), Ct = Ut(et, C), $ = Ot();
60
+ $t(() => {
61
+ Rt(document.body);
62
+ }, []);
63
+ const [f, V] = K({
64
+ value: ot,
65
+ defaultValue: it,
66
+ onChange: rt
67
+ }), [p, X] = K({
68
+ value: at,
69
+ defaultValue: st,
70
+ onChange: dt
71
+ }), [c, Mt] = K({
72
+ value: ct,
73
+ defaultValue: wt,
74
+ onChange: ht
75
+ }), M = T(
76
+ (t, e) => {
77
+ const n = a != null ? a : e.width, i = d != null ? d : e.height, o = Math.max(b, Math.min(n, t.width)), r = Math.max(D, Math.min(i, t.height)), g = Math.min(O, o), S = Math.max(g - o, Math.min(e.width - g, t.x)), L = Math.max(0, Math.min(Math.max(0, e.height - g), t.y));
78
+ return { x: S, y: L, width: o, height: r };
79
+ },
80
+ [O, d, a, D, b]
81
+ ), w = M({ x: f.x, y: f.y, width: p.width, height: p.height }, y()), l = _(w);
82
+ l.current = w;
83
+ const m = T(
84
+ (t) => {
85
+ const e = M(t, y());
86
+ (e.x !== f.x || e.y !== f.y) && V({ x: e.x, y: e.y }), (e.width !== p.width || e.height !== p.height) && X({ width: e.width, height: e.height });
87
+ },
88
+ [M, f.x, f.y, V, X, p.height, p.width]
89
+ ), Y = _(m);
90
+ Y.current = m, Q(() => {
91
+ if (!x) return;
92
+ const t = () => Y.current(l.current);
93
+ return window.addEventListener("resize", t), () => window.removeEventListener("resize", t);
94
+ }, [x]), Q(() => {
95
+ if (!x || !H || !P) return;
96
+ const t = (e) => {
97
+ if (e.key !== "Escape") return;
98
+ const n = C.current;
99
+ !n || !n.contains(document.activeElement) || P();
100
+ };
101
+ return document.addEventListener("keydown", t), () => document.removeEventListener("keydown", t);
102
+ }, [H, P, x]);
103
+ const Z = T(() => {
104
+ R == null || R();
105
+ const t = C.current;
106
+ t && !t.contains(document.activeElement) && t.focus({ preventScroll: !0 });
107
+ }, [R]), k = _(null), kt = (t) => {
108
+ var n, i, o;
109
+ if (!ft || (n = t.target) != null && n.closest("button,[data-no-drag]")) return;
110
+ t.preventDefault();
111
+ const e = l.current;
112
+ k.current = { px: t.clientX, py: t.clientY, x: e.x, y: e.y };
113
+ try {
114
+ (o = (i = t.currentTarget).setPointerCapture) == null || o.call(i, t.pointerId);
115
+ } catch {
116
+ }
117
+ }, zt = (t) => {
118
+ const e = k.current;
119
+ e && m({
120
+ ...l.current,
121
+ x: e.x + t.clientX - e.px,
122
+ y: e.y + t.clientY - e.py
123
+ });
124
+ }, j = (t) => {
125
+ var e, n, i, o;
126
+ if (k.current) {
127
+ k.current = null;
128
+ const r = l.current;
129
+ h == null || h({ x: r.x, y: r.y });
130
+ }
131
+ (n = (e = t.currentTarget).hasPointerCapture) != null && n.call(e, t.pointerId) && ((o = (i = t.currentTarget).releasePointerCapture) == null || o.call(i, t.pointerId));
132
+ }, z = _(null), At = (t, e) => {
133
+ var n, i;
134
+ e.preventDefault(), e.stopPropagation(), z.current = { dir: t, px: e.clientX, py: e.clientY, rect: l.current }, Z();
135
+ try {
136
+ (i = (n = e.currentTarget).setPointerCapture) == null || i.call(n, e.pointerId);
137
+ } catch {
138
+ }
139
+ }, It = (t) => {
140
+ const e = z.current;
141
+ if (!e) return;
142
+ const n = Vt[e.dir], i = t.clientX - e.px, o = t.clientY - e.py, r = e.rect, g = y(), S = a != null ? a : g.width, L = d != null ? d : g.height, B = Math.min(S, Math.max(b, r.width + n.dw * i)), J = Math.min(L, Math.max(D, r.height + n.dh * o));
143
+ m({
144
+ x: n.dx ? r.x + r.width - B : r.x,
145
+ y: n.dy ? r.y + r.height - J : r.y,
146
+ width: B,
147
+ height: J
148
+ });
149
+ }, G = (t) => {
150
+ var e, n, i, o;
151
+ if (z.current) {
152
+ z.current = null;
153
+ const r = l.current;
154
+ u == null || u({ width: r.width, height: r.height });
155
+ }
156
+ (n = (e = t.currentTarget).hasPointerCapture) != null && n.call(e, t.pointerId) && ((o = (i = t.currentTarget).releasePointerCapture) == null || o.call(i, t.pointerId));
157
+ }, q = (t, e) => {
158
+ const n = M(e, y());
159
+ t ? u == null || u({ width: n.width, height: n.height }) : h == null || h({ x: n.x, y: n.y });
160
+ }, Et = (t) => {
161
+ const e = l.current, n = t.shiftKey ? I : lt, o = {
162
+ ArrowLeft: [-n, 0],
163
+ ArrowRight: [n, 0],
164
+ ArrowUp: [0, -n],
165
+ ArrowDown: [0, n]
166
+ }[t.key];
167
+ if (!o) return;
168
+ t.preventDefault();
169
+ const r = t.shiftKey ? { ...e, width: e.width + o[0], height: e.height + o[1] } : { ...e, x: e.x + o[0], y: e.y + o[1] };
170
+ m(r), q(t.shiftKey, r);
171
+ }, St = (t) => {
172
+ const e = l.current, n = y();
173
+ let i;
174
+ if (t.key === "ArrowLeft" || t.key === "ArrowRight") {
175
+ t.preventDefault();
176
+ const o = t.key === "ArrowRight" ? 1 : -1;
177
+ i = { ...e, width: e.width + o * I };
178
+ } else if (t.key === "ArrowUp" || t.key === "ArrowDown") {
179
+ t.preventDefault();
180
+ const o = t.key === "ArrowDown" ? 1 : -1;
181
+ i = { ...e, height: e.height + o * I };
182
+ } else if (t.key === "Home")
183
+ t.preventDefault(), i = { ...e, width: b, height: D };
184
+ else if (t.key === "End")
185
+ t.preventDefault(), i = { ...e, width: a != null ? a : n.width, height: d != null ? d : n.height };
186
+ else
187
+ return;
188
+ m(i), q(!0, i);
189
+ }, Lt = () => Mt((t) => !t);
190
+ if (!U)
191
+ return /* @__PURE__ */ s(Tt, {});
192
+ const Nt = {
193
+ left: `${w.x}px`,
194
+ top: `${w.y}px`,
195
+ width: `${w.width}px`,
196
+ ...c ? {} : { height: `${w.height}px` },
197
+ ...F === void 0 ? {} : { zIndex: F },
198
+ ...E != null ? E : {}
199
+ };
200
+ return Ft(
201
+ /* @__PURE__ */ s(
202
+ Ht,
203
+ {
204
+ in: x,
205
+ timeout: 120,
206
+ mountOnEnter: !0,
207
+ unmountOnExit: !0,
208
+ appear: !0,
209
+ classNames: { enterDone: "smwb-floating-window_entered" },
210
+ nodeRef: C,
211
+ children: /* @__PURE__ */ N(
212
+ "div",
213
+ {
214
+ ...Dt,
215
+ ref: Ct,
216
+ "data-testid": "floating-window",
217
+ role: "dialog",
218
+ tabIndex: -1,
219
+ "aria-labelledby": A ? $ : void 0,
220
+ className: W("smwb-floating-window", Pt, { "smwb-collapsed": c }),
221
+ style: Nt,
222
+ onPointerDown: Z,
223
+ children: [
224
+ /* @__PURE__ */ N(
225
+ "div",
226
+ {
227
+ className: "smwb-floating-window__header",
228
+ "data-testid": "floating-window-header",
229
+ onPointerDown: kt,
230
+ onPointerMove: zt,
231
+ onPointerUp: j,
232
+ onPointerCancel: j,
233
+ children: [
234
+ /* @__PURE__ */ s(
235
+ "span",
236
+ {
237
+ className: "smwb-floating-window__grip",
238
+ "data-testid": "floating-window-move",
239
+ role: "button",
240
+ tabIndex: 0,
241
+ "aria-label": mt,
242
+ onKeyDown: Et,
243
+ children: /* @__PURE__ */ s(v, { name: "drag_indicator" })
244
+ }
245
+ ),
246
+ A ? /* @__PURE__ */ s("span", { className: "smwb-floating-window__title", id: $, children: A }) : null,
247
+ /* @__PURE__ */ N("div", { className: "smwb-floating-window__actions", "data-no-drag": !0, children: [
248
+ nt,
249
+ ut ? /* @__PURE__ */ s(
250
+ "button",
251
+ {
252
+ type: "button",
253
+ className: "smwb-floating-window__action",
254
+ "data-testid": "floating-window-collapse",
255
+ "aria-label": c ? bt : xt,
256
+ "aria-expanded": !c,
257
+ onClick: Lt,
258
+ children: /* @__PURE__ */ s(v, { name: c ? "open_in_full" : "close_fullscreen" })
259
+ }
260
+ ) : null,
261
+ P ? /* @__PURE__ */ s(
262
+ "button",
263
+ {
264
+ type: "button",
265
+ className: "smwb-floating-window__action",
266
+ "data-testid": "floating-window-close",
267
+ "aria-label": yt,
268
+ onClick: P,
269
+ children: /* @__PURE__ */ s(v, { name: "close" })
270
+ }
271
+ ) : null
272
+ ] })
273
+ ]
274
+ }
275
+ ),
276
+ c ? null : /* @__PURE__ */ s("div", { className: "smwb-floating-window__body", "data-testid": "floating-window-body", children: _t }),
277
+ pt && !c ? Xt.map((t) => /* @__PURE__ */ s(
278
+ "div",
279
+ {
280
+ className: W("smwb-floating-window__resize", `smwb-floating-window__resize_${t}`),
281
+ "data-testid": `floating-window-resize-${t}`,
282
+ ...t === "se" ? {
283
+ role: "separator",
284
+ tabIndex: 0,
285
+ "aria-label": gt,
286
+ "aria-valuemin": b,
287
+ "aria-valuemax": Math.round(a != null ? a : y().width),
288
+ "aria-valuenow": Math.round(w.width),
289
+ onKeyDown: St
290
+ } : { "aria-hidden": !0, tabIndex: -1 },
291
+ onPointerDown: (e) => At(t, e),
292
+ onPointerMove: It,
293
+ onPointerUp: G,
294
+ onPointerCancel: G
295
+ },
296
+ t
297
+ )) : null
298
+ ]
299
+ }
300
+ )
301
+ }
302
+ ),
303
+ U
304
+ );
305
+ }
306
+ );
307
+ export {
308
+ oe as FloatingWindow
309
+ };
310
+ //# sourceMappingURL=floatingWindow.js.map