@vev/silke 1.1.10 → 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 (188) hide show
  1. package/.turbo/turbo-build.log +163 -78
  2. package/CHANGELOG.md +31 -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 +1597 -1014
  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 +16 -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/object-field.tsx +2 -0
  117. package/src/components/silke-form-schema/fields/popover-field.tsx +2 -0
  118. package/src/components/silke-form-schema/fields/string-field.tsx +27 -1
  119. package/src/components/silke-form-schema/index.ts +1 -0
  120. package/src/components/silke-form-schema/silke-form-schema.mdx +30 -1
  121. package/src/components/silke-form-schema/silke-form-schema.tsx +12 -6
  122. package/src/components/silke-form-schema/silke-schema-decorator.tsx +32 -0
  123. package/src/components/silke-form-schema/silke-schema-field.tsx +19 -2
  124. package/src/components/silke-form-schema/silke-schema-fields.tsx +30 -4
  125. package/src/components/silke-form-schema/silke-schema-path.spec.tsx +160 -0
  126. package/src/components/silke-gradient-picker/silke-gradient-picker.tsx +3 -1
  127. package/src/components/silke-gradient-picker/silke-gradient-utils.ts +23 -3
  128. package/src/components/silke-icon/silke-shape.tsx +1 -1
  129. package/src/components/silke-icon-picker/color-swatch-section.tsx +61 -0
  130. package/src/components/silke-icon-picker/emoji-tab.tsx +8 -6
  131. package/src/components/silke-icon-picker/icons-tab.tsx +8 -7
  132. package/src/components/silke-icon-picker/silke-icon-picker.tsx +52 -25
  133. package/src/components/silke-icon-picker/styles.scss +66 -1
  134. package/src/components/silke-icon-picker/utils.ts +2 -0
  135. package/src/components/silke-list/silke-list-item.scss +10 -0
  136. package/src/components/silke-list/silke-list-item.tsx +16 -3
  137. package/src/components/silke-list/silke-list.mdx +18 -0
  138. package/src/components/silke-list/types.ts +1 -0
  139. package/src/components/silke-navigation-link/silke-navigation-link.scss +162 -42
  140. package/src/components/silke-navigation-link/silke-navigation-link.tsx +99 -21
  141. package/src/components/silke-popover/popover-context.spec.tsx +44 -0
  142. package/src/components/silke-popover-native/silke-popover-native.scss +5 -3
  143. package/src/components/silke-rich-text-field/blockquote.spec.ts +151 -0
  144. package/src/components/silke-rich-text-field/blockquote.ts +90 -0
  145. package/src/components/silke-rich-text-field/dropcap.spec.ts +67 -0
  146. package/src/components/silke-rich-text-field/dropcap.ts +59 -0
  147. package/src/components/silke-rich-text-field/floating-layer.tsx +15 -0
  148. package/src/components/silke-rich-text-field/font-size.ts +62 -0
  149. package/src/components/silke-rich-text-field/formatting-toolbar.tsx +145 -0
  150. package/src/components/silke-rich-text-field/index.ts +1 -0
  151. package/src/components/silke-rich-text-field/jsdom-rects.ts +15 -0
  152. package/src/components/silke-rich-text-field/link-menu.spec.tsx +502 -0
  153. package/src/components/silke-rich-text-field/link-menu.tsx +553 -0
  154. package/src/components/silke-rich-text-field/link-suggestions.spec.ts +203 -0
  155. package/src/components/silke-rich-text-field/link-suggestions.ts +188 -0
  156. package/src/components/silke-rich-text-field/link-tooltip.tsx +60 -0
  157. package/src/components/silke-rich-text-field/list-item.ts +64 -0
  158. package/src/components/silke-rich-text-field/list-link-fontsize.spec.ts +135 -0
  159. package/src/components/silke-rich-text-field/lorem-ipsum.spec.ts +131 -0
  160. package/src/components/silke-rich-text-field/lorem-ipsum.ts +51 -0
  161. package/src/components/silke-rich-text-field/paste.spec.ts +93 -0
  162. package/src/components/silke-rich-text-field/paste.ts +39 -0
  163. package/src/components/silke-rich-text-field/plugins.spec.ts +143 -0
  164. package/src/components/silke-rich-text-field/plugins.ts +230 -0
  165. package/src/components/silke-rich-text-field/silke-rich-text-field.mdx +180 -0
  166. package/src/components/silke-rich-text-field/silke-rich-text-field.scss +343 -0
  167. package/src/components/silke-rich-text-field/silke-rich-text-field.tsx +505 -0
  168. package/src/components/silke-rich-text-field/slash-menu-items.ts +112 -0
  169. package/src/components/silke-rich-text-field/slash-menu.tsx +50 -0
  170. package/src/components/silke-rich-text-field/table-content-sync.spec.tsx +61 -0
  171. package/src/components/silke-rich-text-field/table-toolbar.spec.tsx +168 -0
  172. package/src/components/silke-rich-text-field/table-toolbar.tsx +121 -0
  173. package/src/components/silke-rich-text-field/table.spec.ts +87 -0
  174. package/src/components/silke-rich-text-field/use-link-hover.ts +63 -0
  175. package/src/components/silke-rich-text-field/use-slash-menu.ts +130 -0
  176. package/src/components/silke-rich-text-field/utils.ts +55 -0
  177. package/src/components/silke-sortable-list/index.ts +1 -1
  178. package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +11 -1
  179. package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +9 -0
  180. package/src/components/silke-sortable-list/silke-sortable-list.mdx +13 -0
  181. package/src/components/silke-tag/silke-tag.scss +12 -3
  182. package/src/components/silke-theme-card/silke-theme-card.module.scss +141 -45
  183. package/src/components/silke-theme-card/silke-theme-card.tsx +76 -47
  184. package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +56 -0
  185. package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +53 -63
  186. package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +99 -14
  187. package/src/icons.tsx +51 -5
  188. package/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,203 @@
