@potok-web-framework/core 0.1.0 → 0.3.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 (94) hide show
  1. package/dist/block.d.ts +17 -0
  2. package/dist/bootstrap-app.d.ts +8 -0
  3. package/dist/client-only.d.ts +3 -0
  4. package/dist/client.mjs +133 -0
  5. package/dist/constants-BOAOReQ3.mjs +26 -0
  6. package/dist/constants.d.ts +2 -0
  7. package/dist/context.d.ts +12 -0
  8. package/dist/detect-child.d.ts +6 -0
  9. package/dist/error-boundary.d.ts +5 -0
  10. package/dist/exports/client.d.ts +1 -0
  11. package/dist/exports/hmr.d.ts +1 -0
  12. package/dist/exports/index.d.ts +14 -0
  13. package/dist/exports/jsx-runtime.d.ts +4 -0
  14. package/dist/exports/server.d.ts +1 -0
  15. package/dist/fragment-BahmURhz.mjs +17 -0
  16. package/dist/fragment.d.ts +4 -0
  17. package/dist/hmr/hmr-dev.d.ts +9 -0
  18. package/dist/hmr/register-component.d.ts +2 -0
  19. package/dist/hmr/registered-component.d.ts +23 -0
  20. package/dist/hmr/registry.d.ts +12 -0
  21. package/dist/hmr/types.d.ts +4 -0
  22. package/dist/hmr/utils.d.ts +3 -0
  23. package/dist/hmr.mjs +42 -0
  24. package/dist/html-element-Cm0RtMkT.mjs +42 -0
  25. package/dist/html-element.d.ts +6 -0
  26. package/dist/index.mjs +199 -0
  27. package/dist/jsx-runtime.mjs +10 -0
  28. package/dist/jsx-types.d.ts +11 -0
  29. package/dist/lazy.d.ts +7 -0
  30. package/dist/lib-context-reader.d.ts +5 -0
  31. package/dist/lib-scripts.d.ts +2 -0
  32. package/dist/lifecycle-4vjEuXGy.mjs +57 -0
  33. package/dist/lifecycle.d.ts +8 -0
  34. package/dist/list.d.ts +9 -0
  35. package/dist/portal-CbcYOHLv.mjs +44 -0
  36. package/dist/portal.d.ts +10 -0
  37. package/dist/prop-types.d.ts +939 -0
  38. package/dist/ref.d.ts +6 -0
  39. package/dist/render-to-dom.d.ts +8 -0
  40. package/dist/render-to-string.d.ts +2 -0
  41. package/dist/server-node.d.ts +10 -0
  42. package/dist/server.mjs +1192 -0
  43. package/dist/show.d.ts +6 -0
  44. package/dist/signals.d.ts +32 -0
  45. package/dist/store.d.ts +26 -0
  46. package/dist/text.d.ts +5 -0
  47. package/dist/types.d.ts +39 -0
  48. package/dist/utils-CAe_kbSH.mjs +345 -0
  49. package/dist/utils.d.ts +11 -0
  50. package/package.json +9 -3
  51. package/CHANGELOG.md +0 -7
  52. package/bun.lock +0 -25
  53. package/src/block.ts +0 -102
  54. package/src/bootstrap-app.ts +0 -115
  55. package/src/client-only.ts +0 -17
  56. package/src/constants.ts +0 -27
  57. package/src/context.ts +0 -85
  58. package/src/detect-child.ts +0 -21
  59. package/src/error-boundary.ts +0 -51
  60. package/src/exports/client.ts +0 -1
  61. package/src/exports/hmr.ts +0 -1
  62. package/src/exports/index.ts +0 -21
  63. package/src/exports/jsx-runtime.ts +0 -4
  64. package/src/exports/server.ts +0 -1
  65. package/src/fragment.ts +0 -28
  66. package/src/global.dev.d.ts +0 -12
  67. package/src/hmr/hmr-dev.ts +0 -10
  68. package/src/hmr/register-component.ts +0 -109
  69. package/src/hmr/registered-component.ts +0 -59
  70. package/src/hmr/registry.ts +0 -78
  71. package/src/hmr/types.ts +0 -6
  72. package/src/hmr/utils.ts +0 -20
  73. package/src/html-element.ts +0 -95
  74. package/src/jsx-types.ts +0 -13
  75. package/src/lazy.ts +0 -44
  76. package/src/lib-context-reader.ts +0 -33
  77. package/src/lib-scripts.ts +0 -8
  78. package/src/lifecycle.ts +0 -44
  79. package/src/list.ts +0 -175
  80. package/src/portal.ts +0 -101
  81. package/src/prop-types.ts +0 -1165
  82. package/src/ref.ts +0 -11
  83. package/src/render-to-dom.ts +0 -325
  84. package/src/render-to-string.ts +0 -65
  85. package/src/server-node.ts +0 -98
  86. package/src/show.ts +0 -46
  87. package/src/signals.ts +0 -323
  88. package/src/store.ts +0 -68
  89. package/src/text.ts +0 -35
  90. package/src/types.ts +0 -69
  91. package/src/utils.ts +0 -118
  92. package/tests/signals.test.ts +0 -403
  93. package/tsconfig.json +0 -17
  94. package/vite.config.ts +0 -21
