@bpmn-io/feel-editor 0.5.0 → 0.6.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.
package/README.md CHANGED
@@ -44,6 +44,18 @@ const editor = new FeelEditor({
44
44
  });
45
45
  ```
46
46
 
47
+ The variables can be updated on the instance via `FeelEditor#setVariables()`:
48
+
49
+ ```javascript
50
+ editor.setVariables([
51
+ {
52
+ name: 'newName',
53
+ detail: 'new variable inline info',
54
+ info: 'new pop-out info
55
+ }
56
+ ]);
57
+ ```
58
+
47
59
  ## Hacking the Project
48
60
 
49
61
  To get the development setup make sure to have [NodeJS](https://nodejs.org/en/download/) installed.
package/dist/index.es.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { snippetCompletion, autocompletion as autocompletion$1, completeFromList, closeBrackets } from '@codemirror/autocomplete';
2
2
  import { defaultKeymap } from '@codemirror/commands';
3
- import { syntaxTree, LanguageSupport, syntaxHighlighting, HighlightStyle, indentOnInput, bracketMatching } from '@codemirror/language';
3
+ import { syntaxTree, LanguageSupport, syntaxHighlighting, HighlightStyle, bracketMatching, indentOnInput } from '@codemirror/language';
4
4
  import { linter as linter$1, setDiagnosticsEffect } from '@codemirror/lint';
5
- import { EditorState } from '@codemirror/state';
6
- import { EditorView, keymap } from '@codemirror/view';
5
+ import { Facet, Compartment, EditorState } from '@codemirror/state';
6
+ import { EditorView, tooltips, keymap } from '@codemirror/view';
7
7
  import { snippets, feelLanguage } from 'lang-feel';
8
8
  import { domify } from 'min-dom';
9
9
  import { tags as tags$1 } from '@lezer/highlight';
@@ -407,7 +407,18 @@ var builtins = context => {
407
407
  };
408
408
  };
409
409
 
410
- var variables = variables => context => {
410
+ /**
411
+ * @type {Facet<import('..').Variable[]>} Variable
412
+ */
413
+ const variablesFacet = Facet.define();
414
+
415
+ /**
416
+ * @type {import('@codemirror/autocomplete').CompletionSource}
417
+ */
418
+ var variables = context => {
419
+
420
+ const variables = context.state.facet(variablesFacet)[0];
421
+
411
422
  const options = variables.map(v => ({
412
423
  label: v.name,
413
424
  type: 'variable',
@@ -446,11 +457,11 @@ var variables = variables => context => {
446
457
  return result;
447
458
  };
448
459
 
449
- function autocompletion(context) {
460
+ function autocompletion() {
450
461
  return [
451
462
  autocompletion$1({
452
463
  override: [
453
- variables(context),
464
+ variables,
454
465
  builtins,
455
466
  completeFromList(snippets)
456
467
  ]
@@ -574,22 +585,33 @@ const syntaxClasses = syntaxHighlighting(
574
585
 
575
586
  var theme = [ baseTheme, highlightTheme, syntaxClasses ];
576
587
 
588
+ /**
589
+ * @typedef {object} Variable
590
+ * @property {string} name
591
+ * @property {string} [info]
592
+ * @property {string} [detail]
593
+ */
594
+
595
+ const autocompletionConf = new Compartment();
596
+
577
597
  /**
578
598
  * Creates a FEEL editor in the supplied container
579
599
  *
580
600
  * @param {Object} config
581
601
  * @param {DOMNode} config.container
602
+ * @param {DOMNode|String} [config.tooltipContainer]
582
603
  * @param {Function} [config.onChange]
583
604
  * @param {Function} [config.onKeyDown]
584
605
  * @param {Function} [config.onLint]
585
606
  * @param {Boolean} [config.readOnly]
586
607
  * @param {String} [config.value]
587
- * @param {Array} [config.variables]
608
+ * @param {Variable[]} [config.variables]
588
609
  *
589
610
  * @returns {Object} editor
590
611
  */
591
612
  function FeelEditor({
592
613
  container,
614
+ tooltipContainer,
593
615
  onChange = () => {},
594
616
  onKeyDown = () => {},
595
617
  onLint = () => {},
@@ -624,20 +646,32 @@ function FeelEditor({
624
646
  }
625
647
  );
626
648
 
649
+ if (typeof tooltipContainer === 'string') {
650
+ tooltipContainer = document.querySelector(tooltipContainer);
651
+ }
652
+
653
+ const tooltipLayout = tooltipContainer ? tooltips({
654
+ tooltipSpace: function() {
655
+ return tooltipContainer.getBoundingClientRect();
656
+ }
657
+ }) : [];
658
+
627
659
  const extensions = [
660
+ autocompletionConf.of(variablesFacet.of(variables)),
661
+ autocompletion(),
662
+ bracketMatching(),
663
+ changeHandler,
664
+ closeBrackets(),
665
+ indentOnInput(),
666
+ keyHandler,
628
667
  keymap.of([
629
668
  ...defaultKeymap,
630
669
  ]),
631
- changeHandler,
632
- keyHandler,
633
670
  language(),
634
- autocompletion(variables),
635
- theme,
636
671
  linter,
637
- indentOnInput(),
638
- bracketMatching(),
639
- closeBrackets(),
640
- lintHandler
672
+ lintHandler,
673
+ tooltipLayout,
674
+ theme
641
675
  ];
642
676
 
643
677
  if (readOnly) {
@@ -698,4 +732,15 @@ FeelEditor.prototype.getSelection = function() {
698
732
  return this._cmEditor.state.selection;
699
733
  };
700
734
 
735
+ /**
736
+ * Set variables to be used for autocompletion.
737
+ * @param {Variable[]} variables
738
+ * @returns {void}
739
+ */
740
+ FeelEditor.prototype.setVariables = function(variables) {
741
+ this._cmEditor.dispatch({
742
+ effects: autocompletionConf.reconfigure(variablesFacet.of(variables))
743
+ });
744
+ };
745
+
701
746
  export { FeelEditor as default };
package/dist/index.js CHANGED
@@ -409,7 +409,18 @@ var builtins = context => {
409
409
  };
410
410
  };
411
411
 
412
- var variables = variables => context => {
412
+ /**
413
+ * @type {Facet<import('..').Variable[]>} Variable
414
+ */
415
+ const variablesFacet = state.Facet.define();
416
+
417
+ /**
418
+ * @type {import('@codemirror/autocomplete').CompletionSource}
419
+ */
420
+ var variables = context => {
421
+
422
+ const variables = context.state.facet(variablesFacet)[0];
423
+
413
424
  const options = variables.map(v => ({
414
425
  label: v.name,
415
426
  type: 'variable',
@@ -448,11 +459,11 @@ var variables = variables => context => {
448
459
  return result;
449
460
  };
450
461
 
451
- function autocompletion(context) {
462
+ function autocompletion() {
452
463
  return [
453
464
  autocomplete.autocompletion({
454
465
  override: [
455
- variables(context),
466
+ variables,
456
467
  builtins,
457
468
  autocomplete.completeFromList(langFeel.snippets)
458
469
  ]
@@ -576,22 +587,33 @@ const syntaxClasses = language$1.syntaxHighlighting(
576
587
 
577
588
  var theme = [ baseTheme, highlightTheme, syntaxClasses ];
578
589
 
590
+ /**
591
+ * @typedef {object} Variable
592
+ * @property {string} name
593
+ * @property {string} [info]
594
+ * @property {string} [detail]
595
+ */
596
+
597
+ const autocompletionConf = new state.Compartment();
598
+
579
599
  /**
580
600
  * Creates a FEEL editor in the supplied container
581
601
  *
582
602
  * @param {Object} config
583
603
  * @param {DOMNode} config.container
604
+ * @param {DOMNode|String} [config.tooltipContainer]
584
605
  * @param {Function} [config.onChange]
585
606
  * @param {Function} [config.onKeyDown]
586
607
  * @param {Function} [config.onLint]
587
608
  * @param {Boolean} [config.readOnly]
588
609
  * @param {String} [config.value]
589
- * @param {Array} [config.variables]
610
+ * @param {Variable[]} [config.variables]
590
611
  *
591
612
  * @returns {Object} editor
592
613
  */
593
614
  function FeelEditor({
594
615
  container,
616
+ tooltipContainer,
595
617
  onChange = () => {},
596
618
  onKeyDown = () => {},
597
619
  onLint = () => {},
@@ -626,20 +648,32 @@ function FeelEditor({
626
648
  }
627
649
  );
628
650
 
651
+ if (typeof tooltipContainer === 'string') {
652
+ tooltipContainer = document.querySelector(tooltipContainer);
653
+ }
654
+
655
+ const tooltipLayout = tooltipContainer ? view.tooltips({
656
+ tooltipSpace: function() {
657
+ return tooltipContainer.getBoundingClientRect();
658
+ }
659
+ }) : [];
660
+
629
661
  const extensions = [
662
+ autocompletionConf.of(variablesFacet.of(variables)),
663
+ autocompletion(),
664
+ language$1.bracketMatching(),
665
+ changeHandler,
666
+ autocomplete.closeBrackets(),
667
+ language$1.indentOnInput(),
668
+ keyHandler,
630
669
  view.keymap.of([
631
670
  ...commands.defaultKeymap,
632
671
  ]),
633
- changeHandler,
634
- keyHandler,
635
672
  language(),
636
- autocompletion(variables),
637
- theme,
638
673
  linter,
639
- language$1.indentOnInput(),
640
- language$1.bracketMatching(),
641
- autocomplete.closeBrackets(),
642
- lintHandler
674
+ lintHandler,
675
+ tooltipLayout,
676
+ theme
643
677
  ];
644
678
 
645
679
  if (readOnly) {
@@ -700,4 +734,15 @@ FeelEditor.prototype.getSelection = function() {
700
734
  return this._cmEditor.state.selection;
701
735
  };
702
736
 
737
+ /**
738
+ * Set variables to be used for autocompletion.
739
+ * @param {Variable[]} variables
740
+ * @returns {void}
741
+ */
742
+ FeelEditor.prototype.setVariables = function(variables) {
743
+ this._cmEditor.dispatch({
744
+ effects: autocompletionConf.reconfigure(variablesFacet.of(variables))
745
+ });
746
+ };
747
+
703
748
  module.exports = FeelEditor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmn-io/feel-editor",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Editor for FEEL expressions.",
5
5
  "files": [
6
6
  "dist"
@@ -45,17 +45,16 @@
45
45
  "license": "MIT",
46
46
  "dependencies": {
47
47
  "@babel/core": "^7.20.2",
48
- "@codemirror/autocomplete": "^6.1.1",
49
- "@codemirror/commands": "^6.0.0",
50
- "@codemirror/language": "^6.0.0",
51
- "@codemirror/lint": "^6.0.0",
52
- "@codemirror/state": "^6.0.0",
53
- "@codemirror/view": "^6.0.0",
54
- "@lezer/highlight": "^1.0.0",
48
+ "@codemirror/autocomplete": "^6.3.2",
49
+ "@codemirror/commands": "^6.1.2",
50
+ "@codemirror/language": "^6.3.1",
51
+ "@codemirror/lint": "^6.1.0",
52
+ "@codemirror/state": "^6.1.4",
53
+ "@codemirror/view": "^6.5.1",
54
+ "@lezer/highlight": "^1.1.2",
55
55
  "babel-loader": "^9.1.0",
56
56
  "babel-plugin-istanbul": "^6.1.1",
57
- "lang-feel": "^0.0.3",
58
- "lezer-feel": "^0.14.1",
57
+ "lang-feel": "^0.1.0",
59
58
  "min-dom": "^4.0.1"
60
59
  },
61
60
  "devDependencies": {