Skip to content

Commit 351dd2a

Browse files
committed
fix: file upload and move status bar count enum to advance
1 parent a1231fd commit 351dd2a

File tree

7 files changed

+53
-79
lines changed

7 files changed

+53
-79
lines changed

packages/pluggableWidgets/rich-text-web/src/RichText.xml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@
2121
<caption>Enable status bar</caption>
2222
<description />
2323
</property>
24-
<property key="statusBarContent" type="enumeration" defaultValue="wordCount">
25-
<caption>Status bar content</caption>
26-
<description>Choose what to display in the status bar</description>
27-
<enumerationValues>
28-
<enumerationValue key="wordCount">Word count</enumerationValue>
29-
<enumerationValue key="characterCount">Character count (text only)</enumerationValue>
30-
<enumerationValue key="characterCountHtml">Character count (including HTML)</enumerationValue>
31-
<enumerationValue key="both">Both word and character count</enumerationValue>
32-
</enumerationValues>
33-
</property>
3424
</propertyGroup>
3525
<propertyGroup caption="Toolbar">
3626
<property key="preset" type="enumeration" defaultValue="basic">
@@ -209,6 +199,15 @@
209199
<caption>Enable default upload</caption>
210200
<description />
211201
</property>
202+
<property key="statusBarContent" type="enumeration" defaultValue="wordCount">
203+
<caption>Status bar content</caption>
204+
<description>Choose what to display in the status bar</description>
205+
<enumerationValues>
206+
<enumerationValue key="wordCount">Word count</enumerationValue>
207+
<enumerationValue key="characterCount">Character count (text only)</enumerationValue>
208+
<enumerationValue key="characterCountHtml">Character count (including HTML)</enumerationValue>
209+
</enumerationValues>
210+
</property>
212211
</propertyGroup>
213212
</propertyGroup>
214213
<propertyGroup caption="Custom toolbar">

packages/pluggableWidgets/rich-text-web/src/components/CustomToolbars/useEmbedModal.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ type ModalReturnType = {
2626

2727
export function useEmbedModal(
2828
ref: MutableRefObject<Quill | null>,
29-
props: Pick<
30-
RichTextContainerProps,
31-
"imageSource" | "imageSourceContent" | "enableDefaultUpload" | "formOrientation"
32-
>
29+
props: Pick<RichTextContainerProps, "formOrientation">
3330
): ModalReturnType {
3431
const [showDialog, setShowDialog] = useState<boolean>(false);
3532
const [dialogConfig, setDialogConfig] = useState<ChildDialogProps>({});
@@ -197,10 +194,7 @@ export function useEmbedModal(
197194
},
198195
onClose: closeDialog,
199196
defaultValue: { ...value },
200-
formOrientation: props.formOrientation,
201-
imageSource: props.imageSource,
202-
imageSourceContent: props.imageSourceContent,
203-
enableDefaultUpload: props.enableDefaultUpload
197+
formOrientation: props.formOrientation
204198
}
205199
});
206200
openDialog();

packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
214214
isOpen={showDialog}
215215
onOpenChange={open => setShowDialog(open)}
216216
parentNode={modalRef.current?.ownerDocument.body}
217+
imageSource={props.imageSource}
218+
imageSourceContent={props.imageSourceContent}
219+
enableDefaultUpload={props.enableDefaultUpload}
217220
{...dialogConfig}
218221
></Dialog>
219222
</Fragment>

packages/pluggableWidgets/rich-text-web/src/components/EditorWrapper.tsx

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
6565
const editorValueRef = useRef<string>("");
6666
const toolbarRef = useRef<HTMLDivElement>(null);
6767
const [wordCount, setWordCount] = useState(0);
68-
const [characterCount, setCharacterCount] = useState(0);
69-
const [characterCountHtml, setCharacterCountHtml] = useState(0);
7068

7169
const { isFullscreen } = globalState;
7270

@@ -83,45 +81,24 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
8381
[stringAttribute, onChange, onChangeType]
8482
);
8583

