@modelform/react-native 0.1.1 → 0.3.0

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.
@@ -483,6 +483,32 @@ var GRID_COLUMNS = 24;
483
483
  var CELL_HEIGHT = 30;
484
484
  var CELL_MARGIN = 8;
485
485
  var gridUnitsToPx = (h) => h * CELL_HEIGHT + (h - 1) * CELL_MARGIN;
486
+ var gridOffsetPx = (y) => y * (CELL_HEIGHT + CELL_MARGIN);
487
+ var overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
488
+ function compactGrid(boxes, fixed2 = /* @__PURE__ */ new Set()) {
489
+ const snapped = boxes.map((b) => {
490
+ const w = Math.min(GRID_COLUMNS, Math.max(1, Math.round(b.x + b.w) - Math.round(b.x)));
491
+ const x = Math.min(GRID_COLUMNS - w, Math.max(0, Math.round(b.x)));
492
+ return { x, y: Math.max(0, b.y), w, h: Math.max(1, Math.round(b.h)) };
493
+ });
494
+ const out = new Array(boxes.length);
495
+ const placed = [];
496
+ for (const i of fixed2) {
497
+ if (!snapped[i]) continue;
498
+ out[i] = { ...snapped[i], y: Math.round(snapped[i].y) };
499
+ placed.push(out[i]);
500
+ }
501
+ const order = snapped.map((_, i) => i).filter((i) => !fixed2.has(i)).sort((a, b) => snapped[a].y - snapped[b].y || snapped[a].x - snapped[b].x || a - b);
502
+ for (const i of order) {
503
+ const box = { ...snapped[i], y: Math.floor(snapped[i].y) };
504
+ box.y = Math.min(box.y, Math.max(0, ...placed.map((p) => p.y + p.h)));
505
+ while (box.y > 0 && !placed.some((p) => overlaps({ ...box, y: box.y - 1 }, p))) box.y--;
506
+ for (let hit = placed.find((p) => overlaps(box, p)); hit; hit = placed.find((p) => overlaps(box, p))) box.y = hit.y + hit.h;
507
+ out[i] = box;
508
+ placed.push(box);
509
+ }
510
+ return out;
511
+ }
486
512
  var isRow = (p) => p.type === "row";
487
513
  var byPosition = (a, b) => a.gridPos.y - b.gridPos.y || a.gridPos.x - b.gridPos.x;
488
514
  function layoutDashboard(dashboard, mode = "phone", repeat2) {
@@ -506,12 +532,15 @@ function layoutDashboard(dashboard, mode = "phone", repeat2) {
506
532
  children: s.children.map((c) => ({ ...c, scopedVars: { ...c.scopedVars, ...scoped } }))
507
533
  };
508
534
  });
509
- }).map((s) => ({
510
- key: s.key,
511
- row: s.row,
512
- collapsed: !!_optionalChain([s, 'access', _51 => _51.row, 'optionalAccess', _52 => _52.collapsed]),
513
- rows: packRows(expandPanelRepeats(s.children, repeat2).sort(byPosition), mode)
514
- }));
535
+ }).map((s) => {
536
+ const panels = expandPanelRepeats(s.children, repeat2).sort(byPosition);
537
+ return { key: s.key, row: s.row, collapsed: !!_optionalChain([s, 'access', _51 => _51.row, 'optionalAccess', _52 => _52.collapsed]), rows: packRows(panels, mode), grid: placeOnGrid(panels) };
538
+ });
539
+ }
540
+ function placeOnGrid(panels) {
541
+ const boxes = compactGrid(panels.map((p) => p.gridPos));
542
+ const cells = panels.map((panel, i) => ({ key: panelKey(panel), panel, span: boxes[i].w, ...boxes[i] }));
543
+ return { cells, h: Math.max(0, ...boxes.map((b) => b.y + b.h)) };
515
544
  }
516
545
  function repeatOptions(name, ctx) {
517
546
  const value = ctx.values[name];
@@ -8068,11 +8097,28 @@ function resolveUrl(base, rel) {
8068
8097
  }
8069
8098
  return origin + out.join("/");
8070
8099
  }
