@vev/silke 1.2.0 → 1.2.2

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 (231) hide show
  1. package/.turbo/turbo-build.log +87 -87
  2. package/CHANGELOG.md +18 -0
  3. package/dist/index.js +42 -45
  4. package/dist/index.js.LEGAL.txt +2 -1
  5. package/dist/index.js.map +4 -4
  6. package/dist/styles.css +145 -119
  7. package/dist/types/components/silke-action-box/silke-action-box.d.ts +1 -1
  8. package/dist/types/components/silke-alert-banner/silke-alert-banner.d.ts +1 -1
  9. package/dist/types/components/silke-autocomplete-field/autocomplete-item.d.ts +1 -1
  10. package/dist/types/components/silke-autocomplete-field/autocomplete-tags.d.ts +2 -1
  11. package/dist/types/components/silke-autocomplete-field/silke-autocomplete-field-native.d.ts +1 -1
  12. package/dist/types/components/silke-autocomplete-field/silke-autocomplete-field.d.ts +1 -1
  13. package/dist/types/components/silke-autocomplete-field/silke-autocomplete-popup-native.d.ts +2 -2
  14. package/dist/types/components/silke-autocomplete-field/silke-autocomplete-popup.d.ts +2 -2
  15. package/dist/types/components/silke-box/silke-box.d.ts +1 -1
  16. package/dist/types/components/silke-breadcrumbs/silke-breadcrumb.d.ts +1 -1
  17. package/dist/types/components/silke-breadcrumbs/silke-breadcrumbs.d.ts +2 -1
  18. package/dist/types/components/silke-button/context.d.ts +1 -1
  19. package/dist/types/components/silke-button/silke-big-button.d.ts +1 -1
  20. package/dist/types/components/silke-button/silke-button-set.d.ts +1 -1
  21. package/dist/types/components/silke-button/silke-confirmation-button.d.ts +1 -1
  22. package/dist/types/components/silke-button/silke-dropdown-button.d.ts +2 -1
  23. package/dist/types/components/silke-button/silke-file-select-button.d.ts +2 -1
  24. package/dist/types/components/silke-card/silke-card-grid.d.ts +1 -1
  25. package/dist/types/components/silke-card/silke-card.spec.d.ts +1 -0
  26. package/dist/types/components/silke-checkbox/silke-checkbox.d.ts +1 -1
  27. package/dist/types/components/silke-code-editor/index.d.ts +2 -1
  28. package/dist/types/components/silke-code-editor/silke-code-editor.d.ts +2 -1
  29. package/dist/types/components/silke-code-snippet/silke-code-snippet.d.ts +1 -1
  30. package/dist/types/components/silke-color-palettes/silke-color-palette.d.ts +2 -1
  31. package/dist/types/components/silke-color-palettes/silke-color-palettes.d.ts +2 -1
  32. package/dist/types/components/silke-color-picker/silke-color-info.d.ts +2 -1
  33. package/dist/types/components/silke-color-picker/silke-color-picker-button.d.ts +1 -1
  34. package/dist/types/components/silke-color-picker/silke-color-picker.d.ts +2 -1
  35. package/dist/types/components/silke-color-picker/silke-color-space.d.ts +2 -1
  36. package/dist/types/components/silke-color-picker/silke-hue-slider.d.ts +2 -1
  37. package/dist/types/components/silke-color-picker/silke-opacity-slider.d.ts +2 -1
  38. package/dist/types/components/silke-color-swatches/silke-swatches.d.ts +2 -1
  39. package/dist/types/components/silke-command-text-field/attachment-chip.d.ts +2 -1
  40. package/dist/types/components/silke-command-text-field/attachment-list.d.ts +2 -0
  41. package/dist/types/components/silke-command-text-field/file-utils.d.ts +21 -1
  42. package/dist/types/components/silke-command-text-field/index.d.ts +1 -1
  43. package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +2 -0
  44. package/dist/types/components/silke-conditions-input/silke-conditions-input-options.d.ts +2 -1
  45. package/dist/types/components/silke-conditions-input/silke-conditions-input.d.ts +2 -1
  46. package/dist/types/components/silke-conditions-input/silke-conditions-tag.d.ts +2 -1
  47. package/dist/types/components/silke-content-column/silke-content-column.d.ts +2 -1
  48. package/dist/types/components/silke-context-menu/silke-context-menu-item.d.ts +1 -1
  49. package/dist/types/components/silke-context-menu/silke-context-menu.d.ts +1 -1
  50. package/dist/types/components/silke-css-number-field/silke-css-context.d.ts +1 -1
  51. package/dist/types/components/silke-css-number-field/silke-css-number-field.d.ts +1 -1
  52. package/dist/types/components/silke-divider/silke-divider.d.ts +2 -1
  53. package/dist/types/components/silke-drawer/silke-drawer.d.ts +1 -1
  54. package/dist/types/components/silke-expression-input/silke-expression-input-tag.d.ts +2 -1
  55. package/dist/types/components/silke-form/form-context.d.ts +1 -1
  56. package/dist/types/components/silke-form/silke-form.d.ts +2 -2
  57. package/dist/types/components/silke-form-schema/fields/array-field-inline.d.ts +2 -1
  58. package/dist/types/components/silke-form-schema/fields/array-field-modal.d.ts +2 -2
  59. package/dist/types/components/silke-form-schema/fields/array-field.d.ts +2 -1
  60. package/dist/types/components/silke-form-schema/fields/audio-field.d.ts +2 -1
  61. package/dist/types/components/silke-form-schema/fields/color-field.d.ts +2 -1
  62. package/dist/types/components/silke-form-schema/fields/event-field.d.ts +2 -1
  63. package/dist/types/components/silke-form-schema/fields/group-field.d.ts +2 -1
  64. package/dist/types/components/silke-form-schema/fields/icon-field.d.ts +2 -1
  65. package/dist/types/components/silke-form-schema/fields/image-field.d.ts +2 -1
  66. package/dist/types/components/silke-form-schema/fields/layout-field.d.ts +2 -1
  67. package/dist/types/components/silke-form-schema/fields/link-field.d.ts +2 -1
  68. package/dist/types/components/silke-form-schema/fields/number-field.d.ts +2 -1
  69. package/dist/types/components/silke-form-schema/fields/object-field.d.ts +2 -1
  70. package/dist/types/components/silke-form-schema/fields/popover-field.d.ts +2 -1
  71. package/dist/types/components/silke-form-schema/fields/select-field.d.ts +2 -1
  72. package/dist/types/components/silke-form-schema/fields/string-field.d.ts +2 -1
  73. package/dist/types/components/silke-form-schema/fields/toggle-field.d.ts +2 -1
  74. package/dist/types/components/silke-form-schema/fields/upload-field.d.ts +2 -1
  75. package/dist/types/components/silke-form-schema/fields/utils/generate-preview.spec.d.ts +1 -0
  76. package/dist/types/components/silke-form-schema/fields/utils/generate-title.d.ts +10 -0
  77. package/dist/types/components/silke-form-schema/fields/video-field.d.ts +2 -1
  78. package/dist/types/components/silke-form-schema/silke-extended-fields-context.d.ts +3 -3
  79. package/dist/types/components/silke-form-schema/silke-form-schema.d.ts +5 -2
  80. package/dist/types/components/silke-form-schema/silke-schema-context.d.ts +2 -2
  81. package/dist/types/components/silke-form-schema/silke-schema-decorator.d.ts +14 -3
  82. package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
  83. package/dist/types/components/silke-form-schema/silke-schema-fields.d.ts +2 -1
  84. package/dist/types/components/silke-gradient-picker/silke-gradient-picker.d.ts +2 -1
  85. package/dist/types/components/silke-gradient-picker/silke-gradient-position.d.ts +2 -1
  86. package/dist/types/components/silke-gradient-picker/silke-gradient-slider.d.ts +2 -1
  87. package/dist/types/components/silke-icon/silke-icon.d.ts +1 -1
  88. package/dist/types/components/silke-icon/silke-shape.d.ts +2 -1
  89. package/dist/types/components/silke-icon/silke-stacked-icon.d.ts +2 -1
  90. package/dist/types/components/silke-icon-picker/color-swatch-section.d.ts +2 -1
  91. package/dist/types/components/silke-icon-picker/emoji-tab.d.ts +2 -1
  92. package/dist/types/components/silke-icon-picker/icons-tab.d.ts +2 -1
  93. package/dist/types/components/silke-icon-picker/silke-icon-picker.d.ts +2 -1
  94. package/dist/types/components/silke-icon-picker/upload-tab.d.ts +2 -1
  95. package/dist/types/components/silke-iframe-portal/silke-iframe-portal.d.ts +1 -1
  96. package/dist/types/components/silke-image/silke-image-color-backdrop.d.ts +2 -1
  97. package/dist/types/components/silke-image/silke-image.d.ts +2 -1
  98. package/dist/types/components/silke-link/silke-link.d.ts +1 -1
  99. package/dist/types/components/silke-list/silke-list-item.d.ts +1 -1
  100. package/dist/types/components/silke-list/silke-list.d.ts +2 -1
  101. package/dist/types/components/silke-loader/silke-loader-overlay.d.ts +1 -1
  102. package/dist/types/components/silke-loader/silke-loader.d.ts +2 -2
  103. package/dist/types/components/silke-modal/silke-confirmation-modal.d.ts +2 -1
  104. package/dist/types/components/silke-modal/silke-modal.d.ts +3 -3
  105. package/dist/types/components/silke-object-field/silke-object-field.d.ts +1 -1
  106. package/dist/types/components/silke-overflow-menu/silke-overflow-menu.d.ts +1 -1
  107. package/dist/types/components/silke-popover/popover-context.d.ts +1 -1
  108. package/dist/types/components/silke-popover/silke-popover.d.ts +2 -2
  109. package/dist/types/components/silke-popover-native/silke-popover-native.d.ts +1 -1
  110. package/dist/types/components/silke-popover-native/types.d.ts +1 -1
  111. package/dist/types/components/silke-popover-native/use-popover-positioning.d.ts +1 -1
  112. package/dist/types/components/silke-progress-indicator/silke-progress-indicator.d.ts +1 -1
  113. package/dist/types/components/silke-progress-indicator/silke-progress-step.d.ts +2 -1
  114. package/dist/types/components/silke-radio-button/silke-radio-button-group.d.ts +1 -1
  115. package/dist/types/components/silke-radio-button/silke-radio-button.d.ts +1 -1
  116. package/dist/types/components/silke-rich-text-field/blockquote.d.ts +3 -18
  117. package/dist/types/components/silke-rich-text-field/floating-layer.d.ts +5 -1
  118. package/dist/types/components/silke-rich-text-field/floating-layer.spec.d.ts +1 -0
  119. package/dist/types/components/silke-rich-text-field/formatting-toolbar.d.ts +2 -1
  120. package/dist/types/components/silke-rich-text-field/link-menu.d.ts +1 -1
  121. package/dist/types/components/silke-rich-text-field/link-tooltip.d.ts +2 -1
  122. package/dist/types/components/silke-rich-text-field/silke-rich-text-field.d.ts +1 -1
  123. package/dist/types/components/silke-rich-text-field/slash-menu.d.ts +5 -4
  124. package/dist/types/components/silke-rich-text-field/slash-menu.spec.d.ts +1 -0
  125. package/dist/types/components/silke-rich-text-field/table-toolbar.d.ts +2 -1
  126. package/dist/types/components/silke-rich-text-field/use-link-hover.d.ts +1 -1
  127. package/dist/types/components/silke-rich-text-field/utils.d.ts +29 -1
  128. package/dist/types/components/silke-rich-text-field/utils.spec.d.ts +1 -0
  129. package/dist/types/components/silke-search-field/silke-search-field.d.ts +2 -1
  130. package/dist/types/components/silke-select-field/silke-select-field-native.d.ts +2 -1
  131. package/dist/types/components/silke-select-field/silke-select-field.d.ts +2 -1
  132. package/dist/types/components/silke-shortcut-button/silke-shortcut-button.d.ts +1 -1
  133. package/dist/types/components/silke-skeleton/silke-skeleton.d.ts +1 -1
  134. package/dist/types/components/silke-slider/silke-slider-point.d.ts +1 -1
  135. package/dist/types/components/silke-slider/silke-slider.d.ts +1 -1
  136. package/dist/types/components/silke-slider/slider-track.d.ts +1 -1
  137. package/dist/types/components/silke-sortable-list/silke-nested-sortable-item.d.ts +1 -1
  138. package/dist/types/components/silke-sortable-list/silke-nested-sortable-list.d.ts +1 -1
  139. package/dist/types/components/silke-sortable-list/silke-sortable-item-wrapper.d.ts +1 -1
  140. package/dist/types/components/silke-sortable-list/silke-sortable-list.d.ts +1 -1
  141. package/dist/types/components/silke-table/silke-table.d.ts +1 -1
  142. package/dist/types/components/silke-table/table-row.d.ts +2 -1
  143. package/dist/types/components/silke-tabs/silke-tab.d.ts +1 -1
  144. package/dist/types/components/silke-tabs/silke-tabs.d.ts +1 -1
  145. package/dist/types/components/silke-tag/silke-tag.d.ts +6 -6
  146. package/dist/types/components/silke-text/silke-text.d.ts +27 -13
  147. package/dist/types/components/silke-text/silke-title.d.ts +2 -1
  148. package/dist/types/components/silke-text-field/text-field-context.d.ts +1 -1
  149. package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +2 -1
  150. package/dist/types/components/silke-theme-editor/silke-theme-editor.d.ts +2 -1
  151. package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +2 -1
  152. package/dist/types/components/silke-tile/silke-tile.d.ts +2 -2
  153. package/dist/types/components/silke-toast-notification/silke-toast-notification.d.ts +1 -1
  154. package/dist/types/components/silke-toggle/silke-toggle.d.ts +1 -1
  155. package/dist/types/components/silke-toolbar/silke-toolbar.d.ts +2 -1
  156. package/dist/types/components/silke-tooltip/silke-definition-tooltip.d.ts +1 -1
  157. package/dist/types/components/silke-tooltip/silke-icon-tooltip.d.ts +1 -1
  158. package/dist/types/components/silke-tooltip/silke-interactive-tooltip.d.ts +1 -1
  159. package/dist/types/components/silke-tooltip/silke-shortcuts.d.ts +2 -1
  160. package/dist/types/components/silke-tooltip/silke-tooltip.d.ts +1 -1
  161. package/dist/types/components/silke-upload-field/silke-upload-field.d.ts +1 -1
  162. package/dist/types/components/silke-variables-wrapper/silke-variables-wrapper-form.d.ts +2 -2
  163. package/dist/types/components/silke-variables-wrapper/silke-variables-wrapper.d.ts +1 -1
  164. package/dist/types/components/silke-virtual/silke-virtual-grid.d.ts +1 -1
  165. package/dist/types/components/silke-virtual/silke-virtual-row.d.ts +1 -1
  166. package/dist/types/hooks/use-drop-zone.d.ts +1 -1
  167. package/dist/types/hooks/use-mouse.d.ts +1 -1
  168. package/dist/types/hooks/use-parent-scroll.d.ts +1 -1
  169. package/dist/types/hooks/use-size.d.ts +1 -1
  170. package/dist/types/icons.d.ts +33 -32
  171. package/dist/types/silke-theme-provider.d.ts +1 -1
  172. package/package.json +18 -16
  173. package/src/@types/declarations.d.ts +1 -1
  174. package/src/components/silke-alert-banner/silke-alert-banner.tsx +1 -1
  175. package/src/components/silke-autocomplete-field/silke-autocomplete-field-native.tsx +3 -3
  176. package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +4 -4
  177. package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +6 -6
  178. package/src/components/silke-autocomplete-field/silke-autocomplete-popup.tsx +6 -6
  179. package/src/components/silke-card/silke-card.scss +30 -3
  180. package/src/components/silke-card/silke-card.spec.tsx +32 -0
  181. package/src/components/silke-card/silke-card.tsx +62 -34
  182. package/src/components/silke-command-text-field/attachment-list.tsx +6 -7
  183. package/src/components/silke-command-text-field/file-utils.ts +103 -23
  184. package/src/components/silke-command-text-field/index.ts +3 -0
  185. package/src/components/silke-command-text-field/silke-command-text-field.mdx +5 -1
  186. package/src/components/silke-command-text-field/silke-command-text-field.tsx +26 -29
  187. package/src/components/silke-conditions-input/silke-conditions-input-options.tsx +1 -1
  188. package/src/components/silke-css-number-field/silke-css-number-field.tsx +4 -4
  189. package/src/components/silke-drawer/silke-drawer.tsx +1 -1
  190. package/src/components/silke-form-schema/fields/string-field.tsx +8 -6
  191. package/src/components/silke-form-schema/fields/utils/generate-image.ts +5 -14
  192. package/src/components/silke-form-schema/fields/utils/generate-preview.spec.ts +49 -0
  193. package/src/components/silke-form-schema/fields/utils/generate-title.ts +23 -10
  194. package/src/components/silke-form-schema/safe-eval/iframe-script.raw.js +1 -0
  195. package/src/components/silke-form-schema/schema-utils.ts +29 -2
  196. package/src/components/silke-form-schema/silke-extended-fields-context.tsx +1 -1
  197. package/src/components/silke-form-schema/silke-form-schema.tsx +9 -2
  198. package/src/components/silke-form-schema/silke-schema-decorator.tsx +22 -1
  199. package/src/components/silke-form-schema/silke-schema-field.tsx +13 -2
  200. package/src/components/silke-icon/silke-icon.tsx +1 -1
  201. package/src/components/silke-list/silke-list.tsx +15 -8
  202. package/src/components/silke-object-field/silke-object-field.tsx +1 -1
  203. package/src/components/silke-popover/silke-popover.tsx +14 -10
  204. package/src/components/silke-popover-native/types.ts +1 -1
  205. package/src/components/silke-popover-native/use-popover-positioning.ts +1 -1
  206. package/src/components/silke-rich-text-field/blockquote.spec.ts +118 -25
  207. package/src/components/silke-rich-text-field/blockquote.ts +46 -53
  208. package/src/components/silke-rich-text-field/floating-layer.spec.tsx +20 -0
  209. package/src/components/silke-rich-text-field/floating-layer.tsx +16 -1
  210. package/src/components/silke-rich-text-field/plugins.ts +1 -2
  211. package/src/components/silke-rich-text-field/silke-rich-text-field.scss +10 -0
  212. package/src/components/silke-rich-text-field/silke-rich-text-field.tsx +9 -4
  213. package/src/components/silke-rich-text-field/slash-menu-items.ts +1 -4
  214. package/src/components/silke-rich-text-field/slash-menu.spec.tsx +52 -0
  215. package/src/components/silke-rich-text-field/slash-menu.tsx +28 -14
  216. package/src/components/silke-rich-text-field/utils.spec.ts +115 -0
  217. package/src/components/silke-rich-text-field/utils.ts +76 -2
  218. package/src/components/silke-tag/silke-tag.tsx +1 -1
  219. package/src/components/silke-text-field/silke-text-field.tsx +2 -2
  220. package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +11 -6
  221. package/src/components/silke-toast-notification/confetti.tsx +1 -1
  222. package/src/components/silke-toast-notification/silke-toast-notification.tsx +1 -1
  223. package/src/components/silke-upload-field/silke-upload-field.tsx +2 -2
  224. package/src/components/silke-variables-wrapper/silke-variables-wrapper-form.tsx +1 -1
  225. package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +9 -3
  226. package/src/hooks/form/use-form-field.ts +2 -2
  227. package/src/hooks/use-drop-zone.ts +1 -1
  228. package/src/hooks/use-html-element.ts +1 -1
  229. package/src/hooks/use-mouse.ts +1 -1
  230. package/src/hooks/use-parent-scroll.ts +1 -1
  231. package/src/hooks/use-size.ts +1 -1
