@selfhelp/shared 1.29.0 → 1.31.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 (45) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/index.d.mts +35 -85
  3. package/dist/index.d.ts +35 -85
  4. package/dist/index.js +18 -5
  5. package/dist/index.mjs +15 -5
  6. package/dist/inlineFormat-Duu5VLMU.d.mts +73 -0
  7. package/dist/inlineFormat-Duu5VLMU.d.ts +73 -0
  8. package/dist/{manifest-BNnCN1Qo.d.mts → manifest-DWHD0PQA.d.mts} +168 -1
  9. package/dist/{manifest-BNnCN1Qo.d.ts → manifest-DWHD0PQA.d.ts} +168 -1
  10. package/dist/plugin-sdk/index.d.mts +260 -7
  11. package/dist/plugin-sdk/index.d.ts +260 -7
  12. package/dist/plugin-sdk/index.js +174 -2
  13. package/dist/plugin-sdk/index.mjs +171 -2
  14. package/dist/plugin-sdk/sync-map.d.mts +22 -0
  15. package/dist/plugin-sdk/sync-map.d.ts +22 -0
  16. package/dist/plugin-sdk/sync-map.js +58 -0
  17. package/dist/plugin-sdk/sync-map.mjs +33 -0
  18. package/dist/registry/index.d.mts +2 -2
  19. package/dist/registry/index.d.ts +2 -2
  20. package/dist/{styles.registry-DnIJqEzM.d.mts → styles.registry-B2cyNdo3.d.mts} +26 -1
  21. package/dist/{styles.registry-C2ACy7H0.d.ts → styles.registry-G_KUYGPv.d.ts} +26 -1
  22. package/dist/testing/index.d.mts +1 -1
  23. package/dist/testing/index.d.ts +1 -1
  24. package/package.json +3 -3
  25. package/src/content/__tests__/languageIndependent.test.ts +26 -0
  26. package/src/content/__tests__/languageIndependentLiteral.test.ts +62 -0
  27. package/src/content/formRecordPrefill.ts +9 -7
  28. package/src/content/index.ts +1 -0
  29. package/src/content/languageIndependent.ts +28 -0
  30. package/src/plugin-sdk/__tests__/define-sync.test.ts +106 -0
  31. package/src/plugin-sdk/__tests__/exports.test.ts +29 -0
  32. package/src/plugin-sdk/__tests__/host-services.test.ts +96 -6
  33. package/src/plugin-sdk/__tests__/sync-map.test.ts +48 -0
  34. package/src/plugin-sdk/__tests__/version.test.ts +9 -0
  35. package/src/plugin-sdk/host-services.ts +106 -0
  36. package/src/plugin-sdk/index.ts +31 -0
  37. package/src/plugin-sdk/manifest.ts +193 -0
  38. package/src/plugin-sdk/sync-map.ts +61 -0
  39. package/src/plugin-sdk/types.ts +142 -2
  40. package/src/plugin-sdk/version.ts +19 -2
  41. package/src/sync/__tests__/sync.test.ts +19 -0
  42. package/src/sync/sync.ts +3 -2
  43. package/src/sync/types.ts +9 -6
  44. package/src/types/api/form-lists.ts +16 -1
  45. package/src/types/api/forms.ts +10 -0
@@ -1,6 +1,6 @@
1
1
  // src/plugin-sdk/version.ts
2
- var PLUGIN_API_VERSION = "0.1.0";
3
- var MOBILE_RENDERER_VERSION = "0.3.0";
2
+ var PLUGIN_API_VERSION = "0.2.0";
3
+ var MOBILE_RENDERER_VERSION = "0.4.0";
4
4
  var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
