1- import Data from '../../BootstrapBlazor/modules/data.js'
2- import { isFunction } from '../../BootstrapBlazor/modules/utility.js'
1+ import { isFunction , registerBootstrapBlazorModule } from '../../BootstrapBlazor/modules/utility.js'
32import { createUniverSheetAsync } from '../univer.js'
3+ import Data from '../../BootstrapBlazor/modules/data.js'
4+ import EventHandler from "../../BootstrapBlazor/modules/event-handler.js"
45
56export async function init ( id , invoke , options ) {
67 const el = document . getElementById ( id ) ;
@@ -24,6 +25,10 @@ export async function init(id, invoke, options) {
2425 Data . set ( id , univerSheet ) ;
2526
2627 invoke . invokeMethodAsync ( 'TriggerReadyAsync' ) ;
28+
29+ registerBootstrapBlazorModule ( 'UniverSheet' , id , ( ) => {
30+ EventHandler . on ( document , 'changed.bb.theme' , updateTheme ) ;
31+ } ) ;
2732}
2833
2934export function execute ( id , data ) {
@@ -39,4 +44,28 @@ export function dispose(id) {
3944 if ( isFunction ( univerSheet . dispose ) ) {
4045 univerSheet . dispose ( ) ;
4146 }
47+
48+ const { UniverSheet } = window . BootstrapBlazor ;
49+ if ( UniverSheet ) {
50+ UniverSheet . dispose ( id , ( ) => {
51+ EventHandler . off ( document , 'changed.bb.theme' , updateTheme ) ;
52+ } ) ;
53+ }
54+ }
55+
56+ const updateTheme = e => {
57+ const theme = e . theme ;
58+
59+ [ ...document . querySelectorAll ( '.bb-univer-sheet' ) ] . forEach ( s => {
60+ const id = s . getAttribute ( 'id' ) ;
61+ if ( id ) {
62+ const univerSheet = Data . get ( id ) ;
63+ if ( univerSheet && univerSheet . darkMode === null ) {
64+ const { univerAPI } = univerSheet ;
65+ if ( univerAPI ) {
66+ univerAPI . toggleDarkMode ( theme === 'dark' ) ;
67+ }
68+ }
69+ }
70+ } ) ;
4271}
0 commit comments