Skip to content

Commit

Permalink
Merge pull request #41 from plastic-io/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
TonyGermaneri authored Feb 3, 2024
2 parents ae48d97 + b5c213b commit ced0660
Show file tree
Hide file tree
Showing 23 changed files with 445 additions and 56 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<div id="app"></div>
<script src="https://unpkg.com/jszip@3.10.1/dist/jszip.min.js"></script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"flatted": "^3.2.7",
"htmlparser2": "^8.0.1",
"jshashes": "^1.0.8",
"jszip": "^3.10.1",
"meriyah": "^4.3.3",
"moment": "^2.29.4",
"monaco-editor": "^0.34.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/Auth0AuthenticationProvider/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default class Auth0 extends EditorModule {
title: 'Logout',
component: 'v-icon',
props: {
style: "cursor: pointer",
"help-topic": "logout",
alt: 'Logout of your current session',
title: 'Logout of your current session',
icon: 'mdi-logout',
Expand Down
1 change: 0 additions & 1 deletion packages/CompileTemplate/importVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const _resolveDynamicComponent = self.dependencies.vue.resolveDynamicComponent;
let styles = blocks.descriptor.styles.map((style: any) => {
const s = compiler.compileStyle({id, source: style.content} as any);
errors.push(...s.errors);
console.log('s', s);
return s.code;
});

Expand Down
88 changes: 84 additions & 4 deletions packages/Graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<template>
<div>
<component
:is="graphPresentationComponent"
v-if="graphSnapshot && presentation"
:graph="graphSnapshot"
/>
<component
v-for="(style, index) in styles"
:is="'style'"
v-if="graphSnapshot && presentation"
v-html="style"
:key="index"
/>
<div
x-graph-canvas
:style="graphCanvasStyle"
v-if="graphSnapshot"
v-if="graphSnapshot && !presentation"
:key="graphUpdateVersion"
@drop="drop($event)"
@dragover="dragOver($event)"
Expand All @@ -20,7 +32,7 @@
:node="c.node"
/>
<node
v-for="node in graphSnapshot.nodes"
v-for="node in sortedNodes"
:key="node.id + graphUpdateVersion"
:node="node"
:graph="graphSnapshot"
Expand All @@ -29,18 +41,44 @@
<div v-if="selectionRect.visible && !presentation" class="selection-rect" :style="selectionRectStyle"></div>
<div v-if="selectedNodes.length !== 0 && !presentation" class="bounding-rect" :style="boundingRectStyle"></div>
</div>
<keep-alive>
<div style="position: fixed; top: 33px;left: 10px;" v-if="showGraphCodeEditor" v-show="!presentation">
<monaco-code-editor
style="opacity: 0.98"
templateType="vue"
language="html"
:graphId="graphSnapshot.id"
:errors="errors.filter(e => e.type === 'graph')"
:value="graphTemplateValue"
helpLink="https://plastic-io.github.io/plastic-io/interfaces/NodeInterface.html"
@close="showGraphCodeEditor = false"
@dirty="setIsDirty = $event"
@save="saveGraphTemplate($event)"
/>
</div>
</keep-alive>
<div class="graph-errors" v-if="errors.length > 0">
<v-alert color="error" @click="showGraphCodeEditor = true">
<pre v-for="error in errors">{{error}}</pre>
</v-alert>
</div>
</div>
</template>
<script lang="ts">
import {markRaw} from "vue";
import {mapWritableState, mapActions} from "pinia";
import {useStore as useOrchestratorStore} from "@plastic-io/graph-editor-vue3-orchestrator";
import {useStore as useGraphStore} from "./store";
import compileTemplate from "@plastic-io/graph-editor-vue3-compile-template";
import {useStore as usePreferencesStore} from "@plastic-io/graph-editor-vue3-preferences-provider";
import {useStore as useOrchestratorStore} from "@plastic-io/graph-editor-vue3-orchestrator";
import colors from "vuetify/lib/util/colors";
export default {
name: 'graph-canvas',
data: () => {
return {
compiledTemplate: null,
errors: [],
styles: [],
innerHeight: 0,
innerWidth: 0,
positionLocationSaveTimeout: 750,
Expand All @@ -49,6 +87,9 @@ export default {
}
},
watch: {
'graphSnapshot.properties.template'() {
this.loadTemplate();
},
graphSnapshot: {
handler() {
// force updates in rewind mode
Expand All @@ -75,7 +116,22 @@ export default {
methods: {
...mapActions(useGraphStore, [
'drop',
'updateGraphFromSnapshot',
]),
async loadTemplate() {
const comp = await compileTemplate(this, this.graphSnapshot.id,
this.graphSnapshot.properties.template);
this.compiledTemplate = markRaw(comp);
this.errors = comp.errors;
this.styles = this.compiledTemplate.styles;
this.errors.forEach((err) => {
useOrchestratorStore().raiseError(this.graphSnapshot.id, err, 'vue');
});
},
async saveGraphTemplate(val) {
this.graphSnapshot.properties.template = val;
await this.updateGraphFromSnapshot('Update Graph Presentation Template');
},
dragOver(e) {
e.preventDefault();
e.dataTransfer.dropEffect = "link";
Expand All @@ -91,7 +147,7 @@ export default {
});
},
},
mounted() {
async mounted() {
const resize = () => {
this.innerWidth = window.innerWidth;
this.innerHeight = window.innerHeight;
Expand All @@ -103,6 +159,10 @@ export default {
this.view = view;
document.addEventListener('resize', resize);
resize();
if (!this.graphSnapshot.properties.template) {
this.graphSnapshot.properties.template = this.preferences!.defaultNewGraphTemplate;
}
await this.loadTemplate();
},
computed: {
...mapWritableState(usePreferencesStore, ['preferences']),
Expand All @@ -118,7 +178,20 @@ export default {
'boundingRect',
'presentation',
'inRewindMode',
'showGraphCodeEditor',
]),
graphPresentationComponent() {
return this.compiledTemplate ? this.compiledTemplate.component : 'div';
},
sortedNodes() {
return this.graphSnapshot.nodes.sort((a, b) => {
return (a.properties.presentation.sort || 0)
- (b.properties.presentation.sort || 0);
});
},
graphTemplateValue() {
return this.graphSnapshot.properties.template;
},
connectors: function () {
let connectors = [];
this.graphSnapshot.nodes.forEach((node) => {
Expand Down Expand Up @@ -228,4 +301,11 @@ export default {
100px 100px,
100px 100px;
}
.graph-errors {
position: fixed;
right: 10px;
top: 33px;
width: 33%;
min-width: 500px;
}
</style>
1 change: 0 additions & 1 deletion packages/Graph/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {Graph, Node} from "@plastic-io/plastic-io";
import JSZip from 'jszip';
import {newId} from "@plastic-io/graph-editor-vue3-utils";
export default {
async unzip(file: any, fileName: string): Promise<any> {
Expand Down
2 changes: 2 additions & 0 deletions packages/Graph/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ export default {
width: 300,
timeout: 30000,
logLevel: 2,
template: this.preferencesStore.preferences!.defaultNewGraphTemplate,
} as any
};
},
Expand Down Expand Up @@ -691,6 +692,7 @@ export default {
x: pos.x,
y: pos.y,
z: 0 + this.preferencesStore.preferences!.newNodeOffset.z,
order: this.graphSnapshot.nodes.length,
},
},
template: {
Expand Down
1 change: 1 addition & 0 deletions packages/Graph/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default () => {
graphSnapshotStore: useGraphSnapshotStore(),
graphSnapshot: null as any,
updatingSnapshotLocally: false,
showGraphCodeEditor: false,
isNewGraph: false,
rewindVersion: 0,
keys: {} as Record<string, string>,
Expand Down
23 changes: 23 additions & 0 deletions packages/GraphPropertiesPanel/GraphCodeMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<v-icon
title="Edit Graph Presentation Code"
@click="showGraphCodeEditor = !showGraphCodeEditor"
help-topic="toggleShowGraphCode"
:color="showGraphCodeEditor ? 'info' : ''"
class="mx-2"
style="cursor: pointer;"
>mdi-vuejs</v-icon>
</template>
<script lang="ts">
import {mapWritableState, mapActions, mapState} from "pinia";
import {useStore as useGraphStore} from "@plastic-io/graph-editor-vue3-graph";
export default {
name: 'graph-properties-menu',
computed: {
...mapWritableState(useGraphStore, [
'showGraphCodeEditor',
]),
}
}
</script>
2 changes: 1 addition & 1 deletion packages/GraphPropertiesPanel/GraphPropertiesMenu.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-menu>
<template v-slot:activator="{props}">
<v-icon icon="mdi-graph" v-bind="props" class="ma-2"/>
<v-icon help-topic="graphProperties" icon="mdi-vector-polyline-edit" v-bind="props" class="ma-2"/>
</template>
<graph-properties @click.stop @mousemove.stop/>
</v-menu>
Expand Down
16 changes: 13 additions & 3 deletions packages/GraphPropertiesPanel/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ import type {App} from "vue";
import type {Router} from "vue-router";
import _GraphProperties from "./GraphProperties.vue";
import GraphPropertiesMenu from "./GraphPropertiesMenu.vue";
import GraphCodeMenu from "./GraphCodeMenu.vue";
import EditorModule, {Plugin} from "@plastic-io/graph-editor-vue3-editor-module";
import {useStore as useOrchestratorStore} from "@plastic-io/graph-editor-vue3-orchestrator";
export default class GraphProperties extends EditorModule {
constructor(config: Record<string, any>, app: App<Element>, hostRouter: Router) {
super();
app.component('graph-properties', _GraphProperties);
app.component('graph-properties-menu', GraphPropertiesMenu);
app.component('graph-code-menu', GraphCodeMenu);
const graphOrchestratorStore = useOrchestratorStore();

const plugin = new Plugin({
graphOrchestratorStore.addPlugin({
name: 'GraphPropertiesMenu',
title: 'Graph Properties',
component: 'graph-properties-menu',
divider: true,
helpTopic: 'graphProperties',
type: 'system-bar-bottom',
order: 3,
order: -1,
});

graphOrchestratorStore.addPlugin(plugin);
graphOrchestratorStore.addPlugin({
name: 'GraphCodeMenu',
title: 'Graph Code',
component: 'graph-code-menu',
divider: true,
helpTopic: 'graphCode',
type: 'system-bar-bottom',
order: 0,
});

}
};
Loading

0 comments on commit ced0660

Please sign in to comment.