@atscript/ui 0.1.206 → 0.1.208

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 (127) hide show
  1. package/dist/form/create-form-def.cjs +16 -18
  2. package/dist/form/create-form-def.mjs +15 -17
  3. package/dist/form/decimal-format.cjs +8 -3
  4. package/dist/form/decimal-format.d.cts +8 -2
  5. package/dist/form/decimal-format.d.mts +8 -2
  6. package/dist/form/decimal-format.mjs +8 -3
  7. package/dist/form/form-actions.cjs +9 -0
  8. package/dist/form/form-actions.d.cts +7 -1
  9. package/dist/form/form-actions.d.mts +7 -1
  10. package/dist/form/form-actions.mjs +9 -1
  11. package/dist/form/measurement.cjs +58 -0
  12. package/dist/form/measurement.d.cts +36 -1
  13. package/dist/form/measurement.d.mts +36 -1
  14. package/dist/form/measurement.mjs +57 -2
  15. package/dist/form/omit-derived.cjs +11 -0
  16. package/dist/form/omit-derived.d.cts +8 -1
  17. package/dist/form/omit-derived.d.mts +8 -1
  18. package/dist/form/omit-derived.mjs +11 -1
  19. package/dist/form/optional-mode.cjs +7 -7
  20. package/dist/form/optional-mode.d.cts +2 -1
  21. package/dist/form/optional-mode.d.mts +2 -1
  22. package/dist/form/optional-mode.mjs +8 -8
  23. package/dist/form/path-utils.cjs +10 -0
  24. package/dist/form/path-utils.d.cts +8 -1
  25. package/dist/form/path-utils.d.mts +8 -1
  26. package/dist/form/path-utils.mjs +10 -1
  27. package/dist/form/types.cjs +5 -0
  28. package/dist/form/types.d.cts +14 -0
  29. package/dist/form/types.d.mts +14 -0
  30. package/dist/form/types.mjs +5 -1
  31. package/dist/form/validate.cjs +56 -5
  32. package/dist/form/validate.d.cts +30 -2
  33. package/dist/form/validate.d.mts +30 -2
  34. package/dist/form/validate.mjs +56 -6
  35. package/dist/index.cjs +42 -6
  36. package/dist/index.d.cts +20 -12
  37. package/dist/index.d.mts +20 -12
  38. package/dist/index.mjs +23 -15
  39. package/dist/plugin/annotations.cjs +33 -14
  40. package/dist/plugin/annotations.mjs +34 -15
  41. package/dist/plugin/value-help-validation.cjs +26 -6
  42. package/dist/plugin/value-help-validation.mjs +26 -7
  43. package/dist/shared/annotation-keys.cjs +3 -0
  44. package/dist/shared/annotation-keys.d.cts +2 -1
  45. package/dist/shared/annotation-keys.d.mts +2 -1
  46. package/dist/shared/annotation-keys.mjs +3 -1
  47. package/dist/shared/dev.cjs +22 -0
  48. package/dist/shared/dev.d.cts +4 -0
  49. package/dist/shared/dev.d.mts +4 -0
  50. package/dist/shared/dev.mjs +22 -0
  51. package/dist/shared/field-resolver.cjs +21 -1
  52. package/dist/shared/field-resolver.d.cts +15 -1
  53. package/dist/shared/field-resolver.d.mts +15 -1
  54. package/dist/shared/field-resolver.mjs +20 -2
  55. package/dist/shared/merge-filters.cjs +28 -0
  56. package/dist/shared/merge-filters.d.cts +13 -0
  57. package/dist/shared/merge-filters.d.mts +13 -0
  58. package/dist/shared/merge-filters.mjs +28 -0
  59. package/dist/shared/meta-cache.cjs +5 -4
  60. package/dist/shared/meta-cache.d.cts +3 -2
  61. package/dist/shared/meta-cache.d.mts +3 -2
  62. package/dist/shared/meta-cache.mjs +5 -4
  63. package/dist/shared/resolve-component.cjs +27 -0
  64. package/dist/shared/resolve-component.d.cts +22 -0
  65. package/dist/shared/resolve-component.d.mts +22 -0
  66. package/dist/shared/resolve-component.mjs +27 -0
  67. package/dist/shared/stable-key.cjs +28 -0
  68. package/dist/shared/stable-key.d.cts +13 -0
  69. package/dist/shared/stable-key.d.mts +13 -0
  70. package/dist/shared/stable-key.mjs +28 -0
  71. package/dist/shared/to-date.cjs +65 -0
  72. package/dist/shared/to-date.d.cts +35 -0
  73. package/dist/shared/to-date.d.mts +35 -0
  74. package/dist/shared/to-date.mjs +64 -0
  75. package/dist/shared/value-label.cjs +14 -2
  76. package/dist/shared/value-label.d.cts +23 -6
  77. package/dist/shared/value-label.d.mts +23 -6
  78. package/dist/shared/value-label.mjs +14 -3
  79. package/dist/table/create-table-def.cjs +53 -13
  80. package/dist/table/create-table-def.mjs +53 -15
  81. package/dist/table/types.d.cts +15 -13
  82. package/dist/table/types.d.mts +15 -13
  83. package/dist/value-help/client-store.cjs +43 -0
  84. package/dist/value-help/client-store.d.mts +1 -0
  85. package/dist/value-help/client-store.mjs +40 -0
  86. package/dist/value-help/display-value.cjs +30 -0
  87. package/dist/value-help/display-value.d.cts +45 -0
  88. package/dist/value-help/display-value.d.mts +45 -0
  89. package/dist/value-help/display-value.mjs +30 -0
  90. package/dist/value-help/distinct-client.cjs +80 -7
  91. package/dist/value-help/distinct-client.d.cts +31 -36
  92. package/dist/value-help/distinct-client.d.mts +31 -36
  93. package/dist/value-help/distinct-client.mjs +80 -7
  94. package/dist/value-help/extract-ref.cjs +15 -4
  95. package/dist/value-help/extract-ref.d.cts +6 -1
  96. package/dist/value-help/extract-ref.d.mts +6 -1
  97. package/dist/value-help/extract-ref.mjs +16 -6
  98. package/dist/value-help/index.d.mts +6 -3
  99. package/dist/value-help/options.cjs +70 -8
  100. package/dist/value-help/options.d.cts +57 -4
  101. package/dist/value-help/options.d.mts +57 -4
  102. package/dist/value-help/options.mjs +67 -9
  103. package/dist/value-help/resolve-options.cjs +9 -7
  104. package/dist/value-help/resolve-options.d.cts +8 -9
  105. package/dist/value-help/resolve-options.d.mts +8 -9
  106. package/dist/value-help/resolve-options.mjs +9 -7
  107. package/dist/value-help/resolve.cjs +29 -8
  108. package/dist/value-help/resolve.d.cts +22 -5
  109. package/dist/value-help/resolve.d.mts +22 -5
  110. package/dist/value-help/resolve.mjs +29 -8
  111. package/dist/value-help/scope.cjs +3 -7
  112. package/dist/value-help/scope.mjs +3 -7
  113. package/dist/value-help/source.cjs +72 -0
  114. package/dist/value-help/source.d.cts +55 -0
  115. package/dist/value-help/source.d.mts +55 -0
  116. package/dist/value-help/source.mjs +71 -0
  117. package/dist/value-help/texts.cjs +318 -0
  118. package/dist/value-help/texts.d.cts +53 -0
  119. package/dist/value-help/texts.d.mts +53 -0
  120. package/dist/value-help/texts.mjs +313 -0
  121. package/dist/value-help/types.d.cts +10 -0
  122. package/dist/value-help/types.d.mts +10 -0
  123. package/dist/value-help/value-help-client.cjs +24 -20
  124. package/dist/value-help/value-help-client.d.cts +10 -5
  125. package/dist/value-help/value-help-client.d.mts +10 -5
  126. package/dist/value-help/value-help-client.mjs +22 -18
  127. package/package.json +10 -10
