@elementor/editor-canvas 4.3.0-987 → 4.3.0-989
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 +113 -117
- package/dist/index.mjs +94 -98
- package/package.json +20 -20
- package/src/mcp/resources/__tests__/dynamic-tags-resource.test.ts +27 -37
- package/src/mcp/resources/dynamic-tags-resource.ts +28 -29
package/dist/index.js
CHANGED
|
@@ -4176,7 +4176,7 @@ function initTabsModelExtensions() {
|
|
|
4176
4176
|
}
|
|
4177
4177
|
|
|
4178
4178
|
// src/mcp/canvas-mcp.ts
|
|
4179
|
-
var
|
|
4179
|
+
var import_editor_props10 = require("@elementor/editor-props");
|
|
4180
4180
|
|
|
4181
4181
|
// src/mcp/resources/available-widgets-resource.ts
|
|
4182
4182
|
var import_editor_v1_adapters15 = require("@elementor/editor-v1-adapters");
|
|
@@ -4358,84 +4358,15 @@ function extractElementData(element) {
|
|
|
4358
4358
|
}
|
|
4359
4359
|
|
|
4360
4360
|
// src/mcp/resources/dynamic-tags-resource.ts
|
|
4361
|
-
var
|
|
4362
|
-
|
|
4363
|
-
// src/mcp/utils/resolve-dynamic-tag.ts
|
|
4364
|
-
var import_editor_v1_adapters17 = require("@elementor/editor-v1-adapters");
|
|
4365
|
-
var DYNAMIC_PROP_TYPE_KEY = "dynamic";
|
|
4366
|
-
var OMITTED_DYNAMIC_SETTING_KEYS = ["fallback"];
|
|
4367
|
-
var getAtomicDynamicTags = () => {
|
|
4368
|
-
const config = (0, import_editor_v1_adapters17.getElementorConfig)();
|
|
4369
|
-
return config.atomicDynamicTags?.tags ?? {};
|
|
4370
|
-
};
|
|
4371
|
-
var getDynamicTagNamesByCategories = (categories) => {
|
|
4372
|
-
if (!categories.length) {
|
|
4373
|
-
return [];
|
|
4374
|
-
}
|
|
4375
|
-
const wanted = new Set(categories);
|
|
4376
|
-
return Object.values(getAtomicDynamicTags()).filter((tag) => tag.categories?.some((category) => wanted.has(category))).map((tag) => tag.name);
|
|
4377
|
-
};
|
|
4378
|
-
var dynamicTagLLMResolver = (value) => {
|
|
4379
|
-
const input = value ?? {};
|
|
4380
|
-
const tag = input.name ? getAtomicDynamicTags()[input.name] : void 0;
|
|
4381
|
-
if (!tag) {
|
|
4382
|
-
return {
|
|
4383
|
-
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4384
|
-
value: { name: input.name ?? "", group: "", settings: {} }
|
|
4385
|
-
};
|
|
4386
|
-
}
|
|
4387
|
-
return {
|
|
4388
|
-
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4389
|
-
value: {
|
|
4390
|
-
name: tag.name,
|
|
4391
|
-
group: tag.group,
|
|
4392
|
-
settings: buildStrictSettings(tag.props_schema ?? {}, input.settings ?? {})
|
|
4393
|
-
}
|
|
4394
|
-
};
|
|
4395
|
-
};
|
|
4396
|
-
var buildStrictSettings = (schema2, provided) => {
|
|
4397
|
-
const settings = {};
|
|
4398
|
-
for (const [key, propType] of Object.entries(schema2)) {
|
|
4399
|
-
if (OMITTED_DYNAMIC_SETTING_KEYS.includes(key)) {
|
|
4400
|
-
continue;
|
|
4401
|
-
}
|
|
4402
|
-
const resolved = provided[key] !== void 0 ? wrapSettingValue(provided[key], propType) : defaultSettingValue(propType);
|
|
4403
|
-
if (resolved !== void 0 && resolved !== null) {
|
|
4404
|
-
settings[key] = resolved;
|
|
4405
|
-
}
|
|
4406
|
-
}
|
|
4407
|
-
return settings;
|
|
4408
|
-
};
|
|
4409
|
-
var wrapSettingValue = (raw, propType) => {
|
|
4410
|
-
if (raw !== null && typeof raw === "object") {
|
|
4411
|
-
return raw;
|
|
4412
|
-
}
|
|
4413
|
-
return propType.key ? { $$type: propType.key, value: raw } : raw;
|
|
4414
|
-
};
|
|
4415
|
-
var defaultSettingValue = (propType) => {
|
|
4416
|
-
if (propType.initial_value !== null && propType.initial_value !== void 0) {
|
|
4417
|
-
return propType.initial_value;
|
|
4418
|
-
}
|
|
4419
|
-
if (propType.default !== null && propType.default !== void 0) {
|
|
4420
|
-
return wrapSettingValue(propType.default, propType);
|
|
4421
|
-
}
|
|
4422
|
-
return void 0;
|
|
4423
|
-
};
|
|
4424
|
-
|
|
4425
|
-
// src/mcp/resources/dynamic-tags-resource.ts
|
|
4361
|
+
var import_http_client3 = require("@elementor/http-client");
|
|
4426
4362
|
var DYNAMIC_TAGS_URI = "elementor://dynamic-tags";
|
|
4427
|
-
var
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
}
|
|
4432
|
-
|
|
4433
|
-
return
|
|
4434
|
-
name: tag.name,
|
|
4435
|
-
label: tag.label,
|
|
4436
|
-
categories: tag.categories,
|
|
4437
|
-
settings: settingsSchema(tag.props_schema)
|
|
4438
|
-
}));
|
|
4363
|
+
var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
|
|
4364
|
+
var fetchDynamicTags = async () => {
|
|
4365
|
+
const { data } = await (0, import_http_client3.httpService)().post(MCP_PROXY_URL2, {
|
|
4366
|
+
tool: "list-dynamic-tags",
|
|
4367
|
+
input: {}
|
|
4368
|
+
});
|
|
4369
|
+
return data.data ?? [];
|
|
4439
4370
|
};
|
|
4440
4371
|
var initDynamicTagsResource = (reg) => {
|
|
4441
4372
|
const { resource } = reg;
|
|
@@ -4446,20 +4377,23 @@ var initDynamicTagsResource = (reg) => {
|
|
|
4446
4377
|
description: `List of available dynamic tags. To bind a property to a dynamic source, set its value to { "$$type": "dynamic", "value": { "name": <tag name>, "settings": { ... } } } using a tag whose name appears in that property's allowed list, and populate "settings" per the tag entry here.`,
|
|
4447
4378
|
mimeType: "application/json"
|
|
4448
4379
|
},
|
|
4449
|
-
async (uri) =>
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4380
|
+
async (uri) => {
|
|
4381
|
+
const tags = await fetchDynamicTags();
|
|
4382
|
+
return {
|
|
4383
|
+
contents: [
|
|
4384
|
+
{
|
|
4385
|
+
uri: uri.href,
|
|
4386
|
+
mimeType: "application/json",
|
|
4387
|
+
text: JSON.stringify(tags)
|
|
4388
|
+
}
|
|
4389
|
+
]
|
|
4390
|
+
};
|
|
4391
|
+
}
|
|
4458
4392
|
);
|
|
4459
4393
|
};
|
|
4460
4394
|
|
|
4461
4395
|
// src/mcp/resources/editor-state-resource.ts
|
|
4462
|
-
var
|
|
4396
|
+
var import_editor_v1_adapters17 = require("@elementor/editor-v1-adapters");
|
|
4463
4397
|
var CURRENTLY_VIEWED_SCREEN = "The user is currently viewing the Elementor editor";
|
|
4464
4398
|
var PAGE_CONTENT_CHARACTER_LIMIT = 500;
|
|
4465
4399
|
var PREVIEW_TEXT_NODE_MIN_LENGTH = 2;
|
|
@@ -4480,8 +4414,8 @@ var initEditorStateResource = (reg) => {
|
|
|
4480
4414
|
lastSerializedState = serialized;
|
|
4481
4415
|
sendResourceUpdated({ uri: EDITOR_STATE_URI });
|
|
4482
4416
|
};
|
|
4483
|
-
(0,
|
|
4484
|
-
[(0,
|
|
4417
|
+
(0, import_editor_v1_adapters17.__privateListenTo)(
|
|
4418
|
+
[(0, import_editor_v1_adapters17.commandEndEvent)("editor/documents/switch"), (0, import_editor_v1_adapters17.commandEndEvent)("editor/documents/attach-preview")],
|
|
4485
4419
|
notifyIfChanged
|
|
4486
4420
|
);
|
|
4487
4421
|
lastSerializedState = JSON.stringify(buildState());
|
|
@@ -4555,7 +4489,7 @@ function getPageTitle() {
|
|
|
4555
4489
|
}
|
|
4556
4490
|
|
|
4557
4491
|
// src/mcp/resources/general-context-resource.ts
|
|
4558
|
-
var
|
|
4492
|
+
var import_editor_v1_adapters18 = require("@elementor/editor-v1-adapters");
|
|
4559
4493
|
var GENERAL_CONTEXT_URI = "elementor://context/general";
|
|
4560
4494
|
var initGeneralContextResource = (reg) => {
|
|
4561
4495
|
const { resource, sendResourceUpdated } = reg;
|
|
@@ -4616,11 +4550,11 @@ var initGeneralContextResource = (reg) => {
|
|
|
4616
4550
|
};
|
|
4617
4551
|
}
|
|
4618
4552
|
);
|
|
4619
|
-
(0,
|
|
4553
|
+
(0, import_editor_v1_adapters18.__privateListenTo)(
|
|
4620
4554
|
[
|
|
4621
|
-
(0,
|
|
4622
|
-
(0,
|
|
4623
|
-
(0,
|
|
4555
|
+
(0, import_editor_v1_adapters18.commandEndEvent)("editor/documents/switch"),
|
|
4556
|
+
(0, import_editor_v1_adapters18.commandEndEvent)("editor/documents/attach-preview"),
|
|
4557
|
+
(0, import_editor_v1_adapters18.commandEndEvent)("document/elements/settings")
|
|
4624
4558
|
],
|
|
4625
4559
|
pushUpdateIfChanged
|
|
4626
4560
|
);
|
|
@@ -4629,7 +4563,7 @@ var initGeneralContextResource = (reg) => {
|
|
|
4629
4563
|
|
|
4630
4564
|
// src/mcp/resources/selected-element-resource.ts
|
|
4631
4565
|
var import_editor_elements12 = require("@elementor/editor-elements");
|
|
4632
|
-
var
|
|
4566
|
+
var import_editor_v1_adapters19 = require("@elementor/editor-v1-adapters");
|
|
4633
4567
|
var SELECTED_ELEMENT_URI = "elementor://context/selected-element";
|
|
4634
4568
|
var initSelectedElementResource = (reg) => {
|
|
4635
4569
|
const { resource, sendResourceUpdated } = reg;
|
|
@@ -4660,11 +4594,11 @@ var initSelectedElementResource = (reg) => {
|
|
|
4660
4594
|
}
|
|
4661
4595
|
publishIfChanged(readSelectionFromEditor());
|
|
4662
4596
|
};
|
|
4663
|
-
(0,
|
|
4597
|
+
(0, import_editor_v1_adapters19.__privateListenTo)(
|
|
4664
4598
|
[
|
|
4665
|
-
(0,
|
|
4666
|
-
(0,
|
|
4667
|
-
(0,
|
|
4599
|
+
(0, import_editor_v1_adapters19.commandEndEvent)("document/elements/select"),
|
|
4600
|
+
(0, import_editor_v1_adapters19.commandEndEvent)("document/elements/deselect-all"),
|
|
4601
|
+
(0, import_editor_v1_adapters19.commandEndEvent)("document/elements/settings")
|
|
4668
4602
|
],
|
|
4669
4603
|
onCommand
|
|
4670
4604
|
);
|
|
@@ -4783,7 +4717,7 @@ var import_editor_elements15 = require("@elementor/editor-elements");
|
|
|
4783
4717
|
|
|
4784
4718
|
// src/mcp/utils/do-update-element-property.ts
|
|
4785
4719
|
var import_editor_elements14 = require("@elementor/editor-elements");
|
|
4786
|
-
var
|
|
4720
|
+
var import_editor_props7 = require("@elementor/editor-props");
|
|
4787
4721
|
var import_editor_styles4 = require("@elementor/editor-styles");
|
|
4788
4722
|
var import_editor_v1_adapters21 = require("@elementor/editor-v1-adapters");
|
|
4789
4723
|
|
|
@@ -4853,6 +4787,68 @@ function resolveCanonicalPropKeys(elementType, props) {
|
|
|
4853
4787
|
return resolved;
|
|
4854
4788
|
}
|
|
4855
4789
|
|
|
4790
|
+
// src/mcp/utils/resolve-dynamic-tag.ts
|
|
4791
|
+
var import_editor_v1_adapters20 = require("@elementor/editor-v1-adapters");
|
|
4792
|
+
var DYNAMIC_PROP_TYPE_KEY = "dynamic";
|
|
4793
|
+
var OMITTED_DYNAMIC_SETTING_KEYS = ["fallback"];
|
|
4794
|
+
var getAtomicDynamicTags = () => {
|
|
4795
|
+
const config = (0, import_editor_v1_adapters20.getElementorConfig)();
|
|
4796
|
+
return config.atomicDynamicTags?.tags ?? {};
|
|
4797
|
+
};
|
|
4798
|
+
var getDynamicTagNamesByCategories = (categories) => {
|
|
4799
|
+
if (!categories.length) {
|
|
4800
|
+
return [];
|
|
4801
|
+
}
|
|
4802
|
+
const wanted = new Set(categories);
|
|
4803
|
+
return Object.values(getAtomicDynamicTags()).filter((tag) => tag.categories?.some((category) => wanted.has(category))).map((tag) => tag.name);
|
|
4804
|
+
};
|
|
4805
|
+
var dynamicTagLLMResolver = (value) => {
|
|
4806
|
+
const input = value ?? {};
|
|
4807
|
+
const tag = input.name ? getAtomicDynamicTags()[input.name] : void 0;
|
|
4808
|
+
if (!tag) {
|
|
4809
|
+
return {
|
|
4810
|
+
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4811
|
+
value: { name: input.name ?? "", group: "", settings: {} }
|
|
4812
|
+
};
|
|
4813
|
+
}
|
|
4814
|
+
return {
|
|
4815
|
+
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4816
|
+
value: {
|
|
4817
|
+
name: tag.name,
|
|
4818
|
+
group: tag.group,
|
|
4819
|
+
settings: buildStrictSettings(tag.props_schema ?? {}, input.settings ?? {})
|
|
4820
|
+
}
|
|
4821
|
+
};
|
|
4822
|
+
};
|
|
4823
|
+
var buildStrictSettings = (schema2, provided) => {
|
|
4824
|
+
const settings = {};
|
|
4825
|
+
for (const [key, propType] of Object.entries(schema2)) {
|
|
4826
|
+
if (OMITTED_DYNAMIC_SETTING_KEYS.includes(key)) {
|
|
4827
|
+
continue;
|
|
4828
|
+
}
|
|
4829
|
+
const resolved = provided[key] !== void 0 ? wrapSettingValue(provided[key], propType) : defaultSettingValue(propType);
|
|
4830
|
+
if (resolved !== void 0 && resolved !== null) {
|
|
4831
|
+
settings[key] = resolved;
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
return settings;
|
|
4835
|
+
};
|
|
4836
|
+
var wrapSettingValue = (raw, propType) => {
|
|
4837
|
+
if (raw !== null && typeof raw === "object") {
|
|
4838
|
+
return raw;
|
|
4839
|
+
}
|
|
4840
|
+
return propType.key ? { $$type: propType.key, value: raw } : raw;
|
|
4841
|
+
};
|
|
4842
|
+
var defaultSettingValue = (propType) => {
|
|
4843
|
+
if (propType.initial_value !== null && propType.initial_value !== void 0) {
|
|
4844
|
+
return propType.initial_value;
|
|
4845
|
+
}
|
|
4846
|
+
if (propType.default !== null && propType.default !== void 0) {
|
|
4847
|
+
return wrapSettingValue(propType.default, propType);
|
|
4848
|
+
}
|
|
4849
|
+
return void 0;
|
|
4850
|
+
};
|
|
4851
|
+
|
|
4856
4852
|
// src/mcp/utils/do-update-element-property.ts
|
|
4857
4853
|
var LOCAL_STYLE_META = {
|
|
4858
4854
|
breakpoint: "desktop",
|
|
@@ -4860,7 +4856,7 @@ var LOCAL_STYLE_META = {
|
|
|
4860
4856
|
};
|
|
4861
4857
|
function resolvePropValue(value, forceKey) {
|
|
4862
4858
|
const Utils = window.elementorV2.editorVariables.Utils;
|
|
4863
|
-
return
|
|
4859
|
+
return import_editor_props7.Schema.adjustLlmPropValueSchema(value, {
|
|
4864
4860
|
forceKey,
|
|
4865
4861
|
transformers: {
|
|
4866
4862
|
...Utils.globalVariablesLLMResolvers,
|
|
@@ -4919,7 +4915,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
4919
4915
|
}
|
|
4920
4916
|
if (propertyRawSchema.kind === "plain") {
|
|
4921
4917
|
if (typeof propertyMapValue[stylePropName] !== "object") {
|
|
4922
|
-
const propUtil = (0,
|
|
4918
|
+
const propUtil = (0, import_editor_props7.getPropSchemaFromCache)(propertyRawSchema.key);
|
|
4923
4919
|
if (propUtil) {
|
|
4924
4920
|
const plainValue = propUtil.create(propertyMapValue[stylePropName]);
|
|
4925
4921
|
propertyMapValue[stylePropName] = plainValue;
|
|
@@ -4972,7 +4968,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
4972
4968
|
}
|
|
4973
4969
|
const propKey = elementPropSchema[propertyName].key;
|
|
4974
4970
|
const value = resolvePropValue(propertyValue, propKey);
|
|
4975
|
-
const { valid, jsonSchema } =
|
|
4971
|
+
const { valid, jsonSchema } = import_editor_props7.Schema.validatePropValue(elementPropSchema[propertyName], propertyValue);
|
|
4976
4972
|
if (!valid) {
|
|
4977
4973
|
throw new Error(
|
|
4978
4974
|
`Invalid PropValue for elementId: ${elementId}. PropKey: ${propKey}, PropValue: ${JSON.stringify(
|
|
@@ -5730,7 +5726,7 @@ function onElementAdded(element) {
|
|
|
5730
5726
|
// src/mcp/tools/configure-element/tool.ts
|
|
5731
5727
|
var import_editor_elements17 = require("@elementor/editor-elements");
|
|
5732
5728
|
var import_editor_mcp5 = require("@elementor/editor-mcp");
|
|
5733
|
-
var
|
|
5729
|
+
var import_editor_props8 = require("@elementor/editor-props");
|
|
5734
5730
|
|
|
5735
5731
|
// src/mcp/tools/configure-element/prompt.ts
|
|
5736
5732
|
var import_editor_mcp4 = require("@elementor/editor-mcp");
|
|
@@ -5919,7 +5915,7 @@ var initConfigureElementTool = (reg) => {
|
|
|
5919
5915
|
const propertiesToUpdate = resolveCanonicalPropKeys(elementType, propertiesToChange);
|
|
5920
5916
|
const toUpdate = Object.entries(propertiesToUpdate);
|
|
5921
5917
|
for (const [propertyName, propertyValue] of toUpdate) {
|
|
5922
|
-
if (!
|
|
5918
|
+
if (!import_editor_props8.Schema.isPropKeyConfigurable(propertyName)) {
|
|
5923
5919
|
throw new Error(`Not allowed to update ${propertyName}`);
|
|
5924
5920
|
}
|
|
5925
5921
|
try {
|
|
@@ -5996,9 +5992,9 @@ Provide styling as raw CSS via the "style" parameter (a flat map of CSS property
|
|
|
5996
5992
|
|
|
5997
5993
|
// src/mcp/tools/create-element/tool.ts
|
|
5998
5994
|
var import_editor_documents4 = require("@elementor/editor-documents");
|
|
5999
|
-
var
|
|
5995
|
+
var import_http_client4 = require("@elementor/http-client");
|
|
6000
5996
|
var import_schema5 = require("@elementor/schema");
|
|
6001
|
-
var
|
|
5997
|
+
var MCP_PROXY_URL3 = "elementor/v1/mcp-proxy";
|
|
6002
5998
|
var initCreateElementTool = (reg) => {
|
|
6003
5999
|
const { addTool } = reg;
|
|
6004
6000
|
addTool({
|
|
@@ -6018,7 +6014,7 @@ var initCreateElementTool = (reg) => {
|
|
|
6018
6014
|
if (!document2?.id) {
|
|
6019
6015
|
throw new Error("No active document found.");
|
|
6020
6016
|
}
|
|
6021
|
-
const { data } = await (0,
|
|
6017
|
+
const { data } = await (0, import_http_client4.httpService)().post(MCP_PROXY_URL3, {
|
|
6022
6018
|
tool: "create-element",
|
|
6023
6019
|
input: {
|
|
6024
6020
|
parent_id: parentId ?? "document",
|
|
@@ -6037,7 +6033,7 @@ var initCreateElementTool = (reg) => {
|
|
|
6037
6033
|
|
|
6038
6034
|
// src/mcp/tools/get-element-config/tool.ts
|
|
6039
6035
|
var import_editor_elements18 = require("@elementor/editor-elements");
|
|
6040
|
-
var
|
|
6036
|
+
var import_editor_props9 = require("@elementor/editor-props");
|
|
6041
6037
|
var import_schema6 = require("@elementor/schema");
|
|
6042
6038
|
var schema = {
|
|
6043
6039
|
elementId: import_schema6.z.string()
|
|
@@ -6094,7 +6090,7 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6094
6090
|
}
|
|
6095
6091
|
const propValues = {};
|
|
6096
6092
|
const stylePropValues = {};
|
|
6097
|
-
|
|
6093
|
+
import_editor_props9.Schema.configurableKeys(propSchema).forEach((key) => {
|
|
6098
6094
|
propValues[key] = structuredClone(elementRawSettings.get(key));
|
|
6099
6095
|
});
|
|
6100
6096
|
const elementStyles = (0, import_editor_elements18.getElementStyles)(elementId) || {};
|
|
@@ -6130,7 +6126,7 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6130
6126
|
|
|
6131
6127
|
// src/mcp/canvas-mcp.ts
|
|
6132
6128
|
var initCanvasMcp = (reg) => {
|
|
6133
|
-
|
|
6129
|
+
import_editor_props10.Schema.setDynamicTagNamesResolver(getDynamicTagNamesByCategories);
|
|
6134
6130
|
initWidgetsSchemaResource(reg);
|
|
6135
6131
|
initAvailableWidgetsResource(reg);
|
|
6136
6132
|
initDocumentStructureResource(reg);
|
|
@@ -6339,12 +6335,12 @@ function shouldBlock(sourceElements, targetElements) {
|
|
|
6339
6335
|
|
|
6340
6336
|
// src/style-commands/paste-style.ts
|
|
6341
6337
|
var import_editor_elements22 = require("@elementor/editor-elements");
|
|
6342
|
-
var
|
|
6338
|
+
var import_editor_props12 = require("@elementor/editor-props");
|
|
6343
6339
|
var import_editor_v1_adapters24 = require("@elementor/editor-v1-adapters");
|
|
6344
6340
|
|
|
6345
6341
|
// src/utils/command-utils.ts
|
|
6346
6342
|
var import_editor_elements20 = require("@elementor/editor-elements");
|
|
6347
|
-
var
|
|
6343
|
+
var import_editor_props11 = require("@elementor/editor-props");
|
|
6348
6344
|
var import_i18n5 = require("@wordpress/i18n");
|
|
6349
6345
|
function hasAtomicWidgets(args) {
|
|
6350
6346
|
const { containers = [args.container] } = args;
|
|
@@ -6362,7 +6358,7 @@ function getClassesProp(container) {
|
|
|
6362
6358
|
return null;
|
|
6363
6359
|
}
|
|
6364
6360
|
const [propKey] = Object.entries(propsSchema).find(
|
|
6365
|
-
([, propType]) => propType.kind === "plain" && propType.key ===
|
|
6361
|
+
([, propType]) => propType.kind === "plain" && propType.key === import_editor_props11.CLASSES_PROP_KEY
|
|
6366
6362
|
) ?? [];
|
|
6367
6363
|
return propKey ?? null;
|
|
6368
6364
|
}
|
|
@@ -6511,8 +6507,8 @@ function pasteClasses(containers, classes) {
|
|
|
6511
6507
|
return;
|
|
6512
6508
|
}
|
|
6513
6509
|
const classesSetting = (0, import_editor_elements22.getElementSetting)(container.id, classesProp);
|
|
6514
|
-
const currentClasses =
|
|
6515
|
-
const newClasses =
|
|
6510
|
+
const currentClasses = import_editor_props12.classesPropTypeUtil.extract(classesSetting) ?? [];
|
|
6511
|
+
const newClasses = import_editor_props12.classesPropTypeUtil.create(Array.from(/* @__PURE__ */ new Set([...classes, ...currentClasses])));
|
|
6516
6512
|
(0, import_editor_elements22.updateElementSettings)({
|
|
6517
6513
|
id: container.id,
|
|
6518
6514
|
props: { [classesProp]: newClasses }
|
package/dist/index.mjs
CHANGED
|
@@ -4139,7 +4139,7 @@ function initTabsModelExtensions() {
|
|
|
4139
4139
|
}
|
|
4140
4140
|
|
|
4141
4141
|
// src/mcp/canvas-mcp.ts
|
|
4142
|
-
import { Schema as
|
|
4142
|
+
import { Schema as Schema5 } from "@elementor/editor-props";
|
|
4143
4143
|
|
|
4144
4144
|
// src/mcp/resources/available-widgets-resource.ts
|
|
4145
4145
|
import { v1ReadyEvent as v1ReadyEvent3 } from "@elementor/editor-v1-adapters";
|
|
@@ -4323,84 +4323,15 @@ function extractElementData(element) {
|
|
|
4323
4323
|
}
|
|
4324
4324
|
|
|
4325
4325
|
// src/mcp/resources/dynamic-tags-resource.ts
|
|
4326
|
-
import {
|
|
4327
|
-
|
|
4328
|
-
// src/mcp/utils/resolve-dynamic-tag.ts
|
|
4329
|
-
import { getElementorConfig } from "@elementor/editor-v1-adapters";
|
|
4330
|
-
var DYNAMIC_PROP_TYPE_KEY = "dynamic";
|
|
4331
|
-
var OMITTED_DYNAMIC_SETTING_KEYS = ["fallback"];
|
|
4332
|
-
var getAtomicDynamicTags = () => {
|
|
4333
|
-
const config = getElementorConfig();
|
|
4334
|
-
return config.atomicDynamicTags?.tags ?? {};
|
|
4335
|
-
};
|
|
4336
|
-
var getDynamicTagNamesByCategories = (categories) => {
|
|
4337
|
-
if (!categories.length) {
|
|
4338
|
-
return [];
|
|
4339
|
-
}
|
|
4340
|
-
const wanted = new Set(categories);
|
|
4341
|
-
return Object.values(getAtomicDynamicTags()).filter((tag) => tag.categories?.some((category) => wanted.has(category))).map((tag) => tag.name);
|
|
4342
|
-
};
|
|
4343
|
-
var dynamicTagLLMResolver = (value) => {
|
|
4344
|
-
const input = value ?? {};
|
|
4345
|
-
const tag = input.name ? getAtomicDynamicTags()[input.name] : void 0;
|
|
4346
|
-
if (!tag) {
|
|
4347
|
-
return {
|
|
4348
|
-
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4349
|
-
value: { name: input.name ?? "", group: "", settings: {} }
|
|
4350
|
-
};
|
|
4351
|
-
}
|
|
4352
|
-
return {
|
|
4353
|
-
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4354
|
-
value: {
|
|
4355
|
-
name: tag.name,
|
|
4356
|
-
group: tag.group,
|
|
4357
|
-
settings: buildStrictSettings(tag.props_schema ?? {}, input.settings ?? {})
|
|
4358
|
-
}
|
|
4359
|
-
};
|
|
4360
|
-
};
|
|
4361
|
-
var buildStrictSettings = (schema2, provided) => {
|
|
4362
|
-
const settings = {};
|
|
4363
|
-
for (const [key, propType] of Object.entries(schema2)) {
|
|
4364
|
-
if (OMITTED_DYNAMIC_SETTING_KEYS.includes(key)) {
|
|
4365
|
-
continue;
|
|
4366
|
-
}
|
|
4367
|
-
const resolved = provided[key] !== void 0 ? wrapSettingValue(provided[key], propType) : defaultSettingValue(propType);
|
|
4368
|
-
if (resolved !== void 0 && resolved !== null) {
|
|
4369
|
-
settings[key] = resolved;
|
|
4370
|
-
}
|
|
4371
|
-
}
|
|
4372
|
-
return settings;
|
|
4373
|
-
};
|
|
4374
|
-
var wrapSettingValue = (raw, propType) => {
|
|
4375
|
-
if (raw !== null && typeof raw === "object") {
|
|
4376
|
-
return raw;
|
|
4377
|
-
}
|
|
4378
|
-
return propType.key ? { $$type: propType.key, value: raw } : raw;
|
|
4379
|
-
};
|
|
4380
|
-
var defaultSettingValue = (propType) => {
|
|
4381
|
-
if (propType.initial_value !== null && propType.initial_value !== void 0) {
|
|
4382
|
-
return propType.initial_value;
|
|
4383
|
-
}
|
|
4384
|
-
if (propType.default !== null && propType.default !== void 0) {
|
|
4385
|
-
return wrapSettingValue(propType.default, propType);
|
|
4386
|
-
}
|
|
4387
|
-
return void 0;
|
|
4388
|
-
};
|
|
4389
|
-
|
|
4390
|
-
// src/mcp/resources/dynamic-tags-resource.ts
|
|
4326
|
+
import { httpService as httpService3 } from "@elementor/http-client";
|
|
4391
4327
|
var DYNAMIC_TAGS_URI = "elementor://dynamic-tags";
|
|
4392
|
-
var
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
}
|
|
4397
|
-
|
|
4398
|
-
return
|
|
4399
|
-
name: tag.name,
|
|
4400
|
-
label: tag.label,
|
|
4401
|
-
categories: tag.categories,
|
|
4402
|
-
settings: settingsSchema(tag.props_schema)
|
|
4403
|
-
}));
|
|
4328
|
+
var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
|
|
4329
|
+
var fetchDynamicTags = async () => {
|
|
4330
|
+
const { data } = await httpService3().post(MCP_PROXY_URL2, {
|
|
4331
|
+
tool: "list-dynamic-tags",
|
|
4332
|
+
input: {}
|
|
4333
|
+
});
|
|
4334
|
+
return data.data ?? [];
|
|
4404
4335
|
};
|
|
4405
4336
|
var initDynamicTagsResource = (reg) => {
|
|
4406
4337
|
const { resource } = reg;
|
|
@@ -4411,15 +4342,18 @@ var initDynamicTagsResource = (reg) => {
|
|
|
4411
4342
|
description: `List of available dynamic tags. To bind a property to a dynamic source, set its value to { "$$type": "dynamic", "value": { "name": <tag name>, "settings": { ... } } } using a tag whose name appears in that property's allowed list, and populate "settings" per the tag entry here.`,
|
|
4412
4343
|
mimeType: "application/json"
|
|
4413
4344
|
},
|
|
4414
|
-
async (uri) =>
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4345
|
+
async (uri) => {
|
|
4346
|
+
const tags = await fetchDynamicTags();
|
|
4347
|
+
return {
|
|
4348
|
+
contents: [
|
|
4349
|
+
{
|
|
4350
|
+
uri: uri.href,
|
|
4351
|
+
mimeType: "application/json",
|
|
4352
|
+
text: JSON.stringify(tags)
|
|
4353
|
+
}
|
|
4354
|
+
]
|
|
4355
|
+
};
|
|
4356
|
+
}
|
|
4423
4357
|
);
|
|
4424
4358
|
};
|
|
4425
4359
|
|
|
@@ -4768,7 +4702,7 @@ import {
|
|
|
4768
4702
|
updateElementSettings,
|
|
4769
4703
|
updateElementStyle
|
|
4770
4704
|
} from "@elementor/editor-elements";
|
|
4771
|
-
import { getPropSchemaFromCache as getPropSchemaFromCache2, Schema as
|
|
4705
|
+
import { getPropSchemaFromCache as getPropSchemaFromCache2, Schema as Schema2 } from "@elementor/editor-props";
|
|
4772
4706
|
import { getStylesSchema as getStylesSchema2, getVariantByMeta } from "@elementor/editor-styles";
|
|
4773
4707
|
import { __privateRunCommandSync as runCommandSync2 } from "@elementor/editor-v1-adapters";
|
|
4774
4708
|
|
|
@@ -4838,6 +4772,68 @@ function resolveCanonicalPropKeys(elementType, props) {
|
|
|
4838
4772
|
return resolved;
|
|
4839
4773
|
}
|
|
4840
4774
|
|
|
4775
|
+
// src/mcp/utils/resolve-dynamic-tag.ts
|
|
4776
|
+
import { getElementorConfig } from "@elementor/editor-v1-adapters";
|
|
4777
|
+
var DYNAMIC_PROP_TYPE_KEY = "dynamic";
|
|
4778
|
+
var OMITTED_DYNAMIC_SETTING_KEYS = ["fallback"];
|
|
4779
|
+
var getAtomicDynamicTags = () => {
|
|
4780
|
+
const config = getElementorConfig();
|
|
4781
|
+
return config.atomicDynamicTags?.tags ?? {};
|
|
4782
|
+
};
|
|
4783
|
+
var getDynamicTagNamesByCategories = (categories) => {
|
|
4784
|
+
if (!categories.length) {
|
|
4785
|
+
return [];
|
|
4786
|
+
}
|
|
4787
|
+
const wanted = new Set(categories);
|
|
4788
|
+
return Object.values(getAtomicDynamicTags()).filter((tag) => tag.categories?.some((category) => wanted.has(category))).map((tag) => tag.name);
|
|
4789
|
+
};
|
|
4790
|
+
var dynamicTagLLMResolver = (value) => {
|
|
4791
|
+
const input = value ?? {};
|
|
4792
|
+
const tag = input.name ? getAtomicDynamicTags()[input.name] : void 0;
|
|
4793
|
+
if (!tag) {
|
|
4794
|
+
return {
|
|
4795
|
+
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4796
|
+
value: { name: input.name ?? "", group: "", settings: {} }
|
|
4797
|
+
};
|
|
4798
|
+
}
|
|
4799
|
+
return {
|
|
4800
|
+
$$type: DYNAMIC_PROP_TYPE_KEY,
|
|
4801
|
+
value: {
|
|
4802
|
+
name: tag.name,
|
|
4803
|
+
group: tag.group,
|
|
4804
|
+
settings: buildStrictSettings(tag.props_schema ?? {}, input.settings ?? {})
|
|
4805
|
+
}
|
|
4806
|
+
};
|
|
4807
|
+
};
|
|
4808
|
+
var buildStrictSettings = (schema2, provided) => {
|
|
4809
|
+
const settings = {};
|
|
4810
|
+
for (const [key, propType] of Object.entries(schema2)) {
|
|
4811
|
+
if (OMITTED_DYNAMIC_SETTING_KEYS.includes(key)) {
|
|
4812
|
+
continue;
|
|
4813
|
+
}
|
|
4814
|
+
const resolved = provided[key] !== void 0 ? wrapSettingValue(provided[key], propType) : defaultSettingValue(propType);
|
|
4815
|
+
if (resolved !== void 0 && resolved !== null) {
|
|
4816
|
+
settings[key] = resolved;
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
return settings;
|
|
4820
|
+
};
|
|
4821
|
+
var wrapSettingValue = (raw, propType) => {
|
|
4822
|
+
if (raw !== null && typeof raw === "object") {
|
|
4823
|
+
return raw;
|
|
4824
|
+
}
|
|
4825
|
+
return propType.key ? { $$type: propType.key, value: raw } : raw;
|
|
4826
|
+
};
|
|
4827
|
+
var defaultSettingValue = (propType) => {
|
|
4828
|
+
if (propType.initial_value !== null && propType.initial_value !== void 0) {
|
|
4829
|
+
return propType.initial_value;
|
|
4830
|
+
}
|
|
4831
|
+
if (propType.default !== null && propType.default !== void 0) {
|
|
4832
|
+
return wrapSettingValue(propType.default, propType);
|
|
4833
|
+
}
|
|
4834
|
+
return void 0;
|
|
4835
|
+
};
|
|
4836
|
+
|
|
4841
4837
|
// src/mcp/utils/do-update-element-property.ts
|
|
4842
4838
|
var LOCAL_STYLE_META = {
|
|
4843
4839
|
breakpoint: "desktop",
|
|
@@ -4845,7 +4841,7 @@ var LOCAL_STYLE_META = {
|
|
|
4845
4841
|
};
|
|
4846
4842
|
function resolvePropValue(value, forceKey) {
|
|
4847
4843
|
const Utils = window.elementorV2.editorVariables.Utils;
|
|
4848
|
-
return
|
|
4844
|
+
return Schema2.adjustLlmPropValueSchema(value, {
|
|
4849
4845
|
forceKey,
|
|
4850
4846
|
transformers: {
|
|
4851
4847
|
...Utils.globalVariablesLLMResolvers,
|
|
@@ -4957,7 +4953,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
4957
4953
|
}
|
|
4958
4954
|
const propKey = elementPropSchema[propertyName].key;
|
|
4959
4955
|
const value = resolvePropValue(propertyValue, propKey);
|
|
4960
|
-
const { valid, jsonSchema } =
|
|
4956
|
+
const { valid, jsonSchema } = Schema2.validatePropValue(elementPropSchema[propertyName], propertyValue);
|
|
4961
4957
|
if (!valid) {
|
|
4962
4958
|
throw new Error(
|
|
4963
4959
|
`Invalid PropValue for elementId: ${elementId}. PropKey: ${propKey}, PropValue: ${JSON.stringify(
|
|
@@ -5715,7 +5711,7 @@ function onElementAdded(element) {
|
|
|
5715
5711
|
// src/mcp/tools/configure-element/tool.ts
|
|
5716
5712
|
import { getContainer as getContainer6, getWidgetsCache as getWidgetsCache10 } from "@elementor/editor-elements";
|
|
5717
5713
|
import { dispatchMcpStylesAppliedEvent as dispatchMcpStylesAppliedEvent2 } from "@elementor/editor-mcp";
|
|
5718
|
-
import { Schema as
|
|
5714
|
+
import { Schema as Schema3 } from "@elementor/editor-props";
|
|
5719
5715
|
|
|
5720
5716
|
// src/mcp/tools/configure-element/prompt.ts
|
|
5721
5717
|
import { toolPrompts as toolPrompts2 } from "@elementor/editor-mcp";
|
|
@@ -5904,7 +5900,7 @@ var initConfigureElementTool = (reg) => {
|
|
|
5904
5900
|
const propertiesToUpdate = resolveCanonicalPropKeys(elementType, propertiesToChange);
|
|
5905
5901
|
const toUpdate = Object.entries(propertiesToUpdate);
|
|
5906
5902
|
for (const [propertyName, propertyValue] of toUpdate) {
|
|
5907
|
-
if (!
|
|
5903
|
+
if (!Schema3.isPropKeyConfigurable(propertyName)) {
|
|
5908
5904
|
throw new Error(`Not allowed to update ${propertyName}`);
|
|
5909
5905
|
}
|
|
5910
5906
|
try {
|
|
@@ -5981,9 +5977,9 @@ Provide styling as raw CSS via the "style" parameter (a flat map of CSS property
|
|
|
5981
5977
|
|
|
5982
5978
|
// src/mcp/tools/create-element/tool.ts
|
|
5983
5979
|
import { getCurrentDocument as getCurrentDocument2 } from "@elementor/editor-documents";
|
|
5984
|
-
import { httpService as
|
|
5980
|
+
import { httpService as httpService4 } from "@elementor/http-client";
|
|
5985
5981
|
import { z as z3 } from "@elementor/schema";
|
|
5986
|
-
var
|
|
5982
|
+
var MCP_PROXY_URL3 = "elementor/v1/mcp-proxy";
|
|
5987
5983
|
var initCreateElementTool = (reg) => {
|
|
5988
5984
|
const { addTool } = reg;
|
|
5989
5985
|
addTool({
|
|
@@ -6003,7 +5999,7 @@ var initCreateElementTool = (reg) => {
|
|
|
6003
5999
|
if (!document2?.id) {
|
|
6004
6000
|
throw new Error("No active document found.");
|
|
6005
6001
|
}
|
|
6006
|
-
const { data } = await
|
|
6002
|
+
const { data } = await httpService4().post(MCP_PROXY_URL3, {
|
|
6007
6003
|
tool: "create-element",
|
|
6008
6004
|
input: {
|
|
6009
6005
|
parent_id: parentId ?? "document",
|
|
@@ -6022,7 +6018,7 @@ var initCreateElementTool = (reg) => {
|
|
|
6022
6018
|
|
|
6023
6019
|
// src/mcp/tools/get-element-config/tool.ts
|
|
6024
6020
|
import { getContainer as getContainer7, getElementStyles as getElementStyles2, getWidgetsCache as getWidgetsCache11 } from "@elementor/editor-elements";
|
|
6025
|
-
import { Schema as
|
|
6021
|
+
import { Schema as Schema4 } from "@elementor/editor-props";
|
|
6026
6022
|
import { z as z4 } from "@elementor/schema";
|
|
6027
6023
|
var schema = {
|
|
6028
6024
|
elementId: z4.string()
|
|
@@ -6079,7 +6075,7 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6079
6075
|
}
|
|
6080
6076
|
const propValues = {};
|
|
6081
6077
|
const stylePropValues = {};
|
|
6082
|
-
|
|
6078
|
+
Schema4.configurableKeys(propSchema).forEach((key) => {
|
|
6083
6079
|
propValues[key] = structuredClone(elementRawSettings.get(key));
|
|
6084
6080
|
});
|
|
6085
6081
|
const elementStyles = getElementStyles2(elementId) || {};
|
|
@@ -6115,7 +6111,7 @@ var initGetElementConfigTool = (reg) => {
|
|
|
6115
6111
|
|
|
6116
6112
|
// src/mcp/canvas-mcp.ts
|
|
6117
6113
|
var initCanvasMcp = (reg) => {
|
|
6118
|
-
|
|
6114
|
+
Schema5.setDynamicTagNamesResolver(getDynamicTagNamesByCategories);
|
|
6119
6115
|
initWidgetsSchemaResource(reg);
|
|
6120
6116
|
initAvailableWidgetsResource(reg);
|
|
6121
6117
|
initDocumentStructureResource(reg);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-canvas",
|
|
3
3
|
"description": "Elementor Editor Canvas",
|
|
4
|
-
"version": "4.3.0-
|
|
4
|
+
"version": "4.3.0-989",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -37,26 +37,26 @@
|
|
|
37
37
|
"react-dom": "^18.3.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@elementor/editor": "4.3.0-
|
|
41
|
-
"@elementor/editor-controls": "4.3.0-
|
|
42
|
-
"@elementor/editor-documents": "4.3.0-
|
|
43
|
-
"@elementor/editor-elements": "4.3.0-
|
|
44
|
-
"@elementor/editor-interactions": "4.3.0-
|
|
45
|
-
"@elementor/editor-mcp": "4.3.0-
|
|
46
|
-
"@elementor/editor-notifications": "4.3.0-
|
|
47
|
-
"@elementor/editor-props": "4.3.0-
|
|
48
|
-
"@elementor/editor-responsive": "4.3.0-
|
|
49
|
-
"@elementor/editor-styles": "4.3.0-
|
|
50
|
-
"@elementor/editor-styles-repository": "4.3.0-
|
|
51
|
-
"@elementor/editor-ui": "4.3.0-
|
|
52
|
-
"@elementor/editor-v1-adapters": "4.3.0-
|
|
53
|
-
"@elementor/events": "4.3.0-
|
|
54
|
-
"@elementor/http-client": "4.3.0-
|
|
55
|
-
"@elementor/schema": "4.3.0-
|
|
56
|
-
"@elementor/twing": "4.3.0-
|
|
40
|
+
"@elementor/editor": "4.3.0-989",
|
|
41
|
+
"@elementor/editor-controls": "4.3.0-989",
|
|
42
|
+
"@elementor/editor-documents": "4.3.0-989",
|
|
43
|
+
"@elementor/editor-elements": "4.3.0-989",
|
|
44
|
+
"@elementor/editor-interactions": "4.3.0-989",
|
|
45
|
+
"@elementor/editor-mcp": "4.3.0-989",
|
|
46
|
+
"@elementor/editor-notifications": "4.3.0-989",
|
|
47
|
+
"@elementor/editor-props": "4.3.0-989",
|
|
48
|
+
"@elementor/editor-responsive": "4.3.0-989",
|
|
49
|
+
"@elementor/editor-styles": "4.3.0-989",
|
|
50
|
+
"@elementor/editor-styles-repository": "4.3.0-989",
|
|
51
|
+
"@elementor/editor-ui": "4.3.0-989",
|
|
52
|
+
"@elementor/editor-v1-adapters": "4.3.0-989",
|
|
53
|
+
"@elementor/events": "4.3.0-989",
|
|
54
|
+
"@elementor/http-client": "4.3.0-989",
|
|
55
|
+
"@elementor/schema": "4.3.0-989",
|
|
56
|
+
"@elementor/twing": "4.3.0-989",
|
|
57
57
|
"@elementor/ui": "1.37.5",
|
|
58
|
-
"@elementor/utils": "4.3.0-
|
|
59
|
-
"@elementor/wp-media": "4.3.0-
|
|
58
|
+
"@elementor/utils": "4.3.0-989",
|
|
59
|
+
"@elementor/wp-media": "4.3.0-989",
|
|
60
60
|
"@floating-ui/react": "^0.27.5",
|
|
61
61
|
"@wordpress/i18n": "^5.13.0",
|
|
62
62
|
"dompurify": "^3.2.6"
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getElementorConfig } from '@elementor/editor-v1-adapters';
|
|
1
|
+
import { httpService } from '@elementor/http-client';
|
|
3
2
|
|
|
4
3
|
import { DYNAMIC_TAGS_URI, initDynamicTagsResource } from '../dynamic-tags-resource';
|
|
5
4
|
|
|
6
|
-
jest.mock( '@elementor/
|
|
7
|
-
|
|
8
|
-
propTypeToJsonSchema: jest.fn( () => ( { mocked: true } ) ),
|
|
9
|
-
},
|
|
5
|
+
jest.mock( '@elementor/http-client', () => ( {
|
|
6
|
+
httpService: jest.fn(),
|
|
10
7
|
} ) );
|
|
11
8
|
|
|
12
|
-
jest.
|
|
13
|
-
getElementorConfig: jest.fn(),
|
|
14
|
-
} ) );
|
|
15
|
-
|
|
16
|
-
const mockedGetElementorConfig = getElementorConfig as jest.MockedFunction< typeof getElementorConfig >;
|
|
9
|
+
const mockedHttpService = httpService as jest.MockedFunction< typeof httpService >;
|
|
17
10
|
|
|
18
11
|
type ResourceHandler = ( uri: URL ) => Promise< { contents: { text: string }[] } >;
|
|
19
12
|
|
|
@@ -34,52 +27,49 @@ describe( 'dynamic-tags-resource', () => {
|
|
|
34
27
|
jest.clearAllMocks();
|
|
35
28
|
} );
|
|
36
29
|
|
|
37
|
-
it( 'returns
|
|
30
|
+
it( 'returns the flat tag list fetched from the server', async () => {
|
|
38
31
|
// Arrange
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
const post = jest.fn().mockResolvedValue( {
|
|
33
|
+
data: {
|
|
34
|
+
data: [
|
|
35
|
+
{
|
|
43
36
|
name: 'post-custom-field',
|
|
44
37
|
label: 'Post Custom Field',
|
|
45
|
-
group: 'post',
|
|
46
38
|
categories: [ 'text', 'url' ],
|
|
47
|
-
|
|
48
|
-
key: { kind: 'string', key: 'string' },
|
|
49
|
-
before: { kind: 'string', key: 'string' },
|
|
50
|
-
fallback: { kind: 'string', key: 'string' },
|
|
51
|
-
},
|
|
39
|
+
settings: { key: { mocked: true }, before: { mocked: true } },
|
|
52
40
|
},
|
|
53
|
-
|
|
54
|
-
groups: { post: { title: 'Post' } },
|
|
41
|
+
],
|
|
55
42
|
},
|
|
56
|
-
}
|
|
43
|
+
} );
|
|
44
|
+
mockedHttpService.mockReturnValue( { post } as never );
|
|
57
45
|
|
|
58
46
|
// Act
|
|
59
47
|
const catalog = await readCatalog();
|
|
60
48
|
|
|
61
49
|
// Assert
|
|
62
|
-
expect(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
name: 'post-custom-field',
|
|
66
|
-
label: 'Post Custom Field',
|
|
67
|
-
categories: [ 'text', 'url' ],
|
|
50
|
+
expect( post ).toHaveBeenCalledWith( 'elementor/v1/mcp-proxy', {
|
|
51
|
+
tool: 'list-dynamic-tags',
|
|
52
|
+
input: {},
|
|
68
53
|
} );
|
|
69
|
-
expect( catalog
|
|
70
|
-
|
|
71
|
-
|
|
54
|
+
expect( catalog ).toEqual( [
|
|
55
|
+
{
|
|
56
|
+
name: 'post-custom-field',
|
|
57
|
+
label: 'Post Custom Field',
|
|
58
|
+
categories: [ 'text', 'url' ],
|
|
59
|
+
settings: { key: { mocked: true }, before: { mocked: true } },
|
|
60
|
+
},
|
|
61
|
+
] );
|
|
72
62
|
} );
|
|
73
63
|
|
|
74
|
-
it( 'returns an empty list when
|
|
64
|
+
it( 'returns an empty list when the server returns no data', async () => {
|
|
75
65
|
// Arrange
|
|
76
|
-
|
|
66
|
+
const post = jest.fn().mockResolvedValue( { data: {} } );
|
|
67
|
+
mockedHttpService.mockReturnValue( { post } as never );
|
|
77
68
|
|
|
78
69
|
// Act
|
|
79
70
|
const catalog = await readCatalog();
|
|
80
71
|
|
|
81
72
|
// Assert
|
|
82
73
|
expect( catalog ).toEqual( [] );
|
|
83
|
-
expect( Schema.propTypeToJsonSchema ).not.toHaveBeenCalled();
|
|
84
74
|
} );
|
|
85
75
|
} );
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
type AtomicDynamicTag,
|
|
6
|
-
getAtomicDynamicTags,
|
|
7
|
-
OMITTED_DYNAMIC_SETTING_KEYS,
|
|
8
|
-
} from '../utils/resolve-dynamic-tag';
|
|
2
|
+
import { type HttpResponse, httpService } from '@elementor/http-client';
|
|
9
3
|
|
|
10
4
|
export const DYNAMIC_TAGS_URI = 'elementor://dynamic-tags';
|
|
11
5
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const MCP_PROXY_URL = 'elementor/v1/mcp-proxy';
|
|
7
|
+
|
|
8
|
+
type DynamicTagEntry = {
|
|
9
|
+
name: string;
|
|
10
|
+
label: string;
|
|
11
|
+
categories: string[];
|
|
12
|
+
settings: Record< string, unknown >;
|
|
18
13
|
};
|
|
19
14
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const fetchDynamicTags = async (): Promise< DynamicTagEntry[] > => {
|
|
16
|
+
const { data } = await httpService().post< HttpResponse< DynamicTagEntry[] > >( MCP_PROXY_URL, {
|
|
17
|
+
tool: 'list-dynamic-tags',
|
|
18
|
+
input: {},
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
return data.data ?? [];
|
|
27
22
|
};
|
|
28
23
|
|
|
29
24
|
export const initDynamicTagsResource = ( reg: MCPRegistryEntry ) => {
|
|
@@ -39,14 +34,18 @@ export const initDynamicTagsResource = ( reg: MCPRegistryEntry ) => {
|
|
|
39
34
|
'name appears in that property\'s allowed list, and populate "settings" per the tag entry here.',
|
|
40
35
|
mimeType: 'application/json',
|
|
41
36
|
},
|
|
42
|
-
async ( uri: URL ) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
async ( uri: URL ) => {
|
|
38
|
+
const tags = await fetchDynamicTags();
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
contents: [
|
|
42
|
+
{
|
|
43
|
+
uri: uri.href,
|
|
44
|
+
mimeType: 'application/json',
|
|
45
|
+
text: JSON.stringify( tags ),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
51
50
|
);
|
|
52
51
|
};
|