@quadrats/common 0.6.7 → 0.7.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 (85) hide show
  1. package/blockquote/createBlockquote.d.ts +1 -1
  2. package/blockquote/createBlockquote.js +33 -33
  3. package/blockquote/index.cjs.js +32 -34
  4. package/bold/createBold.d.ts +2 -1
  5. package/bold/createBold.js +6 -4
  6. package/bold/index.cjs.js +6 -6
  7. package/divider/createDivider.d.ts +1 -1
  8. package/divider/createDivider.js +29 -29
  9. package/divider/index.cjs.js +29 -31
  10. package/embed/createEmbed.js +40 -40
  11. package/embed/deserializeEmbedElementToData.js +6 -6
  12. package/embed/index.cjs.js +54 -56
  13. package/embed/serializeEmbedCode.js +8 -8
  14. package/embed/strategies/facebook/index.cjs.js +45 -47
  15. package/embed/strategies/facebook/index.d.ts +5 -5
  16. package/embed/strategies/facebook/index.js +45 -45
  17. package/embed/strategies/instagram/index.cjs.js +29 -31
  18. package/embed/strategies/instagram/index.d.ts +3 -3
  19. package/embed/strategies/instagram/index.js +29 -29
  20. package/embed/strategies/podcast-apple/index.cjs.js +16 -18
  21. package/embed/strategies/podcast-apple/index.d.ts +4 -4
  22. package/embed/strategies/podcast-apple/index.js +16 -16
  23. package/embed/strategies/spotify/index.cjs.js +14 -16
  24. package/embed/strategies/spotify/index.d.ts +4 -4
  25. package/embed/strategies/spotify/index.js +14 -14
  26. package/embed/strategies/twitter/index.cjs.js +41 -43
  27. package/embed/strategies/twitter/index.d.ts +4 -4
  28. package/embed/strategies/twitter/index.js +41 -41
  29. package/embed/strategies/vimeo/index.cjs.js +14 -16
  30. package/embed/strategies/vimeo/index.d.ts +3 -3
  31. package/embed/strategies/vimeo/index.js +14 -14
  32. package/embed/strategies/youtube/index.cjs.js +14 -16
  33. package/embed/strategies/youtube/index.d.ts +3 -3
  34. package/embed/strategies/youtube/index.js +14 -14
  35. package/embed/typings.d.ts +1 -1
  36. package/file-uploader/_virtual/_tslib.js +3 -1
  37. package/file-uploader/createFileUploader.js +76 -76
  38. package/file-uploader/getFilesFromInput.js +24 -24
  39. package/file-uploader/index.cjs.js +102 -102
  40. package/file-uploader/typings.d.ts +6 -6
  41. package/footnote/createFootnote.d.ts +1 -1
  42. package/footnote/createFootnote.js +65 -65
  43. package/footnote/index.cjs.js +65 -67
  44. package/footnote/typings.d.ts +1 -1
  45. package/heading/constants.js +1 -1
  46. package/heading/createHeading.d.ts +1 -1
  47. package/heading/createHeading.js +45 -45
  48. package/heading/index.cjs.js +46 -48
  49. package/heading/typings.d.ts +1 -1
  50. package/highlight/createHighlight.d.ts +2 -1
  51. package/highlight/createHighlight.js +6 -4
  52. package/highlight/index.cjs.js +6 -6
  53. package/image/constants.js +4 -4
  54. package/image/createImage.js +195 -195
  55. package/image/getImageElementCommonProps.js +6 -6
  56. package/image/getImageFigureElementCommonProps.js +5 -5
  57. package/image/index.cjs.js +211 -213
  58. package/image/isHostingNotRequired.js +2 -2
  59. package/image/typings.d.ts +8 -8
  60. package/input-block/createInputBlock.js +37 -37
  61. package/input-block/index.cjs.js +37 -39
  62. package/input-widget/typings.d.ts +1 -1
  63. package/italic/createItalic.d.ts +2 -1
  64. package/italic/createItalic.js +6 -4
  65. package/italic/index.cjs.js +6 -6
  66. package/link/createLink.js +147 -147
  67. package/link/index.cjs.js +146 -148
  68. package/link/typings.d.ts +2 -2
  69. package/list/constants.js +4 -4
  70. package/list/createList.js +185 -185
  71. package/list/index.cjs.js +188 -190
  72. package/list/typings.d.ts +4 -4
  73. package/package.json +4 -4
  74. package/read-more/createReadMore.d.ts +1 -1
  75. package/read-more/createReadMore.js +51 -51
  76. package/read-more/index.cjs.js +50 -52
  77. package/strikethrough/createStrikethrough.d.ts +2 -1
  78. package/strikethrough/createStrikethrough.js +6 -4
  79. package/strikethrough/index.cjs.js +6 -6
  80. package/toggle-mark/createToggleMarkCreator.d.ts +4 -4
  81. package/toggle-mark/createToggleMarkCreator.js +36 -36
  82. package/toggle-mark/index.cjs.js +36 -38
  83. package/underline/createUnderline.d.ts +2 -1
  84. package/underline/createUnderline.js +6 -4
  85. package/underline/index.cjs.js +6 -6
