@quadrats/common 0.6.7 → 0.7.0
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.d.ts +1 -1
- package/blockquote/createBlockquote.js +33 -33
- package/blockquote/index.cjs.js +32 -34
- package/bold/createBold.d.ts +2 -1
- package/bold/createBold.js +6 -4
- package/bold/index.cjs.js +6 -6
- package/divider/createDivider.d.ts +1 -1
- package/divider/createDivider.js +29 -29
- package/divider/index.cjs.js +29 -31
- package/embed/createEmbed.js +40 -40
- package/embed/deserializeEmbedElementToData.js +6 -6
- package/embed/index.cjs.js +54 -56
- package/embed/serializeEmbedCode.js +8 -8
- package/embed/strategies/facebook/index.cjs.js +45 -47
- package/embed/strategies/facebook/index.d.ts +5 -5
- package/embed/strategies/facebook/index.js +45 -45
- package/embed/strategies/instagram/index.cjs.js +29 -31
- package/embed/strategies/instagram/index.d.ts +3 -3
- package/embed/strategies/instagram/index.js +29 -29
- package/embed/strategies/podcast-apple/index.cjs.js +16 -18
- package/embed/strategies/podcast-apple/index.d.ts +4 -4
- package/embed/strategies/podcast-apple/index.js +16 -16
- package/embed/strategies/spotify/index.cjs.js +14 -16
- package/embed/strategies/spotify/index.d.ts +4 -4
- package/embed/strategies/spotify/index.js +14 -14
- package/embed/strategies/twitter/index.cjs.js +41 -43
- package/embed/strategies/twitter/index.d.ts +4 -4
- package/embed/strategies/twitter/index.js +41 -41
- package/embed/strategies/vimeo/index.cjs.js +14 -16
- package/embed/strategies/vimeo/index.d.ts +3 -3
- package/embed/strategies/vimeo/index.js +14 -14
- package/embed/strategies/youtube/index.cjs.js +14 -16
- package/embed/strategies/youtube/index.d.ts +3 -3
- package/embed/strategies/youtube/index.js +14 -14
- package/embed/typings.d.ts +1 -1
- package/file-uploader/_virtual/_tslib.js +3 -1
- package/file-uploader/createFileUploader.js +76 -76
- package/file-uploader/getFilesFromInput.js +24 -24
- package/file-uploader/index.cjs.js +102 -102
- package/file-uploader/typings.d.ts +6 -6
- package/footnote/createFootnote.d.ts +1 -1
- package/footnote/createFootnote.js +65 -65
- package/footnote/index.cjs.js +65 -67
- package/footnote/typings.d.ts +1 -1
- package/heading/constants.js +1 -1
- package/heading/createHeading.d.ts +1 -1
- package/heading/createHeading.js +45 -45
- package/heading/index.cjs.js +46 -48
- package/heading/typings.d.ts +1 -1
- package/highlight/createHighlight.d.ts +2 -1
- package/highlight/createHighlight.js +6 -4
- package/highlight/index.cjs.js +6 -6
- package/image/constants.js +4 -4
- package/image/createImage.js +195 -195
- package/image/getImageElementCommonProps.js +6 -6
- package/image/getImageFigureElementCommonProps.js +5 -5
- package/image/index.cjs.js +211 -213
- package/image/isHostingNotRequired.js +2 -2
- package/image/typings.d.ts +8 -8
- package/input-block/createInputBlock.js +37 -37
- package/input-block/index.cjs.js +37 -39
- package/input-widget/typings.d.ts +1 -1
- package/italic/createItalic.d.ts +2 -1
- package/italic/createItalic.js +6 -4
- package/italic/index.cjs.js +6 -6
- package/link/createLink.js +147 -147
- package/link/index.cjs.js +146 -148
- package/link/typings.d.ts +2 -2
- package/list/constants.js +4 -4
- package/list/createList.js +185 -185
- package/list/index.cjs.js +188 -190
- package/list/typings.d.ts +4 -4
- package/package.json +4 -4
- package/read-more/createReadMore.d.ts +1 -1
- package/read-more/createReadMore.js +51 -51
- package/read-more/index.cjs.js +50 -52
- package/strikethrough/createStrikethrough.d.ts +2 -1
- package/strikethrough/createStrikethrough.js +6 -4
- package/strikethrough/index.cjs.js +6 -6
- package/toggle-mark/createToggleMarkCreator.d.ts +4 -4
- package/toggle-mark/createToggleMarkCreator.js +36 -36
- package/toggle-mark/index.cjs.js +36 -38
- package/underline/createUnderline.d.ts +2 -1
- package/underline/createUnderline.js +6 -4
- package/underline/index.cjs.js +6 -6
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var utils = require('@quadrats/utils');
|
|
6
4
|
var core = require('@quadrats/core');
|
|
7
5
|
|
|
8
6
|
const FILE_UPLOADER_TYPE = 'file_uploader';
|
|
9
7
|
|
|
10
|
-
function getFilesFromInput(options = {}) {
|
|
11
|
-
const { accept, multiple } = options;
|
|
12
|
-
return new Promise((resolve) => {
|
|
13
|
-
const inputEl = document.createElement('input');
|
|
14
|
-
if (accept) {
|
|
15
|
-
inputEl.accept = accept.join(',');
|
|
16
|
-
}
|
|
17
|
-
inputEl.multiple = !!multiple;
|
|
18
|
-
inputEl.type = 'file';
|
|
19
|
-
inputEl.addEventListener('change', () => {
|
|
20
|
-
const { files: fileList } = inputEl;
|
|
21
|
-
if (!fileList || !fileList.length) {
|
|
22
|
-
resolve(undefined);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const files = [];
|
|
26
|
-
for (const file of fileList) {
|
|
27
|
-
files.push(file);
|
|
28
|
-
}
|
|
29
|
-
resolve(files);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
inputEl.click();
|
|
33
|
-
});
|
|
8
|
+
function getFilesFromInput(options = {}) {
|
|
9
|
+
const { accept, multiple } = options;
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const inputEl = document.createElement('input');
|
|
12
|
+
if (accept) {
|
|
13
|
+
inputEl.accept = accept.join(',');
|
|
14
|
+
}
|
|
15
|
+
inputEl.multiple = !!multiple;
|
|
16
|
+
inputEl.type = 'file';
|
|
17
|
+
inputEl.addEventListener('change', () => {
|
|
18
|
+
const { files: fileList } = inputEl;
|
|
19
|
+
if (!fileList || !fileList.length) {
|
|
20
|
+
resolve(undefined);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const files = [];
|
|
24
|
+
for (const file of fileList) {
|
|
25
|
+
files.push(file);
|
|
26
|
+
}
|
|
27
|
+
resolve(files);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
inputEl.click();
|
|
31
|
+
});
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
/******************************************************************************
|
|
37
35
|
Copyright (c) Microsoft Corporation.
|
|
38
36
|
|
|
39
37
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -47,6 +45,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
47
45
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
48
46
|
PERFORMANCE OF THIS SOFTWARE.
|
|
49
47
|
***************************************************************************** */
|
|
48
|
+
/* global Reflect, Promise */
|
|
49
|
+
|
|
50
50
|
|
|
51
51
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
52
52
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -58,81 +58,81 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function createFileUploader(options = {}) {
|
|
62
|
-
const { type = FILE_UPLOADER_TYPE } = options;
|
|
63
|
-
const createFileUploaderElement = (editor, file, options) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const { createElement, getBody, getHeaders, getUrl, uploader, } = options;
|
|
65
|
-
const [mime] = file.type.split('/');
|
|
66
|
-
const createByMime = createElement[mime];
|
|
67
|
-
if (!createByMime) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const { dataURL: createElementByDataURL, response: createElementByResponse } = createByMime;
|
|
71
|
-
const headers = yield (getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders(file));
|
|
72
|
-
const xhr = uploader || new XMLHttpRequest();
|
|
73
|
-
const dataURL = yield utils.readFileAsDataURL(file);
|
|
74
|
-
let sent = false;
|
|
75
|
-
const fileUploaderElement = {
|
|
76
|
-
type,
|
|
77
|
-
register: (getPath, onProgress) => {
|
|
78
|
-
xhr.onload = () => {
|
|
79
|
-
if (xhr.status < 400) {
|
|
80
|
-
const path = getPath();
|
|
81
|
-
if (path) {
|
|
82
|
-
core.HistoryEditor.withoutSaving(editor, () => {
|
|
83
|
-
core.Transforms.removeNodes(editor, { at: path });
|
|
84
|
-
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
throw xhr.response;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
xhr.upload.onprogress = ({ loaded, total }) => onProgress((loaded * 100) / total);
|
|
93
|
-
if (!sent) {
|
|
94
|
-
sent = true;
|
|
95
|
-
xhr.send(getBody(file));
|
|
96
|
-
}
|
|
97
|
-
return () => {
|
|
98
|
-
xhr.onload = null;
|
|
99
|
-
xhr.upload.onprogress = null;
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
children: [createElementByDataURL(dataURL)],
|
|
103
|
-
};
|
|
104
|
-
xhr.open('POST', getUrl(file));
|
|
105
|
-
if (headers) {
|
|
106
|
-
for (const headerName in headers) {
|
|
107
|
-
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return fileUploaderElement;
|
|
111
|
-
});
|
|
112
|
-
const upload = (editor, options) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const { accept, multiple } = options;
|
|
114
|
-
const files = yield getFilesFromInput({ accept, multiple });
|
|
115
|
-
if (!files) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
yield prev;
|
|
120
|
-
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
121
|
-
if (fileUploaderElement) {
|
|
122
|
-
core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
|
|
123
|
-
core.Transforms.move(editor);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}), Promise.resolve());
|
|
127
|
-
});
|
|
128
|
-
return {
|
|
129
|
-
type,
|
|
130
|
-
createFileUploaderElement,
|
|
131
|
-
upload,
|
|
132
|
-
with(editor) {
|
|
133
|
-
return editor;
|
|
134
|
-
},
|
|
135
|
-
};
|
|
61
|
+
function createFileUploader(options = {}) {
|
|
62
|
+
const { type = FILE_UPLOADER_TYPE } = options;
|
|
63
|
+
const createFileUploaderElement = (editor, file, options) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const { createElement, getBody, getHeaders, getUrl, uploader, } = options;
|
|
65
|
+
const [mime] = file.type.split('/');
|
|
66
|
+
const createByMime = createElement[mime];
|
|
67
|
+
if (!createByMime) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const { dataURL: createElementByDataURL, response: createElementByResponse } = createByMime;
|
|
71
|
+
const headers = yield (getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders(file));
|
|
72
|
+
const xhr = uploader || new XMLHttpRequest();
|
|
73
|
+
const dataURL = yield utils.readFileAsDataURL(file);
|
|
74
|
+
let sent = false;
|
|
75
|
+
const fileUploaderElement = {
|
|
76
|
+
type,
|
|
77
|
+
register: (getPath, onProgress) => {
|
|
78
|
+
xhr.onload = () => {
|
|
79
|
+
if (xhr.status < 400) {
|
|
80
|
+
const path = getPath();
|
|
81
|
+
if (path) {
|
|
82
|
+
core.HistoryEditor.withoutSaving(editor, () => {
|
|
83
|
+
core.Transforms.removeNodes(editor, { at: path });
|
|
84
|
+
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw xhr.response;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
xhr.upload.onprogress = ({ loaded, total }) => onProgress((loaded * 100) / total);
|
|
93
|
+
if (!sent) {
|
|
94
|
+
sent = true;
|
|
95
|
+
xhr.send(getBody(file));
|
|
96
|
+
}
|
|
97
|
+
return () => {
|
|
98
|
+
xhr.onload = null;
|
|
99
|
+
xhr.upload.onprogress = null;
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
children: [createElementByDataURL(dataURL)],
|
|
103
|
+
};
|
|
104
|
+
xhr.open('POST', getUrl(file));
|
|
105
|
+
if (headers) {
|
|
106
|
+
for (const headerName in headers) {
|
|
107
|
+
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return fileUploaderElement;
|
|
111
|
+
});
|
|
112
|
+
const upload = (editor, options) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const { accept, multiple } = options;
|
|
114
|
+
const files = yield getFilesFromInput({ accept, multiple });
|
|
115
|
+
if (!files) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
files.reduce((prev, file) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
yield prev;
|
|
120
|
+
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
121
|
+
if (fileUploaderElement) {
|
|
122
|
+
core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
|
|
123
|
+
core.Transforms.move(editor);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}), Promise.resolve());
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
type,
|
|
130
|
+
createFileUploaderElement,
|
|
131
|
+
upload,
|
|
132
|
+
with(editor) {
|
|
133
|
+
return editor;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
exports.FILE_UPLOADER_TYPE = FILE_UPLOADER_TYPE;
|
|
@@ -10,14 +10,14 @@ export interface FileUploaderElement extends QuadratsElement {
|
|
|
10
10
|
/**
|
|
11
11
|
* For creating temorary element while uploading.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type FileUploaderCreateElementByDataURL = (dataURL: string) => QuadratsElement;
|
|
14
14
|
/**
|
|
15
15
|
* For create element after uploaded.
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
17
|
+
export type FileUploaderCreateElementByResponse = (response: any) => QuadratsElement;
|
|
18
|
+
export type FileUploaderGetBody = (file: File) => BodyInit;
|
|
19
|
+
export type FileUploaderGetHeaders = (file: File) => XHRUploadHeaders | Promise<XHRUploadHeaders>;
|
|
20
|
+
export type FileUploaderGetUrl = (file: File) => string;
|
|
21
21
|
interface FileUploaderUploadImplementOnProgressArgs {
|
|
22
22
|
loaded: number;
|
|
23
23
|
total: number;
|
|
@@ -46,7 +46,7 @@ export interface FileUploaderCreateFileUploaderElementOptions {
|
|
|
46
46
|
getUrl: FileUploaderGetUrl;
|
|
47
47
|
uploader?: FileUploaderImplement;
|
|
48
48
|
}
|
|
49
|
-
export
|
|
49
|
+
export type FileUploaderUploadOptions = FileUploaderCreateFileUploaderElementOptions & GetFilesFromInputOptions & TransformsInsertNodesOptions;
|
|
50
50
|
export interface FileUploader<T extends Editor = Editor> extends Withable {
|
|
51
51
|
type: string;
|
|
52
52
|
createFileUploaderElement(editor: T, file: File, options: FileUploaderCreateFileUploaderElementOptions): Promise<FileUploaderElement | undefined>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { WithElementType } from '@quadrats/core';
|
|
2
2
|
import { Footnote } from './typings';
|
|
3
|
-
export
|
|
3
|
+
export type CreateFootnoteOptions = Partial<WithElementType>;
|
|
4
4
|
export declare function createFootnote({ type, }?: CreateFootnoteOptions): Footnote;
|
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
import { isNodesTypeIn, getNodes, Transforms, unwrapNodesByTypes, wrapNodesWithUnhangRange } from '@quadrats/core';
|
|
2
2
|
import { FOOTNOTE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
|
-
/* eslint-disable max-len */
|
|
5
|
-
function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
|
|
6
|
-
const isSelectionInFootnote = editor => isNodesTypeIn(editor, [type]);
|
|
7
|
-
const getFootnoteText = (editor) => {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
const at = editor.selection;
|
|
10
|
-
if (!at) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
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 firstNode === null || firstNode === void 0 ? void 0 : firstNode.footnote;
|
|
15
|
-
};
|
|
16
|
-
const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
|
|
17
|
-
var _a;
|
|
18
|
-
let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
|
|
19
|
-
for (const [, path] of getNodes(editor, { at: [], match: node => node.type === FOOTNOTE_TYPE })) {
|
|
20
|
-
Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
|
|
21
|
-
footnoteCount += 1;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const unwrapFootnote = (editor, options = {}) => {
|
|
25
|
-
unwrapNodesByTypes(editor, [type], options);
|
|
26
|
-
};
|
|
27
|
-
const wrapFootnote = (editor, footnoteText, options = {}) => {
|
|
28
|
-
var _a;
|
|
29
|
-
const footnote = {
|
|
30
|
-
type,
|
|
31
|
-
footnote: footnoteText,
|
|
32
|
-
index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
|
|
33
|
-
children: [],
|
|
34
|
-
};
|
|
35
|
-
wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
|
|
36
|
-
};
|
|
37
|
-
const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
|
|
38
|
-
const { at = editor.selection } = options;
|
|
39
|
-
if (!at) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (footnoteText !== '') {
|
|
43
|
-
if (isSelectionInFootnote(editor)) {
|
|
44
|
-
Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: node => node.type === type });
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
wrapFootnote(editor, footnoteText, options);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
unwrapFootnote(editor, { at });
|
|
52
|
-
}
|
|
53
|
-
updateFootnoteIndex(editor);
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
type,
|
|
57
|
-
getFootnoteText,
|
|
58
|
-
isSelectionInFootnote,
|
|
59
|
-
updateFootnoteIndex,
|
|
60
|
-
unwrapFootnote,
|
|
61
|
-
wrapFootnote,
|
|
62
|
-
upsertFootnoteAndUpdateIndex,
|
|
63
|
-
with(editor) {
|
|
64
|
-
const { isInline } = editor;
|
|
65
|
-
editor.isInline = element => element.type === type || isInline(element);
|
|
66
|
-
return editor;
|
|
67
|
-
},
|
|
68
|
-
};
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
|
|
6
|
+
const isSelectionInFootnote = editor => isNodesTypeIn(editor, [type]);
|
|
7
|
+
const getFootnoteText = (editor) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const at = editor.selection;
|
|
10
|
+
if (!at) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
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 firstNode === null || firstNode === void 0 ? void 0 : firstNode.footnote;
|
|
15
|
+
};
|
|
16
|
+
const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
|
|
17
|
+
var _a;
|
|
18
|
+
let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
|
|
19
|
+
for (const [, path] of getNodes(editor, { at: [], match: node => node.type === FOOTNOTE_TYPE })) {
|
|
20
|
+
Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
|
|
21
|
+
footnoteCount += 1;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const unwrapFootnote = (editor, options = {}) => {
|
|
25
|
+
unwrapNodesByTypes(editor, [type], options);
|
|
26
|
+
};
|
|
27
|
+
const wrapFootnote = (editor, footnoteText, options = {}) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const footnote = {
|
|
30
|
+
type,
|
|
31
|
+
footnote: footnoteText,
|
|
32
|
+
index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
|
|
33
|
+
children: [],
|
|
34
|
+
};
|
|
35
|
+
wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
|
|
36
|
+
};
|
|
37
|
+
const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
|
|
38
|
+
const { at = editor.selection } = options;
|
|
39
|
+
if (!at) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (footnoteText !== '') {
|
|
43
|
+
if (isSelectionInFootnote(editor)) {
|
|
44
|
+
Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: node => node.type === type });
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
wrapFootnote(editor, footnoteText, options);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
unwrapFootnote(editor, { at });
|
|
52
|
+
}
|
|
53
|
+
updateFootnoteIndex(editor);
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
type,
|
|
57
|
+
getFootnoteText,
|
|
58
|
+
isSelectionInFootnote,
|
|
59
|
+
updateFootnoteIndex,
|
|
60
|
+
unwrapFootnote,
|
|
61
|
+
wrapFootnote,
|
|
62
|
+
upsertFootnoteAndUpdateIndex,
|
|
63
|
+
with(editor) {
|
|
64
|
+
const { isInline } = editor;
|
|
65
|
+
editor.isInline = element => element.type === type || isInline(element);
|
|
66
|
+
return editor;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export { createFootnote };
|
package/footnote/index.cjs.js
CHANGED
|
@@ -1,76 +1,74 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@quadrats/core');
|
|
6
4
|
|
|
7
5
|
const FOOTNOTE_TYPE = 'footnote';
|
|
8
6
|
|
|
9
|
-
/* eslint-disable max-len */
|
|
10
|
-
function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
|
|
11
|
-
const isSelectionInFootnote = editor => core.isNodesTypeIn(editor, [type]);
|
|
12
|
-
const getFootnoteText = (editor) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const at = editor.selection;
|
|
15
|
-
if (!at) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
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 firstNode === null || firstNode === void 0 ? void 0 : firstNode.footnote;
|
|
20
|
-
};
|
|
21
|
-
const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
|
|
22
|
-
var _a;
|
|
23
|
-
let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
|
|
24
|
-
for (const [, path] of core.getNodes(editor, { at: [], match: node => node.type === FOOTNOTE_TYPE })) {
|
|
25
|
-
core.Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
|
|
26
|
-
footnoteCount += 1;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const unwrapFootnote = (editor, options = {}) => {
|
|
30
|
-
core.unwrapNodesByTypes(editor, [type], options);
|
|
31
|
-
};
|
|
32
|
-
const wrapFootnote = (editor, footnoteText, options = {}) => {
|
|
33
|
-
var _a;
|
|
34
|
-
const footnote = {
|
|
35
|
-
type,
|
|
36
|
-
footnote: footnoteText,
|
|
37
|
-
index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
|
|
38
|
-
children: [],
|
|
39
|
-
};
|
|
40
|
-
core.wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
|
|
41
|
-
};
|
|
42
|
-
const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
|
|
43
|
-
const { at = editor.selection } = options;
|
|
44
|
-
if (!at) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (footnoteText !== '') {
|
|
48
|
-
if (isSelectionInFootnote(editor)) {
|
|
49
|
-
core.Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: node => node.type === type });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
wrapFootnote(editor, footnoteText, options);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
unwrapFootnote(editor, { at });
|
|
57
|
-
}
|
|
58
|
-
updateFootnoteIndex(editor);
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
type,
|
|
62
|
-
getFootnoteText,
|
|
63
|
-
isSelectionInFootnote,
|
|
64
|
-
updateFootnoteIndex,
|
|
65
|
-
unwrapFootnote,
|
|
66
|
-
wrapFootnote,
|
|
67
|
-
upsertFootnoteAndUpdateIndex,
|
|
68
|
-
with(editor) {
|
|
69
|
-
const { isInline } = editor;
|
|
70
|
-
editor.isInline = element => element.type === type || isInline(element);
|
|
71
|
-
return editor;
|
|
72
|
-
},
|
|
73
|
-
};
|
|
7
|
+
/* eslint-disable max-len */
|
|
8
|
+
function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
|
|
9
|
+
const isSelectionInFootnote = editor => core.isNodesTypeIn(editor, [type]);
|
|
10
|
+
const getFootnoteText = (editor) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const at = editor.selection;
|
|
13
|
+
if (!at) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
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];
|
|
17
|
+
return firstNode === null || firstNode === void 0 ? void 0 : firstNode.footnote;
|
|
18
|
+
};
|
|
19
|
+
const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
|
|
20
|
+
var _a;
|
|
21
|
+
let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
|
|
22
|
+
for (const [, path] of core.getNodes(editor, { at: [], match: node => node.type === FOOTNOTE_TYPE })) {
|
|
23
|
+
core.Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
|
|
24
|
+
footnoteCount += 1;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const unwrapFootnote = (editor, options = {}) => {
|
|
28
|
+
core.unwrapNodesByTypes(editor, [type], options);
|
|
29
|
+
};
|
|
30
|
+
const wrapFootnote = (editor, footnoteText, options = {}) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const footnote = {
|
|
33
|
+
type,
|
|
34
|
+
footnote: footnoteText,
|
|
35
|
+
index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
|
|
36
|
+
children: [],
|
|
37
|
+
};
|
|
38
|
+
core.wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
|
|
39
|
+
};
|
|
40
|
+
const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
|
|
41
|
+
const { at = editor.selection } = options;
|
|
42
|
+
if (!at) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (footnoteText !== '') {
|
|
46
|
+
if (isSelectionInFootnote(editor)) {
|
|
47
|
+
core.Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: node => node.type === type });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
wrapFootnote(editor, footnoteText, options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
unwrapFootnote(editor, { at });
|
|
55
|
+
}
|
|
56
|
+
updateFootnoteIndex(editor);
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
type,
|
|
60
|
+
getFootnoteText,
|
|
61
|
+
isSelectionInFootnote,
|
|
62
|
+
updateFootnoteIndex,
|
|
63
|
+
unwrapFootnote,
|
|
64
|
+
wrapFootnote,
|
|
65
|
+
upsertFootnoteAndUpdateIndex,
|
|
66
|
+
with(editor) {
|
|
67
|
+
const { isInline } = editor;
|
|
68
|
+
editor.isInline = element => element.type === type || isInline(element);
|
|
69
|
+
return editor;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
exports.FOOTNOTE_TYPE = FOOTNOTE_TYPE;
|
package/footnote/typings.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface FootnoteElement extends QuadratsElement, WithElementType {
|
|
|
11
11
|
export interface FootnoteUpdateFootnoteIndexOptions {
|
|
12
12
|
startAt?: number;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
14
|
+
export type FootnoteUnwrapFootnoteOptions = UnwrapNodeByTypesOptions;
|
|
15
15
|
export interface FootnoteWrapFootnoteOptions extends Omit<TransformsWrapNodesOptions, 'split'> {
|
|
16
16
|
index?: number;
|
|
17
17
|
}
|
package/heading/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { WithElementType } from '@quadrats/core';
|
|
2
2
|
import { Heading, HeadingLevel, WithEnabledHeadingLevels } from './typings';
|
|
3
|
-
export
|
|
3
|
+
export type CreateHeadingOptions<L extends HeadingLevel> = Partial<WithElementType & WithEnabledHeadingLevels<L>>;
|
|
4
4
|
export declare function createHeading<L extends HeadingLevel = HeadingLevel>({ type, enabledLevels, }?: CreateHeadingOptions<L>): Heading<L>;
|