Skip to content

Commit 55f1ffb

Browse files
committed
style: format web project with prettier
1 parent e3395fc commit 55f1ffb

File tree

8 files changed

+132
-115
lines changed

8 files changed

+132
-115
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.nuxt
2+
.ouput
3+
dist

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"scripts": {
4040
"build": "unbuild",
4141
"dev": "vitest",
42-
"lint": "eslint --ext .js,.ts . && prettier -c src test",
43-
"lint:fix": "eslint --fix --ext .js,.ts . && prettier -w src test",
42+
"lint": "eslint --ext .js,.ts . && prettier -c src test web",
43+
"lint:fix": "eslint --fix --ext .js,.ts . && prettier -w src test web",
4444
"prepack": "pnpm build",
4545
"release": "pnpm test && changelogen --release --push && npm publish",
4646
"test": "pnpm lint && vitest run --coverage",

web/components/editor.vue

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,66 @@
33
</template>
44

55
<script>
6-
import { defineComponent } from 'vue'
7-
import 'monaco-editor/esm/vs/language/typescript/monaco.contribution'
8-
import 'monaco-editor/esm/vs/language/json/monaco.contribution'
9-
import 'monaco-editor/esm/vs/basic-languages/monaco.contribution'
10-
import 'monaco-editor/esm/vs/editor/editor.all'
11-
import { editor as moncacoEditor } from 'monaco-editor/esm/vs/editor/editor.api'
6+
import { defineComponent } from "vue";
7+
import "monaco-editor/esm/vs/language/typescript/monaco.contribution";
8+
import "monaco-editor/esm/vs/language/json/monaco.contribution";
9+
import "monaco-editor/esm/vs/basic-languages/monaco.contribution";
10+
import "monaco-editor/esm/vs/editor/editor.all";
11+
import { editor as moncacoEditor } from "monaco-editor/esm/vs/editor/editor.api";
1212
1313
// https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-amd-cross.md
1414
globalThis.MonacoEnvironment = {
15-
getWorkerUrl () {
16-
const moncoCDN = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.23'
15+
getWorkerUrl() {
16+
const moncoCDN = "https://cdn.jsdelivr.net/npm/monaco-editor@0.23";
1717
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
1818
self.MonacoEnvironment = { baseUrl: '${moncoCDN}/min/' };
1919
importScripts('${moncoCDN}/min/vs/base/worker/workerMain.js');
20-
`)}`
21-
}
22-
}
20+
`)}`;
21+
},
22+
};
2323
2424
export default defineComponent({
2525
props: {
2626
modelValue: {
2727
type: String,
28-
required: true
28+
required: true,
2929
},
3030
language: {
3131
type: String,
32-
default: 'javascript'
32+
default: "javascript",
3333
},
3434
readOnly: {
3535
type: Boolean,
36-
default: false
37-
}
36+
default: false,
37+
},
3838
},
3939
watch: {
40-
modelValue (value, oldValue) {
40+
modelValue(value, oldValue) {
4141
if (value !== oldValue && this.readOnly) {
42-
this.editor.setValue(value)
42+
this.editor.setValue(value);
4343
}
44-
}
44+
},
4545
},
46-
mounted () {
46+
mounted() {
4747
const editor = moncacoEditor.create(this.$refs.editor, {
4848
value: this.modelValue,
4949
language: this.language,
5050
readOnly: this.readOnly,
5151
wordWrap: true,
5252
automaticLayout: true,
5353
minimap: {
54-
enabled: false
55-
}
56-
})
57-
this.editor = editor
54+
enabled: false,
55+
},
56+
});
57+
this.editor = editor;
5858
editor.onDidChangeModelContent(() => {
59-
this.$emit('update:modelValue', editor.getValue())
60-
})
59+
this.$emit("update:modelValue", editor.getValue());
60+
});
6161
// editor.onDidBlurEditorWidget(() => {
6262
// this.$emit('update:value', editor.getValue())
6363
// })
64-
}
65-
})
64+
},
65+
});
6666
</script>
6767

6868
<style scoped>

web/components/loading.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<template>
22
<div class="loading">
33
<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->
4-
<svg width="50" height="30" viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="#ababab">
4+
<svg
5+
width="50"
6+
height="30"
7+
viewBox="0 0 120 30"
8+
xmlns="http://www.w3.org/2000/svg"
9+
fill="#ababab"
10+
>
511
<circle cx="15" cy="15" r="15">
612
<animate
713
attributeName="r"
@@ -73,7 +79,7 @@
7379
</template>
7480

