UNPKG

rosetty-solid

Version:

[![Maintainability](https://api.codeclimate.com/v1/badges/a777c53f5370b6900930/maintainability)](https://codeclimate.com/github/qlaffont/rosetty-solid/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/a777c53f5370b6900930/test_cover

83 lines (80 loc) 2.56 kB
var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __hasOwnProp = Object.prototype.hasOwnProperty; function __accessProp(key) { return this[key]; } var __toCommonJS = (from) => { var entry = (__moduleCache ??= new WeakMap).get(from), desc; if (entry) return entry; entry = __defProp({}, "__esModule", { value: true }); if (from && typeof from === "object" || typeof from === "function") { for (var key of __getOwnPropNames(from)) if (!__hasOwnProp.call(entry, key)) __defProp(entry, key, { get: __accessProp.bind(from, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } __moduleCache.set(from, entry); return entry; }; var __moduleCache; var __returnValue = (v) => v; function __exportSetter(name, newValue) { this[name] = __returnValue.bind(null, newValue); } var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true, configurable: true, set: __exportSetter.bind(all, name) }); }; // src/index.ts var exports_src = {}; __export(exports_src, { useRosetty: () => useRosetty, RosettyProvider: () => RosettyProvider, RosettyContext: () => RosettyContext }); module.exports = __toCommonJS(exports_src); var import_rosetty = require("rosetty"); var import_solid_js = require("solid-js"); var bootstrapRosetty = import_rosetty.rosetty; var RosettyContext = import_solid_js.createContext(); var RosettyProvider = (props) => { const [r, setLastR] = import_solid_js.createSignal(bootstrapRosetty(props.languages, props.defaultLanguage, props.translateFallback), { equals: false }); const [actualLang, setActualLang] = import_solid_js.createSignal(props.defaultLanguage); const changeLang = (lang) => { r().changeLang(lang); setActualLang(r().getCurrentLang()); setLastR(r()); }; const returnValue = import_solid_js.createMemo(() => ({ ...r(), actualLang, changeLang })); return import_solid_js.createComponent(RosettyContext.Provider, { get value() { return returnValue; }, get children() { return props.children; } }); }; function useRosetty() { const client = import_solid_js.useContext(RosettyContext); if (!client) { throw new Error("No RosettyClient set, use RosettyProvider to set one"); } return client; } //# debugId=ED25E97A92CE620C64756E2164756E21 //# sourceMappingURL=index.js.map