@@ -0,0 +1,115 @@
1
+ import type { Editor } from '@tiptap/react';
2
+ import {
3
+ FLOATING_MENU_OFFSET,
4
+ SLASH_MENU_MAX_HEIGHT,
5
+ getCursorPosition,
6
+ getFloatingMenuPosition,
7
+ getSlashMenuPosition,
8
+ } from './utils';
9
+
10
+ const editorAt = (caret: { bottom: number; left: number; top: number }): Editor =>
11
+ ({
12
+ state: { selection: { $from: { pos: 1 } } },
13
+ view: { coordsAtPos: () => caret },
14
+ }) as unknown as Editor;
15
+
16
+ describe('getFloatingMenuPosition', () => {
17
+ it('opens below the caret when there is enough room', () => {
18
+ expect(
19
+ getFloatingMenuPosition({ bottom: 120, left: 40, top: 100 }, 800),
20
+ ).toEqual({
21
+ left: 40,
22
+ maxHeight: SLASH_MENU_MAX_HEIGHT,
23
+ top: 120 + FLOATING_MENU_OFFSET,
24
+ });
25
+ });
26
+
27
+ it('flips above the caret when the space below is too short', () => {
28
+ expect(
29
+ getFloatingMenuPosition({ bottom: 720, left: 40, top: 700 }, 800),
30
+ ).toEqual({
31
+ bottom: 800 - 700 + FLOATING_MENU_OFFSET,
32
+ left: 40,
33
+ maxHeight: SLASH_MENU_MAX_HEIGHT,
34
+ });
35
+ });
36
+
37
+ it('caps height to the space below when both sides are short and below is larger', () => {
38
+ expect(
39
+ getFloatingMenuPosition({ bottom: 200, left: 16, top: 180 }, 400),
40
+ ).toEqual({
41
+ left: 16,
42
+ maxHeight: 180,
43
+ top: 200 + FLOATING_MENU_OFFSET,
44
+ });
45
+ });
46
+
47
+ it('caps height to the space above when both sides are short and above is larger', () => {
48
+ expect(
49
+ getFloatingMenuPosition({ bottom: 220, left: 16, top: 200 }, 400),
50
+ ).toEqual({
51
+ bottom: 400 - 200 + FLOATING_MENU_OFFSET,
52
+ left: 16,
53
+ maxHeight: 180,
54
+ });
55
+ });
56
+
57
+ it('stays below when both sides are equally short', () => {
58
+ expect(
59
+ getFloatingMenuPosition({ bottom: 210, left: 0, top: 190 }, 400),
60
+ ).toEqual({
61
+ left: 0,
62
+ maxHeight: 170,
63
+ top: 210 + FLOATING_MENU_OFFSET,
64
+ });
65
+ });
66
+
67
+ it('honors a custom max height', () => {
68
+ expect(
69
+ getFloatingMenuPosition({ bottom: 120, left: 8, top: 100 }, 800, { maxHeight: 120 }),
70
+ ).toEqual({
71
+ left: 8,
72
+ maxHeight: 120,
73
+ top: 120 + FLOATING_MENU_OFFSET,
74
+ });
75
+ });
76
+ });
77
+
78
+ describe('getCursorPosition', () => {
79
+ it('anchors the link menu below the caret', () => {
80
+ expect(getCursorPosition(editorAt({ bottom: 720, left: 40, top: 700 }))).toEqual({
81
+ left: 40,
82
+ top: 720 + FLOATING_MENU_OFFSET,
83
+ });
84
+ });
85
+
86
+ it('returns the origin when there is no editor', () => {
87
+ expect(getCursorPosition(null)).toEqual({ left: 0, top: 0 });
88
+ });
89
+ });
90
+
91
+ describe('getSlashMenuPosition', () => {
92
+ const { innerHeight } = window;
93
+
94
+ afterEach(() => {
95
+ Object.defineProperty(window, 'innerHeight', { configurable: true, value: innerHeight });
96
+ });
97
+
98
+ it('uses the viewport height to flip a low caret', () => {
99
+ Object.defineProperty(window, 'innerHeight', { configurable: true, value: 800 });
100
+
101
+ expect(getSlashMenuPosition(editorAt({ bottom: 720, left: 24, top: 700 }))).toEqual({
102
+ bottom: 800 - 700 + FLOATING_MENU_OFFSET,
103
+ left: 24,
104
+ maxHeight: SLASH_MENU_MAX_HEIGHT,
105
+ });
106
+ });
107
+
108
+ it('returns the default box when there is no editor', () => {
109
+ expect(getSlashMenuPosition(null)).toEqual({
110
+ left: 0,
111
+ maxHeight: SLASH_MENU_MAX_HEIGHT,
112
+ top: 0,
113
+ });
114
+ });
115
+ });
@@ -2,6 +2,61 @@ import type { ResolvedPos } from '@tiptap/pm/model';
2
2
  import type { Editor } from '@tiptap/react';
