@os-design/editor 1.0.159 → 1.0.161
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.
- package/dist/cjs/Editor/BlockToolbar.js +4 -18
- package/dist/cjs/Editor/BlockToolbar.js.map +1 -1
- package/dist/cjs/Editor/StyleToolbar.js +6 -23
- package/dist/cjs/Editor/StyleToolbar.js.map +1 -1
- package/dist/cjs/Editor/Toolbar.js +0 -7
- package/dist/cjs/Editor/Toolbar.js.map +1 -1
- package/dist/cjs/Editor/ToolbarButton.js +2 -21
- package/dist/cjs/Editor/ToolbarButton.js.map +1 -1
- package/dist/cjs/Editor/blocks/Figure.js +0 -6
- package/dist/cjs/Editor/blocks/Figure.js.map +1 -1
- package/dist/cjs/Editor/blocks/FigureCaption.js +0 -7
- package/dist/cjs/Editor/blocks/FigureCaption.js.map +1 -1
- package/dist/cjs/Editor/blocks/imageBlock.js +12 -62
- package/dist/cjs/Editor/blocks/imageBlock.js.map +1 -1
- package/dist/cjs/Editor/blocks/videoBlock.js +4 -22
- package/dist/cjs/Editor/blocks/videoBlock.js.map +1 -1
- package/dist/cjs/Editor/decorators/linkDecorator.js +3 -9
- package/dist/cjs/Editor/decorators/linkDecorator.js.map +1 -1
- package/dist/cjs/Editor/hooks/useBlockToolbarProps.js +14 -32
- package/dist/cjs/Editor/hooks/useBlockToolbarProps.js.map +1 -1
- package/dist/cjs/Editor/hooks/usePastedTextHandler.js +0 -9
- package/dist/cjs/Editor/hooks/usePastedTextHandler.js.map +1 -1
- package/dist/cjs/Editor/hooks/useReturnHandler.js +0 -8
- package/dist/cjs/Editor/hooks/useReturnHandler.js.map +1 -1
- package/dist/cjs/Editor/hooks/useStyleToolbarProps.js +16 -29
- package/dist/cjs/Editor/hooks/useStyleToolbarProps.js.map +1 -1
- package/dist/cjs/Editor/index.js +41 -76
- package/dist/cjs/Editor/index.js.map +1 -1
- package/dist/cjs/Editor/styles/defaultDraftJsStyles.js +0 -4
- package/dist/cjs/Editor/styles/defaultDraftJsStyles.js.map +1 -1
- package/dist/cjs/Editor/styles/overrideDraftJsStyles.js +0 -6
- package/dist/cjs/Editor/styles/overrideDraftJsStyles.js.map +1 -1
- package/dist/cjs/Editor/utils/addNewBlockAt.js +0 -5
- package/dist/cjs/Editor/utils/addNewBlockAt.js.map +1 -1
- package/dist/cjs/Editor/utils/changeBlock.js +0 -3
- package/dist/cjs/Editor/utils/changeBlock.js.map +1 -1
- package/dist/cjs/Editor/utils/createContentEditorState.js +0 -5
- package/dist/cjs/Editor/utils/createContentEditorState.js.map +1 -1
- package/dist/cjs/Editor/utils/createDecorator.js +0 -5
- package/dist/cjs/Editor/utils/createDecorator.js.map +1 -1
- package/dist/cjs/Editor/utils/createEmptyEditorState.js +0 -5
- package/dist/cjs/Editor/utils/createEmptyEditorState.js.map +1 -1
- package/dist/cjs/Editor/utils/defaultStyleToolbarItems.js +0 -7
- package/dist/cjs/Editor/utils/defaultStyleToolbarItems.js.map +1 -1
- package/dist/cjs/Editor/utils/getCurrentBlock.js +0 -2
- package/dist/cjs/Editor/utils/getCurrentBlock.js.map +1 -1
- package/dist/cjs/Editor/utils/getSelectedBlockElement.js +0 -6
- package/dist/cjs/Editor/utils/getSelectedBlockElement.js.map +1 -1
- package/dist/cjs/Editor/utils/getSelectionRange.js +0 -2
- package/dist/cjs/Editor/utils/getSelectionRange.js.map +1 -1
- package/dist/cjs/Editor/utils/setLink.js +0 -6
- package/dist/cjs/Editor/utils/setLink.js.map +1 -1
- package/dist/cjs/Editor/utils/transformers.js +0 -4
- package/dist/cjs/Editor/utils/transformers.js.map +1 -1
- package/dist/cjs/Editor/utils/unsetLink.js +0 -4
- package/dist/cjs/Editor/utils/unsetLink.js.map +1 -1
- package/dist/cjs/EditorSkeleton/index.js +1 -12
- package/dist/cjs/EditorSkeleton/index.js.map +1 -1
- package/dist/cjs/index.js +0 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Editor/BlockToolbar.js +0 -2
- package/dist/esm/Editor/BlockToolbar.js.map +1 -1
- package/dist/esm/Editor/StyleToolbar.js +2 -5
- package/dist/esm/Editor/StyleToolbar.js.map +1 -1
- package/dist/esm/Editor/Toolbar.js.map +1 -1
- package/dist/esm/Editor/ToolbarButton.js +0 -5
- package/dist/esm/Editor/ToolbarButton.js.map +1 -1
- package/dist/esm/Editor/blocks/Figure.js.map +1 -1
- package/dist/esm/Editor/blocks/FigureCaption.js.map +1 -1
- package/dist/esm/Editor/blocks/imageBlock.js +9 -15
- package/dist/esm/Editor/blocks/imageBlock.js.map +1 -1
- package/dist/esm/Editor/blocks/videoBlock.js +0 -5
- package/dist/esm/Editor/blocks/videoBlock.js.map +1 -1
- package/dist/esm/Editor/decorators/linkDecorator.js.map +1 -1
- package/dist/esm/Editor/hooks/useBlockToolbarProps.js +0 -6
- package/dist/esm/Editor/hooks/useBlockToolbarProps.js.map +1 -1
- package/dist/esm/Editor/hooks/usePastedTextHandler.js +0 -4
- package/dist/esm/Editor/hooks/usePastedTextHandler.js.map +1 -1
- package/dist/esm/Editor/hooks/useReturnHandler.js +0 -4
- package/dist/esm/Editor/hooks/useReturnHandler.js.map +1 -1
- package/dist/esm/Editor/hooks/useStyleToolbarProps.js +5 -6
- package/dist/esm/Editor/hooks/useStyleToolbarProps.js.map +1 -1
- package/dist/esm/Editor/index.js +10 -10
- package/dist/esm/Editor/index.js.map +1 -1
- package/dist/esm/Editor/styles/defaultDraftJsStyles.js +1 -1
- package/dist/esm/Editor/styles/defaultDraftJsStyles.js.map +1 -1
- package/dist/esm/Editor/styles/overrideDraftJsStyles.js +2 -2
- package/dist/esm/Editor/styles/overrideDraftJsStyles.js.map +1 -1
- package/dist/esm/Editor/utils/addNewBlockAt.js +0 -2
- package/dist/esm/Editor/utils/addNewBlockAt.js.map +1 -1
- package/dist/esm/Editor/utils/changeBlock.js +0 -2
- package/dist/esm/Editor/utils/changeBlock.js.map +1 -1
- package/dist/esm/Editor/utils/createContentEditorState.js +0 -2
- package/dist/esm/Editor/utils/createContentEditorState.js.map +1 -1
- package/dist/esm/Editor/utils/createDecorator.js +0 -2
- package/dist/esm/Editor/utils/createDecorator.js.map +1 -1
- package/dist/esm/Editor/utils/createEmptyEditorState.js +0 -2
- package/dist/esm/Editor/utils/createEmptyEditorState.js.map +1 -1
- package/dist/esm/Editor/utils/defaultStyleToolbarItems.js.map +1 -1
- package/dist/esm/Editor/utils/getCurrentBlock.js +0 -1
- package/dist/esm/Editor/utils/getCurrentBlock.js.map +1 -1
- package/dist/esm/Editor/utils/getSelectedBlockElement.js +0 -4
- package/dist/esm/Editor/utils/getSelectedBlockElement.js.map +1 -1
- package/dist/esm/Editor/utils/getSelectionRange.js +0 -1
- package/dist/esm/Editor/utils/getSelectionRange.js.map +1 -1
- package/dist/esm/Editor/utils/setLink.js +0 -2
- package/dist/esm/Editor/utils/setLink.js.map +1 -1
- package/dist/esm/Editor/utils/transformers.js.map +1 -1
- package/dist/esm/Editor/utils/unsetLink.js +0 -2
- package/dist/esm/Editor/utils/unsetLink.js.map +1 -1
- package/dist/esm/EditorSkeleton/index.js +1 -2
- package/dist/esm/EditorSkeleton/index.js.map +1 -1
- package/dist/esm/emotion.d.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -6,7 +6,6 @@ import FigureCaption from './FigureCaption';
|
|
|
6
6
|
import changeBlock from '../utils/changeBlock';
|
|
7
7
|
import getCurrentBlock from '../utils/getCurrentBlock';
|
|
8
8
|
import Figure from './Figure';
|
|
9
|
-
|
|
10
9
|
const VideoBlock = props => {
|
|
11
10
|
const {
|
|
12
11
|
block
|
|
@@ -19,7 +18,6 @@ const VideoBlock = props => {
|
|
|
19
18
|
title: block.getText()
|
|
20
19
|
}), /*#__PURE__*/React.createElement(FigureCaption, null, /*#__PURE__*/React.createElement(EditorBlock, props)));
|
|
21
20
|
};
|
|
22
|
-
|
|
23
21
|
const videoTypes = [
|
|
24
22
|
/**
|
|
25
23
|
* YouTube. Supported formats:
|
|
@@ -40,7 +38,6 @@ const videoTypes = [
|
|
|
40
38
|
re: /^https:\/\/rutube\.ru\/(?:video|play\/embed)\/([a-z0-9]*)\/?$/,
|
|
41
39
|
getUrl: id => `https://rutube.ru/play/embed/${id}`
|
|
42
40
|
}];
|
|
43
|
-
|
|
44
41
|
const detectVideo = url => {
|
|
45
42
|
// eslint-disable-next-line no-restricted-syntax
|
|
46
43
|
for (const {
|
|
@@ -50,10 +47,8 @@ const detectVideo = url => {
|
|
|
50
47
|
const groups = url.match(re);
|
|
51
48
|
if (groups && groups[1]) return getUrl(groups[1]);
|
|
52
49
|
}
|
|
53
|
-
|
|
54
50
|
return null;
|
|
55
51
|
};
|
|
56
|
-
|
|
57
52
|
export const VIDEO_BLOCK = 'atomic:video';
|
|
58
53
|
const videoBlock = {
|
|
59
54
|
type: VIDEO_BLOCK,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"videoBlock.js","names":["React","EditorBlock","Video","VideoIcon","FigureCaption","changeBlock","getCurrentBlock","Figure","VideoBlock","props","block","data","getData","src","get","getText","videoTypes","re","getUrl","id","detectVideo","url","groups","match","VIDEO_BLOCK","videoBlock","type","component","icon","onClick","value","onChange","prompt","currentBlock","nextEditorState"],"sources":["../../../../src/Editor/blocks/videoBlock.tsx"],"sourcesContent":["import React from 'react';\nimport { EditorBlock } from 'draft-js';\nimport { Video } from '@os-design/core';\nimport { Video as VideoIcon } from '@os-design/icons';\nimport { BlockToolbarItem, BlockProps } from './types';\nimport FigureCaption from './FigureCaption';\nimport changeBlock from '../utils/changeBlock';\nimport getCurrentBlock from '../utils/getCurrentBlock';\nimport Figure from './Figure';\n\nconst VideoBlock: React.FC<BlockProps> = (props) => {\n const { block } = props;\n const data = block.getData();\n const src = data.get('src');\n\n if (!src) return null;\n\n return (\n <Figure>\n <Video src={src} title={block.getText()} />\n <FigureCaption>\n <EditorBlock {...props} />\n </FigureCaption>\n </Figure>\n );\n};\n\nconst videoTypes = [\n /**\n * YouTube. Supported formats:\n * https://www.youtube.com/watch?v=FJIhWbUt600&ab_channel=IlyaOrdin\n * https://www.youtube.com/embed/FJIhWbUt600\n * https://youtu.be/FJIhWbUt600\n */\n {\n re: /^https:\\/\\/(?:www\\.youtube\\.com\\/(?:watch\\?v=|embed\\/)|youtu\\.be\\/)([A-z0-9-_]*).*$/,\n getUrl: (id: string) => `https://www.youtube.com/embed/${id}`,\n },\n /**\n * RuTube. Supported formats:\n * https://rutube.ru/video/d00526135b2b96d272f6d89b486036c1/\n * https://rutube.ru/play/embed/d00526135b2b96d272f6d89b486036c1\n */\n {\n re: /^https:\\/\\/rutube\\.ru\\/(?:video|play\\/embed)\\/([a-z0-9]*)\\/?$/,\n getUrl: (id: string) => `https://rutube.ru/play/embed/${id}`,\n },\n];\n\nconst detectVideo = (url: string) => {\n // eslint-disable-next-line no-restricted-syntax\n for (const { re, getUrl } of videoTypes) {\n const groups = url.match(re);\n if (groups && groups[1]) return getUrl(groups[1]);\n }\n return null;\n};\n\nexport const VIDEO_BLOCK = 'atomic:video';\n\nconst videoBlock: BlockToolbarItem = {\n type: VIDEO_BLOCK,\n component: VideoBlock,\n icon: <VideoIcon />,\n onClick: ({ value, onChange }) => {\n // eslint-disable-next-line no-alert\n const url = prompt('Insert a link to YouTube or RuTube');\n if (!url) return;\n\n const src = detectVideo(url);\n if (!src) return;\n\n const currentBlock = getCurrentBlock(value);\n const nextEditorState = changeBlock(value, currentBlock, VIDEO_BLOCK, {\n src,\n });\n\n onChange(nextEditorState);\n },\n};\n\nexport default videoBlock;\n"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"videoBlock.js","names":["React","EditorBlock","Video","VideoIcon","FigureCaption","changeBlock","getCurrentBlock","Figure","VideoBlock","props","block","data","getData","src","get","getText","videoTypes","re","getUrl","id","detectVideo","url","groups","match","VIDEO_BLOCK","videoBlock","type","component","icon","onClick","value","onChange","prompt","currentBlock","nextEditorState"],"sources":["../../../../src/Editor/blocks/videoBlock.tsx"],"sourcesContent":["import React from 'react';\nimport { EditorBlock } from 'draft-js';\nimport { Video } from '@os-design/core';\nimport { Video as VideoIcon } from '@os-design/icons';\nimport { BlockToolbarItem, BlockProps } from './types';\nimport FigureCaption from './FigureCaption';\nimport changeBlock from '../utils/changeBlock';\nimport getCurrentBlock from '../utils/getCurrentBlock';\nimport Figure from './Figure';\n\nconst VideoBlock: React.FC<BlockProps> = (props) => {\n const { block } = props;\n const data = block.getData();\n const src = data.get('src');\n\n if (!src) return null;\n\n return (\n <Figure>\n <Video src={src} title={block.getText()} />\n <FigureCaption>\n <EditorBlock {...props} />\n </FigureCaption>\n </Figure>\n );\n};\n\nconst videoTypes = [\n /**\n * YouTube. Supported formats:\n * https://www.youtube.com/watch?v=FJIhWbUt600&ab_channel=IlyaOrdin\n * https://www.youtube.com/embed/FJIhWbUt600\n * https://youtu.be/FJIhWbUt600\n */\n {\n re: /^https:\\/\\/(?:www\\.youtube\\.com\\/(?:watch\\?v=|embed\\/)|youtu\\.be\\/)([A-z0-9-_]*).*$/,\n getUrl: (id: string) => `https://www.youtube.com/embed/${id}`,\n },\n /**\n * RuTube. Supported formats:\n * https://rutube.ru/video/d00526135b2b96d272f6d89b486036c1/\n * https://rutube.ru/play/embed/d00526135b2b96d272f6d89b486036c1\n */\n {\n re: /^https:\\/\\/rutube\\.ru\\/(?:video|play\\/embed)\\/([a-z0-9]*)\\/?$/,\n getUrl: (id: string) => `https://rutube.ru/play/embed/${id}`,\n },\n];\n\nconst detectVideo = (url: string) => {\n // eslint-disable-next-line no-restricted-syntax\n for (const { re, getUrl } of videoTypes) {\n const groups = url.match(re);\n if (groups && groups[1]) return getUrl(groups[1]);\n }\n return null;\n};\n\nexport const VIDEO_BLOCK = 'atomic:video';\n\nconst videoBlock: BlockToolbarItem = {\n type: VIDEO_BLOCK,\n component: VideoBlock,\n icon: <VideoIcon />,\n onClick: ({ value, onChange }) => {\n // eslint-disable-next-line no-alert\n const url = prompt('Insert a link to YouTube or RuTube');\n if (!url) return;\n\n const src = detectVideo(url);\n if (!src) return;\n\n const currentBlock = getCurrentBlock(value);\n const nextEditorState = changeBlock(value, currentBlock, VIDEO_BLOCK, {\n src,\n });\n\n onChange(nextEditorState);\n },\n};\n\nexport default videoBlock;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,QAAQ,UAAU;AACtC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASA,KAAK,IAAIC,SAAS,QAAQ,kBAAkB;AAErD,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,WAAW,MAAM,sBAAsB;AAC9C,OAAOC,eAAe,MAAM,0BAA0B;AACtD,OAAOC,MAAM,MAAM,UAAU;AAE7B,MAAMC,UAAgC,GAAIC,KAAK,IAAK;EAClD,MAAM;IAAEC;EAAM,CAAC,GAAGD,KAAK;EACvB,MAAME,IAAI,GAAGD,KAAK,CAACE,OAAO,EAAE;EAC5B,MAAMC,GAAG,GAAGF,IAAI,CAACG,GAAG,CAAC,KAAK,CAAC;EAE3B,IAAI,CAACD,GAAG,EAAE,OAAO,IAAI;EAErB,oBACE,oBAAC,MAAM,qBACL,oBAAC,KAAK;IAAC,GAAG,EAAEA,GAAI;IAAC,KAAK,EAAEH,KAAK,CAACK,OAAO;EAAG,EAAG,eAC3C,oBAAC,aAAa,qBACZ,oBAAC,WAAW,EAAKN,KAAK,CAAI,CACZ,CACT;AAEb,CAAC;AAED,MAAMO,UAAU,GAAG;AACjB;AACF;AACA;AACA;AACA;AACA;AACE;EACEC,EAAE,EAAE,qFAAqF;EACzFC,MAAM,EAAGC,EAAU,IAAM,iCAAgCA,EAAG;AAC9D,CAAC;AACD;AACF;AACA;AACA;AACA;AACE;EACEF,EAAE,EAAE,+DAA+D;EACnEC,MAAM,EAAGC,EAAU,IAAM,gCAA+BA,EAAG;AAC7D,CAAC,CACF;AAED,MAAMC,WAAW,GAAIC,GAAW,IAAK;EACnC;EACA,KAAK,MAAM;IAAEJ,EAAE;IAAEC;EAAO,CAAC,IAAIF,UAAU,EAAE;IACvC,MAAMM,MAAM,GAAGD,GAAG,CAACE,KAAK,CAACN,EAAE,CAAC;IAC5B,IAAIK,MAAM,IAAIA,MAAM,CAAC,CAAC,CAAC,EAAE,OAAOJ,MAAM,CAACI,MAAM,CAAC,CAAC,CAAC,CAAC;EACnD;EACA,OAAO,IAAI;AACb,CAAC;AAED,OAAO,MAAME,WAAW,GAAG,cAAc;AAEzC,MAAMC,UAA4B,GAAG;EACnCC,IAAI,EAAEF,WAAW;EACjBG,SAAS,EAAEnB,UAAU;EACrBoB,IAAI,eAAE,oBAAC,SAAS,OAAG;EACnBC,OAAO,EAAE,CAAC;IAAEC,KAAK;IAAEC;EAAS,CAAC,KAAK;IAChC;IACA,MAAMV,GAAG,GAAGW,MAAM,CAAC,oCAAoC,CAAC;IACxD,IAAI,CAACX,GAAG,EAAE;IAEV,MAAMR,GAAG,GAAGO,WAAW,CAACC,GAAG,CAAC;IAC5B,IAAI,CAACR,GAAG,EAAE;IAEV,MAAMoB,YAAY,GAAG3B,eAAe,CAACwB,KAAK,CAAC;IAC3C,MAAMI,eAAe,GAAG7B,WAAW,CAACyB,KAAK,EAAEG,YAAY,EAAET,WAAW,EAAE;MACpEX;IACF,CAAC,CAAC;IAEFkB,QAAQ,CAACG,eAAe,CAAC;EAC3B;AACF,CAAC;AAED,eAAeT,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkDecorator.js","names":["Link","React","linkDecorator","strategy","contentBlock","callback","contentState","findEntityRanges","character","entityKey","getEntity","getType","component","children","url","getData"],"sources":["../../../../src/Editor/decorators/linkDecorator.tsx"],"sourcesContent":["import { DraftDecorator } from 'draft-js';\nimport { Link } from '@os-design/core';\nimport React from 'react';\n\nconst linkDecorator: DraftDecorator = {\n strategy: (contentBlock, callback, contentState) =>\n contentBlock.findEntityRanges((character) => {\n const entityKey = character.getEntity();\n return (\n entityKey !== null &&\n contentState.getEntity(entityKey).getType() === 'LINK'\n );\n }, callback),\n\n component: ({ contentState, entityKey, children }) => {\n const { url } = contentState.getEntity(entityKey).getData();\n return <Link href={url}>{children}</Link>;\n },\n};\n\nexport default linkDecorator;\n"],"mappings":"AACA,SAASA,
|
|
1
|
+
{"version":3,"file":"linkDecorator.js","names":["Link","React","linkDecorator","strategy","contentBlock","callback","contentState","findEntityRanges","character","entityKey","getEntity","getType","component","children","url","getData"],"sources":["../../../../src/Editor/decorators/linkDecorator.tsx"],"sourcesContent":["import { DraftDecorator } from 'draft-js';\nimport { Link } from '@os-design/core';\nimport React from 'react';\n\nconst linkDecorator: DraftDecorator = {\n strategy: (contentBlock, callback, contentState) =>\n contentBlock.findEntityRanges((character) => {\n const entityKey = character.getEntity();\n return (\n entityKey !== null &&\n contentState.getEntity(entityKey).getType() === 'LINK'\n );\n }, callback),\n\n component: ({ contentState, entityKey, children }) => {\n const { url } = contentState.getEntity(entityKey).getData();\n return <Link href={url}>{children}</Link>;\n },\n};\n\nexport default linkDecorator;\n"],"mappings":"AACA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAOC,KAAK,MAAM,OAAO;AAEzB,MAAMC,aAA6B,GAAG;EACpCC,QAAQ,EAAE,CAACC,YAAY,EAAEC,QAAQ,EAAEC,YAAY,KAC7CF,YAAY,CAACG,gBAAgB,CAAEC,SAAS,IAAK;IAC3C,MAAMC,SAAS,GAAGD,SAAS,CAACE,SAAS,EAAE;IACvC,OACED,SAAS,KAAK,IAAI,IAClBH,YAAY,CAACI,SAAS,CAACD,SAAS,CAAC,CAACE,OAAO,EAAE,KAAK,MAAM;EAE1D,CAAC,EAAEN,QAAQ,CAAC;EAEdO,SAAS,EAAE,CAAC;IAAEN,YAAY;IAAEG,SAAS;IAAEI;EAAS,CAAC,KAAK;IACpD,MAAM;MAAEC;IAAI,CAAC,GAAGR,YAAY,CAACI,SAAS,CAACD,SAAS,CAAC,CAACM,OAAO,EAAE;IAC3D,oBAAO,oBAAC,IAAI;MAAC,IAAI,EAAED;IAAI,GAAED,QAAQ,CAAQ;EAC3C;AACF,CAAC;AAED,eAAeX,aAAa"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import getSelectedBlockElement from '../utils/getSelectedBlockElement';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Updates the visibility of the block toolbar.
|
|
6
5
|
*/
|
|
@@ -15,23 +14,19 @@ const useBlockToolbarProps = (value, show) => {
|
|
|
15
14
|
useEffect(() => {
|
|
16
15
|
if (!show || !value) return;
|
|
17
16
|
const selectedBlockElement = getSelectedBlockElement();
|
|
18
|
-
|
|
19
17
|
if (!selectedBlockElement) {
|
|
20
18
|
setVisible(false);
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
const selectionState = value.getSelection();
|
|
25
22
|
const currentBlockKey = selectionState.getStartKey();
|
|
26
23
|
const contentState = value.getCurrentContent();
|
|
27
24
|
const currentBlock = contentState.getBlockForKey(currentBlockKey);
|
|
28
25
|
const lineNumber = contentState.getBlockMap().keySeq().findIndex(k => k === currentBlockKey);
|
|
29
|
-
|
|
30
26
|
if (currentBlock.getType() !== 'unstyled' || currentBlock.getLength() > 0 || lineNumber === 0) {
|
|
31
27
|
setVisible(false);
|
|
32
28
|
return;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
const {
|
|
36
31
|
top,
|
|
37
32
|
left,
|
|
@@ -50,6 +45,5 @@ const useBlockToolbarProps = (value, show) => {
|
|
|
50
45
|
visible
|
|
51
46
|
};
|
|
52
47
|
};
|
|
53
|
-
|
|
54
48
|
export default useBlockToolbarProps;
|
|
55
49
|
//# sourceMappingURL=useBlockToolbarProps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockToolbarProps.js","names":["useEffect","useState","getSelectedBlockElement","useBlockToolbarProps","value","show","trigger","setTrigger","top","left","width","height","visible","setVisible","selectedBlockElement","selectionState","getSelection","currentBlockKey","getStartKey","contentState","getCurrentContent","currentBlock","getBlockForKey","lineNumber","getBlockMap","keySeq","findIndex","k","getType","getLength","getBoundingClientRect"],"sources":["../../../../src/Editor/hooks/useBlockToolbarProps.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { EditorState } from 'draft-js';\nimport getSelectedBlockElement from '../utils/getSelectedBlockElement';\n\ninterface Rect {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\ninterface UseBlockToolbarPropsRes {\n trigger: Rect;\n visible: boolean;\n}\n\n/**\n * Updates the visibility of the block toolbar.\n */\nconst useBlockToolbarProps = (\n value: EditorState,\n show: boolean\n): UseBlockToolbarPropsRes => {\n const [trigger, setTrigger] = useState({\n top: 0,\n left: 0,\n width: 0,\n height: 0,\n });\n const [visible, setVisible] = useState(false);\n\n useEffect(() => {\n if (!show || !value) return;\n\n const selectedBlockElement = getSelectedBlockElement();\n if (!selectedBlockElement) {\n setVisible(false);\n return;\n }\n\n const selectionState = value.getSelection();\n const currentBlockKey = selectionState.getStartKey();\n const contentState = value.getCurrentContent();\n const currentBlock = contentState.getBlockForKey(currentBlockKey);\n const lineNumber = contentState\n .getBlockMap()\n .keySeq()\n .findIndex((k) => k === currentBlockKey);\n\n if (\n currentBlock.getType() !== 'unstyled' ||\n currentBlock.getLength() > 0 ||\n lineNumber === 0\n ) {\n setVisible(false);\n return;\n }\n\n const { top, left, height } = selectedBlockElement.getBoundingClientRect();\n setTrigger({\n top,\n left,\n width: 0,\n height,\n });\n setVisible(true);\n }, [show, value]);\n\n return { trigger, visible };\n};\n\nexport default useBlockToolbarProps;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useBlockToolbarProps.js","names":["useEffect","useState","getSelectedBlockElement","useBlockToolbarProps","value","show","trigger","setTrigger","top","left","width","height","visible","setVisible","selectedBlockElement","selectionState","getSelection","currentBlockKey","getStartKey","contentState","getCurrentContent","currentBlock","getBlockForKey","lineNumber","getBlockMap","keySeq","findIndex","k","getType","getLength","getBoundingClientRect"],"sources":["../../../../src/Editor/hooks/useBlockToolbarProps.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { EditorState } from 'draft-js';\nimport getSelectedBlockElement from '../utils/getSelectedBlockElement';\n\ninterface Rect {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\ninterface UseBlockToolbarPropsRes {\n trigger: Rect;\n visible: boolean;\n}\n\n/**\n * Updates the visibility of the block toolbar.\n */\nconst useBlockToolbarProps = (\n value: EditorState,\n show: boolean\n): UseBlockToolbarPropsRes => {\n const [trigger, setTrigger] = useState({\n top: 0,\n left: 0,\n width: 0,\n height: 0,\n });\n const [visible, setVisible] = useState(false);\n\n useEffect(() => {\n if (!show || !value) return;\n\n const selectedBlockElement = getSelectedBlockElement();\n if (!selectedBlockElement) {\n setVisible(false);\n return;\n }\n\n const selectionState = value.getSelection();\n const currentBlockKey = selectionState.getStartKey();\n const contentState = value.getCurrentContent();\n const currentBlock = contentState.getBlockForKey(currentBlockKey);\n const lineNumber = contentState\n .getBlockMap()\n .keySeq()\n .findIndex((k) => k === currentBlockKey);\n\n if (\n currentBlock.getType() !== 'unstyled' ||\n currentBlock.getLength() > 0 ||\n lineNumber === 0\n ) {\n setVisible(false);\n return;\n }\n\n const { top, left, height } = selectedBlockElement.getBoundingClientRect();\n setTrigger({\n top,\n left,\n width: 0,\n height,\n });\n setVisible(true);\n }, [show, value]);\n\n return { trigger, visible };\n};\n\nexport default useBlockToolbarProps;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE3C,OAAOC,uBAAuB,MAAM,kCAAkC;AActE;AACA;AACA;AACA,MAAMC,oBAAoB,GAAG,CAC3BC,KAAkB,EAClBC,IAAa,KACe;EAC5B,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGN,QAAQ,CAAC;IACrCO,GAAG,EAAE,CAAC;IACNC,IAAI,EAAE,CAAC;IACPC,KAAK,EAAE,CAAC;IACRC,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|
import { EditorState, Modifier, RichUtils } from 'draft-js';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Pastes only text if the current block is atomic.
|
|
6
5
|
*/
|
|
7
6
|
const usePastedTextHandler = (onChange, handler) => useCallback((text, html, editorState) => {
|
|
8
7
|
const currentBlockType = RichUtils.getCurrentBlockType(editorState);
|
|
9
|
-
|
|
10
8
|
if (currentBlockType.startsWith('atomic')) {
|
|
11
9
|
const contentState = editorState.getCurrentContent();
|
|
12
10
|
const nextContentState = Modifier.insertText(contentState, editorState.getSelection(), text);
|
|
@@ -14,9 +12,7 @@ const usePastedTextHandler = (onChange, handler) => useCallback((text, html, edi
|
|
|
14
12
|
onChange(nextEditorState);
|
|
15
13
|
return 'handled';
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return handler(text, html, editorState);
|
|
19
16
|
}, [onChange, handler]);
|
|
20
|
-
|
|
21
17
|
export default usePastedTextHandler;
|
|
22
18
|
//# sourceMappingURL=usePastedTextHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePastedTextHandler.js","names":["useCallback","EditorState","Modifier","RichUtils","usePastedTextHandler","onChange","handler","text","html","editorState","currentBlockType","getCurrentBlockType","startsWith","contentState","getCurrentContent","nextContentState","insertText","getSelection","nextEditorState","push"],"sources":["../../../../src/Editor/hooks/usePastedTextHandler.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport {\n DraftHandleValue,\n EditorProps as DraftEditorProps,\n EditorState,\n Modifier,\n RichUtils,\n} from 'draft-js';\n\ntype UsePastedTextHandlerRes = Exclude<\n DraftEditorProps['handlePastedText'],\n undefined\n>;\n\n/**\n * Pastes only text if the current block is atomic.\n */\nconst usePastedTextHandler = (\n onChange: (value: EditorState) => void,\n handler: UsePastedTextHandlerRes\n): UsePastedTextHandlerRes =>\n useCallback<UsePastedTextHandlerRes>(\n (text, html, editorState): DraftHandleValue => {\n const currentBlockType = RichUtils.getCurrentBlockType(editorState);\n\n if (currentBlockType.startsWith('atomic')) {\n const contentState = editorState.getCurrentContent();\n const nextContentState = Modifier.insertText(\n contentState,\n editorState.getSelection(),\n text\n );\n const nextEditorState = EditorState.push(\n editorState,\n nextContentState,\n 'insert-characters'\n );\n onChange(nextEditorState);\n return 'handled';\n }\n\n return handler(text, html, editorState);\n },\n [onChange, handler]\n );\n\nexport default usePastedTextHandler;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"usePastedTextHandler.js","names":["useCallback","EditorState","Modifier","RichUtils","usePastedTextHandler","onChange","handler","text","html","editorState","currentBlockType","getCurrentBlockType","startsWith","contentState","getCurrentContent","nextContentState","insertText","getSelection","nextEditorState","push"],"sources":["../../../../src/Editor/hooks/usePastedTextHandler.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport {\n DraftHandleValue,\n EditorProps as DraftEditorProps,\n EditorState,\n Modifier,\n RichUtils,\n} from 'draft-js';\n\ntype UsePastedTextHandlerRes = Exclude<\n DraftEditorProps['handlePastedText'],\n undefined\n>;\n\n/**\n * Pastes only text if the current block is atomic.\n */\nconst usePastedTextHandler = (\n onChange: (value: EditorState) => void,\n handler: UsePastedTextHandlerRes\n): UsePastedTextHandlerRes =>\n useCallback<UsePastedTextHandlerRes>(\n (text, html, editorState): DraftHandleValue => {\n const currentBlockType = RichUtils.getCurrentBlockType(editorState);\n\n if (currentBlockType.startsWith('atomic')) {\n const contentState = editorState.getCurrentContent();\n const nextContentState = Modifier.insertText(\n contentState,\n editorState.getSelection(),\n text\n );\n const nextEditorState = EditorState.push(\n editorState,\n nextContentState,\n 'insert-characters'\n );\n onChange(nextEditorState);\n return 'handled';\n }\n\n return handler(text, html, editorState);\n },\n [onChange, handler]\n );\n\nexport default usePastedTextHandler;\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AACnC,SAGEC,WAAW,EACXC,QAAQ,EACRC,SAAS,QACJ,UAAU;AAOjB;AACA;AACA;AACA,MAAMC,oBAAoB,GAAG,CAC3BC,QAAsC,EACtCC,OAAgC,KAEhCN,WAAW,CACT,CAACO,IAAI,EAAEC,IAAI,EAAEC,WAAW,KAAuB;EAC7C,MAAMC,gBAAgB,GAAGP,SAAS,CAACQ,mBAAmB,CAACF,WAAW,CAAC;EAEnE,IAAIC,gBAAgB,CAACE,UAAU,CAAC,QAAQ,CAAC,EAAE;IACzC,MAAMC,YAAY,GAAGJ,WAAW,CAACK,iBAAiB,EAAE;IACpD,MAAMC,gBAAgB,GAAGb,QAAQ,CAACc,UAAU,CAC1CH,YAAY,EACZJ,WAAW,CAACQ,YAAY,EAAE,EAC1BV,IAAI,CACL;IACD,MAAMW,eAAe,GAAGjB,WAAW,CAACkB,IAAI,CACtCV,WAAW,EACXM,gBAAgB,EAChB,mBAAmB,CACpB;IACDV,QAAQ,CAACa,eAAe,CAAC;IACzB,OAAO,SAAS;EAClB;EAEA,OAAOZ,OAAO,CAACC,IAAI,EAAEC,IAAI,EAAEC,WAAW,CAAC;AACzC,CAAC,EACD,CAACJ,QAAQ,EAAEC,OAAO,CAAC,CACpB;AAEH,eAAeF,oBAAoB"}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import getCurrentBlock from '../utils/getCurrentBlock';
|
|
3
3
|
import addNewBlockAt from '../utils/addNewBlockAt';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Adds a new unstyled block if the user presses the return key.
|
|
7
6
|
*/
|
|
8
7
|
const useReturnHandler = (onChange, handler) => useCallback((e, editorState) => {
|
|
9
8
|
const currentBlock = getCurrentBlock(editorState);
|
|
10
9
|
const currentBlockType = currentBlock.getType();
|
|
11
|
-
|
|
12
10
|
if (currentBlockType.startsWith('atomic') || currentBlockType.startsWith('header')) {
|
|
13
11
|
const nextEditorState = addNewBlockAt(editorState, currentBlock.getKey());
|
|
14
12
|
onChange(nextEditorState);
|
|
15
13
|
return 'handled';
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return handler(e, editorState);
|
|
19
16
|
}, [onChange, handler]);
|
|
20
|
-
|
|
21
17
|
export default useReturnHandler;
|
|
22
18
|
//# sourceMappingURL=useReturnHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReturnHandler.js","names":["useCallback","getCurrentBlock","addNewBlockAt","useReturnHandler","onChange","handler","e","editorState","currentBlock","currentBlockType","getType","startsWith","nextEditorState","getKey"],"sources":["../../../../src/Editor/hooks/useReturnHandler.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { EditorProps as DraftEditorProps, EditorState } from 'draft-js';\nimport getCurrentBlock from '../utils/getCurrentBlock';\nimport addNewBlockAt from '../utils/addNewBlockAt';\n\ntype UseReturnHandlerRes = Exclude<DraftEditorProps['handleReturn'], undefined>;\n\n/**\n * Adds a new unstyled block if the user presses the return key.\n */\nconst useReturnHandler = (\n onChange: (value: EditorState) => void,\n handler: UseReturnHandlerRes\n): UseReturnHandlerRes =>\n useCallback<UseReturnHandlerRes>(\n (e, editorState) => {\n const currentBlock = getCurrentBlock(editorState);\n const currentBlockType = currentBlock.getType();\n\n if (\n currentBlockType.startsWith('atomic') ||\n currentBlockType.startsWith('header')\n ) {\n const nextEditorState = addNewBlockAt(\n editorState,\n currentBlock.getKey()\n );\n onChange(nextEditorState);\n return 'handled';\n }\n\n return handler(e, editorState);\n },\n [onChange, handler]\n );\n\nexport default useReturnHandler;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useReturnHandler.js","names":["useCallback","getCurrentBlock","addNewBlockAt","useReturnHandler","onChange","handler","e","editorState","currentBlock","currentBlockType","getType","startsWith","nextEditorState","getKey"],"sources":["../../../../src/Editor/hooks/useReturnHandler.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { EditorProps as DraftEditorProps, EditorState } from 'draft-js';\nimport getCurrentBlock from '../utils/getCurrentBlock';\nimport addNewBlockAt from '../utils/addNewBlockAt';\n\ntype UseReturnHandlerRes = Exclude<DraftEditorProps['handleReturn'], undefined>;\n\n/**\n * Adds a new unstyled block if the user presses the return key.\n */\nconst useReturnHandler = (\n onChange: (value: EditorState) => void,\n handler: UseReturnHandlerRes\n): UseReturnHandlerRes =>\n useCallback<UseReturnHandlerRes>(\n (e, editorState) => {\n const currentBlock = getCurrentBlock(editorState);\n const currentBlockType = currentBlock.getType();\n\n if (\n currentBlockType.startsWith('atomic') ||\n currentBlockType.startsWith('header')\n ) {\n const nextEditorState = addNewBlockAt(\n editorState,\n currentBlock.getKey()\n );\n onChange(nextEditorState);\n return 'handled';\n }\n\n return handler(e, editorState);\n },\n [onChange, handler]\n );\n\nexport default useReturnHandler;\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AAEnC,OAAOC,eAAe,MAAM,0BAA0B;AACtD,OAAOC,aAAa,MAAM,wBAAwB;AAIlD;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG,CACvBC,QAAsC,EACtCC,OAA4B,KAE5BL,WAAW,CACT,CAACM,CAAC,EAAEC,WAAW,KAAK;EAClB,MAAMC,YAAY,GAAGP,eAAe,CAACM,WAAW,CAAC;EACjD,MAAME,gBAAgB,GAAGD,YAAY,CAACE,OAAO,EAAE;EAE/C,IACED,gBAAgB,CAACE,UAAU,CAAC,QAAQ,CAAC,IACrCF,gBAAgB,CAACE,UAAU,CAAC,QAAQ,CAAC,EACrC;IACA,MAAMC,eAAe,GAAGV,aAAa,CACnCK,WAAW,EACXC,YAAY,CAACK,MAAM,EAAE,CACtB;IACDT,QAAQ,CAACQ,eAAe,CAAC;IACzB,OAAO,SAAS;EAClB;EAEA,OAAOP,OAAO,CAACC,CAAC,EAAEC,WAAW,CAAC;AAChC,CAAC,EACD,CAACH,QAAQ,EAAEC,OAAO,CAAC,CACpB;AAEH,eAAeF,gBAAgB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { RichUtils } from 'draft-js';
|
|
3
3
|
import getSelectionRange from '../utils/getSelectionRange';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Updates the visibility of the style toolbar
|
|
7
6
|
*/
|
|
@@ -15,16 +14,17 @@ const useStyleToolbarProps = value => {
|
|
|
15
14
|
const [visible, setVisible] = useState(false);
|
|
16
15
|
useEffect(() => {
|
|
17
16
|
if (!value) return;
|
|
18
|
-
const selectionRange = getSelectionRange();
|
|
17
|
+
const selectionRange = getSelectionRange();
|
|
18
|
+
|
|
19
|
+
// Do not show the panel if either there is no selected text,
|
|
19
20
|
// or the selection range is collapsed,
|
|
20
21
|
// or the selected text is in an atomic block.
|
|
21
|
-
|
|
22
22
|
if (!selectionRange || value.getSelection().isCollapsed() || RichUtils.getCurrentBlockType(value).startsWith('atomic')) {
|
|
23
23
|
setVisible(false);
|
|
24
24
|
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
25
|
+
}
|
|
27
26
|
|
|
27
|
+
// Otherwise, set the rect of the selection range
|
|
28
28
|
setTrigger(selectionRange.getBoundingClientRect());
|
|
29
29
|
setVisible(true);
|
|
30
30
|
}, [value]);
|
|
@@ -33,6 +33,5 @@ const useStyleToolbarProps = value => {
|
|
|
33
33
|
visible
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
|
|
37
36
|
export default useStyleToolbarProps;
|
|
38
37
|
//# sourceMappingURL=useStyleToolbarProps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStyleToolbarProps.js","names":["useEffect","useState","RichUtils","getSelectionRange","useStyleToolbarProps","value","trigger","setTrigger","top","left","width","height","visible","setVisible","selectionRange","getSelection","isCollapsed","getCurrentBlockType","startsWith","getBoundingClientRect"],"sources":["../../../../src/Editor/hooks/useStyleToolbarProps.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { EditorState, RichUtils } from 'draft-js';\nimport getSelectionRange from '../utils/getSelectionRange';\n\ninterface Rect {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\ninterface UseStyleToolbarPropsRes {\n trigger: Rect;\n visible: boolean;\n}\n\n/**\n * Updates the visibility of the style toolbar\n */\nconst useStyleToolbarProps = (value: EditorState): UseStyleToolbarPropsRes => {\n const [trigger, setTrigger] = useState({\n top: 0,\n left: 0,\n width: 0,\n height: 0,\n });\n const [visible, setVisible] = useState(false);\n\n useEffect(() => {\n if (!value) return;\n const selectionRange = getSelectionRange();\n\n // Do not show the panel if either there is no selected text,\n // or the selection range is collapsed,\n // or the selected text is in an atomic block.\n if (\n !selectionRange ||\n value.getSelection().isCollapsed() ||\n RichUtils.getCurrentBlockType(value).startsWith('atomic')\n ) {\n setVisible(false);\n return;\n }\n\n // Otherwise, set the rect of the selection range\n setTrigger(selectionRange.getBoundingClientRect());\n setVisible(true);\n }, [value]);\n\n return { trigger, visible };\n};\n\nexport default useStyleToolbarProps;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useStyleToolbarProps.js","names":["useEffect","useState","RichUtils","getSelectionRange","useStyleToolbarProps","value","trigger","setTrigger","top","left","width","height","visible","setVisible","selectionRange","getSelection","isCollapsed","getCurrentBlockType","startsWith","getBoundingClientRect"],"sources":["../../../../src/Editor/hooks/useStyleToolbarProps.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { EditorState, RichUtils } from 'draft-js';\nimport getSelectionRange from '../utils/getSelectionRange';\n\ninterface Rect {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\ninterface UseStyleToolbarPropsRes {\n trigger: Rect;\n visible: boolean;\n}\n\n/**\n * Updates the visibility of the style toolbar\n */\nconst useStyleToolbarProps = (value: EditorState): UseStyleToolbarPropsRes => {\n const [trigger, setTrigger] = useState({\n top: 0,\n left: 0,\n width: 0,\n height: 0,\n });\n const [visible, setVisible] = useState(false);\n\n useEffect(() => {\n if (!value) return;\n const selectionRange = getSelectionRange();\n\n // Do not show the panel if either there is no selected text,\n // or the selection range is collapsed,\n // or the selected text is in an atomic block.\n if (\n !selectionRange ||\n value.getSelection().isCollapsed() ||\n RichUtils.getCurrentBlockType(value).startsWith('atomic')\n ) {\n setVisible(false);\n return;\n }\n\n // Otherwise, set the rect of the selection range\n setTrigger(selectionRange.getBoundingClientRect());\n setVisible(true);\n }, [value]);\n\n return { trigger, visible };\n};\n\nexport default useStyleToolbarProps;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAAsBC,SAAS,QAAQ,UAAU;AACjD,OAAOC,iBAAiB,MAAM,4BAA4B;AAc1D;AACA;AACA;AACA,MAAMC,oBAAoB,GAAIC,KAAkB,IAA8B;EAC5E,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGN,QAAQ,CAAC;IACrCO,GAAG,EAAE,CAAC;IACNC,IAAI,EAAE,CAAC;IACPC,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE;EACV,CAAC,CAAC;EACF,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EAE7CD,SAAS,CAAC,MAAM;IACd,IAAI,CAACK,KAAK,EAAE;IACZ,MAAMS,cAAc,GAAGX,iBAAiB,EAAE;;IAE1C;IACA;IACA;IACA,IACE,CAACW,cAAc,IACfT,KAAK,CAACU,YAAY,EAAE,CAACC,WAAW,EAAE,IAClCd,SAAS,CAACe,mBAAmB,CAACZ,KAAK,CAAC,CAACa,UAAU,CAAC,QAAQ,CAAC,EACzD;MACAL,UAAU,CAAC,KAAK,CAAC;MACjB;IACF;;IAEA;IACAN,UAAU,CAACO,cAAc,CAACK,qBAAqB,EAAE,CAAC;IAClDN,UAAU,CAAC,IAAI,CAAC;EAClB,CAAC,EAAE,CAACR,KAAK,CAAC,CAAC;EAEX,OAAO;IAAEC,OAAO;IAAEM;EAAQ,CAAC;AAC7B,CAAC;AAED,eAAeR,oBAAoB"}
|
package/dist/esm/Editor/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
2
|
import React, { forwardRef, useCallback, useState } from 'react';
|
|
4
3
|
import { Editor as DraftEditor, EditorState } from 'draft-js';
|
|
5
4
|
import { InputContainer } from '@os-design/core';
|
|
@@ -16,11 +15,9 @@ import useStyleToolbarProps from './hooks/useStyleToolbarProps';
|
|
|
16
15
|
import useBlockToolbarProps from './hooks/useBlockToolbarProps';
|
|
17
16
|
import useReturnHandler from './hooks/useReturnHandler';
|
|
18
17
|
import usePastedTextHandler from './hooks/usePastedTextHandler';
|
|
19
|
-
|
|
20
18
|
const disabledStyles = p => p.disabled && css`
|
|
21
19
|
cursor: not-allowed;
|
|
22
20
|
`;
|
|
23
|
-
|
|
24
21
|
const Container = styled(InputContainer)`
|
|
25
22
|
height: unset;
|
|
26
23
|
cursor: text;
|
|
@@ -33,10 +30,10 @@ const Container = styled(InputContainer)`
|
|
|
33
30
|
${overrideDraftJsStyles};
|
|
34
31
|
${disabledStyles};
|
|
35
32
|
`;
|
|
33
|
+
|
|
36
34
|
/**
|
|
37
35
|
* Rich text editor based on the Draft.js.
|
|
38
36
|
*/
|
|
39
|
-
|
|
40
37
|
const Editor = /*#__PURE__*/forwardRef(({
|
|
41
38
|
disabled = false,
|
|
42
39
|
styleToolbarItems = defaultStyleToolbarItems,
|
|
@@ -55,20 +52,22 @@ const Editor = /*#__PURE__*/forwardRef(({
|
|
|
55
52
|
value,
|
|
56
53
|
defaultValue,
|
|
57
54
|
onChange
|
|
58
|
-
});
|
|
59
|
-
// while an image is being uploaded
|
|
55
|
+
});
|
|
60
56
|
|
|
61
|
-
|
|
57
|
+
// Used by ImageBlock to make the editor read-only
|
|
58
|
+
// while an image is being uploaded
|
|
59
|
+
const [innerReadOnly, setInnerReadOnly] = useState(false);
|
|
62
60
|
|
|
61
|
+
// Get the trigger and visible props for the toolbars
|
|
63
62
|
const styleToolbarProps = useStyleToolbarProps(forwardedValue || defaultValue);
|
|
64
|
-
const blockToolbarProps = useBlockToolbarProps(forwardedValue || defaultValue, (blockToolbarItems || []).length > 0);
|
|
63
|
+
const blockToolbarProps = useBlockToolbarProps(forwardedValue || defaultValue, (blockToolbarItems || []).length > 0);
|
|
65
64
|
|
|
65
|
+
// Move the caret to the end of the content when the focus event was fired
|
|
66
66
|
const setEditorState = useCallback(editorState => {
|
|
67
67
|
if (!editorState.getSelection().getHasFocus()) {
|
|
68
68
|
setForwardedValue(EditorState.moveSelectionToEnd(editorState));
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
71
|
setForwardedValue(editorState);
|
|
73
72
|
}, [setForwardedValue]);
|
|
74
73
|
const blockRenderer = useCallback(block => {
|
|
@@ -77,8 +76,9 @@ const Editor = /*#__PURE__*/forwardRef(({
|
|
|
77
76
|
return {
|
|
78
77
|
component: blockConfig.component
|
|
79
78
|
};
|
|
80
|
-
}, [blockToolbarItems]);
|
|
79
|
+
}, [blockToolbarItems]);
|
|
81
80
|
|
|
81
|
+
// Custom handlers
|
|
82
82
|
const returnHandler = useReturnHandler(setForwardedValue, handleReturn);
|
|
83
83
|
const pastedTextHandler = usePastedTextHandler(setForwardedValue, handlePastedText);
|
|
84
84
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Container, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","forwardRef","useCallback","useState","Editor","DraftEditor","EditorState","InputContainer","styled","useForwardedRef","useForwardedState","css","createEmptyEditorState","defaultDraftJsStyles","overrideDraftJsStyles","defaultStyleToolbarItems","StyleToolbar","BlockToolbar","useStyleToolbarProps","useBlockToolbarProps","useReturnHandler","usePastedTextHandler","disabledStyles","p","disabled","Container","theme","editorPaddingVertical","inputPaddingHorizontal","editorMinHeight","styleToolbarItems","blockToolbarItems","value","defaultValue","onChange","size","readOnly","handleReturn","handlePastedText","rest","ref","editorRef","mergedEditorRef","forwardedValue","setForwardedValue","innerReadOnly","setInnerReadOnly","styleToolbarProps","blockToolbarProps","length","setEditorState","editorState","getSelection","getHasFocus","moveSelectionToEnd","blockRenderer","block","blockConfig","find","item","type","getType","component","returnHandler","pastedTextHandler","undefined","current","focus","displayName"],"sources":["../../../src/Editor/index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useState } from 'react';\nimport {\n Editor as DraftEditor,\n EditorState,\n EditorProps as DraftEditorProps,\n} from 'draft-js';\nimport { InputContainer } from '@os-design/core';\nimport styled from '@emotion/styled';\nimport { WithSize } from '@os-design/styles';\nimport { useForwardedRef, useForwardedState } from '@os-design/utils';\nimport { css } from '@emotion/react';\nimport createEmptyEditorState from './utils/createEmptyEditorState';\nimport defaultDraftJsStyles from './styles/defaultDraftJsStyles';\nimport overrideDraftJsStyles from './styles/overrideDraftJsStyles';\nimport defaultStyleToolbarItems, {\n StyleToolbarItem,\n} from './utils/defaultStyleToolbarItems';\nimport StyleToolbar from './StyleToolbar';\nimport BlockToolbar from './BlockToolbar';\nimport useStyleToolbarProps from './hooks/useStyleToolbarProps';\nimport useBlockToolbarProps from './hooks/useBlockToolbarProps';\nimport useReturnHandler from './hooks/useReturnHandler';\nimport usePastedTextHandler from './hooks/usePastedTextHandler';\nimport { BlockToolbarItem } from './blocks/types';\n\nexport interface EditorProps\n extends Omit<DraftEditorProps, 'editorState' | 'onChange'>,\n WithSize {\n /**\n * Whether the editor is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Available styles in the toolbar.\n * @default undefined\n */\n styleToolbarItems?: StyleToolbarItem[];\n /**\n * Available blocks in the toolbar.\n * @default undefined\n */\n blockToolbarItems?: BlockToolbarItem[];\n /**\n * The editor state.\n * @default undefined\n */\n value?: EditorState;\n /**\n * The default value.\n * @default undefined\n */\n defaultValue?: EditorState;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: EditorState) => void;\n}\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n `;\n\nconst Container = styled(InputContainer)`\n height: unset;\n cursor: text;\n\n padding: ${(p) => p.theme.editorPaddingVertical}em\n ${(p) => p.theme.inputPaddingHorizontal}em;\n min-height: ${(p) => p.theme.editorMinHeight}em;\n\n ${defaultDraftJsStyles};\n ${overrideDraftJsStyles};\n ${disabledStyles};\n`;\n\n/**\n * Rich text editor based on the Draft.js.\n */\nconst Editor = forwardRef<DraftEditor, EditorProps>(\n (\n {\n disabled = false,\n styleToolbarItems = defaultStyleToolbarItems,\n blockToolbarItems = [],\n value,\n defaultValue = createEmptyEditorState(),\n onChange,\n size,\n readOnly,\n handleReturn = () => 'not-handled',\n handlePastedText = () => 'not-handled',\n ...rest\n },\n ref\n ) => {\n const [editorRef, mergedEditorRef] = useForwardedRef(ref);\n const [forwardedValue, setForwardedValue] = useForwardedState({\n value,\n defaultValue,\n onChange,\n });\n\n // Used by ImageBlock to make the editor read-only\n // while an image is being uploaded\n const [innerReadOnly, setInnerReadOnly] = useState(false);\n\n // Get the trigger and visible props for the toolbars\n const styleToolbarProps = useStyleToolbarProps(\n forwardedValue || defaultValue\n );\n const blockToolbarProps = useBlockToolbarProps(\n forwardedValue || defaultValue,\n (blockToolbarItems || []).length > 0\n );\n\n // Move the caret to the end of the content when the focus event was fired\n const setEditorState = useCallback(\n (editorState: EditorState) => {\n if (!editorState.getSelection().getHasFocus()) {\n setForwardedValue(EditorState.moveSelectionToEnd(editorState));\n return;\n }\n setForwardedValue(editorState);\n },\n [setForwardedValue]\n );\n\n const blockRenderer = useCallback(\n (block) => {\n const blockConfig = blockToolbarItems.find(\n (item) => item.type === block.getType()\n );\n if (!blockConfig) return null;\n return { component: blockConfig.component };\n },\n [blockToolbarItems]\n );\n\n // Custom handlers\n const returnHandler = useReturnHandler(setForwardedValue, handleReturn);\n const pastedTextHandler = usePastedTextHandler(\n setForwardedValue,\n handlePastedText\n );\n\n return (\n <>\n <Container\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n role={!disabled ? 'textbox' : undefined}\n onFocus={() => {\n if (disabled || !editorRef.current) return;\n editorRef.current.focus();\n }}\n >\n <DraftEditor\n onChange={setEditorState}\n blockRendererFn={blockRenderer}\n handleReturn={returnHandler}\n handlePastedText={pastedTextHandler}\n readOnly={readOnly || innerReadOnly || disabled}\n stripPastedStyles\n {...rest}\n editorState={forwardedValue || defaultValue}\n ref={mergedEditorRef}\n />\n </Container>\n\n <StyleToolbar\n {...styleToolbarProps}\n size={size}\n items={styleToolbarItems}\n value={forwardedValue || defaultValue}\n onChange={setForwardedValue}\n />\n\n <BlockToolbar\n {...blockToolbarProps}\n placement='right'\n gap={2.5}\n size={size}\n items={blockToolbarItems}\n value={forwardedValue || defaultValue}\n onChange={setForwardedValue}\n setReadOnly={setInnerReadOnly}\n />\n </>\n );\n }\n);\n\nEditor.displayName = 'Editor';\n\nexport default Editor;\n"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,UAAhB,EAA4BC,WAA5B,EAAyCC,QAAzC,QAAyD,OAAzD;AACA,SACEC,MAAM,IAAIC,WADZ,EAEEC,WAFF,QAIO,UAJP;AAKA,SAASC,cAAT,QAA+B,iBAA/B;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AAEA,SAASC,eAAT,EAA0BC,iBAA1B,QAAmD,kBAAnD;AACA,SAASC,GAAT,QAAoB,gBAApB;AACA,OAAOC,sBAAP,MAAmC,gCAAnC;AACA,OAAOC,oBAAP,MAAiC,+BAAjC;AACA,OAAOC,qBAAP,MAAkC,gCAAlC;AACA,OAAOC,wBAAP,MAEO,kCAFP;AAGA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,oBAAP,MAAiC,8BAAjC;AACA,OAAOC,oBAAP,MAAiC,8BAAjC;AACA,OAAOC,gBAAP,MAA6B,0BAA7B;AACA,OAAOC,oBAAP,MAAiC,8BAAj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IACE,QAAQ,EAAEjB,cADZ;IAEE,eAAe,EAAEK,aAFnB;IAGE,YAAY,EAAEQ,aAHhB;IAIE,gBAAgB,EAAEC,iBAJpB;IAKE,QAAQ,EAAE5B,QAAQ,IAAIS,aAAZ,IAA6BrB,QALzC;IAME,iBAAiB;EANnB,GAOMe,IAPN;IAQE,WAAW,EAAEI,cAAc,IAAIV,YARjC;IASE,GAAG,EAAES;EATP,GAVF,CADF,eAwBE,oBAAC,YAAD,eACMK,iBADN;IAEE,IAAI,EAAEZ,IAFR;IAGE,KAAK,EAAEL,iBAHT;IAIE,KAAK,EAAEa,cAAc,IAAIV,YAJ3B;IAKE,QAAQ,EAAEW;EALZ,GAxBF,eAgCE,oBAAC,YAAD,eACMI,iBADN;IAEE,SAAS,EAAC,OAFZ;IAGE,GAAG,EAAE,GAHP;IAIE,IAAI,EAAEb,IAJR;IAKE,KAAK,EAAEJ,iBALT;IAME,KAAK,EAAEY,cAAc,IAAIV,YAN3B;IAOE,QAAQ,EAAEW,iBAPZ;IAQE,WAAW,EAAEE;EARf,GAhCF,CADF;AA6CD,CAhHsB,CAAzB;AAmHA1C,MAAM,CAACgE,WAAP,GAAqB,QAArB;AAEA,eAAehE,MAAf"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","forwardRef","useCallback","useState","Editor","DraftEditor","EditorState","InputContainer","styled","useForwardedRef","useForwardedState","css","createEmptyEditorState","defaultDraftJsStyles","overrideDraftJsStyles","defaultStyleToolbarItems","StyleToolbar","BlockToolbar","useStyleToolbarProps","useBlockToolbarProps","useReturnHandler","usePastedTextHandler","disabledStyles","p","disabled","Container","theme","editorPaddingVertical","inputPaddingHorizontal","editorMinHeight","styleToolbarItems","blockToolbarItems","value","defaultValue","onChange","size","readOnly","handleReturn","handlePastedText","rest","ref","editorRef","mergedEditorRef","forwardedValue","setForwardedValue","innerReadOnly","setInnerReadOnly","styleToolbarProps","blockToolbarProps","length","setEditorState","editorState","getSelection","getHasFocus","moveSelectionToEnd","blockRenderer","block","blockConfig","find","item","type","getType","component","returnHandler","pastedTextHandler","undefined","current","focus","displayName"],"sources":["../../../src/Editor/index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useState } from 'react';\nimport {\n Editor as DraftEditor,\n EditorState,\n EditorProps as DraftEditorProps,\n} from 'draft-js';\nimport { InputContainer } from '@os-design/core';\nimport styled from '@emotion/styled';\nimport { WithSize } from '@os-design/styles';\nimport { useForwardedRef, useForwardedState } from '@os-design/utils';\nimport { css } from '@emotion/react';\nimport createEmptyEditorState from './utils/createEmptyEditorState';\nimport defaultDraftJsStyles from './styles/defaultDraftJsStyles';\nimport overrideDraftJsStyles from './styles/overrideDraftJsStyles';\nimport defaultStyleToolbarItems, {\n StyleToolbarItem,\n} from './utils/defaultStyleToolbarItems';\nimport StyleToolbar from './StyleToolbar';\nimport BlockToolbar from './BlockToolbar';\nimport useStyleToolbarProps from './hooks/useStyleToolbarProps';\nimport useBlockToolbarProps from './hooks/useBlockToolbarProps';\nimport useReturnHandler from './hooks/useReturnHandler';\nimport usePastedTextHandler from './hooks/usePastedTextHandler';\nimport { BlockToolbarItem } from './blocks/types';\n\nexport interface EditorProps\n extends Omit<DraftEditorProps, 'editorState' | 'onChange'>,\n WithSize {\n /**\n * Whether the editor is disabled.\n * @default false\n */\n disabled?: boolean;\n /**\n * Available styles in the toolbar.\n * @default undefined\n */\n styleToolbarItems?: StyleToolbarItem[];\n /**\n * Available blocks in the toolbar.\n * @default undefined\n */\n blockToolbarItems?: BlockToolbarItem[];\n /**\n * The editor state.\n * @default undefined\n */\n value?: EditorState;\n /**\n * The default value.\n * @default undefined\n */\n defaultValue?: EditorState;\n /**\n * The change event handler.\n * @default undefined\n */\n onChange?: (value: EditorState) => void;\n}\n\nconst disabledStyles = (p) =>\n p.disabled &&\n css`\n cursor: not-allowed;\n `;\n\nconst Container = styled(InputContainer)`\n height: unset;\n cursor: text;\n\n padding: ${(p) => p.theme.editorPaddingVertical}em\n ${(p) => p.theme.inputPaddingHorizontal}em;\n min-height: ${(p) => p.theme.editorMinHeight}em;\n\n ${defaultDraftJsStyles};\n ${overrideDraftJsStyles};\n ${disabledStyles};\n`;\n\n/**\n * Rich text editor based on the Draft.js.\n */\nconst Editor = forwardRef<DraftEditor, EditorProps>(\n (\n {\n disabled = false,\n styleToolbarItems = defaultStyleToolbarItems,\n blockToolbarItems = [],\n value,\n defaultValue = createEmptyEditorState(),\n onChange,\n size,\n readOnly,\n handleReturn = () => 'not-handled',\n handlePastedText = () => 'not-handled',\n ...rest\n },\n ref\n ) => {\n const [editorRef, mergedEditorRef] = useForwardedRef(ref);\n const [forwardedValue, setForwardedValue] = useForwardedState({\n value,\n defaultValue,\n onChange,\n });\n\n // Used by ImageBlock to make the editor read-only\n // while an image is being uploaded\n const [innerReadOnly, setInnerReadOnly] = useState(false);\n\n // Get the trigger and visible props for the toolbars\n const styleToolbarProps = useStyleToolbarProps(\n forwardedValue || defaultValue\n );\n const blockToolbarProps = useBlockToolbarProps(\n forwardedValue || defaultValue,\n (blockToolbarItems || []).length > 0\n );\n\n // Move the caret to the end of the content when the focus event was fired\n const setEditorState = useCallback(\n (editorState: EditorState) => {\n if (!editorState.getSelection().getHasFocus()) {\n setForwardedValue(EditorState.moveSelectionToEnd(editorState));\n return;\n }\n setForwardedValue(editorState);\n },\n [setForwardedValue]\n );\n\n const blockRenderer = useCallback(\n (block) => {\n const blockConfig = blockToolbarItems.find(\n (item) => item.type === block.getType()\n );\n if (!blockConfig) return null;\n return { component: blockConfig.component };\n },\n [blockToolbarItems]\n );\n\n // Custom handlers\n const returnHandler = useReturnHandler(setForwardedValue, handleReturn);\n const pastedTextHandler = usePastedTextHandler(\n setForwardedValue,\n handlePastedText\n );\n\n return (\n <>\n <Container\n disabled={disabled}\n size={size}\n tabIndex={!disabled ? 0 : -1}\n role={!disabled ? 'textbox' : undefined}\n onFocus={() => {\n if (disabled || !editorRef.current) return;\n editorRef.current.focus();\n }}\n >\n <DraftEditor\n onChange={setEditorState}\n blockRendererFn={blockRenderer}\n handleReturn={returnHandler}\n handlePastedText={pastedTextHandler}\n readOnly={readOnly || innerReadOnly || disabled}\n stripPastedStyles\n {...rest}\n editorState={forwardedValue || defaultValue}\n ref={mergedEditorRef}\n />\n </Container>\n\n <StyleToolbar\n {...styleToolbarProps}\n size={size}\n items={styleToolbarItems}\n value={forwardedValue || defaultValue}\n onChange={setForwardedValue}\n />\n\n <BlockToolbar\n {...blockToolbarProps}\n placement='right'\n gap={2.5}\n size={size}\n items={blockToolbarItems}\n value={forwardedValue || defaultValue}\n onChange={setForwardedValue}\n setReadOnly={setInnerReadOnly}\n />\n </>\n );\n }\n);\n\nEditor.displayName = 'Editor';\n\nexport default Editor;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,OAAO;AAChE,SACEC,MAAM,IAAIC,WAAW,EACrBC,WAAW,QAEN,UAAU;AACjB,SAASC,cAAc,QAAQ,iBAAiB;AAChD,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SAASC,eAAe,EAAEC,iBAAiB,QAAQ,kBAAkB;AACrE,SAASC,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,sBAAsB,MAAM,gCAAgC;AACnE,OAAOC,oBAAoB,MAAM,+BAA+B;AAChE,OAAOC,qBAAqB,MAAM,gCAAgC;AAClE,OAAOC,wBAAwB,MAExB,kCAAkC;AACzC,OAAOC,YAAY,MAAM,gBAAgB;AACzC,OAAOC,YAAY,MAAM,gBAAgB;AACzC,OAAOC,oBAAoB,MAAM,8BAA8B;AAC/D,OAAOC,oBAAoB,MAAM,8BAA8B;AAC/D,OAAOC,gBAAgB,MAAM,0BAA0B;AACvD,OAAOC,oBAAoB,MAAM,8BAA8B;AAsC/D,MAAMC,cAAc,GAAIC,CAAC,IACvBA,CAAC,CAACC,QAAQ,IACVb,GAAI;AACN;AACA,GAAG;AAEH,MAAMc,SAAS,GAAGjB,MAAM,CAACD,cAAc,CAAE;AACzC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AAEI,cAAc,IAAIV,YAAa;IAC5C,GAAG,EAAES;EAAgB,GACrB,CACQ,eAEZ,oBAAC,YAAY,eACPK,iBAAiB;IACrB,IAAI,EAAEZ,IAAK;IACX,KAAK,EAAEL,iBAAkB;IACzB,KAAK,EAAEa,cAAc,IAAIV,YAAa;IACtC,QAAQ,EAAEW;EAAkB,GAC5B,eAEF,oBAAC,YAAY,eACPI,iBAAiB;IACrB,SAAS,EAAC,OAAO;IACjB,GAAG,EAAE,GAAI;IACT,IAAI,EAAEb,IAAK;IACX,KAAK,EAAEJ,iBAAkB;IACzB,KAAK,EAAEY,cAAc,IAAIV,YAAa;IACtC,QAAQ,EAAEW,iBAAkB;IAC5B,WAAW,EAAEE;EAAiB,GAC9B,CACD;AAEP,CAAC,CACF;AAED1C,MAAM,CAACgE,WAAW,GAAG,QAAQ;AAE7B,eAAehE,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultDraftJsStyles.js","names":["css","defaultDraftJsStyles"],"sources":["../../../../src/Editor/styles/defaultDraftJsStyles.ts"],"sourcesContent":["import { css } from '@emotion/react';\n\n/**\n * Default Draft.js styles.\n * The original styles located in `node_modules/draft-js/dist/Draft.css`.\n */\nconst defaultDraftJsStyles = css`\n .DraftEditor-editorContainer,\n .DraftEditor-root,\n .public-DraftEditor-content {\n height: inherit;\n text-align: initial;\n }\n .public-DraftEditor-content[contenteditable='true'] {\n -webkit-user-modify: read-write-plaintext-only;\n }\n .DraftEditor-root {\n position: relative;\n }\n .DraftEditor-editorContainer {\n background-color: rgba(255, 255, 255, 0);\n border-left: 0.1px solid transparent;\n position: relative;\n z-index: 1;\n }\n .public-DraftEditor-block {\n position: relative;\n }\n .DraftEditor-alignLeft .public-DraftStyleDefault-block {\n text-align: left;\n }\n .DraftEditor-alignLeft .public-DraftEditorPlaceholder-root {\n left: 0;\n text-align: left;\n }\n .DraftEditor-alignCenter .public-DraftStyleDefault-block {\n text-align: center;\n }\n .DraftEditor-alignCenter .public-DraftEditorPlaceholder-root {\n margin: 0 auto;\n text-align: center;\n width: 100%;\n }\n .DraftEditor-alignRight .public-DraftStyleDefault-block {\n text-align: right;\n }\n .DraftEditor-alignRight .public-DraftEditorPlaceholder-root {\n right: 0;\n text-align: right;\n }\n .public-DraftEditorPlaceholder-root {\n color: #9197a3;\n position: absolute;\n width: 100%;\n z-index: 1;\n }\n .public-DraftEditorPlaceholder-hasFocus {\n color: #bdc1c9;\n }\n .DraftEditorPlaceholder-hidden {\n display: none;\n }\n .public-DraftStyleDefault-block {\n position: relative;\n white-space: pre-wrap;\n }\n .public-DraftStyleDefault-ltr {\n direction: ltr;\n text-align: left;\n }\n .public-DraftStyleDefault-rtl {\n direction: rtl;\n text-align: right;\n }\n .public-DraftStyleDefault-listLTR {\n direction: ltr;\n }\n .public-DraftStyleDefault-listRTL {\n direction: rtl;\n }\n .public-DraftStyleDefault-ol,\n .public-DraftStyleDefault-ul {\n margin: 16px 0;\n padding: 0;\n }\n .public-DraftStyleDefault-depth0.public-DraftStyleDefault-listLTR {\n margin-left: 1.5em;\n }\n .public-DraftStyleDefault-depth0.public-DraftStyleDefault-listRTL {\n margin-right: 1.5em;\n }\n .public-DraftStyleDefault-depth1.public-DraftStyleDefault-listLTR {\n margin-left: 3em;\n }\n .public-DraftStyleDefault-depth1.public-DraftStyleDefault-listRTL {\n margin-right: 3em;\n }\n .public-DraftStyleDefault-depth2.public-DraftStyleDefault-listLTR {\n margin-left: 4.5em;\n }\n .public-DraftStyleDefault-depth2.public-DraftStyleDefault-listRTL {\n margin-right: 4.5em;\n }\n .public-DraftStyleDefault-depth3.public-DraftStyleDefault-listLTR {\n margin-left: 6em;\n }\n .public-DraftStyleDefault-depth3.public-DraftStyleDefault-listRTL {\n margin-right: 6em;\n }\n .public-DraftStyleDefault-depth4.public-DraftStyleDefault-listLTR {\n margin-left: 7.5em;\n }\n .public-DraftStyleDefault-depth4.public-DraftStyleDefault-listRTL {\n margin-right: 7.5em;\n }\n .public-DraftStyleDefault-unorderedListItem {\n list-style-type: square;\n position: relative;\n }\n .public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth0 {\n list-style-type: disc;\n }\n .public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth1 {\n list-style-type: circle;\n }\n .public-DraftStyleDefault-orderedListItem {\n list-style-type: none;\n position: relative;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listLTR:before {\n left: -36px;\n position: absolute;\n text-align: right;\n width: 30px;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listRTL:before {\n position: absolute;\n right: -36px;\n text-align: left;\n width: 30px;\n }\n .public-DraftStyleDefault-orderedListItem:before {\n content: counter(ol0) '. ';\n counter-increment: ol0;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth1:before {\n content: counter(ol1, lower-alpha) '. ';\n counter-increment: ol1;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth2:before {\n content: counter(ol2, lower-roman) '. ';\n counter-increment: ol2;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth3:before {\n content: counter(ol3) '. ';\n counter-increment: ol3;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth4:before {\n content: counter(ol4, lower-alpha) '. ';\n counter-increment: ol4;\n }\n .public-DraftStyleDefault-depth0.public-DraftStyleDefault-reset {\n counter-reset: ol0;\n }\n .public-DraftStyleDefault-depth1.public-DraftStyleDefault-reset {\n counter-reset: ol1;\n }\n .public-DraftStyleDefault-depth2.public-DraftStyleDefault-reset {\n counter-reset: ol2;\n }\n .public-DraftStyleDefault-depth3.public-DraftStyleDefault-reset {\n counter-reset: ol3;\n }\n .public-DraftStyleDefault-depth4.public-DraftStyleDefault-reset {\n counter-reset: ol4;\n }\n`;\n\nexport default defaultDraftJsStyles;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"defaultDraftJsStyles.js","names":["css","defaultDraftJsStyles"],"sources":["../../../../src/Editor/styles/defaultDraftJsStyles.ts"],"sourcesContent":["import { css } from '@emotion/react';\n\n/**\n * Default Draft.js styles.\n * The original styles located in `node_modules/draft-js/dist/Draft.css`.\n */\nconst defaultDraftJsStyles = css`\n .DraftEditor-editorContainer,\n .DraftEditor-root,\n .public-DraftEditor-content {\n height: inherit;\n text-align: initial;\n }\n .public-DraftEditor-content[contenteditable='true'] {\n -webkit-user-modify: read-write-plaintext-only;\n }\n .DraftEditor-root {\n position: relative;\n }\n .DraftEditor-editorContainer {\n background-color: rgba(255, 255, 255, 0);\n border-left: 0.1px solid transparent;\n position: relative;\n z-index: 1;\n }\n .public-DraftEditor-block {\n position: relative;\n }\n .DraftEditor-alignLeft .public-DraftStyleDefault-block {\n text-align: left;\n }\n .DraftEditor-alignLeft .public-DraftEditorPlaceholder-root {\n left: 0;\n text-align: left;\n }\n .DraftEditor-alignCenter .public-DraftStyleDefault-block {\n text-align: center;\n }\n .DraftEditor-alignCenter .public-DraftEditorPlaceholder-root {\n margin: 0 auto;\n text-align: center;\n width: 100%;\n }\n .DraftEditor-alignRight .public-DraftStyleDefault-block {\n text-align: right;\n }\n .DraftEditor-alignRight .public-DraftEditorPlaceholder-root {\n right: 0;\n text-align: right;\n }\n .public-DraftEditorPlaceholder-root {\n color: #9197a3;\n position: absolute;\n width: 100%;\n z-index: 1;\n }\n .public-DraftEditorPlaceholder-hasFocus {\n color: #bdc1c9;\n }\n .DraftEditorPlaceholder-hidden {\n display: none;\n }\n .public-DraftStyleDefault-block {\n position: relative;\n white-space: pre-wrap;\n }\n .public-DraftStyleDefault-ltr {\n direction: ltr;\n text-align: left;\n }\n .public-DraftStyleDefault-rtl {\n direction: rtl;\n text-align: right;\n }\n .public-DraftStyleDefault-listLTR {\n direction: ltr;\n }\n .public-DraftStyleDefault-listRTL {\n direction: rtl;\n }\n .public-DraftStyleDefault-ol,\n .public-DraftStyleDefault-ul {\n margin: 16px 0;\n padding: 0;\n }\n .public-DraftStyleDefault-depth0.public-DraftStyleDefault-listLTR {\n margin-left: 1.5em;\n }\n .public-DraftStyleDefault-depth0.public-DraftStyleDefault-listRTL {\n margin-right: 1.5em;\n }\n .public-DraftStyleDefault-depth1.public-DraftStyleDefault-listLTR {\n margin-left: 3em;\n }\n .public-DraftStyleDefault-depth1.public-DraftStyleDefault-listRTL {\n margin-right: 3em;\n }\n .public-DraftStyleDefault-depth2.public-DraftStyleDefault-listLTR {\n margin-left: 4.5em;\n }\n .public-DraftStyleDefault-depth2.public-DraftStyleDefault-listRTL {\n margin-right: 4.5em;\n }\n .public-DraftStyleDefault-depth3.public-DraftStyleDefault-listLTR {\n margin-left: 6em;\n }\n .public-DraftStyleDefault-depth3.public-DraftStyleDefault-listRTL {\n margin-right: 6em;\n }\n .public-DraftStyleDefault-depth4.public-DraftStyleDefault-listLTR {\n margin-left: 7.5em;\n }\n .public-DraftStyleDefault-depth4.public-DraftStyleDefault-listRTL {\n margin-right: 7.5em;\n }\n .public-DraftStyleDefault-unorderedListItem {\n list-style-type: square;\n position: relative;\n }\n .public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth0 {\n list-style-type: disc;\n }\n .public-DraftStyleDefault-unorderedListItem.public-DraftStyleDefault-depth1 {\n list-style-type: circle;\n }\n .public-DraftStyleDefault-orderedListItem {\n list-style-type: none;\n position: relative;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listLTR:before {\n left: -36px;\n position: absolute;\n text-align: right;\n width: 30px;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-listRTL:before {\n position: absolute;\n right: -36px;\n text-align: left;\n width: 30px;\n }\n .public-DraftStyleDefault-orderedListItem:before {\n content: counter(ol0) '. ';\n counter-increment: ol0;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth1:before {\n content: counter(ol1, lower-alpha) '. ';\n counter-increment: ol1;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth2:before {\n content: counter(ol2, lower-roman) '. ';\n counter-increment: ol2;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth3:before {\n content: counter(ol3) '. ';\n counter-increment: ol3;\n }\n .public-DraftStyleDefault-orderedListItem.public-DraftStyleDefault-depth4:before {\n content: counter(ol4, lower-alpha) '. ';\n counter-increment: ol4;\n }\n .public-DraftStyleDefault-depth0.public-DraftStyleDefault-reset {\n counter-reset: ol0;\n }\n .public-DraftStyleDefault-depth1.public-DraftStyleDefault-reset {\n counter-reset: ol1;\n }\n .public-DraftStyleDefault-depth2.public-DraftStyleDefault-reset {\n counter-reset: ol2;\n }\n .public-DraftStyleDefault-depth3.public-DraftStyleDefault-reset {\n counter-reset: ol3;\n }\n .public-DraftStyleDefault-depth4.public-DraftStyleDefault-reset {\n counter-reset: ol4;\n }\n`;\n\nexport default defaultDraftJsStyles;\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,gBAAgB;;AAEpC;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAGD,GAAI;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,eAAeC,oBAAoB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { css } from '@emotion/react';
|
|
2
|
-
import { clr } from '@os-design/theming';
|
|
2
|
+
import { clr } from '@os-design/theming';
|
|
3
3
|
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
4
5
|
const overrideDraftJsStyles = p => css`
|
|
5
6
|
.DraftEditor-root {
|
|
6
7
|
width: 100%;
|
|
@@ -15,6 +16,5 @@ const overrideDraftJsStyles = p => css`
|
|
|
15
16
|
margin: 0 0 ${p.theme.paragraphMarginBottom}em;
|
|
16
17
|
}
|
|
17
18
|
`;
|
|
18
|
-
|
|
19
19
|
export default overrideDraftJsStyles;
|
|
20
20
|
//# sourceMappingURL=overrideDraftJsStyles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overrideDraftJsStyles.js","names":["css","clr","overrideDraftJsStyles","p","theme","lineHeight","colorText","inputColorPlaceholder","paragraphMarginBottom"],"sources":["../../../../src/Editor/styles/overrideDraftJsStyles.ts"],"sourcesContent":["import { css } from '@emotion/react';\nimport { clr } from '@os-design/theming';\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nconst overrideDraftJsStyles = (p) => css`\n .DraftEditor-root {\n width: 100%;\n overflow: hidden;\n line-height: ${p.theme.lineHeight};\n color: ${clr(p.theme.colorText)};\n }\n .public-DraftEditorPlaceholder-root {\n color: ${clr(p.theme.inputColorPlaceholder)};\n }\n .public-DraftStyleDefault-block {\n margin: 0 0 ${p.theme.paragraphMarginBottom}em;\n }\n`;\n\nexport default overrideDraftJsStyles;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"overrideDraftJsStyles.js","names":["css","clr","overrideDraftJsStyles","p","theme","lineHeight","colorText","inputColorPlaceholder","paragraphMarginBottom"],"sources":["../../../../src/Editor/styles/overrideDraftJsStyles.ts"],"sourcesContent":["import { css } from '@emotion/react';\nimport { clr } from '@os-design/theming';\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nconst overrideDraftJsStyles = (p) => css`\n .DraftEditor-root {\n width: 100%;\n overflow: hidden;\n line-height: ${p.theme.lineHeight};\n color: ${clr(p.theme.colorText)};\n }\n .public-DraftEditorPlaceholder-root {\n color: ${clr(p.theme.inputColorPlaceholder)};\n }\n .public-DraftStyleDefault-block {\n margin: 0 0 ${p.theme.paragraphMarginBottom}em;\n }\n`;\n\nexport default overrideDraftJsStyles;\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,gBAAgB;AACpC,SAASC,GAAG,QAAQ,oBAAoB;;AAExC;AACA,MAAMC,qBAAqB,GAAIC,CAAC,IAAKH,GAAI;AACzC;AACA;AACA;AACA,mBAAmBG,CAAC,CAACC,KAAK,CAACC,UAAW;AACtC,aAAaJ,GAAG,CAACE,CAAC,CAACC,KAAK,CAACE,SAAS,CAAE;AACpC;AACA;AACA,aAAaL,GAAG,CAACE,CAAC,CAACC,KAAK,CAACG,qBAAqB,CAAE;AAChD;AACA;AACA,kBAAkBJ,CAAC,CAACC,KAAK,CAACI,qBAAsB;AAChD;AACA,CAAC;AAED,eAAeN,qBAAqB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Immutable from 'immutable';
|
|
2
2
|
import { ContentBlock, EditorState, genKey } from 'draft-js';
|
|
3
|
-
|
|
4
3
|
const addNewBlockAt = (editorState, pivotBlockKey, type = 'unstyled', data = {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
5
4
|
) => {
|
|
6
5
|
const contentState = editorState.getCurrentContent();
|
|
@@ -33,6 +32,5 @@ const addNewBlockAt = (editorState, pivotBlockKey, type = 'unstyled', data = {}
|
|
|
33
32
|
});
|
|
34
33
|
return EditorState.push(editorState, nextContentState, 'split-block');
|
|
35
34
|
};
|
|
36
|
-
|
|
37
35
|
export default addNewBlockAt;
|
|
38
36
|
//# sourceMappingURL=addNewBlockAt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addNewBlockAt.js","names":["Immutable","ContentBlock","EditorState","genKey","addNewBlockAt","editorState","pivotBlockKey","type","data","contentState","getCurrentContent","blockMap","getBlockMap","pivotBlock","get","Error","blocksBefore","toSeq","takeUntil","v","blocksAfter","skipUntil","rest","key","block","text","characterList","List","depth","Map","selectionState","getSelection","nextBlockMap","concat","toOrderedMap","nextContentState","merge","selectionBefore","selectionAfter","anchorKey","anchorOffset","focusKey","focusOffset","isBackward","push"],"sources":["../../../../src/Editor/utils/addNewBlockAt.ts"],"sourcesContent":["import Immutable from 'immutable';\nimport { ContentBlock, ContentState, EditorState, genKey } from 'draft-js';\n\nconst addNewBlockAt = (\n editorState: EditorState,\n pivotBlockKey: string,\n type = 'unstyled',\n data: Record<string, any> = {} // eslint-disable-line @typescript-eslint/no-explicit-any\n): EditorState => {\n const contentState = editorState.getCurrentContent();\n const blockMap = contentState.getBlockMap();\n const pivotBlock = blockMap.get(pivotBlockKey);\n if (!pivotBlock)\n throw new Error(\n `The pivot key - ${pivotBlockKey} is not present in blockMap`\n );\n const blocksBefore = blockMap.toSeq().takeUntil((v) => v === pivotBlock);\n const blocksAfter = blockMap\n .toSeq()\n .skipUntil((v) => v === pivotBlock)\n .rest();\n const key = genKey();\n\n const block = new ContentBlock({\n key,\n type,\n text: '',\n characterList: Immutable.List(),\n depth: 0,\n data: Immutable.Map(data),\n });\n\n const selectionState = editorState.getSelection();\n const nextBlockMap = blocksBefore\n .concat(\n [\n [pivotBlockKey, pivotBlock],\n [key, block],\n ],\n blocksAfter\n )\n .toOrderedMap();\n\n const nextContentState = contentState.merge({\n blockMap: nextBlockMap,\n selectionBefore: selectionState,\n selectionAfter: selectionState.merge({\n anchorKey: key,\n anchorOffset: 0,\n focusKey: key,\n focusOffset: 0,\n isBackward: false,\n }),\n }) as ContentState;\n\n return EditorState.push(editorState, nextContentState, 'split-block');\n};\n\nexport default addNewBlockAt;\n"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"addNewBlockAt.js","names":["Immutable","ContentBlock","EditorState","genKey","addNewBlockAt","editorState","pivotBlockKey","type","data","contentState","getCurrentContent","blockMap","getBlockMap","pivotBlock","get","Error","blocksBefore","toSeq","takeUntil","v","blocksAfter","skipUntil","rest","key","block","text","characterList","List","depth","Map","selectionState","getSelection","nextBlockMap","concat","toOrderedMap","nextContentState","merge","selectionBefore","selectionAfter","anchorKey","anchorOffset","focusKey","focusOffset","isBackward","push"],"sources":["../../../../src/Editor/utils/addNewBlockAt.ts"],"sourcesContent":["import Immutable from 'immutable';\nimport { ContentBlock, ContentState, EditorState, genKey } from 'draft-js';\n\nconst addNewBlockAt = (\n editorState: EditorState,\n pivotBlockKey: string,\n type = 'unstyled',\n data: Record<string, any> = {} // eslint-disable-line @typescript-eslint/no-explicit-any\n): EditorState => {\n const contentState = editorState.getCurrentContent();\n const blockMap = contentState.getBlockMap();\n const pivotBlock = blockMap.get(pivotBlockKey);\n if (!pivotBlock)\n throw new Error(\n `The pivot key - ${pivotBlockKey} is not present in blockMap`\n );\n const blocksBefore = blockMap.toSeq().takeUntil((v) => v === pivotBlock);\n const blocksAfter = blockMap\n .toSeq()\n .skipUntil((v) => v === pivotBlock)\n .rest();\n const key = genKey();\n\n const block = new ContentBlock({\n key,\n type,\n text: '',\n characterList: Immutable.List(),\n depth: 0,\n data: Immutable.Map(data),\n });\n\n const selectionState = editorState.getSelection();\n const nextBlockMap = blocksBefore\n .concat(\n [\n [pivotBlockKey, pivotBlock],\n [key, block],\n ],\n blocksAfter\n )\n .toOrderedMap();\n\n const nextContentState = contentState.merge({\n blockMap: nextBlockMap,\n selectionBefore: selectionState,\n selectionAfter: selectionState.merge({\n anchorKey: key,\n anchorOffset: 0,\n focusKey: key,\n focusOffset: 0,\n isBackward: false,\n }),\n }) as ContentState;\n\n return EditorState.push(editorState, nextContentState, 'split-block');\n};\n\nexport default addNewBlockAt;\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,WAAW;AACjC,SAASC,YAAY,EAAgBC,WAAW,EAAEC,MAAM,QAAQ,UAAU;AAE1E,MAAMC,aAAa,GAAG,CACpBC,WAAwB,EACxBC,aAAqB,EACrBC,IAAI,GAAG,UAAU,EACjBC,IAAyB,GAAG,CAAC,CAAC,CAAC;AAAA,KACf;EAChB,MAAMC,YAAY,GAAGJ,WAAW,CAACK,iBAAiB,EAAE;EACpD,MAAMC,QAAQ,GAAGF,YAAY,CAACG,WAAW,EAAE;EAC3C,MAAMC,UAAU,GAAGF,QAAQ,CAACG,GAAG,CAACR,aAAa,CAAC;EAC9C,IAAI,CAACO,UAAU,EACb,MAAM,IAAIE,KAAK,CACZ,mBAAkBT,aAAc,6BAA4B,CAC9D;EACH,MAAMU,YAAY,GAAGL,QAAQ,CAACM,KAAK,EAAE,CAACC,SAAS,CAAEC,CAAC,IAAKA,CAAC,KAAKN,UAAU,CAAC;EACxE,MAAMO,WAAW,GAAGT,QAAQ,CACzBM,KAAK,EAAE,CACPI,SAAS,CAAEF,CAAC,IAAKA,CAAC,KAAKN,UAAU,CAAC,CAClCS,IAAI,EAAE;EACT,MAAMC,GAAG,GAAGpB,MAAM,EAAE;EAEpB,MAAMqB,KAAK,GAAG,IAAIvB,YAAY,CAAC;IAC7BsB,GAAG;IACHhB,IAAI;IACJkB,IAAI,EAAE,EAAE;IACRC,aAAa,EAAE1B,SAAS,CAAC2B,IAAI,EAAE;IAC/BC,KAAK,EAAE,CAAC;IACRpB,IAAI,EAAER,SAAS,CAAC6B,GAAG,CAACrB,IAAI;EAC1B,CAAC,CAAC;EAEF,MAAMsB,cAAc,GAAGzB,WAAW,CAAC0B,YAAY,EAAE;EACjD,MAAMC,YAAY,GAAGhB,YAAY,CAC9BiB,MAAM,CACL,CACE,CAAC3B,aAAa,EAAEO,UAAU,CAAC,EAC3B,CAACU,GAAG,EAAEC,KAAK,CAAC,CACb,EACDJ,WAAW,CACZ,CACAc,YAAY,EAAE;EAEjB,MAAMC,gBAAgB,GAAG1B,YAAY,CAAC2B,KAAK,CAAC;IAC1CzB,QAAQ,EAAEqB,YAAY;IACtBK,eAAe,EAAEP,cAAc;IAC/BQ,cAAc,EAAER,cAAc,CAACM,KAAK,CAAC;MACnCG,SAAS,EAAEhB,GAAG;MACdiB,YAAY,EAAE,CAAC;MACfC,QAAQ,EAAElB,GAAG;MACbmB,WAAW,EAAE,CAAC;MACdC,UAAU,EAAE;IACd,CAAC;EACH,CAAC,CAAiB;EAElB,OAAOzC,WAAW,CAAC0C,IAAI,CAACvC,WAAW,EAAE8B,gBAAgB,EAAE,aAAa,CAAC;AACvE,CAAC;AAED,eAAe/B,aAAa"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EditorState } from 'draft-js';
|
|
2
|
-
|
|
3
2
|
const changeBlock = (editorState, block, type, data = {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
4
3
|
) => {
|
|
5
4
|
const contentState = editorState.getCurrentContent();
|
|
@@ -13,6 +12,5 @@ const changeBlock = (editorState, block, type, data = {} // eslint-disable-line
|
|
|
13
12
|
});
|
|
14
13
|
return EditorState.push(editorState, nextContentState, 'change-block-type');
|
|
15
14
|
};
|
|
16
|
-
|
|
17
15
|
export default changeBlock;
|
|
18
16
|
//# sourceMappingURL=changeBlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeBlock.js","names":["EditorState","changeBlock","editorState","block","type","data","contentState","getCurrentContent","nextCurrentBlock","merge","nextContentState","blockMap","getBlockMap","set","getKey","selectionAfter","getSelection","push"],"sources":["../../../../src/Editor/utils/changeBlock.ts"],"sourcesContent":["import { ContentBlock, ContentState, EditorState } from 'draft-js';\n\nconst changeBlock = (\n editorState: EditorState,\n block: ContentBlock,\n type: string,\n data: Record<string, any> = {} // eslint-disable-line @typescript-eslint/no-explicit-any\n): EditorState => {\n const contentState = editorState.getCurrentContent();\n\n const nextCurrentBlock = block.merge({ type, data }) as ContentBlock;\n const nextContentState = contentState.merge({\n blockMap: contentState.getBlockMap().set(block.getKey(), nextCurrentBlock),\n selectionAfter: editorState.getSelection(),\n }) as ContentState;\n\n return EditorState.push(editorState, nextContentState, 'change-block-type');\n};\n\nexport default changeBlock;\n"],"mappings":"AAAA,SAAqCA,
|
|
1
|
+
{"version":3,"file":"changeBlock.js","names":["EditorState","changeBlock","editorState","block","type","data","contentState","getCurrentContent","nextCurrentBlock","merge","nextContentState","blockMap","getBlockMap","set","getKey","selectionAfter","getSelection","push"],"sources":["../../../../src/Editor/utils/changeBlock.ts"],"sourcesContent":["import { ContentBlock, ContentState, EditorState } from 'draft-js';\n\nconst changeBlock = (\n editorState: EditorState,\n block: ContentBlock,\n type: string,\n data: Record<string, any> = {} // eslint-disable-line @typescript-eslint/no-explicit-any\n): EditorState => {\n const contentState = editorState.getCurrentContent();\n\n const nextCurrentBlock = block.merge({ type, data }) as ContentBlock;\n const nextContentState = contentState.merge({\n blockMap: contentState.getBlockMap().set(block.getKey(), nextCurrentBlock),\n selectionAfter: editorState.getSelection(),\n }) as ContentState;\n\n return EditorState.push(editorState, nextContentState, 'change-block-type');\n};\n\nexport default changeBlock;\n"],"mappings":"AAAA,SAAqCA,WAAW,QAAQ,UAAU;AAElE,MAAMC,WAAW,GAAG,CAClBC,WAAwB,EACxBC,KAAmB,EACnBC,IAAY,EACZC,IAAyB,GAAG,CAAC,CAAC,CAAC;AAAA,KACf;EAChB,MAAMC,YAAY,GAAGJ,WAAW,CAACK,iBAAiB,EAAE;EAEpD,MAAMC,gBAAgB,GAAGL,KAAK,CAACM,KAAK,CAAC;IAAEL,IAAI;IAAEC;EAAK,CAAC,CAAiB;EACpE,MAAMK,gBAAgB,GAAGJ,YAAY,CAACG,KAAK,CAAC;IAC1CE,QAAQ,EAAEL,YAAY,CAACM,WAAW,EAAE,CAACC,GAAG,CAACV,KAAK,CAACW,MAAM,EAAE,EAAEN,gBAAgB,CAAC;IAC1EO,cAAc,EAAEb,WAAW,CAACc,YAAY;EAC1C,CAAC,CAAiB;EAElB,OAAOhB,WAAW,CAACiB,IAAI,CAACf,WAAW,EAAEQ,gBAAgB,EAAE,mBAAmB,CAAC;AAC7E,CAAC;AAED,eAAeT,WAAW"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { EditorState } from 'draft-js';
|
|
2
2
|
import createDecorator from './createDecorator';
|
|
3
|
-
|
|
4
3
|
const createContentEditorState = contentState => EditorState.createWithContent(contentState, createDecorator());
|
|
5
|
-
|
|
6
4
|
export default createContentEditorState;
|
|
7
5
|
//# sourceMappingURL=createContentEditorState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContentEditorState.js","names":["EditorState","createDecorator","createContentEditorState","contentState","createWithContent"],"sources":["../../../../src/Editor/utils/createContentEditorState.ts"],"sourcesContent":["import { ContentState, EditorState } from 'draft-js';\nimport createDecorator from './createDecorator';\n\nconst createContentEditorState = (contentState: ContentState): EditorState =>\n EditorState.createWithContent(contentState, createDecorator());\n\nexport default createContentEditorState;\n"],"mappings":"AAAA,SAAuBA,
|
|
1
|
+
{"version":3,"file":"createContentEditorState.js","names":["EditorState","createDecorator","createContentEditorState","contentState","createWithContent"],"sources":["../../../../src/Editor/utils/createContentEditorState.ts"],"sourcesContent":["import { ContentState, EditorState } from 'draft-js';\nimport createDecorator from './createDecorator';\n\nconst createContentEditorState = (contentState: ContentState): EditorState =>\n EditorState.createWithContent(contentState, createDecorator());\n\nexport default createContentEditorState;\n"],"mappings":"AAAA,SAAuBA,WAAW,QAAQ,UAAU;AACpD,OAAOC,eAAe,MAAM,mBAAmB;AAE/C,MAAMC,wBAAwB,GAAIC,YAA0B,IAC1DH,WAAW,CAACI,iBAAiB,CAACD,YAAY,EAAEF,eAAe,EAAE,CAAC;AAEhE,eAAeC,wBAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDecorator.js","names":["CompositeDecorator","linkDecorator","createDecorator"],"sources":["../../../../src/Editor/utils/createDecorator.ts"],"sourcesContent":["import { CompositeDecorator } from 'draft-js';\nimport linkDecorator from '../decorators/linkDecorator';\n\nconst createDecorator = (): CompositeDecorator =>\n new CompositeDecorator([linkDecorator]);\n\nexport default createDecorator;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"createDecorator.js","names":["CompositeDecorator","linkDecorator","createDecorator"],"sources":["../../../../src/Editor/utils/createDecorator.ts"],"sourcesContent":["import { CompositeDecorator } from 'draft-js';\nimport linkDecorator from '../decorators/linkDecorator';\n\nconst createDecorator = (): CompositeDecorator =>\n new CompositeDecorator([linkDecorator]);\n\nexport default createDecorator;\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,UAAU;AAC7C,OAAOC,aAAa,MAAM,6BAA6B;AAEvD,MAAMC,eAAe,GAAG,MACtB,IAAIF,kBAAkB,CAAC,CAACC,aAAa,CAAC,CAAC;AAEzC,eAAeC,eAAe"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { EditorState } from 'draft-js';
|
|
2
2
|
import createDecorator from './createDecorator';
|
|
3
|
-
|
|
4
3
|
const createEmptyEditorState = () => EditorState.createEmpty(createDecorator());
|
|
5
|
-
|
|
6
4
|
export default createEmptyEditorState;
|
|
7
5
|
//# sourceMappingURL=createEmptyEditorState.js.map
|