@pega/cosmos-react-rte 9.0.0-build.9.9 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +4 -2
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js +64 -59
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -1
- package/lib/components/Editor/Editor.context.d.ts +6 -6
- package/lib/components/Editor/Editor.context.d.ts.map +1 -1
- package/lib/components/Editor/Editor.context.js +1 -1
- package/lib/components/Editor/Editor.context.js.map +1 -1
- package/lib/components/Editor/Editor.d.ts +1 -10
- package/lib/components/Editor/Editor.d.ts.map +1 -1
- package/lib/components/Editor/Editor.js +301 -490
- package/lib/components/Editor/Editor.js.map +1 -1
- package/lib/components/Editor/Editor.styles.d.ts +37 -7
- package/lib/components/Editor/Editor.styles.d.ts.map +1 -1
- package/lib/components/Editor/Editor.styles.js +60 -30
- package/lib/components/Editor/Editor.styles.js.map +1 -1
- package/lib/components/Editor/Editor.test-ids.d.ts +2 -1
- package/lib/components/Editor/Editor.test-ids.d.ts.map +1 -1
- package/lib/components/Editor/Editor.test-ids.js +2 -0
- package/lib/components/Editor/Editor.test-ids.js.map +1 -1
- package/lib/components/Editor/Editor.types.d.ts +34 -14
- package/lib/components/Editor/Editor.types.d.ts.map +1 -1
- package/lib/components/Editor/Editor.types.js.map +1 -1
- package/lib/components/Editor/IframeTiptapEditor.d.ts +30 -0
- package/lib/components/Editor/IframeTiptapEditor.d.ts.map +1 -0
- package/lib/components/Editor/IframeTiptapEditor.js +695 -0
- package/lib/components/Editor/IframeTiptapEditor.js.map +1 -0
- package/lib/components/Editor/ImageActionButtons.d.ts +20 -0
- package/lib/components/Editor/ImageActionButtons.d.ts.map +1 -0
- package/lib/components/Editor/ImageActionButtons.js +84 -0
- package/lib/components/Editor/ImageActionButtons.js.map +1 -0
- package/lib/components/Editor/ImageEditDialog.d.ts +17 -0
- package/lib/components/Editor/ImageEditDialog.d.ts.map +1 -0
- package/lib/components/Editor/ImageEditDialog.js +90 -0
- package/lib/components/Editor/ImageEditDialog.js.map +1 -0
- package/lib/components/Editor/TableCellMenu.d.ts +35 -0
- package/lib/components/Editor/TableCellMenu.d.ts.map +1 -0
- package/lib/components/Editor/TableCellMenu.js +120 -0
- package/lib/components/Editor/TableCellMenu.js.map +1 -0
- package/lib/components/Editor/Toolbar/AIRewriteButton.d.ts +17 -0
- package/lib/components/Editor/Toolbar/AIRewriteButton.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/AIRewriteButton.js +79 -0
- package/lib/components/Editor/Toolbar/AIRewriteButton.js.map +1 -0
- package/lib/components/Editor/Toolbar/AlignmentSelect.d.ts +8 -0
- package/lib/components/Editor/Toolbar/AlignmentSelect.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/AlignmentSelect.js +137 -0
- package/lib/components/Editor/Toolbar/AlignmentSelect.js.map +1 -0
- package/lib/components/Editor/Toolbar/AnchorButton.d.ts +3 -4
- package/lib/components/Editor/Toolbar/AnchorButton.d.ts.map +1 -1
- package/lib/components/Editor/Toolbar/AnchorButton.js +156 -82
- package/lib/components/Editor/Toolbar/AnchorButton.js.map +1 -1
- package/lib/components/Editor/Toolbar/ColorPickerButton.d.ts +9 -0
- package/lib/components/Editor/Toolbar/ColorPickerButton.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/ColorPickerButton.js +190 -0
- package/lib/components/Editor/Toolbar/ColorPickerButton.js.map +1 -0
- package/lib/components/Editor/Toolbar/FontFamilySelect.d.ts +8 -0
- package/lib/components/Editor/Toolbar/FontFamilySelect.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/FontFamilySelect.js +150 -0
- package/lib/components/Editor/Toolbar/FontFamilySelect.js.map +1 -0
- package/lib/components/Editor/Toolbar/FontSizeSelect.d.ts +8 -0
- package/lib/components/Editor/Toolbar/FontSizeSelect.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/FontSizeSelect.js +145 -0
- package/lib/components/Editor/Toolbar/FontSizeSelect.js.map +1 -0
- package/lib/components/Editor/Toolbar/ImageButton.d.ts +5 -5
- package/lib/components/Editor/Toolbar/ImageButton.d.ts.map +1 -1
- package/lib/components/Editor/Toolbar/ImageButton.js +131 -18
- package/lib/components/Editor/Toolbar/ImageButton.js.map +1 -1
- package/lib/components/Editor/Toolbar/SourceCodeButton.d.ts +8 -0
- package/lib/components/Editor/Toolbar/SourceCodeButton.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/SourceCodeButton.js +49 -0
- package/lib/components/Editor/Toolbar/SourceCodeButton.js.map +1 -0
- package/lib/components/Editor/Toolbar/TableButton.d.ts +8 -0
- package/lib/components/Editor/Toolbar/TableButton.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/TableButton.js +291 -0
- package/lib/components/Editor/Toolbar/TableButton.js.map +1 -0
- package/lib/components/Editor/Toolbar/TextSelect.d.ts +4 -5
- package/lib/components/Editor/Toolbar/TextSelect.d.ts.map +1 -1
- package/lib/components/Editor/Toolbar/TextSelect.js +61 -30
- package/lib/components/Editor/Toolbar/TextSelect.js.map +1 -1
- package/lib/components/Editor/Toolbar/Toolbar.d.ts +17 -6
- package/lib/components/Editor/Toolbar/Toolbar.d.ts.map +1 -1
- package/lib/components/Editor/Toolbar/Toolbar.js +169 -47
- package/lib/components/Editor/Toolbar/Toolbar.js.map +1 -1
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts +2 -2
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.d.ts.map +1 -1
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.js +17 -1
- package/lib/components/Editor/Toolbar/Toolbar.test-ids.js.map +1 -1
- package/lib/components/Editor/Toolbar/WordCount.d.ts +8 -0
- package/lib/components/Editor/Toolbar/WordCount.d.ts.map +1 -0
- package/lib/components/Editor/Toolbar/WordCount.js +31 -0
- package/lib/components/Editor/Toolbar/WordCount.js.map +1 -0
- package/lib/components/Editor/extensions/FontSize.d.ts +21 -0
- package/lib/components/Editor/extensions/FontSize.d.ts.map +1 -0
- package/lib/components/Editor/extensions/FontSize.js +42 -0
- package/lib/components/Editor/extensions/FontSize.js.map +1 -0
- package/lib/components/Editor/extensions/PreserveDiv.d.ts +13 -0
- package/lib/components/Editor/extensions/PreserveDiv.d.ts.map +1 -0
- package/lib/components/Editor/extensions/PreserveDiv.js +73 -0
- package/lib/components/Editor/extensions/PreserveDiv.js.map +1 -0
- package/lib/components/Editor/extensions/TableCellSelection.d.ts +4 -0
- package/lib/components/Editor/extensions/TableCellSelection.d.ts.map +1 -0
- package/lib/components/Editor/extensions/TableCellSelection.js +53 -0
- package/lib/components/Editor/extensions/TableCellSelection.js.map +1 -0
- package/lib/components/Editor/extensions/TextIndent.d.ts +22 -0
- package/lib/components/Editor/extensions/TextIndent.d.ts.map +1 -0
- package/lib/components/Editor/extensions/TextIndent.js +137 -0
- package/lib/components/Editor/extensions/TextIndent.js.map +1 -0
- package/lib/components/Editor/hooks/useCloseOnEditorClick.d.ts +5 -0
- package/lib/components/Editor/hooks/useCloseOnEditorClick.d.ts.map +1 -0
- package/lib/components/Editor/hooks/useCloseOnEditorClick.js +18 -0
- package/lib/components/Editor/hooks/useCloseOnEditorClick.js.map +1 -0
- package/lib/components/Editor/hooks/useEscapeKey.d.ts +4 -0
- package/lib/components/Editor/hooks/useEscapeKey.d.ts.map +1 -0
- package/lib/components/Editor/hooks/useEscapeKey.js +24 -0
- package/lib/components/Editor/hooks/useEscapeKey.js.map +1 -0
- package/lib/components/Editor/hooks/useIframeSetup.d.ts +54 -0
- package/lib/components/Editor/hooks/useIframeSetup.d.ts.map +1 -0
- package/lib/components/Editor/hooks/useIframeSetup.js +284 -0
- package/lib/components/Editor/hooks/useIframeSetup.js.map +1 -0
- package/lib/components/Editor/hooks/useImageActions.d.ts +19 -0
- package/lib/components/Editor/hooks/useImageActions.d.ts.map +1 -0
- package/lib/components/Editor/hooks/useImageActions.js +198 -0
- package/lib/components/Editor/hooks/useImageActions.js.map +1 -0
- package/lib/components/Editor/hooks/useTableCellMenu.d.ts +22 -0
- package/lib/components/Editor/hooks/useTableCellMenu.d.ts.map +1 -0
- package/lib/components/Editor/hooks/useTableCellMenu.js +120 -0
- package/lib/components/Editor/hooks/useTableCellMenu.js.map +1 -0
- package/lib/components/Editor/iframeContentStyles.d.ts +10 -0
- package/lib/components/Editor/iframeContentStyles.d.ts.map +1 -0
- package/lib/components/Editor/iframeContentStyles.js +162 -0
- package/lib/components/Editor/iframeContentStyles.js.map +1 -0
- package/lib/components/Editor/index.d.ts +2 -0
- package/lib/components/Editor/index.d.ts.map +1 -1
- package/lib/components/Editor/index.js +1 -0
- package/lib/components/Editor/index.js.map +1 -1
- package/lib/components/Editor/sanitize.d.ts +3 -0
- package/lib/components/Editor/sanitize.d.ts.map +1 -0
- package/lib/components/Editor/sanitize.js +11 -0
- package/lib/components/Editor/sanitize.js.map +1 -0
- package/lib/components/Editor/utils/htmlPlaceholder.d.ts +69 -0
- package/lib/components/Editor/utils/htmlPlaceholder.d.ts.map +1 -0
- package/lib/components/Editor/utils/htmlPlaceholder.js +154 -0
- package/lib/components/Editor/utils/htmlPlaceholder.js.map +1 -0
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts +6 -4
- package/lib/components/RichTextEditor/DecoratorComponents/Table.d.ts.map +1 -1
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js +10 -8
- package/lib/components/RichTextEditor/DecoratorComponents/Table.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.js +15 -2
- package/lib/components/RichTextEditor/RichTextEditor.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts +5 -5
- package/lib/components/RichTextEditor/RichTextEditor.styles.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.styles.js +3 -5
- package/lib/components/RichTextEditor/RichTextEditor.styles.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts +5 -0
- package/lib/components/RichTextEditor/RichTextEditor.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextEditor.types.js.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.d.ts.map +1 -1
- package/lib/components/RichTextEditor/RichTextViewer.js +9 -2
- package/lib/components/RichTextEditor/RichTextViewer.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts +4 -4
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/Toolbar.types.js.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.d.ts.map +1 -1
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js +41 -26
- package/lib/components/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.d.ts +2 -0
- package/lib/components/RichTextEditor/utils/htmlConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/htmlConverter.js +12 -0
- package/lib/components/RichTextEditor/utils/htmlConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/interactionRenderer.js +20 -19
- package/lib/components/RichTextEditor/utils/interactionRenderer.js.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/markdownConverter.js +131 -30
- package/lib/components/RichTextEditor/utils/markdownConverter.js.map +1 -1
- package/lib/components/RichTextEditor/utils/renderers.d.ts +5 -3
- package/lib/components/RichTextEditor/utils/renderers.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/renderers.js +62 -34
- package/lib/components/RichTextEditor/utils/renderers.js.map +1 -1
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts +4 -3
- package/lib/components/RichTextEditor/utils/slateConverter.d.ts.map +1 -1
- package/lib/components/RichTextEditor/utils/slateConverter.js +86 -38
- package/lib/components/RichTextEditor/utils/slateConverter.js.map +1 -1
- package/package.json +30 -8
- package/lib/components/Editor/ImageEditor.d.ts +0 -10
- package/lib/components/Editor/ImageEditor.d.ts.map +0 -1
- package/lib/components/Editor/ImageEditor.js +0 -292
- package/lib/components/Editor/ImageEditor.js.map +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useCallback } from 'react';
|
|
3
|
+
import styled, { css } from 'styled-components';
|
|
4
|
+
import { Popover, Icon, registerIcon, useOuterEvent, Menu, Button, defaultThemeProp, useI18n, Tooltip, calculateFontSize, isInstance } from '@pega/cosmos-react-core';
|
|
5
|
+
import * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';
|
|
6
|
+
import useEscapeKey from '../hooks/useEscapeKey';
|
|
7
|
+
import useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';
|
|
8
|
+
registerIcon(arrowMicroDownIcon);
|
|
9
|
+
const StyledFontSizeSelect = styled(Button)(({ theme }) => {
|
|
10
|
+
const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);
|
|
11
|
+
return css `
|
|
12
|
+
color: ${theme.base.palette['foreground-color']};
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
height: calc(3.5 * ${theme.base.spacing});
|
|
16
|
+
padding: 0 calc(0.5 * ${theme.base.spacing});
|
|
17
|
+
font-size: ${fontSizes.xxs};
|
|
18
|
+
min-width: 6ch;
|
|
19
|
+
|
|
20
|
+
span {
|
|
21
|
+
white-space: nowrap;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
});
|
|
25
|
+
StyledFontSizeSelect.defaultProps = defaultThemeProp;
|
|
26
|
+
const StyledSelectMenu = styled.div(({ theme }) => {
|
|
27
|
+
return css `
|
|
28
|
+
min-width: 8ch;
|
|
29
|
+
max-height: calc(30 * ${theme.base.spacing});
|
|
30
|
+
`;
|
|
31
|
+
});
|
|
32
|
+
StyledSelectMenu.defaultProps = defaultThemeProp;
|
|
33
|
+
const FONT_SIZES = [
|
|
34
|
+
{ id: '8', label: '8px', value: '8px' },
|
|
35
|
+
{ id: '9', label: '9px', value: '9px' },
|
|
36
|
+
{ id: '10', label: '10px', value: '10px' },
|
|
37
|
+
{ id: '11', label: '11px', value: '11px' },
|
|
38
|
+
{ id: '12', label: '12px', value: '12px' },
|
|
39
|
+
{ id: '14', label: '14px', value: '14px' },
|
|
40
|
+
{ id: '16', label: '16px', value: '16px' },
|
|
41
|
+
{ id: '18', label: '18px', value: '18px' },
|
|
42
|
+
{ id: '20', label: '20px', value: '20px' },
|
|
43
|
+
{ id: '24', label: '24px', value: '24px' },
|
|
44
|
+
{ id: '28', label: '28px', value: '28px' },
|
|
45
|
+
{ id: '32', label: '32px', value: '32px' },
|
|
46
|
+
{ id: '36', label: '36px', value: '36px' },
|
|
47
|
+
{ id: '48', label: '48px', value: '48px' },
|
|
48
|
+
{ id: '72', label: '72px', value: '72px' }
|
|
49
|
+
];
|
|
50
|
+
const FontSizeSelect = ({ editor, ...restProps }) => {
|
|
51
|
+
const t = useI18n();
|
|
52
|
+
const [open, setOpen] = useState(false);
|
|
53
|
+
const selecting = useRef(false);
|
|
54
|
+
const openedByClick = useRef(false);
|
|
55
|
+
const buttonRef = useRef(null);
|
|
56
|
+
const popoverRef = useRef(null);
|
|
57
|
+
const menuRef = useRef(null);
|
|
58
|
+
useOuterEvent('mousedown', [buttonRef, popoverRef, menuRef], () => {
|
|
59
|
+
if (open) {
|
|
60
|
+
setOpen(false);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const handleEscapeClose = useCallback(() => {
|
|
64
|
+
setOpen(false);
|
|
65
|
+
buttonRef.current?.focus();
|
|
66
|
+
}, []);
|
|
67
|
+
useEscapeKey(open, handleEscapeClose, editor);
|
|
68
|
+
useCloseOnEditorClick(open, handleEscapeClose);
|
|
69
|
+
const onSizeSelect = (sizeId, e) => {
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
const size = FONT_SIZES.find(s => s.id === sizeId);
|
|
73
|
+
if (size) {
|
|
74
|
+
editor.chain().focus().setFontSize(size.value).run();
|
|
75
|
+
}
|
|
76
|
+
if (!openedByClick.current) {
|
|
77
|
+
buttonRef.current?.focus();
|
|
78
|
+
}
|
|
79
|
+
setOpen(false);
|
|
80
|
+
selecting.current = true;
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
selecting.current = false;
|
|
83
|
+
if (!editor.isFocused && openedByClick.current) {
|
|
84
|
+
editor.commands.focus();
|
|
85
|
+
}
|
|
86
|
+
}, 0);
|
|
87
|
+
};
|
|
88
|
+
const getActiveSize = () => {
|
|
89
|
+
const attrs = editor.getAttributes('textStyle');
|
|
90
|
+
const { fontSize } = attrs;
|
|
91
|
+
if (typeof fontSize !== 'string' || !fontSize)
|
|
92
|
+
return '12px';
|
|
93
|
+
const match = FONT_SIZES.find(s => s.value === fontSize);
|
|
94
|
+
return match ? match.label : '12px';
|
|
95
|
+
};
|
|
96
|
+
const getActiveSizeId = () => {
|
|
97
|
+
const attrs = editor.getAttributes('textStyle');
|
|
98
|
+
const { fontSize } = attrs;
|
|
99
|
+
if (typeof fontSize !== 'string' || !fontSize)
|
|
100
|
+
return '12';
|
|
101
|
+
const match = FONT_SIZES.find(s => s.value === fontSize);
|
|
102
|
+
return match ? match.id : '12';
|
|
103
|
+
};
|
|
104
|
+
return (_jsxs(_Fragment, { children: [_jsxs(StyledFontSizeSelect, { ...restProps, variant: 'simple', type: 'button', icon: false, ref: buttonRef, "data-toolbar-item": 'true', onMouseDown: (e) => {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
if (!open) {
|
|
107
|
+
openedByClick.current = true;
|
|
108
|
+
}
|
|
109
|
+
setOpen(!open);
|
|
110
|
+
}, onKeyDown: (e) => {
|
|
111
|
+
if (e.key === 'Enter' && !selecting.current) {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
setOpen(true);
|
|
114
|
+
openedByClick.current = false;
|
|
115
|
+
}
|
|
116
|
+
else if (e.key === 'Enter') {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
selecting.current = false;
|
|
119
|
+
}
|
|
120
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
121
|
+
setOpen(false);
|
|
122
|
+
}
|
|
123
|
+
else if (e.key === 'Escape' && open) {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
setOpen(false);
|
|
126
|
+
}
|
|
127
|
+
}, onFocus: (e) => {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
e.stopPropagation();
|
|
130
|
+
}, onBlur: (e) => {
|
|
131
|
+
const { relatedTarget } = e;
|
|
132
|
+
if (isInstance(relatedTarget, Node) &&
|
|
133
|
+
!buttonRef.current?.contains(relatedTarget) &&
|
|
134
|
+
!popoverRef.current?.contains(relatedTarget) &&
|
|
135
|
+
!menuRef.current?.contains(relatedTarget)) {
|
|
136
|
+
setOpen(false);
|
|
137
|
+
}
|
|
138
|
+
}, onClick: (e) => e.stopPropagation(), "aria-expanded": open, "aria-label": `${t('rte_font_size')}. ${getActiveSize()} ${t('selected').toLocaleLowerCase()}`, "aria-haspopup": true, children: [_jsx("span", { children: getActiveSize() }), _jsx(Icon, { name: 'arrow-micro-down' })] }), buttonRef.current && (_jsx(Tooltip, { target: buttonRef.current, showDelay: 'none', hideDelay: 'none', children: t('rte_font_size') })), _jsx(Popover, { show: open, as: StyledSelectMenu, target: buttonRef.current, placement: 'bottom-start', ref: popoverRef, children: _jsx(Menu, { items: FONT_SIZES.map(({ id, label }) => ({
|
|
139
|
+
id,
|
|
140
|
+
primary: label,
|
|
141
|
+
selected: id === getActiveSizeId()
|
|
142
|
+
})), focusControlEl: buttonRef.current ?? undefined, mode: 'single-select', ref: menuRef, onItemClick: onSizeSelect }) })] }));
|
|
143
|
+
};
|
|
144
|
+
export default FontSizeSelect;
|
|
145
|
+
//# sourceMappingURL=FontSizeSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FontSizeSelect.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/FontSizeSelect.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGtD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,UAAU,EACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,kBAAkB,MAAM,yEAAyE,CAAC;AAE9G,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,qBAAqB,MAAM,gCAAgC,CAAC;AAEnE,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAEjC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACxD,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACvF,OAAO,GAAG,CAAA;aACC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;;;yBAG1B,KAAK,CAAC,IAAI,CAAC,OAAO;4BACf,KAAK,CAAC,IAAI,CAAC,OAAO;iBAC7B,SAAS,CAAC,GAAG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AC,CAAC,iBAAiB,EAAE,EAAE,oCAG5F,yBAAO,aAAa,EAAE,GAAQ,EAC9B,KAAC,IAAI,IAAC,IAAI,EAAC,kBAAkB,GAAG,IACX,EACtB,SAAS,CAAC,OAAO,IAAI,CACpB,KAAC,OAAO,IAAC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAC,MAAM,EAAC,SAAS,EAAC,MAAM,YAClE,CAAC,CAAC,eAAe,CAAC,GACX,CACX,EACD,KAAC,OAAO,IACN,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,gBAAgB,EACpB,MAAM,EAAE,SAAS,CAAC,OAAO,EACzB,SAAS,EAAC,cAAc,EACxB,GAAG,EAAE,UAAU,YAEf,KAAC,IAAI,IACH,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;wBACxC,EAAE;wBACF,OAAO,EAAE,KAAK;wBACd,QAAQ,EAAE,EAAE,KAAK,eAAe,EAAE;qBACnC,CAAC,CAAC,EACH,cAAc,EAAE,SAAS,CAAC,OAAO,IAAI,SAAS,EAC9C,IAAI,EAAC,eAAe,EACpB,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,YAAY,GACzB,GACM,IACT,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { useRef, useState, useCallback } from 'react';\nimport type { MouseEvent, KeyboardEvent, FocusEvent } from 'react';\nimport type { Editor as TiptapEditor } from '@tiptap/core';\nimport styled, { css } from 'styled-components';\n\nimport {\n Popover,\n Icon,\n registerIcon,\n useOuterEvent,\n Menu,\n Button,\n defaultThemeProp,\n useI18n,\n Tooltip,\n calculateFontSize,\n isInstance\n} from '@pega/cosmos-react-core';\nimport * as arrowMicroDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-micro-down.icon';\n\nimport useEscapeKey from '../hooks/useEscapeKey';\nimport useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';\n\nregisterIcon(arrowMicroDownIcon);\n\nconst StyledFontSizeSelect = styled(Button)(({ theme }) => {\n const fontSizes = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n return css`\n color: ${theme.base.palette['foreground-color']};\n display: inline-flex;\n align-items: center;\n height: calc(3.5 * ${theme.base.spacing});\n padding: 0 calc(0.5 * ${theme.base.spacing});\n font-size: ${fontSizes.xxs};\n min-width: 6ch;\n\n span {\n white-space: nowrap;\n }\n `;\n});\n\nStyledFontSizeSelect.defaultProps = defaultThemeProp;\n\nconst StyledSelectMenu = styled.div(({ theme }) => {\n return css`\n min-width: 8ch;\n max-height: calc(30 * ${theme.base.spacing});\n `;\n});\n\nStyledSelectMenu.defaultProps = defaultThemeProp;\n\nconst FONT_SIZES = [\n { id: '8', label: '8px', value: '8px' },\n { id: '9', label: '9px', value: '9px' },\n { id: '10', label: '10px', value: '10px' },\n { id: '11', label: '11px', value: '11px' },\n { id: '12', label: '12px', value: '12px' },\n { id: '14', label: '14px', value: '14px' },\n { id: '16', label: '16px', value: '16px' },\n { id: '18', label: '18px', value: '18px' },\n { id: '20', label: '20px', value: '20px' },\n { id: '24', label: '24px', value: '24px' },\n { id: '28', label: '28px', value: '28px' },\n { id: '32', label: '32px', value: '32px' },\n { id: '36', label: '36px', value: '36px' },\n { id: '48', label: '48px', value: '48px' },\n { id: '72', label: '72px', value: '72px' }\n];\n\ninterface FontSizeSelectProps {\n editor: TiptapEditor;\n 'data-testid'?: string;\n}\n\nconst FontSizeSelect = ({ editor, ...restProps }: FontSizeSelectProps) => {\n const t = useI18n();\n const [open, setOpen] = useState(false);\n const selecting = useRef(false);\n const openedByClick = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n\n useOuterEvent('mousedown', [buttonRef, popoverRef, menuRef], () => {\n if (open) {\n setOpen(false);\n }\n });\n\n const handleEscapeClose = useCallback(() => {\n setOpen(false);\n buttonRef.current?.focus();\n }, []);\n\n useEscapeKey(open, handleEscapeClose, editor);\n useCloseOnEditorClick(open, handleEscapeClose);\n\n const onSizeSelect = (sizeId: string, e: MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n\n const size = FONT_SIZES.find(s => s.id === sizeId);\n if (size) {\n editor.chain().focus().setFontSize(size.value).run();\n }\n\n if (!openedByClick.current) {\n buttonRef.current?.focus();\n }\n setOpen(false);\n selecting.current = true;\n setTimeout(() => {\n selecting.current = false;\n if (!editor.isFocused && openedByClick.current) {\n editor.commands.focus();\n }\n }, 0);\n };\n\n const getActiveSize = (): string => {\n const attrs = editor.getAttributes('textStyle');\n const { fontSize } = attrs;\n if (typeof fontSize !== 'string' || !fontSize) return '12px';\n const match = FONT_SIZES.find(s => s.value === fontSize);\n return match ? match.label : '12px';\n };\n\n const getActiveSizeId = (): string => {\n const attrs = editor.getAttributes('textStyle');\n const { fontSize } = attrs;\n if (typeof fontSize !== 'string' || !fontSize) return '12';\n const match = FONT_SIZES.find(s => s.value === fontSize);\n return match ? match.id : '12';\n };\n\n return (\n <>\n <StyledFontSizeSelect\n {...restProps}\n variant='simple'\n type='button'\n icon={false}\n ref={buttonRef}\n data-toolbar-item='true'\n onMouseDown={(e: MouseEvent) => {\n e.preventDefault();\n if (!open) {\n openedByClick.current = true;\n }\n setOpen(!open);\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Enter' && !selecting.current) {\n e.preventDefault();\n setOpen(true);\n openedByClick.current = false;\n } else if (e.key === 'Enter') {\n e.preventDefault();\n selecting.current = false;\n } else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {\n setOpen(false);\n } else if (e.key === 'Escape' && open) {\n e.preventDefault();\n setOpen(false);\n }\n }}\n onFocus={(e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onBlur={(e: FocusEvent) => {\n const { relatedTarget } = e;\n if (\n isInstance(relatedTarget, Node) &&\n !buttonRef.current?.contains(relatedTarget) &&\n !popoverRef.current?.contains(relatedTarget) &&\n !menuRef.current?.contains(relatedTarget)\n ) {\n setOpen(false);\n }\n }}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n aria-expanded={open}\n aria-label={`${t('rte_font_size')}. ${getActiveSize()} ${t('selected').toLocaleLowerCase()}`}\n aria-haspopup\n >\n <span>{getActiveSize()}</span>\n <Icon name='arrow-micro-down' />\n </StyledFontSizeSelect>\n {buttonRef.current && (\n <Tooltip target={buttonRef.current} showDelay='none' hideDelay='none'>\n {t('rte_font_size')}\n </Tooltip>\n )}\n <Popover\n show={open}\n as={StyledSelectMenu}\n target={buttonRef.current}\n placement='bottom-start'\n ref={popoverRef}\n >\n <Menu\n items={FONT_SIZES.map(({ id, label }) => ({\n id,\n primary: label,\n selected: id === getActiveSizeId()\n }))}\n focusControlEl={buttonRef.current ?? undefined}\n mode='single-select'\n ref={menuRef}\n onItemClick={onSizeSelect}\n />\n </Popover>\n </>\n );\n};\n\nexport default FontSizeSelect;\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Editor } from 'tinymce';
|
|
1
|
+
import type { Editor as TiptapEditor } from '@tiptap/core';
|
|
3
2
|
import type { ForwardProps } from '@pega/cosmos-react-core';
|
|
4
|
-
declare const ImageButton:
|
|
5
|
-
editor:
|
|
6
|
-
|
|
3
|
+
declare const ImageButton: ({ editor, imageInsertionMode, ...restProps }: {
|
|
4
|
+
editor: TiptapEditor;
|
|
5
|
+
imageInsertionMode: "file" | "url" | "all";
|
|
6
|
+
} & ForwardProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export default ImageButton;
|
|
8
8
|
//# sourceMappingURL=ImageButton.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageButton.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/ImageButton.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImageButton.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/ImageButton.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAa3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAU5D,QAAA,MAAM,WAAW,GAAI,8CAIlB;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAAA;CAAE,GAAG,YAAY,4CAuOrF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,30 +1,143 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { useRef, useContext } from 'react';
|
|
3
|
-
import
|
|
4
|
-
import { hideVisually } from 'polished';
|
|
5
|
-
import { Icon, registerIcon, useI18n } from '@pega/cosmos-react-core';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useContext, useEffect, useCallback } from 'react';
|
|
3
|
+
import { createUID, FileInput, Grid, Icon, Input, RadioButton, RadioButtonGroup, registerIcon, useI18n } from '@pega/cosmos-react-core';
|
|
6
4
|
import * as pictureIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/picture.icon';
|
|
7
5
|
import ToolbarButton from '../../RichTextEditor/Toolbar/ToolbarButton';
|
|
8
6
|
import EditorContext from '../Editor.context';
|
|
7
|
+
import { StyledFormDialog } from '../Editor.styles';
|
|
8
|
+
import useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';
|
|
9
9
|
registerIcon(pictureIcon);
|
|
10
|
-
const
|
|
11
|
-
${hideVisually()}
|
|
12
|
-
`;
|
|
13
|
-
const ImageButton = ({ editor, ...restProps }) => {
|
|
10
|
+
const ImageButton = ({ editor, imageInsertionMode, ...restProps }) => {
|
|
14
11
|
const t = useI18n();
|
|
15
|
-
const fileInputRef = useRef(null);
|
|
16
12
|
const { addImage } = useContext(EditorContext);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const [showImageDialog, setShowImageDialog] = useState(false);
|
|
14
|
+
const imagebuttonRef = useRef(null);
|
|
15
|
+
const imagepopoverRef = useRef(null);
|
|
16
|
+
const [imageTitle, setImageTitle] = useState('');
|
|
17
|
+
const [imageLinkTitle, setImageLinkTitle] = useState('');
|
|
18
|
+
const [selectedAttachmentType, setSelectedAttachmentType] = useState(() => {
|
|
19
|
+
if (imageInsertionMode === 'url') {
|
|
20
|
+
return 'link';
|
|
21
|
+
}
|
|
22
|
+
return 'file';
|
|
23
|
+
});
|
|
24
|
+
const [url, setUrl] = useState('');
|
|
25
|
+
const [tempfile, setTempFile] = useState();
|
|
26
|
+
const [incorrectUrl, setIncorrectUrl] = useState(false);
|
|
27
|
+
const [fileEmpty, setFileEmpty] = useState(false);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (imageInsertionMode === 'url') {
|
|
30
|
+
setSelectedAttachmentType('link');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
setSelectedAttachmentType('file');
|
|
34
|
+
}
|
|
35
|
+
}, [imageInsertionMode]);
|
|
36
|
+
const onImageInputChange = (addedFiles) => {
|
|
37
|
+
setTempFile(addedFiles[0]);
|
|
38
|
+
setFileEmpty(false);
|
|
39
|
+
};
|
|
40
|
+
const resetMenu = () => {
|
|
41
|
+
setUrl('');
|
|
42
|
+
setIncorrectUrl(false);
|
|
43
|
+
setImageLinkTitle('');
|
|
44
|
+
setImageTitle('');
|
|
45
|
+
setTempFile(undefined);
|
|
46
|
+
setSelectedAttachmentType('file');
|
|
47
|
+
setFileEmpty(false);
|
|
48
|
+
setShowImageDialog(false);
|
|
49
|
+
};
|
|
50
|
+
// Close dialog when clicking inside the editor iframe
|
|
51
|
+
const handleEditorClick = useCallback(() => {
|
|
52
|
+
if (showImageDialog) {
|
|
53
|
+
resetMenu();
|
|
54
|
+
}
|
|
55
|
+
}, [showImageDialog]);
|
|
56
|
+
useCloseOnEditorClick(showImageDialog, handleEditorClick);
|
|
57
|
+
const onImageAddSubmit = () => {
|
|
58
|
+
if (selectedAttachmentType === 'file') {
|
|
59
|
+
if (tempfile) {
|
|
60
|
+
addImage(tempfile, undefined, imageTitle);
|
|
61
|
+
resetMenu();
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
setFileEmpty(true);
|
|
22
65
|
}
|
|
23
66
|
}
|
|
67
|
+
else if (selectedAttachmentType === 'link') {
|
|
68
|
+
if (!url || incorrectUrl) {
|
|
69
|
+
setIncorrectUrl(true);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const imageUid = createUID();
|
|
73
|
+
// Tiptap API - insert image using the Image extension command
|
|
74
|
+
editor
|
|
75
|
+
.chain()
|
|
76
|
+
.focus()
|
|
77
|
+
.setImage({
|
|
78
|
+
src: url,
|
|
79
|
+
alt: imageLinkTitle || t('rte_broken_image')
|
|
80
|
+
})
|
|
81
|
+
.updateAttributes('image', { 'data-id': imageUid })
|
|
82
|
+
.run();
|
|
83
|
+
// Add error handler for broken images if no alt text was provided
|
|
84
|
+
if (!imageLinkTitle) {
|
|
85
|
+
// Use the editor's document to target the correct iframe
|
|
86
|
+
const editorDoc = editor.view.dom.ownerDocument;
|
|
87
|
+
requestAnimationFrame(() => {
|
|
88
|
+
const imageEl = editorDoc.querySelector(`img[data-id="${imageUid}"]`);
|
|
89
|
+
if (imageEl) {
|
|
90
|
+
imageEl.onerror = () => {
|
|
91
|
+
imageEl.alt = t('rte_broken_image');
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
resetMenu();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const onImageAddCancel = () => {
|
|
100
|
+
resetMenu();
|
|
24
101
|
};
|
|
25
|
-
return (_jsxs(_Fragment, { children: [_jsx(
|
|
26
|
-
|
|
27
|
-
},
|
|
102
|
+
return (_jsxs(_Fragment, { children: [_jsx(ToolbarButton, { ref: imagebuttonRef, onClick: () => {
|
|
103
|
+
setShowImageDialog(true);
|
|
104
|
+
}, onKeyDown: (e) => {
|
|
105
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
setShowImageDialog(true);
|
|
108
|
+
}
|
|
109
|
+
}, tooltip: t('rte_image'), label: t('rte_image'), ...restProps, children: _jsx(Icon, { name: 'picture' }) }), showImageDialog && imagebuttonRef.current && (_jsx("form", { children: _jsx(StyledFormDialog, { heading: t('rte_add_image'), onSubmit: onImageAddSubmit, onCancel: onImageAddCancel, onDismiss: () => {
|
|
110
|
+
resetMenu();
|
|
111
|
+
}, target: imagebuttonRef.current, ref: imagepopoverRef, children: _jsxs(Grid, { container: {
|
|
112
|
+
gap: 2
|
|
113
|
+
}, children: [imageInsertionMode === 'all' && (_jsx(Grid, { container: { rowGap: 2 }, children: _jsxs(RadioButtonGroup, { name: 'chooseListView', label: t('rte_image_source'), onChange: e => {
|
|
114
|
+
setSelectedAttachmentType(e.target.value);
|
|
115
|
+
}, "data-testid": 'chooseListView', inline: true, required: true, children: [_jsx(RadioButton, { id: 'file', label: t('rte_image_file'), value: 'file', checked: selectedAttachmentType === 'file' }), _jsx(RadioButton, { id: 'link', label: t('rte_image_link'), value: 'link', checked: selectedAttachmentType === 'link' })] }) })), selectedAttachmentType === 'file' && (_jsxs(Grid, { container: { rowGap: 2 }, children: [_jsx(FileInput, { multiple: false, label: t('rte_image_file'), onFilesAdded: onImageInputChange, required: true, accept: 'image/*', info: fileEmpty ? t('rte_empty_image') : '', status: fileEmpty ? 'error' : undefined, files: tempfile
|
|
116
|
+
? [
|
|
117
|
+
{
|
|
118
|
+
name: tempfile.name,
|
|
119
|
+
id: createUID(),
|
|
120
|
+
thumbnail: URL.createObjectURL(tempfile),
|
|
121
|
+
onDelete: () => {
|
|
122
|
+
setTempFile(undefined);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
: [] }), _jsx(Input, { label: t('description'), value: imageTitle, onChange: e => {
|
|
127
|
+
setImageTitle(e.target.value);
|
|
128
|
+
}, info: t('rte_image_description_info') })] })), selectedAttachmentType === 'link' && (_jsxs(Grid, { container: { rowGap: 2 }, children: [_jsx(Input, { label: t('rte_image_url'), value: url, required: true, info: incorrectUrl ? t('rte_invalid_url') : '', status: incorrectUrl ? 'error' : undefined, onChange: e => {
|
|
129
|
+
const urlInput = e.target.value;
|
|
130
|
+
setUrl(urlInput);
|
|
131
|
+
try {
|
|
132
|
+
const newUrl = new URL(urlInput);
|
|
133
|
+
setIncorrectUrl(!['http:', 'https:'].includes(newUrl.protocol));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
setIncorrectUrl(true);
|
|
137
|
+
}
|
|
138
|
+
} }), _jsx(Input, { label: t('description'), value: imageLinkTitle, onChange: e => {
|
|
139
|
+
setImageLinkTitle(e.target.value);
|
|
140
|
+
}, info: t('rte_image_description_info') })] }))] }) }) }))] }));
|
|
28
141
|
};
|
|
29
142
|
export default ImageButton;
|
|
30
143
|
//# sourceMappingURL=ImageButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageButton.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/ImageButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,KAAK,WAAW,MAAM,gEAAgE,CAAC;AAE9F,OAAO,aAAa,MAAM,4CAA4C,CAAC;AACvE,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAE9C,YAA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from 'styled-components';\nimport type { Editor } from 'tinymce';\nimport { hideVisually } from 'polished';\n\nimport { Icon, registerIcon, useI18n } from '@pega/cosmos-react-core';\nimport type { ForwardProps } from '@pega/cosmos-react-core';\nimport * as pictureIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/picture.icon';\n\nimport ToolbarButton from '../../RichTextEditor/Toolbar/ToolbarButton';\nimport EditorContext from '../Editor.context';\n\nregisterIcon(pictureIcon);\n\nconst StyledImageInput = styled.input`\n ${hideVisually()}\n`;\n\nconst ImageButton: FC<{ editor: Editor } & ForwardProps> = ({ editor, ...restProps }) => {\n const t = useI18n();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const { addImage } = useContext(EditorContext);\n\n const onImageInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) {\n addImage(e.target.files[0]);\n\n if (fileInputRef.current) {\n fileInputRef.current.value = '';\n }\n }\n };\n\n return (\n <>\n <StyledImageInput\n type='file'\n accept='image/*'\n ref={fileInputRef}\n onChange={onImageInputChange}\n tabIndex={-1}\n aria-hidden\n />\n <ToolbarButton\n onClick={() => {\n fileInputRef?.current?.click();\n }}\n tooltip={t('rte_image')}\n label={t('rte_image')}\n {...restProps}\n >\n <Icon name='picture' />\n </ToolbarButton>\n </>\n );\n};\n\nexport default ImageButton;\n"]}
|
|
1
|
+
{"version":3,"file":"ImageButton.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/ImageButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAI7E,OAAO,EACL,SAAS,EACT,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,WAAW,MAAM,gEAAgE,CAAC;AAE9F,OAAO,aAAa,MAAM,4CAA4C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EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,aAC5B,KAAC,KAAK,IACJ,KAAK,EAAE,CAAC,CAAC,eAAe,CAAC,EACzB,KAAK,EAAE,GAAG,EACV,QAAQ,QACR,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,EAC9C,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAC1C,QAAQ,EAAE,CAAC,CAAC,EAAE;4CACZ,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;4CAChC,MAAM,CAAC,QAAQ,CAAC,CAAC;4CACjB,IAAI,CAAC;gDACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;gDACjC,eAAe,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;4CAClE,CAAC;4CAAC,MAAM,CAAC;gDACP,eAAe,CAAC,IAAI,CAAC,CAAC;4CACxB,CAAC;wCACH,CAAC,GACD,EACF,KAAC,KAAK,IACJ,KAAK,EAAE,CAAC,CAAC,aAAa,CAAC,EACvB,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,CAAC,CAAC,EAAE;4CACZ,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;wCACpC,CAAC,EACD,IAAI,EAAE,CAAC,CAAC,4BAA4B,CAAC,GACrC,IACG,CACR,IACI,GACU,GACd,CACR,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { useState, useRef, useContext, useEffect, useCallback } from 'react';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { Editor as TiptapEditor } from '@tiptap/core';\n\nimport {\n createUID,\n FileInput,\n Grid,\n Icon,\n Input,\n RadioButton,\n RadioButtonGroup,\n registerIcon,\n useI18n\n} from '@pega/cosmos-react-core';\nimport type { ForwardProps } from '@pega/cosmos-react-core';\nimport * as pictureIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/picture.icon';\n\nimport ToolbarButton from '../../RichTextEditor/Toolbar/ToolbarButton';\nimport EditorContext from '../Editor.context';\nimport { StyledFormDialog } from '../Editor.styles';\nimport useCloseOnEditorClick from '../hooks/useCloseOnEditorClick';\n\nregisterIcon(pictureIcon);\n\nconst ImageButton = ({\n editor,\n imageInsertionMode,\n ...restProps\n}: { editor: TiptapEditor; imageInsertionMode: 'file' | 'url' | 'all' } & ForwardProps) => {\n const t = useI18n();\n const { addImage } = useContext(EditorContext);\n const [showImageDialog, setShowImageDialog] = useState(false);\n const imagebuttonRef = useRef<HTMLElement>(null);\n const imagepopoverRef = useRef(null);\n const [imageTitle, setImageTitle] = useState('');\n const [imageLinkTitle, setImageLinkTitle] = useState('');\n const [selectedAttachmentType, setSelectedAttachmentType] = useState(() => {\n if (imageInsertionMode === 'url') {\n return 'link';\n }\n return 'file';\n });\n const [url, setUrl] = useState('');\n const [tempfile, setTempFile] = useState<File>();\n const [incorrectUrl, setIncorrectUrl] = useState(false);\n const [fileEmpty, setFileEmpty] = useState(false);\n\n useEffect(() => {\n if (imageInsertionMode === 'url') {\n setSelectedAttachmentType('link');\n } else {\n setSelectedAttachmentType('file');\n }\n }, [imageInsertionMode]);\n\n const onImageInputChange = (addedFiles: File[]) => {\n setTempFile(addedFiles[0]);\n setFileEmpty(false);\n };\n\n const resetMenu = () => {\n setUrl('');\n setIncorrectUrl(false);\n setImageLinkTitle('');\n setImageTitle('');\n setTempFile(undefined);\n setSelectedAttachmentType('file');\n setFileEmpty(false);\n setShowImageDialog(false);\n };\n\n // Close dialog when clicking inside the editor iframe\n const handleEditorClick = useCallback(() => {\n if (showImageDialog) {\n resetMenu();\n }\n }, [showImageDialog]);\n useCloseOnEditorClick(showImageDialog, handleEditorClick);\n\n const onImageAddSubmit = () => {\n if (selectedAttachmentType === 'file') {\n if (tempfile) {\n addImage(tempfile, undefined, imageTitle);\n resetMenu();\n } else {\n setFileEmpty(true);\n }\n } else if (selectedAttachmentType === 'link') {\n if (!url || incorrectUrl) {\n setIncorrectUrl(true);\n return;\n }\n\n const imageUid = createUID();\n // Tiptap API - insert image using the Image extension command\n editor\n .chain()\n .focus()\n .setImage({\n src: url,\n alt: imageLinkTitle || t('rte_broken_image')\n })\n .updateAttributes('image', { 'data-id': imageUid })\n .run();\n\n // Add error handler for broken images if no alt text was provided\n if (!imageLinkTitle) {\n // Use the editor's document to target the correct iframe\n const editorDoc = editor.view.dom.ownerDocument;\n requestAnimationFrame(() => {\n const imageEl = editorDoc.querySelector<HTMLImageElement>(`img[data-id=\"${imageUid}\"]`);\n if (imageEl) {\n imageEl.onerror = () => {\n imageEl.alt = t('rte_broken_image');\n };\n }\n });\n }\n resetMenu();\n }\n };\n\n const onImageAddCancel = () => {\n resetMenu();\n };\n\n return (\n <>\n <ToolbarButton\n ref={imagebuttonRef}\n onClick={() => {\n setShowImageDialog(true);\n }}\n onKeyDown={(e: ReactKeyboardEvent) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n setShowImageDialog(true);\n }\n }}\n tooltip={t('rte_image')}\n label={t('rte_image')}\n {...restProps}\n >\n <Icon name='picture' />\n </ToolbarButton>\n {showImageDialog && imagebuttonRef.current && (\n <form>\n <StyledFormDialog\n heading={t('rte_add_image')}\n onSubmit={onImageAddSubmit}\n onCancel={onImageAddCancel}\n onDismiss={() => {\n resetMenu();\n }}\n target={imagebuttonRef.current}\n ref={imagepopoverRef}\n >\n <Grid\n container={{\n gap: 2\n }}\n >\n {imageInsertionMode === 'all' && (\n <Grid container={{ rowGap: 2 }}>\n <RadioButtonGroup\n name='chooseListView'\n label={t('rte_image_source')}\n onChange={e => {\n setSelectedAttachmentType(e.target.value);\n }}\n data-testid='chooseListView'\n inline\n required\n >\n <RadioButton\n id='file'\n label={t('rte_image_file')}\n value='file'\n checked={selectedAttachmentType === 'file'}\n />\n <RadioButton\n id='link'\n label={t('rte_image_link')}\n value='link'\n checked={selectedAttachmentType === 'link'}\n />\n </RadioButtonGroup>\n </Grid>\n )}\n {selectedAttachmentType === 'file' && (\n <Grid container={{ rowGap: 2 }}>\n <FileInput\n multiple={false}\n label={t('rte_image_file')}\n onFilesAdded={onImageInputChange}\n required\n accept='image/*'\n info={fileEmpty ? t('rte_empty_image') : ''}\n status={fileEmpty ? 'error' : undefined}\n files={\n tempfile\n ? [\n {\n name: tempfile.name,\n id: createUID(),\n thumbnail: URL.createObjectURL(tempfile),\n onDelete: () => {\n setTempFile(undefined);\n }\n }\n ]\n : []\n }\n />\n <Input\n label={t('description')}\n value={imageTitle}\n onChange={e => {\n setImageTitle(e.target.value);\n }}\n info={t('rte_image_description_info')}\n />\n </Grid>\n )}\n {selectedAttachmentType === 'link' && (\n <Grid container={{ rowGap: 2 }}>\n <Input\n label={t('rte_image_url')}\n value={url}\n required\n info={incorrectUrl ? t('rte_invalid_url') : ''}\n status={incorrectUrl ? 'error' : undefined}\n onChange={e => {\n const urlInput = e.target.value;\n setUrl(urlInput);\n try {\n const newUrl = new URL(urlInput);\n setIncorrectUrl(!['http:', 'https:'].includes(newUrl.protocol));\n } catch {\n setIncorrectUrl(true);\n }\n }}\n />\n <Input\n label={t('description')}\n value={imageLinkTitle}\n onChange={e => {\n setImageLinkTitle(e.target.value);\n }}\n info={t('rte_image_description_info')}\n />\n </Grid>\n )}\n </Grid>\n </StyledFormDialog>\n </form>\n )}\n </>\n );\n};\n\nexport default ImageButton;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface SourceCodeButtonProps {
|
|
2
|
+
active?: boolean;
|
|
3
|
+
onToggle?: (isSourceMode: boolean) => void;
|
|
4
|
+
'data-testid'?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const SourceCodeButton: ({ active, onToggle, ...restProps }: SourceCodeButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default SourceCodeButton;
|
|
8
|
+
//# sourceMappingURL=SourceCodeButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceCodeButton.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/SourceCodeButton.tsx"],"names":[],"mappings":"AA0CA,UAAU,qBAAqB;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,gBAAgB,GAAI,oCAAoC,qBAAqB,4CA8ClF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import styled, { css } from 'styled-components';
|
|
4
|
+
import { mix } from 'polished';
|
|
5
|
+
import { Icon, registerIcon, Button, defaultThemeProp, useI18n, Tooltip, tryCatch } from '@pega/cosmos-react-core';
|
|
6
|
+
import * as codeIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/code.icon';
|
|
7
|
+
registerIcon(codeIcon);
|
|
8
|
+
const StyledSourceCodeButton = styled(Button)(({ theme, $active }) => {
|
|
9
|
+
const activeColor = tryCatch(() => mix(0.85, theme.base.palette['primary-background'], theme.base.palette.interactive));
|
|
10
|
+
return css `
|
|
11
|
+
color: ${theme.base.palette['foreground-color']};
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
height: calc(3.5 * ${theme.base.spacing});
|
|
16
|
+
min-width: calc(3.5 * ${theme.base.spacing});
|
|
17
|
+
padding: 0;
|
|
18
|
+
|
|
19
|
+
${$active &&
|
|
20
|
+
css `
|
|
21
|
+
background-color: ${activeColor};
|
|
22
|
+
color: ${theme.base.palette.interactive};
|
|
23
|
+
border-bottom: calc(0.25 * ${theme.base.spacing}) solid ${theme.base.palette.interactive};
|
|
24
|
+
`}
|
|
25
|
+
`;
|
|
26
|
+
});
|
|
27
|
+
StyledSourceCodeButton.defaultProps = defaultThemeProp;
|
|
28
|
+
const SourceCodeButton = ({ active, onToggle, ...restProps }) => {
|
|
29
|
+
const t = useI18n();
|
|
30
|
+
const buttonRef = useRef(null);
|
|
31
|
+
const handleToggle = () => {
|
|
32
|
+
onToggle?.(!active);
|
|
33
|
+
};
|
|
34
|
+
return (_jsxs(_Fragment, { children: [_jsx(StyledSourceCodeButton, { ...restProps, variant: 'simple', type: 'button', icon: false, ref: buttonRef, "data-toolbar-item": 'true', "$active": active, onMouseDown: (e) => {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
handleToggle();
|
|
38
|
+
}, onKeyDown: (e) => {
|
|
39
|
+
if (e.key === 'Enter') {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
handleToggle();
|
|
42
|
+
}
|
|
43
|
+
}, onFocus: (e) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
}, onClick: (e) => e.stopPropagation(), "aria-label": t('rte_source_code'), "aria-pressed": active, children: _jsx(Icon, { name: 'code' }) }), buttonRef.current && (_jsx(Tooltip, { target: buttonRef.current, showDelay: 'none', hideDelay: 'none', children: t('rte_source_code') }))] }));
|
|
47
|
+
};
|
|
48
|
+
export default SourceCodeButton;
|
|
49
|
+
//# sourceMappingURL=SourceCodeButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceCodeButton.js","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/SourceCodeButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAA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QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,CACL,8BACE,KAAC,sBAAsB,OACjB,SAAS,EACb,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAC,QAAQ,EACb,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,SAAS,uBACI,MAAM,aACf,MAAM,EACf,WAAW,EAAE,CAAC,CAAa,EAAE,EAAE;oBAC7B,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,CAAC,CAAC,eAAe,EAAE,CAAC;oBACpB,YAAY,EAAE,CAAC;gBACjB,CAAC,EACD,SAAS,EAAE,CAAC,CAAgB,EAAE,EAAE;oBAC9B,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;wBACtB,CAAC,CAAC,cAAc,EAAE,CAAC;wBACnB,YAAY,EAAE,CAAC;oBACjB,CAAC;gBACH,CAAC,EACD,OAAO,EAAE,CAAC,CAAa,EAAE,EAAE;oBACzB,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,CAAC,CAAC,eAAe,EAAE,CAAC;gBACtB,CAAC,EACD,OAAO,EAAE,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,gBACnC,CAAC,CAAC,iBAAiB,CAAC,kBAClB,MAAM,YAEpB,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,GACG,EACxB,SAAS,CAAC,OAAO,IAAI,CACpB,KAAC,OAAO,IAAC,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAC,MAAM,EAAC,SAAS,EAAC,MAAM,YAClE,CAAC,CAAC,iBAAiB,CAAC,GACb,CACX,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import { useRef } from 'react';\nimport type { MouseEvent, KeyboardEvent, FocusEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { mix } from 'polished';\n\nimport {\n Icon,\n registerIcon,\n Button,\n defaultThemeProp,\n useI18n,\n Tooltip,\n tryCatch\n} from '@pega/cosmos-react-core';\nimport * as codeIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/code.icon';\n\nregisterIcon(codeIcon);\n\nconst StyledSourceCodeButton = styled(Button)<{ $active?: boolean }>(({ theme, $active }) => {\n const activeColor = tryCatch(() =>\n mix(0.85, theme.base.palette['primary-background'], theme.base.palette.interactive)\n );\n return css`\n color: ${theme.base.palette['foreground-color']};\n display: inline-flex;\n align-items: center;\n justify-content: center;\n height: calc(3.5 * ${theme.base.spacing});\n min-width: calc(3.5 * ${theme.base.spacing});\n padding: 0;\n\n ${$active &&\n css`\n background-color: ${activeColor};\n color: ${theme.base.palette.interactive};\n border-bottom: calc(0.25 * ${theme.base.spacing}) solid ${theme.base.palette.interactive};\n `}\n `;\n});\n\nStyledSourceCodeButton.defaultProps = defaultThemeProp;\n\ninterface SourceCodeButtonProps {\n active?: boolean;\n onToggle?: (isSourceMode: boolean) => void;\n 'data-testid'?: string;\n}\n\nconst SourceCodeButton = ({ active, onToggle, ...restProps }: SourceCodeButtonProps) => {\n const t = useI18n();\n const buttonRef = useRef<HTMLButtonElement>(null);\n\n const handleToggle = () => {\n onToggle?.(!active);\n };\n\n return (\n <>\n <StyledSourceCodeButton\n {...restProps}\n variant='simple'\n type='button'\n icon={false}\n ref={buttonRef}\n data-toolbar-item='true'\n $active={active}\n onMouseDown={(e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n handleToggle();\n }}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n handleToggle();\n }\n }}\n onFocus={(e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onClick={(e: MouseEvent) => e.stopPropagation()}\n aria-label={t('rte_source_code')}\n aria-pressed={active}\n >\n <Icon name='code' />\n </StyledSourceCodeButton>\n {buttonRef.current && (\n <Tooltip target={buttonRef.current} showDelay='none' hideDelay='none'>\n {t('rte_source_code')}\n </Tooltip>\n )}\n </>\n );\n};\n\nexport default SourceCodeButton;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Editor as TiptapEditor } from '@tiptap/core';
|
|
2
|
+
interface TableButtonProps {
|
|
3
|
+
editor: TiptapEditor;
|
|
4
|
+
'data-testid'?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const TableButton: ({ editor, ...restProps }: TableButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default TableButton;
|
|
8
|
+
//# sourceMappingURL=TableButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableButton.d.ts","sourceRoot":"","sources":["../../../../src/components/Editor/Toolbar/TableButton.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAsH3D,UAAU,gBAAgB;IACxB,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,WAAW,GAAI,0BAA0B,gBAAgB,4CAuT9D,CAAC;AAEF,eAAe,WAAW,CAAC"}
|