diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-05 14:58:37 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-05 18:58:23 +0800 |
| commit | 7ee20b87e0ae47a5220e8e0aad5f56cf8b262f7e (patch) | |
| tree | b27243bf28dd3ff2d38752fef05af14f4f8b3132 /src | |
| parent | 849a9ededf3aa90a8a0e7ccd5d752f51f47a6642 (diff) | |
style: reformat code
remove mapCallback for now
Diffstat (limited to 'src')
| -rw-r--r-- | src/MenuItem.mjs | 10 | ||||
| -rw-r--r-- | src/dumbymap.mjs | 12 | ||||
| -rw-r--r-- | src/editor.mjs | 15 |
3 files changed, 14 insertions, 23 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index 1b58e0b..dbe984f 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs | |||
| @@ -9,9 +9,9 @@ export class Item extends window.HTMLDivElement { | |||
| 9 | /** | 9 | /** |
| 10 | * constructor. | 10 | * constructor. |
| 11 | * | 11 | * |
| 12 | * @param {} | 12 | * @param {Object} |
| 13 | */ | 13 | */ |
| 14 | constructor ({ text, innerHTML, onclick, style, className, onmouseover }) { | 14 | constructor ({ text, innerHTML, onclick, style, className }) { |
| 15 | super() | 15 | super() |
| 16 | this.innerHTML = innerHTML ?? text | 16 | this.innerHTML = innerHTML ?? text |
| 17 | this.onclick = onclick | 17 | this.onclick = onclick |
| @@ -342,3 +342,9 @@ export const toggleMapFocus = map => | |||
| 342 | text: 'Toggle Focus', | 342 | text: 'Toggle Focus', |
| 343 | onclick: () => map.classList.toggle('focus') | 343 | onclick: () => map.classList.toggle('focus') |
| 344 | }) | 344 | }) |
| 345 | |||
| 346 | export const getCoordinatesByPixels = (map, xy) => | ||
| 347 | new Item({ | ||
| 348 | text: 'Get Coordinates', | ||
| 349 | onclick: () => console.log(map.renderer.unproject(xy)) | ||
| 350 | }) | ||
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index e1bf220..512409b 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
| @@ -2,13 +2,13 @@ import MarkdownIt from 'markdown-it' | |||
| 2 | import MarkdownItAnchor from 'markdown-it-anchor' | 2 | import MarkdownItAnchor from 'markdown-it-anchor' |
| 3 | import MarkdownItFootnote from 'markdown-it-footnote' | 3 | import MarkdownItFootnote from 'markdown-it-footnote' |
| 4 | import MarkdownItFrontMatter from 'markdown-it-front-matter' | 4 | import MarkdownItFrontMatter from 'markdown-it-front-matter' |
| 5 | import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' | ||
| 5 | import { renderWith, defaultAliases, parseConfigsFromYaml } from 'mapclay' | 6 | import { renderWith, defaultAliases, parseConfigsFromYaml } from 'mapclay' |
| 6 | import { onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' | 7 | import { onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' |
| 7 | import { Layout, SideBySide, Overlay } from './Layout' | 8 | import { Layout, SideBySide, Overlay } from './Layout' |
| 8 | import * as utils from './dumbyUtils' | 9 | import * as utils from './dumbyUtils' |
| 9 | import * as menuItem from './MenuItem' | 10 | import * as menuItem from './MenuItem' |
| 10 | import PlainModal from 'plain-modal' | 11 | import PlainModal from 'plain-modal' |
| 11 | import markdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' | ||
| 12 | 12 | ||
| 13 | const mapBlockSelector = 'pre:has(.language-map)' | 13 | const mapBlockSelector = 'pre:has(.language-map)' |
| 14 | const docLinkSelector = 'a[href^="#"][title^="=>"]' | 14 | const docLinkSelector = 'a[href^="#"][title^="=>"]' |
| @@ -46,7 +46,7 @@ export const markdown2HTML = (container, mdContent) => { | |||
| 46 | }) | 46 | }) |
| 47 | .use(MarkdownItFootnote) | 47 | .use(MarkdownItFootnote) |
| 48 | .use(MarkdownItFrontMatter) | 48 | .use(MarkdownItFrontMatter) |
| 49 | .use(markdownItInjectLinenumbers) | 49 | .use(MarkdownItInjectLinenumbers) |
| 50 | 50 | ||
| 51 | // Create links with geo scheme | 51 | // Create links with geo scheme |
| 52 | const coordinateRegex = /^(\D*)(-?\d+\.?\d*)\s*([,\x2F\uFF0C])\s*(-?\d+\.?\d*)/g | 52 | const coordinateRegex = /^(\D*)(-?\d+\.?\d*)\s*([,\x2F\uFF0C])\s*(-?\d+\.?\d*)/g |
| @@ -106,9 +106,10 @@ export const markdown2HTML = (container, mdContent) => { | |||
| 106 | * generateMaps. | 106 | * generateMaps. |
| 107 | * | 107 | * |
| 108 | * @param {HTMLElement} container -- Target Element contains HTML contents | 108 | * @param {HTMLElement} container -- Target Element contains HTML contents |
| 109 | * @param {Object} dumbymap -- Include and Elements and Methods about managing contents | 109 | * @param {Number} options.delay -- delay of map generation, milliseconds |
| 110 | * @return {Object} dumbymap -- Include and Elements and Methods about managing contents | ||
| 110 | */ | 111 | */ |
| 111 | export const generateMaps = (container, { delay, mapCallback }) => { | 112 | export const generateMaps = (container, { delay } = {}) => { |
| 112 | container.classList.add('Dumby') | 113 | container.classList.add('Dumby') |
| 113 | container.removeAttribute('data-layout') | 114 | container.removeAttribute('data-layout') |
| 114 | container.setAttribute('data-layout', layouts[0].name) | 115 | container.setAttribute('data-layout', layouts[0].name) |
| @@ -296,9 +297,6 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
| 296 | attributeOldValue: true | 297 | attributeOldValue: true |
| 297 | }) | 298 | }) |
| 298 | onRemove(mapElement, () => observer.disconnect()) | 299 | onRemove(mapElement, () => observer.disconnect()) |
| 299 | |||
| 300 | // Execute callback from caller | ||
| 301 | mapCallback?.call(this, mapElement) | ||
| 302 | } | 300 | } |
| 303 | 301 | ||
| 304 | // Set unique ID for map container | 302 | // Set unique ID for map container |
diff --git a/src/editor.mjs b/src/editor.mjs index 5409c3f..9fe9e75 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
| @@ -244,21 +244,8 @@ new window.MutationObserver(() => { | |||
| 244 | attributeFilter: ['data-scroll-line'] | 244 | attributeFilter: ['data-scroll-line'] |
| 245 | }) | 245 | }) |
| 246 | 246 | ||
| 247 | /** | ||
| 248 | * afterMapRendered. Callback of map rendered | ||
| 249 | * | ||
| 250 | * @param {HTEMLElement} map | ||
| 251 | */ | ||
| 252 | const afterMapRendered = map => { | ||
| 253 | console.info(map) | ||
| 254 | // mapHolder.oncontextmenu = (event) => { | ||
| 255 | // event.preventDefault() | ||
| 256 | // const lonLat = mapHolder.renderer.unproject([event.x, event.y]) | ||
| 257 | // // TODO... | ||
| 258 | // } | ||
| 259 | } | ||
| 260 | markdown2HTML(dumbyContainer, editor.value()) | 247 | markdown2HTML(dumbyContainer, editor.value()) |
| 261 | dumbymap = generateMaps(dumbyContainer, afterMapRendered) | 248 | dumbymap = generateMaps(dumbyContainer) |
| 262 | 249 | ||
| 263 | /** | 250 | /** |
| 264 | * addClassToCodeLines. Quick hack to style lines inside code block | 251 | * addClassToCodeLines. Quick hack to style lines inside code block |