@quadrats/common 0.5.10 → 0.6.4

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,38 +1,35 @@
1
- import { isNodesTypeIn, toggleNodesType, Editor, Transforms, createParagraphElement, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
1
+ import { isNodesTypeIn, unwrapNodesByTypes, wrapNodesWithUnhangRange } from '@quadrats/core';
2
2
  import { BLOCKQUOTE_TYPE } from './constants.js';
3
3
 
4
4
  function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
5
+ const unwrapBlockquote = (editor) => {
6
+ unwrapNodesByTypes(editor, [type]);
7
+ };
8
+ const wrapBlockquote = (editor) => {
9
+ const element = {
10
+ type,
11
+ children: [],
12
+ };
13
+ wrapNodesWithUnhangRange(editor, element, { split: true });
14
+ };
15
+ const isSelectionInBlockquote = editor => (isNodesTypeIn(editor, [type], { mode: 'highest' }));
5
16
  return {
6
17
  type,
7
- isSelectionInBlockquote: editor => isNodesTypeIn(editor, [type]),
18
+ unwrapBlockquote,
19
+ wrapBlockquote,
20
+ isSelectionInBlockquote,
8
21
  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
+ const actived = isSelectionInBlockquote(editor);
23
+ if (editor.selection) {
24
+ if (actived) {
25
+ unwrapBlockquote(editor);
26
+ }
27
+ else {
28
+ wrapBlockquote(editor);
22
29
  }
23
30
  }
24
31
  },
25
32
  with(editor) {
26
- const { normalizeNode } = editor;
27
- editor.normalizeNode = (entry) => {
28
- const [node] = entry;
29
- if (Element.isElement(node) && node.type === type) {
30
- if (normalizeOnlyInlineOrTextInChildren(editor, entry)) {
31
- return;
32
- }
33
- }
34
- normalizeNode(entry);
35
- };
36
33
  return editor;
37
34
  },
38
35
  };
@@ -7,37 +7,34 @@ var core = require('@quadrats/core');
7
7
  const BLOCKQUOTE_TYPE = 'blockquote';
8
8
 
9
9
  function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
10
+ const unwrapBlockquote = (editor) => {
11
+ core.unwrapNodesByTypes(editor, [type]);
12
+ };
13
+ const wrapBlockquote = (editor) => {
14
+ const element = {
15
+ type,
16
+ children: [],
17
+ };
18
+ core.wrapNodesWithUnhangRange(editor, element, { split: true });
19
+ };
20
+ const isSelectionInBlockquote = editor => (core.isNodesTypeIn(editor, [type], { mode: 'highest' }));
10
21
  return {
11
22
  type,
12
- isSelectionInBlockquote: editor => core.isNodesTypeIn(editor, [type]),
23
+ unwrapBlockquote,
24
+ wrapBlockquote,
25
+ isSelectionInBlockquote,
13
26
  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
+ const actived = isSelectionInBlockquote(editor);
28
+ if (editor.selection) {
29
+ if (actived) {
30
+ unwrapBlockquote(editor);
31
+ }
32
+ else {
33
+ wrapBlockquote(editor);
27
34
  }
28
35
  }
29
36
  },
30
37
  with(editor) {
31
- const { normalizeNode } = editor;
32
- editor.normalizeNode = (entry) => {
33
- const [node] = entry;
34
- if (core.Element.isElement(node) && node.type === type) {
35
- if (core.normalizeOnlyInlineOrTextInChildren(editor, entry)) {
36
- return;
37
- }
38
- }
39
- normalizeNode(entry);
40
- };
41
38
  return editor;
42
39
  },
43
40
  };
@@ -2,6 +2,8 @@ import { Editor, QuadratsElement, Withable, WithElementType } from '@quadrats/co
2
2
  export interface BlockquoteElement extends QuadratsElement, WithElementType {
3
3
  }
4
4
  export interface Blockquote<T extends Editor = Editor> extends WithElementType, Withable {
5
+ unwrapBlockquote(editor: T): void;
6
+ wrapBlockquote(editor: T): void;
5
7
  isSelectionInBlockquote(editor: T): boolean;
6
8
  toggleBlockquote(editor: T): void;
7
9
  }
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from './_virtual/_tslib.js';
2
2
  import { readFileAsDataURL } from '@quadrats/utils';
