@jskit-ai/http-web 0.1.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.
Files changed (110) hide show
  1. package/fixtures/crud-list-date-filters/App.vue +107 -0
  2. package/fixtures/crud-list-date-filters/index.html +12 -0
  3. package/fixtures/crud-list-date-filters/main.js +24 -0
  4. package/fixtures/crud-list-date-filters/vite.config.mjs +18 -0
  5. package/package.json +150 -0
  6. package/src/client/bulkActions.js +47 -0
  7. package/src/client/components/CrudAddEditScreen.vue +186 -0
  8. package/src/client/components/CrudDeleteAction.vue +93 -0
  9. package/src/client/components/CrudListBulkActionSurface.vue +126 -0
  10. package/src/client/components/CrudListDateFilterControl.vue +188 -0
  11. package/src/client/components/CrudListFilterSurface.vue +388 -0
  12. package/src/client/components/CrudListRecordActionMenu.vue +120 -0
  13. package/src/client/components/CrudListScreen.vue +501 -0
  14. package/src/client/components/CrudViewScreen.vue +197 -0
  15. package/src/client/composables/crud/crudBindingSupport.js +75 -0
  16. package/src/client/composables/crud/crudHttpClientSupport.js +57 -0
  17. package/src/client/composables/crud/crudJsonApiTransportSupport.js +145 -0
  18. package/src/client/composables/crud/crudLookupFieldLabelSupport.js +151 -0
  19. package/src/client/composables/crud/crudLookupFieldRuntime.js +251 -0
  20. package/src/client/composables/crud/crudSchemaFormHelpers.js +464 -0
  21. package/src/client/composables/internal/crudListFilterLookupSupport.js +161 -0
  22. package/src/client/composables/internal/crudListParentTitleSupport.js +171 -0
  23. package/src/client/composables/internal/useOperationScope.js +144 -0
  24. package/src/client/composables/records/useAddEdit.js +224 -0
  25. package/src/client/composables/records/useCrudAddEdit.js +227 -0
  26. package/src/client/composables/records/useCrudList.js +101 -0
  27. package/src/client/composables/records/useCrudView.js +47 -0
  28. package/src/client/composables/records/useList.js +500 -0
  29. package/src/client/composables/records/useView.js +164 -0
  30. package/src/client/composables/runtime/addEditUiRuntime.js +130 -0
  31. package/src/client/composables/runtime/listUiRuntime.js +123 -0
  32. package/src/client/composables/runtime/modelStateHelpers.js +90 -0
  33. package/src/client/composables/runtime/operationAdapters.js +34 -0
  34. package/src/client/composables/runtime/operationUiHelpers.js +125 -0
  35. package/src/client/composables/runtime/operationValidationHelpers.js +51 -0
  36. package/src/client/composables/runtime/useAddEditCore.js +112 -0
  37. package/src/client/composables/runtime/useCommandCore.js +123 -0
  38. package/src/client/composables/runtime/useEndpointResource.js +199 -0
  39. package/src/client/composables/runtime/useFieldErrorBag.js +61 -0
  40. package/src/client/composables/runtime/useListCore.js +112 -0
  41. package/src/client/composables/runtime/useUiFeedback.js +98 -0
  42. package/src/client/composables/runtime/useViewCore.js +93 -0
  43. package/src/client/composables/runtime/viewUiRuntime.js +96 -0
  44. package/src/client/composables/support/errorMessageHelpers.js +66 -0
  45. package/src/client/composables/support/listQueryParamSupport.js +473 -0
  46. package/src/client/composables/support/listSearchSupport.js +70 -0
  47. package/src/client/composables/support/refValueHelpers.js +19 -0
  48. package/src/client/composables/support/requestQueryRuntimeSupport.js +141 -0
  49. package/src/client/composables/support/resourceLoadStateHelpers.js +208 -0
  50. package/src/client/composables/support/routeTemplateHelpers.js +285 -0
  51. package/src/client/composables/support/scopeHelpers.js +145 -0
  52. package/src/client/composables/useAccess.js +109 -0
  53. package/src/client/composables/useCommand.js +118 -0
  54. package/src/client/composables/useCrudAddEditScreen.js +88 -0
  55. package/src/client/composables/useCrudDeleteAction.js +160 -0
  56. package/src/client/composables/useCrudListBulkActions.js +147 -0
  57. package/src/client/composables/useCrudListFilterLookups.js +146 -0
  58. package/src/client/composables/useCrudListFilters.js +339 -0
  59. package/src/client/composables/useCrudListParentTitle.js +151 -0
  60. package/src/client/composables/useCrudListRowActions.js +144 -0
  61. package/src/client/composables/useCrudListScreen.js +237 -0
  62. package/src/client/composables/useCrudViewScreen.js +77 -0
  63. package/src/client/composables/usePagedCollection.js +181 -0
  64. package/src/client/composables/useRealtimeQueryInvalidation.js +156 -0
  65. package/src/client/composables/useScopeRuntime.js +135 -0
  66. package/src/client/filters.js +15 -0
  67. package/src/client/index.js +24 -0
  68. package/src/client/lib/httpClient.js +47 -0
  69. package/src/client/lib/permissions.js +34 -0
  70. package/src/client/rowActions.js +47 -0
  71. package/src/client/support/contractGuards.js +34 -0
  72. package/src/client/support/crudListDateFilterSupport.js +91 -0
  73. package/test/addEditUiRuntime.test.js +110 -0
  74. package/test/crudBindingSupport.test.js +110 -0
  75. package/test/crudHttpClientSupport.test.js +77 -0
  76. package/test/crudJsonApiTransportSupport.test.js +179 -0
  77. package/test/crudListBulkActionSurface.test.js +27 -0
  78. package/test/crudListDateFilterSupport.test.js +92 -0
  79. package/test/crudListDateFilterSurface.browser.test.js +182 -0
  80. package/test/crudListFilterSurface.test.js +90 -0
  81. package/test/crudLookupFieldRuntime.test.js +264 -0
  82. package/test/crudScreenComponents.test.js +110 -0
  83. package/test/errorIntentContract.test.js +31 -0
  84. package/test/errorMessageHelpers.test.js +28 -0
  85. package/test/exportsContract.test.js +68 -0
  86. package/test/listQueryParamSupport.test.js +223 -0
  87. package/test/listUiRuntime.test.js +102 -0
  88. package/test/operationValidationHelpers.test.js +64 -0
  89. package/test/packageBoundary.test.js +31 -0
  90. package/test/permissions.test.js +35 -0
  91. package/test/refValueHelpers.test.js +14 -0
  92. package/test/requestTransportOptions.test.js +457 -0
  93. package/test/resourceLoadStateHelpers.test.js +189 -0
  94. package/test/routeTemplateHelpers.test.js +85 -0
  95. package/test/scopeHelpers.test.js +57 -0
  96. package/test/useAddEditCore.test.js +124 -0
  97. package/test/useAddEditRequestQueryParams.test.js +190 -0
  98. package/test/useCrudAddEdit.test.js +415 -0
  99. package/test/useCrudDeleteAction.test.js +139 -0
  100. package/test/useCrudListBulkActions.test.js +65 -0
  101. package/test/useCrudListFilterLookups.test.js +114 -0
  102. package/test/useCrudListFilters.test.js +293 -0
  103. package/test/useCrudListParentTitle.test.js +262 -0
  104. package/test/useCrudListRowActions.test.js +77 -0
  105. package/test/useListRouteInitialization.test.js +337 -0
  106. package/test/useListSearchSupport.test.js +61 -0
  107. package/test/usePagedCollection.test.js +53 -0
  108. package/test/useViewRequestQueryParams.test.js +20 -0
  109. package/test/viewCoreLoading.test.js +44 -0
  110. package/test/viewUiRuntime.test.js +95 -0
