@pega/cosmos-react-build 3.0.0-rc.3 → 3.0.0-rc.5

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.
Files changed (67) hide show
  1. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.d.ts.map +1 -1
  2. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.js +96 -37
  3. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.js.map +1 -1
  4. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.d.ts +2 -0
  5. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.d.ts.map +1 -1
  6. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.js +23 -10
  7. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.js.map +1 -1
  8. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.types.d.ts +8 -10
  9. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.types.d.ts.map +1 -1
  10. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.types.js.map +1 -1
  11. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.d.ts +3 -3
  12. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.d.ts.map +1 -1
  13. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.js +26 -21
  14. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.js.map +1 -1
  15. package/lib/components/ExpressionBuilder/ExpressionBuilder.js +1 -1
  16. package/lib/components/ExpressionBuilder/ExpressionBuilder.js.map +1 -1
  17. package/lib/components/ExpressionBuilder/ExpressionItem.d.ts.map +1 -1
  18. package/lib/components/ExpressionBuilder/ExpressionItem.js +3 -3
  19. package/lib/components/ExpressionBuilder/ExpressionItem.js.map +1 -1
  20. package/lib/components/LifeCycle/Category.d.ts.map +1 -1
  21. package/lib/components/LifeCycle/Category.js +1 -1
  22. package/lib/components/LifeCycle/Category.js.map +1 -1
  23. package/lib/components/LifeCycle/LifeCycle.d.ts +2 -0
  24. package/lib/components/LifeCycle/LifeCycle.d.ts.map +1 -1
  25. package/lib/components/LifeCycle/LifeCycle.js +13 -10
  26. package/lib/components/LifeCycle/LifeCycle.js.map +1 -1
  27. package/lib/components/LifeCycle/LifeCycle.types.d.ts +2 -0
  28. package/lib/components/LifeCycle/LifeCycle.types.d.ts.map +1 -1
  29. package/lib/components/LifeCycle/LifeCycle.types.js.map +1 -1
  30. package/lib/components/LifeCycle/LifeCycleContext.d.ts +7 -0
  31. package/lib/components/LifeCycle/LifeCycleContext.d.ts.map +1 -0
  32. package/lib/components/LifeCycle/LifeCycleContext.js +6 -0
  33. package/lib/components/LifeCycle/LifeCycleContext.js.map +1 -0
  34. package/lib/components/LifeCycle/LifeCycleList.d.ts.map +1 -1
  35. package/lib/components/LifeCycle/LifeCycleList.js +3 -3
  36. package/lib/components/LifeCycle/LifeCycleList.js.map +1 -1
  37. package/lib/components/LifeCycle/Stage.d.ts +7 -15
  38. package/lib/components/LifeCycle/Stage.d.ts.map +1 -1
  39. package/lib/components/LifeCycle/Stage.js +81 -128
  40. package/lib/components/LifeCycle/Stage.js.map +1 -1
  41. package/lib/components/LifeCycle/Step.d.ts +12 -16
  42. package/lib/components/LifeCycle/Step.d.ts.map +1 -1
  43. package/lib/components/LifeCycle/Step.js +80 -127
  44. package/lib/components/LifeCycle/Step.js.map +1 -1
  45. package/lib/components/LifeCycle/Task.d.ts +11 -15
  46. package/lib/components/LifeCycle/Task.d.ts.map +1 -1
  47. package/lib/components/LifeCycle/Task.js +64 -83
  48. package/lib/components/LifeCycle/Task.js.map +1 -1
  49. package/lib/components/MobileBuildSummary/MobileBuildSummary.d.ts +9 -0
  50. package/lib/components/MobileBuildSummary/MobileBuildSummary.d.ts.map +1 -0
  51. package/lib/components/MobileBuildSummary/MobileBuildSummary.js +44 -0
  52. package/lib/components/MobileBuildSummary/MobileBuildSummary.js.map +1 -0
  53. package/lib/components/MobileBuildSummary/MobileBuildSummary.types.d.ts +29 -0
  54. package/lib/components/MobileBuildSummary/MobileBuildSummary.types.d.ts.map +1 -0
  55. package/lib/components/MobileBuildSummary/MobileBuildSummary.types.js +2 -0
  56. package/lib/components/MobileBuildSummary/MobileBuildSummary.types.js.map +1 -0
  57. package/lib/components/MobileBuildSummary/index.d.ts +3 -0
  58. package/lib/components/MobileBuildSummary/index.d.ts.map +1 -0
  59. package/lib/components/MobileBuildSummary/index.js +2 -0
  60. package/lib/components/MobileBuildSummary/index.js.map +1 -0
  61. package/lib/components/Workbench/ConfigurationPanel.js +1 -1
  62. package/lib/components/Workbench/ConfigurationPanel.js.map +1 -1
  63. package/lib/index.d.ts +1 -0
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js +1 -0
  66. package/lib/index.js.map +1 -1
  67. package/package.json +3 -5
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAUf,OAAO,qCAAqC,CAAC;AAC7C,OAAO,oCAAoC,CAAC;AAE5C,OAAO,EAAkC,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvF,OAAO,EAEL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAuC5B,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CA8HjE,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAUf,OAAO,qCAAqC,CAAC;AAC7C,OAAO,oCAAoC,CAAC;AAE5C,OAAO,EAAkC,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvF,OAAO,EAEL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAyE5B,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAkKjE,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -11,23 +11,54 @@ import { StyledCodeEditor } from './CodeEditor.styles';
11
11
  import getCodeSuggestions from './getCodeSuggestions';
