grep-components 2.1.0-GREPF-1810.1 → 2.1.0-GREPF-1810.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -53,3 +53,15 @@ export declare const WithLabel: {
|
|
|
53
53
|
name: string;
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
+
export declare const OnlyHeading: {
|
|
57
|
+
(): React.JSX.Element;
|
|
58
|
+
story: {
|
|
59
|
+
name: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export declare const ReadOnly: {
|
|
63
|
+
(): React.JSX.Element;
|
|
64
|
+
story: {
|
|
65
|
+
name: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
|
56
56
|
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
57
57
|
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
58
58
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
59
|
-
import require$$3, { BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, FOCUS_COMMAND, TextNode, ParagraphNode, PASTE_COMMAND, $createTextNode, $insertNodes, RootNode, LineBreakNode, $getSelection, $isRangeSelection, $isTextNode, $isParagraphNode, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND } from 'lexical';
|
|
59
|
+
import require$$3, { BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, FOCUS_COMMAND, TextNode, ParagraphNode, PASTE_COMMAND, $createTextNode, $insertNodes, RootNode, LineBreakNode, $getSelection, $isRangeSelection, $isTextNode, $isParagraphNode, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, $createParagraphNode } from 'lexical';
|
|
60
60
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
61
61
|
import FormatBold from '@mui/icons-material/FormatBold';
|
|
62
62
|
import FormatItalic from '@mui/icons-material/FormatItalic';
|
|
@@ -16109,12 +16109,12 @@ function FloatingTextFormatToolbarPlugin({ anchorElem, buttons, CustomToolbar, }
|
|
|
16109
16109
|
function InsertDataPlugin({ html }) {
|
|
16110
16110
|
const [editor] = useLexicalComposerContext();
|
|
16111
16111
|
const parser = new DOMParser();
|
|
16112
|
-
if (!html) {
|
|
16113
|
-
return null;
|
|
16114
|
-
}
|
|
16115
|
-
const dom = parser.parseFromString(html, 'text/html');
|
|
16116
16112
|
// Initial data insertion
|
|
16117
16113
|
useEffect(() => {
|
|
16114
|
+
if (!html) {
|
|
16115
|
+
return;
|
|
16116
|
+
}
|
|
16117
|
+
const dom = parser.parseFromString(html, 'text/html');
|
|
16118
16118
|
editor.update(() => {
|
|
16119
16119
|
const nodes = LexicalHtml_1.$generateNodesFromDOM(editor, dom);
|
|
16120
16120
|
$insertNodes(nodes);
|
|
@@ -16123,6 +16123,35 @@ function InsertDataPlugin({ html }) {
|
|
|
16123
16123
|
return null;
|
|
16124
16124
|
}
|
|
16125
16125
|
|
|
16126
|
+
const getTagType = (html) => {
|
|
16127
|
+
if (!html) {
|
|
16128
|
+
return null;
|
|
16129
|
+
}
|
|
16130
|
+
const tag = html.match(/^<h[0-6]>/); // Matches h tag at start of line
|
|
16131
|
+
const tagType = tag && tag[0].replace('<', '').replace('>', '');
|
|
16132
|
+
return tagType;
|
|
16133
|
+
};
|
|
16134
|
+
/* Changes behavior of editor, based on the input html: (Only heading, No heading) */
|
|
16135
|
+
function HeadingPlugin({ html }) {
|
|
16136
|
+
const [editor] = useLexicalComposerContext();
|
|
16137
|
+
const tag = getTagType(html);
|
|
16138
|
+
useEffect(() => {
|
|
16139
|
+
// Only replace if tag is heading.
|
|
16140
|
+
if (tag) {
|
|
16141
|
+
editor.registerNodeTransform(ParagraphNode, (node) => {
|
|
16142
|
+
node.replace(LexicalRichText_1.$createHeadingNode(`${tag}`));
|
|
16143
|
+
});
|
|
16144
|
+
}
|
|
16145
|
+
else {
|
|
16146
|
+
// Replace a heading with paragraph
|
|
16147
|
+
editor.registerNodeTransform(LexicalRichText_1.HeadingNode, (node) => {
|
|
16148
|
+
node.replace($createParagraphNode(), true);
|
|
16149
|
+
});
|
|
16150
|
+
}
|
|
16151
|
+
}, [editor, html]);
|
|
16152
|
+
return null;
|
|
16153
|
+
}
|
|
16154
|
+
|
|
16126
16155
|
// Classes here are added to the relevant tags i.e.(<strong>)
|
|
16127
16156
|
const theme = {
|
|
16128
16157
|
text: {
|
|
@@ -16141,6 +16170,7 @@ function Editor({ html, label, classes, autoFocus, helperText, showCharCount, al
|
|
|
16141
16170
|
const initialConfig = {
|
|
16142
16171
|
namespace: 'GrepEditor',
|
|
16143
16172
|
theme,
|
|
16173
|
+
editable: !readOnly,
|
|
16144
16174
|
onError,
|
|
16145
16175
|
nodes: [LexicalRichText_1.HeadingNode],
|
|
16146
16176
|
html: {
|
|
@@ -16164,6 +16194,7 @@ function Editor({ html, label, classes, autoFocus, helperText, showCharCount, al
|
|
|
16164
16194
|
React__default.createElement(HistoryPlugin, null),
|
|
16165
16195
|
React__default.createElement(OnChangePlugin, { onChange: onContentChange }),
|
|
16166
16196
|
React__default.createElement(InsertDataPlugin, { html: html }),
|
|
16197
|
+
React__default.createElement(HeadingPlugin, { html: html }),
|
|
16167
16198
|
React__default.createElement(ModifyPastePlugin, { blockPasting: blockPasting, stripPastedStyles: stripPastedStyles }),
|
|
16168
16199
|
React__default.createElement(PreventNewlinesPlugin, { disableNewlines: disableNewlines }))));
|
|
16169
16200
|
}
|