Skip to content

Commit 589fed1

Browse files
committed
refactor: improve type safety, prop passing cleanup
1 parent 0ce75cb commit 589fed1

File tree

12 files changed

+48
-77
lines changed

12 files changed

+48
-77
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<enumerationValue key="readPanel">Read panel</enumerationValue>
5656
</enumerationValues>
5757
</property>
58-
<property key="formOrientation" type="enumeration" defaultValue="horizontal">
58+
<property key="formOrientation" type="enumeration" defaultValue="horizontal" required="true">
5959
<caption>Form orientation</caption>
6060
<description>The form orientation for modals (Insert link, Insert image, Insert video).</description>
6161
<enumerationValues>

packages/pluggableWidgets/rich-text-web/src/__tests__/RichText.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe("Rich Text", () => {
4545
minHeight: 75,
4646
OverflowY: "auto",
4747
customFonts: [],
48-
enableDefaultUpload: true
48+
enableDefaultUpload: true,
49+
formOrientation: "vertical"
4950
};
5051
});
5152

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { type VideoFormType } from "../ModalDialog/VideoDialog";
1212
import { Delta } from "quill/core";
1313
import { IMG_MIME_TYPES } from "./constants";
1414
import Emitter from "quill/core/emitter";
15+
import { RichTextContainerProps } from "typings/RichTextProps";
1516

1617
type ModalReturnType = {
1718
showDialog: boolean;
@@ -23,7 +24,13 @@ type ModalReturnType = {
2324
customImageUploadHandler(value: any): void;
2425
};
2526

26-
export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnType {
27+
export function useEmbedModal(
28+
ref: MutableRefObject<Quill | null>,
29+
props: Pick<
30+
RichTextContainerProps,
31+
"imageSource" | "imageSourceContent" | "enableDefaultUpload" | "formOrientation"
32+
>
33+
): ModalReturnType {
2734
const [showDialog, setShowDialog] = useState<boolean>(false);
2835
const [dialogConfig, setDialogConfig] = useState<ChildDialogProps>({});
2936
const openDialog = (): void => {
@@ -51,7 +58,8 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
5158
closeDialog();
5259
},
5360
onClose: closeDialog,
54-
defaultValue: { ...value, text }
61+
defaultValue: { ...value, text },
62+
formOrientation: props.formOrientation
5563
}
5664
});
5765
openDialog();
@@ -113,7 +121,8 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
113121
},
114122
onClose: closeDialog,
115123
selection: ref.current?.getSelection(),
116-
defaultValue: { ...value }
124+
defaultValue: { ...value },
125+
formOrientation: props.formOrientation
117126
}
118127
});
119128
openDialog();
@@ -136,7 +145,8 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
136145
}
137146
closeDialog();
138147
},
139-
onClose: closeDialog
148+
onClose: closeDialog,
149+
formOrientation: props.formOrientation
140150
}
141151
});
142152
openDialog();
@@ -186,7 +196,11 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
186196
closeDialog();
187197
},
188198
onClose: closeDialog,
189-
defaultValue: { ...value }
199+
defaultValue: { ...value },
200+
formOrientation: props.formOrientation,
201+
imageSource: props.imageSource,
202+
imageSourceContent: props.imageSourceContent,
203+
enableDefaultUpload: props.enableDefaultUpload
190204
}
191205
});
192206
openDialog();

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface EditorProps
3838
defaultValue?: string;
3939
onTextChange?: (...args: [delta: Delta, oldContent: Delta, source: EmitterSource]) => void;
4040
onSelectionChange?: (...args: [range: Range, oldRange: Range, source: EmitterSource]) => void;
41-
formOrientation?: "horizontal" | "vertical";
41+
formOrientation: "horizontal" | "vertical";
4242
theme: string;
4343
style?: CSSProperties;
4444
className?: string;
@@ -66,7 +66,7 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
6666
customVideoHandler,
6767
customViewCodeHandler,
6868
customImageUploadHandler
69-
} = useEmbedModal(ref);
69+
} = useEmbedModal(ref, props);
7070
const customIndentHandler = getIndentHandler(ref);
7171

7272
// quill instance is not changing, thus, the function reference has to stays.
@@ -214,10 +214,6 @@ 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}
220-
formOrientation={props.formOrientation}
221217
{...dialogConfig}
222218
></Dialog>
223219
</Fragment>

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,6 @@
144144
&-content {
145145
padding: 20px;
146146
flex: 1;
147-
148-
&.form-vertical {
149-
.form-group {
150-
flex-direction: column;
151-
152-
.col-sm-3,
153-
.col-sm-9,
154-
.col-sm-12 {
155-
max-width: 100%;
156-
padding-left: 0;
157-
padding-right: 0;
158-
}
159-
}
160-
}
161147
}
162148

