Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vue demo #69

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function Editor() {

### Setup

- node.js >18.16.0
- node.js > 20.0
- [enable corepack](https://www.totaltypescript.com/how-to-use-corepack): `corepack enable && corepack enable npm`

### Local Development
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"dev": "pnpm -r --parallel dev",
"dev:playground": "pnpm --filter @tidbcloud/tisqleditor-playground... --parallel dev",
"dev:playground-nextjs": "pnpm --filter @tidbcloud/tisqleditor-playground-nextjs... --parallel dev",
"dev:vue-demo": "pnpm --filter @tidbcloud/tisqleditor-vue-demo... --parallel dev",
"build": "pnpm -r build",
"build:playground": "pnpm --filter @tidbcloud/tisqleditor-playground... run build",
"build:playground-nextjs": "pnpm --filter @tidbcloud/tisqleditor-playground-nextjs... run build",
"build:vue-demo": "pnpm --filter @tidbcloud/tisqleditor-vue-demo... run build",
"test": "jest",
"release": "changeset publish"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/playground-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tidbcloud/tisqleditor-playground-nextjs",
"private": true,
"version": "0.0.1",
"version": "0.0.6",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down
24 changes: 24 additions & 0 deletions packages/vue-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -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?
16 changes: 16 additions & 0 deletions packages/vue-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# TiSQLEditor Vue Component Demo

This demo is used to test `@tidbcloud/tisqleditor-vue` package, created by Vue3+Typescript+Vite.

## Preview

👉🏻 [Try it](https://tisqleditor-vue-demo.vercel.app)

![tisqleditor vue demo](./public/tisqleditor-vue-demo.png)

## Getting Started

```bash
pnpm i
pnpm dev
```
13 changes: 13 additions & 0 deletions packages/vue-demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vue.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TiSQLEditor Vue Demo</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions packages/vue-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@tidbcloud/tisqleditor-vue-demo",
"private": true,
"version": "0.0.6",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"@tidbcloud/codemirror-extension-ai-widget": "workspace:^",
"@tidbcloud/codemirror-extension-cur-sql-gutter": "workspace:^",
"@tidbcloud/codemirror-extension-sql-autocomplete": "workspace:^",
"@tidbcloud/codemirror-extension-themes": "workspace:^",
"@tidbcloud/tisqleditor-vue": "workspace:^",
"vue": "^3.4.31"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.5",
"typescript": "^5.2.2",
"vite": "^5.3.4",
"vue-tsc": "^2.0.24"
}
}
Binary file added packages/vue-demo/public/tisqleditor-vue-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/vue-demo/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/vue-demo/public/vue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions packages/vue-demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<script setup lang="ts">
import { ref } from 'vue'

import { SQLEditor, EditorCacheProvide } from '@tidbcloud/tisqleditor-vue'
import { oneDark, bbedit } from '@tidbcloud/codemirror-extension-themes'
import {
aiWidget,
isUnifiedMergeViewActive
} from '@tidbcloud/codemirror-extension-ai-widget'
import { curSqlGutter } from '@tidbcloud/codemirror-extension-cur-sql-gutter'
import { sqlAutoCompletion } from '@tidbcloud/codemirror-extension-sql-autocomplete'

import { delay } from './lib/delay'

const isDark = ref(true)
function toggle() {
isDark.value = !isDark.value
}

const extraExts = [
aiWidget({
chat: async () => {
await delay(2000)
return {
status: 'success',
message:
'select * from test;\n-- the data is mocked, replace by your own api when using'
}
},
cancelChat: () => {},
getDbList: () => {
return ['test1', 'test2']
}
}),
sqlAutoCompletion(),
curSqlGutter({
whenHide(view) {
return isUnifiedMergeViewActive(view.state)
}
})
]
</script>

<template>
<EditorCacheProvide>
<h2>TiSQLEditor Vue Component Demo</h2>
<button @click="toggle">
toggle theme: {{ isDark ? 'dark' : 'light' }}
</button>

<SQLEditor
class="editorContainer"
editorId="test"
doc="select * from test;"
:theme="isDark ? oneDark : bbedit"
:extraExts="extraExts"
/>
</EditorCacheProvide>
</template>

<style scoped>
.editorContainer {
height: 400px;
width: 800px;
text-align: left;
margin-top: 16px;
}
</style>
3 changes: 3 additions & 0 deletions packages/vue-demo/src/lib/delay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
5 changes: 5 additions & 0 deletions packages/vue-demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'

createApp(App).mount('#app')
79 changes: 79 additions & 0 deletions packages/vue-demo/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
: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;
}

.card {
padding: 2em;
}

#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
1 change: 1 addition & 0 deletions packages/vue-demo/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
27 changes: 27 additions & 0 deletions packages/vue-demo/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}
11 changes: 11 additions & 0 deletions packages/vue-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
]
}
13 changes: 13 additions & 0 deletions packages/vue-demo/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true,
"noEmit": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions packages/vue-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()]
})
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tidbcloud/tisqleditor-vue",
"version": "0.0.3",
"version": "0.0.6",
"description": "tisqleditor vue component",
"type": "module",
"main": "dist/index.js",
Expand Down
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.