@frontify/guideline-blocks-settings 0.29.16 → 0.30.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 (49) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/components/Attachments/AttachmentItem.es.js +73 -79
  3. package/dist/components/Attachments/AttachmentItem.es.js.map +1 -1
  4. package/dist/components/Attachments/Attachments.es.js +103 -96
  5. package/dist/components/Attachments/Attachments.es.js.map +1 -1
  6. package/dist/components/Attachments/AttachmentsButtonTrigger.es.js +21 -0
  7. package/dist/components/Attachments/AttachmentsButtonTrigger.es.js.map +1 -0
  8. package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js +47 -43
  9. package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js.map +1 -1
  10. package/dist/components/BlockItemWrapper/Toolbar/Toolbar.es.js +123 -0
  11. package/dist/components/BlockItemWrapper/Toolbar/Toolbar.es.js.map +1 -0
  12. package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachments.es.js +27 -0
  13. package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachments.es.js.map +1 -0
  14. package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.es.js +12 -0
  15. package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.es.js.map +1 -0
  16. package/dist/components/BlockItemWrapper/Toolbar/ToolbarSegment.es.js +6 -0
  17. package/dist/components/BlockItemWrapper/Toolbar/ToolbarSegment.es.js.map +1 -0
  18. package/dist/components/BlockItemWrapper/Toolbar/helpers.es.js +26 -0
  19. package/dist/components/BlockItemWrapper/Toolbar/helpers.es.js.map +1 -0
  20. package/dist/hooks/useAttachments.es.js +43 -20
  21. package/dist/hooks/useAttachments.es.js.map +1 -1
  22. package/dist/index.cjs.js +3 -3
  23. package/dist/index.cjs.js.map +1 -1
  24. package/dist/index.d.ts +84 -15
  25. package/dist/index.es.js +103 -100
  26. package/dist/index.umd.js +3 -3
  27. package/dist/index.umd.js.map +1 -1
  28. package/dist/styles.css +1 -1
  29. package/package.json +3 -3
  30. package/src/components/Attachments/AttachmentItem.tsx +2 -13
  31. package/src/components/Attachments/Attachments.tsx +30 -15
  32. package/src/components/Attachments/AttachmentsButtonTrigger.tsx +22 -0
  33. package/src/components/Attachments/types.ts +10 -2
  34. package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +23 -20
  35. package/src/components/BlockItemWrapper/Toolbar/Toolbar.spec.tsx +127 -0
  36. package/src/components/BlockItemWrapper/Toolbar/Toolbar.tsx +133 -0
  37. package/src/components/BlockItemWrapper/Toolbar/ToolbarAttachments.tsx +29 -0
  38. package/src/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.tsx +14 -0
  39. package/src/components/BlockItemWrapper/Toolbar/ToolbarSegment.tsx +9 -0
  40. package/src/components/BlockItemWrapper/Toolbar/helpers.ts +33 -0
  41. package/src/components/BlockItemWrapper/Toolbar/index.ts +4 -0
  42. package/src/components/BlockItemWrapper/Toolbar/types.ts +38 -0
  43. package/src/components/BlockItemWrapper/types.ts +11 -34
  44. package/src/hooks/{useAttachments.spec.ts → useAttachments.spec.tsx} +55 -4
  45. package/src/hooks/useAttachments.tsx +95 -0
  46. package/dist/components/BlockItemWrapper/Toolbar.es.js +0 -117
  47. package/dist/components/BlockItemWrapper/Toolbar.es.js.map +0 -1
  48. package/src/components/BlockItemWrapper/Toolbar.tsx +0 -133
  49. package/src/hooks/useAttachments.ts +0 -46
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @frontify/guideline-blocks-settings
2
2
 
