@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/index.mjs CHANGED
@@ -1,7 +1,12 @@
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";
5
10
  function ClientOnly(e) {
6
11
  return LibContextReader({ children: (t) => Show({
7
12
  get when() {
@@ -43,88 +48,115 @@ function ErrorBoundary(e) {
43
48
  function Lazy(e) {
44
49
  return LibContextReader({ children: (t) => {
45
50
  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;
51
+ return Lifecycle({
52
+ onMounted() {
53
+ if (isPotokPreloader(e.import)) {
54
+ let n = e.import.dependencies;
55
+ return t.preload.addScripts(n), createEffect(() => {
56
+ n.every((e) => t.preload.scripts.some((t) => t.path === e && t.isLoaded)) && r.block === null && t.promises.push(e.import().then((t) => {
57
+ let n = e.resolve(t);
58
+ process.env.NODE_ENV === "development" && isRegisteredComponentElement(n), r.block = n;
59
+ }).catch((e) => {
60
+ throw e;
61
+ }));
62
+ }, !0).dispose;
63
+ }
51
64
  },
52
- children: [r.block]
53
- }), Show({
65
+ children: [fragment({ children: [Show({
66
+ get when() {
67
+ return r.block !== null;
68
+ },
69
+ children: [fragment({ get children() {
70
+ return r.block;
71
+ } })]
72
+ }), Show({
73
+ get when() {
74
+ return r.block === null;
75
+ },
76
+ children: [fragment({ get children() {
77
+ return e.fallback;
78
+ } })]
79
+ })] })]
80
+ });
81
+ } });
82
+ }
83
+ function FooterScripts() {
84
+ return LibContextReader({ children: (e) => {
85
+ let t = [Show({
54
86
  get when() {
55
- return r.block === null;
87
+ return e.isServer || e.isHydrating;
56
88
  },
57
- children: [e.fallback]
58
- })] });
89
+ children: [htmlElement({
90
+ tag: "script",
91
+ id: HYDRATION_STATE_SCRIPT_ID,
92
+ type: "application/json",
93
+ children: [text({ get text() {
94
+ return escapeFromScriptTag(serializeWithTypes(e.states));
95
+ } })]
96
+ }), htmlElement({
97
+ tag: "script",
98
+ id: PRELOAD_SCRIPTS_SCRIPT_ID,
99
+ type: "application/json",
100
+ children: [text({ get text() {
101
+ return escapeFromScriptTag(serializeWithTypes(e.preload.scripts));
102
+ } })]
103
+ })]
104
+ })];
105
+ return process.env.NODE_ENV === "development" && t.push(htmlElement({
106
+ tag: "script",
107
+ type: "module",
108
+ src: "/@vite/client"
109
+ })), t.push(htmlElement({
110
+ tag: "script",
111
+ type: "module",
112
+ src: __POTOK_CLIENT_ENTRY__
113
+ })), fragment({ children: t });
59
114
  } });
60
115
  }
61
- function LibScripts() {
62
- return PortalOut({ name: "lib-scripts" });
63
- }
64
116
  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];
117
+ entries = /* @__PURE__ */ new Map();
118
+ constructor(n, r) {
119
+ super(), this.props = n, this.context = r, this.addEffect(createEffect(() => {
120
+ let r = n.items;
121
+ isSignal(r) && deepTrack(r, 1), untrack(() => {
122
+ batch(() => {
123
+ this.reconcile(r);
124
+ });
94
125
  });
95
126
  }, !0));
96
127
  }
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;
128
+ reconcile(e) {
129
+ this.children = [];
130
+ let t = /* @__PURE__ */ new Map(), r = [];
131
+ e.forEach((e, n) => {
132
+ let i = this.props.keyExtractor(e, n), a = this.entries.get(i);
133
+ a ? (a.signal.item = e, a.signal.index = n, this.children.push(a.block), t.set(i, a)) : (r.push({
134
+ key: i,
135
+ index: n,
136
+ item: e
137
+ }), this.children.push(null));
138
+ }), r.forEach(({ key: e, index: r, item: i }) => {
139
+ let a = createSignal({
140
+ item: i,
141
+ index: r
142
+ }), o = this.props.render(a)(mergeContext(this.context, {
143
+ parentBlock: this,
144
+ get index() {
145
+ return a.index;
146
+ }
147
+ }));
148
+ this.children[r] = o, t.set(e, {
149
+ signal: a,
150
+ block: o
151
+ });
152
+ }), this.entries.forEach((e, n) => {
153
+ t.has(n) || e.block.unmount();
154
+ }), this.children.forEach((e) => {
155
+ e?.isNode() && e.insert();
156
+ }), this.entries = t;
125
157
  }
126
158
  unmount() {
127
- super.unmount(), this.signals = [];
159
+ super.unmount(), this.entries.clear();
128
160
  }
129
161
  };