package/dist/show.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { PotokElement, WithChildren } from './types';
2
+ type ShowProps = WithChildren<{
3
+ when: boolean;
4
+ }>;
5
+ export declare function Show(props: ShowProps): PotokElement;
6
+ export {};
@@ -0,0 +1,32 @@
1
+ export type SignalValue = Record<string, unknown> | Array<unknown>;
2
+ export type EffectCallback = () => void;
3
+ export type BatchCallback<Value> = () => Value;
4
+ export type UntrackCallback<Value> = () => Value;
5
+ export type DisposerCallback = () => void;
6
+ export type SubscriptionKey = string | number | symbol;
7
+ export type Signal<Value extends SignalValue> = {
8
+ value: Value;
9
+ proxy: Value;
10
+ subscribers: Set<Effect>;
11
+ subscribe(effect: Effect, key: SubscriptionKey): void;
12
+ };
13
+ export type Effect = {
14
+ callback: EffectCallback;
15
+ subscriptions: Map<Signal<SignalValue>, Map<SubscriptionKey, number>>;
16
+ version: number;
17
+ ignoreVersion: boolean;
18
+ dispose(): void;
19
+ runCallback(): void;
20
+ };
21
+ export type Disposer = {
22
+ effects: Set<Effect>;
23
+ dispose(): void;
24
+ };
25
+ export declare function getSignal<Value extends SignalValue>(value: Value): Signal<Value> | undefined;
26
+ export declare function isSignal<Value extends SignalValue>(value: Value): boolean;
27
+ export declare function createSignal<Value extends SignalValue>(value: Value): Value;
28
+ export declare function createEffect(callback: EffectCallback, disableVersionning?: boolean): Effect;
29
+ export declare function batch<Value>(callback: BatchCallback<Value>): Value;
30
+ export declare function untrack<Value>(callback: UntrackCallback<Value>): Value;
31
+ export declare function deepTrack(value: SignalValue, depth?: number): void;
32
+ export declare function createDisposer(callback: DisposerCallback): Disposer;
@@ -0,0 +1,26 @@
1
+ import { PotokElement, WithChildren } from './types';
2
+ type State = Record<string, any>;
3
+ type StateOptions<P extends StoreProps> = {
4
+ props: P;
5
+ };
6
+ type Actions = Record<string, (...args: any[]) => any>;
7
+ type ActionsOptions<P extends StoreProps, S extends State> = {
8
+ props: P;
9
+ state: S;
10
+ };
11
+ type StoreProps = Record<string, any>;
12
+ type StoreInitiator<P extends StoreProps, S extends State, A extends Actions> = {
13
+ state: (options: StateOptions<P>) => S;
14
+ actions: (options: ActionsOptions<P, S>) => A;
15
+ };
16
+ export type Store<P extends StoreProps, S extends State, A extends Actions> = {
17
+ provider(props: WithChildren<P>): PotokElement;
18
+ reader(props: {
19
+ children: (options: {
20
+ state: S;
21
+ actions: A;
22
+ }) => PotokElement;
23
+ }): PotokElement;
24
+ };
25
+ export declare function createStore<P extends StoreProps>(): <S extends State, A extends Actions>(initiator: StoreInitiator<P, S, A>) => Store<P, S, A>;
26
+ export {};
package/dist/text.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { PotokElement } from './types';
2
+ export type LibTextProps = {
3
+ text: unknown;
4
+ };
5
+ export declare function text(props: LibTextProps): PotokElement;
@@ -0,0 +1,39 @@
1
+ import { LibBlock } from './block';
2
+ import { LibHTMLElementProps } from './html-element';
3
+ import { LibHTMLElementEventMap, LibHTMLElementTagNameMap } from './prop-types';
4
+ import { LibTextProps } from './text';
5
+ export type LibProps = Record<string, any>;
6
+ export type LibTextNode = {
7
+ type: 'text';
8
+ context: LibContext;
9
+ props: LibTextProps;
10
+ };
11
+ export type LibHtmlElementNode<Tag extends keyof LibHTMLElementTagNameMap = keyof LibHTMLElementTagNameMap> = {
12
+ type: 'html-element';
13
+ context: LibContext;
14
+ props: LibHTMLElementProps<Tag>;
15
+ };
16
+ export type LibNode = LibTextNode | LibHtmlElementNode;
17
+ export type LibContext = {
18
+ parentBlock: LibBlock | null;
19
+ index: number;
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
+ removeNode(node: LibNode): void;
24
+ portals: Record<string, WithChildren<{}>['children']>;
25
+ contexts: Record<symbol, Record<string, unknown>>;
26
+ listeners: Record<keyof LibHTMLElementEventMap, Map<HTMLElement, LibHTMLElementEventMap[keyof LibHTMLElementEventMap]>>;
27
+ isServer: boolean;
28
+ promises: Promise<unknown>[];
29
+ isHydrating: boolean;
30
+ };
31
+ export type PotokElement = (context: LibContext) => LibBlock;
32
+ export type MaybeArray<T> = T | T[];
33
+ export type Child = PotokElement | Child[] | string | number | null | undefined;
34
+ export type Children = MaybeArray<Child> | undefined;
35
+ export type WithChildren<Props extends Record<string, unknown>> = Props & {
36
+ children?: Children;
37
+ };
38
+ export type ComponentProps = Record<string, unknown>;
39
+ export type Component<Props extends ComponentProps = ComponentProps> = (props: Props) => PotokElement;
@@ -0,0 +1,345 @@
1
+ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), __copyProps = (e, i, o, s) => {
2
+ if (i && typeof i == "object" || typeof i == "function") for (var c = __getOwnPropNames(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !__hasOwnProp.call(e, d) && d !== o && __defProp(e, d, {
3
+ get: ((e) => i[e]).bind(null, d),
4
+ enumerable: !(s = __getOwnPropDesc(i, d)) || s.enumerable
5
+ });
6
+ return e;
7
+ }, __toESM = (n, r, a) => (a = n == null ? {} : __create(__getProtoOf(n)), __copyProps(r || !n || !n.__esModule ? __defProp(a, "default", {
8
+ value: n,
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 {
49
+ component;
50
+ subscribers;
51
+ cachedInstances;
52
+ constructor(e) {
53
+ this.component = e, this.subscribers = /* @__PURE__ */ new Set(), this.cachedInstances = /* @__PURE__ */ new Map();
54
+ }
55
+ getCachedInstance(e) {
56
+ return this.cachedInstances.get(e);
57
+ }
58
+ addCachedInstance(e, t, n) {
59
+ this.cachedInstances.set(e, {
60
+ isRemovable: !1,
61
+ element: t,
62
+ states: n
63
+ });
64
+ }
65
+ markInstanceAsRemovable(e) {
66
+ let t = this.cachedInstances.get(e);
67
+ t && (t.isRemovable = !0);
68
+ }
69
+ unmarkInstanceAsRemovable(e) {
70
+ let t = this.cachedInstances.get(e);
71
+ t && (t.isRemovable = !1);
72
+ }
73
+ removeCachedInstance(e) {
74
+ this.cachedInstances.delete(e);
75
+ }
76
+ };
77
+ const HMR_DEV = {
78
+ registry: new class {
79
+ components = /* @__PURE__ */ new Map();
80
+ getModuleComponentsMap(e) {
81
+ return this.components.has(e) || this.components.set(e, /* @__PURE__ */ new Map()), this.components.get(e);
82
+ }
83
+ addComponent(e, t, n) {
84
+ let r = this.getModuleComponentsMap(e);
85
+ r.has(t) || r.set(t, new RegisteredComponent(n));
86
+ let i = r.get(t);
87
+ return i.component = n, i;
88
+ }
89
+ getRegisteredComponent(e, t) {
90
+ return this.getModuleComponentsMap(e).get(t);
91
+ }
92
+ subscribeToComponent(e, t, n) {
93
+ return this.getRegisteredComponent(e, t)?.subscribers.add(n), () => {
94
+ this.unsubscribeFromComponent(e, t, n);
95
+ };
96
+ }
97
+ unsubscribeFromComponent(e, t, n) {
98
+ this.getRegisteredComponent(e, t)?.subscribers.delete(n);
99
+ }
100
+ notifyComponentUpdate(e, t) {
101
+ let n = this.getRegisteredComponent(e, t);
102
+ if (n) for (let e of n.subscribers) e(n);
103
+ }
104
+ }(),
105
+ currentInstance: null
106
+ };
107
+ function isWindowDefined() {
108
+ return typeof window < "u";
109
+ }
110
+ function getComponentInstanceId(e) {
111
+ let t = [], n = e;
112
+ for (; n;) t.push(n.index), n = n.parentBlock ? n.parentBlock.context : null;
113
+ return t.reverse().join("_");
114
+ }
115
+ function klona(e) {
116
+ if (typeof e != "object") return e;
117
+ var t, n, r = Object.prototype.toString.call(e);
118
+ if (r === "[object Object]") {
119
+ if (e.constructor !== Object && typeof e.constructor == "function") for (t in n = new e.constructor(), e) e.hasOwnProperty(t) && n[t] !== e[t] && (n[t] = klona(e[t]));
120
+ else for (t in n = {}, e) t === "__proto__" ? Object.defineProperty(n, t, {
121
+ value: klona(e[t]),
122
+ configurable: !0,
123
+ enumerable: !0,
124
+ writable: !0
125
+ }) : n[t] = klona(e[t]);
126
+ return n;
127
+ }
128
+ if (r === "[object Array]") {
129
+ for (t = e.length, n = Array(t); t--;) n[t] = klona(e[t]);
130
+ return n;
131
+ }
132
+ return r === "[object Set]" ? (n = /* @__PURE__ */ new Set(), e.forEach(function(e) {
133
+ n.add(klona(e));
134
+ }), n) : r === "[object Map]" ? (n = /* @__PURE__ */ new Map(), e.forEach(function(e, t) {
135
+ n.set(klona(t), klona(e));
136
+ }), n) : r === "[object Date]" ? /* @__PURE__ */ new Date(+e) : r === "[object RegExp]" ? (n = new RegExp(e.source, e.flags), n.lastIndex = e.lastIndex, n) : r === "[object DataView]" ? new e.constructor(klona(e.buffer)) : r === "[object ArrayBuffer]" ? e.slice(0) : r.slice(-6) === "Array]" ? new e.constructor(e) : e;
137
+ }
138
+ var import_fast_deep_equal = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((e, t) => {
139
+ t.exports = function e(t, n) {
140
+ if (t === n) return !0;
141
+ if (t && n && typeof t == "object" && typeof n == "object") {
142
+ if (t.constructor !== n.constructor) return !1;
143
+ var r, i, a;
144
+ if (Array.isArray(t)) {
145
+ if (r = t.length, r != n.length) return !1;
146
+ for (i = r; i-- !== 0;) if (!e(t[i], n[i])) return !1;
147
+ return !0;
148
+ }
149
+ if (t.constructor === RegExp) return t.source === n.source && t.flags === n.flags;
150
+ if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === n.valueOf();
151
+ if (t.toString !== Object.prototype.toString) return t.toString() === n.toString();
152
+ if (a = Object.keys(t), r = a.length, r !== Object.keys(n).length) return !1;
153
+ for (i = r; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(n, a[i])) return !1;
154
+ for (i = r; i-- !== 0;) {
155
+ var o = a[i];
156
+ if (!e(t[o], n[o])) return !1;
157
+ }
158
+ return !0;
159
+ }
160
+ return t !== t && n !== n;
161
+ };
162
+ })))()), currentEffect = null, currentBatch = null, currentDisposer = null, VALUE_SIGNAL_SYMBOL = Symbol("VALUE_SIGNAL"), ANY_KEY_SYMBOL = Symbol("ANY_KEY");
163
+ function getSignal(e) {
164
+ return e[VALUE_SIGNAL_SYMBOL];
165
+ }
166
+ function isSignal(e) {
167
+ return getSignal(e) !== void 0;
168
+ }
169
+ function canBeSignal(e) {
170
+ return typeof e == "object" && !!e && (Array.isArray(e) || Object.getPrototypeOf(e).isPrototypeOf(Object));
171
+ }
172
+ function createSignal(e) {
173
+ if (process.env.NODE_ENV === "development" && isWindowDefined()) {
174
+ let t = HMR_DEV.currentInstance;
175
+ if (t) if (t.stateIndex < t.states.length) {
176
+ let n = t.states[t.stateIndex];
177
+ for (; !(0, import_fast_deep_equal.default)(n?.initial, e) && (t.states.splice(t.stateIndex, 1), n = t.states[t.stateIndex], n););
178
+ if (n) {
179
+ let e = getSignal(n.current);
180
+ if (e) return t.stateIndex++, e.proxy;
181
+ } else t.states.push({
182
+ current: e,
183
+ initial: klona(e)
184
+ }), t.stateIndex++;
185
+ } else t.states.push({
186
+ current: e,
187
+ initial: klona(e)
188
+ }), t.stateIndex++;
189
+ }
190
+ let t = getSignal(e);
191
+ if (t) return t.proxy;
192
+ let n = {
193
+ value: e,
194
+ proxy: new Proxy(e, {
195
+ get(e, t, r) {
196
+ if (t === VALUE_SIGNAL_SYMBOL) return n;
197
+ let i = Reflect.get(e, t, r);
198
+ return currentEffect && n.subscribe(currentEffect, t), canBeSignal(i) ? createSignal(i) : typeof i == "function" ? i.bind(e) : i;
199
+ },
200
+ set(e, t, r, i) {
201
+ let a = Reflect.set(e, t, r, i);
202
+ return a && n.subscribers.forEach((e) => {
203
+ let r = e.subscriptions.get(n);
204
+ (e.ignoreVersion || r?.get(ANY_KEY_SYMBOL) === e.version || r?.get(t) === e.version) && e.runCallback();
205
+ }), a;
206
+ }
207
+ }),
208
+ subscribers: /* @__PURE__ */ new Set(),
209
+ subscribe(e, t) {
210
+ let r = e.subscriptions.get(n);
211
+ r || (r = /* @__PURE__ */ new Map(), e.subscriptions.set(n, r), n.subscribers.add(e)), r.get(t) !== e.version && r.set(t, e.version);
212
+ }
213
+ };
214
+ return Object.defineProperty(e, VALUE_SIGNAL_SYMBOL, {
215
+ value: n,
216
+ enumerable: !1,
217
+ writable: !1,
218
+ configurable: !1
219
+ }), n.proxy;
220
+ }
221
+ function createEffect(e, t = !1) {
222
+ let n = !1, r = {
223
+ callback: e,
224
+ subscriptions: /* @__PURE__ */ new Map(),
225
+ version: 0,
226
+ ignoreVersion: t,
227
+ dispose() {
228
+ n = !0;
229
+ },
230
+ runCallback() {
231
+ if (n) {
232
+ r.subscriptions.forEach((e, t) => {
233
+ t.subscribers.delete(r);
234
+ }), r.subscriptions.clear();
235
+ return;
236
+ }
237
+ if (currentBatch) {
238
+ currentBatch.add(r);
239
+ return;
240
+ }
241
+ currentEffect = r, r.version++, e(), currentEffect = null;
242
+ }
243
+ };
244
+ return currentDisposer && currentDisposer.effects.add(r), r.runCallback(), r;
245
+ }
246
+ function batch(e) {
247
+ if (currentBatch) return e();
248
+ currentBatch = /* @__PURE__ */ new Set();
249
+ let t = e(), n = currentBatch;
250
+ return currentBatch = null, n.forEach((e) => {
251
+ e.runCallback();
252
+ }), t;
253
+ }
254
+ function untrack(e) {
255
+ let t = currentEffect;
256
+ currentEffect = null;
257
+ let n = e();
258
+ return currentEffect = t, n;
259
+ }
260
+ function _deepTrack(e, t, n = 0) {
261
+ if (t !== void 0 && t <= 0) {
262
+ console.warn(`depth=${t} не может быть меньше или равен 0`);
263
+ return;
264
+ }
265
+ if (!currentEffect) {
266
+ console.warn("deepTrack можно использовать только внутри эффекта");
267
+ return;
268
+ }
269
+ let r = currentEffect;
270
+ untrack(() => {
271
+ let i = getSignal(e);
272
+ if (!i) {
273
+ console.warn("deepTrack можно использовать только с сигналами");
274
+ return;
275
+ }
276
+ if (i.subscribe(r, ANY_KEY_SYMBOL), n++, !(t !== void 0 && n >= t)) if (Array.isArray(e)) for (let i = 0; i < e.length; i++) {
277
+ let a = e[i];
278
+ canBeSignal(a) && (currentEffect = r, _deepTrack(a, t, n));
279
+ }
280
+ else for (let i in e) {
281
+ let a = e[i];
282
+ canBeSignal(a) && (currentEffect = r, _deepTrack(a, t, n));
283
+ }
284
+ });
285
+ }
286
+ function deepTrack(e, t) {
287
+ _deepTrack(e, t);
288
+ }
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
328
+ };
329
+ }
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 };
@@ -0,0 +1,11 @@
1
+ import { LibHTMLElementEventMap, LibHTMLElementTagNameMap } from './prop-types';
2
+ 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;
4
+ export declare function objectKeys<Obj extends Record<string, unknown>>(obj: Obj): (keyof Obj)[];
5
+ export declare function extractListenersFromProps(props: LibHTMLElementTagNameMap[keyof LibHTMLElementTagNameMap]): LibHTMLElementEventMap;
6
+ export declare function map<T extends string | number | symbol, K>(field: T, mapObject: Record<T, K>): K;
7
+ 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;
9
+ export declare function normalizeArray<T>(array: MaybeArray<T>): T[];
10
+ export declare function normalizeChild(child: NonNullable<Child>): PotokElement[];
11
+ 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.1.0",
3
+ "version": "0.3.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.mjs",
@@ -21,9 +21,14 @@
21
21
  "import": "./dist/hmr.mjs"
