diff --git a/README.md b/README.md index be7f62bd..416fa97d 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,6 @@ Copyright © 2015 - 2024 [Tyler Liu](https://github.com/tylerlong) - Release a React library so that everyone can use it easily - a few lines of code to embed mdp to their own app - Download as pdf/png/html/html code -- modals should go to separate files in src/components/modals folder - Add explict typings to most code - Make it support node.js, means it could run without browser - Close most GitHub issues diff --git a/src/components/modals/index.tsx b/src/components/modals/index.tsx index d3ed7c18..31d877a6 100644 --- a/src/components/modals/index.tsx +++ b/src/components/modals/index.tsx @@ -1,230 +1,19 @@ -import { Button, Input, InputRef, Modal } from 'antd'; import { auto } from 'manate/react'; -import React, { useRef, useState } from 'react'; +import React from 'react'; -import iconUrl from '../../icon.svg'; import { Store } from '../../store'; import PreferencesModal from './preferences'; +import PromptModals from './prompt'; +import StaticModals from './static'; const Modals = auto((props: { store: Store }) => { console.log('render modals'); const { store } = props; - const { modals } = store; - const emojiInput = useRef(null); - const faInput = useRef(null); - const [emojiValue, setEmojiValue] = useState(''); - const [faValue, setFaValue] = useState(''); - const handleEmojiOK = () => { - modals.emoji.close(); - const value = emojiValue.trim(); - if (value.length > 0) { - store.editor.replaceSelection(`:${value}:`); - } - setEmojiValue(''); - }; - const handleFaOK = () => { - modals.fontAwesome.close(); - const value = faValue.trim(); - if (value.length > 0) { - store.editor.replaceSelection(`:fa-${value}:`); - } - setFaValue(''); - }; return ( <> - {/* emoji modal */} - modals.emoji.close()} - onOk={() => handleEmojiOK()} - maskClosable={true} - centered={true} - afterOpenChange={(open) => { - if (open) { - emojiInput.current?.focus(); - } - }} - > -
-

Please enter an emoji code:

-

- {`Examples: "smile", "whale", "santa", "panda_face", "dog", "truck" - ...`} -

-

- For a complete list, please check - - Emoji Cheat Sheet - - . -

-
- setEmojiValue(e.target.value)} - placeholder="smile" - onKeyUp={(e) => { - if (e.key === 'Enter') { - handleEmojiOK(); - } - }} - /> -
-
-
- - {/* font awesome modal */} - modals.fontAwesome.close()} - onOk={() => handleFaOK()} - maskClosable={true} - centered={true} - afterOpenChange={(open) => { - if (open) { - faInput.current?.focus(); - } - }} - > -
-

Please enter a Font Awesome code:

-

- {`Examples: "cloud", "flag", "car", "truck", "heart", "dollar" ...`} -

-

- For a complete list, please check - - Font Awesome Icons - - . -

-
- setFaValue(e.target.value)} - onKeyUp={(e) => { - if (e.key === 'Enter') { - handleFaOK(); - } - }} - /> -
-
-
- - - {/* help modal */} - - - - } - onCancel={() => modals.help.close()} - maskClosable={true} - centered={true} - > -
-

- -

-

Markdown Plus help

-

- - Online Sample - -

-

- - Markdown Basics - -

-

- - GitHub Flavored Markdown - -

-
-
- - {/* about modal */} - - - - } - onCancel={() => modals.about.close()} - maskClosable={true} - centered={true} - > -
-

- -

-

Markdown Plus

-

Version 3.x

-

Markdown editor with extra features

-

- Copyright © 2015 - 2024{' '} - - Tyler Liu - -

-

- Home page:{' '} - - Home page - -

-
-
+ + ); }); diff --git a/src/components/modals/prompt.tsx b/src/components/modals/prompt.tsx new file mode 100644 index 00000000..3bd2aee9 --- /dev/null +++ b/src/components/modals/prompt.tsx @@ -0,0 +1,127 @@ +import { Input, InputRef, Modal } from 'antd'; +import { auto } from 'manate/react'; +import React, { useRef, useState } from 'react'; + +import { Store } from '../../store'; + +const promptModals = auto((props: { store: Store }) => { + console.log('render prompt modals'); + const { store } = props; + const { modals } = store; + const emojiInput = useRef(null); + const faInput = useRef(null); + const [emojiValue, setEmojiValue] = useState(''); + const [faValue, setFaValue] = useState(''); + const handleEmojiOK = () => { + modals.emoji.close(); + const value = emojiValue.trim(); + if (value.length > 0) { + store.editor.replaceSelection(`:${value}:`); + } + setEmojiValue(''); + }; + const handleFaOK = () => { + modals.fontAwesome.close(); + const value = faValue.trim(); + if (value.length > 0) { + store.editor.replaceSelection(`:fa-${value}:`); + } + setFaValue(''); + }; + return ( + <> + {/* emoji modal */} + modals.emoji.close()} + onOk={() => handleEmojiOK()} + maskClosable={true} + centered={true} + afterOpenChange={(open) => { + if (open) { + emojiInput.current?.focus(); + } + }} + > +
+

Please enter an emoji code:

+

+ {`Examples: "smile", "whale", "santa", "panda_face", "dog", "truck" +...`} +

+

+ For a complete list, please check + + Emoji Cheat Sheet + + . +

+
+ setEmojiValue(e.target.value)} + placeholder="smile" + onKeyUp={(e) => { + if (e.key === 'Enter') { + handleEmojiOK(); + } + }} + /> +
+
+
+ + {/* font awesome modal */} + modals.fontAwesome.close()} + onOk={() => handleFaOK()} + maskClosable={true} + centered={true} + afterOpenChange={(open) => { + if (open) { + faInput.current?.focus(); + } + }} + > +
+

Please enter a Font Awesome code:

+

+ {`Examples: "cloud", "flag", "car", "truck", "heart", "dollar" ...`} +

+

+ For a complete list, please check + + Font Awesome Icons + + . +

+
+ setFaValue(e.target.value)} + onKeyUp={(e) => { + if (e.key === 'Enter') { + handleFaOK(); + } + }} + /> +
+
+
+ + ); +}); + +export default promptModals; diff --git a/src/components/modals/static.tsx b/src/components/modals/static.tsx new file mode 100644 index 00000000..e0891933 --- /dev/null +++ b/src/components/modals/static.tsx @@ -0,0 +1,116 @@ +import { Button, Modal } from 'antd'; +import { auto } from 'manate/react'; +import React from 'react'; + +import iconUrl from '../../icon.svg'; +import store from '../../store'; + +const StaticModals = auto((props: { modals: typeof store.modals }) => { + const { modals } = props; + return ( + <> + {/* help modal */} + + + + } + onCancel={() => modals.help.close()} + maskClosable={true} + centered={true} + > + + + + {/* about modal */} + + + + } + onCancel={() => modals.about.close()} + maskClosable={true} + centered={true} + > +
+

+ +

+

Markdown Plus

+

Version 3.x

+

Markdown editor with extra features

+

+ Copyright © 2015 - 2024{' '} + + Tyler Liu + +

+

+ Home page:{' '} + + Home page + +

+
+
+ + ); +}); + +export default StaticModals;