@assistant-ui/store 0.2.10 → 0.2.12

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.
Files changed (94) hide show
  1. package/README.md +36 -65
  2. package/dist/AuiIf.d.ts +43 -8
  3. package/dist/AuiIf.d.ts.map +1 -1
  4. package/dist/AuiIf.js +28 -3
  5. package/dist/AuiIf.js.map +1 -1
  6. package/dist/Derived.d.ts +15 -13
  7. package/dist/Derived.d.ts.map +1 -1
  8. package/dist/Derived.js +24 -20
  9. package/dist/Derived.js.map +1 -1
  10. package/dist/RenderChildrenWithAccessor.d.ts +13 -6
  11. package/dist/RenderChildrenWithAccessor.d.ts.map +1 -1
  12. package/dist/RenderChildrenWithAccessor.js +42 -48
  13. package/dist/RenderChildrenWithAccessor.js.map +1 -1
  14. package/dist/attachTransformScopes.d.ts +11 -10
  15. package/dist/attachTransformScopes.d.ts.map +1 -1
  16. package/dist/attachTransformScopes.js +20 -23
  17. package/dist/attachTransformScopes.js.map +1 -1
  18. package/dist/index.d.ts +15 -16
  19. package/dist/index.js +14 -18
  20. package/dist/tapClientList.d.ts +26 -23
  21. package/dist/tapClientList.d.ts.map +1 -1
  22. package/dist/tapClientList.js +66 -63
  23. package/dist/tapClientList.js.map +1 -1
  24. package/dist/tapClientLookup.d.ts +14 -11
  25. package/dist/tapClientLookup.d.ts.map +1 -1
  26. package/dist/tapClientLookup.js +31 -37
  27. package/dist/tapClientLookup.js.map +1 -1
  28. package/dist/tapClientResource.d.ts +12 -9
  29. package/dist/tapClientResource.d.ts.map +1 -1
  30. package/dist/tapClientResource.js +92 -104
  31. package/dist/tapClientResource.js.map +1 -1
  32. package/dist/types/client.d.ts +50 -42
  33. package/dist/types/client.d.ts.map +1 -1
  34. package/dist/types/client.js +0 -2
  35. package/dist/types/events.d.ts +23 -24
  36. package/dist/types/events.d.ts.map +1 -1
  37. package/dist/types/events.js +13 -6
  38. package/dist/types/events.js.map +1 -1
  39. package/dist/useAui.d.ts +76 -15
  40. package/dist/useAui.d.ts.map +1 -1
  41. package/dist/useAui.js +178 -175
  42. package/dist/useAui.js.map +1 -1
  43. package/dist/useAuiEvent.d.ts +47 -2
  44. package/dist/useAuiEvent.d.ts.map +1 -1
  45. package/dist/useAuiEvent.js +60 -7
  46. package/dist/useAuiEvent.js.map +1 -1
  47. package/dist/useAuiState.d.ts +31 -10
  48. package/dist/useAuiState.d.ts.map +1 -1
  49. package/dist/useAuiState.js +44 -25
  50. package/dist/useAuiState.js.map +1 -1
  51. package/dist/utils/BaseProxyHandler.d.ts +19 -16
  52. package/dist/utils/BaseProxyHandler.d.ts.map +1 -1
  53. package/dist/utils/BaseProxyHandler.js +46 -43
  54. package/dist/utils/BaseProxyHandler.js.map +1 -1
  55. package/dist/utils/NotificationManager.d.ts +13 -9
  56. package/dist/utils/NotificationManager.d.ts.map +1 -1
  57. package/dist/utils/NotificationManager.js +69 -82
  58. package/dist/utils/NotificationManager.js.map +1 -1
  59. package/dist/utils/proxied-assistant-state.d.ts +8 -4
  60. package/dist/utils/proxied-assistant-state.d.ts.map +1 -1
  61. package/dist/utils/proxied-assistant-state.js +28 -26
  62. package/dist/utils/proxied-assistant-state.js.map +1 -1
  63. package/dist/utils/react-assistant-context.d.ts +31 -13
  64. package/dist/utils/react-assistant-context.d.ts.map +1 -1
  65. package/dist/utils/react-assistant-context.js +69 -56
  66. package/dist/utils/react-assistant-context.js.map +1 -1
  67. package/dist/utils/splitClients.d.ts +12 -8
  68. package/dist/utils/splitClients.d.ts.map +1 -1
  69. package/dist/utils/splitClients.js +39 -43
  70. package/dist/utils/splitClients.js.map +1 -1
  71. package/dist/utils/tap-assistant-context.d.ts +17 -14
  72. package/dist/utils/tap-assistant-context.d.ts.map +1 -1
  73. package/dist/utils/tap-assistant-context.js +18 -15
  74. package/dist/utils/tap-assistant-context.js.map +1 -1
  75. package/dist/utils/tap-client-stack-context.d.ts +10 -6
  76. package/dist/utils/tap-client-stack-context.d.ts.map +1 -1
  77. package/dist/utils/tap-client-stack-context.js +22 -19
  78. package/dist/utils/tap-client-stack-context.js.map +1 -1
  79. package/dist/wrapperResource.d.ts +6 -2
  80. package/dist/wrapperResource.d.ts.map +1 -1
  81. package/dist/wrapperResource.js +12 -9
  82. package/dist/wrapperResource.js.map +1 -1
  83. package/package.json +7 -7
  84. package/src/AuiIf.ts +35 -1
  85. package/src/Derived.ts +1 -1
  86. package/src/types/client.ts +1 -2
  87. package/src/useAui.ts +101 -32
  88. package/src/useAuiEvent.ts +41 -0
  89. package/src/useAuiState.ts +25 -8
  90. package/src/utils/react-assistant-context.tsx +18 -5
  91. package/src/utils/splitClients.ts +4 -2
  92. package/dist/index.d.ts.map +0 -1
  93. package/dist/index.js.map +0 -1
  94. package/dist/types/client.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,18 +1,14 @@