163149
&-footer {

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

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ 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";
2019

2120
interface BaseDialogProps {
2221
isOpen: boolean;
@@ -50,26 +49,13 @@ export type ChildDialogProps =
5049
| ViewCodeDialogBaseProps
5150
| ImageDialogBaseProps;
5251

53-
export type DialogProps = BaseDialogProps &
54-
ChildDialogProps &
55-
Pick<RichTextContainerProps, "imageSource" | "imageSourceContent" | "enableDefaultUpload"> & {
56-
formOrientation?: "horizontal" | "vertical";
57-
};
52+
export type DialogProps = BaseDialogProps & ChildDialogProps;
5853

5954
/**
6055
* Dialog components that will be shown on toolbar's button
6156
*/
6257
export default function Dialog(props: DialogProps): ReactElement {
63-
const {
64-
isOpen,
65-
onOpenChange,
66-
dialogType,
67-
config,
68-
imageSource,
69-
imageSourceContent,
70-
enableDefaultUpload,
71-
formOrientation
72-
} = props;
58+
const { isOpen, onOpenChange, dialogType, config } = props;
7359
const { refs, context } = useFloating({
7460
open: isOpen,
7561
onOpenChange
@@ -93,38 +79,25 @@ export default function Dialog(props: DialogProps): ReactElement {
9379
></FloatingOverlay>
9480
<FloatingFocusManager context={context}>
9581
<div
96-
className={classNames(
97-
"Dialog mx-layoutgrid widget-rich-text",
98-
formOrientation === "vertical" ? "form-vertical" : ""
99-
)}
82+
className={classNames("Dialog mx-layoutgrid widget-rich-text", {
83+
"form-vertical": config?.formOrientation === "vertical"
84+
})}
10085
ref={refs.setFloating}
10186
aria-labelledby={dialogType}
10287
aria-describedby={dialogType}
10388
{...getFloatingProps()}
10489
>
10590
<If condition={dialogType === "link"}>
106-
<LinkDialog
107-
formOrientation={formOrientation}
108-
{...(config as LinkDialogProps)}
109-
></LinkDialog>
91+
<LinkDialog {...(config as LinkDialogProps)}></LinkDialog>
11092
</If>
11193
<If condition={dialogType === "video"}>
112-
<VideoDialog
113-
formOrientation={formOrientation}
114-
{...(config as VideoDialogProps)}
115-
></VideoDialog>
94+
<VideoDialog {...(config as VideoDialogProps)}></VideoDialog>
11695
</If>
11796
<If condition={dialogType === "view-code"}>
11897
<ViewCodeDialog {...(config as ViewCodeDialogProps)}></ViewCodeDialog>
11998
</If>
12099
<If condition={dialogType === "image"}>
121-
<ImageDialog
122-
imageSource={imageSource}
123-
imageSourceContent={imageSourceContent}
124-
enableDefaultUpload={enableDefaultUpload}
125-
formOrientation={formOrientation}
126-
{...(config as ImageDialogProps)}
127-
></ImageDialog>
100+
<ImageDialog {...(config as ImageDialogProps)}></ImageDialog>
128101
</If>
129102
</div>
130103
</FloatingFocusManager>

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function DialogHeader(props: DialogHeaderProps): ReactElement {
3737
}
3838

3939
export function DialogBody(
40-
props: PropsWithChildrenWithClass & { formOrientation?: "horizontal" | "vertical" }
40+
props: PropsWithChildrenWithClass & { formOrientation: "horizontal" | "vertical" }
4141
): ReactElement {
4242
const { children, className, formOrientation } = props;
4343

@@ -56,18 +56,16 @@ export function DialogBody(
5656

5757
export interface FormControlProps extends PropsWithChildrenWithClass {
5858
label?: string;
59-
formOrientation?: "horizontal" | "vertical";
59+
formOrientation: "horizontal" | "vertical";
6060
inputId?: string;
6161
}
6262

63-
export function FormControl(props: FormControlProps & { formOrientation?: "horizontal" | "vertical" }): ReactElement {
63+
export function FormControl(props: FormControlProps): ReactElement {
6464
const { children, className, label, formOrientation, inputId } = props;
6565

66-
console.log("Form orientation:", props.formOrientation);
67-
6866
return (
6967
<If condition={children !== undefined && children !== null}>
70-
<div className={classNames("form-group", formOrientation === "vertical" ? "no-columns" : "", className)}>
68+
<div className={classNames("form-group", { "no-columns": formOrientation === "vertical" }, className)}>
7169
{label && (
7270
<label
7371
htmlFor={inputId}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ interface CustomEvent<T = any> extends Event {
2020
initCustomEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T): void;
2121
}
2222

23-
export interface ImageDialogProps extends Pick<RichTextContainerProps, "imageSource" | "imageSourceContent"> {
23+
export interface ImageDialogProps
24+
extends Pick<
25+
RichTextContainerProps,
26+
"imageSource" | "imageSourceContent" | "enableDefaultUpload" | "formOrientation"
27+
> {
2428
onSubmit(value: imageConfigType): void;
2529
onClose(): void;
2630
defaultValue?: imageConfigType;
27-
enableDefaultUpload?: boolean;
28-
formOrientation?: "horizontal" | "vertical";
2931
}
3032

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface LinkDialogProps {
77
onSubmit(value: linkConfigType): void;
88
onClose(): void;
99
defaultValue?: linkConfigType;
10-
formOrientation?: "horizontal" | "vertical";
10+
formOrientation: "horizontal" | "vertical";
1111
}
1212

1313
export default function LinkDialog(props: LinkDialogProps): ReactElement {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface VideoDialogProps {
1313
onClose(): void;
1414
selection?: Range | null;
1515
defaultValue?: videoConfigType;
16-
formOrientation?: "horizontal" | "vertical";
16+
formOrientation: "horizontal" | "vertical";
1717
}
1818

1919
export function getValueType(value: VideoFormType): VideoFormType {

0 commit comments

Comments
 (0)