material 0.9.0 → 0.9.2

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.
Files changed (61) hide show
  1. package/index.js +24 -10
  2. package/package.json +1 -1
  3. package/scripts/doccoAssistant.js +25 -0
  4. package/src/appbar.js +2 -4
  5. package/src/badge.js +6 -13
  6. package/src/button.js +10 -18
  7. package/src/calendar.js +23 -48
  8. package/src/card.js +2 -4
  9. package/src/checkbox.js +2 -7
  10. package/src/class/component.js +19 -0
  11. package/src/class/control.js +33 -0
  12. package/src/component.js +7 -41
  13. package/src/datehour.js +2 -4
  14. package/src/dialog.js +3 -5
  15. package/src/drawer.js +12 -12
  16. package/src/element.js +16 -20
  17. package/src/file.js +6 -4
  18. package/src/form/build.js +2 -2
  19. package/src/form.js +9 -22
  20. package/src/icon.js +6 -34
  21. package/src/image.js +1 -3
  22. package/src/item.js +3 -3
  23. package/src/link.js +1 -3
  24. package/src/list/build.js +2 -2
  25. package/src/list/render.js +5 -7
  26. package/src/list/select.js +4 -2
  27. package/src/list/update.js +2 -2
  28. package/src/list.js +12 -13
  29. package/src/loader.js +4 -7
  30. package/src/loading.js +2 -8
  31. package/src/map.js +27 -32
  32. package/src/menu.js +2 -2
  33. package/src/mixin/build.js +68 -0
  34. package/src/mixin/emitter.js +0 -2
  35. package/src/module/build.js +51 -46
  36. package/src/module/clone.js +15 -0
  37. package/src/module/dot.js +15 -9
  38. package/src/module/events.js +2 -0
  39. package/src/module/layout.js +75 -0
  40. package/src/module/merge.js +22 -0
  41. package/src/navigation.js +4 -3
  42. package/src/progress.js +9 -24
  43. package/src/search.js +3 -2
  44. package/src/select.js +2 -2
  45. package/src/selecter.js +5 -4
  46. package/src/selector.js +23 -41
  47. package/src/slider.js +33 -55
  48. package/src/snackbar.js +1 -1
  49. package/src/switch.js +1 -1
  50. package/src/switcher.js +1 -1
  51. package/src/tabs.js +12 -19
  52. package/src/tabview.js +1 -1
  53. package/src/text.js +2 -4
  54. package/src/textfield.js +1 -3
  55. package/src/toolbar.js +6 -20
  56. package/src/tooltip.js +14 -24
  57. package/src/tree.js +10 -14
  58. package/src/view/build.js +2 -2
  59. package/src/view.js +2 -2
  60. package/src/divider.js +0 -60
  61. package/src/layout.js +0 -106
@@ -33,6 +33,8 @@ const events = {
33
33
  } else if (f && bound) {
34
34
  handler = f.bind(bound)
35
35
  } else {
36
+ // throw new Error('Cannot bind function for eventDef')
37
+ // console.trace('Cannot bind function for eventDef')
36
38
  return // Cannot bind function for eventDef
37
39
  }
38
40
 
