@dropby/react 0.4.0
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/LICENSE +21 -0
- package/README.md +220 -0
- package/dist/chunks/chat-attachment-types-BG8VFQj5.d.ts +56 -0
- package/dist/chunks/chat-attachments-uP-PsyQf.js +21 -0
- package/dist/chunks/use-dropby-BW4iKpiA.js +54 -0
- package/dist/chunks/use-feature-gByQaSp1.js +78 -0
- package/dist/components/chat-attachments/index.d.ts +9 -0
- package/dist/components/chat-attachments/index.js +88 -0
- package/dist/components/index.d.ts +290 -0
- package/dist/components/index.js +1095 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +47 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { AsksActions, AsksActions as AsksActions$1, AsksState, AsyncResource, BootstrapState, CapabilityState, ChatActions, ChatActions as ChatActions$1, ChatHistoryLoadState, ChatState, ChatThread, ChatThreadActions, ChatThreadActions as ChatThreadActions$1, ChatThreadsCollection, ChatUnread, ConnectionState, DropBy, DropById, DropByOptions, FlagValue, Idea, IdeasActions, IdeasActions as IdeasActions$1, IdeasState, PagedCollection, PendingAsksCollection, ResolvedFeatureConfig } from "@dropby/browser";
|
|
3
|
+
type OwnsCoreProps = {
|
|
4
|
+
/** Options for the instance the provider creates, starts and destroys. Read once. */
|
|
5
|
+
options: DropByOptions;
|
|
6
|
+
/** Pass `options` or `dropby`, not both. */
|
|
7
|
+
dropby?: undefined;
|
|
8
|
+
/** The part of your app that uses DropBy. */
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
type ExternalCoreProps = {
|
|
12
|
+
/** An instance you created; you start and destroy it. */
|
|
13
|
+
dropby: DropBy;
|
|
14
|
+
/** Pass `options` or `dropby`, not both. */
|
|
15
|
+
options?: undefined;
|
|
16
|
+
/** The part of your app that uses DropBy. */
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Props for `DropByProvider`: the `options` to create an instance from, or an
|
|
21
|
+
* instance of your own.
|
|
22
|
+
*/
|
|
23
|
+
type DropByProviderProps = OwnsCoreProps | ExternalCoreProps;
|
|
24
|
+
/**
|
|
25
|
+
* Makes a DropBy instance available to the hooks and components below it. With
|
|
26
|
+
* `options` it creates the instance, starts it once mounted and destroys it on
|
|
27
|
+
* unmount; give it a `key` of the signed-in user's and account's ids so a new
|
|
28
|
+
* identity gets a new instance. With `dropby` it only provides yours.
|
|
29
|
+
*/
|
|
30
|
+
export declare function DropByProvider(props: DropByProviderProps): ReactNode;
|
|
31
|
+
/** The DropBy instance from the nearest `DropByProvider`. Throws outside one. */
|
|
32
|
+
export declare function useDropBy(): DropBy;
|
|
33
|
+
/** The instance's live state, from `useDropByState`. */
|
|
34
|
+
interface UseDropByStateResult {
|
|
35
|
+
/** How live updates arrive. */
|
|
36
|
+
connection: ConnectionState;
|
|
37
|
+
/** What the session may do, with your team's widget settings applied. */
|
|
38
|
+
capabilities: CapabilityState;
|
|
39
|
+
/** The signed-in session, with its feature flags. */
|
|
40
|
+
bootstrap: BootstrapState;
|
|
41
|
+
}
|
|
42
|
+
/** The instance's connection, capabilities and session, re-rendering when any of them changes. */
|
|
43
|
+
export declare function useDropByState(): UseDropByStateResult;
|
|
44
|
+
/** What `useChatThreads` returns. */
|
|
45
|
+
interface UseChatThreadsResult<Data> {
|
|
46
|
+
/** The conversation list, or what your selector picked from chat's state. */
|
|
47
|
+
data: Data;
|
|
48
|
+
/** Chat's actions; the same object on every render. */
|
|
49
|
+
actions: ChatActions$1;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The conversation list and chat's actions. Load it with
|
|
53
|
+
* `actions.listThreads()`. Pass a selector to read another part of chat's
|
|
54
|
+
* state; the component then re-renders only when that part changes, compared
|
|
55
|
+
* with `isEqual` when you give one.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useChatThreads(): UseChatThreadsResult<ChatThreadsCollection>;
|
|
58
|
+
export declare function useChatThreads<Selected>(selector: (state: ChatState) => Selected, isEqual?: (a: Selected, b: Selected) => boolean): UseChatThreadsResult<Selected>;
|
|
59
|
+
/** What `useChatThread` returns. */
|
|
60
|
+
interface UseChatThreadResult<Data> {
|
|
61
|
+
/** The conversation as loaded, or what your selector picked from chat's state. */
|
|
62
|
+
data: Data;
|
|
63
|
+
/** The load of older messages, once one started. */
|
|
64
|
+
olderMessages: ChatHistoryLoadState | undefined;
|
|
65
|
+
/** The load of the newest messages, once one started. */
|
|
66
|
+
latestMessages: ChatHistoryLoadState | undefined;
|
|
67
|
+
/** The conversation's actions, its id bound; the same object while the id is. */
|
|
68
|
+
actions: ChatThreadActions$1;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* One conversation and its actions. Load it with `actions.open()`. While the
|
|
72
|
+
* component is mounted its live updates are applied. Pass a selector to read
|
|
73
|
+
* another part of chat's state.
|
|
74
|
+
*/
|
|
75
|
+
export declare function useChatThread(id: DropById<"thr_">): UseChatThreadResult<AsyncResource<ChatThread> | undefined>;
|
|
76
|
+
export declare function useChatThread<Selected>(id: DropById<"thr_">, selector: (state: ChatState) => Selected, isEqual?: (a: Selected, b: Selected) => boolean): UseChatThreadResult<Selected>;
|
|
77
|
+
/**
|
|
78
|
+
* Unread replies across the user's conversations, and chat's actions. Load with
|
|
79
|
+
* `actions.refreshUnread()`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function useChatUnread(): {
|
|
82
|
+
data: AsyncResource<ChatUnread>;
|
|
83
|
+
actions: ChatActions$1;
|
|
84
|
+
};
|
|
85
|
+
/** What `useIdeas` returns. */
|
|
86
|
+
interface UseIdeasResult<Data> {
|
|
87
|
+
/** The ideas list, or what your selector picked from the board's state. */
|
|
88
|
+
data: Data;
|
|
89
|
+
/** The board's actions; the same object on every render. */
|
|
90
|
+
actions: IdeasActions$1;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The ideas list and the board's actions. It loads nothing itself: list with
|
|
94
|
+
* `actions.list({ view })`. Pass a selector to read another part of the board's
|
|
95
|
+
* state, such as the idea opened.
|
|
96
|
+
*/
|
|
97
|
+
export declare function useIdeas(): UseIdeasResult<PagedCollection<Idea>>;
|
|
98
|
+
export declare function useIdeas<Selected>(selector: (state: IdeasState) => Selected, isEqual?: (a: Selected, b: Selected) => boolean): UseIdeasResult<Selected>;
|
|
99
|
+
/** What `usePendingAsks` returns. */
|
|
100
|
+
interface UsePendingAsksResult<Data> {
|
|
101
|
+
/** The asks waiting for the user, or what your selector picked from the asks state. */
|
|
102
|
+
data: Data;
|
|
103
|
+
/** The asks' actions; the same object on every render. */
|
|
104
|
+
actions: AsksActions$1;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The asks waiting for the user, and their actions. Load them with
|
|
108
|
+
* `actions.listPending()`. Pass a selector to read another part of the asks
|
|
109
|
+
* state.
|
|
110
|
+
*/
|
|
111
|
+
export declare function usePendingAsks(): UsePendingAsksResult<PendingAsksCollection>;
|
|
112
|
+
export declare function usePendingAsks<Selected>(selector: (state: AsksState) => Selected, isEqual?: (a: Selected, b: Selected) => boolean): UsePendingAsksResult<Selected>;
|
|
113
|
+
/**
|
|
114
|
+
* Every feature flag for the signed-in user, empty until the session has loaded.
|
|
115
|
+
* Re-renders when any flag changes, and after a session renewal even when none
|
|
116
|
+
* did; for one flag prefer `useFeatureFlag`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function useFeatureConfig(): ResolvedFeatureConfig;
|
|
119
|
+
/**
|
|
120
|
+
* One feature flag's value; undefined for a flag that does not exist or until the
|
|
121
|
+
* session has loaded. Re-renders only when this flag's value changes.
|
|
122
|
+
*/
|
|
123
|
+
export declare function useFeatureFlag(key: string): FlagValue | undefined;
|
|
124
|
+
export type { AsksActions, ChatActions, ChatThreadActions, DropByProviderProps, IdeasActions, UseChatThreadResult, UseChatThreadsResult, UseDropByStateResult, UseIdeasResult, UsePendingAsksResult };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c as DropByContext, n as useDropByState, t as useDropBy } from "./chunks/use-dropby-BW4iKpiA.js";
|
|
3
|
+
import { a as useChatThread, i as useIdeas, n as useFeatureFlag, o as useChatThreads, r as usePendingAsks, s as useChatUnread, t as useFeatureConfig } from "./chunks/use-feature-gByQaSp1.js";
|
|
4
|
+
import { useEffect, useReducer, useRef } from "react";
|
|
5
|
+
import { createDropBy } from "@dropby/browser";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function DropByProvider(props) {
|
|
8
|
+
if (props.dropby !== void 0) return /* @__PURE__ */ jsx(ExternalCoreProvider, {
|
|
9
|
+
core: props.dropby,
|
|
10
|
+
children: props.children
|
|
11
|
+
});
|
|
12
|
+
return /* @__PURE__ */ jsx(OwnedCoreProvider, {
|
|
13
|
+
options: props.options,
|
|
14
|
+
children: props.children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function ExternalCoreProvider({ core, children }) {
|
|
18
|
+
return /* @__PURE__ */ jsx(DropByContext.Provider, {
|
|
19
|
+
value: core,
|
|
20
|
+
children
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function OwnedCoreProvider({ options, children }) {
|
|
24
|
+
const [, forceRender] = useReducer((tick) => tick + 1, 0);
|
|
25
|
+
const ref = useRef(null);
|
|
26
|
+
if (ref.current === null || ref.current.destroyed) ref.current = {
|
|
27
|
+
core: createDropBy(options),
|
|
28
|
+
destroyed: false
|
|
29
|
+
};
|
|
30
|
+
const entry = ref.current;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (entry.destroyed) {
|
|
33
|
+
forceRender();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
entry.core.start();
|
|
37
|
+
return () => {
|
|
38
|
+
entry.destroyed = true;
|
|
39
|
+
entry.core.destroy();
|
|
40
|
+
};
|
|
41
|
+
}, [entry]);
|
|
42
|
+
return /* @__PURE__ */ jsx(DropByContext.Provider, {
|
|
43
|
+
value: entry.core,
|
|
44
|
+
children
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export { DropByProvider, useChatThread, useChatThreads, useChatUnread, useDropBy, useDropByState, useFeatureConfig, useFeatureFlag, useIdeas, usePendingAsks };
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dropby/react",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "React bindings for DropBy: a provider, hooks and accessible components for chat, ideas and asks.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"dropby",
|
|
8
|
+
"react",
|
|
9
|
+
"customer-support",
|
|
10
|
+
"chat",
|
|
11
|
+
"feedback",
|
|
12
|
+
"feature-requests",
|
|
13
|
+
"surveys",
|
|
14
|
+
"sdk"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Simpllyf Software",
|
|
18
|
+
"homepage": "https://dropby.chat",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./components": {
|
|
28
|
+
"types": "./dist/components/index.d.ts",
|
|
29
|
+
"import": "./dist/components/index.js",
|
|
30
|
+
"default": "./dist/components/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./components/chat-attachments": {
|
|
33
|
+
"types": "./dist/components/chat-attachments/index.d.ts",
|
|
34
|
+
"import": "./dist/components/chat-attachments/index.js",
|
|
35
|
+
"default": "./dist/components/chat-attachments/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "^18 || ^19",
|
|
40
|
+
"react-dom": "^18 || ^19"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"react-dom": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@dropby/browser": "0.4.0"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist"
|
|
52
|
+
],
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "714b80e34a96081832e3c6e66ede69b925c9b851",
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"main": "./dist/index.js"
|
|
59
|
+
}
|