feat(examples): add pinia example to vite-examples
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import './index.css'
|
import './index.css'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { router } from './router'
|
import { router } from './router'
|
||||||
|
|
||||||
@@ -7,4 +8,5 @@ const app = createApp(App)
|
|||||||
|
|
||||||
app.config.performance = true
|
app.config.performance = true
|
||||||
app.use(router)
|
app.use(router)
|
||||||
|
app.use(createPinia())
|
||||||
app.mount('#root')
|
app.mount('#root')
|
||||||
|
|||||||
@@ -7,13 +7,14 @@
|
|||||||
"lint": "eslint --ext .js,.ts,.vue ./"
|
"lint": "eslint --ext .js,.ts,.vue ./"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vueflow": "workspace:*",
|
|
||||||
"@vue-flow/background": "workspace:*",
|
"@vue-flow/background": "workspace:*",
|
||||||
"@vue-flow/controls": "workspace:*",
|
"@vue-flow/controls": "workspace:*",
|
||||||
"@vue-flow/core": "workspace:*",
|
"@vue-flow/core": "workspace:*",
|
||||||
"@vue-flow/minimap": "workspace:*",
|
"@vue-flow/minimap": "workspace:*",
|
||||||
"@vue-flow/node-resizer": "workspace:*",
|
"@vue-flow/node-resizer": "workspace:*",
|
||||||
"@vue-flow/node-toolbar": "workspace:*"
|
"@vue-flow/node-toolbar": "workspace:*",
|
||||||
|
"pinia": "^2.0.35",
|
||||||
|
"vueflow": "workspace:*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tooling/eslint-config": "workspace:*",
|
"@tooling/eslint-config": "workspace:*",
|
||||||
|
|||||||
@@ -122,6 +122,10 @@ export const routes: RouterOptions['routes'] = [
|
|||||||
path: '/easy-connect',
|
path: '/easy-connect',
|
||||||
component: () => import('./src/EasyConnect/EasyConnect.vue'),
|
component: () => import('./src/EasyConnect/EasyConnect.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/pinia',
|
||||||
|
component: () => import('./src/Pinia/PiniaExample.vue'),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export const router = createRouter({
|
export const router = createRouter({
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { Panel, PanelPosition, VueFlow, useVueFlow } from '@vue-flow/core'
|
||||||
|
import useStore from './store'
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
|
||||||
|
const { onConnect, addEdges } = useVueFlow()
|
||||||
|
|
||||||
|
onConnect((params) => addEdges([params]))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VueFlow v-model="store.elements" fit-view-on-init>
|
||||||
|
<Panel :position="PanelPosition.TopCenter">
|
||||||
|
<button @click="store.updatePosition">update positions</button>
|
||||||
|
<button @click="store.toggleClass">toggle class</button>
|
||||||
|
<button @click="store.log">log store state</button>
|
||||||
|
<button @click="store.reset">reset elements</button>
|
||||||
|
</Panel>
|
||||||
|
</VueFlow>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.vue-flow__panel {
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
|
||||||
|
color: #333;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
margin: 0.25rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vue-flow__panel button {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
|
||||||
|
color: #333;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
margin: 0.25rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vue-flow__panel button:hover {
|
||||||
|
background-color: #e5e5e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vue-flow__panel button:active {
|
||||||
|
background-color: #d5d5d5;
|
||||||
|
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { isNode } from '@vue-flow/core'
|
||||||
|
|
||||||
|
const useStore = defineStore('elementsStore', {
|
||||||
|
state() {
|
||||||
|
return {
|
||||||
|
foo: ['bar', 'baz'],
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
type: 'input',
|
||||||
|
label: 'Node 1',
|
||||||
|
position: { x: 250, y: 5 },
|
||||||
|
class: 'light',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
label: 'Node 2',
|
||||||
|
position: { x: 100, y: 100 },
|
||||||
|
class: 'light',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
label: 'Node 3',
|
||||||
|
position: { x: 400, y: 100 },
|
||||||
|
class: 'light',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4',
|
||||||
|
label: 'Node 4',
|
||||||
|
position: { x: 400, y: 200 },
|
||||||
|
class: 'light',
|
||||||
|
},
|
||||||
|
{ id: 'e1-2', source: '1', target: '2' },
|
||||||
|
{ id: 'e1-3', source: '1', target: '3' },
|
||||||
|
{ id: 'e3-4', source: '3', target: '4' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
reset() {
|
||||||
|
this.elements = []
|
||||||
|
},
|
||||||
|
log() {
|
||||||
|
console.log('stored elements', this.elements)
|
||||||
|
},
|
||||||
|
toggleClass() {
|
||||||
|
this.elements.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
|
||||||
|
},
|
||||||
|
updatePosition() {
|
||||||
|
this.elements.forEach((el) => {
|
||||||
|
if (isNode(el)) {
|
||||||
|
el.position = {
|
||||||
|
x: Math.random() * 400,
|
||||||
|
y: Math.random() * 400,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default useStore
|
||||||
Generated
+20
-1
@@ -205,6 +205,9 @@ importers:
|
|||||||
'@vue-flow/node-toolbar':
|
'@vue-flow/node-toolbar':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../packages/node-toolbar
|
version: link:../../packages/node-toolbar
|
||||||
|
pinia:
|
||||||
|
specifier: ^2.0.35
|
||||||
|
version: 2.0.35(vue@3.2.47)
|
||||||
vueflow:
|
vueflow:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../packages/vue-flow
|
version: link:../../packages/vue-flow
|
||||||
@@ -8903,6 +8906,23 @@ packages:
|
|||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/pinia@2.0.35(vue@3.2.47):
|
||||||
|
resolution: {integrity: sha512-P1IKKQWhxGXiiZ3atOaNI75bYlFUbRxtJdhPLX059Z7+b9Z04rnTZdSY8Aph1LA+/4QEMAYHsTQ638Wfe+6K5g==}
|
||||||
|
peerDependencies:
|
||||||
|
'@vue/composition-api': ^1.4.0
|
||||||
|
typescript: '>=4.4.4'
|
||||||
|
vue: ^2.6.14 || ^3.2.0
|
||||||
|
peerDependenciesMeta:
|
||||||
|
'@vue/composition-api':
|
||||||
|
optional: true
|
||||||
|
typescript:
|
||||||
|
optional: true
|
||||||
|
dependencies:
|
||||||
|
'@vue/devtools-api': 6.5.0
|
||||||
|
vue: 3.2.47
|
||||||
|
vue-demi: 0.14.0(vue@3.2.47)
|
||||||
|
dev: false
|
||||||
|
|
||||||
/pkg-dir@4.2.0:
|
/pkg-dir@4.2.0:
|
||||||
resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}
|
resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@@ -11415,7 +11435,6 @@ packages:
|
|||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
dependencies:
|
||||||
vue: 3.2.47
|
vue: 3.2.47
|
||||||
dev: true
|
|
||||||
|
|
||||||
/vue-devtools-stub@0.1.0:
|
/vue-devtools-stub@0.1.0:
|
||||||
resolution: {integrity: sha512-RutnB7X8c5hjq39NceArgXg28WZtZpGc3+J16ljMiYnFhKvd8hITxSWQSQ5bvldxMDU6gG5mkxl1MTQLXckVSQ==}
|
resolution: {integrity: sha512-RutnB7X8c5hjq39NceArgXg28WZtZpGc3+J16ljMiYnFhKvd8hITxSWQSQ5bvldxMDU6gG5mkxl1MTQLXckVSQ==}
|
||||||
|
|||||||
Reference in New Issue
Block a user