@knocklabs/react-core 0.1.0 → 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.
Files changed (114) hide show
  1. package/dist/cjs/index.js +2 -0
  2. package/dist/cjs/index.js.map +1 -0
  3. package/dist/cjs/modules/core/constants.js +2 -0
  4. package/dist/cjs/modules/core/constants.js.map +1 -0
  5. package/dist/cjs/modules/core/context/KnockProvider.js +2 -0
  6. package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -0
  7. package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js +2 -0
  8. package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -0
  9. package/dist/cjs/modules/core/utils.js +2 -0
  10. package/dist/cjs/modules/core/utils.js.map +1 -0
  11. package/dist/cjs/modules/feed/context/KnockFeedProvider.js +2 -0
  12. package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -0
  13. package/dist/cjs/modules/feed/hooks/useFeedSettings.js +2 -0
  14. package/dist/cjs/modules/feed/hooks/useFeedSettings.js.map +1 -0
  15. package/dist/cjs/modules/feed/hooks/useNotifications.js +2 -0
  16. package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -0
  17. package/dist/cjs/modules/i18n/context/KnockI18nProvider.js +2 -0
  18. package/dist/cjs/modules/i18n/context/KnockI18nProvider.js.map +1 -0
  19. package/dist/cjs/modules/i18n/hooks/useTranslations.js +2 -0
  20. package/dist/cjs/modules/i18n/hooks/useTranslations.js.map +1 -0
  21. package/dist/cjs/modules/i18n/languages/de.js +2 -0
  22. package/dist/cjs/modules/i18n/languages/de.js.map +1 -0
  23. package/dist/cjs/modules/i18n/languages/en.js +2 -0
  24. package/dist/cjs/modules/i18n/languages/en.js.map +1 -0
  25. package/dist/cjs/modules/i18n/languages/index.js +2 -0
  26. package/dist/cjs/modules/i18n/languages/index.js.map +1 -0
  27. package/dist/esm/index.js +30 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/modules/core/constants.js +5 -0
  30. package/dist/esm/modules/core/constants.js.map +1 -0
  31. package/dist/esm/modules/core/context/KnockProvider.js +30 -0
  32. package/dist/esm/modules/core/context/KnockProvider.js.map +1 -0
  33. package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.js +14 -0
  34. package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -0
  35. package/dist/esm/modules/core/utils.js +33 -0
  36. package/dist/esm/modules/core/utils.js.map +1 -0
  37. package/dist/esm/modules/feed/context/KnockFeedProvider.js +31 -0
  38. package/dist/esm/modules/feed/context/KnockFeedProvider.js.map +1 -0
  39. package/dist/esm/modules/feed/hooks/useFeedSettings.js +23 -0
  40. package/dist/esm/modules/feed/hooks/useFeedSettings.js.map +1 -0
  41. package/dist/esm/modules/feed/hooks/useNotifications.js +13 -0
  42. package/dist/esm/modules/feed/hooks/useNotifications.js.map +1 -0
  43. package/dist/esm/modules/i18n/context/KnockI18nProvider.js +15 -0
  44. package/dist/esm/modules/i18n/context/KnockI18nProvider.js.map +1 -0
  45. package/dist/esm/modules/i18n/hooks/useTranslations.js +19 -0
  46. package/dist/esm/modules/i18n/hooks/useTranslations.js.map +1 -0
  47. package/{src/modules/i18n/languages/de.ts → dist/esm/modules/i18n/languages/de.js} +8 -9
  48. package/dist/esm/modules/i18n/languages/de.js.map +1 -0
  49. package/{src/modules/i18n/languages/en.ts → dist/esm/modules/i18n/languages/en.js} +7 -7
  50. package/dist/esm/modules/i18n/languages/en.js.map +1 -0
  51. package/dist/esm/modules/i18n/languages/index.js +10 -0
  52. package/dist/esm/modules/i18n/languages/index.js.map +1 -0
  53. package/{src/index.ts → dist/types/index.d.ts} +1 -0
  54. package/dist/types/index.d.ts.map +1 -0
  55. package/dist/types/modules/core/constants.d.ts +8 -0
  56. package/dist/types/modules/core/constants.d.ts.map +1 -0
  57. package/dist/types/modules/core/context/KnockProvider.d.ts +17 -0
  58. package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -0
  59. package/dist/types/modules/core/context/index.d.ts +2 -0
  60. package/dist/types/modules/core/context/index.d.ts.map +1 -0
  61. package/{src/modules/core/hooks/index.ts → dist/types/modules/core/hooks/index.d.ts} +1 -0
  62. package/dist/types/modules/core/hooks/index.d.ts.map +1 -0
  63. package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts +4 -0
  64. package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -0
  65. package/{src/modules/core/index.ts → dist/types/modules/core/index.d.ts} +1 -0
  66. package/dist/types/modules/core/index.d.ts.map +1 -0
  67. package/dist/types/modules/core/utils.d.ts +13 -0
  68. package/dist/types/modules/core/utils.d.ts.map +1 -0
  69. package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +19 -0
  70. package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -0
  71. package/dist/types/modules/feed/context/index.d.ts +2 -0
  72. package/dist/types/modules/feed/context/index.d.ts.map +1 -0
  73. package/{src/modules/feed/hooks/index.ts → dist/types/modules/feed/hooks/index.d.ts} +1 -0
  74. package/dist/types/modules/feed/hooks/index.d.ts.map +1 -0
  75. package/dist/types/modules/feed/hooks/useFeedSettings.d.ts +12 -0
  76. package/dist/types/modules/feed/hooks/useFeedSettings.d.ts.map +1 -0
  77. package/dist/types/modules/feed/hooks/useNotifications.d.ts +4 -0
  78. package/dist/types/modules/feed/hooks/useNotifications.d.ts.map +1 -0
  79. package/{src/modules/feed/index.ts → dist/types/modules/feed/index.d.ts} +1 -0
  80. package/dist/types/modules/feed/index.d.ts.map +1 -0
  81. package/dist/types/modules/i18n/context/KnockI18nProvider.d.ts +10 -0
  82. package/dist/types/modules/i18n/context/KnockI18nProvider.d.ts.map +1 -0
  83. package/{src/modules/i18n/context/index.ts → dist/types/modules/i18n/context/index.d.ts} +1 -0
  84. package/dist/types/modules/i18n/context/index.d.ts.map +1 -0
  85. package/{src/modules/i18n/hooks/index.ts → dist/types/modules/i18n/hooks/index.d.ts} +1 -0
  86. package/dist/types/modules/i18n/hooks/index.d.ts.map +1 -0
  87. package/dist/types/modules/i18n/hooks/useTranslations.d.ts +7 -0
  88. package/dist/types/modules/i18n/hooks/useTranslations.d.ts.map +1 -0
  89. package/{src/modules/i18n/index.ts → dist/types/modules/i18n/index.d.ts} +1 -0
  90. package/dist/types/modules/i18n/index.d.ts.map +1 -0
  91. package/dist/types/modules/i18n/languages/de.d.ts +4 -0
  92. package/dist/types/modules/i18n/languages/de.d.ts.map +1 -0
  93. package/dist/types/modules/i18n/languages/en.d.ts +4 -0
  94. package/dist/types/modules/i18n/languages/en.d.ts.map +1 -0
  95. package/dist/types/modules/i18n/languages/index.d.ts +21 -0
  96. package/dist/types/modules/i18n/languages/index.d.ts.map +1 -0
  97. package/package.json +56 -4
  98. package/.eslintrc.js +0 -9
  99. package/CHANGELOG.md +0 -7
  100. package/src/modules/core/constants.ts +0 -8
  101. package/src/modules/core/context/KnockProvider.tsx +0 -59
  102. package/src/modules/core/context/index.ts +0 -1
  103. package/src/modules/core/hooks/useAuthenticatedKnockClient.ts +0 -23
  104. package/src/modules/core/utils.ts +0 -55
  105. package/src/modules/feed/context/KnockFeedContainer.tsx +0 -8
  106. package/src/modules/feed/context/KnockFeedProvider.tsx +0 -78
  107. package/src/modules/feed/context/index.ts +0 -2
  108. package/src/modules/feed/context/styles.css +0 -10
  109. package/src/modules/feed/hooks/useFeedSettings.ts +0 -44
  110. package/src/modules/feed/hooks/useNotifications.ts +0 -30
  111. package/src/modules/i18n/context/KnockI18nProvider.tsx +0 -16
  112. package/src/modules/i18n/hooks/useTranslations.ts +0 -22
  113. package/src/modules/i18n/languages/index.ts +0 -22
  114. package/tsconfig.json +0 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAExD,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,YAAiB,SAa3B;AAED,eAAe,2BAA2B,CAAC"}
