@getodk/xpath 0.5.0 → 0.7.0

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.
@@ -3,6 +3,7 @@ import { XPathNode } from '../adapter/interface/XPathNode.ts';
3
3
  import { XPathDOMProvider } from '../adapter/xpathDOMProvider.ts';
4
4
  import { XFormsElementRepresentation } from './XFormsElementRepresentation.ts';
5
5
  type XFormsItextTextID = string;
6
+ export type XFormsItextTranslationValueElement<T extends XPathNode> = XFormsElementRepresentation<T, 'value', 'form'>;
6
7
  type XFormsItextTranslationTextElement<T extends XPathNode> = XFormsElementRepresentation<T, 'text'>;
7
8
  export type XFormsItextTranslationElement<T extends XPathNode> = XFormsElementRepresentation<T, 'translation', 'lang'>;
8
9
  type XFormsItextTextMap<T extends XPathNode> = ReadonlyMap<XFormsItextTextID, XFormsItextTranslationTextElement<T>>;
@@ -42,35 +43,34 @@ export declare class XFormsItextTranslations<T extends XPathNode> implements XFo
42
43
  private getTranslationMetadata;
43
44
  private getTranslationTextElement;
44
45
  /**
46
+ * Retrieves all translation value elements for a given Itext in the active language.
47
+ *
45
48
  * @package
46
49
  *
47
- * Here, "default" is meant as more precise language than "regular" as
48
- * {@link https://getodk.github.io/xforms-spec/#languages | specified by ODK XForms}. In other words, this is equivalent to the following hypothetical XPath pseudo-code (whitespace added to improve structural clarity):
50
+ * This method fetches the `text` element matching `itextID` and returns its child `value` elements,
51
+ * which may have an optional `@form` attribute.
52
+ *
53
+ * The operation is conceptually similar to the following XPath query:
49
54
  *
50
55
  * ```xpath
51
- * string(
52
- * imaginary:itext-translation(
53
- * xpath3-fn:environment-variable('activeLanguage')
54
- * )
55
- * /text[@id = $itextID]
56
- * /value[not(@form)]
56
+ * imaginary:itext-translation(
57
+ * xpath3-fn:environment-variable('activeLanguage')
57
58
  * )
59
+ * /text[@id = $itextID]
60
+ * /value
58
61
  * ```
59
62
  *
60
63
  * Or alternately:
61
64
  *
62
65
  * ```xpath
63
- * string(
64
- * imaginary:itext-root()
65
- * /translation[@lang = xpath3-fn:environment-variable('activeLanguage')]
66
- * /text[@id = $itextID]
67
- * /value[not(@form)]
68
- * )
66
+ * imaginary:itext-root()
67
+ * /translation[@lang = xpath3-fn:environment-variable('activeLanguage')]
68
+ * /text[@id = $itextID]
69
+ * /value
69
70
  * ```
70
- *
71
- * @todo The above really feels like it adds some helpful clarity to how `jr:itext()` is designed to work, and the kinds of structures, state and input involved. Since there's already some discomfort around that API as specified, it's worth considering
71
+ * Returns an array of `XFormsItextTranslationValueElement<T>`
72
72
  */
73
- getDefaultTranslationText(itextID: string): string;
73
+ getTranslationValues(itextID: string): Array<XFormsItextTranslationValueElement<T>>;
74
74
  getLanguages(): readonly XFormsItextTranslationLanguage[];
75
75
  getActiveLanguage(): XFormsItextTranslationLanguage | null;
76
76
  setActiveLanguage(language: XFormsItextTranslationLanguage | null): XFormsItextTranslationLanguage | null;
@@ -3,7 +3,7 @@ import { XPathNode } from '../adapter/interface/XPathNode.ts';
3
3
  import { AdapterParentNode } from '../adapter/interface/XPathNodeKindAdapter.ts';
4
4
  import { EvaluationContext } from '../context/EvaluationContext.ts';
5
5
  import { EvaluatorOptions, Evaluator } from '../evaluator/Evaluator.ts';
