@pega/cosmos-react-rte 4.0.0-dev.19.1 → 4.0.0-dev.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +9 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js +239 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts +23 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js +2 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js.map +1 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts +322 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.js +27 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.js.map +1 -0
- package/lib/components/DynamicContentEditor/index.d.ts +3 -0
- package/lib/components/DynamicContentEditor/index.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/index.js +2 -0
- package/lib/components/DynamicContentEditor/index.js.map +1 -0
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +3 -3
- package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts +3 -2
- package/lib/components/RichTextEditor/utils/EditorCommands.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/EditorCommands.js.map +1 -1
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { ForwardProps } from '@pega/cosmos-react-core';
|
|
3
|
+
import { DynamicContentEditorProps } from './DynamicContentEditor.types';
|
|
4
|
+
export declare const StyledSearchPopover: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
|
|
5
|
+
offset?: number | undefined;
|
|
6
|
+
}, never>;
|
|
7
|
+
declare const DynamicContentEditor: FunctionComponent<DynamicContentEditorProps & ForwardProps>;
|
|
8
|
+
export default DynamicContentEditor;
|
|
9
|
+
//# sourceMappingURL=DynamicContentEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicContentEditor.d.ts","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/DynamicContentEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAgD,MAAM,OAAO,CAAC;AAIpG,OAAO,EAGL,YAAY,EAab,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,yBAAyB,EAAY,MAAM,8BAA8B,CAAC;AAOnF,eAAO,MAAM,mBAAmB;;SAE/B,CAAC;AAIF,QAAA,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,yBAAyB,GAAG,YAAY,CA2TnF,CAAC;AAEJ,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useEffect, useState } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { Button, defaultThemeProp, Menu, menuHelpers, Modal, Popover, StyledPopover, useModalManager, useConsolidatedRef, useI18n, useUID } from '@pega/cosmos-react-core';
|
|
5
|
+
import { getKeyCommand } from '@pega/cosmos-react-rte/lib/components/RichTextEditor/Toolbar/utils';
|
|
6
|
+
import { Editor } from '../Editor';
|
|
7
|
+
import { pegaReferenceElementStyle, createPegaReferenceElement } from './PegaCustomElement';
|
|
8
|
+
const StyledDynamicContentEditor = styled.div ``;
|
|
9
|
+
export const StyledSearchPopover = styled(StyledPopover) `
|
|
10
|
+
min-width: 20rem;
|
|
11
|
+
`;
|
|
12
|
+
StyledDynamicContentEditor.defaultProps = defaultThemeProp;
|
|
13
|
+
const DynamicContentEditor = forwardRef(({ form: { dynamicContentPicker, onSubmit }, onActiveFieldChange, label, toolbar, fieldItems, defaultValue, onBlur, ...restProps }, ref) => {
|
|
14
|
+
const menuID = useUID();
|
|
15
|
+
const { create } = useModalManager();
|
|
16
|
+
const t = useI18n();
|
|
17
|
+
const modalMethods = useRef();
|
|
18
|
+
const [editor, setEditor] = useState();
|
|
19
|
+
const [bookmark, setBookmark] = useState();
|
|
20
|
+
const [fieldMenuItems, setFieldMenuItems] = useState(fieldItems || []);
|
|
21
|
+
const [currentElementId, setCurrentElementId] = useState('');
|
|
22
|
+
const [currentElementContent, setCurrentElementContent] = useState('');
|
|
23
|
+
const [currentCursorPosition, setCurrentCursorPosition] = useState({
|
|
24
|
+
bottom: 0,
|
|
25
|
+
height: 0,
|
|
26
|
+
left: 0,
|
|
27
|
+
right: 0,
|
|
28
|
+
top: 0,
|
|
29
|
+
width: 0,
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0,
|
|
32
|
+
toJSON: () => { }
|
|
33
|
+
});
|
|
34
|
+
const [showFieldsPopover, setShowFieldsPopover] = useState(false);
|
|
35
|
+
const fieldPopoverRef = useRef(null);
|
|
36
|
+
const editorRef = useConsolidatedRef(ref);
|
|
37
|
+
const tooltip = getKeyCommand(navigator.appVersion.includes('Mac'), ({ ctrl }) => `${t('rte_insert_field')} (${ctrl}/)`);
|
|
38
|
+
const insertField = (field) => {
|
|
39
|
+
if (!editor)
|
|
40
|
+
return;
|
|
41
|
+
const fieldContent = `<pega-reference role="button" contenteditable="false" data-rule-type='field' data-rule-id=${field.id}>${field.text}</pega-reference>`;
|
|
42
|
+
if (bookmark) {
|
|
43
|
+
editor.selection.moveToBookmark(bookmark);
|
|
44
|
+
editor.selection.setContent(fieldContent);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
editor.insertContent(fieldContent);
|
|
48
|
+
}
|
|
49
|
+
modalMethods.current?.dismiss();
|
|
50
|
+
};
|
|
51
|
+
const modalProps = {
|
|
52
|
+
children: dynamicContentPicker,
|
|
53
|
+
heading: t('rte_insert_field'),
|
|
54
|
+
actions: (_jsxs(_Fragment, { children: [_jsx(Button, { variant: 'secondary', onClick: () => modalMethods.current?.dismiss(), children: t('cancel') }), _jsx(Button, { variant: 'primary', onClick: () => onSubmit(insertField), children: t('submit') })] })),
|
|
55
|
+
center: true,
|
|
56
|
+
onAfterClose: () => {
|
|
57
|
+
setBookmark(undefined);
|
|
58
|
+
setCurrentElementId('');
|
|
59
|
+
setCurrentElementContent('');
|
|
60
|
+
onActiveFieldChange({ id: '', text: '' });
|
|
61
|
+
},
|
|
62
|
+
onBeforeOpen: () => {
|
|
63
|
+
if (currentElementId) {
|
|
64
|
+
onActiveFieldChange({ id: currentElementId, text: currentElementContent });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const findAndRenameField = (fieldId) => {
|
|
69
|
+
if (!editor || !fieldMenuItems)
|
|
70
|
+
return;
|
|
71
|
+
const selectedRange = editor.selection.getRng();
|
|
72
|
+
const endOffset = selectedRange.endOffset;
|
|
73
|
+
const stringToSearch = selectedRange.commonAncestorContainer.nodeValue?.slice(0, endOffset);
|
|
74
|
+
if (stringToSearch === undefined)
|
|
75
|
+
return;
|
|
76
|
+
const splitSearch = stringToSearch.split(' ');
|
|
77
|
+
const fieldString = splitSearch[splitSearch.length - 1];
|
|
78
|
+
const range = editor.getDoc().createRange();
|
|
79
|
+
const startPos = stringToSearch.lastIndexOf(fieldString);
|
|
80
|
+
const endPos = startPos + fieldString.length;
|
|
81
|
+
range.setStart(selectedRange.commonAncestorContainer, startPos);
|
|
82
|
+
range.setEnd(selectedRange.commonAncestorContainer, endPos);
|
|
83
|
+
editor.getDoc().getSelection()?.removeAllRanges();
|
|
84
|
+
editor.getDoc().getSelection()?.addRange(range);
|
|
85
|
+
const selectedField = menuHelpers.getItem(fieldMenuItems, fieldId);
|
|
86
|
+
if (selectedField) {
|
|
87
|
+
editor.selection.setContent(`<pega-reference role="button" contenteditable="false" data-rule-type="field" data-rule-id=".${selectedField.id}">${selectedField.primary}</pega-reference>`);
|
|
88
|
+
setShowFieldsPopover(false);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const hidePopover = () => {
|
|
92
|
+
if (fieldPopoverRef)
|
|
93
|
+
setShowFieldsPopover(false);
|
|
94
|
+
};
|
|
95
|
+
const filterFieldMenu = (searchString) => {
|
|
96
|
+
setShowFieldsPopover(true);
|
|
97
|
+
setFieldMenuItems(fieldItems || []);
|
|
98
|
+
if (/\s/.test(searchString)) {
|
|
99
|
+
setShowFieldsPopover(false);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (searchString && fieldMenuItems) {
|
|
103
|
+
const newFieldMenuItems = menuHelpers
|
|
104
|
+
.flatten(fieldMenuItems)
|
|
105
|
+
.filter(({ primary }) => primary.toLowerCase().startsWith(searchString.toLocaleLowerCase()));
|
|
106
|
+
if (newFieldMenuItems) {
|
|
107
|
+
setShowFieldsPopover(true);
|
|
108
|
+
setFieldMenuItems(newFieldMenuItems);
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
setShowFieldsPopover(false);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const updateBookmarkAndCurrentElement = (editorSelection) => {
|
|
115
|
+
const targetEl = editorSelection.getNode();
|
|
116
|
+
const fieldId = targetEl.getAttribute('data-rule-id');
|
|
117
|
+
const fieldValue = targetEl.innerText;
|
|
118
|
+
setBookmark(editorSelection.getBookmark());
|
|
119
|
+
setCurrentElementId(fieldId || '');
|
|
120
|
+
setCurrentElementContent(fieldValue);
|
|
121
|
+
};
|
|
122
|
+
const handleElementClick = ({ target }) => {
|
|
123
|
+
if (editor && target && target.tagName === 'PEGA-REFERENCE') {
|
|
124
|
+
updateBookmarkAndCurrentElement(editor.selection);
|
|
125
|
+
}
|
|
126
|
+
hidePopover();
|
|
127
|
+
};
|
|
128
|
+
const onInsertField = (incEditor) => {
|
|
129
|
+
const targetEl = incEditor.selection.getNode();
|
|
130
|
+
if (targetEl.tagName === 'PEGA-REFERENCE') {
|
|
131
|
+
updateBookmarkAndCurrentElement(incEditor.selection);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
modalMethods.current = create(Modal, modalProps);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const isPegaRefActive = (incEditor) => {
|
|
138
|
+
const targetEl = incEditor.selection.getNode();
|
|
139
|
+
return targetEl.tagName === 'PEGA-REFERENCE';
|
|
140
|
+
};
|
|
141
|
+
const fieldSelectionPopover = (_jsx(Popover, { show: showFieldsPopover, strategy: 'fixed', ref: fieldPopoverRef, target: {
|
|
142
|
+
getBoundingClientRect() {
|
|
143
|
+
return currentCursorPosition;
|
|
144
|
+
}
|
|
145
|
+
}, modifiers: [
|
|
146
|
+
{
|
|
147
|
+
name: 'offset',
|
|
148
|
+
options: {
|
|
149
|
+
offset: () => {
|
|
150
|
+
const iframe = editorRef.current?.element?.querySelector('iframe');
|
|
151
|
+
const iframeRect = iframe?.getBoundingClientRect();
|
|
152
|
+
const x = iframeRect?.x ?? 0;
|
|
153
|
+
const y = iframeRect?.y ?? 0;
|
|
154
|
+
return [x, y];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
], placement: 'bottom-start', children: fieldMenuItems && (_jsx(Menu, { id: menuID, items: fieldMenuItems, as: StyledSearchPopover, focusControlEl: editor?.getBody() || undefined, mode: 'action', onItemClick: findAndRenameField, variant: 'drill-down' })) }));
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (currentElementId && currentElementContent)
|
|
161
|
+
modalMethods.current = create(Modal, modalProps);
|
|
162
|
+
}, [currentElementId, currentElementContent]);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
editor?.getDoc().addEventListener('click', handleElementClick);
|
|
165
|
+
return () => {
|
|
166
|
+
editor?.getDoc().removeEventListener('click', handleElementClick);
|
|
167
|
+
};
|
|
168
|
+
}, [editor, editorRef.current]);
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (modalMethods.current) {
|
|
171
|
+
modalMethods.current.update(modalProps);
|
|
172
|
+
}
|
|
173
|
+
}, [modalProps]);
|
|
174
|
+
const onEditorChange = (formEditor) => {
|
|
175
|
+
if (formEditor) {
|
|
176
|
+
const targetEl = formEditor.selection.getBoundingClientRect();
|
|
177
|
+
const { left = 0, top = 0 } = targetEl ?? {};
|
|
178
|
+
setCurrentCursorPosition({
|
|
179
|
+
...formEditor.selection.getBoundingClientRect(),
|
|
180
|
+
x: left,
|
|
181
|
+
y: top,
|
|
182
|
+
toJSON: () => { }
|
|
183
|
+
});
|
|
184
|
+
if (formEditor.selection.isCollapsed()) {
|
|
185
|
+
// get the full line string
|
|
186
|
+
const selectedRange = formEditor.selection.getRng();
|
|
187
|
+
const endOffset = selectedRange.endOffset;
|
|
188
|
+
const stringToSearch = selectedRange.commonAncestorContainer.nodeValue?.slice(0, endOffset);
|
|
189
|
+
const fieldString = stringToSearch?.split(' ')[stringToSearch.split(' ').length - 1];
|
|
190
|
+
if (fieldString?.startsWith('@') &&
|
|
191
|
+
fieldString.indexOf('@') === fieldString.lastIndexOf('@')) {
|
|
192
|
+
filterFieldMenu(fieldString.slice(1));
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
setShowFieldsPopover(false);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const onKeyDown = event => {
|
|
200
|
+
if ((event?.key === 'Enter' ||
|
|
201
|
+
event?.key === 'ArrowLeft' ||
|
|
202
|
+
event?.key === 'ArrowRight' ||
|
|
203
|
+
event?.key === 'ArrowDown' ||
|
|
204
|
+
event?.key === 'ArrowUp') &&
|
|
205
|
+
!!fieldPopoverRef.current) {
|
|
206
|
+
event?.preventDefault();
|
|
207
|
+
}
|
|
208
|
+
if (event?.key === 'Escape' && !!fieldPopoverRef.current) {
|
|
209
|
+
hidePopover();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
return (_jsx(Editor, { ref: editorRef, ...restProps, label: label, toolbar: toolbar, customComponents: [
|
|
213
|
+
{
|
|
214
|
+
createCustomElement: createPegaReferenceElement,
|
|
215
|
+
name: 'pega-reference',
|
|
216
|
+
extensionAttributes: ['contenteditable'],
|
|
217
|
+
style: pegaReferenceElementStyle
|
|
218
|
+
}
|
|
219
|
+
], customActions: [
|
|
220
|
+
{
|
|
221
|
+
icon: 'code',
|
|
222
|
+
text: tooltip,
|
|
223
|
+
onMouseDown: () => {
|
|
224
|
+
modalMethods.current = create(Modal, modalProps);
|
|
225
|
+
},
|
|
226
|
+
active: isPegaRefActive,
|
|
227
|
+
shortcut: {
|
|
228
|
+
pattern: 'meta+191',
|
|
229
|
+
description: tooltip,
|
|
230
|
+
command: onInsertField
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
], onInit: setEditor, onChange: onEditorChange, onBlur: () => {
|
|
234
|
+
onBlur?.();
|
|
235
|
+
hidePopover();
|
|
236
|
+
}, onKeyDown: onKeyDown, defaultValue: defaultValue, children: fieldSelectionPopover }));
|
|
237
|
+
});
|
|
238
|
+
export default DynamicContentEditor;
|
|
239
|
+
//# sourceMappingURL=DynamicContentEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicContentEditor.js","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/DynamicContentEditor.tsx"],"names":[],"mapp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,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE;YACxD,WAAW,EAAE,CAAC;SACf;IACH,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,MAAM,IACL,GAAG,EAAE,SAAS,KACV,SAAS,EACb,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE;YAChB;gBACE,mBAAmB,EAAE,0BAA0B;gBAC/C,IAAI,EAAE,gBAAgB;gBACtB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;gBACxC,KAAK,EAAE,yBAAyB;aACjC;SACF,EACD,aAAa,EAAE;YACb;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,GAAG,EAAE;oBAChB,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;gBACnD,CAAC;gBACD,MAAM,EAAE,eAAe;gBACvB,QAAQ,EAAE;oBACR,OAAO,EAAE,UAAU;oBACnB,WAAW,EAAE,OAAO;oBACpB,OAAO,EAAE,aAAa;iBACvB;aACF;SACF,EACD,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,GAAG,EAAE;YACX,MAAM,EAAE,EAAE,CAAC;YACX,WAAW,EAAE,CAAC;QAChB,CAAC,EACD,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,YAAY,YAEzB,qBAAqB,GACf,CACV,CAAC;AACJ,CAAC,CACF,CAAC;AAEJ,eAAe,oBAAoB,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, useRef, useEffect, useState } from 'react';\nimport styled from 'styled-components';\nimport { Bookmark, Editor as TinyMCEEditor, EditorSelection } from 'tinymce';\n\nimport {\n Button,\n defaultThemeProp,\n ForwardProps,\n Menu,\n menuHelpers,\n MenuProps,\n Modal,\n ModalMethods,\n Popover,\n PropsWithDefaults,\n StyledPopover,\n useModalManager,\n useConsolidatedRef,\n useI18n,\n useUID\n} from '@pega/cosmos-react-core';\nimport { getKeyCommand } from '@pega/cosmos-react-rte/lib/components/RichTextEditor/Toolbar/utils';\n\nimport { Editor, EditorProps } from '../Editor';\n\nimport { DynamicContentEditorProps, ItemType } from './DynamicContentEditor.types';\nimport { pegaReferenceElementStyle, createPegaReferenceElement } from './PegaCustomElement';\n\ntype DynamicContentEditorPropsWithDefaults = PropsWithDefaults<DynamicContentEditorProps>;\n\nconst StyledDynamicContentEditor = styled.div<DynamicContentEditorPropsWithDefaults>``;\n\nexport const StyledSearchPopover = styled(StyledPopover)`\n min-width: 20rem;\n`;\n\nStyledDynamicContentEditor.defaultProps = defaultThemeProp;\n\nconst DynamicContentEditor: FunctionComponent<DynamicContentEditorProps & ForwardProps> =\n forwardRef(\n (\n {\n form: { dynamicContentPicker, onSubmit },\n onActiveFieldChange,\n label,\n toolbar,\n fieldItems,\n defaultValue,\n onBlur,\n ...restProps\n }: PropsWithoutRef<DynamicContentEditorProps>,\n ref: DynamicContentEditorProps['ref']\n ) => {\n const menuID = useUID();\n const { create } = useModalManager();\n const t = useI18n();\n\n const modalMethods = useRef<ModalMethods>();\n const [editor, setEditor] = useState<TinyMCEEditor | undefined>();\n const [bookmark, setBookmark] = useState<Bookmark | undefined>();\n const [fieldMenuItems, setFieldMenuItems] = useState<MenuProps['items']>(fieldItems || []);\n const [currentElementId, setCurrentElementId] = useState('');\n const [currentElementContent, setCurrentElementContent] = useState('');\n const [currentCursorPosition, setCurrentCursorPosition] = useState({\n bottom: 0,\n height: 0,\n left: 0,\n right: 0,\n top: 0,\n width: 0,\n x: 0,\n y: 0,\n toJSON: () => {}\n });\n const [showFieldsPopover, setShowFieldsPopover] = useState<boolean>(false);\n\n const fieldPopoverRef = useRef<HTMLDivElement>(null);\n const editorRef = useConsolidatedRef(ref);\n\n const tooltip = getKeyCommand(\n navigator.appVersion.includes('Mac'),\n ({ ctrl }) => `${t('rte_insert_field')} (${ctrl}/)`\n );\n\n const insertField = (field: ItemType) => {\n if (!editor) return;\n\n const fieldContent = `<pega-reference role=\"button\" contenteditable=\"false\" data-rule-type='field' data-rule-id=${field.id}>${field.text}</pega-reference>`;\n if (bookmark) {\n editor.selection.moveToBookmark(bookmark);\n editor.selection.setContent(fieldContent);\n } else {\n editor.insertContent(fieldContent);\n }\n\n modalMethods.current?.dismiss();\n };\n\n const modalProps = {\n children: dynamicContentPicker,\n heading: t('rte_insert_field'),\n actions: (\n <>\n <Button variant='secondary' onClick={() => modalMethods.current?.dismiss()}>\n {t('cancel')}\n </Button>\n <Button variant='primary' onClick={() => onSubmit(insertField)}>\n {t('submit')}\n </Button>\n </>\n ),\n center: true,\n onAfterClose: () => {\n setBookmark(undefined);\n setCurrentElementId('');\n setCurrentElementContent('');\n onActiveFieldChange({ id: '', text: '' });\n },\n onBeforeOpen: () => {\n if (currentElementId) {\n onActiveFieldChange({ id: currentElementId, text: currentElementContent });\n }\n }\n };\n\n const findAndRenameField = (fieldId: string) => {\n if (!editor || !fieldMenuItems) return;\n\n const selectedRange = editor.selection.getRng();\n const endOffset = selectedRange.endOffset;\n const stringToSearch = selectedRange.commonAncestorContainer.nodeValue?.slice(0, endOffset);\n if (stringToSearch === undefined) return;\n\n const splitSearch = stringToSearch.split(' ');\n const fieldString = splitSearch[splitSearch.length - 1];\n const range = editor.getDoc().createRange();\n\n const startPos = stringToSearch.lastIndexOf(fieldString);\n const endPos = startPos + fieldString.length;\n range.setStart(selectedRange.commonAncestorContainer, startPos);\n range.setEnd(selectedRange.commonAncestorContainer, endPos);\n editor.getDoc().getSelection()?.removeAllRanges();\n editor.getDoc().getSelection()?.addRange(range);\n\n const selectedField = menuHelpers.getItem(fieldMenuItems, fieldId);\n if (selectedField) {\n editor.selection.setContent(\n `<pega-reference role=\"button\" contenteditable=\"false\" data-rule-type=\"field\" data-rule-id=\".${selectedField.id}\">${selectedField.primary}</pega-reference>`\n );\n setShowFieldsPopover(false);\n }\n };\n\n const hidePopover = () => {\n if (fieldPopoverRef) setShowFieldsPopover(false);\n };\n\n const filterFieldMenu = (searchString: string) => {\n setShowFieldsPopover(true);\n setFieldMenuItems(fieldItems || []);\n if (/\\s/.test(searchString)) {\n setShowFieldsPopover(false);\n return;\n }\n if (searchString && fieldMenuItems) {\n const newFieldMenuItems: MenuProps['items'] = menuHelpers\n .flatten(fieldMenuItems)\n .filter(({ primary }) =>\n primary.toLowerCase().startsWith(searchString.toLocaleLowerCase())\n );\n if (newFieldMenuItems) {\n setShowFieldsPopover(true);\n setFieldMenuItems(newFieldMenuItems);\n } else setShowFieldsPopover(false);\n }\n };\n\n const updateBookmarkAndCurrentElement = (editorSelection: EditorSelection) => {\n const targetEl = editorSelection.getNode() as HTMLElement;\n const fieldId = targetEl.getAttribute('data-rule-id');\n const fieldValue = targetEl.innerText;\n setBookmark(editorSelection.getBookmark());\n setCurrentElementId(fieldId || '');\n setCurrentElementContent(fieldValue);\n };\n\n const handleElementClick = ({ target }: MouseEvent) => {\n if (editor && target && (target as HTMLElement).tagName === 'PEGA-REFERENCE') {\n updateBookmarkAndCurrentElement(editor.selection);\n }\n hidePopover();\n };\n\n const onInsertField = (incEditor: TinyMCEEditor) => {\n const targetEl = incEditor.selection.getNode();\n if (targetEl.tagName === 'PEGA-REFERENCE') {\n updateBookmarkAndCurrentElement(incEditor.selection);\n } else {\n modalMethods.current = create(Modal, modalProps);\n }\n };\n\n const isPegaRefActive = (incEditor: TinyMCEEditor) => {\n const targetEl = incEditor.selection.getNode();\n return targetEl.tagName === 'PEGA-REFERENCE';\n };\n\n const fieldSelectionPopover = (\n <Popover\n show={showFieldsPopover}\n strategy='fixed'\n ref={fieldPopoverRef}\n target={{\n getBoundingClientRect() {\n return currentCursorPosition;\n }\n }}\n modifiers={[\n {\n name: 'offset',\n options: {\n offset: () => {\n const iframe = editorRef.current?.element?.querySelector('iframe');\n const iframeRect = iframe?.getBoundingClientRect();\n const x = iframeRect?.x ?? 0;\n const y = iframeRect?.y ?? 0;\n return [x, y];\n }\n }\n }\n ]}\n placement='bottom-start'\n >\n {fieldMenuItems && (\n <Menu\n id={menuID}\n items={fieldMenuItems}\n as={StyledSearchPopover}\n focusControlEl={editor?.getBody() || undefined}\n mode='action'\n onItemClick={findAndRenameField}\n variant='drill-down'\n />\n )}\n </Popover>\n );\n\n useEffect(() => {\n if (currentElementId && currentElementContent)\n modalMethods.current = create(Modal, modalProps);\n }, [currentElementId, currentElementContent]);\n\n useEffect(() => {\n editor?.getDoc().addEventListener('click', handleElementClick);\n return () => {\n editor?.getDoc().removeEventListener('click', handleElementClick);\n };\n }, [editor, editorRef.current]);\n\n useEffect(() => {\n if (modalMethods.current) {\n modalMethods.current.update(modalProps);\n }\n }, [modalProps]);\n\n const onEditorChange: EditorProps['onChange'] = (formEditor?: TinyMCEEditor) => {\n if (formEditor) {\n const targetEl = formEditor.selection.getBoundingClientRect();\n const { left = 0, top = 0 } = targetEl ?? {};\n setCurrentCursorPosition({\n ...formEditor.selection.getBoundingClientRect(),\n x: left,\n y: top,\n toJSON: () => {}\n });\n\n if (formEditor.selection.isCollapsed()) {\n // get the full line string\n const selectedRange = formEditor.selection.getRng();\n const endOffset = selectedRange.endOffset;\n const stringToSearch = selectedRange.commonAncestorContainer.nodeValue?.slice(\n 0,\n endOffset\n );\n const fieldString = stringToSearch?.split(' ')[stringToSearch.split(' ').length - 1];\n if (\n fieldString?.startsWith('@') &&\n fieldString.indexOf('@') === fieldString.lastIndexOf('@')\n ) {\n filterFieldMenu(fieldString.slice(1));\n } else setShowFieldsPopover(false);\n }\n }\n };\n\n const onKeyDown: EditorProps['onKeyDown'] = event => {\n if (\n (event?.key === 'Enter' ||\n event?.key === 'ArrowLeft' ||\n event?.key === 'ArrowRight' ||\n event?.key === 'ArrowDown' ||\n event?.key === 'ArrowUp') &&\n !!fieldPopoverRef.current\n ) {\n event?.preventDefault();\n }\n if (event?.key === 'Escape' && !!fieldPopoverRef.current) {\n hidePopover();\n }\n };\n\n return (\n <Editor\n ref={editorRef}\n {...restProps}\n label={label}\n toolbar={toolbar}\n customComponents={[\n {\n createCustomElement: createPegaReferenceElement,\n name: 'pega-reference',\n extensionAttributes: ['contenteditable'],\n style: pegaReferenceElementStyle\n }\n ]}\n customActions={[\n {\n icon: 'code',\n text: tooltip,\n onMouseDown: () => {\n modalMethods.current = create(Modal, modalProps);\n },\n active: isPegaRefActive,\n shortcut: {\n pattern: 'meta+191',\n description: tooltip,\n command: onInsertField\n }\n }\n ]}\n onInit={setEditor}\n onChange={onEditorChange}\n onBlur={() => {\n onBlur?.();\n hidePopover();\n }}\n onKeyDown={onKeyDown}\n defaultValue={defaultValue}\n >\n {fieldSelectionPopover}\n </Editor>\n );\n }\n );\n\nexport default DynamicContentEditor;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { MenuProps } from '@pega/cosmos-react-core/lib/components/Menu/Menu.types';
|
|
3
|
+
import { EditorProps } from '../Editor';
|
|
4
|
+
export type ItemType = {
|
|
5
|
+
id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export interface DynamicContentEditorProps extends EditorProps {
|
|
9
|
+
/** Insert field form */
|
|
10
|
+
form: {
|
|
11
|
+
onSubmit: (insertField: (selectedField: ItemType) => void) => void;
|
|
12
|
+
dynamicContentPicker: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
onActiveFieldChange: (field: ItemType) => void;
|
|
15
|
+
/** Property selection array */
|
|
16
|
+
fieldItems?: MenuProps['items'];
|
|
17
|
+
defaultValue?: string;
|
|
18
|
+
onBlur?: () => void;
|
|
19
|
+
}
|
|
20
|
+
export interface DynamicContentEditorContextProps extends DynamicContentEditorProps {
|
|
21
|
+
updateProperties?: (selectedfield: ItemType) => void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=DynamicContentEditor.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicContentEditor.types.d.ts","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/DynamicContentEditor.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,yBAA0B,SAAQ,WAAW;IAC5D,wBAAwB;IACxB,IAAI,EAAE;QACJ,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAC,aAAa,EAAE,QAAQ,KAAK,IAAI,KAAK,IAAI,CAAC;QACnE,oBAAoB,EAAE,SAAS,CAAC;KACjC,CAAC;IACF,mBAAmB,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC/C,+BAA+B;IAC/B,UAAU,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,gCAAiC,SAAQ,yBAAyB;IACjF,gBAAgB,CAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,KAAK,IAAI,CAAC;CACtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicContentEditor.types.js","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/DynamicContentEditor.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ReactNode } from 'react';\n\nimport { MenuProps } from '@pega/cosmos-react-core/lib/components/Menu/Menu.types';\n\nimport { EditorProps } from '../Editor';\n\nexport type ItemType = {\n id: string;\n text: string;\n};\n\nexport interface DynamicContentEditorProps extends EditorProps {\n /** Insert field form */\n form: {\n onSubmit: (insertField: (selectedField: ItemType) => void) => void;\n dynamicContentPicker: ReactNode;\n };\n onActiveFieldChange: (field: ItemType) => void;\n /** Property selection array */\n fieldItems?: MenuProps['items'];\n defaultValue?: string;\n onBlur?: () => void;\n}\n\nexport interface DynamicContentEditorContextProps extends DynamicContentEditorProps {\n updateProperties?: (selectedfield: ItemType) => void;\n}\n"]}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
export declare const pegaReferenceElementStyle = "pega-reference {\n color: #076bc9;\n cursor: pointer;\n}\n\npega-reference:hover{\n text-decoration: underline;\n}\n\npega-reference::before{\n content: '['\n}\n\npega-reference::after{\n content: ']'\n}";
|
|
2
|
+
export declare const createPegaReferenceElement: (win: typeof globalThis) => {
|
|
3
|
+
new (): {
|
|
4
|
+
connectedCallback(): void;
|
|
5
|
+
accessKey: string;
|
|
6
|
+
readonly accessKeyLabel: string;
|
|
7
|
+
autocapitalize: string;
|
|
8
|
+
dir: string;
|
|
9
|
+
draggable: boolean;
|
|
10
|
+
hidden: boolean;
|
|
11
|
+
inert: boolean;
|
|
12
|
+
innerText: string;
|
|
13
|
+
lang: string;
|
|
14
|
+
readonly offsetHeight: number;
|
|
15
|
+
readonly offsetLeft: number;
|
|
16
|
+
readonly offsetParent: Element | null;
|
|
17
|
+
readonly offsetTop: number;
|
|
18
|
+
readonly offsetWidth: number;
|
|
19
|
+
outerText: string;
|
|
20
|
+
spellcheck: boolean;
|
|
21
|
+
title: string;
|
|
22
|
+
translate: boolean;
|
|
23
|
+
attachInternals(): ElementInternals;
|
|
24
|
+
click(): void;
|
|
25
|
+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void;
|
|
26
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void;
|
|
27
|
+
removeEventListener<K_1 extends keyof HTMLElementEventMap>(type: K_1, listener: (this: HTMLElement, ev: HTMLElementEventMap[K_1]) => any, options?: boolean | EventListenerOptions | undefined): void;
|
|
28
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
|
|
29
|
+
readonly attributes: NamedNodeMap;
|
|
30
|
+
readonly classList: DOMTokenList;
|
|
31
|
+
className: string;
|
|
32
|
+
readonly clientHeight: number;
|
|
33
|
+
readonly clientLeft: number;
|
|
34
|
+
readonly clientTop: number;
|
|
35
|
+
readonly clientWidth: number;
|
|
36
|
+
id: string;
|
|
37
|
+
readonly localName: string;
|
|
38
|
+
readonly namespaceURI: string | null;
|
|
39
|
+
onfullscreenchange: ((this: Element, ev: Event) => any) | null;
|
|
40
|
+
onfullscreenerror: ((this: Element, ev: Event) => any) | null;
|
|
41
|
+
outerHTML: string;
|
|
42
|
+
readonly ownerDocument: Document;
|
|
43
|
+
readonly part: DOMTokenList;
|
|
44
|
+
readonly prefix: string | null;
|
|
45
|
+
readonly scrollHeight: number;
|
|
46
|
+
scrollLeft: number;
|
|
47
|
+
scrollTop: number;
|
|
48
|
+
readonly scrollWidth: number;
|
|
49
|
+
readonly shadowRoot: ShadowRoot | null;
|
|
50
|
+
slot: string;
|
|
51
|
+
readonly tagName: string;
|
|
52
|
+
attachShadow(init: ShadowRootInit): ShadowRoot;
|
|
53
|
+
checkVisibility(options?: CheckVisibilityOptions | undefined): boolean;
|
|
54
|
+
closest<K_2 extends keyof HTMLElementTagNameMap>(selector: K_2): HTMLElementTagNameMap[K_2] | null;
|
|
55
|
+
closest<K_3 extends keyof SVGElementTagNameMap>(selector: K_3): SVGElementTagNameMap[K_3] | null;
|
|
56
|
+
closest<K_4 extends keyof MathMLElementTagNameMap>(selector: K_4): MathMLElementTagNameMap[K_4] | null;
|
|
57
|
+
closest<E extends Element = Element>(selectors: string): E | null;
|
|
58
|
+
getAttribute(qualifiedName: string): string | null;
|
|
59
|
+
getAttributeNS(namespace: string | null, localName: string): string | null;
|
|
60
|
+
getAttributeNames(): string[];
|
|
61
|
+
getAttributeNode(qualifiedName: string): Attr | null;
|
|
62
|
+
getAttributeNodeNS(namespace: string | null, localName: string): Attr | null;
|
|
63
|
+
getBoundingClientRect(): DOMRect;
|
|
64
|
+
getClientRects(): DOMRectList;
|
|
65
|
+
getElementsByClassName(classNames: string): HTMLCollectionOf<Element>;
|
|
66
|
+
getElementsByTagName<K_5 extends keyof HTMLElementTagNameMap>(qualifiedName: K_5): HTMLCollectionOf<HTMLElementTagNameMap[K_5]>;
|
|
67
|
+
getElementsByTagName<K_6 extends keyof SVGElementTagNameMap>(qualifiedName: K_6): HTMLCollectionOf<SVGElementTagNameMap[K_6]>;
|
|
68
|
+
getElementsByTagName<K_7 extends keyof MathMLElementTagNameMap>(qualifiedName: K_7): HTMLCollectionOf<MathMLElementTagNameMap[K_7]>;
|
|
69
|
+
getElementsByTagName<K_8 extends keyof HTMLElementDeprecatedTagNameMap>(qualifiedName: K_8): HTMLCollectionOf<HTMLElementDeprecatedTagNameMap[K_8]>;
|
|
70
|
+
getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>;
|
|
71
|
+
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
|
|
72
|
+
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
|
|
73
|
+
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1998/Math/MathML", localName: string): HTMLCollectionOf<MathMLElement>;
|
|
74
|
+
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollectionOf<Element>;
|
|
75
|
+
hasAttribute(qualifiedName: string): boolean;
|
|
76
|
+
hasAttributeNS(namespace: string | null, localName: string): boolean;
|
|
77
|
+
hasAttributes(): boolean;
|
|
78
|
+
hasPointerCapture(pointerId: number): boolean;
|
|
79
|
+
insertAdjacentElement(where: InsertPosition, element: Element): Element | null;
|
|
80
|
+
insertAdjacentHTML(position: InsertPosition, text: string): void;
|
|
81
|
+
insertAdjacentText(where: InsertPosition, data: string): void;
|
|
82
|
+
matches(selectors: string): boolean;
|
|
83
|
+
releasePointerCapture(pointerId: number): void;
|
|
84
|
+
removeAttribute(qualifiedName: string): void;
|
|
85
|
+
removeAttributeNS(namespace: string | null, localName: string): void;
|
|
86
|
+
removeAttributeNode(attr: Attr): Attr;
|
|
87
|
+
requestFullscreen(options?: FullscreenOptions | undefined): Promise<void>;
|
|
88
|
+
requestPointerLock(): void;
|
|
89
|
+
scroll(options?: ScrollToOptions | undefined): void;
|
|
90
|
+
scroll(x: number, y: number): void;
|
|
91
|
+
scrollBy(options?: ScrollToOptions | undefined): void;
|
|
92
|
+
scrollBy(x: number, y: number): void;
|
|
93
|
+
scrollIntoView(arg?: boolean | ScrollIntoViewOptions | undefined): void;
|
|
94
|
+
scrollTo(options?: ScrollToOptions | undefined): void;
|
|
95
|
+
scrollTo(x: number, y: number): void;
|
|
96
|
+
setAttribute(qualifiedName: string, value: string): void;
|
|
97
|
+
setAttributeNS(namespace: string | null, qualifiedName: string, value: string): void;
|
|
98
|
+
setAttributeNode(attr: Attr): Attr | null;
|
|
99
|
+
setAttributeNodeNS(attr: Attr): Attr | null;
|
|
100
|
+
setPointerCapture(pointerId: number): void;
|
|
101
|
+
toggleAttribute(qualifiedName: string, force?: boolean | undefined): boolean;
|
|
102
|
+
webkitMatchesSelector(selectors: string): boolean;
|
|
103
|
+
readonly baseURI: string;
|
|
104
|
+
readonly childNodes: NodeListOf<ChildNode>;
|
|
105
|
+
readonly firstChild: ChildNode | null;
|
|
106
|
+
readonly isConnected: boolean;
|
|
107
|
+
readonly lastChild: ChildNode | null;
|
|
108
|
+
readonly nextSibling: ChildNode | null;
|
|
109
|
+
readonly nodeName: string;
|
|
110
|
+
readonly nodeType: number;
|
|
111
|
+
nodeValue: string | null;
|
|
112
|
+
readonly parentElement: HTMLElement | null;
|
|
113
|
+
readonly parentNode: ParentNode | null;
|
|
114
|
+
readonly previousSibling: ChildNode | null;
|
|
115
|
+
textContent: string | null;
|
|
116
|
+
appendChild<T extends Node>(node: T): T;
|
|
117
|
+
cloneNode(deep?: boolean | undefined): Node;
|
|
118
|
+
compareDocumentPosition(other: Node): number;
|
|
119
|
+
contains(other: Node | null): boolean;
|
|
120
|
+
getRootNode(options?: GetRootNodeOptions | undefined): Node;
|
|
121
|
+
hasChildNodes(): boolean;
|
|
122
|
+
insertBefore<T_1 extends Node>(node: T_1, child: Node | null): T_1;
|
|
123
|
+
isDefaultNamespace(namespace: string | null): boolean;
|
|
124
|
+
isEqualNode(otherNode: Node | null): boolean;
|
|
125
|
+
isSameNode(otherNode: Node | null): boolean;
|
|
126
|
+
lookupNamespaceURI(prefix: string | null): string | null;
|
|
127
|
+
lookupPrefix(namespace: string | null): string | null;
|
|
128
|
+
normalize(): void;
|
|
129
|
+
removeChild<T_2 extends Node>(child: T_2): T_2;
|
|
130
|
+
replaceChild<T_3 extends Node>(node: Node, child: T_3): T_3;
|
|
131
|
+
readonly ELEMENT_NODE: 1;
|
|
132
|
+
readonly ATTRIBUTE_NODE: 2;
|
|
133
|
+
readonly TEXT_NODE: 3;
|
|
134
|
+
readonly CDATA_SECTION_NODE: 4;
|
|
135
|
+
readonly ENTITY_REFERENCE_NODE: 5;
|
|
136
|
+
readonly ENTITY_NODE: 6;
|
|
137
|
+
readonly PROCESSING_INSTRUCTION_NODE: 7;
|
|
138
|
+
readonly COMMENT_NODE: 8;
|
|
139
|
+
readonly DOCUMENT_NODE: 9;
|
|
140
|
+
readonly DOCUMENT_TYPE_NODE: 10;
|
|
141
|
+
readonly DOCUMENT_FRAGMENT_NODE: 11;
|
|
142
|
+
readonly NOTATION_NODE: 12;
|
|
143
|
+
readonly DOCUMENT_POSITION_DISCONNECTED: 1;
|
|
144
|
+
readonly DOCUMENT_POSITION_PRECEDING: 2;
|
|
145
|
+
readonly DOCUMENT_POSITION_FOLLOWING: 4;
|
|
146
|
+
readonly DOCUMENT_POSITION_CONTAINS: 8;
|
|
147
|
+
readonly DOCUMENT_POSITION_CONTAINED_BY: 16;
|
|
148
|
+
readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32;
|
|
149
|
+
dispatchEvent(event: Event): boolean;
|
|
150
|
+
ariaAtomic: string | null;
|
|
151
|
+
ariaAutoComplete: string | null;
|
|
152
|
+
ariaBusy: string | null;
|
|
153
|
+
ariaChecked: string | null;
|
|
154
|
+
ariaColCount: string | null;
|
|
155
|
+
ariaColIndex: string | null;
|
|
156
|
+
ariaColSpan: string | null;
|
|
157
|
+
ariaCurrent: string | null;
|
|
158
|
+
ariaDisabled: string | null;
|
|
159
|
+
ariaExpanded: string | null;
|
|
160
|
+
ariaHasPopup: string | null;
|
|
161
|
+
ariaHidden: string | null;
|
|
162
|
+
ariaInvalid: string | null;
|
|
163
|
+
ariaKeyShortcuts: string | null;
|
|
164
|
+
ariaLabel: string | null;
|
|
165
|
+
ariaLevel: string | null;
|
|
166
|
+
ariaLive: string | null;
|
|
167
|
+
ariaModal: string | null;
|
|
168
|
+
ariaMultiLine: string | null;
|
|
169
|
+
ariaMultiSelectable: string | null;
|
|
170
|
+
ariaOrientation: string | null;
|
|
171
|
+
ariaPlaceholder: string | null;
|
|
172
|
+
ariaPosInSet: string | null;
|
|
173
|
+
ariaPressed: string | null;
|
|
174
|
+
ariaReadOnly: string | null;
|
|
175
|
+
ariaRequired: string | null;
|
|
176
|
+
ariaRoleDescription: string | null;
|
|
177
|
+
ariaRowCount: string | null;
|
|
178
|
+
ariaRowIndex: string | null;
|
|
179
|
+
ariaRowSpan: string | null;
|
|
180
|
+
ariaSelected: string | null;
|
|
181
|
+
ariaSetSize: string | null;
|
|
182
|
+
ariaSort: string | null;
|
|
183
|
+
ariaValueMax: string | null;
|
|
184
|
+
ariaValueMin: string | null;
|
|
185
|
+
ariaValueNow: string | null;
|
|
186
|
+
ariaValueText: string | null;
|
|
187
|
+
role: string | null;
|
|
188
|
+
animate(keyframes: PropertyIndexedKeyframes | Keyframe[] | null, options?: number | KeyframeAnimationOptions | undefined): Animation;
|
|
189
|
+
getAnimations(options?: GetAnimationsOptions | undefined): Animation[];
|
|
190
|
+
after(...nodes: (string | Node)[]): void;
|
|
191
|
+
before(...nodes: (string | Node)[]): void;
|
|
192
|
+
remove(): void;
|
|
193
|
+
replaceWith(...nodes: (string | Node)[]): void;
|
|
194
|
+
innerHTML: string;
|
|
195
|
+
readonly nextElementSibling: Element | null;
|
|
196
|
+
readonly previousElementSibling: Element | null;
|
|
197
|
+
readonly childElementCount: number;
|
|
198
|
+
readonly children: HTMLCollection;
|
|
199
|
+
readonly firstElementChild: Element | null;
|
|
200
|
+
readonly lastElementChild: Element | null;
|
|
201
|
+
append(...nodes: (string | Node)[]): void;
|
|
202
|
+
prepend(...nodes: (string | Node)[]): void;
|
|
203
|
+
querySelector<K_9 extends keyof HTMLElementTagNameMap>(selectors: K_9): HTMLElementTagNameMap[K_9] | null;
|
|
204
|
+
querySelector<K_10 extends keyof SVGElementTagNameMap>(selectors: K_10): SVGElementTagNameMap[K_10] | null;
|
|
205
|
+
querySelector<K_11 extends keyof MathMLElementTagNameMap>(selectors: K_11): MathMLElementTagNameMap[K_11] | null;
|
|
206
|
+
querySelector<K_12 extends keyof HTMLElementDeprecatedTagNameMap>(selectors: K_12): HTMLElementDeprecatedTagNameMap[K_12] | null;
|
|
207
|
+
querySelector<E_1 extends Element = Element>(selectors: string): E_1 | null;
|
|
208
|
+
querySelectorAll<K_13 extends keyof HTMLElementTagNameMap>(selectors: K_13): NodeListOf<HTMLElementTagNameMap[K_13]>;
|
|
209
|
+
querySelectorAll<K_14 extends keyof SVGElementTagNameMap>(selectors: K_14): NodeListOf<SVGElementTagNameMap[K_14]>;
|
|
210
|
+
querySelectorAll<K_15 extends keyof MathMLElementTagNameMap>(selectors: K_15): NodeListOf<MathMLElementTagNameMap[K_15]>;
|
|
211
|
+
querySelectorAll<K_16 extends keyof HTMLElementDeprecatedTagNameMap>(selectors: K_16): NodeListOf<HTMLElementDeprecatedTagNameMap[K_16]>;
|
|
212
|
+
querySelectorAll<E_2 extends Element = Element>(selectors: string): NodeListOf<E_2>;
|
|
213
|
+
replaceChildren(...nodes: (string | Node)[]): void;
|
|
214
|
+
readonly assignedSlot: HTMLSlotElement | null;
|
|
215
|
+
readonly style: CSSStyleDeclaration;
|
|
216
|
+
contentEditable: string;
|
|
217
|
+
enterKeyHint: string;
|
|
218
|
+
inputMode: string;
|
|
219
|
+
readonly isContentEditable: boolean;
|
|
220
|
+
onabort: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null;
|
|
221
|
+
onanimationcancel: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
222
|
+
onanimationend: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
223
|
+
onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
224
|
+
onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
225
|
+
onauxclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
226
|
+
onbeforeinput: ((this: GlobalEventHandlers, ev: InputEvent) => any) | null;
|
|
227
|
+
onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null;
|
|
228
|
+
oncancel: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
229
|
+
oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
230
|
+
oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
231
|
+
onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
232
|
+
onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
233
|
+
onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
234
|
+
oncontextmenu: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
235
|
+
oncopy: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
236
|
+
oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
237
|
+
oncut: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
238
|
+
ondblclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
239
|
+
ondrag: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
240
|
+
ondragend: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
241
|
+
ondragenter: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
242
|
+
ondragleave: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
243
|
+
ondragover: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
244
|
+
ondragstart: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
245
|
+
ondrop: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
246
|
+
ondurationchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
247
|
+
onemptied: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
248
|
+
onended: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
249
|
+
onerror: OnErrorEventHandler;
|
|
250
|
+
onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null;
|
|
251
|
+
onformdata: ((this: GlobalEventHandlers, ev: FormDataEvent) => any) | null;
|
|
252
|
+
ongotpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
253
|
+
oninput: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
254
|
+
oninvalid: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
255
|
+
onkeydown: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
256
|
+
onkeypress: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
257
|
+
onkeyup: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
258
|
+
onload: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
259
|
+
onloadeddata: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
260
|
+
onloadedmetadata: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
261
|
+
onloadstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
262
|
+
onlostpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
263
|
+
onmousedown: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
264
|
+
onmouseenter: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
265
|
+
onmouseleave: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
266
|
+
onmousemove: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
267
|
+
onmouseout: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
268
|
+
onmouseover: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
269
|
+
onmouseup: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
270
|
+
onpaste: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
271
|
+
onpause: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
272
|
+
onplay: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
273
|
+
onplaying: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
274
|
+
onpointercancel: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
275
|
+
onpointerdown: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
276
|
+
onpointerenter: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
277
|
+
onpointerleave: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
278
|
+
onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
279
|
+
onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
280
|
+
onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
281
|
+
onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
282
|
+
onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent<EventTarget>) => any) | null;
|
|
283
|
+
onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
284
|
+
onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
285
|
+
onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null;
|
|
286
|
+
onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
287
|
+
onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null;
|
|
288
|
+
onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
289
|
+
onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
290
|
+
onselect: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
291
|
+
onselectionchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
292
|
+
onselectstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
293
|
+
onslotchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
294
|
+
onstalled: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
295
|
+
onsubmit: ((this: GlobalEventHandlers, ev: SubmitEvent) => any) | null;
|
|
296
|
+
onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
297
|
+
ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
298
|
+
ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
299
|
+
ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
300
|
+
ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
301
|
+
ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
302
|
+
ontouchstart?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
303
|
+
ontransitioncancel: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
304
|
+
ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
305
|
+
ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
306
|
+
ontransitionstart: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
307
|
+
onvolumechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
308
|
+
onwaiting: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
309
|
+
onwebkitanimationend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
310
|
+
onwebkitanimationiteration: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
311
|
+
onwebkitanimationstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
312
|
+
onwebkittransitionend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
313
|
+
onwheel: ((this: GlobalEventHandlers, ev: WheelEvent) => any) | null;
|
|
314
|
+
autofocus: boolean;
|
|
315
|
+
readonly dataset: DOMStringMap;
|
|
316
|
+
nonce?: string | undefined;
|
|
317
|
+
tabIndex: number;
|
|
318
|
+
blur(): void;
|
|
319
|
+
focus(options?: FocusOptions | undefined): void;
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
//# sourceMappingURL=PegaCustomElement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PegaCustomElement.d.ts","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/PegaCustomElement.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,qNAgBpC,CAAC;AAEH,eAAO,MAAM,0BAA0B,QAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQhE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const pegaReferenceElementStyle = `\
|
|
2
|
+
pega-reference {
|
|
3
|
+
color: #076bc9;
|
|
4
|
+
cursor: pointer;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
pega-reference:hover{
|
|
8
|
+
text-decoration: underline;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
pega-reference::before{
|
|
12
|
+
content: '['
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pega-reference::after{
|
|
16
|
+
content: ']'
|
|
17
|
+
}`;
|
|
18
|
+
export const createPegaReferenceElement = (win) => {
|
|
19
|
+
return class PegaReferenceElement extends win.HTMLElement {
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
const template = document.createElement('template');
|
|
22
|
+
const temp = document.importNode(template.content, true);
|
|
23
|
+
this.append(temp);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=PegaCustomElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PegaCustomElement.js","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/PegaCustomElement.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;EAgBvC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,GAAsB,EAAE,EAAE;IACnE,OAAO,MAAM,oBAAqB,SAAQ,GAAG,CAAC,WAAW;QACvD,iBAAiB;YACf,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACpD,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACzD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export const pegaReferenceElementStyle = `\\\npega-reference {\n color: #076bc9;\n cursor: pointer;\n}\n\npega-reference:hover{\n text-decoration: underline;\n}\n\npega-reference::before{\n content: '['\n}\n\npega-reference::after{\n content: ']'\n}`;\n\nexport const createPegaReferenceElement = (win: typeof globalThis) => {\n return class PegaReferenceElement extends win.HTMLElement {\n connectedCallback() {\n const template = document.createElement('template');\n const temp = document.importNode(template.content, true);\n this.append(temp);\n }\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/DynamicContentEditor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { default } from './DynamicContentEditor';\nexport { DynamicContentEditorProps, ItemType } from './DynamicContentEditor.types';\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { marked } from 'marked';
|
|
2
2
|
import { ComponentType, FC } from 'react';
|
|
3
|
-
import { ErrorStateProps } from '@pega/cosmos-react-core';
|
|
3
|
+
import { ErrorStateProps, ExcludeStrict } from '@pega/cosmos-react-core';
|
|
4
4
|
export interface InteractionRenderers {
|
|
5
5
|
type: string;
|
|
6
6
|
regexPattern: RegExp;
|
|
@@ -14,12 +14,12 @@ export interface InteractionRenderers {
|
|
|
14
14
|
} | undefined;
|
|
15
15
|
}
|
|
16
16
|
export type TokenMap = {
|
|
17
|
-
[K in
|
|
17
|
+
[K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, {
|
|
18
18
|
type: K;
|
|
19
19
|
}>;
|
|
20
20
|
};
|
|
21
21
|
export type MDMap = {
|
|
22
|
-
[K in
|
|
22
|
+
[K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]?: (token: TokenMap[K]) => FC<{
|
|
23
23
|
token: TokenMap[K];
|
|
24
24
|
}> | undefined;
|
|
25
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextViewer.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"RichTextViewer.types.d.ts","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEzE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,CACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,KAElB;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC7F,SAAS,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG;KACpB,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;CAClG,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;KACjB,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAC9D,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KACf,EAAE,CAAC;QAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS;CAC5C,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;IACvC,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import { marked } from 'marked';\nimport { ComponentType, FC } from 'react';\n\nimport { ErrorStateProps } from '@pega/cosmos-react-core';\n\nexport interface InteractionRenderers {\n type: string;\n regexPattern: RegExp;\n xmlElement?: string;\n component?: ComponentType<any>;\n getSearchAttributes?: (\n xmlElement: string,\n searchResult: string\n ) =>\n | { markdown: string; component: ComponentType<any>; props: Record<string, any>; text: string }\n | undefined;\n}\n\nexport type TokenMap = {\n [K in
|
|
1
|
+
{"version":3,"file":"RichTextViewer.types.js","sourceRoot":"","sources":["../../../src/components/RichTextEditor/RichTextViewer.types.ts"],"names":[],"mappings":"","sourcesContent":["import { marked } from 'marked';\nimport { ComponentType, FC } from 'react';\n\nimport { ErrorStateProps, ExcludeStrict } from '@pega/cosmos-react-core';\n\nexport interface InteractionRenderers {\n type: string;\n regexPattern: RegExp;\n xmlElement?: string;\n component?: ComponentType<any>;\n getSearchAttributes?: (\n xmlElement: string,\n searchResult: string\n ) =>\n | { markdown: string; component: ComponentType<any>; props: Record<string, any>; text: string }\n | undefined;\n}\n\nexport type TokenMap = {\n [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]: Extract<marked.Token, { type: K }>;\n};\n\nexport type MDMap = {\n [K in ExcludeStrict<marked.Token, marked.Tokens.Def>['type']]?: (\n token: TokenMap[K]\n ) => FC<{ token: TokenMap[K] }> | undefined;\n};\n\nexport interface RichTextViewerProps {\n content: string;\n type: 'markdown' | 'html' | 'richtext';\n interactionRenderers?: InteractionRenderers[];\n markdownMap?: MDMap;\n onRetry?: ErrorStateProps['onRetry'];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAA+B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAA+B,MAAM,OAAO,CAAC;AAqBxD,OAAO,EAAa,QA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,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { FC, useState, useEffect, useRef } from 'react';\nimport { Text } from 'slate';\nimport { useSlate, useFocused, ReactEditor } from 'slate-react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Flex,\n Icon,\n useArrows,\n useI18n,\n defaultThemeProp,\n TranslationPack,\n navigatorIsAvailable\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\n\nimport EditorCommands from '../utils/EditorCommands';\nimport ListCommands from '../utils/ListCommands';\n\nimport ToolbarButton from './ToolbarButton';\nimport { StyleType, Features } from './Toolbar.types';\nimport TableButton from './TableButton';\nimport AnchorButton from './AnchorButton';\nimport ImageButton from './ImageButton';\nimport TextSelect from './TextSelect';\nimport IndentButton from './IndentButton';\nimport { getKeyCommand } from './utils';\n\nconst StyledToolbar = styled.div<{ sticky?: boolean }>(({ sticky, theme }) => {\n return css`\n background-color: ${props => props.theme.base.palette['primary-background']};\n border-radius: calc(0.25 * ${props => props.theme.base['border-radius']});\n overflow: auto;\n padding: 0.125rem;\n ${sticky &&\n css`\n position: sticky;\n bottom: 0;\n `}\n\n &:has(:focus-visible) {\n box-shadow: ${theme.base.shadow['focus-group']};\n }\n `;\n});\n\nStyledToolbar.defaultProps = defaultThemeProp;\n\nexport interface ToolbarProps {\n features: Features[];\n sticky?: boolean;\n setFocusableBtn: (el: HTMLElement) => void;\n}\n\ntype StyleButtonType = {\n style: StyleType;\n text: string;\n icon?: string;\n label?: string;\n format: Exclude<keyof Text, 'text'>;\n tooltip: string;\n};\n\nconst isMobile = navigatorIsAvailable && navigator.userAgent.includes('Mobile');\n\n// Function that returns the text styling buttons\nfunction renderStyleButtons(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n focused: boolean,\n osx: boolean\n) {\n const inlineStyleButtons: StyleButtonType[] = [\n {\n style: 'BOLD',\n text: 'B',\n format: 'bold',\n label: t('rte_bold'),\n tooltip: isMobile\n ? `${t('rte_bold')}`\n : getKeyCommand(osx, ({ ctrl, shift }) => `${t('rte_bold')} (${ctrl}B, ${ctrl}${shift}B)`)\n },\n {\n style: 'ITALIC',\n text: 'I',\n format: 'italic',\n label: t('rte_italic'),\n tooltip: isMobile\n ? `${t('rte_italic')}`\n : getKeyCommand(osx, ({ ctrl, shift }) => `${t('rte_italic')} (${ctrl}I, ${ctrl}${shift}I)`)\n },\n {\n style: 'STRIKE-THROUGH',\n text: 'S',\n format: 'line-through',\n label: t('rte_strike_through'),\n tooltip: isMobile\n ? `${t('rte_strike_through')}`\n : getKeyCommand(osx, ({ ctrl, shift }) => `${t('rte_strike_through')} (${ctrl}${shift}X)`)\n }\n ];\n\n return inlineStyleButtons.map(({ format, style, text, label, tooltip }) => {\n return (\n <ToolbarButton\n key={style}\n onMouseDown={e => {\n e.preventDefault();\n if (!focused) {\n ReactEditor.focus(editor);\n }\n setTimeout(() => {\n EditorCommands.toggleFormat(format, editor);\n }, 0);\n }}\n styleType={style}\n active={EditorCommands.isFormatActive(format, editor)}\n tooltip={tooltip}\n label={label}\n >\n {text}\n </ToolbarButton>\n );\n });\n}\n\n// Function that returns the cut, copy and paste buttons\nfunction renderCutCopyPaste(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n osx: boolean\n) {\n const CutCopyPasteButtons = [\n {\n text: 'Cut',\n icon: 'scissors',\n label: t('rte_cut'),\n func: () => {\n document.execCommand('cut');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_cut')} (${ctrl}X)`)\n },\n {\n text: 'Copy',\n icon: 'copy',\n label: t('rte_copy'),\n func: () => {\n document.execCommand('copy');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_copy')} (${ctrl}C)`)\n },\n {\n text: 'Paste',\n icon: 'clipboard-data',\n label: t('rte_paste'),\n func: () => {\n navigator.clipboard.readText().then(text => {\n EditorCommands.replaceWithText(editor, editor.selection, text);\n });\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_paste')} (${ctrl}V)`)\n }\n ];\n\n return CutCopyPasteButtons.map(btn => {\n return (\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n btn.func();\n }}\n key={btn.text}\n tooltip={btn.tooltip}\n label={btn.label}\n >\n <Icon name={btn.icon} />\n </ToolbarButton>\n );\n });\n}\n\n// Takes the features array and transforms it into a map for faster lookup\nfunction createActiveFeaturesMap(features: Features[]) {\n return features.reduce((acc, feature) => {\n return { ...acc, [feature]: true };\n }, {} as { [F in Features]: boolean });\n}\n\nconst Toolbar: FC<ToolbarProps> = (props: ToolbarProps) => {\n const { features, sticky, setFocusableBtn } = props;\n const editor = useSlate();\n const focused = useFocused();\n const t = useI18n();\n const [osx, setOsx] = useState(false);\n const toolbarRef = useRef<HTMLElement>(null);\n\n useArrows(toolbarRef, { selector: 'button', dir: 'left-right' });\n\n const [activeFeatures, setActiveFeatures] = useState(createActiveFeaturesMap(features));\n\n useEffect(() => {\n const btn = toolbarRef?.current?.querySelector('button');\n if (btn) setFocusableBtn(btn);\n }, [toolbarRef.current]);\n\n useEffect(() => {\n setActiveFeatures(createActiveFeaturesMap(features));\n }, [features]);\n\n useEffect(() => {\n if (navigator.appVersion.includes('Mac')) setOsx(true);\n }, []);\n\n return (\n <Flex as={StyledToolbar} sticky={sticky} container={{ justify: 'between' }} ref={toolbarRef}>\n <Flex container={{ alignItems: 'end' }}>\n <TextSelect osx={osx} />\n {activeFeatures['inline-styling'] && renderStyleButtons(editor, t, focused, osx)}\n {activeFeatures.lists && (\n <>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('unordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('unordered-list', editor)}\n tooltip={\n isMobile\n ? `${t('rte_bulleted_list')}`\n : getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_bulleted_list')} (${ctrl}${shift}L)`\n )\n }\n label={t('rte_bulleted_list')}\n >\n <Icon name='list' />\n </ToolbarButton>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('ordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('ordered-list', editor)}\n tooltip={t('rte_numbered_list')}\n label={t('rte_numbered_list')}\n >\n <Icon name='list-number' />\n </ToolbarButton>\n </>\n )}\n {activeFeatures.indentation && (\n <>\n <IndentButton type='indent' osx={osx} />\n <IndentButton type='unindent' osx={osx} />\n </>\n )}\n {activeFeatures.tables && <TableButton />}\n </Flex>\n <Flex container={{ alignItems: 'end' }}>\n {activeFeatures.links && <AnchorButton osx={osx} />}\n {activeFeatures.images && <ImageButton />}\n </Flex>\n {activeFeatures['cut-copy-paste'] && (\n <Flex container={{ alignItems: 'end' }}>{renderCutCopyPaste(editor, t, osx)}</Flex>\n )}\n </Flex>\n );\n};\n\nexport default Toolbar;\n"]}
|
|
1
|
+
{"version":3,"file":"Toolbar.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/Toolbar/Toolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,OAAO,EACP,gBAAgB,EAEhB,oBAAoB,EAErB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,Y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AC,WAAW,KAAG,IACpC,EACN,cAAc,CAAC,gBAAgB,CAAC,IAAI,CACnC,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,YAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,GAAQ,CACpF,IACI,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { FC, useState, useEffect, useRef } from 'react';\nimport { Text } from 'slate';\nimport { useSlate, useFocused, ReactEditor } from 'slate-react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Flex,\n Icon,\n useArrows,\n useI18n,\n defaultThemeProp,\n TranslationPack,\n navigatorIsAvailable,\n ExcludeStrict\n} from '@pega/cosmos-react-core';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\n\nimport EditorCommands from '../utils/EditorCommands';\nimport ListCommands from '../utils/ListCommands';\n\nimport ToolbarButton from './ToolbarButton';\nimport { StyleType, Features } from './Toolbar.types';\nimport TableButton from './TableButton';\nimport AnchorButton from './AnchorButton';\nimport ImageButton from './ImageButton';\nimport TextSelect from './TextSelect';\nimport IndentButton from './IndentButton';\nimport { getKeyCommand } from './utils';\n\nconst StyledToolbar = styled.div<{ sticky?: boolean }>(({ sticky, theme }) => {\n return css`\n background-color: ${props => props.theme.base.palette['primary-background']};\n border-radius: calc(0.25 * ${props => props.theme.base['border-radius']});\n overflow: auto;\n padding: 0.125rem;\n ${sticky &&\n css`\n position: sticky;\n bottom: 0;\n `}\n\n &:has(:focus-visible) {\n box-shadow: ${theme.base.shadow['focus-group']};\n }\n `;\n});\n\nStyledToolbar.defaultProps = defaultThemeProp;\n\nexport interface ToolbarProps {\n features: Features[];\n sticky?: boolean;\n setFocusableBtn: (el: HTMLElement) => void;\n}\n\ntype StyleButtonType = {\n style: StyleType;\n text: string;\n icon?: string;\n label?: string;\n format: ExcludeStrict<keyof Text, 'text'>;\n tooltip: string;\n};\n\nconst isMobile = navigatorIsAvailable && navigator.userAgent.includes('Mobile');\n\n// Function that returns the text styling buttons\nfunction renderStyleButtons(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n focused: boolean,\n osx: boolean\n) {\n const inlineStyleButtons: StyleButtonType[] = [\n {\n style: 'BOLD',\n text: 'B',\n format: 'bold',\n label: t('rte_bold'),\n tooltip: isMobile\n ? `${t('rte_bold')}`\n : getKeyCommand(osx, ({ ctrl, shift }) => `${t('rte_bold')} (${ctrl}B, ${ctrl}${shift}B)`)\n },\n {\n style: 'ITALIC',\n text: 'I',\n format: 'italic',\n label: t('rte_italic'),\n tooltip: isMobile\n ? `${t('rte_italic')}`\n : getKeyCommand(osx, ({ ctrl, shift }) => `${t('rte_italic')} (${ctrl}I, ${ctrl}${shift}I)`)\n },\n {\n style: 'STRIKE-THROUGH',\n text: 'S',\n format: 'line-through',\n label: t('rte_strike_through'),\n tooltip: isMobile\n ? `${t('rte_strike_through')}`\n : getKeyCommand(osx, ({ ctrl, shift }) => `${t('rte_strike_through')} (${ctrl}${shift}X)`)\n }\n ];\n\n return inlineStyleButtons.map(({ format, style, text, label, tooltip }) => {\n return (\n <ToolbarButton\n key={style}\n onMouseDown={e => {\n e.preventDefault();\n if (!focused) {\n ReactEditor.focus(editor);\n }\n setTimeout(() => {\n EditorCommands.toggleFormat(format, editor);\n }, 0);\n }}\n styleType={style}\n active={EditorCommands.isFormatActive(format, editor)}\n tooltip={tooltip}\n label={label}\n >\n {text}\n </ToolbarButton>\n );\n });\n}\n\n// Function that returns the cut, copy and paste buttons\nfunction renderCutCopyPaste(\n editor: ReactEditor,\n t: TranslationFunction<TranslationPack>,\n osx: boolean\n) {\n const CutCopyPasteButtons = [\n {\n text: 'Cut',\n icon: 'scissors',\n label: t('rte_cut'),\n func: () => {\n document.execCommand('cut');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_cut')} (${ctrl}X)`)\n },\n {\n text: 'Copy',\n icon: 'copy',\n label: t('rte_copy'),\n func: () => {\n document.execCommand('copy');\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_copy')} (${ctrl}C)`)\n },\n {\n text: 'Paste',\n icon: 'clipboard-data',\n label: t('rte_paste'),\n func: () => {\n navigator.clipboard.readText().then(text => {\n EditorCommands.replaceWithText(editor, editor.selection, text);\n });\n },\n tooltip: getKeyCommand(osx, ({ ctrl }) => `${t('rte_paste')} (${ctrl}V)`)\n }\n ];\n\n return CutCopyPasteButtons.map(btn => {\n return (\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n btn.func();\n }}\n key={btn.text}\n tooltip={btn.tooltip}\n label={btn.label}\n >\n <Icon name={btn.icon} />\n </ToolbarButton>\n );\n });\n}\n\n// Takes the features array and transforms it into a map for faster lookup\nfunction createActiveFeaturesMap(features: Features[]) {\n return features.reduce((acc, feature) => {\n return { ...acc, [feature]: true };\n }, {} as { [F in Features]: boolean });\n}\n\nconst Toolbar: FC<ToolbarProps> = (props: ToolbarProps) => {\n const { features, sticky, setFocusableBtn } = props;\n const editor = useSlate();\n const focused = useFocused();\n const t = useI18n();\n const [osx, setOsx] = useState(false);\n const toolbarRef = useRef<HTMLElement>(null);\n\n useArrows(toolbarRef, { selector: 'button', dir: 'left-right' });\n\n const [activeFeatures, setActiveFeatures] = useState(createActiveFeaturesMap(features));\n\n useEffect(() => {\n const btn = toolbarRef?.current?.querySelector('button');\n if (btn) setFocusableBtn(btn);\n }, [toolbarRef.current]);\n\n useEffect(() => {\n setActiveFeatures(createActiveFeaturesMap(features));\n }, [features]);\n\n useEffect(() => {\n if (navigator.appVersion.includes('Mac')) setOsx(true);\n }, []);\n\n return (\n <Flex as={StyledToolbar} sticky={sticky} container={{ justify: 'between' }} ref={toolbarRef}>\n <Flex container={{ alignItems: 'end' }}>\n <TextSelect osx={osx} />\n {activeFeatures['inline-styling'] && renderStyleButtons(editor, t, focused, osx)}\n {activeFeatures.lists && (\n <>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('unordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('unordered-list', editor)}\n tooltip={\n isMobile\n ? `${t('rte_bulleted_list')}`\n : getKeyCommand(\n osx,\n ({ ctrl, shift }) => `${t('rte_bulleted_list')} (${ctrl}${shift}L)`\n )\n }\n label={t('rte_bulleted_list')}\n >\n <Icon name='list' />\n </ToolbarButton>\n <ToolbarButton\n onMouseDown={e => {\n e.preventDefault();\n ListCommands.toggleList('ordered-list', editor);\n }}\n active={EditorCommands.isBlockActive('ordered-list', editor)}\n tooltip={t('rte_numbered_list')}\n label={t('rte_numbered_list')}\n >\n <Icon name='list-number' />\n </ToolbarButton>\n </>\n )}\n {activeFeatures.indentation && (\n <>\n <IndentButton type='indent' osx={osx} />\n <IndentButton type='unindent' osx={osx} />\n </>\n )}\n {activeFeatures.tables && <TableButton />}\n </Flex>\n <Flex container={{ alignItems: 'end' }}>\n {activeFeatures.links && <AnchorButton osx={osx} />}\n {activeFeatures.images && <ImageButton />}\n </Flex>\n {activeFeatures['cut-copy-paste'] && (\n <Flex container={{ alignItems: 'end' }}>{renderCutCopyPaste(editor, t, osx)}</Flex>\n )}\n </Flex>\n );\n};\n\nexport default Toolbar;\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { KeyboardEvent } from 'react';
|
|
2
2
|
import { Editor, Range, NodeEntry, Node, Element, Text } from 'slate';
|
|
3
|
+
import { ExcludeStrict } from '@pega/cosmos-react-core';
|
|
3
4
|
declare const commands: {
|
|
4
|
-
isFormatActive: (format:
|
|
5
|
-
toggleFormat: (format:
|
|
5
|
+
isFormatActive: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => boolean;
|
|
6
|
+
toggleFormat: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => void;
|
|
6
7
|
isBlockActive: (format: Element['type'], editor: Editor) => boolean;
|
|
7
8
|
getActiveBlockType: (editor: Editor) => string;
|
|
8
9
|
setBlock: (format: Element['type'], editor: Editor) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorCommands.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,MAAM,EAEN,KAAK,EAEL,SAAS,EACT,IAAI,EACJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EditorCommands.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,MAAM,EAEN,KAAK,EAEL,SAAS,EACT,IAAI,EACJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAYxD,QAAA,MAAM,QAAQ;6BAEa,cAAc,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;2BAKnD,cAAc,MAAM,IAAI,EAAE,MAAM,CAAC,UAAU,MAAM;4BAShD,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;iCAQ1B,MAAM,KAAG,MAAM;uBAazB,OAAO,CAAC,MAAM,CAAC,UAAU,MAAM;8BAIxB,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,MAAM;+BAQzC,MAAM,UAAU,KAAK,GAAG,IAAI,QAAQ,IAAI;8BAOzC,MAAM;0BASV,MAAM;0BA0CN,MAAM,aAAa;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,MAAM,MAAM;qCAkBhD,MAAM,KAAG,MAAM;yBAgB3B,MAAM,QAAQ,MAAM,OAAO,MAAM,aAAa,KAAK,GAAG,IAAI;8BAuCrD,MAAM,KAAK,aAAa;6BAsBzB,MAAM,KAAK,aAAa;IAajD;;;;OAIG;kCAC2B,MAAM,KAAK,aAAa;gCAiE1B,MAAM,KAAK,aAAa;qBA4CnC,MAAM;uBAiBJ,MAAM;+BAsBE,MAAM,KAAK,aAAa,iBAAiB,OAAO;CAkF5E,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,EACL,IAAI,EAGJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAEf,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,kBAAkB,GAAuC;IAC7D,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;CAChB,CAAC;AAEF,MAAM,QAAQ,GAAG;IACf,uCAAuC;IACvC,cAAc,EAAE,CAAC,MAAmC,EAAE,MAAc,EAAE,EAAE;QACtE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAChD,CAAC;IACD,qCAAqC;IACrC,YAAY,EAAE,CAAC,MAAmC,EAAE,MAAc,EAAE,EAAE;QACpE,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,IAAI,YAAY,EAAE;YAChB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACnC;aAAM;YACL,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;SACtC;IACH,CAAC;IACD,2CAA2C;IAC3C,aAAa,EAAE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,CAAC,MAAM,EAAE;oBACxB,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;oBACnC,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;iBACnC,CAAC,CAAC;aACJ;SACF;QAED,IAAI,eAAe;YAAE,CAAC,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport {\n Editor,\n Transforms,\n Range,\n Path,\n NodeEntry,\n Node,\n Element,\n Text,\n CosmosCustom\n} from 'slate';\n\nimport ListCommands from './ListCommands';\n\nconst textKeyCodeMapping: { [key: number]: Element['type'] } = {\n 48: 'paragraph',\n 49: 'heading-1',\n 50: 'heading-2',\n 51: 'heading-3',\n 52: 'heading-4'\n};\n\nconst commands = {\n // Checks if an inline format is active\n isFormatActive: (format: Exclude<keyof Text, 'text'>, editor: Editor) => {\n const marks = Editor.marks(editor);\n return marks ? marks[format] === true : false;\n },\n // Toggles an inline format on or off\n toggleFormat: (format: Exclude<keyof Text, 'text'>, editor: Editor) => {\n const formatActive = commands.isFormatActive(format, editor);\n if (formatActive) {\n Editor.removeMark(editor, format);\n } else {\n Editor.addMark(editor, format, true);\n }\n },\n // Checks if a block level format is active\n isBlockActive: (format: Element['type'], editor: Editor) => {\n const [match] = Editor.nodes<Element>(editor, {\n match: n => Element.isElement(n) && n.type === format\n });\n\n return !!match;\n },\n // Gets the active block level type\n getActiveBlockType: (editor: Editor): string => {\n const [match] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: Element.isElement,\n mode: 'lowest'\n });\n\n if (match) {\n return match[0].type;\n }\n return '';\n },\n // Sets the block type of the currently selected block\n setBlock: (format: Element['type'], editor: Editor) => {\n Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });\n },\n // Replaces a target in the editor with the given text\n replaceWithText: (editor: Editor, target: Range | null, text: string) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertText(editor, text);\n Transforms.move(editor);\n },\n // Replaces a target in the editor with the given node\n replaceWithNodes: (editor: Editor, target: Range | null, node: Node) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertNodes(editor, node);\n },\n // Gets the highest selected block level node\n getSelectedNode: (editor: Editor): NodeEntry<Node> => {\n const [node] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: n => Element.isElement(n),\n mode: 'highest'\n });\n return node;\n },\n // Appends a 3x3 table into the editor and adds a blank line to the bottom\n appendTable: (editor: Editor) => {\n const baseArr: unknown[][] = new Array(3).fill(new Array(3).fill(0));\n const table: [CosmosCustom.TableElement, CosmosCustom.ParagraphElement] = [\n {\n type: 'table',\n children: [\n {\n type: 'table-body',\n children: baseArr.map(row => {\n return {\n type: 'table-row',\n children: row.map(() => {\n return {\n type: 'table-cell',\n children: [{ type: 'paragraph', children: [{ text: '' }] }]\n };\n })\n };\n })\n }\n ]\n },\n {\n type: 'paragraph',\n children: [{ text: '' }]\n }\n ];\n\n Transforms.insertNodes(editor, table, { mode: 'highest' });\n const [firstTableCell] = Editor.nodes<CosmosCustom.ParagraphElement>(editor, {\n at: editor.selection?.anchor.path.slice(0, 1),\n match: n => Element.isElement(n) && n.type === 'paragraph',\n mode: 'highest'\n });\n if (firstTableCell) {\n const [, path] = firstTableCell;\n path.push(0);\n const nextPosition = { path, offset: 0 };\n Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });\n }\n },\n // Finds the image placeholder and replaces it with an image node\n appendImage: (editor: Editor, imageData: { src: string; alt: string }, id: string) => {\n const [node] = Editor.nodes<CosmosCustom.ImagePlaceholderElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image-placeholder',\n at: [Number(id)]\n });\n\n if (node) {\n const [, path] = node;\n Transforms.setNodes(\n editor,\n { type: 'image', src: imageData.src, alt: imageData.alt },\n { at: path }\n );\n Transforms.unsetNodes(editor, 'id', { at: path });\n return Editor.end(editor, path);\n }\n return null;\n },\n appendImagePlaceholder: (editor: Editor): string => {\n const node = commands.getSelectedNode(editor);\n\n if (node) {\n const [, path] = node;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'image-placeholder', children: [{ text: '' }] },\n { at: next }\n );\n return next[0].toString();\n }\n return '';\n },\n // Creates a link at the given selection\n createLink: (editor: Editor, text: string, url: string, selection: Range | null) => {\n const linkNode = { text: text || url, href: url };\n if (selection) {\n if (Range.isCollapsed(selection)) {\n const [node] = Editor.node(editor, selection);\n if (Text.isText(node) && node.href) {\n const before = Editor.before(editor, selection, { unit: 'word' });\n const after = Editor.after(editor, selection, { unit: 'word' });\n\n if (before && after) {\n Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });\n } else if (before) {\n const calculatedAfter = Editor.after(editor, before, { unit: 'word' });\n if (calculatedAfter) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: before, focus: calculatedAfter }\n });\n }\n } else if (after) {\n const calculatedBefore = Editor.before(editor, after, { unit: 'word' });\n if (calculatedBefore) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: calculatedBefore, focus: after }\n });\n }\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n } else {\n Transforms.insertNodes(editor, [linkNode], {\n at: selection\n });\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n },\n // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph\n checkImageEnter: (editor: Editor, e: KeyboardEvent) => {\n const [image] = Editor.nodes<CosmosCustom.ImageElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image'\n });\n if (image) {\n if (e.keyCode < 37 && e.keyCode > 40) {\n e.preventDefault();\n }\n if (e.key === 'Enter') {\n e.preventDefault();\n const [, path] = image;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'paragraph', children: [{ text: '' }] },\n { at: next }\n );\n Transforms.select(editor, next);\n }\n }\n },\n // Turns the href and/or searchResult property off on the text node when space is pressed while on a link or mention\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if ((link || searchResult) && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, link ? 'href' : 'searchResult');\n }\n },\n /**\n * Turns the searchResult property off on the text node when any key is pressed while on a searchResult.\n * Will delete the searchResult node if backspace key is hit.\n * Will re-position cursor to the start/end of the searchResult if arrow navigation is used.\n */\n checkSearchDownKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n const nextNode = Editor.next(editor)?.[0] as Text;\n const nextPath = Editor.next(editor)?.[1];\n const previousNode = Editor.previous(editor)?.[0] as Text;\n const previousPath = Editor.previous(editor)?.[1];\n\n const next = nextNode && nextNode.searchResult;\n const nextInline = next && path[0] === nextPath?.[0];\n const previous = previousNode && previousNode.searchResult;\n const previousInline = previous && path[0] === previousPath?.[0];\n\n // Checks if the current selection is a single cursor point rather than spanning multiple characters\n const singlePointSelection =\n editor.selection?.anchor.offset === editor.selection?.focus.offset &&\n editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&\n editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];\n\n // Checks if the current selected node is a search result, or directly adjacent inline with a search result\n if (node.searchResult || (next && nextInline) || (previous && previousInline)) {\n const atStart = node.searchResult && editor.selection?.anchor.offset === 0;\n const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;\n\n // Deletes the entire search result only if the cursor is at the end of the search result\n if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: previous ? previousPath : path });\n // Deletes the entire search result only if the cursor is at the start of the search result\n } else if (e.key === 'Delete' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: next ? nextPath : path });\n // Moves cursor to start of search result only if the cursor is at the end of the search result\n } else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: previous ? previousNode.text.length : node.text.length,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result only if the cursor is at the start of the search result\n } else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: next ? nextNode.text.length : node.text.length,\n unit: 'character'\n });\n // Ensures all other character (besides special key bindings) are inserted as plain text\n } else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : e.key });\n }\n\n // Prevents partial search result selections from disabling the searchResult flag\n if (singlePointSelection) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n }\n },\n // Checks arrow navigation key up events around search results\n checkSearchUpKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n\n const cursorInSearchResult =\n node.searchResult &&\n editor.selection?.anchor.path[0] === path[0] &&\n editor.selection?.anchor.path[1] === path[1];\n\n if (cursorInSearchResult && editor.selection) {\n const distanceToStart = editor.selection.anchor.offset;\n const distanceToEnd = node.text.length - editor.selection.anchor.offset;\n // Moves cursor to the start of the search result\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result\n } else if (e.key === 'ArrowRight') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToEnd,\n unit: 'character'\n });\n // Moves cursor to start or end of search result, whichever is closer\n } else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,\n unit: 'character',\n reverse: distanceToStart <= distanceToEnd\n });\n }\n }\n }\n },\n // Either adds a tab character or indents a list depending on the selection\n indent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.nestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n Transforms.insertText(editor, '\\t', { at: start });\n }\n },\n // Either removes a tab character or un indents a list depending on the selection\n unindent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListItemElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.unNestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n let end = Editor.after(editor, editor.selection, { unit: 'block' });\n end = end || Editor.end(editor, editor.selection);\n if (start && end) {\n const text = Editor.string(editor, { anchor: start, focus: end });\n const newText = text.replace(/\\t/, '');\n Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });\n }\n }\n },\n checkKeyCommands: (editor: Editor, e: KeyboardEvent, markdownOnly?: boolean) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl && !markdownOnly) {\n // Command or Ctrl + Shift\n if (e.shiftKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n case 'x':\n commands.toggleFormat('line-through', editor);\n commandExecuted = true;\n break;\n case 'l':\n ListCommands.toggleList('unordered-list', editor);\n commandExecuted = true;\n break;\n default:\n }\n // Command or Ctrl but not alt\n } else if (!e.shiftKey && !e.altKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n } else if (cmdOrCtrl && markdownOnly && !e.shiftKey && !e.altKey && e.key === 'x') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n\n if (e.altKey && !markdownOnly) {\n if (cmdOrCtrl) {\n if (textKeyCodeMapping[e.keyCode]) {\n commands.setBlock(textKeyCodeMapping[e.keyCode], editor);\n commandExecuted = true;\n }\n } else if (e.keyCode === 77) {\n if (e.shiftKey) {\n commands.unindent(editor);\n commandExecuted = true;\n } else {\n commands.indent(editor);\n commandExecuted = true;\n }\n }\n }\n\n if (markdownOnly && e.key === 'Backspace') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n if (!editor.selection) {\n Transforms.select(editor, {\n anchor: { offset: 0, path: [0, 0] },\n focus: { offset: 0, path: [0, 0] }\n });\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
|
|
1
|
+
{"version":3,"file":"EditorCommands.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/EditorCommands.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,EACL,IAAI,EAGJ,OAAO,EACP,IAAI,EAEL,MAAM,OAAO,CAAC;AAIf,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,kBAAkB,GAAuC;IAC7D,EAAE,EAAE,WAAW;IACf,EAAE,EAAE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AAI,CAAC;iBACxB;aACF;iBAAM,IAAI,CAAC,CAAC,OAAO,KAAK,EAAE,EAAE;gBAC3B,IAAI,CAAC,CAAC,QAAQ,EAAE;oBACd,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBAC1B,eAAe,GAAG,IAAI,CAAC;iBACxB;qBAAM;oBACL,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACxB,eAAe,GAAG,IAAI,CAAC;iBACxB;aACF;SACF;QAED,IAAI,YAAY,IAAI,CAAC,CAAC,GAAG,KAAK,WAAW,EAAE;YACzC,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,KAAK,CAAO,MAAM,EAAE;gBAChD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY;aAC/C,CAAC,CAAC;YACH,IAAI,YAAY,EAAE;gBAChB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;aAC3C;YACD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;gBACrB,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE;oBACxB,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;oBACnC,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;iBACnC,CAAC,CAAC;aACJ;SACF;QAED,IAAI,eAAe;YAAE,CAAC,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { KeyboardEvent } from 'react';\nimport {\n Editor,\n Transforms,\n Range,\n Path,\n NodeEntry,\n Node,\n Element,\n Text,\n CosmosCustom\n} from 'slate';\n\nimport { ExcludeStrict } from '@pega/cosmos-react-core';\n\nimport ListCommands from './ListCommands';\n\nconst textKeyCodeMapping: { [key: number]: Element['type'] } = {\n 48: 'paragraph',\n 49: 'heading-1',\n 50: 'heading-2',\n 51: 'heading-3',\n 52: 'heading-4'\n};\n\nconst commands = {\n // Checks if an inline format is active\n isFormatActive: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => {\n const marks = Editor.marks(editor);\n return marks ? marks[format] === true : false;\n },\n // Toggles an inline format on or off\n toggleFormat: (format: ExcludeStrict<keyof Text, 'text'>, editor: Editor) => {\n const formatActive = commands.isFormatActive(format, editor);\n if (formatActive) {\n Editor.removeMark(editor, format);\n } else {\n Editor.addMark(editor, format, true);\n }\n },\n // Checks if a block level format is active\n isBlockActive: (format: Element['type'], editor: Editor) => {\n const [match] = Editor.nodes<Element>(editor, {\n match: n => Element.isElement(n) && n.type === format\n });\n\n return !!match;\n },\n // Gets the active block level type\n getActiveBlockType: (editor: Editor): string => {\n const [match] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: Element.isElement,\n mode: 'lowest'\n });\n\n if (match) {\n return match[0].type;\n }\n return '';\n },\n // Sets the block type of the currently selected block\n setBlock: (format: Element['type'], editor: Editor) => {\n Transforms.setNodes(editor, { type: format }, { mode: 'lowest' });\n },\n // Replaces a target in the editor with the given text\n replaceWithText: (editor: Editor, target: Range | null, text: string) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertText(editor, text);\n Transforms.move(editor);\n },\n // Replaces a target in the editor with the given node\n replaceWithNodes: (editor: Editor, target: Range | null, node: Node) => {\n if (target) {\n Transforms.select(editor, target);\n }\n Transforms.insertNodes(editor, node);\n },\n // Gets the highest selected block level node\n getSelectedNode: (editor: Editor): NodeEntry<Node> => {\n const [node] = Editor.nodes<Element>(editor, {\n at: editor.selection || undefined,\n match: n => Element.isElement(n),\n mode: 'highest'\n });\n return node;\n },\n // Appends a 3x3 table into the editor and adds a blank line to the bottom\n appendTable: (editor: Editor) => {\n const baseArr: unknown[][] = new Array(3).fill(new Array(3).fill(0));\n const table: [CosmosCustom.TableElement, CosmosCustom.ParagraphElement] = [\n {\n type: 'table',\n children: [\n {\n type: 'table-body',\n children: baseArr.map(row => {\n return {\n type: 'table-row',\n children: row.map(() => {\n return {\n type: 'table-cell',\n children: [{ type: 'paragraph', children: [{ text: '' }] }]\n };\n })\n };\n })\n }\n ]\n },\n {\n type: 'paragraph',\n children: [{ text: '' }]\n }\n ];\n\n Transforms.insertNodes(editor, table, { mode: 'highest' });\n const [firstTableCell] = Editor.nodes<CosmosCustom.ParagraphElement>(editor, {\n at: editor.selection?.anchor.path.slice(0, 1),\n match: n => Element.isElement(n) && n.type === 'paragraph',\n mode: 'highest'\n });\n if (firstTableCell) {\n const [, path] = firstTableCell;\n path.push(0);\n const nextPosition = { path, offset: 0 };\n Transforms.setSelection(editor, { anchor: nextPosition, focus: nextPosition });\n }\n },\n // Finds the image placeholder and replaces it with an image node\n appendImage: (editor: Editor, imageData: { src: string; alt: string }, id: string) => {\n const [node] = Editor.nodes<CosmosCustom.ImagePlaceholderElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image-placeholder',\n at: [Number(id)]\n });\n\n if (node) {\n const [, path] = node;\n Transforms.setNodes(\n editor,\n { type: 'image', src: imageData.src, alt: imageData.alt },\n { at: path }\n );\n Transforms.unsetNodes(editor, 'id', { at: path });\n return Editor.end(editor, path);\n }\n return null;\n },\n appendImagePlaceholder: (editor: Editor): string => {\n const node = commands.getSelectedNode(editor);\n\n if (node) {\n const [, path] = node;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'image-placeholder', children: [{ text: '' }] },\n { at: next }\n );\n return next[0].toString();\n }\n return '';\n },\n // Creates a link at the given selection\n createLink: (editor: Editor, text: string, url: string, selection: Range | null) => {\n const linkNode = { text: text || url, href: url };\n if (selection) {\n if (Range.isCollapsed(selection)) {\n const [node] = Editor.node(editor, selection);\n if (Text.isText(node) && node.href) {\n const before = Editor.before(editor, selection, { unit: 'word' });\n const after = Editor.after(editor, selection, { unit: 'word' });\n\n if (before && after) {\n Transforms.insertNodes(editor, [linkNode], { at: { anchor: before, focus: after } });\n } else if (before) {\n const calculatedAfter = Editor.after(editor, before, { unit: 'word' });\n if (calculatedAfter) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: before, focus: calculatedAfter }\n });\n }\n } else if (after) {\n const calculatedBefore = Editor.before(editor, after, { unit: 'word' });\n if (calculatedBefore) {\n Transforms.insertNodes(editor, [linkNode], {\n at: { anchor: calculatedBefore, focus: after }\n });\n }\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n } else {\n Transforms.insertNodes(editor, [linkNode], {\n at: selection\n });\n }\n } else {\n Transforms.insertNodes(editor, [linkNode]);\n }\n },\n // Used to handle the enter key when the cursor is next to an image, inserts a new paragraph\n checkImageEnter: (editor: Editor, e: KeyboardEvent) => {\n const [image] = Editor.nodes<CosmosCustom.ImageElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'image'\n });\n if (image) {\n if (e.keyCode < 37 && e.keyCode > 40) {\n e.preventDefault();\n }\n if (e.key === 'Enter') {\n e.preventDefault();\n const [, path] = image;\n const next = Path.next(path);\n Transforms.insertNodes(\n editor,\n { type: 'paragraph', children: [{ text: '' }] },\n { at: next }\n );\n Transforms.select(editor, next);\n }\n }\n },\n // Turns the href and/or searchResult property off on the text node when space is pressed while on a link or mention\n checkLinkBreak: (editor: Editor, e: KeyboardEvent) => {\n const [link] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.href\n });\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if ((link || searchResult) && (e.key === ' ' || e.key === 'Enter')) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : ' ' });\n Editor.removeMark(editor, link ? 'href' : 'searchResult');\n }\n },\n /**\n * Turns the searchResult property off on the text node when any key is pressed while on a searchResult.\n * Will delete the searchResult node if backspace key is hit.\n * Will re-position cursor to the start/end of the searchResult if arrow navigation is used.\n */\n checkSearchDownKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n const nextNode = Editor.next(editor)?.[0] as Text;\n const nextPath = Editor.next(editor)?.[1];\n const previousNode = Editor.previous(editor)?.[0] as Text;\n const previousPath = Editor.previous(editor)?.[1];\n\n const next = nextNode && nextNode.searchResult;\n const nextInline = next && path[0] === nextPath?.[0];\n const previous = previousNode && previousNode.searchResult;\n const previousInline = previous && path[0] === previousPath?.[0];\n\n // Checks if the current selection is a single cursor point rather than spanning multiple characters\n const singlePointSelection =\n editor.selection?.anchor.offset === editor.selection?.focus.offset &&\n editor.selection?.anchor.path[0] === editor.selection?.focus.path[0] &&\n editor.selection?.anchor.path[1] === editor.selection?.focus.path[1];\n\n // Checks if the current selected node is a search result, or directly adjacent inline with a search result\n if (node.searchResult || (next && nextInline) || (previous && previousInline)) {\n const atStart = node.searchResult && editor.selection?.anchor.offset === 0;\n const atEnd = node.searchResult && editor.selection?.anchor.offset === node.text.length;\n\n // Deletes the entire search result only if the cursor is at the end of the search result\n if (e.key === 'Backspace' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: previous ? previousPath : path });\n // Deletes the entire search result only if the cursor is at the start of the search result\n } else if (e.key === 'Delete' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.delete(editor, { at: next ? nextPath : path });\n // Moves cursor to start of search result only if the cursor is at the end of the search result\n } else if (e.key === 'ArrowLeft' && (atEnd || (previous && previousInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: previous ? previousNode.text.length : node.text.length,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result only if the cursor is at the start of the search result\n } else if (e.key === 'ArrowRight' && (atStart || (next && nextInline))) {\n if (singlePointSelection) e.preventDefault();\n Transforms.move(editor, {\n distance: next ? nextNode.text.length : node.text.length,\n unit: 'character'\n });\n // Ensures all other character (besides special key bindings) are inserted as plain text\n } else if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {\n e.preventDefault();\n Editor.insertNode(editor, { text: e.key === 'Enter' ? '\\n' : e.key });\n }\n\n // Prevents partial search result selections from disabling the searchResult flag\n if (singlePointSelection) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n }\n },\n // Checks arrow navigation key up events around search results\n checkSearchUpKeys: (editor: Editor, e: KeyboardEvent) => {\n const [text] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n)\n });\n\n if (text) {\n const [node, path] = text;\n\n const cursorInSearchResult =\n node.searchResult &&\n editor.selection?.anchor.path[0] === path[0] &&\n editor.selection?.anchor.path[1] === path[1];\n\n if (cursorInSearchResult && editor.selection) {\n const distanceToStart = editor.selection.anchor.offset;\n const distanceToEnd = node.text.length - editor.selection.anchor.offset;\n // Moves cursor to the start of the search result\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart,\n unit: 'character',\n reverse: true\n });\n // Moves cursor to end of search result\n } else if (e.key === 'ArrowRight') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToEnd,\n unit: 'character'\n });\n // Moves cursor to start or end of search result, whichever is closer\n } else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n Transforms.move(editor, {\n distance: distanceToStart <= distanceToEnd ? distanceToStart : distanceToEnd,\n unit: 'character',\n reverse: distanceToStart <= distanceToEnd\n });\n }\n }\n }\n },\n // Either adds a tab character or indents a list depending on the selection\n indent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.nestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n Transforms.insertText(editor, '\\t', { at: start });\n }\n },\n // Either removes a tab character or un indents a list depending on the selection\n unindent: (editor: Editor) => {\n const [nodeInListItem] = Editor.nodes<CosmosCustom.ListItemElement>(editor, {\n match: n => Element.isElement(n) && n.type === 'list-item'\n });\n\n if (nodeInListItem) {\n ListCommands.unNestList(editor);\n return;\n }\n\n if (editor.selection) {\n let start = Editor.before(editor, editor.selection, { unit: 'block' });\n start = start || Editor.start(editor, editor.selection);\n let end = Editor.after(editor, editor.selection, { unit: 'block' });\n end = end || Editor.end(editor, editor.selection);\n if (start && end) {\n const text = Editor.string(editor, { anchor: start, focus: end });\n const newText = text.replace(/\\t/, '');\n Transforms.insertText(editor, newText, { at: { anchor: start, focus: end } });\n }\n }\n },\n checkKeyCommands: (editor: Editor, e: KeyboardEvent, markdownOnly?: boolean) => {\n const cmdOrCtrl = e.metaKey || e.ctrlKey;\n let commandExecuted = false;\n if (cmdOrCtrl && !markdownOnly) {\n // Command or Ctrl + Shift\n if (e.shiftKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n case 'x':\n commands.toggleFormat('line-through', editor);\n commandExecuted = true;\n break;\n case 'l':\n ListCommands.toggleList('unordered-list', editor);\n commandExecuted = true;\n break;\n default:\n }\n // Command or Ctrl but not alt\n } else if (!e.shiftKey && !e.altKey) {\n switch (e.key) {\n case 'b':\n commands.toggleFormat('bold', editor);\n commandExecuted = true;\n break;\n case 'i':\n commands.toggleFormat('italic', editor);\n commandExecuted = true;\n break;\n default:\n }\n }\n } else if (cmdOrCtrl && markdownOnly && !e.shiftKey && !e.altKey && e.key === 'x') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n }\n\n if (e.altKey && !markdownOnly) {\n if (cmdOrCtrl) {\n if (textKeyCodeMapping[e.keyCode]) {\n commands.setBlock(textKeyCodeMapping[e.keyCode], editor);\n commandExecuted = true;\n }\n } else if (e.keyCode === 77) {\n if (e.shiftKey) {\n commands.unindent(editor);\n commandExecuted = true;\n } else {\n commands.indent(editor);\n commandExecuted = true;\n }\n }\n }\n\n if (markdownOnly && e.key === 'Backspace') {\n const [searchResult] = Editor.nodes<Text>(editor, {\n match: n => Text.isText(n) && !!n.searchResult\n });\n if (searchResult) {\n Editor.removeMark(editor, 'searchResult');\n }\n if (!editor.selection) {\n Transforms.select(editor, {\n anchor: { offset: 0, path: [0, 0] },\n focus: { offset: 0, path: [0, 0] }\n });\n }\n }\n\n if (commandExecuted) e.preventDefault();\n }\n};\n\nexport default commands;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slateConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"slateConverter.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAIpD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;CAoB1B,CAAC;AA8BF,eAAO,MAAM,aAAa,UAAW,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,KAAG,MAkCzD,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,KAAG,MAW9D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slateConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"slateConverter.js","sourceRoot":"","sources":["../../../../src/components/RichTextEditor/utils/slateConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAIpD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,GAAG;IACT,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI;IACpB,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,OAAO;IACrB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,GAAG;IACd,IAAI,EAAE,GAAG;IACT,cAAc,EAAE,KAAK;IACrB,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,oHAAoH;AACpH,MAAM,QAAQ,GAAG,CACf,EAA6F,EAC7F,EAAE;IACF,mDAAmD;IACnD,QAAQ,EAAE,CAAC,IAAI,EAAE;QACf,KAAK,WAAW;YACd,OAAO;gBACL,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;gBACjC,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE;gBAC9C,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE;gBACvC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE;aACxC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACrB,IAAI,IAAI,CAAC,KAAK,EAAE;oBACd,OAAO,GAAG,GAAG,IAAI,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AAC;AACrC,CAAC,CAAC","sourcesContent":["import { CosmosCustom, Element, Text } from 'slate';\n\nimport { ExcludeStrict } from '@pega/cosmos-react-core';\n\nexport const slateToHtmlMap = {\n link: 'a',\n 'heading-1': 'h1',\n 'heading-2': 'h2',\n 'heading-3': 'h3',\n 'heading-4': 'h4',\n 'unordered-list': 'ul',\n 'ordered-list': 'ol',\n 'list-item': 'li',\n table: 'table',\n 'table-body': 'tbody',\n 'table-row': 'tr',\n 'table-cell': 'td',\n text: 'span',\n paragraph: 'p',\n bold: 'b',\n 'line-through': 'del',\n italic: 'i',\n href: 'a',\n image: 'img'\n};\n\n// Reduces the properties in a slate node into the correct html attributes, mostly used for list-items at the moment\nconst getAttrs = (\n el: ExcludeStrict<Element, CosmosCustom.ImagePlaceholderElement | CosmosCustom.CustomElement>\n) => {\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (el.type) {\n case 'list-item':\n return [\n { name: 'data-id', value: el.id },\n { name: 'data-parent-id', value: el.parentId },\n { name: 'data-order', value: el.order },\n { name: 'data-level', value: el.level }\n ].reduce((acc, attr) => {\n if (attr.value) {\n return `${acc} ${attr.name}='${attr.value}'`;\n }\n return acc;\n }, '');\n default:\n return Object.keys(el).reduce((innerAcc, key) => {\n return key !== 'type' && key !== 'children'\n ? `${innerAcc} ${key}='${el[key as keyof Element]}'`\n : innerAcc;\n }, '');\n }\n};\n\n// Recursive function to reduce Slate Nodes into an HTML string\nexport const constructHtml = (nodes: (Element | Text)[]): string => {\n return nodes.reduce((acc, node) => {\n if (\n Element.isElement(node) &&\n (node.type === 'image-placeholder' || node.type === 'custom' || node.type === 'override')\n )\n return acc;\n\n const htmlTag = Element.isElement(node) ? slateToHtmlMap[node.type] : undefined;\n let html;\n if (Text.isText(node)) {\n const { text, ...restNode } = node;\n // Reducing inline style properties from a single Slate Node into the correct HTML tags\n html = Object.keys(restNode).reduce((innerAcc, key, i) => {\n const tag = slateToHtmlMap[key as 'bold' | 'line-through' | 'italic' | 'href'];\n // Add the href attribute if needed\n const firstInnerTag = tag === 'a' ? `${tag} href='${restNode[key as 'href']}'` : tag;\n\n if (i === 0) {\n return `<${firstInnerTag}>${text}</${tag}>`;\n }\n return `<${firstInnerTag}>${innerAcc}</${tag}>`;\n }, '');\n if (!html) {\n html = text;\n }\n } else {\n const attrs = getAttrs(node);\n html = `<${htmlTag}${attrs}>${constructHtml(\n (node.children as (Element | Text)[]) || []\n )}</${htmlTag}>`;\n }\n return `${acc}${html}`;\n }, '');\n};\n\nexport const convertSlateToHtml = (nodes: (Element | Text)[]): string => {\n if (\n nodes.length === 1 &&\n Element.isElement(nodes[0]) &&\n Text.isText(nodes[0].children[0]) &&\n nodes[0].children[0].text === ''\n ) {\n return '';\n }\n const htmlNodes = constructHtml(nodes);\n return `<body>${htmlNodes}</body>`;\n};\n"]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// This file is autogenerated. Any changes will be overwritten.
|
|
2
|
+
export { default as DynamicContentEditor } from './components/DynamicContentEditor';
|
|
3
|
+
export * from './components/DynamicContentEditor';
|
|
2
4
|
export * from './components/Editor';
|
|
3
5
|
export * from './components/RichTextEditor';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport * from './components/Editor';\nexport * from './components/RichTextEditor';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC","sourcesContent":["// This file is autogenerated. Any changes will be overwritten.\nexport { default as DynamicContentEditor } from './components/DynamicContentEditor';\nexport * from './components/DynamicContentEditor';\nexport * from './components/Editor';\nexport * from './components/RichTextEditor';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-rte",
|
|
3
|
-
"version": "4.0.0-dev.19.
|
|
3
|
+
"version": "4.0.0-dev.19.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/pegasystems/cosmos-react.git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"build": "tsc -b"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@pega/cosmos-react-core": "4.0.0-dev.19.
|
|
23
|
+
"@pega/cosmos-react-core": "4.0.0-dev.19.3",
|
|
24
24
|
"@popperjs/core": "^2.11.6",
|
|
25
25
|
"@types/marked": "^4.0.2",
|
|
26
26
|
"@types/parse5": "^6.0.0",
|