@squiz/formatted-text-editor 1.21.1-alpha.2 → 1.21.1-alpha.21

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 (142) hide show
  1. package/demo/App.tsx +45 -10
  2. package/demo/index.scss +11 -10
  3. package/lib/Editor/Editor.js +45 -7
  4. package/lib/Editor/EditorContext.d.ts +10 -0
  5. package/lib/Editor/EditorContext.js +15 -0
  6. package/lib/EditorToolbar/FloatingToolbar.js +11 -5
  7. package/lib/EditorToolbar/Toolbar.js +3 -1
  8. package/lib/EditorToolbar/Tools/Bold/BoldButton.js +2 -2
  9. package/lib/EditorToolbar/Tools/Image/Form/ImageForm.d.ts +17 -0
  10. package/lib/EditorToolbar/Tools/Image/Form/ImageForm.js +82 -0
  11. package/lib/EditorToolbar/Tools/Image/ImageButton.d.ts +5 -0
  12. package/lib/EditorToolbar/Tools/Image/ImageButton.js +77 -0
  13. package/lib/EditorToolbar/Tools/Image/ImageModal.d.ts +8 -0
  14. package/lib/EditorToolbar/Tools/Image/ImageModal.js +16 -0
  15. package/lib/EditorToolbar/Tools/Italic/ItalicButton.js +2 -2
  16. package/lib/EditorToolbar/Tools/Link/Form/LinkForm.d.ts +14 -5
  17. package/lib/EditorToolbar/Tools/Link/Form/LinkForm.js +67 -15
  18. package/lib/EditorToolbar/Tools/Link/LinkButton.js +22 -14
  19. package/lib/EditorToolbar/Tools/Link/LinkModal.js +12 -5
  20. package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.js +2 -9
  21. package/lib/EditorToolbar/Tools/Redo/RedoButton.js +2 -2
  22. package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.js +2 -2
  23. package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.js +2 -2
  24. package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.js +2 -2
  25. package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.js +2 -2
  26. package/lib/EditorToolbar/Tools/Underline/UnderlineButton.js +2 -2
  27. package/lib/EditorToolbar/Tools/Undo/UndoButton.js +2 -2
  28. package/lib/Extensions/CommandsExtension/CommandsExtension.d.ts +20 -0
  29. package/lib/Extensions/CommandsExtension/CommandsExtension.js +52 -0
  30. package/lib/Extensions/Extensions.d.ts +7 -4
  31. package/lib/Extensions/Extensions.js +32 -19
  32. package/lib/Extensions/ImageExtension/ImageExtension.d.ts +10 -0
  33. package/lib/Extensions/ImageExtension/ImageExtension.js +92 -0
  34. package/lib/Extensions/LinkExtension/AssetLinkExtension.d.ts +26 -0
  35. package/lib/Extensions/LinkExtension/AssetLinkExtension.js +102 -0
  36. package/lib/Extensions/LinkExtension/LinkExtension.d.ts +21 -12
  37. package/lib/Extensions/LinkExtension/LinkExtension.js +63 -65
  38. package/lib/Extensions/LinkExtension/common.d.ts +7 -0
  39. package/lib/Extensions/LinkExtension/common.js +14 -0
  40. package/lib/Extensions/PreformattedExtension/PreformattedExtension.d.ts +1 -1
  41. package/lib/hooks/index.d.ts +1 -0
  42. package/lib/hooks/index.js +1 -0
  43. package/lib/hooks/useExpandedSelection.d.ts +23 -0
  44. package/lib/hooks/useExpandedSelection.js +37 -0
  45. package/lib/index.css +159 -74
  46. package/lib/index.d.ts +5 -2
  47. package/lib/index.js +9 -3
  48. package/lib/types.d.ts +3 -0
  49. package/lib/types.js +2 -0
  50. package/lib/ui/Button/Button.d.ts +11 -0
  51. package/lib/ui/{ToolbarButton/ToolbarButton.js → Button/Button.js} +6 -3
  52. package/lib/ui/Fields/Input/Input.d.ts +5 -0
  53. package/lib/ui/{Inputs/Text/TextInput.js → Fields/Input/Input.js} +10 -5
  54. package/lib/ui/Modal/Modal.js +2 -1
  55. package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.d.ts +9 -0
  56. package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.js +165 -0
  57. package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.d.ts +9 -0
  58. package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +129 -0
  59. package/lib/utils/undefinedIfEmpty.d.ts +1 -0
  60. package/lib/utils/undefinedIfEmpty.js +7 -0
  61. package/package.json +9 -4
  62. package/src/Editor/Editor.spec.tsx +78 -18
  63. package/src/Editor/Editor.tsx +28 -9
  64. package/src/Editor/EditorContext.spec.tsx +26 -0
  65. package/src/Editor/EditorContext.ts +19 -0
  66. package/src/Editor/_editor.scss +20 -51
  67. package/src/EditorToolbar/FloatingToolbar.spec.tsx +2 -3
  68. package/src/EditorToolbar/FloatingToolbar.tsx +15 -6
  69. package/src/EditorToolbar/Toolbar.tsx +2 -0
  70. package/src/EditorToolbar/Tools/Bold/BoldButton.spec.tsx +1 -1
  71. package/src/EditorToolbar/Tools/Bold/BoldButton.tsx +2 -2
  72. package/src/EditorToolbar/Tools/Image/Form/ImageForm.spec.tsx +77 -0
  73. package/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx +90 -0
  74. package/src/EditorToolbar/Tools/Image/ImageButton.spec.tsx +135 -0
  75. package/src/EditorToolbar/Tools/Image/ImageButton.tsx +72 -0
  76. package/src/EditorToolbar/Tools/Image/ImageModal.spec.tsx +83 -0
  77. package/src/EditorToolbar/Tools/Image/ImageModal.tsx +24 -0
  78. package/src/EditorToolbar/Tools/Italic/ItalicButton.spec.tsx +1 -1
  79. package/src/EditorToolbar/Tools/Italic/ItalicButton.tsx +2 -2
  80. package/src/EditorToolbar/Tools/Link/Form/LinkForm.spec.tsx +37 -9
  81. package/src/EditorToolbar/Tools/Link/Form/LinkForm.tsx +97 -27
  82. package/src/EditorToolbar/Tools/Link/LinkButton.spec.tsx +104 -26
  83. package/src/EditorToolbar/Tools/Link/LinkButton.tsx +30 -21
  84. package/src/EditorToolbar/Tools/Link/LinkModal.tsx +13 -6
  85. package/src/EditorToolbar/Tools/Link/RemoveLinkButton.spec.tsx +26 -26
  86. package/src/EditorToolbar/Tools/Link/RemoveLinkButton.tsx +4 -12
  87. package/src/EditorToolbar/Tools/Redo/RedoButton.tsx +2 -2
  88. package/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.tsx +2 -2
  89. package/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.tsx +2 -2
  90. package/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.tsx +2 -2
  91. package/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.tsx +2 -2
  92. package/src/EditorToolbar/Tools/Underline/Underline.spec.tsx +1 -1
  93. package/src/EditorToolbar/Tools/Underline/UnderlineButton.tsx +2 -2
  94. package/src/EditorToolbar/Tools/Undo/UndoButton.spec.tsx +22 -1
  95. package/src/EditorToolbar/Tools/Undo/UndoButton.tsx +2 -2
  96. package/src/EditorToolbar/_floating-toolbar.scss +5 -0
  97. package/src/EditorToolbar/_toolbar.scss +11 -5
  98. package/src/Extensions/CommandsExtension/CommandsExtension.ts +54 -0
  99. package/src/Extensions/Extensions.ts +32 -17
  100. package/src/Extensions/ImageExtension/ImageExtension.ts +112 -0
  101. package/src/Extensions/LinkExtension/AssetLinkExtension.spec.ts +104 -0
  102. package/src/Extensions/LinkExtension/AssetLinkExtension.ts +128 -0
  103. package/src/Extensions/LinkExtension/LinkExtension.spec.ts +68 -0
  104. package/src/Extensions/LinkExtension/LinkExtension.ts +88 -82
  105. package/src/Extensions/LinkExtension/common.ts +10 -0
  106. package/src/hooks/index.ts +1 -0
  107. package/src/hooks/useExpandedSelection.ts +44 -0
  108. package/src/index.scss +2 -2
  109. package/src/index.ts +5 -2
  110. package/src/types.ts +5 -0
  111. package/src/ui/Button/Button.spec.tsx +44 -0
  112. package/src/ui/Button/Button.tsx +29 -0
  113. package/src/ui/{_buttons.scss → Button/_button.scss} +19 -1
  114. package/src/ui/{Inputs/Text/TextInput.spec.tsx → Fields/Input/Input.spec.tsx} +8 -8
  115. package/src/ui/Fields/Input/Input.tsx +34 -0
  116. package/src/ui/Modal/Modal.tsx +2 -1
  117. package/src/ui/ToolbarDropdown/_toolbar-dropdown.scss +1 -1
  118. package/src/ui/_forms.scss +14 -0
  119. package/src/ui/_typography.scss +46 -0
  120. package/src/utils/converters/mocks/squizNodeJson.mock.ts +252 -0
  121. package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.spec.ts +480 -0
  122. package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts +202 -0
  123. package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +329 -0
  124. package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +151 -0
  125. package/src/utils/undefinedIfEmpty.spec.ts +12 -0
  126. package/src/utils/undefinedIfEmpty.ts +3 -0
  127. package/tailwind.config.cjs +3 -0
  128. package/tests/renderWithEditor.tsx +28 -15
  129. package/lib/FormattedTextEditor.d.ts +0 -2
  130. package/lib/FormattedTextEditor.js +0 -7
  131. package/lib/ui/Inputs/Text/TextInput.d.ts +0 -4
  132. package/lib/ui/ToolbarButton/ToolbarButton.d.ts +0 -10
  133. package/src/Editor/Editor.mock.tsx +0 -43
  134. package/src/FormattedTextEditor.spec.tsx +0 -10
  135. package/src/FormattedTextEditor.tsx +0 -3
  136. package/src/ui/Inputs/Text/TextInput.tsx +0 -20
  137. package/src/ui/ToolbarButton/ToolbarButton.tsx +0 -26
  138. package/src/ui/ToolbarButton/_toolbar-button.scss +0 -17
  139. /package/lib/ui/{Inputs → Fields}/Select/Select.d.ts +0 -0
  140. /package/lib/ui/{Inputs → Fields}/Select/Select.js +0 -0
  141. /package/src/ui/{Inputs → Fields}/Select/Select.spec.tsx +0 -0
  142. /package/src/ui/{Inputs → Fields}/Select/Select.tsx +0 -0
