feat(project): scaffold Vue 3 + Vite markdown editor
Add initial project structure including: - .gitignore and VSCode settings - Vite configuration and package.json with Vue 3 dependencies - Basic HTML entry point and README update - Core source files: App.vue, main.js, style.css - Markdown editor component with plugin system and related types - Sample HelloWorld component, router, and Pinia store - Assets and SVG icons This commit establishes the foundation for the Vue 3 application.
This commit is contained in:
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
9
.kilocode/rules/rules.md
Normal file
9
.kilocode/rules/rules.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# rules.md
|
||||
|
||||
在构建这个LLM应用网页时,你需要基于VUE3开发。我需要前端只运行渲染和数据回传,后端负责llm api调用,inline suggustions实现和数据解析。
|
||||
|
||||
## 指导原则
|
||||
|
||||
- 不要擅自用npm或者yarn运行网页,你既看不到网页的内容,也无法阻止命令暂停
|
||||
- 应该保证代码效率,不多定义变量,不写冗余注释,把降低延迟放在第一位
|
||||
- 每次完成任务前都要反复检查代码,确保代码准确无误
|
||||
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["Vue.volar"]
|
||||
}
|
||||
@@ -1,2 +1,5 @@
|
||||
# llm-in-text
|
||||
# Vue 3 + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
|
||||
|
||||
13
index.html
Normal file
13
index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>llm-in-text</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
1751
package-lock.json
generated
Normal file
1751
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
Normal file
23
package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "llm-in-text",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.13.2",
|
||||
"pinia": "^2.3.1",
|
||||
"vue": "^3.5.24",
|
||||
"vue-router": "^4.6.4",
|
||||
"markdown-it": "^13.0.0",
|
||||
"prismjs": "^1.29.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"vite": "^7.2.4"
|
||||
}
|
||||
}
|
||||
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
17
src/App.vue
Normal file
17
src/App.vue
Normal file
@@ -0,0 +1,17 @@
|
||||
<script setup>
|
||||
import MarkdownEditor from './components/MarkdownEditor.vue'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const html = ref('')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="editor-container">
|
||||
<MarkdownEditor @update:html="html = $event" class="editor" />
|
||||
<div class="preview" v-html="html"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
</style>
|
||||
1
src/assets/vue.svg
Normal file
1
src/assets/vue.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
43
src/components/HelloWorld.vue
Normal file
43
src/components/HelloWorld.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps({
|
||||
msg: String,
|
||||
})
|
||||
|
||||
const count = ref(0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>{{ msg }}</h1>
|
||||
|
||||
<div class="card">
|
||||
<button type="button" @click="count++">count is {{ count }}</button>
|
||||
<p>
|
||||
Edit
|
||||
<code>components/HelloWorld.vue</code> to test HMR
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Check out
|
||||
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
|
||||
>create-vue</a
|
||||
>, the official Vue + Vite starter
|
||||
</p>
|
||||
<p>
|
||||
Learn more about IDE Support for Vue in the
|
||||
<a
|
||||
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
|
||||
target="_blank"
|
||||
>Vue Docs Scaling up Guide</a
|
||||
>.
|
||||
</p>
|
||||
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
||||
121
src/components/MarkdownEditor.vue
Normal file
121
src/components/MarkdownEditor.vue
Normal file
@@ -0,0 +1,121 @@
|
||||
<template>
|
||||
<!-- Textarea for markdown input -->
|
||||
<textarea
|
||||
v-model="markdown"
|
||||
@keydown="handleKeydown"
|
||||
placeholder="Enter markdown..."
|
||||
rows="10"
|
||||
style="width: 100%;"
|
||||
></textarea>
|
||||
|
||||
<!-- Plugin host (no UI) -->
|
||||
<PluginHost />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, onMounted } from 'vue'
|
||||
import { plugins } from '../plugins/index'
|
||||
import PluginHost from './PluginHost.vue'
|
||||
import markdownIt from 'markdown-it'
|
||||
import Prism from 'prismjs'
|
||||
// 按需加载常用语言
|
||||
import 'prismjs/components/prism-javascript'
|
||||
import 'prismjs/components/prism-python'
|
||||
import 'prismjs/components/prism-css'
|
||||
|
||||
/* ---------- 插件挂载点 ---------- */
|
||||
const pluginContext = {}
|
||||
onMounted(() => {
|
||||
plugins.forEach(p => {
|
||||
if (p.onSetup) p.onSetup(pluginContext)
|
||||
})
|
||||
})
|
||||
|
||||
/* ---------- markdown 解析 ---------- */
|
||||
const md = markdownIt({
|
||||
highlight: (code, lang) => {
|
||||
if (lang && Prism.languages[lang]) {
|
||||
return `<pre class="language-${lang}"><code>${Prism.highlight(
|
||||
code,
|
||||
Prism.languages[lang],
|
||||
lang
|
||||
)}</code></pre>`
|
||||
}
|
||||
return `<pre class="language-${lang}"><code>${md.utils.escapeHtml(
|
||||
code
|
||||
)}</code></pre>`
|
||||
}
|
||||
})
|
||||
|
||||
const markdown = ref('')
|
||||
|
||||
/* ---------- 解析后钩子 & emit ---------- */
|
||||
watch(
|
||||
markdown,
|
||||
(newVal) => {
|
||||
let html = md.render(newVal)
|
||||
|
||||
// onAfterParse 插件
|
||||
const afterPayload = { markdown: newVal, html }
|
||||
plugins.forEach(p => {
|
||||
if (p.onAfterParse) {
|
||||
const res = p.onAfterParse(afterPayload)
|
||||
if (res && res.html) afterPayload.html = res.html
|
||||
}
|
||||
})
|
||||
|
||||
// onBeforeRender 插件
|
||||
const beforePayload = { html: afterPayload.html }
|
||||
plugins.forEach(p => {
|
||||
if (p.onBeforeRender) {
|
||||
const res = p.onBeforeRender(beforePayload)
|
||||
if (res && res.html) beforePayload.html = res.html
|
||||
}
|
||||
})
|
||||
|
||||
emit('update:html', beforePayload.html)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
/* ---------- 键盘快捷键 ---------- */
|
||||
function insertAtCursor(text) {
|
||||
const el = document.activeElement
|
||||
if (el && el.selectionStart !== undefined) {
|
||||
const start = el.selectionStart
|
||||
const end = el.selectionEnd
|
||||
const before = markdown.value.slice(0, start)
|
||||
const after = markdown.value.slice(end)
|
||||
markdown.value = `${before}${text}${after}`
|
||||
// 将光标放在插入文本后
|
||||
const pos = start + text.length
|
||||
nextTick(() => {
|
||||
el.setSelectionRange(pos, pos)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e) {
|
||||
if (e.ctrlKey && !e.shiftKey) {
|
||||
if (e.key === 'b' || e.key === 'B') {
|
||||
e.preventDefault()
|
||||
insertAtCursor('**粗体**')
|
||||
} else if (e.key === 'i' || e.key === 'I') {
|
||||
e.preventDefault()
|
||||
insertAtCursor('_斜体_')
|
||||
} else if (e.key === '`') {
|
||||
e.preventDefault()
|
||||
insertAtCursor('```\n代码块\n```')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
textarea {
|
||||
font-family: inherit;
|
||||
font-size: 1rem;
|
||||
padding: 0.5rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
23
src/components/PluginHost.vue
Normal file
23
src/components/PluginHost.vue
Normal file
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<!-- PluginHost does not render UI; it only runs plugin lifecycle hooks -->
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
import { plugins } from '../plugins/index'
|
||||
|
||||
/**
|
||||
* Context object that can be extended by plugins during onSetup.
|
||||
* Currently empty but can hold shared resources.
|
||||
*/
|
||||
const context = {}
|
||||
|
||||
onMounted(() => {
|
||||
// Invoke onSetup hook of each registered plugin
|
||||
plugins.forEach(p => {
|
||||
if (p.onSetup) {
|
||||
p.onSetup(context)
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
5
src/main.js
Normal file
5
src/main.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import './style.css'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
7
src/plugins/index.ts
Normal file
7
src/plugins/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { MarkdownPlugin } from './types'
|
||||
|
||||
/**
|
||||
* Global plugin registry.
|
||||
* Plugins can implement lifecycle hooks defined in {@link MarkdownPlugin}.
|
||||
*/
|
||||
export const plugins: MarkdownPlugin[] = []
|
||||
21
src/plugins/types.ts
Normal file
21
src/plugins/types.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export interface MarkdownPlugin {
|
||||
/**
|
||||
* Called during component setup. Allows plugin to initialize.
|
||||
* @param context - an object that can be extended by plugins.
|
||||
*/
|
||||
onSetup?(context: Record<string, any>): void
|
||||
|
||||
/**
|
||||
* Called after markdown is parsed to HTML, before emitting.
|
||||
* Allows plugin to modify the HTML.
|
||||
* @param payload - contains original markdown and generated html.
|
||||
*/
|
||||
onAfterParse?(payload: { markdown: string; html: string }): { html?: string }
|
||||
|
||||
/**
|
||||
* Called right before the HTML is rendered (e.g., before v-html).
|
||||
* Allows final adjustments.
|
||||
* @param payload - contains html that will be rendered.
|
||||
*/
|
||||
onBeforeRender?(payload: { html: string }): { html?: string }
|
||||
}
|
||||
16
src/router/index.js
Normal file
16
src/router/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
component: () => import('../App.vue')
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
})
|
||||
|
||||
export default router
|
||||
5
src/store/index.js
Normal file
5
src/store/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
const pinia = createPinia()
|
||||
|
||||
export default pinia
|
||||
167
src/style.css
Normal file
167
src/style.css
Normal file
@@ -0,0 +1,167 @@
|
||||
:root {
|
||||
font-family: 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;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.editor-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.editor-container {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
.editor, .preview {
|
||||
flex: 1;
|
||||
padding: 1rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Editor textarea */
|
||||
.editor textarea,
|
||||
.editor input,
|
||||
.editor .input {
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
line-height: 1.6;
|
||||
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
/* Selection */
|
||||
.editor ::selection {
|
||||
background: rgba(200, 200, 200, 0.3);
|
||||
}
|
||||
|
||||
/* Preview typography */
|
||||
.preview p {
|
||||
line-height: 1.6;
|
||||
}
|
||||
.preview h1 { font-size: 2em; }
|
||||
.preview h2 { font-size: 1.75em; }
|
||||
.preview h3 { font-size: 1.5em; }
|
||||
.preview h4 { font-size: 1.25em; }
|
||||
.preview h5 { font-size: 1em; }
|
||||
.preview h6 { font-size: 0.875em; }
|
||||
.preview blockquote {
|
||||
border-left: 4px solid #ddd;
|
||||
padding-left: 1rem;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
.preview table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
.preview th,
|
||||
.preview td {
|
||||
border: 1px solid #ccc;
|
||||
padding: 0.4rem;
|
||||
}
|
||||
|
||||
/* Code block */
|
||||
.preview pre,
|
||||
.preview code {
|
||||
background: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
padding: 0.8rem;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
/* Global */
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* CSS variables (to be defined elsewhere) */
|
||||
:root {
|
||||
--bg-color: var(--bg-color);
|
||||
--text-color: var(--text-color);
|
||||
}
|
||||
|
||||
/* Light mode overrides (original) */
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
7
vite.config.js
Normal file
7
vite.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
})
|
||||
Reference in New Issue
Block a user