@selfhelp/shared 1.23.0 → 1.25.0

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 (37) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/dist/index.d.mts +300 -100
  3. package/dist/index.d.ts +300 -100
  4. package/dist/index.js +531 -3
  5. package/dist/index.mjs +506 -3
  6. package/dist/plugin-sdk/index.d.mts +1 -1
  7. package/dist/plugin-sdk/index.d.ts +1 -1
  8. package/dist/plugin-sdk/index.js +7 -1
  9. package/dist/plugin-sdk/index.mjs +7 -1
  10. package/dist/registry/index.d.mts +2 -2
  11. package/dist/registry/index.d.ts +2 -2
  12. package/dist/registry/index.js +15 -1
  13. package/dist/registry/index.mjs +14 -1
  14. package/dist/{styles.registry-BBd9T2Ox.d.ts → styles.registry-C2ACy7H0.d.ts} +734 -2
  15. package/dist/{styles.registry-IjDTff8P.d.mts → styles.registry-DnIJqEzM.d.mts} +734 -2
  16. package/package.json +1 -1
  17. package/src/api/__tests__/endpoints.test.ts +45 -0
  18. package/src/api/__tests__/formListErrors.test.ts +143 -0
  19. package/src/api/endpoints.ts +41 -0
  20. package/src/api/formListErrors.ts +134 -0
  21. package/src/api/index.ts +1 -0
  22. package/src/content/__tests__/formListState.test.ts +448 -0
  23. package/src/content/__tests__/formRecordPrefill.test.ts +120 -0
  24. package/src/content/formListState.ts +559 -0
  25. package/src/content/formRecordPrefill.ts +108 -5
  26. package/src/content/index.ts +1 -0
  27. package/src/registry/__tests__/platform.test.ts +15 -6
  28. package/src/registry/__tests__/registry.test.ts +14 -0
  29. package/src/registry/styles.registry.ts +23 -0
  30. package/src/types/api/__tests__/formWrites.test.ts +84 -0
  31. package/src/types/api/form-lists.ts +475 -0
  32. package/src/types/api/forms.ts +149 -4
  33. package/src/types/api/index.ts +1 -0
  34. package/src/types/styles/__tests__/entryFormListFormFields.test.ts +44 -0
  35. package/src/types/styles/composite.ts +13 -0
  36. package/src/types/styles/forms.ts +124 -0
  37. package/src/types/styles/unknown.ts +5 -1
