material 0.8.7 → 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 +1 -1
- package/src/appbar.js +2 -0
- package/src/badge.js +2 -0
- package/src/calendar.js +2 -0
- package/src/card.js +2 -0
- package/src/checkbox.js +2 -0
- package/src/component.js +2 -0
- package/src/datehour.js +2 -0
- package/src/dialog.js +2 -0
- package/src/divider.js +2 -0
- package/src/drawer.js +2 -0
- package/src/element.js +2 -0
- package/src/file.js +2 -0
- package/src/form.js +2 -0
- package/src/icon.js +2 -0
- package/src/image.js +2 -0
- package/src/item.js +2 -0
- package/src/layout.js +47 -94
- package/src/link.js +2 -0
- package/src/list/collection.js +2 -0
- package/src/list/virtual.new.js +2 -0
- package/src/list.js +2 -0
- package/src/loader.js +2 -0
- package/src/loading.js +2 -0
- package/src/map.js +2 -0
- package/src/mixin/controller.js +2 -0
- package/src/mixin/emitter.js +2 -0
- package/src/module/serialize.js +25 -0
- package/src/progress.js +2 -0
- package/src/selector.js +2 -0
- package/src/slider.js +2 -0
- package/src/tabs.js +2 -0
- package/src/text.js +2 -0
- package/src/textfield.js +2 -0
- package/src/toolbar.js +2 -0
- package/src/tooltip.js +2 -0
- package/src/tree.js +2 -0
package/package.json
CHANGED
package/src/appbar.js
CHANGED
package/src/badge.js
CHANGED
package/src/calendar.js
CHANGED
package/src/card.js
CHANGED
package/src/checkbox.js
CHANGED
package/src/component.js
CHANGED
package/src/datehour.js
CHANGED
package/src/dialog.js
CHANGED
package/src/divider.js
CHANGED
package/src/drawer.js
CHANGED
package/src/element.js
CHANGED
package/src/file.js
CHANGED
package/src/form.js
CHANGED
package/src/icon.js
CHANGED
package/src/image.js
CHANGED
package/src/item.js
CHANGED
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
package/src/list/collection.js
CHANGED
package/src/list/virtual.new.js
CHANGED
|
@@ -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
package/src/loader.js
CHANGED
package/src/loading.js
CHANGED
package/src/map.js
CHANGED
package/src/mixin/controller.js
CHANGED
package/src/mixin/emitter.js
CHANGED
|
@@ -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
package/src/selector.js
CHANGED
package/src/slider.js
CHANGED
package/src/tabs.js
CHANGED
package/src/text.js
CHANGED
package/src/textfield.js
CHANGED
package/src/toolbar.js
CHANGED
package/src/tooltip.js
CHANGED