material 0.9.22 → 0.9.24

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.9.22",
3
+ "version": "0.9.24",
4
4
  "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -19,7 +19,6 @@ class Component {
19
19
  }
20
20
 
21
21
  async destroy () {
22
- console.log('destroy')
23
22
  if (this.options.transition && this.element) {
24
23
  this.element.classList.remove('show')
25
24
  if (this.underlay) {
@@ -36,6 +35,8 @@ class Component {
36
35
  dom.destroy(this.element)
37
36
  if (this.underlay) dom.destroy(this.underlay)
38
37
  }
38
+
39
+ // this.emit('destroy')
39
40
  }
40
41
  }
41
42
 
@@ -31,7 +31,7 @@ class Control extends Component {
31
31
  }
32
32
 
33
33
  // Clean up emitter subscriptions
34
- this.removeAll()
34
+ // this.removeAll()
35
35
 
36
36
  // Emit destroy event before DOM removal
37
37
  this.emit('destroy')
@@ -59,21 +59,22 @@ const events = {
59
59
  },
60
60
 
61
61
  detach (eventsArray, context) {
62
+ // console.log('this', this)
62
63
  const uid = context._uid
63
64
  if (!this.eventHandlers[uid]) return
64
65
 
65
66
  eventsArray.forEach(([eventDef, funcDef, option]) => {
66
67
  const e = extract.e(context, eventDef)
67
68
  const handler = this.eventHandlers[uid][eventDef]
68
- if (handler) {
69
+
70
+ if (handler && e?.element?.removeEventListener) {
69
71
  e.element.removeEventListener(e.name, handler)
70
- } else if (e.element.off) {
72
+ delete this.eventHandlers[uid][eventDef]
73
+ } else if (e?.element?.off) {
71
74
  e.element.off(e.name, handler)
75
+ delete this.eventHandlers[uid][eventDef]
72
76
  }
73
-
74
- delete this.eventHandlers[uid][eventDef]
75
- }
76
- )
77
+ })
77
78
  },
78
79
 
79
80
  list (context) {
@@ -1,5 +1,16 @@
1
1
  import { is as isObject } from '../module/object'
2
2
 
3
+ const createComponent = (Component, options = {}) => {
4
+ // Check if Component is a class (has prototype) or function
5
+ const isClass = Component.prototype && Component.prototype.constructor === Component
6
+
7
+ if (isClass) {
8
+ return new Component(options)
9
+ }
10
+
11
+ return Component(options)
12
+ }
13
+
3
14
  /**
4
15
  * Recursively creates components based on a provided schema.
5
16
  *
@@ -9,7 +20,7 @@ import { is as isObject } from '../module/object'
9
20
  * @param {number} [level=0] - The current level of recursion.
10
21
  * @returns {Object} The structure containing all created components.
11
22
  */
12
- function create (schema, container, structure = {}, level = 0, components = []) {
23
+ const create = (schema, container, structure = {}, level = 0, components = []) => {
13
24
  level++
14
25
  let component
15
26
  const object = {}
@@ -20,7 +31,7 @@ function create (schema, container, structure = {}, level = 0, components = [])
20
31
  }
21
32
 
22
33
  for (let i = 0; i < schema.length; i++) {
23
- var name
34
+ let name
24
35
  let options = {}
25
36
 
26
37
  if (schema[i] instanceof Object && typeof schema[i] === 'function') {
@@ -37,7 +48,7 @@ function create (schema, container, structure = {}, level = 0, components = [])
37
48
  }
38
49
  }
39
50
 
40
- component = new schema[i](options)
51
+ component = createComponent(schema[i], options)
41
52
 
42
53
  const element = component.element || component
43
54
  if (level === 1) structure.element = element