@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.mjs CHANGED
@@ -271,7 +271,9 @@ var BASE_STYLE_REGISTRY = {
271
271
  version: { description: "Build/version diagnostic surface", category: "auth", canHaveChildren: false },
272
272
  "ref-container": { description: "Renders content referenced from another section", category: "layout", canHaveChildren: true },
273
273
  "data-container": { description: "Data-scoped container (renders subtree against a data scope)", category: "layout", canHaveChildren: true },
274
- "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 }
274
+ "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 },
275
+ "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 },
276
+ "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 }
275
277
  };
276
278
  var STYLE_REGISTRY = BASE_STYLE_REGISTRY;
277
279
  var PLUGIN_STYLE_REGISTRY = {};
@@ -435,6 +437,35 @@ var ENDPOINTS = {
435
437
  SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
436
438
  UPDATE: `${API_VERSION_PREFIX}/forms/update`,
437
439
  DELETE: `${API_VERSION_PREFIX}/forms/delete`
440
+ },
441
+ /**
442
+ * `entry-form-list` / `data-view` lists. A list never has its own create,
443
+ * update or delete route: writes go through {@link ENDPOINTS.FORMS}. The
444
+ * first paint reads `list_state` from the page payload; these routes serve
445
+ * the interactions after it. Path segments are numeric ids, except the
446
+ * action id and the field key, which are encoded.
447
+ */
448
+ LISTS: {
449
+ STATE: (sectionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/state`,
450
+ QUICK_ACTION: (sectionId, recordId, actionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/actions/${encodeURIComponent(actionId)}`,
451
+ HISTORY: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/history`,
452
+ VERSION: (sectionId, recordId, version) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}`,
453
+ COMPARE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/compare`,
454
+ RESTORE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/restore`,
455
+ VERSION_FILE: (sectionId, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`,
456
+ /** Current file of a record shown by a list / data-view / entry-record (F165). */
457
+ CURRENT_FILE: (sectionId, recordId, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/files/${encodeURIComponent(fieldKey)}`
458
+ },
459
+ /**
460
+ * Admin data-browser record history (contract 6). Route permission
461
+ * `admin.data.read`; the controller also requires table UPDATE.
462
+ */
463
+ ADMIN_DATA_HISTORY: {
464
+ HISTORY: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/history`,
465
+ VERSION: (tableName, recordId, version) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}`,
466
+ COMPARE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/compare`,
467
+ RESTORE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/restore`,
468
+ VERSION_FILE: (tableName, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`
438
469
  }
439
470
  };
440
471
  var HEADER_CLIENT_TYPE = "X-Client-Type";
@@ -442,6 +473,73 @@ var CLIENT_TYPE_WEB = "web";
442
473
  var CLIENT_TYPE_MOBILE = "mobile";
443
474
  var CLIENT_TYPE_MOBILE_AND_WEB = "mobile_and_web";
444
475
 
476
+ // src/api/formListErrors.ts
477
+ function envelope(error) {
478
+ const response = error?.response;
479
+ const status = response?.status;
480
+ const data = response?.data?.data;
481
+ if (typeof status !== "number" || typeof data !== "object" || data === null || Array.isArray(data)) {
482
+ return null;
483
+ }
484
+ return { status, message: response?.data?.message, data };
485
+ }
486
+ function getFormStaleVersion(error) {
487
+ const found = envelope(error);
488
+ if (found === null || found.status !== 409 || found.data.reason !== "stale_version") {
489
+ return null;
490
+ }
491
+ const { record_id: recordId, expected_version: expected, current_version: current } = found.data;
492
+ if (typeof recordId !== "number" || typeof expected !== "number" || typeof current !== "number") {
493
+ return null;
494
+ }
495
+ return { reason: "stale_version", record_id: recordId, expected_version: expected, current_version: current };
496
+ }
497
+ function getFormListRestoreBlocked(error) {
498
+ const found = envelope(error);
499
+ if (found === null || found.status !== 422 || found.data.reason !== "restore_blocked") {
500
+ return null;
501
+ }
502
+ const { record_id: recordId, from_version: fromVersion, blockers } = found.data;
503
+ if (typeof recordId !== "number" || typeof fromVersion !== "number" || !Array.isArray(blockers)) {
504
+ return null;
505
+ }
506
+ return {
507
+ reason: "restore_blocked",
508
+ record_id: recordId,
509
+ from_version: fromVersion,
510
+ blockers
511
+ };
512
+ }
513
+ function getFormInvalidData(error) {
514
+ const found = envelope(error);
515
+ if (found === null || found.status !== 422 || found.data.reason !== "invalid_form_data" || !Array.isArray(found.data.errors)) {
516
+ return null;
517
+ }
518
+ const errors = [];
519
+ for (const entry of found.data.errors) {
520
+ if (typeof entry !== "object" || entry === null) {
521
+ continue;
522
+ }
523
+ const { field, key, rule, message } = entry;
524
+ if (typeof field === "string" && typeof key === "string" && typeof rule === "string" && typeof message === "string") {
525
+ errors.push({ field, key, rule, message });
526
+ }
527
+ }
528
+ return errors.length > 0 ? { reason: "invalid_form_data", errors } : null;
529
+ }
530
+ function getFormListFailure(error) {
531
+ const found = envelope(error);
532
+ if (found === null || typeof found.data.reason !== "string" || found.data.reason === "") {
533
+ return null;
534
+ }
535
+ return {
536
+ status: found.status,
537
+ reason: found.data.reason,
538
+ parameter: typeof found.data.parameter === "string" && found.data.parameter !== "" ? found.data.parameter : null,
539
+ message: typeof found.message === "string" ? found.message : null
540
+ };
541
+ }
542
+
445
543
  // src/api/pagesResolve.ts
446
544
  function normalizePagesResolvePath(rawPath) {
447
545
  const withoutOrigin = rawPath.includes("://") ? (() => {
@@ -1659,10 +1757,12 @@ function serializeFieldsMapLabels(labels) {
1659
1757
  // src/content/formRecordPrefill.ts
1660
1758
  var FORM_RECORD_PREFILL_SKIP_FIELDS = /* @__PURE__ */ new Set([
1661
1759
  "record_id",
1760
+ "_version",
1662
1761
  "entry_date",
1663
1762
  "id_users",
1664
1763
  "user_name",
1665
1764
  "user_code",
1765
+ "id_action_trigger_types",
1666
1766
  "id_actionTriggerTypes",
1667
1767
  "triggerType",
1668
1768
  "id_languages",
@@ -1685,12 +1785,45 @@ function asScalarString(value) {
1685
1785
  }
1686
1786
  return null;
1687
1787
  }
1788
+ function asFilesCell(value) {
1789
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1790
+ return null;
1791
+ }
1792
+ const files = value.files;
1793
+ if (!Array.isArray(files)) {
1794
+ return null;
1795
+ }
1796
+ const out = [];
1797
+ for (const entry of files) {
1798
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
1799
+ continue;
1800
+ }
1801
+ const file = entry;
1802
+ const index = typeof file.index === "number" ? file.index : Number(file.index);
1803
+ const name = typeof file.name === "string" ? file.name : null;
1804
+ const url = typeof file.url === "string" ? file.url : null;
1805
+ if (!Number.isFinite(index) || name === null || url === null) {
1806
+ continue;
1807
+ }
1808
+ const mime = typeof file.mime === "string" ? file.mime : file.mime === null ? null : void 0;
1809
+ 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;
1810
+ out.push({
1811
+ index: Math.trunc(index),
1812
+ name,
1813
+ url,
1814
+ ...mime !== void 0 ? { mime } : {},
1815
+ ...size !== void 0 ? { size } : {}
1816
+ });
1817
+ }
1818
+ return { files: out };
1819
+ }
1688
1820
  function parseFormRecordPrefill(section) {
1689
1821
  const sectionDataArray = section?.section_data;
1690
1822
  if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
1691
1823
  return { recordId: null, values: {} };
1692
1824
  }
1693
1825
  const recordGroups = {};
1826
+ const recordVersions = {};
1694
1827
  for (const row of sectionDataArray) {
1695
1828
  if (!row || typeof row !== "object" || Array.isArray(row)) {
1696
1829
  continue;
@@ -1704,11 +1837,22 @@ function parseFormRecordPrefill(section) {
1704
1837
  if (!recordGroups[recordId]) {
1705
1838
  recordGroups[recordId] = {};
1706
1839
  }
1840
+ const version2 = asRecordVersion(record._version);
1841
+ if (version2 !== null && recordVersions[recordId] === void 0) {
1842
+ recordVersions[recordId] = version2;
1843
+ }
1707
1844
  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;
1708
1845
  for (const [fieldName, fieldValue] of Object.entries(record)) {
1709
1846
  if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
1710
1847
  continue;
1711
1848
  }
1849
+ const filesCell = asFilesCell(fieldValue);
1850
+ if (filesCell !== null) {
1851
+ if (languageId === 1 || !recordGroups[recordId][fieldName]) {
1852
+ recordGroups[recordId][fieldName] = filesCell;
1853
+ }
1854
+ continue;
1855
+ }
1712
1856
  const value = asScalarString(fieldValue);
1713
1857
  if (value === null) {
1714
1858
  continue;
@@ -1721,7 +1865,10 @@ function parseFormRecordPrefill(section) {
1721
1865
  }
1722
1866
  } else if (typeof languageId === "number") {
1723
1867
  const current = recordGroups[recordId][fieldName];
1724
- if (typeof current === "string" || !current) {
1868
+ if (typeof current === "string" || Array.isArray(current) === false || !current) {
1869
+ if (typeof current === "object" && current !== null && "files" in current) {
1870
+ continue;
1871
+ }
1725
1872
  recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
1726
1873
  } else {
1727
1874
  const langValues = current;
@@ -1743,7 +1890,12 @@ function parseFormRecordPrefill(section) {
1743
1890
  return { recordId: null, values: {} };
1744
1891
  }
1745
1892
  const id = Number(firstRecordId);
1746
- return { recordId: id, values: recordGroups[id] ?? {} };
1893
+ const version = recordVersions[id];
1894
+ return version === void 0 ? { recordId: id, values: recordGroups[id] ?? {} } : { recordId: id, values: recordGroups[id] ?? {}, version };
1895
+ }
1896
+ function asRecordVersion(value) {
1897
+ const candidate = typeof value === "number" ? value : typeof value === "string" && /^[1-9]\d*$/.test(value.trim()) ? Number(value.trim()) : Number.NaN;
1898
+ return Number.isSafeInteger(candidate) && candidate >= 1 ? candidate : null;
1747
1899
  }
1748
1900
  function flattenFormRecordPrefillValues(values, languageId) {
1749
1901
  const out = {};
@@ -1752,6 +1904,9 @@ function flattenFormRecordPrefillValues(values, languageId) {
1752
1904
  out[key] = value;
1753
1905
  continue;
1754
1906
  }
1907
+ if (value && typeof value === "object" && !Array.isArray(value) && "files" in value) {
1908
+ continue;
1909
+ }
1755
1910
  if (!Array.isArray(value) || value.length === 0) {
1756
1911
  continue;
1757
1912
  }
@@ -1768,6 +1923,319 @@ function flattenFormRecordPrefillValues(values, languageId) {
1768
1923
  return out;
1769
1924
  }
1770
1925
 
1926
+ // src/content/formListState.ts
1927
+ var FORM_LIST_MODES = ["view", "edit", "create", "history"];
1928
+ var FORM_LIST_MAX_PAGE = 1e6;
1929
+ var FORM_LIST_MAX_VALUE_BYTES = 1e3;
1930
+ var FORM_LIST_SEARCH_MIN_LENGTH = 2;
1931
+ var FORM_LIST_SEARCH_MAX_LENGTH = 100;
1932
+ var FORM_LIST_MAX_SORTS = 3;
1933
+ var FORM_LIST_MAX_ROUTE_PARAMS = 8;
1934
+ var FORM_LIST_MAX_ROUTE_VALUE_LENGTH = 255;
1935
+ var POSITIVE_INT = /^[1-9][0-9]{0,8}$/;
1936
+ var SORT_ITEM = /^([A-Za-z][A-Za-z0-9_]{0,63}):(asc|desc)$/;
1937
+ var CONTROL_ID = /^[a-z][a-z0-9_]{0,31}$/;
1938
+ var LIST_KEY = /^[a-z][a-z0-9_]{0,31}$/;
1939
+ var PHP_TRIM_CHARACTERS = " \n\r\0\v";
1940
+ function emptyFormListUrlState() {
1941
+ return { page: 1, q: null, sort: [], filters: {}, record: null, mode: null };
1942
+ }
1943
+ function isFormListParam(name, key) {
1944
+ return name.startsWith(`${key}.`);
1945
+ }
1946
+ function parseFormListQuery(query, key, rules = {}) {
1947
+ const prefix = `${key}.`;
1948
+ const own = /* @__PURE__ */ new Map();
1949
+ for (const pair of splitPairs(query)) {
1950
+ const equals = pair.indexOf("=");
1951
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
1952
+ if (!name.startsWith(prefix)) {
1953
+ continue;
1954
+ }
1955
+ if (own.has(name)) {
1956
+ return refused(400, "duplicate_list_parameter", name, `The parameter "${name}" is given twice.`);
1957
+ }
1958
+ own.set(name, lenientDecode(equals === -1 ? "" : pair.slice(equals + 1)));
1959
+ }
1960
+ let page = 1;
1961
+ let q = null;
1962
+ let sort = [];
1963
+ const filters = {};
1964
+ let record = null;
1965
+ let mode = null;
1966
+ for (const [name, value] of own) {
1967
+ const suffix = name.slice(prefix.length);
1968
+ if (utf8Length(value) > FORM_LIST_MAX_VALUE_BYTES) {
1969
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is too long.`);
1970
+ }
1971
+ if (suffix === "page") {
1972
+ const parsed = positiveInt(value);
1973
+ if (parsed === null) {
1974
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
1975
+ }
1976
+ if (parsed > FORM_LIST_MAX_PAGE) {
1977
+ return refused(400, "invalid_list_parameter", name, `The page in "${name}" is out of range.`);
1978
+ }
1979
+ page = parsed;
1980
+ } else if (suffix === "q") {
1981
+ const term = phpTrim(value);
1982
+ if (term === "") {
1983
+ q = null;
1984
+ continue;
1985
+ }
1986
+ const length = Array.from(term).length;
1987
+ if (length < FORM_LIST_SEARCH_MIN_LENGTH || length > FORM_LIST_SEARCH_MAX_LENGTH) {
1988
+ return refused(400, "invalid_list_parameter", name, `A search has ${FORM_LIST_SEARCH_MIN_LENGTH} to ${FORM_LIST_SEARCH_MAX_LENGTH} characters.`);
1989
+ }
1990
+ q = term;
1991
+ } else if (suffix === "sort") {
1992
+ const sorts = parseSort(value, name, rules.sortable);
1993
+ if (!Array.isArray(sorts)) {
1994
+ return { ok: false, error: sorts };
1995
+ }
1996
+ sort = sorts;
1997
+ } else if (suffix === "record") {
1998
+ const parsed = positiveInt(value);
1999
+ if (parsed === null) {
2000
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
2001
+ }
2002
+ record = parsed;
2003
+ } else if (suffix === "mode") {
2004
+ if (!isMode(value)) {
2005
+ return refused(400, "invalid_list_parameter", name, `The mode in "${name}" is view, edit, create or history.`);
2006
+ }
2007
+ mode = value;
2008
+ } else if (suffix.startsWith("f.")) {
2009
+ const controlId = suffix.slice(2);
2010
+ const known = rules.controls === void 0 ? CONTROL_ID.test(controlId) : rules.controls.includes(controlId);
2011
+ if (!known) {
2012
+ return refused(400, "unknown_list_parameter", name, `The list has no filter "${controlId}".`);
2013
+ }
2014
+ if (value !== "") {
2015
+ filters[controlId] = value;
2016
+ }
2017
+ } else {
2018
+ return refused(400, "unknown_list_parameter", name, `The list has no parameter "${name}".`);
2019
+ }
2020
+ }
2021
+ return withMode({ page, q, sort, filters, record, mode }, key, rules);
2022
+ }
2023
+ function encodeFormListQuery(key, state) {
2024
+ const query = {};
2025
+ if (state.page > 1) {
2026
+ query[`${key}.page`] = String(state.page);
2027
+ }
2028
+ if (state.q !== null && state.q !== "") {
2029
+ query[`${key}.q`] = state.q;
2030
+ }
2031
+ if (state.sort.length > 0) {
2032
+ query[`${key}.sort`] = state.sort.map((item) => `${item.field}:${item.direction}`).join(",");
2033
+ }
2034
+ for (const [id, value] of Object.entries(state.filters)) {
2035
+ if (value !== "") {
2036
+ query[`${key}.f.${id}`] = value;
2037
+ }
2038
+ }
2039
+ if (state.record !== null) {
2040
+ query[`${key}.record`] = String(state.record);
2041
+ }
2042
+ if (state.mode !== null) {
2043
+ query[`${key}.mode`] = state.mode;
2044
+ }
2045
+ return query;
2046
+ }
2047
+ function formListQueryString(base, key, state) {
2048
+ const kept = splitPairs(base).filter((pair) => {
2049
+ const equals = pair.indexOf("=");
2050
+ return !isFormListParam(lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), key);
2051
+ });
2052
+ const written = Object.entries(encodeFormListQuery(key, state)).map(
2053
+ ([name, value]) => `${encodeURIComponent(name)}=${encodeValue(value)}`
2054
+ );
2055
+ return [...kept, ...written].join("&");
2056
+ }
2057
+ function applyFormListUrlChange(state, change) {
2058
+ switch (change.type) {
2059
+ case "page":
2060
+ return { ...state, page: clampPage(change.page) };
2061
+ case "search": {
2062
+ const term = change.q === null ? "" : phpTrim(change.q);
2063
+ return { ...state, q: term === "" ? null : term, page: 1 };
2064
+ }
2065
+ case "sort":
2066
+ return { ...state, sort: change.sort.slice(0, FORM_LIST_MAX_SORTS).map((item) => ({ ...item })), page: 1 };
2067
+ case "filter": {
2068
+ const filters = { ...state.filters };
2069
+ if (change.value === null || change.value === "") {
2070
+ delete filters[change.id];
2071
+ } else {
2072
+ filters[change.id] = change.value;
2073
+ }
2074
+ return { ...state, filters, page: 1 };
2075
+ }
2076
+ case "reset":
2077
+ return { ...state, page: 1, q: null, sort: [], filters: {} };
2078
+ case "open":
2079
+ return { ...state, record: change.record, mode: change.mode ?? "view" };
2080
+ case "create":
2081
+ return { ...state, record: null, mode: "create" };
2082
+ case "close":
2083
+ return { ...state, record: null, mode: null };
2084
+ default: {
2085
+ const unhandled = change;
2086
+ throw new Error(`Unknown list state change: ${JSON.stringify(unhandled)}`);
2087
+ }
2088
+ }
2089
+ }
2090
+ function nextSortOnHeaderClick(current, field) {
2091
+ const first = current[0];
2092
+ if (first === void 0 || first.field !== field) {
2093
+ return [{ field, direction: "asc" }];
2094
+ }
2095
+ if (first.direction === "asc") {
2096
+ return [{ field, direction: "desc" }];
2097
+ }
2098
+ return [];
2099
+ }
2100
+ function pickFormListQuery(query) {
2101
+ return splitPairs(query).filter((pair) => {
2102
+ const equals = pair.indexOf("=");
2103
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
2104
+ const dot = name.indexOf(".");
2105
+ return dot > 0 && LIST_KEY.test(name.slice(0, dot));
2106
+ }).join("&");
2107
+ }
2108
+ function formListRouteQuery(route) {
2109
+ if (!route) {
2110
+ return "";
2111
+ }
2112
+ return Object.entries(route).filter((entry) => {
2113
+ const [name, value] = entry;
2114
+ return ROUTE_PARAM_NAME.test(name) && typeof value === "string" && value !== "" && value.length <= FORM_LIST_MAX_ROUTE_VALUE_LENGTH;
2115
+ }).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("&");
2116
+ }
2117
+ function formListCacheKey(scope, query) {
2118
+ const own = splitPairs(query).map((pair) => {
2119
+ const equals = pair.indexOf("=");
2120
+ return [lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), lenientDecode(equals === -1 ? "" : pair.slice(equals + 1))];
2121
+ }).filter(([name]) => isFormListParam(name, scope.key)).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, value]) => `${name}=${value}`).join("&");
2122
+ return [
2123
+ "form-list",
2124
+ scope.apiBase,
2125
+ scope.account === null ? "guest" : String(scope.account),
2126
+ scope.languageId,
2127
+ scope.platform,
2128
+ scope.pageId,
2129
+ scope.sectionId,
2130
+ formListRouteQuery(scope.route),
2131
+ own
2132
+ ];
2133
+ }
2134
+ var ROUTE_PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
2135
+ function refused(status, reason, parameter, message) {
2136
+ return { ok: false, error: { status, reason, parameter, message } };
2137
+ }
2138
+ function withMode(state, key, rules) {
2139
+ let mode = state.mode;
2140
+ if (mode === null && state.record !== null) {
2141
+ mode = "view";
2142
+ }
2143
+ if (mode === "create") {
2144
+ if (state.record !== null) {
2145
+ return refused(400, "invalid_list_parameter", `${key}.record`, "A new entry has no record.");
2146
+ }
2147
+ if (rules.allowCreate === false) {
2148
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow new entries.");
2149
+ }
2150
+ } else if (mode !== null && state.record === null) {
2151
+ return refused(400, "invalid_list_parameter", `${key}.record`, `The mode "${mode}" needs a record.`);
2152
+ }
2153
+ if (mode === "edit" && rules.allowUpdate === false) {
2154
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow editing.");
2155
+ }
2156
+ if (mode === "history" && rules.showHistory === false) {
2157
+ return refused(403, "history_disabled", `${key}.mode`, "This list does not offer history.");
2158
+ }
2159
+ return { ok: true, state: { ...state, mode } };
2160
+ }
2161
+ function parseSort(value, name, sortable) {
2162
+ if (value === "") {
2163
+ return [];
2164
+ }
2165
+ const items = value.split(",");
2166
+ const fail = (message) => ({ status: 400, reason: "invalid_list_parameter", parameter: name, message });
2167
+ if (items.length > FORM_LIST_MAX_SORTS) {
2168
+ return fail(`At most ${FORM_LIST_MAX_SORTS} sort keys.`);
2169
+ }
2170
+ const sorts = [];
2171
+ const seen = /* @__PURE__ */ new Set();
2172
+ for (const item of items) {
2173
+ const match = SORT_ITEM.exec(item);
2174
+ if (match === null) {
2175
+ return fail('A sort key is "column:asc" or "column:desc".');
2176
+ }
2177
+ const field = match[1] ?? "";
2178
+ const direction = match[2] === "desc" ? "desc" : "asc";
2179
+ if (sortable !== void 0 && !sortable.includes(field)) {
2180
+ return fail(`The list cannot be sorted by "${field}".`);
2181
+ }
2182
+ if (seen.has(field)) {
2183
+ return fail(`"${field}" is sorted twice.`);
2184
+ }
2185
+ seen.add(field);
2186
+ sorts.push({ field, direction });
2187
+ }
2188
+ return sorts;
2189
+ }
2190
+ function phpTrim(text) {
2191
+ let start = 0;
2192
+ let end = text.length;
2193
+ while (start < end && PHP_TRIM_CHARACTERS.includes(text.charAt(start))) {
2194
+ start += 1;
2195
+ }
2196
+ while (end > start && PHP_TRIM_CHARACTERS.includes(text.charAt(end - 1))) {
2197
+ end -= 1;
2198
+ }
2199
+ return text.slice(start, end);
2200
+ }
2201
+ function positiveInt(value) {
2202
+ return POSITIVE_INT.test(value) ? Number(value) : null;
2203
+ }
2204
+ function isMode(value) {
2205
+ return FORM_LIST_MODES.includes(value);
2206
+ }
2207
+ function clampPage(page) {
2208
+ if (!Number.isFinite(page)) {
2209
+ return 1;
2210
+ }
2211
+ return Math.min(FORM_LIST_MAX_PAGE, Math.max(1, Math.trunc(page)));
2212
+ }
2213
+ function splitPairs(query) {
2214
+ const text = typeof query === "string" ? query : query.toString();
2215
+ const trimmed = text.startsWith("?") ? text.slice(1) : text;
2216
+ return trimmed.split("&").filter((pair) => pair !== "");
2217
+ }
2218
+ function lenientDecode(text) {
2219
+ return text.replace(/\+/g, " ").replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
2220
+ try {
2221
+ return decodeURIComponent(run);
2222
+ } catch {
2223
+ return run;
2224
+ }
2225
+ });
2226
+ }
2227
+ function encodeValue(value) {
2228
+ return encodeURIComponent(value).replace(/%3A/g, ":").replace(/%2C/g, ",");
2229
+ }
2230
+ function utf8Length(text) {
2231
+ let bytes = 0;
2232
+ for (const character of text) {
2233
+ const code = character.codePointAt(0) ?? 0;
2234
+ bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
2235
+ }
2236
+ return bytes;
2237
+ }
2238
+
1771
2239
  // src/navigation/headerPreset.ts
