@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.
Files changed (214) hide show
  1. package/.eslintrc.js +1 -1
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +24 -5
  4. package/package.json +46 -10
  5. package/postcss.config.js +8 -0
  6. package/setupTests.ts +13 -0
  7. package/src/components/Attachments/AttachmentItem.tsx +257 -0
  8. package/src/components/Attachments/Attachments.spec.ct.tsx +151 -0
  9. package/src/components/Attachments/Attachments.tsx +221 -0
  10. package/src/components/Attachments/index.ts +4 -0
  11. package/src/components/Attachments/types.ts +30 -0
  12. package/src/components/BlockInjectButton/BlockInjectButton.spec.ct.tsx +48 -0
  13. package/src/components/BlockInjectButton/BlockInjectButton.tsx +212 -0
  14. package/src/components/BlockInjectButton/index.ts +4 -0
  15. package/src/components/BlockInjectButton/types.ts +18 -0
  16. package/src/components/BlockItemWrapper/BlockItemWrapper.spec.ct.tsx +146 -0
  17. package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +76 -0
  18. package/src/components/BlockItemWrapper/Toolbar.tsx +128 -0
  19. package/src/components/BlockItemWrapper/constants.ts +4 -0
  20. package/src/components/BlockItemWrapper/index.ts +5 -0
  21. package/src/components/BlockItemWrapper/types.ts +46 -0
  22. package/src/components/DownloadButton/DownloadButton.spec.ct.tsx +20 -0
  23. package/src/components/DownloadButton/DownloadButton.tsx +36 -0
  24. package/src/components/DownloadButton/index.ts +3 -0
  25. package/src/components/DownloadButton/types.ts +5 -0
  26. package/src/components/RichTextEditor/RichTextEditor.spec.ct.tsx +204 -0
  27. package/src/components/RichTextEditor/RichTextEditor.tsx +62 -0
  28. package/src/components/RichTextEditor/SerializedText.tsx +25 -0
  29. package/src/components/RichTextEditor/constants.ts +3 -0
  30. package/src/components/RichTextEditor/index.ts +6 -0
  31. package/src/components/RichTextEditor/pluginPresets/defaultPluginsWithLinkChooser.tsx +53 -0
  32. package/src/components/RichTextEditor/pluginPresets/index.ts +3 -0
  33. package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/ButtonMarkupElementNode.tsx +74 -0
  34. package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/index.ts +11 -0
  35. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonButton.tsx +20 -0
  36. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonToolbarButton.tsx +56 -0
  37. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/CustomFloatingButton.tsx +19 -0
  38. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/EditButtonModal/EditModal.tsx +42 -0
  39. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButton.tsx +37 -0
  40. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonEditButton.tsx +22 -0
  41. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonUrlInput.tsx +30 -0
  42. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/InsertButtonModal.tsx +81 -0
  43. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/types.ts +13 -0
  44. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/useInsertModal.ts +143 -0
  45. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/UnlinkButton.tsx +31 -0
  46. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.ts +46 -0
  47. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/index.ts +12 -0
  48. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEdit.ts +113 -0
  49. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEnter.ts +21 -0
  50. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEscape.ts +30 -0
  51. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonInsert.ts +71 -0
  52. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useVirtualFloatingButton.ts +22 -0
  53. package/src/components/RichTextEditor/plugins/ButtonPlugin/components/index.ts +3 -0
  54. package/src/components/RichTextEditor/plugins/ButtonPlugin/createButtonPlugin.ts +116 -0
  55. package/src/components/RichTextEditor/plugins/ButtonPlugin/index.ts +7 -0
  56. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/index.ts +8 -0
  57. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/insertButton.ts +17 -0
  58. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/submitFloatingButton.ts +40 -0
  59. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/unwrapButton.ts +68 -0
  60. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButton.ts +198 -0
  61. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButtonText.ts +40 -0
  62. package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/wrapButton.ts +30 -0
  63. package/src/components/RichTextEditor/plugins/ButtonPlugin/types.ts +13 -0
  64. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/createButtonNode.ts +28 -0
  65. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getButtonStyle.ts +14 -0
  66. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getUrl.ts +18 -0
  67. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/index.ts +8 -0
  68. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/styles.ts +77 -0
  69. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButton.ts +23 -0
  70. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonEdit.ts +30 -0
  71. package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.ts +45 -0
  72. package/src/components/RichTextEditor/plugins/ButtonPlugin/withButton.ts +106 -0
  73. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/CustomFloatingLink.tsx +26 -0
  74. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.tsx +43 -0
  75. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/index.ts +4 -0
  76. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/useFloatingLinkEdit.ts +113 -0
  77. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/FloatingLink.tsx +45 -0
  78. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertLinkModal.tsx +5 -0
  79. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertModal.tsx +105 -0
  80. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/index.ts +4 -0
  81. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/types.ts +16 -0
  82. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useFloatingLinkInsert.ts +73 -0
  83. package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useInsertModal.ts +136 -0
  84. package/src/components/RichTextEditor/plugins/LinkPlugin/LinkButton.tsx +38 -0
  85. package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/LinkMarkupElementNode.tsx +36 -0
  86. package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/index.ts +11 -0
  87. package/src/components/RichTextEditor/plugins/LinkPlugin/id.ts +3 -0
  88. package/src/components/RichTextEditor/plugins/LinkPlugin/index.ts +48 -0
  89. package/src/components/RichTextEditor/plugins/LinkPlugin/types.ts +12 -0
  90. package/src/components/RichTextEditor/plugins/LinkPlugin/utils/getUrl.ts +30 -0
  91. package/src/components/RichTextEditor/plugins/LinkPlugin/utils/index.ts +4 -0
  92. package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.spec.ts +35 -0
  93. package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.ts +3 -0
  94. package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.spec.ts +75 -0
  95. package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.ts +21 -0
  96. package/src/components/RichTextEditor/plugins/TextStylePlugins/custom1Plugin.tsx +61 -0
  97. package/src/components/RichTextEditor/plugins/TextStylePlugins/custom2Plugin.tsx +61 -0
  98. package/src/components/RichTextEditor/plugins/TextStylePlugins/custom3Plugin.tsx +62 -0
  99. package/src/components/RichTextEditor/plugins/TextStylePlugins/heading1Plugin.tsx +61 -0
  100. package/src/components/RichTextEditor/plugins/TextStylePlugins/heading2Plugin.tsx +58 -0
  101. package/src/components/RichTextEditor/plugins/TextStylePlugins/heading3Plugin.tsx +58 -0
  102. package/src/components/RichTextEditor/plugins/TextStylePlugins/heading4Plugin.tsx +59 -0
  103. package/src/components/RichTextEditor/plugins/TextStylePlugins/helpers.tsx +44 -0
  104. package/src/components/RichTextEditor/plugins/TextStylePlugins/imageCaptionPlugin.tsx +61 -0
  105. package/src/components/RichTextEditor/plugins/TextStylePlugins/imageTitlePlugin.tsx +61 -0
  106. package/src/components/RichTextEditor/plugins/TextStylePlugins/index.ts +15 -0
  107. package/src/components/RichTextEditor/plugins/TextStylePlugins/paragraphPlugin.tsx +58 -0
  108. package/src/components/RichTextEditor/plugins/TextStylePlugins/quotePlugin.tsx +62 -0
  109. package/src/components/RichTextEditor/plugins/index.ts +6 -0
  110. package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLink.tsx +80 -0
  111. package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLinks.tsx +97 -0
  112. package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.spec.ct.tsx +138 -0
  113. package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.tsx +80 -0
  114. package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLink.tsx +83 -0
  115. package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLinks.tsx +68 -0
  116. package/src/components/RichTextEditor/plugins/shared/LinkSelector/SectionLink.tsx +37 -0
  117. package/src/components/RichTextEditor/plugins/shared/LinkSelector/index.ts +3 -0
  118. package/src/components/RichTextEditor/plugins/styles.ts +179 -0
  119. package/src/components/RichTextEditor/serializer/index.ts +3 -0
  120. package/src/components/RichTextEditor/serializer/nodes/button.ts +25 -0
  121. package/src/components/RichTextEditor/serializer/nodes/checkItemNode.ts +29 -0
  122. package/src/components/RichTextEditor/serializer/nodes/default.ts +52 -0
  123. package/src/components/RichTextEditor/serializer/nodes/link.ts +25 -0
  124. package/src/components/RichTextEditor/serializer/nodes/mentionHtmlNode.ts +17 -0
  125. package/src/components/RichTextEditor/serializer/serializeNodesToHtmlRecursive.ts +134 -0
  126. package/src/components/RichTextEditor/serializer/serializeToHtml.ts +49 -0
  127. package/src/components/RichTextEditor/serializer/utlis/reactCssPropsToCss.ts +21 -0
  128. package/src/components/RichTextEditor/serializer/utlis/serializeLeafToHtml.ts +32 -0
  129. package/src/components/RichTextEditor/types.ts +23 -0
  130. package/src/components/index.ts +7 -0
  131. package/src/helpers/addHttps.spec.ts +42 -0
  132. package/src/helpers/addHttps.ts +15 -0
  133. package/src/helpers/convertToRichTextValue.spec.ts +32 -0
  134. package/src/helpers/convertToRichTextValue.ts +6 -0
  135. package/src/helpers/customCoordinatesGetterFactory.spec.ts +69 -0
  136. package/src/helpers/customCoordinatesGetterFactory.ts +39 -0
  137. package/src/helpers/hasRichTextValue.spec.ts +63 -0
  138. package/src/helpers/hasRichTextValue.ts +29 -0
  139. package/src/helpers/index.ts +8 -0
  140. package/src/helpers/isDownloadable.spec.ts +47 -0
  141. package/src/helpers/isDownloadable.ts +7 -0
  142. package/src/helpers/mapColorPalettes.spec.ts +146 -0
  143. package/src/helpers/mapColorPalettes.ts +22 -0
  144. package/src/hooks/index.ts +4 -0
  145. package/src/hooks/useAttachments.spec.ts +79 -0
  146. package/src/hooks/useAttachments.ts +46 -0
  147. package/src/hooks/useDndSensors.spec.ts +40 -0
  148. package/src/hooks/useDndSensors.ts +23 -0
  149. package/src/index.ts +8 -0
  150. package/src/settings/background.spec.ts +173 -0
  151. package/src/settings/background.ts +49 -0
  152. package/src/settings/border.spec.ts +76 -0
  153. package/src/settings/border.ts +90 -0
  154. package/src/settings/borderRadius.spec.ts +30 -0
  155. package/src/settings/borderRadius.ts +73 -0
  156. package/src/settings/borderRadiusExtended.spec.ts +52 -0
  157. package/src/settings/borderRadiusExtended.ts +84 -0
  158. package/src/settings/defaultValues.ts +21 -0
  159. package/src/settings/gutter.spec.ts +60 -0
  160. package/src/settings/gutter.ts +75 -0
  161. package/src/settings/index.ts +14 -0
  162. package/src/settings/margin.spec.ts +42 -0
  163. package/src/settings/margin.ts +72 -0
  164. package/src/settings/marginExtended.spec.ts +45 -0
  165. package/src/settings/marginExtended.ts +91 -0
  166. package/src/settings/padding.spec.ts +42 -0
  167. package/src/settings/padding.ts +73 -0
  168. package/src/settings/paddingExtended.spec.ts +45 -0
  169. package/src/settings/paddingExtended.ts +91 -0
  170. package/src/settings/security.spec.ts +87 -0
  171. package/src/settings/security.ts +61 -0
  172. package/src/settings/securityDownloadable.spec.ts +46 -0
  173. package/src/settings/securityDownloadable.ts +33 -0
  174. package/src/settings/securityGlobalControl.ts +42 -0
  175. package/src/settings/types.ts +128 -0
  176. package/src/utilities/color/getReadableColor.spec.ts +32 -0
  177. package/src/utilities/color/getReadableColor.ts +34 -0
  178. package/src/utilities/color/index.ts +10 -0
  179. package/src/utilities/color/isDark.spec.ts +33 -0
  180. package/src/utilities/color/isDark.ts +29 -0
  181. package/src/utilities/color/setAlpha.spec.ts +28 -0
  182. package/src/utilities/color/setAlpha.ts +14 -0
  183. package/src/utilities/color/toColorObject.spec.ts +19 -0
  184. package/src/utilities/color/toColorObject.ts +16 -0
  185. package/src/utilities/color/toHex8String.spec.ts +17 -0
  186. package/src/utilities/color/toHex8String.ts +14 -0
  187. package/src/utilities/color/toHexString.spec.ts +17 -0
  188. package/src/utilities/color/toHexString.ts +10 -0
  189. package/src/utilities/color/toRgbaString.spec.ts +12 -0
  190. package/src/utilities/color/toRgbaString.ts +14 -0
  191. package/src/utilities/color/toShortRgba.spec.ts +16 -0
  192. package/src/utilities/color/toShortRgba.ts +35 -0
  193. package/src/utilities/index.ts +5 -0
  194. package/src/utilities/moveItemInArray.spec.ts +17 -0
  195. package/src/utilities/moveItemInArray.ts +21 -0
  196. package/src/utilities/react/getBackgroundColorStyles.spec.ts +18 -0
  197. package/src/utilities/react/getBackgroundColorStyles.ts +11 -0
  198. package/src/utilities/react/getBorderStyles.spec.ts +39 -0
  199. package/src/utilities/react/getBorderStyles.ts +21 -0
  200. package/src/utilities/react/getRadiusStyles.spec.ts +25 -0
  201. package/src/utilities/react/getRadiusStyles.ts +8 -0
  202. package/src/utilities/react/index.ts +6 -0
  203. package/src/utilities/react/joinClassNames.spec.ts +18 -0
  204. package/src/utilities/react/joinClassNames.ts +10 -0
  205. package/tailwind.config.js +27 -0
  206. package/tsconfig.json +3 -1
  207. package/vite.config.ts +11 -1
  208. package/dist/index.cjs.js +0 -2
  209. package/dist/index.cjs.js.map +0 -1
  210. package/dist/index.d.ts +0 -147
  211. package/dist/index.es.js +0 -9
  212. package/dist/index.es.js.map +0 -1
  213. package/dist/index.umd.js +0 -2
  214. package/dist/index.umd.js.map +0 -1
