mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): dock recovery as host-owned toolbar buttons
Add chrome.json slot mode "toolbar" with grouped and per-action recovery buttons, page-specific anchor candidates and sanitized toolbar style tokens. Keep the floating capsule as the bad-anchor fallback, hide the duplicate plugin launcher, and preserve legacy capsule slots. Document the full contract, add a minimal toolbar example package, and cover the new behavior in unit and browser tests.
This commit is contained in:
1 parent
9a12e2ee7b
commit
881354e283
33 files changed
+2016
-113
No files matched your search
@@ -28,8 +28,77 @@
|
||||
<!-- Trusted recovery entry. It lives in a closed shadow root and a manual
|
||||
popover, so no compiled skin selector can target it (shadow boundary)
|
||||
and no normal stacking context can cover it (top layer). It carries no
|
||||
`data-ws-part`: there is intentionally no skin hook for this control. -->
|
||||
`data-ws-part`: there is intentionally no skin hook for this control.
|
||||
|
||||
With an explicit `chrome.json` `mode: "toolbar"` the host paints plain
|
||||
host buttons instead of the capsule shell. The buttons are still owned,
|
||||
labelled, focusable and clickable by the host; the skin only supplies
|
||||
an anchor and style tokens. -->
|
||||
<Teleport v-if="layer" :to="layer.container">
|
||||
<!-- One grouped toolbar entry: both actions share an anchor. -->
|
||||
<div
|
||||
v-if="groupToolbarConfig"
|
||||
ref="groupToolbarElement"
|
||||
popover="manual"
|
||||
class="ws-host-toolbar"
|
||||
data-ws-host-recovery-toolbar
|
||||
role="group"
|
||||
:aria-label="copy.recovery"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
data-ws-recovery-action="built-in"
|
||||
:title="copy.shortcut"
|
||||
@click="useBuiltInSkin"
|
||||
>{{ copy.useBuiltIn }}</button>
|
||||
<button
|
||||
v-if="pluginLibraryAvailable"
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
data-ws-recovery-action="library"
|
||||
:title="copy.library"
|
||||
@click="openLibrary"
|
||||
>{{ copy.library }}</button>
|
||||
</div>
|
||||
|
||||
<!-- Per-action toolbar entries: each action has its own anchor. -->
|
||||
<div
|
||||
v-if="builtInToolbarConfig"
|
||||
ref="builtInToolbarElement"
|
||||
popover="manual"
|
||||
class="ws-host-toolbar"
|
||||
data-ws-host-recovery-toolbar
|
||||
role="group"
|
||||
:aria-label="copy.recovery"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
data-ws-recovery-action="built-in"
|
||||
:title="copy.shortcut"
|
||||
@click="useBuiltInSkin"
|
||||
>{{ copy.useBuiltIn }}</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="libraryToolbarConfig"
|
||||
ref="libraryToolbarElement"
|
||||
popover="manual"
|
||||
class="ws-host-toolbar"
|
||||
data-ws-host-recovery-toolbar
|
||||
role="group"
|
||||
:aria-label="copy.recovery"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
data-ws-recovery-action="library"
|
||||
:title="copy.library"
|
||||
@click="openLibrary"
|
||||
>{{ copy.library }}</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
ref="recoveryPopover"
|
||||
popover="manual"
|
||||
@@ -38,7 +107,7 @@
|
||||
@focusout="onRecoveryFocusOut"
|
||||
class="ws-host-recovery"
|
||||
:class="{ 'ws-host-recovery-compact': compact }"
|
||||
:data-ws-float="slotMode === 'slotted' ? undefined : floatPosition"
|
||||
:data-ws-float="capsuleSlotConfig && slotMode === 'slotted' ? undefined : floatPosition"
|
||||
:tabindex="compact || compactPinned ? 0 : undefined"
|
||||
data-ws-host-recovery
|
||||
role="region"
|
||||
@@ -46,6 +115,7 @@
|
||||
>
|
||||
<span class="ws-host-recovery-mark" aria-hidden="true">◈</span>
|
||||
<button
|
||||
v-if="capsuleActions.includes('built-in')"
|
||||
type="button"
|
||||
class="ws-host-recovery-action"
|
||||
data-ws-recovery-action="built-in"
|
||||
@@ -53,9 +123,9 @@
|
||||
@click="useBuiltInSkin"
|
||||
>{{ copy.useBuiltIn }}</button>
|
||||
<button
|
||||
v-if="capsuleActions.includes('library') && pluginLibraryAvailable"
|
||||
type="button"
|
||||
class="ws-host-recovery-action"
|
||||
v-if="pluginLibraryAvailable"
|
||||
data-ws-recovery-action="library"
|
||||
:title="copy.library"
|
||||
@click="openLibrary"
|
||||
@@ -65,8 +135,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, watchEffect, type Ref } from "vue";
|
||||
import type { SiteLanguage } from "../../../src/site-copy.js";
|
||||
import type { SkinChromeSlot } from "../../../src/shared/skin-chrome.js";
|
||||
import { hostChromeCopy } from "../i18n/host-chrome.js";
|
||||
import {
|
||||
activeHostSlot,
|
||||
@@ -77,6 +148,7 @@ import {
|
||||
isThirdPartySkinActive,
|
||||
openPluginLibrary,
|
||||
requestBuiltInSkin,
|
||||
setInlineLibraryEntryVisible,
|
||||
} from "../services/host-chrome.js";
|
||||
import {
|
||||
createHostOwnedLayer,
|
||||
@@ -96,6 +168,9 @@ import {
|
||||
bindHostControlTheme,
|
||||
findSkinRoot,
|
||||
} from "../services/host-control-tokens.js";
|
||||
import {
|
||||
resolveHostRecoveryPresentation,
|
||||
} from "../services/host-recovery-presentation.js";
|
||||
|
||||
const props = withDefaults(defineProps<{ language: SiteLanguage; connected?: boolean; pluginLibraryAvailable?: boolean }>(), { connected: false });
|
||||
const copy = computed(() => hostChromeCopy[props.language] ?? hostChromeCopy.en);
|
||||
@@ -164,8 +239,55 @@ const RECOVERY_LAYER_CSS = `
|
||||
min-height: var(--ws-control-hit, 28px);
|
||||
}
|
||||
.ws-host-recovery.ws-host-recovery-compact:focus-visible { outline: 2px solid var(--ws-control-accent, #4c8f88); outline-offset: 2px; }
|
||||
|
||||
/* Toolbar mode: no capsule shell, margin, border or fixed shadow. The wrapper
|
||||
only lays the host buttons out; every visible surface comes from the
|
||||
--ws-toolbar-* variables resolved from the skin's validated tokens. */
|
||||
.ws-host-toolbar {
|
||||
position: fixed;
|
||||
inset: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
max-width: calc(100vw - 8px);
|
||||
pointer-events: auto;
|
||||
}
|
||||
.ws-host-toolbar:popover-open { display: flex; }
|
||||
.ws-host-toolbar-action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
min-height: var(--ws-toolbar-min-height, var(--ws-control-hit, 28px));
|
||||
max-width: min(320px, calc(100vw - 8px));
|
||||
padding: var(--ws-toolbar-padding-y, 6px) var(--ws-toolbar-padding-x, 12px);
|
||||
border: 1px solid var(--ws-toolbar-border, #9db6b2);
|
||||
border-radius: var(--ws-toolbar-radius, 6px);
|
||||
background: var(--ws-toolbar-background, #fff);
|
||||
color: var(--ws-toolbar-foreground, #31524f);
|
||||
box-shadow: var(--ws-toolbar-shadow, none);
|
||||
font-family: var(--ws-toolbar-font, ui-sans-serif, system-ui, sans-serif);
|
||||
font-size: var(--ws-toolbar-font-size, 11px);
|
||||
line-height: 1.25;
|
||||
text-align: center;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
cursor: pointer;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
.ws-host-toolbar-action:hover { filter: brightness(.96); }
|
||||
.ws-host-toolbar-action:focus-visible {
|
||||
outline: 2px solid var(--ws-toolbar-focus, var(--ws-control-accent, #4c8f88));
|
||||
outline-offset: 2px;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ws-host-recovery, .ws-host-recovery button { transition: none !important; }
|
||||
.ws-host-recovery, .ws-host-recovery button, .ws-host-toolbar-action { transition: none !important; }
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -190,14 +312,32 @@ const showRecovery = computed(() => shouldShowRecovery({
|
||||
// already reset). It never renders decoration on its own.
|
||||
const shortcutOpen = ref(false);
|
||||
const recoveryPopover = ref<HTMLElement | null>(null);
|
||||
const groupToolbarElement = ref<HTMLElement | null>(null);
|
||||
const builtInToolbarElement = ref<HTMLElement | null>(null);
|
||||
const libraryToolbarElement = ref<HTMLElement | null>(null);
|
||||
|
||||
let slotBinding: HostSlotBinding | undefined;
|
||||
const recoveryVisible = computed(() => showRecovery.value || (shortcutOpen.value && thirdPartyAllowed.value));
|
||||
|
||||
/**
|
||||
* Theme the capsule even when the skin does not declare a slot. While a slot
|
||||
* binding exists it reads the anchor first and owns the tokens; this
|
||||
* root-level pass covers the slot-less capsule and refreshes itself when the
|
||||
* skin stylesheet arrives after the stored skin id.
|
||||
* Optional anchor from the active skin's chrome.json. Only third-party skins
|
||||
* can declare it; the host still owns the controls and the module falls back
|
||||
* to the default corner whenever an anchor stops being usable.
|
||||
*/
|
||||
const slotConfig = computed(() => activeHostSlot("host.recovery"));
|
||||
const builtInSlotConfig = computed(() => activeHostSlot("host.recovery.built-in"));
|
||||
const librarySlotConfig = computed(() => activeHostSlot("host.recovery.library"));
|
||||
const groupToolbarConfig = computed<SkinChromeSlot | undefined>(() => slotConfig.value?.mode === "toolbar" ? slotConfig.value : undefined);
|
||||
const capsuleSlotConfig = computed<SkinChromeSlot | undefined>(() => slotConfig.value?.mode === "toolbar" ? undefined : slotConfig.value);
|
||||
const builtInToolbarConfig = computed<SkinChromeSlot | undefined>(() => builtInSlotConfig.value?.mode === "toolbar" ? builtInSlotConfig.value : undefined);
|
||||
const libraryToolbarConfig = computed<SkinChromeSlot | undefined>(() => librarySlotConfig.value?.mode === "toolbar" ? librarySlotConfig.value : undefined);
|
||||
|
||||
/**
|
||||
* Theme the capsule even when the skin does not declare a slot. While a
|
||||
* capsule slot binding exists it reads the anchor first and owns the tokens;
|
||||
* this root-level pass covers the slot-less capsule and refreshes itself when
|
||||
* the skin stylesheet arrives after the stored skin id. Toolbar bindings keep
|
||||
* their own `--ws-toolbar-*` variables and do not disable this pass, so the
|
||||
* floating fallback keeps the capsule palette.
|
||||
*/
|
||||
const recoveryTheme = layer ? bindHostControlTheme({
|
||||
layer,
|
||||
@@ -205,19 +345,43 @@ const recoveryTheme = layer ? bindHostControlTheme({
|
||||
part: "host.recovery",
|
||||
defaults: RECOVERY_CONTROL_DEFAULTS,
|
||||
source: () => findSkinRoot(hostChromeActiveSkinId.value),
|
||||
// While a slot binding exists it owns the capsule tokens (anchor first).
|
||||
active: () => !slotBinding,
|
||||
active: () => !capsuleBinding,
|
||||
}) : null;
|
||||
|
||||
const recoveryVisible = computed(() => showRecovery.value || (shortcutOpen.value && thirdPartyAllowed.value));
|
||||
|
||||
/**
|
||||
* Optional anchor from the active skin's chrome.json. Only third-party skins
|
||||
* can declare it; the host still owns the capsule and the module falls back to
|
||||
* the default corner whenever the anchor stops being usable.
|
||||
*/
|
||||
const slotConfig = computed(() => activeHostSlot("host.recovery"));
|
||||
const slotMode = ref<"floating" | "slotted">("floating");
|
||||
const groupToolbarMode = ref<"floating" | "slotted">("floating");
|
||||
const builtInToolbarMode = ref<"floating" | "slotted">("floating");
|
||||
const libraryToolbarMode = ref<"floating" | "slotted">("floating");
|
||||
|
||||
const builtInActionState = computed(() => ({
|
||||
available: Boolean(groupToolbarConfig.value || builtInToolbarConfig.value),
|
||||
docked: groupToolbarConfig.value
|
||||
? groupToolbarMode.value === "slotted"
|
||||
: builtInToolbarMode.value === "slotted",
|
||||
}));
|
||||
const libraryActionState = computed(() => ({
|
||||
available: Boolean(props.pluginLibraryAvailable) && Boolean(groupToolbarConfig.value || libraryToolbarConfig.value),
|
||||
docked: groupToolbarConfig.value
|
||||
? groupToolbarMode.value === "slotted"
|
||||
: libraryToolbarMode.value === "slotted",
|
||||
}));
|
||||
|
||||
const presentation = computed(() => resolveHostRecoveryPresentation({
|
||||
visible: recoveryVisible.value,
|
||||
shortcutOpen: shortcutOpen.value,
|
||||
libraryAvailable: Boolean(props.pluginLibraryAvailable),
|
||||
builtIn: builtInActionState.value,
|
||||
library: libraryActionState.value,
|
||||
}));
|
||||
const capsuleActions = computed(() => presentation.value.capsuleActions);
|
||||
|
||||
// Exactly one application-library entry per page: the host toolbar button is
|
||||
// the library entry while a toolbar slot exists, so PluginPanel hides its
|
||||
// ordinary launcher (including while the capsule fallback shows the button).
|
||||
watchEffect(() => {
|
||||
setInlineLibraryEntryVisible(presentation.value.suppressLauncher);
|
||||
});
|
||||
|
||||
const compactHold = ref(true);
|
||||
let compactHoldTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
@@ -255,11 +419,15 @@ let floatingElement: HTMLElement | null = null;
|
||||
/** Sticky `:hover` after a tap on touch screens must not pause avoidance. */
|
||||
const canHover = () => typeof matchMedia === "function" && matchMedia("(hover: hover)").matches;
|
||||
|
||||
const compact = computed(() => !shortcutExpanded.value
|
||||
&& !compactPinned.value
|
||||
&& (slotMode.value === "slotted"
|
||||
? Boolean(slotConfig.value?.compact) && !compactHold.value
|
||||
: floatCompact.value));
|
||||
const compact = computed(() => {
|
||||
if (shortcutExpanded.value || compactPinned.value) return false;
|
||||
const config = capsuleSlotConfig.value;
|
||||
if (config) return Boolean(config.compact) && !compactHold.value;
|
||||
// A toolbar-mode capsule is the fallback entry, not the target look: never
|
||||
// fold it, otherwise a failed anchor could leave only a small mark.
|
||||
if (groupToolbarConfig.value || builtInToolbarConfig.value || libraryToolbarConfig.value) return false;
|
||||
return floatCompact.value;
|
||||
});
|
||||
|
||||
function onRecoveryEscape() {
|
||||
shortcutOpen.value = false;
|
||||
@@ -282,25 +450,93 @@ function onRecoveryFocusOut(event: FocusEvent) {
|
||||
compactPinned.value = false;
|
||||
}
|
||||
|
||||
function syncSlotBinding() {
|
||||
slotBinding?.dispose();
|
||||
slotBinding = undefined;
|
||||
// Disposing a slot clears its inline tokens; restore the root-level theme
|
||||
// before deciding whether a new anchor should override it.
|
||||
recoveryTheme?.apply();
|
||||
// A fresh binding starts floating and reports its first successful dock.
|
||||
slotMode.value = "floating";
|
||||
const control = recoveryPopover.value;
|
||||
const config = slotConfig.value;
|
||||
if (!control || !config || !layer) return;
|
||||
slotBinding = bindHostSlot({
|
||||
let capsuleBinding: HostSlotBinding | undefined;
|
||||
let toolbarBindings: HostSlotBinding[] = [];
|
||||
|
||||
function syncPopover() {
|
||||
syncRecoveryPopover(recoveryPopover.value, presentation.value.capsuleVisible);
|
||||
}
|
||||
|
||||
function syncToolbarPopovers() {
|
||||
const visible = presentation.value.toolbar.visible;
|
||||
syncRecoveryPopover(
|
||||
groupToolbarElement.value,
|
||||
Boolean(groupToolbarConfig.value) && visible && groupToolbarMode.value === "slotted",
|
||||
);
|
||||
syncRecoveryPopover(
|
||||
builtInToolbarElement.value,
|
||||
Boolean(builtInToolbarConfig.value) && visible && builtInToolbarMode.value === "slotted",
|
||||
);
|
||||
syncRecoveryPopover(
|
||||
libraryToolbarElement.value,
|
||||
Boolean(libraryToolbarConfig.value) && Boolean(props.pluginLibraryAvailable)
|
||||
&& visible && libraryToolbarMode.value === "slotted",
|
||||
);
|
||||
}
|
||||
|
||||
function bindToolbarEntry(
|
||||
control: HTMLElement | null,
|
||||
config: SkinChromeSlot | undefined,
|
||||
mode: Ref<"floating" | "slotted">,
|
||||
) {
|
||||
if (!layer || !control || !config) return;
|
||||
toolbarBindings.push(bindHostSlot({
|
||||
layer,
|
||||
control,
|
||||
anchor: config.anchor,
|
||||
skinId: hostChromeActiveSkinId.value,
|
||||
align: config.align,
|
||||
onModeChange: change => { slotMode.value = change.mode; },
|
||||
});
|
||||
presentation: "toolbar",
|
||||
// A floating toolbar is a closed popover (display:none). Show it for the
|
||||
// synchronous measurement/hit test and hide it again unless it docked.
|
||||
prepare: () => syncRecoveryPopover(control, true),
|
||||
settle: slotted => {
|
||||
if (!slotted || !presentation.value.toolbar.visible) syncRecoveryPopover(control, false);
|
||||
},
|
||||
onModeChange: change => {
|
||||
mode.value = change.mode;
|
||||
syncPopover();
|
||||
syncToolbarPopovers();
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
function syncSlotBindings() {
|
||||
capsuleBinding?.dispose();
|
||||
capsuleBinding = undefined;
|
||||
for (const binding of toolbarBindings) binding.dispose();
|
||||
toolbarBindings = [];
|
||||
// Disposing a slot clears its inline tokens; restore the root-level theme
|
||||
// before deciding whether a new anchor should override it.
|
||||
recoveryTheme?.apply();
|
||||
// A fresh binding starts floating and reports its first successful dock.
|
||||
slotMode.value = "floating";
|
||||
groupToolbarMode.value = "floating";
|
||||
builtInToolbarMode.value = "floating";
|
||||
libraryToolbarMode.value = "floating";
|
||||
const capsuleConfig = capsuleSlotConfig.value;
|
||||
if (recoveryPopover.value && capsuleConfig && layer) {
|
||||
capsuleBinding = bindHostSlot({
|
||||
layer,
|
||||
control: recoveryPopover.value,
|
||||
anchor: capsuleConfig.anchor,
|
||||
skinId: hostChromeActiveSkinId.value,
|
||||
align: capsuleConfig.align,
|
||||
onModeChange: change => { slotMode.value = change.mode; },
|
||||
});
|
||||
}
|
||||
bindToolbarEntry(groupToolbarElement.value, groupToolbarConfig.value, groupToolbarMode);
|
||||
bindToolbarEntry(builtInToolbarElement.value, builtInToolbarConfig.value, builtInToolbarMode);
|
||||
if (props.pluginLibraryAvailable) {
|
||||
bindToolbarEntry(libraryToolbarElement.value, libraryToolbarConfig.value, libraryToolbarMode);
|
||||
}
|
||||
syncPopover();
|
||||
syncToolbarPopovers();
|
||||
}
|
||||
|
||||
function revalidateBindings() {
|
||||
capsuleBinding?.revalidate();
|
||||
for (const binding of toolbarBindings) binding.revalidate();
|
||||
}
|
||||
|
||||
function bindFloating() {
|
||||
@@ -341,10 +577,6 @@ function bindFloating() {
|
||||
});
|
||||
}
|
||||
|
||||
function syncPopover() {
|
||||
syncRecoveryPopover(recoveryPopover.value, recoveryVisible.value);
|
||||
}
|
||||
|
||||
function useBuiltInSkin() {
|
||||
shortcutOpen.value = false;
|
||||
requestBuiltInSkin();
|
||||
@@ -364,8 +596,11 @@ function onKeydown(event: KeyboardEvent) {
|
||||
shortcutOpen.value = true;
|
||||
shortcutExpanded.value = true;
|
||||
void nextTick(() => {
|
||||
// The shortcut always brings back the complete capsule, even while a
|
||||
// toolbar anchor is healthy.
|
||||
syncPopover();
|
||||
slotBinding?.revalidate();
|
||||
syncToolbarPopovers();
|
||||
revalidateBindings();
|
||||
recoveryPopover.value?.querySelector("button")?.focus();
|
||||
});
|
||||
}
|
||||
@@ -376,30 +611,66 @@ function refreshLauncherReachability() {
|
||||
launcherReachable.value = isHostPartVisuallyReachable("host.plugins.launcher");
|
||||
}
|
||||
|
||||
watch([recoveryVisible, recoveryPopover], () => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
slotBinding?.revalidate();
|
||||
bindFloating();
|
||||
floatingAvoidance?.revalidate();
|
||||
});
|
||||
}, { flush: "post" });
|
||||
watch(
|
||||
[recoveryVisible, recoveryPopover, groupToolbarElement, builtInToolbarElement, libraryToolbarElement],
|
||||
() => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
syncToolbarPopovers();
|
||||
revalidateBindings();
|
||||
bindFloating();
|
||||
floatingAvoidance?.revalidate();
|
||||
});
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
watch([recoveryPopover, hostChromeActiveSkinId], () => {
|
||||
void nextTick(() => recoveryTheme?.apply());
|
||||
}, { flush: "post", immediate: true });
|
||||
watch([slotConfig, hostChromeActiveSkinId], () => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
syncSlotBinding();
|
||||
});
|
||||
}, { flush: "post" });
|
||||
watch(
|
||||
[
|
||||
slotConfig,
|
||||
builtInSlotConfig,
|
||||
librarySlotConfig,
|
||||
hostChromeActiveSkinId,
|
||||
groupToolbarElement,
|
||||
builtInToolbarElement,
|
||||
libraryToolbarElement,
|
||||
() => props.pluginLibraryAvailable,
|
||||
],
|
||||
() => {
|
||||
void nextTick(() => {
|
||||
syncSlotBindings();
|
||||
bindFloating();
|
||||
});
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
// Home <-> voice page and skin switches replace the controls the floating
|
||||
// capsule was avoiding; re-place it promptly (and back to its default corner
|
||||
// when that is free) instead of leaving it where the previous screen needed it.
|
||||
watch([() => props.connected, hostChromeActiveSkinId], () => {
|
||||
void nextTick(() => floatingAvoidance?.screenChanged());
|
||||
void nextTick(() => {
|
||||
revalidateBindings();
|
||||
floatingAvoidance?.screenChanged();
|
||||
});
|
||||
}, { flush: "post" });
|
||||
watch(thirdPartyAllowed, allowed => { if (!allowed) shortcutOpen.value = false; });
|
||||
// Opening or closing the shortcut changes which presentation is active; docked
|
||||
// toolbar buttons must hide while the complete capsule is summoned, and come
|
||||
// back (if their anchor is still valid) when it closes.
|
||||
watch(shortcutOpen, () => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
syncToolbarPopovers();
|
||||
revalidateBindings();
|
||||
});
|
||||
}, { flush: "post" });
|
||||
|
||||
// A page switch can mount a new `.ws-skin-root` with a different
|
||||
// `data-ws-page` without changing the skin id. Re-resolve the declared anchor
|
||||
// candidates promptly instead of waiting for the periodic safety check.
|
||||
let pageObserver: MutationObserver | undefined;
|
||||
|
||||
onMounted(() => {
|
||||
refreshLauncherReachability();
|
||||
@@ -407,16 +678,37 @@ onMounted(() => {
|
||||
window.addEventListener("resize", refreshLauncherReachability);
|
||||
window.addEventListener("keydown", onKeydown, true);
|
||||
window.addEventListener("pointerdown", onDocumentPointerDown, true);
|
||||
if (typeof MutationObserver === "function") {
|
||||
pageObserver = new MutationObserver(() => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
syncToolbarPopovers();
|
||||
revalidateBindings();
|
||||
floatingAvoidance?.screenChanged();
|
||||
});
|
||||
});
|
||||
pageObserver.observe(document.documentElement, {
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ["data-ws-page", "data-ws-skin"],
|
||||
});
|
||||
}
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
syncSlotBinding();
|
||||
syncSlotBindings();
|
||||
bindFloating();
|
||||
});
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
if (reachabilityTimer) clearInterval(reachabilityTimer);
|
||||
if (compactHoldTimer) clearTimeout(compactHoldTimer);
|
||||
slotBinding?.dispose();
|
||||
pageObserver?.disconnect();
|
||||
pageObserver = undefined;
|
||||
capsuleBinding?.dispose();
|
||||
capsuleBinding = undefined;
|
||||
for (const binding of toolbarBindings) binding.dispose();
|
||||
toolbarBindings = [];
|
||||
setInlineLibraryEntryVisible(false);
|
||||
floatingAvoidance?.dispose();
|
||||
floatingAvoidance = undefined;
|
||||
floatingElement = null;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<Teleport :to="toolbarTarget ?? 'body'">
|
||||
<div v-if="thirdPartyAllowed && connected && sessionToken" ref="toolbar" class="ws-plugin-toolbar" :class="{ 'ws-plugin-toolbar-fallback': !toolbarTarget }" :data-ws-float="toolbarTarget ? undefined : fallbackPosition" data-ws-part="voice.plugin-launcher" :data-presentation="presentation" :data-theme="theme" @keydown.esc="dismissDrawer">
|
||||
<button v-if="!isHostPartHidden('host.plugins.launcher')" ref="launcher" class="header-action ws-plugin-toolbar-trigger" data-ws-part="host.plugins.launcher" type="button" :title="tr('title')" :aria-label="tr('title')" :aria-expanded="presentation === 'dialog' ? visible : drawerOpen" :aria-controls="drawerOpen ? drawerId : undefined" @click="toggle">
|
||||
<button v-if="!isHostPartHidden('host.plugins.launcher') && !inlineLibraryEntry" ref="launcher" class="header-action ws-plugin-toolbar-trigger" data-ws-part="host.plugins.launcher" type="button" :title="tr('title')" :aria-label="tr('title')" :aria-expanded="presentation === 'dialog' ? visible : drawerOpen" :aria-controls="drawerOpen ? drawerId : undefined" @click="toggle">
|
||||
<svg viewBox="0 0 24 24" data-ws-icon-slot="host.plugins.launcher" aria-hidden="true"><path d="M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z" /></svg>
|
||||
<span v-if="presentation === 'drawer-side'">{{ tr('title') }}</span>
|
||||
</button>
|
||||
@@ -68,7 +68,7 @@ import { pluginTranslations, type PluginTextKey } from '../i18n/plugins.js';
|
||||
import { pluginWindowTranslations } from '../i18n/plugin-window.js';
|
||||
import type { SiteLanguage } from '../../../src/site-copy.js';
|
||||
import { thirdPartyAllowed } from '../services/instance-authorization.js';
|
||||
import { isHostPartHidden, isHostPartVisuallyReachable, pluginLibraryRequests } from '../services/host-chrome.js';
|
||||
import { isHostPartHidden, isHostPartVisuallyReachable, isInlineLibraryEntryVisible, pluginLibraryRequests } from '../services/host-chrome.js';
|
||||
import type { SkinPluginWidgetOptions } from '../../../src/shared/skin-plugin.js';
|
||||
import { bindFloatingAvoidance, type FloatingAvoidance, type FloatingPosition } from '../services/host-floating-placement.js';
|
||||
const props = defineProps<{ sessionToken: string; gatewayUrl: string; connected: boolean; language: SiteLanguage; toolbarTarget: HTMLElement | null; presentation: NonNullable<SkinPluginWidgetOptions['pluginPresentation']> }>();
|
||||
@@ -77,6 +77,9 @@ const ui = computed(() => pluginWindowTranslations[props.language]);
|
||||
const windowElement = ref<HTMLElement | null>(null), launcher = ref<HTMLButtonElement | null>(null), frame = ref<HTMLIFrameElement | null>(null);
|
||||
const available = shallowRef<AvailablePluginApp[]>([]), current = shallowRef<PluginAppLaunch | null>(null);
|
||||
const toolbar = ref<HTMLElement | null>(null);
|
||||
// A toolbar-mode recovery slot already renders the host-owned application
|
||||
// library button; do not render a second launcher on the same page.
|
||||
const inlineLibraryEntry = computed(() => isInlineLibraryEntryVisible());
|
||||
// The fallback toolbar floats in a viewport corner the skin knows nothing
|
||||
// about; move it off any skin control it would cover (runtime only).
|
||||
const fallbackPosition = ref<FloatingPosition>('bottom-right');
|
||||
|
||||
Reference in new issue
Block a user