material 0.7.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.7.8",
3
+ "version": "0.8.0",
4
4
  "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -42,11 +42,11 @@ export default {
42
42
  },
43
43
 
44
44
  getInfoById (id) {
45
- return this.dataStore[id]
45
+ return JSON.parse(JSON.stringify(this.dataStore[id]))
46
46
  },
47
47
 
48
48
  getSelectedInfo () {
49
- return this.dataStore[this.id]
49
+ return JSON.parse(JSON.stringify(this.dataStore[this.id]))
50
50
  },
51
51
 
52
52
  getItemById (id, silent) {
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
- transition: 200,
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 offs = target.getBoundingClientRect()
70
-
71
- const offsw = this.offset = this.ui.surface.getBoundingClientRect()
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
- this.ui.surface.style.top = (offs.top - 4) + 'px'
74
- this.ui.surface.style.left = offs.left - offsw.width + offs.width + 'px'
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
  }
@@ -12,6 +12,10 @@ export default {
12
12
  // console.log('show', this.visible)
13
13
  if (!this.element) return
14
14
 
15
+ if (this.options.display !== false) {
16
+ this.element.style.display = ''
17
+ }
18
+
15
19
  this.element.getBoundingClientRect()
16
20
 
17
21
  this.element.classList.add('show')
@@ -26,6 +30,7 @@ export default {
26
30
  },
27
31
 
28
32
  hide () {
33
+ // console.log('hide', this.element)
29
34
  if (!this.element) return
30
35
 
31
36
  this.element.classList.remove('show')
@@ -35,6 +40,14 @@ export default {
35
40
  this.underlay.classList.remove('show')
36
41
  }
37
42
 
43
+ if (this.options.transition && this.element) {
44
+ setTimeout(() => {
45
+ if (this.options.display !== false) {
46
+ this.element.style.display = 'none'
47
+ }
48
+ }, this.options.transition)
49
+ }
50
+
38
51
  this.emit?.('hide')
39
52
  return this
40
53
  },
@@ -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(`HTTP error! status: ${response.status}`)
24
+ throw new Error(`Network response was not ok! ${response.status}`)
21
25
  }
22
- const data = await response.json()
23
26
 
24
- return data
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
- // Handle fetch or data processing errors
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