@vev/silke 1.0.23 → 1.0.25
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 +17 -0
- package/dist/index.js +71 -30
- package/dist/index.js.LEGAL.txt +10 -0
- package/dist/silke/src/components/index.d.ts +1 -0
- package/dist/silke/src/components/silke-autocomplete-field/silke-autocomplete-field.d.ts +5 -1
- package/dist/silke/src/components/silke-autocomplete-field/silke-autocomplete-popup.d.ts +13 -0
- package/dist/silke/src/components/silke-box/silke-box.d.ts +1 -1
- package/dist/silke/src/components/silke-button/silke-button.d.ts +11 -11
- package/dist/silke/src/components/silke-card/silke-card.d.ts +13 -13
- package/dist/silke/src/components/silke-color-swatches/silke-color-swatch-button.d.ts +1 -1
- package/dist/silke/src/components/silke-css-number-field/index.d.ts +0 -1
- package/dist/silke/src/components/silke-css-number-field/silke-css-context.d.ts +1 -1
- package/dist/silke/src/components/silke-css-number-field/silke-css-number-field.d.ts +0 -2
- package/dist/silke/src/components/silke-form/form-types.d.ts +0 -1
- package/dist/silke/src/components/silke-form-schema/fields/number-field.d.ts +1 -1
- package/dist/silke/src/components/silke-form-schema/fields/utils/generate-title.d.ts +2 -2
- package/dist/silke/src/components/silke-form-schema/silke-schema-context.d.ts +1 -1
- package/dist/silke/src/components/silke-iframe-portal/silke-iframe-context.d.ts +0 -1
- package/dist/silke/src/components/silke-sortable-list/silke-nested-sortable-utils.d.ts +0 -1
- package/dist/silke/src/components/silke-table/table-types.d.ts +0 -1
- package/dist/silke/src/components/silke-tag/silke-tag.d.ts +8 -8
- package/dist/silke/src/components/silke-text/silke-text.d.ts +11 -11
- package/dist/silke/src/components/silke-text-field/silke-text-field-outline.d.ts +0 -3
- package/dist/silke/src/components/silke-tooltip/silke-shortcuts.d.ts +2 -33
- package/dist/silke/src/components/silke-variables-wrapper/index.d.ts +1 -0
- package/dist/silke/src/components/silke-variables-wrapper/silke-variables-wrapper-form.d.ts +12 -0
- package/dist/silke/src/components/silke-variables-wrapper/silke-variables-wrapper.d.ts +22 -0
- package/dist/silke/src/docs/data/app/constants.d.ts +0 -1
- package/dist/silke/src/hooks/use-mouse.d.ts +0 -1
- package/dist/styles.css +235 -212
- package/dist/utils/src/css/number-format.d.ts +1 -1
- package/dist/utils/src/index.d.ts +0 -2
- package/dist/utils/src/keyboard/hooks.d.ts +0 -1
- package/dist/utils/src/mouse/mouse-manager.d.ts +0 -1
- package/dist/utils/src/types/event.d.ts +1 -2
- package/dist/utils/src/types/index.d.ts +0 -1
- package/dist/utils/src/types/vev-props.d.ts +1 -1
- package/esbuild.config.mjs +3 -3
- package/package.json +3 -3
- package/src/components/index.ts +1 -0
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +7 -2
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +40 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +6 -2
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +22 -425
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup.tsx +486 -0
- package/src/components/silke-button/silke-button.mdx +24 -0
- package/src/components/silke-button/silke-dropdown-button.tsx +2 -2
- package/src/components/silke-context-menu/silke-context-menu.tsx +2 -2
- package/src/components/silke-css-number-field/index.ts +0 -1
- package/src/components/silke-css-number-field/silke-css-context.tsx +7 -1
- package/src/components/silke-css-number-field/silke-css-number-field.mdx +3 -3
- package/src/components/silke-css-number-field/silke-css-number-field.scss +0 -12
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +18 -101
- package/src/components/silke-css-number-field/utils.ts +5 -1
- package/src/components/silke-form-schema/fields/string-field.tsx +7 -2
- package/src/components/silke-form-schema/safe-eval/iframe-handler.ts +1 -0
- package/src/components/silke-icon/silke-icon.tsx +7 -3
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +2 -2
- package/src/components/silke-text-field/silke-text-field-outline.tsx +0 -17
- package/src/components/silke-text-field/silke-text-field.scss +1 -58
- package/src/components/silke-text-field/silke-text-field.tsx +0 -6
- package/src/components/silke-variables-wrapper/index.ts +1 -0
- package/src/components/silke-variables-wrapper/silke-variables-wrapper-form.tsx +64 -0
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.mdx +126 -0
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.scss +72 -0
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +260 -0
- package/src/components/silke-virtual/silke-virtual-row.tsx +9 -6
- package/src/hooks/use-drop-zone.ts +1 -1
- package/src/hooks/use-mouse.ts +11 -4
- package/src/hooks/use-size.ts +14 -11
- package/dist/chunk-PP74IZDW.js +0 -22
- package/dist/chunk-PP74IZDW.js.LEGAL.txt +0 -11
- package/dist/chunk-PP74IZDW.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/silke/src/components/silke-css-number-field/variable-picker.d.ts +0 -17
- package/dist/silke-code-editor-LK4ESGQO.js +0 -25
- package/dist/silke-code-editor-LK4ESGQO.js.LEGAL.txt +0 -0
- package/dist/silke-code-editor-LK4ESGQO.js.map +0 -7
- package/dist/utils/src/events/condition-parser/evaluate-condition-expression.d.ts +0 -2
- package/dist/utils/src/events/condition-parser/index.d.ts +0 -1
- package/dist/utils/src/events/condition-parser/lexer.d.ts +0 -37
- package/dist/utils/src/events/condition-parser/parser.d.ts +0 -11
- package/dist/utils/src/interactions/get-interaction-map.d.ts +0 -3
- package/dist/utils/src/interactions/get-node-type.d.ts +0 -2
- package/dist/utils/src/interactions/has-link.d.ts +0 -5
- package/dist/utils/src/interactions/has-pointer-event.d.ts +0 -5
- package/dist/utils/src/interactions/index.d.ts +0 -7
- package/dist/utils/src/interactions/interaction-map-to-array.d.ts +0 -2
- package/dist/utils/src/interactions/is-target-global.d.ts +0 -2
- package/dist/utils/src/interactions/is-trigger-global.d.ts +0 -2
- package/dist/utils/src/types/interaction.d.ts +0 -93
- package/src/components/silke-css-number-field/variable-picker.tsx +0 -181
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Variables Wrapper
|
|
2
|
+
|
|
3
|
+
## Wrapping SilkeCssNumberField
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const [value, setValue] = React.useState("0px");
|
|
7
|
+
|
|
8
|
+
const formats = ["px", "%"];
|
|
9
|
+
|
|
10
|
+
<SilkeCSSContext
|
|
11
|
+
viewport={[1920, 1080]}
|
|
12
|
+
fontSize={18}
|
|
13
|
+
container={[200, 150]}
|
|
14
|
+
variablesv2={[
|
|
15
|
+
{ key: "A", name: "size-xs", value: "10", unit: "px" },
|
|
16
|
+
{ key: "B", name: "size-s", value: "50", unit: "px" },
|
|
17
|
+
{ key: "C", name: "size-m", value: "100", unit: "px" },
|
|
18
|
+
]}
|
|
19
|
+
>
|
|
20
|
+
<SilkeBox>
|
|
21
|
+
<SilkeBox column gap="xl">
|
|
22
|
+
<SilkeBox gap="l">
|
|
23
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
24
|
+
<SilkeVariablesWrapper
|
|
25
|
+
key={kind}
|
|
26
|
+
component={SilkeCssNumberField}
|
|
27
|
+
kind={kind}
|
|
28
|
+
value={value}
|
|
29
|
+
formats={formats}
|
|
30
|
+
label={kind}
|
|
31
|
+
onChange={setValue}
|
|
32
|
+
hasLabelTop
|
|
33
|
+
flex
|
|
34
|
+
/>
|
|
35
|
+
))}
|
|
36
|
+
</SilkeBox>
|
|
37
|
+
<SilkeBox gap="l">
|
|
38
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
39
|
+
<TextFieldContext inline="label-inside" size="xs" key={kind}>
|
|
40
|
+
<SilkeVariablesWrapper
|
|
41
|
+
component={SilkeCssNumberField}
|
|
42
|
+
value={value}
|
|
43
|
+
kind={kind}
|
|
44
|
+
formats={formats}
|
|
45
|
+
label={kind}
|
|
46
|
+
axis="x"
|
|
47
|
+
label="X"
|
|
48
|
+
onChange={setValue}
|
|
49
|
+
/>
|
|
50
|
+
</TextFieldContext>
|
|
51
|
+
))}
|
|
52
|
+
</SilkeBox>
|
|
53
|
+
<SilkeBox gap="l">
|
|
54
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
55
|
+
<TextFieldContext size="xs" key={kind}>
|
|
56
|
+
<SilkeVariablesWrapper
|
|
57
|
+
component={SilkeCssNumberField}
|
|
58
|
+
value={value}
|
|
59
|
+
kind={kind}
|
|
60
|
+
formats={formats}
|
|
61
|
+
label={kind}
|
|
62
|
+
axis="x"
|
|
63
|
+
label="X"
|
|
64
|
+
hasLabelTop
|
|
65
|
+
onChange={setValue}
|
|
66
|
+
/>
|
|
67
|
+
</TextFieldContext>
|
|
68
|
+
))}
|
|
69
|
+
</SilkeBox>
|
|
70
|
+
</SilkeBox>
|
|
71
|
+
</SilkeBox>
|
|
72
|
+
</SilkeCSSContext>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Wrapping SilkeInput
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const [value, setValue] = React.useState("0px");
|
|
79
|
+
|
|
80
|
+
const formats = ["px", "%"];
|
|
81
|
+
|
|
82
|
+
<SilkeCSSContext
|
|
83
|
+
viewport={[1920, 1080]}
|
|
84
|
+
fontSize={18}
|
|
85
|
+
container={[200, 150]}
|
|
86
|
+
variablesv2={[
|
|
87
|
+
{ key: "D", name: "size-xs", value: "10", unit: "px" },
|
|
88
|
+
{ key: "E", name: "size-s", value: "50", unit: "px" },
|
|
89
|
+
{ key: "F", name: "size-m", value: "100", unit: "px" },
|
|
90
|
+
]}
|
|
91
|
+
>
|
|
92
|
+
<SilkeBox>
|
|
93
|
+
<SilkeBox column gap="xl">
|
|
94
|
+
<SilkeBox gap="l" style={{ width: 400 }}>
|
|
95
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
96
|
+
<SilkeVariablesWrapper
|
|
97
|
+
key={kind}
|
|
98
|
+
component={SilkeTextField}
|
|
99
|
+
value={value}
|
|
100
|
+
kind={kind}
|
|
101
|
+
onChange={setValue}
|
|
102
|
+
formats={formats}
|
|
103
|
+
label={kind}
|
|
104
|
+
hasLabelTop
|
|
105
|
+
/>
|
|
106
|
+
))}
|
|
107
|
+
</SilkeBox>
|
|
108
|
+
<SilkeBox gap="l">
|
|
109
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
110
|
+
<TextFieldContext inline="label-inside" size="xs" key={kind}>
|
|
111
|
+
<SilkeVariablesWrapper
|
|
112
|
+
value={value}
|
|
113
|
+
component={SilkeTextField}
|
|
114
|
+
onChange={setValue}
|
|
115
|
+
formats={formats}
|
|
116
|
+
label={kind}
|
|
117
|
+
kind={kind}
|
|
118
|
+
inline="label-inside"
|
|
119
|
+
/>
|
|
120
|
+
</TextFieldContext>
|
|
121
|
+
))}
|
|
122
|
+
</SilkeBox>
|
|
123
|
+
</SilkeBox>
|
|
124
|
+
</SilkeBox>
|
|
125
|
+
</SilkeCSSContext>;
|
|
126
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
@use "../../variables" as *;
|
|
2
|
+
|
|
3
|
+
.wrapper {
|
|
4
|
+
position: relative;
|
|
5
|
+
|
|
6
|
+
&:hover .variableDot:before {
|
|
7
|
+
opacity: 1;
|
|
8
|
+
transform: scale(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Style border of wrapped children when open
|
|
12
|
+
&[data-open="true"] *::after {
|
|
13
|
+
--current-border-color: var(--color-support-tertiary-40) !important;
|
|
14
|
+
--text-field-border-color: var(--color-support-tertiary-40) !important;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Style border of children when hovered
|
|
18
|
+
&[data-is-variable="true"]:hover *::after {
|
|
19
|
+
--current-border-color: var(--color-support-tertiary-40) !important;
|
|
20
|
+
--text-field-border-color: var(--color-support-tertiary-40) !important;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&[data-full-width="true"] {
|
|
24
|
+
width: 100%;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.variableDot {
|
|
29
|
+
position: absolute;
|
|
30
|
+
left: 0px;
|
|
31
|
+
top: 0px;
|
|
32
|
+
width: 12px;
|
|
33
|
+
height: 12px;
|
|
34
|
+
padding: 0;
|
|
35
|
+
z-index: 1;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
|
|
38
|
+
&:after,
|
|
39
|
+
&:before {
|
|
40
|
+
content: "";
|
|
41
|
+
position: absolute;
|
|
42
|
+
width: 12px;
|
|
43
|
+
height: 12px;
|
|
44
|
+
border-radius: 50%;
|
|
45
|
+
background: var(--color-neutral-100);
|
|
46
|
+
margin-top: -6px;
|
|
47
|
+
margin-left: -6px;
|
|
48
|
+
border: 4px solid var(--color-support-tertiary-40);
|
|
49
|
+
opacity: 0;
|
|
50
|
+
transform-origin: center center;
|
|
51
|
+
transition: transform 0.2s ease;
|
|
52
|
+
}
|
|
53
|
+
&:before {
|
|
54
|
+
transform: scale(0);
|
|
55
|
+
transform-origin: center center;
|
|
56
|
+
transition: opacity 0.2s ease, transform 0.2s ease;
|
|
57
|
+
}
|
|
58
|
+
&:after {
|
|
59
|
+
content: attr(data-icon);
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
line-height: 0;
|
|
64
|
+
font-weight: bold;
|
|
65
|
+
background: var(--color-support-tertiary-40);
|
|
66
|
+
transition: opacity 0.2s ease;
|
|
67
|
+
}
|
|
68
|
+
&:hover:after {
|
|
69
|
+
transform: scale(1.2);
|
|
70
|
+
opacity: 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
|
+
import { SilkeAutocompleteField } from '../silke-autocomplete-field';
|
|
3
|
+
import { useSilkeCSSContext } from '../silke-css-number-field';
|
|
4
|
+
import { SilkeBox } from '../silke-box';
|
|
5
|
+
import { SilkeAutocompletePopup } from '../silke-autocomplete-field/silke-autocomplete-popup';
|
|
6
|
+
import { SilkeTextMicro, SilkeTextSmall } from '../silke-text';
|
|
7
|
+
import { SilkeButton } from '../silke-button';
|
|
8
|
+
import styles from './silke-variables-wrapper.scss';
|
|
9
|
+
import { useTextFieldContext } from '../silke-text-field/text-field-context';
|
|
10
|
+
import { getCSSNumberFormat } from '@vev/utils';
|
|
11
|
+
import { SilkeIcon } from '../silke-icon';
|
|
12
|
+
import { capitalize } from 'lodash';
|
|
13
|
+
import { SilkeVariablesWrapperForm } from './silke-variables-wrapper-form';
|
|
14
|
+
|
|
15
|
+
export type LocalVariable = {
|
|
16
|
+
key: string;
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
value?: string;
|
|
20
|
+
unit?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getRelevantVariables = (
|
|
24
|
+
variables: LocalVariable[],
|
|
25
|
+
formats: string[],
|
|
26
|
+
variableType?: string,
|
|
27
|
+
) => {
|
|
28
|
+
// If type is defined, filter by type. Then filter out units.
|
|
29
|
+
return variables
|
|
30
|
+
.filter((v) => (variableType ? v.type === variableType : true))
|
|
31
|
+
.filter((v) => (formats.length ? formats.includes(v.unit || '') : true));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getVariableIcon = (type: string) => {
|
|
35
|
+
return type === 'color' ? 'variable.color' : 'hashtag';
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getVariableValue = (variable: string, variables: { key: string; value?: string }[]) => {
|
|
39
|
+
return variables.find((v) => variable.includes(v.key))?.value;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const getVariableUnit = (variable: string, variables: { key: string; unit?: string }[]) => {
|
|
43
|
+
return variables.find((v) => variable.includes(v.key))?.unit;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getVariableDisplayText = (variableType: string, variable?: LocalVariable) => {
|
|
47
|
+
// For number variables, show the value and unit
|
|
48
|
+
if (variableType === 'number') {
|
|
49
|
+
return `${variable?.value || '0'}${variable?.unit || ''}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// For everything else, show the variable name
|
|
53
|
+
return variable?.name || '0';
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type SilkeVariablesWrapperProps<T extends React.ElementType> = {
|
|
57
|
+
component?: T;
|
|
58
|
+
value: string;
|
|
59
|
+
formats?: string[];
|
|
60
|
+
variableType?: string;
|
|
61
|
+
fullWidthWrapper?: boolean;
|
|
62
|
+
onChange: (value: string) => void; // return key?
|
|
63
|
+
onVariableAdd?: (variable: LocalVariable) => Promise<string>;
|
|
64
|
+
onVariableEdit?: (key: string) => void;
|
|
65
|
+
} & React.ComponentProps<T>;
|
|
66
|
+
|
|
67
|
+
export function SilkeVariablesWrapper<T extends React.ElementType>(
|
|
68
|
+
props: SilkeVariablesWrapperProps<T>,
|
|
69
|
+
) {
|
|
70
|
+
const [openVariables, setOpenVariables] = useState(false);
|
|
71
|
+
const [showAddNewForm, setShowAddNewForm] = useState(false);
|
|
72
|
+
const [newVariableName, setNewVariableName] = useState('');
|
|
73
|
+
|
|
74
|
+
const { value, formats = [], variableType, onChange, component, ...rest } = props;
|
|
75
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
76
|
+
const context = useSilkeCSSContext();
|
|
77
|
+
const textFieldContext = useTextFieldContext();
|
|
78
|
+
const [hoveredItem, setHoveredItem] = useState<string | null>(null);
|
|
79
|
+
|
|
80
|
+
const variables = React.useMemo(() => {
|
|
81
|
+
return getRelevantVariables(context.variablesv2, formats, variableType);
|
|
82
|
+
}, [context.variablesv2, formats, variableType]);
|
|
83
|
+
|
|
84
|
+
const variableItems = React.useMemo(() => {
|
|
85
|
+
return variables.map((v) => ({
|
|
86
|
+
label: v.name,
|
|
87
|
+
value: v.key,
|
|
88
|
+
subLabel: `${v.value}${v.unit ? `${v.unit}` : ''}`,
|
|
89
|
+
icon: getVariableIcon(v.type),
|
|
90
|
+
}));
|
|
91
|
+
}, [variables]);
|
|
92
|
+
|
|
93
|
+
const isVariable = value?.startsWith('var(--vev-');
|
|
94
|
+
const hasVariables = variables.length > 0;
|
|
95
|
+
const currentVariable = variables.find((v) => value?.includes(v.key));
|
|
96
|
+
const hasLabelTop =
|
|
97
|
+
rest.label && rest.inline !== 'label-inside' && textFieldContext.inline !== 'label-inside';
|
|
98
|
+
const offsetPx = rest.size === 'xs' || textFieldContext.size === 'xs' ? 16 : 18;
|
|
99
|
+
|
|
100
|
+
const handleVariablesDotClicked = (e: React.MouseEvent) => {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
|
|
103
|
+
// If active variable, remove link and set to native value
|
|
104
|
+
if (isVariable) {
|
|
105
|
+
const variable = variables.find((v) => value?.includes(v.key));
|
|
106
|
+
onChange(variable ? `${variable.value}${variable.unit || ''}` : '0');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setOpenVariables(true);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const onShowAddForm = () => {
|
|
114
|
+
setOpenVariables(false);
|
|
115
|
+
setShowAddNewForm(true);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const onHideAddForm = () => {
|
|
119
|
+
setShowAddNewForm(false);
|
|
120
|
+
setOpenVariables(true);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const handleVariableAdd = async () => {
|
|
124
|
+
const newVariable = {
|
|
125
|
+
type: variableType,
|
|
126
|
+
name: newVariableName ? newVariableName : capitalize(variableType),
|
|
127
|
+
value: isVariable ? getVariableValue(value, context.variablesv2) || '0' : value,
|
|
128
|
+
unit: '',
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (variableType === 'number') {
|
|
132
|
+
newVariable.value = isVariable
|
|
133
|
+
? getVariableValue(value, context.variablesv2) || '0'
|
|
134
|
+
: String(parseFloat(value || '0'));
|
|
135
|
+
newVariable.unit = isVariable
|
|
136
|
+
? getVariableUnit(value, context.variablesv2) || ''
|
|
137
|
+
: getCSSNumberFormat(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const newKey = await props.onVariableAdd?.(newVariable);
|
|
141
|
+
|
|
142
|
+
if (newKey) {
|
|
143
|
+
onChange(`var(--vev-${newKey})`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setShowAddNewForm(false);
|
|
147
|
+
setNewVariableName('');
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const itemRender = (item: any) => (
|
|
151
|
+
<SilkeBox
|
|
152
|
+
key={`${item.label}-${item.value}`}
|
|
153
|
+
gap="s"
|
|
154
|
+
hPad="s"
|
|
155
|
+
vAlign="center"
|
|
156
|
+
overflow="hidden"
|
|
157
|
+
onMouseEnter={() => setHoveredItem(item.value)}
|
|
158
|
+
onMouseLeave={() => setHoveredItem(null)}
|
|
159
|
+
fill
|
|
160
|
+
>
|
|
161
|
+
<SilkeBox
|
|
162
|
+
size="xs"
|
|
163
|
+
hAlign
|
|
164
|
+
vAlign
|
|
165
|
+
rounded="tiny"
|
|
166
|
+
style={variableType === 'color' ? { backgroundColor: item.subLabel } : undefined}
|
|
167
|
+
>
|
|
168
|
+
{variableType !== 'color' && <SilkeIcon color="neutral-70" icon={item.icon} />}
|
|
169
|
+
</SilkeBox>
|
|
170
|
+
|
|
171
|
+
<SilkeBox column style={{ minWidth: '0', flex: 1 }}>
|
|
172
|
+
<SilkeTextSmall overflow>{item.label}</SilkeTextSmall>
|
|
173
|
+
<SilkeTextMicro overflow color="neutral-60">
|
|
174
|
+
{item.subLabel}
|
|
175
|
+
</SilkeTextMicro>
|
|
176
|
+
</SilkeBox>
|
|
177
|
+
|
|
178
|
+
{hoveredItem === item.value && props.onVariableEdit && (
|
|
179
|
+
<SilkeBox>
|
|
180
|
+
<SilkeButton
|
|
181
|
+
icon="settings"
|
|
182
|
+
kind="ghost"
|
|
183
|
+
size="s"
|
|
184
|
+
onMouseDown={(e) => {
|
|
185
|
+
e.preventDefault;
|
|
186
|
+
e.stopPropagation();
|
|
187
|
+
props.onVariableEdit?.(item.value);
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
</SilkeBox>
|
|
191
|
+
)}
|
|
192
|
+
</SilkeBox>
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<div
|
|
197
|
+
className={styles.wrapper}
|
|
198
|
+
ref={rootRef}
|
|
199
|
+
data-open={openVariables || showAddNewForm}
|
|
200
|
+
data-is-variable={isVariable}
|
|
201
|
+
data-full-width={props.fullWidthWrapper}
|
|
202
|
+
>
|
|
203
|
+
{hasVariables && (
|
|
204
|
+
<div
|
|
205
|
+
className={styles.variableDot}
|
|
206
|
+
data-icon={isVariable ? '−' : '+'}
|
|
207
|
+
onClick={handleVariablesDotClicked}
|
|
208
|
+
style={{ top: hasLabelTop ? offsetPx : 0 }}
|
|
209
|
+
/>
|
|
210
|
+
)}
|
|
211
|
+
{isVariable ? (
|
|
212
|
+
<SilkeAutocompleteField
|
|
213
|
+
{...props}
|
|
214
|
+
isVariable
|
|
215
|
+
items={variableItems}
|
|
216
|
+
renderItem={({ item }) => itemRender(item)}
|
|
217
|
+
value={getVariableDisplayText(variableType, currentVariable)}
|
|
218
|
+
selectedVariableKey={currentVariable?.key}
|
|
219
|
+
dropDownMinWidth={168}
|
|
220
|
+
dropDownMaxWidth={168}
|
|
221
|
+
width={props.width}
|
|
222
|
+
onChange={(value: string) => onChange(`var(--vev-${value})`)}
|
|
223
|
+
disableAddFromList
|
|
224
|
+
/>
|
|
225
|
+
) : (
|
|
226
|
+
<div>
|
|
227
|
+
{component && React.createElement(component, { value, formats, onChange, ...rest })}
|
|
228
|
+
</div>
|
|
229
|
+
)}
|
|
230
|
+
|
|
231
|
+
{openVariables && (
|
|
232
|
+
<SilkeAutocompletePopup
|
|
233
|
+
containerRef={rootRef}
|
|
234
|
+
renderItem={({ item }) => itemRender(item)}
|
|
235
|
+
dropDownMinWidth={168}
|
|
236
|
+
dropDownMaxWidth={168}
|
|
237
|
+
items={variableItems}
|
|
238
|
+
value={currentVariable?.name}
|
|
239
|
+
onAdd={onShowAddForm}
|
|
240
|
+
onChange={(value: string) => onChange(`var(--vev-${value})`)}
|
|
241
|
+
onRequestClose={() => setOpenVariables(false)}
|
|
242
|
+
showAddIcon={!!props.onVariableAdd}
|
|
243
|
+
disableAddFromList
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
|
|
247
|
+
{showAddNewForm && (
|
|
248
|
+
<SilkeVariablesWrapperForm
|
|
249
|
+
containerRef={rootRef}
|
|
250
|
+
value={newVariableName}
|
|
251
|
+
onChange={(value) => setNewVariableName(value)}
|
|
252
|
+
onSubmit={handleVariableAdd}
|
|
253
|
+
onClose={onHideAddForm}
|
|
254
|
+
/>
|
|
255
|
+
)}
|
|
256
|
+
</div>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
SilkeVariablesWrapper.displayName = 'SilkeVariablesWrapper';
|
|
@@ -18,14 +18,17 @@ function findListener(el: HTMLElement): ObserverListener | undefined {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
for (const t of e) {
|
|
23
|
-
const listener = findListener(t.target as HTMLElement);
|
|
24
|
-
if (listener) listener[1](t.isIntersecting);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
21
|
+
let observer: IntersectionObserver;
|
|
27
22
|
|
|
28
23
|
function observe(el: HTMLDivElement, onVisible: (visible: boolean) => void): () => void {
|
|
24
|
+
if (!observer) {
|
|
25
|
+
observer = new IntersectionObserver((e) => {
|
|
26
|
+
for (const t of e) {
|
|
27
|
+
const listener = findListener(t.target as HTMLElement);
|
|
28
|
+
if (listener) listener[1](t.isIntersecting);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
29
32
|
observer.observe(el);
|
|
30
33
|
const pair: ObserverListener = [el, onVisible];
|
|
31
34
|
listeners.push(pair);
|
package/src/hooks/use-mouse.ts
CHANGED
|
@@ -77,15 +77,22 @@ const downListeners: MouseListener[] = [];
|
|
|
77
77
|
const upListeners: MouseListener[] = [];
|
|
78
78
|
const moveListeners: MouseListener[] = [];
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
let initializedListeners = false;
|
|
81
|
+
|
|
82
|
+
function initListeners() {
|
|
83
|
+
if (initializedListeners) return;
|
|
84
|
+
initializedListeners = true;
|
|
85
|
+
|
|
86
|
+
document.addEventListener('mousedown', emit(downListeners), { passive: true });
|
|
87
|
+
document.addEventListener('mousemove', emit(moveListeners), { passive: true });
|
|
88
|
+
document.addEventListener('mouseup', emit(upListeners), { passive: true });
|
|
89
|
+
}
|
|
84
90
|
|
|
85
91
|
function useMouse(cb: MouseListener, disabled: boolean, listeners: MouseListener[]) {
|
|
86
92
|
const cbRef = useCallbackRef(cb);
|
|
87
93
|
useEffect(() => {
|
|
88
94
|
if (disabled) return;
|
|
95
|
+
initListeners();
|
|
89
96
|
const handler = (e: MouseStateEvent) => cbRef.current(e);
|
|
90
97
|
listeners.push(handler);
|
|
91
98
|
return () => {
|
package/src/hooks/use-size.ts
CHANGED
|
@@ -3,17 +3,7 @@ import { RefObject, useEffect, useRef } from 'react';
|
|
|
3
3
|
type SizeCallback = (entry: ResizeObserverEntry) => void;
|
|
4
4
|
type Listener = [el: HTMLElement, cb: SizeCallback];
|
|
5
5
|
const listeners: Listener[] = [];
|
|
6
|
-
|
|
7
|
-
// Setting timeout to ensure the callbacks dose not block the currentAnimation frame
|
|
8
|
-
// will cause ResizeObserver limit exception if callback uses to long time
|
|
9
|
-
self.setTimeout(() => {
|
|
10
|
-
for (const entry of entries) {
|
|
11
|
-
for (const [el, cb] of listeners) {
|
|
12
|
-
if (entry.target === el) cb(entry);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}, 10);
|
|
16
|
-
});
|
|
6
|
+
let observer: ResizeObserver;
|
|
17
7
|
|
|
18
8
|
export function useSize(ref: RefObject<HTMLElement>, cb: SizeCallback) {
|
|
19
9
|
const cbRef = useRef(cb);
|
|
@@ -22,6 +12,19 @@ export function useSize(ref: RefObject<HTMLElement>, cb: SizeCallback) {
|
|
|
22
12
|
const el = ref.current;
|
|
23
13
|
useEffect(() => {
|
|
24
14
|
if (el) {
|
|
15
|
+
if (!observer) {
|
|
16
|
+
observer = new ResizeObserver((entries) => {
|
|
17
|
+
// Setting timeout to ensure the callbacks dose not block the currentAnimation frame
|
|
18
|
+
// will cause ResizeObserver limit exception if callback uses to long time
|
|
19
|
+
self.setTimeout(() => {
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
for (const [el, cb] of listeners) {
|
|
22
|
+
if (entry.target === el) cb(entry);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, 10);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
25
28
|
observer.observe(el);
|
|
26
29
|
const listener: Listener = [el, (entry) => cbRef.current(entry)];
|
|
27
30
|
listeners.push(listener);
|