package/dist/index.js CHANGED
@@ -50,7 +50,16 @@ __export(index_exports, {
50
50
  ENDPOINTS: () => ENDPOINTS,
51
51
  FIELDS_MAP_STYLE_CONFIG: () => FIELDS_MAP_STYLE_CONFIG,
52
52
  FONT_SIZE_PX: () => FONT_SIZE_PX,
53
+ FORM_LIST_MAX_PAGE: () => FORM_LIST_MAX_PAGE,
54
+ FORM_LIST_MAX_ROUTE_PARAMS: () => FORM_LIST_MAX_ROUTE_PARAMS,
55
+ FORM_LIST_MAX_ROUTE_VALUE_LENGTH: () => FORM_LIST_MAX_ROUTE_VALUE_LENGTH,
56
+ FORM_LIST_MAX_SORTS: () => FORM_LIST_MAX_SORTS,
57
+ FORM_LIST_MAX_VALUE_BYTES: () => FORM_LIST_MAX_VALUE_BYTES,
58
+ FORM_LIST_MODES: () => FORM_LIST_MODES,
59
+ FORM_LIST_SEARCH_MAX_LENGTH: () => FORM_LIST_SEARCH_MAX_LENGTH,
60
+ FORM_LIST_SEARCH_MIN_LENGTH: () => FORM_LIST_SEARCH_MIN_LENGTH,
53
61
  FORM_RECORD_PREFILL_SKIP_FIELDS: () => FORM_RECORD_PREFILL_SKIP_FIELDS,
62
+ FORM_SECTION_STYLE_NAMES: () => FORM_SECTION_STYLE_NAMES,
54
63
  FULL_RADIUS_PX: () => FULL_RADIUS_PX,
55
64
  HEADER_CLIENT_TYPE: () => HEADER_CLIENT_TYPE,
56
65
  LINE_HEIGHT: () => LINE_HEIGHT,
@@ -80,7 +89,10 @@ __export(index_exports, {
80
89
  WEB_HEADER_PRESET_OPTIONS: () => WEB_HEADER_PRESET_OPTIONS,
81
90
  WEB_HEADER_PRESET_VALUES: () => WEB_HEADER_PRESET_VALUES,
82
91
  _resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
92
+ applyFormListUrlChange: () => applyFormListUrlChange,
83
93
  arePreviewPreferencesEqual: () => arePreviewPreferencesEqual,
94
+ asFilesCell: () => asFilesCell,
95
+ asRecordVersion: () => asRecordVersion,
84
96
  buildConditionContext: () => buildConditionContext,
85
97
  buildPagesResolvePath: () => buildPagesResolvePath,
86
98
  buildPagesResolveQuery: () => buildPagesResolveQuery,
@@ -91,6 +103,8 @@ __export(index_exports, {
91
103
  classifyClassString: () => classifyClassString,
92
104
  collectPageIdsFromMenuItems: () => collectPageIdsFromMenuItems,
93
105
  colorToHex: () => colorToHex,
106
+ emptyFormListUrlState: () => emptyFormListUrlState,
107
+ encodeFormListQuery: () => encodeFormListQuery,
94
108
  evaluateCondition: () => evaluateCondition,
95
109
  expandedIdsForActiveTrail: () => expandedIdsForActiveTrail,
96
110
  extendStyleRegistry: () => extendStyleRegistry,
@@ -105,7 +119,14 @@ __export(index_exports, {
105
119
  footerColumnItems: () => footerColumnItems,
106
120
  footerGroupLinks: () => footerGroupLinks,
107
121
  footerStandaloneItems: () => footerStandaloneItems,
122
+ formListCacheKey: () => formListCacheKey,
123
+ formListQueryString: () => formListQueryString,
124
+ formListRouteQuery: () => formListRouteQuery,
108
125
  formatRateLimitMessage: () => formatRateLimitMessage,
126
+ getFormInvalidData: () => getFormInvalidData,
127
+ getFormListFailure: () => getFormListFailure,
128
+ getFormListRestoreBlocked: () => getFormListRestoreBlocked,
129
+ getFormStaleVersion: () => getFormStaleVersion,
109
130
  getMergedStyleRegistry: () => getMergedStyleRegistry,
110
131
  getNavigationItemAriaLabel: () => getNavigationItemAriaLabel,
111
132
  getNavigationItemHref: () => getNavigationItemHref,
@@ -123,6 +144,7 @@ __export(index_exports, {
123
144
  hasInlineFormatting: () => hasInlineFormatting,
124
145
  isBottomTabMenuItemActive: () => isBottomTabMenuItemActive,
125
146
  isDoubleWebHeaderPreset: () => isDoubleWebHeaderPreset,
147
+ isFormListParam: () => isFormListParam,
126
148
  isKnownStyleName: () => isKnownStyleName,
127
149
  isMenuItemActiveOnMobile: () => isMenuItemActiveOnMobile,
128
150
  isMenuItemActiveOnWeb: () => isMenuItemActiveOnWeb,
@@ -156,18 +178,21 @@ __export(index_exports, {
156
178
  matchesMobilePath: () => matchesMobilePath,
157
179
  matchesWebPath: () => matchesWebPath,
158
180
  mergeHeaderLayers: () => mergeHeaderLayers,
181
+ nextSortOnHeaderClick: () => nextSortOnHeaderClick,
159
182
  normalizePagesResolvePath: () => normalizePagesResolvePath,
160
183
  pageUrlToMobileRoute: () => pageUrlToMobileRoute,
161
184
  parseDimensionToReactNative: () => parseDimensionToReactNative,
162
185
  parseDimensionToWeb: () => parseDimensionToWeb,
163
186
  parseFieldsMapCatalog: () => parseFieldsMapCatalog,
164
187
  parseFieldsMapLabels: () => parseFieldsMapLabels,
188
+ parseFormListQuery: () => parseFormListQuery,
165
189
  parseFormRecordPrefill: () => parseFormRecordPrefill,
166
190
  parseInlineRich: () => parseInlineRich,
167
191
  parseOptionCatalog: () => parseOptionCatalog,
168
192
  parseOptionCodes: () => parseOptionCodes,
169
193
  parseOptionLabels: () => parseOptionLabels,
170
194
  parseSpacing: () => parseSpacing,
195
+ pickFormListQuery: () => pickFormListQuery,
171
196
  previewKeywordFromPath: () => previewKeywordFromPath,
172
197
  radiusToPx: () => radiusToPx,
173
198
  replaceCalcedValues: () => replaceCalcedValues,
@@ -490,8 +515,20 @@ var BASE_STYLE_REGISTRY = {
490
515
  version: { description: "Build/version diagnostic surface", category: "auth", canHaveChildren: false },
491
516
  "ref-container": { description: "Renders content referenced from another section", category: "layout", canHaveChildren: true },
492
517
  "data-container": { description: "Data-scoped container (renders subtree against a data scope)", category: "layout", canHaveChildren: true },
493
- "entry-table": { description: "Built-in admin CRUD grid over a form's records (search/sort/paginate/CSV, add / edit / delete actions)", category: "forms", canHaveChildren: false }
518
+ "entry-table": { description: "Built-in admin CRUD grid over a form's records (search/sort/paginate/CSV, add / edit / delete actions)", category: "forms", canHaveChildren: false },
519
+ "entry-form-list": {
520
+ description: "Entry List with Form: a list of records that is also the form that creates and edits them (put the inputs directly inside it); supports search, sort, filters, paging, quick actions and history",
521
+ category: "forms",
522
+ canHaveChildren: true
523
+ },
524
+ "data-view": { description: "Read-only server-rendered table, cards or your own layout (sections placed inside, drawn once per record) of records of a data table", category: "forms", canHaveChildren: true }
494
525
  };
526
+ var FORM_SECTION_STYLE_NAMES = [
527
+ "form-record",
528
+ "form-log",
529
+ "entry-record-form",
530
+ "entry-form-list"
531
+ ];
495
532
  var STYLE_REGISTRY = BASE_STYLE_REGISTRY;
496
533
  var PLUGIN_STYLE_REGISTRY = {};
497
534
  var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
@@ -654,6 +691,35 @@ var ENDPOINTS = {
654
691
  SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
655
692
  UPDATE: `${API_VERSION_PREFIX}/forms/update`,
656
693
  DELETE: `${API_VERSION_PREFIX}/forms/delete`
694
+ },
695
+ /**
696
+ * `entry-form-list` / `data-view` lists. A list never has its own create,
697
+ * update or delete route: writes go through {@link ENDPOINTS.FORMS}. The
698
+ * first paint reads `list_state` from the page payload; these routes serve
699
+ * the interactions after it. Path segments are numeric ids, except the
700
+ * action id and the field key, which are encoded.
701
+ */
702
+ LISTS: {
703
+ STATE: (sectionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/state`,
704
+ QUICK_ACTION: (sectionId, recordId, actionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/actions/${encodeURIComponent(actionId)}`,
705
+ HISTORY: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/history`,
706
+ VERSION: (sectionId, recordId, version) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}`,
707
+ COMPARE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/compare`,
708
+ RESTORE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/restore`,
709
+ VERSION_FILE: (sectionId, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`,
710
+ /** Current file of a record shown by a list / data-view / entry-record (F165). */
711
+ CURRENT_FILE: (sectionId, recordId, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/files/${encodeURIComponent(fieldKey)}`
712
+ },
713
+ /**
714
+ * Admin data-browser record history (contract 6). Route permission
715
+ * `admin.data.read`; the controller also requires table UPDATE.
716
+ */
717
+ ADMIN_DATA_HISTORY: {
718
+ HISTORY: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/history`,
719
+ VERSION: (tableName, recordId, version) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}`,
720
+ COMPARE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/compare`,
721
+ RESTORE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/restore`,
722
+ VERSION_FILE: (tableName, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`
657
723
  }
658
724
  };
659
725
  var HEADER_CLIENT_TYPE = "X-Client-Type";
@@ -661,6 +727,73 @@ var CLIENT_TYPE_WEB = "web";
661
727
  var CLIENT_TYPE_MOBILE = "mobile";
662
728
  var CLIENT_TYPE_MOBILE_AND_WEB = "mobile_and_web";
663
729
 
730
+ // src/api/formListErrors.ts
731
+ function envelope(error) {
732
+ const response = error?.response;
733
+ const status = response?.status;
734
+ const data = response?.data?.data;
735
+ if (typeof status !== "number" || typeof data !== "object" || data === null || Array.isArray(data)) {
736
+ return null;
737
+ }
738
+ return { status, message: response?.data?.message, data };
739
+ }
740
+ function getFormStaleVersion(error) {
741
+ const found = envelope(error);
742
+ if (found === null || found.status !== 409 || found.data.reason !== "stale_version") {
743
+ return null;
744
+ }
745
+ const { record_id: recordId, expected_version: expected, current_version: current } = found.data;
746
+ if (typeof recordId !== "number" || typeof expected !== "number" || typeof current !== "number") {
747
+ return null;
748
+ }
749
+ return { reason: "stale_version", record_id: recordId, expected_version: expected, current_version: current };
750
+ }
751
+ function getFormListRestoreBlocked(error) {
752
+ const found = envelope(error);
753
+ if (found === null || found.status !== 422 || found.data.reason !== "restore_blocked") {
754
+ return null;
755
+ }
756
+ const { record_id: recordId, from_version: fromVersion, blockers } = found.data;
757
+ if (typeof recordId !== "number" || typeof fromVersion !== "number" || !Array.isArray(blockers)) {
758
+ return null;
759
+ }
760
+ return {
761
+ reason: "restore_blocked",
762
+ record_id: recordId,
763
+ from_version: fromVersion,
764
+ blockers
765
+ };
766
+ }
767
+ function getFormInvalidData(error) {
768
+ const found = envelope(error);
769
+ if (found === null || found.status !== 422 || found.data.reason !== "invalid_form_data" || !Array.isArray(found.data.errors)) {
770
+ return null;
771
+ }
772
+ const errors = [];
773
+ for (const entry of found.data.errors) {
774
+ if (typeof entry !== "object" || entry === null) {
775
+ continue;
776
+ }
777
+ const { field, key, rule, message } = entry;
778
+ if (typeof field === "string" && typeof key === "string" && typeof rule === "string" && typeof message === "string") {
779
+ errors.push({ field, key, rule, message });
780
+ }
781
+ }
782
+ return errors.length > 0 ? { reason: "invalid_form_data", errors } : null;
783
+ }
784
+ function getFormListFailure(error) {
785
+ const found = envelope(error);
786
+ if (found === null || typeof found.data.reason !== "string" || found.data.reason === "") {
787
+ return null;
788
+ }
789
+ return {
790
+ status: found.status,
791
+ reason: found.data.reason,
792
+ parameter: typeof found.data.parameter === "string" && found.data.parameter !== "" ? found.data.parameter : null,
793
+ message: typeof found.message === "string" ? found.message : null
794
+ };
795
+ }
796
+
664
797
  // src/api/pagesResolve.ts
665
798
  function normalizePagesResolvePath(rawPath) {
666
799
  const withoutOrigin = rawPath.includes("://") ? (() => {
@@ -1878,10 +2011,12 @@ function serializeFieldsMapLabels(labels) {
1878
2011
  // src/content/formRecordPrefill.ts
1879
2012
  var FORM_RECORD_PREFILL_SKIP_FIELDS = /* @__PURE__ */ new Set([
1880
2013
  "record_id",
2014
+ "_version",
1881
2015
  "entry_date",
1882
2016
  "id_users",
1883
2017
  "user_name",
1884
2018
  "user_code",
2019
+ "id_action_trigger_types",
1885
2020
  "id_actionTriggerTypes",
1886
2021
  "triggerType",
1887
2022
  "id_languages",
@@ -1904,12 +2039,45 @@ function asScalarString(value) {
1904
2039
  }
1905
2040
  return null;
1906
2041
  }
2042
+ function asFilesCell(value) {
2043
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
2044
+ return null;
2045
+ }
2046
+ const files = value.files;
2047
+ if (!Array.isArray(files)) {
2048
+ return null;
2049
+ }
2050
+ const out = [];
2051
+ for (const entry of files) {
2052
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
2053
+ continue;
2054
+ }
2055
+ const file = entry;
2056
+ const index = typeof file.index === "number" ? file.index : Number(file.index);
2057
+ const name = typeof file.name === "string" ? file.name : null;
2058
+ const url = typeof file.url === "string" ? file.url : null;
2059
+ if (!Number.isFinite(index) || name === null || url === null) {
2060
+ continue;
2061
+ }
2062
+ const mime = typeof file.mime === "string" ? file.mime : file.mime === null ? null : void 0;
2063
+ const size = typeof file.size === "number" ? file.size : file.size === null ? null : typeof file.size === "string" && Number.isFinite(Number(file.size)) ? Number(file.size) : void 0;
2064
+ out.push({
2065
+ index: Math.trunc(index),
2066
+ name,
2067
+ url,
2068
+ ...mime !== void 0 ? { mime } : {},
2069
+ ...size !== void 0 ? { size } : {}
2070
+ });
2071
+ }
2072
+ return { files: out };
2073
+ }
1907
2074
  function parseFormRecordPrefill(section) {
1908
2075
  const sectionDataArray = section?.section_data;
1909
2076
  if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
1910
2077
  return { recordId: null, values: {} };
1911
2078
  }
1912
2079
  const recordGroups = {};
2080
+ const recordVersions = {};
1913
2081
  for (const row of sectionDataArray) {
1914
2082
  if (!row || typeof row !== "object" || Array.isArray(row)) {
1915
2083
  continue;
@@ -1923,11 +2091,22 @@ function parseFormRecordPrefill(section) {
1923
2091
  if (!recordGroups[recordId]) {
1924
2092
  recordGroups[recordId] = {};
1925
2093
  }
2094
+ const version2 = asRecordVersion(record._version);
2095
+ if (version2 !== null && recordVersions[recordId] === void 0) {
2096
+ recordVersions[recordId] = version2;
2097
+ }
1926
2098
  const languageId = typeof record.id_languages === "number" ? record.id_languages : typeof record.id_languages === "string" && Number.isFinite(Number(record.id_languages)) ? Number(record.id_languages) : void 0;
1927
2099
  for (const [fieldName, fieldValue] of Object.entries(record)) {
1928
2100
  if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
1929
2101
  continue;
1930
2102
  }
2103
+ const filesCell = asFilesCell(fieldValue);
2104
+ if (filesCell !== null) {
2105
+ if (languageId === 1 || !recordGroups[recordId][fieldName]) {
2106
+ recordGroups[recordId][fieldName] = filesCell;
2107
+ }
2108
+ continue;
2109
+ }
1931
2110
  const value = asScalarString(fieldValue);
1932
2111
  if (value === null) {
1933
2112
  continue;
@@ -1940,7 +2119,10 @@ function parseFormRecordPrefill(section) {
1940
2119
  }
1941
2120
  } else if (typeof languageId === "number") {
1942
2121
  const current = recordGroups[recordId][fieldName];
1943
- if (typeof current === "string" || !current) {
2122
+ if (typeof current === "string" || Array.isArray(current) === false || !current) {
2123
+ if (typeof current === "object" && current !== null && "files" in current) {
2124
+ continue;
2125
+ }
1944
2126
  recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
1945
2127
  } else {
1946
2128
  const langValues = current;
@@ -1962,7 +2144,12 @@ function parseFormRecordPrefill(section) {
1962
2144
  return { recordId: null, values: {} };
1963
2145
  }
1964
2146
  const id = Number(firstRecordId);
1965
- return { recordId: id, values: recordGroups[id] ?? {} };
2147
+ const version = recordVersions[id];
2148
+ return version === void 0 ? { recordId: id, values: recordGroups[id] ?? {} } : { recordId: id, values: recordGroups[id] ?? {}, version };
2149
+ }
2150
+ function asRecordVersion(value) {
2151
+ const candidate = typeof value === "number" ? value : typeof value === "string" && /^[1-9]\d*$/.test(value.trim()) ? Number(value.trim()) : Number.NaN;
2152
+ return Number.isSafeInteger(candidate) && candidate >= 1 ? candidate : null;
1966
2153
  }
1967
2154
  function flattenFormRecordPrefillValues(values, languageId) {
1968
2155
  const out = {};
@@ -1971,6 +2158,9 @@ function flattenFormRecordPrefillValues(values, languageId) {
1971
2158
  out[key] = value;
1972
2159
  continue;
1973
2160
  }
2161
+ if (value && typeof value === "object" && !Array.isArray(value) && "files" in value) {
2162
+ continue;
2163
+ }
1974
2164
  if (!Array.isArray(value) || value.length === 0) {
1975
2165
  continue;
1976
2166
  }
@@ -1987,6 +2177,319 @@ function flattenFormRecordPrefillValues(values, languageId) {
1987
2177
  return out;
1988
2178
  }
1989
2179
 
2180
+ // src/content/formListState.ts
2181
+ var FORM_LIST_MODES = ["view", "edit", "create", "history"];
2182
+ var FORM_LIST_MAX_PAGE = 1e6;
2183
+ var FORM_LIST_MAX_VALUE_BYTES = 1e3;
2184
+ var FORM_LIST_SEARCH_MIN_LENGTH = 2;
2185
+ var FORM_LIST_SEARCH_MAX_LENGTH = 100;
2186
+ var FORM_LIST_MAX_SORTS = 3;
2187
+ var FORM_LIST_MAX_ROUTE_PARAMS = 8;
2188
+ var FORM_LIST_MAX_ROUTE_VALUE_LENGTH = 255;
2189
+ var POSITIVE_INT = /^[1-9][0-9]{0,8}$/;
2190
+ var SORT_ITEM = /^([A-Za-z][A-Za-z0-9_]{0,63}):(asc|desc)$/;
2191
+ var CONTROL_ID = /^[a-z][a-z0-9_]{0,31}$/;
2192
+ var LIST_KEY = /^[a-z][a-z0-9_]{0,31}$/;
2193
+ var PHP_TRIM_CHARACTERS = " \n\r\0\v";
2194
+ function emptyFormListUrlState() {
2195
+ return { page: 1, q: null, sort: [], filters: {}, record: null, mode: null };
2196
+ }
2197
+ function isFormListParam(name, key) {
2198
+ return name.startsWith(`${key}.`);
2199
+ }
2200
+ function parseFormListQuery(query, key, rules = {}) {
2201
+ const prefix = `${key}.`;
2202
+ const own = /* @__PURE__ */ new Map();
2203
+ for (const pair of splitPairs(query)) {
2204
+ const equals = pair.indexOf("=");
2205
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
2206
+ if (!name.startsWith(prefix)) {
2207
+ continue;
2208
+ }
2209
+ if (own.has(name)) {
2210
+ return refused(400, "duplicate_list_parameter", name, `The parameter "${name}" is given twice.`);
2211
+ }
2212
+ own.set(name, lenientDecode(equals === -1 ? "" : pair.slice(equals + 1)));
2213
+ }
2214
+ let page = 1;
2215
+ let q = null;
2216
+ let sort = [];
2217
+ const filters = {};
2218
+ let record = null;
2219
+ let mode = null;
2220
+ for (const [name, value] of own) {
2221
+ const suffix = name.slice(prefix.length);
2222
+ if (utf8Length(value) > FORM_LIST_MAX_VALUE_BYTES) {
2223
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is too long.`);
2224
+ }
2225
+ if (suffix === "page") {
2226
+ const parsed = positiveInt(value);
2227
+ if (parsed === null) {
2228
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
2229
+ }
2230
+ if (parsed > FORM_LIST_MAX_PAGE) {
2231
+ return refused(400, "invalid_list_parameter", name, `The page in "${name}" is out of range.`);
2232
+ }
2233
+ page = parsed;
2234
+ } else if (suffix === "q") {
2235
+ const term = phpTrim(value);
2236
+ if (term === "") {
2237
+ q = null;
2238
+ continue;
2239
+ }
2240
+ const length = Array.from(term).length;
2241
+ if (length < FORM_LIST_SEARCH_MIN_LENGTH || length > FORM_LIST_SEARCH_MAX_LENGTH) {
2242
+ return refused(400, "invalid_list_parameter", name, `A search has ${FORM_LIST_SEARCH_MIN_LENGTH} to ${FORM_LIST_SEARCH_MAX_LENGTH} characters.`);
2243
+ }
2244
+ q = term;
2245
+ } else if (suffix === "sort") {
2246
+ const sorts = parseSort(value, name, rules.sortable);
2247
+ if (!Array.isArray(sorts)) {
2248
+ return { ok: false, error: sorts };
2249
+ }
2250
+ sort = sorts;
2251
+ } else if (suffix === "record") {
2252
+ const parsed = positiveInt(value);
2253
+ if (parsed === null) {
2254
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
2255
+ }
2256
+ record = parsed;
2257
+ } else if (suffix === "mode") {
2258
+ if (!isMode(value)) {
2259
+ return refused(400, "invalid_list_parameter", name, `The mode in "${name}" is view, edit, create or history.`);
2260
+ }
2261
+ mode = value;
2262
+ } else if (suffix.startsWith("f.")) {
2263
+ const controlId = suffix.slice(2);
2264
+ const known = rules.controls === void 0 ? CONTROL_ID.test(controlId) : rules.controls.includes(controlId);
2265
+ if (!known) {
2266
+ return refused(400, "unknown_list_parameter", name, `The list has no filter "${controlId}".`);
2267
+ }
2268
+ if (value !== "") {
2269
+ filters[controlId] = value;
2270
+ }
2271
+ } else {
2272
+ return refused(400, "unknown_list_parameter", name, `The list has no parameter "${name}".`);
2273
+ }
2274
+ }
2275
+ return withMode({ page, q, sort, filters, record, mode }, key, rules);
2276
+ }
2277
+ function encodeFormListQuery(key, state) {
2278
+ const query = {};
2279
+ if (state.page > 1) {
2280
+ query[`${key}.page`] = String(state.page);
2281
+ }
2282
+ if (state.q !== null && state.q !== "") {
2283
+ query[`${key}.q`] = state.q;
2284
+ }
2285
+ if (state.sort.length > 0) {
2286
+ query[`${key}.sort`] = state.sort.map((item) => `${item.field}:${item.direction}`).join(",");
2287
+ }
2288
+ for (const [id, value] of Object.entries(state.filters)) {
2289
+ if (value !== "") {
2290
+ query[`${key}.f.${id}`] = value;
2291
+ }
2292
+ }
2293
+ if (state.record !== null) {
2294
+ query[`${key}.record`] = String(state.record);
2295
+ }
2296
+ if (state.mode !== null) {
2297
+ query[`${key}.mode`] = state.mode;
2298
+ }
2299
+ return query;
2300
+ }
2301
+ function formListQueryString(base, key, state) {
2302
+ const kept = splitPairs(base).filter((pair) => {
2303
+ const equals = pair.indexOf("=");
2304
+ return !isFormListParam(lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), key);
2305
+ });
2306
+ const written = Object.entries(encodeFormListQuery(key, state)).map(
2307
+ ([name, value]) => `${encodeURIComponent(name)}=${encodeValue(value)}`
2308
+ );
2309
+ return [...kept, ...written].join("&");
2310
+ }
2311
+ function applyFormListUrlChange(state, change) {
2312
+ switch (change.type) {
2313
+ case "page":
2314
+ return { ...state, page: clampPage(change.page) };
2315
+ case "search": {
2316
+ const term = change.q === null ? "" : phpTrim(change.q);
2317
+ return { ...state, q: term === "" ? null : term, page: 1 };
2318
+ }
2319
+ case "sort":
2320
+ return { ...state, sort: change.sort.slice(0, FORM_LIST_MAX_SORTS).map((item) => ({ ...item })), page: 1 };
2321
+ case "filter": {
2322
+ const filters = { ...state.filters };
2323
+ if (change.value === null || change.value === "") {
2324
+ delete filters[change.id];
2325
+ } else {
2326
+ filters[change.id] = change.value;
2327
+ }
2328
+ return { ...state, filters, page: 1 };
2329
+ }
2330
+ case "reset":
2331
+ return { ...state, page: 1, q: null, sort: [], filters: {} };
2332
+ case "open":
2333
+ return { ...state, record: change.record, mode: change.mode ?? "view" };
2334
+ case "create":
2335
+ return { ...state, record: null, mode: "create" };
2336
+ case "close":
2337
+ return { ...state, record: null, mode: null };
2338
+ default: {
2339
+ const unhandled = change;
2340
+ throw new Error(`Unknown list state change: ${JSON.stringify(unhandled)}`);
2341
+ }
2342
+ }
2343
+ }
2344
+ function nextSortOnHeaderClick(current, field) {
2345
+ const first = current[0];
2346
+ if (first === void 0 || first.field !== field) {
2347
+ return [{ field, direction: "asc" }];
2348
+ }
2349
+ if (first.direction === "asc") {
2350
+ return [{ field, direction: "desc" }];
2351
+ }
2352
+ return [];
2353
+ }
2354
+ function pickFormListQuery(query) {
2355
+ return splitPairs(query).filter((pair) => {
2356
+ const equals = pair.indexOf("=");
2357
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
2358
+ const dot = name.indexOf(".");
2359
+ return dot > 0 && LIST_KEY.test(name.slice(0, dot));
2360
+ }).join("&");
2361
+ }
2362
+ function formListRouteQuery(route) {
2363
+ if (!route) {
2364
+ return "";
2365
+ }
2366
+ return Object.entries(route).filter((entry) => {
2367
+ const [name, value] = entry;
2368
+ return ROUTE_PARAM_NAME.test(name) && typeof value === "string" && value !== "" && value.length <= FORM_LIST_MAX_ROUTE_VALUE_LENGTH;
2369
+ }).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).slice(0, FORM_LIST_MAX_ROUTE_PARAMS).map(([name, value]) => `route%5B${encodeURIComponent(name)}%5D=${encodeURIComponent(value)}`).join("&");
2370
+ }
2371
+ function formListCacheKey(scope, query) {
2372
+ const own = splitPairs(query).map((pair) => {
2373
+ const equals = pair.indexOf("=");
2374
+ return [lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), lenientDecode(equals === -1 ? "" : pair.slice(equals + 1))];
2375
+ }).filter(([name]) => isFormListParam(name, scope.key)).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, value]) => `${name}=${value}`).join("&");
2376
+ return [
2377
+ "form-list",
2378
+ scope.apiBase,
2379
+ scope.account === null ? "guest" : String(scope.account),
2380
+ scope.languageId,
2381
+ scope.platform,
2382
+ scope.pageId,
2383
+ scope.sectionId,
2384
+ formListRouteQuery(scope.route),
2385
+ own
2386
+ ];
2387
+ }
2388
+ var ROUTE_PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
2389
+ function refused(status, reason, parameter, message) {
2390
+ return { ok: false, error: { status, reason, parameter, message } };
2391
+ }
2392
+ function withMode(state, key, rules) {
2393
+ let mode = state.mode;
2394
+ if (mode === null && state.record !== null) {
2395
+ mode = "view";
2396
+ }
2397
+ if (mode === "create") {
2398
+ if (state.record !== null) {
2399
+ return refused(400, "invalid_list_parameter", `${key}.record`, "A new entry has no record.");
2400
+ }
2401
+ if (rules.allowCreate === false) {
2402
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow new entries.");
2403
+ }
2404
+ } else if (mode !== null && state.record === null) {
2405
+ return refused(400, "invalid_list_parameter", `${key}.record`, `The mode "${mode}" needs a record.`);
2406
+ }
2407
+ if (mode === "edit" && rules.allowUpdate === false) {
2408
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow editing.");
2409
+ }
2410
+ if (mode === "history" && rules.showHistory === false) {
2411
+ return refused(403, "history_disabled", `${key}.mode`, "This list does not offer history.");
2412
+ }
2413
+ return { ok: true, state: { ...state, mode } };
2414
+ }
2415
+ function parseSort(value, name, sortable) {
2416
+ if (value === "") {
2417
+ return [];
2418
+ }
2419
+ const items = value.split(",");
2420
+ const fail = (message) => ({ status: 400, reason: "invalid_list_parameter", parameter: name, message });
2421
+ if (items.length > FORM_LIST_MAX_SORTS) {
2422
+ return fail(`At most ${FORM_LIST_MAX_SORTS} sort keys.`);
2423
+ }
2424
+ const sorts = [];
2425
+ const seen = /* @__PURE__ */ new Set();
2426
+ for (const item of items) {
2427
+ const match = SORT_ITEM.exec(item);
2428
+ if (match === null) {
2429
+ return fail('A sort key is "column:asc" or "column:desc".');
2430
+ }
2431
+ const field = match[1] ?? "";
2432
+ const direction = match[2] === "desc" ? "desc" : "asc";
2433
+ if (sortable !== void 0 && !sortable.includes(field)) {
2434
+ return fail(`The list cannot be sorted by "${field}".`);
2435
+ }
2436
+ if (seen.has(field)) {
2437
+ return fail(`"${field}" is sorted twice.`);
2438
+ }
2439
+ seen.add(field);
2440
+ sorts.push({ field, direction });
2441
+ }
2442
+ return sorts;
2443
+ }
2444
+ function phpTrim(text) {
2445
+ let start = 0;
2446
+ let end = text.length;
2447
+ while (start < end && PHP_TRIM_CHARACTERS.includes(text.charAt(start))) {
2448
+ start += 1;
2449
+ }
2450
+ while (end > start && PHP_TRIM_CHARACTERS.includes(text.charAt(end - 1))) {
2451
+ end -= 1;
2452
+ }
2453
+ return text.slice(start, end);
2454
+ }
2455
+ function positiveInt(value) {
2456
+ return POSITIVE_INT.test(value) ? Number(value) : null;
2457
+ }
2458
+ function isMode(value) {
2459
+ return FORM_LIST_MODES.includes(value);
2460
+ }
2461
+ function clampPage(page) {
2462
+ if (!Number.isFinite(page)) {
2463
+ return 1;
2464
+ }
2465
+ return Math.min(FORM_LIST_MAX_PAGE, Math.max(1, Math.trunc(page)));
2466
+ }
2467
+ function splitPairs(query) {
2468
+ const text = typeof query === "string" ? query : query.toString();
2469
+ const trimmed = text.startsWith("?") ? text.slice(1) : text;
2470
+ return trimmed.split("&").filter((pair) => pair !== "");
2471
+ }
2472
+ function lenientDecode(text) {
2473
+ return text.replace(/\+/g, " ").replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
2474
+ try {
2475
+ return decodeURIComponent(run);
2476
+ } catch {
2477
+ return run;
2478
+ }
2479
+ });
2480
+ }
2481
+ function encodeValue(value) {
2482
+ return encodeURIComponent(value).replace(/%3A/g, ":").replace(/%2C/g, ",");
2483
+ }
2484
+ function utf8Length(text) {
2485
+ let bytes = 0;
2486
+ for (const character of text) {
2487
+ const code = character.codePointAt(0) ?? 0;
2488
+ bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
2489
+ }
2490
+ return bytes;
2491
+ }
2492
+
1990
2493
  // src/navigation/headerPreset.ts
1991
2494
  var WEB_HEADER_PRESET_VALUES = [
1992
2495
  "simple",
@@ -2840,7 +3343,16 @@ function transformPagesData(pages) {
2840
3343
  ENDPOINTS,
2841
3344
  FIELDS_MAP_STYLE_CONFIG,
2842
3345
  FONT_SIZE_PX,
3346
+ FORM_LIST_MAX_PAGE,
3347
+ FORM_LIST_MAX_ROUTE_PARAMS,
3348
+ FORM_LIST_MAX_ROUTE_VALUE_LENGTH,
3349
+ FORM_LIST_MAX_SORTS,
3350
+ FORM_LIST_MAX_VALUE_BYTES,
3351
+ FORM_LIST_MODES,
3352
+ FORM_LIST_SEARCH_MAX_LENGTH,
3353
+ FORM_LIST_SEARCH_MIN_LENGTH,
2843
3354
  FORM_RECORD_PREFILL_SKIP_FIELDS,
3355
+ FORM_SECTION_STYLE_NAMES,
2844
3356
  FULL_RADIUS_PX,
2845
3357
  HEADER_CLIENT_TYPE,
2846
3358
  LINE_HEIGHT,
@@ -2870,7 +3382,10 @@ function transformPagesData(pages) {
2870
3382
  WEB_HEADER_PRESET_OPTIONS,
2871
3383
  WEB_HEADER_PRESET_VALUES,
2872
3384
  _resetPluginStyleRegistry,
3385
+ applyFormListUrlChange,
2873
3386
  arePreviewPreferencesEqual,
3387
+ asFilesCell,
3388
+ asRecordVersion,
2874
3389
  buildConditionContext,
2875
3390
  buildPagesResolvePath,
2876
3391
  buildPagesResolveQuery,
@@ -2881,6 +3396,8 @@ function transformPagesData(pages) {
2881
3396
  classifyClassString,
2882
3397
  collectPageIdsFromMenuItems,
2883
3398
  colorToHex,
3399
+ emptyFormListUrlState,
3400
+ encodeFormListQuery,
2884
3401
  evaluateCondition,
2885
3402
  expandedIdsForActiveTrail,
2886
3403
  extendStyleRegistry,
@@ -2895,7 +3412,14 @@ function transformPagesData(pages) {
2895
3412
  footerColumnItems,
2896
3413
  footerGroupLinks,
2897
3414
  footerStandaloneItems,
3415
+ formListCacheKey,
3416
+ formListQueryString,
3417
+ formListRouteQuery,
2898
3418
  formatRateLimitMessage,
3419
+ getFormInvalidData,
3420
+ getFormListFailure,
3421
+ getFormListRestoreBlocked,
3422
+ getFormStaleVersion,
2899
3423
  getMergedStyleRegistry,
2900
3424
  getNavigationItemAriaLabel,
2901
3425
  getNavigationItemHref,
@@ -2913,6 +3437,7 @@ function transformPagesData(pages) {
2913
3437
  hasInlineFormatting,
2914
3438
  isBottomTabMenuItemActive,
2915
3439
  isDoubleWebHeaderPreset,
3440
+ isFormListParam,
2916
3441
  isKnownStyleName,
2917
3442
  isMenuItemActiveOnMobile,
2918
3443
  isMenuItemActiveOnWeb,
@@ -2946,18 +3471,21 @@ function transformPagesData(pages) {
2946
3471
  matchesMobilePath,
2947
3472
  matchesWebPath,
2948
3473
  mergeHeaderLayers,
3474
+ nextSortOnHeaderClick,
2949
3475
  normalizePagesResolvePath,
2950
3476
  pageUrlToMobileRoute,
2951
3477
  parseDimensionToReactNative,
2952
3478
  parseDimensionToWeb,
2953
3479
  parseFieldsMapCatalog,
2954
3480
  parseFieldsMapLabels,
3481
+ parseFormListQuery,
2955
3482
  parseFormRecordPrefill,
2956
3483
  parseInlineRich,
2957
3484
  parseOptionCatalog,
2958
3485
  parseOptionCodes,
2959
3486
  parseOptionLabels,
2960
3487
  parseSpacing,
3488
+ pickFormListQuery,
2961
3489
  previewKeywordFromPath,
2962
3490
  radiusToPx,
2963
3491
  replaceCalcedValues,