-
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.
feat(ScriptEditor): readOnlyNodeFilter, formatting, custom command
- Loading branch information
Showing
8 changed files
with
266 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.Prompter { | ||
--background-color: #000; | ||
--foreground-color: #fff; | ||
--header-color: #999; | ||
|
||
color: var(--foreground-color); | ||
background: var(--background-color); | ||
|
||
word-wrap: break-word; | ||
white-space: pre-wrap; | ||
white-space: break-spaces; | ||
} | ||
|
||
.Prompter p { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.Prompter b { | ||
font-weight: 700; | ||
} | ||
|
||
.Prompter i { | ||
font-style: italic; | ||
} | ||
|
||
.Prompter u { | ||
text-decoration: underline; | ||
} | ||
|
||
.Prompter s { | ||
text-decoration: none; | ||
opacity: 0.3; | ||
} | ||
|
||
.Prompter rev { | ||
background-color: var(--foreground-color); | ||
color: var(--background-color); | ||
} | ||
|
||
.Prompter h1, | ||
.Prompter h2, | ||
.Prompter h3 { | ||
background-color: var(--header-color); | ||
color: var(--background-color); | ||
user-select: none; | ||
margin: 1em 0; | ||
} |
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
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,12 @@ | ||
import React from 'react' | ||
import { Editor } from './Editor' | ||
|
||
import '../PrompterStyles.css' | ||
|
||
export function ScriptEditor(): React.JSX.Element { | ||
return ( | ||
<> | ||
<Editor className="bg-black" /> | ||
<Editor className="bg-black Prompter" /> | ||
</> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/apps/client/src/ScriptEditor/commands/deselectAll.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Command, TextSelection } from 'prosemirror-state' | ||
|
||
export const deselectAll: Command = (state, dispatch): boolean => { | ||
const newSelection = new TextSelection(state.selection.$to) | ||
const transaction = state.tr.setSelection(newSelection) | ||
if (dispatch) dispatch(transaction) | ||
|
||
return true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Command } from 'prosemirror-state' | ||
import { toggleMark } from 'prosemirror-commands' | ||
import { schema } from './scriptSchema' | ||
|
||
export const formatingKeymap: Record<string, Command> = { | ||
'Mod-b': toggleMark(schema.marks.bold), | ||
'Mod-i': toggleMark(schema.marks.italic), | ||
'Mod-u': toggleMark(schema.marks.underline), | ||
'Mod-q': toggleMark(schema.marks.reverse), | ||
'Mod-F10': toggleMark(schema.marks.hidden), | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/apps/client/src/ScriptEditor/plugins/readOnlyNodeFilter.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Plugin } from 'prosemirror-state' | ||
|
||
export function readOnlyNodeFilter() { | ||
return new Plugin({ | ||
filterTransaction: (tr, state): boolean => { | ||
if (!tr.docChanged) return true | ||
|
||
let editAllowed = true | ||
for (const step of tr.steps) { | ||
step.getMap().forEach((oldStart, oldEnd) => { | ||
state.doc.nodesBetween(oldStart, oldEnd, (node, _index, parent) => { | ||
if (node.type.spec.locked || parent?.type.spec.locked) { | ||
editAllowed = false | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
return editAllowed | ||
}, | ||
}) | ||
} |
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
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