@quadrats/common 0.0.2 → 0.4.5

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 (52) hide show
  1. package/blockquote/createBlockquote.js +1 -1
  2. package/bold/createBold.d.ts +1 -1
  3. package/bold/createBold.js +3 -2
  4. package/bold/index.cjs.js +2 -1
  5. package/divider/createDivider.js +1 -1
  6. package/embed/createEmbed.js +1 -1
  7. package/embed/strategies/podcast-apple/index.cjs.js +22 -0
  8. package/embed/strategies/podcast-apple/index.d.ts +9 -0
  9. package/embed/strategies/podcast-apple/index.js +18 -0
  10. package/embed/strategies/podcast-apple/package.json +7 -0
  11. package/embed/strategies/spotify/index.cjs.js +21 -0
  12. package/embed/strategies/spotify/index.d.ts +9 -0
  13. package/embed/strategies/spotify/index.js +17 -0
  14. package/embed/strategies/spotify/package.json +7 -0
  15. package/embed/strategies/twitter/index.cjs.js +10 -10
  16. package/embed/strategies/twitter/index.d.ts +1 -2
  17. package/embed/strategies/twitter/index.js +10 -10
  18. package/file-uploader/createFileUploader.js +2 -2
  19. package/footnote/constants.d.ts +1 -0
  20. package/footnote/constants.js +3 -0
  21. package/footnote/createFootnote.d.ts +4 -0
  22. package/footnote/createFootnote.js +71 -0
  23. package/footnote/index.cjs.js +77 -0
  24. package/footnote/index.d.ts +3 -0
  25. package/footnote/index.js +2 -0
  26. package/footnote/package.json +7 -0
  27. package/footnote/typings.d.ts +28 -0
  28. package/heading/createHeading.js +1 -1
  29. package/highlight/createHighlight.d.ts +1 -1
  30. package/highlight/createHighlight.js +3 -2
  31. package/highlight/index.cjs.js +2 -1
  32. package/image/createImage.js +1 -1
  33. package/input-block/createInputBlock.js +7 -2
  34. package/input-block/index.cjs.js +6 -1
  35. package/input-widget/typings.d.ts +1 -0
  36. package/italic/createItalic.d.ts +1 -1
  37. package/italic/createItalic.js +3 -2
  38. package/italic/index.cjs.js +2 -1
  39. package/link/createLink.js +14 -2
  40. package/link/index.cjs.js +12 -0
  41. package/list/createList.js +1 -1
  42. package/package.json +4 -4
  43. package/read-more/createReadMore.js +1 -1
  44. package/strikethrough/createStrikethrough.d.ts +1 -1
  45. package/strikethrough/createStrikethrough.js +3 -2
  46. package/strikethrough/index.cjs.js +2 -1
  47. package/toggle-mark/createToggleMarkCreator.d.ts +7 -3
  48. package/toggle-mark/createToggleMarkCreator.js +17 -2
  49. package/toggle-mark/index.cjs.js +17 -2
  50. package/underline/createUnderline.d.ts +1 -1
  51. package/underline/createUnderline.js +3 -2
  52. package/underline/index.cjs.js +2 -1
@@ -1,5 +1,5 @@
1
- import { BLOCKQUOTE_TYPE } from './constants.js';
2
1
  import { isNodesTypeIn, toggleNodesType, Element, normalizeOnlyInlineOrTextInChildren } from '@quadrats/core';
2
+ import { BLOCKQUOTE_TYPE } from './constants.js';
3
3
 