@@ -0,0 +1,75 @@
1
+ import { is as isObject } from '../module/object'
2
+
3
+ /**
4
+ * Recursively creates components based on a provided schema.
5
+ *
6
+ * @param {Array} schema - An array of components or sub-schemas.
7
+ * @param {HTMLElement} container - The container for the current level of components.
8
+ * @param {Object} [structure={}] - An accumulator object for components, keyed by name.
9
+ * @param {number} [level=0] - The current level of recursion.
10
+ * @returns {Object} The structure containing all created components.
11
+ */
12
+ function create (schema, container, structure = {}, level = 0, components = []) {
13
+ // console.log('layout create')
14
+ level++
15
+ let component
16
+ const object = {}
17
+ const fragment = document.createDocumentFragment()
18
+
19
+ for (let i = 0; i < schema.length; i++) {
20
+ var name
21
+ let options = {}
22
+
23
+ if (schema[i] instanceof Object && typeof schema[i] === 'function') {
24
+ if (isObject(schema[i + 1])) {
25
+ options = schema[i + 1]
26
+ } else if (isObject(schema[i + 2])) {
27
+ options = schema[i + 2]
28
+ }
29
+
30
+ if (typeof schema[i + 1] === 'string') {
31
+ name = schema[i + 1]
32
+ if (!schema[i].isElement && !schema[i].isComponent) {
33
+ options.name = name
34
+ }
35
+ }
36
+
37
+ component = new schema[i](options)
38
+
39
+ const element = component.element || component
40
+ if (level === 1) structure.element = element
41
+
42
+ if (name) {
43
+ structure[name] = component
44
+ components.push([name, component])
45
+ }
46
+
47
+ if (component) {
48
+ if (component.insert) component.insert(fragment)
49
+ else fragment.appendChild(element)
50
+
51
+ if (component.onInserted) component.onInserted(fragment)
52
+ }
53
+ } else if (Array.isArray(schema[i])) {
54
+ if (!component) component = container
55
+ create(schema[i], component, structure, level, components)
56
+ }
57
+ }
58
+
59
+ if (container && fragment.hasChildNodes()) {
60
+ const wrapper = container.element || container
61
+ wrapper.appendChild(fragment)
62
+ }
63
+
64
+ function get (name) {
65
+ return structure[name] || null
66
+ }
67
+
68
+ object.component = structure
69
+ object.components = components
70
+ object.get = get
71
+
72
+ return object
73
+ }
74
+
75
+ export { create }
@@ -0,0 +1,22 @@
1
+ // deep merge
2
+ const isObject = item =>
3
+ item && typeof item === 'object' && !Array.isArray(item)
4
+
5
+ const merge = (target, ...sources) => {
6
+ sources.forEach(source => {
7
+ if (isObject(source)) {
8
+ Object.keys(source).forEach(key => {
9
+ const sourceValue = source[key]
10
+ if (isObject(sourceValue)) {
11
+ if (!isObject(target[key])) target[key] = {}
12
+ merge(target[key], sourceValue)
13
+ } else {
14
+ target[key] = sourceValue
15
+ }
16
+ })
17
+ }
18
+ })
19
+ return target
20
+ }
21
+
22
+ export default merge
package/src/navigation.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from './mixin/emitter'
2
2
 
3
3
  import * as css from './module/css'
4
- import build from './module/build'
4
+ import build from './mixin/build'
5
5
  import events from './module/events'
6
6
  import display from './mixin/display'
7
7
  import Element from './element'
@@ -25,18 +25,19 @@ class Navigation extends EventEmitter {
25
25
 
26
26
  this.init(options)
27
27
  this.build()
28
- events.attach(this.options.events, this)
29
28
  this.setup()
30
29
  }
31
30
 
32
31
  init (options) {
33
32
  this.options = { ...Navigation.defaults, ...options }
34
33
  Object.assign(this, build, display)
34
+
35
35
  this.items = []
36
36
  }
37
37
 
