@elementor/editor-props 3.33.0-271 → 3.33.0-273

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
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  CLASSES_PROP_KEY: () => CLASSES_PROP_KEY,
24
24
  DateTimePropTypeUtil: () => DateTimePropTypeUtil,
25
+ Schema: () => Schema,
25
26
  backdropFilterPropTypeUtil: () => backdropFilterPropTypeUtil,
26
27
  backgroundColorOverlayPropTypeUtil: () => backgroundColorOverlayPropTypeUtil,
27
28
  backgroundGradientOverlayPropTypeUtil: () => backgroundGradientOverlayPropTypeUtil,
@@ -50,6 +51,7 @@ __export(index_exports, {
50
51
  filterEmptyValues: () => filterEmptyValues,
51
52
  filterPropTypeUtil: () => filterPropTypeUtil,
52
53
  flexPropTypeUtil: () => flexPropTypeUtil,
54
+ getPropSchemaFromCache: () => getPropSchemaFromCache,
53
55
  gradientColorStopPropTypeUtil: () => gradientColorStopPropTypeUtil,
54
56
  htmlPropTypeUtil: () => htmlPropTypeUtil,
55
57
  hueRotateFilterPropTypeUtil: () => hueRotateFilterPropTypeUtil,
@@ -90,6 +92,10 @@ var import_schema4 = require("@elementor/schema");
90
92
 
91
93
  // src/utils/create-prop-utils.ts
92
94
  var import_schema = require("@elementor/schema");
95
+ var SCHEMA_CACHE = /* @__PURE__ */ new Map();
96
+ function getPropSchemaFromCache(key) {
97
+ return SCHEMA_CACHE.get(key);
98
+ }
93
99
  function createPropUtils(key, valueSchema) {
94
100
  const schema = import_schema.z.strictObject({
95
101
  $$type: import_schema.z.literal(key),
@@ -124,13 +130,15 @@ function createPropUtils(key, valueSchema) {
124
130
  }
125
131
  return prop.value;
126
132
  }
127
- return {
133
+ const propUtil = {
128
134
  extract,
129
135
  isValid,
130
136
  create,
131
137
  schema,
132
138
  key
133
139
  };
140
+ SCHEMA_CACHE.set(key, propUtil);
141
+ return propUtil;
134
142
  }
135
143
  function createArrayPropUtils(key, valueSchema, overrideKey) {
136
144
  return createPropUtils(overrideKey || `${key}-array`, import_schema.z.array(valueSchema));
@@ -605,6 +613,314 @@ var backdropFilterPropTypeUtil = createPropUtils(
605
613
  import_schema46.z.array(cssFilterFunctionPropUtil.schema)
606
614
  );
607
615
 
616
+ // src/utils/adjust-llm-prop-value-schema.ts
617
+ var ensureNotNull = (v, fallback) => v === null ? fallback : v;
618
+ var adjustLlmPropValueSchema = (value, forceKey) => {
619
+ const clone = structuredClone(value);
620
+ if (clone && typeof clone === "object") {
621
+ if (Array.isArray(clone)) {
622
+ return clone.map((item) => adjustLlmPropValueSchema(item, forceKey));
623
+ }
624
+ const transformablePropValue = clone;
625
+ if (forceKey) {
626
+ transformablePropValue.$$type = forceKey;
627
+ }
628
+ if (!transformablePropValue.$$type) {
629
+ throw new Error("Missing $$type in property: " + JSON.stringify(transformablePropValue));
630
+ }
631
+ if (!("value" in transformablePropValue)) {
632
+ throw new Error("Missing value property in PropValue: " + JSON.stringify(transformablePropValue));
633
+ }
634
+ switch (transformablePropValue.$$type) {
635
+ case "size": {
636
+ const { value: rawSizePropValue } = transformablePropValue;
637
+ const unit = typeof rawSizePropValue.unit === "string" ? rawSizePropValue.unit : ensureNotNull(stringPropTypeUtil.extract(rawSizePropValue.unit), "px");
638
+ const size = typeof rawSizePropValue.size === "string" || typeof rawSizePropValue.size === "number" ? rawSizePropValue.size : ensureNotNull(
639
+ stringPropTypeUtil.extract(rawSizePropValue.size),
640
+ numberPropTypeUtil.extract(rawSizePropValue.size)
641
+ );
642
+ return {
643
+ $$type: "size",
644
+ value: {
645
+ unit,
646
+ size
647
+ }
648
+ };
649
+ }
650
+ }
651
+ if (typeof transformablePropValue.value === "object") {
652
+ if (Array.isArray(transformablePropValue.value)) {
653
+ transformablePropValue.value = adjustLlmPropValueSchema(
654
+ transformablePropValue.value,
655
+ void 0
656
+ );
657
+ } else {
658
+ const { value: objectValue } = transformablePropValue;
659
+ const clonedObject = clone;
660
+ clonedObject.value = {};
661
+ Object.keys(objectValue).forEach((key) => {
662
+ const childProp = objectValue[key];
663
+ clonedObject.value[key] = adjustLlmPropValueSchema(
664
+ childProp,
665
+ void 0
666
+ );
667
+ });
668
+ }
669
+ }
670
+ }
671
+ return clone;
672
+ };
673
+
674
+ // src/utils/llm-schema-to-props.ts
675
+ function jsonSchemaToPropType(schema, key = schema.key) {
676
+ const meta = {};
677
+ if (schema.description) {
678
+ meta.description = schema.description;
679
+ }
680
+ if (schema.anyOf && Array.isArray(schema.anyOf)) {
681
+ return convertJsonSchemaToUnionPropType(schema, meta);
682
+ }
683
+ if (schema.type === "object" && schema.properties) {
684
+ return convertJsonSchemaToObjectPropType(schema, meta, key);
685
+ }
686
+ if (schema.type === "array" && schema.items) {
687
+ return convertJsonSchemaToArrayPropType(schema, meta, key);
688
+ }
689
+ return convertJsonSchemaToPlainPropType(schema, meta, key);
690
+ }
691
+ function convertJsonSchemaToPlainPropType(schema, meta, key = schema.key) {
692
+ const settings = {};
693
+ let propKey = key || "string";
694
+ if (schema.type === "number") {
695
+ propKey = "number";
696
+ } else if (schema.type === "boolean") {
697
+ propKey = "boolean";
698
+ } else if (schema.type === "string") {
699
+ propKey = "string";
700
+ }
701
+ if (Array.isArray(schema.enum)) {
702
+ settings.enum = schema.enum;
703
+ }
704
+ return {
705
+ kind: "plain",
706
+ key: propKey,
707
+ settings,
708
+ meta
709
+ };
710
+ }
711
+ function convertJsonSchemaToUnionPropType(schema, meta) {
712
+ const propTypes = {};
713
+ if (!schema.anyOf || !Array.isArray(schema.anyOf)) {
714
+ throw new Error("Invalid anyOf schema");
715
+ }
716
+ for (const variantSchema of schema.anyOf) {
717
+ if (variantSchema.type === "object" && variantSchema.properties && variantSchema.properties.$$type && variantSchema.properties.value) {
718
+ const typeProperty = variantSchema.properties.$$type;
719
+ let typeKey;
720
+ if (typeProperty.enum && Array.isArray(typeProperty.enum) && typeProperty.enum.length > 0) {
721
+ typeKey = typeProperty.enum[0];
722
+ } else {
723
+ continue;
724
+ }
725
+ const valuePropType = convertJsonSchemaToPropType(variantSchema.properties.value);
726
+ propTypes[typeKey] = valuePropType;
727
+ }
728
+ }
729
+ return {
730
+ kind: "union",
731
+ prop_types: propTypes,
732
+ settings: {},
733
+ meta
734
+ };
735
+ }
736
+ function convertJsonSchemaToObjectPropType(schema, meta, key = schema.key) {
737
+ const shape = {};
738
+ if (!schema.properties) {
739
+ return {
740
+ kind: "object",
741
+ key,
742
+ shape: {},
743
+ settings: {},
744
+ meta
745
+ };
746
+ }
747
+ const requiredFields = Array.isArray(schema.required) ? schema.required : [];
748
+ for (const [propKey, propSchema] of Object.entries(schema.properties)) {
749
+ const subPropType = convertJsonSchemaToPropType(propSchema, key);
750
+ if (requiredFields.includes(propKey)) {
751
+ subPropType.settings = {
752
+ ...subPropType.settings,
753
+ required: true
754
+ };
755
+ }
756
+ shape[propKey] = subPropType;
757
+ }
758
+ return {
759
+ kind: "object",
760
+ key: key || "object",
761
+ shape,
762
+ settings: {},
763
+ meta
764
+ };
765
+ }
766
+ function convertJsonSchemaToArrayPropType(schema, meta, key = schema.key) {
767
+ if (!schema.items) {
768
+ throw new Error("Array schema must have items property");
769
+ }
770
+ const itemPropType = convertJsonSchemaToPropType(schema.items);
771
+ return {
772
+ kind: "array",
773
+ key: key || "array",
774
+ item_prop_type: itemPropType,
775
+ settings: {},
776
+ meta
777
+ };
778
+ }
779
+ function convertJsonSchemaToPropType(schema, key) {
780
+ return jsonSchemaToPropType(schema, key);
781
+ }
782
+
783
+ // src/utils/props-to-llm-schema.ts
784
+ function propTypeToJsonSchema(propType, key) {
785
+ const description = propType.meta?.description;
786
+ const schema = {};
787
+ if (description) {
788
+ schema.description = description;
789
+ }
790
+ if (key) {
791
+ schema.key = key;
792
+ }
793
+ switch (propType.kind) {
794
+ case "plain":
795
+ return convertPlainPropType(propType, schema);
796
+ case "union":
797
+ return convertUnionPropType(propType, schema);
798
+ case "object":
799
+ return convertObjectPropType(propType, schema);
800
+ case "array":
801
+ return convertArrayPropType(propType, schema);
802
+ default:
803
+ return convertPlainPropType(propType, schema);
804
+ }
805
+ return schema;
806
+ }
807
+ function convertPlainPropType(propType, baseSchema) {
808
+ const schema = { ...baseSchema };
809
+ schema.key = propType.key;
810
+ const key = propType.key.toLowerCase();
811
+ switch (key) {
812
+ case "number":
813
+ schema.type = "number";
814
+ break;
815
+ case "boolean":
816
+ schema.type = "boolean";
817
+ break;
818
+ default:
819
+ schema.type = "string";
820
+ }
821
+ if (Array.isArray(propType.settings?.enum)) {
822
+ schema.enum = propType.settings.enum;
823
+ }
824
+ return schema;
825
+ }
826
+ function convertUnionPropType(propType, baseSchema) {
827
+ const schema = structuredClone(baseSchema);
828
+ const propTypes = propType.prop_types || {};
829
+ const schemas = [];
830
+ for (const [typeKey, subPropType] of Object.entries(propTypes)) {
831
+ const subSchema = convertPropTypeToJsonSchema(subPropType);
832
+ schemas.push({
833
+ type: "object",
834
+ required: ["$$type", "value"],
835
+ properties: {
836
+ $$type: {
837
+ type: "string",
838
+ const: typeKey,
839
+ description: `Discriminator for union type variant: ${typeKey}`
840
+ },
841
+ value: subSchema
842
+ }
843
+ });
844
+ }
845
+ if (schemas.length > 0) {
846
+ schema.anyOf = schemas;
847
+ }
848
+ const propTypeDescription = propType.meta?.description;
849
+ if (propTypeDescription) {
850
+ schema.description = propTypeDescription;
851
+ }
852
+ return schema;
853
+ }
854
+ function convertObjectPropType(propType, baseSchema) {
855
+ const schema = structuredClone(baseSchema);
856
+ schema.type = "object";
857
+ schema.properties = {};
858
+ const required = [];
859
+ const shape = propType.shape || {};
860
+ for (const [key, subPropType] of Object.entries(shape)) {
861
+ const propSchema = convertPropTypeToJsonSchema(subPropType);
862
+ if (subPropType.settings?.required === true) {
863
+ required.push(key);
864
+ }
865
+ schema.properties[key] = propSchema;
866
+ }
867
+ if (required.length > 0) {
868
+ schema.required = required;
869
+ }
870
+ return schema;
871
+ }
872
+ function convertArrayPropType(propType, baseSchema) {
873
+ const schema = structuredClone(baseSchema);
874
+ schema.type = "array";
875
+ schema.key = propType.key;
876
+ const itemPropType = propType.item_prop_type;
877
+ if (itemPropType) {
878
+ schema.items = convertPropTypeToJsonSchema(itemPropType);
879
+ }
880
+ return schema;
881
+ }
882
+ function convertPropTypeToJsonSchema(propType) {
883
+ return propTypeToJsonSchema(propType);
884
+ }
885
+
886
+ // src/utils/is-transformable.ts
887
+ var import_schema47 = require("@elementor/schema");
888
+ var transformableSchema = import_schema47.z.object({
889
+ $$type: import_schema47.z.string(),
890
+ value: import_schema47.z.any(),
891
+ disabled: import_schema47.z.boolean().optional()
892
+ });
893
+ var isTransformable = (value) => {
894
+ return transformableSchema.safeParse(value).success;
895
+ };
896
+
897
+ // src/utils/filter-empty-values.ts
898
+ var filterEmptyValues = (value) => {
899
+ if (isEmpty(value)) {
900
+ return null;
901
+ }
902
+ if (Array.isArray(value)) {
903
+ return value.map(filterEmptyValues).filter((item) => !isEmpty(item));
904
+ }
905
+ if (typeof value === "object") {
906
+ return Object.fromEntries(
907
+ Object.entries(value).map(([key, val]) => [key, filterEmptyValues(val)]).filter(([, val]) => !isEmpty(val))
908
+ );
909
+ }
910
+ return value;
911
+ };
912
+ var isEmpty = (value) => {
913
+ if (value && isTransformable(value)) {
914
+ return isEmpty(value.value);
915
+ }
916
+ return isNullish(value) || isNullishArray(value) || isNullishObject(value);
917
+ };
918
+ var isNullish = (value) => value === null || value === void 0 || value === "";
919
+ var isNullishArray = (value) => Array.isArray(value) && value.every(isEmpty);
920
+ var isNullishObject = (value) => {
921
+ return typeof value === "object" && isNullishArray(Object.values(value));
922
+ };
923
+
608
924
  // src/utils/merge-props.ts
609
925
  function mergeProps(current, updates) {
610
926
  let props = {};
@@ -621,17 +937,6 @@ function mergeProps(current, updates) {
621
937
  return props;
622
938
  }
623
939
 
624
- // src/utils/is-transformable.ts
625
- var import_schema47 = require("@elementor/schema");
626
- var transformableSchema = import_schema47.z.object({
627
- $$type: import_schema47.z.string(),
628
- value: import_schema47.z.any(),
629
- disabled: import_schema47.z.boolean().optional()
630
- });
631
- var isTransformable = (value) => {
632
- return transformableSchema.safeParse(value).success;
633
- };
634
-
635
940
  // src/utils/prop-dependency-utils.ts
636
941
  function isDependencyMet(dependency, values) {
637
942
  if (!dependency?.terms.length) {
@@ -711,36 +1016,17 @@ function isDependency(term) {
711
1016
  return "relation" in term;
712
1017
  }
713
1018
 
714
- // src/utils/filter-empty-values.ts
715
- var filterEmptyValues = (value) => {
716
- if (isEmpty(value)) {
717
- return null;
718
- }
719
- if (Array.isArray(value)) {
720
- return value.map(filterEmptyValues).filter((item) => !isEmpty(item));
721
- }
722
- if (typeof value === "object") {
723
- return Object.fromEntries(
724
- Object.entries(value).map(([key, val]) => [key, filterEmptyValues(val)]).filter(([, val]) => !isEmpty(val))
725
- );
726
- }
727
- return value;
728
- };
729
- var isEmpty = (value) => {
730
- if (value && isTransformable(value)) {
731
- return isEmpty(value.value);
732
- }
733
- return isNullish(value) || isNullishArray(value) || isNullishObject(value);
734
- };
735
- var isNullish = (value) => value === null || value === void 0 || value === "";
736
- var isNullishArray = (value) => Array.isArray(value) && value.every(isEmpty);
737
- var isNullishObject = (value) => {
738
- return typeof value === "object" && isNullishArray(Object.values(value));
1019
+ // src/index.ts
1020
+ var Schema = {
1021
+ jsonSchemaToPropType,
1022
+ propTypeToJsonSchema,
1023
+ adjustLlmPropValueSchema
739
1024
  };
740
1025
  // Annotate the CommonJS export names for ESM import in node:
741
1026
  0 && (module.exports = {
742
1027
  CLASSES_PROP_KEY,
743
1028
  DateTimePropTypeUtil,
1029
+ Schema,
744
1030
  backdropFilterPropTypeUtil,
745
1031
  backgroundColorOverlayPropTypeUtil,
746
1032
  backgroundGradientOverlayPropTypeUtil,
@@ -769,6 +1055,7 @@ var isNullishObject = (value) => {
769
1055
  filterEmptyValues,
770
1056
  filterPropTypeUtil,
771
1057
  flexPropTypeUtil,
1058
+ getPropSchemaFromCache,
772
1059
  gradientColorStopPropTypeUtil,
773
1060
  htmlPropTypeUtil,
774
1061
  hueRotateFilterPropTypeUtil,