@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,230 @@
1
+ import { mergeAttributes } from '@tiptap/core';
2
+ import { Plugin, PluginKey } from '@tiptap/pm/state';
3
+ import { Decoration, DecorationSet } from '@tiptap/pm/view';
4
+ import StarterKit from '@tiptap/starter-kit';
5
+ // StarterKit bundles the list extensions at runtime, but its types do not pull in the
6
+ // `Commands` augmentation that declares toggleBulletList/toggleOrderedList — TypeScript
7
+ // only applies a module's augmentations when that module is part of the program. Without
8
+ // this import the list commands do not exist on ChainedCommands and build:types fails.
9
+ import type {} from '@tiptap/extension-list';
10
+ import Placeholder from '@tiptap/extension-placeholder';
11
+ import Underline from '@tiptap/extension-underline';
12
+ import Superscript from '@tiptap/extension-superscript';
13
+ import Subscript from '@tiptap/extension-subscript';
14
+ import Link, { isAllowedUri } from '@tiptap/extension-link';
15
+ import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
16
+ import classnames from 'classnames/bind';
17
+ import { blockquoteExtension } from './blockquote';
18
+ import { Dropcap } from './dropcap';
19
+ import { FontSize } from './font-size';
20
+ import type { LinkAttributes } from './link-menu';
21
+ import { listItemExtension, StayInList } from './list-item';
22
+ import { LoremIpsum } from './lorem-ipsum';
23
+ import styles from './silke-rich-text-field.scss';
24
+
25
+ const cl = classnames.bind(styles);
26
+
27
+ // ─── Extensions (created once at module level) ──────────────────────
28
+
29
+ export const starterKit = StarterKit.configure({
30
+ heading: { levels: [1, 2, 3, 4, 5, 6] },
31
+ codeBlock: false,
32
+ trailingNode: false,
33
+ // Replaced by listItemExtension, which keeps `paragraph block*` (nested lists)
34
+ // but flattens a heading that is a direct child of `<li>`. See list-item.ts.
35
+ listItem: false,
36
+ // Replaced by blockquoteExtension, which stops the quote stacking and stops it
37
+ // wrapping a heading it should have converted. See blockquote.ts.
38
+ blockquote: false,
39
+ // StarterKit v3 bundles Link + Underline. Disable them here so the custom
40
+ // linkExtension (openOnClick:false, custom class) and the standalone Underline
41
+ // below are the ONLY registrations. Leaving both causes "Duplicate extension
42
+ // names" — TipTap then picks one link mark nondeterministically, so getHTML()
43
+ // renders inconsistently vs the saved value, the setContent sync effect fires
44
+ // on every update, and link edits get reset (never appear to save).
45
+ link: false,
46
+ underline: false,
47
+ });
48
+
49
+ export const linkExtension = Link.extend({
50
+ // Force target/rel defaults to null. The stock Link (and StarterKit's) default
51
+ // `target` to '_blank', so a link with NO target attribute parses back as
52
+ // '_blank' — which made "New Tab off" silently revert to on when the popup
53
+ // reopened or content was reparsed. With a null default, absent === off.
54
+ addAttributes() {
55
+ return {
56
+ ...this.parent?.(),
57
+ target: { default: null },
58
+ rel: { default: null },
59
+ // File links: `download` is what makes the browser save the file instead of
60
+ // navigating to it, and it names the saved file. Declared here so TipTap keeps
61
+ // it through serialize → reparse; without it the attribute is dropped on load.
62
+ download: { default: null },
63
+ // Inline font-size on the <a> itself (plate / pasted HTML). Without this
64
+ // the size is dropped on parse and setLink then saves the stripped mark —
65
+ // list items fall through to the theme heading size (E-1228).
66
+ fontSize: {
67
+ default: null,
68
+ parseHTML: (element: HTMLElement) => element.style?.fontSize || null,
69
+ renderHTML: (attributes: Record<string, unknown>) =>
70
+ attributes.fontSize ? { style: `font-size: ${attributes.fontSize}` } : {},
71
+ },
72
+ };
73
+ },
74
+ addCommands() {
75
+ return {
76
+ ...this.parent?.(),
77
+ setLink:
78
+ (attrs: LinkAttributes) =>
79
+ ({ chain, editor }) => {
80
+ // Merge so a link edit (href / target / rel) cannot wipe fontSize.
81
+ // Typed as LinkAttributes (includes fontSize / download). TipTap's
82
+ // stock setLink type cannot be widened via module augmentation
83
+ // (TS2717 on Commands.link), so we apply the mark through setMark.
84
+ const current = editor.getAttributes('link') as LinkAttributes;
85
+ const next: LinkAttributes = { fontSize: current.fontSize, ...attrs };
86
+ if (
87
+ !this.options.isAllowedUri(next.href, {
88
+ defaultProtocol: this.options.defaultProtocol,
89
+ defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
90
+ protocols: this.options.protocols,
91
+ })
92
+ ) {
93
+ return false;
94
+ }
95
+ return chain().setMark(this.name, next).setMeta('preventAutolink', true).run();
96
+ },
97
+ };
98
+ },
99
+ }).configure({
100
+ enableClickSelection: true,
101
+ openOnClick: false,
102
+ // TipTap defaults autolink to 'http'. The link menu normalizes bare domains to
103
+ // https, so match it here — otherwise typing "vev.design" in the body and typing
104
+ // it in the link menu produce two different links.
105
+ defaultProtocol: 'https',
106
+ HTMLAttributes: { class: cl('link') },
107
+ });
108
+
109
+ export { Underline, Superscript, Subscript };
110
+
111
+ // ─── Table ──────────────────────────────────────────────────────────
112
+ // Without these four nodes `table/tr/th/td` are absent from the schema, and
113
+ // ProseMirror does not preserve elements it has no node for — it unwraps them
114
+ // and keeps the inline content. Every legacy table (the old Plate editor shipped
115
+ // a full table editor) parsed down to a flat run of paragraphs, and the value-sync
116
+ // effect wrote that flattened HTML straight back to the host. Registering the
117
+ // nodes is what makes tables survive a load at all.
118
+
119
+ /**
120
+ * Only render an attribute when it differs from the default. TipTap renders
121
+ * `colspan="1" rowspan="1"` on every single cell otherwise, which is noise in the
122
+ * saved markup and — because the value-sync effect diffs getHTML() against the
123
+ * stored value — would rewrite every existing table the first time it is opened.
124
+ */
125
+ const spanAttribute = (name: 'colspan' | 'rowspan') => ({
126
+ default: 1,
127
+ parseHTML: (element: HTMLElement) => {
128
+ const value = element.getAttribute(name);
129
+ const parsed = value ? parseInt(value, 10) : 1;
130
+ return Number.isNaN(parsed) ? 1 : parsed;
131
+ },
132
+ renderHTML: (attributes: Record<string, any>) =>
133
+ attributes[name] === 1 ? {} : { [name]: attributes[name] },
134
+ });
135
+
136
+ export const tableExtension = Table.extend({
137
+ // Stock renderHTML wraps the rows in a generated <colgroup> and puts an inline
138
+ // `min-width` on the table (see createColGroup). Both would be written into the
139
+ // saved content and shipped to the viewer, changing the layout of tables that
140
+ // were plain auto-layout before. Render the element the way it is stored instead.
141
+ renderHTML({ HTMLAttributes }) {
142
+ return ['table', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), ['tbody', 0]];
143
+ },
144
+ }).configure({
145
+ // Matches the old Plate editor, which had no column resizing. Off also keeps
146
+ // `colwidth` attributes out of the saved markup.
147
+ resizable: false,
148
+ });
149
+
150
+ // Spread over the stock attributes rather than replacing them, so the extension's
151
+ // own colwidth parsing (which reads <colgroup> widths off pasted tables) is kept.
152
+ const spanAttributes = {
153
+ colspan: spanAttribute('colspan'),
154
+ rowspan: spanAttribute('rowspan'),
155
+ };
156
+
157
+ export const tableCellExtension = TableCell.extend({
158
+ addAttributes() {
159
+ return { ...this.parent?.(), ...spanAttributes };
160
+ },
161
+ });
162
+
163
+ export const tableHeaderExtension = TableHeader.extend({
164
+ addAttributes() {
165
+ return { ...this.parent?.(), ...spanAttributes };
166
+ },
167
+ });
168
+
169
+ export { TableRow };
170
+
171
+ // ─── Selection highlight plugin ─────────────────────────────────────
172
+
173
+ export const selectionHighlightKey = new PluginKey('selectionHighlight');
174
+
175
+ export const selectionHighlightPlugin = new Plugin({
176
+ key: selectionHighlightKey,
177
+ state: {
178
+ init: () => DecorationSet.empty,
179
+ apply(tr, decorations, _oldState, newState) {
180
+ const meta = tr.getMeta(selectionHighlightKey);
181
+ if (meta === 'clear') return DecorationSet.empty;
182
+ if (meta === 'show') {
183
+ const { from, to } = newState.selection;
184
+ if (from === to) return DecorationSet.empty;
185
+ return DecorationSet.create(newState.doc, [
186
+ Decoration.inline(from, to, { class: 'selection-highlight' }),
187
+ ]);
188
+ }
189
+ return decorations.map(tr.mapping, tr.doc);
190
+ },
191
+ },
192
+ props: {
193
+ decorations(state) {
194
+ return this.getState(state);
195
+ },
196
+ },
197
+ });
198
+
199
+ // ─── Build extensions array ─────────────────────────────────────────
200
+
201
+ export function buildExtensions(commandPlaceholderRef: { current: string }) {
202
+ return [
203
+ starterKit,
204
+ Placeholder.configure({
205
+ placeholder: ({ node }) =>
206
+ node.type.name === 'heading'
207
+ ? `Heading ${node.attrs.level}`
208
+ : commandPlaceholderRef.current,
209
+ showOnlyWhenEditable: true,
210
+ showOnlyCurrent: true,
211
+ includeChildren: false,
212
+ emptyEditorClass: 'is-editor-empty',
213
+ emptyNodeClass: 'is-empty-node',
214
+ }),
215
+ Underline,
216
+ Superscript,
217
+ Subscript,
218
+ Dropcap,
219
+ FontSize,
220
+ blockquoteExtension,
221
+ listItemExtension,
222
+ StayInList,
223
+ linkExtension,
224
+ tableExtension,
225
+ TableRow,
226
+ tableHeaderExtension,
227
+ tableCellExtension,
228
+ LoremIpsum,
229
+ ];
230
+ }
@@ -0,0 +1,180 @@
1
+ # Rich Text Field
2
+
3
+ A Notion-like rich text editor built on Tiptap. Supports inline formatting via a bubble menu, slash commands for block types, and clean minimal styling.
4
+
5
+ ## Basic usage
6
+
7
+ ```js
8
+ const [value, setValue] = React.useState('');
9
+
10
+ <SilkeRichTextField
11
+ label="Description"
12
+ value={value}
13
+ onChange={setValue}
14
+ placeholder="Start writing..."
15
+ />
16
+ ```
17
+
18
+ ## With help text and error
19
+
20
+ ```js
21
+ const [value, setValue] = React.useState('');
22
+
23
+ <SilkeBox column gap="l">
24
+ <SilkeRichTextField
25
+ label="Bio"
26
+ help="Tell us about yourself"
27
+ value={value}
28
+ onChange={setValue}
29
+ placeholder="Write something..."
30
+ />
31
+ <SilkeRichTextField
32
+ label="Required field"
33
+ error="This field is required"
34
+ value={value}
35
+ onChange={setValue}
36
+ />
37
+ </SilkeBox>
38
+ ```
39
+
40
+ ## Custom height
41
+
42
+ ```js
43
+ const [value, setValue] = React.useState('');
44
+
45
+ <SilkeBox column gap="l">
46
+ <SilkeRichTextField
47
+ label="Short note"
48
+ value={value}
49
+ onChange={setValue}
50
+ minHeight={80}
51
+ placeholder="A short note..."
52
+ />
53
+ <SilkeRichTextField
54
+ label="Long form content"
55
+ value={value}
56
+ onChange={setValue}
57
+ minHeight={300}
58
+ maxHeight={500}
59
+ placeholder="Write a detailed description..."
60
+ />
61
+ </SilkeBox>
62
+ ```
63
+
64
+ ## Disabled and read-only
65
+
66
+ ```js
67
+ <SilkeBox column gap="l">
68
+ <SilkeRichTextField
69
+ label="Disabled"
70
+ disabled
71
+ value="<p>This field is disabled</p>"
72
+ />
73
+ <SilkeRichTextField
74
+ label="Read only"
75
+ readOnly
76
+ value="<p>This content is <strong>read-only</strong>. You can see it but not edit it.</p>"
77
+ />
78
+ </SilkeBox>
79
+ ```
80
+
81
+ ## Kind variants
82
+
83
+ The `kind` prop controls the field style. Use `'plain'` for a bare editor with no outline or label.
84
+
85
+ ```js
86
+ const [v1, setV1] = React.useState('');
87
+ const [v2, setV2] = React.useState('');
88
+ const [v3, setV3] = React.useState('');
89
+ const [v4, setV4] = React.useState('');
90
+
91
+ <SilkeBox column gap="l">
92
+ <SilkeRichTextField label="Default" kind="default" value={v1} onChange={setV1} placeholder="Default kind..." minHeight={80} />
93
+ <SilkeRichTextField label="Ghost" kind="ghost" value={v2} onChange={setV2} placeholder="Ghost kind..." minHeight={80} />
94
+ <SilkeRichTextField label="Zombie" kind="zombie" value={v3} onChange={setV3} placeholder="Zombie kind..." minHeight={80} />
95
+ <SilkeRichTextField kind="plain" value={v4} onChange={setV4} placeholder="Plain — no outline, no label" minHeight={80} />
96
+ </SilkeBox>
97
+ ```
98
+
99
+ ## Link picker with items
100
+
101
+ Pass `linkItems` to show an autocomplete when inserting links. Select text and click the link button in the bubble menu to try it. Click on an existing link to edit it.
102
+
103
+ ```js
104
+ const [value, setValue] = React.useState('<p>Check out our <a href="/blog">Blog</a> for the latest updates, or visit <a href="https://github.com">GitHub</a> for the source code.</p><p>Select any text and click the link button to add more links.</p>');
105
+
106
+ const linkItems = [
107
+ { label: 'Home', value: '/', icon: 'fa-light fa-file', subLabel: 'Main page', groupLabel: 'Pages' },
108
+ { label: 'About', value: '/about', icon: 'fa-light fa-file', subLabel: 'About us', groupLabel: 'Pages' },
109
+ { label: 'Blog', value: '/blog', icon: 'fa-light fa-file', subLabel: 'Latest posts', groupLabel: 'Pages' },
110
+ { label: 'Contact', value: '/contact', icon: 'fa-light fa-file', subLabel: 'Get in touch', groupLabel: 'Pages' },
111
+ { label: 'Google', value: 'https://google.com', icon: 'fa-light fa-external-link', subLabel: 'Search engine', groupLabel: 'Social' },
112
+ { label: 'GitHub', value: 'https://github.com', icon: 'fa-light fa-external-link', subLabel: 'Code hosting', groupLabel: 'Social' },
113
+ { label: 'Twitter', value: 'https://twitter.com', icon: 'fa-light fa-external-link', subLabel: 'Social media', groupLabel: 'Social' },
114
+ ];
115
+
116
+ <SilkeRichTextField
117
+ label="Content with links"
118
+ value={value}
119
+ onChange={setValue}
120
+ linkItems={linkItems}
121
+ onAddLink={(url) => console.log('New link added:', url)}
122
+ minHeight={120}
123
+ />
124
+ ```
125
+
126
+ ## Pre-filled content
127
+
128
+ ```js
129
+ const [value, setValue] = React.useState(
130
+ '<h2>Meeting notes</h2><p>Key takeaways from today:</p><ul><li>Ship the new editor component</li><li>Review design tokens</li><li>Update documentation</li></ul><blockquote><p>The best code is no code at all.</p></blockquote>'
131
+ );
132
+
133
+ <SilkeRichTextField
134
+ label="Notes"
135
+ value={value}
136
+ onChange={setValue}
137
+ minHeight={200}
138
+ />
139
+ ```
140
+
141
+ ## Props
142
+
143
+ | Prop | Type | Default | Description |
144
+ |------|------|---------|-------------|
145
+ | `value` | `string` | — | HTML content |
146
+ | `onChange` | `(html: string) => void` | — | Called on content change |
147
+ | `placeholder` | `string` | — | Placeholder when unfocused and empty |
148
+ | `commandPlaceholder` | `string` | `"Press '/' for commands"` | Placeholder on focused empty blocks |
149
+ | `label` | `string` | — | Label above the editor |
150
+ | `help` | `string` | — | Help text below the editor |
151
+ | `error` | `string` | — | Error message (replaces help) |
152
+ | `kind` | `'default' \| 'ghost' \| 'zombie' \| 'plain'` | `'default'` | Field style variant |
153
+ | `size` | `'s' \| 'base'` | `'base'` | Field size |
154
+ | `minHeight` | `number \| string` | `120` | Minimum editor height |
155
+ | `maxHeight` | `number \| string` | — | Maximum height (scrolls) |
156
+ | `disabled` | `boolean` | `false` | Disable the editor |
157
+ | `readOnly` | `boolean` | `false` | Read-only mode |
158
+ | `autoFocus` | `boolean` | `false` | Focus on mount |
159
+ | `flex` | `boolean` | — | Makes the field flex |
160
+ | `linkItems` | `Entry<string>[]` | — | Autocomplete items for link picker |
161
+ | `onAddLink` | `(value: string) => void` | — | Called when creating a new link |
162
+ | `onSpaceCommand` | `() => void` | — | Called on space in empty block |
163
+
164
+ ## Features
165
+
166
+ - **Bubble menu**: Select text to format — bold, italic, underline, strikethrough,
167
+ superscript, subscript, dropcap, code, link
168
+ - **Slash commands**: Type `/` to insert headings, lists, quotes, tables, dividers
169
+ - **Dropcap**: Serializes as `<span class="dropcap">`, the same markup the Vev text element
170
+ has always used, so it is styled by the element's own `span.dropcap` rule. The default
171
+ typography ships a structural fallback (float, size, line height) for other hosts
172
+ - **Tables**: Insert one with `/table`. Put the caret in any cell to get the row/column
173
+ toolbar — toggle header row, add or remove rows and columns, delete the table. It sits in
174
+ the gutter to the left of the table, level with the row being edited, so it never covers
175
+ a cell. `Tab` moves to the next cell.
176
+ Tables are rendered without a class or inline
177
+ styles, so the saved HTML stays as authored and hosts style tables themselves; the
178
+ field's own borders come from its default typography and are not written into content
179
+ - **Keyboard shortcuts**: Standard shortcuts like `Cmd+B`, `Cmd+I`, `Cmd+U` work
180
+ - **Lorem ipsum**: Type `lorem` (any casing) and press Tab to expand it into a placeholder paragraph. Tab keeps its other jobs — indenting list items, moving focus — when the word before the caret is something else