@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.
Files changed (54) hide show
  1. package/blockquote/createBlockquote.js +19 -3
  2. package/blockquote/index.cjs.js +18 -2
  3. package/blockquote/typings.d.ts +5 -5
  4. package/bold/createBold.d.ts +1 -1
  5. package/bold/createBold.js +2 -3
  6. package/bold/index.cjs.js +2 -3
  7. package/divider/createDivider.js +1 -1
  8. package/divider/index.cjs.js +1 -1
  9. package/divider/typings.d.ts +4 -4
  10. package/embed/createEmbed.js +5 -3
  11. package/embed/index.cjs.js +5 -3
  12. package/embed/typings.d.ts +4 -4
  13. package/file-uploader/createFileUploader.d.ts +2 -1
  14. package/file-uploader/createFileUploader.js +5 -11
  15. package/file-uploader/index.cjs.js +4 -10
  16. package/file-uploader/typings.d.ts +7 -7
  17. package/footnote/createFootnote.js +6 -14
  18. package/footnote/index.cjs.js +6 -14
  19. package/footnote/typings.d.ts +14 -10
  20. package/heading/createHeading.js +1 -1
  21. package/heading/index.cjs.js +1 -1
  22. package/heading/typings.d.ts +6 -6
  23. package/highlight/createHighlight.d.ts +1 -1
  24. package/highlight/createHighlight.js +2 -3
  25. package/highlight/index.cjs.js +2 -3
  26. package/image/createImage.js +6 -6
  27. package/image/index.cjs.js +6 -6
  28. package/image/typings.d.ts +12 -12
  29. package/input-block/createInputBlock.js +7 -1
  30. package/input-block/index.cjs.js +7 -1
  31. package/input-block/typings.d.ts +5 -5
  32. package/italic/createItalic.d.ts +1 -1
  33. package/italic/createItalic.js +2 -3
  34. package/italic/index.cjs.js +2 -3
  35. package/link/createLink.js +6 -3
  36. package/link/index.cjs.js +6 -3
  37. package/link/typings.d.ts +9 -9
  38. package/list/createList.js +11 -5
  39. package/list/index.cjs.js +11 -5
  40. package/list/typings.d.ts +14 -14
  41. package/package.json +4 -4
  42. package/read-more/createReadMore.js +1 -1
  43. package/read-more/index.cjs.js +1 -1
  44. package/read-more/typings.d.ts +4 -4
  45. package/strikethrough/createStrikethrough.d.ts +1 -1
  46. package/strikethrough/createStrikethrough.js +2 -3
  47. package/strikethrough/index.cjs.js +2 -3
  48. package/toggle-mark/createToggleMarkCreator.d.ts +3 -3
  49. package/toggle-mark/createToggleMarkCreator.js +18 -12
  50. package/toggle-mark/index.cjs.js +17 -11
  51. package/toggle-mark/typings.d.ts +3 -3
  52. package/underline/createUnderline.d.ts +1 -1
  53. package/underline/createUnderline.js +2 -3
  54. package/underline/index.cjs.js +2 -3
