@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
@@ -1,11 +1,11 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import { BoxSize, SilkeBox } from '../silke-box';
3
3
  import { SilkeCheckbox } from '../silke-checkbox';
4
- import { SilkeText, SilkeTextMicro } from '../silke-text';
5
4
  import { Data, Entry } from './autocomplete-types';
6
- import styles from './silke-autocomplete-field.scss';
7
5
  import { SilkeIcon } from '../silke-icon';
8
6
  import { EmojiType } from '@vev/utils';
7
+ import { SilkeListItem } from '../silke-list/silke-list-item';
8
+ import styles from './silke-autocomplete-field.scss';
9
9
 
10
10
  export interface AutocompleteRenderItemProps<U> {
11
11
  item: U;
@@ -31,7 +31,6 @@ export default function AutocompleteItem<T, U extends Entry<T>>({
31
31
  multiple,
32
32
  highlight,
33
33
  size,
34
- iconFontSize,
35
34
  onMouseDown,
36
35
  ItemRender,
37
36
  }: AutocompleteItemProps<T, U>) {
@@ -39,77 +38,64 @@ export default function AutocompleteItem<T, U extends Entry<T>>({
39
38
  const isDisabled = (item as Data<T>).disabled;
40
39
  const ref = useRef<HTMLDivElement>(null);
41
40
 
42
- const cl = styles.autocompleteItem;
43
-
44
41
  useEffect(() => {
45
42
  const el = ref.current;
46
43
  if (highlight) (el as any)?.scrollIntoViewIfNeeded?.();
47
44
  }, [highlight]);
48
45
 
49
- let iconSize: BoxSize = size || 'm';
50
- if (size === 'm') iconSize = 'base';
51
- if (size === 'base') iconSize = 's';
52
- if (size === 's') iconSize = 'xs';
46
+ const listSize = size === 's' ? 's' : 'base';
53
47
 
54
48
  // For items with sublabel we need more space
55
49
  let boxSize: BoxSize = size || 'm';
56
50
  if (item.subLabel && (size === 's' || size === 'xs')) boxSize = 'base';
57
51
 
58
- return (
59
- <SilkeBox
60
- ref={ref}
61
- role="option"
62
- height={boxSize}
63
- hPad={ItemRender || item.icon || item.image ? undefined : 's'}
64
- bg={highlight ? 'surface-2' : undefined}
65
- bgHover={isDisabled ? undefined : 'surface-2'}
66
- vAlign="center"
67
- gap={item.icon || item.image ? 'xxs' : 'xs'}
68
- rounded={size === 's' ? 'tiny' : 'small'}
69
- className={cl}
70
- onMouseDown={
71
- isDisabled ? (e: React.MouseEvent<HTMLButtonElement>) => e.preventDefault() : onMouseDown
72
- }
73
- >
74
- {ItemRender ? (
52
+ if (ItemRender) {
53
+ return (
54
+ <SilkeBox
55
+ ref={ref}
56
+ role="option"
57
+ height={boxSize}
58
+ bg={highlight ? 'surface-2' : undefined}
59
+ bgHover={isDisabled ? undefined : 'surface-2'}
60
+ vAlign="center"
61
+ gap={item.icon || item.image ? 'xxs' : 'xs'}
62
+ rounded={size === 's' ? 'tiny' : 'small'}
63
+ className={styles.autocompleteItem}
64
+ onMouseDown={
65
+ isDisabled ? (e: React.MouseEvent<HTMLButtonElement>) => e.preventDefault() : onMouseDown
66
+ }
67
+ >
75
68
  <ItemRender highlight={highlight} selected={selected} item={item} isDisabled={isDisabled} />
76
- ) : (
77
- <>
78
- {multiple && (
79
- <SilkeBox size="s" align="center">
80
- <SilkeCheckbox value={selected} style={{ pointerEvents: 'none' }} />
81
- </SilkeBox>
82
- )}
69
+ </SilkeBox>
70
+ );
71
+ }
83
72
 
84
- {item.image && (
85
- <SilkeBox size={iconSize} align="center" pad="xs">
86
- <SilkeIcon icon={{ type: EmojiType.upload, value: { url: item.image } }} />
87
- </SilkeBox>
88
- )}
73
+ const itemIcon = item.image
74
+ ? <SilkeIcon icon={{ type: EmojiType.upload, value: { url: item.image } }} />
75
+ : item.icon;
89
76
 
90
- {item.icon && (
91
- <SilkeBox size={iconSize} align="center">
92
- <SilkeIcon icon={item.icon} style={{ fontSize: iconFontSize }} />
93
- </SilkeBox>
94
- )}
95
-
96
- <SilkeBox column>
97
- <SilkeText
98
- size={size === 's' ? 'small' : undefined}
99
- tag={size === 's' ? 'small' : undefined}
100
- overflow
101
- color={isDisabled ? 'neutral-40' : undefined}
102
- >
103
- {label}
104
- </SilkeText>
105
- {item.subLabel && (
106
- <SilkeTextMicro overflow color="neutral-60">
107
- {item.subLabel}
108
- </SilkeTextMicro>
109
- )}
110
- </SilkeBox>
111
- </>
112
- )}
77
+ const icon = multiple ? (
78
+ <SilkeBox vAlign="center" gap="xs">
79
+ <SilkeCheckbox value={selected} style={{ pointerEvents: 'none' }} />
80
+ {itemIcon && (React.isValidElement(itemIcon)
81
+ ? itemIcon
82
+ : <SilkeIcon icon={itemIcon} />)}
113
83
  </SilkeBox>
84
+ ) : itemIcon;
85
+
86
+ return (
87
+ <div ref={ref}>
88
+ <SilkeListItem
89
+ role="option"
90
+ label={label}
91
+ subLabel={item.subLabel}
92
+ icon={icon}
93
+ size={listSize}
94
+ active={selected}
95
+ highlight={highlight}
96
+ disabled={isDisabled}
97
+ onMouseDown={onMouseDown as any}
98
+ />
99
+ </div>
114
100
  );
115
101
  }
@@ -77,11 +77,17 @@ export type SilkeAutocompleteFieldNativeProps<T = any, U extends Entry<T> = any>
77
77
  * Custom sort of items (default sorts by label)
78
78
  */
79
79
  sort?: (one: Entry<T>, other: Entry<T>) => number;
80
+
81
+ searchPlaceholder?: string;
80
82
  onSearch?: (value: string) => void;
81
83
  /**
82
84
  * Called when dropdown closes for any reason
83
85
  */
84
86
  onClose?: () => void;
87
+ /**
88
+ * Always show reset when a value is selected
89
+ */
90
+ showReset?: boolean;
85
91
  };
86
92
 
87
93
  const autocompleteValidator: FormValidator<SilkeAutocompleteFieldNativeProps> = (props, value) => {
@@ -142,7 +148,11 @@ export function SilkeAutocompleteFieldNative<T>(props: SilkeAutocompleteFieldNat
142
148
  if (form.multiple) return [];
143
149
  const entry = items.find((entry) => !entry.divider && isEqual(entry.value, form.value));
144
150
 
145
- return [entry?.label || (form.value && form.value.toString()) || '', entry?.icon, entry?.image];
151
+ const fallbackLabel =
152
+ form.value !== null && form.value !== undefined && typeof form.value !== 'object'
153
+ ? String(form.value)
154
+ : '';
155
+ return [entry?.label || fallbackLabel, entry?.icon, entry?.image];
146
156
  }, [items, form.multiple, form.value]);
147
157
 
148
158
  const containerRef = useRef<HTMLDivElement>(null);
@@ -196,7 +206,8 @@ export function SilkeAutocompleteFieldNative<T>(props: SilkeAutocompleteFieldNat
196
206
  };
197
207
 
198
208
  const displayReset =
199
- props.multiple && !form.noReset && Array.isArray(form.value) && form.value.length > 0;
209
+ (props.multiple && !form.noReset && Array.isArray(form.value) && form.value.length > 0) ||
210
+ (!props.multiple && props?.showReset && form.value);
200
211
  const dataCy = props['data-cy'] || undefined;
201
212
  const kind = props?.kind || context.kind || 'default';
202
213
 
@@ -175,9 +175,11 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
175
175
  const kind = props?.kind || context.kind || 'default';
176
176
 
177
177
  const boxSize: BoxSize = size === 's' ? 's' : 'base';
178
+ const isCompact = kind === 'ghost' || kind === 'zombie';
178
179
  let dropDownSize = size;
179
180
  if (kind !== 'default') dropDownSize = 's';
180
181
  else if (size === 's') dropDownSize = 's';
182
+ const iconSize = size === 's' ? 's' : 'base';
181
183
 
182
184
  let cl = styles.root;
183
185
  if (open) cl += ' ' + styles.open;
@@ -234,6 +236,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
234
236
  style={{
235
237
  padding: size === 's' ? 2 : undefined,
236
238
  paddingLeft: selectedIcon || selectedImage ? 0 : undefined,
239
+ paddingRight: kind === 'ghost' || kind === 'zombie' ? 4 : undefined,
237
240
  flex: kind !== 'ghost' && kind !== 'zombie' ? undefined : 'none',
238
241
  maxWidth: `calc(100% - ${size === 's' ? 16 : 24}px)`,
239
242
  }}
@@ -260,15 +263,15 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
260
263
  />
261
264
  </SilkeBox>
262
265
  ) : (
263
- <>
266
+ <SilkeBox vAlign="center" gap="xs">
264
267
  {selectedImage && (
265
- <SilkeBox width={dropDownSize} align="center" hPad="xs">
268
+ <SilkeBox width={iconSize} align="center">
266
269
  <SilkeIcon icon={{ type: EmojiType.upload, value: { url: selectedImage } }} />
267
270
  </SilkeBox>
268
271
  )}
269
272
 
270
273
  {selectedIcon && (
271
- <SilkeBox width={dropDownSize} align="center" hPad="xs">
274
+ <SilkeBox width={iconSize} align="center">
272
275
  <SilkeIcon icon={selectedIcon} />
273
276
  </SilkeBox>
274
277
  )}
@@ -281,14 +284,14 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
281
284
  {placeholder}
282
285
  </SilkeText>
283
286
  )}
284
- </>
287
+ </SilkeBox>
285
288
  )}
