@atscript/ui 0.1.168 → 0.1.170

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/form/create-form-def.cjs +8 -2
  2. package/dist/form/create-form-def.mjs +8 -2
  3. package/dist/form/labels.cjs +4 -4
  4. package/dist/form/labels.d.cts +3 -2
  5. package/dist/form/labels.d.mts +3 -2
  6. package/dist/form/labels.mjs +4 -4
  7. package/dist/form/types.d.cts +12 -0
  8. package/dist/form/types.d.mts +12 -0
  9. package/dist/form/validate.cjs +18 -4
  10. package/dist/form/validate.d.cts +11 -1
  11. package/dist/form/validate.d.mts +11 -1
  12. package/dist/form/validate.mjs +18 -5
  13. package/dist/i18n/model-texts.cjs +50 -0
  14. package/dist/i18n/model-texts.d.cts +42 -0
  15. package/dist/i18n/model-texts.d.mts +42 -0
  16. package/dist/i18n/model-texts.mjs +46 -0
  17. package/dist/i18n/ui-texts.d.cts +5 -1
  18. package/dist/i18n/ui-texts.d.mts +5 -1
  19. package/dist/index.cjs +7 -0
  20. package/dist/index.d.cts +3 -2
  21. package/dist/index.d.mts +3 -2
  22. package/dist/index.mjs +3 -2
  23. package/dist/nav/model-routes.cjs +9 -3
  24. package/dist/nav/model-routes.d.cts +8 -1
  25. package/dist/nav/model-routes.d.mts +8 -1
  26. package/dist/nav/model-routes.mjs +9 -3
  27. package/dist/shared/field-resolver.cjs +3 -2
  28. package/dist/shared/field-resolver.d.cts +6 -0
  29. package/dist/shared/field-resolver.d.mts +6 -0
  30. package/dist/shared/field-resolver.mjs +3 -2
  31. package/dist/shared/meta-cache.cjs +3 -3
  32. package/dist/shared/meta-cache.d.cts +1 -1
  33. package/dist/shared/meta-cache.d.mts +1 -1
  34. package/dist/shared/meta-cache.mjs +3 -3
  35. package/dist/table/create-table-def.cjs +2 -1
  36. package/dist/table/create-table-def.mjs +2 -1
  37. package/dist/value-help/extract-literals.cjs +8 -5
  38. package/dist/value-help/extract-literals.d.cts +5 -2
  39. package/dist/value-help/extract-literals.d.mts +5 -2
  40. package/dist/value-help/extract-literals.mjs +8 -5
  41. package/dist/value-help/resolve-options.cjs +17 -8
  42. package/dist/value-help/resolve-options.d.cts +7 -3
  43. package/dist/value-help/resolve-options.d.mts +7 -3
  44. package/dist/value-help/resolve-options.mjs +17 -8
  45. package/package.json +10 -10
@@ -1,4 +1,5 @@
1
1
  import { TFormEntryOptions } from "./types.cjs";
2
+ import { UserTextT } from "../i18n/model-texts.cjs";
2
3
  import { UiT } from "../i18n/ui-texts.cjs";
3
4
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
5
 
@@ -21,9 +22,10 @@ declare function optionLabel(column: {
21
22
  }[];
22
23
  }, value: unknown): string | undefined;
23
24
  /**
24
- * Converts raw option annotation value to a normalized array.
25
+ * Converts raw option annotation value to a normalized array. `t` translates
26
+ * the labels (never the keys: an option without a value is its own key).
25
27
  */
26
- declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
28
+ declare function parseStaticOptions(raw: unknown, t?: UserTextT): TFormEntryOptions[];
27
29
  /**
28
30
  * Resolves options from metadata with a fallback chain:
29
31
  * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
@@ -34,7 +36,9 @@ declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
34
36
  *
35
37
  * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
36
38
  * texts when omitted — a component passes its app's (`useAsLocale().t`).
39
+ * `text` translates the labels the model declares (`@ui.form.options`,
40
+ * `@ui.literalLabel`); a computed option list is the fn's own to translate.
37
41
  */
38
- declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>, labelsFrom?: TAtscriptAnnotatedType, t?: UiT): TFormEntryOptions[] | undefined;
42
+ declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>, labelsFrom?: TAtscriptAnnotatedType, t?: UiT, text?: UserTextT): TFormEntryOptions[] | undefined;
39
43
  //#endregion
40
44
  export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -1,4 +1,5 @@
1
1
  import { TFormEntryOptions } from "./types.mjs";
2
+ import { UserTextT } from "../i18n/model-texts.mjs";
2
3
  import { UiT } from "../i18n/ui-texts.mjs";
3
4
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
5
 
@@ -21,9 +22,10 @@ declare function optionLabel(column: {
21
22
  }[];
22
23
  }, value: unknown): string | undefined;
