@elementor/editor-components 3.35.0-357 → 3.35.0-358

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.js CHANGED
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/init.ts
38
38
  var import_editor = require("@elementor/editor");
39
- var import_editor_canvas7 = require("@elementor/editor-canvas");
39
+ var import_editor_canvas8 = require("@elementor/editor-canvas");
40
40
  var import_editor_documents10 = require("@elementor/editor-documents");
41
41
  var import_editor_editing_panel5 = require("@elementor/editor-editing-panel");
42
42
  var import_editor_elements_panel = require("@elementor/editor-elements-panel");
@@ -266,25 +266,73 @@ var invalidateComponentDocumentData = (id) => {
266
266
  };
267
267
 
268
268
  // src/component-instance-transformer.ts
269
+ var componentInstanceContext = new import_editor_canvas.RenderContext("component-instance", {
270
+ overrides: {}
271
+ });
269
272
  var componentInstanceTransformer = (0, import_editor_canvas.createTransformer)(
270
- async ({ component_id: id }) => {
273
+ async ({
274
+ component_id: id,
275
+ overrides: overridesValue
276
+ }) => {
271
277
  const unpublishedComponents = selectUnpublishedComponents((0, import_store3.__getState)());
272
278
  const unpublishedComponent = unpublishedComponents.find(({ uid }) => uid === id);
279
+ const overrides = overridesValue?.reduce((acc, override) => ({ ...acc, ...override }), {});
273
280
  if (unpublishedComponent) {
274
- return structuredClone(unpublishedComponent.elements);
281
+ return {
282
+ elements: structuredClone(unpublishedComponent.elements),
283
+ overrides
284
+ };
275
285
  }
276
286
  if (typeof id !== "number") {
277
- throw new Error(`Component ID "${id}" not found.`);
287
+ throw new Error(`Component ID "${id}" not valid.`);
278
288
  }
279
289
  const data = await getComponentDocumentData(id);
280
- return data?.elements ?? [];
290
+ return {
291
+ elements: data?.elements ?? [],
292
+ overrides
293
+ };
281
294
  }
282
295
  );
283
296
 
284
297
  // src/component-overridable-transformer.ts
285
298
  var import_editor_canvas2 = require("@elementor/editor-canvas");
286
- var componentOverridableTransformer = (0, import_editor_canvas2.createTransformer)((value) => {
287
- return value.origin_value;
299
+ var componentOverridableTransformer = (0, import_editor_canvas2.createTransformer)(
300
+ (value, options) => {
301
+ const { overrides } = componentInstanceContext.get();
302
+ const overrideValue = overrides?.[value.override_key];
303
+ if (overrideValue) {
304
+ const isOverride = isOriginValueOverride(value.origin_value);
305
+ if (isOverride) {
306
+ return transformOverride(value, options, overrideValue);
307
+ }
308
+ return overrideValue;
309
+ }
310
+ return value.origin_value;
311
+ }
312
+ );
313
+ function transformOverride(value, options, overrideValue) {
314
+ const transformer = import_editor_canvas2.settingsTransformersRegistry.get("override");
315
+ if (!transformer) {
316
+ return null;
317
+ }
318
+ const transformedValue = transformer(value.origin_value.value, options);
319
+ if (!transformedValue) {
320
+ return null;
321
+ }
322
+ const [key] = Object.keys(transformedValue);
323
+ return {
324
+ [key]: overrideValue
325
+ };
326
+ }
327
+ function isOriginValueOverride(originValue) {
328
+ return originValue.$$type === "override";
329
+ }
330
+
331
+ // src/component-override-transformer.ts
332
+ var import_editor_canvas3 = require("@elementor/editor-canvas");
333
+ var componentOverrideTransformer = (0, import_editor_canvas3.createTransformer)((override) => {
334
+ const { override_key: key, override_value: overrideValue } = override;
335
+ return { [key]: overrideValue };
288
336
  });
289
337
 
290
338
  // src/components/component-panel-header/component-panel-header.tsx
@@ -484,7 +532,7 @@ var useComponents = () => {
484
532
 
485
533
  // src/components/components-tab/components-item.tsx
486
534
  var React5 = __toESM(require("react"));
487
- var import_editor_canvas4 = require("@elementor/editor-canvas");
535
+ var import_editor_canvas5 = require("@elementor/editor-canvas");
488
536
  var import_editor_elements3 = require("@elementor/editor-elements");
489
537
  var import_editor_ui = require("@elementor/editor-ui");
490
538
  var import_icons4 = require("@elementor/icons");
@@ -508,7 +556,7 @@ var archiveComponent = (componentId) => {
508
556
  var import_editor_documents6 = require("@elementor/editor-documents");
509
557
 
510
558
  // src/create-component-type.ts
511
- var import_editor_canvas3 = require("@elementor/editor-canvas");
559
+ var import_editor_canvas4 = require("@elementor/editor-canvas");
512
560
  var import_editor_documents5 = require("@elementor/editor-documents");
513
561
  var import_i18n4 = require("@wordpress/i18n");
514
562
 
@@ -575,7 +623,7 @@ function createComponentType(options) {
575
623
  };
576
624
  }
577
625
  function createComponentView(options) {
578
- return class extends (0, import_editor_canvas3.createTemplatedElementView)(options) {
626
+ return class extends (0, import_editor_canvas4.createTemplatedElementView)(options) {
579
627
  legacyWindow = window;
580
628
  eventsManagerConfig = this.legacyWindow.elementorCommon.eventsManager.config;
581
629
  isComponentCurrentlyEdited() {
@@ -583,9 +631,10 @@ function createComponentView(options) {
583
631
  return currentDocument?.id === this.getComponentId();
584
632
  }
585
633
  afterSettingsResolve(settings) {
586
- if (settings.component_instance) {
634
+ const componentInstance = settings.component_instance;
635
+ if (componentInstance) {
587
636
  this.collection = this.legacyWindow.elementor.createBackboneElementsCollection(
588
- settings.component_instance
637
+ componentInstance.elements
589
638
  );
590
639
  this.collection.models.forEach(setInactiveRecursively);
591
640
  settings.component_instance = "<template data-children-placeholder></template>";
@@ -877,7 +926,7 @@ var ComponentItem = ({ component }) => {
877
926
  };
878
927
  const handleDragEnd = () => {
879
928
  loadComponentsAssets([componentModel]);
880
- (0, import_editor_canvas4.endDragElementFromPanel)();
929
+ (0, import_editor_canvas5.endDragElementFromPanel)();
881
930
  };
882
931
  const handleArchiveClick = () => {
883
932
  popupState.close();
@@ -890,7 +939,7 @@ var ComponentItem = ({ component }) => {
890
939
  import_ui4.ListItemButton,
891
940
  {
892
941
  draggable: true,
893
- onDragStart: () => (0, import_editor_canvas4.startDragElementFromPanel)(componentModel),
942
+ onDragStart: () => (0, import_editor_canvas5.startDragElementFromPanel)(componentModel),
894
943
  onDragEnd: handleDragEnd,
895
944
  shape: "rounded",
896
945
  sx: {
@@ -1422,10 +1471,10 @@ var import_react_dom = require("react-dom");
1422
1471
  var import_i18n9 = require("@wordpress/i18n");
1423
1472
 
1424
1473
  // src/hooks/use-canvas-document.ts
1425
- var import_editor_canvas5 = require("@elementor/editor-canvas");
1474
+ var import_editor_canvas6 = require("@elementor/editor-canvas");
1426
1475
  var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
1427
1476
  function useCanvasDocument() {
1428
- return (0, import_editor_v1_adapters4.__privateUseListenTo)((0, import_editor_v1_adapters4.commandEndEvent)("editor/documents/attach-preview"), () => (0, import_editor_canvas5.getCanvasIframeDocument)());
1477
+ return (0, import_editor_v1_adapters4.__privateUseListenTo)((0, import_editor_v1_adapters4.commandEndEvent)("editor/documents/attach-preview"), () => (0, import_editor_canvas6.getCanvasIframeDocument)());
1429
1478
  }
1430
1479
 
1431
1480
  // src/hooks/use-element-rect.ts
@@ -2286,7 +2335,7 @@ function isPropAllowed(bind) {
2286
2335
  var import_editor_mcp2 = require("@elementor/editor-mcp");
2287
2336
 
2288
2337
  // src/mcp/save-as-component-tool.ts
2289
- var import_editor_canvas6 = require("@elementor/editor-canvas");
2338
+ var import_editor_canvas7 = require("@elementor/editor-canvas");
2290
2339
  var import_editor_elements7 = require("@elementor/editor-elements");
2291
2340
  var import_editor_mcp = require("@elementor/editor-mcp");
2292
2341
  var import_http_client2 = require("@elementor/http-client");
@@ -2473,17 +2522,17 @@ Use this tool when the user wants to:
2473
2522
  - Element elType is a 'widget'
2474
2523
 
2475
2524
  # **CRITICAL - REQUIRED RESOURCES (Must read before using this tool)**
2476
- 1. [${import_editor_canvas6.DOCUMENT_STRUCTURE_URI}]
2525
+ 1. [${import_editor_canvas7.DOCUMENT_STRUCTURE_URI}]
2477
2526
  **MANDATORY** - Required to understand the document structure and identify child elements for overridable properties.
2478
2527
  Use this resource to find element IDs and understand the element hierarchy.
2479
2528
 
2480
- 2. [${import_editor_canvas6.WIDGET_SCHEMA_URI}]
2529
+ 2. [${import_editor_canvas7.WIDGET_SCHEMA_URI}]
2481
2530
  **MANDATORY** - Required to understand which properties are available for each widget type.
2482
2531
  Use this to identify available propKeys in the atomic_props_schema for child elements.
2483
2532
 
2484
2533
  # Instructions - MUST FOLLOW IN ORDER
2485
2534
  ## Step 1: Identify the Target Element
2486
- 1. Read the [${import_editor_canvas6.DOCUMENT_STRUCTURE_URI}] resource to understand the document structure
2535
+ 1. Read the [${import_editor_canvas7.DOCUMENT_STRUCTURE_URI}] resource to understand the document structure
2487
2536
  2. Locate the element you want to save as a component by its element_id
2488
2537
  3. Verify the element type is a valid element type
2489
2538
  4. Ensure the element is not locked and is not already a component
@@ -2493,11 +2542,11 @@ Do this step to make child element properties customizable.
2493
2542
  Skip that step ONLY if the user explicitly requests to not make any properties customizable.
2494
2543
 
2495
2544
  1. **Identify Child Elements**
2496
- - Use the [${import_editor_canvas6.DOCUMENT_STRUCTURE_URI}] resource to find all child elements
2545
+ - Use the [${import_editor_canvas7.DOCUMENT_STRUCTURE_URI}] resource to find all child elements
2497
2546
  - Note the elementId and widgetType/elType of each child element you want to customize
2498
2547
 
2499
2548
  2. **Find Available Properties**
2500
- - Use the [${import_editor_canvas6.WIDGET_SCHEMA_URI}] resource to find the child element's widget type schema
2549
+ - Use the [${import_editor_canvas7.WIDGET_SCHEMA_URI}] resource to find the child element's widget type schema
2501
2550
  - Review the atomic_props_schema to find available propKeys (ONLY use top-level props)
2502
2551
  - Common propKeys include: "text", "url", "tag", "size", etc.
2503
2552
  - Use only the top level properties, do not use nested properties.
@@ -2515,7 +2564,7 @@ Call the tool with:
2515
2564
 
2516
2565
  # CONSTRAINTS
2517
2566
  - NEVER try to override properties of the parent element itself - ONLY child elements
2518
- - NEVER use invalid propKeys - always verify against the widget's atomic_props_schema in [${import_editor_canvas6.WIDGET_SCHEMA_URI}]
2567
+ - NEVER use invalid propKeys - always verify against the widget's atomic_props_schema in [${import_editor_canvas7.WIDGET_SCHEMA_URI}]
2519
2568
  - Property keys must exist in the child element's atomic_props_schema
2520
2569
  - Element IDs must exist within the target element's children
2521
2570
  - When tool execution fails, read the error message and adjust accordingly
@@ -2524,7 +2573,7 @@ Call the tool with:
2524
2573
  saveAsComponentPrompt.parameter(
2525
2574
  "element_id",
2526
2575
  `**MANDATORY** The unique identifier of the element to save as a component.
2527
- Use the [${import_editor_canvas6.DOCUMENT_STRUCTURE_URI}] resource to find available element IDs.`
2576
+ Use the [${import_editor_canvas7.DOCUMENT_STRUCTURE_URI}] resource to find available element IDs.`
2528
2577
  );
2529
2578
  saveAsComponentPrompt.parameter(
2530
2579
  "component_name",
@@ -2548,8 +2597,8 @@ Structure:
2548
2597
  \`\`\`
2549
2598
 
2550
2599
  To populate this correctly:
2551
- 1. Use [${import_editor_canvas6.DOCUMENT_STRUCTURE_URI}] to find child element IDs and their widgetType
2552
- 2. Use [${import_editor_canvas6.WIDGET_SCHEMA_URI}] to find the atomic_props_schema for each child element's widgetType
2600
+ 1. Use [${import_editor_canvas7.DOCUMENT_STRUCTURE_URI}] to find child element IDs and their widgetType
2601
+ 2. Use [${import_editor_canvas7.WIDGET_SCHEMA_URI}] to find the atomic_props_schema for each child element's widgetType
2553
2602
  3. Only include properties you want to be customizable in component instances
2554
2603
  4. Common propKeys: "text", "url", "tag", "size", "align", etc.`
2555
2604
  );
@@ -2814,7 +2863,7 @@ var beforeSave = ({ container, status }) => {
2814
2863
  function init() {
2815
2864
  import_editor_styles_repository2.stylesRepository.register(componentsStylesProvider);
2816
2865
  (0, import_store50.__registerSlice)(slice);
2817
- (0, import_editor_canvas7.registerElementType)(
2866
+ (0, import_editor_canvas8.registerElementType)(
2818
2867
  TYPE,
2819
2868
  (options) => createComponentType({ ...options, showLockedByModal: openEditModeDialog })
2820
2869
  );
@@ -2870,8 +2919,9 @@ function init() {
2870
2919
  condition: (_, elementType) => elementType.key === "e-component",
2871
2920
  component: InstanceEditingPanel
2872
2921
  });
2873
- import_editor_canvas7.settingsTransformersRegistry.register("component-instance", componentInstanceTransformer);
2874
- import_editor_canvas7.settingsTransformersRegistry.register("overridable", componentOverridableTransformer);
2922
+ import_editor_canvas8.settingsTransformersRegistry.register("component-instance", componentInstanceTransformer);
2923
+ import_editor_canvas8.settingsTransformersRegistry.register("overridable", componentOverridableTransformer);
2924
+ import_editor_canvas8.settingsTransformersRegistry.register("override", componentOverrideTransformer);
2875
2925
  initMcp();
2876
2926
  }
2877
2927
  // Annotate the CommonJS export names for ESM import in node: