@atscript/ui 0.1.207 → 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 (86) hide show
  1. package/dist/form/create-form-def.cjs +13 -12
  2. package/dist/form/create-form-def.mjs +14 -13
  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/types.cjs +5 -0
  24. package/dist/form/types.d.cts +14 -0
  25. package/dist/form/types.d.mts +14 -0
  26. package/dist/form/types.mjs +5 -1
  27. package/dist/form/validate.cjs +56 -5
  28. package/dist/form/validate.d.cts +30 -2
  29. package/dist/form/validate.d.mts +30 -2
  30. package/dist/form/validate.mjs +56 -6
  31. package/dist/index.cjs +24 -3
  32. package/dist/index.d.cts +14 -9
  33. package/dist/index.d.mts +14 -9
  34. package/dist/index.mjs +15 -10
  35. package/dist/plugin/annotations.cjs +1 -1
  36. package/dist/plugin/annotations.mjs +1 -1
  37. package/dist/shared/annotation-keys.d.cts +2 -1
  38. package/dist/shared/annotation-keys.d.mts +2 -1
  39. package/dist/shared/dev.cjs +22 -0
  40. package/dist/shared/dev.d.cts +4 -0
  41. package/dist/shared/dev.d.mts +4 -0
  42. package/dist/shared/dev.mjs +22 -0
  43. package/dist/shared/field-resolver.cjs +21 -1
  44. package/dist/shared/field-resolver.d.cts +15 -1
  45. package/dist/shared/field-resolver.d.mts +15 -1
  46. package/dist/shared/field-resolver.mjs +20 -2
  47. package/dist/shared/merge-filters.cjs +28 -0
  48. package/dist/shared/merge-filters.d.cts +13 -0
  49. package/dist/shared/merge-filters.d.mts +13 -0
  50. package/dist/shared/merge-filters.mjs +28 -0
  51. package/dist/shared/resolve-component.cjs +27 -0
  52. package/dist/shared/resolve-component.d.cts +22 -0
  53. package/dist/shared/resolve-component.d.mts +22 -0
  54. package/dist/shared/resolve-component.mjs +27 -0
  55. package/dist/shared/stable-key.cjs +28 -0
  56. package/dist/shared/stable-key.d.cts +13 -0
  57. package/dist/shared/stable-key.d.mts +13 -0
  58. package/dist/shared/stable-key.mjs +28 -0
  59. package/dist/shared/to-date.cjs +65 -0
  60. package/dist/shared/to-date.d.cts +35 -0
  61. package/dist/shared/to-date.d.mts +35 -0
  62. package/dist/shared/to-date.mjs +64 -0
  63. package/dist/table/create-table-def.cjs +49 -15
  64. package/dist/table/create-table-def.mjs +49 -16
  65. package/dist/table/types.d.cts +15 -13
  66. package/dist/table/types.d.mts +15 -13
  67. package/dist/value-help/distinct-client.cjs +80 -7
  68. package/dist/value-help/distinct-client.d.cts +31 -36
  69. package/dist/value-help/distinct-client.d.mts +31 -36
  70. package/dist/value-help/distinct-client.mjs +80 -7
  71. package/dist/value-help/index.d.mts +2 -2
  72. package/dist/value-help/options.cjs +21 -0
  73. package/dist/value-help/options.d.cts +17 -1
  74. package/dist/value-help/options.d.mts +17 -1
  75. package/dist/value-help/options.mjs +21 -1
  76. package/dist/value-help/resolve.cjs +2 -12
  77. package/dist/value-help/resolve.mjs +3 -13
  78. package/dist/value-help/scope.cjs +3 -7
  79. package/dist/value-help/scope.mjs +3 -7
  80. package/dist/value-help/texts.cjs +7 -4
  81. package/dist/value-help/texts.mjs +7 -4
  82. package/dist/value-help/value-help-client.cjs +5 -3
  83. package/dist/value-help/value-help-client.d.cts +3 -2
  84. package/dist/value-help/value-help-client.d.mts +3 -2
  85. package/dist/value-help/value-help-client.mjs +5 -3
  86. package/package.json +10 -10
@@ -1,4 +1,5 @@
1
1
  const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
+ const require_types = require("./types.cjs");
2
3
  const require_model_texts = require("../i18n/model-texts.cjs");
3
4
  const require_field_resolver = require("../shared/field-resolver.cjs");
4
5
  const require_messages = require("../messages.cjs");
@@ -7,6 +8,7 @@ const require_extract_ref = require("../value-help/extract-ref.cjs");
7
8
  const require_db_column = require("./db-column.cjs");
8
9
  const require_path_utils = require("./path-utils.cjs");
9
10
  const require_skipped_nav = require("./skipped-nav.cjs");
11
+ const require_measurement = require("./measurement.cjs");
10
12
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
11
13
  let _atscript_db_meta = require("@atscript/db/meta");
12
14
  let _atscript_db_validator = require("@atscript/db/validator");
@@ -112,7 +114,8 @@ function buildFormDef(type, write, root) {
112
114
  phantom: false,
113
115
  name: "",
114
116
  allStatic: false,
115
- pushDown: false
117
+ pushDown: false,
118
+ component: require_field_resolver.getFieldMeta(type, require_annotation_keys.UI_FORM_COMPONENT)
116
119
  };