5
5
  function parseSemver(version) {
6
6
  const match = SEMVER_REGEX.exec(version);
@@ -139,6 +139,37 @@ function assertPluginVersionSemantics(prevVersion, nextVersion, options) {
139
139
  // src/plugin-sdk/registry.ts
140
140
  var PLUGIN_REGISTRY_CHANNELS = ["stable", "beta", "nightly", "test"];
141
141
 
142
+ // src/plugin-sdk/sync-map.ts
143
+ function matchPluginSyncEntries(entries, tags) {
144
+ if (!entries?.length || tags.length === 0) {
145
+ return [];
146
+ }
147
+ const seen = /* @__PURE__ */ new Set();
148
+ const keys = [];
149
+ for (const entry of entries) {
150
+ if (!entry.tags?.length || !Array.isArray(entry.queryKey)) {
151
+ continue;
152
+ }
153
+ const matched = tags.some((tag) => entry.tags.some((pattern) => tagMatchesPattern(tag, pattern)));
154
+ if (!matched) {
155
+ continue;
156
+ }
157
+ const serialized = JSON.stringify(entry.queryKey);
158
+ if (seen.has(serialized)) {
159
+ continue;
160
+ }
161
+ seen.add(serialized);
162
+ keys.push(entry.queryKey.slice());
163
+ }
164
+ return keys;
165
+ }
166
+ function tagMatchesPattern(tag, pattern) {
167
+ if (pattern.endsWith("*")) {
168
+ return tag.startsWith(pattern.slice(0, -1));
169
+ }
170
+ return tag === pattern;
171
+ }
172
+
142
173
  // src/registry/styles.registry.ts
143
174
  var BASE_STYLE_REGISTRY = {
144
175
  // ===== auth =====
@@ -333,6 +364,141 @@ function getMobileHostServices() {
333
364
  return registeredHostServices;
334
365
  }
335
366
 
367
+ // src/content/inlineFormat.ts
368
+ var HTML_ENTITIES = {
369
+ "&": "&",
370
+ "&lt;": "<",
371
+ "&gt;": ">",
372
+ "&quot;": '"',
373
+ "&#39;": "'",
374
+ "&apos;": "'",
375
+ "&nbsp;": " ",
376
+ "&#x2f;": "/",
377
+ "&#47;": "/"
378
+ };
379
+ function decodeEntities(value) {
380
+ if (!value.includes("&")) return value;
381
+ return value.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
382
+ }
383
+ function looksLikeJson(trimmed) {
384
+ const first = trimmed[0];
385
+ if (first !== "{" && first !== "[") return false;
386
+ try {
387
+ JSON.parse(trimmed);
388
+ return true;
389
+ } catch {
390
+ return false;
391
+ }
392
+ }
393
+ var SEPARATOR_TAGS = /* @__PURE__ */ new Set([
394
+ "br",
395
+ "p",
396
+ "div",
397
+ "li",
398
+ "ul",
399
+ "ol",
400
+ "h1",
401
+ "h2",
402
+ "h3",
403
+ "h4",
404
+ "h5",
405
+ "h6",
406
+ "blockquote",
407
+ "tr",
408
+ "section",
409
+ "article",
410
+ "header",
411
+ "footer",
412
+ "pre"
413
+ ]);
414
+ var TAG_RE = /<\/?([a-z][a-z0-9]*)\b([^>]*)>/gi;
415
+ var HREF_RE = /href\s*=\s*(?:"([^"]*)"|'([^']*)')/i;
416
+ function extractHref(attrs) {
417
+ const match = HREF_RE.exec(attrs);
418
+ return (match?.[1] ?? match?.[2] ?? "").trim();
419
+ }
420
+ function formatKey(node) {
421
+ return `${node.bold ? 1 : 0}|${node.italic ? 1 : 0}|${node.underline ? 1 : 0}|${node.href ?? ""}`;
422
+ }
423
+ function parseInlineRich(value) {
424
+ if (value == null) return [];
425
+ const str = String(value);
426
+ if (str === "") return [];
427
+ const trimmed = str.trim();
428
+ if (looksLikeJson(trimmed)) return [{ text: str }];
429
+ if (!str.includes("<")) {
430
+ const text = decodeEntities(str);
431
+ return text === "" ? [] : [{ text }];
432
+ }
433
+ const raw = [];
434
+ let bold = 0;
435
+ let italic = 0;
436
+ let underline = 0;
437
+ const hrefStack = [];
438
+ const pushText = (segment) => {
439
+ if (segment === "") return;
440
+ raw.push({
441
+ text: segment,
442
+ ...bold > 0 ? { bold: true } : {},
443
+ ...italic > 0 ? { italic: true } : {},
444
+ ...underline > 0 ? { underline: true } : {},
445
+ ...hrefStack.length > 0 ? { href: hrefStack[hrefStack.length - 1] } : {}
446
+ });
447
+ };
448
+ let lastIndex = 0;
449
+ let match;
450
+ TAG_RE.lastIndex = 0;
451
+ while ((match = TAG_RE.exec(str)) !== null) {
452
+ pushText(str.slice(lastIndex, match.index));
453
+ lastIndex = TAG_RE.lastIndex;
454
+ const isClose = match[0].charAt(1) === "/";
455
+ const tag = match[1].toLowerCase();
456
+ const attrs = match[2] ?? "";
457
+ if (tag === "b" || tag === "strong") {
458
+ bold = isClose ? Math.max(0, bold - 1) : bold + 1;
459
+ } else if (tag === "i" || tag === "em") {
460
+ italic = isClose ? Math.max(0, italic - 1) : italic + 1;
461
+ } else if (tag === "u") {
462
+ underline = isClose ? Math.max(0, underline - 1) : underline + 1;
463
+ } else if (tag === "a") {
464
+ if (isClose) {
465
+ hrefStack.pop();
466
+ } else {
467
+ hrefStack.push(extractHref(attrs));
468
+ }
469
+ } else if (SEPARATOR_TAGS.has(tag)) {
470
+ pushText(" ");
471
+ }
472
+ }
473
+ pushText(str.slice(lastIndex));
474
+ const merged = [];
475
+ for (const node of raw) {
476
+ const prev = merged[merged.length - 1];
477
+ if (prev && formatKey(prev) === formatKey(node)) {
478
+ prev.text += node.text;
479
+ } else {
480
+ merged.push({ ...node });
481
+ }
482
+ }
483
+ for (const node of merged) {
484
+ node.text = decodeEntities(node.text).replace(/\s+/g, " ");
485
+ }
486
+ if (merged.length > 0) {
487
+ merged[0].text = merged[0].text.replace(/^\s+/, "");
488
+ merged[merged.length - 1].text = merged[merged.length - 1].text.replace(/\s+$/, "");
489
+ }
490
+ return merged.filter((node) => node.text !== "");
491
+ }
492
+ function stripHtmlToText(value) {
493
+ if (!value || typeof value !== "string") return value ?? "";
494
+ const trimmed = value.trim();
495
+ if (looksLikeJson(trimmed)) return value;
496
+ if (!/[<&]/.test(value)) return value;
497
+ let out = value.replace(/<br\s*\/?>/gi, " ").replace(/<\/(p|div|li|h[1-6]|tr|blockquote)>/gi, " ").replace(/<[^>]+>/g, "");
498
+ out = out.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
499
+ return out.replace(/\s+/g, " ").trim();
500
+ }
501
+
336
502
  // src/plugin-sdk/realtime.ts
337
503
  import { useEffect, useRef, useState } from "react";
338
504
  var DEFAULT_ENDPOINT = "/api/plugins/events";
@@ -521,8 +687,11 @@ export {
521
687
  isMobileRendererCompatible,
522
688
  isPluginApiCompatible,
523
689
  isPluginRuntimeShimSpecifier,
690
+ matchPluginSyncEntries,
691
+ parseInlineRich,
524
692
  parseSemver,
525
693
  satisfiesSemverRange,
526
694
  setMobileHostServices,
695
+ stripHtmlToText,
527
696
  usePluginRealtime
528
697
  };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Declarative plugin sync map (contract C10).
3
+ *
4
+ * A plugin lists tags (exact, or a prefix ending in `*`) and the React Query
5
+ * key each tag should invalidate. Hosts call {@link matchPluginSyncEntries}
6
+ * from `applySyncTags` and invalidate each returned key as a prefix.
7
+ */
8
+ /** One entry of a plugin's optional `sync` map. */
9
+ interface IPluginSyncEntry {
10
+ /** Exact tags, or a prefix ending in `*` (`res:surveyjs_survey:*`, `table:*`). */
11
+ tags: string[];
12
+ /** React Query key the host invalidates as a prefix when a listed tag matches. */
13
+ queryKey: readonly unknown[];
14
+ }
15
+ /**
16
+ * Returns the unique `queryKey` values whose `tags` match any of the message
17
+ * tags. A pattern ending in `*` matches by prefix; every other tag must equal.
18
+ * Uniqueness is by `JSON.stringify(queryKey)`.
19
+ */
20
+ declare function matchPluginSyncEntries(entries: readonly IPluginSyncEntry[] | null | undefined, tags: readonly string[]): readonly unknown[][];
21
+
22
+ export { type IPluginSyncEntry, matchPluginSyncEntries };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Declarative plugin sync map (contract C10).
3
+ *
4
+ * A plugin lists tags (exact, or a prefix ending in `*`) and the React Query
5
+ * key each tag should invalidate. Hosts call {@link matchPluginSyncEntries}
6
+ * from `applySyncTags` and invalidate each returned key as a prefix.
7
+ */
8
+ /** One entry of a plugin's optional `sync` map. */
9
+ interface IPluginSyncEntry {
10
+ /** Exact tags, or a prefix ending in `*` (`res:surveyjs_survey:*`, `table:*`). */
11
+ tags: string[];
12
+ /** React Query key the host invalidates as a prefix when a listed tag matches. */
13
+ queryKey: readonly unknown[];
14
+ }
15
+ /**
16
+ * Returns the unique `queryKey` values whose `tags` match any of the message
17
+ * tags. A pattern ending in `*` matches by prefix; every other tag must equal.
18
+ * Uniqueness is by `JSON.stringify(queryKey)`.
19
+ */
20
+ declare function matchPluginSyncEntries(entries: readonly IPluginSyncEntry[] | null | undefined, tags: readonly string[]): readonly unknown[][];
21
+
22
+ export { type IPluginSyncEntry, matchPluginSyncEntries };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/plugin-sdk/sync-map.ts
21
+ var sync_map_exports = {};
22
+ __export(sync_map_exports, {
23
+ matchPluginSyncEntries: () => matchPluginSyncEntries
24
+ });
25
+ module.exports = __toCommonJS(sync_map_exports);
26
+ function matchPluginSyncEntries(entries, tags) {
27
+ if (!entries?.length || tags.length === 0) {
28
+ return [];
29
+ }
30
+ const seen = /* @__PURE__ */ new Set();
31
+ const keys = [];
32
+ for (const entry of entries) {
33
+ if (!entry.tags?.length || !Array.isArray(entry.queryKey)) {
34
+ continue;
35
+ }
36
+ const matched = tags.some((tag) => entry.tags.some((pattern) => tagMatchesPattern(tag, pattern)));
37
+ if (!matched) {
38
+ continue;
39
+ }
40
+ const serialized = JSON.stringify(entry.queryKey);
41
+ if (seen.has(serialized)) {
42
+ continue;
43
+ }
44
+ seen.add(serialized);
45
+ keys.push(entry.queryKey.slice());
46
+ }
47
+ return keys;
48
+ }
49
+ function tagMatchesPattern(tag, pattern) {
50
+ if (pattern.endsWith("*")) {
51
+ return tag.startsWith(pattern.slice(0, -1));
52
+ }
53
+ return tag === pattern;
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ matchPluginSyncEntries
58
+ });
@@ -0,0 +1,33 @@
1
+ // src/plugin-sdk/sync-map.ts
2
+ function matchPluginSyncEntries(entries, tags) {
3
+ if (!entries?.length || tags.length === 0) {
4
+ return [];
5
+ }
6
+ const seen = /* @__PURE__ */ new Set();
7
+ const keys = [];
8
+ for (const entry of entries) {
9
+ if (!entry.tags?.length || !Array.isArray(entry.queryKey)) {
10
+ continue;
11
+ }
12
+ const matched = tags.some((tag) => entry.tags.some((pattern) => tagMatchesPattern(tag, pattern)));
13
+ if (!matched) {
14
+ continue;
15
+ }
16
+ const serialized = JSON.stringify(entry.queryKey);
17
+ if (seen.has(serialized)) {
18
+ continue;
19
+ }
20
+ seen.add(serialized);
21
+ keys.push(entry.queryKey.slice());
22
+ }
23
+ return keys;
24
+ }
25
+ function tagMatchesPattern(tag, pattern) {
26
+ if (pattern.endsWith("*")) {
27
+ return tag.startsWith(pattern.slice(0, -1));
28
+ }
29
+ return tag === pattern;
30
+ }
31
+ export {
32
+ matchPluginSyncEntries
33
+ };
@@ -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-DnIJqEzM.mjs';
2
- export { B as BASE_STYLE_REGISTRY, F as FORM_SECTION_STYLE_NAMES, S as STYLE_REGISTRY, e as TFormSectionStyleName, f as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, g as _resetPluginStyleRegistry, h as extendStyleRegistry, i as getMergedStyleRegistry, j as getPluginStyleRegistry } from '../styles.registry-DnIJqEzM.mjs';
1
+ import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-B2cyNdo3.mjs';
2
+ export { B as BASE_STYLE_REGISTRY, F as FORM_SECTION_STYLE_NAMES, S as STYLE_REGISTRY, e as TFormSectionStyleName, f as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, g as _resetPluginStyleRegistry, h as extendStyleRegistry, i as getMergedStyleRegistry, j as getPluginStyleRegistry } from '../styles.registry-B2cyNdo3.mjs';
3
3
  import '../common-qaDIAYS3.mjs';
4
4
 
5
5
  /**
@@ -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-C2ACy7H0.js';
2
- export { B as BASE_STYLE_REGISTRY, F as FORM_SECTION_STYLE_NAMES, S as STYLE_REGISTRY, e as TFormSectionStyleName, f as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, g as _resetPluginStyleRegistry, h as extendStyleRegistry, i as getMergedStyleRegistry, j as getPluginStyleRegistry } from '../styles.registry-C2ACy7H0.js';
1
+ import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-G_KUYGPv.js';
2
+ export { B as BASE_STYLE_REGISTRY, F as FORM_SECTION_STYLE_NAMES, S as STYLE_REGISTRY, e as TFormSectionStyleName, f as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, g as _resetPluginStyleRegistry, h as extendStyleRegistry, i as getMergedStyleRegistry, j as getPluginStyleRegistry } from '../styles.registry-G_KUYGPv.js';
3
3
  import '../common-qaDIAYS3.js';
4
4
 
5
5
  /**
@@ -835,6 +835,11 @@ interface IFormSubmitData extends IFormResultLegacyFields {
835
835
  user_authenticated: boolean;
836
836
  /** The record's version after the submit (1 for a new record). */
837
837
  version: number;
838
+ /**
839
+ * Content the write was based on (`page:<id>@v<n>|draft` or
840
+ * `res:<type>:<id>@v<n>`). Null when unknown.
841
+ */
842
+ content_ref?: string | null;
838
843
  }
