@molecule/app-angular 3.3.1 → 3.6.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/README.md +4049 -1255
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +3 -2
- package/dist/chat.js.map +1 -1
- package/dist/hooks/external-store.d.ts +32 -0
- package/dist/hooks/external-store.d.ts.map +1 -0
- package/dist/hooks/external-store.js +62 -0
- package/dist/hooks/external-store.js.map +1 -0
- package/dist/hooks/index.d.ts +24 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +24 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-ai-models.d.ts +53 -0
- package/dist/hooks/use-ai-models.d.ts.map +1 -0
- package/dist/hooks/use-ai-models.js +167 -0
- package/dist/hooks/use-ai-models.js.map +1 -0
- package/dist/hooks/use-async.d.ts +129 -0
- package/dist/hooks/use-async.d.ts.map +1 -0
- package/dist/hooks/use-async.js +194 -0
- package/dist/hooks/use-async.js.map +1 -0
- package/dist/hooks/use-auth-flows.d.ts +226 -0
- package/dist/hooks/use-auth-flows.d.ts.map +1 -0
- package/dist/hooks/use-auth-flows.js +481 -0
- package/dist/hooks/use-auth-flows.js.map +1 -0
- package/dist/hooks/use-auth.d.ts +85 -0
- package/dist/hooks/use-auth.d.ts.map +1 -0
- package/dist/hooks/use-auth.js +104 -0
- package/dist/hooks/use-auth.js.map +1 -0
- package/dist/hooks/use-forms.d.ts +174 -0
- package/dist/hooks/use-forms.d.ts.map +1 -0
- package/dist/hooks/use-forms.js +221 -0
- package/dist/hooks/use-forms.js.map +1 -0
- package/dist/hooks/use-http.d.ts +163 -0
- package/dist/hooks/use-http.d.ts.map +1 -0
- package/dist/hooks/use-http.js +198 -0
- package/dist/hooks/use-http.js.map +1 -0
- package/dist/hooks/use-ide.d.ts +208 -0
- package/dist/hooks/use-ide.d.ts.map +1 -0
- package/dist/hooks/use-ide.js +217 -0
- package/dist/hooks/use-ide.js.map +1 -0
- package/dist/hooks/use-logger.d.ts +40 -0
- package/dist/hooks/use-logger.d.ts.map +1 -0
- package/dist/hooks/use-logger.js +56 -0
- package/dist/hooks/use-logger.js.map +1 -0
- package/dist/hooks/use-native.d.ts +218 -0
- package/dist/hooks/use-native.d.ts.map +1 -0
- package/dist/hooks/use-native.js +173 -0
- package/dist/hooks/use-native.js.map +1 -0
- package/dist/hooks/use-profile-form.d.ts +113 -0
- package/dist/hooks/use-profile-form.d.ts.map +1 -0
- package/dist/hooks/use-profile-form.js +253 -0
- package/dist/hooks/use-profile-form.js.map +1 -0
- package/dist/hooks/use-router.d.ts +219 -0
- package/dist/hooks/use-router.d.ts.map +1 -0
- package/dist/hooks/use-router.js +266 -0
- package/dist/hooks/use-router.js.map +1 -0
- package/dist/hooks/use-storage.d.ts +142 -0
- package/dist/hooks/use-storage.d.ts.map +1 -0
- package/dist/hooks/use-storage.js +299 -0
- package/dist/hooks/use-storage.js.map +1 -0
- package/dist/hooks/use-store.d.ts +81 -0
- package/dist/hooks/use-store.d.ts.map +1 -0
- package/dist/hooks/use-store.js +143 -0
- package/dist/hooks/use-store.js.map +1 -0
- package/dist/hooks/use-theme.d.ts +59 -0
- package/dist/hooks/use-theme.d.ts.map +1 -0
- package/dist/hooks/use-theme.js +117 -0
- package/dist/hooks/use-theme.js.map +1 -0
- package/dist/hooks/use-translation.d.ts +91 -0
- package/dist/hooks/use-translation.d.ts.map +1 -0
- package/dist/hooks/use-translation.js +152 -0
- package/dist/hooks/use-translation.js.map +1 -0
- package/dist/hooks/use-verify-payment-return.d.ts +86 -0
- package/dist/hooks/use-verify-payment-return.d.ts.map +1 -0
- package/dist/hooks/use-verify-payment-return.js +167 -0
- package/dist/hooks/use-verify-payment-return.js.map +1 -0
- package/dist/hooks/use-version.d.ts +49 -0
- package/dist/hooks/use-version.d.ts.map +1 -0
- package/dist/hooks/use-version.js +70 -0
- package/dist/hooks/use-version.js.map +1 -0
- package/dist/i18n-reactive.d.ts +2 -5
- package/dist/i18n-reactive.d.ts.map +1 -1
- package/dist/i18n-reactive.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +24 -0
- package/dist/inject.d.ts.map +1 -0
- package/dist/inject.js +33 -0
- package/dist/inject.js.map +1 -0
- package/dist/link.d.ts +63 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +82 -0
- package/dist/link.js.map +1 -0
- package/dist/maybe-signal.d.ts +26 -0
- package/dist/maybe-signal.d.ts.map +1 -0
- package/dist/maybe-signal.js +20 -0
- package/dist/maybe-signal.js.map +1 -0
- package/dist/providers.d.ts +24 -0
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +44 -3
- package/dist/providers.js.map +1 -1
- package/dist/session-ready.d.ts +41 -0
- package/dist/session-ready.d.ts.map +1 -0
- package/dist/session-ready.js +79 -0
- package/dist/session-ready.js.map +1 -0
- package/dist/tokens.d.ts +15 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +12 -0
- package/dist/tokens.js.map +1 -1
- package/dist/types.d.ts +14 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAOL,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,eAAe,IAAI,mBAAmB,EAEtC,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,EACvD,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAOL,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,eAAe,IAAI,mBAAmB,EAEtC,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,EACvD,MAAM,uBAAuB,CAAA;AAM9B,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,kBAAkB,CAAA;AAE/C,0CAA0C;AAC1C,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAA;AAEhD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,CAAC,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACpE,GAAG,mBAAmB,CAAA;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,mBAAyC,CAAA;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,qBAA6C,CAAA;AAEpF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAAO,2BAChB,CAAA;AAE7B;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAU9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,aAAa,CAkCvF"}
|
package/dist/chat.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { afterNextRender, computed, DestroyRef, effect, inject, isSignal, signal, untracked, } from '@angular/core';
|
|
8
8
|
import { convergeHistory as coreConvergeHistory, createChatSession, localOnlyMessages as coreLocalOnlyMessages, resetChatStoresForTests as coreResetChatStoresForTests, } from '@molecule/app-ai-chat';
|
|
9
9
|
import { t } from '@molecule/app-i18n';
|
|
10
|
+
import { readMaybeSignal } from './maybe-signal.js';
|
|
10
11
|
import { CHAT_PROVIDER } from './tokens.js';
|
|
11
12
|
/**
|
|
12
13
|
* Converges the local transcript with authoritative server history. See
|
|
@@ -77,7 +78,7 @@ export function useChatProvider() {
|
|
|
77
78
|
*/
|
|
78
79
|
export function useChat(options) {
|
|
79
80
|
const provider = useChatProvider();
|
|
80
|
-
let current = untracked(() => (
|
|
81
|
+
let current = untracked(() => readMaybeSignal(options));
|
|
81
82
|
const session = createChatSession({ ...current, provider });
|
|
82
83
|
const state = signal(session.getState(), /* @ts-ignore */
|
|
83
84
|
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
@@ -86,7 +87,7 @@ export function useChat(options) {
|
|
|
86
87
|
// endpoint is a conversation change, which the session loads.
|
|
87
88
|
if (isSignal(options)) {
|
|
88
89
|
effect(() => {
|
|
89
|
-
const next = options
|
|
90
|
+
const next = readMaybeSignal(options);
|
|
90
91
|
if (next === current)
|
|
91
92
|
return;
|
|
92
93
|
current = next;
|
package/dist/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,QAAQ,EACR,UAAU,EACV,MAAM,EACN,MAAM,EACN,QAAQ,EAER,MAAM,EACN,SAAS,GACV,MAAM,eAAe,CAAA;AAStB,OAAO,EACL,eAAe,IAAI,mBAAmB,EACtC,iBAAiB,EACjB,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,GACvD,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AA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AI,KAAK,OAAO;gBAAE,OAAM;YAC5B,OAAO,GAAG,IAAI,CAAA;YACd,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,UAAU,GAAwB,IAAI,CAAA;IAC1C,4EAA4E;IAC5E,uCAAuC;IACvC,eAAe,CAAC,GAAG,EAAE;QACnB,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;IAChC,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE;QAChC,WAAW,EAAE,CAAA;QACb,UAAU,EAAE,EAAE,CAAA;QACd,UAAU,GAAG,IAAI,CAAA;IACnB,CAAC,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAgC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;QAC3E,GAAG;QACH,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;KAC7B,CAAC,CAC+D,CAAA;IACnE,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The external-store read discipline React's `useSyncExternalStore` hooks have,
|
|
3
|
+
* as a reusable bridge for the Angular hooks over providers that announce
|
|
4
|
+
* changes (`useVersion`, `useWorkspace`, `usePreview`).
|
|
5
|
+
*
|
|
6
|
+
* React reads the store twice while rendering, subscribes, then reads again to
|
|
7
|
+
* catch a change that landed in between; every notification re-reads once, and
|
|
8
|
+
* a notification that actually changed the snapshot re-reads three more times
|
|
9
|
+
* while React re-renders and re-checks. Service providers RECORD those reads,
|
|
10
|
+
* so a binding that reads a different number of times is a different client of
|
|
11
|
+
* the provider — this bridge keeps this package's read discipline identical to
|
|
12
|
+
* React's.
|
|
13
|
+
*
|
|
14
|
+
* The `read` passed in must cache its snapshot the way React's hook does (a
|
|
15
|
+
* stable object between notifications); the bridge compares snapshots by
|
|
16
|
+
* identity, exactly like `useSyncExternalStore`.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { type Signal } from '@angular/core';
|
|
21
|
+
/**
|
|
22
|
+
* Subscribes to an external store and mirrors its value into a signal, with
|
|
23
|
+
* React's read discipline. Call it in an injection context.
|
|
24
|
+
*
|
|
25
|
+
* @param read - Reads the store's current snapshot (records on the provider);
|
|
26
|
+
* must return a stable object between notifications.
|
|
27
|
+
* @param subscribe - Subscribes to the store; receives the hook's own
|
|
28
|
+
* snapshot-invalidating callback and returns the unsubscribe function.
|
|
29
|
+
* @returns A signal of the store's current snapshot.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useExternalStore<T>(read: () => T, subscribe: (notify: () => void) => () => void): Signal<T>;
|
|
32
|
+
//# sourceMappingURL=external-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-store.d.ts","sourceRoot":"","sources":["../../src/hooks/external-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAsB,KAAK,MAAM,EAAqB,MAAM,eAAe,CAAA;AAElF;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,CAAC,EACb,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,GAC5C,MAAM,CAAC,CAAC,CAAC,CA2BX"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The external-store read discipline React's `useSyncExternalStore` hooks have,
|
|
3
|
+
* as a reusable bridge for the Angular hooks over providers that announce
|
|
4
|
+
* changes (`useVersion`, `useWorkspace`, `usePreview`).
|
|
5
|
+
*
|
|
6
|
+
* React reads the store twice while rendering, subscribes, then reads again to
|
|
7
|
+
* catch a change that landed in between; every notification re-reads once, and
|
|
8
|
+
* a notification that actually changed the snapshot re-reads three more times
|
|
9
|
+
* while React re-renders and re-checks. Service providers RECORD those reads,
|
|
10
|
+
* so a binding that reads a different number of times is a different client of
|
|
11
|
+
* the provider — this bridge keeps this package's read discipline identical to
|
|
12
|
+
* React's.
|
|
13
|
+
*
|
|
14
|
+
* The `read` passed in must cache its snapshot the way React's hook does (a
|
|
15
|
+
* stable object between notifications); the bridge compares snapshots by
|
|
16
|
+
* identity, exactly like `useSyncExternalStore`.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { DestroyRef, inject, signal, untracked } from '@angular/core';
|
|
21
|
+
/**
|
|
22
|
+
* Subscribes to an external store and mirrors its value into a signal, with
|
|
23
|
+
* React's read discipline. Call it in an injection context.
|
|
24
|
+
*
|
|
25
|
+
* @param read - Reads the store's current snapshot (records on the provider);
|
|
26
|
+
* must return a stable object between notifications.
|
|
27
|
+
* @param subscribe - Subscribes to the store; receives the hook's own
|
|
28
|
+
* snapshot-invalidating callback and returns the unsubscribe function.
|
|
29
|
+
* @returns A signal of the store's current snapshot.
|
|
30
|
+
*/
|
|
31
|
+
export function useExternalStore(read, subscribe) {
|
|
32
|
+
// React reads the snapshot twice during its render phase.
|
|
33
|
+
read();
|
|
34
|
+
const state = signal(read(), /* @ts-ignore */
|
|
35
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
36
|
+
let reRenderScheduled = false;
|
|
37
|
+
const stop = subscribe(() => {
|
|
38
|
+
// Every notification re-reads once, changed or not.
|
|
39
|
+
const next = read();
|
|
40
|
+
if (Object.is(untracked(state), next))
|
|
41
|
+
return;
|
|
42
|
+
state.set(next);
|
|
43
|
+
if (reRenderScheduled)
|
|
44
|
+
return;
|
|
45
|
+
reRenderScheduled = true;
|
|
46
|
+
queueMicrotask(() => {
|
|
47
|
+
reRenderScheduled = false;
|
|
48
|
+
// React re-renders (one read) and its commit re-checks the snapshot
|
|
49
|
+
// (two more reads) once per update, however many notifications landed
|
|
50
|
+
// in the same flush.
|
|
51
|
+
state.set(read());
|
|
52
|
+
read();
|
|
53
|
+
read();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
// A change between the first read and this subscription still shows: React
|
|
57
|
+
// reads again right after subscribing.
|
|
58
|
+
state.set(read());
|
|
59
|
+
inject(DestroyRef).onDestroy(stop);
|
|
60
|
+
return state.asReadonly();
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=external-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-store.js","sourceRoot":"","sources":["../../src/hooks/external-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAElF;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAa,EACb,SAA6C;IAE7C,0DAA0D;IAC1D,IAAI,EAAE,CAAA;IACN,MAAM,KAAK,GAAG,MAAM,CAAI,IAAI,EAAE;8EAAC,CAAA;IAC/B,IAAI,iBAAiB,GAAG,KAAK,CAAA;IAC7B,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,EAAE;QAC1B,oDAAoD;QACpD,MAAM,IAAI,GAAG,IAAI,EAAE,CAAA;QACnB,IAAI,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;YAAE,OAAM;QAC7C,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACf,IAAI,iBAAiB;YAAE,OAAM;QAC7B,iBAAiB,GAAG,IAAI,CAAA;QACxB,cAAc,CAAC,GAAG,EAAE;YAClB,iBAAiB,GAAG,KAAK,CAAA;YACzB,oEAAoE;YACpE,sEAAsE;YACtE,qBAAqB;YACrB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;YACjB,IAAI,EAAE,CAAA;YACN,IAAI,EAAE,CAAA;QACR,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,2EAA2E;IAC3E,uCAAuC;IACvC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IACjB,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAClC,OAAO,KAAK,CAAC,UAAU,EAAE,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular functions mirroring every `@molecule/app-react` hook.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export * from './external-store.js';
|
|
7
|
+
export * from './use-ai-models.js';
|
|
8
|
+
export * from './use-async.js';
|
|
9
|
+
export * from './use-auth.js';
|
|
10
|
+
export * from './use-auth-flows.js';
|
|
11
|
+
export * from './use-forms.js';
|
|
12
|
+
export * from './use-http.js';
|
|
13
|
+
export * from './use-ide.js';
|
|
14
|
+
export * from './use-logger.js';
|
|
15
|
+
export * from './use-native.js';
|
|
16
|
+
export * from './use-profile-form.js';
|
|
17
|
+
export * from './use-router.js';
|
|
18
|
+
export * from './use-storage.js';
|
|
19
|
+
export * from './use-store.js';
|
|
20
|
+
export * from './use-theme.js';
|
|
21
|
+
export * from './use-translation.js';
|
|
22
|
+
export * from './use-verify-payment-return.js';
|
|
23
|
+
export * from './use-version.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular functions mirroring every `@molecule/app-react` hook.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export * from './external-store.js';
|
|
7
|
+
export * from './use-ai-models.js';
|
|
8
|
+
export * from './use-async.js';
|
|
9
|
+
export * from './use-auth.js';
|
|
10
|
+
export * from './use-auth-flows.js';
|
|
11
|
+
export * from './use-forms.js';
|
|
12
|
+
export * from './use-http.js';
|
|
13
|
+
export * from './use-ide.js';
|
|
14
|
+
export * from './use-logger.js';
|
|
15
|
+
export * from './use-native.js';
|
|
16
|
+
export * from './use-profile-form.js';
|
|
17
|
+
export * from './use-router.js';
|
|
18
|
+
export * from './use-storage.js';
|
|
19
|
+
export * from './use-store.js';
|
|
20
|
+
export * from './use-theme.js';
|
|
21
|
+
export * from './use-translation.js';
|
|
22
|
+
export * from './use-verify-payment-return.js';
|
|
23
|
+
export * from './use-version.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular function for the AI model catalog, mirroring `useAIModels` and
|
|
3
|
+
* `resetAIModelsCache` from `@molecule/app-react`.
|
|
4
|
+
*
|
|
5
|
+
* The catalog cache is a module-level singleton shared by every instance of
|
|
6
|
+
* this package, exactly like React's: the first mount of a scope fetches, and
|
|
7
|
+
* later mounts read the cache.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type Signal } from '@angular/core';
|
|
12
|
+
import type { AppModelDefinition, AppModeModelDefaults } from '@molecule/app-ai-models';
|
|
13
|
+
import { type MaybeSignal } from '../maybe-signal.js';
|
|
14
|
+
/**
|
|
15
|
+
* Test-only: drops every cached model list so the next {@link useAIModels}
|
|
16
|
+
* call refetches. Exposed for unit tests; do not call from production code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resetAIModelsCache(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Result returned by {@link useAIModels}: every field as a signal.
|
|
21
|
+
*/
|
|
22
|
+
export interface UseAIModelsResult {
|
|
23
|
+
/** Available models, or an empty array while loading. */
|
|
24
|
+
readonly models: Signal<AppModelDefinition[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Per-mode server default model ids for the requester's tier, or `undefined`
|
|
27
|
+
* while loading or on servers that don't provide them.
|
|
28
|
+
*/
|
|
29
|
+
readonly defaults: Signal<AppModeModelDefaults | undefined>;
|
|
30
|
+
/** The single model marked `freeTier: true`, or `undefined`. */
|
|
31
|
+
readonly freeTierModel: Signal<AppModelDefinition | undefined>;
|
|
32
|
+
/** `true` while the initial fetch is in flight. */
|
|
33
|
+
readonly loading: Signal<boolean>;
|
|
34
|
+
/** Error from the initial fetch, or `null`. */
|
|
35
|
+
readonly error: Signal<Error | null>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Subscribes to the cached AI model catalog. The first mount of a scope
|
|
39
|
+
* triggers a single `GET /ai/models` fetch; subsequent mounts return the
|
|
40
|
+
* cached result. Call it in an injection context.
|
|
41
|
+
*
|
|
42
|
+
* The project id may be a signal: the hook then switches to that project's
|
|
43
|
+
* scope on the same component — resubscribing, resyncing from the new scope's
|
|
44
|
+
* cache and fetching it when it is not cached — the way React re-renders
|
|
45
|
+
* `useAIModels` with a new `projectId`.
|
|
46
|
+
*
|
|
47
|
+
* @param projectId - Optional project scope: includes that project's custom
|
|
48
|
+
* ("bring your own AI") models on servers that support them (or a signal of
|
|
49
|
+
* it).
|
|
50
|
+
* @returns Models, free-tier model, loading flag, and error as signals.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useAIModels(projectId?: MaybeSignal<string | undefined>): UseAIModelsResult;
|
|
53
|
+
//# sourceMappingURL=use-ai-models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-ai-models.d.ts","sourceRoot":"","sources":["../../src/hooks/use-ai-models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAwC,KAAK,MAAM,EAAqB,MAAM,eAAe,CAAA;AAEpG,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAIvF,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,oBAAoB,CAAA;AA+FtE;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CASzC;AAcD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAA;IAC7C;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAA;IAC3D,gEAAgE;IAChE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAA;IAC9D,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IACjC,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;CACrC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,iBAAiB,CAmD1F"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular function for the AI model catalog, mirroring `useAIModels` and
|
|
3
|
+
* `resetAIModelsCache` from `@molecule/app-react`.
|
|
4
|
+
*
|
|
5
|
+
* The catalog cache is a module-level singleton shared by every instance of
|
|
6
|
+
* this package, exactly like React's: the first mount of a scope fetches, and
|
|
7
|
+
* later mounts read the cache.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { computed, DestroyRef, effect, inject, signal, untracked } from '@angular/core';
|
|
12
|
+
import { loadAIModelCatalog, pickFreeTierModel } from '@molecule/app-ai-models';
|
|
13
|
+
import { readMaybeSignal } from '../maybe-signal.js';
|
|
14
|
+
import { useHttpClient } from './use-http.js';
|
|
15
|
+
/** One cache entry per scope — `''` for the unscoped catalog, else the projectId. */
|
|
16
|
+
const caches = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* The cache entry for a scope, created on first use.
|
|
19
|
+
*
|
|
20
|
+
* @param scope - `''` for the unscoped catalog, else the projectId.
|
|
21
|
+
* @returns The scope's cache entry.
|
|
22
|
+
*/
|
|
23
|
+
function cacheFor(scope) {
|
|
24
|
+
let cache = caches.get(scope);
|
|
25
|
+
if (!cache) {
|
|
26
|
+
cache = { models: null, defaults: undefined, error: null, inFlight: null };
|
|
27
|
+
caches.set(scope, cache);
|
|
28
|
+
}
|
|
29
|
+
return cache;
|
|
30
|
+
}
|
|
31
|
+
/** Listeners keyed by the same scope as the cache they observe. */
|
|
32
|
+
const listenersByScope = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* The listener set for a scope, created on first use.
|
|
35
|
+
*
|
|
36
|
+
* @param scope - The cache scope.
|
|
37
|
+
* @returns The scope's listener set.
|
|
38
|
+
*/
|
|
39
|
+
function listenersFor(scope) {
|
|
40
|
+
let set = listenersByScope.get(scope);
|
|
41
|
+
if (!set) {
|
|
42
|
+
set = new Set();
|
|
43
|
+
listenersByScope.set(scope, set);
|
|
44
|
+
}
|
|
45
|
+
return set;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Broadcasts a scope's current cache state to its subscribed listeners.
|
|
49
|
+
*
|
|
50
|
+
* @param scope - The cache scope to notify.
|
|
51
|
+
*/
|
|
52
|
+
function notify(scope) {
|
|
53
|
+
const cache = cacheFor(scope);
|
|
54
|
+
for (const listener of listenersFor(scope)) {
|
|
55
|
+
listener({ models: cache.models, defaults: cache.defaults, error: cache.error });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Triggers (or rejoins) the single in-flight fetch of `/ai/models` for a scope
|
|
60
|
+
* and stores the result in that scope's module-level cache.
|
|
61
|
+
*
|
|
62
|
+
* @param http - HTTP client used for the single fetch.
|
|
63
|
+
* @param scope - `''` for the unscoped catalog, else the projectId.
|
|
64
|
+
* @returns The fetched model list.
|
|
65
|
+
*/
|
|
66
|
+
async function fetchOnce(http, scope) {
|
|
67
|
+
const cache = cacheFor(scope);
|
|
68
|
+
if (cache.models)
|
|
69
|
+
return cache.models;
|
|
70
|
+
if (cache.inFlight)
|
|
71
|
+
return cache.inFlight;
|
|
72
|
+
cache.inFlight = loadAIModelCatalog(http, undefined, scope || undefined)
|
|
73
|
+
.then((catalog) => {
|
|
74
|
+
cache.models = catalog.models;
|
|
75
|
+
cache.defaults = catalog.defaults;
|
|
76
|
+
cache.error = null;
|
|
77
|
+
cache.inFlight = null;
|
|
78
|
+
notify(scope);
|
|
79
|
+
return catalog.models;
|
|
80
|
+
})
|
|
81
|
+
.catch((err) => {
|
|
82
|
+
cache.error = err instanceof Error ? err : new Error(String(err));
|
|
83
|
+
cache.inFlight = null;
|
|
84
|
+
notify(scope);
|
|
85
|
+
throw cache.error;
|
|
86
|
+
});
|
|
87
|
+
return cache.inFlight;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Test-only: drops every cached model list so the next {@link useAIModels}
|
|
91
|
+
* call refetches. Exposed for unit tests; do not call from production code.
|
|
92
|
+
*/
|
|
93
|
+
export function resetAIModelsCache() {
|
|
94
|
+
for (const [scope, cache] of caches) {
|
|
95
|
+
cache.models = null;
|
|
96
|
+
cache.defaults = undefined;
|
|
97
|
+
cache.error = null;
|
|
98
|
+
cache.inFlight = null;
|
|
99
|
+
notify(scope);
|
|
100
|
+
}
|
|
101
|
+
caches.clear();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Subscribes to the cached AI model catalog. The first mount of a scope
|
|
105
|
+
* triggers a single `GET /ai/models` fetch; subsequent mounts return the
|
|
106
|
+
* cached result. Call it in an injection context.
|
|
107
|
+
*
|
|
108
|
+
* The project id may be a signal: the hook then switches to that project's
|
|
109
|
+
* scope on the same component — resubscribing, resyncing from the new scope's
|
|
110
|
+
* cache and fetching it when it is not cached — the way React re-renders
|
|
111
|
+
* `useAIModels` with a new `projectId`.
|
|
112
|
+
*
|
|
113
|
+
* @param projectId - Optional project scope: includes that project's custom
|
|
114
|
+
* ("bring your own AI") models on servers that support them (or a signal of
|
|
115
|
+
* it).
|
|
116
|
+
* @returns Models, free-tier model, loading flag, and error as signals.
|
|
117
|
+
*/
|
|
118
|
+
export function useAIModels(projectId) {
|
|
119
|
+
const http = useHttpClient();
|
|
120
|
+
const destroyRef = inject(DestroyRef);
|
|
121
|
+
// The scope this hook is currently wired to. React's effect keyed on the
|
|
122
|
+
// scope re-subscribes and refetches when a re-render changes it; the effect
|
|
123
|
+
// below does the same for a signal argument.
|
|
124
|
+
let scope = readMaybeSignal(projectId) ?? '';
|
|
125
|
+
const snapshot = signal({ models: null, defaults: undefined, error: null }, /* @ts-ignore */
|
|
126
|
+
...(ngDevMode ? [{ debugName: "snapshot" }] : /* istanbul ignore next */ []));
|
|
127
|
+
const listener = (next) => snapshot.set(next);
|
|
128
|
+
listenersFor(scope).add(listener);
|
|
129
|
+
const seed = () => {
|
|
130
|
+
const cache = cacheFor(scope);
|
|
131
|
+
snapshot.set({ models: cache.models, defaults: cache.defaults, error: cache.error });
|
|
132
|
+
};
|
|
133
|
+
seed();
|
|
134
|
+
// Subscribe, resync and (when the scope has no answer yet) fetch, exactly
|
|
135
|
+
// what React's mount effect does; re-runs only when the scope changes, as
|
|
136
|
+
// its effect's dependency array does.
|
|
137
|
+
effect(() => {
|
|
138
|
+
const nextScope = readMaybeSignal(projectId) ?? '';
|
|
139
|
+
if (nextScope !== scope) {
|
|
140
|
+
listenersFor(scope).delete(listener);
|
|
141
|
+
scope = nextScope;
|
|
142
|
+
listenersFor(scope).add(listener);
|
|
143
|
+
}
|
|
144
|
+
untracked(() => {
|
|
145
|
+
seed();
|
|
146
|
+
const cache = cacheFor(scope);
|
|
147
|
+
if (!cache.models && !cache.error) {
|
|
148
|
+
fetchOnce(http, scope).catch((_error) => {
|
|
149
|
+
// fetchOnce mirrors the error into cache.error, which the listener delivers.
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
destroyRef.onDestroy(() => {
|
|
155
|
+
listenersFor(scope).delete(listener);
|
|
156
|
+
});
|
|
157
|
+
const models = computed(() => snapshot().models ?? [], /* @ts-ignore */
|
|
158
|
+
...(ngDevMode ? [{ debugName: "models" }] : /* istanbul ignore next */ []));
|
|
159
|
+
return {
|
|
160
|
+
models,
|
|
161
|
+
defaults: computed(() => snapshot().defaults),
|
|
162
|
+
freeTierModel: computed(() => pickFreeTierModel(models())),
|
|
163
|
+
loading: computed(() => !snapshot().models && !snapshot().error),
|
|
164
|
+
error: computed(() => snapshot().error),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=use-ai-models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-ai-models.js","sourceRoot":"","sources":["../../src/hooks/use-ai-models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAGpG,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAG/E,OAAO,EAAoB,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAS7C,qFAAqF;AACrF,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAA;AAE5C;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,KAAa;IAC7B,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ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AS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,MAAe,EAAE,EAAE;oBAC/C,6EAA6E;gBAC/E,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE;QACxB,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,EAAE;+EAAC,CAAA;IACtD,OAAO;QACL,MAAM;QACN,QAAQ,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC;QAC7C,aAAa,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1D,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC;QAChE,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC;KACxC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular functions for async state, mirroring `usePromise`, `useAsyncState`
|
|
3
|
+
* and `useOptimisticValue` from `@molecule/app-react`.
|
|
4
|
+
*
|
|
5
|
+
* `usePromise` and `useAsyncState` return a plain mutable TUPLE whose state
|
|
6
|
+
* member is updated in place: the tuple is the mounted result for this
|
|
7
|
+
* component instance's whole lifetime, and every snapshot of it must show the
|
|
8
|
+
* state at that moment (React re-renders a new state object into the same
|
|
9
|
+
* tuple; this port mutates the same tuple's members).
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type Signal } from '@angular/core';
|
|
14
|
+
import type { OptimisticValue, OptimisticValueOptions } from '@molecule/app-state';
|
|
15
|
+
import type { PromiseStatus } from '@molecule/app-utilities';
|
|
16
|
+
import { type MaybeSignal } from '../maybe-signal.js';
|
|
17
|
+
/**
|
|
18
|
+
* The state of the latest {@link usePromise} call.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The resolved value's shape.
|
|
21
|
+
*/
|
|
22
|
+
export interface UsePromiseState<T> {
|
|
23
|
+
/** `'idle'`, `'pending'`, `'resolved'` or `'rejected'`. */
|
|
24
|
+
status: PromiseStatus;
|
|
25
|
+
/** The resolved value, `null` before the first resolution and after a reset. */
|
|
26
|
+
value: T | null;
|
|
27
|
+
/** The rejection of the latest call, or the cancel message as an Error. */
|
|
28
|
+
error: Error | null;
|
|
29
|
+
/** Marks a pending call rejected; its late result is not shown. */
|
|
30
|
+
cancel: (message?: string) => void;
|
|
31
|
+
/** Returns the state to idle and clears value and error. */
|
|
32
|
+
reset: () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wraps an async function with the state of its latest call. Call it in an
|
|
36
|
+
* injection context (a component field initializer or constructor).
|
|
37
|
+
*
|
|
38
|
+
* For one UI action, pass `state.status === 'pending'` to a button's loading
|
|
39
|
+
* input. The control then refuses input while the request is pending and
|
|
40
|
+
* re-enables when the tracked call settles. Handle the returned promise's
|
|
41
|
+
* rejection; the hook also records the failure in `state.error`.
|
|
42
|
+
*
|
|
43
|
+
* This hook tracks the latest call: it does not serialize invocations or
|
|
44
|
+
* cancel their network requests. An explicit reset/cancel changes the tracked
|
|
45
|
+
* state, so it is not proof that an outstanding request has stopped. Use an
|
|
46
|
+
* app-owned queue when every click must be accepted in order.
|
|
47
|
+
*
|
|
48
|
+
* @param asyncFn - The async function to wrap.
|
|
49
|
+
* @returns A tuple of `[state, wrappedFunction]`; the state object is updated
|
|
50
|
+
* in place for this instance's lifetime.
|
|
51
|
+
*/
|
|
52
|
+
export declare const usePromise: <T extends (...args: never[]) => Promise<unknown>>(asyncFn: T) => [UsePromiseState<Awaited<ReturnType<T>>>, (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>];
|
|
53
|
+
/**
|
|
54
|
+
* An async-capable setState function: a value, an updater receiving the
|
|
55
|
+
* previous state, or a promise resolving to either. Errors from a resolved
|
|
56
|
+
* promise are swallowed so they never surface as unhandled rejections.
|
|
57
|
+
*
|
|
58
|
+
* @template T - The state's shape.
|
|
59
|
+
*/
|
|
60
|
+
export type AsyncSetState<T> = (value: T | ((prev: T) => T) | Promise<T | ((prev: T) => T)>) => Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* An async-capable extendState function for partial updates.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The state's shape.
|
|
65
|
+
*/
|
|
66
|
+
export type AsyncExtendState<T> = (partial: Partial<T> | ((prev: T) => Partial<T>) | Promise<Partial<T> | ((prev: T) => Partial<T>)>) => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Like `useState` but accepts Promises and supports partial state extension.
|
|
69
|
+
* Call it in an injection context.
|
|
70
|
+
*
|
|
71
|
+
* There is NO latest-wins guard (pinned like React's): whatever settles last
|
|
72
|
+
* wins, even over a newer synchronous set.
|
|
73
|
+
*
|
|
74
|
+
* @param initialState - Initial state value.
|
|
75
|
+
* @returns A tuple of `[state, setState, extendState]`; the state member is
|
|
76
|
+
* replaced in place for this instance's lifetime.
|
|
77
|
+
*/
|
|
78
|
+
export declare const useAsyncState: <T>(initialState: T) => [T, AsyncSetState<T>, AsyncExtendState<T>];
|
|
79
|
+
/**
|
|
80
|
+
* What {@link useOptimisticValue} returns: the state to render (as signals —
|
|
81
|
+
* the same fields React's result carries as plain values) and the two ways to
|
|
82
|
+
* change it.
|
|
83
|
+
*
|
|
84
|
+
* @template T - The value's shape.
|
|
85
|
+
*/
|
|
86
|
+
export interface UseOptimisticValueResult<T> {
|
|
87
|
+
/** The newest chosen value, or the server's value when nothing is saving. */
|
|
88
|
+
readonly value: Signal<T>;
|
|
89
|
+
/** Whether a save is running or waiting to run. */
|
|
90
|
+
readonly pending: Signal<boolean>;
|
|
91
|
+
/** The failure of the newest change, after the value went back; `null` otherwise. */
|
|
92
|
+
readonly error: Signal<unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Shows `next` at once and saves it, after any save already running.
|
|
95
|
+
*
|
|
96
|
+
* @param next - The value the person chose.
|
|
97
|
+
*/
|
|
98
|
+
set: OptimisticValue<T>['set'];
|
|
99
|
+
/**
|
|
100
|
+
* Like `set`, computed from the value shown now (`update((on) => !on)`).
|
|
101
|
+
*
|
|
102
|
+
* @param change - Computes the next value from the value shown now.
|
|
103
|
+
*/
|
|
104
|
+
update: OptimisticValue<T>['update'];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A server-backed value — a favorite, follow, like or bookmark button, a
|
|
108
|
+
* rating, a quantity, a setting switch — that changes on the first read after
|
|
109
|
+
* a tap and is saved one change at a time, in order. Call it in an injection
|
|
110
|
+
* context.
|
|
111
|
+
*
|
|
112
|
+
* Only a failure of the newest change puts the server value back. A new server
|
|
113
|
+
* `value` is taken only while nothing is being saved, so a parent re-render or
|
|
114
|
+
* a refetch of older data never flips the control mid-save.
|
|
115
|
+
*
|
|
116
|
+
* The options may be a signal, and the controller follows them the way React's
|
|
117
|
+
* re-render does: `commit`, `equals` and `onError` are read from the options
|
|
118
|
+
* the signal holds at the moment they run, and a server `value` that differs
|
|
119
|
+
* (by `equals`) from the last one received is synced in — kept as the fallback
|
|
120
|
+
* while a save runs — with the controller and any pending save kept on the same
|
|
121
|
+
* component.
|
|
122
|
+
*
|
|
123
|
+
* @param options - The server's current value and how to save a change (or a
|
|
124
|
+
* signal of them).
|
|
125
|
+
* @returns The value to render, whether a save is pending, the newest failure,
|
|
126
|
+
* and `set`/`update`.
|
|
127
|
+
*/
|
|
128
|
+
export declare const useOptimisticValue: <T>(options: MaybeSignal<OptimisticValueOptions<T>>) => UseOptimisticValueResult<T>;
|
|
129
|
+
//# sourceMappingURL=use-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-async.d.ts","sourceRoot":"","sources":["../../src/hooks/use-async.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAwC,KAAK,MAAM,EAAa,MAAM,eAAe,CAAA;AAE5F,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAElF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,oBAAoB,CAAA;AAGtE;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,2DAA2D;IAC3D,MAAM,EAAE,aAAa,CAAA;IACrB,gFAAgF;IAChF,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,2EAA2E;IAC3E,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,mEAAmE;IACnE,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,4DAA4D;IAC5D,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,EACzE,SAAS,CAAC,KACT,CACD,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EACvC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAmE5D,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAC7B,KAAK,EAAE,CAAC,GAAG,CAA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