7581
<style scoped>
76-
.loading {
77-
padding: 2em;
78-
}
82+
.loading {
83+
padding: 2em;
84+
}
7985
</style>

web/components/markdown.vue

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<template>
22
<div class="container">
33
<div class="mb-2">
4-
<input id="markdown-raw" v-model="render" type="checkbox">
5-
<label for="markdown-raw" class="select-none"> Render markdown</label><br>
4+
<input id="markdown-raw" v-model="render" type="checkbox" />
5+
<label for="markdown-raw" class="select-none"> Render markdown</label
6+
><br />
67
</div>
78
<!-- eslint-disable-next-line vue/no-v-html -->
89
<div v-if="render" class="markdown" v-html="rendered" />
@@ -11,36 +12,38 @@
1112
</template>
1213

1314
<script>
14-
import 'prismjs/themes/prism.css'
15-
import { defineComponent, ref } from 'vue'
16-
import { marked } from 'marked'
17-
import prism from 'prismjs'
18-
import { safeComputed } from '../composables/utils'
15+
import "prismjs/themes/prism.css";
16+
import { defineComponent, ref } from "vue";
17+
import { marked } from "marked";
18+
import prism from "prismjs";
19+
import { safeComputed } from "../composables/utils";
1920
2021
export default defineComponent({
2122
props: {
2223
value: {
2324
type: String,
24-
default: ''
25-
}
25+
default: "",
26+
},
2627
},
27-
setup (ctx) {
28-
const render = ref(true)
29-
const rendered = safeComputed(() => marked(ctx.value, {
30-
highlight (code, lang) {
31-
if (lang === 'ts') {
32-
lang = 'js'
33-
}
34-
const _lang = prism.languages[lang]
35-
return _lang ? prism.highlight(code, _lang) : code
36-
}
37-
}))
28+
setup(ctx) {
29+
const render = ref(true);
30+
const rendered = safeComputed(() =>
31+
marked(ctx.value, {
32+
highlight(code, lang) {
33+
if (lang === "ts") {
34+
lang = "js";
35+
}
36+
const _lang = prism.languages[lang];
37+
return _lang ? prism.highlight(code, _lang) : code;
38+
},
39+
})
40+
);
3841
return {
3942
render,
40-
rendered
41-
}
42-
}
43-
})
43+
rendered,
44+
};
45+
},
46+
});
4447
</script>
4548

4649
<style scoped>
@@ -51,14 +54,15 @@ export default defineComponent({
5154

5255
<style>
5356
.markdown {
54-
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji !important;
57+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
58+
sans-serif, Apple Color Emoji, Segoe UI Emoji !important;
5559
color: #24292e !important;
5660
word-wrap: break-word;
5761
}
5862
5963
.markdown code {
60-
font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;
61-
padding: .2em .4em;
64+
font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
65+
padding: 0.2em 0.4em;
6266
font-size: 85%;
6367
background-color: #f6f8fa;
6468
border-radius: 6px;

web/components/tabs.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
</template>
1414

1515
<script>
16-
import { defineComponent } from 'vue'
16+
import { defineComponent } from "vue";
1717
1818
export default defineComponent({
1919
props: {
2020
tabs: {
2121
type: Array,
22-
default: () => []
22+
default: () => [],
2323
},
2424
modelValue: {
2525
type: String,
26-
default: ''
27-
}
28-
}
29-
})
26+
default: "",
27+
},
28+
},
29+
});
3030
</script>

web/composables/utils.ts

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { reactive, watch, computed } from 'vue'
1+
import { reactive, watch, computed } from "vue";
22

3-
const globalKeys = Object.getOwnPropertyNames(globalThis)
4-
.filter(key => key[0].toLocaleLowerCase() === key[0] && key !== 'console' && key !== 'module')
3+
const globalKeys = Object.getOwnPropertyNames(globalThis).filter(
4+
(key) =>
5+
key[0].toLocaleLowerCase() === key[0] &&
6+
key !== "console" &&
7+
key !== "module"
8+
);
59