1
- // hooks
2
- export { useAui } from "./useAui.js";
3
- export { useAuiState } from "./useAuiState.js";
4
- export { useAuiEvent } from "./useAuiEvent.js";
5
- export { RenderChildrenWithAccessor } from "./RenderChildrenWithAccessor.js";
6
- // components
7
- export { AuiIf } from "./AuiIf.js";
8
- export { AuiProvider } from "./utils/react-assistant-context.js";
9
- // resources
10
- export { Derived } from "./Derived.js";
11
- export { attachTransformScopes, forwardTransformScopes, } from "./attachTransformScopes.js";
12
- // tap hooks
13
- export { tapAssistantClientRef, tapAssistantEmit, } from "./utils/tap-assistant-context.js";
14
- export { tapClientResource } from "./tapClientResource.js";
15
- export { tapClientLookup } from "./tapClientLookup.js";
16
- export { tapClientList } from "./tapClientList.js";
17
- export { normalizeEventSelector, } from "./types/events.js";
18
- //# sourceMappingURL=index.js.map
1
+ import { tapClientResource } from "./tapClientResource.js";
2
+ import { AuiProvider } from "./utils/react-assistant-context.js";
3
+ import { Derived } from "./Derived.js";
4
+ import { attachTransformScopes, forwardTransformScopes } from "./attachTransformScopes.js";
5
+ import { normalizeEventSelector } from "./types/events.js";
6
+ import { tapAssistantClientRef, tapAssistantEmit } from "./utils/tap-assistant-context.js";
7
+ import { useAui } from "./useAui.js";
8
+ import { useAuiState } from "./useAuiState.js";
9
+ import { AuiIf } from "./AuiIf.js";
10
+ import { RenderChildrenWithAccessor } from "./RenderChildrenWithAccessor.js";
11
+ import { useAuiEvent } from "./useAuiEvent.js";
12
+ import { tapClientLookup } from "./tapClientLookup.js";
13
+ import { tapClientList } from "./tapClientList.js";
14
+ export { AuiIf, AuiProvider, Derived, RenderChildrenWithAccessor, attachTransformScopes, forwardTransformScopes, normalizeEventSelector, tapAssistantClientRef, tapAssistantEmit, tapClientList, tapClientLookup, tapClientResource, useAui, useAuiEvent, useAuiState };
@@ -1,28 +1,31 @@
1
- import type { ContravariantResource } from "@assistant-ui/tap";
2
- import type { ClientMethods } from "./types/client.js";
1
+ import { ClientMethods } from "./types/client.js";
2
+ import { ContravariantResource } from "@assistant-ui/tap";
3
+
4
+ //#region src/tapClientList.d.ts
3
5
  type InferClientState<TMethods> = TMethods extends {
4
- getState: () => infer S;
6
+ getState: () => infer S;
5
7
  } ? S : unknown;
