@lingjingai/script-editor 0.1.0 → 0.1.13
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 +2 -7
- package/dist/index.d.ts +116 -15
- package/dist/index.js +447 -127
- package/dist/index.js.map +1 -1
- package/dist/style.css +25 -2
- package/package.json +2 -6
package/INTEGRATION.md
CHANGED
|
@@ -20,12 +20,7 @@
|
|
|
20
20
|
```ts
|
|
21
21
|
import "@lingjingai/script-editor/style.css";
|
|
22
22
|
```
|
|
23
|
-
-
|
|
24
|
-
- 默认走 `dist`(`tsup` 产物,编译好的 JS + d.ts),消费方无需编译包内 TS。
|
|
25
|
-
- 想直接吃 `src` + HMR(monorepo 开发)→ 打包器加 `development` 解析条件。Vite:
|
|
26
|
-
```ts
|
|
27
|
-
resolve: { conditions: ["development"] }
|
|
28
|
-
```
|
|
23
|
+
- **构建产物**:消费方一律走 `dist`(`tsup` 编译好的 JS + d.ts + style.css + paper-fibers.png),无需编译包内 TS。`exports` 不带 `development` 条件(早期版本带过,会让 Vite **dev 模式**去找未发布的 `src/` 而报 `Failed to resolve import .../style.css` —— `0.1.1+` 已修)。
|
|
29
24
|
|
|
30
25
|
---
|
|
31
26
|
|
|
@@ -72,7 +67,7 @@ function Host({ script, setScript }) {
|
|
|
72
67
|
|
|
73
68
|
**HUD(顶栏)**
|
|
74
69
|
- `saveStatus`:`"idle" | "saving" | "saved" | "error"`
|
|
75
|
-
- `canUndo` / `canRedo` / `onUndo` / `onRedo`
|
|
70
|
+
- `canUndo` / `canRedo` / `onUndo` / `onRedo` —— **Cmd/Ctrl+Z 撤销、Cmd/Ctrl+Shift+Z(或 Ctrl+Y)重做 已内建**(输入框内放行原生撤回),宿主**不要再自己接键盘监听**,否则会双触发(撤销两步)。`0.1.2+`
|
|
76
71
|
|
|
77
72
|
**编辑信号**
|
|
78
73
|
- `onEditingChange(editing: boolean)`:有外部改稿(AI / 协同)时,用它在"正编辑某字段"期间暂停采纳远端,避免覆盖。见 §6。
|
package/dist/index.d.ts
CHANGED
|
@@ -306,6 +306,14 @@ interface FieldChange {
|
|
|
306
306
|
after: string;
|
|
307
307
|
}
|
|
308
308
|
type SceneChangeKind = "added" | "modified";
|
|
309
|
+
/** A host-flagged changed scene the editor should render (highlight + per-scene
|
|
310
|
+
* accept/reject). The host decides WHICH scenes are marked (provenance: e.g.
|
|
311
|
+
* only agent-changed scenes, not the user's own manual edits). */
|
|
312
|
+
interface DiffSceneMark {
|
|
313
|
+
episodeIdx: number;
|
|
314
|
+
sceneId: string;
|
|
315
|
+
kind: SceneChangeKind;
|
|
316
|
+
}
|
|
309
317
|
interface ChangeSet {
|
|
310
318
|
title?: FieldChange;
|
|
311
319
|
worldview?: FieldChange;
|
|
@@ -319,6 +327,78 @@ interface ChangeSet {
|
|
|
319
327
|
}
|
|
320
328
|
declare function sceneChangeKey(episodeIdx: number, sceneId: string | undefined): string;
|
|
321
329
|
declare function computeChangeSet(baseline: ScriptProject | null, current: ScriptProject): ChangeSet;
|
|
330
|
+
/** Convert a ChangeSet's changed-scene map into the editor's DiffSceneMark[]
|
|
331
|
+
* (the `diff.scenes` render descriptor). Keys are `${episodeIdx}:${sceneId}`. */
|
|
332
|
+
declare function changeSetToDiffScenes(changeSet: ChangeSet): DiffSceneMark[];
|
|
333
|
+
/** Convenience for hosts using the simple "baseline vs current" diff model:
|
|
334
|
+
* returns the render-descriptor data (scenes + counts) the `diff` adapter wants.
|
|
335
|
+
* Hosts wanting provenance (user vs agent) compute `scenes` themselves instead. */
|
|
336
|
+
declare function buildDiffFromBaseline(baseline: ScriptProject | null, current: ScriptProject): {
|
|
337
|
+
scenes: DiffSceneMark[];
|
|
338
|
+
removedCount: number;
|
|
339
|
+
count: number;
|
|
340
|
+
};
|
|
341
|
+
/** PER-SCENE ACCEPT — return a baseline patched so its matching scene equals
|
|
342
|
+
* `scene` (the current version), dropping just that scene from the diff. Matches
|
|
343
|
+
* the episode by episode_id (fallback index) and the scene by scene_id; inserts
|
|
344
|
+
* when the baseline lacked it (an added scene). Immutable. */
|
|
345
|
+
declare function acceptSceneIntoBaseline(baseline: ScriptProject, episodeId: string | undefined, episodeIdx: number, scene: Scene): ScriptProject;
|
|
346
|
+
/** PER-SCENE REJECT — return current with the scene at (episodeIdx, sceneIdx)
|
|
347
|
+
* reverted to its baseline version, or removed if it was added (no baseline
|
|
348
|
+
* counterpart). Immutable. */
|
|
349
|
+
declare function rejectSceneToBaseline(current: ScriptProject, episodeIdx: number, sceneIdx: number, baselineScene: Scene | null): ScriptProject;
|
|
350
|
+
/** Look up the baseline scene matching (episodeId/idx, sceneId), or null. */
|
|
351
|
+
declare function findBaselineScene(baseline: ScriptProject | null, episodeId: string | undefined, episodeIdx: number, sceneId: string): Scene | null;
|
|
352
|
+
/** One changed action (line) the editor renders: highlight + ✓/✗.
|
|
353
|
+
* - added/modified: `itemIdx` is the index in the CURRENT scene.
|
|
354
|
+
* - removed: `itemIdx` is the position the ghost row sits BEFORE in the current list.
|
|
355
|
+
* `item` is the OLD baseline action (set for "modified" and "removed") so the
|
|
356
|
+
* editor can render the deleted line above the new one (unified-diff view). */
|
|
357
|
+
interface DiffActionMark {
|
|
358
|
+
episodeIdx: number;
|
|
359
|
+
sceneId: string;
|
|
360
|
+
kind: "added" | "modified" | "removed";
|
|
361
|
+
itemIdx: number;
|
|
362
|
+
baselineItemIdx?: number;
|
|
363
|
+
item?: ScriptItem;
|
|
364
|
+
}
|
|
365
|
+
interface SceneActionDiff {
|
|
366
|
+
changed: Array<{
|
|
367
|
+
itemIdx: number;
|
|
368
|
+
kind: "added" | "modified";
|
|
369
|
+
baselineItemIdx?: number;
|
|
370
|
+
}>;
|
|
371
|
+
removed: Array<{
|
|
372
|
+
beforeItemIdx: number;
|
|
373
|
+
baselineItemIdx: number;
|
|
374
|
+
}>;
|
|
375
|
+
}
|
|
376
|
+
/** LCS-align two action lists → per-line added / modified / removed. Adjacent
|
|
377
|
+
* delete+insert runs are paired as "modified" (so an in-place line edit shows
|
|
378
|
+
* as one modified row, not remove+add); LCS keeps insertions from shifting all
|
|
379
|
+
* following lines into false "modified"s. */
|
|
380
|
+
declare function computeSceneActionDiff(baseline: ScriptItem[], current: ScriptItem[]): SceneActionDiff;
|
|
381
|
+
/** Apply an action ACCEPT onto a baseline scene (returns a new scene): the
|
|
382
|
+
* baseline catches up to current for that line, so it stops being a diff. */
|
|
383
|
+
declare function applyActionAccept(baselineScene: Scene, currentScene: Scene, mark: DiffActionMark): Scene;
|
|
384
|
+
/** Apply an action REJECT onto a current scene (returns a new scene): the
|
|
385
|
+
* working value reverts to the baseline for that line (or drops an added line /
|
|
386
|
+
* restores a removed one). */
|
|
387
|
+
declare function applyActionReject(currentScene: Scene, baselineScene: Scene | null, mark: DiffActionMark): Scene;
|
|
388
|
+
/** Project-level action ACCEPT — advance the baseline for one line. Thin for
|
|
389
|
+
* hosts: `patchBaseline(prev => acceptActionIntoBaseline(prev, current, mark))`. */
|
|
390
|
+
declare function acceptActionIntoBaseline(baseline: ScriptProject, current: ScriptProject, mark: DiffActionMark): ScriptProject;
|
|
391
|
+
/** Project-level action REJECT — revert the working value for one line. Thin:
|
|
392
|
+
* `onEdit(cur => rejectActionToBaseline(cur, baseline, mark))`. */
|
|
393
|
+
declare function rejectActionToBaseline(current: ScriptProject, baseline: ScriptProject | null, mark: DiffActionMark): ScriptProject;
|
|
394
|
+
/** Convenience for the simple baseline model: full action-level descriptor data
|
|
395
|
+
* (whole-scene marks for added scenes; per-line marks for modified scenes). */
|
|
396
|
+
declare function buildActionDiff(baseline: ScriptProject | null, current: ScriptProject): {
|
|
397
|
+
scenes: DiffSceneMark[];
|
|
398
|
+
actions: DiffActionMark[];
|
|
399
|
+
removedCount: number;
|
|
400
|
+
count: number;
|
|
401
|
+
};
|
|
322
402
|
|
|
323
403
|
interface AssetDeleteRequest {
|
|
324
404
|
kind: "actor" | "location" | "prop";
|
|
@@ -336,22 +416,40 @@ interface AssetDeleteRequest {
|
|
|
336
416
|
* services (script-output, chat, asset generation, comments).
|
|
337
417
|
*/
|
|
338
418
|
|
|
339
|
-
/**
|
|
419
|
+
/**
|
|
420
|
+
* Diff overlay — a pure RENDER descriptor. The editor does NOT compute the diff;
|
|
421
|
+
* the HOST decides which scenes count as changed (provenance: e.g. only the
|
|
422
|
+
* agent's edits, not the user's manual ones — see `buildDiffFromBaseline` /
|
|
423
|
+
* `changeSetToDiffScenes` for the simple baseline model, or compute it yourself)
|
|
424
|
+
* and supplies the accept/reject side-effects. The editor highlights the marked
|
|
425
|
+
* scenes, shows per-scene + all accept/reject affordances, and the change count.
|
|
426
|
+
*/
|
|
340
427
|
interface DiffAdapter {
|
|
341
|
-
/**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
*
|
|
428
|
+
/** WHOLE-scene marks (e.g. a brand-new scene) — editor highlights the whole
|
|
429
|
+
* scene + offers scene-level accept/reject */
|
|
430
|
+
scenes: DiffSceneMark[];
|
|
431
|
+
/** ACTION-level marks (added / modified / removed lines within a scene) —
|
|
432
|
+
* editor highlights those rows, renders ghost rows for removed, and offers
|
|
433
|
+
* per-line accept/reject. A scene appears in `scenes` OR has entries here. */
|
|
434
|
+
actions?: DiffActionMark[];
|
|
435
|
+
/** scenes removed vs the host's baseline — shown only as a count (the editor
|
|
436
|
+
* can't render scenes absent from `value`) */
|
|
437
|
+
removedCount?: number;
|
|
438
|
+
/** capsule total; defaults to `scenes.length + (removedCount ?? 0)` */
|
|
439
|
+
count?: number;
|
|
440
|
+
/** "memory" → baseline only in memory (lost on reload); shows a hint */
|
|
346
441
|
baselineStatus?: "ok" | "memory";
|
|
347
|
-
/**
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
442
|
+
/** accept one scene's change — host advances its baseline (resolves it) */
|
|
443
|
+
onAcceptScene?: (mark: DiffSceneMark) => void;
|
|
444
|
+
/** reject one scene's change — host reverts the working value to baseline */
|
|
445
|
+
onRejectScene?: (mark: DiffSceneMark) => void;
|
|
446
|
+
/** accept one line — host advances its baseline for that action */
|
|
447
|
+
onAcceptAction?: (mark: DiffActionMark) => void;
|
|
448
|
+
/** reject one line — host reverts the working value for that action */
|
|
449
|
+
onRejectAction?: (mark: DiffActionMark) => void;
|
|
450
|
+
/** accept everything */
|
|
353
451
|
onAcceptAll?: () => void;
|
|
354
|
-
/** reject
|
|
452
|
+
/** reject everything */
|
|
355
453
|
onRejectAll?: () => void;
|
|
356
454
|
}
|
|
357
455
|
/** Asset display + side-effecting generation/upload (kept in the host). */
|
|
@@ -402,8 +500,11 @@ interface ScriptEditorProps extends ScriptEditorAdapters {
|
|
|
402
500
|
/** host-pushed "jump into the script" signal (inverse of quote-to-chat):
|
|
403
501
|
* bump requestId + supply a reference → editor selects & scrolls to it. */
|
|
404
502
|
referenceFocusRequest?: ScriptReferenceFocusRequest | null;
|
|
503
|
+
/** stable per-scope key (e.g. projectGroupNo) — remembers & restores the
|
|
504
|
+
* scroll position across editor unmount/remount (tab switch / project nav). */
|
|
505
|
+
scrollScopeKey?: string;
|
|
405
506
|
}
|
|
406
|
-
declare function ScriptEditor({ value, onEdit, selection: controlledSelection, onSelectionChange, format: controlledFormat, onFormatChange, disabled, className, dark, saveStatus, canUndo, canRedo, onUndo, onRedo, onEditingChange, referenceFocusRequest, diff, asset, onAddChatReferences, onRequestAssetDelete, }: ScriptEditorProps): react.JSX.Element;
|
|
507
|
+
declare function ScriptEditor({ value, onEdit, selection: controlledSelection, onSelectionChange, format: controlledFormat, onFormatChange, disabled, className, dark, saveStatus, canUndo, canRedo, onUndo, onRedo, onEditingChange, referenceFocusRequest, scrollScopeKey, diff, asset, onAddChatReferences, onRequestAssetDelete, }: ScriptEditorProps): react.JSX.Element;
|
|
407
508
|
|
|
408
509
|
/**
|
|
409
510
|
* Pure ScriptProject mutations.
|
|
@@ -630,4 +731,4 @@ declare function DeleteConfirmButton({ onConfirm, disabled, targetScope, title,
|
|
|
630
731
|
description?: string;
|
|
631
732
|
}): react.JSX.Element;
|
|
632
733
|
|
|
633
|
-
export { type AssetAdapter, type AssetDeleteRequest, type AssetState, type ChangeSet, type ChatReference, DeleteConfirmButton, type DiffAdapter, EMPTY_SELECTION, EditableText, type EpisodeWorkspaceView, type FieldChange, Popover, type SaveStatus, type Scene, 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, buildSelectionFrom, computeChangeSet, fromToSelection, getActorCueVar, getActorMap, getEpisodeTitle, getLocationMap, getPropMap, getSceneContext, getSelectionEpisodeIdx, getSpeakerMap, isClipSelected, isEpisodeOpen, isSameSelectionTarget, isSceneSelected, index as mutations, sceneChangeKey, selectionFromScriptReference, selectionTargetKey, withOrigin };
|
|
734
|
+
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 };
|