@20minutes/draft-convert 3.1.1 → 3.1.2

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 (42) hide show
  1. package/{esm/blockEntities.js → dist/blockEntities.mjs} +4 -4
  2. package/{esm/blockInlineStyles.js → dist/blockInlineStyles.mjs} +5 -5
  3. package/{lib → dist}/convertFromHTML.js +8 -46
  4. package/{esm/convertFromHTML.js → dist/convertFromHTML.mjs} +7 -4
  5. package/{lib → dist}/convertToHTML.js +2 -43
  6. package/{esm/convertToHTML.js → dist/convertToHTML.mjs} +9 -9
  7. package/{esm/encodeBlock.js → dist/encodeBlock.mjs} +2 -2
  8. package/dist/index.d.ts +121 -0
  9. package/dist/index.mjs +4 -0
  10. package/{esm/util/getBlockTags.js → dist/util/getBlockTags.mjs} +1 -1
  11. package/{esm/util/getElementHTML.js → dist/util/getElementHTML.mjs} +1 -1
  12. package/{esm/util/getElementTagLength.js → dist/util/getElementTagLength.mjs} +1 -1
  13. package/{esm/util/getNestedBlockTags.js → dist/util/getNestedBlockTags.mjs} +1 -1
  14. package/package.json +14 -14
  15. package/esm/index.js +0 -4
  16. package/types/index.d.ts +0 -114
  17. /package/{lib → dist}/blockEntities.js +0 -0
  18. /package/{lib → dist}/blockInlineStyles.js +0 -0
  19. /package/{lib → dist}/default/defaultBlockHTML.js +0 -0
  20. /package/{esm/default/defaultBlockHTML.js → dist/default/defaultBlockHTML.mjs} +0 -0
  21. /package/{lib → dist}/default/defaultInlineHTML.js +0 -0
  22. /package/{esm/default/defaultInlineHTML.js → dist/default/defaultInlineHTML.mjs} +0 -0
  23. /package/{lib → dist}/encodeBlock.js +0 -0
  24. /package/{lib/index.js → dist/index.cjs} +0 -0
  25. /package/{lib → dist}/util/accumulateFunction.js +0 -0
  26. /package/{esm/util/accumulateFunction.js → dist/util/accumulateFunction.mjs} +0 -0
  27. /package/{lib → dist}/util/blockTypeObjectFunction.js +0 -0
  28. /package/{esm/util/blockTypeObjectFunction.js → dist/util/blockTypeObjectFunction.mjs} +0 -0
  29. /package/{lib → dist}/util/getBlockTags.js +0 -0
  30. /package/{lib → dist}/util/getElementHTML.js +0 -0
  31. /package/{lib → dist}/util/getElementTagLength.js +0 -0
  32. /package/{lib → dist}/util/getNestedBlockTags.js +0 -0
  33. /package/{lib → dist}/util/parseHTML.js +0 -0
  34. /package/{esm/util/parseHTML.js → dist/util/parseHTML.mjs} +0 -0
  35. /package/{lib → dist}/util/rangeSort.js +0 -0
  36. /package/{esm/util/rangeSort.js → dist/util/rangeSort.mjs} +0 -0
  37. /package/{lib → dist}/util/splitReactElement.js +0 -0
  38. /package/{esm/util/splitReactElement.js → dist/util/splitReactElement.mjs} +0 -0
  39. /package/{lib → dist}/util/styleObjectFunction.js +0 -0
  40. /package/{esm/util/styleObjectFunction.js → dist/util/styleObjectFunction.mjs} +0 -0
  41. /package/{lib → dist}/util/updateMutation.js +0 -0
  42. /package/{esm/util/updateMutation.js → dist/util/updateMutation.mjs} +0 -0
