-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
646 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/pluggableWidgets/rich-text-web/src/components/CustomToolbars/useEmbedModal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import type Quill from "quill"; | ||
import { useState, MutableRefObject, Dispatch, SetStateAction } from "react"; | ||
import { type ChildDialogProps } from "../ModalDialog/Dialog"; | ||
import { type linkConfigType, type videoConfigType, type videoEmbedConfigType } from "../../utils/formats"; | ||
import { type VideoFormType } from "../ModalDialog/VideoDialog"; | ||
|
||
type ModalReturnType = { | ||
showDialog: boolean; | ||
setShowDialog: Dispatch<SetStateAction<boolean>>; | ||
dialogConfig: ChildDialogProps; | ||
customLinkHandler(value: any): void; | ||
customVideoHandler(value: any): void; | ||
}; | ||
|
||
export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnType { | ||
const [showDialog, setShowDialog] = useState<boolean>(false); | ||
const [dialogConfig, setDialogConfig] = useState<ChildDialogProps>({}); | ||
|
||
const customLinkHandler = (value: any): void => { | ||
if (value === true) { | ||
setDialogConfig({ | ||
dialogType: "link", | ||
config: { | ||
onSubmit: (value: linkConfigType) => { | ||
ref.current?.format("link", value); | ||
|
||
setShowDialog(false); | ||
}, | ||
onClose: () => setShowDialog(false) | ||
} | ||
}); | ||
setShowDialog(true); | ||
} else { | ||
ref.current?.format("link", false); | ||
setShowDialog(false); | ||
} | ||
}; | ||
|
||
const customVideoHandler = (value: any): void => { | ||
if (value === true) { | ||
console.log(""); | ||
setDialogConfig({ | ||
dialogType: "video", | ||
config: { | ||
onSubmit: (value: VideoFormType) => { | ||
// const currentValue = Object.hasOwn(value, "src") && (value as VideoFormTypeGeneral).src !== undefined ? value as VideoFormTypeGeneral : value as VideoFormTypeEmbed;; | ||
if (Object.hasOwn(value, "src") && (value as videoConfigType).src !== undefined) { | ||
const currentValue = value as videoConfigType; | ||
ref.current?.format("video", currentValue); | ||
} else { | ||
const currentValue = value as videoEmbedConfigType; | ||
const res = ref.current?.clipboard.convert({ | ||
html: currentValue.embedcode | ||
}); | ||
if (res) { | ||
ref.current?.updateContents(res); | ||
} | ||
} | ||
|
||
setShowDialog(false); | ||
}, | ||
onClose: () => setShowDialog(false) | ||
} | ||
}); | ||
setShowDialog(true); | ||
} else { | ||
ref.current?.format("link", false); | ||
setShowDialog(false); | ||
} | ||
}; | ||
|
||
return { | ||
showDialog, | ||
setShowDialog, | ||
dialogConfig, | ||
customLinkHandler, | ||
customVideoHandler | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/pluggableWidgets/rich-text-web/src/components/ModalDialog/Dialog.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.widget-rich-text-modal { | ||
position: relative; | ||
inset: 40px; | ||
background: rgb(255, 255, 255); | ||
overflow: auto; | ||
border-radius: 4px; | ||
outline: none; | ||
padding: 0; | ||
box-shadow: 0px 0px 0px 1px rgba(136, 143, 170, 0.1), 0px 30px 70px 0px rgba(26, 34, 64, 0.15), | ||
0px 10px 30px 0px rgba(0, 0, 0, 0.2); | ||
|
||
&-overlay { | ||
position: fixed; | ||
inset: 0px; | ||
background-color: var(--shadow-color); | ||
justify-content: center; | ||
align-items: center; | ||
display: flex; | ||
} | ||
|
||
&-body { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
|
||
& > * { | ||
padding: 0 20px; | ||
} | ||
} | ||
|
||
&-header { | ||
padding-top: 15px; | ||
padding-bottom: 14px; | ||
font-size: var(--font-size-large); | ||
} | ||
|
||
&-content { | ||
padding-top: 20px; | ||
padding-bottom: 20px; | ||
flex: 1; | ||
} | ||
|
||
&-footer { | ||
padding-top: 12px; | ||
padding-bottom: 14px; | ||
display: flex; | ||
justify-content: end; | ||
|
||
button.btn:not(:last-child) { | ||
margin-right: 20px; | ||
} | ||
} | ||
|
||
&-form { | ||
&:not(:first-child) { | ||
margin-top: 20px; | ||
} | ||
} | ||
|
||
&-input { | ||
display: flex; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/pluggableWidgets/rich-text-web/src/components/ModalDialog/Dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { If } from "@mendix/widget-plugin-component-kit/If"; | ||
import { createElement, ReactElement } from "react"; | ||
import Modal from "react-modal"; | ||
import "./Dialog.scss"; | ||
import LinkDialog, { LinkDialogProps } from "./LinkDialog"; | ||
import VideoDialog, { VideoDialogProps } from "./VideoDialog"; | ||
|
||
interface BaseDialogProps { | ||
isOpen: boolean; | ||
parentNode?: HTMLElement | null; | ||
onClose?(event: React.MouseEvent | React.KeyboardEvent): void; | ||
} | ||
|
||
export type LinkDialogBaseProps = { | ||
dialogType?: "link"; | ||
config?: LinkDialogProps; | ||
}; | ||
|
||
export type VideoDialogBaseProps = { | ||
dialogType?: "video"; | ||
config?: VideoDialogProps; | ||
}; | ||
|
||
export type ChildDialogProps = LinkDialogBaseProps | VideoDialogBaseProps; | ||
|
||
export type DialogProps = BaseDialogProps & ChildDialogProps; | ||
|
||
export default function Dialog(props: DialogProps): ReactElement { | ||
const { isOpen, onClose, dialogType, config } = props; | ||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
// parentSelector={() => parentNode ?? document.body} | ||
overlayClassName={"widget-rich-text-modal-overlay"} | ||
className={"widget-rich-text-modal modal-dialog"} | ||
// style={{ overlay: { position: "absolute" }, content: { width: "fit-content", padding: 0 } }} | ||
onRequestClose={onClose} | ||
appElement={document.body} | ||
portalClassName={`widget-rich-text-modal-container`} | ||
> | ||
<If condition={dialogType === "link"}> | ||
<LinkDialog {...(config as LinkDialogProps)}></LinkDialog> | ||
</If> | ||
<If condition={dialogType === "video"}> | ||
<VideoDialog {...(config as VideoDialogProps)}></VideoDialog> | ||
</If> | ||
</Modal> | ||
); | ||
} |
Oops, something went wrong.