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

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,192 @@ 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
+ onMoveElements,
507
+ onRestoreElements
508
+ }) => {
509
+ const undoableMove = undoable3(
510
+ {
511
+ do: ({ moves }) => {
512
+ const movedElements = [];
513
+ moves.forEach((move) => {
514
+ const { elementId } = move;
515
+ const sourceContainer = getContainer(elementId);
516
+ if (!sourceContainer) {
517
+ throw new Error(`Element with ID "${elementId}" not found`);
518
+ }
519
+ const originalContainerId = sourceContainer.parent?.id || "";
520
+ const originalIndex = sourceContainer.parent?.children?.indexOf(sourceContainer) ?? -1;
521
+ const originalPosition = {
522
+ elementId,
523
+ originalContainerId,
524
+ originalIndex
525
+ };
526
+ const element = moveElement({
527
+ ...move,
528
+ options: { ...move.options, useHistory: false }
529
+ });
530
+ onMoveElements?.();
531
+ movedElements.push({
532
+ elementId,
533
+ originalPosition,
534
+ move,
535
+ element
536
+ });
537
+ });
538
+ return { movedElements };
539
+ },
540
+ undo: (_, { movedElements }) => {
541
+ [...movedElements].reverse().forEach(({ originalPosition }) => {
542
+ const { elementId, originalContainerId, originalIndex } = originalPosition;
543
+ onRestoreElements?.();
544
+ moveElement({
545
+ elementId,
546
+ targetContainerId: originalContainerId,
547
+ options: {
548
+ useHistory: false,
549
+ at: originalIndex >= 0 ? originalIndex : void 0
550
+ }
551
+ });
552
+ });
553
+ },
554
+ redo: (_, { movedElements }) => {
555
+ const newMovedElements = [];
556
+ movedElements.forEach(({ move, originalPosition }) => {
557
+ const element = moveElement({
558
+ ...move,
559
+ options: { ...move.options, useHistory: false }
560
+ });
561
+ onMoveElements?.();
562
+ newMovedElements.push({
563
+ elementId: move.elementId,
564
+ originalPosition,
565
+ move,
566
+ element
567
+ });
568
+ });
569
+ return { movedElements: newMovedElements };
570
+ }
571
+ },
572
+ {
573
+ title,
574
+ subtitle
575
+ }
576
+ );
577
+ return undoableMove({ moves: movesToMake });
578
+ };
579
+
495
580
  // src/sync/remove-elements.ts
496
581
  import { undoable as undoable4 } from "@elementor/editor-v1-adapters";
497
582
  import { __ as __4 } from "@wordpress/i18n";
@@ -520,18 +605,17 @@ var removeElements = ({
520
605
  });
521
606
  }
522
607
  });
