@phuong-tran-redoc/document-engine-core 0.0.16 → 0.0.18
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/package.json +4 -3
- package/src/constants/indent.constant.js +1 -11
- package/src/constants/index.js +1 -18
- package/src/constants/table.constant.js +1 -11
- package/src/extensions/clear-content.extension.js +2 -12
- package/src/extensions/indent.extension.js +4 -14
- package/src/extensions/index.js +8 -25
- package/src/extensions/ordered-list.extension.js +2 -12
- package/src/extensions/reset-format.extension.js +2 -12
- package/src/extensions/reset-on-enter.extension.js +7 -12
- package/src/extensions/restricted-editing.extension.js +8 -25
- package/src/extensions/table-resizing.extension.js +15 -22
- package/src/extensions/table-style.extension.js +29 -57
- package/src/extensions/text-case.extension.js +4 -14
- package/src/index.d.ts +0 -31
- package/src/index.js +7 -242
- package/src/models/color.model.js +4 -14
- package/src/models/index.js +1 -18
- package/src/nodes/dynamic-field.node.js +9 -13
- package/src/nodes/heading.node.js +3 -13
- package/src/nodes/index.js +3 -20
- package/src/nodes/page-break.node.js +3 -13
- package/src/types/index.js +2 -19
- package/src/types/ordered-list.type.js +1 -4
- package/src/types/text-case.type.js +1 -4
- package/src/utils/color.util.js +1 -11
- package/src/utils/dom.util.js +1 -11
- package/src/utils/index.js +4 -21
- package/src/utils/table.util.js +22 -35
- package/src/utils/text.util.js +9 -22
- package/src/views/block-handler.js +9 -29
- package/src/views/index.js +1 -18
package/src/index.js
CHANGED
|
@@ -1,242 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
AllSelection: function() {
|
|
13
|
-
return _state.AllSelection;
|
|
14
|
-
},
|
|
15
|
-
Bold: function() {
|
|
16
|
-
return _extensionbold.Bold;
|
|
17
|
-
},
|
|
18
|
-
BulletList: function() {
|
|
19
|
-
return _extensionlist.BulletList;
|
|
20
|
-
},
|
|
21
|
-
CellSelection: function() {
|
|
22
|
-
return _tables.CellSelection;
|
|
23
|
-
},
|
|
24
|
-
Code: function() {
|
|
25
|
-
return _extensioncode.Code;
|
|
26
|
-
},
|
|
27
|
-
ContentMatch: function() {
|
|
28
|
-
return _model.ContentMatch;
|
|
29
|
-
},
|
|
30
|
-
DOMParser: function() {
|
|
31
|
-
return _model.DOMParser;
|
|
32
|
-
},
|
|
33
|
-
DOMSerializer: function() {
|
|
34
|
-
return _model.DOMSerializer;
|
|
35
|
-
},
|
|
36
|
-
Decoration: function() {
|
|
37
|
-
return _view.Decoration;
|
|
38
|
-
},
|
|
39
|
-
DecorationSet: function() {
|
|
40
|
-
return _view.DecorationSet;
|
|
41
|
-
},
|
|
42
|
-
EditorState: function() {
|
|
43
|
-
return _state.EditorState;
|
|
44
|
-
},
|
|
45
|
-
EditorView: function() {
|
|
46
|
-
return _view.EditorView;
|
|
47
|
-
},
|
|
48
|
-
Fragment: function() {
|
|
49
|
-
return _model.Fragment;
|
|
50
|
-
},
|
|
51
|
-
Image: function() {
|
|
52
|
-
return _extensionimage.Image;
|
|
53
|
-
},
|
|
54
|
-
Italic: function() {
|
|
55
|
-
return _extensionitalic.Italic;
|
|
56
|
-
},
|
|
57
|
-
Link: function() {
|
|
58
|
-
return _extensionlink.Link;
|
|
59
|
-
},
|
|
60
|
-
ListItem: function() {
|
|
61
|
-
return _extensionlist.ListItem;
|
|
62
|
-
},
|
|
63
|
-
ListKeymap: function() {
|
|
64
|
-
return _extensionlist.ListKeymap;
|
|
65
|
-
},
|
|
66
|
-
Mark: function() {
|
|
67
|
-
return _model.Mark;
|
|
68
|
-
},
|
|
69
|
-
MarkType: function() {
|
|
70
|
-
return _model.MarkType;
|
|
71
|
-
},
|
|
72
|
-
Node: function() {
|
|
73
|
-
return _model.Node;
|
|
74
|
-
},
|
|
75
|
-
NodeRange: function() {
|
|
76
|
-
return _model.NodeRange;
|
|
77
|
-
},
|
|
78
|
-
NodeSelection: function() {
|
|
79
|
-
return _state.NodeSelection;
|
|
80
|
-
},
|
|
81
|
-
NodeType: function() {
|
|
82
|
-
return _model.NodeType;
|
|
83
|
-
},
|
|
84
|
-
OrderedList: function() {
|
|
85
|
-
return _extensionlist.OrderedList;
|
|
86
|
-
},
|
|
87
|
-
Paragraph: function() {
|
|
88
|
-
return _extensionparagraph.Paragraph;
|
|
89
|
-
},
|
|
90
|
-
Plugin: function() {
|
|
91
|
-
return _state.Plugin;
|
|
92
|
-
},
|
|
93
|
-
PluginKey: function() {
|
|
94
|
-
return _state.PluginKey;
|
|
95
|
-
},
|
|
96
|
-
ResolvedPos: function() {
|
|
97
|
-
return _model.ResolvedPos;
|
|
98
|
-
},
|
|
99
|
-
Schema: function() {
|
|
100
|
-
return _model.Schema;
|
|
101
|
-
},
|
|
102
|
-
Selection: function() {
|
|
103
|
-
return _state.Selection;
|
|
104
|
-
},
|
|
105
|
-
Slice: function() {
|
|
106
|
-
return _model.Slice;
|
|
107
|
-
},
|
|
108
|
-
Strike: function() {
|
|
109
|
-
return _extensionstrike.Strike;
|
|
110
|
-
},
|
|
111
|
-
TableMap: function() {
|
|
112
|
-
return _tables.TableMap;
|
|
113
|
-
},
|
|
114
|
-
TableView: function() {
|
|
115
|
-
return _tables.TableView;
|
|
116
|
-
},
|
|
117
|
-
Text: function() {
|
|
118
|
-
return _extensiontext.Text;
|
|
119
|
-
},
|
|
120
|
-
TextSelection: function() {
|
|
121
|
-
return _state.TextSelection;
|
|
122
|
-
},
|
|
123
|
-
TextStyle: function() {
|
|
124
|
-
return _extensiontextstyle.TextStyle;
|
|
125
|
-
},
|
|
126
|
-
TextStyleKit: function() {
|
|
127
|
-
return _extensiontextstyle.TextStyleKit;
|
|
128
|
-
},
|
|
129
|
-
Transaction: function() {
|
|
130
|
-
return _state.Transaction;
|
|
131
|
-
},
|
|
132
|
-
addColumnAfter: function() {
|
|
133
|
-
return _tables.addColumnAfter;
|
|
134
|
-
},
|
|
135
|
-
addColumnBefore: function() {
|
|
136
|
-
return _tables.addColumnBefore;
|
|
137
|
-
},
|
|
138
|
-
addRowAfter: function() {
|
|
139
|
-
return _tables.addRowAfter;
|
|
140
|
-
},
|
|
141
|
-
addRowBefore: function() {
|
|
142
|
-
return _tables.addRowBefore;
|
|
143
|
-
},
|
|
144
|
-
columnResizing: function() {
|
|
145
|
-
return _tables.columnResizing;
|
|
146
|
-
},
|
|
147
|
-
deleteColumn: function() {
|
|
148
|
-
return _tables.deleteColumn;
|
|
149
|
-
},
|
|
150
|
-
deleteRow: function() {
|
|
151
|
-
return _tables.deleteRow;
|
|
152
|
-
},
|
|
153
|
-
deleteTable: function() {
|
|
154
|
-
return _tables.deleteTable;
|
|
155
|
-
},
|
|
156
|
-
fixTables: function() {
|
|
157
|
-
return _tables.fixTables;
|
|
158
|
-
},
|
|
159
|
-
goToNextCell: function() {
|
|
160
|
-
return _tables.goToNextCell;
|
|
161
|
-
},
|
|
162
|
-
goToNextCellCommand: function() {
|
|
163
|
-
return _tables.goToNextCell;
|
|
164
|
-
},
|
|
165
|
-
mergeCells: function() {
|
|
166
|
-
return _tables.mergeCells;
|
|
167
|
-
},
|
|
168
|
-
selectionCell: function() {
|
|
169
|
-
return _tables.selectionCell;
|
|
170
|
-
},
|
|
171
|
-
setCellAttr: function() {
|
|
172
|
-
return _tables.setCellAttr;
|
|
173
|
-
},
|
|
174
|
-
splitCell: function() {
|
|
175
|
-
return _tables.splitCell;
|
|
176
|
-
},
|
|
177
|
-
tableEditing: function() {
|
|
178
|
-
return _tables.tableEditing;
|
|
179
|
-
},
|
|
180
|
-
toggleHeader: function() {
|
|
181
|
-
return _tables.toggleHeader;
|
|
182
|
-
},
|
|
183
|
-
toggleHeaderCell: function() {
|
|
184
|
-
return _tables.toggleHeaderCell;
|
|
185
|
-
},
|
|
186
|
-
toggleHeaderColumn: function() {
|
|
187
|
-
return _tables.toggleHeaderColumn;
|
|
188
|
-
},
|
|
189
|
-
toggleHeaderRow: function() {
|
|
190
|
-
return _tables.toggleHeaderRow;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
_export_star(require("./constants"), exports);
|
|
194
|
-
_export_star(require("./extensions"), exports);
|
|
195
|
-
_export_star(require("./models"), exports);
|
|
196
|
-
_export_star(require("./nodes"), exports);
|
|
197
|
-
_export_star(require("./types"), exports);
|
|
198
|
-
_export_star(require("./utils"), exports);
|
|
199
|
-
_export_star(require("./views"), exports);
|
|
200
|
-
_export_star(require("@tiptap/core"), exports);
|
|
201
|
-
_export_star(require("@tiptap/extension-blockquote"), exports);
|
|
202
|
-
const _extensionbold = require("@tiptap/extension-bold");
|
|
203
|
-
_export_star(require("@tiptap/extension-bubble-menu"), exports);
|
|
204
|
-
const _extensioncode = require("@tiptap/extension-code");
|
|
205
|
-
_export_star(require("@tiptap/extension-code-block"), exports);
|
|
206
|
-
_export_star(require("@tiptap/extension-document"), exports);
|
|
207
|
-
_export_star(require("@tiptap/extension-floating-menu"), exports);
|
|
208
|
-
_export_star(require("@tiptap/extension-hard-break"), exports);
|
|
209
|
-
_export_star(require("@tiptap/extension-heading"), exports);
|
|
210
|
-
_export_star(require("@tiptap/extension-horizontal-rule"), exports);
|
|
211
|
-
const _extensionimage = require("@tiptap/extension-image");
|
|
212
|
-
const _extensionitalic = require("@tiptap/extension-italic");
|
|
213
|
-
const _extensionlink = require("@tiptap/extension-link");
|
|
214
|
-
const _extensionlist = require("@tiptap/extension-list");
|
|
215
|
-
const _extensionparagraph = require("@tiptap/extension-paragraph");
|
|
216
|
-
const _extensionstrike = require("@tiptap/extension-strike");
|
|
217
|
-
_export_star(require("@tiptap/extension-subscript"), exports);
|
|
218
|
-
_export_star(require("@tiptap/extension-superscript"), exports);
|
|
219
|
-
_export_star(require("@tiptap/extension-table"), exports);
|
|
220
|
-
const _extensiontext = require("@tiptap/extension-text");
|
|
221
|
-
_export_star(require("@tiptap/extension-text-align"), exports);
|
|
222
|
-
const _extensiontextstyle = require("@tiptap/extension-text-style");
|
|
223
|
-
_export_star(require("@tiptap/extension-underline"), exports);
|
|
224
|
-
_export_star(require("@tiptap/extensions"), exports);
|
|
225
|
-
const _state = require("@tiptap/pm/state");
|
|
226
|
-
const _view = require("@tiptap/pm/view");
|
|
227
|
-
const _model = require("@tiptap/pm/model");
|
|
228
|
-
_export_star(require("@tiptap/pm/transform"), exports);
|
|
229
|
-
const _tables = require("@tiptap/pm/tables");
|
|
230
|
-
function _export_star(from, to) {
|
|
231
|
-
Object.keys(from).forEach(function(k) {
|
|
232
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
233
|
-
Object.defineProperty(to, k, {
|
|
234
|
-
enumerable: true,
|
|
235
|
-
get: function() {
|
|
236
|
-
return from[k];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
return from;
|
|
242
|
-
}
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './extensions';
|
|
3
|
+
export * from './models';
|
|
4
|
+
export * from './nodes';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './utils';
|
|
7
|
+
export * from './views';
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Color", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Color;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _utils = require("../utils");
|
|
12
|
-
class Color {
|
|
1
|
+
import { normalizeColor } from '../utils';
|
|
2
|
+
export class Color {
|
|
13
3
|
static from(value, name, type) {
|
|
14
4
|
return new Color(value, name, type);
|
|
15
5
|
}
|
|
@@ -25,10 +15,10 @@ class Color {
|
|
|
25
15
|
return this.value === color.value;
|
|
26
16
|
}
|
|
27
17
|
is(color) {
|
|
28
|
-
return this.value ===
|
|
18
|
+
return this.value === normalizeColor(color);
|
|
29
19
|
}
|
|
30
20
|
constructor(value, name, type){
|
|
31
|
-
const normalizedColor =
|
|
21
|
+
const normalizedColor = normalizeColor(value);
|
|
32
22
|
if (!normalizedColor) {
|
|
33
23
|
throw new Error('Invalid or unsupported color.');
|
|
34
24
|
}
|
package/src/models/index.js
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./color.model"), exports);
|
|
6
|
-
function _export_star(from, to) {
|
|
7
|
-
Object.keys(from).forEach(function(k) {
|
|
8
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
-
Object.defineProperty(to, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return from[k];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return from;
|
|
18
|
-
}
|
|
1
|
+
export * from './color.model';
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _core = require("@tiptap/core");
|
|
12
|
-
const DynamicField = _core.Node.create({
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
/**
|
|
3
|
+
* Dynamic Field Node Extension
|
|
4
|
+
*
|
|
5
|
+
* This extension creates atomic, non-editable inline nodes that represent
|
|
6
|
+
* dynamic fields (e.g., {{customer_name}}) in document templates.
|
|
7
|
+
* These fields can be programmatically replaced with actual data later.
|
|
8
|
+
*/ export const DynamicField = Node.create({
|
|
13
9
|
name: 'dynamicField',
|
|
14
10
|
/**
|
|
15
11
|
* Node group configuration
|
|
@@ -65,7 +61,7 @@ const DynamicField = _core.Node.create({
|
|
|
65
61
|
const { fieldId, label } = node.attrs;
|
|
66
62
|
return [
|
|
67
63
|
'span',
|
|
68
|
-
|
|
64
|
+
mergeAttributes(HTMLAttributes, {
|
|
69
65
|
class: 'dynamic-field',
|
|
70
66
|
'data-field-id': fieldId,
|
|
71
67
|
'data-label': label
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NotumHeading", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NotumHeading;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _extensionheading = require("@tiptap/extension-heading");
|
|
12
|
-
require("@tiptap/extension-paragraph");
|
|
13
|
-
const NotumHeading = _extensionheading.Heading.extend({
|
|
1
|
+
import { Heading } from '@tiptap/extension-heading';
|
|
2
|
+
import '@tiptap/extension-paragraph';
|
|
3
|
+
export const NotumHeading = Heading.extend({
|
|
14
4
|
addCommands () {
|
|
15
5
|
return {
|
|
16
6
|
...this.parent?.(),
|
package/src/nodes/index.js
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./heading.node"), exports);
|
|
6
|
-
_export_star(require("./dynamic-field.node"), exports);
|
|
7
|
-
_export_star(require("./page-break.node"), exports);
|
|
8
|
-
function _export_star(from, to) {
|
|
9
|
-
Object.keys(from).forEach(function(k) {
|
|
10
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
-
Object.defineProperty(to, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function() {
|
|
14
|
-
return from[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return from;
|
|
20
|
-
}
|
|
1
|
+
export * from './heading.node';
|
|
2
|
+
export * from './dynamic-field.node';
|
|
3
|
+
export * from './page-break.node';
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "PageBreak", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return PageBreak;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _core = require("@tiptap/core");
|
|
12
|
-
const PageBreak = _core.Node.create({
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
export const PageBreak = Node.create({
|
|
13
3
|
name: 'pageBreak',
|
|
14
4
|
group: 'block',
|
|
15
5
|
atom: true,
|
|
@@ -24,7 +14,7 @@ const PageBreak = _core.Node.create({
|
|
|
24
14
|
renderHTML ({ HTMLAttributes }) {
|
|
25
15
|
return [
|
|
26
16
|
'div',
|
|
27
|
-
|
|
17
|
+
mergeAttributes(HTMLAttributes, {
|
|
28
18
|
'data-page-break': 'true',
|
|
29
19
|
class: 'document-engine-page-break',
|
|
30
20
|
style: 'break-before: page;'
|
package/src/types/index.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./ordered-list.type"), exports);
|
|
6
|
-
_export_star(require("./text-case.type"), exports);
|
|
7
|
-
function _export_star(from, to) {
|
|
8
|
-
Object.keys(from).forEach(function(k) {
|
|
9
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
-
Object.defineProperty(to, k, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return from[k];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return from;
|
|
19
|
-
}
|
|
1
|
+
export * from './ordered-list.type';
|
|
2
|
+
export * from './text-case.type';
|
package/src/utils/color.util.js
CHANGED
|
@@ -10,17 +10,7 @@
|
|
|
10
10
|
* normalizeColor('rgb(255, 0, 0)') // '#ff0000'
|
|
11
11
|
* normalizeColor('#F00') // '#f00'
|
|
12
12
|
* normalizeColor('invalid') // null
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "normalizeColor", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return normalizeColor;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
function normalizeColor(color) {
|
|
13
|
+
*/ export function normalizeColor(color) {
|
|
24
14
|
if (!color) return null;
|
|
25
15
|
const trimmed = color.trim().toLowerCase();
|
|
26
16
|
if (trimmed === 'transparent') return trimmed;
|
package/src/utils/dom.util.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "getClosestDomElement", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return getClosestDomElement;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function getClosestDomElement(editor, selector) {
|
|
1
|
+
export function getClosestDomElement(editor, selector) {
|
|
12
2
|
const { view, state } = editor;
|
|
13
3
|
const { selection } = state;
|
|
14
4
|
const { from } = selection;
|
package/src/utils/index.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
_export_star(require("./color.util"), exports);
|
|
6
|
-
_export_star(require("./dom.util"), exports);
|
|
7
|
-
_export_star(require("./table.util"), exports);
|
|
8
|
-
_export_star(require("./text.util"), exports);
|
|
9
|
-
function _export_star(from, to) {
|
|
10
|
-
Object.keys(from).forEach(function(k) {
|
|
11
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
-
Object.defineProperty(to, k, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function() {
|
|
15
|
-
return from[k];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return from;
|
|
21
|
-
}
|
|
1
|
+
export * from './color.util';
|
|
2
|
+
export * from './dom.util';
|
|
3
|
+
export * from './table.util';
|
|
4
|
+
export * from './text.util';
|
package/src/utils/table.util.js
CHANGED
|
@@ -1,38 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
getCombinedCellAttributeValue: function() {
|
|
13
|
-
return getCombinedCellAttributeValue;
|
|
14
|
-
},
|
|
15
|
-
getCursorCellInfo: function() {
|
|
16
|
-
return getCursorCellInfo;
|
|
17
|
-
},
|
|
18
|
-
getSelectedCells: function() {
|
|
19
|
-
return getSelectedCells;
|
|
20
|
-
},
|
|
21
|
-
getTableDOMFromView: function() {
|
|
22
|
-
return getTableDOMFromView;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const _tables = require("@tiptap/pm/tables");
|
|
26
|
-
const _lodashes = require("lodash-es");
|
|
27
|
-
function getCursorCellInfo(state) {
|
|
1
|
+
import { CellSelection, findTable, selectionCell, TableMap } from '@tiptap/pm/tables';
|
|
2
|
+
import { isEqual } from 'lodash-es';
|
|
3
|
+
export function getCursorCellInfo(state) {
|
|
28
4
|
// 1. Dùng selectionCell để tìm vị trí bắt đầu của ô chứa con trỏ
|
|
29
|
-
const cellInfo =
|
|
5
|
+
const cellInfo = selectionCell(state);
|
|
30
6
|
// Nếu không tìm thấy (con trỏ không nằm trong ô nào), trả về null
|
|
31
7
|
if (!cellInfo) return null;
|
|
32
8
|
// cellInfo.$pos là một ResolvedPos trỏ tới vị trí bắt đầu của ô
|
|
33
|
-
const table =
|
|
9
|
+
const table = findTable(cellInfo);
|
|
34
10
|
if (!table) return null;
|
|
35
|
-
const map =
|
|
11
|
+
const map = TableMap.get(table.node);
|
|
36
12
|
// 2. Lấy vị trí tương đối của ô so với bảng
|
|
37
13
|
const cellOffset = cellInfo.pos - table.start;
|
|
38
14
|
// 3. Tìm chỉ số (index) của ô này trong "bản đồ" của bảng
|
|
@@ -52,11 +28,11 @@ function getCursorCellInfo(state) {
|
|
|
52
28
|
map
|
|
53
29
|
};
|
|
54
30
|
}
|
|
55
|
-
function getSelectedCells(state) {
|
|
31
|
+
export function getSelectedCells(state) {
|
|
56
32
|
const { selection } = state;
|
|
57
33
|
const cells = [];
|
|
58
34
|
// Trường hợp chọn nhiều ô
|
|
59
|
-
if (selection instanceof
|
|
35
|
+
if (selection instanceof CellSelection) {
|
|
60
36
|
selection.forEachCell((node, pos)=>cells.push({
|
|
61
37
|
pos,
|
|
62
38
|
node
|
|
@@ -77,18 +53,29 @@ function getSelectedCells(state) {
|
|
|
77
53
|
}
|
|
78
54
|
return cells;
|
|
79
55
|
}
|
|
80
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Quyết định giá trị thuộc tính cuối cùng từ một danh sách các cell đã chọn.
|
|
58
|
+
* @param cells Danh sách các cell được chọn.
|
|
59
|
+
* @param attributeName Tên của thuộc tính cần lấy (ví dụ: 'backgroundColor').
|
|
60
|
+
* @returns Giá trị chung, hoặc MIXED_VALUE nếu các giá trị không đồng nhất.
|
|
61
|
+
*/ export function getCombinedCellAttributeValue(cells, attributeName, fallbackValue) {
|
|
81
62
|
// Không có cell nào được chọn
|
|
82
63
|
if (cells.length === 0) return fallbackValue;
|
|
83
64
|
const firstValue = cells[0].node.attrs[attributeName];
|
|
84
65
|
for(let i = 1; i < cells.length; i++){
|
|
85
66
|
const currentValue = cells[i].node.attrs[attributeName];
|
|
86
67
|
// Dùng isEqual để so sánh object (quan trọng cho thuộc tính 'border')
|
|
87
|
-
if (!
|
|
68
|
+
if (!isEqual(currentValue, firstValue)) return undefined;
|
|
88
69
|
}
|
|
89
70
|
return firstValue;
|
|
90
71
|
}
|
|
91
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Get the actual table DOM element from a node position
|
|
74
|
+
* Handles both direct table elements and NodeView wrappers
|
|
75
|
+
* Uses :scope selector to avoid selecting nested tables
|
|
76
|
+
*
|
|
77
|
+
* @export For use in other table-related extensions
|
|
78
|
+
*/ export function getTableDOMFromView(view, tablePos) {
|
|
92
79
|
const nodeDOMEl = view.nodeDOM(tablePos);
|
|
93
80
|
if (!nodeDOMEl) return null;
|
|
94
81
|
// Case 1: nodeDOMEl is the table itself
|
package/src/utils/text.util.js
CHANGED
|
@@ -1,34 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
getActiveMarkRange: function() {
|
|
13
|
-
return getActiveMarkRange;
|
|
14
|
-
},
|
|
15
|
-
getSelectedText: function() {
|
|
16
|
-
return getSelectedText;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _state = require("@tiptap/pm/state");
|
|
20
|
-
function getSelectedText(editor) {
|
|
1
|
+
import { TextSelection } from '@tiptap/pm/state';
|
|
2
|
+
export function getSelectedText(editor) {
|
|
21
3
|
const { state } = editor;
|
|
22
4
|
const { selection } = state;
|
|
23
5
|
// 1. Kiểm tra nếu selection rỗng (chỉ là con trỏ) hoặc không phải là TextSelection
|
|
24
|
-
if (selection.empty || !(selection instanceof
|
|
6
|
+
if (selection.empty || !(selection instanceof TextSelection)) {
|
|
25
7
|
return null;
|
|
26
8
|
}
|
|
27
9
|
// 2. Lấy text giữa điểm đầu và điểm cuối của selection
|
|
28
10
|
const { from, to } = selection;
|
|
29
11
|
return state.doc.textBetween(from, to, ' '); // Trả về text
|
|
30
12
|
}
|
|
31
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Tìm instance và range (from, to) của một mark cụ thể tại vị trí con trỏ.
|
|
15
|
+
* @param editor The Tiptap editor instance.
|
|
16
|
+
* @param markName Tên của mark cần tìm (vd: 'link').
|
|
17
|
+
* @returns Object chứa from, to, và mark instance nếu tìm thấy, ngược lại trả về null.
|
|
18
|
+
*/ export function getActiveMarkRange(editor, markName) {
|
|
32
19
|
const { state } = editor;
|
|
33
20
|
const { $from } = state.selection;
|
|
34
21
|
const { doc } = state;
|