22
22
  }
23
23
  },
24
+ "files": [
25
+ "dist",
26
+ "package.json"
27
+ ],
24
28
  "scripts": {
25
29
  "build": "vite build",
26
- "build:watch": "vite build --watch"
30
+ "build:watch": "vite build --watch",
31
+ "prepublishOnly": "bun run build"
27
32
  },
28
33
  "devDependencies": {
29
34
  "@types/bun": "catalog:",
@@ -31,7 +36,8 @@
31
36
  "fetch-to-node": "^2.1.0",
32
37
  "klona": "^2.0.6",
33
38
  "vite": "catalog:",
34
- "vite-plugin-dts": "catalog:"
39
+ "vite-plugin-dts": "catalog:",
40
+ "@potok-web-framework/vite-plugin": "workspace:*"
35
41
  },
36
42
  "peerDependencies": {
37
43
  "typescript": "catalog:"
package/CHANGELOG.md DELETED
@@ -1,7 +0,0 @@
1
- # @potok-web-framework/core
2
-
3
- ## 0.1.0
4
-
5
- ### Minor Changes
6
-
7
- - 1bd95c1: Релиз фреймворка
package/bun.lock DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "lockfileVersion": 1,
3
- "workspaces": {
4
- "": {
5
- "name": "web-framework",
6
- "devDependencies": {
7
- "@types/bun": "latest",
8
- },
9
- "peerDependencies": {
10
- "typescript": "^5",
11
- },
12
- },
13
- },
14
- "packages": {
15
- "@types/bun": ["@types/bun@1.2.17", "", { "dependencies": { "bun-types": "1.2.17" } }, "sha512-l/BYs/JYt+cXA/0+wUhulYJB6a6p//GTPiJ7nV+QHa8iiId4HZmnu/3J/SowP5g0rTiERY2kfGKXEK5Ehltx4Q=="],
16
-
17
- "@types/node": ["@types/node@24.0.3", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-R4I/kzCYAdRLzfiCabn9hxWfbuHS573x+r0dJMkkzThEa7pbrcDWK+9zu3e7aBOouf+rQAciqPFMnxwr0aWgKg=="],
18
-
19
- "bun-types": ["bun-types@1.2.17", "", { "dependencies": { "@types/node": "*" } }, "sha512-ElC7ItwT3SCQwYZDYoAH+q6KT4Fxjl8DtZ6qDulUFBmXA8YB4xo+l54J9ZJN+k2pphfn9vk7kfubeSd5QfTVJQ=="],
20
-
21
- "typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],
22
-
23
- "undici-types": ["undici-types@7.8.0", "", {}, "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw=="],
24
- }
25
- }
package/src/block.ts DELETED
@@ -1,102 +0,0 @@
1
- import type { Effect } from './signals'
2
- import type { LibContext, LibHtmlElementNode, LibNode, LibProps } from './types'
3
-
4
- export abstract class LibBlock {
5
- node: LibNode | null = null
6
- abstract context: LibContext
7
- abstract props: LibProps
8
- effects: Effect[] = []
9
- children: (LibBlock | null)[] = []
10
-
11
- get nearestParentElement(): LibHtmlElementNode | null {
12
- return (
13
- (this.node as LibHtmlElementNode) ??
14
- this.context.parentBlock?.nearestParentElement ??
15
- null
16
- )
17
- }
18
-
19
- get previousBlock(): LibBlock | null {
20
- const parentBlock = this.context.parentBlock
21
-
22
- if (!parentBlock) {
23
- return null
24
- }
25
-
26
- const previousBlock = parentBlock.children[this.context.index - 1]
27
-
28
- if (previousBlock) {
29
- return previousBlock
30
- }
31
-
32
- if (!parentBlock.node) {
33
- return parentBlock.previousBlock
34
- }
35
-
36
- return null
37
- }
38
-
39
- get nearestPreviousNode(): LibNode | null {
40
- if (this.node) {
41
- return this.node
42
- }
43
-
44
- const lastChild = this.children[this.children.length - 1]
45
- if (lastChild) {
46
- return lastChild.nearestPreviousNode
47
- }
48
-
49
- const previousBlock = this.previousBlock
50
- if (previousBlock) {
51
- return previousBlock.nearestPreviousNode
52
- }
53
-
54
- return null
55
- }
56
-
57
- get previousNode(): LibNode | null {
58
- const previousBlock = this.previousBlock
59
-
60
- if (previousBlock) {
61
- return previousBlock.nearestPreviousNode
62
- }
63
-
64
- return null
65
- }
66
-
67
- addEffect(effect: Effect) {
68
- this.effects.push(effect)
69
- }
70
-
71
- unmountChildren() {
72
- this.children.forEach((childBlock) => {
73
- childBlock?.unmount()
74
- })
75
- this.children = []
76
- }
77
-
78
- insertNode() {
79
- if (!this.node) {
80
- return
81
- }
82
-
83
- this.context.insertNode(
84
- this.context.parentBlock?.nearestParentElement ?? null,
85
- this.node,
86
- this.previousNode,
87
- )
88
- }
89
-
90
- unmount() {
91
- if (this.node) {
92
- this.context.removeNode(this.node)
93
- }
94
-
95
- this.unmountChildren()
96
-
97
- this.effects.forEach((effect) => {
98
- effect.dispose()
99
- })
100
- this.effects = []
101
- }
102
- }