@elementor/editor-interactions 4.0.0-636 → 4.0.0-637

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 CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { RefObject, ComponentType } from 'react';
3
- import { ElementInteractions } from '@elementor/editor-elements';
3
+ import { Unit } from '@elementor/editor-controls';
4
+ import { ElementInteractions, InteractionItemPropValue, AnimationPresetPropValue, BooleanPropValue, ConfigPropValue, ExcludedBreakpointsPropValue, InteractionBreakpointsPropValue, NumberPropValue, StringPropValue, TimingConfigPropValue } from '@elementor/editor-elements';
4
5
  export { InteractionItemPropValue } from '@elementor/editor-elements';
5
- import { PropValue } from '@elementor/editor-props';
6
+ import { PropValue, SizePropValue } from '@elementor/editor-props';
6
7
 
7
8
  declare const EmptyState: ({ onCreateInteraction }: {
8
9
  onCreateInteraction: () => void;
@@ -17,7 +18,10 @@ type InteractionConstants = {
17
18
  defaultDelay: number;
18
19
  slideDistance: number;
19
20
  scaleStart: number;
20
- easing: string;
21
+ defaultEasing: string;
22
+ relativeTo: string;
23
+ start: number;
24
+ end: number;
21
25
  };
22
26
  type InteractionsConfig = {
23
27
  constants: InteractionConstants;
@@ -46,6 +50,8 @@ type InteractionsProvider = {
46
50
  all: () => ElementInteractionData[];
47
51
  };
48
52
  };
53
+ type InteractionItemValue = InteractionItemPropValue['value'];
54
+ type SizeStringValue = `${number}${Unit}` | number;
49
55
 
50
56
  declare function getInteractionsConfig(): InteractionsConfig;
51
57
 
@@ -127,4 +133,66 @@ declare const EFFECT_OPTIONS: {
127
133
  };
128
134
  declare const BASE_EFFECTS: string[];
129
135
 
130
- export { BASE_EASINGS, BASE_EFFECTS, BASE_REPLAY, BASE_TRIGGERS, type CreateInteractionsProviderOptions, EASING_OPTIONS, EFFECT_OPTIONS, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, EmptyState, type FieldProps, InteractionsTab, REPLAY_OPTIONS, type ReplayFieldProps, TRIGGER_OPTIONS, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository, registerInteractionsControl };
136
+ declare const createString: (value: string) => StringPropValue;
137
+ declare const createNumber: (value: number) => NumberPropValue;
138
+ declare const createTimingConfig: (duration: SizeStringValue, delay: SizeStringValue) => TimingConfigPropValue;
139
+ declare const createBoolean: (value: boolean) => BooleanPropValue;
140
+ declare const createConfig: ({ replay, easing, relativeTo, start, end, }: {
141
+ replay: boolean;
142
+ easing?: string;
143
+ relativeTo?: string;
144
+ start?: SizeStringValue;
145
+ end?: SizeStringValue;
146
+ }) => ConfigPropValue;
147
+ declare const extractBoolean: (prop: BooleanPropValue | undefined, fallback?: boolean) => boolean;
148
+ declare const createExcludedBreakpoints: (breakpoints: string[]) => ExcludedBreakpointsPropValue;
149
+ declare const createInteractionBreakpoints: (excluded: string[]) => InteractionBreakpointsPropValue;
150
+ declare const extractExcludedBreakpoints: (breakpoints: InteractionBreakpointsPropValue | undefined) => string[];
151
+ declare const createAnimationPreset: ({ effect, type, direction, duration, delay, replay, easing, relativeTo, start, end, customEffects, }: {
152
+ effect: string;
153
+ type: string;
154
+ direction?: string;
155
+ duration: SizeStringValue;
156
+ delay: SizeStringValue;
157
+ replay: boolean;
158
+ easing?: string;
159
+ relativeTo?: string;
160
+ start?: SizeStringValue;
161
+ end?: SizeStringValue;
162
+ customEffects?: PropValue;
163
+ }) => AnimationPresetPropValue;
164
+ declare const createInteractionItem: ({ trigger, effect, type, direction, duration, delay, interactionId, replay, easing, relativeTo, start, end, excludedBreakpoints, customEffects, }: {
165
+ trigger?: string;
166
+ effect?: string;
167
+ type?: string;
168
+ direction?: string;
169
+ duration?: SizeStringValue;
170
+ delay?: SizeStringValue;
171
+ interactionId?: string;
172
+ replay?: boolean;
173
+ easing?: string;
174
+ relativeTo?: string;
175
+ start?: number;
176
+ end?: number;
177
+ excludedBreakpoints?: string[];
178
+ customEffects?: PropValue;
179
+ }) => InteractionItemPropValue;
180
+ declare const createDefaultInteractionItem: () => InteractionItemPropValue;
181
+ declare const createDefaultInteractions: () => ElementInteractions;
182
+ declare const extractString: (prop: StringPropValue | undefined, fallback?: string) => string;
183
+ declare const extractSize: (prop?: SizePropValue, defaultValue?: SizeStringValue) => SizeStringValue;
184
+ declare const buildDisplayLabel: (item: InteractionItemValue) => string;
185
+
186
+ declare function generateTempInteractionId(): string;
187
+ declare function isTempId(id: string | undefined): boolean;
188
+
189
+ declare const resolveDirection: (hasDirection: boolean, newEffect?: string, newDirection?: string, currentDirection?: string, currentEffect?: string) => string | undefined;
190
+
191
+ declare const convertTimeUnit: (value: number, from: Unit, to: Unit) => number;
192
+
193
+ type SizeValue = SizePropValue['value'];
194
+ type SizeUnit = SizeValue['unit'];
195
+ declare const parseSizeValue: (value: SizeStringValue, allowedUnits: SizeUnit[], defaultValue?: SizeStringValue, defaultUnit?: Unit) => SizeValue;
196
+ declare const formatSizeValue: ({ size, unit }: SizeValue) => SizeStringValue;
197
+
198
+ export { BASE_EASINGS, BASE_EFFECTS, BASE_REPLAY, BASE_TRIGGERS, type CreateInteractionsProviderOptions, EASING_OPTIONS, EFFECT_OPTIONS, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, EmptyState, type FieldProps, InteractionsTab, REPLAY_OPTIONS, type ReplayFieldProps, TRIGGER_OPTIONS, buildDisplayLabel, convertTimeUnit, createAnimationPreset, createBoolean, createConfig, createDefaultInteractionItem, createDefaultInteractions, createExcludedBreakpoints, createInteractionBreakpoints, createInteractionItem, createInteractionsProvider, createNumber, createString, createTimingConfig, extractBoolean, extractExcludedBreakpoints, extractSize, extractString, formatSizeValue, generateTempInteractionId, getInteractionsConfig, init, interactionsRepository, isTempId, parseSizeValue, registerInteractionsControl, resolveDirection };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { RefObject, ComponentType } from 'react';
3
- import { ElementInteractions } from '@elementor/editor-elements';
3
+ import { Unit } from '@elementor/editor-controls';
4
+ import { ElementInteractions, InteractionItemPropValue, AnimationPresetPropValue, BooleanPropValue, ConfigPropValue, ExcludedBreakpointsPropValue, InteractionBreakpointsPropValue, NumberPropValue, StringPropValue, TimingConfigPropValue } from '@elementor/editor-elements';
4
5
  export { InteractionItemPropValue } from '@elementor/editor-elements';
5
- import { PropValue } from '@elementor/editor-props';
6
+ import { PropValue, SizePropValue } from '@elementor/editor-props';
6
7
 
7
8
  declare const EmptyState: ({ onCreateInteraction }: {
8
9
  onCreateInteraction: () => void;
@@ -17,7 +18,10 @@ type InteractionConstants = {
17
18
  defaultDelay: number;
18
19
  slideDistance: number;
19
20
  scaleStart: number;
20
- easing: string;
21
+ defaultEasing: string;
22
+ relativeTo: string;
23
+ start: number;
24
+ end: number;
21
25
  };
22
26
  type InteractionsConfig = {
23
27
  constants: InteractionConstants;
@@ -46,6 +50,8 @@ type InteractionsProvider = {
46
50
  all: () => ElementInteractionData[];
47
51
  };
48
52
  };
53
+ type InteractionItemValue = InteractionItemPropValue['value'];
54
+ type SizeStringValue = `${number}${Unit}` | number;
49
55
 
50
56
  declare function getInteractionsConfig(): InteractionsConfig;
51
57
 
@@ -127,4 +133,66 @@ declare const EFFECT_OPTIONS: {
127
133
  };
128
134
  declare const BASE_EFFECTS: string[];
129
135
 
130
- export { BASE_EASINGS, BASE_EFFECTS, BASE_REPLAY, BASE_TRIGGERS, type CreateInteractionsProviderOptions, EASING_OPTIONS, EFFECT_OPTIONS, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, EmptyState, type FieldProps, InteractionsTab, REPLAY_OPTIONS, type ReplayFieldProps, TRIGGER_OPTIONS, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository, registerInteractionsControl };
136
+ declare const createString: (value: string) => StringPropValue;
137
+ declare const createNumber: (value: number) => NumberPropValue;
138
+ declare const createTimingConfig: (duration: SizeStringValue, delay: SizeStringValue) => TimingConfigPropValue;
139
+ declare const createBoolean: (value: boolean) => BooleanPropValue;
140
+ declare const createConfig: ({ replay, easing, relativeTo, start, end, }: {
141
+ replay: boolean;
142
+ easing?: string;
143
+ relativeTo?: string;
144
+ start?: SizeStringValue;
145
+ end?: SizeStringValue;
146
+ }) => ConfigPropValue;
147
+ declare const extractBoolean: (prop: BooleanPropValue | undefined, fallback?: boolean) => boolean;
148
+ declare const createExcludedBreakpoints: (breakpoints: string[]) => ExcludedBreakpointsPropValue;
149
+ declare const createInteractionBreakpoints: (excluded: string[]) => InteractionBreakpointsPropValue;
150
+ declare const extractExcludedBreakpoints: (breakpoints: InteractionBreakpointsPropValue | undefined) => string[];
151
+ declare const createAnimationPreset: ({ effect, type, direction, duration, delay, replay, easing, relativeTo, start, end, customEffects, }: {
152
+ effect: string;
153
+ type: string;
154
+ direction?: string;
155
+ duration: SizeStringValue;
156
+ delay: SizeStringValue;
157
+ replay: boolean;
158
+ easing?: string;
159
+ relativeTo?: string;
160
+ start?: SizeStringValue;
161
+ end?: SizeStringValue;
162
+ customEffects?: PropValue;
163
+ }) => AnimationPresetPropValue;
164
+ declare const createInteractionItem: ({ trigger, effect, type, direction, duration, delay, interactionId, replay, easing, relativeTo, start, end, excludedBreakpoints, customEffects, }: {
165
+ trigger?: string;
166
+ effect?: string;
167
+ type?: string;
168
+ direction?: string;
169
+ duration?: SizeStringValue;
170
+ delay?: SizeStringValue;
171
+ interactionId?: string;
172
+ replay?: boolean;
173
+ easing?: string;
174
+ relativeTo?: string;
175
+ start?: number;
176
+ end?: number;
177
+ excludedBreakpoints?: string[];
178
+ customEffects?: PropValue;
179
+ }) => InteractionItemPropValue;
180
+ declare const createDefaultInteractionItem: () => InteractionItemPropValue;
181
+ declare const createDefaultInteractions: () => ElementInteractions;
182
+ declare const extractString: (prop: StringPropValue | undefined, fallback?: string) => string;
183
+ declare const extractSize: (prop?: SizePropValue, defaultValue?: SizeStringValue) => SizeStringValue;
184
+ declare const buildDisplayLabel: (item: InteractionItemValue) => string;
185
+
186
+ declare function generateTempInteractionId(): string;
187
+ declare function isTempId(id: string | undefined): boolean;
188
+
189
+ declare const resolveDirection: (hasDirection: boolean, newEffect?: string, newDirection?: string, currentDirection?: string, currentEffect?: string) => string | undefined;
190
+
191
+ declare const convertTimeUnit: (value: number, from: Unit, to: Unit) => number;
192
+
193
+ type SizeValue = SizePropValue['value'];
194
+ type SizeUnit = SizeValue['unit'];
195
+ declare const parseSizeValue: (value: SizeStringValue, allowedUnits: SizeUnit[], defaultValue?: SizeStringValue, defaultUnit?: Unit) => SizeValue;
196
+ declare const formatSizeValue: ({ size, unit }: SizeValue) => SizeStringValue;
197
+
198
+ export { BASE_EASINGS, BASE_EFFECTS, BASE_REPLAY, BASE_TRIGGERS, type CreateInteractionsProviderOptions, EASING_OPTIONS, EFFECT_OPTIONS, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, EmptyState, type FieldProps, InteractionsTab, REPLAY_OPTIONS, type ReplayFieldProps, TRIGGER_OPTIONS, buildDisplayLabel, convertTimeUnit, createAnimationPreset, createBoolean, createConfig, createDefaultInteractionItem, createDefaultInteractions, createExcludedBreakpoints, createInteractionBreakpoints, createInteractionItem, createInteractionsProvider, createNumber, createString, createTimingConfig, extractBoolean, extractExcludedBreakpoints, extractSize, extractString, formatSizeValue, generateTempInteractionId, getInteractionsConfig, init, interactionsRepository, isTempId, parseSizeValue, registerInteractionsControl, resolveDirection };
package/dist/index.js CHANGED
@@ -41,11 +41,33 @@ __export(index_exports, {
41
41
  InteractionsTab: () => InteractionsTab,
42
42
  REPLAY_OPTIONS: () => REPLAY_OPTIONS,
43
43
  TRIGGER_OPTIONS: () => TRIGGER_OPTIONS,
44
+ buildDisplayLabel: () => buildDisplayLabel,
45
+ convertTimeUnit: () => convertTimeUnit,
46
+ createAnimationPreset: () => createAnimationPreset,
47
+ createBoolean: () => createBoolean,
48
+ createConfig: () => createConfig,
49
+ createDefaultInteractionItem: () => createDefaultInteractionItem,
50
+ createDefaultInteractions: () => createDefaultInteractions,
51
+ createExcludedBreakpoints: () => createExcludedBreakpoints,
52
+ createInteractionBreakpoints: () => createInteractionBreakpoints,
53
+ createInteractionItem: () => createInteractionItem,
44
54
  createInteractionsProvider: () => createInteractionsProvider,
55
+ createNumber: () => createNumber,
56
+ createString: () => createString,
57
+ createTimingConfig: () => createTimingConfig,
58
+ extractBoolean: () => extractBoolean,
59
+ extractExcludedBreakpoints: () => extractExcludedBreakpoints,
60
+ extractSize: () => extractSize,
61
+ extractString: () => extractString,
62
+ formatSizeValue: () => formatSizeValue,
63
+ generateTempInteractionId: () => generateTempInteractionId,
45
64
  getInteractionsConfig: () => getInteractionsConfig,
46
65
  init: () => init,
47
66
  interactionsRepository: () => interactionsRepository,
48
- registerInteractionsControl: () => registerInteractionsControl
67
+ isTempId: () => isTempId,
68
+ parseSizeValue: () => parseSizeValue,
69
+ registerInteractionsControl: () => registerInteractionsControl,
70
+ resolveDirection: () => resolveDirection
49
71
  });
50
72
  module.exports = __toCommonJS(index_exports);
51
73
 
@@ -219,17 +241,42 @@ var createSizeValue = (size, unit) => {
219
241
  return { size, unit };
220
242
  };
221
243
 
244
+ // src/utils/get-interactions-config.ts
245
+ var DEFAULT_CONFIG = {
246
+ constants: {
247
+ defaultDuration: 600,
248
+ defaultDelay: 0,
249
+ slideDistance: 100,
250
+ scaleStart: 0,
251
+ defaultEasing: "easeIn",
252
+ relativeTo: "viewport",
253
+ end: 15,
254
+ start: 85
255
+ }
256
+ };
257
+ function getInteractionsConfig() {
258
+ return window.ElementorInteractionsConfig || DEFAULT_CONFIG;
259
+ }
260
+
222
261
  // src/utils/temp-id-utils.ts
223
262
  var TEMP_ID_PREFIX = "temp-";
263
+ var TEMP_ID_REGEX = /^temp-[a-z0-9]+$/i;
224
264
  function generateTempInteractionId() {
225
265
  return `${TEMP_ID_PREFIX}${Math.random().toString(36).substring(2, 11)}`;
226
266
  }
267
+ function isTempId(id) {
268
+ return !!id && TEMP_ID_REGEX.test(id);
269
+ }
227
270
 
228
271
  // src/utils/prop-value-utils.ts
229
272
  var createString = (value) => ({
230
273
  $$type: "string",
231
274
  value
232
275
  });
276
+ var createNumber = (value) => ({
277
+ $$type: "number",
278
+ value
279
+ });
233
280
  var createTimingConfig = (duration, delay) => ({
234
281
  $$type: "timing-config",
235
282
  value: {
@@ -347,17 +394,22 @@ var createInteractionItem = ({
347
394
  }
348
395
  });
349
396
  var createDefaultInteractionItem = () => {
397
+ const { constants } = getInteractionsConfig();
350
398
  return createInteractionItem({
351
399
  trigger: "load",
352
400
  effect: "fade",
353
401
  type: "in",
354
- duration: 600,
355
- delay: 0,
402
+ duration: constants.defaultDuration,
403
+ delay: constants.defaultDelay,
356
404
  replay: false,
357
- easing: "easeIn",
405
+ easing: constants.defaultEasing,
358
406
  interactionId: generateTempInteractionId()
359
407
  });
360
408
  };
409
+ var createDefaultInteractions = () => ({
410
+ version: 1,
411
+ items: [createDefaultInteractionItem()]
412
+ });
361
413
  var extractString = (prop, fallback = "") => {
362
414
  return prop?.value ?? fallback;
363
415
  };
@@ -922,20 +974,6 @@ function InteractionsContent({
922
974
  ));
923
975
  }
924
976
 
925
- // src/utils/get-interactions-config.ts
926
- var DEFAULT_CONFIG = {
927
- constants: {
928
- defaultDuration: 300,
929
- defaultDelay: 0,
930
- slideDistance: 100,
931
- scaleStart: 0.5,
932
- easing: "linear"
933
- }
934
- };
935
- function getInteractionsConfig() {
936
- return window.ElementorInteractionsConfig || DEFAULT_CONFIG;
937
- }
938
-
939
977
  // src/utils/create-interactions-repository.ts
940
978
  var createInteractionsRepository = () => {
941
979
  const providers = [];
@@ -1499,12 +1537,29 @@ var initManageElementInteractionTool = (reg) => {
1499
1537
  const elementData = allInteractions.find((data) => data.elementId === elementId);
1500
1538
  const currentInteractions = elementData?.interactions ?? EMPTY_INTERACTIONS;
1501
1539
  if (action === "get") {
1540
+ const summary = currentInteractions.items.map((item) => {
1541
+ const { value } = item;
1542
+ const animValue = value.animation.value;
1543
+ const timingValue = animValue.timing_config.value;
1544
+ const configValue = animValue.config.value;
1545
+ return {
1546
+ id: extractString(value.interaction_id),
1547
+ trigger: extractString(value.trigger),
1548
+ effect: extractString(animValue.effect),
1549
+ effectType: extractString(animValue.type),
1550
+ direction: extractString(animValue.direction),
1551
+ duration: extractSize(timingValue.duration),
1552
+ delay: extractSize(timingValue.delay),
1553
+ easing: extractString(configValue.easing),
1554
+ excludedBreakpoints: extractExcludedBreakpoints(value.breakpoints)
1555
+ };
1556
+ });
1502
1557
  return {
1503
1558
  success: true,
1504
1559
  elementId,
1505
1560
  action,
1506
- interactions: currentInteractions.items,
1507
- count: currentInteractions.items.length
1561
+ interactions: summary,
1562
+ count: summary.length
1508
1563
  };
1509
1564
  }
1510
1565
  let updatedItems = [...currentInteractions.items];
@@ -1709,10 +1764,32 @@ function init() {
1709
1764
  InteractionsTab,
1710
1765
  REPLAY_OPTIONS,
1711
1766
  TRIGGER_OPTIONS,
1767
+ buildDisplayLabel,
1768
+ convertTimeUnit,
1769
+ createAnimationPreset,
1770
+ createBoolean,
1771
+ createConfig,
1772
+ createDefaultInteractionItem,
1773
+ createDefaultInteractions,
1774
+ createExcludedBreakpoints,
1775
+ createInteractionBreakpoints,
1776
+ createInteractionItem,
1712
1777
  createInteractionsProvider,
1778
+ createNumber,
1779
+ createString,
1780
+ createTimingConfig,
1781
+ extractBoolean,
1782
+ extractExcludedBreakpoints,
1783
+ extractSize,
1784
+ extractString,
1785
+ formatSizeValue,
1786
+ generateTempInteractionId,
1713
1787
  getInteractionsConfig,
1714
1788
  init,
1715
1789
  interactionsRepository,
1716
- registerInteractionsControl
1790
+ isTempId,
1791
+ parseSizeValue,
1792
+ registerInteractionsControl,
1793
+ resolveDirection
1717
1794
  });
1718
1795
  //# sourceMappingURL=index.js.map