@hanzogui/toast 2.0.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/dist/cjs/Toast.cjs +170 -0
- package/dist/cjs/Toast.native.js +174 -0
- package/dist/cjs/Toast.native.js.map +1 -0
- package/dist/cjs/ToastAnnounce.cjs +97 -0
- package/dist/cjs/ToastAnnounce.native.js +105 -0
- package/dist/cjs/ToastAnnounce.native.js.map +1 -0
- package/dist/cjs/ToastImperative.cjs +100 -0
- package/dist/cjs/ToastImperative.native.js +122 -0
- package/dist/cjs/ToastImperative.native.js.map +1 -0
- package/dist/cjs/ToastImpl.cjs +292 -0
- package/dist/cjs/ToastImpl.native.js +326 -0
- package/dist/cjs/ToastImpl.native.js.map +1 -0
- package/dist/cjs/ToastPortal.cjs +44 -0
- package/dist/cjs/ToastPortal.native.js +47 -0
- package/dist/cjs/ToastPortal.native.js.map +1 -0
- package/dist/cjs/ToastProvider.cjs +146 -0
- package/dist/cjs/ToastProvider.native.js +159 -0
- package/dist/cjs/ToastProvider.native.js.map +1 -0
- package/dist/cjs/ToastViewport.cjs +278 -0
- package/dist/cjs/ToastViewport.native.js +315 -0
- package/dist/cjs/ToastViewport.native.js.map +1 -0
- package/dist/cjs/constants.cjs +28 -0
- package/dist/cjs/constants.native.js +31 -0
- package/dist/cjs/constants.native.js.map +1 -0
- package/dist/cjs/createNativeToast.cjs +51 -0
- package/dist/cjs/createNativeToast.native.js +48 -0
- package/dist/cjs/createNativeToast.native.js.map +1 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.native.js +21 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.native.js +19 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/esm/Toast.mjs +131 -0
- package/dist/esm/Toast.mjs.map +1 -0
- package/dist/esm/Toast.native.js +132 -0
- package/dist/esm/Toast.native.js.map +1 -0
- package/dist/esm/ToastAnnounce.mjs +62 -0
- package/dist/esm/ToastAnnounce.mjs.map +1 -0
- package/dist/esm/ToastAnnounce.native.js +67 -0
- package/dist/esm/ToastAnnounce.native.js.map +1 -0
- package/dist/esm/ToastImperative.mjs +63 -0
- package/dist/esm/ToastImperative.mjs.map +1 -0
- package/dist/esm/ToastImperative.native.js +82 -0
- package/dist/esm/ToastImperative.native.js.map +1 -0
- package/dist/esm/ToastImpl.mjs +256 -0
- package/dist/esm/ToastImpl.mjs.map +1 -0
- package/dist/esm/ToastImpl.native.js +287 -0
- package/dist/esm/ToastImpl.native.js.map +1 -0
- package/dist/esm/ToastPortal.mjs +21 -0
- package/dist/esm/ToastPortal.mjs.map +1 -0
- package/dist/esm/ToastPortal.native.js +21 -0
- package/dist/esm/ToastPortal.native.js.map +1 -0
- package/dist/esm/ToastProvider.mjs +108 -0
- package/dist/esm/ToastProvider.mjs.map +1 -0
- package/dist/esm/ToastProvider.native.js +118 -0
- package/dist/esm/ToastProvider.native.js.map +1 -0
- package/dist/esm/ToastViewport.mjs +241 -0
- package/dist/esm/ToastViewport.mjs.map +1 -0
- package/dist/esm/ToastViewport.native.js +275 -0
- package/dist/esm/ToastViewport.native.js.map +1 -0
- package/dist/esm/constants.mjs +4 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/constants.native.js +4 -0
- package/dist/esm/constants.native.js.map +1 -0
- package/dist/esm/createNativeToast.mjs +27 -0
- package/dist/esm/createNativeToast.mjs.map +1 -0
- package/dist/esm/createNativeToast.native.js +21 -0
- package/dist/esm/createNativeToast.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/dist/jsx/Toast.mjs +131 -0
- package/dist/jsx/Toast.mjs.map +1 -0
- package/dist/jsx/Toast.native.js +174 -0
- package/dist/jsx/Toast.native.js.map +1 -0
- package/dist/jsx/ToastAnnounce.mjs +62 -0
- package/dist/jsx/ToastAnnounce.mjs.map +1 -0
- package/dist/jsx/ToastAnnounce.native.js +105 -0
- package/dist/jsx/ToastAnnounce.native.js.map +1 -0
- package/dist/jsx/ToastImperative.mjs +63 -0
- package/dist/jsx/ToastImperative.mjs.map +1 -0
- package/dist/jsx/ToastImperative.native.js +122 -0
- package/dist/jsx/ToastImperative.native.js.map +1 -0
- package/dist/jsx/ToastImpl.mjs +256 -0
- package/dist/jsx/ToastImpl.mjs.map +1 -0
- package/dist/jsx/ToastImpl.native.js +326 -0
- package/dist/jsx/ToastImpl.native.js.map +1 -0
- package/dist/jsx/ToastPortal.mjs +21 -0
- package/dist/jsx/ToastPortal.mjs.map +1 -0
- package/dist/jsx/ToastPortal.native.js +47 -0
- package/dist/jsx/ToastPortal.native.js.map +1 -0
- package/dist/jsx/ToastProvider.mjs +108 -0
- package/dist/jsx/ToastProvider.mjs.map +1 -0
- package/dist/jsx/ToastProvider.native.js +159 -0
- package/dist/jsx/ToastProvider.native.js.map +1 -0
- package/dist/jsx/ToastViewport.mjs +241 -0
- package/dist/jsx/ToastViewport.mjs.map +1 -0
- package/dist/jsx/ToastViewport.native.js +315 -0
- package/dist/jsx/ToastViewport.native.js.map +1 -0
- package/dist/jsx/constants.mjs +4 -0
- package/dist/jsx/constants.mjs.map +1 -0
- package/dist/jsx/constants.native.js +31 -0
- package/dist/jsx/constants.native.js.map +1 -0
- package/dist/jsx/createNativeToast.mjs +27 -0
- package/dist/jsx/createNativeToast.mjs.map +1 -0
- package/dist/jsx/createNativeToast.native.js +48 -0
- package/dist/jsx/createNativeToast.native.js.map +1 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +21 -0
- package/dist/jsx/index.native.js.map +1 -0
- package/dist/jsx/types.mjs +2 -0
- package/dist/jsx/types.mjs.map +1 -0
- package/dist/jsx/types.native.js +19 -0
- package/dist/jsx/types.native.js.map +1 -0
- package/package.json +66 -0
- package/src/Toast.tsx +219 -0
- package/src/ToastAnnounce.tsx +103 -0
- package/src/ToastImperative.tsx +192 -0
- package/src/ToastImpl.tsx +502 -0
- package/src/ToastPortal.tsx +19 -0
- package/src/ToastProvider.tsx +197 -0
- package/src/ToastViewport.tsx +429 -0
- package/src/constants.ts +2 -0
- package/src/createNativeToast.native.tsx +29 -0
- package/src/createNativeToast.tsx +48 -0
- package/src/index.ts +3 -0
- package/src/types.ts +71 -0
- package/types/Toast.d.ts +84 -0
- package/types/ToastAnnounce.d.ts +18 -0
- package/types/ToastImperative.d.ts +95 -0
- package/types/ToastImpl.d.ts +109 -0
- package/types/ToastPortal.d.ts +8 -0
- package/types/ToastProvider.d.ts +92 -0
- package/types/ToastViewport.d.ts +75 -0
- package/types/constants.d.ts +3 -0
- package/types/createNativeToast.d.ts +4 -0
- package/types/createNativeToast.native.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/types.d.ts +61 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
33
|
+
}), mod);
|
|
34
|
+
var ToastProvider_exports = {};
|
|
35
|
+
__export(ToastProvider_exports, {
|
|
36
|
+
Collection: () => Collection,
|
|
37
|
+
ReprogapateToastProvider: () => ReprogapateToastProvider,
|
|
38
|
+
ToastProvider: () => ToastProvider,
|
|
39
|
+
useCollection: () => useCollection,
|
|
40
|
+
useToastProviderContext: () => useToastProviderContext
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(ToastProvider_exports);
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime"),
|
|
44
|
+
import_gui_collection = require("@hanzo/gui-collection"),
|
|
45
|
+
import_gui_core = require("@hanzo/gui-core"),
|
|
46
|
+
import_gui_start_transition = require("@hanzo/gui-start-transition"),
|
|
47
|
+
React = __toESM(require("react"), 1),
|
|
48
|
+
import_constants = require("./constants.native.js"),
|
|
49
|
+
import_ToastImperative = require("./ToastImperative.native.js"),
|
|
50
|
+
PROVIDER_NAME = "ToastProvider",
|
|
51
|
+
[Collection, useCollection] = (0, import_gui_collection.createCollection)("Toast"),
|
|
52
|
+
{
|
|
53
|
+
Provider: ToastProviderProvider,
|
|
54
|
+
useStyledContext: useToastProviderContext
|
|
55
|
+
} = (0, import_gui_core.createStyledContext)(
|
|
56
|
+
// since we always provide this we can avoid setting here
|
|
57
|
+
{}, "Toast__"),
|
|
58
|
+
ToastProvider = function (props) {
|
|
59
|
+
var {
|
|
60
|
+
scope = import_constants.TOAST_CONTEXT,
|
|
61
|
+
id: providedId,
|
|
62
|
+
burntOptions,
|
|
63
|
+
native,
|
|
64
|
+
notificationOptions,
|
|
65
|
+
label = "Notification",
|
|
66
|
+
duration = 5e3,
|
|
67
|
+
swipeDirection = "right",
|
|
68
|
+
swipeThreshold = 50,
|
|
69
|
+
children
|
|
70
|
+
} = props,
|
|
71
|
+
backupId = React.useId(),
|
|
72
|
+
id = providedId ?? backupId,
|
|
73
|
+
[viewports, setViewports] = React.useState({}),
|
|
74
|
+
[toastCount, setToastCount] = React.useState(0),
|
|
75
|
+
isFocusedToastEscapeKeyDownRef = React.useRef(!1),
|
|
76
|
+
isClosePausedRef = React.useRef(!1),
|
|
77
|
+
handleViewportChange = React.useCallback(function (name, viewport) {
|
|
78
|
+
(0, import_gui_start_transition.startTransition)(function () {
|
|
79
|
+
setViewports(function (prev) {
|
|
80
|
+
return {
|
|
81
|
+
...prev,
|
|
82
|
+
[name]: viewport
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}, []),
|
|
87
|
+
options = React.useMemo(function () {
|
|
88
|
+
return {
|
|
89
|
+
duration,
|
|
90
|
+
burntOptions,
|
|
91
|
+
native,
|
|
92
|
+
notificationOptions
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
// nested simple object so JSON.stringify
|
|
96
|
+
[JSON.stringify([duration, burntOptions, native, notificationOptions])]);
|
|
97
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
|
|
98
|
+
scope,
|
|
99
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastProviderProvider, {
|
|
100
|
+
scope,
|
|
101
|
+
id,
|
|
102
|
+
label,
|
|
103
|
+
duration,
|
|
104
|
+
swipeDirection,
|
|
105
|
+
swipeThreshold,
|
|
106
|
+
toastCount,
|
|
107
|
+
viewports,
|
|
108
|
+
onViewportChange: handleViewportChange,
|
|
109
|
+
onToastAdd: React.useCallback(function () {
|
|
110
|
+
(0, import_gui_start_transition.startTransition)(function () {
|
|
111
|
+
setToastCount(function (prevCount) {
|
|
112
|
+
return prevCount + 1;
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}, []),
|
|
116
|
+
onToastRemove: React.useCallback(function () {
|
|
117
|
+
(0, import_gui_start_transition.startTransition)(function () {
|
|
118
|
+
setToastCount(function (prevCount) {
|
|
119
|
+
return prevCount - 1;
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}, []),
|
|
123
|
+
isFocusedToastEscapeKeyDownRef,
|
|
124
|
+
isClosePausedRef,
|
|
125
|
+
options,
|
|
126
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastImperative.ToastImperativeProvider, {
|
|
127
|
+
options,
|
|
128
|
+
children
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
function ReprogapateToastProvider(props) {
|
|
134
|
+
var {
|
|
135
|
+
children,
|
|
136
|
+
context
|
|
137
|
+
} = props;
|
|
138
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
|
|
139
|
+
scope: context.toastScope,
|
|
140
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastProviderProvider, {
|
|
141
|
+
...context,
|
|
142
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastImperative.ToastImperativeProvider, {
|
|
143
|
+
options: context.options,
|
|
144
|
+
children
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
ToastProvider.propTypes = {
|
|
150
|
+
label(props) {
|
|
151
|
+
if (props.label && typeof props.label == "string" && !props.label.trim()) {
|
|
152
|
+
var error = `Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
|
|
153
|
+
return new Error(error);
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
ToastProvider.displayName = PROVIDER_NAME;
|
|
159
|
+
//# sourceMappingURL=ToastProvider.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","ToastProvider_exports","__export","Collection","ReprogapateToastProvider","ToastProvider","useCollection","useToastProviderContext","module","exports","import_jsx_runtime","require","import_gui_collection","import_gui_core","import_gui_start_transition","React","__toESM","import_constants","import_ToastImperative","PROVIDER_NAME","createCollection","Provider","ToastProviderProvider","useStyledContext","createStyledContext","props","scope","TOAST_CONTEXT","id","providedId","burntOptions","native","notificationOptions","label","duration","swipeDirection","swipeThreshold","children","backupId","useId","viewports","setViewports","useState","toastCount","setToastCount","isFocusedToastEscapeKeyDownRef","useRef","isClosePausedRef","handleViewportChange","useCallback","name","viewport","startTransition","prev","options","useMemo","JSON","stringify","jsx","onViewportChange","onToastAdd","prevCount","onToastRemove","ToastImperativeProvider","context"],"sources":["../../src/ToastProvider.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,qBAAA;AAAAC,QAAA,CAAAD,qBAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAA,UAAA;EAAAC,wBAAA,EAAAA,CAAA,KAAAA,wBAAA;EAAAC,aAAA,EAAAA,CAAA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
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var ToastViewport_exports = {};
|
|
33
|
+
__export(ToastViewport_exports, {
|
|
34
|
+
ToastViewport: () => ToastViewport,
|
|
35
|
+
VIEWPORT_DEFAULT_HOTKEY: () => VIEWPORT_DEFAULT_HOTKEY,
|
|
36
|
+
VIEWPORT_PAUSE: () => VIEWPORT_PAUSE,
|
|
37
|
+
VIEWPORT_RESUME: () => VIEWPORT_RESUME
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(ToastViewport_exports);
|
|
40
|
+
var import_gui_animate_presence = require("@hanzo/gui-animate-presence"),
|
|
41
|
+
import_gui_compose_refs = require("@hanzo/gui-compose-refs"),
|
|
42
|
+
import_gui_constants = require("@hanzo/gui-constants"),
|
|
43
|
+
import_gui_core = require("@hanzo/gui-core"),
|
|
44
|
+
import_gui_portal = require("@hanzo/gui-portal"),
|
|
45
|
+
import_gui_stacks = require("@hanzo/gui-stacks"),
|
|
46
|
+
import_gui_visually_hidden = require("@hanzo/gui-visually-hidden"),
|
|
47
|
+
React = __toESM(require("react"), 1),
|
|
48
|
+
import_constants = require("./constants.cjs"),
|
|
49
|
+
import_ToastPortal = require("./ToastPortal.cjs"),
|
|
50
|
+
import_ToastProvider = require("./ToastProvider.cjs"),
|
|
51
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
52
|
+
const VIEWPORT_NAME = "ToastViewport",
|
|
53
|
+
VIEWPORT_DEFAULT_HOTKEY = ["F8"],
|
|
54
|
+
VIEWPORT_PAUSE = "toast.viewportPause",
|
|
55
|
+
VIEWPORT_RESUME = "toast.viewportResume",
|
|
56
|
+
ToastViewportWrapperFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
57
|
+
name: "ViewportWrapper",
|
|
58
|
+
variants: {
|
|
59
|
+
unstyled: {
|
|
60
|
+
false: {
|
|
61
|
+
pointerEvents: "box-none",
|
|
62
|
+
top: 0,
|
|
63
|
+
bottom: 0,
|
|
64
|
+
left: 0,
|
|
65
|
+
right: 0,
|
|
66
|
+
position: "fixed",
|
|
67
|
+
maxWidth: "100%",
|
|
68
|
+
tabIndex: 0,
|
|
69
|
+
zIndex: 1e5
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
defaultVariants: {
|
|
74
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
ToastViewportFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
78
|
+
name: VIEWPORT_NAME,
|
|
79
|
+
variants: {
|
|
80
|
+
unstyled: {
|
|
81
|
+
false: {
|
|
82
|
+
pointerEvents: "box-none",
|
|
83
|
+
position: "fixed",
|
|
84
|
+
maxWidth: "100%"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
defaultVariants: {
|
|
89
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
ToastViewport = React.memo(React.forwardRef((props, forwardedRef) => {
|
|
93
|
+
const {
|
|
94
|
+
scope,
|
|
95
|
+
hotkey = VIEWPORT_DEFAULT_HOTKEY,
|
|
96
|
+
label = "Notifications ({hotkey})",
|
|
97
|
+
name = "default",
|
|
98
|
+
multipleToasts,
|
|
99
|
+
zIndex,
|
|
100
|
+
portalToRoot,
|
|
101
|
+
...viewportProps
|
|
102
|
+
} = props,
|
|
103
|
+
context = (0, import_ToastProvider.useToastProviderContext)(scope),
|
|
104
|
+
getItems = (0, import_ToastProvider.useCollection)(scope || import_constants.TOAST_CONTEXT),
|
|
105
|
+
headFocusProxyRef = React.useRef(null),
|
|
106
|
+
tailFocusProxyRef = React.useRef(null),
|
|
107
|
+
wrapperRef = React.useRef(null),
|
|
108
|
+
ref = React.useRef(null),
|
|
109
|
+
onViewportChange = React.useCallback(el => {
|
|
110
|
+
context.viewports[name] !== el && context.onViewportChange(name, el);
|
|
111
|
+
}, [name, context.viewports]),
|
|
112
|
+
composedRefs = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, ref, onViewportChange),
|
|
113
|
+
hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, ""),
|
|
114
|
+
hasToasts = context.toastCount > 0;
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (!import_gui_constants.isWeb || context.toastCount === 0) return;
|
|
117
|
+
const handleKeyDown = event => {
|
|
118
|
+
hotkey.every(key => event[key] || event.code === key) && ref.current?.focus();
|
|
119
|
+
};
|
|
120
|
+
return document.addEventListener("keydown", handleKeyDown), () => {
|
|
121
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
122
|
+
};
|
|
123
|
+
}, [hotkey, context.toastCount]), React.useEffect(() => {
|
|
124
|
+
if (!import_gui_constants.isWeb || context.toastCount === 0) return;
|
|
125
|
+
const wrapper = wrapperRef.current,
|
|
126
|
+
viewport = ref.current;
|
|
127
|
+
if (hasToasts && wrapper && viewport) {
|
|
128
|
+
const handlePause = () => {
|
|
129
|
+
if (!context.isClosePausedRef.current) {
|
|
130
|
+
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
|
|
131
|
+
viewport.dispatchEvent(pauseEvent), context.isClosePausedRef.current = !0;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
handleResume = () => {
|
|
135
|
+
if (context.isClosePausedRef.current) {
|
|
136
|
+
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
|
|
137
|
+
viewport.dispatchEvent(resumeEvent), context.isClosePausedRef.current = !1;
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
handleFocusOutResume = event => {
|
|
141
|
+
!wrapper.contains(event.relatedTarget) && handleResume();
|
|
142
|
+
},
|
|
143
|
+
handlePointerLeaveResume = () => {
|
|
144
|
+
wrapper.contains(document.activeElement) || handleResume();
|
|
145
|
+
};
|
|
146
|
+
return wrapper.addEventListener("focusin", handlePause), wrapper.addEventListener("focusout", handleFocusOutResume), wrapper.addEventListener("pointermove", handlePause), wrapper.addEventListener("pointerleave", handlePointerLeaveResume), window.addEventListener("blur", handlePause), window.addEventListener("focus", handleResume), () => {
|
|
147
|
+
wrapper.removeEventListener("focusin", handlePause), wrapper.removeEventListener("focusout", handleFocusOutResume), wrapper.removeEventListener("pointermove", handlePause), wrapper.removeEventListener("pointerleave", handlePointerLeaveResume), window.removeEventListener("blur", handlePause), window.removeEventListener("focus", handleResume);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}, [hasToasts, context.isClosePausedRef, context.toastCount]);
|
|
151
|
+
const getSortedTabbableCandidates = React.useCallback(({
|
|
152
|
+
tabbingDirection
|
|
153
|
+
}) => {
|
|
154
|
+
const tabbableCandidates = getItems().map(toastItem => {
|
|
155
|
+
const toastNode = toastItem.ref.current,
|
|
156
|
+
toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)];
|
|
157
|
+
return tabbingDirection === "forwards" ? toastTabbableCandidates : toastTabbableCandidates.reverse();
|
|
158
|
+
});
|
|
159
|
+
return (tabbingDirection === "forwards" ? tabbableCandidates.reverse() : tabbableCandidates).flat();
|
|
160
|
+
}, [getItems]);
|
|
161
|
+
React.useEffect(() => {
|
|
162
|
+
if (!import_gui_constants.isWeb || context.toastCount === 0) return;
|
|
163
|
+
const viewport = ref.current;
|
|
164
|
+
if (viewport) {
|
|
165
|
+
const handleKeyDown = event => {
|
|
166
|
+
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
167
|
+
if (event.key === "Tab" && !isMetaKey) {
|
|
168
|
+
const focusedElement = document.activeElement,
|
|
169
|
+
isTabbingBackwards = event.shiftKey;
|
|
170
|
+
if (event.target === viewport && isTabbingBackwards) {
|
|
171
|
+
headFocusProxyRef.current?.focus();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const sortedCandidates = getSortedTabbableCandidates({
|
|
175
|
+
tabbingDirection: isTabbingBackwards ? "backwards" : "forwards"
|
|
176
|
+
}),
|
|
177
|
+
index = sortedCandidates.findIndex(candidate => candidate === focusedElement);
|
|
178
|
+
focusFirst(sortedCandidates.slice(index + 1)) ? event.preventDefault() : isTabbingBackwards ?
|
|
179
|
+
// @ts-ignore ali TODO type
|
|
180
|
+
headFocusProxyRef.current?.focus() :
|
|
181
|
+
// @ts-ignore ali TODO type
|
|
182
|
+
tailFocusProxyRef.current?.focus();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return viewport.addEventListener("keydown", handleKeyDown), () => viewport.removeEventListener("keydown", handleKeyDown);
|
|
186
|
+
}
|
|
187
|
+
}, [getItems, getSortedTabbableCandidates, context.toastCount]);
|
|
188
|
+
const contents = /* @__PURE__ */(0, import_jsx_runtime.jsxs)(ToastViewportWrapperFrame, {
|
|
189
|
+
ref: wrapperRef,
|
|
190
|
+
role: "region",
|
|
191
|
+
"aria-label": label.replace("{hotkey}", hotkeyLabel),
|
|
192
|
+
tabIndex: -1,
|
|
193
|
+
children: [hasToasts && /* @__PURE__ */(0, import_jsx_runtime.jsx)(FocusProxy, {
|
|
194
|
+
context,
|
|
195
|
+
viewportName: name,
|
|
196
|
+
ref: headFocusProxyRef,
|
|
197
|
+
onFocusFromOutsideViewport: () => {
|
|
198
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
199
|
+
tabbingDirection: "forwards"
|
|
200
|
+
});
|
|
201
|
+
focusFirst(tabbableCandidates);
|
|
202
|
+
}
|
|
203
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.Slot, {
|
|
204
|
+
scope: context.toastScope,
|
|
205
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastViewportFrame, {
|
|
206
|
+
focusable: context.toastCount > 0,
|
|
207
|
+
ref: composedRefs,
|
|
208
|
+
...viewportProps,
|
|
209
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_portal.PortalHost, {
|
|
210
|
+
render: children => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_animate_presence.AnimatePresence, {
|
|
211
|
+
exitBeforeEnter: !multipleToasts,
|
|
212
|
+
children
|
|
213
|
+
}),
|
|
214
|
+
name: name ?? "default"
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
}), hasToasts && /* @__PURE__ */(0, import_jsx_runtime.jsx)(FocusProxy, {
|
|
218
|
+
context,
|
|
219
|
+
viewportName: name,
|
|
220
|
+
ref: tailFocusProxyRef,
|
|
221
|
+
onFocusFromOutsideViewport: () => {
|
|
222
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
223
|
+
tabbingDirection: "backwards"
|
|
224
|
+
});
|
|
225
|
+
focusFirst(tabbableCandidates);
|
|
226
|
+
}
|
|
227
|
+
})]
|
|
228
|
+
});
|
|
229
|
+
return portalToRoot ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastPortal.ToastPortal, {
|
|
230
|
+
context,
|
|
231
|
+
...(typeof zIndex == "number" ? {
|
|
232
|
+
zIndex
|
|
233
|
+
} : {}),
|
|
234
|
+
children: contents
|
|
235
|
+
}) : contents;
|
|
236
|
+
}));
|
|
237
|
+
ToastViewport.displayName = VIEWPORT_NAME;
|
|
238
|
+
const FOCUS_PROXY_NAME = "ToastFocusProxy",
|
|
239
|
+
FocusProxy = React.forwardRef((props, forwardedRef) => {
|
|
240
|
+
const {
|
|
241
|
+
onFocusFromOutsideViewport,
|
|
242
|
+
viewportName,
|
|
243
|
+
context,
|
|
244
|
+
...proxyProps
|
|
245
|
+
} = props,
|
|
246
|
+
viewport = context.viewports[viewportName];
|
|
247
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_visually_hidden.VisuallyHidden, {
|
|
248
|
+
"aria-hidden": !0,
|
|
249
|
+
tabIndex: 0,
|
|
250
|
+
...proxyProps,
|
|
251
|
+
ref: forwardedRef,
|
|
252
|
+
position: "fixed",
|
|
253
|
+
onFocus: event => {
|
|
254
|
+
if (!import_gui_constants.isWeb) return;
|
|
255
|
+
const prevFocusedElement = event.relatedTarget;
|
|
256
|
+
!viewport?.contains(prevFocusedElement) && onFocusFromOutsideViewport();
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
FocusProxy.displayName = FOCUS_PROXY_NAME;
|
|
261
|
+
function focusFirst(candidates) {
|
|
262
|
+
if (!import_gui_constants.isWeb) return;
|
|
263
|
+
const previouslyFocusedElement = document.activeElement;
|
|
264
|
+
return candidates.some(candidate => candidate === previouslyFocusedElement ? !0 : (candidate.focus(), document.activeElement !== previouslyFocusedElement));
|
|
265
|
+
}
|
|
266
|
+
function getTabbableCandidates(container) {
|
|
267
|
+
if (!import_gui_constants.isWeb) return [];
|
|
268
|
+
const containerHtml = container,
|
|
269
|
+
nodes = [],
|
|
270
|
+
walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {
|
|
271
|
+
acceptNode: node => {
|
|
272
|
+
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
273
|
+
return node.disabled || node.hidden || isHiddenInput ? NodeFilter.FILTER_SKIP : node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
for (; walker.nextNode();) nodes.push(walker.currentNode);
|
|
277
|
+
return nodes;
|
|
278
|
+
}
|