@atscript/ui 0.1.206 → 0.1.207

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 (67) hide show
  1. package/dist/form/create-form-def.cjs +3 -6
  2. package/dist/form/create-form-def.mjs +1 -4
  3. package/dist/form/path-utils.cjs +10 -0
  4. package/dist/form/path-utils.d.cts +8 -1
  5. package/dist/form/path-utils.d.mts +8 -1
  6. package/dist/form/path-utils.mjs +10 -1
  7. package/dist/index.cjs +18 -3
  8. package/dist/index.d.cts +8 -5
  9. package/dist/index.d.mts +8 -5
  10. package/dist/index.mjs +11 -8
  11. package/dist/plugin/annotations.cjs +33 -14
  12. package/dist/plugin/annotations.mjs +34 -15
  13. package/dist/plugin/value-help-validation.cjs +26 -6
  14. package/dist/plugin/value-help-validation.mjs +26 -7
  15. package/dist/shared/annotation-keys.cjs +3 -0
  16. package/dist/shared/annotation-keys.mjs +3 -1
  17. package/dist/shared/meta-cache.cjs +5 -4
  18. package/dist/shared/meta-cache.d.cts +3 -2
  19. package/dist/shared/meta-cache.d.mts +3 -2
  20. package/dist/shared/meta-cache.mjs +5 -4
  21. package/dist/shared/value-label.cjs +14 -2
  22. package/dist/shared/value-label.d.cts +23 -6
  23. package/dist/shared/value-label.d.mts +23 -6
  24. package/dist/shared/value-label.mjs +14 -3
  25. package/dist/table/create-table-def.cjs +7 -1
  26. package/dist/table/create-table-def.mjs +7 -2
  27. package/dist/table/types.d.cts +1 -1
  28. package/dist/table/types.d.mts +1 -1
  29. package/dist/value-help/client-store.cjs +43 -0
  30. package/dist/value-help/client-store.d.mts +1 -0
  31. package/dist/value-help/client-store.mjs +40 -0
  32. package/dist/value-help/display-value.cjs +30 -0
  33. package/dist/value-help/display-value.d.cts +45 -0
  34. package/dist/value-help/display-value.d.mts +45 -0
  35. package/dist/value-help/display-value.mjs +30 -0
  36. package/dist/value-help/extract-ref.cjs +15 -4
  37. package/dist/value-help/extract-ref.d.cts +6 -1
  38. package/dist/value-help/extract-ref.d.mts +6 -1
  39. package/dist/value-help/extract-ref.mjs +16 -6
  40. package/dist/value-help/index.d.mts +6 -3
  41. package/dist/value-help/options.cjs +49 -8
  42. package/dist/value-help/options.d.cts +41 -4
  43. package/dist/value-help/options.d.mts +41 -4
  44. package/dist/value-help/options.mjs +47 -9
  45. package/dist/value-help/resolve-options.cjs +9 -7
  46. package/dist/value-help/resolve-options.d.cts +8 -9
  47. package/dist/value-help/resolve-options.d.mts +8 -9
  48. package/dist/value-help/resolve-options.mjs +9 -7
  49. package/dist/value-help/resolve.cjs +39 -8
  50. package/dist/value-help/resolve.d.cts +22 -5
  51. package/dist/value-help/resolve.d.mts +22 -5
  52. package/dist/value-help/resolve.mjs +40 -9
  53. package/dist/value-help/source.cjs +72 -0
  54. package/dist/value-help/source.d.cts +55 -0
  55. package/dist/value-help/source.d.mts +55 -0
  56. package/dist/value-help/source.mjs +71 -0
  57. package/dist/value-help/texts.cjs +315 -0
  58. package/dist/value-help/texts.d.cts +53 -0
  59. package/dist/value-help/texts.d.mts +53 -0
  60. package/dist/value-help/texts.mjs +310 -0
  61. package/dist/value-help/types.d.cts +10 -0
  62. package/dist/value-help/types.d.mts +10 -0
  63. package/dist/value-help/value-help-client.cjs +21 -19
  64. package/dist/value-help/value-help-client.d.cts +9 -5
  65. package/dist/value-help/value-help-client.d.mts +9 -5
  66. package/dist/value-help/value-help-client.mjs +19 -17
  67. package/package.json +10 -10
