@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
@@ -1 +1 @@
1
- {"version":3,"file":"Attachments.es.js","sources":["../../../src/components/Attachments/Attachments.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useEffect, useState } from 'react';\nimport {\n DndContext,\n DragEndEvent,\n DragOverlay,\n DragStartEvent,\n KeyboardSensor,\n PointerSensor,\n closestCenter,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport { SortableContext, arrayMove, rectSortingStrategy } from '@dnd-kit/sortable';\nimport { Asset, useAssetUpload, useEditorState } from '@frontify/app-bridge';\nimport {\n AssetInput,\n AssetInputSize,\n Flyout,\n FlyoutPlacement,\n IconCaretDown12,\n IconPaperclip16,\n LegacyTooltip as Tooltip,\n TooltipPosition,\n} from '@frontify/fondue';\nimport { AttachmentItem, SortableAttachmentItem } from './AttachmentItem';\nimport { AttachmentsProps } from './types';\nimport { restrictToWindowEdges } from '@dnd-kit/modifiers';\n\nexport const Attachments = ({\n items = [],\n onDelete,\n onReplaceWithBrowse,\n onReplaceWithUpload,\n onBrowse,\n onUpload,\n onSorted,\n appBridge,\n}: AttachmentsProps) => {\n const [internalItems, setInternalItems] = useState<Asset[]>(items);\n const [isFlyoutOpen, setIsFlyoutOpen] = useState(false);\n const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor));\n const [draggedAssetId, setDraggedAssetId] = useState<number | undefined>(undefined);\n const [isUploadLoading, setIsUploadLoading] = useState(false);\n const [assetIdsLoading, setAssetIdsLoading] = useState<number[]>([]);\n const [selectedFiles, setSelectedFiles] = useState<FileList | null>(null);\n const isEditing = useEditorState(appBridge);\n\n const draggedItem = internalItems?.find((item) => item.id === draggedAssetId);\n\n const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload({\n onUploadProgress: () => !isUploadLoading && setIsUploadLoading(true),\n });\n\n useEffect(() => {\n setInternalItems(items);\n }, [items]);\n\n useEffect(() => {\n if (selectedFiles) {\n setIsUploadLoading(true);\n uploadFile(selectedFiles);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selectedFiles]);\n\n useEffect(() => {\n const uploadDone = async () => {\n if (doneAll) {\n await onUpload(uploadResults);\n setIsUploadLoading(false);\n }\n };\n uploadDone();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [doneAll, uploadResults]);\n\n const onOpenAssetChooser = () => {\n setIsFlyoutOpen(false);\n appBridge.openAssetChooser(\n (result: Asset[]) => {\n onBrowse(result);\n appBridge.closeAssetChooser();\n setIsFlyoutOpen(true);\n },\n {\n multiSelection: true,\n selectedValueIds: internalItems.map((internalItem) => internalItem.id),\n },\n );\n };\n\n const onReplaceItemWithBrowse = (toReplace: Asset) => {\n setIsFlyoutOpen(false);\n appBridge.openAssetChooser(\n async (result: Asset[]) => {\n setIsFlyoutOpen(true);\n appBridge.closeAssetChooser();\n setAssetIdsLoading([...assetIdsLoading, toReplace.id]);\n await onReplaceWithBrowse(toReplace, result[0]);\n setAssetIdsLoading(assetIdsLoading.filter((id) => id !== toReplace.id));\n },\n {\n multiSelection: false,\n selectedValueIds: internalItems.map((internalItem) => internalItem.id),\n },\n );\n };\n\n const onReplaceItemWithUpload = async (toReplace: Asset, uploadedAsset: Asset) => {\n setAssetIdsLoading([...assetIdsLoading, toReplace.id]);\n await onReplaceWithUpload(toReplace, uploadedAsset);\n setAssetIdsLoading(assetIdsLoading.filter((id) => id !== toReplace.id));\n };\n\n const handleDragStart = (event: DragStartEvent) => {\n const { active } = event;\n setDraggedAssetId(active.id as number);\n };\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n if (over && active.id !== over.id && internalItems) {\n const oldIndex = internalItems.findIndex((i) => i.id === active.id);\n const newIndex = internalItems.findIndex((i) => i.id === over.id);\n const sortedItems = arrayMove(internalItems, oldIndex, newIndex);\n setInternalItems(sortedItems);\n onSorted(sortedItems);\n }\n setDraggedAssetId(undefined);\n };\n\n return isEditing || (internalItems?.length ?? 0) > 0 ? (\n <Tooltip\n withArrow\n position={TooltipPosition.Top}\n content=\"Attachments\"\n disabled={isFlyoutOpen}\n enterDelay={500}\n triggerElement={\n <div data-test-id=\"attachments-flyout-button\">\n <Flyout\n placement={FlyoutPlacement.BottomRight}\n onOpenChange={(isOpen) => setIsFlyoutOpen(!!draggedItem ? true : isOpen)}\n isOpen={isFlyoutOpen}\n hug={false}\n fitContent\n legacyFooter={false}\n trigger={\n <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\">\n <IconPaperclip16 />\n <div>{items.length > 0 ? items.length : 'Add'}</div>\n <IconCaretDown12 />\n </div>\n }\n >\n <div className=\"tw-w-[300px]\">\n {internalItems.length > 0 && (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n modifiers={[restrictToWindowEdges]}\n >\n <SortableContext items={internalItems} strategy={rectSortingStrategy}>\n <div className=\"tw-border-b tw-border-b-line\">\n {internalItems.map((item) => (\n <SortableAttachmentItem\n isEditing={isEditing}\n isLoading={assetIdsLoading.includes(item.id)}\n key={item.id}\n item={item}\n onDelete={() => onDelete(item)}\n onReplaceWithBrowse={() => onReplaceItemWithBrowse(item)}\n onReplaceWithUpload={(uploadedAsset: Asset) =>\n onReplaceItemWithUpload(item, uploadedAsset)\n }\n />\n ))}\n </div>\n </SortableContext>\n <DragOverlay>\n {draggedItem && (\n <AttachmentItem\n isOverlay={true}\n isEditing={isEditing}\n key={draggedAssetId}\n item={draggedItem}\n isDragging={true}\n onDelete={() => onDelete(draggedItem)}\n onReplaceWithBrowse={() => onReplaceItemWithBrowse(draggedItem)}\n onReplaceWithUpload={(uploadedAsset: Asset) =>\n onReplaceItemWithUpload(draggedItem, uploadedAsset)\n }\n />\n )}\n </DragOverlay>\n </DndContext>\n )}\n {isEditing && (\n <div className=\"tw-px-5 tw-py-3\">\n <div className=\"tw-font-body tw-font-medium tw-text-text tw-text-s tw-my-4\">\n Add attachments\n </div>\n <AssetInput\n isLoading={isUploadLoading}\n size={AssetInputSize.Small}\n onUploadClick={(fileList) => setSelectedFiles(fileList)}\n onLibraryClick={onOpenAssetChooser}\n />\n </div>\n )}\n </div>\n </Flyout>\n </div>\n }\n />\n ) : null;\n};\n"],"names":["Attachments","items","onDelete","onReplaceWithBrowse","onReplaceWithUpload","onBrowse","onUpload","onSorted","appBridge","internalItems","setInternalItems","useState","isFlyoutOpen","setIsFlyoutOpen","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","draggedAssetId","setDraggedAssetId","isUploadLoading","setIsUploadLoading","assetIdsLoading","setAssetIdsLoading","selectedFiles","setSelectedFiles","isEditing","useEditorState","draggedItem","item","uploadFile","uploadResults","doneAll","useAssetUpload","useEffect","onOpenAssetChooser","result","internalItem","onReplaceItemWithBrowse","toReplace","id","onReplaceItemWithUpload","uploadedAsset","handleDragStart","event","active","handleDragEnd","over","oldIndex","i","newIndex","sortedItems","arrayMove","jsx","Tooltip","TooltipPosition","Flyout","FlyoutPlacement","isOpen","jsxs","IconPaperclip16","IconCaretDown12","DndContext","closestCenter","restrictToWindowEdges","SortableContext","rectSortingStrategy","SortableAttachmentItem","DragOverlay","AttachmentItem","AssetInput","AssetInputSize","fileList"],"mappings":";;;;;;;;AA8BO,MAAMA,KAAc,CAAC;AAAA,EACxB,OAAAC,IAAQ,CAAC;AAAA,EACT,UAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AACJ,MAAwB;AACpB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAkBV,CAAK,GAC3D,CAACW,GAAcC,CAAe,IAAIF,EAAS,EAAK,GAChDG,IAAUC,EAAWC,EAAUC,CAAa,GAAGD,EAAUE,CAAc,CAAC,GACxE,CAACC,GAAgBC,CAAiB,IAAIT,EAA6B,MAAS,GAC5E,CAACU,GAAiBC,CAAkB,IAAIX,EAAS,EAAK,GACtD,CAACY,GAAiBC,CAAkB,IAAIb,EAAmB,CAAE,CAAA,GAC7D,CAACc,GAAeC,CAAgB,IAAIf,EAA0B,IAAI,GAClEgB,IAAYC,EAAepB,CAAS,GAEpCqB,IAAcpB,KAAA,gBAAAA,EAAe,KAAK,CA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ACpC,qBAAqB,MAAMU,EAAwBV,CAAW;AAAA,sBAC9D,qBAAqB,CAACc,MAClBD,EAAwBb,GAAac,CAAa;AAAA,oBAAA;AAAA,oBANjDxB;AAAA,kBAAA,GAUjB;AAAA,gBAAA;AAAA,cAAA;AAAA,YACJ;AAAA,YAEHQ,KACG,gBAAAiC,EAAC,OAAI,EAAA,WAAU,mBACX,UAAA;AAAA,cAAC,gBAAAN,EAAA,OAAA,EAAI,WAAU,8DAA6D,UAE5E,mBAAA;AAAA,cACA,gBAAAA;AAAA,gBAACiB;AAAA,gBAAA;AAAA,kBACG,WAAWlD;AAAA,kBACX,MAAMmD,GAAe;AAAA,kBACrB,eAAe,CAACC,MAAa/C,EAAiB+C,CAAQ;AAAA,kBACtD,gBAAgBrC;AAAA,gBAAA;AAAA,cACpB;AAAA,YAAA,GACJ;AAAA,UAAA,GAER;AAAA,QAAA;AAAA,MAAA,GAER;AAAA,IAAA;AAAA,EAGR,IAAA;AACR;"}
1
+ {"version":3,"file":"Attachments.es.js","sources":["../../../src/components/Attachments/Attachments.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useEffect, useState } from 'react';\nimport {\n DndContext,\n DragEndEvent,\n DragOverlay,\n DragStartEvent,\n KeyboardSensor,\n PointerSensor,\n closestCenter,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport { restrictToWindowEdges } from '@dnd-kit/modifiers';\nimport { SortableContext, arrayMove, rectSortingStrategy } from '@dnd-kit/sortable';\nimport { Asset, useAssetUpload, useEditorState } from '@frontify/app-bridge';\nimport {\n AssetInput,\n AssetInputSize,\n Flyout,\n FlyoutPlacement,\n LegacyTooltip as Tooltip,\n TooltipPosition,\n} from '@frontify/fondue';\n\nimport { AttachmentItem, SortableAttachmentItem } from './AttachmentItem';\nimport { type AttachmentsProps } from './types';\nimport { AttachmentsButtonTrigger } from './AttachmentsButtonTrigger';\n\nexport const Attachments = ({\n items = [],\n onDelete,\n onReplaceWithBrowse,\n onReplaceWithUpload,\n onBrowse,\n onUpload,\n onSorted,\n appBridge,\n triggerComponent: TriggerComponent = AttachmentsButtonTrigger,\n isOpen,\n onOpenChange,\n}: AttachmentsProps) => {\n const [internalItems, setInternalItems] = useState<Asset[]>(items);\n const [isFlyoutOpenInternal, setIsFlyoutOpenInternal] = useState(false);\n const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor));\n const [draggedAssetId, setDraggedAssetId] = useState<number | undefined>(undefined);\n const [isUploadLoading, setIsUploadLoading] = useState(false);\n const [assetIdsLoading, setAssetIdsLoading] = useState<number[]>([]);\n const [selectedFiles, setSelectedFiles] = useState<FileList | null>(null);\n const isEditing = useEditorState(appBridge);\n const isControllingStateExternally = isOpen !== undefined;\n const isFlyoutOpen = isControllingStateExternally ? isOpen : isFlyoutOpenInternal;\n\n const draggedItem = internalItems?.find((item) => item.id === draggedAssetId);\n\n const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload({\n onUploadProgress: () => !isUploadLoading && setIsUploadLoading(true),\n });\n\n const handleFlyoutOpenChange = (isOpen: boolean) => {\n const stateSetter = isControllingStateExternally ? onOpenChange : setIsFlyoutOpenInternal;\n\n stateSetter?.(isOpen);\n };\n\n useEffect(() => {\n setInternalItems(items);\n }, [items]);\n\n useEffect(() => {\n if (selectedFiles) {\n setIsUploadLoading(true);\n uploadFile(selectedFiles);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selectedFiles]);\n\n useEffect(() => {\n const uploadDone = async () => {\n if (doneAll) {\n await onUpload(uploadResults);\n setIsUploadLoading(false);\n }\n };\n uploadDone();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [doneAll, uploadResults]);\n\n const onOpenAssetChooser = () => {\n handleFlyoutOpenChange(false);\n appBridge.openAssetChooser(\n (result: Asset[]) => {\n onBrowse(result);\n appBridge.closeAssetChooser();\n handleFlyoutOpenChange(true);\n },\n {\n multiSelection: true,\n selectedValueIds: internalItems.map((internalItem) => internalItem.id),\n },\n );\n };\n\n const onReplaceItemWithBrowse = (toReplace: Asset) => {\n handleFlyoutOpenChange(false);\n appBridge.openAssetChooser(\n async (result: Asset[]) => {\n handleFlyoutOpenChange(true);\n appBridge.closeAssetChooser();\n setAssetIdsLoading([...assetIdsLoading, toReplace.id]);\n await onReplaceWithBrowse(toReplace, result[0]);\n setAssetIdsLoading(assetIdsLoading.filter((id) => id !== toReplace.id));\n },\n {\n multiSelection: false,\n selectedValueIds: internalItems.map((internalItem) => internalItem.id),\n },\n );\n };\n\n const onReplaceItemWithUpload = async (toReplace: Asset, uploadedAsset: Asset) => {\n setAssetIdsLoading([...assetIdsLoading, toReplace.id]);\n await onReplaceWithUpload(toReplace, uploadedAsset);\n setAssetIdsLoading(assetIdsLoading.filter((id) => id !== toReplace.id));\n };\n\n const handleDragStart = (event: DragStartEvent) => {\n const { active } = event;\n setDraggedAssetId(active.id as number);\n };\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n if (over && active.id !== over.id && internalItems) {\n const oldIndex = internalItems.findIndex((i) => i.id === active.id);\n const newIndex = internalItems.findIndex((i) => i.id === over.id);\n const sortedItems = arrayMove(internalItems, oldIndex, newIndex);\n setInternalItems(sortedItems);\n onSorted(sortedItems);\n }\n setDraggedAssetId(undefined);\n };\n\n return isEditing || (internalItems?.length ?? 0) > 0 ? (\n <Tooltip\n withArrow\n position={TooltipPosition.Top}\n content=\"Attachments\"\n disabled={isFlyoutOpen}\n enterDelay={500}\n triggerElement={\n <div data-test-id=\"attachments-flyout-button\">\n <Flyout\n placement={FlyoutPlacement.BottomRight}\n onOpenChange={(isOpen) => handleFlyoutOpenChange(!!draggedItem ? true : isOpen)}\n isOpen={isFlyoutOpen}\n hug={false}\n fitContent\n legacyFooter={false}\n trigger={\n <TriggerComponent isFlyoutOpen={isFlyoutOpen}>\n <div>{items.length > 0 ? items.length : 'Add'}</div>\n </TriggerComponent>\n }\n >\n <div className=\"tw-w-[300px]\" data-test-id=\"attachments-flyout-content\">\n {internalItems.length > 0 && (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n modifiers={[restrictToWindowEdges]}\n >\n <SortableContext items={internalItems} strategy={rectSortingStrategy}>\n <div className=\"tw-border-b tw-border-b-line\">\n {internalItems.map((item) => (\n <SortableAttachmentItem\n isEditing={isEditing}\n isLoading={assetIdsLoading.includes(item.id)}\n key={item.id}\n item={item}\n onDelete={() => onDelete(item)}\n onReplaceWithBrowse={() => onReplaceItemWithBrowse(item)}\n onReplaceWithUpload={(uploadedAsset: Asset) =>\n onReplaceItemWithUpload(item, uploadedAsset)\n }\n onDownload={() =>\n appBridge.dispatch({\n name: 'downloadAsset',\n payload: item,\n })\n }\n />\n ))}\n </div>\n </SortableContext>\n <DragOverlay>\n {draggedItem && (\n <AttachmentItem\n isOverlay={true}\n isEditing={isEditing}\n key={draggedAssetId}\n item={draggedItem}\n isDragging={true}\n onDelete={() => onDelete(draggedItem)}\n onReplaceWithBrowse={() => onReplaceItemWithBrowse(draggedItem)}\n onReplaceWithUpload={(uploadedAsset: Asset) =>\n onReplaceItemWithUpload(draggedItem, uploadedAsset)\n }\n />\n )}\n </DragOverlay>\n </DndContext>\n )}\n {isEditing && (\n <div className=\"tw-px-5 tw-py-3\">\n <div className=\"tw-font-body tw-font-medium tw-text-text tw-text-s tw-my-4\">\n Add attachments\n </div>\n <AssetInput\n isLoading={isUploadLoading}\n size={AssetInputSize.Small}\n onUploadClick={(fileList) => setSelectedFiles(fileList)}\n onLibraryClick={onOpenAssetChooser}\n />\n </div>\n )}\n </div>\n </Flyout>\n </div>\n }\n />\n ) : null;\n};\n"],"names":["Attachments","items","onDelete","onReplaceWithBrowse","onReplaceWithUpload","onBrowse","onUpload","onSorted","appBridge","TriggerComponent","AttachmentsButtonTrigger","isOpen","onOpenChange","internalItems","setInternalItems","useState","isFlyoutOpenInternal","setIsFlyoutOpenInternal","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","draggedAssetId","setDraggedAssetId","isUploadLoading","setIsUploadLoading","assetIdsLoading","setAssetIdsLoading","selectedFiles","setSelectedFiles","isEditing","useEditorState","isControllingStateExternally","isFlyoutOpen","draggedItem","item","uploadFile","uploadResults","doneAll","useAssetUpload","handleFlyoutOpenChange","stateSetter","useEffect","onOpenAssetChooser","result","internalItem","onReplaceItemWithBrowse","toReplace","id","onReplaceItemWithUpload","uploadedAsset","handleDragStart","event","active","handleDragEnd","over","oldIndex","i","newIndex","sortedItems","arrayMove","jsx","Tooltip","TooltipPosition","Flyout","FlyoutPlacement","jsxs","DndContext","closestCenter","restrictToWindowEdges","SortableContext","rectSortingStrategy","SortableAttachmentItem","DragOverlay","AttachmentItem","AssetInput","AssetInputSize","fileList"],"mappings":";;;;;;;;;AA8BO,MAAMA,KAAc,CAAC;AAAA,EACxB,OAAAC,IAAQ,CAAC;AAAA,EACT,UAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,kBAAkBC,IAAmBC;AAAA,EACrC,QAAAC;AAAA,EACA,cAAAC;AACJ,MAAwB;AACpB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAkBd,CAAK,GAC3D,CAACe,GAAsBC,CAAuB,IAAIF,EAAS,EAAK,GAChEG,IAAUC,EAAWC,EAAUC,CAAa,GAAGD,EAAUE,CAAc,CAAC,GACxE,CAACC,GAAgBC,CAAiB,IAAIT,EAA6B,MAAS,GAC5E,CAACU,GAAiBC,CAAkB,IAAIX,EAAS,EAAK,GACtD,CAACY,GAAiBC,CAAkB,IAAIb,EAAmB,CAAE,CAAA,GAC7D,CAACc,GAAeC,CAAgB,IAAIf,EAA0B,IAAI,GAClEgB,IAAYC,GAAexB,CAAS,GACpCyB,IAA+BtB,MAAW,QAC1CuB,IAAeD,IAA+BtB,IAASK,GAEvDmB,IAActB,KAA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A0B,EAACY,MACI,UACGvC,KAAA,gBAAA2B;AAAA,oBAACa;AAAA,oBAAA;AAAA,sBACG,WAAW;AAAA,sBACX,WAAA5C;AAAA,sBAEA,MAAMI;AAAA,sBACN,YAAY;AAAA,sBACZ,UAAU,MAAMjC,EAASiC,CAAW;AAAA,sBACpC,qBAAqB,MAAMY,EAAwBZ,CAAW;AAAA,sBAC9D,qBAAqB,CAACgB,MAClBD,EAAwBf,GAAagB,CAAa;AAAA,oBAAA;AAAA,oBANjD5B;AAAA,kBAAA,GAUjB;AAAA,gBAAA;AAAA,cAAA;AAAA,YACJ;AAAA,YAEHQ,KACG,gBAAAoC,EAAC,OAAI,EAAA,WAAU,mBACX,UAAA;AAAA,cAAC,gBAAAL,EAAA,OAAA,EAAI,WAAU,8DAA6D,UAE5E,mBAAA;AAAA,cACA,gBAAAA;AAAA,gBAACc;AAAA,gBAAA;AAAA,kBACG,WAAWnD;AAAA,kBACX,MAAMoD,GAAe;AAAA,kBACrB,eAAe,CAACC,MAAahD,EAAiBgD,CAAQ;AAAA,kBACtD,gBAAgBlC;AAAA,gBAAA;AAAA,cACpB;AAAA,YAAA,GACJ;AAAA,UAAA,GAER;AAAA,QAAA;AAAA,MAAA,GAER;AAAA,IAAA;AAAA,EAGR,IAAA;AACR;"}
@@ -0,0 +1,21 @@
1
+ import { jsxs as o, jsx as t } from "react/jsx-runtime";
2
+ import { IconPaperclip16 as n, IconCaretDown12 as s } from "@frontify/fondue";
3
+ import { joinClassNames as i } from "../../utilities/react/joinClassNames.es.js";
4
+ const x = ({ children: e, isFlyoutOpen: r }) => /* @__PURE__ */ o(
5
+ "div",
6
+ {
7
+ className: i([
8
+ "tw-flex tw-text-[13px] tw-font-body tw-items-center tw-gap-1 tw-rounded-full tw-outline tw-outline-1 tw-outline-offset-1 tw-p-1.5 tw-outline-line",
9
+ r ? "tw-bg-box-neutral-pressed tw-text-box-neutral-inverse-pressed" : "tw-bg-base hover:tw-bg-box-neutral-hover active:tw-bg-box-neutral-pressed tw-text-box-neutral-inverse hover:tw-text-box-neutral-inverse-hover active:tw-text-box-neutral-inverse-pressed"
10
+ ]),
11
+ children: [
12
+ /* @__PURE__ */ t(n, {}),
13
+ e,
14
+ /* @__PURE__ */ t(s, {})
15
+ ]
16
+ }
17
+ );
18
+ export {
19
+ x as AttachmentsButtonTrigger
20
+ };
21
+ //# sourceMappingURL=AttachmentsButtonTrigger.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttachmentsButtonTrigger.es.js","sources":["../../../src/components/Attachments/AttachmentsButtonTrigger.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { IconCaretDown12, IconPaperclip16 } from '@frontify/fondue';\n\nimport { joinClassNames } from '../../utilities';\n\nimport { type AttachmentsTriggerProps } from './types';\n\nexport const AttachmentsButtonTrigger = ({ children, isFlyoutOpen }: AttachmentsTriggerProps) => (\n <div\n className={joinClassNames([\n 'tw-flex tw-text-[13px] tw-font-body tw-items-center tw-gap-1 tw-rounded-full tw-outline tw-outline-1 tw-outline-offset-1 tw-p-1.5 tw-outline-line',\n isFlyoutOpen\n ? 'tw-bg-box-neutral-pressed tw-text-box-neutral-inverse-pressed'\n : 'tw-bg-base hover:tw-bg-box-neutral-hover active:tw-bg-box-neutral-pressed tw-text-box-neutral-inverse hover:tw-text-box-neutral-inverse-hover active:tw-text-box-neutral-inverse-pressed',\n ])}\n >\n <IconPaperclip16 />\n {children}\n <IconCaretDown12 />\n </div>\n);\n"],"names":["AttachmentsButtonTrigger","children","isFlyoutOpen","jsxs","joinClassNames","jsx","IconPaperclip16","IconCaretDown12"],"mappings":";;;AAQO,MAAMA,IAA2B,CAAC,EAAE,UAAAC,GAAU,cAAAC,EACjD,MAAA,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,WAAWC,EAAe;AAAA,MACtB;AAAA,MACAF,IACM,kEACA;AAAA,IAAA,CACT;AAAA,IAED,UAAA;AAAA,MAAA,gBAAAG,EAACC,GAAgB,EAAA;AAAA,MAChBL;AAAA,wBACAM,GAAgB,EAAA;AAAA,IAAA;AAAA,EAAA;AACrB;"}
@@ -1,73 +1,77 @@
1
- import { jsx as l, Fragment as g, jsxs as F } from "react/jsx-runtime";
2
- import { useState as a, useRef as b, useEffect as h } from "react";
3
- import { Toolbar as j } from "./Toolbar.es.js";
4
- import { joinClassNames as c } from "../../utilities/react/joinClassNames.es.js";
5
- const R = ({
6
- children: r,
7
- toolbarFlyoutItems: p,
8
- toolbarItems: e,
9
- shouldHideWrapper: w,
10
- shouldHideComponent: n = !1,
11
- isDragging: u,
12
- shouldFillContainer: f,
13
- outlineOffset: o = 2,
14
- shouldBeShown: i = !1
1
+ import { jsx as o, Fragment as O, jsxs as b } from "react/jsx-runtime";
2
+ import { useState as p, useRef as F } from "react";
3
+ import { Toolbar as j } from "./Toolbar/Toolbar.es.js";
4
+ import { joinClassNames as r } from "../../utilities/react/joinClassNames.es.js";
5
+ const A = ({
6
+ children: i,
7
+ toolbarFlyoutItems: w,
8
+ toolbarItems: t,
9
+ shouldHideWrapper: c,
10
+ shouldHideComponent: u = !1,
11
+ isDragging: f,
12
+ shouldFillContainer: m,
13
+ outlineOffset: e = 2,
14
+ shouldBeShown: n = !1,
15
+ showAttachments: y = !1
15
16
  }) => {
16
- const [t, m] = a(i), [y, s] = a(!1), v = b(null);
17
- if (h(() => {
18
- t || s(!0);
19
- }, [t]), w)
20
- return /* @__PURE__ */ l(g, { children: r });
21
- const x = e == null ? void 0 : e.filter((d) => d !== void 0);
22
- return /* @__PURE__ */ F(
17
+ const [s, h] = p(n), [l, d] = p(!1), x = F(null);
18
+ if (c)
19
+ return /* @__PURE__ */ o(O, { children: i });
20
+ const g = t == null ? void 0 : t.filter((v) => v !== void 0), a = s || l || n;
21
+ return /* @__PURE__ */ b(
23
22
  "div",
24
23
  {
25
- ref: v,
26
- onFocus: () => s(!1),
27
- onPointerEnter: () => s(!1),
24
+ ref: x,
28
25
  "data-test-id": "block-item-wrapper",
29
26
  style: {
30
- outlineOffset: o
27
+ outlineOffset: e
31
28
  },
32
- className: c([
29
+ className: r([
33
30
  "tw-relative tw-group tw-outline-1 tw-outline-box-selected-inverse",
34
- f && "tw-flex-1 tw-h-full tw-w-full",
31
+ m && "tw-flex-1 tw-h-full tw-w-full",
35
32
  "hover:tw-outline focus-within:tw-outline",
36
- (t || i) && "tw-outline",
37
- n && "tw-opacity-0"
33
+ a && "tw-outline",
34
+ u && "tw-opacity-0"
38
35
  ]),
39
36
  children: [
40
- /* @__PURE__ */ l(
37
+ /* @__PURE__ */ o(
41
38
  "div",
42
39
  {
43
40
  style: {
44
- right: -1 - o,
45
- bottom: `calc(100% - ${2 + o}px)`
41
+ right: -1 - e,
42
+ bottom: `calc(100% - ${2 + e}px)`
46
43
  },
47
- className: c([
44
+ className: r([
48
45
  "tw-pointer-events-none tw-absolute tw-bottom-[calc(100%-4px)] tw-right-[-3px] tw-w-full tw-opacity-0 tw-z-[60]",
49
46
  "group-hover:tw-opacity-100 group-focus:tw-opacity-100 focus-within:tw-opacity-100",
50
- (t || i) && "tw-opacity-100"
47
+ "tw-flex tw-justify-end",
48
+ a && "tw-opacity-100"
51
49
  ]),
52
- children: /* @__PURE__ */ l(
50
+ children: /* @__PURE__ */ o(
53
51
  j,
54
52
  {
55
- isFlyoutOpen: t,
56
- isFlyoutDisabled: y,
57
- setIsFlyoutOpen: m,
58
- flyoutItems: p,
59
- items: x,
60
- isDragging: u
53
+ flyoutMenu: {
54
+ items: w,
55
+ isOpen: s,
56
+ onOpenChange: h
57
+ },
58
+ attachments: {
59
+ isEnabled: y,
60
+ isOpen: l,
61
+ onOpenChange: d
62
+ },
63
+ items: g,
64
+ isDragging: f
61
65
  }
62
66
  )
63
67
  }
64
68
  ),
65
- r
69
+ i
66
70
  ]
67
71
  }
68
72
  );
69
73
  };
70
74
  export {
71
- R as BlockItemWrapper
75
+ A as BlockItemWrapper
72
76
  };
73
77
  //# sourceMappingURL=BlockItemWrapper.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BlockItemWrapper.es.js","sources":["../../../src/components/BlockItemWrapper/BlockItemWrapper.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { ReactElement, useEffect, useRef, useState } from 'react';\nimport { joinClassNames } from '../../utilities';\nimport { Toolbar } from './Toolbar';\nimport { BlockItemWrapperProps, ToolbarItem } from './types';\n\nexport const BlockItemWrapper = ({\n children,\n toolbarFlyoutItems,\n toolbarItems,\n shouldHideWrapper,\n shouldHideComponent = false,\n isDragging,\n shouldFillContainer,\n outlineOffset = 2,\n shouldBeShown = false,\n}: BlockItemWrapperProps): ReactElement => {\n const [isFlyoutOpen, setIsFlyoutOpen] = useState(shouldBeShown);\n const [isFlyoutDisabled, setIsFlyoutDisabled] = useState(false);\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!isFlyoutOpen) {\n // This prevents automatic refocusing of the trigger element\n setIsFlyoutDisabled(true);\n }\n }, [isFlyoutOpen]);\n\n if (shouldHideWrapper) {\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{children}</>;\n }\n\n const items = toolbarItems?.filter((item): item is ToolbarItem => item !== undefined);\n\n return (\n <div\n ref={wrapperRef}\n onFocus={() => setIsFlyoutDisabled(false)}\n onPointerEnter={() => setIsFlyoutDisabled(false)}\n data-test-id=\"block-item-wrapper\"\n style={{\n outlineOffset,\n }}\n className={joinClassNames([\n 'tw-relative tw-group tw-outline-1 tw-outline-box-selected-inverse',\n shouldFillContainer && 'tw-flex-1 tw-h-full tw-w-full',\n 'hover:tw-outline focus-within:tw-outline',\n (isFlyoutOpen || shouldBeShown) && 'tw-outline',\n shouldHideComponent && 'tw-opacity-0',\n ])}\n >\n <div\n style={{\n right: -1 - outlineOffset,\n bottom: `calc(100% - ${2 + outlineOffset}px)`,\n }}\n className={joinClassNames([\n 'tw-pointer-events-none tw-absolute tw-bottom-[calc(100%-4px)] tw-right-[-3px] tw-w-full tw-opacity-0 tw-z-[60]',\n 'group-hover:tw-opacity-100 group-focus:tw-opacity-100 focus-within:tw-opacity-100',\n (isFlyoutOpen || shouldBeShown) && 'tw-opacity-100',\n ])}\n >\n <Toolbar\n isFlyoutOpen={isFlyoutOpen}\n isFlyoutDisabled={isFlyoutDisabled}\n setIsFlyoutOpen={setIsFlyoutOpen}\n flyoutItems={toolbarFlyoutItems}\n items={items}\n isDragging={isDragging}\n />\n </div>\n {children}\n </div>\n );\n};\n"],"names":["BlockItemWrapper","children","toolbarFlyoutItems","toolbarItems","shouldHideWrapper","shouldHideComponent","isDragging","shouldFillContainer","outlineOffset","shouldBeShown","isFlyoutOpen","setIsFlyoutOpen","useState","isFlyoutDisabled","setIsFlyoutDisabled","wrapperRef","useRef","useEffect","items","item","jsxs","joinClassNames","jsx","Toolbar"],"mappings":";;;;AAOO,MAAMA,IAAmB,CAAC;AAAA,EAC7B,UAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,cAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,qBAAAC,IAAsB;AAAA,EACtB,YAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,eAAAC,IAAgB;AAAA,EAChB,eAAAC,IAAgB;AACpB,MAA2C;AACvC,QAAM,CAACC,GAAcC,CAAe,IAAIC,EAASH,CAAa,GACxD,CAACI,GAAkBC,CAAmB,IAAIF,EAAS,EAAK,GACxDG,IAAaC,EAAuB,IAAI;AAS9C,MAPAC,EAAU,MAAM;AACZ,IAAKP,KAEDI,EAAoB,EAAI;AAAA,EAC5B,GACD,CAACJ,CAAY,CAAC,GAEbN;AAEA,kCAAU,UAAAH,EAAS,CAAA;AAGvB,QAAMiB,IAAQf,KAAA,gBAAAA,EAAc,OAAO,CAACgB,MAA8BA,MAAS;AAGvE,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,KAAKL;AAAA,MACL,SAAS,MAAMD,EAAoB,EAAK;AAAA,MACxC,gBAAgB,MAAMA,EAAoB,EAAK;AAAA,MAC/C,gBAAa;AAAA,MACb,OAAO;AAAA,QACH,eAAAN;AAAA,MACJ;AAAA,MACA,WAAWa,EAAe;AAAA,QACtB;AAAA,QACAd,KAAuB;AAAA,QACvB;AAAA,SACCG,KAAgBD,MAAkB;AAAA,QACnCJ,KAAuB;AAAA,MAAA,CAC1B;AAAA,MAED,UAAA;AAAA,QAAA,gBAAAiB;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,OAAO;AAAA,cACH,OAAO,KAAKd;AAAA,cACZ,QAAQ,eAAe,IAAIA,CAAa;AAAA,YAC5C;AAAA,YACA,WAAWa,EAAe;AAAA,cACtB;AAAA,cACA;AAAA,eACCX,KAAgBD,MAAkB;AAAA,YAAA,CACtC;AAAA,YAED,UAAA,gBAAAa;AAAA,cAACC;AAAA,cAAA;AAAA,gBACG,cAAAb;AAAA,gBACA,kBAAAG;AAAA,gBACA,iBAAAF;AAAA,gBACA,aAAaT;AAAA,gBACb,OAAAgB;AAAA,gBACA,YAAAZ;AAAA,cAAA;AAAA,YACJ;AAAA,UAAA;AAAA,QACJ;AAAA,QACCL;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGb;"}
1
+ {"version":3,"file":"BlockItemWrapper.es.js","sources":["../../../src/components/BlockItemWrapper/BlockItemWrapper.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { type ReactElement, useRef, useState } from 'react';\n\nimport { joinClassNames } from '../../utilities';\n\nimport { Toolbar, type ToolbarItem } from './Toolbar';\nimport { type BlockItemWrapperProps } from './types';\n\nexport const BlockItemWrapper = ({\n children,\n toolbarFlyoutItems,\n toolbarItems,\n shouldHideWrapper,\n shouldHideComponent = false,\n isDragging,\n shouldFillContainer,\n outlineOffset = 2,\n shouldBeShown = false,\n showAttachments = false,\n}: BlockItemWrapperProps): ReactElement => {\n const [isMenuFlyoutOpen, setIsMenuFlyoutOpen] = useState(shouldBeShown);\n const [isAttachmentFlyoutOpen, setIsAttachmentFlyoutOpen] = useState(false);\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n if (shouldHideWrapper) {\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{children}</>;\n }\n\n const items = toolbarItems?.filter((item): item is ToolbarItem => item !== undefined);\n\n const shouldToolbarBeVisible = isMenuFlyoutOpen || isAttachmentFlyoutOpen || shouldBeShown;\n\n return (\n <div\n ref={wrapperRef}\n data-test-id=\"block-item-wrapper\"\n style={{\n outlineOffset,\n }}\n className={joinClassNames([\n 'tw-relative tw-group tw-outline-1 tw-outline-box-selected-inverse',\n shouldFillContainer && 'tw-flex-1 tw-h-full tw-w-full',\n 'hover:tw-outline focus-within:tw-outline',\n shouldToolbarBeVisible && 'tw-outline',\n shouldHideComponent && 'tw-opacity-0',\n ])}\n >\n <div\n style={{\n right: -1 - outlineOffset,\n bottom: `calc(100% - ${2 + outlineOffset}px)`,\n }}\n className={joinClassNames([\n 'tw-pointer-events-none tw-absolute tw-bottom-[calc(100%-4px)] tw-right-[-3px] tw-w-full tw-opacity-0 tw-z-[60]',\n 'group-hover:tw-opacity-100 group-focus:tw-opacity-100 focus-within:tw-opacity-100',\n 'tw-flex tw-justify-end',\n shouldToolbarBeVisible && 'tw-opacity-100',\n ])}\n >\n <Toolbar\n flyoutMenu={{\n items: toolbarFlyoutItems,\n isOpen: isMenuFlyoutOpen,\n onOpenChange: setIsMenuFlyoutOpen,\n }}\n attachments={{\n isEnabled: showAttachments,\n isOpen: isAttachmentFlyoutOpen,\n onOpenChange: setIsAttachmentFlyoutOpen,\n }}\n items={items}\n isDragging={isDragging}\n />\n </div>\n {children}\n </div>\n );\n};\n"],"names":["BlockItemWrapper","children","toolbarFlyoutItems","toolbarItems","shouldHideWrapper","shouldHideComponent","isDragging","shouldFillContainer","outlineOffset","shouldBeShown","showAttachments","isMenuFlyoutOpen","setIsMenuFlyoutOpen","useState","isAttachmentFlyoutOpen","setIsAttachmentFlyoutOpen","wrapperRef","useRef","items","item","shouldToolbarBeVisible","j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BACA,aAAa;AAAA,kBACT,WAAWF;AAAA,kBACX,QAAQI;AAAA,kBACR,cAAcC;AAAA,gBAClB;AAAA,gBACA,OAAAG;AAAA,gBACA,YAAAZ;AAAA,cAAA;AAAA,YACJ;AAAA,UAAA;AAAA,QACJ;AAAA,QACCL;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGb;"}
@@ -0,0 +1,123 @@
1
+ import { jsxs as p, jsx as e } from "react/jsx-runtime";
2
+ import { LegacyTooltip as a, TooltipPosition as s, Flyout as h, IconDotsHorizontal16 as b, ActionMenu as O, MenuItemContentSize as T } from "@frontify/fondue";
3
+ import { DEFAULT_DRAGGING_TOOLTIP as v, DEFAULT_DRAG_TOOLTIP as f } from "../constants.es.js";
4
+ import { ToolbarSegment as c } from "./ToolbarSegment.es.js";
5
+ import { ToolbarAttachments as C } from "./ToolbarAttachments.es.js";
6
+ import { getToolbarButtonClassNames as d } from "./helpers.es.js";
7
+ const y = ({ items: m, flyoutMenu: r, attachments: l, isDragging: o }) => /* @__PURE__ */ p(
8
+ "div",
9
+ {
10
+ "data-test-id": "block-item-wrapper-toolbar",
11
+ className: "tw-rounded-md tw-bg-base tw-border tw-border-line-strong tw-divide-x tw-divide-line-strong tw-shadow-lg tw-flex tw-flex-none tw-items-center tw-isolate",
12
+ children: [
13
+ l.isEnabled && /* @__PURE__ */ e(c, { children: /* @__PURE__ */ e(
14
+ C,
15
+ {
16
+ isOpen: l.isOpen && !o,
17
+ onOpenChange: l.onOpenChange
18
+ }
19
+ ) }),
20
+ /* @__PURE__ */ p(c, { children: [
21
+ m.map(
22
+ (t, n) => "draggableProps" in t ? /* @__PURE__ */ e(
23
+ a,
24
+ {
25
+ withArrow: !0,
26
+ hoverDelay: 0,
27
+ enterDelay: 300,
28
+ open: o,
29
+ position: s.Top,
30
+ content: /* @__PURE__ */ e("div", { children: o ? v : t.tooltip ?? f }),
31
+ triggerElement: /* @__PURE__ */ e(
32
+ "button",
33
+ {
34
+ ref: t.setActivatorNodeRef,
35
+ "data-test-id": "block-item-wrapper-toolbar-btn",
36
+ ...t.draggableProps,
37
+ className: d("grab", o),
38
+ children: t.icon
39
+ }
40
+ )
41
+ },
42
+ n
43
+ ) : /* @__PURE__ */ e(
44
+ a,
45
+ {
46
+ withArrow: !0,
47
+ enterDelay: 300,
48
+ hoverDelay: 0,
49
+ disabled: o,
50
+ position: s.Top,
51
+ content: /* @__PURE__ */ e("div", { children: t.tooltip ?? "" }),
52
+ triggerElement: /* @__PURE__ */ e(
53
+ "button",
54
+ {
55
+ "data-test-id": "block-item-wrapper-toolbar-btn",
56
+ onClick: t.onClick,
57
+ className: d("pointer"),
58
+ children: t.icon
59
+ }
60
+ )
61
+ },
62
+ n
63
+ )
64
+ ),
65
+ r.items.length > 0 && /* @__PURE__ */ e(
66
+ a,
67
+ {
68
+ withArrow: !0,
69
+ hoverDelay: 0,
70
+ enterDelay: 300,
71
+ disabled: o || r.isOpen,
72
+ position: s.Top,
73
+ content: /* @__PURE__ */ e("div", { children: "Options" }),
74
+ triggerElement: /* @__PURE__ */ e("div", { className: "tw-flex tw-flex-shrink-0 tw-flex-1 tw-h-6 tw-relative", children: /* @__PURE__ */ e(
75
+ h,
76
+ {
77
+ isOpen: r.isOpen && !o,
78
+ legacyFooter: !1,
79
+ fitContent: !0,
80
+ hug: !1,
81
+ onOpenChange: r.onOpenChange,
82
+ trigger: /* @__PURE__ */ e(
83
+ "div",
84
+ {
85
+ "data-test-id": "block-item-wrapper-toolbar-flyout",
86
+ className: d(
87
+ "pointer",
88
+ r.isOpen && !o
89
+ ),
90
+ children: /* @__PURE__ */ e(b, {})
91
+ }
92
+ ),
93
+ children: /* @__PURE__ */ e(
94
+ O,
95
+ {
96
+ menuBlocks: r.items.map((t, n) => ({
97
+ id: n.toString(),
98
+ menuItems: t.map((i, w) => ({
99
+ id: n.toString() + w.toString(),
100
+ size: T.XSmall,
101
+ title: i.title,
102
+ style: i.style,
103
+ onClick: () => {
104
+ r.onOpenChange(!1), i.onClick();
105
+ },
106
+ initialValue: !0,
107
+ decorator: /* @__PURE__ */ e("div", { className: "tw-mr-2", children: i.icon })
108
+ }))
109
+ }))
110
+ }
111
+ )
112
+ }
113
+ ) })
114
+ }
115
+ )
116
+ ] })
117
+ ]
118
+ }
119
+ );
120
+ export {
121
+ y as Toolbar
122
+ };
123
+ //# sourceMappingURL=Toolbar.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toolbar.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/Toolbar.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport {\n ActionMenu,\n Flyout,\n IconDotsHorizontal16,\n MenuItemContentSize,\n LegacyTooltip as Tooltip,\n TooltipPosition,\n} from '@frontify/fondue';\n\nimport { DEFAULT_DRAGGING_TOOLTIP, DEFAULT_DRAG_TOOLTIP } from '../constants';\n\nimport { ToolbarSegment } from './ToolbarSegment';\nimport { ToolbarAttachments } from './ToolbarAttachments';\nimport { getToolbarButtonClassNames } from './helpers';\nimport { type ToolbarProps } from './types';\n\nexport const Toolbar = ({ items, flyoutMenu, attachments, isDragging }: ToolbarProps) => {\n return (\n <div\n data-test-id=\"block-item-wrapper-toolbar\"\n className=\"tw-rounded-md tw-bg-base tw-border tw-border-line-strong tw-divide-x tw-divide-line-strong tw-shadow-lg tw-flex tw-flex-none tw-items-center tw-isolate\"\n >\n {attachments.isEnabled && (\n <ToolbarSegment>\n <ToolbarAttachments\n isOpen={attachments.isOpen && !isDragging}\n onOpenChange={attachments.onOpenChange}\n />\n </ToolbarSegment>\n )}\n <ToolbarSegment>\n {items.map((item, i) =>\n 'draggableProps' in item ? (\n <Tooltip\n key={i}\n withArrow\n hoverDelay={0}\n enterDelay={300}\n open={isDragging}\n position={TooltipPosition.Top}\n content={\n <div>\n {isDragging ? DEFAULT_DRAGGING_TOOLTIP : item.tooltip ?? DEFAULT_DRAG_TOOLTIP}\n </div>\n }\n triggerElement={\n <button\n ref={item.setActivatorNodeRef}\n data-test-id=\"block-item-wrapper-toolbar-btn\"\n {...item.draggableProps}\n className={getToolbarButtonClassNames('grab', isDragging)}\n >\n {item.icon}\n </button>\n }\n />\n ) : (\n <Tooltip\n key={i}\n withArrow\n enterDelay={300}\n hoverDelay={0}\n disabled={isDragging}\n position={TooltipPosition.Top}\n content={<div>{item.tooltip ?? ''}</div>}\n triggerElement={\n <button\n data-test-id=\"block-item-wrapper-toolbar-btn\"\n onClick={item.onClick}\n className={getToolbarButtonClassNames('pointer')}\n >\n {item.icon}\n </button>\n }\n />\n ),\n )}\n {flyoutMenu.items.length > 0 && (\n <Tooltip\n withArrow\n hoverDelay={0}\n enterDelay={300}\n disabled={isDragging || flyoutMenu.isOpen}\n position={TooltipPosition.Top}\n content={<div>Options</div>}\n triggerElement={\n <div className=\"tw-flex tw-flex-shrink-0 tw-flex-1 tw-h-6 tw-relative\">\n <Flyout\n isOpen={flyoutMenu.isOpen && !isDragging}\n legacyFooter={false}\n fitContent\n hug={false}\n onOpenChange={flyoutMenu.onOpenChange}\n trigger={\n <div\n data-test-id=\"block-item-wrapper-toolbar-flyout\"\n className={getToolbarButtonClassNames(\n 'pointer',\n flyoutMenu.isOpen && !isDragging,\n )}\n >\n <IconDotsHorizontal16 />\n </div>\n }\n >\n <ActionMenu\n menuBlocks={flyoutMenu.items.map((block, blockIndex) => ({\n id: blockIndex.toString(),\n menuItems: block.map((item, itemIndex) => ({\n id: blockIndex.toString() + itemIndex.toString(),\n size: MenuItemContentSize.XSmall,\n title: item.title,\n style: item.style,\n onClick: () => {\n flyoutMenu.onOpenChange(false);\n item.onClick();\n },\n initialValue: true,\n decorator: <div className=\"tw-mr-2\">{item.icon}</div>,\n })),\n }))}\n />\n </Flyout>\n </div>\n }\n />\n )}\n </ToolbarSegment>\n </div>\n );\n};\n"],"names":["Toolbar","items","flyoutMenu","attachments","isDragging","jsxs","ToolbarSegment","jsx","ToolbarAttachments","item","i","Tooltip","TooltipPosition","DEFAULT_DRAGGING_T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A,wBACZ,SAAS,MAAM;AACX,0BAAAP,EAAW,aAAa,EAAK,GAC7BO,EAAK,QAAQ;AAAA,wBACjB;AAAA,wBACA,cAAc;AAAA,wBACd,WAAY,gBAAAF,EAAA,OAAA,EAAI,WAAU,WAAW,YAAK,MAAK;AAAA,sBAAA,EACjD;AAAA,oBAAA,EACJ;AAAA,kBAAA;AAAA,gBACN;AAAA,cAAA;AAAA,YAAA,GAER;AAAA,UAAA;AAAA,QAER;AAAA,MAAA,GAER;AAAA,IAAA;AAAA,EAAA;AAAA;"}
@@ -0,0 +1,27 @@
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { ToolbarAttachmentsTrigger as p } from "./ToolbarAttachmentsTrigger.es.js";
3
+ import { useAttachmentsContext as h } from "../../../hooks/useAttachments.es.js";
4
+ import { Attachments as i } from "../../Attachments/Attachments.es.js";
5
+ const f = ({ isOpen: o, onOpenChange: n }) => {
6
+ const { appBridge: r, attachments: m, onAttachmentsAdd: t, onAttachmentDelete: a, onAttachmentReplace: e, onAttachmentsSorted: c } = h();
7
+ return /* @__PURE__ */ s(
8
+ i,
9
+ {
10
+ onUpload: t,
11
+ onDelete: a,
12
+ onReplaceWithBrowse: e,
13
+ onReplaceWithUpload: e,
14
+ onSorted: c,
15
+ onBrowse: t,
16
+ items: m,
17
+ appBridge: r,
18
+ triggerComponent: p,
19
+ isOpen: o,
20
+ onOpenChange: n
21
+ }
22
+ );
23
+ };
24
+ export {
25
+ f as ToolbarAttachments
26
+ };
27
+ //# sourceMappingURL=ToolbarAttachments.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolbarAttachments.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/ToolbarAttachments.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Attachments } from '../../Attachments';\nimport { useAttachmentsContext } from '../../../hooks';\n\nimport { type ToolbarFlyoutState } from './types';\n\nimport { ToolbarAttachmentsTrigger } from './ToolbarAttachmentsTrigger';\n\nexport const ToolbarAttachments = ({ isOpen, onOpenChange }: ToolbarFlyoutState) => {\n const { appBridge, attachments, onAttachmentsAdd, onAttachmentDelete, onAttachmentReplace, onAttachmentsSorted } =\n useAttachmentsContext();\n\n return (\n <Attachments\n onUpload={onAttachmentsAdd}\n onDelete={onAttachmentDelete}\n onReplaceWithBrowse={onAttachmentReplace}\n onReplaceWithUpload={onAttachmentReplace}\n onSorted={onAttachmentsSorted}\n onBrowse={onAttachmentsAdd}\n items={attachments}\n appBridge={appBridge}\n triggerComponent={ToolbarAttachmentsTrigger}\n isOpen={isOpen}\n onOpenChange={onOpenChange}\n />\n );\n};\n"],"names":["ToolbarAttachments","isOpen","onOpenChange","appBridge","attachments","onAttachmentsAdd","onAttachmentDelete","onAttachmentReplace","onAttachmentsSorted","useAttachmentsContext","jsx","Attachments","ToolbarAttachmentsTrigger"],"mappings":";;;;AASO,MAAMA,IAAqB,CAAC,EAAE,QAAAC,GAAQ,cAAAC,QAAuC;AAC1E,QAAA,EAAE,WAAAC,GAAW,aAAAC,GAAa,kBAAAC,GAAkB,oBAAAC,GAAoB,qBAAAC,GAAqB,qBAAAC,MACvFC;AAGA,SAAA,gBAAAC;AAAA,IAACC;AAAA,IAAA;AAAA,MACG,UAAUN;AAAA,MACV,UAAUC;AAAA,MACV,qBAAqBC;AAAA,MACrB,qBAAqBA;AAAA,MACrB,UAAUC;AAAA,MACV,UAAUH;AAAA,MACV,OAAOD;AAAA,MACP,WAAAD;AAAA,MACA,kBAAkBS;AAAA,MAClB,QAAAX;AAAA,MACA,cAAAC;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
@@ -0,0 +1,12 @@
1
+ import { jsxs as e, jsx as o } from "react/jsx-runtime";
2
+ import { IconPaperclip16 as s, IconCaretDown12 as a } from "@frontify/fondue";
3
+ import { getToolbarButtonClassNames as m } from "./helpers.es.js";
4
+ const p = ({ children: r, isFlyoutOpen: t }) => /* @__PURE__ */ e("div", { className: m("pointer", t), children: [
5
+ /* @__PURE__ */ o(s, {}),
6
+ r,
7
+ /* @__PURE__ */ o(a, {})
8
+ ] });
9
+ export {
10
+ p as ToolbarAttachmentsTrigger
11
+ };
12
+ //# sourceMappingURL=ToolbarAttachmentsTrigger.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolbarAttachmentsTrigger.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { IconCaretDown12, IconPaperclip16 } from '@frontify/fondue';\nimport { type AttachmentsTriggerProps } from '../../Attachments/types';\n\nimport { getToolbarButtonClassNames } from './helpers';\n\nexport const ToolbarAttachmentsTrigger = ({ children, isFlyoutOpen }: AttachmentsTriggerProps) => (\n <div className={getToolbarButtonClassNames('pointer', isFlyoutOpen)}>\n <IconPaperclip16 />\n {children}\n <IconCaretDown12 />\n </div>\n);\n"],"names":["ToolbarAttachmentsTrigger","children","isFlyoutOpen","jsxs","getToolbarButtonClassNames","jsx","IconPaperclip16","IconCaretDown12"],"mappings":";;;AAOO,MAAMA,IAA4B,CAAC,EAAE,UAAAC,GAAU,cAAAC,EAAa,MAC9D,gBAAAC,EAAA,OAAA,EAAI,WAAWC,EAA2B,WAAWF,CAAY,GAC9D,UAAA;AAAA,EAAA,gBAAAG,EAACC,GAAgB,EAAA;AAAA,EAChBL;AAAA,oBACAM,GAAgB,EAAA;AAAA,EACrB,CAAA;"}
@@ -0,0 +1,6 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ const o = ({ children: t }) => /* @__PURE__ */ e("div", { className: "tw-pointer-events-auto tw-flex tw-flex-shrink-0 tw-gap-px tw-px-px tw-h-[26px] tw-items-center tw-self-start", children: t });
3
+ export {
4
+ o as ToolbarSegment
5
+ };
6
+ //# sourceMappingURL=ToolbarSegment.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolbarSegment.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/ToolbarSegment.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { type ReactNode } from 'react';\n\nexport const ToolbarSegment = ({ children }: { children: ReactNode }) => (\n <div className=\"tw-pointer-events-auto tw-flex tw-flex-shrink-0 tw-gap-px tw-px-px tw-h-[26px] tw-items-center tw-self-start\">\n {children}\n </div>\n);\n"],"names":["ToolbarSegment","children","jsx"],"mappings":";AAIa,MAAAA,IAAiB,CAAC,EAAE,UAAAC,QAC5B,gBAAAC,EAAA,OAAA,EAAI,WAAU,gHACV,UAAAD,EACL,CAAA;"}
@@ -0,0 +1,26 @@
1
+ import { FOCUS_VISIBLE_STYLE as s } from "@frontify/fondue";
2
+ import { joinClassNames as o } from "../../../utilities/react/joinClassNames.es.js";
3
+ const w = (e, r) => {
4
+ const t = [
5
+ s,
6
+ "tw-relative tw-inline-flex tw-items-center tw-justify-center",
7
+ "tw-h-6 tw-p-1",
8
+ "tw-rounded",
9
+ "tw-text-xs tw-font-medium",
10
+ "tw-gap-0.5",
11
+ "focus-visible:tw-z-10"
12
+ ];
13
+ return r ? t.push(
14
+ "tw-bg-box-neutral-pressed",
15
+ "tw-text-box-neutral-inverse-pressed",
16
+ e === "grab" ? "tw-cursor-grabbing" : "tw-cursor-pointer"
17
+ ) : t.push(
18
+ "hover:tw-bg-box-neutral-hover active:tw-bg-box-neutral-pressed",
19
+ "tw-text-text-weak hover:tw-text-box-neutral-inverse-hover active:tw-text-box-neutral-inverse-pressed",
20
+ e === "grab" ? "tw-cursor-grab active:tw-cursor-grabbing" : "tw-cursor-pointer"
21
+ ), o(t);
22
+ };
23
+ export {
24
+ w as getToolbarButtonClassNames
25
+ };
26
+ //# sourceMappingURL=helpers.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/helpers.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { FOCUS_VISIBLE_STYLE } from '@frontify/fondue';\n\nimport { joinClassNames } from '../../../utilities';\n\nexport const getToolbarButtonClassNames = (cursor: 'grab' | 'pointer', forceActiveStyle?: boolean) => {\n const classNames = [\n FOCUS_VISIBLE_STYLE,\n 'tw-relative tw-inline-flex tw-items-center tw-justify-center',\n 'tw-h-6 tw-p-1',\n 'tw-rounded',\n 'tw-text-xs tw-font-medium',\n 'tw-gap-0.5',\n 'focus-visible:tw-z-10',\n ];\n\n if (forceActiveStyle) {\n classNames.push(\n 'tw-bg-box-neutral-pressed',\n 'tw-text-box-neutral-inverse-pressed',\n cursor === 'grab' ? 'tw-cursor-grabbing' : 'tw-cursor-pointer',\n );\n } else {\n classNames.push(\n 'hover:tw-bg-box-neutral-hover active:tw-bg-box-neutral-pressed',\n 'tw-text-text-weak hover:tw-text-box-neutral-inverse-hover active:tw-text-box-neutral-inverse-pressed',\n cursor === 'grab' ? 'tw-cursor-grab active:tw-cursor-grabbing' : 'tw-cursor-pointer',\n );\n }\n\n return joinClassNames(classNames);\n};\n"],"names":["getToolbarButtonClassNames","cursor","forceActiveStyle","classNames","FOCUS_VISIBLE_STYLE","joinClassNames"],"mappings":";;AAMa,MAAAA,IAA6B,CAACC,GAA4BC,MAA+B;AAClG,QAAMC,IAAa;AAAA,IACfC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGJ,SAAIF,IACWC,EAAA;AAAA,IACP;AAAA,IACA;AAAA,IACAF,MAAW,SAAS,uBAAuB;AAAA,EAAA,IAGpCE,EAAA;AAAA,IACP;AAAA,IACA;AAAA,IACAF,MAAW,SAAS,6CAA6C;AAAA,EAAA,GAIlEI,EAAeF,CAAU;AACpC;"}
@@ -1,31 +1,54 @@
1
- import { useBlockAssets as m } from "@frontify/app-bridge";
2
- const l = (i, s) => {
3
- const { blockAssets: a, updateAssetIdsFromKey: o } = m(i), c = (a == null ? void 0 : a[s]) || [];
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { useBlockAssets as h } from "@frontify/app-bridge";
3
+ import { createContext as A, useContext as p } from "react";
4
+ const w = (e, n) => {
5
+ const { blockAssets: s, updateAssetIdsFromKey: o } = h(e), r = (s == null ? void 0 : s[n]) || [];
4
6
  return {
5
- onAddAttachments: async (e) => {
6
- const n = c.map((t) => t.id);
7
- for (const t of e)
8
- n.push(t.id);
9
- await o(s, n);
7
+ onAttachmentsAdd: async (a) => {
8
+ const c = r.map((t) => t.id);
9
+ for (const t of a)
10
+ c.push(t.id);
11
+ await o(n, c);
10
12
  },
11
- onAttachmentDelete: async (e) => {
12
- const n = c.filter((t) => t.id !== e.id).map((t) => t.id);
13
- await o(s, n);
13
+ onAttachmentDelete: async (a) => {
14
+ const c = r.filter((t) => t.id !== a.id).map((t) => t.id);
15
+ await o(n, c);
14
16
  },
15
- onAttachmentReplace: async (e, n) => {
16
- const t = c.map(
17
- (d) => d.id === e.id ? n.id : d.id
17
+ onAttachmentReplace: async (a, c) => {
18
+ const t = r.map(
19
+ (m) => m.id === a.id ? c.id : m.id
18
20
  );
19
- await o(s, t);
21
+ await o(n, t);
20
22
  },
21
- onAttachmentsSorted: async (e) => {
22
- const n = e.map((t) => t.id);
23
- await o(s, n);
23
+ onAttachmentsSorted: async (a) => {
24
+ const c = a.map((t) => t.id);
25
+ await o(n, c);
24
26
  },
25
- attachments: c
27
+ attachments: r,
28
+ appBridge: e
26
29
  };
30
+ }, d = A(null), u = ({
31
+ appBridge: e,
32
+ children: n,
33
+ assetId: s
34
+ }) => {
35
+ const o = w(e, s);
36
+ return /* @__PURE__ */ i(d.Provider, { value: o, children: n });
37
+ }, B = () => {
38
+ const e = p(d);
39
+ if (!e)
40
+ throw new Error(
41
+ "No AttachmentsContext Provided. Component must be wrapped in an 'AttachmentsProvider' or the 'withAttachmentsProvider' HOC"
42
+ );
43
+ return e;
44
+ }, D = (e, n) => {
45
+ const s = (o) => /* @__PURE__ */ i(u, { appBridge: o.appBridge, assetId: n, children: /* @__PURE__ */ i(e, { ...o }) });
46
+ return s.displayName = "withAttachmentsProvider", s;
27
47
  };
28
48
  export {
29
- l as useAttachments
49
+ u as AttachmentsProvider,
50
+ w as useAttachments,
51
+ B as useAttachmentsContext,
52
+ D as withAttachmentsProvider
30
53
  };
31
54
  //# sourceMappingURL=useAttachments.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAttachments.es.js","sources":["../../src/hooks/useAttachments.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { AppBridgeBlock, Asset, useBlockAssets } from '@frontify/app-bridge';\n\nexport const useAttachments = (appBridge: AppBridgeBlock, assetId: string) => {\n const { blockAssets, updateAssetIdsFromKey } = useBlockAssets(appBridge);\n const attachments = blockAssets?.[assetId] || [];\n\n const onAddAttachments = async (newAssets: Asset[]) => {\n const newAssetIds = attachments.map((attachment) => attachment.id);\n for (const asset of newAssets) {\n newAssetIds.push(asset.id);\n }\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n const onAttachmentDelete = async (assetToDelete: Asset) => {\n const newAssetIds = attachments\n .filter((attachment) => attachment.id !== assetToDelete.id)\n .map((attachment) => attachment.id);\n\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n const onAttachmentReplace = async (attachmentToReplace: Asset, newAsset: Asset) => {\n const newAssetIds = attachments.map((attachment) =>\n attachment.id === attachmentToReplace.id ? newAsset.id : attachment.id,\n );\n\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n const onAttachmentsSorted = async (assets: Asset[]) => {\n const newAssetIds = assets.map((asset) => asset.id);\n\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n return {\n onAddAttachments,\n onAttachmentDelete,\n onAttachmentReplace,\n onAttachmentsSorted,\n attachments,\n };\n};\n"],"names":["useAttachments","appBridge","assetId","blockAssets","updateAssetIdsFromKey","useBlockAssets","attachments","newAssets","newAssetIds","attachment","asset","assetToDelete","attachmentToReplace","newAsset","assets"],"mappings":";AAIa,MAAAA,IAAiB,CAACC,GAA2BC,MAAoB;AAC1E,QAAM,EAAE,aAAAC,GAAa,uBAAAC,EAAsB,IAAIC,EAAeJ,CAAS,GACjEK,KAAcH,KAAA,gBAAAA,EAAcD,OAAY,CAAA;AAgCvC,SAAA;AAAA,IACH,kBA/BqB,OAAOK,MAAuB;AACnD,YAAMC,IAAcF,EAAY,IAAI,CAACG,MAAeA,EAAW,EAAE;AACjE,iBAAWC,KAASH;AACJ,QAAAC,EAAA,KAAKE,EAAM,EAAE;AAEvB,YAAAN,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IA2BhD,oBAxBuB,OAAOG,MAAyB;AACvD,YAAMH,IAAcF,EACf,OAAO,CAACG,MAAeA,EAAW,OAAOE,EAAc,EAAE,EACzD,IAAI,CAACF,MAAeA,EAAW,EAAE;AAEhC,YAAAL,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IAoBhD,qBAjBwB,OAAOI,GAA4BC,MAAoB;AAC/E,YAAML,IAAcF,EAAY;AAAA,QAAI,CAACG,MACjCA,EAAW,OAAOG,EAAoB,KAAKC,EAAS,KAAKJ,EAAW;AAAA,MAAA;AAGlE,YAAAL,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IAahD,qBAVwB,OAAOM,MAAoB;AACnD,YAAMN,IAAcM,EAAO,IAAI,CAACJ,MAAUA,EAAM,EAAE;AAE5C,YAAAN,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IAQhD,aAAAF;AAAA,EAAA;AAER;"}
1
+ {"version":3,"file":"useAttachments.es.js","sources":["../../src/hooks/useAttachments.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { AppBridgeBlock, Asset, useBlockAssets } from '@frontify/app-bridge';\nimport { type ReactNode, createContext, useContext } from 'react';\n\nimport { type BlockProps } from '../index';\n\nexport const useAttachments = (appBridge: AppBridgeBlock, assetId: string) => {\n const { blockAssets, updateAssetIdsFromKey } = useBlockAssets(appBridge);\n const attachments = blockAssets?.[assetId] || [];\n\n const onAttachmentsAdd = async (newAssets: Asset[]) => {\n const newAssetIds = attachments.map((attachment) => attachment.id);\n for (const asset of newAssets) {\n newAssetIds.push(asset.id);\n }\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n const onAttachmentDelete = async (assetToDelete: Asset) => {\n const newAssetIds = attachments\n .filter((attachment) => attachment.id !== assetToDelete.id)\n .map((attachment) => attachment.id);\n\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n const onAttachmentReplace = async (attachmentToReplace: Asset, newAsset: Asset) => {\n const newAssetIds = attachments.map((attachment) =>\n attachment.id === attachmentToReplace.id ? newAsset.id : attachment.id,\n );\n\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n const onAttachmentsSorted = async (assets: Asset[]) => {\n const newAssetIds = assets.map((asset) => asset.id);\n\n await updateAssetIdsFromKey(assetId, newAssetIds);\n };\n\n return {\n onAttachmentsAdd,\n onAttachmentDelete,\n onAttachmentReplace,\n onAttachmentsSorted,\n attachments,\n appBridge,\n };\n};\n\nconst AttachmentsContext = createContext<ReturnType<typeof useAttachments> | null>(null);\n\nexport const AttachmentsProvider = ({\n appBridge,\n children,\n assetId,\n}: {\n appBridge: AppBridgeBlock;\n children: ReactNode;\n assetId: string;\n}) => {\n const attachmentContext = useAttachments(appBridge, assetId);\n\n return <AttachmentsContext.Provider value={attachmentContext}>{children}</AttachmentsContext.Provider>;\n};\n\nexport const useAttachmentsContext = () => {\n const context = useContext(AttachmentsContext);\n\n if (!context) {\n throw new Error(\n \"No AttachmentsContext Provided. Component must be wrapped in an 'AttachmentsProvider' or the 'withAttachmentsProvider' HOC\",\n );\n }\n\n return context;\n};\n\n/**\n * Block-level HOC for cases when there is only one attachment asset field related to the block.\n * Recommended for most cases.\n * If finer control is required over attachments, use {@link AttachmentsProvider} component.\n */\nexport const withAttachmentsProvider = <T extends BlockProps>(Component: (props: T) => ReactNode, assetId: string) => {\n const wrappedComponent = (props: T) => (\n <AttachmentsProvider appBridge={props.appBridge} assetId={assetId}>\n <Component {...props} />\n </AttachmentsProvider>\n );\n\n wrappedComponent.displayName = 'withAttachmentsProvider';\n\n return wrappedComponent;\n};\n"],"names":["useAttachments","appBridge","assetId","blockAssets","updateAssetIdsFromKey","useBlockAssets","attachments","newAssets","newAssetIds","attachment","asset","assetToDelete","attachmentToReplace","newAsset","assets","AttachmentsContext","createContext","AttachmentsProvider","children","attachmentContext","useAttachmentsContext","context","useContext","withAttachmentsProvider","Component","wrappedComponent","props","jsx"],"mappings":";;;AAOa,MAAAA,IAAiB,CAACC,GAA2BC,MAAoB;AAC1E,QAAM,EAAE,aAAAC,GAAa,uBAAAC,EAAsB,IAAIC,EAAeJ,CAAS,GACjEK,KAAcH,KAAA,gBAAAA,EAAcD,OAAY,CAAA;AAgCvC,SAAA;AAAA,IACH,kBA/BqB,OAAOK,MAAuB;AACnD,YAAMC,IAAcF,EAAY,IAAI,CAACG,MAAeA,EAAW,EAAE;AACjE,iBAAWC,KAASH;AACJ,QAAAC,EAAA,KAAKE,EAAM,EAAE;AAEvB,YAAAN,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IA2BhD,oBAxBuB,OAAOG,MAAyB;AACvD,YAAMH,IAAcF,EACf,OAAO,CAACG,MAAeA,EAAW,OAAOE,EAAc,EAAE,EACzD,IAAI,CAACF,MAAeA,EAAW,EAAE;AAEhC,YAAAL,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IAoBhD,qBAjBwB,OAAOI,GAA4BC,MAAoB;AAC/E,YAAML,IAAcF,EAAY;AAAA,QAAI,CAACG,MACjCA,EAAW,OAAOG,EAAoB,KAAKC,EAAS,KAAKJ,EAAW;AAAA,MAAA;AAGlE,YAAAL,EAAsBF,GAASM,CAAW;AAAA,IAAA;AAAA,IAahD,qBAVwB,OAAOM,MAAoB;AACnD,YAAMN,IAAcM,EAAO,IAAI,CAACJ,MAAUA,EAAM,EAAE;AA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