117
120
  const def = {
118
121
  type,
@@ -310,6 +313,7 @@ function buildFieldDef(path, typeProp, write) {
310
313
  allStatic,
311
314
  pushDown,
312
315
  valueHelpInfo,
316
+ component: require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_FORM_COMPONENT),
313
317
  ...derived && { derived: true }
314
318
  };
315
319
  const customType = uiType;
@@ -318,12 +322,15 @@ function buildFieldDef(path, typeProp, write) {
318
322
  const hasOptions = require_field_resolver.getFieldMeta(prop, "ui.form.options") !== void 0 || require_field_resolver.getFieldMeta(prop, "ui.form.fn.options") !== void 0 || require_extract_literals.isPureLiteralUnion(arrayType.of);
319
323
  const isTags = customType === "tags" || customType === "multiselect" && !hasOptions;
320
324
  const isMultiselect = customType === "multiselect" || hasOptions;
325
+ const item = arrayType.of.type;
321
326
  return {
322
327
  ...base,
323
328
  type: "array",
324
329
  customType: isTags ? "tags" : isMultiselect ? "multiselect" : customType,
325
330
  itemType: arrayType.of,
326
- itemField: labelledBy(createFieldDef("", arrayType.of, write), prop)
331
+ itemField: labelledBy(createFieldDef("", arrayType.of, write), prop),
332
+ uniqueItems: prop.metadata.has(require_annotation_keys.EXPECT_ARRAY_UNIQUE_ITEMS),
333
+ numericItems: item.kind === "" && item.designType === "number"
327
334
  };
328
335
  }