@@ -4,8 +4,9 @@ const require_field_resolver = require("../shared/field-resolver.cjs");
4
4
  const require_extract_literals = require("../value-help/extract-literals.cjs");
5
5
  const require_extract_ref = require("../value-help/extract-ref.cjs");
6
6
  const require_exact_number = require("../shared/exact-number.cjs");
7
- const require_str = require("../shared/str.cjs");
7
+ const require_path_utils = require("../form/path-utils.cjs");
8
8
  const require_measurement = require("../form/measurement.cjs");
9
+ const require_str = require("../shared/str.cjs");
9
10
  const require_value_label = require("../shared/value-label.cjs");
10
11
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
11
12
  //#region src/table/create-table-def.ts
@@ -59,6 +60,7 @@ function createTableDef(meta, preDeserializedType, t) {
59
60
  preferredId,
60
61
  identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
61
62
  versionColumn: meta.versionColumn,
63
+ label: dictLabelOf(meta, type),
62
64
  crud,
63
65
  canRemove: "remove" in crud,
64
66
  actions,
@@ -80,17 +82,21 @@ function buildColumn(path, prop, fieldMeta, resolved) {
80
82
  const sharedType = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TYPE);
81
83
  const tableComponent = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_COMPONENT);
82
84
  const filterOps = fieldMeta.filterOps;
