@selfhelp/shared 1.23.0 → 1.24.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 (35) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/dist/index.d.mts +300 -100
  3. package/dist/index.d.ts +300 -100
  4. package/dist/index.js +519 -3
  5. package/dist/index.mjs +495 -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 +3 -1
  9. package/dist/plugin-sdk/index.mjs +3 -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 +3 -1
  13. package/dist/registry/index.mjs +3 -1
  14. package/dist/{styles.registry-BBd9T2Ox.d.ts → styles.registry-BKWoDg7q.d.ts} +701 -2
  15. package/dist/{styles.registry-IjDTff8P.d.mts → styles.registry-aopb3vsI.d.mts} +701 -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/styles.registry.ts +2 -0
  29. package/src/types/api/__tests__/formWrites.test.ts +84 -0
  30. package/src/types/api/form-lists.ts +469 -0
  31. package/src/types/api/forms.ts +149 -4
  32. package/src/types/api/index.ts +1 -0
  33. package/src/types/styles/composite.ts +13 -0
  34. package/src/types/styles/forms.ts +84 -0
  35. package/src/types/styles/unknown.ts +5 -1
package/dist/index.js CHANGED
@@ -50,6 +50,14 @@ __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,
54
62
  FULL_RADIUS_PX: () => FULL_RADIUS_PX,
55
63
  HEADER_CLIENT_TYPE: () => HEADER_CLIENT_TYPE,