3
+ ## 0.30.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#672](https://github.com/Frontify/brand-sdk/pull/672) [`22eb8eb`](https://github.com/Frontify/brand-sdk/commit/22eb8eb8dce8f2d4dccf040376b3368b2962a59b) Thanks [@SamCreasey](https://github.com/SamCreasey)! - - Toolbar design updated
8
+ - Add Attachments to the Toolbar component. `isFlyoutOpen`, `setIsFlyoutOpen` and `flyoutItems` props have been removed from the Toolbar and replaced
9
+ with a `flyoutMenu` object (`{ items: FlyoutItem[]; isOpen: boolean; onOpenChange: (isOpen: boolean)=>void }`).
10
+ `isFlyoutDisabled` prop has been removed.
11
+ `attachments` prop has been added (`{ isEnabled: boolean; isOpen: boolean; onOpenChange: (isOpen: boolean)=>void }`).
12
+ To enable block attachments in the Toolbar from the `BlockWrapper` component, set `showAttachments` to `true` and wrap the block in the `withAttachmentsProvider` HOC or alternatively, wrap the `BlockWrapper` in an `AttachmentsProvider`.
13
+ - `onAddAttachments` has been replaced with `onAttachmentsAdd` in the object returned from `useAttachments` hook.
14
+
15
+ ### Patch Changes
16
+
17
+ - [#679](https://github.com/Frontify/brand-sdk/pull/679) [`61edea9`](https://github.com/Frontify/brand-sdk/commit/61edea939fc9c2c64badafb054a5c254c8cef580) Thanks [@ragi96](https://github.com/ragi96)! - feat(Attachments): replace download function to use the appBridge
18
+
19
+ ## 0.29.17
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [[`a2b2ee7`](https://github.com/Frontify/brand-sdk/commit/a2b2ee78b8df136c823a3603c284aba4db08bbf7)]:
24
+ - @frontify/app-bridge@3.0.1
25
+ - @frontify/sidebar-settings@0.8.2
26
+
3
27
  ## 0.29.16
4
28
 
5
29
  ### Patch Changes
@@ -1,102 +1,96 @@
1
- import { jsxs as h, jsx as t } from "react/jsx-runtime";
2
- import { forwardRef as E, useState as L, useEffect as y } from "react";
3
- import { useFileInput as M, useAssetUpload as P } from "@frontify/app-bridge";
4
- import { useSortable as V } from "@dnd-kit/sortable";
5
- import { useFocusRing as B } from "@react-aria/focus";
6
- import { LoadingCircle as O, LoadingCircleSize as $, FOCUS_STYLE as T, IconGrabHandle20 as X, Flyout as G, FlyoutPlacement as H, Button as _, IconPen20 as Y, ButtonEmphasis as q, ActionMenu as J, MenuItemContentSize as g, IconArrowCircleUp20 as K, IconImageStack20 as Q, MenuItemStyle as W, IconTrashBin20 as Z, IconImage24 as tt, IconPlayFrame24 as et, IconMusicNote24 as ot, IconDocument24 as at } from "@frontify/fondue";
7
- import { joinClassNames as v } from "../../utilities/react/joinClassNames.es.js";
8
- const rt = (e) => e === "IMAGE" ? /* @__PURE__ */ t(tt, {}) : e === "VIDEO" ? /* @__PURE__ */ t(et, {}) : e === "AUDIO" ? /* @__PURE__ */ t(ot, {}) : /* @__PURE__ */ t(at, {}), k = E(
1
+ import { jsxs as b, jsx as t } from "react/jsx-runtime";
2
+ import { forwardRef as A, useState as j, useEffect as I } from "react";
3
+ import { useFileInput as D, useAssetUpload as E } from "@frontify/app-bridge";
4
+ import { useSortable as M } from "@dnd-kit/sortable";
5
+ import { useFocusRing as P } from "@react-aria/focus";
6
+ import { LoadingCircle as V, LoadingCircleSize as B, FOCUS_STYLE as L, IconGrabHandle20 as U, Flyout as $, FlyoutPlacement as O, Button as T, IconPen20 as X, ButtonEmphasis as G, ActionMenu as H, MenuItemContentSize as f, IconArrowCircleUp20 as _, IconImageStack20 as Y, MenuItemStyle as q, IconTrashBin20 as J, IconImage24 as K, IconPlayFrame24 as Q, IconMusicNote24 as W, IconDocument24 as Z } from "@frontify/fondue";
7
+ import { joinClassNames as h } from "../../utilities/react/joinClassNames.es.js";
8
+ const tt = (e) => e === "IMAGE" ? /* @__PURE__ */ t(K, {}) : e === "VIDEO" ? /* @__PURE__ */ t(Q, {}) : e === "AUDIO" ? /* @__PURE__ */ t(W, {}) : /* @__PURE__ */ t(Z, {}), y = A(
9
9
  ({
10
10
  item: e,
11
- isEditing: c,
12
- draggableProps: d,
11
+ isEditing: s,
12
+ draggableProps: c,
13
13
  transformStyle: u,
14
14
  isDragging: o,
15
- isOverlay: r,
16
- isLoading: i,
17
- onDelete: w,
15
+ isOverlay: a,
16
+ isLoading: n,
17
+ onDelete: d,
18
18
  onReplaceWithBrowse: m,
19
- onReplaceWithUpload: S
20
- }, N) => {
21
- const [a, n] = L(), [C, { selectedFiles: l }] = M({ multiple: !0, accept: "image/*" }), [F, { results: x, doneAll: p }] = P(), { focusProps: R, isFocusVisible: I } = B();
22
- y(() => {
23
- l && F(l[0]);
24
- }, [l]), y(() => {
25
- p && S(x[0]);
26
- }, [p, x]);
27
- const z = (s, b) => {
28
- fetch(s).then((A) => {
29
- A.blob().then((U) => {
30
- const j = URL.createObjectURL(U), f = document.createElement("a");
31
- f.href = j, f.download = b, f.click();
32
- });
33
- });
34
- }, D = i || l && !p;
35
- return /* @__PURE__ */ h(
19
+ onReplaceWithUpload: S,
20
+ onDownload: w
21
+ }, k) => {
22
+ const [r, i] = j(), [C, { selectedFiles: l }] = D({ multiple: !0, accept: "image/*" }), [N, { results: g, doneAll: p }] = E(), { focusProps: F, isFocusVisible: v } = P();
23
+ I(() => {
24
+ l && N(l[0]);
25
+ }, [l]), I(() => {
26
+ p && S(g[0]);
27
+ }, [p, g]);
28
+ const z = n || l && !p;
29
+ return /* @__PURE__ */ b(
36
30
  "button",
37
31
  {
38
32
  "aria-label": "Download attachment",
39
33
  "data-test-id": "attachments-item",
40
- onClick: () => z(e.genericUrl, e.fileName),
41
- ref: N,
34
+ onClick: () => w == null ? void 0 : w(),
35
+ ref: k,
42
36
  style: {
43
37
  ...u,
44
- opacity: o && !r ? 0.3 : 1,
38
+ opacity: o && !a ? 0.3 : 1,
45
39
  fontFamily: "var(-f-theme-settings-body-font-family)"
46
40
  },
47
- className: v([
41
+ className: h([
48
42
  "tw-cursor-pointer tw-text-left tw-w-full tw-relative tw-flex tw-gap-3 tw-px-5 tw-py-3 tw-items-center tw-group hover:tw-bg-box-neutral-hover",
49
43
  o ? "tw-bg-box-neutral-hover" : ""
50
44
  ]),
51
45
  children: [
52
- /* @__PURE__ */ t("div", { className: "tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover", children: D ? /* @__PURE__ */ t(O, { size: $.Small }) : rt(e.objectType) }),
53
- /* @__PURE__ */ h("div", { className: "tw-text-s tw-flex-1 tw-min-w-0", children: [
46
+ /* @__PURE__ */ t("div", { className: "tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover", children: z ? /* @__PURE__ */ t(V, { size: B.Small }) : tt(e.objectType) }),
47
+ /* @__PURE__ */ b("div", { className: "tw-text-s tw-flex-1 tw-min-w-0", children: [
54
48
  /* @__PURE__ */ t("div", { className: "tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover", children: e.title }),
55
49
  /* @__PURE__ */ t("div", { className: "tw-text-text-weak", children: `${e.fileSizeHumanReadable} - ${e.extension}` })
56
50
  ] }),
57
- c && /* @__PURE__ */ h(
51
+ s && /* @__PURE__ */ b(
58
52
  "div",
59
53
  {
60
54
  "data-test-id": "attachments-actionbar",
61
- className: v([
55
+ className: h([
62
56
  "tw-flex tw-gap-0.5 group-focus:tw-opacity-100 focus-visible:tw-opacity-100 focus-within:tw-opacity-100 group-hover:tw-opacity-100",
63
- r || (a == null ? void 0 : a.id) === e.id ? "tw-opacity-100" : "tw-opacity-0"
57
+ a || (r == null ? void 0 : r.id) === e.id ? "tw-opacity-100" : "tw-opacity-0"
64
58
  ]),
65
59
  children: [
66
60
  /* @__PURE__ */ t(
67
61
  "button",
68
62
  {
69
- ...R,
70
- ...d,
63
+ ...F,
64
+ ...c,
71
65
  "aria-label": "Drag attachment",
72
- className: v([
66
+ className: h([
73
67
  " tw-border-button-border tw-bg-button-background active:tw-bg-button-background-pressed tw-group tw-border tw-box-box tw-relative tw-flex tw-items-center tw-justify-center tw-outline-none tw-font-medium tw-rounded tw-h-9 tw-w-9 ",
74
- o || r ? "tw-cursor-grabbing tw-bg-button-background-pressed hover:tw-bg-button-background-pressed" : "tw-cursor-grab hover:tw-bg-button-background-hover",
75
- I && T,
76
- I && "tw-z-[2]"
68
+ o || a ? "tw-cursor-grabbing tw-bg-button-background-pressed hover:tw-bg-button-background-pressed" : "tw-cursor-grab hover:tw-bg-button-background-hover",
69
+ v && L,
70
+ v && "tw-z-[2]"
77
71
  ]),
78
- children: /* @__PURE__ */ t(X, {})
72
+ children: /* @__PURE__ */ t(U, {})
79
73
  }
80
74
  ),
81
75
  /* @__PURE__ */ t("div", { "data-test-id": "attachments-actionbar-flyout", children: /* @__PURE__ */ t(
82
- G,
76
+ $,
83
77
  {
84
- placement: H.Right,
85
- isOpen: (a == null ? void 0 : a.id) === e.id,
78
+ placement: O.Right,
79
+ isOpen: (r == null ? void 0 : r.id) === e.id,
86
80
  fitContent: !0,
87
81
  legacyFooter: !1,
88
- onOpenChange: (s) => n(s ? e : void 0),
89
- trigger: (s, b) => /* @__PURE__ */ t(
90
- _,
82
+ onOpenChange: (x) => i(x ? e : void 0),
83
+ trigger: (x, R) => /* @__PURE__ */ t(
84
+ T,
91
85
  {
92
- ref: b,
93
- icon: /* @__PURE__ */ t(Y, {}),
94
- emphasis: q.Default,
95
- onClick: () => n(e)
86
+ ref: R,
87
+ icon: /* @__PURE__ */ t(X, {}),
88
+ emphasis: G.Default,
89
+ onClick: () => i(e)
96
90
  }
97
91
  ),
98
92
  children: /* @__PURE__ */ t(
99
- J,
93
+ H,
100
94
  {
101
95
  menuBlocks: [
102
96
  {
@@ -104,23 +98,23 @@ const rt = (e) => e === "IMAGE" ? /* @__PURE__ */ t(tt, {}) : e === "VIDEO" ? /*
104
98
  menuItems: [
105
99
  {
106
100
  id: "upload",
107
- size: g.XSmall,
101
+ size: f.XSmall,
108
102
  title: "Replace with upload",
109
103
  onClick: () => {
110
- C(), n(void 0);
104
+ C(), i(void 0);
111
105
  },
112
106
  initialValue: !0,
113
- decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(K, {}) })
107
+ decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(_, {}) })
114
108
  },
115
109
  {
116
110
  id: "asset",
117
- size: g.XSmall,
111
+ size: f.XSmall,
118
112
  title: "Replace with asset",
119
113
  onClick: () => {
120
- m(), n(void 0);
114
+ m(), i(void 0);
121
115
  },
122
116
  initialValue: !0,
123
- decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(Q, {}) })
117
+ decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(Y, {}) })
124
118
  }
125
119
  ]
126
120
  },
@@ -129,14 +123,14 @@ const rt = (e) => e === "IMAGE" ? /* @__PURE__ */ t(tt, {}) : e === "VIDEO" ? /*
129
123
  menuItems: [
130
124
  {
131
125
  id: "delete",
132
- size: g.XSmall,
126
+ size: f.XSmall,
133
127
  title: "Delete",
134
- style: W.Danger,
128
+ style: q.Danger,
135
129
  onClick: () => {
136
- w(), n(void 0);
130
+ d(), i(void 0);
137
131
  },
138
132
  initialValue: !0,
139
- decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(Z, {}) })
133
+ decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(J, {}) })
140
134
  }
141
135
  ]
142
136
  }
@@ -153,28 +147,28 @@ const rt = (e) => e === "IMAGE" ? /* @__PURE__ */ t(tt, {}) : e === "VIDEO" ? /*
153
147
  );
154
148
  }
155
149
  );
156
- k.displayName = "AttachmentItem";
157
- const wt = (e) => {
158
- const { attributes: c, listeners: d, setNodeRef: u, transform: o, transition: r, isDragging: i } = V({
150
+ y.displayName = "AttachmentItem";
151
+ const st = (e) => {
152
+ const { attributes: s, listeners: c, setNodeRef: u, transform: o, transition: a, isDragging: n } = M({
159
153
  id: e.item.id
160
- }), w = {
154
+ }), d = {
161
155
  transform: o ? `translate(${o.x}px, ${o.y}px)` : "",
162
- transition: r,
163
- zIndex: i ? 2 : 1
164
- }, m = { ...c, ...d };
156
+ transition: a,
157
+ zIndex: n ? 2 : 1
158
+ }, m = { ...s, ...c };
165
159
  return /* @__PURE__ */ t(
166
- k,
160
+ y,
167
161
  {
168
162
  ref: u,
169
- isDragging: i,
170
- transformStyle: w,
163
+ isDragging: n,
164
+ transformStyle: d,
171
165
  draggableProps: m,
172
166
  ...e
173
167
  }
174
168
  );
175
169
  };
176
170
  export {
177
- k as AttachmentItem,
178
- wt as SortableAttachmentItem
171
+ y as AttachmentItem,
172
+ st as SortableAttachmentItem
179
173
  };
180
174
  //# sourceMappingURL=AttachmentItem.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AttachmentItem.es.js","sources":["../../../src/components/Attachments/AttachmentItem.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { MutableRefObject, forwardRef, useEffect, useState } from 'react';\nimport { Asset, useAssetUpload, useFileInput } from '@frontify/app-bridge';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { useFocusRing } from '@react-aria/focus';\n\nimport {\n ActionMenu,\n Button,\n ButtonEmphasis,\n FOCUS_STYLE,\n Flyout,\n FlyoutPlacement,\n IconArrowCircleUp20,\n IconDocument24,\n IconGrabHandle20,\n IconImage24,\n IconImageStack20,\n IconMusicNote24,\n IconPen20,\n IconPlayFrame24,\n IconTrashBin20,\n LoadingCircle,\n LoadingCircleSize,\n MenuItemContentSize,\n MenuItemStyle,\n} from '@frontify/fondue';\nimport { AttachmentItemProps, SortableAttachmentItemProps } from './types';\nimport { joinClassNames } from '../../utilities';\n\nconst getDecorator = (type: string) => {\n if (type === 'IMAGE') {\n return <IconImage24 />;\n } else if (type === 'VIDEO') {\n return <IconPlayFrame24 />;\n } else if (type === 'AUDIO') {\n return <IconMusicNote24 />;\n } else {\n return <IconDocument24 />;\n }\n};\n\nexport const AttachmentItem = forwardRef<HTMLButtonElement, AttachmentItemProps>(\n (\n {\n item,\n isEditing,\n draggableProps,\n transformStyle,\n isDragging,\n isOverlay,\n isLoading,\n onDelete,\n onReplaceWithBrowse,\n onReplaceWithUpload,\n },\n ref,\n ) => {\n const [selectedAsset, setSelectedAsset] = useState<Asset | undefined>();\n const [openFileDialog, { selectedFiles }] = useFileInput({ multiple: true, accept: 'image/*' });\n const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload();\n const { focusProps, isFocusVisible } = useFocusRing();\n\n useEffect(() => {\n if (selectedFiles) {\n uploadFile(selectedFiles[0]);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selectedFiles]);\n\n useEffect(() => {\n if (doneAll) {\n onReplaceWithUpload(uploadResults[0]);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [doneAll, uploadResults]);\n\n const download = (url: string, filename: string) => {\n fetch(url).then((response) => {\n response.blob().then((blob) => {\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = filename;\n a.click();\n });\n });\n };\n\n const showLoadingCircle = isLoading || (selectedFiles && !doneAll);\n\n return (\n <button\n aria-label=\"Download attachment\"\n data-test-id=\"attachments-item\"\n onClick={() => download(item.genericUrl, item.fileName)}\n ref={ref}\n style={{\n ...transformStyle,\n opacity: isDragging && !isOverlay ? 0.3 : 1,\n fontFamily: 'var(-f-theme-settings-body-font-family)',\n }}\n className={joinClassNames([\n 'tw-cursor-pointer tw-text-left tw-w-full tw-relative tw-flex tw-gap-3 tw-px-5 tw-py-3 tw-items-center tw-group hover:tw-bg-box-neutral-hover',\n isDragging ? 'tw-bg-box-neutral-hover' : '',\n ])}\n >\n <div className=\"tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover\">\n {showLoadingCircle ? (\n <LoadingCircle size={LoadingCircleSize.Small} />\n ) : (\n getDecorator(item.objectType)\n )}\n </div>\n <div className=\"tw-text-s tw-flex-1 tw-min-w-0\">\n <div className=\"tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover\">\n {item.title}\n </div>\n <div className=\"tw-text-text-weak\">{`${item.fileSizeHumanReadable} - ${item.extension}`}</div>\n </div>\n {isEditing && (\n <div\n data-test-id=\"attachments-actionbar\"\n className={joinClassNames([\n 'tw-flex tw-gap-0.5 group-focus:tw-opacity-100 focus-visible:tw-opacity-100 focus-within:tw-opacity-100 group-hover:tw-opacity-100',\n isOverlay || selectedAsset?.id === item.id ? 'tw-opacity-100' : 'tw-opacity-0',\n ])}\n >\n <button\n {...focusProps}\n {...draggableProps}\n aria-label=\"Drag attachment\"\n className={joinClassNames([\n ' tw-border-button-border tw-bg-button-background active:tw-bg-button-background-pressed tw-group tw-border tw-box-box tw-relative tw-flex tw-items-center tw-justify-center tw-outline-none tw-font-medium tw-rounded tw-h-9 tw-w-9 ',\n isDragging || isOverlay\n ? 'tw-cursor-grabbing tw-bg-button-background-pressed hover:tw-bg-button-background-pressed'\n : 'tw-cursor-grab hover:tw-bg-button-background-hover',\n isFocusVisible && FOCUS_STYLE,\n isFocusVisible && 'tw-z-[2]',\n ])}\n >\n <IconGrabHandle20 />\n </button>\n <div data-test-id=\"attachments-actionbar-flyout\">\n <Flyout\n placement={FlyoutPlacement.Right}\n isOpen={selectedAsset?.id === item.id}\n fitContent\n legacyFooter={false}\n onOpenChange={(isOpen) => setSelectedAsset(isOpen ? item : undefined)}\n trigger={(_, ref) => (\n <Button\n ref={ref as MutableRefObject<HTMLButtonElement>}\n icon={<IconPen20 />}\n emphasis={ButtonEmphasis.Default}\n onClick={() => setSelectedAsset(item)}\n />\n )}\n >\n <ActionMenu\n menuBlocks={[\n {\n id: 'menu',\n menuItems: [\n {\n id: 'upload',\n size: MenuItemContentSize.XSmall,\n title: 'Replace with upload',\n onClick: () => {\n openFileDialog();\n setSelectedAsset(undefined);\n },\n\n initialValue: true,\n decorator: (\n <div className=\"tw-mr-2\">\n <IconArrowCircleUp20 />\n </div>\n ),\n },\n\n {\n id: 'asset',\n size: MenuItemContentSize.XSmall,\n title: 'Replace with asset',\n onClick: () => {\n onReplaceWithBrowse();\n setSelectedAsset(undefined);\n },\n initialValue: true,\n decorator: (\n <div className=\"tw-mr-2\">\n <IconImageStack20 />\n </div>\n ),\n },\n ],\n },\n {\n id: 'menu-delete',\n menuItems: [\n {\n id: 'delete',\n size: MenuItemContentSize.XSmall,\n title: 'Delete',\n style: MenuItemStyle.Danger,\n onClick: () => {\n onDelete();\n setSelectedAsset(undefined);\n },\n\n initialValue: true,\n decorator: (\n <div className=\"tw-mr-2\">\n <IconTrashBin20 />\n </div>\n ),\n },\n ],\n },\n ]}\n />\n </Flyout>\n </div>\n </div>\n )}\n </button>\n );\n },\n);\n\nAttachmentItem.displayName = 'AttachmentItem';\n\nexport const SortableAttachmentItem = (props: SortableAttachmentItemProps) => {\n const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({\n id: props.item.id,\n });\n\n const transformStyle = {\n transform: transform ? `translate(${transform.x}px, ${transform.y}px)` : '',\n transition,\n zIndex: isDragging ? 2 : 1,\n };\n\n const draggableProps = { ...attributes, ...listeners };\n\n return (\n <AttachmentItem\n ref={setNodeRef}\n isDragging={isDragging}\n transformStyle={transformStyle}\n draggableProps={draggableProps}\n {...props}\n />\n );\n};\n"],"names":["getDecorator","type","IconImage24","IconPlayFrame24","IconMusicNote24","IconDocument24","AttachmentItem","forwardRef","item","isEditing","draggableProps","transformStyle","isDragging","isOverlay","isLoading","onDelete","onReplaceWithBrowse","onReplaceWithUpload","ref","selectedAsset","setSelectedAsset","useState","openFileDialog","selectedFiles","useFileInput","uploadFile","uploadResults","doneAll","useAssetUpload","focusProps","isFocusVisible","useFocusRing","useEffect","download","url","filename","response","blob","a","showLoadingCircle","jsxs","joinClassNames","jsx","LoadingCircle","LoadingCircleSize","FOCUS_STYLE","IconGrabHandle20","Flyout","FlyoutPlacement","isOpen","_","Button","IconPen20","ButtonEmphasis","ActionMenu","MenuItemContentSize","IconArrowCircleUp20","IconImageStack20","MenuItemStyle","IconTrashBin20","SortableAttachmentItem","props","attributes","listeners","setNodeRef","transform","transition","useSortable"],"mappings":";;;;;;;AA+BA,MAAMA,KAAe,CAACC,MACdA,MAAS,4BACDC,IAAY,CAAA,CAAA,IACbD,MAAS,4BACRE,IAAgB,CAAA,CAAA,IACjBF,MAAS,4BACRG,IAAgB,CAAA,CAAA,sBAEhBC,IAAe,CA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CAC1B,OAAO;AAAA,gCACP,OAAOG,EAAc;AAAA,gCACrB,SAAS,MAAM;AACF,kCAAA3C,KACTK,EAAiB,MAAS;AAAA,gCAC9B;AAAA,gCAEA,cAAc;AAAA,gCACd,WACK,gBAAAsB,EAAA,OAAA,EAAI,WAAU,WACX,UAAA,gBAAAA,EAACiB,IAAe,CAAA,GACpB;AAAA,8BAER;AAAA,4BACJ;AAAA,0BACJ;AAAA,wBACJ;AAAA,sBAAA;AAAA,oBACJ;AAAA,kBAAA;AAAA,gBAAA,GAER;AAAA,cAAA;AAAA,YAAA;AAAA,UACJ;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIhB;AACJ;AAEArD,EAAe,cAAc;AAEhB,MAAAsD,KAAyB,CAACC,MAAuC;AACpE,QAAA,EAAE,YAAAC,GAAY,WAAAC,GAAW,YAAAC,GAAY,WAAAC,GAAW,YAAAC,GAAY,YAAAtD,MAAeuD,EAAY;AAAA,IACzF,IAAIN,EAAM,KAAK;AAAA,EAAA,CAClB,GAEKlD,IAAiB;AAAA,IACnB,WAAWsD,IAAY,aAAaA,EAAU,CAAC,OAAOA,EAAU,CAAC,QAAQ;AAAA,IACzE,YAAAC;AAAA,IACA,QAAQtD,IAAa,IAAI;AAAA,EAAA,GAGvBF,IAAiB,EAAE,GAAGoD,GAAY,GAAGC,EAAU;AAGjD,SAAA,gBAAArB;AAAA,IAACpC;AAAA,IAAA;AAAA,MACG,KAAK0D;AAAA,MACL,YAAApD;AAAA,MACA,gBAAAD;AAAA,MACA,gBAAAD;AAAA,MACC,GAAGmD;AAAA,IAAA;AAAA,EAAA;AAGhB;"}
1
+ {"version":3,"file":"AttachmentItem.es.js","sources":["../../../src/components/Attachments/AttachmentItem.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { MutableRefObject, forwardRef, useEffect, useState } from 'react';\nimport { Asset, useAssetUpload, useFileInput } from '@frontify/app-bridge';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { useFocusRing } from '@react-aria/focus';\n\nimport {\n ActionMenu,\n Button,\n ButtonEmphasis,\n FOCUS_STYLE,\n Flyout,\n FlyoutPlacement,\n IconArrowCircleUp20,\n IconDocument24,\n IconGrabHandle20,\n IconImage24,\n IconImageStack20,\n IconMusicNote24,\n IconPen20,\n IconPlayFrame24,\n IconTrashBin20,\n LoadingCircle,\n LoadingCircleSize,\n MenuItemContentSize,\n MenuItemStyle,\n} from '@frontify/fondue';\nimport { AttachmentItemProps, SortableAttachmentItemProps } from './types';\nimport { joinClassNames } from '../../utilities';\n\nconst getDecorator = (type: string) => {\n if (type === 'IMAGE') {\n return <IconImage24 />;\n } else if (type === 'VIDEO') {\n return <IconPlayFrame24 />;\n } else if (type === 'AUDIO') {\n return <IconMusicNote24 />;\n } else {\n return <IconDocument24 />;\n }\n};\n\nexport const AttachmentItem = forwardRef<HTMLButtonElement, AttachmentItemProps>(\n (\n {\n item,\n isEditing,\n draggableProps,\n transformStyle,\n isDragging,\n isOverlay,\n isLoading,\n onDelete,\n onReplaceWithBrowse,\n onReplaceWithUpload,\n onDownload,\n },\n ref,\n ) => {\n const [selectedAsset, setSelectedAsset] = useState<Asset | undefined>();\n const [openFileDialog, { selectedFiles }] = useFileInput({ multiple: true, accept: 'image/*' });\n const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload();\n const { focusProps, isFocusVisible } = useFocusRing();\n\n useEffect(() => {\n if (selectedFiles) {\n uploadFile(selectedFiles[0]);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selectedFiles]);\n\n useEffect(() => {\n if (doneAll) {\n onReplaceWithUpload(uploadResults[0]);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [doneAll, uploadResults]);\n\n const showLoadingCircle = isLoading || (selectedFiles && !doneAll);\n\n return (\n <button\n aria-label=\"Download attachment\"\n data-test-id=\"attachments-item\"\n onClick={() => onDownload?.()}\n ref={ref}\n style={{\n ...transformStyle,\n opacity: isDragging && !isOverlay ? 0.3 : 1,\n fontFamily: 'var(-f-theme-settings-body-font-family)',\n }}\n className={joinClassNames([\n 'tw-cursor-pointer tw-text-left tw-w-full tw-relative tw-flex tw-gap-3 tw-px-5 tw-py-3 tw-items-center tw-group hover:tw-bg-box-neutral-hover',\n isDragging ? 'tw-bg-box-neutral-hover' : '',\n ])}\n >\n <div className=\"tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover\">\n {showLoadingCircle ? (\n <LoadingCircle size={LoadingCircleSize.Small} />\n ) : (\n getDecorator(item.objectType)\n )}\n </div>\n <div className=\"tw-text-s tw-flex-1 tw-min-w-0\">\n <div className=\"tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover\">\n {item.title}\n </div>\n <div className=\"tw-text-text-weak\">{`${item.fileSizeHumanReadable} - ${item.extension}`}</div>\n </div>\n {isEditing && (\n <div\n data-test-id=\"attachments-actionbar\"\n className={joinClassNames([\n 'tw-flex tw-gap-0.5 group-focus:tw-opacity-100 focus-visible:tw-opacity-100 focus-within:tw-opacity-100 group-hover:tw-opacity-100',\n isOverlay || selectedAsset?.id === item.id ? 'tw-opacity-100' : 'tw-opacity-0',\n ])}\n >\n <button\n {...focusProps}\n {...draggableProps}\n aria-label=\"Drag attachment\"\n className={joinClassNames([\n ' tw-border-button-border tw-bg-button-background active:tw-bg-button-background-pressed tw-group tw-border tw-box-box tw-relative tw-flex tw-items-center tw-justify-center tw-outline-none tw-font-medium tw-rounded tw-h-9 tw-w-9 ',\n isDragging || isOverlay\n ? 'tw-cursor-grabbing tw-bg-button-background-pressed hover:tw-bg-button-background-pressed'\n : 'tw-cursor-grab hover:tw-bg-button-background-hover',\n isFocusVisible && FOCUS_STYLE,\n isFocusVisible && 'tw-z-[2]',\n ])}\n >\n <IconGrabHandle20 />\n </button>\n <div data-test-id=\"attachments-actionbar-flyout\">\n <Flyout\n placement={FlyoutPlacement.Right}\n isOpen={selectedAsset?.id === item.id}\n fitContent\n legacyFooter={false}\n onOpenChange={(isOpen) => setSelectedAsset(isOpen ? item : undefined)}\n trigger={(_, ref) => (\n <Button\n ref={ref as MutableRefObject<HTMLButtonElement>}\n icon={<IconPen20 />}\n emphasis={ButtonEmphasis.Default}\n onClick={() => setSelectedAsset(item)}\n />\n )}\n >\n <ActionMenu\n menuBlocks={[\n {\n id: 'menu',\n menuItems: [\n {\n id: 'upload',\n size: MenuItemContentSize.XSmall,\n title: 'Replace with upload',\n onClick: () => {\n openFileDialog();\n setSelectedAsset(undefined);\n },\n\n initialValue: true,\n decorator: (\n <div className=\"tw-mr-2\">\n <IconArrowCircleUp20 />\n </div>\n ),\n },\n\n {\n id: 'asset',\n size: MenuItemContentSize.XSmall,\n title: 'Replace with asset',\n onClick: () => {\n onReplaceWithBrowse();\n setSelectedAsset(undefined);\n },\n initialValue: true,\n decorator: (\n <div className=\"tw-mr-2\">\n <IconImageStack20 />\n </div>\n ),\n },\n ],\n },\n {\n id: 'menu-delete',\n menuItems: [\n {\n id: 'delete',\n size: MenuItemContentSize.XSmall,\n title: 'Delete',\n style: MenuItemStyle.Danger,\n onClick: () => {\n onDelete();\n setSelectedAsset(undefined);\n },\n\n initialValue: true,\n decorator: (\n <div className=\"tw-mr-2\">\n <IconTrashBin20 />\n </div>\n ),\n },\n ],\n },\n ]}\n />\n </Flyout>\n </div>\n </div>\n )}\n </button>\n );\n },\n);\n\nAttachmentItem.displayName = 'AttachmentItem';\n\nexport const SortableAttachmentItem = (props: SortableAttachmentItemProps) => {\n const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({\n id: props.item.id,\n });\n\n const transformStyle = {\n transform: transform ? `translate(${transform.x}px, ${transform.y}px)` : '',\n transition,\n zIndex: isDragging ? 2 : 1,\n };\n\n const draggableProps = { ...attributes, ...listeners };\n\n return (\n <AttachmentItem\n ref={setNodeRef}\n isDragging={isDragging}\n transformStyle={transformStyle}\n draggableProps={draggableProps}\n {...props}\n />\n );\n};\n"],"names":["getDecorator","type","IconImage24","IconPlayFrame24","IconMusicNote24","IconDocument24","AttachmentItem","forwardRef","item","isEditing","draggableProps","transformStyle","isDragging","isOverlay","isLoading","onDelete","onReplaceWithBrowse","onReplaceWithUpload","onDownload","ref","selectedAsset","setSelectedAsset","useState","openFileDialog","selectedFiles","useFileInput","uploadFile","uploadResults","doneAll","useAssetUpload","focusProps","isFocusVisible","useFocusRing","useEffect","showLoadingCircle","jsxs","joinClassNames","jsx","LoadingCircle","LoadingCircleSize","FOCUS_STYLE","IconGrabHandle20","Flyout","FlyoutPlacement","isOpen","_","Button","IconPen20","ButtonEmphasis","ActionMenu","MenuItemContentSize","IconArrowCircleUp20","IconImageStack20","MenuItemStyle","IconTrashBin20","SortableAttachmentItem","props","attributes","listeners","setNodeRef","transform","transition","useSortable"],"mappings":";;;;;;;AA+BA,MAAMA,KAAe,CAACC,MACdA,MAAS,4BACDC,GAAY,CAAA,CAAA,IACbD,MAAS,4BACRE,GAAgB,CAAA,CAAA,IACjBF,MAAS,4BACRG,GAAgB,CAAA,CAAA,sBAEhBC,GAAe,CAAA,CAAA,GAIlBC,IAAiBC;AAAA,EAC1B,CACI;AAAA,IACI,MAAAC;AAAA,IACA,WAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,UAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,YAAAC;AAAA,KAEJC,MACC;AACD,UAAM,CAACC,GAAeC,CAAgB,IAAIC,EAA4B,GAChE,CAACC,GAAgB,EAAE,eAAAC,EAAA,CAAe,IAAIC,EAAa,EAAE,UAAU,IAAM,QAAQ,UAAW,CAAA,GACxF,CAACC,GAAY,EAAE,SAASC,GAAe,SAAAC,EAAS,CAAA,IAAIC,KACpD,EAAE,YAAAC,GAAY,gBAAAC,EAAe,IAAIC,EAAa;AAEpD,IAAAC,EAAU,MAAM;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AAC/B;AAAA,IAAA;AAAA,MACG,KAAKqD;AAAA,MACL,YAAA/C;AAAA,MACA,gBAAAD;AAAA,MACA,gBAAAD;AAAA,MACC,GAAG8C;AAAA,IAAA;AAAA,EAAA;AAGhB;"}
@@ -1,135 +1,142 @@
1
- import { jsx as o, jsxs as p } from "react/jsx-runtime";
2
- import { useState as r, useEffect as f } from "react";
3
- import { useSensors as q, useSensor as U, PointerSensor as B, KeyboardSensor as G, DndContext as H, closestCenter as J, DragOverlay as Q } from "@dnd-kit/core";
4
- import { SortableContext as X, rectSortingStrategy as Y, arrayMove as Z } from "@dnd-kit/sortable";
5
- import { useEditorState as _, useAssetUpload as $ } from "@frontify/app-bridge";
6
- import { LegacyTooltip as ee, TooltipPosition as te, Flyout as oe, FlyoutPlacement as se, IconPaperclip16 as ne, IconCaretDown12 as ie, AssetInput as re, AssetInputSize as le } from "@frontify/fondue";
7
- import { SortableAttachmentItem as de, AttachmentItem as ae } from "./AttachmentItem.es.js";
8
- import { restrictToWindowEdges as ce } from "@dnd-kit/modifiers";
9
- const ye = ({
10
- items: l = [],
11
- onDelete: x,
12
- onReplaceWithBrowse: E,
13
- onReplaceWithUpload: O,
14
- onBrowse: W,
15
- onUpload: N,
16
- onSorted: P,
17
- appBridge: d
1
+ import { jsx as n, jsxs as y } from "react/jsx-runtime";
2
+ import { useState as d, useEffect as w } from "react";
3
+ import { useSensors as X, useSensor as U, PointerSensor as Y, KeyboardSensor as Z, DndContext as _, closestCenter as $, DragOverlay as tt } from "@dnd-kit/core";
4
+ import { restrictToWindowEdges as et } from "@dnd-kit/modifiers";
5
+ import { SortableContext as ot, rectSortingStrategy as nt, arrayMove as st } from "@dnd-kit/sortable";
6
+ import { useEditorState as it, useAssetUpload as lt } from "@frontify/app-bridge";
7
+ import { LegacyTooltip as dt, TooltipPosition as at, Flyout as rt, FlyoutPlacement as ct, AssetInput as ut, AssetInputSize as ht } from "@frontify/fondue";
8
+ import { SortableAttachmentItem as mt, AttachmentItem as gt } from "./AttachmentItem.es.js";
9
+ import { AttachmentsButtonTrigger as pt } from "./AttachmentsButtonTrigger.es.js";
10
+ const Dt = ({
11
+ items: a = [],
12
+ onDelete: A,
13
+ onReplaceWithBrowse: W,
14
+ onReplaceWithUpload: T,
15
+ onBrowse: N,
16
+ onUpload: P,
17
+ onSorted: R,
18
+ appBridge: i,
19
+ triggerComponent: j = pt,
20
+ isOpen: I,
21
+ onOpenChange: k
18
22
  }) => {
19
- const [t, y] = r(l), [v, a] = r(!1), R = q(U(B), U(G)), [I, b] = r(void 0), [A, h] = r(!1), [c, u] = r([]), [m, T] = r(null), g = _(d), i = t == null ? void 0 : t.find((e) => e.id === I), [j, { results: S, doneAll: D }] = $({
20
- onUploadProgress: () => !A && h(!0)
21
- });
22
- f(() => {
23
- y(l);
24
- }, [l]), f(() => {
25
- m && (h(!0), j(m));
26
- }, [m]), f(() => {
23
+ const [o, S] = d(a), [z, V] = d(!1), K = X(U(Y), U(Z)), [v, x] = d(void 0), [C, m] = d(!1), [r, u] = d([]), [g, M] = d(null), h = it(i), D = I !== void 0, p = D ? I : z, l = o == null ? void 0 : o.find((t) => t.id === v), [q, { results: b, doneAll: F }] = lt({
24
+ onUploadProgress: () => !C && m(!0)
25
+ }), c = (t) => {
26
+ const e = D ? k : V;
27
+ e == null || e(t);
28
+ };
29
+ w(() => {
30
+ S(a);
31
+ }, [a]), w(() => {
32
+ g && (m(!0), q(g));
33
+ }, [g]), w(() => {
27
34
  (async () => {
28
- D && (await N(S), h(!1));
35
+ F && (await P(b), m(!1));
29
36
  })();
30
- }, [D, S]);
31
- const k = () => {
32
- a(!1), d.openAssetChooser(
33
- (e) => {
34
- W(e), d.closeAssetChooser(), a(!0);
37
+ }, [F, b]);
38
+ const B = () => {
39
+ c(!1), i.openAssetChooser(
40
+ (t) => {
41
+ N(t), i.closeAssetChooser(), c(!0);
35
42
  },
36
43
  {
37
44
  multiSelection: !0,
38
- selectedValueIds: t.map((e) => e.id)
45
+ selectedValueIds: o.map((t) => t.id)
39
46
  }
40
47
  );
41
- }, C = (e) => {
42
- a(!1), d.openAssetChooser(
43
- async (s) => {
44
- a(!0), d.closeAssetChooser(), u([...c, e.id]), await E(e, s[0]), u(c.filter((n) => n !== e.id));
48
+ }, E = (t) => {
49
+ c(!1), i.openAssetChooser(
50
+ async (e) => {
51
+ c(!0), i.closeAssetChooser(), u([...r, t.id]), await W(t, e[0]), u(r.filter((s) => s !== t.id));
45
52
  },
46
53
  {
47
54
  multiSelection: !1,
48
- selectedValueIds: t.map((s) => s.id)
55
+ selectedValueIds: o.map((e) => e.id)
49
56
  }
50
57
  );
51
- }, F = async (e, s) => {
52
- u([...c, e.id]), await O(e, s), u(c.filter((n) => n !== e.id));
53
- }, z = (e) => {
54
- const { active: s } = e;
55
- b(s.id);
56
- }, V = (e) => {
57
- const { active: s, over: n } = e;
58
- if (n && s.id !== n.id && t) {
59
- const K = t.findIndex((w) => w.id === s.id), M = t.findIndex((w) => w.id === n.id), L = Z(t, K, M);
60
- y(L), P(L);
58
+ }, L = async (t, e) => {
59
+ u([...r, t.id]), await T(t, e), u(r.filter((s) => s !== t.id));
60
+ }, G = (t) => {
61
+ const { active: e } = t;
62
+ x(e.id);
63
+ }, H = (t) => {
64
+ const { active: e, over: s } = t;
65
+ if (s && e.id !== s.id && o) {
66
+ const J = o.findIndex((f) => f.id === e.id), Q = o.findIndex((f) => f.id === s.id), O = st(o, J, Q);
67
+ S(O), R(O);
61
68
  }
62
- b(void 0);
69
+ x(void 0);
63
70
  };
64
- return g || ((t == null ? void 0 : t.length) ?? 0) > 0 ? /* @__PURE__ */ o(
65
- ee,
71
+ return h || ((o == null ? void 0 : o.length) ?? 0) > 0 ? /* @__PURE__ */ n(
72
+ dt,
66
73
  {
67
74
  withArrow: !0,
68
- position: te.Top,
75
+ position: at.Top,
69
76
  content: "Attachments",
70
- disabled: v,
77
+ disabled: p,
71
78
  enterDelay: 500,
72
- triggerElement: /* @__PURE__ */ o("div", { "data-test-id": "attachments-flyout-button", children: /* @__PURE__ */ o(
73
- oe,
79
+ triggerElement: /* @__PURE__ */ n("div", { "data-test-id": "attachments-flyout-button", children: /* @__PURE__ */ n(
80
+ rt,
74
81
  {
75
- placement: se.BottomRight,
76
- onOpenChange: (e) => a(i ? !0 : e),
77
- isOpen: v,
82
+ placement: ct.BottomRight,
83
+ onOpenChange: (t) => c(l ? !0 : t),
84
+ isOpen: p,
78
85
  hug: !1,
79
86
  fitContent: !0,
80
87
  legacyFooter: !1,
81
- trigger: /* @__PURE__ */ p("div", { className: "tw-flex tw-text-[13px] tw-font-body tw-items-center tw-gap-1 tw-rounded-full tw-bg-box-neutral-strong-inverse hover:tw-bg-box-neutral-strong-inverse-hover active:tw-bg-box-neutral-strong-inverse-pressed tw-text-box-neutral-strong tw-outline tw-outline-1 tw-outline-offset-[1px] tw-p-[6px] tw-outline-line", children: [
82
- /* @__PURE__ */ o(ne, {}),
83
- /* @__PURE__ */ o("div", { children: l.length > 0 ? l.length : "Add" }),
84
- /* @__PURE__ */ o(ie, {})
85
- ] }),
86
- children: /* @__PURE__ */ p("div", { className: "tw-w-[300px]", children: [
87
- t.length > 0 && /* @__PURE__ */ p(
88
- H,
88
+ trigger: /* @__PURE__ */ n(j, { isFlyoutOpen: p, children: /* @__PURE__ */ n("div", { children: a.length > 0 ? a.length : "Add" }) }),
89
+ children: /* @__PURE__ */ y("div", { className: "tw-w-[300px]", "data-test-id": "attachments-flyout-content", children: [
90
+ o.length > 0 && /* @__PURE__ */ y(
91
+ _,
89
92
  {
90
- sensors: R,
91
- collisionDetection: J,
92
- onDragStart: z,
93
- onDragEnd: V,
94
- modifiers: [ce],
93
+ sensors: K,
94
+ collisionDetection: $,
95
+ onDragStart: G,
96
+ onDragEnd: H,
97
+ modifiers: [et],
95
98
  children: [
96
- /* @__PURE__ */ o(X, { items: t, strategy: Y, children: /* @__PURE__ */ o("div", { className: "tw-border-b tw-border-b-line", children: t.map((e) => /* @__PURE__ */ o(
97
- de,
99
+ /* @__PURE__ */ n(ot, { items: o, strategy: nt, children: /* @__PURE__ */ n("div", { className: "tw-border-b tw-border-b-line", children: o.map((t) => /* @__PURE__ */ n(
100
+ mt,
98
101
  {
99
- isEditing: g,
100
- isLoading: c.includes(e.id),
101
- item: e,
102
- onDelete: () => x(e),
103
- onReplaceWithBrowse: () => C(e),
104
- onReplaceWithUpload: (s) => F(e, s)
102
+ isEditing: h,
103
+ isLoading: r.includes(t.id),
104
+ item: t,
105
+ onDelete: () => A(t),
106
+ onReplaceWithBrowse: () => E(t),
107
+ onReplaceWithUpload: (e) => L(t, e),
108
+ onDownload: () => i.dispatch({
109
+ name: "downloadAsset",
110
+ payload: t
111
+ })
105
112
  },
106
- e.id
113
+ t.id
107
114
  )) }) }),
108
- /* @__PURE__ */ o(Q, { children: i && /* @__PURE__ */ o(
109
- ae,
115
+ /* @__PURE__ */ n(tt, { children: l && /* @__PURE__ */ n(
116
+ gt,
110
117
  {
111
118
  isOverlay: !0,
112
- isEditing: g,
113
- item: i,
119
+ isEditing: h,
120
+ item: l,
114
121
  isDragging: !0,
115
- onDelete: () => x(i),
116
- onReplaceWithBrowse: () => C(i),
117
- onReplaceWithUpload: (e) => F(i, e)
122
+ onDelete: () => A(l),
123
+ onReplaceWithBrowse: () => E(l),
124
+ onReplaceWithUpload: (t) => L(l, t)
118
125
  },
119
- I
126
+ v
120
127
  ) })
121
128
  ]
122
129
  }
123
130
  ),
124
- g && /* @__PURE__ */ p("div", { className: "tw-px-5 tw-py-3", children: [
125
- /* @__PURE__ */ o("div", { className: "tw-font-body tw-font-medium tw-text-text tw-text-s tw-my-4", children: "Add attachments" }),
126
- /* @__PURE__ */ o(
127
- re,
131
+ h && /* @__PURE__ */ y("div", { className: "tw-px-5 tw-py-3", children: [
132
+ /* @__PURE__ */ n("div", { className: "tw-font-body tw-font-medium tw-text-text tw-text-s tw-my-4", children: "Add attachments" }),
133
+ /* @__PURE__ */ n(
134
+ ut,
128
135
  {
129
- isLoading: A,
130
- size: le.Small,
131
- onUploadClick: (e) => T(e),
132
- onLibraryClick: k
136
+ isLoading: C,
137
+ size: ht.Small,
138
+ onUploadClick: (t) => M(t),
139
+ onLibraryClick: B
133
140
  }
134
141
  )
135
142
  ] })
@@ -140,6 +147,6 @@ const ye = ({
140
147
  ) : null;
141
148
  };
142
149
  export {
143
- ye as Attachments
150
+ Dt as Attachments
144
151
  };
145
152
  //# sourceMappingURL=Attachments.es.js.map