@tumaet/apollon 4.2.23 → 4.4.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.
@@ -18,6 +18,7 @@ export type DiagramStore = {
18
18
  canUndo: boolean;
19
19
  canRedo: boolean;
20
20
  undoManager: Y.UndoManager | null;
21
+ previewMode: boolean;
21
22
  setDiagramId: (diagramId: string) => void;
22
23
  setNodes: (payload: Node[] | ((nodes: Node[]) => Node[])) => void;
23
24
  setEdges: (payload: Edge[] | ((edges: Edge[]) => Edge[])) => void;
@@ -42,5 +43,12 @@ export type DiagramStore = {
42
43
  getInteractiveForSerialization: () => InteractiveElements | undefined;
43
44
  setInteractive: (interactive: InteractiveElements | undefined) => void;
44
45
  isElementInteractive: (elementId: string) => boolean;
46
+ /**
47
+ * Toggle the preview overlay. When entering, the Yjs doc is left
48
+ * untouched by store mutators and observers. When exiting, the local
49
+ * Zustand state is rebuilt from the (peer-augmented) Yjs maps so the
50
+ * canvas catches up to everything that arrived during preview.
51
+ */
52
+ setPreviewMode: (active: boolean) => void;
45
53
  };
46
54
  export declare const createDiagramStore: (ydoc: Y.Doc) => UseBoundStore<StoreApi<DiagramStore>>;
@@ -25,4 +25,4 @@ export type MetadataStore = {
25
25
  reset: () => void;
26
26
  setDebug: (debug: boolean) => void;
27
27
  };
28
- export declare const createMetadataStore: (ydoc: Y.Doc) => UseBoundStore<StoreApi<MetadataStore>>;
28
+ export declare const createMetadataStore: (ydoc: Y.Doc, isPreviewMode?: () => boolean) => UseBoundStore<StoreApi<MetadataStore>>;
@@ -0,0 +1,16 @@
1
+ import { YjsSyncClass } from './yjsSyncClass';
2
+ import * as Y from "yjs";
3
+ /**
4
+ * Construct a `YjsSyncClass` against minimal stub stores. Intended for
5
+ * tests that exercise the wire protocol (sync/awareness handshake,
6
+ * incremental updates, reconnect behaviour) without dragging the React
7
+ * editor / React-Flow / zustand-with-middleware setup into the harness.
8
+ *
9
+ * Stores expose only the methods the sync class actually invokes. The
10
+ * Yjs observers will call them, but their bodies are no-ops because the
11
+ * test asserts directly against the `Y.Doc` that's returned.
12
+ */
13
+ export declare function createHeadlessSync(ydoc?: Y.Doc): {
14
+ ydoc: Y.Doc;
15
+ sync: YjsSyncClass;
16
+ };
@@ -1,10 +1,13 @@
1
- import { StoreApi } from 'zustand';
2
1
  import { DiagramStore } from '../store/diagramStore';
3
2
  import { MetadataStore } from '../store/metadataStore';
3
+ import { CollaborationState, CollaborationUser, CollaboratorInfo } from '../typings';
4
+ import { StoreApi } from 'zustand';
4
5
  import * as Y from "yjs";
5
6
  export declare enum MessageType {
6
7
  YjsSYNC = 0,
7
- YjsUpdate = 1
8
+ YjsUpdate = 1,
9
+ AwarenessSync = 2,
10
+ AwarenessUpdate = 3
8
11
  }
9
12
  export type SendBroadcastMessage = (base64data: string) => void;
10
13
  export declare class YjsSyncClass {
@@ -13,9 +16,34 @@ export declare class YjsSyncClass {
13
16
  private readonly ydoc;
14
17
  private readonly diagramStore;
15
18
  private readonly metadataStore;
19
+ private readonly awareness;
16
20
  constructor(ydoc: Y.Doc, diagramStore: StoreApi<DiagramStore>, metadataStore: StoreApi<MetadataStore>);
17
21
  stopSync(): void;
22
+ /**
23
+ * Push the entire local Yjs document as a single `YjsUpdate`. Callers should
24
+ * invoke this after a (re)connect so peers absorb any edits made while we
25
+ * were disconnected — those updates fire while `readyState !== OPEN`, are
26
+ * silently dropped by the send callback, and never replayed otherwise.
27
+ * Yjs CRDTs converge on merge, so peers that already have these ops just
28
+ * no-op.
29
+ */
30
+ broadcastFullState: () => void;
18
31
  setSendBroadcastMessage: (sendFn: SendBroadcastMessage) => void;
32
+ setLocalAwarenessUser: (user: CollaborationUser) => void;
33
+ setLocalAwarenessCursor: (cursor: {
34
+ x: number;
35
+ y: number;
36
+ } | null) => void;
37
+ setLocalAwarenessSelectedElement: (selectedElementId: string | null) => void;
38
+ setLocalAwarenessState: (state: Partial<CollaborationState>) => void;
39
+ subscribeToAwarenessChanges: (callback: (states: Map<number, CollaborationState>) => void) => () => void;
40
+ getCollaborators: () => CollaboratorInfo[];
41
+ subscribeToCollaboratorChanges: (callback: (collaborators: CollaboratorInfo[]) => void) => () => void;
42
+ getLocalAwarenessClientId: () => number;
43
+ private static narrowState;
44
+ private getTypedStates;
45
+ private computeParticipantSignature;
46
+ private sendFramedMessage;
19
47
  private applyUpdate;
20
48
  handleReceivedData: (base64Data: string) => void;
21
49
  private startYjsObserver;
package/dist/typings.d.ts CHANGED
@@ -10,6 +10,29 @@ export type Subscribers = {
10
10
  [key: number]: Unsubscriber;
11
11
  };
12
12
  export type UMLModelElementType = DiagramNodeType | DiagramEdgeType;
13
+ export type CollaborationUser = {
14
+ name: string;
15
+ color: string;
16
+ id?: string;
17
+ imageUrl?: string;
18
+ };
19
+ export type CollaborationCursor = {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ export type CollaborationState = {
24
+ user?: CollaborationUser;
25
+ cursor?: CollaborationCursor | null;
26
+ selectedElementId?: string | null;
27
+ };
28
+ export type CollaboratorInfo = {
29
+ id: string;
30
+ name: string;
31
+ color: string;
32
+ imageUrl?: string;
33
+ clientIds: number[];
34
+ isLocal: boolean;
35
+ };
13
36
  export declare enum Locale {
14
37
  en = "en",
15
38
  de = "de"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tumaet/apollon",
3
- "version": "4.2.23",
3
+ "version": "4.4.0",
4
4
  "description": "An embeddable UML modeling editor for React. 13 diagram types, SVG/PNG/PDF/JSON export, optional real-time collaboration via Yjs.",
5
5
  "keywords": [
6
6
  "apollon",
@@ -63,6 +63,9 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@chenglou/pretext": "0.0.6",
66
+ "@dnd-kit/core": "6.3.1",
67
+ "@dnd-kit/sortable": "10.0.0",
68
+ "@dnd-kit/utilities": "3.2.2",
66
69
  "@emotion/react": "11.11.1",
67
70
  "@emotion/styled": "11.11.0",
68
71
  "@mui/material": "6.4.2",
@@ -70,6 +73,7 @@
70
73
  "react": "18.3.1",
71
74
  "react-dom": "18.3.1",
72
75
  "uuid": "11.0.3",
76
+ "y-protocols": "1.0.6",
73
77
  "yjs": "13.6.20",
74
78
  "zustand": "5.0.3"
75
79
  },