@elementor/editor-interactions 3.35.0-360 → 3.35.0-362

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,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { ElementInteractions } from '@elementor/editor-elements';
2
+ import { ElementInteractions, InteractionItemPropValue } from '@elementor/editor-elements';
3
+ export { AnimationPresetPropValue, ElementInteractions, InteractionItemPropValue, NumberPropValue, StringPropValue, TimingConfigPropValue } from '@elementor/editor-elements';
3
4
 
4
5
  declare const EmptyState: ({ onCreateInteraction }: {
5
6
  onCreateInteraction: () => void;
@@ -32,25 +33,26 @@ type FieldProps = {
32
33
  type DirectionFieldProps = FieldProps & {
33
34
  interactionType: string;
34
35
  };
35
- type InteractionItem = {
36
+ type ElementInteractionData = {
36
37
  elementId: string;
37
38
  dataId: string;
38
39
  interactions: ElementInteractions;
39
40
  };
40
- type InteractionsCollection = InteractionItem[];
41
+ type InteractionsCollection = ElementInteractionData[];
41
42
  type InteractionsProvider = {
42
43
  getKey: () => string;
43
44
  priority: number;
44
45
  subscribe: (callback: () => void) => () => void;
45
46
  actions: {
46
- all: () => InteractionItem[];
47
+ all: () => ElementInteractionData[];
47
48
  };
48
49
  };
50
+ type InteractionItemValue = InteractionItemPropValue['value'];
49
51
 
50
52
  declare function getInteractionsConfig(): InteractionsConfig;
51
53
 
52
54
  declare const interactionsRepository: {
53
- all: () => InteractionItem[];
55
+ all: () => ElementInteractionData[];
54
56
  register: (provider: InteractionsProvider) => void;
55
57
  subscribe: (cb: () => void) => () => void;
56
58
  getProviders: () => InteractionsProvider[];
@@ -71,4 +73,4 @@ declare const ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX = "document-elements-int
71
73
 
72
74
  declare function init(): void;
73
75
 
74
- export { type AnimationOption, type CreateInteractionsProviderOptions, type DirectionFieldProps, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, EmptyState, type FieldProps, type InteractionConstants, type InteractionItem, type InteractionsCollection, type InteractionsConfig, type InteractionsProvider, InteractionsTab, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository };
76
+ 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, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { ElementInteractions } from '@elementor/editor-elements';
2
+ import { ElementInteractions, InteractionItemPropValue } from '@elementor/editor-elements';
3
+ export { AnimationPresetPropValue, ElementInteractions, InteractionItemPropValue, NumberPropValue, StringPropValue, TimingConfigPropValue } from '@elementor/editor-elements';
3
4
 
4
5
  declare const EmptyState: ({ onCreateInteraction }: {
5
6
  onCreateInteraction: () => void;
@@ -32,25 +33,26 @@ type FieldProps = {
32
33
  type DirectionFieldProps = FieldProps & {
33
34
  interactionType: string;
34
35
  };
35
- type InteractionItem = {
36
+ type ElementInteractionData = {
36
37
  elementId: string;
37
38
  dataId: string;
38
39
  interactions: ElementInteractions;
39
40
  };
40
- type InteractionsCollection = InteractionItem[];
41
+ type InteractionsCollection = ElementInteractionData[];
41
42
  type InteractionsProvider = {
42
43
  getKey: () => string;
43
44
  priority: number;
44
45
  subscribe: (callback: () => void) => () => void;
45
46
  actions: {
46
- all: () => InteractionItem[];
47
+ all: () => ElementInteractionData[];
47
48
  };
48
49
  };
50
+ type InteractionItemValue = InteractionItemPropValue['value'];
49
51
 
50
52
  declare function getInteractionsConfig(): InteractionsConfig;
51
53
 
52
54
  declare const interactionsRepository: {
53
- all: () => InteractionItem[];
55
+ all: () => ElementInteractionData[];
54
56
  register: (provider: InteractionsProvider) => void;
55
57
  subscribe: (cb: () => void) => () => void;
56
58
  getProviders: () => InteractionsProvider[];
@@ -71,4 +73,4 @@ declare const ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX = "document-elements-int
71
73
 
72
74
  declare function init(): void;
73
75
 
74
- export { type AnimationOption, type CreateInteractionsProviderOptions, type DirectionFieldProps, ELEMENTS_INTERACTIONS_PROVIDER_KEY_PREFIX, EmptyState, type FieldProps, type InteractionConstants, type InteractionItem, type InteractionsCollection, type InteractionsConfig, type InteractionsProvider, InteractionsTab, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository };
76
+ 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, createInteractionsProvider, getInteractionsConfig, init, interactionsRepository };
package/dist/index.js CHANGED
@@ -78,11 +78,16 @@ var React2 = __toESM(require("react"));
78
78
  var import_react = require("react");
79
79
  var import_editor_elements = require("@elementor/editor-elements");
80
80
  var InteractionsContext = (0, import_react.createContext)(null);
81
+ var DEFAULT_INTERACTIONS = {
82
+ version: 1,
83
+ items: []
84
+ };
81
85
  var InteractionsProvider = ({ children, elementId }) => {
82
- const interactions = (0, import_editor_elements.useElementInteractions)(elementId);
86
+ const rawInteractions = (0, import_editor_elements.useElementInteractions)(elementId);
83
87
  (0, import_react.useEffect)(() => {
84
88
  window.dispatchEvent(new CustomEvent("elementor/element/update_interactions"));
85
89
  }, []);
90
+ const interactions = rawInteractions ?? DEFAULT_INTERACTIONS;
86
91
  const setInteractions = (value) => {
87
92
  (0, import_editor_elements.updateElementInteractions)({
88
93
  elementId,
@@ -130,20 +135,74 @@ var import_icons3 = require("@elementor/icons");
130
135
  var import_ui8 = require("@elementor/ui");
131
136
  var import_i18n8 = require("@wordpress/i18n");
132
137
 
133
- // src/utils/get-interactions-config.ts
134
- var DEFAULT_CONFIG = {
135
- constants: {
136
- defaultDuration: 300,
137
- defaultDelay: 0,
138
- slideDistance: 100,
139
- scaleStart: 0.5,
140
- easing: "linear"
141
- },
142
- animationOptions: []
138
+ // src/utils/prop-value-utils.ts
139
+ var createString = (value) => ({
140
+ $$type: "string",
141
+ value
142
+ });
143
+ var createNumber = (value) => ({
144
+ $$type: "number",
145
+ value
146
+ });
147
+ var createTimingConfig = (duration, delay) => ({
148
+ $$type: "timing-config",
149
+ value: {
150
+ duration: createNumber(duration),
151
+ delay: createNumber(delay)
152
+ }
153
+ });
154
+ var createAnimationPreset = (effect, type, direction, duration, delay) => ({
155
+ $$type: "animation-preset-props",
156
+ value: {
157
+ effect: createString(effect),
158
+ type: createString(type),
159
+ direction: createString(direction),
160
+ timing_config: createTimingConfig(duration, delay)
161
+ }
162
+ });
163
+ var createInteractionItem = (trigger, effect, type, direction, duration, delay, interactionId) => ({
164
+ $$type: "interaction-item",
165
+ value: {
166
+ ...interactionId && { interaction_id: createString(interactionId) },
167
+ trigger: createString(trigger),
168
+ animation: createAnimationPreset(effect, type, direction, duration, delay)
169
+ }
170
+ });
171
+ var createDefaultInteractionItem = () => {
172
+ return createInteractionItem("load", "fade", "in", "", 300, 0);
173
+ };
174
+ var extractString = (prop, fallback = "") => {
175
+ return prop?.value ?? fallback;
176
+ };
177
+ var extractNumber = (prop, fallback = 0) => {
178
+ return prop?.value ?? fallback;
179
+ };
180
+ var buildAnimationIdString = (item) => {
181
+ const trigger = extractString(item.trigger);
182
+ const effect = extractString(item.animation.value.effect);
183
+ const type = extractString(item.animation.value.type);
184
+ const direction = extractString(item.animation.value.direction);
185
+ const duration = extractNumber(item.animation.value.timing_config.value.duration);
186
+ const delay = extractNumber(item.animation.value.timing_config.value.delay);
187
+ return [trigger, effect, type, direction, duration, delay].join("-");
188
+ };
189
+ var TRIGGER_LABELS = {
190
+ load: "On page load",
191
+ scrollIn: "Scroll into view",
192
+ scrollOut: "Scroll out of view"
193
+ };
194
+ var capitalize = (str) => {
195
+ return str.charAt(0).toUpperCase() + str.slice(1);
196
+ };
197
+ var buildDisplayLabel = (item) => {
198
+ const trigger = extractString(item.trigger);
199
+ const effect = extractString(item.animation.value.effect);
200
+ const type = extractString(item.animation.value.type);
201
+ const triggerLabel = TRIGGER_LABELS[trigger] || capitalize(trigger);
202
+ const effectLabel = capitalize(effect);
203
+ const typeLabel = capitalize(type);
204
+ return `${triggerLabel}: ${effectLabel} ${typeLabel}`;
143
205
  };
144
- function getInteractionsConfig() {
145
- return window.ElementorInteractionsConfig || DEFAULT_CONFIG;
146
- }
147
206
 
148
207
  // src/components/interaction-details.tsx
149
208
  var React9 = __toESM(require("react"));
@@ -300,72 +359,57 @@ function Trigger({ value, onChange }) {
300
359
  }
301
360
 
302
361
  // src/components/interaction-details.tsx
303
- var DELIMITER = "-";
304
- var DEFAULT_INTERACTION = "load-fade-in--300-0";
305
- var getDefaultInteractionDetails = () => {
306
- const [trigger, effect, type, direction, duration, delay] = DEFAULT_INTERACTION.split(DELIMITER);
307
- return {
308
- trigger,
309
- effect,
310
- type,
311
- direction,
312
- duration,
313
- delay
314
- };
315
- };
316
- var buildInteractionDetails = (interaction) => {
317
- const [trigger, effect, type, direction, duration, delay] = interaction.split(DELIMITER);
318
- const defaultInteractionDetails = getDefaultInteractionDetails();
319
- const parsedDirection = direction || defaultInteractionDetails.direction;
320
- const shouldAutoSelectDirection = effect === "slide" && !parsedDirection;
321
- return {
322
- trigger: trigger || defaultInteractionDetails.trigger,
323
- effect: effect || defaultInteractionDetails.effect,
324
- type: type || defaultInteractionDetails.type,
325
- direction: shouldAutoSelectDirection ? "top" : parsedDirection,
326
- duration: duration || defaultInteractionDetails.duration,
327
- delay: delay || defaultInteractionDetails.delay
328
- };
362
+ var DEFAULT_VALUES = {
363
+ trigger: "load",
364
+ effect: "fade",
365
+ type: "in",
366
+ direction: "",
367
+ duration: 300,
368
+ delay: 0
329
369
  };
330
370
  var InteractionDetails = ({ interaction, onChange }) => {
331
- const interactionDetails = React9.useMemo(() => {
332
- return buildInteractionDetails(interaction);
333
- }, [interaction]);
334
- const handleChange = (key, value) => {
335
- if (value === null) {
336
- value = getDefaultInteractionDetails()[key];
337
- }
338
- const newInteractionDetails = { ...interactionDetails, [key]: value };
339
- if (key === "effect" && value === "slide") {
340
- const currentDirection = newInteractionDetails.direction;
341
- if (!currentDirection || currentDirection === "") {
342
- newInteractionDetails.direction = "top";
343
- }
344
- }
345
- onChange(Object.values(newInteractionDetails).join(DELIMITER));
371
+ const trigger = extractString(interaction.trigger, DEFAULT_VALUES.trigger);
372
+ const effect = extractString(interaction.animation.value.effect, DEFAULT_VALUES.effect);
373
+ const type = extractString(interaction.animation.value.type, DEFAULT_VALUES.type);
374
+ const direction = extractString(interaction.animation.value.direction, DEFAULT_VALUES.direction);
375
+ const duration = extractNumber(interaction.animation.value.timing_config.value.duration, DEFAULT_VALUES.duration);
376
+ const delay = extractNumber(interaction.animation.value.timing_config.value.delay, DEFAULT_VALUES.delay);
377
+ const effectiveDirection = effect === "slide" && !direction ? "top" : direction;
378
+ const updateInteraction = (updates) => {
379
+ const newEffect = updates.effect ?? effect;
380
+ const newDirection = updates.direction ?? direction;
381
+ const resolvedDirection = newEffect === "slide" && !newDirection ? "top" : newDirection;
382
+ onChange({
383
+ ...interaction,
384
+ trigger: createString(updates.trigger ?? trigger),
385
+ animation: createAnimationPreset(
386
+ newEffect,
387
+ updates.type ?? type,
388
+ resolvedDirection,
389
+ updates.duration ?? duration,
390
+ updates.delay ?? delay
391
+ )
392
+ });
346
393
  };
347
- return /* @__PURE__ */ React9.createElement(import_editor_controls6.PopoverContent, { p: 1.5 }, /* @__PURE__ */ React9.createElement(import_ui7.Grid, { container: true, spacing: 1.5 }, /* @__PURE__ */ React9.createElement(Trigger, { value: interactionDetails.trigger, onChange: (v) => handleChange("trigger", v) })), /* @__PURE__ */ React9.createElement(import_ui7.Divider, { sx: { mx: 1.5 } }), /* @__PURE__ */ React9.createElement(import_ui7.Grid, { container: true, spacing: 1.5 }, /* @__PURE__ */ React9.createElement(Effect, { value: interactionDetails.effect, onChange: (v) => handleChange("effect", v) }), /* @__PURE__ */ React9.createElement(EffectType, { value: interactionDetails.type, onChange: (v) => handleChange("type", v) }), /* @__PURE__ */ React9.createElement(
394
+ return /* @__PURE__ */ React9.createElement(import_editor_controls6.PopoverContent, { p: 1.5 }, /* @__PURE__ */ React9.createElement(import_ui7.Grid, { container: true, spacing: 1.5 }, /* @__PURE__ */ React9.createElement(Trigger, { value: trigger, onChange: (v) => updateInteraction({ trigger: v }) })), /* @__PURE__ */ React9.createElement(import_ui7.Divider, { sx: { mx: 1.5 } }), /* @__PURE__ */ React9.createElement(import_ui7.Grid, { container: true, spacing: 1.5 }, /* @__PURE__ */ React9.createElement(Effect, { value: effect, onChange: (v) => updateInteraction({ effect: v }) }), /* @__PURE__ */ React9.createElement(EffectType, { value: type, onChange: (v) => updateInteraction({ type: v }) }), /* @__PURE__ */ React9.createElement(
348
395
  Direction,
349
396
  {
350
- value: interactionDetails.effect === "slide" && !interactionDetails.direction ? "top" : interactionDetails.direction,
351
- onChange: (v) => {
352
- const directionValue = interactionDetails.effect === "slide" && (!v || v === "") ? "top" : v;
353
- handleChange("direction", directionValue);
354
- },
355
- interactionType: interactionDetails.type
397
+ value: effectiveDirection,
398
+ onChange: (v) => updateInteraction({ direction: v }),
399
+ interactionType: type
356
400
  }
357
401
  ), /* @__PURE__ */ React9.createElement(
358
402
  TimeFrameIndicator,
359
403
  {
360
- value: interactionDetails.duration,
361
- onChange: (v) => handleChange("duration", v),
404
+ value: String(duration),
405
+ onChange: (v) => updateInteraction({ duration: parseInt(v, 10) }),
362
406
  label: (0, import_i18n7.__)("Duration", "elementor")
363
407
  }
364
408
  ), /* @__PURE__ */ React9.createElement(
365
409
  TimeFrameIndicator,
366
410
  {
367
- value: interactionDetails.delay,
368
- onChange: (v) => handleChange("delay", v),
411
+ value: String(delay),
412
+ onChange: (v) => updateInteraction({ delay: parseInt(v, 10) }),
369
413
  label: (0, import_i18n7.__)("Delay", "elementor")
370
414
  }
371
415
  )));
@@ -387,24 +431,9 @@ function InteractionsList(props) {
387
431
  if (triggerCreateOnShowEmpty && (!interactionsState.items || interactionsState.items?.length === 0)) {
388
432
  setInteractionsState({
389
433
  version: 1,
390
- items: [
391
- {
392
- animation: {
393
- animation_id: DEFAULT_INTERACTION,
394
- animation_type: "full-preset"
395
- }
396
- }
397
- ]
434
+ items: [createDefaultInteractionItem()]
398
435
  });
399
436
  }
400
- const displayLabel = (interactionForDisplay) => {
401
- if (!interactionForDisplay) {
402
- return "";
403
- }
404
- const animationOptions = getInteractionsConfig()?.animationOptions;
405
- const option = animationOptions.find((opt) => opt.value === interactionForDisplay);
406
- return option?.label || interactionForDisplay;
407
- };
408
437
  const infotipContent = isMaxNumberOfInteractionsReached ? /* @__PURE__ */ React10.createElement(import_ui8.Alert, { color: "secondary", icon: /* @__PURE__ */ React10.createElement(import_icons3.InfoCircleFilledIcon, null), size: "small" }, /* @__PURE__ */ React10.createElement(import_ui8.AlertTitle, null, (0, import_i18n8.__)("Interactions", "elementor")), /* @__PURE__ */ React10.createElement(import_ui8.Box, { component: "span" }, (0, import_i18n8.__)(
409
438
  "You've reached the limit of 5 interactions for this element. Please remove an interaction before creating a new one.",
410
439
  "elementor"
@@ -428,32 +457,21 @@ function InteractionsList(props) {
428
457
  disableAddItemButton: isMaxNumberOfInteractionsReached,
429
458
  addButtonInfotipContent: infotipContent,
430
459
  itemSettings: {
431
- initialValues: {
432
- animation: {
433
- animation_id: DEFAULT_INTERACTION,
434
- animation_type: "full-preset"
435
- }
436
- },
437
- Label: ({ value }) => displayLabel(value.animation.animation_id),
460
+ initialValues: createDefaultInteractionItem(),
461
+ Label: ({ value }) => buildDisplayLabel(value.value),
438
462
  Icon: () => null,
439
463
  Content: ({ index, value }) => /* @__PURE__ */ React10.createElement(
440
464
  InteractionDetails,
441
465
  {
442
466
  key: index,
443
- interaction: value.animation.animation_id,
444
- onChange: (newValue) => {
445
- const newInteractions = {
446
- ...interactionsState,
447
- items: structuredClone(interactionsState.items)
448
- };
449
- newInteractions.items[index] = {
450
- ...newInteractions.items[index],
451
- animation: {
452
- ...newInteractions.items[index].animation,
453
- animation_id: newValue
454
- }
467
+ interaction: value.value,
468
+ onChange: (newInteractionValue) => {
469
+ const newItems = structuredClone(interactionsState.items);
470
+ newItems[index] = {
471
+ $$type: "interaction-item",
472
+ value: newInteractionValue
455
473
  };
456
- setInteractionsState({ ...interactionsState, items: newInteractions.items });
474
+ setInteractionsState({ ...interactionsState, items: newItems });
457
475
  }
458
476
  }
459
477
  ),
@@ -462,7 +480,7 @@ function InteractionsList(props) {
462
480
  {
463
481
  "aria-label": (0, import_i18n8.__)("Play interaction", "elementor"),
464
482
  size: "tiny",
465
- onClick: () => onPlayInteraction(value.animation.animation_id)
483
+ onClick: () => onPlayInteraction(buildAnimationIdString(value.value))
466
484
  },
467
485
  /* @__PURE__ */ React10.createElement(import_icons3.PlayerPlayIcon, { fontSize: "tiny" })
468
486
  ))
@@ -514,6 +532,21 @@ function InteractionsContent({
514
532
  ));
515
533
  }
516
534
 
535
+ // src/utils/get-interactions-config.ts
536
+ var DEFAULT_CONFIG = {
537
+ constants: {
538
+ defaultDuration: 300,
539
+ defaultDelay: 0,
540
+ slideDistance: 100,
541
+ scaleStart: 0.5,
542
+ easing: "linear"
543
+ },
544
+ animationOptions: []
545
+ };
546
+ function getInteractionsConfig() {
547
+ return window.ElementorInteractionsConfig || DEFAULT_CONFIG;
548
+ }
549
+
517
550
  // src/utils/create-interactions-repository.ts
518
551
  var createInteractionsRepository = () => {
519
552
  const providers = [];
@@ -648,8 +681,8 @@ function cleanInteractionIds(elementId) {
648
681
  }
649
682
  const updatedInteractions = structuredClone(interactions);
650
683
  updatedInteractions?.items?.forEach((interaction) => {
651
- if (interaction.interaction_id) {
652
- delete interaction.interaction_id;
684
+ if (interaction.$$type === "interaction-item" && interaction.value?.interaction_id) {
685
+ delete interaction.value.interaction_id;
653
686
  }
654
687
  });
655
688
  container.model.set("interactions", updatedInteractions);