@pega/cosmos-react-build 3.0.0-dev.26.0 → 3.0.0-dev.27.2

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 (32) hide show
  1. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.d.ts +8 -0
  2. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.d.ts.map +1 -0
  3. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.js +100 -0
  4. package/lib/components/ExpressionBuilder/CodeEditor/CodeEditor.js.map +1 -0
  5. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.d.ts +13 -0
  6. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.d.ts.map +1 -0
  7. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.js +27 -0
  8. package/lib/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.js.map +1 -0
  9. package/lib/components/ExpressionBuilder/ExpressionBuilder.d.ts.map +1 -1
  10. package/lib/components/ExpressionBuilder/ExpressionBuilder.js +16 -42
  11. package/lib/components/ExpressionBuilder/ExpressionBuilder.js.map +1 -1
  12. package/lib/components/ExpressionBuilder/ExpressionBuilder.styles.d.ts +3 -1
  13. package/lib/components/ExpressionBuilder/ExpressionBuilder.styles.d.ts.map +1 -1
  14. package/lib/components/ExpressionBuilder/ExpressionBuilder.styles.js +474 -9
  15. package/lib/components/ExpressionBuilder/ExpressionBuilder.styles.js.map +1 -1
  16. package/lib/components/ExpressionBuilder/ExpressionBuilder.types.d.ts +33 -3
  17. package/lib/components/ExpressionBuilder/ExpressionBuilder.types.d.ts.map +1 -1
  18. package/lib/components/ExpressionBuilder/ExpressionBuilder.types.js.map +1 -1
  19. package/lib/components/ExpressionBuilder/ExpressionBuilderContext.d.ts +7 -0
  20. package/lib/components/ExpressionBuilder/ExpressionBuilderContext.d.ts.map +1 -0
  21. package/lib/components/ExpressionBuilder/ExpressionBuilderContext.js +6 -0
  22. package/lib/components/ExpressionBuilder/ExpressionBuilderContext.js.map +1 -0
  23. package/lib/components/ExpressionBuilder/ExpressionItem.d.ts.map +1 -1
  24. package/lib/components/ExpressionBuilder/ExpressionItem.js +22 -6
  25. package/lib/components/ExpressionBuilder/ExpressionItem.js.map +1 -1
  26. package/lib/components/ExpressionBuilder/index.d.ts +2 -1
  27. package/lib/components/ExpressionBuilder/index.d.ts.map +1 -1
  28. package/lib/components/ExpressionBuilder/index.js +1 -0
  29. package/lib/components/ExpressionBuilder/index.js.map +1 -1
  30. package/lib/components/FlowModeller/FlowModeller.js +2 -2
  31. package/lib/components/FlowModeller/FlowModeller.js.map +1 -1
  32. package/package.json +6 -3
