@bpmn-io/feel-editor 1.2.0 → 1.4.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 +15 -2
- package/dist/index.es.js +55 -8
- package/dist/index.js +55 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ const editor = new FeelEditor({
|
|
|
28
28
|
|
|
29
29
|
### Variables
|
|
30
30
|
|
|
31
|
-
You can provide a variables array that will be used for auto completion. Nested
|
|
32
|
-
structures are supported.
|
|
31
|
+
You can provide a variables array that will be used for auto completion. Nested
|
|
32
|
+
structures are supported.
|
|
33
33
|
The Variables need to be in the following format:
|
|
34
34
|
|
|
35
35
|
```JavaScript
|
|
@@ -63,6 +63,19 @@ editor.setVariables([
|
|
|
63
63
|
]);
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### Content attributes
|
|
67
|
+
|
|
68
|
+
You can provide attributes which will be set on the content editable div:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
const editor = new FeelEditor({
|
|
72
|
+
container,
|
|
73
|
+
contentAttributes: {
|
|
74
|
+
'aria-label': 'Expression editor'
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
66
79
|
## Hacking the Project
|
|
67
80
|
|
|
68
81
|
To get the development setup make sure to have [NodeJS](https://nodejs.org/en/download/) installed.
|
package/dist/index.es.js
CHANGED
|
@@ -679,12 +679,7 @@ var variables = context => {
|
|
|
679
679
|
|
|
680
680
|
const variables = context.state.facet(variablesFacet)[0];
|
|
681
681
|
|
|
682
|
-
const options = variables.map(v => (
|
|
683
|
-
label: v.name,
|
|
684
|
-
type: 'variable',
|
|
685
|
-
info: v.info,
|
|
686
|
-
detail: v.detail
|
|
687
|
-
}));
|
|
682
|
+
const options = variables.map(v => createVariableSuggestion(v));
|
|
688
683
|
|
|
689
684
|
// In most cases, use what is typed before the cursor
|
|
690
685
|
let nodeBefore = syntaxTree(context.state).resolve(context.pos, -1);
|
|
@@ -717,6 +712,55 @@ var variables = context => {
|
|
|
717
712
|
return result;
|
|
718
713
|
};
|
|
719
714
|
|
|
715
|
+
/**
|
|
716
|
+
* @param {import('..').Variable} variable
|
|
717
|
+
* @returns {import('@codemirror/autocomplete').Completion}
|
|
718
|
+
*/
|
|
719
|
+
function createVariableSuggestion(variable) {
|
|
720
|
+
if (variable.type === 'function') {
|
|
721
|
+
return createFunctionVariable(variable);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return {
|
|
725
|
+
label: variable.name,
|
|
726
|
+
type: 'variable',
|
|
727
|
+
info: variable.info,
|
|
728
|
+
detail: variable.detail
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @param {import('..').Variable} variable
|
|
734
|
+
* @returns {import('@codemirror/autocomplete').Completion}
|
|
735
|
+
*/
|
|
736
|
+
function createFunctionVariable(variable) {
|
|
737
|
+
const {
|
|
738
|
+
name,
|
|
739
|
+
info,
|
|
740
|
+
detail,
|
|
741
|
+
params = []
|
|
742
|
+
} = variable;
|
|
743
|
+
|
|
744
|
+
const paramsWithNames = params.map(({ name, type }, index) => ({
|
|
745
|
+
name: name || `param ${index + 1}`,
|
|
746
|
+
type
|
|
747
|
+
}));
|
|
748
|
+
|
|
749
|
+
const template = `${name}(${paramsWithNames.map(p => '${' + p.name + '}').join(', ')})`;
|
|
750
|
+
|
|
751
|
+
const paramsSignature = paramsWithNames.map(({ name, type }) => (
|
|
752
|
+
type ? `${name}: ${type}` : name
|
|
753
|
+
)).join(', ');
|
|
754
|
+
const label = `${name}(${paramsSignature})`;
|
|
755
|
+
|
|
756
|
+
return snippetCompletion(template, {
|
|
757
|
+
label,
|
|
758
|
+
type: 'function',
|
|
759
|
+
info,
|
|
760
|
+
detail
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
|
|
720
764
|
function autocompletion() {
|
|
721
765
|
return [
|
|
722
766
|
autocompletion$1({
|
|
@@ -813,12 +857,13 @@ var theme = [ baseTheme, highlightTheme, syntaxClasses ];
|
|
|
813
857
|
|
|
814
858
|
/**
|
|
815
859
|
* @typedef {object} Variable
|
|
816
|
-
* @typedef {import('@codemirror/state').Extension} Extension
|
|
817
860
|
* @property {string} name name or key of the variable
|
|
818
861
|
* @property {string} [info] short information about the variable, e.g. type
|
|
819
862
|
* @property {string} [detail] longer description of the variable content
|
|
820
863
|
* @property {boolean} [isList] whether the variable is a list
|
|
821
|
-
* @property {
|
|
864
|
+
* @property {Array<Variable>} [schema] array of child variables if the variable is a context or list
|
|
865
|
+
* @property {'function'|'variable'} [type] type of the variable
|
|
866
|
+
* @property {Array<{name: string, type: string}>} [params] function parameters
|
|
822
867
|
*/
|
|
823
868
|
|
|
824
869
|
const autocompletionConf = new Compartment();
|
|
@@ -842,6 +887,7 @@ const autocompletionConf = new Compartment();
|
|
|
842
887
|
function FeelEditor({
|
|
843
888
|
extensions: editorExtensions = [],
|
|
844
889
|
container,
|
|
890
|
+
contentAttributes = {},
|
|
845
891
|
tooltipContainer,
|
|
846
892
|
onChange = () => {},
|
|
847
893
|
onKeyDown = () => {},
|
|
@@ -893,6 +939,7 @@ function FeelEditor({
|
|
|
893
939
|
bracketMatching(),
|
|
894
940
|
changeHandler,
|
|
895
941
|
closeBrackets(),
|
|
942
|
+
EditorView.contentAttributes.of(contentAttributes),
|
|
896
943
|
indentOnInput(),
|
|
897
944
|
keyHandler,
|
|
898
945
|
keymap.of([
|
package/dist/index.js
CHANGED
|
@@ -681,12 +681,7 @@ var variables = context => {
|
|
|
681
681
|
|
|
682
682
|
const variables = context.state.facet(variablesFacet)[0];
|
|
683
683
|
|
|
684
|
-
const options = variables.map(v => (
|
|
685
|
-
label: v.name,
|
|
686
|
-
type: 'variable',
|
|
687
|
-
info: v.info,
|
|
688
|
-
detail: v.detail
|
|
689
|
-
}));
|
|
684
|
+
const options = variables.map(v => createVariableSuggestion(v));
|
|
690
685
|
|
|
691
686
|
// In most cases, use what is typed before the cursor
|
|
692
687
|
let nodeBefore = language$1.syntaxTree(context.state).resolve(context.pos, -1);
|
|
@@ -719,6 +714,55 @@ var variables = context => {
|
|
|
719
714
|
return result;
|
|
720
715
|
};
|
|
721
716
|
|
|
717
|
+
/**
|
|
718
|
+
* @param {import('..').Variable} variable
|
|
719
|
+
* @returns {import('@codemirror/autocomplete').Completion}
|
|
720
|
+
*/
|
|
721
|
+
function createVariableSuggestion(variable) {
|
|
722
|
+
if (variable.type === 'function') {
|
|
723
|
+
return createFunctionVariable(variable);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return {
|
|
727
|
+
label: variable.name,
|
|
728
|
+
type: 'variable',
|
|
729
|
+
info: variable.info,
|
|
730
|
+
detail: variable.detail
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @param {import('..').Variable} variable
|
|
736
|
+
* @returns {import('@codemirror/autocomplete').Completion}
|
|
737
|
+
*/
|
|
738
|
+
function createFunctionVariable(variable) {
|
|
739
|
+
const {
|
|
740
|
+
name,
|
|
741
|
+
info,
|
|
742
|
+
detail,
|
|
743
|
+
params = []
|
|
744
|
+
} = variable;
|
|
745
|
+
|
|
746
|
+
const paramsWithNames = params.map(({ name, type }, index) => ({
|
|
747
|
+
name: name || `param ${index + 1}`,
|
|
748
|
+
type
|
|
749
|
+
}));
|
|
750
|
+
|
|
751
|
+
const template = `${name}(${paramsWithNames.map(p => '${' + p.name + '}').join(', ')})`;
|
|
752
|
+
|
|
753
|
+
const paramsSignature = paramsWithNames.map(({ name, type }) => (
|
|
754
|
+
type ? `${name}: ${type}` : name
|
|
755
|
+
)).join(', ');
|
|
756
|
+
const label = `${name}(${paramsSignature})`;
|
|
757
|
+
|
|
758
|
+
return autocomplete.snippetCompletion(template, {
|
|
759
|
+
label,
|
|
760
|
+
type: 'function',
|
|
761
|
+
info,
|
|
762
|
+
detail
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
|
|
722
766
|
function autocompletion() {
|
|
723
767
|
return [
|
|
724
768
|
autocomplete.autocompletion({
|
|
@@ -815,12 +859,13 @@ var theme = [ baseTheme, highlightTheme, syntaxClasses ];
|
|
|
815
859
|
|
|
816
860
|
/**
|
|
817
861
|
* @typedef {object} Variable
|
|
818
|
-
* @typedef {import('@codemirror/state').Extension} Extension
|
|
819
862
|
* @property {string} name name or key of the variable
|
|
820
863
|
* @property {string} [info] short information about the variable, e.g. type
|
|
821
864
|
* @property {string} [detail] longer description of the variable content
|
|
822
865
|
* @property {boolean} [isList] whether the variable is a list
|
|
823
|
-
* @property {
|
|
866
|
+
* @property {Array<Variable>} [schema] array of child variables if the variable is a context or list
|
|
867
|
+
* @property {'function'|'variable'} [type] type of the variable
|
|
868
|
+
* @property {Array<{name: string, type: string}>} [params] function parameters
|
|
824
869
|
*/
|
|
825
870
|
|
|
826
871
|
const autocompletionConf = new state.Compartment();
|
|
@@ -844,6 +889,7 @@ const autocompletionConf = new state.Compartment();
|
|
|
844
889
|
function FeelEditor({
|
|
845
890
|
extensions: editorExtensions = [],
|
|
846
891
|
container,
|
|
892
|
+
contentAttributes = {},
|
|
847
893
|
tooltipContainer,
|
|
848
894
|
onChange = () => {},
|
|
849
895
|
onKeyDown = () => {},
|
|
@@ -895,6 +941,7 @@ function FeelEditor({
|
|
|
895
941
|
language$1.bracketMatching(),
|
|
896
942
|
changeHandler,
|
|
897
943
|
autocomplete.closeBrackets(),
|
|
944
|
+
view.EditorView.contentAttributes.of(contentAttributes),
|
|
898
945
|
language$1.indentOnInput(),
|
|
899
946
|
keyHandler,
|
|
900
947
|
view.keymap.of([
|