329
336
  if (kind === "object") return {
@@ -383,16 +390,9 @@ function buildFieldDef(path, typeProp, write) {
383
390
  const dt = kind === "" ? prop.type.designType : void 0;
384
391
  let numericType;
385
392
  if (kind === "") {
386
- const hasCurrency = require_field_resolver.getFieldMeta(prop, "db.amount.currency") !== void 0 || require_field_resolver.getFieldMeta(prop, "db.amount.currency.ref") !== void 0;
387
- const isDecimalDesign = dt === "decimal";
388
- if (hasCurrency) numericType = "decimal";
389
- else if (isDecimalDesign) numericType = "decimal";
390
- else if (dt === "number") {
391
- const hasUnit = require_field_resolver.getFieldMeta(prop, "db.unit") !== void 0 || require_field_resolver.getFieldMeta(prop, "db.unit.ref") !== void 0;
392
- const hasPrefix = require_field_resolver.getFieldMeta(prop, "ui.form.prefix") !== void 0 || require_field_resolver.getFieldMeta(prop, "ui.form.prefix.ref") !== void 0 || require_field_resolver.getFieldMeta(prop, "ui.form.prefix.icon") !== void 0;
393
- const hasSuffix = require_field_resolver.getFieldMeta(prop, "ui.form.suffix") !== void 0 || require_field_resolver.getFieldMeta(prop, "ui.form.suffix.ref") !== void 0 || require_field_resolver.getFieldMeta(prop, "ui.form.suffix.icon") !== void 0;
394
- if (hasUnit || hasPrefix || hasSuffix) numericType = "number";
395
- }
393
+ const adornment = require_measurement.numberAdornment(prop);
394
+ if (adornment === "currency" || dt === "decimal") numericType = "decimal";
395
+ else if (adornment && dt === "number") numericType = "number";
396
396
  }
397
397
  const tagType = isTimestamp ? "datetime" : void 0;
398
398
  return {
@@ -492,6 +492,7 @@ function createUnionVariants(typeDef, write) {
492
492
  for (const item of items) {
493
493
  const v = createVariant(item, write);
494
494
  if (v.itemField) labelledBy(v.itemField, typeDef);
495
+ if (v.itemField && require_types.isArrayField(v.itemField) && typeDef.metadata.has("expect.array.uniqueItems")) v.itemField.uniqueItems = true;
495
496
  if (items.length > 1) v.label = `${String(variants.length + 1)}. ${v.label}`;
496
497
  variants.push(v);
497
498
  }
@@ -1,4 +1,5 @@
1
- import { META_DESCRIPTION, META_LABEL, UI_FORM_COMPONENT, UI_FORM_PUSH_DOWN, UI_TYPE } from "../shared/annotation-keys.mjs";
1
+ import { EXPECT_ARRAY_UNIQUE_ITEMS, META_DESCRIPTION, META_LABEL, UI_FORM_COMPONENT, UI_FORM_PUSH_DOWN, UI_TYPE } from "../shared/annotation-keys.mjs";
2
+ import { isArrayField } from "./types.mjs";
2
3
  import { isServedType } from "../i18n/model-texts.mjs";
3
4
  import { getFieldMeta, hasComputedAnnotations } from "../shared/field-resolver.mjs";
4
5
  import { AS_UI_MESSAGES } from "../messages.mjs";
@@ -7,6 +8,7 @@ import { extractValueHelp, isValueHelpPicker } from "../value-help/extract-ref.m
7
8
  import { columnHas, isDbDefaulted, soleValueMember } from "./db-column.mjs";
8
9
  import { parentPrefix } from "./path-utils.mjs";
9
10
  import { isSkippedNavField } from "./skipped-nav.mjs";
11
+ import { numberAdornment } from "./measurement.mjs";
10
12
  import { flattenAnnotatedType } from "@atscript/typescript/utils";
11
13
  import { writableViewReadOnlyFields } from "@atscript/db/meta";
12
14
  import { isNavRelation, isServerStampedOnUpdate } from "@atscript/db/validator";
@@ -112,7 +114,8 @@ function buildFormDef(type, write, root) {
112
114
  phantom: false,
113
115
  name: "",
114
116
  allStatic: false,
115
- pushDown: false
117
+ pushDown: false,
118
+ component: getFieldMeta(type, UI_FORM_COMPONENT)
116
119
  };
117
120
  const def = {
118
121
  type,
@@ -310,6 +313,7 @@ function buildFieldDef(path, typeProp, write) {
310
313
  allStatic,
311
314
  pushDown,
312
315
  valueHelpInfo,
316
+ component: getFieldMeta(prop, UI_FORM_COMPONENT),
313
317
  ...derived && { derived: true }
314
318
  };
315
319
  const customType = uiType;
@@ -318,12 +322,15 @@ function buildFieldDef(path, typeProp, write) {
318
322
  const hasOptions = getFieldMeta(prop, "ui.form.options") !== void 0 || getFieldMeta(prop, "ui.form.fn.options") !== void 0 || isPureLiteralUnion(arrayType.of);
319
323
  const isTags = customType === "tags" || customType === "multiselect" && !hasOptions;
320
324
  const isMultiselect = customType === "multiselect" || hasOptions;
325
+ const item = arrayType.of.type;
321
326
  return {
322
327
  ...base,
323
328
  type: "array",
324
329
  customType: isTags ? "tags" : isMultiselect ? "multiselect" : customType,
325
330
  itemType: arrayType.of,
326
- itemField: labelledBy(createFieldDef("", arrayType.of, write), prop)
331
+ itemField: labelledBy(createFieldDef("", arrayType.of, write), prop),
332
+ uniqueItems: prop.metadata.has(EXPECT_ARRAY_UNIQUE_ITEMS),
333
+ numericItems: item.kind === "" && item.designType === "number"
327
334
  };
328
335
  }
329
336
  if (kind === "object") return {
@@ -383,16 +390,9 @@ function buildFieldDef(path, typeProp, write) {
383
390
  const dt = kind === "" ? prop.type.designType : void 0;
384
391
  let numericType;
385
392
  if (kind === "") {
386
- const hasCurrency = getFieldMeta(prop, "db.amount.currency") !== void 0 || getFieldMeta(prop, "db.amount.currency.ref") !== void 0;
387
- const isDecimalDesign = dt === "decimal";
388
- if (hasCurrency) numericType = "decimal";
389
- else if (isDecimalDesign) numericType = "decimal";
390
- else if (dt === "number") {
391
- const hasUnit = getFieldMeta(prop, "db.unit") !== void 0 || getFieldMeta(prop, "db.unit.ref") !== void 0;
392
- const hasPrefix = getFieldMeta(prop, "ui.form.prefix") !== void 0 || getFieldMeta(prop, "ui.form.prefix.ref") !== void 0 || getFieldMeta(prop, "ui.form.prefix.icon") !== void 0;
393
- const hasSuffix = getFieldMeta(prop, "ui.form.suffix") !== void 0 || getFieldMeta(prop, "ui.form.suffix.ref") !== void 0 || getFieldMeta(prop, "ui.form.suffix.icon") !== void 0;
394
- if (hasUnit || hasPrefix || hasSuffix) numericType = "number";
395
- }
393
+ const adornment = numberAdornment(prop);
394
+ if (adornment === "currency" || dt === "decimal") numericType = "decimal";
395
+ else if (adornment && dt === "number") numericType = "number";
396
396
  }
397
397
  const tagType = isTimestamp ? "datetime" : void 0;
398
398
  return {
@@ -492,6 +492,7 @@ function createUnionVariants(typeDef, write) {
492
492
  for (const item of items) {
493
493
  const v = createVariant(item, write);
494
494
  if (v.itemField) labelledBy(v.itemField, typeDef);
495
+ if (v.itemField && isArrayField(v.itemField) && typeDef.metadata.has("expect.array.uniqueItems")) v.itemField.uniqueItems = true;
495
496
  if (items.length > 1) v.label = `${String(variants.length + 1)}. ${v.label}`;
496
497
  variants.push(v);
497
498
  }
@@ -257,6 +257,12 @@ function joinDecimalString(parts) {
257
257
  const body = decimal === "" ? integer : `${integer}.${decimal}`;
258
258
  return `${parts.sign}${body}`;
259
259
  }
260
+ /**
261
+ * A decimal as text in `locale`: with a `currency`, as money; else with
262
+ * `scale` fraction digits and the `unit`. Money is never cut: every digit of
263
+ * the value shows, padded to at least `scale`, else the currency's own digits
264
+ * (`"12.5"` → `$12.50`, `"12.505"` stays `$12.505`).
265
+ */
260
266
  function formatDecimalForDisplay(opts) {
261
267
  const { value, scale, locale, currency, unit, useGrouping = currency !== void 0 || unit !== void 0 || scale !== void 0 } = opts;
262
268
  if (value === null || value === void 0 || value === "") return "";
@@ -266,10 +272,9 @@ function formatDecimalForDisplay(opts) {
266
272
  canonical = String(value);
267
273
  } else canonical = value;
268
274
  if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
269
- if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
270
275
  if (currency) {
271
276
  const parts = splitDecimalString(canonical);
272
- const digits = scale ?? Math.min(Math.max(getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
277
+ const digits = Math.min(Math.max(scale ?? getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
273
278
  if (Number.isFinite(Number(canonical))) try {
274
279
  return getNumberFormat(locale, {
275
280
  style: "currency",
@@ -282,7 +287,7 @@ function formatDecimalForDisplay(opts) {
282
287
  } catch {}
283
288
  return `${currency} ${formatPlain(parts, digits, locale, useGrouping)}`;
284
289
  }
285
- const base = formatPlain(splitDecimalString(canonical), scale, locale, useGrouping);
290
+ const base = formatPlain(splitDecimalString(enforceScale(canonical, scale)), scale, locale, useGrouping);
286
291
  return unit ? `${base} ${unit}` : base;
287
292
  }
288
293
  function formatPlain(parts, scale, locale, useGrouping) {
@@ -25,10 +25,10 @@ interface DecimalParts {
25
25
  }
26
26
  interface FormatDecimalOptions {
27
27
  value: string | number | null | undefined;
28
- /** Scale used for display (typically the effective scale, not DB scale). Trailing zeros pad. */
28
+ /** Fraction digits shown: padded with zeros, cut past it — money aside (`formatDecimalForDisplay`). */
29
29
  scale?: number;
30
30
  locale?: string;
31
- /** When set → Intl.NumberFormat with style:currency. Symbol/grouping handled by Intl. */
31
+ /** When set → Intl.NumberFormat with style:currency (`formatDecimalForDisplay`). */
32
32
  currency?: string;
33
33
  /** When set (and no currency) → "<formatted> <unit>". */
34
34
  unit?: string;
@@ -76,6 +76,12 @@ declare function enforceScale(s: string, scale: number | undefined, opts?: {
76
76
  }): string;
77
77
  declare function splitDecimalString(s: string): DecimalParts;
78
78
  declare function joinDecimalString(parts: DecimalParts): string;
79
+ /**
80
+ * A decimal as text in `locale`: with a `currency`, as money; else with
81
+ * `scale` fraction digits and the `unit`. Money is never cut: every digit of
82
+ * the value shows, padded to at least `scale`, else the currency's own digits
83
+ * (`"12.5"` → `$12.50`, `"12.505"` stays `$12.505`).
84
+ */
79
85
  declare function formatDecimalForDisplay(opts: FormatDecimalOptions): string;
80
86
  /**
81
87
  * Insert the locale's thousands separator into a plain integer string.
@@ -25,10 +25,10 @@ interface DecimalParts {
25
25
  }
26
26
  interface FormatDecimalOptions {
27
27
  value: string | number | null | undefined;
28
- /** Scale used for display (typically the effective scale, not DB scale). Trailing zeros pad. */
28
+ /** Fraction digits shown: padded with zeros, cut past it — money aside (`formatDecimalForDisplay`). */
29
29
  scale?: number;
30
30
  locale?: string;
31
- /** When set → Intl.NumberFormat with style:currency. Symbol/grouping handled by Intl. */
31
+ /** When set → Intl.NumberFormat with style:currency (`formatDecimalForDisplay`). */
32
32
  currency?: string;
33
33
  /** When set (and no currency) → "<formatted> <unit>". */
34
34
  unit?: string;
@@ -76,6 +76,12 @@ declare function enforceScale(s: string, scale: number | undefined, opts?: {
76
76
  }): string;
77
77
  declare function splitDecimalString(s: string): DecimalParts;
78
78
  declare function joinDecimalString(parts: DecimalParts): string;
79
+ /**
80
+ * A decimal as text in `locale`: with a `currency`, as money; else with
81
+ * `scale` fraction digits and the `unit`. Money is never cut: every digit of
82
+ * the value shows, padded to at least `scale`, else the currency's own digits
83
+ * (`"12.5"` → `$12.50`, `"12.505"` stays `$12.505`).
84
+ */
79
85
  declare function formatDecimalForDisplay(opts: FormatDecimalOptions): string;
80
86
  /**
81
87
  * Insert the locale's thousands separator into a plain integer string.
@@ -257,6 +257,12 @@ function joinDecimalString(parts) {
257
257
  const body = decimal === "" ? integer : `${integer}.${decimal}`;
258
258
  return `${parts.sign}${body}`;
259
259
  }
260
+ /**
261
+ * A decimal as text in `locale`: with a `currency`, as money; else with
262
+ * `scale` fraction digits and the `unit`. Money is never cut: every digit of
263
+ * the value shows, padded to at least `scale`, else the currency's own digits
264
+ * (`"12.5"` → `$12.50`, `"12.505"` stays `$12.505`).
265
+ */
260
266
  function formatDecimalForDisplay(opts) {
261
267
  const { value, scale, locale, currency, unit, useGrouping = currency !== void 0 || unit !== void 0 || scale !== void 0 } = opts;
262
268
  if (value === null || value === void 0 || value === "") return "";
@@ -266,10 +272,9 @@ function formatDecimalForDisplay(opts) {
266
272
  canonical = String(value);
267
273
  } else canonical = value;
268
274
  if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
269
- if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
270
275
  if (currency) {
271
276
  const parts = splitDecimalString(canonical);
272
- const digits = scale ?? Math.min(Math.max(getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
277
+ const digits = Math.min(Math.max(scale ?? getCurrencyDecimals(currency, locale) ?? 0, parts.decimal.length), 100);
273
278
  if (Number.isFinite(Number(canonical))) try {
274
279
  return getNumberFormat(locale, {
275
280
  style: "currency",
@@ -282,7 +287,7 @@ function formatDecimalForDisplay(opts) {
282
287
  } catch {}
283
288
  return `${currency} ${formatPlain(parts, digits, locale, useGrouping)}`;
284
289
  }
285
- const base = formatPlain(splitDecimalString(canonical), scale, locale, useGrouping);
290
+ const base = formatPlain(splitDecimalString(enforceScale(canonical, scale)), scale, locale, useGrouping);
286
291
  return unit ? `${base} ${unit}` : base;
287
292
  }
288
293
  function formatPlain(parts, scale, locale, useGrouping) {
@@ -26,5 +26,14 @@ function getDeclaredFormActions(def) {
26
26
  }
27
27
  return out;
28
28
  }
29
+ /**
30
+ * The declared action `id` of a form ({@link getDeclaredFormActions}) —
31
+ * `undefined` when the form declares none with that id: what a host gates a
32
+ * fired action on, and its `withData` how it is sent. Since 0.1.208.
33
+ */
34
+ function getDeclaredFormAction(def, id) {
35
+ return getDeclaredFormActions(def).find((a) => a.id === id);
36
+ }
29
37
  //#endregion
38
+ exports.getDeclaredFormAction = getDeclaredFormAction;
30
39
  exports.getDeclaredFormActions = getDeclaredFormActions;
@@ -13,5 +13,11 @@ interface FormActionInfo {
13
13
  * stateless action. Single source of truth for "what actions can a host fire".
14
14
  */
15
15
  declare function getDeclaredFormActions(def: FormDef): FormActionInfo[];
16
+ /**
17
+ * The declared action `id` of a form ({@link getDeclaredFormActions}) —
18
+ * `undefined` when the form declares none with that id: what a host gates a
19
+ * fired action on, and its `withData` how it is sent. Since 0.1.208.
20
+ */
21
+ declare function getDeclaredFormAction(def: FormDef, id: string): FormActionInfo | undefined;
16
22
  //#endregion
17
- export { FormActionInfo, getDeclaredFormActions };
23
+ export { FormActionInfo, getDeclaredFormAction, getDeclaredFormActions };
@@ -13,5 +13,11 @@ interface FormActionInfo {
13
13
  * stateless action. Single source of truth for "what actions can a host fire".
14
14
  */
15
15
  declare function getDeclaredFormActions(def: FormDef): FormActionInfo[];
16
+ /**
17
+ * The declared action `id` of a form ({@link getDeclaredFormActions}) —
18
+ * `undefined` when the form declares none with that id: what a host gates a
19
+ * fired action on, and its `withData` how it is sent. Since 0.1.208.
20
+ */
21
+ declare function getDeclaredFormAction(def: FormDef, id: string): FormActionInfo | undefined;
16
22
  //#endregion
17
- export { FormActionInfo, getDeclaredFormActions };
23
+ export { FormActionInfo, getDeclaredFormAction, getDeclaredFormActions };
@@ -26,5 +26,13 @@ function getDeclaredFormActions(def) {
26
26
  }
27
27
  return out;
28
28
  }
29
+ /**
30
+ * The declared action `id` of a form ({@link getDeclaredFormActions}) —
31
+ * `undefined` when the form declares none with that id: what a host gates a
32
+ * fired action on, and its `withData` how it is sent. Since 0.1.208.
33
+ */
34
+ function getDeclaredFormAction(def, id) {
35
+ return getDeclaredFormActions(def).find((a) => a.id === id);
36
+ }
29
37
  //#endregion
30
- export { getDeclaredFormActions };
38
+ export { getDeclaredFormAction, getDeclaredFormActions };
@@ -1,5 +1,7 @@
1
1
  const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
2
  const require_field_resolver = require("../shared/field-resolver.cjs");
3
+ const require_path_utils = require("./path-utils.cjs");
4
+ const require_decimal_format = require("./decimal-format.cjs");
3
5
  //#region src/form/measurement.ts
4
6
  /**
5
7
  * Read measurement annotations off a single field prop. Returns `undefined`
@@ -16,5 +18,61 @@ function extractMeasurement(prop) {
16
18
  precisionScale: precisionMeta?.scale
17
19
  };
18
20
  }
21
+ const CURRENCY_KEYS = [require_annotation_keys.DB_AMOUNT_CURRENCY, require_annotation_keys.DB_AMOUNT_CURRENCY_REF];
22
+ const ADORNMENT_KEYS = [
23
+ require_annotation_keys.DB_UNIT,
24
+ require_annotation_keys.DB_UNIT_REF,
25
+ require_annotation_keys.UI_FORM_PREFIX,
26
+ require_annotation_keys.UI_FORM_PREFIX_REF,
27
+ require_annotation_keys.UI_FORM_PREFIX_ICON,
28
+ require_annotation_keys.UI_FORM_SUFFIX,
29
+ require_annotation_keys.UI_FORM_SUFFIX_REF,
30
+ require_annotation_keys.UI_FORM_SUFFIX_ICON
31
+ ];
32
+ const hasAny = (prop, keys) => keys.some((key) => require_field_resolver.getFieldMeta(prop, key) !== void 0);
33
+ /**
34
+ * What adorns a number field: `"currency"` — `@db.amount.currency` or its
35
+ * `.ref`; `"other"` — a unit (`@db.unit` or its `.ref`), a `@ui.form.prefix` or
36
+ * `@ui.form.suffix` (text, `.ref` or icon); else `undefined`. The one key list
37
+ * behind a form field's type (money is `decimal`, an adorned `number` is
38
+ * `number`) and `AsField`'s `hasAdornment`.
39
+ *
40
+ * @internal Shared with `@atscript/vue-form`.
41
+ */
42
+ function numberAdornment(prop) {
43
+ if (hasAny(prop, CURRENCY_KEYS)) return "currency";
44
+ return hasAny(prop, ADORNMENT_KEYS) ? "other" : void 0;
45
+ }
46
+ /**
47
+ * The text a `.ref` names: the field `ref` next to `path` (`price.currency` for
48
+ * `price.amount`), read through `read`; only a non-empty string counts.
49
+ *
50
+ * @internal Shared with `@atscript/vue-form` (`AsField`'s `.ref` prefix / suffix).
51
+ */
52
+ function refText(path, ref, read) {
53
+ const v = ref ? read(require_path_utils.parentPrefix(path) + ref) : void 0;
54
+ return typeof v === "string" && v.length > 0 ? v : void 0;
55
+ }
56
+ /**
57
+ * The currency, unit and scale of the number at `path` (since 0.1.208) — the one
58
+ * rule a form field and a table cell write it by. A `.ref` names a sibling: the
59
+ * field next to the number, read through `read` (`price.currency` for
60
+ * `price.amount`); only a non-empty string counts. The scale is
61
+ * `min(currency digits, precisionScale)`, the currency's digits alone, or
62
+ * `precisionScale` alone: a column never shows more digits than it stores.
63
+ */
64
+ function resolveMeasurement(info, path, read, locale) {
65
+ const currency = info.currencyCode || refText(path, info.currencyRefField, read);
66
+ const digits = currency ? require_decimal_format.getCurrencyDecimals(currency, locale) : void 0;
67
+ const stored = info.precisionScale;
68
+ return {
69
+ currency,
70
+ unit: info.unitCode || refText(path, info.unitRefField, read),
71
+ scale: digits === void 0 ? stored : stored === void 0 ? digits : Math.min(digits, stored)
72
+ };
73
+ }
19
74
  //#endregion
20
75
  exports.extractMeasurement = extractMeasurement;
76
+ exports.numberAdornment = numberAdornment;
77
+ exports.refText = refText;
78
+ exports.resolveMeasurement = resolveMeasurement;
@@ -25,5 +25,40 @@ interface MeasurementInfo {
25
25
  * larger record.
26
26
  */
27
27
  declare function extractMeasurement(prop: TAtscriptAnnotatedType): MeasurementInfo;
28
+ /**
29
+ * What adorns a number field: `"currency"` — `@db.amount.currency` or its
30
+ * `.ref`; `"other"` — a unit (`@db.unit` or its `.ref`), a `@ui.form.prefix` or
31
+ * `@ui.form.suffix` (text, `.ref` or icon); else `undefined`. The one key list
32
+ * behind a form field's type (money is `decimal`, an adorned `number` is
33
+ * `number`) and `AsField`'s `hasAdornment`.
34
+ *
35
+ * @internal Shared with `@atscript/vue-form`.
36
+ */
37
+ declare function numberAdornment(prop: TAtscriptAnnotatedType): "currency" | "other" | undefined;
38
+ /** A measured number's currency, unit and scale, as {@link resolveMeasurement} reads them. */
39
+ interface Measurement {
40
+ /** `currencyCode`, else the text of the `currencyRefField` sibling. */
41
+ currency?: string;
42
+ /** `unitCode`, else the text of the `unitRefField` sibling. */
43
+ unit?: string;
44
+ /** The fraction digits the number is written with ({@link resolveMeasurement}). */
45
+ scale?: number;
46
+ }
47
+ /**
48
+ * The text a `.ref` names: the field `ref` next to `path` (`price.currency` for
49
+ * `price.amount`), read through `read`; only a non-empty string counts.
50
+ *
51
+ * @internal Shared with `@atscript/vue-form` (`AsField`'s `.ref` prefix / suffix).
52
+ */
53
+ declare function refText(path: string, ref: string | undefined, read: (path: string) => unknown): string | undefined;
54
+ /**
55
+ * The currency, unit and scale of the number at `path` (since 0.1.208) — the one
56
+ * rule a form field and a table cell write it by. A `.ref` names a sibling: the
57
+ * field next to the number, read through `read` (`price.currency` for
58
+ * `price.amount`); only a non-empty string counts. The scale is
59
+ * `min(currency digits, precisionScale)`, the currency's digits alone, or
60
+ * `precisionScale` alone: a column never shows more digits than it stores.
61
+ */
62
+ declare function resolveMeasurement(info: MeasurementInfo, path: string, read: (path: string) => unknown, locale?: string): Measurement;
28
63
  //#endregion
29
- export { MeasurementInfo, extractMeasurement };
64
+ export { Measurement, MeasurementInfo, extractMeasurement, numberAdornment, refText, resolveMeasurement };
@@ -25,5 +25,40 @@ interface MeasurementInfo {
25
25
  * larger record.
26
26
  */
27
27
  declare function extractMeasurement(prop: TAtscriptAnnotatedType): MeasurementInfo;
28
+ /**
29
+ * What adorns a number field: `"currency"` — `@db.amount.currency` or its
30
+ * `.ref`; `"other"` — a unit (`@db.unit` or its `.ref`), a `@ui.form.prefix` or
31
+ * `@ui.form.suffix` (text, `.ref` or icon); else `undefined`. The one key list
32
+ * behind a form field's type (money is `decimal`, an adorned `number` is
33
+ * `number`) and `AsField`'s `hasAdornment`.
34
+ *
35
+ * @internal Shared with `@atscript/vue-form`.
36
+ */
37
+ declare function numberAdornment(prop: TAtscriptAnnotatedType): "currency" | "other" | undefined;
38
+ /** A measured number's currency, unit and scale, as {@link resolveMeasurement} reads them. */
39
+ interface Measurement {
40
+ /** `currencyCode`, else the text of the `currencyRefField` sibling. */
41
+ currency?: string;
42
+ /** `unitCode`, else the text of the `unitRefField` sibling. */
43
+ unit?: string;
44
+ /** The fraction digits the number is written with ({@link resolveMeasurement}). */
45
+ scale?: number;
46
+ }
47
+ /**
48
+ * The text a `.ref` names: the field `ref` next to `path` (`price.currency` for
49
+ * `price.amount`), read through `read`; only a non-empty string counts.
50
+ *
51
+ * @internal Shared with `@atscript/vue-form` (`AsField`'s `.ref` prefix / suffix).
52
+ */
53
+ declare function refText(path: string, ref: string | undefined, read: (path: string) => unknown): string | undefined;
54
+ /**
55
+ * The currency, unit and scale of the number at `path` (since 0.1.208) — the one
56
+ * rule a form field and a table cell write it by. A `.ref` names a sibling: the
57
+ * field next to the number, read through `read` (`price.currency` for
58
+ * `price.amount`); only a non-empty string counts. The scale is
59
+ * `min(currency digits, precisionScale)`, the currency's digits alone, or
60
+ * `precisionScale` alone: a column never shows more digits than it stores.
61
+ */
62
+ declare function resolveMeasurement(info: MeasurementInfo, path: string, read: (path: string) => unknown, locale?: string): Measurement;
28
63
  //#endregion
29
- export { MeasurementInfo, extractMeasurement };
64
+ export { Measurement, MeasurementInfo, extractMeasurement, numberAdornment, refText, resolveMeasurement };
@@ -1,5 +1,7 @@
1
- import { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_UNIT, DB_UNIT_REF } from "../shared/annotation-keys.mjs";
1
+ import { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_UNIT, DB_UNIT_REF, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF } from "../shared/annotation-keys.mjs";
2
2
  import { getFieldMeta } from "../shared/field-resolver.mjs";
3
+ import { parentPrefix } from "./path-utils.mjs";
4
+ import { getCurrencyDecimals } from "./decimal-format.mjs";
3
5
  //#region src/form/measurement.ts
4
6
  /**
5
7
  * Read measurement annotations off a single field prop. Returns `undefined`
@@ -16,5 +18,58 @@ function extractMeasurement(prop) {
16
18
  precisionScale: precisionMeta?.scale
17
19
  };
18
20
  }
21
+ const CURRENCY_KEYS = [DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF];
22
+ const ADORNMENT_KEYS = [
23
+ DB_UNIT,
24
+ DB_UNIT_REF,
25
+ UI_FORM_PREFIX,
26
+ UI_FORM_PREFIX_REF,
27
+ UI_FORM_PREFIX_ICON,
28
+ UI_FORM_SUFFIX,
29
+ UI_FORM_SUFFIX_REF,
30
+ UI_FORM_SUFFIX_ICON
31
+ ];
32
+ const hasAny = (prop, keys) => keys.some((key) => getFieldMeta(prop, key) !== void 0);
33
+ /**
34
+ * What adorns a number field: `"currency"` — `@db.amount.currency` or its
35
+ * `.ref`; `"other"` — a unit (`@db.unit` or its `.ref`), a `@ui.form.prefix` or
36
+ * `@ui.form.suffix` (text, `.ref` or icon); else `undefined`. The one key list
37
+ * behind a form field's type (money is `decimal`, an adorned `number` is
38
+ * `number`) and `AsField`'s `hasAdornment`.
39
+ *
40
+ * @internal Shared with `@atscript/vue-form`.
41
+ */
42
+ function numberAdornment(prop) {
43
+ if (hasAny(prop, CURRENCY_KEYS)) return "currency";
44
+ return hasAny(prop, ADORNMENT_KEYS) ? "other" : void 0;
45
+ }
46
+ /**
47
+ * The text a `.ref` names: the field `ref` next to `path` (`price.currency` for
48
+ * `price.amount`), read through `read`; only a non-empty string counts.
49
+ *
50
+ * @internal Shared with `@atscript/vue-form` (`AsField`'s `.ref` prefix / suffix).
51
+ */
52
+ function refText(path, ref, read) {
53
+ const v = ref ? read(parentPrefix(path) + ref) : void 0;
54
+ return typeof v === "string" && v.length > 0 ? v : void 0;
55
+ }
56
+ /**
57
+ * The currency, unit and scale of the number at `path` (since 0.1.208) — the one
58
+ * rule a form field and a table cell write it by. A `.ref` names a sibling: the
59
+ * field next to the number, read through `read` (`price.currency` for
60
+ * `price.amount`); only a non-empty string counts. The scale is
61
+ * `min(currency digits, precisionScale)`, the currency's digits alone, or
62
+ * `precisionScale` alone: a column never shows more digits than it stores.
63
+ */
64
+ function resolveMeasurement(info, path, read, locale) {
65
+ const currency = info.currencyCode || refText(path, info.currencyRefField, read);
66
+ const digits = currency ? getCurrencyDecimals(currency, locale) : void 0;
67
+ const stored = info.precisionScale;
68
+ return {
69
+ currency,
70
+ unit: info.unitCode || refText(path, info.unitRefField, read),
71
+ scale: digits === void 0 ? stored : stored === void 0 ? digits : Math.min(digits, stored)
72
+ };
73
+ }
19
74
  //#endregion
20
- export { extractMeasurement };
75
+ export { extractMeasurement, numberAdornment, refText, resolveMeasurement };
@@ -1,6 +1,16 @@
1
1
  const require_path_utils = require("./path-utils.cjs");
2
+ const require_skipped_nav = require("./skipped-nav.cjs");
2
3
  //#region src/form/omit-derived.ts
3
4
  /**
5
+ * What a form sends of its data `value` (the unwrapped domain data of `def`'s
6
+ * type, normalized) — `<AsForm>`'s submit data and an action's: without the
7
+ * navigation fields the form leaves out ({@link omitSkippedNavFields}) and the
8
+ * fields the server owns ({@link omitDerivedFields}). Since 0.1.208.
9
+ */
10
+ function formPayload(def, value) {
11
+ return omitDerivedFields(def, require_skipped_nav.omitSkippedNavFields(def, value));
12
+ }
13
+ /**
4
14
  * Form data `value` (the unwrapped domain data of `def`'s type) without the
5
15
  * fields the server owns — the root fields `createFormDef` marked `derived`: a
6
16
  * served field `/meta` marks `readOnly`, a writable view's own field, a
@@ -35,4 +45,5 @@ function without(obj, keys, i) {
35
45
  return rest;
36
46
  }
37
47
  //#endregion
48
+ exports.formPayload = formPayload;
38
49
  exports.omitDerivedFields = omitDerivedFields;
@@ -1,6 +1,13 @@
1
1
  import { FormDef } from "./types.cjs";
2
2
 
3
3
  //#region src/form/omit-derived.d.ts
4
+ /**
5
+ * What a form sends of its data `value` (the unwrapped domain data of `def`'s
6
+ * type, normalized) — `<AsForm>`'s submit data and an action's: without the
7
+ * navigation fields the form leaves out ({@link omitSkippedNavFields}) and the
8
+ * fields the server owns ({@link omitDerivedFields}). Since 0.1.208.
9
+ */
10
+ declare function formPayload<T>(def: FormDef, value: T): T;
4
11
  /**
5
12
  * Form data `value` (the unwrapped domain data of `def`'s type) without the
6
13
  * fields the server owns — the root fields `createFormDef` marked `derived`: a
@@ -14,4 +21,4 @@ import { FormDef } from "./types.cjs";
14
21
  */
15
22
  declare function omitDerivedFields<T>(def: FormDef, value: T): T;
16
23
  //#endregion
17
- export { omitDerivedFields };
24
+ export { formPayload, omitDerivedFields };
@@ -1,6 +1,13 @@
1
1
  import { FormDef } from "./types.mjs";
2
2
 
3
3
  //#region src/form/omit-derived.d.ts
4
+ /**
5
+ * What a form sends of its data `value` (the unwrapped domain data of `def`'s
6
+ * type, normalized) — `<AsForm>`'s submit data and an action's: without the
7
+ * navigation fields the form leaves out ({@link omitSkippedNavFields}) and the
8
+ * fields the server owns ({@link omitDerivedFields}). Since 0.1.208.
9
+ */
10
+ declare function formPayload<T>(def: FormDef, value: T): T;
4
11
  /**
5
12
  * Form data `value` (the unwrapped domain data of `def`'s type) without the
6
13
  * fields the server owns — the root fields `createFormDef` marked `derived`: a
@@ -14,4 +21,4 @@ import { FormDef } from "./types.mjs";
14
21
  */
15
22
  declare function omitDerivedFields<T>(def: FormDef, value: T): T;
16
23
  //#endregion
17
- export { omitDerivedFields };
24
+ export { formPayload, omitDerivedFields };
@@ -1,6 +1,16 @@
1
1
  import { isPlainObject } from "./path-utils.mjs";
2
+ import { omitSkippedNavFields } from "./skipped-nav.mjs";
2
3
  //#region src/form/omit-derived.ts
3
4
  /**
5
+ * What a form sends of its data `value` (the unwrapped domain data of `def`'s
6
+ * type, normalized) — `<AsForm>`'s submit data and an action's: without the
7
+ * navigation fields the form leaves out ({@link omitSkippedNavFields}) and the
8
+ * fields the server owns ({@link omitDerivedFields}). Since 0.1.208.
9
+ */
10
+ function formPayload(def, value) {
11
+ return omitDerivedFields(def, omitSkippedNavFields(def, value));
12
+ }
13
+ /**
4
14
  * Form data `value` (the unwrapped domain data of `def`'s type) without the
5
15
  * fields the server owns — the root fields `createFormDef` marked `derived`: a
6
16
  * served field `/meta` marks `readOnly`, a writable view's own field, a
@@ -35,4 +45,4 @@ function without(obj, keys, i) {
35
45
  return rest;
36
46
  }
37
47
  //#endregion
38
- export { omitDerivedFields };
48
+ export { formPayload, omitDerivedFields };