@hanzogui/use-did-finish-ssr 2.0.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.
- package/LICENSE +21 -0
- package/dist/cjs/ClientOnly.cjs +39 -0
- package/dist/cjs/ClientOnly.native.js +43 -0
- package/dist/cjs/ClientOnly.native.js.map +1 -0
- package/dist/cjs/index.cjs +51 -0
- package/dist/cjs/index.native.js +60 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/ClientOnly.mjs +15 -0
- package/dist/esm/ClientOnly.mjs.map +1 -0
- package/dist/esm/ClientOnly.native.js +16 -0
- package/dist/esm/ClientOnly.native.js.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +13 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +19 -0
- package/dist/esm/index.native.js.map +1 -0
- package/package.json +43 -0
- package/src/ClientOnly.tsx +18 -0
- package/src/index.ts +32 -0
- package/types/ClientOnly.d.ts +7 -0
- package/types/ClientOnly.d.ts.map +11 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var ClientOnly_exports = {};
|
|
22
|
+
__export(ClientOnly_exports, {
|
|
23
|
+
ClientOnly: () => ClientOnly,
|
|
24
|
+
ClientOnlyContext: () => ClientOnlyContext
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(ClientOnly_exports);
|
|
27
|
+
var import_react = require("react"),
|
|
28
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
const ClientOnlyContext = (0, import_react.createContext)(!1),
|
|
30
|
+
ClientOnly = ({
|
|
31
|
+
children,
|
|
32
|
+
enabled
|
|
33
|
+
}) => {
|
|
34
|
+
const existingValue = (0, import_react.useContext)(ClientOnlyContext);
|
|
35
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ClientOnlyContext.Provider, {
|
|
36
|
+
value: enabled ?? existingValue,
|
|
37
|
+
children
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var ClientOnly_exports = {};
|
|
24
|
+
__export(ClientOnly_exports, {
|
|
25
|
+
ClientOnly: () => ClientOnly,
|
|
26
|
+
ClientOnlyContext: () => ClientOnlyContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(ClientOnly_exports);
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime"),
|
|
30
|
+
import_react = require("react"),
|
|
31
|
+
ClientOnlyContext = /* @__PURE__ */(0, import_react.createContext)(!1),
|
|
32
|
+
ClientOnly = function (param) {
|
|
33
|
+
var {
|
|
34
|
+
children,
|
|
35
|
+
enabled
|
|
36
|
+
} = param,
|
|
37
|
+
existingValue = (0, import_react.useContext)(ClientOnlyContext);
|
|
38
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ClientOnlyContext.Provider, {
|
|
39
|
+
value: enabled ?? existingValue,
|
|
40
|
+
children
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=ClientOnly.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","ClientOnly_exports","__export","ClientOnly","ClientOnlyContext","module","exports","import_jsx_runtime","require","import_react","createContext","param","children","enabled","existingValue","useContext","jsx","Provider"],"sources":["../../src/ClientOnly.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,kBAAA;AAAAC,QAAA,CAAAD,kBAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAA,UAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAA0C,CAAAK,kBAatC;AAXG,IAAAM,kBAAM,GAAAC,OAA4C;EAAAC,YAE5C,GAAAD,OAAc;EAAAJ,iBAAA,sBAAAK,YAAA,CAAAC,aAAA;EAAAP,UAAA,YAAAA,CAAAQ,KAAA;IACzB;QAAAC,QAAA;QAAAC;MAAA,IAAAF,KAAA;MAAAG,aAAA,OAAAL,YAAA,CAAAM,UAAA,EAAAX,iBAAA;IACA,0BAAAG,kBAAA,CAAAS,GAAA,EAAAZ,iBAAA,CAAAa,QAAA;MACFjB,KAGuB,EAAAa,OAAA,IAAAC,aAAA;MACrBF;IACA;EAKF","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
ClientOnly: () => import_ClientOnly2.ClientOnly,
|
|
35
|
+
ClientOnlyContext: () => import_ClientOnly2.ClientOnlyContext,
|
|
36
|
+
useClientValue: () => useClientValue,
|
|
37
|
+
useDidFinishSSR: () => useDidFinishSSR,
|
|
38
|
+
useIsClientOnly: () => useIsClientOnly
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
var React = __toESM(require("react"), 1),
|
|
42
|
+
import_ClientOnly = require("./ClientOnly.cjs"),
|
|
43
|
+
import_ClientOnly2 = require("./ClientOnly.cjs");
|
|
44
|
+
const useIsClientOnly = () => React.useContext(import_ClientOnly.ClientOnlyContext);
|
|
45
|
+
function useDidFinishSSR() {
|
|
46
|
+
return React.useContext(import_ClientOnly.ClientOnlyContext) ? !0 : React.useSyncExternalStore(subscribe, () => !0, () => !1);
|
|
47
|
+
}
|
|
48
|
+
const subscribe = () => () => {};
|
|
49
|
+
function useClientValue(value) {
|
|
50
|
+
return useDidFinishSSR() ? typeof value == "function" ? value() : value : void 0;
|
|
51
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
33
|
+
}), mod);
|
|
34
|
+
var index_exports = {};
|
|
35
|
+
__export(index_exports, {
|
|
36
|
+
ClientOnly: () => import_ClientOnly2.ClientOnly,
|
|
37
|
+
ClientOnlyContext: () => import_ClientOnly2.ClientOnlyContext,
|
|
38
|
+
useClientValue: () => useClientValue,
|
|
39
|
+
useDidFinishSSR: () => useDidFinishSSR,
|
|
40
|
+
useIsClientOnly: () => useIsClientOnly
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
var React = __toESM(require("react"), 1),
|
|
44
|
+
import_ClientOnly = require("./ClientOnly.native.js"),
|
|
45
|
+
import_ClientOnly2 = require("./ClientOnly.native.js"),
|
|
46
|
+
useIsClientOnly = function () {
|
|
47
|
+
return React.useContext(import_ClientOnly.ClientOnlyContext);
|
|
48
|
+
};
|
|
49
|
+
function useDidFinishSSR() {
|
|
50
|
+
var clientOnly = React.useContext(import_ClientOnly.ClientOnlyContext);
|
|
51
|
+
return !0;
|
|
52
|
+
}
|
|
53
|
+
var subscribe = function () {
|
|
54
|
+
return function () {};
|
|
55
|
+
};
|
|
56
|
+
function useClientValue(value) {
|
|
57
|
+
var done = useDidFinishSSR();
|
|
58
|
+
return done ? typeof value == "function" ? value() : value : void 0;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","ClientOnly","import_ClientOnly2","ClientOnlyContext","useClientValue","useDidFinishSSR","useIsClientOnly","module","exports","React","__toESM","require","import_ClientOnly","useContext","clientOnly","subscribe","done"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAC,kBAAA,CAAAD,UAAA;EAAAE,iBAAA,EAAAA,CAAA,KAAAD,kBAAA,CAAAC,iBAAA;EAAAC,cAAA,EAAAA,CAAA,KAAAA,cAAA;EAAAC,eAAA,EAAAA,CAAA,KAAAA,eAAA;EAAAC,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAuB,GAAAd,YAAA,CAAAK,aACvB;AAIO,IAAAU,KAAM,GAAAC,OAAA,CAAAC,OAAkB,QACtB,CAAM;EAAAC,iBAAW,GAAAD,OAAA,yBAAiB;EAAAT,kBAAA,GAAAS,OAAA;EAAAL,eAAA,YAAAA,CAAA;IAGpC,OAASG,KAAA,CAAAI,UAAA,CAAAD,iBAA2B,CAAAT,iBAAA;EAGzC;AAIa,SACXE,gBAAA;EAAA,IACAS,UAAM,GAAAL,KAAA,CAAAI,UAAA,CAAAD,iBAAA,CAAAT,iBAAA;EAAA,OACN,CAAM;AAAA;AAEV,IAAAY,SAAA,YAAAA,CAAA;EAEA,OAAM,YAAY,CAAa;AAIxB;AAGL,SAFaX,eAAAN,KAEc;EAC7B,IAAAkB,IAAA,GAAAX,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
const ClientOnlyContext = createContext(!1),
|
|
4
|
+
ClientOnly = ({
|
|
5
|
+
children,
|
|
6
|
+
enabled
|
|
7
|
+
}) => {
|
|
8
|
+
const existingValue = useContext(ClientOnlyContext);
|
|
9
|
+
return /* @__PURE__ */jsx(ClientOnlyContext.Provider, {
|
|
10
|
+
value: enabled ?? existingValue,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export { ClientOnly, ClientOnlyContext };
|
|
15
|
+
//# sourceMappingURL=ClientOnly.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","useContext","jsx","ClientOnlyContext","ClientOnly","children","enabled","existingValue","Provider","value"],"sources":["../../src/ClientOnly.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,aAAA,EAAeC,UAAA,QAAkB;AAatC,SAAAC,GAAA;AAXG,MAAMC,iBAAA,GAA4CH,aAAA,CAAc,EAAK;EAE/DI,UAAA,GAAaA,CAAC;IACzBC,QAAA;IACAC;EACF,MAGuB;IACrB,MAAMC,aAAA,GAAgBN,UAAA,CAAWE,iBAAiB;IAClD,OACE,eAAAD,GAAA,CAACC,iBAAA,CAAkBK,QAAA,EAAlB;MAA2BC,KAAA,EAAOH,OAAA,IAAWC,aAAA;MAC3CF;IAAA,CACH;EAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
var ClientOnlyContext = /* @__PURE__ */createContext(!1),
|
|
4
|
+
ClientOnly = function (param) {
|
|
5
|
+
var {
|
|
6
|
+
children,
|
|
7
|
+
enabled
|
|
8
|
+
} = param,
|
|
9
|
+
existingValue = useContext(ClientOnlyContext);
|
|
10
|
+
return /* @__PURE__ */_jsx(ClientOnlyContext.Provider, {
|
|
11
|
+
value: enabled ?? existingValue,
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export { ClientOnly, ClientOnlyContext };
|
|
16
|
+
//# sourceMappingURL=ClientOnly.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","createContext","useContext","ClientOnlyContext","ClientOnly","param","children","enabled","existingValue","Provider","value"],"sources":["../../src/ClientOnly.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,QAAe,mBAAkB;AAatC,SAAAC,aAAA,EAAAC,UAAA;AAXG,IAAAC,iBAAM,kBAA0DF,aAE1D;EAAcG,UAAA,YAAAA,CAAAC,KAAA;IACzB;QAAAC,QAAA;QAAAC;MAAA,IAAAF,KAAA;MAAAG,aAAA,GAAAN,UAAA,CAAAC,iBAAA;IACA,sBAAAH,IAAA,CAAAG,iBAAA,CAAAM,QAAA;MACFC,KAGuB,EAAAH,OAAA,IAAAC,aAAA;MACrBF;IACA;EAKF","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ClientOnlyContext } from "./ClientOnly.mjs";
|
|
3
|
+
import { ClientOnly, ClientOnlyContext as ClientOnlyContext2 } from "./ClientOnly.mjs";
|
|
4
|
+
const useIsClientOnly = () => React.useContext(ClientOnlyContext);
|
|
5
|
+
function useDidFinishSSR() {
|
|
6
|
+
return React.useContext(ClientOnlyContext) ? !0 : React.useSyncExternalStore(subscribe, () => !0, () => !1);
|
|
7
|
+
}
|
|
8
|
+
const subscribe = () => () => {};
|
|
9
|
+
function useClientValue(value) {
|
|
10
|
+
return useDidFinishSSR() ? typeof value == "function" ? value() : value : void 0;
|
|
11
|
+
}
|
|
12
|
+
export { ClientOnly, ClientOnlyContext2 as ClientOnlyContext, useClientValue, useDidFinishSSR, useIsClientOnly };
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","ClientOnlyContext","ClientOnly","ClientOnlyContext2","useIsClientOnly","useContext","useDidFinishSSR","useSyncExternalStore","subscribe","useClientValue","value"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,iBAAA,QAAyB;AAElC,SAASC,UAAA,EAAYD,iBAAA,IAAAE,kBAAA,QAAyB;AAEvC,MAAMC,eAAA,GAAkBA,CAAA,KACtBJ,KAAA,CAAMK,UAAA,CAAWJ,iBAAiB;AAGpC,SAASK,gBAAA,EAA2B;EAGzC,OAFmBN,KAAA,CAAMK,UAAA,CAAWJ,iBAAiB,IAG5C,KAGFD,KAAA,CAAMO,oBAAA,CACXC,SAAA,EACA,MAAM,IACN,MAAM,EACR;AACF;AAEA,MAAMA,SAAA,GAAYA,CAAA,KAAM,MAAM,CAAC;AAIxB,SAASC,eAAsBC,KAAA,EAAmD;EAGvF,OAFaJ,eAAA,CAAgB,IAEF,OAAOI,KAAA,IAAU,aAAaA,KAAA,CAAM,IAAIA,KAAA,GAApD;AACjB","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ClientOnlyContext } from "./ClientOnly.mjs";
|
|
3
|
+
import { ClientOnly, ClientOnlyContext as ClientOnlyContext2 } from "./ClientOnly.mjs";
|
|
4
|
+
const useIsClientOnly = () => React.useContext(ClientOnlyContext);
|
|
5
|
+
function useDidFinishSSR() {
|
|
6
|
+
return React.useContext(ClientOnlyContext) ? !0 : React.useSyncExternalStore(subscribe, () => !0, () => !1);
|
|
7
|
+
}
|
|
8
|
+
const subscribe = () => () => {};
|
|
9
|
+
function useClientValue(value) {
|
|
10
|
+
return useDidFinishSSR() ? typeof value == "function" ? value() : value : void 0;
|
|
11
|
+
}
|
|
12
|
+
export { ClientOnly, ClientOnlyContext2 as ClientOnlyContext, useClientValue, useDidFinishSSR, useIsClientOnly };
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","ClientOnlyContext","ClientOnly","ClientOnlyContext2","useIsClientOnly","useContext","useDidFinishSSR","useSyncExternalStore","subscribe","useClientValue","value"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,iBAAA,QAAyB;AAElC,SAASC,UAAA,EAAYD,iBAAA,IAAAE,kBAAA,QAAyB;AAEvC,MAAMC,eAAA,GAAkBA,CAAA,KACtBJ,KAAA,CAAMK,UAAA,CAAWJ,iBAAiB;AAGpC,SAASK,gBAAA,EAA2B;EAGzC,OAFmBN,KAAA,CAAMK,UAAA,CAAWJ,iBAAiB,IAG5C,KAGFD,KAAA,CAAMO,oBAAA,CACXC,SAAA,EACA,MAAM,IACN,MAAM,EACR;AACF;AAEA,MAAMA,SAAA,GAAYA,CAAA,KAAM,MAAM,CAAC;AAIxB,SAASC,eAAsBC,KAAA,EAAmD;EAGvF,OAFaJ,eAAA,CAAgB,IAEF,OAAOI,KAAA,IAAU,aAAaA,KAAA,CAAM,IAAIA,KAAA,GAApD;AACjB","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ClientOnlyContext } from "./ClientOnly.native.js";
|
|
3
|
+
import { ClientOnly, ClientOnlyContext as ClientOnlyContext2 } from "./ClientOnly.native.js";
|
|
4
|
+
var useIsClientOnly = function () {
|
|
5
|
+
return React.useContext(ClientOnlyContext);
|
|
6
|
+
};
|
|
7
|
+
function useDidFinishSSR() {
|
|
8
|
+
var clientOnly = React.useContext(ClientOnlyContext);
|
|
9
|
+
return !0;
|
|
10
|
+
}
|
|
11
|
+
var subscribe = function () {
|
|
12
|
+
return function () {};
|
|
13
|
+
};
|
|
14
|
+
function useClientValue(value) {
|
|
15
|
+
var done = useDidFinishSSR();
|
|
16
|
+
return done ? typeof value == "function" ? value() : value : void 0;
|
|
17
|
+
}
|
|
18
|
+
export { ClientOnly, ClientOnlyContext2 as ClientOnlyContext, useClientValue, useDidFinishSSR, useIsClientOnly };
|
|
19
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","ClientOnlyContext","ClientOnly","ClientOnlyContext2","useIsClientOnly","useContext","useDidFinishSSR","clientOnly","subscribe","useClientValue","value","done"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,iBAAA,QAAyB;AAElC,SAASC,UAAA,EAAYD,iBAAA,IAAAE,kBAAA,QAAyB;AAEvC,IAAAC,eAAM,YAAAA,CAAA,EACJ;EAGF,OAASJ,KAAA,CAAAK,UAAA,CAAAJ,iBAA2B;AAGzC;AAIa,SACXK,gBAAA;EAAA,IACAC,UAAM,GAAAP,KAAA,CAAAK,UAAA,CAAAJ,iBAAA;EAAA,OACN,CAAM;AAAA;AAEV,IAAAO,SAAA,YAAAA,CAAA;EAEA,OAAM,YAAY,CAAa;AAIxB;AAGL,SAFaC,eAAAC,KAEc;EAC7B,IAAAC,IAAA,GAAAL,eAAA","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/use-did-finish-ssr",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
|
+
"files": [
|
|
6
|
+
"src",
|
|
7
|
+
"types",
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "dist/cjs",
|
|
13
|
+
"module": "dist/esm",
|
|
14
|
+
"types": "./types/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./types/index.d.ts",
|
|
19
|
+
"react-native": "./dist/esm/index.native.js",
|
|
20
|
+
"browser": "./dist/esm/index.mjs",
|
|
21
|
+
"module": "./dist/esm/index.mjs",
|
|
22
|
+
"import": "./dist/esm/index.mjs",
|
|
23
|
+
"require": "./dist/cjs/index.cjs",
|
|
24
|
+
"default": "./dist/esm/index.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "hanzo-gui-build",
|
|
32
|
+
"watch": "hanzo-gui-build --watch",
|
|
33
|
+
"clean": "hanzo-gui-build clean",
|
|
34
|
+
"clean:build": "hanzo-gui-build clean:build"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@hanzogui/build": "workspace:*",
|
|
38
|
+
"react": ">=19"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": ">=19"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
export const ClientOnlyContext: React.Context<boolean> = createContext(false)
|
|
4
|
+
|
|
5
|
+
export const ClientOnly = ({
|
|
6
|
+
children,
|
|
7
|
+
enabled,
|
|
8
|
+
}: {
|
|
9
|
+
children: any
|
|
10
|
+
enabled?: boolean
|
|
11
|
+
}): React.ReactNode => {
|
|
12
|
+
const existingValue = useContext(ClientOnlyContext)
|
|
13
|
+
return (
|
|
14
|
+
<ClientOnlyContext.Provider value={enabled ?? existingValue}>
|
|
15
|
+
{children}
|
|
16
|
+
</ClientOnlyContext.Provider>
|
|
17
|
+
)
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ClientOnlyContext } from './ClientOnly'
|
|
3
|
+
|
|
4
|
+
export { ClientOnly, ClientOnlyContext } from './ClientOnly'
|
|
5
|
+
|
|
6
|
+
export const useIsClientOnly = (): boolean => {
|
|
7
|
+
return React.useContext(ClientOnlyContext)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useDidFinishSSR(): boolean {
|
|
11
|
+
const clientOnly = React.useContext(ClientOnlyContext)
|
|
12
|
+
|
|
13
|
+
if (clientOnly || process.env.HANZO_GUI_TARGET === 'native') {
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return React.useSyncExternalStore(
|
|
18
|
+
subscribe,
|
|
19
|
+
() => true,
|
|
20
|
+
() => false
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const subscribe = () => () => {}
|
|
25
|
+
|
|
26
|
+
type FunctionOrValue<Value> = Value extends () => infer X ? X : Value
|
|
27
|
+
|
|
28
|
+
export function useClientValue<Value>(value?: Value): FunctionOrValue<Value> | undefined {
|
|
29
|
+
const done = useDidFinishSSR()
|
|
30
|
+
// @ts-expect-error this is fine but started to error in ts latest
|
|
31
|
+
return !done ? undefined : typeof value === 'function' ? value() : value
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAEA,OAAO,cAAM,mBAAmB,MAAM;AAEtC,OAAO,cAAM,aAAc,EACzB,UACA,WACC;CACD;CACA;MACE,MAAM",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/ClientOnly.tsx"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"import { createContext, useContext } from 'react'\n\nexport const ClientOnlyContext: React.Context<boolean> = createContext(false)\n\nexport const ClientOnly = ({\n children,\n enabled,\n}: {\n children: any\n enabled?: boolean\n}): React.ReactNode => {\n const existingValue = useContext(ClientOnlyContext)\n return (\n <ClientOnlyContext.Provider value={enabled ?? existingValue}>\n {children}\n </ClientOnlyContext.Provider>\n )\n}\n"
|
|
10
|
+
]
|
|
11
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ClientOnly, ClientOnlyContext } from "./ClientOnly";
|
|
2
|
+
export declare const useIsClientOnly: () => boolean;
|
|
3
|
+
export declare function useDidFinishSSR(): boolean;
|
|
4
|
+
type FunctionOrValue<Value> = Value extends () => infer X ? X : Value;
|
|
5
|
+
export declare function useClientValue<Value>(value?: Value): FunctionOrValue<Value> | undefined;
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAGA,SAAS,YAAY,yBAAyB;AAE9C,OAAO,cAAM;AAIb,OAAO,iBAAS;KAgBX,gBAAgB,SAAS,0BAA0B,IAAI,IAAI;AAEhE,OAAO,iBAAS,eAAe,OAAO,QAAQ,QAAQ,gBAAgB",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/index.ts"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"import * as React from 'react'\nimport { ClientOnlyContext } from './ClientOnly'\n\nexport { ClientOnly, ClientOnlyContext } from './ClientOnly'\n\nexport const useIsClientOnly = (): boolean => {\n return React.useContext(ClientOnlyContext)\n}\n\nexport function useDidFinishSSR(): boolean {\n const clientOnly = React.useContext(ClientOnlyContext)\n\n if (clientOnly || process.env.HANZO_GUI_TARGET === 'native') {\n return true\n }\n\n return React.useSyncExternalStore(\n subscribe,\n () => true,\n () => false\n )\n}\n\nconst subscribe = () => () => {}\n\ntype FunctionOrValue<Value> = Value extends () => infer X ? X : Value\n\nexport function useClientValue<Value>(value?: Value): FunctionOrValue<Value> | undefined {\n const done = useDidFinishSSR()\n // @ts-expect-error this is fine but started to error in ts latest\n return !done ? undefined : typeof value === 'function' ? value() : value\n}\n"
|
|
10
|
+
]
|
|
11
|
+
}
|