@onekeyfe/react-native-native-overlay 6.8.0-4 → 6.8.0-6
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/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +871 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
- package/docs/SPEC.md +120 -9
- package/ios/NativeOverlayToastCardView.swift +572 -0
- package/ios/NativeOverlayToastSpec.swift +356 -0
- package/ios/NativeOverlayToasterView.swift +519 -0
- package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
- package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
- package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/toast/OverlayToastHost.js +42 -0
- package/lib/module/toast/OverlayToastHost.js.map +1 -0
- package/lib/module/toast/OverlayToastHost.web.js +32 -0
- package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
- package/lib/module/toast/OverlayToastStore.js +217 -0
- package/lib/module/toast/OverlayToastStore.js.map +1 -0
- package/lib/module/toast/toastBridge.js +65 -0
- package/lib/module/toast/toastBridge.js.map +1 -0
- package/lib/module/toast/toastDomContent.web.js +298 -0
- package/lib/module/toast/toastDomContent.web.js.map +1 -0
- package/lib/module/toast/toastDomRenderer.web.js +629 -0
- package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
- package/lib/module/toast/toastStyles.web.js +97 -0
- package/lib/module/toast/toastStyles.web.js.map +1 -0
- package/lib/module/toast/types.js +2 -0
- package/lib/module/toast/types.js.map +1 -0
- package/lib/module/web/overlayLayers.js +5 -0
- package/lib/module/web/overlayLayers.js.map +1 -1
- package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
- package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
- package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
- package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
- package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
- package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
- package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
- package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
- package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
- package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/types.d.ts +240 -0
- package/lib/typescript/src/toast/types.d.ts.map +1 -0
- package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
- package/package.json +3 -2
- package/react-native.config.js +1 -0
- package/src/NativeOverlayToasterNativeComponent.ts +24 -0
- package/src/index.ts +23 -0
- package/src/toast/OverlayToastHost.tsx +62 -0
- package/src/toast/OverlayToastHost.web.tsx +29 -0
- package/src/toast/OverlayToastStore.ts +254 -0
- package/src/toast/toastBridge.ts +62 -0
- package/src/toast/toastDomContent.web.ts +351 -0
- package/src/toast/toastDomRenderer.web.ts +748 -0
- package/src/toast/toastStyles.web.ts +97 -0
- package/src/toast/types.ts +251 -0
- package/src/web/overlayLayers.ts +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SVG_NS","MESSAGE_ICON_GAP","MESSAGE_TEXT_GAP","NOTIFICATION_GAP","NOTIFICATION_TEXT_GAP","ACTIONS_PADDING_TOP","ACTIONS_PADDING_END","ACTIONS_PADDING_BOTTOM","element","tag","marker","node","document","createElement","setAttribute","createIcon","icon","kind","image","src","uri","alt","draggable","width","size","height","style","borderRadius","svg","createElementNS","String","color","track","arc","forEach","circle","stroke","opacity","strokeDasharray","strokeDashoffset","append","href","use","applyRunStyle","run","fontWeight","fontSize","undefined","underline","textDecorationLine","isPlainRun","link","createParagraph","text","runs","emit","paragraph","lineHeight","fontFamily","letterSpacing","selectable","tabularNumbers","fontVariantNumeric","linkHoverColor","setProperty","linkPressedColor","numberOfLines","createTextNode","span","textContent","tabIndex","open","event","stopPropagation","type","addEventListener","key","createParagraphs","container","paragraphs","createAction","action","button","testID","marginRight","iconGap","label","disabled","backgroundColor","hoverBackgroundColor","pressedBackgroundColor","focusRingColor","padding","paddingVertical","paddingHorizontal","borderWidth","marginHorizontal","marginVertical","margin","disabledOpacity","actionId","id","createActions","actions","align","row","justifyContent","buildToastContent","spec","layout","flex","gap","pressable","target","closest","preventDefault","badge","badgeSize","badgeColor","column","title","message","length","actionsAlign","root","box"],"sourceRoot":"../../../src","sources":["toast/toastDomContent.web.ts"],"mappings":";;AAAA;;AASA,MAAMA,MAAM,GAAG,4BAA4B;;AAE3C;AACA,MAAMC,gBAAgB,GAAG,CAAC;AAC1B,MAAMC,gBAAgB,GAAG,CAAC;AAC1B,MAAMC,gBAAgB,GAAG,CAAC;AAC1B,MAAMC,qBAAqB,GAAG,CAAC;AAC/B,MAAMC,mBAAmB,GAAG,EAAE;AAC9B,MAAMC,mBAAmB,GAAG,CAAC;AAC7B,MAAMC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,GAAG7G,gBAAgB,IAAI;EAC1C,IAAI0G,IAAI,CAACY,KAAK,EAAE;IACdD,MAAM,CAAC/E,MAAM,CAACqC,gBAAgB,CAAC+B,IAAI,CAACY,KAAK,EAAEjE,IAAI,CAAC,CAAC;EACnD;EACA,IAAIqD,IAAI,CAACa,OAAO,EAAE;IAChBF,MAAM,CAAC/E,MAAM,CAACqC,gBAAgB,CAAC+B,IAAI,CAACa,OAAO,EAAElE,IAAI,CAAC,CAAC;EACrD;EACA,IAAIqD,IAAI,CAACL,OAAO,EAAEmB,MAAM,EAAE;IACxBH,MAAM,CAAC/E,MAAM,CACX8D,aAAa,CACXM,IAAI,CAACL,OAAO,EACZK,IAAI,CAACe,YAAY,IAAI,OAAO,EAC5B,GAAGtH,mBAAmB,MAAMC,mBAAmB,MAAMC,sBAAsB,MAAM,EACjFgD,IACF,CACF,CAAC;EACH;EACAkD,GAAG,CAACjE,MAAM,CAAC+E,MAAM,CAAC;EAClBK,IAAI,CAACpF,MAAM,CAACiE,GAAG,CAAC;EAChB,OAAOmB,IAAI;AACb","ignoreList":[]}
|
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* cspell:ignore dasharray dashoffset */
|
|
4
|
+
import { getOverlayLayerRoot, syncOverlayInert } from "../web/overlayLayers.js";
|
|
5
|
+
import { buildToastContent } from "./toastDomContent.web.js";
|
|
6
|
+
import { ensureOverlayToastStyles } from "./toastStyles.web.js";
|
|
7
|
+
// The chrome constants of the renderer this replaces (sonner 1.4.41).
|
|
8
|
+
const VISIBLE_TOASTS = 3;
|
|
9
|
+
const VIEWPORT_OFFSET = 32;
|
|
10
|
+
const TOAST_WIDTH = 356;
|
|
11
|
+
const GAP = 14;
|
|
12
|
+
const SWIPE_THRESHOLD = 20;
|
|
13
|
+
const SWIPE_VELOCITY = 0.11; // px per ms
|
|
14
|
+
// Equal to the exit transition.
|
|
15
|
+
const TIME_BEFORE_UNMOUNT = 200;
|
|
16
|
+
const DEFAULT_POSITION = 'bottom-right';
|
|
17
|
+
const DEFAULT_OBSTRUCTION_GAP = 8;
|
|
18
|
+
const DEFAULT_OBSTRUCTION_ROOM = 88;
|
|
19
|
+
const OBSTRUCTION_SHIFT_MS = 220;
|
|
20
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
21
|
+
function getDocumentDirection() {
|
|
22
|
+
const attribute = document.documentElement.getAttribute('dir');
|
|
23
|
+
if (attribute === 'rtl' || attribute === 'ltr') {
|
|
24
|
+
return attribute;
|
|
25
|
+
}
|
|
26
|
+
return globalThis.getComputedStyle(document.documentElement).direction === 'rtl' ? 'rtl' : 'ltr';
|
|
27
|
+
}
|
|
28
|
+
function createCloseButton(label) {
|
|
29
|
+
const button = document.createElement('button');
|
|
30
|
+
button.type = 'button';
|
|
31
|
+
button.setAttribute('aria-label', label);
|
|
32
|
+
button.setAttribute('data-close-button', '');
|
|
33
|
+
const svg = document.createElementNS(SVG_NS, 'svg');
|
|
34
|
+
const attributes = {
|
|
35
|
+
'width': '12',
|
|
36
|
+
'height': '12',
|
|
37
|
+
'viewBox': '0 0 24 24',
|
|
38
|
+
'fill': 'none',
|
|
39
|
+
'stroke': 'currentColor',
|
|
40
|
+
'stroke-width': '1.5',
|
|
41
|
+
'stroke-linecap': 'round',
|
|
42
|
+
'stroke-linejoin': 'round'
|
|
43
|
+
};
|
|
44
|
+
Object.entries(attributes).forEach(([name, value]) => svg.setAttribute(name, value));
|
|
45
|
+
[['18', '6', '6', '18'], ['6', '6', '18', '18']].forEach(([x1, y1, x2, y2]) => {
|
|
46
|
+
const line = document.createElementNS(SVG_NS, 'line');
|
|
47
|
+
line.setAttribute('x1', x1 ?? '');
|
|
48
|
+
line.setAttribute('y1', y1 ?? '');
|
|
49
|
+
line.setAttribute('x2', x2 ?? '');
|
|
50
|
+
line.setAttribute('y2', y2 ?? '');
|
|
51
|
+
svg.append(line);
|
|
52
|
+
});
|
|
53
|
+
button.append(svg);
|
|
54
|
+
return button;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Draws message toasts with plain DOM in the `toast` overlay layer. No React:
|
|
59
|
+
* the cards, their stacking, timers, swipe and transitions live here, and the
|
|
60
|
+
* stylesheet reproduces the previous renderer's chrome rule for rule.
|
|
61
|
+
*/
|
|
62
|
+
export function createToastDomRenderer(report) {
|
|
63
|
+
ensureOverlayToastStyles();
|
|
64
|
+
|
|
65
|
+
// Events raised while a sync is applying wait for it to finish: the store
|
|
66
|
+
// answers an event by syncing again.
|
|
67
|
+
let syncing = false;
|
|
68
|
+
const pendingEvents = [];
|
|
69
|
+
const onEvent = event => {
|
|
70
|
+
if (syncing) {
|
|
71
|
+
pendingEvents.push(event);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
report(event);
|
|
75
|
+
};
|
|
76
|
+
const nodes = new Map();
|
|
77
|
+
const groups = new Map();
|
|
78
|
+
let config = {};
|
|
79
|
+
let section = null;
|
|
80
|
+
let expanded = false;
|
|
81
|
+
let interacting = false;
|
|
82
|
+
let destroyed = false;
|
|
83
|
+
const isHovered = () => [...groups.values()].some(group => group.hovered);
|
|
84
|
+
const positionOf = spec => spec.position ?? config.position ?? DEFAULT_POSITION;
|
|
85
|
+
function ensureSection() {
|
|
86
|
+
const root = getOverlayLayerRoot('toast');
|
|
87
|
+
if (!section) {
|
|
88
|
+
section = document.createElement('section');
|
|
89
|
+
section.setAttribute('aria-label', 'Notifications alt+T');
|
|
90
|
+
section.setAttribute('data-onekey-toast-section', '');
|
|
91
|
+
section.tabIndex = -1;
|
|
92
|
+
}
|
|
93
|
+
if (config.testID) {
|
|
94
|
+
section.setAttribute('data-testid', config.testID);
|
|
95
|
+
}
|
|
96
|
+
if (section.parentElement !== root) {
|
|
97
|
+
root.prepend(section);
|
|
98
|
+
syncOverlayInert();
|
|
99
|
+
}
|
|
100
|
+
return section;
|
|
101
|
+
}
|
|
102
|
+
function setExpanded(value) {
|
|
103
|
+
if (expanded !== value) {
|
|
104
|
+
expanded = value;
|
|
105
|
+
update();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function setInteracting(value) {
|
|
109
|
+
if (interacting !== value) {
|
|
110
|
+
interacting = value;
|
|
111
|
+
if (!value && !isHovered()) {
|
|
112
|
+
expanded = false;
|
|
113
|
+
}
|
|
114
|
+
update();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function ensureGroup(position) {
|
|
118
|
+
let group = groups.get(position);
|
|
119
|
+
if (!group) {
|
|
120
|
+
const ol = document.createElement('ol');
|
|
121
|
+
ol.tabIndex = -1;
|
|
122
|
+
ol.setAttribute('data-onekey-toast-toaster', '');
|
|
123
|
+
const nextGroup = {
|
|
124
|
+
position,
|
|
125
|
+
ol,
|
|
126
|
+
hovered: false,
|
|
127
|
+
toasts: [],
|
|
128
|
+
heights: []
|
|
129
|
+
};
|
|
130
|
+
ol.addEventListener('mouseenter', () => {
|
|
131
|
+
nextGroup.hovered = true;
|
|
132
|
+
expanded = nodes.size > 1;
|
|
133
|
+
update();
|
|
134
|
+
});
|
|
135
|
+
ol.addEventListener('mousemove', () => {
|
|
136
|
+
if (!nextGroup.hovered || nodes.size > 1 && !expanded) {
|
|
137
|
+
nextGroup.hovered = true;
|
|
138
|
+
expanded = nodes.size > 1;
|
|
139
|
+
update();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
ol.addEventListener('mouseleave', () => {
|
|
143
|
+
nextGroup.hovered = false;
|
|
144
|
+
// Keep the stack open while a card is being dragged.
|
|
145
|
+
if (!interacting && !isHovered()) {
|
|
146
|
+
expanded = false;
|
|
147
|
+
}
|
|
148
|
+
update();
|
|
149
|
+
});
|
|
150
|
+
ol.addEventListener('pointerdown', () => setInteracting(true));
|
|
151
|
+
ol.addEventListener('pointerup', () => setInteracting(false));
|
|
152
|
+
ol.addEventListener('pointercancel', () => setInteracting(false));
|
|
153
|
+
group = nextGroup;
|
|
154
|
+
groups.set(position, group);
|
|
155
|
+
}
|
|
156
|
+
if (group.ol.parentElement !== ensureSection()) {
|
|
157
|
+
ensureSection().append(group.ol);
|
|
158
|
+
}
|
|
159
|
+
return group;
|
|
160
|
+
}
|
|
161
|
+
function offsetOf(group, node) {
|
|
162
|
+
// The height index moves before the card list does, so the layout of the
|
|
163
|
+
// cards behind a leaving one starts closing at once.
|
|
164
|
+
const heightIndex = Math.max(group.heights.findIndex(height => height.id === node.id), 0);
|
|
165
|
+
const heightsBefore = group.heights.slice(0, heightIndex).reduce((sum, height) => sum + height.height, 0);
|
|
166
|
+
return heightIndex * GAP + heightsBefore;
|
|
167
|
+
}
|
|
168
|
+
function measure(node) {
|
|
169
|
+
const group = groups.get(node.position);
|
|
170
|
+
if (!group || node.removed) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// The card's own height: a card further back in the stack is scaled
|
|
174
|
+
// and pinned to the front card's height, neither of which is its size.
|
|
175
|
+
const {
|
|
176
|
+
style
|
|
177
|
+
} = node.li;
|
|
178
|
+
const originalHeight = style.height;
|
|
179
|
+
const originalTransform = style.transform;
|
|
180
|
+
style.height = 'auto';
|
|
181
|
+
style.transform = 'none';
|
|
182
|
+
const {
|
|
183
|
+
height
|
|
184
|
+
} = node.li.getBoundingClientRect();
|
|
185
|
+
style.height = originalHeight;
|
|
186
|
+
style.transform = originalTransform;
|
|
187
|
+
node.initialHeight = height;
|
|
188
|
+
const existing = group.heights.find(entry => entry.id === node.id);
|
|
189
|
+
if (existing) {
|
|
190
|
+
existing.height = height;
|
|
191
|
+
} else {
|
|
192
|
+
group.heights.unshift({
|
|
193
|
+
id: node.id,
|
|
194
|
+
height
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function clearCloseTimer(node) {
|
|
199
|
+
if (node.closeTimer !== undefined) {
|
|
200
|
+
clearTimeout(node.closeTimer);
|
|
201
|
+
node.closeTimer = undefined;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function syncTimers() {
|
|
205
|
+
const paused = expanded || isHovered() || interacting;
|
|
206
|
+
nodes.forEach(node => {
|
|
207
|
+
if (node.removed || !Number.isFinite(node.spec.duration)) {
|
|
208
|
+
clearCloseTimer(node);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (paused) {
|
|
212
|
+
clearCloseTimer(node);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (node.closeTimer === undefined) {
|
|
216
|
+
// A resumed toast starts over with its whole lifetime, as before.
|
|
217
|
+
node.closeTimer = setTimeout(() => {
|
|
218
|
+
node.closeTimer = undefined;
|
|
219
|
+
deleteToast(node, 'timeout', true);
|
|
220
|
+
}, node.spec.duration);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function unmount(node, reason) {
|
|
225
|
+
if (node.unmountTimer !== undefined) {
|
|
226
|
+
clearTimeout(node.unmountTimer);
|
|
227
|
+
node.unmountTimer = undefined;
|
|
228
|
+
}
|
|
229
|
+
clearCloseTimer(node);
|
|
230
|
+
node.li.remove();
|
|
231
|
+
const group = groups.get(node.position);
|
|
232
|
+
if (group) {
|
|
233
|
+
group.toasts = group.toasts.filter(entry => entry !== node);
|
|
234
|
+
group.heights = group.heights.filter(entry => entry.id !== node.id);
|
|
235
|
+
}
|
|
236
|
+
if (nodes.get(node.id) === node) {
|
|
237
|
+
nodes.delete(node.id);
|
|
238
|
+
}
|
|
239
|
+
onEvent({
|
|
240
|
+
id: node.id,
|
|
241
|
+
generation: node.generation,
|
|
242
|
+
type: 'close',
|
|
243
|
+
reason
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function deleteToast(node, reason, notify) {
|
|
247
|
+
if (node.removed) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const group = groups.get(node.position);
|
|
251
|
+
node.removed = true;
|
|
252
|
+
// Keep the offset the card had, for the exit transition.
|
|
253
|
+
node.offsetBeforeRemove = group ? offsetOf(group, node) : 0;
|
|
254
|
+
if (group) {
|
|
255
|
+
group.heights = group.heights.filter(entry => entry.id !== node.id);
|
|
256
|
+
}
|
|
257
|
+
clearCloseTimer(node);
|
|
258
|
+
if (notify) {
|
|
259
|
+
onEvent({
|
|
260
|
+
id: node.id,
|
|
261
|
+
generation: node.generation,
|
|
262
|
+
type: 'dismiss',
|
|
263
|
+
reason
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
node.unmountTimer = setTimeout(() => {
|
|
267
|
+
node.unmountTimer = undefined;
|
|
268
|
+
unmount(node, reason);
|
|
269
|
+
update();
|
|
270
|
+
}, TIME_BEFORE_UNMOUNT);
|
|
271
|
+
update();
|
|
272
|
+
}
|
|
273
|
+
function attachSwipe(node) {
|
|
274
|
+
const {
|
|
275
|
+
li
|
|
276
|
+
} = node;
|
|
277
|
+
li.addEventListener('pointerdown', event => {
|
|
278
|
+
if (node.removed) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
node.dragStartedAt = Date.now();
|
|
282
|
+
const group = groups.get(node.position);
|
|
283
|
+
node.offsetBeforeRemove = group ? offsetOf(group, node) : 0;
|
|
284
|
+
const target = event.target;
|
|
285
|
+
if (target.closest?.('button, [data-okt-link]')) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// Keep the pointer while it travels outside the card.
|
|
289
|
+
target.setPointerCapture?.(event.pointerId);
|
|
290
|
+
node.swiping = true;
|
|
291
|
+
node.pointerStart = {
|
|
292
|
+
x: event.clientX,
|
|
293
|
+
y: event.clientY
|
|
294
|
+
};
|
|
295
|
+
update();
|
|
296
|
+
});
|
|
297
|
+
li.addEventListener('pointerup', () => {
|
|
298
|
+
if (node.swipeOut || node.removed) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
node.pointerStart = null;
|
|
302
|
+
const swipeAmount = Number(li.style.getPropertyValue('--swipe-amount').replace('px', '') || 0);
|
|
303
|
+
const timeTaken = Date.now() - node.dragStartedAt;
|
|
304
|
+
const velocity = Math.abs(swipeAmount) / timeTaken;
|
|
305
|
+
if (Math.abs(swipeAmount) >= SWIPE_THRESHOLD || velocity > SWIPE_VELOCITY) {
|
|
306
|
+
node.swipeOut = true;
|
|
307
|
+
deleteToast(node, 'swipe', true);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
li.style.setProperty('--swipe-amount', '0px');
|
|
311
|
+
node.swiping = false;
|
|
312
|
+
update();
|
|
313
|
+
});
|
|
314
|
+
li.addEventListener('pointercancel', () => {
|
|
315
|
+
if (node.swipeOut || node.removed) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
node.pointerStart = null;
|
|
319
|
+
li.style.setProperty('--swipe-amount', '0px');
|
|
320
|
+
node.swiping = false;
|
|
321
|
+
update();
|
|
322
|
+
});
|
|
323
|
+
li.addEventListener('pointermove', event => {
|
|
324
|
+
if (!node.pointerStart) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const yPosition = event.clientY - node.pointerStart.y;
|
|
328
|
+
const xPosition = event.clientX - node.pointerStart.x;
|
|
329
|
+
const isTop = node.position.startsWith('top');
|
|
330
|
+
// Top toasts leave upwards, bottom toasts downwards.
|
|
331
|
+
const clampedY = isTop ? Math.min(0, yPosition) : Math.max(0, yPosition);
|
|
332
|
+
const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
|
|
333
|
+
if (Math.abs(clampedY) > swipeStartThreshold) {
|
|
334
|
+
li.style.setProperty('--swipe-amount', `${yPosition}px`);
|
|
335
|
+
} else if (Math.abs(xPosition) > swipeStartThreshold) {
|
|
336
|
+
// A sideways drag ends the gesture for this press.
|
|
337
|
+
node.pointerStart = null;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function renderContent(node) {
|
|
342
|
+
const next = buildToastContent(node.spec, event => {
|
|
343
|
+
if (!node.removed) {
|
|
344
|
+
onEvent({
|
|
345
|
+
...event,
|
|
346
|
+
id: node.id,
|
|
347
|
+
generation: node.generation
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
if (node.content.parentElement === node.li) {
|
|
352
|
+
node.content.replaceWith(next);
|
|
353
|
+
} else {
|
|
354
|
+
node.li.append(next);
|
|
355
|
+
}
|
|
356
|
+
node.content = next;
|
|
357
|
+
if (node.spec.testID) {
|
|
358
|
+
node.li.setAttribute('data-testid', node.spec.testID);
|
|
359
|
+
} else {
|
|
360
|
+
node.li.removeAttribute('data-testid');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function createNode(item) {
|
|
364
|
+
const li = document.createElement('li');
|
|
365
|
+
li.setAttribute('aria-live', 'polite');
|
|
366
|
+
li.setAttribute('aria-atomic', 'true');
|
|
367
|
+
li.setAttribute('role', 'status');
|
|
368
|
+
li.tabIndex = 0;
|
|
369
|
+
li.setAttribute('data-onekey-toast', '');
|
|
370
|
+
li.setAttribute('data-styled', 'true');
|
|
371
|
+
li.setAttribute('data-dismissible', 'true');
|
|
372
|
+
li.setAttribute('data-invert', 'false');
|
|
373
|
+
const closeButton = createCloseButton(config.closeButtonLabel ?? 'Close toast');
|
|
374
|
+
li.append(closeButton);
|
|
375
|
+
const node = {
|
|
376
|
+
id: item.spec.id,
|
|
377
|
+
spec: item.spec,
|
|
378
|
+
revision: item.revision,
|
|
379
|
+
generation: item.generation,
|
|
380
|
+
position: positionOf(item.spec),
|
|
381
|
+
li,
|
|
382
|
+
content: document.createElement('div'),
|
|
383
|
+
mounted: false,
|
|
384
|
+
removed: false,
|
|
385
|
+
swiping: false,
|
|
386
|
+
swipeOut: false,
|
|
387
|
+
offsetBeforeRemove: 0,
|
|
388
|
+
initialHeight: 0,
|
|
389
|
+
pointerStart: null,
|
|
390
|
+
dragStartedAt: 0
|
|
391
|
+
};
|
|
392
|
+
closeButton.addEventListener('click', () => deleteToast(node, 'close', true));
|
|
393
|
+
li.addEventListener('keydown', event => {
|
|
394
|
+
if (!node.removed && node.spec.layout === 'notification' && node.spec.pressable && event.target === li && (event.key === 'Enter' || event.key === ' ')) {
|
|
395
|
+
event.preventDefault();
|
|
396
|
+
onEvent({
|
|
397
|
+
id: node.id,
|
|
398
|
+
generation: node.generation,
|
|
399
|
+
type: 'press'
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
renderContent(node);
|
|
404
|
+
attachSwipe(node);
|
|
405
|
+
return node;
|
|
406
|
+
}
|
|
407
|
+
function mountNode(node) {
|
|
408
|
+
const group = ensureGroup(node.position);
|
|
409
|
+
group.toasts.unshift(node);
|
|
410
|
+
group.ol.prepend(node.li);
|
|
411
|
+
nodes.set(node.id, node);
|
|
412
|
+
applyGroup(group);
|
|
413
|
+
// Measuring lays the card out in its resting-out state, so switching it
|
|
414
|
+
// to mounted right after starts the enter transition from there. No frame
|
|
415
|
+
// callback: those do not run while the page is hidden.
|
|
416
|
+
measure(node);
|
|
417
|
+
node.mounted = true;
|
|
418
|
+
update();
|
|
419
|
+
}
|
|
420
|
+
function obstructionTop() {
|
|
421
|
+
const bottom = config.topObstruction ?? 0;
|
|
422
|
+
if (bottom <= 0) {
|
|
423
|
+
return 0;
|
|
424
|
+
}
|
|
425
|
+
const gap = config.topObstructionGap ?? DEFAULT_OBSTRUCTION_GAP;
|
|
426
|
+
const room = config.topObstructionRoom ?? DEFAULT_OBSTRUCTION_ROOM;
|
|
427
|
+
return Math.max(0, Math.min(bottom + gap, globalThis.innerHeight - room));
|
|
428
|
+
}
|
|
429
|
+
function applyGroup(group) {
|
|
430
|
+
const {
|
|
431
|
+
ol
|
|
432
|
+
} = group;
|
|
433
|
+
const [yPosition, xPosition] = group.position.split('-');
|
|
434
|
+
ol.dir = getDocumentDirection();
|
|
435
|
+
ol.setAttribute('data-theme', config.theme ?? 'light');
|
|
436
|
+
ol.setAttribute('data-y-position', yPosition ?? 'bottom');
|
|
437
|
+
ol.setAttribute('data-x-position', xPosition ?? 'right');
|
|
438
|
+
ol.style.setProperty('--front-toast-height', `${group.heights[0]?.height ?? 0}px`);
|
|
439
|
+
ol.style.setProperty('--offset', `${VIEWPORT_OFFSET}px`);
|
|
440
|
+
ol.style.setProperty('--width', `${TOAST_WIDTH}px`);
|
|
441
|
+
ol.style.setProperty('--gap', `${GAP}px`);
|
|
442
|
+
if (config.webContentMaxHeight !== undefined) {
|
|
443
|
+
ol.style.setProperty('--okt-max-height', `${config.webContentMaxHeight}px`);
|
|
444
|
+
} else {
|
|
445
|
+
ol.style.removeProperty('--okt-max-height');
|
|
446
|
+
}
|
|
447
|
+
// Top toasts rest under whatever hangs from the top of the window. An
|
|
448
|
+
// inline `top`: the narrow-window rule pins the toaster otherwise.
|
|
449
|
+
const top = yPosition === 'top' ? obstructionTop() : 0;
|
|
450
|
+
const reducedMotion = config.respectReducedMotion !== false && globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
451
|
+
ol.style.transition = reducedMotion ? '' : `top ${OBSTRUCTION_SHIFT_MS}ms ease`;
|
|
452
|
+
ol.style.top = top > 0 ? `${top}px` : '';
|
|
453
|
+
group.toasts.forEach((node, index) => {
|
|
454
|
+
const {
|
|
455
|
+
li
|
|
456
|
+
} = node;
|
|
457
|
+
li.setAttribute('data-mounted', String(node.mounted));
|
|
458
|
+
li.setAttribute('data-removed', String(node.removed));
|
|
459
|
+
li.setAttribute('data-visible', String(index + 1 <= VISIBLE_TOASTS));
|
|
460
|
+
li.setAttribute('data-y-position', yPosition ?? 'bottom');
|
|
461
|
+
li.setAttribute('data-x-position', xPosition ?? 'right');
|
|
462
|
+
li.setAttribute('data-index', String(index));
|
|
463
|
+
li.setAttribute('data-front', String(index === 0));
|
|
464
|
+
li.setAttribute('data-swiping', String(node.swiping));
|
|
465
|
+
li.setAttribute('data-swipe-out', String(node.swipeOut));
|
|
466
|
+
li.setAttribute('data-expanded', String(expanded));
|
|
467
|
+
li.style.setProperty('--index', String(index));
|
|
468
|
+
li.style.setProperty('--toasts-before', String(index));
|
|
469
|
+
li.style.setProperty('--z-index', String(group.toasts.length - index));
|
|
470
|
+
li.style.setProperty('--offset', `${node.removed ? node.offsetBeforeRemove : offsetOf(group, node)}px`);
|
|
471
|
+
li.style.setProperty('--initial-height', `${node.initialHeight}px`);
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
function update() {
|
|
475
|
+
if (destroyed) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
let releasedHover = false;
|
|
479
|
+
groups.forEach((group, position) => {
|
|
480
|
+
if (group.toasts.length === 0) {
|
|
481
|
+
if (group.hovered) {
|
|
482
|
+
releasedHover = true;
|
|
483
|
+
}
|
|
484
|
+
group.ol.remove();
|
|
485
|
+
groups.delete(position);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
const hovered = isHovered();
|
|
489
|
+
if (nodes.size <= 1 && expanded) {
|
|
490
|
+
// One card has nothing to fan out.
|
|
491
|
+
expanded = false;
|
|
492
|
+
} else if (releasedHover && !hovered && !interacting) {
|
|
493
|
+
expanded = false;
|
|
494
|
+
} else if (nodes.size > 1 && hovered && !expanded) {
|
|
495
|
+
expanded = true;
|
|
496
|
+
}
|
|
497
|
+
groups.forEach(group => {
|
|
498
|
+
applyGroup(group);
|
|
499
|
+
});
|
|
500
|
+
if (nodes.size === 0) {
|
|
501
|
+
section?.remove();
|
|
502
|
+
interacting = false;
|
|
503
|
+
}
|
|
504
|
+
syncTimers();
|
|
505
|
+
}
|
|
506
|
+
function moveNode(node, position) {
|
|
507
|
+
const previous = groups.get(node.position);
|
|
508
|
+
if (previous) {
|
|
509
|
+
previous.toasts = previous.toasts.filter(entry => entry !== node);
|
|
510
|
+
previous.heights = previous.heights.filter(entry => entry.id !== node.id);
|
|
511
|
+
}
|
|
512
|
+
node.position = position;
|
|
513
|
+
const group = ensureGroup(position);
|
|
514
|
+
group.toasts.push(node);
|
|
515
|
+
group.ol.append(node.li);
|
|
516
|
+
if (!node.removed) {
|
|
517
|
+
group.heights.push({
|
|
518
|
+
id: node.id,
|
|
519
|
+
height: node.initialHeight
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
return group;
|
|
523
|
+
}
|
|
524
|
+
function reconcileGroupOrder(group, order) {
|
|
525
|
+
group.toasts.sort((a, b) => (order.get(a.id) ?? 0) - (order.get(b.id) ?? 0));
|
|
526
|
+
group.toasts.forEach(node => group.ol.append(node.li));
|
|
527
|
+
group.heights.sort((a, b) => (order.get(a.id) ?? 0) - (order.get(b.id) ?? 0));
|
|
528
|
+
}
|
|
529
|
+
function onKeyDown(event) {
|
|
530
|
+
if (nodes.size === 0 || section?.inert || section?.parentElement?.inert) {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
const lists = [...groups.values()].map(group => group.ol);
|
|
534
|
+
if (event.altKey && event.code === 'KeyT') {
|
|
535
|
+
setExpanded(true);
|
|
536
|
+
lists[0]?.focus();
|
|
537
|
+
}
|
|
538
|
+
if (event.code === 'Escape' && lists.some(list => document.activeElement === list || list.contains(document.activeElement))) {
|
|
539
|
+
setExpanded(false);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function onResize() {
|
|
543
|
+
if ((config.topObstruction ?? 0) > 0) {
|
|
544
|
+
update();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
document.addEventListener('keydown', onKeyDown);
|
|
548
|
+
globalThis.addEventListener('resize', onResize);
|
|
549
|
+
return {
|
|
550
|
+
sync(items, nextConfig) {
|
|
551
|
+
if (destroyed) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
syncing = true;
|
|
555
|
+
config = nextConfig;
|
|
556
|
+
const present = new Set(items.map(item => item.spec.id));
|
|
557
|
+
// Cards the list no longer knows leave without ceremony.
|
|
558
|
+
[...nodes.values()].forEach(node => {
|
|
559
|
+
if (!present.has(node.id)) {
|
|
560
|
+
unmount(node, 'programmatic');
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
const movedGroups = new Set();
|
|
564
|
+
// Oldest first, so each new card lands in front of the previous one.
|
|
565
|
+
[...items].reverse().forEach(item => {
|
|
566
|
+
let node = nodes.get(item.spec.id);
|
|
567
|
+
if (node?.removed && item.visible) {
|
|
568
|
+
// Shown again while the previous card was leaving.
|
|
569
|
+
unmount(node, 'programmatic');
|
|
570
|
+
node = undefined;
|
|
571
|
+
}
|
|
572
|
+
if (!node) {
|
|
573
|
+
if (item.visible) {
|
|
574
|
+
mountNode(createNode(item));
|
|
575
|
+
} else {
|
|
576
|
+
onEvent({
|
|
577
|
+
id: item.spec.id,
|
|
578
|
+
generation: item.generation,
|
|
579
|
+
type: 'close',
|
|
580
|
+
reason: 'programmatic'
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (node.revision !== item.revision) {
|
|
586
|
+
node.revision = item.revision;
|
|
587
|
+
node.spec = item.spec;
|
|
588
|
+
renderContent(node);
|
|
589
|
+
measure(node);
|
|
590
|
+
}
|
|
591
|
+
if (node.generation !== item.generation) {
|
|
592
|
+
// Shown again: the toast starts its lifetime over.
|
|
593
|
+
node.generation = item.generation;
|
|
594
|
+
clearCloseTimer(node);
|
|
595
|
+
}
|
|
596
|
+
const position = positionOf(node.spec);
|
|
597
|
+
if (position !== node.position) {
|
|
598
|
+
movedGroups.add(moveNode(node, position));
|
|
599
|
+
}
|
|
600
|
+
if (!item.visible) {
|
|
601
|
+
deleteToast(node, 'programmatic', false);
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
if (movedGroups.size > 0) {
|
|
605
|
+
const order = new Map(items.map((item, index) => [item.spec.id, index]));
|
|
606
|
+
movedGroups.forEach(group => reconcileGroupOrder(group, order));
|
|
607
|
+
}
|
|
608
|
+
update();
|
|
609
|
+
syncing = false;
|
|
610
|
+
pendingEvents.splice(0).forEach(report);
|
|
611
|
+
},
|
|
612
|
+
destroy() {
|
|
613
|
+
destroyed = true;
|
|
614
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
615
|
+
globalThis.removeEventListener('resize', onResize);
|
|
616
|
+
nodes.forEach(node => {
|
|
617
|
+
clearCloseTimer(node);
|
|
618
|
+
if (node.unmountTimer !== undefined) {
|
|
619
|
+
clearTimeout(node.unmountTimer);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
nodes.clear();
|
|
623
|
+
groups.clear();
|
|
624
|
+
section?.remove();
|
|
625
|
+
section = null;
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
//# sourceMappingURL=toastDomRenderer.web.js.map
|