solid-use
Version:
A collection of SolidJS utilities
80 lines (78 loc) • 2.48 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/client-only.ts
var client_only_exports = {};
__export(client_only_exports, {
ClientOnly: () => ClientOnly,
clientComponent: () => clientComponent,
clientOnly: () => clientOnly,
createClientSignal: () => createClientSignal
});
module.exports = __toCommonJS(client_only_exports);
var import_solid_js = require("solid-js");
var import_web = require("solid-js/web");
var createClientSignal = import_web.isServer ? () => () => false : () => {
const [flag, setFlag] = (0, import_solid_js.createSignal)(false);
(0, import_solid_js.onMount)(() => {
setFlag(true);
});
return flag;
};
var ClientOnly = (props) => {
const isClient = createClientSignal();
return (0, import_solid_js.Show)({
keyed: false,
get when() {
return isClient();
},
get fallback() {
return props.fallback;
},
get children() {
return props.children;
}
});
};
function clientOnly(fn) {
const Lazy = (0, import_solid_js.lazy)(fn);
return (props) => {
if (import_solid_js.sharedConfig.context) {
const isClient = createClientSignal();
return (0, import_solid_js.createMemo)(() => {
if (isClient()) {
return (0, import_solid_js.createComponent)(Lazy, props);
}
return void 0;
});
}
return (0, import_solid_js.createComponent)(Lazy, props);
};
}
function clientComponent(Comp) {
return (props) => {
const isClient = createClientSignal();
return (0, import_solid_js.createMemo)(() => {
if (isClient()) {
return (0, import_solid_js.createComponent)(Comp, props);
}
return void 0;
});
};
}
//# sourceMappingURL=client-only.cjs.map