material 0.9.22 → 0.9.23

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.23",
4
4
  "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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