@quadrats/common 0.7.3 → 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.
Files changed (91) hide show
  1. package/accordion/constants.d.ts +5 -0
  2. package/accordion/constants.js +10 -0
  3. package/accordion/createAccordion.d.ts +6 -0
  4. package/accordion/createAccordion.js +62 -0
  5. package/accordion/index.cjs.js +76 -0
  6. package/accordion/index.d.ts +3 -0
  7. package/accordion/index.js +2 -0
  8. package/accordion/package.json +7 -0
  9. package/accordion/typings.d.ts +18 -0
  10. package/align/constants.d.ts +1 -0
  11. package/align/constants.js +3 -0
  12. package/align/createAlign.d.ts +9 -0
  13. package/align/createAlign.js +41 -0
  14. package/align/index.cjs.js +45 -0
  15. package/align/index.d.ts +3 -0
  16. package/align/index.js +2 -0
  17. package/align/package.json +7 -0
  18. package/align/typings.d.ts +1 -0
  19. package/blockquote/createBlockquote.js +1 -1
  20. package/bold/createBold.d.ts +1 -1
  21. package/card/constants.d.ts +6 -0
  22. package/card/constants.js +11 -0
  23. package/card/createCard.d.ts +15 -0
  24. package/card/createCard.js +147 -0
  25. package/card/getFilesFromInput.d.ts +4 -0
  26. package/card/index.cjs.js +163 -0
  27. package/card/index.d.ts +3 -0
  28. package/card/index.js +2 -0
  29. package/card/package.json +7 -0
  30. package/card/typings.d.ts +73 -0
  31. package/carousel/_virtual/_tslib.js +33 -0
  32. package/carousel/constants.d.ts +6 -0
  33. package/carousel/constants.js +11 -0
  34. package/carousel/createCarousel.d.ts +16 -0
  35. package/carousel/createCarousel.js +127 -0
  36. package/carousel/getFilesFromInput.d.ts +4 -0
  37. package/carousel/getFilesFromInput.js +30 -0
  38. package/carousel/index.cjs.js +202 -0
  39. package/carousel/index.d.ts +3 -0
  40. package/carousel/index.js +2 -0
  41. package/carousel/package.json +7 -0
  42. package/carousel/typings.d.ts +58 -0
  43. package/embed/constants.d.ts +1 -0
  44. package/embed/constants.js +2 -1
  45. package/embed/createEmbed.js +27 -4
  46. package/embed/index.cjs.js +32 -9
  47. package/embed/index.js +1 -1
  48. package/embed/serializeEmbedCode.d.ts +1 -1
  49. package/embed/serializeEmbedCode.js +5 -7
  50. package/embed/strategies/podcast-apple/index.cjs.js +1 -1
  51. package/embed/strategies/podcast-apple/index.js +1 -1
  52. package/embed/strategies/twitter/index.cjs.js +1 -1
  53. package/embed/strategies/twitter/index.js +1 -1
  54. package/embed/typings.d.ts +16 -1
  55. package/file-uploader/constants.d.ts +1 -0
  56. package/file-uploader/constants.js +2 -1
  57. package/file-uploader/createFileUploader.d.ts +3 -1
  58. package/file-uploader/createFileUploader.js +85 -63
  59. package/file-uploader/getFilesFromInput.js +3 -0
  60. package/file-uploader/index.cjs.js +89 -60
  61. package/file-uploader/index.d.ts +1 -1
  62. package/file-uploader/index.js +2 -2
  63. package/file-uploader/typings.d.ts +8 -2
  64. package/footnote/createFootnote.js +1 -1
  65. package/heading/constants.d.ts +1 -1
  66. package/heading/createHeading.js +2 -2
  67. package/heading/typings.d.ts +1 -0
  68. package/highlight/createHighlight.d.ts +1 -1
  69. package/image/createImage.js +13 -12
  70. package/image/getImageFigureElementCommonProps.d.ts +2 -0
  71. package/image/getImageFigureElementCommonProps.js +28 -2
  72. package/image/index.cjs.js +40 -13
  73. package/image/typings.d.ts +2 -0
  74. package/input-block/createInputBlock.js +1 -1
  75. package/italic/createItalic.d.ts +1 -1
  76. package/link/createLink.js +1 -1
  77. package/list/createList.d.ts +1 -0
  78. package/list/createList.js +4 -1
  79. package/list/index.cjs.js +3 -0
  80. package/list/typings.d.ts +1 -0
  81. package/package.json +4 -4
  82. package/paragraph/createParagraph.d.ts +2 -0
  83. package/paragraph/createParagraph.js +24 -0
  84. package/paragraph/index.cjs.js +26 -0
  85. package/paragraph/index.d.ts +2 -0
  86. package/paragraph/index.js +1 -0
  87. package/paragraph/package.json +7 -0
  88. package/paragraph/typings.d.ts +9 -0
  89. package/read-more/createReadMore.js +1 -1
  90. package/strikethrough/createStrikethrough.d.ts +1 -1
  91. package/underline/createUnderline.d.ts +1 -1
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ var core = require('@quadrats/core');
4
+
5
+ const CARD_TYPE = 'card';
6
+ const CARD_IMAGE_TYPE = 'card_image';
7
+ const CARD_CONTENTS_TYPE = 'card_contents';
8
+ const CARD_PLACEHOLDER_TYPE = 'card_placeholder';
9
+ const CARD_TYPES = {
10
+ card: CARD_TYPE,
11
+ card_image: CARD_IMAGE_TYPE,
12
+ card_contents: CARD_CONTENTS_TYPE,
13
+ };
14
+
15
+ function createCard(options) {
16
+ const { types: typesOptions, accept: acceptOptions, ratio, limitSize: limitSizeOptions, confirmModal = true, getBody, getHeaders, getUrl, uploader, } = options;
17
+ const types = Object.assign(Object.assign({}, CARD_TYPES), typesOptions);
18
+ const limitSize = limitSizeOptions || 5;
19
+ const accept = acceptOptions || ['image/jpeg', 'image/jpg', 'image/png'];
20
+ const insertCardPlaceholder = (editor) => {
21
+ const cardPlaceholderElement = {
22
+ type: CARD_PLACEHOLDER_TYPE,
23
+ ratio,
24
+ children: [{ text: '' }],
25
+ };
26
+ core.Editor.withoutNormalizing(editor, () => {
27
+ core.Transforms.insertNodes(editor, cardPlaceholderElement);
28
+ });
29
+ };
30
+ const removeCardPlaceholder = (editor) => {
31
+ core.Transforms.removeNodes(editor, {
32
+ match: (node) => core.Element.isElement(node) && node.type === CARD_PLACEHOLDER_TYPE,
33
+ });
34
+ };
35
+ const createCardElement = (cardValues) => {
36
+ var _a;
37
+ const cardImageElement = {
38
+ type: types.card_image,
39
+ src: ((_a = cardValues.imageItem) === null || _a === void 0 ? void 0 : _a.url) || '',
40
+ ratio,
41
+ children: [{ text: '' }],
42
+ };
43
+ const cardContentsElement = {
44
+ type: types.card_contents,
45
+ children: [{ text: '' }],
46
+ alignment: cardValues.alignment,
47
+ title: cardValues.title,
48
+ description: cardValues.description,
49
+ remark: cardValues.remark,
50
+ haveLink: cardValues.haveLink,
51
+ linkText: cardValues.linkText,
52
+ linkUrl: cardValues.linkUrl,
53
+ };
54
+ return Object.assign(Object.assign({ type: types.card, confirmModal }, cardValues), { children: [cardImageElement, cardContentsElement] });
55
+ };
56
+ const insertCard = ({ editor, cardValues }) => {
57
+ core.Transforms.insertNodes(editor, [createCardElement(cardValues), core.createParagraphElement()]);
58
+ };
59
+ const updateCardElement = ({ editor, cardValues, path }) => {
60
+ var _a;
61
+ core.Transforms.setNodes(editor, cardValues, { at: path });
62
+ const imageEntries = core.Editor.nodes(editor, {
63
+ at: path,
64
+ match: (node) => core.Element.isElement(node) && node.type === types.card_image,
65
+ mode: 'all',
66
+ });
67
+ const imageNode = imageEntries.next().value;
68
+ const contentsEntries = core.Editor.nodes(editor, {
69
+ at: path,
70
+ match: (node) => core.Element.isElement(node) && node.type === types.card_contents,
71
+ mode: 'all',
72
+ });
73
+ const contentsNode = contentsEntries.next().value;
74
+ if (imageNode) {
75
+ const [, imagePath] = imageNode;
76
+ core.Transforms.setNodes(editor, { src: ((_a = cardValues.imageItem) === null || _a === void 0 ? void 0 : _a.url) || '' }, { at: imagePath });
77
+ }
78
+ if (contentsNode) {
79
+ const [, contentsPath] = contentsNode;
80
+ core.Transforms.setNodes(editor, {
81
+ alignment: cardValues.alignment,
82
+ title: cardValues.title,
83
+ description: cardValues.description,
84
+ remark: cardValues.remark,
85
+ haveLink: cardValues.haveLink,
86
+ linkText: cardValues.linkText,
87
+ linkUrl: cardValues.linkUrl,
88
+ }, {
89
+ at: contentsPath,
90
+ });
91
+ }
92
+ };
93
+ const updateCardAlignment = ({ editor, alignment, path }) => {
94
+ core.Transforms.setNodes(editor, { alignment }, { at: path });
95
+ const contentsEntries = core.Editor.nodes(editor, {
96
+ at: path,
97
+ match: (node) => core.Element.isElement(node) && node.type === types.card_contents,
98
+ mode: 'all',
99
+ });
100
+ const contentsNode = contentsEntries.next().value;
101
+ if (contentsNode) {
102
+ const [, contentsPath] = contentsNode;
103
+ core.Transforms.setNodes(editor, {
104
+ alignment,
105
+ }, {
106
+ at: contentsPath,
107
+ });
108
+ }
109
+ };
110
+ return {
111
+ types,
112
+ createCardElement,
113
+ insertCard,
114
+ updateCardElement,
115
+ updateCardAlignment,
116
+ accept,
117
+ ratio,
118
+ limitSize,
119
+ confirmModal,
120
+ insertCardPlaceholder,
121
+ removeCardPlaceholder,
122
+ getBody,
123
+ getHeaders,
124
+ getUrl,
125
+ uploader,
126
+ with(editor) {
127
+ const { normalizeNode } = editor;
128
+ editor.normalizeNode = (entry) => {
129
+ const [node, path] = entry;
130
+ if (core.Element.isElement(node)) {
131
+ const type = node.type;
132
+ if (type === types.card) {
133
+ for (const [child, childPath] of core.Node.children(editor, path)) {
134
+ if (core.Element.isElement(child) &&
135
+ child.type !== types.card_contents &&
136
+ child.type !== types.card_image) {
137
+ core.Transforms.removeNodes(editor, { at: childPath });
138
+ return;
139
+ }
140
+ }
141
+ }
142
+ else if (type === types.card_contents || type === types.card_image) {
143
+ for (const [child, childPath] of core.Node.children(editor, path)) {
144
+ if (core.Element.isElement(child)) {
145
+ core.Transforms.removeNodes(editor, { at: childPath });
146
+ return;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ normalizeNode(entry);
152
+ };
153
+ return editor;
154
+ },
155
+ };
156
+ }
157
+
158
+ exports.CARD_CONTENTS_TYPE = CARD_CONTENTS_TYPE;
159
+ exports.CARD_IMAGE_TYPE = CARD_IMAGE_TYPE;
160
+ exports.CARD_PLACEHOLDER_TYPE = CARD_PLACEHOLDER_TYPE;
161
+ exports.CARD_TYPE = CARD_TYPE;
162
+ exports.CARD_TYPES = CARD_TYPES;
163
+ exports.createCard = createCard;
@@ -0,0 +1,3 @@
1
+ export * from './typings';
2
+ export * from './constants';
3
+ export * from './createCard';
package/card/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { CARD_CONTENTS_TYPE, CARD_IMAGE_TYPE, CARD_PLACEHOLDER_TYPE, CARD_TYPE, CARD_TYPES } from './constants.js';
2
+ export { createCard } from './createCard.js';
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@quadrats/common/card",
3
+ "sideEffects": false,
4
+ "main": "./index.cjs.js",
5
+ "module": "./index.js",
6
+ "typings": "./index.d.ts"
7
+ }
@@ -0,0 +1,73 @@
1
+ import { Editor, Withable, QuadratsElement, WithElementType, Text, Path } from '@quadrats/core';
2
+ import { ImageAccept, FileUploaderGetBody, FileUploaderGetHeaders, FileUploaderGetUrl, FileUploaderImplement } from '@quadrats/common/file-uploader';
3
+ export type CardTypeKey = 'card';
4
+ export type CardImageTypeKey = 'card_image';
5
+ export type CardContentsTypeKey = 'card_contents';
6
+ export type CardTypes = Record<CardTypeKey | CardImageTypeKey | CardContentsTypeKey, string>;
7
+ export type CardAlignment = 'leftImageRightText' | 'rightImageLeftText' | 'noImage';
8
+ export type CardImageItem = {
9
+ file: File;
10
+ progress: number;
11
+ preview: string;
12
+ url: string;
13
+ };
14
+ export type CardElementValues = {
15
+ alignment: CardAlignment;
16
+ imageItem: CardImageItem | null;
17
+ title: string;
18
+ description: string;
19
+ remark: string;
20
+ haveLink: boolean;
21
+ linkText: string;
22
+ linkUrl: string;
23
+ };
24
+ export interface CardElement extends QuadratsElement, WithElementType, CardElementValues {
25
+ confirmModal: boolean;
26
+ }
27
+ export interface CardImageElement extends QuadratsElement, WithElementType {
28
+ children: [Text];
29
+ ratio?: [number, number];
30
+ src: string;
31
+ }
32
+ export interface CardContentsElement extends QuadratsElement, WithElementType {
33
+ children: [Text];
34
+ alignment: CardAlignment;
35
+ title: string;
36
+ description: string;
37
+ remark: string;
38
+ haveLink: boolean;
39
+ linkText: string;
40
+ linkUrl: string;
41
+ }
42
+ export interface CardPlaceholderElement extends QuadratsElement, WithElementType {
43
+ ratio?: [number, number];
44
+ children: [Text];
45
+ }
46
+ export interface Card<T extends Editor = Editor> extends Withable {
47
+ types: CardTypes;
48
+ insertCardPlaceholder(editor: T): void;
49
+ removeCardPlaceholder(editor: T): void;
50
+ createCardElement(cardValues: CardElementValues): CardElement;
51
+ insertCard({ editor, cardValues }: {
52
+ editor: T;
53
+ cardValues: CardElementValues;
54
+ }): void;
55
+ updateCardElement({ editor, cardValues, path }: {
56
+ editor: T;
57
+ cardValues: CardElementValues;
58
+ path: Path;
59
+ }): void;
60
+ updateCardAlignment({ editor, alignment, path }: {
61
+ editor: T;
62
+ alignment: CardAlignment;
63
+ path: Path;
64
+ }): void;
65
+ accept: ImageAccept[];
66
+ ratio?: [number, number];
67
+ limitSize: number;
68
+ confirmModal: boolean;
69
+ getBody: FileUploaderGetBody;
70
+ getHeaders?: FileUploaderGetHeaders;
71
+ getUrl: FileUploaderGetUrl;
72
+ uploader?: FileUploaderImplement;
73
+ }
@@ -0,0 +1,33 @@
1
+ /******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+ /* global Reflect, Promise, SuppressedError, Symbol */
16
+
17
+
18
+ function __awaiter(thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ }
27
+
28
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
29
+ var e = new Error(message);
30
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
31
+ };
32
+
33
+ export { __awaiter };
@@ -0,0 +1,6 @@
1
+ import { CarouselTypes } from './typings';
2
+ export declare const CAROUSEL_TYPE = "carousel";
3
+ export declare const CAROUSEL_IMAGES_TYPE = "carousel_images";
4
+ export declare const CAROUSEL_CAPTION_TYPE = "carousel_caption";
5
+ export declare const CAROUSEL_PLACEHOLDER_TYPE = "carousel_placeholder";
6
+ export declare const CAROUSEL_TYPES: CarouselTypes;
@@ -0,0 +1,11 @@
1
+ const CAROUSEL_TYPE = 'carousel';
2
+ const CAROUSEL_IMAGES_TYPE = 'carousel_images';
3
+ const CAROUSEL_CAPTION_TYPE = 'carousel_caption';
4
+ const CAROUSEL_PLACEHOLDER_TYPE = 'carousel_placeholder';
5
+ const CAROUSEL_TYPES = {
6
+ carousel: CAROUSEL_TYPE,
7
+ carousel_images: CAROUSEL_IMAGES_TYPE,
8
+ carousel_caption: CAROUSEL_CAPTION_TYPE,
9
+ };
10
+
11
+ export { CAROUSEL_CAPTION_TYPE, CAROUSEL_IMAGES_TYPE, CAROUSEL_PLACEHOLDER_TYPE, CAROUSEL_TYPE, CAROUSEL_TYPES };
@@ -0,0 +1,16 @@
1
+ import { Editor } from '@quadrats/core';
2
+ import { ImageAccept, FileUploaderGetBody, FileUploaderGetHeaders, FileUploaderGetUrl, FileUploaderImplement } from '@quadrats/common/file-uploader';
3
+ import { Carousel, CarouselTypes } from './typings';
4
+ export interface CreateCarouselOptions {
5
+ types?: Partial<CarouselTypes>;
6
+ accept?: ImageAccept[];
7
+ ratio?: [number, number];
8
+ maxLength?: number;
9
+ limitSize?: number;
10
+ confirmModal?: boolean;
11
+ getBody: FileUploaderGetBody;
12
+ getHeaders?: FileUploaderGetHeaders;
13
+ getUrl: FileUploaderGetUrl;
14
+ uploader?: FileUploaderImplement;
15
+ }
16
+ export declare function createCarousel(options: CreateCarouselOptions): Carousel<Editor>;
@@ -0,0 +1,127 @@
1
+ import { __awaiter } from './_virtual/_tslib.js';
2
+ import { Element, Node, Transforms, Editor, createParagraphElement } from '@quadrats/core';
3
+ import { CAROUSEL_TYPES, CAROUSEL_PLACEHOLDER_TYPE } from './constants.js';
4
+ import { getFilesFromInput } from './getFilesFromInput.js';
5
+
6
+ function createCarousel(options) {
7
+ const { types: typesOptions, accept: acceptOptions, ratio, maxLength: maxLengthOptions, limitSize: limitSizeOptions, confirmModal = true, getBody, getHeaders, getUrl, uploader, } = options;
8
+ const types = Object.assign(Object.assign({}, CAROUSEL_TYPES), typesOptions);
9
+ const maxLength = maxLengthOptions || 10;
10
+ const limitSize = limitSizeOptions || 5;
11
+ const accept = acceptOptions || ['image/jpeg', 'image/jpg', 'image/png'];
12
+ const selectFiles = () => __awaiter(this, void 0, void 0, function* () {
13
+ const files = yield getFilesFromInput({ accept });
14
+ return files;
15
+ });
16
+ const insertCarouselPlaceholder = (editor) => {
17
+ const carouselPlaceholderElement = {
18
+ type: CAROUSEL_PLACEHOLDER_TYPE,
19
+ ratio,
20
+ children: [{ text: '' }],
21
+ };
22
+ Editor.withoutNormalizing(editor, () => {
23
+ Transforms.insertNodes(editor, carouselPlaceholderElement);
24
+ });
25
+ };
26
+ const removeCarouselPlaceholder = (editor) => {
27
+ Transforms.removeNodes(editor, {
28
+ match: (node) => Element.isElement(node) && node.type === CAROUSEL_PLACEHOLDER_TYPE,
29
+ });
30
+ };
31
+ const createCarouselElement = ({ items }) => {
32
+ const carouselImagesElement = {
33
+ type: types.carousel_images,
34
+ images: items.map((i) => i.url),
35
+ ratio,
36
+ children: [{ text: '' }],
37
+ };
38
+ const carouselCaptionElement = {
39
+ type: types.carousel_caption,
40
+ captions: items.map((i) => i.caption),
41
+ children: [{ text: '' }],
42
+ };
43
+ return {
44
+ type: types.carousel,
45
+ confirmModal,
46
+ items,
47
+ children: [carouselImagesElement, carouselCaptionElement],
48
+ };
49
+ };
50
+ const insertCarousel = ({ editor, items }) => {
51
+ Transforms.insertNodes(editor, [createCarouselElement({ items }), createParagraphElement()]);
52
+ };
53
+ const updateCarouselElement = ({ editor, items, path }) => {
54
+ Transforms.setNodes(editor, { items }, { at: path });
55
+ const imagesEntries = Editor.nodes(editor, {
56
+ at: path,
57
+ match: (node) => Element.isElement(node) && node.type === types.carousel_images,
58
+ mode: 'all',
59
+ });
60
+ const imagesNode = imagesEntries.next().value;
61
+ const captionEntries = Editor.nodes(editor, {
62
+ at: path,
63
+ match: (node) => Element.isElement(node) && node.type === types.carousel_caption,
64
+ mode: 'all',
65
+ });
66
+ const captionNode = captionEntries.next().value;
67
+ if (imagesNode) {
68
+ const [, imagesPath] = imagesNode;
69
+ Transforms.setNodes(editor, { images: items.map((i) => i.url) }, { at: imagesPath });
70
+ }
71
+ if (captionNode) {
72
+ const [, captionPath] = captionNode;
73
+ Transforms.setNodes(editor, { captions: items.map((i) => i.caption) }, {
74
+ at: captionPath,
75
+ });
76
+ }
77
+ };
78
+ return {
79
+ types,
80
+ accept,
81
+ ratio,
82
+ maxLength,
83
+ limitSize,
84
+ confirmModal,
85
+ selectFiles,
86
+ insertCarouselPlaceholder,
87
+ removeCarouselPlaceholder,
88
+ createCarouselElement,
89
+ insertCarousel,
90
+ updateCarouselElement,
91
+ getBody,
92
+ getHeaders,
93
+ getUrl,
94
+ uploader,
95
+ with(editor) {
96
+ const { normalizeNode } = editor;
97
+ editor.normalizeNode = (entry) => {
98
+ const [node, path] = entry;
99
+ if (Element.isElement(node)) {
100
+ const type = node.type;
101
+ if (type === types.carousel) {
102
+ for (const [child, childPath] of Node.children(editor, path)) {
103
+ if (Element.isElement(child) &&
104
+ child.type !== types.carousel_caption &&
105
+ child.type !== types.carousel_images) {
106
+ Transforms.removeNodes(editor, { at: childPath });
107
+ return;
108
+ }
109
+ }
110
+ }
111
+ else if (type === types.carousel_caption || type === types.carousel_images) {
112
+ for (const [child, childPath] of Node.children(editor, path)) {
113
+ if (Element.isElement(child)) {
114
+ Transforms.removeNodes(editor, { at: childPath });
115
+ return;
116
+ }
117
+ }
118
+ }
119
+ }
120
+ normalizeNode(entry);
121
+ };
122
+ return editor;
123
+ },
124
+ };
125
+ }
126
+
127
+ export { createCarousel };
@@ -0,0 +1,4 @@
1
+ import { ImageAccept } from '@quadrats/common/file-uploader';
2
+ export declare function getFilesFromInput(options: {
3
+ accept: ImageAccept[];
4
+ }): Promise<File[] | undefined>;
@@ -0,0 +1,30 @@
1
+ function getFilesFromInput(options) {
2
+ const { accept } = options;
3
+ return new Promise((resolve) => {
4
+ const inputEl = document.createElement('input');
5
+ if (accept) {
6
+ inputEl.accept = accept.join(',');
7
+ }
8
+ inputEl.multiple = true;
9
+ inputEl.type = 'file';
10
+ inputEl.addEventListener('cancel', () => {
11
+ resolve(undefined);
12
+ });
13
+ inputEl.addEventListener('change', () => {
14
+ const { files: fileList } = inputEl;
15
+ if (!fileList || !fileList.length) {
16
+ resolve(undefined);
17
+ }
18
+ else {
19
+ const files = [];
20
+ for (const file of fileList) {
21
+ files.push(file);
22
+ }
23
+ resolve(files);
24
+ }
25
+ });
26
+ inputEl.click();
27
+ });
28
+ }
29
+
30
+ export { getFilesFromInput };