@bpmn-io/feel-editor 1.3.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/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 {array<Variable>} [schema] array of child variables if the variable is a context or list
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();
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 {array<Variable>} [schema] array of child variables if the variable is a context or list
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmn-io/feel-editor",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Editor for FEEL expressions.",
5
5
  "files": [
6
6
  "dist"