@lexical/react 0.7.5 → 0.7.6
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.
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export declare function CharacterLimitPlugin({ charset, }: {
|
|
8
|
+
export declare function CharacterLimitPlugin({ charset, maxLength, }: {
|
|
9
9
|
charset: 'UTF-8' | 'UTF-16';
|
|
10
|
+
maxLength: number;
|
|
10
11
|
}): JSX.Element;
|
|
@@ -277,10 +277,11 @@ function utf8Length(text) {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
function CharacterLimitPlugin({
|
|
280
|
-
charset = 'UTF-16'
|
|
280
|
+
charset = 'UTF-16',
|
|
281
|
+
maxLength = CHARACTER_LIMIT
|
|
281
282
|
}) {
|
|
282
283
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
283
|
-
const [remainingCharacters, setRemainingCharacters] = React.useState(
|
|
284
|
+
const [remainingCharacters, setRemainingCharacters] = React.useState(maxLength);
|
|
284
285
|
const characterLimitProps = React.useMemo(() => ({
|
|
285
286
|
remainingCharacters: setRemainingCharacters,
|
|
286
287
|
strlen: text => {
|
|
@@ -293,7 +294,7 @@ function CharacterLimitPlugin({
|
|
|
293
294
|
}
|
|
294
295
|
}
|
|
295
296
|
}), [charset]);
|
|
296
|
-
useCharacterLimit(editor,
|
|
297
|
+
useCharacterLimit(editor, maxLength, characterLimitProps);
|
|
297
298
|
return /*#__PURE__*/React.createElement("span", {
|
|
298
299
|
className: `characters-limit ${remainingCharacters < 0 ? 'characters-limit-exceeded' : ''}`
|
|
299
300
|
}, remainingCharacters);
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
function D(b,c,
|
|
9
|
-
{var w=b.isComposing();
|
|
10
|
-
null!==h&&h.select())}else
|
|
11
|
-
else for(var
|
|
12
|
-
function F(b,c,
|
|
13
|
-
exports.CharacterLimitPlugin=function({charset:b="UTF-16"}){let [
|
|
14
|
-
|
|
7
|
+
'use strict';var n=require("@lexical/react/LexicalComposerContext"),u=require("react"),v=require("@lexical/overflow"),z=require("@lexical/text"),A=require("@lexical/utils"),C=require("lexical");
|
|
8
|
+
function D(b,c,p=Object.freeze({})){let {strlen:e=l=>l.length,remainingCharacters:q=()=>{}}=p;u.useEffect(()=>{if(!b.hasNodes([v.OverflowNode]))throw Error("Minified Lexical error #57; visit https://lexical.dev/docs/error?code=57 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[b]);u.useEffect(()=>{let l=b.getEditorState().read(z.$rootTextContent),d=0;return A.mergeRegister(b.registerTextContentListener(f=>{l=f}),b.registerUpdateListener(({dirtyLeaves:f})=>
|
|
9
|
+
{var w=b.isComposing();f=0<f.size;if(!w&&f){w=e(l);f=w>c||null!==d&&d>c;q(c-w);if(null===d||f){let r=F(l,c,e);b.update(()=>{let B=A.$dfs(),J=B.length,x=0;for(let y=0;y<J;y+=1){var {node:a}=B[y];if(v.$isOverflowNode(a)){var g=x;if(x+a.getTextContentSize()<=r){var h=a.getParent();g=a.getPreviousSibling();var k=a.getNextSibling();G(a);a=C.$getSelection();!C.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(C.$isTextNode(g)?g.select():C.$isTextNode(k)?k.select():
|
|
10
|
+
null!==h&&h.select())}else g<r&&(h=a.getFirstDescendant(),k=null!==h?h.getTextContentSize():0,g+=k,h=C.$isTextNode(h)&&h.isSimpleText(),g=g<=r,(h||g)&&G(a))}else if(C.$isLeafNode(a)&&(g=x,x+=a.getTextContentSize(),x>r&&!v.$isOverflowNode(a.getParent())&&(h=C.$getSelection(),g<r&&C.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(r-g),a=H(a)):a=H(a),null!==h&&C.$setSelection(h),g=a.getPreviousSibling(),v.$isOverflowNode(g)))){k=a.getFirstChild();var t=g.getChildren();h=t.length;if(null===k)a.append(...t);
|
|
11
|
+
else for(var m=0;m<h;m++)k.insertBefore(t[m]);m=C.$getSelection();if(C.$isRangeSelection(m)){k=m.anchor;t=k.getNode();m=m.focus;let E=k.getNode();t.is(g)?k.set(a.getKey(),k.offset,"element"):t.is(a)&&k.set(a.getKey(),h+k.offset,"element");E.is(g)?m.set(a.getKey(),m.offset,"element"):E.is(a)&&m.set(a.getKey(),h+m.offset,"element")}g.remove()}}},{tag:"history-merge"})}d=w}}))},[b,c,q,e])}
|
|
12
|
+
function F(b,c,p){var e=Intl.Segmenter;let q=0;var l=0;if("function"===typeof e){b=(new e).segment(b);for(var {segment:d}of b){l+=p(d);if(l>c)break;q+=d.length}}else for(d=Array.from(b),b=d.length,e=0;e<b;e++){let f=d[e];l+=p(f);if(l>c)break;q+=f.length}return q}function H(b){let c=v.$createOverflowNode();b.insertBefore(c);c.append(b);return c}function G(b){let c=b.getChildren(),p=c.length;for(let e=0;e<p;e++)b.insertBefore(c[e]);b.remove();return 0<p?c[p-1]:null}let I=null;
|
|
13
|
+
exports.CharacterLimitPlugin=function({charset:b="UTF-16",maxLength:c=5}){let [p]=n.useLexicalComposerContext(),[e,q]=u.useState(c),l=u.useMemo(()=>({remainingCharacters:q,strlen:d=>{if("UTF-8"===b){if(void 0===window.TextEncoder)var f=null;else null===I&&(I=new window.TextEncoder),f=I;null===f?(f=encodeURIComponent(d).match(/%[89ABab]/g),d=d.length+(f?f.length:0)):d=f.encode(d).length;return d}if("UTF-16"===b)return d.length;throw Error("Unrecognized charset");}}),[b]);D(p,c,l);return u.createElement("span",
|
|
14
|
+
{className:`characters-limit ${0>e?"characters-limit-exceeded":""}`},e)}
|
package/package.json
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.6",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.7.
|
|
14
|
-
"@lexical/code": "0.7.
|
|
15
|
-
"@lexical/dragon": "0.7.
|
|
16
|
-
"@lexical/hashtag": "0.7.
|
|
17
|
-
"@lexical/history": "0.7.
|
|
18
|
-
"@lexical/link": "0.7.
|
|
19
|
-
"@lexical/list": "0.7.
|
|
20
|
-
"@lexical/mark": "0.7.
|
|
21
|
-
"@lexical/markdown": "0.7.
|
|
22
|
-
"@lexical/overflow": "0.7.
|
|
23
|
-
"@lexical/plain-text": "0.7.
|
|
24
|
-
"@lexical/rich-text": "0.7.
|
|
25
|
-
"@lexical/selection": "0.7.
|
|
26
|
-
"@lexical/table": "0.7.
|
|
27
|
-
"@lexical/text": "0.7.
|
|
28
|
-
"@lexical/utils": "0.7.
|
|
29
|
-
"@lexical/yjs": "0.7.
|
|
13
|
+
"@lexical/clipboard": "0.7.6",
|
|
14
|
+
"@lexical/code": "0.7.6",
|
|
15
|
+
"@lexical/dragon": "0.7.6",
|
|
16
|
+
"@lexical/hashtag": "0.7.6",
|
|
17
|
+
"@lexical/history": "0.7.6",
|
|
18
|
+
"@lexical/link": "0.7.6",
|
|
19
|
+
"@lexical/list": "0.7.6",
|
|
20
|
+
"@lexical/mark": "0.7.6",
|
|
21
|
+
"@lexical/markdown": "0.7.6",
|
|
22
|
+
"@lexical/overflow": "0.7.6",
|
|
23
|
+
"@lexical/plain-text": "0.7.6",
|
|
24
|
+
"@lexical/rich-text": "0.7.6",
|
|
25
|
+
"@lexical/selection": "0.7.6",
|
|
26
|
+
"@lexical/table": "0.7.6",
|
|
27
|
+
"@lexical/text": "0.7.6",
|
|
28
|
+
"@lexical/utils": "0.7.6",
|
|
29
|
+
"@lexical/yjs": "0.7.6",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.7.
|
|
33
|
+
"lexical": "0.7.6",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|