@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,71 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
HTMLPropsAs,
|
|
5
|
+
getPluginOptions,
|
|
6
|
+
getSelectionBoundingClientRect,
|
|
7
|
+
useComposedRef,
|
|
8
|
+
useEditorRef,
|
|
9
|
+
useHotkeys,
|
|
10
|
+
} from '@udecode/plate';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
import { useFocused } from 'slate-react';
|
|
13
|
+
import { ButtonPlugin, ELEMENT_BUTTON } from '../../createButtonPlugin';
|
|
14
|
+
import { triggerFloatingButtonInsert } from '../../utils/triggerFloatingButtonInsert';
|
|
15
|
+
import {
|
|
16
|
+
FloatingButtonProps,
|
|
17
|
+
floatingButtonActions,
|
|
18
|
+
useFloatingButtonEscape,
|
|
19
|
+
useFloatingButtonSelectors,
|
|
20
|
+
useVirtualFloatingButton,
|
|
21
|
+
} from '.';
|
|
22
|
+
|
|
23
|
+
export const useFloatingButtonInsert = ({ floatingOptions, ...props }: FloatingButtonProps): HTMLPropsAs<'div'> => {
|
|
24
|
+
const editor = useEditorRef();
|
|
25
|
+
const focused = useFocused();
|
|
26
|
+
const mode = useFloatingButtonSelectors().mode();
|
|
27
|
+
const open = useFloatingButtonSelectors().isOpen(editor.id);
|
|
28
|
+
|
|
29
|
+
const { triggerFloatingButtonHotkeys } = getPluginOptions<ButtonPlugin>(editor, ELEMENT_BUTTON);
|
|
30
|
+
|
|
31
|
+
useHotkeys(
|
|
32
|
+
triggerFloatingButtonHotkeys,
|
|
33
|
+
(e) => {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
|
|
36
|
+
triggerFloatingButtonInsert(editor, {
|
|
37
|
+
focused,
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
enableOnContentEditable: true,
|
|
42
|
+
},
|
|
43
|
+
[focused]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const { update, style, floating } = useVirtualFloatingButton({
|
|
47
|
+
open: open && mode === 'insert',
|
|
48
|
+
getBoundingClientRect: getSelectionBoundingClientRect,
|
|
49
|
+
whileElementsMounted: undefined,
|
|
50
|
+
...floatingOptions,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// wait for update before focusing input
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (open) {
|
|
56
|
+
update();
|
|
57
|
+
}
|
|
58
|
+
floatingButtonActions.updated(open);
|
|
59
|
+
}, [open, update]);
|
|
60
|
+
|
|
61
|
+
useFloatingButtonEscape();
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
style: {
|
|
65
|
+
...style,
|
|
66
|
+
zIndex: 1000,
|
|
67
|
+
},
|
|
68
|
+
...props,
|
|
69
|
+
ref: useComposedRef<HTMLElement | null>(props.ref, floating),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { UseVirtualFloatingOptions, flip, offset, useVirtualFloating } from '@udecode/plate';
|
|
4
|
+
|
|
5
|
+
const OFFSET_Y = 12;
|
|
6
|
+
const OFFSET_X = -22;
|
|
7
|
+
const PADDING = 96;
|
|
8
|
+
|
|
9
|
+
export const useVirtualFloatingButton = (floatingOptions?: UseVirtualFloatingOptions) =>
|
|
10
|
+
useVirtualFloating({
|
|
11
|
+
placement: 'bottom-start',
|
|
12
|
+
middleware: [
|
|
13
|
+
offset({
|
|
14
|
+
mainAxis: OFFSET_Y,
|
|
15
|
+
alignmentAxis: OFFSET_X,
|
|
16
|
+
}),
|
|
17
|
+
flip({
|
|
18
|
+
padding: PADDING,
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
...floatingOptions,
|
|
22
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { AppBridgeBlock } from '@frontify/app-bridge';
|
|
4
|
+
import { Plugin, PluginProps } from '@frontify/fondue';
|
|
5
|
+
import { RangeBeforeOptions, createPluginFactory } from '@udecode/plate';
|
|
6
|
+
import { CSSProperties } from 'react';
|
|
7
|
+
import { isValidUrl } from '../LinkPlugin/utils/url';
|
|
8
|
+
import { ButtonMarkupElement } from './ButtonMarkupElement';
|
|
9
|
+
import { ButtonButton } from './components/ButtonButton';
|
|
10
|
+
import { CustomFloatingButton } from './components/FloatingButton/CustomFloatingButton';
|
|
11
|
+
import { BlockButtonStyles } from './utils';
|
|
12
|
+
import { withButton } from './withButton';
|
|
13
|
+
|
|
14
|
+
export const ELEMENT_BUTTON = 'button';
|
|
15
|
+
export const BUTTON_PLUGIN = 'button-plugin';
|
|
16
|
+
|
|
17
|
+
export interface ButtonPlugin {
|
|
18
|
+
forceSubmit?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Allow custom config for rangeBeforeOptions.
|
|
22
|
+
* @example default
|
|
23
|
+
* {
|
|
24
|
+
* matchString: ' ',
|
|
25
|
+
* skipInvalid: true,
|
|
26
|
+
* afterMatch: true,
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
rangeBeforeOptions?: RangeBeforeOptions;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Hotkeys to trigger floating button.
|
|
33
|
+
* @default 'command+k, ctrl+k'
|
|
34
|
+
*/
|
|
35
|
+
triggerFloatingButtonHotkeys: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Callback to validate an url.
|
|
39
|
+
* @default isUrl
|
|
40
|
+
*/
|
|
41
|
+
isUrl: (text: string) => boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Callback to optionally get the href for a url
|
|
45
|
+
* @returns href: an optional link to be used that is different from the text content (example https://google.com for google.com)
|
|
46
|
+
*/
|
|
47
|
+
getUrlHref?: (url: string) => string | undefined;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* On keyboard shortcut or toolbar mousedown, get the link url by calling this promise. The
|
|
51
|
+
* default behavior is to use the browser's native `prompt`.
|
|
52
|
+
*/
|
|
53
|
+
getLinkUrl?: (prevUrl: string | null) => Promise<string | null>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Enables support for hyperlinks.
|
|
58
|
+
*/
|
|
59
|
+
export const createButtonPlugin = (appBridge: AppBridgeBlock) =>
|
|
60
|
+
createPluginFactory({
|
|
61
|
+
key: ELEMENT_BUTTON,
|
|
62
|
+
isElement: true,
|
|
63
|
+
isInline: true,
|
|
64
|
+
props: ({ element }) => ({
|
|
65
|
+
nodeProps: { href: element?.url, target: element?.target },
|
|
66
|
+
}),
|
|
67
|
+
withOverrides: withButton,
|
|
68
|
+
renderAfterEditable: CustomFloatingButton,
|
|
69
|
+
options: {
|
|
70
|
+
isUrl: isValidUrl,
|
|
71
|
+
rangeBeforeOptions: {
|
|
72
|
+
matchString: ' ',
|
|
73
|
+
skipInvalid: true,
|
|
74
|
+
afterMatch: true,
|
|
75
|
+
},
|
|
76
|
+
triggerFloatingButtonHotkeys: 'command+shift+k, ctrl+shift+k',
|
|
77
|
+
appBridge,
|
|
78
|
+
},
|
|
79
|
+
then: (editor, { type }) => ({
|
|
80
|
+
deserializeHtml: {
|
|
81
|
+
rules: [
|
|
82
|
+
{
|
|
83
|
+
validNodeName: 'A',
|
|
84
|
+
validClassName: 'btn',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
getNode: (el) => ({
|
|
88
|
+
type,
|
|
89
|
+
url: el.getAttribute('href'),
|
|
90
|
+
target: el.getAttribute('target') || '_blank',
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
})();
|
|
95
|
+
|
|
96
|
+
export type ButtonPluginProps = Omit<PluginProps, 'styles'> & {
|
|
97
|
+
styles?: Record<string, CSSProperties & { hover?: CSSProperties }>;
|
|
98
|
+
} & { appBridge: AppBridgeBlock };
|
|
99
|
+
|
|
100
|
+
export class ButtonPlugin extends Plugin {
|
|
101
|
+
public styles: CSSProperties = {};
|
|
102
|
+
private appBridge: AppBridgeBlock;
|
|
103
|
+
constructor({ styles = BlockButtonStyles, ...props }: ButtonPluginProps) {
|
|
104
|
+
super(BUTTON_PLUGIN, {
|
|
105
|
+
button: ButtonButton,
|
|
106
|
+
markupElement: new ButtonMarkupElement(),
|
|
107
|
+
...props,
|
|
108
|
+
});
|
|
109
|
+
this.styles = styles;
|
|
110
|
+
this.appBridge = props?.appBridge as AppBridgeBlock;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
plugins() {
|
|
114
|
+
return [createButtonPlugin(this.appBridge)];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
export * from './insertButton';
|
|
4
|
+
export * from './submitFloatingButton';
|
|
5
|
+
export * from './unwrapButton';
|
|
6
|
+
export * from './upsertButton';
|
|
7
|
+
export * from './upsertButtonText';
|
|
8
|
+
export * from './wrapButton';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { InsertNodesOptions, PlateEditor, TText, Value, insertNodes } from '@udecode/plate';
|
|
4
|
+
import { TButtonElement } from '../types';
|
|
5
|
+
import { CreateButtonNodeOptions, createButtonNode } from '../utils/index';
|
|
6
|
+
|
|
7
|
+
export const insertButton = <V extends Value>(
|
|
8
|
+
editor: PlateEditor<V>,
|
|
9
|
+
createButtonNodeOptions: CreateButtonNodeOptions,
|
|
10
|
+
options?: InsertNodesOptions<V>
|
|
11
|
+
) => {
|
|
12
|
+
insertNodes<TButtonElement | TText>(
|
|
13
|
+
editor,
|
|
14
|
+
[createButtonNode(editor, createButtonNodeOptions)],
|
|
15
|
+
options as InsertNodesOptions
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, Value, focusEditor, getPluginOptions } from '@udecode/plate';
|
|
4
|
+
import { floatingButtonActions, floatingButtonSelectors } from '../components/FloatingButton/floatingButtonStore';
|
|
5
|
+
import { ButtonPlugin, ELEMENT_BUTTON } from '../createButtonPlugin';
|
|
6
|
+
import { upsertButton } from '.';
|
|
7
|
+
|
|
8
|
+
export const submitFloatingButton = <V extends Value>(editor: PlateEditor<V>) => {
|
|
9
|
+
if (!editor.selection) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { isUrl, forceSubmit } = getPluginOptions<ButtonPlugin, V>(editor, ELEMENT_BUTTON);
|
|
14
|
+
const url = floatingButtonSelectors.url();
|
|
15
|
+
|
|
16
|
+
const isValid = isUrl?.(url) || forceSubmit;
|
|
17
|
+
if (!isValid) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const text = floatingButtonSelectors.text();
|
|
22
|
+
const buttonStyle = floatingButtonSelectors.buttonStyle();
|
|
23
|
+
const target = floatingButtonSelectors.newTab() ? undefined : '_self';
|
|
24
|
+
|
|
25
|
+
floatingButtonActions.hide();
|
|
26
|
+
|
|
27
|
+
upsertButton(editor, {
|
|
28
|
+
url,
|
|
29
|
+
text,
|
|
30
|
+
buttonStyle,
|
|
31
|
+
target,
|
|
32
|
+
isUrl: (_url) => (forceSubmit || !isUrl ? true : isUrl(_url)),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
focusEditor(editor, editor.selection ?? undefined);
|
|
37
|
+
}, 0);
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
PlateEditor,
|
|
5
|
+
UnwrapNodesOptions,
|
|
6
|
+
Value,
|
|
7
|
+
getAboveNode,
|
|
8
|
+
getPluginType,
|
|
9
|
+
isElement,
|
|
10
|
+
splitNodes,
|
|
11
|
+
unwrapNodes,
|
|
12
|
+
withoutNormalizing,
|
|
13
|
+
} from '@udecode/plate';
|
|
14
|
+
import { ELEMENT_BUTTON } from '../createButtonPlugin';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Unwrap button node.
|
|
18
|
+
*/
|
|
19
|
+
export const unwrapButton = <V extends Value>(
|
|
20
|
+
editor: PlateEditor<V>,
|
|
21
|
+
options?: UnwrapNodesOptions & {
|
|
22
|
+
split?: boolean;
|
|
23
|
+
}
|
|
24
|
+
) => {
|
|
25
|
+
return withoutNormalizing(editor, () => {
|
|
26
|
+
if (options?.split) {
|
|
27
|
+
const buttonAboveAnchor = getAboveNode(editor, {
|
|
28
|
+
at: editor.selection?.anchor,
|
|
29
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// anchor in button
|
|
33
|
+
if (buttonAboveAnchor) {
|
|
34
|
+
splitNodes(editor, {
|
|
35
|
+
at: editor.selection?.anchor,
|
|
36
|
+
match: (n) => isElement(n) && n.type === getPluginType(editor, ELEMENT_BUTTON),
|
|
37
|
+
});
|
|
38
|
+
unwrapButton(editor, {
|
|
39
|
+
at: editor.selection?.anchor,
|
|
40
|
+
});
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const buttonAboveFocus = getAboveNode(editor, {
|
|
44
|
+
at: editor.selection?.focus,
|
|
45
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// focus in button
|
|
49
|
+
if (buttonAboveFocus) {
|
|
50
|
+
splitNodes(editor, {
|
|
51
|
+
at: editor.selection?.focus,
|
|
52
|
+
match: (n) => isElement(n) && n.type === getPluginType(editor, ELEMENT_BUTTON),
|
|
53
|
+
});
|
|
54
|
+
unwrapButton(editor, {
|
|
55
|
+
at: editor.selection?.focus,
|
|
56
|
+
});
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
unwrapNodes(editor, {
|
|
62
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
63
|
+
...options,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
InsertNodesOptions,
|
|
5
|
+
PlateEditor,
|
|
6
|
+
TNode,
|
|
7
|
+
TNodeEntry,
|
|
8
|
+
UnwrapNodesOptions,
|
|
9
|
+
Value,
|
|
10
|
+
WrapNodesOptions,
|
|
11
|
+
findNode,
|
|
12
|
+
getAboveNode,
|
|
13
|
+
getEditorString,
|
|
14
|
+
getNodeLeaf,
|
|
15
|
+
getNodeProps,
|
|
16
|
+
getPluginOptions,
|
|
17
|
+
getPluginType,
|
|
18
|
+
isDefined,
|
|
19
|
+
isExpanded,
|
|
20
|
+
removeNodes,
|
|
21
|
+
setNodes,
|
|
22
|
+
} from '@udecode/plate';
|
|
23
|
+
import { Path } from 'slate';
|
|
24
|
+
import { ButtonPlugin, ELEMENT_BUTTON } from '../createButtonPlugin';
|
|
25
|
+
import { RichTextButtonStyle, TButtonElement } from '../types';
|
|
26
|
+
import { CreateButtonNodeOptions } from '../utils/index';
|
|
27
|
+
import { insertButton, unwrapButton, upsertButtonText, wrapButton } from '.';
|
|
28
|
+
|
|
29
|
+
export type UpsertButtonOptions<V extends Value = Value> = CreateButtonNodeOptions & {
|
|
30
|
+
/**
|
|
31
|
+
* If true, insert text when selection is in url.
|
|
32
|
+
*/
|
|
33
|
+
insertTextInButton?: boolean;
|
|
34
|
+
insertNodesOptions?: InsertNodesOptions<V>;
|
|
35
|
+
unwrapNodesOptions?: UnwrapNodesOptions<V>;
|
|
36
|
+
wrapNodesOptions?: WrapNodesOptions<V>;
|
|
37
|
+
isUrl?: (url: string) => boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If selection in a button or is not url:
|
|
42
|
+
* - insert text with url, exit
|
|
43
|
+
* If selection is expanded or `update` in a button:
|
|
44
|
+
* - remove button node, get button text
|
|
45
|
+
* Then:
|
|
46
|
+
* - insert button node
|
|
47
|
+
*/
|
|
48
|
+
export const upsertButton = <V extends Value>(
|
|
49
|
+
editor: PlateEditor<V>,
|
|
50
|
+
{
|
|
51
|
+
url,
|
|
52
|
+
text,
|
|
53
|
+
buttonStyle,
|
|
54
|
+
target,
|
|
55
|
+
insertTextInButton,
|
|
56
|
+
insertNodesOptions,
|
|
57
|
+
isUrl = getPluginOptions<ButtonPlugin, V>(editor, ELEMENT_BUTTON).isUrl,
|
|
58
|
+
}: UpsertButtonOptions<V>
|
|
59
|
+
) => {
|
|
60
|
+
const at = editor.selection;
|
|
61
|
+
if (!at) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const buttonAbove = getAboveNode<TButtonElement>(editor, {
|
|
66
|
+
at,
|
|
67
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// anchor and focus in button -> insert text
|
|
71
|
+
if (insertTextInButton && buttonAbove) {
|
|
72
|
+
// we don't want to insert marks in buttons
|
|
73
|
+
editor.insertText(url);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!isUrl?.(url)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isDefined(text) && text.length === 0) {
|
|
82
|
+
text = url;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (buttonAbove) {
|
|
86
|
+
editButtonUrlAndTarget<V>(url, editor, buttonAbove, target, buttonStyle, text);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// selection contains at one edge edge or between the edges
|
|
91
|
+
const buttonEntry = findNode<TButtonElement>(editor, {
|
|
92
|
+
at,
|
|
93
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const [buttonNode, buttonPath] = buttonEntry ?? [];
|
|
97
|
+
|
|
98
|
+
const shouldReplaceText = shouldReplaceButtonText<V>(editor, buttonPath, text);
|
|
99
|
+
|
|
100
|
+
if (isExpanded(at)) {
|
|
101
|
+
anchorAndFocusInButton<V>(buttonAbove, editor, url, buttonStyle, target, text);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (shouldReplaceText) {
|
|
106
|
+
removeNodes(editor, {
|
|
107
|
+
at: buttonPath,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const props = getNodeProps(buttonNode ?? ({} as TNode));
|
|
112
|
+
|
|
113
|
+
const path = editor.selection?.focus.path;
|
|
114
|
+
if (!path) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// button text should have the focused leaf marks
|
|
119
|
+
const leaf = getNodeLeaf(editor, path);
|
|
120
|
+
|
|
121
|
+
// if text is empty, text is url
|
|
122
|
+
if (!text?.length) {
|
|
123
|
+
text = url;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
insertButton(
|
|
127
|
+
editor,
|
|
128
|
+
{
|
|
129
|
+
...props,
|
|
130
|
+
url,
|
|
131
|
+
target,
|
|
132
|
+
children: [
|
|
133
|
+
{
|
|
134
|
+
...leaf,
|
|
135
|
+
text,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
insertNodesOptions
|
|
140
|
+
);
|
|
141
|
+
return true;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
function shouldReplaceButtonText<V extends Value>(editor: PlateEditor<V>, buttonPath?: Path, text?: string) {
|
|
145
|
+
return buttonPath && text?.length && text !== getEditorString(editor, buttonPath);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function anchorAndFocusInButton<V extends Value>(
|
|
149
|
+
buttonAbove: undefined,
|
|
150
|
+
editor: PlateEditor<V>,
|
|
151
|
+
url: string,
|
|
152
|
+
buttonStyle?: RichTextButtonStyle,
|
|
153
|
+
target?: string,
|
|
154
|
+
text?: string
|
|
155
|
+
) {
|
|
156
|
+
if (buttonAbove) {
|
|
157
|
+
unwrapButton(editor, {
|
|
158
|
+
at: buttonAbove[1],
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
unwrapButton(editor, {
|
|
162
|
+
split: true,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
wrapButton(editor, {
|
|
167
|
+
url,
|
|
168
|
+
buttonStyle,
|
|
169
|
+
target,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
upsertButtonText(editor, { url, target, text });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function editButtonUrlAndTarget<V extends Value>(
|
|
176
|
+
url: string,
|
|
177
|
+
editor: PlateEditor<V>,
|
|
178
|
+
buttonAbove: TNodeEntry<TButtonElement>,
|
|
179
|
+
target?: string,
|
|
180
|
+
buttonStyle?: string,
|
|
181
|
+
text?: string
|
|
182
|
+
) {
|
|
183
|
+
if (
|
|
184
|
+
url !== buttonAbove[0]?.url ||
|
|
185
|
+
target !== buttonAbove[0]?.target ||
|
|
186
|
+
buttonStyle !== buttonAbove[0]?.buttonStyle
|
|
187
|
+
) {
|
|
188
|
+
setNodes<TButtonElement>(
|
|
189
|
+
editor,
|
|
190
|
+
{ url, target, buttonStyle },
|
|
191
|
+
{
|
|
192
|
+
at: buttonAbove[1],
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
upsertButtonText(editor, { url, text, target });
|
|
198
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
PlateEditor,
|
|
5
|
+
TText,
|
|
6
|
+
Value,
|
|
7
|
+
getAboveNode,
|
|
8
|
+
getEditorString,
|
|
9
|
+
getPluginType,
|
|
10
|
+
replaceNodeChildren,
|
|
11
|
+
} from '@udecode/plate';
|
|
12
|
+
import { ELEMENT_BUTTON, TButtonElement } from '..';
|
|
13
|
+
import { UpsertButtonOptions } from './upsertButton';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* If the text is different than the button above text, replace button children by a new text.
|
|
17
|
+
* The new text has the same marks than the first text replaced.
|
|
18
|
+
*/
|
|
19
|
+
export const upsertButtonText = <V extends Value>(editor: PlateEditor<V>, { text }: UpsertButtonOptions<V>) => {
|
|
20
|
+
const newButton = getAboveNode<TButtonElement>(editor, {
|
|
21
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (newButton) {
|
|
25
|
+
const [newButtonNode, newButtonPath] = newButton;
|
|
26
|
+
|
|
27
|
+
if (text?.length && text !== getEditorString(editor, newButtonPath)) {
|
|
28
|
+
const firstText = newButtonNode.children[0];
|
|
29
|
+
|
|
30
|
+
// remove button children
|
|
31
|
+
replaceNodeChildren<TText>(editor, {
|
|
32
|
+
at: newButtonPath,
|
|
33
|
+
nodes: { ...firstText, text },
|
|
34
|
+
insertOptions: {
|
|
35
|
+
select: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, Value, WrapNodesOptions, getPluginType, wrapNodes } from '@udecode/plate';
|
|
4
|
+
import { ELEMENT_BUTTON, RichTextButtonStyle, TButtonElement } from '..';
|
|
5
|
+
|
|
6
|
+
export interface WrapButtonOptions<V extends Value = Value> extends WrapNodesOptions<V> {
|
|
7
|
+
url: string;
|
|
8
|
+
buttonStyle?: RichTextButtonStyle;
|
|
9
|
+
target?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a button node with split.
|
|
14
|
+
*/
|
|
15
|
+
export const wrapButton = <V extends Value>(
|
|
16
|
+
editor: PlateEditor<V>,
|
|
17
|
+
{ url, buttonStyle, target, ...options }: WrapButtonOptions<V>
|
|
18
|
+
) => {
|
|
19
|
+
wrapNodes<TButtonElement, Value>(
|
|
20
|
+
editor,
|
|
21
|
+
{
|
|
22
|
+
type: getPluginType(editor, ELEMENT_BUTTON),
|
|
23
|
+
url,
|
|
24
|
+
buttonStyle,
|
|
25
|
+
target,
|
|
26
|
+
children: [],
|
|
27
|
+
},
|
|
28
|
+
{ split: true, ...options } as WrapNodesOptions
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { TLinkElement } from '@udecode/plate';
|
|
4
|
+
|
|
5
|
+
export type TButtonElement = TLinkElement & {
|
|
6
|
+
chosenLink?: {
|
|
7
|
+
searchResult?: {
|
|
8
|
+
link?: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type RichTextButtonStyle = 'primary' | 'secondary' | 'tertiary';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, TText, Value, getPluginType } from '@udecode/plate';
|
|
4
|
+
import { RichTextButtonStyle, TButtonElement } from '..';
|
|
5
|
+
import { ELEMENT_BUTTON } from '../createButtonPlugin';
|
|
6
|
+
|
|
7
|
+
export interface CreateButtonNodeOptions {
|
|
8
|
+
url: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
buttonStyle?: RichTextButtonStyle;
|
|
11
|
+
target?: string;
|
|
12
|
+
children?: TText[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const createButtonNode = <V extends Value>(
|
|
16
|
+
editor: PlateEditor<V>,
|
|
17
|
+
{ url, text = '', buttonStyle = 'primary', target, children }: CreateButtonNodeOptions
|
|
18
|
+
): TButtonElement => {
|
|
19
|
+
const type = getPluginType(editor, ELEMENT_BUTTON);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
type,
|
|
23
|
+
url,
|
|
24
|
+
target,
|
|
25
|
+
buttonStyle,
|
|
26
|
+
children: children ?? [{ text }],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, getAboveNode } from '@udecode/plate';
|
|
4
|
+
import { ELEMENT_BUTTON, RichTextButtonStyle, TButtonElement } from '..';
|
|
5
|
+
|
|
6
|
+
export const getButtonStyle = (editor: PlateEditor): RichTextButtonStyle => {
|
|
7
|
+
const linkNode = getAboveNode<TButtonElement>(editor, { match: { type: ELEMENT_BUTTON } });
|
|
8
|
+
|
|
9
|
+
if (!Array.isArray(linkNode)) {
|
|
10
|
+
return 'primary';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return (linkNode[0]?.buttonStyle as RichTextButtonStyle) || 'primary';
|
|
14
|
+
};
|