@@ -1,11 +1,27 @@
1
- import { isNodesTypeIn, toggleNodesType, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
1
+ import { isNodesTypeIn, toggleNodesType, Editor, Transforms, createParagraphElement, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
2
2
  import { BLOCKQUOTE_TYPE } from './constants.js';
3
3
 
4
4
  function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
5
5
  return {
6
6
  type,
7
- isSelectionInBlockquote: (editor) => isNodesTypeIn(editor, [type]),
8
- toggleBlockquote: (editor) => toggleNodesType(editor, type),
7
+ isSelectionInBlockquote: editor => isNodesTypeIn(editor, [type]),
8
+ toggleBlockquote: (editor) => {
9
+ const actived = isNodesTypeIn(editor, [type]);
10
+ toggleNodesType(editor, type);
11
+ if (!actived) {
12
+ if (editor.selection) {
13
+ // Select to line end
14
+ const originPoint = Editor.point(editor, editor.selection.focus);
15
+ Transforms.move(editor, { unit: 'line', edge: 'end' });
16
+ Transforms.collapse(editor, { edge: 'end' });
17
+ // Only last block add paragraph automatically
18
+ if (!Editor.next(editor)) {
19
+ Transforms.insertNodes(editor, [createParagraphElement()]);
20
+ }
21
+ Transforms.select(editor, originPoint);
22
+ }
23
+ }
24
+ },
9
25
  with(editor) {
10
26
  const { normalizeNode } = editor;
11
27
  editor.normalizeNode = (entry) => {
@@ -9,8 +9,24 @@ const BLOCKQUOTE_TYPE = 'blockquote';
9
9
  function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
10
10
  return {
11
11
  type,
12
- isSelectionInBlockquote: (editor) => core.isNodesTypeIn(editor, [type]),
13
- toggleBlockquote: (editor) => core.toggleNodesType(editor, type),
12
+ isSelectionInBlockquote: editor => core.isNodesTypeIn(editor, [type]),
13
+ toggleBlockquote: (editor) => {
14
+ const actived = core.isNodesTypeIn(editor, [type]);
15
+ core.toggleNodesType(editor, type);
16
+ if (!actived) {
17
+ if (editor.selection) {
18
+ // Select to line end
19
+ const originPoint = core.Editor.point(editor, editor.selection.focus);
20
+ core.Transforms.move(editor, { unit: 'line', edge: 'end' });
21
+ core.Transforms.collapse(editor, { edge: 'end' });
22
+ // Only last block add paragraph automatically
23
+ if (!core.Editor.next(editor)) {
24
+ core.Transforms.insertNodes(editor, [core.createParagraphElement()]);
25
+ }
26
+ core.Transforms.select(editor, originPoint);
27
+ }
28
+ }
29
+ },
14
30
  with(editor) {
15
31
  const { normalizeNode } = editor;
16
32
  editor.normalizeNode = (entry) => {
@@ -1,7 +1,7 @@
1
- import { Editor, Element, Withable, WithElementType } from '@quadrats/core';
2
- export interface BlockquoteElement extends Element, WithElementType {
1
+ import { Editor, QuadratsElement, Withable, WithElementType } from '@quadrats/core';
2
+ export interface BlockquoteElement extends QuadratsElement, WithElementType {
3
3
  }
4
- export interface Blockquote extends WithElementType, Withable {
5
- isSelectionInBlockquote(editor: Editor): boolean;
6
- toggleBlockquote(editor: Editor): void;
4
+ export interface Blockquote<T extends Editor = Editor> extends WithElementType, Withable {
5
+ isSelectionInBlockquote(editor: T): boolean;
6
+ toggleBlockquote(editor: T): void;
7
7
  }
@@ -1 +1 @@
1
- export declare const createBold: (variant?: string | undefined) => ({ type, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
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,10 +1,9 @@
1
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
- import { getVariantType } from '@quadrats/core';
3
2
  import { BOLD_TYPE } from './constants.js';
4
3
 
5
4
  const createBold = (variant) => createToggleMarkCreator({
6
- type: getVariantType(BOLD_TYPE, variant),
7
- parentType: BOLD_TYPE,
5
+ type: BOLD_TYPE,
6
+ variant,
8
7
  });
9
8
 
10
9
  export { createBold };
package/bold/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 BOLD_TYPE = 'bold';
9
8
 
10
9
  const createBold = (variant) => toggleMark.createToggleMarkCreator({
11
- type: core.getVariantType(BOLD_TYPE, variant),
12
- parentType: BOLD_TYPE,
10
+ type: BOLD_TYPE,
11
+ variant,
13
12
  });
14
13
 
15
14
  exports.BOLD_TYPE = BOLD_TYPE;
@@ -14,7 +14,7 @@ function createDivider(options = {}) {
14
14
  insertDivider,
15
15
  with(editor) {
16
16
  const { isVoid, normalizeNode } = editor;
17
- editor.isVoid = (element) => element.type === type || isVoid(element);
17
+ editor.isVoid = element => element.type === type || isVoid(element);
18
18
  editor.normalizeNode = (entry) => {
19
19
  const [node, path] = entry;
20
20
  /**
@@ -19,7 +19,7 @@ function createDivider(options = {}) {
19
19
  insertDivider,
20
20
  with(editor) {
21
21
  const { isVoid, normalizeNode } = editor;
22
- editor.isVoid = (element) => element.type === type || isVoid(element);
22
+ editor.isVoid = element => element.type === type || isVoid(element);
23
23
  editor.normalizeNode = (entry) => {
24
24
  const [node, path] = entry;
25
25
  /**
@@ -1,8 +1,8 @@
1
- import { Editor, Element, Text, Withable, WithElementType } from '@quadrats/core';
2
- export interface DividerElement extends Element, WithElementType {
1
+ import { Editor, QuadratsElement, Text, Withable, WithElementType } from '@quadrats/core';
2
+ export interface DividerElement extends QuadratsElement, WithElementType {
3
3
  children: [Text];
4
4
  }
5
- export interface Divider extends WithElementType, Withable {
5
+ export interface Divider<T extends Editor = Editor> extends WithElementType, Withable {
6
6
  createDividerElement(): DividerElement;
7
- insertDivider(editor: Editor): void;
7
+ insertDivider(editor: T): void;
8
8
  }
@@ -11,7 +11,8 @@ function createEmbed(options) {
11
11
  const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
12
12
  Transforms.insertNodes(editor, [
13
13
  embedElement,
14
- typeof defaultNode === 'string' ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
14
+ typeof defaultNode === 'string'
15
+ ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
15
16
  ]);
16
17
  Transforms.move(editor);
17
18
  }
@@ -22,11 +23,12 @@ function createEmbed(options) {
22
23
  insertEmbed,
23
24
  with(editor) {
24
25
  const { isVoid, normalizeNode } = editor;
25
- editor.isVoid = (element) => element.type === type || isVoid(element);
26
+ editor.isVoid = element => element.type === type || isVoid(element);
26
27
  editor.normalizeNode = (entry) => {
27
28
  const [node, path] = entry;
28
29
  if (Element.isElement(node) && node.type === type) {
29
- const strategy = node.provider ? strategies[node.provider] : undefined;
30
+ const strategy = node.provider
31
+ ? strategies[node.provider] : undefined;
30
32
  if (!strategy || !strategy.isElementDataValid(node)) {
31
33
  Transforms.removeNodes(editor, { at: path });
32
34
  return;
@@ -33,7 +33,8 @@ function createEmbed(options) {
33
33
  const embedElement = Object.assign(Object.assign({}, data), { type, provider, children: [{ text: '' }] });
34
34
  core.Transforms.insertNodes(editor, [
35
35
  embedElement,
36
- typeof defaultNode === 'string' ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
36
+ typeof defaultNode === 'string'
37
+ ? { type: defaultNode, children: [{ text: '' }] } : defaultNode,
37
38
  ]);
38
39
  core.Transforms.move(editor);
39
40
  }
@@ -44,11 +45,12 @@ function createEmbed(options) {
44
45
  insertEmbed,
45
46
  with(editor) {
46
47
  const { isVoid, normalizeNode } = editor;
47
- editor.isVoid = (element) => element.type === type || isVoid(element);
48
+ editor.isVoid = element => element.type === type || isVoid(element);
48
49
  editor.normalizeNode = (entry) => {
49
50
  const [node, path] = entry;
50
51
  if (core.Element.isElement(node) && node.type === type) {
51
- const strategy = node.provider ? strategies[node.provider] : undefined;
52
+ const strategy = node.provider
53
+ ? strategies[node.provider] : undefined;
52
54
  if (!strategy || !strategy.isElementDataValid(node)) {
53
55
  core.Transforms.removeNodes(editor, { at: path });
54
56
  return;
@@ -1,5 +1,5 @@
1
- import { Editor, Element, Node, Text, Withable, WithElementType } from '@quadrats/core';
2
- export interface EmbedElement extends Element, WithElementType {
1
+ import { Editor, QuadratsElement, Node, Text, Withable, WithElementType } from '@quadrats/core';
2
+ export interface EmbedElement extends QuadratsElement, WithElementType {
3
3
  /**
4
4
  * The embed provider.
5
5
  *
@@ -20,7 +20,7 @@ export interface EmbedStrategy<EmbedData extends Record<string, unknown>, Render
20
20
  readonly isElementDataValid: (data: Record<keyof EmbedData, unknown>) => boolean;
21
21
  }
22
22
  export declare type EmbedStrategies<Provider extends string> = Record<Provider, EmbedStrategy<any, any>>;
23
- export interface Embed<P extends string> extends WithElementType, Withable {
23
+ export interface Embed<P extends string, T extends Editor = Editor> extends WithElementType, Withable {
24
24
  strategies: EmbedStrategies<P>;
25
- insertEmbed(editor: Editor, providers: P[], embedCode: string, defaultNode?: Node | string): void;
25
+ insertEmbed(editor: T, providers: P[], embedCode: string, defaultNode?: Node | string): void;
26
26
  }
@@ -1,5 +1,6 @@
1
+ import { Editor } from '@quadrats/core';
1
2
  import { FileUploader } from './typings';
2
3
  export interface CreateFileUploaderOptions {
3
4
  type?: string;
4
5
  }
5
- export declare function createFileUploader(options?: CreateFileUploaderOptions): FileUploader;
6
+ export declare function createFileUploader(options?: CreateFileUploaderOptions): FileUploader<Editor>;
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from './_virtual/_tslib.js';
2
2
  import { readFileAsDataURL } from '@quadrats/utils';
3
- import { HistoryEditor, Transforms, createParagraphElement } from '@quadrats/core';
3
+ import { Transforms, createParagraphElement } from '@quadrats/core';
4
4
  import { FILE_UPLOADER_TYPE } from './constants.js';
5
5
  import { getFilesFromInput } from './getFilesFromInput.js';
6
6
 
@@ -25,10 +25,8 @@ function createFileUploader(options = {}) {
25
25
  if (xhr.status < 400) {
26
26
  const path = getPath();
27
27
  if (path) {
28
- HistoryEditor.withoutSaving(editor, () => {
29
- Transforms.removeNodes(editor, { at: path });
30
- Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
31
- });
28
+ Transforms.removeNodes(editor, { at: path });
29
+ Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
32
30
  }
33
31
  }
34
32
  else {
@@ -65,10 +63,8 @@ function createFileUploader(options = {}) {
65
63
  yield prev;
66
64
  return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
67
65
  if (fileUploaderElement) {
68
- HistoryEditor.withoutSaving(editor, () => {
69
- Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], options);
70
- Transforms.move(editor);
71
- });
66
+ Transforms.insertNodes(editor, [fileUploaderElement, createParagraphElement()], options);
67
+ Transforms.move(editor);
72
68
  }
73
69
  });
74
70
  }), Promise.resolve());
@@ -78,8 +74,6 @@ function createFileUploader(options = {}) {
78
74
  createFileUploaderElement,
79
75
  upload,
80
76
  with(editor) {
81
- // const { isVoid } = editor;
82
- // editor.isVoid = element => element.type === type || isVoid(element);
83
77
  return editor;
84
78
  },
85
79
  };
@@ -79,10 +79,8 @@ function createFileUploader(options = {}) {
79
79
  if (xhr.status < 400) {
80
80
  const path = getPath();
81
81
  if (path) {
82
- core.HistoryEditor.withoutSaving(editor, () => {
83
- core.Transforms.removeNodes(editor, { at: path });
84
- core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
85
- });
82
+ core.Transforms.removeNodes(editor, { at: path });
83
+ core.Transforms.insertNodes(editor, createElementByResponse(xhr.response), { at: path });
86
84
  }
87
85
  }
88
86
  else {
@@ -119,10 +117,8 @@ function createFileUploader(options = {}) {
119
117
  yield prev;
120
118
  return createFileUploaderElement(editor, file, options).then((fileUploaderElement) => {
121
119
  if (fileUploaderElement) {
122
- core.HistoryEditor.withoutSaving(editor, () => {
123
- core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
124
- core.Transforms.move(editor);
125
- });
120
+ core.Transforms.insertNodes(editor, [fileUploaderElement, core.createParagraphElement()], options);
121
+ core.Transforms.move(editor);
126
122
  }
127
123
  });
128
124
  }), Promise.resolve());
@@ -132,8 +128,6 @@ function createFileUploader(options = {}) {
132
128
  createFileUploaderElement,
133
129
  upload,
134
130
  with(editor) {
135
- // const { isVoid } = editor;
136
- // editor.isVoid = element => element.type === type || isVoid(element);
137
131
  return editor;
138
132
  },
139
133
  };
@@ -1,20 +1,20 @@
1
- import { Editor, Element, HistoryEditor, Path, TransformsInsertNodesOptions, Withable } from '@quadrats/core';
1
+ import { Editor, QuadratsElement, Path, TransformsInsertNodesOptions, Withable } from '@quadrats/core';
2
2
  import { GetFilesFromInputOptions } from './getFilesFromInput';
3
3
  export interface XHRUploadHeaders {
4
4
  [name: string]: string;
5
5
  }
6
- export interface FileUploaderElement extends Element {
6
+ export interface FileUploaderElement extends QuadratsElement {
7
7
  type: string;
8
8
  register: (getPath: () => Path | undefined, onProgress: (percentage: number) => void) => VoidFunction;
9
9
  }
10
10
  /**
11
11
  * For creating temorary element while uploading.
12
12
  */
13
- export declare type FileUploaderCreateElementByDataURL = (dataURL: string) => Element;
13
+ export declare type FileUploaderCreateElementByDataURL = (dataURL: string) => QuadratsElement;
14
14
  /**
15
15
  * For create element after uploaded.
16
16
  */
17
- export declare type FileUploaderCreateElementByResponse = (response: any) => Element;
17
+ export declare type FileUploaderCreateElementByResponse = (response: any) => QuadratsElement;
18
18
  export declare type FileUploaderGetBody = (file: File) => BodyInit;
19
19
  export declare type FileUploaderGetHeaders = (file: File) => XHRUploadHeaders | Promise<XHRUploadHeaders>;
20
20
  export declare type FileUploaderGetUrl = (file: File) => string;
@@ -30,8 +30,8 @@ export interface FileUploaderCreateFileUploaderElementOptions {
30
30
  getUrl: FileUploaderGetUrl;
31
31
  }
32
32
  export declare type FileUploaderUploadOptions = FileUploaderCreateFileUploaderElementOptions & GetFilesFromInputOptions & TransformsInsertNodesOptions;
33
- export interface FileUploader extends Withable {
33
+ export interface FileUploader<T extends Editor = Editor> extends Withable {
34
34
  type: string;
35
- createFileUploaderElement(editor: Editor & HistoryEditor, file: File, options: FileUploaderCreateFileUploaderElementOptions): Promise<FileUploaderElement | undefined>;
36
- upload(editor: Editor & HistoryEditor, options: FileUploaderUploadOptions): Promise<void>;
35
+ createFileUploaderElement(editor: T, file: File, options: FileUploaderCreateFileUploaderElementOptions): Promise<FileUploaderElement | undefined>;
36
+ upload(editor: T, options: FileUploaderUploadOptions): Promise<void>;
37
37
  }
@@ -3,27 +3,20 @@ import { FOOTNOTE_TYPE } from './constants.js';
3
3
 
4
4
  /* eslint-disable max-len */
5
5
  function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
6
- const isSelectionInFootnote = (editor) => isNodesTypeIn(editor, [type]);
7
- const getAllFootnotes = (editor) => {
8
- const resultNodes = getNodes(editor, {
9
- at: [],
10
- match: (node) => node.type === FOOTNOTE_TYPE,
11
- });
12
- return Array.from(resultNodes);
13
- };
6
+ const isSelectionInFootnote = editor => isNodesTypeIn(editor, [type]);
14
7
  const getFootnoteText = (editor) => {
15
8
  var _a, _b, _c;
16
9
  const at = editor.selection;
17
10
  if (!at) {
18
11
  return '';
19
12
  }
20
- const nodes = getNodes(editor, { at, match: (node) => node.type === type });
21
- return (_c = (_b = (_a = Array.from(nodes)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.footnote;
13
+ const firstNode = (_b = (_a = Array.from(getNodes(editor, { at, match: node => node.type === type }))) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0];
14
+ return (_c = firstNode) === null || _c === void 0 ? void 0 : _c.footnote;
22
15
  };
23
16
  const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
24
17
  var _a;
25
18
  let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
26
- for (const [, path] of getNodes(editor, { at: [], match: (node) => node.type === FOOTNOTE_TYPE })) {
19
+ for (const [, path] of getNodes(editor, { at: [], match: node => node.type === FOOTNOTE_TYPE })) {
27
20
  Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
28
21
  footnoteCount += 1;
29
22
  }
@@ -48,7 +41,7 @@ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
48
41
  }
49
42
  if (footnoteText !== '') {
50
43
  if (isSelectionInFootnote(editor)) {
51
- Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: (node) => node.type === type });
44
+ Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: node => node.type === type });
52
45
  }
53
46
  else {
54
47
  wrapFootnote(editor, footnoteText, options);
@@ -61,7 +54,6 @@ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
61
54
  };
62
55
  return {
63
56
  type,
64
- getAllFootnotes,
65
57
  getFootnoteText,
66
58
  isSelectionInFootnote,
67
59
  updateFootnoteIndex,
@@ -70,7 +62,7 @@ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
70
62
  upsertFootnoteAndUpdateIndex,
71
63
  with(editor) {
72
64
  const { isInline } = editor;
73
- editor.isInline = (element) => element.type === type || isInline(element);
65
+ editor.isInline = element => element.type === type || isInline(element);
74
66
  return editor;
75
67
  },
76
68
  };
@@ -8,27 +8,20 @@ const FOOTNOTE_TYPE = 'footnote';
8
8
 
9
9
  /* eslint-disable max-len */
10
10
  function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
11
- const isSelectionInFootnote = (editor) => core.isNodesTypeIn(editor, [type]);
12
- const getAllFootnotes = (editor) => {
13
- const resultNodes = core.getNodes(editor, {
14
- at: [],
15
- match: (node) => node.type === FOOTNOTE_TYPE,
16
- });
17
- return Array.from(resultNodes);
18
- };
11
+ const isSelectionInFootnote = editor => core.isNodesTypeIn(editor, [type]);
19
12
  const getFootnoteText = (editor) => {
20
13
  var _a, _b, _c;
21
14
  const at = editor.selection;
22
15
  if (!at) {
23
16
  return '';
24
17
  }
25
- const nodes = core.getNodes(editor, { at, match: (node) => node.type === type });
26
- return (_c = (_b = (_a = Array.from(nodes)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.footnote;
18
+ const firstNode = (_b = (_a = Array.from(core.getNodes(editor, { at, match: node => node.type === type }))) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0];
19
+ return (_c = firstNode) === null || _c === void 0 ? void 0 : _c.footnote;
27
20
  };
28
21
  const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
29
22
  var _a;
30
23
  let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
31
- for (const [, path] of core.getNodes(editor, { at: [], match: (node) => node.type === FOOTNOTE_TYPE })) {
24
+ for (const [, path] of core.getNodes(editor, { at: [], match: node => node.type === FOOTNOTE_TYPE })) {
32
25
  core.Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
33
26
  footnoteCount += 1;
34
27
  }
@@ -53,7 +46,7 @@ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
53
46
  }
54
47
  if (footnoteText !== '') {
55
48
  if (isSelectionInFootnote(editor)) {
56
- core.Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: (node) => node.type === type });
49
+ core.Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: node => node.type === type });
57
50
  }
58
51
  else {
59
52
  wrapFootnote(editor, footnoteText, options);
@@ -66,7 +59,6 @@ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
66
59
  };
67
60
  return {
68
61
  type,
69
- getAllFootnotes,
70
62
  getFootnoteText,
71
63
  isSelectionInFootnote,
72
64
  updateFootnoteIndex,
@@ -75,7 +67,7 @@ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
75
67
  upsertFootnoteAndUpdateIndex,
76
68
  with(editor) {
77
69
  const { isInline } = editor;
78
- editor.isInline = (element) => element.type === type || isInline(element);
70
+ editor.isInline = element => element.type === type || isInline(element);
79
71
  return editor;
80
72
  },
81
73
  };
@@ -1,5 +1,10 @@
1
- import { Editor, Range, Element, WithElementType, UnwrapNodeByTypesOptions, TransformsWrapNodesOptions, Withable, NodeEntry, Node } from '@quadrats/core';
2
- export interface FootnoteElement extends Element, WithElementType {
1
+ import { Editor, Range, QuadratsElement, WithElementType, UnwrapNodeByTypesOptions, TransformsWrapNodesOptions, Withable } from '@quadrats/core';
2
+ export interface FootnoteData {
3
+ footnote: string;
4
+ index: number;
5
+ wrapperText: string;
6
+ }
7
+ export interface FootnoteElement extends QuadratsElement, WithElementType {
3
8
  footnote: string;
4
9
  index?: number;
5
10
  }
@@ -13,12 +18,11 @@ export interface FootnoteWrapFootnoteOptions extends Omit<TransformsWrapNodesOpt
13
18
  export interface FootnoteUpsertFootnoteOptions {
14
19
  at?: Range;
15
20
  }
16
- export interface Footnote extends WithElementType, Withable {
17
- getAllFootnotes(editor: Editor): NodeEntry<Node>[];
18
- getFootnoteText(editor: Editor): string;
19
- isSelectionInFootnote(editor: Editor): boolean;
20
- unwrapFootnote(editor: Editor, options?: FootnoteUnwrapFootnoteOptions): void;
21
- updateFootnoteIndex(editor: Editor, options?: FootnoteUpdateFootnoteIndexOptions): void;
22
- upsertFootnoteAndUpdateIndex(editor: Editor, footnote: string, options?: FootnoteUpsertFootnoteOptions): void;
23
- wrapFootnote(editor: Editor, footnote: string, options?: FootnoteWrapFootnoteOptions): void;
21
+ export interface Footnote<T extends Editor = Editor> extends WithElementType, Withable {
22
+ getFootnoteText(editor: T): string;
23
+ isSelectionInFootnote(editor: T): boolean;
24
+ unwrapFootnote(editor: T, options?: FootnoteUnwrapFootnoteOptions): void;
25
+ updateFootnoteIndex(editor: T, options?: FootnoteUpdateFootnoteIndexOptions): void;
26
+ upsertFootnoteAndUpdateIndex(editor: T, footnote: string, options?: FootnoteUpsertFootnoteOptions): void;
27
+ wrapFootnote(editor: T, footnote: string, options?: FootnoteWrapFootnoteOptions): void;
24
28
  }
@@ -2,7 +2,7 @@ import { Element, Transforms, PARAGRAPH_TYPE, normalizeOnlyInlineOrTextInChildre
2
2
  import { HEADING_TYPE, HEADING_LEVELS } from './constants.js';
3
3
 
4
4
  function createHeading({ type = HEADING_TYPE, enabledLevels = HEADING_LEVELS, } = {}) {
5
- const getHeadingNodes = (editor, level, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === type && node.level === level }));
5
+ const getHeadingNodes = (editor, level, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: node => node.type === type && node.level === level }));
6
6
  const isSelectionInHeading = (editor, level, options = {}) => {
7
7
  const [match] = getHeadingNodes(editor, level, options);
8
8
  return !!match;
@@ -8,7 +8,7 @@ const HEADING_TYPE = 'heading';
8
8
  const HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
9
9
 
10
10
  function createHeading({ type = HEADING_TYPE, enabledLevels = HEADING_LEVELS, } = {}) {
11
- const getHeadingNodes = (editor, level, options = {}) => core.getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === type && node.level === level }));
11
+ const getHeadingNodes = (editor, level, options = {}) => core.getNodes(editor, Object.assign(Object.assign({}, options), { match: node => node.type === type && node.level === level }));
12
12
  const isSelectionInHeading = (editor, level, options = {}) => {
13
13
  const [match] = getHeadingNodes(editor, level, options);
14
14
  return !!match;
@@ -1,6 +1,6 @@
1
- import { Editor, Element, GetNodesOptions, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
1
+ import { Editor, QuadratsElement, GetNodesOptions, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
2
2
  export declare type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
3
- export interface HeadingElement extends Element, WithElementType {
3
+ export interface HeadingElement extends QuadratsElement, WithElementType {
4
4
  level: HeadingLevel;
5
5
  }
6
6
  export interface WithEnabledHeadingLevels<L extends HeadingLevel> {
@@ -9,8 +9,8 @@ export interface WithEnabledHeadingLevels<L extends HeadingLevel> {
9
9
  */
10
10
  enabledLevels: ReadonlyArray<L>;
11
11
  }
12
- export interface Heading<L extends HeadingLevel> extends WithElementType, Withable, WithEnabledHeadingLevels<L> {
13
- getHeadingNodes(editor: Editor, level: L, options?: GetNodesOptions): Generator<NodeEntry<Node>>;
14
- isSelectionInHeading(editor: Editor, level: L, options?: GetNodesOptions): boolean;
15
- toggleHeadingNodes(editor: Editor, level: L, defaultType?: string): void;
12
+ export interface Heading<L extends HeadingLevel, T extends Editor = Editor> extends WithElementType, Withable, WithEnabledHeadingLevels<L> {
13
+ getHeadingNodes(editor: T, level: L, options?: GetNodesOptions): Generator<NodeEntry<Node>>;
14
+ isSelectionInHeading(editor: T, level: L, options?: GetNodesOptions): boolean;
15
+ toggleHeadingNodes(editor: T, level: L, defaultType?: string): void;
16
16
  }
@@ -1 +1 @@
1
- export declare const createHighlight: (variant?: string | undefined) => ({ type, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
1
+ export declare const createHighlight: (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 { HIGHLIGHT_TYPE } from './constants.js';
4
3
 
5
4
  const createHighlight = (variant) => createToggleMarkCreator({
6
- type: getVariantType(HIGHLIGHT_TYPE, variant),
7
- parentType: HIGHLIGHT_TYPE,
5
+ type: HIGHLIGHT_TYPE,
6
+ variant,
8
7
  });
9
8
 
10
9
  export { createHighlight };
@@ -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 HIGHLIGHT_TYPE = 'highlight';
9
8
 
10
9
  const createHighlight = (variant) => toggleMark.createToggleMarkCreator({
11
- type: core.getVariantType(HIGHLIGHT_TYPE, variant),
12
- parentType: HIGHLIGHT_TYPE,
10
+ type: HIGHLIGHT_TYPE,
11
+ variant,
13
12
  });
14
13
 
15
14
  exports.HIGHLIGHT_TYPE = HIGHLIGHT_TYPE;
@@ -3,7 +3,7 @@ import { getAboveByTypes, Element, isNodesTypeIn, Transforms, normalizeVoidEleme
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,9 +16,9 @@ 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,
@@ -51,7 +51,7 @@ function createImage(options = {}) {
51
51
  if (!sizeSteps) {
52
52
  return percentage;
53
53
  }
54
- const lowerIndex = sizeSteps.findIndex((step) => step >= percentage) - 1;
54
+ const lowerIndex = sizeSteps.findIndex(step => step >= percentage) - 1;
55
55
  const upperIndex = lowerIndex + 1;
56
56
  if (lowerIndex < 0) {
57
57
  return sizeSteps[0];
@@ -119,7 +119,7 @@ function createImage(options = {}) {
119
119
  }
120
120
  insertBreak();
121
121
  };
122
- editor.isVoid = (element) => element.type === types.image || isVoid(element);
122
+ editor.isVoid = element => element.type === types.image || isVoid(element);
123
123
  editor.normalizeNode = (entry) => {
124
124
  const [node, path] = entry;
125
125
  if (Element.isElement(node)) {