4
4
  function createBlockquote({ type = BLOCKQUOTE_TYPE } = {}) {
5
5
  return {
@@ -1 +1 @@
1
- export declare const createBold: ({ type }?: Partial<import("@quadrats/core").WithMarkType> | 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;
@@ -1,8 +1,9 @@
1
- import { BOLD_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { BOLD_TYPE } from './constants.js';
3
3
 
4
- const createBold = createToggleMarkCreator({
4
+ const createBold = (variant) => createToggleMarkCreator({
5
5
  type: BOLD_TYPE,
6
+ variant,
6
7
  });
7
8
 
8
9
  export { createBold };
package/bold/index.cjs.js CHANGED
@@ -6,8 +6,9 @@ var toggleMark = require('@quadrats/common/toggle-mark');
6
6
 
7
7
  const BOLD_TYPE = 'bold';
8
8
 
9
- const createBold = toggleMark.createToggleMarkCreator({
9
+ const createBold = (variant) => toggleMark.createToggleMarkCreator({
10
10
  type: BOLD_TYPE,
11
+ variant,
11
12
  });
12
13
 
13
14
  exports.BOLD_TYPE = BOLD_TYPE;
@@ -1,5 +1,5 @@
1
- import { DIVIDER_TYPE } from './constants.js';
2
1
  import { Element, normalizeVoidElementChildren, Transforms, createParagraphElement } from '@quadrats/core';
2
+ import { DIVIDER_TYPE } from './constants.js';
3
3
 
4
4
  function createDivider(options = {}) {
5
5
  const { type = DIVIDER_TYPE } = options;
@@ -1,6 +1,6 @@
1
+ import { Element, Transforms, normalizeVoidElementChildren, PARAGRAPH_TYPE } from '@quadrats/core';
1
2
  import { EMBED_TYPE } from './constants.js';
2
3
  import { serializeEmbedCode } from './serializeEmbedCode.js';
3
- import { Element, Transforms, normalizeVoidElementChildren, PARAGRAPH_TYPE } from '@quadrats/core';
4
4
 
5
5
  function createEmbed(options) {
6
6
  const { type = EMBED_TYPE, strategies } = options;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
6
+ const PodcastAppleEmbedStrategy = {
7
+ serialize: (embedCode) => {
8
+ var _a, _b;
9
+ 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);
10
+ if (result) {
11
+ const [, contextId] = result;
12
+ return {
13
+ embedType: 'podcast-apple',
14
+ contextId,
15
+ };
16
+ }
17
+ },
18
+ deserialize: (data) => `https://embed.podcasts.apple.com/us/podcast/id${data.contextId}`,
19
+ isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
20
+ };
21
+
22
+ exports.PodcastAppleEmbedStrategy = PodcastAppleEmbedStrategy;
@@ -0,0 +1,9 @@
1
+ import { EmbedElement, EmbedStrategy } from '@quadrats/common/embed';
2
+ export declare type PodcastAppleEmbedType = 'podcast-apple';
3
+ export declare type PodcastAppleEmbedElementData = {
4
+ embedType: PodcastAppleEmbedType;
5
+ contextId: string;
6
+ };
7
+ export declare type PodcastAppleEmbedElement = EmbedElement & PodcastAppleEmbedElementData;
8
+ export declare type PodcastAppleEmbedStrategy = EmbedStrategy<PodcastAppleEmbedElementData, string>;
9
+ export declare const PodcastAppleEmbedStrategy: PodcastAppleEmbedStrategy;
@@ -0,0 +1,18 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
2
+ const PodcastAppleEmbedStrategy = {
3
+ serialize: (embedCode) => {
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);
6
+ if (result) {
7
+ const [, contextId] = result;
8
+ return {
9
+ embedType: 'podcast-apple',
10
+ contextId,
11
+ };
12
+ }
13
+ },
14
+ deserialize: (data) => `https://embed.podcasts.apple.com/us/podcast/id${data.contextId}`,
15
+ isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
16
+ };
17
+
18
+ export { PodcastAppleEmbedStrategy };
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@quadrats/common/embed/strategies/podcast-apple",
3
+ "sideEffects": false,
4
+ "main": "./index.cjs.js",
5
+ "module": "./index.js",
6
+ "typings": "./index.d.ts"
7
+ }
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
6
+ const SpotifyEmbedStrategy = {
7
+ serialize: (embedCode) => {
8
+ const result = /^https:\/\/open.spotify.com\/([\S]*)/i.exec(embedCode);
9
+ if (result) {
10
+ const [, contextId] = result;
11
+ return {
12
+ embedType: 'spotify',
13
+ contextId,
14
+ };
15
+ }
16
+ },
17
+ deserialize: (data) => `https://open.spotify.com/embed/${data.contextId}?utm_source=generator`,
18
+ isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
19
+ };
20
+
21
+ exports.SpotifyEmbedStrategy = SpotifyEmbedStrategy;
@@ -0,0 +1,9 @@
1
+ import { EmbedElement, EmbedStrategy } from '@quadrats/common/embed';
2
+ export declare type SpotifyEmbedType = 'spotify';
3
+ export declare type SpotifyEmbedElementData = {
4
+ embedType: SpotifyEmbedType;
5
+ contextId: string;
6
+ };
7
+ export declare type SpotifyEmbedElement = EmbedElement & SpotifyEmbedElementData;
8
+ export declare type SpotifyEmbedStrategy = EmbedStrategy<SpotifyEmbedElementData, string>;
9
+ export declare const SpotifyEmbedStrategy: SpotifyEmbedStrategy;
@@ -0,0 +1,17 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
2
+ const SpotifyEmbedStrategy = {
3
+ serialize: (embedCode) => {
4
+ const result = /^https:\/\/open.spotify.com\/([\S]*)/i.exec(embedCode);
5
+ if (result) {
6
+ const [, contextId] = result;
7
+ return {
8
+ embedType: 'spotify',
9
+ contextId,
10
+ };
11
+ }
12
+ },
13
+ deserialize: (data) => `https://open.spotify.com/embed/${data.contextId}?utm_source=generator`,
14
+ isElementDataValid: (data) => typeof data.contextId === 'string' && !!(data.contextId),
15
+ };
16
+
17
+ export { SpotifyEmbedStrategy };
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@quadrats/common/embed/strategies/spotify",
3
+ "sideEffects": false,
4
+ "main": "./index.cjs.js",
5
+ "module": "./index.js",
6
+ "typings": "./index.d.ts"
7
+ }
@@ -3,13 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function getTwitterTweetDataFromUrl(url) {
6
- const result = /^https:\/\/twitter.com\/([\w]*)\/status\/([\w-]*)/i.exec(url);
6
+ const result = /^https:\/\/twitter.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
7
7
  if (result) {
8
- const [, account, hash] = result;
8
+ const [, tweetId] = result;
9
9
  return {
10
10
  embedType: 'tweet',
11
- account,
12
- hash,
11
+ tweetId,
13
12
  };
14
13
  }
15
14
  }
@@ -31,15 +30,16 @@ const TwitterEmbedStrategy = {
31
30
  const getter = embedCode.startsWith('<blockquote') ? getTwitterTweetDataFromBlockquote : getTwitterTweetDataFromUrl;
32
31
  return getter(embedCode);
33
32
  },
34
- deserialize: ({ embedType, account, hash }) => {
35
- if (embedType === 'tweet') {
36
- return `https://www.twitter.com/${account}/status/${hash}`;
33
+ deserialize: (data) => {
34
+ if (data.embedType === 'tweet') {
35
+ return data.tweetId;
37
36
  }
38
37
  return '';
39
38
  },
40
- isElementDataValid: ({ embedType, account, hash }) => {
41
- if (embedType === 'tweet') {
42
- return typeof account === 'string' && typeof hash === 'string';
39
+ isElementDataValid: (data) => {
40
+ if (data.embedType === 'tweet') {
41
+ const { tweetId } = data;
42
+ return typeof tweetId === 'string' && !!tweetId;
43
43
  }
44
44
  return true;
45
45
  },
@@ -2,8 +2,7 @@ import { EmbedElement, EmbedStrategy } from '@quadrats/common/embed';
2
2
  export declare type TwitterEmbedType = 'tweet';
3
3
  export declare type TwitterEmbedElementData = {
4
4
  embedType: TwitterEmbedType;
5
- account: string;
6
- hash?: string;
5
+ tweetId: string;
7
6
  };
8
7
  export declare type TwitterEmbedElement = EmbedElement & TwitterEmbedElementData;
9
8
  export declare type TwitterEmbedStrategy = EmbedStrategy<TwitterEmbedElementData, string>;
@@ -1,11 +1,10 @@
1
1
  function getTwitterTweetDataFromUrl(url) {
2
- const result = /^https:\/\/twitter.com\/([\w]*)\/status\/([\w-]*)/i.exec(url);
2
+ const result = /^https:\/\/twitter.com\/[\w]*\/status\/([\w-]*)/i.exec(url);
3
3
  if (result) {
4
- const [, account, hash] = result;
4
+ const [, tweetId] = result;
5
5
  return {
6
6
  embedType: 'tweet',
7
- account,
8
- hash,
7
+ tweetId,
9
8
  };
10
9
  }
11
10
  }
@@ -27,15 +26,16 @@ const TwitterEmbedStrategy = {
27
26
  const getter = embedCode.startsWith('<blockquote') ? getTwitterTweetDataFromBlockquote : getTwitterTweetDataFromUrl;
28
27
  return getter(embedCode);
29
28
  },
30
- deserialize: ({ embedType, account, hash }) => {
31
- if (embedType === 'tweet') {
32
- return `https://www.twitter.com/${account}/status/${hash}`;
29
+ deserialize: (data) => {
30
+ if (data.embedType === 'tweet') {
31
+ return data.tweetId;
33
32
  }
34
33
  return '';
35
34
  },
36
- isElementDataValid: ({ embedType, account, hash }) => {
37
- if (embedType === 'tweet') {
38
- return typeof account === 'string' && typeof hash === 'string';
35
+ isElementDataValid: (data) => {
36
+ if (data.embedType === 'tweet') {
37
+ const { tweetId } = data;
38
+ return typeof tweetId === 'string' && !!tweetId;
39
39
  }
40
40
  return true;
41
41
  },
@@ -1,8 +1,8 @@
1
- import { FILE_UPLOADER_TYPE } from './constants.js';
2
- import { getFilesFromInput } from './getFilesFromInput.js';
3
1
  import { __awaiter } from './_virtual/_tslib.js';
4
2
  import { readFileAsDataURL } from '@quadrats/utils';
5
3
  import { HistoryEditor, Transforms, createParagraphElement } from '@quadrats/core';
4
+ import { FILE_UPLOADER_TYPE } from './constants.js';
5
+ import { getFilesFromInput } from './getFilesFromInput.js';
6
6
 
7
7
  function createFileUploader(options = {}) {
8
8
  const { type = FILE_UPLOADER_TYPE } = options;
@@ -0,0 +1 @@
1
+ export declare const FOOTNOTE_TYPE = "footnote";
@@ -0,0 +1,3 @@
1
+ const FOOTNOTE_TYPE = 'footnote';
2
+
3
+ export { FOOTNOTE_TYPE };
@@ -0,0 +1,4 @@
1
+ import { WithElementType } from '@quadrats/core';
2
+ import { Footnote } from './typings';
3
+ export declare type CreateFootnoteOptions = Partial<WithElementType>;
4
+ export declare function createFootnote({ type, }?: CreateFootnoteOptions): Footnote;
@@ -0,0 +1,71 @@
1
+ import { isNodesTypeIn, getNodes, Transforms, unwrapNodesByTypes, wrapNodesWithUnhangRange } from '@quadrats/core';
2
+ import { FOOTNOTE_TYPE } from './constants.js';
3
+
4
+ /* eslint-disable max-len */
5
+ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
6
+ const isSelectionInFootnote = (editor) => isNodesTypeIn(editor, [type]);
7
+ const getFootnoteText = (editor) => {
8
+ var _a, _b, _c;
9
+ const at = editor.selection;
10
+ if (!at) {
11
+ return '';
12
+ }
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;
15
+ };
16
+ const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
17
+ var _a;
18
+ let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
19
+ for (const [, path] of getNodes(editor, { at: [], match: (node) => node.type === FOOTNOTE_TYPE })) {
20
+ Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
21
+ footnoteCount += 1;
22
+ }
23
+ };
24
+ const unwrapFootnote = (editor, options = {}) => {
25
+ unwrapNodesByTypes(editor, [type], options);
26
+ };
27
+ const wrapFootnote = (editor, footnoteText, options = {}) => {
28
+ var _a;
29
+ const footnote = {
30
+ type,
31
+ footnote: footnoteText,
32
+ index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
33
+ children: [],
34
+ };
35
+ wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
36
+ };
37
+ const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
38
+ const { at = editor.selection } = options;
39
+ if (!at) {
40
+ return;
41
+ }
42
+ if (footnoteText !== '') {
43
+ if (isSelectionInFootnote(editor)) {
44
+ Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: (node) => node.type === type });
45
+ }
46
+ else {
47
+ wrapFootnote(editor, footnoteText, options);
48
+ }
49
+ }
50
+ else {
51
+ unwrapFootnote(editor, { at });
52
+ }
53
+ updateFootnoteIndex(editor);
54
+ };
55
+ return {
56
+ type,
57
+ getFootnoteText,
58
+ isSelectionInFootnote,
59
+ updateFootnoteIndex,
60
+ unwrapFootnote,
61
+ wrapFootnote,
62
+ upsertFootnoteAndUpdateIndex,
63
+ with(editor) {
64
+ const { isInline } = editor;
65
+ editor.isInline = (element) => element.type === type || isInline(element);
66
+ return editor;
67
+ },
68
+ };
69
+ }
70
+
71
+ export { createFootnote };
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@quadrats/core');
6
+
7
+ const FOOTNOTE_TYPE = 'footnote';
8
+
9
+ /* eslint-disable max-len */
10
+ function createFootnote({ type = FOOTNOTE_TYPE, } = {}) {
11
+ const isSelectionInFootnote = (editor) => core.isNodesTypeIn(editor, [type]);
12
+ const getFootnoteText = (editor) => {
13
+ var _a, _b, _c;
14
+ const at = editor.selection;
15
+ if (!at) {
16
+ return '';
17
+ }
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;
20
+ };
21
+ const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
22
+ var _a;
23
+ let footnoteCount = (_a = options === null || options === void 0 ? void 0 : options.startAt) !== null && _a !== void 0 ? _a : 1;
24
+ for (const [, path] of core.getNodes(editor, { at: [], match: (node) => node.type === FOOTNOTE_TYPE })) {
25
+ core.Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
26
+ footnoteCount += 1;
27
+ }
28
+ };
29
+ const unwrapFootnote = (editor, options = {}) => {
30
+ core.unwrapNodesByTypes(editor, [type], options);
31
+ };
32
+ const wrapFootnote = (editor, footnoteText, options = {}) => {
33
+ var _a;
34
+ const footnote = {
35
+ type,
36
+ footnote: footnoteText,
37
+ index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
38
+ children: [],
39
+ };
40
+ core.wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
41
+ };
42
+ const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
43
+ const { at = editor.selection } = options;
44
+ if (!at) {
45
+ return;
46
+ }
47
+ if (footnoteText !== '') {
48
+ if (isSelectionInFootnote(editor)) {
49
+ core.Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: (node) => node.type === type });
50
+ }
51
+ else {
52
+ wrapFootnote(editor, footnoteText, options);
53
+ }
54
+ }
55
+ else {
56
+ unwrapFootnote(editor, { at });
57
+ }
58
+ updateFootnoteIndex(editor);
59
+ };
60
+ return {
61
+ type,
62
+ getFootnoteText,
63
+ isSelectionInFootnote,
64
+ updateFootnoteIndex,
65
+ unwrapFootnote,
66
+ wrapFootnote,
67
+ upsertFootnoteAndUpdateIndex,
68
+ with(editor) {
69
+ const { isInline } = editor;
70
+ editor.isInline = (element) => element.type === type || isInline(element);
71
+ return editor;
72
+ },
73
+ };
74
+ }
75
+
76
+ exports.FOOTNOTE_TYPE = FOOTNOTE_TYPE;
77
+ exports.createFootnote = createFootnote;
@@ -0,0 +1,3 @@
1
+ export * from './typings';
2
+ export * from './constants';
3
+ export { CreateFootnoteOptions, createFootnote } from './createFootnote';
@@ -0,0 +1,2 @@
1
+ export { FOOTNOTE_TYPE } from './constants.js';
2
+ export { createFootnote } from './createFootnote.js';
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@quadrats/common/footnote",
3
+ "sideEffects": false,
4
+ "main": "./index.cjs.js",
5
+ "module": "./index.js",
6
+ "typings": "./index.d.ts"
7
+ }
@@ -0,0 +1,28 @@
1
+ import { Editor, Range, Element, 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 Element, WithElementType {
8
+ footnote: string;
9
+ index?: number;
10
+ }
11
+ export interface FootnoteUpdateFootnoteIndexOptions {
12
+ startAt?: number;
13
+ }
14
+ export declare type FootnoteUnwrapFootnoteOptions = UnwrapNodeByTypesOptions;
15
+ export interface FootnoteWrapFootnoteOptions extends Omit<TransformsWrapNodesOptions, 'split'> {
16
+ index?: number;
17
+ }
18
+ export interface FootnoteUpsertFootnoteOptions {
19
+ at?: Range;
20
+ }
21
+ export interface Footnote extends WithElementType, Withable {
22
+ getFootnoteText(editor: Editor): string;
23
+ isSelectionInFootnote(editor: Editor): boolean;
24
+ unwrapFootnote(editor: Editor, options?: FootnoteUnwrapFootnoteOptions): void;
25
+ updateFootnoteIndex(editor: Editor, options?: FootnoteUpdateFootnoteIndexOptions): void;
26
+ upsertFootnoteAndUpdateIndex(editor: Editor, footnote: string, options?: FootnoteUpsertFootnoteOptions): void;
27
+ wrapFootnote(editor: Editor, footnote: string, options?: FootnoteWrapFootnoteOptions): void;
28
+ }
@@ -1,5 +1,5 @@
1
- import { HEADING_TYPE, HEADING_LEVELS } from './constants.js';
2
1
  import { Element, Transforms, PARAGRAPH_TYPE, normalizeOnlyInlineOrTextInChildren, getNodes } from '@quadrats/core';
2
+ import { HEADING_TYPE, HEADING_LEVELS } from './constants.js';
3
3
 
4
4
  function createHeading({ type = HEADING_TYPE, enabledLevels = HEADING_LEVELS, } = {}) {
5
5
  const getHeadingNodes = (editor, level, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === type && node.level === level }));
@@ -1 +1 @@
1
- export declare const createHighlight: ({ type }?: Partial<import("@quadrats/core").WithMarkType> | 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;
@@ -1,8 +1,9 @@
1
- import { HIGHLIGHT_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { HIGHLIGHT_TYPE } from './constants.js';
3
3
 
4
- const createHighlight = createToggleMarkCreator({
4
+ const createHighlight = (variant) => createToggleMarkCreator({
5
5
  type: HIGHLIGHT_TYPE,
6
+ variant,
6
7
  });
7
8
 
8
9
  export { createHighlight };
@@ -6,8 +6,9 @@ var toggleMark = require('@quadrats/common/toggle-mark');
6
6
 
7
7
  const HIGHLIGHT_TYPE = 'highlight';
8
8
 
9
- const createHighlight = toggleMark.createToggleMarkCreator({
9
+ const createHighlight = (variant) => toggleMark.createToggleMarkCreator({
10
10
  type: HIGHLIGHT_TYPE,
11
+ variant,
11
12
  });
12
13
 
13
14
  exports.HIGHLIGHT_TYPE = HIGHLIGHT_TYPE;
@@ -1,6 +1,6 @@
1
- import { IMAGE_TYPES } from './constants.js';
2
1
  import { isImageUrl } from '@quadrats/utils';
3
2
  import { getAboveByTypes, Element, isNodesTypeIn, Transforms, normalizeVoidElementChildren, normalizeOnlyInlineOrTextInChildren, Range, createParagraphElement, Editor } from '@quadrats/core';
3
+ import { IMAGE_TYPES } from './constants.js';
4
4
 
5
5
  function resolveSizeSteps(steps) {
6
6
  let sortedSteps = steps.filter((step) => step > 0 && step < 100).sort();
@@ -1,5 +1,5 @@
1
- import { INPUT_BLOCK_TYPE } from './constants.js';
2
1
  import { Editor, Path, Transforms } from '@quadrats/core';
2
+ import { INPUT_BLOCK_TYPE } from './constants.js';
3
3
 
4
4
  function createInputBlock(options = {}) {
5
5
  const { type = INPUT_BLOCK_TYPE } = options;
@@ -28,7 +28,12 @@ function createInputBlock(options = {}) {
28
28
  confirm,
29
29
  with(editor) {
30
30
  const { isVoid } = editor;
31
- editor.isVoid = (element) => element.type === type || isVoid(element);
31
+ editor.isVoid = (element) => {
32
+ // invalidate unfinished input_block from storage
33
+ if (element.type === type && typeof element.getPlaceholder !== 'function')
34
+ return false;
35
+ return element.type === type || isVoid(element);
36
+ };
32
37
  return editor;
33
38
  },
34
39
  };
@@ -33,7 +33,12 @@ function createInputBlock(options = {}) {
33
33
  confirm,
34
34
  with(editor) {
35
35
  const { isVoid } = editor;
36
- editor.isVoid = (element) => element.type === type || isVoid(element);
36
+ editor.isVoid = (element) => {
37
+ // invalidate unfinished input_block from storage
38
+ if (element.type === type && typeof element.getPlaceholder !== 'function')
39
+ return false;
40
+ return element.type === type || isVoid(element);
41
+ };
37
42
  return editor;
38
43
  },
39
44
  };
@@ -11,5 +11,6 @@ export interface InputWidgetConfig {
11
11
  * Invoked after user confirming the input widget.
12
12
  */
13
13
  confirm(value: string): void;
14
+ defaultValue?: string;
14
15
  }
15
16
  export declare type SetInputWidgetConfig = (value: InputWidgetConfig | null) => void;
@@ -1 +1 @@
1
- export declare const createItalic: ({ type }?: Partial<import("@quadrats/core").WithMarkType> | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
1
+ export declare const createItalic: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,9 @@
1
- import { ITALIC_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { ITALIC_TYPE } from './constants.js';
3
3
 
4
- const createItalic = createToggleMarkCreator({
4
+ const createItalic = (variant) => createToggleMarkCreator({
5
5
  type: ITALIC_TYPE,
6
+ variant,
6
7
  });
7
8
 
8
9
  export { createItalic };
@@ -6,8 +6,9 @@ var toggleMark = require('@quadrats/common/toggle-mark');
6
6
 
7
7
  const ITALIC_TYPE = 'italic';
8
8
 
9
- const createItalic = toggleMark.createToggleMarkCreator({
9
+ const createItalic = (variant) => toggleMark.createToggleMarkCreator({
10
10
  type: ITALIC_TYPE,
11
+ variant,
11
12
  });
12
13
 
13
14
  exports.ITALIC_TYPE = ITALIC_TYPE;
@@ -1,6 +1,6 @@
1
- import { LINK_TYPE } from './constants.js';
2
1
  import { isUrl } from '@quadrats/utils';
3
- import { Range, unwrapNodesByTypes, Editor, Element, Transforms, getRangeBeforeFromAboveBlockStart, getRangeBefore, isNodesTypeIn, wrapNodesWithUnhangRange, Text, getAboveByTypes } from '@quadrats/core';
2
+ import { Range, unwrapNodesByTypes, Editor, Element, Transforms, Text, getRangeBeforeFromAboveBlockStart, getRangeBefore, isNodesTypeIn, wrapNodesWithUnhangRange, getAboveByTypes } from '@quadrats/core';
3
+ import { LINK_TYPE } from './constants.js';
4
4
 
5
5
  function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAfterSpaceEntered = true, wrappableVoidTypes, } = {}) {
6
6
  const getFirstPrevTextAsUrlAndRange = (editor, at) => {
@@ -66,6 +66,9 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
66
66
  unwrapLink(editor, { at: wrappableVoidPath });
67
67
  wrapLink(editor, url, { at: wrappableVoidPath });
68
68
  }
69
+ else {
70
+ insertLink(editor, url, { at });
71
+ }
69
72
  return;
70
73
  }
71
74
  }
@@ -129,6 +132,15 @@ function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAft
129
132
  Transforms.unwrapNodes(editor, { at: path });
130
133
  return;
131
134
  }
135
+ /**
136
+ * Remove empty content.
137
+ */
138
+ if (Text.isTextList(node.children)) {
139
+ if (node.children.every((textNode) => !textNode.text)) {
140
+ Transforms.unwrapNodes(editor, { at: path });
141
+ return;
142
+ }
143
+ }
132
144
  }
133
145
  normalizeNode(entry);
134
146
  };
package/link/index.cjs.js CHANGED
@@ -71,6 +71,9 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
71
71
  unwrapLink(editor, { at: wrappableVoidPath });
72
72
  wrapLink(editor, url, { at: wrappableVoidPath });
73
73
  }
74
+ else {
75
+ insertLink(editor, url, { at });
76
+ }
74
77
  return;
75
78
  }
76
79
  }
@@ -134,6 +137,15 @@ function createLink({ type = LINK_TYPE, isUrl = utils.isUrl, prevUrlToLinkAfterS
134
137
  core.Transforms.unwrapNodes(editor, { at: path });
135
138
  return;
136
139
  }
140
+ /**
141
+ * Remove empty content.
142
+ */
143
+ if (core.Text.isTextList(node.children)) {
144
+ if (node.children.every((textNode) => !textNode.text)) {
145
+ core.Transforms.unwrapNodes(editor, { at: path });
146
+ return;
147
+ }
148
+ }
137
149
  }
138
150
  normalizeNode(entry);
139
151
  };
@@ -1,5 +1,5 @@
1
- import { LIST_TYPES } from './constants.js';
2
1
  import { Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms, isNodesTypeIn, getAboveByTypes, getParent, unwrapNodesByTypes, PARAGRAPH_TYPE, wrapNodesWithUnhangRange, getNodesByTypes, isFirstChild, Editor, Path } from '@quadrats/core';
2
+ import { LIST_TYPES } from './constants.js';
3
3
 
4
4
  function createList(options = {}) {
5
5
  const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadrats/common",
3
- "version": "0.0.2",
3
+ "version": "0.4.5",
4
4
  "description": "",
5
5
  "author": "Rytass",
6
6
  "homepage": "https://github.com/Quadrats/quadrats#readme",
@@ -18,8 +18,8 @@
18
18
  "url": "https://github.com/Quadrats/quadrats/issues"
19
19
  },
20
20
  "dependencies": {
21
- "@quadrats/core": "^0.0.2",
22
- "@quadrats/locales": "^0.0.2",
23
- "@quadrats/utils": "^0.0.2"
21
+ "@quadrats/core": "^0.4.5",
22
+ "@quadrats/locales": "^0.4.0",
23
+ "@quadrats/utils": "^0.4.0"
24
24
  }
25
25
  }
@@ -1,5 +1,5 @@
1
- import { READ_MORE_TYPE } from './constants.js';
2
1
  import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot, getNodesByTypes, Path, Transforms, deleteSelectionFragmentIfExpanded, createParagraphElement } from '@quadrats/core';
2
+ import { READ_MORE_TYPE } from './constants.js';
3
3
 
4
4
  function createReadMore(options = {}) {
5
5
  const { type = READ_MORE_TYPE } = options;
@@ -1 +1 @@
1
- export declare const createStrikethrough: ({ type }?: Partial<import("@quadrats/core").WithMarkType> | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
1
+ export declare const createStrikethrough: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,9 @@
1
- import { STRIKETHROUGH_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { STRIKETHROUGH_TYPE } from './constants.js';
3
3
 
4
- const createStrikethrough = createToggleMarkCreator({
4
+ const createStrikethrough = (variant) => createToggleMarkCreator({
5
5
  type: STRIKETHROUGH_TYPE,
6
+ variant,
6
7
  });
7
8
 
8
9
  export { createStrikethrough };
@@ -6,8 +6,9 @@ var toggleMark = require('@quadrats/common/toggle-mark');
6
6
 
7
7
  const STRIKETHROUGH_TYPE = 'strikethrough';
8
8
 
9
- const createStrikethrough = toggleMark.createToggleMarkCreator({
9
+ const createStrikethrough = (variant) => toggleMark.createToggleMarkCreator({
10
10
  type: STRIKETHROUGH_TYPE,
11
+ variant,
11
12
  });
12
13
 
13
14
  exports.STRIKETHROUGH_TYPE = STRIKETHROUGH_TYPE;
@@ -1,5 +1,9 @@
1
1
  import { WithMarkType } from '@quadrats/core';
2
2
  import { ToggleMark } from './typings';
3
- export declare type CreateToggleMarkCreatorOptions = WithMarkType;
4
- export declare type CreateToggleMarkOptions = Partial<CreateToggleMarkCreatorOptions>;
5
- export declare function createToggleMarkCreator(defaults: CreateToggleMarkCreatorOptions): ({ type }?: CreateToggleMarkOptions) => ToggleMark;
3
+ export declare type CreateToggleMarkCreatorOptions = WithMarkType & {
4
+ variant?: string;
5
+ };
6
+ export declare type CreateToggleMarkOptions = Partial<CreateToggleMarkCreatorOptions> & {
7
+ variant?: string;
8
+ };
9
+ export declare function createToggleMarkCreator(defaults: CreateToggleMarkCreatorOptions): ({ type, variant }?: CreateToggleMarkOptions) => ToggleMark;
@@ -1,18 +1,33 @@
1
1
  import { getMark } from '@quadrats/core';
2
2
 
3
3
  function createToggleMarkCreator(defaults) {
4
- return ({ type = defaults.type } = {}) => {
4
+ return ({ type = defaults.type, variant = defaults.variant } = {}) => {
5
5
  const isToggleMarkActive = (editor) => {
6
6
  const mark = getMark(editor, type);
7
- return mark === true;
7
+ if (mark !== true)
8
+ return false;
9
+ const nowVariant = getMark(editor, `${type}Variant`) || '';
10
+ if (variant) {
11
+ return nowVariant === variant;
12
+ }
13
+ return !nowVariant;
8
14
  };
9
15
  const toggleMark = (editor) => {
10
16
  const isActive = isToggleMarkActive(editor);
11
17
  if (isActive) {
12
18
  editor.removeMark(type);
19
+ if (variant) {
20
+ editor.removeMark(`${type}Variant`);
21
+ }
13
22
  }
14
23
  else {
15
24
  editor.addMark(type, true);
25
+ if (variant) {
26
+ editor.addMark(`${type}Variant`, variant);
27
+ }
28
+ else {
29
+ editor.removeMark(`${type}Variant`);
30
+ }
16
31
  }
17
32
  };
18
33
  return {
@@ -5,18 +5,33 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@quadrats/core');
6
6
 
7
7
  function createToggleMarkCreator(defaults) {
8
- return ({ type = defaults.type } = {}) => {
8
+ return ({ type = defaults.type, variant = defaults.variant } = {}) => {
9
9
  const isToggleMarkActive = (editor) => {
10
10
  const mark = core.getMark(editor, type);
11
- return mark === true;
11
+ if (mark !== true)
12
+ return false;
13
+ const nowVariant = core.getMark(editor, `${type}Variant`) || '';
14
+ if (variant) {
15
+ return nowVariant === variant;
16
+ }
17
+ return !nowVariant;
12
18
  };
13
19
  const toggleMark = (editor) => {
14
20
  const isActive = isToggleMarkActive(editor);
15
21
  if (isActive) {
16
22
  editor.removeMark(type);
23
+ if (variant) {
24
+ editor.removeMark(`${type}Variant`);
25
+ }
17
26
  }
18
27
  else {
19
28
  editor.addMark(type, true);
29
+ if (variant) {
30
+ editor.addMark(`${type}Variant`, variant);
31
+ }
32
+ else {
33
+ editor.removeMark(`${type}Variant`);
34
+ }
20
35
  }
21
36
  };
22
37
  return {
@@ -1 +1 @@
1
- export declare const createUnderline: ({ type }?: Partial<import("@quadrats/core").WithMarkType> | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
1
+ export declare const createUnderline: (variant?: string | undefined) => ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,9 @@
1
- import { UNDERLINE_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { UNDERLINE_TYPE } from './constants.js';
3
3
 
4
- const createUnderline = createToggleMarkCreator({
4
+ const createUnderline = (variant) => createToggleMarkCreator({
5
5
  type: UNDERLINE_TYPE,
6
+ variant,
6
7
  });
7
8
 
8
9
  export { createUnderline };
@@ -6,8 +6,9 @@ var toggleMark = require('@quadrats/common/toggle-mark');
6
6
 
7
7
  const UNDERLINE_TYPE = 'underline';
8
8
 
9
- const createUnderline = toggleMark.createToggleMarkCreator({
9
+ const createUnderline = (variant) => toggleMark.createToggleMarkCreator({
10
10
  type: UNDERLINE_TYPE,
11
+ variant,
11
12
  });
12
13
 
13
14
  exports.UNDERLINE_TYPE = UNDERLINE_TYPE;