@jskit-ai/users-web 0.1.173 → 0.1.175

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 (113) hide show
  1. package/package.json +18 -149
  2. package/src/client/composables/account-settings/accountSettingsAvatarUploadRuntime.js +2 -2
  3. package/src/client/composables/useAccountSettingsRuntime.js +3 -3
  4. package/src/client/index.js +0 -11
  5. package/src/client/providers/UsersWebClientProvider.js +0 -2
  6. package/test/exportsContract.test.js +3 -29
  7. package/test/settingsPlacementContract.test.js +10 -0
  8. package/fixtures/crud-list-date-filters/App.vue +0 -107
  9. package/fixtures/crud-list-date-filters/index.html +0 -12
  10. package/fixtures/crud-list-date-filters/main.js +0 -24
  11. package/fixtures/crud-list-date-filters/vite.config.mjs +0 -18
  12. package/src/client/bulkActions.js +0 -47
  13. package/src/client/components/CrudAddEditScreen.vue +0 -186
  14. package/src/client/components/CrudDeleteAction.vue +0 -93
  15. package/src/client/components/CrudListBulkActionSurface.vue +0 -126
  16. package/src/client/components/CrudListDateFilterControl.vue +0 -188
  17. package/src/client/components/CrudListFilterSurface.vue +0 -388
  18. package/src/client/components/CrudListRecordActionMenu.vue +0 -120
  19. package/src/client/components/CrudListScreen.vue +0 -501
  20. package/src/client/components/CrudViewScreen.vue +0 -197
  21. package/src/client/composables/crud/crudBindingSupport.js +0 -75
  22. package/src/client/composables/crud/crudHttpClientSupport.js +0 -57
  23. package/src/client/composables/crud/crudJsonApiTransportSupport.js +0 -145
  24. package/src/client/composables/crud/crudLookupFieldLabelSupport.js +0 -151
  25. package/src/client/composables/crud/crudLookupFieldRuntime.js +0 -251
  26. package/src/client/composables/crud/crudSchemaFormHelpers.js +0 -464
  27. package/src/client/composables/internal/crudListFilterLookupSupport.js +0 -161
  28. package/src/client/composables/internal/crudListParentTitleSupport.js +0 -171
  29. package/src/client/composables/internal/useOperationScope.js +0 -144
  30. package/src/client/composables/records/useAddEdit.js +0 -224
  31. package/src/client/composables/records/useCrudAddEdit.js +0 -227
  32. package/src/client/composables/records/useCrudList.js +0 -101
  33. package/src/client/composables/records/useCrudView.js +0 -47
  34. package/src/client/composables/records/useList.js +0 -500
  35. package/src/client/composables/records/useView.js +0 -164
  36. package/src/client/composables/runtime/addEditUiRuntime.js +0 -130
  37. package/src/client/composables/runtime/listUiRuntime.js +0 -123
  38. package/src/client/composables/runtime/modelStateHelpers.js +0 -90
  39. package/src/client/composables/runtime/operationAdapters.js +0 -34
  40. package/src/client/composables/runtime/operationUiHelpers.js +0 -125
  41. package/src/client/composables/runtime/operationValidationHelpers.js +0 -51
  42. package/src/client/composables/runtime/useAddEditCore.js +0 -112
  43. package/src/client/composables/runtime/useCommandCore.js +0 -123
  44. package/src/client/composables/runtime/useEndpointResource.js +0 -199
  45. package/src/client/composables/runtime/useFieldErrorBag.js +0 -61
  46. package/src/client/composables/runtime/useListCore.js +0 -112
  47. package/src/client/composables/runtime/useUiFeedback.js +0 -98
  48. package/src/client/composables/runtime/useViewCore.js +0 -93
  49. package/src/client/composables/runtime/viewUiRuntime.js +0 -96
  50. package/src/client/composables/support/errorMessageHelpers.js +0 -66
  51. package/src/client/composables/support/listQueryParamSupport.js +0 -473
  52. package/src/client/composables/support/listSearchSupport.js +0 -70
  53. package/src/client/composables/support/refValueHelpers.js +0 -19
  54. package/src/client/composables/support/requestQueryRuntimeSupport.js +0 -141
  55. package/src/client/composables/support/resourceLoadStateHelpers.js +0 -208
  56. package/src/client/composables/support/routeTemplateHelpers.js +0 -285
  57. package/src/client/composables/support/scopeHelpers.js +0 -145
  58. package/src/client/composables/useAccess.js +0 -109
  59. package/src/client/composables/useCommand.js +0 -118
  60. package/src/client/composables/useCrudAddEditScreen.js +0 -88
  61. package/src/client/composables/useCrudDeleteAction.js +0 -160
  62. package/src/client/composables/useCrudListBulkActions.js +0 -147
  63. package/src/client/composables/useCrudListFilterLookups.js +0 -146
  64. package/src/client/composables/useCrudListFilters.js +0 -339
  65. package/src/client/composables/useCrudListParentTitle.js +0 -151
  66. package/src/client/composables/useCrudListRowActions.js +0 -144
  67. package/src/client/composables/useCrudListScreen.js +0 -237
  68. package/src/client/composables/useCrudViewScreen.js +0 -77
  69. package/src/client/composables/usePagedCollection.js +0 -181
  70. package/src/client/composables/useRealtimeQueryInvalidation.js +0 -156
  71. package/src/client/composables/useScopeRuntime.js +0 -135
  72. package/src/client/filters.js +0 -15
  73. package/src/client/lib/httpClient.js +0 -47
  74. package/src/client/lib/permissions.js +0 -34
  75. package/src/client/rowActions.js +0 -47
  76. package/src/client/support/contractGuards.js +0 -34
  77. package/src/client/support/crudListDateFilterSupport.js +0 -91
  78. package/test/addEditUiRuntime.test.js +0 -110
  79. package/test/crudBindingSupport.test.js +0 -110
  80. package/test/crudHttpClientSupport.test.js +0 -77
  81. package/test/crudJsonApiTransportSupport.test.js +0 -179
  82. package/test/crudListBulkActionSurface.test.js +0 -27
  83. package/test/crudListDateFilterSupport.test.js +0 -92
  84. package/test/crudListDateFilterSurface.browser.test.js +0 -182
  85. package/test/crudListFilterSurface.test.js +0 -90
  86. package/test/crudLookupFieldRuntime.test.js +0 -264
  87. package/test/crudScreenComponents.test.js +0 -117
  88. package/test/errorIntentContract.test.js +0 -31
  89. package/test/errorMessageHelpers.test.js +0 -28
  90. package/test/listQueryParamSupport.test.js +0 -223
  91. package/test/listUiRuntime.test.js +0 -102
  92. package/test/operationValidationHelpers.test.js +0 -64
  93. package/test/permissions.test.js +0 -35
  94. package/test/refValueHelpers.test.js +0 -14
  95. package/test/requestTransportOptions.test.js +0 -457
  96. package/test/resourceLoadStateHelpers.test.js +0 -189
  97. package/test/routeTemplateHelpers.test.js +0 -85
  98. package/test/scopeHelpers.test.js +0 -57
  99. package/test/useAddEditCore.test.js +0 -124
  100. package/test/useAddEditRequestQueryParams.test.js +0 -190
  101. package/test/useCrudAddEdit.test.js +0 -415
  102. package/test/useCrudDeleteAction.test.js +0 -139
  103. package/test/useCrudListBulkActions.test.js +0 -65
  104. package/test/useCrudListFilterLookups.test.js +0 -114
  105. package/test/useCrudListFilters.test.js +0 -293
  106. package/test/useCrudListParentTitle.test.js +0 -262
  107. package/test/useCrudListRowActions.test.js +0 -77
  108. package/test/useListRouteInitialization.test.js +0 -337
  109. package/test/useListSearchSupport.test.js +0 -61
  110. package/test/usePagedCollection.test.js +0 -53
  111. package/test/useViewRequestQueryParams.test.js +0 -20
  112. package/test/viewCoreLoading.test.js +0 -44
  113. package/test/viewUiRuntime.test.js +0 -95