@@ -0,0 +1,8 @@
1
+ import { FunctionComponent } from 'react';
2
+ import 'codemirror/addon/edit/closebrackets';
3
+ import 'codemirror/addon/hint/show-hint.js';
4
+ import { ForwardProps } from '@pega/cosmos-react-core';
5
+ import { CodeEditorProps } from '../ExpressionBuilder.types';
6
+ declare const CodeEditor: FunctionComponent<CodeEditorProps & ForwardProps>;
7
+ export default CodeEditor;
8
+ //# sourceMappingURL=CodeEditor.d.ts.map
@@ -0,0 +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;AAGf,OAAO,qCAAqC,CAAC;AAC7C,OAAO,oCAAoC,CAAC;AAE5C,OAAO,EAAkC,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvF,OAAO,EAEL,eAAe,EAGhB,MAAM,4BAA4B,CAAC;AAqCpC,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAoFjE,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,100 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // cSpell:words unfocus
3
+ import { forwardRef, useRef, useState, useEffect, useImperativeHandle } from 'react';
4
+ import { Controlled as ReactCodeMirror } from 'react-codemirror2';
5
+ import { showHint, defineMode } from 'codemirror';
6
+ import 'codemirror/addon/edit/closebrackets';
7
+ import 'codemirror/addon/hint/show-hint.js';
8
+ import { useConsolidatedRef, useElement } from '@pega/cosmos-react-core';
9
+ import { StyledCodeEditor } from '../ExpressionBuilder.styles';
10
+ import getCodeSuggestions from './getCodeSuggestions';
11
+ const defaultConfigOptions = {
12
+ lineWrapping: true,
13
+ smartIndent: true,
14
+ autoCloseTags: true,
15
+ matchBrackets: true,
16
+ autoCloseBrackets: true
17
+ };
18
+ defineMode('expression', () => {
19
+ const currTokens = [
20
+ {
21
+ token: /[a-zA-Z_$]*[.]+[a-zA-Z_$][a-zA-Z\d_$]*/i,
22
+ style: 'ex-properties'
23
+ },
24
+ {
25
+ token: /(^[@]+)(\([\w.-]+:[\w.-]+\))*([\w.]+)(\s*)/i,
26
+ style: 'ex-functions'
27
+ }
28
+ ];
29
+ return {
30
+ token(stream) {
31
+ for (let i = 0; i < currTokens.length; i += 1) {
32
+ if (stream.match('#') || stream.match('//'))
33
+ stream.skipToEnd();
34
+ else if (stream.match(currTokens[i].token))
35
+ return currTokens[i].style;
36
+ }
37
+ stream.next();
38
+ return null;
39
+ }
40
+ };
41
+ });
42
+ const CodeEditor = forwardRef(({ fetchSuggestions, autoCompleteTriggers, editorConfigProps, codeEditorHandle, defaultValue = '', ...props }, ref) => {
43
+ const [value, setCode] = useState(defaultValue);
44
+ const [suggestions, setList] = useState([]);
45
+ const [codeMirror, setCodeMirror] = useState(null);
46
+ const [codeEditorContainer, setCodeEditorContainer] = useElement();
47
+ const codeEditorConsolidatedRef = useConsolidatedRef(setCodeEditorContainer, ref);
48
+ const mounted = useRef(false);
49
+ useImperativeHandle(codeEditorHandle, () => ({
50
+ insertText: (text) => {
51
+ if (codeMirror) {
52
+ const cur = codeMirror.getCursor();
53
+ codeMirror.replaceRange(text, cur);
54
+ }
55
+ },
56
+ getValue: () => {
57
+ return codeMirror?.getValue();
58
+ }
59
+ }), [codeMirror]);
60
+ const autoComplete = (codeEditor) => {
61
+ const hintOptions = {
62
+ completeSingle: false,
63
+ completeOnSingleClick: true,
64
+ closeOnUnfocus: true,
65
+ suggestions,
66
+ container: codeEditorContainer
67
+ };
68
+ showHint(codeEditor, getCodeSuggestions, hintOptions);
69
+ };
70
+ useEffect(() => {
71
+ if (suggestions.length > 0 && value.length > 0 && codeMirror) {
72
+ autoComplete(codeMirror);
73
+ }
74
+ else {
75
+ codeMirror?.closeHint();
76
+ }
77
+ }, [suggestions]);
78
+ useEffect(() => {
79
+ mounted.current = true;
80
+ return () => {
81
+ mounted.current = false;
82
+ };
83
+ }, []);
84
+ return (_jsx(StyledCodeEditor, { ref: codeEditorConsolidatedRef, ...props, children: _jsx(ReactCodeMirror, { value: value, onBeforeChange: async (editor, _data, textvalue) => {
85
+ setCode(textvalue);
86
+ const currentCursor = editor.getCursor();
87
+ const autoCompleteTrigger = editor.getTokenAt(currentCursor)
88
+ .string;
89
+ if (autoCompleteTriggers?.includes(autoCompleteTrigger) && fetchSuggestions) {
90
+ const newSuggestions = [...(await fetchSuggestions(autoCompleteTrigger))];
91
+ if (mounted.current)
92
+ setList(newSuggestions);
93
+ }
94
+ }, options: { ...defaultConfigOptions, ...editorConfigProps }, editorDidMount: editor => {
95
+ editor.setSize('100%', '100%');
96
+ setCodeMirror(editor);
97
+ } }) }));
98
+ });
99
+ export default CodeEditor;
100
+ //# sourceMappingURL=CodeEditor.js.map
@@ -0,0 +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,EAAE,MAAM,mBAAmB,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Aa,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC,GACD,GACe,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 { showHint, defineMode, Editor, Position } from 'codemirror';\nimport 'codemirror/addon/edit/closebrackets';\nimport 'codemirror/addon/hint/show-hint.js';\n\nimport { useConsolidatedRef, useElement, ForwardProps } from '@pega/cosmos-react-core';\n\nimport {\n AutoCompleteTriggerType,\n CodeEditorProps,\n EditorState,\n SuggestionsType\n} from '../ExpressionBuilder.types';\nimport { StyledCodeEditor } from '../ExpressionBuilder.styles';\n\nimport getCodeSuggestions from './getCodeSuggestions';\n\nconst defaultConfigOptions = {\n lineWrapping: true,\n smartIndent: true,\n autoCloseTags: true,\n matchBrackets: true,\n autoCloseBrackets: true\n};\n\ndefineMode('expression', () => {\n const currTokens = [\n {\n token: /[a-zA-Z_$]*[.]+[a-zA-Z_$][a-zA-Z\\d_$]*/i,\n style: 'ex-properties'\n },\n {\n token: /(^[@]+)(\\([\\w.-]+:[\\w.-]+\\))*([\\w.]+)(\\s*)/i,\n style: 'ex-functions'\n }\n ];\n\n return {\n token(stream) {\n for (let i = 0; i < currTokens.length; i += 1) {\n if (stream.match('#') || stream.match('//')) stream.skipToEnd();\n else if (stream.match(currTokens[i].token)) return currTokens[i].style;\n }\n stream.next();\n return null;\n }\n };\n});\n\nconst CodeEditor: FunctionComponent<CodeEditorProps & ForwardProps> = forwardRef(\n (\n {\n fetchSuggestions,\n autoCompleteTriggers,\n editorConfigProps,\n codeEditorHandle,\n defaultValue = '',\n ...props\n }: PropsWithoutRef<CodeEditorProps>,\n ref: CodeEditorProps['ref']\n ) => {\n const [value, setCode] = useState<string>(defaultValue);\n const [suggestions, setList] = useState<SuggestionsType[]>([]);\n const [codeMirror, setCodeMirror] = useState<Editor | null>(null);\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 };\n showHint(codeEditor, getCodeSuggestions, hintOptions);\n };\n\n useEffect(() => {\n if (suggestions.length > 0 && value.length > 0 && codeMirror) {\n autoComplete(codeMirror);\n } else {\n codeMirror?.closeHint();\n }\n }, [suggestions]);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n return (\n <StyledCodeEditor ref={codeEditorConsolidatedRef} {...props}>\n <ReactCodeMirror\n value={value}\n onBeforeChange={async (editor, _data, textvalue) => {\n setCode(textvalue);\n const currentCursor = editor.getCursor();\n const autoCompleteTrigger = editor.getTokenAt(currentCursor)\n .string as AutoCompleteTriggerType;\n if (autoCompleteTriggers?.includes(autoCompleteTrigger) && fetchSuggestions) {\n const newSuggestions = [...(await fetchSuggestions(autoCompleteTrigger))];\n if (mounted.current) setList(newSuggestions);\n }\n }}\n options={{ ...defaultConfigOptions, ...editorConfigProps }}\n editorDidMount={editor => {\n editor.setSize('100%', '100%');\n setCodeMirror(editor);\n }}\n />\n </StyledCodeEditor>\n );\n }\n);\n\nexport default CodeEditor;\n"]}
@@ -0,0 +1,13 @@
1
+ import { Editor, Hint, Hints } from 'codemirror';
2
+ import { EditorHintOptions } from '../ExpressionBuilder.types';
3
+ declare const getCodeSuggestions: (codeMirror: Editor, options: EditorHintOptions) => {
4
+ list: {
5
+ text: string;
6
+ displayText: string;
7
+ render: (Element: HTMLLIElement, _self: Hints, data: Hint) => void;
8
+ }[];
9
+ from: import("codemirror").Position;
10
+ to: import("codemirror").Position;
11
+ };
12
+ export default getCodeSuggestions;
13
+ //# sourceMappingURL=getCodeSuggestions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCodeSuggestions.d.ts","sourceRoot":"","sources":["../../../../src/components/ExpressionBuilder/CodeEditor/getCodeSuggestions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAO,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,QAAA,MAAM,kBAAkB,eAAgB,MAAM,WAAW,iBAAiB;;;;0BAUlD,aAAa,SAAS,KAAK,QAAQ,IAAI;;;;CAe9D,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { Pos } from 'codemirror';
2
+ const getCodeSuggestions = (codeMirror, options) => {
3
+ const { suggestions = [] } = options;
4
+ const curPos = codeMirror.getCursor();
5
+ const token = codeMirror.getTokenAt(curPos);
6
+ token.end = curPos.ch;
7
+ const suggestionsList = suggestions.map(hint => {
8
+ return {
9
+ text: hint.value,
10
+ displayText: hint.label,
11
+ render: (Element, _self, data) => {
12
+ const itemDiv = document.createElement('div');
13
+ const labelSpan = document.createElement('span');
14
+ labelSpan.textContent = data.text;
15
+ itemDiv.appendChild(labelSpan);
16
+ Element.appendChild(itemDiv);
17
+ }
18
+ };
19
+ });
20
+ return {
21
+ list: suggestionsList,
22
+ from: Pos(curPos.line, token.start),
23
+ to: Pos(curPos.line, token.end)
24
+ };
25
+ };
26
+ export default getCodeSuggestions;
27
+ //# sourceMappingURL=getCodeSuggestions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCodeSuggestions.js","sourceRoot":"","sources":["../../../../src/components/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Hint, Hints } from 'codemirror';\n\nimport { EditorHintOptions } from '../ExpressionBuilder.types';\n\nconst getCodeSuggestions = (codeMirror: Editor, options: EditorHintOptions) => {\n const { suggestions = [] } = options;\n const curPos = codeMirror.getCursor();\n const token = codeMirror.getTokenAt(curPos);\n token.end = curPos.ch;\n\n const suggestionsList = suggestions.map(hint => {\n return {\n text: hint.value,\n displayText: hint.label,\n render: (Element: HTMLLIElement, _self: Hints, data: Hint) => {\n const itemDiv = document.createElement('div');\n const labelSpan = document.createElement('span');\n labelSpan.textContent = data.text;\n itemDiv.appendChild(labelSpan);\n Element.appendChild(itemDiv);\n }\n };\n });\n\n return {\n list: suggestionsList,\n from: Pos(curPos.line, token.start),\n to: Pos(curPos.line, token.end)\n };\n};\n\nexport default getCodeSuggestions;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ExpressionBuilder.d.ts","sourceRoot":"","sources":["../../../src/components/ExpressionBuilder/ExpressionBuilder.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,YAAY,EAKb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAuB,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAIxF,QAAA,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,sBAAsB,GAAG,YAAY,CAiI/E,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"ExpressionBuilder.d.ts","sourceRoot":"","sources":["../../../src/components/ExpressionBuilder/ExpressionBuilder.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,YAAY,EAIb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,sBAAsB,EAEvB,MAAM,2BAA2B,CAAC;AAMnC,QAAA,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,sBAAsB,GAAG,YAAY,CAqG/E,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1,56 +1,28 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
3
- import { Flex, SearchInput, TextArea, useI18n, VisuallyHiddenText } from '@pega/cosmos-react-core';
2
+ import { forwardRef, useImperativeHandle, useMemo, useRef } from 'react';
3
+ import { Flex, SearchInput, useI18n, VisuallyHiddenText } from '@pega/cosmos-react-core';
4
4
  import ExpressionList from './ExpressionList';
