Skip to content

Commit

Permalink
Add vuejs demo (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: Clemens Wolff <clemens@justamouse.com>
  • Loading branch information
eokwukwe and c-w committed Oct 4, 2023
1 parent c167e8d commit 1af8425
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- run: npm install --legacy-peer-deps
- run: npm --prefix=reactjs install --legacy-peer-deps
- run: npm --prefix=nextjs install --legacy-peer-deps
- run: npm --prefix=vuejs install
- run: npm run demo
- uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
"start.reactjs": "npm --prefix=reactjs start",
"start.nextjs": "npm --prefix=nextjs start",
"start": "reload --port 8080 --browser --dir .",
"lint.js": "eslint --ext js .",
"lint.js": "eslint --ext js \"*.js\"",
"lint.css": "stylelint \"*.css\"",
"lint.md": "markdownlint \"*.md\"",
"lint.prettier": "prettier --check \"**/*.js\"",
"lint.prettier": "prettier --check \"*.js\"",
"lint": "run-s lint.js lint.css lint.md lint.prettier",
"demo.vanillajs": "shx cp index.{html,js,css} mathquill4quill.{js,css} demo",
"demo.reactjs": "npm --prefix=reactjs run build",
"demo.nextjs": "npm --prefix=nextjs run build",
"demo.vuejs": "npm --prefix=vuejs run build",
"postdemo.reactjs": "shx mv reactjs/build demo/reactjs",
"postdemo.nextjs": "shx mv nextjs/out demo/nextjs",
"postdemo.vuejs": "shx mv vuejs/dist demo/vuejs",
"predemo": "shx mkdir -p demo",
"demo": "run-s demo.vanillajs demo.reactjs demo.nextjs",
"demo": "run-s demo.vanillajs demo.reactjs demo.nextjs demo.vuejs",
"prebuild": "shx mkdir -p build",
"build.babel": "babel mathquill4quill.js > build/mathquill4quill.js",
"build.uglify": "uglifyjs --compress --mangle -- build/mathquill4quill.js > build/mathquill4quill.min.js",
Expand All @@ -30,7 +32,7 @@
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"chromedriver": "^106.0.0",
"chromedriver": "^117.0.0",
"concurrently": "^4.1.1",
"csso-cli": "^3.0.0",
"eslint": "^7.11.0",
Expand Down
25 changes: 25 additions & 0 deletions vuejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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?
.vscode/
12 changes: 12 additions & 0 deletions vuejs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>mathquill4quill demo (Vue 3)</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions vuejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "vuejs",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "vite --port 4043",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@edtr-io/mathquill": "^0.11.0",
"@vueup/vue-quill": "^1.2.0",
"jquery": "^3.7.1",
"katex": "^0.16.8",
"mathquill4quill": "^2.4.0",
"vue": "^3.3.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
"vite": "^4.4.5"
}
}
128 changes: 128 additions & 0 deletions vuejs/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<script setup>
import "./jquery";
// KaTeX dependency
import katex from "katex";
window.katex = katex;
import { QuillEditor, Quill } from "@vueup/vue-quill";
import "@edtr-io/mathquill/build/mathquill.js";
import "@edtr-io/mathquill/build/mathquill.css";
// mathquill4quill include
import mathquill4quill from "mathquill4quill";
import "mathquill4quill/mathquill4quill.css";
import { onMounted, ref } from "vue";
const operators = [
["\\pm", "\\pm"],
["\\sqrt{x}", "\\sqrt"],
["\\sqrt[3]{x}", "\\sqrt[3]{}"],
["\\sqrt[n]{x}", "\\nthroot"],
["\\frac{x}{y}", "\\frac"],
["\\sum^{s}_{x}{d}", "\\sum"],
["\\prod^{s}_{x}{d}", "\\prod"],
["\\coprod^{s}_{x}{d}", "\\coprod"],
["\\int^{s}_{x}{d}", "\\int"],
["\\binom{n}{k}", "\\binom"]
];
const quill = ref();
const content = ref("");
onMounted(() => {
// For this line, refer to the following issue comment:
// https://github.com/c-w/mathquill4quill/issues/97#issuecomment-1740482856
quill.value.container = quill.value.getEditor();
const enableMathQuillFormulaAuthoring = mathquill4quill({ Quill, katex });
enableMathQuillFormulaAuthoring(quill.value, {
operators
});
});
</script>

<template>
<main class="demo-container">
<QuillEditor
id="quill-editor"
v-model:content="content"
theme="snow"
placeholder="Type text here, or click on the formula button to enter math."
ref="quill"
:options="{
modules: {
formula: true,
toolbar: [['bold', 'italic', 'underline'], ['formula']]
}
}"
/>

<footer>
<a href="https://github.com/c-w/mathquill4quill">
<p>Fork me on Github</p>
<img
width="149"
height="149"
src="https://github.blog/wp-content/uploads/2008/12/forkme_right_darkblue_121621.png?resize=149%2C149"
alt="Fork me on GitHub"
/>
</a>
</footer>
</main>
</template>

<style scoped>
footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #121621;
text-align: center;
}
footer a {
color: #fff;
font-family: sans-serif;
}
footer p {
margin: 0.5em;
}
footer img {
position: fixed;
top: 0;
right: 0;
z-index: 99999;
display: none;
}
main {
width: 100%;
height: 200px;
}
@media (min-width: 500px) {
main {
max-width: 400px;
margin: 50px auto;
}
footer p {
display: none;
}
footer img {
display: block;
}
}
label {
padding-top: 0.5em;
display: block;
}
</style>
3 changes: 3 additions & 0 deletions vuejs/src/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import $ from "jquery";

window.jQuery = window.$ = $;
10 changes: 10 additions & 0 deletions vuejs/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createApp } from "vue";
import "katex/dist/katex.css";
import "@vueup/vue-quill/dist/vue-quill.bubble.css";
import "@vueup/vue-quill/dist/vue-quill.snow.css";

import "mathquill4quill/mathquill4quill.css";

import App from "./App.vue";

createApp(App).mount("#app");
6 changes: 6 additions & 0 deletions vuejs/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
plugins: [vue()]
});

0 comments on commit 1af8425

Please sign in to comment.