1
- import { leftBarTrackScaleWidth , useTimeline } from '@aitube/timeline'
2
1
import Editor , { Monaco } from '@monaco-editor/react'
2
+ import {
3
+ leftBarTrackScaleWidth ,
4
+ TimelineStore ,
5
+ useTimeline ,
6
+ } from '@aitube/timeline'
3
7
import MonacoEditor from 'monaco-editor'
4
8
import { useEffect } from 'react'
5
9
6
10
import { useScriptEditor } from '@/services/editors/script-editor/useScriptEditor'
7
11
import { useUI } from '@/services/ui'
8
12
import { themes } from '@/services/ui/theme'
9
13
10
- import { ScriptEditorStore } from '@aitube/clapper-services'
11
14
import './styles.css'
12
15
13
16
export function ScriptEditor ( ) {
@@ -18,25 +21,14 @@ export function ScriptEditor() {
18
21
const current = useScriptEditor ( ( s ) => s . current )
19
22
const setCurrent = useScriptEditor ( ( s ) => s . setCurrent )
20
23
const publish = useScriptEditor ( ( s ) => s . publish )
21
- const onDidScrollChange = useScriptEditor (
22
- ( s : ScriptEditorStore ) => s . onDidScrollChange
23
- )
24
- const jumpCursorOnLineClick = useScriptEditor (
25
- ( s : { jumpCursorOnLineClick : any } ) => s . jumpCursorOnLineClick
26
- )
27
- const highlightElements = useScriptEditor (
28
- ( s : { highlightElements : any } ) => s . highlightElements
29
- )
30
- const applyClassNameToKeywords = useScriptEditor (
31
- ( s : { applyClassNameToKeywords : any } ) => s . applyClassNameToKeywords
32
- )
24
+ const onDidScrollChange = useScriptEditor ( ( s ) => s . onDidScrollChange )
25
+ const jumpCursorOnLineClick = useScriptEditor ( ( s ) => s . jumpCursorOnLineClick )
26
+ const highlightElements = useScriptEditor ( ( s ) => s . highlightElements )
33
27
34
- const scrollHeight = useScriptEditor (
35
- ( s : { scrollHeight : any } ) => s . scrollHeight
36
- )
28
+ const scrollHeight = useScriptEditor ( ( s ) => s . scrollHeight )
37
29
38
- const scrollX = useTimeline ( ( s : { scrollX : any } ) => s . scrollX )
39
- const contentWidth = useTimeline ( ( s : { contentWidth : any } ) => s . contentWidth )
30
+ const scrollX = useTimeline ( ( s ) => s . scrollX )
31
+ const contentWidth = useTimeline ( ( s ) => s . contentWidth )
40
32
const horizontalTimelineRatio = Math . round (
41
33
( ( scrollX - leftBarTrackScaleWidth ) / contentWidth ) * scrollHeight - 31
42
34
)
@@ -98,38 +90,37 @@ export function ScriptEditor() {
98
90
// as an optimization we can use this later, for surgical edits,
99
91
// to perform real time updates of the timeline
100
92
101
- /* textModel.onDidChangeContent(
102
- (
103
- modelContentChangedEvent: MonacoEditor.editor.IModelContentChangedEvent
104
- ) => {
105
- console.log('onDidChangeContent:')
106
- for (const change of modelContentChangedEvent.changes) {
107
- console.log(" - change:", change)
108
- }
109
- }
110
- )
111
- */
93
+ /*
94
+ textModel.onDidChangeContent(
95
+ (
96
+ modelContentChangedEvent: MonacoEditor.editor.IModelContentChangedEvent
97
+ ) => {
98
+ console.log('onDidChangeContent:')
99
+ for (const change of modelContentChangedEvent.changes) {
100
+ console.log(" - change:", change)
101
+ }
102
+ }
103
+ )
104
+ */
112
105
highlightElements ( )
113
106
}
114
107
115
- const setMonaco = useScriptEditor ( ( s : { setMonaco : any } ) => s . setMonaco )
116
- const setTextModel = useScriptEditor (
117
- ( s : { setTextModel : any } ) => s . setTextModel
118
- )
119
- const setMouseIsInside = useScriptEditor (
120
- ( s : { setMouseIsInside : any } ) => s . setMouseIsInside
121
- )
108
+ const setMonaco = useScriptEditor ( ( s ) => s . setMonaco )
109
+ const setTextModel = useScriptEditor ( ( s ) => s . setTextModel )
110
+ const setMouseIsInside = useScriptEditor ( ( s ) => s . setMouseIsInside )
122
111
const themeName = useUI ( ( s ) => s . themeName )
123
112
const editorFontSize = useUI ( ( s ) => s . editorFontSize )
124
113
125
114
const beforeMount = ( monaco : Monaco ) => {
126
115
setMonaco ( monaco )
127
116
128
- // Create themes
117
+ // create our themes
129
118
for ( const theme of Object . values ( themes ) ) {
119
+ // console.log("loading editor theme:", theme)
120
+ // Define a custom theme with the provided color palette
130
121
monaco . editor . defineTheme ( theme . id , {
131
- base : 'vs-dark' ,
132
- inherit : true ,
122
+ base : 'vs-dark' , // Base theme (you can change to vs for a lighter theme if preferred)
123
+ inherit : true , // Inherit the default rules
133
124
rules : [
134
125
{ token : 'scene.int' , foreground : '#4EC9B0' } ,
135
126
{ token : 'scene.ext' , foreground : '#9CDCFE' } ,
@@ -142,17 +133,17 @@ export function ScriptEditor() {
142
133
] ,
143
134
colors : {
144
135
'editor.background' :
145
- theme . editorBgColor || theme . defaultBgColor || '#000000' ,
136
+ theme . editorBgColor || theme . defaultBgColor || '#000000' , // Editor background color (given)
146
137
'editorCursor.foreground' :
147
- theme . editorCursorColor || theme . defaultPrimaryColor || '' ,
148
- 'editor.lineHighlightBackground' : '#44403c' ,
149
- 'editorLineNumber.foreground' : '#78716c' ,
150
- 'editor.selectionBackground' : '#44403c' ,
138
+ theme . editorCursorColor || theme . defaultPrimaryColor || '' , // Cursor color
139
+ 'editor.lineHighlightBackground' : '#44403c' , // Highlighted line color
140
+ 'editorLineNumber.foreground' : '#78716c' , // Line Numbers color
141
+ 'editor.selectionBackground' : '#44403c' , // Selection color
151
142
'editor.foreground' :
152
- theme . editorTextColor || theme . defaultTextColor || '' ,
153
- 'editorIndentGuide.background' : '#78716c' ,
154
- 'editorIndentGuide.activeBackground' : '#a8a29e' ,
155
- 'editorWhitespace.foreground' : '#a8a29e' ,
143
+ theme . editorTextColor || theme . defaultTextColor || '' , // Main text color
144
+ 'editorIndentGuide.background' : '#78716c' , // Indent guides color
145
+ 'editorIndentGuide.activeBackground' : '#a8a29e' , // Active indent guides color
146
+ 'editorWhitespace.foreground' : '#a8a29e' , // Whitespace symbols color
156
147
} ,
157
148
} )
158
149
}
0 commit comments