@fruit-ui/core 1.2.7 → 1.2.9

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/package.json +2 -2
  2. package/src/index.js +16 -5
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@fruit-ui/core",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "A vanilla JS toolkit for reactive UI",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://asantagata.github.io/fruit-ui/",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "terser .\\src\\index.js -o .\\dist\\index.js && copy ..\\README.md ."
9
+ "build": "terser .\\src\\index.js -o .\\dist\\index.js --mangle --toplevel && copy ..\\README.md ."
10
10
  },
11
11
  "keywords": [
12
12
  "fruit",
package/src/index.js CHANGED
@@ -113,10 +113,13 @@ function enqueueToRerender(componentId) {
113
113
  */
114
114
  function createThis(component) {
115
115
  return {
116
+ rerender() {},
117
+ producer() {},
118
+ element: null,
116
119
  state: {},
117
120
  setState: {},
118
121
  bindings: {},
119
- memo: deepClone(component.memo)
122
+ memo: typeof component.memo === 'object' ? deepClone(component.memo) : component.memo
120
123
  };
121
124
  }
122
125
 
@@ -155,9 +158,13 @@ function createElementFromTemplate(template, onMounts, producer = null) {
155
158
  initializeThis.call(this, element, producer);
156
159
  }
157
160
  return element;
161
+ } else if (template.HTML) {
162
+ const div = document.createElement('div');
163
+ div.innerHTML = template.HTML;
164
+ return div.firstChild;
158
165
  }
159
- const {tag, class: c, style, on, componentId, children, cloneFrom, dataset, key, binding, innerHTML, ...rest} = template;
160
- const element = document.createElement(template.tag || 'div');
166
+ const {tag, class: c, style, on, componentId, children, cloneFrom, dataset, key, binding, innerHTML, xmlns, ...rest} = template;
167
+ const element = template.xmlns ? document.createElementNS(template.xmlns, template.tag) : document.createElement(template.tag || 'div');
161
168
  if (template.class) {
162
169
  switch (typeof template.class) {
163
170
  case 'string':
@@ -284,7 +291,7 @@ function createElementFromElementable(elementable, onMounts) {
284
291
  function createElementFromComponent(component, onMounts) {
285
292
  const boundProducer = bindTemplateProducer(component.render, component);
286
293
  thisRecord[boundProducer.componentId] = boundProducer.this;
287
- boundProducer.this.state = component.state ? component.state() : {};
294
+ boundProducer.this.state = component.state ? component.state.call(boundProducer.this) : {};
288
295
  const template = boundProducer();
289
296
  return createElementFromTemplate.call(boundProducer.this, giveTemplateComponentMetadata(template, boundProducer.componentId, component.key, component.binding), onMounts, boundProducer);
290
297
  }
@@ -400,6 +407,10 @@ function rerenderElementFromTemplate(element, template, onMounts) {
400
407
  }
401
408
  if (template.cloneFrom && !element.isEqualNode(template.cloneFrom)) {
402
409
  return element.replaceWith(template.cloneFrom.cloneNode(true));
410
+ } else if (template.HTML) {
411
+ const div = document.createElement('div');
412
+ div.innerHTML = template.HTML;
413
+ return element.replaceWith(div.firstChild);
403
414
  }
404
415
  if ((template.tag?.toUpperCase() || 'DIV') !== element.tagName) {
405
416
  // tag cannot be changed
@@ -430,7 +441,7 @@ function rerenderElementFromTemplate(element, template, onMounts) {
430
441
  element.dataset[key] = template.dataset[key];
431
442
  }
432
443
  }
433
- const {tag, cloneFrom, class: _, style, on, key, dataset, componentId, children, innerHTML, binding, ...rest} = template;
444
+ const {tag, class: c, style, on, componentId, children, cloneFrom, dataset, key, binding, innerHTML, xmlns, ...rest} = template;
434
445
  for (const attribute in rest) {
435
446
  element.setAttribute(attribute, template[attribute]);
436
447
  }