@rdlabo/ionic-theme-ios27 1.2.0 → 1.2.1-beta.pr273.shae866fb1dca9f
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/dist/css/components/ion-button.css +1 -1
- package/dist/css/components/ion-toolbar.css +1 -1
- package/dist/css/ionic-theme-ios27.css +1 -1
- package/dist/css/vertical-bars.css +1 -1
- package/dist/native/components/index.js +2 -2
- package/dist/native/components/index.js.map +1 -1
- package/dist/native/definitions.d.ts +32 -0
- package/dist/native/definitions.d.ts.map +1 -1
- package/dist/native/index.d.ts.map +1 -1
- package/dist/native/index.js +23 -6
- package/dist/native/index.js.map +1 -1
- package/dist/native/overlays/content.d.ts +4 -0
- package/dist/native/overlays/content.d.ts.map +1 -0
- package/dist/native/overlays/content.js +51 -0
- package/dist/native/overlays/content.js.map +1 -0
- package/dist/native/overlays/controller.d.ts +8 -0
- package/dist/native/overlays/controller.d.ts.map +1 -0
- package/dist/native/overlays/controller.js +266 -0
- package/dist/native/overlays/controller.js.map +1 -0
- package/dist/native/overlays/dialog-animation.d.ts +8 -0
- package/dist/native/overlays/dialog-animation.d.ts.map +1 -0
- package/dist/native/overlays/dialog-animation.js +31 -0
- package/dist/native/overlays/dialog-animation.js.map +1 -0
- package/dist/native/overlays/dismiss-animation.d.ts +4 -0
- package/dist/native/overlays/dismiss-animation.d.ts.map +1 -0
- package/dist/native/overlays/dismiss-animation.js +18 -0
- package/dist/native/overlays/dismiss-animation.js.map +1 -0
- package/dist/native/overlays/focus.d.ts +5 -0
- package/dist/native/overlays/focus.d.ts.map +1 -0
- package/dist/native/overlays/focus.js +59 -0
- package/dist/native/overlays/focus.js.map +1 -0
- package/dist/native/overlays/popover.d.ts +11 -0
- package/dist/native/overlays/popover.d.ts.map +1 -0
- package/dist/native/overlays/popover.js +78 -0
- package/dist/native/overlays/popover.js.map +1 -0
- package/dist/native/overlays/styles.d.ts +9 -0
- package/dist/native/overlays/styles.d.ts.map +1 -0
- package/dist/native/overlays/styles.js +82 -0
- package/dist/native/overlays/styles.js.map +1 -0
- package/dist/native/prehide.d.ts.map +1 -1
- package/dist/native/prehide.js +6 -2
- package/dist/native/prehide.js.map +1 -1
- package/dist/native/runtime.d.ts +4 -1
- package/dist/native/runtime.d.ts.map +1 -1
- package/dist/native/runtime.js +29 -8
- package/dist/native/runtime.js.map +1 -1
- package/dist/native/shared/dom.d.ts +2 -0
- package/dist/native/shared/dom.d.ts.map +1 -1
- package/dist/native/shared/dom.js +5 -1
- package/dist/native/shared/dom.js.map +1 -1
- package/dist/native/shared/projection-id.d.ts +4 -0
- package/dist/native/shared/projection-id.d.ts.map +1 -0
- package/dist/native/shared/projection-id.js +7 -0
- package/dist/native/shared/projection-id.js.map +1 -0
- package/dist/native/vertical-bars-web.d.ts.map +1 -1
- package/dist/native/vertical-bars-web.js +4 -2
- package/dist/native/vertical-bars-web.js.map +1 -1
- package/dist/native-integration/index.d.ts +1 -1
- package/dist/native-integration/index.js.map +1 -1
- package/dist/native-integration/transition.d.ts +1 -1
- package/dist/native-integration/transition.js.map +1 -1
- package/dist/sheets-of-glass/animations.d.ts +1 -1
- package/dist/sheets-of-glass/animations.js +1 -1
- package/dist/sheets-of-glass/animations.js.map +1 -1
- package/dist/sheets-of-glass/index.js +1 -1
- package/dist/sheets-of-glass/index.js.map +1 -1
- package/dist/tab-bar-searchable/animations/enter.d.ts +1 -1
- package/dist/tab-bar-searchable/animations/enter.d.ts.map +1 -1
- package/dist/tab-bar-searchable/animations/enter.js +1 -1
- package/dist/tab-bar-searchable/animations/enter.js.map +1 -1
- package/dist/tab-bar-searchable/animations/leave.d.ts +1 -1
- package/dist/tab-bar-searchable/animations/leave.d.ts.map +1 -1
- package/dist/tab-bar-searchable/animations/leave.js +1 -1
- package/dist/tab-bar-searchable/animations/leave.js.map +1 -1
- package/dist/tab-bar-searchable/index.js +1 -1
- package/dist/tab-bar-searchable/index.js.map +1 -1
- package/dist/transition/index.d.ts +1 -1
- package/dist/transition/index.js +1 -1
- package/dist/transition/index.js.map +1 -1
- package/dist/transition/ios.transition.d.ts +1 -1
- package/dist/transition/ios.transition.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/docs/native-ui-shell.md +20 -4
- package/docs/vertical-bars.md +3 -1
- package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellSearchController.swift +65 -91
- package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellTabBar.swift +9 -3
- package/ios/Sources/IonicNativeUIShellPlugin/Components/ShellVerticalBars.swift +79 -3
- package/ios/Sources/IonicNativeUIShellPlugin/IonicNativeUIShellPlugin.swift +57 -1
- package/ios/Sources/IonicNativeUIShellPlugin/Overlays/ShellOverlayController.swift +116 -0
- package/ios/Sources/IonicNativeUIShellPlugin/Overlays/ShellOverlayHost.swift +36 -0
- package/ios/Tests/IonicNativeUIShellPluginTests/ShellSnapshotTests.swift +27 -0
- package/package.json +2 -2
- package/src/native/components/index.ts +3 -2
- package/src/native/definitions.ts +27 -1
- package/src/native/index.ts +23 -6
- package/src/native/overlays/content.ts +51 -0
- package/src/native/overlays/controller.ts +322 -0
- package/src/native/overlays/dialog-animation.ts +30 -0
- package/src/native/overlays/dismiss-animation.ts +15 -0
- package/src/native/overlays/focus.ts +64 -0
- package/src/native/overlays/popover.ts +80 -0
- package/src/native/overlays/styles.ts +80 -0
- package/src/native/prehide.ts +6 -1
- package/src/native/runtime.ts +39 -15
- package/src/native/shared/dom.ts +14 -0
- package/src/native/shared/projection-id.ts +2 -0
- package/src/native/vertical-bars-web.ts +11 -1
- package/src/native-integration/index.ts +1 -1
- package/src/native-integration/transition.ts +1 -1
- package/src/sheets-of-glass/animations.ts +2 -2
- package/src/sheets-of-glass/index.ts +2 -2
- package/src/styles/components/ion-button.scss +47 -0
- package/src/styles/components/ion-toolbar.scss +62 -7
- package/src/styles/vertical-bars.scss +23 -0
- package/src/tab-bar-searchable/animations/enter.ts +2 -1
- package/src/tab-bar-searchable/animations/leave.ts +2 -1
- package/src/tab-bar-searchable/index.ts +1 -1
- package/src/transition/index.ts +3 -3
- package/src/transition/ios.transition.ts +1 -1
- package/src/utils.ts +1 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import type { NativeUIShellOptions, NativeUIShellPlugin } from '../definitions';
|
|
2
|
+
import { bounded } from '../runtime';
|
|
3
|
+
import { isExcluded, isPermanentlyExcluded, isShellDisabled } from '../shared/dom';
|
|
4
|
+
import { activeElement, trapFocus } from './focus';
|
|
5
|
+
import { relayPopover, popoverPresentation, verticalBarsPopoverAnchor } from './popover';
|
|
6
|
+
import { nativeDialogAnimation } from './dialog-animation';
|
|
7
|
+
import { relayStyles } from './styles';
|
|
8
|
+
|
|
9
|
+
type Presentation = { kind: 'popover'; animated: boolean };
|
|
10
|
+
type Overlay = HTMLIonPopoverElement;
|
|
11
|
+
const lifecycle = (overlay: Overlay, phase: string) =>
|
|
12
|
+
`ion${overlay.localName.slice(4, 5).toUpperCase()}${overlay.localName.slice(5)}${phase}`;
|
|
13
|
+
|
|
14
|
+
interface Connection {
|
|
15
|
+
id: string;
|
|
16
|
+
overlay: Overlay;
|
|
17
|
+
dismissed: boolean;
|
|
18
|
+
win?: Window;
|
|
19
|
+
focus: Element | null;
|
|
20
|
+
stopStyles?: () => void;
|
|
21
|
+
releaseProjection?: () => void;
|
|
22
|
+
stopContent?: () => void;
|
|
23
|
+
stopFocus?: () => void;
|
|
24
|
+
stopEvents?: () => void;
|
|
25
|
+
stopChildEvents?: () => void;
|
|
26
|
+
stopExclusions?: () => void;
|
|
27
|
+
closing?: Promise<void>;
|
|
28
|
+
nativeClosing?: Promise<void>;
|
|
29
|
+
stopAnimation?: () => void;
|
|
30
|
+
hideAnimation?: () => void;
|
|
31
|
+
stopLifecycle?: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Ionic owns lifecycle and dismissal; only one overlay is relayed at a time. */
|
|
35
|
+
export const createOverlayController = async (
|
|
36
|
+
doc: Document,
|
|
37
|
+
plugin: NativeUIShellPlugin,
|
|
38
|
+
options: NativeUIShellOptions,
|
|
39
|
+
retainProjection: (deferActivation?: (id: string) => boolean) => () => void,
|
|
40
|
+
nativeVerticalBars: () => boolean,
|
|
41
|
+
) => {
|
|
42
|
+
let current: Connection | undefined;
|
|
43
|
+
let opening = Promise.resolve();
|
|
44
|
+
let sequence = 0;
|
|
45
|
+
let stopped = false;
|
|
46
|
+
const suspensions = new Set<symbol>();
|
|
47
|
+
const events = ['Modal', 'Popover', 'Alert', 'ActionSheet', 'Loading', 'Picker', 'Toast'].map((name) => `ion${name}WillPresent`);
|
|
48
|
+
const cleanup = async (connection: Connection) => {
|
|
49
|
+
// Every teardown step is isolated and bounded: a throwing or hanging step
|
|
50
|
+
// must not strand the retained page projections or the child window.
|
|
51
|
+
const stage = async (label: string, run?: () => void | Promise<void>) => {
|
|
52
|
+
try {
|
|
53
|
+
await bounded(Promise.resolve(run?.()));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(`Native overlay teardown failed at ${label}; continuing cleanup anyway.`, error);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
await stage('events', connection.stopEvents);
|
|
60
|
+
await stage('lifecycle', connection.stopLifecycle);
|
|
61
|
+
await stage('childEvents', connection.stopChildEvents);
|
|
62
|
+
await stage('exclusions', connection.stopExclusions);
|
|
63
|
+
await stage('focus', connection.stopFocus);
|
|
64
|
+
// A timed-out dismissal must not strand the relayed content in the child window.
|
|
65
|
+
await connection.nativeClosing?.catch((error) => {
|
|
66
|
+
console.error('Native overlay dismissal did not complete; restoring the Web content anyway.', error);
|
|
67
|
+
});
|
|
68
|
+
await stage('content', connection.stopContent);
|
|
69
|
+
await stage('animation', connection.stopAnimation);
|
|
70
|
+
await stage('styles', connection.stopStyles);
|
|
71
|
+
await stage('close', () => bounded(plugin.closeOverlay({ id: connection.id })));
|
|
72
|
+
} finally {
|
|
73
|
+
// The page projections must be released even if teardown throws above.
|
|
74
|
+
connection.releaseProjection?.();
|
|
75
|
+
connection.releaseProjection = undefined;
|
|
76
|
+
try {
|
|
77
|
+
connection.win?.close();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error('Native overlay window was already gone.', error);
|
|
80
|
+
}
|
|
81
|
+
if (current === connection) current = undefined;
|
|
82
|
+
const focus = connection.focus as HTMLElement | null;
|
|
83
|
+
if (focus?.isConnected && focus.tabIndex >= 0) focus.focus({ preventScroll: true });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const release = (connection: Connection): Promise<void> => (connection.closing ??= cleanup(connection));
|
|
87
|
+
const restoreWeb = async () => {
|
|
88
|
+
if (current) await release(current);
|
|
89
|
+
};
|
|
90
|
+
const excluded = (overlay: HTMLElement) => isPermanentlyExcluded(overlay) || isExcluded(overlay) || isShellDisabled(overlay);
|
|
91
|
+
const connect = async (connection: Connection, ready: Promise<void>, presentation: Presentation) => {
|
|
92
|
+
const { overlay } = connection;
|
|
93
|
+
const gone = () =>
|
|
94
|
+
current !== connection ||
|
|
95
|
+
stopped ||
|
|
96
|
+
suspensions.size ||
|
|
97
|
+
connection.dismissed ||
|
|
98
|
+
!overlay.isConnected ||
|
|
99
|
+
!nativeVerticalBars() ||
|
|
100
|
+
excluded(overlay);
|
|
101
|
+
// Keep the source invisible while the native toolbar prepares its popover.
|
|
102
|
+
connection.hideAnimation?.();
|
|
103
|
+
try {
|
|
104
|
+
// Prepare the child window concurrently with Ionic's content initialization.
|
|
105
|
+
const staging = (async () => {
|
|
106
|
+
await bounded(
|
|
107
|
+
plugin.prepareOverlay({
|
|
108
|
+
id: connection.id,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
if (gone()) return undefined;
|
|
112
|
+
const win = doc.defaultView!.open(`about:blank#${connection.id}`, '_blank');
|
|
113
|
+
if (!win) throw new Error('Native overlay window unavailable');
|
|
114
|
+
connection.win = win;
|
|
115
|
+
// The requested blank page replaces the initial document created by window.open.
|
|
116
|
+
// WebKit percent-encodes the '#' marker in the popup URL; compare decoded.
|
|
117
|
+
// Adopt nodes only after that navigation; otherwise WebKit discards the relay.
|
|
118
|
+
if (decodeURIComponent(win.document.URL) !== `about:blank#${connection.id}` || win.document.readyState !== 'complete')
|
|
119
|
+
await bounded(new Promise<void>((resolve) => win.addEventListener('load', () => resolve(), { once: true })));
|
|
120
|
+
if (gone()) return undefined;
|
|
121
|
+
// about:blank is a quirks-mode document in WebKit. Initialize standards
|
|
122
|
+
// mode before adopting live content: otherwise percentage button heights
|
|
123
|
+
// can resolve against the entire popover viewport.
|
|
124
|
+
win.document.open();
|
|
125
|
+
win.document.write('<!doctype html><html><head></head><body></body></html>');
|
|
126
|
+
win.document.close();
|
|
127
|
+
connection.stopChildEvents = observe(win.document);
|
|
128
|
+
const environment = relayStyles(doc, win.document, overlay);
|
|
129
|
+
connection.stopStyles = environment.stop;
|
|
130
|
+
await bounded(environment.ready);
|
|
131
|
+
if (gone()) return undefined;
|
|
132
|
+
return { destination: environment.destination, win };
|
|
133
|
+
})();
|
|
134
|
+
// The staging join is awaited below; settle early rejections quietly.
|
|
135
|
+
staging.catch(() => {});
|
|
136
|
+
// Ionic initializes its gestures after didPresent. Let that turn finish before adopting their content.
|
|
137
|
+
// A stalled presentation must not park the opening queue forever.
|
|
138
|
+
await bounded(ready);
|
|
139
|
+
// Placement is captured after Ionic has laid out the overlay.
|
|
140
|
+
await bounded(new Promise<void>((resolve) => doc.defaultView!.requestAnimationFrame(() => resolve())));
|
|
141
|
+
const staged = await staging;
|
|
142
|
+
if (gone() || !staged) {
|
|
143
|
+
await release(connection);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const focused = activeElement(doc) as HTMLElement | null;
|
|
147
|
+
const nativePresentation = popoverPresentation(overlay);
|
|
148
|
+
const content = relayPopover(overlay, staged.destination);
|
|
149
|
+
connection.stopContent = content.stop;
|
|
150
|
+
connection.hideAnimation?.();
|
|
151
|
+
// Ionic does not dismiss a presented overlay when its page is hidden or
|
|
152
|
+
// destroyed; without this a popover could retain the page projections
|
|
153
|
+
// forever and freeze every later control update.
|
|
154
|
+
const exclusions = new MutationObserver(() => {
|
|
155
|
+
if (!overlay.isConnected || !nativeVerticalBars() || excluded(overlay) || isShellDisabled(content.root))
|
|
156
|
+
void release(connection).catch(console.error);
|
|
157
|
+
});
|
|
158
|
+
const attributes = { attributes: true, attributeFilter: ['class', 'data-shell', 'hidden', 'inert'] };
|
|
159
|
+
for (let node: HTMLElement | null = overlay; node; node = node.parentElement) {
|
|
160
|
+
exclusions.observe(node, attributes);
|
|
161
|
+
exclusions.observe(node, { childList: true });
|
|
162
|
+
}
|
|
163
|
+
exclusions.observe(content.root, { ...attributes, subtree: true });
|
|
164
|
+
connection.stopExclusions = () => exclusions.disconnect();
|
|
165
|
+
connection.stopFocus = trapFocus(
|
|
166
|
+
content.root,
|
|
167
|
+
() =>
|
|
168
|
+
!connection.dismissed &&
|
|
169
|
+
(!('focusTrap' in overlay) || overlay.focusTrap !== false) &&
|
|
170
|
+
!overlay.classList.contains('ion-disable-focus-trap'),
|
|
171
|
+
);
|
|
172
|
+
const close = () => {
|
|
173
|
+
void release(connection).catch(console.error);
|
|
174
|
+
};
|
|
175
|
+
const escape = (event: KeyboardEvent) => {
|
|
176
|
+
if (event.key === 'Escape' && overlay.backdropDismiss) void overlay.dismiss(undefined, 'backdrop');
|
|
177
|
+
};
|
|
178
|
+
staged.win.document.addEventListener('keydown', escape);
|
|
179
|
+
overlay.addEventListener(lifecycle(overlay, 'DidDismiss'), close, { once: true });
|
|
180
|
+
connection.stopEvents = () => {
|
|
181
|
+
staged.win.document.removeEventListener('keydown', escape);
|
|
182
|
+
overlay.removeEventListener(lifecycle(overlay, 'DidDismiss'), close);
|
|
183
|
+
};
|
|
184
|
+
// SwiftUI owns the only visible presentation animation.
|
|
185
|
+
await bounded(
|
|
186
|
+
plugin.presentOverlay({
|
|
187
|
+
id: connection.id,
|
|
188
|
+
presentation: { ...nativePresentation, animated: presentation.animated },
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
(focused?.isConnected && focused.ownerDocument === staged.win.document ? focused : content.root).focus({ preventScroll: true });
|
|
192
|
+
} catch (error) {
|
|
193
|
+
await release(connection);
|
|
194
|
+
console.error('Native overlay projection failed; keeping Ionic content in the source WebView.', error);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const present = (event: Event) => {
|
|
198
|
+
const overlay = event.target as Overlay;
|
|
199
|
+
if (current) {
|
|
200
|
+
const connection = current;
|
|
201
|
+
current = undefined;
|
|
202
|
+
opening = opening.then(() => release(connection)).catch(console.error);
|
|
203
|
+
if (!connection.dismissed) return;
|
|
204
|
+
// A didDismiss handler may immediately open the next popover while SwiftUI is still closing this one.
|
|
205
|
+
connection.stopAnimation?.();
|
|
206
|
+
connection.stopAnimation = undefined;
|
|
207
|
+
}
|
|
208
|
+
const enabled =
|
|
209
|
+
overlay.localName === 'ion-popover' &&
|
|
210
|
+
options.controls?.popover === true &&
|
|
211
|
+
nativeVerticalBars() &&
|
|
212
|
+
verticalBarsPopoverAnchor(overlay) !== undefined;
|
|
213
|
+
if (stopped || suspensions.size || !enabled || excluded(overlay)) {
|
|
214
|
+
opening = opening.then(restoreWeb).catch(console.error);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const connection: Connection = { id: `ios-theme-overlay-${++sequence}`, overlay, dismissed: false, focus: activeElement(doc) };
|
|
218
|
+
const presentation: Presentation = { kind: 'popover', animated: overlay.animated };
|
|
219
|
+
current = connection;
|
|
220
|
+
// Retain synchronously, before the scheduled projection update can retire the rail.
|
|
221
|
+
const anchorId = verticalBarsPopoverAnchor(overlay);
|
|
222
|
+
connection.releaseProjection = retainProjection(
|
|
223
|
+
(id) =>
|
|
224
|
+
id === anchorId &&
|
|
225
|
+
current === connection &&
|
|
226
|
+
!!connection.nativeClosing &&
|
|
227
|
+
!stopped &&
|
|
228
|
+
!suspensions.size &&
|
|
229
|
+
nativeVerticalBars() &&
|
|
230
|
+
!excluded(overlay),
|
|
231
|
+
);
|
|
232
|
+
const closed = () => {
|
|
233
|
+
connection.dismissed = true;
|
|
234
|
+
};
|
|
235
|
+
overlay.addEventListener(lifecycle(overlay, 'DidDismiss'), closed, { once: true });
|
|
236
|
+
let resolveReady!: () => void;
|
|
237
|
+
const readyPromise = new Promise<void>((resolve) => {
|
|
238
|
+
resolveReady = resolve;
|
|
239
|
+
});
|
|
240
|
+
const ready = () => {
|
|
241
|
+
resolveReady();
|
|
242
|
+
};
|
|
243
|
+
const closeNative = () =>
|
|
244
|
+
(connection.nativeClosing ??= bounded(plugin.dismissOverlay({ id: connection.id, animated: presentation.animated })));
|
|
245
|
+
const animation = nativeDialogAnimation(overlay, closeNative);
|
|
246
|
+
connection.stopAnimation = animation.stop;
|
|
247
|
+
connection.hideAnimation = animation.hide;
|
|
248
|
+
animation.hide();
|
|
249
|
+
overlay.addEventListener(lifecycle(overlay, 'DidPresent'), ready, { once: true });
|
|
250
|
+
connection.stopLifecycle = () => overlay.removeEventListener(lifecycle(overlay, 'DidDismiss'), closed);
|
|
251
|
+
opening = opening
|
|
252
|
+
.then(() => connect(connection, readyPromise, presentation))
|
|
253
|
+
.catch(console.error)
|
|
254
|
+
.finally(() => {
|
|
255
|
+
overlay.removeEventListener(lifecycle(overlay, 'DidPresent'), ready);
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const menuOpen = (event: Event) => {
|
|
259
|
+
if (!event.composedPath().some((node): node is HTMLElement => node instanceof HTMLElement && node.matches('ion-menu'))) return;
|
|
260
|
+
// Menus render in the source document below the native overlay; release the relay.
|
|
261
|
+
const connection = current;
|
|
262
|
+
current = undefined;
|
|
263
|
+
if (connection) opening = opening.then(() => release(connection)).catch(console.error);
|
|
264
|
+
};
|
|
265
|
+
const observe = (target: Document) => {
|
|
266
|
+
for (const name of events) target.addEventListener(name, present);
|
|
267
|
+
target.addEventListener('ionWillOpen', menuOpen);
|
|
268
|
+
return () => {
|
|
269
|
+
for (const name of events) target.removeEventListener(name, present);
|
|
270
|
+
target.removeEventListener('ionWillOpen', menuOpen);
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
const invalidate = () => {
|
|
274
|
+
const connection = current;
|
|
275
|
+
current = undefined;
|
|
276
|
+
if (connection) opening = opening.then(() => release(connection)).catch(console.error);
|
|
277
|
+
};
|
|
278
|
+
// Retention must not freeze an obsolete layout or a departed page.
|
|
279
|
+
const win = doc.defaultView!;
|
|
280
|
+
win.addEventListener('resize', invalidate);
|
|
281
|
+
doc.addEventListener('ionViewWillLeave', invalidate);
|
|
282
|
+
const visibility = () => {
|
|
283
|
+
if (doc.hidden) invalidate();
|
|
284
|
+
};
|
|
285
|
+
doc.addEventListener('visibilitychange', visibility);
|
|
286
|
+
const listener = await bounded(
|
|
287
|
+
plugin.addListener('overlay', (event) => {
|
|
288
|
+
if (event.id !== current?.id) return;
|
|
289
|
+
if (event.action === 'dismiss' && current.overlay.backdropDismiss)
|
|
290
|
+
void current.overlay.dismiss(undefined, 'backdrop').catch(console.error);
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
293
|
+
const stopEvents = observe(doc);
|
|
294
|
+
return {
|
|
295
|
+
async suspend() {
|
|
296
|
+
const lease = Symbol();
|
|
297
|
+
suspensions.add(lease);
|
|
298
|
+
await opening;
|
|
299
|
+
await restoreWeb();
|
|
300
|
+
return () => {
|
|
301
|
+
suspensions.delete(lease);
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
async destroy() {
|
|
305
|
+
stopped = true;
|
|
306
|
+
stopEvents();
|
|
307
|
+
win.removeEventListener('resize', invalidate);
|
|
308
|
+
doc.removeEventListener('ionViewWillLeave', invalidate);
|
|
309
|
+
doc.removeEventListener('visibilitychange', visibility);
|
|
310
|
+
try {
|
|
311
|
+
await opening;
|
|
312
|
+
await restoreWeb();
|
|
313
|
+
} finally {
|
|
314
|
+
try {
|
|
315
|
+
await bounded(plugin.stopOverlays());
|
|
316
|
+
} finally {
|
|
317
|
+
await listener.remove();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createAnimation } from '@ionic/core/components/index.js';
|
|
2
|
+
import { dismissAnimation } from './dismiss-animation';
|
|
3
|
+
|
|
4
|
+
export type Dialog = HTMLIonPopoverElement;
|
|
5
|
+
|
|
6
|
+
/** Hide the emptied source surface once the relay hosts the same live content. */
|
|
7
|
+
export const nativeDialogAnimation = (overlay: Dialog, close: () => Promise<void>) => {
|
|
8
|
+
const enterAnimation = overlay.enterAnimation;
|
|
9
|
+
overlay.enterAnimation = () => createAnimation();
|
|
10
|
+
const leaveAnimation = overlay.leaveAnimation;
|
|
11
|
+
const opacity = overlay.style.opacity;
|
|
12
|
+
const event = 'ionPopoverWillDismiss';
|
|
13
|
+
const dismiss = () => {
|
|
14
|
+
const closing = close();
|
|
15
|
+
overlay.leaveAnimation = () => dismissAnimation(closing);
|
|
16
|
+
};
|
|
17
|
+
overlay.addEventListener(event, dismiss);
|
|
18
|
+
return {
|
|
19
|
+
// Hide the source surface while the native presentation prepares.
|
|
20
|
+
hide() {
|
|
21
|
+
overlay.style.opacity = '0';
|
|
22
|
+
},
|
|
23
|
+
stop() {
|
|
24
|
+
overlay.removeEventListener(event, dismiss);
|
|
25
|
+
overlay.enterAnimation = enterAnimation;
|
|
26
|
+
overlay.leaveAnimation = leaveAnimation;
|
|
27
|
+
overlay.style.opacity = opacity;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createAnimation } from '@ionic/core/components/index.js';
|
|
2
|
+
|
|
3
|
+
/** Let Ionic finish dismissal after the native presentation has closed. */
|
|
4
|
+
export const dismissAnimation = (closing: Promise<void>) => {
|
|
5
|
+
const animation = createAnimation();
|
|
6
|
+
const play = animation.play;
|
|
7
|
+
animation.play = async (options) => {
|
|
8
|
+
// A native failure must not suppress Ionic's didDismiss event/data.
|
|
9
|
+
await closing.catch((error) => {
|
|
10
|
+
console.error('Native popover dismissal failed; completing the Ionic lifecycle.', error);
|
|
11
|
+
});
|
|
12
|
+
await play(options);
|
|
13
|
+
};
|
|
14
|
+
return animation;
|
|
15
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const activeElement = (doc: Document): Element | null => {
|
|
2
|
+
let element = doc.activeElement;
|
|
3
|
+
while (element?.shadowRoot?.activeElement) element = element.shadowRoot.activeElement;
|
|
4
|
+
return element;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const focusableElements = (root: HTMLElement): HTMLElement[] => {
|
|
8
|
+
const elements: HTMLElement[] = [];
|
|
9
|
+
const win = root.ownerDocument.defaultView!;
|
|
10
|
+
const collect = (scope: HTMLElement | ShadowRoot) => {
|
|
11
|
+
for (const node of Array.from(scope.querySelectorAll<HTMLElement>('*'))) {
|
|
12
|
+
if (node.inert || node.closest('[inert]') || (node as HTMLButtonElement).disabled) continue;
|
|
13
|
+
const before = elements.length;
|
|
14
|
+
if (node.shadowRoot) collect(node.shadowRoot);
|
|
15
|
+
const css = win.getComputedStyle(node);
|
|
16
|
+
if (
|
|
17
|
+
elements.length === before &&
|
|
18
|
+
node.tabIndex >= 0 &&
|
|
19
|
+
!node.hidden &&
|
|
20
|
+
css.display !== 'none' &&
|
|
21
|
+
css.visibility !== 'hidden' &&
|
|
22
|
+
node.getClientRects().length
|
|
23
|
+
)
|
|
24
|
+
elements.push(node);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
collect(root);
|
|
28
|
+
return elements
|
|
29
|
+
.map((element, index) => ({ element, index }))
|
|
30
|
+
.sort((a, b) => (a.element.tabIndex || Infinity) - (b.element.tabIndex || Infinity) || a.index - b.index)
|
|
31
|
+
.map(({ element }) => element);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const trapFocus = (root: HTMLElement, enabled: () => boolean): (() => void) => {
|
|
35
|
+
const doc = root.ownerDocument;
|
|
36
|
+
const previous = root.getAttribute('tabindex');
|
|
37
|
+
root.tabIndex = -1;
|
|
38
|
+
let last: Element | null;
|
|
39
|
+
const onFocus = (event: FocusEvent) => {
|
|
40
|
+
if (!enabled()) return;
|
|
41
|
+
if (event.composedPath().includes(root)) {
|
|
42
|
+
last = activeElement(doc);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const elements = focusableElements(root);
|
|
46
|
+
(elements.find((element) => element === last) ?? elements[0] ?? root).focus({ preventScroll: true });
|
|
47
|
+
};
|
|
48
|
+
const onKey = (event: KeyboardEvent) => {
|
|
49
|
+
if (event.key !== 'Tab' || event.altKey || event.ctrlKey || event.metaKey || !enabled()) return;
|
|
50
|
+
const elements = focusableElements(root);
|
|
51
|
+
const index = elements.findIndex((element) => element === activeElement(doc));
|
|
52
|
+
const next = event.shiftKey ? (index <= 0 ? elements.length - 1 : index - 1) : (index + 1) % elements.length;
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
(elements[next] ?? root).focus();
|
|
55
|
+
};
|
|
56
|
+
doc.addEventListener('focusin', onFocus, true);
|
|
57
|
+
doc.addEventListener('keydown', onKey, true);
|
|
58
|
+
return () => {
|
|
59
|
+
doc.removeEventListener('focusin', onFocus, true);
|
|
60
|
+
doc.removeEventListener('keydown', onKey, true);
|
|
61
|
+
if (previous === null) root.removeAttribute('tabindex');
|
|
62
|
+
else root.setAttribute('tabindex', previous);
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ShellPopoverPresentation } from '../definitions';
|
|
2
|
+
import { projectionIds } from '../shared/projection-id';
|
|
3
|
+
import { isDark } from '../shared/dom';
|
|
4
|
+
import { moveContent } from './content';
|
|
5
|
+
|
|
6
|
+
export const popoverTrigger = (overlay: HTMLIonPopoverElement): Element | undefined => {
|
|
7
|
+
const event = overlay.event as MouseEvent | undefined;
|
|
8
|
+
const target = (overlay.trigger ? overlay.ownerDocument.getElementById(overlay.trigger) : event?.target) as Element | undefined;
|
|
9
|
+
return target?.closest?.('ion-button,ion-fab-button,ion-item') ?? target;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Only accepted native rail buttons can retain the page projection. */
|
|
13
|
+
export const verticalBarsPopoverAnchor = (overlay: HTMLIonPopoverElement): string | undefined => {
|
|
14
|
+
const trigger = popoverTrigger(overlay);
|
|
15
|
+
if (
|
|
16
|
+
!trigger?.matches('ion-button[data-native-ui-shell-vertical-bars-member]') ||
|
|
17
|
+
!trigger.closest('[data-native-ui-shell]') ||
|
|
18
|
+
(trigger as HTMLIonButtonElement).disabled
|
|
19
|
+
)
|
|
20
|
+
return undefined;
|
|
21
|
+
return projectionIds.get(trigger);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const popoverPresentation = (overlay: HTMLIonPopoverElement): ShellPopoverPresentation => {
|
|
25
|
+
const content = overlay.shadowRoot!.querySelector<HTMLElement>('.popover-content')!;
|
|
26
|
+
const rect = content.getBoundingClientRect();
|
|
27
|
+
const anchorId = verticalBarsPopoverAnchor(overlay);
|
|
28
|
+
if (!anchorId) throw new Error('Native Vertical Bars anchor unavailable');
|
|
29
|
+
return {
|
|
30
|
+
kind: 'popover',
|
|
31
|
+
animated: overlay.animated,
|
|
32
|
+
dark: isDark(overlay.ownerDocument.defaultView!.getComputedStyle(overlay)),
|
|
33
|
+
anchorId,
|
|
34
|
+
width: rect.width,
|
|
35
|
+
height: rect.height,
|
|
36
|
+
backgroundColor: overlay.ownerDocument.defaultView!.getComputedStyle(content).backgroundColor,
|
|
37
|
+
backdropDismiss: overlay.backdropDismiss,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const relayPopover = (overlay: HTMLIonPopoverElement, destination: HTMLElement) => {
|
|
42
|
+
const doc = destination.ownerDocument;
|
|
43
|
+
const source = overlay.shadowRoot!.querySelector<HTMLElement>('.popover-content')!;
|
|
44
|
+
const root = doc.createElement('ion-popover');
|
|
45
|
+
for (const attribute of Array.from(overlay.attributes)) root.setAttribute(attribute.name, attribute.value);
|
|
46
|
+
Object.assign(root.style, {
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
inset: '0',
|
|
49
|
+
display: 'block',
|
|
50
|
+
visibility: 'visible',
|
|
51
|
+
opacity: '1',
|
|
52
|
+
pointerEvents: 'auto',
|
|
53
|
+
});
|
|
54
|
+
root.setAttribute('role', 'dialog');
|
|
55
|
+
root.setAttribute('aria-modal', 'true');
|
|
56
|
+
const shadow = root.attachShadow({ mode: 'open' });
|
|
57
|
+
const shell = doc.createElement('div');
|
|
58
|
+
const css = overlay.ownerDocument.defaultView!.getComputedStyle(source);
|
|
59
|
+
Object.assign(shell.style, { height: '100%', overflow: css.overflow, background: css.backgroundColor });
|
|
60
|
+
shell.append(doc.createElement('slot'));
|
|
61
|
+
shadow.append(shell);
|
|
62
|
+
destination.append(root);
|
|
63
|
+
// Components such as ion-select-popover dismiss their closest ion-popover.
|
|
64
|
+
root.dismiss = (...args) => overlay.dismiss(...args);
|
|
65
|
+
const restore = moveContent(Array.from(source.querySelector('slot')!.assignedElements()) as HTMLElement[], root);
|
|
66
|
+
const select = (event: MouseEvent) => {
|
|
67
|
+
if (!event.composedPath().includes(shell)) {
|
|
68
|
+
if (overlay.backdropDismiss) void overlay.dismiss(undefined, 'backdrop');
|
|
69
|
+
} else if (overlay.dismissOnSelect) void overlay.dismiss();
|
|
70
|
+
};
|
|
71
|
+
root.addEventListener('click', select);
|
|
72
|
+
return {
|
|
73
|
+
root,
|
|
74
|
+
stop() {
|
|
75
|
+
root.removeEventListener('click', select);
|
|
76
|
+
restore();
|
|
77
|
+
root.remove();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const sheetText = (sheets: readonly CSSStyleSheet[]): string =>
|
|
2
|
+
sheets.flatMap((sheet) => Array.from(sheet.cssRules, (rule) => rule.cssText)).join('\n');
|
|
3
|
+
|
|
4
|
+
export const relayStyles = (
|
|
5
|
+
source: Document,
|
|
6
|
+
destination: Document,
|
|
7
|
+
overlay: HTMLElement,
|
|
8
|
+
): { destination: HTMLElement; ready: Promise<void>; stop: () => void } => {
|
|
9
|
+
const base = destination.createElement('base');
|
|
10
|
+
base.href = source.baseURI;
|
|
11
|
+
destination.head.append(base);
|
|
12
|
+
const copies = new Map<Element, Element>();
|
|
13
|
+
const sheets = destination.createElement('style');
|
|
14
|
+
destination.head.append(sheets);
|
|
15
|
+
const sync = () => {
|
|
16
|
+
sheets.textContent = sheetText(source.adoptedStyleSheets);
|
|
17
|
+
const sources = Array.from(source.querySelectorAll('meta[name=viewport],link[rel=stylesheet],style:not([data-overlay-relay-local])'));
|
|
18
|
+
for (const [node, copy] of copies)
|
|
19
|
+
if (!sources.includes(node)) {
|
|
20
|
+
copy.remove();
|
|
21
|
+
copies.delete(node);
|
|
22
|
+
}
|
|
23
|
+
for (const node of sources) {
|
|
24
|
+
let copy = copies.get(node);
|
|
25
|
+
if (!copy) {
|
|
26
|
+
copy = node.cloneNode(true) as Element;
|
|
27
|
+
copies.set(node, copy);
|
|
28
|
+
} else {
|
|
29
|
+
for (const attribute of Array.from(copy.attributes)) copy.removeAttribute(attribute.name);
|
|
30
|
+
for (const attribute of Array.from(node.attributes)) copy.setAttribute(attribute.name, attribute.value);
|
|
31
|
+
copy.textContent = node.textContent;
|
|
32
|
+
}
|
|
33
|
+
destination.head.append(copy);
|
|
34
|
+
}
|
|
35
|
+
destination.head.append(surface);
|
|
36
|
+
};
|
|
37
|
+
const surface = destination.createElement('style');
|
|
38
|
+
surface.textContent = 'html,body{background:transparent!important}';
|
|
39
|
+
const observers: MutationObserver[] = [];
|
|
40
|
+
const mirror = (node: Element, target: HTMLElement, flatten = false) => {
|
|
41
|
+
const update = () => {
|
|
42
|
+
for (const attribute of Array.from(target.attributes)) if (!node.hasAttribute(attribute.name)) target.removeAttribute(attribute.name);
|
|
43
|
+
for (const attribute of Array.from(node.attributes)) target.setAttribute(attribute.name, attribute.value);
|
|
44
|
+
// The popover content must not inherit the source page's rail layout.
|
|
45
|
+
if (target.localName === 'ion-app') target.classList.remove('ios-theme-vertical-bars');
|
|
46
|
+
if (flatten) target.style.setProperty('display', 'contents', 'important');
|
|
47
|
+
};
|
|
48
|
+
update();
|
|
49
|
+
const observer = new MutationObserver(update);
|
|
50
|
+
observer.observe(node, { attributes: true });
|
|
51
|
+
observers.push(observer);
|
|
52
|
+
};
|
|
53
|
+
mirror(source.documentElement, destination.documentElement);
|
|
54
|
+
mirror(source.body, destination.body);
|
|
55
|
+
const ancestors: Element[] = [];
|
|
56
|
+
for (let node = overlay.parentElement; node && node !== source.body; node = node.parentElement) ancestors.unshift(node);
|
|
57
|
+
let parent = destination.body;
|
|
58
|
+
for (const node of ancestors) {
|
|
59
|
+
const shell = destination.createElement(node.localName);
|
|
60
|
+
mirror(node, shell, true);
|
|
61
|
+
parent.append(shell);
|
|
62
|
+
parent = shell;
|
|
63
|
+
}
|
|
64
|
+
sync();
|
|
65
|
+
// A copied external stylesheet can still be loading when Ionic's content is
|
|
66
|
+
// ready. Do not expose an unstyled first native frame (notably button sizes).
|
|
67
|
+
const ready = Promise.all(
|
|
68
|
+
Array.from(destination.querySelectorAll<HTMLLinkElement>('link[rel=stylesheet]'), (link) => {
|
|
69
|
+
if (link.sheet) return Promise.resolve();
|
|
70
|
+
return new Promise<void>((resolve, reject) => {
|
|
71
|
+
link.addEventListener('load', () => resolve(), { once: true });
|
|
72
|
+
link.addEventListener('error', () => reject(new Error('Popover stylesheet unavailable')), { once: true });
|
|
73
|
+
});
|
|
74
|
+
}),
|
|
75
|
+
).then(() => undefined);
|
|
76
|
+
const observer = new MutationObserver(sync);
|
|
77
|
+
observer.observe(source.head, { subtree: true, childList: true, characterData: true, attributes: true });
|
|
78
|
+
observers.push(observer);
|
|
79
|
+
return { destination: parent, ready, stop: () => observers.forEach((item) => item.disconnect()) };
|
|
80
|
+
};
|
package/src/native/prehide.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { modalUsesVerticalBars } from './shared/modal';
|
|
2
|
-
import { LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_ENTER, LIFECYCLE_WILL_LEAVE } from '@ionic/core';
|
|
2
|
+
import { LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_ENTER, LIFECYCLE_WILL_LEAVE } from '@ionic/core/components/index.js';
|
|
3
3
|
import { VERTICAL_BARS_TRANSITION_CANCELED } from '../native-integration';
|
|
4
4
|
import {
|
|
5
5
|
childElements,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
prehideRootClass,
|
|
17
17
|
rejectedClass,
|
|
18
18
|
setVerticalBarsPlacement,
|
|
19
|
+
syncToolbarText,
|
|
19
20
|
} from './shared/dom';
|
|
20
21
|
|
|
21
22
|
const overlays = 'ion-menu, ion-popover';
|
|
@@ -133,6 +134,7 @@ export const prehideVerticalBarsToolbarSources = (doc: Document): { suspend: ()
|
|
|
133
134
|
scopes.set(scope, owned);
|
|
134
135
|
};
|
|
135
136
|
const reconcile = () => {
|
|
137
|
+
syncToolbarText(doc);
|
|
136
138
|
const verticalBars = root();
|
|
137
139
|
if (!verticalBars) {
|
|
138
140
|
Array.from(scopes.keys()).forEach(release);
|
|
@@ -200,6 +202,8 @@ export const prehideVerticalBarsToolbarSources = (doc: Document): { suspend: ()
|
|
|
200
202
|
doc.defaultView?.addEventListener('nativeUIShellRefresh', reconcile, { signal: listeners.signal });
|
|
201
203
|
reconcile();
|
|
202
204
|
const mutationRelevant = (record: MutationRecord) => {
|
|
205
|
+
if (record.type === 'characterData') return record.target.parentElement?.matches('ion-toolbar') === true;
|
|
206
|
+
if (record.type === 'childList' && asElement(record.target)?.matches('ion-toolbar')) return true;
|
|
203
207
|
if (record.type === 'childList')
|
|
204
208
|
return [...Array.from(record.addedNodes), ...Array.from(record.removedNodes)].some(
|
|
205
209
|
(node) =>
|
|
@@ -228,6 +232,7 @@ export const prehideVerticalBarsToolbarSources = (doc: Document): { suspend: ()
|
|
|
228
232
|
observer.observe(doc.documentElement, {
|
|
229
233
|
subtree: true,
|
|
230
234
|
childList: true,
|
|
235
|
+
characterData: true,
|
|
231
236
|
attributes: true,
|
|
232
237
|
attributeOldValue: true,
|
|
233
238
|
attributeFilter: ['class', 'data-shell', 'hidden', 'inert', 'icon', 'color'],
|