diff --git a/packages/apps/backend/src/api-server/services/PartService.ts b/packages/apps/backend/src/api-server/services/PartService.ts index 71d8f01..0c5c433 100644 --- a/packages/apps/backend/src/api-server/services/PartService.ts +++ b/packages/apps/backend/src/api-server/services/PartService.ts @@ -116,8 +116,14 @@ export class PartService extends EventEmitter implements Defi throw new NotImplemented(`Not supported`) } - public async updateScript(_id: Id, _scriptContents: ScriptContents): Promise { - throw new NotImplemented(`Not implemented`) + public async updateScript( + data: { + partId: Id + script: ScriptContents + }, + _params?: Params + ): Promise { + this.store.parts.updateScript(data.partId, data.script) } } type Result = Definition.Result diff --git a/packages/apps/backend/src/data-stores/PartStore.ts b/packages/apps/backend/src/data-stores/PartStore.ts index e9032d6..1705461 100644 --- a/packages/apps/backend/src/data-stores/PartStore.ts +++ b/packages/apps/backend/src/data-stores/PartStore.ts @@ -1,6 +1,6 @@ import { IReactionDisposer, action, autorun, makeObservable, observable } from 'mobx' import isEqual from 'lodash.isequal' -import { Part, PartId } from '@sofie-prompter-editor/shared-model' +import { Part, PartId, ScriptContents } from '@sofie-prompter-editor/shared-model' import { Transformers } from '../sofie-core-connection/dataTransformers/Transformers.js' import * as Core from '../sofie-core-connection/CoreDataTypes/index.js' @@ -8,14 +8,10 @@ import * as Core from '../sofie-core-connection/CoreDataTypes/index.js' export class PartStore { public readonly parts = observable.map() + private readonly _partScripts = observable.map() + private partAutoruns = new Map() - constructor() { - makeObservable(this, { - _updatePart: action, - _removePart: action, - }) - } connectTransformers(transformers: Transformers) { // Observe and retrieve parts from the transformer: autorun(() => { @@ -56,10 +52,29 @@ export class PartStore { } }) } - _updatePart(partId: PartId, part: Part) { - this.parts.set(partId, part) - } - _removePart(partId: PartId) { + + updateScript = action((id: PartId, scriptContents: string) => { + this._partScripts.set(id, scriptContents) + + const part = this.parts.get(id) + if (!part) throw new Error('Not found') + + this.parts.set(id, { + ...part, + editedScriptContents: scriptContents, + }) + }) + + private _updatePart = action((partId: PartId, part: Omit) => { + const partExtended: Part = { + ...part, + editedScriptContents: this._partScripts.get(partId), + } + + this.parts.set(partId, partExtended) + }) + private _removePart = action((partId: PartId) => { this.parts.delete(partId) - } + this._partScripts.delete(partId) + }) } diff --git a/packages/apps/client/src/components/RundownOutput/Line.tsx b/packages/apps/client/src/components/RundownOutput/Line.tsx index d8e0726..4e3fe9d 100644 --- a/packages/apps/client/src/components/RundownOutput/Line.tsx +++ b/packages/apps/client/src/components/RundownOutput/Line.tsx @@ -6,10 +6,11 @@ export const Line = observer(function Line({ line }: { line: UILine }): React.Re return ( <>

{line.slug}

- {!line.script ?

 

: null} - {line.script?.split('\n').map((paragraph) => ( -

{paragraph}

- ))} + {!line.script ? ( +

 

+ ) : ( + line.script.split('\n').map((paragraph, i) =>

{paragraph}

) + )} ) }) diff --git a/packages/apps/client/src/lib/prosemirrorDoc.ts b/packages/apps/client/src/lib/prosemirrorDoc.ts index 94a8f5d..f228529 100644 --- a/packages/apps/client/src/lib/prosemirrorDoc.ts +++ b/packages/apps/client/src/lib/prosemirrorDoc.ts @@ -56,9 +56,9 @@ export function toMarkdown(nodes: ProsemirrorNode[]): string { function stringifyMarkdown(mdAst: MdAstNode): string { if (mdAst.type === 'root') { - return mdAst.children.map(stringifyMarkdown).join('') + return mdAst.children.map(stringifyMarkdown).join('\n') } else if (mdAst.type === 'paragraph') { - return mdAst.children.map(stringifyMarkdown).join('') + '\n' + return mdAst.children.map(stringifyMarkdown).join('') } else if (mdAst.type === 'text') { return mdAst.value } else if (mdAst.type === 'emphasis' || mdAst.type === 'strong' || mdAst.type === 'reverse') { diff --git a/packages/apps/client/src/model/UIRundown.ts b/packages/apps/client/src/model/UIRundown.ts index 5f65f96..8d5d7b0 100644 --- a/packages/apps/client/src/model/UIRundown.ts +++ b/packages/apps/client/src/model/UIRundown.ts @@ -148,9 +148,11 @@ export class UIRundown { existing.updateFromJson(json) }) - async updatePartScript(id: PartId, script: ScriptContents): Promise { - // TODO - is this in the correct place? - await this.store.connection.part.updateScript(id, script) + async updatePartScript(partId: PartId, script: ScriptContents): Promise { + await this.store.connection.part.updateScript({ + partId, + script, + }) // TODO - should this have any side effects? } diff --git a/packages/shared/model/src/client-server-api/PartService.ts b/packages/shared/model/src/client-server-api/PartService.ts index 50b0777..dbe2a92 100644 --- a/packages/shared/model/src/client-server-api/PartService.ts +++ b/packages/shared/model/src/client-server-api/PartService.ts @@ -35,7 +35,13 @@ interface Methods extends Omit { /** updates .isNew */ // setIsNew(read: boolean): Promise - updateScript(id: Id, scriptContents: ScriptContents): Promise + updateScript( + data: { + partId: Id + script: ScriptContents + }, + params?: Params + ): Promise } export interface Service extends Methods, EventEmitter {} diff --git a/packages/shared/model/src/model/Part.ts b/packages/shared/model/src/model/Part.ts index 130cf9e..8d66e66 100644 --- a/packages/shared/model/src/model/Part.ts +++ b/packages/shared/model/src/model/Part.ts @@ -46,7 +46,9 @@ export interface Part extends DataObject { label: string // ie sourceLayer.name in Sofie } + /** scriptContents from Core */ scriptContents?: ScriptContents + /** edited scriptContents. While this is set, display this in favor of scriptContents */ editedScriptContents?: ScriptContents }