@@ -1,4 +1,4 @@
1
1
  import { WithElementType } from '@quadrats/core';
2
2
  import { Blockquote } from './typings';
3
- export declare type CreateBlockquoteOptions = Partial<WithElementType>;
3
+ export type CreateBlockquoteOptions = Partial<WithElementType>;
4
4
  export declare function createBlockquote({ type }?: CreateBlockquoteOptions): Blockquote;
@@ -1,38 +1,38 @@
1
- import { isNodesTypeIn, unwrapNodesByTypes, wrapNodesWithUnhangRange } from '@quadrats/core';
1
+ import { unwrapNodesByTypes, wrapNodesWithUnhangRange, isNodesTypeIn } from '@quadrats/core';
2
2
  import { BLOCKQUOTE_TYPE } from './constants.js';
3
3
 
4
- function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
5
- const unwrapBlockquote = (editor) => {
6
- unwrapNodesByTypes(editor, [type]);
7
- };
8
- const wrapBlockquote = (editor) => {
9
- const element = {
10
- type,
11
- children: [],
12
- };
13
- wrapNodesWithUnhangRange(editor, element, { split: true });
14
- };
15
- const isSelectionInBlockquote = editor => (isNodesTypeIn(editor, [type], { mode: 'highest' }));
16
- return {
17
- type,
18
- unwrapBlockquote,
19
- wrapBlockquote,
20
- isSelectionInBlockquote,
21
- toggleBlockquote: (editor) => {
22
- const actived = isSelectionInBlockquote(editor);
23
- if (editor.selection) {
24
- if (actived) {
25
- unwrapBlockquote(editor);
26
- }
27
- else {
28
- wrapBlockquote(editor);
29
- }
30
- }
31
- },
32
- with(editor) {
33
- return editor;
34
- },
35
- };
4
+ function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
5
+ const unwrapBlockquote = (editor) => {
6
+ unwrapNodesByTypes(editor, [type]);
7
+ };
8
+ const wrapBlockquote = (editor) => {
9
+ const element = {
10
+ type,
11
+ children: [],
12
+ };
13
+ wrapNodesWithUnhangRange(editor, element, { split: true });
14
+ };
15
+ const isSelectionInBlockquote = editor => (isNodesTypeIn(editor, [type], { mode: 'highest' }));
16
+ return {
17
+ type,
18
+ unwrapBlockquote,
19
+ wrapBlockquote,
20
+ isSelectionInBlockquote,
21
+ toggleBlockquote: (editor) => {
22
+ const actived = isSelectionInBlockquote(editor);
23
+ if (editor.selection) {
24
+ if (actived) {
25
+ unwrapBlockquote(editor);
26
+ }
27
+ else {
28
+ wrapBlockquote(editor);
29
+ }
30
+ }
31
+ },
32
+ with(editor) {
33
+ return editor;
34
+ },
35
+ };
36
36
  }
37
37
 
38
38
  export { createBlockquote };
@@ -1,43 +1,41 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@quadrats/core');
6
4
 
7
5
  const BLOCKQUOTE_TYPE = 'blockquote';
8
6
 
