-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ScriptEditor): rename nodes in Schema to match the rest of the UI
- Loading branch information
Showing
3 changed files
with
50 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 28 additions & 3 deletions
31
packages/apps/client/src/ScriptEditor/plugins/updateModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import { Plugin } from 'prosemirror-state' | ||
import { UILineId } from '../../model/UILine' | ||
|
||
export function updateModel() { | ||
export function updateModel(onChange?: (lineId: UILineId, contents: SomeContents) => void) { | ||
return new Plugin({ | ||
appendTransaction: () => { | ||
// console.log(newState) | ||
appendTransaction: (trs, oldState, newState) => { | ||
const anyChanges = trs.reduce<boolean>((memo, tr) => memo || tr.docChanged, false) | ||
if (!anyChanges) return null | ||
|
||
for (const tr of trs) { | ||
for (const step of tr.steps) { | ||
step.getMap().forEach((oldStart, oldEnd, newStart, newEnd) => { | ||
oldState.doc.nodesBetween(oldStart, oldEnd, (_node, _pos, parent) => { | ||
if (!parent) return | ||
if (parent.type.name !== 'line') return | ||
|
||
const lineId = parent.attrs['lineId'] as UILineId | ||
|
||
newState.doc.nodesBetween(newStart, newEnd, (_node, _pos, parent) => { | ||
if (!parent) return | ||
if (parent.type.name !== 'line') return | ||
|
||
if (onChange) onChange(lineId, parent.toString()) | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
return null | ||
}, | ||
}) | ||
} | ||
|
||
type SomeContents = unknown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters