@quadrats/common 0.1.0 → 0.4.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 (47) hide show
  1. package/blockquote/createBlockquote.js +1 -1
  2. package/bold/createBold.d.ts +1 -1
  3. package/bold/createBold.js +5 -3
  4. package/bold/index.cjs.js +4 -2
  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/file-uploader/createFileUploader.js +2 -2
  16. package/footnote/constants.d.ts +1 -0
  17. package/footnote/constants.js +3 -0
  18. package/footnote/createFootnote.d.ts +4 -0
  19. package/footnote/createFootnote.js +79 -0
  20. package/footnote/index.cjs.js +85 -0
  21. package/footnote/index.d.ts +3 -0
  22. package/footnote/index.js +2 -0
  23. package/footnote/package.json +7 -0
  24. package/footnote/typings.d.ts +24 -0
  25. package/heading/createHeading.js +1 -1
  26. package/highlight/createHighlight.d.ts +1 -1
  27. package/highlight/createHighlight.js +5 -3
  28. package/highlight/index.cjs.js +4 -2
  29. package/image/createImage.js +1 -1
  30. package/input-block/createInputBlock.js +1 -1
  31. package/input-widget/typings.d.ts +1 -0
  32. package/italic/createItalic.d.ts +1 -1
  33. package/italic/createItalic.js +5 -3
  34. package/italic/index.cjs.js +4 -2
  35. package/link/createLink.js +1 -1
  36. package/list/createList.js +1 -1
  37. package/package.json +4 -4
  38. package/read-more/createReadMore.js +1 -1
  39. package/strikethrough/createStrikethrough.d.ts +1 -1
  40. package/strikethrough/createStrikethrough.js +5 -3
  41. package/strikethrough/index.cjs.js +4 -2
  42. package/toggle-mark/createToggleMarkCreator.d.ts +7 -3
  43. package/toggle-mark/createToggleMarkCreator.js +11 -2
  44. package/toggle-mark/index.cjs.js +10 -1
  45. package/underline/createUnderline.d.ts +1 -1
  46. package/underline/createUnderline.js +5 -3
  47. package/underline/index.cjs.js +4 -2