@@ -3,10 +3,11 @@ let _atscript_db_shared = require("@atscript/db/shared");
3
3
  //#region src/plugin/value-help-validation.ts
4
4
  /**
5
5
  * Editor scopes + validators of `@ui.valueHelp`, `@ui.valueHelp.distinct` and
6
- * `@ui.literalLabel` (since 0.1.148), and of `@ui.valueHelp.fill`,
6
+ * `@ui.literalLabel` (since 0.1.148), of `@ui.valueHelp.fill`,
7
7
  * `@ui.valueHelp.column`, host references in a binding filter and
8
- * `@ui.valueLabel` (since 0.1.190). Scopes and validators share one source,
9
- * so a diagnostic and what the editor completes never diverge.
8
+ * `@ui.valueLabel` (since 0.1.190), and of `@ui.valueHelp.label` (since
9
+ * 0.1.207). Scopes and validators share one source, so a diagnostic and what
10
+ * the editor completes never diverge.
10
11
  */
11
12
  const WARNING = 2;
12
13
  const ERROR = 1;
@@ -601,23 +602,41 @@ function validateFill(token, args, doc) {
601
602
  }
602
603
  return errors;
603
604
  }
604
- function validateColumn(token, args, doc) {
605
+ /**
606
+ * A field of the target of the field's own binding, named by `args[0]` —
607
+ * `@ui.valueHelp.column` (CL1/CL2) and `@ui.valueHelp.label` (LB1/LB2): the
608
+ * binding must be there (`@ui.valueHelp` or `@db.rel.FK`) and hold the field;
609
+ * `check` adds the annotation's own rule.
610
+ */
611
+ function bindingFieldMessages(token, args, doc, annotation, check) {
605
612
  const field = (0, _atscript_db_shared.annotationTarget)(token, doc);
606
613
  if (!field) return [];
607
614
  const binding = bindingOf(field, doc);
608
615
  if (!binding) return [{
609
- message: "@ui.valueHelp.column needs a binding of this field's own (@ui.valueHelp or @db.rel.FK)",
616
+ message: `${annotation} needs a binding of this field's own (@ui.valueHelp or @db.rel.FK)`,
610
617
  severity: ERROR,
611
618
  range: token.range
612
619
  }];
613
620
  const name = args[0]?.text;
614
- const problem = name === void 0 ? void 0 : targetFieldProblem(binding, name);
621
+ if (name === void 0) return [];
622
+ const problem = targetFieldProblem(binding, name) ?? check?.(binding, name);
615
623
  return problem ? [{
616
624
  message: problem,
617
625
  severity: ERROR,
618
626
  range: args[0].range
619
627
  }] : [];
620
628
  }
629
+ function validateColumn(token, args, doc) {
630
+ return bindingFieldMessages(token, args, doc, "@ui.valueHelp.column");
631
+ }
632
+ function validateValueHelpLabel(token, args, doc) {
633
+ return bindingFieldMessages(token, args, doc, "@ui.valueHelp.label", (binding, name) => {
634
+ const target = binding.target;
635
+ const prop = target?.props.get(name);
636
+ const design = prop && target && designOf(prop.getDefinition(), target.doc);
637
+ return design && design !== "string" ? `'${binding.name}.${name}' must be a string field (the text of the codes)` : void 0;
638
+ });
639
+ }
621
640
  function validateDistinct(token, _args, doc) {
622
641
  const errors = [];
623
642
  const host = token.parentNode;
@@ -789,6 +808,7 @@ exports.validateFormType = validateFormType;
789
808
  exports.validateLiteralLabel = validateLiteralLabel;
790
809
  exports.validateOptionalMode = validateOptionalMode;
791
810
  exports.validateValueHelp = validateValueHelp;
811
+ exports.validateValueHelpLabel = validateValueHelpLabel;
792
812
  exports.validateValueLabel = validateValueLabel;
793
813
  exports.valueHelpScopes = valueHelpScopes;
794
814
  exports.valueLabelFields = valueLabelFields;
@@ -3,10 +3,11 @@ import { NOT_DIMENSION_REASON, annotationTarget, effectiveAnnotationNames, fkCha
3
3
  //#region src/plugin/value-help-validation.ts
4
4
  /**
5
5
  * Editor scopes + validators of `@ui.valueHelp`, `@ui.valueHelp.distinct` and
6
- * `@ui.literalLabel` (since 0.1.148), and of `@ui.valueHelp.fill`,
6
+ * `@ui.literalLabel` (since 0.1.148), of `@ui.valueHelp.fill`,
7
7
  * `@ui.valueHelp.column`, host references in a binding filter and
8
- * `@ui.valueLabel` (since 0.1.190). Scopes and validators share one source,
9
- * so a diagnostic and what the editor completes never diverge.
8
+ * `@ui.valueLabel` (since 0.1.190), and of `@ui.valueHelp.label` (since
9
+ * 0.1.207). Scopes and validators share one source, so a diagnostic and what
10
+ * the editor completes never diverge.
10
11
  */
11
12
  const WARNING = 2;
12
13
  const ERROR = 1;
@@ -601,23 +602,41 @@ function validateFill(token, args, doc) {
601
602
  }
602
603
  return errors;
603
604
  }
604
- function validateColumn(token, args, doc) {
605
+ /**
606
+ * A field of the target of the field's own binding, named by `args[0]` —
607
+ * `@ui.valueHelp.column` (CL1/CL2) and `@ui.valueHelp.label` (LB1/LB2): the
608
+ * binding must be there (`@ui.valueHelp` or `@db.rel.FK`) and hold the field;
609
+ * `check` adds the annotation's own rule.
610
+ */
611
+ function bindingFieldMessages(token, args, doc, annotation, check) {
605
612
  const field = annotationTarget(token, doc);
606
613
  if (!field) return [];
607
614
  const binding = bindingOf(field, doc);
608
615
  if (!binding) return [{
609
- message: "@ui.valueHelp.column needs a binding of this field's own (@ui.valueHelp or @db.rel.FK)",
616
+ message: `${annotation} needs a binding of this field's own (@ui.valueHelp or @db.rel.FK)`,
610
617
  severity: ERROR,
611
618
  range: token.range
612
619
  }];
613
620
  const name = args[0]?.text;
614
- const problem = name === void 0 ? void 0 : targetFieldProblem(binding, name);
621
+ if (name === void 0) return [];
622
+ const problem = targetFieldProblem(binding, name) ?? check?.(binding, name);
615
623
  return problem ? [{
616
624
  message: problem,
617
625
  severity: ERROR,
618
626
  range: args[0].range
619
627
  }] : [];
620
628
  }
629
+ function validateColumn(token, args, doc) {
630
+ return bindingFieldMessages(token, args, doc, "@ui.valueHelp.column");
631
+ }
632
+ function validateValueHelpLabel(token, args, doc) {
633
+ return bindingFieldMessages(token, args, doc, "@ui.valueHelp.label", (binding, name) => {
634
+ const target = binding.target;
635
+ const prop = target?.props.get(name);
636
+ const design = prop && target && designOf(prop.getDefinition(), target.doc);
637
+ return design && design !== "string" ? `'${binding.name}.${name}' must be a string field (the text of the codes)` : void 0;
638
+ });
639
+ }
621
640
  function validateDistinct(token, _args, doc) {
622
641
  const errors = [];
623
642
  const host = token.parentNode;
@@ -780,4 +799,4 @@ function validateFormType(token, args, doc) {
780
799
  }];
781
800
  }
782
801
  //#endregion
783
- export { isValueHelpTarget, literalLabelValues, validateColumn, validateDistinct, validateFill, validateFormType, validateLiteralLabel, validateOptionalMode, validateValueHelp, validateValueLabel, valueHelpScopes, valueLabelFields };
802
+ export { isValueHelpTarget, literalLabelValues, validateColumn, validateDistinct, validateFill, validateFormType, validateLiteralLabel, validateOptionalMode, validateValueHelp, validateValueHelpLabel, validateValueLabel, valueHelpScopes, valueLabelFields };
@@ -51,6 +51,8 @@ const UI_VALUE_HELP_DISTINCT = "ui.valueHelp.distinct";
51
51
  const UI_VALUE_HELP_FILL = "ui.valueHelp.fill";
52
52
  /** `@ui.valueHelp.column 'field'` — since 0.1.190. */
53
53
  const UI_VALUE_HELP_COLUMN = "ui.valueHelp.column";
54
+ /** `@ui.valueHelp.label 'field', 'arrangement'?` — since 0.1.207. */
55
+ const UI_VALUE_HELP_LABEL = "ui.valueHelp.label";
54
56
  const UI_LITERAL_LABEL = "ui.literalLabel";
55
57
  /** `@ui.valueLabel 'field', 'arrangement'?` — a code shown with its text; since 0.1.190. */
56
58
  const UI_VALUE_LABEL = "ui.valueLabel";
@@ -208,5 +210,6 @@ exports.UI_VALUE_HELP = UI_VALUE_HELP;
208
210
  exports.UI_VALUE_HELP_COLUMN = UI_VALUE_HELP_COLUMN;
209
211
  exports.UI_VALUE_HELP_DISTINCT = UI_VALUE_HELP_DISTINCT;
210
212
  exports.UI_VALUE_HELP_FILL = UI_VALUE_HELP_FILL;
213
+ exports.UI_VALUE_HELP_LABEL = UI_VALUE_HELP_LABEL;
211
214
  exports.UI_VALUE_LABEL = UI_VALUE_LABEL;
212
215
  exports.WF_ACTION_WITH_DATA = WF_ACTION_WITH_DATA;
@@ -51,6 +51,8 @@ const UI_VALUE_HELP_DISTINCT = "ui.valueHelp.distinct";
51
51
  const UI_VALUE_HELP_FILL = "ui.valueHelp.fill";
52
52
  /** `@ui.valueHelp.column 'field'` — since 0.1.190. */
53
53
  const UI_VALUE_HELP_COLUMN = "ui.valueHelp.column";
54
+ /** `@ui.valueHelp.label 'field', 'arrangement'?` — since 0.1.207. */
55
+ const UI_VALUE_HELP_LABEL = "ui.valueHelp.label";
54
56
  const UI_LITERAL_LABEL = "ui.literalLabel";
55
57
  /** `@ui.valueLabel 'field', 'arrangement'?` — a code shown with its text; since 0.1.190. */
56
58
  const UI_VALUE_LABEL = "ui.valueLabel";
@@ -108,4 +110,4 @@ const UI_TABLE_FN_CLASSES = "ui.table.fn.classes";
108
110
  const UI_TABLE_FN_STYLES = "ui.table.fn.styles";
109
111
  const UI_FORM_VALIDATE = "ui.form.validate";
110
112
  //#endregion
111
- export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_DERIVED, DB_COLUMN_PRECISION, DB_COLUMN_VERSION, DB_COLUMN_VERSION_TOKEN, DB_COMPUTE, DB_COMPUTE_HOST, DB_ENCRYPTED, DB_HTTP_PATH, DB_JSON, DB_REL_FK, DB_TABLE, DB_UNIT, DB_UNIT_REF, DB_VIEW, DB_VIEW_FOR, EXPECT_ARRAY_KEY, EXPECT_ARRAY_UNIQUE_ITEMS, EXPECT_MAX_LENGTH, EXPECT_MESSAGE, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_NS, UI_FORM_OPTIONAL_MODE, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_PUSH_DOWN, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_LITERAL_LABEL, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FILL, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_DISTINCT, UI_VALUE_HELP_FILL, UI_VALUE_LABEL, WF_ACTION_WITH_DATA };
113
+ export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_DERIVED, DB_COLUMN_PRECISION, DB_COLUMN_VERSION, DB_COLUMN_VERSION_TOKEN, DB_COMPUTE, DB_COMPUTE_HOST, DB_ENCRYPTED, DB_HTTP_PATH, DB_JSON, DB_REL_FK, DB_TABLE, DB_UNIT, DB_UNIT_REF, DB_VIEW, DB_VIEW_FOR, EXPECT_ARRAY_KEY, EXPECT_ARRAY_UNIQUE_ITEMS, EXPECT_MAX_LENGTH, EXPECT_MESSAGE, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_NS, UI_FORM_OPTIONAL_MODE, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_PUSH_DOWN, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_LITERAL_LABEL, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FILL, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_DISTINCT, UI_VALUE_HELP_FILL, UI_VALUE_HELP_LABEL, UI_VALUE_LABEL, WF_ACTION_WITH_DATA };
@@ -1,8 +1,8 @@
1
1
  const require_model_texts = require("../i18n/model-texts.cjs");
