@arrai-innovations/reactive-helpers 18.0.1 → 18.0.2

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 (215) hide show
  1. package/package.json +17 -2
  2. package/types/config/listCrud.d.ts +153 -0
  3. package/types/config/listCrud.d.ts.map +1 -0
  4. package/types/config/objectCrud.d.ts +171 -0
  5. package/types/config/objectCrud.d.ts.map +1 -0
  6. package/types/index.d.ts +37 -0
  7. package/types/index.d.ts.map +1 -0
  8. package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
  9. package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
  10. package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
  11. package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
  12. package/types/tests/unit/crudPromise.d.ts +25 -0
  13. package/types/tests/unit/crudPromise.d.ts.map +1 -0
  14. package/types/tests/unit/expectHelpers.d.ts +2 -0
  15. package/types/tests/unit/expectHelpers.d.ts.map +1 -0
  16. package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
  17. package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
  18. package/types/tests/unit/poll.d.ts +2 -0
  19. package/types/tests/unit/poll.d.ts.map +1 -0
  20. package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
  21. package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
  22. package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
  23. package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
  24. package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
  25. package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
  26. package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
  27. package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
  28. package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
  29. package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
  30. package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
  31. package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
  32. package/types/tests/unit/use/listSort.spec.d.ts +2 -0
  33. package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
  34. package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
  35. package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
  36. package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
  37. package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
  38. package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
  39. package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
  40. package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
  41. package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
  42. package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
  43. package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
  44. package/types/tests/unit/use/search.spec.d.ts +2 -0
  45. package/types/tests/unit/use/search.spec.d.ts.map +1 -0
  46. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
  47. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
  48. package/types/tests/unit/utils/classes.spec.d.ts +2 -0
  49. package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
  50. package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
  51. package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
  52. package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
  53. package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
  54. package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
  55. package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
  56. package/types/tests/unit/utils/set.spec.d.ts +2 -0
  57. package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
  58. package/types/tests/unit/utils/watches.spec.d.ts +2 -0
  59. package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
  60. package/types/use/cancellableIntent.d.ts +129 -0
  61. package/types/use/cancellableIntent.d.ts.map +1 -0
  62. package/types/use/combineClasses.d.ts +43 -0
  63. package/types/use/combineClasses.d.ts.map +1 -0
  64. package/types/use/list.d.ts +176 -0
  65. package/types/use/list.d.ts.map +1 -0
  66. package/types/use/listCalculated.d.ts +192 -0
  67. package/types/use/listCalculated.d.ts.map +1 -0
  68. package/types/use/listFilter.d.ts +203 -0
  69. package/types/use/listFilter.d.ts.map +1 -0
  70. package/types/use/listInstance.d.ts +357 -0
  71. package/types/use/listInstance.d.ts.map +1 -0
  72. package/types/use/listKeys.d.ts +15 -0
  73. package/types/use/listKeys.d.ts.map +1 -0
  74. package/types/use/listRelated.d.ts +239 -0
  75. package/types/use/listRelated.d.ts.map +1 -0
  76. package/types/use/listSearch.d.ts +298 -0
  77. package/types/use/listSearch.d.ts.map +1 -0
  78. package/types/use/listSort.d.ts +235 -0
  79. package/types/use/listSort.d.ts.map +1 -0
  80. package/types/use/listSubscription.d.ts +218 -0
  81. package/types/use/listSubscription.d.ts.map +1 -0
  82. package/types/use/loadingError.d.ts +81 -0
  83. package/types/use/loadingError.d.ts.map +1 -0
  84. package/types/use/object.d.ts +67 -0
  85. package/types/use/object.d.ts.map +1 -0
  86. package/types/use/objectCalculated.d.ts +215 -0
  87. package/types/use/objectCalculated.d.ts.map +1 -0
  88. package/types/use/objectInstance.d.ts +289 -0
  89. package/types/use/objectInstance.d.ts.map +1 -0
  90. package/types/use/objectRelated.d.ts +264 -0
  91. package/types/use/objectRelated.d.ts.map +1 -0
  92. package/types/use/objectSubscription.d.ts +249 -0
  93. package/types/use/objectSubscription.d.ts.map +1 -0
  94. package/types/use/paginatedListInstance.d.ts +51 -0
  95. package/types/use/paginatedListInstance.d.ts.map +1 -0
  96. package/types/use/proxyLoadingError.d.ts +36 -0
  97. package/types/use/proxyLoadingError.d.ts.map +1 -0
  98. package/types/use/search.d.ts +144 -0
  99. package/types/use/search.d.ts.map +1 -0
  100. package/types/use/watchesRunning.d.ts +63 -0
  101. package/types/use/watchesRunning.d.ts.map +1 -0
  102. package/types/utils/assignReactiveObject.d.ts +115 -0
  103. package/types/utils/assignReactiveObject.d.ts.map +1 -0
  104. package/types/utils/classes.d.ts +22 -0
  105. package/types/utils/classes.d.ts.map +1 -0
  106. package/types/utils/compact.d.ts +4 -0
  107. package/types/utils/compact.d.ts.map +1 -0
  108. package/types/utils/deleteKey.d.ts +16 -0
  109. package/types/utils/deleteKey.d.ts.map +1 -0
  110. package/types/utils/flattenPaths.d.ts +23 -0
  111. package/types/utils/flattenPaths.d.ts.map +1 -0
  112. package/types/utils/getFakePk.d.ts +13 -0
  113. package/types/utils/getFakePk.d.ts.map +1 -0
  114. package/types/utils/keepAliveTry.d.ts +15 -0
  115. package/types/utils/keepAliveTry.d.ts.map +1 -0
  116. package/types/utils/keyDiff.d.ts +63 -0
  117. package/types/utils/keyDiff.d.ts.map +1 -0
  118. package/types/utils/loadingCombine.d.ts +9 -0
  119. package/types/utils/loadingCombine.d.ts.map +1 -0
  120. package/types/utils/proxyRunning.d.ts +9 -0
  121. package/types/utils/proxyRunning.d.ts.map +1 -0
  122. package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
  123. package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
  124. package/types/utils/set.d.ts +7 -0
  125. package/types/utils/set.d.ts.map +1 -0
  126. package/types/utils/transformWalk.d.ts +2 -0
  127. package/types/utils/transformWalk.d.ts.map +1 -0
  128. package/types/utils/watches.d.ts +155 -0
  129. package/types/utils/watches.d.ts.map +1 -0
  130. package/.circleci/config.yml +0 -88
  131. package/.commitlintrc.json +0 -3
  132. package/.editorconfig +0 -5
  133. package/.husky/commit-msg +0 -3
  134. package/.husky/pre-commit +0 -3
  135. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  136. package/.idea/encodings.xml +0 -6
  137. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  138. package/.idea/modules.xml +0 -8
  139. package/.idea/prettier.xml +0 -8
  140. package/.idea/reactive-helpers.iml +0 -15
  141. package/.prettierignore +0 -5
  142. package/.prettierrc.cjs +0 -5
  143. package/.vscode/extensions.json +0 -3
  144. package/docs/README.md +0 -45
  145. package/docs/config/listCrud.md +0 -422
  146. package/docs/config/objectCrud.md +0 -427
  147. package/docs/use/cancellableIntent.md +0 -165
  148. package/docs/use/combineClasses.md +0 -62
  149. package/docs/use/list.md +0 -361
  150. package/docs/use/listCalculated.md +0 -794
  151. package/docs/use/listFilter.md +0 -897
  152. package/docs/use/listInstance.md +0 -559
  153. package/docs/use/listKeys.md +0 -91
  154. package/docs/use/listRelated.md +0 -706
  155. package/docs/use/listSearch.md +0 -903
  156. package/docs/use/listSort.md +0 -1171
  157. package/docs/use/listSubscription.md +0 -393
  158. package/docs/use/loadingError.md +0 -115
  159. package/docs/use/object.md +0 -668
  160. package/docs/use/objectCalculated.md +0 -741
  161. package/docs/use/objectInstance.md +0 -685
  162. package/docs/use/objectRelated.md +0 -723
  163. package/docs/use/objectSubscription.md +0 -538
  164. package/docs/use/paginatedListInstance.md +0 -155
  165. package/docs/use/proxyLoadingError.md +0 -51
  166. package/docs/use/search.md +0 -321
  167. package/docs/use/watchesRunning.md +0 -84
  168. package/docs/utils/assignReactiveObject.md +0 -413
  169. package/docs/utils/classes.md +0 -139
  170. package/docs/utils/compact.md +0 -67
  171. package/docs/utils/deleteKey.md +0 -61
  172. package/docs/utils/flattenPaths.md +0 -53
  173. package/docs/utils/getFakePk.md +0 -39
  174. package/docs/utils/keepAliveTry.md +0 -59
  175. package/docs/utils/keyDiff.md +0 -117
  176. package/docs/utils/loadingCombine.md +0 -30
  177. package/docs/utils/proxyRunning.md +0 -39
  178. package/docs/utils/relatedCalculatedHelpers.md +0 -93
  179. package/docs/utils/set.md +0 -223
  180. package/docs/utils/transformWalk.md +0 -68
  181. package/docs/utils/watches.md +0 -489
  182. package/eslint.config.js +0 -125
  183. package/lint-staged.config.js +0 -10
  184. package/makeTypeDoc.sh +0 -25
  185. package/make_type_doc.js +0 -59
  186. package/tests/unit/config/listCrud.spec.js +0 -114
  187. package/tests/unit/config/objectCrud.spec.js +0 -160
  188. package/tests/unit/crudPromise.js +0 -40
  189. package/tests/unit/expectHelpers.js +0 -6
  190. package/tests/unit/mockOnUnmounted.js +0 -9
  191. package/tests/unit/poll.js +0 -50
  192. package/tests/unit/use/cancellableIntent.spec.js +0 -152
  193. package/tests/unit/use/listCalculated.spec.js +0 -135
  194. package/tests/unit/use/listFilter.spec.js +0 -484
  195. package/tests/unit/use/listInstance.spec.js +0 -1166
  196. package/tests/unit/use/listRelated.spec.js +0 -260
  197. package/tests/unit/use/listSearch.spec.js +0 -586
  198. package/tests/unit/use/listSort.spec.js +0 -418
  199. package/tests/unit/use/listSubscription.spec.js +0 -845
  200. package/tests/unit/use/loadingError.spec.js +0 -43
  201. package/tests/unit/use/objectInstance.spec.js +0 -1525
  202. package/tests/unit/use/objectSubscription.spec.js +0 -849
  203. package/tests/unit/use/proxyLoadingError.spec.js +0 -64
  204. package/tests/unit/use/search.spec.js +0 -248
  205. package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
  206. package/tests/unit/utils/classes.spec.js +0 -427
  207. package/tests/unit/utils/deleteKey.spec.js +0 -265
  208. package/tests/unit/utils/flattenPaths.spec.js +0 -126
  209. package/tests/unit/utils/keyDiff.spec.js +0 -110
  210. package/tests/unit/utils/set.spec.js +0 -81
  211. package/tests/unit/utils/watches.spec.js +0 -276
  212. package/tsconfig.json +0 -19
  213. package/typedoc-local-plugins/customize-output.js +0 -13
  214. package/typedoc.json +0 -11
  215. package/vitest.config.js +0 -11
@@ -0,0 +1,239 @@
1
+ /**
2
+ * The options for the list related composition function.
3
+ *
4
+ * @typedef {object} ListRelatedOptions
5
+ * @property {ListRelatedParentState} parentState - The parent state object.
6
+ * @property {import('vue').Ref<ListRelatedRules>} relatedObjectsRules - The rules for the related objects.
7
+ */
8
+ /**
9
+ * The properties for the list related composition function.
10
+ *
11
+ * @typedef {object} ListRelatedProperties
12
+ * @property {ListRelatedState} state - The state for the list related property.
13
+ * @property {ListRelatedParentState} parentState - The parent state object.
14
+ * @property {import('./watchesRunning.js').WatchesRunning} watchesRunning - The watches running instance.
15
+ * @property {import('vue').EffectScope} effectScope - The effect scope for the list related property.
16
+ */
17
+ /**
18
+ * An instance of `useListRelated`.
19
+ *
20
+ * @typedef {ListRelatedProperties} ListRelated
21
+ */
22
+ /**
23
+ * Creates and manages multiple instances of list-related properties, linking each to corresponding parent instances
24
+ * based on provided configuration.
25
+ *
26
+ * @param {{
27
+ * [key: string]: ListRelatedOptions
28
+ * }} listRelatedArgs - The options for the list related properties.
29
+ * @returns {{[key: string]: ListRelated}} - The instances of the list related properties.
30
+ */
31
+ export function useListRelateds(listRelatedArgs: {
32
+ [key: string]: ListRelatedOptions;
33
+ }): {
34
+ [key: string]: ListRelated;
35
+ };
36
+ /**
37
+ * Initializes and returns an instance of a related objects manager. This function sets up reactive states
38
+ * and computations that dynamically adjust as the parent list's state changes. It uses defined rules
39
+ * for object relationships to compute and update related objects in real-time, ensuring that changes in the parent
40
+ * state are reflected in the relationships defined by the rules.
41
+ *
42
+ * @example
43
+ * ```vue
44
+ * <script setup>
45
+ * import { useListInstance, useListRelated } from "@arrai-innovations/reactive-helpers";
46
+ * import { reactive, toRef } from "vue";
47
+ *
48
+ * const props = defineProps({
49
+ * someListFilter: {
50
+ * type: String,
51
+ * default: "",
52
+ * description: "The filter to apply to the list.",
53
+ * },
54
+ * objects: {
55
+ * type: Object,
56
+ * default: () => ({}),
57
+ * description: "The objects to relate to.",
58
+ * },
59
+ * order: {
60
+ * type: Array,
61
+ * default: () => [],
62
+ * description: "The order of the list.",
63
+ * },
64
+ * });
65
+ *
66
+ * const listInstanceProps = reactive({
67
+ * crudArgs: {
68
+ * // whatever arguments are required for your configured list crud function to get the right endpoint
69
+ * },
70
+ * listArgs: {
71
+ * // whatever arguments are required for your configured list function to get the right list
72
+ * someListFilter: toRef(props, "someListFilter"),
73
+ * },
74
+ * pkKey: 'id',
75
+ * retrieveArgs: {
76
+ * // whatever arguments are required for your configured list function to get items back looking as expected
77
+ * },
78
+ * intendToList: false,
79
+ * });
80
+ * listInstanceProps.intendToList = computed(()=> !!props.someListFilter);
81
+ * const listInstance = useListInstance({ props: listInstanceProps });
82
+ * const listRelatedProps = reactive({
83
+ * parentState: listInstance.state, // reactive-to-reactive so no need for toRef
84
+ * relatedObjectsRules: {
85
+ * someRule: {
86
+ * // this can point to a key or an array of keys to relate to
87
+ * pkKey: "dot.separated.key.to.pk.on.an.listInstance.object",
88
+ * objects: toRef(props, "objects"),
89
+ * order: toRef(props, "order"),
90
+ * },
91
+ * },
92
+ * });
93
+ * const listRelated = useListRelated(listRelatedProps);
94
+ * </script>
95
+ * <template>
96
+ * <ul>
97
+ * <!-- reactive list of objects, re-retrieving the list as someListFilter changes. -->
98
+ * <li v-for="obj in listInstance.state.objectsInOrder">
99
+ * {{ obj }}
100
+ * <div>
101
+ * <!-- the related object or objects based on the rule -->
102
+ * {{ listRelated.state.relatedObjects[obj.id].someRule }}
103
+ * </div>
104
+ * </li>
105
+ * </ul>
106
+ * </template>
107
+ * ```
108
+ *
109
+ * @param {ListRelatedOptions} options - The configuration options including the parent state and rules for related
110
+ * objects.
111
+ * @returns {ListRelated} - A reactive instance that manages related objects, providing real-time updates and
112
+ * maintaining the integrity of object relationships as per the specified rules.
113
+ */
114
+ export function useListRelated({ parentState, relatedObjectsRules }: ListRelatedOptions): ListRelated;
115
+ /**
116
+ * The options for the list related composition function.
117
+ */
118
+ export type ListRelatedOptions = {
119
+ /**
120
+ * - The parent state object.
121
+ */
122
+ parentState: ListRelatedParentState;
123
+ /**
124
+ * - The rules for the related objects.
125
+ */
126
+ relatedObjectsRules: import("vue").Ref<ListRelatedRules>;
127
+ };
128
+ /**
129
+ * The properties for the list related composition function.
130
+ */
131
+ export type ListRelatedProperties = {
132
+ /**
133
+ * - The state for the list related property.
134
+ */
135
+ state: ListRelatedState;
136
+ /**
137
+ * - The parent state object.
138
+ */
139
+ parentState: ListRelatedParentState;
140
+ /**
141
+ * - The watches running instance.
142
+ */
143
+ watchesRunning: import("./watchesRunning.js").WatchesRunning;
144
+ /**
145
+ * - The effect scope for the list related property.
146
+ */
147
+ effectScope: import("vue").EffectScope;
148
+ };
149
+ /**
150
+ * An instance of `useListRelated`.
151
+ */
152
+ export type ListRelated = ListRelatedProperties;
153
+ /**
154
+ * The rule for defining relationships for objects in a list.
155
+ */
156
+ export type ListRelatedRule = {
157
+ /**
158
+ * - Specifies the foreign key used to link objects across lists. Planned to be renamed to
159
+ * 'fkKey' to better reflect its usage.
160
+ */
161
+ pkKey: string;
162
+ /**
163
+ * - Specifies the order in which related objects should be sorted, if applicable.
164
+ */
165
+ order?: string[];
166
+ /**
167
+ * - The objects that can be related based on the foreign key.
168
+ */
169
+ objects: import("./listInstance.js").ObjectsByPk;
170
+ };
171
+ /**
172
+ * The rules for defining relationships among objects in a list.
173
+ */
174
+ export type ListRelatedRules = import("vue").UnwrapNestedRefs<{
175
+ [rule: string]: ListRelatedRule;
176
+ }>;
177
+ /**
178
+ * Represents the internal state used by the list related composition function. It manages and computes the relationships
179
+ * between objects based on specified rules, providing real-time updates to related objects as the parent state changes.
180
+ */
181
+ export type ListRelatedRawState = {
182
+ /**
183
+ * - Stores computed references to related objects, allowing for dynamic access based on object pk and specific rules.
184
+ */
185
+ relatedObjects: {
186
+ [pk: string]: {
187
+ [rule: string]: import("vue").ComputedRef<any>;
188
+ };
189
+ };
190
+ /**
191
+ * - Defines the rules for establishing relationships, such as foreign key links and sorting orders.
192
+ */
193
+ relatedObjectsRules: ListRelatedRules;
194
+ /**
195
+ * - Maps each object pk and rule to a tuple consisting of the related object and its respective key, facilitating direct data manipulation.
196
+ */
197
+ objAndKeyForPkAndRule: {
198
+ [pk: string]: {
199
+ [rule: string]: import("vue").ComputedRef<[object, string]>;
200
+ };
201
+ };
202
+ /**
203
+ * - Maintains computed references to the foreign keys for each object pk and rule, crucial for navigating complex data relationships.
204
+ */
205
+ fkForPkAndRule: {
206
+ [pk: string]: {
207
+ [rule: string]: import("vue").ComputedRef<any>;
208
+ };
209
+ };
210
+ /**
211
+ * - Flags whether the watch on parent state objects is currently active, ensuring updates trigger as needed.
212
+ */
213
+ relatedObjectsParentStateObjectsWatchRunning: boolean;
214
+ /**
215
+ * - Indicates if watches on the related objects themselves are active, managing updates efficiently.
216
+ */
217
+ relatedObjectsWatchRunning: boolean;
218
+ /**
219
+ * - Signals whether any computations related to object relationships are currently in progress.
220
+ */
221
+ relatedRunning: boolean;
222
+ /**
223
+ * - General flag that indicates if the list-related logic is processing, used to manage UI feedback or prevent concurrent operations.
224
+ */
225
+ running: import("vue").Ref<boolean>;
226
+ };
227
+ /**
228
+ * The raw state properties for a parent of a list related property.
229
+ */
230
+ export type ListRelatedParentRawState = (import("./listInstance.js").ListInstanceRawState & Partial<import("./listSubscription.js").ListSubscriptionRawState>);
231
+ /**
232
+ * The type for a parentState object.
233
+ */
234
+ export type ListRelatedParentState = import("vue").UnwrapNestedRefs<ListRelatedParentRawState>;
235
+ /**
236
+ * The state for a list related property.
237
+ */
238
+ export type ListRelatedState = import("vue").UnwrapNestedRefs<ListRelatedParentRawState & ListRelatedRawState>;
239
+ //# sourceMappingURL=listRelated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listRelated.d.ts","sourceRoot":"","sources":["../../use/listRelated.js"],"names":[],"mappings":"AA+GA;;;;;;GAMG;AAEH;;;;;;;;GAQG;AAIH;;;;GAIG;AAEH;;;;;;;;GAQG;AACH,iDALW;IACV,CAAO,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAA;CACpC,GACS;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAAC,CASxC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACH,qEALW,kBAAkB,GAEhB,WAAW,CAmLvB;;;;;;;;iBAtSa,sBAAsB;;;;yBACtB,OAAO,KAAK,EAAE,GAAG,CAAC,gBAAgB,CAAC;;;;;;;;;WAOnC,gBAAgB;;;;iBAChB,sBAAsB;;;;oBACtB,OAAO,qBAAqB,EAAE,cAAc;;;;iBAC5C,OAAO,KAAK,EAAE,WAAW;;;;;0BAQ1B,qBAAqB;;;;;;;;;WApGpB,MAAM;;;;YAEN,MAAM,EAAE;;;;aACR,OAAO,mBAAmB,EAAE,WAAW;;;;;+BAMxC,OAAO,KAAK,EAAE,gBAAgB,CAAC;IAC3C,CAAO,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;CACnC,CAAC;;;;;;;;;oBAQS;QACb,CAAO,EAAE,EAAE,MAAM,GAAG;YACpB,CAAW,IAAI,EAAE,MAAM,GAAG,OAAO,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;SAClD,CAAC;KACL;;;;yBACU,gBAAgB;;;;2BAChB;QACb,CAAO,EAAE,EAAE,MAAM,GAAG;YACpB,CAAW,IAAI,EAAE,MAAM,GAAG,OAAO,KAAK,EAAE,WAAW,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;SAC/D,CAAC;KACL;;;;oBACU;QACb,CAAO,EAAE,EAAE,MAAM,GAAG;YACpB,CAAW,IAAI,EAAE,MAAM,GAAG,OAAO,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;SAClD,CAAC;KACL;;;;kDACU,OAAO;;;;gCACP,OAAO;;;;oBACP,OAAO;;;;aACP,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;;;;;wCAM3B,CACZ,OAAa,mBAAmB,EAAE,oBAAoB,GAChD,OAAO,CAAC,OAAO,uBAAuB,EAAE,wBAAwB,CAAC,CACpE;;;;qCAMS,OAAO,KAAK,EAAE,gBAAgB,CAAC,yBAAyB,CAAC;;;;+BAMzD,OAAO,KAAK,EAAE,gBAAgB,CACpC,yBAAyB,GACzB,mBAAmB,CACtB"}
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Represents the raw reactive state used by the list search functionality.
3
+ *
4
+ * @typedef {object} ListSearchRawState
5
+ * @property {import('./listInstance.js').ObjectsByPk} objects - Currently filtered objects based on the search.
6
+ * @property {import('./listInstance.js').ObjectsInOrder} objectsInOrder - The list of objects sorted according to the current search criteria.
7
+ * @property {import('./listInstance.js').ListOrder} order - The current sort order of object pks after search have been applied.
8
+ * @property {object} textSearchRules - Rules defining how text search should be applied on list items. Each rule
9
+ * specifies a key and a function to extract the searchable text.
10
+ * @property {string} textSearchValue - The current value used for searching.
11
+ * @property {object} objectIndexes - Indexes built for quick search across objects based on rules.
12
+ * @property {object} customDocumentOptions - Configuration options for the search document, used by FlexSearch.
13
+ * @property {object} customSearchOptions - Additional search options for FlexSearch.
14
+ * @property {boolean} searched - Flag indicating if a search has been performed.
15
+ * @property {boolean} running - Indicates if the search process is actively running.
16
+ */
17
+ /**
18
+ *
19
+ *
20
+ * @typedef {(
21
+ * import('./listInstance.js').ListInstanceRawState &
22
+ * Partial<import('./listSubscription.js').ListSubscriptionRawState> &
23
+ * Partial<import('./listRelated.js').ListRelatedRawState> &
24
+ * Partial<import('./listCalculated.js').ListCalculatedRawState> &
25
+ * Partial<import('./listFilter.js').ListFilterRawState>
26
+ * )} ListSearchParentRawState
27
+ */
28
+ /**
29
+ * @typedef {import('vue').UnwrapNestedRefs<ListSearchParentRawState>} ListSearchParentState - The parent state for a list search.
30
+ */
31
+ /**
32
+ * @typedef {import('vue').UnwrapNestedRefs<
33
+ * ListSearchRawState &
34
+ * Partial<import('./listFilter.js').ListFilterRawState> &
35
+ * Partial<import('./listCalculated.js').ListCalculatedRawState> &
36
+ * Partial<import('./listRelated.js').ListRelatedRawState> &
37
+ * Partial<import('./listSubscription.js').ListSubscriptionRawState> &
38
+ * import('./listInstance.js').ListInstanceRawState
39
+ * >} ListSearchState - The state for a list search.
40
+ */
41
+ /**
42
+ * @typedef {object} ListSearchRawProps - The raw props for a list search.
43
+ * @property {Array} textSearchRules - Rules for what to search for. Keys are the keys to search for, values are functions that take the object and return The value to search for.
44
+ * @property {string} textSearchValue - The value to search for.
45
+ * @property {object} customDocumentOptions - FlexSearch.Document options.
46
+ * @property {object} customSearchOptions - FlexSearch.Search options.
47
+ * @property {object} [customSearchOptions.limit=1000] - FlexSearch.Search options.
48
+ */
49
+ /**
50
+ * @typedef {object} ListSearchOptions - The options for a list search.
51
+ * @property {ListSearchParentState} parentState - The parent state.
52
+ * @property {import('vue').UnwrapNestedRefs<ListSearchRawProps>} props - The props.
53
+ * @property {number} [throttle=500] - The throttle.
54
+ * @property {boolean} [showAllWhenEmpty=true] - Whether to show all items when the search is empty.
55
+ */
56
+ /**
57
+ * The properties on a list search instance.
58
+ *
59
+ * @typedef {object} ListSearchProperties
60
+ * @property {ListSearchState} state - The state.
61
+ * @property {import('vue').EffectScope} effectScope - The effect scope.
62
+ * @property {import('./search.js').SearchInstance} textSearchIndex - The text search index.
63
+ */
64
+ /**
65
+ * The provided list search instance, containing properties and functions.
66
+ *
67
+ * @typedef {ListSearchProperties} ListSearch
68
+ */
69
+ /**
70
+ * Helper function that initializes multiple list search instances from given configurations. This is typically used
71
+ * when multiple list components require individual search capabilities.
72
+ *
73
+ * @param {{
74
+ * [key: string]: ListSearchOptions
75
+ * }} listSearchArgs - Configuration arguments for each search instance, including state and props.
76
+ * @returns {{
77
+ * [key: string]: ListSearch
78
+ * }} - A collection of initialized list search instances.
79
+ */
80
+ export function useListSearches(listSearchArgs: {
81
+ [key: string]: ListSearchOptions;
82
+ }): {
83
+ [key: string]: ListSearch;
84
+ };
85
+ /**
86
+ * FlexSearch.Document options, specifically for .index. Their documentation isn't very clear on this.
87
+ * Typically, it would be a list of dot-separated keys to index.
88
+ *
89
+ * @typedef {string | string[] | object[]} TextSearchRules
90
+ */
91
+ /**
92
+ * @typedef {object} ListSearchProps
93
+ * @property {TextSearchRules} textSearchRules - Rules for what to search for. Keys are the keys to search for, values are functions that take the object and return The value to search for.
94
+ * @property {string} textSearchValue - The value to search for.
95
+ * @property {object} customDocumentOptions - FlexSearch.Document options.
96
+ * @property {object} customSearchOptions - FlexSearch.Search options.
97
+ * @property {object} [customSearchOptions.limit=1000] - FlexSearch.Search options.
98
+ */
99
+ /**
100
+ * @typedef {object} ListSearchInstanceOptions
101
+ * @property {object} parentState - The list being filtered.
102
+ * @property {ListSearchProps} props - Reactive properties.
103
+ * @property {number} [throttle=500] - Throttle wait time.
104
+ * @property {boolean} [showAllWhenEmpty=true] - Whether to show all items when the search is empty.
105
+ */
106
+ /**
107
+ * Creates a search functionality instance for a list, configuring reactive state and dependencies to
108
+ * dynamically update visible items based on provided search criteria and rules.
109
+ *
110
+ * @example
111
+ * ```vue
112
+ * import { reactive, defineProps, toRef } from 'vue';
113
+ * import { useListInstance, useListSearch } from '@arrai-innovations/reactive-helpers';
114
+ *
115
+ * const props = defineProps({
116
+ * searchQuery: String
117
+ * });
118
+ * const listInstance = useListInstance({ props });
119
+ * const searchProps = reactive({
120
+ * textSearchRules: [{ key: 'name', fn: item => item.name }],
121
+ * textSearchValue: toRef(props, 'searchQuery')
122
+ * });
123
+ * const listSearch = useListSearch({
124
+ * parentState: listInstance.state,
125
+ * props: searchProps
126
+ * });
127
+ * // listSearch.state.objects will contain the filtered items from listInstance.state.objects
128
+ * // listSearch.state.searched will be true if a search has been performed
129
+ * ```
130
+ *
131
+ * @param {ListSearchInstanceOptions} options - Configuration for initializing the list search.
132
+ * @returns {ListSearch} The initialized list search instance with reactive state and utilities for search management.
133
+ */
134
+ export function useListSearch({ parentState, props, throttle, showAllWhenEmpty }: ListSearchInstanceOptions): ListSearch;
135
+ /**
136
+ * Represents the raw reactive state used by the list search functionality.
137
+ */
138
+ export type ListSearchRawState = {
139
+ /**
140
+ * - Currently filtered objects based on the search.
141
+ */
142
+ objects: import("./listInstance.js").ObjectsByPk;
143
+ /**
144
+ * - The list of objects sorted according to the current search criteria.
145
+ */
146
+ objectsInOrder: import("./listInstance.js").ObjectsInOrder;
147
+ /**
148
+ * - The current sort order of object pks after search have been applied.
149
+ */
150
+ order: import("./listInstance.js").ListOrder;
151
+ /**
152
+ * - Rules defining how text search should be applied on list items. Each rule
153
+ * specifies a key and a function to extract the searchable text.
154
+ */
155
+ textSearchRules: object;
156
+ /**
157
+ * - The current value used for searching.
158
+ */
159
+ textSearchValue: string;
160
+ /**
161
+ * - Indexes built for quick search across objects based on rules.
162
+ */
163
+ objectIndexes: object;
164
+ /**
165
+ * - Configuration options for the search document, used by FlexSearch.
166
+ */
167
+ customDocumentOptions: object;
168
+ /**
169
+ * - Additional search options for FlexSearch.
170
+ */
171
+ customSearchOptions: object;
172
+ /**
173
+ * - Flag indicating if a search has been performed.
174
+ */
175
+ searched: boolean;
176
+ /**
177
+ * - Indicates if the search process is actively running.
178
+ */
179
+ running: boolean;
180
+ };
181
+ export type ListSearchParentRawState = (import("./listInstance.js").ListInstanceRawState & Partial<import("./listSubscription.js").ListSubscriptionRawState> & Partial<import("./listRelated.js").ListRelatedRawState> & Partial<import("./listCalculated.js").ListCalculatedRawState> & Partial<import("./listFilter.js").ListFilterRawState>);
182
+ /**
183
+ * - The parent state for a list search.
184
+ */
185
+ export type ListSearchParentState = import("vue").UnwrapNestedRefs<ListSearchParentRawState>;
186
+ /**
187
+ * - The state for a list search.
188
+ */
189
+ export type ListSearchState = import("vue").UnwrapNestedRefs<ListSearchRawState & Partial<import("./listFilter.js").ListFilterRawState> & Partial<import("./listCalculated.js").ListCalculatedRawState> & Partial<import("./listRelated.js").ListRelatedRawState> & Partial<import("./listSubscription.js").ListSubscriptionRawState> & import("./listInstance.js").ListInstanceRawState>;
190
+ /**
191
+ * - The raw props for a list search.
192
+ */
193
+ export type ListSearchRawProps = {
194
+ /**
195
+ * - Rules for what to search for. Keys are the keys to search for, values are functions that take the object and return The value to search for.
196
+ */
197
+ textSearchRules: any[];
198
+ /**
199
+ * - The value to search for.
200
+ */
201
+ textSearchValue: string;
202
+ /**
203
+ * - FlexSearch.Document options.
204
+ */
205
+ customDocumentOptions: object;
206
+ /**
207
+ * - FlexSearch.Search options.
208
+ */
209
+ customSearchOptions: {
210
+ limit?: object;
211
+ };
212
+ };
213
+ /**
214
+ * - The options for a list search.
215
+ */
216
+ export type ListSearchOptions = {
217
+ /**
218
+ * - The parent state.
219
+ */
220
+ parentState: ListSearchParentState;
221
+ /**
222
+ * - The props.
223
+ */
224
+ props: import("vue").UnwrapNestedRefs<ListSearchRawProps>;
225
+ /**
226
+ * - The throttle.
227
+ */
228
+ throttle?: number;
229
+ /**
230
+ * - Whether to show all items when the search is empty.
231
+ */
232
+ showAllWhenEmpty?: boolean;
233
+ };
234
+ /**
235
+ * The properties on a list search instance.
236
+ */
237
+ export type ListSearchProperties = {
238
+ /**
239
+ * - The state.
240
+ */
241
+ state: ListSearchState;
242
+ /**
243
+ * - The effect scope.
244
+ */
245
+ effectScope: import("vue").EffectScope;
246
+ /**
247
+ * - The text search index.
248
+ */
249
+ textSearchIndex: import("./search.js").SearchInstance;
250
+ };
251
+ /**
252
+ * The provided list search instance, containing properties and functions.
253
+ */
254
+ export type ListSearch = ListSearchProperties;
255
+ /**
256
+ * FlexSearch.Document options, specifically for .index. Their documentation isn't very clear on this.
257
+ * Typically, it would be a list of dot-separated keys to index.
258
+ */
259
+ export type TextSearchRules = string | string[] | object[];
260
+ export type ListSearchProps = {
261
+ /**
262
+ * - Rules for what to search for. Keys are the keys to search for, values are functions that take the object and return The value to search for.
263
+ */
264
+ textSearchRules: TextSearchRules;
265
+ /**
266
+ * - The value to search for.
267
+ */
268
+ textSearchValue: string;
269
+ /**
270
+ * - FlexSearch.Document options.
271
+ */
272
+ customDocumentOptions: object;
273
+ /**
274
+ * - FlexSearch.Search options.
275
+ */
276
+ customSearchOptions: {
277
+ limit?: object;
278
+ };
279
+ };
280
+ export type ListSearchInstanceOptions = {
281
+ /**
282
+ * - The list being filtered.
283
+ */
284
+ parentState: object;
285
+ /**
286
+ * - Reactive properties.
287
+ */
288
+ props: ListSearchProps;
289
+ /**
290
+ * - Throttle wait time.
291
+ */
292
+ throttle?: number;
293
+ /**
294
+ * - Whether to show all items when the search is empty.
295
+ */
296
+ showAllWhenEmpty?: boolean;
297
+ };
298
+ //# sourceMappingURL=listSearch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listSearch.d.ts","sourceRoot":"","sources":["../../use/listSearch.js"],"names":[],"mappings":"AA2CA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AAEH;;;;;;GAMG;AAEH;;;;;;;GAOG;AAIH;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,gDAPW;IACV,CAAO,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CACnC,GACS;IACZ,CAAM,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAC3B,CASH;AAED;;;;;GAKG;AAEH;;;;;;;GAOG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,kFAHW,yBAAyB,GACvB,UAAU,CAqStB;;;;;;;;aArba,OAAO,mBAAmB,EAAE,WAAW;;;;oBACvC,OAAO,mBAAmB,EAAE,cAAc;;;;WAC1C,OAAO,mBAAmB,EAAE,SAAS;;;;;qBACrC,MAAM;;;;qBAEN,MAAM;;;;mBACN,MAAM;;;;2BACN,MAAM;;;;yBACN,MAAM;;;;cACN,OAAO;;;;aACP,OAAO;;uCAMR,CACZ,OAAa,mBAAmB,EAAE,oBAAoB,GAChD,OAAO,CAAC,OAAO,uBAAuB,EAAE,wBAAwB,CAAC,GACjE,OAAO,CAAC,OAAO,kBAAkB,EAAE,mBAAmB,CAAC,GACvD,OAAO,CAAC,OAAO,qBAAqB,EAAE,sBAAsB,CAAC,GAC7D,OAAO,CAAC,OAAO,iBAAiB,EAAE,kBAAkB,CAAC,CACxD;;;;oCAIS,OAAO,KAAK,EAAE,gBAAgB,CAAC,wBAAwB,CAAC;;;;8BAIxD,OAAO,KAAK,EAAE,gBAAgB,CACpC,kBAAkB,GAClB,OAAO,CAAC,OAAO,iBAAiB,EAAE,kBAAkB,CAAC,GACrD,OAAO,CAAC,OAAO,qBAAqB,EAAE,sBAAsB,CAAC,GAC7D,OAAO,CAAC,OAAO,kBAAkB,EAAE,mBAAmB,CAAC,GACvD,OAAO,CAAC,OAAO,uBAAuB,EAAE,wBAAwB,CAAC,GACvE,OAAa,mBAAmB,EAAE,oBAAoB,CACnD;;;;;;;;;;;;qBAMU,MAAM;;;;2BACN,MAAM;;;;yBAEjB;QAAwC,KAAK,GAAlC,MAAM;KACnB;;;;;;;;;iBAIa,qBAAqB;;;;WACrB,OAAO,KAAK,EAAE,gBAAgB,CAAC,kBAAkB,CAAC;;;;eAClD,MAAM;;;;uBACN,OAAO;;;;;;;;;WAOP,eAAe;;;;iBACf,OAAO,KAAK,EAAE,WAAW;;;;qBACzB,OAAO,aAAa,EAAE,cAAc;;;;;yBAQrC,oBAAoB;;;;;8BA2BpB,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE;;;;;qBAK3B,eAAe;;;;qBACf,MAAM;;;;2BACN,MAAM;;;;yBAEjB;QAAwC,KAAK,GAAlC,MAAM;KACnB;;;;;;iBAIa,MAAM;;;;WACN,eAAe;;;;eACf,MAAM;;;;uBACN,OAAO"}