@lincyaw/host 1.0.0-rc.116 → 1.0.0-rc.118

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.116",
3
+ "version": "1.0.0-rc.118",
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/design": "1.0.0-rc.116",
49
- "@lincyaw/kernel": "1.0.0-rc.116"
48
+ "@lincyaw/kernel": "1.0.0-rc.118",
49
+ "@lincyaw/design": "1.0.0-rc.118"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/react": "18.3.28",
package/src/approvals.ts CHANGED
@@ -8,5 +8,5 @@ export function PmApprovals({ placement = 'below' }: { placement?: 'below' | 'ab
8
8
  const t = useMessages(HOST_MESSAGES); const [open, setOpen] = useState(false); const [failed, setFailed] = useState<string>(); const pending = useStore(approvals.pending)
9
9
  if (!pending.length) return null
10
10
  const answer = (id: string, allow: boolean) => { setFailed(undefined); void approvals.answer(id, allow).catch(() => setFailed(t.answerFailed)) }
11
- return h(PmPopover, { open, label: t.approvalsTitle, name: 'pm-approvals', placement: placement === 'above' ? 'above-end' : 'below-end', onOpenChange: setOpen, trigger: h(PmButton, { variant: 'accent', small: true }, t.approvals(pending.length)) }, pending.map(({ id, request }) => h('div', { key: id, 'data-approval': id }, h('p', {}, request.title), h('p', {}, t.from(t.origins[request.from] ?? t.otherOrigin)), ...(request.detail ?? '').split('\n').filter(Boolean).map((line, key) => h('p', { key }, line)), h(PmButton, { small: true, variant: 'primary', onClick: () => answer(id, true) }, t.allow), h(PmButton, { small: true, onClick: () => answer(id, false) }, t.deny))), failed ? h(PmNotice, { tone: 'danger' }, failed) : null)
11
+ return h(PmPopover, { open, label: t.approvalsTitle, name: 'pm-approvals', placement: placement === 'above' ? 'above-end' : 'below-end', onOpenChange: setOpen, trigger: h(PmButton, { variant: 'primary', small: true }, t.approvals(pending.length)) }, pending.map(({ id, request }) => h('div', { key: id, 'data-approval': id }, h('p', {}, request.title), h('p', {}, t.from(t.origins[request.from] ?? t.otherOrigin)), ...(request.detail ?? '').split('\n').filter(Boolean).map((line, key) => h('p', { key }, line)), h(PmButton, { small: true, variant: 'primary', onClick: () => answer(id, true) }, t.allow), h(PmButton, { small: true, onClick: () => answer(id, false) }, t.deny))), failed ? h(PmNotice, { tone: 'danger' }, failed) : null)
12
12
  }
@@ -1,4 +1,4 @@
1
- import { createContext, createElement as h, forwardRef, useContext, useEffect, useId, useRef } from 'react'
1
+ import { createContext, createElement as h, forwardRef, useContext, useEffect, useId, useRef, useState } from 'react'
2
2
  import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode } from 'react'
3
3
  import * as Dialog from '@radix-ui/react-dialog'
4
4
  import * as Popover from '@radix-ui/react-popover'
@@ -9,7 +9,7 @@ import { HOST_MESSAGES } from '../messages.ts'
9
9
  import { ICONS } from '@lincyaw/design'
10
10
  import type { IconName } from '@lincyaw/design'
11
11
  import type { ToolbarPlacement } from '../contracts.ts'
12
- export type ButtonVariant = 'default' | 'primary' | 'accent' | 'ghost' | 'danger'
12
+ export type ButtonVariant = 'default' | 'primary' | 'ghost' | 'text' | 'danger'
13
13
  export type ControlDensity = 'compact' | 'regular' | 'touch'
14
14
  /** `overlay`: one large round control laid over media, such as the Play that starts a lecture the browser would not autoplay. */
15
15
  export type IconButtonVariant = 'default' | 'overlay'
@@ -28,9 +28,24 @@ export const PmButton = forwardRef<HTMLButtonElement, ButtonProps>(function PmBu
28
28
  icon || loading !== undefined ? h('span', { className: 'pm-ui-button__icon', 'aria-hidden': true }, loading ? h(PmIcon, { name: 'loading', className: 'pm-ui-loading' }) : icon ? h(PmIcon, { name: icon }) : null) : null,
29
29
  children))
30
30
  })
31
+ const TOOLTIP_DELAY = 500
32
+ const TOOLTIP_SKIP = 300
33
+ let tooltipClosedAt = 0
34
+ /** A pointer shows the tooltip after 500 ms, keyboard focus at once; within 300 ms of one closing the next opens at once. */
31
35
  export function PmTooltip({ label, shortcut, children }: { label: string, shortcut?: string, children: ReactNode }) {
32
- return h(Tooltip.Provider, { delayDuration: 300, skipDelayDuration: 0, children:
33
- h(Tooltip.Root, {}, h(Tooltip.Trigger, { asChild: true }, children), h(Tooltip.Portal, {},
36
+ const [open, setOpen] = useState(false)
37
+ const shown = useRef(false)
38
+ const pointer = useRef(false)
39
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
40
+ useEffect(() => () => clearTimeout(timer.current), [])
41
+ const change = (next: boolean) => {
42
+ clearTimeout(timer.current)
43
+ if (!next) { if (shown.current) tooltipClosedAt = Date.now(); shown.current = false; setOpen(false); return }
44
+ const wait = pointer.current && Date.now() - tooltipClosedAt > TOOLTIP_SKIP ? TOOLTIP_DELAY : 0
45
+ timer.current = setTimeout(() => { shown.current = true; setOpen(true) }, wait)
46
+ }
47
+ return h(Tooltip.Provider, { delayDuration: 0, skipDelayDuration: 0, children:
48
+ h(Tooltip.Root, { open, onOpenChange: change }, h(Tooltip.Trigger, { asChild: true, onPointerEnter: () => { pointer.current = true }, onPointerLeave: () => { pointer.current = false } }, children), h(Tooltip.Portal, {},
34
49
  h(Tooltip.Content, { className: 'pm-ui-tooltip pm-ui', side: 'top', sideOffset: 6, collisionPadding: 8 }, label, shortcut ? h('kbd', { className: 'pm-ui-shortcut' }, shortcut) : null))) })
35
50
  }
36
51
  export const PmIconButton = forwardRef<HTMLButtonElement, Omit<ButtonProps, 'variant'> & { variant?: IconButtonVariant, icon: IconName, label: string, hint?: string, shortcut?: string }>(function PmIconButton({ variant = 'default', icon, label, hint, shortcut, small, density = 'compact', loading, className, disabled, ...rest }, ref) {
@@ -112,7 +127,14 @@ export function PmTabs({ value, modelValue, tabs, label, children, onValueChange
112
127
  })), children)
113
128
  }
114
129
  export function PmTabPanel({ value, children, forceMount, hidden }: { value: string, children?: ReactNode, forceMount?: true, hidden?: boolean }) { return h(Tabs.Content, { value, forceMount, hidden, className: 'pm-ui-tab-panel' }, children) }
115
- export function PmNotice({ tone = 'neutral', children, className, ...rest }: HTMLAttributes<HTMLDivElement> & { tone?: Tone }) { return h('div', { ...rest, className: cls('pm-ui-notice', tone !== 'neutral' && `pm-ui-notice--${tone}`, className), role: tone === 'danger' ? 'alert' : 'status' }, children) }
130
+ const NOTICE_ICONS: Record<Tone, IconName> = { neutral: 'info', outline: 'info', accent: 'info', ok: 'check', warn: 'warning', danger: 'warning' }
131
+ /** A tone icon, the message, and an optional action at the end. */
132
+ export function PmNotice({ tone = 'neutral', action, children, className, ...rest }: HTMLAttributes<HTMLDivElement> & { tone?: Tone, action?: ReactNode }) {
133
+ return h('div', { ...rest, className: cls('pm-ui-notice', tone !== 'neutral' && `pm-ui-notice--${tone}`, className), role: tone === 'danger' ? 'alert' : 'status' },
134
+ h('span', { className: 'pm-ui-notice__icon' }, h(PmIcon, { name: NOTICE_ICONS[tone] })),
135
+ h('div', { className: 'pm-ui-notice__message' }, children),
136
+ action ? h('div', { className: 'pm-ui-notice__action' }, action) : null)
137
+ }
116
138
  export function PmEmpty({ title, icon, action, children }: { title?: string, icon?: IconName, action?: ReactNode, children?: ReactNode }) { return h('div', { className: 'pm-ui-empty' }, icon ? h(PmIcon, { name: icon }) : null, title ? h('p', { className: 'pm-ui-empty__title' }, title) : null, children, action) }
117
139
  /** Loading in the shape of the content: `document` headings and paragraphs, `list` rows, `preview` a slide-shaped area. */
118
140
  export function PmSkeleton({ label, shape = 'document' }: { label: string, shape?: 'document' | 'list' | 'preview' }) {