@@ -2,3 +2,4 @@ export * from "./context";
2
2
  export * from "./hooks";
3
3
  export * from "./constants";
4
4
  export * from "./utils";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { FeedClientOptions } from "@knocklabs/client";
2
+ import { Locale } from "date-fns";
3
+ import { ReactNode } from "react";
4
+ export declare function formatBadgeCount(count: number): string | number;
5
+ type FormatTimestampOptions = {
6
+ locale?: Locale;
7
+ };
8
+ export declare function formatTimestamp(ts: string, options?: FormatTimestampOptions): string;
9
+ export declare function toSentenceCase(string: string): string;
10
+ export declare function renderNodeOrFallback(node: ReactNode, fallback: ReactNode): ReactNode;
11
+ export declare function feedProviderKey(userFeedId: string, options?: FeedClientOptions): string;
12
+ export {};
13
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/core/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAA4B,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE/D;AAED,KAAK,sBAAsB,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,sBAA2B,UAarC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,aAExE;AAMD,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,iBAAsB,UAWhC"}
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ import Knock, { Feed, FeedClientOptions, FeedStoreState } from "@knocklabs/client";
3
+ import { UseStore } from "zustand";
4
+ import { ColorMode } from "../../core/constants";
5
+ export interface KnockFeedProviderState {
6
+ knock: Knock;
7
+ feedClient: Feed;
8
+ useFeedStore: UseStore<FeedStoreState>;
9
+ colorMode: ColorMode;
10
+ }
11
+ export interface KnockFeedProviderProps {
12
+ feedId: string;
13
+ children?: React.ReactElement;
14
+ colorMode?: ColorMode;
15
+ defaultFeedOptions?: FeedClientOptions;
16
+ }
17
+ export declare const KnockFeedProvider: React.FC<KnockFeedProviderProps>;
18
+ export declare const useKnockFeed: () => KnockFeedProviderState;
19
+ //# sourceMappingURL=KnockFeedProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnockFeedProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,EACZ,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAe,EAAY,QAAQ,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;IACjB,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvC,SAAS,EAAE,SAAS,CAAC;CACtB;AAMD,MAAM,WAAW,sBAAsB;IAErC,MAAM,EAAE,MAAM,CAAC;IAGf,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAwB9D,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,sBAM/B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./KnockFeedProvider";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { default as useNotifications } from "./useNotifications";
2
2
  export { default as useFeedSettings } from "./useFeedSettings";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Feed } from "@knocklabs/client";