@@ -1,145 +0,0 @@
1
- import { resolveEnabledRef, resolveTextRef } from "./refValueHelpers.js";
2
- import {
3
- ROUTE_VISIBILITY_TOKENS,
4
- ROUTE_VISIBILITY_WORKSPACE,
5
- ROUTE_VISIBILITY_WORKSPACE_USER
6
- } from "@jskit-ai/kernel/shared/support/visibility";
7
-
8
- const OWNERSHIP_FILTER_VALUES = ROUTE_VISIBILITY_TOKENS;
9
- const SCOPED_OWNERSHIP_FILTER_SET = new Set([
10
- ROUTE_VISIBILITY_WORKSPACE,
11
- ROUTE_VISIBILITY_WORKSPACE_USER
12
- ]);
13
- const ACCESS_MODE_VALUES = Object.freeze(["auto", "always", "never"]);
14
-
15
- function asPlainObject(value) {
16
- if (!value || typeof value !== "object" || Array.isArray(value)) {
17
- return {};
18
- }
19
-
20
- return value;
21
- }
22
-
23
- function normalizePermissions(value) {
24
- if (Array.isArray(value)) {
25
- return value.map((entry) => String(entry || "").trim()).filter(Boolean);
26
- }
27
-
28
- const one = String(value || "").trim();
29
- return one ? [one] : [];
30
- }
31
-
32
- function resolvePermissionAccess(access, normalizedPermissions = []) {
33
- if (normalizedPermissions.length < 1) {
34
- return true;
35
- }
36
-
37
- return access.canAny(normalizedPermissions);
38
- }
39
-
40
- function normalizeAccessMode(value = "auto") {
41
- const normalized = String(value || "auto").trim().toLowerCase();
42
- if (ACCESS_MODE_VALUES.includes(normalized)) {
43
- return normalized;
44
- }
45
-
46
- throw new TypeError(
47
- `access must be one of: ${ACCESS_MODE_VALUES.join(", ")}. Received: ${String(value || "") || "(empty)"}`
48
- );
49
- }
50
-
51
- function resolveAccessModeEnabled(accessMode = "auto", { hasPermissionRequirements = false } = {}) {
52
- const normalizedMode = normalizeAccessMode(accessMode);
53
- if (normalizedMode === "always") {
54
- return true;
55
- }
56
- if (normalizedMode === "never") {
57
- return false;
58
- }
59
-
60
- return hasPermissionRequirements === true;
61
- }
62
-
63
- function ensureAccessModeCompatibility({
64
- accessMode = "auto",
65
- hasPermissionRequirements = false,
66
- caller = "users-web"
67
- } = {}) {
68
- const normalizedMode = normalizeAccessMode(accessMode);
69
- if (normalizedMode === "never" && hasPermissionRequirements) {
70
- throw new TypeError(`${caller} cannot use access:\"never\" when permission requirements are configured.`);
71
- }
72
-
73
- return normalizedMode;
74
- }
75
-
76
- function resolveApiSuffix(apiSuffix, context = {}) {
77
- if (typeof apiSuffix === "function") {
78
- return resolveTextRef(apiSuffix(context));
79
- }
80
-
81
- return resolveTextRef(apiSuffix);
82
- }
83
-
84
- function resolveEnabled(value, context = {}) {
85
- if (typeof value === "function") {
86
- return Boolean(value(context));
87
- }
88
-
89
- return resolveEnabledRef(value);
90
- }
91
-
92
- function normalizeOwnershipFilter(value = ROUTE_VISIBILITY_WORKSPACE) {
93
- const normalized = String(value || ROUTE_VISIBILITY_WORKSPACE).trim().toLowerCase();
94
- if (OWNERSHIP_FILTER_VALUES.includes(normalized)) {
95
- return normalized;
96
- }
97
-
98
- throw new TypeError(
99
- `ownershipFilter must be one of: ${OWNERSHIP_FILTER_VALUES.join(", ")}. Received: ${String(value || "") || "(empty)"}`
100
- );
101
- }
102
-
103
- function isScopedOwnershipFilter(ownershipFilter) {
104
- return SCOPED_OWNERSHIP_FILTER_SET.has(ownershipFilter);
105
- }
106
-
107
- function resolveQueryKey(
108
- queryKeyFactory,
109
- { surfaceId = "", scopeParamValue = "", ownershipFilter = ROUTE_VISIBILITY_WORKSPACE } = {}
110
- ) {
111
- if (typeof queryKeyFactory !== "function") {
112
- throw new TypeError("queryKeyFactory is required.");
113
- }
114
-
115
- if (isScopedOwnershipFilter(ownershipFilter)) {
116
- return queryKeyFactory(surfaceId, scopeParamValue, ownershipFilter);
117
- }
118
-
119
- return queryKeyFactory(surfaceId, ownershipFilter);
120
- }
121
-
122
- function resolveResourceMessages(resource, defaults = {}) {
123
- const defaultMessages = asPlainObject(defaults);
124
- const resourceMessages = asPlainObject(asPlainObject(resource).messages);
125
-
126
- return {
127
- ...defaultMessages,
128
- ...resourceMessages
129
- };
130
- }
131
-
132
- export {
133
- asPlainObject,
134
- normalizePermissions,
135
- resolvePermissionAccess,
136
- normalizeAccessMode,
137
- resolveAccessModeEnabled,
138
- ensureAccessModeCompatibility,
139
- resolveApiSuffix,
140
- resolveEnabled,
141
- normalizeOwnershipFilter,
142
- isScopedOwnershipFilter,
143
- resolveQueryKey,
144
- resolveResourceMessages
145
- };
@@ -1,109 +0,0 @@
1
- import { computed } from "vue";
2
- import { hasPermission, normalizePermissionList } from "../lib/permissions.js";
3
- import { resolveEnabledRef, resolveTextRef } from "./support/refValueHelpers.js";
4
- import {
5
- normalizeAccessMode,
6
- resolveAccessModeEnabled
7
- } from "./support/scopeHelpers.js";
8
- import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
9
-
10
- function asPermissionList(value) {
11
- if (Array.isArray(value)) {
12
- return value;
13
- }
14
-
15
- if (value === undefined || value === null || value === "") {
16
- return [];
17
- }
18
-
19
- return [value];
20
- }
21
-
22
- function useAccess({
23
- scopeParamValue = "",
24
- enabled = true,
25
- access = "always",
26
- hasPermissionRequirements = false
27
- } = {}) {
28
- const normalizedAccessMode = normalizeAccessMode(access);
29
- const accessRequired = resolveAccessModeEnabled(normalizedAccessMode, {
30
- hasPermissionRequirements: hasPermissionRequirements === true
31
- });
32
- const { context: placementContext } = useWebPlacementContext();
33
- const normalizedScopeParamValue = computed(() => resolveTextRef(scopeParamValue));
34
- const queryEnabled = computed(() => resolveEnabledRef(enabled) && accessRequired);
35
- const hasPlacementBootstrapPermissions = computed(() => {
36
- const source = placementContext.value;
37
- if (!source || typeof source !== "object") {
38
- return false;
39
- }
40
- return Object.hasOwn(source, "permissions");
41
- });
42
- const placementPermissions = computed(() => normalizePermissionList(placementContext.value?.permissions));
43
- const permissions = computed(() => {
44
- if (!queryEnabled.value || !hasPlacementBootstrapPermissions.value) {
45
- return [];
46
- }
47
- return placementPermissions.value;
48
- });
49
- const bootstrapError = computed(() => {
50
- if (!queryEnabled.value || hasPlacementBootstrapPermissions.value) {
51
- return "";
52
- }
53
- return "Permissions are unavailable in placement context.";
54
- });
55
- const isBootstrapping = computed(() => queryEnabled.value && !hasPlacementBootstrapPermissions.value);
56
-
57
- function can(permission) {
58
- return hasPermission(permissions.value, permission);
59
- }
60
-
61
- function canAny(requiredPermissions) {
62
- const list = asPermissionList(requiredPermissions);
63
- if (list.length < 1) {
64
- return true;
65
- }
66
-
67
- for (const entry of list) {
68
- if (can(entry)) {
69
- return true;
70
- }
71
- }
72
-
73
- return false;
74
- }
75
-
76
- function canAll(requiredPermissions) {
77
- const list = asPermissionList(requiredPermissions);
78
- if (list.length < 1) {
79
- return true;
80
- }
81
-
82
- for (const entry of list) {
83
- if (!can(entry)) {
84
- return false;
85
- }
86
- }
87
-
88
- return true;
89
- }
90
-
91
- async function refreshBootstrap() {
92
- return null;
93
- }
94
-
95
- return Object.freeze({
96
- accessMode: normalizedAccessMode,
97
- accessRequired,
98
- scopeParamValue: normalizedScopeParamValue,
99
- permissions,
100
- bootstrapError,
101
- isBootstrapping,
102
- can,
103
- canAny,
104
- canAll,
105
- refreshBootstrap
106
- });
107
- }
108
-
109
- export { useAccess };
@@ -1,118 +0,0 @@
1
- import { proxyRefs } from "vue";
2
- import { ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/kernel/shared/support/visibility";
3
- import { useCommandCore } from "./runtime/useCommandCore.js";
4
- import { useEndpointResource } from "./runtime/useEndpointResource.js";
5
- import { useOperationScope } from "./internal/useOperationScope.js";
6
- import { useUiFeedback } from "./runtime/useUiFeedback.js";
7
- import { useFieldErrorBag } from "./runtime/useFieldErrorBag.js";
8
- import {
9
- setupRouteChangeCleanup,
10
- setupOperationErrorReporting
11
- } from "./runtime/operationUiHelpers.js";
12
- import { resolveCrudHttpClient } from "./crud/crudHttpClientSupport.js";
13
-
14
- function useCommand({
15
- ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
16
- surfaceId = "",
17
- access = "auto",
18
- apiSuffix = "",
19
- runPermissions = [],
20
- writeMethod = "POST",
21
- client = null,
22
- resource: commandResource = null,
23
- transport = null,
24
- placementSource = "users-web.command",
25
- fallbackRunError = "Unable to complete action.",
26
- fieldErrorKeys = [],
27
- clearOnRouteChange = true,
28
- model,
29
- input,
30
- buildRawPayload,
31
- buildCommandPayload,
32
- buildCommandOptions,
33
- onRunSuccess,
34
- onRunError,
35
- suppressSuccessMessage = false,
36
- messages = {},
37
- realtime = null
38
- } = {}) {
39
- const operationScope = useOperationScope({
40
- ownershipFilter,
41
- surfaceId,
42
- access,
43
- placementSource,
44
- apiSuffix,
45
- model,
46
- readEnabled: false,
47
- permissionSets: {
48
- run: runPermissions
49
- },
50
- realtime
51
- });
52
- const routeContext = operationScope.routeContext;
53
- const canRun = operationScope.permissionGate("run");
54
-
55
- const endpointResource = useEndpointResource({
56
- path: operationScope.apiPath,
57
- enabled: false,
58
- client: resolveCrudHttpClient(commandResource, { client }),
59
- writeMethod,
60
- transport,
61
- fallbackSaveError: fallbackRunError
62
- });
63
-
64
- const feedback = useUiFeedback({
65
- source: `${placementSource}.feedback`
66
- });
67
- const fieldBag = useFieldErrorBag(fieldErrorKeys);
68
-
69
- const command = useCommandCore({
70
- model,
71
- resource: endpointResource,
72
- writeMethod,
73
- canRun,
74
- fieldBag,
75
- feedback,
76
- input,
77
- buildRawPayload,
78
- buildCommandPayload,
79
- buildCommandOptions,
80
- onRunSuccess,
81
- onRunError,
82
- suppressSuccessMessage: Boolean(suppressSuccessMessage),
83
- messages: {
84
- validation: "Fix invalid values and try again.",
85
- success: "Completed.",
86
- error: String(fallbackRunError || "Unable to complete action."),
87
- ...(messages && typeof messages === "object" ? messages : {})
88
- }
89
- });
90
-
91
- setupRouteChangeCleanup({
92
- enabled: clearOnRouteChange,
93
- route: routeContext.route,
94
- feedback,
95
- fieldBag
96
- });
97
-
98
- const loadError = operationScope.loadError();
99
- const isLoading = operationScope.isLoading();
100
- setupOperationErrorReporting({
101
- source: `${placementSource}.load`,
102
- loadError
103
- });
104
-
105
- return proxyRefs({
106
- canRun,
107
- isLoading,
108
- loadError,
109
- isRunning: command.running,
110
- fieldErrors: command.fieldErrors,
111
- message: command.message,
112
- messageType: command.messageType,
113
- run: command.run,
114
- resource: endpointResource
115
- });
116
- }
117
-
118
- export { useCommand };
@@ -1,88 +0,0 @@
1
- import { computed, unref } from "vue";
2
- import { useRoute } from "vue-router";
3
- import { useCrudAddEdit } from "./records/useCrudAddEdit.js";
4
-
5
- function normalizeProvidedScreen(screen = null) {
6
- return screen && typeof screen === "object" && !Array.isArray(screen)
7
- ? screen
8
- : null;
9
- }
10
-
11
- function useCrudAddEditScreen({
12
- screen = null,
13
- mode = "new",
14
- title = "",
15
- subtitle = "",
16
- saveLabel = "Save",
17
- cancelTo = "",
18
- resource = null,
19
- operationName = "",
20
- formFields = [],
21
- addEditOptions = {},
22
- saveSuccess = {},
23
- fieldBinding = null,
24
- createModel = null,
25
- buildPayload = null,
26
- mapPayloadToModel = null,
27
- input = null,
28
- preserveCancelQuery = false
29
- } = {}) {
30
- const providedScreen = normalizeProvidedScreen(screen);
31
- if (providedScreen) {
32
- return providedScreen;
33
- }
34
-
35
- const route = useRoute();
36
- const formRuntime = useCrudAddEdit({
37
- resource,
38
- operationName,
39
- formFields,
40
- addEditOptions,
41
- saveSuccess,
42
- fieldBinding,
43
- createModel,
44
- buildPayload,
45
- mapPayloadToModel,
46
- input
47
- });
48
- const resolvedMode = computed(() => String(unref(mode) || "new").trim() || "new");
49
- const resolvedTitle = computed(() => String(unref(title) || "").trim());
50
- const resolvedSubtitle = computed(() => String(unref(subtitle) || "").trim());
51
- const resolvedSaveLabel = computed(() => String(unref(saveLabel) || "Save").trim() || "Save");
52
- const resolvedCancelTo = computed(() => unref(cancelTo));
53
-
54
- function resolveCancelTo(target = resolvedCancelTo.value) {
55
- const resolvedTarget = unref(target);
56
- if (!resolvedTarget) {
57
- return "";
58
- }
59
-
60
- if (typeof resolvedTarget === "string") {
61
- const resolvedPath = formRuntime.addEdit.resolveParams(resolvedTarget);
62
- if (!preserveCancelQuery || !resolvedPath) {
63
- return resolvedPath;
64
- }
65
- return {
66
- path: resolvedPath,
67
- query: route.query
68
- };
69
- }
70
-
71
- return resolvedTarget;
72
- }
73
-
74
- return Object.freeze({
75
- mode: resolvedMode,
76
- title: resolvedTitle,
77
- subtitle: resolvedSubtitle,
78
- saveLabel: resolvedSaveLabel,
79
- cancelTo: resolvedCancelTo,
80
- formRuntime,
81
- addEdit: formRuntime.addEdit,
82
- formState: formRuntime.form,
83
- resolveFieldErrors: formRuntime.resolveFieldErrors,
84
- resolveCancelTo
85
- });
86
- }
87
-
88
- export { useCrudAddEditScreen };
@@ -1,160 +0,0 @@
1
- import { computed, proxyRefs, ref, unref } from "vue";
2
- import { useRouter } from "vue-router";
3
- import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
4
- import { resolveCrudJsonApiTransport } from "./crud/crudJsonApiTransportSupport.js";
5
- import { toQueryErrorMessage } from "./support/errorMessageHelpers.js";
6
- import { useCommand } from "./useCommand.js";
7
-
8
- function requireCrudDeleteOperation(resource = null) {
9
- const operation = resource?.operations?.delete;
10
- if (!operation || typeof operation !== "object" || Array.isArray(operation)) {
11
- throw new TypeError("useCrudDeleteAction requires resource.operations.delete.");
12
- }
13
- if (normalizeText(operation.method).toUpperCase() !== "DELETE") {
14
- throw new TypeError("useCrudDeleteAction requires resource.operations.delete.method to be DELETE.");
15
- }
16
- return operation;
17
- }
18
-
19
- function requireCrudViewScreen(screen = null) {
20
- if (!screen || typeof screen !== "object" || typeof screen?.view?.resolveParams !== "function") {
21
- throw new TypeError("useCrudDeleteAction requires a useCrudViewScreen() result.");
22
- }
23
- return screen;
24
- }
25
-
26
- function resolveDeleteApiSuffix(screen, apiUrlTemplate = "") {
27
- const template = normalizeText(unref(apiUrlTemplate));
28
- return template ? normalizeText(screen.view.resolveParams(template)) : "";
29
- }
30
-
31
- function resolveListLocation(screen) {
32
- return unref(screen?.listLocation) || null;
33
- }
34
-
35
- function useCrudDeleteAction({
36
- screen = null,
37
- resource = null,
38
- resourceNamespace = "",
39
- apiUrlTemplate = "",
40
- access = "auto",
41
- client = null,
42
- router: routerOverride = null,
43
- fallbackDeleteError = "Unable to delete record."
44
- } = {}) {
45
- const resolvedScreen = requireCrudViewScreen(screen);
46
- const deleteOperation = requireCrudDeleteOperation(resource);
47
- const namespace = normalizeText(resourceNamespace, {
48
- fallback: resource?.namespace
49
- });
50
- if (!namespace) {
51
- throw new TypeError("useCrudDeleteAction requires resourceNamespace or resource.namespace.");
52
- }
53
-
54
- const activeRouter = routerOverride || useRouter();
55
- if (!activeRouter || typeof activeRouter.push !== "function") {
56
- throw new TypeError("useCrudDeleteAction requires an installed Vue Router.");
57
- }
58
-
59
- const isOpen = ref(false);
60
- const error = ref("");
61
- const deleteApiSuffix = computed(() => resolveDeleteApiSuffix(resolvedScreen, apiUrlTemplate));
62
-
63
- async function handleDeleteSuccess(_response, context = {}) {
64
- await context?.queryClient?.invalidateQueries?.({
65
- queryKey: ["ui-generator", namespace]
66
- });
67
-
68
- const listLocation = resolveListLocation(resolvedScreen);
69
- if (!listLocation) {
70
- throw new Error("Deleted the record, but the generated list route is unavailable.");
71
- }
72
-
73
- isOpen.value = false;
74
- await activeRouter.push(listLocation);
75
- }
76
-
77
- function handleDeleteError(cause) {
78
- error.value = toQueryErrorMessage(
79
- cause,
80
- fallbackDeleteError,
81
- "Unable to delete record."
82
- );
83
- }
84
-
85
- const command = useCommand({
86
- access,
87
- apiSuffix: deleteApiSuffix,
88
- writeMethod: deleteOperation.method,
89
- client,
90
- transport: resolveCrudJsonApiTransport(undefined, resource, {
91
- mode: "delete"
92
- }),
93
- placementSource: `ui-generator.${namespace}.view.delete`,
94
- fallbackRunError: fallbackDeleteError,
95
- onRunSuccess: handleDeleteSuccess,
96
- onRunError: handleDeleteError,
97
- suppressSuccessMessage: true
98
- });
99
-
100
- const isDeleting = computed(() => Boolean(command.isRunning));
101
- const canDelete = computed(() => {
102
- const view = resolvedScreen.view;
103
- return Boolean(
104
- command.canRun &&
105
- deleteApiSuffix.value &&
106
- resolveListLocation(resolvedScreen) &&
107
- unref(view.recordId) &&
108
- unref(view.record) &&
109
- !unref(view.isLoading) &&
110
- !unref(view.isNotFound)
111
- );
112
- });
113
-
114
- function request() {
115
- if (!canDelete.value) {
116
- return false;
117
- }
118
- error.value = "";
119
- isOpen.value = true;
120
- return true;
121
- }
122
-
123
- function cancel() {
124
- if (isDeleting.value) {
125
- return false;
126
- }
127
- error.value = "";
128
- isOpen.value = false;
129
- return true;
130
- }
131
-
132
- async function confirm() {
133
- if (!isOpen.value || !canDelete.value || isDeleting.value) {
134
- return null;
135
- }
136
-
137
- error.value = "";
138
- try {
139
- return await command.run();
140
- } catch {
141
- return null;
142
- }
143
- }
144
-
145
- return proxyRefs({
146
- isOpen,
147
- isDeleting,
148
- canDelete,
149
- error,
150
- request,
151
- cancel,
152
- confirm
153
- });
154
- }
155
-
156
- export {
157
- requireCrudDeleteOperation,
158
- resolveDeleteApiSuffix,
159
- useCrudDeleteAction
160
- };