@@ -0,0 +1,151 @@
1
+ import { computed, proxyRefs } from "vue";
2
+ import { useRoute } from "vue-router";
3
+ import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
4
+ import { inferCrudLookupJsonApiTransport } from "./crud/crudJsonApiTransportSupport.js";
5
+ import {
6
+ resolveRouteParamsSource,
7
+ toRouteParamValue
8
+ } from "./support/routeTemplateHelpers.js";
9
+ import { useView } from "./records/useView.js";
10
+ import {
11
+ resolveCrudListParentDescriptor,
12
+ resolveCrudListParentRecordTitle,
13
+ resolveCrudListParentTitleFromItems
14
+ } from "./internal/crudListParentTitleSupport.js";
15
+
16
+ function normalizeQueryKeyPrefix(value = []) {
17
+ if (Array.isArray(value)) {
18
+ return value
19
+ .map((entry) => normalizeText(entry))
20
+ .filter(Boolean);
21
+ }
22
+
23
+ const normalizedValue = normalizeText(value);
24
+ return normalizedValue ? [normalizedValue] : [];
25
+ }
26
+
27
+ function useCrudListParentTitle({
28
+ listRuntime = null,
29
+ resource = {},
30
+ adapter = null,
31
+ recordIdParam = "recordId",
32
+ queryKeyPrefix = ["http-web", "crud-list-parent-title"],
33
+ placementSource = "http-web.crud-list-parent-title",
34
+ fallbackLoadError = "Unable to load parent record.",
35
+ notFoundMessage = "Parent record not found.",
36
+ route = null,
37
+ viewRuntimeFactory = useView
38
+ } = {}) {
39
+ const sourceRoute = route && typeof route === "object" ? route : useRoute();
40
+ const parentDescriptor = computed(() => {
41
+ const descriptor = resolveCrudListParentDescriptor({
42
+ resource,
43
+ route: sourceRoute,
44
+ recordIdParam
45
+ });
46
+ if (!descriptor) {
47
+ return null;
48
+ }
49
+
50
+ const routeParams = resolveRouteParamsSource(sourceRoute?.params || {});
51
+ const routeParamValue = toRouteParamValue(routeParams[descriptor.routeParamKey]);
52
+ if (!routeParamValue) {
53
+ return null;
54
+ }
55
+
56
+ return Object.freeze({
57
+ ...descriptor,
58
+ routeParamValue
59
+ });
60
+ });
61
+
62
+ const initialParentDescriptor = parentDescriptor.value || {};
63
+ const parentTransport = (() => {
64
+ const baseTransport = inferCrudLookupJsonApiTransport({
65
+ namespace: initialParentDescriptor.relationNamespace
66
+ });
67
+ if (!baseTransport) {
68
+ return null;
69
+ }
70
+
71
+ return Object.freeze({
72
+ ...baseTransport,
73
+ responseKind: "record"
74
+ });
75
+ })();
76
+ const normalizedQueryKeyPrefix = normalizeQueryKeyPrefix(queryKeyPrefix);
77
+ const shouldLoadParentRecord = computed(() => {
78
+ const descriptor = parentDescriptor.value;
79
+ if (!descriptor?.apiUrlTemplate) {
80
+ return false;
81
+ }
82
+ if (Boolean(listRuntime?.isInitialLoading) || normalizeText(listRuntime?.loadError)) {
83
+ return false;
84
+ }
85
+
86
+ const items = Array.isArray(listRuntime?.items) ? listRuntime.items : [];
87
+ if (items.length < 1) {
88
+ return true;
89
+ }
90
+
91
+ const listTitle = resolveCrudListParentTitleFromItems(items, descriptor);
92
+ return !listTitle;
93
+ });
94
+
95
+ const parentView = viewRuntimeFactory({
96
+ adapter,
97
+ apiUrlTemplate: normalizeText(initialParentDescriptor.apiUrlTemplate),
98
+ transport: parentTransport,
99
+ readEnabled: shouldLoadParentRecord,
100
+ recordIdParam: normalizeText(initialParentDescriptor.routeParamKey) || "recordId",
101
+ includeRecordIdInQueryKey: true,
102
+ queryKeyFactory: (surfaceId = "", scopeParamValue = "") => [
103
+ ...normalizedQueryKeyPrefix,
104
+ normalizeText(initialParentDescriptor.relationNamespace),
105
+ normalizeText(initialParentDescriptor.routeParamKey),
106
+ String(surfaceId || ""),
107
+ String(scopeParamValue || "")
108
+ ],
109
+ placementSource,
110
+ fallbackLoadError,
111
+ notFoundMessage
112
+ });
113
+
114
+ const title = computed(() => {
115
+ const descriptor = parentDescriptor.value;
116
+ if (!descriptor) {
117
+ return "";
118
+ }
119
+
120
+ const parentRecordTitle = resolveCrudListParentRecordTitle(parentView?.record || {}, descriptor);
121
+ if (parentRecordTitle && shouldLoadParentRecord.value) {
122
+ return parentRecordTitle;
123
+ }
124
+
125
+ const listTitle = resolveCrudListParentTitleFromItems(listRuntime?.items, descriptor);
126
+ if (listTitle) {
127
+ return listTitle;
128
+ }
129
+
130
+ if (parentRecordTitle) {
131
+ return parentRecordTitle;
132
+ }
133
+
134
+ if (descriptor.routeParamValue) {
135
+ return `${descriptor.entityLabel} #${descriptor.routeParamValue}`;
136
+ }
137
+
138
+ return descriptor.entityLabel;
139
+ });
140
+
141
+ return proxyRefs({
142
+ title,
143
+ descriptor: parentDescriptor,
144
+ shouldLoadParentRecord,
145
+ record: computed(() => parentView?.record || null),
146
+ isLoading: computed(() => Boolean(parentView?.isLoading)),
147
+ loadError: computed(() => normalizeText(parentView?.loadError))
148
+ });
149
+ }
150
+
151
+ export { useCrudListParentTitle };
@@ -0,0 +1,144 @@
1
+ import { computed, ref } from "vue";
2
+ import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
3
+ import { defineCrudListRowActions } from "../rowActions.js";
4
+
5
+ function normalizeRowActionKey(actionOrKey = "") {
6
+ return normalizeText(
7
+ actionOrKey && typeof actionOrKey === "object"
8
+ ? actionOrKey.key
9
+ : actionOrKey
10
+ );
11
+ }
12
+
13
+ function normalizeRowId(value = "") {
14
+ return normalizeText(value);
15
+ }
16
+
17
+ function createExecutionKey(actionKey = "", recordId = "", index = 0) {
18
+ return [
19
+ actionKey,
20
+ recordId || `index-${index}`
21
+ ].join(":");
22
+ }
23
+
24
+ function asContextObject(value = null) {
25
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
26
+ }
27
+
28
+ function useCrudListRowActions(actions = [], {
29
+ resolveRecordId = null,
30
+ resolveContext = null
31
+ } = {}) {
32
+ const normalizedActions = defineCrudListRowActions(actions);
33
+ const executingKeys = ref([]);
34
+ const hasActions = computed(() => normalizedActions.length > 0);
35
+
36
+ function getRecordId(record = {}, index = 0) {
37
+ const resolvedId = typeof resolveRecordId === "function"
38
+ ? resolveRecordId(record, index)
39
+ : record?.id ?? record?.attributes?.id ?? index;
40
+ return normalizeRowId(resolvedId);
41
+ }
42
+
43
+ function createActionContext(action = {}, record = {}, index = 0) {
44
+ const baseContext = typeof resolveContext === "function" ? resolveContext() : {};
45
+ return {
46
+ ...asContextObject(baseContext),
47
+ action,
48
+ record,
49
+ index,
50
+ recordId: getRecordId(record, index)
51
+ };
52
+ }
53
+
54
+ function findAction(actionOrKey = "") {
55
+ const actionKey = normalizeRowActionKey(actionOrKey);
56
+ return normalizedActions.find((action) => action.key === actionKey) || null;
57
+ }
58
+
59
+ function resolveActionFlag(action = {}, flagKey = "", record = {}, index = 0, fallback = false) {
60
+ const flag = action?.[flagKey];
61
+ if (typeof flag === "function") {
62
+ return Boolean(flag(createActionContext(action, record, index)));
63
+ }
64
+ if (flag === undefined || flag === null) {
65
+ return fallback;
66
+ }
67
+ return Boolean(flag);
68
+ }
69
+
70
+ function isActionVisible(actionOrKey = "", record = {}, index = 0) {
71
+ const action = findAction(actionOrKey);
72
+ return action ? resolveActionFlag(action, "visible", record, index, true) : false;
73
+ }
74
+
75
+ function isActionExecuting(actionOrKey = "", record = {}, index = 0) {
76
+ const action = findAction(actionOrKey);
77
+ if (!action) {
78
+ return false;
79
+ }
80
+
81
+ const executionKey = createExecutionKey(action.key, getRecordId(record, index), index);
82
+ return executingKeys.value.includes(executionKey);
83
+ }
84
+
85
+ function isActionLoading(actionOrKey = "", record = {}, index = 0) {
86
+ const action = findAction(actionOrKey);
87
+ if (!action) {
88
+ return false;
89
+ }
90
+
91
+ return isActionExecuting(action, record, index) ||
92
+ resolveActionFlag(action, "loading", record, index, false);
93
+ }
94
+
95
+ function isActionDisabled(actionOrKey = "", record = {}, index = 0) {
96
+ const action = findAction(actionOrKey);
97
+ if (!action || !isActionVisible(action, record, index) || !action.run) {
98
+ return true;
99
+ }
100
+
101
+ return isActionLoading(action, record, index) ||
102
+ resolveActionFlag(action, "disabled", record, index, false);
103
+ }
104
+
105
+ function visibleActionsFor(record = {}, index = 0) {
106
+ return normalizedActions.filter((action) => isActionVisible(action, record, index));
107
+ }
108
+
109
+ function hasVisibleActionsFor(record = {}, index = 0) {
110
+ return visibleActionsFor(record, index).length > 0;
111
+ }
112
+
113
+ async function execute(actionOrKey = "", record = {}, index = 0) {
114
+ const action = findAction(actionOrKey);
115
+ if (!action || typeof action.run !== "function" || isActionDisabled(action, record, index)) {
116
+ return null;
117
+ }
118
+
119
+ const executionKey = createExecutionKey(action.key, getRecordId(record, index), index);
120
+ executingKeys.value = [...executingKeys.value, executionKey];
121
+ try {
122
+ return await action.run(createActionContext(action, record, index));
123
+ } finally {
124
+ executingKeys.value = executingKeys.value.filter((key) => key !== executionKey);
125
+ }
126
+ }
127
+
128
+ return Object.freeze({
129
+ actions: normalizedActions,
130
+ hasActions,
131
+ executingKeys,
132
+ getRecordId,
133
+ findAction,
134
+ isActionVisible,
135
+ isActionDisabled,
136
+ isActionLoading,
137
+ isActionExecuting,
138
+ visibleActionsFor,
139
+ hasVisibleActionsFor,
140
+ execute
141
+ });
142
+ }
143
+
144
+ export { useCrudListRowActions };
@@ -0,0 +1,237 @@
1
+ import { computed, unref } from "vue";
2
+ import { useCrudList } from "./records/useCrudList.js";
3
+ import { useCrudListBulkActions } from "./useCrudListBulkActions.js";
4
+ import { useCrudListFilters } from "./useCrudListFilters.js";
5
+ import { useCrudListRowActions } from "./useCrudListRowActions.js";
6
+ import { resolveCrudHttpClient } from "./crud/crudHttpClientSupport.js";
7
+
8
+ function buildCrudListActionContext(records, client) {
9
+ return Object.freeze({
10
+ records,
11
+ reload: records.reload,
12
+ client
13
+ });
14
+ }
15
+
16
+ function formatCrudListCardValue(value) {
17
+ if (value === null || value === undefined || value === "") {
18
+ return "-";
19
+ }
20
+ if (value === true) {
21
+ return "Yes";
22
+ }
23
+ if (value === false) {
24
+ return "No";
25
+ }
26
+ return value;
27
+ }
28
+
29
+ function asList(value = []) {
30
+ const resolved = unref(value);
31
+ if (resolved == null) {
32
+ return [];
33
+ }
34
+ return Array.isArray(resolved) ? resolved : [resolved];
35
+ }
36
+
37
+ function hasSyntheticRowGroups(value = null) {
38
+ const source = unref(value);
39
+ return Boolean(
40
+ source &&
41
+ typeof source === "object" &&
42
+ !Array.isArray(source) &&
43
+ (Object.hasOwn(source, "prepend") || Object.hasOwn(source, "append"))
44
+ );
45
+ }
46
+
47
+ function normalizeSyntheticDisplayRow(source = null, index = 0, placement = "prepend") {
48
+ const rawRow = unref(source);
49
+ if (!rawRow || typeof rawRow !== "object" || Array.isArray(rawRow)) {
50
+ return null;
51
+ }
52
+
53
+ const hasWrappedRecord = Object.hasOwn(rawRow, "record");
54
+ const record = hasWrappedRecord ? unref(rawRow.record) : rawRow;
55
+ if (!record || typeof record !== "object" || Array.isArray(record)) {
56
+ return null;
57
+ }
58
+
59
+ const keySource = hasWrappedRecord
60
+ ? rawRow.key
61
+ : record.id ?? record.attributes?.id;
62
+ const recordKey = String(keySource || `synthetic-${placement}-${index + 1}`).trim();
63
+
64
+ return Object.freeze({
65
+ key: `synthetic:${placement}:${recordKey}`,
66
+ recordKey,
67
+ record,
68
+ index: hasWrappedRecord && Number.isInteger(rawRow.index) ? rawRow.index : -1,
69
+ synthetic: true,
70
+ selectable: rawRow.selectable === true,
71
+ placement
72
+ });
73
+ }
74
+
75
+ function normalizeSyntheticDisplayRows(value = [], placement = "prepend") {
76
+ return asList(value)
77
+ .map((row, index) => normalizeSyntheticDisplayRow(row, index, placement))
78
+ .filter(Boolean);
79
+ }
80
+
81
+ function normalizeSyntheticDisplayRowGroups(syntheticRows = null) {
82
+ const source = unref(syntheticRows);
83
+ if (hasSyntheticRowGroups(source)) {
84
+ return Object.freeze({
85
+ prepend: normalizeSyntheticDisplayRows(source.prepend, "prepend"),
86
+ append: normalizeSyntheticDisplayRows(source.append, "append")
87
+ });
88
+ }
89
+
90
+ return Object.freeze({
91
+ prepend: normalizeSyntheticDisplayRows(source, "prepend"),
92
+ append: []
93
+ });
94
+ }
95
+
96
+ function createCrudListDisplayRow(record = {}, index = 0, records = {}) {
97
+ const resolveRowKey = typeof records.resolveRowKey === "function"
98
+ ? records.resolveRowKey
99
+ : (_record, fallbackIndex) => fallbackIndex;
100
+ const recordKey = String(resolveRowKey(record, index) || index);
101
+ return Object.freeze({
102
+ key: `record:${recordKey}`,
103
+ recordKey,
104
+ record,
105
+ index,
106
+ synthetic: false,
107
+ selectable: true,
108
+ placement: "records"
109
+ });
110
+ }
111
+
112
+ function useCrudListScreen({
113
+ adapter = null,
114
+ client = null,
115
+ resource = null,
116
+ resourceNamespace = "resource",
117
+ apiSuffix = "",
118
+ recordIdParam = "recordId",
119
+ recordIdSelector = null,
120
+ titleFallbackFieldKey = "",
121
+ viewUrlTemplate = "",
122
+ editUrlTemplate = "",
123
+ newUrlTemplate = "",
124
+ recordChangedEvents = [],
125
+ listFilters = {},
126
+ listBulkActions = [],
127
+ listRowActions = [],
128
+ syntheticRows = null,
129
+ routeQueryBlacklist = Object.freeze(["include", "cursor", "limit"]),
130
+ requestQueryParams = null,
131
+ requestFieldsets = null,
132
+ readEnabled = true,
133
+ requestRecoveryLabel = "Records",
134
+ fallbackLoadError = "Unable to load records."
135
+ } = {}) {
136
+ const crudHttpClient = resolveCrudHttpClient(resource, { client });
137
+ const filterRuntime = useCrudListFilters(listFilters);
138
+ const normalizedRecordChangedEvents = Array.isArray(recordChangedEvents)
139
+ ? recordChangedEvents
140
+ : [];
141
+ const normalizedResourceNamespace = String(resourceNamespace || "resource").trim() || "resource";
142
+ const records = useCrudList({
143
+ adapter: adapter || undefined,
144
+ client: crudHttpClient,
145
+ resource,
146
+ apiSuffix,
147
+ queryKeyFactory: (surfaceId = "", workspaceSlug = "") => [
148
+ "ui-generator",
149
+ normalizedResourceNamespace,
150
+ "list",
151
+ String(surfaceId || ""),
152
+ String(workspaceSlug || "")
153
+ ],
154
+ search: {
155
+ enabled: true,
156
+ mode: "query"
157
+ },
158
+ queryParams: filterRuntime.queryParams,
159
+ routeQueryValueResolvers: filterRuntime.routeQueryValueResolvers,
160
+ syncToRoute: {
161
+ enabled: true,
162
+ mode: "replace",
163
+ search: true,
164
+ queryParams: true,
165
+ queryParamBlacklist: routeQueryBlacklist
166
+ },
167
+ placementSource: `ui-generator.${normalizedResourceNamespace}.list`,
168
+ requestQueryParams,
169
+ requestFieldsets,
170
+ readEnabled,
171
+ requestRecoveryLabel,
172
+ fallbackLoadError,
173
+ recordIdParam,
174
+ recordIdSelector,
175
+ viewUrlTemplate,
176
+ editUrlTemplate,
177
+ realtime: normalizedRecordChangedEvents.length > 0
178
+ ? {
179
+ events: normalizedRecordChangedEvents
180
+ }
181
+ : null
182
+ });
183
+ const displayRows = computed(() => {
184
+ const syntheticRowGroups = normalizeSyntheticDisplayRowGroups(syntheticRows);
185
+ const recordRows = (Array.isArray(records.items) ? records.items : [])
186
+ .map((record, index) => createCrudListDisplayRow(record, index, records));
187
+
188
+ return [
189
+ ...syntheticRowGroups.prepend,
190
+ ...recordRows,
191
+ ...syntheticRowGroups.append
192
+ ];
193
+ });
194
+ const selectableRows = computed(() =>
195
+ displayRows.value.filter((row) => row.selectable !== false)
196
+ );
197
+ const bulkActions = useCrudListBulkActions(listBulkActions, {
198
+ resolveRecordId: (record, index) => records.resolveRowKey(record, index),
199
+ resolveContext: () => buildCrudListActionContext(records, crudHttpClient)
200
+ });
201
+ const rowActions = useCrudListRowActions(listRowActions, {
202
+ resolveRecordId: (record, index) => records.resolveRowKey(record, index),
203
+ resolveContext: () => buildCrudListActionContext(records, crudHttpClient)
204
+ });
205
+ const listPrimaryAction = computed(() =>
206
+ newUrlTemplate ? records.resolveParams(newUrlTemplate) : ""
207
+ );
208
+
209
+ function resolveRecordTitle(record) {
210
+ return records.resolveRecordTitle(record, {
211
+ fallbackKey: titleFallbackFieldKey,
212
+ defaultValue: "Record"
213
+ });
214
+ }
215
+
216
+ return Object.freeze({
217
+ records,
218
+ listFilters,
219
+ filterRuntime,
220
+ bulkActions,
221
+ listRowActions,
222
+ rowActions,
223
+ displayRows,
224
+ selectableRows,
225
+ listPrimaryAction,
226
+ hasViewUrl: Boolean(viewUrlTemplate),
227
+ hasEditUrl: Boolean(editUrlTemplate),
228
+ resolveRecordTitle,
229
+ formatListCardValue: formatCrudListCardValue
230
+ });
231
+ }
232
+
233
+ const __testables = Object.freeze({
234
+ buildCrudListActionContext
235
+ });
236
+
237
+ export { __testables, useCrudListScreen };
@@ -0,0 +1,77 @@
1
+ import { computed, unref } from "vue";
2
+ import { useRoute } from "vue-router";
3
+ import { useCrudView } from "./records/useCrudView.js";
4
+
5
+ function useCrudViewScreen({
6
+ adapter = null,
7
+ resource = null,
8
+ resourceNamespace = "resource",
9
+ apiUrlTemplate = "",
10
+ recordIdParam = "recordId",
11
+ titleFallbackFieldKey = "",
12
+ listUrlTemplate = "",
13
+ editUrlTemplate = "",
14
+ recordChangedEvent = "",
15
+ requestQueryParams = null,
16
+ requestFieldsets = null,
17
+ readEnabled = true,
18
+ queryKeyFactory = null,
19
+ requestRecoveryLabel = "Record",
20
+ fallbackLoadError = "Unable to load record.",
21
+ notFoundMessage = "Record not found."
22
+ } = {}) {
23
+ const route = useRoute();
24
+ const normalizedResourceNamespace = String(resourceNamespace || "resource").trim() || "resource";
25
+ const defaultQueryKeyFactory = (surfaceId = "", workspaceSlug = "") => [
26
+ "ui-generator",
27
+ normalizedResourceNamespace,
28
+ "view",
29
+ String(surfaceId || ""),
30
+ String(workspaceSlug || "")
31
+ ];
32
+ const view = useCrudView({
33
+ adapter: adapter || undefined,
34
+ resource,
35
+ apiUrlTemplate,
36
+ recordIdParam,
37
+ includeRecordIdInQueryKey: true,
38
+ queryKeyFactory: typeof queryKeyFactory === "function" ? queryKeyFactory : defaultQueryKeyFactory,
39
+ requestQueryParams,
40
+ requestFieldsets,
41
+ readEnabled,
42
+ placementSource: `ui-generator.${normalizedResourceNamespace}.view`,
43
+ requestRecoveryLabel,
44
+ fallbackLoadError,
45
+ notFoundMessage,
46
+ listUrlTemplate,
47
+ editUrlTemplate,
48
+ realtime: recordChangedEvent
49
+ ? {
50
+ event: recordChangedEvent
51
+ }
52
+ : null
53
+ });
54
+ const recordTitle = computed(() =>
55
+ view.resolveRecordTitle(view.record, {
56
+ fallbackKey: titleFallbackFieldKey,
57
+ defaultValue: "Record"
58
+ })
59
+ );
60
+
61
+ function resolveRouteLocation(urlTemplate = "") {
62
+ const path = view.resolveParams(unref(urlTemplate));
63
+ return path ? { path, query: route.query } : null;
64
+ }
65
+
66
+ const listLocation = computed(() => resolveRouteLocation(listUrlTemplate));
67
+ const editLocation = computed(() => resolveRouteLocation(editUrlTemplate));
68
+
69
+ return Object.freeze({
70
+ view,
71
+ recordTitle,
72
+ listLocation,
73
+ editLocation
74
+ });
75
+ }
76
+
77
+ export { useCrudViewScreen };