@potok-web-framework/core 0.7.0 → 0.9.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.
Files changed (71) hide show
  1. package/dist/block.d.ts +11 -6
  2. package/dist/client/potok-preload.d.ts +6 -0
  3. package/dist/{dom/utils.d.ts → client/utils/dom.d.ts} +1 -1
  4. package/dist/client.mjs +93 -71
  5. package/dist/constants-Bxn0R4hW.mjs +34 -0
  6. package/dist/constants.d.ts +4 -2
  7. package/dist/css-BercB0Kp.mjs +8 -0
  8. package/dist/escape-from-script-tag-CRT2evI1.mjs +4 -0
  9. package/dist/exports/client.d.ts +1 -1
  10. package/dist/exports/hmr.d.ts +2 -0
  11. package/dist/exports/index.d.ts +2 -2
  12. package/dist/exports/jsx-runtime.d.ts +2 -1
  13. package/dist/exports/server.d.ts +2 -1
  14. package/dist/exports/store.d.ts +2 -0
  15. package/dist/footer-scripts.d.ts +2 -0
  16. package/dist/fragment-CXNEPBWB.mjs +18 -0
  17. package/dist/get-component-instance-id-CP6LDtpX.mjs +97 -0
  18. package/dist/header-scripts.d.ts +2 -0
  19. package/dist/hmr/constants.d.ts +12 -0
  20. package/dist/hmr/register-component.d.ts +4 -0
  21. package/dist/hmr/register-style.d.ts +1 -0
  22. package/dist/hmr/registered-component.d.ts +1 -6
  23. package/dist/hmr/remove-style.d.ts +1 -0
  24. package/dist/hmr/utils.d.ts +0 -2
  25. package/dist/hmr.mjs +13 -41
  26. package/dist/html-element-DBut4UCf.mjs +31 -0
  27. package/dist/html-element.d.ts +9 -1
  28. package/dist/index.mjs +202 -129
  29. package/dist/is-pure-object-s_MkQp1w.mjs +4 -0
  30. package/dist/jsx-runtime.mjs +4 -4
  31. package/dist/lib-node-DyXPvvVQ.mjs +192 -0
  32. package/dist/lib-node.d.ts +6 -0
  33. package/dist/list.d.ts +3 -0
  34. package/dist/normalize-children-BWrn16R7.mjs +48 -0
  35. package/dist/prop-types.d.ts +219 -240
  36. package/dist/register-component-B92kGFqC.mjs +67 -0
  37. package/dist/serialization-qOayQbjE.mjs +108 -0
  38. package/dist/{bootstrap-app.d.ts → server/bootstrap-app.d.ts} +3 -4
  39. package/dist/{render-to-string.d.ts → server/render-to-string.d.ts} +1 -1
  40. package/dist/server-node.d.ts +1 -1
  41. package/dist/server.mjs +83 -1145
  42. package/dist/signals.d.ts +5 -0
  43. package/dist/store/create-store.d.ts +2 -0
  44. package/dist/store/http-extension.d.ts +26 -0
  45. package/dist/store/types.d.ts +40 -0
  46. package/dist/store.mjs +137 -0
  47. package/dist/text-node.d.ts +12 -0
  48. package/dist/types.d.ts +11 -14
  49. package/dist/utils/css.d.ts +2 -0
  50. package/dist/utils/deep-assign-object.d.ts +1 -0
  51. package/dist/utils/escape-from-script-tag.d.ts +1 -0
  52. package/dist/utils/escape-html.d.ts +1 -0
  53. package/dist/utils/get-component-instance-id.d.ts +2 -0
  54. package/dist/utils/is-pure-object.d.ts +1 -0
  55. package/dist/utils/merge-context.d.ts +2 -0
  56. package/dist/utils/normalize-array.d.ts +2 -0
  57. package/dist/utils/normalize-children.d.ts +2 -0
  58. package/dist/utils/serialization.d.ts +2 -0
  59. package/package.json +6 -5
  60. package/dist/constants-BOAOReQ3.mjs +0 -26
  61. package/dist/fragment-BSt6shYv.mjs +0 -103
  62. package/dist/hmr/hmr-dev.d.ts +0 -9
  63. package/dist/html-element-DeGD0uGZ.mjs +0 -24
  64. package/dist/lib-scripts.d.ts +0 -2
  65. package/dist/lifecycle-C9_o5zOU.mjs +0 -58
  66. package/dist/portal-BxUviJsE.mjs +0 -45
  67. package/dist/signals-ZsU9bGc3.mjs +0 -262
  68. package/dist/store.d.ts +0 -26
  69. package/dist/text.d.ts +0 -5
  70. package/dist/utils.d.ts +0 -9
  71. /package/dist/{dom → client}/hydrate.d.ts +0 -0
