2023-04-13 04:21:25 -04:00
|
|
|
import { Compartment, EditorState, TransactionSpec } from '@codemirror/state'
|
2023-04-20 05:59:09 -04:00
|
|
|
import { EditorView } from '@codemirror/view'
|
2023-04-13 04:21:25 -04:00
|
|
|
|
|
|
|
const readOnlyConf = new Compartment()
|
|
|
|
|
|
|
|
export const editable = () => {
|
2023-04-20 05:59:09 -04:00
|
|
|
return [
|
|
|
|
readOnlyConf.of([
|
|
|
|
EditorState.readOnly.of(true),
|
|
|
|
EditorView.editable.of(false),
|
|
|
|
]),
|
|
|
|
]
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const setEditable = (value = true): TransactionSpec => {
|
|
|
|
return {
|
2023-04-20 05:59:09 -04:00
|
|
|
effects: [
|
|
|
|
readOnlyConf.reconfigure([
|
|
|
|
EditorState.readOnly.of(!value),
|
|
|
|
EditorView.editable.of(value),
|
|
|
|
]),
|
|
|
|
],
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
}
|