@arrai-innovations/reactive-helpers 21.0.0 → 21.0.1

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 CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Coverage for 14.x](https://docs.arrai-dev.com/reactive-helpers/artifacts/main/tests.coverage.svg)](https://docs.arrai-dev.com/reactive-helpers/artifacts/main/coverage_tests/)
5
5
  ![ESLint](https://docs.arrai-dev.com/reactive-helpers/artifacts/main/eslint.svg)
6
6
  ![Prettier](https://docs.arrai-dev.com/reactive-helpers/artifacts/main/prettier.svg)
7
+ ![Audit](https://docs.arrai.dev/reactive-helpers/artifacts/main/npm-audit.svg)
7
8
 
8
9
  Vue.js 3 composition utilities to manage reactive lists, objects and other helpers.
9
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "21.0.0",
3
+ "version": "21.0.1",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -83,7 +83,15 @@
83
83
  * @typedef {(newObjects: import('../use/objectInstance.js').ExistingCrudObject[]) => void} PushObjectsFn
84
84
  */
85
85
  /**
86
- * @typedef {() => void} ClearListFn
86
+ * Options to control which reactive state is reset when clearing the list.
87
+ *
88
+ * @typedef {object} ClearListOptions
89
+ * @property {boolean} [keepPagination] - When true, keep the current pagination information.
90
+ * @property {boolean} [keepColumnTotals] - When true, keep the current column totals.
91
+ * @property {boolean} [keepError] - When true, keep the current error state.
92
+ */
93
+ /**
94
+ * @typedef {(options?: ClearListOptions) => void} ClearListFn
87
95
  */
88
96
  /**
89
97
  * @typedef {(info: PaginateInfo) => void} SetPaginateInfoFn
@@ -99,7 +107,8 @@
99
107
  * @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} addListObject - Adds an object to the list.
100
108
  * @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} updateListObject - Updates an object in the list.
101
109
  * @property {(objectId: string) => void} deleteListObject - Deletes an object from the list by pk.
102
- * @property {() => void} clearList - Clears all objects and errors from the list.
110
+ * @property {(options?: ClearListOptions) => void} clearList - Clears the list objects and optionally keeps pagination, totals,
111
+ * or error state.
103
112
  * @property {() => string} getFakePk - Generates a unique fake pk for use within the list.
104
113
  * @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} list - Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
105
114
  * @property {(args: {pks?: string[]}) => Promise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success.
@@ -343,7 +352,24 @@ export type ListInstanceRawState = ListInstanceRawMyState & Pick<import("./loadi
343
352
  */
344
353
  export type ListInstanceState = import("vue").UnwrapNestedRefs<ListInstanceRawState>;
345
354
  export type PushObjectsFn = (newObjects: import("../use/objectInstance.js").ExistingCrudObject[]) => void;
346
- export type ClearListFn = () => void;
355
+ /**
356
+ * Options to control which reactive state is reset when clearing the list.
357
+ */
358
+ export type ClearListOptions = {
359
+ /**
360
+ * - When true, keep the current pagination information.
361
+ */
362
+ keepPagination?: boolean;
363
+ /**
364
+ * - When true, keep the current column totals.
365
+ */
366
+ keepColumnTotals?: boolean;
367
+ /**
368
+ * - When true, keep the current error state.
369
+ */
370
+ keepError?: boolean;
371
+ };
372
+ export type ClearListFn = (options?: ClearListOptions) => void;
347
373
  export type SetPaginateInfoFn = (info: PaginateInfo) => void;
348
374
  export type SetColumnTotalsFn = (total: ColumnTotals) => void;
349
375
  /**
@@ -367,9 +393,10 @@ export type ListInstanceMyFunctions = {
367
393
  */
368
394
  deleteListObject: (objectId: string) => void;
369
395
  /**
370
- * - Clears all objects and errors from the list.
396
+ * - Clears the list objects and optionally keeps pagination, totals,
397
+ * or error state.
371
398
  */
372
- clearList: () => void;
399
+ clearList: (options?: ClearListOptions) => void;
373
400
  /**
374
401
  * - Generates a unique fake pk for use within the list.
375
402
  */
@@ -129,7 +129,16 @@ export class ListInstanceError extends Error {
129
129
  */
130
130
 
131
131
  /**
132
- * @typedef {() => void} ClearListFn
132
+ * Options to control which reactive state is reset when clearing the list.
133
+ *
134
+ * @typedef {object} ClearListOptions
135
+ * @property {boolean} [keepPagination] - When true, keep the current pagination information.
136
+ * @property {boolean} [keepColumnTotals] - When true, keep the current column totals.
137
+ * @property {boolean} [keepError] - When true, keep the current error state.
138
+ */
139
+
140
+ /**
141
+ * @typedef {(options?: ClearListOptions) => void} ClearListFn
133
142
  */
134
143
 
135
144
  /**
@@ -148,7 +157,8 @@ export class ListInstanceError extends Error {
148
157
  * @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} addListObject - Adds an object to the list.
149
158
  * @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} updateListObject - Updates an object in the list.
150
159
  * @property {(objectId: string) => void} deleteListObject - Deletes an object from the list by pk.
151
- * @property {() => void} clearList - Clears all objects and errors from the list.
160
+ * @property {(options?: ClearListOptions) => void} clearList - Clears the list objects and optionally keeps pagination, totals,
161
+ * or error state.
152
162
  * @property {() => string} getFakePk - Generates a unique fake pk for use within the list.
153
163
  * @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} list - Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
154
164
  * @property {(args: {pks?: string[]}) => Promise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success.
@@ -560,12 +570,19 @@ export function useListInstance({ props, handlers = {} }) {
560
570
  }
561
571
  delete state.objects[pk];
562
572
  },
563
- clearList: () => {
564
- // assignReactiveObject(state.objects, {});
565
- assignReactiveObject(state.paginateInfo, {});
566
- assignReactiveObject(state.columnTotals, {});
573
+ clearList: (options) => {
574
+ const { keepPagination = false, keepColumnTotals = false, keepError = false } = options || {};
575
+
576
+ if (!keepPagination) {
577
+ assignReactiveObject(state.paginateInfo, {});
578
+ }
579
+ if (!keepColumnTotals) {
580
+ assignReactiveObject(state.columnTotals, {});
581
+ }
567
582
  state.objectsMap.clear();
568
- loadingError.clearError();
583
+ if (!keepError) {
584
+ loadingError.clearError();
585
+ }
569
586
  },
570
587
  clearError: loadingError.clearError,
571
588
  getFakePk: () => getFakePk(state.objects, state.pkKey),