@@ -2,12 +2,16 @@ import {BehaviorSubject} from 'rxjs';
2
2
import { SavedFormatting } from '../../state/formattings' ;
3
3
import { PersistedSlice } from '../../../../../json-crdt-extensions/peritext/slice/PersistedSlice' ;
4
4
import { subject } from '../../../../util/rx' ;
5
+ import { toSchema } from '../../../../../json-crdt/schema/toSchema' ;
6
+ import { Model , ObjApi } from '../../../../../json-crdt/model' ;
7
+ import { ObjNode } from '../../../../../json-crdt/nodes' ;
5
8
import type { Inline } from '../../../../../json-crdt-extensions' ;
6
9
import type { ToolbarState } from '../../state' ;
7
10
8
11
export class FormattingManageState {
9
12
public readonly selected$ = new BehaviorSubject < SavedFormatting | null > ( null ) ;
10
13
public readonly view$ = new BehaviorSubject < 'view' | 'edit' > ( 'view' ) ;
14
+ public readonly editing$ = new BehaviorSubject < SavedShadowFormatting | undefined > ( undefined ) ;
11
15
12
16
public constructor (
13
17
public readonly state : ToolbarState ,
@@ -38,4 +42,40 @@ export class FormattingManageState {
38
42
public readonly select = ( formatting : SavedFormatting | null ) => {
39
43
this . selected$ . next ( formatting ) ;
40
44
} ;
45
+
46
+ public readonly switchToViewPanel = ( ) : void => {
47
+ this . view$ . next ( 'view' ) ;
48
+ // TODO: Clear the `editing$` state
49
+ } ;
50
+
51
+ public readonly switchToEditPanel = ( ) : void => {
52
+ const selected = this . selected$ . getValue ( ) ;
53
+ if ( ! selected ) return ;
54
+ this . view$ . next ( 'edit' ) ;
55
+ const formatting = new SavedShadowFormatting ( selected ) ;
56
+ this . editing$ . next ( formatting ) ;
57
+ } ;
58
+
59
+ public readonly returnFromEditPanelAndSave = ( ) : void => {
60
+ console . log ( 'saveEdits' ) ;
61
+ } ;
62
+ }
63
+
64
+ export class SavedShadowFormatting < Node extends ObjNode = ObjNode > extends SavedFormatting < Node > {
65
+ protected _model : Model < any > ;
66
+
67
+ constructor ( protected readonly saved : SavedFormatting < Node > ) {
68
+ super ( saved . behavior , saved . range , saved . state ) ;
69
+ const nodeApi = saved . conf ( ) ;
70
+ const schema = nodeApi ? toSchema ( nodeApi . node ) : void 0 ;
71
+ this . _model = Model . create ( schema ) ;
72
+ }
73
+
74
+ public conf ( ) : ObjApi < Node > | undefined {
75
+ return this . _model . api . obj ( [ ] ) as ObjApi < Node > ;
76
+ }
77
+
78
+ public readonly save = ( ) => {
79
+ throw new Error ( 'save() not implemented' ) ;
80
+ } ;
41
81
}
0 commit comments