@jskit-ai/http-web 0.2.7 → 0.2.9

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 (73) hide show
  1. package/package.json +7 -6
  2. package/src/client/bulkActions.js +2 -0
  3. package/src/client/components/CrudAddEditScreen.vue +13 -18
  4. package/src/client/components/CrudDeleteAction.vue +1 -1
  5. package/src/client/components/CrudListBulkActionSurface.vue +13 -13
  6. package/src/client/components/CrudListDateFilterControl.vue +2 -2
  7. package/src/client/components/CrudListFilterControls.vue +4 -4
  8. package/src/client/components/CrudListFilterSurface.vue +8 -8
  9. package/src/client/components/CrudListRecordActionMenu.vue +9 -19
  10. package/src/client/components/CrudListScreen.vue +21 -39
  11. package/src/client/components/CrudViewScreen.vue +4 -4
  12. package/src/client/components/SelectField.vue +1 -0
  13. package/src/client/composables/crud/crudHttpClientSupport.js +10 -10
  14. package/src/client/composables/crud/crudJsonApiTransportSupport.js +1 -0
  15. package/src/client/composables/crud/crudLookupFieldRuntime.js +3 -3
  16. package/src/client/composables/crud/crudSchemaFormHelpers.js +3 -3
  17. package/src/client/composables/internal/crudListFilterLookupSupport.js +10 -8
  18. package/src/client/composables/internal/crudListParentTitleSupport.js +2 -2
  19. package/src/client/composables/internal/useOperationScope.js +7 -5
  20. package/src/client/composables/records/useAddEdit.js +12 -11
  21. package/src/client/composables/records/useCrudAddEdit.js +27 -40
  22. package/src/client/composables/records/useCrudList.js +4 -11
  23. package/src/client/composables/records/useCrudView.js +4 -10
  24. package/src/client/composables/records/useList.js +18 -11
  25. package/src/client/composables/records/useView.js +18 -11
  26. package/src/client/composables/runtime/addEditUiRuntime.js +10 -17
  27. package/src/client/composables/runtime/listUiRuntime.js +17 -20
  28. package/src/client/composables/runtime/modelStateHelpers.js +18 -8
  29. package/src/client/composables/runtime/operationUiHelpers.js +20 -20
  30. package/src/client/composables/runtime/operationValidationHelpers.js +12 -7
  31. package/src/client/composables/runtime/useAddEditCore.js +39 -36
  32. package/src/client/composables/runtime/useCommandCore.js +33 -32
  33. package/src/client/composables/runtime/useEndpointResource.js +10 -14
  34. package/src/client/composables/runtime/useFieldErrorBag.js +3 -2
  35. package/src/client/composables/runtime/useListCore.js +7 -11
  36. package/src/client/composables/runtime/useUiFeedback.js +3 -2
  37. package/src/client/composables/runtime/useViewCore.js +10 -20
  38. package/src/client/composables/runtime/viewUiRuntime.js +7 -6
  39. package/src/client/composables/support/listQueryParamSupport.js +6 -10
  40. package/src/client/composables/support/refValueHelpers.js +2 -6
  41. package/src/client/composables/support/requestQueryRuntimeSupport.js +2 -2
  42. package/src/client/composables/support/routeTemplateHelpers.js +13 -12
  43. package/src/client/composables/support/scopeHelpers.js +5 -4
  44. package/src/client/composables/useAccess.js +8 -5
  45. package/src/client/composables/useCommand.js +7 -6
  46. package/src/client/composables/useCrudAddEditScreen.js +13 -12
  47. package/src/client/composables/useCrudDeleteAction.js +13 -25
  48. package/src/client/composables/useCrudListBulkActions.js +18 -14
  49. package/src/client/composables/useCrudListFilterLookups.js +8 -4
  50. package/src/client/composables/useCrudListFilters.js +13 -6
  51. package/src/client/composables/useCrudListParentTitle.js +10 -9
  52. package/src/client/composables/useCrudListRowActions.js +15 -11
  53. package/src/client/composables/useCrudListScreen.js +17 -16
  54. package/src/client/composables/useCrudViewScreen.js +8 -7
  55. package/src/client/composables/usePagedCollection.js +9 -18
  56. package/src/client/composables/useRealtimeQueryInvalidation.js +15 -13
  57. package/src/client/composables/useScopeRuntime.js +3 -2
  58. package/src/client/lib/httpClient.js +12 -10
  59. package/src/client/rowActions.js +2 -0
  60. package/src/client/support/crudListActionSupport.js +16 -8
  61. package/src/client/types.js +596 -0
  62. package/test/addEditUiRuntime.test.js +8 -8
  63. package/test/crudScreenComponents.test.js +4 -2
  64. package/test/exportsContract.test.js +1 -0
  65. package/test/listUiRuntime.test.js +5 -5
  66. package/test/requestTransportOptions.test.js +15 -15
  67. package/test/routeTemplateHelpers.test.js +5 -5
  68. package/test/translation.test.js +3 -0
  69. package/test/useAddEditCore.test.js +4 -0
  70. package/test/useCrudDeleteAction.test.js +4 -4
  71. package/test/useCrudListParentTitle.test.js +6 -6
  72. package/test/viewCoreLoading.test.js +0 -19
  73. package/test/viewUiRuntime.test.js +5 -5
@@ -4,16 +4,17 @@ import {
4
4
  normalizeRouteParamName
5
5
  } from "../support/routeTemplateHelpers.js";
6
6
 
7
+ /** @param {import("../../types.js").ViewUiRuntimeOptions} options */
7
8
  function createViewUiRuntime({
8
9
  recordIdParam = "recordId",
9
- routeParams = null,
10
- routeParamNames = null,
10
+ routeParams,
11
+ routeParamNames,
11
12
  routePath = "",
12
- routeRecordId = null,
13
+ routeRecordId,
13
14
  apiUrlTemplate = "",
14
15
  listUrlTemplate = "",
15
16
  editUrlTemplate = ""
16
- } = {}) {
17
+ }) {
17
18
  const normalizedRecordIdParam = normalizeRouteParamName(recordIdParam, {
18
19
  context: "useView recordIdParam"
19
20
  });
@@ -36,13 +37,13 @@ function createViewUiRuntime({
36
37
  const listUrl = computed(() => resolveTemplatePath(normalizedListUrlTemplate));
37
38
  const editUrl = computed(() => resolveTemplatePath(normalizedEditUrlTemplate));
38
39
 
39
- return Object.freeze({
40
+ return {
40
41
  recordId,
41
42
  apiSuffix,
42
43
  listUrl,
43
44
  editUrl,
44
45
  resolveParams: resolveTemplatePath
45
- });
46
+ };
46
47
  }
47
48
 
48
49
  export { createViewUiRuntime };
@@ -197,9 +197,7 @@ function resolveQueryParamDescriptors(
197
197
  rawKey,
198
198
  rawValue,
199
199
  key,
200
- resolveRouteValue: typeof resolvers[key] === "function"
201
- ? resolvers[key]
202
- : null
200
+ resolveRouteValue: resolvers[key] ?? null
203
201
  });
204
202
  }
205
203
 
@@ -334,24 +332,22 @@ function parseRouteQueryItemValue(value, itemType = QUERY_PARAM_BINDING_TYPE_TEX
334
332
  }
335
333
 