83
- let selectWith = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_SELECT_WITH);
85
+ const measurement = require_measurement.extractMeasurement(prop);
84
86
  const label = require_value_label.valueLabelOf(prop);
85
- let valueLabel;
86
- if (label) {
87
- const dot = path.lastIndexOf(".");
88
- const textPath = dot < 0 ? label.field : `${path.slice(0, dot + 1)}${label.field}`;
89
- valueLabel = {
90
- path: textPath,
91
- arrangement: label.arrangement
92
- };
93
- if (!selectWith?.includes(textPath)) selectWith = [...selectWith ?? [], textPath];
87
+ const siblings = require_path_utils.parentPrefix(path);
88
+ const valueLabel = label && {
89
+ path: siblings + label.field,
90
+ arrangement: label.arrangement
91
+ };
92
+ let selectWith = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_SELECT_WITH);
93
+ for (const field of [
94
+ label?.field,
95
+ measurement.currencyRefField,
96
+ measurement.unitRefField
97
+ ]) {
98
+ const sibling = field && siblings + field;
99
+ if (sibling && !selectWith?.includes(sibling)) selectWith = [...selectWith ?? [], sibling];
94
100
  }
95
101
  return {
96
102
  path,
@@ -111,7 +117,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
111
117
  valueHelpInfo,
112
118
  ...valueLabel && { valueLabel },
113
119
  ...distinct && { distinct },
114
- ...require_measurement.extractMeasurement(prop)
120
+ ...measurement
115
121
  };
116
122
  }
117
123
  /**
@@ -129,10 +135,42 @@ function identifierFieldsOf(preferredId, actions) {
129
135
  }
130
136
  return out ?? preferredId;
131
137
  }
132
- /** A field the caller may read: listed in `meta.fields` and not write-only. */
138
+ /**
139
+ * A field the caller may read: listed in `meta.fields` and not write-only —
140
+ * the one rule for a table's columns and a dictionary's label.
141
+ */
133
142
  function isReadable(field) {
134
143
  return field !== void 0 && field.writeOnly !== true;
135
144
  }
145
+ /**
146
+ * The label a type's rows declare: the own field its `@ui.dict.label` marks
147
+ * (`@ui.dict.label 'keyText'` → that arrangement, default `textKey`), when
148
+ * the caller can read it. The one rule for a dictionary's label
149
+ * (`ResolvedValueHelp.label`) and a table's (`TableDef.label`).
150
+ */
151
+ function dictLabelOf(meta, type) {
152
+ if (type.type.kind !== "object") return void 0;
153
+ let label;
154
+ for (const [field, prop] of type.type.props) {
155
+ const declared = prop.metadata.get(require_annotation_keys.UI_DICT_LABEL);
156
+ if (declared === void 0 || field === meta.versionColumn) continue;
157
+ label = readableLabel(meta, field, typeof declared === "string" ? declared : void 0);
158
+ }
159
+ return label;
160
+ }
161
+ /**
162
+ * `field` of the served type as a label, when the caller may read it
163
+ * (`isReadable`); the arrangement defaults to `textKey`.
164
+ *
165
+ * @internal Shared with the value help.
166
+ */
167
+ function readableLabel(meta, field, arrangement) {
168
+ if (!isReadable(meta.fields?.[field])) return void 0;
169
+ return {
170
+ field,
171
+ arrangement: arrangement ?? "textKey"
172
+ };
173
+ }
136
174
  /** Sort by (order ?? 0). `toSorted` is stable per spec, so ties preserve declaration order. */
