@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,202 @@
1
+ 'use strict';
2
+
3
+ var core = require('@quadrats/core');
4
+
5
+ const CAROUSEL_TYPE = 'carousel';
6
+ const CAROUSEL_IMAGES_TYPE = 'carousel_images';
7
+ const CAROUSEL_CAPTION_TYPE = 'carousel_caption';
8
+ const CAROUSEL_PLACEHOLDER_TYPE = 'carousel_placeholder';
9
+ const CAROUSEL_TYPES = {
10
+ carousel: CAROUSEL_TYPE,
11
+ carousel_images: CAROUSEL_IMAGES_TYPE,
12
+ carousel_caption: CAROUSEL_CAPTION_TYPE,
13
+ };
14
+
15
+ /******************************************************************************
16
+ Copyright (c) Microsoft Corporation.
17
+
18
+ Permission to use, copy, modify, and/or distribute this software for any
19
+ purpose with or without fee is hereby granted.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
+ PERFORMANCE OF THIS SOFTWARE.
28
+ ***************************************************************************** */
29
+ /* global Reflect, Promise, SuppressedError, Symbol */
30
+
31
+
32
+ function __awaiter(thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ }
41
+
42
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
43
+ var e = new Error(message);
44
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
+ };
46
+
47
+ function getFilesFromInput(options) {
48
+ const { accept } = options;
49
+ return new Promise((resolve) => {
50
+ const inputEl = document.createElement('input');
51
+ if (accept) {
52
+ inputEl.accept = accept.join(',');
53
+ }
54
+ inputEl.multiple = true;
55
+ inputEl.type = 'file';
56
+ inputEl.addEventListener('cancel', () => {
57
+ resolve(undefined);
58
+ });
59
+ inputEl.addEventListener('change', () => {
60
+ const { files: fileList } = inputEl;
61
+ if (!fileList || !fileList.length) {
62
+ resolve(undefined);
63
+ }
64
+ else {
65
+ const files = [];
66
+ for (const file of fileList) {
67
+ files.push(file);
68
+ }
69
+ resolve(files);
70
+ }
71
+ });
72
+ inputEl.click();
73
+ });
74
+ }
75
+
76
+ function createCarousel(options) {
77
+ const { types: typesOptions, accept: acceptOptions, ratio, maxLength: maxLengthOptions, limitSize: limitSizeOptions, confirmModal = true, getBody, getHeaders, getUrl, uploader, } = options;
78
+ const types = Object.assign(Object.assign({}, CAROUSEL_TYPES), typesOptions);
79
+ const maxLength = maxLengthOptions || 10;
80
+ const limitSize = limitSizeOptions || 5;
81
+ const accept = acceptOptions || ['image/jpeg', 'image/jpg', 'image/png'];
82
+ const selectFiles = () => __awaiter(this, void 0, void 0, function* () {
83
+ const files = yield getFilesFromInput({ accept });
84
+ return files;
85
+ });
86
+ const insertCarouselPlaceholder = (editor) => {
87
+ const carouselPlaceholderElement = {
88
+ type: CAROUSEL_PLACEHOLDER_TYPE,
89
+ ratio,
90
+ children: [{ text: '' }],
91
+ };
92
+ core.Editor.withoutNormalizing(editor, () => {
93
+ core.Transforms.insertNodes(editor, carouselPlaceholderElement);
94
+ });
95
+ };
96
+ const removeCarouselPlaceholder = (editor) => {
97
+ core.Transforms.removeNodes(editor, {
98
+ match: (node) => core.Element.isElement(node) && node.type === CAROUSEL_PLACEHOLDER_TYPE,
99
+ });
100
+ };
101
+ const createCarouselElement = ({ items }) => {
102
+ const carouselImagesElement = {
103
+ type: types.carousel_images,
104
+ images: items.map((i) => i.url),
105
+ ratio,
106
+ children: [{ text: '' }],
107
+ };
108
+ const carouselCaptionElement = {
109
+ type: types.carousel_caption,
110
+ captions: items.map((i) => i.caption),
111
+ children: [{ text: '' }],
112
+ };
113
+ return {
114
+ type: types.carousel,
115
+ confirmModal,
116
+ items,
117
+ children: [carouselImagesElement, carouselCaptionElement],
118
+ };
119
+ };
120
+ const insertCarousel = ({ editor, items }) => {
121
+ core.Transforms.insertNodes(editor, [createCarouselElement({ items }), core.createParagraphElement()]);
122
+ };
123
+ const updateCarouselElement = ({ editor, items, path }) => {
124
+ core.Transforms.setNodes(editor, { items }, { at: path });
125
+ const imagesEntries = core.Editor.nodes(editor, {
126
+ at: path,
127
+ match: (node) => core.Element.isElement(node) && node.type === types.carousel_images,
128
+ mode: 'all',
129
+ });
130
+ const imagesNode = imagesEntries.next().value;
131
+ const captionEntries = core.Editor.nodes(editor, {
132
+ at: path,
133
+ match: (node) => core.Element.isElement(node) && node.type === types.carousel_caption,
134
+ mode: 'all',
135
+ });
136
+ const captionNode = captionEntries.next().value;
137
+ if (imagesNode) {
138
+ const [, imagesPath] = imagesNode;
139
+ core.Transforms.setNodes(editor, { images: items.map((i) => i.url) }, { at: imagesPath });
140
+ }
141
+ if (captionNode) {
142
+ const [, captionPath] = captionNode;
143
+ core.Transforms.setNodes(editor, { captions: items.map((i) => i.caption) }, {
144
+ at: captionPath,
145
+ });
146
+ }
147
+ };
148
+ return {
149
+ types,
150
+ accept,
151
+ ratio,
152
+ maxLength,
153
+ limitSize,
154
+ confirmModal,
155
+ selectFiles,
156
+ insertCarouselPlaceholder,
157
+ removeCarouselPlaceholder,
158
+ createCarouselElement,
159
+ insertCarousel,
160
+ updateCarouselElement,
161
+ getBody,
162
+ getHeaders,
163
+ getUrl,
164
+ uploader,
165
+ with(editor) {
166
+ const { normalizeNode } = editor;
167
+ editor.normalizeNode = (entry) => {
168
+ const [node, path] = entry;
169
+ if (core.Element.isElement(node)) {
170
+ const type = node.type;
171
+ if (type === types.carousel) {
172
+ for (const [child, childPath] of core.Node.children(editor, path)) {
173
+ if (core.Element.isElement(child) &&
174
+ child.type !== types.carousel_caption &&
175
+ child.type !== types.carousel_images) {
176
+ core.Transforms.removeNodes(editor, { at: childPath });
177
+ return;
178
+ }
179
+ }
180
+ }
181
+ else if (type === types.carousel_caption || type === types.carousel_images) {
182
+ for (const [child, childPath] of core.Node.children(editor, path)) {
183
+ if (core.Element.isElement(child)) {
184
+ core.Transforms.removeNodes(editor, { at: childPath });
185
+ return;
186
+ }
187
+ }
188
+ }
189
+ }
190
+ normalizeNode(entry);
191
+ };
192
+ return editor;
193
+ },
194
+ };
195
+ }
196
+
197
+ exports.CAROUSEL_CAPTION_TYPE = CAROUSEL_CAPTION_TYPE;
198
+ exports.CAROUSEL_IMAGES_TYPE = CAROUSEL_IMAGES_TYPE;
199
+ exports.CAROUSEL_PLACEHOLDER_TYPE = CAROUSEL_PLACEHOLDER_TYPE;
200
+ exports.CAROUSEL_TYPE = CAROUSEL_TYPE;
201
+ exports.CAROUSEL_TYPES = CAROUSEL_TYPES;
202
+ exports.createCarousel = createCarousel;
@@ -0,0 +1,3 @@
1
+ export * from './typings';
2
+ export * from './constants';
3
+ export * from './createCarousel';
@@ -0,0 +1,2 @@
1
+ export { CAROUSEL_CAPTION_TYPE, CAROUSEL_IMAGES_TYPE, CAROUSEL_PLACEHOLDER_TYPE, CAROUSEL_TYPE, CAROUSEL_TYPES } from './constants.js';
2
+ export { createCarousel } from './createCarousel.js';
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@quadrats/common/carousel",
3
+ "sideEffects": false,
4
+ "main": "./index.cjs.js",
5
+ "module": "./index.js",
6
+ "typings": "./index.d.ts"
7
+ }
@@ -0,0 +1,58 @@
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 CarouselTypeKey = 'carousel';
4
+ export type CarouselImagesTypeKey = 'carousel_images';
5
+ export type CarouselCaptionTypeKey = 'carousel_caption';
6
+ export type CarouselTypes = Record<CarouselTypeKey | CarouselImagesTypeKey | CarouselCaptionTypeKey, string>;
7
+ export interface CarouselFieldArrayItem {
8
+ file: File;
9
+ progress: number;
10
+ preview: string;
11
+ url: string;
12
+ caption: string;
13
+ isError?: boolean;
14
+ }
15
+ export interface CarouselElement extends QuadratsElement, WithElementType {
16
+ confirmModal: boolean;
17
+ items: CarouselFieldArrayItem[];
18
+ }
19
+ export interface CarouselImagesElement extends QuadratsElement, WithElementType {
20
+ children: [Text];
21
+ ratio?: [number, number];
22
+ images: string[];
23
+ }
24
+ export interface CarouselCaptionElement extends QuadratsElement, WithElementType {
25
+ children: [Text];
26
+ captions: string[];
27
+ }
28
+ export interface CarouselPlaceholderElement extends QuadratsElement, WithElementType {
29
+ ratio?: [number, number];
30
+ children: [Text];
31
+ }
32
+ export interface Carousel<T extends Editor = Editor> extends Withable {
33
+ types: CarouselTypes;
34
+ insertCarouselPlaceholder(editor: T): void;
35
+ removeCarouselPlaceholder(editor: T): void;
36
+ createCarouselElement({ items }: {
37
+ items: CarouselFieldArrayItem[];
38
+ }): CarouselElement;
39
+ insertCarousel({ editor, items }: {
40
+ editor: T;
41
+ items: CarouselFieldArrayItem[];
42
+ }): void;
43
+ updateCarouselElement({ editor, items, path }: {
44
+ editor: T;
45
+ items: CarouselFieldArrayItem[];
46
+ path: Path;
47
+ }): void;
48
+ accept: ImageAccept[];
49
+ ratio?: [number, number];
50
+ maxLength: number;
51
+ limitSize: number;
52
+ confirmModal: boolean;
53
+ selectFiles(editor: T): Promise<File[] | undefined>;
54
+ getBody: FileUploaderGetBody;
55
+ getHeaders?: FileUploaderGetHeaders;
56
+ getUrl: FileUploaderGetUrl;
57
+ uploader?: FileUploaderImplement;
58
+ }
@@ -1 +1,2 @@
1
1
  export declare const EMBED_TYPE = "embed";
