rask-ui 0.2.7 → 0.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.
@@ -27,13 +27,29 @@ export function createState(state) {
27
27
  return getProxy(state);
28
28
  }
29
29
  const proxyCache = new WeakMap();
30
+ const PROXY_MARKER = Symbol('isProxy');
30
31
  function getProxy(value) {
32
+ // Check if already a proxy to avoid double-wrapping
33
+ if (PROXY_MARKER in value) {
34
+ return value;
35
+ }
31
36
  if (proxyCache.has(value)) {
32
37
  return proxyCache.get(value);
33
38
  }
34
39
  const signals = {};
35
40
  const proxy = new Proxy(value, {
41
+ has(target, key) {
42
+ // Support the "in" operator check for PROXY_MARKER
43
+ if (key === PROXY_MARKER) {
44
+ return true;
45
+ }
46
+ return Reflect.has(target, key);
47
+ },
36
48
  get(target, key) {
49
+ // Mark this as a proxy to prevent double-wrapping
50
+ if (key === PROXY_MARKER) {
51
+ return true;
52
+ }
37
53
  const value = Reflect.get(target, key);
38
54
  if (typeof key === "symbol" || typeof value === "function") {
39
55
  return value;
@@ -31,7 +31,7 @@ export declare abstract class AbstractVNode {
31
31
  patchChildren(newChildren: VNode[]): {
32
32
  children: VNode[];
33
33
  hasChangedStructure: boolean;
34
- operations: PatchOperation[];
34
+ operations?: PatchOperation[];
35
35
  };
36
36
  applyPatchOperations(target: HTMLElement, operations: PatchOperation[]): void;
37
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractVNode.d.ts","sourceRoot":"","sources":["../../src/vdom/AbstractVNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;CACpB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE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,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE;IAqCtE;;;;OAIG;IACH,SAAS,CAAC,eAAe;CA6B1B"}
@@ -63,13 +63,15 @@ export class AbstractVNode {
63
63
  }
64
64
  patchChildren(newChildren) {
65
65
  const prevChildren = this.children;
66
+ if (newChildren.length === 0 && prevChildren.length === 0) {
67
+ return { children: [], hasChangedStructure: false };
68
+ }
66
69
  // When there are only new children, we just mount them
67
- if (newChildren && prevChildren.length === 0) {
70
+ if (prevChildren.length === 0) {
68
71
  newChildren.forEach((child) => child.mount(this));
69
72
  return {
70
73
  children: newChildren,
71
74
  hasChangedStructure: true,
72
- operations: [],
73
75
  };
74
76
  }
75
77
  // If we want to remove all children, we just unmount the previous ones
@@ -100,11 +100,11 @@ export class ComponentVNode extends AbstractVNode {
100
100
  this.children = children;
101
101
  // So if a fragment is returned where we add new elements we can not safely
102
102
  // add them yet, check Fragment for a potential later optimization
103
- const hasAddOperation = operations.some((operation) => operation.type === "add");
103
+ const hasAddOperation = operations?.some((operation) => operation.type === "add");
104
104
  if (hasChangedStructure || hasAddOperation) {
105
105
  this.parent?.rerender();
106
106
  }
107
- else if (operations.length) {
107
+ else if (operations?.length) {
108
108
  this.parent?.rerender(operations);
109
109
  }
110
110
  this.root?.clearCurrent();
@@ -100,7 +100,7 @@ export class ElementVNode extends AbstractVNode {
100
100
  if (hasChangedStructure) {
101
101
  this.syncDOMChildren();
102
102
  }
103
- else {
103
+ else if (operations?.length) {
104
104
  this.applyPatchOperations(this.getHTMLElement(), operations);
105
105
  }
106
106
  }
@@ -36,7 +36,7 @@ export class FragmentVNode extends AbstractVNode {
36
36
  // handled with some additional detection, changing it to insertBefore. This can be
37
37
  // done by passing this vnode up to the parent
38
38
  this.rerender(hasChangedStructure ||
39
- operations.some((operation) => operation.type === "add")
39
+ operations?.some((operation) => operation.type === "add")
40
40
  ? undefined
41
41
  : operations);
42
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",