137
175
  function byOrder(xs) {
138
176
  return xs.toSorted((x, y) => (x.order ?? 0) - (y.order ?? 0));
@@ -247,4 +285,6 @@ function inferValueKind(prop) {
247
285
  }
248
286
  //#endregion
249
287
  exports.createTableDef = createTableDef;
288
+ exports.dictLabelOf = dictLabelOf;
250
289
  exports.inferValueKind = inferValueKind;
290
+ exports.readableLabel = readableLabel;
@@ -1,11 +1,12 @@
1
- import { DB_HTTP_PATH, EXPECT_MAX_LENGTH, UI_TABLE_COMPONENT, UI_TABLE_SELECT_WITH, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE } from "../shared/annotation-keys.mjs";
1
+ import { DB_HTTP_PATH, EXPECT_MAX_LENGTH, UI_DICT_LABEL, UI_TABLE_COMPONENT, UI_TABLE_SELECT_WITH, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE } from "../shared/annotation-keys.mjs";
2
2
  import { deserializeServedType } from "../i18n/model-texts.mjs";
3
3
  import { getFieldMeta } from "../shared/field-resolver.mjs";
4
4
  import { extractFieldLiteralOptions, isEmptyMember } from "../value-help/extract-literals.mjs";
5
5
  import { extractValueHelp } from "../value-help/extract-ref.mjs";
6
6
  import { isExactNumberText } from "../shared/exact-number.mjs";
7
- import { humanizePath } from "../shared/str.mjs";
7
+ import { parentPrefix } from "../form/path-utils.mjs";
8
8
  import { extractMeasurement } from "../form/measurement.mjs";
9
+ import { humanizePath } from "../shared/str.mjs";
9
10
  import { valueLabelOf } from "../shared/value-label.mjs";
10
11
  import { flattenAnnotatedType } from "@atscript/typescript/utils";
11
12
  //#region src/table/create-table-def.ts
@@ -59,6 +60,7 @@ function createTableDef(meta, preDeserializedType, t) {
59
60
  preferredId,
60
61
  identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
61
62
  versionColumn: meta.versionColumn,
63
+ label: dictLabelOf(meta, type),
62
64
  crud,
63
65
  canRemove: "remove" in crud,
64
66
  actions,
@@ -80,17 +82,21 @@ function buildColumn(path, prop, fieldMeta, resolved) {
80
82
  const sharedType = getFieldMeta(prop, UI_TYPE);
81
83
  const tableComponent = getFieldMeta(prop, UI_TABLE_COMPONENT);
82
84
  const filterOps = fieldMeta.filterOps;
83
- let selectWith = getFieldMeta(prop, UI_TABLE_SELECT_WITH);
85
+ const measurement = extractMeasurement(prop);
84
86
  const label = valueLabelOf(prop);
85
- let valueLabel;
86
- if (label) {
87
- const dot = path.lastIndexOf(".");
88
- const textPath = dot < 0 ? label.field : `${path.slice(0, dot + 1)}${label.field}`;
89
- valueLabel = {
90
- path: textPath,
91
- arrangement: label.arrangement
92
- };
93
- if (!selectWith?.includes(textPath)) selectWith = [...selectWith ?? [], textPath];
87
+ const siblings = parentPrefix(path);
88
+ const valueLabel = label && {
89
+ path: siblings + label.field,
90
+ arrangement: label.arrangement
91
+ };
92
+ let selectWith = getFieldMeta(prop, UI_TABLE_SELECT_WITH);
93
+ for (const field of [
94
+ label?.field,
95
+ measurement.currencyRefField,
96
+ measurement.unitRefField
97
+ ]) {
98
+ const sibling = field && siblings + field;
99
+ if (sibling && !selectWith?.includes(sibling)) selectWith = [...selectWith ?? [], sibling];
94
100
  }
95
101
  return {
96
102
  path,
@@ -111,7 +117,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
111
117
  valueHelpInfo,
112
118
  ...valueLabel && { valueLabel },
113
119
  ...distinct && { distinct },
114
- ...extractMeasurement(prop)
120
+ ...measurement
115
121
  };
116
122
  }
117
123
  /**
@@ -129,10 +135,42 @@ function identifierFieldsOf(preferredId, actions) {
129
135
  }
130
136
  return out ?? preferredId;
131
137
  }
132
- /** A field the caller may read: listed in `meta.fields` and not write-only. */
138
+ /**
139
+ * A field the caller may read: listed in `meta.fields` and not write-only —
140
+ * the one rule for a table's columns and a dictionary's label.
141
+ */
133
142
  function isReadable(field) {
134
143
  return field !== void 0 && field.writeOnly !== true;
135
144
  }
145
+ /**
146
+ * The label a type's rows declare: the own field its `@ui.dict.label` marks
147
+ * (`@ui.dict.label 'keyText'` → that arrangement, default `textKey`), when
148
+ * the caller can read it. The one rule for a dictionary's label
149
+ * (`ResolvedValueHelp.label`) and a table's (`TableDef.label`).
150
+ */
151
+ function dictLabelOf(meta, type) {
152
+ if (type.type.kind !== "object") return void 0;
153
+ let label;
154
+ for (const [field, prop] of type.type.props) {
155
+ const declared = prop.metadata.get(UI_DICT_LABEL);
156
+ if (declared === void 0 || field === meta.versionColumn) continue;
157
+ label = readableLabel(meta, field, typeof declared === "string" ? declared : void 0);
158
+ }
159
+ return label;
160
+ }
161
+ /**
162
+ * `field` of the served type as a label, when the caller may read it
163
+ * (`isReadable`); the arrangement defaults to `textKey`.
164
+ *
165
+ * @internal Shared with the value help.
166
+ */
167
+ function readableLabel(meta, field, arrangement) {
168
+ if (!isReadable(meta.fields?.[field])) return void 0;
169
+ return {
170
+ field,
171
+ arrangement: arrangement ?? "textKey"
172
+ };
173
+ }
136
174
  /** Sort by (order ?? 0). `toSorted` is stable per spec, so ties preserve declaration order. */
137
175
  function byOrder(xs) {
138
176
  return xs.toSorted((x, y) => (x.order ?? 0) - (y.order ?? 0));
@@ -246,4 +284,4 @@ function inferValueKind(prop) {
246
284
  return [...kinds][0];
247
285
  }
248
286
  //#endregion
249
- export { createTableDef, inferValueKind };
287
+ export { createTableDef, dictLabelOf, inferValueKind, readableLabel };
@@ -1,5 +1,6 @@
1
+ import { ValueLabel, ValueLabelArrangement } from "../shared/value-label.cjs";
1
2
  import { ValueHelpInfo } from "../value-help/types.cjs";
2
- import { ValueLabelArrangement } from "../shared/value-label.cjs";
3
+ import { MeasurementInfo } from "../form/measurement.cjs";
3
4
  import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
5
  import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
5
6
 
@@ -165,6 +166,13 @@ interface TableDef {
165
166
  identifierFields?: string[];
166
167
  /** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
167
168
  versionColumn?: string;
169
+ /**
170
+ * The label of the table's own rows: the field its type's `@ui.dict.label`
171
+ * marks — one the caller can read — with its arrangement (default
172
+ * `textKey`). `undefined` without one. An action dialog names a row by it
173
+ * (`Dune (3f2a…)`). Since 0.1.208.
174
+ */
175
+ label?: ValueLabel;
168
176
  /** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
169
177
  crud: TCrudPermissions;
170
178
  canRemove: boolean;
@@ -183,8 +191,12 @@ interface TableDef {
183
191
  * Since 0.1.148.
184
192
  */
185
193
  type ColumnValueKind = "string" | "date" | "isoDate" | "number" | "integer" | "decimal" | "long" | "timestamp" | "boolean";
186
- /** A single column definition — built from field metadata + annotations. */
187
- interface ColumnDef {
194
+ /**
195
+ * A single column definition — built from field metadata + annotations; its
196
+ * currency / unit / precision fields are the `MeasurementInfo` of
197
+ * `extractMeasurement`.
198
+ */
199
+ interface ColumnDef extends MeasurementInfo {
188
200
  /** Field path in dot-notation (e.g. 'address.city'). */
189
201
  path: string;
190
202
  /** Display label — from @meta.label or humanized path. */
@@ -275,16 +287,6 @@ interface ColumnDef {
275
287
  url: string;
276
288
  field: string;
277
289
  };
278
- /** Literal currency code from `@db.amount.currency 'EUR'`. */
279
- currencyCode?: string;
280
- /** Sibling field path from `@db.amount.currency.ref 'fieldName'`. */
281
- currencyRefField?: string;
282
- /** Literal unit-of-measure from `@db.unit 'kg'`. */
283
- unitCode?: string;
284
- /** Sibling field path from `@db.unit.ref 'fieldName'`. */
285
- unitRefField?: string;
286
- /** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
287
- precisionScale?: number;
288
290
  /**
289
291
  * Synthesised, locked-chrome column. When `true`: header-cell column-menu
290
292
  * skipped, resize handle skipped, drag-reorder excluded, NOT in the
@@ -1,5 +1,6 @@
1
+ import { ValueLabel, ValueLabelArrangement } from "../shared/value-label.mjs";
1
2
  import { ValueHelpInfo } from "../value-help/types.mjs";
2
- import { ValueLabelArrangement } from "../shared/value-label.mjs";
3
+ import { MeasurementInfo } from "../form/measurement.mjs";
3
4
  import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
5
  import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
5
6
 
@@ -165,6 +166,13 @@ interface TableDef {
165
166
  identifierFields?: string[];
166
167
  /** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
167
168
  versionColumn?: string;
169
+ /**
170
+ * The label of the table's own rows: the field its type's `@ui.dict.label`
171
+ * marks — one the caller can read — with its arrangement (default
172
+ * `textKey`). `undefined` without one. An action dialog names a row by it
173
+ * (`Dune (3f2a…)`). Since 0.1.208.
174
+ */
175
+ label?: ValueLabel;
168
176
  /** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
169
177
  crud: TCrudPermissions;
170
178
  canRemove: boolean;
@@ -183,8 +191,12 @@ interface TableDef {
183
191
  * Since 0.1.148.
184
192
  */
185
193
  type ColumnValueKind = "string" | "date" | "isoDate" | "number" | "integer" | "decimal" | "long" | "timestamp" | "boolean";
186
- /** A single column definition — built from field metadata + annotations. */
187
- interface ColumnDef {
194
+ /**
195
+ * A single column definition — built from field metadata + annotations; its
196
+ * currency / unit / precision fields are the `MeasurementInfo` of
197
+ * `extractMeasurement`.
198
+ */
199
+ interface ColumnDef extends MeasurementInfo {
188
200
  /** Field path in dot-notation (e.g. 'address.city'). */
189
201
  path: string;
190
202
  /** Display label — from @meta.label or humanized path. */
@@ -275,16 +287,6 @@ interface ColumnDef {
275
287
  url: string;
276
288
  field: string;
277
289
  };
278
- /** Literal currency code from `@db.amount.currency 'EUR'`. */
279
- currencyCode?: string;
280
- /** Sibling field path from `@db.amount.currency.ref 'fieldName'`. */
281
- currencyRefField?: string;
282
- /** Literal unit-of-measure from `@db.unit 'kg'`. */
283
- unitCode?: string;
284
- /** Sibling field path from `@db.unit.ref 'fieldName'`. */
285
- unitRefField?: string;
286
- /** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
287
- precisionScale?: number;
288
290
  /**
289
291
  * Synthesised, locked-chrome column. When `true`: header-cell column-menu
290
292
  * skipped, resize handle skipped, drag-reorder excluded, NOT in the
@@ -0,0 +1,43 @@
1
+ //#region src/value-help/client-store.ts
2
+ let stores = /* @__PURE__ */ new WeakMap();
3
+ /** Data drops of every client so far. */
4
+ let drops = 0;
5
+ /**
6
+ * The store of `client`, created on first use — and again after a data drop,
7
+ * keeping the texts of the store it replaces (one back) as `stale`.
8
+ */
9
+ function clientStore(client) {
10
+ const prev = stores.get(client);
11
+ if (prev?.drop === drops) return prev;
12
+ for (const texts of prev?.texts.values() ?? []) texts.stale = void 0;
13
+ const store = {
14
+ client,
15
+ drop: drops,
16
+ searches: /* @__PURE__ */ new Map(),
17
+ texts: /* @__PURE__ */ new Map(),
18
+ stale: prev?.texts
19
+ };
20
+ stores.set(client, store);
21
+ return store;
22
+ }
23
+ /** The data of `client`, or of every client, changed: its store is replaced on its next use. */
24
+ function staleClientStores(client) {
25
+ if (!client) drops++;
26
+ else {
27
+ const store = stores.get(client);
28
+ if (store) store.drop = -1;
29
+ }
30
+ }
31
+ /** Drop every client's store, stale texts too (`resetMetaCache`: another viewer). */
32
+ function dropClientStores() {
33
+ stores = /* @__PURE__ */ new WeakMap();
34
+ }
35
+ /** A monotonic clock (ms) where there is one. */
36
+ function now() {
37
+ return typeof performance === "undefined" ? Date.now() : performance.now();
38
+ }
39
+ //#endregion
40
+ exports.clientStore = clientStore;
41
+ exports.dropClientStores = dropClientStores;
42
+ exports.now = now;
43
+ exports.staleClientStores = staleClientStores;
@@ -0,0 +1 @@
1
+ import { ClientLike } from "@atscript/db-client";
@@ -0,0 +1,40 @@
1
+ //#region src/value-help/client-store.ts
2
+ let stores = /* @__PURE__ */ new WeakMap();
3
+ /** Data drops of every client so far. */
4
+ let drops = 0;
5
+ /**
6
+ * The store of `client`, created on first use — and again after a data drop,
7
+ * keeping the texts of the store it replaces (one back) as `stale`.
8
+ */
9
+ function clientStore(client) {
10
+ const prev = stores.get(client);
11
+ if (prev?.drop === drops) return prev;
12
+ for (const texts of prev?.texts.values() ?? []) texts.stale = void 0;
13
+ const store = {
14
+ client,
15
+ drop: drops,
16
+ searches: /* @__PURE__ */ new Map(),
17
+ texts: /* @__PURE__ */ new Map(),
18
+ stale: prev?.texts
19
+ };
20
+ stores.set(client, store);
21
+ return store;
22
+ }
23
+ /** The data of `client`, or of every client, changed: its store is replaced on its next use. */
24
+ function staleClientStores(client) {
25
+ if (!client) drops++;
26
+ else {
27
+ const store = stores.get(client);
28
+ if (store) store.drop = -1;
29
+ }
30
+ }
31
+ /** Drop every client's store, stale texts too (`resetMetaCache`: another viewer). */
32
+ function dropClientStores() {
33
+ stores = /* @__PURE__ */ new WeakMap();
34
+ }
35
+ /** A monotonic clock (ms) where there is one. */
36
+ function now() {
37
+ return typeof performance === "undefined" ? Date.now() : performance.now();
38
+ }
39
+ //#endregion
40
+ export { clientStore, dropClientStores, now, staleClientStores };
@@ -0,0 +1,30 @@
1
+ const require_ui_texts = require("../i18n/ui-texts.cjs");
2
+ const require_resolve_options = require("./resolve-options.cjs");
3
+ const require_value_label = require("../shared/value-label.cjs");
4
+ //#region src/value-help/display-value.ts
5
+ /**
6
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
7
+ * cells, the filter chips, the export and the read-only form fields, in this
8
+ * order:
9
+ *
10
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
11
+ * field's own options);
12
+ * 2. `Yes` / `No` for a boolean;
13
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
14
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
15
+ * (`opts.valueText`).
16
+ *
17
+ * `undefined` when none applies: the value shows as itself.
18
+ */
19
+ function displayValue(holder, value, opts = {}) {
20
+ if (value === null || value === void 0) return void 0;
21
+ const option = require_resolve_options.optionLabel(holder, value);
22
+ if (option !== void 0) return option;
23
+ if (typeof value === "boolean") return (opts.t ?? require_ui_texts.getUiTexts().t)(value ? "UI_YES" : "UI_NO");
24
+ const code = require_value_label.codeOf(value);
25
+ if (code === void 0) return void 0;
26
+ const found = opts.siblingText ?? opts.valueText?.();
27
+ return found && require_value_label.arrangeText(opts.keyText ?? code, found.text, found.arrangement);
28
+ }
29
+ //#endregion
30
+ exports.displayValue = displayValue;
@@ -0,0 +1,45 @@
1
+ import { ValueLabelArrangement, ValueText } from "../shared/value-label.cjs";
2
+ import { TFormEntryOptions } from "./types.cjs";
3
+ import { UiT } from "../i18n/ui-texts.cjs";
4
+
5
+ //#region src/value-help/display-value.d.ts
6
+ /** What {@link displayValue} reads besides the value. Since 0.1.207. */
7
+ interface DisplayValueOptions {
8
+ /** The code as the caller writes it (a cell's number in its locale). Default: the code itself. */
9
+ keyText?: string;
10
+ /**
11
+ * The text of the value's `@ui.valueLabel` sibling, read from its row, with
12
+ * the annotation's arrangement. Set for a field that declares one: it wins
13
+ * over the dictionary — also when empty, then the code shows alone.
14
+ */
15
+ siblingText?: {
16
+ text: unknown;
17
+ arrangement: ValueLabelArrangement;
18
+ };
19
+ /**
20
+ * The dictionary text of the code (`valueHelpText`). Called only when
21
+ * nothing before it applies, so a value an option labels sends no lookup.
22
+ */
23
+ valueText?: () => ValueText | undefined;
24
+ /** Words booleans (`UI_YES` / `UI_NO`). Default: the active UI texts. */
25
+ t?: UiT;
26
+ }
27
+ /**
28
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
29
+ * cells, the filter chips, the export and the read-only form fields, in this
30
+ * order:
31
+ *
32
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
33
+ * field's own options);
34
+ * 2. `Yes` / `No` for a boolean;
35
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
36
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
37
+ * (`opts.valueText`).
38
+ *
39
+ * `undefined` when none applies: the value shows as itself.
40
+ */
41
+ declare function displayValue(holder: {
42
+ options?: readonly TFormEntryOptions[];
43
+ }, value: unknown, opts?: DisplayValueOptions): string | undefined;
44
+ //#endregion
45
+ export { DisplayValueOptions, displayValue };
@@ -0,0 +1,45 @@
1
+ import { ValueLabelArrangement, ValueText } from "../shared/value-label.mjs";
2
+ import { TFormEntryOptions } from "./types.mjs";
3
+ import { UiT } from "../i18n/ui-texts.mjs";
4
+
5
+ //#region src/value-help/display-value.d.ts
6
+ /** What {@link displayValue} reads besides the value. Since 0.1.207. */
7
+ interface DisplayValueOptions {
8
+ /** The code as the caller writes it (a cell's number in its locale). Default: the code itself. */
9
+ keyText?: string;
10
+ /**
11
+ * The text of the value's `@ui.valueLabel` sibling, read from its row, with
12
+ * the annotation's arrangement. Set for a field that declares one: it wins
13
+ * over the dictionary — also when empty, then the code shows alone.
14
+ */
15
+ siblingText?: {
16
+ text: unknown;
17
+ arrangement: ValueLabelArrangement;
18
+ };
19
+ /**
20
+ * The dictionary text of the code (`valueHelpText`). Called only when
21
+ * nothing before it applies, so a value an option labels sends no lookup.
22
+ */
23
+ valueText?: () => ValueText | undefined;
24
+ /** Words booleans (`UI_YES` / `UI_NO`). Default: the active UI texts. */
25
+ t?: UiT;
26
+ }
27
+ /**
28
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
29
+ * cells, the filter chips, the export and the read-only form fields, in this
30
+ * order:
31
+ *
32
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
33
+ * field's own options);
34
+ * 2. `Yes` / `No` for a boolean;
35
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
36
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
37
+ * (`opts.valueText`).
38
+ *
39
+ * `undefined` when none applies: the value shows as itself.
40
+ */
41
+ declare function displayValue(holder: {
42
+ options?: readonly TFormEntryOptions[];
43
+ }, value: unknown, opts?: DisplayValueOptions): string | undefined;
44
+ //#endregion
45
+ export { DisplayValueOptions, displayValue };
@@ -0,0 +1,30 @@
1
+ import { getUiTexts } from "../i18n/ui-texts.mjs";
2
+ import { optionLabel } from "./resolve-options.mjs";
3
+ import { arrangeText, codeOf } from "../shared/value-label.mjs";
4
+ //#region src/value-help/display-value.ts
5
+ /**
6
+ * The words a value shows as (since 0.1.207) — the one rule behind the table
7
+ * cells, the filter chips, the export and the read-only form fields, in this
8
+ * order:
9
+ *
10
+ * 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
11
+ * field's own options);
12
+ * 2. `Yes` / `No` for a boolean;
13
+ * 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
14
+ * `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
15
+ * (`opts.valueText`).
16
+ *
17
+ * `undefined` when none applies: the value shows as itself.
18
+ */
19
+ function displayValue(holder, value, opts = {}) {
20
+ if (value === null || value === void 0) return void 0;
21
+ const option = optionLabel(holder, value);
22
+ if (option !== void 0) return option;
23
+ if (typeof value === "boolean") return (opts.t ?? getUiTexts().t)(value ? "UI_YES" : "UI_NO");
24
+ const code = codeOf(value);
25
+ if (code === void 0) return void 0;
26
+ const found = opts.siblingText ?? opts.valueText?.();
27
+ return found && arrangeText(opts.keyText ?? code, found.text, found.arrangement);
28
+ }
29
+ //#endregion
30
+ export { displayValue };