@shop-os/modelkit 0.2.4 → 0.2.5

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/CHANGELOG.md CHANGED
@@ -9,6 +9,11 @@ header in the release PR.
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.2.5] - 2026-09-15
13
+
14
+ ### Changed
15
+ - `Catalog.list()` returns rows in picker order: `display.sortOrder` descending, rows without one after the ordered ones, then `label` ascending (case-insensitive), then `id`. pro-backend orders its query the same way. Before, the order was the insertion order of the primed rows (pro-backend heap order), so an edited row moved to the end of every picker. `compareCatalogOrder` and `sortCatalogRows` are exported from the root and `/catalog` entries for consumers that sort their own lists.
16
+
12
17
  ## [0.2.4] - 2026-09-15
13
18
 
14
19
  ### Fixed
package/dist/catalog.cjs CHANGED
@@ -30,6 +30,7 @@ __export(catalog_entry_exports, {
30
30
  OTHER_MODELS: () => OTHER_MODELS,
31
31
  TEXT_MODELS: () => TEXT_MODELS,
32
32
  VIDEO_MODELS: () => VIDEO_MODELS,
33
+ compareCatalogOrder: () => compareCatalogOrder,
33
34
  isModelKitError: () => isModelKitError,
34
35
  liveCatalog: () => liveCatalog,
35
36
  liveState: () => liveState,
@@ -39,7 +40,8 @@ __export(catalog_entry_exports, {
39
40
  resolveAudioOptions: () => resolveAudioOptions,
40
41
  resolveImageOptions: () => resolveImageOptions,
41
42
  resolveOptions: () => resolveOptions,
42
- resolveVideoOptions: () => resolveVideoOptions
43
+ resolveVideoOptions: () => resolveVideoOptions,
44
+ sortCatalogRows: () => sortCatalogRows
43
45
  });
44
46
  module.exports = __toCommonJS(catalog_entry_exports);
45
47
 
@@ -69,6 +71,22 @@ function isModelKitError(err) {
69
71
  return err instanceof ModelKitError;
70
72
  }
71
73
 
74
+ // src/catalog/order.ts
75
+ function compareCatalogOrder(a, b) {
76
+ const sa = a.display?.sortOrder;
77
+ const sb = b.display?.sortOrder;
78
+ if (sa !== void 0 && sb !== void 0 && sa !== sb) return sb - sa;
79
+ if (sa !== void 0 && sb === void 0) return -1;
80
+ if (sa === void 0 && sb !== void 0) return 1;
81
+ return compareText(a.label.toLowerCase(), b.label.toLowerCase()) || compareText(a.id, b.id);
82
+ }
83
+ function compareText(a, b) {
84
+ return a < b ? -1 : a > b ? 1 : 0;
85
+ }
86
+ function sortCatalogRows(rows) {
87
+ return [...rows].sort(compareCatalogOrder);
88
+ }
89
+
72
90
  // src/catalog/registry.ts
73
91
  var Catalog = class _Catalog {
74
92
  byId = /* @__PURE__ */ new Map();
@@ -125,11 +143,12 @@ var Catalog = class _Catalog {
125
143
  }
126
144
  return model;
127
145
  }
146
+ /** Rows in picker order: `display.sortOrder` descending, then label. See `compareCatalogOrder`. */
128
147
  list(filter = {}) {
129
148
  const lifecycles = filter.lifecycle ?? ["active"];
130
149
  return [...this.byId.values()].filter(
131
150
  (m) => (filter.type ? m.type === filter.type : true) && lifecycles.includes(m.lifecycle)
132
- );
151
+ ).sort(compareCatalogOrder);
133
152
  }
134
153
  /** Merge rows by id. Used for catalogOverride. */
135
154
  withOverrides(rows) {