Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 243 additions & 20 deletions packages/dsh-desktop-client-ui/client.js

Large diffs are not rendered by default.

356 changes: 275 additions & 81 deletions packages/dsh-desktop-office/client.js

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion scripts/verify-workspace-navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,44 @@ try {
appCases++
}
}
// The Square tabs and title share a center line while the native view changes width.
await view.webContents.loadURL('data:text/html,' + encodeURIComponent(\`<!doctype html>
<style>
body { margin:0; font:14px sans-serif; }
.square-tabs { box-sizing:border-box; display:flex; justify-content:center; padding:18px 12px 14px; }
.column { display:flex; justify-content:center; width:100%; max-width:1000px; }
[role=radiogroup] { display:grid; grid-auto-flow:column; grid-auto-columns:1fr; width:100%; max-width:fit-content; height:36px; }
[role=radio] { display:flex; align-items:center; justify-content:center; white-space:nowrap; padding:0 20px; }
[role=radio] span { min-width:0; overflow:hidden; text-overflow:ellipsis; }
h1 { text-align:center; }
</style>
<div id="root" class="dsh-web-chat">
<div class="square-tabs bg-blue-500/[0.05]"><div class="column"><div role="radiogroup">
<button role="radio"><span>Knowledge Space</span></button><button role="radio"><span>Subscriptions</span></button>
<button role="radio"><span>Apps</span></button><button role="radio"><span>Skill Center</span></button>
</div></div></div>
<h1>Explore Square</h1>
</div>\`))
await view.webContents.insertCSS(chatLayoutCss('darwin'))
await run('document.documentElement.dataset.dshPage = "square"')
let squareCases = 0
for (const [windowWidth, zoom] of [[900, 1], [1080, 1], [900, 1.25]]) {
view.webContents.setZoomFactor(zoom)
for (const sidebar of [280, 0, 420, 0]) {
const x = sidebar * zoom, y = 48 * zoom
view.setBounds({x, y, width:windowWidth-x, height:700-y})
await run(chatDialogViewportScript({x:sidebar,y:48,width:(windowWidth-x)/zoom,height:(700-y)/zoom,windowWidth:windowWidth/zoom,windowHeight:700/zoom,background:'#141416',followNativeView:true}))
await run('new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))')
const layout = await run(\`(() => {
const tabs = document.querySelector('[role=radiogroup]').getBoundingClientRect()
const title = document.querySelector('h1').getBoundingClientRect()
return {top:tabs.y, tabsCenter:tabs.x+tabs.width/2, titleCenter:title.x+title.width/2, width:tabs.width}
})()\`)
assert.ok(layout.width > 0 && Math.abs(layout.tabsCenter-layout.titleCenter) < 1, 'Square tabs align with the title')
assert.ok(Math.abs(layout.top*zoom+y-66*zoom) < 1, 'Square tabs keep their distance from the window top')
squareCases++
}
}
let cases = 0
for (const platform of ['win32','darwin']) {
await win.webContents.executeJavaScript('document.documentElement.dataset.platform = ' + JSON.stringify(platform))
Expand Down Expand Up @@ -125,7 +163,7 @@ try {
cases++
}
}
console.log(JSON.stringify({cases,appCases,hostPlatform:process.platform,electron:process.versions.electron,windowsAcceptance:process.platform==='win32'}))
console.log(JSON.stringify({cases,appCases,squareCases,hostPlatform:process.platform,electron:process.versions.electron,windowsAcceptance:process.platform==='win32'}))
view.webContents.close(); win.destroy(); app.exit(0)
}).catch(error=>{console.error(error);app.exit(1)})
`, resolveDir: root, loader: 'ts' }, outfile: entry, bundle: true, platform: 'node', format: 'cjs', external: ['electron'] })
Expand Down
72 changes: 72 additions & 0 deletions src/main/enterprise/chat-landing-geometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { EnterpriseChatLandingGeometry, EnterpriseChatPresentation } from '../../shared/enterprise-chat-view'
import { CHAT_MODEL_TRIGGER } from './chat-layout'

type Rect = EnterpriseChatPresentation['bounds']
type LandingElements = Omit<EnterpriseChatLandingGeometry, 'seat'>

