aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Layout.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-04 13:38:08 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-04 15:11:28 +0800
commitdbd3b03ec842c446488135853ed380f5a75adb27 (patch)
tree00fa406566361a308808add3cdc445ed892e81ec /src/Layout.mjs
parentec23491d3a39f9f9201449f14a536b7540a8c281 (diff)
docs: add jsdoc
Diffstat (limited to 'src/Layout.mjs')
-rw-r--r--src/Layout.mjs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/Layout.mjs b/src/Layout.mjs
index 3c4ea3d..6bb6282 100644
--- a/src/Layout.mjs
+++ b/src/Layout.mjs
@@ -1,7 +1,15 @@
1import PlainDraggable from 'plain-draggable' 1import PlainDraggable from 'plain-draggable'
2import { onRemove, animateRectTransition } from './utils' 2import { onRemove, animateRectTransition } from './utils'
3 3
4/**
5 * Layout. Basic class for layout
6 */
4export class Layout { 7export class Layout {
8 /**
9 * constructor.
10 *
11 * @param {} options
12 */
5 constructor (options = {}) { 13 constructor (options = {}) {
6 if (!options.name) throw Error('Layout name is not given') 14 if (!options.name) throw Error('Layout name is not given')
7 this.name = options.name 15 this.name = options.name
@@ -9,12 +17,28 @@ export class Layout {
9 this.leaveHandler = options.leaveHandler 17 this.leaveHandler = options.leaveHandler
10 } 18 }
11 19
20 /**
21 * valueOf.
22 */
12 valueOf = () => this.name 23 valueOf = () => this.name
13} 24}
14 25
26/**
27 * Side-By-Side Layout, HTML content and Showcase show on left/right side
28 *
29 * @extends {Layout}
30 */
15export class SideBySide extends Layout { 31export class SideBySide extends Layout {
32 /**
33 * @type {}
34 */
16 name = 'side-by-side' 35 name = 'side-by-side'
17 36
37 /**
38 * enterHandler.
39 *
40 * @param {}
41 */
18 enterHandler = ({ container, htmlHolder, showcase }) => { 42 enterHandler = ({ container, htmlHolder, showcase }) => {
19 const bar = document.createElement('div') 43 const bar = document.createElement('div')
20 bar.className = 'bar' 44 bar.className = 'bar'
@@ -46,20 +70,43 @@ export class SideBySide extends Layout {
46 onRemove(bar, () => draggable.remove()) 70 onRemove(bar, () => draggable.remove())
47 } 71 }
48 72
73 /**
74 * leaveHandler.
75 *
76 * @param {}
77 */
49 leaveHandler = ({ container }) => { 78 leaveHandler = ({ container }) => {
50 container.querySelector('.bar')?.remove() 79 container.querySelector('.bar')?.remove()
51 } 80 }
52} 81}
53 82
83/**
84 * Overlay Layout, Showcase occupies viewport, and HTML content becomes draggable blocks
85 *
86 * @extends {Layout}
87 */
54export class Overlay extends Layout { 88export class Overlay extends Layout {
89 /**
90 * @type {}
91 */
55 name = 'overlay' 92 name = 'overlay'
56 93
94 /**
95 * saveLeftTopAsData.
96 *
97 * @param {} element
98 */
57 saveLeftTopAsData = element => { 99 saveLeftTopAsData = element => {
58 const { left, top } = element.getBoundingClientRect() 100 const { left, top } = element.getBoundingClientRect()
59 element.setAttribute('data-left', left) 101 element.setAttribute('data-left', left)
60 element.setAttribute('data-top', top) 102 element.setAttribute('data-top', top)
61 } 103 }
62 104
105 /**
106 * addDraggable.
107 *
108 * @param {} element
109 */
63 addDraggable = element => { 110 addDraggable = element => {
64 // Make sure current element always on top 111 // Make sure current element always on top
65 const siblings = Array.from( 112 const siblings = Array.from(
@@ -119,6 +166,11 @@ export class Overlay extends Layout {
119 }) 166 })
120 } 167 }
121 168
169 /**
170 * enterHandler.
171 *
172 * @param {}
173 */
122 enterHandler = ({ htmlHolder, blocks }) => { 174 enterHandler = ({ htmlHolder, blocks }) => {
123 // FIXME It is weird rect from this method and this scope are different... 175 // FIXME It is weird rect from this method and this scope are different...
124 blocks.forEach(this.saveLeftTopAsData) 176 blocks.forEach(this.saveLeftTopAsData)
@@ -197,6 +249,11 @@ export class Overlay extends Layout {
197 }) 249 })
198 } 250 }
199 251
252 /**
253 * leaveHandler.
254 *
255 * @param {}
256 */
200 leaveHandler = ({ htmlHolder, blocks }) => { 257 leaveHandler = ({ htmlHolder, blocks }) => {
201 const resumeFromDraggable = block => { 258 const resumeFromDraggable = block => {
202 const draggableContainer = block.closest('.draggable-block') 259 const draggableContainer = block.closest('.draggable-block')