@vev/silke 1.1.9 → 1.2.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 (189) hide show
  1. package/.turbo/turbo-build.log +162 -77
  2. package/CHANGELOG.md +40 -0
  3. package/dist/index.js +47 -40
  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/index.d.ts +1 -0
  31. package/dist/types/components/silke-form-schema/silke-form-schema.d.ts +4 -1
  32. package/dist/types/components/silke-form-schema/silke-schema-decorator.d.ts +17 -0
  33. package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
  34. package/dist/types/components/silke-form-schema/silke-schema-fields.d.ts +2 -0
  35. package/dist/types/components/silke-form-schema/silke-schema-path.spec.d.ts +1 -0
  36. package/dist/types/components/silke-gradient-picker/silke-gradient-utils.d.ts +2 -0
  37. package/dist/types/components/silke-icon-picker/color-swatch-section.d.ts +6 -0
  38. package/dist/types/components/silke-icon-picker/emoji-tab.d.ts +1 -1
  39. package/dist/types/components/silke-icon-picker/icons-tab.d.ts +1 -1
  40. package/dist/types/components/silke-icon-picker/silke-icon-picker.d.ts +2 -0
  41. package/dist/types/components/silke-icon-picker/utils.d.ts +2 -0
  42. package/dist/types/components/silke-list/silke-list-item.d.ts +5 -1
  43. package/dist/types/components/silke-list/types.d.ts +1 -0
  44. package/dist/types/components/silke-navigation-link/silke-navigation-link.d.ts +15 -0
  45. package/dist/types/components/silke-popover/popover-context.spec.d.ts +1 -0
  46. package/dist/types/components/silke-rich-text-field/blockquote.d.ts +21 -0
  47. package/dist/types/components/silke-rich-text-field/blockquote.spec.d.ts +1 -0
  48. package/dist/types/components/silke-rich-text-field/dropcap.d.ts +27 -0
  49. package/dist/types/components/silke-rich-text-field/dropcap.spec.d.ts +1 -0
  50. package/dist/types/components/silke-rich-text-field/floating-layer.d.ts +12 -0
  51. package/dist/types/components/silke-rich-text-field/font-size.d.ts +2 -0
  52. package/dist/types/components/silke-rich-text-field/formatting-toolbar.d.ts +9 -0
  53. package/dist/types/components/silke-rich-text-field/index.d.ts +1 -0
  54. package/dist/types/components/silke-rich-text-field/jsdom-rects.d.ts +10 -0
  55. package/dist/types/components/silke-rich-text-field/link-menu.d.ts +26 -0
  56. package/dist/types/components/silke-rich-text-field/link-menu.spec.d.ts +1 -0
  57. package/dist/types/components/silke-rich-text-field/link-suggestions.d.ts +48 -0
  58. package/dist/types/components/silke-rich-text-field/link-suggestions.spec.d.ts +1 -0
  59. package/dist/types/components/silke-rich-text-field/link-tooltip.d.ts +15 -0
  60. package/dist/types/components/silke-rich-text-field/list-item.d.ts +15 -0
  61. package/dist/types/components/silke-rich-text-field/list-link-fontsize.spec.d.ts +1 -0
  62. package/dist/types/components/silke-rich-text-field/lorem-ipsum.d.ts +10 -0
  63. package/dist/types/components/silke-rich-text-field/lorem-ipsum.spec.d.ts +1 -0
  64. package/dist/types/components/silke-rich-text-field/paste.d.ts +1 -0
  65. package/dist/types/components/silke-rich-text-field/paste.spec.d.ts +1 -0
  66. package/dist/types/components/silke-rich-text-field/plugins.d.ts +18 -0
  67. package/dist/types/components/silke-rich-text-field/plugins.spec.d.ts +1 -0
  68. package/dist/types/components/silke-rich-text-field/silke-rich-text-field.d.ts +60 -0
  69. package/dist/types/components/silke-rich-text-field/slash-menu-items.d.ts +10 -0
  70. package/dist/types/components/silke-rich-text-field/slash-menu.d.ts +11 -0
  71. package/dist/types/components/silke-rich-text-field/table-content-sync.spec.d.ts +1 -0
  72. package/dist/types/components/silke-rich-text-field/table-toolbar.d.ts +17 -0
  73. package/dist/types/components/silke-rich-text-field/table-toolbar.spec.d.ts +1 -0
  74. package/dist/types/components/silke-rich-text-field/table.spec.d.ts +1 -0
  75. package/dist/types/components/silke-rich-text-field/use-link-hover.d.ts +15 -0
  76. package/dist/types/components/silke-rich-text-field/use-slash-menu.d.ts +13 -0
  77. package/dist/types/components/silke-rich-text-field/utils.d.ts +13 -0
  78. package/dist/types/components/silke-sortable-list/index.d.ts +1 -1
  79. package/dist/types/components/silke-sortable-list/silke-nested-sortable-list.d.ts +8 -1
  80. package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +13 -6
  81. package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +6 -1
  82. package/dist/types/icons.d.ts +18 -0
  83. package/esbuild.config.mjs +9 -4
  84. package/package.json +22 -9
  85. package/src/components/index.ts +2 -0
  86. package/src/components/silke-alert-banner/silke-alert-banner.tsx +1 -1
  87. package/src/components/silke-autocomplete-field/autocomplete-item.tsx +47 -61
  88. package/src/components/silke-autocomplete-field/silke-autocomplete-field-native.tsx +13 -2
  89. package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +8 -5
  90. package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +2 -1
  91. package/src/components/silke-box/silke-box.scss +4 -0
  92. package/src/components/silke-box/silke-box.tsx +4 -0
  93. package/src/components/silke-button/silke-dropdown-button.tsx +4 -1
  94. package/src/components/silke-card/silke-card.scss +4 -0
  95. package/src/components/silke-card/silke-card.tsx +3 -0
  96. package/src/components/silke-command-text-field/index.ts +1 -0
  97. package/src/components/silke-command-text-field/silke-command-parser.spec.ts +55 -0
  98. package/src/components/silke-command-text-field/silke-command-parser.ts +33 -2
  99. package/src/components/silke-command-text-field/silke-command-text-field.module.scss +3 -0
  100. package/src/components/silke-command-text-field/silke-command-text-field.tsx +53 -48
  101. package/src/components/silke-command-text-field/utils.spec.ts +192 -0
  102. package/src/components/silke-command-text-field/utils.ts +99 -16
  103. package/src/components/silke-css-number-field/silke-css-number-field.spec.tsx +115 -0
  104. package/src/components/silke-css-number-field/silke-css-number-field.tsx +33 -0
  105. package/src/components/silke-expression-input/index.ts +3 -0
  106. package/src/components/silke-expression-input/silke-expression-input-tag.tsx +37 -0
  107. package/src/components/silke-expression-input/silke-expression-input.mdx +40 -0
  108. package/src/components/silke-expression-input/silke-expression-input.scss +24 -0
  109. package/src/components/silke-expression-input/silke-expression-input.tsx +343 -0
  110. package/src/components/silke-expression-input/utils.ts +144 -0
  111. package/src/components/silke-form-schema/fields/array-field-inline.tsx +4 -0
  112. package/src/components/silke-form-schema/fields/array-field-modal.tsx +4 -0
  113. package/src/components/silke-form-schema/fields/array-field.tsx +6 -11
  114. package/src/components/silke-form-schema/fields/group-field.tsx +2 -0
  115. package/src/components/silke-form-schema/fields/layout-field.tsx +2 -0
  116. package/src/components/silke-form-schema/fields/number-field.tsx +114 -4
  117. package/src/components/silke-form-schema/fields/object-field.tsx +2 -0
  118. package/src/components/silke-form-schema/fields/popover-field.tsx +2 -0
  119. package/src/components/silke-form-schema/fields/string-field.tsx +27 -1
  120. package/src/components/silke-form-schema/index.ts +1 -0
  121. package/src/components/silke-form-schema/silke-form-schema.mdx +30 -1
  122. package/src/components/silke-form-schema/silke-form-schema.tsx +12 -6
  123. package/src/components/silke-form-schema/silke-schema-decorator.tsx +32 -0
  124. package/src/components/silke-form-schema/silke-schema-field.tsx +19 -2
  125. package/src/components/silke-form-schema/silke-schema-fields.tsx +30 -4
  126. package/src/components/silke-form-schema/silke-schema-path.spec.tsx +160 -0
  127. package/src/components/silke-gradient-picker/silke-gradient-picker.tsx +3 -1
  128. package/src/components/silke-gradient-picker/silke-gradient-utils.ts +23 -3
  129. package/src/components/silke-icon/silke-shape.tsx +1 -1
  130. package/src/components/silke-icon-picker/color-swatch-section.tsx +61 -0
  131. package/src/components/silke-icon-picker/emoji-tab.tsx +8 -6
  132. package/src/components/silke-icon-picker/icons-tab.tsx +8 -7
  133. package/src/components/silke-icon-picker/silke-icon-picker.tsx +52 -25
  134. package/src/components/silke-icon-picker/styles.scss +66 -1
  135. package/src/components/silke-icon-picker/utils.ts +2 -0
  136. package/src/components/silke-list/silke-list-item.scss +10 -0
  137. package/src/components/silke-list/silke-list-item.tsx +16 -3
  138. package/src/components/silke-list/silke-list.mdx +18 -0
  139. package/src/components/silke-list/types.ts +1 -0
  140. package/src/components/silke-navigation-link/silke-navigation-link.scss +162 -42
  141. package/src/components/silke-navigation-link/silke-navigation-link.tsx +99 -21
  142. package/src/components/silke-popover/popover-context.spec.tsx +44 -0
  143. package/src/components/silke-popover-native/silke-popover-native.scss +5 -3
  144. package/src/components/silke-rich-text-field/blockquote.spec.ts +151 -0
  145. package/src/components/silke-rich-text-field/blockquote.ts +90 -0
  146. package/src/components/silke-rich-text-field/dropcap.spec.ts +67 -0
  147. package/src/components/silke-rich-text-field/dropcap.ts +59 -0
  148. package/src/components/silke-rich-text-field/floating-layer.tsx +15 -0
  149. package/src/components/silke-rich-text-field/font-size.ts +62 -0
  150. package/src/components/silke-rich-text-field/formatting-toolbar.tsx +145 -0
  151. package/src/components/silke-rich-text-field/index.ts +1 -0
  152. package/src/components/silke-rich-text-field/jsdom-rects.ts +15 -0
  153. package/src/components/silke-rich-text-field/link-menu.spec.tsx +502 -0
  154. package/src/components/silke-rich-text-field/link-menu.tsx +553 -0
  155. package/src/components/silke-rich-text-field/link-suggestions.spec.ts +203 -0
  156. package/src/components/silke-rich-text-field/link-suggestions.ts +188 -0
  157. package/src/components/silke-rich-text-field/link-tooltip.tsx +60 -0
  158. package/src/components/silke-rich-text-field/list-item.ts +64 -0
  159. package/src/components/silke-rich-text-field/list-link-fontsize.spec.ts +135 -0
  160. package/src/components/silke-rich-text-field/lorem-ipsum.spec.ts +131 -0
  161. package/src/components/silke-rich-text-field/lorem-ipsum.ts +51 -0
  162. package/src/components/silke-rich-text-field/paste.spec.ts +93 -0
  163. package/src/components/silke-rich-text-field/paste.ts +39 -0
  164. package/src/components/silke-rich-text-field/plugins.spec.ts +143 -0
  165. package/src/components/silke-rich-text-field/plugins.ts +230 -0
  166. package/src/components/silke-rich-text-field/silke-rich-text-field.mdx +180 -0
  167. package/src/components/silke-rich-text-field/silke-rich-text-field.scss +343 -0
  168. package/src/components/silke-rich-text-field/silke-rich-text-field.tsx +505 -0
  169. package/src/components/silke-rich-text-field/slash-menu-items.ts +112 -0
  170. package/src/components/silke-rich-text-field/slash-menu.tsx +50 -0
  171. package/src/components/silke-rich-text-field/table-content-sync.spec.tsx +61 -0
  172. package/src/components/silke-rich-text-field/table-toolbar.spec.tsx +168 -0
  173. package/src/components/silke-rich-text-field/table-toolbar.tsx +121 -0
  174. package/src/components/silke-rich-text-field/table.spec.ts +87 -0
  175. package/src/components/silke-rich-text-field/use-link-hover.ts +63 -0
  176. package/src/components/silke-rich-text-field/use-slash-menu.ts +130 -0
  177. package/src/components/silke-rich-text-field/utils.ts +55 -0
  178. package/src/components/silke-sortable-list/index.ts +1 -1
  179. package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +11 -1
  180. package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +9 -0
  181. package/src/components/silke-sortable-list/silke-sortable-list.mdx +13 -0
  182. package/src/components/silke-tag/silke-tag.scss +12 -3
  183. package/src/components/silke-theme-card/silke-theme-card.module.scss +141 -45
  184. package/src/components/silke-theme-card/silke-theme-card.tsx +76 -47
  185. package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +56 -0
  186. package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +53 -63
  187. package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +99 -14
  188. package/src/icons.tsx +65 -4
  189. package/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,90 @@
