@vev/silke 1.1.8 → 1.1.10

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 (96) hide show
  1. package/.turbo/turbo-build.log +800 -0
  2. package/CHANGELOG.md +17 -0
  3. package/CLAUDE.md +102 -0
  4. package/dist/index.js +44 -40
  5. package/dist/index.js.LEGAL.txt +1 -1
  6. package/dist/styles.css +470 -254
  7. package/dist/types/components/index.d.ts +2 -0
  8. package/dist/types/components/silke-command-text-field/attachment-chip.d.ts +8 -0
  9. package/dist/types/components/silke-command-text-field/attachment-list.d.ts +15 -0
  10. package/dist/types/components/silke-command-text-field/file-utils.d.ts +33 -0
  11. package/dist/types/components/silke-command-text-field/file-utils.spec.d.ts +1 -0
  12. package/dist/types/components/silke-command-text-field/index.d.ts +6 -1
  13. package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +23 -6
  14. package/dist/types/components/silke-command-text-field/utils.d.ts +14 -1
  15. package/dist/types/components/silke-conditions-input/utils.d.ts +1 -1
  16. package/dist/types/components/silke-css-number-field/silke-css-context.d.ts +2 -0
  17. package/dist/types/components/silke-css-number-field/silke-css-number-field.d.ts +2 -0
  18. package/dist/types/components/silke-css-number-field/utils.d.ts +1 -1
  19. package/dist/types/components/silke-form-schema/fields/group-field.d.ts +3 -0
  20. package/dist/types/components/silke-form-schema/fields/object-field.d.ts +1 -1
  21. package/dist/types/components/silke-form-schema/fields/popover-field.d.ts +3 -0
  22. package/dist/types/components/silke-form-schema/fields/utils/generate-image.d.ts +5 -0
  23. package/dist/types/components/silke-form-schema/fields/utils/index.d.ts +1 -1
  24. package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
  25. package/dist/types/components/silke-gradient-picker/index.d.ts +3 -0
  26. package/dist/types/components/silke-icon/silke-icon.d.ts +1 -1
  27. package/dist/types/components/silke-list/silke-list.d.ts +6 -1
  28. package/dist/types/components/silke-list/types.d.ts +2 -0
  29. package/dist/types/components/silke-shortcut-button/silke-shortcut-button.d.ts +4 -1
  30. package/dist/types/components/silke-theme-card/index.d.ts +1 -0
  31. package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +18 -0
  32. package/dist/types/components/silke-theme-swatch/index.d.ts +1 -0
  33. package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +11 -0
  34. package/dist/types/icons.d.ts +7 -2
  35. package/package.json +32 -20
  36. package/src/components/index.ts +2 -0
  37. package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +25 -18
  38. package/src/components/silke-button/silke-dropdown-button.mdx +1 -1
  39. package/src/components/silke-color-picker/color.ts +5 -3
  40. package/src/components/silke-color-swatches/silke-swatches.tsx +3 -3
  41. package/src/components/silke-command-text-field/attachment-chip.tsx +71 -0
  42. package/src/components/silke-command-text-field/attachment-list.tsx +72 -0
  43. package/src/components/silke-command-text-field/file-utils.spec.ts +148 -0
  44. package/src/components/silke-command-text-field/file-utils.ts +159 -0
  45. package/src/components/silke-command-text-field/index.ts +14 -0
  46. package/src/components/silke-command-text-field/silke-command-text-field.mdx +109 -13
  47. package/src/components/silke-command-text-field/silke-command-text-field.module.scss +65 -40
  48. package/src/components/silke-command-text-field/silke-command-text-field.tsx +113 -135
  49. package/src/components/silke-command-text-field/utils.spec.ts +109 -1
  50. package/src/components/silke-command-text-field/utils.ts +44 -7
  51. package/src/components/silke-css-number-field/silke-css-context.tsx +2 -0
  52. package/src/components/silke-css-number-field/silke-css-number-field.tsx +7 -4
  53. package/src/components/silke-css-number-field/utils.ts +8 -2
  54. package/src/components/silke-form-schema/fields/array-field-modal.tsx +69 -48
  55. package/src/components/silke-form-schema/fields/array-field.tsx +144 -130
  56. package/src/components/silke-form-schema/fields/color-field.tsx +118 -18
  57. package/src/components/silke-form-schema/fields/group-field.tsx +49 -0
  58. package/src/components/silke-form-schema/fields/icon-field.tsx +59 -39
  59. package/src/components/silke-form-schema/fields/image-field.tsx +50 -39
  60. package/src/components/silke-form-schema/fields/number-field.tsx +190 -116
  61. package/src/components/silke-form-schema/fields/object-field.tsx +2 -0
  62. package/src/components/silke-form-schema/fields/popover-field.tsx +65 -0
  63. package/src/components/silke-form-schema/fields/select-field.tsx +43 -30
  64. package/src/components/silke-form-schema/fields/string-field.tsx +1 -1
  65. package/src/components/silke-form-schema/fields/styles.scss +2 -39
  66. package/src/components/silke-form-schema/fields/toggle-field.tsx +48 -15
  67. package/src/components/silke-form-schema/fields/utils/generate-image.ts +20 -0
  68. package/src/components/silke-form-schema/fields/utils/generate-title.ts +1 -1
  69. package/src/components/silke-form-schema/fields/utils/index.ts +1 -1
  70. package/src/components/silke-form-schema/silke-form-schema.mdx +498 -311
  71. package/src/components/silke-form-schema/silke-schema-field.tsx +10 -3
  72. package/src/components/silke-form-schema/silke-schema-fields.tsx +9 -5
  73. package/src/components/silke-gradient-picker/index.ts +3 -0
  74. package/src/components/silke-icon/silke-icon.mdx +13 -1
  75. package/src/components/silke-icon/silke-icon.tsx +6 -2
  76. package/src/components/silke-list/silke-list.tsx +59 -26
  77. package/src/components/silke-list/types.ts +2 -0
  78. package/src/components/silke-navigation-link/silke-navigation-link.scss +1 -0
  79. package/src/components/silke-shortcut-button/silke-shortcut-button.scss +16 -0
  80. package/src/components/silke-shortcut-button/silke-shortcut-button.tsx +9 -0
  81. package/src/components/silke-slider/silke-slider.module.scss +1 -1
  82. package/src/components/silke-text-field/silke-text-field-outline.tsx +9 -6
  83. package/src/components/silke-text-field/silke-text-field.scss +3 -0
  84. package/src/components/silke-text-field/silke-text-field.tsx +1 -1
  85. package/src/components/silke-theme-card/index.ts +1 -0
  86. package/src/components/silke-theme-card/silke-theme-card.mdx +50 -0
  87. package/src/components/silke-theme-card/silke-theme-card.module.scss +82 -0
  88. package/src/components/silke-theme-card/silke-theme-card.tsx +82 -0
  89. package/src/components/silke-theme-swatch/index.ts +1 -0
  90. package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +59 -0
  91. package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +108 -0
  92. package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +49 -0
  93. package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +9 -8
  94. package/src/icons.tsx +41 -7
  95. package/tsconfig.build.tsbuildinfo +1 -1
  96. package/project.json +0 -12
