edytor 0.0.5 → 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/dist/edytor.cjs.development.js +256 -176
- package/dist/edytor.cjs.development.js.map +1 -1
- package/dist/edytor.cjs.production.min.js +1 -1
- package/dist/edytor.cjs.production.min.js.map +1 -1
- package/dist/edytor.esm.js +242 -163
- package/dist/edytor.esm.js.map +1 -1
- package/dist/events/onKeyDown.d.ts +67 -0
- package/dist/operations/deleteText.d.ts +1 -1
- package/dist/operations/splitLeaf.d.ts +2 -8
- package/dist/types.d.ts +14 -3
- package/dist/utils/common.d.ts +4 -4
- package/dist/utils/nodes.d.ts +2 -1
- package/dist/utils/selection.d.ts +9 -2
- package/dist/utils/yClasses/EdytorDoc.d.ts +1 -3
- package/dist/yjs/index.d.ts +0 -1
- package/package.json +2 -1
- package/dist/yjs/webrtcProvider.d.ts +0 -11
package/dist/edytor.esm.js
CHANGED
|
@@ -97,9 +97,6 @@ var YNode = /*#__PURE__*/function (_Map) {
|
|
|
97
97
|
}(Map$1);
|
|
98
98
|
|
|
99
99
|
var _excluded$1 = ["type", "content", "children"];
|
|
100
|
-
var getContent = function getContent(leaf) {
|
|
101
|
-
return createLeaf$1(leaf);
|
|
102
|
-
};
|
|
103
100
|
var getChildren = function getChildren(_ref) {
|
|
104
101
|
var type = _ref.type,
|
|
105
102
|
_ref$content = _ref.content,
|
|
@@ -110,27 +107,22 @@ var getChildren = function getChildren(_ref) {
|
|
|
110
107
|
|
|
111
108
|
return createNode(type, _extends({}, props, {
|
|
112
109
|
children: children.map(getChildren),
|
|
113
|
-
content: content.map(
|
|
110
|
+
content: content.map(createLeaf$1)
|
|
114
111
|
}));
|
|
115
112
|
};
|
|
116
113
|
var EdytorDoc = /*#__PURE__*/function (_Doc) {
|
|
117
114
|
_inheritsLoose(EdytorDoc, _Doc);
|
|
118
115
|
|
|
119
|
-
function EdytorDoc(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
_this = _Doc.call(this) || this;
|
|
123
|
-
|
|
124
|
-
return _this;
|
|
116
|
+
function EdytorDoc() {
|
|
117
|
+
return _Doc.apply(this, arguments) || this;
|
|
125
118
|
}
|
|
126
119
|
|
|
127
120
|
return EdytorDoc;
|
|
128
121
|
}(Doc);
|
|
129
|
-
var DocFromJson = function DocFromJson(value) {
|
|
130
|
-
var
|
|
131
|
-
var array = doc.getArray("children");
|
|
122
|
+
var DocFromJson = function DocFromJson(value, initialDoc) {
|
|
123
|
+
var array = (initialDoc || new Doc()).getArray("children");
|
|
132
124
|
array.insert(0, value.map(getChildren));
|
|
133
|
-
return doc;
|
|
125
|
+
return array.doc;
|
|
134
126
|
};
|
|
135
127
|
|
|
136
128
|
var deleteText = function deleteText(editor, _ref) {
|
|
@@ -149,21 +141,28 @@ var deleteText = function deleteText(editor, _ref) {
|
|
|
149
141
|
case "collapsed":
|
|
150
142
|
{
|
|
151
143
|
if (mode === "backward" && edges.startNode) {
|
|
152
|
-
|
|
144
|
+
if (edges.startDocument) return; // unnest node if its the last of its parent and if he is nested or it's the first its the only child of its parent
|
|
153
145
|
|
|
154
|
-
if (start.nodeIndex === start.node.parent.length - 1 && start.path.length >
|
|
155
|
-
console.log(start.leafId);
|
|
146
|
+
if (start.nodeIndex === start.node.parent.length - 1 && start.path.length > 2 && (start.nodeIndex !== 0 || start.node.parent.length === 1)) {
|
|
156
147
|
var node = copyNode(start.node);
|
|
148
|
+
var nodeGrandParent = start.node.parent.parent;
|
|
149
|
+
var index = getIndex(nodeGrandParent);
|
|
157
150
|
start.node.parent["delete"](start.nodeIndex);
|
|
158
|
-
|
|
159
|
-
setPosition(start.leafId, {
|
|
151
|
+
nodeGrandParent.parent.insert(index + 1, [node]);
|
|
152
|
+
return setPosition(start.leafId, {
|
|
160
153
|
offset: 0
|
|
161
154
|
});
|
|
162
155
|
} else {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
return editor.doc.transact(function () {
|
|
157
|
+
var _mergeContentWithPrev = mergeContentWithPrevLeaf(editor),
|
|
158
|
+
prevLeaf = _mergeContentWithPrev[0],
|
|
159
|
+
offset = _mergeContentWithPrev[1];
|
|
160
|
+
|
|
161
|
+
setTimeout(function () {
|
|
162
|
+
setPosition(prevLeaf.get("id"), {
|
|
163
|
+
offset: offset
|
|
164
|
+
});
|
|
165
|
+
});
|
|
167
166
|
});
|
|
168
167
|
}
|
|
169
168
|
}
|
|
@@ -179,14 +178,22 @@ var deleteText = function deleteText(editor, _ref) {
|
|
|
179
178
|
|
|
180
179
|
if (mode === "forward" && edges.endNode) {
|
|
181
180
|
// merge node with the next node because we are at edge end of it
|
|
182
|
-
return
|
|
181
|
+
return editor.doc.transact(function () {
|
|
182
|
+
mergeContentWithNextLeaf(editor);
|
|
183
|
+
setTimeout(function () {
|
|
184
|
+
setPosition(start.leafId, {
|
|
185
|
+
offset: start.offset
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
if (mode === "forward" && edges.endLeaf) {
|
|
186
192
|
// delete content in the next leaf because we are at its edge end
|
|
187
193
|
var nextLeaf = leafNodeContent(start.leaf).get(start.leafIndex + 1);
|
|
188
194
|
return deleteLeafText(nextLeaf, 0, length || 1);
|
|
189
|
-
}
|
|
195
|
+
} // just delete text
|
|
196
|
+
|
|
190
197
|
|
|
191
198
|
deleteLeafText(start.leaf, start.offset + (mode === "backward" ? -length || -1 : length), length || 1);
|
|
192
199
|
setPosition(start.leaf.get("id"), {
|
|
@@ -199,11 +206,11 @@ var deleteText = function deleteText(editor, _ref) {
|
|
|
199
206
|
{
|
|
200
207
|
deleteLeafText(start.leaf, start.offset, length, true);
|
|
201
208
|
|
|
202
|
-
if (
|
|
209
|
+
if (isNodeContentEmpty(start.node)) {
|
|
203
210
|
leafNodeContent(start.leaf).insert(0, [createLeaf$1()]);
|
|
204
211
|
}
|
|
205
212
|
|
|
206
|
-
setPosition(start.
|
|
213
|
+
setPosition(start.leafId, {
|
|
207
214
|
offset: start.offset
|
|
208
215
|
});
|
|
209
216
|
break;
|
|
@@ -251,7 +258,7 @@ var deleteText = function deleteText(editor, _ref) {
|
|
|
251
258
|
|
|
252
259
|
var applyMarksFromParent = function applyMarksFromParent(parent, leafs) {
|
|
253
260
|
Array.from(parent.keys(), function (key) {
|
|
254
|
-
if (key !== "text") {
|
|
261
|
+
if (key !== "text" && key !== "id" && key !== "data") {
|
|
255
262
|
leafs.forEach(function (leaf) {
|
|
256
263
|
leaf.set(key, parent.get(key));
|
|
257
264
|
});
|
|
@@ -323,74 +330,76 @@ var formatText = function formatText(editor, mark) {
|
|
|
323
330
|
switch (type) {
|
|
324
331
|
case "collapsed":
|
|
325
332
|
{
|
|
326
|
-
var isMarkActive = start.leaf.has(format);
|
|
333
|
+
var isMarkActive = start.leaf.has(format) && start.leaf.get(format) === value;
|
|
327
334
|
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
335
|
+
if (isLeafEmpty(start.leaf)) {
|
|
336
|
+
// if the leaf is empty we only toggle the mark
|
|
337
|
+
isMarkActive ? start.leaf["delete"](format) : start.leaf.set(format, value);
|
|
331
338
|
} else {
|
|
339
|
+
var _createLeaf;
|
|
340
|
+
|
|
341
|
+
// if leaf is not empty we split the current leaf in half to insert an empty fragment with the desired mark
|
|
342
|
+
splitLeaf(editor);
|
|
343
|
+
var fragment = createLeaf$1((_createLeaf = {
|
|
344
|
+
text: ""
|
|
345
|
+
}, _createLeaf[format] = value, _createLeaf)); // we are applying the current marks on the fragment
|
|
346
|
+
|
|
347
|
+
applyMarksFromParent(start.leaf, [fragment]); // we remove the mark if its here
|
|
348
|
+
|
|
349
|
+
if (isMarkActive) fragment["delete"](format); // we insert the fragment after the spitted leaf
|
|
350
|
+
|
|
351
|
+
leafNodeContent(start.leaf).insert(start.leafIndex + 1, [fragment]); // we remove the spitted leaf if empty
|
|
352
|
+
|
|
332
353
|
if (isLeafEmpty(start.leaf)) {
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
var _createLeaf;
|
|
354
|
+
leafNodeContent(start.leaf)["delete"](start.leafIndex);
|
|
355
|
+
}
|
|
336
356
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
357
|
+
setTimeout(function () {
|
|
358
|
+
setPosition(fragment.get("id"), {
|
|
359
|
+
offset: 0
|
|
340
360
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
applyMarksFromParent(start.leaf, [newChild]);
|
|
345
|
-
if (isMarkActive) newChild["delete"](format);
|
|
346
|
-
leafNodeContent(start.leaf).insert(start.path.slice().reverse()[0] + 1, [newChild]);
|
|
347
|
-
|
|
348
|
-
if (isLeafEmpty(start.leaf)) {
|
|
349
|
-
leafNodeContent(start.leaf)["delete"](start.path.slice().reverse()[0]);
|
|
350
|
-
}
|
|
361
|
+
console.log(leafNodeContent(start.leaf).toJSON());
|
|
362
|
+
});
|
|
363
|
+
} // we merge leaves to avoid two subsequent leaves with the same marks
|
|
351
364
|
|
|
352
|
-
newPath = leafNodeContent(start.leaf).toArray().indexOf(newChild);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
365
|
|
|
356
366
|
mergeLeafs(leafNodeContent(start.leaf));
|
|
357
|
-
break;
|
|
367
|
+
break;
|
|
358
368
|
}
|
|
359
369
|
|
|
360
370
|
case "singlenode":
|
|
361
371
|
{
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
var isRemoved = formatedLeaf._item.deleted;
|
|
372
|
+
var formatedLeaf = formatAtEqualPath({
|
|
373
|
+
format: format,
|
|
374
|
+
value: value,
|
|
375
|
+
start: start,
|
|
376
|
+
end: end,
|
|
377
|
+
length: length
|
|
378
|
+
});
|
|
379
|
+
mergeLeafs(leafNodeContent(start.leaf));
|
|
380
|
+
var isRemoved = formatedLeaf._item.deleted;
|
|
372
381
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
});
|
|
382
|
+
if (!isRemoved) {
|
|
383
|
+
setPosition(start.leaf.get("id"), {
|
|
384
|
+
offset: start.offset
|
|
385
|
+
});
|
|
386
|
+
setTimeout(function () {
|
|
387
|
+
setPosition(formatedLeaf.get("id"), {
|
|
388
|
+
offset: 0,
|
|
389
|
+
end: leafLength(formatedLeaf)
|
|
382
390
|
});
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
+
});
|
|
392
|
+
} else {
|
|
393
|
+
var remainingLeaf = formatedLeaf.parent.get(start.leafIndex - 1);
|
|
394
|
+
var offset = leafText(remainingLeaf).toJSON().indexOf(selectedText);
|
|
395
|
+
setTimeout(function () {
|
|
396
|
+
setPosition(remainingLeaf.get("id"), {
|
|
397
|
+
offset: offset,
|
|
398
|
+
end: offset + selectedText.length
|
|
391
399
|
});
|
|
392
|
-
}
|
|
393
|
-
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
394
403
|
break;
|
|
395
404
|
}
|
|
396
405
|
|
|
@@ -571,21 +580,19 @@ var removeEmptyText = function removeEmptyText(yText) {
|
|
|
571
580
|
}
|
|
572
581
|
};
|
|
573
582
|
|
|
574
|
-
var splitLeaf = function splitLeaf(editor
|
|
575
|
-
var
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
var content =
|
|
580
|
-
var rightText = content.substring(
|
|
581
|
-
if (
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
yText["delete"](at.offset, yText.length);
|
|
588
|
-
parent.insert(at.path.slice().reverse()[0] + 1, [newLeave]);
|
|
583
|
+
var splitLeaf = function splitLeaf(editor) {
|
|
584
|
+
var _editor$selection$sta = editor.selection.start,
|
|
585
|
+
leaf = _editor$selection$sta.leaf,
|
|
586
|
+
leafIndex = _editor$selection$sta.leafIndex,
|
|
587
|
+
offset = _editor$selection$sta.offset;
|
|
588
|
+
var content = leafString(leaf);
|
|
589
|
+
var rightText = content.substring(offset, content.length);
|
|
590
|
+
if (offset === content.length) return;
|
|
591
|
+
deleteLeafText(leaf, offset, rightText.length);
|
|
592
|
+
leafNodeContent(leaf).insert(leafIndex + 1, [createLeaf$1(_extends({}, leaf.toJSON(), {
|
|
593
|
+
text: rightText,
|
|
594
|
+
id: undefined
|
|
595
|
+
}))]);
|
|
589
596
|
};
|
|
590
597
|
|
|
591
598
|
var splitNode = function splitNode(editor) {
|
|
@@ -617,17 +624,16 @@ var splitNode = function splitNode(editor) {
|
|
|
617
624
|
return createLeaf$1(leaf.toJSON());
|
|
618
625
|
}))
|
|
619
626
|
})]);
|
|
627
|
+
setPosition(newLeaf.get("id"), {
|
|
628
|
+
offset: 0
|
|
629
|
+
});
|
|
620
630
|
leafContent["delete"](indexOfLeaf + 1, leafNodeContentLength(start.leaf) - indexOfLeaf - 1);
|
|
621
|
-
setTimeout(function () {
|
|
622
|
-
setPosition(newLeaf.get("id"), {
|
|
623
|
-
offset: 0
|
|
624
|
-
});
|
|
625
|
-
}, 10);
|
|
626
631
|
};
|
|
627
632
|
|
|
628
633
|
var doSplit = (!edges.startNode || !edges.endNode) && type !== "multinodes";
|
|
629
634
|
|
|
630
635
|
if ((edges.endNode || edges.startNode) && type === "collapsed") {
|
|
636
|
+
// if cursor is at edge node with insert a default block before of after the current node
|
|
631
637
|
var newNode = createNode(editor.defaultBlock);
|
|
632
638
|
node.parent.insert(indexOfNode + (edges.endNode ? 1 : 0), [newNode]);
|
|
633
639
|
return setTimeout(function () {
|
|
@@ -677,7 +683,7 @@ var nestNode = function nestNode(editor) {
|
|
|
677
683
|
end = _editor$selection.end,
|
|
678
684
|
setPosition = _editor$selection.setPosition;
|
|
679
685
|
var startNode = getNode(start.leaf);
|
|
680
|
-
var
|
|
686
|
+
var nodeCopy = copyNode(startNode);
|
|
681
687
|
var startPath = getPath(startNode);
|
|
682
688
|
|
|
683
689
|
var _startPath$slice$reve = startPath.slice().reverse(),
|
|
@@ -695,10 +701,7 @@ var nestNode = function nestNode(editor) {
|
|
|
695
701
|
var id = start.leaf.get("id");
|
|
696
702
|
var prevChildren = prevNode.get("children");
|
|
697
703
|
startContainer["delete"](index);
|
|
698
|
-
prevChildren.insert(prevChildren.length, [
|
|
699
|
-
children: startJsonNode.children.map(getChildren),
|
|
700
|
-
content: startJsonNode.content.map(getContent)
|
|
701
|
-
}))]);
|
|
704
|
+
prevChildren.insert(prevChildren.length, [nodeCopy]);
|
|
702
705
|
setPosition(id, {
|
|
703
706
|
offset: start.offset
|
|
704
707
|
});
|
|
@@ -722,11 +725,7 @@ var nestNode = function nestNode(editor) {
|
|
|
722
725
|
if (path.length === startPath.length) {
|
|
723
726
|
if (path <= endPathString && path >= startPathString) {
|
|
724
727
|
length++;
|
|
725
|
-
|
|
726
|
-
newNodes.push(createNode(jsonNode.type, _extends({}, jsonNode, {
|
|
727
|
-
children: jsonNode.children.map(getChildren),
|
|
728
|
-
content: jsonNode.content.map(getContent)
|
|
729
|
-
})));
|
|
728
|
+
newNodes.push(copyNode(node));
|
|
730
729
|
}
|
|
731
730
|
}
|
|
732
731
|
}
|
|
@@ -780,17 +779,26 @@ var mergeContentWithPrevLeaf = function mergeContentWithPrevLeaf(editor) {
|
|
|
780
779
|
}
|
|
781
780
|
});
|
|
782
781
|
if (!prevLeaf) return;
|
|
782
|
+
var prevLeafLength = leafLength(prevLeaf);
|
|
783
783
|
leafNodeContent(prevLeaf).insert(leafNodeContentLength(prevLeaf), leafNodeContent(start.leaf).toArray().map(function (leaf) {
|
|
784
784
|
return createLeaf$1(leaf.toJSON());
|
|
785
785
|
}));
|
|
786
786
|
mergeLeafs(leafNodeContent(prevLeaf));
|
|
787
|
-
start.
|
|
787
|
+
var children = start.node.get("children").toArray().map(copyNode);
|
|
788
|
+
|
|
789
|
+
if (children.length) {
|
|
790
|
+
start.node.parent.insert(start.nodeIndex, children);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
start.node.parent["delete"](start.nodeIndex + children.length);
|
|
794
|
+
return [prevLeaf, prevLeafLength]; // (start.leaf.parent.parent as YArray<YNode>).delete(index);
|
|
788
795
|
};
|
|
789
796
|
var mergeContentWithNextLeaf = function mergeContentWithNextLeaf(editor) {
|
|
790
|
-
var start = editor.selection.start;
|
|
797
|
+
var start = editor.selection.start; // 1 .get the next leaf
|
|
798
|
+
|
|
791
799
|
var nextLeaf;
|
|
792
800
|
var stop = false;
|
|
793
|
-
|
|
801
|
+
traverse(editor, function (node, isText) {
|
|
794
802
|
if (isText) {
|
|
795
803
|
if (node === start.leaf) {
|
|
796
804
|
stop = true;
|
|
@@ -799,24 +807,21 @@ var mergeContentWithNextLeaf = function mergeContentWithNextLeaf(editor) {
|
|
|
799
807
|
stop = false;
|
|
800
808
|
}
|
|
801
809
|
}
|
|
802
|
-
}); //
|
|
810
|
+
}); // end of document do nothing
|
|
811
|
+
|
|
812
|
+
if (!nextLeaf) return; // 2 .merge the next leaf with the start leaf
|
|
803
813
|
|
|
804
|
-
console.log(leafNodeContent(nextLeaf).toArray());
|
|
805
814
|
leafNodeContent(start.leaf).insert(leafNodeContentLength(start.leaf), leafNodeContent(nextLeaf).toArray().map(function (leaf) {
|
|
806
815
|
return createLeaf$1(leaf.toJSON());
|
|
807
816
|
}));
|
|
808
|
-
mergeLeafs(leafNodeContent(start.leaf));
|
|
809
|
-
console.log(start.leaf.parent.toJSON());
|
|
810
|
-
var node = getNode(nextLeaf);
|
|
817
|
+
mergeLeafs(leafNodeContent(start.leaf)); // 3 get the merged node children if any and place it where the merged node was
|
|
811
818
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
node.parent["delete"](getIndex(node));
|
|
819
|
+
var node = getNode(nextLeaf);
|
|
820
|
+
var index = getIndex(node);
|
|
821
|
+
var parent = node.parent;
|
|
822
|
+
var children = node.get("children").toArray();
|
|
823
|
+
children.length > 0 && parent.insert(index, children.map(copyNode));
|
|
824
|
+
parent["delete"](index + children.length);
|
|
820
825
|
return nextLeaf;
|
|
821
826
|
};
|
|
822
827
|
var deleteNode = function deleteNode(node, defaultBlock) {
|
|
@@ -862,9 +867,19 @@ var copyNode = function copyNode(node) {
|
|
|
862
867
|
var jsonNode = node.toJSON();
|
|
863
868
|
return createNode(jsonNode.type, _extends({}, jsonNode, {
|
|
864
869
|
children: jsonNode.children.map(getChildren),
|
|
865
|
-
content: jsonNode.content.map(
|
|
870
|
+
content: jsonNode.content.map(createLeaf$1)
|
|
866
871
|
}));
|
|
867
872
|
};
|
|
873
|
+
var nodeString = function nodeString(node) {
|
|
874
|
+
var text = "";
|
|
875
|
+
getNodeContent(node).forEach(function (leaf) {
|
|
876
|
+
text += leafString(leaf);
|
|
877
|
+
});
|
|
878
|
+
getNodeChildren(node).forEach(function (node) {
|
|
879
|
+
text += nodeString(node);
|
|
880
|
+
});
|
|
881
|
+
return text;
|
|
882
|
+
};
|
|
868
883
|
|
|
869
884
|
var nanoid = function nanoid() {
|
|
870
885
|
return "y-" + customAlphabet("346789ABCDEFGHJKLMNPQRTUV-WXYabcdefghijkmnpqrtwxyz", 20)();
|
|
@@ -979,7 +994,7 @@ var toString = function toString(editor) {
|
|
|
979
994
|
var array = editor.children.toArray();
|
|
980
995
|
|
|
981
996
|
for (var i = 0; i < array.length; i++) {
|
|
982
|
-
t +=
|
|
997
|
+
t += nodeString(array[i]);
|
|
983
998
|
}
|
|
984
999
|
|
|
985
1000
|
return t;
|
|
@@ -1067,6 +1082,7 @@ var setLeafData = function setLeafData(leaf, data) {
|
|
|
1067
1082
|
};
|
|
1068
1083
|
var removeIfEmpty = function removeIfEmpty(leaf) {
|
|
1069
1084
|
if (isLeafEmpty(leaf)) {
|
|
1085
|
+
console.log("isEmpty", leafNodeContent(leaf).toJSON());
|
|
1070
1086
|
leafNodeContent(leaf)["delete"](getIndex(leaf)); // if (leafNodeContentLength(leaf) === 0) {
|
|
1071
1087
|
// deleteNode(leafNode(leaf));
|
|
1072
1088
|
// }
|
|
@@ -1112,6 +1128,7 @@ var Dropper = function Dropper() {
|
|
|
1112
1128
|
this.startDrag = function (node, e) {
|
|
1113
1129
|
var _e$dataTransfer;
|
|
1114
1130
|
|
|
1131
|
+
if (!_this.editor.dnd.active) return;
|
|
1115
1132
|
_this.node = node;
|
|
1116
1133
|
var dndIndicator = document.getElementById("dndIndicator");
|
|
1117
1134
|
dndIndicator.style.opacity = "1";
|
|
@@ -1174,6 +1191,8 @@ var Dropper = function Dropper() {
|
|
|
1174
1191
|
};
|
|
1175
1192
|
|
|
1176
1193
|
this.onDrag = function (e) {
|
|
1194
|
+
if (!_this.editor.dnd.active) return;
|
|
1195
|
+
|
|
1177
1196
|
var _this$getHoveredNode = _this.getHoveredNode(e.target),
|
|
1178
1197
|
hoveredElement = _this$getHoveredNode.hoveredElement,
|
|
1179
1198
|
hoveredNode = _this$getHoveredNode.hoveredNode;
|
|
@@ -1338,11 +1357,15 @@ var EdytorSelection = function EdytorSelection() {
|
|
|
1338
1357
|
_this.length = _this.selectedText.length;
|
|
1339
1358
|
_this.range = range;
|
|
1340
1359
|
_this.selection = selection;
|
|
1360
|
+
var startNode = _this.start.offset === 0 && getIndex(_this.start.leaf) === 0;
|
|
1361
|
+
var endNode = _this.end.offset === leafLength(_this.end.leaf) && getIndex(_this.start.leaf) === leafNodeContentLength(_this.end.leaf) - 1;
|
|
1341
1362
|
_this.edges = {
|
|
1342
1363
|
startLeaf: _this.start.offset === 0,
|
|
1343
|
-
startNode: _this.start.offset === 0 && getIndex(_this.start.leaf) === 0,
|
|
1344
1364
|
endLeaf: _this.end.offset === leafLength(_this.end.leaf),
|
|
1345
|
-
|
|
1365
|
+
startNode: startNode,
|
|
1366
|
+
endNode: endNode,
|
|
1367
|
+
startDocument: startNode && _this.start.path.join("") === "00",
|
|
1368
|
+
endDocument: false
|
|
1346
1369
|
};
|
|
1347
1370
|
_this.type = isCollapsed ? "collapsed" : equalPaths ? "singlenode" : _this.start.node === _this.end.node ? "multileaves" : "multinodes";
|
|
1348
1371
|
|
|
@@ -1352,7 +1375,16 @@ var EdytorSelection = function EdytorSelection() {
|
|
|
1352
1375
|
this.onChange = function () {
|
|
1353
1376
|
_this.observers.forEach(function (o) {
|
|
1354
1377
|
return o(_this);
|
|
1355
|
-
});
|
|
1378
|
+
}); // console.log(this.editor.awareness);
|
|
1379
|
+
// if (this.collaborationPosition?.node !== this.start.node.get("id")) {
|
|
1380
|
+
// this.collaborationPosition = {
|
|
1381
|
+
// node: this.start.node.get("id"),
|
|
1382
|
+
// leaf: this.start.leaf.get("id"),
|
|
1383
|
+
// offset: this.start.offset
|
|
1384
|
+
// };
|
|
1385
|
+
// this.editor.awareness.setLocalStateField("position", this.collaborationPosition);
|
|
1386
|
+
// }
|
|
1387
|
+
|
|
1356
1388
|
};
|
|
1357
1389
|
|
|
1358
1390
|
this.setPosition = function (id, _ref) {
|
|
@@ -1364,6 +1396,10 @@ var EdytorSelection = function EdytorSelection() {
|
|
|
1364
1396
|
|
|
1365
1397
|
var node = _this.container.querySelector("#" + id);
|
|
1366
1398
|
|
|
1399
|
+
console.log({
|
|
1400
|
+
node: node
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1367
1403
|
while (node && node.nodeType !== 3 && (_node = node) != null && _node.firstChild) {
|
|
1368
1404
|
var _node;
|
|
1369
1405
|
|
|
@@ -1407,14 +1443,21 @@ var getDataTransfer = function getDataTransfer(e) {
|
|
|
1407
1443
|
};
|
|
1408
1444
|
|
|
1409
1445
|
var onBeforeInput = function onBeforeInput(_ref, e) {
|
|
1410
|
-
var
|
|
1411
|
-
onChange = _ref[1],
|
|
1412
|
-
editor = _ref[2];
|
|
1413
|
-
prevent(e); // console.log(e);
|
|
1446
|
+
var _e$target;
|
|
1414
1447
|
|
|
1448
|
+
var onChange = _ref[1],
|
|
1449
|
+
editor = _ref[2];
|
|
1450
|
+
// console.log(e);
|
|
1415
1451
|
var _editor$selection = editor.selection,
|
|
1416
1452
|
start = _editor$selection.start,
|
|
1417
|
-
length = _editor$selection.length
|
|
1453
|
+
length = _editor$selection.length,
|
|
1454
|
+
setPosition = _editor$selection.setPosition; // if (e.composedPath().some((el) => el.getAttribute && el.getAttribute("data-edytor-void") === "true")) {
|
|
1455
|
+
// return;
|
|
1456
|
+
// }
|
|
1457
|
+
|
|
1458
|
+
var tag = (_e$target = e.target) == null ? void 0 : _e$target.tagName;
|
|
1459
|
+
if (tag === "TEXTAREA" || tag === "INPUT") return;
|
|
1460
|
+
prevent(e);
|
|
1418
1461
|
|
|
1419
1462
|
switch (e.inputType) {
|
|
1420
1463
|
case "insertFromPaste":
|
|
@@ -1511,8 +1554,9 @@ var onBeforeInput = function onBeforeInput(_ref, e) {
|
|
|
1511
1554
|
|
|
1512
1555
|
case "insertReplacementText":
|
|
1513
1556
|
{
|
|
1514
|
-
|
|
1515
|
-
|
|
1557
|
+
replaceLeafText(start.leaf, start.offset, length, getDataTransfer(e));
|
|
1558
|
+
setPosition(start.leafId, {
|
|
1559
|
+
offset: start.offset
|
|
1516
1560
|
});
|
|
1517
1561
|
}
|
|
1518
1562
|
}
|
|
@@ -1537,32 +1581,71 @@ var onKeyDown = function onKeyDown(editor, e) {
|
|
|
1537
1581
|
return editor.undoManager.redo();
|
|
1538
1582
|
}
|
|
1539
1583
|
|
|
1540
|
-
|
|
1541
|
-
var
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1584
|
+
if (editor.hotkeys) {
|
|
1585
|
+
for (var i = 0; i < editor.hotkeys.length; i++) {
|
|
1586
|
+
var _editor$hotkeys$i = editor.hotkeys[i],
|
|
1587
|
+
keys = _editor$hotkeys$i.keys,
|
|
1588
|
+
operation = _editor$hotkeys$i.operation,
|
|
1589
|
+
mark = _editor$hotkeys$i.mark;
|
|
1545
1590
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1591
|
+
if (isHotkey(keys, e)) {
|
|
1592
|
+
e.preventDefault();
|
|
1593
|
+
e.stopPropagation();
|
|
1549
1594
|
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1595
|
+
if (typeof operation === "function") {
|
|
1596
|
+
return operation(editor);
|
|
1597
|
+
}
|
|
1553
1598
|
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1599
|
+
switch (operation) {
|
|
1600
|
+
case "formatText":
|
|
1601
|
+
{
|
|
1602
|
+
return formatText(editor, mark);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1560
1605
|
|
|
1561
|
-
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1562
1608
|
}
|
|
1563
1609
|
}
|
|
1564
1610
|
}
|
|
1565
1611
|
};
|
|
1612
|
+
var defaultHotkeys = [{
|
|
1613
|
+
operation: "formatText",
|
|
1614
|
+
keys: "mod+b",
|
|
1615
|
+
mark: {
|
|
1616
|
+
bold: true
|
|
1617
|
+
}
|
|
1618
|
+
}, {
|
|
1619
|
+
operation: "formatText",
|
|
1620
|
+
keys: "mod+i",
|
|
1621
|
+
mark: {
|
|
1622
|
+
italic: true
|
|
1623
|
+
}
|
|
1624
|
+
}, {
|
|
1625
|
+
operation: "formatText",
|
|
1626
|
+
keys: "mod+u",
|
|
1627
|
+
mark: {
|
|
1628
|
+
underline: true
|
|
1629
|
+
}
|
|
1630
|
+
}, {
|
|
1631
|
+
operation: "formatText",
|
|
1632
|
+
keys: "mod+shift+c",
|
|
1633
|
+
mark: {
|
|
1634
|
+
code: true
|
|
1635
|
+
}
|
|
1636
|
+
}, {
|
|
1637
|
+
operation: "formatText",
|
|
1638
|
+
keys: "mod+shift+x",
|
|
1639
|
+
mark: {
|
|
1640
|
+
strikethrough: true
|
|
1641
|
+
}
|
|
1642
|
+
}, {
|
|
1643
|
+
operation: "formatText",
|
|
1644
|
+
keys: "mod+shift+h",
|
|
1645
|
+
mark: {
|
|
1646
|
+
highlight: true
|
|
1647
|
+
}
|
|
1648
|
+
}];
|
|
1566
1649
|
|
|
1567
1650
|
var onDrop = function onDrop(editor, e) {
|
|
1568
1651
|
var _e$dataTransfer;
|
|
@@ -1587,16 +1670,12 @@ var onDragOver = function onDragOver(editor, e) {
|
|
|
1587
1670
|
}
|
|
1588
1671
|
};
|
|
1589
1672
|
|
|
1590
|
-
var createWebRtcProvider = function createWebRtcProvider(doc, room, opts) {// const fakeDoc = new Doc();
|
|
1591
|
-
};
|
|
1592
|
-
|
|
1593
1673
|
var createWSProvider = function createWSProvider(room) {
|
|
1594
1674
|
return new Promise(function (res) {
|
|
1595
1675
|
var doc = new Doc();
|
|
1596
|
-
var dev = "ws://localhost:1234";
|
|
1597
1676
|
var prod = "wss://edytor-production.up.railway.app";
|
|
1598
1677
|
console.log(process.env.NODE_ENV);
|
|
1599
|
-
var provider = new WebsocketProvider(process.env.NODE_ENV === "production" ? prod :
|
|
1678
|
+
var provider = new WebsocketProvider(process.env.NODE_ENV === "production" ? prod : prod, room || "edytor", doc, {
|
|
1600
1679
|
connect: true
|
|
1601
1680
|
});
|
|
1602
1681
|
provider.on("status", function (_ref) {
|
|
@@ -1609,5 +1688,5 @@ var createWSProvider = function createWSProvider(room) {
|
|
|
1609
1688
|
});
|
|
1610
1689
|
};
|
|
1611
1690
|
|
|
1612
|
-
export { DocFromJson, Dropper, EdytorDoc, EdytorSelection, LeavesHarvest, YNode, applyMarksFromParent, areLeafsMergeable, copyNode, createLeaf$1 as createLeaf, createNode, createWSProvider,
|
|
1691
|
+
export { DocFromJson, Dropper, EdytorDoc, EdytorSelection, LeavesHarvest, YNode, applyMarksFromParent, areLeafsMergeable, copyNode, createLeaf$1 as createLeaf, createNode, createWSProvider, defaultHotkeys, deleteLeafText, deleteNode, deleteText, formatAtEqualPath, formatText, getChildren, getContainerAtPath, getId, getIndex, getLeafAtPath, getNode, getNodeAtPath, getNodeChildren, getNodeContainer, getNodeContent, getPath, hasChildren, insertText, insertTextInLeaf, isLeafEmpty, isNodeContentEmpty, isNodeEmpty, leafData, leafLength, leafNode, leafNodeChildren, leafNodeChildrenLength, leafNodeContent, leafNodeContentLength, leafNodeContentStringLength, leafNodeId, leafString, leafText, mergeContentWithNextLeaf, mergeContentWithPrevLeaf, mergeLeafs, moveNode, nanoid, nestNode, nodeString, onBeforeInput, onDragOver, onDrop, onKeyDown, removeEmptyText, removeIfEmpty, replaceLeafText, setLeafData, setLeafText, splitLeaf, splitNode, toString, traverse };
|
|
1613
1692
|
//# sourceMappingURL=edytor.esm.js.map
|