2
+ export type FeedSettings = {
3
+ features: {
4
+ branding_required: boolean;
5
+ };
6
+ };
7
+ declare function useFeedSettings(feedClient: Feed): {
8
+ settings: FeedSettings | null;
9
+ loading: boolean;
10
+ };
11
+ export default useFeedSettings;
12
+ //# sourceMappingURL=useFeedSettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFeedSettings.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGzC,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE;QACR,iBAAiB,EAAE,OAAO,CAAC;KAC5B,CAAC;CACH,CAAC;AAEF,iBAAS,eAAe,CAAC,UAAU,EAAE,IAAI,GAAG;IAC1C,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB,CA6BA;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,4 @@
1
+ import Knock, { Feed, FeedClientOptions } from "@knocklabs/client";
2
+ declare function useNotifications(knock: Knock, feedId: string, options?: FeedClientOptions): Feed;
3
+ export default useNotifications;
4
+ //# sourceMappingURL=useNotifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNotifications.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,iBAAsB,QAqBhC;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./context";
2
2
  export * from "./hooks";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/feed/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { I18nContent } from "../languages";
3
+ export declare const I18nContext: React.Context<I18nContent>;
4
+ interface KnockI18nProviderProps {
5
+ i18n?: I18nContent;
6
+ children: JSX.Element | undefined;
7
+ }
8
+ export declare function KnockI18nProvider({ i18n, ...props }: KnockI18nProviderProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=KnockI18nProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnockI18nProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAW,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,WAAW,4BAA+C,CAAC;AAExE,UAAU,sBAAsB;IAC9B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC;CACnC;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAiB,EACjB,GAAG,KAAK,EACT,EAAE,sBAAsB,2CAExB"}
@@ -1 +1,2 @@
1
1
  export * from "./KnockI18nProvider";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -1 +1,2 @@
1
1
  export * from "./useTranslations";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Locale as DateFnLocale } from "date-fns";
