@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.mjs CHANGED
@@ -271,8 +271,20 @@ 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": {
276
+ 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",
277
+ category: "forms",
278
+ canHaveChildren: true
279
+ },
280
+ "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
281
  };
282
+ var FORM_SECTION_STYLE_NAMES = [
283
+ "form-record",
284
+ "form-log",
285
+ "entry-record-form",
286
+ "entry-form-list"
287
+ ];
276
288
  var STYLE_REGISTRY = BASE_STYLE_REGISTRY;
277
289
  var PLUGIN_STYLE_REGISTRY = {};
278
290
  var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
@@ -435,6 +447,35 @@ var ENDPOINTS = {
435
447
  SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
436
448
  UPDATE: `${API_VERSION_PREFIX}/forms/update`,
437
449
  DELETE: `${API_VERSION_PREFIX}/forms/delete`
450
+ },
451
+ /**
452
+ * `entry-form-list` / `data-view` lists. A list never has its own create,
453
+ * update or delete route: writes go through {@link ENDPOINTS.FORMS}. The
454
+ * first paint reads `list_state` from the page payload; these routes serve
455
+ * the interactions after it. Path segments are numeric ids, except the
456
+ * action id and the field key, which are encoded.
457
+ */
458
+ LISTS: {
459
+ STATE: (sectionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/state`,
460
+ QUICK_ACTION: (sectionId, recordId, actionId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/actions/${encodeURIComponent(actionId)}`,
461
+ HISTORY: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/history`,
462
+ VERSION: (sectionId, recordId, version) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}`,
463
+ COMPARE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/compare`,
464
+ RESTORE: (sectionId, recordId) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/restore`,
465
+ VERSION_FILE: (sectionId, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`,
466
+ /** Current file of a record shown by a list / data-view / entry-record (F165). */
467
+ CURRENT_FILE: (sectionId, recordId, fieldKey) => `${API_VERSION_PREFIX}/lists/${sectionId}/records/${recordId}/files/${encodeURIComponent(fieldKey)}`
468
+ },
469
+ /**
470
+ * Admin data-browser record history (contract 6). Route permission
471
+ * `admin.data.read`; the controller also requires table UPDATE.
472
+ */
473
+ ADMIN_DATA_HISTORY: {
474
+ HISTORY: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/history`,
475
+ VERSION: (tableName, recordId, version) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}`,
476
+ COMPARE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/compare`,
477
+ RESTORE: (tableName, recordId) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/restore`,
478
+ VERSION_FILE: (tableName, recordId, version, fieldKey) => `${API_VERSION_PREFIX}/admin/data/tables/${encodeURIComponent(tableName)}/records/${recordId}/versions/${version}/files/${encodeURIComponent(fieldKey)}`
438
479
  }
439
480
  };
440
481
  var HEADER_CLIENT_TYPE = "X-Client-Type";
@@ -442,6 +483,73 @@ var CLIENT_TYPE_WEB = "web";
442
483
  var CLIENT_TYPE_MOBILE = "mobile";
443
484
  var CLIENT_TYPE_MOBILE_AND_WEB = "mobile_and_web";
444
485
 
486
+ // src/api/formListErrors.ts
487
+ function envelope(error) {
488
+ const response = error?.response;
489
+ const status = response?.status;
490
+ const data = response?.data?.data;
491
+ if (typeof status !== "number" || typeof data !== "object" || data === null || Array.isArray(data)) {
492
+ return null;
493
+ }
494
+ return { status, message: response?.data?.message, data };
495
+ }
496
+ function getFormStaleVersion(error) {
497
+ const found = envelope(error);
498
+ if (found === null || found.status !== 409 || found.data.reason !== "stale_version") {
499
+ return null;
500
+ }
501
+ const { record_id: recordId, expected_version: expected, current_version: current } = found.data;
502
+ if (typeof recordId !== "number" || typeof expected !== "number" || typeof current !== "number") {
503
+ return null;
504
+ }
505
+ return { reason: "stale_version", record_id: recordId, expected_version: expected, current_version: current };
506
+ }
507
+ function getFormListRestoreBlocked(error) {
508
+ const found = envelope(error);
509
+ if (found === null || found.status !== 422 || found.data.reason !== "restore_blocked") {
510
+ return null;
511
+ }
512
+ const { record_id: recordId, from_version: fromVersion, blockers } = found.data;
513
+ if (typeof recordId !== "number" || typeof fromVersion !== "number" || !Array.isArray(blockers)) {
514
+ return null;
515
+ }
516
+ return {
517
+ reason: "restore_blocked",
518
+ record_id: recordId,
519
+ from_version: fromVersion,
520
+ blockers
521
+ };
522
+ }
523
+ function getFormInvalidData(error) {
524
+ const found = envelope(error);
525
+ if (found === null || found.status !== 422 || found.data.reason !== "invalid_form_data" || !Array.isArray(found.data.errors)) {
526
+ return null;
527
+ }
528
+ const errors = [];
529
+ for (const entry of found.data.errors) {
530
+ if (typeof entry !== "object" || entry === null) {
531
+ continue;
532
+ }
533
+ const { field, key, rule, message } = entry;
534
+ if (typeof field === "string" && typeof key === "string" && typeof rule === "string" && typeof message === "string") {
535
+ errors.push({ field, key, rule, message });
536
+ }
537
+ }
538
+ return errors.length > 0 ? { reason: "invalid_form_data", errors } : null;
539
+ }
540
+ function getFormListFailure(error) {
541
+ const found = envelope(error);
542
+ if (found === null || typeof found.data.reason !== "string" || found.data.reason === "") {
543
+ return null;
544
+ }
545
+ return {
546
+ status: found.status,
547
+ reason: found.data.reason,
548
+ parameter: typeof found.data.parameter === "string" && found.data.parameter !== "" ? found.data.parameter : null,
549
+ message: typeof found.message === "string" ? found.message : null
550
+ };
551
+ }
552
+
445
553
  // src/api/pagesResolve.ts
446
554
  function normalizePagesResolvePath(rawPath) {
447
555
  const withoutOrigin = rawPath.includes("://") ? (() => {
@@ -1659,10 +1767,12 @@ function serializeFieldsMapLabels(labels) {
1659
1767
  // src/content/formRecordPrefill.ts
1660
1768
  var FORM_RECORD_PREFILL_SKIP_FIELDS = /* @__PURE__ */ new Set([
1661
1769
  "record_id",
1770
+ "_version",
1662
1771
  "entry_date",
1663
1772
  "id_users",
1664
1773
  "user_name",
1665
1774
  "user_code",
1775
+ "id_action_trigger_types",
1666
1776
  "id_actionTriggerTypes",
1667
1777
  "triggerType",
1668
1778
  "id_languages",
@@ -1685,12 +1795,45 @@ function asScalarString(value) {
1685
1795
  }
1686
1796
  return null;
1687
1797
  }
1798
+ function asFilesCell(value) {
1799
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1800
+ return null;
1801
+ }
1802
+ const files = value.files;
1803
+ if (!Array.isArray(files)) {
1804
+ return null;
1805
+ }
1806
+ const out = [];
1807
+ for (const entry of files) {
1808
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
1809
+ continue;
1810
+ }
1811
+ const file = entry;
1812
+ const index = typeof file.index === "number" ? file.index : Number(file.index);
1813
+ const name = typeof file.name === "string" ? file.name : null;
1814
+ const url = typeof file.url === "string" ? file.url : null;
1815
+ if (!Number.isFinite(index) || name === null || url === null) {
1816
+ continue;
1817
+ }
1818
+ const mime = typeof file.mime === "string" ? file.mime : file.mime === null ? null : void 0;
1819
+ 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;
1820
+ out.push({
1821
+ index: Math.trunc(index),
1822
+ name,
1823
+ url,
1824
+ ...mime !== void 0 ? { mime } : {},
1825
+ ...size !== void 0 ? { size } : {}
1826
+ });
1827
+ }
1828
+ return { files: out };
1829
+ }
1688
1830
  function parseFormRecordPrefill(section) {
1689
1831
  const sectionDataArray = section?.section_data;
1690
1832
  if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
1691
1833
  return { recordId: null, values: {} };
1692
1834
  }
1693
1835
  const recordGroups = {};
1836
+ const recordVersions = {};
1694
1837
  for (const row of sectionDataArray) {
1695
1838
  if (!row || typeof row !== "object" || Array.isArray(row)) {
1696
1839
  continue;
@@ -1704,11 +1847,22 @@ function parseFormRecordPrefill(section) {
1704
1847
  if (!recordGroups[recordId]) {
1705
1848
  recordGroups[recordId] = {};
1706
1849
  }
1850
+ const version2 = asRecordVersion(record._version);
1851
+ if (version2 !== null && recordVersions[recordId] === void 0) {
1852
+ recordVersions[recordId] = version2;
1853
+ }
1707
1854
  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
1855
  for (const [fieldName, fieldValue] of Object.entries(record)) {
1709
1856
  if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
1710
1857
  continue;
1711
1858
  }
1859
+ const filesCell = asFilesCell(fieldValue);
1860
+ if (filesCell !== null) {
1861
+ if (languageId === 1 || !recordGroups[recordId][fieldName]) {
1862
+ recordGroups[recordId][fieldName] = filesCell;
1863
+ }
1864
+ continue;
1865
+ }
1712
1866
  const value = asScalarString(fieldValue);
1713
1867
  if (value === null) {
1714
1868
  continue;
@@ -1721,7 +1875,10 @@ function parseFormRecordPrefill(section) {
1721
1875
  }
1722
1876
  } else if (typeof languageId === "number") {
1723
1877
  const current = recordGroups[recordId][fieldName];
1724
- if (typeof current === "string" || !current) {
1878
+ if (typeof current === "string" || Array.isArray(current) === false || !current) {
1879
+ if (typeof current === "object" && current !== null && "files" in current) {
1880
+ continue;
1881
+ }
1725
1882
  recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
1726
1883
  } else {
1727
1884
  const langValues = current;
@@ -1743,7 +1900,12 @@ function parseFormRecordPrefill(section) {
1743
1900
  return { recordId: null, values: {} };
1744
1901
  }
1745
1902
  const id = Number(firstRecordId);
1746
- return { recordId: id, values: recordGroups[id] ?? {} };
1903
+ const version = recordVersions[id];
1904
+ return version === void 0 ? { recordId: id, values: recordGroups[id] ?? {} } : { recordId: id, values: recordGroups[id] ?? {}, version };
1905
+ }
1906
+ function asRecordVersion(value) {
1907
+ const candidate = typeof value === "number" ? value : typeof value === "string" && /^[1-9]\d*$/.test(value.trim()) ? Number(value.trim()) : Number.NaN;
1908
+ return Number.isSafeInteger(candidate) && candidate >= 1 ? candidate : null;
1747
1909
  }
1748
1910
  function flattenFormRecordPrefillValues(values, languageId) {
1749
1911
  const out = {};
@@ -1752,6 +1914,9 @@ function flattenFormRecordPrefillValues(values, languageId) {
1752
1914
  out[key] = value;
1753
1915
  continue;
1754
1916
  }
1917
+ if (value && typeof value === "object" && !Array.isArray(value) && "files" in value) {
1918
+ continue;
1919
+ }
1755
1920
  if (!Array.isArray(value) || value.length === 0) {
1756
1921
  continue;
1757
1922
  }
@@ -1768,6 +1933,319 @@ function flattenFormRecordPrefillValues(values, languageId) {
1768
1933
  return out;
1769
1934
  }
1770
1935
 
1936
+ // src/content/formListState.ts
1937
+ var FORM_LIST_MODES = ["view", "edit", "create", "history"];
1938
+ var FORM_LIST_MAX_PAGE = 1e6;
1939
+ var FORM_LIST_MAX_VALUE_BYTES = 1e3;
1940
+ var FORM_LIST_SEARCH_MIN_LENGTH = 2;
1941
+ var FORM_LIST_SEARCH_MAX_LENGTH = 100;
1942
+ var FORM_LIST_MAX_SORTS = 3;
1943
+ var FORM_LIST_MAX_ROUTE_PARAMS = 8;
1944
+ var FORM_LIST_MAX_ROUTE_VALUE_LENGTH = 255;
1945
+ var POSITIVE_INT = /^[1-9][0-9]{0,8}$/;
1946
+ var SORT_ITEM = /^([A-Za-z][A-Za-z0-9_]{0,63}):(asc|desc)$/;
1947
+ var CONTROL_ID = /^[a-z][a-z0-9_]{0,31}$/;
1948
+ var LIST_KEY = /^[a-z][a-z0-9_]{0,31}$/;
1949
+ var PHP_TRIM_CHARACTERS = " \n\r\0\v";
1950
+ function emptyFormListUrlState() {
1951
+ return { page: 1, q: null, sort: [], filters: {}, record: null, mode: null };
1952
+ }
1953
+ function isFormListParam(name, key) {
1954
+ return name.startsWith(`${key}.`);
1955
+ }
1956
+ function parseFormListQuery(query, key, rules = {}) {
1957
+ const prefix = `${key}.`;
1958
+ const own = /* @__PURE__ */ new Map();
1959
+ for (const pair of splitPairs(query)) {
1960
+ const equals = pair.indexOf("=");
1961
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
1962
+ if (!name.startsWith(prefix)) {
1963
+ continue;
1964
+ }
1965
+ if (own.has(name)) {
1966
+ return refused(400, "duplicate_list_parameter", name, `The parameter "${name}" is given twice.`);
1967
+ }
1968
+ own.set(name, lenientDecode(equals === -1 ? "" : pair.slice(equals + 1)));
1969
+ }
1970
+ let page = 1;
1971
+ let q = null;
1972
+ let sort = [];
1973
+ const filters = {};
1974
+ let record = null;
1975
+ let mode = null;
1976
+ for (const [name, value] of own) {
1977
+ const suffix = name.slice(prefix.length);
1978
+ if (utf8Length(value) > FORM_LIST_MAX_VALUE_BYTES) {
1979
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is too long.`);
1980
+ }
1981
+ if (suffix === "page") {
1982
+ const parsed = positiveInt(value);
1983
+ if (parsed === null) {
1984
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
1985
+ }
1986
+ if (parsed > FORM_LIST_MAX_PAGE) {
1987
+ return refused(400, "invalid_list_parameter", name, `The page in "${name}" is out of range.`);
1988
+ }
1989
+ page = parsed;
1990
+ } else if (suffix === "q") {
1991
+ const term = phpTrim(value);
1992
+ if (term === "") {
1993
+ q = null;
1994
+ continue;
1995
+ }
1996
+ const length = Array.from(term).length;
1997
+ if (length < FORM_LIST_SEARCH_MIN_LENGTH || length > FORM_LIST_SEARCH_MAX_LENGTH) {
1998
+ return refused(400, "invalid_list_parameter", name, `A search has ${FORM_LIST_SEARCH_MIN_LENGTH} to ${FORM_LIST_SEARCH_MAX_LENGTH} characters.`);
1999
+ }
2000
+ q = term;
2001
+ } else if (suffix === "sort") {
2002
+ const sorts = parseSort(value, name, rules.sortable);
2003
+ if (!Array.isArray(sorts)) {
2004
+ return { ok: false, error: sorts };
2005
+ }
2006
+ sort = sorts;
2007
+ } else if (suffix === "record") {
2008
+ const parsed = positiveInt(value);
2009
+ if (parsed === null) {
2010
+ return refused(400, "invalid_list_parameter", name, `The parameter "${name}" is a positive whole number.`);
2011
+ }
2012
+ record = parsed;
2013
+ } else if (suffix === "mode") {
2014
+ if (!isMode(value)) {
2015
+ return refused(400, "invalid_list_parameter", name, `The mode in "${name}" is view, edit, create or history.`);
2016
+ }
2017
+ mode = value;
2018
+ } else if (suffix.startsWith("f.")) {
2019
+ const controlId = suffix.slice(2);
2020
+ const known = rules.controls === void 0 ? CONTROL_ID.test(controlId) : rules.controls.includes(controlId);
2021
+ if (!known) {
2022
+ return refused(400, "unknown_list_parameter", name, `The list has no filter "${controlId}".`);
2023
+ }
2024
+ if (value !== "") {
2025
+ filters[controlId] = value;
2026
+ }
2027
+ } else {
2028
+ return refused(400, "unknown_list_parameter", name, `The list has no parameter "${name}".`);
2029
+ }
2030
+ }
2031
+ return withMode({ page, q, sort, filters, record, mode }, key, rules);
2032
+ }
2033
+ function encodeFormListQuery(key, state) {
2034
+ const query = {};
2035
+ if (state.page > 1) {
2036
+ query[`${key}.page`] = String(state.page);
2037
+ }
2038
+ if (state.q !== null && state.q !== "") {
2039
+ query[`${key}.q`] = state.q;
2040
+ }
2041
+ if (state.sort.length > 0) {
2042
+ query[`${key}.sort`] = state.sort.map((item) => `${item.field}:${item.direction}`).join(",");
2043
+ }
2044
+ for (const [id, value] of Object.entries(state.filters)) {
2045
+ if (value !== "") {
2046
+ query[`${key}.f.${id}`] = value;
2047
+ }
2048
+ }
2049
+ if (state.record !== null) {
2050
+ query[`${key}.record`] = String(state.record);
2051
+ }
2052
+ if (state.mode !== null) {
2053
+ query[`${key}.mode`] = state.mode;
2054
+ }
2055
+ return query;
2056
+ }
2057
+ function formListQueryString(base, key, state) {
2058
+ const kept = splitPairs(base).filter((pair) => {
2059
+ const equals = pair.indexOf("=");
2060
+ return !isFormListParam(lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), key);
2061
+ });
2062
+ const written = Object.entries(encodeFormListQuery(key, state)).map(
2063
+ ([name, value]) => `${encodeURIComponent(name)}=${encodeValue(value)}`
2064
+ );
2065
+ return [...kept, ...written].join("&");
2066
+ }
2067
+ function applyFormListUrlChange(state, change) {
2068
+ switch (change.type) {
2069
+ case "page":
2070
+ return { ...state, page: clampPage(change.page) };
2071
+ case "search": {
2072
+ const term = change.q === null ? "" : phpTrim(change.q);
2073
+ return { ...state, q: term === "" ? null : term, page: 1 };
2074
+ }
2075
+ case "sort":
2076
+ return { ...state, sort: change.sort.slice(0, FORM_LIST_MAX_SORTS).map((item) => ({ ...item })), page: 1 };
2077
+ case "filter": {
2078
+ const filters = { ...state.filters };
2079
+ if (change.value === null || change.value === "") {
2080
+ delete filters[change.id];
2081
+ } else {
2082
+ filters[change.id] = change.value;
2083
+ }
2084
+ return { ...state, filters, page: 1 };
2085
+ }
2086
+ case "reset":
2087
+ return { ...state, page: 1, q: null, sort: [], filters: {} };
2088
+ case "open":
2089
+ return { ...state, record: change.record, mode: change.mode ?? "view" };
2090
+ case "create":
2091
+ return { ...state, record: null, mode: "create" };
2092
+ case "close":
2093
+ return { ...state, record: null, mode: null };
2094
+ default: {
2095
+ const unhandled = change;
2096
+ throw new Error(`Unknown list state change: ${JSON.stringify(unhandled)}`);
2097
+ }
2098
+ }
2099
+ }
2100
+ function nextSortOnHeaderClick(current, field) {
2101
+ const first = current[0];
2102
+ if (first === void 0 || first.field !== field) {
2103
+ return [{ field, direction: "asc" }];
2104
+ }
2105
+ if (first.direction === "asc") {
2106
+ return [{ field, direction: "desc" }];
2107
+ }
2108
+ return [];
2109
+ }
2110
+ function pickFormListQuery(query) {
2111
+ return splitPairs(query).filter((pair) => {
2112
+ const equals = pair.indexOf("=");
2113
+ const name = lenientDecode(equals === -1 ? pair : pair.slice(0, equals));
2114
+ const dot = name.indexOf(".");
2115
+ return dot > 0 && LIST_KEY.test(name.slice(0, dot));
2116
+ }).join("&");
2117
+ }
2118
+ function formListRouteQuery(route) {
2119
+ if (!route) {
2120
+ return "";
2121
+ }
2122
+ return Object.entries(route).filter((entry) => {
2123
+ const [name, value] = entry;
2124
+ return ROUTE_PARAM_NAME.test(name) && typeof value === "string" && value !== "" && value.length <= FORM_LIST_MAX_ROUTE_VALUE_LENGTH;
2125
+ }).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("&");
2126
+ }
2127
+ function formListCacheKey(scope, query) {
2128
+ const own = splitPairs(query).map((pair) => {
2129
+ const equals = pair.indexOf("=");
2130
+ return [lenientDecode(equals === -1 ? pair : pair.slice(0, equals)), lenientDecode(equals === -1 ? "" : pair.slice(equals + 1))];
2131
+ }).filter(([name]) => isFormListParam(name, scope.key)).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, value]) => `${name}=${value}`).join("&");
2132
+ return [
2133
+ "form-list",
2134
+ scope.apiBase,
2135
+ scope.account === null ? "guest" : String(scope.account),
2136
+ scope.languageId,
2137
+ scope.platform,
2138
+ scope.pageId,
2139
+ scope.sectionId,
2140
+ formListRouteQuery(scope.route),
2141
+ own
2142
+ ];
2143
+ }
2144
+ var ROUTE_PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
2145
+ function refused(status, reason, parameter, message) {
2146
+ return { ok: false, error: { status, reason, parameter, message } };
2147
+ }
2148
+ function withMode(state, key, rules) {
2149
+ let mode = state.mode;
2150
+ if (mode === null && state.record !== null) {
2151
+ mode = "view";
2152
+ }
2153
+ if (mode === "create") {
2154
+ if (state.record !== null) {
2155
+ return refused(400, "invalid_list_parameter", `${key}.record`, "A new entry has no record.");
2156
+ }
2157
+ if (rules.allowCreate === false) {
2158
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow new entries.");
2159
+ }
2160
+ } else if (mode !== null && state.record === null) {
2161
+ return refused(400, "invalid_list_parameter", `${key}.record`, `The mode "${mode}" needs a record.`);
2162
+ }
2163
+ if (mode === "edit" && rules.allowUpdate === false) {
2164
+ return refused(403, "operation_disabled", `${key}.mode`, "This list does not allow editing.");
2165
+ }
2166
+ if (mode === "history" && rules.showHistory === false) {
2167
+ return refused(403, "history_disabled", `${key}.mode`, "This list does not offer history.");
2168
+ }
2169
+ return { ok: true, state: { ...state, mode } };
2170
+ }
2171
+ function parseSort(value, name, sortable) {
2172
+ if (value === "") {
2173
+ return [];
2174
+ }
2175
+ const items = value.split(",");
2176
+ const fail = (message) => ({ status: 400, reason: "invalid_list_parameter", parameter: name, message });
2177
+ if (items.length > FORM_LIST_MAX_SORTS) {
2178
+ return fail(`At most ${FORM_LIST_MAX_SORTS} sort keys.`);
2179
+ }
2180
+ const sorts = [];
2181
+ const seen = /* @__PURE__ */ new Set();
2182
+ for (const item of items) {
2183
+ const match = SORT_ITEM.exec(item);
2184
+ if (match === null) {
2185
+ return fail('A sort key is "column:asc" or "column:desc".');
2186
+ }
2187
+ const field = match[1] ?? "";
2188
+ const direction = match[2] === "desc" ? "desc" : "asc";
2189
+ if (sortable !== void 0 && !sortable.includes(field)) {
2190
+ return fail(`The list cannot be sorted by "${field}".`);
2191
+ }
2192
+ if (seen.has(field)) {
2193
+ return fail(`"${field}" is sorted twice.`);
2194
+ }
2195
+ seen.add(field);
2196
+ sorts.push({ field, direction });
2197
+ }
2198
+ return sorts;
2199
+ }
2200
+ function phpTrim(text) {
2201
+ let start = 0;
2202
+ let end = text.length;
2203
+ while (start < end && PHP_TRIM_CHARACTERS.includes(text.charAt(start))) {
2204
+ start += 1;
2205
+ }
2206
+ while (end > start && PHP_TRIM_CHARACTERS.includes(text.charAt(end - 1))) {
2207
+ end -= 1;
2208
+ }
2209
+ return text.slice(start, end);
2210
+ }
2211
+ function positiveInt(value) {
2212
+ return POSITIVE_INT.test(value) ? Number(value) : null;
2213
+ }
2214
+ function isMode(value) {
2215
+ return FORM_LIST_MODES.includes(value);
2216
+ }
2217
+ function clampPage(page) {
2218
+ if (!Number.isFinite(page)) {
2219
+ return 1;
2220
+ }
2221
+ return Math.min(FORM_LIST_MAX_PAGE, Math.max(1, Math.trunc(page)));
2222
+ }
2223
+ function splitPairs(query) {
2224
+ const text = typeof query === "string" ? query : query.toString();
2225
+ const trimmed = text.startsWith("?") ? text.slice(1) : text;
2226
+ return trimmed.split("&").filter((pair) => pair !== "");
2227
+ }
2228
+ function lenientDecode(text) {
2229
+ return text.replace(/\+/g, " ").replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
2230
+ try {
2231
+ return decodeURIComponent(run);
2232
+ } catch {
2233
+ return run;
2234
+ }
2235
+ });
2236
+ }
2237
+ function encodeValue(value) {
2238
+ return encodeURIComponent(value).replace(/%3A/g, ":").replace(/%2C/g, ",");
2239
+ }
2240
+ function utf8Length(text) {
2241
+ let bytes = 0;
2242
+ for (const character of text) {
2243
+ const code = character.codePointAt(0) ?? 0;
2244
+ bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
2245
+ }
2246
+ return bytes;
2247
+ }
2248
+
1771
2249
  // src/navigation/headerPreset.ts
