@potok-web-framework/core 0.5.0 → 0.7.0

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/dist/block.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare abstract class LibBlock {
4
4
  node: LibNode | null;
5
5
  abstract context: LibContext;
6
6
  abstract props: LibProps;
7
- effects: Effect[];
7
+ effects: Set<Effect>;
8
8
  children: (LibBlock | null)[];
9
9
  get nearestParentElement(): LibHtmlElementNode | null;
10
10
  get previousBlock(): LibBlock | null;
package/dist/client.mjs CHANGED
@@ -1,133 +1,103 @@
1
- import { a as objectKeys, c as createEffect, l as createSignal, p as untrack, u as deepTrack } from "./utils-CAe_kbSH.mjs";
1
+ import { i as createSignal, r as createEffect } from "./signals-ZsU9bGc3.mjs";
2
2
  import { n as HTML_ELEMENT_STYLE_PX_PROPERTIES } from "./constants-BOAOReQ3.mjs";
3
- function renderToDOM(o) {
4
- let s = o.root ?? document, c = /* @__PURE__ */ new Map(), l = createSignal({
3
+ function isTextNode(e) {
4
+ return e.nodeType === Node.TEXT_NODE;
5
+ }
6
+ function isHTMLElementNode(e) {
7
+ return e.nodeType === Node.ELEMENT_NODE;
8
+ }
9
+ function isLibNodeEqualToDomNode(e, t) {
10
+ return e.type === "text" && isTextNode(t) ? String(e.props.text) === t.textContent : e.type === "html-element" && isHTMLElementNode(t) ? e.props.tag === t.tagName.toLowerCase() : !1;
11
+ }
12
+ function hydrate(r) {
13
+ let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), l = createSignal({
5
14
  portals: {},
6
- listeners: {},
7
- isHydrating: o.needToHydrate ?? !1
15
+ isHydrating: !0
8
16
  });
9
- function u(e) {
10
- let t = e.replace(/^on([A-Z])/, (e, t) => t.toLowerCase());
11
- document.addEventListener(t, (t) => {
12
- let n = !1, r = t.target, i = t.stopPropagation.bind(t), a = t.stopImmediatePropagation.bind(t);
13
- for (t.stopPropagation = () => {
14
- n = !0, i();
15
- }, t.stopImmediatePropagation = () => {
16
- n = !0, a();
17
- }; r;) {
18
- let i = l.listeners[e]?.get(r);
19
- if (i && (Object.defineProperty(t, "currentTarget", {
20
- configurable: !0,
21
- enumerable: !0,
22
- get: () => r
23
- }), i(t), n)) break;
24
- r = r.parentElement;
17
+ function u(e, t, r, a) {
18
+ if (e.type === "text") t.textContent = String(a);
19
+ else if (e.type === "html-element" && isHTMLElementNode(t)) if (r.startsWith("on")) if (a) {
20
+ if (s.has(r) || s.set(r, /* @__PURE__ */ new Map()), s.get(r).set(t, a), !c.has(r)) {
21
+ let e = r.replace(/^on/, "").toLowerCase();
22
+ document.addEventListener(e, (e) => {
23
+ let t = !1, n = e.target, i = e.stopPropagation.bind(e), a = e.stopImmediatePropagation.bind(e);
24
+ for (e.stopPropagation = () => {
25
+ t = !0, i();
26
+ }, e.stopImmediatePropagation = () => {
27
+ t = !0, a();
28
+ }; n;) {
29
+ let i = s.get(r)?.get(n);
30
+ if (i && (Object.defineProperty(e, "currentTarget", {
31
+ configurable: !0,
32
+ enumerable: !0,
33
+ get: () => n
34
+ }), i(e), t)) break;
35
+ n = n.parentElement;
36
+ }
37
+ }), c.add(r);
25
38
  }
26
- });
39
+ } else s.get(r)?.delete(t);
40
+ else if (r.startsWith("aria")) {
41
+ let e = r.toLowerCase().replace("aria", "aria-");
42
+ a ? t.setAttribute(e, a) : t.removeAttribute(e);
43
+ } else r === "className" ? a ? t.className = a : t.removeAttribute("class") : r === "style" ? a ? Object.keys(a).forEach((e) => {
44
+ let r = a[e];
45
+ if (r !== void 0) {
46
+ let i = String(HTML_ELEMENT_STYLE_PX_PROPERTIES.has(e) && typeof r == "number" ? `${r}px` : r);
47
+ t.style.setProperty(e, i);
48
+ } else t.style.removeProperty(e);
49
+ }) : t.removeAttribute("style") : a == null ? t.removeAttribute(r) : t.setAttribute(r, String(a));
27
50
  }
28
- let d = /* @__PURE__ */ new Set();
29
- createEffect(() => {
30
- deepTrack(l.listeners, 1), untrack(() => {
31
- objectKeys(l.listeners).forEach((e) => {
32
- d.has(e) || (u(e), d.add(e));
33
- });
34
- });
35
- }, !0);
36
- let f = (e, t, n) => e.insertBefore(t, n ? n.nextSibling : e.firstChild), p = (e) => e instanceof HTMLElement;
37
- if (!o.needToHydrate) for (; s.firstChild;) s.removeChild(s.firstChild);
38
- o.app()({
51
+ let d = {
39
52
  parentBlock: null,
40
53
  index: 0,
41
54
  portals: l.portals,
42
55
  contexts: {},
43
- listeners: l.listeners,
44
56
  isServer: !1,
45
57
  promises: [],
46
58
  get isHydrating() {
47
59
  return l.isHydrating;
48
60
  },
49
- insertNode(e, t, n) {
50
- if (l.isHydrating) {
51
- if (e === null) c.set(t, document.querySelector("html"));
52
- else {
53
- let r = c.get(e);
54
- if (!r) throw Error("Ошибка гидрации");
55
- let i = null;
56
- if (n) {
57
- let e = c.get(n);
58
- if (!e) throw Error("Ошибка гидрации");
59
- i = e.nextSibling;
60
- } else i = r.firstChild;
61
- for (;;) {
62
- if (!i) throw Error("Ошибка гидрации");
63
- if (t.type === "text" && String(t.props.text) === i.textContent || t.type === "html-element" && p(i) && t.props.tag === i.tagName.toLowerCase()) {
64
- c.set(t, i);
65
- break;
66
- } else {
67
- let e = i;
68
- i = i.nextSibling, e.parentElement?.removeChild(e);
69
- }
70
- }
61
+ insertNode(e, n, r) {
62
+ let i;
63
+ if (e) {
64
+ if (!o.has(e)) {
65
+ if (l.isHydrating) throw Error("Ошибка гидрации");
66
+ o.set(e, document.createElement(e.props.tag));
71
67
  }
72
- return;
73
- }
74
- e && !c.has(e) && c.set(e, document.createElement(e.props.tag));
75
- let r = e ? c.get(e) : s, i = (n && c.get(n)) ?? null;
76
- if (t.type === "text") {
77
- let e = document.createTextNode(String(t.props.text));
78
- c.set(t, e), this.updateTextNode(t), f(r, e, i);
79
- } else if (t.type === "html-element") {
80
- c.has(t) || c.set(t, document.createElement(t.props.tag));
81
- for (let [e, n] of Object.entries(Object.getOwnPropertyDescriptors(t.props))) {
82
- if ([
83
- "tag",
84
- "children",
85
- "ref"
86
- ].includes(e)) continue;
87
- let r = n.get?.() ?? n.value;
88
- this.updateHtmlElementNodeProp(t, e, r);
68
+ i = o.get(e);
69
+ } else i = document;
70
+ let s = null;
71
+ if (r && (s = o.get(r) ?? null), l.isHydrating) {
72
+ let e = s ? s.nextSibling : i.firstChild;
73
+ for (;;) {
74
+ if (!e) throw Error("Ошибка гидрации");
75
+ if (isLibNodeEqualToDomNode(n, e)) {
76
+ o.set(n, e);
77
+ break;
78
+ } else {
79
+ let t = e;
80
+ e = e.nextSibling, t.parentElement?.removeChild(t);
81
+ }
89
82
  }
90
- let e = c.get(t);
91
- f(r, e, i), t.props.ref && (t.props.ref.element = e);
92
- } else throw Error("Неверный тип ноды");
93
- },
94
- updateTextNode(e) {
95
- let t = e.props.text, n = c.get(e);
96
- n && (n.textContent = String(t));
97
- },
98
- updateHtmlElementNodeProp(e, t, n) {
99
- let r = c.get(e);
100
- if (!r) return;
101
- let i = r;
102
- if (((e) => e.startsWith("on"))(t)) {
103
- n ? (this.listeners[t] ??= /* @__PURE__ */ new Map(), this.listeners[t].set(i, n)) : this.listeners[t]?.delete(i);
104
- return;
105
- }
106
- if (t.startsWith("aria")) {
107
- let e = t.toLowerCase().replace("aria", "aria-");
108
- n ? i.setAttribute(e, n) : i.removeAttribute(e);
109
- return;
110
- }
111
- if (t === "className") {
112
- n ? i.className = n : i.removeAttribute("class");
113
- return;
114
- }
115
- if (t === "style") {
116
- n ? Object.keys(n).forEach((e) => {
117
- let t = n[e];
118
- if (t !== void 0) {
119
- let n = String(HTML_ELEMENT_STYLE_PX_PROPERTIES.has(e) && typeof t == "number" ? `${t}px` : t);
120
- i.style.setProperty(e, n);
121
- } else i.style.removeProperty(e);
122
- }) : i.removeAttribute("style");
123
- return;
124
- }
125
- n == null ? i.removeAttribute(t) : i.setAttribute(t, String(n));
83
+ } else o.has(n) || (n.type === "text" ? o.set(n, document.createTextNode(String(n.props.text))) : n.type === "html-element" && o.set(n, document.createElement(n.props.tag)));
84
+ let c = o.get(n), d = Object.getOwnPropertyDescriptors(n.props);
85
+ for (let [e, r] of Object.entries(d)) [
86
+ "tag",
87
+ "children",
88
+ "ref"
89
+ ].includes(e) || (r.value && u(n, c, e, r.value), r.get && createEffect(() => {
90
+ u(n, c, e, r.get());
91
+ }, !0));
92
+ l.isHydrating || i.insertBefore(c, s ? s.nextSibling : i.firstChild);
126
93
  },
127
94
  removeNode(e) {
128
- let t = c.get(e);
129
- t && (c.delete(e), p(t) ? t.remove() : t.parentElement?.removeChild(t));
95
+ let t = o.get(e);
96
+ t && (o.delete(e), isHTMLElementNode(t) ? (t.remove(), s.forEach((e) => {
97
+ e.delete(t);
98
+ })) : t.parentElement?.removeChild(t));
130
99
  }
131
- }), o.needToHydrate && (l.isHydrating = !1);
100
+ };
101
+ r.app()(d), l.isHydrating = !1;
132
102
  }
133
- export { renderToDOM };
103
+ export { hydrate };
@@ -0,0 +1,6 @@
1
+ import { PotokElement } from '../types';
2
+ type HydrateOptions = {
3
+ app: () => PotokElement;
4
+ };
5
+ export declare function hydrate(options: HydrateOptions): void;
6
+ export {};
@@ -0,0 +1,4 @@
1
+ import { LibNode } from '../types';
2
+ export declare function isTextNode(node: Node): node is Text;
3
+ export declare function isHTMLElementNode(node: Node): node is HTMLElement;
4
+ export declare function isLibNodeEqualToDomNode(libNode: LibNode, domNode: Node): boolean;
@@ -1 +1 @@
1
- export { renderToDOM } from '../render-to-dom';
1
+ export { hydrate } from '../dom/hydrate';
@@ -11,4 +11,4 @@ export { Show } from '../show';
11
11
  export { createSignal, createEffect, batch, untrack, deepTrack, getSignal, } from '../signals';
12
12
  export { createStore } from '../store';
13
13
  export type { PotokElement, WithChildren } from '../types';
14
- export type * from '../jsx-types.ts';
14
+ export type * from '../jsx-types';
@@ -0,0 +1,103 @@
1
+ import { n as createDisposer } from "./signals-ZsU9bGc3.mjs";
2
+ var LibBlock = class {
3
+ node = null;
4
+ effects = /* @__PURE__ */ new Set();
5
+ children = [];
6
+ get nearestParentElement() {
7
+ return this.node ?? this.context.parentBlock?.nearestParentElement ?? null;
8
+ }
9
+ get previousBlock() {
10
+ let e = this.context.parentBlock;
11
+ return e ? e.children[this.context.index - 1] || (e.node ? null : e.previousBlock) : null;
12
+ }
13
+ get nearestPreviousNode() {
14
+ if (this.node) return this.node;
15
+ let e = this.children[this.children.length - 1];
16
+ if (e) return e.nearestPreviousNode;
17
+ let t = this.previousBlock;
18
+ return t ? t.nearestPreviousNode : null;
19
+ }
20
+ get previousNode() {
21
+ let e = this.previousBlock;
22
+ return e ? e.nearestPreviousNode : null;
23
+ }
24
+ addEffect(e) {
25
+ this.effects.add(e);
26
+ }
27
+ unmountChildren() {
28
+ this.children.forEach((e) => {
29
+ e?.unmount();
30
+ }), this.children = [];
31
+ }
32
+ insertNode() {
33
+ let t = this.node;
34
+ t && createDisposer(() => {
35
+ this.context.insertNode(this.context.parentBlock?.nearestParentElement ?? null, t, this.previousNode);
36
+ }).effects.forEach((e) => {
37
+ this.effects.add(e);
38
+ });
39
+ }
40
+ unmount() {
41
+ this.node && this.context.removeNode(this.node), this.unmountChildren(), this.effects.forEach((e) => {
42
+ e.dispose();
43
+ }), this.effects.clear();
44
+ }
45
+ }, LibText = class extends LibBlock {
46
+ constructor(e, t) {
47
+ super(), this.props = e, this.context = t, this.node = {
48
+ type: "text",
49
+ props: e,
50
+ context: t
51
+ }, this.insertNode();
52
+ }
53
+ };
54
+ function text(e) {
55
+ return function(t) {
56
+ return new LibText(e, t);
57
+ };
58
+ }
59
+ function mergeContext(e, t) {
60
+ return {
61
+ parentBlock: t.parentBlock,
62
+ get index() {
63
+ return t.index;
64
+ },
65
+ portals: e.portals,
66
+ contexts: {
67
+ ...e.contexts,
68
+ ...t.contexts
69
+ },
70
+ isServer: e.isServer,
71
+ promises: e.promises,
72
+ get isHydrating() {
73
+ return e.isHydrating;
74
+ },
75
+ insertNode: e.insertNode,
76
+ removeNode: e.removeNode
77
+ };
78
+ }
79
+ function normalizeArray(e) {
80
+ return Array.isArray(e) ? e : [e];
81
+ }
82
+ function normalizeChild(e) {
83
+ return typeof e == "string" || typeof e == "number" ? [text({ text: String(e) })] : Array.isArray(e) ? e.flatMap(normalizeChildren) : [e];
84
+ }
85
+ function normalizeChildren(e) {
86
+ return e ? normalizeArray(e).filter((e) => e != null).flatMap(normalizeChild) : [];
87
+ }
88
+ var FragmentClass = class extends LibBlock {
89
+ constructor(e, t) {
90
+ super(), this.props = e, this.context = t, normalizeChildren(e.children).forEach((e, n) => {
91
+ this.children.push(e(mergeContext(t, {
92
+ parentBlock: this,
93
+ index: n
94
+ })));
95
+ });
96
+ }
97
+ };
98
+ function fragment(e) {
99
+ return function(t) {
100
+ return new FragmentClass(e, t);
101
+ };
102
+ }
103
+ export { text as a, normalizeChildren as i, mergeContext as n, LibBlock as o, normalizeArray as r, fragment as t };
package/dist/hmr.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { g as HMR_DEV, h as isWindowDefined, l as createSignal, m as getComponentInstanceId } from "./utils-CAe_kbSH.mjs";
2
- import { n as Show, r as LibContextReader, t as Lifecycle } from "./lifecycle-4vjEuXGy.mjs";
3
- import { t as fragment } from "./fragment-BahmURhz.mjs";
1
+ import { d as HMR_DEV, i as createSignal, l as getComponentInstanceId, u as isWindowDefined } from "./signals-ZsU9bGc3.mjs";
2
+ import { t as fragment } from "./fragment-BSt6shYv.mjs";
3
+ import { n as Show, r as LibContextReader, t as Lifecycle } from "./lifecycle-C9_o5zOU.mjs";
4
4
  function registerComponent(o, s, c) {
5
5
  if (!isWindowDefined()) return o;
6
6
  let l = HMR_DEV.registry.addComponent(s, c, o);
@@ -15,15 +15,15 @@ function registerComponent(o, s, c) {
15
15
  let a = l.component(e);
16
16
  return l.addCachedInstance(r, a, HMR_DEV.currentInstance.states), HMR_DEV.currentInstance = null, a;
17
17
  }
18
- return (e) => LibContextReader({ children(r) {
19
- let o = createSignal({ element: u(e, r) }), d = getComponentInstanceId(r);
18
+ return (t) => LibContextReader({ children(i) {
19
+ let o = createSignal({ element: u(t, i) }), d = getComponentInstanceId(i);
20
20
  return Lifecycle({
21
21
  onMounted() {
22
- let t = HMR_DEV.registry.subscribeToComponent(s, c, () => {
23
- o.element = null, o.element = u(e, r, !0);
22
+ let e = HMR_DEV.registry.subscribeToComponent(s, c, () => {
23
+ o.element = null, o.element = u(t, i, !0);
24
24
  });
25
25
  return l.unmarkInstanceAsRemovable(d), () => {
26
- t(), l.markInstanceAsRemovable(d), setTimeout(() => {
26
+ e(), l.markInstanceAsRemovable(d), setTimeout(() => {
27
27
  l.getCachedInstance(d)?.isRemovable && l.removeCachedInstance(d);
28
28
  });
29
29
  };
@@ -0,0 +1,24 @@
1
+ import { i as normalizeChildren, n as mergeContext, o as LibBlock } from "./fragment-BSt6shYv.mjs";
2
+ var LibHTMLElement = class extends LibBlock {
3
+ constructor(n, r) {
4
+ super(), this.props = n, this.context = r, this.node = {
5
+ type: "html-element",
6
+ context: r,
7
+ props: n
8
+ }, r.isHydrating && this.insertNode(), normalizeChildren(n.children).forEach((e, n) => {
9
+ this.children.push(e(mergeContext(r, {
10
+ parentBlock: this,
11
+ index: n
12
+ })));
13
+ }), r.isHydrating || this.insertNode();
14
+ }
15
+ unmount() {
16
+ this.props.ref && (this.props.ref.element = null), super.unmount();
17
+ }
18
+ };
19
+ function htmlElement(e) {
20
+ return function(t) {
21
+ return new LibHTMLElement(e, t);
22
+ };
23
+ }
24
+ export { htmlElement as t };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { _ as LibBlock, c as createEffect, d as getSignal, f as isSignal, i as normalizeChildren, l as createSignal, n as mergeContext, p as untrack, r as normalizeArray, s as batch, u as deepTrack } from "./utils-CAe_kbSH.mjs";
2
- import { n as Show, r as LibContextReader, t as Lifecycle } from "./lifecycle-4vjEuXGy.mjs";
3
- import { t as fragment } from "./fragment-BahmURhz.mjs";
4
- import { n as PortalOut, t as PortalIn } from "./portal-CbcYOHLv.mjs";
1
+ import { a as deepTrack, c as untrack, i as createSignal, o as getSignal, r as createEffect, s as isSignal, t as batch } from "./signals-ZsU9bGc3.mjs";
2
+ import { i as normalizeChildren, n as mergeContext, o as LibBlock, r as normalizeArray, t as fragment } from "./fragment-BSt6shYv.mjs";
3
+ import { n as Show, r as LibContextReader, t as Lifecycle } from "./lifecycle-C9_o5zOU.mjs";
4
+ import { n as PortalOut, t as PortalIn } from "./portal-BxUviJsE.mjs";
5
5
  function ClientOnly(e) {
6
6
  return LibContextReader({ children: (t) => Show({
7
7
  get when() {
@@ -42,17 +42,17 @@ function ErrorBoundary(e) {
42
42
  }
43
43
  function Lazy(e) {
44
44
  return LibContextReader({ children: (t) => {
45
- let n = createSignal({ block: null });
45
+ let r = createSignal({ block: null });
46
46
  return t.promises.push(e.import().then((t) => {
47
- n.block = e.resolve(t);
47
+ r.block = e.resolve(t);
48
48
  })), fragment({ children: [Show({
49
49
  get when() {
50
- return n.block !== null;
50
+ return r.block !== null;
51
51
  },
52
- children: [n.block]
52
+ children: [r.block]
53
53
  }), Show({
54
54
  get when() {
55
- return n.block === null;
55
+ return r.block === null;
56
56
  },
57
57
  children: [e.fallback]
58
58
  })] });
@@ -63,34 +63,34 @@ function LibScripts() {
63
63
  }
64
64
  var ListClass = class extends LibBlock {
65
65
  signals = [];
66
- constructor(e, i) {
67
- super(), this.props = e, this.context = i;
68
- let c = [];
66
+ constructor(o, s) {
67
+ super(), this.props = o, this.context = s;
68
+ let l = [];
69
69
  this.addEffect(createEffect(() => {
70
- let t = e.items;
71
- isSignal(t) && deepTrack(t, 1), untrack(() => {
72
- this.diff(c, t).forEach((t) => {
73
- if (t.type === "add") {
74
- let r = createSignal({
75
- item: t.item,
76
- index: t.index
70
+ let i = o.items;
71
+ isSignal(i) && deepTrack(i, 1), untrack(() => {
72
+ this.diff(l, i).forEach((e) => {
73
+ if (e.type === "add") {
74
+ let t = createSignal({
75
+ item: e.item,
76
+ index: e.index
77
77
  });
78
- this.children.splice(t.index, 0, null), this.signals.splice(t.index, 0, getSignal(r));
79
- let s = e.render(r)(mergeContext(i, {
78
+ this.children.splice(e.index, 0, null), this.signals.splice(e.index, 0, getSignal(t));
79
+ let i = o.render(t)(mergeContext(s, {
80
80
  parentBlock: this,
81
81
  get index() {
82
- return r.index;
82
+ return t.index;
83
83
  }
84
84
  }));
85
- this.children[t.index] = s;
86
- } else if (t.type === "replace") this.signals[t.index].proxy.item = t.newItem;
87
- else if (t.type === "delete") {
88
- let e = this.children[t.index];
89
- this.children.splice(t.index, 1), this.signals.splice(t.index, 1), e?.unmount();
85
+ this.children[e.index] = i;
86
+ } else if (e.type === "replace") this.signals[e.index].proxy.item = e.newItem;
87
+ else if (e.type === "delete") {
88
+ let t = this.children[e.index];
89
+ this.children.splice(e.index, 1), this.signals.splice(e.index, 1), t?.unmount();
90
90
  }
91
91
  }), this.signals.forEach((e, t) => {
92
92
  e.value.index !== t && (e.proxy.index = t);
93
- }), c = [...t];
93
+ }), l = [...i];
94
94
  });
95
95
  }, !0));
96
96
  }
@@ -177,17 +177,17 @@ function createStore() {
177
177
  return function(e) {
178
178
  let t = createContext();
179
179
  return {
180
- provider(n) {
181
- let r = createSignal(e.state({ props: n })), i = e.actions({
182
- props: n,
183
- state: r
184
- }), o = Object.entries(i).reduce((e, [t, n]) => (e[t] = (...e) => batch(() => n.apply(i, e)), e), {});
180
+ provider(r) {
181
+ let i = createSignal(e.state({ props: r })), a = e.actions({
182
+ props: r,
183
+ state: i
184
+ }), s = Object.entries(a).reduce((e, [t, n]) => (e[t] = (...e) => batch(() => n.apply(a, e)), e), {});
185
185
  return t.provider({
186
186
  value: {
187
- state: r,
188
- actions: o
187
+ state: i,
188
+ actions: s
189
189
  },
190
- children: n.children
190
+ children: r.children
191
191
  });
192
192
  },
193
193
  reader(e) {
@@ -1,6 +1,6 @@
1
- import { o as text } from "./utils-CAe_kbSH.mjs";
2
- import { t as fragment } from "./fragment-BahmURhz.mjs";
3
- import { t as htmlElement } from "./html-element-Cm0RtMkT.mjs";
1
+ import "./signals-ZsU9bGc3.mjs";
2
+ import { a as text, t as fragment } from "./fragment-BSt6shYv.mjs";
3
+ import { t as htmlElement } from "./html-element-DeGD0uGZ.mjs";
4
4
  function detectChild(e) {
5
5
  let t = e.value, n = typeof t;
6
6
  return n === "string" || n === "number" || n === "boolean" ? text({ get text() {
@@ -1,4 +1,5 @@
1
- import { _ as LibBlock, c as createEffect, i as normalizeChildren, n as mergeContext, p as untrack, r as normalizeArray } from "./utils-CAe_kbSH.mjs";
1
+ import { c as untrack, r as createEffect } from "./signals-ZsU9bGc3.mjs";
2
+ import { i as normalizeChildren, n as mergeContext, o as LibBlock, r as normalizeArray } from "./fragment-BSt6shYv.mjs";
2
3
  var LibContextReaderClass = class extends LibBlock {
3
4
  constructor(e, t) {
4
5
  super(), this.props = e, this.context = t, normalizeArray(e.children).forEach((e, n) => {
@@ -15,13 +16,13 @@ function LibContextReader(e) {
15
16
  };
16
17
  }
17
18
  var ShowClass = class extends LibBlock {
18
- constructor(e, r) {
19
- super(), this.props = e, this.context = r;
20
- let i = normalizeChildren(e.children);
19
+ constructor(r, i) {
20
+ super(), this.props = r, this.context = i;
21
+ let a = normalizeChildren(r.children);
21
22
  this.addEffect(createEffect(() => {
22
- e.when ? untrack(() => {
23
- i.forEach((e, t) => {
24
- this.children.push(e(mergeContext(r, {
23
+ r.when ? untrack(() => {
24
+ a.forEach((e, t) => {
25
+ this.children.push(e(mergeContext(i, {
25
26
  parentBlock: this,
26
27
  index: t
27
28
  })));
@@ -0,0 +1,45 @@
1
+ import { c as untrack, r as createEffect } from "./signals-ZsU9bGc3.mjs";
2
+ import { i as normalizeChildren, n as mergeContext, o as LibBlock } from "./fragment-BSt6shYv.mjs";
3
+ var PortalInClass = class extends LibBlock {
4
+ constructor(n, r) {
5
+ super(), this.props = n, this.context = r;
6
+ let i;
7
+ r.portals[n.name] ? console.warn(`Портал ${n.name} уже существует`) : this.addEffect(createEffect(() => {
8
+ let t = n.name;
9
+ t !== i && untrack(() => {
10
+ delete r.portals[t], r.portals[t] = n.children;
11
+ }), i = t;
12
+ }));
13
+ }
14
+ unmount() {
15
+ super.unmount(), delete this.context.portals[this.props.name];
16
+ }
17
+ };
18
+ function PortalIn(e) {
19
+ return function(t) {
20
+ return new PortalInClass(e, t);
21
+ };
22
+ }
23
+ var PortalOutClass = class extends LibBlock {
24
+ constructor(i, a) {
25
+ super(), this.props = i, this.context = a;
26
+ let o;
27
+ this.addEffect(createEffect(() => {
28
+ let t = i.name, s = normalizeChildren(a.portals[t]);
29
+ s ? s !== o && (this.unmountChildren(), untrack(() => {
30
+ s.forEach((e, t) => {
31
+ this.children.push(e(mergeContext(a, {
32
+ parentBlock: this,
33
+ index: t
34
+ })));
35
+ });
36
+ }), o = s) : (this.unmountChildren(), o = null);
37
+ }));
38
+ }
39
+ };
40
+ function PortalOut(e) {
41
+ return function(t) {
42
+ return new PortalOutClass(e, t);
43
+ };
44
+ }
45
+ export { PortalOut as n, PortalIn as t };
@@ -181,7 +181,7 @@ type StyleWithNumericSupport = {
181
181
  maxHeight?: CSSLength;
182
182
  minHeight?: CSSLength;
183
183
  };
184
- type LibHTMLElementStyle = Partial<Omit<CSSStyleDeclaration, 'getPropertyCSSValue' | 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | 'cssFloat' | 'cssText' | 'length' | 'parentRule' | keyof StyleWithNumericSupport> & StyleWithNumericSupport>;
184
+ type LibHTMLElementStyle = Partial<Omit<CSSStyleDeclaration, "getPropertyCSSValue" | "getPropertyPriority" | "getPropertyValue" | "item" | "removeProperty" | "setProperty" | "cssFloat" | "cssText" | "length" | "parentRule" | keyof StyleWithNumericSupport> & StyleWithNumericSupport>;
185
185
  export type LibHTMLElementProps = WithChildren<{
186
186
  accessKey?: string;
187
187
  autocapitalize?: string;
@@ -268,7 +268,7 @@ export type LibHTMLAudioElementProps = {
268
268
  loop?: boolean;
269
269
  muted?: boolean;
270
270
  playbackRate?: number;
271
- preload?: HTMLAudioElement['preload'];
271
+ preload?: HTMLAudioElement["preload"];
272
272
  preservesPitch?: boolean;
273
273
  src?: string;
274
274
  srcObject?: MediaProvider | null;
@@ -307,7 +307,7 @@ export type LibHTMLButtonElementProps = {
307
307
  formNoValidate?: boolean;
308
308
  formTarget?: string;
309
309
  name?: string;
310
- type?: HTMLButtonElement['type'];
310
+ type?: HTMLButtonElement["type"];
311
311
  value?: string;
312
312
  } & LibHTMLElementProps & LibHTMLElementEventMap & LibHTMLelementAriaProps;
313
313
  export type LibHTMLCanvasElementProps = {
@@ -457,10 +457,10 @@ export type LibHTMLImageElementProps = {
457
457
  ref?: LibHTMLElementReference<HTMLImageElement>;
458
458
  alt?: string;
459
459
  crossOrigin?: string | null;
460
- decoding?: HTMLImageElement['decoding'];
460
+ decoding?: HTMLImageElement["decoding"];
461
461
  height?: number;
462
462
  isMap?: boolean;
463
- loading?: HTMLImageElement['loading'];
463
+ loading?: HTMLImageElement["loading"];
464
464
  referrerPolicy?: string;
465
465
  sizes?: string;
466
466
  src?: string;
@@ -497,7 +497,7 @@ export type LibHTMLInputElementProps = {
497
497
  placeholder?: string;
498
498
  readOnly?: boolean;
499
499
  required?: boolean;
500
- selectionDirection?: HTMLInputElement['selectionDirection'];
500
+ selectionDirection?: HTMLInputElement["selectionDirection"];
501
501
  selectionEnd?: number | null;
502
502
  selectionStart?: number | null;
503
503
  size?: number;
@@ -716,9 +716,9 @@ export type LibHTMLSupElementProps = {
716
716
  } & LibHTMLElementProps;
717
717
  export type LibHTMLTableElementProps = {
718
718
  ref?: LibHTMLElementReference<HTMLTableElement>;
719
- caption?: HTMLTableElement['caption'];
720
- tFoot?: HTMLTableElement['tFoot'];
721
- tHead?: HTMLTableElement['tHead'];
719
+ caption?: HTMLTableElement["caption"];
720
+ tFoot?: HTMLTableElement["tFoot"];
721
+ tHead?: HTMLTableElement["tHead"];
722
722
  } & LibHTMLElementProps & LibHTMLElementEventMap & LibHTMLelementAriaProps;
723
723
  export type LibHTMLTbodyElementProps = {
724
724
  ref?: LibHTMLElementReference<HTMLTableSectionElement>;
@@ -736,7 +736,7 @@ export type LibHTMLTemplateElementProps = {
736
736
  } & LibHTMLElementProps;
737
737
  export type LibHTMLTextAreaElementProps = {
738
738
  ref?: LibHTMLElementReference<HTMLTextAreaElement>;
739
- autocomplete?: HTMLTextAreaElement['autocomplete'];
739
+ autocomplete?: HTMLTextAreaElement["autocomplete"];
740
740
  cols?: number;
741
741
  defaultValue?: string;
742
742
  dirName?: string;
@@ -748,7 +748,7 @@ export type LibHTMLTextAreaElementProps = {
748
748
  readOnly?: boolean;
749
749
  required?: boolean;
750
750
  rows?: number;
751
- selectionDirection?: HTMLTextAreaElement['selectionDirection'];
751
+ selectionDirection?: HTMLTextAreaElement["selectionDirection"];
752
752
  selectionEnd?: number;
753
753
  selectionStart?: number;
754
754
  value?: string;
@@ -808,10 +808,10 @@ export type LibHTMLVideoElementProps = {
808
808
  loop?: boolean;
809
809
  muted?: boolean;
810
810
  playbackRate?: number;
811
- preload?: HTMLVideoElement['preload'];
811
+ preload?: HTMLVideoElement["preload"];
812
812
  preservesPitch?: boolean;
813
813
  src?: string;
814
- srcObject?: HTMLMediaElement['srcObject'];
814
+ srcObject?: HTMLMediaElement["srcObject"];
815
815
  volume?: number;
816
816
  disablePictureInPicture?: boolean;
817
817
  height?: number;
package/dist/server.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { l as createSignal } from "./utils-CAe_kbSH.mjs";
2
- import { t as fragment } from "./fragment-BahmURhz.mjs";
3
- import { t as PortalIn } from "./portal-CbcYOHLv.mjs";
1
+ import { i as createSignal } from "./signals-ZsU9bGc3.mjs";
2
+ import { t as fragment } from "./fragment-BSt6shYv.mjs";
3
+ import { t as PortalIn } from "./portal-BxUviJsE.mjs";
4
4
  import { t as CLIENT_ENTRY_FILE_NAME } from "./constants-BOAOReQ3.mjs";
5
- import { t as htmlElement } from "./html-element-Cm0RtMkT.mjs";
5
+ import { t as htmlElement } from "./html-element-DeGD0uGZ.mjs";
6
6
  import path from "path";
7
7
  import { Readable, Writable } from "node:stream";
8
8
  import util from "node:util";
@@ -64,16 +64,12 @@ var ServerNode = class {
64
64
  }
65
65
  };
66
66
  async function renderToString(t) {
67
- let n = createSignal({
68
- portals: {},
69
- listeners: {}
70
- }), r = /* @__PURE__ */ new Map(), i, a = [];
67
+ let n = createSignal({ portals: {} }), r = /* @__PURE__ */ new Map(), i, a = [];
71
68
  if (t({
72
69
  parentBlock: null,
73
70
  index: 0,
74
71
  portals: n.portals,
75
72
  contexts: {},
76
- listeners: n.listeners,
77
73
  isServer: !0,
78
74
  promises: a,
79
75
  isHydrating: !1,
@@ -86,8 +82,6 @@ async function renderToString(t) {
86
82
  r.get(e)?.addChild(a, t);
87
83
  }
88
84
  },
89
- updateTextNode() {},
90
- updateHtmlElementNodeProp() {},
91
85
  removeNode(e) {
92
86
  r.get(e)?.remove();
93
87
  }
@@ -7,45 +7,7 @@ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDes
7
7
  }, __toESM = (n, r, a) => (a = n == null ? {} : __create(__getProtoOf(n)), __copyProps(r || !n || !n.__esModule ? __defProp(a, "default", {
8
8
  value: n,
9
9
  enumerable: !0
10
- }) : a, n)), LibBlock = class {
11
- node = null;
12
- effects = [];
13
- children = [];
14
- get nearestParentElement() {
15
- return this.node ?? this.context.parentBlock?.nearestParentElement ?? null;
16
- }
17
- get previousBlock() {
18
- let e = this.context.parentBlock;
19
- return e ? e.children[this.context.index - 1] || (e.node ? null : e.previousBlock) : null;
20
- }
21
- get nearestPreviousNode() {
22
- if (this.node) return this.node;
23
- let e = this.children[this.children.length - 1];
24
- if (e) return e.nearestPreviousNode;
25
- let t = this.previousBlock;
26
- return t ? t.nearestPreviousNode : null;
27
- }
28
- get previousNode() {
29
- let e = this.previousBlock;
30
- return e ? e.nearestPreviousNode : null;
31
- }
32
- addEffect(e) {
33
- this.effects.push(e);
34
- }
35
- unmountChildren() {
36
- this.children.forEach((e) => {
37
- e?.unmount();
38
- }), this.children = [];
39
- }
40
- insertNode() {
41
- this.node && this.context.insertNode(this.context.parentBlock?.nearestParentElement ?? null, this.node, this.previousNode);
42
- }
43
- unmount() {
44
- this.node && this.context.removeNode(this.node), this.unmountChildren(), this.effects.forEach((e) => {
45
- e.dispose();
46
- }), this.effects = [];
47
- }
48
- }, RegisteredComponent = class {
10
+ }) : a, n)), RegisteredComponent = class {
49
11
  component;
50
12
  subscribers;
51
13
  cachedInstances;
@@ -286,60 +248,15 @@ function _deepTrack(e, t, n = 0) {
286
248
  function deepTrack(e, t) {
287
249
  _deepTrack(e, t);
288
250
  }
289
- var LibText = class extends LibBlock {
290
- constructor(e, t) {
291
- super(), this.props = e, this.context = t;
292
- let n = {
293
- type: "text",
294
- props: e,
295
- context: t
296
- };
297
- this.node = n, this.addEffect(createEffect(() => {
298
- t.updateTextNode(n);
299
- }, !0)), this.insertNode();
300
- }
301
- };
302
- function text(e) {
303
- return function(t) {
304
- return new LibText(e, t);
305
- };
306
- }
307
- function mergeContext(e, t) {
308
- return {
309
- parentBlock: t.parentBlock,
310
- get index() {
311
- return t.index;
312
- },
313
- portals: e.portals,
314
- contexts: {
315
- ...e.contexts,
316
- ...t.contexts
317
- },
318
- listeners: e.listeners,
319
- isServer: e.isServer,
320
- promises: e.promises,
321
- get isHydrating() {
322
- return e.isHydrating;
323
- },
324
- insertNode: e.insertNode,
325
- updateTextNode: e.updateTextNode,
326
- updateHtmlElementNodeProp: e.updateHtmlElementNodeProp,
327
- removeNode: e.removeNode
251
+ function createDisposer(e) {
252
+ let t = {
253
+ effects: /* @__PURE__ */ new Set(),
254
+ dispose() {
255
+ t.effects.forEach((e) => {
256
+ e.dispose();
257
+ });
258
+ }
328
259
  };
260
+ return currentDisposer = t, e(), currentDisposer = null, t;
329
261
  }
330
- function objectKeys(e) {
331
- return Object.keys(e);
332
- }
333
- function extractListenersFromProps(e) {
334
- return Object.entries(e).reduce((e, [t, n]) => (t.startsWith("on") && (e[t] = n), e), {});
335
- }
336
- function normalizeArray(e) {
337
- return Array.isArray(e) ? e : [e];
338
- }
339
- function normalizeChild(e) {
340
- return typeof e == "string" || typeof e == "number" ? [text({ text: String(e) })] : Array.isArray(e) ? e.flatMap(normalizeChildren) : [e];
341
- }
342
- function normalizeChildren(e) {
343
- return e ? normalizeArray(e).filter((e) => e != null).flatMap(normalizeChild) : [];
344
- }
345
- export { LibBlock as _, objectKeys as a, createEffect as c, getSignal as d, isSignal as f, HMR_DEV as g, isWindowDefined as h, normalizeChildren as i, createSignal as l, getComponentInstanceId as m, mergeContext as n, text as o, untrack as p, normalizeArray as r, batch as s, extractListenersFromProps as t, deepTrack as u };
262
+ export { deepTrack as a, untrack as c, HMR_DEV as d, createSignal as i, getComponentInstanceId as l, createDisposer as n, getSignal as o, createEffect as r, isSignal as s, batch as t, isWindowDefined as u };
package/dist/types.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { LibBlock } from './block';
2
2
  import { LibHTMLElementProps } from './html-element';
3
- import { LibHTMLElementEventMap, LibHTMLElementTagNameMap } from './prop-types';
3
+ import { LibHTMLElementTagNameMap } from './prop-types';
4
4
  import { LibTextProps } from './text';
5
5
  export type LibProps = Record<string, any>;
6
6
  export type LibTextNode = {
7
- type: 'text';
7
+ type: "text";
8
8
  context: LibContext;
9
9
  props: LibTextProps;
10
10
  };
11
11
  export type LibHtmlElementNode<Tag extends keyof LibHTMLElementTagNameMap = keyof LibHTMLElementTagNameMap> = {
12
- type: 'html-element';
12
+ type: "html-element";
13
13
  context: LibContext;
14
14
  props: LibHTMLElementProps<Tag>;
15
15
  };
@@ -18,12 +18,9 @@ export type LibContext = {
18
18
  parentBlock: LibBlock | null;
19
19
  index: number;
20
20
  insertNode(parent: LibHtmlElementNode | null, node: LibNode, after: LibNode | null): void;
21
- updateTextNode(node: LibTextNode): void;
22
- updateHtmlElementNodeProp(node: LibHtmlElementNode, key: string, value: unknown): void;
23
21
  removeNode(node: LibNode): void;
24
- portals: Record<string, WithChildren<{}>['children']>;
22
+ portals: Record<string, WithChildren<{}>["children"]>;
25
23
  contexts: Record<symbol, Record<string, unknown>>;
26
- listeners: Record<keyof LibHTMLElementEventMap, Map<HTMLElement, LibHTMLElementEventMap[keyof LibHTMLElementEventMap]>>;
27
24
  isServer: boolean;
28
25
  promises: Promise<unknown>[];
29
26
  isHydrating: boolean;
package/dist/utils.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { LibHTMLElementEventMap, LibHTMLElementTagNameMap } from './prop-types';
2
1
  import { Child, Children, LibContext, MaybeArray, PotokElement } from './types';
3
- export declare function mergeContext(rootContext: LibContext, childContext: Pick<LibContext, 'parentBlock' | 'index'> & Partial<Pick<LibContext, 'contexts'>>): LibContext;
2
+ export declare function mergeContext(rootContext: LibContext, childContext: Pick<LibContext, "parentBlock" | "index"> & Partial<Pick<LibContext, "contexts">>): LibContext;
4
3
  export declare function objectKeys<Obj extends Record<string, unknown>>(obj: Obj): (keyof Obj)[];
5
- export declare function extractListenersFromProps(props: LibHTMLElementTagNameMap[keyof LibHTMLElementTagNameMap]): LibHTMLElementEventMap;
6
4
  export declare function map<T extends string | number | symbol, K>(field: T, mapObject: Record<T, K>): K;
7
5
  export declare function map<T extends string | number | symbol, K>(field: T | undefined | null, mapObject: Partial<Record<T, K>>, defaultValue: K): K;
8
- export declare function map<T extends boolean, K>(field: T, mapObject: Record<'true' | 'false', K>): K;
6
+ export declare function map<T extends boolean, K>(field: T, mapObject: Record<"true" | "false", K>): K;
9
7
  export declare function normalizeArray<T>(array: MaybeArray<T>): T[];
10
8
  export declare function normalizeChild(child: NonNullable<Child>): PotokElement[];
11
9
  export declare function normalizeChildren(children: Children): PotokElement[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@potok-web-framework/core",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.mjs",
@@ -36,8 +36,7 @@
36
36
  "fetch-to-node": "^2.1.0",
37
37
  "klona": "^2.0.6",
38
38
  "vite": "8.0.0-beta.10",
39
- "vite-plugin-dts": "^4.5.4",
40
- "@potok-web-framework/vite-plugin": "0.4.0"
39
+ "vite-plugin-dts": "^4.5.4"
41
40
  },
42
41
  "peerDependencies": {
43
42
  "typescript": "^5"
@@ -1,17 +0,0 @@
1
- import { _ as LibBlock, i as normalizeChildren, n as mergeContext } from "./utils-CAe_kbSH.mjs";
2
- var FragmentClass = class extends LibBlock {
3
- constructor(e, n) {
4
- super(), this.props = e, this.context = n, normalizeChildren(e.children).forEach((e, t) => {
5
- this.children.push(e(mergeContext(n, {
6
- parentBlock: this,
7
- index: t
8
- })));
9
- });
10
- }
11
- };
12
- function fragment(e) {
13
- return function(t) {
14
- return new FragmentClass(e, t);
15
- };
16
- }
17
- export { fragment as t };
@@ -1,42 +0,0 @@
1
- import { _ as LibBlock, a as objectKeys, c as createEffect, i as normalizeChildren, n as mergeContext, t as extractListenersFromProps } from "./utils-CAe_kbSH.mjs";
2
- var LibHTMLElement = class extends LibBlock {
3
- constructor(e, t) {
4
- super(), this.props = e, this.context = t;
5
- let a = {
6
- type: "html-element",
7
- context: t,
8
- props: e
9
- };
10
- this.node = a;
11
- let o = Object.getOwnPropertyDescriptors(e);
12
- for (let [e, r] of Object.entries(o)) {
13
- if ([
14
- "tag",
15
- "children",
16
- "ref"
17
- ].includes(e)) continue;
18
- r.value && t.updateHtmlElementNodeProp(a, e, r.value);
19
- let i = r.get;
20
- i && this.addEffect(createEffect(() => {
21
- t.updateHtmlElementNodeProp(a, e, i());
22
- }, !0));
23
- }
24
- t.isHydrating && this.insertNode(), normalizeChildren(e.children).forEach((e, n) => {
25
- this.children.push(e(mergeContext(t, {
26
- parentBlock: this,
27
- index: n
28
- })));
29
- }), t.isHydrating || this.insertNode();
30
- }
31
- unmount() {
32
- this.node && objectKeys(extractListenersFromProps(this.props)).forEach((e) => {
33
- this.context.listeners[e]?.delete(this.node);
34
- }), this.props.ref && (this.props.ref.element = null), super.unmount();
35
- }
36
- };
37
- function htmlElement(e) {
38
- return function(t) {
39
- return new LibHTMLElement(e, t);
40
- };
41
- }
42
- export { htmlElement as t };
@@ -1,44 +0,0 @@
1
- import { _ as LibBlock, c as createEffect, i as normalizeChildren, n as mergeContext, p as untrack } from "./utils-CAe_kbSH.mjs";
2
- var PortalInClass = class extends LibBlock {
3
- constructor(e, n) {
4
- super(), this.props = e, this.context = n;
5
- let r;
6
- n.portals[e.name] ? console.warn(`Портал ${e.name} уже существует`) : this.addEffect(createEffect(() => {
7
- let t = e.name;
8
- t !== r && untrack(() => {
9
- delete n.portals[t], n.portals[t] = e.children;
10
- }), r = t;
11
- }));
12
- }
13
- unmount() {
14
- super.unmount(), delete this.context.portals[this.props.name];
15
- }
16
- };
17
- function PortalIn(e) {
18
- return function(t) {
19
- return new PortalInClass(e, t);
20
- };
21
- }
22
- var PortalOutClass = class extends LibBlock {
23
- constructor(e, i) {
24
- super(), this.props = e, this.context = i;
25
- let a;
26
- this.addEffect(createEffect(() => {
27
- let t = e.name, o = normalizeChildren(i.portals[t]);
28
- o ? o !== a && (this.unmountChildren(), untrack(() => {
29
- o.forEach((e, t) => {
30
- this.children.push(e(mergeContext(i, {
31
- parentBlock: this,
32
- index: t
33
- })));
34
- });
35
- }), a = o) : (this.unmountChildren(), a = null);
36
- }));
37
- }
38
- };
39
- function PortalOut(e) {
40
- return function(t) {
41
- return new PortalOutClass(e, t);
42
- };
43
- }
44
- export { PortalOut as n, PortalIn as t };
@@ -1,8 +0,0 @@
1
- import { PotokElement } from './types';
2
- type RenderToDOMOptions = {
3
- app: () => PotokElement;
4
- needToHydrate?: boolean;
5
- root?: Element;
6
- };
7
- export declare function renderToDOM(options: RenderToDOMOptions): void;
8
- export {};