@quadrats/common 0.7.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/accordion/constants.d.ts +5 -0
  2. package/accordion/constants.js +10 -0
  3. package/accordion/createAccordion.d.ts +6 -0
  4. package/accordion/createAccordion.js +62 -0
  5. package/accordion/index.cjs.js +76 -0
  6. package/accordion/index.d.ts +3 -0
  7. package/accordion/index.js +2 -0
  8. package/accordion/package.json +7 -0
  9. package/accordion/typings.d.ts +18 -0
  10. package/align/constants.d.ts +1 -0
  11. package/align/constants.js +3 -0
  12. package/align/createAlign.d.ts +9 -0
  13. package/align/createAlign.js +41 -0
  14. package/align/index.cjs.js +45 -0
  15. package/align/index.d.ts +3 -0
  16. package/align/index.js +2 -0
  17. package/align/package.json +7 -0
  18. package/align/typings.d.ts +1 -0
  19. package/blockquote/createBlockquote.js +1 -1
  20. package/bold/createBold.d.ts +1 -1
  21. package/card/constants.d.ts +6 -0
  22. package/card/constants.js +11 -0
  23. package/card/createCard.d.ts +15 -0
  24. package/card/createCard.js +147 -0
  25. package/card/getFilesFromInput.d.ts +4 -0
  26. package/card/index.cjs.js +163 -0
  27. package/card/index.d.ts +3 -0
  28. package/card/index.js +2 -0
  29. package/card/package.json +7 -0
  30. package/card/typings.d.ts +73 -0
  31. package/carousel/_virtual/_tslib.js +33 -0
  32. package/carousel/constants.d.ts +6 -0
  33. package/carousel/constants.js +11 -0
  34. package/carousel/createCarousel.d.ts +16 -0
  35. package/carousel/createCarousel.js +127 -0
  36. package/carousel/getFilesFromInput.d.ts +4 -0
  37. package/carousel/getFilesFromInput.js +30 -0
  38. package/carousel/index.cjs.js +202 -0
  39. package/carousel/index.d.ts +3 -0
  40. package/carousel/index.js +2 -0
  41. package/carousel/package.json +7 -0
  42. package/carousel/typings.d.ts +58 -0
  43. package/embed/constants.d.ts +1 -0
  44. package/embed/constants.js +2 -1
  45. package/embed/createEmbed.js +27 -4
  46. package/embed/index.cjs.js +32 -9
  47. package/embed/index.js +1 -1
  48. package/embed/serializeEmbedCode.d.ts +1 -1
  49. package/embed/serializeEmbedCode.js +5 -7
  50. package/embed/strategies/podcast-apple/index.cjs.js +1 -1
  51. package/embed/strategies/podcast-apple/index.js +1 -1
  52. package/embed/strategies/twitter/index.cjs.js +1 -1
  53. package/embed/strategies/twitter/index.js +1 -1
  54. package/embed/typings.d.ts +16 -1
  55. package/file-uploader/constants.d.ts +1 -0
  56. package/file-uploader/constants.js +2 -1
  57. package/file-uploader/createFileUploader.d.ts +3 -1
  58. package/file-uploader/createFileUploader.js +85 -63
  59. package/file-uploader/getFilesFromInput.js +3 -0
  60. package/file-uploader/index.cjs.js +89 -60
  61. package/file-uploader/index.d.ts +1 -1
  62. package/file-uploader/index.js +2 -2
  63. package/file-uploader/typings.d.ts +8 -2
  64. package/footnote/createFootnote.js +1 -1
  65. package/heading/constants.d.ts +1 -1
  66. package/heading/createHeading.js +2 -2
  67. package/heading/typings.d.ts +1 -0
  68. package/highlight/createHighlight.d.ts +1 -1
  69. package/image/createImage.js +13 -12
  70. package/image/getImageFigureElementCommonProps.d.ts +2 -0
  71. package/image/getImageFigureElementCommonProps.js +28 -2
  72. package/image/index.cjs.js +40 -13
  73. package/image/typings.d.ts +2 -0
  74. package/input-block/createInputBlock.js +1 -1
  75. package/italic/createItalic.d.ts +1 -1
  76. package/link/createLink.js +1 -1
  77. package/list/createList.d.ts +1 -0
  78. package/list/createList.js +4 -1
  79. package/list/index.cjs.js +3 -0
  80. package/list/typings.d.ts +1 -0
  81. package/package.json +4 -4
  82. package/paragraph/createParagraph.d.ts +2 -0
  83. package/paragraph/createParagraph.js +24 -0
  84. package/paragraph/index.cjs.js +26 -0
  85. package/paragraph/index.d.ts +2 -0
  86. package/paragraph/index.js +1 -0
  87. package/paragraph/package.json +7 -0
  88. package/paragraph/typings.d.ts +9 -0
  89. package/read-more/createReadMore.js +1 -1
  90. package/strikethrough/createStrikethrough.d.ts +1 -1
  91. package/underline/createUnderline.d.ts +1 -1