@@ -1,7 +1,7 @@
1
- import updateMutation from './util/updateMutation.js';
2
- import rangeSort from './util/rangeSort.js';
3
- import getElementHTML from './util/getElementHTML.js';
4
- import getElementTagLength from './util/getElementTagLength.js';
1
+ import updateMutation from './util/updateMutation.mjs';
2
+ import rangeSort from './util/rangeSort.mjs';
3
+ import getElementHTML from './util/getElementHTML.mjs';
4
+ import getElementTagLength from './util/getElementTagLength.mjs';
5
5
  const converter = (entity = {}, originalText = '')=>originalText;
6
6
  export default ((block, entityMap, entityConverter = converter)=>{
7
7
  let resultText = [
@@ -1,9 +1,9 @@
1
1
  import invariant from 'invariant';
2
- import styleObjectFunction from './util/styleObjectFunction.js';
3
- import accumulateFunction from './util/accumulateFunction.js';
4
- import getElementHTML from './util/getElementHTML.js';
5
- import rangeSort from './util/rangeSort.js';
6
- import defaultInlineHTML from './default/defaultInlineHTML.js';
2
+ import styleObjectFunction from './util/styleObjectFunction.mjs';
3
+ import accumulateFunction from './util/accumulateFunction.mjs';
4
+ import getElementHTML from './util/getElementHTML.mjs';
5
+ import rangeSort from './util/rangeSort.mjs';
6
+ import defaultInlineHTML from './default/defaultInlineHTML.mjs';
7
7
  const subtractStyles = (original, toRemove)=>original.filter((el)=>!toRemove.some((elToRemove)=>elToRemove.style === el.style));
8
8
  const popEndingStyles = (styleStack, endingStyles)=>endingStyles.reduceRight((stack, style)=>{
9
9
  const styleToRemove = stack[stack.length - 1];
@@ -8,7 +8,9 @@
8
8
  * This source code is licensed under the BSD-style license found in the
9
9
  * LICENSE file in the /src directory of this source tree. An additional grant
10
10
  * of patent rights can be found in the PATENTS file in the same directory.
11
- */ "use strict";
11
+ */ // immutable is CJS-only; default import maps to module.exports for Node ESM interop.
12
+ // eslint-disable-next-line import/default
13
+ "use strict";
12
14
  Object.defineProperty(exports, "__esModule", {
13
15
  value: true
14
16
  });
@@ -18,8 +20,8 @@ Object.defineProperty(exports, "default", {
18
20
  return _default;
19
21
  }
20
22
  });
21
- const _immutable = /*#__PURE__*/ _interop_require_wildcard(require("immutable"));
22
- const _draftjs = /*#__PURE__*/ _interop_require_wildcard(require("draft-js"));
23
+ const _immutable = /*#__PURE__*/ _interop_require_default(require("immutable"));
24
+ const _draftjs = /*#__PURE__*/ _interop_require_default(require("draft-js"));
23
25
  const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML.js"));
24
26
  const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
25
27
  function _interop_require_default(obj) {
@@ -27,49 +29,9 @@ function _interop_require_default(obj) {
27
29
  default: obj
28
30
  };
29
31
  }
30
- function _getRequireWildcardCache(nodeInterop) {
31
- if (typeof WeakMap !== "function") return null;
32
- var cacheBabelInterop = new WeakMap();
33
- var cacheNodeInterop = new WeakMap();
34
- return (_getRequireWildcardCache = function(nodeInterop) {
35
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
36
- })(nodeInterop);
37
- }
38
- function _interop_require_wildcard(obj, nodeInterop) {
39
- if (!nodeInterop && obj && obj.__esModule) {
40
- return obj;
41
- }
42
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
43
- return {
44
- default: obj
45
- };
46
- }
47
- var cache = _getRequireWildcardCache(nodeInterop);
48
- if (cache && cache.has(obj)) {
49
- return cache.get(obj);
50
- }
51
- var newObj = {
52
- __proto__: null
53
- };
54
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
55
- for(var key in obj){
56
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
57
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
58
- if (desc && (desc.get || desc.set)) {
59
- Object.defineProperty(newObj, key, desc);
60
- } else {
61
- newObj[key] = obj[key];
62
- }
63
- }
64
- }
65
- newObj.default = obj;
66
- if (cache) {
67
- cache.set(obj, newObj);
68
- }
69
- return newObj;
70
- }
71
- const { List, Map, OrderedSet } = _immutable;
72
- const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = _draftjs;
32
+ // eslint-disable-next-line import/no-named-as-default-member
33
+ const { List, Map, OrderedSet } = _immutable.default;
34
+ const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = _draftjs.default;
73
35
  const SPACE = ' ';
74
36
  // Arbitrary max indent
75
37
  const MAX_DEPTH = 4;
@@ -8,10 +8,13 @@
8
8
  * This source code is licensed under the BSD-style license found in the
9
9
  * LICENSE file in the /src directory of this source tree. An additional grant
10
10
  * of patent rights can be found in the PATENTS file in the same directory.
11
- */ import * as Immutable from 'immutable';
12
- import * as DraftJS from 'draft-js';
13
- import getSafeBodyFromHTML from './util/parseHTML.js';
14
- import rangeSort from './util/rangeSort.js';
11
+ */ // immutable is CJS-only; default import maps to module.exports for Node ESM interop.
12
+ // eslint-disable-next-line import/default
13
+ import Immutable from 'immutable';
14
+ import DraftJS from 'draft-js';
15
+ import getSafeBodyFromHTML from './util/parseHTML.mjs';
16
+ import rangeSort from './util/rangeSort.mjs';
17
+ // eslint-disable-next-line import/no-named-as-default-member
15
18
  const { List, Map, OrderedSet } = Immutable;
16
19
  const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = DraftJS;
17
20
  const SPACE = ' ';
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "default", {
11
11
  const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
12
12
  const _react = /*#__PURE__*/ _interop_require_default(require("react"));
13
13
  const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
14
- const _draftjs = /*#__PURE__*/ _interop_require_wildcard(require("draft-js"));
14
+ const _draftjs = /*#__PURE__*/ _interop_require_default(require("draft-js"));
15
15
  const _encodeBlock = /*#__PURE__*/ _interop_require_default(require("./encodeBlock.js"));
16
16
  const _blockEntities = /*#__PURE__*/ _interop_require_default(require("./blockEntities.js"));
17
17
  const _blockInlineStyles = /*#__PURE__*/ _interop_require_default(require("./blockInlineStyles.js"));
@@ -25,48 +25,7 @@ function _interop_require_default(obj) {
25
25
  default: obj
26
26
  };
27
27
  }
28
- function _getRequireWildcardCache(nodeInterop) {
29
- if (typeof WeakMap !== "function") return null;
30
- var cacheBabelInterop = new WeakMap();
31
- var cacheNodeInterop = new WeakMap();
32
- return (_getRequireWildcardCache = function(nodeInterop) {
33
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
34
- })(nodeInterop);
35
- }
36
- function _interop_require_wildcard(obj, nodeInterop) {
37
- if (!nodeInterop && obj && obj.__esModule) {
38
- return obj;
39
- }
40
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
41
- return {
42
- default: obj
43
- };
44
- }
45
- var cache = _getRequireWildcardCache(nodeInterop);
46
- if (cache && cache.has(obj)) {
47
- return cache.get(obj);
48
- }
49
- var newObj = {
50
- __proto__: null
51
- };
52
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
53
- for(var key in obj){
54
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
55
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
56
- if (desc && (desc.get || desc.set)) {
57
- Object.defineProperty(newObj, key, desc);
58
- } else {
59
- newObj[key] = obj[key];
60
- }
61
- }
62
- }
63
- newObj.default = obj;
64
- if (cache) {
65
- cache.set(obj, newObj);
66
- }
67
- return newObj;
68
- }
69
- const { convertToRaw } = _draftjs;
28
+ const { convertToRaw } = _draftjs.default;
70
29
  const defaultEntityToHTML = (entity, originalText)=>originalText;
