@vev/silke 1.1.8 → 1.1.9
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.
- package/.turbo/turbo-build.log +800 -0
- package/CHANGELOG.md +8 -0
- package/CLAUDE.md +102 -0
- package/dist/index.js +35 -35
- package/dist/index.js.LEGAL.txt +1 -1
- package/dist/styles.css +474 -258
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/components/silke-command-text-field/attachment-chip.d.ts +8 -0
- package/dist/types/components/silke-command-text-field/attachment-list.d.ts +15 -0
- package/dist/types/components/silke-command-text-field/file-utils.d.ts +33 -0
- package/dist/types/components/silke-command-text-field/file-utils.spec.d.ts +1 -0
- package/dist/types/components/silke-command-text-field/index.d.ts +6 -1
- package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +23 -6
- package/dist/types/components/silke-command-text-field/utils.d.ts +14 -1
- package/dist/types/components/silke-conditions-input/utils.d.ts +1 -1
- package/dist/types/components/silke-css-number-field/silke-css-context.d.ts +2 -0
- package/dist/types/components/silke-css-number-field/silke-css-number-field.d.ts +2 -0
- package/dist/types/components/silke-css-number-field/utils.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/group-field.d.ts +3 -0
- package/dist/types/components/silke-form-schema/fields/object-field.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/popover-field.d.ts +3 -0
- package/dist/types/components/silke-form-schema/fields/utils/generate-image.d.ts +5 -0
- package/dist/types/components/silke-form-schema/fields/utils/index.d.ts +1 -1
- package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
- package/dist/types/components/silke-gradient-picker/index.d.ts +3 -0
- package/dist/types/components/silke-icon/silke-icon.d.ts +1 -1
- package/dist/types/components/silke-list/silke-list.d.ts +6 -1
- package/dist/types/components/silke-list/types.d.ts +2 -0
- package/dist/types/components/silke-shortcut-button/silke-shortcut-button.d.ts +4 -1
- package/dist/types/components/silke-theme-card/index.d.ts +1 -0
- package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +18 -0
- package/dist/types/components/silke-theme-swatch/index.d.ts +1 -0
- package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +11 -0
- package/dist/types/icons.d.ts +5 -2
- package/package.json +32 -20
- package/src/components/index.ts +2 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +25 -18
- package/src/components/silke-button/silke-dropdown-button.mdx +1 -1
- package/src/components/silke-color-picker/color.ts +5 -3
- package/src/components/silke-color-swatches/silke-swatches.tsx +3 -3
- package/src/components/silke-command-text-field/attachment-chip.tsx +71 -0
- package/src/components/silke-command-text-field/attachment-list.tsx +72 -0
- package/src/components/silke-command-text-field/file-utils.spec.ts +148 -0
- package/src/components/silke-command-text-field/file-utils.ts +159 -0
- package/src/components/silke-command-text-field/index.ts +14 -0
- package/src/components/silke-command-text-field/silke-command-text-field.mdx +109 -13
- package/src/components/silke-command-text-field/silke-command-text-field.module.scss +65 -40
- package/src/components/silke-command-text-field/silke-command-text-field.tsx +113 -135
- package/src/components/silke-command-text-field/utils.spec.ts +109 -1
- package/src/components/silke-command-text-field/utils.ts +44 -7
- package/src/components/silke-css-number-field/silke-css-context.tsx +2 -0
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +7 -4
- package/src/components/silke-css-number-field/utils.ts +8 -2
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +69 -48
- package/src/components/silke-form-schema/fields/array-field.tsx +144 -130
- package/src/components/silke-form-schema/fields/color-field.tsx +118 -18
- package/src/components/silke-form-schema/fields/group-field.tsx +49 -0
- package/src/components/silke-form-schema/fields/icon-field.tsx +59 -39
- package/src/components/silke-form-schema/fields/image-field.tsx +50 -39
- package/src/components/silke-form-schema/fields/number-field.tsx +148 -184
- package/src/components/silke-form-schema/fields/object-field.tsx +2 -0
- package/src/components/silke-form-schema/fields/popover-field.tsx +65 -0
- package/src/components/silke-form-schema/fields/select-field.tsx +43 -30
- package/src/components/silke-form-schema/fields/string-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/styles.scss +2 -39
- package/src/components/silke-form-schema/fields/toggle-field.tsx +48 -15
- package/src/components/silke-form-schema/fields/utils/generate-image.ts +20 -0
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +1 -1
- package/src/components/silke-form-schema/fields/utils/index.ts +1 -1
- package/src/components/silke-form-schema/silke-form-schema.mdx +498 -311
- package/src/components/silke-form-schema/silke-schema-field.tsx +10 -3
- package/src/components/silke-form-schema/silke-schema-fields.tsx +9 -5
- package/src/components/silke-gradient-picker/index.ts +3 -0
- package/src/components/silke-icon/silke-icon.mdx +13 -1
- package/src/components/silke-icon/silke-icon.tsx +6 -2
- package/src/components/silke-list/silke-list.tsx +59 -26
- package/src/components/silke-list/types.ts +2 -0
- package/src/components/silke-navigation-link/silke-navigation-link.scss +1 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.scss +16 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.tsx +9 -0
- package/src/components/silke-slider/silke-slider.module.scss +1 -1
- package/src/components/silke-text-field/silke-text-field-outline.tsx +9 -6
- package/src/components/silke-text-field/silke-text-field.scss +3 -0
- package/src/components/silke-text-field/silke-text-field.tsx +1 -1
- package/src/components/silke-theme-card/index.ts +1 -0
- package/src/components/silke-theme-card/silke-theme-card.mdx +50 -0
- package/src/components/silke-theme-card/silke-theme-card.module.scss +82 -0
- package/src/components/silke-theme-card/silke-theme-card.tsx +82 -0
- package/src/components/silke-theme-swatch/index.ts +1 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +59 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +108 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +49 -0
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +9 -8
- package/src/icons.tsx +26 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- 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
|
-
.
|
|
9
|
+
.attachmentList {
|
|
9
10
|
display: flex;
|
|
10
|
-
flex-wrap: wrap;
|
|
11
11
|
gap: 8px;
|
|
12
|
-
|
|
12
|
+
overflow-x: auto;
|
|
13
|
+
scrollbar-width: none;
|
|
14
|
+
|
|
15
|
+
&::-webkit-scrollbar {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
.
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
/**
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
//
|
|
107
|
-
const
|
|
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
|
-
|
|
121
|
-
|
|
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
|
|
266
|
-
const
|
|
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 = [...
|
|
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
|
|
515
|
-
(
|
|
516
|
-
const newValue = [...valueRef.current,
|
|
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
|
|
547
|
+
const removeAttachment = useCallback(
|
|
523
548
|
(index: number) => {
|
|
524
|
-
// Find the nth
|
|
525
|
-
let
|
|
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 (
|
|
528
|
-
if (
|
|
529
|
-
|
|
552
|
+
if (isAttachment(item)) {
|
|
553
|
+
if (attachmentCount === index) {
|
|
554
|
+
attachmentCount++;
|
|
530
555
|
return false;
|
|
531
556
|
}
|
|
532
|
-
|
|
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 (
|
|
576
|
+
if (filesDisabled) return;
|
|
544
577
|
|
|
545
|
-
const file =
|
|
578
|
+
const file = getFileFromClipboard(e, effectiveAcceptedTypes);
|
|
546
579
|
if (!file) return;
|
|
547
580
|
|
|
548
581
|
e.preventDefault();
|
|
549
|
-
|
|
550
|
-
if (
|
|
582
|
+
fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
|
|
583
|
+
if (attachmentValue) addAttachment(attachmentValue);
|
|
551
584
|
});
|
|
552
585
|
},
|
|
553
|
-
[
|
|
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 (
|
|
593
|
+
if (filesDisabled) return;
|
|
561
594
|
|
|
562
|
-
const file =
|
|
595
|
+
const file = getFileFromDragEvent(e, effectiveAcceptedTypes);
|
|
563
596
|
if (!file) return;
|
|
564
597
|
|
|
565
|
-
|
|
566
|
-
if (
|
|
598
|
+
fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
|
|
599
|
+
if (attachmentValue) addAttachment(attachmentValue);
|
|
567
600
|
});
|
|
568
601
|
},
|
|
569
|
-
[
|
|
602
|
+
[addAttachment, effectiveAcceptedTypes, filesDisabled],
|
|
570
603
|
);
|
|
571
604
|
|
|
572
605
|
useDropZone(containerRef, handleDrop);
|
|
573
606
|
|
|
574
607
|
return (
|
|
575
608
|
<SilkeTextFieldOutline {...rest}>
|
|
576
|
-
<div
|
|
577
|
-
{
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
{
|
|
624
|
+
<div className={styles.textfieldRow}>
|
|
618
625
|
<div
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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
|
+
});
|