@quadrats/common 0.5.9 → 0.6.2
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 +22 -25
- package/blockquote/index.cjs.js +21 -24
- package/blockquote/typings.d.ts +2 -0
- package/embed/strategies/podcast-apple/index.cjs.js +5 -4
- package/embed/strategies/podcast-apple/index.d.ts +1 -0
- package/embed/strategies/podcast-apple/index.js +5 -4
- package/file-uploader/createFileUploader.js +5 -3
- package/file-uploader/index.cjs.js +4 -2
- package/link/createLink.js +1 -0
- package/link/index.cjs.js +1 -0
- package/package.json +4 -4
|
@@ -1,38 +1,35 @@
|
|
|
1
|
-
import { isNodesTypeIn,
|
|
1
|
+
import { isNodesTypeIn, unwrapNodesByTypes, wrapNodesWithUnhangRange } from '@quadrats/core';
|
|
2
2
|
import { BLOCKQUOTE_TYPE } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
|
5
|
+
const unwrapBlockquote = (editor) => {
|
|
6
|
+
unwrapNodesByTypes(editor, [type]);
|
|
7
|
+
};
|
|
8
|
+
const wrapBlockquote = (editor) => {
|
|
9
|
+
const element = {
|
|
10
|
+
type,
|
|
11
|
+
children: [],
|
|
12
|
+
};
|
|
13
|
+
wrapNodesWithUnhangRange(editor, element, { split: true });
|
|
14
|
+
};
|
|
15
|
+
const isSelectionInBlockquote = editor => (isNodesTypeIn(editor, [type], { mode: 'highest' }));
|
|
5
16
|
return {
|
|
6
17
|
type,
|
|
7
|
-
|
|
18
|
+
unwrapBlockquote,
|
|
19
|
+
wrapBlockquote,
|
|
20
|
+
isSelectionInBlockquote,
|
|
8
21
|
toggleBlockquote: (editor) => {
|
|
9
|
-
const actived =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Transforms.collapse(editor, { edge: 'end' });
|
|
17
|
-
// Only last block add paragraph automatically
|
|
18
|
-
if (!Editor.next(editor)) {
|
|
19
|
-
Transforms.insertNodes(editor, [createParagraphElement()]);
|
|
20
|
-
}
|
|
21
|
-
Transforms.select(editor, originPoint);
|
|
22
|
+
const actived = isSelectionInBlockquote(editor);
|
|
23
|
+
if (editor.selection) {
|
|
24
|
+
if (actived) {
|
|
25
|
+
unwrapBlockquote(editor);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
wrapBlockquote(editor);
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
},
|
|
25
32
|
with(editor) {
|
|
26
|
-
const { normalizeNode } = editor;
|
|
27
|
-
editor.normalizeNode = (entry) => {
|
|
28
|
-
const [node] = entry;
|
|
29
|
-
if (Element.isElement(node) && node.type === type) {
|
|
30
|
-
if (normalizeOnlyInlineOrTextInChildren(editor, entry)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
normalizeNode(entry);
|
|
35
|
-
};
|
|
36
33
|
return editor;
|
|
37
34
|
},
|
|
38
35
|
};
|
package/blockquote/index.cjs.js
CHANGED
|
@@ -7,37 +7,34 @@ var core = require('@quadrats/core');
|
|
|
7
7
|
const BLOCKQUOTE_TYPE = 'blockquote';
|
|
8
8
|
|
|
9
9
|
function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
|
|
10
|
+
const unwrapBlockquote = (editor) => {
|
|
11
|
+
core.unwrapNodesByTypes(editor, [type]);
|
|
12
|
+
};
|
|
13
|
+
const wrapBlockquote = (editor) => {
|
|
14
|
+
const element = {
|
|
15
|
+
type,
|
|
16
|
+
children: [],
|
|
17
|
+
};
|
|
18
|
+
core.wrapNodesWithUnhangRange(editor, element, { split: true });
|
|
19
|
+
};
|
|
20
|
+
const isSelectionInBlockquote = editor => (core.isNodesTypeIn(editor, [type], { mode: 'highest' }));
|
|
10
21
|
return {
|
|
11
22
|
type,
|
|
12
|
-
|
|
23
|
+
unwrapBlockquote,
|
|
24
|
+
wrapBlockquote,
|
|
25
|
+
isSelectionInBlockquote,
|
|
13
26
|
toggleBlockquote: (editor) => {
|
|
14
|
-
const actived =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
core.Transforms.collapse(editor, { edge: 'end' });
|
|
22
|
-
// Only last block add paragraph automatically
|
|
23
|
-
if (!core.Editor.next(editor)) {
|
|
24
|
-
core.Transforms.insertNodes(editor, [core.createParagraphElement()]);
|
|
25
|
-
}
|
|
26
|
-
core.Transforms.select(editor, originPoint);
|
|
27
|
+
const actived = isSelectionInBlockquote(editor);
|
|
28
|
+
if (editor.selection) {
|
|
29
|
+
if (actived) {
|
|
30
|
+
unwrapBlockquote(editor);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
wrapBlockquote(editor);
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
},
|
|
30
37
|
with(editor) {
|
|
31
|
-
const { normalizeNode } = editor;
|
|
32
|
-
editor.normalizeNode = (entry) => {
|
|
33
|
-
const [node] = entry;
|
|
34
|
-
if (core.Element.isElement(node) && node.type === type) {
|
|
35
|
-
if (core.normalizeOnlyInlineOrTextInChildren(editor, entry)) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
normalizeNode(entry);
|
|
40
|
-
};
|
|
41
38
|
return editor;
|
|
42
39
|
},
|
|
43
40
|
};
|
package/blockquote/typings.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Editor, QuadratsElement, Withable, WithElementType } from '@quadrats/co
|
|
|
2
2
|
export interface BlockquoteElement extends QuadratsElement, WithElementType {
|
|
3
3
|
}
|
|
4
4
|
export interface Blockquote<T extends Editor = Editor> extends WithElementType, Withable {
|
|
5
|
+
unwrapBlockquote(editor: T): void;
|
|
6
|
+
wrapBlockquote(editor: T): void;
|
|
5
7
|
isSelectionInBlockquote(editor: T): boolean;
|
|
6
8
|
toggleBlockquote(editor: T): void;
|
|
7
9
|
}
|
|
@@ -6,17 +6,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
const PodcastAppleEmbedStrategy = {
|
|
7
7
|
serialize: (embedCode) => {
|
|
8
8
|
var _a, _b;
|
|
9
|
-
const result = (_b = (_a = /^https:\/\/embed.podcasts.apple.com\/[\w-]
|
|
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
10
|
if (result) {
|
|
11
|
-
const [, contextId] = result;
|
|
11
|
+
const [, language, contextId] = result;
|
|
12
12
|
return {
|
|
13
13
|
embedType: 'podcast-apple',
|
|
14
|
+
language,
|
|
14
15
|
contextId,
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
|
-
deserialize:
|
|
19
|
-
isElementDataValid:
|
|
19
|
+
deserialize: data => { var _a; return `https://embed.podcasts.apple.com/${(_a = data.language) !== null && _a !== void 0 ? _a : 'us'}/podcast/id${data.contextId}`; },
|
|
20
|
+
isElementDataValid: data => typeof data.contextId === 'string' && !!(data.contextId),
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
exports.PodcastAppleEmbedStrategy = PodcastAppleEmbedStrategy;
|
|
@@ -2,6 +2,7 @@ import { EmbedElement, EmbedStrategy } from '@quadrats/common/embed';
|
|
|
2
2
|
export declare type PodcastAppleEmbedType = 'podcast-apple';
|
|
3
3
|
export declare type PodcastAppleEmbedElementData = {
|
|
4
4
|
embedType: PodcastAppleEmbedType;
|
|
5
|
+
language?: string;
|
|
5
6
|
contextId: string;
|
|
6
7
|
};
|
|
7
8
|
export declare type PodcastAppleEmbedElement = EmbedElement & PodcastAppleEmbedElementData;
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
const PodcastAppleEmbedStrategy = {
|
|
3
3
|
serialize: (embedCode) => {
|
|
4
4
|
var _a, _b;
|
|
5
|
-
const result = (_b = (_a = /^https:\/\/embed.podcasts.apple.com\/[\w-]
|
|
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
6
|
if (result) {
|
|
7
|
-
const [, contextId] = result;
|
|
7
|
+
const [, language, contextId] = result;
|
|
8
8
|
return {
|
|
9
9
|
embedType: 'podcast-apple',
|
|
10
|
+
language,
|
|
10
11
|
contextId,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
|
-
deserialize:
|
|
15
|
-
isElementDataValid:
|
|
15
|
+
deserialize: data => { var _a; return `https://embed.podcasts.apple.com/${(_a = data.language) !== null && _a !== void 0 ? _a : 'us'}/podcast/id${data.contextId}`; },
|
|
16
|
+
isElementDataValid: data => typeof data.contextId === 'string' && !!(data.contextId),
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
export { PodcastAppleEmbedStrategy };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from './_virtual/_tslib.js';
|
|
2
2
|
import { readFileAsDataURL } from '@quadrats/utils';
|
|
3
|
-
import { Transforms, createParagraphElement } from '@quadrats/core';
|
|
3
|
+
import { Transforms, createParagraphElement, HistoryEditor } from '@quadrats/core';
|
|
4
4
|
import { FILE_UPLOADER_TYPE } from './constants.js';
|
|
5
5
|
import { getFilesFromInput } from './getFilesFromInput.js';
|
|
6
6
|
|
|
@@ -25,8 +25,10 @@ function createFileUploader(options = {}) {
|
|
|
25
25
|
if (xhr.status < 400) {
|
|
26
26
|
const path = getPath();
|
|
27
27
|
if (path) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
HistoryEditor.withoutSaving(editor, () => {
|
|
29
|
+
Transforms.removeNodes(editor, { at: path });
|
|
30
|
+
Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
31
|
+
});
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
else {
|
|
@@ -79,8 +79,10 @@ function createFileUploader(options = {}) {
|
|
|
79
79
|
if (xhr.status < 400) {
|
|
80
80
|
const path = getPath();
|
|
81
81
|
if (path) {
|
|
82
|
-
core.
|
|
83
|
-
|
|
82
|
+
core.HistoryEditor.withoutSaving(editor, () => {
|
|
83
|
+
core.Transforms.removeNodes(editor, { at: path });
|
|
84
|
+
core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
|
|
85
|
+
});
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
else {
|
package/link/createLink.js
CHANGED
package/link/index.cjs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
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.
|
|
22
|
-
"@quadrats/locales": "^0.
|
|
23
|
-
"@quadrats/utils": "^0.
|
|
21
|
+
"@quadrats/core": "^0.6.2",
|
|
22
|
+
"@quadrats/locales": "^0.6.0",
|
|
23
|
+
"@quadrats/utils": "^0.6.0"
|
|
24
24
|
}
|
|
25
25
|
}
|