@veltdev/react 4.4.0-beta.3 → 4.4.0-beta.5

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare const VELT_SDK_VERSION = "4.4.0-beta.3";
2
+ export declare const VELT_SDK_VERSION = "4.4.0-beta.5";
3
3
  export declare const VELT_SDK_INIT_EVENT = "onVeltInit";
4
4
  export declare const VELT_TAB_ID = "veltTabId";
5
5
  export interface IVeltWireframeCommonProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> {
@@ -1,10 +1,10 @@
1
- import { EditorAccessTimer, LiveStateSyncElement, ServerConnectionState, User, UserEditorAccess } from "@veltdev/types";
1
+ import { EditorAccessTimer, LiveStateSyncElement, ServerConnectionState, SetLiveStateDataConfig, User, UserEditorAccess } from "@veltdev/types";
2
2
  declare class LiveStateDataConfig {
3
3
  listenToNewChangesOnly?: boolean;
4
4
  }
5
5
  export declare function useLiveStateSyncUtils(): LiveStateSyncElement | undefined;
6
6
  export declare function useLiveStateData(liveStateDataId?: string, liveStateDataConfig?: LiveStateDataConfig): any;
7
- export declare function useSetLiveStateData(liveStateDataId: string, liveStateData: any): void;
7
+ export declare function useSetLiveStateData(liveStateDataId: string, liveStateData: any, config?: SetLiveStateDataConfig): void;
8
8
  export declare function useUserEditorState(): UserEditorAccess | null;
9
9
  export declare function useEditor(): User | null;
10
10
  export declare function useEditorAccessTimer(): EditorAccessTimer;
package/esm/index.js CHANGED
@@ -132,7 +132,7 @@ var loadVelt = function (callback, version, staging, develop, proxyDomain) {
132
132
  }
133
133
  };
134
134
 
135
- var VELT_SDK_VERSION = '4.4.0-beta.3';
135
+ var VELT_SDK_VERSION = '4.4.0-beta.5';
136
136
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
137
137
  var VELT_TAB_ID = 'veltTabId';
138
138
 
@@ -6208,17 +6208,17 @@ function useLiveStateData(liveStateDataId, liveStateDataConfig) {
6208
6208
  }, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData, inputs]);
6209
6209
  return data;
6210
6210
  }
6211
- function useSetLiveStateData(liveStateDataId, liveStateData) {
6211
+ function useSetLiveStateData(liveStateDataId, liveStateData, config) {
6212
6212
  var liveStateSyncElement = useLiveStateSyncUtils();
6213
6213
  // Memoize inputs
6214
6214
  var inputs = React.useMemo(function () {
6215
- return { liveStateDataId: liveStateDataId, liveStateData: liveStateData };
6216
- }, [liveStateDataId, JSON.stringify(liveStateData)]);
6215
+ return { liveStateDataId: liveStateDataId, liveStateData: liveStateData, config: config };
6216
+ }, [liveStateDataId, JSON.stringify(liveStateData), JSON.stringify(config)]);
6217
6217
  React.useEffect(function () {
6218
6218
  if (!(liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.setLiveStateData))
6219
6219
  return;
6220
6220
  if (inputs.liveStateDataId && inputs.liveStateData) {
6221
- liveStateSyncElement.setLiveStateData(inputs.liveStateDataId, inputs.liveStateData);
6221
+ liveStateSyncElement.setLiveStateData(inputs.liveStateDataId, inputs.liveStateData, inputs.config);
6222
6222
  }
6223
6223
  }, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.setLiveStateData, inputs]);
6224
6224
  }
