@lincyaw/kernel 1.0.0-rc.55 → 1.0.0-rc.57
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
package/src/authoring.ts
CHANGED
|
@@ -28,6 +28,8 @@ export const DOCUMENT_CHANGE_JSON_SCHEMA: Schema = {
|
|
|
28
28
|
operation('updateSection', { sectionId: id, title: { type: 'string' }, layout: ref('Layout') }, ['sectionId']),
|
|
29
29
|
operation('setStepState', { stepId: id, visuals: { type: 'array', items: ref('Visual') }, inherits: id }, ['stepId', 'visuals']),
|
|
30
30
|
operation('setNarration', { narration: ref('Narration'), stepId: id, index }, ['narration']),
|
|
31
|
+
operation('removeNarration', { stepId: id, narrationId: id }),
|
|
32
|
+
operation('setStepNarrations', { stepId: id, narrationIds: { type: 'array', maxItems: 1000, items: id, uniqueItems: true, description: 'Complete ordered existing narration IDs for this step. Omitted references are removed; entities still used by other steps remain.' } }),
|
|
31
33
|
operation('setTiming', { stepId: id, sectionId: id, value: ref('StepProduction') }, ['value']),
|
|
32
34
|
operation('replaceAsset', { asset: ref('Asset') }),
|
|
33
35
|
] },
|
|
@@ -6,7 +6,7 @@ import type { DocumentOutlineAnswer, DocumentOutlineQuery, DocumentPartAnswer, D
|
|
|
6
6
|
import type { AppliedDocumentAuthoringAction, DocumentAuthoringActionInspection, DocumentAuthoringActionPlan, DocumentAuthoringActionRead, DocumentAuthoringActionReference, DocumentAuthoringActionRequest, DocumentAuthoringAction, DocumentComponentImpactAnswer, DocumentComponentImpactQuery } from './authoring-actions.ts'
|
|
7
7
|
|
|
8
8
|
export const AUTHORING_API_VERSION = 1 as const
|
|
9
|
-
export const DOCUMENT_OPERATION_TYPES = ['insertBlock', 'moveBlock', 'deleteBlock', 'updateText', 'updateSection', 'setStepState', 'setNarration', 'setTiming', 'replaceAsset'] as const satisfies readonly DocumentEditOperation['type'][]
|
|
9
|
+
export const DOCUMENT_OPERATION_TYPES = ['insertBlock', 'moveBlock', 'deleteBlock', 'updateText', 'updateSection', 'setStepState', 'setNarration', 'removeNarration', 'setStepNarrations', 'setTiming', 'replaceAsset'] as const satisfies readonly DocumentEditOperation['type'][]
|
|
10
10
|
|
|
11
11
|
export interface AuthoringCapabilities {
|
|
12
12
|
apiVersion: typeof AUTHORING_API_VERSION
|
|
@@ -249,5 +249,7 @@ export type DocumentEditOperation =
|
|
|
249
249
|
| { type: 'updateSection', sectionId: SectionId, title?: string, layout?: Layout }
|
|
250
250
|
| { type: 'setStepState', stepId: StepId, visuals: VisualState[], inherits?: StepId }
|
|
251
251
|
| { type: 'setNarration', narration: Narration, stepId?: StepId, index?: number }
|
|
252
|
+
| { type: 'removeNarration', stepId: StepId, narrationId: NarrationId }
|
|
253
|
+
| { type: 'setStepNarrations', stepId: StepId, narrationIds: NarrationId[] }
|
|
252
254
|
| { type: 'setTiming', stepId?: StepId, sectionId?: SectionId, value: StepProduction }
|
|
253
255
|
| { type: 'replaceAsset', asset: Asset }
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isDocumentPlaceAnchor } from './contracts/document.ts'
|
|
2
2
|
import { degradeDocumentCommentAnchor } from './document-comments.ts'
|
|
3
|
+
import { replaceStepNarrations } from './document-narrations.ts'
|
|
3
4
|
import type { DocumentBlock, DocumentEditOperation, TeachingDocument } from './contracts/document.ts'
|
|
4
5
|
|
|
5
6
|
/** Operations describe author intent; the caller validates the resulting complete document before committing it. */
|
|
6
7
|
export function applyDocumentOperations(source: TeachingDocument, operations: readonly DocumentEditOperation[]): TeachingDocument {
|
|
7
8
|
if (!operations.length || operations.length > 1000) throw new Error('document-operation-count')
|
|
8
|
-
|
|
9
|
+
let document = structuredClone(source)
|
|
9
10
|
const block = (id: string): DocumentBlock => {
|
|
10
11
|
if (!Object.hasOwn(document.blocks, id)) throw new Error('document-block-missing')
|
|
11
12
|
return document.blocks[id]!
|
|
@@ -129,6 +130,21 @@ export function applyDocumentOperations(source: TeachingDocument, operations: re
|
|
|
129
130
|
}
|
|
130
131
|
break
|
|
131
132
|
}
|
|
133
|
+
case 'removeNarration': {
|
|
134
|
+
const value = step(operation.stepId)
|
|
135
|
+
if (!value.narrationIds.includes(operation.narrationId)) throw new Error('document-narration-target')
|
|
136
|
+
document = replaceStepNarrations(document, value.id, value.narrationIds.filter(id => id !== operation.narrationId).map(id => document.narrations[id]!))
|
|
137
|
+
break
|
|
138
|
+
}
|
|
139
|
+
case 'setStepNarrations': {
|
|
140
|
+
step(operation.stepId)
|
|
141
|
+
const narrations = operation.narrationIds.map(id => {
|
|
142
|
+
if (!Object.hasOwn(document.narrations, id)) throw new Error('document-narration-target')
|
|
143
|
+
return document.narrations[id]!
|
|
144
|
+
})
|
|
145
|
+
document = replaceStepNarrations(document, operation.stepId, narrations)
|
|
146
|
+
break
|
|
147
|
+
}
|
|
132
148
|
case 'setTiming':
|
|
133
149
|
if (operation.stepId && operation.sectionId) throw new Error('document-timing-scope')
|
|
134
150
|
if (operation.stepId) { step(operation.stepId); put(document.production.stepOverrides, operation.stepId, operation.value) }
|