@pega/cosmos-react-rte 3.0.0-dev.2.0 → 3.0.0-dev.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/lib/components/Editor/Editor.d.ts +6 -0
  2. package/lib/components/Editor/Editor.d.ts.map +1 -1
  3. package/lib/components/Editor/Editor.js +167 -50
  4. package/lib/components/Editor/Editor.js.map +1 -1
  5. package/lib/components/Editor/Editor.styles.d.ts +3 -0
  6. package/lib/components/Editor/Editor.styles.d.ts.map +1 -0
  7. package/lib/components/Editor/Editor.styles.js +30 -0
  8. package/lib/components/Editor/Editor.styles.js.map +1 -0
  9. package/lib/components/Editor/Editor.types.d.ts +29 -10
  10. package/lib/components/Editor/Editor.types.d.ts.map +1 -1
  11. package/lib/components/Editor/Editor.types.js.map +1 -1
  12. package/lib/components/Editor/ImageEditor.d.ts +10 -0
  13. package/lib/components/Editor/ImageEditor.d.ts.map +1 -0
  14. package/lib/components/Editor/ImageEditor.js +274 -0
  15. package/lib/components/Editor/ImageEditor.js.map +1 -0
  16. package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +1 -1
  17. package/lib/components/Editor/Toolbar/AnchorButton.js +33 -15
  18. package/lib/components/Editor/Toolbar/AnchorButton.js.map +1 -1
  19. package/lib/components/Editor/Toolbar/ImageButton.js +2 -2
  20. package/lib/components/Editor/Toolbar/ImageButton.js.map +1 -1
  21. package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -1
  22. package/lib/components/Editor/Toolbar/TextSelect.js +4 -3
  23. package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -1
  24. package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -1
  25. package/lib/components/Editor/Toolbar/Toolbar.js +10 -14
  26. package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -1
  27. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js +1 -1
  28. package/lib/components/RichTextEditor/DecoratorComponents/CodeBlock.js.map +1 -1
  29. package/lib/components/RichTextEditor/DecoratorComponents/Image.js +2 -2
  30. package/lib/components/RichTextEditor/DecoratorComponents/Image.js.map +1 -1
  31. package/lib/components/RichTextEditor/DecoratorComponents/Link.js +3 -3
  32. package/lib/components/RichTextEditor/DecoratorComponents/Link.js.map +1 -1
  33. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +0 -2
  34. package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
  35. package/lib/components/RichTextEditor/DecoratorComponents/Table.js +6 -33
  36. package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
  37. package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
  38. package/lib/components/RichTextEditor/RichTextEditor.js +34 -8
  39. package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
  40. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +0 -2
  41. package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
  42. package/lib/components/RichTextEditor/RichTextEditor.styles.js +17 -119
  43. package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
  44. package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
  45. package/lib/components/RichTextEditor/RichTextViewer.js +11 -12
  46. package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
  47. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts +3 -3
  48. package/lib/components/RichTextEditor/RichTextViewer.types.d.ts.map +1 -1
  49. package/lib/components/RichTextEditor/RichTextViewer.types.js.map +1 -1
  50. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js +4 -4
  51. package/lib/components/RichTextEditor/Toolbar/AnchorButton.js.map +1 -1
  52. package/lib/components/RichTextEditor/Toolbar/ImageButton.js +2 -2
  53. package/lib/components/RichTextEditor/Toolbar/ImageButton.js.map +1 -1
  54. package/lib/components/RichTextEditor/Toolbar/IndentButton.js +1 -1
  55. package/lib/components/RichTextEditor/Toolbar/IndentButton.js.map +1 -1
  56. package/lib/components/RichTextEditor/Toolbar/TableButton.js +1 -1
  57. package/lib/components/RichTextEditor/Toolbar/TableButton.js.map +1 -1
  58. package/lib/components/RichTextEditor/Toolbar/TextSelect.js +2 -2
  59. package/lib/components/RichTextEditor/Toolbar/TextSelect.js.map +1 -1
  60. package/lib/components/RichTextEditor/Toolbar/Toolbar.js +4 -4
  61. package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
  62. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +1 -1
  63. package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
  64. package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
  65. package/lib/components/RichTextEditor/utils/htmlConverter.js +5 -2
  66. package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
  67. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts +1 -1
  68. package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -1
  69. package/lib/components/RichTextEditor/utils/interactionRenderer.js +1 -4
  70. package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
  71. package/lib/components/RichTextEditor/utils/markdownConverter.js +3 -3
  72. package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
  73. package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
  74. package/lib/components/RichTextEditor/utils/renderers.js +35 -22
  75. package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
  76. package/lib/components/RichTextEditor/utils/slateConverter.d.ts +1 -0
  77. package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
  78. package/lib/components/RichTextEditor/utils/slateConverter.js +1 -0
  79. package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
  80. package/package.json +23 -19
@@ -2,9 +2,15 @@ import 'tinymce/icons/default';
2
2
  import 'tinymce/themes/silver';
3
3
  import 'tinymce/plugins/advlist';
4
4
  import 'tinymce/plugins/lists';
5
+ import 'tinymce/plugins/paste';
5
6
  import { FC } from 'react';
7
+ import { DefaultTheme } from 'styled-components';
6
8
  import { ForwardProps } from '@pega/cosmos-react-core';
7
9
  import { EditorProps } from './Editor.types';
10
+ export declare const getImageStyles: (theme: DefaultTheme) => string;
11
+ export declare const StyledInnerEditor: import("styled-components").StyledComponent<"div", DefaultTheme, {
12
+ showPlaceholder: boolean;
13
+ }, never>;
8
14
  declare const Editor: FC<EditorProps & ForwardProps>;
9
15
  export default Editor;
10
16
  //# sourceMappingURL=Editor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../../src/components/Editor/Editor.tsx"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EACL,EAAE,EASH,MAAM,OAAO,CAAC;AAGf,OAAO,EAIL,YAAY,EAOb,MAAM,yBAAyB,CAAC;AAWjC,OAAO,EAAE,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAiB1D,QAAA,MAAM,MAAM,EAAE,EAAE,CAAC,WAAW,GAAG,YAAY,CAuQ1C,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../../src/components/Editor/Editor.tsx"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EACL,EAAE,EASH,MAAM,OAAO,CAAC;AACf,OAAe,EAAO,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAI9D,OAAO,EAIL,YAAY,EASb,MAAM,yBAAyB,CAAC;AAejC,OAAO,EAAE,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAI1D,eAAO,MAAM,cAAc,UAAW,YAAY,WAQjD,CAAC;AAEF,eAAO,MAAM,iBAAiB;qBAAiC,OAAO;SAarE,CAAC;AAIF,QAAA,MAAM,MAAM,EAAE,EAAE,CAAC,WAAW,GAAG,YAAY,CA4Y1C,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -4,61 +4,105 @@ import 'tinymce/icons/default';
4
4
  import 'tinymce/themes/silver';
5
5
  import 'tinymce/plugins/advlist';
6
6
  import 'tinymce/plugins/lists';
7
+ import 'tinymce/plugins/paste';
7
8
  import { forwardRef, useEffect, useRef, useState, useLayoutEffect, useImperativeHandle } from 'react';
8
9
  import styled, { css } from 'styled-components';
