@elementor/editor-interactions 4.0.0-679 → 4.0.0-680

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.mjs CHANGED
@@ -42,74 +42,22 @@ import {
42
42
  import { useState } from "react";
43
43
  import { getElementInteractions } from "@elementor/editor-elements";
44
44
  import { __privateUseListenTo as useListenTo, windowEvent } from "@elementor/editor-v1-adapters";
45
- var useElementInteractions = (elementId) => {
46
- const [interactions, setInteractions] = useState(() => {
47
- const initial = getElementInteractions(elementId);
48
- return initial ?? { version: 1, items: [] };
49
- });
50
- useListenTo(
51
- windowEvent("elementor/element/update_interactions"),
52
- () => {
53
- const newInteractions = getElementInteractions(elementId);
54
- setInteractions(newInteractions ?? { version: 1, items: [] });
55
- },
56
- [elementId]
57
- );
58
- return interactions;
59
- };
60
45
 
61
- // src/contexts/interactions-context.tsx
62
- var InteractionsContext = createContext(null);
63
- var DEFAULT_INTERACTIONS = {
64
- version: 1,
65
- items: []
66
- };
67
- var InteractionsProvider = ({ children, elementId }) => {
68
- const rawInteractions = useElementInteractions(elementId);
69
- useEffect(() => {
70
- window.dispatchEvent(new CustomEvent("elementor/element/update_interactions"));
71
- }, []);
72
- const interactions = rawInteractions ?? DEFAULT_INTERACTIONS;
73
- const setInteractions = (value) => {
74
- const normalizedValue = value && value.items?.length === 0 ? void 0 : value;
75
- updateElementInteractions({
76
- elementId,
77
- interactions: normalizedValue
78
- });
79
- };
80
- const playInteractions = (interactionId) => {
81
- playElementInteractions(elementId, interactionId);
82
- };
83
- const contextValue = {
84
- elementId,
85
- interactions,
86
- setInteractions,
87
- playInteractions
88
- };
89
- return /* @__PURE__ */ React2.createElement(InteractionsContext.Provider, { value: contextValue }, children);
90
- };
91
- var useInteractionsContext = () => {
92
- const context = useContext(InteractionsContext);
93
- if (!context) {
94
- throw new Error("useInteractionsContext must be used within InteractionsProvider");
95
- }
96
- return context;
97
- };
98
-
99
- // src/contexts/popup-state-context.tsx
100
- import * as React3 from "react";
101
- import { createContext as createContext2, useCallback, useContext as useContext2, useState as useState2 } from "react";
102
- var PopupStateContext = createContext2(void 0);
103
- var PopupStateProvider = ({ children }) => {
104
- const [openByDefault, setOpenByDefault] = useState2(false);
105
- const triggerDefaultOpen = useCallback(() => {
106
- setOpenByDefault(true);
107
- }, []);
108
- const resetDefaultOpen = useCallback(() => {
109
- setOpenByDefault(false);
110
- }, []);
111
- return /* @__PURE__ */ React3.createElement(PopupStateContext.Provider, { value: { openByDefault, triggerDefaultOpen, resetDefaultOpen } }, children);
112
- };
46
+ // src/interactions-controls-registry.ts
47
+ var controlsRegistry = /* @__PURE__ */ new Map();
48
+ function registerInteractionsControl({
49
+ type,
50
+ component,
51
+ options
52
+ }) {
53
+ controlsRegistry.set(type, { type, component, options });
54
+ }
55
+ function getInteractionsControl(type) {
56
+ return controlsRegistry.get(type);
57
+ }
58
+ function getInteractionsControlOptions(type) {
59
+ return controlsRegistry.get(type)?.options ?? [];
60
+ }
113
61
 
114
62
  // src/utils/prop-value-utils.ts
115
63
  import { sizePropTypeUtil } from "@elementor/editor-props";
@@ -364,6 +312,115 @@ var buildDisplayLabel = (item) => {
364
312
  return `${triggerLabel}: ${effectLabel} ${typeLabel}`;
365
313
  };
366
314
 
315
+ // src/utils/is-supported-interaction-item.ts
316
+ function isSupportedInteractionItem(interaction) {
317
+ const value = interaction.value;
318
+ const replay = extractBoolean(value.animation.value.config?.value.replay);
319
+ if (true === replay) {
320
+ return hasSupport("replay", "yes");
321
+ }
322
+ const trigger = extractString(value.trigger);
323
+ const easing = extractString(value.animation.value.config?.value.easing);
324
+ const effect = extractString(value.animation.value.effect);
325
+ const checks = [
326
+ ["trigger", trigger],
327
+ ["easing", easing],
328
+ ["effect", effect]
329
+ ];
330
+ return checks.every(([controlType, controlValue]) => {
331
+ if (controlValue === "" || controlValue === null) {
332
+ return true;
333
+ }
334
+ return hasSupport(controlType, controlValue);
335
+ });
336
+ }
337
+ function hasSupport(controlType, controlValue) {
338
+ const supportedOptions = getInteractionsControlOptions(controlType);
339
+ if (1 > supportedOptions.length) {
340
+ return true;
341
+ }
342
+ return supportedOptions.includes(controlValue);
343
+ }
344
+
345
+ // src/utils/filter-interactions.ts
346
+ var filterInteractions = (interactions) => {
347
+ return interactions.filter((interaction) => {
348
+ return isSupportedInteractionItem(interaction);
349
+ });
350
+ };
351
+
352
+ // src/hooks/use-element-interactions.ts
353
+ var useElementInteractions = (elementId) => {
354
+ const [interactions, setInteractions] = useState(() => {
355
+ const initial = getElementInteractions(elementId);
356
+ const filteredInteractions = filterInteractions(initial?.items ?? []);
357
+ return { version: initial?.version ?? 1, items: filteredInteractions };
358
+ });
359
+ useListenTo(
360
+ windowEvent("elementor/element/update_interactions"),
361
+ () => {
362
+ const newInteractions = getElementInteractions(elementId);
363
+ const filteredInteractions = filterInteractions(newInteractions?.items ?? []);
364
+ setInteractions({ version: newInteractions?.version ?? 1, items: filteredInteractions });
365
+ },
366
+ [elementId]
367
+ );
368
+ return interactions;
369
+ };
370
+
371
+ // src/contexts/interactions-context.tsx
372
+ var InteractionsContext = createContext(null);
373
+ var DEFAULT_INTERACTIONS = {
374
+ version: 1,
375
+ items: []
376
+ };
377
+ var InteractionsProvider = ({ children, elementId }) => {
378
+ const rawInteractions = useElementInteractions(elementId);
379
+ useEffect(() => {
380
+ window.dispatchEvent(new CustomEvent("elementor/element/update_interactions"));
381
+ }, []);
382
+ const interactions = rawInteractions ?? DEFAULT_INTERACTIONS;
383
+ const setInteractions = (value) => {
384
+ const normalizedValue = value && value.items?.length === 0 ? void 0 : value;
385
+ updateElementInteractions({
386
+ elementId,
387
+ interactions: normalizedValue
388
+ });
389
+ };
390
+ const playInteractions = (interactionId) => {
391
+ playElementInteractions(elementId, interactionId);
392
+ };
393
+ const contextValue = {
394
+ elementId,
395
+ interactions,
396
+ setInteractions,
397
+ playInteractions
398
+ };
399
+ return /* @__PURE__ */ React2.createElement(InteractionsContext.Provider, { value: contextValue }, children);
400
+ };
401
+ var useInteractionsContext = () => {
402
+ const context = useContext(InteractionsContext);
403
+ if (!context) {
404
+ throw new Error("useInteractionsContext must be used within InteractionsProvider");
405
+ }
406
+ return context;
407
+ };
408
+
409
+ // src/contexts/popup-state-context.tsx
410
+ import * as React3 from "react";
411
+ import { createContext as createContext2, useCallback, useContext as useContext2, useState as useState2 } from "react";
412
+ var PopupStateContext = createContext2(void 0);
413
+ var PopupStateProvider = ({ children }) => {
414
+ const [openByDefault, setOpenByDefault] = useState2(false);
415
+ const triggerDefaultOpen = useCallback(() => {
416
+ setOpenByDefault(true);
417
+ }, []);
418
+ const resetDefaultOpen = useCallback(() => {
419
+ setOpenByDefault(false);
420
+ }, []);
421
+ return /* @__PURE__ */ React3.createElement(PopupStateContext.Provider, { value: { openByDefault, triggerDefaultOpen, resetDefaultOpen } }, children);
422
+ };
423
+
367
424
  // src/utils/tracking.ts
368
425
  import { getElementLabel } from "@elementor/editor-elements";
369
426
  import { getMixpanel } from "@elementor/events";
@@ -438,19 +495,6 @@ import { PopoverContent } from "@elementor/editor-controls";
438
495
  import { Box, Divider, Grid as Grid2 } from "@elementor/ui";
439
496
  import { __ as __2 } from "@wordpress/i18n";
440
497
 
441
- // src/interactions-controls-registry.ts
442
- var controlsRegistry = /* @__PURE__ */ new Map();
443
- function registerInteractionsControl({
444
- type,
445
- component,
446
- options
447
- }) {
448
- controlsRegistry.set(type, { type, component, options });
449
- }
450
- function getInteractionsControl(type) {
451
- return controlsRegistry.get(type);
452
- }
453
-
454
498
  // src/utils/resolve-direction.ts
455
499
  var resolveDirection = (hasDirection, newEffect, newDirection, currentDirection, currentEffect) => {
456
500
  if (newEffect === "slide" && !newDirection) {
@@ -1892,7 +1936,7 @@ function init() {
1892
1936
  registerInteractionsControl({
1893
1937
  type: "replay",
1894
1938
  component: Replay,
1895
- options: ["true", "false"]
1939
+ options: ["no"]
1896
1940
  });
1897
1941
  registerInteractionsControl({
1898
1942
  type: "effectType",