@@ -80,7 +88,10 @@ __export(index_exports, {
80
88
  WEB_HEADER_PRESET_OPTIONS: () => WEB_HEADER_PRESET_OPTIONS,
81
89
  WEB_HEADER_PRESET_VALUES: () => WEB_HEADER_PRESET_VALUES,
82
90
  _resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
91
+ applyFormListUrlChange: () => applyFormListUrlChange,
83
92
  arePreviewPreferencesEqual: () => arePreviewPreferencesEqual,
93
+ asFilesCell: () => asFilesCell,
94
+ asRecordVersion: () => asRecordVersion,
84
95
  buildConditionContext: () => buildConditionContext,
85
96
  buildPagesResolvePath: () => buildPagesResolvePath,
86
97
  buildPagesResolveQuery: () => buildPagesResolveQuery,
@@ -91,6 +102,8 @@ __export(index_exports, {
91
102
  classifyClassString: () => classifyClassString,
92
103
  collectPageIdsFromMenuItems: () => collectPageIdsFromMenuItems,
93
104
  colorToHex: () => colorToHex,
105
+ emptyFormListUrlState: () => emptyFormListUrlState,
106
+ encodeFormListQuery: () => encodeFormListQuery,
94
107
  evaluateCondition: () => evaluateCondition,
95
108
  expandedIdsForActiveTrail: () => expandedIdsForActiveTrail,
96
109
  extendStyleRegistry: () => extendStyleRegistry,
@@ -105,7 +118,14 @@ __export(index_exports, {
105
118
  footerColumnItems: () => footerColumnItems,
106
119
  footerGroupLinks: () => footerGroupLinks,
107
120
  footerStandaloneItems: () => footerStandaloneItems,
121
+ formListCacheKey: () => formListCacheKey,
122
+ formListQueryString: () => formListQueryString,
123
+ formListRouteQuery: () => formListRouteQuery,
108
124
  formatRateLimitMessage: () => formatRateLimitMessage,
125
+ getFormInvalidData: () => getFormInvalidData,
126
+ getFormListFailure: () => getFormListFailure,
127
+ getFormListRestoreBlocked: () => getFormListRestoreBlocked,
128
+ getFormStaleVersion: () => getFormStaleVersion,
109
129
  getMergedStyleRegistry: () => getMergedStyleRegistry,
110
130
  getNavigationItemAriaLabel: () => getNavigationItemAriaLabel,
111
131
  getNavigationItemHref: () => getNavigationItemHref,
@@ -123,6 +143,7 @@ __export(index_exports, {
123
143
  hasInlineFormatting: () => hasInlineFormatting,
124
144
  isBottomTabMenuItemActive: () => isBottomTabMenuItemActive,
125
145
  isDoubleWebHeaderPreset: () => isDoubleWebHeaderPreset,
146
+ isFormListParam: () => isFormListParam,
126
147
  isKnownStyleName: () => isKnownStyleName,
127
148
  isMenuItemActiveOnMobile: () => isMenuItemActiveOnMobile,
128
149
  isMenuItemActiveOnWeb: () => isMenuItemActiveOnWeb,
@@ -156,18 +177,21 @@ __export(index_exports, {
156
177
  matchesMobilePath: () => matchesMobilePath,
157
178
  matchesWebPath: () => matchesWebPath,
158
179
  mergeHeaderLayers: () => mergeHeaderLayers,
180
+ nextSortOnHeaderClick: () => nextSortOnHeaderClick,
159
181
  normalizePagesResolvePath: () => normalizePagesResolvePath,
160
182
  pageUrlToMobileRoute: () => pageUrlToMobileRoute,
161
183
  parseDimensionToReactNative: () => parseDimensionToReactNative,
162
184
  parseDimensionToWeb: () => parseDimensionToWeb,
163
185
  parseFieldsMapCatalog: () => parseFieldsMapCatalog,
164
186
  parseFieldsMapLabels: () => parseFieldsMapLabels,
187
+ parseFormListQuery: () => parseFormListQuery,
165
188
  parseFormRecordPrefill: () => parseFormRecordPrefill,
166
189
  parseInlineRich: () => parseInlineRich,
167
190
  parseOptionCatalog: () => parseOptionCatalog,
168
191
  parseOptionCodes: () => parseOptionCodes,
169
192
  parseOptionLabels: () => parseOptionLabels,
170
193
  parseSpacing: () => parseSpacing,
194
+ pickFormListQuery: () => pickFormListQuery,
171
195
  previewKeywordFromPath: () => previewKeywordFromPath,
172
196
  radiusToPx: () => radiusToPx,
173
197
  replaceCalcedValues: () => replaceCalcedValues,
@@ -490,7 +514,9 @@ var BASE_STYLE_REGISTRY = {
490
514
  version: { description: "Build/version diagnostic surface", category: "auth", canHaveChildren: false },
491
515
  "ref-container": { description: "Renders content referenced from another section", category: "layout", canHaveChildren: true },
492
516
  "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 }
517
+ "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-form-list": { description: "Entry list with form: server-rendered list of records with create / view / edit / delete, quick actions and history", category: "forms", canHaveChildren: true },
519
+ "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
520
  };
495
521
  var STYLE_REGISTRY = BASE_STYLE_REGISTRY;
496
522
  var PLUGIN_STYLE_REGISTRY = {};
@@ -654,6 +680,35 @@ var ENDPOINTS = {
654
680
  SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
655
681
  UPDATE: `${API_VERSION_PREFIX}/forms/update`,
656
682
  DELETE: `${API_VERSION_PREFIX}/forms/delete`
683
+ },
684
+ /**
685
+ * `entry-form-list` / `data-view` lists. A list never has its own create,
686
+ * update or delete route: writes go through {@link ENDPOINTS.FORMS}. The
687
+ * first paint reads `list_state` from the page payload; these routes serve
688
+ * the interactions after it. Path segments are numeric ids, except the
689
+ * action id and the field key, which are encoded.
690
+ */
691
+ LISTS: {
692
+ STATE: (sectionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/state`,
693
+ QUICK_ACTION: (sectionId, recordId, actionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/actions/${encodeURIComponent(actionId)}`,
694
+ HISTORY: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/history`,
695
+ VERSION: (sectionId, recordId, version) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}`,
696
+ COMPARE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/compare`,
697
+ RESTORE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/restore`,
698
+ VERSION_FILE: (sectionId, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`,
699
+ /** Current file of a record shown by a list / data-view / entry-record (F165). */
700
+ CURRENT_FILE: (sectionId, recordId, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/files/${encodeURIComponent(fieldKey)}`
701
+ },
702
+ /**
703
+ * Admin data-browser record history (contract 6). Route permission
704
+ * `admin.data.read`; the controller also requires table UPDATE.
705
+ */
706
+ ADMIN_DATA_HISTORY: {
707
+ HISTORY: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/history`,
708
+ VERSION: (tableName, recordId, version) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}`,
709
+ COMPARE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/compare`,
710
+ RESTORE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/restore`,
711
+ VERSION_FILE: (tableName, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`
657
712
  }
658
713
  };
659
714
  var HEADER_CLIENT_TYPE = "X-Client-Type";
@@ -661,6 +716,73 @@ var CLIENT_TYPE_WEB = "web";
661
716
  var CLIENT_TYPE_MOBILE = "mobile";
662
717
  var CLIENT_TYPE_MOBILE_AND_WEB = "mobile_and_web";
663
718
 
719
+ // src/api/formListErrors.ts
720
+ function envelope(error) {
721
+ const response = error?.response;
722
+ const status = response?.status;
723
+ const data = response?.data?.data;
724
+ if (typeof status !== "number" || typeof data !== "object" || data === null || Array.isArray(data)) {
725
+ return null;
726
+ }
727
+ return { status, message: response?.data?.message, data };
728
+ }
729
+ function getFormStaleVersion(error) {
730
+ const found = envelope(error);
731
+ if (found === null || found.status !== 409 || found.data.reason !== "stale_version") {
732
+ return null;
733
+ }
734
+ const { record_id: recordId, expected_version: expected, current_version: current } = found.data;
735
+ if (typeof recordId !== "number" || typeof expected !== "number" || typeof current !== "number") {
736
+ return null;
737
+ }
738
+ return { reason: "stale_version", record_id: recordId, expected_version: expected, current_version: current };
739
+ }
740
+ function getFormListRestoreBlocked(error) {
741
+ const found = envelope(error);
742
+ if (found === null || found.status !== 422 || found.data.reason !== "restore_blocked") {
743
+ return null;
744
+ }
745
+ const { record_id: recordId, from_version: fromVersion, blockers } = found.data;
746
+ if (typeof recordId !== "number" || typeof fromVersion !== "number" || !Array.isArray(blockers)) {
747
+ return null;
748
+ }
749
+ return {
750
+ reason: "restore_blocked",
751
+ record_id: recordId,
752
+ from_version: fromVersion,
753
+ blockers
754
+ };
755
+ }
756
+ function getFormInvalidData(error) {
757
+ const found = envelope(error);
758
+ if (found === null || found.status !== 422 || found.data.reason !== "invalid_form_data" || !Array.isArray(found.data.errors)) {
759
+ return null;
760
+ }
761
+ const errors = [];
762
+ for (const entry of found.data.errors) {
763
+ if (typeof entry !== "object" || entry === null) {
764
+ continue;
765
+ }
766
+ const { field, key, rule, message } = entry;
767
+ if (typeof field === "string" && typeof key === "string" && typeof rule === "string" && typeof message === "string") {
768
+ errors.push({ field, key, rule, message });
769
+ }
770
+ }
771
+ return errors.length > 0 ? { reason: "invalid_form_data", errors } : null;
772
+ }
773
+ function getFormListFailure(error) {
774
+ const found = envelope(error);
775
+ if (found === null || typeof found.data.reason !== "string" || found.data.reason === "") {
776
+ return null;
777
+ }
778
+ return {
779
+ status: found.status,
780
+ reason: found.data.reason,
781
+ parameter: typeof found.data.parameter === "string" && found.data.parameter !== "" ? found.data.parameter : null,
782
+ message: typeof found.message === "string" ? found.message : null
783
+ };
784
+ }
785
+
664
786
  // src/api/pagesResolve.ts
665
787
  function normalizePagesResolvePath(rawPath) {
666
788
  const withoutOrigin = rawPath.includes("://") ? (() => {
@@ -1878,10 +2000,12 @@ function serializeFieldsMapLabels(labels) {
1878
2000
  // src/content/formRecordPrefill.ts
1879
2001
  var FORM_RECORD_PREFILL_SKIP_FIELDS = /* @__PURE__ */ new Set([
1880
2002
  "record_id",
2003
+ "_version",
1881
2004
  "entry_date",
1882
2005
  "id_users",
1883
2006
  "user_name",
1884
2007
  "user_code",
2008
+ "id_action_trigger_types",
1885
2009
  "id_actionTriggerTypes",
1886
2010
  "triggerType",
1887
2011
  "id_languages",
@@ -1904,12 +2028,45 @@ function asScalarString(value) {
1904
2028
  }
1905
2029
  return null;
1906
2030
  }
2031
+ function asFilesCell(value) {
2032
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
2033
+ return null;
2034
+ }
2035
+ const files = value.files;
2036
+ if (!Array.isArray(files)) {
2037
+ return null;
2038
+ }
2039
+ const out = [];
2040
+ for (const entry of files) {
2041
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
2042
+ continue;
2043
+ }
2044
+ const file = entry;
2045
+ const index = typeof file.index === "number" ? file.index : Number(file.index);
2046
+ const name = typeof file.name === "string" ? file.name : null;
2047
+ const url = typeof file.url === "string" ? file.url : null;
2048
+ if (!Number.isFinite(index) || name === null || url === null) {
2049
+ continue;
2050
+ }
2051
+ const mime = typeof file.mime === "string" ? file.mime : file.mime === null ? null : void 0;
2052
+ 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;
2053
+ out.push({
2054
+ index: Math.trunc(index),
2055
+ name,
2056
+ url,
2057
+ ...mime !== void 0 ? { mime } : {},
2058
+ ...size !== void 0 ? { size } : {}
2059
+ });
2060
+ }
2061
+ return { files: out };
2062
+ }
1907
2063
  function parseFormRecordPrefill(section) {
1908
2064
  const sectionDataArray = section?.section_data;
1909
2065
  if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
1910
2066
  return { recordId: null, values: {} };
1911
2067
  }
1912
2068
  const recordGroups = {};
2069
+ const recordVersions = {};
1913
2070
  for (const row of sectionDataArray) {
1914
2071
  if (!row || typeof row !== "object" || Array.isArray(row)) {
1915
2072
  continue;
@@ -1923,11 +2080,22 @@ function parseFormRecordPrefill(section) {
1923
2080
  if (!recordGroups[recordId]) {
1924
2081
  recordGroups[recordId] = {};
1925
2082
  }
2083
+ const version2 = asRecordVersion(record._version);
2084
+ if (version2 !== null && recordVersions[recordId] === void 0) {
2085
+ recordVersions[recordId] = version2;
2086
+ }
1926
2087
  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
2088
  for (const [fieldName, fieldValue] of Object.entries(record)) {
1928
2089
  if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
1929
2090
  continue;
1930
2091
  }
2092
+ const filesCell = asFilesCell(fieldValue);
2093
+ if (filesCell !== null) {
2094
+ if (languageId === 1 || !recordGroups[recordId][fieldName]) {
2095
+ recordGroups[recordId][fieldName] = filesCell;
2096
+ }
2097
+ continue;
2098
+ }
1931
2099
  const value = asScalarString(fieldValue);
1932
2100
  if (value === null) {
1933
2101
  continue;
@@ -1940,7 +2108,10 @@ function parseFormRecordPrefill(section) {
1940
2108
  }
1941
2109
  } else if (typeof languageId === "number") {
1942
2110
  const current = recordGroups[recordId][fieldName];
1943
- if (typeof current === "string" || !current) {
2111
+ if (typeof current === "string" || Array.isArray(current) === false || !current) {
2112
+ if (typeof current === "object" && current !== null && "files" in current) {
2113
+ continue;
2114
+ }
1944
2115
  recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
1945
2116
  } else {
1946
2117
  const langValues = current;
@@ -1962,7 +2133,12 @@ function parseFormRecordPrefill(section) {
1962
2133
  return { recordId: null, values: {} };
1963
2134
  }
1964
2135
  const id = Number(firstRecordId);
1965
- return { recordId: id, values: recordGroups[id] ?? {} };
2136
+ const version = recordVersions[id];
2137
+ return version === void 0 ? { recordId: id, values: recordGroups[id] ?? {} } : { recordId: id, values: recordGroups[id] ?? {}, version };
2138
+ }
2139
+ function asRecordVersion(value) {
2140
+ const candidate = typeof value === "number" ? value : typeof value === "string" && /^[1-9]\d*$/.test(value.trim()) ? Number(value.trim()) : Number.NaN;
2141
+ return Number.isSafeInteger(candidate) && candidate >= 1 ? candidate : null;
1966
2142
  }
1967
2143
  function flattenFormRecordPrefillValues(values, languageId) {
1968
2144
  const out = {};
@@ -1971,6 +2147,9 @@ function flattenFormRecordPrefillValues(values, languageId) {
1971
2147
  out[key] = value;
1972
2148
  continue;
1973
2149
  }
2150
+ if (value && typeof value === "object" && !Array.isArray(value) && "files" in value) {
2151
+ continue;
2152
+ }
1974
2153
  if (!Array.isArray(value) || value.length === 0) {
1975
2154
  continue;
1976
2155
  }
@@ -1987,6 +2166,319 @@ function flattenFormRecordPrefillValues(values, languageId) {
1987
2166
  return out;
1988
2167
  }
1989
2168
 
2169
+ // src/content/formListState.ts
2170
+ var FORM_LIST_MODES = ["view", "edit", "create", "history"];
2171
+ var FORM_LIST_MAX_PAGE = 1e6;
2172
+ var FORM_LIST_MAX_VALUE_BYTES = 1e3;
2173
+ var FORM_LIST_SEARCH_MIN_LENGTH = 2;
2174
+ var FORM_LIST_SEARCH_MAX_LENGTH = 100;
2175
+ var FORM_LIST_MAX_SORTS = 3;
2176
+ var FORM_LIST_MAX_ROUTE_PARAMS = 8;
2177
+ var FORM_LIST_MAX_ROUTE_VALUE_LENGTH = 255;
2178
+ var POSITIVE_INT = /^[1-9][0-9]{0,8}$/;
2179
+ var SORT_ITEM = /^([A-Za-z][A-Za-z0-9_]{0,63}):(asc|desc)$/;
2180
+ var CONTROL_ID = /^[a-z][a-z0-9_]{0,31}$/;
2181
+ var LIST_KEY = /^[a-z][a-z0-9_]{0,31}$/;
2182
+ var PHP_TRIM_CHARACTERS = " \n\r\0\v";
2183
+ function emptyFormListUrlState() {
2184
+ return { page: 1, q: null, sort: [], filters: {}, record: null, mode: null };
2185
+ }
2186
+ function isFormListParam(name, key) {
2187
+ return name.startsWith(`${key}.`);
2188
+ }
2189
+ function parseFormListQuery(query, key, rules = {}) {
2190
+ const prefix = `${key}.`;
2191
+ const own = /* @__PURE__ */ new Map();
2192
+ for (const pair of splitPairs(query)) {
2193
+ const equals = pair.indexOf("=");
2194
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
2195
+ if (!name.startsWith(prefix)) {
2196
+ continue;
2197
+ }
2198
+ if (own.has(name)) {
2199
+ return refused(400, "duplicate_list_parameter", name, `The parameter "${name}" is given twice.`);
2200
+ }
2201
+ own.set(name, lenientDecode(equals === -1 ? "" : pair.slice(equals + 1)));
2202
+ }
2203
+ let page = 1;
2204
+ let q = null;
2205
+ let sort = [];
2206
+ const filters = {};
2207
+ let record = null;
2208
+ let mode = null;
2209
+ for (const [name, value] of own) {
2210
+ const suffix = name.slice(prefix.length);
2211
+ if (utf8Length(value) > FORM_LIST_MAX_VALUE_BYTES) {
2212
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is too long.`);
2213
+ }
2214
+ if (suffix === "page") {
2215
+ const parsed = positiveInt(value);
2216
+ if (parsed === null) {
2217
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
2218
+ }
2219
+ if (parsed > FORM_LIST_MAX_PAGE) {
2220
+ return refused(400, "invalid_list_parameter", name, `The page in "${name}" is out of range.`);
2221
+ }
2222
+ page = parsed;
2223
+ } else if (suffix === "q") {
2224
+ const term = phpTrim(value);
2225
+ if (term === "") {
2226
+ q = null;
2227
+ continue;
2228
+ }
2229
+ const length = Array.from(term).length;
2230
+ if (length < FORM_LIST_SEARCH_MIN_LENGTH || length > FORM_LIST_SEARCH_MAX_LENGTH) {
2231
+ return refused(400, "invalid_list_parameter", name, `A search has ${FORM_LIST_SEARCH_MIN_LENGTH} to ${FORM_LIST_SEARCH_MAX_LENGTH} characters.`);
2232
+ }
2233
+ q = term;
2234
+ } else if (suffix === "sort") {
2235
+ const sorts = parseSort(value, name, rules.sortable);
2236
+ if (!Array.isArray(sorts)) {
2237
+ return { ok: false, error: sorts };
2238
+ }
2239
+ sort = sorts;
2240
+ } else if (suffix === "record") {
2241
+ const parsed = positiveInt(value);
2242
+ if (parsed === null) {
2243
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
2244
+ }
2245
+ record = parsed;
2246
+ } else if (suffix === "mode") {
2247
+ if (!isMode(value)) {
2248
+ return refused(400, "invalid_list_parameter", name, `The mode in "${name}" is view, edit, create or history.`);
2249
+ }
2250
+ mode = value;
2251
+ } else if (suffix.startsWith("f.")) {
2252
+ const controlId = suffix.slice(2);
2253
+ const known = rules.controls === void 0 ? CONTROL_ID.test(controlId) : rules.controls.includes(controlId);
2254
+ if (!known) {
2255
+ return refused(400, "unknown_list_parameter", name, `The list has no filter "${controlId}".`);
2256
+ }
2257
+ if (value !== "") {
2258
+ filters[controlId] = value;
2259
+ }
2260
+ } else {
2261
+ return refused(400, "unknown_list_parameter", name, `The list has no parameter "${name}".`);
2262
+ }
2263
+ }
2264
+ return withMode({ page, q, sort, filters, record, mode }, key, rules);
2265
+ }
2266
+ function encodeFormListQuery(key, state) {
2267
+ const query = {};
2268
+ if (state.page > 1) {
2269
+ query[`${key}.page`] = String(state.page);
2270
+ }
2271
+ if (state.q !== null && state.q !== "") {
2272
+ query[`${key}.q`] = state.q;
2273
+ }
2274
+ if (state.sort.length > 0) {
2275
+ query[`${key}.sort`] = state.sort.map((item) => `${item.field}:${item.direction}`).join(",");
2276
+ }
2277
+ for (const [id, value] of Object.entries(state.filters)) {
2278
+ if (value !== "") {
2279
+ query[`${key}.f.${id}`] = value;
2280
+ }
2281
+ }
2282
+ if (state.record !== null) {
2283
+ query[`${key}.record`] = String(state.record);
2284
+ }
2285
+ if (state.mode !== null) {
2286
+ query[`${key}.mode`] = state.mode;
2287
+ }
2288
+ return query;
2289
+ }
2290
+ function formListQueryString(base, key, state) {
2291
+ const kept = splitPairs(base).filter((pair) => {
2292
+ const equals = pair.indexOf("=");
2293
+ return !isFormListParam(lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), key);
2294
+ });
2295
+ const written = Object.entries(encodeFormListQuery(key, state)).map(
2296
+ ([name, value]) => `${encodeURIComponent(name)}=${encodeValue(value)}`
2297
+ );
2298
+ return [...kept, ...written].join("&");
2299
+ }
2300
+ function applyFormListUrlChange(state, change) {
2301
+ switch (change.type) {
2302
+ case "page":
2303
+ return { ...state, page: clampPage(change.page) };
2304
+ case "search": {
2305
+ const term = change.q === null ? "" : phpTrim(change.q);
2306
+ return { ...state, q: term === "" ? null : term, page: 1 };
2307
+ }
2308
+ case "sort":
2309
+ return { ...state, sort: change.sort.slice(0, FORM_LIST_MAX_SORTS).map((item) => ({ ...item })), page: 1 };
2310
+ case "filter": {
2311
+ const filters = { ...state.filters };
2312
+ if (change.value === null || change.value === "") {
2313
+ delete filters[change.id];
2314
+ } else {
2315
+ filters[change.id] = change.value;
2316
+ }
2317
+ return { ...state, filters, page: 1 };
2318
+ }
2319
+ case "reset":
2320
+ return { ...state, page: 1, q: null, sort: [], filters: {} };
2321
+ case "open":
2322
+ return { ...state, record: change.record, mode: change.mode ?? "view" };
2323
+ case "create":
2324
+ return { ...state, record: null, mode: "create" };
2325
+ case "close":
2326
+ return { ...state, record: null, mode: null };
2327
+ default: {
2328
+ const unhandled = change;
2329
+ throw new Error(`Unknown list state change: ${JSON.stringify(unhandled)}`);
2330
+ }
2331
+ }
2332
+ }
2333
+ function nextSortOnHeaderClick(current, field) {
2334
+ const first = current[0];
2335
+ if (first === void 0 || first.field !== field) {
2336
+ return [{ field, direction: "asc" }];
2337
+ }
2338
+ if (first.direction === "asc") {
2339
+ return [{ field, direction: "desc" }];
2340
+ }
2341
+ return [];
2342
+ }
2343
+ function pickFormListQuery(query) {
2344
+ return splitPairs(query).filter((pair) => {
2345
+ const equals = pair.indexOf("=");
2346
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
2347
+ const dot = name.indexOf(".");
2348
+ return dot > 0 && LIST_KEY.test(name.slice(0, dot));
2349
+ }).join("&");
2350
+ }
2351
+ function formListRouteQuery(route) {
2352
+ if (!route) {
2353
+ return "";
2354
+ }
2355
+ return Object.entries(route).filter((entry) => {
2356
+ const [name, value] = entry;
2357
+ return ROUTE_PARAM_NAME.test(name) && typeof value === "string" && value !== "" && value.length <= FORM_LIST_MAX_ROUTE_VALUE_LENGTH;
2358
+ }).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("&");
2359
+ }
2360
+ function formListCacheKey(scope, query) {
2361
+ const own = splitPairs(query).map((pair) => {
2362
+ const equals = pair.indexOf("=");
2363
+ return [lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), lenientDecode(equals === -1 ? "" : pair.slice(equals + 1))];
2364
+ }).filter(([name]) => isFormListParam(name, scope.key)).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, value]) => `${name}=${value}`).join("&");
2365
+ return [
2366
+ "form-list",
2367
+ scope.apiBase,
2368
+ scope.account === null ? "guest" : String(scope.account),
2369
+ scope.languageId,
2370
+ scope.platform,
2371
+ scope.pageId,
2372
+ scope.sectionId,
2373
+ formListRouteQuery(scope.route),
2374
+ own
2375
+ ];
2376
+ }
2377
+ var ROUTE_PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
2378
+ function refused(status, reason, parameter, message) {
2379
+ return { ok: false, error: { status, reason, parameter, message } };
2380
+ }
2381
+ function withMode(state, key, rules) {
2382
+ let mode = state.mode;
2383
+ if (mode === null && state.record !== null) {
2384
+ mode = "view";
2385
+ }
2386
+ if (mode === "create") {
2387
+ if (state.record !== null) {
2388
+ return refused(400, "invalid_list_parameter", `${key}.record`, "A new entry has no record.");
2389
+ }
2390
+ if (rules.allowCreate === false) {
2391
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow new entries.");
2392
+ }
2393
+ } else if (mode !== null && state.record === null) {
2394
+ return refused(400, "invalid_list_parameter", `${key}.record`, `The mode "${mode}" needs a record.`);
2395
+ }
2396
+ if (mode === "edit" && rules.allowUpdate === false) {
2397
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow editing.");
2398
+ }
2399
+ if (mode === "history" && rules.showHistory === false) {
2400
+ return refused(403, "history_disabled", `${key}.mode`, "This list does not offer history.");
2401
+ }
2402
+ return { ok: true, state: { ...state, mode } };
2403
+ }
2404
+ function parseSort(value, name, sortable) {
2405
+ if (value === "") {
2406
+ return [];
2407
+ }
2408
+ const items = value.split(",");
2409
+ const fail = (message) => ({ status: 400, reason: "invalid_list_parameter", parameter: name, message });
2410
+ if (items.length > FORM_LIST_MAX_SORTS) {
2411
+ return fail(`At most ${FORM_LIST_MAX_SORTS} sort keys.`);
2412
+ }
2413
+ const sorts = [];
2414
+ const seen = /* @__PURE__ */ new Set();
2415
+ for (const item of items) {
2416
+ const match = SORT_ITEM.exec(item);
2417
+ if (match === null) {
2418
+ return fail('A sort key is "column:asc" or "column:desc".');
2419
+ }
2420
+ const field = match[1] ?? "";
2421
+ const direction = match[2] === "desc" ? "desc" : "asc";
2422
+ if (sortable !== void 0 && !sortable.includes(field)) {
2423
+ return fail(`The list cannot be sorted by "${field}".`);
2424
+ }
2425
+ if (seen.has(field)) {
2426
+ return fail(`"${field}" is sorted twice.`);
2427
+ }
2428
+ seen.add(field);
2429
+ sorts.push({ field, direction });
2430
+ }
2431
+ return sorts;
2432
+ }
2433
+ function phpTrim(text) {
2434
+ let start = 0;
2435
+ let end = text.length;
2436
+ while (start < end && PHP_TRIM_CHARACTERS.includes(text.charAt(start))) {
2437
+ start += 1;
2438
+ }
2439
+ while (end > start && PHP_TRIM_CHARACTERS.includes(text.charAt(end - 1))) {
2440
+ end -= 1;
2441
+ }
2442
+ return text.slice(start, end);
2443
+ }
2444
+ function positiveInt(value) {
2445
+ return POSITIVE_INT.test(value) ? Number(value) : null;
2446
+ }
2447
+ function isMode(value) {
2448
+ return FORM_LIST_MODES.includes(value);
2449
+ }
2450
+ function clampPage(page) {
2451
+ if (!Number.isFinite(page)) {
2452
+ return 1;
2453
+ }
2454
+ return Math.min(FORM_LIST_MAX_PAGE, Math.max(1, Math.trunc(page)));
2455
+ }
2456
+ function splitPairs(query) {
2457
+ const text = typeof query === "string" ? query : query.toString();
2458
+ const trimmed = text.startsWith("?") ? text.slice(1) : text;
2459
+ return trimmed.split("&").filter((pair) => pair !== "");
2460
+ }
2461
+ function lenientDecode(text) {
2462
+ return text.replace(/\+/g, " ").replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
2463
+ try {
2464
+ return decodeURIComponent(run);
2465
+ } catch {
2466
+ return run;
2467
+ }
2468
+ });
2469
+ }
2470
+ function encodeValue(value) {
2471
+ return encodeURIComponent(value).replace(/%3A/g, ":").replace(/%2C/g, ",");
2472
+ }
2473
+ function utf8Length(text) {
2474
+ let bytes = 0;
2475
+ for (const character of text) {
2476
+ const code = character.codePointAt(0) ?? 0;
2477
+ bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
2478
+ }
2479
+ return bytes;
2480
+ }
2481
+
1990
2482
  // src/navigation/headerPreset.ts
1991
2483
  var WEB_HEADER_PRESET_VALUES = [
1992
2484
  "simple",
@@ -2840,6 +3332,14 @@ function transformPagesData(pages) {
2840
3332
  ENDPOINTS,
2841
3333
  FIELDS_MAP_STYLE_CONFIG,
2842
3334
  FONT_SIZE_PX,
3335
+ FORM_LIST_MAX_PAGE,
3336
+ FORM_LIST_MAX_ROUTE_PARAMS,
3337
+ FORM_LIST_MAX_ROUTE_VALUE_LENGTH,
3338
+ FORM_LIST_MAX_SORTS,
3339
+ FORM_LIST_MAX_VALUE_BYTES,
3340
+ FORM_LIST_MODES,
3341
+ FORM_LIST_SEARCH_MAX_LENGTH,
3342
+ FORM_LIST_SEARCH_MIN_LENGTH,
2843
3343
  FORM_RECORD_PREFILL_SKIP_FIELDS,
2844
3344
  FULL_RADIUS_PX,
2845
3345
  HEADER_CLIENT_TYPE,
@@ -2870,7 +3370,10 @@ function transformPagesData(pages) {
2870
3370
  WEB_HEADER_PRESET_OPTIONS,
2871
3371
  WEB_HEADER_PRESET_VALUES,
2872
3372
  _resetPluginStyleRegistry,
3373
+ applyFormListUrlChange,
2873
3374
  arePreviewPreferencesEqual,
3375
+ asFilesCell,
3376
+ asRecordVersion,
2874
3377
  buildConditionContext,
2875
3378
  buildPagesResolvePath,
2876
3379
  buildPagesResolveQuery,
@@ -2881,6 +3384,8 @@ function transformPagesData(pages) {
2881
3384
  classifyClassString,
2882
3385
  collectPageIdsFromMenuItems,
2883
3386
  colorToHex,
3387
+ emptyFormListUrlState,
3388
+ encodeFormListQuery,
2884
3389
  evaluateCondition,
2885
3390
  expandedIdsForActiveTrail,
2886
3391
  extendStyleRegistry,
@@ -2895,7 +3400,14 @@ function transformPagesData(pages) {
2895
3400
  footerColumnItems,
2896
3401
  footerGroupLinks,
2897
3402
  footerStandaloneItems,
3403
+ formListCacheKey,
3404
+ formListQueryString,
3405
+ formListRouteQuery,
2898
3406
  formatRateLimitMessage,
3407
+ getFormInvalidData,
3408
+ getFormListFailure,
3409
+ getFormListRestoreBlocked,
3410
+ getFormStaleVersion,
2899
3411
  getMergedStyleRegistry,
2900
3412
  getNavigationItemAriaLabel,
2901
3413
  getNavigationItemHref,
@@ -2913,6 +3425,7 @@ function transformPagesData(pages) {
2913
3425
  hasInlineFormatting,
2914
3426
  isBottomTabMenuItemActive,
2915
3427
  isDoubleWebHeaderPreset,
3428
+ isFormListParam,
2916
3429
  isKnownStyleName,
2917
3430
  isMenuItemActiveOnMobile,
2918
3431
  isMenuItemActiveOnWeb,
@@ -2946,18 +3459,21 @@ function transformPagesData(pages) {
2946
3459
  matchesMobilePath,
2947
3460
  matchesWebPath,
2948
3461
  mergeHeaderLayers,
3462
+ nextSortOnHeaderClick,
2949
3463
  normalizePagesResolvePath,
2950
3464
  pageUrlToMobileRoute,
2951
3465
  parseDimensionToReactNative,
2952
3466
  parseDimensionToWeb,
2953
3467
  parseFieldsMapCatalog,
2954
3468
  parseFieldsMapLabels,
3469
+ parseFormListQuery,
2955
3470
  parseFormRecordPrefill,
2956
3471
  parseInlineRich,
2957
3472
  parseOptionCatalog,
2958
3473
  parseOptionCodes,
2959
3474
  parseOptionLabels,
2960
3475
  parseSpacing,
3476
+ pickFormListQuery,
2961
3477
  previewKeywordFromPath,
2962
3478
  radiusToPx,
2963
3479
  replaceCalcedValues,