71
30
  const defaultValidateHTML = (html)=>true;
72
31
  const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defaultEntityToHTML, validateHTML = defaultValidateHTML })=>(contentState)=>{
@@ -1,15 +1,15 @@
1
1
  import invariant from 'invariant';
2
2
  import React from 'react';
3
3
  import ReactDOMServer from 'react-dom/server';
4
- import * as DraftJS from 'draft-js';
5
- import encodeBlock from './encodeBlock.js';
6
- import blockEntities from './blockEntities.js';
7
- import blockInlineStyles from './blockInlineStyles.js';
8
- import accumulateFunction from './util/accumulateFunction.js';
9
- import blockTypeObjectFunction from './util/blockTypeObjectFunction.js';
10
- import getBlockTags from './util/getBlockTags.js';
11
- import getNestedBlockTags from './util/getNestedBlockTags.js';
12
- import defaultBlockHTML from './default/defaultBlockHTML.js';
4
+ import DraftJS from 'draft-js';
5
+ import encodeBlock from './encodeBlock.mjs';
6
+ import blockEntities from './blockEntities.mjs';
7
+ import blockInlineStyles from './blockInlineStyles.mjs';
8
+ import accumulateFunction from './util/accumulateFunction.mjs';
9
+ import blockTypeObjectFunction from './util/blockTypeObjectFunction.mjs';
10
+ import getBlockTags from './util/getBlockTags.mjs';
11
+ import getNestedBlockTags from './util/getNestedBlockTags.mjs';
12
+ import defaultBlockHTML from './default/defaultBlockHTML.mjs';
13
13
  const { convertToRaw } = DraftJS;
14
14
  const defaultEntityToHTML = (entity, originalText)=>originalText;
15
15
  const defaultValidateHTML = (html)=>true;
@@ -1,5 +1,5 @@
1
- import updateMutation from './util/updateMutation.js';
2
- import rangeSort from './util/rangeSort.js';
1
+ import updateMutation from './util/updateMutation.mjs';
2
+ import rangeSort from './util/rangeSort.mjs';
3
3
  const ENTITY_MAP = {
4
4
  '&': '&',
5
5
  '<': '&lt;',
@@ -0,0 +1,121 @@
1
+ // Based on: https://github.com/HubSpot/draft-convert/issues/107#issuecomment-488581709 by <https://github.com/sbusch>
2
+ // Grabbed from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/draft-convert/index.d.ts
3
+
4
+ import {
5
+ ContentState,
6
+ DraftBlockType,
7
+ DraftEntityMutability,
8
+ DraftInlineStyleType,
9
+ Entity,
10
+ RawDraftContentBlock,
11
+ RawDraftEntity,
12
+ } from 'draft-js'
13
+ import { ReactNode } from 'react'
14
+
15
+ export type RawDraftContentBlockWithCustomType<T> = Omit<
16
+ RawDraftContentBlock,
17
+ 'type'
18
+ > & {
19
+ type: T
20
+ }
21
+
22
+ export type ExtendedHTMLElement<T> = (HTMLElement | HTMLLinkElement) & T
23
+
24
+ export type EntityKey = string
25
+
26
+ export type ContentStateConverter = (contentState: ContentState) => string
27
+ export type HTMLConverter = (html: string) => ContentState
28
+
29
+ export type Tag =
30
+ | ReactNode
31
+ | { start: string; end: string; empty?: string | undefined }
32
+ | {
33
+ element: ReactNode
34
+ empty?: ReactNode | undefined
35
+ }
36
+
37
+ export interface IConvertToHTMLConfig<
38
+ S = DraftInlineStyleType,
39
+ B extends DraftBlockType = DraftBlockType,
40
+ E extends RawDraftEntity = RawDraftEntity,
41
+ > {
42
+ // Inline styles:
43
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
44
+ styleToHTML?: ((style: S) => Tag | null | undefined | void) | undefined
45
+
46
+ // Block styles:
47
+ blockToHTML?: ((block: RawDraftContentBlockWithCustomType<B>) => Tag | null | undefined) | undefined
48
+
49
+ // Entity styling:
50
+ entityToHTML?: ((entity: E, originalText: string) => Tag | null | undefined) | undefined
51
+
52
+ // HTML validation:
53
+ validateHTML?: ((html: string) => boolean) | undefined
54
+ }
55
+
56
+ export interface IConvertFromHTMLConfig<
57
+ S extends {
58
+ [name: string]: unknown
59
+ } = DOMStringMap,
60
+ B extends DraftBlockType = DraftBlockType,
61
+ E extends RawDraftEntity = RawDraftEntity,
62
+ > {
63
+ // Inline styles:
64
+ htmlToStyle?:
65
+ | ((nodeName: string, node: ExtendedHTMLElement<S>, currentStyle: Set<string>) => Set<string>)
66
+ | undefined
67
+
68
+ // Block styles:
69
+ htmlToBlock?:
70
+ | ((
71
+ nodeName: string,
72
+ node: ExtendedHTMLElement<S>
73
+ ) => B | { type: B; data: object } | false | undefined)
74
+ | undefined
75
+
76
+ // Html entities
77
+ htmlToEntity?:
78
+ | ((
79
+ nodeName: string,
80
+ node: ExtendedHTMLElement<S>,
81
+ createEntity: (type: E['type'], mutability: DraftEntityMutability, data: E['data']) => EntityKey,
82
+ getEntity: (key: EntityKey) => Entity,
83
+ mergeEntityData: (key: string, data: object) => void,
84
+ replaceEntityData: (key: string, data: object) => void
85
+ ) => EntityKey | undefined)
86
+ | undefined
87
+
88
+ // Text entities
89
+ textToEntity?:
90
+ | ((
91
+ text: string,
92
+ createEntity: (type: E['type'], mutability: DraftEntityMutability, data: E['data']) => EntityKey,
93
+ getEntity: (key: EntityKey) => Entity,
94
+ mergeEntityData: (key: string, data: object) => void,
95
+ replaceEntityData: (key: string, data: object) => void
96
+ ) => Array<{
97
+ entity: EntityKey
98
+ offset: number
99
+ length: number
100
+ result?: string | undefined
101
+ }>)
102
+ | undefined
103
+ }
104
+
105
+ export function convertToHTML<
106
+ S = DraftInlineStyleType,
107
+ B extends DraftBlockType = DraftBlockType,
108
+ E extends RawDraftEntity = RawDraftEntity,
109
+ >(config: IConvertToHTMLConfig<S, B, E>): ContentStateConverter
110
+ export function convertToHTML(contentState: ContentState): string
111
+
112
+ export function convertFromHTML<
113
+ S extends {
114
+ [name: string]: unknown
115
+ } = DOMStringMap,
116
+ B extends DraftBlockType = DraftBlockType,
117
+ E extends RawDraftEntity = RawDraftEntity,
118
+ >(config: IConvertFromHTMLConfig<S, B, E>): HTMLConverter
119
+ export function convertFromHTML(html: string): ContentState
120
+
121
+ export function parseHTML(html: string): HTMLBodyElement
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import convertToHTML from './convertToHTML.mjs';
2
+ import convertFromHTML from './convertFromHTML.mjs';
3
+ import parseHTML from './util/parseHTML.mjs';
4
+ export { convertToHTML, convertFromHTML, parseHTML };
@@ -1,7 +1,7 @@
1
1
  import invariant from 'invariant';
2
2
  import React from 'react';
3
3
  import ReactDOMServer from 'react-dom/server';
4
- import splitReactElement from './splitReactElement.js';
4
+ import splitReactElement from './splitReactElement.mjs';
5
5
  function hasChildren(element) {
6
6
  return /*#__PURE__*/ React.isValidElement(element) && React.Children.count(element.props.children) > 0;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import invariant from 'invariant';
2
2
  import React from 'react';
3
3
  import ReactDOMServer from 'react-dom/server';
4
- import splitReactElement from './splitReactElement.js';
4
+ import splitReactElement from './splitReactElement.mjs';
5
5
  function hasChildren(element) {
6
6
  return /*#__PURE__*/ React.isValidElement(element) && React.Children.count(element.props.children) > 0;
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import splitReactElement from './splitReactElement.js';
2
+ import splitReactElement from './splitReactElement.mjs';
3
3
  const getElementTagLength = (element, type = 'start')=>{
4
4
  if (/*#__PURE__*/ React.isValidElement(element)) {
5
5
  const splitElement = splitReactElement(element);
@@ -1,6 +1,6 @@
1
1
  import invariant from 'invariant';
2
2
  import React from 'react';
3
- import splitReactElement from './splitReactElement.js';
3
+ import splitReactElement from './splitReactElement.mjs';
4
4
  export default function getNestedBlockTags(blockHTML, depth) {
5
5
  invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
6
6
  if (typeof blockHTML.nest === 'function') {
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@20minutes/draft-convert",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "Extensibly serialize & deserialize Draft.js ContentState",
5
- "main": "lib/index.js",
6
- "types": "types/index.d.ts",
7
- "module": "esm/index.js",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./types/index.d.ts",
11
- "require": "./lib/index.js",
12
- "import": "./esm/index.js"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs",
13
+ "default": "./dist/index.mjs"
13
14
  }
14
15
  },
15
16
  "repository": "20minutes/draft-convert",
16
17
  "scripts": {
17
- "build": "yarn build:cjs && yarn build:esm",
18
- "build:cjs": "swc src -d lib --config-file .swcrc.cjs --strip-leading-paths --delete-dir-on-start",
19
- "build:esm": "swc src -d esm --config-file .swcrc.esm --strip-leading-paths --delete-dir-on-start",
18
+ "build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:types",
19
+ "build:cjs": "swc src -d dist --config-file .swcrc.cjs --strip-leading-paths && node scripts/rename-dist-cjs-entry.js",
20
+ "build:esm": "swc src -d dist --config-file .swcrc.esm --strip-leading-paths --delete-dir-on-start --out-file-extension mjs && node scripts/fix-dist-esm-imports.js",
21
+ "build:types": "node scripts/build-dist-types.js",
20
22
  "test": "jest",
21
23
  "test:watch": "jest --watch",
22
- "clean": "rimraf ./lib ./esm",
24
+ "clean": "rimraf ./dist ./lib ./esm",
23
25
  "build-and-test": "yarn clean && yarn test",
24
26
  "lint": "eslint src/ test/"
25
27
  },
26
28
  "files": [
27
- "types",
28
- "lib",
29
- "esm"
29
+ "dist"
30
30
  ],
31
31
  "keywords": [
32
32
  "draft",
package/esm/index.js DELETED
@@ -1,4 +0,0 @@
1
- import convertToHTML from './convertToHTML.js';
2
- import convertFromHTML from './convertFromHTML.js';
3
- import parseHTML from './util/parseHTML.js';
4
- export { convertToHTML, convertFromHTML, parseHTML };
package/types/index.d.ts DELETED
@@ -1,114 +0,0 @@
1
- // Based on: https://github.com/HubSpot/draft-convert/issues/107#issuecomment-488581709 by <https://github.com/sbusch>
2
- // Grabbed from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/draft-convert/index.d.ts
3
-
4
- declare module "@20minutes/draft-convert" {
5
- import {
6
- ContentState,
7
- DraftBlockType,
8
- DraftEntityMutability,
9
- DraftInlineStyleType,
10
- Entity,
11
- RawDraftContentBlock,
12
- RawDraftEntity,
13
- } from "draft-js";
14
- import { ReactNode } from "react";
15
-
16
- type RawDraftContentBlockWithCustomType<T> = Omit<RawDraftContentBlock, "type"> & {
17
- type: T;
18
- };
19
-
20
- type ExtendedHTMLElement<T> = (HTMLElement | HTMLLinkElement) & T;
21
-
22
- interface IConvertToHTMLConfig<
23
- S = DraftInlineStyleType,
24
- B extends DraftBlockType = DraftBlockType,
25
- E extends RawDraftEntity = RawDraftEntity,
26
- > {
27
- // Inline styles:
28
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
29
- styleToHTML?: ((style: S) => Tag | void) | undefined;
30
-
31
- // Block styles:
32
- blockToHTML?: ((block: RawDraftContentBlockWithCustomType<B>) => Tag) | undefined;
33
-
34
- // Entity styling:
35
- entityToHTML?: ((entity: E, originalText: string) => Tag) | undefined;
36
-
37
- // HTML validation:
38
- validateHTML?: ((html: string) => boolean) | undefined;
39
- }
40
-
41
- type EntityKey = string;
42
-
43
- interface IConvertFromHTMLConfig<
44
- S extends {
45
- [name: string]: unknown;
46
- } = DOMStringMap,
47
- B extends DraftBlockType = DraftBlockType,
48
- E extends RawDraftEntity = RawDraftEntity,
49
- > {
50
- // Inline styles:
51
- htmlToStyle?:
52
- | ((nodeName: string, node: ExtendedHTMLElement<S>, currentStyle: Set<string>) => Set<string>)
53
- | undefined;
54
-
55
- // Block styles:
56
- htmlToBlock?:
57
- | ((
58
- nodeName: string,
59
- node: ExtendedHTMLElement<S>,
60
- ) => B | { type: B; data: object } | false | undefined)
61
- | undefined;
62
-
63
- // Html entities
64
- htmlToEntity?:
65
- | ((
66
- nodeName: string,
67
- node: ExtendedHTMLElement<S>,
68
- createEntity: (type: E["type"], mutability: DraftEntityMutability, data: E["data"]) => EntityKey,
69
- getEntity: (key: EntityKey) => Entity,
70
- mergeEntityData: (key: string, data: object) => void,
71
- replaceEntityData: (key: string, data: object) => void,
72
- ) => EntityKey | undefined)
73
- | undefined;
74
-
75
- // Text entities
76
- textToEntity?:
77
- | ((
78
- text: string,
79
- createEntity: (type: E["type"], mutability: DraftEntityMutability, data: E["data"]) => EntityKey,
80
- getEntity: (key: EntityKey) => Entity,
81
- mergeEntityData: (key: string, data: object) => void,
82
- replaceEntityData: (key: string, data: object) => void,
83
- ) => Array<{
84
- entity: EntityKey;
85
- offset: number;
86
- length: number;
87
- result?: string | undefined;
88
- }>)
89
- | undefined;
90
- }
91
-
92
- type ContentStateConverter = (contentState: ContentState) => string;
93
- type HTMLConverter = (html: string) => ContentState;
94
-
95
- type Tag = ReactNode | { start: string; end: string; empty?: string | undefined } | {
96
- element: ReactNode;
97
- empty?: ReactNode | undefined;
98
- };
99
-
100
- export function convertToHTML<
101
- S = DraftInlineStyleType,
102
- B extends DraftBlockType = DraftBlockType,
103
- E extends RawDraftEntity = RawDraftEntity,
104
- >(config: IConvertToHTMLConfig<S, B, E>): ContentStateConverter;
105
- export function convertToHTML(contentState: ContentState): string;
106
- export function convertFromHTML<
107
- S extends {
108
- [name: string]: unknown;
109
- } = DOMStringMap,
110
- B extends DraftBlockType = DraftBlockType,
111
- E extends RawDraftEntity = RawDraftEntity,
112
- >(config: IConvertFromHTMLConfig<S, B, E>): HTMLConverter;
113
- export function convertFromHTML(html: string): ContentState;
114
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes