@knocklabs/react-core 0.1.1 → 0.1.2
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/dist/cjs/modules/core/constants.js.map +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/cjs/modules/core/utils.js +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useFeedSettings.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
- package/dist/cjs/modules/i18n/context/KnockI18nProvider.js.map +1 -1
- package/dist/cjs/modules/i18n/hooks/useTranslations.js.map +1 -1
- package/dist/cjs/modules/i18n/languages/de.js.map +1 -1
- package/dist/cjs/modules/i18n/languages/en.js.map +1 -1
- package/dist/cjs/modules/i18n/languages/index.js.map +1 -1
- package/dist/esm/{index.mjs → index.js} +11 -11
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules/core/{constants.mjs → constants.js} +1 -1
- package/dist/esm/modules/core/constants.js.map +1 -0
- package/dist/esm/modules/core/context/{KnockProvider.mjs → KnockProvider.js} +7 -15
- package/dist/esm/modules/core/context/KnockProvider.js.map +1 -0
- package/dist/esm/modules/core/hooks/{useAuthenticatedKnockClient.mjs → useAuthenticatedKnockClient.js} +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -0
- package/dist/esm/modules/core/utils.js +33 -0
- package/dist/esm/modules/core/utils.js.map +1 -0
- package/dist/esm/modules/feed/context/{KnockFeedProvider.mjs → KnockFeedProvider.js} +11 -20
- package/dist/esm/modules/feed/context/KnockFeedProvider.js.map +1 -0
- package/dist/esm/modules/feed/hooks/{useFeedSettings.mjs → useFeedSettings.js} +5 -2
- package/dist/esm/modules/feed/hooks/useFeedSettings.js.map +1 -0
- package/dist/esm/modules/feed/hooks/{useNotifications.mjs → useNotifications.js} +2 -9
- package/dist/esm/modules/feed/hooks/useNotifications.js.map +1 -0
- package/dist/esm/modules/i18n/context/{KnockI18nProvider.mjs → KnockI18nProvider.js} +2 -2
- package/dist/esm/modules/i18n/context/KnockI18nProvider.js.map +1 -0
- package/dist/esm/modules/i18n/hooks/{useTranslations.mjs → useTranslations.js} +7 -4
- package/dist/esm/modules/i18n/hooks/useTranslations.js.map +1 -0
- package/dist/esm/modules/i18n/languages/{de.mjs → de.js} +1 -1
- package/dist/esm/modules/i18n/languages/de.js.map +1 -0
- package/dist/esm/modules/i18n/languages/{en.mjs → en.js} +1 -1
- package/dist/esm/modules/i18n/languages/en.js.map +1 -0
- package/dist/esm/modules/i18n/languages/index.js +10 -0
- package/dist/esm/modules/i18n/languages/index.js.map +1 -0
- package/package.json +7 -4
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/modules/core/constants.mjs.map +0 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +0 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +0 -1
- package/dist/esm/modules/core/utils.mjs +0 -38
- package/dist/esm/modules/core/utils.mjs.map +0 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +0 -1
- package/dist/esm/modules/feed/hooks/useFeedSettings.mjs.map +0 -1
- package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +0 -1
- package/dist/esm/modules/i18n/context/KnockI18nProvider.mjs.map +0 -1
- package/dist/esm/modules/i18n/hooks/useTranslations.mjs.map +0 -1
- package/dist/esm/modules/i18n/languages/de.mjs.map +0 -1
- package/dist/esm/modules/i18n/languages/en.mjs.map +0 -1
- package/dist/esm/modules/i18n/languages/index.mjs +0 -7
- package/dist/esm/modules/i18n/languages/index.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus"],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus","All","Read","Unseen","Unread"],"mappings":"gFAAYA,IAAAA,GAAAA,IACVC,EAAAA,IAAM,MACNC,EAAAA,KAAO,OACPC,EAAAA,OAAS,SACTC,EAAAA,OAAS,SAJCJ,IAAAA,GAAAA,CAAAA,CAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock from \"@knocklabs/client\";\n\nimport { useAuthenticatedKnockClient } from \"../hooks\";\nimport { KnockI18nProvider, I18nContent } from \"../../i18n\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n\n // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n}\n\nexport const KnockProvider: React.FC<KnockProviderProps> = ({\n apiKey,\n host,\n userId,\n userToken,\n children,\n i18n,\n}) => {\n const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {\n host,\n });\n\n return (\n <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","KnockProvider","apiKey","host","userId","userToken","children","i18n","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context"],"mappings":"wlBAUMA,EAAuBC,
|
|
1
|
+
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock from \"@knocklabs/client\";\n\nimport { useAuthenticatedKnockClient } from \"../hooks\";\nimport { KnockI18nProvider, I18nContent } from \"../../i18n\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n\n // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n}\n\nexport const KnockProvider: React.FC<KnockProviderProps> = ({\n apiKey,\n host,\n userId,\n userToken,\n children,\n i18n,\n}) => {\n const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {\n host,\n });\n\n return (\n <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","createContext","KnockProvider","apiKey","host","userId","userToken","children","i18n","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":"wlBAUMA,EAAuBC,EAAMC,cACjC,IACF,EAiBaC,EAA8CA,CAAC,CAC1DC,OAAAA,EACAC,KAAAA,EACAC,OAAAA,EACAC,UAAAA,EACAC,SAAAA,EACAC,KAAAA,CACF,IAAM,CACJ,MAAMC,EAAQC,EAA4BP,EAAQE,EAAQC,EAAW,CACnEF,KAAAA,CAAAA,CACD,EAED,OACGO,MAAAZ,EAAqB,SAArB,CACC,MAAO,CACLU,MAAAA,CAAAA,EAGF,SAAAE,EAAAA,IAACC,EAAkB,kBAAA,CAAA,KAAAJ,EAAaD,SAAAA,EAAS,CAC3C,CAAA,CAEJ,EAEaM,EAAiBA,IAAa,CACnCC,MAAAA,EAAUd,EAAMe,WAAWhB,CAAoB,EACrD,GAAIe,IAAYE,OACR,MAAA,IAAIC,MAAM,8CAA8C,EAEhE,OAAOH,EAAQL,KACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport Knock, { KnockOptions } from \"@knocklabs/client\";\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken: string | undefined,\n options: KnockOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return useMemo(() => {\n if (knockRef.current) knockRef.current.teardown();\n\n const knock = new Knock(apiKey, options);\n knock.authenticate(userId, userToken);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["useAuthenticatedKnockClient","apiKey","userId","userToken","options","knockRef","React","useMemo","knock","Knock"],"mappings":"2IAGA,SAASA,EACPC,EACAC,EACAC,EACAC,EAAwB,CAAA,EACxB,
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport Knock, { KnockOptions } from \"@knocklabs/client\";\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken: string | undefined,\n options: KnockOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return useMemo(() => {\n if (knockRef.current) knockRef.current.teardown();\n\n const knock = new Knock(apiKey, options);\n knock.authenticate(userId, userToken);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["useAuthenticatedKnockClient","apiKey","userId","userToken","options","knockRef","React","useRef","useMemo","current","teardown","knock","Knock","authenticate"],"mappings":"2IAGA,SAASA,EACPC,EACAC,EACAC,EACAC,EAAwB,CAAA,EACxB,CACMC,MAAAA,EAAWC,UAAMC,SAEvB,OAAOC,UAAQ,IAAM,CACfH,EAASI,SAASJ,EAASI,QAAQC,WAEvC,MAAMC,EAAQ,IAAIC,EAAAA,QAAMX,EAAQG,CAAO,EACjCS,OAAAA,EAAAA,aAAaX,EAAQC,CAAS,EACpCE,EAASI,QAAUE,EAEZA,CACN,EAAA,CAACV,EAAQC,EAAQC,CAAS,CAAC,CAChC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"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;
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { parseISO, formatDistance, Locale } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: Locale;\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = formatDistance(parsedTs, new Date(), {\n addSuffix: true,\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatDistance","toSentenceCase","string","renderNodeOrFallback","node","fallback","feedProviderKey","userFeedId","f"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { parseISO, formatDistance, Locale } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: Locale;\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = formatDistance(parsedTs, new Date(), {\n addSuffix: true,\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatted","formatDistance","Date","addSuffix","locale","toSentenceCase","string","charAt","toUpperCase","slice","renderNodeOrFallback","node","fallback","undefined","feedProviderKey","userFeedId","source","tenant","has_tenant","archived","filter","f","join"],"mappings":"gOAIO,SAASA,EAAiBC,EAAgC,CACxDA,OAAAA,EAAQ,EAAI,KAAOA,CAC5B,CAMO,SAASC,EACdC,EACAC,EAAkC,GAClC,CACI,GAAA,CACIC,MAAAA,EAAWC,UAASH,CAAE,EAMrBI,OALWC,EAAAA,QAAeH,EAAU,IAAII,KAAQ,CACrDC,UAAW,GACXC,OAAQP,EAAQO,MAAAA,CACjB,OAGS,CACHR,OAAAA,CACT,CACF,CAEO,SAASS,EAAeC,EAAwB,CAC9CA,OAAAA,EAAOC,OAAO,CAAC,EAAEC,cAAgBF,EAAOG,MAAM,CAAC,CACxD,CAEgBC,SAAAA,EAAqBC,EAAiBC,EAAqB,CAClED,OAAAA,IAASE,OAAYF,EAAOC,CACrC,CAMO,SAASE,EACdC,EACAlB,EAA6B,GAC7B,CACA,MAAO,CACLkB,EACAlB,EAAQmB,OACRnB,EAAQoB,OACRpB,EAAQqB,WACRrB,EAAQsB,QAAQ,EAEfC,UAAcC,GAAM,IAAuB,EAC3CC,KAAK,GAAG,CACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockFeedProvider.js","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport create, { StoreApi, UseStore } from \"zustand\";\n\nimport { ColorMode } from \"../../core/constants\";\nimport useNotifications from \"../hooks/useNotifications\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst FeedStateContext = React.createContext<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","jsx","feedProviderKey","useKnockFeed","context"],"mappings":"ssBAoBMA,EAAmBC,
|
|
1
|
+
{"version":3,"file":"KnockFeedProvider.js","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport create, { StoreApi, UseStore } from \"zustand\";\n\nimport { ColorMode } from \"../../core/constants\";\nimport useNotifications from \"../hooks/useNotifications\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst FeedStateContext = React.createContext<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","createContext","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","store","jsx","feedProviderKey","useKnockFeed","context","useContext","undefined","Error"],"mappings":"ssBAoBMA,EAAmBC,EAAMC,cAC7B,IACF,EAcaC,EAAsDA,CAAC,CAClEC,OAAAA,EACAC,SAAAA,EACAC,mBAAAA,EAAqB,CAAC,EACtBC,UAAAA,EAAY,OACd,IAAM,CACJ,MAAMC,EAAQC,EAAAA,iBAERC,EAAaC,EAAiBH,EAAOJ,EAAQE,CAAkB,EAC/DM,EAAeC,EAAAA,QAAOH,EAAWI,KAAkC,EAEzE,OACGC,MAAAf,EAAiB,SAAjB,CAEC,MAAO,CACLQ,MAAAA,EACAE,WAAAA,EACAE,aAAAA,EACAL,UAAAA,CAGDF,EAAAA,SAAAA,CAAAA,EARIW,EAAAA,gBAAgBZ,EAAQE,CAAkB,CASjD,CAEJ,EAEaW,EAAeA,IAA8B,CAClDC,MAAAA,EAAUjB,EAAMkB,WAAWnB,CAAgB,EACjD,GAAIkB,IAAYE,OACR,MAAA,IAAIC,MAAM,sDAAsD,EAEjEH,OAAAA,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","feedSettingsPath","response"],"mappings":"sCASA,SAASA,EAAgBC,EAGvB,CACA,KAAM,CAACC,EAAUC,CAAW,EAAIC,WAAS,IAAI,EACvC,CAACC,EAAWC,CAAY,EAAIF,WAAS,EAAK,EAIhDG,OAAAA,EAAAA,UAAU,IAAM,CACd,eAAeC,GAAc,CAC3B,MAAMC,EAAQR,
|
|
1
|
+
{"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","client","feedSettingsPath","userId","feedId","response","makeRequest","method","url","error","body","loading"],"mappings":"sCASA,SAASA,EAAgBC,EAGvB,CACA,KAAM,CAACC,EAAUC,CAAW,EAAIC,WAAS,IAAI,EACvC,CAACC,EAAWC,CAAY,EAAIF,WAAS,EAAK,EAIhDG,OAAAA,EAAAA,UAAU,IAAM,CACd,eAAeC,GAAc,CAC3B,MAAMC,EAAQR,EAAWQ,MACnBC,EAAYD,EAAME,SAClBC,EAAoB,aAAYH,EAAMI,MAAO,UAASZ,EAAWa,MAAO,YAC9ER,EAAa,EAAI,EAEXS,MAAAA,EAAW,MAAML,EAAUM,YAAY,CAC3CC,OAAQ,MACRC,IAAKN,CAAAA,CACN,EAEIG,EAASI,OACZhB,EAAYY,EAASK,IAAI,EAG3Bd,EAAa,EAAK,CACpB,CAEYE,GACd,EAAG,CAAE,CAAA,EAEE,CAAEN,SAAAA,EAAUmB,QAAShB,CAAAA,CAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nfunction useNotifications(\n knock: Knock,\n feedId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) feedClientRef.current.teardown();\n\n const feedClient = knock.feeds.initialize(feedId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\n }, [\n knock,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedId","options","feedClientRef","useRef","useMemo","feedClient"],"mappings":"sCAGA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,SAEtB,OAAOC,UAAQ,IAAM,CACfF,
|
|
1
|
+
{"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nfunction useNotifications(\n knock: Knock,\n feedId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) feedClientRef.current.teardown();\n\n const feedClient = knock.feeds.initialize(feedId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\n }, [\n knock,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedId","options","feedClientRef","useRef","useMemo","current","teardown","feedClient","feeds","initialize","listenForUpdates","source","tenant","has_tenant","archived"],"mappings":"sCAGA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,SAEtB,OAAOC,UAAQ,IAAM,CACfF,EAAcG,SAASH,EAAcG,QAAQC,WAEjD,MAAMC,EAAaR,EAAMS,MAAMC,WAAWT,EAAQC,CAAO,EAEzDM,OAAAA,EAAWG,iBAAiB,EAC5BR,EAAcG,QAAUE,EAEjBA,CACN,EAAA,CACDR,EACAC,EACAC,EAAQU,OACRV,EAAQW,OACRX,EAAQY,WACRZ,EAAQa,QAAQ,CACjB,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","locales","KnockI18nProvider","i18n","props"],"mappings":"0OAGaA,EAAcC,
|
|
1
|
+
{"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","createContext","locales","en","KnockI18nProvider","i18n","props"],"mappings":"0OAGaA,EAAcC,EAAAA,QAAMC,cAA2BC,EAAAA,QAAQC,EAAE,EAO/D,SAASC,EAAkB,CAChCC,KAAAA,EAAOH,EAAQC,QAAAA,GACf,GAAGG,CACmB,EAAG,CACzB,aAAQP,EAAY,SAAZ,CAAyBO,GAAAA,EAAO,MAAOD,CAAQ,CAAA,CACzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { Locale as DateFnLocale } from \"date-fns\";\nimport * as dateFnsLocales from \"date-fns/locale\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n dateFnsLocale: (): DateFnLocale => {\n return locale in dateFnsLocales\n ? dateFnsLocales[locale as keyof typeof dateFnsLocales]\n : dateFnsLocales.enUS;\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","key","locales","dateFnsLocales"],"mappings":"iiBAMO,SAASA,GAAkB,
|
|
1
|
+
{"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { Locale as DateFnLocale } from \"date-fns\";\nimport * as dateFnsLocales from \"date-fns/locale\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n dateFnsLocale: (): DateFnLocale => {\n return locale in dateFnsLocales\n ? dateFnsLocales[locale as keyof typeof dateFnsLocales]\n : dateFnsLocales.enUS;\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","t","key","locales","en","dateFnsLocale","dateFnsLocales","enUS"],"mappings":"iiBAMO,SAASA,GAAkB,CAC1B,KAAA,CAAEC,aAAAA,EAAcC,OAAAA,CAAAA,EAAWC,EAAAA,WAAwBC,EAAAA,WAAW,EAE7D,MAAA,CACLF,OAAAA,EACAG,EAAIC,GAEKL,EAAaK,CAAG,GAAKC,EAAAA,QAAQC,GAAGP,aAAaK,CAAG,EAEzDG,cAAeA,IACNP,KAAUQ,EACbA,EAAeR,CAAqC,EACpDQ,EAAeC,IACrB,CAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de"],"mappings":"aAEA,MAAMA,EAAkB,
|
|
1
|
+
{"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"aAEA,MAAMA,EAAkB,CACtBC,aAAc,CACZC,oBAAqB,+BACrBC,cAAe,6BACfC,cAAe,qBACfC,eAAgB,gCAChBC,cACE,0EACFC,IAAK,OACLC,OAAQ,YACRC,KAAM,UACNC,OAAQ,WACV,EACAC,OAAQ,IACV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en"],"mappings":"aAEA,MAAMA,EAAkB,
|
|
1
|
+
{"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"aAEA,MAAMA,EAAkB,CACtBC,aAAc,CACZC,oBAAqB,4BACrBC,cAAe,mBACfC,cAAe,gBACfC,eAAgB,uBAChBC,cAAe,2DACfC,IAAK,MACLC,OAAQ,SACRC,KAAM,OACNC,OAAQ,QACV,EACAC,OAAQ,IACV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":"gIAqBaA,EAAU,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":"gIAqBaA,EAAU,CAAEC,GAAAA,EAAIC,GAAAA,CAAG"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { KnockProvider as r, useKnockClient as t } from "./modules/core/context/KnockProvider.
|
|
2
|
-
import { default as a } from "./modules/core/hooks/useAuthenticatedKnockClient.
|
|
3
|
-
import { FilterStatus as s } from "./modules/core/constants.
|
|
4
|
-
import { feedProviderKey as i, formatBadgeCount as m, formatTimestamp as u, renderNodeOrFallback as c, toSentenceCase as l } from "./modules/core/utils.
|
|
5
|
-
import { KnockFeedProvider as x, useKnockFeed as k } from "./modules/feed/context/KnockFeedProvider.
|
|
6
|
-
import { default as C } from "./modules/feed/hooks/useNotifications.
|
|
7
|
-
import { default as v } from "./modules/feed/hooks/useFeedSettings.
|
|
8
|
-
import { I18nContext as S, KnockI18nProvider as g } from "./modules/i18n/context/KnockI18nProvider.
|
|
9
|
-
import { useTranslations as N } from "./modules/i18n/hooks/useTranslations.
|
|
10
|
-
import { locales as b } from "./modules/i18n/languages/index.
|
|
1
|
+
import { KnockProvider as r, useKnockClient as t } from "./modules/core/context/KnockProvider.js";
|
|
2
|
+
import { default as a } from "./modules/core/hooks/useAuthenticatedKnockClient.js";
|
|
3
|
+
import { FilterStatus as s } from "./modules/core/constants.js";
|
|
4
|
+
import { feedProviderKey as i, formatBadgeCount as m, formatTimestamp as u, renderNodeOrFallback as c, toSentenceCase as l } from "./modules/core/utils.js";
|
|
5
|
+
import { KnockFeedProvider as x, useKnockFeed as k } from "./modules/feed/context/KnockFeedProvider.js";
|
|
6
|
+
import { default as C } from "./modules/feed/hooks/useNotifications.js";
|
|
7
|
+
import { default as v } from "./modules/feed/hooks/useFeedSettings.js";
|
|
8
|
+
import { I18nContext as S, KnockI18nProvider as g } from "./modules/i18n/context/KnockI18nProvider.js";
|
|
9
|
+
import { useTranslations as N } from "./modules/i18n/hooks/useTranslations.js";
|
|
10
|
+
import { locales as b } from "./modules/i18n/languages/index.js";
|
|
11
11
|
export {
|
|
12
12
|
s as FilterStatus,
|
|
13
13
|
S as I18nContext,
|
|
@@ -27,4 +27,4 @@ export {
|
|
|
27
27
|
C as useNotifications,
|
|
28
28
|
N as useTranslations
|
|
29
29
|
};
|
|
30
|
-
//# sourceMappingURL=index.
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus","All","Read","Unseen","Unread"],"mappings":"AAAYA,IAAAA,sBAAAA,OACVC,EAAAA,MAAM,OACNC,EAAAA,OAAO,QACPC,EAAAA,SAAS,UACTC,EAAAA,SAAS,UAJCJ,IAAAA,KAAAA,CAAAA,CAAAA;"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import * as r from "react";
|
|
3
|
-
import m from "../hooks/useAuthenticatedKnockClient.
|
|
4
|
-
import { KnockI18nProvider as d } from "../../i18n/context/KnockI18nProvider.
|
|
3
|
+
import m from "../hooks/useAuthenticatedKnockClient.js";
|
|
4
|
+
import { KnockI18nProvider as d } from "../../i18n/context/KnockI18nProvider.js";
|
|
5
5
|
import "date-fns/locale";
|
|
6
|
-
const e = r.createContext(
|
|
7
|
-
null
|
|
8
|
-
), x = ({
|
|
6
|
+
const e = r.createContext(null), x = ({
|
|
9
7
|
apiKey: o,
|
|
10
8
|
host: n,
|
|
11
9
|
userId: c,
|
|
@@ -16,15 +14,9 @@ const e = r.createContext(
|
|
|
16
14
|
const k = m(o, c, i, {
|
|
17
15
|
host: n
|
|
18
16
|
});
|
|
19
|
-
return /* @__PURE__ */ t(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value: {
|
|
23
|
-
knock: k
|
|
24
|
-
},
|
|
25
|
-
children: /* @__PURE__ */ t(d, { i18n: u, children: s })
|
|
26
|
-
}
|
|
27
|
-
);
|
|
17
|
+
return /* @__PURE__ */ t(e.Provider, { value: {
|
|
18
|
+
knock: k
|
|
19
|
+
}, children: /* @__PURE__ */ t(d, { i18n: u, children: s }) });
|
|
28
20
|
}, K = () => {
|
|
29
21
|
const o = r.useContext(e);
|
|
30
22
|
if (o === void 0)
|
|
@@ -35,4 +27,4 @@ export {
|
|
|
35
27
|
x as KnockProvider,
|
|
36
28
|
K as useKnockClient
|
|
37
29
|
};
|
|
38
|
-
//# sourceMappingURL=KnockProvider.
|
|
30
|
+
//# sourceMappingURL=KnockProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock from \"@knocklabs/client\";\n\nimport { useAuthenticatedKnockClient } from \"../hooks\";\nimport { KnockI18nProvider, I18nContent } from \"../../i18n\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n\n // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n}\n\nexport const KnockProvider: React.FC<KnockProviderProps> = ({\n apiKey,\n host,\n userId,\n userToken,\n children,\n i18n,\n}) => {\n const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {\n host,\n });\n\n return (\n <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","createContext","KnockProvider","apiKey","host","userId","userToken","children","i18n","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":";;;;;AAUA,MAAMA,IAAuBC,EAAMC,cACjC,IACF,GAiBaC,IAA8CA,CAAC;AAAA,EAC1DC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AACF,MAAM;AACJ,QAAMC,IAAQC,EAA4BP,GAAQE,GAAQC,GAAW;AAAA,IACnEF,MAAAA;AAAAA,EAAAA,CACD;AAED,SACG,gBAAAO,EAAAZ,EAAqB,UAArB,EACC,OAAO;AAAA,IACLU,OAAAA;AAAAA,EAAAA,GAGF,UAAA,gBAAAE,EAACC,GAAkB,EAAA,MAAAJ,GAAaD,UAAAA,GAAS,EAC3C,CAAA;AAEJ,GAEaM,IAAiBA,MAAa;AACnCC,QAAAA,IAAUd,EAAMe,WAAWhB,CAAoB;AACrD,MAAIe,MAAYE;AACR,UAAA,IAAIC,MAAM,8CAA8C;AAEhE,SAAOH,EAAQL;AACjB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport Knock, { KnockOptions } from \"@knocklabs/client\";\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken: string | undefined,\n options: KnockOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return useMemo(() => {\n if (knockRef.current) knockRef.current.teardown();\n\n const knock = new Knock(apiKey, options);\n knock.authenticate(userId, userToken);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["useAuthenticatedKnockClient","apiKey","userId","userToken","options","knockRef","React","useRef","useMemo","current","teardown","knock","Knock","authenticate"],"mappings":";;AAGA,SAASA,EACPC,GACAC,GACAC,GACAC,IAAwB,CAAA,GACxB;AACMC,QAAAA,IAAWC,EAAMC;AAEvB,SAAOC,EAAQ,MAAM;AACnB,IAAIH,EAASI,WAASJ,EAASI,QAAQC;AAEvC,UAAMC,IAAQ,IAAIC,EAAMX,GAAQG,CAAO;AACjCS,WAAAA,EAAAA,aAAaX,GAAQC,CAAS,GACpCE,EAASI,UAAUE,GAEZA;AAAAA,EACN,GAAA,CAACV,GAAQC,GAAQC,CAAS,CAAC;AAChC;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import a from "date-fns/formatDistance";
|
|
2
|
+
import n from "date-fns/parseISO";
|
|
3
|
+
function u(e) {
|
|
4
|
+
return e > 9 ? "9+" : e;
|
|
5
|
+
}
|
|
6
|
+
function i(e, r = {}) {
|
|
7
|
+
try {
|
|
8
|
+
const t = n(e);
|
|
9
|
+
return a(t, /* @__PURE__ */ new Date(), {
|
|
10
|
+
addSuffix: !0,
|
|
11
|
+
locale: r.locale
|
|
12
|
+
});
|
|
13
|
+
} catch {
|
|
14
|
+
return e;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function d(e) {
|
|
18
|
+
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
19
|
+
}
|
|
20
|
+
function m(e, r) {
|
|
21
|
+
return e !== void 0 ? e : r;
|
|
22
|
+
}
|
|
23
|
+
function l(e, r = {}) {
|
|
24
|
+
return [e, r.source, r.tenant, r.has_tenant, r.archived].filter((t) => t != null).join("-");
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
l as feedProviderKey,
|
|
28
|
+
u as formatBadgeCount,
|
|
29
|
+
i as formatTimestamp,
|
|
30
|
+
m as renderNodeOrFallback,
|
|
31
|
+
d as toSentenceCase
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { parseISO, formatDistance, Locale } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: Locale;\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = formatDistance(parsedTs, new Date(), {\n addSuffix: true,\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatted","formatDistance","Date","addSuffix","locale","toSentenceCase","string","charAt","toUpperCase","slice","renderNodeOrFallback","node","fallback","undefined","feedProviderKey","userFeedId","source","tenant","has_tenant","archived","filter","f","join"],"mappings":";;AAIO,SAASA,EAAiBC,GAAgC;AACxDA,SAAAA,IAAQ,IAAI,OAAOA;AAC5B;AAMO,SAASC,EACdC,GACAC,IAAkC,IAClC;AACI,MAAA;AACIC,UAAAA,IAAWC,EAASH,CAAE;AAMrBI,WALWC,EAAeH,GAAU,oBAAII,QAAQ;AAAA,MACrDC,WAAW;AAAA,MACXC,QAAQP,EAAQO;AAAAA,IAAAA,CACjB;AAAA,UAGS;AACHR,WAAAA;AAAAA,EACT;AACF;AAEO,SAASS,EAAeC,GAAwB;AAC9CA,SAAAA,EAAOC,OAAO,CAAC,EAAEC,gBAAgBF,EAAOG,MAAM,CAAC;AACxD;AAEgBC,SAAAA,EAAqBC,GAAiBC,GAAqB;AAClED,SAAAA,MAASE,SAAYF,IAAOC;AACrC;AAMO,SAASE,EACdC,GACAlB,IAA6B,IAC7B;AACA,SAAO,CACLkB,GACAlB,EAAQmB,QACRnB,EAAQoB,QACRpB,EAAQqB,YACRrB,EAAQsB,QAAQ,EAEfC,OAAQC,OAAMA,KAAM,IAAuB,EAC3CC,KAAK,GAAG;AACb;"}
|
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
import { jsx as u } from "react/jsx-runtime";
|
|
2
2
|
import * as n from "react";
|
|
3
3
|
import d from "zustand";
|
|
4
|
-
import f from "../hooks/useNotifications.
|
|
5
|
-
import { feedProviderKey as a } from "../../core/utils.
|
|
6
|
-
import { useKnockClient as k } from "../../core/context/KnockProvider.
|
|
4
|
+
import f from "../hooks/useNotifications.js";
|
|
5
|
+
import { feedProviderKey as a } from "../../core/utils.js";
|
|
6
|
+
import { useKnockClient as k } from "../../core/context/KnockProvider.js";
|
|
7
7
|
import "@knocklabs/client";
|
|
8
|
-
const i = n.createContext(
|
|
9
|
-
null
|
|
10
|
-
), F = ({
|
|
8
|
+
const i = n.createContext(null), F = ({
|
|
11
9
|
feedId: e,
|
|
12
10
|
children: c,
|
|
13
11
|
defaultFeedOptions: o = {},
|
|
14
12
|
colorMode: s = "light"
|
|
15
13
|
}) => {
|
|
16
14
|
const t = k(), r = f(t, e, o), m = d(r.store);
|
|
17
|
-
return /* @__PURE__ */ u(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
useFeedStore: m,
|
|
24
|
-
colorMode: s
|
|
25
|
-
},
|
|
26
|
-
children: c
|
|
27
|
-
},
|
|
28
|
-
a(e, o)
|
|
29
|
-
);
|
|
15
|
+
return /* @__PURE__ */ u(i.Provider, { value: {
|
|
16
|
+
knock: t,
|
|
17
|
+
feedClient: r,
|
|
18
|
+
useFeedStore: m,
|
|
19
|
+
colorMode: s
|
|
20
|
+
}, children: c }, a(e, o));
|
|
30
21
|
}, P = () => {
|
|
31
22
|
const e = n.useContext(i);
|
|
32
23
|
if (e === void 0)
|
|
@@ -37,4 +28,4 @@ export {
|
|
|
37
28
|
F as KnockFeedProvider,
|
|
38
29
|
P as useKnockFeed
|
|
39
30
|
};
|
|
40
|
-
//# sourceMappingURL=KnockFeedProvider.
|
|
31
|
+
//# sourceMappingURL=KnockFeedProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockFeedProvider.js","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport create, { StoreApi, UseStore } from \"zustand\";\n\nimport { ColorMode } from \"../../core/constants\";\nimport useNotifications from \"../hooks/useNotifications\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst FeedStateContext = React.createContext<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","createContext","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","store","jsx","feedProviderKey","useKnockFeed","context","useContext","undefined","Error"],"mappings":";;;;;;;AAoBA,MAAMA,IAAmBC,EAAMC,cAC7B,IACF,GAcaC,IAAsDA,CAAC;AAAA,EAClEC,QAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,oBAAAA,IAAqB,CAAC;AAAA,EACtBC,WAAAA,IAAY;AACd,MAAM;AACJ,QAAMC,IAAQC,KAERC,IAAaC,EAAiBH,GAAOJ,GAAQE,CAAkB,GAC/DM,IAAeC,EAAOH,EAAWI,KAAkC;AAEzE,SACG,gBAAAC,EAAAf,EAAiB,UAAjB,EAEC,OAAO;AAAA,IACLQ,OAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAE,cAAAA;AAAAA,IACAL,WAAAA;AAAAA,EAGDF,GAAAA,UAAAA,EAAAA,GARIW,EAAgBZ,GAAQE,CAAkB,CASjD;AAEJ,GAEaW,IAAeA,MAA8B;AAClDC,QAAAA,IAAUjB,EAAMkB,WAAWnB,CAAgB;AACjD,MAAIkB,MAAYE;AACR,UAAA,IAAIC,MAAM,sDAAsD;AAEjEH,SAAAA;AACT;"}
|
|
@@ -12,9 +12,12 @@ function l(e) {
|
|
|
12
12
|
n.error || a(n.body), t(!1);
|
|
13
13
|
}
|
|
14
14
|
r();
|
|
15
|
-
}, []), {
|
|
15
|
+
}, []), {
|
|
16
|
+
settings: i,
|
|
17
|
+
loading: c
|
|
18
|
+
};
|
|
16
19
|
}
|
|
17
20
|
export {
|
|
18
21
|
l as default
|
|
19
22
|
};
|
|
20
|
-
//# sourceMappingURL=useFeedSettings.
|
|
23
|
+
//# sourceMappingURL=useFeedSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","client","feedSettingsPath","userId","feedId","response","makeRequest","method","url","error","body","loading"],"mappings":";AASA,SAASA,EAAgBC,GAGvB;AACA,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,IAAI,GACvC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK;AAIhDG,SAAAA,EAAU,MAAM;AACd,mBAAeC,IAAc;AAC3B,YAAMC,IAAQR,EAAWQ,OACnBC,IAAYD,EAAME,UAClBC,IAAoB,aAAYH,EAAMI,MAAO,UAASZ,EAAWa,MAAO;AAC9ER,MAAAA,EAAa,EAAI;AAEXS,YAAAA,IAAW,MAAML,EAAUM,YAAY;AAAA,QAC3CC,QAAQ;AAAA,QACRC,KAAKN;AAAAA,MAAAA,CACN;AAEG,MAACG,EAASI,SACZhB,EAAYY,EAASK,IAAI,GAG3Bd,EAAa,EAAK;AAAA,IACpB;AAEY,IAAAE;EACd,GAAG,CAAE,CAAA,GAEE;AAAA,IAAEN,UAAAA;AAAAA,IAAUmB,SAAShB;AAAAA,EAAAA;AAC9B;"}
|
|
@@ -5,16 +5,9 @@ function c(n, u, e = {}) {
|
|
|
5
5
|
t.current && t.current.teardown();
|
|
6
6
|
const r = n.feeds.initialize(u, e);
|
|
7
7
|
return r.listenForUpdates(), t.current = r, r;
|
|
8
|
-
}, [
|
|
9
|
-
n,
|
|
10
|
-
u,
|
|
11
|
-
e.source,
|
|
12
|
-
e.tenant,
|
|
13
|
-
e.has_tenant,
|
|
14
|
-
e.archived
|
|
15
|
-
]);
|
|
8
|
+
}, [n, u, e.source, e.tenant, e.has_tenant, e.archived]);
|
|
16
9
|
}
|
|
17
10
|
export {
|
|
18
11
|
c as default
|
|
19
12
|
};
|
|
20
|
-
//# sourceMappingURL=useNotifications.
|
|
13
|
+
//# sourceMappingURL=useNotifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nfunction useNotifications(\n knock: Knock,\n feedId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) feedClientRef.current.teardown();\n\n const feedClient = knock.feeds.initialize(feedId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\n }, [\n knock,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedId","options","feedClientRef","useRef","useMemo","current","teardown","feedClient","feeds","initialize","listenForUpdates","source","tenant","has_tenant","archived"],"mappings":";AAGA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC;AAEtB,SAAOC,EAAQ,MAAM;AACnB,IAAIF,EAAcG,WAASH,EAAcG,QAAQC;AAEjD,UAAMC,IAAaR,EAAMS,MAAMC,WAAWT,GAAQC,CAAO;AAEzDM,WAAAA,EAAWG,iBAAiB,GAC5BR,EAAcG,UAAUE,GAEjBA;AAAAA,EACN,GAAA,CACDR,GACAC,GACAC,EAAQU,QACRV,EAAQW,QACRX,EAAQY,YACRZ,EAAQa,QAAQ,CACjB;AACH;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import n from "react";
|
|
3
|
-
import { locales as o } from "../languages/index.
|
|
3
|
+
import { locales as o } from "../languages/index.js";
|
|
4
4
|
const c = n.createContext(o.en);
|
|
5
5
|
function f({
|
|
6
6
|
i18n: e = o.en,
|
|
@@ -12,4 +12,4 @@ export {
|
|
|
12
12
|
c as I18nContext,
|
|
13
13
|
f as KnockI18nProvider
|
|
14
14
|
};
|
|
15
|
-
//# sourceMappingURL=KnockI18nProvider.
|
|
15
|
+
//# sourceMappingURL=KnockI18nProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","createContext","locales","en","KnockI18nProvider","i18n","props"],"mappings":";;;AAGO,MAAMA,IAAcC,EAAMC,cAA2BC,EAAQC,EAAE;AAO/D,SAASC,EAAkB;AAAA,EAChCC,MAAAA,IAAOH,EAAQC;AAAAA,EACf,GAAGG;AACmB,GAAG;AACzB,2BAAQP,EAAY,UAAZ,EAAyBO,GAAAA,GAAO,OAAOD,EAAQ,CAAA;AACzD;"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { useContext as e } from "react";
|
|
2
2
|
import * as n from "date-fns/locale";
|
|
3
|
-
import { locales as s } from "../languages/index.
|
|
4
|
-
import { I18nContext as a } from "../context/KnockI18nProvider.
|
|
3
|
+
import { locales as s } from "../languages/index.js";
|
|
4
|
+
import { I18nContext as a } from "../context/KnockI18nProvider.js";
|
|
5
5
|
function c() {
|
|
6
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
translations: r,
|
|
8
|
+
locale: t
|
|
9
|
+
} = e(a);
|
|
7
10
|
return {
|
|
8
11
|
locale: t,
|
|
9
12
|
t: (o) => r[o] || s.en.translations[o],
|
|
@@ -13,4 +16,4 @@ function c() {
|
|
|
13
16
|
export {
|
|
14
17
|
c as useTranslations
|
|
15
18
|
};
|
|
16
|
-
//# sourceMappingURL=useTranslations.
|
|
19
|
+
//# sourceMappingURL=useTranslations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { Locale as DateFnLocale } from \"date-fns\";\nimport * as dateFnsLocales from \"date-fns/locale\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n dateFnsLocale: (): DateFnLocale => {\n return locale in dateFnsLocales\n ? dateFnsLocales[locale as keyof typeof dateFnsLocales]\n : dateFnsLocales.enUS;\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","t","key","locales","en","dateFnsLocale","dateFnsLocales","enUS"],"mappings":";;;;AAMO,SAASA,IAAkB;AAC1B,QAAA;AAAA,IAAEC,cAAAA;AAAAA,IAAcC,QAAAA;AAAAA,EAAAA,IAAWC,EAAwBC,CAAW;AAE7D,SAAA;AAAA,IACLF,QAAAA;AAAAA,IACAG,GAAGA,CAACC,MAEKL,EAAaK,CAAG,KAAKC,EAAQC,GAAGP,aAAaK,CAAG;AAAA,IAEzDG,eAAeA,MACNP,KAAUQ,IACbA,EAAeR,CAAqC,IACpDQ,EAAeC;AAAAA,EACrB;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtBC,cAAc;AAAA,IACZC,qBAAqB;AAAA,IACrBC,eAAe;AAAA,IACfC,eAAe;AAAA,IACfC,gBAAgB;AAAA,IAChBC,eACE;AAAA,IACFC,KAAK;AAAA,IACLC,QAAQ;AAAA,IACRC,MAAM;AAAA,IACNC,QAAQ;AAAA,EACV;AAAA,EACAC,QAAQ;AACV;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtBC,cAAc;AAAA,IACZC,qBAAqB;AAAA,IACrBC,eAAe;AAAA,IACfC,eAAe;AAAA,IACfC,gBAAgB;AAAA,IAChBC,eAAe;AAAA,IACfC,KAAK;AAAA,IACLC,QAAQ;AAAA,IACRC,MAAM;AAAA,IACNC,QAAQ;AAAA,EACV;AAAA,EACAC,QAAQ;AACV;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":";;AAqBO,MAAMA,IAAU;AAAA,EAAEC,IAAAA;AAAAA,EAAIC,IAAAA;AAAG;"}
|
package/package.json
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
"name": "@knocklabs/react-core",
|
|
3
3
|
"description": "A set of React components to build notification experiences powered by Knock",
|
|
4
4
|
"author": "@knocklabs",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.2",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
|
-
"module": "dist/esm/index.
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
9
|
"types": "dist/types/index.d.ts",
|
|
10
10
|
"typings": "dist/types/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"require": "./dist/cjs/index.js",
|
|
14
14
|
"types": "./dist/types/index.d.ts",
|
|
15
|
-
"default": "./dist/esm/index.
|
|
15
|
+
"default": "./dist/esm/index.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
@@ -39,13 +39,16 @@
|
|
|
39
39
|
"react": ">=16.8.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@knocklabs/client": "*"
|
|
42
|
+
"@knocklabs/client": "*",
|
|
43
|
+
"date-fns": "^2.24.0",
|
|
44
|
+
"zustand": "^3.5.10"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/react": "^18.2.37",
|
|
46
48
|
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
47
49
|
"@typescript-eslint/parser": "^6.10.0",
|
|
48
50
|
"@vitejs/plugin-react": "^4.2.0",
|
|
51
|
+
"babel-plugin-date-fns": "^2.0.0",
|
|
49
52
|
"eslint": "^8.53.0",
|
|
50
53
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
54
|
"eslint-plugin-react-refresh": "^0.4.4",
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus"],"mappings":"AAAY,IAAAA,sBAAAA,OACVA,EAAA,MAAM,OACNA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,SAAS,UAJCA,IAAAA,KAAA,CAAA,CAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock from \"@knocklabs/client\";\n\nimport { useAuthenticatedKnockClient } from \"../hooks\";\nimport { KnockI18nProvider, I18nContent } from \"../../i18n\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n\n // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n}\n\nexport const KnockProvider: React.FC<KnockProviderProps> = ({\n apiKey,\n host,\n userId,\n userToken,\n children,\n i18n,\n}) => {\n const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {\n host,\n });\n\n return (\n <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","KnockProvider","apiKey","host","userId","userToken","children","i18n","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context"],"mappings":";;;;;AAUA,MAAMA,IAAuBC,EAAM;AAAA,EACjC;AACF,GAiBaC,IAA8C,CAAC;AAAA,EAC1D,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AACF,MAAM;AACJ,QAAMC,IAAQC,EAA4BP,GAAQE,GAAQC,GAAW;AAAA,IACnE,MAAAF;AAAA,EAAA,CACD;AAGC,SAAA,gBAAAO;AAAA,IAACX,EAAqB;AAAA,IAArB;AAAA,MACC,OAAO;AAAA,QACL,OAAAS;AAAA,MACF;AAAA,MAEA,UAAA,gBAAAE,EAACC,GAAkB,EAAA,MAAAJ,GAAa,UAAAD,EAAS,CAAA;AAAA,IAAA;AAAA,EAAA;AAG/C,GAEaM,IAAiB,MAAa;AACnC,QAAAC,IAAUb,EAAM,WAAWD,CAAoB;AACrD,MAAIc,MAAY;AACR,UAAA,IAAI,MAAM,8CAA8C;AAEhE,SAAOA,EAAQ;AACjB;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport Knock, { KnockOptions } from \"@knocklabs/client\";\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken: string | undefined,\n options: KnockOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return useMemo(() => {\n if (knockRef.current) knockRef.current.teardown();\n\n const knock = new Knock(apiKey, options);\n knock.authenticate(userId, userToken);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["useAuthenticatedKnockClient","apiKey","userId","userToken","options","knockRef","React","useMemo","knock","Knock"],"mappings":";;AAGA,SAASA,EACPC,GACAC,GACAC,GACAC,IAAwB,CAAA,GACxB;AACM,QAAAC,IAAWC,EAAM;AAEvB,SAAOC,EAAQ,MAAM;AACnB,IAAIF,EAAS,WAASA,EAAS,QAAQ;AAEvC,UAAMG,IAAQ,IAAIC,EAAMR,GAAQG,CAAO;AACjC,WAAAI,EAAA,aAAaN,GAAQC,CAAS,GACpCE,EAAS,UAAUG,GAEZA;AAAA,EACN,GAAA,CAACP,GAAQC,GAAQC,CAAS,CAAC;AAChC;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { parseISO as a, formatDistance as n } from "date-fns";
|
|
2
|
-
function u(e) {
|
|
3
|
-
return e > 9 ? "9+" : e;
|
|
4
|
-
}
|
|
5
|
-
function f(e, r = {}) {
|
|
6
|
-
try {
|
|
7
|
-
const t = a(e);
|
|
8
|
-
return n(t, /* @__PURE__ */ new Date(), {
|
|
9
|
-
addSuffix: !0,
|
|
10
|
-
locale: r.locale
|
|
11
|
-
});
|
|
12
|
-
} catch {
|
|
13
|
-
return e;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function d(e) {
|
|
17
|
-
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
18
|
-
}
|
|
19
|
-
function i(e, r) {
|
|
20
|
-
return e !== void 0 ? e : r;
|
|
21
|
-
}
|
|
22
|
-
function l(e, r = {}) {
|
|
23
|
-
return [
|
|
24
|
-
e,
|
|
25
|
-
r.source,
|
|
26
|
-
r.tenant,
|
|
27
|
-
r.has_tenant,
|
|
28
|
-
r.archived
|
|
29
|
-
].filter((t) => t != null).join("-");
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
l as feedProviderKey,
|
|
33
|
-
u as formatBadgeCount,
|
|
34
|
-
f as formatTimestamp,
|
|
35
|
-
i as renderNodeOrFallback,
|
|
36
|
-
d as toSentenceCase
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { parseISO, formatDistance, Locale } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: Locale;\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = formatDistance(parsedTs, new Date(), {\n addSuffix: true,\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatDistance","toSentenceCase","string","renderNodeOrFallback","node","fallback","feedProviderKey","userFeedId","f"],"mappings":";AAIO,SAASA,EAAiBC,GAAgC;AACxD,SAAAA,IAAQ,IAAI,OAAOA;AAC5B;AAMO,SAASC,EACdC,GACAC,IAAkC,IAClC;AACI,MAAA;AACI,UAAAC,IAAWC,EAASH,CAAE;AAMrB,WALWI,EAAeF,GAAU,oBAAI,QAAQ;AAAA,MACrD,WAAW;AAAA,MACX,QAAQD,EAAQ;AAAA,IAAA,CACjB;AAAA,UAGS;AACH,WAAAD;AAAA,EACT;AACF;AAEO,SAASK,EAAeC,GAAwB;AAC9C,SAAAA,EAAO,OAAO,CAAC,EAAE,gBAAgBA,EAAO,MAAM,CAAC;AACxD;AAEgB,SAAAC,EAAqBC,GAAiBC,GAAqB;AAClE,SAAAD,MAAS,SAAYA,IAAOC;AACrC;AAMO,SAASC,EACdC,GACAV,IAA6B,IAC7B;AACO,SAAA;AAAA,IACLU;AAAA,IACAV,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,EACV,EACG,OAAO,CAACW,MAAMA,KAAM,IAAuB,EAC3C,KAAK,GAAG;AACb;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KnockFeedProvider.mjs","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport create, { StoreApi, UseStore } from \"zustand\";\n\nimport { ColorMode } from \"../../core/constants\";\nimport useNotifications from \"../hooks/useNotifications\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst FeedStateContext = React.createContext<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","jsx","feedProviderKey","useKnockFeed","context"],"mappings":";;;;;;;AAoBA,MAAMA,IAAmBC,EAAM;AAAA,EAC7B;AACF,GAcaC,IAAsD,CAAC;AAAA,EAClE,QAAAC;AAAA,EACA,UAAAC;AAAA,EACA,oBAAAC,IAAqB,CAAC;AAAA,EACtB,WAAAC,IAAY;AACd,MAAM;AACJ,QAAMC,IAAQC,KAERC,IAAaC,EAAiBH,GAAOJ,GAAQE,CAAkB,GAC/DM,IAAeC,EAAOH,EAAW,KAAiC;AAGtE,SAAA,gBAAAI;AAAA,IAACb,EAAiB;AAAA,IAAjB;AAAA,MAEC,OAAO;AAAA,QACL,OAAAO;AAAA,QACA,YAAAE;AAAA,QACA,cAAAE;AAAA,QACA,WAAAL;AAAA,MACF;AAAA,MAEC,UAAAF;AAAA,IAAA;AAAA,IARIU,EAAgBX,GAAQE,CAAkB;AAAA,EAAA;AAWrD,GAEaU,IAAe,MAA8B;AAClD,QAAAC,IAAUf,EAAM,WAAWD,CAAgB;AACjD,MAAIgB,MAAY;AACR,UAAA,IAAI,MAAM,sDAAsD;AAEjE,SAAAA;AACT;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFeedSettings.mjs","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","feedSettingsPath","response"],"mappings":";AASA,SAASA,EAAgBC,GAGvB;AACA,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,IAAI,GACvC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK;AAIhD,SAAAG,EAAU,MAAM;AACd,mBAAeC,IAAc;AAC3B,YAAMC,IAAQR,EAAW,OACnBS,IAAYD,EAAM,UAClBE,IAAmB,aAAaF,EAAM,MAAM,UAAUR,EAAW,MAAM;AAC7E,MAAAK,EAAa,EAAI;AAEX,YAAAM,IAAW,MAAMF,EAAU,YAAY;AAAA,QAC3C,QAAQ;AAAA,QACR,KAAKC;AAAA,MAAA,CACN;AAEG,MAACC,EAAS,SACZT,EAAYS,EAAS,IAAI,GAG3BN,EAAa,EAAK;AAAA,IACpB;AAEY,IAAAE;EACd,GAAG,CAAE,CAAA,GAEE,EAAE,UAAAN,GAAU,SAASG;AAC9B;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.mjs","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nfunction useNotifications(\n knock: Knock,\n feedId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) feedClientRef.current.teardown();\n\n const feedClient = knock.feeds.initialize(feedId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\n }, [\n knock,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedId","options","feedClientRef","useRef","useMemo","feedClient"],"mappings":";AAGA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC;AAEtB,SAAOC,EAAQ,MAAM;AACnB,IAAIF,EAAc,WAASA,EAAc,QAAQ;AAEjD,UAAMG,IAAaN,EAAM,MAAM,WAAWC,GAAQC,CAAO;AAEzD,WAAAI,EAAW,iBAAiB,GAC5BH,EAAc,UAAUG,GAEjBA;AAAA,EAAA,GACN;AAAA,IACDN;AAAA,IACAC;AAAA,IACAC,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,EAAA,CACT;AACH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KnockI18nProvider.mjs","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","locales","KnockI18nProvider","i18n","props"],"mappings":";;;AAGO,MAAMA,IAAcC,EAAM,cAA2BC,EAAQ,EAAE;AAO/D,SAASC,EAAkB;AAAA,EAChC,MAAAC,IAAOF,EAAQ;AAAA,EACf,GAAGG;AACL,GAA2B;AACzB,2BAAQL,EAAY,UAAZ,EAAsB,GAAGK,GAAO,OAAOD,EAAM,CAAA;AACvD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.mjs","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { Locale as DateFnLocale } from \"date-fns\";\nimport * as dateFnsLocales from \"date-fns/locale\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n dateFnsLocale: (): DateFnLocale => {\n return locale in dateFnsLocales\n ? dateFnsLocales[locale as keyof typeof dateFnsLocales]\n : dateFnsLocales.enUS;\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","key","locales","dateFnsLocales"],"mappings":";;;;AAMO,SAASA,IAAkB;AAChC,QAAM,EAAE,cAAAC,GAAc,QAAAC,EAAO,IAAIC,EAAwBC,CAAW;AAE7D,SAAA;AAAA,IACL,QAAAF;AAAA,IACA,GAAG,CAACG,MAEKJ,EAAaI,CAAG,KAAKC,EAAQ,GAAG,aAAaD,CAAG;AAAA,IAEzD,eAAe,MACNH,KAAUK,IACbA,EAAeL,CAAqC,IACpDK,EAAe;AAAA,EACrB;AAEJ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"de.mjs","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtB,cAAc;AAAA,IACZ,qBAAqB;AAAA,IACrB,eAAe;AAAA,IACf,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,eACE;AAAA,IACF,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AACV;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"en.mjs","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtB,cAAc;AAAA,IACZ,qBAAqB;AAAA,IACrB,eAAe;AAAA,IACf,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AACV;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":";;AAqBa,MAAAA,IAAU,EAAE,IAAAC,GAAI,IAAAC,EAAG;"}
|