@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.mjs CHANGED
@@ -174,7 +174,10 @@ import {
174
174
  } from "vue";
175
175
  import {
176
176
  resolveAction,
177
- executeAction
177
+ executeAction,
178
+ nextActionDispatchId,
179
+ notifyActionDispatch,
180
+ notifyActionSettle
178
181
  } from "@json-render/core";
179
182
 
180
183
  // src/composables/validation.ts
@@ -411,109 +414,141 @@ var ActionProvider = defineComponent4({
411
414
  };
412
415
  const execute = async (binding) => {
413
416
  const resolved = resolveAction(binding, getSnapshot());
414
- if (resolved.action === "setState" && resolved.params) {
415
- const statePath = resolved.params.statePath;
416
- const value = resolved.params.value;
417
- if (statePath) {
418
- set(statePath, value);
417
+ const dispatchId = nextActionDispatchId();
418
+ const dispatchedAt = Date.now();
419
+ notifyActionDispatch({
420
+ id: dispatchId,
421
+ name: resolved.action,
422
+ params: resolved.params,
423
+ at: dispatchedAt
424
+ });
425
+ let __ok = true;
426
+ let __error = void 0;
427
+ try {
428
+ if (resolved.action === "setState" && resolved.params) {
429
+ const statePath = resolved.params.statePath;
430
+ const value = resolved.params.value;
431
+ if (statePath) {
432
+ set(statePath, value);
433
+ }
434
+ return;
419
435
  }
420
- return;
421
- }
422
- if (resolved.action === "pushState" && resolved.params) {
423
- const statePath = resolved.params.statePath;
424
- const rawValue = resolved.params.value;
425
- if (statePath) {
426
- const resolvedValue = deepResolveValue(rawValue, get);
427
- const arr = get(statePath) ?? [];
428
- set(statePath, [...arr, resolvedValue]);
429
- const clearStatePath = resolved.params.clearStatePath;
430
- if (clearStatePath) {
431
- set(clearStatePath, "");
436
+ if (resolved.action === "pushState" && resolved.params) {
437
+ const statePath = resolved.params.statePath;
438
+ const rawValue = resolved.params.value;
439
+ if (statePath) {
440
+ const resolvedValue = deepResolveValue(rawValue, get);
441
+ const arr = get(statePath) ?? [];
442
+ set(statePath, [...arr, resolvedValue]);
443
+ const clearStatePath = resolved.params.clearStatePath;
444
+ if (clearStatePath) {
445
+ set(clearStatePath, "");
446
+ }
432
447
  }
448
+ return;
433
449
  }
434
- return;
435
- }
436
- if (resolved.action === "removeState" && resolved.params) {
437
- const statePath = resolved.params.statePath;
438
- const index = resolved.params.index;
439
- if (statePath !== void 0 && index !== void 0) {
440
- const arr = get(statePath) ?? [];
441
- set(
442
- statePath,
443
- arr.filter((_, i) => i !== index)
444
- );
450
+ if (resolved.action === "removeState" && resolved.params) {
451
+ const statePath = resolved.params.statePath;
452
+ const index = resolved.params.index;
453
+ if (statePath !== void 0 && index !== void 0) {
454
+ const arr = get(statePath) ?? [];
455
+ set(
456
+ statePath,
457
+ arr.filter((_, i) => i !== index)
458
+ );
459
+ }
460
+ return;
445
461
  }
446
- return;
447
- }
448
- if (resolved.action === "validateForm") {
449
- const validateAll = validation?.validateAll;
450
- if (!validateAll) {
451
- console.warn(
452
- "validateForm action was dispatched but no ValidationProvider is connected. Ensure ValidationProvider is rendered inside the provider tree."
453
- );
462
+ if (resolved.action === "validateForm") {
463
+ const validateAll = validation?.validateAll;
464
+ if (!validateAll) {
465
+ console.warn(
466
+ "validateForm action was dispatched but no ValidationProvider is connected. Ensure ValidationProvider is rendered inside the provider tree."
467
+ );
468
+ return;
469
+ }
470
+ const valid = validateAll();
471
+ const errors = {};
472
+ for (const [path, fs] of Object.entries(validation.fieldStates)) {
473
+ if (fs.result && !fs.result.valid) {
474
+ errors[path] = fs.result.errors;
475
+ }
476
+ }
477
+ const statePath = resolved.params?.statePath || "/formValidation";
478
+ set(statePath, { valid, errors });
454
479
  return;
455
480
  }
456
- const valid = validateAll();
457
- const errors = {};
458
- for (const [path, fs] of Object.entries(validation.fieldStates)) {
459
- if (fs.result && !fs.result.valid) {
460
- errors[path] = fs.result.errors;
481
+ if (resolved.action === "push" && resolved.params) {
482
+ const screen = resolved.params.screen;
483
+ if (screen) {
484
+ const currentScreen = get("/currentScreen");
485
+ const navStack = get("/navStack") ?? [];
486
+ if (currentScreen) {
487
+ set("/navStack", [...navStack, currentScreen]);
488
+ } else {
489
+ set("/navStack", [...navStack, ""]);
490
+ }
491
+ set("/currentScreen", screen);
461
492
  }
493
+ return;
462
494
  }
463
- const statePath = resolved.params?.statePath || "/formValidation";
464
- set(statePath, { valid, errors });
465
- return;
466
- }
467
- if (resolved.action === "push" && resolved.params) {
468
- const screen = resolved.params.screen;
469
- if (screen) {
470
- const currentScreen = get("/currentScreen");
495
+ if (resolved.action === "pop") {
471
496
  const navStack = get("/navStack") ?? [];
472
- if (currentScreen) {
473
- set("/navStack", [...navStack, currentScreen]);
474
- } else {
475
- set("/navStack", [...navStack, ""]);
497
+ if (navStack.length > 0) {
498
+ const previousScreen = navStack[navStack.length - 1];
499
+ set("/navStack", navStack.slice(0, -1));
500
+ if (previousScreen) {
501
+ set("/currentScreen", previousScreen);
502
+ } else {
503
+ set("/currentScreen", void 0);
504
+ }
476
505
  }
477
- set("/currentScreen", screen);
506
+ return;
478
507
  }
479
- return;
480
- }
481
- if (resolved.action === "pop") {
482
- const navStack = get("/navStack") ?? [];
483
- if (navStack.length > 0) {
484
- const previousScreen = navStack[navStack.length - 1];
485
- set("/navStack", navStack.slice(0, -1));
486
- if (previousScreen) {
487
- set("/currentScreen", previousScreen);
488
- } else {
489
- set("/currentScreen", void 0);
508
+ const handler = handlers.value[resolved.action];
509
+ if (!handler) {
510
+ console.warn(`No handler registered for action: ${resolved.action}`);
511
+ return;
512
+ }
513
+ if (resolved.confirm) {
514
+ await new Promise((resolve, reject) => {
515
+ pendingConfirmation.value = {
516
+ action: resolved,
517
+ handler,
518
+ resolve: () => {
519
+ pendingConfirmation.value = null;
520
+ resolve();
521
+ },
522
+ reject: () => {
523
+ pendingConfirmation.value = null;
524
+ reject(new Error("Action cancelled"));
525
+ }
526
+ };
527
+ });
528
+ const addLoading2 = new Set(loadingActions.value);
529
+ addLoading2.add(resolved.action);
530
+ loadingActions.value = addLoading2;
531
+ try {
532
+ await executeAction({
533
+ action: resolved,
534
+ handler,
535
+ setState: set,
536
+ navigate: props.navigate,
537
+ executeAction: async (name) => {
538
+ const subBinding = { action: name };
539
+ await execute(subBinding);
540
+ }
541
+ });
542
+ } finally {
543
+ const removeLoading = new Set(loadingActions.value);
544
+ removeLoading.delete(resolved.action);
545
+ loadingActions.value = removeLoading;
490
546
  }
547
+ return;
491
548
  }
492
- return;
493
- }
494
- const handler = handlers.value[resolved.action];
495
- if (!handler) {
496
- console.warn(`No handler registered for action: ${resolved.action}`);
497
- return;
498
- }
499
- if (resolved.confirm) {
500
- await new Promise((resolve, reject) => {
501
- pendingConfirmation.value = {
502
- action: resolved,
503
- handler,
504
- resolve: () => {
505
- pendingConfirmation.value = null;
506
- resolve();
507
- },
508
- reject: () => {
509
- pendingConfirmation.value = null;
510
- reject(new Error("Action cancelled"));
511
- }
512
- };
513
- });
514
- const addLoading2 = new Set(loadingActions.value);
515
- addLoading2.add(resolved.action);
516
- loadingActions.value = addLoading2;
549
+ const addLoading = new Set(loadingActions.value);
550
+ addLoading.add(resolved.action);
551
+ loadingActions.value = addLoading;
517
552
  try {
518
553
  await executeAction({
519
554
  action: resolved,
@@ -530,26 +565,20 @@ var ActionProvider = defineComponent4({
530
565
  removeLoading.delete(resolved.action);
531
566
  loadingActions.value = removeLoading;
532
567
  }
533
- return;
534
- }
535
- const addLoading = new Set(loadingActions.value);
536
- addLoading.add(resolved.action);
537
- loadingActions.value = addLoading;
538
- try {
539
- await executeAction({
540
- action: resolved,
541
- handler,
542
- setState: set,
543
- navigate: props.navigate,
544
- executeAction: async (name) => {
545
- const subBinding = { action: name };
546
- await execute(subBinding);
547
- }
548
- });
568
+ } catch (err) {
569
+ __ok = false;
570
+ __error = err;
571
+ throw err;
549
572
  } finally {
550
- const removeLoading = new Set(loadingActions.value);
551
- removeLoading.delete(resolved.action);
552
- loadingActions.value = removeLoading;
573
+ const now = Date.now();
574
+ notifyActionSettle({
575
+ id: dispatchId,
576
+ name: resolved.action,
577
+ ok: __ok,
578
+ at: now,
579
+ durationMs: now - dispatchedAt,
580
+ error: __error
581
+ });
553
582
  }
554
583
  };
555
584
  const confirm = () => pendingConfirmation.value?.resolve();
@@ -1231,6 +1260,7 @@ import {
1231
1260
  defineComponent as defineComponent6,
1232
1261
  h as h2,
1233
1262
  inject as inject6,
1263
+ onBeforeUnmount,
1234
1264
  onErrorCaptured,
1235
1265
  provide as provide6,
1236
1266
  ref as ref5,
@@ -1241,7 +1271,9 @@ import {
1241
1271
  resolveBindings,
1242
1272
  resolveActionParam,
1243
1273
  evaluateVisibility as evaluateVisibility2,
1244
- getByPath as getByPath3
1274
+ getByPath as getByPath3,
1275
+ isDevtoolsActive,
1276
+ subscribeDevtoolsActive
1245
1277
  } from "@json-render/core";
1246
1278
  var EMPTY_FUNCTIONS = {};
1247
1279
  var FUNCTIONS_KEY = /* @__PURE__ */ Symbol("json-render:functions");
@@ -1309,6 +1341,14 @@ async function resolveAndExecuteBindings(actionBindings, ctx, getSnapshot, execu
1309
1341
  if (cancelled?.()) break;
1310
1342
  }
1311
1343
  }
1344
+ function useDevtoolsActive() {
1345
+ const active = ref5(isDevtoolsActive());
1346
+ const unsub = subscribeDevtoolsActive(() => {
1347
+ active.value = isDevtoolsActive();
1348
+ });
1349
+ onBeforeUnmount(unsub);
1350
+ return active;
1351
+ }
1312
1352
  var ElementRenderer = defineComponent6({
1313
1353
  name: "JsonRenderElement",
1314
1354
  props: {
@@ -1316,6 +1356,10 @@ var ElementRenderer = defineComponent6({
1316
1356
  type: Object,
1317
1357
  required: true
1318
1358
  },
1359
+ elementKey: {
1360
+ type: String,
1361
+ default: void 0
1362
+ },
1319
1363
  spec: {
1320
1364
  type: Object,
1321
1365
  required: true
@@ -1334,6 +1378,7 @@ var ElementRenderer = defineComponent6({
1334
1378
  }
1335
1379
  },
1336
1380
  setup(props) {
1381
+ const devtoolsActive = useDevtoolsActive();
1337
1382
  const repeatScope = useRepeatScope();
1338
1383
  const { ctx: visibilityCtx } = useVisibility();
1339
1384
  const { execute } = useActions();
@@ -1448,28 +1493,33 @@ var ElementRenderer = defineComponent6({
1448
1493
  return h2(ElementRenderer, {
1449
1494
  key: childKey,
1450
1495
  element: childElement,
1496
+ elementKey: childKey,
1451
1497
  spec: props.spec,
1452
1498
  registry: props.registry,
1453
1499
  loading: props.loading,
1454
1500
  fallback: props.fallback
1455
1501
  });
1456
1502
  }).filter((n) => n !== null) ?? void 0;
1503
+ const componentVNode = h2(
1504
+ Component,
1505
+ {
1506
+ element: resolvedElement,
1507
+ emit: emitEvent,
1508
+ on: onEvent,
1509
+ bindings: elementBindings,
1510
+ loading: props.loading
1511
+ },
1512
+ { default: () => childrenVNodes }
1513
+ );
1514
+ const tagged = devtoolsActive.value && props.elementKey ? h2(
1515
+ "span",
1516
+ { "data-jr-key": props.elementKey, style: "display:contents" },
1517
+ [componentVNode]
1518
+ ) : componentVNode;
1457
1519
  return h2(
1458
1520
  ElementErrorBoundary,
1459
1521
  { elementType: resolvedElement.type },
1460
- {
1461
- default: () => h2(
1462
- Component,
1463
- {
1464
- element: resolvedElement,
1465
- emit: emitEvent,
1466
- on: onEvent,
1467
- bindings: elementBindings,
1468
- loading: props.loading
1469
- },
1470
- { default: () => childrenVNodes }
1471
- )
1472
- }
1522
+ { default: () => tagged }
1473
1523
  );
1474
1524
  };
1475
1525
  }
@@ -1527,6 +1577,7 @@ var RepeatChildren = defineComponent6({
1527
1577
  return h2(ElementRenderer, {
1528
1578
  key: childKey,
1529
1579
  element: childElement,
1580
+ elementKey: childKey,
1530
1581
  spec: props.spec,
1531
1582
  registry: props.registry,
1532
1583
  loading: props.loading,
@@ -1566,6 +1617,7 @@ var Renderer = defineComponent6({
1566
1617
  if (!rootElement) return null;
1567
1618
  return h2(ElementRenderer, {
1568
1619
  element: rootElement,
1620
+ elementKey: props.spec.root,
1569
1621
  spec: props.spec,
1570
1622
  registry: props.registry,
1571
1623
  loading: props.loading,