@@ -6776,39 +6776,55 @@ var createLiveStateMiddleware = function (config) {
6776
6776
  var isSdkInitialized = false;
6777
6777
  var setupGetDataSubscription = function () {
6778
6778
  var _a, _b;
6779
- if (!dataSubscription && window.Velt && ((_a = window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
6780
- var liveStateSyncElement = (_b = window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
6781
- dataSubscription = liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (data) {
6782
- // Dispatch action to update local state, marking it as remote
6783
- if (data) {
6784
- var sessionId_1 = getSessionId();
6785
- if (data.id === sessionId_1) {
6786
- return;
6787
- }
6788
- else {
6789
- internalStore === null || internalStore === void 0 ? void 0 : internalStore.dispatch(__assign(__assign({}, data.action), { isRemote: true }));
6779
+ try {
6780
+ if (!dataSubscription && window.Velt && ((_a = window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
6781
+ var liveStateSyncElement = (_b = window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
6782
+ dataSubscription = liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (data) {
6783
+ // Dispatch action to update local state, marking it as remote
6784
+ if (data) {
6785
+ var sessionId_1 = getSessionId();
6786
+ if (data.id === sessionId_1) {
6787
+ return;
6788
+ }
6789
+ else {
6790
+ internalStore === null || internalStore === void 0 ? void 0 : internalStore.dispatch(__assign(__assign({}, data.action), { isRemote: true }));
6791
+ }
6790
6792
  }
6791
- }
6792
- });
6793
+ });
6794
+ }
6795
+ }
6796
+ catch (err) {
6793
6797
  }
6794
6798
  };
6795
6799
  var updateLiveStateDataId = function (newId) {
6796
- liveStateDataId = newId || VELT_DEFAULT_LIVE_STATE_ID;
6797
- if (dataSubscription) {
6798
- dataSubscription.unsubscribe();
6799
- dataSubscription = null;
6800
+ try {
6801
+ liveStateDataId = newId || VELT_DEFAULT_LIVE_STATE_ID;
6802
+ if (dataSubscription) {
6803
+ dataSubscription.unsubscribe();
6804
+ dataSubscription = null;
6805
+ }
6806
+ if (isSdkInitialized) {
6807
+ setupGetDataSubscription();
6808
+ }
6800
6809
  }
6801
- if (isSdkInitialized) {
6802
- setupGetDataSubscription();
6810
+ catch (err) {
6811
+ // handle error
6803
6812
  }
6804
6813
  };
6805
6814
  var middleware = function (store) {
6806
6815
  internalStore = store;
6807
6816
  var veltSdkInitializedListener = function () {
6808
- isSdkInitialized = true;
6809
- setupGetDataSubscription();
6810
- // Remove the event listener after it's triggered
6811
- window.removeEventListener(VELT_SDK_INIT_EVENT, veltSdkInitializedListener);
6817
+ try {
6818
+ if (window.Velt) {
6819
+ isSdkInitialized = true;
6820
+ setupGetDataSubscription();
6821
+ // Remove the event listener after it's triggered
6822
+ window.removeEventListener(VELT_SDK_INIT_EVENT, veltSdkInitializedListener);
6823
+ }
6824
+ }
6825
+ catch (err) {
6826
+ // handle error
6827
+ }
6812
6828
  };
6813
6829
  // Add the event listener for the veltSdkInitialized event
6814
6830
  window.addEventListener(VELT_SDK_INIT_EVENT, veltSdkInitializedListener);
@@ -6828,20 +6844,21 @@ var createLiveStateMiddleware = function (config) {
6828
6844
  };
6829
6845
  };
6830
6846
  var logLiveState = function (action, liveStateDataId) {
6831
- var _a;
6832
- if (window.Velt) {
6833
- var sessionId_2 = getSessionId();
6834
- var liveStateElement = (_a = window === null || window === void 0 ? void 0 : window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement();
6835
- if (liveStateElement === null || liveStateElement === void 0 ? void 0 : liveStateElement.setLiveStateData) {
6836
- liveStateElement.setLiveStateData(liveStateDataId, {
6837
- id: sessionId_2,
6838
- action: action
6839
- });
6847
+ var _a, _b;
6848
+ try {
6849
+ if (window.Velt && ((_a = window === null || window === void 0 ? void 0 : window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
6850
+ var sessionId_2 = getSessionId();
6851
+ var liveStateElement = (_b = window === null || window === void 0 ? void 0 : window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
6852
+ if (liveStateElement === null || liveStateElement === void 0 ? void 0 : liveStateElement.setLiveStateData) {
6853
+ liveStateElement.setLiveStateData(liveStateDataId, {
6854
+ id: sessionId_2,
6855
+ action: action
6856
+ });
6857
+ }
6840
6858
  }
6841
- liveStateElement.setLiveStateData(liveStateDataId, {
6842
- id: sessionId_2,
6843
- action: action
6844
- });
6859
+ }
6860
+ catch (err) {
6861
+ // handle error
6845
6862
  }
6846
6863
  };
6847
6864