@abi-software/simulationvuer 0.7.0-vue-3-alpha.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,85 @@
1
- import { evaluateValue } from "./common.js";
2
-
3
- export function initialiseUi(parent) {
4
- // Initialise some output-related data.
5
-
6
- parent.simulationUiInfo.output.data.forEach((data) => {
7
- parent.simulationDataId[data.id] = data.name;
8
- });
9
-
10
- let index = -1;
11
-
12
- parent.simulationUiInfo.output.plots.forEach((outputPlot) => {
13
- ++index;
14
-
15
- parent.layout[index] = {
16
- margin: {
17
- t: 5,
18
- l: 55,
19
- r: 55,
20
- b: 90,
21
- pad: 4
22
- },
23
- dragmode: "pan",
24
- xaxis: {
25
- title: {
26
- text: outputPlot.xAxisTitle,
27
- font: {
28
- size: 10,
29
- },
30
- },
31
- },
32
- yaxis: {
33
- title: {
34
- text: outputPlot.yAxisTitle,
35
- font: {
36
- size: 10,
37
- },
38
- }
39
- },
40
- };
41
-
42
- parent.simulationData[index] = [{}];
43
- });
44
- }
45
-
46
- export function finaliseUi(parent) {
47
- // Finalise our UI, but only if we haven't already done so, we are mounted,
48
- // and we have some valid simulation UI information.
49
-
50
- if (!parent.hasFinalisedUi && parent.isMounted && parent.hasValidSimulationUiInfo) {
51
- // Configure the PlotVuer's.
52
-
53
- parent.$refs.output.classList.add("x" + parent.simulationUiInfo.output.plots.length);
54
-
55
- // Make sure that our UI is up to date.
56
-
57
- updateUi(parent);
58
-
59
- parent.hasFinalisedUi = true;
60
- }
61
- }
62
-
63
- export function updateUi(parent) {
64
- // Show/hide and enable/disable all the elements.
65
- // Note: we do this using $nextTick() to ensure that the UI has been fully
66
- // mounted.
67
- parent.$nextTick(() => {
68
- let index = -1;
69
-
70
- parent.simulationUiInfo.input.forEach((input) => {
71
- ++index;
72
- parent.$refs.simInput[index].visible = (input.visible === undefined)?true:evaluateValue(parent, input.visible);
73
- });
74
- });
75
- }
1
+ import { evaluateValue } from "./common.js";
2
+
3
+ export function initialiseUi(parent) {
4
+ // Initialise some output-related data.
5
+
6
+ parent.simulationUiInfo.output.data.forEach((data) => {
7
+ parent.simulationDataId[data.id] = data.name;
8
+ });
9
+
10
+ let index = -1;
11
+
12
+ parent.simulationUiInfo.output.plots.forEach((outputPlot) => {
13
+ ++index;
14
+
15
+ parent.layout[index] = {
16
+ paper_bgcolor: "rgba(0, 0, 0, 0)",
17
+ plot_bgcolor: "rgba(0, 0, 0, 0)",
18
+ autosize: true,
19
+ margin: {
20
+ t: 25,
21
+ l: 55,
22
+ r: 25,
23
+ b: 30,
24
+ pad: 4,
25
+ },
26
+ loading: false,
27
+ options: {
28
+ responsive: true,
29
+ scrollZoom: true,
30
+ },
31
+ dragmode: "pan",
32
+ xaxis: {
33
+ title: {
34
+ text: outputPlot.xAxisTitle,
35
+ font: {
36
+ size: 10,
37
+ },
38
+ },
39
+ },
40
+ yaxis: {
41
+ title: {
42
+ text: outputPlot.yAxisTitle,
43
+ font: {
44
+ size: 10,
45
+ },
46
+ },
47
+ },
48
+ };
49
+
50
+ parent.simulationData[index] = [{}];
51
+ });
52
+ }
53
+
54
+ export function finaliseUi(parent) {
55
+ // Finalise our UI, but only if we haven't already done so, we are mounted,
56
+ // and we have some valid simulation UI information.
57
+
58
+ if (!parent.hasFinalisedUi && parent.isMounted && parent.hasValidSimulationUiInfo) {
59
+ // Configure the PlotVuer's.
60
+
61
+ parent.$refs.output.classList.add("x" + parent.simulationUiInfo.output.plots.length);
62
+
63
+ // Make sure that our UI is up to date.
64
+
65
+ updateUi(parent);
66
+
67
+ parent.hasFinalisedUi = true;
68
+ }
69
+ }
70
+
71
+ export function updateUi(parent) {
72
+ // Show/hide and enable/disable all the elements.
73
+ // Note: we do this using $nextTick() to ensure that the UI has been fully
74
+ // mounted.
75
+
76
+ parent.$nextTick(() => {
77
+ let index = -1;
78
+
79
+ parent.simulationUiInfo.input.forEach((input) => {
80
+ ++index;
81
+
82
+ parent.$refs.simInput[index].visible = (input.visible === undefined) ? true : evaluateValue(parent, input.visible);
83
+ });
84
+ });
85
+ }
package/src/main.js CHANGED
@@ -1,20 +1,19 @@
1
- import { createApp } from 'vue'
2
- import * as VueRouter from 'vue-router'
3
- import App from './App.vue'
4
- import ElementPlus from 'element-plus'
5
-
6
-
7
- const routes = [
8
- { path: '/'},
9
- ]
10
-
11
- const router = VueRouter.createRouter({
12
- // 4. Provide the history implementation to use. We are using the hash history for simplicity here.
13
- history: VueRouter.createWebHashHistory(),
14
- routes,
15
- })
16
-
17
- const app = createApp(App)
18
- app.use(router)
19
- app.use(ElementPlus)
20
- app.mount('#app')
1
+ import { createApp } from 'vue'
2
+ import * as VueRouter from 'vue-router'
3
+ import App from './App.vue'
4
+ import ElementPlus from 'element-plus'
5
+
6
+ const routes = [
7
+ { path: '/'},
8
+ ]
9
+
10
+ const router = VueRouter.createRouter({
11
+ // Provide the history implementation to use. We are using the hash history for simplicity here.
12
+ history: VueRouter.createWebHashHistory(),
13
+ routes,
14
+ })
15
+
16
+ const app = createApp(App)
17
+ app.use(router)
18
+ app.use(ElementPlus)
19
+ app.mount('#app')
package/vite.config.js CHANGED
@@ -1,73 +1,60 @@
1
- import path from "path";
2
- import { resolve } from "node:path";
3
- const pathSrc = path.resolve(__dirname, "./src");
4
- import { defineConfig } from 'vite'
5
- import vue from '@vitejs/plugin-vue'
6
- import Components from 'unplugin-vue-components/vite'
7
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
8
-
9
- // https://vitejs.dev/config/
10
- export default defineConfig(({ command, mode }) => {
11
- const config = {
12
- // css: {
13
- // preprocessorOptions: {
14
- // scss: {
15
- // additionalData: `@use '${pathSrc}\\assets\\styles' as *;`
16
- // },
17
- // },
18
- // },
19
- plugins: [
20
- vue(),
21
- Components({
22
- // allow auto load markdown components under `./src/components/`
23
- extensions: ['vue', 'md'],
24
- // allow auto import and register components used in markdown
25
- include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
26
- resolvers: [
27
- ElementPlusResolver({
28
- importStyle: 'sass',
29
- }),
30
- ],
31
- dts: 'src/components.d.ts',
32
- }),
33
-
34
- // https://github.com/antfu/unocss
35
- // see unocss.config.ts for config
36
- ],
37
- build: {
38
- lib: {
39
- entry: path.resolve(__dirname, "./src/components/index.js"),
40
- name: "SimulationVuer",
41
- fileName: "simulationvuer",
42
- },
43
- rollupOptions: {
44
- external: ["vue", "@abi-software/svg-sprite", "@abi-software/plotvuer"],
45
- output: {
46
- globals: {
47
- vue: "Vue",
48
- "@abi-software/svg-sprite": "@abi-software/svg-sprite",
49
- "@abi-software/plotvuer": "@abi-software/plotvuer"
50
- },
51
- },
52
- },
53
- },
54
- resolve: {
55
- alias: {
56
- '~/': `${pathSrc}/`,
57
- },
58
- },
59
- };
60
-
61
- if (command === 'serve') {
62
- config.server = {
63
- port: 8081,
64
- };
65
- config.define = {
66
- 'process.env.HTTP_PROXY': 8081,
67
- global: 'globalThis',
68
- // If you want to exposes all env variables, which is not recommended
69
- // 'process.env': env
70
- };
71
- };
72
- return config;
73
- })
1
+ import path from "path";
2
+ import { resolve } from "node:path";
3
+ const pathSrc = path.resolve(__dirname, "./src");
4
+ import { defineConfig } from "vite";
5
+ import vue from "@vitejs/plugin-vue";
6
+ import Components from "unplugin-vue-components/vite";
7
+ import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
8
+
9
+ export default defineConfig(({ command, mode }) => {
10
+ const config = {
11
+ plugins: [
12
+ vue(),
13
+ Components({
14
+ // Allow auto load markdown components under `./src/components/`.
15
+ extensions: ["vue", "md"],
16
+ // Allow auto import and register components used in markdown.
17
+ include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
18
+ resolvers: [
19
+ ElementPlusResolver({
20
+ importStyle: "sass",
21
+ }),
22
+ ],
23
+ dts: "src/components.d.ts",
24
+ }),
25
+ ],
26
+ build: {
27
+ lib: {
28
+ entry: path.resolve(__dirname, "./src/components/index.js"),
29
+ name: "SimulationVuer",
30
+ fileName: "simulationvuer",
31
+ },
32
+ rollupOptions: {
33
+ external: ["vue", "@abi-software/svg-sprite", "@abi-software/plotvuer"],
34
+ output: {
35
+ globals: {
36
+ vue: "Vue",
37
+ "@abi-software/svg-sprite": "@abi-software/svg-sprite",
38
+ "@abi-software/plotvuer": "@abi-software/plotvuer",
39
+ },
40
+ },
41
+ },
42
+ },
43
+ resolve: {
44
+ alias: {
45
+ "~/": `${pathSrc}/`,
46
+ },
47
+ },
48
+ };
49
+
50
+ if (command === "serve") {
51
+ config.server = {
52
+ port: 8081,
53
+ };
54
+ config.define = {
55
+ "process.env.HTTP_PROXY": 8081,
56
+ global: "globalThis",
57
+ };
58
+ }
59
+ return config;
60
+ });
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Vuese Generator
3
+ *
4
+ * To generate markdown files from Vue components
5
+ * To watch components changes for Vitepress on Dev Mode
6
+ */
7
+
8
+ import fs from 'fs'
9
+ import path from 'path'
10
+ import chokidar from 'chokidar'
11
+ import { parser } from '@vuese/parser'
12
+ import { Render } from '@vuese/markdown-render'
13
+
14
+ const watchMode = process.argv.find((argv) => argv === 'watch')
15
+
16
+ const componentsDir = 'src/components'
17
+ const components = ['SimulationVuer.vue']
18
+ const outputDir = 'docs/components'
19
+
20
+ function generateMarkdown(file) {
21
+ const fileWithPath = `${componentsDir}/${file}`
22
+ const fileContent = fs.readFileSync(fileWithPath, 'utf-8')
23
+
24
+ try {
25
+ const parserResult = parser(fileContent)
26
+ parserResult.name = 'SimulationVuer' // Because there has another name prop in component
27
+ const r = new Render(parserResult)
28
+ const renderResult = r.render()
29
+ const markdownResult = r.renderMarkdown()
30
+ const markdownContent = markdownResult.content
31
+ const componentName = path.basename(fileWithPath, '.vue')
32
+
33
+ if (!fs.existsSync(outputDir)) {
34
+ fs.mkdirSync(outputDir)
35
+ }
36
+
37
+ fs.writeFile(`${outputDir}/${componentName}.md`, markdownContent, (err) => {
38
+ if (err) {
39
+ console.error(`Error writing markdown file for ${componentName}`, err)
40
+ } else {
41
+ console.log(`Markdown file for ${componentName} is generated!`)
42
+ }
43
+ })
44
+ } catch(e) {
45
+ console.error(e)
46
+ }
47
+ }
48
+
49
+ // To generate markdown files - one time
50
+ components.forEach((component) => {
51
+ console.log(`Write markdown file for ${component} on first load.`)
52
+ generateMarkdown(component)
53
+ })
54
+
55
+ // To watch component changes and generate markdown files
56
+ if (watchMode) {
57
+ const watcher = chokidar.watch(components, {
58
+ cwd: componentsDir,
59
+ ignoreInitial: true,
60
+ })
61
+
62
+ watcher.on('change', (file) => {
63
+ console.log(`The component ${file} has changed!`)
64
+ generateMarkdown(file)
65
+ })
66
+ }