@lingjingai/script-editor 0.1.17 → 0.1.18
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/INTEGRATION.md +59 -0
- package/dist/index.d.ts +66 -2
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/INTEGRATION.md
CHANGED
|
@@ -64,6 +64,7 @@ function Host({ script, setScript }) {
|
|
|
64
64
|
- `selection` / `onSelectionChange`(`StudioSelection`,不传则内部自管)
|
|
65
65
|
- `format` / `onFormatChange`(`"standard" | "asian"`)
|
|
66
66
|
- `disabled`、`dark`、`className`
|
|
67
|
+
- `toc?: "sidebar" | "none"`:内置左侧目录。默认 `"sidebar"` 渲染自带 256px 目录列;`"none"` = **无目录模式**——只渲染顶栏 + 画布(占满宽度),宿主自建导航。见 §10。`0.1.18+`
|
|
67
68
|
|
|
68
69
|
**HUD(顶栏)**
|
|
69
70
|
- `onTitleChange?(next: string)`:顶栏左侧常驻**剧本标题**(取 `value.title`)。传了它,标题变**点击即改**;不传则只读展示(`value.title` 为空时不显示)。包**不碰存储**——拿到新标题宿主自己持久化(可 `onEdit(p => ({...p, title}))` 写回 `script.json`,或另调重命名接口)。`0.1.16+`
|
|
@@ -127,3 +128,61 @@ function Host({ script, setScript }) {
|
|
|
127
128
|
- `apps/web/src/features/script-editor/useScriptDocument.ts` —— 自动保存 + undo/redo + 8s 轮询探测
|
|
128
129
|
- `apps/web/src/features/script-editor/script-output-api.ts` —— 后端存取
|
|
129
130
|
- `apps/web/src/main.tsx` / `apps/web/vite.config.ts` —— CSS 引入 + `development` 解析条件
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 10. 无目录模式 / 自建导航(`toc="none"`)`0.1.18+`
|
|
135
|
+
|
|
136
|
+
把内置左侧目录关掉、导航**透出**给宿主自己渲染(嵌进已有全局导航、或做成面包屑下拉 / ⌘K 命令面板 / 移动端 sheet 等完全不同的形态)。包只给**纯数据模型**,不给 UI。
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import {
|
|
140
|
+
ScriptEditor,
|
|
141
|
+
buildScriptNav,
|
|
142
|
+
selectionTargetKey,
|
|
143
|
+
withOrigin,
|
|
144
|
+
type StudioSelection,
|
|
145
|
+
} from "@lingjingai/script-editor";
|
|
146
|
+
|
|
147
|
+
function Host({ script, onEdit }) {
|
|
148
|
+
// 无目录模式下 selection 必须受控(宿主自己的导航要驱动它)
|
|
149
|
+
const [sel, setSel] = useState<StudioSelection>({ kind: "empty" });
|
|
150
|
+
const nav = buildScriptNav(script); // 派生导航树(纯函数)
|
|
151
|
+
const active = selectionTargetKey(sel); // 当前激活节点的 key
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<>
|
|
155
|
+
{/* 宿主自建的任意导航 UI —— 这里是最朴素的列表 */}
|
|
156
|
+
<MyNav>
|
|
157
|
+
{nav.episodes.flatMap((e) => e.scenes).map((s) => (
|
|
158
|
+
<button
|
|
159
|
+
key={s.key}
|
|
160
|
+
data-active={s.key === active}
|
|
161
|
+
onClick={() => setSel(withOrigin(s.selection, "sidebar"))}
|
|
162
|
+
>
|
|
163
|
+
{s.label} · {s.meta}
|
|
164
|
+
</button>
|
|
165
|
+
))}
|
|
166
|
+
</MyNav>
|
|
167
|
+
|
|
168
|
+
<ScriptEditor
|
|
169
|
+
value={script}
|
|
170
|
+
onEdit={onEdit}
|
|
171
|
+
toc="none" {/* ← 关掉内置目录,画布占满 */}
|
|
172
|
+
selection={sel}
|
|
173
|
+
onSelectionChange={setSel} {/* ← 编辑器内滚动 spy 也会回吐 selection */}
|
|
174
|
+
/>
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`buildScriptNav(value): ScriptNav` 返回:
|
|
181
|
+
- `worldview` / `episodes[]` / `actors[]` / `locations[]` / `props[]`,`episodes[].scenes[]` 内嵌。
|
|
182
|
+
- 每个节点都带 **`key`**(= `selectionTargetKey(node.selection)`,拿去和 `selectionTargetKey(当前selection)` 比对即判激活)和 **`selection`**(即用型 `StudioSelection`,**不带 origin**;点击时 `withOrigin(node.selection, "sidebar")` 再喂 `onSelectionChange`)。
|
|
183
|
+
- 标签字段(`label`/`title`/`meta`/`name`)与内置目录**同 helper 派生**,长相一致。
|
|
184
|
+
|
|
185
|
+
要点:
|
|
186
|
+
- selection 同时也是**回吐**通道:编辑器画布滚动时会上抛 `onSelectionChange`(origin `"scroll"`),宿主导航据此高亮当前位置。
|
|
187
|
+
- 无目录模式下内置「新增一集」按钮消失——宿主可自行调 `mutations.addEpisode`(已从包导出:`mutations.addEpisode(prev)`)接到自己的按钮上。
|
|
188
|
+
- 形态对照交互演示:`toc-modes-demo.html`(本包根目录,不随包发布)「形态 B」tab,演示用同一个 `buildScriptNav` 模型同时驱动面包屑下拉 + ⌘K 两种 UI。
|
package/dist/index.d.ts
CHANGED
|
@@ -488,6 +488,12 @@ interface ScriptEditorProps extends ScriptEditorAdapters {
|
|
|
488
488
|
disabled?: boolean;
|
|
489
489
|
className?: string;
|
|
490
490
|
dark?: boolean;
|
|
491
|
+
/** built-in left directory. Default "sidebar" renders the bundled 256px TOC
|
|
492
|
+
* column; "none" → directory-less mode: the editor renders top bar + canvas
|
|
493
|
+
* only (full width) and the host drives navigation via controlled
|
|
494
|
+
* selection/onSelectionChange + the exported buildScriptNav(value) model.
|
|
495
|
+
* 0.1.18+ */
|
|
496
|
+
toc?: "sidebar" | "none";
|
|
491
497
|
/** when provided, the script title (value.title) becomes click-to-edit in the
|
|
492
498
|
* top bar; the host persists the new value (the editor never touches storage,
|
|
493
499
|
* matching the value + onEdit contract — just one more delegated hook). Omit →
|
|
@@ -512,7 +518,65 @@ interface ScriptEditorProps extends ScriptEditorAdapters {
|
|
|
512
518
|
* scroll position across editor unmount/remount (tab switch / project nav). */
|
|
513
519
|
scrollScopeKey?: string;
|
|
514
520
|
}
|
|
515
|
-
declare function ScriptEditor({ value, onEdit, selection: controlledSelection, onSelectionChange, format: controlledFormat, onFormatChange, disabled, className, dark, onTitleChange, topBarActions, saveStatus, canUndo, canRedo, onUndo, onRedo, onEditingChange, referenceFocusRequest, scrollScopeKey, diff, asset, onAddChatReferences, onRequestAssetDelete, }: ScriptEditorProps): react.JSX.Element;
|
|
521
|
+
declare function ScriptEditor({ value, onEdit, selection: controlledSelection, onSelectionChange, format: controlledFormat, onFormatChange, disabled, className, dark, toc, onTitleChange, topBarActions, saveStatus, canUndo, canRedo, onUndo, onRedo, onEditingChange, referenceFocusRequest, scrollScopeKey, diff, asset, onAddChatReferences, onRequestAssetDelete, }: ScriptEditorProps): react.JSX.Element;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Headless navigation model — surfaces the script's TOC tree (the same
|
|
525
|
+
* episodes/scenes/entity structure `StudioToc` renders) as plain data so a host
|
|
526
|
+
* in directory-less mode (`<ScriptEditor toc="none" />`) can build its OWN
|
|
527
|
+
* navigation UI: breadcrumb dropdown, ⌘K command palette, mobile sheet, etc.
|
|
528
|
+
*
|
|
529
|
+
* Each node carries:
|
|
530
|
+
* - `key` — `selectionTargetKey` of its selection; compare against
|
|
531
|
+
* `selectionTargetKey(currentSelection)` to mark the active node.
|
|
532
|
+
* - `selection` — a ready-to-use `StudioSelection` (no origin). On click do
|
|
533
|
+
* `onSelectionChange(withOrigin(node.selection, "sidebar"))`.
|
|
534
|
+
*
|
|
535
|
+
* Labels reuse the exact same helpers as `StudioToc`, so a custom nav stays
|
|
536
|
+
* label-identical to the built-in one. Pure function, zero side effects.
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
interface ScriptNavScene {
|
|
540
|
+
key: string;
|
|
541
|
+
episodeIdx: number;
|
|
542
|
+
sceneIdx: number;
|
|
543
|
+
sceneId: string;
|
|
544
|
+
/** e.g. "场 7" */
|
|
545
|
+
label: string;
|
|
546
|
+
/** e.g. "scn_007 · 夜内" */
|
|
547
|
+
meta: string;
|
|
548
|
+
selection: StudioSelection;
|
|
549
|
+
}
|
|
550
|
+
interface ScriptNavEpisode {
|
|
551
|
+
key: string;
|
|
552
|
+
episodeIdx: number;
|
|
553
|
+
/** zero-padded episode number, e.g. "01" */
|
|
554
|
+
label: string;
|
|
555
|
+
/** human title (falls back to "第 NN 集") */
|
|
556
|
+
title: string;
|
|
557
|
+
sceneCount: number;
|
|
558
|
+
scenes: ScriptNavScene[];
|
|
559
|
+
selection: StudioSelection;
|
|
560
|
+
}
|
|
561
|
+
interface ScriptNavEntity {
|
|
562
|
+
key: string;
|
|
563
|
+
id: string;
|
|
564
|
+
name: string;
|
|
565
|
+
selection: StudioSelection;
|
|
566
|
+
}
|
|
567
|
+
interface ScriptNav {
|
|
568
|
+
worldview: {
|
|
569
|
+
key: string;
|
|
570
|
+
label: string;
|
|
571
|
+
selection: StudioSelection;
|
|
572
|
+
};
|
|
573
|
+
episodes: ScriptNavEpisode[];
|
|
574
|
+
actors: ScriptNavEntity[];
|
|
575
|
+
locations: ScriptNavEntity[];
|
|
576
|
+
props: ScriptNavEntity[];
|
|
577
|
+
}
|
|
578
|
+
/** Derive the navigation tree from a ScriptProject (see file header). */
|
|
579
|
+
declare function buildScriptNav(value: ScriptProject): ScriptNav;
|
|
516
580
|
|
|
517
581
|
/**
|
|
518
582
|
* Pure ScriptProject mutations.
|
|
@@ -739,4 +803,4 @@ declare function DeleteConfirmButton({ onConfirm, disabled, targetScope, title,
|
|
|
739
803
|
description?: string;
|
|
740
804
|
}): react.JSX.Element;
|
|
741
805
|
|
|
742
|
-
export { type AssetAdapter, type AssetDeleteRequest, type AssetState, type ChangeSet, type ChatReference, DeleteConfirmButton, type DiffActionMark, type DiffAdapter, type DiffSceneMark, EMPTY_SELECTION, EditableText, type EpisodeWorkspaceView, type FieldChange, Popover, type SaveStatus, type Scene, type SceneActionDiff, type SceneChangeKind, type SceneContext, type SceneEnvironment, type ScriptActor, ScriptContentType, type ScriptData, ScriptEditor, type ScriptEditorAdapters, type ScriptEditorProps, type ScriptEpisode, type ScriptFormat, type ScriptItem, type ScriptLocation, type ScriptProject, type ScriptProp, type ScriptReferenceFocusRequest, type ScriptReferenceLocator, type ScriptSpeaker, type ScriptTargetKind, SelectField, type StateChange, type StudioSelection, type StudioSelectionFrom, type StudioSelectionOrigin, type TransitionPrompt, acceptActionIntoBaseline, acceptSceneIntoBaseline, applyActionAccept, applyActionReject, buildActionDiff, buildDiffFromBaseline, buildSelectionFrom, changeSetToDiffScenes, computeChangeSet, computeSceneActionDiff, findBaselineScene, fromToSelection, getActorCueVar, getActorMap, getEpisodeTitle, getLocationMap, getPropMap, getSceneContext, getSelectionEpisodeIdx, getSpeakerMap, isClipSelected, isEpisodeOpen, isSameSelectionTarget, isSceneSelected, index as mutations, rejectActionToBaseline, rejectSceneToBaseline, sceneChangeKey, selectionFromScriptReference, selectionTargetKey, withOrigin };
|
|
806
|
+
export { type AssetAdapter, type AssetDeleteRequest, type AssetState, type ChangeSet, type ChatReference, DeleteConfirmButton, type DiffActionMark, type DiffAdapter, type DiffSceneMark, EMPTY_SELECTION, EditableText, type EpisodeWorkspaceView, type FieldChange, Popover, type SaveStatus, type Scene, type SceneActionDiff, type SceneChangeKind, type SceneContext, type SceneEnvironment, type ScriptActor, ScriptContentType, type ScriptData, ScriptEditor, type ScriptEditorAdapters, type ScriptEditorProps, type ScriptEpisode, type ScriptFormat, type ScriptItem, type ScriptLocation, type ScriptNav, type ScriptNavEntity, type ScriptNavEpisode, type ScriptNavScene, type ScriptProject, type ScriptProp, type ScriptReferenceFocusRequest, type ScriptReferenceLocator, type ScriptSpeaker, type ScriptTargetKind, SelectField, type StateChange, type StudioSelection, type StudioSelectionFrom, type StudioSelectionOrigin, type TransitionPrompt, acceptActionIntoBaseline, acceptSceneIntoBaseline, applyActionAccept, applyActionReject, buildActionDiff, buildDiffFromBaseline, buildScriptNav, buildSelectionFrom, changeSetToDiffScenes, computeChangeSet, computeSceneActionDiff, findBaselineScene, fromToSelection, getActorCueVar, getActorMap, getEpisodeTitle, getLocationMap, getPropMap, getSceneContext, getSelectionEpisodeIdx, getSpeakerMap, isClipSelected, isEpisodeOpen, isSameSelectionTarget, isSceneSelected, index as mutations, rejectActionToBaseline, rejectSceneToBaseline, sceneChangeKey, selectionFromScriptReference, selectionTargetKey, withOrigin };
|
package/dist/index.js
CHANGED
|
@@ -3989,6 +3989,7 @@ function ScriptEditor({
|
|
|
3989
3989
|
disabled = false,
|
|
3990
3990
|
className,
|
|
3991
3991
|
dark,
|
|
3992
|
+
toc = "sidebar",
|
|
3992
3993
|
onTitleChange,
|
|
3993
3994
|
topBarActions,
|
|
3994
3995
|
saveStatus = "idle",
|
|
@@ -4152,7 +4153,7 @@ function ScriptEditor({
|
|
|
4152
4153
|
}
|
|
4153
4154
|
);
|
|
4154
4155
|
return /* @__PURE__ */ jsx(EditingSignalContext.Provider, { value: editingSignal, children: /* @__PURE__ */ jsxs("div", { className: rootClass, children: [
|
|
4155
|
-
/* @__PURE__ */ jsx(
|
|
4156
|
+
toc === "sidebar" ? /* @__PURE__ */ jsx(
|
|
4156
4157
|
StudioToc,
|
|
4157
4158
|
{
|
|
4158
4159
|
data: value,
|
|
@@ -4160,7 +4161,7 @@ function ScriptEditor({
|
|
|
4160
4161
|
onSelect: setSelection,
|
|
4161
4162
|
onAddEpisode: disabled ? void 0 : () => onEdit((p) => addEpisode(p))
|
|
4162
4163
|
}
|
|
4163
|
-
),
|
|
4164
|
+
) : null,
|
|
4164
4165
|
/* @__PURE__ */ jsxs("div", { className: "lj-se-main", children: [
|
|
4165
4166
|
/* @__PURE__ */ jsx(
|
|
4166
4167
|
CanvasTopBar,
|
|
@@ -4258,6 +4259,54 @@ function resolveReturnTarget(value, selection) {
|
|
|
4258
4259
|
return { label, selection: withOrigin(fromToSelection(from), "reference") };
|
|
4259
4260
|
}
|
|
4260
4261
|
|
|
4262
|
+
// src/toc/nav-model.ts
|
|
4263
|
+
function nav(selection) {
|
|
4264
|
+
return { key: selectionTargetKey(selection), selection };
|
|
4265
|
+
}
|
|
4266
|
+
function buildScriptNav(value) {
|
|
4267
|
+
const episodes = (value.episodes ?? []).map((episode, episodeIdx) => {
|
|
4268
|
+
const scenes = (episode.scenes ?? []).map((scene, sceneIdx) => {
|
|
4269
|
+
const selection2 = { kind: "scene", episodeIdx, sceneIdx };
|
|
4270
|
+
return {
|
|
4271
|
+
...nav(selection2),
|
|
4272
|
+
episodeIdx,
|
|
4273
|
+
sceneIdx,
|
|
4274
|
+
sceneId: scene.scene_id ?? "",
|
|
4275
|
+
label: getSceneNumberLabel(scene, sceneIdx),
|
|
4276
|
+
meta: getSceneSidebarLabel(scene, sceneIdx)
|
|
4277
|
+
};
|
|
4278
|
+
});
|
|
4279
|
+
const selection = { kind: "episode", episodeIdx };
|
|
4280
|
+
return {
|
|
4281
|
+
...nav(selection),
|
|
4282
|
+
episodeIdx,
|
|
4283
|
+
label: getEpisodeNumberLabel(episode, episodeIdx),
|
|
4284
|
+
title: getEpisodeTitle(episode, episodeIdx),
|
|
4285
|
+
sceneCount: scenes.length,
|
|
4286
|
+
scenes
|
|
4287
|
+
};
|
|
4288
|
+
});
|
|
4289
|
+
const actors = (value.actors ?? []).map((a) => {
|
|
4290
|
+
const id = (a.actor_id ?? "").trim();
|
|
4291
|
+
return { ...nav({ kind: "actor", actorId: id }), id, name: getActorDisplayName(a) };
|
|
4292
|
+
}).filter((e) => e.id);
|
|
4293
|
+
const locations = (value.locations ?? []).map((l) => {
|
|
4294
|
+
const id = (l.location_id ?? "").trim();
|
|
4295
|
+
return { ...nav({ kind: "location", locationId: id }), id, name: getLocationDisplayName(l) };
|
|
4296
|
+
}).filter((e) => e.id);
|
|
4297
|
+
const props = (value.props ?? []).map((p) => {
|
|
4298
|
+
const id = (p.prop_id ?? "").trim();
|
|
4299
|
+
return { ...nav({ kind: "prop", propId: id }), id, name: getPropDisplayName(p) };
|
|
4300
|
+
}).filter((e) => e.id);
|
|
4301
|
+
return {
|
|
4302
|
+
worldview: { ...nav({ kind: "worldview" }), label: "\u4E16\u754C\u89C2 & \u98CE\u683C" },
|
|
4303
|
+
episodes,
|
|
4304
|
+
actors,
|
|
4305
|
+
locations,
|
|
4306
|
+
props
|
|
4307
|
+
};
|
|
4308
|
+
}
|
|
4309
|
+
|
|
4261
4310
|
// src/mutations/index.ts
|
|
4262
4311
|
var mutations_exports = {};
|
|
4263
4312
|
__export(mutations_exports, {
|
|
@@ -4299,6 +4348,6 @@ __export(mutations_exports, {
|
|
|
4299
4348
|
updateScenePropState: () => updateScenePropState
|
|
4300
4349
|
});
|
|
4301
4350
|
|
|
4302
|
-
export { DeleteConfirmButton, EMPTY_SELECTION, EditableText, Popover, ScriptContentType, ScriptEditor, SelectField, acceptActionIntoBaseline, acceptSceneIntoBaseline, applyActionAccept, applyActionReject, buildActionDiff, buildDiffFromBaseline, buildSelectionFrom, changeSetToDiffScenes, computeChangeSet, computeSceneActionDiff, findBaselineScene, fromToSelection, getActorCueVar, getActorMap, getEpisodeTitle, getLocationMap, getPropMap, getSceneContext, getSelectionEpisodeIdx, getSpeakerMap, isClipSelected, isEpisodeOpen, isSameSelectionTarget, isSceneSelected, mutations_exports as mutations, rejectActionToBaseline, rejectSceneToBaseline, sceneChangeKey, selectionFromScriptReference, selectionTargetKey, withOrigin };
|
|
4351
|
+
export { DeleteConfirmButton, EMPTY_SELECTION, EditableText, Popover, ScriptContentType, ScriptEditor, SelectField, acceptActionIntoBaseline, acceptSceneIntoBaseline, applyActionAccept, applyActionReject, buildActionDiff, buildDiffFromBaseline, buildScriptNav, buildSelectionFrom, changeSetToDiffScenes, computeChangeSet, computeSceneActionDiff, findBaselineScene, fromToSelection, getActorCueVar, getActorMap, getEpisodeTitle, getLocationMap, getPropMap, getSceneContext, getSelectionEpisodeIdx, getSpeakerMap, isClipSelected, isEpisodeOpen, isSameSelectionTarget, isSceneSelected, mutations_exports as mutations, rejectActionToBaseline, rejectSceneToBaseline, sceneChangeKey, selectionFromScriptReference, selectionTargetKey, withOrigin };
|
|
4303
4352
|
//# sourceMappingURL=index.js.map
|
|
4304
4353
|
//# sourceMappingURL=index.js.map
|