@toptal/picasso-rich-text-editor 17.2.3-alpha-FF-49-restore-publishing-0960a3e32.0 → 17.2.3
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-package/src/plugins/TextLengthPlugin/TextLengthPlugin.d.ts.map +1 -1
- package/dist-package/src/plugins/TextLengthPlugin/TextLengthPlugin.js +7 -1
- package/dist-package/src/plugins/TextLengthPlugin/TextLengthPlugin.js.map +1 -1
- package/package.json +21 -21
- package/src/plugins/TextLengthPlugin/TextLengthPlugin.test.tsx +70 -0
- package/src/plugins/TextLengthPlugin/TextLengthPlugin.tsx +9 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextLengthPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/TextLengthPlugin/TextLengthPlugin.tsx"],"names":[],"mappings":"AAKA,oBAAY,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;AAE9D,oBAAY,KAAK,GAAG;IAClB;;OAEG;IACH,kBAAkB,EAAE,uBAAuB,CAAA;CAC5C,CAAA;AAED,QAAA,MAAM,gBAAgB;6BAAmC,KAAK;;
|
|
1
|
+
{"version":3,"file":"TextLengthPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/TextLengthPlugin/TextLengthPlugin.tsx"],"names":[],"mappings":"AAKA,oBAAY,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;AAE9D,oBAAY,KAAK,GAAG;IAClB;;OAEG;IACH,kBAAkB,EAAE,uBAAuB,CAAA;CAC5C,CAAA;AAED,QAAA,MAAM,gBAAgB;6BAAmC,KAAK;;CAyB7D,CAAA;AAID,eAAe,gBAAgB,CAAA"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
-
import { RootNode } from 'lexical';
|
|
3
|
+
import { $getRoot, RootNode } from 'lexical';
|
|
4
4
|
import { noop } from '@toptal/picasso-utils';
|
|
5
5
|
const TextLengthPlugin = ({ onTextLengthChange = noop }) => {
|
|
6
6
|
const [editor] = useLexicalComposerContext();
|
|
7
7
|
useEffect(() => {
|
|
8
|
+
// Set initial text length on mount
|
|
9
|
+
editor.getEditorState().read(() => {
|
|
10
|
+
const rootNode = $getRoot();
|
|
11
|
+
const initialTextContentSize = rootNode.getTextContentSize();
|
|
12
|
+
onTextLengthChange(initialTextContentSize);
|
|
13
|
+
});
|
|
8
14
|
return editor.registerNodeTransform(RootNode, (rootNode) => {
|
|
9
15
|
const prevTextContentSize = editor
|
|
10
16
|
.getEditorState()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextLengthPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/TextLengthPlugin/TextLengthPlugin.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"TextLengthPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/TextLengthPlugin/TextLengthPlugin.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAW5C,MAAM,gBAAgB,GAAG,CAAC,EAAE,kBAAkB,GAAG,IAAI,EAAS,EAAE,EAAE;IAChE,MAAM,CAAC,MAAM,CAAC,GAAG,yBAAyB,EAAE,CAAA;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,mCAAmC;QACnC,MAAM,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAChC,MAAM,QAAQ,GAAG,QAAQ,EAAE,CAAA;YAC3B,MAAM,sBAAsB,GAAG,QAAQ,CAAC,kBAAkB,EAAE,CAAA;YAE5D,kBAAkB,CAAC,sBAAsB,CAAC,CAAA;QAC5C,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAC,qBAAqB,CAAC,QAAQ,EAAE,CAAC,QAAkB,EAAE,EAAE;YACnE,MAAM,mBAAmB,GAAG,MAAM;iBAC/B,cAAc,EAAE;iBAChB,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAA;YAC5C,MAAM,eAAe,GAAG,QAAQ,CAAC,kBAAkB,EAAE,CAAA;YAErD,IAAI,mBAAmB,KAAK,eAAe,EAAE;gBAC3C,kBAAkB,CAAC,eAAe,CAAC,CAAA;aACpC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAA;IAEhC,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,gBAAgB,CAAC,WAAW,GAAG,yBAAyB,CAAA;AAExD,eAAe,gBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/picasso-rich-text-editor",
|
|
3
|
-
"version": "17.2.3
|
|
3
|
+
"version": "17.2.3",
|
|
4
4
|
"description": "Picasso rich text editor",
|
|
5
5
|
"author": "Toptal",
|
|
6
6
|
"homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso-rich-text-editor#readme",
|
|
@@ -29,33 +29,33 @@
|
|
|
29
29
|
"@lexical/text": "0.11.2",
|
|
30
30
|
"@lexical/utils": "0.11.2",
|
|
31
31
|
"@material-ui/core": "4.12.4",
|
|
32
|
-
"@toptal/picasso-shared": "^15.0.
|
|
32
|
+
"@toptal/picasso-shared": "^15.0.0",
|
|
33
33
|
"react": ">=16.12.0 < 19.0.0",
|
|
34
34
|
"react-dom": ">=16.12.0 < 19.0.0",
|
|
35
35
|
"typescript": "~4.7.0",
|
|
36
|
-
"@toptal/picasso-tailwind-merge": "2.0.
|
|
37
|
-
"@toptal/picasso-tailwind": "
|
|
36
|
+
"@toptal/picasso-tailwind-merge": "^2.0.0",
|
|
37
|
+
"@toptal/picasso-tailwind": ">=2.7"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@emoji-mart/data": "^1.2.1",
|
|
41
41
|
"@emoji-mart/react": "^1.1.1",
|
|
42
42
|
"@lexical/html": "0.11.2",
|
|
43
43
|
"@lexical/react": "0.11.2",
|
|
44
|
-
"@toptal/picasso-container": "3.1.
|
|
45
|
-
"@toptal/picasso-button": "4.0.
|
|
46
|
-
"@toptal/picasso-icons": "1.12.
|
|
47
|
-
"@toptal/picasso-file-input": "4.0.
|
|
48
|
-
"@toptal/picasso-image": "3.0.
|
|
49
|
-
"@toptal/picasso-outlined-input": "4.1.
|
|
50
|
-
"@toptal/picasso-list": "5.0.
|
|
51
|
-
"@toptal/picasso-link": "3.0.
|
|
52
|
-
"@toptal/picasso-select": "4.1.
|
|
53
|
-
"@toptal/picasso-input-adornment": "3.0.
|
|
54
|
-
"@toptal/picasso-typography": "4.0.
|
|
55
|
-
"@toptal/picasso-modal": "3.2.
|
|
56
|
-
"@toptal/picasso-form": "6.3.
|
|
57
|
-
"@toptal/picasso-input": "4.1.
|
|
58
|
-
"@toptal/picasso-utils": "3.1.
|
|
44
|
+
"@toptal/picasso-container": "3.1.2",
|
|
45
|
+
"@toptal/picasso-button": "4.0.23",
|
|
46
|
+
"@toptal/picasso-icons": "1.12.1",
|
|
47
|
+
"@toptal/picasso-file-input": "4.0.22",
|
|
48
|
+
"@toptal/picasso-image": "3.0.3",
|
|
49
|
+
"@toptal/picasso-outlined-input": "4.1.2",
|
|
50
|
+
"@toptal/picasso-list": "5.0.11",
|
|
51
|
+
"@toptal/picasso-link": "3.0.6",
|
|
52
|
+
"@toptal/picasso-select": "4.1.2",
|
|
53
|
+
"@toptal/picasso-input-adornment": "3.0.10",
|
|
54
|
+
"@toptal/picasso-typography": "4.0.4",
|
|
55
|
+
"@toptal/picasso-modal": "3.2.2",
|
|
56
|
+
"@toptal/picasso-form": "6.3.2",
|
|
57
|
+
"@toptal/picasso-input": "4.1.2",
|
|
58
|
+
"@toptal/picasso-utils": "3.1.0",
|
|
59
59
|
"classnames": "^2.5.1",
|
|
60
60
|
"emoji-mart": "^5.5.2",
|
|
61
61
|
"hast-to-hyperscript": "^9.0.1",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@material-ui/core": "4.12.4",
|
|
70
70
|
"@testing-library/react-hooks": "^8.0.1",
|
|
71
|
-
"@toptal/picasso-test-utils": "1.1.
|
|
72
|
-
"@toptal/picasso-tailwind-merge": "2.0.
|
|
71
|
+
"@toptal/picasso-test-utils": "1.1.1",
|
|
72
|
+
"@toptal/picasso-tailwind-merge": "2.0.3",
|
|
73
73
|
"@types/classnames": "^2.3.1"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from '@toptal/picasso-test-utils'
|
|
3
|
+
import { LexicalComposer } from '@lexical/react/LexicalComposer'
|
|
4
|
+
import { $createParagraphNode, $createTextNode, $getRoot } from 'lexical'
|
|
5
|
+
|
|
6
|
+
import TextLengthPlugin from './TextLengthPlugin'
|
|
7
|
+
|
|
8
|
+
const createEditor = (initialText = '') => {
|
|
9
|
+
const initialConfig = {
|
|
10
|
+
namespace: 'test',
|
|
11
|
+
theme: {},
|
|
12
|
+
onError: () => {},
|
|
13
|
+
editorState: () => {
|
|
14
|
+
const root = $getRoot()
|
|
15
|
+
|
|
16
|
+
if (initialText) {
|
|
17
|
+
const paragraph = $createParagraphNode()
|
|
18
|
+
const textNode = $createTextNode(initialText)
|
|
19
|
+
|
|
20
|
+
paragraph.append(textNode)
|
|
21
|
+
root.append(paragraph)
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return initialConfig
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('TextLengthPlugin', () => {
|
|
30
|
+
it('calls onTextLengthChange with initial text length on mount', () => {
|
|
31
|
+
const onTextLengthChange = jest.fn()
|
|
32
|
+
const initialText = 'Hello world'
|
|
33
|
+
const editorConfig = createEditor(initialText)
|
|
34
|
+
|
|
35
|
+
render(
|
|
36
|
+
<LexicalComposer initialConfig={editorConfig}>
|
|
37
|
+
<TextLengthPlugin onTextLengthChange={onTextLengthChange} />
|
|
38
|
+
</LexicalComposer>
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
expect(onTextLengthChange).toHaveBeenCalledWith(initialText.length)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('calls onTextLengthChange with 0 when no initial text', () => {
|
|
45
|
+
const onTextLengthChange = jest.fn()
|
|
46
|
+
const editorConfig = createEditor()
|
|
47
|
+
|
|
48
|
+
render(
|
|
49
|
+
<LexicalComposer initialConfig={editorConfig}>
|
|
50
|
+
<TextLengthPlugin onTextLengthChange={onTextLengthChange} />
|
|
51
|
+
</LexicalComposer>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(onTextLengthChange).toHaveBeenCalledWith(0)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('calls onTextLengthChange with correct length for multi-line text', () => {
|
|
58
|
+
const onTextLengthChange = jest.fn()
|
|
59
|
+
const initialText = 'First line\nSecond line'
|
|
60
|
+
const editorConfig = createEditor(initialText)
|
|
61
|
+
|
|
62
|
+
render(
|
|
63
|
+
<LexicalComposer initialConfig={editorConfig}>
|
|
64
|
+
<TextLengthPlugin onTextLengthChange={onTextLengthChange} />
|
|
65
|
+
</LexicalComposer>
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(onTextLengthChange).toHaveBeenCalledWith(initialText.length)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react'
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
|
3
|
-
import { RootNode } from 'lexical'
|
|
3
|
+
import { $getRoot, RootNode } from 'lexical'
|
|
4
4
|
import { noop } from '@toptal/picasso-utils'
|
|
5
5
|
|
|
6
6
|
export type TextLengthChangeHandler = (length: number) => void
|
|
@@ -16,6 +16,14 @@ const TextLengthPlugin = ({ onTextLengthChange = noop }: Props) => {
|
|
|
16
16
|
const [editor] = useLexicalComposerContext()
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
|
+
// Set initial text length on mount
|
|
20
|
+
editor.getEditorState().read(() => {
|
|
21
|
+
const rootNode = $getRoot()
|
|
22
|
+
const initialTextContentSize = rootNode.getTextContentSize()
|
|
23
|
+
|
|
24
|
+
onTextLengthChange(initialTextContentSize)
|
|
25
|
+
})
|
|
26
|
+
|
|
19
27
|
return editor.registerNodeTransform(RootNode, (rootNode: RootNode) => {
|
|
20
28
|
const prevTextContentSize = editor
|
|
21
29
|
.getEditorState()
|