@vev/silke 1.1.7 → 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 +14 -0
- package/CLAUDE.md +102 -0
- package/dist/index.js +36 -36
- package/dist/index.js.LEGAL.txt +1 -1
- package/dist/styles.css +498 -282
- 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/color-field.d.ts +3 -0
- 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/schema-utils.d.ts +6 -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 +7 -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 +120 -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 +71 -46
- package/src/components/silke-form-schema/fields/array-field.tsx +160 -122
- package/src/components/silke-form-schema/fields/color-field.tsx +136 -0
- 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/schema-utils.ts +27 -1
- package/src/components/silke-form-schema/silke-form-schema.mdx +498 -311
- package/src/components/silke-form-schema/silke-schema-field.tsx +12 -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-tag/silke-tag.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 +41 -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);
|
|
@@ -430,6 +454,13 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
430
454
|
return;
|
|
431
455
|
}
|
|
432
456
|
|
|
457
|
+
// Cmd+Enter or Shift+Enter inserts a line break
|
|
458
|
+
if (e.key === 'Enter' && (e.metaKey || e.shiftKey)) {
|
|
459
|
+
e.preventDefault();
|
|
460
|
+
document.execCommand('insertLineBreak');
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
|
|
433
464
|
const element = inputRef.current;
|
|
434
465
|
if (!element) return;
|
|
435
466
|
|
|
@@ -504,25 +535,26 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
504
535
|
[disabled, handleArrowNavigation, handleCharacterInput, handleDelete, onKeyDown],
|
|
505
536
|
);
|
|
506
537
|
|
|
507
|
-
const
|
|
508
|
-
(
|
|
509
|
-
const newValue = [...valueRef.current,
|
|
538
|
+
const addAttachment = useCallback(
|
|
539
|
+
(attachmentValue: SilkeImageValue | SilkeFileValue) => {
|
|
540
|
+
const newValue = [...valueRef.current, attachmentValue];
|
|
510
541
|
onChange(newValue);
|
|
542
|
+
inputRef.current?.focus();
|
|
511
543
|
},
|
|
512
544
|
[onChange],
|
|
513
545
|
);
|
|
514
546
|
|
|
515
|
-
const
|
|
547
|
+
const removeAttachment = useCallback(
|
|
516
548
|
(index: number) => {
|
|
517
|
-
// Find the nth
|
|
518
|
-
let
|
|
549
|
+
// Find the nth attachment in the value array and remove it
|
|
550
|
+
let attachmentCount = 0;
|
|
519
551
|
const newValue = valueRef.current.filter((item) => {
|
|
520
|
-
if (
|
|
521
|
-
if (
|
|
522
|
-
|
|
552
|
+
if (isAttachment(item)) {
|
|
553
|
+
if (attachmentCount === index) {
|
|
554
|
+
attachmentCount++;
|
|
523
555
|
return false;
|
|
524
556
|
}
|
|
525
|
-
|
|
557
|
+
attachmentCount++;
|
|
526
558
|
}
|
|
527
559
|
return true;
|
|
528
560
|
});
|
|
@@ -531,130 +563,83 @@ const SilkeCommandTextField = React.forwardRef<
|
|
|
531
563
|
[onChange],
|
|
532
564
|
);
|
|
533
565
|
|
|
566
|
+
const addMultipleAttachments = useCallback(
|
|
567
|
+
(newAttachments: (SilkeImageValue | SilkeFileValue)[]) => {
|
|
568
|
+
onChange([...valueRef.current, ...newAttachments]);
|
|
569
|
+
inputRef.current?.focus();
|
|
570
|
+
},
|
|
571
|
+
[onChange],
|
|
572
|
+
);
|
|
573
|
+
|
|
534
574
|
const handlePaste = useCallback(
|
|
535
575
|
(e: React.ClipboardEvent<HTMLDivElement>) => {
|
|
536
|
-
if (
|
|
576
|
+
if (filesDisabled) return;
|
|
537
577
|
|
|
538
|
-
const file =
|
|
578
|
+
const file = getFileFromClipboard(e, effectiveAcceptedTypes);
|
|
539
579
|
if (!file) return;
|
|
540
580
|
|
|
541
581
|
e.preventDefault();
|
|
542
|
-
|
|
543
|
-
if (
|
|
582
|
+
fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
|
|
583
|
+
if (attachmentValue) addAttachment(attachmentValue);
|
|
544
584
|
});
|
|
545
585
|
},
|
|
546
|
-
[
|
|
586
|
+
[addAttachment, effectiveAcceptedTypes, filesDisabled],
|
|
547
587
|
);
|
|
548
588
|
|
|
549
589
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
550
590
|
|
|
551
591
|
const handleDrop = useCallback(
|
|
552
592
|
(e: DragEvent) => {
|
|
553
|
-
if (
|
|
593
|
+
if (filesDisabled) return;
|
|
554
594
|
|
|
555
|
-
const file =
|
|
595
|
+
const file = getFileFromDragEvent(e, effectiveAcceptedTypes);
|
|
556
596
|
if (!file) return;
|
|
557
597
|
|
|
558
|
-
|
|
559
|
-
if (
|
|
598
|
+
fileToAttachmentValue(file, effectiveAcceptedTypes).then((attachmentValue) => {
|
|
599
|
+
if (attachmentValue) addAttachment(attachmentValue);
|
|
560
600
|
});
|
|
561
601
|
},
|
|
562
|
-
[
|
|
602
|
+
[addAttachment, effectiveAcceptedTypes, filesDisabled],
|
|
563
603
|
);
|
|
564
604
|
|
|
565
605
|
useDropZone(containerRef, handleDrop);
|
|
566
606
|
|
|
567
607
|
return (
|
|
568
608
|
<SilkeTextFieldOutline {...rest}>
|
|
569
|
-
<div
|
|
570
|
-
{
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
}}
|
|
585
|
-
>
|
|
586
|
-
<img src={imageValueToDataUrl(img)} alt={img.name || `Image ${idx + 1}`} />
|
|
587
|
-
{!disabled && (
|
|
588
|
-
<SilkeButton
|
|
589
|
-
kind="secondary"
|
|
590
|
-
size="s"
|
|
591
|
-
icon="close"
|
|
592
|
-
style={{
|
|
593
|
-
position: 'absolute',
|
|
594
|
-
top: 2,
|
|
595
|
-
right: 2,
|
|
596
|
-
backdropFilter: 'blur(8px) brightness(0.7)',
|
|
597
|
-
}}
|
|
598
|
-
className={styles.imageRemove}
|
|
599
|
-
onClick={(e) => {
|
|
600
|
-
e.stopPropagation();
|
|
601
|
-
removeImage(idx);
|
|
602
|
-
}}
|
|
603
|
-
aria-label={`Remove ${img.name || `image ${idx + 1}`}`}
|
|
604
|
-
/>
|
|
605
|
-
)}
|
|
606
|
-
</div>
|
|
607
|
-
))}
|
|
608
|
-
</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
|
+
/>
|
|
609
623
|
)}
|
|
610
|
-
{
|
|
624
|
+
<div className={styles.textfieldRow}>
|
|
611
625
|
<div
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
icon="close"
|
|
630
|
-
style={{
|
|
631
|
-
position: 'absolute',
|
|
632
|
-
top: 8,
|
|
633
|
-
right: 8,
|
|
634
|
-
backdropFilter: 'blur(8px) brightness(0.7)',
|
|
635
|
-
}}
|
|
636
|
-
onClick={() => setPreviewImageIndex(-1)}
|
|
637
|
-
aria-label="Close preview"
|
|
638
|
-
/>
|
|
639
|
-
</div>
|
|
640
|
-
</div>
|
|
641
|
-
)}
|
|
642
|
-
{placeholder && isEmpty && <div className={styles.placeholder}>{placeholder}</div>}
|
|
643
|
-
<div
|
|
644
|
-
aria-disabled={disabled}
|
|
645
|
-
aria-placeholder={placeholder}
|
|
646
|
-
className={styles.textfield}
|
|
647
|
-
contentEditable={!disabled}
|
|
648
|
-
dangerouslySetInnerHTML={{ __html: html }}
|
|
649
|
-
onFocus={handleFocus}
|
|
650
|
-
onInput={handleInput}
|
|
651
|
-
onKeyDown={handleKeyDown}
|
|
652
|
-
onPaste={handlePaste}
|
|
653
|
-
ref={inputRef}
|
|
654
|
-
role="textbox"
|
|
655
|
-
suppressContentEditableWarning
|
|
656
|
-
tabIndex={disabled ? -1 : 0}
|
|
657
|
-
/>
|
|
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>
|
|
658
643
|
</div>
|
|
659
644
|
</SilkeTextFieldOutline>
|
|
660
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
|
+
});
|