@bpmn-io/feel-editor 1.12.0 → 1.12.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/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { snippetCompletion, autocompletion, closeBrackets } from '@codemirror/autocomplete';
1
+ import { snippetCompletion, completeFromList, autocompletion, closeBrackets } from '@codemirror/autocomplete';
2
2
  import { defaultKeymap } from '@codemirror/commands';
3
3
  import { syntaxHighlighting, HighlightStyle, syntaxTree, bracketMatching, indentOnInput } from '@codemirror/language';
4
4
  import { linter as linter$1, setDiagnosticsEffect } from '@codemirror/lint';
@@ -148,7 +148,7 @@ function pathExpressionCompletion({ variables }) {
148
148
  const nodeBefore = syntaxTree(context.state).resolve(context.pos, -1);
149
149
 
150
150
  if (!isPathExpression(nodeBefore)) {
151
- return;
151
+ return null;
152
152
  }
153
153
 
154
154
  const expression = findPathExpression(nodeBefore);
@@ -169,26 +169,27 @@ function pathExpressionCompletion({ variables }) {
169
169
  // only suggest if variable type matches
170
170
  if (
171
171
  childVar.isList !== 'optional' &&
172
- !!childVar.isList !== path[i].isList
172
+ !!childVar.isList !== path[i].isList
173
173
  ) {
174
- return;
174
+ return null;
175
175
  }
176
176
 
177
177
  options = childVar.entries;
178
178
  }
179
179
 
180
- if (!options) return;
180
+ if (!options) return null;
181
181
 
182
- options = options.map(v => ({
183
- label: v.name,
184
- type: 'variable',
185
- info: v.info,
186
- detail: v.detail
187
- }));
182
+ const completionOptions = options.map(option => (
183
+ {
184
+ label: option.name,
185
+ type: 'variable',
186
+ info: option.info,
187
+ detail: option.detail
188
+ }));
188
189
 
189
190
  const result = {
190
191
  from: from,
191
- options: options
192
+ options: completionOptions
192
193
  };
193
194
 
194
195
  return result;
@@ -312,8 +313,8 @@ function getVariableSuggestions(variables, builtins) {
312
313
 
313
314
  /**
314
315
  * @param {import('..').Variable} variable
315
- * @param {number} boost
316
-
316
+ * @param {number} [boost]
317
+ *
317
318
  * @returns {import('@codemirror/autocomplete').Completion}
318
319
  */
319
320
  function createVariableSuggestion(variable, boost) {
@@ -383,7 +384,7 @@ function completions({ variables = [], builtins = [] }) {
383
384
  return [
384
385
  pathExpressionCompletion({ variables }),
385
386
  variableCompletion({ variables, builtins }),
386
- snippets,
387
+ completeFromList(snippets),
387
388
  ...keywordCompletions
388
389
  ];
389
390
  }
@@ -452,12 +453,12 @@ const parserDialectFacet = Facet.define();
452
453
  /**
453
454
  * @typedef {object} Variable
454
455
  * @property {string} name name or key of the variable
455
- * @property {string} [info] short information about the variable, e.g. type
456
+ * @property {string | (() => HTMLElement)} [info] short information about the variable, e.g. type
456
457
  * @property {string} [detail] longer description of the variable content
457
- * @property {boolean} [isList] whether the variable is a list
458
- * @property {Array<Variable>} [schema] array of child variables if the variable is a context or list
458
+ * @property {boolean|'optional'} [isList] whether the variable is a list
459
+ * @property {Array<Variable>} [entries] array of child variables if the variable is a context or list
459
460
  * @property {'function'|'variable'} [type] type of the variable
460
- * @property {Array<{name: string, type: string}>} [params] function parameters
461
+ * @property {Array<{name: string, type?: string}>} [params] function parameters
461
462
  */
462
463
 
463
464
  /**
@@ -549,12 +550,14 @@ const placeholderConf = new Compartment();
549
550
  * @param {ParserDialect} [config.parserDialect]
550
551
  * @param {DOMNode|String} [config.tooltipContainer]
551
552
  * @param {Function} [config.onChange]
552
- * @param {Function} [config.onKeyDown]
553
+ * @param {(event: KeyboardEvent, view: import('@codemirror/view').EditorView) => boolean | void} [config.onKeyDown]
553
554
  * @param {Function} [config.onLint]
554
555
  * @param {Boolean} [config.readOnly]
555
556
  * @param {String} [config.value]
556
557
  * @param {Variable[]} [config.variables]
557
558
  * @param {Variable[]} [config.builtins]
559
+ * @param {Object} [config.contentAttributes]
560
+ * @param {String} [config.placeholder]
558
561
  */
559
562
  function FeelEditor({
560
563
  extensions: editorExtensions = [],
@@ -600,12 +603,12 @@ function FeelEditor({
600
603
  );
601
604
 
602
605
  if (typeof tooltipContainer === 'string') {
603
- tooltipContainer = document.querySelector(tooltipContainer);
606
+ tooltipContainer = /** @type {HTMLElement} */ (document.querySelector(tooltipContainer));
604
607
  }
605
608
 
606
609
  const tooltipLayout = tooltipContainer ? tooltips({
607
610
  tooltipSpace: function() {
608
- return tooltipContainer.getBoundingClientRect();
611
+ return /** @type {HTMLElement} */ (tooltipContainer).getBoundingClientRect();
609
612
  }
610
613
  }) : [];
611
614
 
@@ -685,8 +688,7 @@ FeelEditor.prototype.focus = function(position) {
685
688
  * Returns the current selection ranges. If no text is selected, a single
686
689
  * range with the start and end index at the cursor position will be returned.
687
690
  *
688
- * @returns {Object} selection
689
- * @returns {Array} selection.ranges
691
+ * @returns {import('@codemirror/state').EditorSelection} selection - Selection object with ranges array
690
692
  */
691
693
  FeelEditor.prototype.getSelection = function() {
692
694
  return this._cmEditor.state.selection;
package/dist/index.js CHANGED
@@ -150,7 +150,7 @@ function pathExpressionCompletion({ variables }) {
150
150
  const nodeBefore = language$1.syntaxTree(context.state).resolve(context.pos, -1);
151
151
 
152
152
  if (!isPathExpression(nodeBefore)) {
153
- return;
153
+ return null;
154
154
  }
155
155
 
156
156
  const expression = findPathExpression(nodeBefore);
@@ -171,26 +171,27 @@ function pathExpressionCompletion({ variables }) {
171
171
  // only suggest if variable type matches
172
172
  if (
173
173
  childVar.isList !== 'optional' &&
174
- !!childVar.isList !== path[i].isList
174
+ !!childVar.isList !== path[i].isList
175
175
  ) {
176
- return;
176
+ return null;
177
177
  }
178
178
 
179
179
  options = childVar.entries;
180
180
  }
181
181
 
182
- if (!options) return;
182
+ if (!options) return null;
183
183
 
184
- options = options.map(v => ({
185
- label: v.name,
186
- type: 'variable',
187
- info: v.info,
188
- detail: v.detail
189
- }));
184
+ const completionOptions = options.map(option => (
185
+ {
186
+ label: option.name,
187
+ type: 'variable',
188
+ info: option.info,
189
+ detail: option.detail
190
+ }));
190
191
 
191
192
  const result = {
192
193
  from: from,
193
- options: options
194
+ options: completionOptions
194
195
  };
195
196
 
196
197
  return result;
@@ -314,8 +315,8 @@ function getVariableSuggestions(variables, builtins) {
314
315
 
315
316
  /**
316
317
  * @param {import('..').Variable} variable
317
- * @param {number} boost
318
-
318
+ * @param {number} [boost]
319
+ *
319
320
  * @returns {import('@codemirror/autocomplete').Completion}
320
321
  */
321
322
  function createVariableSuggestion(variable, boost) {
@@ -385,7 +386,7 @@ function completions({ variables = [], builtins = [] }) {
385
386
  return [
386
387
  pathExpressionCompletion({ variables }),
387
388
  variableCompletion({ variables, builtins }),
388
- langFeel.snippets,
389
+ autocomplete.completeFromList(langFeel.snippets),
389
390
  ...langFeel.keywordCompletions
390
391
  ];
391
392
  }
@@ -454,12 +455,12 @@ const parserDialectFacet = state.Facet.define();
454
455
  /**
455
456
  * @typedef {object} Variable
456
457
  * @property {string} name name or key of the variable
457
- * @property {string} [info] short information about the variable, e.g. type
458
+ * @property {string | (() => HTMLElement)} [info] short information about the variable, e.g. type
458
459
  * @property {string} [detail] longer description of the variable content
459
- * @property {boolean} [isList] whether the variable is a list
460
- * @property {Array<Variable>} [schema] array of child variables if the variable is a context or list
460
+ * @property {boolean|'optional'} [isList] whether the variable is a list
461
+ * @property {Array<Variable>} [entries] array of child variables if the variable is a context or list
461
462
  * @property {'function'|'variable'} [type] type of the variable
462
- * @property {Array<{name: string, type: string}>} [params] function parameters
463
+ * @property {Array<{name: string, type?: string}>} [params] function parameters
463
464
  */
464
465
 
465
466
  /**
@@ -551,12 +552,14 @@ const placeholderConf = new state.Compartment();
551
552
  * @param {ParserDialect} [config.parserDialect]
552
553
  * @param {DOMNode|String} [config.tooltipContainer]
553
554
  * @param {Function} [config.onChange]
554
- * @param {Function} [config.onKeyDown]
555
+ * @param {(event: KeyboardEvent, view: import('@codemirror/view').EditorView) => boolean | void} [config.onKeyDown]
555
556
  * @param {Function} [config.onLint]
556
557
  * @param {Boolean} [config.readOnly]
557
558
  * @param {String} [config.value]
558
559
  * @param {Variable[]} [config.variables]
559
560
  * @param {Variable[]} [config.builtins]
561
+ * @param {Object} [config.contentAttributes]
562
+ * @param {String} [config.placeholder]
560
563
  */
561
564
  function FeelEditor({
562
565
  extensions: editorExtensions = [],
@@ -602,12 +605,12 @@ function FeelEditor({
602
605
  );
603
606
 
604
607
  if (typeof tooltipContainer === 'string') {
605
- tooltipContainer = document.querySelector(tooltipContainer);
608
+ tooltipContainer = /** @type {HTMLElement} */ (document.querySelector(tooltipContainer));
606
609
  }
607
610
 
608
611
  const tooltipLayout = tooltipContainer ? view.tooltips({
609
612
  tooltipSpace: function() {
610
- return tooltipContainer.getBoundingClientRect();
613
+ return /** @type {HTMLElement} */ (tooltipContainer).getBoundingClientRect();
611
614
  }
612
615
  }) : [];
613
616
 
@@ -687,8 +690,7 @@ FeelEditor.prototype.focus = function(position) {
687
690
  * Returns the current selection ranges. If no text is selected, a single
688
691
  * range with the start and end index at the cursor position will be returned.
689
692
  *
690
- * @returns {Object} selection
691
- * @returns {Array} selection.ranges
693
+ * @returns {import('@codemirror/state').EditorSelection} selection - Selection object with ranges array
692
694
  */
693
695
  FeelEditor.prototype.getSelection = function() {
694
696
  return this._cmEditor.state.selection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmn-io/feel-editor",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "Editor for FEEL expressions.",
5
5
  "files": [
6
6
  "dist"
@@ -8,11 +8,14 @@
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.es.js",
10
10
  "scripts": {
11
- "all": "run-s lint test build",
11
+ "all": "run-s lint check-types test build",
12
12
  "test": "karma start",
13
13
  "build": "rollup -c --bundleConfigAsCjs",
14
14
  "build:watch": "npm run build -- -w",
15
15
  "lint": "eslint .",
16
+ "check-types": "run-s check-types:*",
17
+ "check-types:src": "tsc",
18
+ "check-types:test": "tsc -p test",
16
19
  "start": "cross-env SINGLE_START=true npm run dev",
17
20
  "start:camunda": "cross-env SINGLE_START=camunda npm run dev",
18
21
  "dev": "npm test -- --auto-watch --no-single-run",
@@ -46,6 +49,7 @@
46
49
  "license": "MIT",
47
50
  "dependencies": {
48
51
  "@bpmn-io/feel-lint": "^2.1.0",
52
+ "@bpmn-io/lang-feel": "^2.4.0",
49
53
  "@camunda/feel-builtins": "^0.2.0",
50
54
  "@codemirror/autocomplete": "^6.16.2",
51
55
  "@codemirror/commands": "^6.8.0",
@@ -54,7 +58,6 @@
54
58
  "@codemirror/state": "^6.5.1",
55
59
  "@codemirror/view": "^6.36.2",
56
60
  "@lezer/highlight": "^1.2.1",
57
- "@bpmn-io/lang-feel": "^2.4.0",
58
61
  "min-dom": "^4.2.1"
59
62
  },
60
63
  "devDependencies": {
@@ -63,6 +66,10 @@
63
66
  "@rollup/plugin-json": "^6.1.0",
64
67
  "@testing-library/dom": "^10.4.0",
65
68
  "@testing-library/user-event": "^14.6.1",
69
+ "@types/chai": "^5.2.3",
70
+ "@types/mocha": "^10.0.10",
71
+ "@types/sinon": "^17.0.4",
72
+ "@types/sinon-chai": "^4.0.0",
66
73
  "babel-loader": "^9.2.1",
67
74
  "babel-plugin-istanbul": "^7.0.0",
68
75
  "chai": "^4.5.0",
@@ -85,6 +92,7 @@
85
92
  "rollup": "^4.31.0",
86
93
  "sinon": "^17.0.1",
87
94
  "sinon-chai": "^3.7.0",
95
+ "typescript": "^5.9.3",
88
96
  "webpack": "^5.97.1"
89
97
  }
90
98
  }