130
162
  function List(e) {
@@ -135,65 +167,106 @@ function List(e) {
135
167
  function createElementReference() {
136
168
  return createSignal({ element: null });
137
169
  }
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) {
170
+ function HeaderScripts() {
171
+ return LibContextReader({ children: (e) => {
172
+ let n = [List({
173
+ get items() {
174
+ return e.preload.scripts;
175
+ },
176
+ keyExtractor(e) {
177
+ return e.path;
178
+ },
179
+ render(e) {
180
+ let n = createElementReference();
181
+ return Lifecycle({
182
+ onMounted() {
183
+ if (e.item.isLoaded) return;
184
+ let r = createEffect(() => {
185
+ let r = n.element;
186
+ r && (r.onload = () => {
187
+ untrack(() => {
188
+ e.item.isLoaded = !0;
189
+ });
190
+ });
191
+ }, !0);
192
+ return () => {
193
+ r.dispose(), n.element && (n.element.onload = null);
194
+ };
195
+ },
196
+ children: [htmlElement({
197
+ tag: "link",
198
+ get rel() {
199
+ return e.item.path.endsWith(".css") ? "stylesheet" : "modulepreload";
200
+ },
201
+ get href() {
202
+ return e.item.path;
203
+ },
204
+ ref: n
205
+ })]
206
+ });
207
+ }
208
+ })];
209
+ return process.env.NODE_ENV === "development" && n.push(ClientOnly({ children: [List({
210
+ get items() {
211
+ return HMR_STYLES.styles;
212
+ },
213
+ keyExtractor(e) {
214
+ return e.id;
215
+ },
216
+ render(e) {
217
+ return htmlElement({
218
+ tag: "style",
219
+ get "data-id"() {
220
+ return e.item.id;
221
+ },
222
+ children: [text({ get text() {
223
+ return e.item.css;
224
+ } })]
225
+ });
226
+ }
227
+ })] })), fragment({ children: n });
228
+ } });
229
+ }
230
+ var PortalInClass = class extends LibBlock {
231
+ constructor(e, n) {
150
232
  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
- });
233
+ let r;
234
+ n.portals[e.name] ? console.warn(`Портал ${e.name} уже существует`) : this.addEffect(createEffect(() => {
235
+ let i = e.name;
236
+ i !== r && untrack(() => {
237
+ delete n.portals[i], n.portals[i] = e.children;
238
+ }), r = i;
239
+ }));
240
+ }
241
+ unmount() {
242
+ super.unmount(), delete this.context.portals[this.props.name];
159
243
  }
160
244
  };
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
- }
245
+ function PortalIn(e) {
246
+ return function(t) {
247
+ return new PortalInClass(e, t);
174
248
  };
175
249
  }
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
250
+ var PortalOutClass = class extends LibBlock {
251
+ constructor(e, n) {
252
+ super(), this.props = e, this.context = n;
253
+ let r;
254
+ this.addEffect(createEffect(() => {
255
+ let i = e.name, a = normalizeChildren(n.portals[i]);
256
+ a ? a !== r && (this.unmountChildren(), untrack(() => {
257
+ a.forEach((e, t) => {
258
+ this.children.push(e(mergeContext(n, {
259
+ parentBlock: this,
260
+ index: t
261
+ })));
191
262
  });
192
- },
193
- reader(e) {
194
- return t.reader({ children: (t) => e.children(t) });
195
- }
196
- };
263
+ }), r = a) : (this.unmountChildren(), r = null);
264
+ }));
265
+ }
266
+ };
267
+ function PortalOut(e) {
268
+ return function(t) {
269
+ return new PortalOutClass(e, t);
197
270
  };
198
271
  }
199
- export { ClientOnly, ErrorBoundary, Lazy, LibContextReader, LibScripts, Lifecycle, List, PortalIn, PortalOut, Show, batch, createEffect, createElementReference, createSignal, createStore, deepTrack, getSignal, untrack };
272
+ 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 };