@elementor/editor-interactions 4.0.0-538 → 4.0.0-540
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/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +130 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +136 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/components/controls/time-frame-indicator.tsx +24 -19
- package/src/components/interaction-details.tsx +10 -9
- package/src/configs/time-constants.ts +5 -0
- package/src/providers/document-elements-interactions-provider.ts +5 -1
- package/src/providers/utils/normalize-interactions.ts +65 -0
- package/src/types.ts +5 -0
- package/src/utils/prop-value-utils.ts +28 -19
- package/src/utils/size-transform-utils.ts +67 -0
- package/src/utils/time-conversion.ts +10 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
+
import { Unit } from '@elementor/editor-controls';
|
|
3
4
|
import { ElementInteractions, InteractionItemPropValue } from '@elementor/editor-elements';
|
|
4
5
|
export { AnimationPresetPropValue, BooleanPropValue, ConfigPropValue, ElementInteractions, ExcludedBreakpointsPropValue, InteractionBreakpointsPropValue, InteractionItemPropValue, NumberPropValue, StringPropValue, TimingConfigPropValue } from '@elementor/editor-elements';
|
|
5
6
|
|
|
@@ -54,6 +55,8 @@ type InteractionsProvider = {
|
|
|
54
55
|
};
|
|
55
56
|
};
|
|
56
57
|
type InteractionItemValue = InteractionItemPropValue['value'];
|
|
58
|
+
type TimeUnit = Extract<Unit, 'ms' | 's'>;
|
|
59
|
+
type TimeValue = `${number}${TimeUnit}` | number;
|
|
57
60
|
|
|
58
61
|
declare function getInteractionsConfig(): InteractionsConfig;
|
|
59
62
|
|
|
@@ -100,4 +103,4 @@ type ControlOptions<T extends InteractionsControlType> = {
|
|
|
100
103
|
};
|
|
101
104
|
declare function registerInteractionsControl<T extends InteractionsControlType>({ type, component, options, }: ControlOptions<T>): void;
|
|
102
105
|
|
|
103
|
-
export { type AnimationOption, type CreateInteractionsProviderOptions, type DirectionFieldProps, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, type ElementInteractionData, EmptyState, type FieldProps, type InteractionConstants, type InteractionItemValue, type InteractionsCollection, type InteractionsConfig, type InteractionsProvider, InteractionsTab, type ReplayFieldProps, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository, registerInteractionsControl };
|
|
106
|
+
export { type AnimationOption, type CreateInteractionsProviderOptions, type DirectionFieldProps, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, type ElementInteractionData, EmptyState, type FieldProps, type InteractionConstants, type InteractionItemValue, type InteractionsCollection, type InteractionsConfig, type InteractionsProvider, InteractionsTab, type ReplayFieldProps, type TimeUnit, type TimeValue, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository, registerInteractionsControl };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
+
import { Unit } from '@elementor/editor-controls';
|
|
3
4
|
import { ElementInteractions, InteractionItemPropValue } from '@elementor/editor-elements';
|
|
4
5
|
export { AnimationPresetPropValue, BooleanPropValue, ConfigPropValue, ElementInteractions, ExcludedBreakpointsPropValue, InteractionBreakpointsPropValue, InteractionItemPropValue, NumberPropValue, StringPropValue, TimingConfigPropValue } from '@elementor/editor-elements';
|
|
5
6
|
|
|
@@ -54,6 +55,8 @@ type InteractionsProvider = {
|
|
|
54
55
|
};
|
|
55
56
|
};
|
|
56
57
|
type InteractionItemValue = InteractionItemPropValue['value'];
|
|
58
|
+
type TimeUnit = Extract<Unit, 'ms' | 's'>;
|
|
59
|
+
type TimeValue = `${number}${TimeUnit}` | number;
|
|
57
60
|
|
|
58
61
|
declare function getInteractionsConfig(): InteractionsConfig;
|
|
59
62
|
|
|
@@ -100,4 +103,4 @@ type ControlOptions<T extends InteractionsControlType> = {
|
|
|
100
103
|
};
|
|
101
104
|
declare function registerInteractionsControl<T extends InteractionsControlType>({ type, component, options, }: ControlOptions<T>): void;
|
|
102
105
|
|
|
103
|
-
export { type AnimationOption, type CreateInteractionsProviderOptions, type DirectionFieldProps, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, type ElementInteractionData, EmptyState, type FieldProps, type InteractionConstants, type InteractionItemValue, type InteractionsCollection, type InteractionsConfig, type InteractionsProvider, InteractionsTab, type ReplayFieldProps, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository, registerInteractionsControl };
|
|
106
|
+
export { type AnimationOption, type CreateInteractionsProviderOptions, type DirectionFieldProps, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, type ElementInteractionData, EmptyState, type FieldProps, type InteractionConstants, type InteractionItemValue, type InteractionsCollection, type InteractionsConfig, type InteractionsProvider, InteractionsTab, type ReplayFieldProps, type TimeUnit, type TimeValue, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository, registerInteractionsControl };
|
package/dist/index.js
CHANGED
|
@@ -155,6 +155,56 @@ function useInteractionItemContext() {
|
|
|
155
155
|
return context;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
// src/utils/prop-value-utils.ts
|
|
159
|
+
var import_editor_props = require("@elementor/editor-props");
|
|
160
|
+
|
|
161
|
+
// src/configs/time-constants.ts
|
|
162
|
+
var TIME_UNITS = ["s", "ms"];
|
|
163
|
+
var DEFAULT_TIME_UNIT = "ms";
|
|
164
|
+
|
|
165
|
+
// src/utils/size-transform-utils.ts
|
|
166
|
+
var SIZE_REGEX = /^(?:(-?\d*\.?\d+)([a-z%]+)|([a-z%]+))$/i;
|
|
167
|
+
var parseSizeValue = (value, allowedUnits, defaultValue, defaultUnit) => {
|
|
168
|
+
if (typeof value === "number") {
|
|
169
|
+
return {
|
|
170
|
+
size: value,
|
|
171
|
+
unit: defaultUnit
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const sizeValue = tryParse(value, allowedUnits, defaultUnit);
|
|
175
|
+
if (sizeValue) {
|
|
176
|
+
return sizeValue;
|
|
177
|
+
}
|
|
178
|
+
if (defaultValue) {
|
|
179
|
+
const fallbackSize = tryParse(defaultValue, allowedUnits, defaultUnit);
|
|
180
|
+
if (fallbackSize) {
|
|
181
|
+
return fallbackSize;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return createSizeValue(null, defaultUnit);
|
|
185
|
+
};
|
|
186
|
+
var tryParse = (value, allowedUnits, defaultUnit) => {
|
|
187
|
+
if (typeof value === "number") {
|
|
188
|
+
return createSizeValue(value, defaultUnit);
|
|
189
|
+
}
|
|
190
|
+
const match = value && value.match(SIZE_REGEX);
|
|
191
|
+
if (!match) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const size = match[1] ? parseFloat(match[1]) : null;
|
|
195
|
+
const unit = match[2] || match[3];
|
|
196
|
+
if (!allowedUnits.includes(unit)) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
return createSizeValue(size, unit);
|
|
200
|
+
};
|
|
201
|
+
var formatSizeValue = ({ size, unit }) => {
|
|
202
|
+
return `${size ?? ""}${unit}`;
|
|
203
|
+
};
|
|
204
|
+
var createSizeValue = (size, unit) => {
|
|
205
|
+
return { size, unit };
|
|
206
|
+
};
|
|
207
|
+
|
|
158
208
|
// src/utils/temp-id-utils.ts
|
|
159
209
|
var TEMP_ID_PREFIX = "temp-";
|
|
160
210
|
function generateTempInteractionId() {
|
|
@@ -173,8 +223,8 @@ var createNumber = (value) => ({
|
|
|
173
223
|
var createTimingConfig = (duration, delay) => ({
|
|
174
224
|
$$type: "timing-config",
|
|
175
225
|
value: {
|
|
176
|
-
duration:
|
|
177
|
-
delay:
|
|
226
|
+
duration: import_editor_props.sizePropTypeUtil.create(parseSizeValue(duration, TIME_UNITS, void 0, DEFAULT_TIME_UNIT)),
|
|
227
|
+
delay: import_editor_props.sizePropTypeUtil.create(parseSizeValue(delay, TIME_UNITS, void 0, DEFAULT_TIME_UNIT))
|
|
178
228
|
}
|
|
179
229
|
});
|
|
180
230
|
var createBoolean = (value) => ({
|
|
@@ -291,6 +341,9 @@ var createDefaultInteractionItem = () => {
|
|
|
291
341
|
var extractString = (prop, fallback = "") => {
|
|
292
342
|
return prop?.value ?? fallback;
|
|
293
343
|
};
|
|
344
|
+
var extractSize = (prop) => {
|
|
345
|
+
return formatSizeValue(prop?.value);
|
|
346
|
+
};
|
|
294
347
|
var extractNumber = (prop, fallback = 0) => {
|
|
295
348
|
return prop?.value ?? fallback;
|
|
296
349
|
};
|
|
@@ -430,28 +483,45 @@ function EffectType({ value, onChange }) {
|
|
|
430
483
|
var React8 = __toESM(require("react"));
|
|
431
484
|
var import_react5 = require("react");
|
|
432
485
|
var import_editor_controls3 = require("@elementor/editor-controls");
|
|
433
|
-
|
|
434
|
-
|
|
486
|
+
|
|
487
|
+
// src/utils/time-conversion.ts
|
|
488
|
+
var UNIT_TO_MS = {
|
|
489
|
+
ms: 1,
|
|
490
|
+
s: 1e3
|
|
491
|
+
};
|
|
492
|
+
var convertTimeUnit = (value, from, to) => {
|
|
493
|
+
return value * UNIT_TO_MS[from] / UNIT_TO_MS[to];
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// src/components/controls/time-frame-indicator.tsx
|
|
435
497
|
function TimeFrameIndicator({ value, onChange, defaultValue }) {
|
|
436
|
-
const sizeValue =
|
|
498
|
+
const sizeValue = parseSizeValue(value, TIME_UNITS, defaultValue, DEFAULT_TIME_UNIT);
|
|
499
|
+
const prevUnitRef = (0, import_react5.useRef)(sizeValue.unit);
|
|
437
500
|
const setValue = (0, import_react5.useCallback)(
|
|
438
501
|
(size) => {
|
|
439
|
-
|
|
502
|
+
const unitChanged = prevUnitRef.current !== size.unit;
|
|
503
|
+
if (unitChanged) {
|
|
504
|
+
const fromUnit = prevUnitRef.current;
|
|
505
|
+
const toUnit = size.unit;
|
|
506
|
+
size.size = convertTimeUnit(Number(size.size), fromUnit, toUnit);
|
|
507
|
+
prevUnitRef.current = toUnit;
|
|
508
|
+
}
|
|
509
|
+
onChange(formatSizeValue(size));
|
|
440
510
|
},
|
|
441
511
|
[onChange]
|
|
442
512
|
);
|
|
443
513
|
const handleChange = (newValue) => {
|
|
444
|
-
setValue(newValue
|
|
514
|
+
setValue(newValue);
|
|
445
515
|
};
|
|
446
516
|
const handleBlur = () => {
|
|
447
517
|
if (!sizeValue.size) {
|
|
448
|
-
setValue(defaultValue);
|
|
518
|
+
setValue(parseSizeValue(defaultValue, TIME_UNITS, void 0, DEFAULT_TIME_UNIT));
|
|
449
519
|
}
|
|
450
520
|
};
|
|
451
521
|
return /* @__PURE__ */ React8.createElement(
|
|
452
522
|
import_editor_controls3.UnstableSizeField,
|
|
453
523
|
{
|
|
454
|
-
units:
|
|
524
|
+
units: TIME_UNITS,
|
|
455
525
|
value: sizeValue,
|
|
456
526
|
onChange: handleChange,
|
|
457
527
|
onBlur: handleBlur,
|
|
@@ -463,12 +533,6 @@ function TimeFrameIndicator({ value, onChange, defaultValue }) {
|
|
|
463
533
|
}
|
|
464
534
|
);
|
|
465
535
|
}
|
|
466
|
-
var toSizeValue = (value) => {
|
|
467
|
-
return import_editor_props.sizePropTypeUtil.create({
|
|
468
|
-
size: Number(value),
|
|
469
|
-
unit: DEFAULT_UNIT
|
|
470
|
-
}).value;
|
|
471
|
-
};
|
|
472
536
|
|
|
473
537
|
// src/components/interaction-details.tsx
|
|
474
538
|
var DEFAULT_VALUES = {
|
|
@@ -512,8 +576,8 @@ var InteractionDetails = ({ interaction, onChange, onPlayInteraction }) => {
|
|
|
512
576
|
const effect = extractString(interaction.animation.value.effect, DEFAULT_VALUES.effect);
|
|
513
577
|
const type = extractString(interaction.animation.value.type, DEFAULT_VALUES.type);
|
|
514
578
|
const direction = extractString(interaction.animation.value.direction, DEFAULT_VALUES.direction);
|
|
515
|
-
const duration =
|
|
516
|
-
const delay =
|
|
579
|
+
const duration = extractSize(interaction.animation.value.timing_config.value.duration);
|
|
580
|
+
const delay = extractSize(interaction.animation.value.timing_config.value.delay);
|
|
517
581
|
const replay = extractBoolean(interaction.animation.value.config?.value.replay, DEFAULT_VALUES.replay);
|
|
518
582
|
const easing = extractString(interaction.animation.value.config?.value.easing, DEFAULT_VALUES.easing);
|
|
519
583
|
const relativeTo = extractString(interaction.animation.value.config?.value.relativeTo, DEFAULT_VALUES.relativeTo);
|
|
@@ -599,14 +663,14 @@ var InteractionDetails = ({ interaction, onChange, onPlayInteraction }) => {
|
|
|
599
663
|
TimeFrameIndicator,
|
|
600
664
|
{
|
|
601
665
|
value: String(duration),
|
|
602
|
-
onChange: (v) => updateInteraction({ duration:
|
|
666
|
+
onChange: (v) => updateInteraction({ duration: v }),
|
|
603
667
|
defaultValue: DEFAULT_VALUES.duration
|
|
604
668
|
}
|
|
605
669
|
)), controlVisibilityConfig.delay(interactionValues) && /* @__PURE__ */ React9.createElement(Field, { label: (0, import_i18n5.__)("Delay", "elementor") }, /* @__PURE__ */ React9.createElement(
|
|
606
670
|
TimeFrameIndicator,
|
|
607
671
|
{
|
|
608
672
|
value: String(delay),
|
|
609
|
-
onChange: (v) => updateInteraction({ delay:
|
|
673
|
+
onChange: (v) => updateInteraction({ delay: v }),
|
|
610
674
|
defaultValue: DEFAULT_VALUES.delay
|
|
611
675
|
}
|
|
612
676
|
))), controlVisibilityConfig.relativeTo(interactionValues) && RelativeToControl && /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement(import_ui3.Divider, null), /* @__PURE__ */ React9.createElement(import_ui3.Grid, { container: true, spacing: 1.5 }, /* @__PURE__ */ React9.createElement(Field, { label: (0, import_i18n5.__)("Relative To", "elementor") }, /* @__PURE__ */ React9.createElement(
|
|
@@ -946,6 +1010,51 @@ function createInteractionsProvider({
|
|
|
946
1010
|
// src/providers/document-elements-interactions-provider.ts
|
|
947
1011
|
var import_editor_elements3 = require("@elementor/editor-elements");
|
|
948
1012
|
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
1013
|
+
|
|
1014
|
+
// src/providers/utils/normalize-interactions.ts
|
|
1015
|
+
var import_editor_props2 = require("@elementor/editor-props");
|
|
1016
|
+
var FIELD_NORMALIZERS = {
|
|
1017
|
+
size: (value) => {
|
|
1018
|
+
const sizeProp = value;
|
|
1019
|
+
const { size, unit } = sizeProp.value;
|
|
1020
|
+
const numberPropValue = convertTimeUnit(size, unit, "ms");
|
|
1021
|
+
return import_editor_props2.numberPropTypeUtil.create(numberPropValue);
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
var normalizeInteractions = (interactions) => {
|
|
1025
|
+
if (!interactions) {
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (interactions.items.length === 0) {
|
|
1029
|
+
return interactions;
|
|
1030
|
+
}
|
|
1031
|
+
return {
|
|
1032
|
+
...interactions,
|
|
1033
|
+
items: interactions.items.map(normalizeNode)
|
|
1034
|
+
};
|
|
1035
|
+
};
|
|
1036
|
+
var normalizeNode = (node) => {
|
|
1037
|
+
if (Array.isArray(node)) {
|
|
1038
|
+
return node.map(normalizeNode);
|
|
1039
|
+
}
|
|
1040
|
+
if (node !== null && typeof node === "object") {
|
|
1041
|
+
if ((0, import_editor_props2.isTransformable)(node) && node.value !== void 0) {
|
|
1042
|
+
const normalizer = FIELD_NORMALIZERS[node.$$type];
|
|
1043
|
+
if (normalizer) {
|
|
1044
|
+
return normalizer(node);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
const typedNode = node;
|
|
1048
|
+
const out = {};
|
|
1049
|
+
for (const k in typedNode) {
|
|
1050
|
+
out[k] = normalizeNode(typedNode[k]);
|
|
1051
|
+
}
|
|
1052
|
+
return out;
|
|
1053
|
+
}
|
|
1054
|
+
return node;
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
// src/providers/document-elements-interactions-provider.ts
|
|
949
1058
|
var ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX = "document-elements-interactions-";
|
|
950
1059
|
var documentElementsInteractionsProvider = createInteractionsProvider({
|
|
951
1060
|
key: () => {
|
|
@@ -973,10 +1082,11 @@ var documentElementsInteractionsProvider = createInteractionsProvider({
|
|
|
973
1082
|
});
|
|
974
1083
|
return filtered.map((element) => {
|
|
975
1084
|
const interactions = (0, import_editor_elements3.getElementInteractions)(element.id);
|
|
1085
|
+
const normalizedInteractions = normalizeInteractions(interactions);
|
|
976
1086
|
return {
|
|
977
1087
|
elementId: element.id,
|
|
978
1088
|
dataId: element.id,
|
|
979
|
-
interactions:
|
|
1089
|
+
interactions: normalizedInteractions || { version: 1, items: [] }
|
|
980
1090
|
};
|
|
981
1091
|
});
|
|
982
1092
|
}
|