Spaces:
Running
Running
More CRDT work. I fail to hook up the nodes/edges stores to the synced store.
Browse files- web/src/LynxKiteFlow.svelte +44 -15
web/src/LynxKiteFlow.svelte
CHANGED
@@ -32,18 +32,15 @@
|
|
32 |
|
33 |
function getCRDTStore(path) {
|
34 |
const sstore = syncedStore({ workspace: {} });
|
35 |
-
console.log('ss', sstore.workspace);
|
36 |
const doc = getYjsDoc(sstore);
|
37 |
-
console.log('doc', doc.toJSON());
|
38 |
const wsProvider = new WebsocketProvider("ws://localhost:8000/ws/crdt", path, doc);
|
39 |
wsProvider.on('sync', function(isSynced: boolean) {
|
40 |
console.log('synced', isSynced, 'ydoc', doc.toJSON());
|
41 |
});
|
42 |
-
return {store: svelteSyncedStore(sstore), doc};
|
43 |
}
|
44 |
$: connection = getCRDTStore(path);
|
45 |
$: store = connection.store;
|
46 |
-
$: ws = connection.doc?.getMap('workspace');
|
47 |
|
48 |
export let path = '';
|
49 |
|
@@ -58,6 +55,31 @@
|
|
58 |
area: NodeWithArea,
|
59 |
};
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
function closeNodeSearch() {
|
62 |
nodeSearchSettings = undefined;
|
63 |
}
|
@@ -69,12 +91,14 @@
|
|
69 |
event.preventDefault();
|
70 |
nodeSearchSettings = {
|
71 |
pos: { x: event.clientX, y: event.clientY },
|
72 |
-
boxes: $catalog.data[
|
73 |
};
|
74 |
}
|
75 |
function addNode(e) {
|
76 |
const meta = {...e.detail};
|
77 |
-
|
|
|
|
|
78 |
const node = {
|
79 |
type: meta.type,
|
80 |
data: {
|
@@ -88,17 +112,18 @@
|
|
88 |
const title = node.data.title;
|
89 |
let i = 1;
|
90 |
node.id = `${title} ${i}`;
|
91 |
-
|
|
|
92 |
i += 1;
|
93 |
node.id = `${title} ${i}`;
|
94 |
}
|
95 |
node.parentId = nodeSearchSettings.parentId;
|
96 |
if (node.parentId) {
|
97 |
node.extent = 'parent';
|
98 |
-
const parent =
|
99 |
node.position = { x: node.position.x - parent.position.x, y: node.position.y - parent.position.y };
|
100 |
}
|
101 |
-
return
|
102 |
});
|
103 |
closeNodeSearch();
|
104 |
}
|
@@ -128,15 +153,19 @@
|
|
128 |
};
|
129 |
}
|
130 |
$: parentDir = path.split('/').slice(0, -1).join('/');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
</script>
|
133 |
|
134 |
<div class="page">
|
135 |
-
<br>
|
136 |
-
|
137 |
-
<br>ws: {connection.doc?.getMap("workspace")}
|
138 |
-
{#if ws !== undefined}
|
139 |
-
{{ws}}
|
140 |
<div class="top-bar">
|
141 |
<div class="ws-name">
|
142 |
<a href><img src="/favicon.ico"></a>
|
@@ -157,7 +186,7 @@
|
|
157 |
</div>
|
158 |
</div>
|
159 |
<div style:height="100%">
|
160 |
-
<SvelteFlow
|
161 |
on:paneclick={toggleNodeSearch}
|
162 |
on:nodeclick={nodeClick}
|
163 |
proOptions={{ hideAttribution: true }}
|
|
|
32 |
|
33 |
function getCRDTStore(path) {
|
34 |
const sstore = syncedStore({ workspace: {} });
|
|
|
35 |
const doc = getYjsDoc(sstore);
|
|
|
36 |
const wsProvider = new WebsocketProvider("ws://localhost:8000/ws/crdt", path, doc);
|
37 |
wsProvider.on('sync', function(isSynced: boolean) {
|
38 |
console.log('synced', isSynced, 'ydoc', doc.toJSON());
|
39 |
});
|
40 |
+
return {store: svelteSyncedStore(sstore), sstore, doc};
|
41 |
}
|
42 |
$: connection = getCRDTStore(path);
|
43 |
$: store = connection.store;
|
|
|
44 |
|
45 |
export let path = '';
|
46 |
|
|
|
55 |
area: NodeWithArea,
|
56 |
};
|
57 |
|
58 |
+
function substore(store, field) {
|
59 |
+
if (!store) return;
|
60 |
+
const ss = derived(store, (store) => store.workspace[field]?.value);
|
61 |
+
ss.set = (value) => {
|
62 |
+
console.log('set called', field, value);
|
63 |
+
$store.workspace[field] = value;
|
64 |
+
};
|
65 |
+
ss.update = (fn) => {
|
66 |
+
console.log('update called', field);
|
67 |
+
console.log(JSON.stringify($store));
|
68 |
+
console.log(JSON.stringify($store.workspace.nodes));
|
69 |
+
const before = $store.workspace[field];
|
70 |
+
console.log({before});
|
71 |
+
const after = fn(before);
|
72 |
+
console.log({after});
|
73 |
+
$store.workspace[field] = after;
|
74 |
+
};
|
75 |
+
return ss;
|
76 |
+
}
|
77 |
+
$: nodes = substore(store, 'nodes');
|
78 |
+
$: edges = substore(store, 'edges');
|
79 |
+
|
80 |
+
// const nodes = writable<Node[]>([]);
|
81 |
+
// const edges = writable<Edge[]>([]);
|
82 |
+
|
83 |
function closeNodeSearch() {
|
84 |
nodeSearchSettings = undefined;
|
85 |
}
|
|
|
91 |
event.preventDefault();
|
92 |
nodeSearchSettings = {
|
93 |
pos: { x: event.clientX, y: event.clientY },
|
94 |
+
boxes: $catalog.data[$store.workspace.env],
|
95 |
};
|
96 |
}
|
97 |
function addNode(e) {
|
98 |
const meta = {...e.detail};
|
99 |
+
console.log(store);
|
100 |
+
nodes.update((nodes) => {
|
101 |
+
console.log({v: nodes});
|
102 |
const node = {
|
103 |
type: meta.type,
|
104 |
data: {
|
|
|
112 |
const title = node.data.title;
|
113 |
let i = 1;
|
114 |
node.id = `${title} ${i}`;
|
115 |
+
console.log({nodes})
|
116 |
+
while (nodes.find((x) => x.id === node.id)) {
|
117 |
i += 1;
|
118 |
node.id = `${title} ${i}`;
|
119 |
}
|
120 |
node.parentId = nodeSearchSettings.parentId;
|
121 |
if (node.parentId) {
|
122 |
node.extent = 'parent';
|
123 |
+
const parent = nodes.find((x) => x.id === node.parentId);
|
124 |
node.position = { x: node.position.x - parent.position.x, y: node.position.y - parent.position.y };
|
125 |
}
|
126 |
+
return [...nodes, node];
|
127 |
});
|
128 |
closeNodeSearch();
|
129 |
}
|
|
|
153 |
};
|
154 |
}
|
155 |
$: parentDir = path.split('/').slice(0, -1).join('/');
|
156 |
+
$: console.log($store);
|
157 |
+
// <br>{JSON.stringify($store)}
|
158 |
+
// <br>{JSON.stringify($store?.workspace)}
|
159 |
+
// <br>{JSON.stringify($store?.workspace?.nodes)}
|
160 |
+
// <br>{JSON.stringify($store?.workspace?.nodes?.value)}
|
161 |
+
// <br>{$store.workspace?.nodes?.toArray()}
|
162 |
+
// <br>{$store.workspace?.nodes?.length}
|
163 |
|
164 |
</script>
|
165 |
|
166 |
<div class="page">
|
167 |
+
<br>{JSON.stringify($store)}
|
168 |
+
{#if $store.workspace !== undefined}
|
|
|
|
|
|
|
169 |
<div class="top-bar">
|
170 |
<div class="ws-name">
|
171 |
<a href><img src="/favicon.ico"></a>
|
|
|
186 |
</div>
|
187 |
</div>
|
188 |
<div style:height="100%">
|
189 |
+
<SvelteFlow {nodes} {edges} {nodeTypes} fitView
|
190 |
on:paneclick={toggleNodeSearch}
|
191 |
on:nodeclick={nodeClick}
|
192 |
proOptions={{ hideAttribution: true }}
|