@@ -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, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,10 @@
1
- import { BOLD_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { getVariantType } from '@quadrats/core';
3
+ import { BOLD_TYPE } from './constants.js';
3
4
 
4
- const createBold = createToggleMarkCreator({
5
- type: BOLD_TYPE,
5
+ const createBold = (variant) => createToggleMarkCreator({
6
+ type: getVariantType(BOLD_TYPE, variant),
7
+ parentType: BOLD_TYPE,
6
8
  });
7
9
 
8
10
  export { createBold };
package/bold/index.cjs.js CHANGED
@@ -3,11 +3,13 @@
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');
6
7
 
7
8
  const BOLD_TYPE = 'bold';
8
9
 
9
- const createBold = toggleMark.createToggleMarkCreator({
10
- type: BOLD_TYPE,
10
+ const createBold = (variant) => toggleMark.createToggleMarkCreator({
11
+ type: core.getVariantType(BOLD_TYPE, variant),
12
+ parentType: BOLD_TYPE,
11
13
  });
12
14
 
13
15
  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
+ }
@@ -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,79 @@
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 getAllFootnotes = (editor) => {
8
+ const resultNodes = getNodes(editor, {
9
+ at: [],
10
+ match: (node) => node.type === FOOTNOTE_TYPE,
11
+ });
12
+ return Array.from(resultNodes);
13
+ };
14
+ const getFootnoteText = (editor) => {
15
+ var _a, _b, _c;
16
+ const at = editor.selection;
17
+ if (!at) {
18
+ return '';
19
+ }
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;
22
+ };
23
+ const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
24
+ var _a;
25
+ 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 })) {
27
+ Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
28
+ footnoteCount += 1;
29
+ }
30
+ };
31
+ const unwrapFootnote = (editor, options = {}) => {
32
+ unwrapNodesByTypes(editor, [type], options);
33
+ };
34
+ const wrapFootnote = (editor, footnoteText, options = {}) => {
35
+ var _a;
36
+ const footnote = {
37
+ type,
38
+ footnote: footnoteText,
39
+ index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
40
+ children: [],
41
+ };
42
+ wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
43
+ };
44
+ const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
45
+ const { at = editor.selection } = options;
46
+ if (!at) {
47
+ return;
48
+ }
49
+ if (footnoteText !== '') {
50
+ if (isSelectionInFootnote(editor)) {
51
+ Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: (node) => node.type === type });
52
+ }
53
+ else {
54
+ wrapFootnote(editor, footnoteText, options);
55
+ }
56
+ }
57
+ else {
58
+ unwrapFootnote(editor, { at });
59
+ }
60
+ updateFootnoteIndex(editor);
61
+ };
62
+ return {
63
+ type,
64
+ getAllFootnotes,
65
+ getFootnoteText,
66
+ isSelectionInFootnote,
67
+ updateFootnoteIndex,
68
+ unwrapFootnote,
69
+ wrapFootnote,
70
+ upsertFootnoteAndUpdateIndex,
71
+ with(editor) {
72
+ const { isInline } = editor;
73
+ editor.isInline = (element) => element.type === type || isInline(element);
74
+ return editor;
75
+ },
76
+ };
77
+ }
78
+
79
+ export { createFootnote };
@@ -0,0 +1,85 @@
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 getAllFootnotes = (editor) => {
13
+ const resultNodes = core.getNodes(editor, {
14
+ at: [],
15
+ match: (node) => node.type === FOOTNOTE_TYPE,
16
+ });
17
+ return Array.from(resultNodes);
18
+ };
19
+ const getFootnoteText = (editor) => {
20
+ var _a, _b, _c;
21
+ const at = editor.selection;
22
+ if (!at) {
23
+ return '';
24
+ }
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;
27
+ };
28
+ const updateFootnoteIndex = (editor, options = { startAt: 1 }) => {
29
+ var _a;
30
+ 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 })) {
32
+ core.Transforms.setNodes(editor, { index: footnoteCount }, { at: path });
33
+ footnoteCount += 1;
34
+ }
35
+ };
36
+ const unwrapFootnote = (editor, options = {}) => {
37
+ core.unwrapNodesByTypes(editor, [type], options);
38
+ };
39
+ const wrapFootnote = (editor, footnoteText, options = {}) => {
40
+ var _a;
41
+ const footnote = {
42
+ type,
43
+ footnote: footnoteText,
44
+ index: (_a = options === null || options === void 0 ? void 0 : options.index) !== null && _a !== void 0 ? _a : 0,
45
+ children: [],
46
+ };
47
+ core.wrapNodesWithUnhangRange(editor, footnote, Object.assign(Object.assign({}, options), { split: true }));
48
+ };
49
+ const upsertFootnoteAndUpdateIndex = (editor, footnoteText, options = {}) => {
50
+ const { at = editor.selection } = options;
51
+ if (!at) {
52
+ return;
53
+ }
54
+ if (footnoteText !== '') {
55
+ if (isSelectionInFootnote(editor)) {
56
+ core.Transforms.setNodes(editor, { footnote: footnoteText }, { at, match: (node) => node.type === type });
57
+ }
58
+ else {
59
+ wrapFootnote(editor, footnoteText, options);
60
+ }
61
+ }
62
+ else {
63
+ unwrapFootnote(editor, { at });
64
+ }
65
+ updateFootnoteIndex(editor);
66
+ };
67
+ return {
68
+ type,
69
+ getAllFootnotes,
70
+ getFootnoteText,
71
+ isSelectionInFootnote,
72
+ updateFootnoteIndex,
73
+ unwrapFootnote,
74
+ wrapFootnote,
75
+ upsertFootnoteAndUpdateIndex,
76
+ with(editor) {
77
+ const { isInline } = editor;
78
+ editor.isInline = (element) => element.type === type || isInline(element);
79
+ return editor;
80
+ },
81
+ };
82
+ }
83
+
84
+ exports.FOOTNOTE_TYPE = FOOTNOTE_TYPE;
85
+ 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,24 @@
1
+ import { Editor, Range, Element, WithElementType, UnwrapNodeByTypesOptions, TransformsWrapNodesOptions, Withable, NodeEntry, Node } from '@quadrats/core';
2
+ export interface FootnoteElement extends Element, WithElementType {
3
+ footnote: string;
4
+ index?: number;
5
+ }
6
+ export interface FootnoteUpdateFootnoteIndexOptions {
7
+ startAt?: number;
8
+ }
9
+ export declare type FootnoteUnwrapFootnoteOptions = UnwrapNodeByTypesOptions;
10
+ export interface FootnoteWrapFootnoteOptions extends Omit<TransformsWrapNodesOptions, 'split'> {
11
+ index?: number;
12
+ }
13
+ export interface FootnoteUpsertFootnoteOptions {
14
+ at?: Range;
15
+ }
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;
24
+ }
@@ -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, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,10 @@
1
- import { HIGHLIGHT_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { getVariantType } from '@quadrats/core';
3
+ import { HIGHLIGHT_TYPE } from './constants.js';
3
4
 
4
- const createHighlight = createToggleMarkCreator({
5
- type: HIGHLIGHT_TYPE,
5
+ const createHighlight = (variant) => createToggleMarkCreator({
6
+ type: getVariantType(HIGHLIGHT_TYPE, variant),
7
+ parentType: HIGHLIGHT_TYPE,
6
8
  });
7
9
 
8
10
  export { createHighlight };
@@ -3,11 +3,13 @@
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');
6
7
 
7
8
  const HIGHLIGHT_TYPE = 'highlight';
8
9
 
9
- const createHighlight = toggleMark.createToggleMarkCreator({
10
- type: HIGHLIGHT_TYPE,
10
+ const createHighlight = (variant) => toggleMark.createToggleMarkCreator({
11
+ type: core.getVariantType(HIGHLIGHT_TYPE, variant),
12
+ parentType: HIGHLIGHT_TYPE,
11
13
  });
12
14
 
13
15
  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;
@@ -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, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,10 @@
1
- import { ITALIC_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { getVariantType } from '@quadrats/core';
3
+ import { ITALIC_TYPE } from './constants.js';
3
4
 
4
- const createItalic = createToggleMarkCreator({
5
- type: ITALIC_TYPE,
5
+ const createItalic = (variant) => createToggleMarkCreator({
6
+ type: getVariantType(ITALIC_TYPE, variant),
7
+ parentType: ITALIC_TYPE,
6
8
  });
7
9
 
8
10
  export { createItalic };
@@ -3,11 +3,13 @@
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');
6
7
 
7
8
  const ITALIC_TYPE = 'italic';
8
9
 
9
- const createItalic = toggleMark.createToggleMarkCreator({
10
- type: ITALIC_TYPE,
10
+ const createItalic = (variant) => toggleMark.createToggleMarkCreator({
11
+ type: core.getVariantType(ITALIC_TYPE, variant),
12
+ parentType: ITALIC_TYPE,
11
13
  });
12
14
 
13
15
  exports.ITALIC_TYPE = ITALIC_TYPE;
@@ -1,6 +1,6 @@
1
- import { LINK_TYPE } from './constants.js';
2
1
  import { isUrl } from '@quadrats/utils';
3
2
  import { Range, unwrapNodesByTypes, Editor, Element, Transforms, getRangeBeforeFromAboveBlockStart, getRangeBefore, isNodesTypeIn, wrapNodesWithUnhangRange, Text, 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) => {
@@ -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.1.0",
3
+ "version": "0.4.0",
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.1.0",
22
- "@quadrats/locales": "^0.1.0",
23
- "@quadrats/utils": "^0.1.0"
21
+ "@quadrats/core": "^0.4.0",
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, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,10 @@
1
- import { STRIKETHROUGH_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { getVariantType } from '@quadrats/core';
3
+ import { STRIKETHROUGH_TYPE } from './constants.js';
3
4
 
4
- const createStrikethrough = createToggleMarkCreator({
5
- type: STRIKETHROUGH_TYPE,
5
+ const createStrikethrough = (variant) => createToggleMarkCreator({
6
+ type: getVariantType(STRIKETHROUGH_TYPE, variant),
7
+ parentType: STRIKETHROUGH_TYPE,
6
8
  });
7
9
 
8
10
  export { createStrikethrough };
@@ -3,11 +3,13 @@
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');
6
7
 
7
8
  const STRIKETHROUGH_TYPE = 'strikethrough';
8
9
 
9
- const createStrikethrough = toggleMark.createToggleMarkCreator({
10
- type: STRIKETHROUGH_TYPE,
10
+ const createStrikethrough = (variant) => toggleMark.createToggleMarkCreator({
11
+ type: core.getVariantType(STRIKETHROUGH_TYPE, variant),
12
+ parentType: STRIKETHROUGH_TYPE,
11
13
  });
12
14
 
13
15
  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
+ parentType?: string;
5
+ };
6
+ export declare type CreateToggleMarkOptions = Partial<CreateToggleMarkCreatorOptions> & {
7
+ parentType?: string;
8
+ };
9
+ export declare function createToggleMarkCreator(defaults: CreateToggleMarkCreatorOptions): ({ type, parentType }?: CreateToggleMarkOptions) => ToggleMark;
@@ -1,7 +1,7 @@
1
- import { getMark } from '@quadrats/core';
1
+ import { getMark, marksGroupBy } from '@quadrats/core';
2
2
 
3
3
  function createToggleMarkCreator(defaults) {
4
- return ({ type = defaults.type } = {}) => {
4
+ return ({ type = defaults.type, parentType = defaults.parentType } = {}) => {
5
5
  const isToggleMarkActive = (editor) => {
6
6
  const mark = getMark(editor, type);
7
7
  return mark === true;
@@ -12,6 +12,15 @@ function createToggleMarkCreator(defaults) {
12
12
  editor.removeMark(type);
13
13
  }
14
14
  else {
15
+ if (parentType) {
16
+ marksGroupBy(editor, (_mark) => {
17
+ if (_mark.match(parentType)) {
18
+ editor.removeMark(_mark);
19
+ return true;
20
+ }
21
+ return false;
22
+ });
23
+ }
15
24
  editor.addMark(type, true);
16
25
  }
17
26
  };
@@ -5,7 +5,7 @@ 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, parentType = defaults.parentType } = {}) => {
9
9
  const isToggleMarkActive = (editor) => {
10
10
  const mark = core.getMark(editor, type);
11
11
  return mark === true;
@@ -16,6 +16,15 @@ function createToggleMarkCreator(defaults) {
16
16
  editor.removeMark(type);
17
17
  }
18
18
  else {
19
+ if (parentType) {
20
+ core.marksGroupBy(editor, (_mark) => {
21
+ if (_mark.match(parentType)) {
22
+ editor.removeMark(_mark);
23
+ return true;
24
+ }
25
+ return false;
26
+ });
27
+ }
19
28
  editor.addMark(type, true);
20
29
  }
21
30
  };
@@ -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, parentType }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark;
@@ -1,8 +1,10 @@
1
- import { UNDERLINE_TYPE } from './constants.js';
2
1
  import { createToggleMarkCreator } from '@quadrats/common/toggle-mark';
2
+ import { getVariantType } from '@quadrats/core';
3
+ import { UNDERLINE_TYPE } from './constants.js';
3
4
 
4
- const createUnderline = createToggleMarkCreator({
5
- type: UNDERLINE_TYPE,
5
+ const createUnderline = (variant) => createToggleMarkCreator({
6
+ type: getVariantType(UNDERLINE_TYPE, variant),
7
+ parentType: UNDERLINE_TYPE,
6
8
  });
7
9
 
8
10
  export { createUnderline };
@@ -3,11 +3,13 @@
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');
6
7
 
7
8
  const UNDERLINE_TYPE = 'underline';
8
9
 
9
- const createUnderline = toggleMark.createToggleMarkCreator({
10
- type: UNDERLINE_TYPE,
10
+ const createUnderline = (variant) => toggleMark.createToggleMarkCreator({
11
+ type: core.getVariantType(UNDERLINE_TYPE, variant),
12
+ parentType: UNDERLINE_TYPE,
11
13
  });
12
14
 
13
15
  exports.UNDERLINE_TYPE = UNDERLINE_TYPE;