9
- function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
10
- const unwrapBlockquote = (editor) => {
11
- core.unwrapNodesByTypes(editor, [type]);
12
- };
13
- const wrapBlockquote = (editor) => {
14
- const element = {
15
- type,
16
- children: [],
17
- };
18
- core.wrapNodesWithUnhangRange(editor, element, { split: true });
19
- };
20
- const isSelectionInBlockquote = editor => (core.isNodesTypeIn(editor, [type], { mode: 'highest' }));
21
- return {
22
- type,
23
- unwrapBlockquote,
24
- wrapBlockquote,
25
- isSelectionInBlockquote,
26
- toggleBlockquote: (editor) => {
27
- const actived = isSelectionInBlockquote(editor);
28
- if (editor.selection) {
29
- if (actived) {
30
- unwrapBlockquote(editor);
31
- }
32
- else {
33
- wrapBlockquote(editor);
34
- }
35
- }
36
- },
37
- with(editor) {
38
- return editor;
39
- },
40
- };
7
+ function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
8
+ const unwrapBlockquote = (editor) => {
9
+ core.unwrapNodesByTypes(editor, [type]);
10
+ };
11
+ const wrapBlockquote = (editor) => {
12
+ const element = {
13
+ type,
14
+ children: [],
15
+ };
16
+ core.wrapNodesWithUnhangRange(editor, element, { split: true });
17
+ };
18
+ const isSelectionInBlockquote = editor => (core.isNodesTypeIn(editor, [type], { mode: 'highest' }));
19
+ return {
20
+ type,
21
+ unwrapBlockquote,
22
+ wrapBlockquote,
23
+ isSelectionInBlockquote,
24
+ toggleBlockquote: (editor) => {
25
+ const actived = isSelectionInBlockquote(editor);
26
+ if (editor.selection) {
27
+ if (actived) {
28
+ unwrapBlockquote(editor);
29
+ }
30
+ else {
31
+ wrapBlockquote(editor);
32
+ }
33
+ }
34
+ },
35
+ with(editor) {
36
+ return editor;
37
+ },
38
+ };
41
39
  }
42
40
 
43
41
  exports.BLOCKQUOTE_TYPE = BLOCKQUOTE_TYPE;
@@ -1 +1,2 @@
1
- export declare const createBold: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<import("slate").BaseEditor>;
1
+ import { Editor } from '@quadrats/core';
2
+ export declare function createBold<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
@@ -1,9 +1,11 @@
1
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
2
  import { BOLD_TYPE } from './constants.js';
3
3
 
4
- const createBold = (variant) => createToggleMarkCreator({
5
- type: BOLD_TYPE,
6
- variant,
7
- });
4
+ function createBold(variant) {
5
+ return createToggleMarkCreator({
6
+ type: BOLD_TYPE,
7
+ variant,
8
+ });
9
+ }
8
10
 
9
11
  export { createBold };
package/bold/index.cjs.js CHANGED
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var toggleMark = require('@quadrats/common/toggle-mark');
6
4
 
7
5
  const BOLD_TYPE = 'bold';
8
6
 
9
- const createBold = (variant) => toggleMark.createToggleMarkCreator({
10
- type: BOLD_TYPE,
11
- variant,
12
- });
7
+ function createBold(variant) {
8
+ return toggleMark.createToggleMarkCreator({
9
+ type: BOLD_TYPE,
10
+ variant,
11
+ });
12
+ }
13
13
 
14
14
  exports.BOLD_TYPE = BOLD_TYPE;
15
15
  exports.createBold = createBold;
@@ -1,4 +1,4 @@
1
1
  import { WithElementType } from '@quadrats/core';
2
2
  import { Divider } from './typings';
3
- export declare type CreateDividerOptions = Partial<WithElementType>;
3
+ export type CreateDividerOptions = Partial<WithElementType>;
4
4
  export declare function createDivider(options?: CreateDividerOptions): Divider;
@@ -1,35 +1,35 @@
1
1
  import { Element, normalizeVoidElementChildren, Transforms, createParagraphElement } from '@quadrats/core';
2
2
  import { DIVIDER_TYPE } from './constants.js';
3
3
 