23
24
  /**
24
- * Converts raw option annotation value to a normalized array.
25
+ * Converts raw option annotation value to a normalized array. `t` translates
26
+ * the labels (never the keys: an option without a value is its own key).
25
27
  */
26
- declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
28
+ declare function parseStaticOptions(raw: unknown, t?: UserTextT): TFormEntryOptions[];
27
29
  /**
28
30
  * Resolves options from metadata with a fallback chain:
29
31
  * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
@@ -34,7 +36,9 @@ declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
34
36
  *
35
37
  * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
36
38
  * texts when omitted — a component passes its app's (`useAsLocale().t`).
39
+ * `text` translates the labels the model declares (`@ui.form.options`,
40
+ * `@ui.literalLabel`); a computed option list is the fn's own to translate.
37
41
  */
38
- declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>, labelsFrom?: TAtscriptAnnotatedType, t?: UiT): TFormEntryOptions[] | undefined;
42
+ declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>, labelsFrom?: TAtscriptAnnotatedType, t?: UiT, text?: UserTextT): TFormEntryOptions[] | undefined;
39
43
  //#endregion
40
44
  export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -1,4 +1,5 @@
1
1
  import { UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS } from "../shared/annotation-keys.mjs";
2
+ import { userText } from "../i18n/model-texts.mjs";
2
3
  import { asArray, resolveFieldProp } from "../shared/field-resolver.mjs";
3
4
  import { extractFieldLiteralOptions, extractLiteralOptions } from "./extract-literals.mjs";
4
5
  //#region src/value-help/resolve-options.ts
@@ -30,16 +31,22 @@ function optionLabel(column, value) {
30
31
  return labels.get(String(value));
31
32
  }
32
33
  /**
33
- * Converts raw option annotation value to a normalized array.
34
+ * Converts raw option annotation value to a normalized array. `t` translates
35
+ * the labels (never the keys: an option without a value is its own key).
34
36
  */
35
- function parseStaticOptions(raw) {
37
+ function parseStaticOptions(raw, t) {
36
38
  return asArray(raw).map((item) => {
37
39
  if (typeof item === "object" && item !== null && "label" in item) {
38
40
  const { label, value } = item;
39
- return value !== void 0 ? {
41
+ const shown = userText(UI_FORM_OPTIONS, { label }, t).label;
42
+ if (value !== void 0) return {
40
43
  key: value,
41
- label
42
- } : label;
44
+ label: shown
45
+ };
46
+ return shown === label ? label : {
47
+ key: label,
48
+ label: shown
49
+ };
43
50
  }
44
51
  return String(item);
45
52
  });
@@ -54,11 +61,13 @@ function parseStaticOptions(raw) {
54
61
  *
55
62
  * `t` words the default boolean labels (`UI_YES` / `UI_NO`); the active UI
56
63
  * texts when omitted — a component passes its app's (`useAsLocale().t`).
64
+ * `text` translates the labels the model declares (`@ui.form.options`,
65
+ * `@ui.literalLabel`); a computed option list is the fn's own to translate.
57
66
  */
58
- function resolveOptions(prop, scope, labelsFrom, t) {
59
- const resolved = resolveFieldProp(prop, UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS, scope, { transform: parseStaticOptions });
67
+ function resolveOptions(prop, scope, labelsFrom, t, text) {
68
+ const resolved = resolveFieldProp(prop, UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS, scope, { transform: (raw) => parseStaticOptions(raw, text) });
60
69
  if (resolved !== void 0) return resolved;
61
- return labelsFrom ? extractLiteralOptions(prop, labelsFrom, t) : extractFieldLiteralOptions(prop, t);
70
+ return labelsFrom ? extractLiteralOptions(prop, labelsFrom, t, text) : extractFieldLiteralOptions(prop, t, text);
62
71
  }
63
72
  //#endregion
64
73
  export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.168",
3
+ "version": "0.1.170",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",
@@ -52,20 +52,20 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@atscript/db-client": "^0.1.173"
55
+ "@atscript/db-client": "^0.1.175"
56
56
  },
57
57
  "devDependencies": {
58
- "@atscript/core": "^0.2.9",
59
- "@atscript/db": "^0.1.173",
60
- "@atscript/typescript": "^0.2.9",
61
- "@uniqu/core": "^0.2.1",
62
- "unplugin-atscript": "^0.2.9",
58
+ "@atscript/core": "^0.2.11",
59
+ "@atscript/db": "^0.1.175",
60
+ "@atscript/typescript": "^0.2.11",
61
+ "@uniqu/core": "^0.2.2",
62
+ "unplugin-atscript": "^0.2.11",
63
63
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
64
64
  },
65
65
  "peerDependencies": {
66
- "@atscript/core": "^0.2.9",
67
- "@atscript/db": "^0.1.173",
68
- "@atscript/typescript": "^0.2.9"
66
+ "@atscript/core": "^0.2.11",
67
+ "@atscript/db": "^0.1.175",
68
+ "@atscript/typescript": "^0.2.11"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "vp pack",