@quadrats/common 0.4.4 → 0.5.3
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 +19 -3
- package/blockquote/index.cjs.js +18 -2
- package/blockquote/typings.d.ts +5 -5
- package/bold/createBold.d.ts +1 -1
- package/bold/createBold.js +2 -3
- package/bold/index.cjs.js +2 -3
- package/divider/createDivider.js +1 -1
- package/divider/index.cjs.js +1 -1
- package/divider/typings.d.ts +4 -4
- package/embed/createEmbed.js +5 -3
- package/embed/index.cjs.js +5 -3
- package/embed/typings.d.ts +4 -4
- package/file-uploader/createFileUploader.d.ts +2 -1
- package/file-uploader/createFileUploader.js +5 -11
- package/file-uploader/index.cjs.js +4 -10
- package/file-uploader/typings.d.ts +7 -7
- package/footnote/createFootnote.js +6 -14
- package/footnote/index.cjs.js +6 -14
- package/footnote/typings.d.ts +14 -10
- package/heading/createHeading.js +1 -1
- package/heading/index.cjs.js +1 -1
- package/heading/typings.d.ts +6 -6
- package/highlight/createHighlight.d.ts +1 -1
- package/highlight/createHighlight.js +2 -3
- package/highlight/index.cjs.js +2 -3
- package/image/createImage.js +6 -6
- package/image/index.cjs.js +6 -6
- package/image/typings.d.ts +12 -12
- package/input-block/createInputBlock.js +7 -1
- package/input-block/index.cjs.js +7 -1
- package/input-block/typings.d.ts +5 -5
- package/italic/createItalic.d.ts +1 -1
- package/italic/createItalic.js +2 -3
- package/italic/index.cjs.js +2 -3
- package/link/createLink.js +6 -3
- package/link/index.cjs.js +6 -3
- package/link/typings.d.ts +9 -9
- package/list/createList.js +11 -5
- package/list/index.cjs.js +11 -5
- package/list/typings.d.ts +14 -14
- package/package.json +4 -4
- package/read-more/createReadMore.js +1 -1
- package/read-more/index.cjs.js +1 -1
- package/read-more/typings.d.ts +4 -4
- package/strikethrough/createStrikethrough.d.ts +1 -1
- package/strikethrough/createStrikethrough.js +2 -3
- package/strikethrough/index.cjs.js +2 -3
- package/toggle-mark/createToggleMarkCreator.d.ts +3 -3
- package/toggle-mark/createToggleMarkCreator.js +18 -12
- package/toggle-mark/index.cjs.js +17 -11
- package/toggle-mark/typings.d.ts +3 -3
- package/underline/createUnderline.d.ts +1 -1
- package/underline/createUnderline.js +2 -3
- package/underline/index.cjs.js +2 -3
package/image/index.cjs.js
CHANGED
|
@@ -31,7 +31,7 @@ function getImageElementCommonProps(element, hostingResolvers) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function resolveSizeSteps(steps) {
|
|
34
|
-
let sortedSteps = steps.filter(
|
|
34
|
+
let sortedSteps = steps.filter(step => step > 0 && step < 100).sort();
|
|
35
35
|
if (!sortedSteps.includes(100)) {
|
|
36
36
|
sortedSteps = [...sortedSteps, 100];
|
|
37
37
|
}
|
|
@@ -44,9 +44,9 @@ function createImage(options = {}) {
|
|
|
44
44
|
const getAboveImageFigure = (editor, options) => core.getAboveByTypes(editor, [types.figure], options);
|
|
45
45
|
const getAboveImageCaption = (editor, options) => core.getAboveByTypes(editor, [types.caption], options);
|
|
46
46
|
const isNodesInImage = (editor, options) => core.isNodesTypeIn(editor, [types.image], options);
|
|
47
|
-
const isSelectionInImage =
|
|
48
|
-
const isSelectionInImageCaption =
|
|
49
|
-
const isCollapsedOnImage =
|
|
47
|
+
const isSelectionInImage = editor => isNodesInImage(editor);
|
|
48
|
+
const isSelectionInImageCaption = editor => core.isNodesTypeIn(editor, [types.caption]);
|
|
49
|
+
const isCollapsedOnImage = editor => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
|
|
50
50
|
const createImageElement = (src, hosting) => {
|
|
51
51
|
const imageElement = {
|
|
52
52
|
type: types.image,
|
|
@@ -79,7 +79,7 @@ function createImage(options = {}) {
|
|
|
79
79
|
if (!sizeSteps) {
|
|
80
80
|
return percentage;
|
|
81
81
|
}
|
|
82
|
-
const lowerIndex = sizeSteps.findIndex(
|
|
82
|
+
const lowerIndex = sizeSteps.findIndex(step => step >= percentage) - 1;
|
|
83
83
|
const upperIndex = lowerIndex + 1;
|
|
84
84
|
if (lowerIndex < 0) {
|
|
85
85
|
return sizeSteps[0];
|
|
@@ -147,7 +147,7 @@ function createImage(options = {}) {
|
|
|
147
147
|
}
|
|
148
148
|
insertBreak();
|
|
149
149
|
};
|
|
150
|
-
editor.isVoid =
|
|
150
|
+
editor.isVoid = element => element.type === types.image || isVoid(element);
|
|
151
151
|
editor.normalizeNode = (entry) => {
|
|
152
152
|
const [node, path] = entry;
|
|
153
153
|
if (core.Element.isElement(node)) {
|
package/image/typings.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Editor,
|
|
1
|
+
import { Editor, QuadratsElement, GetAboveByTypesOptions, Location, NodeEntry, Text, Withable, WithElementType } from '@quadrats/core';
|
|
2
2
|
export declare type ImageFigureTypeKey = 'figure';
|
|
3
3
|
export declare type ImageTypeKey = 'image';
|
|
4
4
|
export declare type ImageCaptionTypeKey = 'caption';
|
|
5
5
|
export declare type ImageTypes = Record<ImageFigureTypeKey | ImageTypeKey | ImageCaptionTypeKey, string>;
|
|
6
|
-
export interface ImageFigureElement extends
|
|
6
|
+
export interface ImageFigureElement extends QuadratsElement, WithElementType {
|
|
7
7
|
width?: number;
|
|
8
8
|
}
|
|
9
|
-
export interface ImageElement extends
|
|
9
|
+
export interface ImageElement extends QuadratsElement, WithElementType {
|
|
10
10
|
children: [Text];
|
|
11
11
|
src: string;
|
|
12
12
|
/**
|
|
@@ -15,7 +15,7 @@ export interface ImageElement extends Element, WithElementType {
|
|
|
15
15
|
*/
|
|
16
16
|
hosting?: string;
|
|
17
17
|
}
|
|
18
|
-
export interface ImageCaptionElement extends
|
|
18
|
+
export interface ImageCaptionElement extends QuadratsElement, WithElementType {
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Indicate how to resolve the `src` and `hosting` of image element.
|
|
@@ -37,7 +37,7 @@ export declare type ImageHostingResolvers<Hosting extends string> = Record<Hosti
|
|
|
37
37
|
export declare type ImageSizeSteps = ReadonlyArray<number>;
|
|
38
38
|
export declare type ImageGetAboveImageFigureOptions = GetAboveByTypesOptions;
|
|
39
39
|
export declare type ImageGetAboveImageCaptionOptions = GetAboveByTypesOptions;
|
|
40
|
-
export interface Image<Hosting extends string> extends Withable {
|
|
40
|
+
export interface Image<Hosting extends string, T extends Editor = Editor> extends Withable {
|
|
41
41
|
/**
|
|
42
42
|
* An object which keys are `figure`, `image`, 'caption` and values are the corresponding element types.
|
|
43
43
|
*/
|
|
@@ -51,15 +51,15 @@ export interface Image<Hosting extends string> extends Withable {
|
|
|
51
51
|
*/
|
|
52
52
|
sizeSteps?: ImageSizeSteps;
|
|
53
53
|
isImageUrl(url: string): boolean;
|
|
54
|
-
getAboveImageFigure(editor:
|
|
55
|
-
getAboveImageCaption(editor:
|
|
56
|
-
isSelectionInImage(editor:
|
|
57
|
-
isSelectionInImageCaption(editor:
|
|
58
|
-
isCollapsedOnImage(editor:
|
|
54
|
+
getAboveImageFigure(editor: T, options?: ImageGetAboveImageFigureOptions): NodeEntry<ImageFigureElement> | undefined;
|
|
55
|
+
getAboveImageCaption(editor: T, options?: ImageGetAboveImageCaptionOptions): NodeEntry<ImageCaptionElement> | undefined;
|
|
56
|
+
isSelectionInImage(editor: T): boolean;
|
|
57
|
+
isSelectionInImageCaption(editor: T): boolean;
|
|
58
|
+
isCollapsedOnImage(editor: T): boolean;
|
|
59
59
|
createImageElement(src: string, hosting?: Hosting): ImageFigureElement;
|
|
60
|
-
insertImage(editor:
|
|
60
|
+
insertImage(editor: T, src: string, options?: {
|
|
61
61
|
hosting?: Hosting;
|
|
62
62
|
at?: Location;
|
|
63
63
|
}): void;
|
|
64
|
-
resizeImage(editor:
|
|
64
|
+
resizeImage(editor: T, entry: NodeEntry<QuadratsElement>, width: number): void;
|
|
65
65
|
}
|
|
@@ -28,7 +28,13 @@ function createInputBlock(options = {}) {
|
|
|
28
28
|
confirm,
|
|
29
29
|
with(editor) {
|
|
30
30
|
const { isVoid } = editor;
|
|
31
|
-
editor.isVoid = (element) =>
|
|
31
|
+
editor.isVoid = (element) => {
|
|
32
|
+
// invalidate unfinished input_block from storage
|
|
33
|
+
if (element.type === type
|
|
34
|
+
&& typeof element.getPlaceholder !== 'function')
|
|
35
|
+
return false;
|
|
36
|
+
return element.type === type || isVoid(element);
|
|
37
|
+
};
|
|
32
38
|
return editor;
|
|
33
39
|
},
|
|
34
40
|
};
|
package/input-block/index.cjs.js
CHANGED
|
@@ -33,7 +33,13 @@ function createInputBlock(options = {}) {
|
|
|
33
33
|
confirm,
|
|
34
34
|
with(editor) {
|
|
35
35
|
const { isVoid } = editor;
|
|
36
|
-
editor.isVoid = (element) =>
|
|
36
|
+
editor.isVoid = (element) => {
|
|
37
|
+
// invalidate unfinished input_block from storage
|
|
38
|
+
if (element.type === type
|
|
39
|
+
&& typeof element.getPlaceholder !== 'function')
|
|
40
|
+
return false;
|
|
41
|
+
return element.type === type || isVoid(element);
|
|
42
|
+
};
|
|
37
43
|
return editor;
|
|
38
44
|
},
|
|
39
45
|
};
|
package/input-block/typings.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Editor,
|
|
1
|
+
import { Editor, QuadratsElement, NodeEntry, Withable } from '@quadrats/core';
|
|
2
2
|
import { InputWidgetConfig } from '@quadrats/common/input-widget';
|
|
3
|
-
export interface InputBlockElement extends
|
|
3
|
+
export interface InputBlockElement extends QuadratsElement, InputWidgetConfig {
|
|
4
4
|
type: string;
|
|
5
5
|
}
|
|
6
|
-
export interface InputBlock extends Withable {
|
|
6
|
+
export interface InputBlock<T extends Editor = Editor> extends Withable {
|
|
7
7
|
type: string;
|
|
8
|
-
start(editor:
|
|
9
|
-
remove(editor:
|
|
8
|
+
start(editor: T, config: InputWidgetConfig): void;
|
|
9
|
+
remove(editor: T, entry: NodeEntry<InputBlockElement>, foucs: VoidFunction): void;
|
|
10
10
|
confirm(element: InputBlockElement, value: string, remove: VoidFunction): void;
|
|
11
11
|
}
|
package/italic/createItalic.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const createItalic: (variant?: string | undefined) => ({ type,
|
|
1
|
+
export declare const createItalic: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<import("slate").BaseEditor>;
|
package/italic/createItalic.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
|
|
2
|
-
import { getVariantType } from '@quadrats/core';
|
|
3
2
|
import { ITALIC_TYPE } from './constants.js';
|
|
4
3
|
|
|
5
4
|
const createItalic = (variant) => createToggleMarkCreator({
|
|
6
|
-
type:
|
|
7
|
-
|
|
5
|
+
type: ITALIC_TYPE,
|
|
6
|
+
variant,
|
|
8
7
|
});
|
|
9
8
|
|
|
10
9
|
export { createItalic };
|
package/italic/index.cjs.js
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var toggleMark = require('@quadrats/common/toggle-mark');
|
|
6
|
-
var core = require('@quadrats/core');
|
|
7
6
|
|
|
8
7
|
const ITALIC_TYPE = 'italic';
|
|
9
8
|
|
|
10
9
|
const createItalic = (variant) => toggleMark.createToggleMarkCreator({
|
|
11
|
-
type:
|
|
12
|
-
|
|
10
|
+
type: ITALIC_TYPE,
|
|
11
|
+
variant,
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
exports.ITALIC_TYPE = ITALIC_TYPE;
|
package/link/createLink.js
CHANGED
|
@@ -35,7 +35,7 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
const isSelectionInLink =
|
|
38
|
+
const isSelectionInLink = editor => isNodesTypeIn(editor, [type]);
|
|
39
39
|
const insertLink = (editor, url, options = {}) => {
|
|
40
40
|
const { text = url } = options;
|
|
41
41
|
const link = {
|
|
@@ -66,6 +66,9 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
|
|
|
66
66
|
unwrapLink(editor, { at: wrappableVoidPath });
|
|
67
67
|
wrapLink(editor, url, { at: wrappableVoidPath });
|
|
68
68
|
}
|
|
69
|
+
else {
|
|
70
|
+
insertLink(editor, url, { at });
|
|
71
|
+
}
|
|
69
72
|
return;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -115,7 +118,7 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
|
|
|
115
118
|
if (!wrappableVoidTypes) {
|
|
116
119
|
return true;
|
|
117
120
|
}
|
|
118
|
-
return !element.children.some(
|
|
121
|
+
return !element.children.some(child => Editor.isBlock(editor, child)
|
|
119
122
|
&& Editor.isVoid(editor, child)
|
|
120
123
|
&& wrappableVoidTypes.includes(child.type));
|
|
121
124
|
};
|
|
@@ -133,7 +136,7 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
|
|
|
133
136
|
* Remove empty content.
|
|
134
137
|
*/
|
|
135
138
|
if (Text.isTextList(node.children)) {
|
|
136
|
-
if (node.children.every(
|
|
139
|
+
if (node.children.every(textNode => !textNode.text)) {
|
|
137
140
|
Transforms.unwrapNodes(editor, { at: path });
|
|
138
141
|
return;
|
|
139
142
|
}
|
package/link/index.cjs.js
CHANGED
|
@@ -40,7 +40,7 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
const isSelectionInLink =
|
|
43
|
+
const isSelectionInLink = editor => core.isNodesTypeIn(editor, [type]);
|
|
44
44
|
const insertLink = (editor, url, options = {}) => {
|
|
45
45
|
const { text = url } = options;
|
|
46
46
|
const link = {
|
|
@@ -71,6 +71,9 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
|
|
|
71
71
|
unwrapLink(editor, { at: wrappableVoidPath });
|
|
72
72
|
wrapLink(editor, url, { at: wrappableVoidPath });
|
|
73
73
|
}
|
|
74
|
+
else {
|
|
75
|
+
insertLink(editor, url, { at });
|
|
76
|
+
}
|
|
74
77
|
return;
|
|
75
78
|
}
|
|
76
79
|
}
|
|
@@ -120,7 +123,7 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
|
|
|
120
123
|
if (!wrappableVoidTypes) {
|
|
121
124
|
return true;
|
|
122
125
|
}
|
|
123
|
-
return !element.children.some(
|
|
126
|
+
return !element.children.some(child => core.Editor.isBlock(editor, child)
|
|
124
127
|
&& core.Editor.isVoid(editor, child)
|
|
125
128
|
&& wrappableVoidTypes.includes(child.type));
|
|
126
129
|
};
|
|
@@ -138,7 +141,7 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
|
|
|
138
141
|
* Remove empty content.
|
|
139
142
|
*/
|
|
140
143
|
if (core.Text.isTextList(node.children)) {
|
|
141
|
-
if (node.children.every(
|
|
144
|
+
if (node.children.every(textNode => !textNode.text)) {
|
|
142
145
|
core.Transforms.unwrapNodes(editor, { at: path });
|
|
143
146
|
return;
|
|
144
147
|
}
|
package/link/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Editor, Location, Range,
|
|
2
|
-
export interface LinkElement extends
|
|
1
|
+
import { Editor, Location, Range, WithElementType, TransformsInsertNodesOptions, UnwrapNodeByTypesOptions, TransformsWrapNodesOptions, Withable, QuadratsElement } from '@quadrats/core';
|
|
2
|
+
export interface LinkElement extends QuadratsElement, WithElementType {
|
|
3
3
|
url: string;
|
|
4
4
|
}
|
|
5
5
|
export interface LinkInsertLinkOptions extends TransformsInsertNodesOptions {
|
|
@@ -10,18 +10,18 @@ export declare type LinkWrapLinkOptions = Omit<TransformsWrapNodesOptions, 'spli
|
|
|
10
10
|
export interface LinkUpsertLinkOptions {
|
|
11
11
|
at?: Range;
|
|
12
12
|
}
|
|
13
|
-
export interface Link extends WithElementType, Withable {
|
|
13
|
+
export interface Link<T extends Editor = Editor> extends WithElementType, Withable {
|
|
14
14
|
isUrl(value: string): boolean;
|
|
15
15
|
/**
|
|
16
16
|
* To get the first previous text which is url and its range.
|
|
17
17
|
*/
|
|
18
|
-
getFirstPrevTextAsUrlAndRange(editor:
|
|
18
|
+
getFirstPrevTextAsUrlAndRange(editor: T, at: Location): {
|
|
19
19
|
url: string;
|
|
20
20
|
at: Range;
|
|
21
21
|
} | undefined;
|
|
22
|
-
isSelectionInLink(editor:
|
|
23
|
-
insertLink(editor:
|
|
24
|
-
unwrapLink(editor:
|
|
25
|
-
wrapLink(editor:
|
|
26
|
-
upsertLink(editor:
|
|
22
|
+
isSelectionInLink(editor: T): boolean;
|
|
23
|
+
insertLink(editor: T, url: string, options?: LinkInsertLinkOptions): void;
|
|
24
|
+
unwrapLink(editor: T, options?: LinkUnwrapLinkOptions): void;
|
|
25
|
+
wrapLink(editor: T, url: string, options?: LinkWrapLinkOptions): void;
|
|
26
|
+
upsertLink(editor: T, url: string, options?: LinkUpsertLinkOptions): void;
|
|
27
27
|
}
|
package/list/createList.js
CHANGED
|
@@ -50,19 +50,24 @@ function createList(options = {}) {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
const increaseListItemDepth = (editor, entries) => {
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
53
54
|
const { list: [listNode], listItem: [, listItemPath], } = entries;
|
|
54
55
|
if (!isFirstChild(listItemPath)) {
|
|
55
56
|
const previousEntry = Editor.node(editor, Path.previous(listItemPath));
|
|
56
57
|
if (previousEntry) {
|
|
57
58
|
const [previousNode, previousPath] = previousEntry;
|
|
58
|
-
const lastNodeOfPreviousNode = previousNode.children[previousNode.children.length - 1];
|
|
59
|
+
const lastNodeOfPreviousNode = ((_a = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _a !== void 0 ? _a : [])[((_b = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _b !== void 0 ? _b : []).length - 1];
|
|
59
60
|
/**
|
|
60
61
|
* Move list item next to the last node of previous node of list item.
|
|
61
62
|
*/
|
|
62
63
|
if (isListElement(lastNodeOfPreviousNode)) {
|
|
63
64
|
Transforms.moveNodes(editor, {
|
|
64
65
|
at: listItemPath,
|
|
65
|
-
to: [
|
|
66
|
+
to: [
|
|
67
|
+
...previousPath,
|
|
68
|
+
((_c = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _c !== void 0 ? _c : []).length - 1,
|
|
69
|
+
((_d = lastNodeOfPreviousNode === null || lastNodeOfPreviousNode === void 0 ? void 0 : lastNodeOfPreviousNode.children) !== null && _d !== void 0 ? _d : []).length,
|
|
70
|
+
],
|
|
66
71
|
});
|
|
67
72
|
/**
|
|
68
73
|
* Wrap list item by a new list and move the new list next to the last node of previous node.
|
|
@@ -73,13 +78,14 @@ function createList(options = {}) {
|
|
|
73
78
|
Transforms.wrapNodes(editor, newSubListElement, { at: listItemPath });
|
|
74
79
|
Transforms.moveNodes(editor, {
|
|
75
80
|
at: listItemPath,
|
|
76
|
-
to: [...previousPath, previousNode.children.length],
|
|
81
|
+
to: [...previousPath, ((_e = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _e !== void 0 ? _e : []).length],
|
|
77
82
|
});
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
const decreaseListItemDepth = (editor, entries) => {
|
|
88
|
+
var _a, _b, _c;
|
|
83
89
|
const { list: [listNode, listPath], listItem: [listItemNode, listItemPath], } = entries;
|
|
84
90
|
const [listParentNode, listParentPath] = Editor.parent(editor, listPath);
|
|
85
91
|
/**
|
|
@@ -90,7 +96,7 @@ function createList(options = {}) {
|
|
|
90
96
|
}
|
|
91
97
|
const newListItemPath = Path.next(listParentPath);
|
|
92
98
|
const listItemIndex = listItemPath[listItemPath.length - 1];
|
|
93
|
-
const nextSiblingListItems = listNode.children.slice(listItemIndex + 1, listNode.children.length);
|
|
99
|
+
const nextSiblingListItems = ((_a = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _a !== void 0 ? _a : []).slice(listItemIndex + 1, ((_b = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _b !== void 0 ? _b : []).length);
|
|
94
100
|
Transforms.moveNodes(editor, {
|
|
95
101
|
at: listItemPath,
|
|
96
102
|
to: newListItemPath,
|
|
@@ -100,7 +106,7 @@ function createList(options = {}) {
|
|
|
100
106
|
*/
|
|
101
107
|
if (nextSiblingListItems.length) {
|
|
102
108
|
const newSubListElement = { type: listNode.type, children: [] };
|
|
103
|
-
const newSubListPath = [...newListItemPath, listItemNode.children.length];
|
|
109
|
+
const newSubListPath = [...newListItemPath, ((_c = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.children) !== null && _c !== void 0 ? _c : []).length];
|
|
104
110
|
Transforms.insertNodes(editor, newSubListElement, { at: newSubListPath });
|
|
105
111
|
nextSiblingListItems.forEach((_, index) => {
|
|
106
112
|
Transforms.moveNodes(editor, {
|
package/list/index.cjs.js
CHANGED
|
@@ -59,19 +59,24 @@ function createList(options = {}) {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
const increaseListItemDepth = (editor, entries) => {
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
62
63
|
const { list: [listNode], listItem: [, listItemPath], } = entries;
|
|
63
64
|
if (!core.isFirstChild(listItemPath)) {
|
|
64
65
|
const previousEntry = core.Editor.node(editor, core.Path.previous(listItemPath));
|
|
65
66
|
if (previousEntry) {
|
|
66
67
|
const [previousNode, previousPath] = previousEntry;
|
|
67
|
-
const lastNodeOfPreviousNode = previousNode.children[previousNode.children.length - 1];
|
|
68
|
+
const lastNodeOfPreviousNode = ((_a = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _a !== void 0 ? _a : [])[((_b = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _b !== void 0 ? _b : []).length - 1];
|
|
68
69
|
/**
|
|
69
70
|
* Move list item next to the last node of previous node of list item.
|
|
70
71
|
*/
|
|
71
72
|
if (isListElement(lastNodeOfPreviousNode)) {
|
|
72
73
|
core.Transforms.moveNodes(editor, {
|
|
73
74
|
at: listItemPath,
|
|
74
|
-
to: [
|
|
75
|
+
to: [
|
|
76
|
+
...previousPath,
|
|
77
|
+
((_c = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _c !== void 0 ? _c : []).length - 1,
|
|
78
|
+
((_d = lastNodeOfPreviousNode === null || lastNodeOfPreviousNode === void 0 ? void 0 : lastNodeOfPreviousNode.children) !== null && _d !== void 0 ? _d : []).length,
|
|
79
|
+
],
|
|
75
80
|
});
|
|
76
81
|
/**
|
|
77
82
|
* Wrap list item by a new list and move the new list next to the last node of previous node.
|
|
@@ -82,13 +87,14 @@ function createList(options = {}) {
|
|
|
82
87
|
core.Transforms.wrapNodes(editor, newSubListElement, { at: listItemPath });
|
|
83
88
|
core.Transforms.moveNodes(editor, {
|
|
84
89
|
at: listItemPath,
|
|
85
|
-
to: [...previousPath, previousNode.children.length],
|
|
90
|
+
to: [...previousPath, ((_e = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _e !== void 0 ? _e : []).length],
|
|
86
91
|
});
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
};
|
|
91
96
|
const decreaseListItemDepth = (editor, entries) => {
|
|
97
|
+
var _a, _b, _c;
|
|
92
98
|
const { list: [listNode, listPath], listItem: [listItemNode, listItemPath], } = entries;
|
|
93
99
|
const [listParentNode, listParentPath] = core.Editor.parent(editor, listPath);
|
|
94
100
|
/**
|
|
@@ -99,7 +105,7 @@ function createList(options = {}) {
|
|
|
99
105
|
}
|
|
100
106
|
const newListItemPath = core.Path.next(listParentPath);
|
|
101
107
|
const listItemIndex = listItemPath[listItemPath.length - 1];
|
|
102
|
-
const nextSiblingListItems = listNode.children.slice(listItemIndex + 1, listNode.children.length);
|
|
108
|
+
const nextSiblingListItems = ((_a = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _a !== void 0 ? _a : []).slice(listItemIndex + 1, ((_b = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _b !== void 0 ? _b : []).length);
|
|
103
109
|
core.Transforms.moveNodes(editor, {
|
|
104
110
|
at: listItemPath,
|
|
105
111
|
to: newListItemPath,
|
|
@@ -109,7 +115,7 @@ function createList(options = {}) {
|
|
|
109
115
|
*/
|
|
110
116
|
if (nextSiblingListItems.length) {
|
|
111
117
|
const newSubListElement = { type: listNode.type, children: [] };
|
|
112
|
-
const newSubListPath = [...newListItemPath, listItemNode.children.length];
|
|
118
|
+
const newSubListPath = [...newListItemPath, ((_c = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.children) !== null && _c !== void 0 ? _c : []).length];
|
|
113
119
|
core.Transforms.insertNodes(editor, newSubListElement, { at: newSubListPath });
|
|
114
120
|
nextSiblingListItems.forEach((_, index) => {
|
|
115
121
|
core.Transforms.moveNodes(editor, {
|
package/list/typings.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { Editor,
|
|
1
|
+
import { Editor, QuadratsElement, Location, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
|
|
2
2
|
export declare type ListRootTypeKey = 'ol' | 'ul';
|
|
3
3
|
export declare type ListItemTypeKey = 'li';
|
|
4
4
|
export declare type ListTypeKey = ListRootTypeKey | ListItemTypeKey;
|
|
5
5
|
export declare type ListTypes = Record<ListTypeKey, string>;
|
|
6
|
-
export interface ListElement extends
|
|
6
|
+
export interface ListElement extends QuadratsElement, WithElementType {
|
|
7
7
|
}
|
|
8
8
|
export interface ListAboveListAndItem {
|
|
9
|
-
list: NodeEntry<
|
|
10
|
-
listItem: NodeEntry<
|
|
9
|
+
list: NodeEntry<QuadratsElement>;
|
|
10
|
+
listItem: NodeEntry<QuadratsElement>;
|
|
11
11
|
}
|
|
12
12
|
export interface ListGetAboveListEntriesOptions {
|
|
13
13
|
at?: Location;
|
|
14
14
|
}
|
|
15
|
-
export interface List extends Withable {
|
|
15
|
+
export interface List<T extends Editor = Editor> extends Withable {
|
|
16
16
|
/**
|
|
17
17
|
* An object which keys are `ul`, `ol`, `li` and values are the corresponding element types.
|
|
18
18
|
*/
|
|
19
19
|
types: ListTypes;
|
|
20
|
-
isListElement(node: Node): node is
|
|
21
|
-
isListItemElement(node: Node): node is
|
|
22
|
-
isSelectionInList(editor:
|
|
20
|
+
isListElement(node: Node): node is QuadratsElement;
|
|
21
|
+
isListItemElement(node: Node): node is QuadratsElement;
|
|
22
|
+
isSelectionInList(editor: T, listTypeKey: ListRootTypeKey): boolean;
|
|
23
23
|
/**
|
|
24
24
|
* If expanded, get the list wrapping the location.
|
|
25
25
|
*/
|
|
26
|
-
getAboveListAndItem(editor:
|
|
27
|
-
unwrapList(editor:
|
|
28
|
-
toggleList(editor:
|
|
26
|
+
getAboveListAndItem(editor: T, options?: ListGetAboveListEntriesOptions): ListAboveListAndItem | undefined;
|
|
27
|
+
unwrapList(editor: T): void;
|
|
28
|
+
toggleList(editor: T, listTypeKey: ListRootTypeKey, defaultType?: string): void;
|
|
29
29
|
/**
|
|
30
30
|
* Increase the depth of the first item in the location if increasable.
|
|
31
31
|
*/
|
|
32
|
-
increaseListItemDepth(editor:
|
|
32
|
+
increaseListItemDepth(editor: T, entries: ListAboveListAndItem): void;
|
|
33
33
|
/**
|
|
34
34
|
* Decrease the depth of the first item in the location if decreasable.
|
|
35
35
|
*/
|
|
36
|
-
decreaseListItemDepth(editor:
|
|
36
|
+
decreaseListItemDepth(editor: T, entries: ListAboveListAndItem): void;
|
|
37
37
|
/**
|
|
38
38
|
* Unwrap the list if at root, or decrease the depth of list item.
|
|
39
39
|
*/
|
|
40
|
-
decreaseListItemDepthOrUnwrapIfNeed(editor:
|
|
40
|
+
decreaseListItemDepthOrUnwrapIfNeed(editor: T, entries: ListAboveListAndItem): void;
|
|
41
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.3",
|
|
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.5.2",
|
|
22
|
+
"@quadrats/locales": "^0.5.0",
|
|
23
|
+
"@quadrats/utils": "^0.5.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -29,7 +29,7 @@ function createReadMore(options = {}) {
|
|
|
29
29
|
insertReadMore,
|
|
30
30
|
with(editor) {
|
|
31
31
|
const { isVoid, normalizeNode } = editor;
|
|
32
|
-
editor.isVoid =
|
|
32
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
33
33
|
editor.normalizeNode = (entry) => {
|
|
34
34
|
const [node, path] = entry;
|
|
35
35
|
if (Element.isElement(node) && node.type === type) {
|
package/read-more/index.cjs.js
CHANGED
|
@@ -34,7 +34,7 @@ function createReadMore(options = {}) {
|
|
|
34
34
|
insertReadMore,
|
|
35
35
|
with(editor) {
|
|
36
36
|
const { isVoid, normalizeNode } = editor;
|
|
37
|
-
editor.isVoid =
|
|
37
|
+
editor.isVoid = element => element.type === type || isVoid(element);
|
|
38
38
|
editor.normalizeNode = (entry) => {
|
|
39
39
|
const [node, path] = entry;
|
|
40
40
|
if (core.Element.isElement(node) && node.type === type) {
|
package/read-more/typings.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Editor,
|
|
2
|
-
export interface ReadMoreElement extends
|
|
1
|
+
import { Editor, QuadratsElement, Text, Withable, WithElementType } from '@quadrats/core';
|
|
2
|
+
export interface ReadMoreElement extends QuadratsElement, WithElementType {
|
|
3
3
|
children: [Text];
|
|
4
4
|
}
|
|
5
|
-
export interface ReadMore extends WithElementType, Withable {
|
|
5
|
+
export interface ReadMore<T extends Editor = Editor> extends WithElementType, Withable {
|
|
6
6
|
createReadMoreElement(): ReadMoreElement;
|
|
7
|
-
insertReadMore(editor:
|
|
7
|
+
insertReadMore(editor: T): void;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const createStrikethrough: (variant?: string | undefined) => ({ type,
|
|
1
|
+
export declare const createStrikethrough: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<import("slate").BaseEditor>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
|
|
2
|
-
import { getVariantType } from '@quadrats/core';
|
|
3
2
|
import { STRIKETHROUGH_TYPE } from './constants.js';
|
|
4
3
|
|
|
5
4
|
const createStrikethrough = (variant) => createToggleMarkCreator({
|
|
6
|
-
type:
|
|
7
|
-
|
|
5
|
+
type: STRIKETHROUGH_TYPE,
|
|
6
|
+
variant,
|
|
8
7
|
});
|
|
9
8
|
|
|
10
9
|
export { createStrikethrough };
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var toggleMark = require('@quadrats/common/toggle-mark');
|
|
6
|
-
var core = require('@quadrats/core');
|
|
7
6
|
|
|
8
7
|
const STRIKETHROUGH_TYPE = 'strikethrough';
|
|
9
8
|
|
|
10
9
|
const createStrikethrough = (variant) => toggleMark.createToggleMarkCreator({
|
|
11
|
-
type:
|
|
12
|
-
|
|
10
|
+
type: STRIKETHROUGH_TYPE,
|
|
11
|
+
variant,
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
exports.STRIKETHROUGH_TYPE = STRIKETHROUGH_TYPE;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WithMarkType } from '@quadrats/core';
|
|
2
2
|
import { ToggleMark } from './typings';
|
|
3
3
|
export declare type CreateToggleMarkCreatorOptions = WithMarkType & {
|
|
4
|
-
|
|
4
|
+
variant?: string;
|
|
5
5
|
};
|
|
6
6
|
export declare type CreateToggleMarkOptions = Partial<CreateToggleMarkCreatorOptions> & {
|
|
7
|
-
|
|
7
|
+
variant?: string;
|
|
8
8
|
};
|
|
9
|
-
export declare function createToggleMarkCreator(defaults: CreateToggleMarkCreatorOptions): ({ type,
|
|
9
|
+
export declare function createToggleMarkCreator(defaults: CreateToggleMarkCreatorOptions): ({ type, variant }?: CreateToggleMarkOptions) => ToggleMark;
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import { getMark
|
|
1
|
+
import { getMark } from '@quadrats/core';
|
|
2
2
|
|
|
3
3
|
function createToggleMarkCreator(defaults) {
|
|
4
|
-
return ({ type = defaults.type,
|
|
4
|
+
return ({ type = defaults.type, variant = defaults.variant } = {}) => {
|
|
5
5
|
const isToggleMarkActive = (editor) => {
|
|
6
6
|
const mark = getMark(editor, type);
|
|
7
|
-
|
|
7
|
+
if (mark !== true)
|
|
8
|
+
return false;
|
|
9
|
+
const nowVariant = getMark(editor, `${type}Variant`) || '';
|
|
10
|
+
if (variant) {
|
|
11
|
+
return nowVariant === variant;
|
|
12
|
+
}
|
|
13
|
+
return !nowVariant;
|
|
8
14
|
};
|
|
9
15
|
const toggleMark = (editor) => {
|
|
10
16
|
const isActive = isToggleMarkActive(editor);
|
|
11
17
|
if (isActive) {
|
|
12
18
|
editor.removeMark(type);
|
|
19
|
+
if (variant) {
|
|
20
|
+
editor.removeMark(`${type}Variant`);
|
|
21
|
+
}
|
|
13
22
|
}
|
|
14
23
|
else {
|
|
15
|
-
if (parentType) {
|
|
16
|
-
marksGroupBy(editor, (_mark) => {
|
|
17
|
-
if (_mark.match(parentType)) {
|
|
18
|
-
editor.removeMark(_mark);
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
24
|
editor.addMark(type, true);
|
|
25
|
+
if (variant) {
|
|
26
|
+
editor.addMark(`${type}Variant`, variant);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
editor.removeMark(`${type}Variant`);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
};
|
|
27
33
|
return {
|