@frontify/guideline-blocks-settings 0.29.17 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/components/Attachments/AttachmentItem.es.js +73 -79
- package/dist/components/Attachments/AttachmentItem.es.js.map +1 -1
- package/dist/components/Attachments/Attachments.es.js +103 -96
- package/dist/components/Attachments/Attachments.es.js.map +1 -1
- package/dist/components/Attachments/AttachmentsButtonTrigger.es.js +21 -0
- package/dist/components/Attachments/AttachmentsButtonTrigger.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js +47 -43
- package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js.map +1 -1
- package/dist/components/BlockItemWrapper/Toolbar/Toolbar.es.js +123 -0
- package/dist/components/BlockItemWrapper/Toolbar/Toolbar.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachments.es.js +27 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachments.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.es.js +12 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarSegment.es.js +6 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarSegment.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/helpers.es.js +26 -0
- package/dist/components/BlockItemWrapper/Toolbar/helpers.es.js.map +1 -0
- package/dist/hooks/useAttachments.es.js +43 -20
- package/dist/hooks/useAttachments.es.js.map +1 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +95 -8
- package/dist/index.es.js +176 -171
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -3
- package/src/components/Attachments/AttachmentItem.tsx +2 -13
- package/src/components/Attachments/Attachments.tsx +30 -15
- package/src/components/Attachments/AttachmentsButtonTrigger.tsx +22 -0
- package/src/components/Attachments/types.ts +10 -2
- package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +23 -20
- package/src/components/BlockItemWrapper/Toolbar/Toolbar.spec.tsx +127 -0
- package/src/components/BlockItemWrapper/Toolbar/Toolbar.tsx +133 -0
- package/src/components/BlockItemWrapper/Toolbar/ToolbarAttachments.tsx +29 -0
- package/src/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.tsx +14 -0
- package/src/components/BlockItemWrapper/Toolbar/ToolbarSegment.tsx +9 -0
- package/src/components/BlockItemWrapper/Toolbar/helpers.ts +33 -0
- package/src/components/BlockItemWrapper/Toolbar/index.ts +4 -0
- package/src/components/BlockItemWrapper/Toolbar/types.ts +38 -0
- package/src/components/BlockItemWrapper/index.ts +1 -0
- package/src/components/BlockItemWrapper/types.ts +11 -34
- package/src/hooks/{useAttachments.spec.ts → useAttachments.spec.tsx} +55 -4
- package/src/hooks/useAttachments.tsx +95 -0
- package/dist/components/BlockItemWrapper/Toolbar.es.js +0 -117
- package/dist/components/BlockItemWrapper/Toolbar.es.js.map +0 -1
- package/src/components/BlockItemWrapper/Toolbar.tsx +0 -133
- package/src/hooks/useAttachments.ts +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @frontify/guideline-blocks-settings
|
|
2
2
|
|
|
3
|
+
## 0.30.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#691](https://github.com/Frontify/brand-sdk/pull/691) [`2a2f106`](https://github.com/Frontify/brand-sdk/commit/2a2f106c0f79c7d43dfddf3d0193fa9eeb7835a3) Thanks [@SamCreasey](https://github.com/SamCreasey)! - Toolbar components and types have been made available in build
|
|
8
|
+
|
|
9
|
+
- [#692](https://github.com/Frontify/brand-sdk/pull/692) [`43866c2`](https://github.com/Frontify/brand-sdk/commit/43866c28fa470d5dbf4e61a7d42796904629fead) Thanks [@SamCreasey](https://github.com/SamCreasey)! - BlockItemToolbar: Force line-height to be 1 on toolbar items to prevent wrapping element height from being miscalculated.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`3fa74ba`](https://github.com/Frontify/brand-sdk/commit/3fa74badfedd8c52661f23e0528dc35d8a10062d)]:
|
|
12
|
+
- @frontify/app-bridge@3.0.2
|
|
13
|
+
- @frontify/sidebar-settings@0.8.3
|
|
14
|
+
|
|
15
|
+
## 0.30.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#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
|
|
20
|
+
- Add Attachments to the Toolbar component. `isFlyoutOpen`, `setIsFlyoutOpen` and `flyoutItems` props have been removed from the Toolbar and replaced
|
|
21
|
+
with a `flyoutMenu` object (`{ items: FlyoutItem[]; isOpen: boolean; onOpenChange: (isOpen: boolean)=>void }`).
|
|
22
|
+
`isFlyoutDisabled` prop has been removed.
|
|
23
|
+
`attachments` prop has been added (`{ isEnabled: boolean; isOpen: boolean; onOpenChange: (isOpen: boolean)=>void }`).
|
|
24
|
+
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`.
|
|
25
|
+
- `onAddAttachments` has been replaced with `onAttachmentsAdd` in the object returned from `useAttachments` hook.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- [#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
|
|
30
|
+
|
|
3
31
|
## 0.29.17
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -1,102 +1,96 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { useFileInput as
|
|
4
|
-
import { useSortable as
|
|
5
|
-
import { useFocusRing as
|
|
6
|
-
import { LoadingCircle as
|
|
7
|
-
import { joinClassNames as
|
|
8
|
-
const
|
|
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:
|
|
12
|
-
draggableProps:
|
|
11
|
+
isEditing: s,
|
|
12
|
+
draggableProps: c,
|
|
13
13
|
transformStyle: u,
|
|
14
14
|
isDragging: o,
|
|
15
|
-
isOverlay:
|
|
16
|
-
isLoading:
|
|
17
|
-
onDelete:
|
|
15
|
+
isOverlay: a,
|
|
16
|
+
isLoading: n,
|
|
17
|
+
onDelete: d,
|
|
18
18
|
onReplaceWithBrowse: m,
|
|
19
|
-
onReplaceWithUpload: S
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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: () =>
|
|
41
|
-
ref:
|
|
34
|
+
onClick: () => w == null ? void 0 : w(),
|
|
35
|
+
ref: k,
|
|
42
36
|
style: {
|
|
43
37
|
...u,
|
|
44
|
-
opacity: o && !
|
|
38
|
+
opacity: o && !a ? 0.3 : 1,
|
|
45
39
|
fontFamily: "var(-f-theme-settings-body-font-family)"
|
|
46
40
|
},
|
|
47
|
-
className:
|
|
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:
|
|
53
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
51
|
+
s && /* @__PURE__ */ b(
|
|
58
52
|
"div",
|
|
59
53
|
{
|
|
60
54
|
"data-test-id": "attachments-actionbar",
|
|
61
|
-
className:
|
|
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
|
-
|
|
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
|
-
...
|
|
70
|
-
...
|
|
63
|
+
...F,
|
|
64
|
+
...c,
|
|
71
65
|
"aria-label": "Drag attachment",
|
|
72
|
-
className:
|
|
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 ||
|
|
75
|
-
|
|
76
|
-
|
|
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(
|
|
72
|
+
children: /* @__PURE__ */ t(U, {})
|
|
79
73
|
}
|
|
80
74
|
),
|
|
81
75
|
/* @__PURE__ */ t("div", { "data-test-id": "attachments-actionbar-flyout", children: /* @__PURE__ */ t(
|
|
82
|
-
|
|
76
|
+
$,
|
|
83
77
|
{
|
|
84
|
-
placement:
|
|
85
|
-
isOpen: (
|
|
78
|
+
placement: O.Right,
|
|
79
|
+
isOpen: (r == null ? void 0 : r.id) === e.id,
|
|
86
80
|
fitContent: !0,
|
|
87
81
|
legacyFooter: !1,
|
|
88
|
-
onOpenChange: (
|
|
89
|
-
trigger: (
|
|
90
|
-
|
|
82
|
+
onOpenChange: (x) => i(x ? e : void 0),
|
|
83
|
+
trigger: (x, R) => /* @__PURE__ */ t(
|
|
84
|
+
T,
|
|
91
85
|
{
|
|
92
|
-
ref:
|
|
93
|
-
icon: /* @__PURE__ */ t(
|
|
94
|
-
emphasis:
|
|
95
|
-
onClick: () =>
|
|
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
|
-
|
|
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:
|
|
101
|
+
size: f.XSmall,
|
|
108
102
|
title: "Replace with upload",
|
|
109
103
|
onClick: () => {
|
|
110
|
-
C(),
|
|
104
|
+
C(), i(void 0);
|
|
111
105
|
},
|
|
112
106
|
initialValue: !0,
|
|
113
|
-
decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(
|
|
107
|
+
decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(_, {}) })
|
|
114
108
|
},
|
|
115
109
|
{
|
|
116
110
|
id: "asset",
|
|
117
|
-
size:
|
|
111
|
+
size: f.XSmall,
|
|
118
112
|
title: "Replace with asset",
|
|
119
113
|
onClick: () => {
|
|
120
|
-
m(),
|
|
114
|
+
m(), i(void 0);
|
|
121
115
|
},
|
|
122
116
|
initialValue: !0,
|
|
123
|
-
decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(
|
|
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:
|
|
126
|
+
size: f.XSmall,
|
|
133
127
|
title: "Delete",
|
|
134
|
-
style:
|
|
128
|
+
style: q.Danger,
|
|
135
129
|
onClick: () => {
|
|
136
|
-
|
|
130
|
+
d(), i(void 0);
|
|
137
131
|
},
|
|
138
132
|
initialValue: !0,
|
|
139
|
-
decorator: /* @__PURE__ */ t("div", { className: "tw-mr-2", children: /* @__PURE__ */ t(
|
|
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
|
-
|
|
157
|
-
const
|
|
158
|
-
const { attributes:
|
|
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
|
-
}),
|
|
154
|
+
}), d = {
|
|
161
155
|
transform: o ? `translate(${o.x}px, ${o.y}px)` : "",
|
|
162
|
-
transition:
|
|
163
|
-
zIndex:
|
|
164
|
-
}, m = { ...
|
|
156
|
+
transition: a,
|
|
157
|
+
zIndex: n ? 2 : 1
|
|
158
|
+
}, m = { ...s, ...c };
|
|
165
159
|
return /* @__PURE__ */ t(
|
|
166
|
-
|
|
160
|
+
y,
|
|
167
161
|
{
|
|
168
162
|
ref: u,
|
|
169
|
-
isDragging:
|
|
170
|
-
transformStyle:
|
|
163
|
+
isDragging: n,
|
|
164
|
+
transformStyle: d,
|
|
171
165
|
draggableProps: m,
|
|
172
166
|
...e
|
|
173
167
|
}
|
|
174
168
|
);
|
|
175
169
|
};
|
|
176
170
|
export {
|
|
177
|
-
|
|
178
|
-
|
|
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,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,KAEJC,MACC;AACD,UAAM,CAACC,GAAeC,CAAgB,IAAIC,EAA4B,GAChE,CAACC,GAAgB,EAAE,eAAAC,EAAA,CAAe,IAAIC,EAAa,EAAE,UAAU,IAAM,QAAQ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AA,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;AACZ,MAAIT,KACWE,EAAAF,EAAc,CAAC,CAAC;AAAA,IAC/B,GAED,CAACA,CAAa,CAAC,GAElBS,EAAU,MAAM;AACZ,MAAIL,KACoBX,EAAAU,EAAc,CAAC,CAAC;AAAA,IACxC,GAED,CAACC,GAASD,CAAa,CAAC;AAErB,UAAAO,IAAoBpB,KAAcU,KAAiB,CAACI;AAGtD,WAAA,gBAAAO;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,cAAW;AAAA,QACX,gBAAa;AAAA,QACb,SAAS,MAAMjB,KAAA,gBAAAA;AAAA,QACf,KAAAC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|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 [
|
|
20
|
-
onUploadProgress: () => !
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
+
F && (await P(b), m(!1));
|
|
29
36
|
})();
|
|
30
|
-
}, [
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
(
|
|
34
|
-
|
|
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:
|
|
45
|
+
selectedValueIds: o.map((t) => t.id)
|
|
39
46
|
}
|
|
40
47
|
);
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
async (
|
|
44
|
-
|
|
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:
|
|
55
|
+
selectedValueIds: o.map((e) => e.id)
|
|
49
56
|
}
|
|
50
57
|
);
|
|
51
|
-
},
|
|
52
|
-
u([...
|
|
53
|
-
},
|
|
54
|
-
const { active:
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
const { active:
|
|
58
|
-
if (
|
|
59
|
-
const
|
|
60
|
-
|
|
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
|
-
|
|
69
|
+
x(void 0);
|
|
63
70
|
};
|
|
64
|
-
return
|
|
65
|
-
|
|
71
|
+
return h || ((o == null ? void 0 : o.length) ?? 0) > 0 ? /* @__PURE__ */ n(
|
|
72
|
+
dt,
|
|
66
73
|
{
|
|
67
74
|
withArrow: !0,
|
|
68
|
-
position:
|
|
75
|
+
position: at.Top,
|
|
69
76
|
content: "Attachments",
|
|
70
|
-
disabled:
|
|
77
|
+
disabled: p,
|
|
71
78
|
enterDelay: 500,
|
|
72
|
-
triggerElement: /* @__PURE__ */
|
|
73
|
-
|
|
79
|
+
triggerElement: /* @__PURE__ */ n("div", { "data-test-id": "attachments-flyout-button", children: /* @__PURE__ */ n(
|
|
80
|
+
rt,
|
|
74
81
|
{
|
|
75
|
-
placement:
|
|
76
|
-
onOpenChange: (
|
|
77
|
-
isOpen:
|
|
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__ */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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:
|
|
91
|
-
collisionDetection:
|
|
92
|
-
onDragStart:
|
|
93
|
-
onDragEnd:
|
|
94
|
-
modifiers: [
|
|
93
|
+
sensors: K,
|
|
94
|
+
collisionDetection: $,
|
|
95
|
+
onDragStart: G,
|
|
96
|
+
onDragEnd: H,
|
|
97
|
+
modifiers: [et],
|
|
95
98
|
children: [
|
|
96
|
-
/* @__PURE__ */
|
|
97
|
-
|
|
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:
|
|
100
|
-
isLoading:
|
|
101
|
-
item:
|
|
102
|
-
onDelete: () =>
|
|
103
|
-
onReplaceWithBrowse: () =>
|
|
104
|
-
onReplaceWithUpload: (
|
|
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
|
-
|
|
113
|
+
t.id
|
|
107
114
|
)) }) }),
|
|
108
|
-
/* @__PURE__ */
|
|
109
|
-
|
|
115
|
+
/* @__PURE__ */ n(tt, { children: l && /* @__PURE__ */ n(
|
|
116
|
+
gt,
|
|
110
117
|
{
|
|
111
118
|
isOverlay: !0,
|
|
112
|
-
isEditing:
|
|
113
|
-
item:
|
|
119
|
+
isEditing: h,
|
|
120
|
+
item: l,
|
|
114
121
|
isDragging: !0,
|
|
115
|
-
onDelete: () =>
|
|
116
|
-
onReplaceWithBrowse: () =>
|
|
117
|
-
onReplaceWithUpload: (
|
|
122
|
+
onDelete: () => A(l),
|
|
123
|
+
onReplaceWithBrowse: () => E(l),
|
|
124
|
+
onReplaceWithUpload: (t) => L(l, t)
|
|
118
125
|
},
|
|
119
|
-
|
|
126
|
+
v
|
|
120
127
|
) })
|
|
121
128
|
]
|
|
122
129
|
}
|
|
123
130
|
),
|
|
124
|
-
|
|
125
|
-
/* @__PURE__ */
|
|
126
|
-
/* @__PURE__ */
|
|
127
|
-
|
|
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:
|
|
130
|
-
size:
|
|
131
|
-
onUploadClick: (
|
|
132
|
-
onLibraryClick:
|
|
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
|
-
|
|
150
|
+
Dt as Attachments
|
|
144
151
|
};
|
|
145
152
|
//# sourceMappingURL=Attachments.es.js.map
|