@elementor/editor-elements 3.32.0-79 → 3.32.0-81

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
@@ -104,18 +104,31 @@ type ElementModel = {
104
104
  type ElementChildren = Record<string, ElementModel[]>;
105
105
  declare function useElementChildren<T extends ElementChildren>(elementId: ElementID, childrenTypes: (keyof T & string)[]): T;
106
106
 
107
- type Options$1 = {
107
+ type Options$2 = {
108
108
  useHistory?: boolean;
109
109
  at?: number;
110
+ clone?: boolean;
110
111
  };
111
112
  type CreateElementParams = {
112
- settings: V1ElementSettingsProps;
113
- type: string;
114
113
  containerId: string;
115
- id?: string;
114
+ options?: Options$2;
115
+ model?: Omit<V1ElementModelProps, 'settings' | 'id'> & {
116
+ settings?: V1ElementSettingsProps;
117
+ id?: string;
118
+ };
119
+ };
120
+ declare function createElement({ containerId, model, options }: CreateElementParams): V1Element;
121
+
122
+ type Options$1 = {
123
+ useHistory?: boolean;
124
+ at?: number;
125
+ clone?: boolean;
126
+ };
127
+ type DuplicateElementParams = {
128
+ elementId: string;
116
129
  options?: Options$1;
117
130
  };
118
- declare function createElement({ containerId, settings, type, id, options }: CreateElementParams): V1Element;
131
+ declare function duplicateElement({ elementId, options }: DuplicateElementParams): V1Element;
119
132
 
120
133
  type CreateNestedElementsParams = {
121
134
  elements: CreateElementParams[];
@@ -133,6 +146,26 @@ type CreatedElementsResult = {
133
146
 
134
147
  declare const createElements: ({ elements, title, subtitle, }: CreateNestedElementsParams) => CreatedElementsResult;
135
148
 
149
+ type DuplicateElementsParams = {
150
+ elementIds: string[];
151
+ title: string;
152
+ subtitle?: string;
153
+ onCreate?: (duplicatedElements: DuplicatedElement[]) => DuplicatedElement[];
154
+ };
155
+ type DuplicatedElement = {
156
+ id: string;
157
+ model: V1ElementModelProps;
158
+ originalElementId: string;
159
+ modelToRestore?: V1ElementModelProps;
160
+ parentContainerId?: string;
161
+ at?: number;
162
+ };
163
+ type DuplicatedElementsResult = {
164
+ duplicatedElements: DuplicatedElement[];
165
+ };
166
+
167
+ declare const duplicateElements: ({ elementIds, title, subtitle, onCreate, }: DuplicateElementsParams) => DuplicatedElementsResult;
168
+
136
169
  type Options = {
137
170
  useHistory?: boolean;
138
171
  at?: number;
@@ -231,4 +264,4 @@ declare function getAnchoredDescendantId(elementId: string): string | null;
231
264
  declare function getAnchoredAncestorId(elementId: string): string | null;
232
265
  declare function isElementAnchored(elementId: string): boolean;
233
266
 
234
- export { type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementID, type ElementType, type LinkInLinkRestriction, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementModelProps, type V1ElementSettingsProps, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, generateElementId, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentId, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, removeElements, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementChildren, useElementSetting, useElementSettings, useElementType, useParentElement, useSelectedElement };
267
+ export { type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementID, type ElementType, type LinkInLinkRestriction, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementModelProps, type V1ElementSettingsProps, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, duplicateElement, duplicateElements, generateElementId, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentId, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, removeElements, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementChildren, useElementSetting, useElementSettings, useElementType, useParentElement, useSelectedElement };
package/dist/index.d.ts CHANGED
@@ -104,18 +104,31 @@ type ElementModel = {
104
104
  type ElementChildren = Record<string, ElementModel[]>;
105
105
  declare function useElementChildren<T extends ElementChildren>(elementId: ElementID, childrenTypes: (keyof T & string)[]): T;
106
106
 
107
- type Options$1 = {
107
+ type Options$2 = {
108
108
  useHistory?: boolean;
109
109
  at?: number;
110
+ clone?: boolean;
110
111
  };
111
112
  type CreateElementParams = {
112
- settings: V1ElementSettingsProps;
113
- type: string;
114
113
  containerId: string;
115
- id?: string;
114
+ options?: Options$2;
115
+ model?: Omit<V1ElementModelProps, 'settings' | 'id'> & {
116
+ settings?: V1ElementSettingsProps;
117
+ id?: string;
118
+ };
119
+ };
120
+ declare function createElement({ containerId, model, options }: CreateElementParams): V1Element;
121
+
122
+ type Options$1 = {
123
+ useHistory?: boolean;
124
+ at?: number;
125
+ clone?: boolean;
126
+ };
127
+ type DuplicateElementParams = {
128
+ elementId: string;
116
129
  options?: Options$1;
117
130
  };
118
- declare function createElement({ containerId, settings, type, id, options }: CreateElementParams): V1Element;
131
+ declare function duplicateElement({ elementId, options }: DuplicateElementParams): V1Element;
119
132
 
120
133
  type CreateNestedElementsParams = {
121
134
  elements: CreateElementParams[];
@@ -133,6 +146,26 @@ type CreatedElementsResult = {
133
146
 
134
147
  declare const createElements: ({ elements, title, subtitle, }: CreateNestedElementsParams) => CreatedElementsResult;
135
148
 
149
+ type DuplicateElementsParams = {
150
+ elementIds: string[];
151
+ title: string;
152
+ subtitle?: string;
153
+ onCreate?: (duplicatedElements: DuplicatedElement[]) => DuplicatedElement[];
154
+ };
155
+ type DuplicatedElement = {
156
+ id: string;
157
+ model: V1ElementModelProps;
158
+ originalElementId: string;
159
+ modelToRestore?: V1ElementModelProps;
160
+ parentContainerId?: string;
161
+ at?: number;
162
+ };
163
+ type DuplicatedElementsResult = {
164
+ duplicatedElements: DuplicatedElement[];
165
+ };
166
+
167
+ declare const duplicateElements: ({ elementIds, title, subtitle, onCreate, }: DuplicateElementsParams) => DuplicatedElementsResult;
168
+
136
169
  type Options = {
137
170
  useHistory?: boolean;
138
171
  at?: number;
@@ -231,4 +264,4 @@ declare function getAnchoredDescendantId(elementId: string): string | null;
231
264
  declare function getAnchoredAncestorId(elementId: string): string | null;
232
265
  declare function isElementAnchored(elementId: string): boolean;
233
266
 
234
- export { type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementID, type ElementType, type LinkInLinkRestriction, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementModelProps, type V1ElementSettingsProps, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, generateElementId, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentId, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, removeElements, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementChildren, useElementSetting, useElementSettings, useElementType, useParentElement, useSelectedElement };
267
+ export { type Control, type ControlItem, type ControlLayout, type ControlsSection, type CreateElementParams, type CreateElementStyleArgs, type DuplicateElementParams, type DuplicateElementsParams, type DuplicatedElement, type DuplicatedElementsResult, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementChildren, type ElementID, type ElementType, type LinkInLinkRestriction, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementConfig, type V1ElementModelProps, type V1ElementSettingsProps, createElement, createElementStyle, createElements, deleteElement, deleteElementStyle, duplicateElement, duplicateElements, generateElementId, getAnchoredAncestorId, getAnchoredDescendantId, getContainer, getCurrentDocumentId, getElementLabel, getElementSetting, getElementSettings, getElementStyles, getElements, getLinkInLinkRestriction, getSelectedElements, getWidgetsCache, isElementAnchored, removeElements, selectElement, shouldCreateNewLocalStyle, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementChildren, useElementSetting, useElementSettings, useElementType, useParentElement, useSelectedElement };
package/dist/index.js CHANGED
@@ -26,6 +26,8 @@ __export(index_exports, {
26
26
  createElements: () => createElements,
27
27
  deleteElement: () => deleteElement,
28
28
  deleteElementStyle: () => deleteElementStyle,
29
+ duplicateElement: () => duplicateElement,
30
+ duplicateElements: () => duplicateElements,
29
31
  generateElementId: () => generateElementId,
30
32
  getAnchoredAncestorId: () => getAnchoredAncestorId,
31
33
  getAnchoredDescendantId: () => getAnchoredDescendantId,
@@ -217,9 +219,9 @@ function useElementChildren(elementId, childrenTypes) {
217
219
  return acc;
218
220
  }, {});
219
221
  container?.children?.forEachRecursive?.(({ model, id }) => {
220
- const widgetType = model.get("widgetType");
221
- if (widgetType && widgetType in elementChildren) {
222
- elementChildren[widgetType].push({ id });
222
+ const elType = model.get("elType");
223
+ if (elType && elType in elementChildren) {
224
+ elementChildren[elType].push({ id });
223
225
  }
224
226
  });
225
227
  return elementChildren;
@@ -230,9 +232,8 @@ function useElementChildren(elementId, childrenTypes) {
230
232
 
231
233
  // src/sync/create-element.ts
232
234
  var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
233
- function createElement({ containerId, settings, type, id, options }) {
235
+ function createElement({ containerId, model, options }) {
234
236
  const container = getContainer(containerId);
235
- const model = createElementModel({ settings, type, id });
236
237
  if (!container) {
237
238
  throw new Error(`Container with ID "${containerId}" not found`);
238
239
  }
@@ -242,15 +243,28 @@ function createElement({ containerId, settings, type, id, options }) {
242
243
  options: { edit: false, ...options }
243
244
  });
244
245
  }
245
- function createElementModel({ settings, type, id }) {
246
- return {
247
- id,
248
- elType: "widget",
249
- widgetType: type,
250
- settings: {
251
- ...settings
246
+
247
+ // src/sync/duplicate-element.ts
248
+ function duplicateElement({ elementId, options = {} }) {
249
+ const elementToDuplicate = getContainer(elementId);
250
+ if (!elementToDuplicate) {
251
+ throw new Error(`Element with ID "${elementId}" not found`);
252
+ }
253
+ if (!elementToDuplicate.parent) {
254
+ throw new Error(`Element with ID "${elementId}" has no parent container`);
255
+ }
256
+ const parentContainer = elementToDuplicate.parent;
257
+ const elementModel = elementToDuplicate.model.toJSON();
258
+ const currentIndex = elementToDuplicate.view?._index ?? 0;
259
+ const insertPosition = options.clone !== false ? currentIndex + 1 : void 0;
260
+ return createElement({
261
+ containerId: parentContainer.id,
262
+ model: elementModel,
263
+ options: {
264
+ at: insertPosition,
265
+ ...options
252
266
  }
253
- };
267
+ });
254
268
  }
255
269
 
256
270
  // src/sync/create-elements.ts
@@ -291,8 +305,7 @@ var createElements = ({
291
305
  elementId,
292
306
  model: element.model?.toJSON() || {},
293
307
  createParams: {
294
- ...createParams,
295
- id: elementId
308
+ ...createParams
296
309
  }
297
310
  });
298
311
  });
@@ -308,9 +321,10 @@ var createElements = ({
308
321
  },
309
322
  redo: (_, { createdElements }) => {
310
323
  const newElements = [];
311
- createdElements.forEach(({ createParams }) => {
324
+ createdElements.forEach(({ createParams, model }) => {
312
325
  const element = createElement({
313
- ...createParams,
326
+ containerId: createParams.containerId,
327
+ model,
314
328
  options: { ...createParams.options, useHistory: false }
315
329
  });
316
330
  const elementId = element.id;
@@ -334,15 +348,89 @@ var createElements = ({
334
348
  return undoableCreate({ elements });
335
349
  };
336
350
 
337
- // src/sync/remove-elements.ts
351
+ // src/sync/duplicate-elements.ts
338
352
  var import_editor_v1_adapters10 = require("@elementor/editor-v1-adapters");
339
353
  var import_i18n2 = require("@wordpress/i18n");
354
+ var duplicateElements = ({
355
+ elementIds,
356
+ title,
357
+ subtitle = (0, import_i18n2.__)("Item duplicated", "elementor"),
358
+ onCreate
359
+ }) => {
360
+ const undoableDuplicate = (0, import_editor_v1_adapters10.undoable)(
361
+ {
362
+ do: ({ elementIds: elementIdsToDuplicate }) => {
363
+ const duplicatedElements = elementIdsToDuplicate.reduce((acc, elementId) => {
364
+ const originalContainer = getContainer(elementId);
365
+ if (originalContainer?.parent) {
366
+ const duplicatedElement = duplicateElement({
367
+ elementId,
368
+ options: { useHistory: false, clone: true }
369
+ });
370
+ acc.push({
371
+ id: duplicatedElement.id,
372
+ model: duplicatedElement.model.toJSON(),
373
+ originalElementId: elementId,
374
+ modelToRestore: duplicatedElement.model.toJSON(),
375
+ parentContainerId: duplicatedElement.parent?.id,
376
+ at: duplicatedElement.view?._index
377
+ });
378
+ }
379
+ return acc;
380
+ }, []);
381
+ return { duplicatedElements: onCreate?.(duplicatedElements) ?? duplicatedElements };
382
+ },
383
+ undo: (_, { duplicatedElements }) => {
384
+ [...duplicatedElements].reverse().forEach(({ id }) => {
385
+ deleteElement({
386
+ elementId: id,
387
+ options: { useHistory: false }
388
+ });
389
+ });
390
+ },
391
+ redo: (_, { duplicatedElements: previousElements }) => {
392
+ const duplicatedElements = previousElements.reduce((acc, previousElement) => {
393
+ if (previousElement.modelToRestore && previousElement.parentContainerId) {
394
+ const createdElement = createElement({
395
+ containerId: previousElement.parentContainerId,
396
+ model: previousElement.modelToRestore,
397
+ options: {
398
+ useHistory: false,
399
+ clone: false,
400
+ at: previousElement.at
401
+ }
402
+ });
403
+ acc.push({
404
+ id: createdElement.id,
405
+ model: createdElement.model.toJSON(),
406
+ originalElementId: previousElement.originalElementId,
407
+ modelToRestore: previousElement.modelToRestore,
408
+ parentContainerId: previousElement.parentContainerId,
409
+ at: previousElement.at
410
+ });
411
+ }
412
+ return acc;
413
+ }, []);
414
+ return { duplicatedElements: onCreate?.(duplicatedElements) ?? duplicatedElements };
415
+ }
416
+ },
417
+ {
418
+ title,
419
+ subtitle
420
+ }
421
+ );
422
+ return undoableDuplicate({ elementIds });
423
+ };
424
+
425
+ // src/sync/remove-elements.ts
426
+ var import_editor_v1_adapters11 = require("@elementor/editor-v1-adapters");
427
+ var import_i18n3 = require("@wordpress/i18n");
340
428
  var removeElements = ({
341
429
  elementIds,
342
430
  title,
343
- subtitle = (0, import_i18n2.__)("Item removed", "elementor")
431
+ subtitle = (0, import_i18n3.__)("Item removed", "elementor")
344
432
  }) => {
345
- const undoableRemove = (0, import_editor_v1_adapters10.undoable)(
433
+ const undoableRemove = (0, import_editor_v1_adapters11.undoable)(
346
434
  {
347
435
  do: ({ elementIds: elementIdsParam }) => {
348
436
  const removedElements = [];
@@ -373,9 +461,7 @@ var removeElements = ({
373
461
  if (parent && model) {
374
462
  createElement({
375
463
  containerId: parent.id,
376
- settings: model.settings || {},
377
- type: model.widgetType || model.elType,
378
- id: model.id,
464
+ model,
379
465
  options: { useHistory: false, at }
380
466
  });
381
467
  }
@@ -463,7 +549,7 @@ function getCurrentDocumentId() {
463
549
  }
464
550
 
465
551
  // src/sync/update-element-settings.ts
466
- var import_editor_v1_adapters11 = require("@elementor/editor-v1-adapters");
552
+ var import_editor_v1_adapters12 = require("@elementor/editor-v1-adapters");
467
553
  var updateElementSettings = ({ id, props, withHistory = true }) => {
468
554
  const container = getContainer(id);
469
555
  const args = {
@@ -471,9 +557,9 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
471
557
  settings: { ...props }
472
558
  };
473
559
  if (withHistory) {
474
- (0, import_editor_v1_adapters11.__privateRunCommandSync)("document/elements/settings", args);
560
+ (0, import_editor_v1_adapters12.__privateRunCommandSync)("document/elements/settings", args);
475
561
  } else {
476
- (0, import_editor_v1_adapters11.__privateRunCommandSync)("document/elements/set-settings", args, { internal: true });
562
+ (0, import_editor_v1_adapters12.__privateRunCommandSync)("document/elements/set-settings", args, { internal: true });
477
563
  }
478
564
  };
479
565
 
@@ -484,14 +570,14 @@ var generateElementId = () => {
484
570
  };
485
571
 
486
572
  // src/styles/consts.ts
487
- var import_editor_v1_adapters12 = require("@elementor/editor-v1-adapters");
573
+ var import_editor_v1_adapters13 = require("@elementor/editor-v1-adapters");
488
574
  var ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style";
489
575
  var styleRerenderEvents = [
490
- (0, import_editor_v1_adapters12.commandEndEvent)("document/elements/create"),
491
- (0, import_editor_v1_adapters12.commandEndEvent)("document/elements/duplicate"),
492
- (0, import_editor_v1_adapters12.commandEndEvent)("document/elements/import"),
493
- (0, import_editor_v1_adapters12.commandEndEvent)("document/elements/paste"),
494
- (0, import_editor_v1_adapters12.windowEvent)(ELEMENT_STYLE_CHANGE_EVENT)
576
+ (0, import_editor_v1_adapters13.commandEndEvent)("document/elements/create"),
577
+ (0, import_editor_v1_adapters13.commandEndEvent)("document/elements/duplicate"),
578
+ (0, import_editor_v1_adapters13.commandEndEvent)("document/elements/import"),
579
+ (0, import_editor_v1_adapters13.commandEndEvent)("document/elements/paste"),
580
+ (0, import_editor_v1_adapters13.windowEvent)(ELEMENT_STYLE_CHANGE_EVENT)
495
581
  ];
496
582
 
497
583
  // src/styles/create-element-style.ts
@@ -500,7 +586,7 @@ var import_editor_styles = require("@elementor/editor-styles");
500
586
 
501
587
  // src/styles/mutate-element-styles.ts
502
588
  var import_editor_props = require("@elementor/editor-props");
503
- var import_editor_v1_adapters13 = require("@elementor/editor-v1-adapters");
589
+ var import_editor_v1_adapters14 = require("@elementor/editor-v1-adapters");
504
590
  function mutateElementStyles(elementId, mutator) {
505
591
  const container = getContainer(elementId);
506
592
  if (!container) {
@@ -556,7 +642,7 @@ function getClassesProps(container) {
556
642
  }
557
643
  function notifyChanges() {
558
644
  dispatchChangeEvent();
559
- (0, import_editor_v1_adapters13.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
645
+ (0, import_editor_v1_adapters14.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
560
646
  }
561
647
  function dispatchChangeEvent() {
562
648
  window.dispatchEvent(new CustomEvent(ELEMENT_STYLE_CHANGE_EVENT));
@@ -728,6 +814,8 @@ function isElementorElement(element) {
728
814
  createElements,
729
815
  deleteElement,
730
816
  deleteElementStyle,
817
+ duplicateElement,
818
+ duplicateElements,
731
819
  generateElementId,
732
820
  getAnchoredAncestorId,
733
821
  getAnchoredDescendantId,