@op-ted/efx-syntax-highlighter 0.4.0 → 0.4.1

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/README.md CHANGED
@@ -34,14 +34,16 @@ const view = new EditorView({
34
34
  });
35
35
  ```
36
36
 
37
- The package offers four things:
37
+ The package offers five things:
38
38
 
39
39
  - **`efx(kind)`** gives an editor what it needs to read one kind of EFX-2 text: its parser, the EFX colours and the completions. The kind is `'template'` for a template file, `'rules'` for a rules file, `'expression'` for a single expression with its context, such as `WITH ND-Root COMPUTE BT-01-notice is present`, or `'bare-expression'` for an expression with no context in the text, such as `BT-01-notice is present`, read as the expression of `WITH … COMPUTE`. Any other kind is refused with a `RangeError`. `efx(kind).language` is the CodeMirror language, for an application that needs it on its own.
40
40
  - **`efx(kind, { version: 1 })`** does the same for EFX-1 text, without completions. The kinds are `'template'`, `'expression'`, such as `{ND-Root} ${BT-01-notice is present}`, and `'bare-expression'`; EFX-1 has no rules files. Any other kind or version is refused with a `RangeError`.
41
- - **`efxSymbols`** gives the editor the field and node ids it offers: `efxSymbols.of({ fields, nodes })`, each a list of ids, for example those of the SDK's `fields.json`. The ids of several such extensions add up.
41
+ - **`efxSymbols`** gives the editor the field and node ids it offers: `efxSymbols.of({ fields, nodes })`, each a list of ids, for example those of the SDK's `fields.json`. An entry can also be an id with its type, such as `{ id: 'BT-01-notice', type: 'code' }`; the editor shows the type beside the id, and "field" or "node" beside an id without one. The ids of several such extensions add up.
42
42
  - **`efxHighlightStyle`** is the EFX colours. `efx(kind)` already uses them as the editor's default colours; an application that gives its editor its own colours with `syntaxHighlighting(...)` replaces them.
43
43
  - **`efxTheme`** is a light look for the editor itself (white background, black cursor). Add it if you want it.
44
44
 
45
+ The package ships its TypeScript types, so that an application written in TypeScript has its calls checked.
46
+
45
47
  ### Completions
46
48
 
47
49
  The application turns completion on, with `autocompletion()` from `@codemirror/autocomplete` (or the `basicSetup` of the `codemirror` package, which includes it). While you type, the editor offers the words the grammar can take at the cursor:
@@ -18,9 +18,9 @@ export const EFX1_STYLES = {
18
18
  "DateFunction TimeFunction DayTimeDurationFunction YearMonthDurationFunction AddMeasure SubtractMeasure": t.function(t.keyword),
19
19
  "DistinctValuesFunction UnionFunction IntersectFunction ExceptFunction SequenceEqualFunction": t.function(t.keyword),
20
20
 
21
- // Literals.
21
+ // Literals, and the outline numbers of a template.
22
22
  "STRING UUIDV4 INTEGER DECIMAL DATE TIME DayTimeDurationLiteral YearMonthDurationLiteral": t.literal,
23
- "True False Always Never": t.literal,
23
+ "True False Always Never OutlineNumber": t.literal,
24
24
 
25
25
  // The data of a notice: fields, nodes and attributes.
26
26
  "FieldId NodeId BtId AttributeReference/Identifier": t.propertyName,
@@ -35,7 +35,7 @@ export const EFX1_STYLES = {
35
35
  FreeText: t.special(t.string),
36
36
 
37
37
  "Comparison Plus Minus Star Slash Percent ColonColon": t.operator,
38
- "OpenParenthesis CloseParenthesis OpenBracket CloseBracket Pipe": t.punctuation,
38
+ "OpenParenthesis CloseParenthesis OpenBracket CloseBracket Pipe Comma": t.punctuation,
39
39
  SlashAt: t.punctuation,
40
40
  "StartExpression StartLabel StartSelector EndExpression EndLabel": t.bracket,
41
41
  Comment: t.lineComment,
@@ -70,7 +70,10 @@ export class EfxCompletions {
70
70
 
71
71
  static #symbolOptions(expected, state) {
72
72
  const { fields, nodes } = state.facet(efxSymbols);
73
- const options = (ids, type, detail) => ids.map((id) => ({ label: id, type, detail }));
73
+ // Each id is shown with its type, if the application gives one, or else with what it is.
74
+ const options = (entries, type, what) => entries.map((entry) => (typeof entry === 'string'
75
+ ? { label: entry, type, detail: what }
76
+ : { label: entry.id, type, detail: entry.type ?? what }));
74
77
  return [
75
78
  ...(expected.has(terms.FieldId) ? options(fields, 'constant', 'field') : []),
76
79
  ...(expected.has(terms.NodeId) ? options(nodes, 'namespace', 'node') : []),
@@ -44,10 +44,10 @@ export const EFX2_STYLES = {
44
44
  "SubsequenceFunction IndexOfFunction PreferredLanguageFunction PreferredLanguageTextFunction": t.function(t.keyword),
45
45
  "SortFunction ReverseFunction SplitFunction": t.function(t.keyword),
46
46
 
47
- // Literals, and the notice types of a rule and the path of an include.
47
+ // Literals, the notice types of a rule, the path of an include and the outline numbers of a template.
48
48
  "StringLiteral UuidV4Literal IntegerLiteral DecimalLiteral True False Always Never DateLiteral TimeLiteral": t.literal,
49
49
  "DayTimeDurationLiteral YearMonthDurationLiteral NumericLiteral/Minus NoticeType/Identifier NoticeTypeRange/Minus": t.literal,
50
- IncludePath: t.literal,
50
+ "IncludePath OutlineNumber": t.literal,
51
51
 
52
52
  // The data of a notice: fields, nodes and attributes.
53
53
  "FieldId NodeId BtId SimpleFieldReference/Identifier FieldMention/Identifier SingleExpression/Identifier": t.propertyName,
@@ -72,7 +72,7 @@ export const EFX2_STYLES = {
72
72
  "FreeText OtherEscapeSequence CharacterReference NewLine": t.special(t.string),
73
73
 
74
74
  "Assignment Comparison Plus Minus Star Slash Percent ColonColon": t.operator,
75
- "OpenParenthesis CloseParenthesis OpenBracket CloseBracket Pipe Colon Ellipsis": t.punctuation,
75
+ "OpenParenthesis CloseParenthesis OpenBracket CloseBracket Pipe Colon Ellipsis Comma Semicolon": t.punctuation,
76
76
  "AttributeReference/Slash AttributeExpression/Slash": t.punctuation,
77
77
  "StartContextBlock StartExpressionBlock StartLabelBlock StartHyperlinkBlock StartSelectorBlock EndBlock": t.bracket,
78
78
  Comment: t.lineComment,
@@ -1,6 +1,8 @@
1
1
  // The field and node ids an application gives the editor, which it offers where the grammar takes
2
2
  // one: an extension, `efxSymbols.of({ fields, nodes })`, each a list of ids, for example those of
3
- // the SDK's fields.json. The ids of several such extensions add up.
3
+ // the SDK's fields.json. An entry is an id, or an id with its type, `{ id, type }`, such as a
4
+ // field's type in fields.json, which the editor shows beside the id. The ids of several such
5
+ // extensions add up, each entry as the application gave it.
4
6
 
5
7
  import { Facet } from '@codemirror/state';
6
8
 
@@ -0,0 +1,41 @@
1
+ // The types of the package's public surface (index.js), for applications written in TypeScript.
2
+
3
+ import type { HighlightStyle, LanguageSupport } from '@codemirror/language';
4
+ import type { Extension, Facet } from '@codemirror/state';
5
+
6
+ /** The kinds of EFX text an editor can hold. */
7
+ export type EfxKind = 'template' | 'rules' | 'expression' | 'bare-expression';
8
+
9
+ /** The kinds of EFX text that both versions of EFX have: EFX-1 has no rules files. */
10
+ export type EfxCommonKind = Exclude<EfxKind, 'rules'>;
11
+
12
+ /** EFX support for an editor that holds one kind of EFX-2 text: its parser, the EFX colours and the completions. */
13
+ export function efx(kind: EfxKind, options?: { version?: 2 }): LanguageSupport;
14
+ /** EFX support for an editor that holds one kind of EFX-1 text: its parser and the EFX colours. */
15
+ export function efx(kind: EfxCommonKind, options: { version: 1 }): LanguageSupport;
16
+ /** EFX support for a kind of text both versions have, in a version chosen when the application runs. */
17
+ export function efx(kind: EfxCommonKind, options?: { version?: 1 | 2 }): LanguageSupport;
18
+
19
+ /** A field or node id, with its type, such as a field's type in the SDK's fields.json, shown beside the id. */
20
+ export interface EfxSymbol {
21
+ id: string;
22
+ type?: string;
23
+ }
24
+
25
+ /** The field and node ids an application gives the editor: ids, or ids with their type. */
26
+ export interface EfxSymbols {
27
+ fields?: readonly (string | EfxSymbol)[];
28
+ nodes?: readonly (string | EfxSymbol)[];
29
+ }
30
+
31
+ /**
32
+ * The field and node ids the editor offers where the grammar takes one: `efxSymbols.of({ fields, nodes })`.
33
+ * The ids of several such extensions add up, each entry as the application gave it.
34
+ */
35
+ export const efxSymbols: Facet<EfxSymbols, { fields: (string | EfxSymbol)[]; nodes: (string | EfxSymbol)[] }>;
36
+
37
+ /** The EFX colours, which efx() gives the editor as its default colours. */
38
+ export const efxHighlightStyle: HighlightStyle;
39
+
40
+ /** A light look for the editor itself, which an application adds if it wants it. */
41
+ export const efxTheme: Extension;
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@op-ted/efx-syntax-highlighter",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Lezer-based parser and CodeMirror 6 language support for EFX: syntax highlighting and completions.",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "exports": {
7
- ".": "./dist/index.js"
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
8
12
  },
9
13
  "files": [
10
14
  "dist",
@@ -12,7 +16,7 @@
12
16
  ],
13
17
  "scripts": {
14
18
  "build": "node scripts/build.js",
15
- "test": "node test/synced.js && node test/package.js && node test/sync.js && node test/lexer.js && node test/conformance.js && node test/styles.js && node test/efx2/trees.js && node test/efx2/completions.js && node test/efx1/entries.js && node test/incremental.js",
19
+ "test": "node test/synced.js && node test/package.js && node test/sync.js && node test/lexer.js && node test/conformance.js && node test/styles.js && node test/efx2/trees.js && node test/efx2/completions.js && node test/efx1/entries.js && node test/incremental.js && node test/types.js",
16
20
  "sync": "node scripts/sync.js",
17
21
  "demo": "node scripts/demo.js",
18
22
  "site": "node scripts/site.js"
@@ -54,7 +58,8 @@
54
58
  "devDependencies": {
55
59
  "@lezer/generator": "^1.3.0",
56
60
  "antlr-ng": "1.0.10",
57
- "antlr4ng": "3.0.16"
61
+ "antlr4ng": "3.0.16",
62
+ "typescript": "5.9.3"
58
63
  },
59
64
  "config": {
60
65
  "sdk": "OP-TED/eForms-SDK@e64ae124230cfae2f44924291e1909baada2102d",