@quadrats/common 0.7.1 → 0.7.3

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.
@@ -12,7 +12,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
12
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
14
  ***************************************************************************** */
15
- /* global Reflect, Promise */
15
+ /* global Reflect, Promise, SuppressedError, Symbol */
16
16
 
17
17
 
18
18
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -23,6 +23,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
23
23
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
24
  step((generator = generator.apply(thisArg, _arguments || [])).next());
25
25
  });
26
- }
26
+ }
27
+
28
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
29
+ var e = new Error(message);
30
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
31
+ };
27
32
 
28
33
  export { __awaiter };
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from './_virtual/_tslib.js';
2
2
  import { readFileAsDataURL } from '@quadrats/utils';
3
- import { HistoryEditor, Transforms, createParagraphElement } from '@quadrats/core';
3
+ import { HistoryEditor, Transforms, isAboveBlockEmpty, createParagraphElement } from '@quadrats/core';
4
4
  import { FILE_UPLOADER_TYPE } from './constants.js';
5
5
  import { getFilesFromInput } from './getFilesFromInput.js';
6
6
 
@@ -64,8 +64,17 @@ function createFileUploader(options = {}) {
64
64
  files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
65
65
  yield prev;
66
66
  return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
67
+ var _a, _b, _c;
67
68
  if (fileUploaderElement) {
68
- Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], options);
69
+ // Clear empty node
70
+ if (isAboveBlockEmpty(editor)) {
71
+ Transforms.removeNodes(editor, {
72
+ at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
73
+ });
74
+ }
75
+ Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], {
76
+ at: ((_b = editor.selection) === null || _b === void 0 ? void 0 : _b.anchor.path.length) ? [((_c = editor.selection) === null || _c === void 0 ? void 0 : _c.anchor.path[0]) + 1] : undefined,
77
+ });
69
78
  Transforms.move(editor);
70
79
  }
71
80
  });
@@ -45,7 +45,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
45
45
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
46
46
  PERFORMANCE OF THIS SOFTWARE.
47
47
  ***************************************************************************** */
48
- /* global Reflect, Promise */
48
+ /* global Reflect, Promise, SuppressedError, Symbol */
49
49
 
50
50
 
51
51
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -56,7 +56,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
56
56
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
57
  step((generator = generator.apply(thisArg, _arguments || [])).next());
58
58
  });
59
- }
59
+ }
60
+
61
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
62
+ var e = new Error(message);
63
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
64
+ };
60
65
 
61
66
  function createFileUploader(options = {}) {
62
67
  const { type = FILE_UPLOADER_TYPE } = options;
@@ -118,8 +123,17 @@ function createFileUploader(options = {}) {
118
123
  files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
119
124
  yield prev;
120
125
  return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
126
+ var _a, _b, _c;
121
127
  if (fileUploaderElement) {
122
- core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
128
+ // Clear empty node
129
+ if (core.isAboveBlockEmpty(editor)) {
130
+ core.Transforms.removeNodes(editor, {
131
+ at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
132
+ });
133
+ }
134
+ core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], {
135
+ at: ((_b = editor.selection) === null || _b === void 0 ? void 0 : _b.anchor.path.length) ? [((_c = editor.selection) === null || _c === void 0 ? void 0 : _c.anchor.path[0]) + 1] : undefined,
136
+ });
123
137
  core.Transforms.move(editor);
124
138
  }
125
139
  });
@@ -19,17 +19,6 @@ function createImage(options = {}) {
19
19
  const isSelectionInImage = editor => isNodesInImage(editor);
20
20
  const isSelectionInImageCaption = editor => isNodesTypeIn(editor, [types.caption]);
21
21
  const isCollapsedOnImage = editor => !!editor.selection && Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
22
- const previousNodeIsCaption = (editor) => {
23
- const previous = Editor.previous(editor);
24
- if (!previous)
25
- return false;
26
- const [, previousLocation] = previous;
27
- const previousWrapper = Editor.parent(editor, previousLocation);
28
- if (!previousWrapper)
29
- return false;
30
- const [previousWrapperNode] = previousWrapper;
31
- return previousWrapperNode.type === types.caption;
32
- };
33
22
  const createImageElement = (src, hosting) => {
34
23
  const imageElement = {
35
24
  type: types.image,
@@ -111,27 +100,6 @@ function createImage(options = {}) {
111
100
  if ((captionPath && Editor[isEdgeMethodName](editor, selection.focus, captionPath))) {
112
101
  return;
113
102
  }
114
- // Remove image element when backwards from external
115
- if (!captionPath && previousNodeIsCaption(editor)) {
116
- const previous = Editor.previous(editor);
117
- if (!previous)
118
- return false;
119
- const [, previousLocation] = previous;
120
- const previousWrapper = Editor.parent(editor, previousLocation);
121
- if (!previousWrapper)
122
- return false;
123
- const [previousWrapperNode, wrapperLocation] = previousWrapper;
124
- if (previousWrapperNode.type === types.caption) {
125
- const imageContainer = Editor.parent(editor, wrapperLocation);
126
- if (imageContainer) {
127
- const [imageElement, imageLocation] = imageContainer;
128
- if (imageElement.type === types.figure) {
129
- Transforms.removeNodes(editor, { at: imageLocation });
130
- }
131
- }
132
- }
133
- return;
134
- }
135
103
  }
136
104
  origin();
137
105
  };
@@ -45,17 +45,6 @@ function createImage(options = {}) {
45
45
  const isSelectionInImage = editor => isNodesInImage(editor);
46
46
  const isSelectionInImageCaption = editor => core.isNodesTypeIn(editor, [types.caption]);
47
47
  const isCollapsedOnImage = editor => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
48
- const previousNodeIsCaption = (editor) => {
49
- const previous = core.Editor.previous(editor);
50
- if (!previous)
51
- return false;
52
- const [, previousLocation] = previous;
53
- const previousWrapper = core.Editor.parent(editor, previousLocation);
54
- if (!previousWrapper)
55
- return false;
56
- const [previousWrapperNode] = previousWrapper;
57
- return previousWrapperNode.type === types.caption;
58
- };
59
48
  const createImageElement = (src, hosting) => {
60
49
  const imageElement = {
61
50
  type: types.image,
@@ -137,27 +126,6 @@ function createImage(options = {}) {
137
126
  if ((captionPath && core.Editor[isEdgeMethodName](editor, selection.focus, captionPath))) {
138
127
  return;
139
128
  }
140
- // Remove image element when backwards from external
141
- if (!captionPath && previousNodeIsCaption(editor)) {
142
- const previous = core.Editor.previous(editor);
143
- if (!previous)
144
- return false;
145
- const [, previousLocation] = previous;
146
- const previousWrapper = core.Editor.parent(editor, previousLocation);
147
- if (!previousWrapper)
148
- return false;
149
- const [previousWrapperNode, wrapperLocation] = previousWrapper;
150
- if (previousWrapperNode.type === types.caption) {
151
- const imageContainer = core.Editor.parent(editor, wrapperLocation);
152
- if (imageContainer) {
153
- const [imageElement, imageLocation] = imageContainer;
154
- if (imageElement.type === types.figure) {
155
- core.Transforms.removeNodes(editor, { at: imageLocation });
156
- }
157
- }
158
- }
159
- return;
160
- }
161
129
  }
162
130
  origin();
163
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadrats/common",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
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.7.0",
21
+ "@quadrats/core": "^0.7.2",
22
22
  "@quadrats/locales": "^0.7.0",
23
- "@quadrats/utils": "^0.7.1"
23
+ "@quadrats/utils": "^0.7.2"
24
24
  }
25
25
  }