@vev/silke 1.1.10 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/.turbo/turbo-build.log +162 -77
  2. package/CHANGELOG.md +41 -0
  3. package/dist/index.js +44 -41
  4. package/dist/index.js.LEGAL.txt +1 -1
  5. package/dist/index.js.map +7 -0
  6. package/dist/styles.css +1596 -1013
  7. package/dist/types/components/index.d.ts +2 -0
  8. package/dist/types/components/silke-autocomplete-field/autocomplete-item.d.ts +1 -1
  9. package/dist/types/components/silke-autocomplete-field/silke-autocomplete-field-native.d.ts +5 -0
  10. package/dist/types/components/silke-box/silke-box.d.ts +2 -0
  11. package/dist/types/components/silke-button/silke-dropdown-button.d.ts +3 -1
  12. package/dist/types/components/silke-card/silke-card-grid.d.ts +1 -0
  13. package/dist/types/components/silke-card/silke-card.d.ts +1 -0
  14. package/dist/types/components/silke-command-text-field/index.d.ts +1 -1
  15. package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +16 -0
  16. package/dist/types/components/silke-command-text-field/utils.d.ts +25 -0
  17. package/dist/types/components/silke-css-number-field/silke-css-number-field.spec.d.ts +1 -0
  18. package/dist/types/components/silke-expression-input/index.d.ts +3 -0
  19. package/dist/types/components/silke-expression-input/silke-expression-input-tag.d.ts +6 -0
  20. package/dist/types/components/silke-expression-input/silke-expression-input.d.ts +29 -0
  21. package/dist/types/components/silke-expression-input/utils.d.ts +18 -0
  22. package/dist/types/components/silke-form-schema/fields/array-field-inline.d.ts +2 -1
  23. package/dist/types/components/silke-form-schema/fields/array-field-modal.d.ts +2 -1
  24. package/dist/types/components/silke-form-schema/fields/array-field.d.ts +1 -1
  25. package/dist/types/components/silke-form-schema/fields/group-field.d.ts +1 -1
  26. package/dist/types/components/silke-form-schema/fields/layout-field.d.ts +1 -1
  27. package/dist/types/components/silke-form-schema/fields/object-field.d.ts +1 -1
  28. package/dist/types/components/silke-form-schema/fields/popover-field.d.ts +1 -1
  29. package/dist/types/components/silke-form-schema/fields/string-field.d.ts +1 -1
  30. package/dist/types/components/silke-form-schema/fields/utils/generate-preview.spec.d.ts +1 -0
  31. package/dist/types/components/silke-form-schema/fields/utils/generate-title.d.ts +10 -0
  32. package/dist/types/components/silke-form-schema/index.d.ts +1 -0
  33. package/dist/types/components/silke-form-schema/silke-form-schema.d.ts +4 -1
  34. package/dist/types/components/silke-form-schema/silke-schema-decorator.d.ts +17 -0
  35. package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
  36. package/dist/types/components/silke-form-schema/silke-schema-fields.d.ts +2 -0
  37. package/dist/types/components/silke-form-schema/silke-schema-path.spec.d.ts +1 -0
  38. package/dist/types/components/silke-gradient-picker/silke-gradient-utils.d.ts +2 -0
  39. package/dist/types/components/silke-icon-picker/color-swatch-section.d.ts +6 -0
  40. package/dist/types/components/silke-icon-picker/emoji-tab.d.ts +1 -1
  41. package/dist/types/components/silke-icon-picker/icons-tab.d.ts +1 -1
  42. package/dist/types/components/silke-icon-picker/silke-icon-picker.d.ts +2 -0
  43. package/dist/types/components/silke-icon-picker/utils.d.ts +2 -0
  44. package/dist/types/components/silke-list/silke-list-item.d.ts +5 -1
  45. package/dist/types/components/silke-list/types.d.ts +1 -0
  46. package/dist/types/components/silke-navigation-link/silke-navigation-link.d.ts +15 -0
  47. package/dist/types/components/silke-popover/popover-context.spec.d.ts +1 -0
  48. package/dist/types/components/silke-rich-text-field/blockquote.d.ts +21 -0
  49. package/dist/types/components/silke-rich-text-field/blockquote.spec.d.ts +1 -0
  50. package/dist/types/components/silke-rich-text-field/dropcap.d.ts +27 -0
  51. package/dist/types/components/silke-rich-text-field/dropcap.spec.d.ts +1 -0
  52. package/dist/types/components/silke-rich-text-field/floating-layer.d.ts +12 -0
  53. package/dist/types/components/silke-rich-text-field/font-size.d.ts +2 -0
  54. package/dist/types/components/silke-rich-text-field/formatting-toolbar.d.ts +9 -0
  55. package/dist/types/components/silke-rich-text-field/index.d.ts +1 -0
  56. package/dist/types/components/silke-rich-text-field/jsdom-rects.d.ts +10 -0
  57. package/dist/types/components/silke-rich-text-field/link-menu.d.ts +26 -0
  58. package/dist/types/components/silke-rich-text-field/link-menu.spec.d.ts +1 -0
  59. package/dist/types/components/silke-rich-text-field/link-suggestions.d.ts +48 -0
  60. package/dist/types/components/silke-rich-text-field/link-suggestions.spec.d.ts +1 -0
  61. package/dist/types/components/silke-rich-text-field/link-tooltip.d.ts +15 -0
  62. package/dist/types/components/silke-rich-text-field/list-item.d.ts +15 -0
  63. package/dist/types/components/silke-rich-text-field/list-link-fontsize.spec.d.ts +1 -0
  64. package/dist/types/components/silke-rich-text-field/lorem-ipsum.d.ts +10 -0
  65. package/dist/types/components/silke-rich-text-field/lorem-ipsum.spec.d.ts +1 -0
  66. package/dist/types/components/silke-rich-text-field/paste.d.ts +1 -0
  67. package/dist/types/components/silke-rich-text-field/paste.spec.d.ts +1 -0
  68. package/dist/types/components/silke-rich-text-field/plugins.d.ts +18 -0
  69. package/dist/types/components/silke-rich-text-field/plugins.spec.d.ts +1 -0
  70. package/dist/types/components/silke-rich-text-field/silke-rich-text-field.d.ts +60 -0
  71. package/dist/types/components/silke-rich-text-field/slash-menu-items.d.ts +10 -0
  72. package/dist/types/components/silke-rich-text-field/slash-menu.d.ts +11 -0
  73. package/dist/types/components/silke-rich-text-field/table-content-sync.spec.d.ts +1 -0
  74. package/dist/types/components/silke-rich-text-field/table-toolbar.d.ts +17 -0
  75. package/dist/types/components/silke-rich-text-field/table-toolbar.spec.d.ts +1 -0
  76. package/dist/types/components/silke-rich-text-field/table.spec.d.ts +1 -0
  77. package/dist/types/components/silke-rich-text-field/use-link-hover.d.ts +15 -0
  78. package/dist/types/components/silke-rich-text-field/use-slash-menu.d.ts +13 -0
  79. package/dist/types/components/silke-rich-text-field/utils.d.ts +13 -0
  80. package/dist/types/components/silke-sortable-list/index.d.ts +1 -1
  81. package/dist/types/components/silke-sortable-list/silke-nested-sortable-list.d.ts +8 -1
  82. package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +13 -6
  83. package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +6 -1
  84. package/dist/types/icons.d.ts +16 -0
  85. package/esbuild.config.mjs +9 -4
  86. package/package.json +22 -9
  87. package/src/components/index.ts +2 -0
  88. package/src/components/silke-alert-banner/silke-alert-banner.tsx +1 -1
  89. package/src/components/silke-autocomplete-field/autocomplete-item.tsx +47 -61
  90. package/src/components/silke-autocomplete-field/silke-autocomplete-field-native.tsx +13 -2
  91. package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +8 -5
  92. package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +2 -1
  93. package/src/components/silke-box/silke-box.scss +4 -0
  94. package/src/components/silke-box/silke-box.tsx +4 -0
  95. package/src/components/silke-button/silke-dropdown-button.tsx +4 -1
  96. package/src/components/silke-card/silke-card.scss +4 -0
  97. package/src/components/silke-card/silke-card.tsx +3 -0
  98. package/src/components/silke-command-text-field/index.ts +1 -0
  99. package/src/components/silke-command-text-field/silke-command-parser.spec.ts +55 -0
  100. package/src/components/silke-command-text-field/silke-command-parser.ts +33 -2
  101. package/src/components/silke-command-text-field/silke-command-text-field.module.scss +3 -0
  102. package/src/components/silke-command-text-field/silke-command-text-field.tsx +53 -48
  103. package/src/components/silke-command-text-field/utils.spec.ts +192 -0
  104. package/src/components/silke-command-text-field/utils.ts +99 -16
  105. package/src/components/silke-css-number-field/silke-css-number-field.spec.tsx +115 -0
  106. package/src/components/silke-css-number-field/silke-css-number-field.tsx +33 -0
  107. package/src/components/silke-expression-input/index.ts +3 -0
  108. package/src/components/silke-expression-input/silke-expression-input-tag.tsx +37 -0
  109. package/src/components/silke-expression-input/silke-expression-input.mdx +40 -0
  110. package/src/components/silke-expression-input/silke-expression-input.scss +24 -0
  111. package/src/components/silke-expression-input/silke-expression-input.tsx +343 -0
  112. package/src/components/silke-expression-input/utils.ts +144 -0
  113. package/src/components/silke-form-schema/fields/array-field-inline.tsx +4 -0
  114. package/src/components/silke-form-schema/fields/array-field-modal.tsx +4 -0
  115. package/src/components/silke-form-schema/fields/array-field.tsx +6 -11
  116. package/src/components/silke-form-schema/fields/group-field.tsx +2 -0
  117. package/src/components/silke-form-schema/fields/layout-field.tsx +2 -0
  118. package/src/components/silke-form-schema/fields/object-field.tsx +2 -0
  119. package/src/components/silke-form-schema/fields/popover-field.tsx +2 -0
  120. package/src/components/silke-form-schema/fields/string-field.tsx +33 -5
  121. package/src/components/silke-form-schema/fields/utils/generate-image.ts +5 -14
  122. package/src/components/silke-form-schema/fields/utils/generate-preview.spec.ts +49 -0
  123. package/src/components/silke-form-schema/fields/utils/generate-title.ts +23 -10
  124. package/src/components/silke-form-schema/index.ts +1 -0
  125. package/src/components/silke-form-schema/silke-form-schema.mdx +30 -1
  126. package/src/components/silke-form-schema/silke-form-schema.tsx +12 -6
  127. package/src/components/silke-form-schema/silke-schema-decorator.tsx +32 -0
  128. package/src/components/silke-form-schema/silke-schema-field.tsx +19 -2
  129. package/src/components/silke-form-schema/silke-schema-fields.tsx +30 -4
  130. package/src/components/silke-form-schema/silke-schema-path.spec.tsx +160 -0
  131. package/src/components/silke-gradient-picker/silke-gradient-picker.tsx +3 -1
  132. package/src/components/silke-gradient-picker/silke-gradient-utils.ts +23 -3
  133. package/src/components/silke-icon/silke-shape.tsx +1 -1
  134. package/src/components/silke-icon-picker/color-swatch-section.tsx +61 -0
  135. package/src/components/silke-icon-picker/emoji-tab.tsx +8 -6
  136. package/src/components/silke-icon-picker/icons-tab.tsx +8 -7
  137. package/src/components/silke-icon-picker/silke-icon-picker.tsx +52 -25
  138. package/src/components/silke-icon-picker/styles.scss +66 -1
  139. package/src/components/silke-icon-picker/utils.ts +2 -0
  140. package/src/components/silke-list/silke-list-item.scss +10 -0
  141. package/src/components/silke-list/silke-list-item.tsx +16 -3
  142. package/src/components/silke-list/silke-list.mdx +18 -0
  143. package/src/components/silke-list/types.ts +1 -0
  144. package/src/components/silke-navigation-link/silke-navigation-link.scss +162 -42
  145. package/src/components/silke-navigation-link/silke-navigation-link.tsx +99 -21
  146. package/src/components/silke-popover/popover-context.spec.tsx +44 -0
  147. package/src/components/silke-popover-native/silke-popover-native.scss +5 -3
  148. package/src/components/silke-rich-text-field/blockquote.spec.ts +151 -0
  149. package/src/components/silke-rich-text-field/blockquote.ts +90 -0
  150. package/src/components/silke-rich-text-field/dropcap.spec.ts +67 -0
  151. package/src/components/silke-rich-text-field/dropcap.ts +59 -0
  152. package/src/components/silke-rich-text-field/floating-layer.tsx +15 -0
  153. package/src/components/silke-rich-text-field/font-size.ts +62 -0
  154. package/src/components/silke-rich-text-field/formatting-toolbar.tsx +145 -0
  155. package/src/components/silke-rich-text-field/index.ts +1 -0
  156. package/src/components/silke-rich-text-field/jsdom-rects.ts +15 -0
  157. package/src/components/silke-rich-text-field/link-menu.spec.tsx +502 -0
  158. package/src/components/silke-rich-text-field/link-menu.tsx +553 -0
  159. package/src/components/silke-rich-text-field/link-suggestions.spec.ts +203 -0
  160. package/src/components/silke-rich-text-field/link-suggestions.ts +188 -0
  161. package/src/components/silke-rich-text-field/link-tooltip.tsx +60 -0
  162. package/src/components/silke-rich-text-field/list-item.ts +64 -0
  163. package/src/components/silke-rich-text-field/list-link-fontsize.spec.ts +135 -0
  164. package/src/components/silke-rich-text-field/lorem-ipsum.spec.ts +131 -0
  165. package/src/components/silke-rich-text-field/lorem-ipsum.ts +51 -0
  166. package/src/components/silke-rich-text-field/paste.spec.ts +93 -0
  167. package/src/components/silke-rich-text-field/paste.ts +39 -0
  168. package/src/components/silke-rich-text-field/plugins.spec.ts +143 -0
  169. package/src/components/silke-rich-text-field/plugins.ts +230 -0
  170. package/src/components/silke-rich-text-field/silke-rich-text-field.mdx +180 -0
  171. package/src/components/silke-rich-text-field/silke-rich-text-field.scss +343 -0
  172. package/src/components/silke-rich-text-field/silke-rich-text-field.tsx +505 -0
  173. package/src/components/silke-rich-text-field/slash-menu-items.ts +112 -0
  174. package/src/components/silke-rich-text-field/slash-menu.tsx +50 -0
  175. package/src/components/silke-rich-text-field/table-content-sync.spec.tsx +61 -0
  176. package/src/components/silke-rich-text-field/table-toolbar.spec.tsx +168 -0
  177. package/src/components/silke-rich-text-field/table-toolbar.tsx +121 -0
  178. package/src/components/silke-rich-text-field/table.spec.ts +87 -0
  179. package/src/components/silke-rich-text-field/use-link-hover.ts +63 -0
  180. package/src/components/silke-rich-text-field/use-slash-menu.ts +130 -0
  181. package/src/components/silke-rich-text-field/utils.ts +55 -0
  182. package/src/components/silke-sortable-list/index.ts +1 -1
  183. package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +11 -1
  184. package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +9 -0
  185. package/src/components/silke-sortable-list/silke-sortable-list.mdx +13 -0
  186. package/src/components/silke-tag/silke-tag.scss +12 -3
  187. package/src/components/silke-theme-card/silke-theme-card.module.scss +141 -45
  188. package/src/components/silke-theme-card/silke-theme-card.tsx +76 -47
  189. package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +56 -0
  190. package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +53 -63
  191. package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +99 -14
  192. package/src/icons.tsx +51 -5
  193. package/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,131 @@
