@quadrats/common 0.7.2 → 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.
- package/file-uploader/createFileUploader.js +11 -2
- package/file-uploader/index.cjs.js +10 -1
- package/image/createImage.js +0 -32
- package/image/index.cjs.js +0 -32
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
});
|
|
@@ -123,8 +123,17 @@ function createFileUploader(options = {}) {
|
|
|
123
123
|
files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
yield prev;
|
|
125
125
|
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
126
|
+
var _a, _b, _c;
|
|
126
127
|
if (fileUploaderElement) {
|
|
127
|
-
|
|
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
|
+
});
|
|
128
137
|
core.Transforms.move(editor);
|
|
129
138
|
}
|
|
130
139
|
});
|
package/image/createImage.js
CHANGED
|
@@ -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
|
};
|
package/image/index.cjs.js
CHANGED
|
@@ -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
|
};
|