@webiny/lexical-editor 5.35.2 → 5.36.0-beta.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/components/Editor/HeadingEditor.js +1 -1
- package/components/Editor/HeadingEditor.js.map +1 -1
- package/components/Editor/RichTextEditor.js +1 -1
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +0 -2
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +30 -3
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/hooks/useQuote.d.ts +2 -0
- package/hooks/{useWebinyQuote.js → useQuote.js} +2 -2
- package/hooks/useQuote.js.map +1 -0
- package/nodes/HeadingNode.d.ts +34 -0
- package/nodes/HeadingNode.js +192 -0
- package/nodes/HeadingNode.js.map +1 -0
- package/nodes/ParagraphNode.d.ts +32 -0
- package/nodes/ParagraphNode.js +218 -0
- package/nodes/ParagraphNode.js.map +1 -0
- package/nodes/QuoteNode.d.ts +34 -0
- package/nodes/QuoteNode.js +225 -0
- package/nodes/QuoteNode.js.map +1 -0
- package/nodes/TypographyElementNode.js +2 -1
- package/nodes/TypographyElementNode.js.map +1 -1
- package/nodes/list-node/WebinyListItemNode.js +2 -1
- package/nodes/list-node/WebinyListItemNode.js.map +1 -1
- package/nodes/list-node/formatList.js +3 -2
- package/nodes/list-node/formatList.js.map +1 -1
- package/nodes/types.d.ts +15 -0
- package/nodes/types.js +5 -0
- package/nodes/types.js.map +1 -0
- package/nodes/webinyNodes.js +29 -5
- package/nodes/webinyNodes.js.map +1 -1
- package/package.json +17 -17
- package/plugins/FontColorPlugin/FontColorPlugin.js +2 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +9 -5
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts +1 -1
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +7 -7
- package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -1
- package/themes/webinyLexicalTheme.css +18 -9
- package/types.d.ts +2 -3
- package/types.js.map +1 -1
- package/ui/DropDown.js +52 -19
- package/ui/DropDown.js.map +1 -1
- package/utils/findTypographyStyleByHtmlTag.d.ts +8 -0
- package/utils/findTypographyStyleByHtmlTag.js +16 -0
- package/utils/findTypographyStyleByHtmlTag.js.map +1 -0
- package/utils/generateInitialLexicalValue.js +2 -1
- package/utils/generateInitialLexicalValue.js.map +1 -1
- package/utils/getLexicalTextSelectionState.js +19 -3
- package/utils/getLexicalTextSelectionState.js.map +1 -1
- package/utils/nodes/formatToHeading.d.ts +3 -0
- package/utils/nodes/formatToHeading.js +25 -0
- package/utils/nodes/formatToHeading.js.map +1 -0
- package/utils/nodes/formatToParagraph.d.ts +1 -1
- package/utils/nodes/formatToParagraph.js +4 -3
- package/utils/nodes/formatToParagraph.js.map +1 -1
- package/utils/nodes/formatToQuote.js +8 -3
- package/utils/nodes/formatToQuote.js.map +1 -1
- package/hooks/useWebinyQuote.d.ts +0 -2
- package/hooks/useWebinyQuote.js.map +0 -1
- package/nodes/WebinyQuoteNode.d.ts +0 -29
- package/nodes/WebinyQuoteNode.js +0 -148
- package/nodes/WebinyQuoteNode.js.map +0 -1
|
@@ -4,21 +4,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.QuotePlugin = QuotePlugin;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
10
10
|
var _react = require("react");
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
function
|
|
11
|
+
var _QuoteNode = require("../../nodes/QuoteNode");
|
|
12
|
+
var _useQuote = require("../../hooks/useQuote");
|
|
13
|
+
function QuotePlugin() {
|
|
14
14
|
var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
|
|
15
15
|
_useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
|
|
16
16
|
editor = _useLexicalComposerCo2[0];
|
|
17
17
|
(0, _react.useEffect)(function () {
|
|
18
|
-
if (!editor.hasNodes([
|
|
19
|
-
throw new Error("
|
|
18
|
+
if (!editor.hasNodes([_QuoteNode.QuoteNode])) {
|
|
19
|
+
throw new Error("QuoteNodePlugin: QuoteNode is e not registered on editor");
|
|
20
20
|
}
|
|
21
21
|
}, [editor]);
|
|
22
|
-
(0,
|
|
22
|
+
(0, _useQuote.useQuote)(editor);
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["QuotePlugin","useLexicalComposerContext","editor","useEffect","hasNodes","QuoteNode","Error","useQuote"],"sources":["WebinyQuoteNodePlugin.ts"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { useEffect } from \"react\";\nimport { QuoteNode } from \"~/nodes/QuoteNode\";\nimport { useQuote } from \"~/hooks/useQuote\";\n\nexport function QuotePlugin(): null {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n if (!editor.hasNodes([QuoteNode])) {\n throw new Error(\"QuoteNodePlugin: QuoteNode is e not registered on editor\");\n }\n }, [editor]);\n\n useQuote(editor);\n\n return null;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAEO,SAASA,WAAW,GAAS;EAChC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EAEb,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAI,CAACD,MAAM,CAACE,QAAQ,CAAC,CAACC,oBAAS,CAAC,CAAC,EAAE;MAC/B,MAAM,IAAIC,KAAK,CAAC,0DAA0D,CAAC;IAC/E;EACJ,CAAC,EAAE,CAACJ,MAAM,CAAC,CAAC;EAEZ,IAAAK,kBAAQ,EAACL,MAAM,CAAC;EAEhB,OAAO,IAAI;AACf"}
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This are fallback styles for Webiny.
|
|
10
|
+
*/
|
|
11
|
+
|
|
7
12
|
.ContentEditable__root{
|
|
8
13
|
font-size: inherit;
|
|
9
14
|
line-height: 1.25;
|
|
@@ -34,25 +39,26 @@
|
|
|
34
39
|
}
|
|
35
40
|
.WebinyLexical__h1 {
|
|
36
41
|
font-size: 24px;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
margin: 0;
|
|
42
|
+
font-weight: inherit;
|
|
43
|
+
margin: inherit;
|
|
40
44
|
}
|
|
45
|
+
|
|
41
46
|
.WebinyLexical__h2 {
|
|
42
47
|
font-size: 15px;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
margin: 0;
|
|
46
|
-
text-transform: uppercase;
|
|
48
|
+
font-weight: inherit;
|
|
49
|
+
margin: inherit;
|
|
47
50
|
}
|
|
51
|
+
|
|
48
52
|
.WebinyLexical__h3 {
|
|
49
53
|
font-size: 12px;
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
font-weight: inherit;
|
|
55
|
+
margin: inherit;
|
|
52
56
|
}
|
|
57
|
+
|
|
53
58
|
.WebinyLexical__textBold {
|
|
54
59
|
font-weight: bold;
|
|
55
60
|
}
|
|
61
|
+
|
|
56
62
|
.WebinyLexical__textItalic {
|
|
57
63
|
font-style: italic;
|
|
58
64
|
}
|
|
@@ -65,14 +71,17 @@
|
|
|
65
71
|
.WebinyLexical__textUnderlineStrikethrough {
|
|
66
72
|
text-decoration: underline line-through;
|
|
67
73
|
}
|
|
74
|
+
|
|
68
75
|
.WebinyLexical__textSubscript {
|
|
69
76
|
font-size: 0.8em;
|
|
70
77
|
vertical-align: sub !important;
|
|
71
78
|
}
|
|
79
|
+
|
|
72
80
|
.WebinyLexical__textSuperscript {
|
|
73
81
|
font-size: 0.8em;
|
|
74
82
|
vertical-align: super;
|
|
75
83
|
}
|
|
84
|
+
|
|
76
85
|
.WebinyLexical__textCode {
|
|
77
86
|
background-color: rgb(240, 242, 245);
|
|
78
87
|
padding: 1px 0.25rem;
|
package/types.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export declare type ToolbarState = {
|
|
|
25
25
|
list: NodeState;
|
|
26
26
|
quote: NodeState;
|
|
27
27
|
textType: LexicalTextType;
|
|
28
|
+
paragraph: NodeState;
|
|
29
|
+
heading: NodeState;
|
|
28
30
|
};
|
|
29
31
|
export declare type TextBlockSelection = {
|
|
30
32
|
elementKey?: string;
|
|
@@ -47,9 +49,6 @@ export declare type TypographyValue = {
|
|
|
47
49
|
tag: TypographyHTMLTag;
|
|
48
50
|
name: string;
|
|
49
51
|
};
|
|
50
|
-
export interface WebinyThemeNode {
|
|
51
|
-
getStyleId: () => string;
|
|
52
|
-
}
|
|
53
52
|
export declare type ThemeEmotionMap = {
|
|
54
53
|
[styleId: string]: {
|
|
55
54
|
id: string;
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { ElementNode, LexicalNode, NodeSelection, RangeSelection, TextNode } from \"lexical\";\nimport { ListType } from \"@lexical/list\";\nimport { CSSObject } from \"@emotion/react\";\nexport type ToolbarType = \"heading\" | \"paragraph\" | string;\nexport type LexicalValue = string;\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type LexicalTextType =\n | ListType\n | \"paragraph\"\n | \"heading\"\n | \"quoteblock\"\n | \"bullet\"\n | \"number\"\n | \"link\"\n | undefined;\n\nexport type TextFormatting = {\n bold: boolean;\n underline: boolean;\n italic: boolean;\n // highlight: boolean #TODO implement with highlight action\n code: boolean;\n};\n\nexport type NodeState = {\n isSelected: boolean;\n};\n\nexport type ToolbarState = {\n // text format\n bold: boolean;\n underline: boolean;\n italic: boolean;\n code: boolean;\n // nodes selection state\n link: NodeState;\n typography: NodeState;\n fontColor: NodeState;\n list: NodeState;\n quote: NodeState;\n textType: LexicalTextType;\n};\n\n/*\n * Represent set of data from the current selection of the text and nodes selected by the user.\n * You can access this object through the @see useRichTextEditor context.\n */\nexport type TextBlockSelection = {\n elementKey?: string;\n selection: RangeSelection | NodeSelection | null;\n element: LexicalNode;\n parent: ElementNode | null;\n node: ElementNode | TextNode;\n anchorNode: ElementNode | TextNode;\n isElementDom: boolean;\n state: ToolbarState | undefined;\n};\n\n// Supported HTML tags by webiny lexical implementation\nexport type ListHtmlTag = \"ol\" | \"ul\";\nexport type HeadingHtmlTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\nexport type ParagraphHtmlTag = \"p\";\nexport type QuoteBlockHtmlTag = \"quoteblock\";\n\n// Typography\nexport type TypographyHTMLTag = HeadingHtmlTag | ParagraphHtmlTag | ListHtmlTag | QuoteBlockHtmlTag;\n\nexport type TypographyValue = {\n // CSSObject type\n css: CSSObject;\n id: string;\n tag: TypographyHTMLTag;\n // Display name\n name: string;\n};\n\n/* Nodes */\
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { ElementNode, LexicalNode, NodeSelection, RangeSelection, TextNode } from \"lexical\";\nimport { ListType } from \"@lexical/list\";\nimport { CSSObject } from \"@emotion/react\";\nexport type ToolbarType = \"heading\" | \"paragraph\" | string;\nexport type LexicalValue = string;\nexport { FontColorPicker } from \"~/components/ToolbarActions/FontColorAction\";\n\nexport type LexicalTextType =\n | ListType\n | \"paragraph\"\n | \"heading\"\n | \"quoteblock\"\n | \"bullet\"\n | \"number\"\n | \"link\"\n | undefined;\n\nexport type TextFormatting = {\n bold: boolean;\n underline: boolean;\n italic: boolean;\n // highlight: boolean #TODO implement with highlight action\n code: boolean;\n};\n\nexport type NodeState = {\n isSelected: boolean;\n};\n\nexport type ToolbarState = {\n // text format\n bold: boolean;\n underline: boolean;\n italic: boolean;\n code: boolean;\n // nodes selection state\n link: NodeState;\n typography: NodeState;\n fontColor: NodeState;\n list: NodeState;\n quote: NodeState;\n textType: LexicalTextType;\n paragraph: NodeState;\n heading: NodeState;\n};\n\n/*\n * Represent set of data from the current selection of the text and nodes selected by the user.\n * You can access this object through the @see useRichTextEditor context.\n */\nexport type TextBlockSelection = {\n elementKey?: string;\n selection: RangeSelection | NodeSelection | null;\n element: LexicalNode;\n parent: ElementNode | null;\n node: ElementNode | TextNode;\n anchorNode: ElementNode | TextNode;\n isElementDom: boolean;\n state: ToolbarState | undefined;\n};\n\n// Supported HTML tags by webiny lexical implementation\nexport type ListHtmlTag = \"ol\" | \"ul\";\nexport type HeadingHtmlTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\nexport type ParagraphHtmlTag = \"p\";\nexport type QuoteBlockHtmlTag = \"quoteblock\";\n\n// Typography\nexport type TypographyHTMLTag = HeadingHtmlTag | ParagraphHtmlTag | ListHtmlTag | QuoteBlockHtmlTag;\n\nexport type TypographyValue = {\n // CSSObject type\n css: CSSObject;\n id: string;\n tag: TypographyHTMLTag;\n // Display name\n name: string;\n};\n\n/* Nodes */\n\n/*\n * Contains IDs of the styles and Emotion generated classes.\n */\nexport type ThemeEmotionMap = {\n [styleId: string]: {\n id: string;\n tag: TypographyHTMLTag;\n name: string;\n styles: Record<string, any>;\n // emotion generated class\n className: string;\n };\n};\n"],"mappings":";;;;;;;;;;;AAKA"}
|
package/ui/DropDown.js
CHANGED
|
@@ -39,7 +39,8 @@ function DropDownItem(_ref) {
|
|
|
39
39
|
className: className,
|
|
40
40
|
onClick: onClick,
|
|
41
41
|
ref: ref,
|
|
42
|
-
title: title
|
|
42
|
+
title: title,
|
|
43
|
+
type: "button"
|
|
43
44
|
}, children);
|
|
44
45
|
}
|
|
45
46
|
function DropDownItems(_ref2) {
|
|
@@ -105,7 +106,7 @@ function DropDownItems(_ref2) {
|
|
|
105
106
|
value: contextValue
|
|
106
107
|
}, /*#__PURE__*/React.createElement("div", {
|
|
107
108
|
className: "lexical-dropdown ".concat(showScroll ? "" : "no-scroll"),
|
|
108
|
-
ref: dropDownRef
|
|
109
|
+
ref: dropDownRef,
|
|
109
110
|
onKeyDown: handleKeyDown
|
|
110
111
|
}, children));
|
|
111
112
|
}
|
|
@@ -120,12 +121,19 @@ function DropDown(_ref3) {
|
|
|
120
121
|
stopCloseOnClickSelf = _ref3.stopCloseOnClickSelf,
|
|
121
122
|
_ref3$showScroll = _ref3.showScroll,
|
|
122
123
|
showScroll = _ref3$showScroll === void 0 ? true : _ref3$showScroll;
|
|
124
|
+
var dropDownRef = (0, React.useRef)(null);
|
|
123
125
|
var buttonRef = (0, React.useRef)(null);
|
|
126
|
+
// Used to prevent flickering of the dropdown while calculating the dropdown position.
|
|
124
127
|
var _useState5 = (0, React.useState)(false),
|
|
125
128
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
positionIsCalculated = _useState6[0],
|
|
130
|
+
setPositionIsCalculated = _useState6[1];
|
|
131
|
+
var _useState7 = (0, React.useState)(false),
|
|
132
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
133
|
+
showDropDown = _useState8[0],
|
|
134
|
+
setShowDropDown = _useState8[1];
|
|
128
135
|
var handleClose = function handleClose() {
|
|
136
|
+
setPositionIsCalculated(false);
|
|
129
137
|
setShowDropDown(false);
|
|
130
138
|
if (buttonRef && buttonRef.current) {
|
|
131
139
|
buttonRef.current.focus();
|
|
@@ -133,21 +141,44 @@ function DropDown(_ref3) {
|
|
|
133
141
|
};
|
|
134
142
|
(0, React.useEffect)(function () {
|
|
135
143
|
var button = buttonRef.current;
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
var dropDown = dropDownRef.current;
|
|
145
|
+
if (showDropDown && button && dropDown) {
|
|
146
|
+
dropDown.style.top = "44px";
|
|
147
|
+
dropDown.style.left = "".concat(button.offsetLeft, "px");
|
|
148
|
+
setPositionIsCalculated(true);
|
|
138
149
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
}, [dropDownRef, buttonRef, showDropDown]);
|
|
151
|
+
(0, React.useEffect)(function () {
|
|
152
|
+
var button = buttonRef.current;
|
|
153
|
+
if (button && showDropDown) {
|
|
154
|
+
var handle = function handle(event) {
|
|
155
|
+
var target = event.target;
|
|
156
|
+
if (stopCloseOnClickSelf) {
|
|
157
|
+
if (dropDownRef.current && dropDownRef.current.contains(target)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (!button.contains(target)) {
|
|
162
|
+
setShowDropDown(false);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
document.addEventListener("click", handle);
|
|
166
|
+
return function () {
|
|
167
|
+
document.removeEventListener("click", handle);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}, [dropDownRef, buttonRef, showDropDown, stopCloseOnClickSelf]);
|
|
172
|
+
var displayContainer = (0, React.useMemo)(function () {
|
|
173
|
+
// To prevent blinking, we show the container only when the dropdown position is calculated.
|
|
174
|
+
// Without this, window would be visible first on left (0px), and after a millisecond on the right side.
|
|
175
|
+
return positionIsCalculated ? {
|
|
176
|
+
display: "block"
|
|
177
|
+
} : {
|
|
178
|
+
display: "none"
|
|
148
179
|
};
|
|
149
|
-
}, [
|
|
150
|
-
return /*#__PURE__*/React.createElement("button", {
|
|
180
|
+
}, [positionIsCalculated]);
|
|
181
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
151
182
|
style: {
|
|
152
183
|
position: "relative"
|
|
153
184
|
},
|
|
@@ -164,10 +195,12 @@ function DropDown(_ref3) {
|
|
|
164
195
|
className: "text dropdown-button-text"
|
|
165
196
|
}, buttonLabel), /*#__PURE__*/React.createElement("i", {
|
|
166
197
|
className: "chevron-down"
|
|
167
|
-
}), showDropDown && /*#__PURE__*/React.createElement("div", {
|
|
168
|
-
className: "lexical-dropdown-container"
|
|
198
|
+
})), showDropDown && /*#__PURE__*/React.createElement("div", {
|
|
199
|
+
className: "lexical-dropdown-container",
|
|
200
|
+
style: displayContainer
|
|
169
201
|
}, /*#__PURE__*/React.createElement(DropDownItems, {
|
|
170
202
|
showScroll: showScroll,
|
|
203
|
+
dropDownRef: dropDownRef,
|
|
171
204
|
onClose: handleClose
|
|
172
205
|
}, children)));
|
|
173
206
|
}
|
package/ui/DropDown.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DropDownContext","React","createContext","DropDownItem","children","className","onClick","title","ref","useRef","dropDownContext","useContext","Error","registerItem","useEffect","current","DropDownItems","dropDownRef","showScroll","onClose","useState","items","setItems","highlightedItem","setHighlightedItem","useCallback","itemRef","prev","handleKeyDown","event","key","includes","preventDefault","index","indexOf","length","contextValue","useMemo","focus","DropDown","disabled","buttonLabel","buttonAriaLabel","buttonClassName","buttonIconClassName","stopCloseOnClickSelf","buttonRef","showDropDown","setShowDropDown","handleClose","button","handle","target","contains","document","addEventListener","removeEventListener","position"],"sources":["DropDown.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport * as React from \"react\";\n\ntype DropDownContextType = {\n registerItem: (ref: React.RefObject<HTMLButtonElement>) => void;\n};\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null);\n\nexport function DropDownItem({\n children,\n className,\n onClick,\n title\n}: {\n children: React.ReactNode;\n className: string;\n onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;\n title?: string;\n}) {\n const ref = useRef<HTMLButtonElement>(null);\n\n const dropDownContext = React.useContext(DropDownContext);\n\n if (dropDownContext === null) {\n throw new Error(\"DropDownItem must be used within a DropDown\");\n }\n\n const { registerItem } = dropDownContext;\n\n useEffect(() => {\n if (ref && ref.current) {\n registerItem(ref);\n }\n }, [ref, registerItem]);\n\n return (\n <button className={className} onClick={onClick} ref={ref} title={title}>\n {children}\n </button>\n );\n}\n\nfunction DropDownItems({\n children,\n dropDownRef,\n showScroll = true,\n onClose\n}: {\n children: React.ReactNode;\n dropDownRef?: React.Ref<HTMLDivElement>;\n showScroll?: boolean;\n onClose: () => void;\n}) {\n const [items, setItems] = useState<React.RefObject<HTMLButtonElement>[]>();\n const [highlightedItem, setHighlightedItem] = useState<React.RefObject<HTMLButtonElement>>();\n\n const registerItem = useCallback(\n (itemRef: React.RefObject<HTMLButtonElement>) => {\n setItems(prev => (prev ? [...prev, itemRef] : [itemRef]));\n },\n [setItems]\n );\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (!items) {\n return;\n }\n\n const key = event.key;\n\n if ([\"Escape\", \"ArrowUp\", \"ArrowDown\", \"Tab\"].includes(key)) {\n event.preventDefault();\n }\n\n if (key === \"Escape\" || key === \"Tab\") {\n onClose();\n } else if (key === \"ArrowUp\") {\n setHighlightedItem(prev => {\n if (!prev) {\n return items[0];\n }\n const index = items.indexOf(prev) - 1;\n return items[index === -1 ? items.length - 1 : index];\n });\n } else if (key === \"ArrowDown\") {\n setHighlightedItem(prev => {\n if (!prev) {\n return items[0];\n }\n return items[items.indexOf(prev) + 1];\n });\n }\n };\n\n const contextValue = useMemo(\n () => ({\n registerItem\n }),\n [registerItem]\n );\n\n useEffect(() => {\n if (items && !highlightedItem) {\n setHighlightedItem(items[0]);\n }\n\n if (highlightedItem && highlightedItem.current) {\n highlightedItem.current.focus();\n }\n }, [items, highlightedItem]);\n\n return (\n <DropDownContext.Provider value={contextValue}>\n <div\n className={`lexical-dropdown ${showScroll ? \"\" : \"no-scroll\"}`}\n ref={dropDownRef ?? null}\n onKeyDown={handleKeyDown}\n >\n {children}\n </div>\n </DropDownContext.Provider>\n );\n}\n\nexport function DropDown({\n disabled = false,\n buttonLabel,\n buttonAriaLabel,\n buttonClassName,\n buttonIconClassName,\n children,\n stopCloseOnClickSelf,\n showScroll = true\n}: {\n disabled?: boolean;\n buttonAriaLabel?: string;\n buttonClassName: string;\n buttonIconClassName?: string;\n buttonLabel?: string;\n children: ReactNode;\n stopCloseOnClickSelf?: boolean;\n showScroll?: boolean;\n}): JSX.Element {\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [showDropDown, setShowDropDown] = useState(false);\n\n const handleClose = () => {\n setShowDropDown(false);\n if (buttonRef && buttonRef.current) {\n buttonRef.current.focus();\n }\n };\n\n useEffect(() => {\n const button = buttonRef.current;\n if (button === null || !showDropDown) {\n return;\n }\n\n const handle = (event: MouseEvent) => {\n const target = event.target;\n if (!button.contains(target as Node)) {\n setShowDropDown(false);\n }\n };\n document.addEventListener(\"click\", handle);\n\n return () => {\n document.removeEventListener(\"click\", handle);\n };\n }, [buttonRef, showDropDown, stopCloseOnClickSelf]);\n\n return (\n <button\n style={{ position: \"relative\" }}\n disabled={disabled}\n aria-label={buttonAriaLabel || buttonLabel}\n className={buttonClassName}\n onClick={() => setShowDropDown(!showDropDown)}\n ref={buttonRef}\n >\n {buttonIconClassName && <span className={buttonIconClassName} />}\n {buttonLabel && <span className=\"text dropdown-button-text\">{buttonLabel}</span>}\n <i className=\"chevron-down\" />\n {showDropDown && (\n <div className={\"lexical-dropdown-container\"}>\n <DropDownItems showScroll={showScroll} onClose={handleClose}>\n {children}\n </DropDownItems>\n </div>\n )}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;;AAQA;AARA;AAC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M,GAAGJ,SAAS,CAAC/B,OAAO;IAChC,IAAImC,MAAM,KAAK,IAAI,IAAI,CAACH,YAAY,EAAE;MAClC;IACJ;IAEA,IAAMI,MAAM,GAAG,SAATA,MAAM,CAAItB,KAAiB,EAAK;MAClC,IAAMuB,MAAM,GAAGvB,KAAK,CAACuB,MAAM;MAC3B,IAAI,CAACF,MAAM,CAACG,QAAQ,CAACD,MAAM,CAAS,EAAE;QAClCJ,eAAe,CAAC,KAAK,CAAC;MAC1B;IACJ,CAAC;IACDM,QAAQ,CAACC,gBAAgB,CAAC,OAAO,EAAEJ,MAAM,CAAC;IAE1C,OAAO,YAAM;MACTG,QAAQ,CAACE,mBAAmB,CAAC,OAAO,EAAEL,MAAM,CAAC;IACjD,CAAC;EACL,CAAC,EAAE,CAACL,SAAS,EAAEC,YAAY,EAAEF,oBAAoB,CAAC,CAAC;EAEnD,oBACI;IACI,KAAK,EAAE;MAAEY,QAAQ,EAAE;IAAW,CAAE;IAChC,QAAQ,EAAEjB,QAAS;IACnB,cAAYE,eAAe,IAAID,WAAY;IAC3C,SAAS,EAAEE,eAAgB;IAC3B,OAAO,EAAE;MAAA,OAAMK,eAAe,CAAC,CAACD,YAAY,CAAC;IAAA,CAAC;IAC9C,GAAG,EAAED;EAAU,GAEdF,mBAAmB,iBAAI;IAAM,SAAS,EAAEA;EAAoB,EAAG,EAC/DH,WAAW,iBAAI;IAAM,SAAS,EAAC;EAA2B,GAAEA,WAAW,CAAQ,eAChF;IAAG,SAAS,EAAC;EAAc,EAAG,EAC7BM,YAAY,iBACT;IAAK,SAAS,EAAE;EAA6B,gBACzC,oBAAC,aAAa;IAAC,UAAU,EAAE7B,UAAW;IAAC,OAAO,EAAE+B;EAAY,GACvD7C,QAAQ,CACG,CAEvB,CACI;AAEjB"}
|
|
1
|
+
{"version":3,"names":["DropDownContext","React","createContext","DropDownItem","children","className","onClick","title","ref","useRef","dropDownContext","useContext","Error","registerItem","useEffect","current","DropDownItems","dropDownRef","showScroll","onClose","useState","items","setItems","highlightedItem","setHighlightedItem","useCallback","itemRef","prev","handleKeyDown","event","key","includes","preventDefault","index","indexOf","length","contextValue","useMemo","focus","DropDown","disabled","buttonLabel","buttonAriaLabel","buttonClassName","buttonIconClassName","stopCloseOnClickSelf","buttonRef","positionIsCalculated","setPositionIsCalculated","showDropDown","setShowDropDown","handleClose","button","dropDown","style","top","left","offsetLeft","handle","target","contains","document","addEventListener","removeEventListener","displayContainer","display","position"],"sources":["DropDown.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport * as React from \"react\";\n\ntype DropDownContextType = {\n registerItem: (ref: React.RefObject<HTMLButtonElement>) => void;\n};\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null);\n\nexport function DropDownItem({\n children,\n className,\n onClick,\n title\n}: {\n children: React.ReactNode;\n className: string;\n onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;\n title?: string;\n}) {\n const ref = useRef<HTMLButtonElement>(null);\n\n const dropDownContext = React.useContext(DropDownContext);\n\n if (dropDownContext === null) {\n throw new Error(\"DropDownItem must be used within a DropDown\");\n }\n\n const { registerItem } = dropDownContext;\n\n useEffect(() => {\n if (ref && ref.current) {\n registerItem(ref);\n }\n }, [ref, registerItem]);\n\n return (\n <button className={className} onClick={onClick} ref={ref} title={title} type=\"button\">\n {children}\n </button>\n );\n}\n\nfunction DropDownItems({\n children,\n dropDownRef,\n showScroll = true,\n onClose\n}: {\n children: React.ReactNode;\n dropDownRef?: React.Ref<HTMLDivElement>;\n showScroll?: boolean;\n onClose: () => void;\n}) {\n const [items, setItems] = useState<React.RefObject<HTMLButtonElement>[]>();\n const [highlightedItem, setHighlightedItem] = useState<React.RefObject<HTMLButtonElement>>();\n\n const registerItem = useCallback(\n (itemRef: React.RefObject<HTMLButtonElement>) => {\n setItems(prev => (prev ? [...prev, itemRef] : [itemRef]));\n },\n [setItems]\n );\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (!items) {\n return;\n }\n\n const key = event.key;\n\n if ([\"Escape\", \"ArrowUp\", \"ArrowDown\", \"Tab\"].includes(key)) {\n event.preventDefault();\n }\n\n if (key === \"Escape\" || key === \"Tab\") {\n onClose();\n } else if (key === \"ArrowUp\") {\n setHighlightedItem(prev => {\n if (!prev) {\n return items[0];\n }\n const index = items.indexOf(prev) - 1;\n return items[index === -1 ? items.length - 1 : index];\n });\n } else if (key === \"ArrowDown\") {\n setHighlightedItem(prev => {\n if (!prev) {\n return items[0];\n }\n return items[items.indexOf(prev) + 1];\n });\n }\n };\n\n const contextValue = useMemo(\n () => ({\n registerItem\n }),\n [registerItem]\n );\n\n useEffect(() => {\n if (items && !highlightedItem) {\n setHighlightedItem(items[0]);\n }\n\n if (highlightedItem && highlightedItem.current) {\n highlightedItem.current.focus();\n }\n }, [items, highlightedItem]);\n\n return (\n <DropDownContext.Provider value={contextValue}>\n <div\n className={`lexical-dropdown ${showScroll ? \"\" : \"no-scroll\"}`}\n ref={dropDownRef}\n onKeyDown={handleKeyDown}\n >\n {children}\n </div>\n </DropDownContext.Provider>\n );\n}\n\nexport function DropDown({\n disabled = false,\n buttonLabel,\n buttonAriaLabel,\n buttonClassName,\n buttonIconClassName,\n children,\n stopCloseOnClickSelf,\n showScroll = true\n}: {\n disabled?: boolean;\n buttonAriaLabel?: string;\n buttonClassName: string;\n buttonIconClassName?: string;\n buttonLabel?: string;\n children: ReactNode;\n stopCloseOnClickSelf?: boolean;\n showScroll?: boolean;\n}): JSX.Element {\n const dropDownRef = useRef<HTMLDivElement>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n // Used to prevent flickering of the dropdown while calculating the dropdown position.\n const [positionIsCalculated, setPositionIsCalculated] = useState(false);\n const [showDropDown, setShowDropDown] = useState(false);\n\n const handleClose = () => {\n setPositionIsCalculated(false);\n setShowDropDown(false);\n if (buttonRef && buttonRef.current) {\n buttonRef.current.focus();\n }\n };\n\n useEffect(() => {\n const button = buttonRef.current;\n const dropDown = dropDownRef.current;\n\n if (showDropDown && button && dropDown) {\n dropDown.style.top = \"44px\";\n dropDown.style.left = `${button.offsetLeft}px`;\n setPositionIsCalculated(true);\n }\n }, [dropDownRef, buttonRef, showDropDown]);\n\n useEffect(() => {\n const button = buttonRef.current;\n if (button && showDropDown) {\n const handle = (event: MouseEvent) => {\n const target = event.target;\n if (stopCloseOnClickSelf) {\n if (dropDownRef.current && dropDownRef.current.contains(target as Node)) {\n return;\n }\n }\n\n if (!button.contains(target as Node)) {\n setShowDropDown(false);\n }\n };\n document.addEventListener(\"click\", handle);\n return () => {\n document.removeEventListener(\"click\", handle);\n };\n }\n return;\n }, [dropDownRef, buttonRef, showDropDown, stopCloseOnClickSelf]);\n\n const displayContainer = useMemo(() => {\n // To prevent blinking, we show the container only when the dropdown position is calculated.\n // Without this, window would be visible first on left (0px), and after a millisecond on the right side.\n return positionIsCalculated ? { display: \"block\" } : { display: \"none\" };\n }, [positionIsCalculated]);\n\n return (\n <>\n <button\n style={{ position: \"relative\" }}\n disabled={disabled}\n aria-label={buttonAriaLabel || buttonLabel}\n className={buttonClassName}\n onClick={() => setShowDropDown(!showDropDown)}\n ref={buttonRef}\n >\n {buttonIconClassName && <span className={buttonIconClassName} />}\n {buttonLabel && <span className=\"text dropdown-button-text\">{buttonLabel}</span>}\n <i className=\"chevron-down\" />\n </button>\n {showDropDown && (\n <div className={\"lexical-dropdown-container\"} style={displayContainer}>\n <DropDownItems\n showScroll={showScroll}\n dropDownRef={dropDownRef}\n onClose={handleClose}\n >\n {children}\n </DropDownItems>\n </div>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AAQA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,IAAMA,eAAe,gBAAGC,KAAK,CAACC,aAAa,CAA6B,IAAI,CAAC;AAEtE,SAASC,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C;IACA;IACA,OAAOU,oBAAoB,GAAG;MAAEkB,OAAO,EAAE;IAAQ,CAAC,GAAG;MAAEA,OAAO,EAAE;IAAO,CAAC;EAC5E,CAAC,EAAE,CAAClB,oBAAoB,CAAC,CAAC;EAE1B,oBACI,uDACI;IACI,KAAK,EAAE;MAAEmB,QAAQ,EAAE;IAAW,CAAE;IAChC,QAAQ,EAAE1B,QAAS;IACnB,cAAYE,eAAe,IAAID,WAAY;IAC3C,SAAS,EAAEE,eAAgB;IAC3B,OAAO,EAAE;MAAA,OAAMO,eAAe,CAAC,CAACD,YAAY,CAAC;IAAA,CAAC;IAC9C,GAAG,EAAEH;EAAU,GAEdF,mBAAmB,iBAAI;IAAM,SAAS,EAAEA;EAAoB,EAAG,EAC/DH,WAAW,iBAAI;IAAM,SAAS,EAAC;EAA2B,GAAEA,WAAW,CAAQ,eAChF;IAAG,SAAS,EAAC;EAAc,EAAG,CACzB,EACRQ,YAAY,iBACT;IAAK,SAAS,EAAE,4BAA6B;IAAC,KAAK,EAAEe;EAAiB,gBAClE,oBAAC,aAAa;IACV,UAAU,EAAE9C,UAAW;IACvB,WAAW,EAAED,WAAY;IACzB,OAAO,EAAEkC;EAAY,GAEpB/C,QAAQ,CACG,CAEvB,CACF;AAEX"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ThemeEmotionMap } from "../types";
|
|
2
|
+
export declare const findTypographyStyleByHtmlTag: (htmlTag: string, themeEmotionMap: ThemeEmotionMap) => {
|
|
3
|
+
id: string;
|
|
4
|
+
tag: import("../types").TypographyHTMLTag;
|
|
5
|
+
name: string;
|
|
6
|
+
styles: Record<string, any>;
|
|
7
|
+
className: string;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findTypographyStyleByHtmlTag = void 0;
|
|
7
|
+
var findTypographyStyleByHtmlTag = function findTypographyStyleByHtmlTag(htmlTag, themeEmotionMap) {
|
|
8
|
+
for (var styleId in themeEmotionMap) {
|
|
9
|
+
var style = themeEmotionMap[styleId];
|
|
10
|
+
if (style.tag === htmlTag) {
|
|
11
|
+
return style;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
exports.findTypographyStyleByHtmlTag = findTypographyStyleByHtmlTag;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["findTypographyStyleByHtmlTag","htmlTag","themeEmotionMap","styleId","style","tag","undefined"],"sources":["findTypographyStyleByHtmlTag.ts"],"sourcesContent":["import { ThemeEmotionMap } from \"~/types\";\n\nexport const findTypographyStyleByHtmlTag = (htmlTag: string, themeEmotionMap: ThemeEmotionMap) => {\n for (const styleId in themeEmotionMap) {\n const style = themeEmotionMap[styleId];\n if (style.tag === htmlTag) {\n return style;\n }\n }\n return undefined;\n};\n"],"mappings":";;;;;;AAEO,IAAMA,4BAA4B,GAAG,SAA/BA,4BAA4B,CAAIC,OAAe,EAAEC,eAAgC,EAAK;EAC/F,KAAK,IAAMC,OAAO,IAAID,eAAe,EAAE;IACnC,IAAME,KAAK,GAAGF,eAAe,CAACC,OAAO,CAAC;IACtC,IAAIC,KAAK,CAACC,GAAG,KAAKJ,OAAO,EAAE;MACvB,OAAOG,KAAK;IAChB;EACJ;EACA,OAAOE,SAAS;AACpB,CAAC;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["generateInitialLexicalValue","JSON","stringify","root","children","direction","format","indent","type","version"],"sources":["generateInitialLexicalValue.ts"],"sourcesContent":["import { LexicalValue } from \"~/types\";\n\n/**\n * @description Basic JSON data string that will initialize the editor.\n */\nexport const generateInitialLexicalValue = (): LexicalValue => {\n return JSON.stringify({\n root: {\n children: [\n {\n children: [],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"paragraph\",\n version: 1\n }\n ],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"root\",\n version: 1\n }\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2B,GAAuB;EAC3D,OAAOC,IAAI,CAACC,SAAS,CAAC;IAClBC,IAAI,EAAE;MACFC,QAAQ,EAAE,CACN;QACIA,QAAQ,EAAE,EAAE;QACZC,SAAS,EAAE,IAAI;QACfC,MAAM,EAAE,EAAE;QACVC,MAAM,EAAE,CAAC;QACTC,IAAI,EAAE,
|
|
1
|
+
{"version":3,"names":["generateInitialLexicalValue","JSON","stringify","root","children","direction","format","indent","styles","type","version"],"sources":["generateInitialLexicalValue.ts"],"sourcesContent":["import { LexicalValue } from \"~/types\";\n\n/**\n * @description Basic JSON data string that will initialize the editor.\n */\nexport const generateInitialLexicalValue = (): LexicalValue => {\n return JSON.stringify({\n root: {\n children: [\n {\n children: [],\n direction: null,\n format: \"\",\n indent: 0,\n styles: [],\n type: \"base-paragraph-node\",\n version: 1\n }\n ],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"root\",\n version: 1\n }\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2B,GAAuB;EAC3D,OAAOC,IAAI,CAACC,SAAS,CAAC;IAClBC,IAAI,EAAE;MACFC,QAAQ,EAAE,CACN;QACIA,QAAQ,EAAE,EAAE;QACZC,SAAS,EAAE,IAAI;QACfC,MAAM,EAAE,EAAE;QACVC,MAAM,EAAE,CAAC;QACTC,MAAM,EAAE,EAAE;QACVC,IAAI,EAAE,qBAAqB;QAC3BC,OAAO,EAAE;MACb,CAAC,CACJ;MACDL,SAAS,EAAE,IAAI;MACfC,MAAM,EAAE,EAAE;MACVC,MAAM,EAAE,CAAC;MACTE,IAAI,EAAE,MAAM;MACZC,OAAO,EAAE;IACb;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -14,7 +14,9 @@ var _WebinyListNode = require("../nodes/list-node/WebinyListNode");
|
|
|
14
14
|
var _richText = require("@lexical/rich-text");
|
|
15
15
|
var _TypographyElementNode = require("../nodes/TypographyElementNode");
|
|
16
16
|
var _FontColorNode = require("../nodes/FontColorNode");
|
|
17
|
-
var
|
|
17
|
+
var _ParagraphNode = require("../nodes/ParagraphNode");
|
|
18
|
+
var _HeadingNode = require("../nodes/HeadingNode");
|
|
19
|
+
var _QuoteNode = require("../nodes/QuoteNode");
|
|
18
20
|
var getSelectionTextFormat = function getSelectionTextFormat(selection) {
|
|
19
21
|
return !(0, _lexical.$isRangeSelection)(selection) ? {
|
|
20
22
|
italic: false,
|
|
@@ -50,6 +52,12 @@ var getDefaultToolbarState = function getDefaultToolbarState() {
|
|
|
50
52
|
quote: {
|
|
51
53
|
isSelected: false
|
|
52
54
|
},
|
|
55
|
+
paragraph: {
|
|
56
|
+
isSelected: false
|
|
57
|
+
},
|
|
58
|
+
heading: {
|
|
59
|
+
isSelected: false
|
|
60
|
+
},
|
|
53
61
|
textType: undefined
|
|
54
62
|
};
|
|
55
63
|
};
|
|
@@ -77,12 +85,20 @@ var getToolbarState = function getToolbarState(selection, node, parent, element,
|
|
|
77
85
|
var type = parentList ? parentList.getListType() : element.getListType();
|
|
78
86
|
state.textType = type;
|
|
79
87
|
}
|
|
80
|
-
if ((0, _richText.$isHeadingNode)(
|
|
88
|
+
if ((0, _richText.$isHeadingNode)(element)) {
|
|
81
89
|
state.textType = "heading";
|
|
82
90
|
}
|
|
91
|
+
if ((0, _HeadingNode.$isHeadingNode)(element)) {
|
|
92
|
+
state.textType = "heading";
|
|
93
|
+
state.heading.isSelected = true;
|
|
94
|
+
}
|
|
83
95
|
if ((0, _lexical.$isParagraphNode)(element)) {
|
|
84
96
|
state.textType = "paragraph";
|
|
85
97
|
}
|
|
98
|
+
if ((0, _ParagraphNode.$isParagraphNode)(element)) {
|
|
99
|
+
state.textType = "paragraph";
|
|
100
|
+
state.paragraph.isSelected = true;
|
|
101
|
+
}
|
|
86
102
|
if ((0, _TypographyElementNode.$isTypographyElementNode)(element)) {
|
|
87
103
|
state.typography.isSelected = true;
|
|
88
104
|
var value = element === null || element === void 0 ? void 0 : element.getTypographyValue();
|
|
@@ -96,7 +112,7 @@ var getToolbarState = function getToolbarState(selection, node, parent, element,
|
|
|
96
112
|
if ((0, _TypographyElementNode.$isTypographyElementNode)(element)) {
|
|
97
113
|
state.fontColor.isSelected = true;
|
|
98
114
|
}
|
|
99
|
-
if ((0,
|
|
115
|
+
if ((0, _QuoteNode.$isQuoteNode)(element)) {
|
|
100
116
|
state.textType = "quoteblock";
|
|
101
117
|
state.quote.isSelected = true;
|
|
102
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getSelectionTextFormat","selection","$isRangeSelection","italic","bold","underline","code","hasFormat","getDefaultToolbarState","link","isSelected","list","typography","fontColor","quote","textType","undefined","getToolbarState","node","parent","element","anchorNode","textFormat","state","$isLinkNode","$isFontColorNode","$isWebinyListNode","parentList","$getNearestNodeOfType","WebinyListNode","type","getListType","$isHeadingNode","$isParagraphNode","$isTypographyElementNode","value","getTypographyValue","tag","includes","$isWebinyQuoteNode","getLexicalTextSelectionState","activeEditor","anchor","getNode","getKey","$findMatchingParent","e","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","elementKey","elementDOM","getElementByKey","getSelectedNode","isElementDom"],"sources":["getLexicalTextSelectionState.ts"],"sourcesContent":["import { TextFormatting, TextBlockSelection, ToolbarState, TypographyValue } from \"~/types\";\nimport {\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n ElementNode,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n TextNode\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType } from \"@lexical/utils\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { $isWebinyListNode, WebinyListNode } from \"~/nodes/list-node/WebinyListNode\";\nimport { $isHeadingNode } from \"@lexical/rich-text\";\nimport { $isTypographyElementNode } from \"~/nodes/TypographyElementNode\";\nimport { $isFontColorNode } from \"~/nodes/FontColorNode\";\nimport { $isWebinyQuoteNode } from \"~/nodes/WebinyQuoteNode\";\n\nexport const getSelectionTextFormat = (selection: RangeSelection | undefined): TextFormatting => {\n return !$isRangeSelection(selection)\n ? {\n italic: false,\n bold: false,\n underline: false,\n code: false\n }\n : {\n bold: selection.hasFormat(\"bold\"),\n italic: selection.hasFormat(\"italic\"),\n underline: selection.hasFormat(\"underline\"),\n code: selection.hasFormat(\"code\")\n };\n};\n\nconst getDefaultToolbarState = (): ToolbarState => {\n return {\n bold: false,\n italic: false,\n underline: false,\n code: false,\n link: { isSelected: false },\n list: { isSelected: false },\n typography: { isSelected: false },\n fontColor: { isSelected: false },\n quote: { isSelected: false },\n textType: undefined\n };\n};\n\nexport const getToolbarState = (\n selection: RangeSelection,\n node: LexicalNode,\n parent: LexicalNode | null,\n element: LexicalNode | null,\n anchorNode: ElementNode | TextNode\n): ToolbarState => {\n const textFormat = getSelectionTextFormat(selection);\n let state: ToolbarState = getDefaultToolbarState();\n state = {\n ...state,\n bold: textFormat.bold,\n italic: textFormat.italic,\n underline: textFormat.underline,\n code: textFormat.code\n };\n\n // link\n state.link.isSelected = $isLinkNode(parent) || $isLinkNode(node);\n if (state.link.isSelected) {\n state.textType = \"link\";\n }\n // font color\n if ($isFontColorNode(node)) {\n state.fontColor.isSelected = true;\n }\n if ($isWebinyListNode(element)) {\n const parentList = $getNearestNodeOfType<WebinyListNode>(anchorNode, WebinyListNode);\n const type = parentList ? parentList.getListType() : element.getListType();\n state.textType = type;\n }\n if ($isHeadingNode(node) || $isHeadingNode(element)) {\n state.textType = \"heading\";\n }\n if ($isParagraphNode(element)) {\n state.textType = \"paragraph\";\n }\n if ($isTypographyElementNode(element)) {\n state.typography.isSelected = true;\n const value = element?.getTypographyValue() as TypographyValue;\n if (value.tag.includes(\"h\")) {\n state.textType = \"heading\";\n }\n if (value.tag.includes(\"p\")) {\n state.textType = \"paragraph\";\n }\n }\n if ($isTypographyElementNode(element)) {\n state.fontColor.isSelected = true;\n }\n if ($isWebinyQuoteNode(element)) {\n state.textType = \"quoteblock\";\n state.quote.isSelected = true;\n }\n\n return state;\n};\n\n/*\n * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.\n */\nexport const getLexicalTextSelectionState = (\n activeEditor: LexicalEditor,\n selection: RangeSelection\n): TextBlockSelection | null => {\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode();\n let element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n if (element === null) {\n element = anchorNode.getTopLevelElementOrThrow();\n }\n\n const elementKey = element.getKey();\n const elementDOM = activeEditor.getElementByKey(elementKey);\n\n // Update links\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n const isElementDom = elementDOM !== null;\n\n return {\n // node/element data from selection\n elementKey,\n element,\n parent,\n node,\n anchorNode,\n selection,\n isElementDom,\n state: getToolbarState(selection, node, parent, element, anchorNode)\n };\n }\n return null;\n};\n"],"mappings":";;;;;;;;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,CAAIC,SAAqC,EAAqB;EAC7F,OAAO,CAAC,IAAAC,0BAAiB,EAACD,SAAS,CAAC,GAC9B;IACIE,MAAM,EAAE,KAAK;IACbC,IAAI,EAAE,KAAK;IACXC,SAAS,EAAE,KAAK;IAChBC,IAAI,EAAE;EACV,CAAC,GACD;IACIF,IAAI,EAAEH,SAAS,CAACM,SAAS,CAAC,MAAM,CAAC;IACjCJ,MAAM,EAAEF,SAAS,CAACM,SAAS,CAAC,QAAQ,CAAC;IACrCF,SAAS,EAAEJ,SAAS,CAACM,SAAS,CAAC,WAAW,CAAC;IAC3CD,IA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AAI;AACf,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["getSelectionTextFormat","selection","$isRangeSelection","italic","bold","underline","code","hasFormat","getDefaultToolbarState","link","isSelected","list","typography","fontColor","quote","paragraph","heading","textType","undefined","getToolbarState","node","parent","element","anchorNode","textFormat","state","$isLinkNode","$isFontColorNode","$isWebinyListNode","parentList","$getNearestNodeOfType","WebinyListNode","type","getListType","$isBaseHeadingNode","$isHeadingNode","$isBaseParagraphNode","$isParagraphNode","$isTypographyElementNode","value","getTypographyValue","tag","includes","$isQuoteNode","getLexicalTextSelectionState","activeEditor","anchor","getNode","getKey","$findMatchingParent","e","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","elementKey","elementDOM","getElementByKey","getSelectedNode","isElementDom"],"sources":["getLexicalTextSelectionState.ts"],"sourcesContent":["import { TextFormatting, TextBlockSelection, ToolbarState, TypographyValue } from \"~/types\";\nimport {\n $isParagraphNode as $isBaseParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n ElementNode,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n TextNode\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType } from \"@lexical/utils\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { $isWebinyListNode, WebinyListNode } from \"~/nodes/list-node/WebinyListNode\";\nimport { $isHeadingNode as $isBaseHeadingNode } from \"@lexical/rich-text\";\nimport { $isTypographyElementNode } from \"~/nodes/TypographyElementNode\";\nimport { $isFontColorNode } from \"~/nodes/FontColorNode\";\nimport { $isParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $isHeadingNode } from \"~/nodes/HeadingNode\";\nimport { $isQuoteNode } from \"~/nodes/QuoteNode\";\n\nexport const getSelectionTextFormat = (selection: RangeSelection | undefined): TextFormatting => {\n return !$isRangeSelection(selection)\n ? {\n italic: false,\n bold: false,\n underline: false,\n code: false\n }\n : {\n bold: selection.hasFormat(\"bold\"),\n italic: selection.hasFormat(\"italic\"),\n underline: selection.hasFormat(\"underline\"),\n code: selection.hasFormat(\"code\")\n };\n};\n\nconst getDefaultToolbarState = (): ToolbarState => {\n return {\n bold: false,\n italic: false,\n underline: false,\n code: false,\n link: { isSelected: false },\n list: { isSelected: false },\n typography: { isSelected: false },\n fontColor: { isSelected: false },\n quote: { isSelected: false },\n paragraph: { isSelected: false },\n heading: { isSelected: false },\n textType: undefined\n };\n};\n\nexport const getToolbarState = (\n selection: RangeSelection,\n node: LexicalNode,\n parent: LexicalNode | null,\n element: LexicalNode | null,\n anchorNode: ElementNode | TextNode\n): ToolbarState => {\n const textFormat = getSelectionTextFormat(selection);\n let state: ToolbarState = getDefaultToolbarState();\n state = {\n ...state,\n bold: textFormat.bold,\n italic: textFormat.italic,\n underline: textFormat.underline,\n code: textFormat.code\n };\n\n // link\n state.link.isSelected = $isLinkNode(parent) || $isLinkNode(node);\n if (state.link.isSelected) {\n state.textType = \"link\";\n }\n // font color\n if ($isFontColorNode(node)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isWebinyListNode(element)) {\n const parentList = $getNearestNodeOfType<WebinyListNode>(anchorNode, WebinyListNode);\n const type = parentList ? parentList.getListType() : element.getListType();\n state.textType = type;\n }\n\n if ($isBaseHeadingNode(element)) {\n state.textType = \"heading\";\n }\n\n if ($isHeadingNode(element)) {\n state.textType = \"heading\";\n state.heading.isSelected = true;\n }\n\n if ($isBaseParagraphNode(element)) {\n state.textType = \"paragraph\";\n }\n\n if ($isParagraphNode(element)) {\n state.textType = \"paragraph\";\n state.paragraph.isSelected = true;\n }\n\n if ($isTypographyElementNode(element)) {\n state.typography.isSelected = true;\n const value = element?.getTypographyValue() as TypographyValue;\n if (value.tag.includes(\"h\")) {\n state.textType = \"heading\";\n }\n if (value.tag.includes(\"p\")) {\n state.textType = \"paragraph\";\n }\n }\n\n if ($isTypographyElementNode(element)) {\n state.fontColor.isSelected = true;\n }\n\n if ($isQuoteNode(element)) {\n state.textType = \"quoteblock\";\n state.quote.isSelected = true;\n }\n\n return state;\n};\n\n/*\n * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.\n */\nexport const getLexicalTextSelectionState = (\n activeEditor: LexicalEditor,\n selection: RangeSelection\n): TextBlockSelection | null => {\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode();\n let element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n if (element === null) {\n element = anchorNode.getTopLevelElementOrThrow();\n }\n\n const elementKey = element.getKey();\n const elementDOM = activeEditor.getElementByKey(elementKey);\n\n // Update links\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n const isElementDom = elementDOM !== null;\n\n return {\n // node/element data from selection\n elementKey,\n element,\n parent,\n node,\n anchorNode,\n selection,\n isElementDom,\n state: getToolbarState(selection, node, parent, element, anchorNode)\n };\n }\n return null;\n};\n"],"mappings":";;;;;;;;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,CAAIC,SAAqC,EAAqB;EAC7F,OAAO,CAAC,IAAAC,0BAAiB,EAACD,SAAS,CAAC,GAC9B;IACIE,MAAM,EAAE,KAAK;IACbC,IAAI,EAAE,KAAK;IACXC,SAAS,EAAE,KAAK;IAChBC,IAAI,EAAE;EACV,CAAC,GACD;IACIF,IAAI,EAAEH,SAAS,CAACM,SAAS,CAAC,MAAM,CAAC;IACjCJ,MAAM,EAAEF,SAAS,CAACM,SAAS,CAAC,QAAQ,CAAC;IACrCF,SAAS,EAAEJ,SAAS,CAACM,SAAS,CAAC,WAAW,CAAC;IAC3CD,IAAI,EAAEL,SAAS,CAACM,SAAS,CAAC,MAAM;EACpC,CAAC;AACX,CAAC;AAAC;AAEF,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsB,GAAuB;EAC/C,OAAO;I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O;MACPD,MAAM,EAANA,MAAM;MACND,IAAI,EAAJA,IAAI;MACJG,UAAU,EAAVA,UAAU;MACVtB,SAAS,EAATA,SAAS;MACTyD,YAAY,EAAZA,YAAY;MACZjC,KAAK,EAAEN,eAAe,CAAClB,SAAS,EAAEmB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,UAAU;IACvE,CAAC;EACL;EACA,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatToHeading = void 0;
|
|
7
|
+
var _lexical = require("lexical");
|
|
8
|
+
var _selection = require("@lexical/selection");
|
|
9
|
+
var _HeadingNode = require("../../nodes/HeadingNode");
|
|
10
|
+
/*
|
|
11
|
+
* Will change the selected HTML tag to specified heading or h1-h6.
|
|
12
|
+
* For example if the selection is p with content inside after formatting the root tag
|
|
13
|
+
* will be h1 with heading 1 theme style and the same content inside.
|
|
14
|
+
* */
|
|
15
|
+
var formatToHeading = function formatToHeading(editor, tag, typographyStyleId) {
|
|
16
|
+
editor.update(function () {
|
|
17
|
+
var selection = (0, _lexical.$getSelection)();
|
|
18
|
+
if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
|
|
19
|
+
(0, _selection.$setBlocksType)(selection, function () {
|
|
20
|
+
return (0, _HeadingNode.$createHeadingNode)(tag, typographyStyleId);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.formatToHeading = formatToHeading;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatToHeading","editor","tag","typographyStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$setBlocksType","$createHeadingNode"],"sources":["formatToHeading.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $setBlocksType } from \"@lexical/selection\";\nimport { $createHeadingNode } from \"~/nodes/HeadingNode\";\nimport { HeadingTagType } from \"@lexical/rich-text\";\n\n/*\n * Will change the selected HTML tag to specified heading or h1-h6.\n * For example if the selection is p with content inside after formatting the root tag\n * will be h1 with heading 1 theme style and the same content inside.\n * */\nexport const formatToHeading = (\n editor: LexicalEditor,\n tag: HeadingTagType,\n typographyStyleId?: string\n) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $setBlocksType(selection, () => $createHeadingNode(tag, typographyStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAGA;AACA;AACA;AACA;AACA;AACO,IAAMA,eAAe,GAAG,SAAlBA,eAAe,CACxBC,MAAqB,EACrBC,GAAmB,EACnBC,iBAA0B,EACzB;EACDF,MAAM,CAACG,MAAM,CAAC,YAAM;IAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,IAAI,IAAAG,oCAA2B,EAACH,SAAS,CAAC,EAAE;MACxE,IAAAI,yBAAc,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,+BAAkB,EAACR,GAAG,EAAEC,iBAAiB,CAAC;MAAA,EAAC;IAC/E;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { LexicalEditor } from "lexical";
|
|
2
|
-
export declare const formatToParagraph: (editor: LexicalEditor) => void;
|
|
2
|
+
export declare const formatToParagraph: (editor: LexicalEditor, typographyStyleId?: string) => void;
|
|
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.formatToParagraph = void 0;
|
|
7
7
|
var _lexical = require("lexical");
|
|
8
|
+
var _ParagraphNode = require("../../nodes/ParagraphNode");
|
|
8
9
|
var _selection = require("@lexical/selection");
|
|
9
|
-
var formatToParagraph = function formatToParagraph(editor) {
|
|
10
|
+
var formatToParagraph = function formatToParagraph(editor, typographyStyleId) {
|
|
10
11
|
editor.update(function () {
|
|
11
12
|
var selection = (0, _lexical.$getSelection)();
|
|
12
13
|
if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
|
|
13
|
-
(0, _selection.$
|
|
14
|
-
return (0,
|
|
14
|
+
(0, _selection.$setBlocksType)(selection, function () {
|
|
15
|
+
return (0, _ParagraphNode.$createParagraphNode)(typographyStyleId);
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["formatToParagraph","editor","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$
|
|
1
|
+
{"version":3,"names":["formatToParagraph","editor","typographyStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$setBlocksType","$createParagraphNode"],"sources":["formatToParagraph.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $createParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $setBlocksType } from \"@lexical/selection\";\n\nexport const formatToParagraph = (editor: LexicalEditor, typographyStyleId?: string) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $setBlocksType(selection, () => $createParagraphNode(typographyStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIC,MAAqB,EAAEC,iBAA0B,EAAK;EACpFD,MAAM,CAACE,MAAM,CAAC,YAAM;IAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,IAAI,IAAAG,oCAA2B,EAACH,SAAS,CAAC,EAAE;MACxE,IAAAI,yBAAc,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,mCAAoB,EAACP,iBAAiB,CAAC;MAAA,EAAC;IAC5E;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -6,13 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.formatToQuote = void 0;
|
|
7
7
|
var _lexical = require("lexical");
|
|
8
8
|
var _selection = require("@lexical/selection");
|
|
9
|
-
var
|
|
9
|
+
var _QuoteNode = require("../../nodes/QuoteNode");
|
|
10
|
+
/*
|
|
11
|
+
* Will change the selected root HTML tag to specified quoteblock tag.
|
|
12
|
+
* For example if the selection is paragraph <p> with content inside after formatting the root tag
|
|
13
|
+
* will be quoteblock with same content inside.
|
|
14
|
+
* */
|
|
10
15
|
var formatToQuote = function formatToQuote(editor, themeStyleId) {
|
|
11
16
|
editor.update(function () {
|
|
12
17
|
var selection = (0, _lexical.$getSelection)();
|
|
13
18
|
if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
|
|
14
|
-
(0, _selection.$
|
|
15
|
-
return (0,
|
|
19
|
+
(0, _selection.$setBlocksType)(selection, function () {
|
|
20
|
+
return (0, _QuoteNode.$createQuoteNode)(themeStyleId);
|
|
16
21
|
});
|
|
17
22
|
}
|
|
18
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["formatToQuote","editor","themeStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$
|
|
1
|
+
{"version":3,"names":["formatToQuote","editor","themeStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$setBlocksType","$createQuoteNode"],"sources":["formatToQuote.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $setBlocksType } from \"@lexical/selection\";\nimport { $createQuoteNode } from \"~/nodes/QuoteNode\";\n\n/*\n * Will change the selected root HTML tag to specified quoteblock tag.\n * For example if the selection is paragraph <p> with content inside after formatting the root tag\n * will be quoteblock with same content inside.\n * */\nexport const formatToQuote = (editor: LexicalEditor, themeStyleId?: string) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $setBlocksType(selection, () => $createQuoteNode(themeStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMA,aAAa,GAAG,SAAhBA,aAAa,CAAIC,MAAqB,EAAEC,YAAqB,EAAK;EAC3ED,MAAM,CAACE,MAAM,CAAC,YAAM;IAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,IAAI,IAAAG,oCAA2B,EAACH,SAAS,CAAC,EAAE;MACxE,IAAAI,yBAAc,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,2BAAgB,EAACP,YAAY,CAAC;MAAA,EAAC;IACnE;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useWebinyQuote","editor","useEffect","mergeRegister","registerCommand","INSERT_WEBINY_QUOTE_COMMAND","themeStyleId","formatToQuote","COMMAND_PRIORITY_LOW"],"sources":["useWebinyQuote.ts"],"sourcesContent":["import type { LexicalEditor } from \"lexical\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport { COMMAND_PRIORITY_LOW } from \"lexical\";\nimport { useEffect } from \"react\";\nimport { INSERT_WEBINY_QUOTE_COMMAND } from \"~/commands/webiny-quote\";\nimport { formatToQuote } from \"~/utils/nodes/formatToQuote\";\n\nexport function useWebinyQuote(editor: LexicalEditor): void {\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n INSERT_WEBINY_QUOTE_COMMAND,\n ({ themeStyleId }) => {\n formatToQuote(editor, themeStyleId);\n return false;\n },\n COMMAND_PRIORITY_LOW\n )\n );\n }, [editor]);\n}\n"],"mappings":";;;;;;AACA;AACA;AACA;AACA;AACA;AAEO,SAASA,cAAc,CAACC,MAAqB,EAAQ;EACxD,IAAAC,gBAAS,EAAC,YAAM;IACZ,OAAO,IAAAC,oBAAa,EAChBF,MAAM,CAACG,eAAe,CAClBC,wCAA2B,EAC3B,gBAAsB;MAAA,IAAnBC,YAAY,QAAZA,YAAY;MACX,IAAAC,4BAAa,EAACN,MAAM,EAAEK,YAAY,CAAC;MACnC,OAAO,KAAK;IAChB,CAAC,EACDE,6BAAoB,CACvB,CACJ;EACL,CAAC,EAAE,CAACP,MAAM,CAAC,CAAC;AAChB"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
/// <reference types="web" />
|
|
3
|
-
import { DOMConversionMap, EditorConfig, ElementNode, LexicalNode, NodeKey, ParagraphNode, SerializedElementNode, Spread } from "lexical";
|
|
4
|
-
import { WebinyEditorTheme } from "../themes/webinyLexicalTheme";
|
|
5
|
-
import { QuoteBlockHtmlTag, WebinyThemeNode } from "../types";
|
|
6
|
-
export declare type SerializedWebinyQuoteNode = Spread<{
|
|
7
|
-
tag: QuoteBlockHtmlTag;
|
|
8
|
-
styleId: string;
|
|
9
|
-
type: "webiny-quote";
|
|
10
|
-
version: 1;
|
|
11
|
-
}, SerializedElementNode>;
|
|
12
|
-
export declare class WebinyQuoteNode extends ElementNode implements WebinyThemeNode {
|
|
13
|
-
__themeStyleId: string;
|
|
14
|
-
constructor(themeStyleId?: string, key?: NodeKey);
|
|
15
|
-
getStyleId: () => string;
|
|
16
|
-
static getType(): string;
|
|
17
|
-
getTag(): QuoteBlockHtmlTag;
|
|
18
|
-
static clone(node: WebinyQuoteNode): WebinyQuoteNode;
|
|
19
|
-
addThemeStylesToHTMLElement(element: HTMLElement, theme: WebinyEditorTheme): HTMLElement;
|
|
20
|
-
createDOM(config: EditorConfig): HTMLElement;
|
|
21
|
-
updateDOM(): boolean;
|
|
22
|
-
static importDOM(): DOMConversionMap | null;
|
|
23
|
-
static importJSON(serializedNode: SerializedWebinyQuoteNode): WebinyQuoteNode;
|
|
24
|
-
exportJSON(): SerializedWebinyQuoteNode;
|
|
25
|
-
insertNewAfter(): ParagraphNode;
|
|
26
|
-
collapseAtStart(): true;
|
|
27
|
-
}
|
|
28
|
-
export declare function $createWebinyQuoteNode(themeStyleId?: string, key?: NodeKey): WebinyQuoteNode;
|
|
29
|
-
export declare function $isWebinyQuoteNode(node: LexicalNode | null | undefined): node is WebinyQuoteNode;
|