@lincyaw/workbench 0.2.0-rc.102 → 0.2.0-rc.104

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/workbench",
3
- "version": "0.2.0-rc.102",
3
+ "version": "0.2.0-rc.104",
4
4
  "description": "Presmium's workbench panels in React (the documents, a document edited on its rendered page with comments and version history) with the workspace service's client and the preview protocol's workbench side; @lincyaw/dsh places them in presmium studio (experimental)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -55,8 +55,8 @@
55
55
  "@tiptap/pm": "3.32.0",
56
56
  "katex": "0.18.10",
57
57
  "react-resizable-panels": "4.14.5",
58
- "@lincyaw/design": "1.0.0-rc.102",
59
- "@lincyaw/kernel": "1.0.0-rc.102"
58
+ "@lincyaw/kernel": "1.0.0-rc.104",
59
+ "@lincyaw/design": "1.0.0-rc.104"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "react": "^18.3.1",
@@ -67,6 +67,6 @@
67
67
  "@types/react-dom": "18.3.7",
68
68
  "react": "^18.3.1",
69
69
  "react-dom": "^18.3.1",
70
- "@lincyaw/compiler": "1.0.0-rc.102"
70
+ "@lincyaw/compiler": "1.0.0-rc.104"
71
71
  }
72
72
  }
@@ -10,7 +10,7 @@ import type { Locale } from '../messages.ts'
10
10
  import { PmIcon, PmIconButton, PmNotice, PmTooltip } from '../components.tsx'
11
11
  import { DOCUMENT_NODE_VIEWS, documentEditorSchema } from './schema.tsx'
12
12
  import type { DocumentEditorBlock, DocumentEditorInput, DocumentNodeViews, NativeDocumentEditor } from './schema.tsx'
13
- import { documentSelection } from './selection.ts'
13
+ import { documentSelection, nativeTextPoint } from './selection.ts'
14
14
  import type { NativeDocumentSelection } from './selection.ts'
15
15
  import { DOCUMENT_EDITOR_MESSAGES, IMAGE_IMPORT_MESSAGES, slashAliases } from './messages.ts'
16
16
  import { blockNoteDictionary } from './blocknote-messages.ts'
@@ -93,10 +93,20 @@ export interface BlockNoteSurfaceProps {
93
93
  children?: ReactNode
94
94
  }
95
95
 
96
+ /** Text comments require a text range; opaque blocks use their preview's place-comment entry. */
97
+ function DocumentAddCommentButton() {
98
+ const editor = useBlockNoteEditor(documentEditorSchema)
99
+ const selectedText = useEditorState({ editor, selector: ({ editor }) => {
100
+ const { selection } = editor.prosemirrorState
101
+ return !selection.empty && Boolean(nativeTextPoint(editor, selection.from) && nativeTextPoint(editor, selection.to))
102
+ } })
103
+ return selectedText ? <AddCommentButton /> : null
104
+ }
105
+
96
106
  function EditorToolbar(props: FormattingToolbarProps) {
97
107
  const editor = useBlockNoteEditor(documentEditorSchema)
98
108
  const title = useEditorState({ editor, selector: ({ editor }) => editor.getSelection()?.blocks.some(block => block.type === 'presmiumPage') ?? false })
99
- if (title) return <FormattingToolbar {...props}><AddCommentButton /></FormattingToolbar>
109
+ if (title) return <FormattingToolbar {...props}><DocumentAddCommentButton /></FormattingToolbar>
100
110
  return <FormattingToolbar {...props}>
101
111
  <BlockTypeSelect items={props.blockTypeSelectItems} />
102
112
  <BasicTextStyleButton basicTextStyle="bold" /><BasicTextStyleButton basicTextStyle="italic" />
@@ -104,7 +114,7 @@ function EditorToolbar(props: FormattingToolbarProps) {
104
114
  <TextAlignButton textAlignment="left" /><TextAlignButton textAlignment="center" /><TextAlignButton textAlignment="right" />
105
115
  <DocumentColorButton /><NestBlockButton /><UnnestBlockButton /><CreateLinkButton /><FormulaToolbarButton />
106
116
  <TableCellMergeButton />
107
- <AddCommentButton />
117
+ <DocumentAddCommentButton />
108
118
  </FormattingToolbar>
109
119
  }
110
120
 
@@ -116,7 +126,7 @@ function PlainContentComments({ editor }: { editor: NativeDocumentEditor }) {
116
126
  return plain
117
127
  } })
118
128
  // BlockNote hides formatting controls over code; its own comment action still applies.
119
- return show && editor.getExtension('comments') ? <div className="pm-document-editor__comment-tools"><FormattingToolbar><AddCommentButton /></FormattingToolbar></div> : null
129
+ return show && editor.getExtension('comments') ? <div className="pm-document-editor__comment-tools"><FormattingToolbar><DocumentAddCommentButton /></FormattingToolbar></div> : null
120
130
  }
121
131
 
122
132
  // Added items join the end of their group (formulas the one that holds tables, the animation request the one that holds
@@ -134,7 +134,7 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
134
134
  if (action.view === 'document') await controls.current.exitPresent(signal)
135
135
  else if (action.view === 'production') await controls.current.openProduction(signal)
