@quadrats/common 0.5.1 → 0.5.2
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.
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
import { isNodesTypeIn, toggleNodesType, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
|
|
1
|
+
import { isNodesTypeIn, toggleNodesType, Editor, Transforms, createParagraphElement, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
|
|
2
2
|
import { BLOCKQUOTE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
|
5
5
|
return {
|
|
6
6
|
type,
|
|
7
7
|
isSelectionInBlockquote: editor => isNodesTypeIn(editor, [type]),
|
|
8
|
-
toggleBlockquote: editor =>
|
|
8
|
+
toggleBlockquote: (editor) => {
|
|
9
|
+
const actived = isNodesTypeIn(editor, [type]);
|
|
10
|
+
toggleNodesType(editor, type);
|
|
11
|
+
if (!actived) {
|
|
12
|
+
if (editor.selection) {
|
|
13
|
+
// Select to line end
|
|
14
|
+
const originPoint = Editor.point(editor, editor.selection.focus);
|
|
15
|
+
Transforms.move(editor, { unit: 'line', edge: 'end' });
|
|
16
|
+
Transforms.collapse(editor, { edge: 'end' });
|
|
17
|
+
// Only last block add paragraph automatically
|
|
18
|
+
if (!Editor.next(editor)) {
|
|
19
|
+
Transforms.insertNodes(editor, [createParagraphElement()]);
|
|
20
|
+
}
|
|
21
|
+
Transforms.select(editor, originPoint);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
9
25
|
with(editor) {
|
|
10
26
|
const { normalizeNode } = editor;
|
|
11
27
|
editor.normalizeNode = (entry) => {
|
package/blockquote/index.cjs.js
CHANGED
|
@@ -10,7 +10,23 @@ function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
|
|
10
10
|
return {
|
|
11
11
|
type,
|
|
12
12
|
isSelectionInBlockquote: editor => core.isNodesTypeIn(editor, [type]),
|
|
13
|
-
toggleBlockquote: editor =>
|
|
13
|
+
toggleBlockquote: (editor) => {
|
|
14
|
+
const actived = core.isNodesTypeIn(editor, [type]);
|
|
15
|
+
core.toggleNodesType(editor, type);
|
|
16
|
+
if (!actived) {
|
|
17
|
+
if (editor.selection) {
|
|
18
|
+
// Select to line end
|
|
19
|
+
const originPoint = core.Editor.point(editor, editor.selection.focus);
|
|
20
|
+
core.Transforms.move(editor, { unit: 'line', edge: 'end' });
|
|
21
|
+
core.Transforms.collapse(editor, { edge: 'end' });
|
|
22
|
+
// Only last block add paragraph automatically
|
|
23
|
+
if (!core.Editor.next(editor)) {
|
|
24
|
+
core.Transforms.insertNodes(editor, [core.createParagraphElement()]);
|
|
25
|
+
}
|
|
26
|
+
core.Transforms.select(editor, originPoint);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
14
30
|
with(editor) {
|
|
15
31
|
const { normalizeNode } = editor;
|
|
16
32
|
editor.normalizeNode = (entry) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Rytass",
|
|
6
6
|
"homepage": "https://github.com/Quadrats/quadrats#readme",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"url": "https://github.com/Quadrats/quadrats/issues"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@quadrats/core": "^0.5.
|
|
21
|
+
"@quadrats/core": "^0.5.2",
|
|
22
22
|
"@quadrats/locales": "^0.5.0",
|
|
23
23
|
"@quadrats/utils": "^0.5.0"
|
|
24
24
|
}
|