6
- export declare const tapClientList: <TData, TMethods extends ClientMethods>(props: tapClientList.Props<TData, TMethods>) => {
7
- state: InferClientState<TMethods>[];
8
- get: (lookup: {
9
- index: number;
10
- } | {
11
- key: string;
12
- }) => TMethods;
13
- add: (initialData: TData) => void;
8
+ declare const tapClientList: <TData, TMethods extends ClientMethods>(props: tapClientList.Props<TData, TMethods>) => {
9
+ state: InferClientState<TMethods>[];
10
+ get: (lookup: {
11
+ index: number;
12
+ } | {
13
+ key: string;
14
+ }) => TMethods;
15
+ add: (initialData: TData) => void;
14
16
  };
15
- export declare namespace tapClientList {
16
- type ResourceProps<TData> = {
17
- key: string;
18
- getInitialData: () => TData;
19
- remove: () => void;
20
- };
21
- type Props<TData, TMethods extends ClientMethods> = {
22
- initialValues: TData[];
23
- getKey: (data: TData) => string;
24
- resource: ContravariantResource<TMethods, ResourceProps<TData>>;
25
- };
17
+ declare namespace tapClientList {
18
+ type ResourceProps<TData> = {
19
+ key: string;
20
+ getInitialData: () => TData;
21
+ remove: () => void;
22
+ };
23
+ type Props<TData, TMethods extends ClientMethods> = {
24
+ initialValues: TData[];
25
+ getKey: (data: TData) => string;
26
+ resource: ContravariantResource<TMethods, ResourceProps<TData>>;
27
+ };
26
28
  }
27
- export {};
29
+ //#endregion
30
+ export { tapClientList };
28
31
  //# sourceMappingURL=tapClientList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tapClientList.d.ts","sourceRoot":"","sources":["../src/tapClientList.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,0BAAuB;AAEpD,KAAK,gBAAgB,CAAC,QAAQ,IAAI,QAAQ,SAAS;IACjD,QAAQ,EAAE,MAAM,MAAM,CAAC,CAAC;CACzB,GACG,CAAC,GACD,OAAO,CAAC;AAuBZ,eAAO,MAAM,aAAa,GAAI,KAAK,EAAE,QAAQ,SAAS,aAAa,EACjE,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,KAC1C;IACD,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACpC,GAAG,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,QAAQ,CAAC;IAC/D,GAAG,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC;CAqEnC,CAAC;AAEF,yBAAiB,aAAa,CAAC;IAC7B,KAAY,aAAa,CAAC,KAAK,IAAI;QACjC,GAAG,EAAE,MAAM,CAAC;QACZ,cAAc,EAAE,MAAM,KAAK,CAAC;QAC5B,MAAM,EAAE,MAAM,IAAI,CAAC;KACpB,CAAC;IAEF,KAAY,KAAK,CAAC,KAAK,EAAE,QAAQ,SAAS,aAAa,IAAI;QACzD,aAAa,EAAE,KAAK,EAAE,CAAC;QACvB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC;QAChC,QAAQ,EAAE,qBAAqB,CAAC,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;KACjE,CAAC;CACH"}
1
+ {"version":3,"file":"tapClientList.d.ts","names":[],"sources":["../src/tapClientList.ts"],"mappings":";;;;KAKK,gBAAA,aAA6B,QAAQ;EACxC,QAAA;AAAA,IAEE,CAAA;AAAA,cAwBS,aAAA,2BAAyC,aAAA,EACpD,KAAA,EAAO,aAAA,CAAc,KAAA,CAAM,KAAA,EAAO,QAAA;EAElC,KAAA,EAAO,gBAAA,CAAiB,QAAA;EACxB,GAAA,GAAM,MAAA;IAAU,KAAA;EAAA;IAAoB,GAAA;EAAA,MAAkB,QAAA;EACtD,GAAA,GAAM,WAAA,EAAa,KAAA;AAAA;AAAA,kBAuEJ,aAAA;EAAA,KACH,aAAA;IACV,GAAA;IACA,cAAA,QAAsB,KAAA;IACtB,MAAA;EAAA;EAAA,KAGU,KAAA,yBAA8B,aAAA;IACxC,aAAA,EAAe,KAAA;IACf,MAAA,GAAS,IAAA,EAAM,KAAA;IACf,QAAA,EAAU,qBAAA,CAAsB,QAAA,EAAU,aAAA,CAAc,KAAA;EAAA;AAAA"}
@@ -1,68 +1,71 @@
1
- import { tapConst, tapState, withKey } from "@assistant-ui/tap";
2
1
  import { tapClientLookup } from "./tapClientLookup.js";
2
+ import { tapConst, tapState, withKey } from "@assistant-ui/tap";
3
+ //#region src/tapClientList.ts
3
4
  const createProps = (key, data, remove) => {
4
- return {
5
- key,
6
- getInitialData: () => {
7
- if (!data.hasData) {
8
- throw new Error("getInitialData may only be called during initial render");
9
- }
10
- return data.data;
11
- },
12
- remove,
13
- };
5
+ return {
6
+ key,
7
+ getInitialData: () => {
8
+ if (!data.hasData) throw new Error("getInitialData may only be called during initial render");
9
+ return data.data;
10
+ },
11
+ remove
12
+ };
14
13
  };
15
- export const tapClientList = (props) => {
16
- const { initialValues, getKey, resource: Resource } = props;
17
- const initialDataHandles = tapConst(() => [], []);
18
- const [items, setItems] = tapState(() => {
19
- const entries = [];
20
- for (const data of initialValues) {
21
- const key = getKey(data);
22
- const handle = { data, hasData: true };
23
- entries.push([
24
- key,
25
- createProps(key, handle, () => {
26
- setItems((items) => {
27
- const newItems = { ...items };
28
- delete newItems[key];
29
- return newItems;
30
- });
31
- }),
32
- ]);
33
- initialDataHandles.push(handle);
34
- }
35
- return Object.fromEntries(entries);
36
- });
37
- const lookup = tapClientLookup(() => Object.values(items).map((props) => withKey(props.key, Resource(props))), [items, Resource]);
38
- initialDataHandles.forEach((handle) => {
39
- handle.data = undefined;
40
- handle.hasData = false;
41
- });
42
- const add = (data) => {
43
- const key = getKey(data);
44
- setItems((items) => {
45
- if (key in items) {
46
- throw new Error(`Tried to add item with a key ${key} that already exists`);
47
- }
48
- const handle = { data, hasData: true };
49
- initialDataHandles.push(handle);
50
- return {
51
- ...items,
52
- [key]: createProps(key, handle, () => {
53
- setItems((items) => {
54
- const newItems = { ...items };
55
- delete newItems[key];
56
- return newItems;
57
- });
58
- }),
59
- };
60
- });
61
- };
62
- return {
63
- state: lookup.state,
64
- get: lookup.get,
65
- add,
66
- };
14
+ const tapClientList = (props) => {
15
+ const { initialValues, getKey, resource: Resource } = props;
16
+ const initialDataHandles = tapConst(() => [], []);
17
+ const [items, setItems] = tapState(() => {
18
+ const entries = [];
19
+ for (const data of initialValues) {
20
+ const key = getKey(data);
21
+ const handle = {
22
+ data,
23
+ hasData: true
24
+ };
25
+ entries.push([key, createProps(key, handle, () => {
26
+ setItems((items) => {
27
+ const newItems = { ...items };
28
+ delete newItems[key];
29
+ return newItems;
30
+ });
31
+ })]);
32
+ initialDataHandles.push(handle);
33
+ }
34
+ return Object.fromEntries(entries);
35
+ });
36
+ const lookup = tapClientLookup(() => Object.values(items).map((props) => withKey(props.key, Resource(props))), [items, Resource]);
37
+ initialDataHandles.forEach((handle) => {
38
+ handle.data = void 0;
39
+ handle.hasData = false;
40
+ });
41
+ const add = (data) => {
42
+ const key = getKey(data);
43
+ setItems((items) => {
44
+ if (key in items) throw new Error(`Tried to add item with a key ${key} that already exists`);
45
+ const handle = {
46
+ data,
47
+ hasData: true
48
+ };
49
+ initialDataHandles.push(handle);
50
+ return {
51
+ ...items,
52
+ [key]: createProps(key, handle, () => {
53
+ setItems((items) => {
54
+ const newItems = { ...items };
55
+ delete newItems[key];
56
+ return newItems;
57
+ });
58
+ })
59
+ };
60
+ });
61
+ };
62
+ return {
63
+ state: lookup.state,
64
+ get: lookup.get,
65
+ add
66
+ };
67
67
  };
68
+ //#endregion
69
+ export { tapClientList };
70
+
68
71
  //# sourceMappingURL=tapClientList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tapClientList.js","sourceRoot":"","sources":["../src/tapClientList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,6BAA0B;AAWpD,MAAM,WAAW,GAAG,CAClB,GAAW,EACX,IAAuB,EACvB,MAAkB,EACkB,EAAE;IACtC,OAAO;QACL,GAAG;QACH,cAAc,EAAE,GAAG,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,IAAK,CAAC;QACpB,CAAC;QACD,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAA2C,EAK3C,EAAE;IACF,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAI5D,MAAM,kBAAkB,GAAwB,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAEvE,MAA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AAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;YACjB,IAAI,GAAG,IAAI,KAAK,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACb,gCAAgC,GAAG,sBAAsB,CAC1D,CAAC;YACJ,CAAC;YAED,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YACvC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAEhC,OAAO;gBACL,GAAG,KAAK;gBACR,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;oBACnC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;wBACjB,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;wBAC9B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;wBACrB,OAAO,QAAQ,CAAC;oBAClB,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC;aACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,GAAG;KACJ,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"tapClientList.js","names":[],"sources":["../src/tapClientList.ts"],"sourcesContent":["import { tapConst, tapState, withKey } from \"@assistant-ui/tap\";\nimport type { ContravariantResource } from \"@assistant-ui/tap\";\nimport { tapClientLookup } from \"./tapClientLookup\";\nimport type { ClientMethods } from \"./types/client\";\n\ntype InferClientState<TMethods> = TMethods extends {\n getState: () => infer S;\n}\n ? S\n : unknown;\n\ntype DataHandle<TData> = { data: TData | undefined; hasData: boolean };\n\nconst createProps = <TData>(\n key: string,\n data: DataHandle<TData>,\n remove: () => void,\n): tapClientList.ResourceProps<TData> => {\n return {\n key,\n getInitialData: () => {\n if (!data.hasData) {\n throw new Error(\n \"getInitialData may only be called during initial render\",\n );\n }\n return data.data!;\n },\n remove,\n };\n};\n\nexport const tapClientList = <TData, TMethods extends ClientMethods>(\n props: tapClientList.Props<TData, TMethods>,\n): {\n state: InferClientState<TMethods>[];\n get: (lookup: { index: number } | { key: string }) => TMethods;\n add: (initialData: TData) => void;\n} => {\n const { initialValues, getKey, resource: Resource } = props;\n\n type Props = tapClientList.ResourceProps<TData>;\n\n const initialDataHandles: DataHandle<TData>[] = tapConst(() => [], []);\n\n const [items, setItems] = tapState<Record<string, Props>>(() => {\n const entries: [string, Props][] = [];\n for (const data of initialValues) {\n const key = getKey(data);\n const handle = { data, hasData: true };\n entries.push([\n key,\n createProps(key, handle, () => {\n setItems((items) => {\n const newItems = { ...items };\n delete newItems[key];\n return newItems;\n });\n }),\n ]);\n initialDataHandles.push(handle);\n }\n return Object.fromEntries(entries);\n });\n\n const lookup = tapClientLookup<TMethods>(\n () =>\n Object.values(items).map((props) => withKey(props.key, Resource(props))),\n [items, Resource],\n );\n\n initialDataHandles.forEach((handle) => {\n handle.data = undefined;\n handle.hasData = false;\n });\n\n const add = (data: TData) => {\n const key = getKey(data);\n setItems((items) => {\n if (key in items) {\n throw new Error(\n `Tried to add item with a key ${key} that already exists`,\n );\n }\n\n const handle = { data, hasData: true };\n initialDataHandles.push(handle);\n\n return {\n ...items,\n [key]: createProps(key, handle, () => {\n setItems((items) => {\n const newItems = { ...items };\n delete newItems[key];\n return newItems;\n });\n }),\n };\n });\n };\n\n return {\n state: lookup.state,\n get: lookup.get,\n add,\n };\n};\n\nexport namespace tapClientList {\n export type ResourceProps<TData> = {\n key: string;\n getInitialData: () => TData;\n remove: () => void;\n };\n\n export type Props<TData, TMethods extends ClientMethods> = {\n initialValues: TData[];\n getKey: (data: TData) => string;\n resource: ContravariantResource<TMethods, ResourceProps<TData>>;\n };\n}\n"],"mappings":";;;AAaA,MAAM,eACJ,KACA,MACA,WACuC;CACvC,OAAO;EACL;E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;EACL,OAAO,OAAO;EACd,KAAK,OAAO;EACZ;CACF;AACF"}
@@ -1,15 +1,18 @@
1
- import { type ResourceElement } from "@assistant-ui/tap";
2
- import type { ClientMethods } from "./types/client.js";
1
+ import { ClientMethods } from "./types/client.js";
2
+ import { ResourceElement } from "@assistant-ui/tap";
3
+
4
+ //#region src/tapClientLookup.d.ts
3
5
  type InferClientState<TMethods> = TMethods extends {
4
- getState: () => infer S;
6
+ getState: () => infer S;
5
7
  } ? S : unknown;
6
- export declare function tapClientLookup<TMethods extends ClientMethods>(getElements: () => readonly ResourceElement<TMethods>[], getElementsDeps: readonly unknown[]): {
7
- state: InferClientState<TMethods>[];
8
- get: (lookup: {
9
- index: number;
10
- } | {
11
- key: string;
12
- }) => TMethods;
8
+ declare function tapClientLookup<TMethods extends ClientMethods>(getElements: () => readonly ResourceElement<TMethods>[], getElementsDeps: readonly unknown[]): {
9
+ state: InferClientState<TMethods>[];
10
+ get: (lookup: {
11
+ index: number;
12
+ } | {
13
+ key: string;
14
+ }) => TMethods;
13
15
  };
14
- export {};
16
+ //#endregion
17
+ export { tapClientLookup };
15
18
  //# sourceMappingURL=tapClientLookup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tapClientLookup.d.ts","sourceRoot":"","sources":["../src/tapClientLookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,0BAAuB;AAIpD,KAAK,gBAAgB,CAAC,QAAQ,IAAI,QAAQ,SAAS;IACjD,QAAQ,EAAE,MAAM,MAAM,CAAC,CAAC;CACzB,GACG,CAAC,GACD,OAAO,CAAC;AAeZ,wBAAgB,eAAe,CAAC,QAAQ,SAAS,aAAa,EAC5D,WAAW,EAAE,MAAM,SAAS,eAAe,CAAC,QAAQ,CAAC,EAAE,EACvD,eAAe,EAAE,SAAS,OAAO,EAAE,GAClC;IACD,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACpC,GAAG,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,QAAQ,CAAC;CAChE,CA2CA"}
1
+ {"version":3,"file":"tapClientLookup.d.ts","names":[],"sources":["../src/tapClientLookup.ts"],"mappings":";;;;KAUK,gBAAA,aAA6B,QAAQ;EACxC,QAAA;AAAA,IAEE,CAAA;AAAA,iBAgBY,eAAA,kBAAiC,aAAA,CAAA,CAC/C,WAAA,iBAA4B,eAAA,CAAgB,QAAA,KAC5C,eAAA;EAEA,KAAA,EAAO,gBAAA,CAAiB,QAAA;EACxB,GAAA,GAAM,MAAA;IAAU,KAAA;EAAA;IAAoB,GAAA;EAAA,MAAkB,QAAA;AAAA"}
@@ -1,42 +1,36 @@
1
- import { tapMemo, tapResource, tapResources, } from "@assistant-ui/tap";
2
- import { ClientResource } from "./tapClientResource.js";
3
1
  import { wrapperResource } from "./wrapperResource.js";
2
+ import { ClientResource } from "./tapClientResource.js";
3
+ import { tapMemo, tapResource, tapResources } from "@assistant-ui/tap";
4
+ //#region src/tapClientLookup.ts
4
5
  const ClientResourceWithKey = wrapperResource((el) => {
5
- if (el.key === undefined) {
6
- throw new Error("tapClientResource: Element has no key");
7
- }
8
- return tapResource(ClientResource(el));
6
+ if (el.key === void 0) throw new Error("tapClientResource: Element has no key");
7
+ return tapResource(ClientResource(el));
9
8
  });
10
- export function tapClientLookup(getElements, getElementsDeps) {
11
- const resources = tapResources(() => getElements().map((el) => ClientResourceWithKey(el)),
12
- // biome-ignore lint/correctness/useExhaustiveDependencies: getElementsDeps is passed through from caller
13
- getElementsDeps);
14
- const keys = tapMemo(() => Object.keys(resources), [resources]);
15
- // For arrays, track element key -> index mapping
16
- const keyToIndex = tapMemo(() => {
17
- return resources.reduce((acc, resource, index) => {
18
- acc[resource.key] = index;
19
- return acc;
20
- }, {});
21
- }, [resources]);
22
- const state = tapMemo(() => {
23
- return resources.map((r) => r.state);
24
- }, [resources]);
25
- return {
26
- state,
27
- get: (lookup) => {
28
- if ("index" in lookup) {
29
- if (lookup.index < 0 || lookup.index >= keys.length) {
30
- throw new Error(`tapClientLookup: Index ${lookup.index} out of bounds (length: ${keys.length})`);
31
- }
32
- return resources[lookup.index].methods;
33
- }
34
- const index = keyToIndex[lookup.key];
35
- if (index === undefined) {
36
- throw new Error(`tapClientLookup: Key "${lookup.key}" not found`);
37
- }
38
- return resources[index].methods;
39
- },
40
- };
9
+ function tapClientLookup(getElements, getElementsDeps) {
10
+ const resources = tapResources(() => getElements().map((el) => ClientResourceWithKey(el)), getElementsDeps);
11
+ const keys = tapMemo(() => Object.keys(resources), [resources]);
12
+ const keyToIndex = tapMemo(() => {
13
+ return resources.reduce((acc, resource, index) => {
14
+ acc[resource.key] = index;
15
+ return acc;
16
+ }, {});
17
+ }, [resources]);
18
+ return {
19
+ state: tapMemo(() => {
20
+ return resources.map((r) => r.state);
21
+ }, [resources]),
22
+ get: (lookup) => {
23
+ if ("index" in lookup) {
24
+ if (lookup.index < 0 || lookup.index >= keys.length) throw new Error(`tapClientLookup: Index ${lookup.index} out of bounds (length: ${keys.length})`);
25
+ return resources[lookup.index].methods;
26
+ }
27
+ const index = keyToIndex[lookup.key];
28
+ if (index === void 0) throw new Error(`tapClientLookup: Key "${lookup.key}" not found`);
29
+ return resources[index].methods;
30
+ }
31
+ };
41
32
  }
33
+ //#endregion
34
+ export { tapClientLookup };
35
+
42
36
  //# sourceMappingURL=tapClientLookup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tapClientLookup.js","sourceRoot":"","sources":["../src/tapClientLookup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,YAAY,GAEb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,+BAA4B;AACrD,OAAO,EAAE,eAAe,EAAE,6BAA0B;AAQpD,MAAM,qBAAq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,CAAC;gBACtB,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBACpD,MAAM,IAAI,KAAK,CACb,0BAA0B,MAAM,CAAC,KAAK,2BAA2B,IAAI,CAAC,MAAM,GAAG,CAChF,CAAC;gBACJ,CAAC;gBACD,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAE,CAAC,OAAO,CAAC;YAC1C,CAAC;YAED,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,SAAS,CAAC,KAAK,CAAE,CAAC,OAAO,CAAC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"tapClientLookup.js","names":[],"sources":["../src/tapClientLookup.ts"],"sourcesContent":["import {\n tapMemo,\n tapResource,\n tapResources,\n type ResourceElement,\n} from \"@assistant-ui/tap\";\nimport type { ClientMethods } from \"./types/client\";\nimport { ClientResource } from \"./tapClientResource\";\nimport { wrapperResource } from \"./wrapperResource\";\n\ntype InferClientState<TMethods> = TMethods extends {\n getState: () => infer S;\n}\n ? S\n : unknown;\n\nconst ClientResourceWithKey = wrapperResource(\n <TMethods extends ClientMethods>(el: ResourceElement<TMethods>) => {\n if (el.key === undefined) {\n throw new Error(\"tapClientResource: Element has no key\");\n }\n return tapResource(ClientResource(el)) as {\n methods: TMethods;\n state: InferClientState<TMethods>;\n key: string | number;\n };\n },\n);\n\nexport function tapClientLookup<TMethods extends ClientMethods>(\n getElements: () => readonly ResourceElement<TMethods>[],\n getElementsDeps: readonly unknown[],\n): {\n state: InferClientState<TMethods>[];\n get: (lookup: { index: number } | { key: string }) => TMethods;\n} {\n const resources = tapResources(\n () => getElements().map((el) => ClientResourceWithKey(el)),\n // biome-ignore lint/correctness/useExhaustiveDependencies: getElementsDeps is passed through from caller\n getElementsDeps,\n );\n\n const keys = tapMemo(() => Object.keys(resources), [resources]);\n\n // For arrays, track element key -> index mapping\n const keyToIndex = tapMemo(() => {\n return resources.reduce(\n (acc, resource, index) => {\n acc[resource.key] = index;\n return acc;\n },\n {} as Record<string, number>,\n );\n }, [resources]);\n\n const state = tapMemo(() => {\n return resources.map((r) => r.state);\n }, [resources]);\n\n return {\n state,\n get: (lookup: { index: number } | { key: string }) => {\n if (\"index\" in lookup) {\n if (lookup.index < 0 || lookup.index >= keys.length) {\n throw new Error(\n `tapClientLookup: Index ${lookup.index} out of bounds (length: ${keys.length})`,\n );\n }\n return resources[lookup.index]!.methods;\n }\n\n const index = keyToIndex[lookup.key];\n if (index === undefined) {\n throw new Error(`tapClientLookup: Key \"${lookup.key}\" not found`);\n }\n return resources[index]!.methods;\n },\n };\n}\n"],"mappings":";;;;AAgBA,MAAM,wBAAwB,iBACK,OAAkC;CACjE,IAAI,GAAG,QAAQ,KAAA,GACb,MAAM,IAAI,MAAM,uCAAuC;CAEzD,OAAO,YAAY,eAAe,EAAE,CAAC;AAKvC,CACF;AAEA,SAAgB,gBACd,aACA,iBAIA;CACA,MAAM,YAAY,mBACV,YAAY,EAAE,KAAK,OAAO,sBAAsB,EAAE,CAAC,GAEzD,eACF;CAEA,MAAM,OAAO,cAAc,OAAO,KAAK,SAAS,GAAG,CAAC,SAAS,CAAC;CAG9D,MAAM,aAAa,cAAc;EAC/B,OAAO,UAAU,QACd,KAAK,UAAU,UAAU;GACxB,IAAI,SAAS,OAAO;GACpB,OAAO;EACT,GACA,CAAC,CACH;CACF,GAAG,CAAC,SAAS,CAAC;CAMd,OAAO;EACL,OALY,cAAc;GAC1B,OAAO,UAAU,KAAK,MAAM,EAAE,KAAK;EACrC,GAAG,CAAC,SAAS,CAGP;EACJ,MAAM,WAAgD;GACpD,IAAI,WAAW,QAAQ;IACrB,IAAI,OAAO,QAAQ,KAAK,OAAO,SAAS,KAAK,QAC3C,MAAM,IAAI,MACR,0BAA0B,OAAO,MAAM,0BAA0B,KAAK,OAAO,EAC/E;IAEF,OAAO,UAAU,OAAO,OAAQ;GAClC;GAEA,MAAM,QAAQ,WAAW,OAAO;GAChC,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MAAM,yBAAyB,OAAO,IAAI,YAAY;GAElE,OAAO,UAAU,OAAQ;EAC3B;CACF;AACF"}
@@ -1,13 +1,16 @@
1
- import { type ResourceElement } from "@assistant-ui/tap";
2
- import type { ClientMethods } from "./types/client.js";
3
- export declare const getClientState: (client: ClientMethods) => any;
1
+ import { ClientMethods } from "./types/client.js";
2
+ import { ResourceElement } from "@assistant-ui/tap";
3
+
4
+ //#region src/tapClientResource.d.ts
5
+ declare const getClientState: (client: ClientMethods) => any;
4
6
  type InferClientState<TMethods> = TMethods extends {
5
- getState: () => infer S;
7
+ getState: () => infer S;
6
8
  } ? S : undefined;
7
- export declare const tapClientResource: <TMethods extends ClientMethods>(element: ResourceElement<TMethods>) => {
8
- state: InferClientState<TMethods>;
9
- methods: TMethods;
10
- key: string | number | undefined;
9
+ declare const tapClientResource: <TMethods extends ClientMethods>(element: ResourceElement<TMethods>) => {
10
+ state: InferClientState<TMethods>;
11
+ methods: TMethods;
12
+ key: string | number | undefined;
11
13
  };
12
- export {};
14
+ //#endregion
15
+ export { getClientState, tapClientResource };
13
16
  //# sourceMappingURL=tapClientResource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tapClientResource.d.ts","sourceRoot":"","sources":["../src/tapClientResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAErB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,0BAAuB;AAsBpD,eAAO,MAAM,cAAc,GAAI,QAAQ,aAAa,QASnD,CAAC;AAoIF,KAAK,gBAAgB,CAAC,QAAQ,IAAI,QAAQ,SAAS;IACjD,QAAQ,EAAE,MAAM,MAAM,CAAC,CAAC;CACzB,GACG,CAAC,GACD,SAAS,CAAC;AAEd,eAAO,MAAM,iBAAiB,GAAI,QAAQ,SAAS,aAAa,EAC9D,SAAS,eAAe,CAAC,QAAQ,CAAC,KACjC;IACD,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAOlC,CAAC"}
1
+ {"version":3,"file":"tapClientResource.d.ts","names":[],"sources":["../src/tapClientResource.ts"],"mappings":";;;;cA6Ba,cAAA,GAAkB,MAAqB,EAAb,aAAa;AAAA,KA6I/C,gBAAA,aAA6B,QAAQ;EACxC,QAAA;AAAA,IAEE,CAAA;AAAA,cAGS,iBAAA,oBAAsC,aAAA,EACjD,OAAA,EAAS,eAAA,CAAgB,QAAA;EAEzB,KAAA,EAAO,gBAAA,CAAiB,QAAA;EACxB,OAAA,EAAS,QAAA;EACT,GAAA;AAAA"}