diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dumbymap.mjs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index a21dadb..2ea5b0c 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -105,7 +105,7 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
105 | renderedMaps: () => | 105 | renderedMaps: () => |
106 | Array.from( | 106 | Array.from( |
107 | container.querySelectorAll('.mapclay[data-render=fulfilled]') | 107 | container.querySelectorAll('.mapclay[data-render=fulfilled]') |
108 | ), | 108 | ).sort((a, b) => a.style.order > b.style.order), |
109 | focusNextMap: throttle(utils.focusNextMap, utils.focusDelay), | 109 | focusNextMap: throttle(utils.focusNextMap, utils.focusDelay), |
110 | switchToNextLayout: throttle(utils.switchToNextLayout, 300) | 110 | switchToNextLayout: throttle(utils.switchToNextLayout, 300) |
111 | } | 111 | } |
@@ -232,11 +232,16 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
232 | // Placeholder for map in Showcase, it should has the same DOMRect | 232 | // Placeholder for map in Showcase, it should has the same DOMRect |
233 | const placeholder = target.cloneNode(true) | 233 | const placeholder = target.cloneNode(true) |
234 | placeholder.removeAttribute('id') | 234 | placeholder.removeAttribute('id') |
235 | placeholder.classList.remove('mapclay', 'focus') | 235 | placeholder.className = '' |
236 | target.parentElement.replaceChild(placeholder, target) | 236 | |
237 | const parent = target.parentElement | ||
238 | parent.replaceChild(placeholder, target) | ||
239 | onRemove(placeholder, () => { | ||
240 | parent.appendChild(target) | ||
241 | }) | ||
237 | 242 | ||
238 | // FIXME Maybe use @start-style for CSS | 243 | // FIXME Maybe use @start-style for CSS |
239 | // Trigger CSS transition, if placeholde is the olny chil element in block, | 244 | // Trigger CSS transition, if placeholde is the olny child element in block, |
240 | // reduce its height to zero. | 245 | // reduce its height to zero. |
241 | // To make sure the original height of placeholder is applied, DOM changes seems needed | 246 | // To make sure the original height of placeholder is applied, DOM changes seems needed |
242 | // then set data-attribute for CSS selector to change height to 0 | 247 | // then set data-attribute for CSS selector to change height to 0 |
@@ -245,6 +250,7 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
245 | 250 | ||
246 | // To fit showcase, remove all inline style | 251 | // To fit showcase, remove all inline style |
247 | target.removeAttribute('style') | 252 | target.removeAttribute('style') |
253 | target.style.order = placeholder.style.order | ||
248 | showcase.appendChild(target) | 254 | showcase.appendChild(target) |
249 | 255 | ||
250 | // Resume rect from Semantic HTML to Showcase, with animation | 256 | // Resume rect from Semantic HTML to Showcase, with animation |
@@ -257,11 +263,10 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
257 | const placeholder = htmlHolder.querySelector( | 263 | const placeholder = htmlHolder.querySelector( |
258 | `[data-placeholder="${target.id}"]` | 264 | `[data-placeholder="${target.id}"]` |
259 | ) | 265 | ) |
260 | if (!placeholder) { throw Error(`Cannot fine placeholder for map "${target.id}"`) } | 266 | if (!placeholder) { throw Error(`Cannot find placeholder for map "${target.id}"`) } |
261 | 267 | ||
262 | // Consider animation may fail, write callback | 268 | // Consider animation may fail, write callback |
263 | const afterAnimation = () => { | 269 | const afterAnimation = () => { |
264 | placeholder.parentElement.replaceChild(target, placeholder) | ||
265 | target.style = placeholder.style.cssText | 270 | target.style = placeholder.style.cssText |
266 | placeholder.remove() | 271 | placeholder.remove() |
267 | } | 272 | } |
@@ -410,6 +415,7 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
410 | stepCallback: updateAttributeByStep | 415 | stepCallback: updateAttributeByStep |
411 | }) | 416 | }) |
412 | const render = renderWith(configConverter) | 417 | const render = renderWith(configConverter) |
418 | let order = 0 | ||
413 | elementsWithMapConfig.forEach(target => { | 419 | elementsWithMapConfig.forEach(target => { |
414 | // Get text in code block starts with markdown text '```map' | 420 | // Get text in code block starts with markdown text '```map' |
415 | const configText = target | 421 | const configText = target |
@@ -446,11 +452,16 @@ export const generateMaps = (container, { delay, mapCallback }) => { | |||
446 | // TODO Use debounce of user input to decide rendering timing | 452 | // TODO Use debounce of user input to decide rendering timing |
447 | // Render maps with delay | 453 | // Render maps with delay |
448 | const timer = setTimeout( | 454 | const timer = setTimeout( |
449 | () => | 455 | () => { |
450 | render(target, configList).forEach(renderPromise => { | 456 | render(target, configList).forEach(renderPromise => { |
451 | renderPromises.push(renderPromise) | 457 | renderPromises.push(renderPromise) |
452 | renderPromise.then(afterMapRendered) | 458 | renderPromise.then(afterMapRendered) |
453 | }), | 459 | }) |
460 | Array.from(target.children).forEach(e => { | ||
461 | e.style.order = order | ||
462 | order++ | ||
463 | }) | ||
464 | }, | ||
454 | delay ?? 1000 | 465 | delay ?? 1000 |
455 | ) | 466 | ) |
456 | onRemove(htmlHolder, () => { | 467 | onRemove(htmlHolder, () => { |