package/dist/block.d.ts CHANGED
@@ -1,17 +1,22 @@
1
+ import { LibHTMLElementNode } from './html-element';
2
+ import { LibNode } from './lib-node';
1
3
  import { Effect } from './signals';
2
- import { LibContext, LibHtmlElementNode, LibNode, LibProps } from './types';
4
+ import { LibTextNode } from './text-node';
5
+ import { LibContext, LibProps } from './types';
3
6
  export declare abstract class LibBlock {
4
- node: LibNode | null;
5
7
  abstract context: LibContext;
6
8
  abstract props: LibProps;
7
9
  effects: Set<Effect>;
8
10
  children: (LibBlock | null)[];
9
- get nearestParentElement(): LibHtmlElementNode | null;
10
- get previousBlock(): LibBlock | null;
11
- get nearestPreviousNode(): LibNode | null;
11
+ get parentBlock(): LibBlock | null;
12
+ get parentElementNode(): LibHTMLElementNode | null;
13
+ private get previousBlock();
14
+ private get nearestPreviousNode();
12
15
  get previousNode(): LibNode | null;
16
+ isNode(): this is LibNode;
17
+ isHTMLElementNode(): this is LibHTMLElementNode;
18
+ isTextNode(): this is LibTextNode;
13
19
  addEffect(effect: Effect): void;
14
20
  unmountChildren(): void;
15
- insertNode(): void;
16
21
  unmount(): void;
17
22
  }
@@ -0,0 +1,6 @@
1
+ export type PotokPreloader = {
2
+ (): Promise<any>;
3
+ dependencies: string[];
4
+ };
5
+ export declare function potokPreload(loader: () => Promise<any>, dependencies: string[]): PotokPreloader;
6
+ export declare function isPotokPreloader(obj: any): obj is PotokPreloader;
@@ -1,4 +1,4 @@
1
- import { LibNode } from '../types';
1
+ import { LibNode } from '../../lib-node';
2
2
  export declare function isTextNode(node: Node): node is Text;
3
3
  export declare function isHTMLElementNode(node: Node): node is HTMLElement;
4
4
  export declare function isLibNodeEqualToDomNode(libNode: LibNode, domNode: Node): boolean;
package/dist/client.mjs CHANGED
@@ -1,5 +1,7 @@
1
- import { i as createSignal, r as createEffect } from "./signals-ZsU9bGc3.mjs";
2
- import { n as HTML_ELEMENT_STYLE_PX_PROPERTIES } from "./constants-BOAOReQ3.mjs";
1
+ import { i as createSignal, n as batch, r as createEffect } from "./lib-node-DyXPvvVQ.mjs";
2
+ import { i as PRELOAD_SCRIPTS_SCRIPT_ID, n as HYDRATION_STATE_SCRIPT_ID, r as NON_BUBBLING_EVENTS } from "./constants-Bxn0R4hW.mjs";
3
+ import { t as deserializeWithTypes } from "./serialization-qOayQbjE.mjs";
4
+ import { n as normalizeCssPropertyValue, t as normalizeCssPropertyName } from "./css-BercB0Kp.mjs";
3
5
  function isTextNode(e) {
4
6
  return e.nodeType === Node.TEXT_NODE;
5
7
  }
@@ -7,97 +9,117 @@ function isHTMLElementNode(e) {
7
9
  return e.nodeType === Node.ELEMENT_NODE;
8
10
  }
9
11
  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;