@@ -1,24 +1,50 @@
1
1
  .container {
2
2
  flex: 1;
3
3
  min-height: 32px;
4
- overflow: hidden;
4
+ overflow-x: hidden;
5
+ overflow-y: auto;
5
6
  position: relative;
6
7
  }
7
8
 
8
- .imageList {
9
+ .attachmentList {
9
10
  display: flex;
10
- flex-wrap: wrap;
11
11
  gap: 8px;
12
- padding: 8px 4px;
12
+ overflow-x: auto;
13
+ scrollbar-width: none;
14
+
15
+ &::-webkit-scrollbar {
16
+ display: none;
17
+ }
13
18
  }
14
19
 
15
- .imageThumbnail {
16
- position: relative;
17
- width: 48px;
18
- height: 48px;
20
+ .attachmentChip {
21
+ display: flex;
22
+ align-items: center;
23
+ gap: 6px;
24
+ height: 32px;
25
+ padding: 0 4px 0 8px;
26
+ border-radius: var(--border-radius-small);
27
+ background-color: rgba(var(--color-neutral-40-rgb), var(--opacity-level-light));
28
+ color: var(--color-neutral-80);
29
+ font-size: 12px;
30
+ flex-shrink: 0;
31
+ cursor: default;
32
+
33
+ &:hover {
34
+ background-color: rgba(var(--color-neutral-40-rgb), var(--opacity-level-medium));
35
+ }
36
+ }
37
+
38
+ .imageChip {
39
+ padding-left: 4px;
40
+ }
41
+
42
+ .chipThumbnail {
43
+ width: 24px;
44
+ height: 24px;
19
45
  border-radius: var(--border-radius-tiny);
20
46
  overflow: hidden;
21
- background-color: var(--color-neutral-20);
47
+ flex-shrink: 0;
22
48
  cursor: pointer;
23
49
 
24
50
  img {
@@ -26,47 +52,28 @@
26
52
  height: 100%;
27
53
  object-fit: cover;
28
54
  }
29
-
30
- &:hover {
31
- opacity: 0.9;
32
- }
33
55
  }
34
56
 
35
- .imageRemove {
36
- opacity: 0;
37
- transition: opacity 0.15s ease;
38
-
39
- .imageThumbnail:hover & {
40
- opacity: 1;
41
- }
57
+ .chipName {
58
+ overflow: hidden;
59
+ text-overflow: ellipsis;
60
+ white-space: nowrap;
61
+ max-width: 120px;
42
62
  }
43
63
 
44
- .imagePreviewOverlay {
45
- position: fixed;
46
- top: 0;
47
- left: 0;
48
- right: 0;
49
- bottom: 0;
50
- background-color: rgba(0, 0, 0, 0.7);
51
- display: flex;
52
- align-items: center;
53
- justify-content: center;
54
- z-index: 1000;
55
- cursor: pointer;
64
+ .chipRemove {
65
+ flex-shrink: 0;
56
66
  }
57
67
 
58
68
  .imagePreview {
59
- position: relative;
60
- max-width: 90vw;
61
- max-height: 90vh;
62
- cursor: default;
63
-
64
69
  img {
65
- max-width: 100%;
70
+ width: 1080px;
71
+ height: 1080px;
72
+ max-width: 90vw;
66
73
  max-height: 90vh;
67
74
  object-fit: contain;
68
75
  border-radius: var(--border-radius-small);
69
- box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
76
+ display: block;
70
77
  }
71
78
  }
72
79
 
@@ -79,13 +86,23 @@
79
86
  user-select: none;
80
87
  }
81
88
 
89
+ .textfieldRow {
90
+ display: flex;
91
+ align-items: flex-end;
92
+ flex-wrap: wrap;
93
+ }
94
+
82
95
  .textfield {
83
96
  border: none;
84
97
  height: 100%;
98
+ flex: 1;
99
+ max-width: 100%;
100
+ min-width: 0;
85
101
  outline: none;
102
+ overflow-y: auto;
103
+ overscroll-behavior: contain;
86
104
  padding: 4px 4px;
87
105
  white-space: pre-wrap;
88
- width: 100%;
89
106
  word-break: break-word;
90
107
 
91
108
  &[aria-disabled='true'] {
@@ -93,6 +110,14 @@
93
110
  opacity: 0.5;
94
111
  }
95
112
  }
113
+
114
+ .fileInput {
115
+ height: 0;
116
+ opacity: 0;
117
+ position: absolute;
118
+ width: 0;
119
+ }
120
+
96
121
  .tag {
97
122
  display: inline-block;
98
123
  line-height: 1;
@@ -7,46 +7,55 @@ import React, {
7
7
  useRef,
8
8
  useState,
9
9
  } from 'react';
10
- import { useDropZone } from '../../hooks/use-drop-zone';
11
10
  import { useFormField } from '../../hooks/form';
12
- import { SilkeButton } from '../silke-button';
11
+ import { useDropZone } from '../../hooks/use-drop-zone';
13
12
  import {
14
13
  SilkeTextFieldOutline,
15
14
  SilkeTextFieldOutlineProps,
16
15
  } from '../silke-text-field/silke-text-field-outline';
16
+ import { AttachmentList, AttachmentListHandle } from './attachment-list';
17
17
  import {
18
- fileToImageValue,
19
- getImageFromClipboard,
20
- getImageFromDragEvent,
21
- imageValueToDataUrl,
22
- } from './image-utils';
18
+ SilkeFileCategory,
19
+ fileToAttachmentValue,
20
+ getFileFromClipboard,
21
+ getFileFromDragEvent,
22
+ resolveFileCategories,
23
+ } from './file-utils';
23
24
  import { parseTextToSilkeCommands } from './silke-command-parser';
24
25
  import styles from './silke-command-text-field.module.scss';
25
26
  import {
27
+ KEY_DIRECTION,
28
+ SilkeCommand,
29
+ SilkeCommandTextFieldValue,
30
+ SilkeFileValue,
31
+ SilkeImageValue,
32
+ convertSilkeCommandsToString,
26
33
  filterAndSortCommands,
27
34
  getActiveCommandIndex,
28
35
  getCaretOffset,
29
36
  getItemLength,
30
37
  getTextLength,
31
38
  hasSelectionLength,
32
- isImage,
39
+ isAttachment,
33
40
  isSilkeCommand,
34
41
  isText,
35
- KEY_DIRECTION,
36
42
  setCaretOffset,
37
- SilkeCommand,
38
- SilkeCommandTextFieldValue,
39
- SilkeImageValue,
40
43
  valueToHtml,
41
- convertSilkeCommandsToString,
42
44
  } from './utils';
43
45
 
44
- export type SilkeCommandTextFieldProps = Omit<SilkeTextFieldOutlineProps, 'children'> & {
46
+ export type SilkeCommandTextFieldProps = SilkeTextFieldOutlineProps & {
47
+ /**
48
+ * File type categories to accept as attachments.
49
+ * - `'image'` — all image types (png, jpeg, gif, etc.)
50
+ * - `'text'` — documents and text files (PDF, Word, Excel, CSV, TXT, JSON, etc.)
51
+ * Defaults to `[]` (no files accepted).
52
+ */
53
+ acceptedFileTypes?: SilkeFileCategory[];
45
54
  autoFocus?: boolean;
46
55
  availableCommands: SilkeCommand[];
47
56
  disabled?: boolean;
48
- /** When true, images cannot be added via paste or drag-and-drop */
49
- disableImages?: boolean;
57
+ /** Maximum height in pixels before the field starts scrolling */
58
+ maxHeight?: number;
50
59
  name?: string;
51
60
  onChange: (value: SilkeCommandTextFieldValue[]) => void;
52
61
  onCommandFocus?: (index: number, command: SilkeCommandTextFieldValue | undefined) => void;
@@ -66,6 +75,8 @@ export type SilkeCommandTextFieldHandle = {
66
75
  blur: () => void;
67
76
  /** Focus the input */
68
77
  focus: () => void;
78
+ /** Open the file picker dialog (requires acceptedFileTypes to be set) */
79
+ openFilePicker: () => void;
69
80
  /** Get the current value as a string */
70
81
  toString: (value?: SilkeCommandTextFieldValue[]) => string;
71
82
  /**
@@ -81,30 +92,38 @@ const SilkeCommandTextField = React.forwardRef<
81
92
  SilkeCommandTextFieldProps
82
93
  >((props, ref) => {
83
94
  const {
95
+ acceptedFileTypes,
84
96
  autoFocus = false,
85
97
  availableCommands,
86
98
  disabled = false,
87
- disableImages = false,
99
+ maxHeight,
88
100
  onChange,
89
101
  onCommandFocus,
90
102
  onKeyDown,
91
103
  onSuggestions,
92
104
  placeholder,
93
105
  value,
106
+ children,
94
107
  ...rest
95
108
  } = useFormField(props);
96
109
 
97
110
  const inputRef = useRef<HTMLDivElement>(null);
111
+ const attachmentListRef = useRef<AttachmentListHandle>(null);
98
112
  const valueRef = useRef<SilkeCommandTextFieldValue[]>(value);
99
113
  valueRef.current = value;
100
114
 
101
- // Extract images from value
102
- const images = useMemo(() => value.filter(isImage), [value]);
103
- // Get non-image values for text field rendering
104
- const textValues = useMemo(() => value.filter((v) => !isImage(v)), [value]);
115
+ // Resolve file categories to MIME patterns
116
+ const effectiveAcceptedTypes = useMemo(
117
+ () => resolveFileCategories(acceptedFileTypes ?? []),
118
+ [acceptedFileTypes],
119
+ );
120
+
121
+ const filesDisabled = effectiveAcceptedTypes.length === 0;
105
122
 
106
- // Track which image is being previewed (-1 means no preview)
107
- const [previewImageIndex, setPreviewImageIndex] = useState(-1);
123
+ // Extract attachments (images + files) and text values
124
+ const attachments = useMemo(() => value.filter(isAttachment), [value]);
125
+ // Get non-attachment values for text field rendering
126
+ const textValues = useMemo(() => value.filter((v) => !isAttachment(v)), [value]);
108
127
 
109
128
  const [activeCommand, setActiveCommand] = useState<ActiveCommandState>(() => {
110
129
  const lastIndex = Math.max(0, value.length - 1);
@@ -117,14 +136,18 @@ const SilkeCommandTextField = React.forwardRef<
117
136
 
118
137
  const html = useMemo(() => valueToHtml(textValues || [], styles), [textValues]);
119
138
  const isEmpty =
120
- (!value || value.length === 0 || convertSilkeCommandsToString(value).length === 0) &&
121
- images.length === 0;
139
+ !textValues ||
140
+ textValues.length === 0 ||
141
+ convertSilkeCommandsToString(textValues).trim().length === 0;
122
142
 
123
143
  // Restore caret position after value changes
124
144
  useLayoutEffect(() => {
125
145
  const element = inputRef.current;
126
146
  if (!element || document.activeElement !== element) return;
127
147
 
148
+ // Don't collapse an active text selection (e.g. from double-click word selection)
149
+ if (hasSelectionLength()) return;
150
+
128
151
  const calculatedCaretPos =
129
152
  getTextLength(value, activeCommand.index) + activeCommand.localOffset;
130
153
  setCaretOffset(element, calculatedCaretPos);
@@ -173,6 +196,7 @@ const SilkeCommandTextField = React.forwardRef<
173
196
  () => ({
174
197
  blur: () => inputRef.current?.blur(),
175
198
  focus: focusAtEnd,
199
+ openFilePicker: () => attachmentListRef.current?.openFilePicker(),
176
200
  toString: (val = valueRef.current || []) => convertSilkeCommandsToString(val),
177
201
  update: (command, index = activeCommand.index) => {
178
202
  // If the current item is a completed command, insert after it instead of replacing
@@ -262,10 +286,10 @@ const SilkeCommandTextField = React.forwardRef<
262
286
 
263
287
  const handleInput = useCallback(
264
288
  (e: React.FormEvent<HTMLDivElement>) => {
265
- // Preserve existing images when parsing new text
266
- const existingImages = valueRef.current.filter(isImage);
289
+ // Preserve existing attachments when parsing new text
290
+ const existingAttachments = valueRef.current.filter(isAttachment);
267
291
  const parsedValue = parseTextToSilkeCommands(e.currentTarget.innerText, availableCommands);
268
- const newValue = [...existingImages, ...parsedValue];
292
+ const newValue = [...existingAttachments, ...parsedValue];
269
293
  valueRef.current = newValue;
270
294
  updateActiveCommandFromCaret(newValue);
271
295
  onChange(newValue);
@@ -511,25 +535,26 @@ const SilkeCommandTextField = React.forwardRef<
511
535
  [disabled, handleArrowNavigation, handleCharacterInput, handleDelete, onKeyDown],
512
536
  );
513
537
 
514
- const addImage = useCallback(
515
- (imageValue: SilkeImageValue) => {
516
- const newValue = [...valueRef.current, imageValue];
538
+ const addAttachment = useCallback(
539
+ (attachmentValue: SilkeImageValue | SilkeFileValue) => {
540
+ const newValue = [...valueRef.current, attachmentValue];
517
541
  onChange(newValue);
542
+ inputRef.current?.focus();
518
543
  },
519
544
  [onChange],
520
545
  );
521
546
 
522
- const removeImage = useCallback(
547
+ const removeAttachment = useCallback(
523
548
  (index: number) => {
524
- // Find the nth image in the value array and remove it
525
- let imageCount = 0;
549
+ // Find the nth attachment in the value array and remove it
550
+ let attachmentCount = 0;
526
551
  const newValue = valueRef.current.filter((item) => {
527
- if (isImage(item)) {
528
- if (imageCount === index) {
529
- imageCount++;
552
+ if (isAttachment(item)) {
553
+ if (attachmentCount === index) {
554
+ attachmentCount++;
530
555
  return false;
531
556
  }
532
- imageCount++;
557
+ attachmentCount++;
533
558
  }
534
559
  return true;
535
560
  });
@@ -538,130 +563,83 @@ const SilkeCommandTextField = React.forwardRef<
538
563
  [onChange],
539
564
  );
540
565
 
566
+ const addMultipleAttachments = useCallback(
567
+ (newAttachments: (SilkeImageValue | SilkeFileValue)[]) => {
568
+ onChange([...valueRef.current, ...newAttachments]);
569
+ inputRef.current?.focus();
570
+ },
571
+ [onChange],
572
+ );
573
+
541
574
  const handlePaste = useCallback(
542
575
  (e: React.ClipboardEvent<HTMLDivElement>) => {
543
- if (disableImages) return;
576
+ if (filesDisabled) return;
544
577
 
545
- const file = getImageFromClipboard(e);
578
+ const file = getFileFromClipboard(e, effectiveAcceptedTypes);
546
579
  if (!file) return;
547
580
 
548
581
  e.preventDefault();
549
- fileToImageValue(file).then((imageValue) => {
550
- if (imageValue) addImage(imageValue);
582
+ fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
583
+ if (attachmentValue) addAttachment(attachmentValue);
551
584
  });
552
585
  },
553
- [addImage, disableImages],
586
+ [addAttachment, effectiveAcceptedTypes, filesDisabled],
554
587
  );
555
588
 
556
589
  const containerRef = useRef<HTMLDivElement>(null);
557
590
 
558
591
  const handleDrop = useCallback(
559
592
  (e: DragEvent) => {
560
- if (disableImages) return;
593
+ if (filesDisabled) return;
561
594
 
562
- const file = getImageFromDragEvent(e);
595
+ const file = getFileFromDragEvent(e, effectiveAcceptedTypes);
563
596
  if (!file) return;
564
597
 
565
- fileToImageValue(file).then((imageValue) => {
566
- if (imageValue) addImage(imageValue);
598
+ fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
599
+ if (attachmentValue) addAttachment(attachmentValue);
567
600
  });
568
601
  },
569
- [addImage, disableImages],
602
+ [addAttachment, effectiveAcceptedTypes, filesDisabled],
570
603
  );
571
604
 
572
605
  useDropZone(containerRef, handleDrop);
573
606
 
574
607
  return (
575
608
  <SilkeTextFieldOutline {...rest}>
576
- <div className={styles.container} ref={containerRef}>
577
- {!disableImages && images.length > 0 && (
578
- <div className={styles.imageList}>
579
- {images.map((img, idx) => (
580
- <div
581
- key={idx}
582
- className={styles.imageThumbnail}
583
- onClick={() => setPreviewImageIndex(idx)}
584
- role="button"
585
- tabIndex={0}
586
- onKeyDown={(e) => {
587
- if (e.key === 'Enter' || e.key === ' ') {
588
- e.preventDefault();
589
- setPreviewImageIndex(idx);
590
- }
591
- }}
592
- >
593
- <img src={imageValueToDataUrl(img)} alt={img.name || `Image ${idx + 1}`} />
594
- {!disabled && (
595
- <SilkeButton
596
- kind="secondary"
597
- size="s"
598
- icon="close"
599
- style={{
600
- position: 'absolute',
601
- top: 2,
602
- right: 2,
603
- backdropFilter: 'blur(8px) brightness(0.7)',
604
- }}
605
- className={styles.imageRemove}
606
- onClick={(e) => {
607
- e.stopPropagation();
608
- removeImage(idx);
609
- }}
610
- aria-label={`Remove ${img.name || `image ${idx + 1}`}`}
611
- />
612
- )}
613
- </div>
614
- ))}
615
- </div>
609
+ <div
610
+ className={styles.container}
611
+ ref={containerRef}
612
+ style={maxHeight ? { maxHeight, overflowY: 'auto' } : undefined}
613
+ >
614
+ {!filesDisabled && (
615
+ <AttachmentList
616
+ ref={attachmentListRef}
617
+ acceptedTypes={effectiveAcceptedTypes}
618
+ attachments={attachments}
619
+ disabled={disabled}
620
+ onAdd={addMultipleAttachments}
621
+ onRemove={removeAttachment}
622
+ />
616
623
  )}
617
- {previewImageIndex >= 0 && images[previewImageIndex] && (
624
+ <div className={styles.textfieldRow}>
618
625
  <div
619
- className={styles.imagePreviewOverlay}
620
- onClick={() => setPreviewImageIndex(-1)}
621
- role="button"
622
- tabIndex={0}
623
- onKeyDown={(e) => {
624
- if (e.key === 'Escape' || e.key === 'Enter' || e.key === ' ') {
625
- setPreviewImageIndex(-1);
626
- }
627
- }}
628
- >
629
- <div className={styles.imagePreview} onClick={(e) => e.stopPropagation()}>
630
- <img
631
- src={imageValueToDataUrl(images[previewImageIndex])}
632
- alt={images[previewImageIndex].name || `Image ${previewImageIndex + 1}`}
633
- />
634
- <SilkeButton
635
- kind="secondary"
636
- icon="close"
637
- style={{
638
- position: 'absolute',
639
- top: 8,
640
- right: 8,
641
- backdropFilter: 'blur(8px) brightness(0.7)',
642
- }}
643
- onClick={() => setPreviewImageIndex(-1)}
644
- aria-label="Close preview"
645
- />
646
- </div>
647
- </div>
648
- )}
649
- {placeholder && isEmpty && <div className={styles.placeholder}>{placeholder}</div>}
650
- <div
651
- aria-disabled={disabled}
652
- aria-placeholder={placeholder}
653
- className={styles.textfield}
654
- contentEditable={!disabled}
655
- dangerouslySetInnerHTML={{ __html: html }}
656
- onFocus={handleFocus}
657
- onInput={handleInput}
658
- onKeyDown={handleKeyDown}
659
- onPaste={handlePaste}
660
- ref={inputRef}
661
- role="textbox"
662
- suppressContentEditableWarning
663
- tabIndex={disabled ? -1 : 0}
664
- />
626
+ aria-disabled={disabled}
627
+ aria-placeholder={placeholder}
628
+ className={styles.textfield}
629
+ contentEditable={!disabled}
630
+ dangerouslySetInnerHTML={{ __html: html }}
631
+ onFocus={handleFocus}
632
+ onInput={handleInput}
633
+ onKeyDown={handleKeyDown}
634
+ onPaste={handlePaste}
635
+ ref={inputRef}
636
+ role="textbox"
637
+ suppressContentEditableWarning
638
+ tabIndex={disabled ? -1 : 0}
639
+ />
640
+ {placeholder && isEmpty && <div className={styles.placeholder}>{placeholder}</div>}
641
+ {children}
642
+ </div>
665
643
  </div>
666
644
  </SilkeTextFieldOutline>
667
645
  );
@@ -1,17 +1,22 @@
1
1
  import {
2
+ convertSilkeCommandsToString,
2
3
  escapeHtml,
3
4
  filterAndSortCommands,
4
5
  getActiveCommandIndex,
5
6
  getCommandMatchScore,
6
7
  getItemLength,
7
8
  getTextLength,
9
+ isAttachment,
10
+ isFile,
11
+ isImage,
8
12
  isSilkeCommand,
9
13
  isText,
10
14
  SilkeCommand,
11
15
  SilkeCommandTextFieldValue,
12
16
  SilkeCommandType,
17
+ SilkeFileValue,
18
+ SilkeImageValue,
13
19
  valueToHtml,
14
- convertSilkeCommandsToString,
15
20
  } from './utils';
16
21
 
17
22
  describe('escapeHtml', () => {
@@ -364,3 +369,106 @@ describe('filterAndSortCommands', () => {
364
369
  expect(filterAndSortCommands(commands, 'xyz', SilkeCommandType.MENTION)).toEqual([]);
365
370
  });
366
371
  });
372
+
373
+ const fileValue: SilkeFileValue = {
374
+ type: 'file',
375
+ data: 'dGVzdA==',
376
+ mimeType: 'text/csv',
377
+ name: 'data.csv',
378
+ };
379
+
380
+ const imageValue: SilkeImageValue = {
381
+ type: 'image',
382
+ data: 'iVBORw0K',
383
+ mimeType: 'image/png',
384
+ name: 'photo.png',
385
+ };
386
+
387
+ describe('isFile', () => {
388
+ test('returns true for file value', () => {
389
+ expect(isFile(fileValue)).toBe(true);
390
+ });
391
+
392
+ test('returns false for image value', () => {
393
+ expect(isFile(imageValue)).toBe(false);
394
+ });
395
+
396
+ test('returns false for text value', () => {
397
+ expect(isFile({ type: 'text', value: 'hello' })).toBe(false);
398
+ });
399
+
400
+ test('returns false for command value', () => {
401
+ expect(isFile({ type: SilkeCommandType.MENTION, value: 'user' })).toBe(false);
402
+ });
403
+
404
+ test('returns false for undefined', () => {
405
+ expect(isFile(undefined)).toBe(false);
406
+ });
407
+ });
408
+
409
+ describe('isImage', () => {
410
+ test('returns true for image value', () => {
411
+ expect(isImage(imageValue)).toBe(true);
412
+ });
413
+
414
+ test('returns false for file value', () => {
415
+ expect(isImage(fileValue)).toBe(false);
416
+ });
417
+ });
418
+
419
+ describe('isAttachment', () => {
420
+ test('returns true for image value', () => {
421
+ expect(isAttachment(imageValue)).toBe(true);
422
+ });
423
+
424
+ test('returns true for file value', () => {
425
+ expect(isAttachment(fileValue)).toBe(true);
426
+ });
427
+
428
+ test('returns false for text value', () => {
429
+ expect(isAttachment({ type: 'text', value: 'hello' })).toBe(false);
430
+ });
431
+
432
+ test('returns false for command value', () => {
433
+ expect(isAttachment({ type: SilkeCommandType.MENTION, value: 'user' })).toBe(false);
434
+ });
435
+
436
+ test('returns false for undefined', () => {
437
+ expect(isAttachment(undefined)).toBe(false);
438
+ });
439
+ });
440
+
441
+ describe('functions skip file items', () => {
442
+ const valueWithFile: SilkeCommandTextFieldValue[] = [
443
+ { type: 'text', value: 'Hello' },
444
+ fileValue,
445
+ { type: 'text', value: ' world' },
446
+ ];
447
+
448
+ test('getTextLength ignores file items', () => {
449
+ expect(getTextLength(valueWithFile)).toBe(11); // "Hello" + " world"
450
+ });
451
+
452
+ test('getItemLength returns 0 for file items', () => {
453
+ expect(getItemLength(fileValue)).toBe(0);
454
+ });
455
+
456
+ test('getActiveCommandIndex skips file items', () => {
457
+ // Caret at position 7 should be in " world" (index 2), not in file (index 1)
458
+ expect(getActiveCommandIndex(7, valueWithFile)).toBe(2);
459
+ });
460
+
461
+ test('isSilkeCommand returns false for file items', () => {
462
+ expect(isSilkeCommand(fileValue)).toBe(false);
463
+ });
464
+
465
+ test('convertSilkeCommandsToString ignores file items', () => {
466
+ expect(convertSilkeCommandsToString(valueWithFile)).toBe('Hello world');
467
+ });
468
+
469
+ test('valueToHtml ignores file items', () => {
470
+ const mockStyles = { action: 'a', mention: 'm', partial: 'p', tag: 't' };
471
+ const html = valueToHtml(valueWithFile, mockStyles);
472
+ expect(html).toBe('<span>Hello</span><span> world</span>');
473
+ });
474
+ });