aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/editor.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-23 12:45:40 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-23 16:50:30 +0800
commit24c4fe6d2fa8c1824129535502d4f619fcf0f912 (patch)
treecfec74036861ca3e63e6c50ca9e36abdb463895e /src/editor.mjs
parent1e1ad1a1f8dc738d1f716646ceed30174ee76331 (diff)
refactor: set observers for charactorData/childList separately
* this patches e774e55, make code easier to understanded * use data attribute to initialize content in container * add limitation on method replaceNode(), to prevent GeoLinks generated in pre/code/a element
Diffstat (limited to 'src/editor.mjs')
-rw-r--r--src/editor.mjs24
1 files changed, 3 insertions, 21 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 3a70ae6..430353a 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -30,22 +30,17 @@ dumbyContainer.dataset.scrollLine = ''
30new window.MutationObserver(mutations => { 30new window.MutationObserver(mutations => {
31 const mutation = mutations.at(-1) 31 const mutation = mutations.at(-1)
32 32
33 /** Handle layout change */ 33 // Handle layout change
34 const layout = dumbyContainer.dataset.layout 34 const layout = dumbyContainer.dataset.layout
35 if (layout !== 'normal' || mutation.oldValue === 'normal') { 35 if (layout && (layout !== 'normal' || mutation.oldValue === 'normal')) {
36 context.dataset.mode = '' 36 context.dataset.mode = ''
37 } 37 }
38}).observe(dumbyContainer, { 38}).observe(dumbyContainer, {
39 attributes: true, 39 attributes: true,
40 attributeFilter: ['data-layout'], 40 attributeFilter: ['data-layout'],
41 attributeOldValue: true, 41 attributeOldValue: true,
42 childList: true,
43 subtree: true,
44}) 42})
45const dumbymap = generateMaps(dumbyContainer, { crs }) 43const dumbymap = generateMaps(dumbyContainer, { crs, initialLayout })
46if (initialLayout) {
47 dumbyContainer.dataset.layout = initialLayout
48}
49// Set oncontextmenu callback 44// Set oncontextmenu callback
50dumbymap.utils.setContextMenu(menuForEditor) 45dumbymap.utils.setContextMenu(menuForEditor)
51 46
@@ -431,19 +426,6 @@ const completeForCodeBlock = change => {
431 } 426 }
432} 427}
433 428
434/* Disable debounce temporarily */
435// const debounceForMap = (() => {
436// const timer = null
437//
438// return function (...args) {
439// dumbymap = generateMaps.apply(this, args)
440// clearTimeout(timer);
441// timer = setTimeout(() => {
442// dumbymap = generateMaps.apply(this, args)
443// }, 10);
444// }
445// })()
446
447/** 429/**
448 * menuForEditor. 430 * menuForEditor.
449 * 431 *