@knocklabs/react-core
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),d=require("react"),l=require("../hooks/useAuthenticatedKnockClient.js"),k=require("../../i18n/context/KnockI18nProvider.js");require("date-fns/locale");function f(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const c=f(d),i=c.createContext(null),v=({apiKey:e,host:n,userId:t,userToken:r,children:u,i18n:s})=>{const a=l(e,t,r,{host:n});return o.jsx(i.Provider,{value:{knock:a},children:o.jsx(k.KnockI18nProvider,{i18n:s,children:u})})},b=()=>{const e=c.useContext(i);if(e===void 0)throw new Error("useKnock must be used within a KnockProvider");return e.knock};exports.KnockProvider=v;exports.useKnockClient=b; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),d=require("react"),l=require("../hooks/useAuthenticatedKnockClient.js"),k=require("../../i18n/context/KnockI18nProvider.js");function f(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const c=f(d),i=c.createContext(null),v=({apiKey:e,host:n,userId:t,userToken:o,children:u,i18n:s})=>{const a=l(e,t,o,{host:n});return r.jsx(i.Provider,{value:{knock:a},children:r.jsx(k.KnockI18nProvider,{i18n:s,children:u})})},b=()=>{const e=c.useContext(i);if(e===void 0)throw new Error("useKnock must be used within a KnockProvider");return e.knock};exports.KnockProvider=v;exports.useKnockClient=b; | ||
//# sourceMappingURL=KnockProvider.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("date-fns/formatDistance"),o=require("date-fns/parseISO"),a=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},c=a(n),u=a(o);function f(e){return e>9?"9+":e}function d(e,t={}){try{const r=u.default(e);return c.default(r,new Date,{addSuffix:!0,locale:t.locale})}catch{return e}}function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function i(e,t){return e!==void 0?e:t}function s(e,t={}){return[e,t.source,t.tenant,t.has_tenant,t.archived].filter(r=>r!=null).join("-")}exports.feedProviderKey=s;exports.formatBadgeCount=f;exports.formatTimestamp=d;exports.renderNodeOrFallback=i;exports.toSentenceCase=l; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("date-fns");function n(e){return e>9?"9+":e}function o(e,t={}){try{const r=a.parseISO(e);return a.intlFormatDistance(r,new Date,{locale:t.locale})}catch{return e}}function c(e){return e.charAt(0).toUpperCase()+e.slice(1)}function d(e,t){return e!==void 0?e:t}function u(e,t={}){return[e,t.source,t.tenant,t.has_tenant,t.archived].filter(r=>r!=null).join("-")}exports.feedProviderKey=u;exports.formatBadgeCount=n;exports.formatTimestamp=o;exports.renderNodeOrFallback=d;exports.toSentenceCase=c; | ||
//# sourceMappingURL=utils.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),s=require("date-fns/locale"),c=require("../languages/index.js"),i=require("../context/KnockI18nProvider.js");function u(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const r=u(s);function l(){const{translations:e,locale:t}=a.useContext(i.I18nContext);return{locale:t,t:n=>e[n]||c.locales.en.translations[n],dateFnsLocale:()=>t in r?r[t]:r.enUS}}exports.useTranslations=l; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),o=require("../languages/index.js"),s=require("../context/KnockI18nProvider.js");function a(){const{translations:n,locale:t}=r.useContext(s.I18nContext);return{locale:t,t:e=>n[e]||o.locales.en.translations[e]}}exports.useTranslations=a; | ||
//# sourceMappingURL=useTranslations.js.map |
import { jsx as t } from "react/jsx-runtime"; | ||
import * as r from "react"; | ||
import m from "../hooks/useAuthenticatedKnockClient.js"; | ||
import { KnockI18nProvider as d } from "../../i18n/context/KnockI18nProvider.js"; | ||
import "date-fns/locale"; | ||
const e = r.createContext(null), x = ({ | ||
import * as e from "react"; | ||
import d from "../hooks/useAuthenticatedKnockClient.js"; | ||
import { KnockI18nProvider as m } from "../../i18n/context/KnockI18nProvider.js"; | ||
const r = e.createContext( | ||
null | ||
), x = ({ | ||
apiKey: o, | ||
@@ -14,10 +15,16 @@ host: n, | ||
}) => { | ||
const k = m(o, c, i, { | ||
const k = d(o, c, i, { | ||
host: n | ||
}); | ||
return /* @__PURE__ */ t(e.Provider, { value: { | ||
knock: k | ||
}, children: /* @__PURE__ */ t(d, { i18n: u, children: s }) }); | ||
return /* @__PURE__ */ t( | ||
r.Provider, | ||
{ | ||
value: { | ||
knock: k | ||
}, | ||
children: /* @__PURE__ */ t(m, { i18n: u, children: s }) | ||
} | ||
); | ||
}, K = () => { | ||
const o = r.useContext(e); | ||
const o = e.useContext(r); | ||
if (o === void 0) | ||
@@ -24,0 +31,0 @@ throw new Error("useKnock must be used within a KnockProvider"); |
@@ -1,3 +0,2 @@ | ||
import a from "date-fns/formatDistance"; | ||
import n from "date-fns/parseISO"; | ||
import { parseISO as n, intlFormatDistance as a } from "date-fns"; | ||
function u(e) { | ||
@@ -10,3 +9,2 @@ return e > 9 ? "9+" : e; | ||
return a(t, /* @__PURE__ */ new Date(), { | ||
addSuffix: !0, | ||
locale: r.locale | ||
@@ -18,18 +16,24 @@ }); | ||
} | ||
function d(e) { | ||
function f(e) { | ||
return e.charAt(0).toUpperCase() + e.slice(1); | ||
} | ||
function m(e, r) { | ||
function l(e, r) { | ||
return e !== void 0 ? e : r; | ||
} | ||
function l(e, r = {}) { | ||
return [e, r.source, r.tenant, r.has_tenant, r.archived].filter((t) => t != null).join("-"); | ||
function d(e, r = {}) { | ||
return [ | ||
e, | ||
r.source, | ||
r.tenant, | ||
r.has_tenant, | ||
r.archived | ||
].filter((t) => t != null).join("-"); | ||
} | ||
export { | ||
l as feedProviderKey, | ||
d as feedProviderKey, | ||
u as formatBadgeCount, | ||
i as formatTimestamp, | ||
m as renderNodeOrFallback, | ||
d as toSentenceCase | ||
l as renderNodeOrFallback, | ||
f as toSentenceCase | ||
}; | ||
//# sourceMappingURL=utils.js.map |
@@ -8,3 +8,5 @@ import { jsx as u } from "react/jsx-runtime"; | ||
import "@knocklabs/client"; | ||
const i = n.createContext(null), F = ({ | ||
const i = n.createContext( | ||
null | ||
), F = ({ | ||
feedId: e, | ||
@@ -16,8 +18,15 @@ children: c, | ||
const t = k(), r = f(t, e, o), m = d(r.store); | ||
return /* @__PURE__ */ u(i.Provider, { value: { | ||
knock: t, | ||
feedClient: r, | ||
useFeedStore: m, | ||
colorMode: s | ||
}, children: c }, a(e, o)); | ||
return /* @__PURE__ */ u( | ||
i.Provider, | ||
{ | ||
value: { | ||
knock: t, | ||
feedClient: r, | ||
useFeedStore: m, | ||
colorMode: s | ||
}, | ||
children: c | ||
}, | ||
a(e, o) | ||
); | ||
}, P = () => { | ||
@@ -24,0 +33,0 @@ const e = n.useContext(i); |
@@ -15,6 +15,3 @@ import { useState as o, useEffect as f } from "react"; | ||
r(); | ||
}, []), { | ||
settings: i, | ||
loading: c | ||
}; | ||
}, []), { settings: i, loading: c }; | ||
} | ||
@@ -21,0 +18,0 @@ export { |
@@ -8,3 +8,10 @@ import { useRef as a, useMemo as i } from "react"; | ||
return r.listenForUpdates(), t.current = r, r; | ||
}, [n, u, e.source, e.tenant, e.has_tenant, e.archived]); | ||
}, [ | ||
n, | ||
u, | ||
e.source, | ||
e.tenant, | ||
e.has_tenant, | ||
e.archived | ||
]); | ||
} | ||
@@ -11,0 +18,0 @@ export { |
@@ -1,19 +0,14 @@ | ||
import { useContext as e } from "react"; | ||
import * as n from "date-fns/locale"; | ||
import { useContext as r } from "react"; | ||
import { locales as s } from "../languages/index.js"; | ||
import { I18nContext as a } from "../context/KnockI18nProvider.js"; | ||
function c() { | ||
const { | ||
translations: r, | ||
locale: t | ||
} = e(a); | ||
import { I18nContext as e } from "../context/KnockI18nProvider.js"; | ||
function m() { | ||
const { translations: o, locale: n } = r(e); | ||
return { | ||
locale: t, | ||
t: (o) => r[o] || s.en.translations[o], | ||
dateFnsLocale: () => t in n ? n[t] : n.enUS | ||
locale: n, | ||
t: (t) => o[t] || s.en.translations[t] | ||
}; | ||
} | ||
export { | ||
c as useTranslations | ||
m as useTranslations | ||
}; | ||
//# sourceMappingURL=useTranslations.js.map |
import o from "./en.js"; | ||
import r from "./de.js"; | ||
const t = { | ||
en: o, | ||
de: r | ||
}; | ||
const t = { en: o, de: r }; | ||
export { | ||
@@ -8,0 +5,0 @@ t as locales |
import { FeedClientOptions } from "@knocklabs/client"; | ||
import { Locale } from "date-fns"; | ||
import { ReactNode } from "react"; | ||
export declare function formatBadgeCount(count: number): string | number; | ||
type FormatTimestampOptions = { | ||
locale?: Locale; | ||
locale?: string | string[]; | ||
}; | ||
@@ -8,0 +7,0 @@ export declare function formatTimestamp(ts: string, options?: FormatTimestampOptions): string; |
@@ -1,7 +0,5 @@ | ||
import { Locale as DateFnLocale } from "date-fns"; | ||
export declare function useTranslations(): { | ||
locale: string; | ||
t: (key: keyof import("../languages").Translations) => string | undefined; | ||
dateFnsLocale: () => DateFnLocale; | ||
}; | ||
//# sourceMappingURL=useTranslations.d.ts.map |
@@ -5,3 +5,3 @@ { | ||
"author": "@knocklabs", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -30,2 +30,7 @@ "main": "dist/cjs/index.js", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write", | ||
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"coverage": "vitest run --coverage", | ||
"preview": "vite preview" | ||
@@ -45,6 +50,7 @@ }, | ||
"@knocklabs/client": "*", | ||
"date-fns": "^2.24.0", | ||
"zustand": "^3.5.10" | ||
"date-fns": "^3.3.1", | ||
"zustand": "^3.7.2" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react": "^14.2.0", | ||
"@types/react": "^18.2.37", | ||
@@ -54,6 +60,7 @@ "@typescript-eslint/eslint-plugin": "^6.10.0", | ||
"@vitejs/plugin-react": "^4.2.0", | ||
"babel-plugin-date-fns": "^2.0.0", | ||
"eslint": "^8.53.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.4", | ||
"jsdom": "^24.0.0", | ||
"react": "^18.2.0", | ||
"rimraf": "^5.0.5", | ||
@@ -64,4 +71,5 @@ "rollup-plugin-execute": "^1.1.1", | ||
"vite-plugin-dts": "^3.6.3", | ||
"vite-plugin-no-bundle": "^3.0.0" | ||
"vite-plugin-no-bundle": "^3.0.0", | ||
"vitest": "^1.2.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
448
9
0
61602
17
+ Addeddate-fns@3.6.0(transitive)
- Removeddate-fns@2.30.0(transitive)
Updateddate-fns@^3.3.1
Updatedzustand@^3.7.2