@quadrats/common 0.7.2 → 0.7.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.
- package/blockquote/createBlockquote.js +1 -1
- package/bold/createBold.d.ts +1 -1
- package/embed/createEmbed.js +7 -1
- package/embed/index.cjs.js +6 -0
- package/embed/strategies/twitter/index.cjs.js +1 -1
- package/embed/strategies/twitter/index.js +1 -1
- package/file-uploader/createFileUploader.d.ts +3 -1
- package/file-uploader/createFileUploader.js +66 -53
- package/file-uploader/index.cjs.js +66 -51
- package/file-uploader/index.d.ts +1 -1
- package/file-uploader/index.js +1 -1
- package/footnote/createFootnote.js +1 -1
- package/heading/constants.d.ts +1 -1
- package/heading/createHeading.js +2 -2
- package/highlight/createHighlight.d.ts +1 -1
- package/image/createImage.js +1 -33
- package/image/index.cjs.js +0 -32
- package/input-block/createInputBlock.js +1 -1
- package/italic/createItalic.d.ts +1 -1
- package/link/createLink.js +1 -1
- package/list/createList.js +1 -1
- package/package.json +3 -3
- package/read-more/createReadMore.js +1 -1
- package/strikethrough/createStrikethrough.d.ts +1 -1
- package/underline/createUnderline.d.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isNodesTypeIn, wrapNodesWithUnhangRange, unwrapNodesByTypes } from '@quadrats/core';
|
|
2
2
|
import { BLOCKQUOTE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
package/bold/createBold.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Editor } from '@quadrats/core';
|
|
2
|
-
export declare function createBold<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions
|
|
2
|
+
export declare function createBold<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
|
package/embed/createEmbed.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { Element, Transforms, normalizeVoidElementChildren,
|
|
1
|
+
import { PARAGRAPH_TYPE, Element, Transforms, normalizeVoidElementChildren, isAboveBlockEmpty } from '@quadrats/core';
|
|
2
2
|
import { EMBED_TYPE } from './constants.js';
|
|
3
3
|
import { serializeEmbedCode } from './serializeEmbedCode.js';
|
|
4
4
|
|
|
5
5
|
function createEmbed(options) {
|
|
6
6
|
const { type = EMBED_TYPE, strategies } = options;
|
|
7
7
|
const insertEmbed = (editor, providers, embedCode, defaultNode = PARAGRAPH_TYPE) => {
|
|
8
|
+
var _a;
|
|
8
9
|
const result = serializeEmbedCode(embedCode, strategies, providers);
|
|
9
10
|
if (result) {
|
|
10
11
|
const [provider, data] = result;
|
|
11
12
|
const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
|
|
13
|
+
if (isAboveBlockEmpty(editor)) {
|
|
14
|
+
Transforms.removeNodes(editor, {
|
|
15
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
12
18
|
Transforms.insertNodes(editor, [
|
|
13
19
|
embedElement,
|
|
14
20
|
typeof defaultNode === 'string'
|
package/embed/index.cjs.js
CHANGED
|
@@ -25,10 +25,16 @@ function deserializeEmbedElementToData(element, strategies) {
|
|
|
25
25
|
function createEmbed(options) {
|
|
26
26
|
const { type = EMBED_TYPE, strategies } = options;
|
|
27
27
|
const insertEmbed = (editor, providers, embedCode, defaultNode = core.PARAGRAPH_TYPE) => {
|
|
28
|
+
var _a;
|
|
28
29
|
const result = serializeEmbedCode(embedCode, strategies, providers);
|
|
29
30
|
if (result) {
|
|
30
31
|
const [provider, data] = result;
|
|
31
32
|
const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
|
|
33
|
+
if (core.isAboveBlockEmpty(editor)) {
|
|
34
|
+
core.Transforms.removeNodes(editor, {
|
|
35
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
32
38
|
core.Transforms.insertNodes(editor, [
|
|
33
39
|
embedElement,
|
|
34
40
|
typeof defaultNode === 'string'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function getTwitterTweetDataFromUrl(url) {
|
|
4
|
-
const result = /^https:\/\/
|
|
4
|
+
const result = /^https:\/\/x.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
|
|
5
5
|
if (result) {
|
|
6
6
|
const [, tweetId] = result;
|
|
7
7
|
return {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Editor } from '@quadrats/core';
|
|
2
|
-
import { FileUploader } from './typings';
|
|
2
|
+
import { FileUploader, FileUploaderElement } from './typings';
|
|
3
3
|
export interface CreateFileUploaderOptions {
|
|
4
4
|
type?: string;
|
|
5
5
|
}
|
|
6
|
+
export declare const createFileUploaderElementByType: (type: string) => FileUploader<Editor>['createFileUploaderElement'];
|
|
7
|
+
export declare function insertFileUploaderElement(editor: Editor, fileUploaderElement: FileUploaderElement | undefined): void;
|
|
6
8
|
export declare function createFileUploader(options?: CreateFileUploaderOptions): FileUploader<Editor>;
|
|
@@ -1,60 +1,76 @@
|
|
|
1
1
|
import { __awaiter } from './_virtual/_tslib.js';
|
|
2
2
|
import { readFileAsDataURL } from '@quadrats/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { isAboveBlockEmpty, Transforms, createParagraphElement, HistoryEditor } from '@quadrats/core';
|
|
4
4
|
import { FILE_UPLOADER_TYPE } from './constants.js';
|
|
5
5
|
import { getFilesFromInput } from './getFilesFromInput.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
throw xhr.response;
|
|
7
|
+
const createFileUploaderElementByType = type => (editor, file, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
const { createElement, getBody, getHeaders, getUrl, uploader, } = options;
|
|
9
|
+
const [mime] = file.type.split('/');
|
|
10
|
+
const createByMime = createElement[mime];
|
|
11
|
+
if (!createByMime) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const { dataURL: createElementByDataURL, response: createElementByResponse } = createByMime;
|
|
15
|
+
const headers = yield (getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders(file));
|
|
16
|
+
const xhr = uploader || new XMLHttpRequest();
|
|
17
|
+
const dataURL = yield readFileAsDataURL(file);
|
|
18
|
+
let sent = false;
|
|
19
|
+
const fileUploaderElement = {
|
|
20
|
+
type,
|
|
21
|
+
register: (getPath, onProgress) => {
|
|
22
|
+
xhr.onload = () => {
|
|
23
|
+
if (xhr.status < 400) {
|
|
24
|
+
const path = getPath();
|
|
25
|
+
if (path) {
|
|
26
|
+
HistoryEditor.withoutSaving(editor, () => {
|
|
27
|
+
Transforms.removeNodes(editor, { at: path });
|
|
28
|
+
Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
29
|
+
});
|
|
36
30
|
}
|
|
37
|
-
};
|
|
38
|
-
xhr.upload.onprogress = ({ loaded, total }) => onProgress((loaded * 100) / total);
|
|
39
|
-
if (!sent) {
|
|
40
|
-
sent = true;
|
|
41
|
-
xhr.send(getBody(file));
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
xhr.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (headers) {
|
|
52
|
-
for (const headerName in headers) {
|
|
53
|
-
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
32
|
+
else {
|
|
33
|
+
throw xhr.response;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
xhr.upload.onprogress = ({ loaded, total }) => onProgress((loaded * 100) / total);
|
|
37
|
+
if (!sent) {
|
|
38
|
+
sent = true;
|
|
39
|
+
xhr.send(getBody(file));
|
|
54
40
|
}
|
|
41
|
+
return () => {
|
|
42
|
+
xhr.onload = null;
|
|
43
|
+
xhr.upload.onprogress = null;
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
children: [createElementByDataURL(dataURL)],
|
|
47
|
+
};
|
|
48
|
+
xhr.open('POST', getUrl(file));
|
|
49
|
+
if (headers) {
|
|
50
|
+
for (const headerName in headers) {
|
|
51
|
+
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
55
52
|
}
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
}
|
|
54
|
+
return fileUploaderElement;
|
|
55
|
+
});
|
|
56
|
+
function insertFileUploaderElement(editor, fileUploaderElement) {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
if (fileUploaderElement) {
|
|
59
|
+
// Clear empty node
|
|
60
|
+
if (isAboveBlockEmpty(editor)) {
|
|
61
|
+
Transforms.removeNodes(editor, {
|
|
62
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], {
|
|
66
|
+
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,
|
|
67
|
+
});
|
|
68
|
+
Transforms.move(editor);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function createFileUploader(options = {}) {
|
|
72
|
+
const { type = FILE_UPLOADER_TYPE } = options;
|
|
73
|
+
const createFileUploaderElement = createFileUploaderElementByType(type);
|
|
58
74
|
const upload = (editor, options) => __awaiter(this, void 0, void 0, function* () {
|
|
59
75
|
const { accept, multiple } = options;
|
|
60
76
|
const files = yield getFilesFromInput({ accept, multiple });
|
|
@@ -64,10 +80,7 @@ function createFileUploader(options = {}) {
|
|
|
64
80
|
files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
|
|
65
81
|
yield prev;
|
|
66
82
|
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
67
|
-
|
|
68
|
-
Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], options);
|
|
69
|
-
Transforms.move(editor);
|
|
70
|
-
}
|
|
83
|
+
insertFileUploaderElement(editor, fileUploaderElement);
|
|
71
84
|
});
|
|
72
85
|
}), Promise.resolve());
|
|
73
86
|
});
|
|
@@ -81,4 +94,4 @@ function createFileUploader(options = {}) {
|
|
|
81
94
|
};
|
|
82
95
|
}
|
|
83
96
|
|
|
84
|
-
export { createFileUploader };
|
|
97
|
+
export { createFileUploader, createFileUploaderElementByType, insertFileUploaderElement };
|
|
@@ -63,57 +63,73 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
63
63
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
const {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
core.
|
|
88
|
-
|
|
89
|
-
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
throw xhr.response;
|
|
66
|
+
const createFileUploaderElementByType = type => (editor, file, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const { createElement, getBody, getHeaders, getUrl, uploader, } = options;
|
|
68
|
+
const [mime] = file.type.split('/');
|
|
69
|
+
const createByMime = createElement[mime];
|
|
70
|
+
if (!createByMime) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { dataURL: createElementByDataURL, response: createElementByResponse } = createByMime;
|
|
74
|
+
const headers = yield (getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders(file));
|
|
75
|
+
const xhr = uploader || new XMLHttpRequest();
|
|
76
|
+
const dataURL = yield utils.readFileAsDataURL(file);
|
|
77
|
+
let sent = false;
|
|
78
|
+
const fileUploaderElement = {
|
|
79
|
+
type,
|
|
80
|
+
register: (getPath, onProgress) => {
|
|
81
|
+
xhr.onload = () => {
|
|
82
|
+
if (xhr.status < 400) {
|
|
83
|
+
const path = getPath();
|
|
84
|
+
if (path) {
|
|
85
|
+
core.HistoryEditor.withoutSaving(editor, () => {
|
|
86
|
+
core.Transforms.removeNodes(editor, { at: path });
|
|
87
|
+
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
88
|
+
});
|
|
95
89
|
}
|
|
96
|
-
};
|
|
97
|
-
xhr.upload.onprogress = ({ loaded, total }) => onProgress((loaded * 100) / total);
|
|
98
|
-
if (!sent) {
|
|
99
|
-
sent = true;
|
|
100
|
-
xhr.send(getBody(file));
|
|
101
90
|
}
|
|
102
|
-
|
|
103
|
-
xhr.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (headers) {
|
|
111
|
-
for (const headerName in headers) {
|
|
112
|
-
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
91
|
+
else {
|
|
92
|
+
throw xhr.response;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
xhr.upload.onprogress = ({ loaded, total }) => onProgress((loaded * 100) / total);
|
|
96
|
+
if (!sent) {
|
|
97
|
+
sent = true;
|
|
98
|
+
xhr.send(getBody(file));
|
|
113
99
|
}
|
|
100
|
+
return () => {
|
|
101
|
+
xhr.onload = null;
|
|
102
|
+
xhr.upload.onprogress = null;
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
children: [createElementByDataURL(dataURL)],
|
|
106
|
+
};
|
|
107
|
+
xhr.open('POST', getUrl(file));
|
|
108
|
+
if (headers) {
|
|
109
|
+
for (const headerName in headers) {
|
|
110
|
+
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
114
111
|
}
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
}
|
|
113
|
+
return fileUploaderElement;
|
|
114
|
+
});
|
|
115
|
+
function insertFileUploaderElement(editor, fileUploaderElement) {
|
|
116
|
+
var _a, _b, _c;
|
|
117
|
+
if (fileUploaderElement) {
|
|
118
|
+
// Clear empty node
|
|
119
|
+
if (core.isAboveBlockEmpty(editor)) {
|
|
120
|
+
core.Transforms.removeNodes(editor, {
|
|
121
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], {
|
|
125
|
+
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,
|
|
126
|
+
});
|
|
127
|
+
core.Transforms.move(editor);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function createFileUploader(options = {}) {
|
|
131
|
+
const { type = FILE_UPLOADER_TYPE } = options;
|
|
132
|
+
const createFileUploaderElement = createFileUploaderElementByType(type);
|
|
117
133
|
const upload = (editor, options) => __awaiter(this, void 0, void 0, function* () {
|
|
118
134
|
const { accept, multiple } = options;
|
|
119
135
|
const files = yield getFilesFromInput({ accept, multiple });
|
|
@@ -123,10 +139,7 @@ function createFileUploader(options = {}) {
|
|
|
123
139
|
files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
|
|
124
140
|
yield prev;
|
|
125
141
|
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
126
|
-
|
|
127
|
-
core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
|
|
128
|
-
core.Transforms.move(editor);
|
|
129
|
-
}
|
|
142
|
+
insertFileUploaderElement(editor, fileUploaderElement);
|
|
130
143
|
});
|
|
131
144
|
}), Promise.resolve());
|
|
132
145
|
});
|
|
@@ -142,4 +155,6 @@ function createFileUploader(options = {}) {
|
|
|
142
155
|
|
|
143
156
|
exports.FILE_UPLOADER_TYPE = FILE_UPLOADER_TYPE;
|
|
144
157
|
exports.createFileUploader = createFileUploader;
|
|
158
|
+
exports.createFileUploaderElementByType = createFileUploaderElementByType;
|
|
145
159
|
exports.getFilesFromInput = getFilesFromInput;
|
|
160
|
+
exports.insertFileUploaderElement = insertFileUploaderElement;
|
package/file-uploader/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './typings';
|
|
2
2
|
export * from './constants';
|
|
3
3
|
export { GetFilesFromInputOptions, getFilesFromInput } from './getFilesFromInput';
|
|
4
|
-
export { CreateFileUploaderOptions, createFileUploader } from './createFileUploader';
|
|
4
|
+
export { CreateFileUploaderOptions, createFileUploaderElementByType, insertFileUploaderElement, createFileUploader, } from './createFileUploader';
|
package/file-uploader/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { FILE_UPLOADER_TYPE } from './constants.js';
|
|
2
2
|
export { getFilesFromInput } from './getFilesFromInput.js';
|
|
3
|
-
export { createFileUploader } from './createFileUploader.js';
|
|
3
|
+
export { createFileUploader, createFileUploaderElementByType, insertFileUploaderElement } from './createFileUploader.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNodesTypeIn,
|
|
1
|
+
import { isNodesTypeIn, Transforms, wrapNodesWithUnhangRange, unwrapNodesByTypes, getNodes } from '@quadrats/core';
|
|
2
2
|
import { FOOTNOTE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
/* eslint-disable max-len */
|
package/heading/constants.d.ts
CHANGED
package/heading/createHeading.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PARAGRAPH_TYPE, getNodes, Element, Transforms, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
|
|
2
|
+
import { HEADING_LEVELS, HEADING_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createHeading({ type = HEADING_TYPE, enabledLevels = HEADING_LEVELS, } = {}) {
|
|
5
5
|
const getHeadingNodes = (editor, level, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: node => node.type === type && node.level === level }));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Editor } from '@quadrats/core';
|
|
2
|
-
export declare function createHighlight<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions
|
|
2
|
+
export declare function createHighlight<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
|
package/image/createImage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isImageUrl } from '@quadrats/utils';
|
|
2
|
-
import { Editor, Transforms, createParagraphElement, Element, normalizeVoidElementChildren, normalizeOnlyInlineOrTextInChildren
|
|
2
|
+
import { Range, isNodesTypeIn, getAboveByTypes, Editor, Transforms, createParagraphElement, Element, normalizeVoidElementChildren, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
|
|
3
3
|
import { IMAGE_TYPES } from './constants.js';
|
|
4
4
|
|
|
5
5
|
function resolveSizeSteps(steps) {
|
|
@@ -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
|
};
|
package/italic/createItalic.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Editor } from '@quadrats/core';
|
|
2
|
-
export declare function createItalic<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions
|
|
2
|
+
export declare function createItalic<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
|
package/link/createLink.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUrl } from '@quadrats/utils';
|
|
2
|
-
import { Range, Editor, Element, Transforms, Text,
|
|
2
|
+
import { unwrapNodesByTypes, isNodesTypeIn, Range, Editor, Element, Transforms, Text, getAboveByTypes, wrapNodesWithUnhangRange, getRangeBeforeFromAboveBlockStart, getRangeBefore } from '@quadrats/core';
|
|
3
3
|
import { LINK_TYPE } from './constants.js';
|
|
4
4
|
|
|
5
5
|
function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAfterSpaceEntered = true, wrappableVoidTypes, } = {}) {
|
package/list/createList.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms,
|
|
1
|
+
import { PARAGRAPH_TYPE, isNodesTypeIn, Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms, Editor, Path, isFirstChild, wrapNodesWithUnhangRange, getNodesByTypes, unwrapNodesByTypes, getAboveByTypes, getParent } from '@quadrats/core';
|
|
2
2
|
import { LIST_TYPES } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createList(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.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.7.
|
|
22
|
-
"@quadrats/locales": "^0.7.
|
|
21
|
+
"@quadrats/core": "^0.7.7",
|
|
22
|
+
"@quadrats/locales": "^0.7.7",
|
|
23
23
|
"@quadrats/utils": "^0.7.2"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot, Path, Transforms,
|
|
1
|
+
import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot, getNodesByTypes, Path, Transforms, deleteSelectionFragmentIfExpanded, createParagraphElement } from '@quadrats/core';
|
|
2
2
|
import { READ_MORE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createReadMore(options = {}) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Editor } from '@quadrats/core';
|
|
2
|
-
export declare function createStrikethrough<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions
|
|
2
|
+
export declare function createStrikethrough<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Editor } from '@quadrats/core';
|
|
2
|
-
export declare function createUnderline<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions
|
|
2
|
+
export declare function createUnderline<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
|