@gcforms/editor 1.0.0 → 1.0.1
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/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [1.0.
|
|
8
|
+
## [1.0.1] - 2025-04-17
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Only show contentLength/maxLength indicator when contentLength reaches 80% of maxLength
|
|
13
|
+
|
|
14
|
+
## [1.0.0] - 2025-04-17
|
|
9
15
|
|
|
10
16
|
### Changed
|
|
11
17
|
|
package/package.json
CHANGED
package/src/Editor.tsx
CHANGED
|
@@ -59,7 +59,6 @@ export const Editor = ({
|
|
|
59
59
|
|
|
60
60
|
const [floatingAnchorElem, setFloatingAnchorElem] = useState<HTMLDivElement | null>(null);
|
|
61
61
|
const [isLinkEditMode, setIsLinkEditMode] = useState<boolean>(false);
|
|
62
|
-
const [contentLength, setContentLength] = useState<number>(0);
|
|
63
62
|
|
|
64
63
|
const randomId = useId();
|
|
65
64
|
const editorId = id || `editor-${randomId}`;
|
|
@@ -116,9 +115,7 @@ export const Editor = ({
|
|
|
116
115
|
<LinkPlugin />
|
|
117
116
|
<TabControlPlugin />
|
|
118
117
|
<ListMaxIndentLevelPlugin maxDepth={5} />
|
|
119
|
-
|
|
120
|
-
<MaxLengthPlugin maxLength={maxLength} setContentLength={setContentLength} />
|
|
121
|
-
)}
|
|
118
|
+
|
|
122
119
|
{floatingAnchorElem && (
|
|
123
120
|
<>
|
|
124
121
|
<FloatingLinkEditorPlugin
|
|
@@ -129,13 +126,9 @@ export const Editor = ({
|
|
|
129
126
|
</>
|
|
130
127
|
)}
|
|
131
128
|
{maxLength && (
|
|
132
|
-
|
|
133
|
-
{maxLength
|
|
134
|
-
|
|
135
|
-
{contentLength}/{maxLength}
|
|
136
|
-
</>
|
|
137
|
-
)}
|
|
138
|
-
</div>
|
|
129
|
+
<>
|
|
130
|
+
<MaxLengthPlugin maxLength={maxLength} />
|
|
131
|
+
</>
|
|
139
132
|
)}
|
|
140
133
|
</div>
|
|
141
134
|
</LexicalComposer>
|
|
@@ -10,16 +10,33 @@ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext
|
|
|
10
10
|
import { $trimTextContentFromAnchor } from "@lexical/selection";
|
|
11
11
|
import { $restoreEditorState } from "@lexical/utils";
|
|
12
12
|
import { $getSelection, $isRangeSelection, EditorState, RootNode } from "lexical";
|
|
13
|
-
import { useEffect } from "react";
|
|
13
|
+
import { JSX, useEffect, useState } from "react";
|
|
14
|
+
import "./styles.css";
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
const MaxLengthIndicator = ({
|
|
16
17
|
maxLength,
|
|
17
|
-
|
|
18
|
+
contentLength,
|
|
18
19
|
}: {
|
|
19
|
-
maxLength
|
|
20
|
-
|
|
21
|
-
})
|
|
20
|
+
maxLength?: number;
|
|
21
|
+
contentLength: number;
|
|
22
|
+
}) => {
|
|
23
|
+
if (!maxLength) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
// Only show if contentLength reaches 80% of maxLength
|
|
29
|
+
contentLength >= 0.8 * maxLength && (
|
|
30
|
+
<div className="gc-editor-max-length">
|
|
31
|
+
{contentLength >= maxLength ? maxLength : contentLength}/{maxLength}
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function MaxLengthPlugin({ maxLength }: { maxLength: number }): JSX.Element {
|
|
22
38
|
const [editor] = useLexicalComposerContext();
|
|
39
|
+
const [contentLength, setContentLength] = useState(0);
|
|
23
40
|
|
|
24
41
|
useEffect(() => {
|
|
25
42
|
let lastRestoredEditorState: EditorState | null = null;
|
|
@@ -52,5 +69,5 @@ export function MaxLengthPlugin({
|
|
|
52
69
|
});
|
|
53
70
|
}, [editor, maxLength, setContentLength]);
|
|
54
71
|
|
|
55
|
-
return
|
|
72
|
+
return <MaxLengthIndicator contentLength={contentLength} maxLength={maxLength} />;
|
|
56
73
|
}
|