@aryacode/dsh-aryacode-polish 0.8.2 → 0.9.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.
@@ -0,0 +1,51 @@
1
+ # Better workspace
2
+
3
+ Our own sidebar browser, mounted into `sidebar.workspaces` at `priority: -1` so it
4
+ shadows the shipped one while the switch is on, and steps aside the moment it is off.
5
+
6
+ ## Why a takeover instead of a menu item
7
+
8
+ A plugin can add a menu to any surface it renders itself, and it can extend a
9
+ Shell-rendered surface only through a slot that surface declares. The workspace row
10
+ declares none: its "..." menu is a closed two-item array and the row has no
11
+ `onContextMenu`. So the only sanctioned route to "right-click a workspace" is to
12
+ replace the region that draws it - this feature - and own that region's upkeep.
13
+
14
+ ## The two traps
15
+
16
+ **No `children` declaration.** A single-occupant seat renders its LOWEST priority
17
+ entry, which is why `priority: -1` shadows the shipped browser without touching it.
18
+ But declaring children is exclusive: the shipped registration already owns
19
+ `sidebar.workspaces.session.menu.item` and its siblings, so a second declaration
20
+ throws and the whole seat is dropped. This file reads the occupants off the slots
21
+ service (`slots.entries('sidebar.workspaces.session.menu.item')`) and renders them
22
+ by hand, reproducing exactly the two props the renderer would have synthesised:
23
+
24
+ - `t` - the occupant's own namespace bound through the locale face, so the shipped
25
+ labels stay translated;
26
+ - `useMenuOpenState` - the row's open-state pair, produced by the owner's declared
27
+ hook factory (`inject.hooks.menuOpenState(standard, hookContext)`).
28
+
29
+ Everything else on the occupant (Pin, Rename, Fork, Archive, Copy Session ID, and our
30
+ own "Open workspace folder") therefore keeps working untouched.
31
+
32
+ **Presence is the switch.** Because presence is what shadows the shipped browser, the
33
+ seat is registered and disposed with the `betterWorkspace` switch rather than
34
+ registered once and hidden. `installWorkspaceSeat` subscribes to the row's live
35
+ config form and adds/removes the registration each time the switch flips.
36
+
37
+ ## What M1 ships
38
+
39
+ - Workspace rows: caret, folder, title, session count; click to fold.
40
+ - Session rows underneath, newest first, click to open.
41
+ - Session "..." menu: the shipped occupant list rendered as above.
42
+ - Workspace right-click menu: Open in File Explorer, Copy path, Remove workspace
43
+ (two-click confirm).
44
+ - `docs/panel-screenshot.md`-style honesty: a broken third-party menu row is caught
45
+ by a boundary so the tree still renders.
46
+
47
+ ## What is not here yet
48
+
49
+ Drag and drop, reorder and pinned ordering, the "/" name grouping the reference
50
+ plugin offers, appearance options, and the same tree in the New Session picker. Those
51
+ are M2/M3; the seat is already the right place for them.
@@ -68,6 +68,12 @@ export const features = [
68
68
  defaultOn: true,
69
69
  mount: mountFolders,
70
70
  },
