@jskit-ai/users-web 0.1.172 → 0.1.174
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/package.json +18 -149
- package/src/client/composables/account-settings/accountSettingsAvatarUploadRuntime.js +2 -2
- package/src/client/composables/useAccountSettingsRuntime.js +3 -3
- package/src/client/index.js +0 -11
- package/test/exportsContract.test.js +3 -29
- package/test/settingsPlacementContract.test.js +10 -0
- package/fixtures/crud-list-date-filters/App.vue +0 -107
- package/fixtures/crud-list-date-filters/index.html +0 -12
- package/fixtures/crud-list-date-filters/main.js +0 -24
- package/fixtures/crud-list-date-filters/vite.config.mjs +0 -18
- package/src/client/bulkActions.js +0 -47
- package/src/client/components/CrudAddEditScreen.vue +0 -186
- package/src/client/components/CrudDeleteAction.vue +0 -93
- package/src/client/components/CrudListBulkActionSurface.vue +0 -126
- package/src/client/components/CrudListDateFilterControl.vue +0 -188
- package/src/client/components/CrudListFilterSurface.vue +0 -388
- package/src/client/components/CrudListRecordActionMenu.vue +0 -120
- package/src/client/components/CrudListScreen.vue +0 -501
- package/src/client/components/CrudViewScreen.vue +0 -197
- package/src/client/composables/crud/crudBindingSupport.js +0 -75
- package/src/client/composables/crud/crudHttpClientSupport.js +0 -57
- package/src/client/composables/crud/crudJsonApiTransportSupport.js +0 -145
- package/src/client/composables/crud/crudLookupFieldLabelSupport.js +0 -151
- package/src/client/composables/crud/crudLookupFieldRuntime.js +0 -251
- package/src/client/composables/crud/crudSchemaFormHelpers.js +0 -464
- package/src/client/composables/internal/crudListFilterLookupSupport.js +0 -161
- package/src/client/composables/internal/crudListParentTitleSupport.js +0 -171
- package/src/client/composables/internal/useOperationScope.js +0 -144
- package/src/client/composables/records/useAddEdit.js +0 -224
- package/src/client/composables/records/useCrudAddEdit.js +0 -227
- package/src/client/composables/records/useCrudList.js +0 -101
- package/src/client/composables/records/useCrudView.js +0 -47
- package/src/client/composables/records/useList.js +0 -500
- package/src/client/composables/records/useView.js +0 -164
- package/src/client/composables/runtime/addEditUiRuntime.js +0 -130
- package/src/client/composables/runtime/listUiRuntime.js +0 -123
- package/src/client/composables/runtime/modelStateHelpers.js +0 -90
- package/src/client/composables/runtime/operationAdapters.js +0 -34
- package/src/client/composables/runtime/operationUiHelpers.js +0 -125
- package/src/client/composables/runtime/operationValidationHelpers.js +0 -51
- package/src/client/composables/runtime/useAddEditCore.js +0 -112
- package/src/client/composables/runtime/useCommandCore.js +0 -123
- package/src/client/composables/runtime/useEndpointResource.js +0 -199
- package/src/client/composables/runtime/useFieldErrorBag.js +0 -61
- package/src/client/composables/runtime/useListCore.js +0 -112
- package/src/client/composables/runtime/useUiFeedback.js +0 -98
- package/src/client/composables/runtime/useViewCore.js +0 -93
- package/src/client/composables/runtime/viewUiRuntime.js +0 -96
- package/src/client/composables/support/errorMessageHelpers.js +0 -66
- package/src/client/composables/support/listQueryParamSupport.js +0 -473
- package/src/client/composables/support/listSearchSupport.js +0 -70
- package/src/client/composables/support/refValueHelpers.js +0 -19
- package/src/client/composables/support/requestQueryRuntimeSupport.js +0 -141
- package/src/client/composables/support/resourceLoadStateHelpers.js +0 -208
- package/src/client/composables/support/routeTemplateHelpers.js +0 -285
- package/src/client/composables/support/scopeHelpers.js +0 -145
- package/src/client/composables/useAccess.js +0 -109
- package/src/client/composables/useCommand.js +0 -118
- package/src/client/composables/useCrudAddEditScreen.js +0 -88
- package/src/client/composables/useCrudDeleteAction.js +0 -160
- package/src/client/composables/useCrudListBulkActions.js +0 -147
- package/src/client/composables/useCrudListFilterLookups.js +0 -146
- package/src/client/composables/useCrudListFilters.js +0 -339
- package/src/client/composables/useCrudListParentTitle.js +0 -151
- package/src/client/composables/useCrudListRowActions.js +0 -144
- package/src/client/composables/useCrudListScreen.js +0 -237
- package/src/client/composables/useCrudViewScreen.js +0 -77
- package/src/client/composables/usePagedCollection.js +0 -181
- package/src/client/composables/useRealtimeQueryInvalidation.js +0 -156
- package/src/client/composables/useScopeRuntime.js +0 -135
- package/src/client/filters.js +0 -15
- package/src/client/lib/httpClient.js +0 -47
- package/src/client/lib/permissions.js +0 -34
- package/src/client/rowActions.js +0 -47
- package/src/client/support/contractGuards.js +0 -34
- package/src/client/support/crudListDateFilterSupport.js +0 -91
- package/test/addEditUiRuntime.test.js +0 -110
- package/test/crudBindingSupport.test.js +0 -110
- package/test/crudHttpClientSupport.test.js +0 -77
- package/test/crudJsonApiTransportSupport.test.js +0 -179
- package/test/crudListBulkActionSurface.test.js +0 -27
- package/test/crudListDateFilterSupport.test.js +0 -92
- package/test/crudListDateFilterSurface.browser.test.js +0 -182
- package/test/crudListFilterSurface.test.js +0 -90
- package/test/crudLookupFieldRuntime.test.js +0 -264
- package/test/crudScreenComponents.test.js +0 -117
- package/test/errorIntentContract.test.js +0 -31
- package/test/errorMessageHelpers.test.js +0 -28
- package/test/listQueryParamSupport.test.js +0 -223
- package/test/listUiRuntime.test.js +0 -102
- package/test/operationValidationHelpers.test.js +0 -64
- package/test/permissions.test.js +0 -35
- package/test/refValueHelpers.test.js +0 -14
- package/test/requestTransportOptions.test.js +0 -457
- package/test/resourceLoadStateHelpers.test.js +0 -189
- package/test/routeTemplateHelpers.test.js +0 -85
- package/test/scopeHelpers.test.js +0 -57
- package/test/useAddEditCore.test.js +0 -124
- package/test/useAddEditRequestQueryParams.test.js +0 -190
- package/test/useCrudAddEdit.test.js +0 -415
- package/test/useCrudDeleteAction.test.js +0 -139
- package/test/useCrudListBulkActions.test.js +0 -65
- package/test/useCrudListFilterLookups.test.js +0 -114
- package/test/useCrudListFilters.test.js +0 -293
- package/test/useCrudListParentTitle.test.js +0 -262
- package/test/useCrudListRowActions.test.js +0 -77
- package/test/useListRouteInitialization.test.js +0 -337
- package/test/useListSearchSupport.test.js +0 -61
- package/test/usePagedCollection.test.js +0 -53
- package/test/useViewRequestQueryParams.test.js +0 -20
- package/test/viewCoreLoading.test.js +0 -44
- package/test/viewUiRuntime.test.js +0 -95
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
import { asPlainObject } from "../support/scopeHelpers.js";
|
|
2
|
-
import { toRouteParamValue } from "../support/routeTemplateHelpers.js";
|
|
3
|
-
|
|
4
|
-
const EMPTY_FIELD_ERROR_LIST = Object.freeze([]);
|
|
5
|
-
const fieldErrorListCache = new Map();
|
|
6
|
-
|
|
7
|
-
function resolveStableFieldErrorList(fieldKey, message) {
|
|
8
|
-
if (!message) {
|
|
9
|
-
return EMPTY_FIELD_ERROR_LIST;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const cacheKey = `${fieldKey}::${message}`;
|
|
13
|
-
if (fieldErrorListCache.has(cacheKey)) {
|
|
14
|
-
return fieldErrorListCache.get(cacheKey);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const nextValue = Object.freeze([message]);
|
|
18
|
-
fieldErrorListCache.set(cacheKey, nextValue);
|
|
19
|
-
return nextValue;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function normalizeCrudFormFields(fields = []) {
|
|
23
|
-
const normalizedFields = [];
|
|
24
|
-
const seenKeys = new Set();
|
|
25
|
-
for (const field of Array.isArray(fields) ? fields : []) {
|
|
26
|
-
const source = asPlainObject(field);
|
|
27
|
-
const key = String(source.key || "").trim();
|
|
28
|
-
if (!key || seenKeys.has(key)) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
seenKeys.add(key);
|
|
33
|
-
normalizedFields.push({
|
|
34
|
-
...source,
|
|
35
|
-
key
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return Object.freeze(normalizedFields);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function resolveFormFieldType(field = {}) {
|
|
43
|
-
return String(field.type || "").trim().toLowerCase();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function resolveFormFieldFormat(field = {}) {
|
|
47
|
-
return String(field.format || "").trim().toLowerCase();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function isNullableFormField(field = {}) {
|
|
51
|
-
return field?.nullable === true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isLookupFormField(field = {}) {
|
|
55
|
-
return field?.component === "lookup" || field?.relation?.kind === "lookup";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function padDateTimePart(value) {
|
|
59
|
-
return String(value).padStart(2, "0");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function normalizeTimeWhitespace(value) {
|
|
63
|
-
return String(value ?? "").replaceAll(/\s+/gu, " ").trim();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function toTimeInputValue(value) {
|
|
67
|
-
const normalized = normalizeTimeWhitespace(value);
|
|
68
|
-
if (!normalized) {
|
|
69
|
-
return "";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const twentyFourHourMatch = normalized.match(/^(\d{1,2}):(\d{2})(?::(\d{2})(\.\d+)?)?$/u);
|
|
73
|
-
if (twentyFourHourMatch) {
|
|
74
|
-
const hours = Number(twentyFourHourMatch[1]);
|
|
75
|
-
const minutes = Number(twentyFourHourMatch[2]);
|
|
76
|
-
const seconds = Number(twentyFourHourMatch[3] || 0);
|
|
77
|
-
if (
|
|
78
|
-
hours >= 0 && hours <= 23 &&
|
|
79
|
-
minutes >= 0 && minutes <= 59 &&
|
|
80
|
-
seconds >= 0 && seconds <= 59
|
|
81
|
-
) {
|
|
82
|
-
const secondsValue = twentyFourHourMatch[3]
|
|
83
|
-
? `:${padDateTimePart(seconds)}${twentyFourHourMatch[4] || ""}`
|
|
84
|
-
: "";
|
|
85
|
-
return `${padDateTimePart(hours)}:${padDateTimePart(minutes)}${secondsValue}`;
|
|
86
|
-
}
|
|
87
|
-
return normalized;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const meridiemMatch = normalized.match(/^(\d{1,2}):(\d{2})\s*([ap]\.?m\.?)$/iu);
|
|
91
|
-
if (!meridiemMatch) {
|
|
92
|
-
return normalized;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const rawHours = Number(meridiemMatch[1]);
|
|
96
|
-
const minutes = Number(meridiemMatch[2]);
|
|
97
|
-
if (rawHours < 1 || rawHours > 12 || minutes < 0 || minutes > 59) {
|
|
98
|
-
return normalized;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
let hours = rawHours % 12;
|
|
102
|
-
if (String(meridiemMatch[3] || "").toLowerCase().startsWith("p")) {
|
|
103
|
-
hours += 12;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return `${padDateTimePart(hours)}:${padDateTimePart(minutes)}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function toDateTimeLocalInputValue(value) {
|
|
110
|
-
if (value == null || value === "") {
|
|
111
|
-
return "";
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const sourceText = typeof value === "string" ? value.trim() : "";
|
|
115
|
-
const sourceFraction = sourceText.match(/T\d{2}:\d{2}:\d{2}\.(\d+)/u)?.[1] || "";
|
|
116
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
117
|
-
if (Number.isNaN(date.getTime())) {
|
|
118
|
-
return String(value);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const minuteValue = [
|
|
122
|
-
date.getFullYear(),
|
|
123
|
-
padDateTimePart(date.getMonth() + 1),
|
|
124
|
-
padDateTimePart(date.getDate())
|
|
125
|
-
].join("-") + `T${padDateTimePart(date.getHours())}:${padDateTimePart(date.getMinutes())}`;
|
|
126
|
-
if (sourceFraction && !/^0+$/u.test(sourceFraction)) {
|
|
127
|
-
return `${minuteValue}:${padDateTimePart(date.getSeconds())}.${sourceFraction}`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const milliseconds = date.getMilliseconds();
|
|
131
|
-
if (milliseconds > 0) {
|
|
132
|
-
return `${minuteValue}:${padDateTimePart(date.getSeconds())}.${String(milliseconds).padStart(3, "0")}`;
|
|
133
|
-
}
|
|
134
|
-
if (date.getSeconds() > 0) {
|
|
135
|
-
return `${minuteValue}:${padDateTimePart(date.getSeconds())}`;
|
|
136
|
-
}
|
|
137
|
-
return minuteValue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function toDateInputValue(value) {
|
|
141
|
-
if (value == null || value === "") {
|
|
142
|
-
return "";
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (value instanceof Date) {
|
|
146
|
-
return Number.isNaN(value.getTime())
|
|
147
|
-
? String(value)
|
|
148
|
-
: value.toISOString().slice(0, 10);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const normalized = String(value).trim();
|
|
152
|
-
if (!normalized) {
|
|
153
|
-
return "";
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const calendarDateMatch = normalized.match(/^(\d{4}-\d{2}-\d{2})(?:$|[T\s])/u);
|
|
157
|
-
if (calendarDateMatch) {
|
|
158
|
-
const calendarDate = calendarDateMatch[1];
|
|
159
|
-
const parsedCalendarDate = new Date(`${calendarDate}T00:00:00.000Z`);
|
|
160
|
-
if (
|
|
161
|
-
!Number.isNaN(parsedCalendarDate.getTime()) &&
|
|
162
|
-
parsedCalendarDate.toISOString().slice(0, 10) === calendarDate
|
|
163
|
-
) {
|
|
164
|
-
return calendarDate;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return normalized;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function applyDateTimePrecision(isoValue, temporalPrecision) {
|
|
172
|
-
if (!Number.isInteger(temporalPrecision) || temporalPrecision < 0) {
|
|
173
|
-
return isoValue;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const match = String(isoValue || "").match(/^(.*?)(?:\.(\d+))?Z$/u);
|
|
177
|
-
if (!match?.[2]) {
|
|
178
|
-
return isoValue;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const fraction = match[2];
|
|
182
|
-
if (fraction.length <= temporalPrecision) {
|
|
183
|
-
return isoValue;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const excess = fraction.slice(temporalPrecision);
|
|
187
|
-
if (!/^0+$/u.test(excess)) {
|
|
188
|
-
return isoValue;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const retained = fraction.slice(0, temporalPrecision);
|
|
192
|
-
return `${match[1]}${retained ? `.${retained}` : ""}Z`;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function toIsoUtcDateTimeValue(value, temporalPrecision) {
|
|
196
|
-
const normalized = String(value ?? "").trim();
|
|
197
|
-
if (!normalized) {
|
|
198
|
-
return "";
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const date = new Date(normalized);
|
|
202
|
-
if (Number.isNaN(date.getTime())) {
|
|
203
|
-
return normalized;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const sourceFraction = normalized.match(/T\d{2}:\d{2}:\d{2}\.(\d+)/u)?.[1] || "";
|
|
207
|
-
const dateIsoValue = date.toISOString();
|
|
208
|
-
const preciseIsoValue = sourceFraction
|
|
209
|
-
? dateIsoValue.replace(/\.\d{3}Z$/u, `.${sourceFraction}Z`)
|
|
210
|
-
: dateIsoValue;
|
|
211
|
-
return applyDateTimePrecision(preciseIsoValue, temporalPrecision);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function resolveFormFieldInitialValue(field = {}) {
|
|
215
|
-
if (Object.prototype.hasOwnProperty.call(field, "initialValue")) {
|
|
216
|
-
return field.initialValue;
|
|
217
|
-
}
|
|
218
|
-
if (Object.prototype.hasOwnProperty.call(field, "defaultValue")) {
|
|
219
|
-
return field.defaultValue;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const fieldType = resolveFormFieldType(field);
|
|
223
|
-
if (fieldType === "boolean") {
|
|
224
|
-
return isNullableFormField(field) ? null : false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (isNullableFormField(field) && isLookupFormField(field)) {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return "";
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function shouldSerializeClearedFieldAsNull(field = {}) {
|
|
235
|
-
if (field?.nullable !== true) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (isLookupFormField(field)) {
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const fieldType = resolveFormFieldType(field);
|
|
244
|
-
const fieldFormat = resolveFormFieldFormat(field);
|
|
245
|
-
|
|
246
|
-
return (
|
|
247
|
-
fieldType === "integer" ||
|
|
248
|
-
fieldType === "number" ||
|
|
249
|
-
fieldFormat === "date" ||
|
|
250
|
-
fieldFormat === "date-time" ||
|
|
251
|
-
fieldFormat === "time"
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function createCrudFormModel(fields = []) {
|
|
256
|
-
const model = {};
|
|
257
|
-
for (const field of normalizeCrudFormFields(fields)) {
|
|
258
|
-
model[field.key] = resolveFormFieldInitialValue(field);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return model;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function buildCrudFormPayload(fields = [], model = {}) {
|
|
265
|
-
const payload = {};
|
|
266
|
-
const sourceModel = asPlainObject(model);
|
|
267
|
-
|
|
268
|
-
for (const field of normalizeCrudFormFields(fields)) {
|
|
269
|
-
const fieldKey = field.key;
|
|
270
|
-
const fieldType = resolveFormFieldType(field);
|
|
271
|
-
const fieldFormat = resolveFormFieldFormat(field);
|
|
272
|
-
const clearAsNull = shouldSerializeClearedFieldAsNull(field);
|
|
273
|
-
const rawValue = sourceModel[fieldKey];
|
|
274
|
-
|
|
275
|
-
if (fieldType === "boolean") {
|
|
276
|
-
payload[fieldKey] = rawValue == null && isNullableFormField(field)
|
|
277
|
-
? null
|
|
278
|
-
: Boolean(rawValue);
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (fieldType === "integer" || fieldType === "number") {
|
|
283
|
-
const normalizedValue = String(rawValue ?? "").trim();
|
|
284
|
-
if (!normalizedValue) {
|
|
285
|
-
if (clearAsNull) {
|
|
286
|
-
payload[fieldKey] = null;
|
|
287
|
-
}
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const parsedNumber = Number(normalizedValue);
|
|
292
|
-
payload[fieldKey] = Number.isFinite(parsedNumber)
|
|
293
|
-
? (fieldType === "integer" ? Math.trunc(parsedNumber) : parsedNumber)
|
|
294
|
-
: rawValue;
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (rawValue == null) {
|
|
299
|
-
if (clearAsNull) {
|
|
300
|
-
payload[fieldKey] = null;
|
|
301
|
-
}
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (isLookupFormField(field)) {
|
|
306
|
-
const normalizedLookupValue = String(rawValue).trim();
|
|
307
|
-
if (!normalizedLookupValue) {
|
|
308
|
-
if (clearAsNull) {
|
|
309
|
-
payload[fieldKey] = null;
|
|
310
|
-
}
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
payload[fieldKey] = normalizedLookupValue;
|
|
315
|
-
continue;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (fieldFormat === "date") {
|
|
319
|
-
const normalizedValue = String(rawValue).trim();
|
|
320
|
-
if (!normalizedValue) {
|
|
321
|
-
if (clearAsNull) {
|
|
322
|
-
payload[fieldKey] = null;
|
|
323
|
-
}
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
payload[fieldKey] = normalizedValue;
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (fieldFormat === "date-time") {
|
|
332
|
-
const normalizedValue = toIsoUtcDateTimeValue(rawValue, field.temporalPrecision);
|
|
333
|
-
if (!normalizedValue) {
|
|
334
|
-
if (clearAsNull) {
|
|
335
|
-
payload[fieldKey] = null;
|
|
336
|
-
}
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
payload[fieldKey] = normalizedValue;
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (fieldFormat === "time") {
|
|
345
|
-
const normalizedValue = toTimeInputValue(rawValue);
|
|
346
|
-
if (!normalizedValue) {
|
|
347
|
-
if (clearAsNull) {
|
|
348
|
-
payload[fieldKey] = null;
|
|
349
|
-
}
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
payload[fieldKey] = normalizedValue;
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
payload[fieldKey] = rawValue;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
return payload;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function applyCrudPayloadToForm(fields = [], model = {}, payload = {}) {
|
|
364
|
-
const targetModel = asPlainObject(model);
|
|
365
|
-
const sourcePayload = asPlainObject(payload);
|
|
366
|
-
for (const field of normalizeCrudFormFields(fields)) {
|
|
367
|
-
const fieldKey = field.key;
|
|
368
|
-
const fieldType = resolveFormFieldType(field);
|
|
369
|
-
const fieldFormat = resolveFormFieldFormat(field);
|
|
370
|
-
const rawValue = sourcePayload[fieldKey];
|
|
371
|
-
|
|
372
|
-
if (fieldType === "boolean") {
|
|
373
|
-
targetModel[fieldKey] = rawValue == null && isNullableFormField(field)
|
|
374
|
-
? null
|
|
375
|
-
: Boolean(rawValue);
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (fieldType === "integer" || fieldType === "number") {
|
|
380
|
-
targetModel[fieldKey] = rawValue == null ? "" : String(rawValue);
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (fieldFormat === "date") {
|
|
385
|
-
targetModel[fieldKey] = toDateInputValue(rawValue);
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (fieldFormat === "date-time") {
|
|
390
|
-
targetModel[fieldKey] = toDateTimeLocalInputValue(rawValue);
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
if (fieldFormat === "time") {
|
|
395
|
-
targetModel[fieldKey] = toTimeInputValue(rawValue);
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (isLookupFormField(field)) {
|
|
400
|
-
targetModel[fieldKey] = rawValue == null ? null : String(rawValue);
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
targetModel[fieldKey] = rawValue == null ? "" : String(rawValue);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
function resolveCrudRouteBoundFieldValues(fields = [], routeParams = {}) {
|
|
409
|
-
const sourceRouteParams = asPlainObject(routeParams);
|
|
410
|
-
const values = {};
|
|
411
|
-
|
|
412
|
-
for (const field of normalizeCrudFormFields(fields)) {
|
|
413
|
-
const routeParamKey = String(field?.routeParamKey || "").trim();
|
|
414
|
-
if (!routeParamKey) {
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
if (!Object.prototype.hasOwnProperty.call(sourceRouteParams, routeParamKey)) {
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const routeValue = toRouteParamValue(sourceRouteParams[routeParamKey]);
|
|
422
|
-
if (!routeValue) {
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
values[field.key] = routeValue;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return values;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function applyCrudRouteBoundFieldValues(fields = [], target = {}, routeParams = {}) {
|
|
432
|
-
const resolved = resolveCrudRouteBoundFieldValues(fields, routeParams);
|
|
433
|
-
const destination = asPlainObject(target);
|
|
434
|
-
for (const [key, value] of Object.entries(resolved)) {
|
|
435
|
-
destination[key] = value;
|
|
436
|
-
}
|
|
437
|
-
return resolved;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function resolveCrudFieldErrors(fieldErrors = {}, fieldKey = "") {
|
|
441
|
-
const key = String(fieldKey || "").trim();
|
|
442
|
-
if (!key) {
|
|
443
|
-
return [];
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
const source = asPlainObject(fieldErrors);
|
|
447
|
-
const message = String(source[key] || "").trim();
|
|
448
|
-
|
|
449
|
-
if (!message) {
|
|
450
|
-
return resolveStableFieldErrorList(key, "");
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return resolveStableFieldErrorList(key, message);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export {
|
|
457
|
-
normalizeCrudFormFields,
|
|
458
|
-
createCrudFormModel,
|
|
459
|
-
buildCrudFormPayload,
|
|
460
|
-
applyCrudPayloadToForm,
|
|
461
|
-
resolveCrudRouteBoundFieldValues,
|
|
462
|
-
applyCrudRouteBoundFieldValues,
|
|
463
|
-
resolveCrudFieldErrors
|
|
464
|
-
};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { normalizeText, normalizeUniqueTextList } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
-
import { resolveLookupItemLabel } from "../crud/crudLookupFieldLabelSupport.js";
|
|
3
|
-
import { asPlainObject } from "../support/scopeHelpers.js";
|
|
4
|
-
|
|
5
|
-
function normalizeLookupQueryKeyPrefix(value = []) {
|
|
6
|
-
const source = Array.isArray(value) ? value : [];
|
|
7
|
-
return Object.freeze(
|
|
8
|
-
source
|
|
9
|
-
.map((entry) => normalizeText(entry))
|
|
10
|
-
.filter(Boolean)
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function normalizeLookupLabelResolverMap(value = {}) {
|
|
15
|
-
const source = value && typeof value === "object" && !Array.isArray(value)
|
|
16
|
-
? value
|
|
17
|
-
: {};
|
|
18
|
-
const normalized = {};
|
|
19
|
-
|
|
20
|
-
for (const [key, entry] of Object.entries(source)) {
|
|
21
|
-
const normalizedKey = normalizeText(key);
|
|
22
|
-
if (!normalizedKey || typeof entry !== "function") {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
normalized[normalizedKey] = entry;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return Object.freeze(normalized);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function normalizeLookupRequestQueryParamsMap(value = {}) {
|
|
33
|
-
const source = value && typeof value === "object" && !Array.isArray(value)
|
|
34
|
-
? value
|
|
35
|
-
: {};
|
|
36
|
-
const normalized = {};
|
|
37
|
-
|
|
38
|
-
for (const [key, entry] of Object.entries(source)) {
|
|
39
|
-
const normalizedKey = normalizeText(key);
|
|
40
|
-
if (!normalizedKey) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (entry == null) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (typeof entry === "function") {
|
|
47
|
-
normalized[normalizedKey] = entry;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (typeof entry !== "object" || Array.isArray(entry)) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
normalized[normalizedKey] = asPlainObject(entry);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return Object.freeze(normalized);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function resolveLookupSelectedValues(filter = {}, rawValue = undefined) {
|
|
61
|
-
if (filter?.type === "recordIdMany") {
|
|
62
|
-
return normalizeUniqueTextList(rawValue, {
|
|
63
|
-
acceptSingle: true
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const normalizedValue = normalizeText(rawValue);
|
|
68
|
-
return normalizedValue ? Object.freeze([normalizedValue]) : Object.freeze([]);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function createLookupOptionFromItem(item = {}, filter = {}, labelResolver = null) {
|
|
72
|
-
const sourceRecord = asPlainObject(item);
|
|
73
|
-
const valueKey = normalizeText(filter?.lookup?.valueKey) || "id";
|
|
74
|
-
const labelKey = normalizeText(filter?.lookup?.labelKey);
|
|
75
|
-
const value = normalizeText(sourceRecord[valueKey]);
|
|
76
|
-
if (!value) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const customLabel = typeof labelResolver === "function"
|
|
81
|
-
? normalizeText(labelResolver(sourceRecord, filter))
|
|
82
|
-
: "";
|
|
83
|
-
const fallbackLabel = resolveLookupItemLabel(sourceRecord, labelKey) || value;
|
|
84
|
-
|
|
85
|
-
return Object.freeze({
|
|
86
|
-
value,
|
|
87
|
-
label: customLabel || String(fallbackLabel || value),
|
|
88
|
-
record: sourceRecord
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function createLookupOptionsFromItems(items = [], filter = {}, labelResolver = null) {
|
|
93
|
-
const optionMap = new Map();
|
|
94
|
-
for (const item of Array.isArray(items) ? items : []) {
|
|
95
|
-
const option = createLookupOptionFromItem(item, filter, labelResolver);
|
|
96
|
-
if (!option || optionMap.has(option.value)) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
optionMap.set(option.value, option);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return Object.freeze([...optionMap.values()]);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function mergeSelectedLookupOptions(options = [], selectedValues = [], cachedOptions = new Map()) {
|
|
107
|
-
const optionMap = new Map(
|
|
108
|
-
(Array.isArray(options) ? options : []).map((option) => [normalizeText(option?.value), option])
|
|
109
|
-
);
|
|
110
|
-
const normalizedCache = cachedOptions instanceof Map ? cachedOptions : new Map();
|
|
111
|
-
|
|
112
|
-
for (const value of Array.isArray(selectedValues) ? selectedValues : []) {
|
|
113
|
-
const normalizedValue = normalizeText(value);
|
|
114
|
-
if (!normalizedValue || optionMap.has(normalizedValue)) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const cachedOption = normalizedCache.get(normalizedValue);
|
|
119
|
-
if (cachedOption) {
|
|
120
|
-
optionMap.set(normalizedValue, cachedOption);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return Object.freeze(
|
|
125
|
-
[...optionMap.values()].sort((left, right) => {
|
|
126
|
-
return String(left?.label || "").localeCompare(String(right?.label || ""));
|
|
127
|
-
})
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function resolveLookupOptionLabel(options = [], cachedOptions = new Map(), value = "", fallback = "Option") {
|
|
132
|
-
const normalizedValue = normalizeText(value);
|
|
133
|
-
if (!normalizedValue) {
|
|
134
|
-
return normalizeText(fallback) || "Option";
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const matchingOption = (Array.isArray(options) ? options : [])
|
|
138
|
-
.find((option) => normalizeText(option?.value) === normalizedValue);
|
|
139
|
-
if (matchingOption?.label) {
|
|
140
|
-
return String(matchingOption.label);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const normalizedCache = cachedOptions instanceof Map ? cachedOptions : new Map();
|
|
144
|
-
const cachedOption = normalizedCache.get(normalizedValue);
|
|
145
|
-
if (cachedOption?.label) {
|
|
146
|
-
return String(cachedOption.label);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const normalizedFallback = normalizeText(fallback) || "Option";
|
|
150
|
-
return `${normalizedFallback} ${normalizedValue}`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export {
|
|
154
|
-
normalizeLookupQueryKeyPrefix,
|
|
155
|
-
normalizeLookupLabelResolverMap,
|
|
156
|
-
normalizeLookupRequestQueryParamsMap,
|
|
157
|
-
resolveLookupSelectedValues,
|
|
158
|
-
createLookupOptionsFromItems,
|
|
159
|
-
mergeSelectedLookupOptions,
|
|
160
|
-
resolveLookupOptionLabel
|
|
161
|
-
};
|