2
2
  const require_ui_texts = require("../i18n/ui-texts.cjs");
3
3
  const require_create_table_def = require("../table/create-table-def.cjs");
4
- const require_value_help_client = require("../value-help/value-help-client.cjs");
5
4
  const require_client_factory = require("../client-factory.cjs");
5
+ const require_texts = require("../value-help/texts.cjs");
6
6
  let _atscript_db_client = require("@atscript/db-client");
7
7
  //#region src/shared/meta-cache.ts
8
8
  /**
@@ -231,8 +231,9 @@ function customStoreOf(client) {
231
231
  * Drop every cached `/meta` — including the copy each cached `Client`
232
232
  * memoizes and the `@atscript/db-client` meta stores used to revalidate it
233
233
  * (the shared default one and any custom one a factory supplied) — the
234
- * value-help searches shared under them, and everything registered through
235
- * {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
234
+ * value-help searches shared under them, the texts of codes read from the
235
+ * dictionaries and the labels resolved for their bindings, and everything
236
+ * registered through {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
236
237
  * handed out keep working; the next `getMetaEntry` refetches.
237
238
  */
238
239
  function resetMetaCache() {
@@ -243,7 +244,7 @@ function resetMetaCache() {
243
244
  (0, _atscript_db_client.clearMetaStore)();
244
245
  for (const store of customStores.keys()) store.clear();
245
246
  customStores.clear();
246
- require_value_help_client.invalidateValueHelpCache();
247
+ require_texts.resetValueHelpTexts();
247
248
  for (const listener of resetListeners) listener();
248
249
  }
249
250
  /**
@@ -106,8 +106,9 @@ declare function getMetaTableDef(entry: MetaCacheEntry, texts?: Pick<UiTexts, "l
106
106
  * Drop every cached `/meta` — including the copy each cached `Client`
107
107
  * memoizes and the `@atscript/db-client` meta stores used to revalidate it
108
108
  * (the shared default one and any custom one a factory supplied) — the
109
- * value-help searches shared under them, and everything registered through
110
- * {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
109
+ * value-help searches shared under them, the texts of codes read from the
110
+ * dictionaries and the labels resolved for their bindings, and everything
111
+ * registered through {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
111
112
  * handed out keep working; the next `getMetaEntry` refetches.
112
113
  */
113
114
  declare function resetMetaCache(): void;
@@ -106,8 +106,9 @@ declare function getMetaTableDef(entry: MetaCacheEntry, texts?: Pick<UiTexts, "l
106
106
  * Drop every cached `/meta` — including the copy each cached `Client`
107
107
  * memoizes and the `@atscript/db-client` meta stores used to revalidate it
108
108
  * (the shared default one and any custom one a factory supplied) — the
109
- * value-help searches shared under them, and everything registered through
110
- * {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
109
+ * value-help searches shared under them, the texts of codes read from the
110
+ * dictionaries and the labels resolved for their bindings, and everything
111
+ * registered through {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
111
112
  * handed out keep working; the next `getMetaEntry` refetches.
112
113
  */
113
114
  declare function resetMetaCache(): void;
@@ -1,8 +1,8 @@
1
1
  import { deserializeServedType } from "../i18n/model-texts.mjs";
2
2
  import { getUiTexts } from "../i18n/ui-texts.mjs";
3
3
  import { createTableDef } from "../table/create-table-def.mjs";
4
- import { invalidateValueHelpCache } from "../value-help/value-help-client.mjs";
5
4
  import { getDefaultClientFactory } from "../client-factory.mjs";
5
+ import { resetValueHelpTexts } from "../value-help/texts.mjs";
6
6
  import { clearMetaStore, defaultMetaStore } from "@atscript/db-client";
7
7
  //#region src/shared/meta-cache.ts
8
8
  /**
@@ -231,8 +231,9 @@ function customStoreOf(client) {
231
231
  * Drop every cached `/meta` — including the copy each cached `Client`
232
232
  * memoizes and the `@atscript/db-client` meta stores used to revalidate it
233
233
  * (the shared default one and any custom one a factory supplied) — the
234
- * value-help searches shared under them, and everything registered through
235
- * {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
234
+ * value-help searches shared under them, the texts of codes read from the
235
+ * dictionaries and the labels resolved for their bindings, and everything
236
+ * registered through {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
236
237
  * handed out keep working; the next `getMetaEntry` refetches.
237
238
  */
238
239
  function resetMetaCache() {
@@ -243,7 +244,7 @@ function resetMetaCache() {
243
244
  clearMetaStore();
244
245
  for (const store of customStores.keys()) store.clear();
245
246
  customStores.clear();
246
- invalidateValueHelpCache();
247
+ resetValueHelpTexts();
247
248
  for (const listener of resetListeners) listener();
248
249
  }
249
250
  /**
@@ -11,18 +11,30 @@ function valueLabelOf(prop) {
11
11
  };
12
12
  }
13
13
  /**
14
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
14
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
15
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
15
16
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
16
17
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
17
18
  * key; an empty key yields `""` — a text without a code labels nothing.
18
19
  */
19
20
  function arrangeText(key, text, arrangement = "textKey") {
20
21
  if (key === "") return "";
21
- const label = typeof text === "string" ? text : typeof text === "number" ? String(text) : void 0;
22
+ const label = codeOf(text);
22
23
  if (!label) return key;
23
24
  if (arrangement === "text") return label;
24
25
  return arrangement === "keyText" ? `${key} (${label})` : `${label} (${key})`;
25
26
  }
27
+ /**
28
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
29
+ * written out; `undefined` for anything else. Only a code shows with a text
30
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
31
+ * (`valueHelpText`).
32
+ */
33
+ function codeOf(value) {
34
+ if (typeof value === "string") return value === "" ? void 0 : value;
35
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
36
+ }
26
37
  //#endregion
27
38
  exports.arrangeText = arrangeText;
39
+ exports.codeOf = codeOf;
28
40
  exports.valueLabelOf = valueLabelOf;
@@ -2,24 +2,41 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
2
 
3
3
  //#region src/shared/value-label.d.ts
4
4
  /**
5
- * How `@ui.valueLabel` shows a code with its text (since 0.1.190):
6
- * `textKey` — `Berlin (BER)`, `keyText` — `BER (Berlin)`, `text` — `Berlin`.
5
+ * How a code shows with its text (since 0.1.190): `textKey` — `Berlin (BER)`,
6
+ * `keyText` — `BER (Berlin)`, `text` — `Berlin`.
7
7
  */
8
8
  type ValueLabelArrangement = "textKey" | "keyText" | "text";
9
- /** `@ui.valueLabel` of a field: the sibling holding the text, and the arrangement. Since 0.1.190. */
9
+ /**
10
+ * Where a code's text is, and how it shows: `@ui.valueLabel` of a field (the
11
+ * sibling holding the text, since 0.1.190), or the label of a dictionary
12
+ * (`ResolvedValueHelp.label`: a field of the dictionary, since 0.1.207).
13
+ */
10
14
  interface ValueLabel {
11
- /** The sibling field holding the text (a name, relative to the field's parent). */
15
+ /** The field holding the text: a sibling's name, or a field of the dictionary. */
12
16
  field: string;
13
17
  arrangement: ValueLabelArrangement;
14
18
  }
19
+ /** A code's text and the arrangement it shows in — what `arrangeText` renders. Since 0.1.207. */
20
+ interface ValueText {
21
+ text: string;
22
+ arrangement: ValueLabelArrangement;
23
+ }
15
24
  /** The field's `@ui.valueLabel`, the arrangement defaulted to `textKey`; `undefined` without one. */
16
25
  declare function valueLabelOf(prop: TAtscriptAnnotatedType): ValueLabel | undefined;
17
26
  /**
18
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
27
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
28
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
19
29
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
20
30
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
21
31
  * key; an empty key yields `""` — a text without a code labels nothing.
22
32
  */
23
33
  declare function arrangeText(key: string, text: unknown, arrangement?: ValueLabelArrangement): string;
34
+ /**
35
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
36
+ * written out; `undefined` for anything else. Only a code shows with a text
37
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
38
+ * (`valueHelpText`).
39
+ */
40
+ declare function codeOf(value: unknown): string | undefined;
24
41
  //#endregion
25
- export { ValueLabel, ValueLabelArrangement, arrangeText, valueLabelOf };
42
+ export { ValueLabel, ValueLabelArrangement, ValueText, arrangeText, codeOf, valueLabelOf };
@@ -2,24 +2,41 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
2
 
3
3
  //#region src/shared/value-label.d.ts
4
4
  /**
5
- * How `@ui.valueLabel` shows a code with its text (since 0.1.190):
6
- * `textKey` — `Berlin (BER)`, `keyText` — `BER (Berlin)`, `text` — `Berlin`.
5
+ * How a code shows with its text (since 0.1.190): `textKey` — `Berlin (BER)`,
6
+ * `keyText` — `BER (Berlin)`, `text` — `Berlin`.
7
7
  */
8
8
  type ValueLabelArrangement = "textKey" | "keyText" | "text";
9
- /** `@ui.valueLabel` of a field: the sibling holding the text, and the arrangement. Since 0.1.190. */
9
+ /**
10
+ * Where a code's text is, and how it shows: `@ui.valueLabel` of a field (the
11
+ * sibling holding the text, since 0.1.190), or the label of a dictionary
12
+ * (`ResolvedValueHelp.label`: a field of the dictionary, since 0.1.207).
13
+ */
10
14
  interface ValueLabel {
11
- /** The sibling field holding the text (a name, relative to the field's parent). */
15
+ /** The field holding the text: a sibling's name, or a field of the dictionary. */
12
16
  field: string;
13
17
  arrangement: ValueLabelArrangement;
14
18
  }
19
+ /** A code's text and the arrangement it shows in — what `arrangeText` renders. Since 0.1.207. */
20
+ interface ValueText {
21
+ text: string;
22
+ arrangement: ValueLabelArrangement;
23
+ }
15
24
  /** The field's `@ui.valueLabel`, the arrangement defaulted to `textKey`; `undefined` without one. */
16
25
  declare function valueLabelOf(prop: TAtscriptAnnotatedType): ValueLabel | undefined;
17
26
  /**
18
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
27
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
28
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
19
29
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
20
30
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
21
31
  * key; an empty key yields `""` — a text without a code labels nothing.
22
32
  */
23
33
  declare function arrangeText(key: string, text: unknown, arrangement?: ValueLabelArrangement): string;
34
+ /**
35
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
36
+ * written out; `undefined` for anything else. Only a code shows with a text
37
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
38
+ * (`valueHelpText`).
39
+ */
40
+ declare function codeOf(value: unknown): string | undefined;
24
41
  //#endregion
25
- export { ValueLabel, ValueLabelArrangement, arrangeText, valueLabelOf };
42
+ export { ValueLabel, ValueLabelArrangement, ValueText, arrangeText, codeOf, valueLabelOf };
@@ -11,17 +11,28 @@ function valueLabelOf(prop) {
11
11
  };
12
12
  }
13
13
  /**
14
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
14
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
15
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
15
16
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
16
17
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
17
18
  * key; an empty key yields `""` — a text without a code labels nothing.
18
19
  */
19
20
  function arrangeText(key, text, arrangement = "textKey") {
20
21
  if (key === "") return "";
21
- const label = typeof text === "string" ? text : typeof text === "number" ? String(text) : void 0;
22
+ const label = codeOf(text);
22
23
  if (!label) return key;
23
24
  if (arrangement === "text") return label;
24
25
  return arrangement === "keyText" ? `${key} (${label})` : `${label} (${key})`;
25
26
  }
27
+ /**
28
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
29
+ * written out; `undefined` for anything else. Only a code shows with a text
30
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
31
+ * (`valueHelpText`).
32
+ */
33
+ function codeOf(value) {
34
+ if (typeof value === "string") return value === "" ? void 0 : value;
35
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
36
+ }
26
37
  //#endregion
27
- export { arrangeText, valueLabelOf };
38
+ export { arrangeText, codeOf, valueLabelOf };
@@ -129,7 +129,12 @@ function identifierFieldsOf(preferredId, actions) {
129
129
  }
130
130
  return out ?? preferredId;
131
131
  }
132
- /** A field the caller may read: listed in `meta.fields` and not write-only. */
132
+ /**
133
+ * A field the caller may read: listed in `meta.fields` and not write-only —
134
+ * the one rule for a table's columns and a dictionary's label.
135
+ *
136
+ * @internal Shared with the value help.
137
+ */
133
138
  function isReadable(field) {
134
139
  return field !== void 0 && field.writeOnly !== true;
135
140
  }
@@ -248,3 +253,4 @@ function inferValueKind(prop) {
248
253
  //#endregion
249
254
  exports.createTableDef = createTableDef;
250
255
  exports.inferValueKind = inferValueKind;
256
+ exports.isReadable = isReadable;
@@ -129,7 +129,12 @@ function identifierFieldsOf(preferredId, actions) {
129
129
  }
130
130
  return out ?? preferredId;
131
131
  }
132
- /** A field the caller may read: listed in `meta.fields` and not write-only. */
132
+ /**
133
+ * A field the caller may read: listed in `meta.fields` and not write-only —
134
+ * the one rule for a table's columns and a dictionary's label.
135
+ *
136
+ * @internal Shared with the value help.
137
+ */
133
138
  function isReadable(field) {
134
139
  return field !== void 0 && field.writeOnly !== true;
135
140
  }
@@ -246,4 +251,4 @@ function inferValueKind(prop) {
246
251
  return [...kinds][0];
247
252
  }
248
253
  //#endregion
249
- export { createTableDef, inferValueKind };
254
+ export { createTableDef, inferValueKind, isReadable };
@@ -1,5 +1,5 @@
1
- import { ValueHelpInfo } from "../value-help/types.cjs";
2
1
  import { ValueLabelArrangement } from "../shared/value-label.cjs";
2
+ import { ValueHelpInfo } from "../value-help/types.cjs";
3
3
  import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
4
  import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
5
5
 
@@ -1,5 +1,5 @@
1
- import { ValueHelpInfo } from "../value-help/types.mjs";
2
1
  import { ValueLabelArrangement } from "../shared/value-label.mjs";
2
+ import { ValueHelpInfo } from "../value-help/types.mjs";
3
3
  import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
4
  import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
5
5
 
@@ -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 };