@json-render/vue 0.16.0 → 0.18.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/index.js +168 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -124
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -422,109 +422,141 @@ var ActionProvider = (0, import_vue4.defineComponent)({
|
|
|
422
422
|
};
|
|
423
423
|
const execute = async (binding) => {
|
|
424
424
|
const resolved = (0, import_core4.resolveAction)(binding, getSnapshot());
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
425
|
+
const dispatchId = (0, import_core4.nextActionDispatchId)();
|
|
426
|
+
const dispatchedAt = Date.now();
|
|
427
|
+
(0, import_core4.notifyActionDispatch)({
|
|
428
|
+
id: dispatchId,
|
|
429
|
+
name: resolved.action,
|
|
430
|
+
params: resolved.params,
|
|
431
|
+
at: dispatchedAt
|
|
432
|
+
});
|
|
433
|
+
let __ok = true;
|
|
434
|
+
let __error = void 0;
|
|
435
|
+
try {
|
|
436
|
+
if (resolved.action === "setState" && resolved.params) {
|
|
437
|
+
const statePath = resolved.params.statePath;
|
|
438
|
+
const value = resolved.params.value;
|
|
439
|
+
if (statePath) {
|
|
440
|
+
set(statePath, value);
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
430
443
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
set(clearStatePath, "");
|
|
444
|
+
if (resolved.action === "pushState" && resolved.params) {
|
|
445
|
+
const statePath = resolved.params.statePath;
|
|
446
|
+
const rawValue = resolved.params.value;
|
|
447
|
+
if (statePath) {
|
|
448
|
+
const resolvedValue = deepResolveValue(rawValue, get);
|
|
449
|
+
const arr = get(statePath) ?? [];
|
|
450
|
+
set(statePath, [...arr, resolvedValue]);
|
|
451
|
+
const clearStatePath = resolved.params.clearStatePath;
|
|
452
|
+
if (clearStatePath) {
|
|
453
|
+
set(clearStatePath, "");
|
|
454
|
+
}
|
|
443
455
|
}
|
|
456
|
+
return;
|
|
444
457
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
458
|
+
if (resolved.action === "removeState" && resolved.params) {
|
|
459
|
+
const statePath = resolved.params.statePath;
|
|
460
|
+
const index = resolved.params.index;
|
|
461
|
+
if (statePath !== void 0 && index !== void 0) {
|
|
462
|
+
const arr = get(statePath) ?? [];
|
|
463
|
+
set(
|
|
464
|
+
statePath,
|
|
465
|
+
arr.filter((_, i) => i !== index)
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
return;
|
|
456
469
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
470
|
+
if (resolved.action === "validateForm") {
|
|
471
|
+
const validateAll = validation?.validateAll;
|
|
472
|
+
if (!validateAll) {
|
|
473
|
+
console.warn(
|
|
474
|
+
"validateForm action was dispatched but no ValidationProvider is connected. Ensure ValidationProvider is rendered inside the provider tree."
|
|
475
|
+
);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const valid = validateAll();
|
|
479
|
+
const errors = {};
|
|
480
|
+
for (const [path, fs] of Object.entries(validation.fieldStates)) {
|
|
481
|
+
if (fs.result && !fs.result.valid) {
|
|
482
|
+
errors[path] = fs.result.errors;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const statePath = resolved.params?.statePath || "/formValidation";
|
|
486
|
+
set(statePath, { valid, errors });
|
|
465
487
|
return;
|
|
466
488
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
489
|
+
if (resolved.action === "push" && resolved.params) {
|
|
490
|
+
const screen = resolved.params.screen;
|
|
491
|
+
if (screen) {
|
|
492
|
+
const currentScreen = get("/currentScreen");
|
|
493
|
+
const navStack = get("/navStack") ?? [];
|
|
494
|
+
if (currentScreen) {
|
|
495
|
+
set("/navStack", [...navStack, currentScreen]);
|
|
496
|
+
} else {
|
|
497
|
+
set("/navStack", [...navStack, ""]);
|
|
498
|
+
}
|
|
499
|
+
set("/currentScreen", screen);
|
|
472
500
|
}
|
|
501
|
+
return;
|
|
473
502
|
}
|
|
474
|
-
|
|
475
|
-
set(statePath, { valid, errors });
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
if (resolved.action === "push" && resolved.params) {
|
|
479
|
-
const screen = resolved.params.screen;
|
|
480
|
-
if (screen) {
|
|
481
|
-
const currentScreen = get("/currentScreen");
|
|
503
|
+
if (resolved.action === "pop") {
|
|
482
504
|
const navStack = get("/navStack") ?? [];
|
|
483
|
-
if (
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
505
|
+
if (navStack.length > 0) {
|
|
506
|
+
const previousScreen = navStack[navStack.length - 1];
|
|
507
|
+
set("/navStack", navStack.slice(0, -1));
|
|
508
|
+
if (previousScreen) {
|
|
509
|
+
set("/currentScreen", previousScreen);
|
|
510
|
+
} else {
|
|
511
|
+
set("/currentScreen", void 0);
|
|
512
|
+
}
|
|
487
513
|
}
|
|
488
|
-
|
|
514
|
+
return;
|
|
489
515
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
516
|
+
const handler = handlers.value[resolved.action];
|
|
517
|
+
if (!handler) {
|
|
518
|
+
console.warn(`No handler registered for action: ${resolved.action}`);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (resolved.confirm) {
|
|
522
|
+
await new Promise((resolve, reject) => {
|
|
523
|
+
pendingConfirmation.value = {
|
|
524
|
+
action: resolved,
|
|
525
|
+
handler,
|
|
526
|
+
resolve: () => {
|
|
527
|
+
pendingConfirmation.value = null;
|
|
528
|
+
resolve();
|
|
529
|
+
},
|
|
530
|
+
reject: () => {
|
|
531
|
+
pendingConfirmation.value = null;
|
|
532
|
+
reject(new Error("Action cancelled"));
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
const addLoading2 = new Set(loadingActions.value);
|
|
537
|
+
addLoading2.add(resolved.action);
|
|
538
|
+
loadingActions.value = addLoading2;
|
|
539
|
+
try {
|
|
540
|
+
await (0, import_core4.executeAction)({
|
|
541
|
+
action: resolved,
|
|
542
|
+
handler,
|
|
543
|
+
setState: set,
|
|
544
|
+
navigate: props.navigate,
|
|
545
|
+
executeAction: async (name) => {
|
|
546
|
+
const subBinding = { action: name };
|
|
547
|
+
await execute(subBinding);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
} finally {
|
|
551
|
+
const removeLoading = new Set(loadingActions.value);
|
|
552
|
+
removeLoading.delete(resolved.action);
|
|
553
|
+
loadingActions.value = removeLoading;
|
|
501
554
|
}
|
|
555
|
+
return;
|
|
502
556
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
if (!handler) {
|
|
507
|
-
console.warn(`No handler registered for action: ${resolved.action}`);
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
if (resolved.confirm) {
|
|
511
|
-
await new Promise((resolve, reject) => {
|
|
512
|
-
pendingConfirmation.value = {
|
|
513
|
-
action: resolved,
|
|
514
|
-
handler,
|
|
515
|
-
resolve: () => {
|
|
516
|
-
pendingConfirmation.value = null;
|
|
517
|
-
resolve();
|
|
518
|
-
},
|
|
519
|
-
reject: () => {
|
|
520
|
-
pendingConfirmation.value = null;
|
|
521
|
-
reject(new Error("Action cancelled"));
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
});
|
|
525
|
-
const addLoading2 = new Set(loadingActions.value);
|
|
526
|
-
addLoading2.add(resolved.action);
|
|
527
|
-
loadingActions.value = addLoading2;
|
|
557
|
+
const addLoading = new Set(loadingActions.value);
|
|
558
|
+
addLoading.add(resolved.action);
|
|
559
|
+
loadingActions.value = addLoading;
|
|
528
560
|
try {
|
|
529
561
|
await (0, import_core4.executeAction)({
|
|
530
562
|
action: resolved,
|
|
@@ -541,26 +573,20 @@ var ActionProvider = (0, import_vue4.defineComponent)({
|
|
|
541
573
|
removeLoading.delete(resolved.action);
|
|
542
574
|
loadingActions.value = removeLoading;
|
|
543
575
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
loadingActions.value = addLoading;
|
|
549
|
-
try {
|
|
550
|
-
await (0, import_core4.executeAction)({
|
|
551
|
-
action: resolved,
|
|
552
|
-
handler,
|
|
553
|
-
setState: set,
|
|
554
|
-
navigate: props.navigate,
|
|
555
|
-
executeAction: async (name) => {
|
|
556
|
-
const subBinding = { action: name };
|
|
557
|
-
await execute(subBinding);
|
|
558
|
-
}
|
|
559
|
-
});
|
|
576
|
+
} catch (err) {
|
|
577
|
+
__ok = false;
|
|
578
|
+
__error = err;
|
|
579
|
+
throw err;
|
|
560
580
|
} finally {
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
581
|
+
const now = Date.now();
|
|
582
|
+
(0, import_core4.notifyActionSettle)({
|
|
583
|
+
id: dispatchId,
|
|
584
|
+
name: resolved.action,
|
|
585
|
+
ok: __ok,
|
|
586
|
+
at: now,
|
|
587
|
+
durationMs: now - dispatchedAt,
|
|
588
|
+
error: __error
|
|
589
|
+
});
|
|
564
590
|
}
|
|
565
591
|
};
|
|
566
592
|
const confirm = () => pendingConfirmation.value?.resolve();
|
|
@@ -1372,6 +1398,14 @@ async function resolveAndExecuteBindings(actionBindings, ctx, getSnapshot, execu
|
|
|
1372
1398
|
if (cancelled?.()) break;
|
|
1373
1399
|
}
|
|
1374
1400
|
}
|
|
1401
|
+
function useDevtoolsActive() {
|
|
1402
|
+
const active = (0, import_vue7.ref)((0, import_core7.isDevtoolsActive)());
|
|
1403
|
+
const unsub = (0, import_core7.subscribeDevtoolsActive)(() => {
|
|
1404
|
+
active.value = (0, import_core7.isDevtoolsActive)();
|
|
1405
|
+
});
|
|
1406
|
+
(0, import_vue7.onBeforeUnmount)(unsub);
|
|
1407
|
+
return active;
|
|
1408
|
+
}
|
|
1375
1409
|
var ElementRenderer = (0, import_vue7.defineComponent)({
|
|
1376
1410
|
name: "JsonRenderElement",
|
|
1377
1411
|
props: {
|
|
@@ -1379,6 +1413,10 @@ var ElementRenderer = (0, import_vue7.defineComponent)({
|
|
|
1379
1413
|
type: Object,
|
|
1380
1414
|
required: true
|
|
1381
1415
|
},
|
|
1416
|
+
elementKey: {
|
|
1417
|
+
type: String,
|
|
1418
|
+
default: void 0
|
|
1419
|
+
},
|
|
1382
1420
|
spec: {
|
|
1383
1421
|
type: Object,
|
|
1384
1422
|
required: true
|
|
@@ -1397,6 +1435,7 @@ var ElementRenderer = (0, import_vue7.defineComponent)({
|
|
|
1397
1435
|
}
|
|
1398
1436
|
},
|
|
1399
1437
|
setup(props) {
|
|
1438
|
+
const devtoolsActive = useDevtoolsActive();
|
|
1400
1439
|
const repeatScope = useRepeatScope();
|
|
1401
1440
|
const { ctx: visibilityCtx } = useVisibility();
|
|
1402
1441
|
const { execute } = useActions();
|
|
@@ -1511,28 +1550,33 @@ var ElementRenderer = (0, import_vue7.defineComponent)({
|
|
|
1511
1550
|
return (0, import_vue7.h)(ElementRenderer, {
|
|
1512
1551
|
key: childKey,
|
|
1513
1552
|
element: childElement,
|
|
1553
|
+
elementKey: childKey,
|
|
1514
1554
|
spec: props.spec,
|
|
1515
1555
|
registry: props.registry,
|
|
1516
1556
|
loading: props.loading,
|
|
1517
1557
|
fallback: props.fallback
|
|
1518
1558
|
});
|
|
1519
1559
|
}).filter((n) => n !== null) ?? void 0;
|
|
1560
|
+
const componentVNode = (0, import_vue7.h)(
|
|
1561
|
+
Component,
|
|
1562
|
+
{
|
|
1563
|
+
element: resolvedElement,
|
|
1564
|
+
emit: emitEvent,
|
|
1565
|
+
on: onEvent,
|
|
1566
|
+
bindings: elementBindings,
|
|
1567
|
+
loading: props.loading
|
|
1568
|
+
},
|
|
1569
|
+
{ default: () => childrenVNodes }
|
|
1570
|
+
);
|
|
1571
|
+
const tagged = devtoolsActive.value && props.elementKey ? (0, import_vue7.h)(
|
|
1572
|
+
"span",
|
|
1573
|
+
{ "data-jr-key": props.elementKey, style: "display:contents" },
|
|
1574
|
+
[componentVNode]
|
|
1575
|
+
) : componentVNode;
|
|
1520
1576
|
return (0, import_vue7.h)(
|
|
1521
1577
|
ElementErrorBoundary,
|
|
1522
1578
|
{ elementType: resolvedElement.type },
|
|
1523
|
-
{
|
|
1524
|
-
default: () => (0, import_vue7.h)(
|
|
1525
|
-
Component,
|
|
1526
|
-
{
|
|
1527
|
-
element: resolvedElement,
|
|
1528
|
-
emit: emitEvent,
|
|
1529
|
-
on: onEvent,
|
|
1530
|
-
bindings: elementBindings,
|
|
1531
|
-
loading: props.loading
|
|
1532
|
-
},
|
|
1533
|
-
{ default: () => childrenVNodes }
|
|
1534
|
-
)
|
|
1535
|
-
}
|
|
1579
|
+
{ default: () => tagged }
|
|
1536
1580
|
);
|
|
1537
1581
|
};
|
|
1538
1582
|
}
|
|
@@ -1590,6 +1634,7 @@ var RepeatChildren = (0, import_vue7.defineComponent)({
|
|
|
1590
1634
|
return (0, import_vue7.h)(ElementRenderer, {
|
|
1591
1635
|
key: childKey,
|
|
1592
1636
|
element: childElement,
|
|
1637
|
+
elementKey: childKey,
|
|
1593
1638
|
spec: props.spec,
|
|
1594
1639
|
registry: props.registry,
|
|
1595
1640
|
loading: props.loading,
|
|
@@ -1629,6 +1674,7 @@ var Renderer = (0, import_vue7.defineComponent)({
|
|
|
1629
1674
|
if (!rootElement) return null;
|
|
1630
1675
|
return (0, import_vue7.h)(ElementRenderer, {
|
|
1631
1676
|
element: rootElement,
|
|
1677
|
+
elementKey: props.spec.root,
|
|
1632
1678
|
spec: props.spec,
|
|
1633
1679
|
registry: props.registry,
|
|
1634
1680
|
loading: props.loading,
|