@symbo.ls/sdk 2.31.37 → 2.32.1

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.
@@ -704,6 +704,260 @@ var BaseService = class {
704
704
  }
705
705
  };
706
706
 
707
+ // src/utils/ordering.js
708
+ function isObjectLike(val) {
709
+ return val && typeof val === "object" && !Array.isArray(val);
710
+ }
711
+ function normalizePath(path) {
712
+ if (Array.isArray(path)) {
713
+ return path;
714
+ }
715
+ if (typeof path === "string") {
716
+ return [path];
717
+ }
718
+ return [];
719
+ }
720
+ function getParentPathsFromTuples(tuples = []) {
721
+ const seen = /* @__PURE__ */ new Set();
722
+ const parents = [];
723
+ const META_KEYS = /* @__PURE__ */ new Set([
724
+ "style",
725
+ "class",
726
+ "text",
727
+ "html",
728
+ "content",
729
+ "data",
730
+ "attr",
731
+ "state",
732
+ "scope",
733
+ "props",
734
+ "define",
735
+ "on",
736
+ "extend",
737
+ "extends",
738
+ "childExtend",
739
+ "childExtends",
740
+ "childProps",
741
+ "children",
742
+ "component",
743
+ "context",
744
+ "tag",
745
+ "key",
746
+ "__order",
747
+ "if"
748
+ ]);
749
+ for (let i = 0; i < tuples.length; i++) {
750
+ const tuple = tuples[i];
751
+ if (!Array.isArray(tuple) || tuple.length < 2) {
752
+ continue;
753
+ }
754
+ const path = normalizePath(tuple[1]);
755
+ if (!path.length) {
756
+ continue;
757
+ }
758
+ if (path[0] === "schema") {
759
+ continue;
760
+ }
761
+ const immediateParent = path.slice(0, -1);
762
+ if (immediateParent.length) {
763
+ const key = JSON.stringify(immediateParent);
764
+ if (!seen.has(key)) {
765
+ seen.add(key);
766
+ parents.push(immediateParent);
767
+ }
768
+ }
769
+ const last = path[path.length - 1];
770
+ if (META_KEYS.has(last) && path.length >= 2) {
771
+ const containerParent = path.slice(0, -2);
772
+ if (containerParent.length) {
773
+ const key2 = JSON.stringify(containerParent);
774
+ if (!seen.has(key2)) {
775
+ seen.add(key2);
776
+ parents.push(containerParent);
777
+ }
778
+ }
779
+ }
780
+ for (let j = 0; j < path.length; j++) {
781
+ const seg = path[j];
782
+ if (!META_KEYS.has(seg)) {
783
+ continue;
784
+ }
785
+ const containerParent2 = path.slice(0, j);
786
+ if (!containerParent2.length) {
787
+ continue;
788
+ }
789
+ const key3 = JSON.stringify(containerParent2);
790
+ if (!seen.has(key3)) {
791
+ seen.add(key3);
792
+ parents.push(containerParent2);
793
+ }
794
+ }
795
+ }
796
+ return parents;
797
+ }
798
+ function computeOrdersFromState(root, parentPaths = []) {
799
+ if (!root || typeof root.getByPath !== "function") {
800
+ return [];
801
+ }
802
+ const orders = [];
803
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
804
+ for (let i = 0; i < parentPaths.length; i++) {
805
+ const parentPath = parentPaths[i];
806
+ const obj = (() => {
807
+ try {
808
+ return root.getByPath(parentPath);
809
+ } catch {
810
+ return null;
811
+ }
812
+ })();
813
+ if (!isObjectLike(obj)) {
814
+ continue;
815
+ }
816
+ const keys = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
817
+ orders.push({ path: parentPath, keys });
818
+ }
819
+ return orders;
820
+ }
821
+ function normaliseSchemaCode(code) {
822
+ if (typeof code !== "string" || !code.length) {
823
+ return "";
824
+ }
825
+ return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
826
+ }
827
+ function parseExportedObject(code) {
828
+ const src = normaliseSchemaCode(code);
829
+ if (!src) {
830
+ return null;
831
+ }
832
+ const body = src.replace(/^\s*export\s+default\s*/u, "return ");
833
+ try {
834
+ return new Function(body)();
835
+ } catch {
836
+ return null;
837
+ }
838
+ }
839
+ function extractTopLevelKeysFromCode(code) {
840
+ const obj = parseExportedObject(code);
841
+ if (!obj || typeof obj !== "object") {
842
+ return [];
843
+ }
844
+ return Object.keys(obj);
845
+ }
846
+ function computeOrdersForTuples(root, tuples = []) {
847
+ const pendingChildrenByContainer = /* @__PURE__ */ new Map();
848
+ for (let i = 0; i < tuples.length; i++) {
849
+ const t = tuples[i];
850
+ if (!Array.isArray(t)) {
851
+ continue;
852
+ }
853
+ const [action, path] = t;
854
+ const p = normalizePath(path);
855
+ if (!Array.isArray(p) || p.length < 3) {
856
+ continue;
857
+ }
858
+ if (p[0] === "schema") {
859
+ continue;
860
+ }
861
+ const [typeName, containerKey, childKey] = p;
862
+ const containerPath = [typeName, containerKey];
863
+ const key = JSON.stringify(containerPath);
864
+ if (!pendingChildrenByContainer.has(key)) {
865
+ pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
866
+ }
867
+ if (action === "update" || action === "set") {
868
+ pendingChildrenByContainer.get(key).add(childKey);
869
+ }
870
+ }
871
+ const preferredOrderMap = /* @__PURE__ */ new Map();
872
+ for (let i = 0; i < tuples.length; i++) {
873
+ const t = tuples[i];
874
+ if (!Array.isArray(t)) {
875
+ continue;
876
+ }
877
+ const [action, path, value] = t;
878
+ const p = normalizePath(path);
879
+ if (action !== "update" || !Array.isArray(p) || p.length < 3) {
880
+ continue;
881
+ }
882
+ if (p[0] !== "schema") {
883
+ continue;
884
+ }
885
+ const [, type, key] = p;
886
+ const containerPath = [type, key];
887
+ const uses = value && Array.isArray(value.uses) ? value.uses : null;
888
+ const code = value && value.code;
889
+ const obj = (() => {
890
+ try {
891
+ return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
892
+ } catch {
893
+ return null;
894
+ }
895
+ })();
896
+ if (!obj) {
897
+ continue;
898
+ }
899
+ const present = new Set(Object.keys(obj));
900
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
901
+ const codeKeys = extractTopLevelKeysFromCode(code);
902
+ let resolved = [];
903
+ const pendingKey = JSON.stringify(containerPath);
904
+ const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
905
+ const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
906
+ if (Array.isArray(codeKeys) && codeKeys.length) {
907
+ resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
908
+ }
909
+ if (Array.isArray(uses) && uses.length) {
910
+ for (let u = 0; u < uses.length; u++) {
911
+ const keyName = uses[u];
912
+ if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
913
+ resolved.push(keyName);
914
+ }
915
+ }
916
+ }
917
+ if (pendingChildren.size) {
918
+ for (const child of pendingChildren) {
919
+ if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
920
+ resolved.push(child);
921
+ }
922
+ }
923
+ }
924
+ if (resolved.length) {
925
+ preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
926
+ }
927
+ }
928
+ const parents = getParentPathsFromTuples(tuples);
929
+ const orders = [];
930
+ const seen = /* @__PURE__ */ new Set();
931
+ preferredOrderMap.forEach((v) => {
932
+ const k = JSON.stringify(v.path);
933
+ if (!seen.has(k)) {
934
+ seen.add(k);
935
+ orders.push(v);
936
+ }
937
+ });
938
+ const fallbackOrders = computeOrdersFromState(root, parents);
939
+ for (let i = 0; i < fallbackOrders.length; i++) {
940
+ const v = fallbackOrders[i];
941
+ const k = JSON.stringify(v.path);
942
+ if (seen.has(k)) {
943
+ continue;
944
+ }
945
+ const pending = pendingChildrenByContainer.get(k);
946
+ if (pending && pending.size) {
947
+ const existing = new Set(v.keys);
948
+ for (const child of pending) {
949
+ if (existing.has(child)) {
950
+ continue;
951
+ }
952
+ v.keys.push(child);
953
+ }
954
+ }
955
+ seen.add(k);
956
+ orders.push(v);
957
+ }
958
+ return orders;
959
+ }
960
+
707
961
  // src/services/ProjectService.js