@@ -14,9 +14,35 @@ function isHostingNotRequired(src) {
14
14
  }
15
15
 
16
16
  function getImageFigureElementCommonProps(element) {
17
- const { width } = element;
17
+ const { width, align } = element;
18
18
  return {
19
- style: typeof width === 'number' ? { width: `${width}%` } : undefined,
19
+ style: {
20
+ width: typeof width === 'number' ? `${width}%` : 'unset',
21
+ '--qdr-image-align': (() => {
22
+ switch (align) {
23
+ case 'start':
24
+ return 'flex-start';
25
+ case 'center':
26
+ return 'center';
27
+ case 'end':
28
+ return 'flex-end';
29
+ default:
30
+ return 'flex-start';
31
+ }
32
+ })(),
33
+ '--qdr-image-caption-align': (() => {
34
+ switch (align) {
35
+ case 'start':
36
+ return 'left';
37
+ case 'center':
38
+ return 'center';
39
+ case 'end':
40
+ return 'right';
41
+ default:
42
+ return 'left';
43
+ }
44
+ })(),
45
+ },
20
46
  };
21
47
  }
22
48
 
@@ -29,7 +55,7 @@ function getImageElementCommonProps(element, hostingResolvers) {
29
55
  }
30
56
 
31
57
  function resolveSizeSteps(steps) {
32
- let sortedSteps = steps.filter(step => step > 0 && step < 100).sort();
58
+ let sortedSteps = steps.filter((step) => step > 0 && step < 100).sort();
33
59
  if (!sortedSteps.includes(100)) {
34
60
  sortedSteps = [...sortedSteps, 100];
35
61
  }
@@ -42,12 +68,13 @@ function createImage(options = {}) {
42
68
  const getAboveImageFigure = (editor, options) => core.getAboveByTypes(editor, [types.figure], options);
43
69
  const getAboveImageCaption = (editor, options) => core.getAboveByTypes(editor, [types.caption], options);
44
70
  const isNodesInImage = (editor, options) => core.isNodesTypeIn(editor, [types.image], options);
45
- const isSelectionInImage = editor => isNodesInImage(editor);
46
- const isSelectionInImageCaption = editor => core.isNodesTypeIn(editor, [types.caption]);
47
- const isCollapsedOnImage = editor => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
71
+ const isSelectionInImage = (editor) => isNodesInImage(editor);
72
+ const isSelectionInImageCaption = (editor) => core.isNodesTypeIn(editor, [types.caption]);
73
+ const isCollapsedOnImage = (editor) => !!editor.selection && core.Range.isCollapsed(editor.selection) && isSelectionInImage(editor);
48
74
  const createImageElement = (src, hosting) => {
49
75
  const imageElement = {
50
76
  type: types.image,
77
+ figureType: types.figure,
51
78
  src,
52
79
  hosting,
53
80
  children: [{ text: '' }],
@@ -77,7 +104,7 @@ function createImage(options = {}) {
77
104
  if (!sizeSteps) {
78
105
  return percentage;
79
106
  }
80
- const lowerIndex = sizeSteps.findIndex(step => step >= percentage) - 1;
107
+ const lowerIndex = sizeSteps.findIndex((step) => step >= percentage) - 1;
81
108
  const upperIndex = lowerIndex + 1;
82
109
  if (lowerIndex < 0) {
83
110
  return sizeSteps[0];
@@ -115,7 +142,7 @@ function createImage(options = {}) {
115
142
  insertImage,
116
143
  resizeImage,
117
144
  with(editor) {
118
- const { deleteBackward, deleteForward, insertBreak, isVoid, normalizeNode, } = editor;
145
+ const { deleteBackward, deleteForward, insertBreak, isVoid, normalizeNode } = editor;
119
146
  const deleteCollapsed = (origin, isEdgeMethodName) => {
120
147
  const { selection } = editor;
121
148
  /**
@@ -123,7 +150,7 @@ function createImage(options = {}) {
123
150
  */
124
151
  if (selection && core.Range.isCollapsed(selection)) {
125
152
  const [, captionPath] = getAboveImageCaption(editor) || [];
126
- if ((captionPath && core.Editor[isEdgeMethodName](editor, selection.focus, captionPath))) {
153
+ if (captionPath && core.Editor[isEdgeMethodName](editor, selection.focus, captionPath)) {
127
154
  return;
128
155
  }
129
156
  }
@@ -154,7 +181,7 @@ function createImage(options = {}) {
154
181
  }
155
182
  insertBreak();
156
183
  };
157
- editor.isVoid = element => element.type === types.image || isVoid(element);
184
+ editor.isVoid = (element) => element.type === types.image || isVoid(element);
158
185
  editor.normalizeNode = (entry) => {
159
186
  const [node, path] = entry;
160
187
  if (core.Element.isElement(node)) {
@@ -166,9 +193,9 @@ function createImage(options = {}) {
166
193
  }
167
194
  else if (node.type === types.image) {
168
195
  const { src, width, hosting } = node;
169
- if (typeof src !== 'string'
170
- || !(width == null || typeof width === 'number')
171
- || !(hosting == null || typeof hosting === 'string')) {
196
+ if (typeof src !== 'string' ||
197
+ !(width == null || typeof width === 'number') ||
198
+ !(hosting == null || typeof hosting === 'string')) {
172
199
  const [, figurePath] = getAboveImageFigure(editor, { at: path }) || [];
173
200
  if (figurePath) {
174
201
  core.Transforms.removeNodes(editor, { at: figurePath });
@@ -4,11 +4,13 @@ export type ImageTypeKey = 'image';
4
4
  export type ImageCaptionTypeKey = 'caption';
5
5
  export type ImageTypes = Record<ImageFigureTypeKey | ImageTypeKey | ImageCaptionTypeKey, string>;
6
6
  export interface ImageFigureElement extends QuadratsElement, WithElementType {
7
+ align?: 'start' | 'center' | 'end';
7
8
  width?: number;
8
9
  }
9
10
  export interface ImageElement extends QuadratsElement, WithElementType {
10
11
  children: [Text];
11
12
  src: string;
13
+ figureType: string;
12
14
  /**
13
15
  * e.g. The src of image is `8gy9pbaht92y4.jpg` and your static files are hosted by `https://foo.storage`.
14
16
  * Then you can make the hosting of element be `foo`.
@@ -1,4 +1,4 @@
1
- import { Editor, Path, Transforms } from '@quadrats/core';
1
+ import { Path, Editor, Transforms } from '@quadrats/core';
2
2
  import { INPUT_BLOCK_TYPE } from './constants.js';
3
3
 
4
4
  function createInputBlock(options = {}) {
@@ -1,2 +1,2 @@
1
1
  import { Editor } from '@quadrats/core';
2
- export declare function createItalic<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
2
+ export declare function createItalic<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
@@ -1,5 +1,5 @@
1
1
  import { isUrl } from '@quadrats/utils';
2
- import { Range, Editor, Element, Transforms, Text, getRangeBeforeFromAboveBlockStart, getRangeBefore, isNodesTypeIn, unwrapNodesByTypes, wrapNodesWithUnhangRange, getAboveByTypes } from '@quadrats/core';
2
+ import { unwrapNodesByTypes, isNodesTypeIn, Range, Editor, Element, Transforms, Text, getAboveByTypes, wrapNodesWithUnhangRange, getRangeBeforeFromAboveBlockStart, getRangeBefore } from '@quadrats/core';
3
3
  import { LINK_TYPE } from './constants.js';
4
4
 
5
5
  function createLink({ type = LINK_TYPE, isUrl: isUrl$1 = isUrl, prevUrlToLinkAfterSpaceEntered = true, wrappableVoidTypes, } = {}) {
@@ -1,5 +1,6 @@
1
1
  import { List, ListTypes } from './typings';
2
2
  export interface CreateListOptions {
3
3
  types?: Partial<ListTypes>;
4
+ labels?: number;
4
5
  }
5
6
  export declare function createList(options?: CreateListOptions): List;
@@ -1,7 +1,9 @@
1
- import { Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms, isNodesTypeIn, getAboveByTypes, getParent, unwrapNodesByTypes, wrapNodesWithUnhangRange, getNodesByTypes, PARAGRAPH_TYPE, isFirstChild, Editor, Path } from '@quadrats/core';
1
+ import { PARAGRAPH_TYPE, isNodesTypeIn, Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms, Editor, Path, isFirstChild, wrapNodesWithUnhangRange, getNodesByTypes, unwrapNodesByTypes, getAboveByTypes, getParent } from '@quadrats/core';
2
2
  import { LIST_TYPES } from './constants.js';
3
3
 
4
4
  function createList(options = {}) {
5
+ var _a;
6
+ const labels = (_a = options.labels) !== null && _a !== void 0 ? _a : 4;
5
7
  const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
6
8
  const isListElement = (node) => [types.ol, types.ul].includes(node.type);
7
9
  const isListItemElement = (node) => node.type === types.li;
@@ -140,6 +142,7 @@ function createList(options = {}) {
140
142
  };
141
143
  return {
142
144
  types,
145
+ labels,
143
146
  isListElement,
144
147
  isListItemElement,
145
148
  isSelectionInList,
package/list/index.cjs.js CHANGED
@@ -9,6 +9,8 @@ const LIST_TYPES = {
9
9
  };
10
10
 
11
11
  function createList(options = {}) {
12
+ var _a;
13
+ const labels = (_a = options.labels) !== null && _a !== void 0 ? _a : 4;
12
14
  const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
13
15
  const isListElement = (node) => [types.ol, types.ul].includes(node.type);
14
16
  const isListItemElement = (node) => node.type === types.li;
@@ -147,6 +149,7 @@ function createList(options = {}) {
147
149
  };
148
150
  return {
149
151
  types,
152
+ labels,
150
153
  isListElement,
151
154
  isListItemElement,
152
155
  isSelectionInList,
package/list/typings.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface List<T extends Editor = Editor> extends Withable {
17
17
  * An object which keys are `ul`, `ol`, `li` and values are the corresponding element types.
18
18
  */
19
19
  types: ListTypes;
20
+ labels: number;
20
21
  isListElement(node: Node): node is QuadratsElement;
21
22
  isListItemElement(node: Node): node is QuadratsElement;
22
23
  isSelectionInList(editor: T, listTypeKey: ListRootTypeKey): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadrats/common",
3
- "version": "0.7.3",
3
+ "version": "1.0.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.7.2",
22
- "@quadrats/locales": "^0.7.0",
23
- "@quadrats/utils": "^0.7.2"
21
+ "@quadrats/core": "^1.0.0",
22
+ "@quadrats/locales": "^1.0.0",
23
+ "@quadrats/utils": "^1.0.0"
24
24
  }
25
25
  }
@@ -0,0 +1,2 @@
1
+ import { Paragraph } from './typings';
2
+ export declare function createParagraph(): Paragraph;
@@ -0,0 +1,24 @@
1
+ import { getNodes, PARAGRAPH_TYPE, Transforms } from '@quadrats/core';
2
+
3
+ function createParagraph() {
4
+ const getParagraphNodes = (editor, options = {}) => getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === PARAGRAPH_TYPE }));
5
+ const isSelectionInParagraph = (editor, options = {}) => {
6
+ const [match] = getParagraphNodes(editor, options);
7
+ return !!match;
8
+ };
9
+ const setParagraphNodes = (editor) => {
10
+ const paragraph = { type: PARAGRAPH_TYPE, children: [] };
11
+ Transforms.setNodes(editor, paragraph);
12
+ };
13
+ return {
14
+ type: PARAGRAPH_TYPE,
15
+ getParagraphNodes,
16
+ isSelectionInParagraph,
17
+ setParagraphNodes,
18
+ with(editor) {
19
+ return editor;
20
+ },
21
+ };
22
+ }
23
+
24
+ export { createParagraph };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ var core = require('@quadrats/core');
4
+
5
+ function createParagraph() {
6
+ const getParagraphNodes = (editor, options = {}) => core.getNodes(editor, Object.assign(Object.assign({}, options), { match: (node) => node.type === core.PARAGRAPH_TYPE }));
7
+ const isSelectionInParagraph = (editor, options = {}) => {
8
+ const [match] = getParagraphNodes(editor, options);
9
+ return !!match;
10
+ };
11
+ const setParagraphNodes = (editor) => {
12
+ const paragraph = { type: core.PARAGRAPH_TYPE, children: [] };
13
+ core.Transforms.setNodes(editor, paragraph);
14
+ };
15
+ return {
16
+ type: core.PARAGRAPH_TYPE,
17
+ getParagraphNodes,
18
+ isSelectionInParagraph,
19
+ setParagraphNodes,
20
+ with(editor) {
21
+ return editor;
22
+ },
23
+ };
24
+ }
25
+
26
+ exports.createParagraph = createParagraph;
@@ -0,0 +1,2 @@
1
+ export * from './typings';
2
+ export * from './createParagraph';
@@ -0,0 +1 @@
1
+ export { createParagraph } from './createParagraph.js';
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@quadrats/common/paragraph",
3
+ "sideEffects": false,
4
+ "main": "./index.cjs.js",
5
+ "module": "./index.js",
6
+ "typings": "./index.d.ts"
7
+ }
@@ -0,0 +1,9 @@
1
+ import { Editor, QuadratsElement, GetNodesOptions, Node, NodeEntry, Withable, WithElementType } from '@quadrats/core';
2
+ export interface ParagraphElement extends QuadratsElement {
3
+ align?: 'left' | 'center' | 'right';
4
+ }
5
+ export interface Paragraph<T extends Editor = Editor> extends WithElementType, Withable {
6
+ getParagraphNodes(editor: T, options?: GetNodesOptions): Generator<NodeEntry<Node>>;
7
+ isSelectionInParagraph(editor: T, options?: GetNodesOptions): boolean;
8
+ setParagraphNodes(editor: T): void;
9
+ }
@@ -1,4 +1,4 @@
1
- import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot, Path, Transforms, getNodesByTypes, deleteSelectionFragmentIfExpanded, createParagraphElement } from '@quadrats/core';
1
+ import { Element, normalizeVoidElementChildren, normalizeOnlyAtRoot, getNodesByTypes, Path, Transforms, deleteSelectionFragmentIfExpanded, createParagraphElement } from '@quadrats/core';
2
2
  import { READ_MORE_TYPE } from './constants.js';
3
3
 
4
4
  function createReadMore(options = {}) {
@@ -1,2 +1,2 @@
1
1
  import { Editor } from '@quadrats/core';
2
- export declare function createStrikethrough<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
2
+ export declare function createStrikethrough<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
@@ -1,2 +1,2 @@
1
1
  import { Editor } from '@quadrats/core';
2
- export declare function createUnderline<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions | undefined) => import("@quadrats/common/toggle-mark").ToggleMark<E>;
2
+ export declare function createUnderline<E extends Editor = Editor>(variant?: string): ({ type, variant }?: import("@quadrats/common/toggle-mark").CreateToggleMarkOptions) => import("@quadrats/common/toggle-mark").ToggleMark<E>;