/** Read the painted landing elements only after Chromium has applied the native seat resize. */
export function chatLandingGeometryScript(url: string, width: number, height: number): string {
return `(() => {
if (location.href !== ${JSON.stringify(url)} || location.pathname !== '/workspace/c/new') return;
if (Math.abs(innerWidth - ${width}) > 1 || Math.abs(innerHeight - ${height}) > 1) return null;
const landing = document.querySelector('.dsh-chat-surface .dsh-chat-landing');
const title = landing?.querySelector('.dsh-chat-headline');
const composer = landing?.querySelector('.dsh-chat-composer');
if (!landing || !title || !composer) return;
const clip = landing.getBoundingClientRect();
const read = element => {
const { x, y, width, height, right, bottom } = element.getBoundingClientRect();
if (x < clip.left - 1 || y < clip.top - 1 || right > clip.right + 1 || bottom > clip.bottom + 1) return;
return { x, y, width, height };
};
const trigger = composer.querySelector(${JSON.stringify(CHAT_MODEL_TRIGGER)});
const modelBounds = trigger && read(trigger);
// Read the selected display caption only when closed. Never read the searchable input's value.
const label = trigger?.getAttribute('data-state') === 'closed'
? trigger.querySelector('[data-label][aria-hidden="true"]')?.getAttribute('data-label') ?? trigger.firstElementChild?.textContent
: undefined;
const send = composer.querySelector('button.dsh-composer-send[data-testid="send-button"]');
const sendBounds = send && read(send);
return {
title: read(title), composer: read(composer),
model: label && modelBounds ? { label, width: modelBounds.width } : undefined,
sendOpacity: sendBounds?.width > 0 ? Number(getComputedStyle(send).opacity) : undefined
};
})()`
}

function parseRect(value: unknown, viewportWidth: number, viewportHeight: number): Rect | undefined {
if (!value || typeof value !== 'object') return
const { x, y, width, height } = value as Record<string, unknown>
if (typeof x !== 'number' || typeof y !== 'number' || typeof width !== 'number' || typeof height !== 'number' ||
![x, y, width, height].every(Number.isFinite) || x < -1 || y < -1 || width <= 0 || height <= 0 ||
x + width > viewportWidth + 1 || y + height > viewportHeight + 1) return
return { x, y, width, height }
}

function parseModel(value: unknown, composerWidth: number): LandingElements['model'] {
if (!value || typeof value !== 'object') return
const { label, width } = value as Record<string, unknown>
if (typeof label !== 'string' || label.length > 160 || typeof width !== 'number' ||
!Number.isFinite(width) || width <= 0 || width > composerWidth + 1) return
const normalized = label.replace(/\s+/gu, ' ').trim()
if (normalized && !/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/u.test(normalized)) {
return { label: normalized, width }
}
}

/** A remote document supplies advisory geometry and a plain-text caption for the morph. */
export function parseChatLandingGeometry(value: unknown, width: number, height: number): LandingElements | undefined {
if (!value || typeof value !== 'object') return
const input = value as Record<string, unknown>
const title = parseRect(input.title, width, height)
const composer = parseRect(input.composer, width, height)
if (!title || !composer) return
const model = parseModel(input.model, composer.width)
const opacity = input.sendOpacity
return {
title, composer,
...(model ? { model } : {}),
...(typeof opacity === 'number' && opacity >= 0 && opacity <= 1 ? { sendOpacity: opacity } : {})
}
}
34 changes: 34 additions & 0 deletions src/main/enterprise/chat-landing-text-motion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const FADE_OUT_MS = 78
const RESTORE_START_MS = 210
const RESTORE_END_MS = 310
const FADE_IN_DELAY_MS = 45
const FADE_IN_MS = 135