3
3
  import { useRef } from 'react';
4
4
 
5
+ /** Gap between the caret and a floating menu. */
6
+ export const FLOATING_MENU_OFFSET = 12;
7
+ /** Same cap as `.linkMenuList` — long slash/block menus must scroll, not clip. */
8
+ export const SLASH_MENU_MAX_HEIGHT = 280;
9
+ const VIEWPORT_PADDING = 8;
10
+
11
+ export interface CaretRect {
12
+ bottom: number;
13
+ left: number;
14
+ top: number;
15
+ }
16
+
17
+ /** Viewport box for a floating menu. `bottom` is set when the menu flips above the caret. */
18
+ export interface FloatingMenuPosition {
19
+ bottom?: number;
20
+ left: number;
21
+ maxHeight: number;
22
+ top?: number;
23
+ }
24
+
25
+ /**
26
+ * Place a capped-height menu below the caret, or flip it above when there is not
27
+ * enough room underneath. `maxHeight` is the smaller of the preferred cap and the
28
+ * space on the chosen side, so the list can scroll instead of clipping off-screen.
29
+ */
30
+ export function getFloatingMenuPosition(
31
+ caret: CaretRect,
32
+ viewportHeight: number,
33
+ options?: { maxHeight?: number; offset?: number; padding?: number },
34
+ ): FloatingMenuPosition {
35
+ const maxHeight = options?.maxHeight ?? SLASH_MENU_MAX_HEIGHT;
36
+ const offset = options?.offset ?? FLOATING_MENU_OFFSET;
37
+ const padding = options?.padding ?? VIEWPORT_PADDING;
38
+
39
+ const spaceBelow = viewportHeight - caret.bottom - offset - padding;
40
+ const spaceAbove = caret.top - offset - padding;
41
+ const openAbove = spaceBelow < maxHeight && spaceAbove > spaceBelow;
42
+ const available = openAbove ? spaceAbove : spaceBelow;
43
+ const height = available > 0 ? Math.min(maxHeight, available) : maxHeight;
44
+
45
+ if (openAbove) {
46
+ return {
47
+ bottom: viewportHeight - caret.top + offset,
48
+ left: caret.left,
49
+ maxHeight: height,
50
+ };
51
+ }
52
+
53
+ return {
54
+ left: caret.left,
55
+ maxHeight: height,
56
+ top: caret.bottom + offset,
57
+ };
58
+ }
59
+
5
60
  /** Viewport position of the cursor, for the menus that render in the floating layer */
