f1ow 1.1.0 → 1.1.1
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.
- package/dist/f1ow-collaboration.js +1894 -3095
- package/dist/f1ow.js +8929 -13465
- package/dist/f1ow.umd.cjs +101 -17767
- package/dist/syncBridge-BBEfPdNb.js +254 -0
- package/dist/yjsProvider-CXmqUJXr.js +72 -0
- package/package.json +1 -1
- package/dist/syncBridge-CveP4QyQ.js +0 -428
- package/dist/yjsProvider-mWrSFiNG.js +0 -100
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import * as A from "yjs";
|
|
2
|
+
import { useCanvasStore as w } from "./f1ow.js";
|
|
3
|
+
import { getYElements as _, getYDoc as W } from "./yjsProvider-CXmqUJXr.js";
|
|
4
|
+
const R = [
|
|
5
|
+
"id",
|
|
6
|
+
"type",
|
|
7
|
+
"x",
|
|
8
|
+
"y",
|
|
9
|
+
"width",
|
|
10
|
+
"height",
|
|
11
|
+
"rotation",
|
|
12
|
+
"isLocked",
|
|
13
|
+
"isVisible",
|
|
14
|
+
"sortOrder",
|
|
15
|
+
"version"
|
|
16
|
+
], T = [
|
|
17
|
+
"strokeColor",
|
|
18
|
+
"fillColor",
|
|
19
|
+
"strokeWidth",
|
|
20
|
+
"opacity",
|
|
21
|
+
"strokeStyle",
|
|
22
|
+
"roughness",
|
|
23
|
+
"fontSize",
|
|
24
|
+
"fontFamily"
|
|
25
|
+
];
|
|
26
|
+
function B(t, e) {
|
|
27
|
+
const s = t;
|
|
28
|
+
for (const i of R) {
|
|
29
|
+
const r = s[i];
|
|
30
|
+
r !== void 0 && e.set(i, r);
|
|
31
|
+
}
|
|
32
|
+
if (t.style)
|
|
33
|
+
for (const i of T)
|
|
34
|
+
e.set(`style.${i}`, t.style[i]);
|
|
35
|
+
switch (t.boundElements ? e.set("boundElements", JSON.stringify(t.boundElements)) : e.set("boundElements", null), t.ports && e.set("ports", JSON.stringify(t.ports)), "lineStyle" in t && t.lineStyle && e.set("lineStyle", JSON.stringify(t.lineStyle)), t.ports && e.set("ports", JSON.stringify(t.ports)), "lineStyle" in t && t.lineStyle && e.set("lineStyle", JSON.stringify(t.lineStyle)), t.groupIds && e.set("groupIds", JSON.stringify(t.groupIds)), t.type) {
|
|
36
|
+
case "rectangle":
|
|
37
|
+
e.set("cornerRadius", t.cornerRadius);
|
|
38
|
+
break;
|
|
39
|
+
case "line":
|
|
40
|
+
case "arrow":
|
|
41
|
+
e.set("points", JSON.stringify(t.points)), e.set("lineType", t.lineType), t.curvature !== void 0 && e.set("curvature", t.curvature), e.set("startBinding", t.startBinding ? JSON.stringify(t.startBinding) : null), e.set("endBinding", t.endBinding ? JSON.stringify(t.endBinding) : null), t.type === "arrow" && (e.set("startArrowhead", t.startArrowhead), e.set("endArrowhead", t.endArrowhead));
|
|
42
|
+
break;
|
|
43
|
+
case "freedraw":
|
|
44
|
+
e.set("points", JSON.stringify(t.points));
|
|
45
|
+
break;
|
|
46
|
+
case "text":
|
|
47
|
+
e.set("text", t.text), e.set("containerId", t.containerId), e.set("textAlign", t.textAlign), e.set("verticalAlign", t.verticalAlign);
|
|
48
|
+
break;
|
|
49
|
+
case "image":
|
|
50
|
+
e.set("src", t.src), e.set("naturalWidth", t.naturalWidth), e.set("naturalHeight", t.naturalHeight), e.set("scaleMode", t.scaleMode), e.set("crop", t.crop ? JSON.stringify(t.crop) : null), e.set("cornerRadius", t.cornerRadius), e.set("alt", t.alt);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function E(t) {
|
|
55
|
+
const e = t.get("type"), s = t.get("id");
|
|
56
|
+
if (!e || !s) return null;
|
|
57
|
+
const i = {};
|
|
58
|
+
for (const n of T) {
|
|
59
|
+
const h = t.get(`style.${n}`);
|
|
60
|
+
h !== void 0 && (i[n] = h);
|
|
61
|
+
}
|
|
62
|
+
const r = {
|
|
63
|
+
id: s,
|
|
64
|
+
type: e,
|
|
65
|
+
x: t.get("x") ?? 0,
|
|
66
|
+
y: t.get("y") ?? 0,
|
|
67
|
+
width: t.get("width") ?? 100,
|
|
68
|
+
height: t.get("height") ?? 100,
|
|
69
|
+
rotation: t.get("rotation") ?? 0,
|
|
70
|
+
isLocked: t.get("isLocked") ?? !1,
|
|
71
|
+
isVisible: t.get("isVisible") ?? !0,
|
|
72
|
+
version: t.get("version") ?? 0,
|
|
73
|
+
style: i,
|
|
74
|
+
boundElements: u(t.get("boundElements")) ?? null,
|
|
75
|
+
groupIds: u(t.get("groupIds")) ?? void 0,
|
|
76
|
+
sortOrder: t.get("sortOrder") ?? void 0,
|
|
77
|
+
ports: u(t.get("ports")) ?? void 0
|
|
78
|
+
};
|
|
79
|
+
switch (e) {
|
|
80
|
+
case "rectangle":
|
|
81
|
+
r.cornerRadius = t.get("cornerRadius") ?? 0;
|
|
82
|
+
break;
|
|
83
|
+
case "line":
|
|
84
|
+
case "arrow":
|
|
85
|
+
r.points = u(t.get("points")) ?? [0, 0, 100, 0], r.lineType = t.get("lineType") ?? "sharp", r.curvature = t.get("curvature") ?? void 0, r.startBinding = u(t.get("startBinding")), r.endBinding = u(t.get("endBinding")), e === "arrow" && (r.startArrowhead = t.get("startArrowhead") ?? null, r.endArrowhead = t.get("endArrowhead") ?? "arrow");
|
|
86
|
+
{
|
|
87
|
+
const n = u(t.get("lineStyle"));
|
|
88
|
+
n && (r.lineStyle = n);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case "freedraw":
|
|
92
|
+
r.points = u(t.get("points")) ?? [];
|
|
93
|
+
break;
|
|
94
|
+
case "text":
|
|
95
|
+
r.text = t.get("text") ?? "", r.containerId = t.get("containerId") ?? null, r.textAlign = t.get("textAlign") ?? "center", r.verticalAlign = t.get("verticalAlign") ?? "middle";
|
|
96
|
+
break;
|
|
97
|
+
case "image":
|
|
98
|
+
r.src = t.get("src") ?? "", r.naturalWidth = t.get("naturalWidth") ?? 0, r.naturalHeight = t.get("naturalHeight") ?? 0, r.scaleMode = t.get("scaleMode") ?? "fit", r.crop = u(t.get("crop")) ?? null, r.cornerRadius = t.get("cornerRadius") ?? 0, r.alt = t.get("alt") ?? "";
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
return r;
|
|
102
|
+
}
|
|
103
|
+
function u(t) {
|
|
104
|
+
if (t == null) return null;
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(t);
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
let m = !1, S = !1, x = null, J = null, O = null, a = [];
|
|
112
|
+
function $(t = 50) {
|
|
113
|
+
const e = W(), s = _();
|
|
114
|
+
if (!e || !s)
|
|
115
|
+
return;
|
|
116
|
+
if (H(), s.size > 0) {
|
|
117
|
+
m = !0;
|
|
118
|
+
const o = C(s);
|
|
119
|
+
w.getState().setElements(o), a = o, m = !1;
|
|
120
|
+
} else {
|
|
121
|
+
const o = w.getState().elements;
|
|
122
|
+
o.length > 0 && (S = !0, e.transact(() => {
|
|
123
|
+
for (const l of o) {
|
|
124
|
+
const c = new A.Map();
|
|
125
|
+
B(l, c), s.set(l.id, c);
|
|
126
|
+
}
|
|
127
|
+
}, "local-init"), S = !1), a = o;
|
|
128
|
+
}
|
|
129
|
+
const i = (o, l) => {
|
|
130
|
+
if (l.origin === "local-sync" || l.origin === "local-init" || S) return;
|
|
131
|
+
m = !0;
|
|
132
|
+
const c = w.getState();
|
|
133
|
+
let d = [...a], v = !1;
|
|
134
|
+
for (const [f, g] of o.keys)
|
|
135
|
+
if (g.action === "add" || g.action === "update") {
|
|
136
|
+
const b = s.get(f);
|
|
137
|
+
if (b) {
|
|
138
|
+
const k = E(b);
|
|
139
|
+
if (k) {
|
|
140
|
+
const N = d.findIndex((I) => I.id === f);
|
|
141
|
+
N >= 0 ? d[N] = k : d.push(k), v = !0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else g.action === "delete" && (d = d.filter((b) => b.id !== f), v = !0);
|
|
145
|
+
v && (d.sort((f, g) => f.sortOrder && g.sortOrder ? f.sortOrder < g.sortOrder ? -1 : f.sortOrder > g.sortOrder ? 1 : 0 : 0), c.setElements(d), a = d), m = !1;
|
|
146
|
+
};
|
|
147
|
+
let r = null;
|
|
148
|
+
const n = /* @__PURE__ */ new Set(), h = (o) => {
|
|
149
|
+
if (!S) {
|
|
150
|
+
for (const l of o) {
|
|
151
|
+
let c = l.target;
|
|
152
|
+
for (; c && !(c instanceof A.Map && c.parent === s); )
|
|
153
|
+
c = c.parent;
|
|
154
|
+
if (c instanceof A.Map) {
|
|
155
|
+
const d = c.get("id");
|
|
156
|
+
d && n.add(d);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
r && clearTimeout(r), r = setTimeout(() => {
|
|
160
|
+
if (n.size === 0 || S) return;
|
|
161
|
+
m = !0;
|
|
162
|
+
let l = [...a], c = !1;
|
|
163
|
+
for (const d of n) {
|
|
164
|
+
const v = s.get(d);
|
|
165
|
+
if (!v) continue;
|
|
166
|
+
const f = E(v);
|
|
167
|
+
if (!f) continue;
|
|
168
|
+
const g = l.findIndex((b) => b.id === d);
|
|
169
|
+
g >= 0 && (l[g] = f, c = !0);
|
|
170
|
+
}
|
|
171
|
+
n.clear(), c && (w.getState().setElements(l), a = l), m = !1;
|
|
172
|
+
}, 16);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
s.observe(i), s.observeDeep(h), J = () => {
|
|
176
|
+
s.unobserve(i), s.unobserveDeep(h), r && clearTimeout(r), n.clear();
|
|
177
|
+
}, x = w.subscribe(
|
|
178
|
+
(o) => {
|
|
179
|
+
m || o.elements !== a && (O && clearTimeout(O), O = setTimeout(() => {
|
|
180
|
+
L(o.elements, s, e);
|
|
181
|
+
}, t));
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
function H() {
|
|
186
|
+
x && (x(), x = null), J && (J(), J = null), O && (clearTimeout(O), O = null), a = [];
|
|
187
|
+
}
|
|
188
|
+
function L(t, e, s) {
|
|
189
|
+
S = !0, a = t;
|
|
190
|
+
const i = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const r of t)
|
|
192
|
+
i.set(r.id, r);
|
|
193
|
+
s.transact(() => {
|
|
194
|
+
for (const [r] of e.entries())
|
|
195
|
+
i.has(r) || e.delete(r);
|
|
196
|
+
for (const r of t) {
|
|
197
|
+
let n = e.get(r.id);
|
|
198
|
+
n ? Y(r, n) : (n = new A.Map(), B(r, n), e.set(r.id, n));
|
|
199
|
+
}
|
|
200
|
+
}, "local-sync"), S = !1;
|
|
201
|
+
}
|
|
202
|
+
function Y(t, e) {
|
|
203
|
+
const s = t;
|
|
204
|
+
for (const r of R) {
|
|
205
|
+
const n = s[r];
|
|
206
|
+
n !== e.get(r) && e.set(r, n);
|
|
207
|
+
}
|
|
208
|
+
if (t.style)
|
|
209
|
+
for (const r of T) {
|
|
210
|
+
const n = t.style[r];
|
|
211
|
+
n !== e.get(`style.${r}`) && e.set(`style.${r}`, n);
|
|
212
|
+
}
|
|
213
|
+
const i = t.boundElements ? JSON.stringify(t.boundElements) : null;
|
|
214
|
+
switch (i !== e.get("boundElements") && e.set("boundElements", i), t.type) {
|
|
215
|
+
case "rectangle":
|
|
216
|
+
t.cornerRadius !== e.get("cornerRadius") && e.set("cornerRadius", t.cornerRadius);
|
|
217
|
+
break;
|
|
218
|
+
case "line":
|
|
219
|
+
case "arrow": {
|
|
220
|
+
const n = JSON.stringify(t.points);
|
|
221
|
+
n !== e.get("points") && e.set("points", n), t.lineType !== e.get("lineType") && e.set("lineType", t.lineType), t.curvature !== e.get("curvature") && e.set("curvature", t.curvature);
|
|
222
|
+
const h = t.startBinding ? JSON.stringify(t.startBinding) : null;
|
|
223
|
+
h !== e.get("startBinding") && e.set("startBinding", h);
|
|
224
|
+
const o = t.endBinding ? JSON.stringify(t.endBinding) : null;
|
|
225
|
+
o !== e.get("endBinding") && e.set("endBinding", o), t.type === "arrow" && (t.startArrowhead !== e.get("startArrowhead") && e.set("startArrowhead", t.startArrowhead), t.endArrowhead !== e.get("endArrowhead") && e.set("endArrowhead", t.endArrowhead));
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case "freedraw": {
|
|
229
|
+
const n = JSON.stringify(t.points);
|
|
230
|
+
n !== e.get("points") && e.set("points", n);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "text":
|
|
234
|
+
t.text !== e.get("text") && e.set("text", t.text), t.containerId !== e.get("containerId") && e.set("containerId", t.containerId), t.textAlign !== e.get("textAlign") && e.set("textAlign", t.textAlign), t.verticalAlign !== e.get("verticalAlign") && e.set("verticalAlign", t.verticalAlign);
|
|
235
|
+
break;
|
|
236
|
+
case "image":
|
|
237
|
+
t.src !== e.get("src") && e.set("src", t.src), t.naturalWidth !== e.get("naturalWidth") && e.set("naturalWidth", t.naturalWidth), t.naturalHeight !== e.get("naturalHeight") && e.set("naturalHeight", t.naturalHeight), t.scaleMode !== e.get("scaleMode") && e.set("scaleMode", t.scaleMode);
|
|
238
|
+
const r = t.crop ? JSON.stringify(t.crop) : null;
|
|
239
|
+
r !== e.get("crop") && e.set("crop", r), t.cornerRadius !== e.get("cornerRadius") && e.set("cornerRadius", t.cornerRadius), t.alt !== e.get("alt") && e.set("alt", t.alt);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function C(t) {
|
|
244
|
+
const e = [];
|
|
245
|
+
for (const [, s] of t.entries()) {
|
|
246
|
+
const i = E(s);
|
|
247
|
+
i && e.push(i);
|
|
248
|
+
}
|
|
249
|
+
return e.sort((s, i) => s.sortOrder && i.sortOrder ? s.sortOrder < i.sortOrder ? -1 : s.sortOrder > i.sortOrder ? 1 : 0 : 0), e;
|
|
250
|
+
}
|
|
251
|
+
export {
|
|
252
|
+
$ as startSync,
|
|
253
|
+
H as stopSync
|
|
254
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as c from "yjs";
|
|
2
|
+
import { WebsocketProvider as i } from "y-websocket";
|
|
3
|
+
let n = null, e = null, u = null, l = /* @__PURE__ */ new Set();
|
|
4
|
+
function w(t) {
|
|
5
|
+
return e && d(), u = t, n = new c.Doc(), e = new i(
|
|
6
|
+
t.serverUrl,
|
|
7
|
+
t.roomName,
|
|
8
|
+
n,
|
|
9
|
+
{
|
|
10
|
+
connect: !0,
|
|
11
|
+
params: t.authToken ? { token: t.authToken } : void 0
|
|
12
|
+
}
|
|
13
|
+
), e.awareness.setLocalState({
|
|
14
|
+
user: t.user,
|
|
15
|
+
cursor: null,
|
|
16
|
+
selectedIds: []
|
|
17
|
+
}), e.on("status", (r) => {
|
|
18
|
+
const o = r.status;
|
|
19
|
+
for (const s of l)
|
|
20
|
+
s(o);
|
|
21
|
+
}), { doc: n, provider: e };
|
|
22
|
+
}
|
|
23
|
+
function d() {
|
|
24
|
+
e && (e.awareness.setLocalState(null), e.disconnect(), e.destroy(), e = null), n && (n.destroy(), n = null), u = null;
|
|
25
|
+
}
|
|
26
|
+
function m() {
|
|
27
|
+
return n;
|
|
28
|
+
}
|
|
29
|
+
function p() {
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
function v() {
|
|
33
|
+
return n?.getMap("elements");
|
|
34
|
+
}
|
|
35
|
+
function S() {
|
|
36
|
+
return u;
|
|
37
|
+
}
|
|
38
|
+
function g() {
|
|
39
|
+
return e !== null && e.wsconnected;
|
|
40
|
+
}
|
|
41
|
+
function C(t) {
|
|
42
|
+
return l.add(t), () => {
|
|
43
|
+
l.delete(t);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function b(t) {
|
|
47
|
+
if (!e) return;
|
|
48
|
+
const r = e.awareness.getLocalState();
|
|
49
|
+
e.awareness.setLocalState({
|
|
50
|
+
...r,
|
|
51
|
+
...t
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function L() {
|
|
55
|
+
if (!e) return /* @__PURE__ */ new Map();
|
|
56
|
+
const t = e.awareness.getStates(), r = e.awareness.clientID, o = /* @__PURE__ */ new Map();
|
|
57
|
+
for (const [s, a] of t)
|
|
58
|
+
s !== r && a && a.user && o.set(s, a);
|
|
59
|
+
return o;
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
w as createCollaborationProvider,
|
|
63
|
+
d as destroyCollaborationProvider,
|
|
64
|
+
S as getCollaborationConfig,
|
|
65
|
+
L as getRemoteAwareness,
|
|
66
|
+
m as getYDoc,
|
|
67
|
+
v as getYElements,
|
|
68
|
+
p as getYProvider,
|
|
69
|
+
g as isCollaborationActive,
|
|
70
|
+
C as onStatusChange,
|
|
71
|
+
b as updateAwareness
|
|
72
|
+
};
|
package/package.json
CHANGED