@frontify/guideline-blocks-settings 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +15 -0
- package/README.md +24 -5
- 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
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -147
- package/dist/index.es.js +0 -9
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { CSSProperties } from 'react';
|
|
4
|
+
|
|
5
|
+
export const BlockButtonStyles: Record<string, CSSProperties & { hover?: CSSProperties }> = {
|
|
6
|
+
buttonPrimary: {
|
|
7
|
+
fontFamily: 'var(--f-theme-settings-button-primary-font-family)',
|
|
8
|
+
fontSize: 'var(--f-theme-settings-button-primary-font-size)',
|
|
9
|
+
fontWeight: 'var(--f-theme-settings-button-primary-font-weight)',
|
|
10
|
+
lineHeight: 'var(--f-theme-settings-button-primary-line-height)',
|
|
11
|
+
paddingTop: 'var(--f-theme-settings-button-primary-padding-top)',
|
|
12
|
+
paddingRight: 'var(--f-theme-settings-button-primary-padding-right)',
|
|
13
|
+
paddingBottom: 'var(--f-theme-settings-button-primary-padding-bottom)',
|
|
14
|
+
paddingLeft: 'var(--f-theme-settings-button-primary-padding-left)',
|
|
15
|
+
fontStyle: 'var(--f-theme-settings-button-primary-font-style)',
|
|
16
|
+
textTransform: 'var(--f-theme-settings-button-primary-text-transform)' as CSSProperties['textTransform'],
|
|
17
|
+
backgroundColor: 'var(--f-theme-settings-button-primary-background-color)',
|
|
18
|
+
borderColor: 'var(--f-theme-settings-button-primary-border-color)',
|
|
19
|
+
borderRadius: 'var(--f-theme-settings-button-primary-border-radius)',
|
|
20
|
+
borderWidth: 'var(--f-theme-settings-button-primary-border-width)',
|
|
21
|
+
color: 'var(--f-theme-settings-button-primary-color)',
|
|
22
|
+
display: 'inline-block',
|
|
23
|
+
hover: {
|
|
24
|
+
backgroundColor: 'var(--f-theme-settings-button-primary-background-color-hover)',
|
|
25
|
+
borderColor: 'var(--f-theme-settings-button-primary-border-color-hover)',
|
|
26
|
+
color: 'var(--f-theme-settings-button-primary-color-hover)',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
buttonSecondary: {
|
|
31
|
+
fontFamily: 'var(--f-theme-settings-button-secondary-font-family)',
|
|
32
|
+
fontSize: 'var(--f-theme-settings-button-secondary-font-size)',
|
|
33
|
+
fontWeight: 'var(--f-theme-settings-button-secondary-font-weight)',
|
|
34
|
+
lineHeight: 'var(--f-theme-settings-button-secondary-line-height)',
|
|
35
|
+
paddingTop: 'var(--f-theme-settings-button-secondary-padding-top)',
|
|
36
|
+
paddingRight: 'var(--f-theme-settings-button-secondary-padding-right)',
|
|
37
|
+
paddingBottom: 'var(--f-theme-settings-button-secondary-padding-bottom)',
|
|
38
|
+
paddingLeft: 'var(--f-theme-settings-button-secondary-padding-left)',
|
|
39
|
+
fontStyle: 'var(--f-theme-settings-button-secondary-font-style)',
|
|
40
|
+
textTransform: 'var(--f-theme-settings-button-secondary-text-transform)' as CSSProperties['textTransform'],
|
|
41
|
+
backgroundColor: 'var(--f-theme-settings-button-secondary-background-color)',
|
|
42
|
+
borderColor: 'var(--f-theme-settings-button-secondary-border-color)',
|
|
43
|
+
borderRadius: 'var(--f-theme-settings-button-secondary-border-radius)',
|
|
44
|
+
borderWidth: 'var(--f-theme-settings-button-secondary-border-width)',
|
|
45
|
+
color: 'var(--f-theme-settings-button-secondary-color)',
|
|
46
|
+
display: 'inline-block',
|
|
47
|
+
hover: {
|
|
48
|
+
backgroundColor: 'var(--f-theme-settings-button-secondary-background-color-hover)',
|
|
49
|
+
borderColor: 'var(--f-theme-settings-button-secondary-border-color-hover)',
|
|
50
|
+
color: 'var(--f-theme-settings-button-secondary-color-hover)',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
buttonTertiary: {
|
|
55
|
+
fontFamily: 'var(--f-theme-settings-button-tertiary-font-family)',
|
|
56
|
+
fontSize: 'var(--f-theme-settings-button-tertiary-font-size)',
|
|
57
|
+
fontWeight: 'var(--f-theme-settings-button-tertiary-font-weight)',
|
|
58
|
+
lineHeight: 'var(--f-theme-settings-button-tertiary-line-height)',
|
|
59
|
+
paddingTop: 'var(--f-theme-settings-button-tertiary-padding-top)',
|
|
60
|
+
paddingRight: 'var(--f-theme-settings-button-tertiary-padding-right)',
|
|
61
|
+
paddingBottom: 'var(--f-theme-settings-button-tertiary-padding-bottom)',
|
|
62
|
+
paddingLeft: 'var(--f-theme-settings-button-tertiary-padding-left)',
|
|
63
|
+
fontStyle: 'var(--f-theme-settings-button-tertiary-font-style)',
|
|
64
|
+
textTransform: 'var(--f-theme-settings-button-tertiary-text-transform)' as CSSProperties['textTransform'],
|
|
65
|
+
backgroundColor: 'var(--f-theme-settings-button-tertiary-background-color)',
|
|
66
|
+
borderColor: 'var(--f-theme-settings-button-tertiary-border-color)',
|
|
67
|
+
borderRadius: 'var(--f-theme-settings-button-tertiary-border-radius)',
|
|
68
|
+
borderWidth: 'var(--f-theme-settings-button-tertiary-border-width)',
|
|
69
|
+
color: 'var(--f-theme-settings-button-tertiary-color)',
|
|
70
|
+
display: 'inline-block',
|
|
71
|
+
hover: {
|
|
72
|
+
backgroundColor: 'var(--f-theme-settings-button-tertiary-background-color-hover)',
|
|
73
|
+
borderColor: 'var(--f-theme-settings-button-tertiary-border-color-hover)',
|
|
74
|
+
color: 'var(--f-theme-settings-button-tertiary-color-hover)',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, Value } from '@udecode/plate';
|
|
4
|
+
import { floatingButtonSelectors } from '../components';
|
|
5
|
+
import { triggerFloatingButtonEdit, triggerFloatingButtonInsert } from '.';
|
|
6
|
+
|
|
7
|
+
export const triggerFloatingButton = <V extends Value>(
|
|
8
|
+
editor: PlateEditor<V>,
|
|
9
|
+
{
|
|
10
|
+
focused,
|
|
11
|
+
}: {
|
|
12
|
+
focused?: boolean;
|
|
13
|
+
} = {}
|
|
14
|
+
) => {
|
|
15
|
+
if (floatingButtonSelectors.mode() === 'edit') {
|
|
16
|
+
triggerFloatingButtonEdit(editor);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
triggerFloatingButtonInsert(editor, {
|
|
21
|
+
focused,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, Value, findNode, getEditorString, getPluginType } from '@udecode/plate';
|
|
4
|
+
import { ELEMENT_BUTTON, TButtonElement } from '..';
|
|
5
|
+
import { floatingButtonActions } from '../components/FloatingButton/floatingButtonStore';
|
|
6
|
+
|
|
7
|
+
export const triggerFloatingButtonEdit = <V extends Value>(editor: PlateEditor<V>) => {
|
|
8
|
+
const entry = findNode<TButtonElement>(editor, {
|
|
9
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
10
|
+
});
|
|
11
|
+
if (!entry) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const [link, path] = entry;
|
|
16
|
+
|
|
17
|
+
let text = getEditorString(editor, path);
|
|
18
|
+
|
|
19
|
+
floatingButtonActions.url(link.url);
|
|
20
|
+
|
|
21
|
+
floatingButtonActions.newTab(link.target === undefined);
|
|
22
|
+
|
|
23
|
+
if (text === link.url) {
|
|
24
|
+
text = '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
floatingButtonActions.text(text);
|
|
28
|
+
|
|
29
|
+
floatingButtonActions.isEditing(true);
|
|
30
|
+
};
|
package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { PlateEditor, Value, getEditorString, getPluginType, isRangeAcrossBlocks, someNode } from '@udecode/plate';
|
|
4
|
+
import { floatingButtonActions, floatingButtonSelectors } from '../components/FloatingButton/floatingButtonStore';
|
|
5
|
+
import { ELEMENT_BUTTON } from '../createButtonPlugin';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Trigger floating button.
|
|
9
|
+
*
|
|
10
|
+
* Do not trigger when:
|
|
11
|
+
* - selection is across blocks
|
|
12
|
+
* - selection has more than one leaf node
|
|
13
|
+
* - lowest selection is not text
|
|
14
|
+
* - selection has a button node
|
|
15
|
+
*/
|
|
16
|
+
export const triggerFloatingButtonInsert = <V extends Value>(
|
|
17
|
+
editor: PlateEditor<V>,
|
|
18
|
+
{
|
|
19
|
+
focused,
|
|
20
|
+
}: {
|
|
21
|
+
focused?: boolean;
|
|
22
|
+
} = {}
|
|
23
|
+
) => {
|
|
24
|
+
if (floatingButtonSelectors.mode()) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!focused) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (isRangeAcrossBlocks(editor, { at: editor.selection })) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const hasButton = someNode(editor, {
|
|
37
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
38
|
+
});
|
|
39
|
+
if (hasButton) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
floatingButtonActions.text(getEditorString(editor, editor.selection));
|
|
44
|
+
floatingButtonActions.show('insert', editor.id);
|
|
45
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AnyObject,
|
|
5
|
+
EText,
|
|
6
|
+
PlateEditor,
|
|
7
|
+
Value,
|
|
8
|
+
WithOverride,
|
|
9
|
+
getAboveNode,
|
|
10
|
+
getNextNodeStartPoint,
|
|
11
|
+
getPluginType,
|
|
12
|
+
getPreviousNodeEndPoint,
|
|
13
|
+
insertNodes,
|
|
14
|
+
isCollapsed,
|
|
15
|
+
isEndPoint,
|
|
16
|
+
isStartPoint,
|
|
17
|
+
mockPlugin,
|
|
18
|
+
select,
|
|
19
|
+
withRemoveEmptyNodes,
|
|
20
|
+
} from '@udecode/plate';
|
|
21
|
+
import { Path, Point, Range } from 'slate';
|
|
22
|
+
import { ELEMENT_BUTTON } from './createButtonPlugin';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Insert space after a url to wrap a button.
|
|
26
|
+
* Lookup from the block start to the cursor to check if there is an url.
|
|
27
|
+
* If not found, lookup before the cursor for a space character to check the url.
|
|
28
|
+
*
|
|
29
|
+
* On insert data:
|
|
30
|
+
* Paste a string inside a button element will edit its children text but not its url.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export const withButton: WithOverride = (editor, { type }) => {
|
|
35
|
+
const { apply, normalizeNode } = editor;
|
|
36
|
+
|
|
37
|
+
editor.apply = (operation) => {
|
|
38
|
+
if (operation.type !== 'set_selection') {
|
|
39
|
+
apply(operation);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const range = operation.newProperties;
|
|
44
|
+
if (!range?.focus || !range.anchor || !isCollapsed(range as Range)) {
|
|
45
|
+
apply(operation);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const entry = getAboveNode(editor, {
|
|
50
|
+
at: range as Range,
|
|
51
|
+
match: { type: getPluginType(editor, ELEMENT_BUTTON) },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (entry) {
|
|
55
|
+
const [, path] = entry;
|
|
56
|
+
|
|
57
|
+
let newPoint: Point | undefined;
|
|
58
|
+
|
|
59
|
+
if (isStartPoint(editor, range.focus, path)) {
|
|
60
|
+
newPoint = getPreviousNodeEndPoint(editor, path);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (isEndPoint(editor, range.focus, path)) {
|
|
64
|
+
newPoint = getNextNodeStartPoint(editor, path);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (newPoint) {
|
|
68
|
+
operation.newProperties = {
|
|
69
|
+
anchor: newPoint,
|
|
70
|
+
focus: newPoint,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
apply(operation);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
editor.normalizeNode = ([node, path]) => {
|
|
79
|
+
if (node.type === getPluginType(editor, ELEMENT_BUTTON)) {
|
|
80
|
+
const range = editor.selection as Range | null;
|
|
81
|
+
|
|
82
|
+
if (range && isCollapsed(range) && isEndPoint(editor, range.focus, path)) {
|
|
83
|
+
const nextPoint = getNextNodeStartPoint(editor, path);
|
|
84
|
+
|
|
85
|
+
// select next text node if any
|
|
86
|
+
if (nextPoint) {
|
|
87
|
+
select(editor, nextPoint);
|
|
88
|
+
} else {
|
|
89
|
+
// insert text node then select
|
|
90
|
+
const nextPath = Path.next(path);
|
|
91
|
+
insertNodes(editor, { text: '' } as EText<Value>, { at: nextPath });
|
|
92
|
+
select(editor, nextPath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
normalizeNode([node, path]);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return withRemoveEmptyNodes<Value, PlateEditor<Value>>(
|
|
101
|
+
editor,
|
|
102
|
+
mockPlugin<AnyObject, Value, PlateEditor<Value>>({
|
|
103
|
+
options: { types: type },
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { TEditableProps, useFloatingLinkSelectors } from '@udecode/plate';
|
|
4
|
+
|
|
5
|
+
import { EditModal } from './EditLinkModal';
|
|
6
|
+
import { FloatingLink } from './FloatingLink';
|
|
7
|
+
import { InsertLinkModal } from './InsertLinkModal/InsertLinkModal';
|
|
8
|
+
|
|
9
|
+
export const CustomFloatingLink = ({ readOnly }: TEditableProps) => {
|
|
10
|
+
const isEditing = useFloatingLinkSelectors().isEditing();
|
|
11
|
+
|
|
12
|
+
if (readOnly) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const input = <InsertLinkModal />;
|
|
17
|
+
const editContent = isEditing ? input : <EditModal />;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<FloatingLink.InsertRoot>{input}</FloatingLink.InsertRoot>
|
|
22
|
+
|
|
23
|
+
<FloatingLink.EditRoot>{editContent}</FloatingLink.EditRoot>
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
26
|
+
};
|
package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { IconPen16, IconTrashBin16 } from '@frontify/fondue';
|
|
4
|
+
import { useFloatingLinkUrlInput } from '@udecode/plate';
|
|
5
|
+
import { FloatingLink } from '../FloatingLink';
|
|
6
|
+
import { BlockStyles } from '../../../styles';
|
|
7
|
+
|
|
8
|
+
export const EditModal = () => {
|
|
9
|
+
const urlHtmlProps = useFloatingLinkUrlInput({});
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div data-test-id="floating-link-edit" className="tw-bg-white tw-rounded tw-shadow tw-p-4 tw-min-w-[400px]">
|
|
13
|
+
<span data-test-id={'preview-link-flyout'} className="tw-flex tw-justify-between">
|
|
14
|
+
<span className="tw-pointer-events-none" style={BlockStyles.p}>
|
|
15
|
+
{urlHtmlProps.defaultValue}
|
|
16
|
+
</span>
|
|
17
|
+
<span className="tw-flex tw-gap-2">
|
|
18
|
+
<span
|
|
19
|
+
role="button"
|
|
20
|
+
tabIndex={0}
|
|
21
|
+
data-test-id={'edit-link-button'}
|
|
22
|
+
className="tw-transition tw-cursor-pointer tw-rounded hover:tw-bg-black-10 tw-p-1"
|
|
23
|
+
>
|
|
24
|
+
<FloatingLink.EditButton>
|
|
25
|
+
<IconPen16 />
|
|
26
|
+
</FloatingLink.EditButton>
|
|
27
|
+
</span>
|
|
28
|
+
|
|
29
|
+
<span
|
|
30
|
+
role="button"
|
|
31
|
+
tabIndex={0}
|
|
32
|
+
data-test-id={'remove-link-button'}
|
|
33
|
+
className="tw-transition tw-cursor-pointer tw-rounded hover:tw-bg-black-10 tw-p-1"
|
|
34
|
+
>
|
|
35
|
+
<FloatingLink.UnlinkButton>
|
|
36
|
+
<IconTrashBin16 />
|
|
37
|
+
</FloatingLink.UnlinkButton>
|
|
38
|
+
</span>
|
|
39
|
+
</span>
|
|
40
|
+
</span>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ELEMENT_LINK,
|
|
5
|
+
FloatingLinkProps,
|
|
6
|
+
HTMLPropsAs,
|
|
7
|
+
LinkPlugin,
|
|
8
|
+
floatingLinkActions,
|
|
9
|
+
floatingLinkSelectors,
|
|
10
|
+
getAboveNode,
|
|
11
|
+
getDefaultBoundingClientRect,
|
|
12
|
+
getEndPoint,
|
|
13
|
+
getPluginOptions,
|
|
14
|
+
getPluginType,
|
|
15
|
+
getRangeBoundingClientRect,
|
|
16
|
+
getStartPoint,
|
|
17
|
+
someNode,
|
|
18
|
+
triggerFloatingLinkEdit,
|
|
19
|
+
useComposedRef,
|
|
20
|
+
useEditorRef,
|
|
21
|
+
useFloatingLinkEnter,
|
|
22
|
+
useFloatingLinkEscape,
|
|
23
|
+
useFloatingLinkSelectors,
|
|
24
|
+
useHotkeys,
|
|
25
|
+
usePlateSelectors,
|
|
26
|
+
useVirtualFloatingLink,
|
|
27
|
+
} from '@udecode/plate';
|
|
28
|
+
import { useCallback, useEffect } from 'react';
|
|
29
|
+
import { getUrlFromEditor } from '../../utils';
|
|
30
|
+
|
|
31
|
+
export const useFloatingLinkEdit = ({ floatingOptions, ...props }: FloatingLinkProps): HTMLPropsAs<'div'> => {
|
|
32
|
+
const editor = useEditorRef();
|
|
33
|
+
const keyEditor = usePlateSelectors().keyEditor();
|
|
34
|
+
const mode = useFloatingLinkSelectors().mode();
|
|
35
|
+
const open = useFloatingLinkSelectors().isOpen(editor.id);
|
|
36
|
+
|
|
37
|
+
const { triggerFloatingLinkHotkeys = 'command+k, ctrl+k' } = getPluginOptions<LinkPlugin>(editor, ELEMENT_LINK);
|
|
38
|
+
|
|
39
|
+
const getBoundingClientRect = useCallback(() => {
|
|
40
|
+
const entry = getAboveNode(editor, {
|
|
41
|
+
match: { type: getPluginType(editor, ELEMENT_LINK) },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (entry) {
|
|
45
|
+
const [, path] = entry;
|
|
46
|
+
return getRangeBoundingClientRect(editor, {
|
|
47
|
+
anchor: getStartPoint(editor, path),
|
|
48
|
+
focus: getEndPoint(editor, path),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return getDefaultBoundingClientRect();
|
|
53
|
+
}, [editor]);
|
|
54
|
+
|
|
55
|
+
const isOpen = open && mode === 'edit';
|
|
56
|
+
|
|
57
|
+
const { update, style, floating } = useVirtualFloatingLink({
|
|
58
|
+
editorId: editor.id,
|
|
59
|
+
open: isOpen,
|
|
60
|
+
getBoundingClientRect,
|
|
61
|
+
...floatingOptions,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const url = getUrlFromEditor(editor);
|
|
66
|
+
if (url) {
|
|
67
|
+
floatingLinkActions.url(url);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
editor.selection &&
|
|
72
|
+
someNode(editor, {
|
|
73
|
+
match: { type: getPluginType(editor, ELEMENT_LINK) },
|
|
74
|
+
})
|
|
75
|
+
) {
|
|
76
|
+
floatingLinkActions.show('edit', editor.id);
|
|
77
|
+
update();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (floatingLinkSelectors.mode() === 'edit') {
|
|
82
|
+
floatingLinkActions.hide();
|
|
83
|
+
}
|
|
84
|
+
}, [editor, keyEditor, update]);
|
|
85
|
+
|
|
86
|
+
useHotkeys(
|
|
87
|
+
triggerFloatingLinkHotkeys,
|
|
88
|
+
(e) => {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
|
|
91
|
+
if (floatingLinkSelectors.mode() === 'edit') {
|
|
92
|
+
triggerFloatingLinkEdit(editor);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
enableOnContentEditable: true,
|
|
97
|
+
},
|
|
98
|
+
[]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
useFloatingLinkEnter();
|
|
102
|
+
|
|
103
|
+
useFloatingLinkEscape();
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
style: {
|
|
107
|
+
...style,
|
|
108
|
+
zIndex: 1000,
|
|
109
|
+
},
|
|
110
|
+
...props,
|
|
111
|
+
ref: useComposedRef<HTMLElement | null>(props.ref, floating),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
FloatingLinkProps,
|
|
5
|
+
FloatingLink as PlateFloatingLink,
|
|
6
|
+
createComponentAs,
|
|
7
|
+
createElementAs,
|
|
8
|
+
} from '@udecode/plate';
|
|
9
|
+
import { useFloatingLinkEdit } from './EditLinkModal';
|
|
10
|
+
import { useFloatingLinkInsert } from './InsertLinkModal/useFloatingLinkInsert';
|
|
11
|
+
|
|
12
|
+
const FloatingLinkInsertRoot = createComponentAs<FloatingLinkProps>((props) => {
|
|
13
|
+
const htmlProps = useFloatingLinkInsert({
|
|
14
|
+
...props,
|
|
15
|
+
floatingOptions: {
|
|
16
|
+
strategy: 'absolute',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (htmlProps.style?.display === 'none') {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return createElementAs('div', htmlProps);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const FloatingLinkEditRoot = createComponentAs<FloatingLinkProps>((props) => {
|
|
28
|
+
const htmlProps = useFloatingLinkEdit({
|
|
29
|
+
...props,
|
|
30
|
+
floatingOptions: {
|
|
31
|
+
strategy: 'absolute',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (htmlProps.style?.display === 'none') {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return createElementAs('div', htmlProps);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
PlateFloatingLink.EditRoot = FloatingLinkEditRoot;
|
|
43
|
+
PlateFloatingLink.InsertRoot = FloatingLinkInsertRoot;
|
|
44
|
+
|
|
45
|
+
export const FloatingLink = PlateFloatingLink;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { AppBridgeBlock } from '@frontify/app-bridge';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
ButtonEmphasis,
|
|
7
|
+
ButtonSize,
|
|
8
|
+
ButtonStyle,
|
|
9
|
+
Checkbox,
|
|
10
|
+
FormControl,
|
|
11
|
+
IconCheckMark20,
|
|
12
|
+
TextInput,
|
|
13
|
+
} from '@frontify/fondue';
|
|
14
|
+
import { FC, ReactNode } from 'react';
|
|
15
|
+
import { LinkSelector } from '../../../shared/LinkSelector';
|
|
16
|
+
import { InsertModalStateProps } from './types';
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
state: InsertModalStateProps;
|
|
20
|
+
onTextChange: (value: string) => void;
|
|
21
|
+
onUrlChange: (value: string) => void;
|
|
22
|
+
onToggleTab: (checked: boolean) => void;
|
|
23
|
+
onCancel: () => void;
|
|
24
|
+
onSave: (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | KeyboardEvent | undefined) => void;
|
|
25
|
+
hasValues: boolean;
|
|
26
|
+
isValidUrlOrEmpty: (url: string) => boolean | undefined;
|
|
27
|
+
testId?: string;
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
appBridge: AppBridgeBlock;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const InsertModal: FC<Props> = ({
|
|
33
|
+
state,
|
|
34
|
+
onTextChange,
|
|
35
|
+
onUrlChange,
|
|
36
|
+
onToggleTab,
|
|
37
|
+
onCancel,
|
|
38
|
+
onSave,
|
|
39
|
+
isValidUrlOrEmpty,
|
|
40
|
+
hasValues,
|
|
41
|
+
testId,
|
|
42
|
+
appBridge,
|
|
43
|
+
children,
|
|
44
|
+
}) => (
|
|
45
|
+
<div data-test-id={testId} className="tw-bg-white tw-rounded tw-shadow tw-p-7 tw-min-w-[400px] tw-overflow-y-auto">
|
|
46
|
+
<FormControl
|
|
47
|
+
label={{
|
|
48
|
+
children: 'Text',
|
|
49
|
+
htmlFor: 'linkText',
|
|
50
|
+
required: true,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<TextInput id="linkText" value={state.text} placeholder="Link Text" onChange={onTextChange} />
|
|
54
|
+
</FormControl>
|
|
55
|
+
|
|
56
|
+
{children}
|
|
57
|
+
|
|
58
|
+
<div className="tw-pt-5">
|
|
59
|
+
<FormControl
|
|
60
|
+
label={{
|
|
61
|
+
children: 'URL',
|
|
62
|
+
htmlFor: 'url',
|
|
63
|
+
required: true,
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<TextInput
|
|
67
|
+
id="url"
|
|
68
|
+
value={state.url}
|
|
69
|
+
placeholder="https://example.com"
|
|
70
|
+
focusOnMount
|
|
71
|
+
onChange={onUrlChange}
|
|
72
|
+
/>
|
|
73
|
+
</FormControl>
|
|
74
|
+
{!isValidUrlOrEmpty(state?.url) && <div className="tw-text-red-65 tw-mt-3">Please enter a valid URL.</div>}
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<div className="tw-mt-3">
|
|
78
|
+
<LinkSelector url={state.url} appBridge={appBridge} onUrlChange={onUrlChange} />
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<div className="tw-mt-3">
|
|
82
|
+
<Checkbox value="new-tab" label="Open in new tab" state={state.newTab} onChange={onToggleTab} />
|
|
83
|
+
</div>
|
|
84
|
+
<div className="tw-mt-3">
|
|
85
|
+
<div className={'tw-pt-5 tw-flex tw-gap-x-3 tw-justify-end tw-border-t tw-border-t-black-10'}>
|
|
86
|
+
<Button
|
|
87
|
+
onClick={onCancel}
|
|
88
|
+
size={ButtonSize.Medium}
|
|
89
|
+
style={ButtonStyle.Default}
|
|
90
|
+
emphasis={ButtonEmphasis.Default}
|
|
91
|
+
>
|
|
92
|
+
Cancel
|
|
93
|
+
</Button>
|
|
94
|
+
<Button
|
|
95
|
+
onClick={onSave}
|
|
96
|
+
size={ButtonSize.Medium}
|
|
97
|
+
icon={<IconCheckMark20 />}
|
|
98
|
+
disabled={!hasValues || !isValidUrlOrEmpty(state?.url)}
|
|
99
|
+
>
|
|
100
|
+
Save
|
|
101
|
+
</Button>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/types.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { CheckboxState } from '@frontify/fondue';
|
|
4
|
+
|
|
5
|
+
export type InsertModalDispatchType = { type: string; payload?: Partial<InsertModalStateProps> };
|
|
6
|
+
|
|
7
|
+
export type InsertModalStateProps = {
|
|
8
|
+
url: string;
|
|
9
|
+
text: string;
|
|
10
|
+
newTab: CheckboxState;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type InitiallyExpandedItems = {
|
|
14
|
+
documentId: number | undefined;
|
|
15
|
+
pageId: number | undefined;
|
|
16
|
+
};
|