ziko 2.0.0-beta.13 → 2.0.0-beta.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
5
5
  "keywords": [
6
6
  "front-end",
@@ -1,8 +1,8 @@
1
1
  import { isStateGetter } from "../../hooks/use-state.js";
2
- // import {
3
- // is_camelcase,
4
- // camel2hyphencase
5
- // } from '../../../data/string/index.js'
2
+ import {
3
+ is_camelcase,
4
+ camel2hyphencase
5
+ } from '../../string/index.js'
6
6
 
7
7
  export function setAttr(name, value) {
8
8
  if(name instanceof Object){
@@ -32,65 +32,16 @@ export function setContentEditable(bool = true) {
32
32
  }
33
33
 
34
34
 
35
- // export function _set_attrs_(name, value){
36
- // if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
37
- // if(this?.attr[name] && this?.attr[name]===value) return;
38
- // if(isStateGetter(value)){
39
- // const getter = value()
40
- // getter._subscribe(
41
- // (newValue) => this.element?.setAttribute(name, newValue),
42
- // this
43
- // );
44
- // }
45
- // else this.element?.setAttribute(name, value)
46
- // Object.assign(this.cache.attributes, {[name]:value});
47
- // }
48
-
49
- function _set_attrs_(name, value) {
50
- if (!this?.element || name == null)
51
- return;
52
- // Normalize SVG attribute names
53
- if (
54
- globalThis.SVGAElement &&
55
- this.element instanceof globalThis.SVGAElement
56
- ) {
57
- name = is_camelcase(name)
58
- ? camel2hyphencase(name)
59
- : name;
60
- }
61
-
62
- // Ensure internal attribute storage exists
63
- // this.attr ??= {};
64
- // this.cache ??= {};
65
- // this.cache.attributes ??= {};
66
-
67
- // Skip unchanged attributes
68
- if (
69
- Object.prototype.hasOwnProperty.call(this.attr, name) &&
70
- this.attr[name] === value
71
- ) {
72
- return;
73
- }
74
-
75
- // Reactive/state attribute
76
- if (isStateGetter(value)) {
77
- const state = value();
78
-
79
- state?._subscribe(
80
- (newValue) => {
81
- this.element?.setAttribute(name, newValue);
82
- this.cache.attributes[name] = newValue;
83
- this.attr[name] = newValue;
84
- },
85
- this
35
+ export function _set_attrs_(name, value){
36
+ if(globalThis.SVGAElement && this.element instanceof globalThis.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
37
+ // if(this?.attr[name] && this?.attr[name]===value) return;
38
+ if(isStateGetter(value)){
39
+ const getter = value()
40
+ getter._subscribe(
41
+ (newValue) => this.element?.setAttribute(name, newValue),
42
+ this
86
43
  );
87
-
88
- return;
89
44
  }
90
-
91
- // Normal attribute
92
- this.element.setAttribute(name, value);
93
-
94
- this.attr[name] = value;
95
- this.cache.attributes[name] = value;
96
- }
45
+ else this.element?.setAttribute(name, value)
46
+ // Object.assign(this.cache.attributes, {[name]:value});
47
+ }
@@ -62,12 +62,17 @@ export async function __addItem__(adder, pusher, item, referenceNode = null, ind
62
62
  if (["number", "string"].includes(typeof item)) item = text(item);
63
63
  if (typeof item === "function" && isStateGetter(item)) {
64
64
  const getter = item();
65
- item = text(getter.value);
66
- getter._subscribe(
67
- (newValue) => { item.element.textContent = newValue; },
68
- item
69
- );
70
- }
65
+ item = getter.value;
66
+
67
+ getter._subscribe((newValue) => {
68
+ if (newValue?.isUIElement?.()) {
69
+ item.element.replaceWith(newValue.element);
70
+ item = newValue;
71
+ } else {
72
+ item.element.textContent = newValue;
73
+ }
74
+ });
75
+ }
71
76
  if (typeof globalThis?.Node === "function" && item instanceof globalThis.Node)
72
77
  item = new this.constructor(item);
73
78
  if (item instanceof Promise) item = await item;