@xmachines/json-render-svelte 0.20.0-xm.2 → 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.
@@ -179,6 +179,8 @@
179
179
  });
180
180
  let __ok = true;
181
181
  let __error: unknown = undefined;
182
+ let __cancelled = false;
183
+ let __confirmMs: number | undefined = undefined;
182
184
 
183
185
  try {
184
186
  if (resolved.action === "setState" && resolved.params) {
@@ -282,38 +284,43 @@
282
284
  return;
283
285
  }
284
286
 
287
+ // If confirmation is required, show dialog and wait for user response.
288
+ // Uses resolve(boolean) instead of reject() to avoid unhandled rejections:
289
+ // cancelling is a normal user outcome, not an error, so the action is
290
+ // skipped silently and no state changes.
285
291
  if (resolved.confirm) {
286
- return new Promise<void>((resolve, reject) => {
292
+ // Decline any confirmation that is already open, so that its promise
293
+ // resolves. This prevents an orphaned await when a second confirm gate
294
+ // opens.
295
+ pendingConfirmation?.reject();
296
+
297
+ const confirmOpenedAt = Date.now();
298
+ const confirmed = await new Promise<boolean>((res) => {
287
299
  pendingConfirmation = {
288
300
  action: resolved,
289
301
  handler,
290
302
  resolve: () => {
291
303
  pendingConfirmation = null;
292
- resolve();
304
+ res(true);
293
305
  },
294
306
  reject: () => {
295
307
  pendingConfirmation = null;
296
- reject(new Error("Action cancelled"));
308
+ res(false);
297
309
  },
298
310
  };
299
- }).then(async () => {
300
- loadingActions.add(resolved.action);
301
- try {
302
- await executeAction({
303
- action: resolved,
304
- handler,
305
- setState: stateCtx.set,
306
- navigate,
307
- executeAction: async (binding) => {
308
- await execute(binding);
309
- },
310
- });
311
- } finally {
312
- loadingActions.delete(resolved.action);
313
- }
314
311
  });
312
+ __confirmMs = Date.now() - confirmOpenedAt;
313
+
314
+ // The user declined. The handler does not run, so the observer reads
315
+ // `ok: false` with `cancelled: true`.
316
+ if (!confirmed) {
317
+ __ok = false;
318
+ __cancelled = true;
319
+ return;
320
+ }
315
321
  }
316
322
 
323
+ // Execute (confirmed, or no confirmation required)
317
324
  loadingActions.add(resolved.action);
318
325
  try {
319
326
  await executeAction({
@@ -340,6 +347,8 @@
340
347
  ok: __ok,
341
348
  at: now,
342
349
  durationMs: now - dispatchedAt,
350
+ cancelled: __cancelled || undefined,
351
+ confirmMs: __confirmMs,
343
352
  error: __error,
344
353
  });
345
354
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ActionProvider.svelte.d.ts","sourceRoot":"","sources":["../../src/contexts/ActionProvider.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,cAAc,EACf,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,qCAAqC;IACrC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,kCAAkC;IAClC,mBAAmB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAChD,gCAAgC;IAChC,OAAO,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,iCAAiC;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,gCAAgC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,iCAAiC;IACjC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;CACjE;AAED;;GAEG;AACH,wBAAgB,gBA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,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
@@ -185,4 +185,36 @@ describe("createActionContext", () => {
185
185
  expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("validateForm action was dispatched"));
186
186
  warnSpy.mockRestore();
187
187
  }));
188
+ /**
189
+ * Cancelling used to reject the gate's promise with
190
+ * `new Error("Action cancelled")`. Callers discard the promise `execute()`
191
+ * returns (a DOM handler does), so the rejection escaped as an unhandled
192
+ * rejection, which fails a whole Vitest run. Cancel is a normal user
193
+ * outcome: the action is skipped and the dispatch resolves.
194
+ */
195
+ it("cancelling a confirm gate resolves, skips the action, and leaves state untouched", component(async () => {
196
+ const stateCtx = getStateContext();
197
+ const actionCtx = getActionContext();
198
+ const dispatched = actionCtx.execute({
199
+ action: "destroy",
200
+ confirm: { title: "Delete?", message: "This cannot be undone." },
201
+ onSuccess: { set: { "/status": "destroyed" } },
202
+ onError: { set: { "/status": "errored" } },
203
+ });
204
+ await vi.waitFor(() => {
205
+ if (!actionCtx.pendingConfirmation)
206
+ throw new Error("no pending confirmation");
207
+ });
208
+ actionCtx.cancel();
209
+ await expect(dispatched).resolves.toBeUndefined();
210
+ expect(actionCtx.pendingConfirmation).toBeNull();
211
+ expect(stateCtx.get("/status")).toBe("untouched");
212
+ }, {
213
+ initialState: { status: "untouched" },
214
+ handlers: {
215
+ destroy: () => {
216
+ throw new Error("destroy must not run after a cancel");
217
+ },
218
+ },
219
+ }));
188
220
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/json-render-svelte",
3
- "version": "0.20.0-xm.2",
3
+ "version": "0.20.0-xm.3",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Svelte 5 renderer for @xmachines/json-render-core. JSON becomes Svelte components.",
6
6
  "keywords": [
@@ -49,7 +49,7 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@xmachines/json-render-core": "0.20.0-xm.2"
52
+ "@xmachines/json-render-core": "0.20.0-xm.3"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@sveltejs/package": "^2.3.0",