@elementor/editor-elements 3.33.0-271 → 3.33.0-272

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
@@ -1,5 +1,5 @@
1
- // src/hooks/use-element-setting.ts
2
- import { __privateUseListenTo as useListenTo, commandEndEvent } from "@elementor/editor-v1-adapters";
1
+ // src/hooks/use-element-children.ts
2
+ import { __privateUseListenTo as useListenTo, commandEndEvent, v1ReadyEvent } from "@elementor/editor-v1-adapters";
3
3
 
4
4
  // src/sync/get-container.ts
5
5
  import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
@@ -16,6 +16,55 @@ var selectElement = (elementId) => {
16
16
  }
17
17
  };
18
18
 
19
+ // src/hooks/use-element-children.ts
20
+ function useElementChildren(elementId, childrenTypes) {
21
+ return useListenTo(
22
+ [
23
+ v1ReadyEvent(),
24
+ commandEndEvent("document/elements/create"),
25
+ commandEndEvent("document/elements/delete"),
26
+ commandEndEvent("document/elements/update"),
27
+ commandEndEvent("document/elements/set-settings")
28
+ ],
29
+ () => {
30
+ const container = getContainer(elementId);
31
+ const elementChildren = childrenTypes.reduce((acc, type) => {
32
+ acc[type] = [];
33
+ return acc;
34
+ }, {});
35
+ container?.children?.forEachRecursive?.(({ model, id }) => {
36
+ const elType = model.get("elType");
37
+ if (elType && elType in elementChildren) {
38
+ elementChildren[elType].push({ id });
39
+ }
40
+ });
41
+ return elementChildren;
42
+ },
43
+ [elementId]
44
+ );
45
+ }
46
+
47
+ // src/hooks/use-element-editor-settings.ts
48
+ import { __privateUseListenTo as useListenTo2, windowEvent } from "@elementor/editor-v1-adapters";
49
+
50
+ // src/sync/get-element-editor-settings.ts
51
+ function getElementEditorSettings(elementId) {
52
+ const container = getContainer(elementId);
53
+ return container?.model.get("editor_settings") ?? {};
54
+ }
55
+
56
+ // src/hooks/use-element-editor-settings.ts
57
+ var useElementEditorSettings = (elementId) => {
58
+ return useListenTo2(
59
+ windowEvent("elementor/element/update_editor_settings"),
60
+ () => getElementEditorSettings(elementId),
61
+ [elementId]
62
+ );
63
+ };
64
+
65
+ // src/hooks/use-element-setting.ts
66
+ import { __privateUseListenTo as useListenTo3, commandEndEvent as commandEndEvent2 } from "@elementor/editor-v1-adapters";
67
+
19
68
  // src/sync/get-element-setting.ts