1772
2240
  var WEB_HEADER_PRESET_VALUES = [
1773
2241
  "simple",
@@ -2620,6 +3088,14 @@ export {
2620
3088
  ENDPOINTS,
2621
3089
  FIELDS_MAP_STYLE_CONFIG,
2622
3090
  FONT_SIZE_PX,
3091
+ FORM_LIST_MAX_PAGE,
3092
+ FORM_LIST_MAX_ROUTE_PARAMS,
3093
+ FORM_LIST_MAX_ROUTE_VALUE_LENGTH,
3094
+ FORM_LIST_MAX_SORTS,
3095
+ FORM_LIST_MAX_VALUE_BYTES,
3096
+ FORM_LIST_MODES,
3097
+ FORM_LIST_SEARCH_MAX_LENGTH,
3098
+ FORM_LIST_SEARCH_MIN_LENGTH,
2623
3099
  FORM_RECORD_PREFILL_SKIP_FIELDS,
2624
3100
  FULL_RADIUS_PX,
2625
3101
  HEADER_CLIENT_TYPE,
@@ -2650,7 +3126,10 @@ export {
2650
3126
  WEB_HEADER_PRESET_OPTIONS,
2651
3127
  WEB_HEADER_PRESET_VALUES,
2652
3128
  _resetPluginStyleRegistry,
3129
+ applyFormListUrlChange,
2653
3130
  arePreviewPreferencesEqual,
3131
+ asFilesCell,
3132
+ asRecordVersion,
2654
3133
  buildConditionContext,
2655
3134
  buildPagesResolvePath,
2656
3135
  buildPagesResolveQuery,
@@ -2661,6 +3140,8 @@ export {
2661
3140
  classifyClassString,
2662
3141
  collectPageIdsFromMenuItems,
2663
3142
  colorToHex,
3143
+ emptyFormListUrlState,
3144
+ encodeFormListQuery,
2664
3145
  evaluateCondition,
2665
3146
  expandedIdsForActiveTrail,
2666
3147
  extendStyleRegistry,
@@ -2675,7 +3156,14 @@ export {
2675
3156
  footerColumnItems,
2676
3157
  footerGroupLinks,
2677
3158
  footerStandaloneItems,
3159
+ formListCacheKey,
3160
+ formListQueryString,
3161
+ formListRouteQuery,
2678
3162
  formatRateLimitMessage,
3163
+ getFormInvalidData,
3164
+ getFormListFailure,
3165
+ getFormListRestoreBlocked,
3166
+ getFormStaleVersion,
2679
3167
  getMergedStyleRegistry,
2680
3168
  getNavigationItemAriaLabel,
2681
3169
  getNavigationItemHref,
@@ -2693,6 +3181,7 @@ export {
2693
3181
  hasInlineFormatting,
2694
3182
  isBottomTabMenuItemActive,
2695
3183
  isDoubleWebHeaderPreset,
3184
+ isFormListParam,
2696
3185
  isKnownStyleName,
2697
3186
  isMenuItemActiveOnMobile,
2698
3187
  isMenuItemActiveOnWeb,
@@ -2726,18 +3215,21 @@ export {
2726
3215
  matchesMobilePath,
2727
3216
  matchesWebPath,
2728
3217
  mergeHeaderLayers,
3218
+ nextSortOnHeaderClick,
2729
3219
  normalizePagesResolvePath,
2730
3220
  pageUrlToMobileRoute,
2731
3221
  parseDimensionToReactNative,
2732
3222
  parseDimensionToWeb,
2733
3223
  parseFieldsMapCatalog,
2734
3224
  parseFieldsMapLabels,
3225
+ parseFormListQuery,
2735
3226
  parseFormRecordPrefill,
2736
3227
  parseInlineRich,
2737
3228
  parseOptionCatalog,
2738
3229
  parseOptionCodes,
2739
3230
  parseOptionLabels,
2740
3231
  parseSpacing,
3232
+ pickFormListQuery,
2741
3233
  previewKeywordFromPath,
2742
3234
  radiusToPx,
2743
3235
  replaceCalcedValues,
@@ -1,5 +1,5 @@
1
1
  export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestHealth, l as IPluginManifestLookupExtension, m as IPluginManifestMobile, n as IPluginManifestPermission, o as IPluginManifestRealtimeTopic, p as IPluginManifestScheduledJob, q as IPluginManifestSecurity, r as IPluginManifestStyle, s as IPluginManifestTrustLevel } from '../manifest-8YXAk-4o.mjs';
2
- import { I as IStyleRegistryEntry } from '../styles.registry-IjDTff8P.mjs';
2
+ import { I as IStyleRegistryEntry } from '../styles.registry-aopb3vsI.mjs';
3
3
  import '../common-qaDIAYS3.mjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestHealth, l as IPluginManifestLookupExtension, m as IPluginManifestMobile, n as IPluginManifestPermission, o as IPluginManifestRealtimeTopic, p as IPluginManifestScheduledJob, q as IPluginManifestSecurity, r as IPluginManifestStyle, s as IPluginManifestTrustLevel } from '../manifest-8YXAk-4o.js';
2
- import { I as IStyleRegistryEntry } from '../styles.registry-BBd9T2Ox.js';
2
+ import { I as IStyleRegistryEntry } from '../styles.registry-BKWoDg7q.js';
3
3
  import '../common-qaDIAYS3.js';
4
4
 
5
5
  /**
@@ -287,7 +287,9 @@ var BASE_STYLE_REGISTRY = {
287
287
  version: { description: "Build/version diagnostic surface", category: "auth", canHaveChildren: false },
288
288
  "ref-container": { description: "Renders content referenced from another section", category: "layout", canHaveChildren: true },
289
289
  "data-container": { description: "Data-scoped container (renders subtree against a data scope)", category: "layout", canHaveChildren: true },
290
- "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 }
290
+ "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 },
291
+ "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 },
292
+ "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 }
291
293
  };
292
294
  var PLUGIN_STYLE_REGISTRY = {};
293
295
  var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
@@ -239,7 +239,9 @@ var BASE_STYLE_REGISTRY = {
239
239
  version: { description: "Build/version diagnostic surface", category: "auth", canHaveChildren: false },
240
240
  "ref-container": { description: "Renders content referenced from another section", category: "layout", canHaveChildren: true },
241
241
  "data-container": { description: "Data-scoped container (renders subtree against a data scope)", category: "layout", canHaveChildren: true },
242
- "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 }
242
+ "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 },
243
+ "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 },
244
+ "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 }
243
245
  };
244
246
  var PLUGIN_STYLE_REGISTRY = {};
245
247
  var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
- import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-IjDTff8P.mjs';
2
- export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, e as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, f as _resetPluginStyleRegistry, g as extendStyleRegistry, h as getMergedStyleRegistry, i as getPluginStyleRegistry } from '../styles.registry-IjDTff8P.mjs';
1
+ import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-aopb3vsI.mjs';
2
+ export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, e as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, f as _resetPluginStyleRegistry, g as extendStyleRegistry, h as getMergedStyleRegistry, i as getPluginStyleRegistry } from '../styles.registry-aopb3vsI.mjs';
3
3
  import '../common-qaDIAYS3.mjs';
4
4
 
5
5
  /**