material 0.8.6 → 0.8.8

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.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/appbar.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class AppBar {
4
+ static uid = "material-appbar";
5
+
4
6
  static defaults = {
5
7
  class: 'appbar'
6
8
  }
package/src/badge.js CHANGED
@@ -4,6 +4,8 @@ import display from './mixin/display'
4
4
  const isStringNumber = (str) => !isNaN(parseFloat(str)) && isFinite(str)
5
5
 
6
6
  class Badge {
7
+ static uid = "material-badge";
8
+
7
9
  static defaults = {
8
10
  class: 'badge'
9
11
  }
package/src/calendar.js CHANGED
@@ -36,6 +36,8 @@ const defaults = {
36
36
  * @type {prime}
37
37
  */
38
38
  class Calendar {
39
+ static uid = "material-calendar";
40
+
39
41
  /**
40
42
  * init
41
43
  * @return {Object} The class options
package/src/card.js CHANGED
@@ -3,6 +3,8 @@ import display from './mixin/display'
3
3
  import position from './mixin/position'
4
4
 
5
5
  class Card {
6
+ static uid = "material-card";
7
+
6
8
  static defaults = {
7
9
  class: 'card',
8
10
  position: {
package/src/checkbox.js CHANGED
@@ -9,6 +9,8 @@ import icon from './skin/material/icon/checkbox.svg'
9
9
  import Element from './element'
10
10
 
11
11
  class Checkbox {
12
+ static uid = "material-checkbox";
13
+
12
14
  static defaults = {
13
15
  class: 'checkbox',
14
16
  layout: [
package/src/component.js CHANGED
@@ -27,6 +27,8 @@ const defaults = {
27
27
  * });
28
28
  */
29
29
  class Component {
30
+ static uid = "material-component";
31
+
30
32
  /**
31
33
  * Constructor
32
34
  * @param {Object} options - Component options
package/src/datehour.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class DateHour {
4
+ static uid = "material-datehour";
5
+
4
6
  static defaults = {
5
7
  class: 'date',
6
8
  tag: 'span'
package/src/dialog.js CHANGED
@@ -9,6 +9,8 @@ import Button from './button'
9
9
  import Layout from './layout'
10
10
 
11
11
  class Dialog {
12
+ static uid = "material-dialog";
13
+
12
14
  static defaults = {
13
15
  class: 'dialog',
14
16
  close: true,
package/src/divider.js CHANGED
@@ -16,6 +16,8 @@ const defaults = {
16
16
  * @example new Item(object);
17
17
  */
18
18
  class Divider {
19
+ static uid = "material-divider";
20
+
19
21
  /**
20
22
  * init
21
23
  * @return {Object} The class options
package/src/drawer.js CHANGED
@@ -18,6 +18,8 @@ const defaults = {
18
18
  }
19
19
 
20
20
  class Drawer {
21
+ static uid = "material-drawer";
22
+
21
23
  constructor (options) {
22
24
  this.options = Object.assign({}, defaults, options || {})
23
25
 
package/src/element.js CHANGED
@@ -1,4 +1,6 @@
1
1
  class Element {
2
+ static uid = "material-element";
3
+
2
4
  static isElement () {
3
5
  return true
4
6
  }
package/src/file.js CHANGED
@@ -5,6 +5,8 @@ import dataset from './module/dataset'
5
5
  import attributes from './module/attributes'
6
6
 
7
7
  class File {
8
+ static uid = "material-file";
9
+
8
10
  static defaults = {
9
11
  class: 'file',
10
12
  attributes: ['name', 'accept', 'required', 'disabled', 'multiple'],
package/src/form.js CHANGED
@@ -21,6 +21,8 @@ const defaults = {
21
21
  * @return {Class} This class instance
22
22
  */
23
23
  class Form {
24
+ static uid = "material-form";
25
+
24
26
  /**
25
27
  * Constructor
26
28
  * @param {Object} options - Component options
package/src/icon.js CHANGED
@@ -16,6 +16,8 @@ var defaults = {
16
16
  * @example new Item(object);
17
17
  */
18
18
  class Icon {
19
+ static uid = "material-icon";
20
+
19
21
  /**
20
22
  * init
21
23
  * @return {Object} The class options
package/src/image.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class Image {
4
+ static uid = "material-image";
5
+
4
6
  static defaults = {
5
7
  class: 'image',
6
8
  tag: 'div',
package/src/item.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class Item {
4
+ static uid = "material-item";
5
+
4
6
  static defaults = {
5
7
  prefix: 'material',
6
8
  class: 'item',
package/src/layout.js CHANGED
@@ -1,28 +1,47 @@
1
1
  import { is as isObject } from './module/object'
2
- import * as css from './module/css'
3
2
 
3
+ /**
4
+ * Layout class for creating and managing UI components.
5
+ */
4
6
  class Layout {
7
+ /**
8
+ * Constructs a new Layout instance.
9
+ *
10
+ * @param {Array} schema - An array defining the structure and components of the layout.
11
+ * @param {HTMLElement} container - The container in which the layout components are placed.
12
+ * @param {boolean} [enableMemoization=false] - Flag to enable memoization (not implemented in current version).
13
+ */
5
14
  constructor (schema, container) {
6
15
  this.components = []
16
+ // const startTime = Date.now()
7
17
  this.component = this.create(schema, container)
8
-
18
+ // const endTime = Date.now()
19
+ // console.log(`Execution time: ${endTime - startTime} ms`)
9
20
  return this
10
21
  }
11
22
 
23
+ /**
24
+ * Recursively creates components based on a provided schema.
25
+ *
26
+ * @param {Array} schema - An array of components or sub-schemas.
27
+ * @param {HTMLElement} container - The container for the current level of components.
28
+ * @param {Object} [structure={}] - An accumulator object for components, keyed by name.
29
+ * @param {number} [level=0] - The current level of recursion.
30
+ * @returns {Object} The structure containing all created components.
31
+ */
12
32
  create (schema, container, structure, level) {
13
33
  level = level || 0
14
34
  level++
15
35
 
16
36
  structure = structure || {}
17
37
  let component = null
38
+ const fragment = document.createDocumentFragment()
18
39
 
19
40
  for (let i = 0; i < schema.length; i++) {
20
- // console.log('index', i, typeof schema[i])
21
41
  var name
22
42
  let options = {}
23
43
 
24
- if (schema[i] instanceof Object &&
25
- typeof schema[i] === 'function') {
44
+ if (schema[i] instanceof Object && typeof schema[i] === 'function') {
26
45
  if (isObject(schema[i + 1])) {
27
46
  options = schema[i + 1]
28
47
  } else if (isObject(schema[i + 2])) {
@@ -37,113 +56,47 @@ class Layout {
37
56
  }
38
57
 
39
58
  component = new schema[i](options)
40
- const element = component.element || component
41
59
 
42
- if (level === 1) {
43
- structure.element = element
44
- }
60
+ const element = component.element || component
61
+ if (level === 1) structure.element = element
45
62
 
46
63
  if (name) {
47
64
  structure[name] = component
48
65
  this.components.push([name, component])
49
66
  }
50
67
 
51
- // if (component) {
52
- // this.display(component.element, options)
53
- // this.style(component, options)
54
- // }
55
-
56
- if (component && container) {
57
- if (component.insert) {
58
- component.insert(container)
59
- } else {
60
- const wrapper = container.element || container
68
+ if (component) {
69
+ if (component.insert) component.insert(fragment)
70
+ else fragment.appendChild(element)
61
71
 
62
- wrapper.appendChild(element)
63
-
64
- if (component.onInserted) {
65
- component.onInserted(wrapper)
66
- }
67
- }
68
- component._container = container
72
+ if (component.onInserted) component.onInserted(fragment)
69
73
  }
70
74
  } else if (Array.isArray(schema[i])) {
71
- // console.log('------', schema[i])
72
- if (component == null) {
73
- component = container
74
- }
75
+ if (!component) component = container
75
76
  this.create(schema[i], component, structure, level)
76
77
  }
77
78
  }
78
79
 
79
- return structure
80
- }
81
-
82
- display (element, options) {
83
- const display = options.display
84
- const direction = options.direction || 'horizontal'
85
-
86
- if (!element || !display) return
87
-
88
- if (direction === 'horizontal') {
89
- element.className += ' ' + 'flex-row'
90
- } else if (direction === 'vertical') {
91
- element.className += ' ' + 'flex-column'
92
- }
93
- }
94
-
95
- style (component) {
96
- const options = component.options || {}
97
-
98
- // console.log('component', component);
99
-
100
- if (options.flex) {
101
- css.add(component.element, 'flex-' + options.flex)
102
- } else {
103
- const size = options.size
104
- if (options.size && options.width) {
105
- component.element.width = size + 'px'
106
- } else if (options.size && options.height) {
107
- component.element.height = size + 'px'
108
- }
109
- }
110
-
111
- if (options.position) {
112
- component.element.position = options.position
113
- }
114
-
115
- if (options.bottom) {
116
- component.element.bottom = options.bottom
117
- }
118
-
119
- if (options.hide) {
120
- component.element.display = 'none'
121
- }
122
-
123
- if (options.theme) {
124
- css.add(component.element, 'theme' + '-' + options.theme)
80
+ if (container && fragment.hasChildNodes()) {
81
+ const wrapper = container.element || container
82
+ // console.log('wrapper', wrapper)
83
+ // console.log('fragment', fragment)
84
+ wrapper.appendChild(fragment)
125
85
  }
126
- }
127
-
128
- extractInfo (object) {
129
- // console.log('extractField', object)
130
-
131
- const field = {}
132
86
 
133
- for (const property in object) {
134
- if (object.hasOwnProperty(property)) {
135
- const infos = property.split(/\./)
136
-
137
- if (infos[0] === 'info' && infos[1] !== undefined) {
138
- // console.log('field', infos[0], infos[1])
139
- field[infos[1]] = object[property]
140
- }
141
- }
142
- }
143
-
144
- return field
87
+ return structure
145
88
  }
146
89
 
90
+ /**
91
+ * Retrieves a specific component or the entire component structure.
92
+ *
93
+ * This method allows accessing a component from the created layout by its name.
94
+ * If a name is provided, it returns the component associated with that name.
95
+ * If no name is provided, it returns the entire component structure.
96
+ *
97
+ * @param {string} name - The name of the component to retrieve.
98
+ * @returns {Object} The requested component or the entire component structure.
99
+ */
147
100
  get (name) {
148
101
  if (name) return this.component[name]
149
102
  else return this.component
package/src/link.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class Link {
4
+ static uid = "material-link";
5
+
4
6
  static defaults = {
5
7
  class: 'link',
6
8
  tag: 'a'
@@ -7,6 +7,8 @@ const defaults = {
7
7
  }
8
8
 
9
9
  class Collection {
10
+ static uid = "material-list-collection";
11
+
10
12
  /**
11
13
  * Constructor
12
14
  * @param {Object} options - Component options
@@ -6,6 +6,8 @@ import emitter from '../module/emitter' // Import the emitter module.
6
6
 
7
7
  // Define the VirtualList class
8
8
  class VirtualList {
9
+ static uid = "material-list-virtuallist";
10
+
9
11
  constructor (options) {
10
12
  // Initialize the class with options passed to the constructor.
11
13
  this.options = { ...(options || {}) } // Spread operator to merge options with default values.
package/src/list.js CHANGED
@@ -7,6 +7,8 @@ const defaults = {
7
7
  }
8
8
 
9
9
  class List {
10
+ static uid = "material-list";
11
+
10
12
  constructor (options) {
11
13
  this.options = Object.assign({}, defaults, options || {})
12
14
 
package/src/loader.js CHANGED
@@ -1,4 +1,6 @@
1
1
  class Loader {
2
+ static uid = "material-loader";
3
+
2
4
  static defaults = {
3
5
  class: 'loader'
4
6
  }
package/src/loading.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class Loading {
4
+ static uid = "material-loading";
5
+
4
6
  static isComponent () {
5
7
  return true
6
8
  }
package/src/map.js CHANGED
@@ -41,6 +41,8 @@ const defaults = {
41
41
  }
42
42
 
43
43
  class Map {
44
+ static uid = "material-map";
45
+
44
46
  /**
45
47
  * Constructor component options
46
48
  * @return {Object} Class instance
@@ -6,6 +6,8 @@ let instance = null
6
6
  *
7
7
  */
8
8
  class Controller {
9
+ static uid = "material-mixin-controller";
10
+
9
11
  /**
10
12
  * Setting up block level variable to store class state
11
13
  * , set's to null by default.
@@ -1,4 +1,6 @@
1
1
  class EventEmitter {
2
+ static uid = "material-mixin-eventemitter";
3
+
2
4
  constructor () {
3
5
  this.events = {}
4
6
  }
@@ -5,7 +5,6 @@ export default {
5
5
  const { offsetX = 0, offsetY = 0, align = 'center', vAlign = 'middle' } = position
6
6
 
7
7
  const name = this.constructor.name
8
- console.log('constructor', name)
9
8
 
10
9
  if (!target) return
11
10
 
@@ -13,15 +12,8 @@ export default {
13
12
  const screen = this.element.parentNode.getBoundingClientRect()
14
13
  const element = this.element.getBoundingClientRect()
15
14
 
16
- console.log('caller', caller)
17
- console.log('screen', screen)
18
- console.log('element', element)
19
-
20
15
  let left, top
21
16
 
22
- console.log('align', align)
23
- console.log('target left', caller.left)
24
-
25
17
  switch (align) {
26
18
  case 'left':
27
19
  left = caller.left + caller.width
@@ -40,13 +32,15 @@ export default {
40
32
  left = caller.left + (caller.width / 2) - (element.width / 2)
41
33
  }
42
34
 
35
+ // ensure that the element remains within the limits of its container
36
+
43
37
  if (left < 0) left = offsetX
44
38
 
45
39
  if (left + element.width + offsetX > screen.width) {
46
- left = caller.left - element.width + caller.width - offsetX
40
+ left = screen.width - element.width - offsetX
47
41
  }
48
42
 
49
- console.log('left', left)
43
+ // console.log('left', left)
50
44
 
51
45
  // left = Math.max(offsetX, Math.min(left, screen.width - element.width - offsetX))
52
46
 
@@ -77,12 +71,6 @@ export default {
77
71
  top = caller.top + scrollY + (caller.height / 2) - (element.height / 2)
78
72
  }
79
73
 
80
- // if (this.options.class !== 'menu') {
81
- // top = Math.max(offsetY, Math.min(top, screen.height - element.height - offsetY))
82
- // }
83
-
84
- console.log('top', top)
85
-
86
74
  this.element.style.left = `${left}px`
87
75
  this.element.style.top = `${top}px`
88
76
 
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Serializes an object into a string representation.
3
+ *
4
+ * This function takes an object and serializes its properties into a string format.
5
+ * It sorts the keys of the object, and for each key, it checks if the corresponding
6
+ * value is an object. If it is, the function is called recursively on that object.
7
+ * The output is a string where each key-value pair is separated by a colon, and
8
+ * pairs are separated by a pipe character.
9
+ *
10
+ * @param {Object} object - The object to be serialized.
11
+ * @returns {string} The serialized string representation of the object.
12
+ */
13
+ const serialize (object, separator = '|') => {
14
+ const keys = Object.keys(object).sort()
15
+ const serialized = keys.map(key => {
16
+ const value = object[key]
17
+ if (typeof value === 'object' && value !== null) {
18
+ return `${key}:${serialize(value)}`
19
+ }
20
+ return `${key}:${value}`
21
+ })
22
+ return serialized.join(separator)
23
+ }
24
+
25
+ export default serialize
package/src/progress.js CHANGED
@@ -14,6 +14,8 @@ const defaults = {
14
14
  }
15
15
 
16
16
  class Spinner {
17
+ static uid = "material-spinner";
18
+
17
19
  /**
18
20
  * init
19
21
  * @return {Object} The class options
package/src/selector.js CHANGED
@@ -18,6 +18,8 @@ const defaults = {
18
18
  }
19
19
 
20
20
  class Selector {
21
+ static uid = "material-selector";
22
+
21
23
  static isComponent () {
22
24
  return true
23
25
  }
package/src/slider.js CHANGED
@@ -50,6 +50,8 @@ const defaults = {
50
50
  * @extends Control
51
51
  */
52
52
  class Slider {
53
+ static uid = "material-slider";
54
+
53
55
  /**
54
56
  * init
55
57
  * @return {Object} The class options
package/src/tabs.js CHANGED
@@ -20,6 +20,8 @@ const defaults = {
20
20
  }
21
21
 
22
22
  class Tabs {
23
+ static uid = "material-tabs";
24
+
23
25
  /**
24
26
  * Constructor
25
27
  * @param {Object} options - Component options
package/src/text.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import build from './module/build'
2
2
 
3
3
  class Text {
4
+ static uid = "material-text";
5
+
4
6
  static defaults = {
5
7
  class: 'text',
6
8
  tag: 'span'
package/src/textfield.js CHANGED
@@ -4,6 +4,8 @@ import dataset from './module/dataset'
4
4
  import attributes from './module/attributes'
5
5
 
6
6
  class Textfield {
7
+ static uid = "material-textfield";
8
+
7
9
  static isComponent () {
8
10
  return true
9
11
  }
package/src/toolbar.js CHANGED
@@ -11,6 +11,8 @@ const defaults = {
11
11
  }
12
12
 
13
13
  class Toolbar {
14
+ static uid = "material-toolbar";
15
+
14
16
  /**
15
17
  * Constructor
16
18
  * @param {Object} options - Component options
package/src/tooltip.js CHANGED
@@ -20,6 +20,8 @@ const defaults = {
20
20
  }
21
21
 
22
22
  class Tooltip {
23
+ static uid = "material-tooltip";
24
+
23
25
  /**
24
26
  * The init method of the Button class
25
27
  * @param {Object} The element attributes
package/src/tree.js CHANGED
@@ -14,6 +14,8 @@ const defaults = {
14
14
  }
15
15
 
16
16
  class Tree {
17
+ static uid = "material-tree";
18
+
17
19
  constructor (options) {
18
20
  this.options = Object.assign({}, defaults, options || {})
19
21