@elementor/editor-canvas 3.33.0-291 → 3.33.0-293
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 +157 -57
- package/dist/index.mjs +150 -46
- package/package.json +17 -17
- package/src/mcp/canvas-mcp.ts +2 -0
- package/src/mcp/mcp-description.ts +18 -8
- package/src/mcp/resources/widgets-schema-resource.ts +22 -3
- package/src/mcp/tools/build-composition/prompt.ts +5 -2
- package/src/mcp/tools/build-composition/tool.ts +20 -15
- package/src/mcp/tools/configure-element/prompt.ts +6 -3
- package/src/mcp/tools/get-element-config/tool.ts +75 -0
- package/src/mcp/utils/do-update-element-property.ts +17 -3
package/dist/index.js
CHANGED
|
@@ -480,10 +480,10 @@ var getMultiPropsValue = (multiProps) => {
|
|
|
480
480
|
// src/renderers/create-props-resolver.ts
|
|
481
481
|
var TRANSFORM_DEPTH_LIMIT = 3;
|
|
482
482
|
function createPropsResolver({ transformers, schema: initialSchema, onPropResolve }) {
|
|
483
|
-
async function resolve({ props, schema, signal }) {
|
|
484
|
-
|
|
483
|
+
async function resolve({ props, schema: schema2, signal }) {
|
|
484
|
+
schema2 = schema2 ?? initialSchema;
|
|
485
485
|
const promises = Promise.all(
|
|
486
|
-
Object.entries(
|
|
486
|
+
Object.entries(schema2).map(async ([key, type]) => {
|
|
487
487
|
const value = props[key] ?? type.default;
|
|
488
488
|
const transformed = await transform({ value, key, type, signal });
|
|
489
489
|
onPropResolve?.({ key, value: transformed });
|
|
@@ -1148,11 +1148,11 @@ function getVal2(val) {
|
|
|
1148
1148
|
var transformOriginTransformer = createTransformer((value) => {
|
|
1149
1149
|
const x = getVal2(value.x);
|
|
1150
1150
|
const y = getVal2(value.y);
|
|
1151
|
-
const
|
|
1152
|
-
if (x === DEFAULT_XY && y === DEFAULT_XY &&
|
|
1151
|
+
const z4 = getVal2(value.z);
|
|
1152
|
+
if (x === DEFAULT_XY && y === DEFAULT_XY && z4 === DEFAULT_Z) {
|
|
1153
1153
|
return null;
|
|
1154
1154
|
}
|
|
1155
|
-
return `${x} ${y} ${
|
|
1155
|
+
return `${x} ${y} ${z4}`;
|
|
1156
1156
|
});
|
|
1157
1157
|
|
|
1158
1158
|
// src/transformers/styles/transform-rotate-transformer.ts
|
|
@@ -1501,8 +1501,24 @@ var import_editor_props2 = require("@elementor/editor-props");
|
|
|
1501
1501
|
var import_editor_styles4 = require("@elementor/editor-styles");
|
|
1502
1502
|
var WIDGET_SCHEMA_URI = "elementor://widgets/schema/{widgetType}";
|
|
1503
1503
|
var STYLE_SCHEMA_URI = "elementor://styles/schema/{category}";
|
|
1504
|
+
var BEST_PRACTICES_URI = "elementor://styles/best-practices";
|
|
1504
1505
|
var initWidgetsSchemaResource = (reg) => {
|
|
1505
1506
|
const { mcpServer } = reg;
|
|
1507
|
+
mcpServer.resource("styles-best-practices", BEST_PRACTICES_URI, async () => {
|
|
1508
|
+
return {
|
|
1509
|
+
contents: [
|
|
1510
|
+
{
|
|
1511
|
+
uri: BEST_PRACTICES_URI,
|
|
1512
|
+
text: `# Styling best practices
|
|
1513
|
+
Prefer using "em" and "rem" values for text-related sizes, padding and spacing. Use percentages for dynamic sizing relative to parent containers.
|
|
1514
|
+
This flexboxes are by default "flex" with "stretch" alignment. To ensure proper layout, define the "justify-content" and "align-items" as in the schema, or in custom_css, depends on your needs.
|
|
1515
|
+
|
|
1516
|
+
When applicable for styles, use the "custom_css" property for free-form CSS styling. This property accepts a string of CSS rules that will be applied directly to the element.
|
|
1517
|
+
The css string must follow standard CSS syntax, with properties and values separated by semicolons, no selectors, or nesting rules allowed.`
|
|
1518
|
+
}
|
|
1519
|
+
]
|
|
1520
|
+
};
|
|
1521
|
+
});
|
|
1506
1522
|
mcpServer.resource(
|
|
1507
1523
|
"styles-schema",
|
|
1508
1524
|
new import_editor_mcp.ResourceTemplate(STYLE_SCHEMA_URI, {
|
|
@@ -1579,9 +1595,9 @@ var initWidgetsSchemaResource = (reg) => {
|
|
|
1579
1595
|
import_editor_props2.Schema.propTypeToJsonSchema(propType)
|
|
1580
1596
|
])
|
|
1581
1597
|
);
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1598
|
+
import_editor_props2.Schema.nonConfigurablePropKeys.forEach((key) => {
|
|
1599
|
+
delete asJson[key];
|
|
1600
|
+
});
|
|
1585
1601
|
return {
|
|
1586
1602
|
contents: [
|
|
1587
1603
|
{
|
|
@@ -1669,8 +1685,12 @@ var doUpdateElementProperty = (params) => {
|
|
|
1669
1685
|
Object.keys(propertyMapValue).forEach((stylePropName) => {
|
|
1670
1686
|
const propertyRawSchema = styleSchema[stylePropName];
|
|
1671
1687
|
if (stylePropName === "custom_css") {
|
|
1688
|
+
let customCssValue = propertyMapValue[stylePropName];
|
|
1689
|
+
if (typeof customCssValue === "object") {
|
|
1690
|
+
customCssValue = import_editor_props3.stringPropTypeUtil.extract(customCssValue) || customCssValue?.value || "";
|
|
1691
|
+
}
|
|
1672
1692
|
customCss = {
|
|
1673
|
-
raw: btoa(
|
|
1693
|
+
raw: btoa(customCssValue)
|
|
1674
1694
|
};
|
|
1675
1695
|
return;
|
|
1676
1696
|
}
|
|
@@ -1692,7 +1712,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
1692
1712
|
if (!localStyle) {
|
|
1693
1713
|
(0, import_editor_elements4.createElementStyle)({
|
|
1694
1714
|
elementId,
|
|
1695
|
-
custom_css: customCss,
|
|
1715
|
+
...typeof customCss !== "undefined" ? { custom_css: customCss } : {},
|
|
1696
1716
|
classesProp: "classes",
|
|
1697
1717
|
label: "local",
|
|
1698
1718
|
meta: {
|
|
@@ -1711,6 +1731,7 @@ var doUpdateElementProperty = (params) => {
|
|
|
1711
1731
|
breakpoint: "desktop",
|
|
1712
1732
|
state: null
|
|
1713
1733
|
},
|
|
1734
|
+
...typeof customCss !== "undefined" ? { custom_css: customCss } : {},
|
|
1714
1735
|
props: {
|
|
1715
1736
|
...transformedStyleValues
|
|
1716
1737
|
}
|
|
@@ -1775,6 +1796,7 @@ Prefer this tool over any other tool for building HTML structure, unless you are
|
|
|
1775
1796
|
For easy execution, USE ONLY "custom_css" category from the styles schema resource to apply styles.
|
|
1776
1797
|
5. Ensure the XML structure is valid and parsable.
|
|
1777
1798
|
6. Do not add any attribute nodes, classes, id's, and no text nodes allowed, for inline styles prefer USE the [${CUSTOM_CSS_URI}] resource for custom_css.
|
|
1799
|
+
Layout properties, such as margin, padding, align, etc. must be applied using the [${STYLE_SCHEMA_URI}] PropValues.
|
|
1778
1800
|
7. Some elements allow nesting of other elements, and most of the DO NOT. The allowed elements that can have nested children are "e-div-block" and "e-flexbox".
|
|
1779
1801
|
8. Make sure that non-container elements do NOT have any nested elements.
|
|
1780
1802
|
9. Unsless the user specifically requires structure only, BE EXPRESSIVE AND VISUALLY CREATIVE AS POSSIBLE IN APPLYING STYLE CONFIGURATION.
|
|
@@ -1789,6 +1811,8 @@ Prefer this tool over any other tool for building HTML structure, unless you are
|
|
|
1789
1811
|
- Always aim for a clean and professional look that aligns with modern design principles.
|
|
1790
1812
|
- When you are required to create placeholder texts, use texts that have a length that fits the goal. When long texts are required, use longer placeholder texts. When the user specifies exact texts, use the exact texts.
|
|
1791
1813
|
- Image size does not affect the actual size on the screen, only which quality to use. If you use images, specifically add _styles PropValues to define the image sizes.
|
|
1814
|
+
- Attempt to use layout, margin, padding, size properties from the styles schema and not the custom_css, unless necessary.
|
|
1815
|
+
- If your elements library is limited, encourage use of nesting containers to achieve complex layouts.
|
|
1792
1816
|
|
|
1793
1817
|
# CONSTRAINTS
|
|
1794
1818
|
When a tool execution fails, retry up to 10 more times, read the error message carefully, and adjust the XML structure or the configurations accordingly.
|
|
@@ -1820,7 +1844,7 @@ A Heading and a button inside a flexbox
|
|
|
1820
1844
|
"value": "section"
|
|
1821
1845
|
},
|
|
1822
1846
|
},
|
|
1823
|
-
|
|
1847
|
+
stylesConfig: {
|
|
1824
1848
|
"heading1": {
|
|
1825
1849
|
"custom_css": "font-size: 24px; color: #333;"
|
|
1826
1850
|
}
|
|
@@ -1836,7 +1860,7 @@ A Heading and a button inside a flexbox
|
|
|
1836
1860
|
`**MANDATORY** A record mapping configuration IDs to their corresponding configuration objects, defining the PropValues for each element created.`
|
|
1837
1861
|
);
|
|
1838
1862
|
buildCompositionsToolPrompt.parameter(
|
|
1839
|
-
"
|
|
1863
|
+
"stylesConfig",
|
|
1840
1864
|
`**MANDATORY** A record mapping style PropTypes to their corresponding style configuration objects, defining the PropValues for styles to be applied to elements.`
|
|
1841
1865
|
);
|
|
1842
1866
|
buildCompositionsToolPrompt.instruction(
|
|
@@ -1884,16 +1908,9 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1884
1908
|
const { xmlStructure, elementConfig, stylesConfig } = params;
|
|
1885
1909
|
const errors = [];
|
|
1886
1910
|
const softErrors = [];
|
|
1911
|
+
const rootContainers = [];
|
|
1887
1912
|
const widgetsCache = (0, import_editor_elements5.getWidgetsCache)() || {};
|
|
1888
1913
|
const documentContainer = (0, import_editor_elements5.getContainer)("document");
|
|
1889
|
-
const rootContainer = (0, import_editor_elements5.createElement)({
|
|
1890
|
-
containerId: documentContainer.id,
|
|
1891
|
-
model: {
|
|
1892
|
-
elType: "container",
|
|
1893
|
-
id: (0, import_editor_elements5.generateElementId)()
|
|
1894
|
-
},
|
|
1895
|
-
options: { useHistory: false }
|
|
1896
|
-
});
|
|
1897
1914
|
try {
|
|
1898
1915
|
const parser = new DOMParser();
|
|
1899
1916
|
xml = parser.parseFromString(xmlStructure, "application/xml");
|
|
@@ -1902,7 +1919,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1902
1919
|
throw new Error("Failed to parse XML structure: " + errorNode.textContent);
|
|
1903
1920
|
}
|
|
1904
1921
|
const children = Array.from(xml.children);
|
|
1905
|
-
const iterate = (node, containerElement) => {
|
|
1922
|
+
const iterate = (node, containerElement = documentContainer) => {
|
|
1906
1923
|
const elementTag = node.tagName;
|
|
1907
1924
|
if (!widgetsCache[elementTag]) {
|
|
1908
1925
|
errors.push(new Error(`Unknown widget type: ${elementTag}`));
|
|
@@ -1924,6 +1941,9 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1924
1941
|
},
|
|
1925
1942
|
options: { useHistory: false }
|
|
1926
1943
|
});
|
|
1944
|
+
if (containerElement === documentContainer) {
|
|
1945
|
+
rootContainers.push(newElement);
|
|
1946
|
+
}
|
|
1927
1947
|
node.setAttribute("id", newElement.id);
|
|
1928
1948
|
const configId = node.getAttribute("configuration-id") || "";
|
|
1929
1949
|
try {
|
|
@@ -1932,7 +1952,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1932
1952
|
configObject._styles = styleObject;
|
|
1933
1953
|
for (const [propertyName, propertyValue] of Object.entries(configObject)) {
|
|
1934
1954
|
const widgetSchema = widgetsCache[elementTag];
|
|
1935
|
-
if (!widgetSchema?.atomic_props_schema?.[propertyName] && propertyName !== "_styles") {
|
|
1955
|
+
if (!widgetSchema?.atomic_props_schema?.[propertyName] && propertyName !== "_styles" && propertyName !== "custom_css") {
|
|
1936
1956
|
softErrors.push(
|
|
1937
1957
|
new Error(
|
|
1938
1958
|
`Property "${propertyName}" does not exist on element type "${elementTag}".`
|
|
@@ -1944,7 +1964,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1944
1964
|
doUpdateElementProperty({
|
|
1945
1965
|
elementId: newElement.id,
|
|
1946
1966
|
propertyName,
|
|
1947
|
-
propertyValue,
|
|
1967
|
+
propertyValue: propertyName === "custom_css" ? { _styles: propertyValue } : propertyValue,
|
|
1948
1968
|
elementType: elementTag
|
|
1949
1969
|
});
|
|
1950
1970
|
} catch (error) {
|
|
@@ -1963,7 +1983,7 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1963
1983
|
}
|
|
1964
1984
|
};
|
|
1965
1985
|
for (const childNode of children) {
|
|
1966
|
-
iterate(childNode,
|
|
1986
|
+
iterate(childNode, documentContainer);
|
|
1967
1987
|
try {
|
|
1968
1988
|
} catch (error) {
|
|
1969
1989
|
errors.push(error);
|
|
@@ -1973,9 +1993,11 @@ var initBuildCompositionsTool = (reg) => {
|
|
|
1973
1993
|
errors.push(error);
|
|
1974
1994
|
}
|
|
1975
1995
|
if (errors.length) {
|
|
1976
|
-
(
|
|
1977
|
-
|
|
1978
|
-
|
|
1996
|
+
rootContainers.forEach((rootContainer) => {
|
|
1997
|
+
(0, import_editor_elements5.deleteElement)({
|
|
1998
|
+
elementId: rootContainer.id,
|
|
1999
|
+
options: { useHistory: false }
|
|
2000
|
+
});
|
|
1979
2001
|
});
|
|
1980
2002
|
}
|
|
1981
2003
|
if (errors.length > 0) {
|
|
@@ -2009,19 +2031,20 @@ Next Steps:
|
|
|
2009
2031
|
// src/mcp/tools/configure-element/prompt.ts
|
|
2010
2032
|
var configureElementToolPrompt = `Configure an existing element on the page.
|
|
2011
2033
|
|
|
2012
|
-
# **CRITICAL - REQUIRED
|
|
2034
|
+
# **CRITICAL - REQUIRED INFORMATION (Must read before using this tool)**
|
|
2013
2035
|
1. [${WIDGET_SCHEMA_URI}]
|
|
2014
2036
|
Required to understand which widgets are available, and what are their configuration schemas.
|
|
2015
2037
|
Every widgetType (i.e. e-heading, e-button) that is supported has it's own property schema, that you must follow in order to apply property values correctly.
|
|
2016
2038
|
2. [${STYLE_SCHEMA_URI}]
|
|
2017
2039
|
Required to understand the styles schema for the widgets. All widgets share the same styles schema, grouped by categories.
|
|
2018
2040
|
Use this resource to understand which style properties are available for each element, and how to structure the "_styles" configuration property.
|
|
2041
|
+
3. If not sure about the PropValues schema, you can use the "get-element-configuration-values" tool to retreive the current PropValues configuration of the element.
|
|
2019
2042
|
|
|
2020
2043
|
Before using this tool, check the definitions of the elements PropTypes at the resource "widget-schema-by-type" at editor-canvas__elementor://widgets/schema/{widgetType}
|
|
2021
2044
|
All widgets share a common _style property for styling, which uses the common styles schema.
|
|
2022
2045
|
Retreive and check the common styles schema at the resource list "styles-schema" at editor-canvas__elementor://styles/schema/{category}
|
|
2023
2046
|
|
|
2024
|
-
|
|
2047
|
+
Attempt to use the _style property "custom_css" for any styling that have complicated schemas (such as backgrounds), read the resource editor-canvas__elementor://styles/schema/custom_css for more information.
|
|
2025
2048
|
|
|
2026
2049
|
# Parameters
|
|
2027
2050
|
- propertiesToChange: An object containing the properties to change, with their new values. MANDATORY
|
|
@@ -2066,6 +2089,7 @@ Use the EXACT "PROP-TYPE" Schema given, and ALWAYS include the "key" property fr
|
|
|
2066
2089
|
\`\`\`json
|
|
2067
2090
|
{
|
|
2068
2091
|
propertiesToChange: {
|
|
2092
|
+
// List of properties TO CHANGE, following the PropType schema for the element as defined in the resource [${WIDGET_SCHEMA_URI}]
|
|
2069
2093
|
title: {
|
|
2070
2094
|
$$type: 'string',
|
|
2071
2095
|
value: 'New Title Text'
|
|
@@ -2075,8 +2099,9 @@ Use the EXACT "PROP-TYPE" Schema given, and ALWAYS include the "key" property fr
|
|
|
2075
2099
|
value: false
|
|
2076
2100
|
},
|
|
2077
2101
|
_styles: {
|
|
2102
|
+
// List of available keys available at the [${STYLE_SCHEMA_URI}] dynamic resource
|
|
2078
2103
|
'line-height': {
|
|
2079
|
-
$$type: 'size',
|
|
2104
|
+
$$type: 'size', // MANDATORY do not forget to include the correct $$type for every property
|
|
2080
2105
|
value: {
|
|
2081
2106
|
size: {
|
|
2082
2107
|
$$type: 'number',
|
|
@@ -2170,6 +2195,70 @@ Check the element's PropType schema at the resource [${WIDGET_SCHEMA_URI.replace
|
|
|
2170
2195
|
Now that you have this information, ensure you have the schema and try again.`;
|
|
2171
2196
|
}
|
|
2172
2197
|
|
|
2198
|
+
// src/mcp/tools/get-element-config/tool.ts
|
|
2199
|
+
var import_editor_elements6 = require("@elementor/editor-elements");
|
|
2200
|
+
var import_editor_props4 = require("@elementor/editor-props");
|
|
2201
|
+
var import_schema5 = require("@elementor/schema");
|
|
2202
|
+
var import_utils4 = require("@elementor/utils");
|
|
2203
|
+
var schema = {
|
|
2204
|
+
elementId: import_schema5.z.string()
|
|
2205
|
+
};
|
|
2206
|
+
var outputSchema3 = {
|
|
2207
|
+
propValues: import_schema5.z.record(import_schema5.z.string(), import_schema5.z.any()).describe(
|
|
2208
|
+
"A record mapping PropTypes to their corresponding PropValues, with _styles record for style-related PropValues"
|
|
2209
|
+
),
|
|
2210
|
+
customCss: import_schema5.z.string().optional().describe("The custom CSS string associated with the element, if any.")
|
|
2211
|
+
};
|
|
2212
|
+
var initGetElementConfigTool = (reg) => {
|
|
2213
|
+
const { addTool } = reg;
|
|
2214
|
+
addTool({
|
|
2215
|
+
name: "get-element-configuration-values",
|
|
2216
|
+
description: "Retrieve the element's configuration PropValues for a specific element by unique ID.",
|
|
2217
|
+
schema,
|
|
2218
|
+
outputSchema: outputSchema3,
|
|
2219
|
+
handler: async ({ elementId }) => {
|
|
2220
|
+
const element = (0, import_editor_elements6.getContainer)(elementId);
|
|
2221
|
+
if (!element) {
|
|
2222
|
+
throw new Error(`Element with ID ${elementId} not found.`);
|
|
2223
|
+
}
|
|
2224
|
+
const elementRawSettings = element.settings;
|
|
2225
|
+
const propSchema = (0, import_editor_elements6.getWidgetsCache)()?.[element.model.get("widgetType") || ""]?.atomic_props_schema;
|
|
2226
|
+
if (!elementRawSettings || !propSchema) {
|
|
2227
|
+
throw new Error(`No settings or prop schema found for element ID: ${elementId}`);
|
|
2228
|
+
}
|
|
2229
|
+
const propValues = {};
|
|
2230
|
+
const stylePropValues = {};
|
|
2231
|
+
import_editor_props4.Schema.configurableKeys(propSchema).forEach((key) => {
|
|
2232
|
+
propValues[key] = structuredClone(elementRawSettings.get(key));
|
|
2233
|
+
});
|
|
2234
|
+
const elementStyles = (0, import_editor_elements6.getElementStyles)(elementId) || {};
|
|
2235
|
+
const localStyle = Object.values(elementStyles).find((style) => style.label === "local");
|
|
2236
|
+
if (localStyle) {
|
|
2237
|
+
const defaultVariant = localStyle.variants.find(
|
|
2238
|
+
(variant) => variant.meta.breakpoint === "desktop" && !variant.meta.state
|
|
2239
|
+
);
|
|
2240
|
+
if (defaultVariant) {
|
|
2241
|
+
const styleProps = defaultVariant.props || {};
|
|
2242
|
+
Object.keys(styleProps).forEach((stylePropName) => {
|
|
2243
|
+
if (typeof styleProps[stylePropName] !== "undefined") {
|
|
2244
|
+
stylePropValues[stylePropName] = structuredClone(styleProps[stylePropName]);
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
if (defaultVariant.custom_css?.raw) {
|
|
2248
|
+
stylePropValues.custom_css = (0, import_utils4.decodeString)(defaultVariant.custom_css.raw, void 0);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
return {
|
|
2253
|
+
propValues: {
|
|
2254
|
+
...propValues,
|
|
2255
|
+
_styles: stylePropValues
|
|
2256
|
+
}
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
};
|
|
2261
|
+
|
|
2173
2262
|
// src/mcp/canvas-mcp.ts
|
|
2174
2263
|
var initCanvasMcp = (reg) => {
|
|
2175
2264
|
const { setMCPDescription } = reg;
|
|
@@ -2178,6 +2267,7 @@ var initCanvasMcp = (reg) => {
|
|
|
2178
2267
|
);
|
|
2179
2268
|
initWidgetsSchemaResource(reg);
|
|
2180
2269
|
initBuildCompositionsTool(reg);
|
|
2270
|
+
initGetElementConfigTool(reg);
|
|
2181
2271
|
initConfigureElementTool(reg);
|
|
2182
2272
|
};
|
|
2183
2273
|
|
|
@@ -2186,36 +2276,46 @@ var mcpDescription = `Canvas MCP - Working with widgets and styles: how to use t
|
|
|
2186
2276
|
|
|
2187
2277
|
# Elementor's PropValue configuration system
|
|
2188
2278
|
|
|
2189
|
-
Every widget in Elementor has a set of properties that can be configured
|
|
2190
|
-
All values are
|
|
2279
|
+
Every widget in Elementor has a set of properties that can be configured, defined in a STRICT SCHEMA we call "PropType".
|
|
2280
|
+
All widget configuration values are represented using a structure we call "PropValue".
|
|
2191
2281
|
|
|
2192
|
-
To correctly configure a widget's properties,
|
|
2282
|
+
To correctly configure a widget's properties, FOLLOW THE PropType schema defined for that widget. This schema outlines the expected structure and types for each property, ensuring that the values you provide are valid and can be properly interpreted by Elementor.
|
|
2193
2283
|
Every widget has it's own PropType schema, retreivable from the resource [${WIDGET_SCHEMA_URI}].
|
|
2194
2284
|
ALL WIDGETS share a common _styles property with a uniform styles schema, retreivable from the resource [${STYLE_SCHEMA_URI}].
|
|
2195
2285
|
The style schema is grouped by categories, such as "typography", "background", "border", etc.
|
|
2196
2286
|
|
|
2287
|
+
# Tools and usage
|
|
2288
|
+
- Use the "get-element-configuration-values" tool to retrieve the current configuration of a specific element, including its PropValues and styles. It is recommended to use this tool when you are required to make changes to an existing element, to ensure you have the correct current configuration schema.
|
|
2289
|
+
If a PropValue changes it's type (only on union PropTypes), read the new schema from the resources mentioned above, and adjust the PropValue structure accordingly.
|
|
2290
|
+
- Use the "build-composition" tool to create a NEW ELEMENTS in a composition on the page. You can use this tool to also create a new single element.
|
|
2291
|
+
- Use the "configure-element" tool to update the configuration of an EXISTING element on the page.
|
|
2292
|
+
|
|
2197
2293
|
All array types that can receive union types, are typed as mixed array, which means that each item in the array can be of any of the allowed types defined in the PropType schema.
|
|
2198
2294
|
Example: the "background" can have a background-overlay property, which can contain multiple overlays, such as color, gradient, image, etc. Each item in the array must follow the PropType schema for each overlay type.
|
|
2199
2295
|
All _style properties are OPTIONAL. When a _style is defined, we MERGE the values with existing styles, so only the properties you define will be changed, and the rest will remain as is.
|
|
2200
2296
|
|
|
2297
|
+
# Styling best practices
|
|
2298
|
+
Prefer using "em" and "rem" values for text-related sizes, padding and spacing. Use percentages for dynamic sizing relative to parent containers.
|
|
2299
|
+
This flexboxes are by default "flex" with "stretch" alignment. To ensure proper layout, define the "justify-content" and "align-items" as in the schema, or in custom_css, depends on your needs.
|
|
2300
|
+
|
|
2201
2301
|
When applicable for styles, use the "custom_css" property for free-form CSS styling. This property accepts a string of CSS rules that will be applied directly to the element.
|
|
2202
2302
|
The css string must follow standard CSS syntax, with properties and values separated by semicolons, no selectors, or nesting rules allowed.
|
|
2203
2303
|
|
|
2204
2304
|
Additionaly, some PropTypes have metadata information (meta property) that can help in understaind the PropType usage, such as description or other useful information.
|
|
2205
2305
|
|
|
2206
|
-
|
|
2207
|
-
|
|
2306
|
+
Example of null values:
|
|
2307
|
+
{
|
|
2308
|
+
$$type: 'as-defined-for-propValue',
|
|
2309
|
+
value: null
|
|
2310
|
+
}
|
|
2208
2311
|
|
|
2209
2312
|
Example of "image" PropValue structure:
|
|
2210
|
-
|
|
2211
|
-
PropValue structure:
|
|
2212
2313
|
{$$type:'image',value:{src:{$$type:'image-src',value:{url:{$$type:'url',value:'https://example.com/image.jpg'}}},size:{$$type:'string',value:'full'}}}
|
|
2213
2314
|
|
|
2214
|
-
Example of
|
|
2215
2315
|
`;
|
|
2216
2316
|
|
|
2217
2317
|
// src/prevent-link-in-link-commands.ts
|
|
2218
|
-
var
|
|
2318
|
+
var import_editor_elements7 = require("@elementor/editor-elements");
|
|
2219
2319
|
var import_editor_notifications = require("@elementor/editor-notifications");
|
|
2220
2320
|
var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
|
|
2221
2321
|
var import_i18n = require("@wordpress/i18n");
|
|
@@ -2286,13 +2386,13 @@ function shouldBlock(sourceElements, targetElements) {
|
|
|
2286
2386
|
return false;
|
|
2287
2387
|
}
|
|
2288
2388
|
const isSourceContainsAnAnchor = sourceElements.some((src) => {
|
|
2289
|
-
return src?.id ? (0,
|
|
2389
|
+
return src?.id ? (0, import_editor_elements7.isElementAnchored)(src.id) || !!(0, import_editor_elements7.getAnchoredDescendantId)(src.id) : false;
|
|
2290
2390
|
});
|
|
2291
2391
|
if (!isSourceContainsAnAnchor) {
|
|
2292
2392
|
return false;
|
|
2293
2393
|
}
|
|
2294
2394
|
const isTargetContainsAnAnchor = targetElements.some((target) => {
|
|
2295
|
-
return target?.id ? (0,
|
|
2395
|
+
return target?.id ? (0, import_editor_elements7.isElementAnchored)(target.id) || !!(0, import_editor_elements7.getAnchoredAncestorId)(target.id) : false;
|
|
2296
2396
|
});
|
|
2297
2397
|
return isTargetContainsAnAnchor;
|
|
2298
2398
|
}
|
|
@@ -2301,14 +2401,14 @@ function shouldBlock(sourceElements, targetElements) {
|
|
|
2301
2401
|
var import_editor_v1_adapters10 = require("@elementor/editor-v1-adapters");
|
|
2302
2402
|
|
|
2303
2403
|
// src/style-commands/undoable-actions/paste-element-style.ts
|
|
2304
|
-
var
|
|
2404
|
+
var import_editor_elements9 = require("@elementor/editor-elements");
|
|
2305
2405
|
var import_editor_styles_repository4 = require("@elementor/editor-styles-repository");
|
|
2306
2406
|
var import_editor_v1_adapters9 = require("@elementor/editor-v1-adapters");
|
|
2307
2407
|
var import_i18n3 = require("@wordpress/i18n");
|
|
2308
2408
|
|
|
2309
2409
|
// src/style-commands/utils.ts
|
|
2310
|
-
var
|
|
2311
|
-
var
|
|
2410
|
+
var import_editor_elements8 = require("@elementor/editor-elements");
|
|
2411
|
+
var import_editor_props5 = require("@elementor/editor-props");
|
|
2312
2412
|
var import_i18n2 = require("@wordpress/i18n");
|
|
2313
2413
|
function hasAtomicWidgets(args) {
|
|
2314
2414
|
const { containers = [args.container] } = args;
|
|
@@ -2326,13 +2426,13 @@ function getClassesProp(container) {
|
|
|
2326
2426
|
return null;
|
|
2327
2427
|
}
|
|
2328
2428
|
const [propKey] = Object.entries(propsSchema).find(
|
|
2329
|
-
([, propType]) => propType.kind === "plain" && propType.key ===
|
|
2429
|
+
([, propType]) => propType.kind === "plain" && propType.key === import_editor_props5.CLASSES_PROP_KEY
|
|
2330
2430
|
) ?? [];
|
|
2331
2431
|
return propKey ?? null;
|
|
2332
2432
|
}
|
|
2333
2433
|
function getContainerSchema(container) {
|
|
2334
2434
|
const type = container?.model.get("widgetType") || container?.model.get("elType");
|
|
2335
|
-
const widgetsCache = (0,
|
|
2435
|
+
const widgetsCache = (0, import_editor_elements8.getWidgetsCache)();
|
|
2336
2436
|
const elementType = widgetsCache?.[type];
|
|
2337
2437
|
return elementType?.atomic_props_schema ?? null;
|
|
2338
2438
|
}
|
|
@@ -2345,7 +2445,7 @@ function getClipboardElements(storageKey = "clipboard") {
|
|
|
2345
2445
|
}
|
|
2346
2446
|
}
|
|
2347
2447
|
function getTitleForContainers(containers) {
|
|
2348
|
-
return containers.length > 1 ? (0, import_i18n2.__)("Elements", "elementor") : (0,
|
|
2448
|
+
return containers.length > 1 ? (0, import_i18n2.__)("Elements", "elementor") : (0, import_editor_elements8.getElementLabel)(containers[0].id);
|
|
2349
2449
|
}
|
|
2350
2450
|
|
|
2351
2451
|
// src/style-commands/undoable-actions/paste-element-style.ts
|
|
@@ -2358,7 +2458,7 @@ var undoablePasteElementStyle = () => (0, import_editor_v1_adapters9.undoable)(
|
|
|
2358
2458
|
if (!classesProp) {
|
|
2359
2459
|
return null;
|
|
2360
2460
|
}
|
|
2361
|
-
const originalStyles = (0,
|
|
2461
|
+
const originalStyles = (0, import_editor_elements9.getElementStyles)(container.id);
|
|
2362
2462
|
const [styleId, styleDef] = Object.entries(originalStyles ?? {})[0] ?? [];
|
|
2363
2463
|
const originalStyle = Object.keys(styleDef ?? {}).length ? styleDef : null;
|
|
2364
2464
|
const revertData = {
|
|
@@ -2367,7 +2467,7 @@ var undoablePasteElementStyle = () => (0, import_editor_v1_adapters9.undoable)(
|
|
|
2367
2467
|
};
|
|
2368
2468
|
if (styleId) {
|
|
2369
2469
|
newStyle.variants.forEach(({ meta, props, custom_css: customCss }) => {
|
|
2370
|
-
(0,
|
|
2470
|
+
(0, import_editor_elements9.updateElementStyle)({
|
|
2371
2471
|
elementId,
|
|
2372
2472
|
styleId,
|
|
2373
2473
|
meta,
|
|
@@ -2378,7 +2478,7 @@ var undoablePasteElementStyle = () => (0, import_editor_v1_adapters9.undoable)(
|
|
|
2378
2478
|
} else {
|
|
2379
2479
|
const [firstVariant] = newStyle.variants;
|
|
2380
2480
|
const additionalVariants = newStyle.variants.slice(1);
|
|
2381
|
-
revertData.styleId = (0,
|
|
2481
|
+
revertData.styleId = (0, import_editor_elements9.createElementStyle)({
|
|
2382
2482
|
elementId,
|
|
2383
2483
|
classesProp,
|
|
2384
2484
|
label: import_editor_styles_repository4.ELEMENTS_STYLES_RESERVED_LABEL,
|
|
@@ -2396,7 +2496,7 @@ var undoablePasteElementStyle = () => (0, import_editor_v1_adapters9.undoable)(
|
|
|
2396
2496
|
return;
|
|
2397
2497
|
}
|
|
2398
2498
|
if (!revertData.originalStyle) {
|
|
2399
|
-
(0,
|
|
2499
|
+
(0, import_editor_elements9.deleteElementStyle)(container.id, revertData.styleId);
|
|
2400
2500
|
return;
|
|
2401
2501
|
}
|
|
2402
2502
|
const classesProp = getClassesProp(container);
|
|
@@ -2405,7 +2505,7 @@ var undoablePasteElementStyle = () => (0, import_editor_v1_adapters9.undoable)(
|
|
|
2405
2505
|
}
|
|
2406
2506
|
const [firstVariant] = revertData.originalStyle.variants;
|
|
2407
2507
|
const additionalVariants = revertData.originalStyle.variants.slice(1);
|
|
2408
|
-
(0,
|
|
2508
|
+
(0, import_editor_elements9.createElementStyle)({
|
|
2409
2509
|
elementId: container.id,
|
|
2410
2510
|
classesProp,
|
|
2411
2511
|
label: import_editor_styles_repository4.ELEMENTS_STYLES_RESERVED_LABEL,
|
|
@@ -2457,7 +2557,7 @@ function pasteStyles(args, pasteCallback) {
|
|
|
2457
2557
|
var import_editor_v1_adapters12 = require("@elementor/editor-v1-adapters");
|
|
2458
2558
|
|
|
2459
2559
|
// src/style-commands/undoable-actions/reset-element-style.ts
|
|
2460
|
-
var
|
|
2560
|
+
var import_editor_elements10 = require("@elementor/editor-elements");
|
|
2461
2561
|
var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
|
|
2462
2562
|
var import_editor_v1_adapters11 = require("@elementor/editor-v1-adapters");
|
|
2463
2563
|
var import_i18n4 = require("@wordpress/i18n");
|
|
@@ -2466,9 +2566,9 @@ var undoableResetElementStyle = () => (0, import_editor_v1_adapters11.undoable)(
|
|
|
2466
2566
|
do: ({ containers }) => {
|
|
2467
2567
|
return containers.map((container) => {
|
|
2468
2568
|
const elementId = container.model.get("id");
|
|
2469
|
-
const containerStyles = (0,
|
|
2569
|
+
const containerStyles = (0, import_editor_elements10.getElementStyles)(elementId);
|
|
2470
2570
|
Object.keys(containerStyles ?? {}).forEach(
|
|
2471
|
-
(styleId) => (0,
|
|
2571
|
+
(styleId) => (0, import_editor_elements10.deleteElementStyle)(elementId, styleId)
|
|
2472
2572
|
);
|
|
2473
2573
|
return containerStyles;
|
|
2474
2574
|
});
|
|
@@ -2484,7 +2584,7 @@ var undoableResetElementStyle = () => (0, import_editor_v1_adapters11.undoable)(
|
|
|
2484
2584
|
Object.entries(containerStyles ?? {}).forEach(([styleId, style]) => {
|
|
2485
2585
|
const [firstVariant] = style.variants;
|
|
2486
2586
|
const additionalVariants = style.variants.slice(1);
|
|
2487
|
-
(0,
|
|
2587
|
+
(0, import_editor_elements10.createElementStyle)({
|
|
2488
2588
|
elementId,
|
|
2489
2589
|
classesProp,
|
|
2490
2590
|
styleId,
|