286
289
  </SilkeTextFieldItem>
287
290
 
288
291
  {(displayReset || !hideListArrow) && (
289
292
  <SilkeTextFieldItem
290
293
  align="center"
291
- width={dropDownSize}
294
+ width={kind === 'ghost' || kind === 'zombie' ? 'xs' : dropDownSize}
292
295
  className={styles.downIcon}
293
296
  onClick={displayReset ? handleReset : undefined}
294
297
  >
@@ -167,7 +167,8 @@ export function SilkeAutocompletePopupNative<T>(props: SilkeAutocompletePopupNat
167
167
  const [selectedLabel] = useMemo((): [label?: string] => {
168
168
  if (form.multiple) return [];
169
169
  const entry = items.find((entry) => !entry.divider && isEqual(entry.value, form.value));
170
- return [entry?.label || (form.value && form.value.toString()) || ''];
170
+ const fallbackLabel = form.value !== null && form.value !== undefined && typeof form.value !== 'object' ? String(form.value) : '';
171
+ return [entry?.label || fallbackLabel];
171
172
  }, [items, form.multiple, form.value]);
172
173
 
173
174
  const [searchText, _setSearchText] = useState<undefined | string>();
@@ -28,6 +28,10 @@ input {
28
28
  height: 100%;
29
29
  }
30
30
 
31
+ .border {
32
+ border: 1px solid var(--color-surface-2);
33
+ }
34
+
31
35
  .scroll {
32
36
  overflow-y: auto;
33
37
  overflow-x: hidden;
@@ -87,6 +87,8 @@ type BaseProps = {
87
87
 
88
88
  /** Text color on hover */
89
89
  colorHover?: SilkeColor;
90
+ /** Adds a 1px border using surface-2 color */
91
+ border?: boolean;
90
92
  aspectRatio?: '16:9' | '4:3' | '1:1';
91
93
  /** Flex item */
92
94
  flex?: boolean;
@@ -223,6 +225,7 @@ function BoxComp(
223
225
  debug,
224
226
  scroll,
225
227
  rounded,
228
+ border,
226
229
  shadow,
227
230
  overflow,
228
231
  cursor,
@@ -235,6 +238,7 @@ function BoxComp(
235
238
  if (className) cl.push(className);
236
239
 
237
240
  if (column) cl.push(styles.column);
241
+ if (border) cl.push(styles.border);
238
242
  if (flex) cl.push(styles.flex);
239
243
  if (fill) cl.push(styles.fill);
240
244
  if (overflow) cl.push(styles['overflow-' + overflow]);
@@ -13,6 +13,8 @@ export type SilkeDropdownButtonProps = {
13
13
  animate?: boolean;
14
14
  size?: 's' | 'base';
15
15
  closeOnSelect?: boolean;
16
+ /** Max height (px) of the dropdown list before it scrolls. Defaults to 400. */
17
+ maxHeight?: number;
16
18
  } & SilkeButtonProps &
17
19
  Omit<SilkePopoverProps, 'anchor' | 'hide' | 'children' | 'kind'>;
18
20
 
@@ -27,6 +29,7 @@ export function SilkeDropdownButton({
27
29
  size = 'base',
28
30
  animate = false,
29
31
  closeOnSelect = false,
32
+ maxHeight = 400,
30
33
  ...rest
31
34
  }: SilkeDropdownButtonProps) {
32
35
  const [isOpen, setIsOpen] = useState(false);
@@ -61,7 +64,7 @@ export function SilkeDropdownButton({
61
64
  <SilkeList
62
65
  items={items || []}
63
66
  size={size}
64
- maxHeight={400}
67
+ maxHeight={maxHeight}
65
68
  onSelect={() => closeOnSelect && setIsOpen(false)}
66
69
  />
67
70
  </SilkePopoverNative>
@@ -86,6 +86,10 @@ body {
86
86
  left: 8px;
87
87
  }
88
88
 
89
+ &.imgContain .imageWrapper img {
90
+ object-fit: contain;
91
+ }
92
+
89
93
  .img {
90
94
  width: 100%;
91
95
  height: 100%;
@@ -15,6 +15,7 @@ type SilkeCardProps = {
15
15
  title: React.ReactNode;
16
16
  subTitle?: React.ReactNode;
17
17
  image?: string | React.ReactElement | string[];
18
+ imageFit?: 'cover' | 'contain';
18
19
  autoFocus?: boolean;
19
20
  text?: string;
20
21
  customTags?: React.ReactNode;
@@ -46,6 +47,7 @@ export const SilkeCard = React.forwardRef(
46
47
  (
47
48
  {
48
49
  image,
50
+ imageFit,
49
51
  title,
50
52
  subTitle,
51
53
  text,
@@ -73,6 +75,7 @@ export const SilkeCard = React.forwardRef(
73
75
  if (tags?.length) cl += ' ' + styles.hasTags;
74
76
  if (checked) cl += ' ' + styles.checked;
75
77
  if (selected) cl += ' ' + styles.selected;
78
+ if (imageFit === 'contain') cl += ' ' + styles.imgContain;
76
79
 
77
80
  return (
78
81
  <SilkeBox
@@ -13,6 +13,7 @@ export { fileToImageValue, imageValueToDataUrl } from './image-utils';
13
13
  export { parseTextToSilkeCommands } from './silke-command-parser';
14
14
  export * from './silke-command-text-field';
15
15
  export {
16
+ getCommandLabel,
16
17
  SilkeCommand,
17
18
  SilkeCommandTextFieldValue,
18
19
  SilkeCommandType,
@@ -87,3 +87,58 @@ describe('parseTextToCommands', () => {
87
87
  expect(result).toEqual([{ partialMatch: true, type: '@', value: 'USER' }]);
88
88
  });
89
89
  });
90
+
91
+ describe('parseTextToSilkeCommands with labelled commands', () => {
92
+ // A mention whose value is an opaque id but which renders as a display name
93
+ const labelled: SilkeCommand[] = [
94
+ { type: SilkeCommandType.MENTION, value: 'uid-1', label: 'Nicolay Hansen' },
95
+ { type: SilkeCommandType.MENTION, value: 'uid-2', label: 'Nicolay Hansen-Berg' },
96
+ { type: SilkeCommandType.MENTION, value: 'uid-3', label: 'Ada' },
97
+ ];
98
+
99
+ test('matches a label containing a space back to its value', () => {
100
+ const result = parseTextToSilkeCommands('Hi @Nicolay Hansen how are you', labelled);
101
+ expect(result).toEqual([
102
+ { type: 'text', value: 'Hi ' },
103
+ { type: '@', value: 'uid-1', label: 'Nicolay Hansen' },
104
+ { type: 'text', value: ' how are you' },
105
+ ]);
106
+ });
107
+
108
+ test('prefers the longest label when two labels share a prefix', () => {
109
+ const result = parseTextToSilkeCommands('@Nicolay Hansen-Berg', labelled);
110
+ expect(result).toEqual([{ type: '@', value: 'uid-2', label: 'Nicolay Hansen-Berg' }]);
111
+ });
112
+
113
+ test('normalizes the non-breaking spaces the field renders labels with', () => {
114
+ const result = parseTextToSilkeCommands('@Nicolay\u00A0Hansen', labelled);
115
+ expect(result).toEqual([{ type: '@', value: 'uid-1', label: 'Nicolay Hansen' }]);
116
+ });
117
+
118
+ test('parses several labelled mentions in one string', () => {
119
+ const result = parseTextToSilkeCommands('@Ada and @Nicolay Hansen', labelled);
120
+ expect(result).toEqual([
121
+ { type: '@', value: 'uid-3', label: 'Ada' },
122
+ { type: 'text', value: ' and ' },
123
+ { type: '@', value: 'uid-1', label: 'Nicolay Hansen' },
124
+ ]);
125
+ });
126
+
127
+ test('reports a partial match while the label is still being typed', () => {
128
+ const result = parseTextToSilkeCommands('@Nico', labelled);
129
+ expect(result).toEqual([{ partialMatch: true, type: '@', value: 'Nico' }]);
130
+ });
131
+
132
+ test('keeps the label when a command is matched by its value', () => {
133
+ const result = parseTextToSilkeCommands('@uid-1', labelled);
134
+ expect(result).toEqual([{ type: '@', value: 'uid-1', label: 'Nicolay Hansen' }]);
135
+ });
136
+
137
+ test('leaves text after a labelled mention intact', () => {
138
+ const result = parseTextToSilkeCommands('@Ada, hello', labelled);
139
+ expect(result).toEqual([
140
+ { type: '@', value: 'uid-3', label: 'Ada' },
141
+ { type: 'text', value: ', hello' },
142
+ ]);
143
+ });
144
+ });
@@ -1,4 +1,9 @@
1
- import { SilkeCommand, SilkeCommandTextFieldValue, SilkeCommandType } from './utils';
1
+ import {
2
+ getCommandLabel,
3
+ SilkeCommand,
4
+ SilkeCommandTextFieldValue,
5
+ SilkeCommandType,
6
+ } from './utils';
2
7
 
3
8
  /** Parse raw text into structured command values */
4
9
  export function parseTextToSilkeCommands(
@@ -10,6 +15,16 @@ export function parseTextToSilkeCommands(
10
15
 
11
16
  const result: SilkeCommandTextFieldValue[] = [];
12
17
  let lastIndex = 0;
18
+ // Length of the '@' or '/' that introduces a command
19
+ const prefixLength = 1;
20
+
21
+ // Commands rendering a custom label are matched by that label rather than by
22
+ // their value, so a label containing spaces or capitals still round-trips
23
+ // through the field's own rendered text. Longest first, so that of two labels
24
+ // sharing a prefix the more specific one wins.
25
+ const labelledCommands = availableCommands
26
+ .filter((cmd) => cmd.label)
27
+ .sort((a, b) => getCommandLabel(b).length - getCommandLabel(a).length);
13
28
 
14
29
  // Match @ or / at start of string or after whitespace, followed by alphanumeric, underscore, or hyphen
15
30
  const commandRegexp = /(^|[\s])(@|\/)([a-z0-9_-]*)/gi;
@@ -25,14 +40,30 @@ export function parseTextToSilkeCommands(
25
40
  }
26
41
 
27
42
  const commandType = type as SilkeCommandType;
43
+ const labelled = labelledCommands.find(
44
+ (cmd) =>
45
+ cmd.type === commandType &&
46
+ normalizedText.startsWith(getCommandLabel(cmd), commandStart + prefixLength),
47
+ );
48
+
49
+ if (labelled) {
50
+ result.push({ type: commandType, value: labelled.value, label: labelled.label });
51
+ lastIndex = commandStart + prefixLength + getCommandLabel(labelled).length;
52
+ // The regexp stopped at the end of [a-z0-9_-]*, which is not where the
53
+ // label ends; resume scanning from the label instead
54
+ commandRegexp.lastIndex = lastIndex;
55
+ continue;
56
+ }
57
+
28
58
  const commandValue = value;
29
59
 
30
60
  // Check if this is a complete command (exists in availableCommands)
31
- const foundCommand = availableCommands.some(
61
+ const foundCommand = availableCommands.find(
32
62
  (cmd) => cmd.type === commandType && cmd.value === commandValue,
33
63
  );
34
64
 
35
65
  const command: SilkeCommand = { type: commandType, value: commandValue };
66
+ if (foundCommand?.label) command.label = foundCommand.label;
36
67
  if (!foundCommand) command.partialMatch = true;
37
68
  result.push(command);
38
69
  lastIndex = match.index + match[0].length;
@@ -90,6 +90,9 @@
90
90
  display: flex;
91
91
  align-items: flex-end;
92
92
  flex-wrap: wrap;
93
+ // Anchors .placeholder to the text row. Against .container it overlapped whatever rows sit
94
+ // above the text (attachments, chips) whenever the field was empty.
95
+ position: relative;
93
96
  }
94
97
 
95
98
  .textfield {
@@ -36,6 +36,7 @@ import {
36
36
  getItemLength,
37
37
  getTextLength,
38
38
  hasSelectionLength,
39
+ insertCharacterAtCommandBoundary,
39
40
  isAttachment,
40
41
  isSilkeCommand,
41
42
  isText,
@@ -53,6 +54,14 @@ export type SilkeCommandTextFieldProps = SilkeTextFieldOutlineProps & {
53
54
  acceptedFileTypes?: SilkeFileCategory[];
54
55
  autoFocus?: boolean;
55
56
  availableCommands: SilkeCommand[];
57
+ /**
58
+ * Chips shown inside the field, above the text, on their own row.
59
+ *
60
+ * Placed here rather than passed as `children` (which land after the text, where the absolutely
61
+ * positioned placeholder sits) so a chip stays legible on an empty field and does not move as
62
+ * the text wraps.
63
+ */
64
+ chips?: React.ReactNode;
56
65
  disabled?: boolean;
57
66
  /** Maximum height in pixels before the field starts scrolling */
58
67
  maxHeight?: number;
@@ -95,6 +104,7 @@ const SilkeCommandTextField = React.forwardRef<
95
104
  acceptedFileTypes,
96
105
  autoFocus = false,
97
106
  availableCommands,
107
+ chips,
98
108
  disabled = false,
99
109
  maxHeight,
100
110
  onChange,
@@ -386,7 +396,6 @@ const SilkeCommandTextField = React.forwardRef<
386
396
  (
387
397
  e: React.KeyboardEvent,
388
398
  commandIndex: number,
389
- commandItem: SilkeCommandTextFieldValue,
390
399
  currentValue: SilkeCommandTextFieldValue[],
391
400
  ) => {
392
401
  const element = inputRef.current;
@@ -397,50 +406,20 @@ const SilkeCommandTextField = React.forwardRef<
397
406
 
398
407
  const currentCaretPos = getCaretOffset(element);
399
408
  const startOfCommand = getTextLength(currentValue, commandIndex);
400
- const itemLength = getItemLength(commandItem);
401
409
  const localOffset = currentCaretPos - startOfCommand;
402
410
 
403
411
  e.preventDefault();
404
412
 
405
- const newValue = [...currentValue];
413
+ const result = insertCharacterAtCommandBoundary(
414
+ currentValue,
415
+ commandIndex,
416
+ localOffset,
417
+ e.key,
418
+ );
419
+ if (!result) return;
406
420
 
407
- if (localOffset <= 0) {
408
- // At start of command - insert text before
409
- const prevItem = newValue[commandIndex - 1];
410
- if (commandIndex > 0 && isText(prevItem)) {
411
- // Append to previous text segment
412
- newValue[commandIndex - 1] = {
413
- type: 'text',
414
- value: prevItem.value + e.key,
415
- };
416
- setActiveCommand({
417
- index: commandIndex - 1,
418
- localOffset: prevItem.value.length + 1,
419
- });
420
- } else {
421
- // Insert new text segment before command
422
- newValue.splice(commandIndex, 0, { type: 'text', value: e.key });
423
- setActiveCommand({ index: commandIndex, localOffset: 1 });
424
- }
425
- onChange(newValue);
426
- } else if (localOffset >= itemLength) {
427
- // At end of command - insert text after
428
- const nextItem = newValue[commandIndex + 1];
429
- if (commandIndex < newValue.length - 1 && isText(nextItem)) {
430
- // Prepend to next text segment
431
- newValue[commandIndex + 1] = {
432
- type: 'text',
433
- value: e.key + nextItem.value,
434
- };
435
- setActiveCommand({ index: commandIndex + 1, localOffset: 1 });
436
- } else {
437
- // Insert new text segment after command
438
- newValue.splice(commandIndex + 1, 0, { type: 'text', value: e.key });
439
- setActiveCommand({ index: commandIndex + 1, localOffset: 1 });
440
- }
441
- onChange(newValue);
442
- }
443
- // If inside command (not at boundary), just prevent - no insertion
421
+ setActiveCommand({ index: result.index, localOffset: result.localOffset });
422
+ onChange(result.value);
444
423
  },
445
424
  [onChange],
446
425
  );
@@ -529,7 +508,7 @@ const SilkeCommandTextField = React.forwardRef<
529
508
  // If at boundary (localOffset = 0 or itemLength), let browser handle
530
509
  break;
531
510
  default:
532
- handleCharacterInput(e, commandIndex, commandItem, currentValue);
511
+ handleCharacterInput(e, commandIndex, currentValue);
533
512
  }
534
513
  },
535
514
  [disabled, handleArrowNavigation, handleCharacterInput, handleDelete, onKeyDown],
@@ -573,17 +552,42 @@ const SilkeCommandTextField = React.forwardRef<
573
552
 
574
553
  const handlePaste = useCallback(
575
554
  (e: React.ClipboardEvent<HTMLDivElement>) => {
576
- if (filesDisabled) return;
555
+ if (!filesDisabled) {
556
+ const file = getFileFromClipboard(e, effectiveAcceptedTypes);
557
+ if (file) {
558
+ e.preventDefault();
559
+ fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
560
+ if (attachmentValue) addAttachment(attachmentValue);
561
+ });
562
+ return;
563
+ }
564
+ }
577
565
 
578
- const file = getFileFromClipboard(e, effectiveAcceptedTypes);
579
- if (!file) return;
566
+ // Paste text as plain text. This is a contenteditable, so the browser's default paste
567
+ // inserts the clipboard's HTML — nested elements, styles and all — and `handleInput` reads
568
+ // the result back with `innerText`, which mangles anything richer than a single run of
569
+ // text. Copying a line out of the chat above and pasting it here landed a single word.
570
+ const text = e.clipboardData?.getData('text/plain');
571
+ if (!text) return;
580
572
 
581
573
  e.preventDefault();
582
- fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
583
- if (attachmentValue) addAttachment(attachmentValue);
584
- });
574
+ // execCommand is deprecated but remains the only insertion that keeps the caret position
575
+ // and the browser's native undo stack intact; the Range path below is the fallback.
576
+ if (!document.execCommand('insertText', false, text)) {
577
+ const selection = window.getSelection();
578
+ if (!selection?.rangeCount) return;
579
+ const range = selection.getRangeAt(0);
580
+ range.deleteContents();
581
+ range.insertNode(document.createTextNode(text));
582
+ range.collapse(false);
583
+ selection.removeAllRanges();
584
+ selection.addRange(range);
585
+ }
586
+
587
+ // execCommand fires `input`, the manual path does not, so re-parse from the DOM either way.
588
+ handleInput({ currentTarget: e.currentTarget } as React.FormEvent<HTMLDivElement>);
585
589
  },
586
- [addAttachment, effectiveAcceptedTypes, filesDisabled],
590
+ [addAttachment, effectiveAcceptedTypes, filesDisabled, handleInput],
587
591
  );
588
592
 
589
593
  const containerRef = useRef<HTMLDivElement>(null);
@@ -621,6 +625,7 @@ const SilkeCommandTextField = React.forwardRef<
621
625
  onRemove={removeAttachment}
622
626
  />
623
627
  )}
628
+ {chips && <div className={styles.attachmentList}>{chips}</div>}
624
629
  <div className={styles.textfieldRow}>
625
630
  <div
626
631
  aria-disabled={disabled}