@quadrats/common 0.7.7 → 1.0.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/accordion/constants.d.ts +5 -0
- package/accordion/constants.js +10 -0
- package/accordion/createAccordion.d.ts +6 -0
- package/accordion/createAccordion.js +62 -0
- package/accordion/index.cjs.js +76 -0
- package/accordion/index.d.ts +3 -0
- package/accordion/index.js +2 -0
- package/accordion/package.json +7 -0
- package/accordion/typings.d.ts +18 -0
- package/align/constants.d.ts +1 -0
- package/align/constants.js +3 -0
- package/align/createAlign.d.ts +9 -0
- package/align/createAlign.js +41 -0
- package/align/index.cjs.js +45 -0
- package/align/index.d.ts +3 -0
- package/align/index.js +2 -0
- package/align/package.json +7 -0
- package/align/typings.d.ts +1 -0
- package/card/constants.d.ts +6 -0
- package/card/constants.js +11 -0
- package/card/createCard.d.ts +15 -0
- package/card/createCard.js +147 -0
- package/card/getFilesFromInput.d.ts +4 -0
- package/card/index.cjs.js +163 -0
- package/card/index.d.ts +3 -0
- package/card/index.js +2 -0
- package/card/package.json +7 -0
- package/card/typings.d.ts +73 -0
- package/carousel/_virtual/_tslib.js +33 -0
- package/carousel/constants.d.ts +6 -0
- package/carousel/constants.js +11 -0
- package/carousel/createCarousel.d.ts +16 -0
- package/carousel/createCarousel.js +127 -0
- package/carousel/getFilesFromInput.d.ts +4 -0
- package/carousel/getFilesFromInput.js +30 -0
- package/carousel/index.cjs.js +202 -0
- package/carousel/index.d.ts +3 -0
- package/carousel/index.js +2 -0
- package/carousel/package.json +7 -0
- package/carousel/typings.d.ts +58 -0
- package/embed/constants.d.ts +1 -0
- package/embed/constants.js +2 -1
- package/embed/createEmbed.js +21 -4
- package/embed/index.cjs.js +26 -9
- package/embed/index.js +1 -1
- package/embed/serializeEmbedCode.d.ts +1 -1
- package/embed/serializeEmbedCode.js +5 -7
- package/embed/strategies/podcast-apple/index.cjs.js +1 -1
- package/embed/strategies/podcast-apple/index.js +1 -1
- package/embed/typings.d.ts +16 -1
- package/file-uploader/constants.d.ts +1 -0
- package/file-uploader/constants.js +2 -1
- package/file-uploader/createFileUploader.js +20 -2
- package/file-uploader/getFilesFromInput.js +3 -0
- package/file-uploader/index.cjs.js +23 -0
- package/file-uploader/index.js +1 -1
- package/file-uploader/typings.d.ts +8 -2
- package/heading/typings.d.ts +1 -0
- package/image/createImage.js +12 -11
- package/image/getImageFigureElementCommonProps.d.ts +2 -0
- package/image/getImageFigureElementCommonProps.js +28 -2
- package/image/index.cjs.js +40 -13
- package/image/typings.d.ts +2 -0
- package/list/createList.d.ts +1 -0
- package/list/createList.js +3 -0
- package/list/index.cjs.js +3 -0
- package/list/typings.d.ts +1 -0
- package/package.json +4 -4
- package/paragraph/createParagraph.d.ts +2 -0
- package/paragraph/createParagraph.js +24 -0
- package/paragraph/index.cjs.js +26 -0
- package/paragraph/index.d.ts +2 -0
- package/paragraph/index.js +1 -0
- package/paragraph/package.json +7 -0
- package/paragraph/typings.d.ts +9 -0
package/heading/typings.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Editor, QuadratsElement, GetNodesOptions, Node, NodeEntry, Withable, Wi
|
|
|
2
2
|
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
3
|
export interface HeadingElement extends QuadratsElement, WithElementType {
|
|
4
4
|
level: HeadingLevel;
|
|
5
|
+
align?: 'left' | 'center' | 'right';
|
|
5
6
|
}
|
|
6
7
|
export interface WithEnabledHeadingLevels<L extends HeadingLevel> {
|
|
7
8
|
/**
|
package/image/createImage.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Range, isNodesTypeIn, getAboveByTypes, Editor, Transforms, createParagr
|
|
|
3
3
|
import { IMAGE_TYPES } from './constants.js';
|
|
4
4
|
|
|
5
5
|
function resolveSizeSteps(steps) {
|
|
6
|
-
let sortedSteps = steps.filter(step => step > 0 && step < 100).sort();
|
|
6
|
+
let sortedSteps = steps.filter((step) => step > 0 && step < 100).sort();
|
|
7
7
|
if (!sortedSteps.includes(100)) {
|
|
8
8
|
sortedSteps = [...sortedSteps, 100];
|
|
9
9
|
}
|
|
@@ -16,12 +16,13 @@ function createImage(options = {}) {
|
|
|
16
16
|
const getAboveImageFigure = (editor, options) => getAboveByTypes(editor, [types.figure], options);
|
|
17
17
|
const getAboveImageCaption = (editor, options) => getAboveByTypes(editor, [types.caption], options);
|
|
18
18
|
const isNodesInImage = (editor, options) => isNodesTypeIn(editor, [types.image], options);
|
|
19
|
-
const isSelectionInImage = editor => isNodesInImage(editor);
|
|
20
|
-
const isSelectionInImageCaption = editor => isNodesTypeIn(editor, [types.caption]);
|
|
21
|
-
const isCollapsedOnImage = editor => !!editor.selection && Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
|
|
19
|
+
const isSelectionInImage = (editor) => isNodesInImage(editor);
|
|
20
|
+
const isSelectionInImageCaption = (editor) => isNodesTypeIn(editor, [types.caption]);
|
|
21
|
+
const isCollapsedOnImage = (editor) => !!editor.selection && Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
|
|
22
22
|
const createImageElement = (src, hosting) => {
|
|
23
23
|
const imageElement = {
|
|
24
24
|
type: types.image,
|
|
25
|
+
figureType: types.figure,
|
|
25
26
|
src,
|
|
26
27
|
hosting,
|
|
27
28
|
children: [{ text: '' }],
|
|
@@ -51,7 +52,7 @@ function createImage(options = {}) {
|
|
|
51
52
|
if (!sizeSteps) {
|
|
52
53
|
return percentage;
|
|
53
54
|
}
|
|
54
|
-
const lowerIndex = sizeSteps.findIndex(step => step >= percentage) - 1;
|
|
55
|
+
const lowerIndex = sizeSteps.findIndex((step) => step >= percentage) - 1;
|
|
55
56
|
const upperIndex = lowerIndex + 1;
|
|
56
57
|
if (lowerIndex < 0) {
|
|
57
58
|
return sizeSteps[0];
|
|
@@ -89,7 +90,7 @@ function createImage(options = {}) {
|
|
|
89
90
|
insertImage,
|
|
90
91
|
resizeImage,
|
|
91
92
|
with(editor) {
|
|
92
|
-
const { deleteBackward, deleteForward, insertBreak, isVoid, normalizeNode
|
|
93
|
+
const { deleteBackward, deleteForward, insertBreak, isVoid, normalizeNode } = editor;
|
|
93
94
|
const deleteCollapsed = (origin, isEdgeMethodName) => {
|
|
94
95
|
const { selection } = editor;
|
|
95
96
|
/**
|
|
@@ -97,7 +98,7 @@ function createImage(options = {}) {
|
|
|
97
98
|
*/
|
|
98
99
|
if (selection && Range.isCollapsed(selection)) {
|
|
99
100
|
const [, captionPath] = getAboveImageCaption(editor) || [];
|
|
100
|
-
if (
|
|
101
|
+
if (captionPath && Editor[isEdgeMethodName](editor, selection.focus, captionPath)) {
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
104
|
}
|
|
@@ -128,7 +129,7 @@ function createImage(options = {}) {
|
|
|
128
129
|
}
|
|
129
130
|
insertBreak();
|
|
130
131
|
};
|
|
131
|
-
editor.isVoid = element => element.type === types.image || isVoid(element);
|
|
132
|
+
editor.isVoid = (element) => element.type === types.image || isVoid(element);
|
|
132
133
|
editor.normalizeNode = (entry) => {
|
|
133
134
|
const [node, path] = entry;
|
|
134
135
|
if (Element.isElement(node)) {
|
|
@@ -140,9 +141,9 @@ function createImage(options = {}) {
|
|
|
140
141
|
}
|
|
141
142
|
else if (node.type === types.image) {
|
|
142
143
|
const { src, width, hosting } = node;
|
|
143
|
-
if (typeof src !== 'string'
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
if (typeof src !== 'string' ||
|
|
145
|
+
!(width == null || typeof width === 'number') ||
|
|
146
|
+
!(hosting == null || typeof hosting === 'string')) {
|
|
146
147
|
const [, figurePath] = getAboveImageFigure(editor, { at: path }) || [];
|
|
147
148
|
if (figurePath) {
|
|
148
149
|
Transforms.removeNodes(editor, { at: figurePath });
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ImageFigureElement } from './typings';
|
|
2
2
|
export declare function getImageFigureElementCommonProps(element: ImageFigureElement): {
|
|
3
3
|
style?: {
|
|
4
|
+
'--qdr-image-align': 'flex-start' | 'center' | 'flex-end';
|
|
5
|
+
'--qdr-image-caption-align': 'left' | 'center' | 'right';
|
|
4
6
|
width: string;
|
|
5
7
|
};
|
|
6
8
|
};
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
function getImageFigureElementCommonProps(element) {
|
|
2
|
-
const { width } = element;
|
|
2
|
+
const { width, align } = element;
|
|
3
3
|
return {
|
|
4
|
-
style:
|
|
4
|
+
style: {
|
|
5
|
+
width: typeof width === 'number' ? `${width}%` : 'unset',
|
|
6
|
+
'--qdr-image-align': (() => {
|
|
7
|
+
switch (align) {
|
|
8
|
+
case 'start':
|
|
9
|
+
return 'flex-start';
|
|
10
|
+
case 'center':
|
|
11
|
+
return 'center';
|
|
12
|
+
case 'end':
|
|
13
|
+
return 'flex-end';
|
|
14
|
+
default:
|
|
15
|
+
return 'flex-start';
|
|
16
|
+
}
|
|
17
|
+
})(),
|
|
18
|
+
'--qdr-image-caption-align': (() => {
|
|
19
|
+
switch (align) {
|
|
20
|
+
case 'start':
|
|
21
|
+
return 'left';
|
|
22
|
+
case 'center':
|
|
23
|
+
return 'center';
|
|
24
|
+
case 'end':
|
|
25
|
+
return 'right';
|
|
26
|
+
default:
|
|
27
|
+
return 'left';
|
|
28
|
+
}
|
|
29
|
+
})(),
|
|
30
|
+
},
|
|
5
31
|
};
|
|
6
32
|
}
|
|
7
33
|
|
package/image/index.cjs.js
CHANGED
|
@@ -14,9 +14,35 @@ function isHostingNotRequired(src) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function getImageFigureElementCommonProps(element) {
|
|
17
|
-
const { width } = element;
|
|
17
|
+
const { width, align } = element;
|
|
18
18
|
return {
|
|
19
|
-
style:
|
|
19
|
+
style: {
|
|
20
|
+
width: typeof width === 'number' ? `${width}%` : 'unset',
|
|
21
|
+
'--qdr-image-align': (() => {
|
|
22
|
+
switch (align) {
|
|
23
|
+
case 'start':
|
|
24
|
+
return 'flex-start';
|
|
25
|
+
case 'center':
|
|
26
|
+
return 'center';
|
|
27
|
+
case 'end':
|
|
28
|
+
return 'flex-end';
|
|
29
|
+
default:
|
|
30
|
+
return 'flex-start';
|
|
31
|
+
}
|
|
32
|
+
})(),
|
|
33
|
+
'--qdr-image-caption-align': (() => {
|
|
34
|
+
switch (align) {
|
|
35
|
+
case 'start':
|
|
36
|
+
return 'left';
|
|
37
|
+
case 'center':
|
|
38
|
+
return 'center';
|
|
39
|
+
case 'end':
|
|
40
|
+
return 'right';
|
|
41
|
+
default:
|
|
42
|
+
return 'left';
|
|
43
|
+
}
|
|
44
|
+
})(),
|
|
45
|
+
},
|
|
20
46
|
};
|
|
21
47
|
}
|
|
22
48
|
|
|
@@ -29,7 +55,7 @@ function getImageElementCommonProps(element, hostingResolvers) {
|
|
|
29
55
|
}
|
|
30
56
|
|
|
31
57
|
function resolveSizeSteps(steps) {
|
|
32
|
-
let sortedSteps = steps.filter(step => step > 0 && step < 100).sort();
|
|
58
|
+
let sortedSteps = steps.filter((step) => step > 0 && step < 100).sort();
|
|
33
59
|
if (!sortedSteps.includes(100)) {
|
|
34
60
|
sortedSteps = [...sortedSteps, 100];
|
|
35
61
|
}
|
|
@@ -42,12 +68,13 @@ function createImage(options = {}) {
|
|
|
42
68
|
const getAboveImageFigure = (editor, options) => core.getAboveByTypes(editor, [types.figure], options);
|
|
43
69
|
const getAboveImageCaption = (editor, options) => core.getAboveByTypes(editor, [types.caption], options);
|
|
44
70
|
const isNodesInImage = (editor, options) => core.isNodesTypeIn(editor, [types.image], options);
|
|
45
|
-
const isSelectionInImage = editor => isNodesInImage(editor);
|
|
46
|
-
const isSelectionInImageCaption = editor => core.isNodesTypeIn(editor, [types.caption]);
|
|
47
|
-
const isCollapsedOnImage = editor => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
|
|
71
|
+
const isSelectionInImage = (editor) => isNodesInImage(editor);
|
|
72
|
+
const isSelectionInImageCaption = (editor) => core.isNodesTypeIn(editor, [types.caption]);
|
|
73
|
+
const isCollapsedOnImage = (editor) => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
|
|
48
74
|
const createImageElement = (src, hosting) => {
|
|
49
75
|
const imageElement = {
|
|
50
76
|
type: types.image,
|
|
77
|
+
figureType: types.figure,
|
|
51
78
|
src,
|
|
52
79
|
hosting,
|
|
53
80
|
children: [{ text: '' }],
|
|
@@ -77,7 +104,7 @@ function createImage(options = {}) {
|
|
|
77
104
|
if (!sizeSteps) {
|
|
78
105
|
return percentage;
|
|
79
106
|
}
|
|
80
|
-
const lowerIndex = sizeSteps.findIndex(step => step >= percentage) - 1;
|
|
107
|
+
const lowerIndex = sizeSteps.findIndex((step) => step >= percentage) - 1;
|
|
81
108
|
const upperIndex = lowerIndex + 1;
|
|
82
109
|
if (lowerIndex < 0) {
|
|
83
110
|
return sizeSteps[0];
|
|
@@ -115,7 +142,7 @@ function createImage(options = {}) {
|
|
|
115
142
|
insertImage,
|
|
116
143
|
resizeImage,
|
|
117
144
|
with(editor) {
|
|
118
|
-
const { deleteBackward, deleteForward, insertBreak, isVoid, normalizeNode
|
|
145
|
+
const { deleteBackward, deleteForward, insertBreak, isVoid, normalizeNode } = editor;
|
|
119
146
|
const deleteCollapsed = (origin, isEdgeMethodName) => {
|
|
120
147
|
const { selection } = editor;
|
|
121
148
|
/**
|
|
@@ -123,7 +150,7 @@ function createImage(options = {}) {
|
|
|
123
150
|
*/
|
|
124
151
|
if (selection && core.Range.isCollapsed(selection)) {
|
|
125
152
|
const [, captionPath] = getAboveImageCaption(editor) || [];
|
|
126
|
-
if (
|
|
153
|
+
if (captionPath && core.Editor[isEdgeMethodName](editor, selection.focus, captionPath)) {
|
|
127
154
|
return;
|
|
128
155
|
}
|
|
129
156
|
}
|
|
@@ -154,7 +181,7 @@ function createImage(options = {}) {
|
|
|
154
181
|
}
|
|
155
182
|
insertBreak();
|
|
156
183
|
};
|
|
157
|
-
editor.isVoid = element => element.type === types.image || isVoid(element);
|
|
184
|
+
editor.isVoid = (element) => element.type === types.image || isVoid(element);
|
|
158
185
|
editor.normalizeNode = (entry) => {
|
|
159
186
|
const [node, path] = entry;
|
|
160
187
|
if (core.Element.isElement(node)) {
|
|
@@ -166,9 +193,9 @@ function createImage(options = {}) {
|
|
|
166
193
|
}
|
|
167
194
|
else if (node.type === types.image) {
|
|
168
195
|
const { src, width, hosting } = node;
|
|
169
|
-
if (typeof src !== 'string'
|
|
170
|
-
|
|
171
|
-
|
|
196
|
+
if (typeof src !== 'string' ||
|
|
197
|
+
!(width == null || typeof width === 'number') ||
|
|
198
|
+
!(hosting == null || typeof hosting === 'string')) {
|
|
172
199
|
const [, figurePath] = getAboveImageFigure(editor, { at: path }) || [];
|
|
173
200
|
if (figurePath) {
|
|
174
201
|
core.Transforms.removeNodes(editor, { at: figurePath });
|
package/image/typings.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ export type ImageTypeKey = 'image';
|
|
|
4
4
|
export type ImageCaptionTypeKey = 'caption';
|
|
5
5
|
export type ImageTypes = Record<ImageFigureTypeKey | ImageTypeKey | ImageCaptionTypeKey, string>;
|
|
6
6
|
export interface ImageFigureElement extends QuadratsElement, WithElementType {
|
|
7
|
+
align?: 'start' | 'center' | 'end';
|
|
7
8
|
width?: number;
|
|
8
9
|
}
|
|
9
10
|
export interface ImageElement extends QuadratsElement, WithElementType {
|
|
10
11
|
children: [Text];
|
|
11
12
|
src: string;
|
|
13
|
+
figureType: string;
|
|
12
14
|
/**
|
|
13
15
|
* e.g. The src of image is `8gy9pbaht92y4.jpg` and your static files are hosted by `https://foo.storage`.
|
|
14
16
|
* Then you can make the hosting of element be `foo`.
|
package/list/createList.d.ts
CHANGED
package/list/createList.js
CHANGED
|
@@ -2,6 +2,8 @@ import { PARAGRAPH_TYPE, isNodesTypeIn, Range, isSelectionAtBlockEdge, deleteSel
|
|
|
2
2
|
import { LIST_TYPES } from './constants.js';
|
|
3
3
|
|
|
4
4
|
function createList(options = {}) {
|
|
5
|
+
var _a;
|
|
6
|
+
const labels = (_a = options.labels) !== null && _a !== void 0 ? _a : 4;
|
|
5
7
|
const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
|
|
6
8
|
const isListElement = (node) => [types.ol, types.ul].includes(node.type);
|
|
7
9
|
const isListItemElement = (node) => node.type === types.li;
|
|
@@ -140,6 +142,7 @@ function createList(options = {}) {
|
|
|
140
142
|
};
|
|
141
143
|
return {
|
|
142
144
|
types,
|
|
145
|
+
labels,
|
|
143
146
|
isListElement,
|
|
144
147
|
isListItemElement,
|
|
145
148
|
isSelectionInList,
|
package/list/index.cjs.js
CHANGED
|
@@ -9,6 +9,8 @@ const LIST_TYPES = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
function createList(options = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
const labels = (_a = options.labels) !== null && _a !== void 0 ? _a : 4;
|
|
12
14
|
const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
|
|
13
15
|
const isListElement = (node) => [types.ol, types.ul].includes(node.type);
|
|
14
16
|
const isListItemElement = (node) => node.type === types.li;
|
|
@@ -147,6 +149,7 @@ function createList(options = {}) {
|
|
|
147
149
|
};
|
|
148
150
|
return {
|
|
149
151
|
types,
|
|
152
|
+
labels,
|
|
150
153
|
isListElement,
|
|
151
154
|
isListItemElement,
|
|
152
155
|
isSelectionInList,
|
package/list/typings.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface List<T extends Editor = Editor> extends Withable {
|
|
|
17
17
|
* An object which keys are `ul`, `ol`, `li` and values are the corresponding element types.
|
|
18
18
|
*/
|
|
19
19
|
types: ListTypes;
|
|
20
|
+
labels: number;
|
|
20
21
|
isListElement(node: Node): node is QuadratsElement;
|
|
21
22
|
isListItemElement(node: Node): node is QuadratsElement;
|
|
22
23
|
isSelectionInList(editor: T, listTypeKey: ListRootTypeKey): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrats/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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": "^1.0.0",
|
|
22
|
+
"@quadrats/locales": "^1.0.0",
|
|
23
|
+
"@quadrats/utils": "^1.0.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getNodes, PARAGRAPH_TYPE, Transforms } from '@quadrats/core';
|
|
2
|
+
|
|
3
|
+
function createParagraph() {
|
|
4
|
+
const getParagraphNodes = (editor, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === PARAGRAPH_TYPE }));
|
|
5
|
+
const isSelectionInParagraph = (editor, options = {}) => {
|
|
6
|
+
const [match] = getParagraphNodes(editor, options);
|
|
7
|
+
return !!match;
|
|
8
|
+
};
|
|
9
|
+
const setParagraphNodes = (editor) => {
|
|
10
|
+
const paragraph = { type: PARAGRAPH_TYPE, children: [] };
|
|
11
|
+
Transforms.setNodes(editor, paragraph);
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
type: PARAGRAPH_TYPE,
|
|
15
|
+
getParagraphNodes,
|
|
16
|
+
isSelectionInParagraph,
|
|
17
|
+
setParagraphNodes,
|
|
18
|
+
with(editor) {
|
|
19
|
+
return editor;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { createParagraph };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@quadrats/core');
|
|
4
|
+
|
|
5
|
+
function createParagraph() {
|
|
6
|
+
const getParagraphNodes = (editor, options = {}) => core.getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === core.PARAGRAPH_TYPE }));
|
|
7
|
+
const isSelectionInParagraph = (editor, options = {}) => {
|
|
8
|
+
const [match] = getParagraphNodes(editor, options);
|
|
9
|
+
return !!match;
|
|
10
|
+
};
|
|
11
|
+
const setParagraphNodes = (editor) => {
|
|
12
|
+
const paragraph = { type: core.PARAGRAPH_TYPE, children: [] };
|
|
13
|
+
core.Transforms.setNodes(editor, paragraph);
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
type: core.PARAGRAPH_TYPE,
|
|
17
|
+
getParagraphNodes,
|
|
18
|
+
isSelectionInParagraph,
|
|
19
|
+
setParagraphNodes,
|
|
20
|
+
with(editor) {
|
|
21
|
+
return editor;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.createParagraph = createParagraph;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createParagraph } from './createParagraph.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Editor, QuadratsElement, GetNodesOptions, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
|
|
2
|
+
export interface ParagraphElement extends QuadratsElement {
|
|
3
|
+
align?: 'left' | 'center' | 'right';
|
|
4
|
+
}
|
|
5
|
+
export interface Paragraph<T extends Editor = Editor> extends WithElementType, Withable {
|
|
6
|
+
getParagraphNodes(editor: T, options?: GetNodesOptions): Generator<NodeEntry<Node>>;
|
|
7
|
+
isSelectionInParagraph(editor: T, options?: GetNodesOptions): boolean;
|
|
8
|
+
setParagraphNodes(editor: T): void;
|
|
9
|
+
}
|