136
136
  else await controls.current.compilePresentation(() => {
137
- workbench.setMode('viewing'); workbench.setWebView(action.view === 'presentation' ? 'present' : 'document')
137
+ workbench.setMode('viewing'); workbench.setWebView(action.view === 'presentation' ? 'present' : 'scrolly')
138
138
  controls.current.setWorkspace(action.view)
139
139
  }, action.view === 'reading', signal, deadline)
140
140
  }
@@ -218,7 +218,7 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
218
218
  </PmToolbar>}
219
219
  {!producing && !presenting && !reading && <DocumentToolbar narrow={narrow} presentButton={presentButton} framed={framed} onBack={onBack} actions={actions} aside={aside} navigation={navigation} changingView={changingView} onProduction={() => void openProduction()} onRead={() => void compilePresentation(() => {
220
220
  workbench.setMode('viewing')
221
- workbench.setWebView('document')
221
+ workbench.setWebView('scrolly')
222
222
  setWorkspace('reading')
223
223
  }, true)} onPresent={() => void compilePresentation(() => {
224
224
  workbench.setMode('viewing')
@@ -251,7 +251,7 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
251
251
  const documentId = useWorkbenchState(state => state.authoring?.content?.id)
252
252
  const reset = useWorkbenchState(state => state.authoring?.reset)
253
253
  const locale = useWorkbenchState(state => state.locale)
254
- const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView !== 'document')
254
+ const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView === 'present')
255
255
  const current = useWorkbenchState(state => state.position?.section)
256
256
  const editing = useWorkbenchState(state => state.mode === 'editing' && workbench.client.capabilities?.readOnly !== true)
257
257
  const creating = useWorkbenchState(state => Boolean(state.isCreatingPage))
@@ -332,7 +332,7 @@ function StatusBar() {
332
332
  const t = useMessages()
333
333
  const doc = useWorkbenchState(state => state.authoring?.content)
334
334
  const identity = useWorkbenchState(state => state.authoring?.identity)
335
- const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView !== 'document')
335
+ const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView === 'present')
336
336
  const section = useWorkbenchState(state => state.position?.section)
337
337
  const counter = useMemo(() => new DocumentWordCounter(), [])
338
338
  const words = useMemo(() => counter.count(doc, identity), [counter, doc, identity])
@@ -9,7 +9,7 @@ export type WorkbenchMode = 'editing' | 'viewing'
9
9
  * How the web form is shown: as a page or as its presentation, whose controls can play a configured lecture.
10
10
  * Both share one preview page and switch in place with `go.view`.
11
11
  */
12
- export type WebView = 'document' | 'present'
12
+ export type WebView = 'document' | 'scrolly' | 'present'
13
13
 
14
14
  /** A playback key pressed in a preview that the workbench plays: Space, and the left and right arrows. */
15
15
  export type PlaybackKey = 'play-pause' | 'previous' | 'next'
package/src/workbench.ts CHANGED
@@ -910,7 +910,7 @@ export class Workbench {
910
910
  ...source.member?.id && this.#componentPropertyDrafts.readable(source.identity, source.member.id) ? ['component-drafts.inspect' as const, 'component-drafts.read' as const] : [],
911
911
  ...clean && !state.isHistoryBusy && !state.isHistoryPreparing && source.member?.id && this.#componentPropertyDrafts.readable(source.identity, source.member.id) ? ['component-drafts.restore' as const, 'component-drafts.discard' as const] : [],
912
912
  ...this.#canPreparePresentation() ? ['preview.prepare' as const] : [],
913
- ...clean && (state.webView === 'document' || ready) ? ['position.step' as const] : [],
913
+ ...clean && (state.webView === 'document' || state.webView === 'scrolly' && preparedCurrent && this.#previewSinks.size === 1 && state.previewIrRevision === prepared.revision || ready) ? ['position.step' as const] : [],
914
914
  ...ready ? ['playback.play' as const, 'playback.rate' as const, ...plan?.timing === 'confirmed' ? ['playback.seek' as const] : []] : []], unsubmittedContent: 'not-inspected' }
915
915
  }
916
916
 
@@ -1019,8 +1019,16 @@ export class Workbench {
1019
1019
  await this.pausePlayback(); current()
1020
1020
  if (interaction !== this.#state.documentPositionToken) throw new Error('client-position-changed')
1021
1021
  const present = this.#state.webView === 'present'
1022
+ const reading = this.#state.webView === 'scrolly', connection = this.#state.previewConnection
1022
1023
  const result = await this.selectDocumentStep(action.sectionId, action.stepId)
1023
1024
  owned()
1025
+ if (reading) await this.waitForAuthoringClientState(() => {
1026
+ owned()
1027
+ if (this.#state.webView !== 'scrolly' || this.#state.previewConnection !== connection || this.#previewSinks.size !== 1) throw new Error('client-preview-unavailable')
1028
+ const state = this.authoringClientSnapshot(0)
1029
+ return this.#lastPosition !== undefined && state?.view === 'scrolly' && sameSource(state.source, expected)
1030
+ && state.position?.sectionId === action.sectionId && state.position.stepId === action.stepId
1031
+ }, signal)
1024
1032
  const state = this.authoringClientSnapshot(0)
1025
1033
  if (!state || !sameSource(state.source, expected) || state.position?.sectionId !== action.sectionId || state.position.stepId !== action.stepId
1026
1034
  || present && (!result || result.status !== 'ready' || result.position?.sectionId !== action.sectionId || result.position.stepId !== action.stepId || result.position.playing)) throw new Error('client-step-unverified')