@frontify/guideline-blocks-settings 3.0.0 → 3.0.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/dist/components/Attachments/AttachmentItem.es.js +88 -92
- package/dist/components/Attachments/AttachmentItem.es.js.map +1 -1
- package/dist/components/Attachments/Attachments.es.js +91 -82
- package/dist/components/Attachments/Attachments.es.js.map +1 -1
- package/dist/index.cjs.js +7 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.umd.js +6 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -1,135 +1,131 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useSortable as
|
|
3
|
-
import { useFileInput as
|
|
4
|
-
import { LoadingCircle as
|
|
5
|
-
import { IconGrabHandle as
|
|
6
|
-
import {
|
|
7
|
-
import { forwardRef as q, useState as O, useEffect as x } from "react";
|
|
1
|
+
import { jsx as e, jsxs as a } from "react/jsx-runtime";
|
|
2
|
+
import { useSortable as P } from "@dnd-kit/sortable";
|
|
3
|
+
import { useFileInput as C, useAssetUpload as R } from "@frontify/app-bridge";
|
|
4
|
+
import { LoadingCircle as F, Button as v, Dropdown as s } from "@frontify/fondue/components";
|
|
5
|
+
import { IconGrabHandle as j, IconPen as k, IconArrowCircleUp as G, IconImageStack as $, IconTrashBin as E, IconImage as T, IconPlayFrame as U, IconMusicNote as q, IconDocument as B } from "@frontify/fondue/icons";
|
|
6
|
+
import { forwardRef as H, useState as L, useEffect as I } from "react";
|
|
8
7
|
import { joinClassNames as g } from "../../utilities/react/joinClassNames.es.js";
|
|
9
|
-
const
|
|
8
|
+
const M = (t) => t === "IMAGE" ? /* @__PURE__ */ e(T, { size: "24" }) : t === "VIDEO" ? /* @__PURE__ */ e(U, { size: "24" }) : t === "AUDIO" ? /* @__PURE__ */ e(q, { size: "24" }) : /* @__PURE__ */ e(B, { size: "24" }), y = H(
|
|
10
9
|
({
|
|
11
|
-
item:
|
|
12
|
-
isEditing:
|
|
13
|
-
draggableProps:
|
|
14
|
-
transformStyle:
|
|
15
|
-
isDragging:
|
|
16
|
-
isOverlay:
|
|
17
|
-
isLoading:
|
|
18
|
-
onDelete:
|
|
19
|
-
onReplaceWithBrowse:
|
|
20
|
-
onReplaceWithUpload:
|
|
21
|
-
onDownload:
|
|
22
|
-
},
|
|
23
|
-
const [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, [
|
|
27
|
-
h &&
|
|
28
|
-
}, [h,
|
|
29
|
-
const
|
|
30
|
-
return /* @__PURE__ */
|
|
10
|
+
item: t,
|
|
11
|
+
isEditing: p,
|
|
12
|
+
draggableProps: m,
|
|
13
|
+
transformStyle: u,
|
|
14
|
+
isDragging: i,
|
|
15
|
+
isOverlay: r,
|
|
16
|
+
isLoading: n,
|
|
17
|
+
onDelete: w,
|
|
18
|
+
onReplaceWithBrowse: f,
|
|
19
|
+
onReplaceWithUpload: x,
|
|
20
|
+
onDownload: z
|
|
21
|
+
}, N) => {
|
|
22
|
+
const [c, l] = L(), [A, { selectedFiles: d }] = C({ multiple: !0, accept: "image/*" }), [S, { results: b, doneAll: h }] = R();
|
|
23
|
+
I(() => {
|
|
24
|
+
d && S(d[0]);
|
|
25
|
+
}, [d]), I(() => {
|
|
26
|
+
h && x(b[0]);
|
|
27
|
+
}, [h, b]);
|
|
28
|
+
const D = n || d && !h;
|
|
29
|
+
return /* @__PURE__ */ a(
|
|
31
30
|
"button",
|
|
32
31
|
{
|
|
33
32
|
type: "button",
|
|
34
33
|
"aria-label": "Download attachment",
|
|
35
34
|
"data-test-id": "attachments-item",
|
|
36
|
-
onClick: () => !
|
|
37
|
-
ref:
|
|
35
|
+
onClick: () => !c && z?.(),
|
|
36
|
+
ref: N,
|
|
38
37
|
style: {
|
|
39
|
-
...
|
|
40
|
-
opacity:
|
|
38
|
+
...u,
|
|
39
|
+
opacity: i && !r ? 0.3 : 1,
|
|
41
40
|
fontFamily: "var(-f-theme-settings-body-font-family)"
|
|
42
41
|
},
|
|
43
42
|
className: g([
|
|
44
|
-
"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-
|
|
45
|
-
|
|
43
|
+
"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-surface-hover focus-visible:tw-outline focus-visible:!-tw-outline-offset-4",
|
|
44
|
+
i ? "tw-bg-surface-hover" : ""
|
|
46
45
|
]),
|
|
47
46
|
children: [
|
|
48
|
-
/* @__PURE__ */
|
|
49
|
-
/* @__PURE__ */
|
|
50
|
-
/* @__PURE__ */
|
|
51
|
-
/* @__PURE__ */
|
|
47
|
+
/* @__PURE__ */ e("div", { className: "tw-text-secondary group-hover:tw-text-container-secondary-on-secondary-container", children: D ? /* @__PURE__ */ e(F, { size: "small" }) : M(t.objectType) }),
|
|
48
|
+
/* @__PURE__ */ a("div", { className: "tw-text-small tw-flex-1 tw-min-w-0", children: [
|
|
49
|
+
/* @__PURE__ */ e("div", { className: "tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-secondary group-hover:tw-text-container-secondary-on-secondary-container", children: t.title }),
|
|
50
|
+
/* @__PURE__ */ e("div", { className: "tw-text-secondary", children: `${t.fileSizeHumanReadable} - ${t.extension}` })
|
|
52
51
|
] }),
|
|
53
|
-
|
|
52
|
+
p && /* @__PURE__ */ a(
|
|
54
53
|
"div",
|
|
55
54
|
{
|
|
56
55
|
"data-test-id": "attachments-actionbar",
|
|
57
56
|
className: g([
|
|
58
|
-
"tw-flex tw-gap-0.5 group-
|
|
59
|
-
|
|
57
|
+
"tw-flex tw-gap-0.5 group-hover:tw-opacity-100 group-focus-visible:tw-opacity-100 has-[:focus-visible]:tw-opacity-100",
|
|
58
|
+
r || c?.id === t.id ? "tw-opacity-100" : "tw-opacity-0"
|
|
60
59
|
]),
|
|
61
60
|
children: [
|
|
62
|
-
/* @__PURE__ */
|
|
63
|
-
|
|
61
|
+
/* @__PURE__ */ e(
|
|
62
|
+
v,
|
|
64
63
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
...w,
|
|
64
|
+
aspect: "square",
|
|
65
|
+
emphasis: "weak",
|
|
68
66
|
"aria-label": "Drag attachment",
|
|
69
67
|
className: g([
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
v && "tw-ring-4 tw-ring-blue tw-ring-offset-2 dark:tw-ring-offset-black tw-outline-none",
|
|
73
|
-
v && "tw-z-[2]"
|
|
68
|
+
i || r ? "tw-cursor-grabbing" : "tw-cursor-grab",
|
|
69
|
+
"focus-visible:tw-z-[2]"
|
|
74
70
|
]),
|
|
75
|
-
|
|
71
|
+
...m,
|
|
72
|
+
children: /* @__PURE__ */ e(j, {})
|
|
76
73
|
}
|
|
77
74
|
),
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
|
|
75
|
+
/* @__PURE__ */ e("div", { "data-test-id": "attachments-actionbar-flyout", children: /* @__PURE__ */ a(
|
|
76
|
+
s.Root,
|
|
80
77
|
{
|
|
81
|
-
open:
|
|
82
|
-
onOpenChange: (o) =>
|
|
78
|
+
open: c?.id === t.id,
|
|
79
|
+
onOpenChange: (o) => l(o ? t : void 0),
|
|
83
80
|
children: [
|
|
84
|
-
/* @__PURE__ */
|
|
85
|
-
|
|
81
|
+
/* @__PURE__ */ e(s.Trigger, { children: /* @__PURE__ */ e(
|
|
82
|
+
v,
|
|
86
83
|
{
|
|
87
84
|
aspect: "square",
|
|
88
|
-
|
|
85
|
+
emphasis: c?.id === t.id ? "default" : "weak",
|
|
89
86
|
onPress: (o) => {
|
|
90
87
|
o?.stopPropagation(), o?.preventDefault();
|
|
91
88
|
},
|
|
92
|
-
|
|
93
|
-
children: /* @__PURE__ */ t($, { size: "20" })
|
|
89
|
+
children: /* @__PURE__ */ e(k, { size: "20" })
|
|
94
90
|
}
|
|
95
91
|
) }),
|
|
96
|
-
/* @__PURE__ */
|
|
97
|
-
/* @__PURE__ */
|
|
98
|
-
/* @__PURE__ */
|
|
99
|
-
|
|
92
|
+
/* @__PURE__ */ a(s.Content, { side: "right", children: [
|
|
93
|
+
/* @__PURE__ */ a(s.Group, { children: [
|
|
94
|
+
/* @__PURE__ */ a(
|
|
95
|
+
s.Item,
|
|
100
96
|
{
|
|
101
97
|
"data-test-id": "menu-item",
|
|
102
98
|
onSelect: (o) => {
|
|
103
|
-
o?.stopPropagation(), A(),
|
|
99
|
+
o?.stopPropagation(), A(), l(void 0);
|
|
104
100
|
},
|
|
105
101
|
children: [
|
|
106
|
-
/* @__PURE__ */
|
|
102
|
+
/* @__PURE__ */ e(G, { size: "20" }),
|
|
107
103
|
"Replace with upload"
|
|
108
104
|
]
|
|
109
105
|
}
|
|
110
106
|
),
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
|
|
107
|
+
/* @__PURE__ */ a(
|
|
108
|
+
s.Item,
|
|
113
109
|
{
|
|
114
110
|
onSelect: (o) => {
|
|
115
|
-
o?.stopPropagation(),
|
|
111
|
+
o?.stopPropagation(), f(), l(void 0);
|
|
116
112
|
},
|
|
117
113
|
children: [
|
|
118
|
-
/* @__PURE__ */
|
|
114
|
+
/* @__PURE__ */ e($, { size: "20" }),
|
|
119
115
|
"Replace with asset"
|
|
120
116
|
]
|
|
121
117
|
}
|
|
122
118
|
)
|
|
123
119
|
] }),
|
|
124
|
-
/* @__PURE__ */
|
|
125
|
-
|
|
120
|
+
/* @__PURE__ */ e(s.Group, { children: /* @__PURE__ */ a(
|
|
121
|
+
s.Item,
|
|
126
122
|
{
|
|
127
123
|
emphasis: "danger",
|
|
128
124
|
onSelect: (o) => {
|
|
129
|
-
o?.stopPropagation(),
|
|
125
|
+
o?.stopPropagation(), w(), l(void 0);
|
|
130
126
|
},
|
|
131
127
|
children: [
|
|
132
|
-
/* @__PURE__ */
|
|
128
|
+
/* @__PURE__ */ e(E, { size: "20" }),
|
|
133
129
|
"Delete"
|
|
134
130
|
]
|
|
135
131
|
}
|
|
@@ -146,28 +142,28 @@ const J = (e) => e === "IMAGE" ? /* @__PURE__ */ t(B, { size: "24" }) : e === "V
|
|
|
146
142
|
);
|
|
147
143
|
}
|
|
148
144
|
);
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const { attributes:
|
|
152
|
-
id:
|
|
153
|
-
}),
|
|
154
|
-
transform:
|
|
155
|
-
transition:
|
|
156
|
-
zIndex:
|
|
157
|
-
},
|
|
158
|
-
return /* @__PURE__ */
|
|
159
|
-
|
|
145
|
+
y.displayName = "AttachmentItem";
|
|
146
|
+
const Y = (t) => {
|
|
147
|
+
const { attributes: p, listeners: m, setNodeRef: u, transform: i, transition: r, isDragging: n } = P({
|
|
148
|
+
id: t.item.id
|
|
149
|
+
}), w = {
|
|
150
|
+
transform: i ? `translate(${i.x}px, ${i.y}px)` : "",
|
|
151
|
+
transition: r,
|
|
152
|
+
zIndex: n ? 2 : 1
|
|
153
|
+
}, f = { ...p, ...m };
|
|
154
|
+
return /* @__PURE__ */ e(
|
|
155
|
+
y,
|
|
160
156
|
{
|
|
161
|
-
ref:
|
|
162
|
-
isDragging:
|
|
163
|
-
transformStyle:
|
|
164
|
-
draggableProps:
|
|
165
|
-
...
|
|
157
|
+
ref: u,
|
|
158
|
+
isDragging: n,
|
|
159
|
+
transformStyle: w,
|
|
160
|
+
draggableProps: f,
|
|
161
|
+
...t
|
|
166
162
|
}
|
|
167
163
|
);
|
|
168
164
|
};
|
|
169
165
|
export {
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
y as AttachmentItem,
|
|
167
|
+
Y as SortableAttachmentItem
|
|
172
168
|
};
|
|
173
169
|
//# 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 { useSortable } from '@dnd-kit/sortable';\nimport { type Asset, useAssetUpload, useFileInput } from '@frontify/app-bridge';\nimport { LoadingCircle, Dropdown, Button } from '@frontify/fondue/components';\nimport {\n IconArrowCircleUp,\n IconImageStack,\n IconPen,\n IconTrashBin,\n IconDocument,\n IconImage,\n IconPlayFrame,\n IconMusicNote,\n IconGrabHandle,\n} from '@frontify/fondue/icons';\nimport { useFocusRing } from '@react-aria/focus';\nimport { type MutableRefObject, forwardRef, useEffect, useState } from 'react';\n\nimport { joinClassNames } from '../../utilities';\n\nimport { type AttachmentItemProps, type SortableAttachmentItemProps } from './types';\n\nconst getDecorator = (type: string) => {\n if (type === 'IMAGE') {\n return <IconImage size=\"24\" />;\n } else if (type === 'VIDEO') {\n return <IconPlayFrame size=\"24\" />;\n } else if (type === 'AUDIO') {\n return <IconMusicNote size=\"24\" />;\n } else {\n return <IconDocument size=\"24\" />;\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\n const { focusProps, isFocusVisible } = useFocusRing();\n\n useEffect(() => {\n if (selectedFiles) {\n uploadFile(selectedFiles[0]);\n }\n // eslint-disable-next-line @eslint-react/exhaustive-deps\n }, [selectedFiles]);\n\n useEffect(() => {\n if (doneAll) {\n onReplaceWithUpload(uploadResults[0]);\n }\n // eslint-disable-next-line @eslint-react/exhaustive-deps\n }, [doneAll, uploadResults]);\n\n const showLoadingCircle = isLoading || (selectedFiles && !doneAll);\n\n return (\n <button\n type=\"button\"\n aria-label=\"Download attachment\"\n data-test-id=\"attachments-item\"\n onClick={() => !selectedAsset && 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-container-secondary-hover -tw-outline-offset-1',\n isDragging ? 'tw-bg-container-secondary-hover' : '',\n ])}\n >\n <div className=\"tw-text-secondary group-hover:tw-text-container-secondary-on-secondary-container\">\n {showLoadingCircle ? <LoadingCircle size=\"small\" /> : getDecorator(item.objectType)}\n </div>\n <div className=\"tw-text-small tw-flex-1 tw-min-w-0\">\n <div className=\"tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-secondary group-hover:tw-text-container-secondary-on-secondary-container\">\n {item.title}\n </div>\n <div className=\"tw-text-secondary\">{`${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 type=\"button\"\n {...focusProps}\n {...draggableProps}\n aria-label=\"Drag attachment\"\n className={joinClassNames([\n ' tw-border-primary tw-bg-container-secondary active:tw-bg-container-secondary-active 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-medium tw-h-9 tw-w-9 ',\n isDragging || isOverlay\n ? 'tw-cursor-grabbing tw-bg-container-secondary-active hover:tw-bg-container-secondary-active'\n : 'tw-cursor-grab hover:tw-bg-container-secondary-hover',\n isFocusVisible &&\n 'tw-ring-4 tw-ring-blue tw-ring-offset-2 dark:tw-ring-offset-black tw-outline-none',\n isFocusVisible && 'tw-z-[2]',\n ])}\n >\n <IconGrabHandle />\n </button>\n <div data-test-id=\"attachments-actionbar-flyout\">\n <Dropdown.Root\n open={selectedAsset?.id === item.id}\n onOpenChange={(isOpen) => setSelectedAsset(isOpen ? item : undefined)}\n >\n <Dropdown.Trigger>\n <Button\n aspect=\"square\"\n ref={ref as MutableRefObject<HTMLButtonElement>}\n onPress={(e) => {\n e?.stopPropagation();\n e?.preventDefault();\n }}\n emphasis=\"default\"\n >\n <IconPen size=\"20\" />\n </Button>\n </Dropdown.Trigger>\n <Dropdown.Content side=\"right\">\n <Dropdown.Group>\n <Dropdown.Item\n data-test-id=\"menu-item\"\n onSelect={(event) => {\n event?.stopPropagation();\n openFileDialog();\n setSelectedAsset(undefined);\n }}\n >\n <IconArrowCircleUp size=\"20\" />\n Replace with upload\n </Dropdown.Item>\n <Dropdown.Item\n onSelect={(event) => {\n event?.stopPropagation();\n onReplaceWithBrowse();\n setSelectedAsset(undefined);\n }}\n >\n <IconImageStack size=\"20\" />\n Replace with asset\n </Dropdown.Item>\n </Dropdown.Group>\n <Dropdown.Group>\n <Dropdown.Item\n emphasis=\"danger\"\n onSelect={(event) => {\n event?.stopPropagation();\n onDelete();\n setSelectedAsset(undefined);\n }}\n >\n <IconTrashBin size=\"20\" />\n Delete\n </Dropdown.Item>\n </Dropdown.Group>\n </Dropdown.Content>\n </Dropdown.Root>\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","jsx","IconImage","IconPlayFrame","IconMusicNote","IconDocument","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","LoadingCircle","IconGrabHandle","Dropdown","isOpen","Button","e","IconPen","event","IconArrowCircleUp","IconImageStack","IconTrashBin","SortableAttachmentItem","props","attributes","listeners","setNodeRef","transform","transition","useSortable"],"mappings":";;;;;;;;AAuBA,MAAMA,IAAe,CAACC,MACdA,MAAS,UACF,gBAAAC,EAACC,GAAA,EAAU,MAAK,KAAA,CAAK,IACrBF,MAAS,UACT,gBAAAC,EAACE,GAAA,EAAc,MAAK,KAAA,CAAK,IACzBH,MAAS,UACT,gBAAAC,EAACG,GAAA,EAAc,MAAK,KAAA,CAAK,IAEzB,gBAAAH,EAACI,GAAA,EAAa,MAAK,KAAA,CAAK,GAI1BC,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,EAAA,GAEJC,MACC;AACD,UAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAA,GACpC,CAACC,GAAgB,EAAE,eAAAC,EAAA,CAAe,IAAIC,EAAa,EAAE,UAAU,IAAM,QAAQ,WAAW,GACxF,CAACC,GAAY,EAAE,SAASC,GAAe,SAAAC,EAAA,CAAS,IAAIC,EAAA,GAEpD,EAAE,YAAAC,GAAY,gB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,EAAU,CAAC,QAAQ;AAAA,IACzE,YAAAC;AAAA,IACA,QAAQ1C,IAAa,IAAI;AAAA,EAAA,GAGvBF,IAAiB,EAAE,GAAGwC,GAAY,GAAGC,EAAA;AAE3C,SACI,gBAAAlD;AAAA,IAACK;AAAA,IAAA;AAAA,MACG,KAAK8C;AAAA,MACL,YAAAxC;AAAA,MACA,gBAAAD;AAAA,MACA,gBAAAD;AAAA,MACC,GAAGuC;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 { useSortable } from '@dnd-kit/sortable';\nimport { type Asset, useAssetUpload, useFileInput } from '@frontify/app-bridge';\nimport { LoadingCircle, Dropdown, Button } from '@frontify/fondue/components';\nimport {\n IconArrowCircleUp,\n IconImageStack,\n IconPen,\n IconTrashBin,\n IconDocument,\n IconImage,\n IconPlayFrame,\n IconMusicNote,\n IconGrabHandle,\n} from '@frontify/fondue/icons';\nimport { forwardRef, useEffect, useState } from 'react';\n\nimport { joinClassNames } from '../../utilities';\n\nimport { type AttachmentItemProps, type SortableAttachmentItemProps } from './types';\n\nconst getDecorator = (type: string) => {\n if (type === 'IMAGE') {\n return <IconImage size=\"24\" />;\n } else if (type === 'VIDEO') {\n return <IconPlayFrame size=\"24\" />;\n } else if (type === 'AUDIO') {\n return <IconMusicNote size=\"24\" />;\n } else {\n return <IconDocument size=\"24\" />;\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\n useEffect(() => {\n if (selectedFiles) {\n uploadFile(selectedFiles[0]);\n }\n // eslint-disable-next-line @eslint-react/exhaustive-deps\n }, [selectedFiles]);\n\n useEffect(() => {\n if (doneAll) {\n onReplaceWithUpload(uploadResults[0]);\n }\n // eslint-disable-next-line @eslint-react/exhaustive-deps\n }, [doneAll, uploadResults]);\n\n const showLoadingCircle = isLoading || (selectedFiles && !doneAll);\n\n return (\n <button\n type=\"button\"\n aria-label=\"Download attachment\"\n data-test-id=\"attachments-item\"\n onClick={() => !selectedAsset && 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-surface-hover focus-visible:tw-outline focus-visible:!-tw-outline-offset-4',\n isDragging ? 'tw-bg-surface-hover' : '',\n ])}\n >\n <div className=\"tw-text-secondary group-hover:tw-text-container-secondary-on-secondary-container\">\n {showLoadingCircle ? <LoadingCircle size=\"small\" /> : getDecorator(item.objectType)}\n </div>\n <div className=\"tw-text-small tw-flex-1 tw-min-w-0\">\n <div className=\"tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-secondary group-hover:tw-text-container-secondary-on-secondary-container\">\n {item.title}\n </div>\n <div className=\"tw-text-secondary\">{`${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-hover:tw-opacity-100 group-focus-visible:tw-opacity-100 has-[:focus-visible]:tw-opacity-100',\n isOverlay || selectedAsset?.id === item.id ? 'tw-opacity-100' : 'tw-opacity-0',\n ])}\n >\n <Button\n aspect=\"square\"\n emphasis=\"weak\"\n aria-label=\"Drag attachment\"\n className={joinClassNames([\n isDragging || isOverlay ? 'tw-cursor-grabbing' : 'tw-cursor-grab',\n 'focus-visible:tw-z-[2]',\n ])}\n {...draggableProps}\n >\n <IconGrabHandle />\n </Button>\n <div data-test-id=\"attachments-actionbar-flyout\">\n <Dropdown.Root\n open={selectedAsset?.id === item.id}\n onOpenChange={(isOpen) => setSelectedAsset(isOpen ? item : undefined)}\n >\n <Dropdown.Trigger>\n <Button\n aspect=\"square\"\n emphasis={selectedAsset?.id === item.id ? 'default' : 'weak'}\n onPress={(e) => {\n e?.stopPropagation();\n e?.preventDefault();\n }}\n >\n <IconPen size=\"20\" />\n </Button>\n </Dropdown.Trigger>\n <Dropdown.Content side=\"right\">\n <Dropdown.Group>\n <Dropdown.Item\n data-test-id=\"menu-item\"\n onSelect={(event) => {\n event?.stopPropagation();\n openFileDialog();\n setSelectedAsset(undefined);\n }}\n >\n <IconArrowCircleUp size=\"20\" />\n Replace with upload\n </Dropdown.Item>\n <Dropdown.Item\n onSelect={(event) => {\n event?.stopPropagation();\n onReplaceWithBrowse();\n setSelectedAsset(undefined);\n }}\n >\n <IconImageStack size=\"20\" />\n Replace with asset\n </Dropdown.Item>\n </Dropdown.Group>\n <Dropdown.Group>\n <Dropdown.Item\n emphasis=\"danger\"\n onSelect={(event) => {\n event?.stopPropagation();\n onDelete();\n setSelectedAsset(undefined);\n }}\n >\n <IconTrashBin size=\"20\" />\n Delete\n </Dropdown.Item>\n </Dropdown.Group>\n </Dropdown.Content>\n </Dropdown.Root>\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","jsx","IconImage","IconPlayFrame","IconMusicNote","IconDocument","AttachmentItem","forwardRef","item","isEditing","draggableProps","transformStyle","isDragging","isOverlay","isLoading","onDelete","onReplaceWithBrowse","onReplaceWithUpload","onDownload","ref","selectedAsset","setSelectedAsset","useState","openFileDialog","selectedFiles","useFileInput","uploadFile","uploadResults","doneAll","useAssetUpload","useEffect","showLoadingCircle","jsxs","joinClassNames","LoadingCircle","Button","IconGrabHandle","Dropdown","isOpen","e","IconPen","event","IconArrowCircleUp","IconImageStack","IconTrashBin","SortableAttachmentItem","props","attributes","listeners","setNodeRef","transform","transition","useSortable"],"mappings":";;;;;;;AAsBA,MAAMA,IAAe,CAACC,MACdA,MAAS,UACF,gBAAAC,EAACC,GAAA,EAAU,MAAK,KAAA,CAAK,IACrBF,MAAS,UACT,gBAAAC,EAACE,GAAA,EAAc,MAAK,KAAA,CAAK,IACzBH,MAAS,UACT,gBAAAC,EAACG,GAAA,EAAc,MAAK,KAAA,CAAK,IAEzB,gBAAAH,EAACI,GAAA,EAAa,MAAK,KAAA,CAAK,GAI1BC,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,EAAA,GAEJC,MACC;AACD,UAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAA,GACpC,CAACC,GAAgB,EAAE,eAAAC,EAAA,CAAe,IAAIC,EAAa,EAAE,UAAU,IAAM,QAAQ,WAAW,GACxF,CAACC,GAAY,EAAE,SAASC,GAAe,SAAAC,EAAA,CAA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C;AAAA,IACA,QAAQvC,IAAa,IAAI;AAAA,EAAA,GAGvBF,IAAiB,EAAE,GAAGqC,GAAY,GAAGC,EAAA;AAE3C,SACI,gBAAA/C;AAAA,IAACK;AAAA,IAAA;AAAA,MACG,KAAK2C;AAAA,MACL,YAAArC;AAAA,MACA,gBAAAD;AAAA,MACA,gBAAAD;AAAA,MACC,GAAGoC;AAAA,IAAA;AAAA,EAAA;AAGhB;"}
|
|
@@ -1,102 +1,103 @@
|
|
|
1
|
-
import { jsx as e, jsxs as
|
|
2
|
-
import { useSensors as
|
|
3
|
-
import {
|
|
4
|
-
import { SortableContext as
|
|
5
|
-
import { useEditorState as
|
|
6
|
-
import { AssetInput as
|
|
7
|
-
import {
|
|
8
|
-
import { useState as r, useEffect as
|
|
9
|
-
import { SortableAttachmentItem as
|
|
10
|
-
import { AttachmentsButtonTrigger as
|
|
11
|
-
const
|
|
12
|
-
items:
|
|
13
|
-
onDelete:
|
|
14
|
-
onReplaceWithBrowse:
|
|
1
|
+
import { jsx as e, jsxs as d } from "react/jsx-runtime";
|
|
2
|
+
import { useSensors as nt, useSensor as B, PointerSensor as st, KeyboardSensor as at, DndContext as rt, closestCenter as it } from "@dnd-kit/core";
|
|
3
|
+
import { restrictToParentElement as dt } from "@dnd-kit/modifiers";
|
|
4
|
+
import { SortableContext as lt, rectSortingStrategy as ct, arrayMove as ht } from "@dnd-kit/sortable";
|
|
5
|
+
import { useEditorState as pt, useAssetChooser as ut, useAssetUpload as mt } from "@frontify/app-bridge";
|
|
6
|
+
import { Flyout as I, Tooltip as y, AssetInput as s, Flex as gt } from "@frontify/fondue/components";
|
|
7
|
+
import { IconImageStack as ft, IconArrowCircleUp as wt } from "@frontify/fondue/icons";
|
|
8
|
+
import { useState as r, useEffect as S } from "react";
|
|
9
|
+
import { SortableAttachmentItem as It } from "./AttachmentItem.es.js";
|
|
10
|
+
import { AttachmentsButtonTrigger as yt } from "./AttachmentsButtonTrigger.es.js";
|
|
11
|
+
const Et = ({
|
|
12
|
+
items: l = [],
|
|
13
|
+
onDelete: M,
|
|
14
|
+
onReplaceWithBrowse: O,
|
|
15
15
|
onReplaceWithUpload: N,
|
|
16
|
-
onBrowse:
|
|
17
|
-
onUpload:
|
|
18
|
-
onSorted:
|
|
19
|
-
appBridge:
|
|
20
|
-
triggerComponent:
|
|
21
|
-
isOpen:
|
|
22
|
-
onOpenChange:
|
|
16
|
+
onBrowse: R,
|
|
17
|
+
onUpload: W,
|
|
18
|
+
onSorted: z,
|
|
19
|
+
appBridge: p,
|
|
20
|
+
triggerComponent: j = yt,
|
|
21
|
+
isOpen: A,
|
|
22
|
+
onOpenChange: K
|
|
23
23
|
}) => {
|
|
24
|
-
const [n,
|
|
25
|
-
onUploadProgress: () => !
|
|
24
|
+
const [n, v] = r(l), [V, k] = r(!1), q = nt(B(st), B(at)), [G, C] = r(void 0), [x, u] = r(!1), [m, D] = r(!1), [c, h] = r([]), [g, H] = r(null), f = pt(p), { openAssetChooser: b, closeAssetChooser: F } = ut(p), L = A !== void 0, U = L ? A : V, J = n?.find((t) => t.id === G), [Q, { results: E, doneAll: P }] = mt({
|
|
25
|
+
onUploadProgress: () => !x && u(!0)
|
|
26
26
|
}), i = (t) => {
|
|
27
|
-
(
|
|
27
|
+
(L ? K : k)?.(t);
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, [
|
|
32
|
-
|
|
33
|
-
}, [
|
|
34
|
-
(async () =>
|
|
35
|
-
}, [
|
|
36
|
-
const
|
|
37
|
-
i(!1),
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
S(() => {
|
|
30
|
+
v(l);
|
|
31
|
+
}, [l]), S(() => {
|
|
32
|
+
g && (u(!0), Q(g));
|
|
33
|
+
}, [g]), S(() => {
|
|
34
|
+
(async () => P && (await W(E), u(!1)))();
|
|
35
|
+
}, [P, E]);
|
|
36
|
+
const X = () => {
|
|
37
|
+
i(!1), b(
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
39
|
+
async (t) => {
|
|
40
|
+
F(), i(!0), D(!0), await R(t), D(!1);
|
|
40
41
|
},
|
|
41
42
|
{
|
|
42
43
|
multiSelection: !0,
|
|
43
44
|
selectedValueIds: n.map((t) => t.id)
|
|
44
45
|
}
|
|
45
46
|
);
|
|
46
|
-
},
|
|
47
|
-
i(!1),
|
|
47
|
+
}, Y = (t) => {
|
|
48
|
+
i(!1), b(
|
|
48
49
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
49
50
|
async (o) => {
|
|
50
|
-
i(!0),
|
|
51
|
+
i(!0), F(), h([...c, t.id]), await O(t, o[0]), h(c.filter((a) => a !== t.id));
|
|
51
52
|
},
|
|
52
53
|
{
|
|
53
54
|
multiSelection: !1,
|
|
54
55
|
selectedValueIds: n.map((o) => o.id)
|
|
55
56
|
}
|
|
56
57
|
);
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
},
|
|
58
|
+
}, Z = async (t, o) => {
|
|
59
|
+
h([...c, t.id]), await N(t, o), h(c.filter((a) => a !== t.id));
|
|
60
|
+
}, _ = (t) => {
|
|
60
61
|
const { active: o } = t;
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
const { active: o, over:
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
|
|
62
|
+
C(o.id);
|
|
63
|
+
}, $ = (t) => {
|
|
64
|
+
const { active: o, over: a } = t;
|
|
65
|
+
if (a && o.id !== a.id && n) {
|
|
66
|
+
const et = n.findIndex((w) => w.id === o.id), ot = n.findIndex((w) => w.id === a.id), T = ht(n, et, ot);
|
|
67
|
+
v(T), z(T);
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
-
},
|
|
69
|
+
C(void 0);
|
|
70
|
+
}, tt = {
|
|
70
71
|
onEscapeKeyDown: (t) => {
|
|
71
72
|
t.stopPropagation(), i(!1);
|
|
72
73
|
}
|
|
73
74
|
};
|
|
74
|
-
return
|
|
75
|
-
|
|
75
|
+
return f || (n?.length ?? 0) > 0 ? /* @__PURE__ */ e("div", { "data-test-id": "attachments-flyout-button", children: /* @__PURE__ */ e(
|
|
76
|
+
I.Root,
|
|
76
77
|
{
|
|
77
|
-
open:
|
|
78
|
-
onOpenChange: (t) => i(
|
|
79
|
-
children: /* @__PURE__ */
|
|
80
|
-
/* @__PURE__ */ e(
|
|
81
|
-
/* @__PURE__ */ e(
|
|
78
|
+
open: U,
|
|
79
|
+
onOpenChange: (t) => i(J ? !0 : t),
|
|
80
|
+
children: /* @__PURE__ */ d(y.Root, { enterDelay: 500, children: [
|
|
81
|
+
/* @__PURE__ */ e(y.Trigger, { asChild: !0, children: /* @__PURE__ */ e(I.Trigger, { asChild: !0, "data-test-id": "attachments-button-trigger", children: /* @__PURE__ */ e(j, { isFlyoutOpen: U, children: /* @__PURE__ */ e("div", { children: l.length > 0 ? l.length : "Add" }) }) }) }),
|
|
82
|
+
/* @__PURE__ */ e(I.Content, { side: "bottom", align: "end", width: "300px", ...tt, children: /* @__PURE__ */ d("div", { className: "tw-w-full", "data-test-id": "attachments-flyout-content", children: [
|
|
82
83
|
n.length > 0 && /* @__PURE__ */ e(
|
|
83
|
-
|
|
84
|
+
rt,
|
|
84
85
|
{
|
|
85
|
-
sensors:
|
|
86
|
-
collisionDetection:
|
|
87
|
-
onDragStart:
|
|
88
|
-
onDragEnd:
|
|
89
|
-
modifiers: [
|
|
90
|
-
children: /* @__PURE__ */ e(
|
|
91
|
-
|
|
86
|
+
sensors: q,
|
|
87
|
+
collisionDetection: it,
|
|
88
|
+
onDragStart: _,
|
|
89
|
+
onDragEnd: $,
|
|
90
|
+
modifiers: [dt],
|
|
91
|
+
children: /* @__PURE__ */ e(lt, { items: n, strategy: ct, children: /* @__PURE__ */ e("div", { className: "tw-border-b tw-border-b-line tw-relative", children: n.map((t) => /* @__PURE__ */ e(
|
|
92
|
+
It,
|
|
92
93
|
{
|
|
93
|
-
isEditing:
|
|
94
|
-
isLoading:
|
|
94
|
+
isEditing: f,
|
|
95
|
+
isLoading: c.includes(t.id),
|
|
95
96
|
item: t,
|
|
96
|
-
onDelete: () =>
|
|
97
|
-
onReplaceWithBrowse: () =>
|
|
98
|
-
onReplaceWithUpload: (o) =>
|
|
99
|
-
onDownload: () =>
|
|
97
|
+
onDelete: () => M(t),
|
|
98
|
+
onReplaceWithBrowse: () => Y(t),
|
|
99
|
+
onReplaceWithUpload: (o) => Z(t, o),
|
|
100
|
+
onDownload: () => p.dispatch({
|
|
100
101
|
name: "downloadAsset",
|
|
101
102
|
payload: t
|
|
102
103
|
})
|
|
@@ -105,25 +106,33 @@ const bt = ({
|
|
|
105
106
|
)) }) })
|
|
106
107
|
}
|
|
107
108
|
),
|
|
108
|
-
|
|
109
|
+
f && /* @__PURE__ */ d("div", { className: "tw-px-5 tw-py-3", "data-test-id": "asset-input-placeholder", children: [
|
|
109
110
|
/* @__PURE__ */ e("div", { className: "tw-font-primary tw-font-medium tw-text-primary tw-text-small tw-my-4", children: "Add attachments" }),
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
size:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
x || m ? /* @__PURE__ */ d(s.Root, { orientation: "horizontal", children: [
|
|
112
|
+
/* @__PURE__ */ e(s.Preview, { children: /* @__PURE__ */ e(s.PreviewLoading, {}) }),
|
|
113
|
+
/* @__PURE__ */ e(s.Title, { children: "Asset" }),
|
|
114
|
+
/* @__PURE__ */ e(s.Metadata, { children: /* @__PURE__ */ e(s.MetadataItem, { children: /* @__PURE__ */ d(gt, { align: "center", gap: 0.5, children: [
|
|
115
|
+
m ? /* @__PURE__ */ e(ft, { size: 16 }) : /* @__PURE__ */ e(wt, { size: 16 }),
|
|
116
|
+
m ? "Loading" : "Uploading"
|
|
117
|
+
] }) }) })
|
|
118
|
+
] }) : /* @__PURE__ */ d(s.Placeholder, { children: [
|
|
119
|
+
/* @__PURE__ */ e(
|
|
120
|
+
s.UploadInput,
|
|
121
|
+
{
|
|
122
|
+
allowMultiple: !0,
|
|
123
|
+
onSelect: (t) => H(t.target.files)
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
/* @__PURE__ */ e(s.BrowseInput, { onBrowse: X })
|
|
127
|
+
] })
|
|
119
128
|
] })
|
|
120
129
|
] }) }),
|
|
121
|
-
/* @__PURE__ */ e(
|
|
130
|
+
/* @__PURE__ */ e(y.Content, { side: "top", children: "Attachments" })
|
|
122
131
|
] })
|
|
123
132
|
}
|
|
124
133
|
) }) : null;
|
|
125
134
|
};
|
|
126
135
|
export {
|
|
127
|
-
|
|
136
|
+
Et as Attachments
|
|
128
137
|
};
|
|
129
138
|
//# sourceMappingURL=Attachments.es.js.map
|