2
+ export declare function useTranslations(): {
3
+ locale: string;
4
+ t: (key: keyof import("../languages").Translations) => string | undefined;
5
+ dateFnsLocale: () => DateFnLocale;
6
+ };
7
+ //# sourceMappingURL=useTranslations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,UAAU,CAAC;AAKlD,wBAAgB,eAAe;;;yBASR,YAAY;EAMlC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./context";
2
2
  export * from "./hooks";
3
3
  export * from "./languages";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/i18n/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { I18nContent } from ".";
2
+ declare const de: I18nContent;
3
+ export default de;
4
+ //# sourceMappingURL=de.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"de.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/languages/de.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAEhC,QAAA,MAAM,EAAE,EAAE,WAcT,CAAC;AAEF,eAAe,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { I18nContent } from ".";
2
+ declare const en: I18nContent;
3
+ export default en;
4
+ //# sourceMappingURL=en.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/languages/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAEhC,QAAA,MAAM,EAAE,EAAE,WAaT,CAAC;AAEF,eAAe,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface Translations {
2
+ readonly emptyFeedTitle: string;
3
+ readonly emptyFeedBody: string;
4
+ readonly notifications: string;
5
+ readonly poweredBy: string;
6
+ readonly markAllAsRead: string;
7
+ readonly archiveNotification: string;
8
+ readonly all: string;
9
+ readonly unread: string;
10
+ readonly read: string;
11
+ readonly unseen: string;
12
+ }
13
+ export interface I18nContent {
14
+ readonly translations: Partial<Translations>;
15
+ readonly locale: string;
16
+ }
17
+ export declare const locales: {
18
+ en: I18nContent;
19
+ de: I18nContent;
20
+ };
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/languages/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,OAAO;;;CAAa,CAAC"}
package/package.json CHANGED
@@ -2,9 +2,61 @@
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.0",
5
+ "version": "0.1.2",
6
6
  "license": "MIT",
