@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,62 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { PlateRenderElementProps, createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ TextStyles,
11
+ alignmentClassnames,
12
+ getColumnBreakClasses,
13
+ merge,
14
+ } from '@frontify/fondue';
15
+ import { BlockStyles } from '../styles';
16
+
17
+ const ID = 'textstyle-custom3-plugin';
18
+
19
+ export class Custom3Plugin extends Plugin {
20
+ public styles: CSSProperties = {};
21
+ constructor({ styles = BlockStyles.custom3, ...props }: PluginProps = {}) {
22
+ super(TextStyles.custom3, {
23
+ label: 'Custom 3',
24
+ markupElement: new Custom3MarkupElement(),
25
+ ...props,
26
+ });
27
+ this.styles = styles;
28
+ }
29
+
30
+ plugins() {
31
+ return [createCustom3Plugin(this.styles)];
32
+ }
33
+ }
34
+
35
+ class Custom3MarkupElement extends MarkupElement {
36
+ constructor(id = ID, node = Custom3MarkupElementNode) {
37
+ super(id, node);
38
+ }
39
+ }
40
+
41
+ const Custom3MarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
42
+ const align = element.align as string;
43
+ return (
44
+ <p
45
+ {...attributes}
46
+ className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element), 'a-custom3'])}
47
+ >
48
+ <span style={styles}>{children}</span>
49
+ </p>
50
+ );
51
+ };
52
+
53
+ const createCustom3Plugin = (styles: CSSProperties) =>
54
+ createPluginFactory({
55
+ key: TextStyles.custom3,
56
+ isElement: true,
57
+ deserializeHtml: {
58
+ rules: [{ validClassName: TextStyles.custom3 }],
59
+ },
60
+ })({
61
+ component: (props: PlateRenderElementProps) => <Custom3MarkupElementNode {...props} styles={styles} />,
62
+ });
@@ -0,0 +1,61 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { PlateRenderElementProps, createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ const ID = 'textstyle-heading1-plugin';
17
+ export class Heading1Plugin extends Plugin {
18
+ public styles: CSSProperties = {};
19
+ constructor({ styles = BlockStyles.heading1, ...props }: PluginProps = {}) {
20
+ super(TextStyles.heading1, {
21
+ label: 'Heading 1',
22
+ markupElement: new Heading1MarkupElement(),
23
+ ...props,
24
+ });
25
+ this.styles = styles;
26
+ }
27
+
28
+ plugins() {
29
+ return [createHeading1Plugin(this.styles)];
30
+ }
31
+ }
32
+
33
+ class Heading1MarkupElement extends MarkupElement {
34
+ constructor(id = ID, node = Heading1MarkupElementNode) {
35
+ super(id, node);
36
+ }
37
+ }
38
+
39
+ const Heading1MarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
40
+ const align = element.align as string;
41
+ return (
42
+ <h1
43
+ {...attributes}
44
+ className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element), 'a-h1'])}
45
+ >
46
+ <span style={styles}>{children}</span>
47
+ </h1>
48
+ );
49
+ };
50
+
51
+ const createHeading1Plugin = (styles: CSSProperties) =>
52
+ createPluginFactory({
53
+ key: TextStyles.heading1,
54
+ isElement: true,
55
+ component: Heading1MarkupElementNode,
56
+ deserializeHtml: {
57
+ rules: [{ validNodeName: ['h1', 'H1'] }],
58
+ },
59
+ })({
60
+ component: (props: PlateRenderElementProps) => <Heading1MarkupElementNode {...props} styles={styles} />,
61
+ });
@@ -0,0 +1,58 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+ const ID = 'textstyle-heading2-plugin';
16
+
17
+ export class Heading2Plugin extends Plugin {
18
+ public styles: CSSProperties = {};
19
+ constructor({ styles = BlockStyles.heading2, ...props }: PluginProps = {}) {
20
+ super(TextStyles.heading2, {
21
+ label: 'Heading 2',
22
+ markupElement: new Heading2MarkupElement(),
23
+ ...props,
24
+ });
25
+ this.styles = styles;
26
+ }
27
+
28
+ plugins() {
29
+ return [createHeading2Plugin(this.styles)];
30
+ }
31
+ }
32
+
33
+ class Heading2MarkupElement extends MarkupElement {
34
+ constructor(id = ID, node = Heading2MarkupElementNode) {
35
+ super(id, node);
36
+ }
37
+ }
38
+
39
+ const Heading2MarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
40
+ const align = element.align as string;
41
+ return (
42
+ <h2 {...attributes} className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element)])}>
43
+ <span style={styles}>{children}</span>
44
+ </h2>
45
+ );
46
+ };
47
+
48
+ const createHeading2Plugin = (styles: CSSProperties) =>
49
+ createPluginFactory({
50
+ key: TextStyles.heading2,
51
+ isElement: true,
52
+ component: Heading2MarkupElementNode,
53
+ deserializeHtml: {
54
+ rules: [{ validNodeName: ['h2', 'H2'] }],
55
+ },
56
+ })({
57
+ component: (props: TextStyleRenderElementProps) => <Heading2MarkupElementNode {...props} styles={styles} />,
58
+ });
@@ -0,0 +1,58 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ const ID = 'textstyle-heading3-plugin';
17
+
18
+ export class Heading3Plugin extends Plugin {
19
+ public styles: CSSProperties = {};
20
+ constructor({ styles = BlockStyles.heading3, ...props }: PluginProps = {}) {
21
+ super(TextStyles.heading3, {
22
+ label: 'Heading 3',
23
+ markupElement: new Heading3MarkupElement(),
24
+ ...props,
25
+ });
26
+ this.styles = styles;
27
+ }
28
+
29
+ plugins() {
30
+ return [createHeading3Plugin(this.styles)];
31
+ }
32
+ }
33
+
34
+ class Heading3MarkupElement extends MarkupElement {
35
+ constructor(id = ID, node = Heading3MarkupElementNode) {
36
+ super(id, node);
37
+ }
38
+ }
39
+ const Heading3MarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
40
+ const align = element.align as string;
41
+ return (
42
+ <h3 {...attributes} className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element)])}>
43
+ <span style={styles}>{children}</span>
44
+ </h3>
45
+ );
46
+ };
47
+
48
+ const createHeading3Plugin = (styles: CSSProperties) =>
49
+ createPluginFactory({
50
+ key: TextStyles.heading3,
51
+ isElement: true,
52
+ component: Heading3MarkupElementNode,
53
+ deserializeHtml: {
54
+ rules: [{ validNodeName: ['h3', 'H3'] }],
55
+ },
56
+ })({
57
+ component: (props: TextStyleRenderElementProps) => <Heading3MarkupElementNode {...props} styles={styles} />,
58
+ });
@@ -0,0 +1,59 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ const ID = 'textstyle-heading4-plugin';
17
+
18
+ export class Heading4Plugin extends Plugin {
19
+ public styles: CSSProperties = {};
20
+ constructor({ styles = BlockStyles.heading4, ...props }: PluginProps = {}) {
21
+ super(TextStyles.heading4, {
22
+ label: 'Heading 4',
23
+ markupElement: new Heading4MarkupElement(),
24
+ ...props,
25
+ });
26
+ this.styles = styles;
27
+ }
28
+
29
+ plugins() {
30
+ return [createHeading4Plugin(this.styles)];
31
+ }
32
+ }
33
+
34
+ class Heading4MarkupElement extends MarkupElement {
35
+ constructor(id = ID, node = Heading4MarkupElementNode) {
36
+ super(id, node);
37
+ }
38
+ }
39
+
40
+ const Heading4MarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
41
+ const align = element.align as string;
42
+ return (
43
+ <h4 {...attributes} className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element)])}>
44
+ <span style={styles}>{children}</span>
45
+ </h4>
46
+ );
47
+ };
48
+
49
+ const createHeading4Plugin = (styles: CSSProperties) =>
50
+ createPluginFactory({
51
+ key: TextStyles.heading4,
52
+ isElement: true,
53
+ component: Heading4MarkupElementNode,
54
+ deserializeHtml: {
55
+ rules: [{ validNodeName: ['h4', 'H4'] }],
56
+ },
57
+ })({
58
+ component: (props: TextStyleRenderElementProps) => <Heading4MarkupElementNode {...props} styles={styles} />,
59
+ });
@@ -0,0 +1,44 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import {
4
+ Custom1Plugin,
5
+ Custom2Plugin,
6
+ Custom3Plugin,
7
+ Heading1Plugin,
8
+ Heading2Plugin,
9
+ Heading3Plugin,
10
+ Heading4Plugin,
11
+ ImageCaptionPlugin,
12
+ ImageTitlePlugin,
13
+ ParagraphPlugin,
14
+ QuotePlugin,
15
+ } from '.';
16
+ import { TextStyles } from '../styles';
17
+
18
+ export const TextStylePluginsWithoutImage = [
19
+ new Heading1Plugin(),
20
+ new Heading2Plugin(),
21
+ new Heading3Plugin(),
22
+ new Heading4Plugin(),
23
+ new Custom1Plugin(),
24
+ new Custom2Plugin(),
25
+ new Custom3Plugin(),
26
+ new QuotePlugin(),
27
+ new ParagraphPlugin(),
28
+ ];
29
+
30
+ export const TextStylesWithoutImage = [
31
+ TextStyles.heading1,
32
+ TextStyles.heading2,
33
+ TextStyles.heading3,
34
+ TextStyles.heading4,
35
+ TextStyles.custom1,
36
+ TextStyles.custom2,
37
+ TextStyles.custom3,
38
+ TextStyles.quote,
39
+ TextStyles.p,
40
+ ];
41
+
42
+ export const AllTextStylePlugins = [...TextStylePluginsWithoutImage, new ImageCaptionPlugin(), new ImageTitlePlugin()];
43
+
44
+ export const AllTextStyles = [...TextStylesWithoutImage, TextStyles.imageCaption, TextStyles.imageTitle];
@@ -0,0 +1,61 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ const ID = 'textstyle-imageCaption-plugin';
17
+
18
+ export class ImageCaptionPlugin extends Plugin {
19
+ public styles: CSSProperties = {};
20
+ constructor({ styles = BlockStyles.imageCaption, ...props }: PluginProps = {}) {
21
+ super(TextStyles.imageCaption, {
22
+ label: 'Image Caption',
23
+ markupElement: new ImageCaptionMarkupElement(),
24
+ ...props,
25
+ });
26
+ this.styles = styles;
27
+ }
28
+
29
+ plugins() {
30
+ return [createImageCaptionPlugin(this.styles)];
31
+ }
32
+ }
33
+
34
+ class ImageCaptionMarkupElement extends MarkupElement {
35
+ constructor(id = ID, node = ImageCaptionMarkupElementNode) {
36
+ super(id, node);
37
+ }
38
+ }
39
+ const ImageCaptionMarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
40
+ const align = element.align as string;
41
+ return (
42
+ <p
43
+ {...attributes}
44
+ className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element), 'a-image-caption'])}
45
+ >
46
+ <span style={styles}>{children}</span>
47
+ </p>
48
+ );
49
+ };
50
+
51
+ const createImageCaptionPlugin = (styles: CSSProperties) =>
52
+ createPluginFactory({
53
+ key: TextStyles.imageCaption,
54
+ isElement: true,
55
+ component: ImageCaptionMarkupElementNode,
56
+ deserializeHtml: {
57
+ rules: [{ validClassName: TextStyles.imageCaption }],
58
+ },
59
+ })({
60
+ component: (props: TextStyleRenderElementProps) => <ImageCaptionMarkupElementNode {...props} styles={styles} />,
61
+ });
@@ -0,0 +1,61 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ const ID = 'textstyle-imageTitle-plugin';
17
+
18
+ export class ImageTitlePlugin extends Plugin {
19
+ public styles: CSSProperties = {};
20
+ constructor({ styles = BlockStyles.imageTitle, ...props }: PluginProps = {}) {
21
+ super(TextStyles.imageTitle, {
22
+ label: 'Image Title',
23
+ markupElement: new ImageTitleMarkupElement(),
24
+ ...props,
25
+ });
26
+ this.styles = styles;
27
+ }
28
+
29
+ plugins() {
30
+ return [createImageTitlePlugin(this.styles)];
31
+ }
32
+ }
33
+
34
+ class ImageTitleMarkupElement extends MarkupElement {
35
+ constructor(id = ID, node = ImageTitleMarkupElementNode) {
36
+ super(id, node);
37
+ }
38
+ }
39
+ const ImageTitleMarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
40
+ const align = element.align as string;
41
+ return (
42
+ <p
43
+ {...attributes}
44
+ className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element), 'a-image-title'])}
45
+ >
46
+ <span style={styles}>{children}</span>
47
+ </p>
48
+ );
49
+ };
50
+
51
+ const createImageTitlePlugin = (styles: CSSProperties) =>
52
+ createPluginFactory({
53
+ key: TextStyles.imageTitle,
54
+ isElement: true,
55
+ component: ImageTitleMarkupElementNode,
56
+ deserializeHtml: {
57
+ rules: [{ validClassName: TextStyles.imageTitle }],
58
+ },
59
+ })({
60
+ component: (props: TextStyleRenderElementProps) => <ImageTitleMarkupElementNode {...props} styles={styles} />,
61
+ });
@@ -0,0 +1,15 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ export * from './custom1Plugin';
4
+ export * from './custom2Plugin';
5
+ export * from './custom3Plugin';
6
+ export * from './heading1Plugin';
7
+ export * from './heading2Plugin';
8
+ export * from './heading3Plugin';
9
+ export * from './heading4Plugin';
10
+ export * from './imageCaptionPlugin';
11
+ export * from './imageTitlePlugin';
12
+ export * from './paragraphPlugin';
13
+ export * from './quotePlugin';
14
+
15
+ export * from './helpers';
@@ -0,0 +1,58 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createParagraphPlugin as createPlateParagraphPlugin, createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ export class ParagraphPlugin extends Plugin {
17
+ public styles: CSSProperties = {};
18
+ constructor({ styles = BlockStyles.p, ...props }: PluginProps = {}) {
19
+ super(TextStyles.p, {
20
+ markupElement: new ParagraphMarkupElement(),
21
+ label: 'Body Text',
22
+ ...props,
23
+ });
24
+ this.styles = styles;
25
+ }
26
+
27
+ plugins() {
28
+ return [createParagraphPlugin(this.styles)];
29
+ }
30
+ }
31
+
32
+ export const PARAGRAPH_CLASSES = 'tw-m-0 tw-px-0 tw-py-0';
33
+
34
+ export const ParagraphMarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
35
+ const align = element.align as string;
36
+ const className = merge([align && alignmentClassnames[align], PARAGRAPH_CLASSES, getColumnBreakClasses(element)]);
37
+ return (
38
+ <p {...attributes} className={className} style={styles}>
39
+ {children}
40
+ </p>
41
+ );
42
+ };
43
+
44
+ export class ParagraphMarkupElement extends MarkupElement {
45
+ constructor(id = TextStyles.p, node = ParagraphMarkupElementNode) {
46
+ super(id, node);
47
+ }
48
+ }
49
+
50
+ export const createParagraphPlugin = (styles: CSSProperties) =>
51
+ createPluginFactory({
52
+ ...createPlateParagraphPlugin(),
53
+ key: TextStyles.p,
54
+ isElement: true,
55
+ component: ParagraphMarkupElementNode,
56
+ })({
57
+ component: (props: TextStyleRenderElementProps) => <ParagraphMarkupElementNode {...props} styles={styles} />,
58
+ });
@@ -0,0 +1,62 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ import { createPluginFactory } from '@udecode/plate';
4
+ import { CSSProperties } from 'react';
5
+ import {
6
+ MarkupElement,
7
+ Plugin,
8
+ PluginProps,
9
+ TextStyleRenderElementProps,
10
+ alignmentClassnames,
11
+ getColumnBreakClasses,
12
+ merge,
13
+ } from '@frontify/fondue';
14
+ import { BlockStyles, TextStyles } from '../styles';
15
+
16
+ const ID = 'textstyle-quote-plugin';
17
+
18
+ export class QuotePlugin extends Plugin {
19
+ public styles: CSSProperties = {};
20
+ constructor({ styles = BlockStyles.quote, ...props }: PluginProps = {}) {
21
+ super(TextStyles.quote, {
22
+ label: 'Quote',
23
+ markupElement: new QuoteMarkupElement(),
24
+ ...props,
25
+ });
26
+ this.styles = styles;
27
+ }
28
+
29
+ plugins() {
30
+ return [createQuotePlugin(this.styles)];
31
+ }
32
+ }
33
+
34
+ class QuoteMarkupElement extends MarkupElement {
35
+ constructor(id = ID, node = QuoteMarkupElementNode) {
36
+ super(id, node);
37
+ }
38
+ }
39
+
40
+ export const QuoteMarkupElementNode = ({ element, attributes, children, styles }: TextStyleRenderElementProps) => {
41
+ const align = element.align as string;
42
+ return (
43
+ <blockquote
44
+ {...attributes}
45
+ className={merge([align && alignmentClassnames[align], getColumnBreakClasses(element), 'a-quote'])}
46
+ >
47
+ <span style={styles}>{children}</span>
48
+ </blockquote>
49
+ );
50
+ };
51
+
52
+ export const createQuotePlugin = (styles: CSSProperties) =>
53
+ createPluginFactory({
54
+ key: TextStyles.quote,
55
+ isElement: true,
56
+ component: QuoteMarkupElementNode,
57
+ deserializeHtml: {
58
+ rules: [{ validNodeName: ['blockquote', 'BLOCKQUOTE'] }],
59
+ },
60
+ })({
61
+ component: (props: TextStyleRenderElementProps) => <QuoteMarkupElementNode {...props} styles={styles} />,
62
+ });
@@ -0,0 +1,6 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ export * from './LinkPlugin';
4
+ export * from './ButtonPlugin';
5
+ export * from './TextStylePlugins';
6
+ export * from './styles';