839
844
  /**
840
845
  * Data returned by a successful PUT form update. Mirrors the backend contract
@@ -848,6 +853,11 @@ interface IFormUpdateData extends IFormResultLegacyFields {
848
853
  updated_at: string;
849
854
  /** The record's version after the update. */
850
855
  version: number;
856
+ /**
857
+ * Content the write was based on (`page:<id>@v<n>|draft` or
858
+ * `res:<type>:<id>@v<n>`). Null when unknown.
859
+ */
860
+ content_ref?: string | null;
851
861
  }
852
862
  /**
853
863
  * Data returned by a successful DELETE form delete. Mirrors the backend contract
@@ -1007,6 +1017,11 @@ interface IFormListRow extends IFormListRecordAccess {
1007
1017
  entry_date: string;
1008
1018
  /** Send back as `expected_version` when changing the record. */
1009
1019
  version: number;
1020
+ /**
1021
+ * Content the write was based on (`page:<id>@v<n>|draft` or
1022
+ * `res:<type>:<id>@v<n>`). Null when unknown (older rows).
1023
+ */
1024
+ content_ref?: string | null;
1010
1025
  /** Exactly the configured columns, by field. */
1011
1026
  values: Record<string, TFormListCellValue>;
1012
1027
  /**
@@ -1023,6 +1038,11 @@ interface IFormListSelected extends IFormListRecordAccess {
1023
1038
  entry_date: string;
1024
1039
  /** Send back as `expected_version` when saving, deleting, running an action or restoring. */