@@ -0,0 +1,179 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { CSSProperties } from 'react';
4
+ import { LINK_PLUGIN } from './LinkPlugin/id';
5
+ import { BlockButtonStyles } from './ButtonPlugin';
6
+
7
+ export const enum TextStyles {
8
+ heading1 = 'heading1',
9
+ heading2 = 'heading2',
10
+ heading3 = 'heading3',
11
+ heading4 = 'heading4',
12
+ custom1 = 'custom1',
13
+ custom2 = 'custom2',
14
+ custom3 = 'custom3',
15
+ quote = 'quote',
16
+ imageCaption = 'imageCaption',
17
+ imageTitle = 'imageTitle',
18
+ p = 'p',
19
+ }
20
+ export const BlockStyles: Record<string, CSSProperties & { hover?: CSSProperties }> = {
21
+ [TextStyles.heading1]: {
22
+ display: 'inline-block',
23
+ fontSize: 'var(--f-theme-settings-heading1-font-size)',
24
+ lineHeight: 'var(--f-theme-settings-heading1-line-height)',
25
+ marginTop: 'var(--f-theme-settings-heading1-margin-top)',
26
+ marginBottom: 'var(--f-theme-settings-heading1-margin-bottom)',
27
+ textDecoration: 'var(--f-theme-settings-heading1-text-decoration)',
28
+ fontStyle: 'var(--f-theme-settings-heading1-font-style)',
29
+ textTransform: 'var(--f-theme-settings-heading1-text-transform)' as CSSProperties['textTransform'],
30
+ letterSpacing: 'var(--f-theme-settings-heading1-letter-spacing)',
31
+ fontWeight: 'var(--f-theme-settings-heading1-font-weight)',
32
+ fontFamily: 'var(--f-theme-settings-heading1-font-family)',
33
+ color: 'var(--f-theme-settings-heading1-color)',
34
+ },
35
+ [TextStyles.heading2]: {
36
+ fontSize: 'var(--f-theme-settings-heading2-font-size)',
37
+ lineHeight: 'var(--f-theme-settings-heading2-line-height)',
38
+ marginTop: 'var(--f-theme-settings-heading2-margin-top)',
39
+ marginBottom: 'var(--f-theme-settings-heading2-margin-bottom)',
40
+ textDecoration: 'var(--f-theme-settings-heading2-text-decoration)',
41
+ fontStyle: 'var(--f-theme-settings-heading2-font-style)',
42
+ textTransform: 'var(--f-theme-settings-heading2-text-transform)' as CSSProperties['textTransform'],
43
+ letterSpacing: 'var(--f-theme-settings-heading2-letter-spacing)',
44
+ fontWeight: 'var(--f-theme-settings-heading2-font-weight)',
45
+ fontFamily: 'var(--f-theme-settings-heading2-font-family)',
46
+ color: 'var(--f-theme-settings-heading2-color)',
47
+ },
48
+ [TextStyles.heading3]: {
49
+ fontSize: 'var(--f-theme-settings-heading3-font-size)',
50
+ lineHeight: 'var(--f-theme-settings-heading3-line-height)',
51
+ marginTop: 'var(--f-theme-settings-heading3-margin-top)',
52
+ marginBottom: 'var(--f-theme-settings-heading3-margin-bottom)',
53
+ textDecoration: 'var(--f-theme-settings-heading3-text-decoration)',
54
+ fontStyle: 'var(--f-theme-settings-heading3-font-style)',
55
+ textTransform: 'var(--f-theme-settings-heading3-text-transform)' as CSSProperties['textTransform'],
56
+ letterSpacing: 'var(--f-theme-settings-heading3-letter-spacing)',
57
+ fontWeight: 'var(--f-theme-settings-heading3-font-weight)',
58
+ fontFamily: 'var(--f-theme-settings-heading3-font-family)',
59
+ color: 'var(--f-theme-settings-heading3-color)',
60
+ },
61
+ [TextStyles.heading4]: {
62
+ fontSize: 'var(--f-theme-settings-heading4-font-size)',
63
+ lineHeight: 'var(--f-theme-settings-heading4-line-height)',
64
+ marginTop: 'var(--f-theme-settings-heading4-margin-top)',
65
+ marginBottom: 'var(--f-theme-settings-heading4-margin-bottom)',
66
+ textDecoration: 'var(--f-theme-settings-heading4-text-decoration)',
67
+ fontStyle: 'var(--f-theme-settings-heading4-font-style)',
68
+ textTransform: 'var(--f-theme-settings-heading4-text-transform)' as CSSProperties['textTransform'],
69
+ letterSpacing: 'var(--f-theme-settings-heading4-letter-spacing)',
70
+ fontWeight: 'var(--f-theme-settings-heading4-font-weight)',
71
+ fontFamily: 'var(--f-theme-settings-heading4-font-family)',
72
+ color: 'var(--f-theme-settings-heading4-color)',
73
+ },
74
+ [TextStyles.custom1]: {
75
+ fontSize: 'var(--f-theme-settings-custom1-font-size)',
76
+ lineHeight: 'var(--f-theme-settings-custom1-line-height)',
77
+ marginTop: 'var(--f-theme-settings-custom1-margin-top)',
78
+ marginBottom: 'var(--f-theme-settings-custom1-margin-bottom)',
79
+ textDecoration: 'var(--f-theme-settings-custom1-text-decoration)',
80
+ fontStyle: 'var(--f-theme-settings-custom1-font-style)',
81
+ textTransform: 'var(--f-theme-settings-custom1-text-transform)' as CSSProperties['textTransform'],
82
+ letterSpacing: 'var(--f-theme-settings-custom1-letter-spacing)',
83
+ fontWeight: 'var(--f-theme-settings-custom1-font-weight)',
84
+ fontFamily: 'var(--f-theme-settings-custom1-font-family)',
85
+ color: 'var(--f-theme-settings-custom1-color)',
86
+ },
87
+ [TextStyles.custom2]: {
88
+ fontSize: 'var(--f-theme-settings-custom2-font-size)',
89
+ lineHeight: 'var(--f-theme-settings-custom2-line-height)',
90
+ marginTop: 'var(--f-theme-settings-custom2-margin-top)',
91
+ marginBottom: 'var(--f-theme-settings-custom2-margin-bottom)',
92
+ textDecoration: 'var(--f-theme-settings-custom2-text-decoration)',
93
+ fontStyle: 'var(--f-theme-settings-custom2-font-style)',
94
+ textTransform: 'var(--f-theme-settings-custom2-text-transform)' as CSSProperties['textTransform'],
95
+ letterSpacing: 'var(--f-theme-settings-custom2-letter-spacing)',
96
+ fontWeight: 'var(--f-theme-settings-custom2-font-weight)',
97
+ fontFamily: 'var(--f-theme-settings-custom2-font-family)',
98
+ color: 'var(--f-theme-settings-custom2-color)',
99
+ },
100
+ [TextStyles.custom3]: {
101
+ fontSize: 'var(--f-theme-settings-custom3-font-size)',
102
+ lineHeight: 'var(--f-theme-settings-custom3-line-height)',
103
+ marginTop: 'var(--f-theme-settings-custom3-margin-top)',
104
+ marginBottom: 'var(--f-theme-settings-custom3-margin-bottom)',
105
+ textDecoration: 'var(--f-theme-settings-custom3-text-decoration)',
106
+ fontStyle: 'var(--f-theme-settings-custom3-font-style)',
107
+ textTransform: 'var(--f-theme-settings-custom3-text-transform)' as CSSProperties['textTransform'],
108
+ letterSpacing: 'var(--f-theme-settings-custom3-letter-spacing)',
109
+ fontWeight: 'var(--f-theme-settings-custom3-font-weight)',
110
+ fontFamily: 'var(--f-theme-settings-custom3-font-family)',
111
+ color: 'var(--f-theme-settings-custom3-color)',
112
+ },
113
+ [TextStyles.p]: {
114
+ fontSize: 'var(--f-theme-settings-body-font-size)',
115
+ lineHeight: 'var(--f-theme-settings-body-line-height)',
116
+ marginTop: 'var(--f-theme-settings-body-margin-top)',
117
+ marginBottom: 'var(--f-theme-settings-body-margin-bottom)',
118
+ textDecoration: 'var(--f-theme-settings-body-text-decoration)',
119
+ fontStyle: 'var(--f-theme-settings-body-font-style)',
120
+ textTransform: 'var(--f-theme-settings-body-text-transform)' as CSSProperties['textTransform'],
121
+ letterSpacing: 'var(--f-theme-settings-body-letter-spacing)',
122
+ fontWeight: 'var(--f-theme-settings-body-font-weight)',
123
+ fontFamily: 'var(--f-theme-settings-body-font-family)',
124
+ color: 'var(--f-theme-settings-body-color)',
125
+ },
126
+ [TextStyles.quote]: {
127
+ fontSize: 'var(--f-theme-settings-quote-font-size)',
128
+ lineHeight: 'var(--f-theme-settings-quote-line-height)',
129
+ marginTop: 'var(--f-theme-settings-quote-margin-top)',
130
+ marginBottom: 'var(--f-theme-settings-quote-margin-bottom)',
131
+ textDecoration: 'var(--f-theme-settings-quote-text-decoration)',
132
+ fontStyle: 'var(--f-theme-settings-quote-font-style)',
133
+ textTransform: 'var(--f-theme-settings-quote-text-transform)' as CSSProperties['textTransform'],
134
+ letterSpacing: 'var(--f-theme-settings-quote-letter-spacing)',
135
+ fontWeight: 'var(--f-theme-settings-quote-font-weight)',
136
+ fontFamily: 'var(--f-theme-settings-quote-font-family)',
137
+ color: 'var(--f-theme-settings-quote-color)',
138
+ },
139
+ [TextStyles.imageCaption]: {
140
+ fontSize: 'var(--f-theme-settings-image-caption-font-size)',
141
+ lineHeight: 'var(--f-theme-settings-image-caption-line-height)',
142
+ marginTop: 'var(--f-theme-settings-image-caption-margin-top)',
143
+ marginBottom: 'var(--f-theme-settings-image-caption-margin-bottom)',
144
+ textDecoration: 'var(--f-theme-settings-image-caption-text-decoration)',
145
+ fontStyle: 'var(--f-theme-settings-image-caption-font-style)',
146
+ textTransform: 'var(--f-theme-settings-image-caption-text-transform)' as CSSProperties['textTransform'],
147
+ letterSpacing: 'var(--f-theme-settings-image-caption-letter-spacing)',
148
+ fontWeight: 'var(--f-theme-settings-image-caption-font-weight)',
149
+ fontFamily: 'var(--f-theme-settings-image-caption-font-family)',
150
+ color: 'var(--f-theme-settings-image-caption-color)',
151
+ },
152
+ [TextStyles.imageTitle]: {
153
+ fontSize: 'var(--f-theme-settings-image-title-font-size)',
154
+ lineHeight: 'var(--f-theme-settings-image-title-line-height)',
155
+ marginTop: 'var(--f-theme-settings-image-title-margin-top)',
156
+ marginBottom: 'var(--f-theme-settings-image-title-margin-bottom)',
157
+ textDecoration: 'var(--f-theme-settings-image-title-text-decoration)',
158
+ fontStyle: 'var(--f-theme-settings-image-title-font-style)',
159
+ textTransform: 'var(--f-theme-settings-image-title-text-transform)' as CSSProperties['textTransform'],
160
+ letterSpacing: 'var(--f-theme-settings-image-title-letter-spacing)',
161
+ fontWeight: 'var(--f-theme-settings-image-title-font-weight)',
162
+ fontFamily: 'var(--f-theme-settings-image-title-font-family)',
163
+ color: 'var(--f-theme-settings-image-title-color)',
164
+ },
165
+ [LINK_PLUGIN]: {
166
+ fontSize: 'var(--f-theme-settings-link-font-size)',
167
+ lineHeight: 'var(--f-theme-settings-link-line-height)',
168
+ marginTop: 'var(--f-theme-settings-link-margin-top)',
169
+ marginBottom: 'var(--f-theme-settings-link-margin-bottom)',
170
+ textDecoration: 'var(--f-theme-settings-link-text-decoration)',
171
+ fontStyle: 'var(--f-theme-settings-link-font-style)',
172
+ textTransform: 'var(--f-theme-settings-link-text-transform)' as CSSProperties['textTransform'],
173
+ letterSpacing: 'var(--f-theme-settings-link-letter-spacing)',
174
+ fontWeight: 'var(--f-theme-settings-link-font-weight)',
175
+ fontFamily: 'var(--f-theme-settings-link-font-family)',
176
+ color: 'var(--f-theme-settings-link-color)',
177
+ },
178
+ ...BlockButtonStyles,
179
+ };
@@ -0,0 +1,3 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ export * from './serializeToHtml';
@@ -0,0 +1,25 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { TElement } from '@udecode/plate';
4
+ import { reactCssPropsToCss } from '../utlis/reactCssPropsToCss';
5
+ import { CSSProperties } from 'react';
6
+ import { BUTTON_PLUGIN } from '../../plugins';
7
+
8
+ export type ButtonStylesType = Record<string, Record<string, CSSProperties & { hover?: CSSProperties }>>;
9
+
10
+ export const buttonNode = (node: TElement, children: string, defaultClassNames: string, styles: ButtonStylesType) => {
11
+ const buttonStyles = styles[BUTTON_PLUGIN];
12
+ const buttonTypeString = (node.buttonStyle as string) ?? 'primary';
13
+ const buttonType = `button${buttonTypeString.charAt(0).toUpperCase()}${buttonTypeString.slice(1)}`;
14
+ const buttonStyle = buttonStyles[buttonType];
15
+
16
+ const defaultStyles = reactCssPropsToCss(buttonStyle);
17
+
18
+ return `<a href="${node.url}"
19
+ target="${node.target ?? '_blank'}"
20
+ style="${defaultStyles}"
21
+ class="${defaultClassNames}"
22
+ onmouseenter="this.setAttribute('style', '${defaultStyles} ${reactCssPropsToCss(buttonStyle?.hover)}');"
23
+ onmouseleave="this.setAttribute('style', '${reactCssPropsToCss(buttonStyle)}');"
24
+ >${children}</a>`;
25
+ };
@@ -0,0 +1,29 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { merge } from '@frontify/fondue';
4
+ import { TElement } from '@udecode/plate';
5
+ import { CSSProperties } from 'react';
6
+ import { reactCssPropsToCss } from '../utlis/reactCssPropsToCss';
7
+
8
+ export const checkItemNode = (
9
+ node: TElement,
10
+ children: string,
11
+ defaultClassNames: string,
12
+ styles: Record<string, CSSProperties & { hover?: CSSProperties }>
13
+ ) => {
14
+ return `<div disabled class="tw-flex tw-flex-row tw-pb-2 first-of-type:tw-ml-0 ${defaultClassNames}" style="margin-left:${
15
+ ((node.indent as number) ?? 0) * 24
16
+ }px;">
17
+ <div class="tw-flex tw-items-center tw-justify-center tw-select-none tw-mr-1.5">
18
+ <input
19
+ class="tw-w-4 tw-h-4 tw-m-0"
20
+ type="checkbox"
21
+ ${node.checked ? 'checked' : ''}
22
+ onclick="return false;" />
23
+ </div>
24
+ <span class="${merge([
25
+ 'tw-flex-1 tw-focus:outline-none',
26
+ node.checked ? '!tw-line-through' : '',
27
+ ])}" style="${reactCssPropsToCss(styles[node.children[0].textStyle as string])}">${children}</span>
28
+ </div>`;
29
+ };
@@ -0,0 +1,52 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { TElement } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import { TextStyles } from '../../plugins';
6
+ import { reactCssPropsToCss } from '../utlis/reactCssPropsToCss';
7
+ import { merge } from '@frontify/fondue';
8
+
9
+ export const defaultNode = (node: TElement, children: string, styles: CSSProperties, defaultClassNames: string) => {
10
+ const defaultStyles = reactCssPropsToCss(styles);
11
+
12
+ if (node.type === TextStyles.heading1) {
13
+ return `<h1 class="${merge([defaultClassNames, 'a-h1'])}">${getStyledChild(children, defaultStyles)}</h1>`;
14
+ }
15
+ if (node.type === TextStyles.heading2) {
16
+ return `<h2 class="${defaultClassNames}">${getStyledChild(children, defaultStyles)}</h2>`;
17
+ }
18
+ if (node.type === TextStyles.heading3) {
19
+ return `<h3 class="${defaultClassNames}">${getStyledChild(children, defaultStyles)}</h3>`;
20
+ }
21
+ if (node.type === TextStyles.heading4) {
22
+ return `<h4 class="${defaultClassNames}">${getStyledChild(children, defaultStyles)}</h4>`;
23
+ }
24
+ if (node.type === TextStyles.custom1) {
25
+ return `<p class="${merge([defaultClassNames, 'a-custom1'])}">${getStyledChild(children, defaultStyles)}</p>`;
26
+ }
27
+ if (node.type === TextStyles.custom2) {
28
+ return `<p class="${merge([defaultClassNames, 'a-custom2'])}">${getStyledChild(children, defaultStyles)}</p>`;
29
+ }
30
+ if (node.type === TextStyles.custom3) {
31
+ return `<p class="${merge([defaultClassNames, 'a-custom3'])}">${getStyledChild(children, defaultStyles)}</p>`;
32
+ }
33
+ if (node.type === TextStyles.quote) {
34
+ return `<p class="${merge([defaultClassNames, 'a-quote'])}">${getStyledChild(children, defaultStyles)}</p>`;
35
+ }
36
+ if (node.type === TextStyles.imageTitle) {
37
+ return `<p class="${merge([defaultClassNames, 'a-image-title'])}">${getStyledChild(
38
+ children,
39
+ defaultStyles
40
+ )}</p>`;
41
+ }
42
+ if (node.type === TextStyles.imageCaption) {
43
+ return `<p class="${merge([defaultClassNames, 'a-image-caption'])}">${getStyledChild(
44
+ children,
45
+ defaultStyles
46
+ )}</p>`;
47
+ }
48
+
49
+ return `<p class="${defaultClassNames}">${getStyledChild(children, defaultStyles)}</p>`;
50
+ };
51
+
52
+ const getStyledChild = (children: string, styles: string) => `<span style="${styles}">${children}</span>`;
@@ -0,0 +1,25 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { TElement } from '@udecode/plate';
4
+ import { LINK_PLUGIN } from '../../plugins/LinkPlugin/id';
5
+ import { TLinkElement } from '../../plugins/LinkPlugin/types';
6
+ import { reactCssPropsToCss } from '../utlis/reactCssPropsToCss';
7
+ import escapeHtml from 'escape-html';
8
+ import { CSSProperties } from 'react';
9
+
10
+ export const linkNode = (
11
+ node: TElement,
12
+ children: string,
13
+ defaultClassNames: string,
14
+ styles: Record<string, CSSProperties & { hover?: CSSProperties }>
15
+ ) => {
16
+ if (node.chosenLink) {
17
+ const { chosenLink } = node as TLinkElement;
18
+ return `<a class="${defaultClassNames}" style="${reactCssPropsToCss(styles[LINK_PLUGIN])}" target=${
19
+ chosenLink?.openInNewTab ? '_blank' : '_self'
20
+ } href="${escapeHtml(chosenLink?.searchResult?.link)}">${children}</a>`;
21
+ }
22
+ return `<a class="${defaultClassNames}" style="${reactCssPropsToCss(styles[LINK_PLUGIN])}" target="${
23
+ node?.target ?? '_blank'
24
+ }" href="${escapeHtml(node.url as string)}">${children}</a>`;
25
+ };
@@ -0,0 +1,17 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import ReactDOM from 'react-dom';
4
+ import { TElement, TMentionElement } from '@udecode/plate';
5
+ import { MappedMentionableItems, MentionMarkupElementNode } from '@frontify/fondue';
6
+
7
+ type MentionHtmlNodeProps = { mentionable?: MappedMentionableItems };
8
+
9
+ export const mentionHtmlNode = (node: TElement, { mentionable }: MentionHtmlNodeProps = {}) => {
10
+ if (!mentionable) {
11
+ return '';
12
+ }
13
+
14
+ const div = document.createElement('div');
15
+ ReactDOM.render(MentionMarkupElementNode(mentionable)({ element: node as TMentionElement }), div);
16
+ return div.innerHTML;
17
+ };
@@ -0,0 +1,134 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import {
4
+ ELEMENT_CHECK_ITEM,
5
+ LI_CLASSNAMES,
6
+ MappedMentionableItems,
7
+ OL_STYLES,
8
+ UL_CLASSES,
9
+ alignmentClassnames,
10
+ getLiStyles,
11
+ getLicElementClassNames,
12
+ getOrderedListClasses,
13
+ merge,
14
+ } from '@frontify/fondue';
15
+ import {
16
+ ELEMENT_LI,
17
+ ELEMENT_LIC,
18
+ ELEMENT_LINK,
19
+ ELEMENT_MENTION,
20
+ ELEMENT_OL,
21
+ ELEMENT_UL,
22
+ TDescendant,
23
+ TElement,
24
+ isText,
25
+ } from '@udecode/plate';
26
+ import { serializeLeafToHtml } from './utlis/serializeLeafToHtml';
27
+ import { reactCssPropsToCss } from './utlis/reactCssPropsToCss';
28
+ import { CSSProperties } from 'react';
29
+ import { ButtonStylesType, buttonNode } from './nodes/button';
30
+ import { linkNode } from './nodes/link';
31
+ import { defaultNode } from './nodes/default';
32
+ import { checkItemNode } from './nodes/checkItemNode';
33
+ import { mentionHtmlNode } from './nodes/mentionHtmlNode';
34
+ import { ELEMENT_BUTTON } from '../plugins';
35
+
36
+ const countNodesOfType = (nodes: TDescendant[], type: string): number => {
37
+ return nodes.reduce((acc, node) => {
38
+ if (node.type === type) {
39
+ acc++;
40
+ }
41
+ if (node.children) {
42
+ return acc + countNodesOfType(node.children as TDescendant[], type);
43
+ }
44
+ return acc;
45
+ }, 0);
46
+ };
47
+
48
+ type NestingCount = {
49
+ [type: string]: number;
50
+ };
51
+
52
+ type SerializeNodeToHtmlRecursiveOptions = {
53
+ mappedMentionable?: MappedMentionableItems;
54
+ nestingCount?: NestingCount;
55
+ };
56
+
57
+ export const serializeNodeToHtmlRecursive = (
58
+ node: TDescendant,
59
+ styles: Record<string, CSSProperties & { hover?: CSSProperties }> | ButtonStylesType,
60
+ { mappedMentionable, nestingCount = {} }: SerializeNodeToHtmlRecursiveOptions
61
+ ): string => {
62
+ if (isText(node)) {
63
+ return serializeLeafToHtml(node);
64
+ }
65
+
66
+ const rootNestingCount = nestingCount[node.type] || countNodesOfType([node], node.type);
67
+ let children = '';
68
+ for (const element of node.children) {
69
+ children += serializeNodeToHtmlRecursive(element, styles, {
70
+ nestingCount: {
71
+ ...nestingCount,
72
+ [element.type as string]: rootNestingCount,
73
+ },
74
+ mappedMentionable,
75
+ });
76
+ }
77
+
78
+ const htmlMapper = MapNodeTypesToHtml[node.type];
79
+ if (typeof htmlMapper !== 'undefined') {
80
+ return htmlMapper({
81
+ classNames: getClassNames(node.breakAfterColumn as string | undefined, node.align as string | undefined),
82
+ children,
83
+ rootNestingCount,
84
+ node,
85
+ mappedMentionable,
86
+ styles,
87
+ });
88
+ } else {
89
+ return defaultNode(
90
+ node,
91
+ children,
92
+ styles[node.type],
93
+ getClassNames(node.breakAfterColumn as string | undefined, node.align as string | undefined)
94
+ );
95
+ }
96
+ };
97
+
98
+ type Arguments = {
99
+ classNames: string;
100
+ children: string;
101
+ rootNestingCount: number;
102
+ node: TElement;
103
+ mappedMentionable?: MappedMentionableItems;
104
+ styles: Record<string, CSSProperties & { hover?: CSSProperties }> | ButtonStylesType;
105
+ };
106
+
107
+ const MapNodeTypesToHtml: { [key: string]: ({ ...args }: Arguments) => string } = {
108
+ [ELEMENT_UL]: (args) => `<ul class="${UL_CLASSES} ${args.classNames}">${args.children}</ul>`,
109
+ [ELEMENT_OL]: ({ classNames, children, node, rootNestingCount }) => {
110
+ const nestingLevel = Math.max(rootNestingCount - countNodesOfType([node], ELEMENT_OL), 0);
111
+ return `<ol class="${getOrderedListClasses(nestingLevel)} ${classNames}" style="${reactCssPropsToCss(
112
+ OL_STYLES
113
+ )}">${children}</ol>`;
114
+ },
115
+ [ELEMENT_LI]: ({ classNames, children, node, styles }) =>
116
+ `<li class="${classNames} ${LI_CLASSNAMES}" style="${reactCssPropsToCss(
117
+ getLiStyles(node, styles)
118
+ )}">${children}</li>`,
119
+ [ELEMENT_LIC]: ({ classNames, children, node }) =>
120
+ `<p class="${classNames} ${getLicElementClassNames(node)}"><span>${children}</span></p>`,
121
+ [ELEMENT_LINK]: ({ node, children, classNames, styles }) => linkNode(node, children, classNames, styles),
122
+ [ELEMENT_BUTTON]: ({ node, children, classNames, styles }) =>
123
+ buttonNode(node, children, classNames, styles as ButtonStylesType),
124
+ [ELEMENT_CHECK_ITEM]: ({ node, children, classNames, styles }) => checkItemNode(node, children, classNames, styles),
125
+ [ELEMENT_MENTION]: ({ node, mappedMentionable }) => mentionHtmlNode(node, { mentionable: mappedMentionable }),
126
+ };
127
+
128
+ const getClassNames = (breakAfterColumn?: string, align?: string) => {
129
+ const breakWordsClass = 'tw-break-words';
130
+ const columnBreakClasses =
131
+ breakAfterColumn === 'active' ? 'tw-break-after-column tw-break-inside-avoid-column' : '';
132
+ const alignClass = align ? alignmentClassnames[align] : '';
133
+ return merge([alignClass, breakWordsClass, columnBreakClasses]);
134
+ };
@@ -0,0 +1,49 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { TDescendant } from '@udecode/plate';
4
+ import { PluginComposer, SerializeNodesToHtmlOptions, mapMentionable, parseRawValue } from '@frontify/fondue';
5
+ import { BlockStyles } from '../plugins';
6
+ import { serializeNodeToHtmlRecursive } from './serializeNodesToHtmlRecursive';
7
+
8
+ export const serializeRawToHtmlAsync = async (
9
+ raw: string,
10
+ columns: SerializeNodesToHtmlOptions['columns'] = 1,
11
+ columnGap: SerializeNodesToHtmlOptions['columnGap'] = 'normal',
12
+ plugins: PluginComposer = new PluginComposer()
13
+ ): Promise<string> => {
14
+ const nodes = parseRawValue({ raw, plugins });
15
+ const styles = plugins.getStyles;
16
+ return Promise.resolve(serializeNodesToHtml(nodes, { columns, columnGap, styles }));
17
+ };
18
+
19
+ export const serializeNodesToHtml = (
20
+ nodes: TDescendant[],
21
+ { mentionable, columns = 1, columnGap = 'normal', styles = BlockStyles }: SerializeNodesToHtmlOptions = {}
22
+ ): string => {
23
+ const mappedMentionable = mentionable ? mapMentionable(mentionable) : new Map();
24
+
25
+ let html = '';
26
+ for (let i = 0, len = nodes.length; i < len; i++) {
27
+ const node = nodes[i];
28
+ if (isEmptyNode(node)) {
29
+ html += '<br />';
30
+ } else {
31
+ html += serializeNodeToHtmlRecursive(node, styles, {
32
+ mappedMentionable,
33
+ });
34
+ }
35
+ }
36
+
37
+ if (columns > 1) {
38
+ return `<div style="columns:${columns}; column-gap:${columnGap};">${html}</div>`;
39
+ }
40
+
41
+ return html;
42
+ };
43
+
44
+ const isEmptyNode = (node: TDescendant): boolean => {
45
+ if (!Array.isArray(node?.children)) {
46
+ return false;
47
+ }
48
+ return node?.children?.every((child) => child.text === '');
49
+ };
@@ -0,0 +1,21 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { CSSProperties } from 'react';
4
+
5
+ export const reactCssPropsToCss = (props?: CSSProperties): string => {
6
+ if (!props) {
7
+ return '';
8
+ }
9
+
10
+ return Object.keys(props)
11
+ .reduce<string>((acc, key) => {
12
+ const value = props[key as keyof CSSProperties];
13
+ return value ? `${acc}${convertCamelCaseToKebabCase(key)}: ${value}; ` : acc;
14
+ }, '')
15
+ .trim()
16
+ .replaceAll('"', "'");
17
+ };
18
+
19
+ const convertCamelCaseToKebabCase = (str: string): string => {
20
+ return str.replaceAll(/([A-Z])/g, '-$1').toLowerCase();
21
+ };
@@ -0,0 +1,32 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { BOLD_CLASSES, CODE_CLASSES, ITALIC_CLASSES, STRIKETHROUGH_CLASSES, UNDERLINE_CLASSES } from '@frontify/fondue';
4
+ import { TText } from '@udecode/plate';
5
+ import escapeHtml from 'escape-html';
6
+
7
+ export const serializeLeafToHtml = (node: TText): string => {
8
+ let string = escapeHtml(node.text);
9
+ string = string.replaceAll('\n', '<br />');
10
+ const { bold, italic, underline, strikethrough, code, subscript, superscript } = node;
11
+ if (bold) {
12
+ string = `<span class="${BOLD_CLASSES}">${string}</span>`;
13
+ }
14
+ if (italic) {
15
+ string = `<span class="${ITALIC_CLASSES}">${string}</span>`;
16
+ }
17
+ if (underline) {
18
+ string = `<span class="${UNDERLINE_CLASSES}">${string}</span>`;
19
+ }
20
+ if (strikethrough) {
21
+ string = `<span class="${STRIKETHROUGH_CLASSES}">${string}</span>`;
22
+ }
23
+ if (code) {
24
+ string = `<span class="${CODE_CLASSES}">${string}</span>`;
25
+ }
26
+ if (subscript) {
27
+ string = `<sub>${string}</sub>`;
28
+ } else if (superscript) {
29
+ string = `<sup>${string}</sup>`;
30
+ }
31
+ return string;
32
+ };
@@ -0,0 +1,23 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { PluginComposer } from '@frontify/fondue';
4
+
5
+ export type RichTextEditorProps = {
6
+ id?: string;
7
+ isEditing: boolean;
8
+ value?: string;
9
+ placeholder?: string;
10
+ columns?: number;
11
+ gap?: string;
12
+ plugins?: PluginComposer;
13
+ showSerializedText?: boolean;
14
+ onTextChange?: (value: string) => void;
15
+ };
16
+
17
+ export type SerializedTextProps = {
18
+ value?: string;
19
+ show?: boolean;
20
+ columns?: number;
21
+ gap?: string;
22
+ plugins?: PluginComposer;
23
+ };
@@ -0,0 +1,7 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ export * from './BlockInjectButton';
4
+ export * from './BlockItemWrapper';
5
+ export * from './Attachments';
6
+ export * from './DownloadButton';
7
+ export * from './RichTextEditor';
@@ -0,0 +1,42 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { describe, expect, it } from 'vitest';
4
+ import { addHttps } from './addHttps';
5
+
6
+ describe('String converted to Richtext value', () => {
7
+ it('should return rich text value with correct textStyle', () => {
8
+ const url = 'https://www.frontify.com';
9
+ const result = addHttps(url);
10
+ expect(result).toBe(url);
11
+ });
12
+
13
+ it('should not add https:// for mailto', () => {
14
+ const url = 'mailto:info@frontify.com';
15
+ const result = addHttps(url);
16
+ expect(result).toBe(url);
17
+ });
18
+
19
+ it('should not add https:// for tel', () => {
20
+ const url = 'tel:+41 44 552 02 22';
21
+ const result = addHttps(url);
22
+ expect(result).toBe(url);
23
+ });
24
+
25
+ it('should add https://', () => {
26
+ const url = 'frontify.com';
27
+ const result = addHttps(url);
28
+ expect(result).toBe('https://frontify.com');
29
+ });
30
+
31
+ it('should not add https:// for relative url', () => {
32
+ const url = '/document/123';
33
+ const result = addHttps(url);
34
+ expect(result).toBe(url);
35
+ });
36
+
37
+ it('should not add https:// for http://', () => {
38
+ const url = 'http://localhost:3000/document/123';
39
+ const result = addHttps(url);
40
+ expect(result).toBe(url);
41
+ });
42
+ });