From c0a8ff0c2bc292aa591a7a4d0c3389cab720f1b5 Mon Sep 17 00:00:00 2001 From: linyz5 Date: Fri, 17 Jan 2025 15:13:26 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B5=8B=E8=AF=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/H2/h2.tsx | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/mini-markdown-material/src/components/H2/h2.tsx diff --git a/packages/mini-markdown-material/src/components/H2/h2.tsx b/packages/mini-markdown-material/src/components/H2/h2.tsx new file mode 100644 index 0000000..3cfccc6 --- /dev/null +++ b/packages/mini-markdown-material/src/components/H2/h2.tsx @@ -0,0 +1,36 @@ +import { FC } from 'react' +import styled from 'styled-components' + +const HeadingStyle = styled.h1` + font-size: 1.5em; + text-align: center; + color: palevioletred; +`; + +const Heading: FC<{ + level: number, + children: React.ReactNode +}> = ({ level, children }) => { + switch (level) { + case 1: + return +

# {children}

+
+ case 2: + return

## {children}

+ case 3: + return

### {children}

+ case 4: + return

#### {children}

+ case 5: + return
##### {children}
+ case 6: + return
###### {children}
+ default: + return <> + } +} + +export { + Heading +} -- Gitee From ea0348529c2ce7b11cf640927ea6debaaa2574c2 Mon Sep 17 00:00:00 2001 From: linyz5 Date: Fri, 17 Jan 2025 15:13:26 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B5=8B=E8=AF=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/H2/h2.tsx | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/mini-markdown-material/src/components/H2/h2.tsx diff --git a/packages/mini-markdown-material/src/components/H2/h2.tsx b/packages/mini-markdown-material/src/components/H2/h2.tsx new file mode 100644 index 0000000..3cfccc6 --- /dev/null +++ b/packages/mini-markdown-material/src/components/H2/h2.tsx @@ -0,0 +1,36 @@ +import { FC } from 'react' +import styled from 'styled-components' + +const HeadingStyle = styled.h1` + font-size: 1.5em; + text-align: center; + color: palevioletred; +`; + +const Heading: FC<{ + level: number, + children: React.ReactNode +}> = ({ level, children }) => { + switch (level) { + case 1: + return +

# {children}

+
+ case 2: + return

## {children}

+ case 3: + return

### {children}

+ case 4: + return

#### {children}

+ case 5: + return
##### {children}
+ case 6: + return
###### {children}
+ default: + return <> + } +} + +export { + Heading +} -- Gitee From fd32f568d75957985049a524a572d37a4cd2d399 Mon Sep 17 00:00:00 2001 From: linyz5 Date: Fri, 17 Jan 2025 16:02:04 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/H2/h2.tsx | 36 ------------------- .../src/components/H2/h3.tsx | 0 2 files changed, 36 deletions(-) delete mode 100644 packages/mini-markdown-material/src/components/H2/h2.tsx create mode 100644 packages/mini-markdown-material/src/components/H2/h3.tsx diff --git a/packages/mini-markdown-material/src/components/H2/h2.tsx b/packages/mini-markdown-material/src/components/H2/h2.tsx deleted file mode 100644 index 3cfccc6..0000000 --- a/packages/mini-markdown-material/src/components/H2/h2.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { FC } from 'react' -import styled from 'styled-components' - -const HeadingStyle = styled.h1` - font-size: 1.5em; - text-align: center; - color: palevioletred; -`; - -const Heading: FC<{ - level: number, - children: React.ReactNode -}> = ({ level, children }) => { - switch (level) { - case 1: - return -

# {children}

-
- case 2: - return

## {children}

- case 3: - return

### {children}

- case 4: - return

#### {children}

- case 5: - return
##### {children}
- case 6: - return
###### {children}
- default: - return <> - } -} - -export { - Heading -} diff --git a/packages/mini-markdown-material/src/components/H2/h3.tsx b/packages/mini-markdown-material/src/components/H2/h3.tsx new file mode 100644 index 0000000..e69de29 -- Gitee From a7ee83d8a6834e256ed9e67491395901034cd7ae Mon Sep 17 00:00:00 2001 From: xiaotianna <127941140+xiaotianna@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:08:47 +0800 Subject: [PATCH 4/6] test(mini-markdown-play): new mini-markdown-play project demo --- packages/mini-markdown-material/src/App.css | 42 ----------- .../src/assets/react.svg | 1 - .../src/components/Heading/index.tsx | 64 +++++++++------- packages/mini-markdown-material/src/index.css | 68 ----------------- packages/mini-markdown-material/src/main.tsx | 8 +- .../src/style/LineWrap.tsx | 9 +++ .../mini-markdown-material/tsconfig.app.json | 9 ++- .../mini-markdown-material/vite.config.ts | 7 +- packages/mini-markdown-play/src/App.css | 42 ----------- packages/mini-markdown-play/src/App.tsx | 73 ++++++++++++++----- packages/mini-markdown-play/src/index.css | 68 ----------------- packages/mini-markdown-play/src/main.tsx | 9 +-- packages/mini-markdown-play/src/reset.css | 5 ++ packages/mini-markdown-play/tsconfig.app.json | 2 +- packages/mini-markdown-play/vite.config.ts | 8 +- 15 files changed, 130 insertions(+), 285 deletions(-) delete mode 100644 packages/mini-markdown-material/src/App.css delete mode 100644 packages/mini-markdown-material/src/assets/react.svg delete mode 100644 packages/mini-markdown-material/src/index.css create mode 100644 packages/mini-markdown-material/src/style/LineWrap.tsx delete mode 100644 packages/mini-markdown-play/src/App.css delete mode 100644 packages/mini-markdown-play/src/index.css create mode 100644 packages/mini-markdown-play/src/reset.css diff --git a/packages/mini-markdown-material/src/App.css b/packages/mini-markdown-material/src/App.css deleted file mode 100644 index b9d355d..0000000 --- a/packages/mini-markdown-material/src/App.css +++ /dev/null @@ -1,42 +0,0 @@ -#root { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/packages/mini-markdown-material/src/assets/react.svg b/packages/mini-markdown-material/src/assets/react.svg deleted file mode 100644 index 6c87de9..0000000 --- a/packages/mini-markdown-material/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/packages/mini-markdown-material/src/components/Heading/index.tsx b/packages/mini-markdown-material/src/components/Heading/index.tsx index 3cfccc6..d45eb12 100644 --- a/packages/mini-markdown-material/src/components/Heading/index.tsx +++ b/packages/mini-markdown-material/src/components/Heading/index.tsx @@ -1,36 +1,48 @@ import { FC } from 'react' import styled from 'styled-components' +import { LineWrap } from '../../style/LineWrap' -const HeadingStyle = styled.h1` - font-size: 1.5em; - text-align: center; - color: palevioletred; -`; +/** + * '#' 这个字符,以及后面内容的样式(span包裹) + */ +const HeadingStyle = styled.span` + color: #3f4a54; + font-weight: bold; + .heading-tag { + color: #0000ff; + } +` const Heading: FC<{ - level: number, + level: number children: React.ReactNode }> = ({ level, children }) => { - switch (level) { - case 1: - return -

