@alexgyver/component 1.0.10 → 1.0.13

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 (2) hide show
  1. package/component.js +11 -2
  2. package/package.json +1 -1
package/component.js CHANGED
@@ -77,7 +77,7 @@ export class Component {
77
77
  html {string} добавить в innerHTML
78
78
  class {string} добавить в className
79
79
  also {function} - вызвать с текущим компонентом: { ... , also(el) { console.log(el); }, }
80
- export {} - присвоить к указанной переменной
80
+ export {array} - положить в 0 ячейку указанного массива
81
81
  var {string} создаёт переменную $имя в указанном контексте
82
82
  events {object} добавляет addEventListener'ы {event: handler}
83
83
  parent - {Element} добавляет компонент к указанному элементу (имеет смысл только для корневого компонента)
@@ -109,7 +109,7 @@ export class Component {
109
109
  case 'html': $el.innerHTML = val; break;
110
110
  case 'class': $el.className = val; break;
111
111
  case 'also': if (context) val.call(context, $el); break;
112
- case 'export': val = $el; break;
112
+ case 'export': val[0] = $el; break;
113
113
  case 'var': if (context) context['$' + val] = $el; break;
114
114
  case 'events': for (const [ev, handler] of Object.entries(val)) if (handler) $el.addEventListener(ev, handler.bind(context)); break;
115
115
  case 'parent': if (val instanceof Element) val.append($el); break;
@@ -135,4 +135,13 @@ export class Component {
135
135
  }
136
136
  return $el;
137
137
  }
138
+
139
+ /**
140
+ * Создать массив компонентов из массива объектов конфигурации
141
+ * @param {array} arr массив объектов конфигурации
142
+ * @returns {array} of Elements
143
+ */
144
+ static makeArray(arr) {
145
+ return arr.map(x => Component.make(x.tag, x));
146
+ }
138
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgyver/component",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "Simple HTML element builder",
5
5
  "main": "./component.js",
6
6
  "module": "./component.js",