@modelform/react-native 0.3.0 → 0.4.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-PU7RRUV4.mjs → chunk-ATRMUHKJ.mjs} +258 -88
- package/dist/{chunk-HZEXKGDS.js → chunk-WMRDOYPV.js} +258 -88
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +12 -2
- package/dist/core/index.mjs +11 -1
- package/dist/core/layoutEdit.d.ts +3 -3
- package/dist/core/snippets.d.ts +64 -0
- package/dist/index.js +144 -134
- package/dist/index.mjs +11 -1
- package/package.json +1 -1
|
@@ -8347,12 +8347,12 @@ function documentUses(manifest) {
|
|
|
8347
8347
|
// node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
8348
8348
|
function createScanner(text, ignoreTrivia = false) {
|
|
8349
8349
|
const len = text.length;
|
|
8350
|
-
let
|
|
8350
|
+
let pos3 = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
8351
8351
|
function scanHexDigits(count, exact) {
|
|
8352
8352
|
let digits = 0;
|
|
8353
8353
|
let value2 = 0;
|
|
8354
8354
|
while (digits < count || !exact) {
|
|
8355
|
-
let ch = text.charCodeAt(
|
|
8355
|
+
let ch = text.charCodeAt(pos3);
|
|
8356
8356
|
if (ch >= 48 && ch <= 57) {
|
|
8357
8357
|
value2 = value2 * 16 + ch - 48;
|
|
8358
8358
|
} else if (ch >= 65 && ch <= 70) {
|
|
@@ -8362,7 +8362,7 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8362
8362
|
} else {
|
|
8363
8363
|
break;
|
|
8364
8364
|
}
|
|
8365
|
-
|
|
8365
|
+
pos3++;
|
|
8366
8366
|
digits++;
|
|
8367
8367
|
}
|
|
8368
8368
|
if (digits < count) {
|
|
@@ -8371,46 +8371,46 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8371
8371
|
return value2;
|
|
8372
8372
|
}
|
|
8373
8373
|
function setPosition(newPosition) {
|
|
8374
|
-
|
|
8374
|
+
pos3 = newPosition;
|
|
8375
8375
|
value = "";
|
|
8376
8376
|
tokenOffset = 0;
|
|
8377
8377
|
token = 16;
|
|
8378
8378
|
scanError = 0;
|
|
8379
8379
|
}
|
|
8380
8380
|
function scanNumber() {
|
|
8381
|
-
let start =
|
|
8382
|
-
if (text.charCodeAt(
|
|
8383
|
-
|
|
8381
|
+
let start = pos3;
|
|
8382
|
+
if (text.charCodeAt(pos3) === 48) {
|
|
8383
|
+
pos3++;
|
|
8384
8384
|
} else {
|
|
8385
|
-
|
|
8386
|
-
while (
|
|
8387
|
-
|
|
8385
|
+
pos3++;
|
|
8386
|
+
while (pos3 < text.length && isDigit(text.charCodeAt(pos3))) {
|
|
8387
|
+
pos3++;
|
|
8388
8388
|
}
|
|
8389
8389
|
}
|
|
8390
|
-
if (
|
|
8391
|
-
|
|
8392
|
-
if (
|
|
8393
|
-
|
|
8394
|
-
while (
|
|
8395
|
-
|
|
8390
|
+
if (pos3 < text.length && text.charCodeAt(pos3) === 46) {
|
|
8391
|
+
pos3++;
|
|
8392
|
+
if (pos3 < text.length && isDigit(text.charCodeAt(pos3))) {
|
|
8393
|
+
pos3++;
|
|
8394
|
+
while (pos3 < text.length && isDigit(text.charCodeAt(pos3))) {
|
|
8395
|
+
pos3++;
|
|
8396
8396
|
}
|
|
8397
8397
|
} else {
|
|
8398
8398
|
scanError = 3;
|
|
8399
|
-
return text.substring(start,
|
|
8399
|
+
return text.substring(start, pos3);
|
|
8400
8400
|
}
|
|
8401
8401
|
}
|
|
8402
|
-
let end =
|
|
8403
|
-
if (
|
|
8404
|
-
|
|
8405
|
-
if (
|
|
8406
|
-
|
|
8402
|
+
let end = pos3;
|
|
8403
|
+
if (pos3 < text.length && (text.charCodeAt(pos3) === 69 || text.charCodeAt(pos3) === 101)) {
|
|
8404
|
+
pos3++;
|
|
8405
|
+
if (pos3 < text.length && text.charCodeAt(pos3) === 43 || text.charCodeAt(pos3) === 45) {
|
|
8406
|
+
pos3++;
|
|
8407
8407
|
}
|
|
8408
|
-
if (
|
|
8409
|
-
|
|
8410
|
-
while (
|
|
8411
|
-
|
|
8408
|
+
if (pos3 < text.length && isDigit(text.charCodeAt(pos3))) {
|
|
8409
|
+
pos3++;
|
|
8410
|
+
while (pos3 < text.length && isDigit(text.charCodeAt(pos3))) {
|
|
8411
|
+
pos3++;
|
|
8412
8412
|
}
|
|
8413
|
-
end =
|
|
8413
|
+
end = pos3;
|
|
8414
8414
|
} else {
|
|
8415
8415
|
scanError = 3;
|
|
8416
8416
|
}
|
|
@@ -8418,27 +8418,27 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8418
8418
|
return text.substring(start, end);
|
|
8419
8419
|
}
|
|
8420
8420
|
function scanString() {
|
|
8421
|
-
let result = "", start =
|
|
8421
|
+
let result = "", start = pos3;
|
|
8422
8422
|
while (true) {
|
|
8423
|
-
if (
|
|
8424
|
-
result += text.substring(start,
|
|
8423
|
+
if (pos3 >= len) {
|
|
8424
|
+
result += text.substring(start, pos3);
|
|
8425
8425
|
scanError = 2;
|
|
8426
8426
|
break;
|
|
8427
8427
|
}
|
|
8428
|
-
const ch = text.charCodeAt(
|
|
8428
|
+
const ch = text.charCodeAt(pos3);
|
|
8429
8429
|
if (ch === 34) {
|
|
8430
|
-
result += text.substring(start,
|
|
8431
|
-
|
|
8430
|
+
result += text.substring(start, pos3);
|
|
8431
|
+
pos3++;
|
|
8432
8432
|
break;
|
|
8433
8433
|
}
|
|
8434
8434
|
if (ch === 92) {
|
|
8435
|
-
result += text.substring(start,
|
|
8436
|
-
|
|
8437
|
-
if (
|
|
8435
|
+
result += text.substring(start, pos3);
|
|
8436
|
+
pos3++;
|
|
8437
|
+
if (pos3 >= len) {
|
|
8438
8438
|
scanError = 2;
|
|
8439
8439
|
break;
|
|
8440
8440
|
}
|
|
8441
|
-
const ch2 = text.charCodeAt(
|
|
8441
|
+
const ch2 = text.charCodeAt(pos3++);
|
|
8442
8442
|
switch (ch2) {
|
|
8443
8443
|
case 34:
|
|
8444
8444
|
result += '"';
|
|
@@ -8475,126 +8475,126 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8475
8475
|
default:
|
|
8476
8476
|
scanError = 5;
|
|
8477
8477
|
}
|
|
8478
|
-
start =
|
|
8478
|
+
start = pos3;
|
|
8479
8479
|
continue;
|
|
8480
8480
|
}
|
|
8481
8481
|
if (ch >= 0 && ch <= 31) {
|
|
8482
8482
|
if (isLineBreak(ch)) {
|
|
8483
|
-
result += text.substring(start,
|
|
8483
|
+
result += text.substring(start, pos3);
|
|
8484
8484
|
scanError = 2;
|
|
8485
8485
|
break;
|
|
8486
8486
|
} else {
|
|
8487
8487
|
scanError = 6;
|
|
8488
8488
|
}
|
|
8489
8489
|
}
|
|
8490
|
-
|
|
8490
|
+
pos3++;
|
|
8491
8491
|
}
|
|
8492
8492
|
return result;
|
|
8493
8493
|
}
|
|
8494
8494
|
function scanNext() {
|
|
8495
8495
|
value = "";
|
|
8496
8496
|
scanError = 0;
|
|
8497
|
-
tokenOffset =
|
|
8497
|
+
tokenOffset = pos3;
|
|
8498
8498
|
lineStartOffset = lineNumber;
|
|
8499
8499
|
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
8500
|
-
if (
|
|
8500
|
+
if (pos3 >= len) {
|
|
8501
8501
|
tokenOffset = len;
|
|
8502
8502
|
return token = 17;
|
|
8503
8503
|
}
|
|
8504
|
-
let code = text.charCodeAt(
|
|
8504
|
+
let code = text.charCodeAt(pos3);
|
|
8505
8505
|
if (isWhiteSpace(code)) {
|
|
8506
8506
|
do {
|
|
8507
|
-
|
|
8507
|
+
pos3++;
|
|
8508
8508
|
value += String.fromCharCode(code);
|
|
8509
|
-
code = text.charCodeAt(
|
|
8509
|
+
code = text.charCodeAt(pos3);
|
|
8510
8510
|
} while (isWhiteSpace(code));
|
|
8511
8511
|
return token = 15;
|
|
8512
8512
|
}
|
|
8513
8513
|
if (isLineBreak(code)) {
|
|
8514
|
-
|
|
8514
|
+
pos3++;
|
|
8515
8515
|
value += String.fromCharCode(code);
|
|
8516
|
-
if (code === 13 && text.charCodeAt(
|
|
8517
|
-
|
|
8516
|
+
if (code === 13 && text.charCodeAt(pos3) === 10) {
|
|
8517
|
+
pos3++;
|
|
8518
8518
|
value += "\n";
|
|
8519
8519
|
}
|
|
8520
8520
|
lineNumber++;
|
|
8521
|
-
tokenLineStartOffset =
|
|
8521
|
+
tokenLineStartOffset = pos3;
|
|
8522
8522
|
return token = 14;
|
|
8523
8523
|
}
|
|
8524
8524
|
switch (code) {
|
|
8525
8525
|
// tokens: []{}:,
|
|
8526
8526
|
case 123:
|
|
8527
|
-
|
|
8527
|
+
pos3++;
|
|
8528
8528
|
return token = 1;
|
|
8529
8529
|
case 125:
|
|
8530
|
-
|
|
8530
|
+
pos3++;
|
|
8531
8531
|
return token = 2;
|
|
8532
8532
|
case 91:
|
|
8533
|
-
|
|
8533
|
+
pos3++;
|
|
8534
8534
|
return token = 3;
|
|
8535
8535
|
case 93:
|
|
8536
|
-
|
|
8536
|
+
pos3++;
|
|
8537
8537
|
return token = 4;
|
|
8538
8538
|
case 58:
|
|
8539
|
-
|
|
8539
|
+
pos3++;
|
|
8540
8540
|
return token = 6;
|
|
8541
8541
|
case 44:
|
|
8542
|
-
|
|
8542
|
+
pos3++;
|
|
8543
8543
|
return token = 5;
|
|
8544
8544
|
// strings
|
|
8545
8545
|
case 34:
|
|
8546
|
-
|
|
8546
|
+
pos3++;
|
|
8547
8547
|
value = scanString();
|
|
8548
8548
|
return token = 10;
|
|
8549
8549
|
// comments
|
|
8550
8550
|
case 47:
|
|
8551
|
-
const start =
|
|
8552
|
-
if (text.charCodeAt(
|
|
8553
|
-
|
|
8554
|
-
while (
|
|
8555
|
-
if (isLineBreak(text.charCodeAt(
|
|
8551
|
+
const start = pos3 - 1;
|
|
8552
|
+
if (text.charCodeAt(pos3 + 1) === 47) {
|
|
8553
|
+
pos3 += 2;
|
|
8554
|
+
while (pos3 < len) {
|
|
8555
|
+
if (isLineBreak(text.charCodeAt(pos3))) {
|
|
8556
8556
|
break;
|
|
8557
8557
|
}
|
|
8558
|
-
|
|
8558
|
+
pos3++;
|
|
8559
8559
|
}
|
|
8560
|
-
value = text.substring(start,
|
|
8560
|
+
value = text.substring(start, pos3);
|
|
8561
8561
|
return token = 12;
|
|
8562
8562
|
}
|
|
8563
|
-
if (text.charCodeAt(
|
|
8564
|
-
|
|
8563
|
+
if (text.charCodeAt(pos3 + 1) === 42) {
|
|
8564
|
+
pos3 += 2;
|
|
8565
8565
|
const safeLength = len - 1;
|
|
8566
8566
|
let commentClosed = false;
|
|
8567
|
-
while (
|
|
8568
|
-
const ch = text.charCodeAt(
|
|
8569
|
-
if (ch === 42 && text.charCodeAt(
|
|
8570
|
-
|
|
8567
|
+
while (pos3 < safeLength) {
|
|
8568
|
+
const ch = text.charCodeAt(pos3);
|
|
8569
|
+
if (ch === 42 && text.charCodeAt(pos3 + 1) === 47) {
|
|
8570
|
+
pos3 += 2;
|
|
8571
8571
|
commentClosed = true;
|
|
8572
8572
|
break;
|
|
8573
8573
|
}
|
|
8574
|
-
|
|
8574
|
+
pos3++;
|
|
8575
8575
|
if (isLineBreak(ch)) {
|
|
8576
|
-
if (ch === 13 && text.charCodeAt(
|
|
8577
|
-
|
|
8576
|
+
if (ch === 13 && text.charCodeAt(pos3) === 10) {
|
|
8577
|
+
pos3++;
|
|
8578
8578
|
}
|
|
8579
8579
|
lineNumber++;
|
|
8580
|
-
tokenLineStartOffset =
|
|
8580
|
+
tokenLineStartOffset = pos3;
|
|
8581
8581
|
}
|
|
8582
8582
|
}
|
|
8583
8583
|
if (!commentClosed) {
|
|
8584
|
-
|
|
8584
|
+
pos3++;
|
|
8585
8585
|
scanError = 1;
|
|
8586
8586
|
}
|
|
8587
|
-
value = text.substring(start,
|
|
8587
|
+
value = text.substring(start, pos3);
|
|
8588
8588
|
return token = 13;
|
|
8589
8589
|
}
|
|
8590
8590
|
value += String.fromCharCode(code);
|
|
8591
|
-
|
|
8591
|
+
pos3++;
|
|
8592
8592
|
return token = 16;
|
|
8593
8593
|
// numbers
|
|
8594
8594
|
case 45:
|
|
8595
8595
|
value += String.fromCharCode(code);
|
|
8596
|
-
|
|
8597
|
-
if (
|
|
8596
|
+
pos3++;
|
|
8597
|
+
if (pos3 === len || !isDigit(text.charCodeAt(pos3))) {
|
|
8598
8598
|
return token = 16;
|
|
8599
8599
|
}
|
|
8600
8600
|
// found a minus, followed by a number so
|
|
@@ -8614,12 +8614,12 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8614
8614
|
return token = 11;
|
|
8615
8615
|
// literals and unknown symbols
|
|
8616
8616
|
default:
|
|
8617
|
-
while (
|
|
8618
|
-
|
|
8619
|
-
code = text.charCodeAt(
|
|
8617
|
+
while (pos3 < len && isUnknownContentCharacter(code)) {
|
|
8618
|
+
pos3++;
|
|
8619
|
+
code = text.charCodeAt(pos3);
|
|
8620
8620
|
}
|
|
8621
|
-
if (tokenOffset !==
|
|
8622
|
-
value = text.substring(tokenOffset,
|
|
8621
|
+
if (tokenOffset !== pos3) {
|
|
8622
|
+
value = text.substring(tokenOffset, pos3);
|
|
8623
8623
|
switch (value) {
|
|
8624
8624
|
case "true":
|
|
8625
8625
|
return token = 8;
|
|
@@ -8631,7 +8631,7 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8631
8631
|
return token = 16;
|
|
8632
8632
|
}
|
|
8633
8633
|
value += String.fromCharCode(code);
|
|
8634
|
-
|
|
8634
|
+
pos3++;
|
|
8635
8635
|
return token = 16;
|
|
8636
8636
|
}
|
|
8637
8637
|
}
|
|
@@ -8661,12 +8661,12 @@ function createScanner(text, ignoreTrivia = false) {
|
|
|
8661
8661
|
}
|
|
8662
8662
|
return {
|
|
8663
8663
|
setPosition,
|
|
8664
|
-
getPosition: () =>
|
|
8664
|
+
getPosition: () => pos3,
|
|
8665
8665
|
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
8666
8666
|
getToken: () => token,
|
|
8667
8667
|
getTokenValue: () => value,
|
|
8668
8668
|
getTokenOffset: () => tokenOffset,
|
|
8669
|
-
getTokenLength: () =>
|
|
8669
|
+
getTokenLength: () => pos3 - tokenOffset,
|
|
8670
8670
|
getTokenStartLine: () => lineStartOffset,
|
|
8671
8671
|
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
8672
8672
|
getTokenError: () => scanError
|
|
@@ -10492,7 +10492,8 @@ function collapseRow(panels, index) {
|
|
|
10492
10492
|
var bottom = (panels) => Math.max(0, ...panels.map((p) => pos(p).y + pos(p).h));
|
|
10493
10493
|
var gridBoxes = (panels) => panels.map((p) => isRow(p) ? { ...pos(p), x: 0, w: GRID_COLUMNS, h: 1 } : pos(p));
|
|
10494
10494
|
function settleBoxes(boxes, fixed2) {
|
|
10495
|
-
const
|
|
10495
|
+
const keep = new Set(fixed2 === void 0 ? [] : [fixed2].flat());
|
|
10496
|
+
const made = keep.size ? compactGrid(boxes, keep) : boxes;
|
|
10496
10497
|
return compactGrid(made);
|
|
10497
10498
|
}
|
|
10498
10499
|
function writeBoxes(panels, boxes) {
|
|
@@ -10601,6 +10602,170 @@ function sampleEntries(forms, metrics, now = Date.now(), days = 180) {
|
|
|
10601
10602
|
return out;
|
|
10602
10603
|
}
|
|
10603
10604
|
|
|
10605
|
+
// src/core/snippets.ts
|
|
10606
|
+
var SNIPPET_VERSION = 1;
|
|
10607
|
+
var DEFAULT_POS2 = { x: 0, y: 0, w: GRID_COLUMNS, h: 4 };
|
|
10608
|
+
var pos2 = (p) => ({ ...DEFAULT_POS2, ...p.gridPos });
|
|
10609
|
+
var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
10610
|
+
var refers2 = (name) => new RegExp(`\\$${name}\\b|\\$\\{${name}(:\\w+)?\\}|\\[\\[${name}(:\\w+)?\\]\\]`);
|
|
10611
|
+
var withChildren = (p) => [p, ...isRow(p) ? p.panels ?? [] : []];
|
|
10612
|
+
function panelMetrics(p) {
|
|
10613
|
+
const found = [];
|
|
10614
|
+
if (isInputType(p.type) && typeof p.options?.metric === "string") found.push(p.options.metric);
|
|
10615
|
+
for (const t of p.targets ?? []) if (typeof t.metric === "string" && t.metric && !t.metric.startsWith("$")) found.push(t.metric);
|
|
10616
|
+
return found;
|
|
10617
|
+
}
|
|
10618
|
+
function renameMetrics(panels, map) {
|
|
10619
|
+
const rename = (p) => {
|
|
10620
|
+
let out = p;
|
|
10621
|
+
if (isInputType(p.type) && typeof p.options?.metric === "string" && map[p.options.metric]) out = { ...out, options: { ...out.options, metric: map[p.options.metric] } };
|
|
10622
|
+
if (p.targets?.some((t) => typeof t.metric === "string" && map[t.metric])) out = { ...out, targets: p.targets.map((t) => typeof t.metric === "string" && map[t.metric] ? { ...t, metric: map[t.metric] } : t) };
|
|
10623
|
+
if (p.panels?.length) out = { ...out, panels: p.panels.map(rename) };
|
|
10624
|
+
return out;
|
|
10625
|
+
};
|
|
10626
|
+
return panels.map(rename);
|
|
10627
|
+
}
|
|
10628
|
+
function copyPanels(dashboard, indices) {
|
|
10629
|
+
const panels = dashboard.panels ?? [];
|
|
10630
|
+
const order = readingOrder(panels);
|
|
10631
|
+
const picked = /* @__PURE__ */ new Set();
|
|
10632
|
+
for (const i of indices) {
|
|
10633
|
+
if (!panels[i]) continue;
|
|
10634
|
+
picked.add(i);
|
|
10635
|
+
if (isRow(panels[i]) && !panels[i].collapsed) {
|
|
10636
|
+
for (const j of order.slice(order.indexOf(i) + 1)) {
|
|
10637
|
+
if (isRow(panels[j])) break;
|
|
10638
|
+
picked.add(j);
|
|
10639
|
+
}
|
|
10640
|
+
}
|
|
10641
|
+
}
|
|
10642
|
+
const chosen = order.filter((i) => picked.has(i)).map((i) => panels[i]);
|
|
10643
|
+
return snippetOf(chosen, dashboard.templating?.list ?? []);
|
|
10644
|
+
}
|
|
10645
|
+
function snippetOf(panels, available) {
|
|
10646
|
+
const left = Math.min(...panels.map((p) => pos2(p).x));
|
|
10647
|
+
const top = Math.min(...panels.map((p) => pos2(p).y));
|
|
10648
|
+
const shift = (p) => {
|
|
10649
|
+
const { id: _, ...rest } = p;
|
|
10650
|
+
const g = pos2(p);
|
|
10651
|
+
return { ...rest, gridPos: { ...g, x: g.x - (isRow(p) ? 0 : left), y: g.y - top }, ...p.panels && { panels: p.panels.map(shift) } };
|
|
10652
|
+
};
|
|
10653
|
+
const out = panels.map(shift);
|
|
10654
|
+
const text = JSON.stringify(panels);
|
|
10655
|
+
const names = available.map((v) => v.name);
|
|
10656
|
+
const used = new Set(names.filter((n) => panels.some((p) => withChildren(p).some((c) => c.repeat === n)) || refers2(n).test(text)));
|
|
10657
|
+
for (let grew = true; grew; ) {
|
|
10658
|
+
grew = false;
|
|
10659
|
+
for (const v of available) {
|
|
10660
|
+
if (!used.has(v.name)) continue;
|
|
10661
|
+
for (const r of variableReferences(v, names)) {
|
|
10662
|
+
if (used.has(r)) continue;
|
|
10663
|
+
used.add(r);
|
|
10664
|
+
grew = true;
|
|
10665
|
+
}
|
|
10666
|
+
}
|
|
10667
|
+
}
|
|
10668
|
+
const all = panels.flatMap(withChildren);
|
|
10669
|
+
return {
|
|
10670
|
+
$modelform: "panels",
|
|
10671
|
+
version: SNIPPET_VERSION,
|
|
10672
|
+
kind: all.some((p) => isInputType(p.type)) ? "form" : "dashboard",
|
|
10673
|
+
panels: out,
|
|
10674
|
+
variables: available.filter((v) => used.has(v.name)),
|
|
10675
|
+
metrics: [...new Set(all.flatMap(panelMetrics))]
|
|
10676
|
+
};
|
|
10677
|
+
}
|
|
10678
|
+
var looksLikePanel = (v) => isObject4(v) && typeof v.type === "string";
|
|
10679
|
+
function parseSnippet(text) {
|
|
10680
|
+
let json;
|
|
10681
|
+
try {
|
|
10682
|
+
json = JSON.parse(text);
|
|
10683
|
+
} catch {
|
|
10684
|
+
return { error: "That isn\u2019t JSON" };
|
|
10685
|
+
}
|
|
10686
|
+
let panels;
|
|
10687
|
+
let variables = [];
|
|
10688
|
+
if (isObject4(json) && json.$modelform === "panels") {
|
|
10689
|
+
if (typeof json.version !== "number" || json.version > SNIPPET_VERSION) return { error: "Those panels come from a newer version of modelform" };
|
|
10690
|
+
if (!Array.isArray(json.panels)) return { error: "The copied panels are missing their panels" };
|
|
10691
|
+
panels = json.panels;
|
|
10692
|
+
variables = Array.isArray(json.variables) ? json.variables : [];
|
|
10693
|
+
} else if (Array.isArray(json)) panels = json;
|
|
10694
|
+
else if (isObject4(json) && Array.isArray(json.panels) && !looksLikePanel(json)) {
|
|
10695
|
+
panels = json.panels;
|
|
10696
|
+
const templating = json.templating;
|
|
10697
|
+
variables = isObject4(templating) && Array.isArray(templating.list) ? templating.list : [];
|
|
10698
|
+
} else if (looksLikePanel(json)) panels = [json];
|
|
10699
|
+
else return { error: "That isn\u2019t a panel, a list of panels or a dashboard" };
|
|
10700
|
+
const usable = panels.filter(looksLikePanel);
|
|
10701
|
+
if (!usable.length) return { error: "There are no panels in it" };
|
|
10702
|
+
const vars = variables.filter((v) => isObject4(v) && typeof v.name === "string" && typeof v.type === "string");
|
|
10703
|
+
return { snippet: snippetOf(usable, vars) };
|
|
10704
|
+
}
|
|
10705
|
+
var stable = (v) => Array.isArray(v) ? `[${v.map(stable).join(",")}]` : isObject4(v) ? `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${stable(v[k])}`).join(",")}}` : JSON.stringify(v);
|
|
10706
|
+
var sameVariable = (a, b) => {
|
|
10707
|
+
const strip = ({ current: _, options: __, ...rest }) => stable(rest);
|
|
10708
|
+
return strip(a) === strip(b);
|
|
10709
|
+
};
|
|
10710
|
+
function previewPaste(dashboard, snippet) {
|
|
10711
|
+
const { added, renamed } = mergeVariables(dashboard.templating?.list ?? [], snippet.variables);
|
|
10712
|
+
return { added, renamed };
|
|
10713
|
+
}
|
|
10714
|
+
function mergeVariables(existing, incoming) {
|
|
10715
|
+
const taken = new Set(existing.map((v) => v.name));
|
|
10716
|
+
const added = [];
|
|
10717
|
+
const renamed = {};
|
|
10718
|
+
const out = [...existing];
|
|
10719
|
+
for (const v of incoming) {
|
|
10720
|
+
const same = existing.find((e) => e.name === v.name);
|
|
10721
|
+
if (same && sameVariable(same, v)) continue;
|
|
10722
|
+
let name = v.name;
|
|
10723
|
+
if (same) {
|
|
10724
|
+
let n = 2;
|
|
10725
|
+
while (taken.has(`${v.name}_${n}`)) n++;
|
|
10726
|
+
name = `${v.name}_${n}`;
|
|
10727
|
+
renamed[v.name] = name;
|
|
10728
|
+
}
|
|
10729
|
+
taken.add(name);
|
|
10730
|
+
added.push(name);
|
|
10731
|
+
out.push({ ...v, name });
|
|
10732
|
+
}
|
|
10733
|
+
const follow = (v) => Object.entries(renamed).reduce((acc, [from, to]) => renameVariableInPanels([acc], from, to)[0], v);
|
|
10734
|
+
return { variables: out.map((v, i) => i < existing.length ? v : follow(v)), added, renamed };
|
|
10735
|
+
}
|
|
10736
|
+
function pasteSnippet(dashboard, snippet, options = {}) {
|
|
10737
|
+
const existing = dashboard.panels ?? [];
|
|
10738
|
+
const kind = options.kind ?? (existing.flatMap(withChildren).some((p) => isInputType(p.type)) ? "form" : "dashboard");
|
|
10739
|
+
const skipped = [];
|
|
10740
|
+
const keep = (p) => {
|
|
10741
|
+
if (kind === "dashboard" && isInputType(p.type)) {
|
|
10742
|
+
skipped.push(p.title || p.type);
|
|
10743
|
+
return false;
|
|
10744
|
+
}
|
|
10745
|
+
return true;
|
|
10746
|
+
};
|
|
10747
|
+
let incoming = snippet.panels.filter(keep).map((p) => p.panels ? { ...p, panels: p.panels.filter(keep) } : p);
|
|
10748
|
+
const { variables, added, renamed } = mergeVariables(dashboard.templating?.list ?? [], snippet.variables);
|
|
10749
|
+
for (const [from, to] of Object.entries(renamed)) incoming = renameVariableInPanels(incoming, from, to);
|
|
10750
|
+
if (options.metrics) incoming = renameMetrics(incoming, options.metrics);
|
|
10751
|
+
const after = options.after != null ? existing[options.after] : void 0;
|
|
10752
|
+
const top = after ? pos2(after).y + pos2(after).h : Math.max(0, ...existing.map((p) => pos2(p).y + pos2(p).h));
|
|
10753
|
+
let id = nextPanelId(existing);
|
|
10754
|
+
const place = (p) => ({ ...p, id: id++, gridPos: { ...pos2(p), y: pos2(p).y + top }, ...p.panels && { panels: p.panels.map(place) } });
|
|
10755
|
+
const pasted = incoming.map(place);
|
|
10756
|
+
const index = existing.length;
|
|
10757
|
+
const all = [...existing, ...pasted];
|
|
10758
|
+
return {
|
|
10759
|
+
panels: settleLayout(all, pasted.map((_, i) => index + i)),
|
|
10760
|
+
variables,
|
|
10761
|
+
index,
|
|
10762
|
+
count: pasted.length,
|
|
10763
|
+
added,
|
|
10764
|
+
renamed,
|
|
10765
|
+
skipped
|
|
10766
|
+
};
|
|
10767
|
+
}
|
|
10768
|
+
|
|
10604
10769
|
export {
|
|
10605
10770
|
frameLength,
|
|
10606
10771
|
timeField,
|
|
@@ -10797,5 +10962,10 @@ export {
|
|
|
10797
10962
|
placePanel,
|
|
10798
10963
|
snapToGrid,
|
|
10799
10964
|
panelEdits,
|
|
10800
|
-
sampleEntries
|
|
10965
|
+
sampleEntries,
|
|
10966
|
+
SNIPPET_VERSION,
|
|
10967
|
+
copyPanels,
|
|
10968
|
+
parseSnippet,
|
|
10969
|
+
previewPaste,
|
|
10970
|
+
pasteSnippet
|
|
10801
10971
|
};
|