# {children}

+ // switch (level) { + // case 1: + // return + //

# {children}

+ //
+ // case 2: + // return

## {children}

+ // case 3: + // return

### {children}

+ // case 4: + // return

#### {children}

+ // case 5: + // return
##### {children}
+ // case 6: + // return
###### {children}
+ // default: + // return <> + // } + return ( + + + {'#'.repeat(level)} - case 2: - return

## {children}

- case 3: - return

### {children}

- case 4: - return

#### {children}

- case 5: - return
##### {children}
- case 6: - return
###### {children}
- default: - return <> - } + {children} +
+ ) } -export { - Heading -} +export { Heading } diff --git a/packages/mini-markdown-material/src/index.css b/packages/mini-markdown-material/src/index.css deleted file mode 100644 index 6119ad9..0000000 --- a/packages/mini-markdown-material/src/index.css +++ /dev/null @@ -1,68 +0,0 @@ -:root { - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); - background-color: #242424; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} -a:hover { - color: #535bf2; -} - -body { - margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; -} - -h1 { - font-size: 3.2em; - line-height: 1.1; -} - -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - background-color: #1a1a1a; - cursor: pointer; - transition: border-color 0.25s; -} -button:hover { - border-color: #646cff; -} -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} - -@media (prefers-color-scheme: light) { - :root { - color: #213547; - background-color: #ffffff; - } - a:hover { - color: #747bff; - } - button { - background-color: #f9f9f9; - } -} diff --git a/packages/mini-markdown-material/src/main.tsx b/packages/mini-markdown-material/src/main.tsx index bef5202..2a6ca91 100644 --- a/packages/mini-markdown-material/src/main.tsx +++ b/packages/mini-markdown-material/src/main.tsx @@ -1,10 +1,4 @@ -import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import './index.css' import App from './App.tsx' -createRoot(document.getElementById('root')!).render( - - - , -) +createRoot(document.getElementById('root')!).render() diff --git a/packages/mini-markdown-material/src/style/LineWrap.tsx b/packages/mini-markdown-material/src/style/LineWrap.tsx new file mode 100644 index 0000000..15a5a7e --- /dev/null +++ b/packages/mini-markdown-material/src/style/LineWrap.tsx @@ -0,0 +1,9 @@ +import styled from 'styled-components' + +/** + * 包裹容器,用于限制每一行内容 + */ +export const LineWrap = styled.div` + width: 100%; + height: 20px; +` \ No newline at end of file diff --git a/packages/mini-markdown-material/tsconfig.app.json b/packages/mini-markdown-material/tsconfig.app.json index 358ca9b..e6d3442 100644 --- a/packages/mini-markdown-material/tsconfig.app.json +++ b/packages/mini-markdown-material/tsconfig.app.json @@ -20,7 +20,14 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true + "noUncheckedSideEffectImports": true, + + /* alias */ + "baseUrl": "src", + "paths": { + "@/*": ["./*"], + "@": ["./"] + } }, "include": ["src"] } diff --git a/packages/mini-markdown-material/vite.config.ts b/packages/mini-markdown-material/vite.config.ts index 8b0f57b..5048e18 100644 --- a/packages/mini-markdown-material/vite.config.ts +++ b/packages/mini-markdown-material/vite.config.ts @@ -1,7 +1,12 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +// import { fileURLToPath, URL } from 'node:url' -// https://vite.dev/config/ export default defineConfig({ plugins: [react()], + resolve: { + alias: { + // '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } }) diff --git a/packages/mini-markdown-play/src/App.css b/packages/mini-markdown-play/src/App.css deleted file mode 100644 index b9d355d..0000000 --- a/packages/mini-markdown-play/src/App.css +++ /dev/null @@ -1,42 +0,0 @@ -#root { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/packages/mini-markdown-play/src/App.tsx b/packages/mini-markdown-play/src/App.tsx index ab772b9..e07f092 100644 --- a/packages/mini-markdown-play/src/App.tsx +++ b/packages/mini-markdown-play/src/App.tsx @@ -1,26 +1,59 @@ -import reactLogo from './assets/react.svg' -import viteLogo from '/vite.svg' -import './App.css' -import { Heading } from '@mini-markdown/material/src/components/Heading/index.tsx' +import { Heading } from '@mini-markdown/material/src/components/Heading/index.tsx'; +import { useRef } from 'react'; +import ReactDOMServer from 'react-dom/server'; function App() { + const editRef = useRef(null); + const handleClick = () => { + if (document.activeElement != editRef.current) { + editRef.current!.focus() + } + const headingHtml = ReactDOMServer.renderToStaticMarkup(hello); + document.execCommand('insertHTML', false, headingHtml); + }; + + const handleInput = (e: React.FormEvent) => { + console.log('input event', e); + // const selection = getSelection(); + // if (selection && selection.rangeCount > 0) + // const range = selection.getRangeAt(0); + // console.log('Current cursor position:', range); + // } + }; + return ( - <> -
- - Vite logo - - - React logo - +
+
+ +
+
+ hello
- - hello - - - ) +
+ ); } - - -export default App +export default App; \ No newline at end of file diff --git a/packages/mini-markdown-play/src/index.css b/packages/mini-markdown-play/src/index.css deleted file mode 100644 index 6119ad9..0000000 --- a/packages/mini-markdown-play/src/index.css +++ /dev/null @@ -1,68 +0,0 @@ -:root { - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); - background-color: #242424; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} -a:hover { - color: #535bf2; -} - -body { - margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; -} - -h1 { - font-size: 3.2em; - line-height: 1.1; -} - -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - background-color: #1a1a1a; - cursor: pointer; - transition: border-color 0.25s; -} -button:hover { - border-color: #646cff; -} -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} - -@media (prefers-color-scheme: light) { - :root { - color: #213547; - background-color: #ffffff; - } - a:hover { - color: #747bff; - } - button { - background-color: #f9f9f9; - } -} diff --git a/packages/mini-markdown-play/src/main.tsx b/packages/mini-markdown-play/src/main.tsx index bef5202..b0b4176 100644 --- a/packages/mini-markdown-play/src/main.tsx +++ b/packages/mini-markdown-play/src/main.tsx @@ -1,10 +1,5 @@ -import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import './index.css' import App from './App.tsx' +import './reset.css' -createRoot(document.getElementById('root')!).render( - - - , -) +createRoot(document.getElementById('root')!).render() diff --git a/packages/mini-markdown-play/src/reset.css b/packages/mini-markdown-play/src/reset.css new file mode 100644 index 0000000..5b2d803 --- /dev/null +++ b/packages/mini-markdown-play/src/reset.css @@ -0,0 +1,5 @@ +* { + margin: 0; + padding: 0; + list-style: none; +} \ No newline at end of file diff --git a/packages/mini-markdown-play/tsconfig.app.json b/packages/mini-markdown-play/tsconfig.app.json index 358ca9b..cfb6964 100644 --- a/packages/mini-markdown-play/tsconfig.app.json +++ b/packages/mini-markdown-play/tsconfig.app.json @@ -20,7 +20,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, - "noUncheckedSideEffectImports": true + "noUncheckedSideEffectImports": true, }, "include": ["src"] } diff --git a/packages/mini-markdown-play/vite.config.ts b/packages/mini-markdown-play/vite.config.ts index 8b0f57b..cbe9972 100644 --- a/packages/mini-markdown-play/vite.config.ts +++ b/packages/mini-markdown-play/vite.config.ts @@ -1,7 +1,13 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { fileURLToPath, URL } from 'node:url' +console.log(fileURLToPath(new URL('./src', import.meta.url))); -// https://vite.dev/config/ export default defineConfig({ plugins: [react()], + resolve: { + // alias: { + // '@src': fileURLToPath(new URL('./src', import.meta.url)) + // } + } }) -- Gitee From 1456f5cf6b242a5dc1d117f8bfba2f33d2981839 Mon Sep 17 00:00:00 2001 From: xiaotianna <127941140+xiaotianna@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:09:41 +0800 Subject: [PATCH 5/6] refactor(mini-markdown-material): delete non-standard code --- packages/mini-markdown-material/src/components/H2/h3.tsx | 1 - 1 file changed, 1 deletion(-) delete mode 100644 packages/mini-markdown-material/src/components/H2/h3.tsx diff --git a/packages/mini-markdown-material/src/components/H2/h3.tsx b/packages/mini-markdown-material/src/components/H2/h3.tsx deleted file mode 100644 index 957e0e6..0000000 --- a/packages/mini-markdown-material/src/components/H2/h3.tsx +++ /dev/null @@ -1 +0,0 @@ -6666 \ No newline at end of file -- Gitee From 278bb9a65624627eefa79dc7fef751f57aa73e67 Mon Sep 17 00:00:00 2001 From: linyz5 Date: Fri, 17 Jan 2025 17:16:35 +0800 Subject: [PATCH 6/6] fix(mini-markdown-material): delete test h2.tsx --- .../src/components/H2/h2.tsx | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 packages/mini-markdown-material/src/components/H2/h2.tsx diff --git a/packages/mini-markdown-material/src/components/H2/h2.tsx b/packages/mini-markdown-material/src/components/H2/h2.tsx deleted file mode 100644 index 3cfccc6..0000000 --- a/packages/mini-markdown-material/src/components/H2/h2.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { FC } from 'react' -import styled from 'styled-components' - -const HeadingStyle = styled.h1` - font-size: 1.5em; - text-align: center; - color: palevioletred; -`; - -const Heading: FC<{ - level: number, - children: React.ReactNode -}> = ({ level, children }) => { - switch (level) { - case 1: - return -

# {children}

-
- case 2: - return

## {children}

- case 3: - return

### {children}

- case 4: - return

#### {children}

- case 5: - return
##### {children}
- case 6: - return
###### {children}
- default: - return <> - } -} - -export { - Heading -} -- Gitee