86-
const calculateWordCount = useCallback(
84+
const calculateCounts = useCallback(
8785
(quill: Quill | null): void => {
8886
if (enableStatusBar) {
89-
const text = quill?.getText().trim();
90-
setWordCount(text && text.length > 0 ? text.split(/\s+/).length : 0);
91-
}
92-
},
93-
[enableStatusBar]
94-
);
95-
96-
const calculateCharacterCount = useCallback(
97-
(quill: Quill | null): void => {
98-
if (enableStatusBar && (statusBarContent === "characterCount" || statusBarContent === "both")) {
99-
const text = quill?.getText() || "";
100-
setCharacterCount(text.length);
101-
}
102-
},
103-
[enableStatusBar, statusBarContent]
104-
);
105-
106-
const calculateCharacterCountHtml = useCallback(
107-
(quill: Quill | null): void => {
108-
if (enableStatusBar && (statusBarContent === "characterCountHtml" || statusBarContent === "both")) {
109-
const html = quill?.getSemanticHTML() || "";
110-
setCharacterCountHtml(html.length);
87+
if (statusBarContent === "wordCount") {
88+
const text = quill?.getText().trim();
89+
setWordCount(text && text.length > 0 ? text.split(/\s+/).length : 0);
90+
} else if (statusBarContent === "characterCount") {
91+
const text = quill?.getText() || "";
92+
setWordCount(text.length);
93+
} else if (statusBarContent === "characterCountHtml") {
94+
const html = quill?.getSemanticHTML() || "";
95+
setWordCount(html.length);
96+
}
11197
}
11298
},
11399
[enableStatusBar, statusBarContent]
114100
);
115101

116-
const calculateCounts = useCallback(
117-
(quill: Quill | null): void => {
118-
calculateWordCount(quill);
119-
calculateCharacterCount(quill);
120-
calculateCharacterCountHtml(quill);
121-
},
122-
[calculateWordCount, calculateCharacterCount, calculateCharacterCountHtml]
123-
);
124-
125102
useEffect(() => {
126103
if (quillRef.current) {
127104
calculateCounts(quillRef.current);
@@ -207,7 +184,9 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
207184
spellCheck={props.spellCheck}
208185
tabIndex={tabIndex}
209186
>
210-
{toolbarLocation === "auto" && <StickySentinel />}
187+
<If condition={toolbarLocation === "auto"}>
188+
<StickySentinel />
189+
</If>
211190
<div
212191
className={classNames(
213192
"flexcontainer",
@@ -252,24 +231,15 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
252231
formOrientation={formOrientation}
253232
/>
254233
</div>
255-
{enableStatusBar && (
234+
<If condition={enableStatusBar}>
256235
<div className="widget-rich-text-footer" tabIndex={-1}>
257-
{statusBarContent === "wordCount" && (
258-
<span>{wordCount} word{wordCount === 1 ? "" : "s"}</span>
259-
)}
260-
{statusBarContent === "characterCount" && (
261-
<span>{characterCount} character{characterCount === 1 ? "" : "s"}</span>
262-
)}
263-
{statusBarContent === "characterCountHtml" && (
264-
<span>{characterCountHtml} character{characterCountHtml === 1 ? "" : "s"} (with HTML)</span>
265-
)}
266-
{statusBarContent === "both" && (
267-
<span>
268-
{wordCount} word{wordCount === 1 ? "" : "s"}{characterCount} character{characterCount === 1 ? "" : "s"}
269-
</span>
270-
)}
236+
<span>
237+
<span>{wordCount}</span>
238+
<span>{` ${statusBarContent === "wordCount" ? "word" : "character"}`}</span>
239+
<span>{wordCount === 1 ? "" : "s"}</span>
240+
</span>
271241
</div>
272-
)}
242+
</If>
273243
</div>
274244
);
275245
}

packages/pluggableWidgets/rich-text-web/src/components/ModalDialog/Dialog.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import VideoDialog, { VideoDialogProps } from "./VideoDialog";
1616
import ViewCodeDialog, { ViewCodeDialogProps } from "./ViewCodeDialog";
1717
import ImageDialog, { ImageDialogProps } from "./ImageDialog";
1818
import "./Dialog.scss";
19+
import { RichTextContainerProps } from "../../../typings/RichTextProps";
1920

2021
interface BaseDialogProps {
2122
isOpen: boolean;
@@ -49,13 +50,15 @@ export type ChildDialogProps =
4950
| ViewCodeDialogBaseProps
5051
| ImageDialogBaseProps;
5152

52-
export type DialogProps = BaseDialogProps & ChildDialogProps;
53+
export type DialogProps = BaseDialogProps &
54+
ChildDialogProps &
55+
Pick<RichTextContainerProps, "imageSource" | "imageSourceContent" | "enableDefaultUpload">;
5356

5457
/**
5558
* Dialog components that will be shown on toolbar's button
5659
*/
5760
export default function Dialog(props: DialogProps): ReactElement {
58-
const { isOpen, onOpenChange, dialogType, config } = props;
61+
const { isOpen, onOpenChange, dialogType, config, imageSource, imageSourceContent, enableDefaultUpload } = props;
5962
const { refs, context } = useFloating({
6063
open: isOpen,
6164
onOpenChange
@@ -97,7 +100,12 @@ export default function Dialog(props: DialogProps): ReactElement {
97100
<ViewCodeDialog {...(config as ViewCodeDialogProps)}></ViewCodeDialog>
98101
</If>
99102
<If condition={dialogType === "image"}>
100-
<ImageDialog {...(config as ImageDialogProps)}></ImageDialog>
103+
<ImageDialog
104+
imageSource={imageSource}
105+
imageSourceContent={imageSourceContent}
106+
enableDefaultUpload={enableDefaultUpload}
107+
{...(config as ImageDialogProps)}
108+
></ImageDialog>
101109
</If>
102110
</div>
103111
</FloatingFocusManager>

packages/pluggableWidgets/rich-text-web/src/components/ModalDialog/ImageDialog.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ interface CustomEvent<T = any> extends Event {
2121
}
2222

2323
export interface ImageDialogProps
24-
extends Pick<
25-
RichTextContainerProps,
26-
"imageSource" | "imageSourceContent" | "enableDefaultUpload" | "formOrientation"
27-
> {
24+
extends Pick<RichTextContainerProps, "imageSource" | "imageSourceContent" | "formOrientation"> {
2825
onSubmit(value: imageConfigType): void;
2926
onClose(): void;
3027
defaultValue?: imageConfigType;
28+
enableDefaultUpload?: boolean;
3129
}
3230

3331
export default function ImageDialog(props: ImageDialogProps): ReactElement {

packages/pluggableWidgets/rich-text-web/typings/RichTextProps.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type ToolbarLocationEnum = "auto" | "top" | "bottom" | "hide";
1212

1313
export type ReadOnlyStyleEnum = "text" | "bordered" | "readPanel";
1414

15-
export type StatusBarContentEnum = "wordCount" | "characterCount" | "characterCountHtml" | "both";
15+
export type FormOrientationEnum = "horizontal" | "vertical";
1616

1717
export type WidthUnitEnum = "pixels" | "percentage";
1818

@@ -31,6 +31,8 @@ export interface CustomFontsType {
3131
fontStyle: string;
3232
}
3333

34+
export type StatusBarContentEnum = "wordCount" | "characterCount" | "characterCountHtml";
35+
3436
export type ToolbarConfigEnum = "basic" | "advanced";
3537

3638
export type CtItemTypeEnum = "separator" | "undo" | "redo" | "bold" | "italic" | "underline" | "strike" | "superScript" | "subScript" | "orderedList" | "bulletList" | "lowerAlphaList" | "checkList" | "minIndent" | "plusIndent" | "direction" | "link" | "image" | "video" | "formula" | "blockquote" | "code" | "codeBlock" | "viewCode" | "align" | "centerAlign" | "rightAlign" | "font" | "size" | "color" | "background" | "header" | "fullscreen" | "clean" | "tableBetter";
@@ -54,7 +56,6 @@ export interface RichTextContainerProps {
5456
id: string;
5557
stringAttribute: EditableValue<string>;
5658
enableStatusBar: boolean;
57-
statusBarContent: StatusBarContentEnum;
5859
preset: PresetEnum;
5960
toolbarLocation: ToolbarLocationEnum;
6061
readOnlyStyle: ReadOnlyStyleEnum;
@@ -78,6 +79,7 @@ export interface RichTextContainerProps {
7879
imageSource?: ListValue;
7980
imageSourceContent?: ReactNode;
8081
enableDefaultUpload: boolean;
82+
statusBarContent: StatusBarContentEnum;
8183
toolbarConfig: ToolbarConfigEnum;
8284
history: boolean;
8385
fontStyle: boolean;
@@ -101,7 +103,6 @@ export interface RichTextPreviewProps {
101103
translate: (text: string) => string;
102104
stringAttribute: string;
103105
enableStatusBar: boolean;
104-
statusBarContent: StatusBarContentEnum;
105106
preset: PresetEnum;
106107
toolbarLocation: ToolbarLocationEnum;
107108
readOnlyStyle: ReadOnlyStyleEnum;
@@ -125,6 +126,7 @@ export interface RichTextPreviewProps {
125126
imageSource: {} | { caption: string } | { type: string } | null;
126127
imageSourceContent: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
127128
enableDefaultUpload: boolean;
129+
statusBarContent: StatusBarContentEnum;
128130
toolbarConfig: ToolbarConfigEnum;
129131
history: boolean;
130132
fontStyle: boolean;

0 commit comments

Comments
 (0)