9
- import { createUID, FormControl, FormField, useAfterInitialEffect, useTheme, useUID, useI18n, useConsolidatedRef, defaultThemeProp } from '@pega/cosmos-react-core';
10
- import StyledRichTextEditor, { StyledEditorContainer, StyledRichTextFormField, StyledHtml } from '../RichTextEditor/RichTextEditor.styles';
10
+ import { compile, serialize, stringify } from 'stylis';
11
+ import { stripUnit } from 'polished';
12
+ import { createUID, FormControl, FormField, useAfterInitialEffect, useTheme, useUID, useI18n, useConsolidatedRef, defaultThemeProp, useAutoResize, useConfiguration } from '@pega/cosmos-react-core';
13
+ import { getHtmlStyles } from '@pega/cosmos-react-core/lib/components/HTML/HTML';
14
+ import { createGlobalBodyStyles, createGlobalRootStyles, globalSpacingStyles } from '@pega/cosmos-react-core/lib/styles/GlobalStyle';
15
+ import StyledRichTextEditor, { StyledRichTextFormField } from '../RichTextEditor/RichTextEditor.styles';
11
16
  import Toolbar from './Toolbar/Toolbar';
12
17
  import EditorContext from './Editor.context';
13
18
  import { getTextFormats } from './Toolbar/TextSelect';
