@xmachines/json-render-react 0.20.0-xm.1 → 0.20.0-xm.3

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.d.mts CHANGED
@@ -104,9 +104,9 @@ interface PendingConfirmation {
104
104
  action: ResolvedAction;
105
105
  /** The action handler */
106
106
  handler: ActionHandler;
107
- /** Resolve callback */
107
+ /** Accept the confirmation — the action runs */
108
108
  resolve: () => void;
109
- /** Reject callback */
109
+ /** Decline the confirmation — the action is skipped, nothing throws */
110
110
  reject: () => void;
111
111
  }
112
112
  /**
package/dist/index.d.ts CHANGED
@@ -104,9 +104,9 @@ interface PendingConfirmation {
104
104
  action: ResolvedAction;
105
105
  /** The action handler */
106
106
  handler: ActionHandler;
107
- /** Resolve callback */
107
+ /** Accept the confirmation — the action runs */
108
108
  resolve: () => void;
109
- /** Reject callback */
109
+ /** Decline the confirmation — the action is skipped, nothing throws */
110
110
  reject: () => void;
111
111
  }
112
112
  /**
package/dist/index.js CHANGED
@@ -399,6 +399,7 @@ function useValidation() {
399
399
  function useOptionalValidation() {
400
400
  return (0, import_react3.useContext)(ValidationContext);
401
401
  }
402
+ var useIsomorphicLayoutEffect = typeof document !== "undefined" ? import_react3.default.useLayoutEffect : import_react3.default.useEffect;
402
403
  function useFieldValidation(path, config) {
403
404
  const {
404
405
  fieldStates,
@@ -411,7 +412,7 @@ function useFieldValidation(path, config) {
411
412
  const configKey = config === void 0 ? void 0 : JSON.stringify(config);
412
413
  const configRef = import_react3.default.useRef(config);
413
414
  configRef.current = config;
414
- import_react3.default.useEffect(() => {
415
+ useIsomorphicLayoutEffect(() => {
415
416
  const current = configRef.current;
416
417
  if (path && current) {
417
418
  registerField(path, current);
@@ -485,6 +486,7 @@ function ActionProvider({
485
486
  const [handlers, setHandlers] = (0, import_react4.useState)(initialHandlers);
486
487
  const [loadingActions, setLoadingActions] = (0, import_react4.useState)(/* @__PURE__ */ new Set());
487
488
  const [pendingConfirmation, setPendingConfirmation] = (0, import_react4.useState)(null);
489
+ const pendingRef = (0, import_react4.useRef)(null);
488
490
  const registerHandler = (0, import_react4.useCallback)(
489
491
  (name, handler) => {
490
492
  setHandlers((prev) => ({ ...prev, [name]: handler }));
@@ -504,6 +506,8 @@ function ActionProvider({
504
506
  });
505
507
  let __ok = true;
506
508
  let __error = void 0;
509
+ let __cancelled = false;
510
+ let __confirmMs = void 0;
507
511
  try {
508
512
  if (resolved.action === "setState" && resolved.params) {
509
513
  const statePath = resolved.params.statePath;
@@ -591,39 +595,32 @@ function ActionProvider({
591
595
  return;
592
596
  }
593
597
  if (resolved.confirm) {
594
- return new Promise((resolve, reject) => {
595
- setPendingConfirmation({
598
+ pendingRef.current?.reject();
599
+ const confirmOpenedAt = Date.now();
600
+ const confirmed = await new Promise((res) => {
601
+ const entry = {
596
602
  action: resolved,
597
603
  handler,
598
604
  resolve: () => {
605
+ pendingRef.current = null;
599
606
  setPendingConfirmation(null);
600
- resolve();
607
+ res(true);
601
608
  },
602
609
  reject: () => {
610
+ pendingRef.current = null;
603
611
  setPendingConfirmation(null);
604
- reject(new Error("Action cancelled"));
612
+ res(false);
605
613
  }
606
- });
607
- }).then(async () => {
608
- setLoadingActions((prev) => new Set(prev).add(resolved.action));
609
- try {
610
- await (0, import_core4.executeAction)({
611
- action: resolved,
612
- handler,
613
- setState: set,
614
- navigate,
615
- executeAction: async (binding2) => {
616
- await execute(binding2);
617
- }
618
- });
619
- } finally {
620
- setLoadingActions((prev) => {
621
- const next = new Set(prev);
622
- next.delete(resolved.action);
623
- return next;
624
- });
625
- }
614
+ };
615
+ pendingRef.current = entry;
616
+ setPendingConfirmation(entry);
626
617
  });
618
+ __confirmMs = Date.now() - confirmOpenedAt;
619
+ if (!confirmed) {
620
+ __ok = false;
621
+ __cancelled = true;
622
+ return;
623
+ }
627
624
  }
628
625
  setLoadingActions((prev) => new Set(prev).add(resolved.action));
629
626
  try {
@@ -655,6 +652,8 @@ function ActionProvider({
655
652
  ok: __ok,
656
653
  at: now,
657
654
  durationMs: now - dispatchedAt,
655
+ cancelled: __cancelled || void 0,
656
+ confirmMs: __confirmMs,
658
657
  error: __error
659
658
  });
660
659
  }
@@ -662,11 +661,11 @@ function ActionProvider({
662
661
  [handlers, get, set, getSnapshot, navigate, validation]
663
662
  );
664
663
  const confirm = (0, import_react4.useCallback)(() => {
665
- pendingConfirmation?.resolve();
666
- }, [pendingConfirmation]);
664
+ pendingRef.current?.resolve();
665
+ }, []);
667
666
  const cancel = (0, import_react4.useCallback)(() => {
668
- pendingConfirmation?.reject();
669
- }, [pendingConfirmation]);
667
+ pendingRef.current?.reject();
668
+ }, []);
670
669
  const value = (0, import_react4.useMemo)(
671
670
  () => ({
672
671
  handlers,