aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-15 11:51:30 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-15 15:16:13 +0800
commit7a3cbaf8bb8fdbae487f96a81b881d42f732f6b5 (patch)
tree5d737e4bfdc3d5025807e16f016f17abd9633ca7
parent1c5a950c274a7acd9f98a3ac68ad2426c16eb097 (diff)
feat(CSS): Make draggable blocks resizable
-rw-r--r--src/css/dumbymap.css8
-rw-r--r--src/dumbymap.mjs7
2 files changed, 10 insertions, 5 deletions
diff --git a/src/css/dumbymap.css b/src/css/dumbymap.css
index 2da2376..876d980 100644
--- a/src/css/dumbymap.css
+++ b/src/css/dumbymap.css
@@ -145,14 +145,18 @@
145 position: absolute; 145 position: absolute;
146 width: fit-content; 146 width: fit-content;
147 max-height: 50vh; 147 max-height: 50vh;
148 max-width: 25vw;
148 overflow: scroll; 149 overflow: scroll;
149 border: solid gray; 150 border: solid gray;
150 padding: 0.3rem; 151 padding: 0.3rem;
151 padding-top: 0.5rem; 152 padding-top: 0.5rem;
152 padding-bottom: 0; 153 padding-bottom: 0;
154 resize: both;
153 155
154 * { 156 &[style*="height"],
155 max-width: calc(100vw/4); 157 &[style*="width"] {
158 max-height: unset;
159 max-width: unset;
156 } 160 }
157 161
158 .map-container { 162 .map-container {
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index e19e2d9..922f413 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -375,12 +375,13 @@ export const generateMaps = async (container) => {
375 let x = 0; 375 let x = 0;
376 let y = 0; 376 let y = 0;
377 htmlHolder.blocks.forEach(block =>{ 377 htmlHolder.blocks.forEach(block =>{
378 // Add draggable instance
378 block.draggableInstance = new PlainDraggable(block, { 379 block.draggableInstance = new PlainDraggable(block, {
379 handle: block.draggablePart, 380 handle: block.draggablePart,
380 snap: { x: { step: 20 }, y: { step: 20 } }, 381 snap: { x: { step: 20 }, y: { step: 20 } },
381 autoScroll: false, 382 autoScroll: false,
382 }) 383 })
383 // block.style.transform = `translate(${x}px, ${y}px)` 384 // Set initial postion side by side
384 block.style.left = `${x}px` 385 block.style.left = `${x}px`
385 block.style.top = `${y}px` 386 block.style.top = `${y}px`
386 x += parseInt(window.getComputedStyle(block).width) + 50 387 x += parseInt(window.getComputedStyle(block).width) + 50
@@ -391,9 +392,9 @@ export const generateMaps = async (container) => {
391 }) 392 })
392 } else { 393 } else {
393 htmlHolder.blocks.forEach(block => { 394 htmlHolder.blocks.forEach(block => {
394 block.style.transform = 'none' 395 block.removeAttribute('style')
395 try { 396 try {
396 block.draggableInstance?.remove() 397 block.draggableInstance.remove()
397 } catch (_) { } 398 } catch (_) { }
398 }) 399 })
399 } 400 }