@frontify/guideline-blocks-settings 0.27.0 → 0.28.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/.eslintrc.js +1 -1
- package/CHANGELOG.md +21 -0
- package/README.md +24 -5
- package/dist/_virtual/_commonjsHelpers.es.js +7 -0
- package/dist/_virtual/_commonjsHelpers.es.js.map +1 -0
- package/dist/_virtual/index.es.js +5 -0
- package/dist/_virtual/index.es.js.map +1 -0
- package/dist/_virtual/index.es2.js +5 -0
- package/dist/_virtual/index.es2.js.map +1 -0
- package/dist/_virtual/index.es3.js +5 -0
- package/dist/_virtual/index.es3.js.map +1 -0
- package/dist/_virtual/jsx-runtime.es.js +5 -0
- package/dist/_virtual/jsx-runtime.es.js.map +1 -0
- package/dist/_virtual/react-dom.development.es.js +5 -0
- package/dist/_virtual/react-dom.development.es.js.map +1 -0
- package/dist/_virtual/react-dom.production.min.es.js +5 -0
- package/dist/_virtual/react-dom.production.min.es.js.map +1 -0
- package/dist/_virtual/react-jsx-runtime.development.es.js +5 -0
- package/dist/_virtual/react-jsx-runtime.development.es.js.map +1 -0
- package/dist/_virtual/react-jsx-runtime.production.min.es.js +5 -0
- package/dist/_virtual/react-jsx-runtime.production.min.es.js.map +1 -0
- package/dist/_virtual/react.development.es.js +5 -0
- package/dist/_virtual/react.development.es.js.map +1 -0
- package/dist/_virtual/react.production.min.es.js +5 -0
- package/dist/_virtual/react.production.min.es.js.map +1 -0
- package/dist/_virtual/scheduler.development.es.js +5 -0
- package/dist/_virtual/scheduler.development.es.js.map +1 -0
- package/dist/_virtual/scheduler.production.min.es.js +5 -0
- package/dist/_virtual/scheduler.production.min.es.js.map +1 -0
- package/dist/components/Attachments/AttachmentItem.es.js +180 -0
- package/dist/components/Attachments/AttachmentItem.es.js.map +1 -0
- package/dist/components/Attachments/Attachments.es.js +145 -0
- package/dist/components/Attachments/Attachments.es.js.map +1 -0
- package/dist/components/BlockInjectButton/BlockInjectButton.es.js +150 -0
- package/dist/components/BlockInjectButton/BlockInjectButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js +73 -0
- package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar.es.js +113 -0
- package/dist/components/BlockItemWrapper/Toolbar.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/constants.es.js +6 -0
- package/dist/components/BlockItemWrapper/constants.es.js.map +1 -0
- package/dist/components/DownloadButton/DownloadButton.es.js +39 -0
- package/dist/components/DownloadButton/DownloadButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/RichTextEditor.es.js +42 -0
- package/dist/components/RichTextEditor/RichTextEditor.es.js.map +1 -0
- package/dist/components/RichTextEditor/SerializedText.es.js +13 -0
- package/dist/components/RichTextEditor/SerializedText.es.js.map +1 -0
- package/dist/components/RichTextEditor/constants.es.js +5 -0
- package/dist/components/RichTextEditor/constants.es.js.map +1 -0
- package/dist/components/RichTextEditor/pluginPresets/defaultPluginsWithLinkChooser.es.js +34 -0
- package/dist/components/RichTextEditor/pluginPresets/defaultPluginsWithLinkChooser.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/ButtonMarkupElementNode.es.js +54 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/ButtonMarkupElementNode.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/index.es.js +12 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/index.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonButton.es.js +17 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonToolbarButton.es.js +30 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonToolbarButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/CustomFloatingButton.es.js +16 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/CustomFloatingButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/EditButtonModal/EditModal.es.js +37 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/EditButtonModal/EditModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButton.es.js +25 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonEditButton.es.js +20 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonEditButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonUrlInput.es.js +26 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonUrlInput.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/InsertButtonModal.es.js +69 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/InsertButtonModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/useInsertModal.es.js +105 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/useInsertModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/UnlinkButton.es.js +20 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/UnlinkButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.es.js +32 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEdit.es.js +58 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEdit.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEnter.es.js +19 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEnter.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEscape.es.js +26 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEscape.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonInsert.es.js +43 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonInsert.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useVirtualFloatingButton.es.js +18 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useVirtualFloatingButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/createButtonPlugin.es.js +62 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/createButtonPlugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/insertButton.es.js +13 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/insertButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/submitFloatingButton.es.js +25 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/submitFloatingButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/unwrapButton.es.js +35 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/unwrapButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButton.es.js +86 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButtonText.es.js +24 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButtonText.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/wrapButton.es.js +19 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/transforms/wrapButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/createButtonNode.es.js +13 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/createButtonNode.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/getButtonStyle.es.js +11 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/getButtonStyle.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/getUrl.es.js +10 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/getUrl.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/styles.es.js +75 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/styles.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButton.es.js +18 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonEdit.es.js +17 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonEdit.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.es.js +14 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/withButton.es.js +53 -0
- package/dist/components/RichTextEditor/plugins/ButtonPlugin/withButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/CustomFloatingLink.es.js +19 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/CustomFloatingLink.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.es.js +37 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/useFloatingLinkEdit.es.js +53 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/useFloatingLinkEdit.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/FloatingLink.es.js +29 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/FloatingLink.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertLinkModal.es.js +8 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertLinkModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertModal.es.js +80 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useFloatingLinkInsert.es.js +40 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useFloatingLinkInsert.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useInsertModal.es.js +93 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useInsertModal.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/LinkButton.es.js +25 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/LinkButton.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/LinkMarkupElementNode.es.js +27 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/LinkMarkupElementNode.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/index.es.js +12 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/index.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/id.es.js +5 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/id.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/index.es.js +39 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/index.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/utils/getUrl.es.js +18 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/utils/getUrl.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.es.js +5 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/utils/url.es.js +17 -0
- package/dist/components/RichTextEditor/plugins/LinkPlugin/utils/url.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/custom1Plugin.es.js +45 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/custom1Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/custom2Plugin.es.js +45 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/custom2Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/custom3Plugin.es.js +45 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/custom3Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading1Plugin.es.js +46 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading1Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading2Plugin.es.js +39 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading2Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading3Plugin.es.js +39 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading3Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading4Plugin.es.js +39 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/heading4Plugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/helpers.es.js +40 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/helpers.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/imageCaptionPlugin.es.js +46 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/imageCaptionPlugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/imageTitlePlugin.es.js +46 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/imageTitlePlugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/paragraphPlugin.es.js +41 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/paragraphPlugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/quotePlugin.es.js +48 -0
- package/dist/components/RichTextEditor/plugins/TextStylePlugins/quotePlugin.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLink.es.js +68 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLink.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLinks.es.js +55 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLinks.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.es.js +62 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/PageLink.es.js +61 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/PageLink.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/PageLinks.es.js +34 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/PageLinks.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/SectionLink.es.js +26 -0
- package/dist/components/RichTextEditor/plugins/shared/LinkSelector/SectionLink.es.js.map +1 -0
- package/dist/components/RichTextEditor/plugins/styles.es.js +168 -0
- package/dist/components/RichTextEditor/plugins/styles.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/nodes/button.es.js +16 -0
- package/dist/components/RichTextEditor/serializer/nodes/button.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/nodes/checkItemNode.es.js +19 -0
- package/dist/components/RichTextEditor/serializer/nodes/checkItemNode.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/nodes/default.es.js +17 -0
- package/dist/components/RichTextEditor/serializer/nodes/default.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/nodes/link.es.js +15 -0
- package/dist/components/RichTextEditor/serializer/nodes/link.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/nodes/mentionHtmlNode.es.js +12 -0
- package/dist/components/RichTextEditor/serializer/nodes/mentionHtmlNode.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/serializeNodesToHtmlRecursive.es.js +61 -0
- package/dist/components/RichTextEditor/serializer/serializeNodesToHtmlRecursive.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/serializeToHtml.es.js +25 -0
- package/dist/components/RichTextEditor/serializer/serializeToHtml.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/utlis/reactCssPropsToCss.es.js +8 -0
- package/dist/components/RichTextEditor/serializer/utlis/reactCssPropsToCss.es.js.map +1 -0
- package/dist/components/RichTextEditor/serializer/utlis/serializeLeafToHtml.es.js +13 -0
- package/dist/components/RichTextEditor/serializer/utlis/serializeLeafToHtml.es.js.map +1 -0
- package/dist/helpers/addHttps.es.js +14 -0
- package/dist/helpers/addHttps.es.js.map +1 -0
- package/dist/helpers/convertToRichTextValue.es.js +6 -0
- package/dist/helpers/convertToRichTextValue.es.js.map +1 -0
- package/dist/helpers/customCoordinatesGetterFactory.es.js +32 -0
- package/dist/helpers/customCoordinatesGetterFactory.es.js.map +1 -0
- package/dist/helpers/hasRichTextValue.es.js +15 -0
- package/dist/helpers/hasRichTextValue.es.js.map +1 -0
- package/dist/helpers/isDownloadable.es.js +6 -0
- package/dist/helpers/isDownloadable.es.js.map +1 -0
- package/dist/helpers/mapColorPalettes.es.js +16 -0
- package/dist/helpers/mapColorPalettes.es.js.map +1 -0
- package/dist/hooks/useAttachments.es.js +31 -0
- package/dist/hooks/useAttachments.es.js.map +1 -0
- package/dist/hooks/useDndSensors.es.js +20 -0
- package/dist/hooks/useDndSensors.es.js.map +1 -0
- package/dist/index.cjs.js +252 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +816 -1
- package/dist/index.es.js +172 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +252 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/settings/background.es.js +22 -0
- package/dist/settings/background.es.js.map +1 -0
- package/dist/settings/border.es.js +61 -0
- package/dist/settings/border.es.js.map +1 -0
- package/dist/settings/borderRadius.es.js +56 -0
- package/dist/settings/borderRadius.es.js.map +1 -0
- package/dist/settings/borderRadiusExtended.es.js +64 -0
- package/dist/settings/borderRadiusExtended.es.js.map +1 -0
- package/dist/settings/defaultValues.es.js +19 -0
- package/dist/settings/defaultValues.es.js.map +1 -0
- package/dist/settings/gutter.es.js +56 -0
- package/dist/settings/gutter.es.js.map +1 -0
- package/dist/settings/margin.es.js +53 -0
- package/dist/settings/margin.es.js.map +1 -0
- package/dist/settings/marginExtended.es.js +65 -0
- package/dist/settings/marginExtended.es.js.map +1 -0
- package/dist/settings/padding.es.js +53 -0
- package/dist/settings/padding.es.js.map +1 -0
- package/dist/settings/paddingExtended.es.js +65 -0
- package/dist/settings/paddingExtended.es.js.map +1 -0
- package/dist/settings/securityDownloadable.es.js +19 -0
- package/dist/settings/securityDownloadable.es.js.map +1 -0
- package/dist/settings/securityGlobalControl.es.js +33 -0
- package/dist/settings/securityGlobalControl.es.js.map +1 -0
- package/dist/settings/types.es.js +48 -0
- package/dist/settings/types.es.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/utilities/color/getReadableColor.es.js +14 -0
- package/dist/utilities/color/getReadableColor.es.js.map +1 -0
- package/dist/utilities/color/isDark.es.js +10 -0
- package/dist/utilities/color/isDark.es.js.map +1 -0
- package/dist/utilities/color/setAlpha.es.js +6 -0
- package/dist/utilities/color/setAlpha.es.js.map +1 -0
- package/dist/utilities/color/toColorObject.es.js +9 -0
- package/dist/utilities/color/toColorObject.es.js.map +1 -0
- package/dist/utilities/color/toHex8String.es.js +7 -0
- package/dist/utilities/color/toHex8String.es.js.map +1 -0
- package/dist/utilities/color/toHexString.es.js +7 -0
- package/dist/utilities/color/toHexString.es.js.map +1 -0
- package/dist/utilities/color/toRgbaString.es.js +7 -0
- package/dist/utilities/color/toRgbaString.es.js.map +1 -0
- package/dist/utilities/color/toShortRgba.es.js +11 -0
- package/dist/utilities/color/toShortRgba.es.js.map +1 -0
- package/dist/utilities/moveItemInArray.es.js +12 -0
- package/dist/utilities/moveItemInArray.es.js.map +1 -0
- package/dist/utilities/react/getBackgroundColorStyles.es.js +8 -0
- package/dist/utilities/react/getBackgroundColorStyles.es.js.map +1 -0
- package/dist/utilities/react/getBorderStyles.es.js +12 -0
- package/dist/utilities/react/getBorderStyles.es.js.map +1 -0
- package/dist/utilities/react/getRadiusStyles.es.js +8 -0
- package/dist/utilities/react/getRadiusStyles.es.js.map +1 -0
- package/dist/utilities/react/joinClassNames.es.js +5 -0
- package/dist/utilities/react/joinClassNames.es.js.map +1 -0
- package/package.json +46 -10
- package/postcss.config.js +8 -0
- package/setupTests.ts +13 -0
- package/src/components/Attachments/AttachmentItem.tsx +257 -0
- package/src/components/Attachments/Attachments.spec.ct.tsx +151 -0
- package/src/components/Attachments/Attachments.tsx +221 -0
- package/src/components/Attachments/index.ts +4 -0
- package/src/components/Attachments/types.ts +30 -0
- package/src/components/BlockInjectButton/BlockInjectButton.spec.ct.tsx +48 -0
- package/src/components/BlockInjectButton/BlockInjectButton.tsx +212 -0
- package/src/components/BlockInjectButton/index.ts +4 -0
- package/src/components/BlockInjectButton/types.ts +18 -0
- package/src/components/BlockItemWrapper/BlockItemWrapper.spec.ct.tsx +146 -0
- package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +76 -0
- package/src/components/BlockItemWrapper/Toolbar.tsx +128 -0
- package/src/components/BlockItemWrapper/constants.ts +4 -0
- package/src/components/BlockItemWrapper/index.ts +5 -0
- package/src/components/BlockItemWrapper/types.ts +46 -0
- package/src/components/DownloadButton/DownloadButton.spec.ct.tsx +20 -0
- package/src/components/DownloadButton/DownloadButton.tsx +36 -0
- package/src/components/DownloadButton/index.ts +3 -0
- package/src/components/DownloadButton/types.ts +5 -0
- package/src/components/RichTextEditor/RichTextEditor.spec.ct.tsx +204 -0
- package/src/components/RichTextEditor/RichTextEditor.tsx +62 -0
- package/src/components/RichTextEditor/SerializedText.tsx +25 -0
- package/src/components/RichTextEditor/constants.ts +3 -0
- package/src/components/RichTextEditor/index.ts +6 -0
- package/src/components/RichTextEditor/pluginPresets/defaultPluginsWithLinkChooser.tsx +53 -0
- package/src/components/RichTextEditor/pluginPresets/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/ButtonMarkupElementNode.tsx +74 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/index.ts +11 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonButton.tsx +20 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonToolbarButton.tsx +56 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/CustomFloatingButton.tsx +19 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/EditButtonModal/EditModal.tsx +42 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButton.tsx +37 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonEditButton.tsx +22 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonUrlInput.tsx +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/InsertButtonModal.tsx +81 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/types.ts +13 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/useInsertModal.ts +143 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/UnlinkButton.tsx +31 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.ts +46 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/index.ts +12 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEdit.ts +113 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEnter.ts +21 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEscape.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonInsert.ts +71 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useVirtualFloatingButton.ts +22 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/createButtonPlugin.ts +116 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/index.ts +7 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/index.ts +8 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/insertButton.ts +17 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/submitFloatingButton.ts +40 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/unwrapButton.ts +68 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButton.ts +198 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButtonText.ts +40 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/wrapButton.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/types.ts +13 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/createButtonNode.ts +28 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getButtonStyle.ts +14 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getUrl.ts +18 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/index.ts +8 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/styles.ts +77 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButton.ts +23 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonEdit.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.ts +45 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/withButton.ts +106 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/CustomFloatingLink.tsx +26 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.tsx +43 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/useFloatingLinkEdit.ts +113 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/FloatingLink.tsx +45 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertLinkModal.tsx +5 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertModal.tsx +105 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/types.ts +16 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useFloatingLinkInsert.ts +73 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useInsertModal.ts +136 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkButton.tsx +38 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/LinkMarkupElementNode.tsx +36 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/index.ts +11 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/id.ts +3 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/index.ts +48 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/types.ts +12 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/getUrl.ts +30 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.spec.ts +35 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.ts +3 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.spec.ts +75 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.ts +21 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom1Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom2Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom3Plugin.tsx +62 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading1Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading2Plugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading3Plugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading4Plugin.tsx +59 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/helpers.tsx +44 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/imageCaptionPlugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/imageTitlePlugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/index.ts +15 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/paragraphPlugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/quotePlugin.tsx +62 -0
- package/src/components/RichTextEditor/plugins/index.ts +6 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLink.tsx +80 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLinks.tsx +97 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.spec.ct.tsx +138 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.tsx +80 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLink.tsx +83 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLinks.tsx +68 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/SectionLink.tsx +37 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/styles.ts +179 -0
- package/src/components/RichTextEditor/serializer/index.ts +3 -0
- package/src/components/RichTextEditor/serializer/nodes/button.ts +25 -0
- package/src/components/RichTextEditor/serializer/nodes/checkItemNode.ts +29 -0
- package/src/components/RichTextEditor/serializer/nodes/default.ts +52 -0
- package/src/components/RichTextEditor/serializer/nodes/link.ts +25 -0
- package/src/components/RichTextEditor/serializer/nodes/mentionHtmlNode.ts +17 -0
- package/src/components/RichTextEditor/serializer/serializeNodesToHtmlRecursive.ts +134 -0
- package/src/components/RichTextEditor/serializer/serializeToHtml.ts +49 -0
- package/src/components/RichTextEditor/serializer/utlis/reactCssPropsToCss.ts +21 -0
- package/src/components/RichTextEditor/serializer/utlis/serializeLeafToHtml.ts +32 -0
- package/src/components/RichTextEditor/types.ts +23 -0
- package/src/components/index.ts +7 -0
- package/src/helpers/addHttps.spec.ts +42 -0
- package/src/helpers/addHttps.ts +15 -0
- package/src/helpers/convertToRichTextValue.spec.ts +32 -0
- package/src/helpers/convertToRichTextValue.ts +6 -0
- package/src/helpers/customCoordinatesGetterFactory.spec.ts +69 -0
- package/src/helpers/customCoordinatesGetterFactory.ts +39 -0
- package/src/helpers/hasRichTextValue.spec.ts +63 -0
- package/src/helpers/hasRichTextValue.ts +29 -0
- package/src/helpers/index.ts +8 -0
- package/src/helpers/isDownloadable.spec.ts +47 -0
- package/src/helpers/isDownloadable.ts +7 -0
- package/src/helpers/mapColorPalettes.spec.ts +146 -0
- package/src/helpers/mapColorPalettes.ts +22 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAttachments.spec.ts +79 -0
- package/src/hooks/useAttachments.ts +46 -0
- package/src/hooks/useDndSensors.spec.ts +40 -0
- package/src/hooks/useDndSensors.ts +23 -0
- package/src/index.ts +8 -0
- package/src/settings/background.spec.ts +173 -0
- package/src/settings/background.ts +49 -0
- package/src/settings/border.spec.ts +76 -0
- package/src/settings/border.ts +90 -0
- package/src/settings/borderRadius.spec.ts +30 -0
- package/src/settings/borderRadius.ts +73 -0
- package/src/settings/borderRadiusExtended.spec.ts +52 -0
- package/src/settings/borderRadiusExtended.ts +84 -0
- package/src/settings/defaultValues.ts +21 -0
- package/src/settings/gutter.spec.ts +60 -0
- package/src/settings/gutter.ts +75 -0
- package/src/settings/index.ts +14 -0
- package/src/settings/margin.spec.ts +42 -0
- package/src/settings/margin.ts +72 -0
- package/src/settings/marginExtended.spec.ts +45 -0
- package/src/settings/marginExtended.ts +91 -0
- package/src/settings/padding.spec.ts +42 -0
- package/src/settings/padding.ts +73 -0
- package/src/settings/paddingExtended.spec.ts +45 -0
- package/src/settings/paddingExtended.ts +91 -0
- package/src/settings/security.spec.ts +87 -0
- package/src/settings/security.ts +61 -0
- package/src/settings/securityDownloadable.spec.ts +46 -0
- package/src/settings/securityDownloadable.ts +33 -0
- package/src/settings/securityGlobalControl.ts +42 -0
- package/src/settings/types.ts +128 -0
- package/src/utilities/color/getReadableColor.spec.ts +32 -0
- package/src/utilities/color/getReadableColor.ts +34 -0
- package/src/utilities/color/index.ts +10 -0
- package/src/utilities/color/isDark.spec.ts +33 -0
- package/src/utilities/color/isDark.ts +29 -0
- package/src/utilities/color/setAlpha.spec.ts +28 -0
- package/src/utilities/color/setAlpha.ts +14 -0
- package/src/utilities/color/toColorObject.spec.ts +19 -0
- package/src/utilities/color/toColorObject.ts +16 -0
- package/src/utilities/color/toHex8String.spec.ts +17 -0
- package/src/utilities/color/toHex8String.ts +14 -0
- package/src/utilities/color/toHexString.spec.ts +17 -0
- package/src/utilities/color/toHexString.ts +10 -0
- package/src/utilities/color/toRgbaString.spec.ts +12 -0
- package/src/utilities/color/toRgbaString.ts +14 -0
- package/src/utilities/color/toShortRgba.spec.ts +16 -0
- package/src/utilities/color/toShortRgba.ts +35 -0
- package/src/utilities/index.ts +5 -0
- package/src/utilities/moveItemInArray.spec.ts +17 -0
- package/src/utilities/moveItemInArray.ts +21 -0
- package/src/utilities/react/getBackgroundColorStyles.spec.ts +18 -0
- package/src/utilities/react/getBackgroundColorStyles.ts +11 -0
- package/src/utilities/react/getBorderStyles.spec.ts +39 -0
- package/src/utilities/react/getBorderStyles.ts +21 -0
- package/src/utilities/react/getRadiusStyles.spec.ts +25 -0
- package/src/utilities/react/getRadiusStyles.ts +8 -0
- package/src/utilities/react/index.ts +6 -0
- package/src/utilities/react/joinClassNames.spec.ts +18 -0
- package/src/utilities/react/joinClassNames.ts +10 -0
- package/tailwind.config.js +27 -0
- package/tsconfig.json +3 -1
- package/vite.config.ts +11 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { MutableRefObject, forwardRef, useEffect, useState } from 'react';
|
|
4
|
+
import { Asset, useAssetUpload, useFileInput } from '@frontify/app-bridge';
|
|
5
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
6
|
+
import { useFocusRing } from '@react-aria/focus';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ActionMenu,
|
|
10
|
+
Button,
|
|
11
|
+
ButtonEmphasis,
|
|
12
|
+
FOCUS_STYLE,
|
|
13
|
+
Flyout,
|
|
14
|
+
FlyoutPlacement,
|
|
15
|
+
IconArrowCircleUp20,
|
|
16
|
+
IconDocument24,
|
|
17
|
+
IconGrabHandle20,
|
|
18
|
+
IconImage24,
|
|
19
|
+
IconImageStack20,
|
|
20
|
+
IconMusicNote24,
|
|
21
|
+
IconPen20,
|
|
22
|
+
IconPlayFrame24,
|
|
23
|
+
IconTrashBin20,
|
|
24
|
+
LoadingCircle,
|
|
25
|
+
LoadingCircleSize,
|
|
26
|
+
MenuItemContentSize,
|
|
27
|
+
MenuItemStyle,
|
|
28
|
+
} from '@frontify/fondue';
|
|
29
|
+
import { AttachmentItemProps, SortableAttachmentItemProps } from './types';
|
|
30
|
+
import { joinClassNames } from '../../utilities';
|
|
31
|
+
|
|
32
|
+
const getDecorator = (type: string) => {
|
|
33
|
+
if (type === 'IMAGE') {
|
|
34
|
+
return <IconImage24 />;
|
|
35
|
+
} else if (type === 'VIDEO') {
|
|
36
|
+
return <IconPlayFrame24 />;
|
|
37
|
+
} else if (type === 'AUDIO') {
|
|
38
|
+
return <IconMusicNote24 />;
|
|
39
|
+
} else {
|
|
40
|
+
return <IconDocument24 />;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const AttachmentItem = forwardRef<HTMLButtonElement, AttachmentItemProps>(
|
|
45
|
+
(
|
|
46
|
+
{
|
|
47
|
+
item,
|
|
48
|
+
isEditing,
|
|
49
|
+
draggableProps,
|
|
50
|
+
transformStyle,
|
|
51
|
+
isDragging,
|
|
52
|
+
isOverlay,
|
|
53
|
+
isLoading,
|
|
54
|
+
onDelete,
|
|
55
|
+
onReplaceWithBrowse,
|
|
56
|
+
onReplaceWithUpload,
|
|
57
|
+
},
|
|
58
|
+
ref
|
|
59
|
+
) => {
|
|
60
|
+
const [selectedAsset, setSelectedAsset] = useState<Asset | undefined>();
|
|
61
|
+
const [openFileDialog, { selectedFiles }] = useFileInput({ multiple: true, accept: 'image/*' });
|
|
62
|
+
const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload();
|
|
63
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (selectedFiles) {
|
|
67
|
+
uploadFile(selectedFiles[0]);
|
|
68
|
+
}
|
|
69
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
+
}, [selectedFiles]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (doneAll) {
|
|
74
|
+
onReplaceWithUpload(uploadResults[0]);
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, [doneAll, uploadResults]);
|
|
78
|
+
|
|
79
|
+
const download = (url: string, filename: string) => {
|
|
80
|
+
fetch(url).then((response) => {
|
|
81
|
+
response.blob().then((blob) => {
|
|
82
|
+
const url = URL.createObjectURL(blob);
|
|
83
|
+
const a = document.createElement('a');
|
|
84
|
+
a.href = url;
|
|
85
|
+
a.download = filename;
|
|
86
|
+
a.click();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const showLoadingCircle = isLoading || (selectedFiles && !doneAll);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<button
|
|
95
|
+
aria-label="Download attachment"
|
|
96
|
+
data-test-id="attachments-item"
|
|
97
|
+
onClick={() => download(item.genericUrl, item.fileName)}
|
|
98
|
+
ref={ref}
|
|
99
|
+
style={{
|
|
100
|
+
...transformStyle,
|
|
101
|
+
opacity: isDragging && !isOverlay ? 0.3 : 1,
|
|
102
|
+
fontFamily: 'var(-f-theme-settings-body-font-family)',
|
|
103
|
+
}}
|
|
104
|
+
className={joinClassNames([
|
|
105
|
+
'tw-cursor-pointer tw-text-left tw-w-full tw-relative tw-flex tw-gap-3 tw-px-5 tw-py-3 tw-items-center tw-group hover:tw-bg-box-neutral-hover',
|
|
106
|
+
isDragging ? 'tw-bg-box-neutral-hover' : '',
|
|
107
|
+
])}
|
|
108
|
+
>
|
|
109
|
+
<div className="tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover">
|
|
110
|
+
{showLoadingCircle ? (
|
|
111
|
+
<LoadingCircle size={LoadingCircleSize.Small} />
|
|
112
|
+
) : (
|
|
113
|
+
getDecorator(item.objectType)
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
<div className="tw-text-s tw-flex-1 tw-min-w-0">
|
|
117
|
+
<div className="tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover">
|
|
118
|
+
{item.title}
|
|
119
|
+
</div>
|
|
120
|
+
<div className="tw-text-text-weak">{`${item.fileSizeHumanReadable} - ${item.extension}`}</div>
|
|
121
|
+
</div>
|
|
122
|
+
{isEditing && (
|
|
123
|
+
<div
|
|
124
|
+
data-test-id="attachments-actionbar"
|
|
125
|
+
className={joinClassNames([
|
|
126
|
+
'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',
|
|
127
|
+
isOverlay || selectedAsset?.id === item.id ? 'tw-opacity-100' : 'tw-opacity-0',
|
|
128
|
+
])}
|
|
129
|
+
>
|
|
130
|
+
<button
|
|
131
|
+
{...focusProps}
|
|
132
|
+
{...draggableProps}
|
|
133
|
+
aria-label="Drag attachment"
|
|
134
|
+
className={joinClassNames([
|
|
135
|
+
' tw-border-button-border tw-bg-button-background active:tw-bg-button-background-pressed tw-group tw-border tw-box-box tw-relative tw-flex tw-items-center tw-justify-center tw-outline-none tw-font-medium tw-rounded tw-h-9 tw-w-9 ',
|
|
136
|
+
isDragging || isOverlay
|
|
137
|
+
? 'tw-cursor-grabbing tw-bg-button-background-pressed hover:tw-bg-button-background-pressed'
|
|
138
|
+
: 'tw-cursor-grab hover:tw-bg-button-background-hover',
|
|
139
|
+
isFocusVisible && FOCUS_STYLE,
|
|
140
|
+
isFocusVisible && 'tw-z-[2]',
|
|
141
|
+
])}
|
|
142
|
+
>
|
|
143
|
+
<IconGrabHandle20 />
|
|
144
|
+
</button>
|
|
145
|
+
<div data-test-id="attachments-actionbar-flyout">
|
|
146
|
+
<Flyout
|
|
147
|
+
placement={FlyoutPlacement.Right}
|
|
148
|
+
isOpen={selectedAsset?.id === item.id}
|
|
149
|
+
fitContent
|
|
150
|
+
legacyFooter={false}
|
|
151
|
+
onOpenChange={(isOpen) => setSelectedAsset(isOpen ? item : undefined)}
|
|
152
|
+
trigger={(_, ref) => (
|
|
153
|
+
<Button
|
|
154
|
+
ref={ref as MutableRefObject<HTMLButtonElement>}
|
|
155
|
+
icon={<IconPen20 />}
|
|
156
|
+
emphasis={ButtonEmphasis.Default}
|
|
157
|
+
onClick={() => setSelectedAsset(item)}
|
|
158
|
+
/>
|
|
159
|
+
)}
|
|
160
|
+
>
|
|
161
|
+
<ActionMenu
|
|
162
|
+
menuBlocks={[
|
|
163
|
+
{
|
|
164
|
+
id: 'menu',
|
|
165
|
+
menuItems: [
|
|
166
|
+
{
|
|
167
|
+
id: 'upload',
|
|
168
|
+
size: MenuItemContentSize.XSmall,
|
|
169
|
+
title: 'Replace with upload',
|
|
170
|
+
onClick: () => {
|
|
171
|
+
openFileDialog();
|
|
172
|
+
setSelectedAsset(undefined);
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
initialValue: true,
|
|
176
|
+
decorator: (
|
|
177
|
+
<div className="tw-mr-2">
|
|
178
|
+
<IconArrowCircleUp20 />
|
|
179
|
+
</div>
|
|
180
|
+
),
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
{
|
|
184
|
+
id: 'asset',
|
|
185
|
+
size: MenuItemContentSize.XSmall,
|
|
186
|
+
title: 'Replace with asset',
|
|
187
|
+
onClick: () => {
|
|
188
|
+
onReplaceWithBrowse();
|
|
189
|
+
setSelectedAsset(undefined);
|
|
190
|
+
},
|
|
191
|
+
initialValue: true,
|
|
192
|
+
decorator: (
|
|
193
|
+
<div className="tw-mr-2">
|
|
194
|
+
<IconImageStack20 />
|
|
195
|
+
</div>
|
|
196
|
+
),
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'menu-delete',
|
|
202
|
+
menuItems: [
|
|
203
|
+
{
|
|
204
|
+
id: 'delete',
|
|
205
|
+
size: MenuItemContentSize.XSmall,
|
|
206
|
+
title: 'Delete',
|
|
207
|
+
style: MenuItemStyle.Danger,
|
|
208
|
+
onClick: () => {
|
|
209
|
+
onDelete();
|
|
210
|
+
setSelectedAsset(undefined);
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
initialValue: true,
|
|
214
|
+
decorator: (
|
|
215
|
+
<div className="tw-mr-2">
|
|
216
|
+
<IconTrashBin20 />
|
|
217
|
+
</div>
|
|
218
|
+
),
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
]}
|
|
223
|
+
/>
|
|
224
|
+
</Flyout>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
</button>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
AttachmentItem.displayName = 'AttachmentItem';
|
|
234
|
+
|
|
235
|
+
export const SortableAttachmentItem = (props: SortableAttachmentItemProps) => {
|
|
236
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
237
|
+
id: props.item.id,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const transformStyle = {
|
|
241
|
+
transform: transform ? `translate(${transform.x}px, ${transform.y}px)` : '',
|
|
242
|
+
transition,
|
|
243
|
+
zIndex: isDragging ? 2 : 1,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const draggableProps = { ...attributes, ...listeners };
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<AttachmentItem
|
|
250
|
+
ref={setNodeRef}
|
|
251
|
+
isDragging={isDragging}
|
|
252
|
+
transformStyle={transformStyle}
|
|
253
|
+
draggableProps={draggableProps}
|
|
254
|
+
{...props}
|
|
255
|
+
/>
|
|
256
|
+
);
|
|
257
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { AssetDummy, getAppBridgeBlockStub } from '@frontify/app-bridge';
|
|
4
|
+
import { mount } from 'cypress/react18';
|
|
5
|
+
import { Attachments as AttachmentsComponent } from './Attachments';
|
|
6
|
+
import { AttachmentsProps } from './types';
|
|
7
|
+
import { SinonStub } from 'cypress/types/sinon';
|
|
8
|
+
|
|
9
|
+
const FlyoutButtonSelector = '[data-test-id="attachments-flyout-button"]';
|
|
10
|
+
const AssetInputSelector = '[data-test-id="asset-input-placeholder"]';
|
|
11
|
+
const ActionBarSelector = '[data-test-id="attachments-actionbar"]';
|
|
12
|
+
const DragHandleSelector = '[data-test-id="attachments-actionbar"] > button';
|
|
13
|
+
const FlyoutTriggerSelector = '[data-test-id="attachments-actionbar-flyout"] button';
|
|
14
|
+
const AttachmentItemSelector = '[data-test-id="attachments-item"]';
|
|
15
|
+
const MenuItemSelector = '[data-test-id="menu-item"]';
|
|
16
|
+
const LoadingCircleSelector = '[data-test-id="loading-circle"]';
|
|
17
|
+
|
|
18
|
+
const Attachments = ({
|
|
19
|
+
appBridge = getAppBridgeBlockStub(),
|
|
20
|
+
onDelete = cy.stub(),
|
|
21
|
+
items,
|
|
22
|
+
onReplaceWithBrowse = cy.stub(),
|
|
23
|
+
onReplaceWithUpload = cy.stub(),
|
|
24
|
+
onSorted = cy.stub(),
|
|
25
|
+
onBrowse = cy.stub(),
|
|
26
|
+
onUpload = cy.stub(),
|
|
27
|
+
}: Partial<AttachmentsProps>) => {
|
|
28
|
+
return (
|
|
29
|
+
<AttachmentsComponent
|
|
30
|
+
appBridge={appBridge}
|
|
31
|
+
onDelete={onDelete}
|
|
32
|
+
items={items}
|
|
33
|
+
onReplaceWithBrowse={onReplaceWithBrowse}
|
|
34
|
+
onReplaceWithUpload={onReplaceWithUpload}
|
|
35
|
+
onSorted={onSorted}
|
|
36
|
+
onBrowse={onBrowse}
|
|
37
|
+
onUpload={onUpload}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe('Attachments', () => {
|
|
43
|
+
it('renders attachments flyout if it is in edit mode', () => {
|
|
44
|
+
mount(<Attachments appBridge={getAppBridgeBlockStub({ editorState: true })} />);
|
|
45
|
+
cy.get(FlyoutButtonSelector).should('exist');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('renders attachments flyout if it has attachments', () => {
|
|
49
|
+
mount(<Attachments items={[AssetDummy.with(1)]} />);
|
|
50
|
+
cy.get(FlyoutButtonSelector).should('exist');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('does not render attachments flyout if there are no attachments', () => {
|
|
54
|
+
mount(<Attachments items={[]} />);
|
|
55
|
+
cy.get(FlyoutButtonSelector).should('not.exist');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders asset input if in edit mode', () => {
|
|
59
|
+
mount(<Attachments appBridge={getAppBridgeBlockStub({ editorState: true })} items={[AssetDummy.with(1)]} />);
|
|
60
|
+
cy.get(FlyoutButtonSelector).click();
|
|
61
|
+
cy.get(AssetInputSelector).should('exist');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('does not render asset input if in view mode', () => {
|
|
65
|
+
mount(<Attachments items={[AssetDummy.with(1)]} />);
|
|
66
|
+
cy.get(FlyoutButtonSelector).click();
|
|
67
|
+
cy.get(AssetInputSelector).should('not.exist');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('renders asset action buttons if in edit mode', () => {
|
|
71
|
+
mount(<Attachments appBridge={getAppBridgeBlockStub({ editorState: true })} items={[AssetDummy.with(1)]} />);
|
|
72
|
+
cy.get(FlyoutButtonSelector).click();
|
|
73
|
+
cy.get(ActionBarSelector).should('exist');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('does not render asset action buttons if in view mode', () => {
|
|
77
|
+
mount(<Attachments items={[AssetDummy.with(1)]} />);
|
|
78
|
+
cy.get(FlyoutButtonSelector).click();
|
|
79
|
+
cy.get(ActionBarSelector).should('not.exist');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('renders an attachment item for each asset', () => {
|
|
83
|
+
mount(<Attachments items={[AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)]} />);
|
|
84
|
+
cy.get(FlyoutButtonSelector).click();
|
|
85
|
+
cy.get(AttachmentItemSelector).should('have.length', 3);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders loading circle for attachment item', () => {
|
|
89
|
+
const appBridge = getAppBridgeBlockStub({
|
|
90
|
+
editorState: true,
|
|
91
|
+
});
|
|
92
|
+
(appBridge.openAssetChooser as SinonStub) = cy.stub().callsArgWith(0, AssetDummy.with(4));
|
|
93
|
+
|
|
94
|
+
cy.clock();
|
|
95
|
+
const replaceStub = () =>
|
|
96
|
+
new Promise<void>((resolve) =>
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
resolve();
|
|
99
|
+
}, 2000)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
mount(
|
|
103
|
+
<Attachments
|
|
104
|
+
onReplaceWithBrowse={replaceStub}
|
|
105
|
+
items={[AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)]}
|
|
106
|
+
appBridge={appBridge}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
cy.get(FlyoutButtonSelector).click();
|
|
111
|
+
cy.get(AttachmentItemSelector).eq(0).focus();
|
|
112
|
+
cy.get(FlyoutTriggerSelector).eq(1).click();
|
|
113
|
+
cy.get(MenuItemSelector).eq(1).click();
|
|
114
|
+
cy.get(LoadingCircleSelector).should('exist');
|
|
115
|
+
cy.tick(2000);
|
|
116
|
+
cy.get(LoadingCircleSelector).should('not.exist');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('renders focus ring on flyout button while tabbing and open it', () => {
|
|
120
|
+
mount(
|
|
121
|
+
<Attachments
|
|
122
|
+
appBridge={getAppBridgeBlockStub({ editorState: true })}
|
|
123
|
+
items={[AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)]}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
cy.get(FlyoutButtonSelector).click();
|
|
127
|
+
cy.realPress('Tab');
|
|
128
|
+
cy.realPress('Tab');
|
|
129
|
+
cy.realPress('Tab');
|
|
130
|
+
cy.get(FlyoutTriggerSelector).eq(0).should('have.class', 'focus-visible:tw-ring-blue');
|
|
131
|
+
cy.get(FlyoutTriggerSelector).eq(0).type('{enter}');
|
|
132
|
+
cy.get(MenuItemSelector).should('exist');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('reorders items using only keyboard events', () => {
|
|
136
|
+
const onSortStub = cy.stub();
|
|
137
|
+
mount(
|
|
138
|
+
<Attachments
|
|
139
|
+
appBridge={getAppBridgeBlockStub({ editorState: true })}
|
|
140
|
+
items={[{ ...AssetDummy.with(1), title: 'Moved item' }, AssetDummy.with(2), AssetDummy.with(3)]}
|
|
141
|
+
onSorted={onSortStub}
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
cy.get(FlyoutButtonSelector).click();
|
|
145
|
+
cy.realPress('Tab');
|
|
146
|
+
cy.realPress('Tab');
|
|
147
|
+
cy.realPress('Tab');
|
|
148
|
+
cy.get(DragHandleSelector).eq(0).type(' {downarrow}{downarrow} ');
|
|
149
|
+
cy.get(AttachmentItemSelector).eq(1).should('contain.text', 'Moved item');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
DndContext,
|
|
6
|
+
DragEndEvent,
|
|
7
|
+
DragOverlay,
|
|
8
|
+
DragStartEvent,
|
|
9
|
+
KeyboardSensor,
|
|
10
|
+
PointerSensor,
|
|
11
|
+
closestCenter,
|
|
12
|
+
useSensor,
|
|
13
|
+
useSensors,
|
|
14
|
+
} from '@dnd-kit/core';
|
|
15
|
+
import { SortableContext, arrayMove, rectSortingStrategy } from '@dnd-kit/sortable';
|
|
16
|
+
import { Asset, useAssetUpload, useEditorState } from '@frontify/app-bridge';
|
|
17
|
+
import {
|
|
18
|
+
AssetInput,
|
|
19
|
+
AssetInputSize,
|
|
20
|
+
Flyout,
|
|
21
|
+
FlyoutPlacement,
|
|
22
|
+
IconCaretDown12,
|
|
23
|
+
IconPaperclip16,
|
|
24
|
+
Tooltip,
|
|
25
|
+
TooltipPosition,
|
|
26
|
+
} from '@frontify/fondue';
|
|
27
|
+
import { AttachmentItem, SortableAttachmentItem } from './AttachmentItem';
|
|
28
|
+
import { AttachmentsProps } from './types';
|
|
29
|
+
import { restrictToWindowEdges } from '@dnd-kit/modifiers';
|
|
30
|
+
|
|
31
|
+
export const Attachments = ({
|
|
32
|
+
items = [],
|
|
33
|
+
onDelete,
|
|
34
|
+
onReplaceWithBrowse,
|
|
35
|
+
onReplaceWithUpload,
|
|
36
|
+
onBrowse,
|
|
37
|
+
onUpload,
|
|
38
|
+
onSorted,
|
|
39
|
+
appBridge,
|
|
40
|
+
}: AttachmentsProps) => {
|
|
41
|
+
const [internalItems, setInternalItems] = useState<Asset[]>(items);
|
|
42
|
+
const [isFlyoutOpen, setIsFlyoutOpen] = useState(false);
|
|
43
|
+
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor));
|
|
44
|
+
const [draggedAssetId, setDraggedAssetId] = useState<number | undefined>(undefined);
|
|
45
|
+
const [isUploadLoading, setIsUploadLoading] = useState(false);
|
|
46
|
+
const [assetIdsLoading, setAssetIdsLoading] = useState<number[]>([]);
|
|
47
|
+
const [selectedFiles, setSelectedFiles] = useState<FileList | null>(null);
|
|
48
|
+
const isEditing = useEditorState(appBridge);
|
|
49
|
+
|
|
50
|
+
const draggedItem = internalItems?.find((item) => item.id === draggedAssetId);
|
|
51
|
+
|
|
52
|
+
const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload({
|
|
53
|
+
onUploadProgress: () => !isUploadLoading && setIsUploadLoading(true),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
setInternalItems(items);
|
|
58
|
+
}, [items]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (selectedFiles) {
|
|
62
|
+
setIsUploadLoading(true);
|
|
63
|
+
uploadFile(selectedFiles);
|
|
64
|
+
}
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [selectedFiles]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const uploadDone = async () => {
|
|
70
|
+
if (doneAll) {
|
|
71
|
+
await onUpload(uploadResults);
|
|
72
|
+
setIsUploadLoading(false);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
uploadDone();
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, [doneAll, uploadResults]);
|
|
78
|
+
|
|
79
|
+
const onOpenAssetChooser = () => {
|
|
80
|
+
setIsFlyoutOpen(false);
|
|
81
|
+
appBridge.openAssetChooser(
|
|
82
|
+
(result: Asset[]) => {
|
|
83
|
+
onBrowse(result);
|
|
84
|
+
appBridge.closeAssetChooser();
|
|
85
|
+
setIsFlyoutOpen(true);
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
multiSelection: true,
|
|
89
|
+
selectedValueIds: internalItems.map((internalItem) => internalItem.id),
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const onReplaceItemWithBrowse = (toReplace: Asset) => {
|
|
95
|
+
setIsFlyoutOpen(false);
|
|
96
|
+
appBridge.openAssetChooser(
|
|
97
|
+
async (result: Asset[]) => {
|
|
98
|
+
setIsFlyoutOpen(true);
|
|
99
|
+
appBridge.closeAssetChooser();
|
|
100
|
+
setAssetIdsLoading([...assetIdsLoading, toReplace.id]);
|
|
101
|
+
await onReplaceWithBrowse(toReplace, result[0]);
|
|
102
|
+
setAssetIdsLoading(assetIdsLoading.filter((id) => id !== toReplace.id));
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
multiSelection: false,
|
|
106
|
+
selectedValueIds: internalItems.map((internalItem) => internalItem.id),
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const onReplaceItemWithUpload = async (toReplace: Asset, uploadedAsset: Asset) => {
|
|
112
|
+
setAssetIdsLoading([...assetIdsLoading, toReplace.id]);
|
|
113
|
+
await onReplaceWithUpload(toReplace, uploadedAsset);
|
|
114
|
+
setAssetIdsLoading(assetIdsLoading.filter((id) => id !== toReplace.id));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const handleDragStart = (event: DragStartEvent) => {
|
|
118
|
+
const { active } = event;
|
|
119
|
+
setDraggedAssetId(active.id as number);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const handleDragEnd = (event: DragEndEvent) => {
|
|
123
|
+
const { active, over } = event;
|
|
124
|
+
if (over && active.id !== over.id && internalItems) {
|
|
125
|
+
const oldIndex = internalItems.findIndex((i) => i.id === active.id);
|
|
126
|
+
const newIndex = internalItems.findIndex((i) => i.id === over.id);
|
|
127
|
+
const sortedItems = arrayMove(internalItems, oldIndex, newIndex);
|
|
128
|
+
setInternalItems(sortedItems);
|
|
129
|
+
onSorted(sortedItems);
|
|
130
|
+
}
|
|
131
|
+
setDraggedAssetId(undefined);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return isEditing || (internalItems?.length ?? 0) > 0 ? (
|
|
135
|
+
<Tooltip
|
|
136
|
+
withArrow
|
|
137
|
+
position={TooltipPosition.Top}
|
|
138
|
+
content="Attachments"
|
|
139
|
+
disabled={isFlyoutOpen}
|
|
140
|
+
enterDelay={500}
|
|
141
|
+
triggerElement={
|
|
142
|
+
<div data-test-id="attachments-flyout-button">
|
|
143
|
+
<Flyout
|
|
144
|
+
placement={FlyoutPlacement.BottomRight}
|
|
145
|
+
onOpenChange={(isOpen) => setIsFlyoutOpen(!!draggedItem ? true : isOpen)}
|
|
146
|
+
isOpen={isFlyoutOpen}
|
|
147
|
+
hug={false}
|
|
148
|
+
fitContent
|
|
149
|
+
legacyFooter={false}
|
|
150
|
+
trigger={
|
|
151
|
+
<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">
|
|
152
|
+
<IconPaperclip16 />
|
|
153
|
+
<div>{items.length > 0 ? items.length : 'Add'}</div>
|
|
154
|
+
<IconCaretDown12 />
|
|
155
|
+
</div>
|
|
156
|
+
}
|
|
157
|
+
>
|
|
158
|
+
<div className="tw-w-[300px]">
|
|
159
|
+
{internalItems.length > 0 && (
|
|
160
|
+
<DndContext
|
|
161
|
+
sensors={sensors}
|
|
162
|
+
collisionDetection={closestCenter}
|
|
163
|
+
onDragStart={handleDragStart}
|
|
164
|
+
onDragEnd={handleDragEnd}
|
|
165
|
+
modifiers={[restrictToWindowEdges]}
|
|
166
|
+
>
|
|
167
|
+
<SortableContext items={internalItems} strategy={rectSortingStrategy}>
|
|
168
|
+
<div className="tw-border-b tw-border-b-line">
|
|
169
|
+
{internalItems.map((item) => (
|
|
170
|
+
<SortableAttachmentItem
|
|
171
|
+
isEditing={isEditing}
|
|
172
|
+
isLoading={assetIdsLoading.includes(item.id)}
|
|
173
|
+
key={item.id}
|
|
174
|
+
item={item}
|
|
175
|
+
onDelete={() => onDelete(item)}
|
|
176
|
+
onReplaceWithBrowse={() => onReplaceItemWithBrowse(item)}
|
|
177
|
+
onReplaceWithUpload={(uploadedAsset: Asset) =>
|
|
178
|
+
onReplaceItemWithUpload(item, uploadedAsset)
|
|
179
|
+
}
|
|
180
|
+
/>
|
|
181
|
+
))}
|
|
182
|
+
</div>
|
|
183
|
+
</SortableContext>
|
|
184
|
+
<DragOverlay>
|
|
185
|
+
{draggedItem && (
|
|
186
|
+
<AttachmentItem
|
|
187
|
+
isOverlay={true}
|
|
188
|
+
isEditing={isEditing}
|
|
189
|
+
key={draggedAssetId}
|
|
190
|
+
item={draggedItem}
|
|
191
|
+
isDragging={true}
|
|
192
|
+
onDelete={() => onDelete(draggedItem)}
|
|
193
|
+
onReplaceWithBrowse={() => onReplaceItemWithBrowse(draggedItem)}
|
|
194
|
+
onReplaceWithUpload={(uploadedAsset: Asset) =>
|
|
195
|
+
onReplaceItemWithUpload(draggedItem, uploadedAsset)
|
|
196
|
+
}
|
|
197
|
+
/>
|
|
198
|
+
)}
|
|
199
|
+
</DragOverlay>
|
|
200
|
+
</DndContext>
|
|
201
|
+
)}
|
|
202
|
+
{isEditing && (
|
|
203
|
+
<div className="tw-px-5 tw-py-3">
|
|
204
|
+
<div className="tw-font-body tw-font-medium tw-text-text tw-text-s tw-my-4">
|
|
205
|
+
Add attachments
|
|
206
|
+
</div>
|
|
207
|
+
<AssetInput
|
|
208
|
+
isLoading={isUploadLoading}
|
|
209
|
+
size={AssetInputSize.Small}
|
|
210
|
+
onUploadClick={(fileList) => setSelectedFiles(fileList)}
|
|
211
|
+
onLibraryClick={onOpenAssetChooser}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
)}
|
|
215
|
+
</div>
|
|
216
|
+
</Flyout>
|
|
217
|
+
</div>
|
|
218
|
+
}
|
|
219
|
+
/>
|
|
220
|
+
) : null;
|
|
221
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { AppBridgeBlock, Asset } from '@frontify/app-bridge';
|
|
4
|
+
|
|
5
|
+
export type AttachmentsProps = {
|
|
6
|
+
items?: Asset[];
|
|
7
|
+
appBridge: AppBridgeBlock;
|
|
8
|
+
onReplaceWithUpload: (attachmentToReplace: Asset, newAsset: Asset) => Promise<void>;
|
|
9
|
+
onReplaceWithBrowse: (attachmentToReplace: Asset, newAsset: Asset) => Promise<void>;
|
|
10
|
+
onDelete: (attachmentToDelete: Asset) => void;
|
|
11
|
+
onUpload: (uploadedAttachments: Asset[]) => Promise<void>;
|
|
12
|
+
onBrowse: (browserAttachments: Asset[]) => void;
|
|
13
|
+
onSorted: (sortedAttachments: Asset[]) => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type AttachmentItemProps = SortableAttachmentItemProps & {
|
|
17
|
+
isDragging?: boolean;
|
|
18
|
+
transformStyle?: Record<string, unknown>;
|
|
19
|
+
draggableProps?: Record<string, unknown>;
|
|
20
|
+
isOverlay?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type SortableAttachmentItemProps = {
|
|
24
|
+
item: Asset;
|
|
25
|
+
isEditing: boolean;
|
|
26
|
+
onDelete: () => void;
|
|
27
|
+
isLoading?: boolean;
|
|
28
|
+
onReplaceWithBrowse: () => void;
|
|
29
|
+
onReplaceWithUpload: (uploadedAsset: Asset) => void;
|
|
30
|
+
};
|