@@ -2,6 +2,7 @@ import React, { ForwardedRef, forwardRef, ReactElement, useEffect, useMemo } fro
2
2
  import { createPortal } from 'react-dom';
3
3
  import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
4
4
  import { FocusTrap } from '@mui/base';
5
+ import clsx from 'clsx';
5
6
 
6
7
  export type ModalProps = {
7
8
  title: string;
@@ -50,7 +51,7 @@ const Modal = (
50
51
  return createPortal(
51
52
  <>
52
53
  <FocusTrap open>
53
- <div ref={ref} className={`squiz-fte-modal-wrapper ${className ? className : ''}`} tabIndex={-1}>
54
+ <div ref={ref} className={clsx('squiz-fte-modal-wrapper', className)} tabIndex={-1}>
54
55
  <div className="w-modal-sm my-6 mx-auto">
55
56
  <div className="squiz-fte-modal">
56
57
  <div className="squiz-fte-modal-header p-6 pb-2">
@@ -1,6 +1,6 @@
1
1
  .toolbar-dropdown {
2
2
  &__button {
3
- @apply flex items-center font-base text-md font-semibold text-gray-600;
3
+ @apply flex items-center font-base text-md font-semibold text-gray-600 rounded;
4
4
  align-self: center;
5
5
 
6
6
  height: 2rem;
@@ -13,4 +13,18 @@
13
13
  box-shadow: none;
14
14
  }
15
15
  }
16
+ &-invalid-form-field {
17
+ .squiz-fte-form-control {
18
+ @apply border-red-300 bg-no-repeat;
19
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHdpZHRoPSIyNCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0ibm9uZSIvPjxnIGNsYXNzPSJjdXJyZW50TGF5ZXIiPjxwYXRoIGQ9Ik00LjQ3IDIxaDE1LjA2YzEuNTQgMCAyLjUtMS42NyAxLjczLTNMMTMuNzMgNC45OWMtLjc3LTEuMzMtMi42OS0xLjMzLTMuNDYgMEwyLjc0IDE4Yy0uNzcgMS4zMy4xOSAzIDEuNzMgM3pNMTIgMTRjLS41NSAwLTEtLjQ1LTEtMXYtMmMwLS41NS40NS0xIDEtMXMxIC40NSAxIDF2MmMwIC41NS0uNDUgMS0xIDF6bTEgNGgtMnYtMmgydjJ6IiBjbGFzcz0ic2VsZWN0ZWQiIGZpbGw9IiNkNzIzMjEiLz48L2c+PC9zdmc+');
20
+ background-position: top 0.25rem right 0.25rem;
21
+ background-size: 1.5rem;
22
+ }
23
+ }
24
+ &-form-error {
25
+ @apply text-red-300;
26
+ font-size: 13px;
27
+ line-height: 1.23;
28
+ padding-top: 0.25rem;
29
+ }
16
30
  }
@@ -0,0 +1,46 @@
1
+ a {
2
+ @apply text-blue-300;
3
+ text-decoration: underline;
4
+ }
5
+
6
+ h1 {
7
+ font-size: 1.625rem;
8
+ font-weight: 600;
9
+ letter-spacing: -0.2px;
10
+ line-height: 2rem;
11
+ }
12
+
13
+ h2 {
14
+ font-size: 1.25rem;
15
+ font-weight: 600;
16
+ letter-spacing: -0.5px;
17
+ line-height: 1.5rem;
18
+ }
19
+
20
+ h3 {
21
+ font-size: 1.125rem;
22
+ font-weight: 600;
23
+ letter-spacing: -0.2px;
24
+ line-height: 1.375rem;
25
+ }
26
+
27
+ h4 {
28
+ font-size: 1rem;
29
+ font-weight: 700;
30
+ letter-spacing: -0.2px;
31
+ line-height: 1.25rem;
32
+ }
33
+
34
+ h5 {
35
+ font-size: 1rem;
36
+ font-weight: 600;
37
+ letter-spacing: -0.2px;
38
+ line-height: 1.25rem;
39
+ }
40
+
41
+ h6 {
42
+ font-size: 0.875rem;
43
+ font-weight: 600;
44
+ letter-spacing: -0.2px;
45
+ line-height: 1.25rem;
46
+ }
@@ -0,0 +1,252 @@
1
+ import { FORMATTED_TEXT_MODELS as FormattedTextModels } from '@squiz/dx-json-schema-lib';
2
+ import { RemirrorJSON } from '@remirror/core';
3
+
4
+ export const mockSquizNodeJson: FormattedTextModels.v1.FormattedText = [
5
+ {
6
+ children: [
7
+ {
8
+ type: 'text',
9
+ value: 'Hello ',
10
+ },
11
+ {
12
+ children: [
13
+ {
14
+ type: 'text',
15
+ value: 'Mr Bean',
16
+ },
17
+ ],
18
+ attributes: {
19
+ href: 'https://www.google.com',
20
+ },
21
+ font: {
22
+ bold: true,
23
+ },
24
+ type: 'tag',
25
+ tag: 'a',
26
+ },
27
+ {
28
+ type: 'text',
29
+ value: ', nice to ',
30
+ },
31
+ {
32
+ children: [
33
+ {
34
+ type: 'text',
35
+ value: 'meet you',
36
+ },
37
+ ],
38
+ attributes: {
39
+ href: 'https://www.google.com',
40
+ },
41
+ type: 'tag',
42
+ tag: 'a',
43
+ },
44
+ {
45
+ type: 'text',
46
+ value: '.',
47
+ },
48
+ {
49
+ children: [],
50
+ attributes: {
51
+ alt: 'Test',
52
+ height: '150',
53
+ width: '200',
54
+ src: 'https://media2.giphy.com/media/3o6ozsIxg5legYvggo/giphy.gif',
55
+ title: '',
56
+ resizable: 'false',
57
+ },
58
+ type: 'tag',
59
+ tag: 'img',
60
+ },
61
+ ],
62
+ type: 'tag',
63
+ tag: 'p',
64
+ },
65
+ ];
66
+
67
+ export const mockSquizNodeTextJson: FormattedTextModels.v1.FormattedText = [
68
+ {
69
+ value: 'Hello world!',
70
+ type: 'text',
71
+ },
72
+ {
73
+ value: 'Another one...',
74
+ type: 'text',
75
+ },
76
+ ];
77
+
78
+ type NodeExample = {
79
+ description: string;
80
+ remirrorNode: RemirrorJSON;
81
+ squizNode: FormattedTextModels.v1.FormattedText;
82
+ };
83
+
84
+ export const sharedNodeExamples: NodeExample[] = [
85
+ {
86
+ description: 'Asset link',
87
+ remirrorNode: {
88
+ type: 'text',
89
+ text: 'Hello',
90
+ marks: [
91
+ {
92
+ type: 'assetLink',
93
+ attrs: {
94
+ target: '_blank',
95
+ matrixAssetId: '123',
96
+ matrixDomain: 'https://my-matrix.squiz.net',
97
+ matrixIdentifier: 'matrix-api-identifier',
98
+ },
99
+ },
100
+ ],
101
+ },
102
+ squizNode: [
103
+ {
104
+ type: 'link-to-matrix-asset',
105
+ target: '_blank',
106
+ matrixAssetId: '123',
107
+ matrixDomain: 'https://my-matrix.squiz.net',
108
+ matrixIdentifier: 'matrix-api-identifier',
109
+ children: [{ type: 'text', value: 'Hello' }],
110
+ },
111
+ ],
112
+ },
113
+ {
114
+ description: 'Asset link with formatting applied inside of the link',
115
+ remirrorNode: {
116
+ type: 'text',
117
+ text: 'Hello',
118
+ marks: [
119
+ { type: 'bold' },
120
+ {
121
+ type: 'assetLink',
122
+ attrs: {
123
+ target: '_blank',
124
+ matrixAssetId: '123',
125
+ matrixDomain: 'https://my-matrix.squiz.net',
126
+ matrixIdentifier: 'matrix-api-identifier',
127
+ },
128
+ },
129
+ ],
130
+ },
131
+ squizNode: [
132
+ {
133
+ type: 'link-to-matrix-asset',
134
+ target: '_blank',
135
+ matrixAssetId: '123',
136
+ matrixDomain: 'https://my-matrix.squiz.net',
137
+ matrixIdentifier: 'matrix-api-identifier',
138
+ children: [
139
+ {
140
+ type: 'tag',
141
+ tag: 'span',
142
+ font: { bold: true },
143
+ children: [{ type: 'text', value: 'Hello' }],
144
+ },
145
+ ],
146
+ },
147
+ ],
148
+ },
149
+ ];
150
+
151
+ export const squizOnlyNodeExamples: NodeExample[] = [
152
+ {
153
+ description: 'Asset link with formatting applied inside, outside and with multiple levels of nesting',
154
+ squizNode: [
155
+ {
156
+ type: 'tag',
157
+ tag: 'span',
158
+ font: { bold: true },
159
+ children: [
160
+ {
161
+ type: 'link-to-matrix-asset',
162
+ target: '_blank',
163
+ matrixAssetId: '123',
164
+ matrixDomain: 'https://my-matrix.squiz.net',
165
+ matrixIdentifier: 'matrix-api-identifier',
166
+ children: [
167
+ {
168
+ type: 'tag',
169
+ tag: 'span',
170
+ font: { italics: true },
171
+ children: [
172
+ {
173
+ type: 'tag',
174
+ tag: 'span',
175
+ font: { underline: true },
176
+ children: [{ type: 'text', value: 'Hello' }],
177
+ },
178
+ ],
179
+ },
180
+ ],
181
+ },
182
+ ],
183
+ },
184
+ ],
185
+ remirrorNode: {
186
+ // reverse operation covered by "Asset link with formatting applied inside of the link".
187
+ type: 'text',
188
+ text: 'Hello',
189
+ marks: [
190
+ { type: 'underline' },
191
+ { type: 'italic' },
192
+ {
193
+ type: 'assetLink',
194
+ attrs: {
195
+ target: '_blank',
196
+ matrixAssetId: '123',
197
+ matrixDomain: 'https://my-matrix.squiz.net',
198
+ matrixIdentifier: 'matrix-api-identifier',
199
+ },
200
+ },
201
+ { type: 'bold' },
202
+ ],
203
+ },
204
+ },
205
+ {
206
+ description: 'Asset link with multiple levels of un-necessary nesting',
207
+ squizNode: [
208
+ {
209
+ type: 'tag',
210
+ tag: 'span',
211
+ children: [
212
+ {
213
+ type: 'link-to-matrix-asset',
214
+ target: '_blank',
215
+ matrixAssetId: '123',
216
+ matrixDomain: 'https://my-matrix.squiz.net',
217
+ matrixIdentifier: 'matrix-api-identifier',
218
+ children: [
219
+ {
220
+ type: 'tag',
221
+ tag: 'span',
222
+ children: [
223
+ {
224
+ type: 'tag',
225
+ tag: 'span',
226
+ children: [{ type: 'text', value: 'Hello' }],
227
+ },
228
+ ],
229
+ },
230
+ ],
231
+ },
232
+ ],
233
+ },
234
+ ],
235
+ remirrorNode: {
236
+ // reverse operation covered by "Asset link".
237
+ type: 'text',
238
+ text: 'Hello',
239
+ marks: [
240
+ {
241
+ type: 'assetLink',
242
+ attrs: {
243
+ target: '_blank',
244
+ matrixAssetId: '123',
245
+ matrixDomain: 'https://my-matrix.squiz.net',
246
+ matrixIdentifier: 'matrix-api-identifier',
247
+ },
248
+ },
249
+ ],
250
+ },
251
+ },
252
+ ];