|
28 | 28 |
|
29 | 29 | markDownEditor.$connector = {}; |
30 | 30 |
|
31 | | - const supportedTheme = theme => ['light', 'dark'].includes(theme); |
32 | | - |
| 31 | + const supportedTheme = theme => ['light', 'dark'].includes(theme); |
| 32 | + |
33 | 33 | const setDataColorMode = theme => { |
34 | 34 | if (supportedTheme(theme)) { |
35 | 35 | markDownEditor.setAttribute('data-color-mode', theme); |
36 | 36 | } else { |
37 | | - markDownEditor.removeAttribute('data-color-mode'); |
| 37 | + // force light theme which is Vaadin's default theme |
| 38 | + markDownEditor.setAttribute('data-color-mode', 'light'); |
38 | 39 | } |
39 | 40 | }; |
40 | 41 |
|
|
43 | 44 | if (supportedTheme(mainTheme)) { |
44 | 45 | setDataColorMode(mainTheme); |
45 | 46 | } else { |
46 | | - // Listen for theme changes in body element otherwise |
| 47 | + // set light theme by default |
| 48 | + markDownEditor.setAttribute('data-color-mode', 'light'); |
| 49 | + } |
47 | 50 |
|
48 | | - // options for the observer (which mutations to observe) |
49 | | - const config = { attributes: true }; |
| 51 | + // options for the observer (which mutations to observe) |
| 52 | + const config = { attributes: true }; |
50 | 53 |
|
51 | | - // callback function to execute when mutations are observed |
52 | | - const callback = (mutationList, observer) => { |
53 | | - for (const mutation of mutationList) { |
54 | | - if (mutation.type === 'attributes' && mutation.attributeName === 'theme') { |
55 | | - const themeName = mutation.target.getAttribute(mutation.attributeName); |
56 | | - setDataColorMode(themeName); |
57 | | - } |
| 54 | + // callback function to execute when mutations are observed |
| 55 | + const callback = (mutationList, observer) => { |
| 56 | + for (const mutation of mutationList) { |
| 57 | + if (mutation.type === 'attributes' && mutation.attributeName === 'theme') { |
| 58 | + const themeName = mutation.target.getAttribute(mutation.attributeName); |
| 59 | + console.log("theme", themeName); |
| 60 | + setDataColorMode(themeName); |
58 | 61 | } |
59 | | - }; |
| 62 | + } |
| 63 | + }; |
60 | 64 |
|
61 | | - // create an observer instance linked to the callback function |
62 | | - markDownEditor.$connector.themeChangeObserver = new MutationObserver(callback); |
| 65 | + // create an observer instance linked to the callback function |
| 66 | + markDownEditor.$connector.themeChangeObserver = new MutationObserver(callback); |
63 | 67 |
|
64 | | - // start observing html tag for configured mutations |
65 | | - markDownEditor.$connector.themeChangeObserver.observe(document.documentElement, config); |
| 68 | + // observe html tag for configured mutations |
| 69 | + markDownEditor.$connector.themeChangeObserver.observe(document.documentElement, config); |
66 | 70 |
|
67 | | - // start observing body tag for configured mutations |
68 | | - markDownEditor.$connector.themeChangeObserver.observe(document.body, config); |
69 | | - } |
| 71 | + // observe body tag for configured mutations |
| 72 | + markDownEditor.$connector.themeChangeObserver.observe(document.body, config); |
70 | 73 | }, |
71 | 74 | unobserveThemeChange: markDownEditor => { |
72 | 75 | // stop observing the target node for configured mutations |
|
0 commit comments