6
61
  export function getCursorPosition(editor: Editor | null): { left: number; top: number } {
7
62
  if (!editor) return { left: 0, top: 0 };
@@ -10,12 +65,25 @@ export function getCursorPosition(editor: Editor | null): { left: number; top: n
10
65
  const { $from } = editor.state.selection;
11
66
  const coords = editor.view.coordsAtPos($from.pos);
12
67
 
13
- return { left: coords.left, top: coords.bottom + 12 };
68
+ return { left: coords.left, top: coords.bottom + FLOATING_MENU_OFFSET };
14
69
  } catch {
15
70
  return { left: 0, top: 0 };
16
71
  }
17
72
  }
18
73
 
74
+ /** Slash/block menu placement: flips and caps height so every item stays reachable. */
75
+ export function getSlashMenuPosition(editor: Editor | null): FloatingMenuPosition {
76
+ if (!editor) return { left: 0, maxHeight: SLASH_MENU_MAX_HEIGHT, top: 0 };
77
+
78
+ try {
79
+ const { $from } = editor.state.selection;
80
+ const coords = editor.view.coordsAtPos($from.pos);
81
+ return getFloatingMenuPosition(coords, window.innerHeight);
82
+ } catch {
83
+ return { left: 0, maxHeight: SLASH_MENU_MAX_HEIGHT, top: 0 };
84
+ }
85
+ }
86
+
19
87
  /** The <table> element the caret sits in, for anchoring the table toolbar to its edge. */