38
38
  setup () {
39
- console.log('setup', this.options)
39
+ events.attach(this.options.events, this)
40
+
40
41
  if (this.options.type) css.add(this.element, 'type-' + this.options.type)
41
42
  if (this.options.type === 'rail') this.show()
42
43
  if (this.options.items) this.render(this.options.items)
package/src/progress.js CHANGED
@@ -3,23 +3,17 @@ import create from './element/create'
3
3
  import classify from './module/classify'
4
4
  import insert from './element/insert'
5
5
 
6
- const defaults = {
7
- prefix: 'material',
8
- class: 'progress',
9
- tag: 'div',
10
- progress: '0%',
11
- circular: `<svg class="progress" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
6
+ class Spinner {
7
+ static defaults = {
8
+ prefix: 'material',
9
+ class: 'progress',
10
+ tag: 'div',
11
+ progress: '0%',
12
+ circular: `<svg class="progress" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
12
13
  <circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
13
14
  </svg>`
14
- }
15
-
16
- class Spinner {
17
- static uid = "material-spinner";
15
+ }
18
16
 
19
- /**
20
- * init
21
- * @return {Object} The class options
22
- */
23
17
  constructor (options) {
24
18
  this.init(options)
25
19
  this.build()
@@ -27,14 +21,9 @@ class Spinner {
27
21
  return this
28
22
  }
29
23
 
30
- /**
31
- * [init description]
32
- * @param {?} options [description]
33
- * @return {?} [description]
34
- */
35
24
  init (options) {
36
25
  // merge options
37
- this.options = Object.assign({}, defaults, options || {})
26
+ this.options = { ...Spinner.defaults, ...options }
38
27
 
39
28
  // define class
40
29
 
@@ -42,10 +31,6 @@ class Spinner {
42
31
  Object.assign(this, insert)
43
32
  }
44
33
 
45
- /**
46
- * Build function for item
47
- * @return {Object} This class instance
48
- */
49
34
  build (options) {
50
35
  this.element = create(this.options.tag)
51
36
  classify(this.element, this.options)
package/src/search.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from './mixin/emitter'
2
2
 
3
- import build from './module/build'
3
+ import build from './mixin/build'
4
4
  import display from './mixin/display'
5
5
  import events from './module/events'
6
6
 
@@ -36,8 +36,9 @@ class Search extends EventEmitter {
36
36
  }
37
37
 
38
38
  setup () {
39
- this.input = this.ui.input
40
39
  events.attach(this.options.events, this)
40
+
41
+ this.input = this.ui.input
41
42
  }
42
43
 
43
44
  set (value) {
package/src/select.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from './mixin/emitter'
2
2
  // modules
3
- import build from './module/build'
3
+ import build from './mixin/build'
4
4
  import events from './module/events'
5
5
  import attributes from './module/attributes'
6
6
  import dataset from './module/dataset'
@@ -24,7 +24,7 @@ class Select extends EventEmitter {
24
24
  }
25
25
 
26
26
  init (options) {
27
- this.options = Object.assign({}, Select.defaults, options || {})
27
+ this.options = { ...Select.defaults, ...options }
28
28
  Object.assign(this, build, dataset)
29
29
  }
30
30
 
package/src/selecter.js CHANGED
@@ -5,7 +5,7 @@ import dataset from './module/dataset'
5
5
  import attributes from './module/attributes'
6
6
  import * as css from './module/css'
7
7
  // components
8
- import Layout from './layout'
8
+ import { create } from './module/layout'
9
9
  import Element from './element'
10
10
  import Button from './button'
11
11
 
@@ -39,15 +39,16 @@ class Selecter extends EventEmitter {
39
39
  this.init(options)
40
40
  this.build()
41
41
  this.setup()
42
- events.attach(this.options.events, this)
43
42
  }
44
43
 
45
44
  init (options) {
46
- this.options = Object.assign({}, Selecter.defaults, options || {})
45
+ this.options = { ...Selecter.defaults, ...options }
47
46
  Object.assign(this, dataset)
48
47
  }
49
48
 
50
49
  setup () {
50
+ events.attach(this.options.events, this)
51
+
51
52
  if (this.options.data) {
52
53
  dataset(this.element, this.options.data)
53
54
  }
@@ -87,7 +88,7 @@ class Selecter extends EventEmitter {
87
88
  css.add(this.element, this.options.class)
88
89
  }
89
90
 
90
- this.layout = new Layout(this.options.layout, this.element)
91
+ this.layout = create(this.options.layout, this.element)
91
92
  this.ui = this.layout.component
92
93
 
93
94
  // console.log('ui', this.ui)
package/src/selector.js CHANGED
@@ -1,53 +1,32 @@
1
1
  import emitter from './module/emitter'
2
2
  import events from './module/events'
3
3
 
4
- const defaults = {
5
- class: 'selector',
6
- tag: 'div',
7
- styles: ['style', 'color'],
8
- modules: ['border', 'label', 'resizer'],
9
- resizer: {
10
- keepRatio: true,
11
- minWidth: 10,
12
- minHeight: 10
13
- },
14
- events: [
15
- ['resizer.pointerdown', 'onPointerDown']
16
- ]
17
-
18
- }
19
-
20
4
  class Selector {
21
- static uid = "material-selector";
22
-
23
- static isComponent () {
24
- return true
5
+ static defaults = {
6
+ class: 'selector',
7
+ tag: 'div',
8
+ styles: ['style', 'color'],
9
+ modules: ['border', 'label', 'resizer'],
10
+ resizer: {
11
+ keepRatio: true,
12
+ minWidth: 10,
13
+ minHeight: 10
14
+ },
15
+ events: [
16
+ ['resizer.pointerdown', 'onPointerDown']
17
+ ]
25
18
  }
26
19
 
27
- /**
28
- * Constructor
29
- * @param {Object} options - Component options
30
- * @return {Object} Class instance
31
- */
32
20
  constructor (options) {
33
21
  // console.log('constructor')
34
- this.options = Object.assign({}, defaults, options || {})
35
- Object.assign(this, emitter, attach)
36
- // console.log('options', options)
37
-
38
- this.init()
39
-
40
- return this
41
- }
42
-
43
- init () {
22
+ this.init(options)
44
23
  this.build()
45
24
  this.setup()
46
- events.attach(this.options.events, this)
25
+ }
47
26
 
48
- if (this.options.container) {
49
- this.options.container.appendChild(this.element)
50
- }
27
+ init (options) {
28
+ this.options = Object.assign({}, Selector.defaults, options || {})
29
+ Object.assign(this, emitter, attach)
51
30
  }
52
31
 
53
32
  /**
@@ -81,12 +60,15 @@ class Selector {
81
60
  this.element.appendChild(this.resizer)
82
61
  }
83
62
 
84
- return this
63
+ if (this.options.container) {
64
+ this.options.container.appendChild(this.element)
65
+ }
85
66
  }
86
67
 
87
68
  setup () {
88
- if (!this.options.src) return
69
+ events.attach(this.options.events, this)
89
70
 
71
+ if (!this.options.src) return
90
72
  this.setTarget(this.options.element)
91
73
  }
92
74
 
package/src/slider.js CHANGED
@@ -12,75 +12,53 @@ import emitter from './module/emitter'
12
12
 
13
13
  import icon from './skin/material/icon/pin.svg'
14
14
 
15
- const defaults = {
16
- prefix: 'material',
17
- class: 'slider',
18
- type: 'control',
19
- label: null,
20
- checked: false,
21
- error: false,
22
- value: false,
23
- range: [0, 100],
24
- step: 5,
25
- modules: [control, emitter],
26
- mixins: [],
27
- build: ['$root.material-slider', {},
28
- ['label$label.slider-label', {}],
29
- ['input$input'],
30
- ['$control.slider-control', {},
31
- ['$track.slider-track', {},
32
- ['canvas$canvas.slider-canvas', {}],
33
- ['$trackvalue.slider-track-value', {}],
34
- ['$knob.slider-knob', {}],
35
- ['$marker.slider-marker', {},
36
- ['$value.slider-value', {}]
15
+ class Slider {
16
+ static defaults = {
17
+ class: 'slider',
18
+ type: 'control',
19
+ label: null,
20
+ checked: false,
21
+ error: false,
22
+ value: false,
23
+ range: [0, 100],
24
+ step: 5,
25
+ modules: [control, emitter],
26
+ mixins: [],
27
+ build: ['$root.material-slider', {},
28
+ ['label$label.slider-label', {}],
29
+ ['input$input'],
30
+ ['$control.slider-control', {},
31
+ ['$track.slider-track', {},
32
+ ['canvas$canvas.slider-canvas', {}],
33
+ ['$trackvalue.slider-track-value', {}],
34
+ ['$knob.slider-knob', {}],
35
+ ['$marker.slider-marker', {},
36
+ ['$value.slider-value', {}]
37
+ ]
37
38
  ]
38
39
  ]
40
+ ],
41
+ events: [
42
+ ['element.input.focus', 'focus'],
43
+ ['element.input.blur', 'blur']
39
44
  ]
40
- ],
41
- events: [
42
- ['element.input.focus', 'focus'],
43
- ['element.input.blur', 'blur']
44
- ]
45
- }
46
-
47
- /**
48
- * Switch class
49
- * @class
50
- * @extends Control
51
- */
52
- class Slider {
53
- static uid = "material-slider";
45
+ }
54
46
 
55
- /**
56
- * init
57
- * @return {Object} The class options
58
- */
59
47
  constructor (options) {
60
- this.options = Object.assign({}, defaults, options || {})
61
-
62
48
  this.init(this.options)
63
49
  this.build(this.options)
64
- events.attach(this.options.events, this)
65
-
66
- return this
50
+ this.setup()
67
51
  }
68
52
 
69
- /**
70
- * Constructor
71
- * @param {Object} options The class options
72
- * @return {Object} This class instance
73
- */
74
53
  init (options) {
54
+ this.options = Object.assign({}, Slider.defaults, options || {})
75
55
  init(this)
56
+ }
76
57
 
77
- return this
58
+ setup () {
59
+ events.attach(this.options.events, this)
78
60
  }
79
61
 
80
- /**
81
- * build method
82
- * @return {Object} The class instance
83
- */
84
62
  build () {
85
63
  this.element = build(this.options.build)
86
64
  this.element = this.element.root
package/src/snackbar.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // base class
2
2
  import EventEmitter from './mixin/emitter'
3
3
  // related modules
4
- import build from './module/build'
4
+ import build from './mixin/build'
5
5
  import events from './module/events'
6
6
  import display from './mixin/display'
7
7
  // ui element
package/src/switch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // base
2
2
  import EventEmitter from './mixin/emitter'
3
3
  // module
4
- import build from './module/build'
4
+ import build from './mixin/build'
5
5
  import dataset from './module/dataset'
6
6
  import events from './module/events'
7
7
  import attributes from './module/attributes'
package/src/switcher.js CHANGED
@@ -23,7 +23,7 @@ class Switcher extends EventEmitter {
23
23
  }
24
24
 
25
25
  init (options) {
26
- this.options = Object.assign({}, Switcher.defaults, options || {})
26
+ this.options = { ...Switcher.defaults, ...options }
27
27
  }
28
28
 
29
29
  build () {
package/src/tabs.js CHANGED
@@ -6,27 +6,20 @@ import offset from './element/offset'
6
6
 
7
7
  import List from './list'
8
8
  import Button from './button'
9
- import Divider from './divider'
9
+ import Element from './element'
10
10
 
11
- const defaults = {
12
- prefix: 'material',
13
- class: 'tabs',
14
- tag: 'div',
15
- indicator: {
11
+ class Tabs {
12
+ static defaults = {
16
13
  prefix: 'material',
17
- class: 'indicator',
18
- tag: 'div'
14
+ class: 'tabs',
15
+ tag: 'div',
16
+ indicator: {
17
+ prefix: 'material',
18
+ class: 'indicator',
19
+ tag: 'div'
20
+ }
19
21
  }
20
- }
21
22
 
22
- class Tabs {
23
- static uid = "material-tabs";
24
-
25
- /**
26
- * Constructor
27
- * @param {Object} options - Component options
28
- * @return {Object} Class instance
29
- */
30
23
  constructor (options) {
31
24
  this.init(options)
32
25
  this.build()
@@ -35,7 +28,7 @@ class Tabs {
35
28
  }
36
29
 
37
30
  init (options) {
38
- this.options = Object.assign({}, defaults, options || {})
31
+ this.options = { ...Tabs.defaults, ...options }
39
32
  Object.assign(this, insert, emitter)
40
33
  }
41
34
 
@@ -58,7 +51,7 @@ class Tabs {
58
51
  render: (info) => {
59
52
  let item
60
53
  if (info.type === 'divider') {
61
- item = new Divider()
54
+ item = new Element({ class: 'divider' })
62
55
  } else {
63
56
  item = new Button({
64
57
  name: info.name,
package/src/tabview.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from './mixin/emitter'
2
2
  import observer from './element/observer'
3
3
  import events from './module/events'
4
- import build from './module/build'
4
+ import build from './mixin/build'
5
5
  import display from './view/display'
6
6
 
7
7
  class TabView extends EventEmitter {
package/src/text.js CHANGED
@@ -1,8 +1,6 @@
1
- import build from './module/build'
1
+ import build from './mixin/build'
2
2
 
3
3
  class Text {
4
- static uid = "material-text";
5
-
6
4
  static defaults = {
7
5
  class: 'text',
8
6
  tag: 'span'
@@ -15,7 +13,7 @@ class Text {
15
13
  }
16
14
 
17
15
  init (options) {
18
- this.options = Object.assign({}, Text.defaults, options || {})
16
+ this.options = { ...Text.defaults, ...options }
19
17
  Object.assign(this, build)
20
18
  }
21
19
 
package/src/textfield.js CHANGED
@@ -4,8 +4,6 @@ import dataset from './module/dataset'
4
4
  import attributes from './module/attributes'
5
5
 
6
6
  class Textfield {
7
- static uid = "material-textfield";
8
-
9
7
  static isComponent () {
10
8
  return true
11
9
  }
@@ -28,7 +26,7 @@ class Textfield {
28
26
  }
29
27
 
30
28
  init (options) {
31
- this.options = Object.assign({}, Textfield.defaults, options || {})
29
+ this.options = { ...Textfield.defaults, ...options }
32
30
  Object.assign(this, emitter, dataset)
33
31
  // console.log('options', options)
34
32
  }
package/src/toolbar.js CHANGED
@@ -4,40 +4,26 @@ import create from './mixin/create'
4
4
  import insert from './mixin/insert'
5
5
  import offset from './element/offset'
6
6
 
7
- const defaults = {
8
- prefix: 'material',
9
- class: 'toolbar',
10
- tag: 'div'
11
- }
12
-
13
7
  class Toolbar {
14
- static uid = "material-toolbar";
8
+ static defaults = {
9
+ prefix: 'material',
10
+ class: 'toolbar',
11
+ tag: 'div'
12
+ }
15
13
 
16
- /**
17
- * Constructor
18
- * @param {Object} options - Component options
19
- * @return {Object} Class instance
20
- */
21
14
  constructor (options) {
22
15
  this.init(options)
23
16
  this.build()
24
17
  this.attach()
25
- return this
26
18
  }
27
19
 
28
20
  init (options) {
29
- this.options = Object.assign({}, defaults, options || {})
21
+ this.options = { ...Toolbar.defaults, ...options }
30
22
  Object.assign(this, insert)
31
23
 
32
- // console.log('waterfALL', this.options.waterfall)
33
-
34
24
  this.waterfall = this.options.waterfall
35
25
  }
36
26
 
37
- /**
38
- * Build Method
39
- * @return {Object} This class instance
40
- */
41
27
  build () {
42
28
  this.element = create(this.options)
43
29