@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.
- package/dist/form/create-form-def.cjs +16 -18
- package/dist/form/create-form-def.mjs +15 -17
- package/dist/form/decimal-format.cjs +8 -3
- package/dist/form/decimal-format.d.cts +8 -2
- package/dist/form/decimal-format.d.mts +8 -2
- package/dist/form/decimal-format.mjs +8 -3
- package/dist/form/form-actions.cjs +9 -0
- package/dist/form/form-actions.d.cts +7 -1
- package/dist/form/form-actions.d.mts +7 -1
- package/dist/form/form-actions.mjs +9 -1
- package/dist/form/measurement.cjs +58 -0
- package/dist/form/measurement.d.cts +36 -1
- package/dist/form/measurement.d.mts +36 -1
- package/dist/form/measurement.mjs +57 -2
- package/dist/form/omit-derived.cjs +11 -0
- package/dist/form/omit-derived.d.cts +8 -1
- package/dist/form/omit-derived.d.mts +8 -1
- package/dist/form/omit-derived.mjs +11 -1
- package/dist/form/optional-mode.cjs +7 -7
- package/dist/form/optional-mode.d.cts +2 -1
- package/dist/form/optional-mode.d.mts +2 -1
- package/dist/form/optional-mode.mjs +8 -8
- package/dist/form/path-utils.cjs +10 -0
- package/dist/form/path-utils.d.cts +8 -1
- package/dist/form/path-utils.d.mts +8 -1
- package/dist/form/path-utils.mjs +10 -1
- package/dist/form/types.cjs +5 -0
- package/dist/form/types.d.cts +14 -0
- package/dist/form/types.d.mts +14 -0
- package/dist/form/types.mjs +5 -1
- package/dist/form/validate.cjs +56 -5
- package/dist/form/validate.d.cts +30 -2
- package/dist/form/validate.d.mts +30 -2
- package/dist/form/validate.mjs +56 -6
- package/dist/index.cjs +42 -6
- package/dist/index.d.cts +20 -12
- package/dist/index.d.mts +20 -12
- package/dist/index.mjs +23 -15
- package/dist/plugin/annotations.cjs +33 -14
- package/dist/plugin/annotations.mjs +34 -15
- package/dist/plugin/value-help-validation.cjs +26 -6
- package/dist/plugin/value-help-validation.mjs +26 -7
- package/dist/shared/annotation-keys.cjs +3 -0
- package/dist/shared/annotation-keys.d.cts +2 -1
- package/dist/shared/annotation-keys.d.mts +2 -1
- package/dist/shared/annotation-keys.mjs +3 -1
- package/dist/shared/dev.cjs +22 -0
- package/dist/shared/dev.d.cts +4 -0
- package/dist/shared/dev.d.mts +4 -0
- package/dist/shared/dev.mjs +22 -0
- package/dist/shared/field-resolver.cjs +21 -1
- package/dist/shared/field-resolver.d.cts +15 -1
- package/dist/shared/field-resolver.d.mts +15 -1
- package/dist/shared/field-resolver.mjs +20 -2
- package/dist/shared/merge-filters.cjs +28 -0
- package/dist/shared/merge-filters.d.cts +13 -0
- package/dist/shared/merge-filters.d.mts +13 -0
- package/dist/shared/merge-filters.mjs +28 -0
- package/dist/shared/meta-cache.cjs +5 -4
- package/dist/shared/meta-cache.d.cts +3 -2
- package/dist/shared/meta-cache.d.mts +3 -2
- package/dist/shared/meta-cache.mjs +5 -4
- package/dist/shared/resolve-component.cjs +27 -0
- package/dist/shared/resolve-component.d.cts +22 -0
- package/dist/shared/resolve-component.d.mts +22 -0
- package/dist/shared/resolve-component.mjs +27 -0
- package/dist/shared/stable-key.cjs +28 -0
- package/dist/shared/stable-key.d.cts +13 -0
- package/dist/shared/stable-key.d.mts +13 -0
- package/dist/shared/stable-key.mjs +28 -0
- package/dist/shared/to-date.cjs +65 -0
- package/dist/shared/to-date.d.cts +35 -0
- package/dist/shared/to-date.d.mts +35 -0
- package/dist/shared/to-date.mjs +64 -0
- package/dist/shared/value-label.cjs +14 -2
- package/dist/shared/value-label.d.cts +23 -6
- package/dist/shared/value-label.d.mts +23 -6
- package/dist/shared/value-label.mjs +14 -3
- package/dist/table/create-table-def.cjs +53 -13
- package/dist/table/create-table-def.mjs +53 -15
- package/dist/table/types.d.cts +15 -13
- package/dist/table/types.d.mts +15 -13
- package/dist/value-help/client-store.cjs +43 -0
- package/dist/value-help/client-store.d.mts +1 -0
- package/dist/value-help/client-store.mjs +40 -0
- package/dist/value-help/display-value.cjs +30 -0
- package/dist/value-help/display-value.d.cts +45 -0
- package/dist/value-help/display-value.d.mts +45 -0
- package/dist/value-help/display-value.mjs +30 -0
- package/dist/value-help/distinct-client.cjs +80 -7
- package/dist/value-help/distinct-client.d.cts +31 -36
- package/dist/value-help/distinct-client.d.mts +31 -36
- package/dist/value-help/distinct-client.mjs +80 -7
- package/dist/value-help/extract-ref.cjs +15 -4
- package/dist/value-help/extract-ref.d.cts +6 -1
- package/dist/value-help/extract-ref.d.mts +6 -1
- package/dist/value-help/extract-ref.mjs +16 -6
- package/dist/value-help/index.d.mts +6 -3
- package/dist/value-help/options.cjs +70 -8
- package/dist/value-help/options.d.cts +57 -4
- package/dist/value-help/options.d.mts +57 -4
- package/dist/value-help/options.mjs +67 -9
- package/dist/value-help/resolve-options.cjs +9 -7
- package/dist/value-help/resolve-options.d.cts +8 -9
- package/dist/value-help/resolve-options.d.mts +8 -9
- package/dist/value-help/resolve-options.mjs +9 -7
- package/dist/value-help/resolve.cjs +29 -8
- package/dist/value-help/resolve.d.cts +22 -5
- package/dist/value-help/resolve.d.mts +22 -5
- package/dist/value-help/resolve.mjs +29 -8
- package/dist/value-help/scope.cjs +3 -7
- package/dist/value-help/scope.mjs +3 -7
- package/dist/value-help/source.cjs +72 -0
- package/dist/value-help/source.d.cts +55 -0
- package/dist/value-help/source.d.mts +55 -0
- package/dist/value-help/source.mjs +71 -0
- package/dist/value-help/texts.cjs +318 -0
- package/dist/value-help/texts.d.cts +53 -0
- package/dist/value-help/texts.d.mts +53 -0
- package/dist/value-help/texts.mjs +313 -0
- package/dist/value-help/types.d.cts +10 -0
- package/dist/value-help/types.d.mts +10 -0
- package/dist/value-help/value-help-client.cjs +24 -20
- package/dist/value-help/value-help-client.d.cts +10 -5
- package/dist/value-help/value-help-client.d.mts +10 -5
- package/dist/value-help/value-help-client.mjs +22 -18
- package/package.json +10 -10
|
@@ -1,11 +1,14 @@
|
|
|
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");
|
|
5
6
|
const require_extract_literals = require("../value-help/extract-literals.cjs");
|
|
6
7
|
const require_extract_ref = require("../value-help/extract-ref.cjs");
|
|
7
8
|
const require_db_column = require("./db-column.cjs");
|
|
9
|
+
const require_path_utils = require("./path-utils.cjs");
|
|
8
10
|
const require_skipped_nav = require("./skipped-nav.cjs");
|
|
11
|
+
const require_measurement = require("./measurement.cjs");
|
|
9
12
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
10
13
|
let _atscript_db_meta = require("@atscript/db/meta");
|
|
11
14
|
let _atscript_db_validator = require("@atscript/db/validator");
|
|
@@ -111,7 +114,8 @@ function buildFormDef(type, write, root) {
|
|
|
111
114
|
phantom: false,
|
|
112
115
|
name: "",
|
|
113
116
|
allStatic: false,
|
|
114
|
-
pushDown: false
|
|
117
|
+
pushDown: false,
|
|
118
|
+
component: require_field_resolver.getFieldMeta(type, require_annotation_keys.UI_FORM_COMPONENT)
|
|
115
119
|
};
|
|
116
120
|
const def = {
|
|
117
121
|
type,
|
|
@@ -186,7 +190,7 @@ function markServerOwned(fields, type, metaFields) {
|
|
|
186
190
|
if (own.size === 0 && !metaFields) return;
|
|
187
191
|
const filled = /* @__PURE__ */ new Set();
|
|
188
192
|
for (const { field } of fields) {
|
|
189
|
-
const parent = parentPrefix(field.path);
|
|
193
|
+
const parent = require_path_utils.parentPrefix(field.path);
|
|
190
194
|
for (const f of field.valueHelpInfo?.fill ?? []) filled.add(parent + f.local);
|
|
191
195
|
}
|
|
192
196
|
for (const c of fields) {
|
|
@@ -224,10 +228,6 @@ function servedReadOnly(metaFields, path) {
|
|
|
224
228
|
function writtenByForm(field, filled) {
|
|
225
229
|
return filled.has(field.path) || require_field_resolver.getFieldMeta(field.prop, "ui.form.fn.value") !== void 0 || require_field_resolver.getFieldMeta(field.prop, "ui.form.fn.readonly") !== void 0;
|
|
226
230
|
}
|
|
227
|
-
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
228
|
-
function parentPrefix(path) {
|
|
229
|
-
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
230
|
-
}
|
|
231
231
|
/**
|
|
232
232
|
* Scopes a binding's sibling names to the def (since 0.1.190). Host references
|
|
233
233
|
* (`hostFilter`) and fills (`@ui.valueHelp.fill`) name fields of the interface
|
|
@@ -244,7 +244,7 @@ function keepWritableFills(fields) {
|
|
|
244
244
|
for (const { field } of fields) {
|
|
245
245
|
const info = field.valueHelpInfo;
|
|
246
246
|
if (!info?.fill && !info?.hostFilter) continue;
|
|
247
|
-
const parent = parentPrefix(field.path);
|
|
247
|
+
const parent = require_path_utils.parentPrefix(field.path);
|
|
248
248
|
const hostFilter = parent && info.hostFilter ? info.hostFilter.map((h) => ({
|
|
249
249
|
...h,
|
|
250
250
|
local: parent + h.local
|
|
@@ -313,6 +313,7 @@ function buildFieldDef(path, typeProp, write) {
|
|
|
313
313
|
allStatic,
|
|
314
314
|
pushDown,
|
|
315
315
|
valueHelpInfo,
|
|
316
|
+
component: require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_FORM_COMPONENT),
|
|
316
317
|
...derived && { derived: true }
|
|
317
318
|
};
|
|
318
319
|
const customType = uiType;
|
|
@@ -321,12 +322,15 @@ function buildFieldDef(path, typeProp, write) {
|
|
|
321
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);
|
|
322
323
|
const isTags = customType === "tags" || customType === "multiselect" && !hasOptions;
|
|
323
324
|
const isMultiselect = customType === "multiselect" || hasOptions;
|
|
325
|
+
const item = arrayType.of.type;
|
|
324
326
|
return {
|
|
325
327
|
...base,
|
|
326
328
|
type: "array",
|
|
327
329
|
customType: isTags ? "tags" : isMultiselect ? "multiselect" : customType,
|
|
328
330
|
itemType: arrayType.of,
|
|
329
|
-
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"
|
|
330
334
|
};
|
|
331
335
|
}
|
|
332
336
|
if (kind === "object") return {
|
|
@@ -386,16 +390,9 @@ function buildFieldDef(path, typeProp, write) {
|
|
|
386
390
|
const dt = kind === "" ? prop.type.designType : void 0;
|
|
387
391
|
let numericType;
|
|
388
392
|
if (kind === "") {
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
if (
|
|
392
|
-
else if (isDecimalDesign) numericType = "decimal";
|
|
393
|
-
else if (dt === "number") {
|
|
394
|
-
const hasUnit = require_field_resolver.getFieldMeta(prop, "db.unit") !== void 0 || require_field_resolver.getFieldMeta(prop, "db.unit.ref") !== void 0;
|
|
395
|
-
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;
|
|
396
|
-
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;
|
|
397
|
-
if (hasUnit || hasPrefix || hasSuffix) numericType = "number";
|
|
398
|
-
}
|
|
393
|
+
const adornment = require_measurement.numberAdornment(prop);
|
|
394
|
+
if (adornment === "currency" || dt === "decimal") numericType = "decimal";
|
|
395
|
+
else if (adornment && dt === "number") numericType = "number";
|
|
399
396
|
}
|
|
400
397
|
const tagType = isTimestamp ? "datetime" : void 0;
|
|
401
398
|
return {
|
|
@@ -495,6 +492,7 @@ function createUnionVariants(typeDef, write) {
|
|
|
495
492
|
for (const item of items) {
|
|
496
493
|
const v = createVariant(item, write);
|
|
497
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;
|
|
498
496
|
if (items.length > 1) v.label = `${String(variants.length + 1)}. ${v.label}`;
|
|
499
497
|
variants.push(v);
|
|
500
498
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
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";
|
|
5
6
|
import { isPureLiteralUnion } from "../value-help/extract-literals.mjs";
|
|
6
7
|
import { extractValueHelp, isValueHelpPicker } from "../value-help/extract-ref.mjs";
|
|
7
8
|
import { columnHas, isDbDefaulted, soleValueMember } from "./db-column.mjs";
|
|
9
|
+
import { parentPrefix } from "./path-utils.mjs";
|
|
8
10
|
import { isSkippedNavField } from "./skipped-nav.mjs";
|
|
11
|
+
import { numberAdornment } from "./measurement.mjs";
|
|
9
12
|
import { flattenAnnotatedType } from "@atscript/typescript/utils";
|
|
10
13
|
import { writableViewReadOnlyFields } from "@atscript/db/meta";
|
|
11
14
|
import { isNavRelation, isServerStampedOnUpdate } from "@atscript/db/validator";
|
|
@@ -111,7 +114,8 @@ function buildFormDef(type, write, root) {
|
|
|
111
114
|
phantom: false,
|
|
112
115
|
name: "",
|
|
113
116
|
allStatic: false,
|
|
114
|
-
pushDown: false
|
|
117
|
+
pushDown: false,
|
|
118
|
+
component: getFieldMeta(type, UI_FORM_COMPONENT)
|
|
115
119
|
};
|
|
116
120
|
const def = {
|
|
117
121
|
type,
|
|
@@ -224,10 +228,6 @@ function servedReadOnly(metaFields, path) {
|
|
|
224
228
|
function writtenByForm(field, filled) {
|
|
225
229
|
return filled.has(field.path) || getFieldMeta(field.prop, "ui.form.fn.value") !== void 0 || getFieldMeta(field.prop, "ui.form.fn.readonly") !== void 0;
|
|
226
230
|
}
|
|
227
|
-
/** The path of the object holding `path`, with its trailing dot — `""` at the top. */
|
|
228
|
-
function parentPrefix(path) {
|
|
229
|
-
return path.slice(0, path.lastIndexOf(".") + 1);
|
|
230
|
-
}
|
|
231
231
|
/**
|
|
232
232
|
* Scopes a binding's sibling names to the def (since 0.1.190). Host references
|
|
233
233
|
* (`hostFilter`) and fills (`@ui.valueHelp.fill`) name fields of the interface
|
|
@@ -313,6 +313,7 @@ function buildFieldDef(path, typeProp, write) {
|
|
|
313
313
|
allStatic,
|
|
314
314
|
pushDown,
|
|
315
315
|
valueHelpInfo,
|
|
316
|
+
component: getFieldMeta(prop, UI_FORM_COMPONENT),
|
|
316
317
|
...derived && { derived: true }
|
|
317
318
|
};
|
|
318
319
|
const customType = uiType;
|
|
@@ -321,12 +322,15 @@ function buildFieldDef(path, typeProp, write) {
|
|
|
321
322
|
const hasOptions = getFieldMeta(prop, "ui.form.options") !== void 0 || getFieldMeta(prop, "ui.form.fn.options") !== void 0 || isPureLiteralUnion(arrayType.of);
|
|
322
323
|
const isTags = customType === "tags" || customType === "multiselect" && !hasOptions;
|
|
323
324
|
const isMultiselect = customType === "multiselect" || hasOptions;
|
|
325
|
+
const item = arrayType.of.type;
|
|
324
326
|
return {
|
|
325
327
|
...base,
|
|
326
328
|
type: "array",
|
|
327
329
|
customType: isTags ? "tags" : isMultiselect ? "multiselect" : customType,
|
|
328
330
|
itemType: arrayType.of,
|
|
329
|
-
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"
|
|
330
334
|
};
|
|
331
335
|
}
|
|
332
336
|
if (kind === "object") return {
|
|
@@ -386,16 +390,9 @@ function buildFieldDef(path, typeProp, write) {
|
|
|
386
390
|
const dt = kind === "" ? prop.type.designType : void 0;
|
|
387
391
|
let numericType;
|
|
388
392
|
if (kind === "") {
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
if (
|
|
392
|
-
else if (isDecimalDesign) numericType = "decimal";
|
|
393
|
-
else if (dt === "number") {
|
|
394
|
-
const hasUnit = getFieldMeta(prop, "db.unit") !== void 0 || getFieldMeta(prop, "db.unit.ref") !== void 0;
|
|
395
|
-
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;
|
|
396
|
-
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;
|
|
397
|
-
if (hasUnit || hasPrefix || hasSuffix) numericType = "number";
|
|
398
|
-
}
|
|
393
|
+
const adornment = numberAdornment(prop);
|
|
394
|
+
if (adornment === "currency" || dt === "decimal") numericType = "decimal";
|
|
395
|
+
else if (adornment && dt === "number") numericType = "number";
|
|
399
396
|
}
|
|
400
397
|
const tagType = isTimestamp ? "datetime" : void 0;
|
|
401
398
|
return {
|
|
@@ -495,6 +492,7 @@ function createUnionVariants(typeDef, write) {
|
|
|
495
492
|
for (const item of items) {
|
|
496
493
|
const v = createVariant(item, write);
|
|
497
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;
|
|
498
496
|
if (items.length > 1) v.label = `${String(variants.length + 1)}. ${v.label}`;
|
|
499
497
|
variants.push(v);
|
|
500
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 =
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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 =
|
|
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 };
|