3
- import { Transforms, createParagraphElement } from '@quadrats/core';
3
+ import { Transforms, createParagraphElement, HistoryEditor } from '@quadrats/core';
4
4
  import { FILE_UPLOADER_TYPE } from './constants.js';
5
5
  import { getFilesFromInput } from './getFilesFromInput.js';
6
6
 
@@ -25,8 +25,10 @@ function createFileUploader(options = {}) {
25
25
  if (xhr.status < 400) {
26
26
  const path = getPath();
27
27
  if (path) {
28
- Transforms.removeNodes(editor, { at: path });
29
- Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
28
+ HistoryEditor.withoutSaving(editor, () => {
29
+ Transforms.removeNodes(editor, { at: path });
30
+ Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
31
+ });
30
32
  }
31
33
  }
32
34
  else {
@@ -79,8 +79,10 @@ function createFileUploader(options = {}) {
79
79
  if (xhr.status < 400) {
80
80
  const path = getPath();
81
81
  if (path) {
82
- core.Transforms.removeNodes(editor, { at: path });
83
- core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
82
+ core.HistoryEditor.withoutSaving(editor, () => {
83
+ core.Transforms.removeNodes(editor, { at: path });
84
+ core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
85
+ });
84
86
  }
85
87
  }
86
88
  else {
@@ -5,13 +5,13 @@ import { FOOTNOTE_TYPE } from './constants.js';
5
5
  function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
6
6
  const isSelectionInFootnote = editor => isNodesTypeIn(editor, [type]);
7
7
  const getFootnoteText = (editor) => {
8
- var _a, _b, _c;
8
+ var _a, _b;
9
9
  const at = editor.selection;
10
10
  if (!at) {
11
11
  return '';
12
12
  }
13
13
  const firstNode = (_b = (_a = Array.from(getNodes(editor, { at, match: node => node.type === type }))) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0];
14
- return (_c = firstNode) === null || _c === void 0 ? void 0 : _c.footnote;
14
+ return firstNode === null || firstNode === void 0 ? void 0 : firstNode.footnote;
15
15
  };
16
16
  const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
17
17
  var _a;
@@ -10,13 +10,13 @@ const FOOTNOTE_TYPE = 'footnote';
10
10
  function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
11
11
  const isSelectionInFootnote = editor => core.isNodesTypeIn(editor, [type]);
12
12
  const getFootnoteText = (editor) => {
13
- var _a, _b, _c;
13
+ var _a, _b;
14
14
  const at = editor.selection;
15
15
  if (!at) {
16
16
  return '';
17
17
  }
18
18
  const firstNode = (_b = (_a = Array.from(core.getNodes(editor, { at, match: node => node.type === type }))) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0];
19
- return (_c = firstNode) === null || _c === void 0 ? void 0 : _c.footnote;
19
+ return firstNode === null || firstNode === void 0 ? void 0 : firstNode.footnote;
20
20
  };
21
21
  const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
22
22
  var _a;
@@ -68,6 +68,7 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
68
68
  }
69
69
  else {
70
70
  insertLink(editor, url, { at });
71
+ Transforms.move(editor, { distance: url.length });
71
72
  }
72
73
  return;
73
74
  }
package/link/index.cjs.js CHANGED
@@ -73,6 +73,7 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
73
73
  }
74
74
  else {
75
75
  insertLink(editor, url, { at });
76
+ core.Transforms.move(editor, { distance: url.length });
76
77
  }
77
78
  return;
78
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadrats/common",
3
- "version": "0.5.10",
3
+ "version": "0.6.4",
4
4
  "description": "",
5
5
  "author": "Rytass",
6
6
  "homepage": "https://github.com/Quadrats/quadrats#readme",
@@ -18,8 +18,8 @@
18
18
  "url": "https://github.com/Quadrats/quadrats/issues"
19
19
  },
20
20
  "dependencies": {
21
- "@quadrats/core": "^0.5.9",
22
- "@quadrats/locales": "^0.5.0",
23
- "@quadrats/utils": "^0.5.0"
21
+ "@quadrats/core": "^0.6.4",
22
+ "@quadrats/locales": "^0.6.0",
23
+ "@quadrats/utils": "^0.6.0"
24
24
  }
25
25
  }