20
88
  export function getTableElement(editor: Editor | null): HTMLElement | null {
21
89
  if (!editor) return null;
@@ -30,7 +98,13 @@ export function getTableElement(editor: Editor | null): HTMLElement | null {
30
98
  // Duck-typed rather than `instanceof HTMLElement`: the editor's DOM can live in
31
99
  // another realm (the canvas renders content inside custom elements), and there
32
100
  // instanceof against this bundle's constructor is false for a perfectly good node.
33
- return dom && typeof dom.getBoundingClientRect === 'function' ? dom : null;
101
+ if (!dom || typeof dom.getBoundingClientRect !== 'function') return null;
102
+ // TipTap 3.30+ table views wrap the <table> in a .tableWrapper div. nodeDOM
103
+ // returns that wrapper; the toolbar still needs the table's left edge.
104
+ if (dom.tagName === 'TABLE') return dom;
105
+ const table =
106
+ typeof dom.querySelector === 'function' ? dom.querySelector('table') : null;
107
+ return table && typeof table.getBoundingClientRect === 'function' ? table : null;
34
108
  }
35
109
  return null;
36
110
  } catch {
@@ -90,7 +90,7 @@ function SilkeTagComp(
90
90
  }
91
91
 
92
92
  export const SilkeTag = React.forwardRef(SilkeTagComp);
93
- SilkeBox.displayName = 'SilkeTag';
93
+ SilkeTag.displayName = 'SilkeTag';
94
94
 
95
95
  export const SilkeTagDark = ({ color, ...rest }: SilkeTagProps) => {
96
96
  return <SilkeTag {...rest} color="dark" />;
@@ -1,4 +1,4 @@
1
- import { generateGuid } from '@vev/utils';
1
+ import { generateGuid, hasProps } from '@vev/utils';
2
2
  import { isString, upperFirst } from 'lodash';
3
3
  import React, {
4
4
  Children,
@@ -120,7 +120,7 @@ export const SilkeTextField = React.forwardRef<HTMLDivElement, SilkeTextFieldPro
120
120
  const before: ReactNode[] = [];
121
121
  const after: ReactNode[] = [];
122
122
  Children.forEach(children, (child) => {
123
- if (React.isValidElement(child) && child.type === SilkeTextFieldItem && child.props.before) {
123
+ if (hasProps(child, ['before']) && child.type === SilkeTextFieldItem) {
124
124
  before.push(child);
125
125
  } else {
126
126
  after.push(child);
@@ -1,3 +1,4 @@
1
+ import { formatColorTokenLabel } from '@vev/utils';
1
2
  import React, { useRef, useState } from 'react';
2
3
  import tinycolor from 'tinycolor2';
3
4
  import { SilkeIcon } from '../silke-icon';
@@ -41,7 +42,13 @@ export function SilkeThemeSwatch({
41
42
  const hoveredCellRef = useRef<HTMLDivElement | null>(null);
42
43
 
43
44
  const restShades = SHADE_KEYS.filter((s) => !disabledShades?.includes(s));
44
- const showPrimary = primaryShade != null && !disabledShades?.includes(primaryShade);
45
+ const showPrimary = primaryShade !== undefined && !disabledShades?.includes(primaryShade);
46
+
47
+ const shadeTooltip = (shade: ShadeKey | null) => {
48
+ if (shade === null) return '';
49
+ const base = token ? `${token} ${shade}` : String(shade);
50
+ return formatColorTokenLabel(base, shades[shade]);
51
+ };
45
52
 
46
53
  return (
47
54
  <div className={styles.wrapper}>
@@ -116,18 +123,16 @@ export function SilkeThemeSwatch({
116
123
  anchorOrigin="top-center"
117
124
  targetOrigin="bottom-center"
118
125
  >
119
- {token ? `${token} ` : ''}
120
- {primaryShade}
126
+ {shadeTooltip(primaryShade ?? null)}
121
127
  </SilkeTooltip>
122
128
  )}
123
129
  <SilkeTooltip
124
- show={hoveredStripShade != null}
130
+ show={hoveredStripShade !== null}
125
131
  anchor={hoveredCellRef}
126
132
  anchorOrigin="top-center"
127
133
  targetOrigin="bottom-center"
128
134
  >
129
- {token ? `${token} ` : ''}
130
- {hoveredStripShade}
135
+ {shadeTooltip(hoveredStripShade)}
131
136
  </SilkeTooltip>
132
137
  </div>
133
138
  );
@@ -12,7 +12,7 @@ const createCanvasConfetti = () => {
12
12
  };
13
13
 
14
14
  const useConfetti = (ref: React.RefObject<HTMLBaseElement>) => {
15
- const requestRef = useRef<any>();
15
+ const requestRef = useRef<any>(null);
16
16
 
17
17
  useEffect(() => {
18
18
  let confetti = document.getElementById('confetti') as HTMLCanvasElement;
@@ -46,7 +46,7 @@ export function SilkeToastNotification({
46
46
  ...rest
47
47
  }: SilkeToastNotificationProps) {
48
48
  const cl: string[] = [styles.notificationBox];
49
- const iconRef = useRef<HTMLBaseElement>();
49
+ const iconRef = useRef<HTMLBaseElement>(null);
50
50
  const doublePadding = title && subtitle;
51
51
 
52
52
  if (kind === 'confetti') userConfetti(iconRef as any);
@@ -77,9 +77,9 @@ export function SilkeUploadField(props: SilkeUploadFieldProps) {
77
77
  dropzoneStyle,
78
78
  fileItemStyle,
79
79
  } = useFormField(props, validate);
80
- const ref = useRef<HTMLLabelElement>(null);
80
+ const ref = useRef<HTMLLabelElement | null>(null);
81
81
  const pendingRef = useRef<PendingFile[]>([]);
82
- const valueRef = useRef<SilkeUploadFieldProps['value']>();
82
+ const valueRef = useRef<SilkeUploadFieldProps['value'] | null>(null);
83
83
  const [dropState, setDropState] = useState<null | 'over' | 'invalid'>(null);
84
84
 
85
85
  pendingRef.current = pending;
@@ -8,7 +8,7 @@ import { SilkeTextField, TextFieldContext } from '../silke-text-field';
8
8
 
9
9
  export type SilkeVariablesWrapperFormProps = {
10
10
  variableValue: string;
11
- containerRef?: React.RefObject<HTMLDivElement>;
11
+ containerRef?: React.RefObject<HTMLDivElement | null>;
12
12
  onSubmit: (form: { variableName: string }) => void;
13
13
  onClose: () => void;
14
14
  };
@@ -8,6 +8,7 @@ import { SilkeButton } from '../silke-button';
8
8
  import styles from './silke-variables-wrapper.scss';
9
9
  import { useTextFieldContext } from '../silke-text-field/text-field-context';
10
10
  import {
11
+ formatColorTokenLabel,
11
12
  getCSSNumberFormat,
12
13
  getRelevantVariables,
13
14
  getVariableDisplayText,
@@ -63,7 +64,7 @@ export function SilkeVariablesWrapper<T extends React.ElementType>({
63
64
 
64
65
  const variableItems = React.useMemo(() => {
65
66
  return filteredVariables.map((v) => ({
66
- label: v.name,
67
+ label: v.type === 'color' ? formatColorTokenLabel(v.name, v.value) : v.name,
67
68
  value: v.key,
68
69
  subLabel:
69
70
  v.type === 'font'
@@ -78,7 +79,10 @@ export function SilkeVariablesWrapper<T extends React.ElementType>({
78
79
  (rest.value?.startsWith('var(--vev-') || rest.value?.startsWith('{{'));
79
80
 
80
81
  const currentVariable = React.useMemo(
81
- () => context.variablesv2.find((v) => typeof rest.value === 'string' && rest.value?.includes(v.key)),
82
+ () =>
83
+ context.variablesv2.find(
84
+ (v) => typeof rest.value === 'string' && rest.value?.includes(v.key),
85
+ ),
82
86
  [context.variablesv2, rest.value],
83
87
  );
84
88
 
@@ -250,7 +254,9 @@ export function SilkeVariablesWrapper<T extends React.ElementType>({
250
254
  )}
251
255
  {hovering && isVariable && currentVariable && (
252
256
  <SilkeTooltip show anchor={rootRef} anchorOrigin="top-center" targetOrigin="bottom-center">
253
- {currentVariable?.name}
257
+ {currentVariable.type === 'color'
258
+ ? formatColorTokenLabel(currentVariable.name, currentVariable.value)
259
+ : currentVariable.name}
254
260
  </SilkeTooltip>
255
261
  )}
256
262
  {isVariable && currentVariable ? (
@@ -10,8 +10,8 @@ export function useFormField<T extends FormFieldProps<U>, U = any>(
10
10
  const { name, onError } = props;
11
11
  let { value, onChange } = props;
12
12
  const context = useContext(getFieldContext<any>());
13
- const valueRef = useRef<U>();
14
- const propsRef = useRef<T>();
13
+ const valueRef = useRef<U | undefined>(undefined);
14
+ const propsRef = useRef<T | null>(null);
15
15
  const validatorRef = useRef<FormValidator<T>>(validator);
16
16
  validatorRef.current = validator;
17
17
 
@@ -14,7 +14,7 @@ function preventDragDefault(el: HTMLElement) {
14
14
  if (typeof document !== 'undefined') preventDragDefault(document.body);
15
15
 
16
16
  export function useDropZone(
17
- target: RefObject<HTMLElement>,
17
+ target: RefObject<HTMLElement | null>,
18
18
  onDrop: (e: DragEvent) => void,
19
19
  onEnter?: (e: DragEvent) => void,
20
20
  onLeave?: (e: DragEvent) => void,
@@ -9,7 +9,7 @@ export function useHTMLElement(
9
9
  attrs?: Record<string, string>,
10
10
  appendTo?: HTMLElement,
11
11
  ): RefObject<HTMLElement> {
12
- const ref = useRef<HTMLElement>();
12
+ const ref = useRef<HTMLElement | null>(null);
13
13
  if (!ref.current) ref.current = document.createElement(tag);
14
14
 
15
15
  useLayoutEffect(() => {
@@ -115,7 +115,7 @@ export function useMouseUp(cb: MouseListener, disabled = false) {
115
115
  }
116
116
 
117
117
  export function useMouseDownOutside(
118
- ref: React.RefObject<HTMLElement>,
118
+ ref: React.RefObject<HTMLElement | null>,
119
119
  cb: MouseListener,
120
120
  disabled?: boolean,
121
121
  ) {
@@ -18,7 +18,7 @@ function getScrollParent(element: HTMLElement, includeHidden = false): HTMLEleme
18
18
  }
19
19
 
20
20
  export function useParentScroll(
21
- ref: RefObject<HTMLElement> | null | undefined,
21
+ ref: RefObject<HTMLElement | null> | null | undefined,
22
22
  cb: (e: Event) => void,
23
23
  ) {
24
24
  const cbRef = useCallbackRef(cb);
@@ -5,7 +5,7 @@ type Listener = [el: HTMLElement, cb: SizeCallback];
5
5
  const listeners: Listener[] = [];
6
6
  let observer: ResizeObserver;
7
7
 
8
- export function useSize(ref: RefObject<HTMLElement>, cb: SizeCallback) {
8
+ export function useSize(ref: RefObject<HTMLElement | null>, cb: SizeCallback) {
9
9
  const cbRef = useRef(cb);
10
10
  cbRef.current = cb;
11
11