@elementor/editor-props 4.2.0-924 → 4.2.0-925

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -879,7 +879,13 @@ function convertJsonSchemaToPropType(schema, key) {
879
879
  }
880
880
 
881
881
  // src/utils/props-to-llm-schema.ts
882
- function propTypeToJsonSchema(propType) {
882
+ var DYNAMIC_PROP_TYPE_KEY = "dynamic";
883
+ var OVERRIDABLE_PROP_TYPE_KEY = "overridable";
884
+ var dynamicTagNamesResolver = null;
885
+ function setDynamicTagNamesResolver(resolver) {
886
+ dynamicTagNamesResolver = resolver;
887
+ }
888
+ function propTypeToJsonSchema(propType, suppressDynamic = false) {
883
889
  const description = propType.meta?.description;
884
890
  const schema = {};
885
891
  if (description) {
@@ -890,11 +896,11 @@ function propTypeToJsonSchema(propType) {
890
896
  }
891
897
  switch (propType.kind) {
892
898
  case "union":
893
- return convertUnionPropType(propType, schema);
899
+ return convertUnionPropType(propType, schema, suppressDynamic);
894
900
  case "object":
895
- return convertObjectPropType(propType, schema);
901
+ return convertObjectPropType(propType, schema, suppressDynamic);
896
902
  case "array":
897
- return convertArrayPropType(propType, schema);
903
+ return convertArrayPropType(propType, schema, suppressDynamic);
898
904
  default:
899
905
  return convertPlainPropType(propType, schema);
900
906
  }
@@ -935,16 +941,23 @@ function convertPlainPropType(propType, baseSchema) {
935
941
  };
936
942
  }
937
943
  }
938
- function convertUnionPropType(propType, baseSchema) {
944
+ function convertUnionPropType(propType, baseSchema, suppressDynamic) {
939
945
  const schema = structuredClone(baseSchema);
940
946
  const propTypes = propType.prop_types || {};
947
+ const offersDynamic = !suppressDynamic && Boolean(propTypes[DYNAMIC_PROP_TYPE_KEY]);
948
+ const suppressNestedDynamic = suppressDynamic || offersDynamic;
941
949
  const schemas = [];
942
950
  for (const [typeKey, subPropType] of Object.entries(propTypes)) {
943
- if (typeKey === "dynamic" || typeKey === "overridable") {
951
+ if (typeKey === OVERRIDABLE_PROP_TYPE_KEY) {
944
952
  continue;
945
953
  }
946
- const subSchema = convertPropTypeToJsonSchema(subPropType);
947
- schemas.push(subSchema);
954
+ if (typeKey === DYNAMIC_PROP_TYPE_KEY) {
955
+ if (offersDynamic) {
956
+ schemas.push(convertDynamicPropType(subPropType));
957
+ }
958
+ continue;
959
+ }
960
+ schemas.push(propTypeToJsonSchema(subPropType, suppressNestedDynamic));
948
961
  }
949
962
  if (schemas.length > 0) {
950
963
  schema.anyOf = schemas;
@@ -955,7 +968,34 @@ function convertUnionPropType(propType, baseSchema) {
955
968
  }
956
969
  return schema;
957
970
  }
958
- function convertObjectPropType(propType, baseSchema) {
971
+ function convertDynamicPropType(propType) {
972
+ const categories = Array.isArray(propType.settings?.categories) ? propType.settings.categories : [];
973
+ const allowedTagNames = dynamicTagNamesResolver?.(categories) ?? [];
974
+ return {
975
+ type: "object",
976
+ description: `Bind THIS value to a dynamic tag instead of a static value (this may be a nested field, e.g. an image's "src"). Look up the chosen tag in the "elementor://dynamic-tags" resource and populate "settings" exactly as its schema requires.`,
977
+ properties: {
978
+ $$type: { type: "string", const: DYNAMIC_PROP_TYPE_KEY },
979
+ value: {
980
+ type: "object",
981
+ properties: {
982
+ name: {
983
+ type: "string",
984
+ description: 'Dynamic tag name from "elementor://dynamic-tags".',
985
+ ...allowedTagNames.length ? { enum: allowedTagNames } : {}
986
+ },
987
+ settings: {
988
+ type: "object",
989
+ description: "Tag settings matching the chosen tag's schema in the resource."
990
+ }
991
+ },
992
+ required: ["name"]
993
+ }
994
+ },
995
+ required: ["$$type", "value"]
996
+ };
997
+ }
998
+ function convertObjectPropType(propType, baseSchema, suppressDynamic) {
959
999
  const schema = structuredClone(baseSchema);
960
1000
  schema.type = "object";
961
1001
  const internalStructure = {
@@ -975,7 +1015,7 @@ function convertObjectPropType(propType, baseSchema) {
975
1015
  const valueRequired = [];
976
1016
  const shape = propType.shape || {};
977
1017
  for (const [key, subPropType] of Object.entries(shape)) {
978
- const propSchema = propTypeToJsonSchema(subPropType);
1018
+ const propSchema = propTypeToJsonSchema(subPropType, suppressDynamic);
979
1019
  if (subPropType.settings?.required === true) {
980
1020
  valueRequired.push(key);
981
1021
  }
@@ -992,13 +1032,13 @@ function convertObjectPropType(propType, baseSchema) {
992
1032
  ...internalStructure
993
1033
  };
994
1034
  }
995
- function convertArrayPropType(propType, baseSchema) {
1035
+ function convertArrayPropType(propType, baseSchema, suppressDynamic) {
996
1036
  const schema = structuredClone(baseSchema);
997
1037
  schema.type = "object";
998
1038
  let items;
999
1039
  const itemPropType = propType.item_prop_type;
1000
1040
  if (itemPropType) {
1001
- items = convertPropTypeToJsonSchema(itemPropType);
1041
+ items = propTypeToJsonSchema(itemPropType, suppressDynamic);
1002
1042
  }
1003
1043
  schema.properties = {
1004
1044
  $$type: {
@@ -1012,9 +1052,6 @@ function convertArrayPropType(propType, baseSchema) {
1012
1052
  };
1013
1053
  return schema;
1014
1054
  }
1015
- function convertPropTypeToJsonSchema(propType) {
1016
- return propTypeToJsonSchema(propType);
1017
- }
1018
1055
  var nonConfigurablePropKeys = ["_cssid", "classes", "attributes"];
1019
1056
  function isPropKeyConfigurable(propKey, propType) {
1020
1057
  if (!nonConfigurablePropKeys.includes(propKey)) {
@@ -1363,7 +1400,8 @@ var Schema = {
1363
1400
  configurableKeys,
1364
1401
  validatePropValue,
1365
1402
  enrichWithIntention,
1366
- removeIntention
1403
+ removeIntention,
1404
+ setDynamicTagNamesResolver
1367
1405
  };
1368
1406
  export {
1369
1407
  CLASSES_PROP_KEY,