5
- import { StyledExpressionBuilder, StyledExpressionEditor } from './ExpressionBuilder.styles';
6
- const ExpressionBuilder = forwardRef(({ list, search, errors, defaultValue, handle, ...restProps }, ref) => {
5
+ import { StyledExpressionBuilder, StyledCodeEditor } from './ExpressionBuilder.styles';
6
+ import CodeEditor from './CodeEditor/CodeEditor';
7
+ import ExpressionBuilderContext from './ExpressionBuilderContext';
8
+ const ExpressionBuilder = forwardRef(({ list, search, errors, defaultValue, handle, fetchSuggestions, ...restProps }, ref) => {
7
9
  const t = useI18n();
8
- const textArea = useRef();
9
- const [selection, setSelection] = useState({
10
- start: 0,
11
- end: 0
12
- });
10
+ const codeEditorHandle = useRef(null);
13
11
  const getExpression = () => {
14
- return textArea.current?.value || '';
12
+ return codeEditorHandle.current?.getValue() || '';
15
13
  };
16
14
  useImperativeHandle(handle, () => ({
17
15
  getExpression
18
16
  }), [getExpression]);
19
17
  const addExpression = (expression) => {
20
- if (!textArea.current)
21
- return;
22
- const currentValue = textArea.current.value;
23
- const newValue = `${currentValue.slice(0, selection.start)}${expression}${currentValue.slice(selection.end)}`;
24
- textArea.current.value = newValue;
25
- setSelection(prev => {
26
- return { start: prev.start + expression.length, end: prev.start + expression.length };
27
- });
28
- };
29
- const onBlur = () => {
30
- if (!textArea.current)
31
- return;
32
- const lastIndex = textArea.current.value.length >= 0 ? textArea.current.value.length : 0;
33
- const selectionStart = textArea.current.selectionStart === null ? lastIndex : textArea.current.selectionStart;
34
- const selectionEnd = textArea.current.selectionEnd === null ? lastIndex : textArea.current.selectionEnd;
35
- const currentSelection = {
36
- start: selectionStart,
37
- end: selectionEnd
38
- };
39
- if (selectionStart > selectionEnd) {
40
- currentSelection.start = selectionEnd;
41
- currentSelection.end = selectionStart;
42
- }
43
- setSelection(currentSelection);
18
+ codeEditorHandle.current?.insertText(expression);
44
19
  };
45
20
  const onItemAdd = (id) => {
46
21
  list.onItemAdd(id, addExpression);
47
22
  };
48
- useEffect(() => {
49
- if (defaultValue && textArea.current) {
50
- setSelection({ start: defaultValue.length, end: defaultValue.length });
51
- textArea.current.value = defaultValue;
52
- }
53
- }, []);
23
+ const ctxValue = useMemo(() => ({
24
+ accent: search.accent
25
+ }), [search.accent]);
54
26
  return (_jsxs(Flex, { ...restProps, as: StyledExpressionBuilder, ref: ref, container: {
55
27
  justify: 'between',
56
28
  colGap: 2,
@@ -64,13 +36,15 @@ const ExpressionBuilder = forwardRef(({ list, search, errors, defaultValue, hand
64
36
  }, item: {
65
37
  grow: 1,
66
38
  basis: '50%'
67
- }, children: [_jsx(SearchInput, { ...search }), _jsx(ExpressionList, { ...list, onItemAdd: onItemAdd })] }), _jsx(Flex, { as: StyledExpressionEditor, container: {
39
+ }, children: [_jsx(SearchInput, { ...search }), _jsx(ExpressionBuilderContext.Provider, { value: ctxValue, children: _jsx(ExpressionList, { ...list, onItemAdd: onItemAdd }) })] }), _jsx(Flex, { as: StyledCodeEditor, container: {
68
40
  direction: 'column',
69
41
  justify: 'between'
70
42
  }, item: {
71
43
  grow: 1,
72
44
  basis: '50%'
73
- }, children: _jsx(TextArea, { status: errors ? 'error' : undefined, ref: textArea, onBlur: onBlur, label: t('expression_editor'), labelHidden: true, info: errors }) })] }));
45
+ }, children: _jsx(CodeEditor, { fetchSuggestions: fetchSuggestions, codeEditorHandle: codeEditorHandle, autoCompleteTriggers: ['.', '@'], editorConfigProps: {
46
+ mode: 'expression'
47
+ }, defaultValue: defaultValue }) })] }));
74
48
  });
75
49
  export default ExpressionBuilder;
76
50
  //# sourceMappingURL=ExpressionBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpressionBuilder.js","sourceRoot":"","sources":["../../../src/components/ExpressionBuilder/ExpressionBuilder.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,SAAS,EACT,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,IAAI,EAEJ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,MAAM,iBAAiB,GAA6D,UAAU,CAC5F,CACE,EACE,IAAI,EACJ,MAAM,EACN,MAAM,EACN,YAAY,EACZ,MAAM,EACN,GAAG,SAAS,EAC4B,EAC1C,GAAkC,EAClC,EAAE;IACF,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,QAAQ,GAAG,MAAM,EAAoB,CAAC;IAC5C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAiC;QACzE,KAAK,EAAE,CAAC;QACR,GAAG,EAAE,CAAC;KACP,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,GAAG,EAAE;QACzB,OAAO,QAAQ,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;IACvC,CAAC,CAAC;IAEF,mBAAmB,CACjB,MAAM,EACN,GAAG,EAAE,CAAC,CAAC;QACL,aAAa;KACd,CAAC,EACF,CAAC,aAAa,CAAC,CAChB,CAAC;IAEF,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAE,EAAE;QAC3C,IAAI,CAAC,QAAQ,CAAC,OAAO;YAAE,OAAO;QAC9B,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;QAC5C,MAAM,QAAQ,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S,EAAE;oBACT,SAAS,EAAE,QAAQ;oBACnB,OAAO,EAAE,SAAS;iBACnB,EACD,IAAI,EAAE;oBACJ,IAAI,EAAE,CAAC;oBACP,KAAK,EAAE,KAAK;iBACb,YAED,KAAC,QAAQ,IACP,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EACpC,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,CAAC,mBAAmB,CAAC,EAC7B,WAAW,QACX,IAAI,EAAE,MAAM,GACZ,GACG,IACF,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState\n} from 'react';\n\nimport {\n Flex,\n ForwardProps,\n SearchInput,\n TextArea,\n useI18n,\n VisuallyHiddenText\n} from '@pega/cosmos-react-core';\n\nimport { ExpressionItemProps, ExpressionBuilderProps } from './ExpressionBuilder.types';\nimport ExpressionList from './ExpressionList';\nimport { StyledExpressionBuilder, StyledExpressionEditor } from './ExpressionBuilder.styles';\n\nconst ExpressionBuilder: FunctionComponent<ExpressionBuilderProps & ForwardProps> = forwardRef(\n (\n {\n list,\n search,\n errors,\n defaultValue,\n handle,\n ...restProps\n }: PropsWithoutRef<ExpressionBuilderProps>,\n ref: ExpressionBuilderProps['ref']\n ) => {\n const t = useI18n();\n const textArea = useRef<HTMLInputElement>();\n const [selection, setSelection] = useState<{ start: number; end: number }>({\n start: 0,\n end: 0\n });\n\n const getExpression = () => {\n return textArea.current?.value || '';\n };\n\n useImperativeHandle(\n handle,\n () => ({\n getExpression\n }),\n [getExpression]\n );\n\n const addExpression = (expression: string) => {\n if (!textArea.current) return;\n const currentValue = textArea.current.value;\n const newValue = `${currentValue.slice(0, selection.start)}${expression}${currentValue.slice(\n selection.end\n )}`;\n textArea.current.value = newValue;\n setSelection(prev => {\n return { start: prev.start + expression.length, end: prev.start + expression.length };\n });\n };\n\n const onBlur = () => {\n if (!textArea.current) return;\n const lastIndex = textArea.current.value.length >= 0 ? textArea.current.value.length : 0;\n const selectionStart =\n textArea.current.selectionStart === null ? lastIndex : textArea.current.selectionStart;\n const selectionEnd =\n textArea.current.selectionEnd === null ? lastIndex : textArea.current.selectionEnd;\n const currentSelection = {\n start: selectionStart,\n end: selectionEnd\n };\n if (selectionStart > selectionEnd) {\n currentSelection.start = selectionEnd;\n currentSelection.end = selectionStart;\n }\n\n setSelection(currentSelection);\n };\n\n const onItemAdd = (id: ExpressionItemProps['id']) => {\n list.onItemAdd(id, addExpression);\n };\n\n useEffect(() => {\n if (defaultValue && textArea.current) {\n setSelection({ start: defaultValue.length, end: defaultValue.length });\n textArea.current.value = defaultValue;\n }\n }, []);\n\n return (\n <Flex\n {...restProps}\n as={StyledExpressionBuilder}\n ref={ref}\n container={{\n justify: 'between',\n colGap: 2,\n pad: 1\n }}\n item={{\n grow: 1\n }}\n >\n <VisuallyHiddenText aria-live='polite' role='status'>\n {t('results_count', [list.items?.length || 0], { count: list.items?.length || 0 })}\n </VisuallyHiddenText>\n {/* Column 1 */}\n <Flex\n container={{\n direction: 'column',\n justify: 'between',\n gap: 1\n }}\n item={{\n grow: 1,\n basis: '50%'\n }}\n >\n <SearchInput {...search} />\n <ExpressionList {...list} onItemAdd={onItemAdd} />\n </Flex>\n {/* Column 2 */}\n <Flex\n as={StyledExpressionEditor}\n container={{\n direction: 'column',\n justify: 'between'\n }}\n item={{\n grow: 1,\n basis: '50%'\n }}\n >\n <TextArea\n status={errors ? 'error' : undefined}\n ref={textArea}\n onBlur={onBlur}\n label={t('expression_editor')}\n labelHidden\n info={errors}\n />\n </Flex>\n </Flex>\n );\n }\n);\n\nexport default ExpressionBuilder;\n"]}