1
+ import { Selection } from '@tiptap/pm/state';
2
+ import { Editor } from '@tiptap/react';
3
+ import { LOREM_IPSUM_TEXT } from './lorem-ipsum';
4
+ import { buildExtensions } from './plugins';
5
+
6
+ /**
7
+ * lorem + Tab expands to a full paragraph, as it did in the old plate editor
8
+ * (E-1211). Tab is dispatched as a real keydown so these also cover the wiring:
9
+ * the extension has to outrank ListItem's Tab binding, and it has to decline the
10
+ * key whenever the word before the caret is not `lorem`.
11
+ */
12
+
13
+ const createEditor = (content: string) => {
14
+ const editor = new Editor({ extensions: buildExtensions({ current: '' }), content });
15
+ editor.view.dispatch(editor.state.tr.setSelection(Selection.atEnd(editor.state.doc)));
16
+ return editor;
17
+ };
18
+
19
+ /** Returns the event so tests can assert whether the key was consumed. */
20
+ const pressTab = (editor: Editor) => {
21
+ const event = new KeyboardEvent('keydown', { key: 'Tab', cancelable: true });
22
+ editor.view.dispatchEvent(event);
23
+ return event;
24
+ };
25
+
26
+ describe('rich text field lorem ipsum', () => {
27
+ it('expands a trailing lorem into the full paragraph', () => {
28
+ const editor = createEditor('<p>lorem</p>');
29
+ const event = pressTab(editor);
30
+ expect(editor.getText()).toBe(LOREM_IPSUM_TEXT);
31
+ expect(event.defaultPrevented).toBe(true);
32
+ editor.destroy();
33
+ });
34
+
35
+ it.each(['lorem', 'Lorem', 'LOREM', 'LoReM'])('expands %s (case insensitive)', (word) => {
36
+ const editor = createEditor(`<p>${word}</p>`);
37
+ pressTab(editor);
38
+ expect(editor.getText()).toBe(LOREM_IPSUM_TEXT);
39
+ editor.destroy();
40
+ });
41
+
42
+ it('replaces only the trigger word, keeping the text before it', () => {
43
+ const editor = createEditor('<p>Intro text lorem</p>');
44
+ pressTab(editor);
45
+ expect(editor.getText()).toBe(`Intro text ${LOREM_IPSUM_TEXT}`);
46
+ editor.destroy();
47
+ });
48
+
49
+ it('leaves the caret after the inserted paragraph', () => {
50
+ const editor = createEditor('<p>lorem</p>');
51
+ pressTab(editor);
52
+ const { from, empty } = editor.state.selection;
53
+ expect(empty).toBe(true);
54
+ expect(from).toBe(LOREM_IPSUM_TEXT.length + 1);
55
+ editor.destroy();
56
+ });
57
+
58
+ it('keeps the marks that were active on the trigger word', () => {
59
+ const editor = createEditor('<p><strong>lorem</strong></p>');
60
+ pressTab(editor);
61
+ expect(editor.getHTML()).toBe(`<p><strong>${LOREM_IPSUM_TEXT}</strong></p>`);
62
+ editor.destroy();
63
+ });
64
+
65
+ it('expands in a heading too', () => {
66
+ const editor = createEditor('<h2>lorem</h2>');
67
+ pressTab(editor);
68
+ expect(editor.getHTML()).toBe(`<h2>${LOREM_IPSUM_TEXT}</h2>`);
69
+ editor.destroy();
70
+ });
71
+
72
+ it('passes Tab through when the preceding word is not lorem', () => {
73
+ const editor = createEditor('<p>just some text</p>');
74
+ const before = editor.getHTML();
75
+ const event = pressTab(editor);
76
+ expect(editor.getHTML()).toBe(before);
77
+ expect(event.defaultPrevented).toBe(false);
78
+ editor.destroy();
79
+ });
80
+
81
+ it('passes Tab through on an empty paragraph', () => {
82
+ const editor = createEditor('<p></p>');
83
+ const event = pressTab(editor);
84
+ expect(editor.getText()).toBe('');
85
+ expect(event.defaultPrevented).toBe(false);
86
+ editor.destroy();
87
+ });
88
+
89
+ it('does not expand lorem inside a longer word', () => {
90
+ const editor = createEditor('<p>watermelorem</p>');
91
+ const event = pressTab(editor);
92
+ expect(editor.getText()).toBe('watermelorem');
93
+ expect(event.defaultPrevented).toBe(false);
94
+ editor.destroy();
95
+ });
96
+
97
+ it('does not expand when the caret is not right after the word', () => {
98
+ const editor = createEditor('<p>lorem</p>');
99
+ // Typed rather than parsed from HTML — ProseMirror trims a trailing space on parse.
100
+ editor.view.dispatch(editor.state.tr.insertText(' '));
101
+ const event = pressTab(editor);
102
+ expect(editor.getText()).toBe('lorem ');
103
+ expect(event.defaultPrevented).toBe(false);
104
+ editor.destroy();
105
+ });
106
+
107
+ it('does not expand when text is selected', () => {
108
+ const editor = createEditor('<p>lorem</p>');
109
+ editor.commands.setTextSelection({ from: 1, to: 6 });
110
+ pressTab(editor);
111
+ expect(editor.getText()).toBe('lorem');
112
+ editor.destroy();
113
+ });
114
+
115
+ it('still indents a list item when the word is not lorem', () => {
116
+ const editor = createEditor('<ul><li><p>one</p></li><li><p>two</p></li></ul>');
117
+ pressTab(editor);
118
+ // sinkListItem nests "two" under "one"
119
+ expect(editor.getHTML()).toContain('<ul><li><p>one</p><ul><li><p>two</p></li></ul></li></ul>');
120
+ editor.destroy();
121
+ });
122
+
123
+ it('expands inside a list item instead of indenting it', () => {
124
+ const editor = createEditor('<ul><li><p>one</p></li><li><p>lorem</p></li></ul>');
125
+ pressTab(editor);
126
+ expect(editor.getHTML()).toBe(
127
+ `<ul><li><p>one</p></li><li><p>${LOREM_IPSUM_TEXT}</p></li></ul>`,
128
+ );
129
+ editor.destroy();
130
+ });
131
+ });
@@ -0,0 +1,51 @@
1
+ import { Extension, type Editor } from '@tiptap/react';
2
+
3
+ /** Verbatim from the old plate editor's lorem ipsum plugin, so the two stay in parity. */
4
+ export const LOREM_IPSUM_TEXT =
5
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
6
+
7
+ const TRIGGER_WORD = 'lorem';
8
+
9
+ const ALPHANUMERIC = /[0-9A-Za-z]/;
10
+
11
+ /**
12
+ * Replaces a trailing `lorem` with the full paragraph. Returns false when the word
13
+ * before the caret is something else, which lets Tab fall through to whatever else
14
+ * binds it (ListItem sinks the item, otherwise the browser moves focus).
15
+ */
16
+ export function expandLoremIpsum(editor: Editor): boolean {
17
+ const { doc, selection } = editor.state;
18
+ const { $from, empty } = selection;
19
+ if (!empty || !$from.parent.isTextblock) return false;
20
+
21
+ const blockStart = $from.start();
22
+ const wordStart = $from.pos - TRIGGER_WORD.length;
23
+ if (wordStart < blockStart) return false;
24
+ if (doc.textBetween(wordStart, $from.pos).toLowerCase() !== TRIGGER_WORD) return false;
25
+
26
+ // Only expand a standalone word — "watermelorem" keeps its Tab.
27
+ const charBefore = wordStart > blockStart ? doc.textBetween(wordStart - 1, wordStart) : '';
28
+ if (ALPHANUMERIC.test(charBefore)) return false;
29
+
30
+ return editor
31
+ .chain()
32
+ .command(({ tr }) => {
33
+ // insertText over insertContent: it carries the marks at the caret onto the new
34
+ // text (so expanding inside bold stays bold) and never reparses the string as HTML.
35
+ tr.insertText(LOREM_IPSUM_TEXT, wordStart, $from.pos);
36
+ return true;
37
+ })
38
+ .run();
39
+ }
40
+
41
+ export const LoremIpsum = Extension.create({
42
+ name: 'loremIpsum',
43
+ // Above ListItem's default-priority Tab binding, so `lorem` expands inside a list
44
+ // item instead of indenting it.
45
+ priority: 1000,
46
+ addKeyboardShortcuts() {
47
+ return {
48
+ Tab: () => expandLoremIpsum(this.editor),
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,93 @@
1
+ import { Editor } from '@tiptap/react';
2
+ import { stripPastedInlineStyles } from './paste';
3
+ import { buildExtensions } from './plugins';
4
+
5
+ /**
6
+ * E-1235: text pasted from Word / Google Docs kept the source's inline styles,
7
+ * which outrank theme text styles, style presets and the element's own CSS — so
8
+ * switching the element to H1/H2 and changing the size in the design editor had
9
+ * no visible effect.
10
+ */
11
+ describe('stripPastedInlineStyles (E-1235)', () => {
12
+ it('drops font-size from a pasted span and the attribute with it', () => {
13
+ expect(stripPastedInlineStyles('<h1><span style="font-size: 18pt;">Headline</span></h1>')).toBe(
14
+ '<h1><span>Headline</span></h1>',
15
+ );
16
+ });
17
+
18
+ it('drops the size off the paragraph itself', () => {
19
+ expect(stripPastedInlineStyles('<p style="font-size:12.0pt">Body</p>')).toBe('<p>Body</p>');
20
+ });
21
+
22
+ it('drops every other declaration too', () => {
23
+ expect(
24
+ stripPastedInlineStyles(
25
+ '<p style="color:#f00;background:#eee;line-height:2;margin:40px;text-align:right">Body</p>',
26
+ ),
27
+ ).toBe('<p>Body</p>');
28
+ });
29
+
30
+ it('drops the size off a pasted <a>, keeping the href', () => {
31
+ expect(stripPastedInlineStyles('<a href="/x" style="font-size: 14pt">Link</a>')).toBe(
32
+ '<a href="/x">Link</a>',
33
+ );
34
+ });
35
+
36
+ it('holds back the declarations the mark set parses formatting from', () => {
37
+ // Word and Google Docs express bold / italic / underline this way, and these
38
+ // never survive as inline style — TipTap re-serializes them as tags.
39
+ expect(
40
+ stripPastedInlineStyles(
41
+ '<span style="font-size:11pt;font-weight:700;font-style:italic;text-decoration:underline">Hi</span>',
42
+ ),
43
+ ).toBe(
44
+ '<span style="font-weight: 700; font-style: italic; text-decoration: underline;">Hi</span>',
45
+ );
46
+ });
47
+
48
+ it('leaves markup without inline styles untouched', () => {
49
+ const html = '<p>Plain <strong>text</strong></p>';
50
+ expect(stripPastedInlineStyles(html)).toBe(html);
51
+ });
52
+ });
53
+
54
+ describe('the paste transform in the editor (E-1235)', () => {
55
+ const createEditor = () =>
56
+ new Editor({ extensions: buildExtensions({ current: '' }), content: '' });
57
+
58
+ /** The transform TipTap composes from the extensions, as createView wires it up. */
59
+ const transformPaste = (editor: Editor, html: string) =>
60
+ editor.extensionManager.transformPastedHTML()(html);
61
+
62
+ it('is contributed by the FontSize mark, so no editorProps wiring is needed', () => {
63
+ const editor = createEditor();
64
+
65
+ expect(transformPaste(editor, '<h2><span style="font-size: 18pt;">Headline</span></h2>')).toBe(
66
+ '<h2><span>Headline</span></h2>',
67
+ );
68
+ });
69
+
70
+ it('leaves no inline style in the document a paste produces', () => {
71
+ const editor = createEditor();
72
+ const pasted = transformPaste(
73
+ editor,
74
+ '<h2 style="margin:0"><span style="font-size: 18pt; color: red">Headline</span></h2>',
75
+ );
76
+
77
+ editor.commands.setContent(pasted);
78
+
79
+ expect(editor.getHTML()).toBe('<h2>Headline</h2>');
80
+ });
81
+
82
+ it('still turns a Google Docs bold span into <strong>', () => {
83
+ const editor = createEditor();
84
+ const pasted = transformPaste(
85
+ editor,
86
+ '<b style="font-weight:normal"><p><span style="font-size:11pt;font-weight:700">Bold</span></p></b>',
87
+ );
88
+
89
+ editor.commands.setContent(pasted);
90
+
91
+ expect(editor.getHTML()).toBe('<p><strong>Bold</strong></p>');
92
+ });
93
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Inline styles have no business in a text element: they outrank every
3
+ * stylesheet Vev writes — theme text styles, style presets and the element's own
4
+ * CSS — so markup pasted from Word, Google Docs or a web page arrived deaf to
5
+ * the H1/H2 tag and to the size set in the design editor (E-1235). Pasted markup
6
+ * therefore loses its `style` attribute here, before the schema parses it.
7
+ *
8
+ * Three declarations are held back for the parse, because the mark set reads
9
+ * formatting off them rather than off tags:
10
+ *
11
+ * - `font-weight` — Bold. Also load-bearing in reverse: Google Docs wraps its
12
+ * whole payload in `<b style="font-weight:normal">`, and Bold's parse rule
13
+ * keeps a `<b>` unless the style says normal. Drop the declaration and every
14
+ * Docs paste turns bold.
15
+ * - `font-style` — Italic.
16
+ * - `text-decoration` — Underline and Strike.
17
+ *
18
+ * None of them survive as inline style: TipTap re-serializes them as `<strong>`,
19
+ * `<em>`, `<u>` and `<s>`. The one mark that does render inline style is FontSize
20
+ * (font-size.ts, kept for legacy Plate content on *load*), which is exactly what
21
+ * this has to take away from a paste.
22
+ */
23
+ const PARSED_DECLARATIONS = ['font-weight', 'font-style', 'text-decoration'];
24
+
25
+ export function stripPastedInlineStyles(html: string): string {
26
+ if (!html || !/style\s*=/i.test(html)) return html;
27
+
28
+ const doc = new DOMParser().parseFromString(html, 'text/html');
29
+ doc.body.querySelectorAll<HTMLElement>('[style]').forEach((element) => {
30
+ const keep = PARSED_DECLARATIONS.map(
31
+ (property) => [property, element.style.getPropertyValue(property)] as const,
32
+ ).filter(([, value]) => value);
33
+
34
+ element.removeAttribute('style');
35
+ for (const [property, value] of keep) element.style.setProperty(property, value);
36
+ });
37
+
38
+ return doc.body.innerHTML;
39
+ }
@@ -0,0 +1,143 @@
1
+ import { Editor } from '@tiptap/react';
2
+ import { buildExtensions } from './plugins';
3
+ import type { LinkAttributes } from './link-menu';
4
+
5
+ /**
6
+ * Regression tests for the link menu "settings don't persist" bug.
7
+ *
8
+ * Two root causes are covered:
9
+ * 1. StarterKit v3 bundles Link + Underline, which duplicated our custom
10
+ * linkExtension ("Duplicate extension names" warning). The two link marks
11
+ * rendered HTML differently, so getHTML() never matched the saved value and
12
+ * the value-sync effect reset the editor on every update.
13
+ * 2. The stock Link mark defaults `target` to '_blank', so a link with NO
14
+ * target attribute (= "New Tab" toggled off) parsed back as '_blank',
15
+ * silently reverting the toggle on reopen/reload.
16
+ */
17
+
18
+ const createEditor = (content: string) =>
19
+ new Editor({ extensions: buildExtensions({ current: '' }), content });
20
+
21
+ const selectLinkText = (editor: Editor) =>
22
+ // Place cursor inside the link text, then extend over the whole mark —
23
+ // same as the rich text field's updateLink/selectLink commands.
24
+ editor.chain().setTextSelection(3).extendMarkRange('link').run();
25
+
26
+ describe('rich text field link extension', () => {
27
+ it('registers exactly one link and one underline extension (no StarterKit duplicates)', () => {
28
+ const editor = createEditor('<p>hi</p>');
29
+ const names = editor.extensionManager.extensions.map((e) => e.name);
30
+ expect(names.filter((n) => n === 'link')).toHaveLength(1);
31
+ expect(names.filter((n) => n === 'underline')).toHaveLength(1);
32
+ editor.destroy();
33
+ });
34
+
35
+ it('parses a link without target as target=null (New Tab off stays off)', () => {
36
+ const editor = createEditor('<p><a href="pnXR4lkvnq1">home</a></p>');
37
+ selectLinkText(editor);
38
+ const attrs = editor.getAttributes('link');
39
+ expect(attrs.href).toBe('pnXR4lkvnq1');
40
+ expect(attrs.target).toBeNull();
41
+ expect(attrs.rel).toBeNull();
42
+ editor.destroy();
43
+ });
44
+
45
+ it('persists toggling New Tab ON through serialize → reparse', () => {
46
+ const editor = createEditor('<p><a href="pnXR4lkvnq1">home</a></p>');
47
+ selectLinkText(editor);
48
+ editor
49
+ .chain()
50
+ .extendMarkRange('link')
51
+ .setLink({ href: 'pnXR4lkvnq1', target: '_blank', rel: null })
52
+ .run();
53
+ const html = editor.getHTML();
54
+ expect(html).toContain('target="_blank"');
55
+ editor.destroy();
56
+
57
+ // Reparse (what happens when the field remounts from the saved value)
58
+ const reopened = createEditor(html);
59
+ selectLinkText(reopened);
60
+ expect(reopened.getAttributes('link').target).toBe('_blank');
61
+ reopened.destroy();
62
+ });
63
+
64
+ it('persists toggling New Tab OFF through serialize → reparse', () => {
65
+ const editor = createEditor('<p><a href="pnXR4lkvnq1" target="_blank">home</a></p>');
66
+ selectLinkText(editor);
67
+ expect(editor.getAttributes('link').target).toBe('_blank');
68
+
69
+ editor
70
+ .chain()
71
+ .extendMarkRange('link')
72
+ .setLink({ href: 'pnXR4lkvnq1', target: null, rel: null })
73
+ .run();
74
+ const html = editor.getHTML();
75
+ expect(html).not.toContain('target=');
76
+ editor.destroy();
77
+
78
+ const reopened = createEditor(html);
79
+ selectLinkText(reopened);
80
+ expect(reopened.getAttributes('link').target).toBeNull();
81
+ reopened.destroy();
82
+ });
83
+
84
+ it('persists rel attributes through serialize → reparse', () => {
85
+ const editor = createEditor('<p><a href="pnXR4lkvnq1">home</a></p>');
86
+ selectLinkText(editor);
87
+ editor
88
+ .chain()
89
+ .extendMarkRange('link')
90
+ .setLink({ href: 'pnXR4lkvnq1', target: null, rel: 'noreferrer ugc' })
91
+ .run();
92
+ const html = editor.getHTML();
93
+ editor.destroy();
94
+
95
+ const reopened = createEditor(html);
96
+ selectLinkText(reopened);
97
+ expect(reopened.getAttributes('link').rel).toBe('noreferrer ugc');
98
+ reopened.destroy();
99
+ });
100
+
101
+ it('persists the download attribute through serialize \u2192 reparse (file links)', () => {
102
+ const editor = createEditor('<p><a href="pnXR4lkvnq1">home</a></p>');
103
+ selectLinkText(editor);
104
+ // Typed as LinkAttributes rather than inline: TipTap's stock setLink type
105
+ // does not list download / fontSize (we add those on the mark).
106
+ const attrs: LinkAttributes = {
107
+ href: 'https://storage.vev.design/abc',
108
+ download: 'report.pdf',
109
+ };
110
+ editor.chain().extendMarkRange('link').setLink(attrs).run();
111
+ const html = editor.getHTML();
112
+ // `download` is what makes the browser save the file rather than navigate to it.
113
+ expect(html).toContain('download="report.pdf"');
114
+ editor.destroy();
115
+
116
+ const reopened = createEditor(html);
117
+ selectLinkText(reopened);
118
+ expect(reopened.getAttributes('link').download).toBe('report.pdf');
119
+ reopened.destroy();
120
+ });
121
+
122
+ it('leaves download off links that are not files', () => {
123
+ const editor = createEditor('<p><a href="pnXR4lkvnq1">home</a></p>');
124
+ selectLinkText(editor);
125
+ expect(editor.getAttributes('link').download).toBeNull();
126
+ expect(editor.getHTML()).not.toContain('download');
127
+ editor.destroy();
128
+ });
129
+
130
+ it('round-trips link HTML stably (guards against the value-sync reset loop)', () => {
131
+ const source =
132
+ '<p><a rel="noreferrer ugc" class="link" href="pnXR4lkvnq1">home</a> and <a target="_blank" class="link" href="https://vev.design">vev</a></p>';
133
+ const editor = createEditor(source);
134
+ const firstPass = editor.getHTML();
135
+ editor.destroy();
136
+
137
+ // Feeding getHTML() output back in must produce identical output, otherwise
138
+ // the field's `getHTML() !== value` effect calls setContent forever.
139
+ const second = createEditor(firstPass);
140
+ expect(second.getHTML()).toBe(firstPass);
141
+ second.destroy();
142
+ });
143
+ });