@lincyaw/workbench 0.0.0-stage → 0.2.0-rc.0
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/LICENSE +202 -0
- package/README.md +66 -2
- package/package.json +68 -3
- package/src/MediaClipEditor.tsx +122 -0
- package/src/StepProductionEditor.tsx +130 -0
- package/src/approvals.tsx +60 -0
- package/src/assistant-mascot.ts +62 -0
- package/src/audio-recording-messages.ts +44 -0
- package/src/audio-recording.ts +192 -0
- package/src/audio-wav.ts +25 -0
- package/src/audio-waveform.ts +110 -0
- package/src/audition.ts +84 -0
- package/src/authoring-client.ts +136 -0
- package/src/authoring-draft-fragment.ts +28 -0
- package/src/base-controls.tsx +47 -0
- package/src/caption-timing-drafts.ts +61 -0
- package/src/caption-timing-messages.ts +14 -0
- package/src/caption-timing.css +20 -0
- package/src/caption-timing.ts +14 -0
- package/src/component-draft-actions.ts +54 -0
- package/src/component-draft-inspection.ts +35 -0
- package/src/component-properties.css +24 -0
- package/src/component-properties.ts +45 -0
- package/src/component-property-drafts.ts +273 -0
- package/src/component-property-messages.ts +31 -0
- package/src/components.tsx +631 -0
- package/src/context.tsx +27 -0
- package/src/diagnostics.ts +113 -0
- package/src/document-draft-store.ts +179 -0
- package/src/document-drafts.ts +178 -0
- package/src/document-editor/BlockNoteSurface.tsx +209 -0
- package/src/document-editor/ComponentMaterials.tsx +62 -0
- package/src/document-editor/ComponentPropertiesDialog.tsx +282 -0
- package/src/document-editor/DocumentBlockFallback.tsx +31 -0
- package/src/document-editor/DocumentBlockPreview.tsx +239 -0
- package/src/document-editor/DocumentComments.tsx +282 -0
- package/src/document-editor/DocumentEditor.tsx +192 -0
- package/src/document-editor/DocumentStepNarration.tsx +93 -0
- package/src/document-editor/NarrationEditor.tsx +110 -0
- package/src/document-editor/NewCommentDrafts.tsx +224 -0
- package/src/document-editor/authoring.tsx +259 -0
- package/src/document-editor/block-playback.ts +90 -0
- package/src/document-editor/block-preview-messages.ts +13 -0
- package/src/document-editor/blocknote-messages.ts +98 -0
- package/src/document-editor/clipboard.ts +40 -0
- package/src/document-editor/colors.ts +57 -0
- package/src/document-editor/comment-draft-actions.ts +58 -0
- package/src/document-editor/comment-draft-inspection.ts +38 -0
- package/src/document-editor/comment-drafts.ts +361 -0
- package/src/document-editor/comments.ts +410 -0
- package/src/document-editor/file-input.ts +71 -0
- package/src/document-editor/focus.ts +54 -0
- package/src/document-editor/inline.ts +104 -0
- package/src/document-editor/math.tsx +63 -0
- package/src/document-editor/messages.ts +14 -0
- package/src/document-editor/narration-schema.tsx +85 -0
- package/src/document-editor/narration.ts +37 -0
- package/src/document-editor/popover.tsx +107 -0
- package/src/document-editor/projection.ts +423 -0
- package/src/document-editor/rich-text.ts +152 -0
- package/src/document-editor/schema.tsx +117 -0
- package/src/document-editor/selection.ts +152 -0
- package/src/document-editor/style.css +9 -0
- package/src/document-editor/styles.d.ts +1 -0
- package/src/document-editor/table-identities.ts +67 -0
- package/src/document-preview.ts +112 -0
- package/src/document-return-point.ts +59 -0
- package/src/document-session.ts +678 -0
- package/src/document-timing-drafts.ts +61 -0
- package/src/document-voices.ts +2 -0
- package/src/history.ts +167 -0
- package/src/index.ts +36 -0
- package/src/jobs.ts +111 -0
- package/src/mascot-preference.ts +37 -0
- package/src/media-drafts.ts +83 -0
- package/src/media-messages.ts +53 -0
- package/src/media-time.ts +12 -0
- package/src/messages.ts +781 -0
- package/src/outline.ts +97 -0
- package/src/panels/ChangeTrail.tsx +79 -0
- package/src/panels/DocumentNarrationPanel.tsx +27 -0
- package/src/panels/DocumentView.tsx +462 -0
- package/src/panels/DocumentVoiceDialog.tsx +179 -0
- package/src/panels/DocumentVoiceField.tsx +35 -0
- package/src/panels/ExportPanel.tsx +133 -0
- package/src/panels/HistoryPanel.tsx +88 -0
- package/src/panels/HomePanel.tsx +184 -0
- package/src/panels/PageDeleteDialog.tsx +33 -0
- package/src/panels/PageRenameDialog.tsx +27 -0
- package/src/panels/PreviewPanel.tsx +79 -0
- package/src/panels/ProductionCaptionTiming.tsx +122 -0
- package/src/panels/ProductionMediaClips.tsx +156 -0
- package/src/panels/ProductionPanel.tsx +272 -0
- package/src/panels/ProductionRecording.tsx +107 -0
- package/src/panels/ProductionRecordingRange.tsx +118 -0
- package/src/panels/ProductionTimeline.tsx +62 -0
- package/src/panels/ProductionTranscription.tsx +140 -0
- package/src/panels/SourceDocumentPanel.tsx +215 -0
- package/src/panels/SpeechSettingsPanel.tsx +64 -0
- package/src/panels/TranscriptionAdoption.tsx +147 -0
- package/src/panels/VoiceCloneDialog.tsx +152 -0
- package/src/panels/VoicePreviewDialog.tsx +74 -0
- package/src/panels/VoiceScopeField.tsx +30 -0
- package/src/panels/VoiceoverDialog.tsx +216 -0
- package/src/places.ts +102 -0
- package/src/preview-playback.ts +125 -0
- package/src/preview-pool.ts +320 -0
- package/src/preview.ts +110 -0
- package/src/production-messages.ts +151 -0
- package/src/production-playback.ts +109 -0
- package/src/production-voice-playback.ts +114 -0
- package/src/recording-adoption.ts +33 -0
- package/src/schema-form/PmSchemaForm.tsx +187 -0
- package/src/schema-form/context.ts +26 -0
- package/src/schema-form/fields.tsx +59 -0
- package/src/schema-form/templates.tsx +50 -0
- package/src/schema-form/validator.ts +36 -0
- package/src/schema-form/widgets.tsx +60 -0
- package/src/shortcuts.ts +8 -0
- package/src/sortable-list.tsx +201 -0
- package/src/speech-settings-messages.ts +40 -0
- package/src/step-production.css +5 -0
- package/src/step-production.ts +51 -0
- package/src/styles.css +1025 -0
- package/src/telemetry.ts +152 -0
- package/src/transcription-messages.ts +26 -0
- package/src/transcription-session.ts +159 -0
- package/src/use-recording-adoption.ts +84 -0
- package/src/voice-clone-messages.ts +92 -0
- package/src/voice-drafts.ts +89 -0
- package/src/voice-messages.ts +146 -0
- package/src/voice-snapshot.ts +55 -0
- package/src/voiceover-jobs.ts +87 -0
- package/src/workbench.ts +2328 -0
- package/src/workspace-client.ts +480 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lincyaw/workbench
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Presmium's workbench panels in React, for teachers who know no code. The panels are:
|
|
4
|
+
|
|
5
|
+
- the documents of a workspace, listed by title (made from a template, renamed, copied and deleted by title);
|
|
6
|
+
- a document shown as its readers see it (the web form or the slides, driven over Presmium's preview protocol), edited right on the page;
|
|
7
|
+
- the document's comments and its version history.
|
|
8
|
+
|
|
9
|
+
Under them, bound to no framework, are the client of the workspace service (`presmium serve`), the workbench's state, the mapping of an edit on the page back to the source, the preview protocol's workbench side, and the shared components of Presmium's design (`PmButton`, `PmDialog`, `PmMenu` and the others) in React. Experimental (0.x).
|
|
10
|
+
|
|
11
|
+
Part of [Presmium](https://github.com/Lincyaw/presmium), which compiles canonical lecture.json teaching documents into web pages, slides, Jupyter notebooks and narrated playback.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
`presmium studio` shows these panels in DeepSeek Harness's web client: `@lincyaw/dsh` bundles them into its client part and places them. They know nothing of the host they are drawn in. A layout gives them one `Workbench` and places them:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { DocumentView, HomePanel, Workbench, WorkbenchProvider, workspaceClient } from '@lincyaw/workbench'
|
|
19
|
+
import '@lincyaw/design/design.css'
|
|
20
|
+
import '@lincyaw/workbench/styles.css'
|
|
21
|
+
|
|
22
|
+
const workbench = new Workbench({ client: workspaceClient('api/presmium/'), locale: 'zh-CN' })
|
|
23
|
+
|
|
24
|
+
export function Centre({ open }: { open: boolean }) {
|
|
25
|
+
return <WorkbenchProvider workbench={workbench}>{open ? <DocumentView /> : <HomePanel />}</WorkbenchProvider>
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The page reaches the workspace service's routes under its own `api/presmium/` path; the host passes them on to the service. React 18 is a peer dependency. Dialogs and menus wrap Radix Primitives. Presmium maintains the visual tokens, the editing, the versions and the preview.
|
|
30
|
+
|
|
31
|
+
A host exposing a subset of the workspace service can set `client.capabilities` before constructing `Workbench`: `{ diagnostics: 'none', production: false, narration: false, export: false, readOnly: true }`. This disables diagnostic subscriptions and reports, hides the corresponding document controls, and makes the source session and canonical write requests read-only. Omitted fields preserve the local workspace's complete behavior. Hosts explain unavailable services in their own interface and enforce authorization on every server request. The optional third `workspaceClient` argument, `{ fetch }`, provides an instance-specific transport for authentication headers.
|
|
32
|
+
|
|
33
|
+
`client.capabilities.readOnly: true` also disables canonical document writes, including source transactions, asset imports, comments, page operations and history changes. The source actor and editor controls share this restriction; the service still checks the authenticated member on every request.
|
|
34
|
+
|
|
35
|
+
`DocumentView` keeps the document title, toolbar, editor and preview in one shared view. Its optional `onBack()` callback replaces the default return to the workspace's document list. `actions` places host controls, such as sharing, beside the document's own commands; hosts provide localized accessible names and use the public workbench controls.
|
|
36
|
+
|
|
37
|
+
`historyRevisionAction` adds an explicit host operation to the existing Version History rows. It uses the exported `HistoryRevisionAction` configuration: `label`, optional `icon`, `onSelect(revision)`, optional `disabled` (a boolean or a predicate of the revision), and optional `pendingRevision` (the opaque revision ID being processed). The standalone `HistoryPanel` accepts the same configuration as `revisionAction`. The host owns confirmation, source flushing, authorization, conflict checks and request recovery; it controls pending state while the shared panel disables its other history operations and pagination. Read-only clients cannot activate the action.
|
|
38
|
+
|
|
39
|
+
An absolute snapshot restore is separate from selective undo. A host that stores full snapshots can return `revertible: false` in its history rows and supply a clearly named restore action. Treat revision IDs as opaque references and resolve them on the server; do not reinterpret them in the browser or fetch another history list. Reuse the ordinary compilation and presentation flow, which checks the exact saved source, fingerprint and revision before showing a presentation.
|
|
40
|
+
|
|
41
|
+
## On the page
|
|
42
|
+
|
|
43
|
+
The document toolbar holds the navigation pane, Undo and Redo, whether the document is saved, Video production, Captions, Comments, Version History, Presentation preview and Export. Below 768 px, Video production, Captions and Version History move into a More menu. When the view owns its title (`framed` is false), Back and the title use their own row; Undo, Redo and Comments join the same More menu so the main commands fit within the available width. A framed view retains its existing single command row.
|
|
44
|
+
|
|
45
|
+
The names follow Microsoft Word's, in Chinese and English.
|
|
46
|
+
|
|
47
|
+
The document is one continuous editor: the author types in place and the change is saved after a short pause. Selecting text opens the formatting toolbar, which includes Add comment. Generated content (components and diagrams) shows its preview, not its source; authors change it through its properties or the AI assistant.
|
|
48
|
+
|
|
49
|
+
Every save is a version. Undo and Redo (Ctrl+Z, Ctrl+Y or Ctrl+Shift+Z) walk the versions, and Version History undoes any one of them.
|
|
50
|
+
|
|
51
|
+
The AI's turns become versions too. When the workspace asks to review them (`review: required`), the author accepts or rejects them first.
|
|
52
|
+
|
|
53
|
+
Comments are saved in the document with the text they point at. The Comments panel lists them; each can be replied to, reacted to, resolved and reopened.
|
|
54
|
+
|
|
55
|
+
Presentation preview shows the slides with the arrow keys and `Esc` working at once; `Esc` first closes an open menu or dialog, then leaves the presentation.
|
|
56
|
+
|
|
57
|
+
Operations that an outside AI tool asks to perform appear as Approvals in the app bar, where the author allows or denies them.
|
|
58
|
+
|
|
59
|
+
The workbench hands requests to the conversation through `workbench.onAgentRequest`; the host binds that to its agent session. Hosts route links to a document's source through `workbench.revealSource(path, line)`, which opens that document and outlines the block at the line.
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
- [Design of the workbench on DeepSeek Harness](https://github.com/Lincyaw/presmium/blob/main/docs/studio.md) (section 7)
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
Apache-2.0.
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workbench",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0-rc.0",
|
|
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
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Lincyaw/presmium.git",
|
|
9
|
+
"directory": "packages/workbench"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Lincyaw/presmium/tree/main/packages/workbench#readme",
|
|
12
|
+
"bugs": "https://github.com/Lincyaw/presmium/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"presmium",
|
|
15
|
+
"workbench",
|
|
16
|
+
"react"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.19"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./src/index.ts",
|
|
27
|
+
"./components": "./src/components.tsx",
|
|
28
|
+
"./styles.css": "./src/styles.css"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@blocknote/core": "0.56.0",
|
|
35
|
+
"@blocknote/mantine": "0.56.0",
|
|
36
|
+
"@blocknote/react": "0.56.0",
|
|
37
|
+
"@dnd-kit/dom": "0.5.1",
|
|
38
|
+
"@dnd-kit/react": "0.5.1",
|
|
39
|
+
"@floating-ui/react": "0.27.20",
|
|
40
|
+
"@mantine/core": "8.3.11",
|
|
41
|
+
"@mantine/hooks": "8.3.11",
|
|
42
|
+
"@radix-ui/react-dialog": "^1.3.1",
|
|
43
|
+
"@radix-ui/react-dropdown-menu": "^2.2.1",
|
|
44
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
45
|
+
"@radix-ui/react-radio-group": "^1.5.1",
|
|
46
|
+
"@radix-ui/react-tabs": "^1.2.1",
|
|
47
|
+
"@radix-ui/react-toolbar": "^1.2.1",
|
|
48
|
+
"@radix-ui/react-tooltip": "^1.4.1",
|
|
49
|
+
"@rjsf/core": "6.11.0",
|
|
50
|
+
"@rjsf/utils": "6.11.0",
|
|
51
|
+
"@rjsf/validator-ajv8": "6.11.0",
|
|
52
|
+
"@tiptap/core": "3.32.0",
|
|
53
|
+
"@tiptap/extension-file-handler": "3.32.0",
|
|
54
|
+
"@tiptap/pm": "3.32.0",
|
|
55
|
+
"katex": "0.18.10",
|
|
56
|
+
"react-resizable-panels": "4.14.5",
|
|
57
|
+
"@lincyaw/design": "1.0.0-rc.1",
|
|
58
|
+
"@lincyaw/kernel": "1.0.0-rc.1"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"react": "^18.3.1",
|
|
62
|
+
"react-dom": "^18.3.1"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/react": "18.3.28",
|
|
66
|
+
"@types/react-dom": "18.3.7",
|
|
67
|
+
"react": "^18.3.1",
|
|
68
|
+
"react-dom": "^18.3.1",
|
|
69
|
+
"@lincyaw/compiler": "1.0.0-rc.1"
|
|
70
|
+
}
|
|
6
71
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useId, useRef, useState } from 'react'
|
|
2
|
+
import type { MediaClip, ProductionAssetInspection } from '@lincyaw/kernel'
|
|
3
|
+
import { PmButton, PmField, PmInput, PmNotice, PmRange, PmSelect } from './components.tsx'
|
|
4
|
+
import type { ControlDensity } from './components.tsx'
|
|
5
|
+
import type { Locale } from './messages.ts'
|
|
6
|
+
import { MEDIA_MESSAGES } from './media-messages.ts'
|
|
7
|
+
import { mediaTime, mediaTimeValue as timeValue } from './media-time.ts'
|
|
8
|
+
export { mediaTime } from './media-time.ts'
|
|
9
|
+
|
|
10
|
+
/** Unaccepted input. Untouched fields keep their original numeric precision. */
|
|
11
|
+
export interface MediaClipDraft {
|
|
12
|
+
version: string
|
|
13
|
+
clip: MediaClip
|
|
14
|
+
baseClip?: MediaClip
|
|
15
|
+
startText?: string
|
|
16
|
+
endText?: string
|
|
17
|
+
offsetText?: string
|
|
18
|
+
}
|
|
19
|
+
export interface MediaClipAssetChoice { id: string, label: string }
|
|
20
|
+
export interface MediaClipEditorProps {
|
|
21
|
+
locale: Locale
|
|
22
|
+
density?: ControlDensity
|
|
23
|
+
assets: readonly MediaClipAssetChoice[]
|
|
24
|
+
clips: readonly MediaClip[]
|
|
25
|
+
selectedClipId?: string
|
|
26
|
+
draft: MediaClipDraft
|
|
27
|
+
inspection?: ProductionAssetInspection
|
|
28
|
+
stepDurationMs?: number
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
canApply?: boolean
|
|
31
|
+
loading?: boolean
|
|
32
|
+
busy?: 'import' | 'apply' | 'remove'
|
|
33
|
+
pending?: boolean
|
|
34
|
+
review?: boolean
|
|
35
|
+
storageFailed?: boolean
|
|
36
|
+
failure?: string
|
|
37
|
+
status?: string
|
|
38
|
+
retryImport?: boolean
|
|
39
|
+
onSelectClip(id: string | undefined): void
|
|
40
|
+
onSelectAsset(id: string): void
|
|
41
|
+
onChange(draft: MediaClipDraft): void
|
|
42
|
+
onImport(file: File): void
|
|
43
|
+
onRetryImport(): void
|
|
44
|
+
onRead(): void
|
|
45
|
+
onReview(): void
|
|
46
|
+
onApply(clip: MediaClip): void
|
|
47
|
+
onRemove(): void
|
|
48
|
+
onEditStart(): void
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function offsetValue(raw: string | undefined, original: number): number | undefined {
|
|
52
|
+
if (raw === undefined || raw === (original / 1000).toFixed(3)) return original
|
|
53
|
+
const text = raw.normalize('NFKC').trim(), value = Number(text) * 1000
|
|
54
|
+
return /^\d+(?:\.\d+)?$/.test(text) && Number.isFinite(value) ? value : undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Compose native public fields; only the caller can adopt a clip into the source. */
|
|
58
|
+
export function MediaClipEditor(props: MediaClipEditorProps) {
|
|
59
|
+
const { locale, density = 'compact', assets, clips, selectedClipId, draft, inspection, stepDurationMs, disabled, busy, loading, review } = props
|
|
60
|
+
const t = MEDIA_MESSAGES[locale], file = useRef<HTMLInputElement>(null), composing = useRef(new Set<string>()), [volumePreview, setVolumePreview] = useState<number>()
|
|
61
|
+
const formatId = useId(), rangeErrorId = useId(), clip = draft.clip
|
|
62
|
+
const startMs = timeValue(draft.startText, clip.sourceRange.startMs), endMs = timeValue(draft.endText, clip.sourceRange.endMs), offsetMs = offsetValue(draft.offsetText, clip.attachment.offsetMs)
|
|
63
|
+
const inspected = inspection?.assetId === clip.assetId ? inspection : undefined
|
|
64
|
+
const rangeInvalid = startMs !== undefined && endMs !== undefined && (startMs < 0 || endMs <= startMs || inspected !== undefined && endMs > inspected.durationMs)
|
|
65
|
+
const exceedsStep = stepDurationMs !== undefined && startMs !== undefined && endMs !== undefined && offsetMs !== undefined && offsetMs + endMs - startMs > stepDurationMs
|
|
66
|
+
const rangeError = rangeInvalid ? t.invalidRange : exceedsStep ? t.exceedsStep : undefined
|
|
67
|
+
const rangeDescription = `${formatId}${rangeError ? ` ${rangeErrorId}` : ''}`
|
|
68
|
+
const originalRemoved = Boolean(selectedClipId && !clips.some(clip => clip.id === selectedClipId))
|
|
69
|
+
const valid = Boolean(inspected && startMs !== undefined && endMs !== undefined && offsetMs !== undefined && !rangeInvalid && !exceedsStep && !originalRemoved)
|
|
70
|
+
const submit = () => {
|
|
71
|
+
if (disabled || busy || !props.canApply || review || !valid || composing.current.size) return
|
|
72
|
+
props.onApply({ ...clip, sourceRange: { startMs: startMs!, endMs: endMs! }, attachment: { ...clip.attachment, offsetMs: offsetMs! } })
|
|
73
|
+
}
|
|
74
|
+
const change = (patch: Partial<MediaClipDraft>) => props.onChange({ ...draft, ...patch })
|
|
75
|
+
const composition = (field: string) => ({ onCompositionStart: () => composing.current.add(field), onCompositionEnd: () => { composing.current.delete(field) } })
|
|
76
|
+
return <section className="pm-ui-media-clip-editor" aria-label={t.title} data-density={density} onFocusCapture={props.onEditStart} onPointerDownCapture={props.onEditStart}
|
|
77
|
+
onKeyDown={event => {
|
|
78
|
+
event.stopPropagation()
|
|
79
|
+
if (event.key === 'Enter' && event.target instanceof HTMLInputElement && event.target.type !== 'range' && !event.nativeEvent.isComposing && !composing.current.size) { event.preventDefault(); submit() }
|
|
80
|
+
}}>
|
|
81
|
+
<div className="pm-ui-media-clip-editor__heading"><h2>{t.title}</h2><PmButton density={density} loading={busy === 'import'} disabled={disabled || Boolean(busy)} onClick={() => file.current?.click()}>{t.import}</PmButton>
|
|
82
|
+
<input ref={file} type="file" hidden accept="audio/*,.wav,.ogg,.mp3,.m4a,.webm" onChange={event => { const selected = event.currentTarget.files?.[0]; event.currentTarget.value = ''; if (selected && !disabled && !busy) props.onImport(selected) }} />
|
|
83
|
+
</div>
|
|
84
|
+
<PmSelect label={t.asset} density={density} value={clip.assetId} disabled={disabled || Boolean(busy)} onChange={event => props.onSelectAsset(event.target.value)}>
|
|
85
|
+
<option value="">{t.chooseAsset}</option>{assets.map(asset => <option key={asset.id} value={asset.id}>{asset.label}</option>)}
|
|
86
|
+
{clip.assetId && !assets.some(asset => asset.id === clip.assetId) && <option value={clip.assetId}>{clip.assetId}</option>}
|
|
87
|
+
</PmSelect>
|
|
88
|
+
{clips.length > 0 || selectedClipId ? <PmSelect label={t.clip} density={density} value={selectedClipId ?? ''} disabled={disabled || Boolean(busy)} onChange={event => props.onSelectClip(event.target.value || undefined)}>
|
|
89
|
+
<option value="">{t.newClip}</option>{clips.map((clip, index) => <option key={clip.id} value={clip.id}>{t.clipLabel(index, assets.find(asset => asset.id === clip.assetId)?.label ?? clip.assetId)}</option>)}
|
|
90
|
+
{originalRemoved && <option value={selectedClipId}>{t.removed}</option>}
|
|
91
|
+
</PmSelect> : null}
|
|
92
|
+
{clip.assetId && <>
|
|
93
|
+
{loading ? <span className="pm-ui-field__hint" role="status">{t.loading}</span> : inspected && <output className="pm-ui-field__hint">{t.original(mediaTime(inspected.durationMs), valid ? mediaTime(endMs! - startMs!) : undefined)}</output>}
|
|
94
|
+
<div className="pm-ui-media-clip-editor__times">
|
|
95
|
+
<PmInput label={t.in} density={density} width="time" maxLength={32} value={draft.startText ?? mediaTime(clip.sourceRange.startMs)} aria-describedby={rangeDescription} aria-invalid={rangeInvalid || undefined}
|
|
96
|
+
readOnly={disabled || !inspected} error={startMs === undefined ? t.invalidTime : undefined} onChange={event => change({ startText: event.target.value })} {...composition('in')} />
|
|
97
|
+
<PmInput label={t.out} density={density} width="time" maxLength={32} value={draft.endText ?? mediaTime(clip.sourceRange.endMs)} aria-describedby={rangeDescription} aria-invalid={Boolean(rangeError) || undefined}
|
|
98
|
+
readOnly={disabled || !inspected} error={endMs === undefined ? t.invalidTime : undefined} onChange={event => change({ endText: event.target.value })} {...composition('out')} />
|
|
99
|
+
</div>
|
|
100
|
+
<span className="pm-ui-field__hint" id={formatId}>{t.timeFormat}</span>
|
|
101
|
+
{rangeError && <span id={rangeErrorId} className="pm-ui-field__error" role="alert">{rangeError}</span>}
|
|
102
|
+
<PmInput label={t.offset} density={density} width="number" inputMode="decimal" maxLength={32} value={draft.offsetText ?? (clip.attachment.offsetMs / 1000).toFixed(3)}
|
|
103
|
+
readOnly={disabled || !inspected} error={offsetMs === undefined ? t.invalidOffset : undefined} onChange={event => change({ offsetText: event.target.value })} {...composition('offset')} />
|
|
104
|
+
<PmField label={t.volume} density={density} group><div className="pm-ui-media-clip-editor__volume">
|
|
105
|
+
<PmRange label={t.volume} density={density} value={clip.volume * 100} max={100} disabled={disabled || !inspected} valueText={value => `${Math.round(value)}%`} onPreviewChange={setVolumePreview}
|
|
106
|
+
onValueCommit={value => change({ clip: { ...clip, volume: value / 100 } })} />
|
|
107
|
+
<output>{Math.round(volumePreview ?? clip.volume * 100)}%</output><PmButton density={density} aria-pressed={Boolean(clip.muted)} disabled={disabled || !inspected} onClick={() => change({ clip: { ...clip, muted: !clip.muted } })}>{clip.muted ? t.unmute : t.mute}</PmButton>
|
|
108
|
+
</div></PmField>
|
|
109
|
+
<div className="pm-ui-media-clip-editor__actions">
|
|
110
|
+
<PmButton density={density} variant="primary" loading={busy === 'apply'} disabled={disabled || Boolean(busy) || !props.canApply || review || !valid} onClick={submit}>{selectedClipId ? t.apply : t.add}</PmButton>
|
|
111
|
+
<PmButton density={density} disabled={disabled || !inspected} onClick={() => change({ clip: { ...clip, sourceRange: { startMs: 0, endMs: inspected!.durationMs } }, startText: undefined, endText: undefined })}>{t.restore}</PmButton>
|
|
112
|
+
{selectedClipId && <PmButton density={density} variant="danger" loading={busy === 'remove'} disabled={disabled || Boolean(busy) || originalRemoved} onClick={props.onRemove}>{t.remove}</PmButton>}
|
|
113
|
+
</div>
|
|
114
|
+
</>}
|
|
115
|
+
{originalRemoved ? <PmNotice tone="warn">{t.removed}</PmNotice> : review ? <PmNotice tone="warn"><span>{t.review}</span><PmButton density={density} disabled={disabled || Boolean(busy) || !props.canApply || !inspected} onClick={props.onReview}>{t.check}</PmButton></PmNotice>
|
|
116
|
+
: clip.assetId && !props.canApply && !busy && <span className="pm-ui-field__hint">{t.unavailable}</span>}
|
|
117
|
+
{props.failure && <PmNotice tone="danger"><span>{props.failure}</span><PmButton density={density} disabled={disabled || Boolean(busy)} onClick={props.retryImport ? props.onRetryImport : props.onRead}>{props.retryImport ? t.retryImport : t.retry}</PmButton></PmNotice>}
|
|
118
|
+
{props.storageFailed && <PmNotice tone="warn">{t.storageFailed}</PmNotice>}
|
|
119
|
+
{props.pending && !props.failure && <span className="pm-ui-field__hint" role="status">{t.pending}</span>}
|
|
120
|
+
{props.status && <span className="pm-ui-field__hint" role="status">{props.status}</span>}
|
|
121
|
+
</section>
|
|
122
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { TeachingDocument } from '@lincyaw/kernel'
|
|
3
|
+
import { PmButton, PmField, PmInput, PmSegmented } from './components.tsx'
|
|
4
|
+
import type { Locale } from './messages.ts'
|
|
5
|
+
import { stepNarrationStarts, stepTimingValue } from './step-production.ts'
|
|
6
|
+
import type { ProductionSource, StepDurationDraft, StepDurationKey, StepTimingPatch } from './step-production.ts'
|
|
7
|
+
|
|
8
|
+
const MESSAGES = {
|
|
9
|
+
'zh-CN': {
|
|
10
|
+
timing: '播放时机', start: '配音开始', during: '同步动画', after: '动画后', minimum: '最短停留', trailing: '结束停顿', automatic: '自动', unit: '毫秒',
|
|
11
|
+
source: { step: '本步设置', section: '继承本页', document: '继承文稿默认', unset: '未设置,使用讲授默认' },
|
|
12
|
+
restore: '使用继承的时机', restoreHint: '只把本步的开始时机、最短停留与结束停顿改回继承值;为单个讲稿设置的时机保留。',
|
|
13
|
+
legacy: '继承讲稿设置', mixed: '本步讲稿的开始时机不同。',
|
|
14
|
+
unify: '统一本步时机', unifyHint: '只覆盖本步;改回继承后继续使用讲稿原有的时机。',
|
|
15
|
+
invalid: '未采用:请输入不小于 0 的毫秒数。',
|
|
16
|
+
review: '草稿尚未采用。请核对当前来源设置,再修改或使用继承值。', pending: '输入尚未采用。', storageFailure: '无法在本机保留草稿,请保持页面打开。',
|
|
17
|
+
count: (index: number, value: string) => `讲稿 ${index}:${value}`,
|
|
18
|
+
advancedDraft: '有未完成的视频设置,请在视频制作中处理。',
|
|
19
|
+
},
|
|
20
|
+
en: {
|
|
21
|
+
timing: 'Playback timing', start: 'Voiceover starts', during: 'With animation', after: 'After animation', minimum: 'Minimum hold', trailing: 'Trailing pause', automatic: 'Auto', unit: 'ms',
|
|
22
|
+
source: { step: 'This step', section: 'Inherited from page', document: 'Inherited from document', unset: 'Not set; the lecture default applies' },
|
|
23
|
+
restore: 'Use Inherited Timing', restoreHint: 'Returns only this step’s start, minimum hold, and trailing pause to the inherited values. Timing set on individual scripts stays.',
|
|
24
|
+
legacy: 'Inherited from the script', mixed: 'Scripts in this step start at different times.',
|
|
25
|
+
unify: 'Unify Step Timing', unifyHint: 'Applies only to this step. Using inherited timing again returns to each script’s original timing.',
|
|
26
|
+
invalid: 'Not applied: enter a duration of 0 ms or more.',
|
|
27
|
+
review: 'This draft has not been applied. Check the current source setting, then edit it or use the inherited value.', pending: 'Input has not been applied.', storageFailure: 'Couldn’t keep the draft on this device. Keep this page open.',
|
|
28
|
+
count: (index: number, value: string) => `Script ${index}: ${value}`,
|
|
29
|
+
advancedDraft: 'Review the pending settings in Video Production.',
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface DurationFieldProps {
|
|
34
|
+
label: string
|
|
35
|
+
value?: number
|
|
36
|
+
source: ProductionSource
|
|
37
|
+
locale: Locale
|
|
38
|
+
readOnly?: boolean
|
|
39
|
+
draft?: StepDurationDraft
|
|
40
|
+
onDraft?(draft: StepDurationDraft | undefined): void
|
|
41
|
+
onChange(value: number | null): void
|
|
42
|
+
onComposition?(composing: boolean): void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Short author intent, never an estimated timestamp or a second playback clock. */
|
|
46
|
+
function DurationField({ label, value, source, locale, readOnly, draft, onDraft, onChange, onComposition }: DurationFieldProps) {
|
|
47
|
+
const t = MESSAGES[locale], current = useRef({ onComposition, onChange, onDraft, value })
|
|
48
|
+
current.current = { onComposition, onChange, onDraft, value }
|
|
49
|
+
const [text, setText] = useState(draft?.text ?? (value === undefined ? '' : String(value))), [error, setError] = useState(draft?.error ?? false)
|
|
50
|
+
const focused = useRef(false), composing = useRef(false)
|
|
51
|
+
useEffect(() => { if (!focused.current) { setText(draft?.text ?? (value === undefined ? '' : String(value))); setError(draft?.error ?? false) } }, [value, source, draft?.text, draft?.error, draft?.review])
|
|
52
|
+
useEffect(() => () => { if (composing.current) current.current.onComposition?.(false) }, [])
|
|
53
|
+
const commit = (input: string): boolean => {
|
|
54
|
+
const normalized = input.normalize('NFKC').trim()
|
|
55
|
+
if (!normalized) { setError(false); current.current.onDraft?.(undefined); current.current.onChange(null); return true }
|
|
56
|
+
const number = Number(normalized)
|
|
57
|
+
if (!/^\d+(?:\.\d+)?$/.test(normalized) || !Number.isFinite(number)) { setError(true); current.current.onDraft?.({ text: input, error: true }); return false }
|
|
58
|
+
setError(false); current.current.onDraft?.(undefined); current.current.onChange(number); return true
|
|
59
|
+
}
|
|
60
|
+
return <PmInput label={locale === 'zh-CN' ? `${label}(${t.unit})` : `${label} (${t.unit})`} width="number" inputMode="decimal" maxLength={256} value={text} placeholder={t.automatic}
|
|
61
|
+
hint={draft && !error && !draft.review ? `${t.source[source]} · ${t.pending}` : t.source[source]} error={draft?.review ? t.review : error ? t.invalid : undefined} readOnly={readOnly}
|
|
62
|
+
onFocus={() => { focused.current = true }}
|
|
63
|
+
onChange={event => {
|
|
64
|
+
setText(event.target.value)
|
|
65
|
+
if (readOnly) return
|
|
66
|
+
if (composing.current) { setError(false); current.current.onDraft?.({ text: event.target.value, error: false }) }
|
|
67
|
+
else commit(event.target.value)
|
|
68
|
+
}}
|
|
69
|
+
onBlur={() => {
|
|
70
|
+
focused.current = false
|
|
71
|
+
if (readOnly || composing.current || error || draft) return
|
|
72
|
+
setText(current.current.value === undefined ? '' : String(current.current.value))
|
|
73
|
+
}}
|
|
74
|
+
onCompositionStart={() => { composing.current = true; onComposition?.(true) }}
|
|
75
|
+
onCompositionEnd={event => {
|
|
76
|
+
composing.current = false
|
|
77
|
+
if (!readOnly) commit(event.currentTarget.value)
|
|
78
|
+
queueMicrotask(() => current.current.onComposition?.(false))
|
|
79
|
+
}} />
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface StepProductionEditorProps {
|
|
83
|
+
document: TeachingDocument
|
|
84
|
+
stepId: string
|
|
85
|
+
locale: Locale
|
|
86
|
+
readOnly?: boolean
|
|
87
|
+
advanced?: boolean
|
|
88
|
+
onPause(): void
|
|
89
|
+
onInteraction?(): void
|
|
90
|
+
onChange(patch: StepTimingPatch): void
|
|
91
|
+
drafts?: Partial<Record<StepDurationKey, StepDurationDraft>>
|
|
92
|
+
draftStorageFailure?: boolean
|
|
93
|
+
onDraft?(key: StepDurationKey, draft: StepDurationDraft | undefined): void
|
|
94
|
+
onComposition?(key: StepDurationKey, composing: boolean): void
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A reusable view of the canonical step production, including inherited and migrated settings. */
|
|
98
|
+
export function StepProductionEditor({ document, stepId, locale, readOnly, advanced = true, onPause, onInteraction, onChange, drafts, onDraft, draftStorageFailure, onComposition }: StepProductionEditorProps) {
|
|
99
|
+
const t = MESSAGES[locale], [unifying, setUnifying] = useState(false)
|
|
100
|
+
const start = stepTimingValue(document, stepId, 'narrationStart'), minimum = stepTimingValue(document, stepId, 'minimumHoldMs'), trailing = stepTimingValue(document, stepId, 'trailingPauseMs')
|
|
101
|
+
const narrations = stepNarrationStarts(document, stepId), hasOverrides = narrations.some(value => value.overridden)
|
|
102
|
+
const mixed = new Set(narrations.map(value => value.value ?? 'with-animation')).size > 1
|
|
103
|
+
const hasStepTiming = [start, minimum, trailing].some(value => value.source === 'step')
|
|
104
|
+
const apply = (patch: StepTimingPatch) => { if (!readOnly) { onPause(); onChange(patch) } }
|
|
105
|
+
const options = [{ value: 'with-animation', label: t.during, icon: 'timing-during' as const }, { value: 'after-animation', label: t.after, icon: 'timing-after' as const }]
|
|
106
|
+
return <section className="pm-ui-step-production" contentEditable={false} data-step-production={stepId} aria-label={t.timing}
|
|
107
|
+
onFocus={() => { onInteraction?.(); onPause() }} onKeyDown={event => event.stopPropagation()} onPointerDown={event => event.stopPropagation()}>
|
|
108
|
+
{advanced && <div className="pm-ui-step-production__heading"><span className="pm-ui-field__label">{t.timing}</span>
|
|
109
|
+
<PmButton small variant="ghost" disabled={readOnly || !hasStepTiming && !drafts?.minimumHoldMs && !drafts?.trailingPauseMs} title={t.restoreHint} onClick={() => { onDraft?.('minimumHoldMs', undefined); onDraft?.('trailingPauseMs', undefined); apply({ narrationStart: null, minimumHoldMs: null, trailingPauseMs: null }) }}>{t.restore}</PmButton>
|
|
110
|
+
</div>}
|
|
111
|
+
{!advanced ? <PmField group label={t.start} density="compact" hint={mixed ? t.mixed : undefined}>
|
|
112
|
+
<div className="pm-ui-step-production__actions"><PmSegmented label={t.start} value={mixed ? '' : narrations[0]?.value ?? start.value ?? 'with-animation'} options={options} disabled={readOnly} onChange={value => apply({ narrationStart: value as 'with-animation' | 'after-animation' })} /></div>
|
|
113
|
+
</PmField> : <><PmField group label={t.start} density="compact" hint={hasOverrides ? (mixed ? t.mixed : t.legacy) : t.source[start.source]}>
|
|
114
|
+
{!hasOverrides && <div className="pm-ui-step-production__actions"><PmSegmented label={t.start} value={start.value ?? ''} options={options} disabled={readOnly} onChange={value => apply({ narrationStart: value as 'with-animation' | 'after-animation' })} /></div>}
|
|
115
|
+
{hasOverrides && <>
|
|
116
|
+
<div className="pm-ui-step-production__narration-settings">{narrations.map((entry, index) => <span key={entry.id} className="pm-ui-field__hint">{t.count(index + 1, entry.value === 'after-animation' ? t.after : t.during)}{entry.overridden ? ` · ${t.legacy}` : ` · ${t.source[start.source]}`}</span>)}</div>
|
|
117
|
+
<div className="pm-ui-step-production__actions"><PmButton small disabled={readOnly} onClick={() => setUnifying(value => !value)} aria-expanded={unifying}>{t.unify}</PmButton></div>
|
|
118
|
+
{unifying && <><span className="pm-ui-field__hint">{t.unifyHint}</span><div className="pm-ui-step-production__actions"><PmSegmented label={t.unify} value="" options={options} disabled={readOnly} onChange={value => { apply({ narrationStart: value as 'with-animation' | 'after-animation' }); setUnifying(false) }} /></div></>}
|
|
119
|
+
</>}
|
|
120
|
+
</PmField>
|
|
121
|
+
<div className="pm-ui-step-production__durations">
|
|
122
|
+
<DurationField label={t.minimum} value={minimum.value} source={minimum.source} locale={locale} readOnly={readOnly} draft={drafts?.minimumHoldMs} onDraft={draft => onDraft?.('minimumHoldMs', draft)}
|
|
123
|
+
onChange={value => apply({ minimumHoldMs: value })} onComposition={composing => onComposition?.('minimumHoldMs', composing)} />
|
|
124
|
+
<DurationField label={t.trailing} value={trailing.value} source={trailing.source} locale={locale} readOnly={readOnly} draft={drafts?.trailingPauseMs} onDraft={draft => onDraft?.('trailingPauseMs', draft)}
|
|
125
|
+
onChange={value => apply({ trailingPauseMs: value })} onComposition={composing => onComposition?.('trailingPauseMs', composing)} />
|
|
126
|
+
</div></>}
|
|
127
|
+
{!advanced && (drafts?.minimumHoldMs || drafts?.trailingPauseMs || draftStorageFailure) ? <span className="pm-ui-field__error" role="alert">{t.advancedDraft}</span>
|
|
128
|
+
: draftStorageFailure && <span className="pm-ui-field__error" role="alert">{t.storageFailure}</span>}
|
|
129
|
+
</section>
|
|
130
|
+
}
|