@vev/silke 1.0.15 → 1.0.17
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/CHANGELOG.md +16 -0
- package/dist/chunk-SOFGXMET.js +22 -0
- package/dist/chunk-SOFGXMET.js.LEGAL.txt +11 -0
- package/dist/{chunk-KMZFUBRE.js.map → chunk-SOFGXMET.js.map} +3 -3
- package/dist/index.js +44 -9
- package/dist/index.js.LEGAL.txt +45 -21
- package/dist/index.js.map +4 -4
- package/dist/silke-code-editor-3Y2KM5KB.js +25 -0
- package/dist/silke-code-editor-3Y2KM5KB.js.LEGAL.txt +0 -0
- package/dist/silke-code-editor-3Y2KM5KB.js.map +7 -0
- package/dist/styles.css +351 -425
- package/esbuild.config.mjs +47 -43
- package/jest.config.js +1 -2
- package/package.json +4 -4
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +33 -7
- package/src/components/silke-autocomplete-field/autocomplete-tags.tsx +6 -2
- package/src/components/silke-autocomplete-field/autocomplete-types.ts +4 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +67 -24
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +32 -13
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.spec.tsx +24 -111
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +305 -219
- package/src/components/silke-box/silke-box.scss +9 -10
- package/src/components/silke-box/silke-box.tsx +9 -0
- package/src/components/silke-button/silke-button.scss +3 -3
- package/src/components/silke-color-picker/silke-color-info.tsx +2 -18
- package/src/components/silke-context-menu/silke-context-menu.tsx +0 -1
- package/src/components/silke-css-number-field/silke-css-number-field.mdx +43 -4
- package/src/components/silke-css-number-field/silke-css-number-field.scss +47 -14
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +114 -186
- package/src/components/silke-css-number-field/utils.ts +25 -0
- package/src/components/silke-drawer/silke-drawer.tsx +0 -14
- package/src/components/silke-form/silke-form.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field-inline.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field.tsx +2 -2
- package/src/components/silke-form-schema/fields/event-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/icon-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/image-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/layout-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/link-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/number-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/object-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/select-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/string-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/toggle-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/upload-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/utils/generate-image.ts +1 -1
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +6 -5
- package/src/components/silke-form-schema/schema-utils.ts +1 -1
- package/src/components/silke-form-schema/silke-form-schema.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-context.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-field.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-fields.tsx +1 -1
- package/src/components/silke-image/silke-image.scss +2 -2
- package/src/components/silke-modal/silke-modal.tsx +11 -2
- package/src/components/silke-navigation-link/silke-navigation-link.scss +12 -2
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +21 -17
- package/src/components/silke-notification/silke-notification.scss +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +1 -2
- package/src/components/silke-popover/silke-popover.tsx +1 -20
- package/src/components/silke-select-field/silke-select-field.mdx +137 -7
- package/src/components/silke-select-field/silke-select-field.spec.tsx +45 -128
- package/src/components/silke-sortable-list/silke-nested-sortable-item.tsx +17 -2
- package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +6 -2
- package/src/components/silke-sortable-list/silke-nested-sortable-utils.ts +6 -0
- package/src/components/silke-table/silke-table.tsx +1 -1
- package/src/components/silke-tag/silke-tag.tsx +3 -3
- package/src/components/silke-text-field/silke-text-field-item.tsx +12 -7
- package/src/components/silke-text-field/silke-text-field-outline.tsx +39 -42
- package/src/components/silke-text-field/silke-text-field.mdx +73 -6
- package/src/components/silke-text-field/silke-text-field.scss +153 -247
- package/src/components/silke-text-field/silke-text-field.tsx +4 -3
- package/src/components/silke-tooltip/silke-icon-tooltip.tsx +2 -1
- package/src/docs/app.tsx +9 -16
- package/src/hooks/form/use-form-field.ts +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-drop-zone.ts +0 -3
- package/src/hooks/use-uniq-id.ts +6 -0
- package/src/icons.tsx +9 -1
- package/tsconfig.json +1 -1
- package/webpack.docs.ts +1 -1
- package/dist/chunk-KMZFUBRE.js +0 -22
- package/dist/chunk-KMZFUBRE.js.LEGAL.txt +0 -8
- package/dist/silke-code-editor-UX2ML2WG.js +0 -23
- package/dist/silke-code-editor-UX2ML2WG.js.map +0 -7
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
import { getCSSNumberFormat
|
|
1
|
+
import { getCSSNumberFormat } from '@vev/utils';
|
|
2
2
|
import { get, isNumber, isString } from 'lodash';
|
|
3
|
-
import React, {
|
|
4
|
-
Children,
|
|
5
|
-
ReactNode,
|
|
6
|
-
SyntheticEvent,
|
|
7
|
-
useEffect,
|
|
8
|
-
useLayoutEffect,
|
|
9
|
-
useRef,
|
|
10
|
-
useState,
|
|
11
|
-
} from 'react';
|
|
3
|
+
import React, { Children, ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
12
4
|
import { useCallbackRef, useFormField } from '../../hooks';
|
|
13
5
|
import { SilkeBox } from '../silke-box';
|
|
14
6
|
import { FormFieldProps } from '../silke-form';
|
|
7
|
+
import { SilkeIcon } from '../silke-icon';
|
|
15
8
|
import { SilkeOverflowMenuItem } from '../silke-overflow-menu';
|
|
16
9
|
import { SilkePopover } from '../silke-popover';
|
|
17
10
|
import { SilkeTextFieldItem } from '../silke-text-field';
|
|
18
11
|
import {
|
|
19
|
-
getInputSize,
|
|
20
12
|
SilkeTextFieldOutline,
|
|
21
13
|
SilkeTextFieldOutlineProps,
|
|
22
14
|
} from '../silke-text-field/silke-text-field-outline';
|
|
23
|
-
import textFieldStyles from '../silke-text-field/silke-text-field.scss';
|
|
24
|
-
import { useTextFieldContext } from '../silke-text-field/text-field-context';
|
|
25
15
|
import { useSilkeCSSContext } from './silke-css-context';
|
|
26
16
|
import styles from './silke-css-number-field.scss';
|
|
27
17
|
import {
|
|
28
|
-
convertCSSNumberFormat,
|
|
29
|
-
convertCSSNumberString,
|
|
30
18
|
FORMAT_LABELS,
|
|
19
|
+
convertCSSNumberFormat,
|
|
20
|
+
formatNumberForDisplay,
|
|
21
|
+
getDragCursorImage,
|
|
22
|
+
getFormatFromText,
|
|
31
23
|
roundCSSNumber,
|
|
32
24
|
} from './utils';
|
|
25
|
+
import { useTextFieldContext } from '../silke-text-field/text-field-context';
|
|
33
26
|
|
|
34
27
|
export type SilkeCssNumberFieldProps = FormFieldProps<string> &
|
|
35
28
|
SilkeTextFieldOutlineProps & {
|
|
@@ -73,9 +66,8 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
73
66
|
const [openFormat, setFormatOpen] = useState(false);
|
|
74
67
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
75
68
|
const numberRef = useRef<HTMLDivElement>(null);
|
|
76
|
-
const formatRef = useRef<HTMLDivElement>(null);
|
|
77
69
|
const context = useSilkeCSSContext();
|
|
78
|
-
const
|
|
70
|
+
const textFieldContext = useTextFieldContext();
|
|
79
71
|
const isAuto = allowAuto && value === 'auto';
|
|
80
72
|
const isMixed = value === 'mixed';
|
|
81
73
|
const number = isAuto ? 'Auto' : isMixed ? 'Mixed' : parseFloat(value || '0') || 0;
|
|
@@ -84,94 +76,73 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
84
76
|
let cl = styles.root;
|
|
85
77
|
if (openFormat) cl += ' ' + styles.openFormat;
|
|
86
78
|
if (className) cl += ' ' + className;
|
|
87
|
-
if (disabled) cl
|
|
79
|
+
if (disabled) cl += ' ' + styles.disabled;
|
|
88
80
|
|
|
89
81
|
const handleNumberChange = () => {
|
|
90
|
-
const formatEl = formatRef.current;
|
|
82
|
+
// const formatEl = formatRef.current;
|
|
91
83
|
const numberEl = numberRef.current;
|
|
92
|
-
if (
|
|
93
|
-
const numberText = numberEl.innerText || '';
|
|
84
|
+
if (numberEl) {
|
|
85
|
+
const numberText = (numberEl.innerText || '').replace(/,/g, '.') || '0';
|
|
94
86
|
|
|
95
87
|
if (allowAuto && numberText && /au?t?o?/i.test(numberText)) {
|
|
96
|
-
numberEl.innerText = 'Auto';
|
|
97
|
-
formatEl.innerText = '';
|
|
88
|
+
// numberEl.innerText = 'Auto';
|
|
98
89
|
onChange('auto');
|
|
99
|
-
handleSelectText(numberEl, false);
|
|
100
|
-
} else if (formats?.length && /[a-z%]$/i.test(numberText)) {
|
|
101
|
-
const partialFormat = numberText.replace(/[^a-z%]/g, '');
|
|
102
|
-
const value = parseFloat(numberText) || 0;
|
|
103
|
-
const reg = new RegExp('^' + partialFormat, 'i');
|
|
104
|
-
const newFormat = formats?.find((f) => f.match(reg)) || formats?.[0];
|
|
105
|
-
formatEl.innerText = newFormat;
|
|
106
|
-
numberEl.innerText = value.toString();
|
|
107
|
-
handleSelectText(numberEl, false);
|
|
108
|
-
handleChange(value, newFormat);
|
|
90
|
+
// handleSelectText(numberEl, false);
|
|
109
91
|
} else {
|
|
110
|
-
const newFormat =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
92
|
+
const newFormat = getFormatFromText(numberText, format, formats);
|
|
93
|
+
let value: string | number;
|
|
94
|
+
try {
|
|
95
|
+
value = eval(numberText.replace(/[^()*+-./%0-9]/g, ''));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
value = parseFloat(numberText) || 0;
|
|
98
|
+
}
|
|
117
99
|
|
|
118
|
-
|
|
119
|
-
const formatEl = formatRef.current;
|
|
120
|
-
const numberEl = numberRef.current;
|
|
121
|
-
if (formatEl && numberEl) {
|
|
122
|
-
let newFormat: string | undefined = formatEl.innerText;
|
|
123
|
-
const reg = new RegExp('^' + newFormat, 'i');
|
|
124
|
-
|
|
125
|
-
if (allowAuto && newFormat && /au?t?o?/i.test(newFormat)) {
|
|
126
|
-
numberEl.innerText = 'Auto';
|
|
127
|
-
formatEl.innerText = '';
|
|
128
|
-
numberEl.focus();
|
|
129
|
-
handleSelectText(numberEl, false);
|
|
130
|
-
handleNumberChange();
|
|
131
|
-
} else {
|
|
132
|
-
newFormat = formats?.find((f) => f.match(reg)) || formats?.[0];
|
|
133
|
-
if (newFormat && newFormat !== format) handleFormatSelect(newFormat);
|
|
100
|
+
handleChange(value, newFormat);
|
|
134
101
|
}
|
|
135
102
|
}
|
|
136
103
|
};
|
|
137
104
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
(e.currentTarget === formatRef.current || isAuto || isMixed)
|
|
143
|
-
)
|
|
144
|
-
setFormatOpen(true);
|
|
105
|
+
const handleOpenFormat = (e: React.MouseEvent) => {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
setFormatOpen(true);
|
|
108
|
+
};
|
|
145
109
|
|
|
110
|
+
const handleFocus = () => {
|
|
111
|
+
if (disabled) return;
|
|
146
112
|
const selection = window.getSelection();
|
|
147
|
-
|
|
148
|
-
|
|
113
|
+
const el = numberRef.current;
|
|
114
|
+
if (selection?.isCollapsed && el) {
|
|
115
|
+
handleSelectText(el, true);
|
|
149
116
|
}
|
|
150
117
|
};
|
|
151
118
|
|
|
152
119
|
const handleNumberBlur = () => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
};
|
|
120
|
+
if (openFormat) setFormatOpen(false);
|
|
121
|
+
const numberEl = numberRef.current;
|
|
156
122
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
123
|
+
if (numberEl) {
|
|
124
|
+
const parent = numberEl.parentElement;
|
|
125
|
+
if (parent) parent.scrollLeft = 0;
|
|
126
|
+
|
|
127
|
+
numberEl.innerText = formatNumberForDisplay(
|
|
128
|
+
isNumber(number) ? roundCSSNumber(number, format).toString() + format : number + format,
|
|
129
|
+
);
|
|
162
130
|
}
|
|
163
131
|
};
|
|
164
132
|
|
|
165
133
|
const handleChange = (number: number | string, format: string) => {
|
|
166
|
-
|
|
134
|
+
const newValue = isString(number)
|
|
135
|
+
? number + format
|
|
136
|
+
: roundCSSNumber(number, format, min, max) + format;
|
|
137
|
+
console.log(newValue, typeof number, format);
|
|
138
|
+
onChange(newValue);
|
|
167
139
|
};
|
|
168
140
|
|
|
169
141
|
const handleFormatSelect = (newFormat: string) => {
|
|
170
|
-
const
|
|
142
|
+
const el = numberRef.current;
|
|
171
143
|
setFormatOpen(false);
|
|
172
|
-
if (
|
|
144
|
+
if (el && newFormat !== format) {
|
|
173
145
|
const fromFormat = isAuto ? 'auto' : format.toLowerCase();
|
|
174
|
-
formatEl.innerHTML = newFormat;
|
|
175
146
|
const newValue = convertCSSNumberFormat(
|
|
176
147
|
isString(number) ? 0 : number,
|
|
177
148
|
fromFormat,
|
|
@@ -182,8 +153,7 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
182
153
|
axis,
|
|
183
154
|
);
|
|
184
155
|
onChange(newValue);
|
|
185
|
-
|
|
186
|
-
handleSelectText(formatEl, true);
|
|
156
|
+
handleSelectText(el, true);
|
|
187
157
|
}
|
|
188
158
|
};
|
|
189
159
|
|
|
@@ -200,29 +170,14 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
200
170
|
useLayoutEffect(() => {
|
|
201
171
|
const el = numberRef.current;
|
|
202
172
|
if (el && document.activeElement !== el) {
|
|
203
|
-
el.innerText =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
el.focus();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}, [number, isAuto, isMixed]);
|
|
210
|
-
|
|
211
|
-
useLayoutEffect(() => {
|
|
212
|
-
const el = formatRef.current;
|
|
213
|
-
if (el && document.activeElement !== el) {
|
|
214
|
-
el.innerText = format;
|
|
215
|
-
}
|
|
216
|
-
}, [format]);
|
|
217
|
-
|
|
218
|
-
const handleFieldClick = (e: React.MouseEvent<HTMLElement>) => {
|
|
219
|
-
const formatEl = formatRef.current;
|
|
220
|
-
if (!formatEl || !Mouse.isInside(e, formatEl)) {
|
|
221
|
-
numberRef.current?.focus();
|
|
173
|
+
el.innerText = formatNumberForDisplay(
|
|
174
|
+
isNumber(number) ? roundCSSNumber(number, format).toString() + format : number + format,
|
|
175
|
+
);
|
|
222
176
|
}
|
|
223
|
-
};
|
|
177
|
+
}, [number, format, isAuto, isMixed]);
|
|
224
178
|
|
|
225
179
|
const handleNumberKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
180
|
+
if (openFormat) setFormatOpen(false);
|
|
226
181
|
let step = 0;
|
|
227
182
|
if (e.key === 'Enter') {
|
|
228
183
|
e.preventDefault();
|
|
@@ -246,46 +201,11 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
246
201
|
const newNumber = roundCSSNumber(number + step, format, min, max);
|
|
247
202
|
|
|
248
203
|
handleChange(newNumber, format);
|
|
249
|
-
numberEl.innerText = newNumber.toString();
|
|
204
|
+
numberEl.innerText = formatNumberForDisplay(newNumber.toString());
|
|
250
205
|
handleSelectText(numberEl, false);
|
|
251
206
|
}
|
|
252
207
|
});
|
|
253
208
|
|
|
254
|
-
const handleFormatKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
255
|
-
if (e.key === 'Enter') {
|
|
256
|
-
e.preventDefault();
|
|
257
|
-
const numberEl = numberRef.current;
|
|
258
|
-
if (numberEl) {
|
|
259
|
-
numberEl.focus();
|
|
260
|
-
handleSelectText(numberEl, true);
|
|
261
|
-
}
|
|
262
|
-
// e.currentTarget.blur();
|
|
263
|
-
}
|
|
264
|
-
let step = 0;
|
|
265
|
-
if (e.key === 'ArrowUp') step = -1;
|
|
266
|
-
else if (e.key === 'ArrowDown') step = 1;
|
|
267
|
-
|
|
268
|
-
if (step && formats) {
|
|
269
|
-
const len = formats.length || 0;
|
|
270
|
-
e.preventDefault();
|
|
271
|
-
let index = (formats.indexOf(format) + step) % len;
|
|
272
|
-
if (index < 0) index = len - 1;
|
|
273
|
-
const newFormat = formats[index];
|
|
274
|
-
const newValue = convertCSSNumberFormat(
|
|
275
|
-
isString(number) ? 0 : number,
|
|
276
|
-
format.toLocaleLowerCase(),
|
|
277
|
-
newFormat.toLocaleLowerCase(),
|
|
278
|
-
context,
|
|
279
|
-
min,
|
|
280
|
-
max,
|
|
281
|
-
axis,
|
|
282
|
-
);
|
|
283
|
-
onChange(newValue);
|
|
284
|
-
e.currentTarget.innerText = formats[index];
|
|
285
|
-
handleSelectText(e.currentTarget, true);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
209
|
const before: ReactNode[] = [];
|
|
290
210
|
const after: ReactNode[] = [];
|
|
291
211
|
Children.forEach(children, (child) => {
|
|
@@ -296,13 +216,13 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
296
216
|
}
|
|
297
217
|
});
|
|
298
218
|
|
|
299
|
-
const handleStartDrag = (e: React.MouseEvent) => {
|
|
219
|
+
const handleStartDrag = async (e: React.MouseEvent) => {
|
|
300
220
|
const canvas = document.createElement('canvas');
|
|
301
221
|
canvas.width = window.innerWidth;
|
|
302
222
|
canvas.height = window.innerHeight;
|
|
303
223
|
canvas.classList.add(styles.counterCanvas);
|
|
304
224
|
document.body.appendChild(canvas);
|
|
305
|
-
|
|
225
|
+
const img = await getDragCursorImage();
|
|
306
226
|
const ctx = canvas.getContext('2d');
|
|
307
227
|
canvas.requestPointerLock();
|
|
308
228
|
|
|
@@ -321,72 +241,72 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
321
241
|
}
|
|
322
242
|
};
|
|
323
243
|
|
|
324
|
-
const draw = () => {
|
|
325
|
-
if (x > canvas.width) x = 0;
|
|
326
|
-
else if (x < 0) x = canvas.width;
|
|
327
|
-
ctx?.clearRect(0, 0, canvas.width, canvas.height);
|
|
328
|
-
ctx?.drawImage(img, x, y);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
244
|
const handleMouseUp = () => {
|
|
332
245
|
window.removeEventListener('mousemove', handleMouseMove);
|
|
333
246
|
window.removeEventListener('mouseup', handleMouseUp);
|
|
334
247
|
canvas.remove();
|
|
335
248
|
};
|
|
336
249
|
|
|
337
|
-
const img = new Image();
|
|
338
|
-
img.onload = draw;
|
|
339
|
-
img.width = 35;
|
|
340
|
-
img.height = 20;
|
|
341
|
-
img.src = `data:image/svg+xml,%3Csvg height='35' viewBox='0 0 35 35' width='35' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cpath d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/%3E%3Cpath d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/%3E%3C/g%3E%3C/svg%3E`;
|
|
342
250
|
window.addEventListener('mousemove', handleMouseMove);
|
|
343
251
|
window.addEventListener('mouseup', handleMouseUp);
|
|
252
|
+
|
|
253
|
+
const draw = () => {
|
|
254
|
+
if (x > canvas.width) x = 0;
|
|
255
|
+
else if (x < 0) x = canvas.width;
|
|
256
|
+
ctx?.clearRect(0, 0, canvas.width, canvas.height);
|
|
257
|
+
ctx?.drawImage(img, x, y);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
draw();
|
|
344
261
|
};
|
|
345
262
|
|
|
346
|
-
const
|
|
263
|
+
const showFormatsArrow = !disabled && !context.readonly && (formats?.length || 0 > 1);
|
|
264
|
+
let inputCl = styles.field;
|
|
265
|
+
if (showFormatsArrow) inputCl += ' ' + styles.hasFormats;
|
|
266
|
+
|
|
267
|
+
const size = rest.size || textFieldContext.size;
|
|
347
268
|
|
|
348
269
|
return (
|
|
349
270
|
<SilkeTextFieldOutline
|
|
350
271
|
{...rest}
|
|
351
272
|
className={cl}
|
|
352
|
-
onClick={handleFieldClick}
|
|
353
273
|
ref={rootRef}
|
|
354
|
-
hAlign="
|
|
355
|
-
|
|
356
|
-
|
|
274
|
+
hAlign="start"
|
|
275
|
+
vAlign="center"
|
|
276
|
+
onClick={handleFocus}
|
|
357
277
|
>
|
|
358
278
|
{before}
|
|
359
|
-
<
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
279
|
+
<SilkeBox flex className={styles.inputHolder} overflow="hidden" vAlign="center">
|
|
280
|
+
<div
|
|
281
|
+
key="number"
|
|
282
|
+
data-input
|
|
283
|
+
className={inputCl + ' ' + styles.editable}
|
|
284
|
+
ref={numberRef}
|
|
285
|
+
role="textbox"
|
|
286
|
+
tabIndex={disabled ? -1 : undefined}
|
|
287
|
+
contentEditable={!disabled && !context.readonly}
|
|
288
|
+
autoCorrect="off"
|
|
289
|
+
spellCheck={false}
|
|
290
|
+
onInput={disabled ? preventDefault : handleNumberChange}
|
|
291
|
+
onKeyDown={disabled ? preventDefault : handleNumberKeyDown}
|
|
292
|
+
onFocus={handleFocus}
|
|
293
|
+
onBlur={handleNumberBlur}
|
|
294
|
+
/>
|
|
295
|
+
|
|
296
|
+
{showFormatsArrow && (
|
|
297
|
+
<SilkeBox
|
|
298
|
+
className={styles.downIcon}
|
|
299
|
+
width="xs"
|
|
300
|
+
height="s"
|
|
301
|
+
align="center"
|
|
302
|
+
tag="button"
|
|
303
|
+
tabIndex={-1}
|
|
304
|
+
onMouseDown={handleOpenFormat}
|
|
305
|
+
>
|
|
306
|
+
<SilkeIcon icon={openFormat ? 'chevron.up' : 'chevron.down'} />
|
|
307
|
+
</SilkeBox>
|
|
308
|
+
)}
|
|
309
|
+
</SilkeBox>
|
|
390
310
|
{!disabled && !context.readonly && !isAuto && (
|
|
391
311
|
<div className={styles.dragBar} onMouseDown={handleStartDrag} />
|
|
392
312
|
)}
|
|
@@ -398,9 +318,17 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
398
318
|
targetOrigin="top-left"
|
|
399
319
|
anchorOrigin="bottom-left"
|
|
400
320
|
shadow="level2"
|
|
321
|
+
offsetY={1}
|
|
401
322
|
onRequestClose={() => setFormatOpen(false)}
|
|
402
323
|
>
|
|
403
|
-
<SilkeBox
|
|
324
|
+
<SilkeBox
|
|
325
|
+
column
|
|
326
|
+
bg="neutral-20"
|
|
327
|
+
rounded={size === 'xs' ? 'tiny' : 'small'}
|
|
328
|
+
pad="xs"
|
|
329
|
+
overflow="hidden"
|
|
330
|
+
className={styles.menu}
|
|
331
|
+
>
|
|
404
332
|
{formats?.map((item) => (
|
|
405
333
|
<SilkeOverflowMenuItem
|
|
406
334
|
key={item}
|
|
@@ -38,6 +38,10 @@ export function roundCSSNumber(value: number, format: string, min?: number, max?
|
|
|
38
38
|
return round(value, precision);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
export function formatNumberForDisplay(value: string) {
|
|
42
|
+
return value?.replace('deg', 'º').replace('rad', 'r');
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
export function convertCSSNumberString(
|
|
42
46
|
numberText: string,
|
|
43
47
|
format: string,
|
|
@@ -105,3 +109,24 @@ function getFormatScale(
|
|
|
105
109
|
}
|
|
106
110
|
return 1;
|
|
107
111
|
}
|
|
112
|
+
|
|
113
|
+
export function getDragCursorImage(): Promise<HTMLImageElement> {
|
|
114
|
+
return new Promise((resolve) => {
|
|
115
|
+
const img = new Image();
|
|
116
|
+
img.onload = () => resolve(img);
|
|
117
|
+
img.width = 35;
|
|
118
|
+
img.height = 20;
|
|
119
|
+
img.src = `data:image/svg+xml,%3Csvg height='35' viewBox='0 0 35 35' width='35' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cpath d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/%3E%3Cpath d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/%3E%3C/g%3E%3C/svg%3E`;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getFormatFromText(
|
|
124
|
+
text: string,
|
|
125
|
+
prevFormat: string,
|
|
126
|
+
supportedFormats?: string[],
|
|
127
|
+
): string {
|
|
128
|
+
if (!supportedFormats?.length || !/[a-z%]$/i.test(text)) return prevFormat || 'px';
|
|
129
|
+
const partialFormat = text.replace(/[^a-z%]/g, '');
|
|
130
|
+
const reg = new RegExp('^' + partialFormat, 'i');
|
|
131
|
+
return supportedFormats?.find((f) => f.match(reg)) || supportedFormats?.[0];
|
|
132
|
+
}
|
|
@@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { Flex, SilkeBox } from '../silke-box';
|
|
3
3
|
import { SilkeTitle } from '../silke-text';
|
|
4
4
|
import { SilkeButton } from '../silke-button';
|
|
5
|
-
import * as focusTrap from 'focus-trap';
|
|
6
5
|
import { useKeyUp } from '@vev/utils';
|
|
7
6
|
import { useMouseDownOutside } from '../../hooks';
|
|
8
7
|
import classnames from 'classnames/bind';
|
|
@@ -27,24 +26,11 @@ export const SilkeDrawer = ({
|
|
|
27
26
|
displayCloseButton = true,
|
|
28
27
|
children,
|
|
29
28
|
title,
|
|
30
|
-
disableFocusTrap = false,
|
|
31
29
|
titleKind = 's',
|
|
32
30
|
displayFader,
|
|
33
31
|
}: React.PropsWithChildren<SilkeDrawerProps>) => {
|
|
34
32
|
const [shouldRender, setShouldRender] = useState(false);
|
|
35
33
|
const ref = useRef<HTMLDivElement>(null);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (disableFocusTrap) return;
|
|
38
|
-
const trap = focusTrap.createFocusTrap(ref.current as HTMLDivElement, {
|
|
39
|
-
initialFocus: ref.current || false,
|
|
40
|
-
});
|
|
41
|
-
if (open) {
|
|
42
|
-
trap.activate();
|
|
43
|
-
return () => {
|
|
44
|
-
trap.deactivate();
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}, [open, ref.current]);
|
|
48
34
|
|
|
49
35
|
useKeyUp('Escape', () => {
|
|
50
36
|
if (open) {
|
|
@@ -59,7 +59,7 @@ export function SilkeForm<T>({
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
|
-
<SilkeBox tag="form" column gap="
|
|
62
|
+
<SilkeBox tag="form" column gap="m" onSubmit={handleSubmit} onReset={handleReset} {...rest}>
|
|
63
63
|
<SilkeObjectField
|
|
64
64
|
name="form"
|
|
65
65
|
errors={errors}
|
|
@@ -6,7 +6,7 @@ import { SilkeText } from '../../silke-text';
|
|
|
6
6
|
import { SilkeBox } from '../../silke-box';
|
|
7
7
|
import { SilkeButton } from '../../silke-button';
|
|
8
8
|
import { generateTitle } from './utils';
|
|
9
|
-
import { VevProps } from '@vev/
|
|
9
|
+
import { VevProps } from '@vev/utils';
|
|
10
10
|
|
|
11
11
|
type Props = {
|
|
12
12
|
selected: number;
|
|
@@ -7,7 +7,7 @@ import { SilkeText } from '../../silke-text';
|
|
|
7
7
|
import { SilkeBox } from '../../silke-box';
|
|
8
8
|
import { SilkeButton } from '../../silke-button';
|
|
9
9
|
import { generateTitle } from './utils';
|
|
10
|
-
import { VevProps } from '@vev/
|
|
10
|
+
import { VevProps } from '@vev/utils';
|
|
11
11
|
import styles from './styles.scss';
|
|
12
12
|
|
|
13
13
|
type Props = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayField as ArrayFieldType, SchemaFieldProps, VevProps } from '@vev/
|
|
1
|
+
import { ArrayField as ArrayFieldType, SchemaFieldProps, VevProps } from '@vev/utils';
|
|
2
2
|
import React, { useCallback, useRef, useState } from 'react';
|
|
3
3
|
import { SilkeBox } from '../../silke-box';
|
|
4
4
|
import { SilkeButton } from '../../silke-button';
|
|
@@ -142,7 +142,7 @@ const ArrayField = ({ value = [], schema, onChange }: SchemaFieldProps<ArrayFiel
|
|
|
142
142
|
))}
|
|
143
143
|
<SilkeBox flex vAlign="center">
|
|
144
144
|
<SilkeTextSmall>
|
|
145
|
-
{typeof item === 'string' ? item : generateTitle(item, fieldSchema)}
|
|
145
|
+
{typeof item === 'string' ? item : generateTitle(item?.item, fieldSchema)}
|
|
146
146
|
</SilkeTextSmall>
|
|
147
147
|
</SilkeBox>
|
|
148
148
|
</SilkeBox>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import { EventField as EventFieldType, SchemaFieldProps, VevContentEvent } from '@vev/
|
|
2
|
+
import { EventField as EventFieldType, SchemaFieldProps, VevContentEvent } from '@vev/utils';
|
|
3
3
|
import { SilkeBox } from '../../silke-box';
|
|
4
4
|
import { SilkeTextSmall } from '../../silke-text';
|
|
5
5
|
import { SilkeNotification } from '../../silke-notification';
|
|
@@ -3,7 +3,7 @@ import { SilkeBox } from '../../silke-box';
|
|
|
3
3
|
import { SilkeButton } from '../../silke-button';
|
|
4
4
|
import { SilkeIcon, SilkeIcons } from '../../silke-icon';
|
|
5
5
|
import { SilkeTextSmall } from '../../silke-text';
|
|
6
|
-
import { IconField as IconFieldType, SchemaFieldProps } from '@vev/
|
|
6
|
+
import { IconField as IconFieldType, SchemaFieldProps } from '@vev/utils';
|
|
7
7
|
import { useSchemaContext } from '../silke-schema-context';
|
|
8
8
|
import { EmojiType } from '@vev/utils';
|
|
9
9
|
import { getTitle } from './utils/schema-util';
|
|
@@ -3,7 +3,7 @@ import { SilkeBox } from '../../silke-box';
|
|
|
3
3
|
import { SilkeButton } from '../../silke-button';
|
|
4
4
|
import { SilkeImage } from '../../silke-image';
|
|
5
5
|
import { SilkeTextSmall } from '../../silke-text';
|
|
6
|
-
import { ImageField as ImageFieldType, SchemaFieldProps } from '@vev/
|
|
6
|
+
import { ImageField as ImageFieldType, SchemaFieldProps } from '@vev/utils';
|
|
7
7
|
import { useSchemaContext } from '../silke-schema-context';
|
|
8
8
|
import styles from './styles.scss';
|
|
9
9
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutField as LayoutFieldType, SchemaFieldProps } from '@vev/
|
|
1
|
+
import { LayoutField as LayoutFieldType, SchemaFieldProps } from '@vev/utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { SilkeBox } from '../../silke-box';
|
|
4
4
|
import { SilkeSchemaFields } from '../silke-schema-fields';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaFieldProps, LinkField as LinkFieldType } from '@vev/
|
|
1
|
+
import { SchemaFieldProps, LinkField as LinkFieldType } from '@vev/utils';
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
3
|
import { SilkeAutocompleteField } from '../../silke-autocomplete-field';
|
|
4
4
|
import { SilkeBox } from '../../silke-box';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NumberField as NumberFieldType, SchemaFieldProps } from '@vev/
|
|
1
|
+
import { NumberField as NumberFieldType, SchemaFieldProps } from '@vev/utils';
|
|
2
2
|
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { SilkeCssNumberField } from '../../silke-css-number-field';
|
|
4
4
|
import { SilkeBox } from '../../silke-box';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectField as ObjectFieldType, SchemaFieldProps } from '@vev/
|
|
1
|
+
import { ObjectField as ObjectFieldType, SchemaFieldProps } from '@vev/utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { SilkeBox } from '../../silke-box';
|
|
4
4
|
import { SilkeObjectField } from '../../silke-object-field';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaFieldProps, SelectField as SelectFieldType, SelectFieldItem } from '@vev/
|
|
1
|
+
import { SchemaFieldProps, SelectField as SelectFieldType, SelectFieldItem } from '@vev/utils';
|
|
2
2
|
import { isArray, isFunction } from 'lodash';
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import { SilkeText, SilkeTextSmall } from '../../silke-text';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaFieldProps, StringField as StringFieldType } from '@vev/
|
|
1
|
+
import { SchemaFieldProps, StringField as StringFieldType } from '@vev/utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { SilkeTextField } from '../../silke-text-field';
|
|
4
4
|
import { getTitle } from './utils/schema-util';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaFieldProps, UploadField as UploadFieldType } from '@vev/
|
|
1
|
+
import { SchemaFieldProps, UploadField as UploadFieldType } from '@vev/utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { SilkeBox } from '../../silke-box';
|
|
4
4
|
import { SilkeTextSmall } from '../../silke-text';
|