@quadrats/common 0.1.0 → 0.5.1
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 +3 -3
- package/blockquote/index.cjs.js +2 -2
- package/blockquote/typings.d.ts +2 -2
- package/bold/createBold.d.ts +1 -1
- package/bold/createBold.js +3 -2
- package/bold/index.cjs.js +2 -1
- package/divider/createDivider.js +2 -2
- package/divider/index.cjs.js +1 -1
- package/divider/typings.d.ts +2 -2
- package/embed/createEmbed.js +6 -4
- package/embed/index.cjs.js +5 -3
- package/embed/strategies/podcast-apple/index.cjs.js +22 -0
- package/embed/strategies/podcast-apple/index.d.ts +9 -0
- package/embed/strategies/podcast-apple/index.js +18 -0
- package/embed/strategies/podcast-apple/package.json +7 -0
- package/embed/strategies/spotify/index.cjs.js +21 -0
- package/embed/strategies/spotify/index.d.ts +9 -0
- package/embed/strategies/spotify/index.js +17 -0
- package/embed/strategies/spotify/package.json +7 -0
- package/embed/typings.d.ts +2 -2
- package/file-uploader/createFileUploader.js +7 -11
- package/file-uploader/index.cjs.js +4 -8
- package/file-uploader/typings.d.ts +6 -6
- package/footnote/constants.d.ts +1 -0
- package/footnote/constants.js +3 -0
- package/footnote/createFootnote.d.ts +4 -0
- package/footnote/createFootnote.js +71 -0
- package/footnote/index.cjs.js +77 -0
- package/footnote/index.d.ts +3 -0
- package/footnote/index.js +2 -0
- package/footnote/package.json +7 -0
- package/footnote/typings.d.ts +28 -0
- package/heading/createHeading.js +2 -2
- package/heading/index.cjs.js +1 -1
- package/heading/typings.d.ts +2 -2
- package/highlight/createHighlight.d.ts +1 -1
- package/highlight/createHighlight.js +3 -2
- package/highlight/index.cjs.js +2 -1
- package/image/createImage.js +7 -7
- package/image/index.cjs.js +6 -6
- package/image/typings.d.ts +5 -5
- package/input-block/createInputBlock.js +8 -2
- package/input-block/index.cjs.js +7 -1
- package/input-block/typings.d.ts +2 -2
- package/input-widget/typings.d.ts +1 -0
- package/italic/createItalic.d.ts +1 -1
- package/italic/createItalic.js +3 -2
- package/italic/index.cjs.js +2 -1
- package/link/createLink.js +16 -4
- package/link/index.cjs.js +14 -2
- package/link/typings.d.ts +2 -2
- package/list/createList.js +12 -6
- package/list/index.cjs.js +11 -5
- package/list/typings.d.ts +6 -6
- package/package.json +4 -4
- package/read-more/createReadMore.js +2 -2
- package/read-more/index.cjs.js +1 -1
- package/read-more/typings.d.ts +2 -2
- package/strikethrough/createStrikethrough.d.ts +1 -1
- package/strikethrough/createStrikethrough.js +3 -2
- package/strikethrough/index.cjs.js +2 -1
- package/toggle-mark/createToggleMarkCreator.d.ts +7 -3
- package/toggle-mark/createToggleMarkCreator.js +17 -2
- package/toggle-mark/index.cjs.js +17 -2
- package/underline/createUnderline.d.ts +1 -1
- package/underline/createUnderline.js +3 -2
- package/underline/index.cjs.js +2 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BLOCKQUOTE_TYPE } from './constants.js';
|
|
2
1
|
import { isNodesTypeIn, toggleNodesType, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
|
|
2
|
+
import { BLOCKQUOTE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
|
5
5
|
return {
|
|
6
6
|
type,
|
|
7
|
-
isSelectionInBlockquote:
|
|
8
|
-
toggleBlockquote:
|
|
7
|
+
isSelectionInBlockquote: editor => isNodesTypeIn(editor, [type]),
|
|
8
|
+
toggleBlockquote: editor => toggleNodesType(editor, type),
|
|
9
9
|
with(editor) {
|
|
10
10
|
const { normalizeNode } = editor;
|
|
11
11
|
editor.normalizeNode = (entry) => {
|
package/blockquote/index.cjs.js
CHANGED
|
@@ -9,8 +9,8 @@ const BLOCKQUOTE_TYPE = 'blockquote';
|
|
|
9
9
|
function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
|
10
10
|
return {
|
|
11
11
|
type,
|
|
12
|
-
isSelectionInBlockquote:
|
|
13
|
-
toggleBlockquote:
|
|
12
|
+
isSelectionInBlockquote: editor => core.isNodesTypeIn(editor, [type]),
|
|
13
|
+
toggleBlockquote: editor => core.toggleNodesType(editor, type),
|
|
14
14
|
with(editor) {
|
|
15
15
|
const { normalizeNode } = editor;
|
|
16
16
|
editor.normalizeNode = (entry) => {
|
package/blockquote/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Editor,
|
|
2
|
-
export interface BlockquoteElement extends
|
|
1
|
+
import { Editor, QuadratsElement, Withable, WithElementType } from '@quadrats/core';
|
|
2
|
+
export interface BlockquoteElement extends QuadratsElement, WithElementType {
|
|
3
3
|
}
|
|
4
4
|
export interface Blockquote extends WithElementType, Withable {
|
|
5
5
|
isSelectionInBlockquote(editor: Editor): boolean;
|
package/bold/createBold.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const createBold: ({ type }?:
|
|
1
|
+
export declare const createBold: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
|
package/bold/createBold.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BOLD_TYPE } from './constants.js';
|
|
2
1
|
import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
|
|
2
|
+
import { BOLD_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
|
-
const createBold = createToggleMarkCreator({
|
|
4
|
+
const createBold = (variant) => createToggleMarkCreator({
|
|
5
5
|
type: BOLD_TYPE,
|
|
6
|
+
variant,
|
|
6
7
|
});
|
|
7
8
|
|
|
8
9
|
export { createBold };
|
package/bold/index.cjs.js
CHANGED
|
@@ -6,8 +6,9 @@ var toggleMark = require('@quadrats/common/toggle-mark');
|
|
|
6
6
|
|
|
7
7
|
const BOLD_TYPE = 'bold';
|
|
8
8
|
|
|
9
|
-
const createBold = toggleMark.createToggleMarkCreator({
|
|
9
|
+
const createBold = (variant) => toggleMark.createToggleMarkCreator({
|
|
10
10
|
type: BOLD_TYPE,
|
|
11
|
+
variant,
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
exports.BOLD_TYPE = BOLD_TYPE;
|
package/divider/createDivider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DIVIDER_TYPE } from './constants.js';
|
|
2
1
|
import { Element, normalizeVoidElementChildren, Transforms, createParagraphElement } from '@quadrats/core';
|
|
2
|
+
import { DIVIDER_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createDivider(options = {}) {
|
|
5
5
|
const { type = DIVIDER_TYPE } = options;
|
|
@@ -14,7 +14,7 @@ function createDivider(options = {}) {
|
|
|
14
14
|
insertDivider,
|
|
15
15
|
with(editor) {
|
|
16
16
|
const { isVoid, normalizeNode } = editor;
|
|
17
|
-
editor.isVoid =
|
|
17
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
18
18
|
editor.normalizeNode = (entry) => {
|
|
19
19
|
const [node, path] = entry;
|
|
20
20
|
/**
|
package/divider/index.cjs.js
CHANGED
|
@@ -19,7 +19,7 @@ function createDivider(options = {}) {
|
|
|
19
19
|
insertDivider,
|
|
20
20
|
with(editor) {
|
|
21
21
|
const { isVoid, normalizeNode } = editor;
|
|
22
|
-
editor.isVoid =
|
|
22
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
23
23
|
editor.normalizeNode = (entry) => {
|
|
24
24
|
const [node, path] = entry;
|
|
25
25
|
/**
|
package/divider/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Editor,
|
|
2
|
-
export interface DividerElement extends
|
|
1
|
+
import { Editor, QuadratsElement, Text, Withable, WithElementType } from '@quadrats/core';
|
|
2
|
+
export interface DividerElement extends QuadratsElement, WithElementType {
|
|
3
3
|
children: [Text];
|
|
4
4
|
}
|
|
5
5
|
export interface Divider extends WithElementType, Withable {
|
package/embed/createEmbed.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Element, Transforms, normalizeVoidElementChildren, PARAGRAPH_TYPE } from '@quadrats/core';
|
|
1
2
|
import { EMBED_TYPE } from './constants.js';
|
|
2
3
|
import { serializeEmbedCode } from './serializeEmbedCode.js';
|
|
3
|
-
import { Element, Transforms, normalizeVoidElementChildren, PARAGRAPH_TYPE } from '@quadrats/core';
|
|
4
4
|
|
|
5
5
|
function createEmbed(options) {
|
|
6
6
|
const { type = EMBED_TYPE, strategies } = options;
|
|
@@ -11,7 +11,8 @@ function createEmbed(options) {
|
|
|
11
11
|
const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
|
|
12
12
|
Transforms.insertNodes(editor, [
|
|
13
13
|
embedElement,
|
|
14
|
-
typeof defaultNode === 'string'
|
|
14
|
+
typeof defaultNode === 'string'
|
|
15
|
+
? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
|
|
15
16
|
]);
|
|
16
17
|
Transforms.move(editor);
|
|
17
18
|
}
|
|
@@ -22,11 +23,12 @@ function createEmbed(options) {
|
|
|
22
23
|
insertEmbed,
|
|
23
24
|
with(editor) {
|
|
24
25
|
const { isVoid, normalizeNode } = editor;
|
|
25
|
-
editor.isVoid =
|
|
26
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
26
27
|
editor.normalizeNode = (entry) => {
|
|
27
28
|
const [node, path] = entry;
|
|
28
29
|
if (Element.isElement(node) && node.type === type) {
|
|
29
|
-
const strategy = node.provider
|
|
30
|
+
const strategy = node.provider
|
|
31
|
+
? strategies[node.provider] : undefined;
|
|
30
32
|
if (!strategy || !strategy.isElementDataValid(node)) {
|
|
31
33
|
Transforms.removeNodes(editor, { at: path });
|
|
32
34
|
return;
|
package/embed/index.cjs.js
CHANGED
|
@@ -33,7 +33,8 @@ function createEmbed(options) {
|
|
|
33
33
|
const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
|
|
34
34
|
core.Transforms.insertNodes(editor, [
|
|
35
35
|
embedElement,
|
|
36
|
-
typeof defaultNode === 'string'
|
|
36
|
+
typeof defaultNode === 'string'
|
|
37
|
+
? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
|
|
37
38
|
]);
|
|
38
39
|
core.Transforms.move(editor);
|
|
39
40
|
}
|
|
@@ -44,11 +45,12 @@ function createEmbed(options) {
|
|
|
44
45
|
insertEmbed,
|
|
45
46
|
with(editor) {
|
|
46
47
|
const { isVoid, normalizeNode } = editor;
|
|
47
|
-
editor.isVoid =
|
|
48
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
48
49
|
editor.normalizeNode = (entry) => {
|
|
49
50
|
const [node, path] = entry;
|
|
50
51
|
if (core.Element.isElement(node) && node.type === type) {
|
|
51
|
-
const strategy = node.provider
|
|
52
|
+
const strategy = node.provider
|
|
53
|
+
? strategies[node.provider] : undefined;
|
|
52
54
|
if (!strategy || !strategy.isElementDataValid(node)) {
|
|
53
55
|
core.Transforms.removeNodes(editor, { at: path });
|
|
54
56
|
return;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
6
|
+
const PodcastAppleEmbedStrategy = {
|
|
7
|
+
serialize: (embedCode) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const result = (_b = (_a = /^https:\/\/embed.podcasts.apple.com\/[\w-]*\/podcast\/[\S]*\/id([\d]*)/i.exec(embedCode)) !== null && _a !== void 0 ? _a : /^https:\/\/embed.podcasts.apple.com\/[\w-]*\/podcast\/id([\d]*)/i.exec(embedCode)) !== null && _b !== void 0 ? _b : /^https:\/\/podcasts.apple.com\/[\w-]*\/podcast\/[\S]*\/id([\d]*)/i.exec(embedCode);
|
|
10
|
+
if (result) {
|
|
11
|
+
const [, contextId] = result;
|
|
12
|
+
return {
|
|
13
|
+
embedType: 'podcast-apple',
|
|
14
|
+
contextId,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
deserialize: (data) => `https://embed.podcasts.apple.com/us/podcast/id${data.contextId}`,
|
|
19
|
+
isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.PodcastAppleEmbedStrategy = PodcastAppleEmbedStrategy;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EmbedElement, EmbedStrategy } from '@quadrats/common/embed';
|
|
2
|
+
export declare type PodcastAppleEmbedType = 'podcast-apple';
|
|
3
|
+
export declare type PodcastAppleEmbedElementData = {
|
|
4
|
+
embedType: PodcastAppleEmbedType;
|
|
5
|
+
contextId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type PodcastAppleEmbedElement = EmbedElement & PodcastAppleEmbedElementData;
|
|
8
|
+
export declare type PodcastAppleEmbedStrategy = EmbedStrategy<PodcastAppleEmbedElementData, string>;
|
|
9
|
+
export declare const PodcastAppleEmbedStrategy: PodcastAppleEmbedStrategy;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
2
|
+
const PodcastAppleEmbedStrategy = {
|
|
3
|
+
serialize: (embedCode) => {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const result = (_b = (_a = /^https:\/\/embed.podcasts.apple.com\/[\w-]*\/podcast\/[\S]*\/id([\d]*)/i.exec(embedCode)) !== null && _a !== void 0 ? _a : /^https:\/\/embed.podcasts.apple.com\/[\w-]*\/podcast\/id([\d]*)/i.exec(embedCode)) !== null && _b !== void 0 ? _b : /^https:\/\/podcasts.apple.com\/[\w-]*\/podcast\/[\S]*\/id([\d]*)/i.exec(embedCode);
|
|
6
|
+
if (result) {
|
|
7
|
+
const [, contextId] = result;
|
|
8
|
+
return {
|
|
9
|
+
embedType: 'podcast-apple',
|
|
10
|
+
contextId,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
deserialize: (data) => `https://embed.podcasts.apple.com/us/podcast/id${data.contextId}`,
|
|
15
|
+
isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { PodcastAppleEmbedStrategy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
6
|
+
const SpotifyEmbedStrategy = {
|
|
7
|
+
serialize: (embedCode) => {
|
|
8
|
+
const result = /^https:\/\/open.spotify.com\/([\S]*)/i.exec(embedCode);
|
|
9
|
+
if (result) {
|
|
10
|
+
const [, contextId] = result;
|
|
11
|
+
return {
|
|
12
|
+
embedType: 'spotify',
|
|
13
|
+
contextId,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
deserialize: (data) => `https://open.spotify.com/embed/${data.contextId}?utm_source=generator`,
|
|
18
|
+
isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.SpotifyEmbedStrategy = SpotifyEmbedStrategy;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EmbedElement, EmbedStrategy } from '@quadrats/common/embed';
|
|
2
|
+
export declare type SpotifyEmbedType = 'spotify';
|
|
3
|
+
export declare type SpotifyEmbedElementData = {
|
|
4
|
+
embedType: SpotifyEmbedType;
|
|
5
|
+
contextId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type SpotifyEmbedElement = EmbedElement & SpotifyEmbedElementData;
|
|
8
|
+
export declare type SpotifyEmbedStrategy = EmbedStrategy<SpotifyEmbedElementData, string>;
|
|
9
|
+
export declare const SpotifyEmbedStrategy: SpotifyEmbedStrategy;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
2
|
+
const SpotifyEmbedStrategy = {
|
|
3
|
+
serialize: (embedCode) => {
|
|
4
|
+
const result = /^https:\/\/open.spotify.com\/([\S]*)/i.exec(embedCode);
|
|
5
|
+
if (result) {
|
|
6
|
+
const [, contextId] = result;
|
|
7
|
+
return {
|
|
8
|
+
embedType: 'spotify',
|
|
9
|
+
contextId,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
deserialize: (data) => `https://open.spotify.com/embed/${data.contextId}?utm_source=generator`,
|
|
14
|
+
isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { SpotifyEmbedStrategy };
|
package/embed/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Editor,
|
|
2
|
-
export interface EmbedElement extends
|
|
1
|
+
import { Editor, QuadratsElement, Node, Text, Withable, WithElementType } from '@quadrats/core';
|
|
2
|
+
export interface EmbedElement extends QuadratsElement, WithElementType {
|
|
3
3
|
/**
|
|
4
4
|
* The embed provider.
|
|
5
5
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FILE_UPLOADER_TYPE } from './constants.js';
|
|
2
|
-
import { getFilesFromInput } from './getFilesFromInput.js';
|
|
3
1
|
import { __awaiter } from './_virtual/_tslib.js';
|
|
4
2
|
import { readFileAsDataURL } from '@quadrats/utils';
|
|
5
|
-
import {
|
|
3
|
+
import { Transforms, createParagraphElement } from '@quadrats/core';
|
|
4
|
+
import { FILE_UPLOADER_TYPE } from './constants.js';
|
|
5
|
+
import { getFilesFromInput } from './getFilesFromInput.js';
|
|
6
6
|
|
|
7
7
|
function createFileUploader(options = {}) {
|
|
8
8
|
const { type = FILE_UPLOADER_TYPE } = options;
|
|
@@ -25,10 +25,8 @@ function createFileUploader(options = {}) {
|
|
|
25
25
|
if (xhr.status < 400) {
|
|
26
26
|
const path = getPath();
|
|
27
27
|
if (path) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
31
|
-
});
|
|
28
|
+
Transforms.removeNodes(editor, { at: path });
|
|
29
|
+
Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
else {
|
|
@@ -65,10 +63,8 @@ function createFileUploader(options = {}) {
|
|
|
65
63
|
yield prev;
|
|
66
64
|
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
67
65
|
if (fileUploaderElement) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Transforms.move(editor);
|
|
71
|
-
});
|
|
66
|
+
Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], options);
|
|
67
|
+
Transforms.move(editor);
|
|
72
68
|
}
|
|
73
69
|
});
|
|
74
70
|
}), Promise.resolve());
|
|
@@ -79,10 +79,8 @@ function createFileUploader(options = {}) {
|
|
|
79
79
|
if (xhr.status < 400) {
|
|
80
80
|
const path = getPath();
|
|
81
81
|
if (path) {
|
|
82
|
-
core.
|
|
83
|
-
|
|
84
|
-
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
85
|
-
});
|
|
82
|
+
core.Transforms.removeNodes(editor, { at: path });
|
|
83
|
+
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
else {
|
|
@@ -119,10 +117,8 @@ function createFileUploader(options = {}) {
|
|
|
119
117
|
yield prev;
|
|
120
118
|
return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
|
|
121
119
|
if (fileUploaderElement) {
|
|
122
|
-
core.
|
|
123
|
-
|
|
124
|
-
core.Transforms.move(editor);
|
|
125
|
-
});
|
|
120
|
+
core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
|
|
121
|
+
core.Transforms.move(editor);
|
|
126
122
|
}
|
|
127
123
|
});
|
|
128
124
|
}), Promise.resolve());
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Editor,
|
|
1
|
+
import { Editor, QuadratsElement, Path, TransformsInsertNodesOptions, Withable } from '@quadrats/core';
|
|
2
2
|
import { GetFilesFromInputOptions } from './getFilesFromInput';
|
|
3
3
|
export interface XHRUploadHeaders {
|
|
4
4
|
[name: string]: string;
|
|
5
5
|
}
|
|
6
|
-
export interface FileUploaderElement extends
|
|
6
|
+
export interface FileUploaderElement extends QuadratsElement {
|
|
7
7
|
type: string;
|
|
8
8
|
register: (getPath: () => Path | undefined, onProgress: (percentage: number) => void) => VoidFunction;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* For creating temorary element while uploading.
|
|
12
12
|
*/
|
|
13
|
-
export declare type FileUploaderCreateElementByDataURL = (dataURL: string) =>
|
|
13
|
+
export declare type FileUploaderCreateElementByDataURL = (dataURL: string) => QuadratsElement;
|
|
14
14
|
/**
|
|
15
15
|
* For create element after uploaded.
|
|
16
16
|
*/
|
|
17
|
-
export declare type FileUploaderCreateElementByResponse = (response: any) =>
|
|
17
|
+
export declare type FileUploaderCreateElementByResponse = (response: any) => QuadratsElement;
|
|
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;
|
|
@@ -32,6 +32,6 @@ export interface FileUploaderCreateFileUploaderElementOptions {
|
|
|
32
32
|
export declare type FileUploaderUploadOptions = FileUploaderCreateFileUploaderElementOptions & GetFilesFromInputOptions & TransformsInsertNodesOptions;
|
|
33
33
|
export interface FileUploader extends Withable {
|
|
34
34
|
type: string;
|
|
35
|
-
createFileUploaderElement(editor: Editor
|
|
36
|
-
upload(editor: Editor
|
|
35
|
+
createFileUploaderElement(editor: Editor, file: File, options: FileUploaderCreateFileUploaderElementOptions): Promise<FileUploaderElement | undefined>;
|
|
36
|
+
upload(editor: Editor, options: FileUploaderUploadOptions): Promise<void>;
|
|
37
37
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FOOTNOTE_TYPE = "footnote";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isNodesTypeIn, getNodes, Transforms, unwrapNodesByTypes, wrapNodesWithUnhangRange } from '@quadrats/core';
|
|
2
|
+
import { FOOTNOTE_TYPE } from './constants.js';
|
|
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, _c;
|
|
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 (_c = firstNode) === null || _c === void 0 ? void 0 : _c.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
|
+
}
|
|
70
|
+
|
|
71
|
+
export { createFootnote };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@quadrats/core');
|
|
6
|
+
|
|
7
|
+
const FOOTNOTE_TYPE = 'footnote';
|
|
8
|
+
|
|
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, _c;
|
|
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 (_c = firstNode) === null || _c === void 0 ? void 0 : _c.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
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.FOOTNOTE_TYPE = FOOTNOTE_TYPE;
|
|
77
|
+
exports.createFootnote = createFootnote;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Editor, Range, QuadratsElement, WithElementType, UnwrapNodeByTypesOptions, TransformsWrapNodesOptions, Withable } from '@quadrats/core';
|
|
2
|
+
export interface FootnoteData {
|
|
3
|
+
footnote: string;
|
|
4
|
+
index: number;
|
|
5
|
+
wrapperText: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FootnoteElement extends QuadratsElement, WithElementType {
|
|
8
|
+
footnote: string;
|
|
9
|
+
index?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface FootnoteUpdateFootnoteIndexOptions {
|
|
12
|
+
startAt?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare type FootnoteUnwrapFootnoteOptions = UnwrapNodeByTypesOptions;
|
|
15
|
+
export interface FootnoteWrapFootnoteOptions extends Omit<TransformsWrapNodesOptions, 'split'> {
|
|
16
|
+
index?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface FootnoteUpsertFootnoteOptions {
|
|
19
|
+
at?: Range;
|
|
20
|
+
}
|
|
21
|
+
export interface Footnote extends WithElementType, Withable {
|
|
22
|
+
getFootnoteText(editor: Editor): string;
|
|
23
|
+
isSelectionInFootnote(editor: Editor): boolean;
|
|
24
|
+
unwrapFootnote(editor: Editor, options?: FootnoteUnwrapFootnoteOptions): void;
|
|
25
|
+
updateFootnoteIndex(editor: Editor, options?: FootnoteUpdateFootnoteIndexOptions): void;
|
|
26
|
+
upsertFootnoteAndUpdateIndex(editor: Editor, footnote: string, options?: FootnoteUpsertFootnoteOptions): void;
|
|
27
|
+
wrapFootnote(editor: Editor, footnote: string, options?: FootnoteWrapFootnoteOptions): void;
|
|
28
|
+
}
|
package/heading/createHeading.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { HEADING_TYPE, HEADING_LEVELS } from './constants.js';
|
|
2
1
|
import { Element, Transforms, PARAGRAPH_TYPE, normalizeOnlyInlineOrTextInChildren, getNodes } from '@quadrats/core';
|
|
2
|
+
import { HEADING_TYPE, HEADING_LEVELS } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createHeading({ type = HEADING_TYPE, enabledLevels = HEADING_LEVELS, } = {}) {
|
|
5
|
-
const getHeadingNodes = (editor, level, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match:
|
|
5
|
+
const getHeadingNodes = (editor, level, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: node => node.type === type && node.level === level }));
|
|
6
6
|
const isSelectionInHeading = (editor, level, options = {}) => {
|
|
7
7
|
const [match] = getHeadingNodes(editor, level, options);
|
|
8
8
|
return !!match;
|
package/heading/index.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ const HEADING_TYPE = 'heading';
|
|
|
8
8
|
const HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
|
|
9
9
|
|
|
10
10
|
function createHeading({ type = HEADING_TYPE, enabledLevels = HEADING_LEVELS, } = {}) {
|
|
11
|
-
const getHeadingNodes = (editor, level, options = {}) => core.getNodes(editor, Object.assign(Object.assign({}, options), { match:
|
|
11
|
+
const getHeadingNodes = (editor, level, options = {}) => core.getNodes(editor, Object.assign(Object.assign({}, options), { match: node => node.type === type && node.level === level }));
|
|
12
12
|
const isSelectionInHeading = (editor, level, options = {}) => {
|
|
13
13
|
const [match] = getHeadingNodes(editor, level, options);
|
|
14
14
|
return !!match;
|
package/heading/typings.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Editor,
|
|
1
|
+
import { Editor, QuadratsElement, GetNodesOptions, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
|
|
2
2
|
export declare type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
|
-
export interface HeadingElement extends
|
|
3
|
+
export interface HeadingElement extends QuadratsElement, WithElementType {
|
|
4
4
|
level: HeadingLevel;
|
|
5
5
|
}
|
|
6
6
|
export interface WithEnabledHeadingLevels<L extends HeadingLevel> {
|