@modelform/react-native 0.1.1 → 0.2.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.
- package/dist/{chunk-L4SQVIJV.js → chunk-M5R44SAF.js} +132 -72
- package/dist/{chunk-PIHXMZ4G.mjs → chunk-MRHC6AEU.mjs} +87 -27
- package/dist/core/index.js +6 -2
- package/dist/core/index.mjs +5 -1
- package/dist/core/manifest.d.ts +40 -6
- package/dist/index.js +135 -131
- package/dist/index.mjs +5 -1
- package/package.json +1 -1
|
@@ -8068,11 +8068,28 @@ function resolveUrl(base, rel) {
|
|
|
8068
8068
|
}
|
|
8069
8069
|
return origin + out.join("/");
|
|
8070
8070
|
}
|
|
8071
|
-
|
|
8072
|
-
const
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8071
|
+
function httpFetchJson(options = {}) {
|
|
8072
|
+
const seen = /* @__PURE__ */ new Map();
|
|
8073
|
+
return async (url, { accept = "application/json", signal } = {}) => {
|
|
8074
|
+
const extra = await _asyncNullishCoalesce(await _optionalChain([options, 'access', _219 => _219.headers, 'optionalCall', _220 => _220()]), async () => ( {}));
|
|
8075
|
+
const key = JSON.stringify([url, accept, extra]);
|
|
8076
|
+
const last = seen.get(key);
|
|
8077
|
+
const get = (etag2) => fetch(url, { headers: { Accept: accept, ...extra, ...etag2 && { "If-None-Match": etag2 } }, cache: "no-store", signal });
|
|
8078
|
+
const res = await get(_optionalChain([last, 'optionalAccess', _221 => _221.etag])).catch((e) => {
|
|
8079
|
+
if (!last || _optionalChain([signal, 'optionalAccess', _222 => _222.aborted])) throw e;
|
|
8080
|
+
seen.delete(key);
|
|
8081
|
+
return get();
|
|
8082
|
+
});
|
|
8083
|
+
if (res.status === 304 && last) return last.json;
|
|
8084
|
+
if (!res.ok) throw new Error(_nullishCoalesce(_optionalChain([options, 'access', _223 => _223.httpError, 'optionalCall', _224 => _224(res.status)]), () => ( `HTTP ${res.status}`)));
|
|
8085
|
+
const json = JSON.parse(await res.text());
|
|
8086
|
+
const etag = res.headers.get("ETag");
|
|
8087
|
+
if (etag) seen.set(key, { etag, json });
|
|
8088
|
+
else seen.delete(key);
|
|
8089
|
+
return json;
|
|
8090
|
+
};
|
|
8091
|
+
}
|
|
8092
|
+
var defaultFetchJson = httpFetchJson();
|
|
8076
8093
|
var fileName = (url) => url.replace(/[?#].*$/, "").split("/").pop() || url;
|
|
8077
8094
|
var BUNDLE_TYPE = "application/vnd.modelform.bundle+json";
|
|
8078
8095
|
var BUNDLE_ACCEPT = `${BUNDLE_TYPE}, application/json;q=0.9`;
|
|
@@ -8085,7 +8102,7 @@ function bundleRoot(manifestUrl, manifestPath) {
|
|
|
8085
8102
|
return bare.endsWith(manifestPath) ? bare.slice(0, bare.length - manifestPath.length) : bare.replace(/[^/]*$/, "");
|
|
8086
8103
|
}
|
|
8087
8104
|
var NOT_IN_BUNDLE = "not found in the config";
|
|
8088
|
-
async function assembleFromResponse(url, response, fetchJson = defaultFetchJson) {
|
|
8105
|
+
async function assembleFromResponse(url, response, fetchJson = defaultFetchJson, signal) {
|
|
8089
8106
|
const root = bundleRoot(url, response.manifest);
|
|
8090
8107
|
const file = fileName(url);
|
|
8091
8108
|
const parse3 = (path) => {
|
|
@@ -8103,7 +8120,7 @@ async function assembleFromResponse(url, response, fetchJson = defaultFetchJson)
|
|
|
8103
8120
|
manifest,
|
|
8104
8121
|
async (ref) => {
|
|
8105
8122
|
const abs = resolveUrl(url, ref).replace(/[?#].*$/, "");
|
|
8106
|
-
return abs.startsWith(root) ? parse3(abs.slice(root.length)) : fetchJson(resolveUrl(url, ref));
|
|
8123
|
+
return abs.startsWith(root) ? parse3(abs.slice(root.length)) : fetchJson(resolveUrl(url, ref), { signal });
|
|
8107
8124
|
},
|
|
8108
8125
|
file
|
|
8109
8126
|
);
|
|
@@ -8131,18 +8148,35 @@ async function assembleBundle(manifest, load, file = "manifest") {
|
|
|
8131
8148
|
issues.push(...validateBundle(bundle, file));
|
|
8132
8149
|
return issues.some((i) => i.severity === "error") ? { issues } : { bundle, issues };
|
|
8133
8150
|
}
|
|
8134
|
-
async function fetchBundle(url, fetchJson = defaultFetchJson) {
|
|
8151
|
+
async function fetchBundle(url, fetchJson = defaultFetchJson, signal) {
|
|
8135
8152
|
let manifest;
|
|
8136
8153
|
try {
|
|
8137
|
-
manifest = await fetchJson(url, { accept: BUNDLE_ACCEPT });
|
|
8154
|
+
manifest = await fetchJson(url, { accept: BUNDLE_ACCEPT, signal });
|
|
8138
8155
|
} catch (e) {
|
|
8139
|
-
return { issues: [{ severity: "error", path: fileName(url), message: e.message }] };
|
|
8156
|
+
return { issues: [{ severity: "error", path: fileName(url), message: e.message }], ...!(e instanceof SyntaxError) && { unreachable: true } };
|
|
8157
|
+
}
|
|
8158
|
+
if (isBundleResponse(manifest)) return assembleFromResponse(url, manifest, fetchJson, signal);
|
|
8159
|
+
return assembleBundle(manifest, (path) => fetchJson(resolveUrl(url, path), { signal }), fileName(url));
|
|
8160
|
+
}
|
|
8161
|
+
function revalidateBundle(bundle) {
|
|
8162
|
+
try {
|
|
8163
|
+
const { manifest } = bundle;
|
|
8164
|
+
if (validateManifest(manifest).length) return void 0;
|
|
8165
|
+
const documents = {};
|
|
8166
|
+
for (const id of Object.keys(manifest.documents)) {
|
|
8167
|
+
const { dashboard } = prepareDashboard(bundle.documents[id], id);
|
|
8168
|
+
if (!dashboard) return void 0;
|
|
8169
|
+
documents[id] = dashboard;
|
|
8170
|
+
}
|
|
8171
|
+
const checked = { manifest, documents };
|
|
8172
|
+
return validateBundle(checked).some((i) => i.severity === "error") ? void 0 : checked;
|
|
8173
|
+
} catch (e12) {
|
|
8174
|
+
return void 0;
|
|
8140
8175
|
}
|
|
8141
|
-
if (isBundleResponse(manifest)) return assembleFromResponse(url, manifest, fetchJson);
|
|
8142
|
-
return assembleBundle(manifest, (path) => fetchJson(resolveUrl(url, path)), fileName(url));
|
|
8143
8176
|
}
|
|
8177
|
+
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
8144
8178
|
var ConfigLoader = (_class2 = class {
|
|
8145
|
-
constructor(options) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);
|
|
8179
|
+
constructor(options) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);
|
|
8146
8180
|
this.options = options;
|
|
8147
8181
|
const { fallback, url } = options;
|
|
8148
8182
|
this.snapshot = { bundle: fallback, source: fallback ? "bundled" : "none", url, loading: !!url, issues: [] };
|
|
@@ -8153,57 +8187,85 @@ var ConfigLoader = (_class2 = class {
|
|
|
8153
8187
|
|
|
8154
8188
|
|
|
8155
8189
|
|
|
8190
|
+
|
|
8191
|
+
__init5() {this.disposed = false}
|
|
8156
8192
|
get state() {
|
|
8157
8193
|
return this.snapshot;
|
|
8158
8194
|
}
|
|
8159
|
-
|
|
8195
|
+
__init6() {this.subscribe = (listener) => {
|
|
8160
8196
|
this.listeners.add(listener);
|
|
8161
8197
|
return () => {
|
|
8162
8198
|
this.listeners.delete(listener);
|
|
8163
8199
|
};
|
|
8164
8200
|
}}
|
|
8165
|
-
|
|
8166
|
-
/** Loads the cached copy (if it was fetched from the same URL), then fetches. */
|
|
8201
|
+
__init7() {this.getSnapshot = () => this.snapshot}
|
|
8202
|
+
/** Loads the cached copy (if it was fetched from the same URL and still checks out), then fetches. */
|
|
8167
8203
|
async start() {
|
|
8168
8204
|
const { url, cache: cache2 } = this.options;
|
|
8169
8205
|
if (!url) return;
|
|
8170
|
-
const cached = await _optionalChain([cache2, 'optionalAccess',
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
this.
|
|
8206
|
+
const cached = await _optionalChain([cache2, 'optionalAccess', _225 => _225.read, 'call', _226 => _226(), 'access', _227 => _227.catch, 'call', _228 => _228(() => null)]);
|
|
8207
|
+
const bundle = _optionalChain([cached, 'optionalAccess', _229 => _229.url]) === url ? revalidateBundle(cached.bundle) : void 0;
|
|
8208
|
+
if (cached && bundle && !this.snapshot.fetchedAt) {
|
|
8209
|
+
this.lastJson = JSON.stringify(bundle);
|
|
8210
|
+
this.set({ bundle, source: "cache", fetchedAt: cached.fetchedAt, revision: cached.revision });
|
|
8174
8211
|
}
|
|
8175
8212
|
await this.refresh();
|
|
8176
8213
|
}
|
|
8177
8214
|
/** Fetches now. Concurrent calls share one fetch. Only notifies listeners when something changed. */
|
|
8178
8215
|
refresh() {
|
|
8179
|
-
const { url, cache: cache2, fetchJson } = this.options;
|
|
8180
|
-
if (!url) return Promise.resolve();
|
|
8216
|
+
const { url, cache: cache2, fetchJson, timeoutMs = DEFAULT_TIMEOUT_MS } = this.options;
|
|
8217
|
+
if (!url || this.disposed) return Promise.resolve();
|
|
8181
8218
|
this.inflight ??= (async () => {
|
|
8219
|
+
const controller = new AbortController();
|
|
8220
|
+
this.controller = controller;
|
|
8221
|
+
let timer;
|
|
8222
|
+
const abandoned = new Promise((resolve) => {
|
|
8223
|
+
const fail = (message) => resolve({ issues: [{ severity: "error", path: fileName(url), message }], unreachable: true });
|
|
8224
|
+
timer = setTimeout(() => {
|
|
8225
|
+
fail(`no answer in ${timeoutMs / 1e3}s`);
|
|
8226
|
+
controller.abort();
|
|
8227
|
+
}, timeoutMs);
|
|
8228
|
+
controller.signal.addEventListener("abort", () => fail("cancelled"));
|
|
8229
|
+
});
|
|
8182
8230
|
try {
|
|
8183
|
-
const
|
|
8231
|
+
const result = await Promise.race([fetchBundle(url, fetchJson, controller.signal), abandoned]);
|
|
8232
|
+
if (this.disposed) return;
|
|
8233
|
+
const { bundle, issues, revision, unreachable } = result;
|
|
8184
8234
|
if (!bundle) {
|
|
8185
8235
|
const errors = issues.filter((i) => i.severity === "error").length;
|
|
8186
|
-
|
|
8236
|
+
const error = unreachable ? _optionalChain([issues, 'access', _230 => _230[0], 'optionalAccess', _231 => _231.message]) : errors === 1 ? "1 error" : `${errors} errors`;
|
|
8237
|
+
return this.set(
|
|
8238
|
+
{ loading: false, error, unreachable: !!unreachable, issues },
|
|
8239
|
+
this.snapshot.loading || error !== this.snapshot.error || !!unreachable !== !!this.snapshot.unreachable || !sameIssues(issues, this.snapshot.issues)
|
|
8240
|
+
);
|
|
8187
8241
|
}
|
|
8188
8242
|
const json = JSON.stringify(bundle);
|
|
8189
8243
|
const changed = json !== this.lastJson;
|
|
8190
8244
|
this.lastJson = json;
|
|
8191
8245
|
const fetchedAt = Date.now();
|
|
8192
|
-
if (changed || revision !== this.snapshot.revision) _optionalChain([cache2, 'optionalAccess',
|
|
8246
|
+
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
8247
|
})]);
|
|
8194
8248
|
this.set(
|
|
8195
|
-
{ ...changed && { bundle }, source: "remote", fetchedAt, revision, loading: false, error: void 0, issues },
|
|
8249
|
+
{ ...changed && { bundle }, source: "remote", fetchedAt, revision, loading: false, error: void 0, unreachable: void 0, issues },
|
|
8196
8250
|
changed || revision !== this.snapshot.revision || this.snapshot.source !== "remote" || !!this.snapshot.error || this.snapshot.loading || !sameIssues(issues, this.snapshot.issues)
|
|
8197
8251
|
);
|
|
8198
8252
|
} finally {
|
|
8253
|
+
clearTimeout(timer);
|
|
8254
|
+
if (this.controller === controller) this.controller = void 0;
|
|
8199
8255
|
this.inflight = void 0;
|
|
8200
8256
|
}
|
|
8201
8257
|
})();
|
|
8202
8258
|
return this.inflight;
|
|
8203
8259
|
}
|
|
8260
|
+
/** Stops the loader: cancels a fetch in flight, and nothing it does afterwards changes the state or the cache. */
|
|
8261
|
+
dispose() {
|
|
8262
|
+
this.disposed = true;
|
|
8263
|
+
_optionalChain([this, 'access', _236 => _236.controller, 'optionalAccess', _237 => _237.abort, 'call', _238 => _238()]);
|
|
8264
|
+
this.listeners.clear();
|
|
8265
|
+
}
|
|
8204
8266
|
/** `notify: false` drops the patch, so the snapshot only changes when listeners hear about it. */
|
|
8205
8267
|
set(patch, notify = true) {
|
|
8206
|
-
if (!notify) return;
|
|
8268
|
+
if (!notify || this.disposed) return;
|
|
8207
8269
|
this.snapshot = { ...this.snapshot, ...patch };
|
|
8208
8270
|
this.listeners.forEach((l) => l());
|
|
8209
8271
|
}
|
|
@@ -8219,7 +8281,7 @@ function tabIdFor(title, taken) {
|
|
|
8219
8281
|
}
|
|
8220
8282
|
function screenOfType(type, from, docs) {
|
|
8221
8283
|
const shown = from ? screenDocuments(from) : [];
|
|
8222
|
-
const firstOf = (ids) => _nullishCoalesce(_nullishCoalesce(_optionalChain([shown, 'access',
|
|
8284
|
+
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
8285
|
switch (type) {
|
|
8224
8286
|
case "dashboard":
|
|
8225
8287
|
return { type, dashboard: firstOf(docs.dashboards) };
|
|
@@ -8232,7 +8294,7 @@ function screenOfType(type, from, docs) {
|
|
|
8232
8294
|
}
|
|
8233
8295
|
}
|
|
8234
8296
|
function screenDocuments(screen) {
|
|
8235
|
-
switch (_optionalChain([screen, 'optionalAccess',
|
|
8297
|
+
switch (_optionalChain([screen, 'optionalAccess', _242 => _242.type])) {
|
|
8236
8298
|
case "dashboard":
|
|
8237
8299
|
return [{ id: screen.dashboard, kind: "dashboard" }];
|
|
8238
8300
|
case "forms":
|
|
@@ -9647,8 +9709,8 @@ function removeNode(text, path) {
|
|
|
9647
9709
|
const tree = parseTree2(text);
|
|
9648
9710
|
const value = tree && findNodeAtLocation2(tree, path);
|
|
9649
9711
|
if (!value) return text;
|
|
9650
|
-
const node = _optionalChain([value, 'access',
|
|
9651
|
-
const siblings = _nullishCoalesce(_optionalChain([node, 'access',
|
|
9712
|
+
const node = _optionalChain([value, 'access', _243 => _243.parent, 'optionalAccess', _244 => _244.type]) === "property" ? value.parent : value;
|
|
9713
|
+
const siblings = _nullishCoalesce(_optionalChain([node, 'access', _245 => _245.parent, 'optionalAccess', _246 => _246.children]), () => ( []));
|
|
9652
9714
|
const i = siblings.indexOf(node);
|
|
9653
9715
|
const next = siblings[i + 1];
|
|
9654
9716
|
const prev = siblings[i - 1];
|
|
@@ -9719,7 +9781,7 @@ function parseManifest(text) {
|
|
|
9719
9781
|
let value;
|
|
9720
9782
|
try {
|
|
9721
9783
|
value = JSON.parse(text);
|
|
9722
|
-
} catch (
|
|
9784
|
+
} catch (e13) {
|
|
9723
9785
|
throw new Error("The manifest isn\u2019t valid JSON");
|
|
9724
9786
|
}
|
|
9725
9787
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The manifest isn\u2019t an object");
|
|
@@ -9731,20 +9793,20 @@ function removeDocumentFromManifest(text, id) {
|
|
|
9731
9793
|
const edits = [];
|
|
9732
9794
|
const removedTabs = [];
|
|
9733
9795
|
for (let i = tabs.length - 1; i >= 0; i--) {
|
|
9734
|
-
const screen = _optionalChain([tabs, 'access',
|
|
9796
|
+
const screen = _optionalChain([tabs, 'access', _247 => _247[i], 'optionalAccess', _248 => _248.screen]);
|
|
9735
9797
|
const at = ["tabs", i, "screen"];
|
|
9736
9798
|
const removeTab = () => {
|
|
9737
9799
|
edits.push({ path: ["tabs", i], remove: true });
|
|
9738
9800
|
removedTabs.unshift(_nullishCoalesce(tabs[i].title, () => ( tabs[i].id)));
|
|
9739
9801
|
};
|
|
9740
|
-
if (_optionalChain([screen, 'optionalAccess',
|
|
9741
|
-
else if (_optionalChain([screen, 'optionalAccess',
|
|
9802
|
+
if (_optionalChain([screen, 'optionalAccess', _249 => _249.type]) === "dashboard" && screen.dashboard === id) removeTab();
|
|
9803
|
+
else if (_optionalChain([screen, 'optionalAccess', _250 => _250.type]) === "forms" && Array.isArray(screen.forms) && screen.forms.includes(id)) {
|
|
9742
9804
|
if (screen.forms.every((f) => f === id)) removeTab();
|
|
9743
9805
|
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',
|
|
9806
|
+
} else if (_optionalChain([screen, 'optionalAccess', _251 => _251.type]) === "menu" && Array.isArray(screen.items))
|
|
9745
9807
|
for (let j = screen.items.length - 1; j >= 0; j--) {
|
|
9746
9808
|
const item = screen.items[j];
|
|
9747
|
-
if (_optionalChain([item, 'optionalAccess',
|
|
9809
|
+
if (_optionalChain([item, 'optionalAccess', _252 => _252.dashboard]) === id || _optionalChain([item, 'optionalAccess', _253 => _253.form]) === id) edits.push({ path: [...at, "items", j], remove: true });
|
|
9748
9810
|
}
|
|
9749
9811
|
}
|
|
9750
9812
|
if (tabs.length && removedTabs.length === tabs.length) throw new Error(`Every tab shows only "${id}". Add another tab first`);
|
|
@@ -9757,21 +9819,21 @@ function renameDocumentInManifest(text, from, to, path) {
|
|
|
9757
9819
|
if (to !== from && to in manifest.documents) throw new Error(`There\u2019s already a document "${to}"`);
|
|
9758
9820
|
const edits = [];
|
|
9759
9821
|
(Array.isArray(manifest.tabs) ? manifest.tabs : []).forEach((tab, i) => {
|
|
9760
|
-
const screen = _optionalChain([tab, 'optionalAccess',
|
|
9822
|
+
const screen = _optionalChain([tab, 'optionalAccess', _254 => _254.screen]);
|
|
9761
9823
|
const at = ["tabs", i, "screen"];
|
|
9762
|
-
if (_optionalChain([screen, 'optionalAccess',
|
|
9763
|
-
if (_optionalChain([screen, 'optionalAccess',
|
|
9824
|
+
if (_optionalChain([screen, 'optionalAccess', _255 => _255.type]) === "dashboard" && screen.dashboard === from) edits.push({ path: [...at, "dashboard"], value: to });
|
|
9825
|
+
if (_optionalChain([screen, 'optionalAccess', _256 => _256.type]) === "forms" && Array.isArray(screen.forms))
|
|
9764
9826
|
screen.forms.forEach((f, j) => f === from && edits.push({ path: [...at, "forms", j], value: to }));
|
|
9765
|
-
if (_optionalChain([screen, 'optionalAccess',
|
|
9827
|
+
if (_optionalChain([screen, 'optionalAccess', _257 => _257.type]) === "menu" && Array.isArray(screen.items))
|
|
9766
9828
|
screen.items.forEach((item, j) => {
|
|
9767
|
-
if (_optionalChain([item, 'optionalAccess',
|
|
9768
|
-
if (_optionalChain([item, 'optionalAccess',
|
|
9829
|
+
if (_optionalChain([item, 'optionalAccess', _258 => _258.dashboard]) === from) edits.push({ path: [...at, "items", j, "dashboard"], value: to });
|
|
9830
|
+
if (_optionalChain([item, 'optionalAccess', _259 => _259.form]) === from) edits.push({ path: [...at, "items", j, "form"], value: to });
|
|
9769
9831
|
});
|
|
9770
9832
|
});
|
|
9771
9833
|
if (path !== void 0) edits.push({ path: ["documents", from], value: path });
|
|
9772
9834
|
let out = applyJsonEdits(text, edits);
|
|
9773
9835
|
if (to !== from) {
|
|
9774
|
-
const key = _optionalChain([findNodeAtLocation2, 'call',
|
|
9836
|
+
const key = _optionalChain([findNodeAtLocation2, 'call', _260 => _260(parseTree2(out), ["documents", from]), 'optionalAccess', _261 => _261.parent, 'optionalAccess', _262 => _262.children, 'optionalAccess', _263 => _263[0]]);
|
|
9775
9837
|
if (key) out = out.slice(0, key.offset) + JSON.stringify(to) + out.slice(key.offset + key.length);
|
|
9776
9838
|
}
|
|
9777
9839
|
return out;
|
|
@@ -9781,7 +9843,7 @@ function parse2(text) {
|
|
|
9781
9843
|
try {
|
|
9782
9844
|
const d = JSON.parse(text);
|
|
9783
9845
|
return d && Array.isArray(d.panels) && d.panels.every((p) => p && typeof p === "object") ? d : void 0;
|
|
9784
|
-
} catch (
|
|
9846
|
+
} catch (e14) {
|
|
9785
9847
|
return void 0;
|
|
9786
9848
|
}
|
|
9787
9849
|
}
|
|
@@ -9790,16 +9852,16 @@ function inputs(text) {
|
|
|
9790
9852
|
const out = /* @__PURE__ */ new Map();
|
|
9791
9853
|
try {
|
|
9792
9854
|
if (d) {
|
|
9793
|
-
for (const p of inputPanels(d)) if (typeof p.id === "number" && typeof _optionalChain([p, 'access',
|
|
9855
|
+
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
9856
|
}
|
|
9795
|
-
} catch (
|
|
9857
|
+
} catch (e15) {
|
|
9796
9858
|
}
|
|
9797
9859
|
return out;
|
|
9798
9860
|
}
|
|
9799
9861
|
function reads(text, metric) {
|
|
9800
9862
|
const d = parse2(text);
|
|
9801
9863
|
const panels = d ? d.panels.flatMap((p) => p.type === "row" ? [p, ..._nullishCoalesce(p.panels, () => ( []))] : [p]) : [];
|
|
9802
|
-
return panels.some((p) => (_nullishCoalesce(_optionalChain([p, 'optionalAccess',
|
|
9864
|
+
return panels.some((p) => (_nullishCoalesce(_optionalChain([p, 'optionalAccess', _266 => _266.targets]), () => ( []))).some((t) => t.metric === metric));
|
|
9803
9865
|
}
|
|
9804
9866
|
function metricChanges(before, after) {
|
|
9805
9867
|
const merged = { ...before, ...after };
|
|
@@ -9814,7 +9876,7 @@ function metricChanges(before, after) {
|
|
|
9814
9876
|
for (const [file, text] of Object.entries(after)) {
|
|
9815
9877
|
const old = inputs(before[file]);
|
|
9816
9878
|
for (const [id, input] of inputs(text))
|
|
9817
|
-
if (_optionalChain([old, 'access',
|
|
9879
|
+
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
9880
|
}
|
|
9819
9881
|
changes.push(_nullishCoalesce(rename, () => ( { metric, readBy })));
|
|
9820
9882
|
}
|
|
@@ -9854,14 +9916,14 @@ function variableWithType(v, type) {
|
|
|
9854
9916
|
}
|
|
9855
9917
|
function currentFor(v, value) {
|
|
9856
9918
|
const options = variableOptions({ ...v, current: void 0 });
|
|
9857
|
-
const text = (x) => x === ALL ? "All" : _nullishCoalesce(_optionalChain([options, 'access',
|
|
9919
|
+
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
9920
|
return Array.isArray(value) ? { text: value.map(text), value } : { text: text(value), value };
|
|
9859
9921
|
}
|
|
9860
9922
|
function variableWithQuery(v, query) {
|
|
9861
9923
|
const { options: _, current, ...rest } = v;
|
|
9862
9924
|
const next = { ...rest, query };
|
|
9863
9925
|
if (v.type === "textbox" || v.type === "constant") return { ...next, current: { text: query, value: query } };
|
|
9864
|
-
const value = selectValue(next, _optionalChain([current, 'optionalAccess',
|
|
9926
|
+
const value = selectValue(next, _optionalChain([current, 'optionalAccess', _273 => _273.value]), variableOptions(next));
|
|
9865
9927
|
return { ...next, current: currentFor(next, value) };
|
|
9866
9928
|
}
|
|
9867
9929
|
function variableWithCurrent(v, value) {
|
|
@@ -9871,13 +9933,13 @@ function variableWithFlags(v, flags) {
|
|
|
9871
9933
|
const next = { ...v, ...flags };
|
|
9872
9934
|
if (!next.multi) delete next.multi;
|
|
9873
9935
|
if (!next.includeAll) delete next.includeAll;
|
|
9874
|
-
const raw = _optionalChain([v, 'access',
|
|
9936
|
+
const raw = _optionalChain([v, 'access', _274 => _274.current, 'optionalAccess', _275 => _275.value]);
|
|
9875
9937
|
const current = next.multi ? raw == null ? [] : Array.isArray(raw) ? raw : [raw] : Array.isArray(raw) ? raw[0] : raw;
|
|
9876
9938
|
return variableWithCurrent(next, selectValue(next, current, variableOptions({ ...next, current: void 0 })));
|
|
9877
9939
|
}
|
|
9878
9940
|
var refers = (name, flags) => new RegExp(`\\$${name}\\b|\\$\\{${name}(:\\w+)?\\}|\\[\\[${name}(:\\w+)?\\]\\]`, flags);
|
|
9879
9941
|
function allPanels2(dashboard) {
|
|
9880
|
-
return (_nullishCoalesce(dashboard.panels, () => ( []))).flatMap((p) => _optionalChain([p, 'optionalAccess',
|
|
9942
|
+
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
9943
|
}
|
|
9882
9944
|
function variableUses(dashboard, name) {
|
|
9883
9945
|
const re = refers(name);
|
|
@@ -9949,7 +10011,7 @@ function locate(text, tree, path) {
|
|
|
9949
10011
|
for (let n = segs.length; n >= 0; n--) {
|
|
9950
10012
|
const node = findNodeAtLocation2(tree, segs.slice(0, n));
|
|
9951
10013
|
if (!node) continue;
|
|
9952
|
-
const key = _optionalChain([node, 'access',
|
|
10014
|
+
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
10015
|
if ((node.type === "object" || node.type === "array") && key) return located(text, key.offset, key.length);
|
|
9954
10016
|
if (node.type === "object" || node.type === "array") return located(text, node.offset, 1);
|
|
9955
10017
|
return located(text, node.offset, node.length);
|
|
@@ -10069,16 +10131,16 @@ async function errorText(res) {
|
|
|
10069
10131
|
const body = await res.text();
|
|
10070
10132
|
try {
|
|
10071
10133
|
return _nullishCoalesce(JSON.parse(body).error, () => ( body));
|
|
10072
|
-
} catch (
|
|
10134
|
+
} catch (e16) {
|
|
10073
10135
|
return body || `HTTP ${res.status}`;
|
|
10074
10136
|
}
|
|
10075
10137
|
}
|
|
10076
10138
|
async function authHeaders(token) {
|
|
10077
|
-
const t = await _optionalChain([token, 'optionalCall',
|
|
10139
|
+
const t = await _optionalChain([token, 'optionalCall', _282 => _282()]);
|
|
10078
10140
|
return t ? { Authorization: `Bearer ${t}` } : {};
|
|
10079
10141
|
}
|
|
10080
10142
|
var HttpConfigFiles = (_class3 = class {
|
|
10081
|
-
constructor(manifestUrl, token) {;_class3.prototype.
|
|
10143
|
+
constructor(manifestUrl, token) {;_class3.prototype.__init8.call(this);
|
|
10082
10144
|
this.manifestUrl = manifestUrl;
|
|
10083
10145
|
this.token = token;
|
|
10084
10146
|
this.manifestPath = manifestUrl.replace(/[?#].*$/, "").split("/").pop() || "app.json";
|
|
@@ -10087,7 +10149,7 @@ var HttpConfigFiles = (_class3 = class {
|
|
|
10087
10149
|
|
|
10088
10150
|
|
|
10089
10151
|
/** The revision of each file as last read or saved here, by path relative to the manifest. */
|
|
10090
|
-
|
|
10152
|
+
__init8() {this.revisions = /* @__PURE__ */ new Map()}
|
|
10091
10153
|
|
|
10092
10154
|
/** The bundle's root URL, which its file paths are relative to. */
|
|
10093
10155
|
|
|
@@ -10107,7 +10169,7 @@ var HttpConfigFiles = (_class3 = class {
|
|
|
10107
10169
|
let body;
|
|
10108
10170
|
try {
|
|
10109
10171
|
body = JSON.parse(await res.text());
|
|
10110
|
-
} catch (
|
|
10172
|
+
} catch (e17) {
|
|
10111
10173
|
return null;
|
|
10112
10174
|
}
|
|
10113
10175
|
if (!isBundleResponse(body)) return null;
|
|
@@ -10177,27 +10239,23 @@ var HttpConfigFiles = (_class3 = class {
|
|
|
10177
10239
|
}
|
|
10178
10240
|
}, _class3);
|
|
10179
10241
|
function fetchJsonWithToken(token) {
|
|
10180
|
-
return
|
|
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
|
-
};
|
|
10242
|
+
return httpFetchJson({ headers: () => authHeaders(token), httpError: (status) => status === 401 ? "not signed in" : `HTTP ${status}` });
|
|
10185
10243
|
}
|
|
10186
10244
|
async function readConfigFiles(source) {
|
|
10187
|
-
const all = await _optionalChain([source, 'access',
|
|
10245
|
+
const all = await _optionalChain([source, 'access', _283 => _283.readAll, 'optionalCall', _284 => _284()]);
|
|
10188
10246
|
const read = all ? async (p) => {
|
|
10189
10247
|
if (!(p in all)) throw new Error(NOT_FOUND);
|
|
10190
10248
|
return all[p];
|
|
10191
10249
|
} : (p) => source.read(p);
|
|
10192
10250
|
const files = { [source.manifestPath]: await read(source.manifestPath) };
|
|
10193
10251
|
const { value } = parseJsonText(files[source.manifestPath]);
|
|
10194
|
-
const documents = _nullishCoalesce(_optionalChain([value, 'optionalAccess',
|
|
10252
|
+
const documents = _nullishCoalesce(_optionalChain([value, 'optionalAccess', _285 => _285.documents]), () => ( {}));
|
|
10195
10253
|
const paths = [...new Set(Object.values(documents).filter((d) => typeof d === "string"))];
|
|
10196
10254
|
await Promise.all(
|
|
10197
10255
|
paths.map(async (p) => {
|
|
10198
10256
|
try {
|
|
10199
10257
|
files[p] = await read(p);
|
|
10200
|
-
} catch (
|
|
10258
|
+
} catch (e18) {
|
|
10201
10259
|
}
|
|
10202
10260
|
})
|
|
10203
10261
|
);
|
|
@@ -10245,7 +10303,7 @@ var CANVAS_ROW_HEADER = 32;
|
|
|
10245
10303
|
function panelSize(panel, mode) {
|
|
10246
10304
|
const p = pos(panel);
|
|
10247
10305
|
if (mode === "grid") return { span: clampW(p.w), h: clampH(p.h) };
|
|
10248
|
-
return { span: panelSpan(panel, "phone"), h: clampH(_nullishCoalesce(_optionalChain([panel, 'access',
|
|
10306
|
+
return { span: panelSpan(panel, "phone"), h: clampH(_nullishCoalesce(_optionalChain([panel, 'access', _286 => _286.mobile, 'optionalAccess', _287 => _287.h]), () => ( p.h))) };
|
|
10249
10307
|
}
|
|
10250
10308
|
function layoutCanvas(panels, order, mode, width, override) {
|
|
10251
10309
|
const colW = (width + CANVAS_GAP) / GRID_COLUMNS;
|
|
@@ -10282,11 +10340,11 @@ function layoutCanvas(panels, order, mode, width, override) {
|
|
|
10282
10340
|
y += CANVAS_ROW_HEADER + CANVAS_GAP;
|
|
10283
10341
|
continue;
|
|
10284
10342
|
}
|
|
10285
|
-
if (mode === "phone" && _optionalChain([panel, 'access',
|
|
10343
|
+
if (mode === "phone" && _optionalChain([panel, 'access', _288 => _288.mobile, 'optionalAccess', _289 => _289.hidden])) {
|
|
10286
10344
|
hidden.push(index);
|
|
10287
10345
|
continue;
|
|
10288
10346
|
}
|
|
10289
|
-
const size = _optionalChain([override, 'optionalAccess',
|
|
10347
|
+
const size = _optionalChain([override, 'optionalAccess', _290 => _290.index]) === index ? { span: clampW(override.span), h: clampH(override.h) } : panelSize(panel, mode);
|
|
10290
10348
|
if (used + size.span > GRID_COLUMNS) flush();
|
|
10291
10349
|
line.push({ index, row: false, x: 0, y: 0, width: 0, height: 0, ...size });
|
|
10292
10350
|
used += size.span;
|
|
@@ -10304,7 +10362,7 @@ function dropTarget(canvas, x, y, dragging) {
|
|
|
10304
10362
|
for (const c of pool) if (distance(c) < distance(best)) best = c;
|
|
10305
10363
|
const after = best.row ? y > best.y + best.height / 2 : x > best.x + best.width / 2;
|
|
10306
10364
|
if (!after) return best.index;
|
|
10307
|
-
return _nullishCoalesce(_optionalChain([items, 'access',
|
|
10365
|
+
return _nullishCoalesce(_optionalChain([items, 'access', _291 => _291[items.indexOf(best) + 1], 'optionalAccess', _292 => _292.index]), () => ( null));
|
|
10308
10366
|
}
|
|
10309
10367
|
function movePanel(panels, index, before) {
|
|
10310
10368
|
const order = readingOrder(panels).filter((i) => i !== index);
|
|
@@ -10627,4 +10685,6 @@ function sampleEntries(forms, metrics, now = Date.now(), days = 180) {
|
|
|
10627
10685
|
|
|
10628
10686
|
|
|
10629
10687
|
|
|
10630
|
-
|
|
10688
|
+
|
|
10689
|
+
|
|
10690
|
+
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.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.panelEdits = panelEdits; exports.sampleEntries = sampleEntries;
|