1
+ import { InputRule, type ChainedCommands, type Editor } from '@tiptap/core';
2
+ import { Blockquote, inputRegex } from '@tiptap/extension-blockquote';
3
+ import { DOMParser } from '@tiptap/pm/model';
4
+
5
+ /**
6
+ * A heading inside a quote takes the theme's heading typography, which is never
7
+ * what "quote this" means — demote it first, exactly as the bullet and numbered
8
+ * list items in slash-menu-items.ts do.
9
+ */
10
+ function demoteHeading(editor: Editor, chain: ChainedCommands): ChainedCommands {
11
+ if (editor.isActive('heading')) chain.setParagraph();
12
+ return chain;
13
+ }
14
+
15
+ /**
16
+ * Stock `setBlockquote` is `wrapIn`, and blockquote's content spec is `block+`
17
+ * — so the quote wraps *around* whatever block is there instead of converting
18
+ * it, and wraps again every time it is applied. Quoting a heading produced
19
+ * `<blockquote><h3>…</h3></blockquote>`, and picking Quote a second time
20
+ * produced `<blockquote><blockquote><h3>…</h3></blockquote></blockquote>`.
21
+ *
22
+ * Neither is visible in the editor. The inner heading keeps the theme's h3
23
+ * font-family/size, so the quote renders as a heading, and any block nested
24
+ * under the quote inherits the quote's font-family (theme heading styles fall
25
+ * back to `font-family: inherit` when the theme sets no family for that level —
26
+ * see viewer/theme.css) — so an h5 attribution line inside the quote turned
27
+ * serif. The stacking is silent too: a theme with no quote margin emits
28
+ * `--vev-blockquote-margin: 0`, so the doubled indent that would have given it
29
+ * away is zeroed out.
30
+ *
31
+ * Same class of bug as the heading-in-`<li>` fix in list-item.ts (E-1228), and
32
+ * the same two-part shape: normalize what is already saved while parsing, and
33
+ * stop the command creating more of it.
34
+ */
35
+ export const blockquoteExtension = Blockquote.extend({
36
+ parseHTML() {
37
+ return [
38
+ {
39
+ tag: 'blockquote',
40
+ getContent(dom, schema) {
41
+ const element = dom as HTMLElement;
42
+
43
+ // Collapse a blockquote whose only child is another blockquote. Only
44
+ // the redundant case — a quote with sibling content alongside a nested
45
+ // quote is left alone, so a genuine quote-within-a-quote survives.
46
+ let inner = element;
47
+ while (inner.children.length === 1 && inner.firstElementChild?.tagName === 'BLOCKQUOTE') {
48
+ inner = inner.firstElementChild as HTMLElement;
49
+ }
50
+
51
+ return DOMParser.fromSchema(schema).parseSlice(inner).content;
52
+ },
53
+ },
54
+ ];
55
+ },
56
+
57
+ addCommands() {
58
+ return {
59
+ ...this.parent?.(),
60
+ setBlockquote:
61
+ () =>
62
+ ({ chain, editor }) => {
63
+ // `set` is idempotent: already a quote means there is nothing to do.
64
+ // Wrapping again is what stacked the blockquotes.
65
+ if (editor.isActive('blockquote')) return demoteHeading(editor, chain()).run();
66
+ return demoteHeading(editor, chain()).wrapIn(this.name).run();
67
+ },
68
+ toggleBlockquote:
69
+ () =>
70
+ ({ chain, commands, editor }) => {
71
+ if (editor.isActive('blockquote')) return commands.lift(this.name);
72
+ return demoteHeading(editor, chain()).wrapIn(this.name).run();
73
+ },
74
+ };
75
+ },
76
+
77
+ // Stock rule is a `wrappingInputRule`, which bypasses the commands above — so
78
+ // typing "> " in a heading rebuilt the same `<blockquote><h3>`. Route it through
79
+ // setBlockquote instead.
80
+ addInputRules() {
81
+ return [
82
+ new InputRule({
83
+ find: inputRegex,
84
+ handler: ({ chain, range }) => {
85
+ chain().deleteRange(range).setBlockquote().run();
86
+ },
87
+ }),
88
+ ];
89
+ },
90
+ });
@@ -0,0 +1,67 @@
1
+ import { Editor } from '@tiptap/react';
2
+ import { buildExtensions } from './plugins';
3
+
4
+ /**
5
+ * Regression tests for "the dropcap is gone from the new text editor".
6
+ *
7
+ * The missing toolbar button was the visible half. The damaging half was that with no
8
+ * `dropcap` mark in the schema ProseMirror unwrapped `<span class="dropcap">` on load —
9
+ * `<p><span class="dropcap">L</span>orem</p>` parsed to `<p>Lorem</p>` — so the first
10
+ * keystroke in a legacy text element saved the stripped HTML over the user's dropcap.
11
+ */
12
+
13
+ const createEditor = (content: string) =>
14
+ new Editor({ extensions: buildExtensions({ current: '' }), content });
15
+
16
+ const selectFirstCharacter = (editor: Editor) =>
17
+ editor.chain().setTextSelection({ from: 1, to: 2 }).run();
18
+
19
+ describe('rich text field dropcap mark', () => {
20
+ it('round-trips legacy dropcap markup untouched', () => {
21
+ const editor = createEditor('<p><span class="dropcap">L</span>orem ipsum</p>');
22
+ // Byte-for-byte: anything else and the value-sync effect rewrites every existing
23
+ // dropcap the first time the element is opened.
24
+ expect(editor.getHTML()).toBe('<p><span class="dropcap">L</span>orem ipsum</p>');
25
+ editor.destroy();
26
+ });
27
+
28
+ it('reports the mark as active inside a legacy dropcap', () => {
29
+ const editor = createEditor('<p><span class="dropcap">L</span>orem ipsum</p>');
30
+ selectFirstCharacter(editor);
31
+ expect(editor.isActive('dropcap')).toBe(true);
32
+ editor.destroy();
33
+ });
34
+
35
+ it('toggles a dropcap on and back off', () => {
36
+ const editor = createEditor('<p>Lorem ipsum</p>');
37
+ selectFirstCharacter(editor);
38
+
39
+ editor.chain().toggleDropcap().run();
40
+ expect(editor.getHTML()).toBe('<p><span class="dropcap">L</span>orem ipsum</p>');
41
+
42
+ selectFirstCharacter(editor);
43
+ editor.chain().toggleDropcap().run();
44
+ expect(editor.getHTML()).toBe('<p>Lorem ipsum</p>');
45
+ editor.destroy();
46
+ });
47
+
48
+ it('keeps the class-first markup the design panel matches on when nested in bold', () => {
49
+ const editor = createEditor('<p>Lorem ipsum</p>');
50
+ selectFirstCharacter(editor);
51
+ editor.chain().toggleBold().run();
52
+ selectFirstCharacter(editor);
53
+ editor.chain().toggleDropcap().run();
54
+
55
+ // The panel reveals its "Span Dropcap" style section by searching the saved text for
56
+ // this literal substring (editor data/selection/utils/helpers.ts), so it has to survive
57
+ // whatever other marks the character carries.
58
+ expect(editor.getHTML()).toContain('<span class="dropcap"');
59
+ editor.destroy();
60
+ });
61
+
62
+ it('normalizes a dropcap carrying other classes back to just dropcap', () => {
63
+ const editor = createEditor('<p><span class="dropcap slate-leaf">L</span>orem</p>');
64
+ expect(editor.getHTML()).toBe('<p><span class="dropcap">L</span>orem</p>');
65
+ editor.destroy();
66
+ });
67
+ });
@@ -0,0 +1,59 @@
1
+ import { Mark, mergeAttributes } from '@tiptap/core';
2
+
3
+ /**
4
+ * The dropcap the old plate editor shipped, ported to TipTap.
5
+ *
6
+ * Registering it is not only what puts the toolbar button back — ProseMirror does not
7
+ * preserve inline elements it has no mark for, it unwraps them and keeps the text. So
8
+ * without this mark every legacy `<span class="dropcap">` parsed away on load, and the
9
+ * first keystroke in the element saved the stripped HTML over the user's content.
10
+ *
11
+ * The markup is deliberately identical to what plate serialized. That keeps three things
12
+ * working with no migration and no viewer change:
13
+ * - `.text span.dropcap` in viewer/static-components.css styles the published render,
14
+ * - the text element's package CSS declares `span.dropcap` with `vev()` properties, which
15
+ * is what gives the design panel its "Span Dropcap" style section,
16
+ * - the panel only reveals that section when the saved text contains the literal
17
+ * `<span class="dropcap"` (see editor data/selection/utils/helpers.ts).
18
+ */
19
+ export const Dropcap = Mark.create({
20
+ name: 'dropcap',
21
+
22
+ parseHTML() {
23
+ return [{ tag: 'span.dropcap' }];
24
+ },
25
+
26
+ renderHTML({ HTMLAttributes }) {
27
+ // class last so it always wins: a dropcap that arrives carrying some other class
28
+ // (or none) still serializes as exactly `<span class="dropcap">`, which is the string
29
+ // the design panel's selector detection matches on.
30
+ return ['span', mergeAttributes(HTMLAttributes, { class: 'dropcap' }), 0];
31
+ },
32
+
33
+ addCommands() {
34
+ return {
35
+ setDropcap:
36
+ () =>
37
+ ({ commands }) =>
38
+ commands.setMark(this.name),
39
+ toggleDropcap:
40
+ () =>
41
+ ({ commands }) =>
42
+ commands.toggleMark(this.name),
43
+ unsetDropcap:
44
+ () =>
45
+ ({ commands }) =>
46
+ commands.unsetMark(this.name),
47
+ };
48
+ },
49
+ });
50
+
51
+ declare module '@tiptap/core' {
52
+ interface Commands<ReturnType> {
53
+ dropcap: {
54
+ setDropcap: () => ReturnType;
55
+ toggleDropcap: () => ReturnType;
56
+ unsetDropcap: () => ReturnType;
57
+ };
58
+ }
59
+ }
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { createPortal } from 'react-dom';
3
+
4
+ /**
5
+ * Renders the editor's floating menus into `document.body`.
6
+ *
7
+ * The menus have to escape the editor's own DOM: hosts position the field inside
8
+ * containers that create a stacking context (the Vev editor canvas is one), which
9
+ * traps the menus underneath neighbouring panels no matter how high their z-index.
10
+ * Positioned as `fixed` with viewport coordinates once they live on the body.
11
+ */
12
+ export function FloatingLayer({ children }: { children: React.ReactNode }) {
13
+ if (typeof document === 'undefined') return <>{children}</>;
14
+ return createPortal(children, document.body);
15
+ }
@@ -0,0 +1,62 @@
1
+ import { Mark, mergeAttributes } from '@tiptap/core';
2
+ import { stripPastedInlineStyles } from './paste';
3
+
4
+ /**
5
+ * Inline font-size, same job as Dropcap: ProseMirror unwraps elements it has
6
+ * no mark for. The old plate editor stored size on `<span style="font-size: …">`
7
+ * or on the `<a>` itself. Without this mark those sizes parsed away, and the
8
+ * first link edit saved the stripped HTML — list items then fell through to the
9
+ * theme heading size (~48px) while the properties panel still showed the
10
+ * element's set size (E-1228).
11
+ *
12
+ * Content that is *pasted* is the other way round: the size belongs to whatever
13
+ * the user copied from, and keeping it makes the element deaf to its own text
14
+ * styles (E-1235). Pasted markup loses its inline styles on the way in — see
15
+ * transformPastedHTML.
16
+ *
17
+ * Only `font-size` is kept. Other inline styles are out of scope.
18
+ */
19
+
20
+ function readFontSize(element: HTMLElement): string | null {
21
+ const fontSize = element.style?.fontSize?.trim();
22
+ return fontSize || null;
23
+ }
24
+
25
+ export const FontSize = Mark.create({
26
+ name: 'fontSize',
27
+
28
+ // TipTap chains this hook across extensions (and after editorProps'), so the
29
+ // mark that makes inline sizes stick is also the one that keeps them out of a
30
+ // paste. See paste.ts — the whole style attribute goes, not only the size.
31
+ transformPastedHTML: stripPastedInlineStyles,
32
+
33
+ addAttributes() {
34
+ return {
35
+ fontSize: {
36
+ default: null,
37
+ parseHTML: (element) => readFontSize(element),
38
+ renderHTML: (attributes) =>
39
+ attributes.fontSize ? { style: `font-size: ${attributes.fontSize}` } : {},
40
+ },
41
+ };
42
+ },
43
+
44
+ parseHTML() {
45
+ return [
46
+ {
47
+ tag: 'span',
48
+ getAttrs: (node) => {
49
+ if (!(node instanceof HTMLElement)) return false;
50
+ // Dropcap owns `span.dropcap` — do not steal those.
51
+ if (node.classList.contains('dropcap')) return false;
52
+ const fontSize = readFontSize(node);
53
+ return fontSize ? { fontSize } : false;
54
+ },
55
+ },
56
+ ];
57
+ },
58
+
59
+ renderHTML({ HTMLAttributes }) {
60
+ return ['span', mergeAttributes(HTMLAttributes), 0];
61
+ },
62
+ });
@@ -0,0 +1,145 @@
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import type { Editor } from '@tiptap/react';
3
+ import { BubbleMenu } from '@tiptap/react/menus';
4
+ import { SilkeBox } from '../silke-box';
5
+ import { SilkeButton } from '../silke-button';
6
+ import { SilkeDivider } from '../silke-divider';
7
+ import type { SilkeIcons } from '../silke-icon';
8
+
9
+ interface FormattingToolbarProps {
10
+ editor: Editor;
11
+ onLinkClick: () => void;
12
+ onBlockTypeClick: () => void;
13
+ onAIClick?: () => void;
14
+ }
15
+
16
+ function getBlockTypeIcon(editor: Editor): SilkeIcons {
17
+ if (editor.isActive('heading', { level: 1 })) return 'text.h1';
18
+ if (editor.isActive('heading', { level: 2 })) return 'text.h2';
19
+ if (editor.isActive('heading', { level: 3 })) return 'text.h3';
20
+ if (editor.isActive('heading', { level: 4 })) return 'text.h4';
21
+ if (editor.isActive('heading', { level: 5 })) return 'text.h5';
22
+ if (editor.isActive('heading', { level: 6 })) return 'text.h6';
23
+ if (editor.isActive('bulletList')) return 'list.check';
24
+ if (editor.isActive('orderedList')) return 'list.ol';
25
+ if (editor.isActive('blockquote')) return 'text.blockquote';
26
+ return 'text.p';
27
+ }
28
+
29
+ export function FormattingToolbar({
30
+ editor,
31
+ onLinkClick,
32
+ onBlockTypeClick,
33
+ onAIClick,
34
+ }: FormattingToolbarProps) {
35
+ // Both are dependencies of BubbleMenu's "update plugin options" effect, which ends in
36
+ // view.dispatch(). Inline literals are a new identity on every render, so the toolbar
37
+ // dispatched a transaction per render — feeding every transaction listener on the
38
+ // editor, and looping outright against any listener that sets state.
39
+ const appendTo = useCallback(() => document.body, []);
40
+ const bubbleOptions = useMemo(() => ({ strategy: 'fixed' as const }), []);
41
+
42
+ return (
43
+ // Appended to the body and fixed to the viewport so the toolbar is not trapped
44
+ // under panels by whatever stacking context the host puts the editor in.
45
+ <BubbleMenu editor={editor} appendTo={appendTo} options={bubbleOptions} style={{ zIndex: 999 }}>
46
+ <SilkeBox
47
+ data-rich-text-menu
48
+ gap="xxs"
49
+ vAlign="center"
50
+ bg="neutral-10"
51
+ rounded="small"
52
+ shadow="level3"
53
+ border
54
+ pad="xxs"
55
+ >
56
+ {onAIClick && (
57
+ <SilkeButton kind="ghost" size="base" onClick={onAIClick} icon="ai.gradient" title="AI" />
58
+ )}
59
+ <SilkeButton
60
+ kind="ghost"
61
+ size="base"
62
+ icon={getBlockTypeIcon(editor)}
63
+ onClick={onBlockTypeClick}
64
+ title="Change block type"
65
+ />
66
+ <SilkeDivider vertical />
67
+ <SilkeButton
68
+ kind="ghost"
69
+ size="base"
70
+ selected={editor.isActive('bold')}
71
+ onClick={() => editor.chain().focus().toggleBold().run()}
72
+ icon="text.bold"
73
+ title="Bold"
74
+ />
75
+ <SilkeButton
76
+ kind="ghost"
77
+ size="base"
78
+ selected={editor.isActive('italic')}
79
+ onClick={() => editor.chain().focus().toggleItalic().run()}
80
+ icon="text.italic"
81
+ title="Italic"
82
+ />
83
+ <SilkeButton
84
+ kind="ghost"
85
+ size="base"
86
+ selected={editor.isActive('underline')}
87
+ onClick={() => editor.chain().focus().toggleUnderline().run()}
88
+ icon="text.underline"
89
+ title="Underline"
90
+ />
91
+ <SilkeButton
92
+ kind="ghost"
93
+ size="base"
94
+ selected={editor.isActive('strike')}
95
+ onClick={() => editor.chain().focus().toggleStrike().run()}
96
+ label={<s>S</s>}
97
+ title="Strikethrough"
98
+ />
99
+ <SilkeDivider vertical dark />
100
+ <SilkeButton
101
+ kind="ghost"
102
+ size="base"
103
+ selected={editor.isActive('superscript')}
104
+ onClick={() => editor.chain().focus().toggleSuperscript().run()}
105
+ icon="text.superscript"
106
+ title="Superscript"
107
+ />
108
+ <SilkeButton
109
+ kind="ghost"
110
+ size="base"
111
+ selected={editor.isActive('subscript')}
112
+ onClick={() => editor.chain().focus().toggleSubscript().run()}
113
+ icon="text.subscript"
114
+ title="Subscript"
115
+ />
116
+ <SilkeButton
117
+ kind="ghost"
118
+ size="base"
119
+ selected={editor.isActive('dropcap')}
120
+ onClick={() => editor.chain().focus().toggleDropcap().run()}
121
+ icon="text.dropcap"
122
+ title="Dropcap"
123
+ />
124
+ <SilkeDivider vertical dark />
125
+ <SilkeButton
126
+ kind="ghost"
127
+ size="base"
128
+ selected={editor.isActive('code')}
129
+ onClick={() => editor.chain().focus().toggleCode().run()}
130
+ icon="editor.code"
131
+ title="Inline code"
132
+ />
133
+ <SilkeButton
134
+ kind="ghost"
135
+ size="base"
136
+ selected={editor.isActive('link')}
137
+ onClick={onLinkClick}
138
+ icon="link.external"
139
+ title="Link"
140
+ data-cy="rich-text-link"
141
+ />
142
+ </SilkeBox>
143
+ </BubbleMenu>
144
+ );
145
+ }
@@ -0,0 +1 @@
1
+ export * from './silke-rich-text-field';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * jsdom implements neither `getClientRects` nor `Range.getBoundingClientRect`, and
3
+ * ProseMirror calls them via `coordsAtPos` — on every focus, and on mount as soon as a
4
+ * BubbleMenu is present, since it positions against the caret rect. Any spec that renders
5
+ * SilkeRichTextField needs these or it throws "target.getClientRects is not a function".
6
+ *
7
+ * They return empty rects: enough to get through the call, not enough to assert position
8
+ * against. Placement has to be checked in a browser.
9
+ */
10
+ export function stubProseMirrorRects() {
11
+ const emptyRectList = { length: 0, item: () => null } as unknown as DOMRectList;
12
+ Range.prototype.getClientRects = () => emptyRectList;
13
+ Range.prototype.getBoundingClientRect = () => new DOMRect();
14
+ Element.prototype.getClientRects = () => emptyRectList;
15
+ }