@vev/silke 1.0.22 → 1.0.23
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 +7 -0
- package/dist/index.js +22 -22
- package/dist/index.js.map +4 -4
- package/dist/silke/src/components/silke-autocomplete-field/silke-autocomplete-field.d.ts +4 -0
- package/dist/silke/src/components/silke-breadcrumbs/silke-breadcrumb.d.ts +2 -1
- package/dist/silke/src/components/silke-button/index.d.ts +1 -0
- package/dist/silke/src/components/silke-button/silke-button.d.ts +2 -0
- package/dist/silke/src/components/silke-button/silke-dropdown-button.d.ts +17 -0
- package/dist/silke/src/components/silke-card/silke-card.d.ts +1 -1
- package/dist/silke/src/components/silke-color-swatches/silke-swatches.d.ts +2 -1
- package/dist/silke/src/components/silke-context-menu/silke-context-menu.d.ts +3 -1
- package/dist/silke/src/components/silke-css-number-field/index.d.ts +1 -0
- package/dist/silke/src/components/silke-css-number-field/silke-css-context.d.ts +7 -0
- package/dist/silke/src/components/silke-css-number-field/silke-css-number-field.d.ts +3 -0
- package/dist/silke/src/components/silke-css-number-field/variable-picker.d.ts +17 -0
- package/dist/silke/src/components/silke-form-schema/fields/video-field.d.ts +4 -0
- package/dist/silke/src/components/silke-link/silke-link.d.ts +1 -0
- package/dist/silke/src/components/silke-navigation-link/silke-navigation-link.d.ts +6 -1
- package/dist/silke/src/components/silke-text/silke-text.d.ts +1 -4
- package/dist/silke/src/components/silke-text-field/silke-text-field-outline.d.ts +3 -0
- package/dist/silke/src/hooks/drag-and-drop/use-drop.d.ts +2 -1
- package/dist/silke/src/icons.d.ts +8 -0
- package/dist/silke-code-editor-LK4ESGQO.js +25 -0
- package/dist/silke-code-editor-LK4ESGQO.js.map +7 -0
- package/dist/styles.css +898 -783
- package/dist/utils/src/types/context.d.ts +3 -1
- package/dist/utils/src/types/interaction.d.ts +8 -4
- package/dist/utils/src/types/vev-plugin.d.ts +10 -1
- package/dist/utils/src/types/vev-props.d.ts +6 -0
- package/esbuild.config.mjs +2 -4
- package/package.json +2 -2
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +6 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +25 -2
- package/src/components/silke-breadcrumbs/silke-breadcrumb.scss +11 -4
- package/src/components/silke-breadcrumbs/silke-breadcrumb.tsx +26 -6
- package/src/components/silke-button/index.ts +1 -0
- package/src/components/silke-button/silke-button.scss +0 -4
- package/src/components/silke-button/silke-button.tsx +8 -0
- package/src/components/silke-button/silke-dropdown-button.tsx +148 -0
- package/src/components/silke-color-picker/silke-color-picker.tsx +1 -0
- package/src/components/silke-color-swatches/silke-swatches.tsx +38 -6
- package/src/components/silke-context-menu/silke-context-menu.mdx +32 -0
- package/src/components/silke-context-menu/silke-context-menu.scss +6 -0
- package/src/components/silke-context-menu/silke-context-menu.tsx +22 -0
- package/src/components/silke-css-number-field/index.ts +1 -0
- package/src/components/silke-css-number-field/silke-css-context.tsx +17 -1
- package/src/components/silke-css-number-field/silke-css-number-field.mdx +30 -0
- package/src/components/silke-css-number-field/silke-css-number-field.scss +14 -2
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +113 -13
- package/src/components/silke-css-number-field/variable-picker.tsx +181 -0
- package/src/components/silke-form-schema/fields/video-field.tsx +52 -0
- package/src/components/silke-form-schema/silke-schema-field.tsx +3 -1
- package/src/components/silke-image/silke-image.scss +1 -0
- package/src/components/silke-link/silke-link.mdx +3 -0
- package/src/components/silke-link/silke-link.scss +5 -1
- package/src/components/silke-link/silke-link.tsx +15 -3
- package/src/components/silke-modal/silke-modal.tsx +2 -0
- package/src/components/silke-navigation-link/silke-navigation-link.scss +67 -11
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +171 -51
- package/src/components/silke-overflow-menu/silke-overflow-menu.scss +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +1 -1
- package/src/components/silke-text-field/silke-text-field-outline.tsx +69 -47
- package/src/components/silke-text-field/silke-text-field.scss +63 -0
- package/src/components/silke-text-field/silke-text-field.tsx +6 -0
- package/src/hooks/drag-and-drop/use-drop.tsx +3 -1
- package/src/icons.tsx +12 -2
- package/dist/silke-code-editor-B2CVBA63.js +0 -25
- package/dist/silke-code-editor-B2CVBA63.js.map +0 -7
- /package/dist/{silke-code-editor-B2CVBA63.js.LEGAL.txt → silke-code-editor-LK4ESGQO.js.LEGAL.txt} +0 -0
|
@@ -8,6 +8,7 @@ import { SilkeContextMenuItem, SilkeContextMenuItemProps } from './silke-context
|
|
|
8
8
|
|
|
9
9
|
import { SilkeDivider } from '../silke-divider';
|
|
10
10
|
import styles from './silke-context-menu.scss';
|
|
11
|
+
import { SilkeTag } from '../silke-tag';
|
|
11
12
|
|
|
12
13
|
export type SilkeContextMenuItems =
|
|
13
14
|
| (SilkeContextMenuItemProps | React.ReactElement | 'divider')[]
|
|
@@ -21,6 +22,8 @@ export type SilkeContextMenuProps = {
|
|
|
21
22
|
/** Used internally to keep track of menu and closing */
|
|
22
23
|
subMenu?: boolean;
|
|
23
24
|
gap?: BoxSpace;
|
|
25
|
+
beta?: boolean;
|
|
26
|
+
title?: string;
|
|
24
27
|
} & Omit<SilkePopoverProps, 'children' | 'kind'>;
|
|
25
28
|
|
|
26
29
|
export function SilkeContextMenu({
|
|
@@ -32,6 +35,8 @@ export function SilkeContextMenu({
|
|
|
32
35
|
subMenu,
|
|
33
36
|
gap,
|
|
34
37
|
onRequestClose,
|
|
38
|
+
beta,
|
|
39
|
+
title = '',
|
|
35
40
|
...rest
|
|
36
41
|
}: SilkeContextMenuProps) {
|
|
37
42
|
const [showContextMenu, setShowContextMenu] = useState(false);
|
|
@@ -102,6 +107,23 @@ export function SilkeContextMenu({
|
|
|
102
107
|
}
|
|
103
108
|
}}
|
|
104
109
|
>
|
|
110
|
+
{(beta || !!title) && (
|
|
111
|
+
<SilkeBox pad="xs" gap="l">
|
|
112
|
+
<SilkeBox hPad="s" className={[styles.item, styles.title].join(' ')}>
|
|
113
|
+
{title}
|
|
114
|
+
</SilkeBox>
|
|
115
|
+
{beta && (
|
|
116
|
+
<SilkeBox hPad="xs">
|
|
117
|
+
<SilkeTag
|
|
118
|
+
color="sand"
|
|
119
|
+
label="Beta"
|
|
120
|
+
size="tiny"
|
|
121
|
+
style={{ alignSelf: 'center' }}
|
|
122
|
+
/>
|
|
123
|
+
</SilkeBox>
|
|
124
|
+
)}
|
|
125
|
+
</SilkeBox>
|
|
126
|
+
)}
|
|
105
127
|
{(isFunction(items) ? items() : items)?.map((item, index) => {
|
|
106
128
|
return !item ? null : React.isValidElement(item) ? (
|
|
107
129
|
item
|
|
@@ -18,6 +18,7 @@ export type SilkeCSSContextType = {
|
|
|
18
18
|
*/
|
|
19
19
|
self?: [width: number, height: number];
|
|
20
20
|
variables: { [variableName: string]: string };
|
|
21
|
+
variablesv2: { key: string; name: string; type: string; value?: string; unit?: string }[];
|
|
21
22
|
readonly?: boolean;
|
|
22
23
|
onVariableAdd?: (color: string) => void;
|
|
23
24
|
onVariableDelete?: (color: string) => void;
|
|
@@ -27,6 +28,7 @@ const Context = React.createContext<SilkeCSSContextType>({
|
|
|
27
28
|
fontSize: 14,
|
|
28
29
|
viewport: [1440, 900],
|
|
29
30
|
variables: {},
|
|
31
|
+
variablesv2: [],
|
|
30
32
|
onVariableAdd: () => null,
|
|
31
33
|
onVariableDelete: () => null,
|
|
32
34
|
});
|
|
@@ -41,7 +43,8 @@ export function SilkeCSSContext({
|
|
|
41
43
|
...rest
|
|
42
44
|
}: Partial<SilkeCSSContextType> & { children: React.ReactNode }) {
|
|
43
45
|
const context = useContext(Context);
|
|
44
|
-
const { variables } = rest;
|
|
46
|
+
const { variables, variablesv2 } = rest;
|
|
47
|
+
|
|
45
48
|
useEffect(() => {
|
|
46
49
|
if (variables) {
|
|
47
50
|
const style = document.createElement('style');
|
|
@@ -53,5 +56,18 @@ export function SilkeCSSContext({
|
|
|
53
56
|
return () => style.remove();
|
|
54
57
|
}
|
|
55
58
|
}, [variables]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (variablesv2) {
|
|
62
|
+
const style = document.createElement('style');
|
|
63
|
+
style.innerText = `body{${variablesv2
|
|
64
|
+
.map((v) => `--vev-${v.key}:${v.value}${v.unit ? v.unit : ''}`)
|
|
65
|
+
.join(';')}}`;
|
|
66
|
+
|
|
67
|
+
document.body.appendChild(style);
|
|
68
|
+
return () => style.remove();
|
|
69
|
+
}
|
|
70
|
+
}, [variablesv2]);
|
|
71
|
+
|
|
56
72
|
return <Context.Provider value={{ ...context, ...rest }}>{children}</Context.Provider>;
|
|
57
73
|
}
|
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
This filed can be used to easyly format CSS number
|
|
4
4
|
You can wrap the filed in a css context to enable automatic convertion between formats
|
|
5
5
|
|
|
6
|
+
### With variables
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
const [value, setValue] = React.useState('20px');
|
|
10
|
+
const formats = ['px', '%', 'em', 'vh', 'vw']
|
|
11
|
+
<SilkeCSSContext viewport={[1920, 1080]} fontSize={18} container={[200,150]} variablesv2={[
|
|
12
|
+
{ key: 'A', name: 'size-xs', value: '10', unit: 'px'},
|
|
13
|
+
{ key: 'B', name: 'size-s', value: '50', unit: 'px'},
|
|
14
|
+
{ key: 'C', name: 'size-m', value: '100', unit: 'px'},
|
|
15
|
+
{ key: 'D', name: 'size-l', value: '200', unit: 'px'},
|
|
16
|
+
{ key: 'E', name: 'size-xl', value: '400', unit: 'px'},
|
|
17
|
+
{ key: 'F', name: 'size-xxl', value: '800', unit: 'px'},
|
|
18
|
+
{ key: 'G', name: 'size-xxxl', value: '1600', unit: 'px'},
|
|
19
|
+
{ key: 'H', name: 'size-xxxxl', value: '3200', unit: 'px'}
|
|
20
|
+
]}>
|
|
21
|
+
<TextFieldContext inline="label-inside" size="xs">
|
|
22
|
+
<SilkeBox column gap="s">
|
|
23
|
+
<h1>{value}</h1>
|
|
24
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
25
|
+
<SilkeBox gap="s" key={kind} style={{width: 256}}>
|
|
26
|
+
<SilkeCssNumberField kind={kind} label="Label" allowAuto value={value} formats={formats} onChange={setValue} />
|
|
27
|
+
<SilkeCssNumberField kind={kind} value={value} label="Label" formats={formats} onChange={setValue}/>
|
|
28
|
+
<SilkeCssNumberField kind={kind} label="Label" value={value} formats={formats} onChange={setValue} />
|
|
29
|
+
</SilkeBox>
|
|
30
|
+
))}
|
|
31
|
+
</SilkeBox>
|
|
32
|
+
</TextFieldContext>
|
|
33
|
+
</SilkeCSSContext>
|
|
34
|
+
```
|
|
35
|
+
|
|
6
36
|
### Basic usage
|
|
7
37
|
|
|
8
38
|
```js
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
--text-field-focus-border-color: transparent;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
&.openVariables {
|
|
20
|
+
--current-border-color: var(--color-support-tertiary-30) !important;
|
|
21
|
+
--text-field-hover-border-color: var(--color-support-tertiary-30) !important;
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
.field {
|
|
@@ -31,7 +36,8 @@
|
|
|
31
36
|
|
|
32
37
|
padding:0 !important;
|
|
33
38
|
// width: auto !important;
|
|
34
|
-
&.hasFormats
|
|
39
|
+
&.hasFormats,
|
|
40
|
+
&.hasVariables {
|
|
35
41
|
max-width: calc(100% - 16px);
|
|
36
42
|
}
|
|
37
43
|
flex: none !important;
|
|
@@ -56,6 +62,12 @@
|
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
.variable {
|
|
66
|
+
.field {
|
|
67
|
+
color: var(--color-support-tertiary-30);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
.counterCanvas {
|
|
60
72
|
width: 100vw;
|
|
61
73
|
height: 100vh;
|
|
@@ -87,4 +99,4 @@
|
|
|
87
99
|
.downIcon:hover,
|
|
88
100
|
.openFormat .downIcon {
|
|
89
101
|
color: var(--text-field-color);
|
|
90
|
-
}
|
|
102
|
+
}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
roundCSSNumber,
|
|
24
24
|
} from './utils';
|
|
25
25
|
import { useTextFieldContext } from '../silke-text-field/text-field-context';
|
|
26
|
+
import { VariablePicker } from './variable-picker';
|
|
26
27
|
|
|
27
28
|
export type SilkeCssNumberFieldProps = FormFieldProps<string> &
|
|
28
29
|
SilkeTextFieldOutlineProps & {
|
|
@@ -31,10 +32,13 @@ export type SilkeCssNumberFieldProps = FormFieldProps<string> &
|
|
|
31
32
|
max?: number;
|
|
32
33
|
autoFocus?: boolean;
|
|
33
34
|
allowAuto?: boolean;
|
|
35
|
+
disableVariables?: boolean;
|
|
34
36
|
disabled?: boolean;
|
|
35
37
|
/** Define witch axis the number belongs to (used when converting values for the CSSContext) */
|
|
36
38
|
axis?: 'x' | 'y';
|
|
37
39
|
onEnter?: (e: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
40
|
+
onVariableAdd?: (type: string) => void;
|
|
41
|
+
onVariableEdit?: (key: string) => void;
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
const handleSelectText = (el: HTMLDivElement, selectAll: boolean) => {
|
|
@@ -57,18 +61,23 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
57
61
|
formats,
|
|
58
62
|
axis,
|
|
59
63
|
allowAuto,
|
|
64
|
+
disableVariables,
|
|
60
65
|
autoFocus,
|
|
61
66
|
className,
|
|
62
67
|
onEnter,
|
|
63
68
|
onChange,
|
|
69
|
+
onVariableAdd,
|
|
70
|
+
onVariableEdit,
|
|
64
71
|
...rest
|
|
65
72
|
} = useFormField(props);
|
|
66
73
|
const [openFormat, setFormatOpen] = useState(false);
|
|
74
|
+
const [openVariables, setOpenVariables] = useState(false);
|
|
67
75
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
68
76
|
const numberRef = useRef<HTMLDivElement>(null);
|
|
69
77
|
const context = useSilkeCSSContext();
|
|
70
78
|
const textFieldContext = useTextFieldContext();
|
|
71
79
|
const isAuto = allowAuto && value === 'auto';
|
|
80
|
+
const isVariable = value?.startsWith('var(--vev-');
|
|
72
81
|
const isMixed = value === 'mixed';
|
|
73
82
|
const number = isAuto ? 'Auto' : isMixed ? 'Mixed' : parseFloat(value || '0') || 0;
|
|
74
83
|
const format = isAuto || isMixed ? '' : getCSSNumberFormat(value || '0');
|
|
@@ -77,6 +86,13 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
77
86
|
if (openFormat) cl += ' ' + styles.openFormat;
|
|
78
87
|
if (className) cl += ' ' + className;
|
|
79
88
|
if (disabled) cl += ' ' + styles.disabled;
|
|
89
|
+
if (isVariable) cl += ' ' + styles.variable;
|
|
90
|
+
if (openVariables) cl += ' ' + styles.openVariables;
|
|
91
|
+
|
|
92
|
+
const variables = React.useMemo(() => {
|
|
93
|
+
return (context.variablesv2 || []).filter((v) => formats?.includes(v.unit || ''));
|
|
94
|
+
}, [context.variablesv2, formats]);
|
|
95
|
+
const showVariables = variables?.length > 0 && !disableVariables;
|
|
80
96
|
|
|
81
97
|
const handleNumberChange = () => {
|
|
82
98
|
// const formatEl = formatRef.current;
|
|
@@ -107,13 +123,32 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
107
123
|
setFormatOpen(true);
|
|
108
124
|
};
|
|
109
125
|
|
|
126
|
+
const handleOpenVariables = (e: React.MouseEvent) => {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
setOpenVariables(true);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const handleVariablesDotClicked = (e: React.MouseEvent) => {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
|
|
134
|
+
// If active variable, remove link and set to native value
|
|
135
|
+
if (isVariable) {
|
|
136
|
+
const variable = variables.find((v) => value?.includes(v.key));
|
|
137
|
+
onChange(variable ? `${variable.value}${variable.unit}` : '0');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
setOpenVariables(true);
|
|
142
|
+
};
|
|
143
|
+
|
|
110
144
|
const handleFocus = () => {
|
|
111
145
|
if (disabled) return;
|
|
112
146
|
const selection = window.getSelection();
|
|
113
147
|
const el = numberRef.current;
|
|
114
|
-
if (selection?.isCollapsed && el) {
|
|
148
|
+
if (selection?.isCollapsed && el && !isVariable) {
|
|
115
149
|
handleSelectText(el, true);
|
|
116
150
|
}
|
|
151
|
+
if (isVariable && !openVariables) setOpenVariables(true);
|
|
117
152
|
};
|
|
118
153
|
|
|
119
154
|
const handleNumberBlur = () => {
|
|
@@ -131,10 +166,12 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
131
166
|
};
|
|
132
167
|
|
|
133
168
|
const handleChange = (number: number | string, format: string) => {
|
|
134
|
-
const newValue =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
169
|
+
const newValue =
|
|
170
|
+
format === 'variable'
|
|
171
|
+
? number
|
|
172
|
+
: isString(number)
|
|
173
|
+
? number + format
|
|
174
|
+
: roundCSSNumber(number, format, min, max) + format;
|
|
138
175
|
onChange(newValue);
|
|
139
176
|
};
|
|
140
177
|
|
|
@@ -170,11 +207,16 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
170
207
|
useLayoutEffect(() => {
|
|
171
208
|
const el = numberRef.current;
|
|
172
209
|
if (el && document.activeElement !== el) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
210
|
+
if (isVariable) {
|
|
211
|
+
const variable = variables.find((v) => value?.includes(v.key));
|
|
212
|
+
el.innerText = variable?.name || 'variable';
|
|
213
|
+
} else {
|
|
214
|
+
el.innerText = formatNumberForDisplay(
|
|
215
|
+
isNumber(number) ? roundCSSNumber(number, format).toString() + format : number + format,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
176
218
|
}
|
|
177
|
-
}, [number, format, isAuto, isMixed]);
|
|
219
|
+
}, [number, format, variables, isAuto, isMixed, isVariable]);
|
|
178
220
|
|
|
179
221
|
const handleNumberKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
180
222
|
if (openFormat) setFormatOpen(false);
|
|
@@ -260,9 +302,13 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
260
302
|
draw();
|
|
261
303
|
};
|
|
262
304
|
|
|
263
|
-
const
|
|
305
|
+
const showVariablesArrow = !disabled && !context.readonly && isVariable;
|
|
306
|
+
const showFormatsArrow =
|
|
307
|
+
!disabled && !context.readonly && (formats?.length || 0 > 1) && !isVariable;
|
|
308
|
+
|
|
264
309
|
let inputCl = styles.field;
|
|
265
310
|
if (showFormatsArrow) inputCl += ' ' + styles.hasFormats;
|
|
311
|
+
if (showVariablesArrow) inputCl += ' ' + styles.hasVariables;
|
|
266
312
|
|
|
267
313
|
const size = rest.size || textFieldContext.size;
|
|
268
314
|
|
|
@@ -274,8 +320,12 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
274
320
|
hAlign="start"
|
|
275
321
|
vAlign="center"
|
|
276
322
|
onClick={handleFocus}
|
|
323
|
+
showVariableDot={showVariables && !openVariables}
|
|
324
|
+
hasActiveVariable={isVariable}
|
|
325
|
+
onVariableClick={handleVariablesDotClicked}
|
|
277
326
|
>
|
|
278
327
|
{before}
|
|
328
|
+
|
|
279
329
|
<SilkeBox flex className={styles.inputHolder} overflow="hidden" vAlign="center">
|
|
280
330
|
<div
|
|
281
331
|
key="number"
|
|
@@ -289,10 +339,30 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
289
339
|
spellCheck={false}
|
|
290
340
|
onInput={disabled ? preventDefault : handleNumberChange}
|
|
291
341
|
onKeyDown={disabled ? preventDefault : handleNumberKeyDown}
|
|
292
|
-
onFocus={
|
|
293
|
-
|
|
342
|
+
onFocus={(e) => {
|
|
343
|
+
handleFocus();
|
|
344
|
+
if (props.onFocus) props.onFocus(e.nativeEvent);
|
|
345
|
+
}}
|
|
346
|
+
onBlur={(e) => {
|
|
347
|
+
handleNumberBlur();
|
|
348
|
+
if (props.onBlur) props.onBlur(e.nativeEvent);
|
|
349
|
+
}}
|
|
294
350
|
/>
|
|
295
351
|
|
|
352
|
+
{showVariablesArrow && (
|
|
353
|
+
<SilkeBox
|
|
354
|
+
className={styles.downIcon}
|
|
355
|
+
width="xs"
|
|
356
|
+
height="s"
|
|
357
|
+
align="center"
|
|
358
|
+
tag="button"
|
|
359
|
+
tabIndex={-1}
|
|
360
|
+
onMouseDown={handleOpenVariables}
|
|
361
|
+
>
|
|
362
|
+
<SilkeIcon icon={openVariables ? 'chevron.up' : 'chevron.down'} />
|
|
363
|
+
</SilkeBox>
|
|
364
|
+
)}
|
|
365
|
+
|
|
296
366
|
{showFormatsArrow && (
|
|
297
367
|
<SilkeBox
|
|
298
368
|
className={styles.downIcon}
|
|
@@ -307,7 +377,7 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
307
377
|
</SilkeBox>
|
|
308
378
|
)}
|
|
309
379
|
</SilkeBox>
|
|
310
|
-
{!disabled && !context.readonly && !isAuto && (
|
|
380
|
+
{!disabled && !context.readonly && !isAuto && !isVariable && (
|
|
311
381
|
<div className={styles.dragBar} onMouseDown={handleStartDrag} />
|
|
312
382
|
)}
|
|
313
383
|
{after}
|
|
@@ -350,6 +420,36 @@ export function SilkeCssNumberField(props: SilkeCssNumberFieldProps) {
|
|
|
350
420
|
</SilkeBox>
|
|
351
421
|
</SilkePopover>
|
|
352
422
|
)}
|
|
423
|
+
|
|
424
|
+
{openVariables && (
|
|
425
|
+
<SilkePopover
|
|
426
|
+
anchor={rootRef}
|
|
427
|
+
targetOrigin="top-left"
|
|
428
|
+
anchorOrigin="bottom-left"
|
|
429
|
+
shadow="level2"
|
|
430
|
+
offsetY={1}
|
|
431
|
+
onRequestClose={() => setOpenVariables(false)}
|
|
432
|
+
>
|
|
433
|
+
<SilkeBox
|
|
434
|
+
column
|
|
435
|
+
bg="neutral-20"
|
|
436
|
+
rounded={size === 'xs' ? 'tiny' : 'small'}
|
|
437
|
+
overflow="hidden"
|
|
438
|
+
className={styles.menu}
|
|
439
|
+
>
|
|
440
|
+
<VariablePicker
|
|
441
|
+
variables={variables}
|
|
442
|
+
type="number"
|
|
443
|
+
onAdd={onVariableAdd}
|
|
444
|
+
onEdit={onVariableEdit}
|
|
445
|
+
onSelect={(key) => {
|
|
446
|
+
handleChange(`var(--vev-${key})`, 'variable');
|
|
447
|
+
setOpenVariables(false);
|
|
448
|
+
}}
|
|
449
|
+
/>
|
|
450
|
+
</SilkeBox>
|
|
451
|
+
</SilkePopover>
|
|
452
|
+
)}
|
|
353
453
|
</SilkeTextFieldOutline>
|
|
354
454
|
);
|
|
355
455
|
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { Data } from '../silke-autocomplete-field/autocomplete-types';
|
|
3
|
+
import { SilkeBox } from '../silke-box';
|
|
4
|
+
import { SilkeIcon } from '../silke-icon';
|
|
5
|
+
import { SilkeTextMicro, SilkeTextSmall } from '../silke-text';
|
|
6
|
+
import { SilkeDivider } from '../silke-divider';
|
|
7
|
+
import AutocompleteItem from '../silke-autocomplete-field/autocomplete-item';
|
|
8
|
+
import { SilkeTextField, SilkeTextFieldItem } from '../silke-text-field';
|
|
9
|
+
import { SilkeButton } from '../silke-button';
|
|
10
|
+
|
|
11
|
+
const getVariableIcon = (variable: Variable) => {
|
|
12
|
+
return variable.type === 'color' ? 'variable.color' : 'hashtag';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function getIndexInDir(
|
|
16
|
+
currentIndex: number,
|
|
17
|
+
listLength: number,
|
|
18
|
+
dir: 'ArrowUp' | 'ArrowDown',
|
|
19
|
+
): number {
|
|
20
|
+
if (dir === 'ArrowUp') {
|
|
21
|
+
return currentIndex === 0 ? listLength - 1 : currentIndex - 1;
|
|
22
|
+
}
|
|
23
|
+
return currentIndex < 0 ? 0 : currentIndex === listLength - 1 ? 0 : currentIndex + 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Variable = { key: string; name: string; type: string; value?: string; unit?: string };
|
|
27
|
+
|
|
28
|
+
type VariablePickerProps = {
|
|
29
|
+
variables: Variable[];
|
|
30
|
+
type: 'color' | 'number' | 'font';
|
|
31
|
+
onAdd?: (type: string) => void;
|
|
32
|
+
onEdit?: (key: string) => void;
|
|
33
|
+
onSelect: (variableKey: string) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function VariablePicker(props: VariablePickerProps) {
|
|
37
|
+
const { variables = [], type, onAdd, onEdit, onSelect } = props;
|
|
38
|
+
const [highlight, setHighlight] = useState<undefined | number>(-1);
|
|
39
|
+
const [search, setSearch] = useState('');
|
|
40
|
+
|
|
41
|
+
const variableItems = useMemo(() => {
|
|
42
|
+
const items = variables.map((v) => ({
|
|
43
|
+
label: v.name,
|
|
44
|
+
value: v.key,
|
|
45
|
+
subLabel: `${v.value}${v.unit ? `${v.unit}` : ''}`,
|
|
46
|
+
icon: getVariableIcon(v),
|
|
47
|
+
})) as Data<string>[];
|
|
48
|
+
|
|
49
|
+
return search
|
|
50
|
+
? items.filter(
|
|
51
|
+
(item) =>
|
|
52
|
+
item.label?.toLowerCase().includes(search.toLowerCase()) ||
|
|
53
|
+
item.subLabel?.toLowerCase().includes(search.toLowerCase()),
|
|
54
|
+
)
|
|
55
|
+
: items;
|
|
56
|
+
}, [variables, search]);
|
|
57
|
+
|
|
58
|
+
const handleChange = (value: string) => {
|
|
59
|
+
onSelect(value);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const handleKeyUp = (e: React.KeyboardEvent) => {
|
|
63
|
+
switch (e.key) {
|
|
64
|
+
case 'ArrowUp':
|
|
65
|
+
case 'ArrowDown': {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
const { key } = e;
|
|
69
|
+
setHighlight((value) => getIndexInDir(value || 0, variableItems.length, key));
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'Enter': {
|
|
73
|
+
const item = highlight !== undefined && variableItems[highlight];
|
|
74
|
+
if (item && item.value) {
|
|
75
|
+
onSelect(item.value);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<SilkeBox column bg="neutral-20" style={{ width: '168px' }} onKeyUp={handleKeyUp}>
|
|
84
|
+
<SilkeBox gap="s" pad="xs" vAlign="center">
|
|
85
|
+
<SilkeTextField
|
|
86
|
+
kind="ghost"
|
|
87
|
+
value={search}
|
|
88
|
+
onChange={setSearch}
|
|
89
|
+
size="xs"
|
|
90
|
+
inline
|
|
91
|
+
autoFocus
|
|
92
|
+
placeholder={type === 'color' ? 'Color' : type === 'number' ? 'Number' : 'Font'}
|
|
93
|
+
>
|
|
94
|
+
<SilkeTextFieldItem before align="center">
|
|
95
|
+
<SilkeBox size="s" align="center">
|
|
96
|
+
<SilkeIcon
|
|
97
|
+
icon={type === 'color' ? 'variable.color' : 'hashtag'}
|
|
98
|
+
color="neutral-60"
|
|
99
|
+
/>
|
|
100
|
+
</SilkeBox>
|
|
101
|
+
</SilkeTextFieldItem>
|
|
102
|
+
{search && (
|
|
103
|
+
<SilkeTextFieldItem>
|
|
104
|
+
<SilkeButton icon="close" kind="ghost" size="s" onClick={() => setSearch('')} />
|
|
105
|
+
</SilkeTextFieldItem>
|
|
106
|
+
)}
|
|
107
|
+
{onAdd && !search && (
|
|
108
|
+
<SilkeTextFieldItem>
|
|
109
|
+
<SilkeButton icon="add" kind="ghost" size="s" onClick={() => onAdd(type)} />
|
|
110
|
+
</SilkeTextFieldItem>
|
|
111
|
+
)}
|
|
112
|
+
</SilkeTextField>
|
|
113
|
+
</SilkeBox>
|
|
114
|
+
|
|
115
|
+
<SilkeDivider dark />
|
|
116
|
+
|
|
117
|
+
<SilkeBox
|
|
118
|
+
role="listbox"
|
|
119
|
+
column
|
|
120
|
+
style={{ maxHeight: 162, overflow: 'auto' }}
|
|
121
|
+
hPad="xs"
|
|
122
|
+
vPad="xs"
|
|
123
|
+
>
|
|
124
|
+
{variableItems?.map((item, i) => (
|
|
125
|
+
<AutocompleteItem
|
|
126
|
+
size="base"
|
|
127
|
+
highlight={i === highlight}
|
|
128
|
+
ItemRender={({ item }) => (
|
|
129
|
+
<SilkeBox
|
|
130
|
+
key={`${item.label}-${item.value}`}
|
|
131
|
+
gap="s"
|
|
132
|
+
hPad="s"
|
|
133
|
+
vAlign="center"
|
|
134
|
+
overflow="hidden"
|
|
135
|
+
onMouseEnter={() => setHighlight(i)}
|
|
136
|
+
fill
|
|
137
|
+
>
|
|
138
|
+
<SilkeBox
|
|
139
|
+
size="xs"
|
|
140
|
+
hAlign
|
|
141
|
+
vAlign
|
|
142
|
+
rounded="tiny"
|
|
143
|
+
bg="neutral-50"
|
|
144
|
+
style={type === 'color' ? { backgroundColor: item.subLabel } : undefined}
|
|
145
|
+
/>
|
|
146
|
+
<SilkeBox column style={{ minWidth: '0', flex: 1 }}>
|
|
147
|
+
<SilkeTextSmall overflow>{item.label}</SilkeTextSmall>
|
|
148
|
+
<SilkeTextMicro overflow color="neutral-60">
|
|
149
|
+
{item.subLabel}
|
|
150
|
+
</SilkeTextMicro>
|
|
151
|
+
</SilkeBox>
|
|
152
|
+
|
|
153
|
+
{onEdit && i === highlight && (
|
|
154
|
+
<SilkeBox>
|
|
155
|
+
<SilkeButton
|
|
156
|
+
icon="settings"
|
|
157
|
+
kind="ghost"
|
|
158
|
+
size="s"
|
|
159
|
+
onMouseDown={(e) => {
|
|
160
|
+
e.preventDefault;
|
|
161
|
+
e.stopPropagation();
|
|
162
|
+
onEdit(item.value);
|
|
163
|
+
}}
|
|
164
|
+
/>
|
|
165
|
+
</SilkeBox>
|
|
166
|
+
)}
|
|
167
|
+
</SilkeBox>
|
|
168
|
+
)}
|
|
169
|
+
key={i}
|
|
170
|
+
item={item}
|
|
171
|
+
onMouseDown={(e) => {
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
e.stopPropagation();
|
|
174
|
+
if (!item.divider && !item.disabled) handleChange(item.value);
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
177
|
+
))}
|
|
178
|
+
</SilkeBox>
|
|
179
|
+
</SilkeBox>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { SilkeBox } from '../../silke-box';
|
|
3
|
+
import { SilkeButton } from '../../silke-button';
|
|
4
|
+
import { SilkeTextSmall } from '../../silke-text';
|
|
5
|
+
import { VideoField as VideoFieldType, SchemaFieldProps } from '@vev/utils';
|
|
6
|
+
import { useSchemaContext } from '../silke-schema-context';
|
|
7
|
+
import styles from './styles.scss';
|
|
8
|
+
|
|
9
|
+
import { getTitle } from './utils/schema-util';
|
|
10
|
+
|
|
11
|
+
const VideoField = ({ value, schema, onChange }: SchemaFieldProps<VideoFieldType>) => {
|
|
12
|
+
console.log('value', value);
|
|
13
|
+
const { actions } = useSchemaContext();
|
|
14
|
+
const handleDeleteVideo = useCallback(() => {
|
|
15
|
+
onChange(null);
|
|
16
|
+
}, [onChange]);
|
|
17
|
+
|
|
18
|
+
const handleSelectVideo = useCallback(() => {
|
|
19
|
+
if (!actions) return;
|
|
20
|
+
actions.videoLibraryOpen((video: any) => {
|
|
21
|
+
if (!video || !video.url) return;
|
|
22
|
+
onChange({ key: video.key, url: video.url });
|
|
23
|
+
actions.videoLibraryClose();
|
|
24
|
+
});
|
|
25
|
+
}, [onChange, actions]);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<SilkeBox column flex vPad="s" gap="s">
|
|
29
|
+
<SilkeTextSmall>{getTitle(schema)}</SilkeTextSmall>
|
|
30
|
+
{schema.description && (
|
|
31
|
+
<SilkeTextSmall color="neutral-80">{schema.description}</SilkeTextSmall>
|
|
32
|
+
)}
|
|
33
|
+
<SilkeBox column>
|
|
34
|
+
<video
|
|
35
|
+
loop
|
|
36
|
+
muted
|
|
37
|
+
autoPlay
|
|
38
|
+
src={value?.url}
|
|
39
|
+
style={{ background: '#444', borderRadius: '4px', overflow: 'hidden' }}
|
|
40
|
+
/>
|
|
41
|
+
<SilkeBox flex align="center" className={styles.imageField__actions}>
|
|
42
|
+
<SilkeButton size="m" icon="edit" kind="ghost" onClick={handleSelectVideo} />
|
|
43
|
+
{value?.url && (
|
|
44
|
+
<SilkeButton size="m" icon="delete" kind="ghost" onClick={handleDeleteVideo} />
|
|
45
|
+
)}
|
|
46
|
+
</SilkeBox>
|
|
47
|
+
</SilkeBox>
|
|
48
|
+
</SilkeBox>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default VideoField;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SchemaFieldComponents, VevProps } from '@vev/utils';
|
|
2
2
|
import { isFunction } from 'lodash';
|
|
3
|
-
import React
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { SilkeBox, useExtendedFields, useFormField } from '..';
|
|
5
5
|
import { SilkeNotification } from '../silke-notification';
|
|
6
6
|
import { safeEvalFunction } from './safe-eval';
|
|
@@ -10,6 +10,7 @@ import { SilkeDivider } from '../silke-divider';
|
|
|
10
10
|
|
|
11
11
|
import ArrayField from './fields/array-field';
|
|
12
12
|
import ImageField from './fields/image-field';
|
|
13
|
+
import VideoField from './fields/video-field';
|
|
13
14
|
import NumberField from './fields/number-field';
|
|
14
15
|
import ObjectField from './fields/object-field';
|
|
15
16
|
import SelectField from './fields/select-field';
|
|
@@ -33,6 +34,7 @@ const SCHEMA_FIELD_COMPONENTS: Partial<SchemaFieldComponents> = {
|
|
|
33
34
|
number: NumberField,
|
|
34
35
|
array: ArrayField,
|
|
35
36
|
image: ImageField,
|
|
37
|
+
video: VideoField,
|
|
36
38
|
boolean: ToggleField,
|
|
37
39
|
object: ObjectField,
|
|
38
40
|
select: SelectField,
|