1
+ {"version":3,"file":"ExpressionBuilder.js","sourceRoot":"","sources":["../../../src/components/ExpressionBuilder/ExpressionBuilder.tsx"],"names":[],"mappings":";A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AAE,YAAY,GAC1B,GACG,IACF,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useImperativeHandle,\n useMemo,\n useRef\n} from 'react';\n\nimport {\n Flex,\n ForwardProps,\n SearchInput,\n useI18n,\n VisuallyHiddenText\n} from '@pega/cosmos-react-core';\n\nimport {\n ExpressionItemProps,\n ExpressionBuilderProps,\n EditorState\n} from './ExpressionBuilder.types';\nimport ExpressionList from './ExpressionList';\nimport { StyledExpressionBuilder, StyledCodeEditor } from './ExpressionBuilder.styles';\nimport CodeEditor from './CodeEditor/CodeEditor';\nimport ExpressionBuilderContext from './ExpressionBuilderContext';\n\nconst ExpressionBuilder: FunctionComponent<ExpressionBuilderProps & ForwardProps> = forwardRef(\n (\n {\n list,\n search,\n errors,\n defaultValue,\n handle,\n fetchSuggestions,\n ...restProps\n }: PropsWithoutRef<ExpressionBuilderProps>,\n ref: ExpressionBuilderProps['ref']\n ) => {\n const t = useI18n();\n const codeEditorHandle = useRef<EditorState>(null);\n\n const getExpression = () => {\n return codeEditorHandle.current?.getValue() || '';\n };\n\n useImperativeHandle(\n handle,\n () => ({\n getExpression\n }),\n [getExpression]\n );\n\n const addExpression = (expression: string) => {\n codeEditorHandle.current?.insertText(expression);\n };\n const onItemAdd = (id: ExpressionItemProps['id']) => {\n list.onItemAdd(id, addExpression);\n };\n\n const ctxValue = useMemo(\n () => ({\n accent: search.accent\n }),\n [search.accent]\n );\n\n return (\n <Flex\n {...restProps}\n as={StyledExpressionBuilder}\n ref={ref}\n container={{\n justify: 'between',\n colGap: 2,\n pad: 1\n }}\n item={{\n grow: 1\n }}\n >\n <VisuallyHiddenText aria-live='polite' role='status'>\n {t('results_count', [list.items?.length || 0], { count: list.items?.length || 0 })}\n </VisuallyHiddenText>\n {/* Column 1 */}\n <Flex\n container={{\n direction: 'column',\n justify: 'between',\n gap: 1\n }}\n item={{\n grow: 1,\n basis: '50%'\n }}\n >\n <SearchInput {...search} />\n <ExpressionBuilderContext.Provider value={ctxValue}>\n <ExpressionList {...list} onItemAdd={onItemAdd} />\n </ExpressionBuilderContext.Provider>\n </Flex>\n {/* Column 2 */}\n <Flex\n as={StyledCodeEditor}\n container={{\n direction: 'column',\n justify: 'between'\n }}\n item={{\n grow: 1,\n basis: '50%'\n }}\n >\n <CodeEditor\n fetchSuggestions={fetchSuggestions}\n codeEditorHandle={codeEditorHandle}\n autoCompleteTriggers={['.', '@']}\n editorConfigProps={{\n mode: 'expression'\n }}\n defaultValue={defaultValue}\n />\n </Flex>\n </Flex>\n );\n }\n);\n\nexport default ExpressionBuilder;\n"]}
@@ -1,8 +1,9 @@
1
+ /// <reference types="react" />
1
2
  import { ExpressionItemProps } from './ExpressionBuilder.types';
3
+ export declare const StyledPrimaryText: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").TextProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
2
4
  export declare const StyledExpressionSummary: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
3
5
  export declare const StyledExpressionList: import("styled-components").StyledComponent<"ul", import("styled-components").DefaultTheme, {}, never>;
4
6
  export declare const StyledExpressionBuilder: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
5
- export declare const StyledExpressionEditor: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
6
7
  export declare const StyledParamsGroup: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
7
8
  export declare const StyledInputParamsGroup: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
8
9
  export declare const StyledExpressionDetails: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -10,4 +11,5 @@ export declare const StyledExpandCollapseContent: import("styled-components").St
10
11
  export declare const StyledExpressionItem: import("styled-components").StyledComponent<"li", import("styled-components").DefaultTheme, {
11
12
  expanded: ExpressionItemProps['expanded'];
12
13
  }, never>;
14
+ export declare const StyledCodeEditor: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
13
15
  //# sourceMappingURL=ExpressionBuilder.styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpressionBuilder.styles.d.ts","sourceRoot":"","sources":["../../../src/components/ExpressionBuilder/ExpressionBuilder.styles.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,eAAO,MAAM,uBAAuB,yGAKlC,CAAC;AAIH,eAAO,MAAM,oBAAoB,wGAIhC,CAAC;AAEF,eAAO,MAAM,uBAAuB,yGAYlC,CAAC;AAIH,eAAO,MAAM,sBAAsB,yGAMjC,CAAC;AAEH,eAAO,MAAM,iBAAiB,yGAQ5B,CAAC;AAIH,eAAO,MAAM,sBAAsB,yGAIjC,CAAC;AAIH,eAAO,MAAM,uBAAuB,yGAAe,CAAC;AAIpD,eAAO,MAAM,2BAA2B,yGAQtC,CAAC;AAIH,eAAO,MAAM,oBAAoB;cACrB,mBAAmB,CAAC,UAAU,CAAC;SAkBzC,CAAC"}
1
+ {"version":3,"file":"ExpressionBuilder.styles.d.ts","sourceRoot":"","sources":["../../../src/components/ExpressionBuilder/ExpressionBuilder.styles.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,mOAE7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,yGAKlC,CAAC;AAIH,eAAO,MAAM,oBAAoB,wGAIhC,CAAC;AAEF,eAAO,MAAM,uBAAuB,yGAalC,CAAC;AAIH,eAAO,MAAM,iBAAiB,yGAQ5B,CAAC;AAIH,eAAO,MAAM,sBAAsB,yGAIjC,CAAC;AAIH,eAAO,MAAM,uBAAuB,yGAAe,CAAC;AAIpD,eAAO,MAAM,2BAA2B,yGAQtC,CAAC;AAIH,eAAO,MAAM,oBAAoB;cACrB,mBAAmB,CAAC,UAAU,CAAC;SAuBzC,CAAC;AAIH,eAAO,MAAM,gBAAgB,yGA6c3B,CAAC"}