8071
- var defaultFetchJson = async (url, options) => {
8072
- const res = await fetch(url, { headers: { Accept: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _219 => _219.accept]), () => ( "application/json")) }, cache: "no-store" });
8073
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
8074
- return JSON.parse(await res.text());
8075
- };
8100
+ function httpFetchJson(options = {}) {
8101
+ const seen = /* @__PURE__ */ new Map();
8102
+ return async (url, { accept = "application/json", signal } = {}) => {
8103
+ const extra = await _asyncNullishCoalesce(await _optionalChain([options, 'access', _219 => _219.headers, 'optionalCall', _220 => _220()]), async () => ( {}));
8104
+ const key = JSON.stringify([url, accept, extra]);
8105
+ const last = seen.get(key);
8106
+ const get = (etag2) => fetch(url, { headers: { Accept: accept, ...extra, ...etag2 && { "If-None-Match": etag2 } }, cache: "no-store", signal });
8107
+ const res = await get(_optionalChain([last, 'optionalAccess', _221 => _221.etag])).catch((e) => {
8108
+ if (!last || _optionalChain([signal, 'optionalAccess', _222 => _222.aborted])) throw e;
8109
+ seen.delete(key);
8110
+ return get();
8111
+ });
8112
+ if (res.status === 304 && last) return last.json;
8113
+ if (!res.ok) throw new Error(_nullishCoalesce(_optionalChain([options, 'access', _223 => _223.httpError, 'optionalCall', _224 => _224(res.status)]), () => ( `HTTP ${res.status}`)));
8114
+ const json = JSON.parse(await res.text());
8115
+ const etag = res.headers.get("ETag");
8116
+ if (etag) seen.set(key, { etag, json });
8117
+ else seen.delete(key);
8118
+ return json;
8119
+ };
8120
+ }
8121
+ var defaultFetchJson = httpFetchJson();
8076
8122
  var fileName = (url) => url.replace(/[?#].*$/, "").split("/").pop() || url;
8077
8123
  var BUNDLE_TYPE = "application/vnd.modelform.bundle+json";
8078
8124
  var BUNDLE_ACCEPT = `${BUNDLE_TYPE}, application/json;q=0.9`;
@@ -8085,7 +8131,7 @@ function bundleRoot(manifestUrl, manifestPath) {
8085
8131
  return bare.endsWith(manifestPath) ? bare.slice(0, bare.length - manifestPath.length) : bare.replace(/[^/]*$/, "");
8086
8132
  }
8087
8133
  var NOT_IN_BUNDLE = "not found in the config";
8088
- async function assembleFromResponse(url, response, fetchJson = defaultFetchJson) {
8134
+ async function assembleFromResponse(url, response, fetchJson = defaultFetchJson, signal) {
8089
8135
  const root = bundleRoot(url, response.manifest);
8090
8136
  const file = fileName(url);
8091
8137
  const parse3 = (path) => {
@@ -8103,7 +8149,7 @@ async function assembleFromResponse(url, response, fetchJson = defaultFetchJson)
8103
8149
  manifest,
8104
8150
  async (ref) => {
8105
8151
  const abs = resolveUrl(url, ref).replace(/[?#].*$/, "");
8106
- return abs.startsWith(root) ? parse3(abs.slice(root.length)) : fetchJson(resolveUrl(url, ref));
8152
+ return abs.startsWith(root) ? parse3(abs.slice(root.length)) : fetchJson(resolveUrl(url, ref), { signal });
8107
8153
  },
8108
8154
  file
8109
8155
  );
@@ -8131,18 +8177,35 @@ async function assembleBundle(manifest, load, file = "manifest") {
8131
8177
  issues.push(...validateBundle(bundle, file));
8132
8178
  return issues.some((i) => i.severity === "error") ? { issues } : { bundle, issues };
8133
8179
  }
8134
- async function fetchBundle(url, fetchJson = defaultFetchJson) {
8180
+ async function fetchBundle(url, fetchJson = defaultFetchJson, signal) {
8135
8181
  let manifest;
8136
8182
  try {
8137
- manifest = await fetchJson(url, { accept: BUNDLE_ACCEPT });
8183
+ manifest = await fetchJson(url, { accept: BUNDLE_ACCEPT, signal });
8138
8184
  } catch (e) {
8139
- return { issues: [{ severity: "error", path: fileName(url), message: e.message }] };
8185
+ return { issues: [{ severity: "error", path: fileName(url), message: e.message }], ...!(e instanceof SyntaxError) && { unreachable: true } };
8140
8186
  }
8141
- if (isBundleResponse(manifest)) return assembleFromResponse(url, manifest, fetchJson);
8142
- return assembleBundle(manifest, (path) => fetchJson(resolveUrl(url, path)), fileName(url));
8187
+ if (isBundleResponse(manifest)) return assembleFromResponse(url, manifest, fetchJson, signal);
8188
+ return assembleBundle(manifest, (path) => fetchJson(resolveUrl(url, path), { signal }), fileName(url));
8143
8189
  }
8190
+ function revalidateBundle(bundle) {
8191
+ try {
8192
+ const { manifest } = bundle;
8193
+ if (validateManifest(manifest).length) return void 0;
8194
+ const documents = {};
8195
+ for (const id of Object.keys(manifest.documents)) {
8196
+ const { dashboard } = prepareDashboard(bundle.documents[id], id);
8197
+ if (!dashboard) return void 0;
8198
+ documents[id] = dashboard;
8199
+ }
8200
+ const checked = { manifest, documents };
8201
+ return validateBundle(checked).some((i) => i.severity === "error") ? void 0 : checked;
8202
+ } catch (e12) {
8203
+ return void 0;
8204
+ }
8205
+ }
8206
+ var DEFAULT_TIMEOUT_MS = 15e3;
8144
8207
  var ConfigLoader = (_class2 = class {
8145
- constructor(options) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);
8208
+ constructor(options) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);
8146
8209
  this.options = options;
8147
8210
  const { fallback, url } = options;
8148
8211
  this.snapshot = { bundle: fallback, source: fallback ? "bundled" : "none", url, loading: !!url, issues: [] };
@@ -8153,57 +8216,85 @@ var ConfigLoader = (_class2 = class {
8153
8216
 
8154
8217
 
8155
8218
 
8219
+
8220
+ __init5() {this.disposed = false}
8156
8221
  get state() {
8157
8222
  return this.snapshot;
8158
8223
  }
8159
- __init5() {this.subscribe = (listener) => {
8224
+ __init6() {this.subscribe = (listener) => {
8160
8225
  this.listeners.add(listener);
8161
8226
  return () => {
8162
8227
  this.listeners.delete(listener);
8163
8228
  };
8164
8229
  }}
8165
- __init6() {this.getSnapshot = () => this.snapshot}
8166
- /** Loads the cached copy (if it was fetched from the same URL), then fetches. */
8230
+ __init7() {this.getSnapshot = () => this.snapshot}
8231
+ /** Loads the cached copy (if it was fetched from the same URL and still checks out), then fetches. */
8167
8232
  async start() {
8168
8233
  const { url, cache: cache2 } = this.options;
8169
8234
  if (!url) return;
8170
- const cached = await _optionalChain([cache2, 'optionalAccess', _220 => _220.read, 'call', _221 => _221(), 'access', _222 => _222.catch, 'call', _223 => _223(() => null)]);
8171
- if (_optionalChain([cached, 'optionalAccess', _224 => _224.url]) === url && !this.snapshot.fetchedAt) {
8172
- this.lastJson = JSON.stringify(cached.bundle);
8173
- this.set({ bundle: cached.bundle, source: "cache", fetchedAt: cached.fetchedAt, revision: cached.revision });
8235
+ const cached = await _optionalChain([cache2, 'optionalAccess', _225 => _225.read, 'call', _226 => _226(), 'access', _227 => _227.catch, 'call', _228 => _228(() => null)]);
8236
+ const bundle = _optionalChain([cached, 'optionalAccess', _229 => _229.url]) === url ? revalidateBundle(cached.bundle) : void 0;
8237
+ if (cached && bundle && !this.snapshot.fetchedAt) {
8238
+ this.lastJson = JSON.stringify(bundle);
8239
+ this.set({ bundle, source: "cache", fetchedAt: cached.fetchedAt, revision: cached.revision });
8174
8240
  }
8175
8241
  await this.refresh();
8176
8242
  }
8177
8243
  /** Fetches now. Concurrent calls share one fetch. Only notifies listeners when something changed. */
8178
8244
  refresh() {
8179
- const { url, cache: cache2, fetchJson } = this.options;
8180
- if (!url) return Promise.resolve();
8245
+ const { url, cache: cache2, fetchJson, timeoutMs = DEFAULT_TIMEOUT_MS } = this.options;
8246
+ if (!url || this.disposed) return Promise.resolve();
8181
8247
  this.inflight ??= (async () => {
8248
+ const controller = new AbortController();
8249
+ this.controller = controller;
8250
+ let timer;
8251
+ const abandoned = new Promise((resolve) => {
8252
+ const fail = (message) => resolve({ issues: [{ severity: "error", path: fileName(url), message }], unreachable: true });
8253
+ timer = setTimeout(() => {
8254
+ fail(`no answer in ${timeoutMs / 1e3}s`);
8255
+ controller.abort();
8256
+ }, timeoutMs);
8257
+ controller.signal.addEventListener("abort", () => fail("cancelled"));
8258
+ });
8182
8259
  try {
8183
- const { bundle, issues, revision } = await fetchBundle(url, fetchJson);
8260
+ const result = await Promise.race([fetchBundle(url, fetchJson, controller.signal), abandoned]);
8261
+ if (this.disposed) return;
8262
+ const { bundle, issues, revision, unreachable } = result;
8184
8263
  if (!bundle) {
8185
8264
  const errors = issues.filter((i) => i.severity === "error").length;
8186
- return this.set({ loading: false, error: errors === 1 ? "1 error" : `${errors} errors`, issues });
8265
+ const error = unreachable ? _optionalChain([issues, 'access', _230 => _230[0], 'optionalAccess', _231 => _231.message]) : errors === 1 ? "1 error" : `${errors} errors`;
8266
+ return this.set(
8267
+ { loading: false, error, unreachable: !!unreachable, issues },
8268
+ this.snapshot.loading || error !== this.snapshot.error || !!unreachable !== !!this.snapshot.unreachable || !sameIssues(issues, this.snapshot.issues)
8269
+ );
8187
8270
  }
8188
8271
  const json = JSON.stringify(bundle);
8189
8272
  const changed = json !== this.lastJson;
8190
8273
  this.lastJson = json;
8191
8274
  const fetchedAt = Date.now();
8192
- if (changed || revision !== this.snapshot.revision) _optionalChain([cache2, 'optionalAccess', _225 => _225.write, 'call', _226 => _226({ url, fetchedAt, bundle, revision }), 'access', _227 => _227.catch, 'call', _228 => _228(() => {
8275
+ if (changed || revision !== this.snapshot.revision) _optionalChain([cache2, 'optionalAccess', _232 => _232.write, 'call', _233 => _233({ url, fetchedAt, bundle, revision }), 'access', _234 => _234.catch, 'call', _235 => _235(() => {
8193
8276
  })]);
8194
8277
  this.set(
8195
- { ...changed && { bundle }, source: "remote", fetchedAt, revision, loading: false, error: void 0, issues },
8278
+ { ...changed && { bundle }, source: "remote", fetchedAt, revision, loading: false, error: void 0, unreachable: void 0, issues },
8196
8279
  changed || revision !== this.snapshot.revision || this.snapshot.source !== "remote" || !!this.snapshot.error || this.snapshot.loading || !sameIssues(issues, this.snapshot.issues)
8197
8280
  );
8198
8281
  } finally {
8282
+ clearTimeout(timer);
8283
+ if (this.controller === controller) this.controller = void 0;
8199
8284
  this.inflight = void 0;
8200
8285
  }
8201
8286
  })();
8202
8287
  return this.inflight;
8203
8288
  }
8289
+ /** Stops the loader: cancels a fetch in flight, and nothing it does afterwards changes the state or the cache. */
8290
+ dispose() {
8291
+ this.disposed = true;
8292
+ _optionalChain([this, 'access', _236 => _236.controller, 'optionalAccess', _237 => _237.abort, 'call', _238 => _238()]);
8293
+ this.listeners.clear();
8294
+ }
8204
8295
  /** `notify: false` drops the patch, so the snapshot only changes when listeners hear about it. */
8205
8296
  set(patch, notify = true) {
8206
- if (!notify) return;
8297
+ if (!notify || this.disposed) return;
8207
8298
  this.snapshot = { ...this.snapshot, ...patch };
8208
8299
  this.listeners.forEach((l) => l());
8209
8300
  }
@@ -8219,7 +8310,7 @@ function tabIdFor(title, taken) {
8219
8310
  }
8220
8311
  function screenOfType(type, from, docs) {
8221
8312
  const shown = from ? screenDocuments(from) : [];
8222
- const firstOf = (ids) => _nullishCoalesce(_nullishCoalesce(_optionalChain([shown, 'access', _229 => _229.find, 'call', _230 => _230((d) => ids.includes(d.id)), 'optionalAccess', _231 => _231.id]), () => ( ids[0])), () => ( ""));
8313
+ const firstOf = (ids) => _nullishCoalesce(_nullishCoalesce(_optionalChain([shown, 'access', _239 => _239.find, 'call', _240 => _240((d) => ids.includes(d.id)), 'optionalAccess', _241 => _241.id]), () => ( ids[0])), () => ( ""));
8223
8314
  switch (type) {
8224
8315
  case "dashboard":
8225
8316
  return { type, dashboard: firstOf(docs.dashboards) };
@@ -8232,7 +8323,7 @@ function screenOfType(type, from, docs) {
8232
8323
  }
8233
8324
  }
8234
8325
  function screenDocuments(screen) {
8235
- switch (_optionalChain([screen, 'optionalAccess', _232 => _232.type])) {
8326
+ switch (_optionalChain([screen, 'optionalAccess', _242 => _242.type])) {
8236
8327
  case "dashboard":
8237
8328
  return [{ id: screen.dashboard, kind: "dashboard" }];
8238
8329
  case "forms":
@@ -9647,8 +9738,8 @@ function removeNode(text, path) {
9647
9738
  const tree = parseTree2(text);
9648
9739
  const value = tree && findNodeAtLocation2(tree, path);
9649
9740
  if (!value) return text;
9650
- const node = _optionalChain([value, 'access', _233 => _233.parent, 'optionalAccess', _234 => _234.type]) === "property" ? value.parent : value;
9651
- const siblings = _nullishCoalesce(_optionalChain([node, 'access', _235 => _235.parent, 'optionalAccess', _236 => _236.children]), () => ( []));
9741
+ const node = _optionalChain([value, 'access', _243 => _243.parent, 'optionalAccess', _244 => _244.type]) === "property" ? value.parent : value;
9742
+ const siblings = _nullishCoalesce(_optionalChain([node, 'access', _245 => _245.parent, 'optionalAccess', _246 => _246.children]), () => ( []));
9652
9743
  const i = siblings.indexOf(node);
9653
9744
  const next = siblings[i + 1];
9654
9745
  const prev = siblings[i - 1];
@@ -9719,7 +9810,7 @@ function parseManifest(text) {
9719
9810
  let value;
9720
9811
  try {
9721
9812
  value = JSON.parse(text);
9722
- } catch (e12) {
9813
+ } catch (e13) {
9723
9814
  throw new Error("The manifest isn\u2019t valid JSON");
9724
9815
  }
9725
9816
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The manifest isn\u2019t an object");
@@ -9731,20 +9822,20 @@ function removeDocumentFromManifest(text, id) {
9731
9822
  const edits = [];
9732
9823
  const removedTabs = [];
9733
9824
  for (let i = tabs.length - 1; i >= 0; i--) {
9734
- const screen = _optionalChain([tabs, 'access', _237 => _237[i], 'optionalAccess', _238 => _238.screen]);
9825
+ const screen = _optionalChain([tabs, 'access', _247 => _247[i], 'optionalAccess', _248 => _248.screen]);
9735
9826
  const at = ["tabs", i, "screen"];
9736
9827
  const removeTab = () => {
9737
9828
  edits.push({ path: ["tabs", i], remove: true });
9738
9829
  removedTabs.unshift(_nullishCoalesce(tabs[i].title, () => ( tabs[i].id)));
9739
9830
  };
9740
- if (_optionalChain([screen, 'optionalAccess', _239 => _239.type]) === "dashboard" && screen.dashboard === id) removeTab();
9741
- else if (_optionalChain([screen, 'optionalAccess', _240 => _240.type]) === "forms" && Array.isArray(screen.forms) && screen.forms.includes(id)) {
9831
+ if (_optionalChain([screen, 'optionalAccess', _249 => _249.type]) === "dashboard" && screen.dashboard === id) removeTab();
9832
+ else if (_optionalChain([screen, 'optionalAccess', _250 => _250.type]) === "forms" && Array.isArray(screen.forms) && screen.forms.includes(id)) {
9742
9833
  if (screen.forms.every((f) => f === id)) removeTab();
9743
9834
  else for (let j = screen.forms.length - 1; j >= 0; j--) if (screen.forms[j] === id) edits.push({ path: [...at, "forms", j], remove: true });
9744
- } else if (_optionalChain([screen, 'optionalAccess', _241 => _241.type]) === "menu" && Array.isArray(screen.items))
9835
+ } else if (_optionalChain([screen, 'optionalAccess', _251 => _251.type]) === "menu" && Array.isArray(screen.items))
9745
9836
  for (let j = screen.items.length - 1; j >= 0; j--) {
9746
9837
  const item = screen.items[j];
9747
- if (_optionalChain([item, 'optionalAccess', _242 => _242.dashboard]) === id || _optionalChain([item, 'optionalAccess', _243 => _243.form]) === id) edits.push({ path: [...at, "items", j], remove: true });
9838
+ if (_optionalChain([item, 'optionalAccess', _252 => _252.dashboard]) === id || _optionalChain([item, 'optionalAccess', _253 => _253.form]) === id) edits.push({ path: [...at, "items", j], remove: true });
9748
9839
  }
9749
9840
  }
9750
9841
  if (tabs.length && removedTabs.length === tabs.length) throw new Error(`Every tab shows only "${id}". Add another tab first`);
@@ -9757,21 +9848,21 @@ function renameDocumentInManifest(text, from, to, path) {
9757
9848
  if (to !== from && to in manifest.documents) throw new Error(`There\u2019s already a document "${to}"`);
9758
9849
  const edits = [];
9759
9850
  (Array.isArray(manifest.tabs) ? manifest.tabs : []).forEach((tab, i) => {
9760
- const screen = _optionalChain([tab, 'optionalAccess', _244 => _244.screen]);
9851
+ const screen = _optionalChain([tab, 'optionalAccess', _254 => _254.screen]);
9761
9852
  const at = ["tabs", i, "screen"];
9762
- if (_optionalChain([screen, 'optionalAccess', _245 => _245.type]) === "dashboard" && screen.dashboard === from) edits.push({ path: [...at, "dashboard"], value: to });
9763
- if (_optionalChain([screen, 'optionalAccess', _246 => _246.type]) === "forms" && Array.isArray(screen.forms))
9853
+ if (_optionalChain([screen, 'optionalAccess', _255 => _255.type]) === "dashboard" && screen.dashboard === from) edits.push({ path: [...at, "dashboard"], value: to });
9854
+ if (_optionalChain([screen, 'optionalAccess', _256 => _256.type]) === "forms" && Array.isArray(screen.forms))
9764
9855
  screen.forms.forEach((f, j) => f === from && edits.push({ path: [...at, "forms", j], value: to }));
9765
- if (_optionalChain([screen, 'optionalAccess', _247 => _247.type]) === "menu" && Array.isArray(screen.items))
9856
+ if (_optionalChain([screen, 'optionalAccess', _257 => _257.type]) === "menu" && Array.isArray(screen.items))
9766
9857
  screen.items.forEach((item, j) => {
9767
- if (_optionalChain([item, 'optionalAccess', _248 => _248.dashboard]) === from) edits.push({ path: [...at, "items", j, "dashboard"], value: to });
9768
- if (_optionalChain([item, 'optionalAccess', _249 => _249.form]) === from) edits.push({ path: [...at, "items", j, "form"], value: to });
9858
+ if (_optionalChain([item, 'optionalAccess', _258 => _258.dashboard]) === from) edits.push({ path: [...at, "items", j, "dashboard"], value: to });
9859
+ if (_optionalChain([item, 'optionalAccess', _259 => _259.form]) === from) edits.push({ path: [...at, "items", j, "form"], value: to });
9769
9860
  });
9770
9861
  });
9771
9862
  if (path !== void 0) edits.push({ path: ["documents", from], value: path });
9772
9863
  let out = applyJsonEdits(text, edits);
9773
9864
  if (to !== from) {
9774
- const key = _optionalChain([findNodeAtLocation2, 'call', _250 => _250(parseTree2(out), ["documents", from]), 'optionalAccess', _251 => _251.parent, 'optionalAccess', _252 => _252.children, 'optionalAccess', _253 => _253[0]]);
9865
+ const key = _optionalChain([findNodeAtLocation2, 'call', _260 => _260(parseTree2(out), ["documents", from]), 'optionalAccess', _261 => _261.parent, 'optionalAccess', _262 => _262.children, 'optionalAccess', _263 => _263[0]]);
9775
9866
  if (key) out = out.slice(0, key.offset) + JSON.stringify(to) + out.slice(key.offset + key.length);
9776
9867
  }
9777
9868
  return out;
@@ -9781,7 +9872,7 @@ function parse2(text) {
9781
9872
  try {
9782
9873
  const d = JSON.parse(text);
9783
9874
  return d && Array.isArray(d.panels) && d.panels.every((p) => p && typeof p === "object") ? d : void 0;
9784
- } catch (e13) {
9875
+ } catch (e14) {
9785
9876
  return void 0;
9786
9877
  }
9787
9878
  }
@@ -9790,16 +9881,16 @@ function inputs(text) {
9790
9881
  const out = /* @__PURE__ */ new Map();
9791
9882
  try {
9792
9883
  if (d) {
9793
- for (const p of inputPanels(d)) if (typeof p.id === "number" && typeof _optionalChain([p, 'access', _254 => _254.options, 'optionalAccess', _255 => _255.metric]) === "string") out.set(p.id, { metric: p.options.metric, title: p.title });
9884
+ for (const p of inputPanels(d)) if (typeof p.id === "number" && typeof _optionalChain([p, 'access', _264 => _264.options, 'optionalAccess', _265 => _265.metric]) === "string") out.set(p.id, { metric: p.options.metric, title: p.title });
9794
9885
  }
9795
- } catch (e14) {
9886
+ } catch (e15) {
9796
9887
  }
9797
9888
  return out;
9798
9889
  }
9799
9890
  function reads(text, metric) {
9800
9891
  const d = parse2(text);
9801
9892
  const panels = d ? d.panels.flatMap((p) => p.type === "row" ? [p, ..._nullishCoalesce(p.panels, () => ( []))] : [p]) : [];
9802
- return panels.some((p) => (_nullishCoalesce(_optionalChain([p, 'optionalAccess', _256 => _256.targets]), () => ( []))).some((t) => t.metric === metric));
9893
+ return panels.some((p) => (_nullishCoalesce(_optionalChain([p, 'optionalAccess', _266 => _266.targets]), () => ( []))).some((t) => t.metric === metric));
9803
9894
  }
9804
9895
  function metricChanges(before, after) {
9805
9896
  const merged = { ...before, ...after };
@@ -9814,7 +9905,7 @@ function metricChanges(before, after) {
9814
9905
  for (const [file, text] of Object.entries(after)) {
9815
9906
  const old = inputs(before[file]);
9816
9907
  for (const [id, input] of inputs(text))
9817
- if (_optionalChain([old, 'access', _257 => _257.get, 'call', _258 => _258(id), 'optionalAccess', _259 => _259.metric]) === metric && input.metric !== metric) rename ??= { metric, renamedTo: input.metric, file, input: input.title, readBy };
9908
+ if (_optionalChain([old, 'access', _267 => _267.get, 'call', _268 => _268(id), 'optionalAccess', _269 => _269.metric]) === metric && input.metric !== metric) rename ??= { metric, renamedTo: input.metric, file, input: input.title, readBy };
9818
9909
  }
9819
9910
  changes.push(_nullishCoalesce(rename, () => ( { metric, readBy })));
9820
9911
  }
@@ -9854,14 +9945,14 @@ function variableWithType(v, type) {
9854
9945
  }
9855
9946
  function currentFor(v, value) {
9856
9947
  const options = variableOptions({ ...v, current: void 0 });
9857
- const text = (x) => x === ALL ? "All" : _nullishCoalesce(_optionalChain([options, 'access', _260 => _260.find, 'call', _261 => _261((o) => o.value === x), 'optionalAccess', _262 => _262.text]), () => ( x));
9948
+ const text = (x) => x === ALL ? "All" : _nullishCoalesce(_optionalChain([options, 'access', _270 => _270.find, 'call', _271 => _271((o) => o.value === x), 'optionalAccess', _272 => _272.text]), () => ( x));
9858
9949
  return Array.isArray(value) ? { text: value.map(text), value } : { text: text(value), value };
9859
9950
  }
9860
9951
  function variableWithQuery(v, query) {
9861
9952
  const { options: _, current, ...rest } = v;
9862
9953
  const next = { ...rest, query };
9863
9954
  if (v.type === "textbox" || v.type === "constant") return { ...next, current: { text: query, value: query } };
9864
- const value = selectValue(next, _optionalChain([current, 'optionalAccess', _263 => _263.value]), variableOptions(next));
9955
+ const value = selectValue(next, _optionalChain([current, 'optionalAccess', _273 => _273.value]), variableOptions(next));
9865
9956
  return { ...next, current: currentFor(next, value) };
9866
9957
  }
9867
9958
  function variableWithCurrent(v, value) {
@@ -9871,13 +9962,13 @@ function variableWithFlags(v, flags) {
9871
9962
  const next = { ...v, ...flags };
9872
9963
  if (!next.multi) delete next.multi;
9873
9964
  if (!next.includeAll) delete next.includeAll;
9874
- const raw = _optionalChain([v, 'access', _264 => _264.current, 'optionalAccess', _265 => _265.value]);
9965
+ const raw = _optionalChain([v, 'access', _274 => _274.current, 'optionalAccess', _275 => _275.value]);
9875
9966
  const current = next.multi ? raw == null ? [] : Array.isArray(raw) ? raw : [raw] : Array.isArray(raw) ? raw[0] : raw;
9876
9967
  return variableWithCurrent(next, selectValue(next, current, variableOptions({ ...next, current: void 0 })));
9877
9968
  }
9878
9969
  var refers = (name, flags) => new RegExp(`\\$${name}\\b|\\$\\{${name}(:\\w+)?\\}|\\[\\[${name}(:\\w+)?\\]\\]`, flags);
9879
9970
  function allPanels2(dashboard) {
9880
- return (_nullishCoalesce(dashboard.panels, () => ( []))).flatMap((p) => _optionalChain([p, 'optionalAccess', _266 => _266.type]) === "row" ? [p, ..._nullishCoalesce(p.panels, () => ( []))] : [p]).filter((p) => p && typeof p === "object");
9971
+ return (_nullishCoalesce(dashboard.panels, () => ( []))).flatMap((p) => _optionalChain([p, 'optionalAccess', _276 => _276.type]) === "row" ? [p, ..._nullishCoalesce(p.panels, () => ( []))] : [p]).filter((p) => p && typeof p === "object");
9881
9972
  }
9882
9973
  function variableUses(dashboard, name) {
9883
9974
  const re = refers(name);
@@ -9949,7 +10040,7 @@ function locate(text, tree, path) {
9949
10040
  for (let n = segs.length; n >= 0; n--) {
9950
10041
  const node = findNodeAtLocation2(tree, segs.slice(0, n));
9951
10042
  if (!node) continue;
9952
- const key = _optionalChain([node, 'access', _267 => _267.parent, 'optionalAccess', _268 => _268.type]) === "property" ? _optionalChain([node, 'access', _269 => _269.parent, 'access', _270 => _270.children, 'optionalAccess', _271 => _271[0]]) : void 0;
10043
+ const key = _optionalChain([node, 'access', _277 => _277.parent, 'optionalAccess', _278 => _278.type]) === "property" ? _optionalChain([node, 'access', _279 => _279.parent, 'access', _280 => _280.children, 'optionalAccess', _281 => _281[0]]) : void 0;
9953
10044
  if ((node.type === "object" || node.type === "array") && key) return located(text, key.offset, key.length);
9954
10045
  if (node.type === "object" || node.type === "array") return located(text, node.offset, 1);
9955
10046
  return located(text, node.offset, node.length);
@@ -10069,16 +10160,16 @@ async function errorText(res) {
10069
10160
  const body = await res.text();
10070
10161
  try {
10071
10162
  return _nullishCoalesce(JSON.parse(body).error, () => ( body));
10072
- } catch (e15) {
10163
+ } catch (e16) {
10073
10164
  return body || `HTTP ${res.status}`;
10074
10165
  }
10075
10166
  }
10076
10167
  async function authHeaders(token) {
10077
- const t = await _optionalChain([token, 'optionalCall', _272 => _272()]);
10168
+ const t = await _optionalChain([token, 'optionalCall', _282 => _282()]);
10078
10169
  return t ? { Authorization: `Bearer ${t}` } : {};
10079
10170
  }
10080
10171
  var HttpConfigFiles = (_class3 = class {
10081
- constructor(manifestUrl, token) {;_class3.prototype.__init7.call(this);
10172
+ constructor(manifestUrl, token) {;_class3.prototype.__init8.call(this);
10082
10173
  this.manifestUrl = manifestUrl;
10083
10174
  this.token = token;
10084
10175
  this.manifestPath = manifestUrl.replace(/[?#].*$/, "").split("/").pop() || "app.json";
@@ -10087,7 +10178,7 @@ var HttpConfigFiles = (_class3 = class {
10087
10178
 
10088
10179
 
10089
10180
  /** The revision of each file as last read or saved here, by path relative to the manifest. */
10090
- __init7() {this.revisions = /* @__PURE__ */ new Map()}
10181
+ __init8() {this.revisions = /* @__PURE__ */ new Map()}
10091
10182
 
10092
10183
  /** The bundle's root URL, which its file paths are relative to. */
10093
10184
 
@@ -10107,7 +10198,7 @@ var HttpConfigFiles = (_class3 = class {
10107
10198
  let body;
10108
10199
  try {
10109
10200
  body = JSON.parse(await res.text());
10110
- } catch (e16) {
10201
+ } catch (e17) {
10111
10202
  return null;
10112
10203
  }
10113
10204
  if (!isBundleResponse(body)) return null;
@@ -10177,27 +10268,23 @@ var HttpConfigFiles = (_class3 = class {
10177
10268
  }
10178
10269
  }, _class3);
10179
10270
  function fetchJsonWithToken(token) {
10180
- return async (url, options) => {
10181
- const res = await fetch(url, { headers: { Accept: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _273 => _273.accept]), () => ( "application/json")), ...await authHeaders(token) }, cache: "no-store" });
10182
- if (!res.ok) throw new Error(res.status === 401 ? "not signed in" : `HTTP ${res.status}`);
10183
- return JSON.parse(await res.text());
10184
- };
10271
+ return httpFetchJson({ headers: () => authHeaders(token), httpError: (status) => status === 401 ? "not signed in" : `HTTP ${status}` });
10185
10272
  }
10186
10273
  async function readConfigFiles(source) {
10187
- const all = await _optionalChain([source, 'access', _274 => _274.readAll, 'optionalCall', _275 => _275()]);
10274
+ const all = await _optionalChain([source, 'access', _283 => _283.readAll, 'optionalCall', _284 => _284()]);
10188
10275
  const read = all ? async (p) => {
10189
10276
  if (!(p in all)) throw new Error(NOT_FOUND);
10190
10277
  return all[p];
10191
10278
  } : (p) => source.read(p);
10192
10279
  const files = { [source.manifestPath]: await read(source.manifestPath) };
10193
10280
  const { value } = parseJsonText(files[source.manifestPath]);
10194
- const documents = _nullishCoalesce(_optionalChain([value, 'optionalAccess', _276 => _276.documents]), () => ( {}));
10281
+ const documents = _nullishCoalesce(_optionalChain([value, 'optionalAccess', _285 => _285.documents]), () => ( {}));
10195
10282
  const paths = [...new Set(Object.values(documents).filter((d) => typeof d === "string"))];
10196
10283
  await Promise.all(
10197
10284
  paths.map(async (p) => {
10198
10285
  try {
10199
10286
  files[p] = await read(p);
10200
- } catch (e17) {
10287
+ } catch (e18) {
10201
10288
  }
10202
10289
  })
10203
10290
  );
@@ -10245,9 +10332,36 @@ var CANVAS_ROW_HEADER = 32;
10245
10332
  function panelSize(panel, mode) {
10246
10333
  const p = pos(panel);
10247
10334
  if (mode === "grid") return { span: clampW(p.w), h: clampH(p.h) };
10248
- return { span: panelSpan(panel, "phone"), h: clampH(_nullishCoalesce(_optionalChain([panel, 'access', _277 => _277.mobile, 'optionalAccess', _278 => _278.h]), () => ( p.h))) };
10335
+ return { span: panelSpan(panel, "phone"), h: clampH(_nullishCoalesce(_optionalChain([panel, 'access', _286 => _286.mobile, 'optionalAccess', _287 => _287.h]), () => ( p.h))) };
10249
10336
  }
10250
10337
  function layoutCanvas(panels, order, mode, width, override) {
10338
+ return mode === "grid" ? layoutGridCanvas(panels, width, override) : layoutPhoneCanvas(panels, order, width, override);
10339
+ }
10340
+ function layoutGridCanvas(panels, width, override) {
10341
+ const colW = (width + CANVAS_GAP) / GRID_COLUMNS;
10342
+ let boxes = gridBoxes(panels);
10343
+ if (override && boxes[override.index]) {
10344
+ const b = { ...boxes[override.index] };
10345
+ if (!isRow(panels[override.index])) {
10346
+ if (override.span !== void 0) b.w = clampW(override.span);
10347
+ if (override.h !== void 0) b.h = clampH(override.h);
10348
+ }
10349
+ if (override.x !== void 0) b.x = isRow(panels[override.index]) ? 0 : Math.min(GRID_COLUMNS - b.w, Math.max(0, Math.round(override.x)));
10350
+ if (override.y !== void 0) b.y = Math.max(0, Math.round(override.y));
10351
+ b.x = Math.min(b.x, GRID_COLUMNS - b.w);
10352
+ boxes = [...boxes];
10353
+ boxes[override.index] = b;
10354
+ }
10355
+ const settled = settleBoxes(boxes, _optionalChain([override, 'optionalAccess', _288 => _288.index]));
10356
+ const items = settled.map((b, index) => {
10357
+ const row = isRow(panels[index]);
10358
+ return { index, row, x: b.x * colW, y: gridOffsetPx(b.y), width: b.w * colW - CANVAS_GAP, height: row ? gridUnitsToPx(1) : gridUnitsToPx(b.h), span: b.w, h: b.h };
10359
+ });
10360
+ items.sort((a, b) => a.y - b.y || a.x - b.x);
10361
+ return { items, height: Math.max(0, ...items.map((c) => c.y + c.height)), hidden: [] };
10362
+ }
10363
+ function layoutPhoneCanvas(panels, order, width, override) {
10364
+ const mode = "phone";
10251
10365
  const colW = (width + CANVAS_GAP) / GRID_COLUMNS;
10252
10366
  const items = [];
10253
10367
  const hidden = [];
@@ -10282,11 +10396,12 @@ function layoutCanvas(panels, order, mode, width, override) {
10282
10396
  y += CANVAS_ROW_HEADER + CANVAS_GAP;
10283
10397
  continue;
10284
10398
  }
10285
- if (mode === "phone" && _optionalChain([panel, 'access', _279 => _279.mobile, 'optionalAccess', _280 => _280.hidden])) {
10399
+ if (mode === "phone" && _optionalChain([panel, 'access', _289 => _289.mobile, 'optionalAccess', _290 => _290.hidden])) {
10286
10400
  hidden.push(index);
10287
10401
  continue;
10288
10402
  }
10289
- const size = _optionalChain([override, 'optionalAccess', _281 => _281.index]) === index ? { span: clampW(override.span), h: clampH(override.h) } : panelSize(panel, mode);
10403
+ const natural = panelSize(panel, mode);
10404
+ const size = _optionalChain([override, 'optionalAccess', _291 => _291.index]) === index ? { span: clampW(_nullishCoalesce(override.span, () => ( natural.span))), h: clampH(_nullishCoalesce(override.h, () => ( natural.h))) } : natural;
10290
10405
  if (used + size.span > GRID_COLUMNS) flush();
10291
10406
  line.push({ index, row: false, x: 0, y: 0, width: 0, height: 0, ...size });
10292
10407
  used += size.span;
@@ -10304,19 +10419,24 @@ function dropTarget(canvas, x, y, dragging) {
10304
10419
  for (const c of pool) if (distance(c) < distance(best)) best = c;
10305
10420
  const after = best.row ? y > best.y + best.height / 2 : x > best.x + best.width / 2;
10306
10421
  if (!after) return best.index;
10307
- return _nullishCoalesce(_optionalChain([items, 'access', _282 => _282[items.indexOf(best) + 1], 'optionalAccess', _283 => _283.index]), () => ( null));
10422
+ return _nullishCoalesce(_optionalChain([items, 'access', _292 => _292[items.indexOf(best) + 1], 'optionalAccess', _293 => _293.index]), () => ( null));
10308
10423
  }
10309
10424
  function movePanel(panels, index, before) {
10310
- const order = readingOrder(panels).filter((i) => i !== index);
10311
- const at = before === null ? order.length : order.indexOf(before);
10312
- order.splice(at === -1 ? order.length : at, 0, index);
10313
- return repack(panels, order);
10425
+ if (before === index) return panels;
10426
+ const others = panels.filter((_, i) => i !== index);
10427
+ const at = before === null || !panels[before] ? { x: 0, y: bottom(others) } : pos(panels[before]);
10428
+ return placePanel(panels, index, at.x, at.y);
10314
10429
  }
10315
10430
  function resizePanel(panels, index, mode, span, h) {
10316
10431
  const out = [...panels];
10317
10432
  const p = panels[index];
10318
- out[index] = mode === "grid" ? { ...p, gridPos: { ...pos(p), w: clampW(span), h: clampH(h) } } : { ...p, mobile: { ...p.mobile, span: clampW(span), h: clampH(h) } };
10319
- return repack(out, readingOrder(out));
10433
+ if (mode === "phone") {
10434
+ out[index] = { ...p, mobile: { ...p.mobile, span: clampW(span), h: clampH(h) } };
10435
+ return out;
10436
+ }
10437
+ const w = clampW(span);
10438
+ out[index] = { ...p, gridPos: { ...pos(p), x: Math.min(pos(p).x, GRID_COLUMNS - w), w, h: clampH(h) } };
10439
+ return settleLayout(out, index);
10320
10440
  }
10321
10441
  function setHiddenOnPhones(panels, index, hidden) {
10322
10442
  const out = [...panels];
@@ -10331,34 +10451,77 @@ function nextPanelId(panels) {
10331
10451
  }
10332
10452
  function insertPanel(panels, panel, after) {
10333
10453
  const index = panels.length;
10334
- const out = [...panels, { ...panel, id: nextPanelId(panels), gridPos: { ...DEFAULT_POS, ...panel.gridPos } }];
10335
- const order = readingOrder(panels);
10336
- order.splice(after === null ? order.length : order.indexOf(after) + 1, 0, index);
10337
- return { panels: repack(out, order), index };
10454
+ const p = { ...DEFAULT_POS, ...panel.gridPos };
10455
+ const w = isRow(panel) ? GRID_COLUMNS : clampW(p.w);
10456
+ let at;
10457
+ if (after === null || !panels[after]) at = { x: 0, y: bottom(panels) };
10458
+ else {
10459
+ const a = pos(panels[after]);
10460
+ at = !isRow(panel) && !isRow(panels[after]) && a.x + a.w + w <= GRID_COLUMNS ? { x: a.x + a.w, y: a.y } : { x: isRow(panel) ? 0 : Math.min(a.x, GRID_COLUMNS - w), y: a.y + a.h };
10461
+ }
10462
+ const out = [...panels, { ...panel, id: nextPanelId(panels), gridPos: { ...p, ...at, w } }];
10463
+ return { panels: settleLayout(out, index), index };
10338
10464
  }
10339
10465
  function duplicatePanel(panels, index) {
10340
10466
  return insertPanel(panels, structuredClone(panels[index]), index);
10341
10467
  }
10342
10468
  function removePanel(panels, index) {
10343
- const out = panels.filter((_, i) => i !== index);
10344
- return repack(out, readingOrder(out));
10469
+ return settleLayout(panels.filter((_, i) => i !== index));
10345
10470
  }
10346
10471
  function expandRow(panels, index) {
10347
10472
  const row = panels[index];
10348
10473
  const children = _nullishCoalesce(row.panels, () => ( []));
10349
- const out = [...panels, ...children];
10474
+ const top = pos(row).y + 1;
10475
+ const first = Math.min(...children.map((c) => pos(c).y));
10476
+ const height = Math.max(0, ...children.map((c) => pos(c).y - first + pos(c).h));
10477
+ const out = panels.map((p, i) => i !== index && pos(p).y > pos(row).y ? { ...p, gridPos: { ...pos(p), y: pos(p).y + height } } : p);
10350
10478
  out[index] = { ...row, collapsed: false, panels: [] };
10479
+ out.push(...children.map((c) => ({ ...c, gridPos: { ...pos(c), y: top + pos(c).y - first } })));
10480
+ return settleLayout(out);
10481
+ }
10482
+ function collapseRow(panels, index) {
10351
10483
  const order = readingOrder(panels);
10352
- order.splice(order.indexOf(index) + 1, 0, ...children.map((_, i) => panels.length + i));
10353
- return repack(out, order);
10484
+ const at = order.indexOf(index);
10485
+ const next = order.findIndex((i, n) => n > at && isRow(panels[i]));
10486
+ const removed = order.slice(at + 1, next === -1 ? order.length : next).sort((a, b) => a - b);
10487
+ const out = panels.filter((_, i) => !removed.includes(i));
10488
+ const rowAt = index - removed.filter((i) => i < index).length;
10489
+ out[rowAt] = { ...panels[index], collapsed: true, panels: removed.map((i) => panels[i]) };
10490
+ return { panels: settleLayout(out), removed };
10491
+ }
10492
+ var bottom = (panels) => Math.max(0, ...panels.map((p) => pos(p).y + pos(p).h));
10493
+ var gridBoxes = (panels) => panels.map((p) => isRow(p) ? { ...pos(p), x: 0, w: GRID_COLUMNS, h: 1 } : pos(p));
10494
+ function settleBoxes(boxes, fixed2) {
10495
+ const made = fixed2 === void 0 ? boxes : compactGrid(boxes, /* @__PURE__ */ new Set([fixed2]));
10496
+ return compactGrid(made);
10497
+ }
10498
+ function writeBoxes(panels, boxes) {
10499
+ return panels.map((p, i) => {
10500
+ const before = p.gridPos;
10501
+ const b = boxes[i];
10502
+ return before && before.x === b.x && before.y === b.y && before.w === b.w && before.h === b.h ? p : { ...p, gridPos: { ...pos(p), ...b } };
10503
+ });
10504
+ }
10505
+ function settleLayout(panels, fixed2) {
10506
+ return writeBoxes(panels, settleBoxes(gridBoxes(panels), fixed2));
10507
+ }
10508
+ function placePanel(panels, index, x, y) {
10509
+ const out = [...panels];
10510
+ const p = pos(panels[index]);
10511
+ const w = isRow(panels[index]) ? GRID_COLUMNS : clampW(p.w);
10512
+ out[index] = { ...panels[index], gridPos: { ...p, x: Math.min(GRID_COLUMNS - w, Math.max(0, Math.round(x))), y: Math.max(0, Math.round(y)) } };
10513
+ return settleLayout(out, index);
10514
+ }
10515
+ function snapToGrid(width, x, y, w) {
10516
+ const colW = (width + CANVAS_GAP) / GRID_COLUMNS;
10517
+ return { x: Math.min(GRID_COLUMNS - w, Math.max(0, Math.round(x / colW))), y: Math.max(0, Math.round(y / gridOffsetPx(1))) };
10354
10518
  }
10355
10519
  function panelEdits(before, after, removed) {
10356
10520
  const edits = [];
10357
10521
  let base = before;
10358
- if (removed !== void 0) {
10359
- edits.push({ path: ["panels", removed], remove: true });
10360
- base = before.filter((_, i) => i !== removed);
10361
- }
10522
+ const gone = [...new Set(removed === void 0 ? [] : [removed].flat())].sort((a, b) => b - a);
10523
+ for (const i of gone) edits.push({ path: ["panels", i], remove: true });
10524
+ if (gone.length) base = before.filter((_, i) => !gone.includes(i));
10362
10525
  base.forEach((p, i) => edits.push(...diffJson(p, after[i], ["panels", i])));
10363
10526
  for (let i = base.length; i < after.length; i++) edits.push({ path: ["panels", i], value: after[i], insert: true });
10364
10527
  return edits;
@@ -10627,4 +10790,12 @@ function sampleEntries(forms, metrics, now = Date.now(), days = 180) {
10627
10790
 
10628
10791
 
10629
10792
 
10630
- exports.frameLength = frameLength; exports.timeField = timeField; exports.numberFields = numberFields; exports.fieldDisplayName = fieldDisplayName; exports.toSeries = toSeries; exports.toXYSeries = toXYSeries; exports.uniqueNames = uniqueNames; exports.toMillis = toMillis; exports.parseTime = parseTime; exports.parseRange = parseRange; exports.addTime = addTime; exports.startOf = startOf; exports.parseDuration = parseDuration; exports.calculateInterval = calculateInterval; exports.formatDuration = formatDuration; exports.TIME_PRESETS = TIME_PRESETS; exports.RELATIVE_RANGES = RELATIVE_RANGES; exports.parseLocalDateTime = parseLocalDateTime; exports.formatLocalDateTime = formatLocalDateTime; exports.timeExprError = timeExprError; exports.describeRange = describeRange; exports.zoomRange = zoomRange; exports.ALL = ALL; exports.initialVariableValues = initialVariableValues; exports.variableOptions = variableOptions; exports.variableInfo = variableInfo; exports.visibleVariables = visibleVariables; exports.isSqlDatasource = isSqlDatasource; exports.framesToOptions = framesToOptions; exports.refineOptions = refineOptions; exports.selectValue = selectValue; exports.variableReferences = variableReferences; exports.interpolate = interpolate; exports.queryParam = queryParam; exports.interpolateDeep = interpolateDeep; exports.resolveTimezone = resolveTimezone; exports.valueText = valueText; exports.GRID_COLUMNS = GRID_COLUMNS; exports.gridUnitsToPx = gridUnitsToPx; exports.isRow = isRow; exports.layoutDashboard = layoutDashboard; exports.repeatOptions = repeatOptions; exports.panelKey = panelKey; exports.panelSpan = panelSpan; exports.applyTransformations = applyTransformations; exports.DASHBOARD_DS = DASHBOARD_DS; exports.dashboardSourceIds = dashboardSourceIds; exports.panelHasQueries = panelHasQueries; exports.queryPanel = queryPanel; exports.normalizeRef = normalizeRef; exports.refreshedVariables = refreshedVariables; exports.variableDependents = variableDependents; exports.variableOrder = variableOrder; exports.resolveVariables = resolveVariables; exports.REDUCER_LABELS = REDUCER_LABELS; exports.isReducer = isReducer; exports.reduce = reduce; exports.INPUT_OPTION_KEYS = INPUT_OPTION_KEYS; exports.INPUT_TYPES = INPUT_TYPES; exports.isInputType = isInputType; exports.isInputPanel = isInputPanel; exports.inputPanels = inputPanels; exports.parseClockDigits = parseClockDigits; exports.formatClock = formatClock; exports.toEntries = toEntries; exports.inputProblem = inputProblem; exports.entryToInputValue = entryToInputValue; exports.textSuggestions = textSuggestions; exports.entriesSavedWith = entriesSavedWith; exports.formatValue = formatValue; exports.thresholdStep = thresholdStep; exports.NAMED_COLORS = NAMED_COLORS; exports.resolveColor = resolveColor; exports.SERIES_PALETTE = SERIES_PALETTE; exports.seriesColor = seriesColor; exports.mappedResult = mappedResult; exports.formatDisplay = formatDisplay; exports.valueColor = valueColor; exports.resolveFieldConfig = resolveFieldConfig; exports.fieldMatches = fieldMatches; exports.GrafanaError = GrafanaError; exports.GrafanaClient = GrafanaClient; exports.GrafanaDataSource = GrafanaDataSource; exports.fromWire = fromWire; exports.LOCAL_DATASOURCE_TYPE = LOCAL_DATASOURCE_TYPE; exports.isLocalDatasource = isLocalDatasource; exports.LocalDataSource = LocalDataSource; exports.buildFrames = buildFrames; exports.MemoryEntryStore = MemoryEntryStore; exports.DEFAULT_GAZETTEER = DEFAULT_GAZETTEER; exports.parseGazetteer = parseGazetteer; exports.loadGazetteer = loadGazetteer; exports.resolveLinks = resolveLinks; exports.parseDashboardLink = parseDashboardLink; exports.applyDashboardLink = applyDashboardLink; exports.appSchema = appSchema; exports.dashboardSchema = dashboardSchema; exports.pointerToPath = pointerToPath; exports.manifestSchemaIssues = manifestSchemaIssues; exports.dashboardSchemaIssues = dashboardSchemaIssues; exports.cleanDashboard = cleanDashboard; exports.MAPPING_TYPES = MAPPING_TYPES; exports.SPECIAL_MATCHES = SPECIAL_MATCHES; exports.mappingRows = mappingRows; exports.rowsToMappings = rowsToMappings; exports.mappingRow = mappingRow; exports.mappingProblem = mappingProblem; exports.OPTION_CATEGORIES = OPTION_CATEGORIES; exports.UNIT_CHOICES = UNIT_CHOICES; exports.panelOptions = panelOptions; exports.getPath = getPath; exports.optionValue = optionValue; exports.setOption = setOption; exports.setOptionValue = setOptionValue; exports.cleanPanelOptions = cleanPanelOptions; exports.OVERRIDE_MATCHERS = OVERRIDE_MATCHERS; exports.overrideProperties = overrideProperties; exports.panelOverrides = panelOverrides; exports.setOverrides = setOverrides; exports.MANIFEST_VERSION = MANIFEST_VERSION; exports.validateManifest = validateManifest; exports.prepareDashboard = prepareDashboard; exports.validateDashboard = validateDashboard2; exports.validateBundle = validateBundle; exports.resolveUrl = resolveUrl; exports.defaultFetchJson = defaultFetchJson; exports.BUNDLE_TYPE = BUNDLE_TYPE; exports.BUNDLE_ACCEPT = BUNDLE_ACCEPT; exports.isBundleResponse = isBundleResponse; exports.bundleRoot = bundleRoot; exports.assembleFromResponse = assembleFromResponse; exports.assembleBundle = assembleBundle; exports.fetchBundle = fetchBundle; exports.ConfigLoader = ConfigLoader; exports.tabIdFor = tabIdFor; exports.screenOfType = screenOfType; exports.screenDocuments = screenDocuments; exports.documentUses = documentUses; exports.stringifyCompact = stringifyCompact; exports.applyJsonEdits = applyJsonEdits; exports.diffJson = diffJson; exports.documentIdFor = documentIdFor; exports.removeDocumentFromManifest = removeDocumentFromManifest; exports.renameDocumentInManifest = renameDocumentInManifest; exports.metricChanges = metricChanges; exports.REFRESH_CHOICES = REFRESH_CHOICES; exports.EDITABLE_VARIABLE_TYPES = EDITABLE_VARIABLE_TYPES; exports.isEditableVariableType = isEditableVariableType; exports.variableNameError = variableNameError; exports.newVariable = newVariable; exports.variableWithType = variableWithType; exports.variableWithQuery = variableWithQuery; exports.variableWithCurrent = variableWithCurrent; exports.variableWithFlags = variableWithFlags; exports.variableUses = variableUses; exports.renameVariableInPanels = renameVariableInPanels; exports.lineColumn = lineColumn; exports.parseJsonText = parseJsonText; exports.splitPath = splitPath; exports.locate = locate; exports.checkFiles = checkFiles; exports.bundleFromFiles = bundleFromFiles; exports.formatJsonText = formatJsonText; exports.setJsonValue = setJsonValue; exports.PANEL_TYPES = PANEL_TYPES; exports.newPanel = newPanel; exports.newDocument = newDocument; exports.SaveConflictError = SaveConflictError; exports.HttpConfigFiles = HttpConfigFiles; exports.fetchJsonWithToken = fetchJsonWithToken; exports.readConfigFiles = readConfigFiles; exports.readingOrder = readingOrder; exports.repack = repack; exports.CANVAS_GAP = CANVAS_GAP; exports.CANVAS_ROW_HEADER = CANVAS_ROW_HEADER; exports.panelSize = panelSize; exports.layoutCanvas = layoutCanvas; exports.dropTarget = dropTarget; exports.movePanel = movePanel; exports.resizePanel = resizePanel; exports.setHiddenOnPhones = setHiddenOnPhones; exports.nextPanelId = nextPanelId; exports.insertPanel = insertPanel; exports.duplicatePanel = duplicatePanel; exports.removePanel = removePanel; exports.expandRow = expandRow; exports.panelEdits = panelEdits; exports.sampleEntries = sampleEntries;
10793
+
10794
+
10795
+
10796
+
10797
+
10798
+
10799
+
10800
+
10801
+ exports.frameLength = frameLength; exports.timeField = timeField; exports.numberFields = numberFields; exports.fieldDisplayName = fieldDisplayName; exports.toSeries = toSeries; exports.toXYSeries = toXYSeries; exports.uniqueNames = uniqueNames; exports.toMillis = toMillis; exports.parseTime = parseTime; exports.parseRange = parseRange; exports.addTime = addTime; exports.startOf = startOf; exports.parseDuration = parseDuration; exports.calculateInterval = calculateInterval; exports.formatDuration = formatDuration; exports.TIME_PRESETS = TIME_PRESETS; exports.RELATIVE_RANGES = RELATIVE_RANGES; exports.parseLocalDateTime = parseLocalDateTime; exports.formatLocalDateTime = formatLocalDateTime; exports.timeExprError = timeExprError; exports.describeRange = describeRange; exports.zoomRange = zoomRange; exports.ALL = ALL; exports.initialVariableValues = initialVariableValues; exports.variableOptions = variableOptions; exports.variableInfo = variableInfo; exports.visibleVariables = visibleVariables; exports.isSqlDatasource = isSqlDatasource; exports.framesToOptions = framesToOptions; exports.refineOptions = refineOptions; exports.selectValue = selectValue; exports.variableReferences = variableReferences; exports.interpolate = interpolate; exports.queryParam = queryParam; exports.interpolateDeep = interpolateDeep; exports.resolveTimezone = resolveTimezone; exports.valueText = valueText; exports.GRID_COLUMNS = GRID_COLUMNS; exports.gridUnitsToPx = gridUnitsToPx; exports.gridOffsetPx = gridOffsetPx; exports.compactGrid = compactGrid; exports.isRow = isRow; exports.layoutDashboard = layoutDashboard; exports.repeatOptions = repeatOptions; exports.panelKey = panelKey; exports.panelSpan = panelSpan; exports.applyTransformations = applyTransformations; exports.DASHBOARD_DS = DASHBOARD_DS; exports.dashboardSourceIds = dashboardSourceIds; exports.panelHasQueries = panelHasQueries; exports.queryPanel = queryPanel; exports.normalizeRef = normalizeRef; exports.refreshedVariables = refreshedVariables; exports.variableDependents = variableDependents; exports.variableOrder = variableOrder; exports.resolveVariables = resolveVariables; exports.REDUCER_LABELS = REDUCER_LABELS; exports.isReducer = isReducer; exports.reduce = reduce; exports.INPUT_OPTION_KEYS = INPUT_OPTION_KEYS; exports.INPUT_TYPES = INPUT_TYPES; exports.isInputType = isInputType; exports.isInputPanel = isInputPanel; exports.inputPanels = inputPanels; exports.parseClockDigits = parseClockDigits; exports.formatClock = formatClock; exports.toEntries = toEntries; exports.inputProblem = inputProblem; exports.entryToInputValue = entryToInputValue; exports.textSuggestions = textSuggestions; exports.entriesSavedWith = entriesSavedWith; exports.formatValue = formatValue; exports.thresholdStep = thresholdStep; exports.NAMED_COLORS = NAMED_COLORS; exports.resolveColor = resolveColor; exports.SERIES_PALETTE = SERIES_PALETTE; exports.seriesColor = seriesColor; exports.mappedResult = mappedResult; exports.formatDisplay = formatDisplay; exports.valueColor = valueColor; exports.resolveFieldConfig = resolveFieldConfig; exports.fieldMatches = fieldMatches; exports.GrafanaError = GrafanaError; exports.GrafanaClient = GrafanaClient; exports.GrafanaDataSource = GrafanaDataSource; exports.fromWire = fromWire; exports.LOCAL_DATASOURCE_TYPE = LOCAL_DATASOURCE_TYPE; exports.isLocalDatasource = isLocalDatasource; exports.LocalDataSource = LocalDataSource; exports.buildFrames = buildFrames; exports.MemoryEntryStore = MemoryEntryStore; exports.DEFAULT_GAZETTEER = DEFAULT_GAZETTEER; exports.parseGazetteer = parseGazetteer; exports.loadGazetteer = loadGazetteer; exports.resolveLinks = resolveLinks; exports.parseDashboardLink = parseDashboardLink; exports.applyDashboardLink = applyDashboardLink; exports.appSchema = appSchema; exports.dashboardSchema = dashboardSchema; exports.pointerToPath = pointerToPath; exports.manifestSchemaIssues = manifestSchemaIssues; exports.dashboardSchemaIssues = dashboardSchemaIssues; exports.cleanDashboard = cleanDashboard; exports.MAPPING_TYPES = MAPPING_TYPES; exports.SPECIAL_MATCHES = SPECIAL_MATCHES; exports.mappingRows = mappingRows; exports.rowsToMappings = rowsToMappings; exports.mappingRow = mappingRow; exports.mappingProblem = mappingProblem; exports.OPTION_CATEGORIES = OPTION_CATEGORIES; exports.UNIT_CHOICES = UNIT_CHOICES; exports.panelOptions = panelOptions; exports.getPath = getPath; exports.optionValue = optionValue; exports.setOption = setOption; exports.setOptionValue = setOptionValue; exports.cleanPanelOptions = cleanPanelOptions; exports.OVERRIDE_MATCHERS = OVERRIDE_MATCHERS; exports.overrideProperties = overrideProperties; exports.panelOverrides = panelOverrides; exports.setOverrides = setOverrides; exports.MANIFEST_VERSION = MANIFEST_VERSION; exports.validateManifest = validateManifest; exports.prepareDashboard = prepareDashboard; exports.validateDashboard = validateDashboard2; exports.validateBundle = validateBundle; exports.resolveUrl = resolveUrl; exports.httpFetchJson = httpFetchJson; exports.defaultFetchJson = defaultFetchJson; exports.BUNDLE_TYPE = BUNDLE_TYPE; exports.BUNDLE_ACCEPT = BUNDLE_ACCEPT; exports.isBundleResponse = isBundleResponse; exports.bundleRoot = bundleRoot; exports.assembleFromResponse = assembleFromResponse; exports.assembleBundle = assembleBundle; exports.fetchBundle = fetchBundle; exports.revalidateBundle = revalidateBundle; exports.ConfigLoader = ConfigLoader; exports.tabIdFor = tabIdFor; exports.screenOfType = screenOfType; exports.screenDocuments = screenDocuments; exports.documentUses = documentUses; exports.stringifyCompact = stringifyCompact; exports.applyJsonEdits = applyJsonEdits; exports.diffJson = diffJson; exports.documentIdFor = documentIdFor; exports.removeDocumentFromManifest = removeDocumentFromManifest; exports.renameDocumentInManifest = renameDocumentInManifest; exports.metricChanges = metricChanges; exports.REFRESH_CHOICES = REFRESH_CHOICES; exports.EDITABLE_VARIABLE_TYPES = EDITABLE_VARIABLE_TYPES; exports.isEditableVariableType = isEditableVariableType; exports.variableNameError = variableNameError; exports.newVariable = newVariable; exports.variableWithType = variableWithType; exports.variableWithQuery = variableWithQuery; exports.variableWithCurrent = variableWithCurrent; exports.variableWithFlags = variableWithFlags; exports.variableUses = variableUses; exports.renameVariableInPanels = renameVariableInPanels; exports.lineColumn = lineColumn; exports.parseJsonText = parseJsonText; exports.splitPath = splitPath; exports.locate = locate; exports.checkFiles = checkFiles; exports.bundleFromFiles = bundleFromFiles; exports.formatJsonText = formatJsonText; exports.setJsonValue = setJsonValue; exports.PANEL_TYPES = PANEL_TYPES; exports.newPanel = newPanel; exports.newDocument = newDocument; exports.SaveConflictError = SaveConflictError; exports.HttpConfigFiles = HttpConfigFiles; exports.fetchJsonWithToken = fetchJsonWithToken; exports.readConfigFiles = readConfigFiles; exports.readingOrder = readingOrder; exports.repack = repack; exports.CANVAS_GAP = CANVAS_GAP; exports.CANVAS_ROW_HEADER = CANVAS_ROW_HEADER; exports.panelSize = panelSize; exports.layoutCanvas = layoutCanvas; exports.dropTarget = dropTarget; exports.movePanel = movePanel; exports.resizePanel = resizePanel; exports.setHiddenOnPhones = setHiddenOnPhones; exports.nextPanelId = nextPanelId; exports.insertPanel = insertPanel; exports.duplicatePanel = duplicatePanel; exports.removePanel = removePanel; exports.expandRow = expandRow; exports.collapseRow = collapseRow; exports.settleLayout = settleLayout; exports.placePanel = placePanel; exports.snapToGrid = snapToGrid; exports.panelEdits = panelEdits; exports.sampleEntries = sampleEntries;