7
- "main": "src/index.ts",
8
- "types": "src/index.ts",
9
- "dependencies": {}
7
+ "main": "dist/cjs/index.js",
8
+ "module": "dist/esm/index.js",
9
+ "types": "dist/types/index.d.ts",
10
+ "typings": "dist/types/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "require": "./dist/cjs/index.js",
14
+ "types": "./dist/types/index.d.ts",
15
+ "default": "./dist/esm/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "clean": "rimraf dist",
24
+ "dev": "tsc && vite build --watch",
25
+ "build": "yarn clean && yarn build:esm && yarn build:cjs",
26
+ "build:esm": "export BUILD_TARGET=esm; tsc && vite build",
27
+ "build:cjs": "export BUILD_TARGET=cjs; tsc && vite build",
28
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
29
+ "preview": "vite preview"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/knocklabs/javascript.git"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/knocklabs/javascript/issues"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=16.8.0"
40
+ },
41
+ "dependencies": {
42
+ "@knocklabs/client": "*",
43
+ "date-fns": "^2.24.0",
44
+ "zustand": "^3.5.10"
45
+ },
46
+ "devDependencies": {
47
+ "@types/react": "^18.2.37",
48
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
49
+ "@typescript-eslint/parser": "^6.10.0",
50
+ "@vitejs/plugin-react": "^4.2.0",
51
+ "babel-plugin-date-fns": "^2.0.0",
52
+ "eslint": "^8.53.0",
53
+ "eslint-plugin-react-hooks": "^4.6.0",
54
+ "eslint-plugin-react-refresh": "^0.4.4",
55
+ "rimraf": "^5.0.5",
56
+ "rollup-plugin-execute": "^1.1.1",
57
+ "typescript": "^5.2.2",
58
+ "vite": "^5.0.0",
59
+ "vite-plugin-dts": "^3.6.3",
60
+ "vite-plugin-no-bundle": "^3.0.0"
61
+ }
10
62
  }