12
12
  defineMode('expression', () => {
13
13
  const tokens = [
14
- {
15
- token: /[a-zA-Z_$]*\.[\w$]+/,
16
- style: 'ex-properties'
17
- },
18
- {
19
- token: /(^@+)(\([\w.-]+:[\w.-]+\))*([\w.]+)(\s*)/,
20
- style: 'ex-functions'
21
- }
14
+ /* Below regex is used to identify the context */
15
+ { token: /\w+@/, style: 'ex-context' },
16
+ /* Below regex is used to identify the RuleType */
17
+ { token: /\w+:/, style: 'ex-context' },
18
+ /* Below regex is used to identify the RuleName */
19
+ { token: /\w+[(]/, style: 'ex-ruleName' },
20
+ /* Below regex is used to identify the delimeters */
21
+ { token: /[:.(),]/, style: 'ex-delimeter' },
22
+ /* Below regex is used to identify the operators */
23
+ { token: /[-+\\/*=<>@]+/, style: 'ex-operator' }
22
24
  ];
23
25
  return {
24
- token(stream) {
26
+ startState() {
27
+ return { inString: false };
28
+ },
29
+ token(stream, state) {
30
+ /* Used to identify the constants in the expression */
31
+ const nextChar = stream.peek();
32
+ if (!state.inString && (nextChar === "'" || nextChar === '"')) {
33
+ stream.next(); // Skip quote
34
+ state.inString = true; // Update state
35
+ }
36
+ if (state.inString) {
37
+ if (nextChar && stream.skipTo(nextChar)) {
38
+ // Quote found on this line
39
+ stream.next(); // Skip quote
40
+ state.inString = false; // Clear flag
41
+ }
42
+ else {
43
+ stream.skipToEnd(); // Rest of line is string
44
+ }
45
+ return nextChar === '"' ? 'ex-constant' : 'ex-context'; // Token style
46
+ }
47
+ if (stream.peek() === '.') {
48
+ stream.next();
49
+ if (stream.match(/.\w+\(/))
50
+ return 'ex-delimeter';
51
+ }
52
+ /* Used to match the regex in the expression */
25
53
  // eslint-disable-next-line no-restricted-syntax
26
54
  for (const element of tokens) {
27
- if (stream.match('#') || stream.match('//'))
28
- stream.skipToEnd();
29
- else if (stream.match(element.token))
55
+ const match = stream.match(element.token, false);
56
+ if (match) {
57
+ if (stream.pos === stream.start) {
58
+ stream.next();
59
+ }
30
60
  return element.style;
61
+ }
31
62
  }
32
63
  stream.next();
33
64
  return null;
@@ -44,9 +75,10 @@ const CodeEditor = forwardRef(({ fetchSuggestions, autoCompleteTriggers, editorC
44
75
  const [value, setCode] = useState(defaultValue);
45
76
  const [suggestions, setSuggestions] = useState([]);
46
77
  const [codeMirror, setCodeMirror] = useState(null);
47
- const [autoCompleteTrigger, setAutoCompleteTrigger] = useState('');
48
78
  const [codeEditorContainer, setCodeEditorContainer] = useElement();
49
79
  const codeEditorConsolidatedRef = useConsolidatedRef(setCodeEditorContainer, ref);
80
+ const [suggestionTrigger, setSuggestionTrigger] = useState(null);
81
+ const [popover, showPopover] = useState(false);
50
82
  const mounted = useRef(false);
51
83
  useImperativeHandle(codeEditorHandle, () => ({
52
84
  insertText: (text) => {
@@ -67,7 +99,7 @@ const CodeEditor = forwardRef(({ fetchSuggestions, autoCompleteTriggers, editorC
67
99
  suggestions,
68
100
  container: codeEditorContainer,
69
101
  loading,
70
- autoCompleteTrigger
102
+ triggerCharacterCursorPos: suggestionTrigger?.cursorPosition
71
103
  };
72
104
  showHint(codeEditor, getCodeSuggestions, hintOptions);
73
105
  };
@@ -75,35 +107,62 @@ const CodeEditor = forwardRef(({ fetchSuggestions, autoCompleteTriggers, editorC
75
107
  setCode(textvalue);
76
108
  onChange?.(textvalue);
77
109
  const currentCursor = editor.getCursor();
78
- const textTillCursorPos = editor.getValue().split('\n')[currentCursor.line];
79
- let start = textTillCursorPos?.lastIndexOf(' ');
80
- if (start === -1) {
81
- start = 0;
82
- }
83
- const currentWord = textTillCursorPos.substring(start, currentCursor.ch);
84
- /* Below regex is used to find the query token which is present before the triggering character
85
- to send update list. */
86
- const regexp = /[\w$]*(\.+[\w$)(\][]*)+/g;
87
- const tokenArray = [...currentWord.matchAll(regexp)];
88
- const autoCompleteTriggerChar = editor.getTokenAt(currentCursor)
89
- .string;
90
- if (!codeMirror?.getTokenAt(codeMirror.getCursor()).string.includes(autoCompleteTrigger))
91
- setSuggestions([]);
92
- if (autoCompleteTriggers?.includes(autoCompleteTriggerChar) && fetchSuggestions) {
93
- setAutoCompleteTrigger(autoCompleteTriggerChar);
94
- const newSuggestions = [
95
- ...(await fetchSuggestions(autoCompleteTriggerChar, tokenArray.length === 0 ? '' : tokenArray[tokenArray.length - 1][0]))
96
- ];
97
- if (mounted.current)
110
+ const currentCharacter = editor.getTokenAt(currentCursor).string;
111
+ let newSuggestions = [];
112
+ if (autoCompleteTriggers?.includes(currentCharacter) && fetchSuggestions) {
113
+ setSuggestionTrigger({
114
+ character: currentCharacter,
115
+ cursorPosition: currentCursor
116
+ });
117
+ /* Used to find the query token which is present before the triggering character
118
+ to get updated list. */
119
+ const textTillCursorPos = editor.getValue().split('\n')[currentCursor.line];
120
+ let start = textTillCursorPos?.lastIndexOf(' ');
121
+ if (start === -1) {
122
+ start = 0;
123
+ }
124
+ const currentWord = textTillCursorPos.substring(start, currentCursor.ch);
125
+ let regexp;
126
+ if (currentCharacter === '.') {
127
+ regexp = /[\w$]*(\.+[\w$)[\](]*)+/g;
128
+ }
129
+ else {
130
+ regexp = /[\w@'-]*[@:]/g;
131
+ }
132
+ const tokenArray = [...currentWord.matchAll(regexp)];
133
+ let queryToken = '';
134
+ if (tokenArray.length > 0) {
135
+ const queryString = tokenArray[tokenArray.length - 1][0];
136
+ queryToken = queryString.substring(0, queryString.length - 1);
137
+ }
138
+ newSuggestions = [...(await fetchSuggestions(currentCharacter, queryToken))];
139
+ if (mounted.current) {
98
140
  setSuggestions(newSuggestions);
141
+ }
99
142
  }
100
143
  };
101
144
  useEffect(() => {
102
- if (codeMirror && ((suggestions.length > 0 && value.length > 0) || loading)) {
145
+ if (!popover)
146
+ return;
147
+ const isSuggestionTriggerPresent = suggestionTrigger &&
148
+ codeMirror
149
+ ?.getTokenAt(suggestionTrigger.cursorPosition)
150
+ .string.includes(suggestionTrigger.character);
151
+ if (!isSuggestionTriggerPresent) {
152
+ codeMirror?.closeHint();
153
+ showPopover(false);
154
+ setSuggestionTrigger(null);
155
+ }
156
+ }, [onBeforeChange]);
157
+ useEffect(() => {
158
+ if (codeMirror && (suggestionTrigger || loading)) {
103
159
  autoComplete(codeMirror);
160
+ showPopover(true);
104
161
  }
105
- else
162
+ else {
106
163
  codeMirror?.closeHint();
164
+ showPopover(false);
165
+ }
107
166
  }, [suggestions, loading]);
108
167
  useEffect(() => {
109
168
  mounted.current = true;
@@ -116,7 +175,7 @@ const CodeEditor = forwardRef(({ fetchSuggestions, autoCompleteTriggers, editorC
116
175
  justify: 'between'
117
176
  }, item: {
118
177
  grow: 1
119
- }, ref: codeEditorConsolidatedRef, errors: errors, readOnly: readOnly, isLoading: loading, ...props, children: [_jsx(ReactCodeMirror, { value: value, onBeforeChange: onBeforeChange, options: { ...defaultConfigOptions, ...editorConfigProps }, editorDidMount: editor => {
178
+ }, ref: codeEditorConsolidatedRef, errors: errors, readOnly: readOnly, isLoading: loading, suggestions: suggestions, ...props, children: [_jsx(ReactCodeMirror, { value: value, onBeforeChange: onBeforeChange, options: { ...defaultConfigOptions, ...editorConfigProps }, editorDidMount: editor => {
120
179
  editor.setSize('100%', '100%');
121
180
  setCodeMirror(editor);
122
181
  } }), errors && _jsx(StyledFormFieldInfo, { status: 'error', children: errors })] }));
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":";AAAA,uBAAuB;AACvB,OAAO,EACL,UAAU,EAGV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,mBAAmB,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,IAAI,eAAe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CAAC,EAAE;oBACvB,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;oBAC/B,aAAa,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC,GACD,EACD,MAAM,IAAI,KAAC,mBAAmB,IAAC,MAAM,EAAC,OAAO,YAAE,MAAM,GAAuB,IAC5D,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["// cSpell:words unfocus\nimport {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useRef,\n useState,\n useEffect,\n useImperativeHandle\n} from 'react';\nimport { Controlled as ReactCodeMirror } from 'react-codemirror2';\nimport {\n showHint,\n defineMode,\n Editor,\n Position,\n EditorChange,\n EditorConfiguration\n} from 'codemirror';\nimport 'codemirror/addon/edit/closebrackets';\nimport 'codemirror/addon/hint/show-hint.js';\n\nimport { useConsolidatedRef, useElement, ForwardProps } from '@pega/cosmos-react-core';\nimport { StyledFormFieldInfo } from '@pega/cosmos-react-core/lib/components/FormField/FormField';\n\nimport {\n AutoCompleteTriggerType,\n CodeEditorProps,\n EditorState,\n SuggestionsType\n} from './CodeEditor.types';\nimport { StyledCodeEditor } from './CodeEditor.styles';\nimport getCodeSuggestions from './getCodeSuggestions';\n\ndefineMode('expression', () => {\n const tokens = [\n {\n token: /[a-zA-Z_$]*\\.[\\w$]+/,\n style: 'ex-properties'\n },\n {\n token: /(^@+)(\\([\\w.-]+:[\\w.-]+\\))*([\\w.]+)(\\s*)/,\n style: 'ex-functions'\n }\n ];\n\n return {\n token(stream) {\n // eslint-disable-next-line no-restricted-syntax\n for (const element of tokens) {\n if (stream.match('#') || stream.match('//')) stream.skipToEnd();\n else if (stream.match(element.token)) return element.style;\n }\n stream.next();\n return null;\n }\n };\n});\n\nconst defaultConfigOptions: Pick<\n EditorConfiguration,\n 'lineWrapping' | 'smartIndent' | 'autoCloseBrackets' | 'extraKeys'\n> = {\n lineWrapping: true,\n smartIndent: true,\n autoCloseBrackets: true,\n extraKeys: { Tab: false, 'Shift-Tab': false }\n};\n\nconst CodeEditor: FunctionComponent<CodeEditorProps & ForwardProps> = forwardRef(\n (\n {\n fetchSuggestions,\n autoCompleteTriggers,\n editorConfigProps,\n codeEditorHandle,\n defaultValue = '',\n loading = false,\n readOnly,\n errors,\n onChange,\n ...props\n }: PropsWithoutRef<CodeEditorProps>,\n ref: CodeEditorProps['ref']\n ) => {\n const [value, setCode] = useState<string>(defaultValue);\n const [suggestions, setSuggestions] = useState<SuggestionsType[]>([]);\n const [codeMirror, setCodeMirror] = useState<Editor | null>(null);\n const [autoCompleteTrigger, setAutoCompleteTrigger] = useState('');\n const [codeEditorContainer, setCodeEditorContainer] = useElement<HTMLDivElement>();\n const codeEditorConsolidatedRef = useConsolidatedRef(setCodeEditorContainer, ref);\n const mounted = useRef(false);\n\n useImperativeHandle<any, EditorState>(\n codeEditorHandle,\n () => ({\n insertText: (text: string) => {\n if (codeMirror) {\n const cur: Position = codeMirror.getCursor();\n codeMirror.replaceRange(text, cur);\n }\n },\n getValue: () => {\n return codeMirror?.getValue();\n }\n }),\n [codeMirror]\n );\n\n const autoComplete = (codeEditor: Editor) => {\n const hintOptions = {\n completeSingle: false,\n completeOnSingleClick: true,\n closeOnUnfocus: true,\n suggestions,\n container: codeEditorContainer,\n loading,\n autoCompleteTrigger\n };\n showHint(codeEditor, getCodeSuggestions, hintOptions);\n };\n\n const onBeforeChange = async (editor: Editor, _data: EditorChange, textvalue: string) => {\n setCode(textvalue);\n onChange?.(textvalue);\n const currentCursor = editor.getCursor();\n const textTillCursorPos = editor.getValue().split('\\n')[currentCursor.line];\n let start = textTillCursorPos?.lastIndexOf(' ');\n if (start === -1) {\n start = 0;\n }\n const currentWord = textTillCursorPos.substring(start, currentCursor.ch);\n /* Below regex is used to find the query token which is present before the triggering character\n to send update list. */\n const regexp = /[\\w$]*(\\.+[\\w$)(\\][]*)+/g;\n const tokenArray = [...currentWord.matchAll(regexp)];\n const autoCompleteTriggerChar = editor.getTokenAt(currentCursor)\n .string as AutoCompleteTriggerType;\n\n if (!codeMirror?.getTokenAt(codeMirror.getCursor()).string.includes(autoCompleteTrigger))\n setSuggestions([]);\n\n if (autoCompleteTriggers?.includes(autoCompleteTriggerChar) && fetchSuggestions) {\n setAutoCompleteTrigger(autoCompleteTriggerChar);\n const newSuggestions = [\n ...(await fetchSuggestions(\n autoCompleteTriggerChar,\n tokenArray.length === 0 ? '' : tokenArray[tokenArray.length - 1][0]\n ))\n ];\n if (mounted.current) setSuggestions(newSuggestions);\n }\n };\n\n useEffect(() => {\n if (codeMirror && ((suggestions.length > 0 && value.length > 0) || loading)) {\n autoComplete(codeMirror);\n } else codeMirror?.closeHint();\n }, [suggestions, loading]);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n return (\n <StyledCodeEditor\n container={{\n direction: 'column',\n justify: 'between'\n }}\n item={{\n grow: 1\n }}\n ref={codeEditorConsolidatedRef}\n errors={errors}\n readOnly={readOnly}\n isLoading={loading}\n {...props}\n >\n <ReactCodeMirror\n value={value}\n onBeforeChange={onBeforeChange}\n options={{ ...defaultConfigOptions, ...editorConfigProps }}\n editorDidMount={editor => {\n editor.setSize('100%', '100%');\n setCodeMirror(editor);\n }}\n />\n {errors && <StyledFormFieldInfo status='error'>{errors}</StyledFormFieldInfo>}\n </StyledCodeEditor>\n );\n }\n);\n\nexport default CodeEditor;\n"]}
1
+ {"version":3,"file":"CodeEditor.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":";AAAA,uBAAuB;AACvB,OAAO,EACL,UAAU,EAGV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,mBAAmB,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACL,QAAQ,EACR,UAAU,EAKX,MAAM,YAAY,CAAC;AACpB,OA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,CAAC;SACpB;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,MAAC,gBAAgB,IACf,SAAS,EAAE;YACT,SAAS,EAAE,QAAQ;YACnB,OAAO,EAAE,SAAS;SACnB,EACD,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC;SACR,EACD,GAAG,EAAE,yBAAyB,EAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,OAAO,EAClB,WAAW,EAAE,WAAW,KACpB,KAAK,aAET,KAAC,eAAe,IACd,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,EAAE,GAAG,oBAAoB,EAAE,GAAG,iBAAiB,EAAE,EAC1D,cAAc,EAAE,MAAM,CAAC,EAAE;oBACvB,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;oBAC/B,aAAa,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC,GACD,EACD,MAAM,IAAI,KAAC,mBAAmB,IAAC,MAAM,EAAC,OAAO,YAAE,MAAM,GAAuB,IAC5D,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["// cSpell:words unfocus\nimport {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useRef,\n useState,\n useEffect,\n useImperativeHandle\n} from 'react';\nimport { Controlled as ReactCodeMirror } from 'react-codemirror2';\nimport {\n showHint,\n defineMode,\n Editor,\n Position,\n EditorChange,\n EditorConfiguration\n} from 'codemirror';\nimport 'codemirror/addon/edit/closebrackets';\nimport 'codemirror/addon/hint/show-hint.js';\n\nimport { useConsolidatedRef, useElement, ForwardProps } from '@pega/cosmos-react-core';\nimport { StyledFormFieldInfo } from '@pega/cosmos-react-core/lib/components/FormField/FormField';\n\nimport {\n AutoCompleteTriggerChar,\n CodeEditorProps,\n EditorState,\n SuggestionType\n} from './CodeEditor.types';\nimport { StyledCodeEditor } from './CodeEditor.styles';\nimport getCodeSuggestions from './getCodeSuggestions';\n\ndefineMode('expression', () => {\n const tokens = [\n /* Below regex is used to identify the context */\n { token: /\\w+@/, style: 'ex-context' },\n /* Below regex is used to identify the RuleType */\n { token: /\\w+:/, style: 'ex-context' },\n /* Below regex is used to identify the RuleName */\n { token: /\\w+[(]/, style: 'ex-ruleName' },\n /* Below regex is used to identify the delimeters */\n { token: /[:.(),]/, style: 'ex-delimeter' },\n /* Below regex is used to identify the operators */\n { token: /[-+\\\\/*=<>@]+/, style: 'ex-operator' }\n ];\n\n return {\n startState() {\n return { inString: false };\n },\n token(stream, state) {\n /* Used to identify the constants in the expression */\n const nextChar = stream.peek();\n if (!state.inString && (nextChar === \"'\" || nextChar === '\"')) {\n stream.next(); // Skip quote\n state.inString = true; // Update state\n }\n\n if (state.inString) {\n if (nextChar && stream.skipTo(nextChar)) {\n // Quote found on this line\n stream.next(); // Skip quote\n state.inString = false; // Clear flag\n } else {\n stream.skipToEnd(); // Rest of line is string\n }\n return nextChar === '\"' ? 'ex-constant' : 'ex-context'; // Token style\n }\n\n if (stream.peek() === '.') {\n stream.next();\n if (stream.match(/.\\w+\\(/)) return 'ex-delimeter';\n }\n\n /* Used to match the regex in the expression */\n // eslint-disable-next-line no-restricted-syntax\n for (const element of tokens) {\n const match = stream.match(element.token, false);\n if (match) {\n if (stream.pos === stream.start) {\n stream.next();\n }\n return element.style;\n }\n }\n stream.next();\n return null;\n }\n };\n});\n\nconst defaultConfigOptions: Pick<\n EditorConfiguration,\n 'lineWrapping' | 'smartIndent' | 'autoCloseBrackets' | 'extraKeys'\n> = {\n lineWrapping: true,\n smartIndent: true,\n autoCloseBrackets: true,\n extraKeys: { Tab: false, 'Shift-Tab': false }\n};\n\nconst CodeEditor: FunctionComponent<CodeEditorProps & ForwardProps> = forwardRef(\n (\n {\n fetchSuggestions,\n autoCompleteTriggers,\n editorConfigProps,\n codeEditorHandle,\n defaultValue = '',\n loading = false,\n readOnly,\n errors,\n onChange,\n ...props\n }: PropsWithoutRef<CodeEditorProps>,\n ref: CodeEditorProps['ref']\n ) => {\n const [value, setCode] = useState<string>(defaultValue);\n const [suggestions, setSuggestions] = useState<SuggestionType[]>([]);\n const [codeMirror, setCodeMirror] = useState<Editor | null>(null);\n const [codeEditorContainer, setCodeEditorContainer] = useElement<HTMLDivElement>();\n const codeEditorConsolidatedRef = useConsolidatedRef(setCodeEditorContainer, ref);\n const [suggestionTrigger, setSuggestionTrigger] = useState<{\n character: AutoCompleteTriggerChar;\n cursorPosition: Position;\n } | null>(null);\n const [popover, showPopover] = useState(false);\n const mounted = useRef(false);\n\n useImperativeHandle<any, EditorState>(\n codeEditorHandle,\n () => ({\n insertText: (text: string) => {\n if (codeMirror) {\n const cur: Position = codeMirror.getCursor();\n codeMirror.replaceRange(text, cur);\n }\n },\n getValue: () => {\n return codeMirror?.getValue();\n }\n }),\n [codeMirror]\n );\n\n const autoComplete = (codeEditor: Editor) => {\n const hintOptions = {\n completeSingle: false,\n completeOnSingleClick: true,\n closeOnUnfocus: true,\n suggestions,\n container: codeEditorContainer,\n loading,\n triggerCharacterCursorPos: suggestionTrigger?.cursorPosition\n };\n showHint(codeEditor, getCodeSuggestions, hintOptions);\n };\n\n const onBeforeChange = async (editor: Editor, _data: EditorChange, textvalue: string) => {\n setCode(textvalue);\n onChange?.(textvalue);\n const currentCursor = editor.getCursor();\n const currentCharacter = editor.getTokenAt(currentCursor).string as AutoCompleteTriggerChar;\n\n let newSuggestions: SuggestionType[] = [];\n\n if (autoCompleteTriggers?.includes(currentCharacter) && fetchSuggestions) {\n setSuggestionTrigger({\n character: currentCharacter,\n cursorPosition: currentCursor\n });\n\n /* Used to find the query token which is present before the triggering character\n to get updated list. */\n const textTillCursorPos = editor.getValue().split('\\n')[currentCursor.line];\n let start = textTillCursorPos?.lastIndexOf(' ');\n if (start === -1) {\n start = 0;\n }\n const currentWord = textTillCursorPos.substring(start, currentCursor.ch);\n\n let regexp;\n if (currentCharacter === '.') {\n regexp = /[\\w$]*(\\.+[\\w$)[\\](]*)+/g;\n } else {\n regexp = /[\\w@'-]*[@:]/g;\n }\n\n const tokenArray = [...currentWord.matchAll(regexp)];\n let queryToken = '';\n if (tokenArray.length > 0) {\n const queryString = tokenArray[tokenArray.length - 1][0];\n queryToken = queryString.substring(0, queryString.length - 1);\n }\n\n newSuggestions = [...(await fetchSuggestions(currentCharacter, queryToken))];\n if (mounted.current) {\n setSuggestions(newSuggestions);\n }\n }\n };\n\n useEffect(() => {\n if (!popover) return;\n const isSuggestionTriggerPresent =\n suggestionTrigger &&\n codeMirror\n ?.getTokenAt(suggestionTrigger.cursorPosition)\n .string.includes(suggestionTrigger.character);\n\n if (!isSuggestionTriggerPresent) {\n codeMirror?.closeHint();\n showPopover(false);\n setSuggestionTrigger(null);\n }\n }, [onBeforeChange]);\n\n useEffect(() => {\n if (codeMirror && (suggestionTrigger || loading)) {\n autoComplete(codeMirror);\n showPopover(true);\n } else {\n codeMirror?.closeHint();\n showPopover(false);\n }\n }, [suggestions, loading]);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n return (\n <StyledCodeEditor\n container={{\n direction: 'column',\n justify: 'between'\n }}\n item={{\n grow: 1\n }}\n ref={codeEditorConsolidatedRef}\n errors={errors}\n readOnly={readOnly}\n isLoading={loading}\n suggestions={suggestions}\n {...props}\n >\n <ReactCodeMirror\n value={value}\n onBeforeChange={onBeforeChange}\n options={{ ...defaultConfigOptions, ...editorConfigProps }}\n editorDidMount={editor => {\n editor.setSize('100%', '100%');\n setCodeMirror(editor);\n }}\n />\n {errors && <StyledFormFieldInfo status='error'>{errors}</StyledFormFieldInfo>}\n </StyledCodeEditor>\n );\n }\n);\n\nexport default CodeEditor;\n"]}
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
+ import { SuggestionType } from './CodeEditor.types';
2
3
  export declare const StyledLoading: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
3
4
  export declare const StyledCodeEditor: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").FlexProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {
4
5
  isLoading?: boolean | undefined;
5
6
  errors?: string | undefined;
6
7
  readOnly?: boolean | undefined;
8
+ suggestions: SuggestionType[];
7
9
  }, never>;
8
10
  //# sourceMappingURL=CodeEditor.styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.ts"],"names":[],"mappings":";AAOA,eAAO,MAAM,aAAa,yGAEzB,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;SAihB5B,CAAC"}
1
+ {"version":3,"file":"CodeEditor.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,eAAO,MAAM,aAAa,yGAEzB,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;iBAId,cAAc,EAAE;SA4hB9B,CAAC"}
@@ -6,7 +6,7 @@ import { StyledFormField } from '@pega/cosmos-react-core/lib/components/FormFiel
6
6
  export const StyledLoading = styled.div `
7
7
  font-size: 1.5rem;
8
8
  `;
9
- export const StyledCodeEditor = styled(Flex)(({ theme: { base, components: { 'form-control': { ':read-only': { 'background-color': readOnlyBackgroundColor } }, 'form-field': { error: { 'status-color': errorBackground } } } }, errors, isLoading, readOnly }) => {
9
+ export const StyledCodeEditor = styled(Flex)(({ theme: { base, components: { 'form-control': { ':read-only': { 'background-color': readOnlyBackgroundColor } }, 'form-field': { error: { 'status-color': errorBackground } } } }, errors, isLoading, suggestions, readOnly }) => {
10
10
  const activeColor = mix(0.85, base.palette['primary-background'], base.palette.interactive);
11
11
  const hoverColor = mix(0.95, base.palette['primary-background'], base.palette.interactive);
12
12
  const fontSizes = calculateFontSize(base['font-size'], base['font-scale']);
@@ -462,12 +462,24 @@ export const StyledCodeEditor = styled(Flex)(({ theme: { base, components: { 'fo
462
462
  background-color: ${readOnlyBackgroundColor};
463
463
  `}
464
464
  }
465
- .cm-ex-properties {
466
- color: ${base.palette.success};
465
+
466
+ .cm-ex-context {
467
+ color: ${base.palette['brand-primary']};
467
468
  }
468
- .cm-ex-functions {
469
+ .cm-ex-operator {
469
470
  color: ${base.palette.warn};
471
+ font-weight: bold;
472
+ }
473
+ .cm-ex-ruleName {
474
+ color: ${base.palette.success};
470
475
  }
476
+ .cm-ex-delimeter {
477
+ color: ${base.palette['foreground-color']};
478
+ }
479
+ .cm-ex-constant {
480
+ color: ${base.palette.pending};
481
+ }
482
+
471
483
  .CodeMirror-hints {
472
484
  position: absolute;
473
485
  z-index: 10;
@@ -478,23 +490,23 @@ export const StyledCodeEditor = styled(Flex)(({ theme: { base, components: { 'fo
478
490
  border: 0.0625rem solid ${base.palette['border-line']};
479
491
  background-color: ${base.palette['primary-background']};
480
492
  font-size: ${fontSizes.s};
481
- font-family: monospace;
482
- max-height: 10em;
493
+ max-height: 12rem;
483
494
  overflow-y: auto;
484
495
  min-width: 8rem;
485
496
  }
486
497
 
487
498
  .CodeMirror-hint {
488
- ${isLoading &&
499
+ ${(isLoading || suggestions?.length === 0) &&
489
500
  css `
490
501
  pointer-events: none;
491
502
  `}
492
- min-height: ${base['hit-area']['compact-min']};
503
+ min-height: 1.2rem;
504
+ width: calc(1.5 * ${base['content-width'].xs});
493
505
  cursor: pointer;
494
506
  @media (pointer: coarse) {
495
- min-height: ${base['hit-area']['compact-min']};
507
+ min-height: 1.2rem;
496
508
  }
497
- line-height: ${base['hit-area']['compact-min']};
509
+ line-height: 1.2rem;
498
510
  &:focus-within {
499
511
  background-color: ${activeColor};
500
512
  }
@@ -507,6 +519,7 @@ export const StyledCodeEditor = styled(Flex)(({ theme: { base, components: { 'fo
507
519
 
508
520
  li.CodeMirror-hint-active {
509
521
  ${!isLoading &&
522
+ suggestions?.length > 0 &&
510
523
  css `
511
524
  background-color: ${activeColor};
512
525
  `}
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.styles.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,4DAA4D,CAAC;AAE7F,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAA;;CAEtC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAK1C,CAAC,EACC,KAAK,EAAE,EACL,IAAI,EACJ,UAAU,EAAE,EACV,cAAc,EAAE,EACd,YAAY,EAAE,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,EAC9D,EACD,YAAY,EAAE,EACZ,KAAK,EAAE,EAAE,cAAc,EAAE,eAAe,EAAE,EAC3C,EACF,EACF,EACD,MAAM,EACN,SAAS,EACT,QAAQ,EACT,EAAE,EAAE;IACH,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE5F,MAAM,UAAU,G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I,CAAC,OAAO,CAAC,OAAO;;;iBAGpB,IAAI,CAAC,OAAO,CAAC,IAAI;;;;;6BAKL,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI;;oCAE3C,IAAI,CAAC,eAAe,CAAC;sBACnC,IAAI,CAAC,MAAM,CAAC,GAAG;kCACH,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;4BACjC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;qBACzC,SAAS,CAAC,CAAC;;;;;;;;UAQtB,SAAS;QACX,GAAG,CAAA;;SAEF;sBACa,IAAI,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC;;;wBAG7B,IAAI,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC;;uBAEhC,IAAI,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC;;8BAExB,WAAW;;;;8BAIX,UAAU;;0BAEd,IAAI,CAAC,OAAO;;;;UAI5B,CAAC,SAAS;QACZ,GAAG,CAAA;8BACmB,WAAW;SAChC;;KAEJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["// cSpell:words vscrollbar hscrollbar\nimport styled, { css } from 'styled-components';\nimport { mix } from 'polished';\n\nimport { defaultThemeProp, calculateFontSize, Flex } from '@pega/cosmos-react-core';\nimport { StyledFormField } from '@pega/cosmos-react-core/lib/components/FormField/FormField';\n\nexport const StyledLoading = styled.div`\n font-size: 1.5rem;\n`;\n\nexport const StyledCodeEditor = styled(Flex)<{\n isLoading?: boolean;\n errors?: string;\n readOnly?: boolean;\n}>(\n ({\n theme: {\n base,\n components: {\n 'form-control': {\n ':read-only': { 'background-color': readOnlyBackgroundColor }\n },\n 'form-field': {\n error: { 'status-color': errorBackground }\n }\n }\n },\n errors,\n isLoading,\n readOnly\n }) => {\n const activeColor = mix(0.85, base.palette['primary-background'], base.palette.interactive);\n\n const hoverColor = mix(0.95, base.palette['primary-background'], base.palette.interactive);\n\n const fontSizes = calculateFontSize(base['font-size'], base['font-scale']);\n return css`\n position: relative;\n max-height: 100%;\n overflow-y: auto;\n ${StyledFormField} {\n flex-grow: 1;\n }\n\n /* PADDING */\n .react-codemirror2 {\n flex-grow: 1;\n min-height: 3.75rem;\n overflow-y: auto;\n ${readOnly &&\n css`\n max-height: 5.625rem;\n `}\n }\n\n .CodeMirror-lines {\n cursor: text;\n min-height: 0.063rem; /* prevents collapsing before first draw */\n padding: ${base.spacing};\n }\n\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n background-color: white; /* The little square between H and V scrollbars */\n }\n\n /* GUTTER */\n\n .CodeMirror-gutters {\n position: absolute;\n left: 0;\n top: 0;\n min-height: 100%;\n z-index: 3;\n border-right: 0.063rem solid #dddddd;\n background-color: #f7f7f7;\n white-space: nowrap;\n }\n .CodeMirror-linenumber {\n padding: 0 0.125rem 0 0.313rem;\n min-width: 1.25rem;\n text-align: right;\n color: #999999;\n white-space: nowrap;\n }\n\n .CodeMirror-guttermarker {\n color: black;\n }\n .CodeMirror-guttermarker-subtle {\n color: #999999;\n }\n\n /* CURSOR */\n\n .CodeMirror-cursor {\n position: absolute;\n pointer-events: none;\n border-left: 0.0625rem solid ${base.palette.dark};\n border-right: none;\n width: 0;\n ${readOnly &&\n css`\n display: none;\n `}\n }\n\n /* Shown when moving in bi-directional text */\n .CodeMirror div.CodeMirror-secondarycursor {\n border-left: 0.063rem solid silver;\n }\n .cm-fat-cursor-mark {\n background-color: rgba(20, 255, 20, 0.5);\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n }\n .cm-animate-fat-cursor {\n width: auto;\n border: 0;\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n background-color: #77ee77;\n }\n @-moz-keyframes blink {\n 50% {\n background-color: transparent;\n }\n }\n @-webkit-keyframes blink {\n 50% {\n background-color: transparent;\n }\n }\n @keyframes blink {\n 50% {\n background-color: transparent;\n }\n }\n\n .cm-tab {\n display: inline-block;\n text-decoration: inherit;\n }\n\n .CodeMirror-rulers {\n position: absolute;\n left: 0;\n right: 0;\n top: -3.125rem;\n bottom: 0;\n overflow: hidden;\n }\n .CodeMirror-ruler {\n border-left: 0.063rem solid #cccccc;\n top: 0;\n bottom: 0;\n position: absolute;\n }\n\n /* DEFAULT THEME */\n\n .cm-s-default .cm-header {\n color: blue;\n }\n .cm-negative {\n color: #dd4444;\n }\n .cm-positive {\n color: #229922;\n }\n .cm-strong {\n font-weight: bold;\n }\n .cm-s-default .cm-quote {\n color: #009900;\n }\n .cm-em {\n font-style: italic;\n }\n .cm-link {\n text-decoration: underline;\n }\n .cm-strikethrough {\n text-decoration: line-through;\n }\n\n .cm-s-default .cm-keyword {\n color: #770088;\n }\n .cm-s-default .cm-atom {\n color: #221199;\n }\n .cm-s-default .cm-number {\n color: #116644;\n }\n .cm-s-default .cm-def {\n color: #0000ff;\n }\n .cm-s-default .cm-variable-2 {\n color: #0055aa;\n }\n .cm-s-default .cm-variable-3,\n .cm-s-default .cm-type {\n color: #008855;\n }\n .cm-s-default .cm-comment {\n color: #aa5500;\n }\n .cm-s-default .cm-string {\n color: #aa1111;\n }\n .cm-s-default .cm-string-2 {\n color: #ff5500;\n }\n .cm-s-default .cm-meta {\n color: #555555;\n }\n .cm-s-default .cm-qualifier {\n color: #555555;\n }\n .cm-s-default .cm-builtin {\n color: #3300aa;\n }\n .cm-s-default .cm-bracket {\n color: #999977;\n }\n .cm-s-default .cm-tag {\n color: #117700;\n }\n .cm-s-default .cm-attribute {\n color: #0000cc;\n }\n .cm-s-default .cm-hr {\n color: #999999;\n }\n .cm-s-default .cm-link {\n color: #0000cc;\n }\n\n .cm-s-default .cm-error {\n color: #ff0000;\n }\n .cm-invalidchar {\n color: #ff0000;\n }\n\n .CodeMirror-composing {\n border-bottom: 0.125rem solid;\n }\n\n /* Default styles for common addons */\n\n div.CodeMirror span.CodeMirror-matchingbracket {\n color: #00bb00;\n }\n div.CodeMirror span.CodeMirror-nonmatchingbracket {\n color: #aa2222;\n }\n .CodeMirror-matchingtag {\n background: rgba(255, 150, 0, 0.3);\n }\n .CodeMirror-activeline-background {\n background: #e8f2ff;\n }\n\n /* STOP */\n\n /* The rest of this file contains styles related to the mechanics of\n the editor. You probably shouldn't touch them. */\n\n .CodeMirror-scroll {\n overflow: scroll !important;\n margin-bottom: -3.125rem;\n margin-right: -3.125rem;\n padding-bottom: 3.125rem;\n height: 100%;\n outline: none; /* Prevent dragging from highlighting the element */\n position: relative;\n }\n .CodeMirror-sizer {\n position: relative;\n border-right: 3.125rem solid transparent;\n }\n\n /* The fake, visible scrollbars. Used to force redraw during scrolling\n before actual scrolling happens, thus preventing shaking and\n flickering artifacts. */\n .CodeMirror-vscrollbar,\n .CodeMirror-hscrollbar,\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n position: absolute;\n z-index: 6;\n display: none;\n }\n .CodeMirror-vscrollbar {\n right: 0;\n top: 0;\n overflow-x: hidden;\n overflow-y: scroll;\n }\n .CodeMirror-hscrollbar {\n bottom: 0;\n left: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n }\n .CodeMirror-scrollbar-filler {\n right: 0;\n bottom: 0;\n }\n .CodeMirror-gutter-filler {\n left: 0;\n bottom: 0;\n }\n .CodeMirror-gutter {\n white-space: normal;\n height: 100%;\n display: inline-block;\n vertical-align: top;\n margin-bottom: -3.125rem;\n }\n .CodeMirror-gutter-wrapper {\n position: absolute;\n z-index: 4;\n background: none !important;\n border: none !important;\n }\n .CodeMirror-gutter-background {\n position: absolute;\n top: 0;\n bottom: 0;\n z-index: 4;\n }\n .CodeMirror-gutter-elt {\n position: absolute;\n cursor: default;\n z-index: 4;\n }\n .CodeMirror-gutter-wrapper ::selection {\n background-color: transparent;\n }\n .CodeMirror-gutter-wrapper ::-moz-selection {\n background-color: transparent;\n }\n\n .CodeMirror pre.CodeMirror-line,\n .CodeMirror pre.CodeMirror-line-like {\n /* Reset some styles that the rest of the page might have set */\n -moz-border-radius: 0;\n -webkit-border-radius: 0;\n border-radius: 0;\n border-width: 0;\n background: transparent;\n font-family: inherit;\n font-size: inherit;\n margin: 0;\n white-space: pre;\n word-wrap: normal;\n line-height: inherit;\n color: inherit;\n z-index: 2;\n position: relative;\n overflow: visible;\n -webkit-tap-highlight-color: transparent;\n -webkit-font-variant-ligatures: contextual;\n font-variant-ligatures: contextual;\n }\n .CodeMirror-wrap pre.CodeMirror-line,\n .CodeMirror-wrap pre.CodeMirror-line-like {\n word-wrap: break-word;\n white-space: pre-wrap;\n word-break: normal;\n }\n\n .CodeMirror-linebackground {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n z-index: 0;\n }\n\n .CodeMirror-linewidget {\n position: relative;\n z-index: 2;\n padding: 0.006rem; /* Force widget margins to stay inside of the container */\n }\n\n .CodeMirror-rtl pre {\n direction: rtl;\n }\n\n .CodeMirror-code {\n outline: none;\n }\n\n /* Force content-box sizing for the elements where we expect it */\n .CodeMirror-scroll,\n .CodeMirror-sizer,\n .CodeMirror-gutter,\n .CodeMirror-linenumber {\n -moz-box-sizing: content-box;\n box-sizing: content-box;\n }\n\n .CodeMirror-measure {\n position: absolute;\n width: 100%;\n height: 0;\n overflow: hidden;\n visibility: hidden;\n }\n\n .CodeMirror-measure pre {\n position: static;\n }\n\n div.CodeMirror-dragcursors {\n visibility: visible;\n }\n\n .CodeMirror-selected {\n background: #d9d9d9;\n }\n .CodeMirror-focused .CodeMirror-selected {\n background: #d7d4f0;\n }\n .CodeMirror-focused {\n border-color: ${base.palette.interactive} !important;\n }\n .CodeMirror:not(.CodeMirror-focused) .CodeMirror-cursors {\n visibility: hidden;\n }\n .CodeMirror-crosshair {\n cursor: crosshair;\n }\n .CodeMirror-line::selection,\n .CodeMirror-line > span::selection,\n .CodeMirror-line > span > span::selection {\n background: #d7d4f0;\n }\n .CodeMirror-line::-moz-selection,\n .CodeMirror-line > span::-moz-selection,\n .CodeMirror-line > span > span::-moz-selection {\n background: #d7d4f0;\n }\n\n .cm-searching {\n background-color: rgba(255, 255, 0, 0.4);\n }\n\n /* Used to force a border model for a node */\n .cm-force-border {\n padding-right: 0.006rem;\n }\n\n /* See issue #2901 */\n .cm-tab-wrap-hack::after {\n content: '';\n }\n\n /* Help users use markselection to safely style text background */\n span.CodeMirror-selectedtext {\n background: none;\n }\n\n .CodeMirror {\n overflow: hidden;\n font-family: monospace;\n direction: ltr;\n position: relative;\n background-color: ${base.palette['background-color']};\n color: ${base.palette['foreground-color']};\n border: 0.0625rem solid ${base.palette['border-line']};\n border-radius: calc(0.5 * ${base['border-radius']});\n ${errors &&\n css`\n border-color: ${errorBackground};\n `}\n ${readOnly &&\n css`\n background-color: ${readOnlyBackgroundColor};\n `}\n }\n .cm-ex-properties {\n color: ${base.palette.success};\n }\n .cm-ex-functions {\n color: ${base.palette.warn};\n }\n .CodeMirror-hints {\n position: absolute;\n z-index: 10;\n transition: height ${base.animation.speed} ${base.animation.timing.ease};\n padding: 0;\n border-radius: calc(0.5 * ${base['border-radius']});\n box-shadow: ${base.shadow.low};\n border: 0.0625rem solid ${base.palette['border-line']};\n background-color: ${base.palette['primary-background']};\n font-size: ${fontSizes.s};\n font-family: monospace;\n max-height: 10em;\n overflow-y: auto;\n min-width: 8rem;\n }\n\n .CodeMirror-hint {\n ${isLoading &&\n css`\n pointer-events: none;\n `}\n min-height: ${base['hit-area']['compact-min']};\n cursor: pointer;\n @media (pointer: coarse) {\n min-height: ${base['hit-area']['compact-min']};\n }\n line-height: ${base['hit-area']['compact-min']};\n &:focus-within {\n background-color: ${activeColor};\n }\n\n &:hover:not([aria-disabled='true']) {\n background-color: ${hoverColor};\n }\n padding-inline: ${base.spacing};\n }\n\n li.CodeMirror-hint-active {\n ${!isLoading &&\n css`\n background-color: ${activeColor};\n `}\n }\n `;\n }\n);\n\nStyledCodeEditor.defaultProps = defaultThemeProp;\n"]}
1
+ {"version":3,"file":"CodeEditor.styles.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.styles.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,4DAA4D,CAAC;AAI7F,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAA;;CAEtC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAM1C,CAAC,EACC,KAAK,EAAE,EACL,IAAI,EACJ,UAAU,EAAE,EACV,cAAc,EAAE,EACd,YAAY,EAAE,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,EAC9D,EACD,YAAY,EAAE,EACZ,KAAK,EAAE,EAAE,cAAc,EAAE,eAAe,EAAE,EAC3C,EACF,EACF,EACD,MAAM,EACN,SAAS,EACT,WAAW,EACX,QAAQ,EACT,EAAE,EAAE;IACH,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE5F,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3F,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3E,OAAO,GAAG,CAAA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AAK,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI;;oCAE3C,IAAI,CAAC,eAAe,CAAC;sBACnC,IAAI,CAAC,MAAM,CAAC,GAAG;kCACH,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;4BACjC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;qBACzC,SAAS,CAAC,CAAC;;;;;;;UAOtB,CAAC,SAAS,IAAI,WAAW,EAAE,MAAM,KAAK,CAAC,CAAC;QAC1C,GAAG,CAAA;;SAEF;;4BAEmB,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE;;;;;;;8BAOtB,WAAW;;;;8BAIX,UAAU;;0BAEd,IAAI,CAAC,OAAO;;;;UAI5B,CAAC,SAAS;QACZ,WAAW,EAAE,MAAM,GAAG,CAAC;QACvB,GAAG,CAAA;8BACmB,WAAW;SAChC;;KAEJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["// cSpell:words vscrollbar hscrollbar\nimport styled, { css } from 'styled-components';\nimport { mix } from 'polished';\n\nimport { defaultThemeProp, calculateFontSize, Flex } from '@pega/cosmos-react-core';\nimport { StyledFormField } from '@pega/cosmos-react-core/lib/components/FormField/FormField';\n\nimport { SuggestionType } from './CodeEditor.types';\n\nexport const StyledLoading = styled.div`\n font-size: 1.5rem;\n`;\n\nexport const StyledCodeEditor = styled(Flex)<{\n isLoading?: boolean;\n errors?: string;\n readOnly?: boolean;\n suggestions: SuggestionType[];\n}>(\n ({\n theme: {\n base,\n components: {\n 'form-control': {\n ':read-only': { 'background-color': readOnlyBackgroundColor }\n },\n 'form-field': {\n error: { 'status-color': errorBackground }\n }\n }\n },\n errors,\n isLoading,\n suggestions,\n readOnly\n }) => {\n const activeColor = mix(0.85, base.palette['primary-background'], base.palette.interactive);\n\n const hoverColor = mix(0.95, base.palette['primary-background'], base.palette.interactive);\n\n const fontSizes = calculateFontSize(base['font-size'], base['font-scale']);\n return css`\n position: relative;\n max-height: 100%;\n overflow-y: auto;\n ${StyledFormField} {\n flex-grow: 1;\n }\n\n /* PADDING */\n .react-codemirror2 {\n flex-grow: 1;\n min-height: 3.75rem;\n overflow-y: auto;\n ${readOnly &&\n css`\n max-height: 5.625rem;\n `}\n }\n\n .CodeMirror-lines {\n cursor: text;\n min-height: 0.063rem; /* prevents collapsing before first draw */\n padding: ${base.spacing};\n }\n\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n background-color: white; /* The little square between H and V scrollbars */\n }\n\n /* GUTTER */\n\n .CodeMirror-gutters {\n position: absolute;\n left: 0;\n top: 0;\n min-height: 100%;\n z-index: 3;\n border-right: 0.063rem solid #dddddd;\n background-color: #f7f7f7;\n white-space: nowrap;\n }\n .CodeMirror-linenumber {\n padding: 0 0.125rem 0 0.313rem;\n min-width: 1.25rem;\n text-align: right;\n color: #999999;\n white-space: nowrap;\n }\n\n .CodeMirror-guttermarker {\n color: black;\n }\n .CodeMirror-guttermarker-subtle {\n color: #999999;\n }\n\n /* CURSOR */\n\n .CodeMirror-cursor {\n position: absolute;\n pointer-events: none;\n border-left: 0.0625rem solid ${base.palette.dark};\n border-right: none;\n width: 0;\n ${readOnly &&\n css`\n display: none;\n `}\n }\n\n /* Shown when moving in bi-directional text */\n .CodeMirror div.CodeMirror-secondarycursor {\n border-left: 0.063rem solid silver;\n }\n .cm-fat-cursor-mark {\n background-color: rgba(20, 255, 20, 0.5);\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n }\n .cm-animate-fat-cursor {\n width: auto;\n border: 0;\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n background-color: #77ee77;\n }\n @-moz-keyframes blink {\n 50% {\n background-color: transparent;\n }\n }\n @-webkit-keyframes blink {\n 50% {\n background-color: transparent;\n }\n }\n @keyframes blink {\n 50% {\n background-color: transparent;\n }\n }\n\n .cm-tab {\n display: inline-block;\n text-decoration: inherit;\n }\n\n .CodeMirror-rulers {\n position: absolute;\n left: 0;\n right: 0;\n top: -3.125rem;\n bottom: 0;\n overflow: hidden;\n }\n .CodeMirror-ruler {\n border-left: 0.063rem solid #cccccc;\n top: 0;\n bottom: 0;\n position: absolute;\n }\n\n /* DEFAULT THEME */\n\n .cm-s-default .cm-header {\n color: blue;\n }\n .cm-negative {\n color: #dd4444;\n }\n .cm-positive {\n color: #229922;\n }\n .cm-strong {\n font-weight: bold;\n }\n .cm-s-default .cm-quote {\n color: #009900;\n }\n .cm-em {\n font-style: italic;\n }\n .cm-link {\n text-decoration: underline;\n }\n .cm-strikethrough {\n text-decoration: line-through;\n }\n\n .cm-s-default .cm-keyword {\n color: #770088;\n }\n .cm-s-default .cm-atom {\n color: #221199;\n }\n .cm-s-default .cm-number {\n color: #116644;\n }\n .cm-s-default .cm-def {\n color: #0000ff;\n }\n .cm-s-default .cm-variable-2 {\n color: #0055aa;\n }\n .cm-s-default .cm-variable-3,\n .cm-s-default .cm-type {\n color: #008855;\n }\n .cm-s-default .cm-comment {\n color: #aa5500;\n }\n .cm-s-default .cm-string {\n color: #aa1111;\n }\n .cm-s-default .cm-string-2 {\n color: #ff5500;\n }\n .cm-s-default .cm-meta {\n color: #555555;\n }\n .cm-s-default .cm-qualifier {\n color: #555555;\n }\n .cm-s-default .cm-builtin {\n color: #3300aa;\n }\n .cm-s-default .cm-bracket {\n color: #999977;\n }\n .cm-s-default .cm-tag {\n color: #117700;\n }\n .cm-s-default .cm-attribute {\n color: #0000cc;\n }\n .cm-s-default .cm-hr {\n color: #999999;\n }\n .cm-s-default .cm-link {\n color: #0000cc;\n }\n\n .cm-s-default .cm-error {\n color: #ff0000;\n }\n .cm-invalidchar {\n color: #ff0000;\n }\n\n .CodeMirror-composing {\n border-bottom: 0.125rem solid;\n }\n\n /* Default styles for common addons */\n\n div.CodeMirror span.CodeMirror-matchingbracket {\n color: #00bb00;\n }\n div.CodeMirror span.CodeMirror-nonmatchingbracket {\n color: #aa2222;\n }\n .CodeMirror-matchingtag {\n background: rgba(255, 150, 0, 0.3);\n }\n .CodeMirror-activeline-background {\n background: #e8f2ff;\n }\n\n /* STOP */\n\n /* The rest of this file contains styles related to the mechanics of\n the editor. You probably shouldn't touch them. */\n\n .CodeMirror-scroll {\n overflow: scroll !important;\n margin-bottom: -3.125rem;\n margin-right: -3.125rem;\n padding-bottom: 3.125rem;\n height: 100%;\n outline: none; /* Prevent dragging from highlighting the element */\n position: relative;\n }\n .CodeMirror-sizer {\n position: relative;\n border-right: 3.125rem solid transparent;\n }\n\n /* The fake, visible scrollbars. Used to force redraw during scrolling\n before actual scrolling happens, thus preventing shaking and\n flickering artifacts. */\n .CodeMirror-vscrollbar,\n .CodeMirror-hscrollbar,\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n position: absolute;\n z-index: 6;\n display: none;\n }\n .CodeMirror-vscrollbar {\n right: 0;\n top: 0;\n overflow-x: hidden;\n overflow-y: scroll;\n }\n .CodeMirror-hscrollbar {\n bottom: 0;\n left: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n }\n .CodeMirror-scrollbar-filler {\n right: 0;\n bottom: 0;\n }\n .CodeMirror-gutter-filler {\n left: 0;\n bottom: 0;\n }\n .CodeMirror-gutter {\n white-space: normal;\n height: 100%;\n display: inline-block;\n vertical-align: top;\n margin-bottom: -3.125rem;\n }\n .CodeMirror-gutter-wrapper {\n position: absolute;\n z-index: 4;\n background: none !important;\n border: none !important;\n }\n .CodeMirror-gutter-background {\n position: absolute;\n top: 0;\n bottom: 0;\n z-index: 4;\n }\n .CodeMirror-gutter-elt {\n position: absolute;\n cursor: default;\n z-index: 4;\n }\n .CodeMirror-gutter-wrapper ::selection {\n background-color: transparent;\n }\n .CodeMirror-gutter-wrapper ::-moz-selection {\n background-color: transparent;\n }\n\n .CodeMirror pre.CodeMirror-line,\n .CodeMirror pre.CodeMirror-line-like {\n /* Reset some styles that the rest of the page might have set */\n -moz-border-radius: 0;\n -webkit-border-radius: 0;\n border-radius: 0;\n border-width: 0;\n background: transparent;\n font-family: inherit;\n font-size: inherit;\n margin: 0;\n white-space: pre;\n word-wrap: normal;\n line-height: inherit;\n color: inherit;\n z-index: 2;\n position: relative;\n overflow: visible;\n -webkit-tap-highlight-color: transparent;\n -webkit-font-variant-ligatures: contextual;\n font-variant-ligatures: contextual;\n }\n .CodeMirror-wrap pre.CodeMirror-line,\n .CodeMirror-wrap pre.CodeMirror-line-like {\n word-wrap: break-word;\n white-space: pre-wrap;\n word-break: normal;\n }\n\n .CodeMirror-linebackground {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n z-index: 0;\n }\n\n .CodeMirror-linewidget {\n position: relative;\n z-index: 2;\n padding: 0.006rem; /* Force widget margins to stay inside of the container */\n }\n\n .CodeMirror-rtl pre {\n direction: rtl;\n }\n\n .CodeMirror-code {\n outline: none;\n }\n\n /* Force content-box sizing for the elements where we expect it */\n .CodeMirror-scroll,\n .CodeMirror-sizer,\n .CodeMirror-gutter,\n .CodeMirror-linenumber {\n -moz-box-sizing: content-box;\n box-sizing: content-box;\n }\n\n .CodeMirror-measure {\n position: absolute;\n width: 100%;\n height: 0;\n overflow: hidden;\n visibility: hidden;\n }\n\n .CodeMirror-measure pre {\n position: static;\n }\n\n div.CodeMirror-dragcursors {\n visibility: visible;\n }\n\n .CodeMirror-selected {\n background: #d9d9d9;\n }\n .CodeMirror-focused .CodeMirror-selected {\n background: #d7d4f0;\n }\n .CodeMirror-focused {\n border-color: ${base.palette.interactive} !important;\n }\n .CodeMirror:not(.CodeMirror-focused) .CodeMirror-cursors {\n visibility: hidden;\n }\n .CodeMirror-crosshair {\n cursor: crosshair;\n }\n .CodeMirror-line::selection,\n .CodeMirror-line > span::selection,\n .CodeMirror-line > span > span::selection {\n background: #d7d4f0;\n }\n .CodeMirror-line::-moz-selection,\n .CodeMirror-line > span::-moz-selection,\n .CodeMirror-line > span > span::-moz-selection {\n background: #d7d4f0;\n }\n\n .cm-searching {\n background-color: rgba(255, 255, 0, 0.4);\n }\n\n /* Used to force a border model for a node */\n .cm-force-border {\n padding-right: 0.006rem;\n }\n\n /* See issue #2901 */\n .cm-tab-wrap-hack::after {\n content: '';\n }\n\n /* Help users use markselection to safely style text background */\n span.CodeMirror-selectedtext {\n background: none;\n }\n\n .CodeMirror {\n overflow: hidden;\n font-family: monospace;\n direction: ltr;\n position: relative;\n background-color: ${base.palette['background-color']};\n color: ${base.palette['foreground-color']};\n border: 0.0625rem solid ${base.palette['border-line']};\n border-radius: calc(0.5 * ${base['border-radius']});\n ${errors &&\n css`\n border-color: ${errorBackground};\n `}\n ${readOnly &&\n css`\n background-color: ${readOnlyBackgroundColor};\n `}\n }\n\n .cm-ex-context {\n color: ${base.palette['brand-primary']};\n }\n .cm-ex-operator {\n color: ${base.palette.warn};\n font-weight: bold;\n }\n .cm-ex-ruleName {\n color: ${base.palette.success};\n }\n .cm-ex-delimeter {\n color: ${base.palette['foreground-color']};\n }\n .cm-ex-constant {\n color: ${base.palette.pending};\n }\n\n .CodeMirror-hints {\n position: absolute;\n z-index: 10;\n transition: height ${base.animation.speed} ${base.animation.timing.ease};\n padding: 0;\n border-radius: calc(0.5 * ${base['border-radius']});\n box-shadow: ${base.shadow.low};\n border: 0.0625rem solid ${base.palette['border-line']};\n background-color: ${base.palette['primary-background']};\n font-size: ${fontSizes.s};\n max-height: 12rem;\n overflow-y: auto;\n min-width: 8rem;\n }\n\n .CodeMirror-hint {\n ${(isLoading || suggestions?.length === 0) &&\n css`\n pointer-events: none;\n `}\n min-height: 1.2rem;\n width: calc(1.5 * ${base['content-width'].xs});\n cursor: pointer;\n @media (pointer: coarse) {\n min-height: 1.2rem;\n }\n line-height: 1.2rem;\n &:focus-within {\n background-color: ${activeColor};\n }\n\n &:hover:not([aria-disabled='true']) {\n background-color: ${hoverColor};\n }\n padding-inline: ${base.spacing};\n }\n\n li.CodeMirror-hint-active {\n ${!isLoading &&\n suggestions?.length > 0 &&\n css`\n background-color: ${activeColor};\n `}\n }\n `;\n }\n);\n\nStyledCodeEditor.defaultProps = defaultThemeProp;\n"]}
@@ -1,10 +1,8 @@
1
1
  import { Ref } from 'react';
2
- import { ShowHintOptions, EditorConfiguration } from 'codemirror';
3
- export declare type AutoCompleteTriggerType = '@' | '.';
4
- export declare type SuggestionsType = {
5
- label: string;
6
- value: string;
7
- };
2
+ import { ShowHintOptions, EditorConfiguration, Position } from 'codemirror';
3
+ import { MenuItemProps } from '@pega/cosmos-react-core';
4
+ export declare type AutoCompleteTriggerChar = '@' | '.' | ':';
5
+ export declare type SuggestionType = Pick<MenuItemProps, 'primary' | 'secondary' | 'id'>;
8
6
  export interface EditorState {
9
7
  getValue: () => string | undefined;
10
8
  insertText: (text: string) => void;
@@ -17,9 +15,9 @@ export interface CodeEditorProps {
17
15
  /** Enable read only mode */
18
16
  readOnly?: boolean;
19
17
  /** Fetches suggestion list for suggestions popover */
20
- fetchSuggestions?: (autoCompleteTrigger: AutoCompleteTriggerType, queryString: string) => Promise<SuggestionsType[]>;
18
+ fetchSuggestions?: (autoCompleteTrigger: AutoCompleteTriggerChar, queryString: string) => Promise<SuggestionType[]>;
21
19
  /** characters which triggers suggestions */
22
- autoCompleteTriggers?: AutoCompleteTriggerType[];
20
+ autoCompleteTriggers?: AutoCompleteTriggerChar[];
23
21
  /** Code editor configuration props */
24
22
  editorConfigProps?: EditorConfiguration;
25
23
  /** To show loader for intellisense popover */
@@ -30,8 +28,8 @@ export interface CodeEditorProps {
30
28
  ref?: Ref<HTMLDivElement>;
31
29
  }
32
30
  export interface EditorHintOptions extends ShowHintOptions {
33
- suggestions?: SuggestionsType[];
31
+ suggestions?: SuggestionType[];
34
32
  loading?: boolean;
35
- autoCompleteTrigger?: AutoCompleteTriggerType;
33
+ triggerCharacterCursorPos?: Position;
36
34
  }
37
35
  //# sourceMappingURL=CodeEditor.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.types.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAElE,oBAAY,uBAAuB,GAAG,GAAG,GAAG,GAAG,CAAC;AAEhD,oBAAY,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACnC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,CACjB,mBAAmB,EAAE,uBAAuB,EAC5C,WAAW,EAAE,MAAM,KAChB,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAChC,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACjD,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,mBAAmB,CAAC;IACxC,8CAA8C;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,gBAAgB,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,iB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;IAC1C,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,gBAAgB,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACxD,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yBAAyB,CAAC,EAAE,QAAQ,CAAC;CACtC"}
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.types.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\nimport { ShowHintOptions, EditorConfiguration } from 'codemirror';\n\nexport type AutoCompleteTriggerType = '@' | '.';\n\nexport type SuggestionsType = { label: string; value: string };\n\nexport interface EditorState {\n getValue: () => string | undefined;\n insertText: (text: string) => void;\n}\n\nexport interface CodeEditorProps {\n /** Default expression to set in the code editor */\n defaultValue?: string;\n /** Compiled error message */\n errors?: string;\n /** Enable read only mode */\n readOnly?: boolean;\n /** Fetches suggestion list for suggestions popover */\n fetchSuggestions?: (\n autoCompleteTrigger: AutoCompleteTriggerType,\n queryString: string\n ) => Promise<SuggestionsType[]>;\n /** characters which triggers suggestions */\n autoCompleteTriggers?: AutoCompleteTriggerType[];\n /** Code editor configuration props */\n editorConfigProps?: EditorConfiguration;\n /** To show loader for intellisense popover */\n loading?: boolean;\n /** Called when editor content changes. */\n onChange?: (expression: string) => void;\n codeEditorHandle: Ref<EditorState>;\n ref?: Ref<HTMLDivElement>;\n}\n\nexport interface EditorHintOptions extends ShowHintOptions {\n suggestions?: SuggestionsType[];\n loading?: boolean;\n autoCompleteTrigger?: AutoCompleteTriggerType;\n}\n"]}
1
+ {"version":3,"file":"CodeEditor.types.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/CodeEditor.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\nimport { ShowHintOptions, EditorConfiguration, Position } from 'codemirror';\n\nimport { MenuItemProps } from '@pega/cosmos-react-core';\n\nexport type AutoCompleteTriggerChar = '@' | '.' | ':';\n\nexport type SuggestionType = Pick<MenuItemProps, 'primary' | 'secondary' | 'id'>;\n\nexport interface EditorState {\n getValue: () => string | undefined;\n insertText: (text: string) => void;\n}\n\nexport interface CodeEditorProps {\n /** Default expression to set in the code editor */\n defaultValue?: string;\n /** Compiled error message */\n errors?: string;\n /** Enable read only mode */\n readOnly?: boolean;\n /** Fetches suggestion list for suggestions popover */\n fetchSuggestions?: (\n autoCompleteTrigger: AutoCompleteTriggerChar,\n queryString: string\n ) => Promise<SuggestionType[]>;\n /** characters which triggers suggestions */\n autoCompleteTriggers?: AutoCompleteTriggerChar[];\n /** Code editor configuration props */\n editorConfigProps?: EditorConfiguration;\n /** To show loader for intellisense popover */\n loading?: boolean;\n /** Called when editor content changes. */\n onChange?: (expression: string) => void;\n codeEditorHandle: Ref<EditorState>;\n ref?: Ref<HTMLDivElement>;\n}\n\nexport interface EditorHintOptions extends ShowHintOptions {\n suggestions?: SuggestionType[];\n loading?: boolean;\n triggerCharacterCursorPos?: Position;\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { Editor, Hint, Hints } from 'codemirror';
1
+ import { Editor } from 'codemirror';
2
2
  import { EditorHintOptions } from './CodeEditor.types';
3
- declare const getCodeSuggestions: (codeMirror: Editor, { suggestions, loading, autoCompleteTrigger }: EditorHintOptions) => {
3
+ declare const getCodeSuggestions: (codeMirror: Editor, { suggestions, loading, triggerCharacterCursorPos }: EditorHintOptions) => {
4
4
  list: {
5
5
  text: string;
6
6
  displayText: string;
7
- render: (element: HTMLLIElement, _: Hints, listItem: Hint) => void;
7
+ render: (element: HTMLLIElement) => void;
8
8
  }[];
9
9
  from: import("codemirror").Position;
10
10
  to: import("codemirror").Position;
@@ -1 +1 @@
1
- {"version":3,"file":"getCodeSuggestions.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAO,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAItD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,QAAA,MAAM,kBAAkB,eACV,MAAM,iDAC0C,iBAAiB;;;;0BA+BjD,aAAa,KAAK,KAAK,YAAY,IAAI;;;;CAkBpE,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"getCodeSuggestions.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AAKzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,QAAA,MAAM,kBAAkB,eACV,MAAM,uDAQf,iBAAiB;;cASZ,MAAM;qBACC,MAAM;0BACD,aAAa,KAAK,IAAI;;;;CA8C3C,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -1,15 +1,21 @@
1
+ import { createElement as _createElement } from "react";
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import ReactDOM from 'react-dom';
3
4
  import { Pos } from 'codemirror';
4
- import { Progress, Flex } from '@pega/cosmos-react-core';
5
+ import { Progress, Flex, EmptyState } from '@pega/cosmos-react-core';
6
+ import MenuItem from '@pega/cosmos-react-core/lib/components/Menu/MenuItem';
5
7
  import { StyledLoading } from './CodeEditor.styles';
6
- const getCodeSuggestions = (codeMirror, { suggestions = [], loading = false, autoCompleteTrigger }) => {
8
+ const getCodeSuggestions = (codeMirror, { suggestions = [], loading = false, triggerCharacterCursorPos = {
9
+ ch: 0,
10
+ line: 0
11
+ } }) => {
7
12
  const currentPosition = codeMirror.getCursor();
8
- const word = codeMirror.getTokenAt(currentPosition);
9
- const tokens = word.string.split(autoCompleteTrigger);
10
- const prefixToken = tokens.slice(0, tokens.length - 1).join();
11
- const filteredList = loading
12
- ? [
13
+ const filterQuery = codeMirror
14
+ .getValue()
15
+ .split('\n')[triggerCharacterCursorPos.line]?.substring(triggerCharacterCursorPos.ch, currentPosition.ch);
16
+ let filteredList = [];
17
+ if (loading || suggestions.length === 0) {
18
+ filteredList = [
13
19
  {
14
20
  text: '',
15
21
  displayText: '',
@@ -17,29 +23,28 @@ const getCodeSuggestions = (codeMirror, { suggestions = [], loading = false, aut
17
23
  ReactDOM.render(_jsx(Flex, { container: {
18
24
  justify: 'center',
19
25
  pad: 1
20
- }, children: _jsx(Progress, { variant: 'ring', placement: 'inline', visible: loading, as: StyledLoading }) }), element);
26
+ }, children: loading ? (_jsx(Progress, { variant: 'ring', placement: 'inline', visible: loading, as: StyledLoading })) : (_jsx(EmptyState, {})) }), element);
21
27
  }
22
28
  }
23
- ]
24
- : suggestions
29
+ ];
30
+ }
31
+ else {
32
+ filteredList = suggestions
25
33
  .map(hint => {
26
34
  return {
27
- text: prefixToken.concat(hint.value),
28
- displayText: hint.label,
29
- render: (element, _, listItem) => {
30
- const itemDiv = document.createElement('div');
31
- const labelSpan = document.createElement('span');
32
- labelSpan.textContent = listItem.displayText;
33
- itemDiv.appendChild(labelSpan);
34
- element.appendChild(itemDiv);
35
+ text: hint.id,
36
+ displayText: hint.primary,
37
+ render: (element) => {
38
+ ReactDOM.render(_createElement(MenuItem, { ...hint, key: hint.id, role: 'menuitem' }), element);
35
39
  }
36
40
  };
37
41
  })
38
- .filter(item => item.displayText.toLowerCase().startsWith(tokens[tokens.length - 1].toLowerCase()));
42
+ .filter(item => item.displayText.toLowerCase().startsWith(filterQuery.toLowerCase()));
43
+ }
39
44
  return {
40
45
  list: filteredList,
41
- from: Pos(currentPosition.line, word.start + prefixToken.length),
42
- to: Pos(currentPosition.line, word.end)
46
+ from: Pos(currentPosition.line, triggerCharacterCursorPos.ch - 1),
47
+ to: Pos(currentPosition.line, currentPosition.ch)
43
48
  };
44
49
  };
45
50
  export default getCodeSuggestions;
@@ -1 +1 @@
1
- {"version":3,"file":"getCodeSuggestions.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.tsx"],"names":[],"mappings":";AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAU,GAAG,EAAe,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,kBAAkB,GAAG,CACzB,UAAkB,EAClB,EAAE,WAAW,GAAG,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,mBAAmB,EAAqB,EAC7E,EAAE;IACF,MAAM,eAAe,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;IAC/C,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAoB,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9D,MAAM,YAAY,GAAG,OAAO;QAC1B,CAAC,CAAC;YACE;gBACE,IAAI,EAAE,EAAE;gBACR,WAAW,EAAE,EAAE;gBACf,MAAM,EAAE,CAAC,OAAsB,EAAE,EAAE;oBACjC,QAAQ,CAAC,MAAM,CACb,KAAC,IAAI,IACH,SAAS,EAAE;4BACT,OAAO,EAAE,QAAQ;4BACjB,GAAG,EAAE,CAAC;yBACP,YAED,KAAC,QAAQ,IAAC,OAAO,EAAC,MAAM,EAAC,SAAS,EAAC,QAAQ,EAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,GAAI,GAC9E,EACP,OAAO,CACR,CAAC;gBACJ,CAAC;aACF;SACF;QACH,CAAC,CAAC,WAAW;aACR,GAAG,CAAC,IAAI,CAAC,EAAE;YACV,OAAO;gBACL,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;gBACpC,WAAW,EAAE,IAAI,CAAC,KAAK;gBACvB,MAAM,EAAE,CAAC,OAAsB,EAAE,CAAQ,EAAE,QAAc,EAAE,EAAE;oBAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;oBAC9C,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;oBACjD,SAAS,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAY,CAAC;oBAC9C,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;oBAC/B,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAC/B,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;aACD,MAAM,CAAC,IAAI,CAAC,EAAE,CACb,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CACnF,CAAC;IAER,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC;QAChE,EAAE,EAAE,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;KACxC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import ReactDOM from 'react-dom';\nimport { Editor, Pos, Hint, Hints } from 'codemirror';\n\nimport { Progress, Flex } from '@pega/cosmos-react-core';\n\nimport { EditorHintOptions } from './CodeEditor.types';\nimport { StyledLoading } from './CodeEditor.styles';\n\nconst getCodeSuggestions = (\n codeMirror: Editor,\n { suggestions = [], loading = false, autoCompleteTrigger }: EditorHintOptions\n) => {\n const currentPosition = codeMirror.getCursor();\n const word = codeMirror.getTokenAt(currentPosition);\n const tokens = word.string.split(autoCompleteTrigger!);\n const prefixToken = tokens.slice(0, tokens.length - 1).join();\n const filteredList = loading\n ? [\n {\n text: '',\n displayText: '',\n render: (element: HTMLLIElement) => {\n ReactDOM.render(\n <Flex\n container={{\n justify: 'center',\n pad: 1\n }}\n >\n <Progress variant='ring' placement='inline' visible={loading} as={StyledLoading} />\n </Flex>,\n element\n );\n }\n }\n ]\n : suggestions\n .map(hint => {\n return {\n text: prefixToken.concat(hint.value),\n displayText: hint.label,\n render: (element: HTMLLIElement, _: Hints, listItem: Hint) => {\n const itemDiv = document.createElement('div');\n const labelSpan = document.createElement('span');\n labelSpan.textContent = listItem.displayText!;\n itemDiv.appendChild(labelSpan);\n element.appendChild(itemDiv);\n }\n };\n })\n .filter(item =>\n item.displayText.toLowerCase().startsWith(tokens[tokens.length - 1].toLowerCase())\n );\n\n return {\n list: filteredList,\n from: Pos(currentPosition.line, word.start + prefixToken.length),\n to: Pos(currentPosition.line, word.end)\n };\n};\n\nexport default getCodeSuggestions;\n"]}
1
+ {"version":3,"file":"getCodeSuggestions.js","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.tsx"],"names":[],"mappings":";;AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAU,GAAG,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,QAAQ,MAAM,sDAAsD,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,kBAAkB,GAAG,CACzB,UAAkB,EAClB,EACE,WAAW,GAAG,EAAE,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AAE,IAAI,EAAC,UAAU,GAAG,EAAE,OAAO,CAAC,CAAC;gBACjF,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;aACD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;KACzF;IAED,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,yBAAyB,CAAC,EAAE,GAAG,CAAC,CAAC;QACjE,EAAE,EAAE,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;KAClD,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import ReactDOM from 'react-dom';\nimport { Editor, Pos } from 'codemirror';\n\nimport { Progress, Flex, EmptyState } from '@pega/cosmos-react-core';\nimport MenuItem from '@pega/cosmos-react-core/lib/components/Menu/MenuItem';\n\nimport { EditorHintOptions } from './CodeEditor.types';\nimport { StyledLoading } from './CodeEditor.styles';\n\nconst getCodeSuggestions = (\n codeMirror: Editor,\n {\n suggestions = [],\n loading = false,\n triggerCharacterCursorPos = {\n ch: 0,\n line: 0\n }\n }: EditorHintOptions\n) => {\n const currentPosition = codeMirror.getCursor();\n const filterQuery = codeMirror\n .getValue()\n .split('\\n')\n [triggerCharacterCursorPos.line]?.substring(triggerCharacterCursorPos.ch, currentPosition.ch);\n\n let filteredList: {\n text: string;\n displayText: string;\n render: (element: HTMLLIElement) => void;\n }[] = [];\n\n if (loading || suggestions.length === 0) {\n filteredList = [\n {\n text: '',\n displayText: '',\n render: (element: HTMLLIElement) => {\n ReactDOM.render(\n <Flex\n container={{\n justify: 'center',\n pad: 1\n }}\n >\n {loading ? (\n <Progress variant='ring' placement='inline' visible={loading} as={StyledLoading} />\n ) : (\n <EmptyState />\n )}\n </Flex>,\n element\n );\n }\n }\n ];\n } else {\n filteredList = suggestions\n .map(hint => {\n return {\n text: hint.id,\n displayText: hint.primary,\n render: (element: HTMLLIElement) => {\n ReactDOM.render(<MenuItem {...hint} key={hint.id} role='menuitem' />, element);\n }\n };\n })\n .filter(item => item.displayText.toLowerCase().startsWith(filterQuery.toLowerCase()));\n }\n\n return {\n list: filteredList,\n from: Pos(currentPosition.line, triggerCharacterCursorPos.ch - 1),\n to: Pos(currentPosition.line, currentPosition.ch)\n };\n};\n\nexport default getCodeSuggestions;\n"]}