@quadrats/common 0.6.4 → 0.6.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.
|
@@ -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 | BodyInit | 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 {};
|
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,28 @@ 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
|
+
if (imageElement.type === types.figure) {
|
|
129
|
+
Transforms.removeNodes(editor, { at: imageLocation });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
101
133
|
return;
|
|
102
134
|
}
|
|
103
135
|
}
|
|
@@ -115,6 +147,15 @@ function createImage(options = {}) {
|
|
|
115
147
|
* Avoid from splitting children of caption.
|
|
116
148
|
*/
|
|
117
149
|
if (captionEntry) {
|
|
150
|
+
const [, captionLocation] = captionEntry;
|
|
151
|
+
const imageEntry = Editor.parent(editor, captionLocation);
|
|
152
|
+
if (imageEntry) {
|
|
153
|
+
const [imageElement, imagePosition] = imageEntry;
|
|
154
|
+
if (imageElement.type === types.figure) {
|
|
155
|
+
Transforms.insertNodes(editor, createParagraphElement(), { at: Editor.after(editor, imagePosition) });
|
|
156
|
+
Transforms.move(editor);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
118
159
|
return;
|
|
119
160
|
}
|
|
120
161
|
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,28 @@ 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
|
+
if (imageElement.type === types.figure) {
|
|
157
|
+
core.Transforms.removeNodes(editor, { at: imageLocation });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
129
161
|
return;
|
|
130
162
|
}
|
|
131
163
|
}
|
|
@@ -143,6 +175,15 @@ function createImage(options = {}) {
|
|
|
143
175
|
* Avoid from splitting children of caption.
|
|
144
176
|
*/
|
|
145
177
|
if (captionEntry) {
|
|
178
|
+
const [, captionLocation] = captionEntry;
|
|
179
|
+
const imageEntry = core.Editor.parent(editor, captionLocation);
|
|
180
|
+
if (imageEntry) {
|
|
181
|
+
const [imageElement, imagePosition] = imageEntry;
|
|
182
|
+
if (imageElement.type === types.figure) {
|
|
183
|
+
core.Transforms.insertNodes(editor, core.createParagraphElement(), { at: core.Editor.after(editor, imagePosition) });
|
|
184
|
+
core.Transforms.move(editor);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
146
187
|
return;
|
|
147
188
|
}
|
|
148
189
|
insertBreak();
|
package/link/createLink.js
CHANGED
|
@@ -40,14 +40,14 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
|
|
|
40
40
|
const { text = url } = options;
|
|
41
41
|
const link = {
|
|
42
42
|
type,
|
|
43
|
-
url,
|
|
43
|
+
url: url.trim(),
|
|
44
44
|
children: [{ text }],
|
|
45
45
|
};
|
|
46
46
|
Transforms.insertNodes(editor, link, options);
|
|
47
47
|
};
|
|
48
48
|
const unwrapLink = (editor, options = {}) => unwrapNodesByTypes(editor, [type], options);
|
|
49
49
|
const wrapLink = (editor, url, options = {}) => {
|
|
50
|
-
const link = { type, url, children: [] };
|
|
50
|
+
const link = { type, url: url.trim(), children: [] };
|
|
51
51
|
wrapNodesWithUnhangRange(editor, link, Object.assign(Object.assign({}, options), { split: true }));
|
|
52
52
|
};
|
|
53
53
|
const upsertLink = (editor, url, options = {}) => {
|
package/link/index.cjs.js
CHANGED
|
@@ -45,14 +45,14 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
|
|
|
45
45
|
const { text = url } = options;
|
|
46
46
|
const link = {
|
|
47
47
|
type,
|
|
48
|
-
url,
|
|
48
|
+
url: url.trim(),
|
|
49
49
|
children: [{ text }],
|
|
50
50
|
};
|
|
51
51
|
core.Transforms.insertNodes(editor, link, options);
|
|
52
52
|
};
|
|
53
53
|
const unwrapLink = (editor, options = {}) => core.unwrapNodesByTypes(editor, [type], options);
|
|
54
54
|
const wrapLink = (editor, url, options = {}) => {
|
|
55
|
-
const link = { type, url, children: [] };
|
|
55
|
+
const link = { type, url: url.trim(), children: [] };
|
|
56
56
|
core.wrapNodesWithUnhangRange(editor, link, Object.assign(Object.assign({}, options), { split: true }));
|
|
57
57
|
};
|
|
58
58
|
const upsertLink = (editor, url, options = {}) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
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
|
}
|