@veltdev/react 1.0.118 → 1.0.119
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 +31 -4
- package/cjs/index.js.map +1 -1
- package/cjs/types/hooks/LiveStateSyncElement.d.ts +4 -1
- package/esm/index.js +31 -4
- package/esm/index.js.map +1 -1
- package/esm/types/hooks/LiveStateSyncElement.d.ts +4 -1
- package/index.d.ts +4 -1
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -1992,18 +1992,45 @@ function useEditorAccessRequestHandler() {
|
|
|
1992
1992
|
/**
|
|
1993
1993
|
* @beta This hook is in beta
|
|
1994
1994
|
*/
|
|
1995
|
-
function useLiveState(liveStateDataId, initialValue,
|
|
1996
|
-
if (debounceTime === void 0) { debounceTime = 50; }
|
|
1995
|
+
function useLiveState(liveStateDataId, initialValue, options) {
|
|
1997
1996
|
var liveStateSyncElement = useLiveStateSyncUtils();
|
|
1998
|
-
var
|
|
1997
|
+
var client = useVeltClient().client;
|
|
1998
|
+
var _a = React__default["default"].useState(null), documentId = _a[0], setDocumentId = _a[1];
|
|
1999
|
+
var _b = React__default["default"].useState(null), user = _b[0], setUser = _b[1];
|
|
2000
|
+
var _c = React__default["default"].useState(initialValue), data = _c[0], setData = _c[1];
|
|
2001
|
+
React.useEffect(function () {
|
|
2002
|
+
resetLiveStateData();
|
|
2003
|
+
}, [documentId, user]);
|
|
2004
|
+
var resetLiveStateData = function () {
|
|
2005
|
+
if (user && documentId) {
|
|
2006
|
+
liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.setLiveStateData(liveStateDataId, data);
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
1999
2009
|
React.useEffect(function () {
|
|
2000
2010
|
if (!(liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData))
|
|
2001
2011
|
return;
|
|
2012
|
+
var documentPathsSubscription, userSubscription;
|
|
2013
|
+
if (options === null || options === void 0 ? void 0 : options.resetLiveState) {
|
|
2014
|
+
documentPathsSubscription = client.docService.getDocumentPaths$().subscribe(function (paths) {
|
|
2015
|
+
if (paths) {
|
|
2016
|
+
setDocumentId(paths === null || paths === void 0 ? void 0 : paths.documentId);
|
|
2017
|
+
documentPathsSubscription === null || documentPathsSubscription === void 0 ? void 0 : documentPathsSubscription.unsubscribe();
|
|
2018
|
+
}
|
|
2019
|
+
});
|
|
2020
|
+
userSubscription = client.authService.getUser$().subscribe(function (user) {
|
|
2021
|
+
if (user) {
|
|
2022
|
+
setUser(user);
|
|
2023
|
+
userSubscription === null || userSubscription === void 0 ? void 0 : userSubscription.unsubscribe();
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2002
2027
|
var subscription = liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (res) {
|
|
2003
2028
|
setData(res);
|
|
2004
2029
|
});
|
|
2005
2030
|
return function () {
|
|
2006
2031
|
subscription.unsubscribe();
|
|
2032
|
+
documentPathsSubscription === null || documentPathsSubscription === void 0 ? void 0 : documentPathsSubscription.unsubscribe();
|
|
2033
|
+
userSubscription === null || userSubscription === void 0 ? void 0 : userSubscription.unsubscribe();
|
|
2007
2034
|
};
|
|
2008
2035
|
}, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData]);
|
|
2009
2036
|
var useDebounce = function (callback) {
|
|
@@ -2024,7 +2051,7 @@ function useLiveState(liveStateDataId, initialValue, debounceTime) {
|
|
|
2024
2051
|
};
|
|
2025
2052
|
var setDataFunction = function (value) {
|
|
2026
2053
|
setData(value);
|
|
2027
|
-
debouncedOnInput(value,
|
|
2054
|
+
debouncedOnInput(value, (options === null || options === void 0 ? void 0 : options.syncDuration) >= 0 ? options === null || options === void 0 ? void 0 : options.syncDuration : 50); // default 50ms debounce time
|
|
2028
2055
|
};
|
|
2029
2056
|
var debouncedOnInput = useDebounce(function (value) {
|
|
2030
2057
|
if (liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.setLiveStateData) {
|