@quadrats/common 0.6.1 → 0.6.5
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 +2 -2
- package/file-uploader/index.cjs.js +2 -2
- package/file-uploader/typings.d.ts +18 -0
- package/footnote/createFootnote.js +2 -2
- package/footnote/index.cjs.js +2 -2
- package/image/createImage.js +45 -2
- package/image/index.cjs.js +44 -1
- package/package.json +3 -3
|
@@ -7,7 +7,7 @@ import { getFilesFromInput } from './getFilesFromInput.js';
|
|
|
7
7
|
function createFileUploader(options = {}) {
|
|
8
8
|
const { type = FILE_UPLOADER_TYPE } = options;
|
|
9
9
|
const createFileUploaderElement = (editor, file, options) => __awaiter(this, void 0, void 0, function* () {
|
|
10
|
-
const { createElement, getBody, getHeaders, getUrl, } = options;
|
|
10
|
+
const { createElement, getBody, getHeaders, getUrl, uploader, } = options;
|
|
11
11
|
const [mime] = file.type.split('/');
|
|
12
12
|
const createByMime = createElement[mime];
|
|
13
13
|
if (!createByMime) {
|
|
@@ -15,7 +15,7 @@ function createFileUploader(options = {}) {
|
|
|
15
15
|
}
|
|
16
16
|
const { dataURL: createElementByDataURL, response: createElementByResponse } = createByMime;
|
|
17
17
|
const headers = yield (getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders(file));
|
|
18
|
-
const xhr = new XMLHttpRequest();
|
|
18
|
+
const xhr = uploader || new XMLHttpRequest();
|
|
19
19
|
const dataURL = yield readFileAsDataURL(file);
|
|
20
20
|
let sent = false;
|
|
21
21
|
const fileUploaderElement = {
|
|
@@ -61,7 +61,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
61
61
|
function createFileUploader(options = {}) {
|
|
62
62
|
const { type = FILE_UPLOADER_TYPE } = options;
|
|
63
63
|
const createFileUploaderElement = (editor, file, options) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const { createElement, getBody, getHeaders, getUrl, } = options;
|
|
64
|
+
const { createElement, getBody, getHeaders, getUrl, uploader, } = options;
|
|
65
65
|
const [mime] = file.type.split('/');
|
|
66
66
|
const createByMime = createElement[mime];
|
|
67
67
|
if (!createByMime) {
|
|
@@ -69,7 +69,7 @@ function createFileUploader(options = {}) {
|
|
|
69
69
|
}
|
|
70
70
|
const { dataURL: createElementByDataURL, response: createElementByResponse } = createByMime;
|
|
71
71
|
const headers = yield (getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders(file));
|
|
72
|
-
const xhr = new XMLHttpRequest();
|
|
72
|
+
const xhr = uploader || new XMLHttpRequest();
|
|
73
73
|
const dataURL = yield utils.readFileAsDataURL(file);
|
|
74
74
|
let sent = false;
|
|
75
75
|
const fileUploaderElement = {
|
|
@@ -18,6 +18,22 @@ export declare type FileUploaderCreateElementByResponse = (response: any) => Qua
|
|
|
18
18
|
export declare type FileUploaderGetBody = (file: File) => BodyInit;
|
|
19
19
|
export declare type FileUploaderGetHeaders = (file: File) => XHRUploadHeaders | Promise<XHRUploadHeaders>;
|
|
20
20
|
export declare type FileUploaderGetUrl = (file: File) => string;
|
|
21
|
+
interface FileUploaderUploadImplementOnProgressArgs {
|
|
22
|
+
loaded: number;
|
|
23
|
+
total: number;
|
|
24
|
+
}
|
|
25
|
+
interface FileUploaderUploadImplement {
|
|
26
|
+
onprogress: ((options: FileUploaderUploadImplementOnProgressArgs) => void) | null;
|
|
27
|
+
}
|
|
28
|
+
interface FileUploaderImplement {
|
|
29
|
+
onload: (() => void) | null;
|
|
30
|
+
open: (method: string, url: string | URL) => void;
|
|
31
|
+
setRequestHeader: (key: string, value: string) => void;
|
|
32
|
+
send(body?: Document | XMLHttpRequestBodyInit | null): void;
|
|
33
|
+
readonly status: number;
|
|
34
|
+
readonly response: any;
|
|
35
|
+
readonly upload: FileUploaderUploadImplement;
|
|
36
|
+
}
|
|
21
37
|
export interface FileUploaderCreateFileUploaderElementOptions {
|
|
22
38
|
createElement: {
|
|
23
39
|
[mime in string]?: {
|
|
@@ -28,6 +44,7 @@ export interface FileUploaderCreateFileUploaderElementOptions {
|
|
|
28
44
|
getBody: FileUploaderGetBody;
|
|
29
45
|
getHeaders?: FileUploaderGetHeaders;
|
|
30
46
|
getUrl: FileUploaderGetUrl;
|
|
47
|
+
uploader?: FileUploaderImplement;
|
|
31
48
|
}
|
|
32
49
|
export declare type FileUploaderUploadOptions = FileUploaderCreateFileUploaderElementOptions & GetFilesFromInputOptions & TransformsInsertNodesOptions;
|
|
33
50
|
export interface FileUploader<T extends Editor = Editor> extends Withable {
|
|
@@ -35,3 +52,4 @@ export interface FileUploader<T extends Editor = Editor> extends Withable {
|
|
|
35
52
|
createFileUploaderElement(editor: T, file: File, options: FileUploaderCreateFileUploaderElementOptions): Promise<FileUploaderElement | undefined>;
|
|
36
53
|
upload(editor: T, options: FileUploaderUploadOptions): Promise<void>;
|
|
37
54
|
}
|
|
55
|
+
export {};
|
|
@@ -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
|
|
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
|
|
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;
|
package/footnote/index.cjs.js
CHANGED
|
@@ -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
|
|
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
|
|
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;
|
package/image/createImage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isImageUrl } from '@quadrats/utils';
|
|
2
|
-
import { getAboveByTypes,
|
|
2
|
+
import { getAboveByTypes, Editor, Transforms, createParagraphElement, Element, isNodesTypeIn, normalizeVoidElementChildren, normalizeOnlyInlineOrTextInChildren, Range } from '@quadrats/core';
|
|
3
3
|
import { IMAGE_TYPES } from './constants.js';
|
|
4
4
|
|
|
5
5
|
function resolveSizeSteps(steps) {
|
|
@@ -19,6 +19,17 @@ 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
|
+
};
|
|
22
33
|
const createImageElement = (src, hosting) => {
|
|
23
34
|
const imageElement = {
|
|
24
35
|
type: types.image,
|
|
@@ -97,7 +108,30 @@ function createImage(options = {}) {
|
|
|
97
108
|
*/
|
|
98
109
|
if (selection && Range.isCollapsed(selection)) {
|
|
99
110
|
const [, captionPath] = getAboveImageCaption(editor) || [];
|
|
100
|
-
if (captionPath && Editor[isEdgeMethodName](editor, selection.focus, captionPath)) {
|
|
111
|
+
if ((captionPath && Editor[isEdgeMethodName](editor, selection.focus, captionPath))) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
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
|
+
console.log(imageLocation, imageContainer);
|
|
129
|
+
if (imageElement.type === types.figure) {
|
|
130
|
+
console.log('???');
|
|
131
|
+
Transforms.removeNodes(editor, { at: imageLocation });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
101
135
|
return;
|
|
102
136
|
}
|
|
103
137
|
}
|
|
@@ -115,6 +149,15 @@ function createImage(options = {}) {
|
|
|
115
149
|
* Avoid from splitting children of caption.
|
|
116
150
|
*/
|
|
117
151
|
if (captionEntry) {
|
|
152
|
+
const [, captionLocation] = captionEntry;
|
|
153
|
+
const imageEntry = Editor.parent(editor, captionLocation);
|
|
154
|
+
if (imageEntry) {
|
|
155
|
+
const [imageElement, imagePosition] = imageEntry;
|
|
156
|
+
if (imageElement.type === types.figure) {
|
|
157
|
+
Transforms.insertNodes(editor, createParagraphElement(), { at: Editor.after(editor, imagePosition) });
|
|
158
|
+
Transforms.move(editor);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
118
161
|
return;
|
|
119
162
|
}
|
|
120
163
|
insertBreak();
|
package/image/index.cjs.js
CHANGED
|
@@ -47,6 +47,17 @@ function createImage(options = {}) {
|
|
|
47
47
|
const isSelectionInImage = editor => isNodesInImage(editor);
|
|
48
48
|
const isSelectionInImageCaption = editor => core.isNodesTypeIn(editor, [types.caption]);
|
|
49
49
|
const isCollapsedOnImage = editor => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
|
|
50
|
+
const previousNodeIsCaption = (editor) => {
|
|
51
|
+
const previous = core.Editor.previous(editor);
|
|
52
|
+
if (!previous)
|
|
53
|
+
return false;
|
|
54
|
+
const [, previousLocation] = previous;
|
|
55
|
+
const previousWrapper = core.Editor.parent(editor, previousLocation);
|
|
56
|
+
if (!previousWrapper)
|
|
57
|
+
return false;
|
|
58
|
+
const [previousWrapperNode] = previousWrapper;
|
|
59
|
+
return previousWrapperNode.type === types.caption;
|
|
60
|
+
};
|
|
50
61
|
const createImageElement = (src, hosting) => {
|
|
51
62
|
const imageElement = {
|
|
52
63
|
type: types.image,
|
|
@@ -125,7 +136,30 @@ function createImage(options = {}) {
|
|
|
125
136
|
*/
|
|
126
137
|
if (selection && core.Range.isCollapsed(selection)) {
|
|
127
138
|
const [, captionPath] = getAboveImageCaption(editor) || [];
|
|
128
|
-
if (captionPath && core.Editor[isEdgeMethodName](editor, selection.focus, captionPath)) {
|
|
139
|
+
if ((captionPath && core.Editor[isEdgeMethodName](editor, selection.focus, captionPath))) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Remove image element when backwards from external
|
|
143
|
+
if (!captionPath && previousNodeIsCaption(editor)) {
|
|
144
|
+
const previous = core.Editor.previous(editor);
|
|
145
|
+
if (!previous)
|
|
146
|
+
return false;
|
|
147
|
+
const [, previousLocation] = previous;
|
|
148
|
+
const previousWrapper = core.Editor.parent(editor, previousLocation);
|
|
149
|
+
if (!previousWrapper)
|
|
150
|
+
return false;
|
|
151
|
+
const [previousWrapperNode, wrapperLocation] = previousWrapper;
|
|
152
|
+
if (previousWrapperNode.type === types.caption) {
|
|
153
|
+
const imageContainer = core.Editor.parent(editor, wrapperLocation);
|
|
154
|
+
if (imageContainer) {
|
|
155
|
+
const [imageElement, imageLocation] = imageContainer;
|
|
156
|
+
console.log(imageLocation, imageContainer);
|
|
157
|
+
if (imageElement.type === types.figure) {
|
|
158
|
+
console.log('???');
|
|
159
|
+
core.Transforms.removeNodes(editor, { at: imageLocation });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
129
163
|
return;
|
|
130
164
|
}
|
|
131
165
|
}
|
|
@@ -143,6 +177,15 @@ function createImage(options = {}) {
|
|
|
143
177
|
* Avoid from splitting children of caption.
|
|
144
178
|
*/
|
|
145
179
|
if (captionEntry) {
|
|
180
|
+
const [, captionLocation] = captionEntry;
|
|
181
|
+
const imageEntry = core.Editor.parent(editor, captionLocation);
|
|
182
|
+
if (imageEntry) {
|
|
183
|
+
const [imageElement, imagePosition] = imageEntry;
|
|
184
|
+
if (imageElement.type === types.figure) {
|
|
185
|
+
core.Transforms.insertNodes(editor, core.createParagraphElement(), { at: core.Editor.after(editor, imagePosition) });
|
|
186
|
+
core.Transforms.move(editor);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
146
189
|
return;
|
|
147
190
|
}
|
|
148
191
|
insertBreak();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
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.6.
|
|
21
|
+
"@quadrats/core": "^0.6.5",
|
|
22
22
|
"@quadrats/locales": "^0.6.0",
|
|
23
|
-
"@quadrats/utils": "^0.6.
|
|
23
|
+
"@quadrats/utils": "^0.6.5"
|
|
24
24
|
}
|
|
25
25
|
}
|