@webiny/lexical-nodes 5.38.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/FontColorNode.d.ts +43 -0
- package/FontColorNode.js +125 -0
- package/FontColorNode.js.map +1 -0
- package/HeadingNode.d.ts +32 -0
- package/HeadingNode.js +193 -0
- package/HeadingNode.js.map +1 -0
- package/ImageNode.d.ts +58 -0
- package/ImageNode.js +217 -0
- package/ImageNode.js.map +1 -0
- package/LICENSE +21 -0
- package/LinkNode.d.ts +106 -0
- package/LinkNode.js +531 -0
- package/LinkNode.js.map +1 -0
- package/ListItemNode.d.ts +44 -0
- package/ListItemNode.js +442 -0
- package/ListItemNode.js.map +1 -0
- package/ListNode.d.ts +42 -0
- package/ListNode.js +290 -0
- package/ListNode.js.map +1 -0
- package/ParagraphNode.d.ts +31 -0
- package/ParagraphNode.js +220 -0
- package/ParagraphNode.js.map +1 -0
- package/QuoteNode.d.ts +33 -0
- package/QuoteNode.js +227 -0
- package/QuoteNode.js.map +1 -0
- package/README.md +6 -0
- package/TypographyNode.d.ts +41 -0
- package/TypographyNode.js +153 -0
- package/TypographyNode.js.map +1 -0
- package/components/ImageNode/ContentEditable.css +22 -0
- package/components/ImageNode/ContentEditable.d.ts +12 -0
- package/components/ImageNode/ContentEditable.js +26 -0
- package/components/ImageNode/ContentEditable.js.map +1 -0
- package/components/ImageNode/ImageComponent.css +43 -0
- package/components/ImageNode/ImageComponent.d.ts +16 -0
- package/components/ImageNode/ImageComponent.js +254 -0
- package/components/ImageNode/ImageComponent.js.map +1 -0
- package/components/ImageNode/ImageResizer.d.ts +26 -0
- package/components/ImageNode/ImageResizer.js +215 -0
- package/components/ImageNode/ImageResizer.js.map +1 -0
- package/components/ImageNode/Placeholder.css +20 -0
- package/components/ImageNode/Placeholder.d.ts +15 -0
- package/components/ImageNode/Placeholder.js +30 -0
- package/components/ImageNode/Placeholder.js.map +1 -0
- package/components/ImageNode/SharedHistoryContext.d.ts +11 -0
- package/components/ImageNode/SharedHistoryContext.js +28 -0
- package/components/ImageNode/SharedHistoryContext.js.map +1 -0
- package/index.d.ts +22 -0
- package/index.js +226 -0
- package/index.js.map +1 -0
- package/package.json +32 -0
- package/types.d.ts +15 -0
- package/types.js +7 -0
- package/types.js.map +1 -0
- package/utils/clearNodeFormating.d.ts +2 -0
- package/utils/clearNodeFormating.js +30 -0
- package/utils/clearNodeFormating.js.map +1 -0
- package/utils/formatList.d.ts +19 -0
- package/utils/formatList.js +449 -0
- package/utils/formatList.js.map +1 -0
- package/utils/formatToHeading.d.ts +3 -0
- package/utils/formatToHeading.js +27 -0
- package/utils/formatToHeading.js.map +1 -0
- package/utils/formatToParagraph.d.ts +2 -0
- package/utils/formatToParagraph.js +22 -0
- package/utils/formatToParagraph.js.map +1 -0
- package/utils/formatToQuote.d.ts +2 -0
- package/utils/formatToQuote.js +27 -0
- package/utils/formatToQuote.js.map +1 -0
- package/utils/listNode.d.ts +11 -0
- package/utils/listNode.js +109 -0
- package/utils/listNode.js.map +1 -0
package/QuoteNode.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.$createQuoteNode = $createQuoteNode;
|
|
8
|
+
exports.$isQuoteNode = $isQuoteNode;
|
|
9
|
+
exports.QuoteNode = void 0;
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
16
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
18
|
+
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
20
|
+
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
21
|
+
var _utils = require("@lexical/utils");
|
|
22
|
+
var _richText = require("@lexical/rich-text");
|
|
23
|
+
var QuoteNode = /*#__PURE__*/function (_BaseQuoteNode) {
|
|
24
|
+
(0, _inherits2.default)(QuoteNode, _BaseQuoteNode);
|
|
25
|
+
var _super = (0, _createSuper2.default)(QuoteNode);
|
|
26
|
+
function QuoteNode(themeStyleId, key) {
|
|
27
|
+
var _this;
|
|
28
|
+
(0, _classCallCheck2.default)(this, QuoteNode);
|
|
29
|
+
_this = _super.call(this, key);
|
|
30
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "__styles", []);
|
|
31
|
+
if (themeStyleId) {
|
|
32
|
+
_this.__styles.push({
|
|
33
|
+
styleId: themeStyleId,
|
|
34
|
+
type: "typography"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Find the first occurrence of the quoteblock in the theme styles and set as default.
|
|
42
|
+
*/
|
|
43
|
+
(0, _createClass2.default)(QuoteNode, [{
|
|
44
|
+
key: "setDefaultTypography",
|
|
45
|
+
value: function setDefaultTypography(themeEmotionMap) {
|
|
46
|
+
var typographyStyle = (0, _lexicalTheme.findTypographyStyleByHtmlTag)("quoteblock", themeEmotionMap);
|
|
47
|
+
if (typographyStyle) {
|
|
48
|
+
this.__styles.push({
|
|
49
|
+
styleId: typographyStyle.id,
|
|
50
|
+
type: "typography"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "typographyStyleExist",
|
|
56
|
+
value: function typographyStyleExist(themeEmotionMap) {
|
|
57
|
+
var styleId = this.getTypographyStyleId();
|
|
58
|
+
if (!styleId) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
var style = themeEmotionMap[styleId];
|
|
62
|
+
return !!style;
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: "setTypography",
|
|
66
|
+
value: function setTypography(typographyStyleId) {
|
|
67
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(QuoteNode.prototype), "getWritable", this).call(this);
|
|
68
|
+
if (!typographyStyleId) {
|
|
69
|
+
return self;
|
|
70
|
+
}
|
|
71
|
+
if (!this.hasTypographyStyle()) {
|
|
72
|
+
var themeStyle = {
|
|
73
|
+
styleId: typographyStyleId,
|
|
74
|
+
type: "typography"
|
|
75
|
+
};
|
|
76
|
+
self.__styles.push(themeStyle);
|
|
77
|
+
}
|
|
78
|
+
return self;
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "getTypographyStyleId",
|
|
82
|
+
value: function getTypographyStyleId() {
|
|
83
|
+
var style = this.__styles.find(function (x) {
|
|
84
|
+
return x.type === "typography";
|
|
85
|
+
});
|
|
86
|
+
return (style === null || style === void 0 ? void 0 : style.styleId) || undefined;
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
key: "clearTypographyStyle",
|
|
90
|
+
value: function clearTypographyStyle() {
|
|
91
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(QuoteNode.prototype), "getWritable", this).call(this);
|
|
92
|
+
self.__styles = self.__styles.filter(function (s) {
|
|
93
|
+
return s.type !== "typography";
|
|
94
|
+
});
|
|
95
|
+
return self;
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "hasTypographyStyle",
|
|
99
|
+
value: function hasTypographyStyle() {
|
|
100
|
+
return !!this.getTypographyStyleId();
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "getThemeStyles",
|
|
104
|
+
value: function getThemeStyles() {
|
|
105
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(QuoteNode.prototype), "getLatest", this).call(this);
|
|
106
|
+
return self.__styles;
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: "setThemeStyles",
|
|
110
|
+
value: function setThemeStyles(styles) {
|
|
111
|
+
var self = (0, _get2.default)((0, _getPrototypeOf2.default)(QuoteNode.prototype), "getWritable", this).call(this);
|
|
112
|
+
self.__styles = (0, _toConsumableArray2.default)(styles);
|
|
113
|
+
return self;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "addThemeStylesToHTMLElement",
|
|
117
|
+
value: function addThemeStylesToHTMLElement(element, theme) {
|
|
118
|
+
var themeEmotionMap = theme === null || theme === void 0 ? void 0 : theme.emotionMap;
|
|
119
|
+
if (!themeEmotionMap) {
|
|
120
|
+
return element;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// style exist and is in active use
|
|
124
|
+
if (this.hasTypographyStyle() && this.typographyStyleExist(themeEmotionMap)) {
|
|
125
|
+
var styleId = this.getTypographyStyleId();
|
|
126
|
+
if (styleId) {
|
|
127
|
+
var typographyValue = themeEmotionMap[styleId];
|
|
128
|
+
(0, _utils.addClassNamesToElement)(element, typographyValue === null || typographyValue === void 0 ? void 0 : typographyValue.className);
|
|
129
|
+
return element;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return element;
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "createDOM",
|
|
136
|
+
value: function createDOM(config) {
|
|
137
|
+
var element = (0, _get2.default)((0, _getPrototypeOf2.default)(QuoteNode.prototype), "createDOM", this).call(this, config);
|
|
138
|
+
var wTheme = config.theme;
|
|
139
|
+
var emotionThemeMap = wTheme === null || wTheme === void 0 ? void 0 : wTheme.emotionMap;
|
|
140
|
+
if (!emotionThemeMap) {
|
|
141
|
+
return element;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// if styleId is not set or user removed the style from theme, set default style
|
|
145
|
+
if (!this.hasTypographyStyle() || !this.typographyStyleExist(emotionThemeMap)) {
|
|
146
|
+
this.setDefaultTypography(emotionThemeMap);
|
|
147
|
+
}
|
|
148
|
+
this.addThemeStylesToHTMLElement(element, config.theme);
|
|
149
|
+
return element;
|
|
150
|
+
}
|
|
151
|
+
}, {
|
|
152
|
+
key: "exportJSON",
|
|
153
|
+
value: function exportJSON() {
|
|
154
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(QuoteNode.prototype), "exportJSON", this).call(this)), {}, {
|
|
155
|
+
type: "webiny-quote",
|
|
156
|
+
styles: this.__styles,
|
|
157
|
+
styleId: this.getTypographyStyleId()
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}], [{
|
|
161
|
+
key: "getType",
|
|
162
|
+
value: function getType() {
|
|
163
|
+
return "webiny-quote";
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "clone",
|
|
167
|
+
value: function clone(node) {
|
|
168
|
+
return new QuoteNode(node.getTypographyStyleId(), node.__key);
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
key: "importDomConversionMap",
|
|
172
|
+
value: function importDomConversionMap() {
|
|
173
|
+
return {
|
|
174
|
+
conversion: convertBlockquoteElement,
|
|
175
|
+
priority: 0
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "importDOM",
|
|
180
|
+
value: function importDOM() {
|
|
181
|
+
var _this2 = this;
|
|
182
|
+
return {
|
|
183
|
+
blockquote: function blockquote() {
|
|
184
|
+
return _this2.importDomConversionMap();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}, {
|
|
189
|
+
key: "importJSON",
|
|
190
|
+
value: function importJSON(serializedNode) {
|
|
191
|
+
var _serializedNode$style;
|
|
192
|
+
var node = $createQuoteNode();
|
|
193
|
+
node.setFormat(serializedNode.format);
|
|
194
|
+
node.setIndent(serializedNode.indent);
|
|
195
|
+
node.setDirection(serializedNode.direction);
|
|
196
|
+
if (!!(serializedNode !== null && serializedNode !== void 0 && (_serializedNode$style = serializedNode.styles) !== null && _serializedNode$style !== void 0 && _serializedNode$style.length)) {
|
|
197
|
+
node.setThemeStyles(serializedNode.styles);
|
|
198
|
+
return node;
|
|
199
|
+
}
|
|
200
|
+
// for old nodes data migrate the style id into the list
|
|
201
|
+
if (!!(serializedNode !== null && serializedNode !== void 0 && serializedNode.styleId)) {
|
|
202
|
+
var styles = [{
|
|
203
|
+
styleId: serializedNode.styleId,
|
|
204
|
+
type: "typography"
|
|
205
|
+
}];
|
|
206
|
+
node.setThemeStyles(styles);
|
|
207
|
+
}
|
|
208
|
+
return node;
|
|
209
|
+
}
|
|
210
|
+
}]);
|
|
211
|
+
return QuoteNode;
|
|
212
|
+
}(_richText.QuoteNode);
|
|
213
|
+
exports.QuoteNode = QuoteNode;
|
|
214
|
+
function convertBlockquoteElement() {
|
|
215
|
+
var node = $createQuoteNode();
|
|
216
|
+
return {
|
|
217
|
+
node: node
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function $createQuoteNode(themeStyleId, key) {
|
|
221
|
+
return new QuoteNode(themeStyleId, key);
|
|
222
|
+
}
|
|
223
|
+
function $isQuoteNode(node) {
|
|
224
|
+
return node instanceof QuoteNode;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=QuoteNode.js.map
|
package/QuoteNode.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lexicalTheme","require","_utils","_richText","QuoteNode","_BaseQuoteNode","_inherits2","default","_super","_createSuper2","themeStyleId","key","_this","_classCallCheck2","call","_defineProperty2","_assertThisInitialized2","__styles","push","styleId","type","_createClass2","value","setDefaultTypography","themeEmotionMap","typographyStyle","findTypographyStyleByHtmlTag","id","typographyStyleExist","getTypographyStyleId","style","setTypography","typographyStyleId","self","_get2","_getPrototypeOf2","prototype","hasTypographyStyle","themeStyle","find","x","undefined","clearTypographyStyle","filter","s","getThemeStyles","setThemeStyles","styles","_toConsumableArray2","addThemeStylesToHTMLElement","element","theme","emotionMap","typographyValue","addClassNamesToElement","className","createDOM","config","wTheme","emotionThemeMap","exportJSON","_objectSpread2","getType","clone","node","__key","importDomConversionMap","conversion","convertBlockquoteElement","priority","importDOM","_this2","blockquote","importJSON","serializedNode","_serializedNode$style","$createQuoteNode","setFormat","format","setIndent","indent","setDirection","direction","length","BaseQuoteNode","exports","$isQuoteNode"],"sources":["QuoteNode.ts"],"sourcesContent":["import {\n DOMConversion,\n DOMConversionMap,\n EditorConfig,\n LexicalNode,\n NodeKey,\n Spread\n} from \"lexical\";\nimport {\n EditorTheme,\n ThemeEmotionMap,\n WebinyTheme,\n findTypographyStyleByHtmlTag\n} from \"@webiny/lexical-theme\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport {\n QuoteNode as BaseQuoteNode,\n SerializedQuoteNode as BaseSerializedQuoteNode\n} from \"@lexical/rich-text\";\nimport { TextNodeThemeStyles, ThemeStyleValue, TypographyStylesNode } from \"~/types\";\n\nexport type SerializedQuoteNode = Spread<\n {\n styleId?: string;\n styles: ThemeStyleValue[];\n type: \"webiny-quote\";\n },\n BaseSerializedQuoteNode\n>;\n\nexport class QuoteNode extends BaseQuoteNode implements TextNodeThemeStyles, TypographyStylesNode {\n __styles: ThemeStyleValue[] = [];\n\n constructor(themeStyleId?: string, key?: NodeKey) {\n super(key);\n if (themeStyleId) {\n this.__styles.push({ styleId: themeStyleId, type: \"typography\" });\n }\n }\n\n /*\n * Find the first occurrence of the quoteblock in the theme styles and set as default.\n */\n protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap) {\n const typographyStyle = findTypographyStyleByHtmlTag(\"quoteblock\", themeEmotionMap);\n if (typographyStyle) {\n this.__styles.push({ styleId: typographyStyle.id, type: \"typography\" });\n }\n }\n\n protected typographyStyleExist(themeEmotionMap: ThemeEmotionMap): boolean {\n const styleId = this.getTypographyStyleId();\n if (!styleId) {\n return false;\n }\n const style = themeEmotionMap[styleId];\n return !!style;\n }\n\n setTypography(typographyStyleId: string): this {\n const self = super.getWritable();\n if (!typographyStyleId) {\n return self;\n }\n\n if (!this.hasTypographyStyle()) {\n const themeStyle = {\n styleId: typographyStyleId,\n type: \"typography\"\n } as ThemeStyleValue;\n self.__styles.push(themeStyle);\n }\n return self;\n }\n\n getTypographyStyleId(): string | undefined {\n const style = this.__styles.find(x => x.type === \"typography\");\n return style?.styleId || undefined;\n }\n\n clearTypographyStyle(): this {\n const self = super.getWritable();\n self.__styles = self.__styles.filter(s => s.type !== \"typography\");\n return self;\n }\n\n hasTypographyStyle(): boolean {\n return !!this.getTypographyStyleId();\n }\n\n getThemeStyles(): ThemeStyleValue[] {\n const self = super.getLatest();\n return self.__styles;\n }\n\n setThemeStyles(styles: ThemeStyleValue[]) {\n const self = super.getWritable();\n self.__styles = [...styles];\n return self;\n }\n\n static override getType(): string {\n return \"webiny-quote\";\n }\n\n static override clone(node: QuoteNode): QuoteNode {\n return new QuoteNode(node.getTypographyStyleId(), node.__key);\n }\n\n addThemeStylesToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n const themeEmotionMap = theme?.emotionMap;\n\n if (!themeEmotionMap) {\n return element;\n }\n\n // style exist and is in active use\n if (this.hasTypographyStyle() && this.typographyStyleExist(themeEmotionMap)) {\n const styleId = this.getTypographyStyleId();\n if (styleId) {\n const typographyValue = themeEmotionMap[styleId];\n addClassNamesToElement(element, typographyValue?.className);\n return element;\n }\n }\n\n return element;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n const wTheme = config.theme as WebinyTheme;\n const emotionThemeMap = wTheme?.emotionMap;\n\n if (!emotionThemeMap) {\n return element;\n }\n\n // if styleId is not set or user removed the style from theme, set default style\n if (!this.hasTypographyStyle() || !this.typographyStyleExist(emotionThemeMap)) {\n this.setDefaultTypography(emotionThemeMap);\n }\n\n this.addThemeStylesToHTMLElement(element, config.theme);\n return element;\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertBlockquoteElement,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n blockquote: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n static override importJSON(serializedNode: SerializedQuoteNode): QuoteNode {\n const node = $createQuoteNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n if (!!serializedNode?.styles?.length) {\n node.setThemeStyles(serializedNode.styles);\n return node;\n }\n // for old nodes data migrate the style id into the list\n if (!!serializedNode?.styleId) {\n const styles = [\n { styleId: serializedNode.styleId, type: \"typography\" }\n ] as ThemeStyleValue[];\n node.setThemeStyles(styles);\n }\n return node;\n }\n\n override exportJSON(): SerializedQuoteNode {\n return {\n ...super.exportJSON(),\n type: \"webiny-quote\",\n styles: this.__styles,\n styleId: this.getTypographyStyleId()\n };\n }\n}\n\nfunction convertBlockquoteElement() {\n const node = $createQuoteNode();\n return {\n node\n };\n}\n\nexport function $createQuoteNode(themeStyleId?: string, key?: NodeKey): QuoteNode {\n return new QuoteNode(themeStyleId, key);\n}\n\nexport function $isQuoteNode(node: LexicalNode | null | undefined): node is QuoteNode {\n return node instanceof QuoteNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA,IAAAA,aAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAG4B,IAYfG,SAAS,0BAAAC,cAAA;EAAA,IAAAC,UAAA,CAAAC,OAAA,EAAAH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O,SAASY,gBAAgBA,CAAClE,YAAqB,EAAEC,GAAa,EAAa;EAC9E,OAAO,IAAIP,SAAS,CAACM,YAAY,EAAEC,GAAG,CAAC;AAC3C;AAEO,SAAS2E,YAAYA,CAACtB,IAAoC,EAAqB;EAClF,OAAOA,IAAI,YAAY5D,SAAS;AACpC"}
|
package/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# @webiny/lexical-nodes
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/llexical-lexical-nodes)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/lexical-nodes)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/// <reference types="web" />
|
|
3
|
+
import { EditorConfig, ElementNode, LexicalCommand, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from "lexical";
|
|
4
|
+
import { EditorTheme, TypographyHTMLTag, TypographyValue } from "@webiny/lexical-theme";
|
|
5
|
+
export declare const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload>;
|
|
6
|
+
export interface TypographyPayload {
|
|
7
|
+
value: TypographyValue;
|
|
8
|
+
caption?: LexicalEditor;
|
|
9
|
+
key?: NodeKey;
|
|
10
|
+
}
|
|
11
|
+
export declare type SerializedTypographyNode = Spread<{
|
|
12
|
+
tag: TypographyHTMLTag;
|
|
13
|
+
styleId: string;
|
|
14
|
+
name: string;
|
|
15
|
+
typographyStyles: Record<string, any>;
|
|
16
|
+
type: "typography-el-node";
|
|
17
|
+
version: 1;
|
|
18
|
+
}, SerializedElementNode>;
|
|
19
|
+
/**
|
|
20
|
+
* Main responsibility of this node is to apply custom or Webiny theme typography to selected text.
|
|
21
|
+
* Extends the original ElementNode node to add additional transformation and support for webiny theme typography.
|
|
22
|
+
*/
|
|
23
|
+
export declare class TypographyNode extends ElementNode {
|
|
24
|
+
__styleId: string;
|
|
25
|
+
__tag: TypographyHTMLTag;
|
|
26
|
+
__name: string;
|
|
27
|
+
__css: Record<string, any>;
|
|
28
|
+
constructor(value: TypographyValue, key?: NodeKey);
|
|
29
|
+
static getType(): string;
|
|
30
|
+
static clone(node: TypographyNode): TypographyNode;
|
|
31
|
+
getTypographyValue(): TypographyValue;
|
|
32
|
+
addStylesHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement;
|
|
33
|
+
exportJSON(): SerializedTypographyNode;
|
|
34
|
+
static importJSON(serializedNode: SerializedTypographyNode): TypographyNode;
|
|
35
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
36
|
+
updateDOM(): boolean;
|
|
37
|
+
insertNewAfter(): TypographyNode;
|
|
38
|
+
collapseAtStart(): true;
|
|
39
|
+
}
|
|
40
|
+
export declare const $createTypographyNode: (value: TypographyValue, key?: NodeKey) => TypographyNode;
|
|
41
|
+
export declare const $isTypographyNode: (node: ElementNode | LexicalNode | null) => node is TypographyNode;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TypographyNode = exports.ADD_TYPOGRAPHY_COMMAND = exports.$isTypographyNode = exports.$createTypographyNode = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
12
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
|
+
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
|
15
|
+
var _lexical = require("lexical");
|
|
16
|
+
var _utils = require("@lexical/utils");
|
|
17
|
+
var _ParagraphNode = require("./ParagraphNode");
|
|
18
|
+
// Command and payload
|
|
19
|
+
var ADD_TYPOGRAPHY_COMMAND = (0, _lexical.createCommand)("ADD_TYPOGRAPHY_COMMAND");
|
|
20
|
+
exports.ADD_TYPOGRAPHY_COMMAND = ADD_TYPOGRAPHY_COMMAND;
|
|
21
|
+
var TypographyNodeAttrName = "data-typography-style-id";
|
|
22
|
+
|
|
23
|
+
// Node
|
|
24
|
+
/**
|
|
25
|
+
* Main responsibility of this node is to apply custom or Webiny theme typography to selected text.
|
|
26
|
+
* Extends the original ElementNode node to add additional transformation and support for webiny theme typography.
|
|
27
|
+
*/
|
|
28
|
+
var TypographyNode = /*#__PURE__*/function (_ElementNode) {
|
|
29
|
+
(0, _inherits2.default)(TypographyNode, _ElementNode);
|
|
30
|
+
var _super = (0, _createSuper2.default)(TypographyNode);
|
|
31
|
+
function TypographyNode(value, key) {
|
|
32
|
+
var _this;
|
|
33
|
+
(0, _classCallCheck2.default)(this, TypographyNode);
|
|
34
|
+
_this = _super.call(this, key);
|
|
35
|
+
_this.__tag = value.tag;
|
|
36
|
+
_this.__styleId = value.id;
|
|
37
|
+
_this.__name = value.name;
|
|
38
|
+
_this.__css = value.css;
|
|
39
|
+
return _this;
|
|
40
|
+
}
|
|
41
|
+
(0, _createClass2.default)(TypographyNode, [{
|
|
42
|
+
key: "getTypographyValue",
|
|
43
|
+
value: function getTypographyValue() {
|
|
44
|
+
return {
|
|
45
|
+
tag: this.__tag,
|
|
46
|
+
css: this.__css,
|
|
47
|
+
id: this.__styleId,
|
|
48
|
+
name: this.__name
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "addStylesHTMLElement",
|
|
53
|
+
value: function addStylesHTMLElement(element, theme) {
|
|
54
|
+
var typographyStyleValue = theme !== null && theme !== void 0 && theme.emotionMap ? theme === null || theme === void 0 ? void 0 : theme.emotionMap[this.__styleId] : undefined;
|
|
55
|
+
if (typographyStyleValue) {
|
|
56
|
+
this.__css = typographyStyleValue.styles;
|
|
57
|
+
(0, _utils.addClassNamesToElement)(element, typographyStyleValue.className);
|
|
58
|
+
}
|
|
59
|
+
element.setAttribute(TypographyNodeAttrName, this.__styleId);
|
|
60
|
+
return element;
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "exportJSON",
|
|
64
|
+
value: function exportJSON() {
|
|
65
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(TypographyNode.prototype), "exportJSON", this).call(this)), {}, {
|
|
66
|
+
tag: this.__tag,
|
|
67
|
+
typographyStyles: this.__css,
|
|
68
|
+
name: this.__name,
|
|
69
|
+
styleId: this.__styleId,
|
|
70
|
+
type: "typography-el-node",
|
|
71
|
+
version: 1
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "createDOM",
|
|
76
|
+
value: function createDOM(config) {
|
|
77
|
+
var tag = this.__tag;
|
|
78
|
+
var element = document.createElement(tag);
|
|
79
|
+
return this.addStylesHTMLElement(element, config.theme);
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "updateDOM",
|
|
83
|
+
value: function updateDOM() {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "insertNewAfter",
|
|
88
|
+
value: function insertNewAfter() {
|
|
89
|
+
var newElement = $createTypographyNode({
|
|
90
|
+
tag: this.__tag,
|
|
91
|
+
name: this.__name,
|
|
92
|
+
css: this.__css,
|
|
93
|
+
id: this.__styleId
|
|
94
|
+
});
|
|
95
|
+
var direction = this.getDirection();
|
|
96
|
+
newElement.setDirection(direction);
|
|
97
|
+
this.insertAfter(newElement);
|
|
98
|
+
return newElement;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "collapseAtStart",
|
|
102
|
+
value: function collapseAtStart() {
|
|
103
|
+
var paragraph = (0, _ParagraphNode.$createParagraphNode)();
|
|
104
|
+
var children = this.getChildren();
|
|
105
|
+
children.forEach(function (child) {
|
|
106
|
+
return paragraph.append(child);
|
|
107
|
+
});
|
|
108
|
+
this.replace(paragraph);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}], [{
|
|
112
|
+
key: "getType",
|
|
113
|
+
value: function getType() {
|
|
114
|
+
return "typography-el-node";
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "clone",
|
|
118
|
+
value: function clone(node) {
|
|
119
|
+
return new TypographyNode({
|
|
120
|
+
css: node.__css,
|
|
121
|
+
id: node.__styleId,
|
|
122
|
+
name: node.__name,
|
|
123
|
+
tag: node.__tag
|
|
124
|
+
}, node.__key);
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "importJSON",
|
|
128
|
+
value: function importJSON(serializedNode) {
|
|
129
|
+
var node = new TypographyNode({
|
|
130
|
+
id: serializedNode.styleId,
|
|
131
|
+
css: serializedNode.typographyStyles,
|
|
132
|
+
tag: serializedNode.tag,
|
|
133
|
+
name: serializedNode.name
|
|
134
|
+
});
|
|
135
|
+
node.setFormat(serializedNode.format);
|
|
136
|
+
node.setIndent(serializedNode.indent);
|
|
137
|
+
node.setDirection(serializedNode.direction);
|
|
138
|
+
return node;
|
|
139
|
+
}
|
|
140
|
+
}]);
|
|
141
|
+
return TypographyNode;
|
|
142
|
+
}(_lexical.ElementNode);
|
|
143
|
+
exports.TypographyNode = TypographyNode;
|
|
144
|
+
var $createTypographyNode = function $createTypographyNode(value, key) {
|
|
145
|
+
return new TypographyNode(value, key);
|
|
146
|
+
};
|
|
147
|
+
exports.$createTypographyNode = $createTypographyNode;
|
|
148
|
+
var $isTypographyNode = function $isTypographyNode(node) {
|
|
149
|
+
return node instanceof TypographyNode;
|
|
150
|
+
};
|
|
151
|
+
exports.$isTypographyNode = $isTypographyNode;
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=TypographyNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lexical","require","_utils","_ParagraphNode","ADD_TYPOGRAPHY_COMMAND","createCommand","exports","TypographyNodeAttrName","TypographyNode","_ElementNode","_inherits2","default","_super","_createSuper2","value","key","_this","_classCallCheck2","call","__tag","tag","__styleId","id","__name","name","__css","css","_createClass2","getTypographyValue","addStylesHTMLElement","element","theme","typographyStyleValue","emotionMap","undefined","styles","addClassNamesToElement","className","setAttribute","exportJSON","_objectSpread2","_get2","_getPrototypeOf2","prototype","typographyStyles","styleId","type","version","createDOM","config","document","createElement","updateDOM","insertNewAfter","newElement","$createTypographyNode","direction","getDirection","setDirection","insertAfter","collapseAtStart","paragraph","$createParagraphNode","children","getChildren","forEach","child","append","replace","getType","clone","node","__key","importJSON","serializedNode","setFormat","format","setIndent","indent","ElementNode","$isTypographyNode"],"sources":["TypographyNode.ts"],"sourcesContent":["import {\n createCommand,\n EditorConfig,\n ElementNode,\n LexicalCommand,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport { EditorTheme, TypographyHTMLTag, TypographyValue } from \"@webiny/lexical-theme\";\nimport { $createParagraphNode } from \"~/ParagraphNode\";\n\n// Command and payload\nexport const ADD_TYPOGRAPHY_COMMAND: LexicalCommand<TypographyPayload> =\n createCommand(\"ADD_TYPOGRAPHY_COMMAND\");\n\nconst TypographyNodeAttrName = \"data-typography-style-id\";\n\nexport interface TypographyPayload {\n value: TypographyValue;\n caption?: LexicalEditor;\n key?: NodeKey;\n}\n\n// Node\nexport type SerializedTypographyNode = Spread<\n {\n tag: TypographyHTMLTag;\n styleId: string;\n name: string;\n typographyStyles: Record<string, any>;\n type: \"typography-el-node\";\n version: 1;\n },\n SerializedElementNode\n>;\n\n/**\n * Main responsibility of this node is to apply custom or Webiny theme typography to selected text.\n * Extends the original ElementNode node to add additional transformation and support for webiny theme typography.\n */\nexport class TypographyNode extends ElementNode {\n __styleId: string;\n __tag: TypographyHTMLTag;\n __name: string;\n __css: Record<string, any>;\n\n constructor(value: TypographyValue, key?: NodeKey) {\n super(key);\n this.__tag = value.tag;\n this.__styleId = value.id;\n this.__name = value.name;\n this.__css = value.css;\n }\n\n static override getType(): string {\n return \"typography-el-node\";\n }\n\n static override clone(node: TypographyNode): TypographyNode {\n return new TypographyNode(\n {\n css: node.__css,\n id: node.__styleId,\n name: node.__name,\n tag: node.__tag\n },\n node.__key\n );\n }\n getTypographyValue(): TypographyValue {\n return {\n tag: this.__tag,\n css: this.__css,\n id: this.__styleId,\n name: this.__name\n };\n }\n\n addStylesHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n const typographyStyleValue = theme?.emotionMap\n ? theme?.emotionMap[this.__styleId]\n : undefined;\n if (typographyStyleValue) {\n this.__css = typographyStyleValue.styles;\n addClassNamesToElement(element, typographyStyleValue.className);\n }\n element.setAttribute(TypographyNodeAttrName, this.__styleId);\n\n return element;\n }\n\n override exportJSON(): SerializedTypographyNode {\n return {\n ...super.exportJSON(),\n tag: this.__tag,\n typographyStyles: this.__css,\n name: this.__name,\n styleId: this.__styleId,\n type: \"typography-el-node\",\n version: 1\n };\n }\n\n static override importJSON(serializedNode: SerializedTypographyNode): TypographyNode {\n const node = new TypographyNode({\n id: serializedNode.styleId,\n css: serializedNode.typographyStyles,\n tag: serializedNode.tag,\n name: serializedNode.name\n });\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n return node;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const tag = this.__tag;\n const element = document.createElement(tag);\n return this.addStylesHTMLElement(element, config.theme);\n }\n\n override updateDOM(): boolean {\n return false;\n }\n\n override insertNewAfter(): TypographyNode {\n const newElement = $createTypographyNode({\n tag: this.__tag,\n name: this.__name,\n css: this.__css,\n id: this.__styleId\n });\n const direction = this.getDirection();\n newElement.setDirection(direction);\n this.insertAfter(newElement);\n return newElement;\n }\n\n override collapseAtStart(): true {\n const paragraph = $createParagraphNode();\n const children = this.getChildren();\n children.forEach(child => paragraph.append(child));\n this.replace(paragraph);\n return true;\n }\n}\n\nexport const $createTypographyNode = (value: TypographyValue, key?: NodeKey): TypographyNode => {\n return new TypographyNode(value, key);\n};\n\nexport const $isTypographyNode = (\n node: ElementNode | LexicalNode | null\n): node is TypographyNode => {\n return node instanceof TypographyNode;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAWA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAEA;AACO,IAAMG,sBAAyD,GAClE,IAAAC,sBAAa,EAAC,wBAAwB,CAAC;AAACC,OAAA,CAAAF,sBAAA,GAAAA,sBAAA;AAE5C,IAAMG,sBAAsB,GAAG,0BAA0B;;AAQzD;AAaA;AACA;AACA;AACA;AAHA,IAIaC,cAAc,0BAAAC,YAAA;EAAA,IAAAC,UAAA,CAAAC,OAAA,EAAAH,cAAA,EAAAC,YAAA;EAAA,IAAAG,MAAA,OAAAC,aAAA,CAAAF,OAAA,EAAAH,cAAA;EAMvB,SAAAA,eAAYM,KAAsB,EAAEC,GAAa,EAAE;IAAA,IAAAC,KAAA;IAAA,IAAAC,gBAAA,CAAAN,OAAA,QAAAH,cAAA;IAC/CQ,KAAA,GAAAJ,MAAA,CAAAM,IAAA,OAAMH,GAAG;IACTC,KAAA,CAAKG,KAAK,GAAGL,KAAK,CAACM,GAAG;IACtBJ,KAAA,CAAKK,SAAS,GAAGP,KAAK,CAACQ,EAAE;IACzBN,KAAA,CAAKO,MAAM,GAAGT,KAAK,CAACU,IAAI;IACxBR,KAAA,CAAKS,KAAK,GAAGX,KAAK,C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GAAAA,iBAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
.ContentEditable__root {
|
|
10
|
+
border: 0;
|
|
11
|
+
font-size: 15px;
|
|
12
|
+
display: block;
|
|
13
|
+
position: relative;
|
|
14
|
+
outline: 0;
|
|
15
|
+
padding: 8px 28px 40px;
|
|
16
|
+
}
|
|
17
|
+
@media (max-width: 1025px) {
|
|
18
|
+
.ContentEditable__root {
|
|
19
|
+
padding-left: 8px;
|
|
20
|
+
padding-right: 8px;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import "./ContentEditable.css";
|
|
10
|
+
export declare function LexicalContentEditable({ className }: {
|
|
11
|
+
className?: string;
|
|
12
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LexicalContentEditable = LexicalContentEditable;
|
|
8
|
+
require("./ContentEditable.css");
|
|
9
|
+
var _LexicalContentEditable = require("@lexical/react/LexicalContentEditable");
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
/**
|
|
12
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the MIT license found in the
|
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function LexicalContentEditable(_ref) {
|
|
20
|
+
var className = _ref.className;
|
|
21
|
+
return /*#__PURE__*/React.createElement(_LexicalContentEditable.ContentEditable, {
|
|
22
|
+
className: className || "ContentEditable__root"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=ContentEditable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["require","_LexicalContentEditable","React","_interopRequireWildcard","LexicalContentEditable","_ref","className","createElement","ContentEditable"],"sources":["ContentEditable.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 */\nimport \"./ContentEditable.css\";\n\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport * as React from \"react\";\n\nexport function LexicalContentEditable({ className }: { className?: string }): JSX.Element {\n return <ContentEditable className={className || \"ContentEditable__root\"} />;\n}\n"],"mappings":";;;;;;;AAOAA,OAAA;AAEA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,uBAAA,CAAAH,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMO,SAASI,sBAAsBA,CAAAC,IAAA,EAAqD;EAAA,IAAlDC,SAAS,GAAAD,IAAA,CAATC,SAAS;EAC9C,oBAAOJ,KAAA,CAAAK,aAAA,CAACN,uBAAA,CAAAO,eAAe;IAACF,SAAS,EAAEA,SAAS,IAAI;EAAwB,CAAE,CAAC;AAC/E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
.ImageNode__contentEditable {
|
|
11
|
+
min-height: 20px;
|
|
12
|
+
border: 0px;
|
|
13
|
+
resize: none;
|
|
14
|
+
cursor: text;
|
|
15
|
+
caret-color: rgb(5, 5, 5);
|
|
16
|
+
display: block;
|
|
17
|
+
position: relative;
|
|
18
|
+
outline: 0px;
|
|
19
|
+
padding: 10px;
|
|
20
|
+
user-select: text;
|
|
21
|
+
font-size: 12px;
|
|
22
|
+
width: calc(100% - 20px);
|
|
23
|
+
white-space: pre-wrap;
|
|
24
|
+
word-break: break-word;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ImageNode__placeholder {
|
|
28
|
+
font-size: 12px;
|
|
29
|
+
color: #888;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
position: absolute;
|
|
32
|
+
text-overflow: ellipsis;
|
|
33
|
+
top: 10px;
|
|
34
|
+
left: 10px;
|
|
35
|
+
user-select: none;
|
|
36
|
+
white-space: nowrap;
|
|
37
|
+
display: inline-block;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.image-control-wrapper--resizing {
|
|
42
|
+
touch-action: none;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LexicalEditor, NodeKey } from "lexical";
|
|
3
|
+
import "./ImageComponent.css";
|
|
4
|
+
export default function ImageComponent({ id, src, altText, nodeKey, width, height, maxWidth, resizable, showCaption, caption, captionsEnabled }: {
|
|
5
|
+
id: string;
|
|
6
|
+
altText: string;
|
|
7
|
+
caption: LexicalEditor;
|
|
8
|
+
height: "inherit" | number;
|
|
9
|
+
maxWidth: number;
|
|
10
|
+
nodeKey: NodeKey;
|
|
11
|
+
resizable: boolean;
|
|
12
|
+
showCaption: boolean;
|
|
13
|
+
src: string;
|
|
14
|
+
width: "inherit" | number;
|
|
15
|
+
captionsEnabled: boolean;
|
|
16
|
+
}): JSX.Element;
|