package/.eslintrc.js DELETED
@@ -1,9 +0,0 @@
1
- /** @type {import("eslint").Linter.Config} */
2
- module.exports = {
3
- root: true,
4
- extends: ["@knocklabs/eslint-config/react-internal.js"],
5
- parser: "@typescript-eslint/parser",
6
- parserOptions: {
7
- project: true,
8
- },
9
- };
package/CHANGELOG.md DELETED
@@ -1,7 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.1.0
4
-
5
- ### Patch Changes
6
-
7
- - bcdbc86: Initialize monorepo
@@ -1,8 +0,0 @@
1
- export enum FilterStatus {
2
- All = "all",
3
- Read = "read",
4
- Unseen = "unseen",
5
- Unread = "unread",
6
- }
7
-
8
- export type ColorMode = "light" | "dark";
@@ -1,59 +0,0 @@
1
- import * as React from "react";
2
- import Knock from "@knocklabs/client";
3
-
4
- import { useAuthenticatedKnockClient } from "../hooks";
5
- import { KnockI18nProvider, I18nContent } from "../../i18n";
6
-
7
- export interface KnockProviderState {
8
- knock: Knock;
9
- }
10
-
11
- const ProviderStateContext = React.createContext<KnockProviderState | null>(
12
- null,
13
- );
14
-
15
- export interface KnockProviderProps {
16
- // Knock client props
17
- apiKey: string;
18
- host?: string;
19
- // Authentication props
20
- userId: string;
21
- userToken?: string;
22
-
23
- // Extra options
24
- children?: React.ReactElement;
25
-
26
- // i18n translations
27
- i18n?: I18nContent;
28
- }
29
-
30
- export const KnockProvider: React.FC<KnockProviderProps> = ({
31
- apiKey,
32
- host,
33
- userId,
34
- userToken,
35
- children,
36
- i18n,
37
- }) => {
38
- const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {
39
- host,
40
- });
41
-
42
- return (
43
- <ProviderStateContext.Provider
44
- value={{
45
- knock,
46
- }}
47
- >
48
- <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>
49
- </ProviderStateContext.Provider>
50
- );
51
- };
52
-
53
- export const useKnockClient = (): Knock => {
54
- const context = React.useContext(ProviderStateContext) as KnockProviderState;
55
- if (context === undefined) {
56
- throw new Error("useKnock must be used within a KnockProvider");
57
- }
58
- return context.knock;
59
- };
@@ -1 +0,0 @@
1
- export * from "./KnockProvider";
@@ -1,23 +0,0 @@
1
- import React, { useMemo } from "react";
2
- import Knock, { KnockOptions } from "@knocklabs/client";
3
-
4
- function useAuthenticatedKnockClient(
5
- apiKey: string,
6
- userId: string,
7
- userToken: string | undefined,
8
- options: KnockOptions = {},
9
- ) {
10
- const knockRef = React.useRef<Knock | null>();
11
-
12
- return useMemo(() => {
13
- if (knockRef.current) knockRef.current.teardown();
14
-
15
- const knock = new Knock(apiKey, options);
16
- knock.authenticate(userId, userToken);
17
- knockRef.current = knock;
18
-
19
- return knock;
20
- }, [apiKey, userId, userToken]);
21
- }
22
-
23
- export default useAuthenticatedKnockClient;
@@ -1,55 +0,0 @@
1
- import { FeedClientOptions } from "@knocklabs/client";
2
- import { parseISO, formatDistance, Locale } from "date-fns";
3
- import { ReactNode } from "react";
4
-
5
- export function formatBadgeCount(count: number): string | number {
6
- return count > 9 ? "9+" : count;
7
- }
8
-
9
- type FormatTimestampOptions = {
10
- locale?: Locale;
11
- };
12
-
13
- export function formatTimestamp(
14
- ts: string,
15
- options: FormatTimestampOptions = {},
16
- ) {
17
- try {
18
- const parsedTs = parseISO(ts);
19
- const formatted = formatDistance(parsedTs, new Date(), {
20
- addSuffix: true,
21
- locale: options.locale,
22
- });
23
-
24
- return formatted;
25
- } catch (e) {
26
- return ts;
27
- }
28
- }
29
-
30
- export function toSentenceCase(string: string): string {
31
- return string.charAt(0).toUpperCase() + string.slice(1);
32
- }
33
-
34
- export function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {
35
- return node !== undefined ? node : fallback;
36
- }
37
-
38
- /*
39
- Used to build a consistent key for the KnockFeedProvider so that React knows when
40
- to trigger a re-render of the context when a key property changes.
41
- */
42
- export function feedProviderKey(
43
- userFeedId: string,
44
- options: FeedClientOptions = {},
45
- ) {
46
- return [
47
- userFeedId,
48
- options.source,
49
- options.tenant,
50
- options.has_tenant,
51
- options.archived,
52
- ]
53
- .filter((f) => f !== null && f !== undefined)
54
- .join("-");
55
- }
@@ -1,8 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- import "./styles.css";
3
-
4
- export const KnockFeedContainer: React.FC<PropsWithChildren> = ({
5
- children,
6
- }) => {
7
- return <div className="rnf-feed-provider">{children}</div>;
8
- };
@@ -1,78 +0,0 @@
1
- import * as React from "react";
2
- import Knock, {
3
- Feed,
4
- FeedClientOptions,
5
- FeedStoreState,
6
- } from "@knocklabs/client";
7
- import create, { StoreApi, UseStore } from "zustand";
8
-
9
- import { ColorMode } from "../../core/constants";
10
- import useNotifications from "../hooks/useNotifications";
11
- import { feedProviderKey } from "../../core/utils";
12
- import { KnockFeedContainer } from "./KnockFeedContainer";
13
- import { useKnockClient } from "../../core";
14
-
15
- export interface KnockFeedProviderState {
16
- knock: Knock;
17
- feedClient: Feed;
18
- useFeedStore: UseStore<FeedStoreState>;
19
- colorMode: ColorMode;
20
- }
21
-
22
- const FeedStateContext = React.createContext<KnockFeedProviderState | null>(
23
- null,
24
- );
25
-
26
- export interface KnockFeedProviderProps {
27
- // Feed props
28
- feedId: string;
29
-
30
- // Extra options
31
- children?: React.ReactElement;
32
- rootless?: boolean;
33
- colorMode?: ColorMode;
34
-
35
- // Feed client options
36
- defaultFeedOptions?: FeedClientOptions;
37
- }
38
-
39
- export const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({
40
- feedId,
41
- children,
42
- defaultFeedOptions = {},
43
- rootless = false,
44
- colorMode = "light",
45
- }) => {
46
- const knock = useKnockClient();
47
-
48
- const feedClient = useNotifications(knock, feedId, defaultFeedOptions);
49
- const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);
50
-
51
- const content = rootless ? (
52
- children
53
- ) : (
54
- <KnockFeedContainer>{children}</KnockFeedContainer>
55
- );
56
-
57
- return (
58
- <FeedStateContext.Provider
59
- key={feedProviderKey(feedId, defaultFeedOptions)}
60
- value={{
61
- knock,
62
- feedClient,
63
- useFeedStore,
64
- colorMode,
65
- }}
66
- >
67
- {content}
68
- </FeedStateContext.Provider>
69
- );
70
- };
71
-
72
- export const useKnockFeed = (): KnockFeedProviderState => {
73
- const context = React.useContext(FeedStateContext);
74
- if (context === undefined) {
75
- throw new Error("useKnockFeed must be used within a KnockFeedProvider");
76
- }
77
- return context as KnockFeedProviderState;
78
- };
@@ -1,2 +0,0 @@
1
- export * from "./KnockFeedProvider";
2
- export * from "./KnockFeedContainer";
@@ -1,10 +0,0 @@
1
- .rnf-feed-provider {
2
- font-family: var(--rnf-font-family-sanserif) !important;
3
- margin: 0 !important;
4
- padding: 0 !important;
5
- }
6
-
7
- .rnf-feed-provider * {
8
- font-family: var(--rnf-font-family-sanserif) !important;
9
- box-sizing: border-box;
10
- }
@@ -1,44 +0,0 @@
1
- import { Feed } from "@knocklabs/client";
2
- import { useEffect, useState } from "react";
3
-
4
- export type FeedSettings = {
5
- features: {
6
- branding_required: boolean;
7
- };
8
- };
9
-
10
- function useFeedSettings(feedClient: Feed): {
11
- settings: FeedSettings | null;
12
- loading: boolean;
13
- } {
14
- const [settings, setSettings] = useState(null);
15
- const [isLoading, setIsLoading] = useState(false);
16
-
17
- // TODO: consider moving this into the feed client and into the feed store state when
18
- // we're using this in other areas of the feed
19
- useEffect(() => {
20
- async function getSettings() {
21
- const knock = feedClient.knock;
22
- const apiClient = knock.client();
23
- const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;
24
- setIsLoading(true);
25
-
26
- const response = await apiClient.makeRequest({
27
- method: "GET",
28
- url: feedSettingsPath,
29
- });
30
-
31
- if (!response.error) {
32
- setSettings(response.body);
33
- }
34
-
35
- setIsLoading(false);
36
- }
37
-
38
- getSettings();
39
- }, []);
40
-
41
- return { settings, loading: isLoading };
42
- }
43
-
44
- export default useFeedSettings;
@@ -1,30 +0,0 @@
1
- import Knock, { Feed, FeedClientOptions } from "@knocklabs/client";
2
- import { useMemo, useRef } from "react";
3
-
4
- function useNotifications(
5
- knock: Knock,
6
- feedId: string,
7
- options: FeedClientOptions = {},
8
- ) {
9
- const feedClientRef = useRef<Feed | null>();
10
-
11
- return useMemo(() => {
12
- if (feedClientRef.current) feedClientRef.current.teardown();
13
-
14
- const feedClient = knock.feeds.initialize(feedId, options);
15
-
16
- feedClient.listenForUpdates();
17
- feedClientRef.current = feedClient;
18
-
19
- return feedClient;
20
- }, [
21
- knock,
22
- feedId,
23
- options.source,
24
- options.tenant,
25
- options.has_tenant,
26
- options.archived,
27
- ]);
28
- }
29
-
30
- export default useNotifications;
@@ -1,16 +0,0 @@
1
- import React from "react";
2
- import { locales, I18nContent } from "../languages";
3
-
4
- export const I18nContext = React.createContext<I18nContent>(locales.en);
5
-
6
- interface KnockI18nProviderProps {
7
- i18n?: I18nContent;
8
- children: JSX.Element | undefined;
9
- }
10
-
11
- export function KnockI18nProvider({
12
- i18n = locales.en,
13
- ...props
14
- }: KnockI18nProviderProps) {
15
- return <I18nContext.Provider {...props} value={i18n} />;
16
- }