@potok-web-framework/core 0.7.0 → 0.10.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 +203 -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 +84 -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/index.mjs CHANGED
@@ -1,7 +1,13 @@
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";
1
+ import { a as deepTrack, c as untrack, i as createSignal, l as LibBlock, n as batch, o as getSignal, r as createEffect, s as isSignal } from "./lib-node-DyXPvvVQ.mjs";
2
+ import { i as mergeContext, n as text, t as normalizeChildren } from "./normalize-children-BWrn16R7.mjs";
3
+ import { a as Lifecycle, i as HMR_STYLES, o as LibContextReader } from "./get-component-instance-id-CP6LDtpX.mjs";
4
+ import { r as Show, t as isRegisteredComponentElement } from "./register-component-B92kGFqC.mjs";
5
+ import { n as isPotokPreloader, t as htmlElement } from "./html-element-DBut4UCf.mjs";
6
+ import { t as fragment } from "./fragment-CXNEPBWB.mjs";
7
+ import { i as PRELOAD_SCRIPTS_SCRIPT_ID, n as HYDRATION_STATE_SCRIPT_ID } from "./constants-Bxn0R4hW.mjs";
8
+ import { t as escapeFromScriptTag } from "./escape-from-script-tag-CRT2evI1.mjs";
9
+ import { n as serializeWithTypes } from "./serialization-qOayQbjE.mjs";
10
+ import { clientEntry } from "virtual:client-variables";
5
11
  function ClientOnly(e) {
6
12
  return LibContextReader({ children: (t) => Show({
7
13
  get when() {
@@ -43,88 +49,115 @@ function ErrorBoundary(e) {
43
49
  function Lazy(e) {
44
50
  return LibContextReader({ children: (t) => {
45
51
  let r = createSignal({ block: null });
46
- return t.promises.push(e.import().then((t) => {
47
- r.block = e.resolve(t);
48
- })), fragment({ children: [Show({
49
- get when() {
50
- return r.block !== null;
52
+ return Lifecycle({
53
+ onMounted() {
54
+ if (isPotokPreloader(e.import)) {
55
+ let n = e.import.dependencies;
56
+ return t.preload.addScripts(n), createEffect(() => {
57
+ n.every((e) => t.preload.scripts.some((t) => t.path === e && t.isLoaded)) && r.block === null && t.promises.push(e.import().then((t) => {
58
+ let n = e.resolve(t);
59
+ process.env.NODE_ENV === "development" && isRegisteredComponentElement(n), r.block = n;
60
+ }).catch((e) => {
61
+ throw e;
62
+ }));
63
+ }, !0).dispose;
64
+ }
51
65
  },
52
- children: [r.block]
53
- }), Show({
66
+ children: [fragment({ children: [Show({
67
+ get when() {
68
+ return r.block !== null;
69
+ },
70
+ children: [fragment({ get children() {
71
+ return r.block;
72
+ } })]
73
+ }), Show({
74
+ get when() {
75
+ return r.block === null;
76
+ },
77
+ children: [fragment({ get children() {
78
+ return e.fallback;
79
+ } })]
80
+ })] })]
81
+ });
82
+ } });
83
+ }
84
+ function FooterScripts() {
85
+ return LibContextReader({ children: (e) => {
86
+ let t = [Show({
54
87
  get when() {
55
- return r.block === null;
88
+ return e.isServer || e.isHydrating;
56
89
  },
57
- children: [e.fallback]
58
- })] });
90
+ children: [htmlElement({
91
+ tag: "script",
92
+ id: HYDRATION_STATE_SCRIPT_ID,
93
+ type: "application/json",
94
+ children: [text({ get text() {
95
+ return escapeFromScriptTag(serializeWithTypes(e.states));
96
+ } })]
97
+ }), htmlElement({
98
+ tag: "script",
99
+ id: PRELOAD_SCRIPTS_SCRIPT_ID,
100
+ type: "application/json",
101
+ children: [text({ get text() {
102
+ return escapeFromScriptTag(serializeWithTypes(e.preload.scripts));
103
+ } })]
104
+ })]
105
+ })];
106
+ return process.env.NODE_ENV === "development" && t.push(htmlElement({
107
+ tag: "script",
108
+ type: "module",
109
+ src: "/@vite/client"
110
+ })), t.push(htmlElement({
111
+ tag: "script",
112
+ type: "module",
113
+ src: clientEntry
114
+ })), fragment({ children: t });
59
115
  } });
60
116
  }
61
- function LibScripts() {
62
- return PortalOut({ name: "lib-scripts" });
63
- }
64
117
  var ListClass = class extends LibBlock {
65
- signals = [];
66
- constructor(o, s) {
67
- super(), this.props = o, this.context = s;
68
- let l = [];
69
- this.addEffect(createEffect(() => {
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
- });
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
- parentBlock: this,
81
- get index() {
82
- return t.index;
83
- }
84
- }));
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
- }
91
- }), this.signals.forEach((e, t) => {
92
- e.value.index !== t && (e.proxy.index = t);
93
- }), l = [...i];
118
+ entries = /* @__PURE__ */ new Map();
119
+ constructor(n, r) {
120
+ super(), this.props = n, this.context = r, this.addEffect(createEffect(() => {
121
+ let r = n.items;
122
+ isSignal(r) && deepTrack(r, 1), untrack(() => {
123
+ batch(() => {
124
+ this.reconcile(r);
125
+ });
94
126
  });
95
127
  }, !0));
96
128
  }
97
- diff(e, t) {
98
- let n = [];
99
- for (let r = 0; r <= e.length; r++) {
100
- n.push([r]);
101
- for (let i = 1; i <= t.length; i++) if (r === 0) n[r].push(i);
102
- else {
103
- let a = n[r - 1][i] + 1, o = n[r][i - 1] + 1, s = n[r - 1][i - 1] + (e[r - 1] === t[i - 1] ? 0 : 1);
104
- n[r].push(Math.min(a, o, s));
105
- }
106
- }
107
- let r = [], i = t.length, a = e.length;
108
- for (; i > 0 || a > 0;) {
109
- let o = a > 0 ? n[a - 1][i] : Infinity, s = i > 0 ? n[a][i - 1] : Infinity, c = a > 0 && i > 0 ? n[a - 1][i - 1] : Infinity, l = Math.min(o, s, c);
110
- l === c ? (e[a - 1] !== t[i - 1] && r.push({
111
- type: "replace",
112
- index: a - 1,
113
- oldItem: e[a - 1],
114
- newItem: t[i - 1]
115
- }), i--, a--) : l === o ? (r.push({
116
- type: "delete",
117
- index: a - 1
118
- }), a--) : (r.push({
119
- type: "add",
120
- index: a,
121
- item: t[i - 1]
122
- }), i--);
123
- }
124
- return r;
129
+ reconcile(e) {
130
+ this.children = [];
131
+ let t = /* @__PURE__ */ new Map(), r = [];
132
+ e.forEach((e, n) => {
133
+ let i = this.props.keyExtractor(e, n), a = this.entries.get(i);
134
+ a ? (a.signal.item = e, a.signal.index = n, this.children.push(a.block), t.set(i, a)) : (r.push({
135
+ key: i,
136
+ index: n,
137
+ item: e
138
+ }), this.children.push(null));
139
+ }), r.forEach(({ key: e, index: r, item: i }) => {
140
+ let a = createSignal({
141
+ item: i,
142
+ index: r
143
+ }), o = this.props.render(a)(mergeContext(this.context, {
144
+ parentBlock: this,
145
+ get index() {
146
+ return a.index;
147
+ }
148
+ }));
149
+ this.children[r] = o, t.set(e, {
150
+ signal: a,
151
+ block: o
152
+ });
153
+ }), this.entries.forEach((e, n) => {
154
+ t.has(n) || e.block.unmount();
155
+ }), this.children.forEach((e) => {
156
+ e?.isNode() && e.insert();
157
+ }), this.entries = t;
125
158
  }
126
159
  unmount() {
127
- super.unmount(), this.signals = [];
160
+ super.unmount(), this.entries.clear();
128
161
  }
129
162
  };
130
163
  function List(e) {
@@ -135,65 +168,106 @@ function List(e) {
135
168
  function createElementReference() {
136
169
  return createSignal({ element: null });
137
170
  }
138
- var ContextProvider = class extends LibBlock {
139
- constructor(e, t, n) {
140
- super(), this.props = e, this.context = n, normalizeChildren(e.children).forEach((r, i) => {
141
- this.children.push(r(mergeContext(n, {
142
- parentBlock: this,
143
- index: i,
144
- contexts: { [t]: e.value }
145
- })));
146
- });
147
- }
148
- }, ContextConsumer = class extends LibBlock {
149
- constructor(e, t, n) {
171
+ function HeaderScripts() {
172
+ return LibContextReader({ children: (e) => {
173
+ let n = [List({
174
+ get items() {
175
+ return e.preload.scripts;
176
+ },
177
+ keyExtractor(e) {
178
+ return e.path;
179
+ },
180
+ render(e) {
181
+ let n = createElementReference();
182
+ return Lifecycle({
183
+ onMounted() {
184
+ if (e.item.isLoaded) return;
185
+ let r = createEffect(() => {
186
+ let r = n.element;
187
+ r && (r.onload = () => {
188
+ untrack(() => {
189
+ e.item.isLoaded = !0;
190
+ });
191
+ });
192
+ }, !0);
193
+ return () => {
194
+ r.dispose(), n.element && (n.element.onload = null);
195
+ };
196
+ },
197
+ children: [htmlElement({
198
+ tag: "link",
199
+ get rel() {
200
+ return e.item.path.endsWith(".css") ? "stylesheet" : "modulepreload";
201
+ },
202
+ get href() {
203
+ return e.item.path;
204
+ },
205
+ ref: n
206
+ })]
207
+ });
208
+ }
209
+ })];
210
+ return process.env.NODE_ENV === "development" && n.push(ClientOnly({ children: [List({
211
+ get items() {
212
+ return HMR_STYLES.styles;
213
+ },
214
+ keyExtractor(e) {
215
+ return e.id;
216
+ },
217
+ render(e) {
218
+ return htmlElement({
219
+ tag: "style",
220
+ get "data-id"() {
221
+ return e.item.id;
222
+ },
223
+ children: [text({ get text() {
224
+ return e.item.css;
225
+ } })]
226
+ });
227
+ }
228
+ })] })), fragment({ children: n });
229
+ } });
230
+ }
231
+ var PortalInClass = class extends LibBlock {
232
+ constructor(e, n) {
150
233
  super(), this.props = e, this.context = n;
151
- let r = n.contexts[t];
152
- if (!r) throw Error("Контекст не найден");
153
- normalizeArray(e.children).forEach((e, t) => {
154
- this.children.push(e(r)(mergeContext(n, {
155
- parentBlock: this,
156
- index: t
157
- })));
158
- });
234
+ let r;
235
+ n.portals[e.name] ? console.warn(`Портал ${e.name} уже существует`) : this.addEffect(createEffect(() => {
236
+ let i = e.name;
237
+ i !== r && untrack(() => {
238
+ delete n.portals[i], n.portals[i] = e.children;
239
+ }), r = i;
240
+ }));
241
+ }
242
+ unmount() {
243
+ super.unmount(), delete this.context.portals[this.props.name];
159
244
  }
160
245
  };
161
- function createContext() {
162
- let e = Symbol("context");
163
- return {
164
- provider(t) {
165
- return function(n) {
166
- return new ContextProvider(t, e, n);
167
- };
168
- },
169
- reader(t) {
170
- return function(n) {
171
- return new ContextConsumer(t, e, n);
172
- };
173
- }
246
+ function PortalIn(e) {
247
+ return function(t) {
248
+ return new PortalInClass(e, t);
174
249
  };
175
250
  }
176
- function createStore() {
177
- return function(e) {
178
- let t = createContext();
179
- return {
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
- return t.provider({
186
- value: {
187
- state: i,
188
- actions: s
189
- },
190
- children: r.children
251
+ var PortalOutClass = class extends LibBlock {
252
+ constructor(e, n) {
253
+ super(), this.props = e, this.context = n;
254
+ let r;
255
+ this.addEffect(createEffect(() => {
256
+ let i = e.name, a = normalizeChildren(n.portals[i]);
257
+ a ? a !== r && (this.unmountChildren(), untrack(() => {
258
+ a.forEach((e, t) => {
259
+ this.children.push(e(mergeContext(n, {
260
+ parentBlock: this,
261
+ index: t
262
+ })));
191
263
  });
192
- },
193
- reader(e) {
194
- return t.reader({ children: (t) => e.children(t) });
195
- }
196
- };
264
+ }), r = a) : (this.unmountChildren(), r = null);
265
+ }));
266
+ }
267
+ };
268
+ function PortalOut(e) {
269
+ return function(t) {
270
+ return new PortalOutClass(e, t);
197
271
  };
198
272
  }
199
- export { ClientOnly, ErrorBoundary, Lazy, LibContextReader, LibScripts, Lifecycle, List, PortalIn, PortalOut, Show, batch, createEffect, createElementReference, createSignal, createStore, deepTrack, getSignal, untrack };
273
+ export { ClientOnly, ErrorBoundary, FooterScripts, HeaderScripts, Lazy, LibContextReader, Lifecycle, List, PortalIn, PortalOut, Show, batch, createEffect, createElementReference, createSignal, deepTrack, getSignal, untrack };
@@ -0,0 +1,4 @@
1
+ function isPureObject(e) {
2
+ return typeof e == "object" && !!e && Object.getPrototypeOf(e).isPrototypeOf(Object);
3
+ }
4
+ export { isPureObject as t };
@@ -1,10 +1,10 @@
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";
1
+ import { n as text } from "./normalize-children-BWrn16R7.mjs";
2
+ import { r as potokPreload, t as htmlElement } from "./html-element-DBut4UCf.mjs";
3
+ import { t as fragment } from "./fragment-CXNEPBWB.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() {
7
7
  return e.value;
8
8
  } }) : t;
9
9
  }
10
- export { detectChild, fragment, htmlElement, text };
10
+ export { detectChild, fragment, htmlElement, potokPreload, text };
@@ -0,0 +1,192 @@
1
+ var LibBlock = class {
2
+ effects = /* @__PURE__ */ new Set();
3
+ children = [];
4
+ get parentBlock() {
5
+ return this.context.parentBlock;
6
+ }
7
+ get parentElementNode() {
8
+ let e = this.parentBlock;
9
+ return e ? e.isHTMLElementNode() ? e : e.parentElementNode : null;
10
+ }
11
+ get previousBlock() {
12
+ let e = this.context.parentBlock;
13
+ return e ? e.children[this.context.index - 1] || (e.isNode() ? null : e.previousBlock) : null;
14
+ }
15
+ get nearestPreviousNode() {
16
+ if (this.isNode()) return this;
17
+ let e = this.children[this.children.length - 1];
18
+ if (e) return e.nearestPreviousNode;
19
+ let t = this.previousBlock;
20
+ return t ? t.nearestPreviousNode : null;
21
+ }
22
+ get previousNode() {
23
+ let e = this.previousBlock;
24
+ return e ? e.nearestPreviousNode : null;
25
+ }
26
+ isNode() {
27
+ return !1;
28
+ }
29
+ isHTMLElementNode() {
30
+ return !1;
31
+ }
32
+ isTextNode() {
33
+ return !1;
34
+ }
35
+ addEffect(e) {
36
+ this.effects.add(e);
37
+ }
38
+ unmountChildren() {
39
+ this.children.forEach((e) => {
40
+ e?.unmount();
41
+ }), this.children = [];
42
+ }
43
+ unmount() {
44
+ this.unmountChildren(), this.effects.forEach((e) => {
45
+ e.dispose();
46
+ }), this.effects.clear();
47
+ }
48
+ }, currentEffect = null, currentBatch = null, currentDisposer = null, VALUE_SIGNAL_SYMBOL = Symbol("VALUE_SIGNAL"), ANY_KEY_SYMBOL = Symbol("ANY_KEY");
49
+ function getSignal(e) {
50
+ return e[VALUE_SIGNAL_SYMBOL];
51
+ }
52
+ function isSignal(e) {
53
+ return getSignal(e) !== void 0;
54
+ }
55
+ function canBeSignal(e) {
56
+ return typeof e == "object" && !!e && (Array.isArray(e) || Object.getPrototypeOf(e).isPrototypeOf(Object));
57
+ }
58
+ function createSignal(e) {
59
+ let n = getSignal(e);
60
+ if (n) return n.proxy;
61
+ let r = {
62
+ value: e,
63
+ proxy: new Proxy(e, {
64
+ get(e, n, a) {
65
+ if (n === VALUE_SIGNAL_SYMBOL) return r;
66
+ let o = Reflect.get(e, n, a);
67
+ return currentEffect && r.subscribe(currentEffect, n), canBeSignal(o) ? createSignal(o) : typeof o == "function" ? o.bind(e) : o;
68
+ },
69
+ set(e, t, n, i) {
70
+ let o = Reflect.set(e, t, n, i);
71
+ return o && r.subscribers.forEach((e) => {
72
+ let n = e.subscriptions.get(r);
73
+ (e.ignoreVersion || n?.get(ANY_KEY_SYMBOL) === e.version || n?.get(t) === e.version) && e.runCallback();
74
+ }), o;
75
+ }
76
+ }),
77
+ subscribers: /* @__PURE__ */ new Set(),
78
+ subscribe(e, t) {
79
+ let n = e.subscriptions.get(r);
80
+ n || (n = /* @__PURE__ */ new Map(), e.subscriptions.set(r, n), r.subscribers.add(e)), n.get(t) !== e.version && n.set(t, e.version);
81
+ }
82
+ };
83
+ return Object.defineProperty(e, VALUE_SIGNAL_SYMBOL, {
84
+ value: r,
85
+ enumerable: !1,
86
+ writable: !1,
87
+ configurable: !1
88
+ }), r.proxy;
89
+ }
90
+ function createEffect(e, i = !1) {
91
+ let a = !1, o = {
92
+ callback: e,
93
+ subscriptions: /* @__PURE__ */ new Map(),
94
+ version: 0,
95
+ ignoreVersion: i,
96
+ dispose() {
97
+ a = !0;
98
+ },
99
+ runCallback() {
100
+ if (a) {
101
+ o.subscriptions.forEach((e, t) => {
102
+ t.subscribers.delete(o);
103
+ }), o.subscriptions.clear();
104
+ return;
105
+ }
106
+ if (currentBatch) {
107
+ currentBatch.add(o);
108
+ return;
109
+ }
110
+ currentEffect = o, o.version++, e(), currentEffect = null;
111
+ }
112
+ };
113
+ return currentDisposer && currentDisposer.effects.add(o), o.runCallback(), o;
114
+ }
115
+ function batch(e) {
116
+ if (currentBatch) return e();
117
+ currentBatch = {
118
+ effects: /* @__PURE__ */ new Set(),
119
+ add(e) {
120
+ this.effects.add(e);
121
+ },
122
+ run() {
123
+ this.effects.forEach((e) => {
124
+ e.runCallback();
125
+ });
126
+ }
127
+ };
128
+ let t = e(), r = currentBatch;
129
+ return currentBatch = null, r.run(), t;
130
+ }
131
+ function untrack(e) {
132
+ let n = currentEffect;
133
+ currentEffect = null;
134
+ let r = e();
135
+ return currentEffect = n, r;
136
+ }
137
+ function _deepTrack(e, n, r = 0) {
138
+ if (n !== void 0 && n <= 0) {
139
+ console.warn(`depth=${n} не может быть меньше или равен 0`);
140
+ return;
141
+ }
142
+ if (!currentEffect) {
143
+ console.warn("deepTrack можно использовать только внутри эффекта");
144
+ return;
145
+ }
146
+ let i = currentEffect;
147
+ untrack(() => {
148
+ let s = getSignal(e);
149
+ if (!s) {
150
+ console.warn("deepTrack можно использовать только с сигналами");
151
+ return;
152
+ }
153
+ if (s.subscribe(i, ANY_KEY_SYMBOL), r++, !(n !== void 0 && r >= n)) if (Array.isArray(e)) for (let a = 0; a < e.length; a++) {
154
+ let o = e[a];
155
+ canBeSignal(o) && (currentEffect = i, _deepTrack(o, n, r));
156
+ }
157
+ else for (let a in e) {
158
+ let o = e[a];
159
+ canBeSignal(o) && (currentEffect = i, _deepTrack(o, n, r));
160
+ }
161
+ });
162
+ }
163
+ function deepTrack(e, t) {
164
+ _deepTrack(e, t);
165
+ }
166
+ function createDisposer(e) {
167
+ let t = {
168
+ effects: /* @__PURE__ */ new Set(),
169
+ dispose() {
170
+ t.effects.forEach((e) => {
171
+ e.dispose();
172
+ });
173
+ }
174
+ };
175
+ return currentDisposer = t, e(), currentDisposer = null, t;
176
+ }
177
+ var LibNode = class extends LibBlock {
178
+ isNode() {
179
+ return !0;
180
+ }
181
+ insert() {
182
+ createDisposer(() => {
183
+ this.context.insertNode(this);
184
+ }).effects.forEach((e) => {
185
+ this.effects.add(e);
186
+ });
187
+ }
188
+ unmount() {
189
+ this.context.removeNode(this), super.unmount();
190
+ }
191
+ };
192
+ export { deepTrack as a, untrack as c, createSignal as i, LibBlock as l, batch as n, getSignal as o, createEffect as r, isSignal as s, LibNode as t };
@@ -0,0 +1,6 @@
1
+ import { LibBlock } from './block';
2
+ export declare abstract class LibNode extends LibBlock {
3
+ isNode(): this is LibNode;
4
+ insert(): void;
5
+ unmount(): void;
6
+ }
package/dist/list.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import { PotokElement } from './types';
2
+ type ListKey = string | number;
2
3
  export type ListProps<Item> = {
3
4
  items: Item[];
5
+ keyExtractor: (item: Item, index: number) => ListKey;
4
6
  render: (each: {
5
7
  item: Item;
6
8
  index: number;
7
9
  }) => PotokElement;
8
10
  };
9
11
  export declare function List<Item>(props: ListProps<Item>): PotokElement;
12
+ export {};
@@ -0,0 +1,48 @@
1
+ import { t as LibNode } from "./lib-node-DyXPvvVQ.mjs";
2
+ function mergeContext(e, t) {
3
+ return {
4
+ parentBlock: t.parentBlock,
5
+ get index() {
6
+ return t.index;
7
+ },
8
+ portals: e.portals,
9
+ preload: e.preload,
10
+ states: e.states,
11
+ contexts: {
12
+ ...e.contexts,
13
+ ...t.contexts
14
+ },
15
+ isServer: e.isServer,
16
+ promises: e.promises,
17
+ get isHydrating() {
18
+ return e.isHydrating;
19
+ },
20
+ insertNode: e.insertNode,
21
+ removeNode: e.removeNode
22
+ };
23
+ }
24
+ function normalizeArray(e) {
25
+ return Array.isArray(e) ? e : [e];
26
+ }
27
+ var LibTextNode = class extends LibNode {
28
+ constructor(e, t) {
29
+ super(), this.props = e, this.context = t, this.insert();
30
+ }
31
+ isTextNode() {
32
+ return !0;
33
+ }
34
+ };
35
+ function text(e) {
36
+ return function(t) {
37
+ return new LibTextNode(e, t);
38
+ };
39
+ }
40
+ function normalizeChild(e) {
41
+ return typeof e == "string" || typeof e == "number" ? [text({ get text() {
42
+ return String(e);
43
+ } })] : Array.isArray(e) ? e.flatMap(normalizeChildren) : [e];
44
+ }
45
+ function normalizeChildren(e) {
46
+ return e ? normalizeArray(e).filter((e) => e != null).flatMap(normalizeChild) : [];
47
+ }
48
+ export { mergeContext as i, text as n, normalizeArray as r, normalizeChildren as t };