1
+ import { buildMailto, getLinkSuggestion, normalizeHref, parseMailto } from './link-suggestions';
2
+
3
+ describe('normalizeHref', () => {
4
+ it.each([
5
+ // Bare domains were the broken case: saved as-is they resolve relative to the
6
+ // current page, so the link 404s.
7
+ ['vev.design', 'https://vev.design'],
8
+ ['www.vev.design', 'https://www.vev.design'],
9
+ ['vev.design/pricing', 'https://vev.design/pricing'],
10
+ ['vev.design/pricing?ref=a#b', 'https://vev.design/pricing?ref=a#b'],
11
+ // Mail
12
+ ['hello@vev.design', 'mailto:hello@vev.design'],
13
+ [' hello@vev.design ', 'mailto:hello@vev.design'],
14
+ // Phone — spaces and punctuation stripped, leading + kept
15
+ ['+47 987 65 432', 'tel:+4798765432'],
16
+ ['+4798765432', 'tel:+4798765432'],
17
+ ['(555) 123-4567', 'tel:5551234567'],
18
+ ])('normalizes %j to %j', (input, expected) => {
19
+ expect(normalizeHref(input)).toBe(expected);
20
+ });
21
+
22
+ it.each([
23
+ // Already explicit — must be left exactly alone
24
+ ['https://vev.design'],
25
+ ['http://vev.design'],
26
+ ['mailto:hello@vev.design'],
27
+ ['tel:+4798765432'],
28
+ ['ftp://files.vev.design'],
29
+ // Internal destinations
30
+ ['/about'],
31
+ ['#someElementKey'],
32
+ ['./'],
33
+ ['../up'],
34
+ // Page keys and search text must survive untouched
35
+ ['pnXR4lkvnq1'],
36
+ ['Contact page'],
37
+ ['vev'],
38
+ ])('leaves %j untouched', (input) => {
39
+ expect(normalizeHref(input)).toBe(input);
40
+ });
41
+
42
+ it('does not read a dotted-quad IP as a phone number', () => {
43
+ expect(normalizeHref('1.2.3.4')).toBe('1.2.3.4');
44
+ });
45
+
46
+ it('does not turn a short number-like string into a phone number', () => {
47
+ expect(normalizeHref('123')).toBe('123');
48
+ });
49
+
50
+ it('returns empty for empty input', () => {
51
+ expect(normalizeHref('')).toBe('');
52
+ expect(normalizeHref(' ')).toBe('');
53
+ });
54
+ });
55
+
56
+ describe('getLinkSuggestion', () => {
57
+ it('offers a mail link for an email address', () => {
58
+ expect(getLinkSuggestion('hello@vev.design')).toMatchObject({
59
+ kind: 'email',
60
+ href: 'mailto:hello@vev.design',
61
+ label: 'Email hello@vev.design',
62
+ });
63
+ });
64
+
65
+ it('offers a phone link for a number', () => {
66
+ expect(getLinkSuggestion('+47 987 65 432')).toMatchObject({
67
+ kind: 'phone',
68
+ href: 'tel:+4798765432',
69
+ label: 'Call +4798765432',
70
+ });
71
+ });
72
+
73
+ it('offers an external link for a bare domain, showing the scheme it added', () => {
74
+ expect(getLinkSuggestion('vev.design')).toMatchObject({
75
+ kind: 'external',
76
+ href: 'https://vev.design',
77
+ label: 'Go to https://vev.design',
78
+ });
79
+ });
80
+
81
+ it('still offers a row when the user typed the scheme themselves', () => {
82
+ expect(getLinkSuggestion('mailto:hello@vev.design')?.kind).toBe('email');
83
+ expect(getLinkSuggestion('tel:+4798765432')?.kind).toBe('phone');
84
+ expect(getLinkSuggestion('https://vev.design')?.kind).toBe('external');
85
+ });
86
+
87
+ it('offers a row for internal paths and anchors', () => {
88
+ expect(getLinkSuggestion('/about')).toMatchObject({ kind: 'internal', href: '/about' });
89
+ expect(getLinkSuggestion('#key')).toMatchObject({ kind: 'internal', href: '#key' });
90
+ });
91
+
92
+ it('offers nothing for plain search text, so the page list is the answer', () => {
93
+ expect(getLinkSuggestion('Contact')).toBeNull();
94
+ expect(getLinkSuggestion('vev')).toBeNull();
95
+ expect(getLinkSuggestion('')).toBeNull();
96
+ });
97
+
98
+ it('folds a subject into the mail link while keeping the label readable', () => {
99
+ expect(getLinkSuggestion('hello@vev.design', { subject: 'Hi there' })).toMatchObject({
100
+ href: 'mailto:hello@vev.design?subject=Hi%20there',
101
+ label: 'Email hello@vev.design',
102
+ });
103
+ });
104
+
105
+ it('keeps the subject already on the href when none is supplied', () => {
106
+ expect(getLinkSuggestion('mailto:hello@vev.design?subject=Kept')?.href).toBe(
107
+ 'mailto:hello@vev.design?subject=Kept',
108
+ );
109
+ });
110
+ });
111
+
112
+ describe('mailto round-trip', () => {
113
+ it('splits an address and subject apart', () => {
114
+ expect(parseMailto('mailto:hello@vev.design?subject=Hi%20there')).toEqual({
115
+ email: 'hello@vev.design',
116
+ subject: 'Hi there',
117
+ });
118
+ });
119
+
120
+ it('reads the legacy ?Subject= casing written by the old text editor', () => {
121
+ expect(parseMailto('mailto:hello@vev.design?Subject=Old%20link')).toEqual({
122
+ email: 'hello@vev.design',
123
+ subject: 'Old link',
124
+ });
125
+ });
126
+
127
+ it('handles a mail link with no subject', () => {
128
+ expect(parseMailto('mailto:hello@vev.design')).toEqual({
129
+ email: 'hello@vev.design',
130
+ subject: '',
131
+ });
132
+ });
133
+
134
+ it('is not a mail link', () => {
135
+ expect(parseMailto('https://vev.design')).toBeNull();
136
+ expect(parseMailto('tel:+4798765432')).toBeNull();
137
+ });
138
+
139
+ it('builds a mail link, encoding the subject', () => {
140
+ expect(buildMailto('hello@vev.design', 'Hi & bye')).toBe(
141
+ 'mailto:hello@vev.design?subject=Hi%20%26%20bye',
142
+ );
143
+ });
144
+
145
+ it('leaves the query off when there is no subject', () => {
146
+ expect(buildMailto('hello@vev.design')).toBe('mailto:hello@vev.design');
147
+ expect(buildMailto('hello@vev.design', ' ')).toBe('mailto:hello@vev.design');
148
+ });
149
+
150
+ it('survives a full round-trip', () => {
151
+ const href = buildMailto('hello@vev.design', 'Quote request');
152
+ expect(parseMailto(href)).toEqual({ email: 'hello@vev.design', subject: 'Quote request' });
153
+ });
154
+
155
+ it('returns empty for a missing address', () => {
156
+ expect(buildMailto('', 'Subject')).toBe('');
157
+ });
158
+ });
159
+
160
+ describe('getLinkSuggestion with a kind the user picked', () => {
161
+ it('takes a short number at its word, which detection alone would skip', () => {
162
+ expect(normalizeHref('1234')).toBe('1234');
163
+ expect(getLinkSuggestion('1234', { kind: 'phone' })).toMatchObject({
164
+ kind: 'phone',
165
+ href: 'tel:1234',
166
+ label: 'Call 1234',
167
+ });
168
+ });
169
+
170
+ it('keeps a leading + on a picked phone number', () => {
171
+ expect(getLinkSuggestion('+47 12', { kind: 'phone' })?.href).toBe('tel:+4712');
172
+ });
173
+
174
+ it('takes an incomplete address at its word while it is being typed', () => {
175
+ expect(getLinkSuggestion('hello@vev', { kind: 'email' })).toMatchObject({
176
+ kind: 'email',
177
+ href: 'mailto:hello@vev',
178
+ label: 'Email hello@vev',
179
+ });
180
+ });
181
+
182
+ it('applies the subject to a picked email', () => {
183
+ expect(getLinkSuggestion('a@b.com', { kind: 'email', subject: 'Hi' })?.href).toBe(
184
+ 'mailto:a@b.com?subject=Hi',
185
+ );
186
+ });
187
+
188
+ it('tolerates the scheme being typed in a picked kind', () => {
189
+ expect(getLinkSuggestion('mailto:a@b.com', { kind: 'email' })?.href).toBe('mailto:a@b.com');
190
+ });
191
+
192
+ it('offers nothing until there is something to link to', () => {
193
+ expect(getLinkSuggestion('mailto:', { kind: 'email' })).toBeNull();
194
+ expect(getLinkSuggestion('abc', { kind: 'phone' })).toBeNull();
195
+ });
196
+
197
+ it.each([['mailto:'], ['tel:'], ['https://'], ['#']])(
198
+ 'offers no row for %j, which has no destination yet',
199
+ (input) => {
200
+ expect(getLinkSuggestion(input)).toBeNull();
201
+ },
202
+ );
203
+ });
@@ -0,0 +1,188 @@
1
+ import type { SilkeIcons } from '../silke-icon';
2
+
3
+ /**
4
+ * Turning what someone typed into a link that actually works.
5
+ *
6
+ * The link menu is one free-text field, so "hello@vev.design", "+47 987 65 432" and
7
+ * "vev.design" all arrive as plain strings. Saved verbatim they become *relative*
8
+ * URLs — `<a href="vev.design">` resolves against the current page and 404s — which
9
+ * is why external, mail and phone links get reported as broken.
10
+ *
11
+ * TipTap's autolink already does this normalizing when you type the same text into
12
+ * the body (`vev.design` there becomes a real link); the menu skipped it. These
13
+ * helpers close that gap, and feed the action row that shows the user which link
14
+ * they are about to create instead of leaving them to guess whether Enter works.
15
+ */
16
+
17
+ /** Schemes that mean "the user already said what they meant". */
18
+ const KNOWN_SCHEMES = [
19
+ 'http',
20
+ 'https',
21
+ 'mailto',
22
+ 'tel',
23
+ 'sms',
24
+ 'ftp',
25
+ 'ftps',
26
+ 'callto',
27
+ 'webcal',
28
+ 'file',
29
+ ];
30
+
31
+ const SCHEME_RE = new RegExp(`^(${KNOWN_SCHEMES.join('|')}):`, 'i');
32
+ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[a-z]{2,}$/i;
33
+ // Deliberately excludes '.' so dotted-quad IPs and "123.456" can't read as a number.
34
+ const PHONE_RE = /^\+?[\d\s()-]{6,}$/;
35
+ const DOMAIN_RE = /^[^\s/?#@]+\.[a-z]{2,}(?:[/?#]\S*)?$/i;
36
+
37
+ export type LinkSuggestionKind = 'email' | 'phone' | 'external' | 'internal';
38
+
39
+ export interface LinkSuggestion {
40
+ kind: LinkSuggestionKind;
41
+ /** The href that will be saved. */
42
+ href: string;
43
+ /** Row label, e.g. "Email hello@vev.design". */
44
+ label: string;
45
+ icon: SilkeIcons;
46
+ }
47
+
48
+ /** Input that already points somewhere real and must be left alone. */
49
+ function isExplicit(value: string): boolean {
50
+ return SCHEME_RE.test(value) || /^[/#]/.test(value) || /^\.\.?\//.test(value);
51
+ }
52
+
53
+ export interface MailtoParts {
54
+ email: string;
55
+ subject: string;
56
+ }
57
+
58
+ /**
59
+ * Split a mailto href back into address and subject, so editing an existing mail
60
+ * link shows "hello@vev.design" in the field rather than the whole encoded href.
61
+ *
62
+ * The query key is matched case-insensitively: the previous text editor wrote
63
+ * `?Subject=`, so links made there have to round-trip too.
64
+ */
65
+ export function parseMailto(href: string): MailtoParts | null {
66
+ if (!/^mailto:/i.test(href)) return null;
67
+
68
+ const [email, query = ''] = href.slice('mailto:'.length).split('?');
69
+ let subject = '';
70
+ for (const [key, value] of new URLSearchParams(query)) {
71
+ if (key.toLowerCase() === 'subject') {
72
+ subject = value;
73
+ break;
74
+ }
75
+ }
76
+
77
+ return { email, subject };
78
+ }
79
+
80
+ /** Build a mailto href, dropping the query entirely when there is no subject. */
81
+ export function buildMailto(email: string, subject?: string): string {
82
+ const address = email.trim().replace(/^mailto:/i, '');
83
+ if (!address) return '';
84
+
85
+ const trimmed = (subject || '').trim();
86
+ return `mailto:${address}${trimmed ? `?subject=${encodeURIComponent(trimmed)}` : ''}`;
87
+ }
88
+
89
+ /**
90
+ * Best-effort href for free text. Returns the input untouched when it is already
91
+ * explicit, or when the intent isn't clear — it never guesses destructively, and
92
+ * anything it does change is shown back to the user via `getLinkSuggestion`.
93
+ */
94
+ export function normalizeHref(input: string): string {
95
+ const value = input.trim();
96
+ if (!value || isExplicit(value)) return value;
97
+ if (EMAIL_RE.test(value)) return `mailto:${value}`;
98
+ if (PHONE_RE.test(value)) return telHref(value) || value;
99
+ if (DOMAIN_RE.test(value)) return `https://${value}`;
100
+ return value;
101
+ }
102
+
103
+ /** tel: hrefs are unreliable with spaces in them, so keep only '+' and digits. */
104
+ export function telHref(value: string): string {
105
+ const digits = value.replace(/\D/g, '');
106
+ if (!digits) return '';
107
+ return `tel:${value.trim().startsWith('+') ? '+' : ''}${digits}`;
108
+ }
109
+
110
+ /** The bare address out of anything mailto-shaped, ignoring any query. */
111
+ export function mailAddress(value: string): string {
112
+ return value.trim().replace(/^mailto:/i, '').split('?')[0];
113
+ }
114
+
115
+ /**
116
+ * The action row shown above the page/element list. It exists so that typing an
117
+ * address gives you something to see and click — previously the list simply went
118
+ * empty and there was no sign that Enter would do anything.
119
+ *
120
+ * Returns null for plain search text, where the page/element list is the answer.
121
+ *
122
+ * `subject` is folded into mail links here so the row commits the same href the
123
+ * Subject field is showing.
124
+ */
125
+ export function getLinkSuggestion(
126
+ input: string,
127
+ options?: { subject?: string; kind?: 'email' | 'phone' },
128
+ ): LinkSuggestion | null {
129
+ const value = input.trim();
130
+ if (!value) return null;
131
+
132
+ // Picked "Email address" or "Phone number" from the list: take them at their
133
+ // word rather than re-guessing, so a number too short to look like one, or an
134
+ // address still being typed, is still treated as what they asked for.
135
+ if (options?.kind === 'email') {
136
+ const address = mailAddress(value);
137
+ if (!address) return null;
138
+ return {
139
+ kind: 'email',
140
+ href: buildMailto(address, options.subject),
141
+ label: `Email ${address}`,
142
+ icon: 'email',
143
+ };
144
+ }
145
+
146
+ if (options?.kind === 'phone') {
147
+ const href = telHref(value);
148
+ if (!href) return null;
149
+ return { kind: 'phone', href, label: `Call ${href.slice('tel:'.length)}`, icon: 'mobile' };
150
+ }
151
+
152
+ const href = normalizeHref(value);
153
+
154
+ // A scheme or hash with nothing after it is not a destination yet, so offering a
155
+ // row would just create <a href="mailto:">.
156
+ if (/^([a-z][a-z0-9+.-]*:\/*|#)$/i.test(href)) return null;
157
+
158
+ const mail = parseMailto(href);
159
+ if (mail?.email) {
160
+ return {
161
+ kind: 'email',
162
+ href: buildMailto(mail.email, options?.subject ?? mail.subject),
163
+ label: `Email ${mail.email}`,
164
+ icon: 'email',
165
+ };
166
+ }
167
+
168
+ if (href.startsWith('tel:')) {
169
+ return {
170
+ kind: 'phone',
171
+ href,
172
+ label: `Call ${href.slice('tel:'.length)}`,
173
+ icon: 'mobile',
174
+ };
175
+ }
176
+
177
+ if (/^https?:\/\//i.test(href)) {
178
+ return { kind: 'external', href, label: `Go to ${href}`, icon: 'link.external' };
179
+ }
180
+
181
+ // Paths, anchors and the remaining schemes: still worth a row, so every address
182
+ // you can type has a visible way to commit it.
183
+ if (isExplicit(href)) {
184
+ return { kind: 'internal', href, label: `Link to ${href}`, icon: 'link' };
185
+ }
186
+
187
+ return null;
188
+ }
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames/bind';
3
+ import { SilkeBox } from '../silke-box';
4
+ import { SilkeButton } from '../silke-button';
5
+ import { SilkeText } from '../silke-text/silke-text';
6
+ import styles from './silke-rich-text-field.scss';
7
+
8
+ const cl = classnames.bind(styles);
9
+
10
+ interface LinkTooltipProps {
11
+ href: string;
12
+ label?: string;
13
+ position: { left: number; top: number };
14
+ onOpen: () => void;
15
+ onEdit: () => void;
16
+ onUnlink: () => void;
17
+ onMouseEnter: () => void;
18
+ onMouseLeave: () => void;
19
+ }
20
+
21
+ export function LinkTooltip({
22
+ href,
23
+ label,
24
+ position,
25
+ onOpen,
26
+ onEdit,
27
+ onUnlink,
28
+ onMouseEnter,
29
+ onMouseLeave,
30
+ }: LinkTooltipProps) {
31
+ return (
32
+ <SilkeBox
33
+ data-rich-text-menu
34
+ className={cl('linkTooltip')}
35
+ style={{ left: position.left, top: position.top }}
36
+ onMouseEnter={onMouseEnter}
37
+ onMouseLeave={onMouseLeave}
38
+ gap="xs"
39
+ vAlign="center"
40
+ pad="s"
41
+ border
42
+ bg="neutral-10"
43
+ rounded="small"
44
+ shadow="level3"
45
+ >
46
+ <SilkeText size="small" color="neutral-80" overflow flex>
47
+ {label || href}
48
+ </SilkeText>
49
+ <SilkeButton
50
+ icon="link.external"
51
+ kind="ghost"
52
+ size="s"
53
+ title="Open in new tab"
54
+ onClick={onOpen}
55
+ />
56
+ <SilkeButton icon="edit" kind="ghost" size="s" title="Edit link" onClick={onEdit} />
57
+ <SilkeButton icon="unlink" kind="ghost" size="s" title="Remove link" onClick={onUnlink} />
58
+ </SilkeBox>
59
+ );
60
+ }
@@ -0,0 +1,64 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import { ListItem } from '@tiptap/extension-list';
3
+ import { DOMParser } from '@tiptap/pm/model';
4
+
5
+ const HEADING_TAG = /^H[1-6]$/;
6
+
7
+ /**
8
+ * Keep StarterKit's `paragraph block*` (needed so Tab can nest a list under an
9
+ * item). Convert a heading that is a *direct* child of `<li>` to a paragraph
10
+ * while parsing — otherwise the heading is lifted next to the list and the
11
+ * text sticks at the theme h1 size (~48px) instead of the element's set size
12
+ * (E-1228). Nested lists are left alone.
13
+ */
14
+ export const listItemExtension = ListItem.extend({
15
+ parseHTML() {
16
+ return [
17
+ {
18
+ getContent(dom, schema) {
19
+ const element = dom as HTMLElement;
20
+ const wrapper = element.ownerDocument.createElement('div');
21
+ Array.from(element.childNodes).forEach((child) => {
22
+ if (child instanceof HTMLElement && HEADING_TAG.test(child.tagName)) {
23
+ const paragraph = element.ownerDocument.createElement('p');
24
+ while (child.firstChild) paragraph.appendChild(child.firstChild);
25
+ wrapper.appendChild(paragraph);
26
+ return;
27
+ }
28
+ wrapper.appendChild(child.cloneNode(true));
29
+ });
30
+ return DOMParser.fromSchema(schema).parseSlice(wrapper).content;
31
+ },
32
+ tag: 'li',
33
+ },
34
+ ];
35
+ },
36
+ });
37
+
38
+ /**
39
+ * Registered after StarterKit so these replace its setHeading / toggleHeading.
40
+ * `setNode('heading')` inside a list item lifts the item out of the list
41
+ * (TipTap #7197); no-op instead so the item keeps inheriting the element size.
42
+ */
43
+ export const StayInList = Extension.create({
44
+ addCommands() {
45
+ return {
46
+ setHeading:
47
+ (attributes) =>
48
+ ({ commands, editor }) => {
49
+ if (editor.isActive('listItem')) return true;
50
+ return commands.setNode('heading', attributes);
51
+ },
52
+ toggleHeading:
53
+ (attributes) =>
54
+ ({ commands, editor }) => {
55
+ if (editor.isActive('listItem')) return true;
56
+ if (editor.isActive('heading', attributes)) {
57
+ return commands.setNode('paragraph');
58
+ }
59
+ return commands.setNode('heading', attributes);
60
+ },
61
+ };
62
+ },
63
+ name: 'stayInList',
64
+ });
@@ -0,0 +1,135 @@
1
+ import { Editor } from '@tiptap/react';
2
+ import { buildExtensions } from './plugins';
3
+
4
+ /**
5
+ * Regression tests for E-1228: bullet-list text stuck at a heading-sized
6
+ * ~48px after editing a link, while the properties panel still shows the
7
+ * element's set size (18px in the MillerKnoll report).
8
+ *
9
+ * Two things the schema used to drop on parse, which the first link edit
10
+ * then wrote back through onUpdate:
11
+ * 1. Inline `font-size` on a span or on the <a> itself — ProseMirror
12
+ * unwraps elements it has no mark/attribute for, same as dropcap.
13
+ * 2. A heading inside a list item (or a list item lifted to a heading).
14
+ * Theme/inspector h1 is 42–48px and outranks :host font-size.
15
+ */
16
+
17
+ const createEditor = (content: string) =>
18
+ new Editor({ extensions: buildExtensions({ current: '' }), content });
19
+
20
+ const selectText = (editor: Editor, text: string) => {
21
+ editor.state.doc.descendants((node, pos) => {
22
+ if (node.isText && node.text?.includes(text)) {
23
+ const offset = node.text.indexOf(text);
24
+ editor.commands.setTextSelection({ from: pos + offset, to: pos + offset + text.length });
25
+ return false;
26
+ }
27
+ });
28
+ };
29
+
30
+ const setLinkLikeTheField = (editor: Editor, href = 'https://vev.design') =>
31
+ // Same chain the field's selectLink / updateLink uses.
32
+ editor.chain().focus().extendMarkRange('link').setLink({ href, target: null, rel: null }).run();
33
+
34
+ describe('list + link + font-size (E-1228)', () => {
35
+ it('keeps a bullet list as a list after setLink (does not lift to a heading)', () => {
36
+ const editor = createEditor(
37
+ '<ul><li><p>Facility <a href="https://example.com">information</a></p></li></ul>',
38
+ );
39
+ selectText(editor, 'information');
40
+ setLinkLikeTheField(editor);
41
+
42
+ const html = editor.getHTML();
43
+ expect(html).toContain('<ul>');
44
+ expect(html).toContain('<li>');
45
+ expect(html).not.toMatch(/<h[1-6][ >]/);
46
+ editor.destroy();
47
+ });
48
+
49
+ it('preserves a span font-size inside a list item through setLink', () => {
50
+ const editor = createEditor(
51
+ '<ul><li><p><span style="font-size: 18px">Facility <a href="https://example.com">information</a></span></p></li></ul>',
52
+ );
53
+ expect(editor.getHTML()).toContain('font-size: 18px');
54
+
55
+ selectText(editor, 'information');
56
+ setLinkLikeTheField(editor);
57
+
58
+ const html = editor.getHTML();
59
+ expect(html).toContain('font-size: 18px');
60
+ expect(html).toContain('<ul>');
61
+ editor.destroy();
62
+ });
63
+
64
+ it('preserves font-size set on the link itself through setLink', () => {
65
+ const editor = createEditor(
66
+ '<ul><li><p>See <a href="https://example.com" style="font-size: 18px">information</a></p></li></ul>',
67
+ );
68
+ expect(editor.getHTML()).toContain('font-size: 18px');
69
+
70
+ selectText(editor, 'information');
71
+ setLinkLikeTheField(editor, 'https://vev.design');
72
+
73
+ const html = editor.getHTML();
74
+ expect(html).toContain('font-size: 18px');
75
+ expect(html).toContain('href="https://vev.design"');
76
+ expect(html).toContain('<ul>');
77
+ editor.destroy();
78
+ });
79
+
80
+ it('round-trips inline font-size in a list without rewriting it', () => {
81
+ const source =
82
+ '<ul><li><p><span style="font-size: 18px">Facility information</span></p></li></ul>';
83
+ const editor = createEditor(source);
84
+ const firstPass = editor.getHTML();
85
+ expect(firstPass).toContain('font-size: 18px');
86
+ editor.destroy();
87
+
88
+ const second = createEditor(firstPass);
89
+ expect(second.getHTML()).toBe(firstPass);
90
+ second.destroy();
91
+ });
92
+
93
+ it('wraps a heading toggled to a bullet list as a paragraph, not an h1', () => {
94
+ const editor = createEditor('<h1>Facility information</h1>');
95
+ editor.chain().selectAll().toggleBulletList().run();
96
+
97
+ const html = editor.getHTML();
98
+ expect(html).toContain('<ul>');
99
+ expect(html).toContain('<li>');
100
+ expect(html).not.toContain('<h1>');
101
+ editor.destroy();
102
+ });
103
+
104
+ it('does not lift a list item to a heading when setHeading is used inside the list', () => {
105
+ const editor = createEditor('<ul><li><p>Facility information</p></li></ul>');
106
+ selectText(editor, 'Facility');
107
+ editor.chain().focus().setHeading({ level: 1 }).run();
108
+
109
+ const html = editor.getHTML();
110
+ expect(html).toContain('<ul>');
111
+ expect(html).not.toContain('<h1>');
112
+ editor.destroy();
113
+ });
114
+
115
+ it('parses a heading inside a list item as a paragraph (does not lift it out)', () => {
116
+ const editor = createEditor('<ul><li><h1>Facility information</h1></li></ul>');
117
+ const html = editor.getHTML();
118
+ expect(html).toContain('<ul>');
119
+ expect(html).toContain('<li>');
120
+ expect(html).toContain('Facility information');
121
+ expect(html).not.toContain('<h1>');
122
+ // Pre-fix: the heading was lifted next to an empty list item
123
+ // (`<ul><li><p></p></li></ul><h1>…</h1>`), so the text rendered at 48px.
124
+ expect(html).not.toMatch(/<\/ul>\s*<h1>/);
125
+ editor.destroy();
126
+ });
127
+
128
+ it('still allows nesting a list item under another (Tab indent)', () => {
129
+ const editor = createEditor('<ul><li><p>one</p></li><li><p>two</p></li></ul>');
130
+ editor.commands.focus('end');
131
+ editor.commands.sinkListItem('listItem');
132
+ expect(editor.getHTML()).toContain('<ul><li><p>one</p><ul><li><p>two</p></li></ul></li></ul>');
133
+ editor.destroy();
134
+ });
135
+ });