1772
2250
  var WEB_HEADER_PRESET_VALUES = [
1773
2251
  "simple",
@@ -2620,7 +3098,16 @@ export {
2620
3098
  ENDPOINTS,
2621
3099
  FIELDS_MAP_STYLE_CONFIG,
2622
3100
  FONT_SIZE_PX,
3101
+ FORM_LIST_MAX_PAGE,
3102
+ FORM_LIST_MAX_ROUTE_PARAMS,
3103
+ FORM_LIST_MAX_ROUTE_VALUE_LENGTH,
3104
+ FORM_LIST_MAX_SORTS,
3105
+ FORM_LIST_MAX_VALUE_BYTES,
3106
+ FORM_LIST_MODES,
3107
+ FORM_LIST_SEARCH_MAX_LENGTH,
3108
+ FORM_LIST_SEARCH_MIN_LENGTH,
2623
3109
  FORM_RECORD_PREFILL_SKIP_FIELDS,
3110
+ FORM_SECTION_STYLE_NAMES,
2624
3111
  FULL_RADIUS_PX,
2625
3112
  HEADER_CLIENT_TYPE,
2626
3113
  LINE_HEIGHT,
@@ -2650,7 +3137,10 @@ export {
2650
3137
  WEB_HEADER_PRESET_OPTIONS,
2651
3138
  WEB_HEADER_PRESET_VALUES,
2652
3139
  _resetPluginStyleRegistry,
3140
+ applyFormListUrlChange,
2653
3141
  arePreviewPreferencesEqual,
3142
+ asFilesCell,
3143
+ asRecordVersion,
2654
3144
  buildConditionContext,
2655
3145
  buildPagesResolvePath,
2656
3146
  buildPagesResolveQuery,
@@ -2661,6 +3151,8 @@ export {
2661
3151
  classifyClassString,
2662
3152
  collectPageIdsFromMenuItems,
2663
3153
  colorToHex,
3154
+ emptyFormListUrlState,
3155
+ encodeFormListQuery,
2664
3156
  evaluateCondition,
2665
3157
  expandedIdsForActiveTrail,
2666
3158
  extendStyleRegistry,
@@ -2675,7 +3167,14 @@ export {
2675
3167
  footerColumnItems,
2676
3168
  footerGroupLinks,
2677
3169
  footerStandaloneItems,
3170
+ formListCacheKey,
3171
+ formListQueryString,
3172
+ formListRouteQuery,
2678
3173
  formatRateLimitMessage,
3174
+ getFormInvalidData,
3175
+ getFormListFailure,
3176
+ getFormListRestoreBlocked,
3177
+ getFormStaleVersion,
2679
3178
  getMergedStyleRegistry,
2680
3179
  getNavigationItemAriaLabel,
2681
3180
  getNavigationItemHref,
@@ -2693,6 +3192,7 @@ export {
2693
3192
  hasInlineFormatting,
2694
3193
  isBottomTabMenuItemActive,
2695
3194
  isDoubleWebHeaderPreset,
3195
+ isFormListParam,
2696
3196
  isKnownStyleName,
2697
3197
  isMenuItemActiveOnMobile,
2698
3198
  isMenuItemActiveOnWeb,
@@ -2726,18 +3226,21 @@ export {
2726
3226
  matchesMobilePath,
2727
3227
  matchesWebPath,
2728
3228
  mergeHeaderLayers,
3229
+ nextSortOnHeaderClick,
2729
3230
  normalizePagesResolvePath,
2730
3231
  pageUrlToMobileRoute,
2731
3232
  parseDimensionToReactNative,
2732
3233
  parseDimensionToWeb,
2733
3234
  parseFieldsMapCatalog,
2734
3235
  parseFieldsMapLabels,
3236
+ parseFormListQuery,
2735
3237
  parseFormRecordPrefill,
2736
3238
  parseInlineRich,
2737
3239
  parseOptionCatalog,
2738
3240
  parseOptionCodes,
2739
3241
  parseOptionLabels,
2740
3242
  parseSpacing,
3243
+ pickFormListQuery,
2741
3244
  previewKeywordFromPath,
2742
3245
  radiusToPx,
2743
3246
  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-DnIJqEzM.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-C2ACy7H0.js';
3
3
  import '../common-qaDIAYS3.js';
4
4
 
5
5
  /**
@@ -287,7 +287,13 @@ 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": {
292
+ 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",
293
+ category: "forms",
294
+ canHaveChildren: true
295
+ },
296
+ "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
297
  };
292
298
  var PLUGIN_STYLE_REGISTRY = {};
293
299
  var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();