4
- function createDivider(options = {}) {
5
- const { type = DIVIDER_TYPE } = options;
6
- const createDividerElement = () => ({ type, children: [{ text: '' }] });
7
- const insertDivider = (editor) => {
8
- Transforms.insertNodes(editor, [createDividerElement(), createParagraphElement()]);
9
- Transforms.move(editor);
10
- };
11
- return {
12
- type,
13
- createDividerElement,
14
- insertDivider,
15
- with(editor) {
16
- const { isVoid, normalizeNode } = editor;
17
- editor.isVoid = element => element.type === type || isVoid(element);
18
- editor.normalizeNode = (entry) => {
19
- const [node, path] = entry;
20
- /**
21
- * Only accept single empty text inside void element.
22
- */
23
- if (Element.isElement(node) && node.type === type) {
24
- if (normalizeVoidElementChildren(editor, [node, path])) {
25
- return;
26
- }
27
- }
28
- normalizeNode(entry);
29
- };
30
- return editor;
31
- },
32
- };
4
+ function createDivider(options = {}) {
5
+ const { type = DIVIDER_TYPE } = options;
6
+ const createDividerElement = () => ({ type, children: [{ text: '' }] });
7
+ const insertDivider = (editor) => {
8
+ Transforms.insertNodes(editor, [createDividerElement(), createParagraphElement()]);
9
+ Transforms.move(editor);
10
+ };
11
+ return {
12
+ type,
13
+ createDividerElement,
14
+ insertDivider,
15
+ with(editor) {
16
+ const { isVoid, normalizeNode } = editor;
17
+ editor.isVoid = element => element.type === type || isVoid(element);
18
+ editor.normalizeNode = (entry) => {
19
+ const [node, path] = entry;
20
+ /**
21
+ * Only accept single empty text inside void element.
22
+ */
23
+ if (Element.isElement(node) && node.type === type) {
24
+ if (normalizeVoidElementChildren(editor, [node, path])) {
25
+ return;
26
+ }
27
+ }
28
+ normalizeNode(entry);
29
+ };
30
+ return editor;
31
+ },
32
+ };
33
33
  }
34
34
 
35
35
  export { createDivider };
@@ -1,40 +1,38 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@quadrats/core');
6
4
 
7
5
  const DIVIDER_TYPE = 'hr';
8
6
 
9
- function createDivider(options = {}) {
10
- const { type = DIVIDER_TYPE } = options;
11
- const createDividerElement = () => ({ type, children: [{ text: '' }] });
12
- const insertDivider = (editor) => {
13
- core.Transforms.insertNodes(editor, [createDividerElement(), core.createParagraphElement()]);
14
- core.Transforms.move(editor);
15
- };
16
- return {
17
- type,
18
- createDividerElement,
19
- insertDivider,
20
- with(editor) {
21
- const { isVoid, normalizeNode } = editor;
22
- editor.isVoid = element => element.type === type || isVoid(element);
23
- editor.normalizeNode = (entry) => {
24
- const [node, path] = entry;
25
- /**
26
- * Only accept single empty text inside void element.
27
- */
28
- if (core.Element.isElement(node) && node.type === type) {
29
- if (core.normalizeVoidElementChildren(editor, [node, path])) {
30
- return;
31
- }
32
- }
33
- normalizeNode(entry);
34
- };
35
- return editor;
36
- },
37
- };
7
+ function createDivider(options = {}) {
8
+ const { type = DIVIDER_TYPE } = options;
9
+ const createDividerElement = () => ({ type, children: [{ text: '' }] });
10
+ const insertDivider = (editor) => {
11
+ core.Transforms.insertNodes(editor, [createDividerElement(), core.createParagraphElement()]);
12
+ core.Transforms.move(editor);
13
+ };
14
+ return {
15
+ type,
16
+ createDividerElement,
17
+ insertDivider,
18
+ with(editor) {
19
+ const { isVoid, normalizeNode } = editor;
20
+ editor.isVoid = element => element.type === type || isVoid(element);
21
+ editor.normalizeNode = (entry) => {
22
+ const [node, path] = entry;
23
+ /**
24
+ * Only accept single empty text inside void element.
25
+ */
26
+ if (core.Element.isElement(node) && node.type === type) {
27
+ if (core.normalizeVoidElementChildren(editor, [node, path])) {
28
+ return;
29
+ }
30
+ }
31
+ normalizeNode(entry);
32
+ };
33
+ return editor;
34
+ },
35
+ };
38
36
  }
39
37
 
40
38
  exports.DIVIDER_TYPE = DIVIDER_TYPE;
@@ -2,46 +2,46 @@ import { Element, Transforms, normalizeVoidElementChildren, PARAGRAPH_TYPE } fro
2
2
  import { EMBED_TYPE } from './constants.js';
3
3
  import { serializeEmbedCode } from './serializeEmbedCode.js';
4
4
 
5
- function createEmbed(options) {
6
- const { type = EMBED_TYPE, strategies } = options;
7
- const insertEmbed = (editor, providers, embedCode, defaultNode = PARAGRAPH_TYPE) => {
8
- const result = serializeEmbedCode(embedCode, strategies, providers);
9
- if (result) {
10
- const [provider, data] = result;
11
- const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
12
- Transforms.insertNodes(editor, [
13
- embedElement,
14
- typeof defaultNode === 'string'
15
- ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
16
- ]);
17
- Transforms.move(editor);
18
- }
19
- };
20
- return {
21
- type,
22
- strategies,
23
- insertEmbed,
24
- with(editor) {
25
- const { isVoid, normalizeNode } = editor;
26
- editor.isVoid = element => element.type === type || isVoid(element);
27
- editor.normalizeNode = (entry) => {
28
- const [node, path] = entry;
29
- if (Element.isElement(node) && node.type === type) {
30
- const strategy = node.provider
31
- ? strategies[node.provider] : undefined;
32
- if (!strategy || !strategy.isElementDataValid(node)) {
33
- Transforms.removeNodes(editor, { at: path });
34
- return;
35
- }
36
- if (normalizeVoidElementChildren(editor, [node, path])) {
37
- return;
38
- }
39
- }
40
- normalizeNode(entry);
41
- };
42
- return editor;
43
- },
44
- };
5
+ function createEmbed(options) {
6
+ const { type = EMBED_TYPE, strategies } = options;
7
+ const insertEmbed = (editor, providers, embedCode, defaultNode = PARAGRAPH_TYPE) => {
8
+ const result = serializeEmbedCode(embedCode, strategies, providers);
9
+ if (result) {
10
+ const [provider, data] = result;
11
+ const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
12
+ Transforms.insertNodes(editor, [
13
+ embedElement,
14
+ typeof defaultNode === 'string'
15
+ ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
16
+ ]);
17
+ Transforms.move(editor);
18
+ }
19
+ };
20
+ return {
21
+ type,
22
+ strategies,
23
+ insertEmbed,
24
+ with(editor) {
25
+ const { isVoid, normalizeNode } = editor;
26
+ editor.isVoid = element => element.type === type || isVoid(element);
27
+ editor.normalizeNode = (entry) => {
28
+ const [node, path] = entry;
29
+ if (Element.isElement(node) && node.type === type) {
30
+ const strategy = node.provider
31
+ ? strategies[node.provider] : undefined;
32
+ if (!strategy || !strategy.isElementDataValid(node)) {
33
+ Transforms.removeNodes(editor, { at: path });
34
+ return;
35
+ }
36
+ if (normalizeVoidElementChildren(editor, [node, path])) {
37
+ return;
38
+ }
39
+ }
40
+ normalizeNode(entry);
41
+ };
42
+ return editor;
43
+ },
44
+ };
45
45
  }
46
46
 
47
47
  export { createEmbed };
@@ -1,9 +1,9 @@
1
- function deserializeEmbedElementToData(element, strategies) {
2
- const { provider } = element;
3
- const strategy = provider ? strategies[provider] : undefined;
4
- if (strategy) {
5
- return [provider, strategy.deserialize(element)];
6
- }
1
+ function deserializeEmbedElementToData(element, strategies) {
2
+ const { provider } = element;
3
+ const strategy = provider ? strategies[provider] : undefined;
4
+ if (strategy) {
5
+ return [provider, strategy.deserialize(element)];
6
+ }
7
7
  }
8
8
 
9
9
  export { deserializeEmbedElementToData };
@@ -1,69 +1,67 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@quadrats/core');
6
4
 
7
5
  const EMBED_TYPE = 'embed';
8
6
 
9
- function serializeEmbedCode(embedCode, strategies, providers) {
10
- for (const provider of providers) {
11
- const strategy = strategies[provider];
12
- const data = strategy.serialize(embedCode);
13
- if (data) {
14
- return [provider, data];
15
- }
16
- }
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
+ }
14
+ }
17
15
  }
18
16
 
19
- function deserializeEmbedElementToData(element, strategies) {
20
- const { provider } = element;
21
- const strategy = provider ? strategies[provider] : undefined;
22
- if (strategy) {
23
- return [provider, strategy.deserialize(element)];
24
- }
17
+ function deserializeEmbedElementToData(element, strategies) {
18
+ const { provider } = element;
19
+ const strategy = provider ? strategies[provider] : undefined;
20
+ if (strategy) {
21
+ return [provider, strategy.deserialize(element)];
22
+ }
25
23
  }
26
24
 
27
- function createEmbed(options) {
28
- const { type = EMBED_TYPE, strategies } = options;
29
- const insertEmbed = (editor, providers, embedCode, defaultNode = core.PARAGRAPH_TYPE) => {
30
- const result = serializeEmbedCode(embedCode, strategies, providers);
31
- if (result) {
32
- const [provider, data] = result;
33
- const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
34
- core.Transforms.insertNodes(editor, [
35
- embedElement,
36
- typeof defaultNode === 'string'
37
- ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
38
- ]);
39
- core.Transforms.move(editor);
40
- }
41
- };
42
- return {
43
- type,
44
- strategies,
45
- insertEmbed,
46
- with(editor) {
47
- const { isVoid, normalizeNode } = editor;
48
- editor.isVoid = element => element.type === type || isVoid(element);
49
- editor.normalizeNode = (entry) => {
50
- const [node, path] = entry;
51
- if (core.Element.isElement(node) && node.type === type) {
52
- const strategy = node.provider
53
- ? strategies[node.provider] : undefined;
54
- if (!strategy || !strategy.isElementDataValid(node)) {
55
- core.Transforms.removeNodes(editor, { at: path });
56
- return;
57
- }
58
- if (core.normalizeVoidElementChildren(editor, [node, path])) {
59
- return;
60
- }
61
- }
62
- normalizeNode(entry);
63
- };
64
- return editor;
65
- },
66
- };
25
+ function createEmbed(options) {
26
+ const { type = EMBED_TYPE, strategies } = options;
27
+ const insertEmbed = (editor, providers, embedCode, defaultNode = core.PARAGRAPH_TYPE) => {
28
+ const result = serializeEmbedCode(embedCode, strategies, providers);
29
+ if (result) {
30
+ const [provider, data] = result;
31
+ const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
32
+ core.Transforms.insertNodes(editor, [
33
+ embedElement,
34
+ typeof defaultNode === 'string'
35
+ ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
36
+ ]);
37
+ core.Transforms.move(editor);
38
+ }
39
+ };
40
+ return {
41
+ type,
42
+ strategies,
43
+ insertEmbed,
44
+ with(editor) {
45
+ const { isVoid, normalizeNode } = editor;
46
+ editor.isVoid = element => element.type === type || isVoid(element);
47
+ editor.normalizeNode = (entry) => {
48
+ const [node, path] = entry;
49
+ if (core.Element.isElement(node) && node.type === type) {
50
+ const strategy = node.provider
51
+ ? strategies[node.provider] : undefined;
52
+ if (!strategy || !strategy.isElementDataValid(node)) {
53
+ core.Transforms.removeNodes(editor, { at: path });
54
+ return;
55
+ }
56
+ if (core.normalizeVoidElementChildren(editor, [node, path])) {
57
+ return;
58
+ }
59
+ }
60
+ normalizeNode(entry);
61
+ };
62
+ return editor;
63
+ },
64
+ };
67
65
  }
68
66
 
69
67
  exports.EMBED_TYPE = EMBED_TYPE;
@@ -1,11 +1,11 @@
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
- }
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
+ }
8
+ }
9
9
  }
10
10
 
11
11
  export { serializeEmbedCode };