aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/dumbymap.mjs14
-rw-r--r--src/editor.mjs35
2 files changed, 32 insertions, 17 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index f4e3d83..e5dd2cd 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -348,16 +348,20 @@ export const generateMaps = (container, {
348 const mapElement = renderer.target 348 const mapElement = renderer.target
349 // FIXME 349 // FIXME
350 mapElement.renderer = renderer 350 mapElement.renderer = renderer
351 // Make map not focusable by tab key
351 mapElement.tabindex = -1 352 mapElement.tabindex = -1
353
354 // Cache if render is fulfilled
352 if (mapElement.dataset.render === 'fulfilled') { 355 if (mapElement.dataset.render === 'fulfilled') {
353 mapCache[mapElement.id] = renderer 356 mapCache[mapElement.id] = renderer
354 } else { 357 } else {
355 return 358 return
356 } 359 }
357 360
361 // Simple callback by caller
358 renderCallback?.(renderer) 362 renderCallback?.(renderer)
359 363
360 // Work with Mutation Observer 364 // Watch change of class
361 const observer = mapClassObserver() 365 const observer = mapClassObserver()
362 observer.observe(mapElement, { 366 observer.observe(mapElement, {
363 attributes: true, 367 attributes: true,
@@ -367,6 +371,14 @@ export const generateMaps = (container, {
367 onRemove(dumbymap.htmlHolder, () => { 371 onRemove(dumbymap.htmlHolder, () => {
368 observer.disconnect() 372 observer.disconnect()
369 }) 373 })
374
375 // Focus current map is no map is focused
376 if (
377 !dumbymap.utils.renderedMaps().find(map => map.classList.contains('focus')) ||
378 container.querySelectorAll('.mapclay.focus').length === 0
379 ) {
380 mapElement.classList.add('focus')
381 }
370 } 382 }
371 383
372 // Set unique ID for map container 384 // Set unique ID for map container
diff --git a/src/editor.mjs b/src/editor.mjs
index ecf3735..fd18f78 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -20,12 +20,25 @@ import * as tutorial from './tutorial'
20const url = new URL(window.location) 20const url = new URL(window.location)
21const pageParams = url.searchParams 21const pageParams = url.searchParams
22const crs = pageParams.get('crs') ?? 'EPSG:4326' 22const crs = pageParams.get('crs') ?? 'EPSG:4326'
23const initialLayout = pageParams.get('layout')
23 24
24/** Variables: dumbymap and editor **/ 25/** Variables: dumbymap and editor **/
25const context = document.querySelector('[data-mode]') 26const context = document.querySelector('[data-mode]')
27const textArea = document.querySelector('.editor textarea')
26const dumbyContainer = document.querySelector('.DumbyMap') 28const dumbyContainer = document.querySelector('.DumbyMap')
27dumbyContainer.dataset.scrollLine = '' 29dumbyContainer.dataset.scrollLine = ''
28const textArea = document.querySelector('.editor textarea') 30/** Watch: Layout of DumbyMap */
31new window.MutationObserver(mutaions => {
32 const mutation = mutaions.at(-1)
33 const layout = dumbyContainer.dataset.layout
34 if (layout !== 'normal' || mutation.oldValue === 'normal') {
35 delete context.dataset.mode
36 }
37}).observe(dumbyContainer, {
38 attributes: true,
39 attributeFilter: ['data-layout'],
40 attributeOldValue: true,
41})
29let dumbymap 42let dumbymap
30 43
31/** Variables: Reference Style Links in Markdown */ 44/** Variables: Reference Style Links in Markdown */
@@ -472,7 +485,11 @@ const updateDumbyMap = (callback = null) => {
472 485
473 callback?.(dumbymap) 486 callback?.(dumbymap)
474} 487}
475updateDumbyMap() 488updateDumbyMap(() => {
489 if (initialLayout) {
490 dumbyContainer.dataset.layout = initialLayout
491 }
492})
476 493
477// Re-render HTML by editor content 494// Re-render HTML by editor content
478cm.on('change', (_, change) => { 495cm.on('change', (_, change) => {
@@ -931,20 +948,6 @@ document.onkeydown = e => {
931 948
932// }}} 949// }}}
933// }}} 950// }}}
934// Layout Switch {{{
935new window.MutationObserver(mutaions => {
936 const mutation = mutaions.at(-1)
937 const layout = dumbyContainer.dataset.layout
938 if (layout !== 'normal' || mutation.oldValue === 'normal') {
939 delete context.dataset.mode
940 }
941}).observe(dumbyContainer, {
942 attributes: true,
943 attributeFilter: ['data-layout'],
944 attributeOldValue: true,
945})
946// }}}
947
948/** 951/**
949 * addMapRandomlyByPreset. insert random text of valid mapclay yaml into editor 952 * addMapRandomlyByPreset. insert random text of valid mapclay yaml into editor
950 */ 953 */