@inditextech/weave-react 0.77.0 → 1.0.0
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/package.json +4 -3
- package/dist/react.cjs +0 -387
- package/dist/react.d.cts +0 -133
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inditextech/weave-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"link": "npm link",
|
|
33
33
|
"lint:fix": "npm run lint -- --fix",
|
|
34
34
|
"lint": "eslint ./src",
|
|
35
|
+
"pack": "npm pack",
|
|
35
36
|
"publish:snapshot": "npm publish",
|
|
36
37
|
"release:perform": "npm publish --access public",
|
|
37
38
|
"release:prepare": "npm run verify",
|
|
@@ -44,11 +45,11 @@
|
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
47
|
"@syncedstore/core": "0.6.0",
|
|
47
|
-
"konva": "
|
|
48
|
+
"konva": "10.0.2",
|
|
48
49
|
"yjs": "13.6.27"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@inditextech/weave-sdk": "0.
|
|
52
|
+
"@inditextech/weave-sdk": "1.0.0",
|
|
52
53
|
"@types/node": "^22.15.3",
|
|
53
54
|
"@typescript-eslint/eslint-plugin": "8.26.0",
|
|
54
55
|
"@typescript-eslint/parser": "8.26.0",
|
package/dist/react.cjs
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//#region rolldown:runtime
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
const react = __toESM(require("react"));
|
|
26
|
-
const __inditextech_weave_sdk = __toESM(require("@inditextech/weave-sdk"));
|
|
27
|
-
require("konva");
|
|
28
|
-
require("yjs");
|
|
29
|
-
|
|
30
|
-
//#region ../types/dist/types.js
|
|
31
|
-
const WEAVE_INSTANCE_STATUS = {
|
|
32
|
-
["IDLE"]: "idle",
|
|
33
|
-
["STARTING"]: "starting",
|
|
34
|
-
["LOADING_FONTS"]: "loadingFonts",
|
|
35
|
-
["CONNECTING_TO_ROOM"]: "connectingToRoom",
|
|
36
|
-
["CONNECTING_ERROR"]: "connectingError",
|
|
37
|
-
["LOADING_ROOM"]: "loadingRoom",
|
|
38
|
-
["RUNNING"]: "running"
|
|
39
|
-
};
|
|
40
|
-
const WEAVE_TRANSFORMER_ANCHORS = {
|
|
41
|
-
["TOP_LEFT"]: "top-left",
|
|
42
|
-
["TOP_CENTER"]: "top-center",
|
|
43
|
-
["TOP_RIGHT"]: "top-right",
|
|
44
|
-
["MIDDLE_RIGHT"]: "middle-right",
|
|
45
|
-
["MIDDLE_LEFT"]: "middle-left",
|
|
46
|
-
["BOTTOM_LEFT"]: "bottom-left",
|
|
47
|
-
["BOTTOM_CENTER"]: "bottom-center",
|
|
48
|
-
["BOTTOM_RIGHT"]: "bottom-right"
|
|
49
|
-
};
|
|
50
|
-
const WEAVE_DEFAULT_ENABLED_ANCHORS = Object.values(WEAVE_TRANSFORMER_ANCHORS);
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region ../../node_modules/zustand/esm/vanilla.mjs
|
|
54
|
-
const createStoreImpl = (createState) => {
|
|
55
|
-
let state;
|
|
56
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
57
|
-
const setState = (partial, replace) => {
|
|
58
|
-
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
59
|
-
if (!Object.is(nextState, state)) {
|
|
60
|
-
const previousState = state;
|
|
61
|
-
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
62
|
-
listeners.forEach((listener) => listener(state, previousState));
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const getState = () => state;
|
|
66
|
-
const getInitialState = () => initialState;
|
|
67
|
-
const subscribe = (listener) => {
|
|
68
|
-
listeners.add(listener);
|
|
69
|
-
return () => listeners.delete(listener);
|
|
70
|
-
};
|
|
71
|
-
const api = {
|
|
72
|
-
setState,
|
|
73
|
-
getState,
|
|
74
|
-
getInitialState,
|
|
75
|
-
subscribe
|
|
76
|
-
};
|
|
77
|
-
const initialState = state = createState(setState, getState, api);
|
|
78
|
-
return api;
|
|
79
|
-
};
|
|
80
|
-
const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region ../../node_modules/zustand/esm/react.mjs
|
|
84
|
-
const identity = (arg) => arg;
|
|
85
|
-
function useStore(api, selector = identity) {
|
|
86
|
-
const slice = react.default.useSyncExternalStore(api.subscribe, () => selector(api.getState()), () => selector(api.getInitialState()));
|
|
87
|
-
react.default.useDebugValue(slice);
|
|
88
|
-
return slice;
|
|
89
|
-
}
|
|
90
|
-
const createImpl = (createState) => {
|
|
91
|
-
const api = createStore(createState);
|
|
92
|
-
const useBoundStore = (selector) => useStore(api, selector);
|
|
93
|
-
Object.assign(useBoundStore, api);
|
|
94
|
-
return useBoundStore;
|
|
95
|
-
};
|
|
96
|
-
const create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
97
|
-
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/components/store.tsx
|
|
100
|
-
const useWeave = create()((set) => ({
|
|
101
|
-
instance: null,
|
|
102
|
-
appState: { weave: {} },
|
|
103
|
-
status: WEAVE_INSTANCE_STATUS.IDLE,
|
|
104
|
-
room: { loaded: false },
|
|
105
|
-
connection: { status: "disconnected" },
|
|
106
|
-
users: {},
|
|
107
|
-
undoRedo: {
|
|
108
|
-
canUndo: false,
|
|
109
|
-
canRedo: false
|
|
110
|
-
},
|
|
111
|
-
zoom: {
|
|
112
|
-
value: 1,
|
|
113
|
-
canZoomIn: false,
|
|
114
|
-
canZoomOut: false
|
|
115
|
-
},
|
|
116
|
-
contextMenu: {
|
|
117
|
-
show: false,
|
|
118
|
-
position: {
|
|
119
|
-
x: 0,
|
|
120
|
-
y: 0
|
|
121
|
-
},
|
|
122
|
-
options: []
|
|
123
|
-
},
|
|
124
|
-
selection: {
|
|
125
|
-
active: false,
|
|
126
|
-
nodes: [],
|
|
127
|
-
node: void 0
|
|
128
|
-
},
|
|
129
|
-
actions: {
|
|
130
|
-
active: false,
|
|
131
|
-
actual: void 0
|
|
132
|
-
},
|
|
133
|
-
setInstance: (newInstance) => set((state) => ({
|
|
134
|
-
...state,
|
|
135
|
-
instance: newInstance
|
|
136
|
-
})),
|
|
137
|
-
setStatus: (newStatus) => set((state) => ({
|
|
138
|
-
...state,
|
|
139
|
-
status: newStatus
|
|
140
|
-
})),
|
|
141
|
-
setAppState: (newAppState) => set((state) => ({
|
|
142
|
-
...state,
|
|
143
|
-
appState: newAppState
|
|
144
|
-
})),
|
|
145
|
-
setConnectionStatus: (newConnectionStatus) => set((state) => ({
|
|
146
|
-
...state,
|
|
147
|
-
connection: {
|
|
148
|
-
...state.connection,
|
|
149
|
-
status: newConnectionStatus
|
|
150
|
-
}
|
|
151
|
-
})),
|
|
152
|
-
setRoomLoaded: (newStatus) => set((state) => ({
|
|
153
|
-
...state,
|
|
154
|
-
room: {
|
|
155
|
-
...state.room,
|
|
156
|
-
loaded: newStatus
|
|
157
|
-
}
|
|
158
|
-
})),
|
|
159
|
-
setUsers: (newUsers) => set((state) => ({
|
|
160
|
-
...state,
|
|
161
|
-
users: newUsers
|
|
162
|
-
})),
|
|
163
|
-
setCanUndo: (newCanUndo) => set((state) => ({
|
|
164
|
-
...state,
|
|
165
|
-
undoRedo: {
|
|
166
|
-
...state.undoRedo,
|
|
167
|
-
canUndo: newCanUndo
|
|
168
|
-
}
|
|
169
|
-
})),
|
|
170
|
-
setCanRedo: (newCanRedo) => set((state) => ({
|
|
171
|
-
...state,
|
|
172
|
-
undoRedo: {
|
|
173
|
-
...state.undoRedo,
|
|
174
|
-
canRedo: newCanRedo
|
|
175
|
-
}
|
|
176
|
-
})),
|
|
177
|
-
setZoom: (newZoom) => set((state) => ({
|
|
178
|
-
...state,
|
|
179
|
-
zoom: {
|
|
180
|
-
...state.zoom,
|
|
181
|
-
value: newZoom
|
|
182
|
-
}
|
|
183
|
-
})),
|
|
184
|
-
setCanZoomIn: (newCanZoomIn) => set((state) => ({
|
|
185
|
-
...state,
|
|
186
|
-
zoom: {
|
|
187
|
-
...state.zoom,
|
|
188
|
-
canZoomIn: newCanZoomIn
|
|
189
|
-
}
|
|
190
|
-
})),
|
|
191
|
-
setCanZoomOut: (newCanZoomOut) => set((state) => ({
|
|
192
|
-
...state,
|
|
193
|
-
zoom: {
|
|
194
|
-
...state.zoom,
|
|
195
|
-
canZoomOut: newCanZoomOut
|
|
196
|
-
}
|
|
197
|
-
})),
|
|
198
|
-
setSelectionActive: (newSelectionActive) => set((state) => ({
|
|
199
|
-
...state,
|
|
200
|
-
selection: {
|
|
201
|
-
...state.selection,
|
|
202
|
-
active: newSelectionActive
|
|
203
|
-
}
|
|
204
|
-
})),
|
|
205
|
-
setSelectedNodes: (newSelectedNodes) => set((state) => ({
|
|
206
|
-
...state,
|
|
207
|
-
selection: {
|
|
208
|
-
...state.selection,
|
|
209
|
-
nodes: newSelectedNodes
|
|
210
|
-
}
|
|
211
|
-
})),
|
|
212
|
-
setNode: (newNode) => set((state) => ({
|
|
213
|
-
...state,
|
|
214
|
-
selection: {
|
|
215
|
-
...state.selection,
|
|
216
|
-
node: newNode
|
|
217
|
-
}
|
|
218
|
-
})),
|
|
219
|
-
setActualAction: (newActualAction) => set((state) => ({
|
|
220
|
-
...state,
|
|
221
|
-
actions: {
|
|
222
|
-
...state.actions,
|
|
223
|
-
active: typeof newActualAction !== "undefined",
|
|
224
|
-
actual: newActualAction
|
|
225
|
-
}
|
|
226
|
-
}))
|
|
227
|
-
}));
|
|
228
|
-
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/components/provider.tsx
|
|
231
|
-
const WeaveProvider = ({ getContainer, store, nodes = [], actions = [], plugins = [], customPlugins = [], fonts = [], logLevel = "info", children }) => {
|
|
232
|
-
const weaveInstanceRef = react.default.useRef(null);
|
|
233
|
-
const selectedNodes = useWeave((state) => state.selection.nodes);
|
|
234
|
-
const setInstance = useWeave((state) => state.setInstance);
|
|
235
|
-
const setAppState = useWeave((state) => state.setAppState);
|
|
236
|
-
const setStatus = useWeave((state) => state.setStatus);
|
|
237
|
-
const setRoomLoaded = useWeave((state) => state.setRoomLoaded);
|
|
238
|
-
const setCanUndo = useWeave((state) => state.setCanUndo);
|
|
239
|
-
const setCanRedo = useWeave((state) => state.setCanRedo);
|
|
240
|
-
const setActualAction = useWeave((state) => state.setActualAction);
|
|
241
|
-
const setConnectionStatus = useWeave((state) => state.setConnectionStatus);
|
|
242
|
-
const onInstanceStatusHandler = react.default.useCallback(
|
|
243
|
-
(status) => {
|
|
244
|
-
setStatus(status);
|
|
245
|
-
},
|
|
246
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
247
|
-
[]
|
|
248
|
-
);
|
|
249
|
-
const onStoreConnectionStatusChangeHandler = react.default.useCallback(
|
|
250
|
-
(status) => {
|
|
251
|
-
setConnectionStatus(status);
|
|
252
|
-
},
|
|
253
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
-
[]
|
|
255
|
-
);
|
|
256
|
-
const onRoomLoadedHandler = react.default.useCallback(
|
|
257
|
-
(status) => {
|
|
258
|
-
setRoomLoaded(status);
|
|
259
|
-
},
|
|
260
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
261
|
-
[]
|
|
262
|
-
);
|
|
263
|
-
const onStateChangeHandler = react.default.useCallback(
|
|
264
|
-
(state) => {
|
|
265
|
-
setAppState(state);
|
|
266
|
-
},
|
|
267
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
268
|
-
[selectedNodes]
|
|
269
|
-
);
|
|
270
|
-
const onUndoManagerStatusChangeHandler = react.default.useCallback(
|
|
271
|
-
(undoManagerStatus) => {
|
|
272
|
-
const { canUndo, canRedo } = undoManagerStatus;
|
|
273
|
-
setCanUndo(canUndo);
|
|
274
|
-
setCanRedo(canRedo);
|
|
275
|
-
},
|
|
276
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
277
|
-
[]
|
|
278
|
-
);
|
|
279
|
-
const onActiveActionChangeHandler = react.default.useCallback(
|
|
280
|
-
(actionName) => {
|
|
281
|
-
setActualAction(actionName);
|
|
282
|
-
},
|
|
283
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
284
|
-
[selectedNodes]
|
|
285
|
-
);
|
|
286
|
-
react.default.useEffect(() => {
|
|
287
|
-
async function initWeave() {
|
|
288
|
-
const weaveEle = getContainer();
|
|
289
|
-
if (!weaveEle) throw new Error(`Weave container not defined.`);
|
|
290
|
-
const weaveEleClientRect = weaveEle?.getBoundingClientRect();
|
|
291
|
-
if (weaveEle && !weaveInstanceRef.current) {
|
|
292
|
-
const instanceNodes = [];
|
|
293
|
-
if (nodes.length > 0) for (const node of nodes) instanceNodes.push(node);
|
|
294
|
-
const instanceActions = [];
|
|
295
|
-
if (actions.length > 0) for (const action of actions) instanceActions.push(action);
|
|
296
|
-
const instancePlugins = [];
|
|
297
|
-
if (plugins.length > 0) for (const plugin of plugins) instancePlugins.push(plugin);
|
|
298
|
-
weaveInstanceRef.current = new __inditextech_weave_sdk.Weave({
|
|
299
|
-
store,
|
|
300
|
-
nodes,
|
|
301
|
-
actions,
|
|
302
|
-
plugins: [...instancePlugins, ...customPlugins],
|
|
303
|
-
fonts,
|
|
304
|
-
logger: { level: logLevel }
|
|
305
|
-
}, {
|
|
306
|
-
container: weaveEle,
|
|
307
|
-
width: weaveEleClientRect?.width ?? 1920,
|
|
308
|
-
height: weaveEleClientRect?.height ?? 1080
|
|
309
|
-
});
|
|
310
|
-
weaveInstanceRef.current.addEventListener("onInstanceStatus", onInstanceStatusHandler);
|
|
311
|
-
weaveInstanceRef.current.addEventListener("onStoreConnectionStatusChange", onStoreConnectionStatusChangeHandler);
|
|
312
|
-
weaveInstanceRef.current.addEventListener("onRoomLoaded", onRoomLoadedHandler);
|
|
313
|
-
weaveInstanceRef.current.addEventListener("onStateChange", onStateChangeHandler);
|
|
314
|
-
weaveInstanceRef.current.addEventListener("onUndoManagerStatusChange", onUndoManagerStatusChangeHandler);
|
|
315
|
-
weaveInstanceRef.current.addEventListener("onActiveActionChange", onActiveActionChangeHandler);
|
|
316
|
-
setInstance(weaveInstanceRef.current);
|
|
317
|
-
weaveInstanceRef.current.start();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
setStatus(WEAVE_INSTANCE_STATUS.IDLE);
|
|
321
|
-
setRoomLoaded(false);
|
|
322
|
-
initWeave();
|
|
323
|
-
return () => {
|
|
324
|
-
weaveInstanceRef.current?.removeEventListener("onInstanceStatus", onInstanceStatusHandler);
|
|
325
|
-
weaveInstanceRef.current?.removeEventListener("onStoreConnectionStatusChange", onStoreConnectionStatusChangeHandler);
|
|
326
|
-
weaveInstanceRef.current?.removeEventListener("onRoomLoaded", onRoomLoadedHandler);
|
|
327
|
-
weaveInstanceRef.current?.removeEventListener("onStateChange", onStateChangeHandler);
|
|
328
|
-
weaveInstanceRef.current?.removeEventListener("onUndoManagerStatusChange", onUndoManagerStatusChangeHandler);
|
|
329
|
-
weaveInstanceRef.current?.removeEventListener("onActiveActionChange", onActiveActionChangeHandler);
|
|
330
|
-
weaveInstanceRef.current?.destroy();
|
|
331
|
-
weaveInstanceRef.current = null;
|
|
332
|
-
};
|
|
333
|
-
}, []);
|
|
334
|
-
return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, children);
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
//#endregion
|
|
338
|
-
//#region src/hooks/events.tsx
|
|
339
|
-
const useWeaveEvents = () => {
|
|
340
|
-
const instance = useWeave((state) => state.instance);
|
|
341
|
-
const node = useWeave((state) => state.selection.node);
|
|
342
|
-
const setZoom = useWeave((state) => state.setZoom);
|
|
343
|
-
const setCanZoomIn = useWeave((state) => state.setCanZoomIn);
|
|
344
|
-
const setCanZoomOut = useWeave((state) => state.setCanZoomOut);
|
|
345
|
-
const setSelectionActive = useWeave((state) => state.setSelectionActive);
|
|
346
|
-
const setSelectedNodes = useWeave((state) => state.setSelectedNodes);
|
|
347
|
-
const setNode = useWeave((state) => state.setNode);
|
|
348
|
-
const setUsers = useWeave((state) => state.setUsers);
|
|
349
|
-
const onSelectionStateHandler = react.default.useCallback((active) => {
|
|
350
|
-
setSelectionActive(active);
|
|
351
|
-
}, []);
|
|
352
|
-
const onZoomChangeHandler = react.default.useCallback(
|
|
353
|
-
(zoomInfo) => {
|
|
354
|
-
setZoom(zoomInfo.scale);
|
|
355
|
-
setCanZoomIn(zoomInfo.canZoomIn);
|
|
356
|
-
setCanZoomOut(zoomInfo.canZoomOut);
|
|
357
|
-
},
|
|
358
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
359
|
-
[]
|
|
360
|
-
);
|
|
361
|
-
const onNodesChangeHandler = react.default.useCallback((nodes) => {
|
|
362
|
-
if (nodes.length === 1 && node?.key !== nodes[0].node?.key) setNode(nodes[0].node);
|
|
363
|
-
if (nodes.length === 0) setNode(void 0);
|
|
364
|
-
setSelectedNodes(nodes);
|
|
365
|
-
}, [node]);
|
|
366
|
-
const onConnectedUsersChangedHandler = react.default.useCallback((users) => {
|
|
367
|
-
setUsers(users);
|
|
368
|
-
}, []);
|
|
369
|
-
react.default.useEffect(() => {
|
|
370
|
-
if (!instance) return;
|
|
371
|
-
instance.addEventListener("onSelectionState", onSelectionStateHandler);
|
|
372
|
-
instance.addEventListener("onZoomChange", onZoomChangeHandler);
|
|
373
|
-
instance.addEventListener("onNodesChange", onNodesChangeHandler);
|
|
374
|
-
instance.addEventListener("onConnectedUsersChange", onConnectedUsersChangedHandler);
|
|
375
|
-
return () => {
|
|
376
|
-
instance.removeEventListener("onSelectionState", onSelectionStateHandler);
|
|
377
|
-
instance.removeEventListener("onZoomChange", onZoomChangeHandler);
|
|
378
|
-
instance.removeEventListener("onNodesChange", onNodesChangeHandler);
|
|
379
|
-
instance.removeEventListener("onConnectedUsersChange", onConnectedUsersChangedHandler);
|
|
380
|
-
};
|
|
381
|
-
}, [instance]);
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
//#endregion
|
|
385
|
-
exports.WeaveProvider = WeaveProvider
|
|
386
|
-
exports.useWeave = useWeave
|
|
387
|
-
exports.useWeaveEvents = useWeaveEvents
|
package/dist/react.d.cts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Weave, WeaveAction, WeaveConnectedUsers, WeaveNode, WeavePlugin, WeaveStore } from "@inditextech/weave-sdk";
|
|
3
|
-
import Konva from "konva";
|
|
4
|
-
import "yjs";
|
|
5
|
-
import "konva/lib/types";
|
|
6
|
-
import { StoreApi, UseBoundStore } from "zustand";
|
|
7
|
-
|
|
8
|
-
//#region ../types/dist/types.d.ts
|
|
9
|
-
|
|
10
|
-
type WeaveStatusKeys = keyof typeof WEAVE_INSTANCE_STATUS;
|
|
11
|
-
type WeaveStatus = (typeof WEAVE_INSTANCE_STATUS)[WeaveStatusKeys];
|
|
12
|
-
type WeaveElementAttributes = {
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
id?: string;
|
|
15
|
-
nodeType?: string;
|
|
16
|
-
children?: WeaveStateElement[];
|
|
17
|
-
};
|
|
18
|
-
type WeaveStateElement = {
|
|
19
|
-
key: string;
|
|
20
|
-
type: string;
|
|
21
|
-
props: WeaveElementAttributes;
|
|
22
|
-
};
|
|
23
|
-
type WeaveState = {
|
|
24
|
-
weave: {
|
|
25
|
-
key: "stage";
|
|
26
|
-
type: "stage";
|
|
27
|
-
props: {
|
|
28
|
-
[key: string]: unknown;
|
|
29
|
-
id: "stage";
|
|
30
|
-
children: WeaveStateElement[];
|
|
31
|
-
};
|
|
32
|
-
} | Record<string, WeaveStateElement>;
|
|
33
|
-
};
|
|
34
|
-
type WeaveSelection = {
|
|
35
|
-
instance: Konva.Shape | Konva.Group;
|
|
36
|
-
node: WeaveStateElement | undefined;
|
|
37
|
-
};
|
|
38
|
-
type WeaveFont = {
|
|
39
|
-
id: string;
|
|
40
|
-
name: string;
|
|
41
|
-
offsetX?: number;
|
|
42
|
-
offsetY?: number;
|
|
43
|
-
};
|
|
44
|
-
declare const WEAVE_INSTANCE_STATUS: {
|
|
45
|
-
readonly "IDLE": "idle";
|
|
46
|
-
readonly "STARTING": "starting";
|
|
47
|
-
readonly "LOADING_FONTS": "loadingFonts";
|
|
48
|
-
readonly "CONNECTING_TO_ROOM": "connectingToRoom";
|
|
49
|
-
readonly "CONNECTING_ERROR": "connectingError";
|
|
50
|
-
readonly "LOADING_ROOM": "loadingRoom";
|
|
51
|
-
readonly "RUNNING": "running";
|
|
52
|
-
}; //#endregion
|
|
53
|
-
//#region src/components/provider.d.ts
|
|
54
|
-
type WeaveProviderType = {
|
|
55
|
-
getContainer: () => HTMLElement;
|
|
56
|
-
fonts?: WeaveFont[] | (() => Promise<WeaveFont[]>);
|
|
57
|
-
store: WeaveStore;
|
|
58
|
-
nodes?: WeaveNode[];
|
|
59
|
-
actions?: WeaveAction[];
|
|
60
|
-
plugins?: WeavePlugin[];
|
|
61
|
-
customNodes?: WeaveNode[];
|
|
62
|
-
customActions?: WeaveAction[];
|
|
63
|
-
customPlugins?: WeavePlugin[];
|
|
64
|
-
children: React.ReactNode;
|
|
65
|
-
logLevel?: "debug" | "info" | "warn" | "error";
|
|
66
|
-
};
|
|
67
|
-
declare const WeaveProvider: ({
|
|
68
|
-
getContainer,
|
|
69
|
-
store,
|
|
70
|
-
nodes,
|
|
71
|
-
actions,
|
|
72
|
-
plugins,
|
|
73
|
-
customPlugins,
|
|
74
|
-
fonts,
|
|
75
|
-
logLevel,
|
|
76
|
-
children
|
|
77
|
-
}: Readonly<WeaveProviderType>) => React.JSX.Element;
|
|
78
|
-
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/components/store.d.ts
|
|
81
|
-
interface WeaveRuntimeState {
|
|
82
|
-
instance: Weave | null;
|
|
83
|
-
appState: WeaveState;
|
|
84
|
-
status: WeaveStatus;
|
|
85
|
-
connection: {
|
|
86
|
-
status: string;
|
|
87
|
-
};
|
|
88
|
-
room: {
|
|
89
|
-
loaded: boolean;
|
|
90
|
-
};
|
|
91
|
-
users: WeaveConnectedUsers;
|
|
92
|
-
undoRedo: {
|
|
93
|
-
canUndo: boolean;
|
|
94
|
-
canRedo: boolean;
|
|
95
|
-
};
|
|
96
|
-
zoom: {
|
|
97
|
-
value: number;
|
|
98
|
-
canZoomIn: boolean;
|
|
99
|
-
canZoomOut: boolean;
|
|
100
|
-
};
|
|
101
|
-
selection: {
|
|
102
|
-
active: boolean;
|
|
103
|
-
nodes: WeaveSelection[];
|
|
104
|
-
node: WeaveStateElement | undefined;
|
|
105
|
-
};
|
|
106
|
-
actions: {
|
|
107
|
-
active: boolean;
|
|
108
|
-
actual: string | undefined;
|
|
109
|
-
};
|
|
110
|
-
setInstance: (newInstance: Weave | null) => void;
|
|
111
|
-
setStatus: (newStatus: WeaveStatus) => void;
|
|
112
|
-
setAppState: (newAppState: WeaveState) => void;
|
|
113
|
-
setConnectionStatus: (newConnectionStatus: string) => void;
|
|
114
|
-
setRoomLoaded: (newStatus: boolean) => void;
|
|
115
|
-
setUsers: (newUsers: WeaveConnectedUsers) => void;
|
|
116
|
-
setCanUndo: (newCanUndo: boolean) => void;
|
|
117
|
-
setCanRedo: (newCanRedo: boolean) => void;
|
|
118
|
-
setZoom: (newZoom: number) => void;
|
|
119
|
-
setCanZoomIn: (newCanZoomIn: boolean) => void;
|
|
120
|
-
setCanZoomOut: (newCanZoomOut: boolean) => void;
|
|
121
|
-
setSelectionActive: (newSelectionActive: boolean) => void;
|
|
122
|
-
setSelectedNodes: (newSelectedNodes: WeaveSelection[]) => void;
|
|
123
|
-
setNode: (newNode: WeaveStateElement | undefined) => void;
|
|
124
|
-
setActualAction: (newActualAction: string | undefined) => void;
|
|
125
|
-
}
|
|
126
|
-
declare const useWeave: UseBoundStore<StoreApi<WeaveRuntimeState>>;
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/hooks/events.d.ts
|
|
130
|
-
declare const useWeaveEvents: () => void;
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
export { WeaveProvider, useWeave, useWeaveEvents };
|