@lincyaw/host 1.0.0-rc.126 → 1.0.0-rc.128

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/host",
3
- "version": "1.0.0-rc.126",
3
+ "version": "1.0.0-rc.128",
4
4
  "description": "Presmium's host interface for plugin components in every form: step state, services, interface text, and the design system (tokens, components, fonts)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -45,8 +45,8 @@
45
45
  "@radix-ui/react-tooltip": "^1.2.8",
46
46
  "react": "18.3.1",
47
47
  "react-dom": "18.3.1",
48
- "@lincyaw/kernel": "1.0.0-rc.126",
49
- "@lincyaw/design": "1.0.0-rc.126"
48
+ "@lincyaw/design": "1.0.0-rc.128",
49
+ "@lincyaw/kernel": "1.0.0-rc.128"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/react": "18.3.28",
package/src/contracts.ts CHANGED
@@ -138,10 +138,15 @@ export interface ProductionPlayback {
138
138
  }
139
139
  export const PRODUCTION_PLAYBACK = defineService<ProductionPlayback>('presmium.productionPlayback')
140
140
 
141
- /** A loaded timed-caption player owns presentation captions until its lease is released. */
141
+ /**
142
+ * A loaded timed-caption player owns presentation captions until its lease is released. `shown` tells whether it shows
143
+ * them (turned on, in a production preview, burned into an export): the slides keep room for them while it does.
144
+ */
142
145
  export interface TimedCaptions {
143
146
  readonly active: Store<boolean>
147
+ readonly shown: Store<boolean>
144
148
  claim(): Unsubscribe
149
+ show(on: boolean): void
145
150
  }
146
151
  export const TIMED_CAPTIONS = defineService<TimedCaptions>('presmium.timedCaptions')
147
152
 
package/src/index.ts CHANGED
@@ -76,6 +76,7 @@ export { PmToolbar } from './panels.ts'
76
76
  export { NAVIGATION, OPERATIONS, PAGE_READINESS, PLAYBACK_CONTROL, PRODUCTION_PLAYBACK, STATUS, STEP_CLOCK, SYNC_TRANSPORTS, TIMED_CAPTIONS, TOOLBAR } from './contracts.ts'
77
77
  export type { PageReadiness, TimedCaptions } from './contracts.ts'
78
78
  export { joinWindows } from './windows.ts'
79
+ export { useAudienceControl, useAudienceRemote } from './window-control.ts'
79
80
  export { setSiteBase, siteBase } from './site.ts'
80
81
  export type { WindowChannel } from './windows.ts'
81
82
  export type {
package/src/messages.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { zhSpaced } from '@lincyaw/kernel'
1
2
  import type { PluginStatus } from '@lincyaw/kernel/contracts'
2
3
  import type { Catalog } from './locale.ts'
3
4
 
@@ -31,7 +32,7 @@ export const HOST_MESSAGES: Catalog<HostMessages> = {
31
32
  status: { started: '已启动', degraded: '部分可用', disabled: '已禁用', failed: '启动失败' },
32
33
  because: ':',
33
34
  unnamedPlugin: '其他插件',
34
- componentError: (component, message) => `${component} 出错:${message}`,
35
+ componentError: (component, message) => zhSpaced`${component}出错:${message}`,
35
36
  problems: count => `${count} 个问题`,
36
37
  approvals: count => `待确认 ${count}`,
37
38
  approvalsTitle: '待确认的操作',
package/src/registries.ts CHANGED
@@ -6,12 +6,12 @@ import type { PageReadiness, StatusProvider, StatusRegistry, TimedCaptions, Tool
6
6
  import { createStore } from './store.ts'
7
7
 
8
8
  export function createTimedCaptions(): TimedCaptions {
9
- const owners = new Set<symbol>(), active = createStore(false)
10
- return { active, claim() {
9
+ const owners = new Set<symbol>(), active = createStore(false), shown = createStore(false)
10
+ return { active, shown, claim() {
11
11
  const owner = Symbol()
12
12
  owners.add(owner); active.set(true)
13
13
  return () => { if (owners.delete(owner)) active.set(owners.size > 0) }
14
- } }
14
+ }, show(on) { shown.set(on) } }
15
15
  }
16
16
 
17
17
  export function createPageReadiness(): PageReadiness {
@@ -0,0 +1,50 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react'
2
+ import { joinWindows } from './windows.ts'
3
+ import type { WindowChannel } from './windows.ts'
4
+
5
+ type Message = { state: unknown } | { command: string }
6
+
7
+ const isMessage = (value: unknown): value is Message => typeof value === 'object' && value !== null && ('state' in value || typeof (value as { command?: unknown }).command === 'string')
8
+
9
+ /**
10
+ * A control of the audience's window that another window of the same presentation drives (the presenter view): the
11
+ * audience tells the control's state (`undefined` while it offers none) through the windows' channel and runs the
12
+ * commands it receives. A window that joins later is told the current state.
13
+ */
14
+ export function useAudienceControl<S>(name: string, state: S | undefined, run: (command: string) => void): void {
15
+ const latest = useRef({ state, run })
16
+ latest.current = { state, run }
17
+ const channel = useRef<WindowChannel | undefined>(undefined)
18
+ useEffect(() => {
19
+ const windows = joinWindows(name, value => {
20
+ if (isMessage(value) && 'command' in value && latest.current.state !== undefined) latest.current.run(value.command)
21
+ }, () => ({ state: latest.current.state ?? null }))
22
+ channel.current = windows
23
+ return () => {
24
+ windows?.send({ state: null })
25
+ windows?.close()
26
+ channel.current = undefined
27
+ }
28
+ }, [name])
29
+ const shown = JSON.stringify(state ?? null)
30
+ useEffect(() => { channel.current?.send({ state: state ?? null }) }, [name, shown])
31
+ }
32
+
33
+ /** The other side of `useAudienceControl`: the state the audience tells, and the way to send it a command. */
34
+ export function useAudienceRemote<S>(name: string): [S | undefined, (command: string) => void] {
35
+ const [state, setState] = useState<S | undefined>(undefined)
36
+ const channel = useRef<WindowChannel | undefined>(undefined)
37
+ useEffect(() => {
38
+ const windows = joinWindows(name, value => {
39
+ if (isMessage(value) && 'state' in value) setState((value.state ?? undefined) as S | undefined)
40
+ }, () => undefined)
41
+ channel.current = windows
42
+ return () => {
43
+ windows?.close()
44
+ channel.current = undefined
45
+ setState(undefined)
46
+ }
47
+ }, [name])
48
+ const send = useCallback((command: string) => { channel.current?.send({ command }) }, [])
49
+ return [state, send]
50
+ }