@fruit-ui/core 1.2.6 → 1.2.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/README.md CHANGED
@@ -64,7 +64,7 @@ Smaller apps don't always warrant heavyweight frameworks, but interfacing with t
64
64
  ## Getting started
65
65
 
66
66
  There are three ways to use FRUIT in your projects:
67
- - Download and copy the [Terser-compressed JS file](https://github.com/asantagata/fruit-ui/blob/main/core/dist/index.js) file into your project. (This is a compressed version built with Terser; you can just as well use the [non-compressed version](https://github.com/asantagata/fruit-ui/blob/main/core/src/index.js) which uses JSDoc annotations.) Then you can use `import * as fruit from "./modules/fruit.js"` or `<script type="module" src="./modules/fruit.js">` to access FRUIT in your JS apps.
67
+ - Download and copy the [Terser-compressed JS file](https://github.com/asantagata/fruit-ui/blob/main/core/dist/index.js) file into your project. (This is a compressed version built with Terser; you can just as well use the [non-compressed version](https://github.com/asantagata/fruit-ui/blob/main/core/src/index.js) which uses JSDoc annotations). Then you can use `import * as fruit from "./modules/fruit.js"` or `<script type="module" src="./modules/fruit.js">` to access FRUIT in your JS apps.
68
68
  - Access via browser loading, i.e., `import * as fruit from "https://cdn.jsdelivr.net/npm/@fruit-ui/core@latest/src/index.js"`.
69
69
  - With NPM installed, run `npm install @fruit-ui/core`. Then use `import * as fruit from "@fruit-ui/core"`.
70
70
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@fruit-ui/core",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
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
@@ -155,9 +155,13 @@ function createElementFromTemplate(template, onMounts, producer = null) {
155
155
  initializeThis.call(this, element, producer);
156
156
  }
157
157
  return element;
158
+ } else if (template.HTML) {
159
+ const div = document.createElement('div');
160
+ div.innerHTML = template.HTML;
161
+ return div.firstChild;
158
162
  }
159
- const {tag, class: c, style, on, componentId, children, cloneFrom, dataset, key, binding, innerHTML, ...rest} = template;
160
- const element = document.createElement(template.tag || 'div');
163
+ const {tag, class: c, style, on, componentId, children, cloneFrom, dataset, key, binding, innerHTML, xmlns, ...rest} = template;
164
+ const element = template.xmlns ? document.createElementNS(template.xmlns, template.tag) : document.createElement(template.tag || 'div');
161
165
  if (template.class) {
162
166
  switch (typeof template.class) {
163
167
  case 'string':
@@ -400,6 +404,10 @@ function rerenderElementFromTemplate(element, template, onMounts) {
400
404
  }
401
405
  if (template.cloneFrom && !element.isEqualNode(template.cloneFrom)) {
402
406
  return element.replaceWith(template.cloneFrom.cloneNode(true));
407
+ } else if (template.HTML) {
408
+ const div = document.createElement('div');
409
+ div.innerHTML = template.HTML;
410
+ return element.replaceWith(div.firstChild);
403
411
  }
404
412
  if ((template.tag?.toUpperCase() || 'DIV') !== element.tagName) {
405
413
  // tag cannot be changed
@@ -430,7 +438,7 @@ function rerenderElementFromTemplate(element, template, onMounts) {
430
438
  element.dataset[key] = template.dataset[key];
431
439
  }
432
440
  }
433
- const {tag, cloneFrom, class: _, style, on, key, dataset, componentId, children, innerHTML, binding, ...rest} = template;
441
+ const {tag, class: c, style, on, componentId, children, cloneFrom, dataset, key, binding, innerHTML, xmlns, ...rest} = template;
434
442
  for (const attribute in rest) {
435
443
  element.setAttribute(attribute, template[attribute]);
436
444
  }
@@ -649,6 +657,21 @@ function rerenderChildren(element, template, onMounts) {
649
657
  childEl.remove();
650
658
  }
651
659
  }
660
+ } else if (tmChildrenArray.length === 0 && elChildrenArray.length > 0) {
661
+ // delete all children
662
+ for (let i = elChildrenArray.length - 1; i >= 0; i--) {
663
+ let childEl = elChildrenArray[i];
664
+ if ('componentId' in childEl.dataset) delete thisRecord[childEl.dataset.componentId];
665
+ if ('binding' in childEl.dataset) delete this.bindings[childEl.dataset.binding];
666
+ childEl.remove();
667
+ }
668
+ } else if (tmChildrenArray.length > 0 && elChildrenArray.length === 0) {
669
+ // create all children
670
+ for (let i = 0; i < tmChildrenArray.length; i++) {
671
+ let childTm = tmChildrenArray[i];
672
+ const newChild = createElementFromElementable.call(this, childTm, onMounts);
673
+ element.appendChild(newChild);
674
+ }
652
675
  }
653
676
 
654
677
  // handle bindings