material 0.7.9 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/menu.js +17 -6
- package/src/module/request.js +13 -6
- package/src/skin/material/control/menu.sass +0 -2
package/package.json
CHANGED
package/src/menu.js
CHANGED
|
@@ -10,7 +10,7 @@ import Button from './button'
|
|
|
10
10
|
class Menu extends EventEmitter {
|
|
11
11
|
static defaults = {
|
|
12
12
|
class: 'menu',
|
|
13
|
-
|
|
13
|
+
offset: 8,
|
|
14
14
|
modal: false,
|
|
15
15
|
layout: [
|
|
16
16
|
[Element, 'surface', { class: 'surface' },
|
|
@@ -66,12 +66,23 @@ class Menu extends EventEmitter {
|
|
|
66
66
|
|
|
67
67
|
position (target) {
|
|
68
68
|
if (!target) return
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
69
|
+
const caller = target.getBoundingClientRect()
|
|
70
|
+
const screen = this.ui.surface.getBoundingClientRect()
|
|
71
|
+
const menu = this.ui.list.getBoundingClientRect()
|
|
72
|
+
|
|
73
|
+
// Calculate top position
|
|
74
|
+
let top = caller.top + caller.height
|
|
75
|
+
if (top + menu.height > window.innerHeight) {
|
|
76
|
+
top = window.innerHeight - menu.height - this.options.offset
|
|
77
|
+
}
|
|
78
|
+
this.ui.surface.style.top = top + 'px'
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
// Calculate left position
|
|
81
|
+
let left = caller.left - caller.width + menu.width - screen.width + caller.width
|
|
82
|
+
if (left + menu.width > window.innerWidth) {
|
|
83
|
+
left = window.innerWidth - menu.width - this.options.offset
|
|
84
|
+
}
|
|
85
|
+
this.ui.surface.style.left = left + 'px'
|
|
75
86
|
|
|
76
87
|
return this
|
|
77
88
|
}
|
package/src/module/request.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const request = async (url, method = 'GET', body = null, headers = {}, signal = null) => {
|
|
1
|
+
const request = async (url, method = 'GET', body = null, headers = {}, signal = null, debug = false) => {
|
|
2
2
|
const defaultHeaders = {
|
|
3
3
|
Accept: 'application/json',
|
|
4
4
|
'Content-Type': 'application/json'
|
|
@@ -10,6 +10,10 @@ const request = async (url, method = 'GET', body = null, headers = {}, signal =
|
|
|
10
10
|
signal
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
if (debug) {
|
|
14
|
+
console.log('debug', options)
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
if (body) {
|
|
14
18
|
options.body = JSON.stringify(body)
|
|
15
19
|
}
|
|
@@ -17,14 +21,17 @@ const request = async (url, method = 'GET', body = null, headers = {}, signal =
|
|
|
17
21
|
try {
|
|
18
22
|
const response = await fetch(url, options)
|
|
19
23
|
if (!response.ok) {
|
|
20
|
-
throw new Error(`
|
|
24
|
+
throw new Error(`Network response was not ok! ${response.status}`)
|
|
21
25
|
}
|
|
22
|
-
const data = await response.json()
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
// Determine response type based on 'Accept' header
|
|
28
|
+
if (headers.Accept === 'text/xml') {
|
|
29
|
+
return await response.text()
|
|
30
|
+
} else {
|
|
31
|
+
return await response.json()
|
|
32
|
+
}
|
|
25
33
|
} catch (error) {
|
|
26
|
-
|
|
27
|
-
// console.log('error', error)
|
|
34
|
+
console.error('There has been a problem with your fetch operation:', error)
|
|
28
35
|
return { error }
|
|
29
36
|
}
|
|
30
37
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
&.show
|
|
4
4
|
//display: block
|
|
5
5
|
.surface
|
|
6
|
-
background: rgba(0,0,0,.05)
|
|
7
6
|
.list
|
|
8
7
|
background: white
|
|
9
8
|
.item
|
|
@@ -15,7 +14,6 @@
|
|
|
15
14
|
left: 0
|
|
16
15
|
bottom: 0
|
|
17
16
|
right: 0
|
|
18
|
-
background-color: rgba(0, 0, 0, 0.5)
|
|
19
17
|
display: flex
|
|
20
18
|
align-items: center
|
|
21
19
|
justify-content: center
|