@quadrats/react 1.1.6 → 1.1.7

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.
@@ -4,7 +4,7 @@ import { createRenderElement } from '@quadrats/react';
4
4
  import { createOnKeyDownBreak, COMMON_SOFT_BREAK_HOTKEY } from '@quadrats/react/line-break';
5
5
  import { BLOCKQUOTE_HOTKEY } from './constants.js';
6
6
  import { defaultRenderBlockquoteElement } from './defaultRenderBlockquoteElement.js';
7
- import { getNodesByTypes, PARAGRAPH_TYPE, Editor, Transforms } from '@quadrats/core';
7
+ import { getNodesByTypes, PARAGRAPH_TYPE, Editor, Transforms, Path } from '@quadrats/core';
8
8
 
9
9
  const BLOCKQUOTE_EXIT_BREAK_HOTKEY = 'enter';
10
10
  function createReactBlockquote(options = {}) {
@@ -38,25 +38,40 @@ function createReactBlockquote(options = {}) {
38
38
  core.toggleBlockquote(editor);
39
39
  }
40
40
  else {
41
- if (editor.selection && isHotkey(BLOCKQUOTE_EXIT_BREAK_HOTKEY, event)) {
41
+ if (editor.selection) {
42
42
  const [highestIsQuote] = getNodesByTypes(editor, [type], { mode: 'highest' });
43
43
  const [selectInParagraph] = getNodesByTypes(editor, [PARAGRAPH_TYPE], { at: editor.selection });
44
- if (highestIsQuote && selectInParagraph) {
45
- const [, quotePath] = highestIsQuote;
46
- const isEnd = Editor.isEnd(editor, Editor.point(editor, editor.selection), quotePath);
47
- const [paragraphNode] = selectInParagraph;
48
- const text = paragraphNode.children[0].text;
49
- const isEmptyParagraph = text.length === 0;
50
- // move out the empty paragraph if end of the quote
51
- if (isEnd && isEmptyParagraph) {
52
- event.preventDefault();
53
- const moveto = quotePath.slice();
54
- moveto[(quotePath.length - 1)] += 1;
55
- Transforms.moveNodes(editor, {
56
- at: editor.selection,
57
- to: moveto,
58
- });
59
- return;
44
+ if (isHotkey(BLOCKQUOTE_EXIT_BREAK_HOTKEY, event)) {
45
+ if (highestIsQuote && selectInParagraph) {
46
+ const [, quotePath] = highestIsQuote;
47
+ const isEnd = Editor.isEnd(editor, Editor.point(editor, editor.selection), quotePath);
48
+ const [paragraphNode] = selectInParagraph;
49
+ const text = paragraphNode.children[0].text;
50
+ const isEmptyParagraph = text.length === 0;
51
+ // move out the empty paragraph if end of the quote
52
+ if (isEnd && isEmptyParagraph) {
53
+ event.preventDefault();
54
+ const moveto = quotePath.slice();
55
+ moveto[quotePath.length - 1] += 1;
56
+ Transforms.moveNodes(editor, {
57
+ at: editor.selection,
58
+ to: moveto,
59
+ });
60
+ return;
61
+ }
62
+ }
63
+ }
64
+ else if (event.key === 'Backspace') {
65
+ if (highestIsQuote && selectInParagraph) {
66
+ const [, quotePath] = highestIsQuote;
67
+ const [paragraphNode, currentPath] = selectInParagraph;
68
+ const isFirst = Path.equals(currentPath, quotePath.concat(0));
69
+ const text = paragraphNode.children[0].text;
70
+ if (isFirst && !text) {
71
+ event.preventDefault();
72
+ core.toggleBlockquote(editor);
73
+ return;
74
+ }
60
75
  }
61
76
  }
62
77
  }
@@ -50,25 +50,40 @@ function createReactBlockquote(options = {}) {
50
50
  core$1.toggleBlockquote(editor);
51
51
  }
52
52
  else {
53
- if (editor.selection && isHotkey(BLOCKQUOTE_EXIT_BREAK_HOTKEY, event)) {
53
+ if (editor.selection) {
54
54
  const [highestIsQuote] = core.getNodesByTypes(editor, [type], { mode: 'highest' });
55
55
  const [selectInParagraph] = core.getNodesByTypes(editor, [core.PARAGRAPH_TYPE], { at: editor.selection });
56
- if (highestIsQuote && selectInParagraph) {
57
- const [, quotePath] = highestIsQuote;
58
- const isEnd = core.Editor.isEnd(editor, core.Editor.point(editor, editor.selection), quotePath);
59
- const [paragraphNode] = selectInParagraph;
60
- const text = paragraphNode.children[0].text;
61
- const isEmptyParagraph = text.length === 0;
62
- // move out the empty paragraph if end of the quote
63
- if (isEnd && isEmptyParagraph) {
64
- event.preventDefault();
65
- const moveto = quotePath.slice();
66
- moveto[(quotePath.length - 1)] += 1;
67
- core.Transforms.moveNodes(editor, {
68
- at: editor.selection,
69
- to: moveto,
70
- });
71
- return;
56
+ if (isHotkey(BLOCKQUOTE_EXIT_BREAK_HOTKEY, event)) {
57
+ if (highestIsQuote && selectInParagraph) {
58
+ const [, quotePath] = highestIsQuote;
59
+ const isEnd = core.Editor.isEnd(editor, core.Editor.point(editor, editor.selection), quotePath);
60
+ const [paragraphNode] = selectInParagraph;
61
+ const text = paragraphNode.children[0].text;
62
+ const isEmptyParagraph = text.length === 0;
63
+ // move out the empty paragraph if end of the quote
64
+ if (isEnd && isEmptyParagraph) {
65
+ event.preventDefault();
66
+ const moveto = quotePath.slice();
67
+ moveto[quotePath.length - 1] += 1;
68
+ core.Transforms.moveNodes(editor, {
69
+ at: editor.selection,
70
+ to: moveto,
71
+ });
72
+ return;
73
+ }
74
+ }
75
+ }
76
+ else if (event.key === 'Backspace') {
77
+ if (highestIsQuote && selectInParagraph) {
78
+ const [, quotePath] = highestIsQuote;
79
+ const [paragraphNode, currentPath] = selectInParagraph;
80
+ const isFirst = core.Path.equals(currentPath, quotePath.concat(0));
81
+ const text = paragraphNode.children[0].text;
82
+ if (isFirst && !text) {
83
+ event.preventDefault();
84
+ core$1.toggleBlockquote(editor);
85
+ return;
86
+ }
72
87
  }
73
88
  }
74
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadrats/react",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "author": "Rytass",
6
6
  "homepage": "https://github.com/Quadrats/quadrats#readme",
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/Quadrats/quadrats/issues"
21
21
  },
22
22
  "dependencies": {
23
- "@quadrats/common": "^1.1.5",
23
+ "@quadrats/common": "^1.1.7",
24
24
  "@quadrats/core": "^1.1.5",
25
25
  "@quadrats/icons": "^1.1.1",
26
26
  "@quadrats/locales": "^1.0.0",