336
334
  function parseRouteBindingValue(binding, routeQueryValue, context = {}) {
337
- if (typeof binding?.resolveRouteValue === "function") {
335
+ if (binding.resolveRouteValue) {
338
336
  return binding.resolveRouteValue(routeQueryValue, context);
339
337
  }
340
338
 
341
- const valueType = normalizeText(binding?.valueType).toLowerCase();
339
+ const valueType = normalizeText(binding.valueType).toLowerCase();
342
340
  if (valueType === QUERY_PARAM_BINDING_TYPE_BOOLEAN) {
343
341
  return parseRouteBooleanValue(routeQueryValue, false);
344
342
  }
345
343
  if (valueType === QUERY_PARAM_BINDING_TYPE_NUMBER) {
346
- const fallback = typeof binding?.get === "function" ? binding.get() : null;
347
- return parseRouteNumberValue(routeQueryValue, fallback);
344
+ return parseRouteNumberValue(routeQueryValue, binding.get());
348
345
  }
349
346
  if (valueType === QUERY_PARAM_BINDING_TYPE_DATE) {
350
- const fallback = typeof binding?.get === "function" ? binding.get() : null;
351
- return parseRouteDateValue(routeQueryValue, fallback);
347
+ return parseRouteDateValue(routeQueryValue, binding.get());
352
348
  }
353
349
  if (valueType === QUERY_PARAM_BINDING_TYPE_ARRAY) {
354
- const itemType = normalizeText(binding?.arrayItemType).toLowerCase() || QUERY_PARAM_BINDING_TYPE_TEXT;
350
+ const itemType = normalizeText(binding.arrayItemType).toLowerCase() || QUERY_PARAM_BINDING_TYPE_TEXT;
355
351
  return normalizeRouteQueryValues(routeQueryValue)
356
352
  .map((value) => parseRouteQueryItemValue(value, itemType, null))
357
353
  .filter((value) => value != null && !(typeof value === "string" && !value));
@@ -1,15 +1,11 @@
1
- import { unref } from "vue";
1
+ import { toValue, unref } from "vue";
2
2
 
3
3
  function resolveEnabledRef(value) {
4
4
  if (value === undefined) {
5
5
  return true;
6
6
  }
7
7
 
8
- if (typeof value === "function") {
9
- return Boolean(value());
10
- }
11
-
12
- return Boolean(unref(value));
8
+ return Boolean(toValue(value));
13
9
  }
14
10
 
15
11
  function resolveTextRef(value) {
@@ -123,7 +123,7 @@ function createRequestQueryRuntime({
123
123
  return query;
124
124
  });
125
125
 
126
- return Object.freeze({
126
+ return {
127
127
  requestQueryParamDescriptors,
128
128
  activeRequestQueryParamEntries,
129
129
  activeRequestQueryParamsToken,
@@ -132,7 +132,7 @@ function createRequestQueryRuntime({
132
132
  queryKeyParts,
133
133
  queryKey,
134
134
  requestQuery
135
- });
135
+ };
136
136
  }
137
137
 
138
138
  export {
@@ -1,4 +1,4 @@
1
- import { unref } from "vue";
1
+ import { toValue } from "vue";
2
2
  import { asPlainObject } from "./scopeHelpers.js";
3
3
 
4
4
  const ROUTE_PARAM_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/;
@@ -28,16 +28,12 @@ function toRouteParamValue(value) {
28
28
  return String(value).trim();
29
29
  }
30
30
 
31
- function resolveRouteSourceValue(source = null) {
32
- if (typeof source === "function") {
33
- return source();
34
- }
35
-
36
- return unref(source);
31
+ function selectRecordId(record) {
32
+ return record.id;
37
33
  }
38
34
 
39
35
  function resolveRouteParamsSource(source = null) {
40
- return asPlainObject(resolveRouteSourceValue(source));
36
+ return asPlainObject(toValue(source));
41
37
  }
42
38
 
43
39
  function normalizeRouteParamNameList(value = []) {
@@ -48,7 +44,7 @@ function normalizeRouteParamNameList(value = []) {
48
44
  }
49
45
 
50
46
  function resolveRouteParamNamesSource(source = []) {
51
- return normalizeRouteParamNameList(resolveRouteSourceValue(source));
47
+ return normalizeRouteParamNameList(toValue(source));
52
48
  }
53
49
 
54
50
  function normalizeRoutePathname(value = "") {
@@ -62,7 +58,7 @@ function normalizeRoutePathname(value = "") {
62
58
  }
63
59
 
64
60
  function resolveRoutePathnameSource(source = "") {
65
- return normalizeRoutePathname(resolveRouteSourceValue(source));
61
+ return normalizeRoutePathname(toValue(source));
66
62
  }
67
63
 
68
64
  function segmentMatchesParamValue(segment = "", paramValue = "") {
@@ -231,7 +227,7 @@ function createRouteTemplateResolver({
231
227
  fillRecordId = true
232
228
  } = {}) {
233
229
  function resolveCurrentRecordId(currentRouteParams = resolveRouteParamsSource(routeParams)) {
234
- const explicitRecordId = toRouteParamValue(resolveRouteSourceValue(routeRecordId));
230
+ const explicitRecordId = toRouteParamValue(toValue(routeRecordId));
235
231
  if (explicitRecordId) {
236
232
  return explicitRecordId;
237
233
  }
@@ -270,8 +266,12 @@ function createRouteTemplateResolver({
270
266
  });
271
267
  }
272
268
 
269
+ function resolveRecordId() {
270
+ return resolveCurrentRecordId();
271
+ }
272
+
273
273
  return Object.freeze({
274
- resolveRecordId: () => resolveCurrentRecordId(),
274
+ resolveRecordId,
275
275
  resolveTemplatePath
276
276
  });
277
277
  }
@@ -330,6 +330,7 @@ function resolveRouteParamNamesInOrder(route = null) {
330
330
  export {
331
331
  normalizeRouteParamName,
332
332
  toRouteParamValue,
333
+ selectRecordId,
333
334
  resolveRouteParamsSource,
334
335
  resolveRouteParamNamesSource,
335
336
  resolveRoutePathnameSource,
@@ -20,6 +20,10 @@ function asPlainObject(value) {
20
20
  return value;
21
21
  }
22
22
 
23
+ function emptyRecord() {
24
+ return {};
25
+ }
26
+
23
27
  function normalizePermissions(value) {
24
28
  if (Array.isArray(value)) {
25
29
  return value.map((entry) => String(entry || "").trim()).filter(Boolean);
@@ -108,10 +112,6 @@ function resolveQueryKey(
108
112
  queryKeyFactory,
109
113
  { surfaceId = "", scopeParamValue = "", ownershipFilter = ROUTE_VISIBILITY_WORKSPACE } = {}
110
114
  ) {
111
- if (typeof queryKeyFactory !== "function") {
112
- throw new TypeError("queryKeyFactory is required.");
113
- }
114
-
115
115
  if (isScopedOwnershipFilter(ownershipFilter)) {
116
116
  return queryKeyFactory(surfaceId, scopeParamValue, ownershipFilter);
117
117
  }
@@ -131,6 +131,7 @@ function resolveResourceMessages(resource, defaults = {}) {
131
131
 
132
132
  export {
133
133
  asPlainObject,
134
+ emptyRecord,
134
135
  normalizePermissions,
135
136
  resolvePermissionAccess,
136
137
  normalizeAccessMode,
@@ -22,9 +22,12 @@ function asPermissionList(value) {
22
22
  return [value];
23
23
  }
24
24
 
25
- // Permissions come only from the web placement context, which the shell fills
26
- // from its bootstrap. Until that context carries a `permissions` key, access is
27
- // awaiting placement permissions and reports them as unavailable.
25
+ /**
26
+ * Permissions come only from the web placement context, which the shell fills
27
+ * from its bootstrap. Until that context carries a `permissions` key, access is
28
+ * awaiting placement permissions and reports them as unavailable.
29
+ * @param {import("../types.js").AccessOptions} [options]
30
+ */
28
31
  function useAccess({
29
32
  enabled = true,
30
33
  access = "always",
@@ -92,7 +95,7 @@ function useAccess({
92
95
  return true;
93
96
  }
94
97
 
95
- return Object.freeze({
98
+ return {
96
99
  accessMode: normalizedAccessMode,
97
100
  accessRequired,
98
101
  permissions,
@@ -101,7 +104,7 @@ function useAccess({
101
104
  can,
102
105
  canAny,
103
106
  canAll
104
- });
107
+ };
105
108
  }
106
109
 
107
110
  export { useAccess };
@@ -11,6 +11,7 @@ import {
11
11
  } from "./runtime/operationUiHelpers.js";
12
12
  import { resolveCrudHttpClient } from "./crud/crudHttpClientSupport.js";
13
13
 
14
+ /** @param {import("../types.js").CommandOptions} options */
14
15
  function useCommand({
15
16
  ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
16
17
  surfaceId = "",
@@ -18,12 +19,12 @@ function useCommand({
18
19
  apiSuffix = "",
19
20
  runPermissions = [],
20
21
  writeMethod = "POST",
21
- client = null,
22
+ client,
22
23
  resource: commandResource = null,
23
- transport = null,
24
+ transport,
24
25
  placementSource = "http-web.command",
25
26
  fallbackRunError = "jskit.http.feedback.actionFailed",
26
- fieldErrorKeys = [],
27
+ fieldErrorKeys,
27
28
  clearOnRouteChange = true,
28
29
  model,
29
30
  input,
@@ -34,8 +35,8 @@ function useCommand({
34
35
  onRunError,
35
36
  suppressSuccessMessage = false,
36
37
  messages = {},
37
- realtime = null
38
- } = {}) {
38
+ realtime
39
+ }) {
39
40
  const operationScope = useOperationScope({
40
41
  ownershipFilter,
41
42
  surfaceId,
@@ -92,7 +93,7 @@ function useCommand({
92
93
  enabled: clearOnRouteChange,
93
94
  route: routeContext.route,
94
95
  feedback,
95
- fieldBag
96
+ onClear: fieldBag.clear
96
97
  });
97
98
 
98
99
  const loadError = operationScope.loadError();
@@ -11,6 +11,7 @@ function normalizeProvidedScreen(screen = null) {
11
11
  : null;
12
12
  }
13
13
 
14
+ /** @param {import("../types.js").CrudAddEditScreenOptions} options */
14
15
  function useCrudAddEditScreen({
15
16
  screen = null,
16
17
  mode = "new",
@@ -18,18 +19,18 @@ function useCrudAddEditScreen({
18
19
  subtitle = "",
19
20
  saveLabel = "",
20
21
  cancelTo = "",
21
- resource = null,
22
+ resource,
22
23
  operationName = "",
23
- formFields = [],
24
- addEditOptions = {},
25
- saveSuccess = {},
26
- fieldBinding = null,
27
- createModel = null,
28
- buildPayload = null,
29
- mapPayloadToModel = null,
30
- input = null,
24
+ formFields,
25
+ addEditOptions,
26
+ saveSuccess,
27
+ fieldBinding,
28
+ createModel,
29
+ buildPayload,
30
+ mapPayloadToModel,
31
+ input,
31
32
  preserveCancelQuery = false
32
- } = {}) {
33
+ }) {
33
34
  const providedScreen = normalizeProvidedScreen(screen);
34
35
  if (providedScreen) {
35
36
  return providedScreen;
@@ -74,7 +75,7 @@ function useCrudAddEditScreen({
74
75
  return resolvedTarget;
75
76
  }
76
77
 
77
- return Object.freeze({
78
+ return {
78
79
  mode: resolvedMode,
79
80
  title: resolvedTitle,
80
81
  subtitle: resolvedSubtitle,
@@ -85,7 +86,7 @@ function useCrudAddEditScreen({
85
86
  formState: formRuntime.form,
86
87
  resolveFieldErrors: formRuntime.resolveFieldErrors,
87
88
  resolveCancelTo
88
- });
89
+ };
89
90
  }
90
91
 
91
92
  export { useCrudAddEditScreen };
@@ -20,33 +20,26 @@ function requireCrudDeleteOperation(resource = null) {
20
20
  return operation;
21
21
  }
22
22
 
23
- function requireCrudViewScreen(screen = null) {
24
- if (!screen || typeof screen !== "object" || typeof screen?.view?.resolveParams !== "function") {
25
- throw new TypeError("useCrudDeleteAction requires a useCrudViewScreen() result.");
26
- }
27
- return screen;
28
- }
29
-
30
23
  function resolveDeleteApiSuffix(screen, apiUrlTemplate = "") {
31
24
  const template = normalizeText(unref(apiUrlTemplate));
32
25
  return template ? normalizeText(screen.view.resolveParams(template)) : "";
33
26
  }
34
27
 
35
28
  function resolveListLocation(screen) {
36
- return unref(screen?.listLocation) || null;
29
+ return unref(screen.listLocation) || null;
37
30
  }
38
31
 
32
+ /** @param {import("../types.js").CrudDeleteActionOptions} options */
39
33
  function useCrudDeleteAction({
40
- screen = null,
34
+ screen,
41
35
  resource = null,
42
36
  resourceNamespace = "",
43
37
  apiUrlTemplate = "",
44
38
  access = "auto",
45
- client = null,
46
- router: routerOverride = null,
39
+ client,
40
+ router = useRouter(),
47
41
  fallbackDeleteError = t("jskit.http.crud.delete.failed")
48
- } = {}) {
49
- const resolvedScreen = requireCrudViewScreen(screen);
42
+ }) {
50
43
  const deleteOperation = requireCrudDeleteOperation(resource);
51
44
  const namespace = normalizeText(resourceNamespace, {
52
45
  fallback: resource?.namespace
@@ -55,17 +48,12 @@ function useCrudDeleteAction({
55
48
  throw new TypeError("useCrudDeleteAction requires resourceNamespace or resource.namespace.");
56
49
  }
57
50
 
58
- const activeRouter = routerOverride || useRouter();
59
- if (!activeRouter || typeof activeRouter.push !== "function") {
60
- throw new TypeError("useCrudDeleteAction requires an installed Vue Router.");
61
- }
62
-
63
51
  const isOpen = ref(false);
64
52
  const error = ref("");
65
- const deleteApiSuffix = computed(() => resolveDeleteApiSuffix(resolvedScreen, apiUrlTemplate));
53
+ const deleteApiSuffix = computed(() => resolveDeleteApiSuffix(screen, apiUrlTemplate));
66
54
 
67
- async function handleDeleteSuccess(_response, context = {}) {
68
- const listLocation = resolveListLocation(resolvedScreen);
55
+ async function handleDeleteSuccess(_response, context) {
56
+ const listLocation = resolveListLocation(screen);
69
57
  if (!listLocation) {
70
58
  throw createTextError("jskit.http.crud.delete.listRouteUnavailable");
71
59
  }
@@ -73,9 +61,9 @@ function useCrudDeleteAction({
73
61
  isOpen.value = false;
74
62
  // Leave the deleted record's view before invalidating: while its view query is
75
63
  // still observed, invalidation would refetch it and report "Record not found.".
76
- await activeRouter.push(listLocation);
64
+ await router.push(listLocation);
77
65
  await nextTick();
78
- await context?.queryClient?.invalidateQueries?.({
66
+ await context.queryClient.invalidateQueries({
79
67
  queryKey: ["crud", namespace]
80
68
  });
81
69
  }
@@ -105,11 +93,11 @@ function useCrudDeleteAction({
105
93
 
106
94
  const isDeleting = computed(() => Boolean(command.isRunning));
107
95
  const canDelete = computed(() => {
108
- const view = resolvedScreen.view;
96
+ const view = screen.view;
109
97
  return Boolean(
110
98
  command.canRun &&
111
99
  deleteApiSuffix.value &&
112
- resolveListLocation(resolvedScreen) &&
100
+ resolveListLocation(screen) &&
113
101
  unref(view.recordId) &&
114
102
  unref(view.record) &&
115
103
  !unref(view.isLoading) &&
@@ -1,14 +1,21 @@
1
1
  import { computed, ref } from "vue";
2
2
  import { defineCrudListBulkActions } from "../bulkActions.js";
3
+ import { emptyRecord } from "./support/scopeHelpers.js";
3
4
  import {
4
5
  normalizeListActionKey,
5
6
  resolveListActionBaseContext,
6
- resolveListRecordId
7
+ resolveListActionFlag,
8
+ resolveListRecordId,
9
+ selectListRecordId
7
10
  } from "../support/crudListActionSupport.js";
8
11
 
12
+ /**
13
+ * @param {import("../types.js").CrudListBulkActionDefinition[]} [actions]
14
+ * @param {import("../types.js").CrudListActionOptions} [options]
15
+ */
9
16
  function useCrudListBulkActions(actions = [], {
10
- resolveRecordId = null,
11
- resolveContext = null
17
+ resolveRecordId = selectListRecordId,
18
+ resolveContext = emptyRecord
12
19
  } = {}) {
13
20
  const normalizedActions = defineCrudListBulkActions(actions);
14
21
  const selectedIds = ref([]);
@@ -81,19 +88,16 @@ function useCrudListBulkActions(actions = [], {
81
88
  if (!action || !hasSelection.value || executingActionKey.value) {
82
89
  return true;
83
90
  }
84
- if (typeof action.disabled === "function") {
85
- return Boolean(action.disabled({
86
- selectedIds: selectedIds.value.slice(),
87
- selectedRecords: Array.from(selectedRecordMap.values()),
88
- action
89
- }));
90
- }
91
- return Boolean(action.disabled);
91
+ return Boolean(resolveListActionFlag(action.disabled, () => ({
92
+ selectedIds: selectedIds.value.slice(),
93
+ selectedRecords: Array.from(selectedRecordMap.values()),
94
+ action
95
+ })));
92
96
  }
93
97
 
94
98
  async function execute(actionOrKey = "") {
95
99
  const action = findAction(actionOrKey);
96
- if (!action || typeof action.run !== "function" || isActionDisabled(action)) {
100
+ if (!action || !action.run || isActionDisabled(action)) {
97
101
  return null;
98
102
  }
99
103
 
@@ -112,7 +116,7 @@ function useCrudListBulkActions(actions = [], {
112
116
  }
113
117
  }
114
118
 
115
- return Object.freeze({
119
+ return {
116
120
  actions: normalizedActions,
117
121
  selectedIds,
118
122
  selectedCount,
@@ -129,7 +133,7 @@ function useCrudListBulkActions(actions = [], {
129
133
  isActionDisabled,
130
134
  isActionExecuting,
131
135
  execute
132
- });
136
+ };
133
137
  }
134
138
 
135
139
  export { useCrudListBulkActions };
@@ -20,6 +20,10 @@ import { useJskitText } from "../i18n.js";
20
20
 
21
21
  const { t, text } = useJskitText();
22
22
 
23
+ /**
24
+ * @param {Record<string, object>} [definitions]
25
+ * @param {import("../types.js").CrudListFilterLookupsOptions} [options]
26
+ */
23
27
  function useCrudListFilterLookups(
24
28
  definitions = {},
25
29
  {
@@ -80,7 +84,7 @@ function useCrudListFilterLookups(
80
84
  });
81
85
 
82
86
  const cachedOptions = ref(new Map());
83
- const selectedValues = computed(() => resolveLookupSelectedValues(filter, values?.[filter.key]));
87
+ const selectedValues = computed(() => resolveLookupSelectedValues(filter, values[filter.key]));
84
88
  const currentOptions = computed(() => createLookupOptionsFromItems(
85
89
  Array.isArray(runtime.items) ? runtime.items : [],
86
90
  filter,
@@ -122,8 +126,8 @@ function useCrudListFilterLookups(
122
126
  return lookups[normalizeText(filterKey)] || null;
123
127
  }
124
128
 
125
- return Object.freeze({
126
- lookups: Object.freeze(lookups),
129
+ return {
130
+ lookups,
127
131
  resolveLookup,
128
132
  resolveLookupItems(filterKey = "") {
129
133
  return resolveLookup(filterKey)?.options || [];
@@ -141,7 +145,7 @@ function useCrudListFilterLookups(
141
145
  return resolveLookup(filterKey)?.resolveLabel(value, fallback)
142
146
  || resolveLookupOptionLabel([], new Map(), value, fallback);
143
147
  }
144
- });
148
+ };
145
149
  }
146
150
 
147
151
  export { useCrudListFilterLookups };
@@ -39,6 +39,7 @@ function normalizeFunctionMap(value = {}) {
39
39
  return Object.freeze(normalized);
40
40
  }
41
41
 
42
+ // readable-check: allow method-probe - input validation: a preset carries fixed values, a resolveValues function, or both
42
43
  function normalizePresetEntries(presets = []) {
43
44
  const source = Array.isArray(presets) ? presets : [];
44
45
  const normalized = [];
@@ -75,7 +76,7 @@ function normalizePresetEntries(presets = []) {
75
76
  }
76
77
 
77
78
  function resolvePresetValues(preset = {}, { values = {}, filters = {} } = {}) {
78
- const rawValues = typeof preset.resolveValues === "function"
79
+ const rawValues = preset.resolveValues
79
80
  ? preset.resolveValues({
80
81
  values,
81
82
  filters,
@@ -120,7 +121,7 @@ function applyPresetFilterValue(values, filter = {}, rawValue) {
120
121
  assignFilterValue(values, filter, rawValue);
121
122
  }
122
123
 
123
- function createQueryParams(values, filterEntries = []) {
124
+ function createQueryParams(values, filterEntries) {
124
125
  const queryParams = {};
125
126
 
126
127
  for (const filter of filterEntries) {
@@ -153,7 +154,7 @@ function resolveFilterRouteValue(filter, routeValue, { initial = false } = {}) {
153
154
  : parsedValue;
154
155
  }
155
156
 
156
- function createRouteQueryValueResolvers(filterEntries = []) {
157
+ function createRouteQueryValueResolvers(filterEntries) {
157
158
  return Object.freeze(Object.fromEntries(
158
159
  filterEntries.map((filter) => [
159
160
  filter.queryKey,
@@ -164,7 +165,7 @@ function createRouteQueryValueResolvers(filterEntries = []) {
164
165
 
165
166
  function resolveAtomicValueLabel(filter = {}, value = "", labelResolvers = {}) {
166
167
  const customResolver = labelResolvers[filter.key];
167
- if (typeof customResolver === "function") {
168
+ if (customResolver) {
168
169
  const customLabel = normalizeText(customResolver(value, filter));
169
170
  if (customLabel) {
170
171
  return customLabel;
@@ -186,6 +187,10 @@ function formatDefaultChipLabel(filter = {}, chipValue, labelResolvers = {}) {
186
187
  });
187
188
  }
188
189
 
190
+ /**
191
+ * @param {Record<string, object>} [definitions]
192
+ * @param {import("../types.js").CrudListFiltersOptions} [options]
193
+ */
189
194
  function useCrudListFilters(definitions = {}, { labelResolvers = {}, chipLabels = {}, presets = [] } = {}) {
190
195
  const filters = defineCrudListFilters(definitions);
191
196
  const filterEntries = Object.values(filters);
@@ -217,7 +222,9 @@ function useCrudListFilters(definitions = {}, { labelResolvers = {}, chipLabels
217
222
  id: isCrudListFilterMultiValue(filter) ? `${filter.key}:${chipValue}` : filter.key,
218
223
  filterKey: filter.key,
219
224
  ...(isCrudListFilterMultiValue(filter) ? { value: chipValue } : {}),
225
+ // readable-check: allow optional-call - optional operation: only a filter named in chipLabels has this chip label
220
226
  label: normalizeText(customChipLabel?.(chipValue, filter, values))
227
+ // readable-check: allow optional-call - optional operation: a filter definition may leave chipLabel out
221
228
  || normalizeText(filter.chipLabel?.(chipValue, filter, values))
222
229
  || formatDefaultChipLabel(filter, chipValue, normalizedLabelResolvers)
223
230
  });
@@ -322,7 +329,7 @@ function useCrudListFilters(definitions = {}, { labelResolvers = {}, chipLabels
322
329
  return matchedFilter;
323
330
  }
324
331
 
325
- return Object.freeze({
332
+ return {
326
333
  filters,
327
334
  values,
328
335
  queryParams,
@@ -337,7 +344,7 @@ function useCrudListFilters(definitions = {}, { labelResolvers = {}, chipLabels
337
344
  toggle,
338
345
  applyPreset,
339
346
  matchesPreset
340
- });
347
+ };
341
348
  }
342
349
 
343
350
  export { useCrudListFilters };