/** The isolated Chat document animates its own writing region without exporting any text. */
export function chatLandingTextMotionScript(url: string, phase: 'out' | 'in', revision: number, deadline: number): string {
return `(() => {
if (location.href !== ${JSON.stringify(url)} || location.pathname !== '/workspace/c/new' || Date.now() > ${deadline}) return;
const previous = window.__dshChatLandingTextMotion;
if (previous && previous.revision >= ${revision}) return;
previous?.animation?.cancel();
const motion = { revision: ${revision} };
window.__dshChatLandingTextMotion = motion;
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
const writing = document.querySelector('.dsh-chat-surface .dsh-chat-landing .dsh-chat-composer .dsh-composer-writing');
if (!writing || typeof writing.animate !== 'function') return;
const leaving = ${phase === 'out'};
const animation = leaving ? writing.animate([
{ opacity: 1, offset: 0, easing: 'ease-in' },
{ opacity: 0, offset: ${FADE_OUT_MS / RESTORE_END_MS} },
{ opacity: 0, offset: ${RESTORE_START_MS / RESTORE_END_MS}, easing: 'ease-out' },
{ opacity: 1, offset: 1 }
], { duration: ${RESTORE_END_MS} }) : writing.animate([
{ opacity: 0 }, { opacity: 1 }
], { duration: ${FADE_IN_MS}, delay: ${FADE_IN_DELAY_MS}, fill: 'backwards', easing: 'ease-out' });
motion.animation = animation;
const release = () => { if (window.__dshChatLandingTextMotion === motion) delete motion.animation; };
void animation.finished.then(release, release);
// Wait for the first fade, but let the track restore opacity on its own if the switch is interrupted.
if (leaving) return animation.ready.then(() => new Promise(resolve => setTimeout(resolve, ${FADE_OUT_MS})), release);
})()`
}
38 changes: 38 additions & 0 deletions src/main/enterprise/chat-layout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// The searchable Cascader puts the combobox role on its input; the compact one puts it on the shell.
export const CHAT_MODEL_TRIGGER = '.dsh-composer-trailing > [data-state]:is([role="combobox"], :has(input[role="combobox"]))'
const DESKTOP_MODEL_TRIGGER = `:root[data-bisheng-surface="desktop"] .dsh-chat-surface .dsh-composer-toolbar ${CHAT_MODEL_TRIGGER}`

/** Shared content layout for the isolated enterprise document. */
export const CHAT_LAYOUT_CSS = `
/* The cached Apps panel sits inside auto-height KeepAlive wrappers.
Expand All @@ -20,6 +24,40 @@ html[data-dsh-chat-viewport][data-dsh-page="apps"] .dsh-web-chat [data-workbench
.dsh-chat-surface .dsh-chat-header :is(button, a[href], input, textarea, select, [role="button"], [role="link"], [tabindex], [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]) {
-webkit-app-region: no-drag;
}

/* Match the native Work model trigger while retaining the web Cascader's search and focus handling. */
${DESKTOP_MODEL_TRIGGER} {
box-sizing: border-box;
height: 28px;
min-height: 28px;
max-width: min(360px, 45cqw);
gap: 4px;
padding: 0 4px 0 8px;
border-radius: var(--dsw-radius-sm, 8px);
background: transparent;
color: var(--dsw-alias-label-secondary, rgb(var(--text-2)));
font-size: 13px;
font-weight: 400;
line-height: 20px;
}
${DESKTOP_MODEL_TRIGGER} input[role="combobox"] { font: inherit; }
${DESKTOP_MODEL_TRIGGER} > :last-child {
color: var(--dsw-alias-label-caption, rgb(var(--text-3)));
}
${DESKTOP_MODEL_TRIGGER} > :last-child > svg {
width: 16px;
height: 16px;
transition-duration: 120ms;
}
${DESKTOP_MODEL_TRIGGER}:hover:not([aria-disabled="true"], :has(input:disabled)) {
background: var(--dsw-alias-interactive-bg-hover, rgb(var(--fill-2)));
}
${DESKTOP_MODEL_TRIGGER}:is(:focus-visible, :has(input:focus-visible)) {
box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary, rgb(var(--brand-500))));
}
${DESKTOP_MODEL_TRIGGER}:is([aria-disabled="true"], :has(input:disabled)) {
color: var(--dsw-alias-label-dimmed, rgb(var(--text-3)));
}
`

/** Windows owns dragging in its separate caption row; macOS uses the Chat header. */
Expand Down
4 changes: 3 additions & 1 deletion src/main/enterprise/chat-module-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ export function moduleThemePaletteCss(palette: EnterprisePalette): string {
return [
`html.dsh-host-dark:root{${body}}`,
`html.dsh-module-dark body[data-dsh-chat-theme] :is(${CHAT_LAYOUT_SCOPES}){${body}}`,
...(palette.composer ? [`html[data-dsh-host-theme=dark] body[data-dsh-chat-theme=dark] .dsh-web-chat{--dsh-composer-bg:${palette.composer.join(' ')}}`] : [])
...(palette.composer ? [`html[data-dsh-host-theme=dark] body[data-dsh-chat-theme=dark] .dsh-web-chat{--dsh-composer-bg:${palette.composer.join(' ')}}`] : []),
// The tab row and each Square banner share this upstream tint utility.
...(palette.squareBanner ? [`html[data-dsh-page="square"] .dsh-web-chat [class~="bg-blue-500/[0.05]"]{background-color:rgb(${palette.squareBanner.join(' ')})}`] : [])
].join('\n')
}

Expand Down
Loading
Loading