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

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
@@ -3,6 +3,10 @@ import { z as z4 } from "@elementor/schema";
3
3
 
4
4
  // src/utils/create-prop-utils.ts
5
5
  import { z } from "@elementor/schema";
6
+ var SCHEMA_CACHE = /* @__PURE__ */ new Map();
7
+ function getPropSchemaFromCache(key) {
8
+ return SCHEMA_CACHE.get(key);
9
+ }
6
10
  function createPropUtils(key, valueSchema) {
7
11
  const schema = z.strictObject({
8
12
  $$type: z.literal(key),
@@ -37,13 +41,15 @@ function createPropUtils(key, valueSchema) {
37
41
  }
38
42
  return prop.value;
39
43
  }
40
- return {
44
+ const propUtil = {
41
45
  extract,
42
46
  isValid,
43
47
  create,
44
48
  schema,
45
49
  key
46
50
  };
51
+ SCHEMA_CACHE.set(key, propUtil);
52
+ return propUtil;
47
53
  }
48
54
  function createArrayPropUtils(key, valueSchema, overrideKey) {
49
55
  return createPropUtils(overrideKey || `${key}-array`, z.array(valueSchema));
@@ -518,6 +524,314 @@ var backdropFilterPropTypeUtil = createPropUtils(
518
524
  z46.array(cssFilterFunctionPropUtil.schema)
519
525
  );
520
526
 
527
+ // src/utils/adjust-llm-prop-value-schema.ts
528
+ var ensureNotNull = (v, fallback) => v === null ? fallback : v;
529
+ var adjustLlmPropValueSchema = (value, forceKey) => {
530
+ const clone = structuredClone(value);
531
+ if (clone && typeof clone === "object") {
532
+ if (Array.isArray(clone)) {
533
+ return clone.map((item) => adjustLlmPropValueSchema(item, forceKey));
534
+ }
535
+ const transformablePropValue = clone;
536
+ if (forceKey) {
537
+ transformablePropValue.$$type = forceKey;
538
+ }
539
+ if (!transformablePropValue.$$type) {
540
+ throw new Error("Missing $$type in property: " + JSON.stringify(transformablePropValue));
541
+ }
542
+ if (!("value" in transformablePropValue)) {
543
+ throw new Error("Missing value property in PropValue: " + JSON.stringify(transformablePropValue));
544
+ }
545
+ switch (transformablePropValue.$$type) {
546
+ case "size": {
547
+ const { value: rawSizePropValue } = transformablePropValue;
548
+ const unit = typeof rawSizePropValue.unit === "string" ? rawSizePropValue.unit : ensureNotNull(stringPropTypeUtil.extract(rawSizePropValue.unit), "px");
549
+ const size = typeof rawSizePropValue.size === "string" || typeof rawSizePropValue.size === "number" ? rawSizePropValue.size : ensureNotNull(
550
+ stringPropTypeUtil.extract(rawSizePropValue.size),
551
+ numberPropTypeUtil.extract(rawSizePropValue.size)
552
+ );
553
+ return {
554
+ $$type: "size",
555
+ value: {
556
+ unit,
557
+ size
558
+ }
559
+ };
560
+ }
561
+ }
562
+ if (typeof transformablePropValue.value === "object") {
563
+ if (Array.isArray(transformablePropValue.value)) {
564
+ transformablePropValue.value = adjustLlmPropValueSchema(
565
+ transformablePropValue.value,
566
+ void 0
567
+ );
568
+ } else {
569
+ const { value: objectValue } = transformablePropValue;
570
+ const clonedObject = clone;
571
+ clonedObject.value = {};
572
+ Object.keys(objectValue).forEach((key) => {
573
+ const childProp = objectValue[key];
574
+ clonedObject.value[key] = adjustLlmPropValueSchema(
575
+ childProp,
576
+ void 0
577
+ );
578
+ });
579
+ }
580
+ }
581
+ }
582
+ return clone;
583
+ };
584
+
585
+ // src/utils/llm-schema-to-props.ts
586
+ function jsonSchemaToPropType(schema, key = schema.key) {
587
+ const meta = {};
588
+ if (schema.description) {
589
+ meta.description = schema.description;
590
+ }
591
+ if (schema.anyOf && Array.isArray(schema.anyOf)) {
592
+ return convertJsonSchemaToUnionPropType(schema, meta);
593
+ }
594
+ if (schema.type === "object" && schema.properties) {
595
+ return convertJsonSchemaToObjectPropType(schema, meta, key);
596
+ }
597
+ if (schema.type === "array" && schema.items) {
598
+ return convertJsonSchemaToArrayPropType(schema, meta, key);
599
+ }
600
+ return convertJsonSchemaToPlainPropType(schema, meta, key);
601
+ }
602
+ function convertJsonSchemaToPlainPropType(schema, meta, key = schema.key) {
603
+ const settings = {};
604
+ let propKey = key || "string";
605
+ if (schema.type === "number") {
606
+ propKey = "number";
607
+ } else if (schema.type === "boolean") {
608
+ propKey = "boolean";
609
+ } else if (schema.type === "string") {
610
+ propKey = "string";
611
+ }
612
+ if (Array.isArray(schema.enum)) {
613
+ settings.enum = schema.enum;
614
+ }
615
+ return {
616
+ kind: "plain",
617
+ key: propKey,
618
+ settings,
619
+ meta
620
+ };
621
+ }
622
+ function convertJsonSchemaToUnionPropType(schema, meta) {
623
+ const propTypes = {};
624
+ if (!schema.anyOf || !Array.isArray(schema.anyOf)) {
625
+ throw new Error("Invalid anyOf schema");
626
+ }
627
+ for (const variantSchema of schema.anyOf) {
628
+ if (variantSchema.type === "object" && variantSchema.properties && variantSchema.properties.$$type && variantSchema.properties.value) {
629
+ const typeProperty = variantSchema.properties.$$type;
630
+ let typeKey;
631
+ if (typeProperty.enum && Array.isArray(typeProperty.enum) && typeProperty.enum.length > 0) {
632
+ typeKey = typeProperty.enum[0];
633
+ } else {
634
+ continue;
635
+ }
636
+ const valuePropType = convertJsonSchemaToPropType(variantSchema.properties.value);
637
+ propTypes[typeKey] = valuePropType;
638
+ }
639
+ }
640
+ return {
641
+ kind: "union",
642
+ prop_types: propTypes,
643
+ settings: {},
644
+ meta
645
+ };
646
+ }
647
+ function convertJsonSchemaToObjectPropType(schema, meta, key = schema.key) {
648
+ const shape = {};
649
+ if (!schema.properties) {
650
+ return {
651
+ kind: "object",
652
+ key,
653
+ shape: {},
654
+ settings: {},
655
+ meta
656
+ };
657
+ }
658
+ const requiredFields = Array.isArray(schema.required) ? schema.required : [];
659
+ for (const [propKey, propSchema] of Object.entries(schema.properties)) {
660
+ const subPropType = convertJsonSchemaToPropType(propSchema, key);
661
+ if (requiredFields.includes(propKey)) {
662
+ subPropType.settings = {
663
+ ...subPropType.settings,
664
+ required: true
665
+ };
666
+ }
667
+ shape[propKey] = subPropType;
668
+ }
669
+ return {
670
+ kind: "object",
671
+ key: key || "object",
672
+ shape,
673
+ settings: {},
674
+ meta
675
+ };
676
+ }
677
+ function convertJsonSchemaToArrayPropType(schema, meta, key = schema.key) {
678
+ if (!schema.items) {
679
+ throw new Error("Array schema must have items property");
680
+ }
681
+ const itemPropType = convertJsonSchemaToPropType(schema.items);
682
+ return {
683
+ kind: "array",
684
+ key: key || "array",
685
+ item_prop_type: itemPropType,
686
+ settings: {},
687
+ meta
688
+ };
689
+ }
690
+ function convertJsonSchemaToPropType(schema, key) {
691
+ return jsonSchemaToPropType(schema, key);
692
+ }
693
+
694
+ // src/utils/props-to-llm-schema.ts
695
+ function propTypeToJsonSchema(propType, key) {
696
+ const description = propType.meta?.description;
697
+ const schema = {};
698
+ if (description) {
699
+ schema.description = description;
700
+ }
701
+ if (key) {
702
+ schema.key = key;
703
+ }
704
+ switch (propType.kind) {
705
+ case "plain":
706
+ return convertPlainPropType(propType, schema);
707
+ case "union":
708
+ return convertUnionPropType(propType, schema);
709
+ case "object":
710
+ return convertObjectPropType(propType, schema);
711
+ case "array":
712
+ return convertArrayPropType(propType, schema);
713
+ default:
714
+ return convertPlainPropType(propType, schema);
715
+ }
716
+ return schema;
717
+ }
718
+ function convertPlainPropType(propType, baseSchema) {
719
+ const schema = { ...baseSchema };
720
+ schema.key = propType.key;
721
+ const key = propType.key.toLowerCase();
722
+ switch (key) {
723
+ case "number":
724
+ schema.type = "number";
725
+ break;
726
+ case "boolean":
727
+ schema.type = "boolean";
728
+ break;
729
+ default:
730
+ schema.type = "string";
731
+ }
732
+ if (Array.isArray(propType.settings?.enum)) {
733
+ schema.enum = propType.settings.enum;
734
+ }
735
+ return schema;
736
+ }
737
+ function convertUnionPropType(propType, baseSchema) {
738
+ const schema = structuredClone(baseSchema);
739
+ const propTypes = propType.prop_types || {};
740
+ const schemas = [];
741
+ for (const [typeKey, subPropType] of Object.entries(propTypes)) {
742
+ const subSchema = convertPropTypeToJsonSchema(subPropType);
743
+ schemas.push({
744
+ type: "object",
745
+ required: ["$$type", "value"],
746
+ properties: {
747
+ $$type: {
748
+ type: "string",
749
+ const: typeKey,
750
+ description: `Discriminator for union type variant: ${typeKey}`
751
+ },
752
+ value: subSchema
753
+ }
754
+ });
755
+ }
756
+ if (schemas.length > 0) {
757
+ schema.anyOf = schemas;
758
+ }
759
+ const propTypeDescription = propType.meta?.description;
760
+ if (propTypeDescription) {
761
+ schema.description = propTypeDescription;
762
+ }
763
+ return schema;
764
+ }
765
+ function convertObjectPropType(propType, baseSchema) {
766
+ const schema = structuredClone(baseSchema);
767
+ schema.type = "object";
768
+ schema.properties = {};
769
+ const required = [];
770
+ const shape = propType.shape || {};
771
+ for (const [key, subPropType] of Object.entries(shape)) {
772
+ const propSchema = convertPropTypeToJsonSchema(subPropType);
773
+ if (subPropType.settings?.required === true) {
774
+ required.push(key);
775
+ }
776
+ schema.properties[key] = propSchema;
777
+ }
778
+ if (required.length > 0) {
779
+ schema.required = required;
780
+ }
781
+ return schema;
782
+ }
783
+ function convertArrayPropType(propType, baseSchema) {
784
+ const schema = structuredClone(baseSchema);
785
+ schema.type = "array";
786
+ schema.key = propType.key;
787
+ const itemPropType = propType.item_prop_type;
788
+ if (itemPropType) {
789
+ schema.items = convertPropTypeToJsonSchema(itemPropType);
790
+ }
791
+ return schema;
792
+ }
793
+ function convertPropTypeToJsonSchema(propType) {
794
+ return propTypeToJsonSchema(propType);
795
+ }
796
+
797
+ // src/utils/is-transformable.ts
798
+ import { z as z47 } from "@elementor/schema";
799
+ var transformableSchema = z47.object({
800
+ $$type: z47.string(),
801
+ value: z47.any(),
802
+ disabled: z47.boolean().optional()
803
+ });
804
+ var isTransformable = (value) => {
805
+ return transformableSchema.safeParse(value).success;
806
+ };
807
+
808
+ // src/utils/filter-empty-values.ts
809
+ var filterEmptyValues = (value) => {
810
+ if (isEmpty(value)) {
811
+ return null;
812
+ }
813
+ if (Array.isArray(value)) {
814
+ return value.map(filterEmptyValues).filter((item) => !isEmpty(item));
815
+ }
816
+ if (typeof value === "object") {
817
+ return Object.fromEntries(
818
+ Object.entries(value).map(([key, val]) => [key, filterEmptyValues(val)]).filter(([, val]) => !isEmpty(val))
819
+ );
820
+ }
821
+ return value;
822
+ };
823
+ var isEmpty = (value) => {
824
+ if (value && isTransformable(value)) {
825
+ return isEmpty(value.value);
826
+ }
827
+ return isNullish(value) || isNullishArray(value) || isNullishObject(value);
828
+ };
829
+ var isNullish = (value) => value === null || value === void 0 || value === "";
830
+ var isNullishArray = (value) => Array.isArray(value) && value.every(isEmpty);
831
+ var isNullishObject = (value) => {
832
+ return typeof value === "object" && isNullishArray(Object.values(value));
833
+ };
834
+
521
835
  // src/utils/merge-props.ts
522
836
  function mergeProps(current, updates) {
523
837
  let props = {};
@@ -534,17 +848,6 @@ function mergeProps(current, updates) {
534
848
  return props;
535
849
  }
536
850
 
537
- // src/utils/is-transformable.ts
538
- import { z as z47 } from "@elementor/schema";
539
- var transformableSchema = z47.object({
540
- $$type: z47.string(),
541
- value: z47.any(),
542
- disabled: z47.boolean().optional()
543
- });
544
- var isTransformable = (value) => {
545
- return transformableSchema.safeParse(value).success;
546
- };
547
-
548
851
  // src/utils/prop-dependency-utils.ts
549
852
  function isDependencyMet(dependency, values) {
550
853
  if (!dependency?.terms.length) {
@@ -624,35 +927,16 @@ function isDependency(term) {
624
927
  return "relation" in term;
625
928
  }
626
929
 
627
- // src/utils/filter-empty-values.ts
628
- var filterEmptyValues = (value) => {
629
- if (isEmpty(value)) {
630
- return null;
631
- }
632
- if (Array.isArray(value)) {
633
- return value.map(filterEmptyValues).filter((item) => !isEmpty(item));
634
- }
635
- if (typeof value === "object") {
636
- return Object.fromEntries(
637
- Object.entries(value).map(([key, val]) => [key, filterEmptyValues(val)]).filter(([, val]) => !isEmpty(val))
638
- );
639
- }
640
- return value;
641
- };
642
- var isEmpty = (value) => {
643
- if (value && isTransformable(value)) {
644
- return isEmpty(value.value);
645
- }
646
- return isNullish(value) || isNullishArray(value) || isNullishObject(value);
647
- };
648
- var isNullish = (value) => value === null || value === void 0 || value === "";
649
- var isNullishArray = (value) => Array.isArray(value) && value.every(isEmpty);
650
- var isNullishObject = (value) => {
651
- return typeof value === "object" && isNullishArray(Object.values(value));
930
+ // src/index.ts
931
+ var Schema = {
932
+ jsonSchemaToPropType,
933
+ propTypeToJsonSchema,
934
+ adjustLlmPropValueSchema
652
935
  };
653
936
  export {
654
937
  CLASSES_PROP_KEY,
655
938
  DateTimePropTypeUtil,
939
+ Schema,
656
940
  backdropFilterPropTypeUtil,
657
941
  backgroundColorOverlayPropTypeUtil,
658
942
  backgroundGradientOverlayPropTypeUtil,
@@ -681,6 +965,7 @@ export {
681
965
  filterEmptyValues,
682
966
  filterPropTypeUtil,
683
967
  flexPropTypeUtil,
968
+ getPropSchemaFromCache,
684
969
  gradientColorStopPropTypeUtil,
685
970
  htmlPropTypeUtil,
686
971
  hueRotateFilterPropTypeUtil,