71
+ {
72
+ id: 'betterWorkspace',
73
+ label: 'Better workspace',
74
+ description: 'Replace the sidebar workspace list with our own tree, with a right-click menu on every workspace.',
75
+ defaultOn: true,
76
+ },
71
77
  {
72
78
  id: 'panelScreenshot',
73
79
  label: 'Right-panel screenshot',
package/lib/client.js CHANGED
@@ -43,11 +43,17 @@ window.__ModuleLoader__.load({
43
43
  "label": "Right-panel screenshot",
44
44
  "description": "Copy the open right panel into the chat as an image, and onto the clipboard.",
45
45
  "defaultOn": true
46
+ },
47
+ {
48
+ "key": "betterWorkspace",
49
+ "label": "Better workspace",
50
+ "description": "Replace the sidebar workspace list with our own tree: workspaces with their sessions, a right-click menu on a workspace (open, copy path, remove), and the shipped session menu inside it.",
51
+ "defaultOn": true
46
52
  }
47
53
  ]
48
54
  const ROW_ID = "polish"
49
55
  const ROW_KEY = "@aryacode/dsh-aryacode-polish" + '#' + ROW_ID
50
- const CLIENT_VERSION = "0.8.2"
56
+ const CLIENT_VERSION = "0.9.6"
51
57
 
52
58
  /* html2canvas 1.4.1 — MIT, vendored from vendor/html2canvas.min.js.
53
59
  * A UMD build, so it assigns itself to globalThis; face.js reads it lazily. */
@@ -193,6 +199,594 @@ window.__ModuleLoader__.load({
193
199
  clearTimeout(timer)
194
200
  }
195
201
  }
202
+ /**
203
+ * Better workspace - our own sidebar browser, registered into `sidebar.workspaces`
204
+ * at `priority: -1` so it shadows the shipped one while the switch is on.
205
+ *
206
+ * Two rules shape this file:
207
+ *
208
+ * 1. No `children` declaration. A child-hole declaration is exclusive: the shipped
209
+ * entry already owns `session.menu.item` and its siblings, so re-declaring them
210
+ * throws and the seat is silently dropped. We read the shipped occupants off the
211
+ * slots service instead and render them ourselves, reproducing the two props the
212
+ * renderer would have synthesised - `t` (bound to the occupant's own namespace)
213
+ * and `useMenuOpenState` (the row's open-state pair, through the owner's declared
214
+ * hook factory).
215
+ *
216
+ * 2. The stock browser has to come back the moment the switch goes off, so the seat
217
+ * is added and disposed with the switch rather than always registered.
218
+ */
219
+
220
+ /** Session rows read newest first, then by title, so the tree never reshuffles. */
221
+ function sessionRank(a, b) {
222
+ const left = a && a.updatedAt
223
+ const right = b && b.updatedAt
224
+ // Only a real timestamp may reorder: SessionSummary carries none in this Shell,
225
+ // and the Host's own list order is the display order.
226
+ if (typeof left === 'number' && typeof right === 'number' && left !== right) return right - left
227
+ return 0
228
+ }
229
+
230
+ /** Pair each workspace with the session summaries it owns, in display order. */
231
+ function workspaceRows(workspaces, sessions) {
232
+ const byId = new Map()
233
+ for (const session of sessions || []) {
234
+ if (session && session.id !== undefined) byId.set(String(session.id), session)
235
+ }
236
+ return (workspaces || []).map(workspace => ({
237
+ workspace,
238
+ sessions: (workspace && workspace.sessionIds ? workspace.sessionIds : [])
239
+ .map(id => byId.get(String(id)))
240
+ .filter(Boolean)
241
+ .sort(sessionRank),
242
+ }))
243
+ }
244
+
245
+ /** Snapshot of an observable source (`{ subscribe, getSnapshot }`) as React state. */
246
+ function useLive(source) {
247
+ const read = React.useCallback(() => {
248
+ try {
249
+ return source.getSnapshot()
250
+ } catch {
251
+ return undefined
252
+ }
253
+ }, [source])
254
+ const subscribe = React.useCallback(listener => {
255
+ try {
256
+ return source.subscribe(listener)
257
+ } catch {
258
+ return () => {}
259
+ }
260
+ }, [source])
261
+ return React.useSyncExternalStore(subscribe, read, read)
262
+ }
263
+
264
+ /**
265
+ * The shipped `sidebar.workspaces` registration, which is the only place the child
266
+ * menu declaration lives. Returns undefined before the shipped package has
267
+ * registered or after we shadow it away at a different priority.
268
+ */
269
+ function shippedBrowserEntry(slots) {
270
+ try {
271
+ const entries = slots.entries('sidebar.workspaces') || []
272
+ return entries.find(entry => entry && entry.options && !(Number(entry.options.priority) < 0)) || undefined
273
+ } catch {
274
+ return undefined
275
+ }
276
+ }
277
+
278
+ /** Everything a row menu needs to render the shipped occupant list faithfully. */
279
+ function menuRuntime(ctx, slots, standard) {
280
+ const owner = shippedBrowserEntry(slots)
281
+ const children = owner && owner.children ? owner.children : undefined
282
+ const spec = children ? children['sidebar.workspaces.session.menu.item'] : undefined
283
+ const hooks = spec && spec.inject ? spec.inject.hooks : undefined
284
+ let injected = {}
285
+ if (owner && typeof owner.inject === 'function') {
286
+ try {
287
+ injected = owner.inject(standard) || {}
288
+ } catch {
289
+ injected = {}
290
+ }
291
+ }
292
+ let locale
293
+ try {
294
+ locale = ctx.get('locale')
295
+ } catch {
296
+ locale = undefined
297
+ }
298
+ return {
299
+ hooks,
300
+ injected,
301
+ standard,
302
+ bindHook: (hookContext) => {
303
+ if (!hooks || typeof hooks.menuOpenState !== 'function') return () => hookContext
304
+ try {
305
+ return hooks.menuOpenState(standard, hookContext)
306
+ } catch {
307
+ return () => hookContext
308
+ }
309
+ },
310
+ /**
311
+ * The standard hooks the shipped rows call. The slot renderer synthesises them
312
+ * from the Shell's own sources; we derive the same answers from the snapshots we
313
+ * already subscribe to, so Pin/Rename/Fork/Archive render instead of throwing.
314
+ */
315
+ standards: (workspacesSnapshot) => {
316
+ const snapshot = workspacesSnapshot || {}
317
+ const pinned = new Set(snapshot.pinnedSessionIds || [])
318
+ const archived = new Set(snapshot.archivedSessionIds || [])
319
+ const shortcuts = hooks && hooks.shortcuts && typeof hooks.shortcuts.getSnapshot === 'function'
320
+ ? hooks.shortcuts.getSnapshot()
321
+ : []
322
+ return {
323
+ usePinned: selector => (selector ? selector(pinned) : pinned),
324
+ useArchived: selector => (selector ? selector(archived) : archived),
325
+ // Access is the Shell's answer to give; offering the row and letting the
326
+ // call fail is friendlier than hiding a menu that would have worked.
327
+ useSessionAccess: () => true,
328
+ useShortcuts: selector => (selector ? selector(shortcuts) : shortcuts),
329
+ }
330
+ },
331
+ injectFor: (entry, standard) => {
332
+ const own = entry && typeof entry.inject === 'function' ? entry.inject(standard) : undefined
333
+ return Object.assign({}, injected, own || {})
334
+ },
335
+ translate: (ns) => {
336
+ if (locale && typeof locale.bind === 'function') {
337
+ try {
338
+ return locale.bind(ns)
339
+ } catch {
340
+ return undefined
341
+ }
342
+ }
343
+ return undefined
344
+ },
345
+ }
346
+ }
347
+
348
+ /** One shipped occupant, mounted per row so it keeps its own state across renders. */
349
+ function ShippedMenuRow({ entry, session, runtime, workspacesSnapshot }) {
350
+ const menuOpenState = React.useState([false, () => {}])
351
+ const useMenuOpenState = React.useMemo(
352
+ () => runtime.bindHook(menuOpenState),
353
+ [runtime, menuOpenState],
354
+ )
355
+ const t = React.useMemo(() => runtime.translate(entry.locale), [runtime, entry.locale])
356
+ runtime.workspacesSnapshot = workspacesSnapshot
357
+ const props = Object.assign({}, session, runtime.injectFor(entry, runtime.standard), runtime.standards(runtime.workspacesSnapshot), { useMenuOpenState })
358
+ if (t !== undefined) props.t = t
359
+ return React.createElement(entry.component, props)
360
+ }
361
+
362
+ /**
363
+ * Keeps one broken third-party row from blanking the whole tree. Built lazily so
364
+ * this file stays importable from a plain Node test, where React is absent.
365
+ */
366
+ function rowBoundary() {
367
+ if (typeof React === 'undefined') {
368
+ return function Passthrough(props) {
369
+ return props.children
370
+ }
371
+ }
372
+ return class RowBoundary extends React.Component {
373
+ constructor(props) {
374
+ super(props)
375
+ this.state = { failed: false }
376
+ }
377
+
378
+ static getDerivedStateFromError() {
379
+ return { failed: true }
380
+ }
381
+
382
+ render() {
383
+ return this.state.failed ? null : this.props.children
384
+ }
385
+ }
386
+ }
387
+
388
+ /** Our own chrome for a row menu: the shipped occupants, in their declared order. */
389
+ function rowMenuEntries(slots) {
390
+ try {
391
+ return (slots.entries('sidebar.workspaces.session.menu.item') || [])
392
+ .slice()
393
+ .sort((a, b) => (Number(a.options && a.options.order) || 0) - (Number(b.options && b.options.order) || 0))
394
+ } catch {
395
+ return []
396
+ }
397
+ }
398
+
399
+ const WS_FONT = 'calc(var(--dsh-content-font-size-secondary, 13px) - 1px)'
400
+ const WS_ROW = {
401
+ display: 'flex',
402
+ alignItems: 'center',
403
+ gap: '6px',
404
+ boxSizing: 'border-box',
405
+ width: '100%',
406
+ height: '28px',
407
+ padding: '0 6px',
408
+ border: 'none',
409
+ borderRadius: 'var(--dsw-radius-sm, 6px)',
410
+ background: 'transparent',
411
+ color: 'var(--dsw-alias-label-secondary, #61666b)',
412
+ fontSize: WS_FONT,
413
+ font: 'inherit',
414
+ cursor: 'pointer',
415
+ textAlign: 'left',
416
+ whiteSpace: 'nowrap',
417
+ overflow: 'hidden',
418
+ }
419
+ const WS_TITLE = { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' }
420
+ const WS_COUNT = { flex: 'none', color: 'var(--dsw-alias-label-quaternary, #8a8a8a)', fontVariantNumeric: 'tabular-nums' }
421
+ const WS_MENU = {
422
+ position: 'fixed',
423
+ zIndex: 1200,
424
+ minWidth: '180px',
425
+ padding: '4px',
426
+ borderRadius: 'var(--dsw-radius-md, 8px)',
427
+ border: '0.5px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.12))',
428
+ backgroundColor: 'Canvas',
429
+ backgroundImage:
430
+ 'linear-gradient(var(--dsw-specific-menu, rgba(248,249,250,0.94)), var(--dsw-specific-menu, rgba(248,249,250,0.94)))',
431
+ boxShadow: 'var(--dsw-elevation-prominent, 0 3px 8px rgba(0,0,0,0.06))',
432
+ color: 'var(--dsw-alias-label-secondary, #61666b)',
433
+ fontSize: WS_FONT,
434
+ }
435
+ const WS_MENU_ITEM = {
436
+ display: 'flex',
437
+ alignItems: 'center',
438
+ gap: '8px',
439
+ boxSizing: 'border-box',
440
+ width: '100%',
441
+ height: '28px',
442
+ padding: '0 8px',
443
+ border: 'none',
444
+ borderRadius: 'var(--dsw-radius-sm, 6px)',
445
+ background: 'transparent',
446
+ color: 'inherit',
447
+ font: 'inherit',
448
+ cursor: 'pointer',
449
+ textAlign: 'left',
450
+ whiteSpace: 'nowrap',
451
+ }
452
+
453
+ function CaretGlyph({ open }) {
454
+ return React.createElement('svg', {
455
+ viewBox: '0 0 16 16',
456
+ width: 12,
457
+ height: 12,
458
+ fill: 'none',
459
+ stroke: 'currentColor',
460
+ strokeWidth: 1.4,
461
+ strokeLinecap: 'round',
462
+ strokeLinejoin: 'round',
463
+ 'aria-hidden': true,
464
+ style: { flex: 'none', transform: open ? 'rotate(90deg)' : 'none', transition: 'transform 120ms ease' },
465
+ }, React.createElement('path', { d: 'M6 3.5 10.5 8 6 12.5' }))
466
+ }
467
+
468
+ function FolderGlyph() {
469
+ return React.createElement('svg', {
470
+ viewBox: '0 0 16 16',
471
+ width: 14,
472
+ height: 14,
473
+ fill: 'none',
474
+ stroke: 'currentColor',
475
+ strokeWidth: 1.1,
476
+ strokeLinecap: 'round',
477
+ strokeLinejoin: 'round',
478
+ 'aria-hidden': true,
479
+ style: { flex: 'none' },
480
+ }, React.createElement('path', { d: 'M2 4.5h4l1.2 1.5H14v6.2a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1z' }))
481
+ }
482
+
483
+ function DotsGlyph() {
484
+ return React.createElement('svg', {
485
+ viewBox: '0 0 16 16',
486
+ width: 14,
487
+ height: 14,
488
+ fill: 'currentColor',
489
+ 'aria-hidden': true,
490
+ }, [3.5, 8, 12.5].map(x => React.createElement('circle', { key: x, cx: x, cy: 8, r: 1.1 })))
491
+ }
492
+
493
+ /** A small anchored menu; every row is the caller's, so the tree owns no policy. */
494
+ function RowMenu({ anchor, onClose, children }) {
495
+ const style = Object.assign({}, WS_MENU, {
496
+ top: Math.round(anchor.top),
497
+ left: Math.round(anchor.left),
498
+ })
499
+ React.useEffect(() => {
500
+ const close = event => {
501
+ if (event && event.type === 'keydown' && event.key !== 'Escape') return
502
+ onClose()
503
+ }
504
+ const pointer = event => {
505
+ if (event && event.target && event.target.closest && event.target.closest('[data-polish-ws-menu]')) return
506
+ onClose()
507
+ }
508
+ document.addEventListener('pointerdown', pointer, true)
509
+ document.addEventListener('keydown', close, true)
510
+ return () => {
511
+ document.removeEventListener('pointerdown', pointer, true)
512
+ document.removeEventListener('keydown', close, true)
513
+ }
514
+ }, [onClose])
515
+ return ReactDOM.createPortal(
516
+ React.createElement('div', { 'data-polish-ws-menu': 'row', style }, children),
517
+ document.body,
518
+ )
519
+ }
520
+
521
+ function workspaceLabel(workspace) {
522
+ const title = workspace && typeof workspace.title === 'string' ? workspace.title.trim() : ''
523
+ const id = String((workspace && workspace.workspaceId) || '')
524
+ // The Host sets the default workspace's title to its own id, so a title that
525
+ // merely repeats the id is not a name a reader wants to see.
526
+ if (title && title !== id) return title
527
+ const words = id.replace(/[-_]+/g, ' ').trim()
528
+ if (!words) return 'Workspace'
529
+ return words.charAt(0).toUpperCase() + words.slice(1)
530
+ }
531
+
532
+ function BetterWorkspace(props) {
533
+ const services = props.services || {}
534
+ const { ctx, slots } = services
535
+ const standard = { wide: props.wide === true, expandSidebar: props.expandSidebar }
536
+ const [expanded, setExpanded] = React.useState({})
537
+ const [menu, setMenu] = React.useState(null)
538
+ const [armed, setArmed] = React.useState(null)
539
+ const [adding, setAdding] = React.useState(false)
540
+ const [notice, setNotice] = React.useState('')
541
+
542
+ const workspaceState = useLive(services.workspacesLive)
543
+ const sessionState = useLive(services.sessionsLive)
544
+ const workspaceList = (workspaceState && (workspaceState.items || workspaceState.workspaces)) || []
545
+ const sessionList = sessionState && sessionState.ids && sessionState.byId
546
+ ? sessionState.ids.map(id => sessionState.byId[id]).filter(Boolean)
547
+ : (sessionState && (sessionState.items || sessionState.sessions)) || []
548
+ const rows = workspaceRows(workspaceList, sessionList)
549
+ const runtime = React.useMemo(() => menuRuntime(ctx, slots, standard), [ctx, slots, standard.wide])
550
+ const RowBoundary = React.useMemo(() => rowBoundary(), [])
551
+ const entries = React.useMemo(() => rowMenuEntries(slots), [slots, workspaceList.length, sessionList.length])
552
+
553
+ const openMenu = (event, row, workspace) => {
554
+ event.preventDefault()
555
+ event.stopPropagation()
556
+ setMenu({ kind: 'session', row, workspace, anchor: { top: event.clientY, left: event.clientX } })
557
+ }
558
+ const openWorkspaceMenu = (event, workspace) => {
559
+ event.preventDefault()
560
+ event.stopPropagation()
561
+ setArmed(null)
562
+ setMenu({ kind: 'workspace', workspace, anchor: { top: event.clientY, left: event.clientX } })
563
+ }
564
+
565
+ const closeMenu = React.useCallback(() => setMenu(null), [])
566
+
567
+ const workspaceMenu = menu && menu.kind === 'workspace'
568
+ ? React.createElement(RowMenu, { anchor: menu.anchor, onClose: closeMenu },
569
+ React.createElement('button', {
570
+ type: 'button',
571
+ style: WS_MENU_ITEM,
572
+ onClick: async () => {
573
+ closeMenu()
574
+ try {
575
+ await services.openFolder(menu.workspace.path)
576
+ } catch {}
577
+ },
578
+ }, 'Open in File Explorer'),
579
+ React.createElement('button', {
580
+ type: 'button',
581
+ style: WS_MENU_ITEM,
582
+ onClick: async () => {
583
+ closeMenu()
584
+ try {
585
+ await navigator.clipboard.writeText(menu.workspace.path)
586
+ } catch {}
587
+ },
588
+ }, 'Copy path'),
589
+ React.createElement('button', {
590
+ type: 'button',
591
+ style: Object.assign({}, WS_MENU_ITEM, { color: 'var(--dsw-alias-label-error, #d92d20)' }),
592
+ onClick: async () => {
593
+ const workspace = menu.workspace
594
+ if (!armed || armed !== workspace.workspaceId) {
595
+ setArmed(workspace.workspaceId)
596
+ setMenu(Object.assign({}, menu, { anchor: menu.anchor }))
597
+ return
598
+ }
599
+ closeMenu()
600
+ try {
601
+ await services.removeWorkspace(workspace.workspaceId)
602
+ } catch {}
603
+ },
604
+ }, armed && armed === menu.workspace.workspaceId ? 'Remove workspace?' : 'Remove workspace'),
605
+ )
606
+ : null
607
+
608
+ const sessionMenu = menu && menu.kind === 'session'
609
+ ? React.createElement(RowMenu, { anchor: menu.anchor, onClose: closeMenu },
610
+ entries.map((entry, index) => React.createElement(RowBoundary, { key: (entry.options && entry.options.id) || index },
611
+ React.createElement(ShippedMenuRow, {
612
+ entry,
613
+ runtime,
614
+ workspacesSnapshot: workspaceState,
615
+ session: { sessionId: menu.row.id, displayTitle: menu.row.displayTitle, session: menu.row },
616
+ }))),
617
+ )
618
+ : null
619
+
620
+ return React.createElement('div', {
621
+ 'data-polish-ws': 'tree',
622
+ style: {
623
+ display: 'flex',
624
+ flexDirection: 'column',
625
+ gap: '1px',
626
+ minHeight: 0,
627
+ height: '100%',
628
+ overflowY: 'auto',
629
+ overflowX: 'hidden',
630
+ padding: '2px 6px 12px',
631
+ },
632
+ },
633
+ React.createElement('div', { 'data-polish-ws': 'header', style: WS_HEADER },
634
+ React.createElement('span', { style: WS_HEADER_TITLE }, 'Workspaces'),
635
+ React.createElement('button', {
636
+ type: 'button',
637
+ 'data-polish-ws-add': 'true',
638
+ title: 'Add a workspace',
639
+ 'aria-label': 'Add a workspace',
640
+ style: WS_ADD,
641
+ onClick: () => { setAdding(true); setNotice('') },
642
+ }, '+')),
643
+ notice ? React.createElement('div', { 'data-polish-ws': 'notice', style: WS_NOTICE }, notice) : null,
644
+ adding && services.sourceFlow
645
+ ? React.createElement(services.sourceFlow, {
646
+ configForms: services.configForms(),
647
+ open: true,
648
+ onPicked: async (path) => {
649
+ if (!path) return
650
+ try {
651
+ await services.createWorkspace(path)
652
+ setAdding(false)
653
+ } catch (error) {
654
+ setNotice((error && error.message) || 'Could not add that folder.')
655
+ }
656
+ },
657
+ onCancel: () => setAdding(false),
658
+ onError: (message) => setNotice(message || 'Could not add that folder.'),
659
+ })
660
+ : null,
661
+ rows.length === 0
662
+ ? React.createElement('div', { style: { padding: '8px 6px', color: 'var(--dsw-alias-label-quaternary, #8a8a8a)' } }, 'No workspace yet.')
663
+ : rows.map(({ workspace, sessions }) => {
664
+ const open = expanded[workspace.workspaceId] !== false
665
+ return React.createElement('div', { key: workspace.workspaceId, style: { display: 'flex', flexDirection: 'column' } },
666
+ React.createElement('div', {
667
+ 'data-polish-ws-row': workspace.workspaceId,
668
+ style: Object.assign({}, WS_ROW, { fontWeight: 500 }),
669
+ onClick: () => setExpanded(prev => Object.assign({}, prev, { [workspace.workspaceId]: prev[workspace.workspaceId] === false })),
670
+ onContextMenu: event => openWorkspaceMenu(event, workspace),
671
+ },
672
+ React.createElement(CaretGlyph, { open }),
673
+ React.createElement(FolderGlyph),
674
+ React.createElement('span', { style: WS_TITLE, title: workspace.path || workspace.title }, workspaceLabel(workspace)),
675
+ React.createElement('span', { style: WS_COUNT }, String(sessions.length))),
676
+ open
677
+ ? sessions.map(row => React.createElement('div', {
678
+ key: row.id,
679
+ 'data-polish-ws-session': row.id,
680
+ style: Object.assign({}, WS_ROW, { paddingLeft: '24px' }),
681
+ onClick: () => services.openSession(row.id),
682
+ onContextMenu: event => openMenu(event, row, workspace),
683
+ },
684
+ React.createElement('span', { style: WS_TITLE }, row.displayTitle || row.id),
685
+ React.createElement('button', {
686
+ type: 'button',
687
+ 'aria-label': 'Session menu',
688
+ style: Object.assign({}, WS_MENU_ITEM, { width: '20px', height: '20px', padding: 0, justifyContent: 'center', flex: 'none' }),
689
+ onClick: event => openMenu(event, row, workspace),
690
+ }, React.createElement(DotsGlyph))))
691
+ : null)
692
+ }),
693
+ sessionMenu,
694
+ workspaceMenu)
695
+ }
696
+
697
+ /**
698
+ * Add and dispose the seat with the switch. A `single` slot renders its LOWEST
699
+ * priority occupant, so presence is the only way to stand aside: without this the
700
+ * stock browser would be shadowed even while the switch is off.
701
+ */
702
+ function installWorkspaceSeat(ctx, configForms, extras = {}) {
703
+ let dispose
704
+ let unlisten
705
+ const scope = () => {
706
+ try {
707
+ return configForms()
708
+ } catch {
709
+ return undefined
710
+ }
711
+ }
712
+ const readSwitch = () => {
713
+ const forms = scope()
714
+ if (!forms || typeof forms.get !== 'function') return true
715
+ const live = forms.get(ROW_ID)
716
+ if (!live || typeof live.getSnapshot !== 'function') return true
717
+ let snapshot
718
+ try {
719
+ snapshot = live.getSnapshot()
720
+ } catch {
721
+ return true
722
+ }
723
+ const value = snapshot && (snapshot.value || (snapshot.state && snapshot.state.value))
724
+ if (!value || typeof value !== 'object') return true
725
+ if (value.betterWorkspace === undefined) return true
726
+ return value.betterWorkspace === true || (value.betterWorkspace && value.betterWorkspace.get && value.betterWorkspace.get() === true)
727
+ }
728
+ const install = () => {
729
+ if (dispose !== undefined) return
730
+ try {
731
+ dispose = ctx.inject(
732
+ ['slots', 'sessions', 'workspaces', 'uiWorkspace', 'locale', 'remote', 'remote.session'],
733
+ (seated) => {
734
+ const services = {
735
+ ctx: seated,
736
+ configForms,
737
+ sourceFlow: extras.sourceFlow,
738
+ slots: seated.slots,
739
+ workspacesLive: seated.workspaces.list,
740
+ sessionsLive: seated.sessions.list,
741
+ openSession: (id) => seated.uiWorkspace.openSession(id),
742
+ createWorkspace: (path) => seated.workspaces.create({ path }),
743
+ removeWorkspace: (id) => seated.workspaces.delete(id),
744
+ openFolder: async (path) => {
745
+ const answer = await seated.remote.session.openWorkspacePath({ path })
746
+ if (answer && answer.ok === false) throw new Error('cannot open the folder')
747
+ },
748
+ }
749
+ seated.slots.inject('sidebar.workspaces', () => seated.slots.register({
750
+ name: 'sidebar.workspaces',
751
+ priority: -1,
752
+ inject: () => ({ services }),
753
+ }, BetterWorkspace))
754
+ },
755
+ )
756
+ } catch (error) {
757
+ console.warn('[aryacode-polish] better workspace seat skipped:', error && error.message)
758
+ dispose = undefined
759
+ }
760
+ }
761
+ const sync = () => {
762
+ if (readSwitch()) {
763
+ install()
764
+ return
765
+ }
766
+ if (typeof dispose === 'function') {
767
+ try {
768
+ dispose()
769
+ } catch {}
770
+ }
771
+ dispose = undefined
772
+ }
773
+ sync()
774
+ const forms = scope()
775
+ if (forms && typeof forms.get === 'function') {
776
+ const live = forms.get(ROW_ID)
777
+ if (live && typeof live.subscribe === 'function') {
778
+ unlisten = live.subscribe(() => sync())
779
+ }
780
+ }
781
+ return () => {
782
+ if (typeof unlisten === 'function') unlisten()
783
+ if (typeof dispose === 'function') dispose()
784
+ }
785
+ }
786
+ const WS_HEADER = { display: 'flex', alignItems: 'center', gap: '6px', padding: '2px 4px 4px' }
787
+ const WS_HEADER_TITLE = { flex: 1, minWidth: 0, fontSize: 'calc(' + "var(--dsh-content-font-size-secondary, 13px)" + ' - 2px)', letterSpacing: '0.02em', textTransform: 'uppercase', color: 'var(--dsw-alias-label-quaternary, #8a8a8a)' }
788
+ const WS_ADD = { flex: 'none', width: '20px', height: '20px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', padding: 0, border: 'none', background: 'transparent', color: 'var(--dsw-alias-label-tertiary)', fontSize: '15px', lineHeight: 1, borderRadius: 'var(--dsw-radius-sm)', cursor: 'pointer' }
789
+ const WS_NOTICE = { margin: '0 4px 6px', fontSize: 'calc(' + "var(--dsh-content-font-size-secondary, 13px)" + ' - 2px)', color: 'var(--dsw-alias-label-secondary)' }
196
790
 
197
791
  /**
198
792
  * AryaCode Polish — the browser face.
@@ -2045,6 +2639,9 @@ window.__ModuleLoader__.load({
2045
2639
  return undefined
2046
2640
  }
2047
2641
  }
2642
+ // The Better workspace seat shadows the shipped browser at a different priority,
2643
+ // so it must be present only while its switch is on.
2644
+ installWorkspaceSeat(ctx, configForms, { sourceFlow: WorkspaceSourceFlow })
2048
2645
  ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
2049
2646
  name: 'plugins.row.config',
2050
2647
  key: ROW_KEY,