6
- import { XFormsItextTranslationLanguage, XFormsItextTranslationMap, XFormsItextTranslationsState } from './XFormsItextTranslations.ts';
6
+ import { XFormsItextTranslationLanguage, XFormsItextTranslationMap, XFormsItextTranslationsState, XFormsItextTranslationValueElement } from './XFormsItextTranslations.ts';
7
7
  import { XFormsSecondaryInstanceElement, XFormsSecondaryInstanceMap } from './XFormsSecondaryInstances.ts';
8
8
  /**
9
9
  * @todo We accept an arbitrary parent node specifically for legacy WHATWG DOM
@@ -18,7 +18,7 @@ export interface XFormsXPathEvaluatorOptions<T extends XPathNode> extends Evalua
18
18
  }
19
19
  export declare class XFormsXPathEvaluator<T extends XPathNode> extends Evaluator<T> implements XFormsItextTranslationsState {
20
20
  static getSecondaryInstance<T extends XPathNode>(context: EvaluationContext<T>, id: string): XFormsSecondaryInstanceElement<T> | null;
21
- static getDefaultTranslationText<T extends XPathNode>(context: EvaluationContext<T>, itextID: string): string;
21
+ static getTranslationValues<T extends XPathNode>(context: EvaluationContext<T>, itextID: string): Array<XFormsItextTranslationValueElement<T>>;
22
22
  readonly rootNode: AdapterParentNode<T>;
23
23
  /**
24
24
  * @package
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getodk/xpath",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "XPath implementation for ODK Web Forms",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "README.md"
32
32
  ],
33
33
  "engines": {
34
- "node": "^18.20.5 || ^20.18.1 || ^22.12.0",
34
+ "node": "^20.19.3 || ^22.12.0 || ^24.3.0",
35
35
  "yarn": "1.22.22"
36
36
  },
37
37
  "scripts": {
@@ -54,23 +54,23 @@
54
54
  "test:types:test": "tsc --project ./test/tsconfig.json --emitDeclarationOnly false --noEmit"
55
55
  },
56
56
  "dependencies": {
57
- "@getodk/common": "0.6.0",
57
+ "@getodk/common": "0.7.0",
58
58
  "crypto-js": "^4.2.0",
59
59
  "temporal-polyfill": "^0.3.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/core": "^7.26.10",
63
- "@getodk/tree-sitter-xpath": "0.1.3",
64
- "@playwright/test": "^1.49.1",
62
+ "@babel/core": "^7.28.0",
63
+ "@getodk/tree-sitter-xpath": "0.2.0",
64
+ "@playwright/test": "^1.53.2",
65
65
  "@types/crypto-js": "^4.2.2",
66
- "@vitest/browser": "^3.0.9",
66
+ "@vitest/browser": "^3.2.4",
67
67
  "babel-plugin-transform-jsbi-to-bigint": "^1.4.2",
68
- "jsdom": "^26.0.0",
69
- "vite": "^6.2.3",
70
- "vite-plugin-babel": "^1.3.0",
71
- "vite-plugin-dts": "^4.5.3",
68
+ "jsdom": "^26.1.0",
69
+ "vite": "^7.0.3",
70
+ "vite-plugin-babel": "^1.3.2",
71
+ "vite-plugin-dts": "^4.5.4",
72
72
  "vite-plugin-no-bundle": "^4.0.0",
73
- "vitest": "^3.0.9",
73
+ "vitest": "^3.2.4",
74
74
  "web-tree-sitter": "0.24.5"
75
75
  },
76
76
  "publishConfig": {
@@ -1,9 +0,0 @@
1
- import { StringFunction } from '../../evaluator/functions/StringFunction.ts';
2
- /**
3
- * @todo This could be a {@link NodeSetFunction}. If it were, that might be a
4
- * good starting point for thinking about how we'll support:
5
- *
6
- * - `<output>` in itext translations
7
- * - `<value form="...">` (short, guidance, various media types)
8
- */
9
- export declare const itext: StringFunction;