docs: move examples dir out of components dir
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import { VueFlow } from '@vue-flow/core'
|
||||
import { ref } from 'vue'
|
||||
import SaveRestoreControls from './Controls.vue'
|
||||
|
||||
const elements = ref([{ id: '1', label: 'Node 1', position: { x: 100, y: 100 } }])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VueFlow v-model="elements">
|
||||
<SaveRestoreControls />
|
||||
</VueFlow>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup>
|
||||
import { Panel, useVueFlow } from '@vue-flow/core'
|
||||
|
||||
const flowKey = 'example-flow'
|
||||
|
||||
const { nodes, addNodes, setNodes, setEdges, dimensions, setTransform, toObject } = useVueFlow()
|
||||
|
||||
function onSave() {
|
||||
localStorage.setItem(flowKey, JSON.stringify(toObject()))
|
||||
}
|
||||
|
||||
function onRestore() {
|
||||
const flow = JSON.parse(localStorage.getItem(flowKey))
|
||||
|
||||
if (flow) {
|
||||
const [x = 0, y = 0] = flow.position
|
||||
setNodes(flow.nodes)
|
||||
setEdges(flow.edges)
|
||||
setTransform({ x, y, zoom: flow.zoom || 0 })
|
||||
}
|
||||
}
|
||||
|
||||
function onAdd() {
|
||||
const id = nodes.value.length + 1
|
||||
|
||||
const newNode = {
|
||||
id: `random_node-${id}`,
|
||||
label: `Node ${id}`,
|
||||
position: { x: Math.random() * dimensions.value.width, y: Math.random() * dimensions.value.height },
|
||||
}
|
||||
|
||||
addNodes([newNode])
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel position="top-right" class="save-restore-controls">
|
||||
<button style="background-color: #33a6b8" @click="onSave">save</button>
|
||||
<button style="background-color: #113285" @click="onRestore">restore</button>
|
||||
<button style="background-color: #6f3381" @click="onAdd">add node</button>
|
||||
</Panel>
|
||||
</template>
|
||||
@@ -0,0 +1,3 @@
|
||||
export { default as SaveRestoreApp } from './App.vue?raw'
|
||||
export { default as SaveRestoreControls } from './Controls.vue?raw'
|
||||
export { default as SaveRestoreCSS } from './style.css?inline'
|
||||
@@ -0,0 +1,20 @@
|
||||
.save-restore-controls {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.save-restore-controls button {
|
||||
margin-left: 5px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
color: white;
|
||||
-webkit-box-shadow: 0px 5px 10px 0px rgba(0,0,0,0.3);
|
||||
box-shadow: 0px 5px 10px 0px rgba(0,0,0,0.3);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.save-restore-controls button:hover {
|
||||
transform: scale(105%);
|
||||
transition: 250ms all ease-in-out;
|
||||
}
|
||||
Reference in New Issue
Block a user