@thangph2146/lexical-editor 0.0.4 → 0.0.6
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/README.md +47 -0
- package/dist/editor-x/editor.cjs +732 -443
- package/dist/editor-x/editor.cjs.map +1 -1
- package/dist/editor-x/editor.css +1418 -1120
- package/dist/editor-x/editor.css.map +1 -1
- package/dist/editor-x/editor.d.cts +2 -1
- package/dist/editor-x/editor.d.ts +2 -1
- package/dist/editor-x/editor.js +736 -447
- package/dist/editor-x/editor.js.map +1 -1
- package/dist/index.cjs +772 -482
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1418 -1120
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +775 -485
- package/dist/index.js.map +1 -1
- package/package.json +86 -84
- package/src/components/lexical-editor.tsx +140 -123
- package/src/editor-x/editor.tsx +20 -5
- package/src/editor-x/plugins.tsx +385 -380
- package/src/nodes/list-with-color-node.tsx +160 -160
- package/src/plugins/autocomplete-plugin.tsx +2574 -2574
- package/src/plugins/context-menu-plugin.tsx +239 -9
- package/src/plugins/floating-text-format-plugin.tsx +84 -92
- package/src/plugins/images-plugin.tsx +4 -4
- package/src/plugins/list-color-plugin.tsx +178 -178
- package/src/plugins/tab-focus-plugin.tsx +66 -66
- package/src/plugins/table-column-resizer-plugin.tsx +329 -190
- package/src/plugins/toolbar/block-format/block-format-data.tsx +4 -0
- package/src/plugins/toolbar/block-format/format-bulleted-list.tsx +40 -40
- package/src/plugins/toolbar/block-format/format-list-with-marker.tsx +74 -74
- package/src/plugins/toolbar/block-format/format-numbered-list.tsx +40 -40
- package/src/plugins/toolbar/block-format-toolbar-plugin.tsx +118 -117
- package/src/plugins/toolbar/element-format-toolbar-plugin.tsx +37 -53
- package/src/plugins/toolbar/font-format-toolbar-plugin.tsx +8 -15
- package/src/plugins/toolbar/font-size-toolbar-plugin.tsx +2 -3
- package/src/plugins/toolbar/history-toolbar-plugin.tsx +2 -5
- package/src/plugins/toolbar/subsuper-toolbar-plugin.tsx +15 -23
- package/src/themes/_mixins.scss +158 -10
- package/src/themes/_variables.scss +168 -0
- package/src/themes/core/_code.scss +59 -0
- package/src/themes/core/_images.scss +80 -0
- package/src/themes/core/_lists.scss +214 -0
- package/src/themes/core/_misc.scss +46 -0
- package/src/themes/core/_reset.scss +119 -0
- package/src/themes/core/_tables.scss +145 -0
- package/src/themes/core/_text.scss +35 -0
- package/src/themes/core/_typography.scss +73 -0
- package/src/themes/editor-theme.scss +9 -623
- package/src/themes/editor-theme.ts +118 -118
- package/src/themes/plugins/_auto-embed.scss +11 -0
- package/src/themes/plugins/_color-picker.scss +103 -0
- package/src/themes/plugins/_draggable-block.scss +32 -0
- package/src/themes/plugins/_floating-link-editor.scss +47 -0
- package/src/themes/plugins/_floating-toolbars.scss +61 -0
- package/src/themes/plugins/_image-resizer.scss +38 -0
- package/src/themes/plugins/_image.scss +57 -0
- package/src/themes/plugins/_layout.scss +39 -0
- package/src/themes/plugins/_list-color.scss +23 -0
- package/src/themes/plugins/_mentions.scss +21 -0
- package/src/themes/plugins/_menus-and-pickers.scss +153 -0
- package/src/themes/plugins/_table.scss +20 -0
- package/src/themes/plugins/_toolbar.scss +36 -0
- package/src/themes/plugins/_tree-view.scss +11 -0
- package/src/themes/plugins.scss +20 -1165
- package/src/themes/ui-components/_animations.scss +31 -0
- package/src/themes/ui-components/_backgrounds.scss +27 -0
- package/src/themes/ui-components/_borders.scss +20 -0
- package/src/themes/ui-components/_button.scss +176 -0
- package/src/themes/ui-components/_checkbox.scss +14 -0
- package/src/themes/ui-components/_cursors.scss +31 -0
- package/src/themes/ui-components/_dialog.scss +86 -0
- package/src/themes/ui-components/_display-sizing.scss +100 -0
- package/src/themes/ui-components/_flex.scss +124 -0
- package/src/themes/ui-components/_form-layout.scss +15 -0
- package/src/themes/ui-components/_icons.scss +23 -0
- package/src/themes/ui-components/_input.scss +86 -0
- package/src/themes/ui-components/_label.scss +19 -0
- package/src/themes/ui-components/_loader.scss +9 -0
- package/src/themes/ui-components/_margins-paddings.scss +45 -0
- package/src/themes/ui-components/_popover.scss +16 -0
- package/src/themes/ui-components/_positioning.scss +73 -0
- package/src/themes/ui-components/_rounded.scss +19 -0
- package/src/themes/ui-components/_scroll-area.scss +11 -0
- package/src/themes/ui-components/_select.scss +110 -0
- package/src/themes/ui-components/_separator.scss +19 -0
- package/src/themes/ui-components/_shadow.scss +15 -0
- package/src/themes/ui-components/_tabs.scss +46 -0
- package/src/themes/ui-components/_text-utilities.scss +48 -0
- package/src/themes/ui-components/_toggle-toolbar.scss +128 -0
- package/src/themes/ui-components/_toggle.scss +80 -0
- package/src/themes/ui-components/_typography.scss +22 -0
- package/src/themes/ui-components.scss +27 -937
- package/src/transformers/markdown-list-transformer.ts +51 -51
- package/src/ui/button.tsx +11 -2
- package/src/ui/collapsible.tsx +1 -1
- package/src/ui/dialog.tsx +2 -2
- package/src/ui/flex.tsx +4 -4
- package/src/ui/popover.tsx +1 -1
- package/src/ui/tooltip.tsx +2 -2
|
@@ -1,160 +1,160 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import type { DOMExportOutput, EditorConfig, LexicalEditor } from "lexical"
|
|
4
|
-
import {
|
|
5
|
-
ListNode,
|
|
6
|
-
type ListType,
|
|
7
|
-
type SerializedListNode,
|
|
8
|
-
} from "@lexical/list"
|
|
9
|
-
import type { LexicalNode, LexicalUpdateJSON, NodeKey } from "lexical"
|
|
10
|
-
import { $applyNodeReplacement } from "lexical"
|
|
11
|
-
|
|
12
|
-
export type SerializedListWithColorNode = Omit<SerializedListNode, "type"> & {
|
|
13
|
-
type: "listwithcolor"
|
|
14
|
-
listColor?: string
|
|
15
|
-
markerType?: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const LIST_WITH_COLOR_TYPE = "listwithcolor"
|
|
19
|
-
|
|
20
|
-
function applyListAttributesToDom(dom: HTMLElement, color?: string, markerType?: string): void {
|
|
21
|
-
if (color) {
|
|
22
|
-
dom.style.setProperty("--list-marker-color", color, "important")
|
|
23
|
-
dom.setAttribute("data-list-color", color)
|
|
24
|
-
} else {
|
|
25
|
-
dom.style.removeProperty("--list-marker-color")
|
|
26
|
-
dom.removeAttribute("data-list-color")
|
|
27
|
-
}
|
|
28
|
-
if (markerType) {
|
|
29
|
-
dom.setAttribute("data-list-marker", markerType)
|
|
30
|
-
} else {
|
|
31
|
-
dom.removeAttribute("data-list-marker")
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class ListWithColorNode extends ListNode {
|
|
36
|
-
__listColor?: string
|
|
37
|
-
__markerType?: string
|
|
38
|
-
|
|
39
|
-
constructor(listType?: ListType, start?: number, key?: NodeKey) {
|
|
40
|
-
super(listType, start, key)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static getType(): "listwithcolor" {
|
|
44
|
-
return LIST_WITH_COLOR_TYPE
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
override getType(): "listwithcolor" {
|
|
48
|
-
return LIST_WITH_COLOR_TYPE
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static override clone(node: ListWithColorNode, key?: NodeKey): ListWithColorNode {
|
|
52
|
-
const listType = node.getListType()
|
|
53
|
-
const start = node.getStart()
|
|
54
|
-
const sameKey = key ?? node.getKey()
|
|
55
|
-
const cloned = new ListWithColorNode(listType, start, sameKey)
|
|
56
|
-
if (node.__listColor) cloned.__listColor = node.__listColor
|
|
57
|
-
if (node.__markerType) cloned.__markerType = node.__markerType
|
|
58
|
-
return cloned
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static override importJSON(
|
|
62
|
-
serializedNode: SerializedListWithColorNode
|
|
63
|
-
): ListWithColorNode {
|
|
64
|
-
const { listType, start, listColor, markerType } = serializedNode
|
|
65
|
-
const node = new ListWithColorNode(listType, start)
|
|
66
|
-
if (listColor != null) node.__listColor = listColor
|
|
67
|
-
if (markerType != null) node.__markerType = markerType
|
|
68
|
-
return node
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
override afterCloneFrom(prevNode: ListWithColorNode): void {
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lexical ListNode.afterCloneFrom(prevNode: this) không chấp nhận subtype
|
|
73
|
-
super.afterCloneFrom(prevNode as any)
|
|
74
|
-
this.__listColor = prevNode.__listColor
|
|
75
|
-
this.__markerType = prevNode.__markerType
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getListColor(): string | undefined {
|
|
79
|
-
return this.getLatest().__listColor
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
setListColor(color: string | undefined): this {
|
|
83
|
-
const writable = this.getWritable()
|
|
84
|
-
writable.__listColor = color
|
|
85
|
-
return this
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getMarkerType(): string | undefined {
|
|
89
|
-
return this.getLatest().__markerType
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
setMarkerType(markerType: string | undefined): this {
|
|
93
|
-
const writable = this.getWritable()
|
|
94
|
-
writable.__markerType = markerType
|
|
95
|
-
return this
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
override createDOM(config: EditorConfig, _editor?: LexicalEditor): HTMLElement {
|
|
99
|
-
const dom = super.createDOM(config, _editor)
|
|
100
|
-
applyListAttributesToDom(dom, this.__listColor, this.__markerType)
|
|
101
|
-
return dom
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
override updateDOM(
|
|
105
|
-
prevNode: ListWithColorNode,
|
|
106
|
-
dom: HTMLElement,
|
|
107
|
-
config: EditorConfig
|
|
108
|
-
): boolean {
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lexical ListNode.updateDOM(prevNode: this)
|
|
110
|
-
const isUpdated = super.updateDOM(prevNode as any, dom, config)
|
|
111
|
-
if (
|
|
112
|
-
prevNode.__listColor !== this.__listColor ||
|
|
113
|
-
prevNode.__markerType !== this.__markerType
|
|
114
|
-
) {
|
|
115
|
-
applyListAttributesToDom(dom, this.__listColor, this.__markerType)
|
|
116
|
-
}
|
|
117
|
-
return isUpdated
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
override updateFromJSON(
|
|
121
|
-
serializedNode: LexicalUpdateJSON<SerializedListWithColorNode>
|
|
122
|
-
): this {
|
|
123
|
-
super.updateFromJSON(serializedNode)
|
|
124
|
-
const { listColor, markerType } = serializedNode as SerializedListWithColorNode
|
|
125
|
-
if (listColor !== undefined) this.setListColor(listColor)
|
|
126
|
-
if (markerType !== undefined) this.setMarkerType(markerType)
|
|
127
|
-
return this
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
override exportDOM(editor: LexicalEditor): DOMExportOutput {
|
|
131
|
-
const output = super.exportDOM(editor)
|
|
132
|
-
if (output.element && output.element instanceof HTMLElement) {
|
|
133
|
-
applyListAttributesToDom(output.element, this.__listColor, this.__markerType)
|
|
134
|
-
}
|
|
135
|
-
return output
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
override exportJSON(): SerializedListWithColorNode {
|
|
139
|
-
const json = super.exportJSON() as SerializedListWithColorNode
|
|
140
|
-
json.type = LIST_WITH_COLOR_TYPE
|
|
141
|
-
if (this.__listColor) json.listColor = this.__listColor
|
|
142
|
-
if (this.__markerType) json.markerType = this.__markerType
|
|
143
|
-
return json
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function $createListWithColorNode(
|
|
148
|
-
listType?: ListType,
|
|
149
|
-
start?: number
|
|
150
|
-
): ListWithColorNode {
|
|
151
|
-
return $applyNodeReplacement(
|
|
152
|
-
new ListWithColorNode(listType, start)
|
|
153
|
-
) as ListWithColorNode
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function $isListWithColorNode(
|
|
157
|
-
node: LexicalNode | null | undefined
|
|
158
|
-
): node is ListWithColorNode {
|
|
159
|
-
return node instanceof ListWithColorNode
|
|
160
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import type { DOMExportOutput, EditorConfig, LexicalEditor } from "lexical"
|
|
4
|
+
import {
|
|
5
|
+
ListNode,
|
|
6
|
+
type ListType,
|
|
7
|
+
type SerializedListNode,
|
|
8
|
+
} from "@lexical/list"
|
|
9
|
+
import type { LexicalNode, LexicalUpdateJSON, NodeKey } from "lexical"
|
|
10
|
+
import { $applyNodeReplacement } from "lexical"
|
|
11
|
+
|
|
12
|
+
export type SerializedListWithColorNode = Omit<SerializedListNode, "type"> & {
|
|
13
|
+
type: "listwithcolor"
|
|
14
|
+
listColor?: string
|
|
15
|
+
markerType?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const LIST_WITH_COLOR_TYPE = "listwithcolor"
|
|
19
|
+
|
|
20
|
+
function applyListAttributesToDom(dom: HTMLElement, color?: string, markerType?: string): void {
|
|
21
|
+
if (color) {
|
|
22
|
+
dom.style.setProperty("--list-marker-color", color, "important")
|
|
23
|
+
dom.setAttribute("data-list-color", color)
|
|
24
|
+
} else {
|
|
25
|
+
dom.style.removeProperty("--list-marker-color")
|
|
26
|
+
dom.removeAttribute("data-list-color")
|
|
27
|
+
}
|
|
28
|
+
if (markerType) {
|
|
29
|
+
dom.setAttribute("data-list-marker", markerType)
|
|
30
|
+
} else {
|
|
31
|
+
dom.removeAttribute("data-list-marker")
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class ListWithColorNode extends ListNode {
|
|
36
|
+
__listColor?: string
|
|
37
|
+
__markerType?: string
|
|
38
|
+
|
|
39
|
+
constructor(listType?: ListType, start?: number, key?: NodeKey) {
|
|
40
|
+
super(listType, start, key)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getType(): "listwithcolor" {
|
|
44
|
+
return LIST_WITH_COLOR_TYPE
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override getType(): "listwithcolor" {
|
|
48
|
+
return LIST_WITH_COLOR_TYPE
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static override clone(node: ListWithColorNode, key?: NodeKey): ListWithColorNode {
|
|
52
|
+
const listType = node.getListType()
|
|
53
|
+
const start = node.getStart()
|
|
54
|
+
const sameKey = key ?? node.getKey()
|
|
55
|
+
const cloned = new ListWithColorNode(listType, start, sameKey)
|
|
56
|
+
if (node.__listColor) cloned.__listColor = node.__listColor
|
|
57
|
+
if (node.__markerType) cloned.__markerType = node.__markerType
|
|
58
|
+
return cloned
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static override importJSON(
|
|
62
|
+
serializedNode: SerializedListWithColorNode
|
|
63
|
+
): ListWithColorNode {
|
|
64
|
+
const { listType, start, listColor, markerType } = serializedNode
|
|
65
|
+
const node = new ListWithColorNode(listType, start)
|
|
66
|
+
if (listColor != null) node.__listColor = listColor
|
|
67
|
+
if (markerType != null) node.__markerType = markerType
|
|
68
|
+
return node
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override afterCloneFrom(prevNode: ListWithColorNode): void {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lexical ListNode.afterCloneFrom(prevNode: this) không chấp nhận subtype
|
|
73
|
+
super.afterCloneFrom(prevNode as any)
|
|
74
|
+
this.__listColor = prevNode.__listColor
|
|
75
|
+
this.__markerType = prevNode.__markerType
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getListColor(): string | undefined {
|
|
79
|
+
return this.getLatest().__listColor
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setListColor(color: string | undefined): this {
|
|
83
|
+
const writable = this.getWritable()
|
|
84
|
+
writable.__listColor = color
|
|
85
|
+
return this
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getMarkerType(): string | undefined {
|
|
89
|
+
return this.getLatest().__markerType
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setMarkerType(markerType: string | undefined): this {
|
|
93
|
+
const writable = this.getWritable()
|
|
94
|
+
writable.__markerType = markerType
|
|
95
|
+
return this
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
override createDOM(config: EditorConfig, _editor?: LexicalEditor): HTMLElement {
|
|
99
|
+
const dom = super.createDOM(config, _editor)
|
|
100
|
+
applyListAttributesToDom(dom, this.__listColor, this.__markerType)
|
|
101
|
+
return dom
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override updateDOM(
|
|
105
|
+
prevNode: ListWithColorNode,
|
|
106
|
+
dom: HTMLElement,
|
|
107
|
+
config: EditorConfig
|
|
108
|
+
): boolean {
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lexical ListNode.updateDOM(prevNode: this)
|
|
110
|
+
const isUpdated = super.updateDOM(prevNode as any, dom, config)
|
|
111
|
+
if (
|
|
112
|
+
prevNode.__listColor !== this.__listColor ||
|
|
113
|
+
prevNode.__markerType !== this.__markerType
|
|
114
|
+
) {
|
|
115
|
+
applyListAttributesToDom(dom, this.__listColor, this.__markerType)
|
|
116
|
+
}
|
|
117
|
+
return isUpdated
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
override updateFromJSON(
|
|
121
|
+
serializedNode: LexicalUpdateJSON<SerializedListWithColorNode>
|
|
122
|
+
): this {
|
|
123
|
+
super.updateFromJSON(serializedNode)
|
|
124
|
+
const { listColor, markerType } = serializedNode as SerializedListWithColorNode
|
|
125
|
+
if (listColor !== undefined) this.setListColor(listColor)
|
|
126
|
+
if (markerType !== undefined) this.setMarkerType(markerType)
|
|
127
|
+
return this
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override exportDOM(editor: LexicalEditor): DOMExportOutput {
|
|
131
|
+
const output = super.exportDOM(editor)
|
|
132
|
+
if (output.element && output.element instanceof HTMLElement) {
|
|
133
|
+
applyListAttributesToDom(output.element, this.__listColor, this.__markerType)
|
|
134
|
+
}
|
|
135
|
+
return output
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
override exportJSON(): SerializedListWithColorNode {
|
|
139
|
+
const json = super.exportJSON() as SerializedListWithColorNode
|
|
140
|
+
json.type = LIST_WITH_COLOR_TYPE
|
|
141
|
+
if (this.__listColor) json.listColor = this.__listColor
|
|
142
|
+
if (this.__markerType) json.markerType = this.__markerType
|
|
143
|
+
return json
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function $createListWithColorNode(
|
|
148
|
+
listType?: ListType,
|
|
149
|
+
start?: number
|
|
150
|
+
): ListWithColorNode {
|
|
151
|
+
return $applyNodeReplacement(
|
|
152
|
+
new ListWithColorNode(listType, start)
|
|
153
|
+
) as ListWithColorNode
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function $isListWithColorNode(
|
|
157
|
+
node: LexicalNode | null | undefined
|
|
158
|
+
): node is ListWithColorNode {
|
|
159
|
+
return node instanceof ListWithColorNode
|
|
160
|
+
}
|