1025
1040
  version: number;
1041
+ /**
1042
+ * Content the write was based on (`page:<id>@v<n>|draft` or
1043
+ * `res:<type>:<id>@v<n>`). Null when unknown (older rows).
1044
+ */
1045
+ content_ref?: string | null;
1026
1046
  values: Record<string, TFormListCellValue>;
1027
1047
  /** The prefill the inline form receives on a page load; null when the caller cannot edit the record. */
1028
1048
  form_values: Record<string, unknown> | unknown[] | null;
@@ -1081,7 +1101,7 @@ interface IFormListQuickActionData {
1081
1101
  }
1082
1102
  type IFormListQuickActionResponse = IBaseApiResponse<IFormListQuickActionData>;
1083
1103
  type TDataRevisionOperation = 'create' | 'update' | 'delete' | 'restore' | 'baseline';
1084
- type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system';
1104
+ type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system' | 'plugin';
1085
1105
  interface IFormListActor {
1086
1106
  id: number;
1087
1107
  name: string | null;
@@ -1099,6 +1119,11 @@ interface IFormListRevision {
1099
1119
  /** The number of fields the revision changed. */
1100
1120
  changed_fields: number;
1101
1121
  is_checkpoint: boolean;
1122
+ /**
1123
+ * Content that revision was based on (`page:<id>@v<n>|draft` or
1124
+ * `res:<type>:<id>@v<n>`). Null when unknown (older revisions).
1125
+ */
1126
+ content_ref?: string | null;
1102
1127
  }
1103
1128
  /** A file a revision held; `available` is false once the file was erased. */
1104
1129
  interface IFormListHistoricalFile {
@@ -835,6 +835,11 @@ interface IFormSubmitData extends IFormResultLegacyFields {
835
835
  user_authenticated: boolean;
836
836
  /** The record's version after the submit (1 for a new record). */
837
837
  version: number;
838
+ /**
839
+ * Content the write was based on (`page:<id>@v<n>|draft` or
840
+ * `res:<type>:<id>@v<n>`). Null when unknown.
841
+ */
842
+ content_ref?: string | null;
838
843
  }
839
844
  /**
840
845
  * Data returned by a successful PUT form update. Mirrors the backend contract
@@ -848,6 +853,11 @@ interface IFormUpdateData extends IFormResultLegacyFields {
848
853
  updated_at: string;
849
854
  /** The record's version after the update. */
850
855
  version: number;
856
+ /**
857
+ * Content the write was based on (`page:<id>@v<n>|draft` or
858
+ * `res:<type>:<id>@v<n>`). Null when unknown.
859
+ */
860
+ content_ref?: string | null;
851
861
  }
852
862
  /**
853
863
  * Data returned by a successful DELETE form delete. Mirrors the backend contract
@@ -1007,6 +1017,11 @@ interface IFormListRow extends IFormListRecordAccess {
1007
1017
  entry_date: string;
1008
1018
  /** Send back as `expected_version` when changing the record. */
1009
1019
  version: number;
1020
+ /**
1021
+ * Content the write was based on (`page:<id>@v<n>|draft` or
1022
+ * `res:<type>:<id>@v<n>`). Null when unknown (older rows).
1023
+ */
1024
+ content_ref?: string | null;
1010
1025
  /** Exactly the configured columns, by field. */
1011
1026
  values: Record<string, TFormListCellValue>;
1012
1027
  /**
@@ -1023,6 +1038,11 @@ interface IFormListSelected extends IFormListRecordAccess {
1023
1038
  entry_date: string;
1024
1039
  /** Send back as `expected_version` when saving, deleting, running an action or restoring. */
1025
1040
  version: number;
1041
+ /**
1042
+ * Content the write was based on (`page:<id>@v<n>|draft` or
1043
+ * `res:<type>:<id>@v<n>`). Null when unknown (older rows).
1044
+ */
1045
+ content_ref?: string | null;
1026
1046
  values: Record<string, TFormListCellValue>;
1027
1047
  /** The prefill the inline form receives on a page load; null when the caller cannot edit the record. */
1028
1048
  form_values: Record<string, unknown> | unknown[] | null;
@@ -1081,7 +1101,7 @@ interface IFormListQuickActionData {
1081
1101
  }
1082
1102
  type IFormListQuickActionResponse = IBaseApiResponse<IFormListQuickActionData>;
1083
1103
  type TDataRevisionOperation = 'create' | 'update' | 'delete' | 'restore' | 'baseline';
1084
- type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system';
1104
+ type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system' | 'plugin';
1085
1105
  interface IFormListActor {
1086
1106
  id: number;
1087
1107
  name: string | null;
@@ -1099,6 +1119,11 @@ interface IFormListRevision {
1099
1119
  /** The number of fields the revision changed. */
1100
1120
  changed_fields: number;
1101
1121
  is_checkpoint: boolean;
1122
+ /**
1123
+ * Content that revision was based on (`page:<id>@v<n>|draft` or
1124
+ * `res:<type>:<id>@v<n>`). Null when unknown (older revisions).
1125
+ */
1126
+ content_ref?: string | null;
1102
1127
  }
1103
1128
  /** A file a revision held; `available` is false once the file was erased. */
1104
1129
  interface IFormListHistoricalFile {
@@ -1,4 +1,4 @@
1
- import { I as IPluginManifest } from '../manifest-BNnCN1Qo.mjs';
1
+ import { I as IPluginManifest } from '../manifest-DWHD0PQA.mjs';
2
2
 
3
3
  /**
4
4
  * `@selfhelp/shared/testing` — the plugin certification kit.
@@ -1,4 +1,4 @@
1
- import { I as IPluginManifest } from '../manifest-BNnCN1Qo.js';
1
+ import { I as IPluginManifest } from '../manifest-DWHD0PQA.js';
2
2
 
3
3
  /**
4
4
  * `@selfhelp/shared/testing` — the plugin certification kit.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfhelp/shared",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,8 +52,8 @@
52
52
  "CHANGELOG.md"
53
53
  ],
54
54
  "scripts": {
55
- "build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --clean --no-splitting",
56
- "dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --watch --no-splitting",
55
+ "build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/plugin-sdk/sync-map.ts src/testing/index.ts --format cjs,esm --dts --clean --no-splitting",
56
+ "dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/plugin-sdk/sync-map.ts src/testing/index.ts --format cjs,esm --dts --watch --no-splitting",
57
57
  "lint": "eslint .",
58
58
  "lint:fix": "eslint . --fix",
59
59
  "typecheck": "tsc --noEmit",
@@ -0,0 +1,26 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { describe, expect, it } from 'vitest';
7
+ import {
8
+ LANGUAGE_INDEPENDENT_ID,
9
+ LANGUAGE_INDEPENDENT_LOCALE,
10
+ isLanguageIndependent,
11
+ } from '../languageIndependent';
12
+
13
+ describe('isLanguageIndependent', () => {
14
+ it('is true only for the sentinel id 1', () => {
15
+ expect(LANGUAGE_INDEPENDENT_ID).toBe(1);
16
+ expect(LANGUAGE_INDEPENDENT_LOCALE).toBe('all');
17
+ expect(isLanguageIndependent(1)).toBe(true);
18
+ expect(isLanguageIndependent(LANGUAGE_INDEPENDENT_ID)).toBe(true);
19
+ });
20
+
21
+ it('is false for a real language, null and undefined', () => {
22
+ expect(isLanguageIndependent(2)).toBe(false);
23
+ expect(isLanguageIndependent(null)).toBe(false);
24
+ expect(isLanguageIndependent(undefined)).toBe(false);
25
+ });
26
+ });
@@ -0,0 +1,62 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
7
+ import { join, relative, sep } from 'node:path';
8
+ import { describe, expect, it } from 'vitest';
9
+
10
+ /**
11
+ * Fails when source under `src/` still compares against bare language id 1 or
12
+ * locale `all`. The constant module itself and every `__tests__` folder are
13
+ * excluded; clients must import `LANGUAGE_INDEPENDENT_*` / `isLanguageIndependent`.
14
+ */
15
+ const SRC_ROOT = join(__dirname, '..', '..');
16
+ const OWN_MODULE = join('content', 'languageIndependent.ts');
17
+
18
+ const FORBIDDEN = [
19
+ /language_id\s*===\s*1\b/,
20
+ /language_id\s*!==\s*1\b/,
21
+ /languageId\s*===\s*1\b/,
22
+ /language_id\s*>\s*1\b/,
23
+ /locale\s*===\s*['"]all['"]/,
24
+ ] as const;
25
+
26
+ function listSourceFiles(dir: string): string[] {
27
+ const out: string[] = [];
28
+ for (const name of readdirSync(dir)) {
29
+ const full = join(dir, name);
30
+ const st = statSync(full);
31
+ if (st.isDirectory()) {
32
+ if (name === '__tests__' || name === 'node_modules' || name === 'dist') {
33
+ continue;
34
+ }
35
+ out.push(...listSourceFiles(full));
36
+ continue;
37
+ }
38
+ if (/\.(ts|tsx|js|mjs|cjs)$/.test(name) && !name.endsWith('.d.ts')) {
39
+ out.push(full);
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+
45
+ describe('language-independent literals in src/', () => {
46
+ it('uses LANGUAGE_INDEPENDENT_* / isLanguageIndependent instead of bare 1 or locale all', () => {
47
+ const hits: string[] = [];
48
+ for (const file of listSourceFiles(SRC_ROOT)) {
49
+ const rel = relative(SRC_ROOT, file).split(sep).join('/');
50
+ if (rel === OWN_MODULE.replace(/\\/g, '/')) {
51
+ continue;
52
+ }
53
+ const text = readFileSync(file, 'utf8');
54
+ for (const pattern of FORBIDDEN) {
55
+ if (pattern.test(text)) {
56
+ hits.push(`${rel} matches ${pattern}`);
57
+ }
58
+ }
59
+ }
60
+ expect(hits).toEqual([]);
61
+ });
62
+ });
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import type { IFormListFilesCell, IFormListFileValue } from '../types/api/form-lists';
15
+ import { isLanguageIndependent } from './languageIndependent';
15
16
 
16
17
  /** Per-language value for a translatable form field. */
17
18
  export interface IFormRecordPrefillTranslatedValue {
@@ -142,9 +143,10 @@ export function asFilesCell(value: unknown): TFormRecordPrefillFileValue | null
142
143
  *
143
144
  * - Missing / empty / non-array `section_data` → empty create state.
144
145
  * - Rows without a numeric `record_id` are ignored.
145
- * - Translatable fields accumulate `{ language_id, value }[]` (language id `1`
146
- * is an Independent seed kept only until a public-language row arrives).
147
- * - Non-translatable fields prefer language id `1`, else the first seen value.
146
+ * - Translatable fields accumulate `{ language_id, value }[]` (the
147
+ * language-independent seed is kept only until a public-language row arrives).
148
+ * - Non-translatable fields prefer the language-independent row, else the first
149
+ * seen value.
148
150
  */
149
151
  export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFormRecordPrefill {
150
152
  const sectionDataArray = section?.section_data;
@@ -194,7 +196,7 @@ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFor
194
196
  }
195
197
  const filesCell = asFilesCell(fieldValue);
196
198
  if (filesCell !== null) {
197
- if (languageId === 1 || !recordGroups[recordId][fieldName]) {
199
+ if (isLanguageIndependent(languageId) || !recordGroups[recordId][fieldName]) {
198
200
  recordGroups[recordId][fieldName] = filesCell;
199
201
  }
200
202
  continue;
@@ -207,7 +209,7 @@ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFor
207
209
  const translatable = isTranslatableChild(section.children, fieldName);
208
210
 
209
211
  if (translatable) {
210
- if (languageId === 1) {
212
+ if (isLanguageIndependent(languageId)) {
211
213
  if (!recordGroups[recordId][fieldName]) {
212
214
  recordGroups[recordId][fieldName] = value;
213
215
  }
@@ -229,7 +231,7 @@ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFor
229
231
  }
230
232
  }
231
233
  }
232
- } else if (languageId === 1 || !recordGroups[recordId][fieldName]) {
234
+ } else if (isLanguageIndependent(languageId) || !recordGroups[recordId][fieldName]) {
233
235
  recordGroups[recordId][fieldName] = value;
234
236
  }
235
237
  }
@@ -287,7 +289,7 @@ export function flattenFormRecordPrefillValues(
287
289
  continue;
288
290
  }
289
291
  }
290
- const nonIndependent = value.find((entry) => entry.language_id !== 1);
292
+ const nonIndependent = value.find((entry) => !isLanguageIndependent(entry.language_id));
291
293
  out[key] = (nonIndependent ?? value[0]).value;
292
294
  }
293
295
  return out;