@lapp-studio/react-toast-engine 0.0.1
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 +118 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +38 -0
- package/dist/core.d.cts.map +1 -0
- package/dist/core.d.ts +38 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/native.cjs +1 -0
- package/dist/native.d.cts +10 -0
- package/dist/native.d.cts.map +1 -0
- package/dist/native.d.ts +10 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +2 -0
- package/dist/native.js.map +1 -0
- package/dist/renderer-context-CV7Cqf_Q.js +2 -0
- package/dist/renderer-context-CV7Cqf_Q.js.map +1 -0
- package/dist/renderer-context-Cco23num.cjs +1 -0
- package/dist/toasts-renderer-DsSfXdUq.d.cts +53 -0
- package/dist/toasts-renderer-DsSfXdUq.d.cts.map +1 -0
- package/dist/toasts-renderer-vMIJr1FV.d.ts +52 -0
- package/dist/toasts-renderer-vMIJr1FV.d.ts.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) <year> Adam Veldhousen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# React Toast Engine 🍞
|
|
2
|
+
|
|
3
|
+
**React Toast Engine** is a high-performance, headless toast management library for **React** and **React Native**.
|
|
4
|
+
|
|
5
|
+
It separates state logic (powered by Zustand) from the UI layer, allowing you to share the same notification logic across Web and Mobile while maintaining 60FPS native animations using **Reanimated**.
|
|
6
|
+
|
|
7
|
+
## ✨ Key Features
|
|
8
|
+
|
|
9
|
+
- 🚀 **Zero-Lag State:** Atomic updates via Zustand to prevent unnecessary re-renders.
|
|
10
|
+
- 📱 **Native First:** Deep integration with `react-native-reanimated` and `gesture-handler`.
|
|
11
|
+
- 🌐 **Truly Hybrid:** Multiple entry points to ensure Web builds don't bundle Native code.
|
|
12
|
+
- 🏗️ **Headless & Flexible:** You provide the components; we handle the stack, queue, and lifecycle.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 📦 Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# npm
|
|
20
|
+
npm i @lapp-studio/react-toast-engine
|
|
21
|
+
# yarn
|
|
22
|
+
yarn add @lapp-studio/react-toast-engine
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Peer Dependencies
|
|
26
|
+
|
|
27
|
+
For **React Native** environments, ensure the following are installed:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add react-native-reanimated react-native-gesture-handler react-native-safe-area-context
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🚀 Quick Start
|
|
36
|
+
|
|
37
|
+
### 1. Initialize the Client
|
|
38
|
+
|
|
39
|
+
Define your UI components and initialize the engine.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// src/lib/toasts.ts
|
|
43
|
+
import { createToastsClient } from "@lapp-studio/react-toast-engine";
|
|
44
|
+
import PoolRenderer from "@lapp-studio/react-toast-engine/native"; // For React Native
|
|
45
|
+
|
|
46
|
+
const components = {
|
|
47
|
+
success: MySuccessComponent,
|
|
48
|
+
error: MyErrorComponent,
|
|
49
|
+
info: MyInfoComponent,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const { store, utilities, renderer } = createToastsClient({
|
|
53
|
+
components,
|
|
54
|
+
PoolRenderer,
|
|
55
|
+
storeSettings: { poolLimit: 5 },
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Setup the Provider
|
|
60
|
+
|
|
61
|
+
Wrap your application root with the generated `Provider`.
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { renderer } from "./lib/toasts";
|
|
65
|
+
|
|
66
|
+
export function App() {
|
|
67
|
+
return (
|
|
68
|
+
<renderer.Provider>
|
|
69
|
+
<MainScreen />
|
|
70
|
+
</renderer.Provider>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 3. Trigger Toasts
|
|
76
|
+
|
|
77
|
+
Use hooks inside components or helpers for business logic (e.g., API interceptors).
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { utilities } from "./lib/toasts";
|
|
81
|
+
|
|
82
|
+
// Inside a React Component
|
|
83
|
+
const stack = utilities.hooks.useStackToast();
|
|
84
|
+
|
|
85
|
+
// Outside React (e.g., inside an Axios Interceptor)
|
|
86
|
+
utilities.helpers.stack({
|
|
87
|
+
title: "Success!",
|
|
88
|
+
description: "Changes saved successfully.",
|
|
89
|
+
infoType: "success",
|
|
90
|
+
durationInMs: 3000,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 🛠️ Architecture
|
|
97
|
+
|
|
98
|
+
The library follows a **Decoupled Provider-Consumer** pattern:
|
|
99
|
+
|
|
100
|
+
1. **Store (Zustand):** Manages the global toast pool and provider stack.
|
|
101
|
+
2. **Utilities:** Provides a clean API via `hooks` for UI and `helpers` for logic.
|
|
102
|
+
3. **Renderer:** Handles priority. If multiple providers are present, only the topmost (latest) one renders the active toasts to prevent duplicates.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 📱 React Native Specifics
|
|
107
|
+
|
|
108
|
+
The native build uses **Shared Values** and **Worklets** for maximum performance:
|
|
109
|
+
|
|
110
|
+
- **Swipe to Dismiss:** Fully interactive gestures to clear notifications.
|
|
111
|
+
- **Safe Area Aware:** Automatically calculates offsets using `react-native-safe-area-context`.
|
|
112
|
+
- **Z-Index Management:** Smart stacking logic that works across different navigation screens.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 📄 License
|
|
117
|
+
|
|
118
|
+
MIT © LApp
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./renderer-context-Cco23num.cjs`);require(`./native.cjs`);let t=require(`react`),n=require(`react/jsx-runtime`),r=require(`zustand`);const i=({components:r,PoolRenderer:i,store:a})=>{let o=a;return{Provider:({children:s})=>{let c=(0,t.useId)(),l=o(e=>e.addProvider),u=o(e=>e.removeProvider),d=o(e=>e.providers.length===0||e.providers.at(0)===c);return(0,t.useEffect)(()=>(l(c),()=>{u(c)}),[c,l,u]),(0,n.jsx)(e.t,{components:r,store:a,children:d?(0,n.jsx)(i,{children:s}):s})}}},a=()=>Math.random().toString(36).substring(2,9),o=({poolLimit:e=10}={})=>(0,r.create)(t=>({pool:[],providers:[],stack:n=>t(t=>({...t,pool:[...t.pool.length>=e?t.pool.slice(e-1):t.pool,{id:a(),...n}]})),remove:e=>t(t=>({...t,pool:t.pool.filter(t=>t.id!==e)})),pop:()=>t(e=>({...e,pool:e.pool.slice(0,1)})),addProvider:e=>t(t=>({...t,providers:[...new Set([e,...t.providers])]})),removeProvider:e=>t(t=>({...t,providers:t.providers.filter(t=>t!==e)}))})),s=e=>({stack:t=>e.getState().stack(t),remove:t=>e.getState().remove(t),pop:()=>e.getState().pop()}),c=({store:e})=>({hooks:{useStackToast:()=>e(e=>e.stack),useRemoveToast:()=>e(e=>e.remove),useToastsPool:()=>e(e=>e.pool)},helpers:s(e)}),l=({components:e,PoolRenderer:t,storeSettings:n})=>{let r=o(n);return{store:r,utilities:c({store:r}),renderer:i({components:e,PoolRenderer:t,store:r})}};let u=function(e){return e.info=`info`,e.error=`error`,e.success=`success`,e}({});exports.ToastInfoType=u,exports.createToastsClient=l;
|
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { a as ToastsStoreSettings, c as ToastAction, i as ToastsStore, l as ToastActions, n as ToastsPoolRendererProps, o as NewToast, r as ToastsProviderProps, s as Toast, t as ToastsComponentsByInfoType, u as ToastInfoType } from "./toasts-renderer-DsSfXdUq.cjs";
|
|
2
|
+
import * as zustand from "zustand";
|
|
3
|
+
import { ElementType } from "react";
|
|
4
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/core/createToastsClient.d.ts
|
|
7
|
+
type Parameters = {
|
|
8
|
+
components: ToastsComponentsByInfoType;
|
|
9
|
+
PoolRenderer: ElementType<ToastsPoolRendererProps>;
|
|
10
|
+
storeSettings?: ToastsStoreSettings;
|
|
11
|
+
};
|
|
12
|
+
declare const createToastsClient: ({
|
|
13
|
+
components,
|
|
14
|
+
PoolRenderer,
|
|
15
|
+
storeSettings
|
|
16
|
+
}: Parameters) => {
|
|
17
|
+
store: zustand.UseBoundStore<zustand.StoreApi<ToastsStore>>;
|
|
18
|
+
utilities: {
|
|
19
|
+
hooks: {
|
|
20
|
+
useStackToast: () => (toast: NewToast) => void;
|
|
21
|
+
useRemoveToast: () => (toast: Toast["id"]) => void;
|
|
22
|
+
useToastsPool: () => Toast[];
|
|
23
|
+
};
|
|
24
|
+
helpers: {
|
|
25
|
+
stack: (toast: NewToast) => void;
|
|
26
|
+
remove: (toastId: Toast["id"]) => void;
|
|
27
|
+
pop: () => void;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
renderer: {
|
|
31
|
+
Provider: ({
|
|
32
|
+
children
|
|
33
|
+
}: ToastsProviderProps) => react_jsx_runtime0.JSX.Element;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { NewToast, Toast, ToastAction, ToastActions, ToastInfoType, ToastsStore, ToastsStoreSettings, createToastsClient };
|
|
38
|
+
//# sourceMappingURL=core.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.cts","names":[],"sources":["../src/core/createToastsClient.ts"],"mappings":";;;;;;KAWK,UAAA;EACH,UAAA,EAAY,0BAAA;EACZ,YAAA,EAAc,WAAA,CAAY,uBAAA;EAC1B,aAAA,GAAgB,mBAAA;AAAA;AAAA,cAGL,kBAAA;EAAsB,UAAA;EAAA,YAAA;EAAA;AAAA,GAIhC,UAAA;gDAAU,WAAA"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { a as ToastsStoreSettings, c as ToastAction, i as ToastsStore, l as ToastActions, n as ToastsPoolRendererProps, o as NewToast, r as ToastsProviderProps, s as Toast, t as ToastsComponentsByInfoType, u as ToastInfoType } from "./toasts-renderer-vMIJr1FV.js";
|
|
2
|
+
import { ElementType } from "react";
|
|
3
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import * as zustand from "zustand";
|
|
5
|
+
|
|
6
|
+
//#region src/core/createToastsClient.d.ts
|
|
7
|
+
type Parameters = {
|
|
8
|
+
components: ToastsComponentsByInfoType;
|
|
9
|
+
PoolRenderer: ElementType<ToastsPoolRendererProps>;
|
|
10
|
+
storeSettings?: ToastsStoreSettings;
|
|
11
|
+
};
|
|
12
|
+
declare const createToastsClient: ({
|
|
13
|
+
components,
|
|
14
|
+
PoolRenderer,
|
|
15
|
+
storeSettings
|
|
16
|
+
}: Parameters) => {
|
|
17
|
+
store: zustand.UseBoundStore<zustand.StoreApi<ToastsStore>>;
|
|
18
|
+
utilities: {
|
|
19
|
+
hooks: {
|
|
20
|
+
useStackToast: () => (toast: NewToast) => void;
|
|
21
|
+
useRemoveToast: () => (toast: Toast["id"]) => void;
|
|
22
|
+
useToastsPool: () => Toast[];
|
|
23
|
+
};
|
|
24
|
+
helpers: {
|
|
25
|
+
stack: (toast: NewToast) => void;
|
|
26
|
+
remove: (toastId: Toast["id"]) => void;
|
|
27
|
+
pop: () => void;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
renderer: {
|
|
31
|
+
Provider: ({
|
|
32
|
+
children
|
|
33
|
+
}: ToastsProviderProps) => react_jsx_runtime0.JSX.Element;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { NewToast, Toast, ToastAction, ToastActions, ToastInfoType, ToastsStore, ToastsStoreSettings, createToastsClient };
|
|
38
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","names":[],"sources":["../src/core/createToastsClient.ts"],"mappings":";;;;;;KAWK,UAAA;EACH,UAAA,EAAY,0BAAA;EACZ,YAAA,EAAc,WAAA,CAAY,uBAAA;EAC1B,aAAA,GAAgB,mBAAA;AAAA;AAAA,cAGL,kBAAA;EAAsB,UAAA;EAAA,YAAA;EAAA;AAAA,GAIhC,UAAA;gDAAU,WAAA"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./renderer-context-CV7Cqf_Q.js";import{useEffect as t,useId as n}from"react";import{jsx as r}from"react/jsx-runtime";import{create as i}from"zustand";const a=({components:i,PoolRenderer:a,store:o})=>{let s=o;return{Provider:({children:c})=>{let l=n(),u=s(e=>e.addProvider),d=s(e=>e.removeProvider),f=s(e=>e.providers.length===0||e.providers.at(0)===l);return t(()=>(u(l),()=>{d(l)}),[l,u,d]),r(e,{components:i,store:o,children:f?r(a,{children:c}):c})}}},o=()=>Math.random().toString(36).substring(2,9),s=({poolLimit:e=10}={})=>i(t=>({pool:[],providers:[],stack:n=>t(t=>({...t,pool:[...t.pool.length>=e?t.pool.slice(e-1):t.pool,{id:o(),...n}]})),remove:e=>t(t=>({...t,pool:t.pool.filter(t=>t.id!==e)})),pop:()=>t(e=>({...e,pool:e.pool.slice(0,1)})),addProvider:e=>t(t=>({...t,providers:[...new Set([e,...t.providers])]})),removeProvider:e=>t(t=>({...t,providers:t.providers.filter(t=>t!==e)}))})),c=e=>({stack:t=>e.getState().stack(t),remove:t=>e.getState().remove(t),pop:()=>e.getState().pop()}),l=({store:e})=>({hooks:{useStackToast:()=>e(e=>e.stack),useRemoveToast:()=>e(e=>e.remove),useToastsPool:()=>e(e=>e.pool)},helpers:c(e)}),u=({components:e,PoolRenderer:t,storeSettings:n})=>{let r=s(n);return{store:r,utilities:l({store:r}),renderer:a({components:e,PoolRenderer:t,store:r})}};let d=function(e){return e.info=`info`,e.error=`error`,e.success=`success`,e}({});export{d as ToastInfoType,u as createToastsClient};
|
|
2
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","names":[],"sources":["../src/core/utils/create-toasts-renderer.tsx","../src/core/utils/create-toast-id.ts","../src/core/utils/create-toasts-store.ts","../src/core/utils/create-toasts-utilities.ts","../src/core/createToastsClient.ts","../src/core/types/toast.ts"],"sourcesContent":["import { ElementType, useEffect, useId } from \"react\";\n\nimport { createToastsStore } from \"./create-toasts-store\";\n\nimport RendererProviderContext from \"../providers/renderer-context\";\nimport {\n ToastsComponentsByInfoType,\n ToastsPoolRendererProps,\n ToastsProviderProps,\n} from \"../types/toasts-renderer\";\n\ntype Parameters = {\n components: ToastsComponentsByInfoType;\n store: ReturnType<typeof createToastsStore>;\n PoolRenderer: ElementType<ToastsPoolRendererProps>;\n};\n\nexport const createToastsRenderer = ({\n components,\n PoolRenderer,\n store,\n}: Parameters) => {\n const useStore = store;\n const Provider = ({ children }: ToastsProviderProps) => {\n const id = useId();\n const addProvider = useStore((store) => store.addProvider);\n const removeProvider = useStore((store) => store.removeProvider);\n const isCurrentProvider = useStore(\n (store) => store.providers.length === 0 || store.providers.at(0) === id,\n );\n\n useEffect(() => {\n addProvider(id);\n return () => {\n removeProvider(id);\n };\n }, [id, addProvider, removeProvider]);\n\n return (\n <RendererProviderContext components={components} store={store}>\n {isCurrentProvider ? <PoolRenderer>{children}</PoolRenderer> : children}\n </RendererProviderContext>\n );\n };\n\n return { Provider };\n};\n","export const createToastRandomId = (): string =>\n Math.random().toString(36).substring(2, 9);\n","import { create } from \"zustand\";\n\nimport { ToastsStore, ToastsStoreSettings } from \"../types/toasts-store\";\nimport { createToastRandomId } from \"./create-toast-id\";\n\nconst DEFAULT_POOL_LIMIT = 10;\n\nexport const createToastsStore = ({\n poolLimit = DEFAULT_POOL_LIMIT,\n}: ToastsStoreSettings = {}) => {\n const store = create<ToastsStore>((set) => ({\n pool: [],\n providers: [],\n stack: (toast) =>\n set((store) => ({\n ...store,\n pool: [\n ...(store.pool.length >= poolLimit\n ? store.pool.slice(poolLimit - 1)\n : store.pool),\n { id: createToastRandomId(), ...toast },\n ],\n })),\n remove: (toastId) =>\n set((store) => ({\n ...store,\n pool: store.pool.filter((t) => t.id !== toastId),\n })),\n pop: () => set((store) => ({ ...store, pool: store.pool.slice(0, 1) })),\n\n addProvider: (providerId) =>\n set((store) => ({\n ...store,\n providers: [...new Set([providerId, ...store.providers])],\n })),\n\n removeProvider: (providerId) =>\n set((store) => ({\n ...store,\n providers: store.providers.filter((id) => id !== providerId),\n })),\n }));\n\n return store;\n};\n","import { createToastsStore } from \"./create-toasts-store\";\n\nimport { NewToast, Toast } from \"../types/toast\";\n\ntype Parameters = {\n store: ReturnType<typeof createToastsStore>;\n};\n\nconst getHelpers = (store: Parameters[\"store\"]) => {\n const stack = (toast: NewToast) => store.getState().stack(toast);\n const remove = (toastId: Toast[\"id\"]) => store.getState().remove(toastId);\n const pop = () => store.getState().pop();\n\n return { stack, remove, pop };\n};\n\nexport const createToastsUtilities = ({ store: useStore }: Parameters) => {\n const useStackToast = () => {\n return useStore((store) => store.stack);\n };\n const useRemoveToast = () => {\n return useStore((store) => store.remove);\n };\n const useToastsPool = () => {\n return useStore((store) => store.pool);\n };\n\n const hooks = {\n useStackToast,\n useRemoveToast,\n useToastsPool,\n };\n\n const helpers = getHelpers(useStore);\n\n return { hooks, helpers };\n};\n","import { ElementType } from \"react\";\n\nimport {\n ToastsComponentsByInfoType,\n ToastsPoolRendererProps,\n} from \"./types/toasts-renderer\";\nimport { createToastsRenderer } from \"./utils/create-toasts-renderer\";\nimport { createToastsStore } from \"./utils/create-toasts-store\";\nimport { createToastsUtilities } from \"./utils/create-toasts-utilities\";\nimport { ToastsStoreSettings } from \"./types/toasts-store\";\n\ntype Parameters = {\n components: ToastsComponentsByInfoType;\n PoolRenderer: ElementType<ToastsPoolRendererProps>;\n storeSettings?: ToastsStoreSettings;\n};\n\nexport const createToastsClient = ({\n components,\n PoolRenderer,\n storeSettings,\n}: Parameters) => {\n const store = createToastsStore(storeSettings);\n const utilities = createToastsUtilities({ store });\n const renderer = createToastsRenderer({\n components,\n PoolRenderer,\n store,\n });\n\n return { store, utilities, renderer };\n};\n","export enum ToastInfoType {\n info = \"info\",\n error = \"error\",\n success = \"success\",\n}\n\nexport type Toast = {\n id: string;\n title: string;\n description: string;\n durationInMs: number;\n infoType: `${ToastInfoType}`;\n};\n\nexport type NewToast = Omit<Toast, \"id\">;\n\nexport type ToastAction = (toast: Toast) => void;\n\nexport type ToastActions = {\n onDismiss?: ToastAction;\n onPress?: ToastAction;\n};\n"],"mappings":"yKAiBA,MAAa,GAAwB,CACnC,aACA,eACA,WACgB,CAChB,IAAM,EAAW,EAuBjB,MAAO,CAAE,UAtBS,CAAE,cAAoC,CACtD,IAAM,EAAK,GAAO,CACZ,EAAc,EAAU,GAAU,EAAM,YAAY,CACpD,EAAiB,EAAU,GAAU,EAAM,eAAe,CAC1D,EAAoB,EACvB,GAAU,EAAM,UAAU,SAAW,GAAK,EAAM,UAAU,GAAG,EAAE,GAAK,EACtE,CASD,OAPA,OACE,EAAY,EAAG,KACF,CACX,EAAe,EAAG,GAEnB,CAAC,EAAI,EAAa,EAAe,CAAC,CAGnC,EAAC,EAAD,CAAqC,aAAmB,iBACrD,EAAoB,EAAC,EAAD,CAAe,WAAwB,CAAA,CAAG,EACvC,CAAA,EAIX,EC7CR,MACX,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAG,EAAE,CCM/B,GAAqB,CAChC,YAAY,IACW,EAAE,GACX,EAAqB,IAAS,CAC1C,KAAM,EAAE,CACR,UAAW,EAAE,CACb,MAAQ,GACN,EAAK,IAAW,CACd,GAAG,EACH,KAAM,CACJ,GAAI,EAAM,KAAK,QAAU,EACrB,EAAM,KAAK,MAAM,EAAY,EAAE,CAC/B,EAAM,KACV,CAAE,GAAI,GAAqB,CAAE,GAAG,EAAO,CACxC,CACF,EAAE,CACL,OAAS,GACP,EAAK,IAAW,CACd,GAAG,EACH,KAAM,EAAM,KAAK,OAAQ,GAAM,EAAE,KAAO,EAAQ,CACjD,EAAE,CACL,QAAW,EAAK,IAAW,CAAE,GAAG,EAAO,KAAM,EAAM,KAAK,MAAM,EAAG,EAAE,CAAE,EAAE,CAEvE,YAAc,GACZ,EAAK,IAAW,CACd,GAAG,EACH,UAAW,CAAC,GAAG,IAAI,IAAI,CAAC,EAAY,GAAG,EAAM,UAAU,CAAC,CAAC,CAC1D,EAAE,CAEL,eAAiB,GACf,EAAK,IAAW,CACd,GAAG,EACH,UAAW,EAAM,UAAU,OAAQ,GAAO,IAAO,EAAW,CAC7D,EAAE,CACN,EAAE,CCjCC,EAAc,IAKX,CAAE,MAJM,GAAoB,EAAM,UAAU,CAAC,MAAM,EAAM,CAIhD,OAHA,GAAyB,EAAM,UAAU,CAAC,OAAO,EAAQ,CAGjD,QAFN,EAAM,UAAU,CAAC,KAAK,CAEX,EAGlB,GAAyB,CAAE,MAAO,MAmBtC,CAAE,MARK,CACZ,kBAVO,EAAU,GAAU,EAAM,MAAM,CAWvC,mBARO,EAAU,GAAU,EAAM,OAAO,CASxC,kBANO,EAAU,GAAU,EAAM,KAAK,CAOvC,CAIe,QAFA,EAAW,EAAS,CAEX,EClBd,GAAsB,CACjC,aACA,eACA,mBACgB,CAChB,IAAM,EAAQ,EAAkB,EAAc,CAQ9C,MAAO,CAAE,QAAO,UAPE,EAAsB,CAAE,QAAO,CAAC,CAOvB,SANV,EAAqB,CACpC,aACA,eACA,QACD,CAAC,CAEmC,EC9BvC,IAAY,EAAL,SAAA,EAAA,OACL,GAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,QAAA,gBACD"}
|
package/dist/native.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./renderer-context-Cco23num.cjs`);let l=require(`react`),u=require(`react/jsx-runtime`),d=require(`react-native`),f=require(`react-native-reanimated`);f=s(f);let p=require(`react-native-safe-area-context`),m=require(`react-native-gesture-handler`),h=require(`react-native-worklets`);const g=({children:e,index:t,timeoutInMs:n,id:r})=>{let{width:i}=(0,d.useWindowDimensions)(),{store:a}=c.n(),o=a(e=>e.remove),s=a(e=>e.pool.length),p=(0,l.useRef)(!1),g=(0,f.useSharedValue)(0),_=t===0,v=(0,l.useCallback)(()=>{o(r)},[r,o]);(0,f.useAnimatedReaction)(()=>Math.abs(g.value)>i*1.5,(e,t)=>{e&&e!==t&&p.current&&(0,h.scheduleOnRN)(v)});let y=m.Gesture.Pan().enabled(_).onChange(e=>{Math.abs(e.velocityX)>1e3&&(p.current=!0),g.value=e.translationX}).onFinalize(e=>{if(!p.current){g.value=(0,f.withSpring)(0);return}g.value=(0,f.withSpring)(e.velocityX>0?i*2:-i*2)}),b=(0,f.useAnimatedStyle)(()=>({zIndex:10+s-t,opacity:(0,f.withTiming)((0,f.interpolate)(t,[0,1],[1,.5],f.Extrapolation.EXTEND)),transform:[{translateY:(0,f.withSpring)((0,f.interpolate)(t,[0,1],[1,10],f.Extrapolation.EXTEND))},{translateX:g.value},{scale:(0,f.withSpring)((0,f.interpolate)(t,[0,1],[1,.95],f.Extrapolation.EXTEND))}]}));return(0,l.useEffect)(()=>{let e;return _&&(e=setTimeout(()=>{v()},n)),()=>{e&&clearTimeout(e)}},[n,v,_]),(0,u.jsx)(f.default.View,{style:[{position:`absolute`,left:0,right:0,top:0},b],children:(0,u.jsx)(m.GestureDetector,{gesture:y,children:e})})},_=()=>{let{store:e,components:t}=c.n(),n=e(e=>e.pool),r=n.length;return n.map((e,n)=>{let i=t[e.infoType];return(0,u.jsx)(f.default.View,{entering:f.FadeInUp,exiting:f.FadeOutUp,children:(0,u.jsx)(g,{index:r-n-1,id:e.id,timeoutInMs:e.durationInMs,children:(0,u.jsx)(i,{toast:e,actions:{}})})},e.id)})},v=({children:e})=>{let{top:t}=(0,p.useSafeAreaInsets)(),{store:n}=c.n(),r=n(e=>e.pool.length>0);return(0,u.jsxs)(d.View,{style:y.container,children:[e,r&&(0,u.jsx)(f.default.View,{style:[y.poolWrapper,{top:t}],entering:f.FadeInUp,exiting:f.FadeOutUp,children:(0,u.jsx)(_,{})})]})},y=d.StyleSheet.create({container:{position:`relative`,flex:1},poolWrapper:{position:`absolute`,flexDirection:`column`,height:100,left:10,right:10},pool:{}});exports.PoolRenderer=v,exports.t=s;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as ToastsPoolRendererProps } from "./toasts-renderer-DsSfXdUq.cjs";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/native/pool-renderer.d.ts
|
|
5
|
+
declare const PoolRenderer: ({
|
|
6
|
+
children
|
|
7
|
+
}: ToastsPoolRendererProps) => react_jsx_runtime0.JSX.Element;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { PoolRenderer };
|
|
10
|
+
//# sourceMappingURL=native.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.cts","names":[],"sources":["../src/native/pool-renderer.tsx"],"mappings":";;;;cAgCa,YAAA;EAAgB;AAAA,GAAc,uBAAA,KAAuB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as ToastsPoolRendererProps } from "./toasts-renderer-vMIJr1FV.js";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/native/pool-renderer.d.ts
|
|
5
|
+
declare const PoolRenderer: ({
|
|
6
|
+
children
|
|
7
|
+
}: ToastsPoolRendererProps) => react_jsx_runtime0.JSX.Element;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { PoolRenderer };
|
|
10
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","names":[],"sources":["../src/native/pool-renderer.tsx"],"mappings":";;;;cAgCa,YAAA;EAAgB;AAAA,GAAc,uBAAA,KAAuB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{n as e}from"./renderer-context-CV7Cqf_Q.js";import{useCallback as t,useEffect as n,useRef as r}from"react";import{jsx as i,jsxs as a}from"react/jsx-runtime";import{StyleSheet as o,View as s,useWindowDimensions as c}from"react-native";import l,{Extrapolation as u,FadeInUp as d,FadeOutUp as f,interpolate as p,useAnimatedReaction as m,useAnimatedStyle as h,useSharedValue as g,withSpring as _,withTiming as v}from"react-native-reanimated";import{useSafeAreaInsets as y}from"react-native-safe-area-context";import{Gesture as b,GestureDetector as x}from"react-native-gesture-handler";import{scheduleOnRN as S}from"react-native-worklets";const C=({children:a,index:o,timeoutInMs:s,id:d})=>{let{width:f}=c(),{store:y}=e(),C=y(e=>e.remove),w=y(e=>e.pool.length),T=r(!1),E=g(0),D=o===0,O=t(()=>{C(d)},[d,C]);m(()=>Math.abs(E.value)>f*1.5,(e,t)=>{e&&e!==t&&T.current&&S(O)});let k=b.Pan().enabled(D).onChange(e=>{Math.abs(e.velocityX)>1e3&&(T.current=!0),E.value=e.translationX}).onFinalize(e=>{if(!T.current){E.value=_(0);return}E.value=_(e.velocityX>0?f*2:-f*2)}),A=h(()=>({zIndex:10+w-o,opacity:v(p(o,[0,1],[1,.5],u.EXTEND)),transform:[{translateY:_(p(o,[0,1],[1,10],u.EXTEND))},{translateX:E.value},{scale:_(p(o,[0,1],[1,.95],u.EXTEND))}]}));return n(()=>{let e;return D&&(e=setTimeout(()=>{O()},s)),()=>{e&&clearTimeout(e)}},[s,O,D]),i(l.View,{style:[{position:`absolute`,left:0,right:0,top:0},A],children:i(x,{gesture:k,children:a})})},w=()=>{let{store:t,components:n}=e(),r=t(e=>e.pool),a=r.length;return r.map((e,t)=>{let r=n[e.infoType];return i(l.View,{entering:d,exiting:f,children:i(C,{index:a-t-1,id:e.id,timeoutInMs:e.durationInMs,children:i(r,{toast:e,actions:{}})})},e.id)})},T=({children:t})=>{let{top:n}=y(),{store:r}=e(),o=r(e=>e.pool.length>0);return a(s,{style:E.container,children:[t,o&&i(l.View,{style:[E.poolWrapper,{top:n}],entering:d,exiting:f,children:i(w,{})})]})},E=o.create({container:{position:`relative`,flex:1},poolWrapper:{position:`absolute`,flexDirection:`column`,height:100,left:10,right:10},pool:{}});export{T as PoolRenderer};
|
|
2
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","names":[],"sources":["../src/native/toast-wrapper.tsx","../src/native/pool-renderer.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\nimport { useWindowDimensions } from \"react-native\";\nimport { Gesture, GestureDetector } from \"react-native-gesture-handler\";\nimport Animated, {\n Extrapolation,\n interpolate,\n useAnimatedReaction,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n withTiming,\n} from \"react-native-reanimated\";\nimport { scheduleOnRN } from \"react-native-worklets\";\n\nimport { useRendererContext } from \"../core/providers/renderer-context\";\n\nconst MIN_DISMISS_VELOCITY = 1e3;\n\ntype ToastWrapperProps = {\n children: React.ReactNode;\n index: number;\n timeoutInMs: number;\n id: string;\n};\n\nexport const ToastWrapper = ({\n children,\n index,\n timeoutInMs,\n id,\n}: ToastWrapperProps) => {\n const { width } = useWindowDimensions();\n const { store: useStore } = useRendererContext();\n\n const remove = useStore((store) => store.remove);\n const count = useStore((store) => store.pool.length);\n\n const shouldDelete = useRef<boolean>(false);\n const offsetX = useSharedValue(0);\n\n const isActive = index === 0;\n\n const handleRemove = useCallback(() => {\n remove(id);\n }, [id, remove]);\n\n useAnimatedReaction(\n () => Math.abs(offsetX.value) > width * 1.5,\n (current, previous) => {\n if (current && current !== previous && shouldDelete.current)\n scheduleOnRN(handleRemove);\n },\n );\n\n const pan = Gesture.Pan()\n .enabled(isActive)\n .onChange((ev) => {\n if (Math.abs(ev.velocityX) > MIN_DISMISS_VELOCITY) {\n shouldDelete.current = true;\n }\n offsetX.value = ev.translationX;\n })\n .onFinalize((ev) => {\n if (!shouldDelete.current) {\n offsetX.value = withSpring(0);\n return;\n }\n offsetX.value = withSpring(ev.velocityX > 0 ? width * 2 : -width * 2);\n });\n\n const animatedStyle = useAnimatedStyle(() => ({\n zIndex: 10 + count - index,\n opacity: withTiming(\n interpolate(index, [0, 1], [1, 0.5], Extrapolation.EXTEND),\n ),\n transform: [\n {\n translateY: withSpring(\n interpolate(index, [0, 1], [1, 10], Extrapolation.EXTEND),\n ),\n },\n { translateX: offsetX.value },\n {\n scale: withSpring(\n interpolate(index, [0, 1], [1, 0.95], Extrapolation.EXTEND),\n ),\n },\n ],\n }));\n\n useEffect(() => {\n let timeout: number;\n if (isActive) {\n timeout = setTimeout(() => {\n handleRemove();\n }, timeoutInMs);\n }\n return () => {\n if (timeout) clearTimeout(timeout);\n };\n }, [timeoutInMs, handleRemove, isActive]);\n\n return (\n <Animated.View\n style={[\n { position: \"absolute\", left: 0, right: 0, top: 0 },\n animatedStyle,\n ]}\n >\n <GestureDetector gesture={pan}>{children}</GestureDetector>\n </Animated.View>\n );\n};\n","import { StyleSheet, View } from \"react-native\";\nimport Animated, { FadeInUp, FadeOutUp } from \"react-native-reanimated\";\nimport { useSafeAreaInsets } from \"react-native-safe-area-context\";\n\nimport { ToastWrapper } from \"./toast-wrapper\";\n\nimport { useRendererContext } from \"../core/providers/renderer-context\";\nimport { ToastsPoolRendererProps } from \"../core/types/toasts-renderer\";\n\nconst Toasts = () => {\n const { store: useStore, components } = useRendererContext();\n\n const pool = useStore((store) => store.pool);\n\n const count = pool.length;\n\n return pool.map((item, index) => {\n const Render = components[item.infoType];\n return (\n <Animated.View entering={FadeInUp} exiting={FadeOutUp} key={item.id}>\n <ToastWrapper\n index={count - index - 1}\n id={item.id}\n timeoutInMs={item.durationInMs}\n >\n <Render toast={item} actions={{}} />\n </ToastWrapper>\n </Animated.View>\n );\n });\n};\n\nexport const PoolRenderer = ({ children }: ToastsPoolRendererProps) => {\n const { top } = useSafeAreaInsets();\n const { store: useStore } = useRendererContext();\n const hasToasts = useStore((store) => store.pool.length > 0);\n\n return (\n <View style={styles.container}>\n {children}\n {hasToasts && (\n <Animated.View\n style={[styles.poolWrapper, { top }]}\n entering={FadeInUp}\n exiting={FadeOutUp}\n >\n <Toasts />\n </Animated.View>\n )}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n position: \"relative\",\n flex: 1,\n },\n poolWrapper: {\n position: \"absolute\",\n flexDirection: \"column\",\n height: 100,\n left: 10,\n right: 10,\n },\n pool: {},\n});\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createContext as e,useContext as t}from"react";import{jsx as n}from"react/jsx-runtime";const r=e({}),i=()=>t(r),a=({children:e,components:t,store:i})=>n(r.Provider,{value:{components:t,store:i},children:e});export{i as n,a as t};
|
|
2
|
+
//# sourceMappingURL=renderer-context-CV7Cqf_Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer-context-CV7Cqf_Q.js","names":[],"sources":["../src/core/providers/renderer-context.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\n\nimport { ToastsRendererContextProps } from \"../types/toasts-renderer\";\n\ntype ContextValues = Partial<\n Pick<ToastsRendererContextProps, \"store\" | \"components\">\n>;\n\nconst Context = createContext<Partial<ContextValues>>({});\n\nexport const useRendererContext = () =>\n useContext(Context) as Required<ContextValues>;\n\nconst RendererProviderContext = ({\n children,\n components,\n store,\n}: ToastsRendererContextProps) => {\n return (\n <Context.Provider value={{ components, store }}>\n {children}\n </Context.Provider>\n );\n};\n\nexport default RendererProviderContext;\n"],"mappings":"8FAQA,MAAM,EAAU,EAAsC,EAAE,CAAC,CAE5C,MACX,EAAW,EAAQ,CAEf,GAA2B,CAC/B,WACA,aACA,WAGE,EAAC,EAAQ,SAAT,CAAkB,MAAO,CAAE,aAAY,QAAO,CAC3C,WACgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`./native.cjs`);let e=require(`react`),t=require(`react/jsx-runtime`);const n=(0,e.createContext)({}),r=()=>(0,e.useContext)(n),i=({children:e,components:r,store:i})=>(0,t.jsx)(n.Provider,{value:{components:r,store:i},children:e});Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ElementType } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/core/types/toast.d.ts
|
|
4
|
+
declare enum ToastInfoType {
|
|
5
|
+
info = "info",
|
|
6
|
+
error = "error",
|
|
7
|
+
success = "success"
|
|
8
|
+
}
|
|
9
|
+
type Toast = {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
durationInMs: number;
|
|
14
|
+
infoType: `${ToastInfoType}`;
|
|
15
|
+
};
|
|
16
|
+
type NewToast = Omit<Toast, "id">;
|
|
17
|
+
type ToastAction = (toast: Toast) => void;
|
|
18
|
+
type ToastActions = {
|
|
19
|
+
onDismiss?: ToastAction;
|
|
20
|
+
onPress?: ToastAction;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/types/toast-component.d.ts
|
|
24
|
+
type ToastComponentProps = {
|
|
25
|
+
toast: Toast;
|
|
26
|
+
actions: ToastActions;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/core/types/toasts-store.d.ts
|
|
30
|
+
type ToastsStore = {
|
|
31
|
+
pool: Toast[];
|
|
32
|
+
providers: string[];
|
|
33
|
+
stack: (toast: NewToast) => void;
|
|
34
|
+
remove: (toast: Toast["id"]) => void;
|
|
35
|
+
pop: () => void;
|
|
36
|
+
addProvider: (providerId: string) => void;
|
|
37
|
+
removeProvider: (providerId: string) => void;
|
|
38
|
+
};
|
|
39
|
+
type ToastsStoreSettings = {
|
|
40
|
+
poolLimit?: number;
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/core/types/toasts-renderer.d.ts
|
|
44
|
+
type ToastsComponentsByInfoType = Record<ToastInfoType, ElementType<ToastComponentProps>>;
|
|
45
|
+
type ToastsPoolRendererProps = {
|
|
46
|
+
children: React.ReactNode;
|
|
47
|
+
};
|
|
48
|
+
type ToastsProviderProps = {
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { ToastsStoreSettings as a, ToastAction as c, ToastsStore as i, ToastActions as l, ToastsPoolRendererProps as n, NewToast as o, ToastsProviderProps as r, Toast as s, ToastsComponentsByInfoType as t, ToastInfoType as u };
|
|
53
|
+
//# sourceMappingURL=toasts-renderer-DsSfXdUq.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toasts-renderer-DsSfXdUq.d.cts","names":[],"sources":["../src/core/types/toast.ts","../src/core/types/toast-component.ts","../src/core/types/toasts-store.ts","../src/core/types/toasts-renderer.ts"],"mappings":";;;aAAY,aAAA;EACV,IAAA;EACA,KAAA;EACA,OAAA;AAAA;AAAA,KAGU,KAAA;EACV,EAAA;EACA,KAAA;EACA,WAAA;EACA,YAAA;EACA,QAAA,KAAa,aAAA;AAAA;AAAA,KAGH,QAAA,GAAW,IAAA,CAAK,KAAA;AAAA,KAEhB,WAAA,IAAe,KAAA,EAAO,KAAA;AAAA,KAEtB,YAAA;EACV,SAAA,GAAY,WAAA;EACZ,OAAA,GAAU,WAAA;AAAA;;;KClBA,mBAAA;EACV,KAAA,EAAO,KAAA;EACP,OAAA,EAAS,YAAA;AAAA;;;KCFC,WAAA;EACV,IAAA,EAAM,KAAA;EACN,SAAA;EAEA,KAAA,GAAQ,KAAA,EAAO,QAAA;EACf,MAAA,GAAS,KAAA,EAAO,KAAA;EAChB,GAAA;EAEA,WAAA,GAAc,UAAA;EACd,cAAA,GAAiB,UAAA;AAAA;AAAA,KAGP,mBAAA;EACV,SAAA;AAAA;;;KCRU,0BAAA,GAA6B,MAAA,CACvC,aAAA,EACA,WAAA,CAAY,mBAAA;AAAA,KASF,uBAAA;EACV,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA;AAAA,KAGN,mBAAA;EACV,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ElementType } from "react";
|
|
2
|
+
//#region src/core/types/toast.d.ts
|
|
3
|
+
declare enum ToastInfoType {
|
|
4
|
+
info = "info",
|
|
5
|
+
error = "error",
|
|
6
|
+
success = "success"
|
|
7
|
+
}
|
|
8
|
+
type Toast = {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
description: string;
|
|
12
|
+
durationInMs: number;
|
|
13
|
+
infoType: `${ToastInfoType}`;
|
|
14
|
+
};
|
|
15
|
+
type NewToast = Omit<Toast, "id">;
|
|
16
|
+
type ToastAction = (toast: Toast) => void;
|
|
17
|
+
type ToastActions = {
|
|
18
|
+
onDismiss?: ToastAction;
|
|
19
|
+
onPress?: ToastAction;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/core/types/toast-component.d.ts
|
|
23
|
+
type ToastComponentProps = {
|
|
24
|
+
toast: Toast;
|
|
25
|
+
actions: ToastActions;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/core/types/toasts-store.d.ts
|
|
29
|
+
type ToastsStore = {
|
|
30
|
+
pool: Toast[];
|
|
31
|
+
providers: string[];
|
|
32
|
+
stack: (toast: NewToast) => void;
|
|
33
|
+
remove: (toast: Toast["id"]) => void;
|
|
34
|
+
pop: () => void;
|
|
35
|
+
addProvider: (providerId: string) => void;
|
|
36
|
+
removeProvider: (providerId: string) => void;
|
|
37
|
+
};
|
|
38
|
+
type ToastsStoreSettings = {
|
|
39
|
+
poolLimit?: number;
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/core/types/toasts-renderer.d.ts
|
|
43
|
+
type ToastsComponentsByInfoType = Record<ToastInfoType, ElementType<ToastComponentProps>>;
|
|
44
|
+
type ToastsPoolRendererProps = {
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
};
|
|
47
|
+
type ToastsProviderProps = {
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ToastsStoreSettings as a, ToastAction as c, ToastsStore as i, ToastActions as l, ToastsPoolRendererProps as n, NewToast as o, ToastsProviderProps as r, Toast as s, ToastsComponentsByInfoType as t, ToastInfoType as u };
|
|
52
|
+
//# sourceMappingURL=toasts-renderer-vMIJr1FV.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toasts-renderer-vMIJr1FV.d.ts","names":[],"sources":["../src/core/types/toast.ts","../src/core/types/toast-component.ts","../src/core/types/toasts-store.ts","../src/core/types/toasts-renderer.ts"],"mappings":";;aAAY,aAAA;EACV,IAAA;EACA,KAAA;EACA,OAAA;AAAA;AAAA,KAGU,KAAA;EACV,EAAA;EACA,KAAA;EACA,WAAA;EACA,YAAA;EACA,QAAA,KAAa,aAAA;AAAA;AAAA,KAGH,QAAA,GAAW,IAAA,CAAK,KAAA;AAAA,KAEhB,WAAA,IAAe,KAAA,EAAO,KAAA;AAAA,KAEtB,YAAA;EACV,SAAA,GAAY,WAAA;EACZ,OAAA,GAAU,WAAA;AAAA;;;KClBA,mBAAA;EACV,KAAA,EAAO,KAAA;EACP,OAAA,EAAS,YAAA;AAAA;;;KCFC,WAAA;EACV,IAAA,EAAM,KAAA;EACN,SAAA;EAEA,KAAA,GAAQ,KAAA,EAAO,QAAA;EACf,MAAA,GAAS,KAAA,EAAO,KAAA;EAChB,GAAA;EAEA,WAAA,GAAc,UAAA;EACd,cAAA,GAAiB,UAAA;AAAA;AAAA,KAGP,mBAAA;EACV,SAAA;AAAA;;;KCRU,0BAAA,GAA6B,MAAA,CACvC,aAAA,EACA,WAAA,CAAY,mBAAA;AAAA,KASF,uBAAA;EACV,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA;AAAA,KAGN,mBAAA;EACV,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lapp-studio/react-toast-engine",
|
|
3
|
+
"version": "0.00.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/core.js",
|
|
7
|
+
"types": "dist/core.d.ts",
|
|
8
|
+
"module": "dist/core.mjs",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./core": {
|
|
11
|
+
"types": "./dist/core.d.ts",
|
|
12
|
+
"import": "./dist/core.mjs",
|
|
13
|
+
"require": "./dist/core.js"
|
|
14
|
+
},
|
|
15
|
+
"./native": {
|
|
16
|
+
"types": "./dist/native.d.ts",
|
|
17
|
+
"import": "./dist/native.mjs",
|
|
18
|
+
"require": "./dist/native.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "tsdown --watch",
|
|
26
|
+
"build": "tsdown",
|
|
27
|
+
"lint": "eslint .",
|
|
28
|
+
"lint:fix": "eslint --fix",
|
|
29
|
+
"type-check": "tsc --noEmit",
|
|
30
|
+
"prepublishOnly": "yarn build"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@eslint/js": "^10.0.1",
|
|
34
|
+
"@types/react": "^19.2.14",
|
|
35
|
+
"@types/react-dom": "^19.2.3",
|
|
36
|
+
"eslint": "^10.1.0",
|
|
37
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
38
|
+
"tsdown": "^0.21.4",
|
|
39
|
+
"typescript": "^6.0.2",
|
|
40
|
+
"typescript-eslint": "^8.57.2",
|
|
41
|
+
"zustand": "^5.0.0",
|
|
42
|
+
"react": "~19.0.0",
|
|
43
|
+
"react-native": "~0.83.0",
|
|
44
|
+
"react-native-gesture-handler": "~2.30.0",
|
|
45
|
+
"react-native-reanimated": "~4.2.1",
|
|
46
|
+
"react-native-safe-area-context": "~5.6.0",
|
|
47
|
+
"react-native-worklets": "~0.7.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"zustand": "^5.0.0",
|
|
51
|
+
"react": "~19.0.0",
|
|
52
|
+
"react-native": "~0.83.0",
|
|
53
|
+
"react-native-gesture-handler": "~2.30.0",
|
|
54
|
+
"react-native-reanimated": "~4.2.1",
|
|
55
|
+
"react-native-safe-area-context": "~5.6.0",
|
|
56
|
+
"react-native-worklets": "~0.7.2"
|
|
57
|
+
},
|
|
58
|
+
"maintainers": [
|
|
59
|
+
"giovanninp"
|
|
60
|
+
],
|
|
61
|
+
"license": "MIT"
|
|
62
|
+
}
|