@molecule/app-query-angular 0.0.0-stage → 1.1.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/LICENSE +202 -0
- package/README.md +979 -2
- package/dist/index.d.ts +464 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +464 -0
- package/dist/index.js.map +1 -0
- package/dist/query-content.component.d.ts +73 -0
- package/dist/query-content.component.d.ts.map +1 -0
- package/dist/query-content.component.js +148 -0
- package/dist/query-content.component.js.map +1 -0
- package/dist/resource.d.ts +11 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +10 -0
- package/dist/resource.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/use-prefetch.d.ts +46 -0
- package/dist/use-prefetch.d.ts.map +1 -0
- package/dist/use-prefetch.js +31 -0
- package/dist/use-prefetch.js.map +1 -0
- package/dist/use-query.d.ts +72 -0
- package/dist/use-query.d.ts.map +1 -0
- package/dist/use-query.js +265 -0
- package/dist/use-query.js.map +1 -0
- package/package.json +73 -4
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render resource-dependent content only after its document exists — the
|
|
3
|
+
* Angular counterpart of `QueryContent` in `@molecule/app-query-react`, with
|
|
4
|
+
* the node-valued props as `TemplateRef`s. The component is headless: it owns
|
|
5
|
+
* no translations and no styling, and projects the rendered branch beside the
|
|
6
|
+
* host (`display: contents`), so the DOM is exactly the branch's own.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { ChangeDetectorRef, Component, effect, inject, signal, untracked, ViewChild, ViewContainerRef, } from '@angular/core';
|
|
10
|
+
import * as i0 from "@angular/core";
|
|
11
|
+
const _c0 = ["outlet"];
|
|
12
|
+
/**
|
|
13
|
+
* The loaded-data branch receives a non-null document. Pending, failed initial
|
|
14
|
+
* reads and missing records never mount that branch, so its actions cannot
|
|
15
|
+
* swallow an early click. Cached data remains mounted during refresh, including
|
|
16
|
+
* a failed refresh. Status fallbacks belong outside the list or record
|
|
17
|
+
* container rendered by `children`, and so does a refresh line; the default
|
|
18
|
+
* fallbacks render nothing.
|
|
19
|
+
*
|
|
20
|
+
* The templates receive the render arguments as template context: `children`
|
|
21
|
+
* gets the document as `$implicit` and `a0` (`let-data`), `error` gets the
|
|
22
|
+
* error value (`let-error`), and `pending`/`missing` render without a context.
|
|
23
|
+
*/
|
|
24
|
+
export class QueryContent {
|
|
25
|
+
/** State from useQuery, or any compatible query observer. */
|
|
26
|
+
query = { data: undefined, status: 'idle', error: undefined };
|
|
27
|
+
/** Mounted only with a real document, including false, zero and an empty list. */
|
|
28
|
+
children = null;
|
|
29
|
+
/** Initial idle/loading content. Render a status template, never a fake item or action. */
|
|
30
|
+
pending = null;
|
|
31
|
+
/** Content for a loaded null record. Null is distinct from an unfinished request. */
|
|
32
|
+
missing = null;
|
|
33
|
+
/** A failed initial read. Cached data stays visible if its refresh fails. */
|
|
34
|
+
error = null;
|
|
35
|
+
/** Where the chosen branch renders. */
|
|
36
|
+
outlet;
|
|
37
|
+
/** Marks this region for check when the observed document changes. */
|
|
38
|
+
changeDetector = inject(ChangeDetectorRef);
|
|
39
|
+
/** The observer the reactivity effect is subscribed to (a new prop re-subscribes it). */
|
|
40
|
+
observer = signal(this.query, /* @ts-ignore */
|
|
41
|
+
...(ngDevMode ? [{ debugName: "observer" }] : /* istanbul ignore next */ []));
|
|
42
|
+
/** The template currently mounted. */
|
|
43
|
+
current = null;
|
|
44
|
+
/** The context object the mounted view reads (updated in place). */
|
|
45
|
+
context = {};
|
|
46
|
+
/** The mounted branch view, when a template is showing. */
|
|
47
|
+
view;
|
|
48
|
+
constructor() {
|
|
49
|
+
// A `useQuery` result exposes its state through getters that read the
|
|
50
|
+
// observer's own signals. React re-renders a `QueryContent`'s parent on
|
|
51
|
+
// every state change; Angular only re-checks a view something marked, and
|
|
52
|
+
// the parent's `[query]="query"` binding reads none of those signals. Read
|
|
53
|
+
// them here, in an effect, so a changed document marks this region for
|
|
54
|
+
// check exactly when React would re-render it. A replaced `query` prop
|
|
55
|
+
// re-subscribes the same effect to the new observer.
|
|
56
|
+
effect(() => {
|
|
57
|
+
const query = this.observer();
|
|
58
|
+
void query?.data;
|
|
59
|
+
void query?.status;
|
|
60
|
+
void query?.error;
|
|
61
|
+
untracked(() => {
|
|
62
|
+
this.update();
|
|
63
|
+
this.changeDetector.markForCheck();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The branch the current query state shows.
|
|
69
|
+
* @returns The template and its context, or nothing.
|
|
70
|
+
*/
|
|
71
|
+
branch() {
|
|
72
|
+
const query = this.query;
|
|
73
|
+
if (query?.data === undefined) {
|
|
74
|
+
return query?.status === 'error' && this.error
|
|
75
|
+
? {
|
|
76
|
+
template: this.error,
|
|
77
|
+
context: { $implicit: query.error, a0: query.error },
|
|
78
|
+
}
|
|
79
|
+
: { template: this.pending ?? null, context: {} };
|
|
80
|
+
}
|
|
81
|
+
if (query.data === null)
|
|
82
|
+
return { template: this.missing ?? null, context: {} };
|
|
83
|
+
return { template: this.children, context: { $implicit: query.data, a0: query.data } };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Follows a replaced `query` prop: the reactivity effect subscribes to the
|
|
87
|
+
* new observer's own signals on its next run.
|
|
88
|
+
*/
|
|
89
|
+
ngOnChanges() {
|
|
90
|
+
this.observer.set(this.query);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Mounts the branch the query state shows, and refreshes the mounted view's
|
|
94
|
+
* context when the state changes. Runs on every change-detection pass, so an
|
|
95
|
+
* input set by a host binding is always folded in before this runs.
|
|
96
|
+
*/
|
|
97
|
+
ngDoCheck() {
|
|
98
|
+
this.update();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Shows the branch the current query state describes: a different template
|
|
102
|
+
* replaces the mounted view, and a changed document (or error) is written into
|
|
103
|
+
* the context the mounted view reads.
|
|
104
|
+
*/
|
|
105
|
+
update() {
|
|
106
|
+
const next = this.branch();
|
|
107
|
+
if (next.template !== this.current) {
|
|
108
|
+
this.view?.destroy();
|
|
109
|
+
this.view = undefined;
|
|
110
|
+
this.current = next.template;
|
|
111
|
+
if (next.template)
|
|
112
|
+
this.view = this.outlet.createEmbeddedView(next.template, this.context);
|
|
113
|
+
}
|
|
114
|
+
for (const key of Object.keys(this.context)) {
|
|
115
|
+
if (!(key in next.context))
|
|
116
|
+
delete this.context[key];
|
|
117
|
+
}
|
|
118
|
+
Object.assign(this.context, next.context);
|
|
119
|
+
this.view?.markForCheck();
|
|
120
|
+
}
|
|
121
|
+
static ɵfac = function QueryContent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || QueryContent)(); };
|
|
122
|
+
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: QueryContent, selectors: [["mol-query-content"]], viewQuery: function QueryContent_Query(rf, ctx) { if (rf & 1) {
|
|
123
|
+
i0.ɵɵviewQuery(_c0, 7, ViewContainerRef);
|
|
124
|
+
} if (rf & 2) {
|
|
125
|
+
let _t;
|
|
126
|
+
i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.outlet = _t.first);
|
|
127
|
+
} }, hostAttrs: ["data-parity-unwrap", "", 2, "display", "contents"], inputs: { query: "query", pending: "pending", missing: "missing", children: "children", error: "error" }, features: [i0.ɵɵNgOnChangesFeature], decls: 2, vars: 0, consts: [["outlet", ""]], template: function QueryContent_Template(rf, ctx) { if (rf & 1) {
|
|
128
|
+
i0.ɵɵdomElementContainer(0, null, 0);
|
|
129
|
+
} }, encapsulation: 2 });
|
|
130
|
+
}
|
|
131
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(QueryContent, [{
|
|
132
|
+
type: Component,
|
|
133
|
+
args: [{
|
|
134
|
+
selector: 'mol-query-content',
|
|
135
|
+
standalone: true,
|
|
136
|
+
template: '<ng-container #outlet></ng-container>',
|
|
137
|
+
inputs: ['query', 'pending', 'missing', 'children', 'error'],
|
|
138
|
+
host: {
|
|
139
|
+
'data-parity-unwrap': '',
|
|
140
|
+
style: 'display: contents',
|
|
141
|
+
},
|
|
142
|
+
}]
|
|
143
|
+
}], () => [], { outlet: [{
|
|
144
|
+
type: ViewChild,
|
|
145
|
+
args: ['outlet', { read: ViewContainerRef, static: true }]
|
|
146
|
+
}] }); })();
|
|
147
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(QueryContent, { className: "QueryContent", filePath: "query-content.component.ts", lineNumber: 54 }); })();
|
|
148
|
+
//# sourceMappingURL=query-content.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-content.component.js","sourceRoot":"","sources":["../src/query-content.component.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,iBAAiB,EACjB,SAAS,EAET,MAAM,EAEN,MAAM,EAEN,MAAM,EAEN,SAAS,EACT,SAAS,EACT,gBAAgB,GACjB,MAAM,eAAe,CAAA;;;AAUtB;;;;;;;;;;;GAWG;AAWH,MAAM,OAAO,YAAY;IACvB,6DAA6D;IAC7D,KAAK,GAAkC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;IAC5F,kFAAkF;IAClF,QAAQ,GAA+C,IAAI,CAAA;IAC3D,2FAA2F;IAC3F,OAAO,GAAgC,IAAI,CAAA;IAC3C,qFAAqF;IACrF,OAAO,GAAgC,IAAI,CAAA;IAC3C,6EAA6E;IAC7E,KAAK,GAAiD,IAAI,CAAA;IAE1D,uCAAuC;IAE/B,MAAM,CAAmB;IACjC,sEAAsE;IACrD,cAAc,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA;IAC3D,yFAAyF;IACxE,QAAQ,G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,YAAY;mCAaM,gBAAgB;;;;;YApBlC,oCAAqC;;;iFAOrC,YAAY;cAVxB,SAAS;eAAC;gBACT,QAAQ,EAAE,mBAAmB;gBAC7B,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE,uCAAuC;gBACjD,MAAM,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC;gBAC5D,IAAI,EAAE;oBACJ,oBAAoB,EAAE,EAAE;oBACxB,KAAK,EAAE,mBAAmB;iBAC3B;aACF;;kBAcE,SAAS;mBAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE;;kFAblD,YAAY"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One API resource on the shared query cache. `createQueryResource` is
|
|
3
|
+
* framework-neutral, so it lives in `@molecule/app-query` (with its full
|
|
4
|
+
* documentation); this package re-exports it so Angular pages import it next to
|
|
5
|
+
* `useQuery` and `QueryContent`.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export type { QueryResource, QueryResourceConfig, ResourceHttp, ResourceResponse, } from '@molecule/app-query';
|
|
10
|
+
export { createQueryResource } from '@molecule/app-query';
|
|
11
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,GACjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/resource.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One API resource on the shared query cache. `createQueryResource` is
|
|
3
|
+
* framework-neutral, so it lives in `@molecule/app-query` (with its full
|
|
4
|
+
* documentation); this package re-exports it so Angular pages import it next to
|
|
5
|
+
* `useQuery` and `QueryContent`.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export { createQueryResource } from '@molecule/app-query';
|
|
10
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular query observer contracts — the counterparts of the types
|
|
3
|
+
* `@molecule/app-query-react` exports, with the node-valued props typed as
|
|
4
|
+
* Angular `TemplateRef`s.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { TemplateRef } from '@angular/core';
|
|
8
|
+
import type { QueryState } from '@molecule/app-query';
|
|
9
|
+
/**
|
|
10
|
+
* A mounted query's state and its explicit cache and refresh actions. The state
|
|
11
|
+
* fields read as plain values at read time (each reads the observer's current
|
|
12
|
+
* state signal), so a template binding that calls them re-renders when the
|
|
13
|
+
* document changes, and a test can snapshot the object at any moment.
|
|
14
|
+
*/
|
|
15
|
+
export interface UseQueryResult<T> extends QueryState<T> {
|
|
16
|
+
/**
|
|
17
|
+
* Publish a saved document to this key and all its observers. Render `data`
|
|
18
|
+
* directly instead of copying it to local state: later cache updates then
|
|
19
|
+
* remain visible. A function receives this key's current cached document,
|
|
20
|
+
* never retained previous-page data. Returning `undefined` leaves the cache
|
|
21
|
+
* unchanged. A disabled (`null`) query does nothing, including not calling an
|
|
22
|
+
* updater. Like React state setters, wrap a function-valued document in an
|
|
23
|
+
* updater. A saved callback stays bound to its original key. The write
|
|
24
|
+
* supersedes older in-flight reads, using the bonded client's `set` contract.
|
|
25
|
+
*/
|
|
26
|
+
setData: (value: T | ((previous: T | undefined) => T | undefined)) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Fetch this key again, even when its cached document is fresh. Observers
|
|
29
|
+
* receive the updated state. Resolves with that state, including an error
|
|
30
|
+
* when the request fails; a disabled (`null`) query resolves idle without a
|
|
31
|
+
* request.
|
|
32
|
+
*/
|
|
33
|
+
refetch: () => Promise<QueryState<T>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The context a children template receives: the loaded, non-null document, as
|
|
37
|
+
* `$implicit` and as the render function's first argument (`a0`).
|
|
38
|
+
*
|
|
39
|
+
* @template T - The document's shape.
|
|
40
|
+
*/
|
|
41
|
+
export interface QueryContentContext<T> {
|
|
42
|
+
/** The loaded document (never `undefined` or `null`). */
|
|
43
|
+
$implicit: NonNullable<T>;
|
|
44
|
+
/** The same document, as the first render argument. */
|
|
45
|
+
a0: NonNullable<T>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The context an error template receives: the failed read's error value, as
|
|
49
|
+
* `$implicit` and as the render function's first argument (`a0`).
|
|
50
|
+
*/
|
|
51
|
+
export interface QueryContentErrorContext {
|
|
52
|
+
/** The error the failed read rejected with. */
|
|
53
|
+
$implicit: unknown;
|
|
54
|
+
/** The same error, as the first render argument. */
|
|
55
|
+
a0: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** A loaded document owns its controls; absent documents expose only status content. */
|
|
58
|
+
export interface QueryContentProps<T> {
|
|
59
|
+
/** State from useQuery, or any compatible query observer. */
|
|
60
|
+
query: Pick<QueryState<T>, 'data' | 'status' | 'error'>;
|
|
61
|
+
/** Mounted only with a real document, including false, zero and an empty list. */
|
|
62
|
+
children: TemplateRef<QueryContentContext<T>> | null;
|
|
63
|
+
/** Initial idle/loading content. Render a status template, never a fake item or action. */
|
|
64
|
+
pending?: TemplateRef<unknown> | null;
|
|
65
|
+
/** Content for a loaded null record. Null is distinct from an unfinished request. */
|
|
66
|
+
missing?: TemplateRef<unknown> | null;
|
|
67
|
+
/** A failed initial read. Cached data stays visible if its refresh fails. */
|
|
68
|
+
error?: TemplateRef<QueryContentErrorContext> | null;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD;;;;;;;;;OASG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,IAAI,CAAA;IAC1E;;;;;OAKG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;CACtC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,yDAAyD;IACzD,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IACzB,uDAAuD;IACvD,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAA;IAClB,oDAAoD;IACpD,EAAE,EAAE,OAAO,CAAA;CACZ;AAED,wFAAwF;AACxF,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,6DAA6D;IAC7D,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,CAAA;IACvD,kFAAkF;IAClF,QAAQ,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;IACpD,2FAA2F;IAC3F,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IACrC,qFAAqF;IACrF,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IACrC,6EAA6E;IAC7E,KAAK,CAAC,EAAE,WAAW,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAA;CACrD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Warm the cache ahead of a navigation — the Angular counterpart of
|
|
3
|
+
* `usePrefetch` in `@molecule/app-query-react`. `prefetchQuery` itself is
|
|
4
|
+
* framework-neutral and lives in `@molecule/app-query`; this module re-exports
|
|
5
|
+
* it and adds the hook and the intent handlers.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { QueryOptions } from '@molecule/app-query';
|
|
10
|
+
export { prefetchQuery } from '@molecule/app-query';
|
|
11
|
+
/**
|
|
12
|
+
* A stable `prefetch(options)` function for event handlers. Call it in an
|
|
13
|
+
* injection context (a component field initializer or constructor); the
|
|
14
|
+
* returned function is one object for the component's lifetime.
|
|
15
|
+
*
|
|
16
|
+
* @returns The prefetch function.
|
|
17
|
+
*/
|
|
18
|
+
export declare function usePrefetch(): <T>(options: QueryOptions<T>) => void;
|
|
19
|
+
/**
|
|
20
|
+
* The handlers {@link intentPrefetchProps} returns, named after the DOM events
|
|
21
|
+
* an Angular template binds (`(pointerenter)`, `(focus)`, `(touchstart)`).
|
|
22
|
+
*/
|
|
23
|
+
export interface IntentPrefetchProps {
|
|
24
|
+
/** Warms the document when the pointer arrives. */
|
|
25
|
+
pointerenter: () => void;
|
|
26
|
+
/** Warms the document on keyboard focus. */
|
|
27
|
+
focus: () => void;
|
|
28
|
+
/** Warms the document when a touch starts. */
|
|
29
|
+
touchstart: () => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handlers that warm a document at the first sign of intent: the pointer
|
|
33
|
+
* arriving, keyboard focus, or a touch starting. Put them on a link's host
|
|
34
|
+
* bindings (each property is named after the DOM event it warms on):
|
|
35
|
+
*
|
|
36
|
+
* ```typescript
|
|
37
|
+
* host: { '(pointerenter)': 'prefetch.pointerenter()', '(focus)': 'prefetch.focus()' }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* It is a plain function (not a hook), so it works inside `@for` loops too.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Key, fetch, freshness.
|
|
43
|
+
* @returns The handlers.
|
|
44
|
+
*/
|
|
45
|
+
export declare function intentPrefetchProps<T>(options: QueryOptions<T>): IntentPrefetchProps;
|
|
46
|
+
//# sourceMappingURL=use-prefetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prefetch.d.ts","sourceRoot":"","sources":["../src/use-prefetch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;;;GAMG;AACH,wBAAgB,WAAW,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAEnE;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,YAAY,EAAE,MAAM,IAAI,CAAA;IACxB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAGpF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { prefetchQuery } from '@molecule/app-query';
|
|
2
|
+
export { prefetchQuery } from '@molecule/app-query';
|
|
3
|
+
/**
|
|
4
|
+
* A stable `prefetch(options)` function for event handlers. Call it in an
|
|
5
|
+
* injection context (a component field initializer or constructor); the
|
|
6
|
+
* returned function is one object for the component's lifetime.
|
|
7
|
+
*
|
|
8
|
+
* @returns The prefetch function.
|
|
9
|
+
*/
|
|
10
|
+
export function usePrefetch() {
|
|
11
|
+
return (options) => prefetchQuery(options);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Handlers that warm a document at the first sign of intent: the pointer
|
|
15
|
+
* arriving, keyboard focus, or a touch starting. Put them on a link's host
|
|
16
|
+
* bindings (each property is named after the DOM event it warms on):
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* host: { '(pointerenter)': 'prefetch.pointerenter()', '(focus)': 'prefetch.focus()' }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* It is a plain function (not a hook), so it works inside `@for` loops too.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Key, fetch, freshness.
|
|
25
|
+
* @returns The handlers.
|
|
26
|
+
*/
|
|
27
|
+
export function intentPrefetchProps(options) {
|
|
28
|
+
const go = () => prefetchQuery(options);
|
|
29
|
+
return { pointerenter: go, focus: go, touchstart: go };
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=use-prefetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prefetch.js","sourceRoot":"","sources":["../src/use-prefetch.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAI,OAAwB,EAAQ,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;AACtE,CAAC;AAeD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAI,OAAwB;IAC7D,MAAM,EAAE,GAAG,GAAS,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC7C,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observe one document from the shared cache — the Angular counterpart of
|
|
3
|
+
* `useQuery` in `@molecule/app-query-react`.
|
|
4
|
+
*
|
|
5
|
+
* Call it in an injection context (a component field initializer or
|
|
6
|
+
* constructor). The options may be a plain object or a signal of one: a
|
|
7
|
+
* component that derives its options from an `input()` or `computed()` passes
|
|
8
|
+
* the signal, and a changed key (or principal, or `keepPreviousData` flag) is
|
|
9
|
+
* followed on the SAME hook instance, the way React's re-render follows a new
|
|
10
|
+
* options object.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { type Signal } from '@angular/core';
|
|
15
|
+
import type { QueryOptions } from '@molecule/app-query';
|
|
16
|
+
import type { UseQueryResult } from './types.js';
|
|
17
|
+
/** The options a query may arrive in: plain values, or a signal of them. */
|
|
18
|
+
type QueryOptionsSource<T> = QueryOptions<T> | null | Signal<QueryOptions<T> | null>;
|
|
19
|
+
/**
|
|
20
|
+
* The document for the options' key, kept current: cached data is read on the
|
|
21
|
+
* very first render (so a warmed page never flashes a loading state), a stale
|
|
22
|
+
* or missing document is fetched, and every change re-renders the template that
|
|
23
|
+
* reads the result. Pass `null` to observe nothing. A key change resets to that
|
|
24
|
+
* key's state; the hook never hands a caller another key's document — unless
|
|
25
|
+
* the caller opts into {@link QueryOptions.keepPreviousData}, and then only
|
|
26
|
+
* within one {@link QueryOptions.principal}.
|
|
27
|
+
*
|
|
28
|
+
* The request is stable across template refreshes — a parent state change
|
|
29
|
+
* neither restarts it nor cancels it, so a response that arrives after one still
|
|
30
|
+
* lands. It is aborted only when the key changes or the component is destroyed
|
|
31
|
+
* (the `signal` given to `options.fetch`). Use this instead of a hand-written
|
|
32
|
+
* effect + `fetch`: an effect whose cleanup sets a `cancelled` flag, and whose
|
|
33
|
+
* tracked dependencies include a function rebuilt each run, cancels its own
|
|
34
|
+
* request on every run and then skips the refetch.
|
|
35
|
+
* An explicit `refetch()` is an awaited cache fetch; it can finish after the
|
|
36
|
+
* observer is destroyed, like an explicit `client.fetch(options)` caller.
|
|
37
|
+
*
|
|
38
|
+
* For a LIST, put the route's page, filter and selected view in the key and
|
|
39
|
+
* pass `keepPreviousData` with a `principal`: a Next/Previous or filter change
|
|
40
|
+
* then keeps the rows already on screen until the new page answers, instead of
|
|
41
|
+
* rendering a loading state over an empty list. The key names everything the
|
|
42
|
+
* answer depends on, and the app's HTTP client sends the session, so a list the
|
|
43
|
+
* server can filter or personalize per viewer puts the viewer in its key and
|
|
44
|
+
* passes the same value as `principal` (`'anonymous'` when signed out): an
|
|
45
|
+
* account switch then drops the previous account's document immediately. Only
|
|
46
|
+
* an endpoint that answers every viewer the same takes a viewer-free key with
|
|
47
|
+
* `principal: 'public'`.
|
|
48
|
+
*
|
|
49
|
+
* For custom mutation handlers, `setData(saved)` publishes the server's response to this
|
|
50
|
+
* key and every observer. Use `setData(current => next)` for a local cache update. Render
|
|
51
|
+
* `data` directly; a component-local copy stops observing later server responses. Prefer
|
|
52
|
+
* `createQueryResource` when the API's reads and writes can share one resource definition.
|
|
53
|
+
* Mount record-dependent actions inside `QueryContent` (or an explicit non-null data branch),
|
|
54
|
+
* so a visible action cannot return early because its initial record is still missing.
|
|
55
|
+
* Keep loaded actions mounted during refreshes. Server-backed toggles use
|
|
56
|
+
* `OptimisticToggleButton` from `@molecule/app-ui-angular` (or `useOptimisticValue`
|
|
57
|
+
* from `@molecule/app-angular` in a control that is re-created per record) to keep
|
|
58
|
+
* their displayed label and queued clicks on the same state while a save finishes.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Key, fetch, freshness, and optionally `principal` with
|
|
61
|
+
* `keepPreviousData`; or `null`; or a signal of either (the options a
|
|
62
|
+
* component recomputes on its own state — every change is followed on the
|
|
63
|
+
* same instance).
|
|
64
|
+
* @returns The document's state, `setData()` and `refetch()`. `isPreviousData` is `true` while
|
|
65
|
+
* `data` is the previous key's document for the same principal.
|
|
66
|
+
* @throws {Error} When `keepPreviousData` is set without `principal` — the
|
|
67
|
+
* hook cannot tell a route change from a principal switch, so it refuses
|
|
68
|
+
* rather than risk showing one principal's document to another.
|
|
69
|
+
*/
|
|
70
|
+
export declare function useQuery<T>(options: QueryOptionsSource<T>): UseQueryResult<T>;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=use-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../src/use-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAwC,KAAK,MAAM,EAAqB,MAAM,eAAe,CAAA;AAEpG,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAA;AAGnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,4EAA4E;AAC5E,KAAK,kBAAkB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;AAuBpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CA4M7E"}
|