veles 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-V3EV7UG6.js → chunk-ILNLS6QO.js} +14 -11
- package/dist/chunk-MH6DPZ3V.js +490 -0
- package/dist/chunk-X6QYYW56.js +15 -0
- package/dist/create-state-Bo6TT4qP.d.ts +33 -0
- package/dist/create-state-D1JASFVs.d.cts +33 -0
- package/dist/fragment-CU26z590.d.cts +9 -0
- package/dist/fragment-IVSEC7-Q.d.ts +9 -0
- package/dist/index.cjs +318 -235
- package/dist/index.d.cts +4 -45
- package/dist/index.d.ts +4 -45
- package/dist/index.js +7 -407
- package/dist/jsx-runtime.cjs +1 -1
- package/dist/jsx-runtime.d.cts +2 -2
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js +4 -2
- package/dist/{fragment-CHmQ0MhU.d.cts → types.d-DgVBp6oa.d.cts} +1 -7
- package/dist/{fragment-CHmQ0MhU.d.ts → types.d-DgVBp6oa.d.ts} +1 -7
- package/dist/utils/index.cjs +814 -0
- package/dist/utils/index.d.cts +18 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.js +37 -0
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,12 @@
|
|
|
1
|
-
import { V as VelesElement, a as VelesComponent
|
|
2
|
-
export { F as Fragment, c as createElement } from './fragment-
|
|
1
|
+
import { V as VelesElement, a as VelesComponent } from './types.d-DgVBp6oa.js';
|
|
2
|
+
export { F as Fragment, c as createElement } from './fragment-IVSEC7-Q.js';
|
|
3
|
+
export { S as State, c as createState } from './create-state-Bo6TT4qP.js';
|
|
3
4
|
|
|
4
5
|
declare function attachComponent({ htmlElement, component, }: {
|
|
5
6
|
htmlElement: HTMLElement;
|
|
6
7
|
component: VelesElement | VelesComponent;
|
|
7
8
|
}): () => void;
|
|
8
9
|
|
|
9
|
-
type State<ValueType> = {
|
|
10
|
-
trackValue(cb: (value: ValueType) => void | Function, options?: {
|
|
11
|
-
callOnMount?: boolean;
|
|
12
|
-
skipFirstCall?: boolean;
|
|
13
|
-
comparator?: (value1: ValueType, value2: ValueType) => boolean;
|
|
14
|
-
}): void;
|
|
15
|
-
trackValueSelector<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, cb: (value: SelectorValueType) => void | Function, options?: {
|
|
16
|
-
callOnMount?: boolean;
|
|
17
|
-
skipFirstCall?: boolean;
|
|
18
|
-
comparator?: (value1: SelectorValueType, value2: SelectorValueType) => boolean;
|
|
19
|
-
}): void;
|
|
20
|
-
useValue(cb?: (value: ValueType) => VelesElement | VelesComponent | string | undefined | null, comparator?: (value1: ValueType, value2: ValueType) => boolean): VelesElement | VelesComponent | VelesStringElement;
|
|
21
|
-
useValueSelector<SelectorValueType>(selector: (value: ValueType) => SelectorValueType, cb?: (value: SelectorValueType) => VelesElement | VelesComponent | string | undefined | null, comparator?: (value1: SelectorValueType, value2: SelectorValueType) => boolean): VelesElement | VelesComponent | VelesStringElement;
|
|
22
|
-
useAttribute(cb?: (value: ValueType) => any): AttributeHelper<any>;
|
|
23
|
-
useValueIterator<Element>(options: {
|
|
24
|
-
key: string | ((options: {
|
|
25
|
-
element: Element;
|
|
26
|
-
index: number;
|
|
27
|
-
}) => string);
|
|
28
|
-
selector?: (value: ValueType) => Element[];
|
|
29
|
-
}, cb: (props: {
|
|
30
|
-
elementState: State<Element>;
|
|
31
|
-
index: number;
|
|
32
|
-
}) => VelesElement | VelesComponent): VelesComponent | VelesElement | null;
|
|
33
|
-
getValue(): ValueType;
|
|
34
|
-
getPreviousValue(): undefined | ValueType;
|
|
35
|
-
setValue(newValueCB: ((currentValue: ValueType) => ValueType) | ValueType): void;
|
|
36
|
-
_triggerUpdates(): void;
|
|
37
|
-
};
|
|
38
|
-
declare function createState<T>(initialValue: T, subscribeCallback?: (setValue: ReturnType<typeof createState<T>>["setValue"]) => Function): State<T>;
|
|
39
|
-
|
|
40
|
-
type createdState<StateType> = ReturnType<typeof createState<StateType>>;
|
|
41
|
-
declare function combineState<A, B>(state1: createdState<A>, state2: createdState<B>): createdState<[A, B]>;
|
|
42
|
-
declare function combineState<A, B, C>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>): createdState<[A, B, C]>;
|
|
43
|
-
declare function combineState<A, B, C, D>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>): createdState<[A, B, C, D]>;
|
|
44
|
-
declare function combineState<A, B, C, D, E>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>): createdState<[A, B, C, D, E]>;
|
|
45
|
-
declare function combineState<A, B, C, D, E, F>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>): createdState<[A, B, C, D, E, F]>;
|
|
46
|
-
declare function combineState<A, B, C, D, E, F, G>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>): createdState<[A, B, C, D, E, F, G]>;
|
|
47
|
-
declare function combineState<A, B, C, D, E, F, G, H>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>, state8: createdState<H>): createdState<[A, B, C, D, E, F, G, H]>;
|
|
48
|
-
declare function combineState<A, B, C, D, E, F, G, H, I>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>, state8: createdState<H>, state9: createdState<I>): createdState<[A, B, C, D, E, F, G, H, I]>;
|
|
49
|
-
declare function combineState<A, B, C, D, E, F, G, H, I, J>(state1: createdState<A>, state2: createdState<B>, state3: createdState<C>, state4: createdState<D>, state5: createdState<E>, state6: createdState<F>, state7: createdState<G>, state8: createdState<H>, state9: createdState<I>, state10: createdState<J>): createdState<[A, B, C, D, E, F, G, H, I, J]>;
|
|
50
|
-
|
|
51
10
|
declare function onMount(cb: () => void | Function): void;
|
|
52
11
|
declare function onUnmount(cb: Function): void;
|
|
53
12
|
|
|
@@ -56,4 +15,4 @@ declare function createRef<T>(initialRefValue?: T | null): {
|
|
|
56
15
|
current: T | null;
|
|
57
16
|
};
|
|
58
17
|
|
|
59
|
-
export {
|
|
18
|
+
export { attachComponent, createRef, onMount, onUnmount };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Fragment
|
|
2
|
+
Fragment
|
|
3
|
+
} from "./chunk-X6QYYW56.js";
|
|
4
|
+
import {
|
|
5
|
+
createState
|
|
6
|
+
} from "./chunk-MH6DPZ3V.js";
|
|
7
|
+
import {
|
|
3
8
|
callMountHandlers,
|
|
4
9
|
createElement,
|
|
5
10
|
getComponentVelesNode,
|
|
6
|
-
identity,
|
|
7
11
|
onMount,
|
|
8
12
|
onUnmount
|
|
9
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ILNLS6QO.js";
|
|
10
14
|
|
|
11
15
|
// src/attach-component.ts
|
|
12
16
|
function attachComponent({
|
|
@@ -22,409 +26,6 @@ function attachComponent({
|
|
|
22
26
|
};
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
// src/create-element/create-text-element.ts
|
|
26
|
-
function createTextElement(text) {
|
|
27
|
-
const unmountHandlers = [];
|
|
28
|
-
return {
|
|
29
|
-
velesStringElement: true,
|
|
30
|
-
// in case there is no text, we create an empty Text node, so we still can
|
|
31
|
-
// have a reference to it, replace it, call lifecycle methods, etc
|
|
32
|
-
html: document.createTextNode(text || ""),
|
|
33
|
-
_privateMethods: {
|
|
34
|
-
_addUnmountHandler: (cb) => {
|
|
35
|
-
unmountHandlers.push(cb);
|
|
36
|
-
},
|
|
37
|
-
_callUnmountHandlers: () => {
|
|
38
|
-
unmountHandlers.forEach((cb) => cb());
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/hooks/create-state.ts
|
|
45
|
-
function createState(initialValue, subscribeCallback) {
|
|
46
|
-
let value = initialValue;
|
|
47
|
-
let previousValue = void 0;
|
|
48
|
-
let trackingEffects = [];
|
|
49
|
-
let trackingSelectorElements = [];
|
|
50
|
-
let trackingAttributes = [];
|
|
51
|
-
let trackingIterators = [];
|
|
52
|
-
const result = {
|
|
53
|
-
// supposed to be used at the component level
|
|
54
|
-
trackValue: (cb, options = {}) => {
|
|
55
|
-
result.trackValueSelector(void 0, cb, options);
|
|
56
|
-
},
|
|
57
|
-
trackValueSelector(selector, cb, options = {}) {
|
|
58
|
-
const trackedValue = selector ? selector(value) : value;
|
|
59
|
-
trackingEffects.push({
|
|
60
|
-
cb,
|
|
61
|
-
selector,
|
|
62
|
-
comparator: options.comparator,
|
|
63
|
-
selectedValue: trackedValue
|
|
64
|
-
});
|
|
65
|
-
if (!options.skipFirstCall) {
|
|
66
|
-
if (options.callOnMount) {
|
|
67
|
-
onMount(() => {
|
|
68
|
-
cb(trackedValue);
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
cb(trackedValue);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
onUnmount(() => {
|
|
75
|
-
trackingEffects = trackingEffects.filter(
|
|
76
|
-
(trackingCallback) => trackingCallback.cb !== cb
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
useValue: (cb, comparator) => {
|
|
81
|
-
return result.useValueSelector(void 0, cb, comparator);
|
|
82
|
-
},
|
|
83
|
-
useValueSelector(selector, cb, comparator = identity) {
|
|
84
|
-
const selectedValue = selector ? selector(value) : value;
|
|
85
|
-
const returnedNode = cb ? cb(selectedValue) : String(selectedValue);
|
|
86
|
-
const node = !returnedNode || typeof returnedNode === "string" ? createTextElement(returnedNode) : returnedNode;
|
|
87
|
-
const trackingSelectorElement = {
|
|
88
|
-
selector,
|
|
89
|
-
selectedValue,
|
|
90
|
-
cb,
|
|
91
|
-
node,
|
|
92
|
-
comparator
|
|
93
|
-
};
|
|
94
|
-
trackingSelectorElements.push(trackingSelectorElement);
|
|
95
|
-
node._privateMethods._addUnmountHandler(() => {
|
|
96
|
-
trackingSelectorElements = trackingSelectorElements.filter(
|
|
97
|
-
(el) => trackingSelectorElement !== el
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
return node;
|
|
101
|
-
},
|
|
102
|
-
useValueIterator(options, cb) {
|
|
103
|
-
const children = [];
|
|
104
|
-
const elementsByKey = {};
|
|
105
|
-
const elements = options.selector ? options.selector(value) : value;
|
|
106
|
-
if (!Array.isArray(elements)) {
|
|
107
|
-
console.error("useValueIterator received non-array value");
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
elements.forEach((element, index) => {
|
|
111
|
-
let calculatedKey = "";
|
|
112
|
-
if (typeof options.key === "string" && typeof element === "object" && element !== null && options.key in element) {
|
|
113
|
-
calculatedKey = element[options.key];
|
|
114
|
-
} else if (typeof options.key === "function") {
|
|
115
|
-
calculatedKey = options.key({ element, index });
|
|
116
|
-
} else {
|
|
117
|
-
}
|
|
118
|
-
const elementState = createState(element);
|
|
119
|
-
if (!calculatedKey) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
let node = cb({ elementState, index });
|
|
123
|
-
elementsByKey[calculatedKey] = {
|
|
124
|
-
node,
|
|
125
|
-
index,
|
|
126
|
-
elementState
|
|
127
|
-
};
|
|
128
|
-
children.push([node, calculatedKey, elementState]);
|
|
129
|
-
});
|
|
130
|
-
const trackingParams = {};
|
|
131
|
-
trackingIterators.push(trackingParams);
|
|
132
|
-
const wrapperComponent = createElement(() => {
|
|
133
|
-
onUnmount(() => {
|
|
134
|
-
trackingIterators = trackingIterators.filter(
|
|
135
|
-
(currentTrackingParams) => currentTrackingParams !== trackingParams
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
return createElement("div", {
|
|
139
|
-
phantom: true,
|
|
140
|
-
children: children.map((child) => child[0])
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
trackingParams.cb = cb;
|
|
144
|
-
trackingParams.key = options.key;
|
|
145
|
-
trackingParams.elementsByKey = elementsByKey;
|
|
146
|
-
trackingParams.renderedElements = children;
|
|
147
|
-
trackingParams.wrapperComponent = wrapperComponent;
|
|
148
|
-
if (options.selector) {
|
|
149
|
-
trackingParams.selector = options.selector;
|
|
150
|
-
}
|
|
151
|
-
return wrapperComponent;
|
|
152
|
-
},
|
|
153
|
-
useAttribute: (cb) => {
|
|
154
|
-
const attributeValue = cb ? cb(value) : value;
|
|
155
|
-
const attributeHelper = (htmlElement, attributeName, node) => {
|
|
156
|
-
const trackingElement = { cb, htmlElement, attributeName };
|
|
157
|
-
trackingAttributes.push(trackingElement);
|
|
158
|
-
node._privateMethods._addUnmountHandler(() => {
|
|
159
|
-
trackingAttributes = trackingAttributes.filter(
|
|
160
|
-
(trackingAttribute) => trackingAttribute !== trackingElement
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
return attributeValue;
|
|
164
|
-
};
|
|
165
|
-
attributeHelper.velesAttribute = true;
|
|
166
|
-
return attributeHelper;
|
|
167
|
-
},
|
|
168
|
-
// useful for stuff like callbacks
|
|
169
|
-
getValue: () => {
|
|
170
|
-
return value;
|
|
171
|
-
},
|
|
172
|
-
getPreviousValue: () => {
|
|
173
|
-
return previousValue;
|
|
174
|
-
},
|
|
175
|
-
// set up new value only through the callback which
|
|
176
|
-
// gives the latest value to ensure no outdated data
|
|
177
|
-
// can be used for the state
|
|
178
|
-
setValue: (newValueCB) => {
|
|
179
|
-
const newValue = (
|
|
180
|
-
// @ts-expect-error
|
|
181
|
-
typeof newValueCB === "function" ? newValueCB(value) : newValueCB
|
|
182
|
-
);
|
|
183
|
-
if (newValue !== value) {
|
|
184
|
-
previousValue = value;
|
|
185
|
-
value = newValue;
|
|
186
|
-
result._triggerUpdates();
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
// TODO: remove it from this object completely
|
|
190
|
-
// and access it from closure
|
|
191
|
-
_triggerUpdates: () => {
|
|
192
|
-
trackingSelectorElements = trackingSelectorElements.map(
|
|
193
|
-
(selectorTrackingElement) => {
|
|
194
|
-
const { selectedValue, selector, cb, node, comparator } = selectorTrackingElement;
|
|
195
|
-
const newSelectedValue = selector ? selector(value) : value;
|
|
196
|
-
if (comparator(selectedValue, newSelectedValue)) {
|
|
197
|
-
return selectorTrackingElement;
|
|
198
|
-
}
|
|
199
|
-
const returnednewNode = cb ? cb(newSelectedValue) : String(newSelectedValue);
|
|
200
|
-
const newNode = !returnednewNode || typeof returnednewNode === "string" ? createTextElement(returnednewNode) : returnednewNode;
|
|
201
|
-
const { velesElementNode: oldVelesElementNode } = getComponentVelesNode(node);
|
|
202
|
-
const { velesElementNode: newVelesElementNode } = getComponentVelesNode(newNode);
|
|
203
|
-
const parentVelesElement = oldVelesElementNode.parentVelesElement;
|
|
204
|
-
const newTrackingSelectorElement = {
|
|
205
|
-
selector,
|
|
206
|
-
selectedValue: newSelectedValue,
|
|
207
|
-
cb,
|
|
208
|
-
node: newNode,
|
|
209
|
-
comparator
|
|
210
|
-
};
|
|
211
|
-
if (parentVelesElement) {
|
|
212
|
-
newVelesElementNode.parentVelesElement = parentVelesElement;
|
|
213
|
-
parentVelesElement.html.replaceChild(
|
|
214
|
-
newVelesElementNode.html,
|
|
215
|
-
oldVelesElementNode.html
|
|
216
|
-
);
|
|
217
|
-
parentVelesElement.childComponents = parentVelesElement.childComponents.map(
|
|
218
|
-
(childComponent) => childComponent === node ? newNode : node
|
|
219
|
-
);
|
|
220
|
-
node._privateMethods._callUnmountHandlers();
|
|
221
|
-
callMountHandlers(newNode);
|
|
222
|
-
newNode._privateMethods._addUnmountHandler(() => {
|
|
223
|
-
trackingSelectorElements = trackingSelectorElements.filter(
|
|
224
|
-
(el) => el !== newTrackingSelectorElement
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
console.log("parent node was not found");
|
|
229
|
-
}
|
|
230
|
-
return newTrackingSelectorElement;
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
trackingAttributes.forEach(({ cb, htmlElement, attributeName }) => {
|
|
234
|
-
const newAttributeValue = cb ? cb(value) : value;
|
|
235
|
-
htmlElement.setAttribute(attributeName, newAttributeValue);
|
|
236
|
-
});
|
|
237
|
-
trackingEffects.forEach((trackingEffect) => {
|
|
238
|
-
const { cb, selectedValue, selector, comparator } = trackingEffect;
|
|
239
|
-
const newSelectedValue = selector ? selector(value) : value;
|
|
240
|
-
if (comparator ? comparator(selectedValue, newSelectedValue) : selectedValue === newSelectedValue) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
cb(newSelectedValue);
|
|
244
|
-
trackingEffect.selectedValue = newSelectedValue;
|
|
245
|
-
});
|
|
246
|
-
trackingIterators.forEach((trackingIterator) => {
|
|
247
|
-
const {
|
|
248
|
-
cb,
|
|
249
|
-
key,
|
|
250
|
-
renderedElements,
|
|
251
|
-
elementsByKey,
|
|
252
|
-
wrapperComponent,
|
|
253
|
-
selector
|
|
254
|
-
} = trackingIterator;
|
|
255
|
-
if (!wrapperComponent) {
|
|
256
|
-
console.error("there is no wrapper component for the iterator");
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const { velesElementNode: wrapperVelesElementNode } = getComponentVelesNode(wrapperComponent);
|
|
260
|
-
const parentVelesElement = wrapperVelesElementNode.parentVelesElement;
|
|
261
|
-
if (!parentVelesElement) {
|
|
262
|
-
console.error(
|
|
263
|
-
"there is no parent Veles node for the iterator wrapper"
|
|
264
|
-
);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
const elements = selector ? selector(value) : value;
|
|
268
|
-
if (Array.isArray(elements)) {
|
|
269
|
-
const newRenderedElements = [];
|
|
270
|
-
const newElementsByKey = {};
|
|
271
|
-
const renderedExistingElements = {};
|
|
272
|
-
elements.forEach((element, index) => {
|
|
273
|
-
let calculatedKey = "";
|
|
274
|
-
if (typeof key === "string" && typeof element === "object" && element !== null && key in element) {
|
|
275
|
-
calculatedKey = element[key];
|
|
276
|
-
} else if (typeof key === "function") {
|
|
277
|
-
calculatedKey = key({ element, index });
|
|
278
|
-
} else {
|
|
279
|
-
}
|
|
280
|
-
if (!calculatedKey) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
const existingElement = elementsByKey[calculatedKey];
|
|
284
|
-
if (existingElement) {
|
|
285
|
-
renderedExistingElements[calculatedKey] = true;
|
|
286
|
-
const currentValue = existingElement.elementState.getValue();
|
|
287
|
-
if (currentValue !== element) {
|
|
288
|
-
existingElement.elementState.setValue(() => element);
|
|
289
|
-
}
|
|
290
|
-
newRenderedElements.push([
|
|
291
|
-
existingElement.node,
|
|
292
|
-
calculatedKey,
|
|
293
|
-
existingElement.elementState
|
|
294
|
-
]);
|
|
295
|
-
newElementsByKey[calculatedKey] = {
|
|
296
|
-
elementState: existingElement.elementState,
|
|
297
|
-
index,
|
|
298
|
-
node: existingElement.node
|
|
299
|
-
};
|
|
300
|
-
} else {
|
|
301
|
-
const elementState = createState(element);
|
|
302
|
-
const node = cb({ elementState, index });
|
|
303
|
-
newRenderedElements.push([node, calculatedKey, elementState]);
|
|
304
|
-
newElementsByKey[calculatedKey] = {
|
|
305
|
-
elementState,
|
|
306
|
-
index,
|
|
307
|
-
node
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
const positioningOffset = {};
|
|
312
|
-
let newElementsCount = 0;
|
|
313
|
-
let offset = 0;
|
|
314
|
-
let currentElement = null;
|
|
315
|
-
newRenderedElements.forEach((newRenderedElement, index) => {
|
|
316
|
-
var _a, _b, _c;
|
|
317
|
-
if (positioningOffset[index]) {
|
|
318
|
-
offset = offset + positioningOffset[index];
|
|
319
|
-
}
|
|
320
|
-
const [newNode, calculatedKey, newState] = newRenderedElement;
|
|
321
|
-
const existingElement = elementsByKey[calculatedKey];
|
|
322
|
-
if (existingElement) {
|
|
323
|
-
const { velesElementNode: existingElementNode } = getComponentVelesNode(existingElement.node);
|
|
324
|
-
if (existingElement.index + offset === index) {
|
|
325
|
-
currentElement = existingElementNode.html;
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (existingElement.index + offset > index) {
|
|
329
|
-
if (currentElement) {
|
|
330
|
-
currentElement.after(existingElementNode.html);
|
|
331
|
-
positioningOffset[existingElement.index + 1] = -1;
|
|
332
|
-
} else {
|
|
333
|
-
const firstRenderedElement = (_a = renderedElements[0]) == null ? void 0 : _a[0];
|
|
334
|
-
if (firstRenderedElement) {
|
|
335
|
-
const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
|
|
336
|
-
firstRenderedVelesNode.html.before(
|
|
337
|
-
existingElementNode.html
|
|
338
|
-
);
|
|
339
|
-
} else {
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
currentElement = existingElementNode.html;
|
|
343
|
-
offset = offset + 1;
|
|
344
|
-
} else {
|
|
345
|
-
if (currentElement) {
|
|
346
|
-
currentElement.after(existingElementNode.html);
|
|
347
|
-
positioningOffset[existingElement.index + 1] = 1;
|
|
348
|
-
} else {
|
|
349
|
-
const firstRenderedElement = (_b = renderedElements[0]) == null ? void 0 : _b[0];
|
|
350
|
-
if (firstRenderedElement) {
|
|
351
|
-
const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
|
|
352
|
-
firstRenderedVelesNode.html.before(
|
|
353
|
-
existingElementNode.html
|
|
354
|
-
);
|
|
355
|
-
} else {
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
currentElement = existingElementNode.html;
|
|
359
|
-
offset = offset - 1;
|
|
360
|
-
}
|
|
361
|
-
} else {
|
|
362
|
-
const { velesElementNode: newNodeVelesElement } = getComponentVelesNode(newNode);
|
|
363
|
-
newNodeVelesElement.parentVelesElement = parentVelesElement;
|
|
364
|
-
if (currentElement) {
|
|
365
|
-
currentElement.after(newNodeVelesElement.html);
|
|
366
|
-
} else {
|
|
367
|
-
const firstRenderedElement = (_c = renderedElements[0]) == null ? void 0 : _c[0];
|
|
368
|
-
if (firstRenderedElement) {
|
|
369
|
-
const { velesElementNode: firstRenderedVelesNode } = getComponentVelesNode(firstRenderedElement);
|
|
370
|
-
firstRenderedVelesNode.html.before(newNodeVelesElement.html);
|
|
371
|
-
} else {
|
|
372
|
-
parentVelesElement.html.prepend(newNodeVelesElement.html);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
offset = offset + 1;
|
|
376
|
-
currentElement = newNodeVelesElement.html;
|
|
377
|
-
newElementsCount = newElementsCount + 1;
|
|
378
|
-
callMountHandlers(newNode);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
if (renderedElements.length === newRenderedElements.length + newElementsCount) {
|
|
382
|
-
} else {
|
|
383
|
-
renderedElements.forEach(([oldNode, calculatedKey]) => {
|
|
384
|
-
if (renderedExistingElements[calculatedKey] === true) {
|
|
385
|
-
return;
|
|
386
|
-
} else {
|
|
387
|
-
const { velesElementNode: oldRenderedVelesNode } = getComponentVelesNode(oldNode);
|
|
388
|
-
oldRenderedVelesNode.html.remove();
|
|
389
|
-
oldNode._privateMethods._callUnmountHandlers();
|
|
390
|
-
if ("velesNode" in wrapperVelesElementNode) {
|
|
391
|
-
wrapperVelesElementNode.childComponents = wrapperVelesElementNode.childComponents.filter(
|
|
392
|
-
(childComponent) => childComponent !== oldNode
|
|
393
|
-
);
|
|
394
|
-
} else {
|
|
395
|
-
throw new Error("Wrapper iterator element is a string");
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
trackingIterator.renderedElements = newRenderedElements;
|
|
401
|
-
trackingIterator.elementsByKey = newElementsByKey;
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
if (subscribeCallback) {
|
|
407
|
-
const unsubscribe = subscribeCallback(result.setValue);
|
|
408
|
-
if (unsubscribe) {
|
|
409
|
-
onUnmount(unsubscribe);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return result;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// src/hooks/combine-state.ts
|
|
416
|
-
function combineState(...states) {
|
|
417
|
-
const initialValue = states.map((state) => state.getValue());
|
|
418
|
-
const combinedState = createState(initialValue);
|
|
419
|
-
states.forEach((state) => {
|
|
420
|
-
state.trackValue(() => {
|
|
421
|
-
const updatedValue = states.map((state2) => state2.getValue());
|
|
422
|
-
combinedState.setValue(updatedValue);
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
return combinedState;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
29
|
// src/create-ref.ts
|
|
429
30
|
function createRef(initialRefValue = null) {
|
|
430
31
|
return {
|
|
@@ -435,7 +36,6 @@ function createRef(initialRefValue = null) {
|
|
|
435
36
|
export {
|
|
436
37
|
Fragment,
|
|
437
38
|
attachComponent,
|
|
438
|
-
combineState,
|
|
439
39
|
createElement,
|
|
440
40
|
createRef,
|
|
441
41
|
createState,
|
package/dist/jsx-runtime.cjs
CHANGED
package/dist/jsx-runtime.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { F as Fragment, c as jsx, c as jsxDEV, c as jsxs } from './fragment-CU26z590.cjs';
|
|
2
|
+
import { A as AttributeHelper, b as VelesChildren } from './types.d-DgVBp6oa.cjs';
|
|
3
3
|
|
|
4
4
|
// pretty much all the credit goes to Preact JSX type definitions
|
|
5
5
|
// https://github.com/preactjs/preact/blob/main/src/jsx.d.ts
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { F as Fragment, c as jsx, c as jsxDEV, c as jsxs } from './fragment-IVSEC7-Q.js';
|
|
2
|
+
import { A as AttributeHelper, b as VelesChildren } from './types.d-DgVBp6oa.js';
|
|
3
3
|
|
|
4
4
|
// pretty much all the credit goes to Preact JSX type definitions
|
|
5
5
|
// https://github.com/preactjs/preact/blob/main/src/jsx.d.ts
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -253,10 +253,4 @@ type AttributeHelper<T> = {
|
|
|
253
253
|
velesAttribute: boolean;
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
declare function Fragment({ children }: {
|
|
259
|
-
children: VelesChildren;
|
|
260
|
-
}): VelesComponent | VelesElement;
|
|
261
|
-
|
|
262
|
-
export { type AttributeHelper as A, Fragment as F, type VelesElement as V, type VelesComponent as a, type VelesStringElement as b, createElement as c, type VelesChildren as d };
|
|
256
|
+
export type { AttributeHelper as A, ComponentFunction as C, VelesElement as V, VelesComponent as a, VelesChildren as b, VelesElementProps as c, VelesStringElement as d };
|
|
@@ -253,10 +253,4 @@ type AttributeHelper<T> = {
|
|
|
253
253
|
velesAttribute: boolean;
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
declare function Fragment({ children }: {
|
|
259
|
-
children: VelesChildren;
|
|
260
|
-
}): VelesComponent | VelesElement;
|
|
261
|
-
|
|
262
|
-
export { type AttributeHelper as A, Fragment as F, type VelesElement as V, type VelesComponent as a, type VelesStringElement as b, createElement as c, type VelesChildren as d };
|
|
256
|
+
export type { AttributeHelper as A, ComponentFunction as C, VelesElement as V, VelesComponent as a, VelesChildren as b, VelesElementProps as c, VelesStringElement as d };
|