@xoong/data 0.0.36 → 0.0.41
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/package.json +2 -2
- package/src/view.js +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xoong/data",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
4
4
|
"description": "xoong data layer: OpenAPI-driven client, auto cache, entity store, derived views, live updates. Depends only on @xoong/core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@xoong/core": "0.0.
|
|
18
|
+
"@xoong/core": "0.0.41"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"src"
|
package/src/view.js
CHANGED
|
@@ -382,7 +382,7 @@ function bindNode(node, scope, ctx, disposers) {
|
|
|
382
382
|
disposers.push(() => el.removeEventListener('click', refresh));
|
|
383
383
|
continue;
|
|
384
384
|
}
|
|
385
|
-
if (attr.name === 'xo-body' || attr.name === 'xo-keep' || attr.name === 'xo-optimistic' || attr.name === 'xo-selected' || attr.name === 'xo-with' || attr.name === 'xo-confirm' || attr.name === 'xo-notice' || attr.name === 'xo-t') continue;
|
|
385
|
+
if (attr.name === 'xo-body' || attr.name === 'xo-keep' || attr.name === 'xo-optimistic' || attr.name === 'xo-selected' || attr.name === 'xo-with' || attr.name === 'xo-confirm' || attr.name === 'xo-notice' || attr.name === 'xo-then' || attr.name === 'xo-t') continue;
|
|
386
386
|
const parts = parseInterpolation(attr.value);
|
|
387
387
|
if (parts) {
|
|
388
388
|
const name = attr.name;
|
|
@@ -513,8 +513,8 @@ function bindAction(el, eventName, opRef, scope, ctx, disposers) {
|
|
|
513
513
|
try { op0 = client.op(opRef); } catch { /* reported when the form is submitted */ }
|
|
514
514
|
if (op0?.bodySchema) {
|
|
515
515
|
const bodyPath = el.getAttribute('xo-body');
|
|
516
|
-
// An edit form (the operation has path parameters, or xo-body names a record) starts from that record; a create form starts empty.
|
|
517
|
-
const edits = !!bodyPath || /\{[^}]+\}/.test(op0.path);
|
|
516
|
+
// An edit form (the operation has path parameters, is a PUT or PATCH, or xo-body names a record) starts from that record; a create form starts empty.
|
|
517
|
+
const edits = !!bodyPath || /\{[^}]+\}/.test(op0.path) || op0.method === 'PUT' || op0.method === 'PATCH';
|
|
518
518
|
const record = edits ? () => { const plain = client.store.denormalize(lookup(scope, bodyPath ?? '.')); return plain && typeof plain === 'object' ? plain : undefined; } : undefined;
|
|
519
519
|
engine = formEngine.attach(el, { schema: op0.bodySchema, record, hadRecord: edits });
|
|
520
520
|
disposers.push(() => engine.detach());
|
|
@@ -571,6 +571,12 @@ function bindAction(el, eventName, opRef, scope, ctx, disposers) {
|
|
|
571
571
|
const result = bulk ? results : results[0];
|
|
572
572
|
if (!engine && eventName === 'submit' && !el.hasAttribute('xo-keep')) /** @type {HTMLFormElement} */ (el).reset?.(); // a sent form starts empty again
|
|
573
573
|
host.emit('xo-done', result);
|
|
574
|
+
const then = el.getAttribute('xo-then'); // go on to another page: `{field}` comes from the result (a created record), then from the item acted on
|
|
575
|
+
if (then !== null) {
|
|
576
|
+
const resultScope = { value: () => (Array.isArray(result) ? undefined : result), parent: scope };
|
|
577
|
+
const path = evalParts(parseInterpolation(then) ?? [then], resultScope, lookup);
|
|
578
|
+
if (el.dispatchEvent(new CustomEvent('xo-go', { bubbles: true, cancelable: true, detail: { path } }))) location.assign(path); // <xo-router> handles it and cancels the default
|
|
579
|
+
}
|
|
574
580
|
if (noticeText) host.emit('xo-notice', { message: noticeText, kind: 'success' }); // shown by <xo-toast>
|
|
575
581
|
} catch (e) {
|
|
576
582
|
// API failures are expected flows (events + global onError). Anything else is a bug in the screen.
|