2
+ export declare const EMBED_PLACEHOLDER_TYPE = "embed_placeholder";
@@ -1,3 +1,4 @@
1
1
  const EMBED_TYPE = 'embed';
2
+ const EMBED_PLACEHOLDER_TYPE = 'embed_placeholder';
2
3
 
3
- export { EMBED_TYPE };
4
+ export { EMBED_PLACEHOLDER_TYPE, EMBED_TYPE };
@@ -1,14 +1,20 @@
1
- import { Element, Transforms, normalizeVoidElementChildren, PARAGRAPH_TYPE } from '@quadrats/core';
2
- import { EMBED_TYPE } from './constants.js';
1
+ import { PARAGRAPH_TYPE, Element, Transforms, normalizeVoidElementChildren, Editor, isAboveBlockEmpty } from '@quadrats/core';
2
+ import { EMBED_TYPE, EMBED_PLACEHOLDER_TYPE } from './constants.js';
3
3
  import { serializeEmbedCode } from './serializeEmbedCode.js';
4
4
 
5
5
  function createEmbed(options) {
6
6
  const { type = EMBED_TYPE, strategies } = options;
7
- const insertEmbed = (editor, providers, embedCode, defaultNode = PARAGRAPH_TYPE) => {
8
- const result = serializeEmbedCode(embedCode, strategies, providers);
7
+ const insertEmbed = (editor, provider, embedCode, defaultNode = PARAGRAPH_TYPE) => {
8
+ var _a;
9
+ const result = serializeEmbedCode(embedCode, strategies, provider);
9
10
  if (result) {
10
11
  const [provider, data] = result;
11
12
  const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
13
+ if (isAboveBlockEmpty(editor)) {
14
+ Transforms.removeNodes(editor, {
15
+ at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
16
+ });
17
+ }
12
18
  Transforms.insertNodes(editor, [
13
19
  embedElement,
14
20
  typeof defaultNode === 'string'
@@ -17,10 +23,27 @@ function createEmbed(options) {
17
23
  Transforms.move(editor);
18
24
  }
19
25
  };
26
+ const insertEmbedPlaceholder = (editor, provider) => {
27
+ const embedPlaceholderElement = {
28
+ type: EMBED_PLACEHOLDER_TYPE,
29
+ provider,
30
+ children: [{ text: '' }],
31
+ };
32
+ Editor.withoutNormalizing(editor, () => {
33
+ Transforms.insertNodes(editor, embedPlaceholderElement);
34
+ });
35
+ };
36
+ const removeEmbedPlaceholder = (editor) => {
37
+ Transforms.removeNodes(editor, {
38
+ match: node => Element.isElement(node) && node.type === EMBED_PLACEHOLDER_TYPE,
39
+ });
40
+ };
20
41
  return {
21
42
  type,
22
43
  strategies,
23
44
  insertEmbed,
45
+ insertEmbedPlaceholder,
46
+ removeEmbedPlaceholder,
24
47
  with(editor) {
25
48
  const { isVoid, normalizeNode } = editor;
26
49
  editor.isVoid = element => element.type === type || isVoid(element);
@@ -3,14 +3,13 @@
3
3
  var core = require('@quadrats/core');
4
4
 
5
5
  const EMBED_TYPE = 'embed';
6
+ const EMBED_PLACEHOLDER_TYPE = 'embed_placeholder';
6
7
 
7
- function serializeEmbedCode(embedCode, strategies, providers) {
8
- for (const provider of providers) {
9
- const strategy = strategies[provider];
10
- const data = strategy.serialize(embedCode);
11
- if (data) {
12
- return [provider, data];
13
- }
8
+ function serializeEmbedCode(embedCode, strategies, provider) {
9
+ const strategy = strategies[provider];
10
+ const data = strategy.serialize(embedCode);
11
+ if (data) {
12
+ return [provider, data];
14
13
  }
15
14
  }
16
15
 
@@ -24,11 +23,17 @@ function deserializeEmbedElementToData(element, strategies) {
24
23
 
25
24
  function createEmbed(options) {
26
25
  const { type = EMBED_TYPE, strategies } = options;
27
- const insertEmbed = (editor, providers, embedCode, defaultNode = core.PARAGRAPH_TYPE) => {
28
- const result = serializeEmbedCode(embedCode, strategies, providers);
26
+ const insertEmbed = (editor, provider, embedCode, defaultNode = core.PARAGRAPH_TYPE) => {
27
+ var _a;
28
+ const result = serializeEmbedCode(embedCode, strategies, provider);
29
29
  if (result) {
30
30
  const [provider, data] = result;
31
31
  const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
32
+ if (core.isAboveBlockEmpty(editor)) {
33
+ core.Transforms.removeNodes(editor, {
34
+ at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.anchor,
35
+ });
36
+ }
32
37
  core.Transforms.insertNodes(editor, [
33
38
  embedElement,
34
39
  typeof defaultNode === 'string'
@@ -37,10 +42,27 @@ function createEmbed(options) {
37
42
  core.Transforms.move(editor);
38
43
  }
39
44
  };
45
+ const insertEmbedPlaceholder = (editor, provider) => {
46
+ const embedPlaceholderElement = {
47
+ type: EMBED_PLACEHOLDER_TYPE,
48
+ provider,
49
+ children: [{ text: '' }],
50
+ };
51
+ core.Editor.withoutNormalizing(editor, () => {
52
+ core.Transforms.insertNodes(editor, embedPlaceholderElement);
53
+ });
54
+ };
55
+ const removeEmbedPlaceholder = (editor) => {
56
+ core.Transforms.removeNodes(editor, {
57
+ match: node => core.Element.isElement(node) && node.type === EMBED_PLACEHOLDER_TYPE,
58
+ });
59
+ };
40
60
  return {
41
61
  type,
42
62
  strategies,
43
63
  insertEmbed,
64
+ insertEmbedPlaceholder,
65
+ removeEmbedPlaceholder,
44
66
  with(editor) {
45
67
  const { isVoid, normalizeNode } = editor;
46
68
  editor.isVoid = element => element.type === type || isVoid(element);
@@ -64,6 +86,7 @@ function createEmbed(options) {
64
86
  };
65
87
  }
66
88
 
89
+ exports.EMBED_PLACEHOLDER_TYPE = EMBED_PLACEHOLDER_TYPE;
67
90
  exports.EMBED_TYPE = EMBED_TYPE;
68
91
  exports.createEmbed = createEmbed;
69
92
  exports.deserializeEmbedElementToData = deserializeEmbedElementToData;
package/embed/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { EMBED_TYPE } from './constants.js';
1
+ export { EMBED_PLACEHOLDER_TYPE, EMBED_TYPE } from './constants.js';
2
2
  export { serializeEmbedCode } from './serializeEmbedCode.js';
3
3
  export { deserializeEmbedElementToData } from './deserializeEmbedElementToData.js';
4
4
  export { createEmbed } from './createEmbed.js';
@@ -1,2 +1,2 @@
1
1
  import { EmbedStrategies } from './typings';
2
- export declare function serializeEmbedCode<P extends string>(embedCode: string, strategies: EmbedStrategies<P>, providers: P[]): [P, any] | undefined;
2
+ export declare function serializeEmbedCode<P extends string>(embedCode: string, strategies: EmbedStrategies<P>, provider: P): [P, any] | undefined;
@@ -1,10 +1,8 @@
1
- function serializeEmbedCode(embedCode, strategies, providers) {
2
- for (const provider of providers) {
3
- const strategy = strategies[provider];
4
- const data = strategy.serialize(embedCode);
5
- if (data) {
6
- return [provider, data];
7
- }
1
+ function serializeEmbedCode(embedCode, strategies, provider) {
2
+ const strategy = strategies[provider];
3
+ const data = strategy.serialize(embedCode);
4
+ if (data) {
5
+ return [provider, data];
8
6
  }
9
7
  }
10
8
 
@@ -4,7 +4,7 @@
4
4
  const PodcastAppleEmbedStrategy = {
5
5
  serialize: (embedCode) => {
6
6
  var _a, _b;
7
- 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);
7
+ const result = (_b = (_a = /^https:\/\/embed.podcasts.apple.com\/([\w-]*)\/podcast\/[\S]*\/id([\S]*)/i.exec(embedCode)) !== null && _a !== void 0 ? _a : /^https:\/\/embed.podcasts.apple.com\/([\w-]*)\/podcast\/id([\S]*)/i.exec(embedCode)) !== null && _b !== void 0 ? _b : /^https:\/\/podcasts.apple.com\/([\w-]*)\/podcast\/[\S]*\/id([\S]*)/i.exec(embedCode);
8
8
  if (result) {
9
9
  const [, language, contextId] = result;
10
10
  return {
@@ -2,7 +2,7 @@
2
2
  const PodcastAppleEmbedStrategy = {
3
3
  serialize: (embedCode) => {
4
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);
5
+ const result = (_b = (_a = /^https:\/\/embed.podcasts.apple.com\/([\w-]*)\/podcast\/[\S]*\/id([\S]*)/i.exec(embedCode)) !== null && _a !== void 0 ? _a : /^https:\/\/embed.podcasts.apple.com\/([\w-]*)\/podcast\/id([\S]*)/i.exec(embedCode)) !== null && _b !== void 0 ? _b : /^https:\/\/podcasts.apple.com\/([\w-]*)\/podcast\/[\S]*\/id([\S]*)/i.exec(embedCode);
6
6
  if (result) {
7
7
  const [, language, contextId] = result;
8
8
  return {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  function getTwitterTweetDataFromUrl(url) {
4
- const result = /^https:\/\/twitter.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
4
+ const result = /^https:\/\/x.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
5
5
  if (result) {
6
6
  const [, tweetId] = result;
7
7
  return {
@@ -1,5 +1,5 @@
1
1
  function getTwitterTweetDataFromUrl(url) {
2
- const result = /^https:\/\/twitter.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
2
+ const result = /^https:\/\/x.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
3
3
  if (result) {
4
4
  const [, tweetId] = result;
5
5
  return {
@@ -1,5 +1,18 @@
1
1
  import { Editor, QuadratsElement, Node, Text, Withable, WithElementType } from '@quadrats/core';
2
2
  export interface EmbedElement extends QuadratsElement, WithElementType {
3
+ /**
4
+ * The embed provider.
5
+ *
6
+ * e.g. If you embed a youtube video, then you can use `youtube` as provider.
7
+ */
8
+ provider: string;
9
+ /**
10
+ * The embed alignment. default is `left`.
11
+ */
12
+ align?: 'left' | 'center' | 'right';
13
+ children: [Text];
14
+ }
15
+ export interface EmbedPlaceholderElement extends QuadratsElement, WithElementType {
3
16
  /**
4
17
  * The embed provider.
5
18
  *
@@ -22,5 +35,7 @@ export interface EmbedStrategy<EmbedData extends Record<string, unknown>, Render
22
35
  export type EmbedStrategies<Provider extends string> = Record<Provider, EmbedStrategy<any, any>>;
23
36
  export interface Embed<P extends string, T extends Editor = Editor> extends WithElementType, Withable {
24
37
  strategies: EmbedStrategies<P>;
25
- insertEmbed(editor: T, providers: P[], embedCode: string, defaultNode?: Node | string): void;
38
+ insertEmbed(editor: T, provider: P, embedCode: string, defaultNode?: Node | string): void;
39
+ insertEmbedPlaceholder(editor: T, provider: P): void;
40
+ removeEmbedPlaceholder(editor: T): void;
26
41
  }
@@ -1 +1,2 @@
1
1
  export declare const FILE_UPLOADER_TYPE = "file_uploader";
2
+ export declare const FILE_UPLOADER_PLACEHOLDER_TYPE = "file_uploader_placeholder";
@@ -1,3 +1,4 @@
1
1
  const FILE_UPLOADER_TYPE = 'file_uploader';
2
+ const FILE_UPLOADER_PLACEHOLDER_TYPE = 'file_uploader_placeholder';
2
3
 
3
- export { FILE_UPLOADER_TYPE };
4
+ export { FILE_UPLOADER_PLACEHOLDER_TYPE, FILE_UPLOADER_TYPE };
@@ -1,6 +1,8 @@
1
1
  import { Editor } from '@quadrats/core';
2
- import { FileUploader } from './typings';
2
+ import { FileUploader, FileUploaderElement } from './typings';
3
3
  export interface CreateFileUploaderOptions {
4
4
  type?: string;
5
5
  }
6
+ export declare const createFileUploaderElementByType: (type: string) => FileUploader<Editor>['createFileUploaderElement'];
7
+ export declare function insertFileUploaderElement(editor: Editor, fileUploaderElement: FileUploaderElement | undefined): void;
6
8
  export declare function createFileUploader(options?: CreateFileUploaderOptions): FileUploader<Editor>;