14
- const StyledInnerEditor = styled.div(({ theme, showPlaceholder }) => {
19
+ import ImageEditor, { imgHoverClass } from './ImageEditor';
20
+ import { offscreenSelectionStyles, StyledEditorContainer } from './Editor.styles';
21
+ export const getImageStyles = (theme) => {
22
+ return `
23
+ img:hover,
24
+ img.${imgHoverClass} {
25
+ box-shadow: 0 0 0 0.06125rem ${theme.base.palette['primary-background']},
26
+ 0 0 0 0.125rem ${theme.base.palette.interactive}, 0 0 0 0.25rem rgba(0, 118, 209, 0.3);
27
+ }
28
+ `;
29
+ };
30
+ export const StyledInnerEditor = styled.div(({ theme, showPlaceholder }) => {
15
31
  return css `
16
- ${showPlaceholder &&
32
+ ${showPlaceholder &&
17
33
  css `
18
- ::before {
19
- color: ${theme.base.colors.slate.medium};
20
- position: absolute;
21
- content: attr(data-mce-placeholder);
22
- }
23
- `}
24
- `;
34
+ ::before {
35
+ color: ${theme.base.colors.slate.medium};
36
+ position: absolute;
37
+ content: attr(data-mce-placeholder);
38
+ }
39
+ `}
40
+ `;
25
41
  });
26
42
  StyledInnerEditor.defaultProps = defaultThemeProp;
27
43
  const Editor = forwardRef((props, ref) => {
28
- const { components: { 'text-area': { 'min-height': minHeight } } } = useTheme();
44
+ const { components: { 'text-area': { 'min-height': textAreaMinHeight } } } = useTheme();
45
+ const theme = useTheme();
46
+ const { styleSheetTarget } = useConfiguration();
29
47
  const [editor, setEditor] = useState();
48
+ const [focused, setFocused] = useState(false);
30
49
  const t = useI18n();
31
50
  const uid = useUID();
32
51
  const labelId = useUID();
33
52
  const editorRef = useConsolidatedRef(ref);
53
+ const tinyMceRef = useRef(null);
54
+ const tinyMceContainerRef = useRef(null);
34
55
  const initialized = useRef(false);
35
- const { id = uid, toolbar = [], label, labelHidden, info, status, required, disabled, readOnly, onChange, onFocus, onBlur, onImageAdded, onInit, defaultValue, customComponents = [], height = { min: minHeight }, customActions, placeholder, ...restProps } = props;
36
- const [showPlaceholder, setShowPlaceholder] = useState(() => !defaultValue);
56
+ const { id = uid, toolbar = [], label, labelHidden, info, status, required, disabled, readOnly, onChange, onKeyDown, onFocus, onBlur, onImageAdded, onInit, defaultValue, customComponents = [], height, customActions, placeholder, children, spellcheck = true, ...restProps } = props;
57
+ const baseHeight = {
58
+ min: height?.min ?? stripUnit(textAreaMinHeight) * 16,
59
+ max: height?.max ?? undefined
60
+ };
61
+ const getHeight = (type) => {
62
+ if (typeof baseHeight === 'number') {
63
+ return stripUnit(baseHeight);
64
+ }
65
+ if (baseHeight[type]) {
66
+ return stripUnit(baseHeight[type]);
67
+ }
68
+ return undefined;
69
+ };
70
+ const imagesEnabled = toolbar.includes('images');
71
+ const maxHeight = getHeight('max');
72
+ const minHeight = getHeight('min');
73
+ const [autoResizeRef, resizeEditor] = useAutoResize(maxHeight, minHeight);
37
74
  const formFieldRef = useRef(null);
38
75
  const value = useRef(defaultValue);
76
+ const renderToolbar = editor && toolbar.length > 0 && !readOnly && !disabled;
77
+ const pastePreprocess = (plugin, args) => {
78
+ if (!imagesEnabled && args.content.includes('<img')) {
79
+ args.content = '';
80
+ }
81
+ };
39
82
  useImperativeHandle(editorRef, () => ({
40
83
  focus: () => {
41
84
  editor?.focus();
42
85
  },
43
86
  getPlainText: () => {
44
- return editor ? editor?.getContent({ format: 'text' }) : '';
87
+ return editor ? editor.getContent({ format: 'text' }) : '';
45
88
  },
46
89
  getRichText: () => {
47
- return editor ? JSON.stringify(editor?.getContent({ format: 'raw' })) : '';
90
+ return editor ? JSON.stringify(editor.getContent({ format: 'raw' })) : '';
48
91
  },
49
92
  getHtml: () => {
50
- return editor ? editor?.getContent({ format: 'html' }) : '';
93
+ return editor ? editor.getContent({ format: 'html' }) : '';
51
94
  },
52
95
  clear: () => {
53
96
  editor?.setContent('');
54
97
  },
55
98
  appendImage: ({ src, alt }, imageId) => {
56
99
  if (editor) {
57
- const editorEl = editor.getElement();
100
+ const editorEl = editor.getDoc();
58
101
  const imageEl = editorEl.querySelector(`#${imageId}`);
59
102
  if (imageEl) {
60
103
  imageEl.setAttribute('src', src);
61
104
  imageEl.setAttribute('alt', alt);
105
+ resizeEditor();
62
106
  }
63
107
  }
64
108
  },
@@ -73,32 +117,56 @@ const Editor = forwardRef((props, ref) => {
73
117
  },
74
118
  getEditor: () => {
75
119
  return editor;
76
- }
120
+ },
121
+ element: formFieldRef.current || undefined
77
122
  }), [editor]);
78
123
  useLayoutEffect(() => {
124
+ if (!tinyMceRef.current || !tinyMceContainerRef.current)
125
+ return;
126
+ const styles = serialize(compile(getHtmlStyles(theme)), stringify);
127
+ const imageStyles = serialize(compile(getImageStyles(theme)), stringify);
79
128
  tinymce
80
129
  .init({
81
130
  readonly: readOnly || disabled,
82
131
  skin: false,
83
- selector: `#${id}`,
132
+ target: tinyMceRef.current,
84
133
  toolbar: false,
85
134
  menubar: false,
86
- inline: true,
87
- plugins: 'lists advlist',
135
+ plugins: 'lists advlist paste',
136
+ paste_data_images: true,
88
137
  lists_indent_on_tab: true,
89
138
  icons: '',
139
+ branding: false,
140
+ elementpath: false,
90
141
  placeholder,
91
- init_instance_callback: () => {
92
- customComponents.forEach(comp => {
93
- if (!customElements.get(comp.name)) {
94
- customElements.define(comp.name, comp.customElement);
95
- }
96
- });
142
+ content_css: false,
143
+ browser_spellcheck: spellcheck,
144
+ paste_preprocess: pastePreprocess,
145
+ content_style: `${createGlobalRootStyles(theme)} ${globalSpacingStyles} ${createGlobalBodyStyles(theme)} body { min-height: 3rem; padding: ${toolbar.length > 0 && !readOnly ? theme.base.spacing : 0}; } html { overflow: hidden; } ${offscreenSelectionStyles} ${imageStyles} ${styles}`,
146
+ init_instance_callback: initializedEditor => {
147
+ const iframeWindow = tinyMceContainerRef.current?.querySelector('iframe').contentWindow;
148
+ const editorCustomElements = iframeWindow?.customElements;
149
+ if (editorCustomElements) {
150
+ customComponents.forEach(({ name, createCustomElement: customElementCreator, style }) => {
151
+ if (!editorCustomElements.get(name)) {
152
+ editorCustomElements.define(name, customElementCreator(iframeWindow));
153
+ }
154
+ if (style) {
155
+ const styleEl = document.createElement('style');
156
+ styleEl.innerText = style;
157
+ initializedEditor.getDoc().head.appendChild(styleEl);
158
+ }
159
+ });
160
+ }
97
161
  },
98
- custom_elements: customComponents.reduce((prev, { name }, i) => {
99
- return i === 0 ? name : `${prev},${name}`;
100
- }, ''),
162
+ extended_valid_elements: `${customComponents
163
+ .map(comp => `${comp.name}${comp.extensionAttributes ? `[${comp.extensionAttributes.join('|')}]` : ''}`)
164
+ .join(',')}`,
165
+ custom_elements: `~${customComponents.map(comp => comp.name).join('~,')}`,
101
166
  setup: editorSettings => {
167
+ editorSettings.on('keydown', e => {
168
+ onKeyDown?.(e);
169
+ });
102
170
  getTextFormats().forEach((format, i) => {
103
171
  editorSettings.addShortcut(`meta+alt+${i}`, `${t('rte_change_text_format')} ${format.text}`, () => {
104
172
  editorSettings.execCommand('FormatBlock', false, format.type);
@@ -113,12 +181,37 @@ const Editor = forwardRef((props, ref) => {
113
181
  editorSettings.addShortcut('alt+shift+m', t('rte_unindent_selection'), () => {
114
182
  editorSettings.execCommand('Outdent');
115
183
  });
184
+ customActions?.forEach(action => {
185
+ if (action.shortcut) {
186
+ editorSettings.addShortcut(action.shortcut.pattern, action.shortcut.description, () => {
187
+ action.shortcut?.command(editorSettings);
188
+ });
189
+ }
190
+ });
116
191
  }
117
192
  })
118
193
  .then(tinymceEditors => {
119
194
  setEditor(tinymceEditors[0]);
195
+ tinymceEditors[0].editorContainer?.setAttribute('style', '');
196
+ const iframe = tinyMceContainerRef.current?.querySelector('iframe');
197
+ if (iframe) {
198
+ const globalStyles = styleSheetTarget?.querySelectorAll('[data-cosmos-global-style]') ??
199
+ [];
200
+ const extraStyles = document.querySelectorAll('[data-cosmos-global-style]') ?? [];
201
+ const iframeContentHead = iframe?.contentDocument?.querySelector('head');
202
+ [...globalStyles, ...extraStyles].forEach(sheet => {
203
+ iframeContentHead?.appendChild(sheet.cloneNode(true));
204
+ });
205
+ autoResizeRef.current = iframe;
206
+ resizeEditor();
207
+ }
120
208
  });
121
209
  }, []);
210
+ useEffect(() => {
211
+ if (editor) {
212
+ editor.settings.paste_preprocess = pastePreprocess;
213
+ }
214
+ }, [imagesEnabled]);
122
215
  useEffect(() => {
123
216
  if (!editor || initialized.current)
124
217
  return;
@@ -128,20 +221,37 @@ const Editor = forwardRef((props, ref) => {
128
221
  useEffect(() => {
129
222
  if (!editor)
130
223
  return;
224
+ const onChangeEvents = ['keyup', 'FormatApply', 'FormatRemove', 'ExecCommand'];
225
+ const onEditorKeyDown = (event) => {
226
+ resizeEditor();
227
+ if (event.key === 'Enter') {
228
+ editor.selection.getNode().scrollIntoView(false);
229
+ }
230
+ };
131
231
  const onEditorChange = () => {
132
- setShowPlaceholder(!editor?.getContent({ format: 'text' }));
232
+ onChange?.(editor);
133
233
  };
134
234
  const onEditorFocus = () => {
235
+ setFocused(true);
135
236
  onFocus?.();
136
237
  };
137
238
  const onEditorBlur = () => {
239
+ setFocused(false);
138
240
  onBlur?.();
139
241
  };
140
- editor.on('input', onEditorChange);
242
+ onChangeEvents.forEach(event => {
243
+ editor.on(event, onEditorChange);
244
+ });
245
+ editor.on('keydown', onEditorKeyDown);
246
+ editor.on('paste', resizeEditor);
141
247
  editor.on('focus', onEditorFocus);
142
248
  editor.on('blur', onEditorBlur);
143
249
  return () => {
144
- editor.off('input', onEditorChange);
250
+ onChangeEvents.forEach(event => {
251
+ editor.off(event, onEditorChange);
252
+ });
253
+ editor.off('keydown', onEditorKeyDown);
254
+ editor.off('paste', resizeEditor);
145
255
  editor.off('focus', onEditorFocus);
146
256
  editor.off('blur', onEditorBlur);
147
257
  };
@@ -161,31 +271,38 @@ const Editor = forwardRef((props, ref) => {
161
271
  e.preventDefault();
162
272
  if (e.dataTransfer) {
163
273
  Array.from(e.dataTransfer.files).forEach(file => {
164
- if (file.type.includes('image')) {
274
+ if (file.type.includes('image') && imagesEnabled) {
165
275
  addImage(file);
166
276
  }
167
277
  });
168
278
  }
169
279
  };
170
280
  editor?.on('drop', onEditorDrop);
281
+ const body = editor?.getDoc().body;
282
+ const resizeObserver = new ResizeObserver(() => {
283
+ resizeEditor();
284
+ });
285
+ if (body) {
286
+ resizeObserver.observe(body);
287
+ }
171
288
  return () => {
172
289
  editor?.off('drop', onEditorDrop);
290
+ resizeObserver.disconnect();
173
291
  };
174
- }, [editor]);
175
- const renderToolbar = editor && toolbar.length > 0 && !readOnly && !disabled;
176
- return (_jsx(EditorContext.Provider, { value: { addImage, editor: editor || {} }, children: _jsx(FormField, { as: StyledRichTextFormField, toolbar: renderToolbar, label:
177
- // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
178
- _jsx("span", { onClick: () => {
179
- editor?.focus();
180
- }, children: label }, void 0), labelFor: '', labelId: labelId, labelHidden: labelHidden, id: id, info: info, status: status, required: required, disabled: disabled, readOnly: readOnly, onFocus: (e) => {
181
- if (e.target === formFieldRef.current && !disabled) {
182
- editor?.focus();
183
- }
184
- }, ref: formFieldRef, tabIndex: disabled ? -1 : undefined, children: _jsxs(FormControl, { ...restProps, ref: editorRef, required: required, disabled: disabled, readOnly: readOnly, status: status, as: StyledRichTextEditor, toolbar: renderToolbar, children: [_jsx(StyledEditorContainer, { readOnly: readOnly, onClick: () => {
185
- if (!disabled) {
186
- editor?.focus();
187
- }
188
- }, toolbar: renderToolbar, containerHeight: height, children: _jsx(StyledHtml, { id: id, style: { outline: 'none', border: 'none' }, dangerouslySetInnerHTML: { __html: value.current || '' }, "aria-label": `${label}${renderToolbar ? `. ${t('rte_toolbar_instructions')}.` : ''}`, as: StyledInnerEditor, showPlaceholder: showPlaceholder, "aria-labelledby": labelId, role: 'textbox' }, void 0) }, void 0), renderToolbar && (_jsx(Toolbar, { features: toolbar, editor: editor, customActions: customActions }, void 0))] }, void 0) }, void 0) }, void 0));
292
+ }, [editor, resizeEditor]);
293
+ return (_jsxs(EditorContext.Provider, { value: { addImage, editor: editor || {} }, children: [_jsx(FormField, { as: StyledRichTextFormField, toolbar: renderToolbar, label:
294
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
295
+ _jsx("span", { onClick: () => {
296
+ editor?.focus();
297
+ }, children: label }), labelFor: '', labelId: labelId, labelHidden: labelHidden, id: id, info: info, status: status, required: required, disabled: disabled, readOnly: readOnly, onFocus: (e) => {
298
+ if (e.target === formFieldRef.current && !disabled) {
299
+ editor?.focus();
300
+ }
301
+ }, ref: formFieldRef, tabIndex: disabled ? -1 : undefined, children: _jsxs(FormControl, { ...restProps, ref: editorRef, required: required, disabled: disabled, readOnly: readOnly, status: status, as: StyledRichTextEditor, toolbar: renderToolbar, focused: focused, children: [_jsxs(StyledEditorContainer, { onClick: () => {
302
+ if (!disabled) {
303
+ editor?.focus();
304
+ }
305
+ }, ref: tinyMceContainerRef, children: [_jsx("textarea", { id: id, value: value.current || '', onChange: () => { }, "aria-label": `${label}${renderToolbar ? `. ${t('rte_toolbar_instructions')}.` : ''}`, "aria-labelledby": labelId, ref: tinyMceRef }), tinyMceContainerRef.current && editor && (_jsx(ImageEditor, { editor: editor, editorEl: tinyMceContainerRef.current, onChange: () => onChange?.(editor) }))] }), renderToolbar && (_jsx(Toolbar, { features: toolbar, editor: editor, customActions: customActions }))] }) }), children] }));
189
306
  });
190
307
  export default Editor;
191
308
  //# sourceMappingURL=Editor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/components/Editor/Editor.tsx"],"names":[],"mappings":";AAAA,OAAO,OAAoC,MAAM,iBAAiB,CAAC;AACnE,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAEL,UAAU,EAEV,SAAS,EACT,MAAM,EACN,QAAQ,EACR,eAAe,EACf,mBAAmB,EAEpB,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,SAAS,EACT,WAAW,EACX,SAAS,EAET,qBAAqB,EACrB,QAAQ,EACR,MAAM,EACN,OAAO,EACP,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,oBAAoB,EAAE,EAC3B,qBAAqB,EACrB,uBAAuB,EACvB,UAAU,EACX,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M,EAAE,EAC1C,uBAAuB,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE,EAAE,gBAC5C,GAAG,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EACnF,EAAE,EAAE,iBAAiB,EACrB,eAAe,EAAE,eAAe,qBACf,OAAO,EACxB,IAAI,EAAC,SAAS,WACd,WACoB,EACvB,aAAa,IAAI,CAChB,KAAC,OAAO,IAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,WAAI,CAC7E,YACW,WACJ,WACW,CAC1B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import tinymce, { Editor as TinymceEditor } from 'tinymce/tinymce';\nimport 'tinymce/icons/default';\nimport 'tinymce/themes/silver';\nimport 'tinymce/plugins/advlist';\nimport 'tinymce/plugins/lists';\nimport {\n FC,\n forwardRef,\n PropsWithoutRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n useImperativeHandle,\n FocusEvent\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n createUID,\n FormControl,\n FormField,\n ForwardProps,\n useAfterInitialEffect,\n useTheme,\n useUID,\n useI18n,\n useConsolidatedRef,\n defaultThemeProp\n} from '@pega/cosmos-react-core';\n\nimport StyledRichTextEditor, {\n StyledEditorContainer,\n StyledRichTextFormField,\n StyledHtml\n} from '../RichTextEditor/RichTextEditor.styles';\n\nimport Toolbar from './Toolbar/Toolbar';\nimport EditorContext from './Editor.context';\nimport { getTextFormats } from './Toolbar/TextSelect';\nimport { EditorProps, EditorState } from './Editor.types';\n\nconst StyledInnerEditor = styled.div<{ showPlaceholder: boolean }>(({ theme, showPlaceholder }) => {\n return css`\n ${showPlaceholder &&\n css`\n ::before {\n color: ${theme.base.colors.slate.medium};\n position: absolute;\n content: attr(data-mce-placeholder);\n }\n `}\n `;\n});\n\nStyledInnerEditor.defaultProps = defaultThemeProp;\n\nconst Editor: FC<EditorProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<EditorProps>, ref: EditorProps['ref']) => {\n const {\n components: {\n 'text-area': { 'min-height': minHeight }\n }\n } = useTheme();\n const [editor, setEditor] = useState<TinymceEditor>();\n const t = useI18n();\n const uid = useUID();\n const labelId = useUID();\n const editorRef = useConsolidatedRef(ref);\n const initialized = useRef(false);\n\n const {\n id = uid,\n toolbar = [],\n label,\n labelHidden,\n info,\n status,\n required,\n disabled,\n readOnly,\n onChange,\n onFocus,\n onBlur,\n onImageAdded,\n onInit,\n defaultValue,\n customComponents = [],\n height = { min: minHeight },\n customActions,\n placeholder,\n ...restProps\n } = props;\n\n const [showPlaceholder, setShowPlaceholder] = useState(() => !defaultValue);\n const formFieldRef = useRef<HTMLElement>(null);\n const value = useRef(defaultValue);\n\n useImperativeHandle<any, EditorState>(\n editorRef,\n () => ({\n focus: () => {\n editor?.focus();\n },\n getPlainText: () => {\n return editor ? editor?.getContent({ format: 'text' }) : '';\n },\n getRichText: () => {\n return editor ? JSON.stringify(editor?.getContent({ format: 'raw' })) : '';\n },\n getHtml: () => {\n return editor ? editor?.getContent({ format: 'html' }) : '';\n },\n clear: () => {\n editor?.setContent('');\n },\n appendImage: ({ src, alt }, imageId) => {\n if (editor) {\n const editorEl = editor.getElement();\n const imageEl = editorEl.querySelector(`#${imageId}`);\n if (imageEl) {\n imageEl.setAttribute('src', src);\n imageEl.setAttribute('alt', alt);\n }\n }\n },\n insertText: (text: string) => {\n editor?.insertContent(text);\n },\n insertHtml: (html: string, overwrite: boolean = false) => {\n if (overwrite) {\n editor?.setContent('');\n }\n editor?.insertContent(html);\n },\n getEditor: () => {\n return editor;\n }\n }),\n [editor]\n );\n\n useLayoutEffect(() => {\n tinymce\n .init({\n readonly: readOnly || disabled,\n skin: false,\n selector: `#${id}`,\n toolbar: false,\n menubar: false,\n inline: true,\n plugins: 'lists advlist',\n lists_indent_on_tab: true,\n icons: '',\n placeholder,\n init_instance_callback: () => {\n customComponents.forEach(comp => {\n if (!customElements.get(comp.name)) {\n customElements.define(comp.name, comp.customElement);\n }\n });\n },\n custom_elements: customComponents.reduce((prev, { name }, i) => {\n return i === 0 ? name : `${prev},${name}`;\n }, ''),\n setup: editorSettings => {\n getTextFormats().forEach((format, i) => {\n editorSettings.addShortcut(\n `meta+alt+${i}`,\n `${t('rte_change_text_format')} ${format.text}`,\n () => {\n editorSettings.execCommand('FormatBlock', false, format.type);\n }\n );\n });\n editorSettings.addShortcut('meta+shift+l', t('rte_toggle_unordered_list'), () => {\n editorSettings.execCommand('InsertUnorderedList');\n });\n editorSettings.addShortcut('alt+m', t('rte_indent_selection'), () => {\n editorSettings.execCommand('Indent');\n });\n editorSettings.addShortcut('alt+shift+m', t('rte_unindent_selection'), () => {\n editorSettings.execCommand('Outdent');\n });\n }\n })\n .then(tinymceEditors => {\n setEditor(tinymceEditors[0]);\n });\n }, []);\n\n useEffect(() => {\n if (!editor || initialized.current) return;\n initialized.current = true;\n onInit?.(editor);\n }, [editor, onInit]);\n\n useEffect(() => {\n if (!editor) return;\n const onEditorChange = () => {\n setShowPlaceholder(!editor?.getContent({ format: 'text' }));\n };\n const onEditorFocus = () => {\n onFocus?.();\n };\n const onEditorBlur = () => {\n onBlur?.();\n };\n editor.on('input', onEditorChange);\n editor.on('focus', onEditorFocus);\n editor.on('blur', onEditorBlur);\n return () => {\n editor.off('input', onEditorChange);\n editor.off('focus', onEditorFocus);\n editor.off('blur', onEditorBlur);\n };\n }, [editor, onFocus, onBlur]);\n\n useAfterInitialEffect(() => {\n editor?.mode.set(readOnly || disabled ? 'readonly' : 'design');\n }, [readOnly, disabled]);\n\n const addImage = (image: File) => {\n if (editor) {\n const imageId = createUID();\n editor.insertContent(`<img src='' id='${imageId}' style=\"max-width: 100%;\"/>`);\n onImageAdded?.(image, imageId);\n }\n };\n\n useEffect(() => {\n const onEditorDrop = (e: DragEvent) => {\n e.preventDefault();\n if (e.dataTransfer) {\n Array.from(e.dataTransfer.files).forEach(file => {\n if (file.type.includes('image')) {\n addImage(file);\n }\n });\n }\n };\n editor?.on('drop', onEditorDrop);\n return () => {\n editor?.off('drop', onEditorDrop);\n };\n }, [editor]);\n\n const renderToolbar = editor && toolbar.length > 0 && !readOnly && !disabled;\n\n return (\n <EditorContext.Provider value={{ addImage, editor: editor || ({} as TinymceEditor) }}>\n <FormField\n as={StyledRichTextFormField}\n toolbar={renderToolbar}\n label={\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events\n <span\n onClick={() => {\n editor?.focus();\n }}\n >\n {label}\n </span>\n }\n labelFor=''\n labelId={labelId}\n labelHidden={labelHidden}\n id={id}\n info={info}\n status={status}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n onFocus={(e: FocusEvent) => {\n if (e.target === formFieldRef.current && !disabled) {\n editor?.focus();\n }\n }}\n ref={formFieldRef}\n tabIndex={disabled ? -1 : undefined}\n >\n <FormControl\n {...restProps}\n ref={editorRef}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n status={status}\n as={StyledRichTextEditor}\n toolbar={renderToolbar}\n >\n <StyledEditorContainer\n readOnly={readOnly}\n onClick={() => {\n if (!disabled) {\n editor?.focus();\n }\n }}\n toolbar={renderToolbar}\n containerHeight={height}\n >\n <StyledHtml\n id={id}\n style={{ outline: 'none', border: 'none' }}\n dangerouslySetInnerHTML={{ __html: value.current || '' }}\n aria-label={`${label}${renderToolbar ? `. ${t('rte_toolbar_instructions')}.` : ''}`}\n as={StyledInnerEditor}\n showPlaceholder={showPlaceholder}\n aria-labelledby={labelId}\n role='textbox'\n />\n </StyledEditorContainer>\n {renderToolbar && (\n <Toolbar features={toolbar} editor={editor} customActions={customActions} />\n )}\n </FormControl>\n </FormField>\n </EditorContext.Provider>\n );\n }\n);\n\nexport default Editor;\n"]}
1
+ {"version":3,"file":"Editor.js","sourceRoot":"","s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AAC,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,qBAClE,OAAO,EACxB,GAAG,EAAE,UAAU,GACf,EACD,mBAAmB,CAAC,OAAO,IAAI,MAAM,IAAI,CACxC,KAAC,WAAW,IACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,mBAAmB,CAAC,OAAO,EACrC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,GAClC,CACH,IACqB,EACvB,aAAa,IAAI,CAChB,KAAC,OAAO,IAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAI,CAC7E,IACW,GACJ,EACX,QAAQ,IACc,CAC1B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import tinymce, { Editor as TinymceEditor, EditorEvent } from 'tinymce/tinymce';\nimport 'tinymce/icons/default';\nimport 'tinymce/themes/silver';\nimport 'tinymce/plugins/advlist';\nimport 'tinymce/plugins/lists';\nimport 'tinymce/plugins/paste';\nimport {\n FC,\n forwardRef,\n PropsWithoutRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n useImperativeHandle,\n FocusEvent\n} from 'react';\nimport styled, { css, DefaultTheme } from 'styled-components';\nimport { compile, serialize, stringify } from 'stylis';\nimport { stripUnit } from 'polished';\n\nimport {\n createUID,\n FormControl,\n FormField,\n ForwardProps,\n useAfterInitialEffect,\n useTheme,\n useUID,\n useI18n,\n useConsolidatedRef,\n defaultThemeProp,\n useAutoResize,\n useConfiguration\n} from '@pega/cosmos-react-core';\nimport { getHtmlStyles } from '@pega/cosmos-react-core/lib/components/HTML/HTML';\nimport {\n createGlobalBodyStyles,\n createGlobalRootStyles,\n globalSpacingStyles\n} from '@pega/cosmos-react-core/lib/styles/GlobalStyle';\n\nimport StyledRichTextEditor, {\n StyledRichTextFormField\n} from '../RichTextEditor/RichTextEditor.styles';\n\nimport Toolbar from './Toolbar/Toolbar';\nimport EditorContext from './Editor.context';\nimport { getTextFormats } from './Toolbar/TextSelect';\nimport { EditorProps, EditorState } from './Editor.types';\nimport ImageEditor, { imgHoverClass } from './ImageEditor';\nimport { offscreenSelectionStyles, StyledEditorContainer } from './Editor.styles';\n\nexport const getImageStyles = (theme: DefaultTheme) => {\n return `\n img:hover,\n img.${imgHoverClass} {\n box-shadow: 0 0 0 0.06125rem ${theme.base.palette['primary-background']},\n 0 0 0 0.125rem ${theme.base.palette.interactive}, 0 0 0 0.25rem rgba(0, 118, 209, 0.3);\n }\n `;\n};\n\nexport const StyledInnerEditor = styled.div<{ showPlaceholder: boolean }>(\n ({ theme, showPlaceholder }) => {\n return css`\n ${showPlaceholder &&\n css`\n ::before {\n color: ${theme.base.colors.slate.medium};\n position: absolute;\n content: attr(data-mce-placeholder);\n }\n `}\n `;\n }\n);\n\nStyledInnerEditor.defaultProps = defaultThemeProp;\n\nconst Editor: FC<EditorProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<EditorProps>, ref: EditorProps['ref']) => {\n const {\n components: {\n 'text-area': { 'min-height': textAreaMinHeight }\n }\n } = useTheme();\n const theme = useTheme();\n const { styleSheetTarget } = useConfiguration();\n const [editor, setEditor] = useState<TinymceEditor>();\n const [focused, setFocused] = useState(false);\n const t = useI18n();\n const uid = useUID();\n const labelId = useUID();\n const editorRef = useConsolidatedRef(ref);\n const tinyMceRef = useRef<HTMLTextAreaElement>(null);\n const tinyMceContainerRef = useRef<HTMLDivElement>(null);\n const initialized = useRef(false);\n\n const {\n id = uid,\n toolbar = [],\n label,\n labelHidden,\n info,\n status,\n required,\n disabled,\n readOnly,\n onChange,\n onKeyDown,\n onFocus,\n onBlur,\n onImageAdded,\n onInit,\n defaultValue,\n customComponents = [],\n height,\n customActions,\n placeholder,\n children,\n spellcheck = true,\n ...restProps\n } = props;\n const baseHeight: EditorProps['height'] = {\n min: height?.min ?? (stripUnit(textAreaMinHeight) as number) * 16,\n max: height?.max ?? undefined\n };\n const getHeight = (type: 'max' | 'min') => {\n if (typeof baseHeight === 'number') {\n return stripUnit(baseHeight) as number;\n }\n if (baseHeight[type]) {\n return stripUnit(baseHeight[type] as number) as number;\n }\n return undefined;\n };\n\n const imagesEnabled = toolbar.includes('images');\n const maxHeight = getHeight('max');\n const minHeight = getHeight('min');\n const [autoResizeRef, resizeEditor] = useAutoResize<HTMLIFrameElement>(maxHeight, minHeight);\n const formFieldRef = useRef<HTMLElement>(null);\n const value = useRef(defaultValue);\n const renderToolbar = editor && toolbar.length > 0 && !readOnly && !disabled;\n\n const pastePreprocess = (plugin: unknown, args: { content: string }) => {\n if (!imagesEnabled && args.content.includes('<img')) {\n args.content = '';\n }\n };\n\n useImperativeHandle<any, EditorState>(\n editorRef,\n () => ({\n focus: () => {\n editor?.focus();\n },\n getPlainText: () => {\n return editor ? editor.getContent({ format: 'text' }) : '';\n },\n getRichText: () => {\n return editor ? JSON.stringify(editor.getContent({ format: 'raw' })) : '';\n },\n getHtml: () => {\n return editor ? editor.getContent({ format: 'html' }) : '';\n },\n clear: () => {\n editor?.setContent('');\n },\n appendImage: ({ src, alt }, imageId) => {\n if (editor) {\n const editorEl = editor.getDoc();\n const imageEl = editorEl.querySelector(`#${imageId}`);\n if (imageEl) {\n imageEl.setAttribute('src', src);\n imageEl.setAttribute('alt', alt);\n resizeEditor();\n }\n }\n },\n insertText: (text: string) => {\n editor?.insertContent(text);\n },\n insertHtml: (html: string, overwrite: boolean = false) => {\n if (overwrite) {\n editor?.setContent('');\n }\n editor?.insertContent(html);\n },\n getEditor: () => {\n return editor;\n },\n element: formFieldRef.current || undefined\n }),\n [editor]\n );\n\n useLayoutEffect(() => {\n if (!tinyMceRef.current || !tinyMceContainerRef.current) return;\n const styles = serialize(compile(getHtmlStyles(theme)), stringify);\n const imageStyles = serialize(compile(getImageStyles(theme)), stringify);\n tinymce\n .init({\n readonly: readOnly || disabled,\n skin: false,\n target: tinyMceRef.current,\n toolbar: false,\n menubar: false,\n plugins: 'lists advlist paste',\n paste_data_images: true,\n lists_indent_on_tab: true,\n icons: '',\n branding: false,\n elementpath: false,\n placeholder,\n content_css: false,\n browser_spellcheck: spellcheck,\n paste_preprocess: pastePreprocess,\n content_style: `${createGlobalRootStyles(\n theme\n )} ${globalSpacingStyles} ${createGlobalBodyStyles(\n theme\n )} body { min-height: 3rem; padding: ${\n toolbar.length > 0 && !readOnly ? theme.base.spacing : 0\n }; } html { overflow: hidden; } ${offscreenSelectionStyles} ${imageStyles} ${styles}`,\n init_instance_callback: initializedEditor => {\n const iframeWindow = (\n tinyMceContainerRef.current?.querySelector('iframe') as HTMLIFrameElement\n ).contentWindow;\n const editorCustomElements = iframeWindow?.customElements;\n if (editorCustomElements) {\n customComponents.forEach(\n ({ name, createCustomElement: customElementCreator, style }) => {\n if (!editorCustomElements.get(name)) {\n editorCustomElements.define(\n name,\n customElementCreator(iframeWindow as unknown as typeof globalThis)\n );\n }\n if (style) {\n const styleEl = document.createElement('style');\n styleEl.innerText = style;\n initializedEditor.getDoc().head.appendChild(styleEl);\n }\n }\n );\n }\n },\n extended_valid_elements: `${customComponents\n .map(\n comp =>\n `${comp.name}${\n comp.extensionAttributes ? `[${comp.extensionAttributes.join('|')}]` : ''\n }`\n )\n .join(',')}`,\n custom_elements: `~${customComponents.map(comp => comp.name).join('~,')}`,\n setup: editorSettings => {\n editorSettings.on('keydown', e => {\n onKeyDown?.(e);\n });\n getTextFormats().forEach((format, i) => {\n editorSettings.addShortcut(\n `meta+alt+${i}`,\n `${t('rte_change_text_format')} ${format.text}`,\n () => {\n editorSettings.execCommand('FormatBlock', false, format.type);\n }\n );\n });\n editorSettings.addShortcut('meta+shift+l', t('rte_toggle_unordered_list'), () => {\n editorSettings.execCommand('InsertUnorderedList');\n });\n editorSettings.addShortcut('alt+m', t('rte_indent_selection'), () => {\n editorSettings.execCommand('Indent');\n });\n editorSettings.addShortcut('alt+shift+m', t('rte_unindent_selection'), () => {\n editorSettings.execCommand('Outdent');\n });\n customActions?.forEach(action => {\n if (action.shortcut) {\n editorSettings.addShortcut(\n action.shortcut.pattern,\n action.shortcut.description,\n () => {\n action.shortcut?.command(editorSettings);\n }\n );\n }\n });\n }\n })\n .then(tinymceEditors => {\n setEditor(tinymceEditors[0]);\n tinymceEditors[0].editorContainer?.setAttribute('style', '');\n const iframe = tinyMceContainerRef.current?.querySelector('iframe');\n if (iframe) {\n const globalStyles =\n styleSheetTarget?.querySelectorAll('[data-cosmos-global-style]') ??\n ([] as HTMLElement[]);\n const extraStyles =\n document.querySelectorAll('[data-cosmos-global-style]') ?? ([] as HTMLElement[]);\n const iframeContentHead = iframe?.contentDocument?.querySelector('head');\n [...globalStyles, ...extraStyles].forEach(sheet => {\n iframeContentHead?.appendChild(sheet.cloneNode(true));\n });\n autoResizeRef.current = iframe;\n resizeEditor();\n }\n });\n }, []);\n\n useEffect(() => {\n if (editor) {\n editor.settings.paste_preprocess = pastePreprocess;\n }\n }, [imagesEnabled]);\n\n useEffect(() => {\n if (!editor || initialized.current) return;\n initialized.current = true;\n onInit?.(editor);\n }, [editor, onInit]);\n\n useEffect(() => {\n if (!editor) return;\n const onChangeEvents = ['keyup', 'FormatApply', 'FormatRemove', 'ExecCommand'];\n const onEditorKeyDown = (event: EditorEvent<KeyboardEvent>) => {\n resizeEditor();\n if (event.key === 'Enter') {\n editor.selection.getNode().scrollIntoView(false);\n }\n };\n const onEditorChange = () => {\n onChange?.(editor);\n };\n const onEditorFocus = () => {\n setFocused(true);\n onFocus?.();\n };\n const onEditorBlur = () => {\n setFocused(false);\n onBlur?.();\n };\n onChangeEvents.forEach(event => {\n editor.on(event, onEditorChange);\n });\n editor.on('keydown', onEditorKeyDown);\n editor.on('paste', resizeEditor);\n editor.on('focus', onEditorFocus);\n editor.on('blur', onEditorBlur);\n return () => {\n onChangeEvents.forEach(event => {\n editor.off(event, onEditorChange);\n });\n editor.off('keydown', onEditorKeyDown);\n editor.off('paste', resizeEditor);\n editor.off('focus', onEditorFocus);\n editor.off('blur', onEditorBlur);\n };\n }, [editor, onFocus, onBlur]);\n\n useAfterInitialEffect(() => {\n editor?.mode.set(readOnly || disabled ? 'readonly' : 'design');\n }, [readOnly, disabled]);\n\n const addImage = (image: File) => {\n if (editor) {\n const imageId = createUID();\n editor.insertContent(`<img src='' id='${imageId}' style=\"max-width: 100%;\"/>`);\n onImageAdded?.(image, imageId);\n }\n };\n\n useEffect(() => {\n const onEditorDrop = (e: DragEvent) => {\n e.preventDefault();\n if (e.dataTransfer) {\n Array.from(e.dataTransfer.files).forEach(file => {\n if (file.type.includes('image') && imagesEnabled) {\n addImage(file);\n }\n });\n }\n };\n editor?.on('drop', onEditorDrop);\n const body = editor?.getDoc().body;\n const resizeObserver = new ResizeObserver(() => {\n resizeEditor();\n });\n if (body) {\n resizeObserver.observe(body);\n }\n return () => {\n editor?.off('drop', onEditorDrop);\n resizeObserver.disconnect();\n };\n }, [editor, resizeEditor]);\n\n return (\n <EditorContext.Provider value={{ addImage, editor: editor || ({} as TinymceEditor) }}>\n <FormField\n as={StyledRichTextFormField}\n toolbar={renderToolbar}\n label={\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events\n <span\n onClick={() => {\n editor?.focus();\n }}\n >\n {label}\n </span>\n }\n labelFor=''\n labelId={labelId}\n labelHidden={labelHidden}\n id={id}\n info={info}\n status={status}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n onFocus={(e: FocusEvent) => {\n if (e.target === formFieldRef.current && !disabled) {\n editor?.focus();\n }\n }}\n ref={formFieldRef}\n tabIndex={disabled ? -1 : undefined}\n >\n <FormControl\n {...restProps}\n ref={editorRef}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n status={status}\n as={StyledRichTextEditor}\n toolbar={renderToolbar}\n focused={focused}\n >\n <StyledEditorContainer\n onClick={() => {\n if (!disabled) {\n editor?.focus();\n }\n }}\n ref={tinyMceContainerRef}\n >\n <textarea\n id={id}\n value={value.current || ''}\n onChange={() => {}}\n aria-label={`${label}${renderToolbar ? `. ${t('rte_toolbar_instructions')}.` : ''}`}\n aria-labelledby={labelId}\n ref={tinyMceRef}\n />\n {tinyMceContainerRef.current && editor && (\n <ImageEditor\n editor={editor}\n editorEl={tinyMceContainerRef.current}\n onChange={() => onChange?.(editor)}\n />\n )}\n </StyledEditorContainer>\n {renderToolbar && (\n <Toolbar features={toolbar} editor={editor} customActions={customActions} />\n )}\n </FormControl>\n </FormField>\n {children}\n </EditorContext.Provider>\n );\n }\n);\n\nexport default Editor;\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const offscreenSelectionStyles = "\n .mce-offscreen-selection {\n border: 0;\n clip: rect(0 0 0 0);\n height: 1px;\n margin: -1px;\n overflow: hidden;\n padding: 0;\n position: absolute;\n whiteSpace: nowrap;\n width: 1px;\n }\n";
2
+ export declare const StyledEditorContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
3
+ //# sourceMappingURL=Editor.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Editor.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Editor/Editor.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB,oOAYpC,CAAC;AAEF,eAAO,MAAM,qBAAqB,yGAchC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import styled, { css } from 'styled-components';
2
+ export const offscreenSelectionStyles = `
3
+ .mce-offscreen-selection {
4
+ border: 0;
5
+ clip: rect(0 0 0 0);
6
+ height: 1px;
7
+ margin: -1px;
8
+ overflow: hidden;
9
+ padding: 0;
10
+ position: absolute;
11
+ whiteSpace: nowrap;
12
+ width: 1px;
13
+ }
14
+ `;
15
+ export const StyledEditorContainer = styled.div(() => {
16
+ return css `
17
+ &:hover {
18
+ cursor: text;
19
+ }
20
+
21
+ iframe {
22
+ width: 100%;
23
+ }
24
+
25
+ .tox-statusbar {
26
+ display: none !important;
27
+ }
28
+ `;
29
+ });
30
+ //# sourceMappingURL=Editor.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Editor.styles.js","sourceRoot":"","sources":["../../../src/components/Editor/Editor.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;CAYvC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE;IACnD,OAAO,GAAG,CAAA;;;;;;;;;;;;GAYT,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nexport const offscreenSelectionStyles = `\n .mce-offscreen-selection {\n border: 0;\n clip: rect(0 0 0 0);\n height: 1px;\n margin: -1px;\n overflow: hidden;\n padding: 0;\n position: absolute;\n whiteSpace: nowrap;\n width: 1px;\n }\n`;\n\nexport const StyledEditorContainer = styled.div(() => {\n return css`\n &:hover {\n cursor: text;\n }\n\n iframe {\n width: 100%;\n }\n\n .tox-statusbar {\n display: none !important;\n }\n `;\n});\n"]}
@@ -1,21 +1,38 @@
1
- import { Ref } from 'react';
1
+ import { ReactNode, Ref, MouseEvent as ReactMouseEvent, KeyboardEvent as ReactKeyboardEvent } from 'react';
2
2
  import { Editor as TinymceEditor } from 'tinymce/tinymce';
3
3
  import { Action, BaseProps, FormControlProps } from '@pega/cosmos-react-core';
4
4
  import { Features } from '../RichTextEditor/Toolbar/Toolbar.types';
5
5
  import { RichTextEditorState } from '../RichTextEditor';
6
6
  export declare type EditorState = RichTextEditorState & {
7
7
  getEditor: () => TinymceEditor | undefined;
8
+ element?: HTMLElement;
8
9
  };
9
10
  export declare type CustomAction = {
10
11
  text: Action['text'];
11
12
  icon: NonNullable<Action['icon']>;
12
- onMouseDown: () => void;
13
+ onMouseDown: (e: ReactMouseEvent | ReactKeyboardEvent) => void;
14
+ active?: (editor: TinymceEditor) => void;
15
+ shortcut?: {
16
+ pattern: string;
17
+ description: string;
18
+ command: (editor: TinymceEditor) => void;
19
+ };
20
+ };
21
+ export declare type CustomComponent = {
22
+ createCustomElement: (window: typeof globalThis) => CustomElementConstructor;
23
+ name: string;
24
+ extensionAttributes?: string[];
25
+ style?: string;
13
26
  };
14
27
  export interface EditorProps extends FormControlProps, BaseProps {
15
28
  /** An array of strings that activate features on the toolbar */
16
29
  toolbar?: Features[];
30
+ /** Children content */
31
+ children?: ReactNode;
17
32
  /** A callback that supplies an object with functions that can manipulate the editor and retrieve it's content/state */
18
- onChange?: () => void;
33
+ onChange?: (editor?: TinymceEditor) => void;
34
+ /** KeyDown event custom handlers for the editor */
35
+ onKeyDown?: (event?: KeyboardEvent) => void;
19
36
  /** A callback that runs if the editor is focused */
20
37
  onFocus?: () => void;
21
38
  /** A callback that runs if the editor loses focus */
@@ -31,17 +48,19 @@ export interface EditorProps extends FormControlProps, BaseProps {
31
48
  /** Will automatically focus the RTE on render if true */
32
49
  autoFocus?: boolean;
33
50
  /** Sets the height for the RTE. If no max height is set the RTE will continue to expand, otherwise an overflow will be applied */
34
- height?: string | {
35
- min?: string;
36
- max?: string;
51
+ height?: {
52
+ min?: number;
53
+ max?: number;
37
54
  };
38
55
  /** An array of custom components, custom components must use web component API */
39
- customComponents?: {
40
- customElement: CustomElementConstructor;
41
- name: string;
42
- }[];
56
+ customComponents?: CustomComponent[];
43
57
  /** An array of custom buttons to be inserted into the toolbar */
44
58
  customActions?: CustomAction[];
59
+ /**
60
+ * Enables browser spellcheck.
61
+ * @default true
62
+ */
63
+ spellcheck?: boolean;
45
64
  /** Handle to the state. */
46
65
  ref?: Ref<EditorState>;
47
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.types.d.ts","sourceRoot":"","sources":["../../../src/components/Editor/Editor.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,iBAAiB,CA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E,CAAC;IACrC,iEAAiE;IACjE,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2BAA2B;IAC3B,GAAG,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.types.js","sourceRoot":"","sources":["../../../src/components/Editor/Editor.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\nimport { Editor as TinymceEditor } from 'tinymce/tinymce';\n\nimport { Action, BaseProps, FormControlProps } from '@pega/cosmos-react-core';\n\nimport { Features } from '../RichTextEditor/Toolbar/Toolbar.types';\nimport { RichTextEditorState } from '../RichTextEditor';\n\nexport type EditorState = RichTextEditorState & { getEditor: () => TinymceEditor | undefined };\n\nexport type CustomAction = {\n text: Action['text'];\n icon: NonNullable<Action['icon']>;\n onMouseDown: () => void;\n};\n\nexport interface EditorProps extends FormControlProps, BaseProps {\n /** An array of strings that activate features on the toolbar */\n toolbar?: Features[];\n /** A callback that supplies an object with functions that can manipulate the editor and retrieve it's content/state */\n onChange?: () => void;\n /** A callback that runs if the editor is focused */\n onFocus?: () => void;\n /** A callback that runs if the editor loses focus */\n onBlur?: () => void;\n /** A callback when an image is added through the toolbar image feature */\n onImageAdded?: (image: File, id: string) => void;\n /** A callback for when tinymce is finished initializing */\n onInit?: (editor: TinymceEditor) => void;\n /** Standard placeholder for an input */\n placeholder?: string;\n /** Default value for the RTE - HTML String */\n defaultValue?: string;\n /** Will automatically focus the RTE on render if true */\n autoFocus?: boolean;\n /** Sets the height for the RTE. If no max height is set the RTE will continue to expand, otherwise an overflow will be applied */\n height?:\n | string\n | {\n min?: string;\n max?: string;\n };\n /** An array of custom components, custom components must use web component API */\n customComponents?: { customElement: CustomElementConstructor; name: string }[];\n /** An array of custom buttons to be inserted into the toolbar */\n customActions?: CustomAction[];\n /** Handle to the state. */\n ref?: Ref<EditorState>;\n}\n"]}
1
+ {"version":3,"file":"Editor.types.js","sourceRoot":"","sources":["../../../src/components/Editor/Editor.types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ReactNode,\n Ref,\n MouseEvent as ReactMouseEvent,\n KeyboardEvent as ReactKeyboardEvent\n} from 'react';\nimport { Editor as TinymceEditor } from 'tinymce/tinymce';\n\nimport { Action, BaseProps, FormControlProps } from '@pega/cosmos-react-core';\n\nimport { Features } from '../RichTextEditor/Toolbar/Toolbar.types';\nimport { RichTextEditorState } from '../RichTextEditor';\n\nexport type EditorState = RichTextEditorState & {\n getEditor: () => TinymceEditor | undefined;\n element?: HTMLElement;\n};\n\nexport type CustomAction = {\n text: Action['text'];\n icon: NonNullable<Action['icon']>;\n onMouseDown: (e: ReactMouseEvent | ReactKeyboardEvent) => void;\n active?: (editor: TinymceEditor) => void;\n shortcut?: { pattern: string; description: string; command: (editor: TinymceEditor) => void };\n};\n\nexport type CustomComponent = {\n createCustomElement: (window: typeof globalThis) => CustomElementConstructor;\n name: string;\n extensionAttributes?: string[];\n style?: string;\n};\n\nexport interface EditorProps extends FormControlProps, BaseProps {\n /** An array of strings that activate features on the toolbar */\n toolbar?: Features[];\n /** Children content */\n children?: ReactNode;\n /** A callback that supplies an object with functions that can manipulate the editor and retrieve it's content/state */\n onChange?: (editor?: TinymceEditor) => void;\n /** KeyDown event custom handlers for the editor */\n onKeyDown?: (event?: KeyboardEvent) => void;\n /** A callback that runs if the editor is focused */\n onFocus?: () => void;\n /** A callback that runs if the editor loses focus */\n onBlur?: () => void;\n /** A callback when an image is added through the toolbar image feature */\n onImageAdded?: (image: File, id: string) => void;\n /** A callback for when tinymce is finished initializing */\n onInit?: (editor: TinymceEditor) => void;\n /** Standard placeholder for an input */\n placeholder?: string;\n /** Default value for the RTE - HTML String */\n defaultValue?: string;\n /** Will automatically focus the RTE on render if true */\n autoFocus?: boolean;\n /** Sets the height for the RTE. If no max height is set the RTE will continue to expand, otherwise an overflow will be applied */\n height?: {\n min?: number;\n max?: number;\n };\n /** An array of custom components, custom components must use web component API */\n customComponents?: CustomComponent[];\n /** An array of custom buttons to be inserted into the toolbar */\n customActions?: CustomAction[];\n /**\n * Enables browser spellcheck.\n * @default true\n */\n spellcheck?: boolean;\n /** Handle to the state. */\n ref?: Ref<EditorState>;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { FC } from 'react';
2
+ import { Editor } from 'tinymce';
3
+ export declare const imgHoverClass: string;
4
+ declare const ImageEditor: FC<{
5
+ editorEl: HTMLElement;
6
+ editor: Editor;
7
+ onChange: () => void;
8
+ }>;
9
+ export default ImageEditor;
10
+ //# sourceMappingURL=ImageEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Editor/ImageEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAQH,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AA4BjC,eAAO,MAAM,aAAa,QAAc,CAAC;AAEzC,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,IAAI,CAAA;CAAE,CAiYpF,CAAC;AAEF,eAAe,WAAW,CAAC"}