523
- const results = elementIdsParam.map((elementId) => {
524
- return deleteElement({
608
+ onRemoveElements?.();
609
+ elementIdsParam.forEach((elementId) => {
610
+ deleteElement({
525
611
  elementId,
526
612
  options: { useHistory: false }
527
613
  });
528
614
  });
529
- Promise.all(results).then(() => {
530
- onRemoveElements?.();
531
- });
532
615
  return { elementIds: elementIdsParam, removedElements };
533
616
  },
534
617
  undo: (_, { removedElements }) => {
618
+ onRestoreElements?.();
535
619
  [...removedElements].reverse().forEach(({ model, parent, at }) => {
536
620
  if (parent && model) {
537
621
  createElement({
@@ -541,16 +625,15 @@ var removeElements = ({
541
625
  });
542
626
  }
543
627
  });
544
- onRestoreElements?.();
545
628
  },
546
629
  redo: (_, { elementIds: originalElementIds, removedElements }) => {
630
+ onRemoveElements?.();
547
631
  originalElementIds.forEach((elementId) => {
548
632
  deleteElement({
549
633
  elementId,
550
634
  options: { useHistory: false }
551
635
  });
552
636
  });
553
- onRemoveElements?.();
554
637
  return { elementIds: originalElementIds, removedElements };
555
638
  }
556
639
  },
@@ -562,82 +645,65 @@ var removeElements = ({
562
645
  return undoableRemove({ elementIds });
563
646
  };
564
647
 
565
- // src/sync/get-element-styles.ts
566
- var getElementStyles = (elementID) => {
567
- const container = getContainer(elementID);
568
- return container?.model.get("styles") || null;
648
+ // src/sync/replace-element.ts
649
+ var replaceElement = ({ currentElement, newElement, withHistory = true }) => {
650
+ const { containerId, index } = getNewElementLocation(currentElement, newElement);
651
+ createElement({
652
+ containerId,
653
+ model: newElement,
654
+ options: { at: index, useHistory: withHistory }
655
+ });
656
+ deleteElement({ elementId: currentElement.id, options: { useHistory: withHistory } });
569
657
  };
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;
658
+ function getNewElementLocation(currentElement, newElement) {
659
+ let location;
660
+ const currentElementContainer = getContainer(currentElement.id);
661
+ if (!currentElementContainer) {
662
+ throw new ElementNotFoundError({ context: { elementId: currentElement.id } });
602
663
  }
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 } });
664
+ const parent = currentElementContainer.parent;
665
+ if (!parent) {
666
+ throw new ElementParentNotFoundError({ context: { elementId: currentElement.id } });
607
667
  }
608
- const label = getWidgetsCache()?.[type]?.title;
609
- if (!label) {
610
- throw new ElementLabelNotExistsError({ context: { elementType: type } });
668
+ const elementIndex = currentElementContainer.view?._index ?? 0;
669
+ if (elementIndex === void 0 || elementIndex === -1) {
670
+ throw new ElementIndexNotFoundError({ context: { elementId: currentElement.id } });
611
671
  }
612
- return label;
672
+ location = { containerId: parent.id, index: elementIndex };
673
+ if (parent.id === "document" && newElement.elType === "widget") {
674
+ location = createWrapperForWidget(parent.id, elementIndex);
675
+ }
676
+ return location;
613
677
  }
614
-
615
- // src/sync/get-current-document-container.ts
616
- function getCurrentDocumentContainer() {
617
- const extendedWindow = window;
618
- return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
678
+ function createWrapperForWidget(parentId, elementIndex) {
679
+ const container = createElement({
680
+ containerId: parentId,
681
+ model: { elType: "container" },
682
+ options: { at: elementIndex, useHistory: false }
683
+ });
684
+ return { containerId: container.id, index: 0 };
619
685
  }
620
686
 
621
- // src/sync/get-elements.ts
622
- function getElements(root) {
623
- const container = root ? getContainer(root) : getCurrentDocumentContainer();
624
- if (!container) {
625
- return [];
687
+ // src/sync/update-element-editor-settings.ts
688
+ import { __privateRunCommandSync as runCommandSync3 } from "@elementor/editor-v1-adapters";
689
+ var updateElementEditorSettings = ({
690
+ elementId,
691
+ settings
692
+ }) => {
693
+ const element = getContainer(elementId);
694
+ if (!element) {
695
+ throw new Error(`Element with id ${elementId} not found`);
626
696
  }
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;
697
+ const editorSettings = element.model.get("editor_settings") ?? {};
698
+ element.model.set("editor_settings", { ...editorSettings, ...settings });
699
+ setDocumentModifiedStatus(true);
700
+ };
701
+ function setDocumentModifiedStatus(status) {
702
+ runCommandSync3("document/save/set-is-modified", { status }, { internal: true });
637
703
  }
638
704
 
639
705
  // src/sync/update-element-settings.ts
640
- import { __privateRunCommandSync as runCommandSync3 } from "@elementor/editor-v1-adapters";
706
+ import { __privateRunCommandSync as runCommandSync4 } from "@elementor/editor-v1-adapters";
641
707
  var updateElementSettings = ({ id, props, withHistory = true }) => {
642
708
  const container = getContainer(id);
643
709
  const args = {
@@ -645,69 +711,94 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
645
711
  settings: { ...props }
646
712
  };
647
713
  if (withHistory) {
648
- runCommandSync3("document/elements/settings", args);
714
+ runCommandSync4("document/elements/settings", args);
649
715
  } else {
650
- runCommandSync3("document/elements/set-settings", args, { internal: true });
716
+ runCommandSync4("document/elements/set-settings", args, { internal: true });
651
717
  }
652
718
  };
653
719
 
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 } });
720
+ // src/link-restriction.ts
721
+ function getLinkInLinkRestriction(elementId) {
722
+ const anchoredDescendantId = getAnchoredDescendantId(elementId);
723
+ if (anchoredDescendantId) {
724
+ return {
725
+ shouldRestrict: true,
726
+ reason: "descendant",
727
+ elementId: anchoredDescendantId
728
+ };
675
729
  }
676
- const parent = currentElementContainer.parent;
677
- if (!parent) {
678
- throw new ElementParentNotFoundError({ context: { elementId: currentElement.id } });
730
+ const ancestor = getAnchoredAncestorId(elementId);
731
+ if (ancestor) {
732
+ return {
733
+ shouldRestrict: true,
734
+ reason: "ancestor",
735
+ elementId: ancestor
736
+ };
679
737
  }
680
- const elementIndex = currentElementContainer.view?._index ?? 0;
681
- if (elementIndex === void 0 || elementIndex === -1) {
682
- throw new ElementIndexNotFoundError({ context: { elementId: currentElement.id } });
738
+ return {
739
+ shouldRestrict: false
740
+ };
741
+ }
742
+ function getAnchoredDescendantId(elementId) {
743
+ const element = getElementDOM(elementId);
744
+ if (!element) {
745
+ return null;
683
746
  }
684
- location = { containerId: parent.id, index: elementIndex };
685
- if (parent.id === "document" && newElement.elType === "widget") {
686
- location = createWrapperForWidget(parent.id, elementIndex);
747
+ for (const childAnchorElement of Array.from(element.querySelectorAll("a"))) {
748
+ const childElementId = findElementIdOf(childAnchorElement);
749
+ if (childElementId !== elementId) {
750
+ return childElementId;
751
+ }
687
752
  }
688
- return location;
753
+ return null;
689
754
  }
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 };
755
+ function getAnchoredAncestorId(elementId) {
756
+ const element = getElementDOM(elementId);
757
+ if (!element || element.parentElement === null) {
758
+ return null;
759
+ }
760
+ const parentAnchor = element.parentElement.closest("a");
761
+ return parentAnchor ? findElementIdOf(parentAnchor) : null;
697
762
  }
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`);
763
+ function isElementAnchored(elementId) {
764
+ const element = getElementDOM(elementId);
765
+ if (!element) {
766
+ return false;
767
+ }
768
+ if (isAnchorTag(element.tagName)) {
769
+ return true;
770
+ }
771
+ return doesElementContainAnchor(element);
772
+ }
773
+ function doesElementContainAnchor(element) {
774
+ for (const child of element.children) {
775
+ if (isElementorElement(child)) {
776
+ continue;
777
+ }
778
+ if (isAnchorTag(child.tagName)) {
779
+ return true;
780
+ }
781
+ if (doesElementContainAnchor(child)) {
782
+ return true;
783
+ }
784
+ }
785
+ return false;
786
+ }
787
+ function findElementIdOf(element) {
788
+ return element.closest("[data-id]")?.dataset.id || null;
789
+ }
790
+ function getElementDOM(id) {
791
+ try {
792
+ return getContainer(id)?.view?.el || null;
793
+ } catch {
794
+ return null;
705
795
  }
706
- return runCommandSync4("preview/drop", {
707
- container,
708
- model,
709
- options
710
- });
796
+ }
797
+ function isAnchorTag(tagName) {
798
+ return tagName.toLowerCase() === "a";
799
+ }
800
+ function isElementorElement(element) {
801
+ return element.hasAttribute("data-id");
711
802
  }
712
803
 
713
804
  // src/styles/consts.ts
@@ -837,6 +928,14 @@ function shouldCreateNewLocalStyle(payload) {
837
928
  return !payload?.styleId && !payload?.provider;
838
929
  }
839
930
 
931
+ // src/styles/delete-element-style.ts
932
+ function deleteElementStyle(elementId, styleId) {
933
+ mutateElementStyles(elementId, (styles) => {
934
+ delete styles[styleId];
935
+ return styles;
936
+ });
937
+ }
938
+
840
939
  // src/styles/update-element-style.ts
841
940
  import { mergeProps } from "@elementor/editor-props";
842
941
  import { getVariantByMeta } from "@elementor/editor-styles";
@@ -858,97 +957,9 @@ function updateElementStyle(args) {
858
957
  });
859
958
  }
860
959
 
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
- }
960
+ // src/hooks/use-element-interactions.ts
961
+ import { useState } from "react";
962
+ import { __privateUseListenTo as useListenTo6, windowEvent as windowEvent3 } from "@elementor/editor-v1-adapters";
952
963
 
953
964
  // src/sync/get-element-interactions.ts
954
965
  function getElementInteractions(elementId) {
@@ -960,6 +971,23 @@ function getElementInteractions(elementId) {
960
971
  return JSON.stringify(interactions);
961
972
  }
962
973
 
974
+ // src/hooks/use-element-interactions.ts
975
+ var useElementInteractions = (elementId) => {
976
+ const [interactions, setInteractions] = useState(() => {
977
+ const initial = getElementInteractions(elementId);
978
+ return initial;
979
+ });
980
+ useListenTo6(
981
+ windowEvent3("elementor/element/update_interactions"),
982
+ () => {
983
+ const newInteractions = getElementInteractions(elementId);
984
+ setInteractions(newInteractions);
985
+ },
986
+ [elementId]
987
+ );
988
+ return interactions;
989
+ };
990
+
963
991
  // src/sync/update-element-interactions.ts
964
992
  import { __privateRunCommandSync as runCommandSync6 } from "@elementor/editor-v1-adapters";
965
993
  var updateElementInteractions = ({
@@ -981,25 +1009,6 @@ function setDocumentModifiedStatus2(status) {
981
1009
  runCommandSync6("document/save/set-is-modified", { status }, { internal: true });
982
1010
  }
983
1011
 
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
1012
  // src/mcp/index.ts
1004
1013
  import { getMCPByDomain as getMCPByDomain2 } from "@elementor/editor-mcp";
1005
1014