@liveblocks/client 0.17.7 → 0.17.8
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/index.js +55 -28
- package/index.mjs +23 -4
- package/package.json +1 -1
- package/shared.d.ts +47 -0
- package/shared.js +2 -1
- package/shared.mjs +2 -1
package/index.js
CHANGED
|
@@ -161,7 +161,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
161
161
|
_state$pausedHistory,
|
|
162
162
|
historyItem
|
|
163
163
|
)
|
|
164
|
-
: state.undoStack.push(historyItem);
|
|
164
|
+
: (state.undoStack.push(historyItem), onHistoryChange());
|
|
165
165
|
}
|
|
166
166
|
function storageDispatch(ops, reverse, storageUpdates) {
|
|
167
167
|
var _state$batch$ops, _state$batch$reverseO;
|
|
@@ -414,7 +414,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
414
414
|
var ws = WebSocketPolyfill || WebSocket;
|
|
415
415
|
return function (token) {
|
|
416
416
|
return new ws(
|
|
417
|
-
liveblocksServer + "/?token=" + token + "&version=0.17.
|
|
417
|
+
liveblocksServer + "/?token=" + token + "&version=0.17.8"
|
|
418
418
|
);
|
|
419
419
|
};
|
|
420
420
|
})(
|
|
@@ -514,6 +514,18 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
514
514
|
(0, _step8.value)({ connectionId: message.actor, event: message.event });
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
+
function onHistoryChange() {
|
|
518
|
+
for (
|
|
519
|
+
var _step9,
|
|
520
|
+
_iterator9 = Json._createForOfIteratorHelperLoose(
|
|
521
|
+
state.listeners.history
|
|
522
|
+
);
|
|
523
|
+
!(_step9 = _iterator9()).done;
|
|
524
|
+
|
|
525
|
+
) {
|
|
526
|
+
(0, _step9.value)({ canUndo: canUndo(), canRedo: canRedo() });
|
|
527
|
+
}
|
|
528
|
+
}
|
|
517
529
|
function onUserJoinedMessage(message) {
|
|
518
530
|
return (
|
|
519
531
|
(state.users[message.actor] = {
|
|
@@ -552,13 +564,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
552
564
|
: Json.compact([parseServerMessage(data)]));
|
|
553
565
|
if (null !== messages && 0 !== messages.length) {
|
|
554
566
|
for (
|
|
555
|
-
var
|
|
567
|
+
var _step10,
|
|
556
568
|
updates = { storageUpdates: new Map(), others: [] },
|
|
557
|
-
|
|
558
|
-
!(
|
|
569
|
+
_iterator10 = Json._createForOfIteratorHelperLoose(messages);
|
|
570
|
+
!(_step10 = _iterator10()).done;
|
|
559
571
|
|
|
560
572
|
) {
|
|
561
|
-
var message =
|
|
573
|
+
var message = _step10.value;
|
|
562
574
|
switch (message.type) {
|
|
563
575
|
case Json.ServerMsgCode.USER_JOINED:
|
|
564
576
|
updates.others.push(onUserJoinedMessage(message));
|
|
@@ -615,15 +627,15 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
615
627
|
) {
|
|
616
628
|
updateConnection({ state: "failed" });
|
|
617
629
|
for (
|
|
618
|
-
var
|
|
630
|
+
var _step11,
|
|
619
631
|
error = new LiveblocksError(event.reason, event.code),
|
|
620
|
-
|
|
632
|
+
_iterator11 = Json._createForOfIteratorHelperLoose(
|
|
621
633
|
state.listeners.error
|
|
622
634
|
);
|
|
623
|
-
!(
|
|
635
|
+
!(_step11 = _iterator11()).done;
|
|
624
636
|
|
|
625
637
|
) {
|
|
626
|
-
(0,
|
|
638
|
+
(0, _step11.value)(error);
|
|
627
639
|
}
|
|
628
640
|
var _delay = getRetryDelay(!0);
|
|
629
641
|
state.numberOfRetry++,
|
|
@@ -659,14 +671,14 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
659
671
|
function updateConnection(connection) {
|
|
660
672
|
state.connection = connection;
|
|
661
673
|
for (
|
|
662
|
-
var
|
|
663
|
-
|
|
674
|
+
var _step12,
|
|
675
|
+
_iterator12 = Json._createForOfIteratorHelperLoose(
|
|
664
676
|
state.listeners.connection
|
|
665
677
|
);
|
|
666
|
-
!(
|
|
678
|
+
!(_step12 = _iterator12()).done;
|
|
667
679
|
|
|
668
680
|
) {
|
|
669
|
-
(0,
|
|
681
|
+
(0, _step12.value)(connection.state);
|
|
670
682
|
}
|
|
671
683
|
}
|
|
672
684
|
function getRetryDelay(slow) {
|
|
@@ -757,14 +769,14 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
757
769
|
data: state.buffer.presence,
|
|
758
770
|
});
|
|
759
771
|
for (
|
|
760
|
-
var
|
|
761
|
-
|
|
772
|
+
var _step13,
|
|
773
|
+
_iterator13 = Json._createForOfIteratorHelperLoose(
|
|
762
774
|
state.buffer.messages
|
|
763
775
|
);
|
|
764
|
-
!(
|
|
776
|
+
!(_step13 = _iterator13()).done;
|
|
765
777
|
|
|
766
778
|
) {
|
|
767
|
-
var _event3 =
|
|
779
|
+
var _event3 = _step13.value;
|
|
768
780
|
messages.push(_event3);
|
|
769
781
|
}
|
|
770
782
|
state.buffer.storageOperations.length > 0 &&
|
|
@@ -803,6 +815,12 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
803
815
|
}
|
|
804
816
|
var _getInitialStatePromise = null,
|
|
805
817
|
_getInitialStateResolver = null;
|
|
818
|
+
function canUndo() {
|
|
819
|
+
return state.undoStack.length > 0;
|
|
820
|
+
}
|
|
821
|
+
function canRedo() {
|
|
822
|
+
return state.redoStack.length > 0;
|
|
823
|
+
}
|
|
806
824
|
return {
|
|
807
825
|
onClose: onClose,
|
|
808
826
|
onMessage: onMessage,
|
|
@@ -953,14 +971,16 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
953
971
|
if (null != historyItem) {
|
|
954
972
|
state.isHistoryPaused = !1;
|
|
955
973
|
var result = apply(historyItem, !0);
|
|
956
|
-
notify(result.updates),
|
|
974
|
+
notify(result.updates),
|
|
975
|
+
state.redoStack.push(result.reverse),
|
|
976
|
+
onHistoryChange();
|
|
957
977
|
for (
|
|
958
|
-
var
|
|
959
|
-
|
|
960
|
-
!(
|
|
978
|
+
var _step14,
|
|
979
|
+
_iterator14 = Json._createForOfIteratorHelperLoose(historyItem);
|
|
980
|
+
!(_step14 = _iterator14()).done;
|
|
961
981
|
|
|
962
982
|
) {
|
|
963
|
-
var op =
|
|
983
|
+
var op = _step14.value;
|
|
964
984
|
"presence" !== op.type && state.buffer.storageOperations.push(op);
|
|
965
985
|
}
|
|
966
986
|
tryFlushing();
|
|
@@ -973,19 +993,23 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
973
993
|
if (null != historyItem) {
|
|
974
994
|
state.isHistoryPaused = !1;
|
|
975
995
|
var result = apply(historyItem, !0);
|
|
976
|
-
notify(result.updates),
|
|
996
|
+
notify(result.updates),
|
|
997
|
+
state.undoStack.push(result.reverse),
|
|
998
|
+
onHistoryChange();
|
|
977
999
|
for (
|
|
978
|
-
var
|
|
979
|
-
|
|
980
|
-
!(
|
|
1000
|
+
var _step15,
|
|
1001
|
+
_iterator15 = Json._createForOfIteratorHelperLoose(historyItem);
|
|
1002
|
+
!(_step15 = _iterator15()).done;
|
|
981
1003
|
|
|
982
1004
|
) {
|
|
983
|
-
var op =
|
|
1005
|
+
var op = _step15.value;
|
|
984
1006
|
"presence" !== op.type && state.buffer.storageOperations.push(op);
|
|
985
1007
|
}
|
|
986
1008
|
tryFlushing();
|
|
987
1009
|
}
|
|
988
1010
|
},
|
|
1011
|
+
canUndo: canUndo,
|
|
1012
|
+
canRedo: canRedo,
|
|
989
1013
|
pauseHistory: function () {
|
|
990
1014
|
(state.pausedHistory = []), (state.isHistoryPaused = !0);
|
|
991
1015
|
},
|
|
@@ -1058,6 +1082,7 @@ function createRoom(options, context) {
|
|
|
1058
1082
|
error: [],
|
|
1059
1083
|
connection: [],
|
|
1060
1084
|
storage: [],
|
|
1085
|
+
history: [],
|
|
1061
1086
|
},
|
|
1062
1087
|
numberOfRetry: 0,
|
|
1063
1088
|
lastFlushTime: 0,
|
|
@@ -1113,6 +1138,8 @@ function createRoom(options, context) {
|
|
|
1113
1138
|
history: {
|
|
1114
1139
|
undo: machine.undo,
|
|
1115
1140
|
redo: machine.redo,
|
|
1141
|
+
canUndo: machine.canUndo,
|
|
1142
|
+
canRedo: machine.canRedo,
|
|
1116
1143
|
pause: machine.pauseHistory,
|
|
1117
1144
|
resume: machine.resumeHistory,
|
|
1118
1145
|
},
|
package/index.mjs
CHANGED
|
@@ -141,7 +141,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
141
141
|
state.undoStack.length >= 50 && state.undoStack.shift(),
|
|
142
142
|
state.isHistoryPaused
|
|
143
143
|
? state.pausedHistory.unshift(...historyItem)
|
|
144
|
-
: state.undoStack.push(historyItem);
|
|
144
|
+
: (state.undoStack.push(historyItem), onHistoryChange());
|
|
145
145
|
}
|
|
146
146
|
function storageDispatch(ops, reverse, storageUpdates) {
|
|
147
147
|
state.isBatching
|
|
@@ -337,7 +337,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
337
337
|
);
|
|
338
338
|
const ws = WebSocketPolyfill || WebSocket;
|
|
339
339
|
return (token) =>
|
|
340
|
-
new ws(`${liveblocksServer}/?token=${token}&version=0.17.
|
|
340
|
+
new ws(`${liveblocksServer}/?token=${token}&version=0.17.8`);
|
|
341
341
|
})(
|
|
342
342
|
context.liveblocksServer,
|
|
343
343
|
null !==
|
|
@@ -427,6 +427,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
427
427
|
for (const listener of state.listeners.event)
|
|
428
428
|
listener({ connectionId: message.actor, event: message.event });
|
|
429
429
|
}
|
|
430
|
+
function onHistoryChange() {
|
|
431
|
+
for (const listener of state.listeners.history)
|
|
432
|
+
listener({ canUndo: canUndo(), canRedo: canRedo() });
|
|
433
|
+
}
|
|
430
434
|
function onUserJoinedMessage(message) {
|
|
431
435
|
return (
|
|
432
436
|
(state.users[message.actor] = {
|
|
@@ -655,6 +659,12 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
655
659
|
}
|
|
656
660
|
let _getInitialStatePromise = null,
|
|
657
661
|
_getInitialStateResolver = null;
|
|
662
|
+
function canUndo() {
|
|
663
|
+
return state.undoStack.length > 0;
|
|
664
|
+
}
|
|
665
|
+
function canRedo() {
|
|
666
|
+
return state.redoStack.length > 0;
|
|
667
|
+
}
|
|
658
668
|
return {
|
|
659
669
|
onClose: onClose,
|
|
660
670
|
onMessage: onMessage,
|
|
@@ -795,7 +805,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
795
805
|
if (null == historyItem) return;
|
|
796
806
|
state.isHistoryPaused = !1;
|
|
797
807
|
const result = apply(historyItem, !0);
|
|
798
|
-
notify(result.updates),
|
|
808
|
+
notify(result.updates),
|
|
809
|
+
state.redoStack.push(result.reverse),
|
|
810
|
+
onHistoryChange();
|
|
799
811
|
for (const op of historyItem)
|
|
800
812
|
"presence" !== op.type && state.buffer.storageOperations.push(op);
|
|
801
813
|
tryFlushing();
|
|
@@ -807,11 +819,15 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
807
819
|
if (null == historyItem) return;
|
|
808
820
|
state.isHistoryPaused = !1;
|
|
809
821
|
const result = apply(historyItem, !0);
|
|
810
|
-
notify(result.updates),
|
|
822
|
+
notify(result.updates),
|
|
823
|
+
state.undoStack.push(result.reverse),
|
|
824
|
+
onHistoryChange();
|
|
811
825
|
for (const op of historyItem)
|
|
812
826
|
"presence" !== op.type && state.buffer.storageOperations.push(op);
|
|
813
827
|
tryFlushing();
|
|
814
828
|
},
|
|
829
|
+
canUndo: canUndo,
|
|
830
|
+
canRedo: canRedo,
|
|
815
831
|
pauseHistory: function () {
|
|
816
832
|
(state.pausedHistory = []), (state.isHistoryPaused = !0);
|
|
817
833
|
},
|
|
@@ -877,6 +893,7 @@ function createRoom(options, context) {
|
|
|
877
893
|
error: [],
|
|
878
894
|
connection: [],
|
|
879
895
|
storage: [],
|
|
896
|
+
history: [],
|
|
880
897
|
},
|
|
881
898
|
numberOfRetry: 0,
|
|
882
899
|
lastFlushTime: 0,
|
|
@@ -932,6 +949,8 @@ function createRoom(options, context) {
|
|
|
932
949
|
history: {
|
|
933
950
|
undo: machine.undo,
|
|
934
951
|
redo: machine.redo,
|
|
952
|
+
canUndo: machine.canUndo,
|
|
953
|
+
canRedo: machine.canRedo,
|
|
935
954
|
pause: machine.pauseHistory,
|
|
936
955
|
resume: machine.resumeHistory,
|
|
937
956
|
},
|
package/package.json
CHANGED
package/shared.d.ts
CHANGED
|
@@ -312,6 +312,7 @@ declare type EventCallback<TRoomEvent extends Json> = ({
|
|
|
312
312
|
}) => void;
|
|
313
313
|
declare type ErrorCallback = (error: Error) => void;
|
|
314
314
|
declare type ConnectionCallback = (state: ConnectionState) => void;
|
|
315
|
+
declare type HistoryCallback = (event: HistoryEvent) => void;
|
|
315
316
|
declare type UpdateDelta =
|
|
316
317
|
| {
|
|
317
318
|
type: "update";
|
|
@@ -604,6 +605,27 @@ interface History {
|
|
|
604
605
|
* // room.getPresence() equals { selectedId: "yy" }
|
|
605
606
|
*/
|
|
606
607
|
redo: () => void;
|
|
608
|
+
/**
|
|
609
|
+
* Returns whether there are any operations to undo.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* room.updatePresence({ selectedId: "xx" }, { addToHistory: true });
|
|
613
|
+
* // room.history.canUndo() is true
|
|
614
|
+
* room.history.undo();
|
|
615
|
+
* // room.history.canUndo() is false
|
|
616
|
+
*/
|
|
617
|
+
canUndo: () => boolean;
|
|
618
|
+
/**
|
|
619
|
+
* Returns whether there are any operations to redo.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* room.updatePresence({ selectedId: "xx" }, { addToHistory: true });
|
|
623
|
+
* room.history.undo();
|
|
624
|
+
* // room.history.canRedo() is true
|
|
625
|
+
* room.history.redo();
|
|
626
|
+
* // room.history.canRedo() is false
|
|
627
|
+
*/
|
|
628
|
+
canRedo: () => boolean;
|
|
607
629
|
/**
|
|
608
630
|
* All future modifications made on the Room will be merged together to create a single history item until resume is called.
|
|
609
631
|
*
|
|
@@ -631,6 +653,10 @@ interface History {
|
|
|
631
653
|
*/
|
|
632
654
|
resume: () => void;
|
|
633
655
|
}
|
|
656
|
+
interface HistoryEvent {
|
|
657
|
+
canUndo: boolean;
|
|
658
|
+
canRedo: boolean;
|
|
659
|
+
}
|
|
634
660
|
declare type Room<
|
|
635
661
|
TPresence extends JsonObject,
|
|
636
662
|
TStorage extends LsonObject,
|
|
@@ -648,6 +674,8 @@ declare type Room<
|
|
|
648
674
|
*
|
|
649
675
|
* @param listener the callback that is called every time the current user presence is updated with {@link Room.updatePresence}.
|
|
650
676
|
*
|
|
677
|
+
* @returns Unsubscribe function.
|
|
678
|
+
*
|
|
651
679
|
* @example
|
|
652
680
|
* room.subscribe("my-presence", (presence) => {
|
|
653
681
|
* // Do something
|
|
@@ -659,6 +687,8 @@ declare type Room<
|
|
|
659
687
|
*
|
|
660
688
|
* @param listener the callback that is called when a user enters or leaves the room or when a user update its presence.
|
|
661
689
|
*
|
|
690
|
+
* @returns Unsubscribe function.
|
|
691
|
+
*
|
|
662
692
|
* @example
|
|
663
693
|
* room.subscribe("others", (others) => {
|
|
664
694
|
* // Do something
|
|
@@ -673,6 +703,8 @@ declare type Room<
|
|
|
673
703
|
*
|
|
674
704
|
* @param listener the callback that is called when a user calls {@link Room.broadcastEvent}
|
|
675
705
|
*
|
|
706
|
+
* @returns Unsubscribe function.
|
|
707
|
+
*
|
|
676
708
|
* @example
|
|
677
709
|
* room.subscribe("event", ({ event, connectionId }) => {
|
|
678
710
|
* // Do something
|
|
@@ -681,10 +713,14 @@ declare type Room<
|
|
|
681
713
|
(type: "event", listener: EventCallback<TRoomEvent>): () => void;
|
|
682
714
|
/**
|
|
683
715
|
* Subscribe to errors thrown in the room.
|
|
716
|
+
*
|
|
717
|
+
* @returns Unsubscribe function.
|
|
684
718
|
*/
|
|
685
719
|
(type: "error", listener: ErrorCallback): () => void;
|
|
686
720
|
/**
|
|
687
721
|
* Subscribe to connection state updates.
|
|
722
|
+
*
|
|
723
|
+
* @returns Unsubscribe function.
|
|
688
724
|
*/
|
|
689
725
|
(type: "connection", listener: ConnectionCallback): () => void;
|
|
690
726
|
/**
|
|
@@ -726,6 +762,17 @@ declare type Room<
|
|
|
726
762
|
isDeep: true;
|
|
727
763
|
}
|
|
728
764
|
): () => void;
|
|
765
|
+
/**
|
|
766
|
+
* Subscribe to the current user's history changes.
|
|
767
|
+
*
|
|
768
|
+
* @returns Unsubscribe function.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* room.subscribe("history", ({ canUndo, canRedo }) => {
|
|
772
|
+
* // Do something
|
|
773
|
+
* });
|
|
774
|
+
*/
|
|
775
|
+
(type: "history", listener: HistoryCallback): () => void;
|
|
729
776
|
};
|
|
730
777
|
/**
|
|
731
778
|
* Room's history contains functions that let you undo and redo operation made on by the current client on the presence and storage.
|
package/shared.js
CHANGED
|
@@ -2565,7 +2565,8 @@ function isJsonArray(data) {
|
|
|
2565
2565
|
"others" === value ||
|
|
2566
2566
|
"event" === value ||
|
|
2567
2567
|
"error" === value ||
|
|
2568
|
-
"connection" === value
|
|
2568
|
+
"connection" === value ||
|
|
2569
|
+
"history" === value
|
|
2569
2570
|
);
|
|
2570
2571
|
}),
|
|
2571
2572
|
(exports.isRootCrdt = function (crdt) {
|