708
962
  var ProjectService = class extends BaseService {
709
963
  // ==================== PROJECT METHODS ====================
@@ -1236,6 +1490,8 @@ var ProjectService = class extends BaseService {
1236
1490
  throw new Error("Changes must be an array");
1237
1491
  }
1238
1492
  const { message, branch = "main", type = "patch" } = options;
1493
+ const state = this._context && this._context.state;
1494
+ const derivedOrders = options.orders || (state ? computeOrdersForTuples(state, changes) : []);
1239
1495
  try {
1240
1496
  const response = await this._request(`/projects/${projectId}/changes`, {
1241
1497
  method: "POST",
@@ -1243,7 +1499,8 @@ var ProjectService = class extends BaseService {
1243
1499
  changes,
1244
1500
  message,
1245
1501
  branch,
1246
- type
1502
+ type,
1503
+ ...derivedOrders && derivedOrders.length ? { orders: derivedOrders } : {}
1247
1504
  }),
1248
1505
  methodName: "applyProjectChanges"
1249
1506
  });
@@ -948,8 +948,8 @@ var ScreenshotService = class extends BaseService {
948
948
  waitAfterRecreateMs = 2e4,
949
949
  recreate = {
950
950
  process_pages: true,
951
- process_components: true,
952
- process_descriptions: true,
951
+ process_components: false,
952
+ process_descriptions: false,
953
953
  force: false,
954
954
  priority: 5
955
955
  },