12
+ return e.isTextNode() && isTextNode(t) ? String(e.props.text) === t.textContent : e.isHTMLElementNode() && isHTMLElementNode(t) ? e.props.tag === t.tagName.toLowerCase() : !1;
11
13
  }
12
- function hydrate(r) {
13
- let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), l = createSignal({
14
+ function hydrate(s) {
15
+ let c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set(), d = document.getElementById(PRELOAD_SCRIPTS_SCRIPT_ID), f = createSignal({
14
16
  portals: {},
15
- isHydrating: !0
16
- });
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);
17
+ preload: {
18
+ scripts: d?.textContent ? deserializeWithTypes(d.textContent) : [],
19
+ addScripts(n) {
20
+ batch(() => {
21
+ for (let t of n) f.preload.scripts.some((e) => e.path === t) || (f.preload.scripts = [...f.preload.scripts, createSignal({
22
+ path: t,
23
+ isLoaded: !1
24
+ })]);
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
+ },
28
+ isHydrating: !0
29
+ }), p = document.getElementById(HYDRATION_STATE_SCRIPT_ID), m = p?.textContent ? deserializeWithTypes(p.textContent) : {};
30
+ function h(e, t) {
31
+ let r = Object.getOwnPropertyDescriptors(e.props);
32
+ for (let [e, i] of Object.entries(r)) {
33
+ if ([
34
+ "tag",
35
+ "children",
36
+ "ref"
37
+ ].includes(e)) continue;
38
+ i.value && t(e, i.value);
39
+ let r = i.get;
40
+ r && createEffect(() => {
41
+ t(e, r());
42
+ }, !0);
43
+ }
50
44
  }
51
- let d = {
45
+ let g = {
52
46
  parentBlock: null,
53
47
  index: 0,
54
- portals: l.portals,
48
+ portals: f.portals,
49
+ preload: f.preload,
50
+ states: m,
55
51
  contexts: {},
56
52
  isServer: !1,
57
53
  promises: [],
58
54
  get isHydrating() {
59
- return l.isHydrating;
55
+ return f.isHydrating;
60
56
  },
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));
57
+ insertNode(e) {
58
+ let t, n = e.parentElementNode;
59
+ if (n) {
60
+ if (!c.has(n)) {
61
+ if (f.isHydrating) throw Error("Ошибка гидрации: родительский узел должен быть уже отрендерен");
62
+ c.set(n, document.createElement(n.props.tag));
67
63
  }
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;
64
+ t = c.get(n);
65
+ } else t = document;
66
+ let r = null, i = e.previousNode;
67
+ i && (r = c.get(i) ?? null);
68
+ let o = c.get(e);
69
+ if (o && o.parentElement === t && o === (r ? r.nextSibling : t.firstChild)) return;
70
+ if (f.isHydrating) {
71
+ let n = r ? r.nextSibling : t.firstChild;
73
72
  for (;;) {
74
- if (!e) throw Error("Ошибка гидрации");
75
- if (isLibNodeEqualToDomNode(n, e)) {
76
- o.set(n, e);
73
+ if (!n) throw Error("Ошибка гидрации: не найден соответствующий DOM-узел для ноды библиотеки");
74
+ if (isLibNodeEqualToDomNode(e, n)) {
75
+ c.set(e, n);
77
76
  break;
78
77
  } else {
79
- let t = e;
80
- e = e.nextSibling, t.parentElement?.removeChild(t);
78
+ let e = n;
79
+ n = n.nextSibling, e.parentElement?.removeChild(e);
81
80
  }
82
81
  }
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);
82
+ } else c.has(e) || (e.isTextNode() ? c.set(e, document.createTextNode(String(e.props.text))) : e.isHTMLElementNode() && c.set(e, document.createElement(e.props.tag)));
83
+ let s = c.get(e);
84
+ h(e, (t, n) => {
85
+ if (e.isTextNode()) s.textContent = String(n);
86
+ else if (e.isHTMLElementNode() && isHTMLElementNode(s)) if (t.startsWith("on")) if (n) {
87
+ if (l.has(t) || l.set(t, /* @__PURE__ */ new Map()), l.get(t).set(s, n), !u.has(t)) {
88
+ let e = t.replace(/^on/, "").toLowerCase();
89
+ (NON_BUBBLING_EVENTS.includes(e) ? s : document).addEventListener(e, (e) => {
90
+ let n = !1, r = e.target, i = e.stopPropagation.bind(e), a = e.stopImmediatePropagation.bind(e);
91
+ for (e.stopPropagation = () => {
92
+ n = !0, i();
93
+ }, e.stopImmediatePropagation = () => {
94
+ n = !0, a();
95
+ }; r;) {
96
+ let i = l.get(t)?.get(r);
97
+ if (i && (Object.defineProperty(e, "currentTarget", {
98
+ configurable: !0,
99
+ enumerable: !0,
100
+ get: () => r
101
+ }), i(e), n)) break;
102
+ r = r.parentElement;
103
+ }
104
+ }), u.add(t);
105
+ }
106
+ } else l.get(t)?.delete(s);
107
+ else if (t.startsWith("aria")) {
108
+ let e = t.toLowerCase().replace("aria", "aria-");
109
+ n == null ? s.removeAttribute(e) : s.setAttribute(e, String(n));
110
+ } else t === "className" ? n == null ? s.removeAttribute("class") : s.className = String(n) : t === "style" ? n ? (s.style.cssText = "", Object.keys(n).forEach((e) => {
111
+ let t = n[e], r = normalizeCssPropertyName(e);
112
+ t != null && t !== "" ? s.style.setProperty(r, normalizeCssPropertyValue(e, t)) : s.style.removeProperty(r);
113
+ })) : s.removeAttribute("style") : t in s ? s[t] = n : n == null ? s.removeAttribute(t) : s.setAttribute(t, String(n));
114
+ }), f.isHydrating || t.insertBefore(s, r ? r.nextSibling : t.firstChild), e.isHTMLElementNode() && e.props.ref && (e.props.ref.element = s);
93
115
  },
94
116
  removeNode(e) {
95
- let t = o.get(e);
96
- t && (o.delete(e), isHTMLElementNode(t) ? (t.remove(), s.forEach((e) => {
117
+ let t = c.get(e);
118
+ t && (c.delete(e), isHTMLElementNode(t) ? (t.remove(), l.forEach((e) => {
97
119
  e.delete(t);
98
120
  })) : t.parentElement?.removeChild(t));
99
121
  }
100
122
  };
101
- r.app()(d), l.isHydrating = !1;
123
+ s.app()(g), f.isHydrating = !1, g.states = {};
102
124
  }
103
125
  export { hydrate };
@@ -0,0 +1,34 @@
1
+ const HTML_ELEMENT_STYLE_PX_PROPERTIES = [
2
+ "width",
3
+ "height",
4
+ "top",
5
+ "left",
6
+ "right",
7
+ "bottom",
8
+ "margin",
9
+ "marginTop",
10
+ "marginBottom",
11
+ "marginLeft",
12
+ "marginRight",
13
+ "padding",
14
+ "paddingTop",
15
+ "paddingBottom",
16
+ "paddingLeft",
17
+ "paddingRight",
18
+ "fontSize",
19
+ "borderWidth",
20
+ "borderRadius",
21
+ "maxWidth",
22
+ "minWidth",
23
+ "maxHeight",
24
+ "minHeight"
25
+ ], NON_BUBBLING_EVENTS = [
26
+ "blur",
27
+ "focus",
28
+ "mouseenter",
29
+ "mouseleave",
30
+ "scroll",
31
+ "load",
32
+ "unload"
33
+ ], HYDRATION_STATE_SCRIPT_ID = "potok-initial-states", PRELOAD_SCRIPTS_SCRIPT_ID = "potok-preload-scripts";
34
+ export { PRELOAD_SCRIPTS_SCRIPT_ID as i, HYDRATION_STATE_SCRIPT_ID as n, NON_BUBBLING_EVENTS as r, HTML_ELEMENT_STYLE_PX_PROPERTIES as t };
@@ -1,2 +1,4 @@
1
- export declare const HTML_ELEMENT_STYLE_PX_PROPERTIES: Set<string>;
2
- export declare const CLIENT_ENTRY_FILE_NAME = "client";
1
+ export declare const HTML_ELEMENT_STYLE_PX_PROPERTIES: readonly ["width", "height", "top", "left", "right", "bottom", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "fontSize", "borderWidth", "borderRadius", "maxWidth", "minWidth", "maxHeight", "minHeight"];
2
+ export declare const NON_BUBBLING_EVENTS: string[];
3
+ export declare const HYDRATION_STATE_SCRIPT_ID = "potok-initial-states";
4
+ export declare const PRELOAD_SCRIPTS_SCRIPT_ID = "potok-preload-scripts";
@@ -0,0 +1,8 @@
1
+ import { t as HTML_ELEMENT_STYLE_PX_PROPERTIES } from "./constants-Bxn0R4hW.mjs";
2
+ function normalizeCssPropertyName(e) {
3
+ return e.replace(/([A-Z])/g, "-$1").toLowerCase();
4
+ }
5
+ function normalizeCssPropertyValue(t, n) {
6
+ return typeof n == "number" && HTML_ELEMENT_STYLE_PX_PROPERTIES.includes(t) ? `${n}px` : String(n);
7
+ }
8
+ export { normalizeCssPropertyValue as n, normalizeCssPropertyName as t };
@@ -0,0 +1,4 @@
1
+ function escapeFromScriptTag(e) {
2
+ return e.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
3
+ }
4
+ export { escapeFromScriptTag as t };
@@ -1 +1 @@
1
- export { hydrate } from '../dom/hydrate';
1
+ export { hydrate } from '../client/hydrate';
@@ -1 +1,3 @@
1
1
  export { registerComponent } from '../hmr/register-component';
2
+ export { registerStyle } from '../hmr/register-style';
3
+ export { removeStyle } from '../hmr/remove-style';
@@ -2,13 +2,13 @@ export { ClientOnly } from '../client-only';
2
2
  export { ErrorBoundary } from '../error-boundary';
3
3
  export { Lazy } from '../lazy';
4
4
  export { LibContextReader } from '../lib-context-reader';
5
- export { LibScripts } from '../lib-scripts';
5
+ export { FooterScripts } from '../footer-scripts';
6
+ export { HeaderScripts } from '../header-scripts';
6
7
  export { Lifecycle } from '../lifecycle';
7
8
  export { List } from '../list';
8
9
  export { PortalIn, PortalOut } from '../portal';
9
10
  export { createElementReference } from '../ref';
10
11
  export { Show } from '../show';
11
12
  export { createSignal, createEffect, batch, untrack, deepTrack, getSignal, } from '../signals';
12
- export { createStore } from '../store';
13
13
  export type { PotokElement, WithChildren } from '../types';
14
14
  export type * from '../jsx-types';
@@ -1,4 +1,5 @@
1
1
  export { fragment } from '../fragment';
2
2
  export { htmlElement } from '../html-element';
3
- export { text } from '../text';
3
+ export { text } from '../text-node';
4
4
  export { detectChild } from '../detect-child';
5
+ export { potokPreload } from '../client/potok-preload';
@@ -1 +1,2 @@
1
- export { bootstrapApp } from '../bootstrap-app';
1
+ export { bootstrapApp } from '../server/bootstrap-app';
2
+ export { renderToString } from '../server/render-to-string';
@@ -0,0 +1,2 @@
1
+ export { createStore } from '../store/create-store';
2
+ export { httpExtension } from '../store/http-extension';
@@ -0,0 +1,2 @@
1
+ import { PotokElement } from './types';
2
+ export declare function FooterScripts(): PotokElement;
@@ -0,0 +1,18 @@
1
+ import { l as LibBlock } from "./lib-node-DyXPvvVQ.mjs";
2
+ import { i as mergeContext, t as normalizeChildren } from "./normalize-children-BWrn16R7.mjs";
3
+ var FragmentClass = class extends LibBlock {
4
+ constructor(e, r) {
5
+ super(), this.props = e, this.context = r, normalizeChildren(e.children).forEach((e, n) => {
6
+ this.children.push(e(mergeContext(r, {
7
+ parentBlock: this,
8
+ index: n
9
+ })));
10
+ });
11
+ }
12
+ };
13
+ function fragment(e) {
14
+ return function(t) {
15
+ return new FragmentClass(e, t);
16
+ };
17
+ }
18
+ export { fragment as t };
@@ -0,0 +1,97 @@
1
+ import { i as createSignal, l as LibBlock } from "./lib-node-DyXPvvVQ.mjs";
2
+ import { i as mergeContext, r as normalizeArray, t as normalizeChildren } from "./normalize-children-BWrn16R7.mjs";
3
+ var LibContextReaderClass = class extends LibBlock {
4
+ constructor(e, t) {
5
+ super(), this.props = e, this.context = t, normalizeArray(e.children).forEach((e, r) => {
6
+ this.children.push(e(t)(mergeContext(t, {
7
+ parentBlock: this,
8
+ index: r
9
+ })));
10
+ });
11
+ }
12
+ };
13
+ function LibContextReader(e) {
14
+ return function(t) {
15
+ return new LibContextReaderClass(e, t);
16
+ };
17
+ }
18
+ var LifecycleClass = class extends LibBlock {
19
+ onMountedReturn;
20
+ constructor(e, t) {
21
+ super(), this.props = e, this.context = t, normalizeChildren(e.children).forEach((e, r) => {
22
+ this.children.push(e(mergeContext(t, {
23
+ parentBlock: this,
24
+ index: r
25
+ })));
26
+ }), this.onMountedReturn = e.onMounted?.();
27
+ }
28
+ unmount() {
29
+ super.unmount(), this.onMountedReturn?.(), this.props.onUnmounted?.();
30
+ }
31
+ };
32
+ function Lifecycle(e) {
33
+ return function(t) {
34
+ return new LifecycleClass(e, t);
35
+ };
36
+ }
37
+ var RegisteredComponent = class {
38
+ component;
39
+ subscribers;
40
+ cachedInstances;
41
+ constructor(e) {
42
+ this.component = e, this.subscribers = /* @__PURE__ */ new Set(), this.cachedInstances = /* @__PURE__ */ new Map();
43
+ }
44
+ getCachedInstance(e) {
45
+ return this.cachedInstances.get(e);
46
+ }
47
+ addCachedInstance(e, t) {
48
+ this.cachedInstances.set(e, {
49
+ isRemovable: !1,
50
+ element: t
51
+ });
52
+ }
53
+ markInstanceAsRemovable(e) {
54
+ let t = this.cachedInstances.get(e);
55
+ t && (t.isRemovable = !0);
56
+ }
57
+ unmarkInstanceAsRemovable(e) {
58
+ let t = this.cachedInstances.get(e);
59
+ t && (t.isRemovable = !1);
60
+ }
61
+ removeCachedInstance(e) {
62
+ this.cachedInstances.delete(e);
63
+ }
64
+ };
65
+ const HMR_COMPONENTS_REGISTRY = new class {
66
+ components = /* @__PURE__ */ new Map();
67
+ getModuleComponentsMap(e) {
68
+ return this.components.has(e) || this.components.set(e, /* @__PURE__ */ new Map()), this.components.get(e);
69
+ }
70
+ addComponent(e, t, n) {
71
+ let r = this.getModuleComponentsMap(e);
72
+ r.has(t) || r.set(t, new RegisteredComponent(n));
73
+ let i = r.get(t);
74
+ return i.component = n, i;
75
+ }
76
+ getRegisteredComponent(e, t) {
77
+ return this.getModuleComponentsMap(e).get(t);
78
+ }
79
+ subscribeToComponent(e, t, n) {
80
+ return this.getRegisteredComponent(e, t)?.subscribers.add(n), () => {
81
+ this.unsubscribeFromComponent(e, t, n);
82
+ };
83
+ }
84
+ unsubscribeFromComponent(e, t, n) {
85
+ this.getRegisteredComponent(e, t)?.subscribers.delete(n);
86
+ }
87
+ notifyComponentUpdate(e, t) {
88
+ let n = this.getRegisteredComponent(e, t);
89
+ if (n) for (let e of n.subscribers) e(n);
90
+ }
91
+ }(), HMR_STATE_CACHE = /* @__PURE__ */ new Map(), HMR_STYLES = createSignal({ styles: [] });
92
+ function getComponentInstanceId(e) {
93
+ let t = [], n = e;
94
+ for (; n;) t.push(n.index), n = n.parentBlock ? n.parentBlock.context : null;
95
+ return t.reverse().join("_");
96
+ }
97
+ export { Lifecycle as a, HMR_STYLES as i, HMR_COMPONENTS_REGISTRY as n, LibContextReader as o, HMR_STATE_CACHE as r, getComponentInstanceId as t };
@@ -0,0 +1,2 @@
1
+ import { PotokElement } from './types';
2
+ export declare function HeaderScripts(): PotokElement;
@@ -0,0 +1,12 @@
1
+ import { HMRRegistry } from './registry';
2
+ export declare const HMR_COMPONENTS_REGISTRY: HMRRegistry;
3
+ export declare const HMR_STATE_CACHE: Map<string, {
4
+ value: unknown;
5
+ isRemovable: boolean;
6
+ }>;
7
+ export declare const HMR_STYLES: {
8
+ styles: {
9
+ id: string;
10
+ css: string;
11
+ }[];
12
+ };
@@ -1,2 +1,6 @@
1
1
  import { Component, ComponentProps, PotokElement } from '../types';
2
+ export interface RegisteredComponentElement extends PotokElement {
3
+ dependencies: string[];
4
+ }
2
5
  export declare function registerComponent<Props extends ComponentProps>(component: (props: Props) => PotokElement, moduleId: string, componentId: string): Component<Props>;
6
+ export declare function isRegisteredComponentElement(value: any): value is RegisteredComponentElement;
@@ -0,0 +1 @@
1
+ export declare function registerStyle(id: string, css: string): void;
@@ -1,13 +1,8 @@
1
1
  import { Component, PotokElement } from '../types';
2
2
  import { HMRSubscriber } from './types';
3
- export type CachedInstanceState = {
4
- current: unknown;
5
- initial: unknown;
6
- };
7
3
  type CachedInstance = {
8
4
  isRemovable: boolean;
9
5
  element: PotokElement;
10
- states: CachedInstanceState[];
11
6
  };
12
7
  export declare class RegisteredComponent {
13
8
  component: Component<any>;
@@ -15,7 +10,7 @@ export declare class RegisteredComponent {
15
10
  private cachedInstances;
16
11
  constructor(component: Component<any>);
17
12
  getCachedInstance(instanceId: string): CachedInstance | undefined;
18
- addCachedInstance(instanceId: string, element: PotokElement, states: CachedInstanceState[]): void;
13
+ addCachedInstance(instanceId: string, element: PotokElement): void;
19
14
  markInstanceAsRemovable(instanceId: string): void;
20
15
  unmarkInstanceAsRemovable(instanceId: string): void;
21
16
  removeCachedInstance(instanceId: string): void;
@@ -0,0 +1 @@
1
+ export declare function removeStyle(id: string): void;
@@ -1,3 +1 @@
1
- import { LibContext } from '../types';
2
1
  export declare function isWindowDefined(): boolean;
3
- export declare function getComponentInstanceId(context: LibContext): string;
package/dist/hmr.mjs CHANGED
@@ -1,42 +1,14 @@
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
- function registerComponent(o, s, c) {
5
- if (!isWindowDefined()) return o;
6
- let l = HMR_DEV.registry.addComponent(s, c, o);
7
- HMR_DEV.registry.notifyComponentUpdate(s, c);
8
- function u(e, t, n = !1) {
9
- let r = getComponentInstanceId(t), i = l.getCachedInstance(r);
10
- if (!n && i) return i.element;
11
- HMR_DEV.currentInstance = {
12
- states: i ? i.states : [],
13
- stateIndex: 0
14
- };
15
- let a = l.component(e);
16
- return l.addCachedInstance(r, a, HMR_DEV.currentInstance.states), HMR_DEV.currentInstance = null, a;
17
- }
18
- return (t) => LibContextReader({ children(i) {
19
- let o = createSignal({ element: u(t, i) }), d = getComponentInstanceId(i);
20
- return Lifecycle({
21
- onMounted() {
22
- let e = HMR_DEV.registry.subscribeToComponent(s, c, () => {
23
- o.element = null, o.element = u(t, i, !0);
24
- });
25
- return l.unmarkInstanceAsRemovable(d), () => {
26
- e(), l.markInstanceAsRemovable(d), setTimeout(() => {
27
- l.getCachedInstance(d)?.isRemovable && l.removeCachedInstance(d);
28
- });
29
- };
30
- },
31
- children: [Show({
32
- get when() {
33
- return o.element !== null;
34
- },
35
- children: [fragment({ get children() {
36
- return [o.element];
37
- } })]
38
- })]
39
- });
40
- } });
1
+ import { i as createSignal } from "./lib-node-DyXPvvVQ.mjs";
2
+ import { i as HMR_STYLES } from "./get-component-instance-id-CP6LDtpX.mjs";
3
+ import { n as registerComponent } from "./register-component-B92kGFqC.mjs";
4
+ function registerStyle(n, r) {
5
+ let i = HMR_STYLES.styles.find((e) => e.id === n);
6
+ i ? i.css = r : HMR_STYLES.styles = [...HMR_STYLES.styles, createSignal({
7
+ id: n,
8
+ css: r
9
+ })];
41
10
  }
42
- export { registerComponent };
11
+ function removeStyle(e) {
12
+ HMR_STYLES.styles = HMR_STYLES.styles.filter((t) => t.id !== e);
13
+ }
14
+ export { registerComponent, registerStyle, removeStyle };
@@ -0,0 +1,31 @@
1
+ import { t as LibNode } from "./lib-node-DyXPvvVQ.mjs";
2
+ import { i as mergeContext, t as normalizeChildren } from "./normalize-children-BWrn16R7.mjs";
3
+ function potokPreload(e, t) {
4
+ let n = () => e();
5
+ return n.dependencies = t, n;
6
+ }
7
+ function isPotokPreloader(e) {
8
+ return typeof e == "function" && Array.isArray(e.dependencies);
9
+ }
10
+ var LibHTMLElementNode = class extends LibNode {
11
+ constructor(e, r) {
12
+ super(), this.props = e, this.context = r, r.isHydrating && this.insert(), normalizeChildren(e.children).forEach((e, n) => {
13
+ this.children.push(e(mergeContext(r, {
14
+ parentBlock: this,
15
+ index: n
16
+ })));
17
+ }), r.isHydrating || this.insert();
18
+ }
19
+ isHTMLElementNode() {
20
+ return !0;
21
+ }
22
+ unmount() {
23
+ this.props.ref && (this.props.ref.element = null), super.unmount();
24
+ }
25
+ };
26
+ function htmlElement(e) {
27
+ return function(t) {
28
+ return new LibHTMLElementNode(e, t);
29
+ };
30
+ }
31
+ export { isPotokPreloader as n, potokPreload as r, htmlElement as t };
@@ -1,6 +1,14 @@
1
+ import { LibNode } from './lib-node';
1
2
  import { LibHTMLElementTagNameMap } from './prop-types';
2
- import { PotokElement } from './types';
3
+ import { LibContext, PotokElement } from './types';
3
4
  export type LibHTMLElementProps<Tag extends keyof LibHTMLElementTagNameMap> = {
4
5
  tag: Tag;
5
6
  } & LibHTMLElementTagNameMap[Tag];
7
+ export declare class LibHTMLElementNode<Tag extends keyof LibHTMLElementTagNameMap = keyof LibHTMLElementTagNameMap> extends LibNode {
8
+ readonly props: LibHTMLElementProps<Tag>;
9
+ readonly context: LibContext;
10
+ constructor(props: LibHTMLElementProps<Tag>, context: LibContext);
11
+ isHTMLElementNode(): this is LibHTMLElementNode;
12
+ unmount(): void;
13
+ }
6
14
  export declare function htmlElement<Tag extends keyof LibHTMLElementTagNameMap>(props: LibHTMLElementProps<Tag>): PotokElement;