@veltdev/react 1.0.97 → 1.0.99

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/cjs/index.js CHANGED
@@ -109,7 +109,7 @@ var loadVelt = function (callback, version, staging, develop) {
109
109
  }
110
110
  };
111
111
 
112
- var VELT_SDK_VERSION = '1.0.111';
112
+ var VELT_SDK_VERSION = '1.0.112';
113
113
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
114
114
 
115
115
  var SnippylyProvider = function (props) {
@@ -852,6 +852,24 @@ function useEditor() {
852
852
  }, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getEditor]);
853
853
  return data;
854
854
  }
855
+ /**
856
+ * @beta This hook is in beta
857
+ */
858
+ function useEditorAccessTimer() {
859
+ var liveStateSyncElement = useLiveStateSyncUtils();
860
+ var _a = React__default["default"].useState({ state: 'idle' }), data = _a[0], setData = _a[1];
861
+ React.useEffect(function () {
862
+ if (!(liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getEditorAccessTimer))
863
+ return;
864
+ var subscription = liveStateSyncElement.getEditorAccessTimer().subscribe(function (res) {
865
+ setData(res);
866
+ });
867
+ return function () {
868
+ subscription.unsubscribe();
869
+ };
870
+ }, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getEditorAccessTimer]);
871
+ return data;
872
+ }
855
873
  /**
856
874
  * @beta This hook is in beta
857
875
  */
@@ -1145,28 +1163,39 @@ var createLiveStateMiddleware = function (config) {
1145
1163
  if (!liveStateDataId) {
1146
1164
  liveStateDataId = VELT_DEFAULT_LIVE_STATE_ID;
1147
1165
  }
1148
- return function (store) {
1149
- var isSdkInitialized = false;
1150
- var getDataSubscriptionSet = false;
1151
- var setupGetDataSubscription = function () {
1152
- var _a;
1153
- if (!getDataSubscriptionSet) {
1154
- getDataSubscriptionSet = true;
1155
- var liveStateSyncElement = (_a = window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement();
1156
- liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (data) {
1157
- // Dispatch action to update local state, marking it as remote
1158
- if (data) {
1159
- var sessionId_1 = getSessionId();
1160
- if (data.id === sessionId_1) {
1161
- return;
1162
- }
1163
- else {
1164
- store.dispatch(__assign(__assign({}, data.action), { isRemote: true }));
1165
- }
1166
+ var internalStore; // This variable will hold the reference to the store
1167
+ var dataSubscription; // This variable will hold the reference to the data subscription
1168
+ var isSdkInitialized = false;
1169
+ var setupGetDataSubscription = function () {
1170
+ var _a, _b;
1171
+ if (!dataSubscription && window.Velt && ((_a = window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
1172
+ var liveStateSyncElement = (_b = window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
1173
+ dataSubscription = liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (data) {
1174
+ // Dispatch action to update local state, marking it as remote
1175
+ if (data) {
1176
+ var sessionId_1 = getSessionId();
1177
+ if (data.id === sessionId_1) {
1178
+ return;
1166
1179
  }
1167
- });
1168
- }
1169
- };
1180
+ else {
1181
+ internalStore === null || internalStore === void 0 ? void 0 : internalStore.dispatch(__assign(__assign({}, data.action), { isRemote: true }));
1182
+ }
1183
+ }
1184
+ });
1185
+ }
1186
+ };
1187
+ var updateLiveStateDataId = function (newId) {
1188
+ liveStateDataId = newId || VELT_DEFAULT_LIVE_STATE_ID;
1189
+ if (dataSubscription) {
1190
+ dataSubscription.unsubscribe();
1191
+ dataSubscription = null;
1192
+ }
1193
+ if (isSdkInitialized) {
1194
+ setupGetDataSubscription();
1195
+ }
1196
+ };
1197
+ var middleware = function (store) {
1198
+ internalStore = store;
1170
1199
  var veltSdkInitializedListener = function () {
1171
1200
  isSdkInitialized = true;
1172
1201
  setupGetDataSubscription();
@@ -1185,6 +1214,10 @@ var createLiveStateMiddleware = function (config) {
1185
1214
  return result;
1186
1215
  }; };
1187
1216
  };
1217
+ return {
1218
+ middleware: middleware,
1219
+ updateLiveStateDataId: updateLiveStateDataId,
1220
+ };
1188
1221
  };
1189
1222
  var logLiveState = function (action, liveStateDataId) {
1190
1223
  var _a;
@@ -1246,6 +1279,7 @@ exports.useCursorUsers = useCursorUsers;
1246
1279
  exports.useCursorUtils = useCursorUtils;
1247
1280
  exports.useEditor = useEditor;
1248
1281
  exports.useEditorAccessRequestHandler = useEditorAccessRequestHandler;
1282
+ exports.useEditorAccessTimer = useEditorAccessTimer;
1249
1283
  exports.useHuddleUtils = useHuddleUtils;
1250
1284
  exports.useIdentify = useIdentify;
1251
1285
  exports.useLiveSelectionUtils = useLiveSelectionUtils;