20
69
  var getElementSetting = (elementId, settingKey) => {
21
70
  const container = getContainer(elementId);
@@ -27,15 +76,15 @@ var getElementSettings = (elementId, settingKey) => {
27
76
 
28
77
  // src/hooks/use-element-setting.ts
29
78
  var useElementSetting = (elementId, settingKey) => {
30
- return useListenTo(
31
- commandEndEvent("document/elements/set-settings"),
79
+ return useListenTo3(
80
+ commandEndEvent2("document/elements/set-settings"),
32
81
  () => getElementSetting(elementId, settingKey),
33
82
  [elementId, settingKey]
34
83
  );
35
84
  };
36
85
  var useElementSettings = (elementId, settingKeys) => {
37
- return useListenTo(
38
- commandEndEvent("document/elements/set-settings"),
86
+ return useListenTo3(
87
+ commandEndEvent2("document/elements/set-settings"),
39
88
  () => settingKeys.reduce((settings, key) => {
40
89
  const value = getElementSetting(elementId, key);
41
90
  if (value !== null) {
@@ -47,8 +96,28 @@ var useElementSettings = (elementId, settingKeys) => {
47
96
  );
48
97
  };
49
98
 
99
+ // src/hooks/use-parent-element.ts
100
+ import { __privateUseListenTo as useListenTo4, commandEndEvent as commandEndEvent3 } from "@elementor/editor-v1-adapters";
101
+ function useParentElement(elementId) {
102
+ return useListenTo4(
103
+ [commandEndEvent3("document/elements/create")],
104
+ () => {
105
+ if (!elementId) {
106
+ return null;
107
+ }
108
+ const extendedWindow = window;
109
+ const element = extendedWindow?.elementor?.getContainer?.(elementId);
110
+ if (!element) {
111
+ return null;
112
+ }
113
+ return element.parent;
114
+ },
115
+ [elementId]
116
+ );
117
+ }
118
+
50
119
  // src/hooks/use-selected-element.ts
51
- import { __privateUseListenTo as useListenTo2, commandEndEvent as commandEndEvent2 } from "@elementor/editor-v1-adapters";
120
+ import { __privateUseListenTo as useListenTo5, commandEndEvent as commandEndEvent4 } from "@elementor/editor-v1-adapters";
52
121
 
53
122
  // src/sync/get-widgets-cache.ts
54
123
  function getWidgetsCache() {
@@ -97,12 +166,12 @@ function getSelectedElements() {
97
166
 
98
167
  // src/hooks/use-selected-element.ts
99
168
  function useSelectedElement() {
100
- const elements = useListenTo2(
169
+ const elements = useListenTo5(
101
170
  [
102
- commandEndEvent2("document/elements/select"),
103
- commandEndEvent2("document/elements/deselect"),
104
- commandEndEvent2("document/elements/select-all"),
105
- commandEndEvent2("document/elements/deselect-all")
171
+ commandEndEvent4("document/elements/select"),
172
+ commandEndEvent4("document/elements/deselect"),
173
+ commandEndEvent4("document/elements/select-all"),
174
+ commandEndEvent4("document/elements/deselect-all")
106
175
  ],
107
176
  getSelectedElements
108
177
  );
@@ -114,73 +183,6 @@ function useSelectedElement() {
114
183
  return { element, elementType };
115
184
  }
116
185
 
117
- // src/hooks/use-parent-element.ts
118
- import { __privateUseListenTo as useListenTo3, commandEndEvent as commandEndEvent3 } from "@elementor/editor-v1-adapters";
119
- function useParentElement(elementId) {
120
- return useListenTo3(
121
- [commandEndEvent3("document/elements/create")],
122
- () => {
123
- if (!elementId) {
124
- return null;
125
- }
126
- const extendedWindow = window;
127
- const element = extendedWindow?.elementor?.getContainer?.(elementId);
128
- if (!element) {
129
- return null;
130
- }
131
- return element.parent;
132
- },
133
- [elementId]
134
- );
135
- }
136
-
137
- // src/hooks/use-element-children.ts
138
- import { __privateUseListenTo as useListenTo4, commandEndEvent as commandEndEvent4, v1ReadyEvent } from "@elementor/editor-v1-adapters";
139
- function useElementChildren(elementId, childrenTypes) {
140
- return useListenTo4(
141
- [
142
- v1ReadyEvent(),
143
- commandEndEvent4("document/elements/create"),
144
- commandEndEvent4("document/elements/delete"),
145
- commandEndEvent4("document/elements/update"),
146
- commandEndEvent4("document/elements/set-settings")
147
- ],
148
- () => {
149
- const container = getContainer(elementId);
150
- const elementChildren = childrenTypes.reduce((acc, type) => {
151
- acc[type] = [];
152
- return acc;
153
- }, {});
154
- container?.children?.forEachRecursive?.(({ model, id }) => {
155
- const elType = model.get("elType");
156
- if (elType && elType in elementChildren) {
157
- elementChildren[elType].push({ id });
158
- }
159
- });
160
- return elementChildren;
161
- },
162
- [elementId]
163
- );
164
- }
165
-
166
- // src/hooks/use-element-editor-settings.ts
167
- import { __privateUseListenTo as useListenTo5, windowEvent } from "@elementor/editor-v1-adapters";
168
-
169
- // src/sync/get-element-editor-settings.ts
170
- function getElementEditorSettings(elementId) {
171
- const container = getContainer(elementId);
172
- return container?.model.get("editor_settings") ?? {};
173
- }
174
-
175
- // src/hooks/use-element-editor-settings.ts
176
- var useElementEditorSettings = (elementId) => {
177
- return useListenTo5(
178
- windowEvent("elementor/element/update_editor_settings"),
179
- () => getElementEditorSettings(elementId),
180
- [elementId]
181
- );
182
- };
183
-
184
186
  // src/sync/create-element.ts
185
187
  import { __privateRunCommandSync as runCommandSync } from "@elementor/editor-v1-adapters";
186
188
  function createElement({ containerId, model, options }) {
@@ -195,23 +197,9 @@ function createElement({ containerId, model, options }) {
195
197
  });
196
198
  }
197
199
 
198
- // src/sync/update-element-editor-settings.ts
199
- import { __privateRunCommandSync as runCommandSync2 } from "@elementor/editor-v1-adapters";
200
- var updateElementEditorSettings = ({
201
- elementId,
202
- settings
203
- }) => {
204
- const element = getContainer(elementId);
205
- if (!element) {
206
- throw new Error(`Element with id ${elementId} not found`);
207
- }
208
- const editorSettings = element.model.get("editor_settings") ?? {};
209
- element.model.set("editor_settings", { ...editorSettings, ...settings });
210
- setDocumentModifiedStatus(true);
211
- };
212
- function setDocumentModifiedStatus(status) {
213
- runCommandSync2("document/save/set-is-modified", { status }, { internal: true });
214
- }
200
+ // src/sync/create-elements.ts
201
+ import { undoable } from "@elementor/editor-v1-adapters";
202
+ import { __ } from "@wordpress/i18n";
215
203
 
216
204
  // src/sync/delete-element.ts
217
205
  import { __privateRunCommand as runCommand2 } from "@elementor/editor-v1-adapters";
@@ -229,97 +217,60 @@ function deleteElement({
229
217
  });
230
218
  }
231
219
 
232
- // src/sync/move-element.ts
233
- function moveElement({ elementId, targetContainerId, options = {} }) {
234
- const container = getContainer(elementId);
235
- const target = getContainer(targetContainerId);
236
- if (!container) {
237
- throw new Error(`Element with ID "${elementId}" not found`);
238
- }
239
- if (!target) {
240
- throw new Error(`Target container with ID "${targetContainerId}" not found`);
241
- }
242
- const modelToRecreate = container.model.toJSON();
243
- deleteElement({
244
- elementId,
245
- // prevent inner history from being created
246
- options: { ...options, useHistory: false }
247
- });
248
- const newContainer = createElement({
249
- containerId: targetContainerId,
250
- model: modelToRecreate,
251
- // prevent inner history from being created
252
- options: { edit: false, ...options, useHistory: false }
253
- });
254
- return newContainer;
255
- }
256
-
257
- // src/sync/move-elements.ts
258
- import { undoable } from "@elementor/editor-v1-adapters";
259
- import { __ } from "@wordpress/i18n";
260
- var moveElements = ({
261
- moves: movesToMake,
220
+ // src/sync/create-elements.ts
221
+ var createElements = ({
222
+ elements,
262
223
  title,
263
- subtitle = __("Elements moved", "elementor")
224
+ subtitle = __("Item added", "elementor")
264
225
  }) => {
265
- const undoableMove = undoable(
226
+ const undoableCreate = undoable(
266
227
  {
267
- do: ({ moves }) => {
268
- const movedElements = [];
269
- moves.forEach((move) => {
270
- const { elementId } = move;
271
- const sourceContainer = getContainer(elementId);
272
- if (!sourceContainer) {
273
- throw new Error(`Element with ID "${elementId}" not found`);
274
- }
275
- const originalContainerId = sourceContainer.parent?.id || "";
276
- const originalIndex = sourceContainer.parent?.children?.indexOf(sourceContainer) ?? -1;
277
- const originalPosition = {
278
- elementId,
279
- originalContainerId,
280
- originalIndex
281
- };
282
- const element = moveElement({
283
- ...move,
284
- options: { ...move.options, useHistory: false }
228
+ do: ({ elements: elementsParam }) => {
229
+ const createdElements = [];
230
+ elementsParam.forEach((createParams) => {
231
+ const { options, ...elementParams } = createParams;
232
+ const element = createElement({
233
+ ...elementParams,
234
+ options: { ...options, useHistory: false }
285
235
  });
286
- movedElements.push({
236
+ const elementId = element.id;
237
+ createdElements.push({
287
238
  elementId,
288
- originalPosition,
289
- move,
290
- element
239
+ model: element.model?.toJSON() || {},
240
+ createParams: {
241
+ ...createParams
242
+ }
291
243
  });
292
244
  });
293
- return { movedElements };
245
+ return { createdElements };
294
246
  },
295
- undo: (_, { movedElements }) => {
296
- [...movedElements].reverse().forEach(({ originalPosition }) => {
297
- const { elementId, originalContainerId, originalIndex } = originalPosition;
298
- moveElement({
247
+ undo: (_, { createdElements }) => {
248
+ [...createdElements].reverse().forEach(({ elementId }) => {
249
+ deleteElement({
299
250
  elementId,
300
- targetContainerId: originalContainerId,
301
- options: {
302
- useHistory: false,
303
- at: originalIndex >= 0 ? originalIndex : void 0
304
- }
251
+ options: { useHistory: false }
305
252
  });
306
253
  });
307
254
  },
308
- redo: (_, { movedElements }) => {
309
- const newMovedElements = [];
310
- movedElements.forEach(({ move, originalPosition }) => {
311
- const element = moveElement({
312
- ...move,
313
- options: { ...move.options, useHistory: false }
314
- });
315
- newMovedElements.push({
316
- elementId: move.elementId,
317
- originalPosition,
318
- move,
319
- element
255
+ redo: (_, { createdElements }) => {
256
+ const newElements = [];
257
+ createdElements.forEach(({ createParams, model }) => {
258
+ const element = createElement({
259
+ containerId: createParams.containerId,
260
+ model,
261
+ options: { ...createParams.options, useHistory: false }
320
262
  });
263
+ const elementId = element.id;
264
+ const container = getContainer(elementId);
265
+ if (container) {
266
+ newElements.push({
267
+ elementId,
268
+ model: container.model.toJSON(),
269
+ createParams
270
+ });
271
+ }
321
272
  });
322
- return { movedElements: newMovedElements };
273
+ return { createdElements: newElements };
323
274
  }
324
275
  },
325
276
  {
@@ -327,9 +278,23 @@ var moveElements = ({
327
278
  subtitle
328
279
  }
329
280
  );
330
- return undoableMove({ moves: movesToMake });
281
+ return undoableCreate({ elements });
331
282
  };
332
283
 
284
+ // src/sync/drop-element.ts
285
+ import { __privateRunCommandSync as runCommandSync2 } from "@elementor/editor-v1-adapters";
286
+ function dropElement({ containerId, model, options }) {
287
+ const container = getContainer(containerId);
288
+ if (!container) {
289
+ throw new Error(`Container with ID "${containerId}" not found`);
290
+ }
291
+ return runCommandSync2("preview/drop", {
292
+ container,
293
+ model,
294
+ options
295
+ });
296
+ }
297
+
333
298
  // src/sync/duplicate-element.ts
334
299
  function duplicateElement({ elementId, options = {} }) {
335
300
  const elementToDuplicate = getContainer(elementId);
@@ -353,81 +318,15 @@ function duplicateElement({ elementId, options = {} }) {
353
318
  });
354
319
  }
355
320
 
356
- // src/sync/create-elements.ts
321
+ // src/sync/duplicate-elements.ts
357
322
  import { undoable as undoable2 } from "@elementor/editor-v1-adapters";
358
323
  import { __ as __2 } from "@wordpress/i18n";
359
- var createElements = ({
360
- elements,
361
- title,
362
- subtitle = __2("Item added", "elementor")
363
- }) => {
364
- const undoableCreate = undoable2(
365
- {
366
- do: ({ elements: elementsParam }) => {
367
- const createdElements = [];
368
- elementsParam.forEach((createParams) => {
369
- const { options, ...elementParams } = createParams;
370
- const element = createElement({
371
- ...elementParams,
372
- options: { ...options, useHistory: false }
373
- });
374
- const elementId = element.id;
375
- createdElements.push({
376
- elementId,
377
- model: element.model?.toJSON() || {},
378
- createParams: {
379
- ...createParams
380
- }
381
- });
382
- });
383
- return { createdElements };
384
- },
385
- undo: (_, { createdElements }) => {
386
- [...createdElements].reverse().forEach(({ elementId }) => {
387
- deleteElement({
388
- elementId,
389
- options: { useHistory: false }
390
- });
391
- });
392
- },
393
- redo: (_, { createdElements }) => {
394
- const newElements = [];
395
- createdElements.forEach(({ createParams, model }) => {
396
- const element = createElement({
397
- containerId: createParams.containerId,
398
- model,
399
- options: { ...createParams.options, useHistory: false }
400
- });
401
- const elementId = element.id;
402
- const container = getContainer(elementId);
403
- if (container) {
404
- newElements.push({
405
- elementId,
406
- model: container.model.toJSON(),
407
- createParams
408
- });
409
- }
410
- });
411
- return { createdElements: newElements };
412
- }
413
- },
414
- {
415
- title,
416
- subtitle
417
- }
418
- );
419
- return undoableCreate({ elements });
420
- };
421
-
422
- // src/sync/duplicate-elements.ts
423
- import { undoable as undoable3 } from "@elementor/editor-v1-adapters";
424
- import { __ as __3 } from "@wordpress/i18n";
425
324
  var duplicateElements = ({
426
325
  elementIds,
427
326
  title,
428
- subtitle = __3("Item duplicated", "elementor")
327
+ subtitle = __2("Item duplicated", "elementor")
429
328
  }) => {
430
- const undoableDuplicate = undoable3(
329
+ const undoableDuplicate = undoable2(
431
330
  {
432
331
  do: ({ elementIds: elementIdsToDuplicate }) => {
433
332
  const duplicatedElements = elementIdsToDuplicate.reduce((acc, elementId) => {
@@ -492,6 +391,187 @@ var duplicateElements = ({
492
391
  return undoableDuplicate({ elementIds });
493
392
  };
494
393
 
394
+ // src/sync/generate-element-id.ts
395
+ var generateElementId = () => {
396
+ const extendedWindow = window;
397
+ return extendedWindow.elementorCommon?.helpers?.getUniqueId?.() ?? `el-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
398
+ };
399
+
400
+ // src/sync/get-current-document-container.ts
401
+ function getCurrentDocumentContainer() {
402
+ const extendedWindow = window;
403
+ return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
404
+ }
405
+
406
+ // src/sync/get-current-document-id.ts
407
+ function getCurrentDocumentId() {
408
+ const extendedWindow = window;
409
+ return extendedWindow.elementor?.documents?.getCurrentId?.() ?? null;
410
+ }
411
+
412
+ // src/errors.ts
413
+ import { createError } from "@elementor/utils";
414
+ var ElementNotFoundError = createError({
415
+ code: "element_not_found",
416
+ message: "Element not found."
417
+ });
418
+ var StyleNotFoundError = createError({
419
+ code: "style_not_found",
420
+ message: "Style not found."
421
+ });
422
+ var ElementTypeNotExistsError = createError({
423
+ code: "element_type_not_exists",
424
+ message: "Element type does not exist."
425
+ });
426
+ var ElementLabelNotExistsError = createError({
427
+ code: "element_label_not_exists",
428
+ message: "Element label does not exist."
429
+ });
430
+ var ElementParentNotFoundError = createError({
431
+ code: "element_parent_not_found",
432
+ message: "Element parent not found."
433
+ });
434
+ var ElementIndexNotFoundError = createError({
435
+ code: "element_index_not_found",
436
+ message: "Element index not found."
437
+ });
438
+
439
+ // src/sync/get-element-label.ts
440
+ function getElementLabel(elementId) {
441
+ if (!elementId) {
442
+ elementId = getSelectedElements()?.[0]?.id;
443
+ }
444
+ const container = getContainer(elementId);
445
+ const type = container?.model.get("widgetType") || container?.model.get("elType");
446
+ if (!type) {
447
+ throw new ElementTypeNotExistsError({ context: { elementId } });
448
+ }
449
+ const label = getWidgetsCache()?.[type]?.title;
450
+ if (!label) {
451
+ throw new ElementLabelNotExistsError({ context: { elementType: type } });
452
+ }
453
+ return label;
454
+ }
455
+
456
+ // src/sync/get-element-styles.ts
457
+ var getElementStyles = (elementID) => {
458
+ const container = getContainer(elementID);
459
+ return container?.model.get("styles") || null;
460
+ };
461
+
462
+ // src/sync/get-elements.ts
463
+ function getElements(root) {
464
+ const container = root ? getContainer(root) : getCurrentDocumentContainer();
465
+ if (!container) {
466
+ return [];
467
+ }
468
+ const children = [...container.model.get("elements") ?? []].flatMap(
469
+ (childModel) => getElements(childModel.get("id"))
470
+ );
471
+ return [container, ...children];
472
+ }
473
+
474
+ // src/sync/move-element.ts
475
+ function moveElement({ elementId, targetContainerId, options = {} }) {
476
+ const container = getContainer(elementId);
477
+ const target = getContainer(targetContainerId);
478
+ if (!container) {
479
+ throw new Error(`Element with ID "${elementId}" not found`);
480
+ }
481
+ if (!target) {
482
+ throw new Error(`Target container with ID "${targetContainerId}" not found`);
483
+ }
484
+ const modelToRecreate = container.model.toJSON();
485
+ deleteElement({
486
+ elementId,
487
+ // prevent inner history from being created
488
+ options: { ...options, useHistory: false }
489
+ });
490
+ const newContainer = createElement({
491
+ containerId: targetContainerId,
492
+ model: modelToRecreate,
493
+ // prevent inner history from being created
494
+ options: { edit: false, ...options, useHistory: false }
495
+ });
496
+ return newContainer;
497
+ }
498
+
499
+ // src/sync/move-elements.ts
500
+ import { undoable as undoable3 } from "@elementor/editor-v1-adapters";
501
+ import { __ as __3 } from "@wordpress/i18n";
502
+ var moveElements = ({
503
+ moves: movesToMake,
504
+ title,
505
+ subtitle = __3("Elements moved", "elementor")
506
+ }) => {
507
+ const undoableMove = undoable3(
508
+ {
509
+ do: ({ moves }) => {
510
+ const movedElements = [];
511
+ moves.forEach((move) => {
512
+ const { elementId } = move;
513
+ const sourceContainer = getContainer(elementId);
514
+ if (!sourceContainer) {
515
+ throw new Error(`Element with ID "${elementId}" not found`);
516
+ }
517
+ const originalContainerId = sourceContainer.parent?.id || "";
518
+ const originalIndex = sourceContainer.parent?.children?.indexOf(sourceContainer) ?? -1;
519
+ const originalPosition = {
520
+ elementId,
521
+ originalContainerId,
522
+ originalIndex
523
+ };
524
+ const element = moveElement({
525
+ ...move,
526
+ options: { ...move.options, useHistory: false }
527
+ });
528
+ movedElements.push({
529
+ elementId,
530
+ originalPosition,
531
+ move,
532
+ element
533
+ });
534
+ });
535
+ return { movedElements };
536
+ },
537
+ undo: (_, { movedElements }) => {
538
+ [...movedElements].reverse().forEach(({ originalPosition }) => {
539
+ const { elementId, originalContainerId, originalIndex } = originalPosition;
540
+ moveElement({
541
+ elementId,
542
+ targetContainerId: originalContainerId,
543
+ options: {
544
+ useHistory: false,
545
+ at: originalIndex >= 0 ? originalIndex : void 0
546
+ }
547
+ });
548
+ });
549
+ },
550
+ redo: (_, { movedElements }) => {
551
+ const newMovedElements = [];
552
+ movedElements.forEach(({ move, originalPosition }) => {
553
+ const element = moveElement({
554
+ ...move,
555
+ options: { ...move.options, useHistory: false }
556
+ });
557
+ newMovedElements.push({
558
+ elementId: move.elementId,
559
+ originalPosition,
560
+ move,
561
+ element
562
+ });
563
+ });
564
+ return { movedElements: newMovedElements };
565
+ }
566
+ },
567
+ {
568
+ title,
569
+ subtitle
570
+ }
571
+ );
572
+ return undoableMove({ moves: movesToMake });
573
+ };
574
+
495
575
  // src/sync/remove-elements.ts
496
576
  import { undoable as undoable4 } from "@elementor/editor-v1-adapters";
497
577
  import { __ as __4 } from "@wordpress/i18n";
@@ -562,82 +642,65 @@ var removeElements = ({
562
642
  return undoableRemove({ elementIds });
563
643
  };
564
644
 
565
- // src/sync/get-element-styles.ts
566
- var getElementStyles = (elementID) => {
567
- const container = getContainer(elementID);
568
- return container?.model.get("styles") || null;
645
+ // src/sync/replace-element.ts
646
+ var replaceElement = ({ currentElement, newElement, withHistory = true }) => {
647
+ const { containerId, index } = getNewElementLocation(currentElement, newElement);
648
+ createElement({
649
+ containerId,
650
+ model: newElement,
651
+ options: { at: index, useHistory: withHistory }
652
+ });
653
+ deleteElement({ elementId: currentElement.id, options: { useHistory: withHistory } });
569
654
  };
570
-
571
- // src/errors.ts
572
- import { createError } from "@elementor/utils";
573
- var ElementNotFoundError = createError({
574
- code: "element_not_found",
575
- message: "Element not found."
576
- });
577
- var StyleNotFoundError = createError({
578
- code: "style_not_found",
579
- message: "Style not found."
580
- });
581
- var ElementTypeNotExistsError = createError({
582
- code: "element_type_not_exists",
583
- message: "Element type does not exist."
584
- });
585
- var ElementLabelNotExistsError = createError({
586
- code: "element_label_not_exists",
587
- message: "Element label does not exist."
588
- });
589
- var ElementParentNotFoundError = createError({
590
- code: "element_parent_not_found",
591
- message: "Element parent not found."
592
- });
593
- var ElementIndexNotFoundError = createError({
594
- code: "element_index_not_found",
595
- message: "Element index not found."
596
- });
597
-
598
- // src/sync/get-element-label.ts
599
- function getElementLabel(elementId) {
600
- if (!elementId) {
601
- elementId = getSelectedElements()?.[0]?.id;
655
+ function getNewElementLocation(currentElement, newElement) {
656
+ let location;
657
+ const currentElementContainer = getContainer(currentElement.id);
658
+ if (!currentElementContainer) {
659
+ throw new ElementNotFoundError({ context: { elementId: currentElement.id } });
602
660
  }
603
- const container = getContainer(elementId);
604
- const type = container?.model.get("widgetType") || container?.model.get("elType");
605
- if (!type) {
606
- throw new ElementTypeNotExistsError({ context: { elementId } });
661
+ const parent = currentElementContainer.parent;
662
+ if (!parent) {
663
+ throw new ElementParentNotFoundError({ context: { elementId: currentElement.id } });
607
664
  }
608
- const label = getWidgetsCache()?.[type]?.title;
609
- if (!label) {
610
- throw new ElementLabelNotExistsError({ context: { elementType: type } });
665
+ const elementIndex = currentElementContainer.view?._index ?? 0;
666
+ if (elementIndex === void 0 || elementIndex === -1) {
667
+ throw new ElementIndexNotFoundError({ context: { elementId: currentElement.id } });
611
668
  }
612
- return label;
669
+ location = { containerId: parent.id, index: elementIndex };
670
+ if (parent.id === "document" && newElement.elType === "widget") {
671
+ location = createWrapperForWidget(parent.id, elementIndex);
672
+ }
673
+ return location;
613
674
  }
614
-
615
- // src/sync/get-current-document-container.ts
616
- function getCurrentDocumentContainer() {
617
- const extendedWindow = window;
618
- return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
675
+ function createWrapperForWidget(parentId, elementIndex) {
676
+ const container = createElement({
677
+ containerId: parentId,
678
+ model: { elType: "container" },
679
+ options: { at: elementIndex, useHistory: false }
680
+ });
681
+ return { containerId: container.id, index: 0 };
619
682
  }
620
683
 
621
- // src/sync/get-elements.ts
622
- function getElements(root) {
623
- const container = root ? getContainer(root) : getCurrentDocumentContainer();
624
- if (!container) {
625
- return [];
684
+ // src/sync/update-element-editor-settings.ts
685
+ import { __privateRunCommandSync as runCommandSync3 } from "@elementor/editor-v1-adapters";
686
+ var updateElementEditorSettings = ({
687
+ elementId,
688
+ settings
689
+ }) => {
690
+ const element = getContainer(elementId);
691
+ if (!element) {
692
+ throw new Error(`Element with id ${elementId} not found`);
626
693
  }
627
- const children = [...container.model.get("elements") ?? []].flatMap(
628
- (childModel) => getElements(childModel.get("id"))
629
- );
630
- return [container, ...children];
631
- }
632
-
633
- // src/sync/get-current-document-id.ts
634
- function getCurrentDocumentId() {
635
- const extendedWindow = window;
636
- return extendedWindow.elementor?.documents?.getCurrentId?.() ?? null;
694
+ const editorSettings = element.model.get("editor_settings") ?? {};
695
+ element.model.set("editor_settings", { ...editorSettings, ...settings });
696
+ setDocumentModifiedStatus(true);
697
+ };
698
+ function setDocumentModifiedStatus(status) {
699
+ runCommandSync3("document/save/set-is-modified", { status }, { internal: true });
637
700
  }
638
701
 
639
702
  // src/sync/update-element-settings.ts
640
- import { __privateRunCommandSync as runCommandSync3 } from "@elementor/editor-v1-adapters";
703
+ import { __privateRunCommandSync as runCommandSync4 } from "@elementor/editor-v1-adapters";
641
704
  var updateElementSettings = ({ id, props, withHistory = true }) => {
642
705
  const container = getContainer(id);
643
706
  const args = {
@@ -645,69 +708,94 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
645
708
  settings: { ...props }
646
709
  };
647
710
  if (withHistory) {
648
- runCommandSync3("document/elements/settings", args);
711
+ runCommandSync4("document/elements/settings", args);
649
712
  } else {
650
- runCommandSync3("document/elements/set-settings", args, { internal: true });
713
+ runCommandSync4("document/elements/set-settings", args, { internal: true });
651
714
  }
652
715
  };
653
716
 
654
- // src/sync/generate-element-id.ts
655
- var generateElementId = () => {
656
- const extendedWindow = window;
657
- return extendedWindow.elementorCommon?.helpers?.getUniqueId?.() ?? `el-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
658
- };
659
-
660
- // src/sync/replace-element.ts
661
- var replaceElement = ({ currentElement, newElement, withHistory = true }) => {
662
- const { containerId, index } = getNewElementLocation(currentElement, newElement);
663
- createElement({
664
- containerId,
665
- model: newElement,
666
- options: { at: index, useHistory: withHistory }
667
- });
668
- deleteElement({ elementId: currentElement.id, options: { useHistory: withHistory } });
669
- };
670
- function getNewElementLocation(currentElement, newElement) {
671
- let location;
672
- const currentElementContainer = getContainer(currentElement.id);
673
- if (!currentElementContainer) {
674
- throw new ElementNotFoundError({ context: { elementId: currentElement.id } });
717
+ // src/link-restriction.ts
718
+ function getLinkInLinkRestriction(elementId) {
719
+ const anchoredDescendantId = getAnchoredDescendantId(elementId);
720
+ if (anchoredDescendantId) {
721
+ return {
722
+ shouldRestrict: true,
723
+ reason: "descendant",
724
+ elementId: anchoredDescendantId
725
+ };
675
726
  }
676
- const parent = currentElementContainer.parent;
677
- if (!parent) {
678
- throw new ElementParentNotFoundError({ context: { elementId: currentElement.id } });
727
+ const ancestor = getAnchoredAncestorId(elementId);
728
+ if (ancestor) {
729
+ return {
730
+ shouldRestrict: true,
731
+ reason: "ancestor",
732
+ elementId: ancestor
733
+ };
679
734
  }
680
- const elementIndex = currentElementContainer.view?._index ?? 0;
681
- if (elementIndex === void 0 || elementIndex === -1) {
682
- throw new ElementIndexNotFoundError({ context: { elementId: currentElement.id } });
735
+ return {
736
+ shouldRestrict: false
737
+ };
738
+ }
739
+ function getAnchoredDescendantId(elementId) {
740
+ const element = getElementDOM(elementId);
741
+ if (!element) {
742
+ return null;
683
743
  }
684
- location = { containerId: parent.id, index: elementIndex };
685
- if (parent.id === "document" && newElement.elType === "widget") {
686
- location = createWrapperForWidget(parent.id, elementIndex);
744
+ for (const childAnchorElement of Array.from(element.querySelectorAll("a"))) {
745
+ const childElementId = findElementIdOf(childAnchorElement);
746
+ if (childElementId !== elementId) {
747
+ return childElementId;
748
+ }
687
749
  }
688
- return location;
750
+ return null;
689
751
  }
690
- function createWrapperForWidget(parentId, elementIndex) {
691
- const container = createElement({
692
- containerId: parentId,
693
- model: { elType: "container" },
694
- options: { at: elementIndex, useHistory: false }
695
- });
696
- return { containerId: container.id, index: 0 };
752
+ function getAnchoredAncestorId(elementId) {
753
+ const element = getElementDOM(elementId);
754
+ if (!element || element.parentElement === null) {
755
+ return null;
756
+ }
757
+ const parentAnchor = element.parentElement.closest("a");
758
+ return parentAnchor ? findElementIdOf(parentAnchor) : null;
697
759
  }
698
-
699
- // src/sync/drop-element.ts
700
- import { __privateRunCommandSync as runCommandSync4 } from "@elementor/editor-v1-adapters";
701
- function dropElement({ containerId, model, options }) {
702
- const container = getContainer(containerId);
703
- if (!container) {
704
- throw new Error(`Container with ID "${containerId}" not found`);
760
+ function isElementAnchored(elementId) {
761
+ const element = getElementDOM(elementId);
762
+ if (!element) {
763
+ return false;
764
+ }
765
+ if (isAnchorTag(element.tagName)) {
766
+ return true;
767
+ }
768
+ return doesElementContainAnchor(element);
769
+ }
770
+ function doesElementContainAnchor(element) {
771
+ for (const child of element.children) {
772
+ if (isElementorElement(child)) {
773
+ continue;
774
+ }
775
+ if (isAnchorTag(child.tagName)) {
776
+ return true;
777
+ }
778
+ if (doesElementContainAnchor(child)) {
779
+ return true;
780
+ }
781
+ }
782
+ return false;
783
+ }
784
+ function findElementIdOf(element) {
785
+ return element.closest("[data-id]")?.dataset.id || null;
786
+ }
787
+ function getElementDOM(id) {
788
+ try {
789
+ return getContainer(id)?.view?.el || null;
790
+ } catch {
791
+ return null;
705
792
  }
706
- return runCommandSync4("preview/drop", {
707
- container,
708
- model,
709
- options
710
- });
793
+ }
794
+ function isAnchorTag(tagName) {
795
+ return tagName.toLowerCase() === "a";
796
+ }
797
+ function isElementorElement(element) {
798
+ return element.hasAttribute("data-id");
711
799
  }
712
800
 
713
801
  // src/styles/consts.ts
@@ -837,6 +925,14 @@ function shouldCreateNewLocalStyle(payload) {
837
925
  return !payload?.styleId && !payload?.provider;
838
926
  }
839
927
 
928
+ // src/styles/delete-element-style.ts
929
+ function deleteElementStyle(elementId, styleId) {
930
+ mutateElementStyles(elementId, (styles) => {
931
+ delete styles[styleId];
932
+ return styles;
933
+ });
934
+ }
935
+
840
936
  // src/styles/update-element-style.ts
841
937
  import { mergeProps } from "@elementor/editor-props";
842
938
  import { getVariantByMeta } from "@elementor/editor-styles";
@@ -858,97 +954,9 @@ function updateElementStyle(args) {
858
954
  });
859
955
  }
860
956
 
861
- // src/styles/delete-element-style.ts
862
- function deleteElementStyle(elementId, styleId) {
863
- mutateElementStyles(elementId, (styles) => {
864
- delete styles[styleId];
865
- return styles;
866
- });
867
- }
868
-
869
- // src/link-restriction.ts
870
- function getLinkInLinkRestriction(elementId) {
871
- const anchoredDescendantId = getAnchoredDescendantId(elementId);
872
- if (anchoredDescendantId) {
873
- return {
874
- shouldRestrict: true,
875
- reason: "descendant",
876
- elementId: anchoredDescendantId
877
- };
878
- }
879
- const ancestor = getAnchoredAncestorId(elementId);
880
- if (ancestor) {
881
- return {
882
- shouldRestrict: true,
883
- reason: "ancestor",
884
- elementId: ancestor
885
- };
886
- }
887
- return {
888
- shouldRestrict: false
889
- };
890
- }
891
- function getAnchoredDescendantId(elementId) {
892
- const element = getElementDOM(elementId);
893
- if (!element) {
894
- return null;
895
- }
896
- for (const childAnchorElement of Array.from(element.querySelectorAll("a"))) {
897
- const childElementId = findElementIdOf(childAnchorElement);
898
- if (childElementId !== elementId) {
899
- return childElementId;
900
- }
901
- }
902
- return null;
903
- }
904
- function getAnchoredAncestorId(elementId) {
905
- const element = getElementDOM(elementId);
906
- if (!element || element.parentElement === null) {
907
- return null;
908
- }
909
- const parentAnchor = element.parentElement.closest("a");
910
- return parentAnchor ? findElementIdOf(parentAnchor) : null;
911
- }
912
- function isElementAnchored(elementId) {
913
- const element = getElementDOM(elementId);
914
- if (!element) {
915
- return false;
916
- }
917
- if (isAnchorTag(element.tagName)) {
918
- return true;
919
- }
920
- return doesElementContainAnchor(element);
921
- }
922
- function doesElementContainAnchor(element) {
923
- for (const child of element.children) {
924
- if (isElementorElement(child)) {
925
- continue;
926
- }
927
- if (isAnchorTag(child.tagName)) {
928
- return true;
929
- }
930
- if (doesElementContainAnchor(child)) {
931
- return true;
932
- }
933
- }
934
- return false;
935
- }
936
- function findElementIdOf(element) {
937
- return element.closest("[data-id]")?.dataset.id || null;
938
- }
939
- function getElementDOM(id) {
940
- try {
941
- return getContainer(id)?.view?.el || null;
942
- } catch {
943
- return null;
944
- }
945
- }
946
- function isAnchorTag(tagName) {
947
- return tagName.toLowerCase() === "a";
948
- }
949
- function isElementorElement(element) {
950
- return element.hasAttribute("data-id");
951
- }
957
+ // src/hooks/use-element-interactions.ts
958
+ import { useState } from "react";
959
+ import { __privateUseListenTo as useListenTo6, windowEvent as windowEvent3 } from "@elementor/editor-v1-adapters";
952
960
 
953
961
  // src/sync/get-element-interactions.ts
954
962
  function getElementInteractions(elementId) {
@@ -960,6 +968,23 @@ function getElementInteractions(elementId) {
960
968
  return JSON.stringify(interactions);
961
969
  }
962
970
 
971
+ // src/hooks/use-element-interactions.ts
972
+ var useElementInteractions = (elementId) => {
973
+ const [interactions, setInteractions] = useState(() => {
974
+ const initial = getElementInteractions(elementId);
975
+ return initial;
976
+ });
977
+ useListenTo6(
978
+ windowEvent3("elementor/element/update_interactions"),
979
+ () => {
980
+ const newInteractions = getElementInteractions(elementId);
981
+ setInteractions(newInteractions);
982
+ },
983
+ [elementId]
984
+ );
985
+ return interactions;
986
+ };
987
+
963
988
  // src/sync/update-element-interactions.ts
964
989
  import { __privateRunCommandSync as runCommandSync6 } from "@elementor/editor-v1-adapters";
965
990
  var updateElementInteractions = ({
@@ -981,25 +1006,6 @@ function setDocumentModifiedStatus2(status) {
981
1006
  runCommandSync6("document/save/set-is-modified", { status }, { internal: true });
982
1007
  }
983
1008
 
984
- // src/hooks/use-element-interactions.ts
985
- import { useState } from "react";
986
- import { __privateUseListenTo as useListenTo6, windowEvent as windowEvent3 } from "@elementor/editor-v1-adapters";
987
- var useElementInteractions = (elementId) => {
988
- const [interactions, setInteractions] = useState(() => {
989
- const initial = getElementInteractions(elementId);
990
- return initial;
991
- });
992
- useListenTo6(
993
- windowEvent3("elementor/element/update_interactions"),
994
- () => {
995
- const newInteractions = getElementInteractions(elementId);
996
- setInteractions(newInteractions);
997
- },
998
- [elementId]
999
- );
1000
- return interactions;
1001
- };
1002
-
1003
1009
  // src/mcp/index.ts
1004
1010
  import { getMCPByDomain as getMCPByDomain2 } from "@elementor/editor-mcp";
1005
1011