6-
export function evaluateSource (src) {
10+
export function evaluateSource(src) {
711
// Basic commonjs transform
812
src = src
9-
.replace('export default', '_module._exports = ')
10-
.replace(/export (const|let|var) (\w+) ?= ?/g, '_exports.$2 = ')
11-
.replace(/export (function|class) (\w+)/g, '_exports.$2 = $1 $2 ')
13+
.replace("export default", "_module._exports = ")
14+
.replace(/export (const|let|var) (\w+) ?= ?/g, "_exports.$2 = ")
15+
.replace(/export (function|class) (\w+)/g, "_exports.$2 = $1 $2 ");
1216

1317
// eslint-disable-next-line no-new-func
1418
const fn = Function(`
@@ -17,69 +21,71 @@ export function evaluateSource (src) {
1721
const sandbox = {
1822
_module,
1923
_exports,
20-
${globalKeys.map(key => `"${key}": {}`).join(',')}
24+
${globalKeys.map((key) => `"${key}": {}`).join(",")}
2125
}
2226
with (sandbox) {
2327
${src};
2428
};
2529
return sandbox._module._exports;
26-
`)
30+
`);
2731

28-
return fn.call({})
32+
return fn.call({});
2933
}
3034

31-
export function tryFn (fn) {
35+
export function tryFn(fn) {
3236
try {
33-
return fn()
37+
return fn();
3438
} catch (err) {
3539
// eslint-disable-next-line no-console
36-
console.error(err)
37-
return null
40+
console.error(err);
41+
return null;
3842
}
3943
}
4044

41-
export function persistedState (initialState = {}) {
45+
export function persistedState(initialState = {}) {
4246
const state = reactive({
4347
...initialState,
44-
...tryFn(() => JSON.parse(atob(window.location.hash.substr(1)) || '{}'))
45-
})
48+
...tryFn(() => JSON.parse(atob(window.location.hash.substr(1)) || "{}")),
49+
});
4650
watch(state, () => {
47-
window.location.hash = '#' + btoa(JSON.stringify(state))
48-
})
49-
return state
51+
window.location.hash = "#" + btoa(JSON.stringify(state));
52+
});
53+
return state;
5054
}
5155

52-
export function safeComputed (fn) {
53-
let lastState = null
56+
export function safeComputed(fn) {
57+
let lastState = null;
5458
return computed(() => {
5559
try {
56-
lastState = fn()
57-
return lastState
60+
lastState = fn();
61+
return lastState;
5862
} catch (err) {
5963
// eslint-disable-next-line no-console
60-
console.error(err)
61-
return lastState
64+
console.error(err);
65+
return lastState;
6266
}
63-
})
67+
});
6468
}
6569

66-
export function asyncComputed (fn) {
67-
const state = ref(undefined)
68-
const computedPromise = safeComputed(fn)
69-
watch(computedPromise, val => {
70-
val.then(r => state.value = r)
71-
})
72-
return state
70+
export function asyncComputed(fn) {
71+
const state = ref(undefined);
72+
const computedPromise = safeComputed(fn);
73+
watch(computedPromise, (val) => {
74+
val.then((r) => (state.value = r));
75+
});
76+
return state;
7377
}
7478

75-
export function asyncImport ({ loader, loading, error }) {
76-
const m = reactive(loading || {})
77-
loader().then(res => Object.assign(m, res)).catch((err) => {
78-
if (error) {
79-
Object.assign(m, error(err))
80-
}
81-
// eslint-disable-next-line no-console
82-
console.error(err)
83-
})
84-
return m
79+
export function asyncImport({ loader, loading, error }) {
80+
const m = reactive(loading || {});
81+
loader()
82+
.then((res) => Object.assign(m, res))
83+
.catch((err) => {
84+
if (error) {
85+
Object.assign(m, error(err));
86+
}
87+
// eslint-disable-next-line no-console
88+
console.error(err);
89+
});
90+
return m;
8591
}

web/nuxt.config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { defineNuxtConfig } from 'nuxt/config'
1+
import { defineNuxtConfig } from "nuxt/config";
22

33
// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
44
export default defineNuxtConfig({
55
ssr: false,
6-
modules: [
7-
'nuxt-windicss'
8-
]
9-
})
6+
modules: ["nuxt-windicss"],
7+
});

0 commit comments

Comments
 (0)