@unsetsoft/ryunixjs 0.4.13-nightly.5 → 0.4.14
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/Ryunix.js +35 -7
- package/dist/cj/Ryunix.js +702 -0
- package/package.json +21 -7
- package/src/lib/commits.ts +69 -0
- package/src/lib/components.ts +33 -0
- package/src/lib/createElement.ts +61 -0
- package/src/lib/dom.js +12 -1
- package/src/lib/dom.ts +85 -0
- package/src/lib/effects.ts +55 -0
- package/src/lib/hooks.js +5 -0
- package/src/lib/hooks.ts +80 -0
- package/src/lib/index.ts +23 -0
- package/src/lib/navigation.js +13 -6
- package/src/lib/navigation.ts +74 -0
- package/src/lib/reconciler.ts +62 -0
- package/src/lib/render.ts +33 -0
- package/src/lib/workers.ts +60 -0
- package/src/main.ts +12 -0
- package/src/utils/index.js +7 -2
- package/src/utils/index.ts +32 -0
package/dist/Ryunix.js
CHANGED
|
@@ -24,9 +24,14 @@
|
|
|
24
24
|
const STRINGS = Object.freeze({
|
|
25
25
|
object: 'object',
|
|
26
26
|
function: 'function',
|
|
27
|
+
style: 'ryunix-style',
|
|
28
|
+
className: 'ryunix-class',
|
|
29
|
+
children: 'children',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const OLD_STRINGS = Object.freeze({
|
|
27
33
|
style: 'style',
|
|
28
34
|
className: 'className',
|
|
29
|
-
children: 'children',
|
|
30
35
|
});
|
|
31
36
|
|
|
32
37
|
const EFFECT_TAGS = Object.freeze({
|
|
@@ -240,6 +245,11 @@
|
|
|
240
245
|
vars.hookIndex++;
|
|
241
246
|
};
|
|
242
247
|
|
|
248
|
+
/**
|
|
249
|
+
* The `useQuery` function is a custom hook in JavaScript that retrieves query parameters from the URL
|
|
250
|
+
* and stores them in a hook for easy access.
|
|
251
|
+
* @returns The `useQuery` function returns the `query` property of the `hook` object.
|
|
252
|
+
*/
|
|
243
253
|
const useQuery = () => {
|
|
244
254
|
vars.hookIndex++;
|
|
245
255
|
|
|
@@ -264,7 +274,7 @@
|
|
|
264
274
|
return hook.query
|
|
265
275
|
};
|
|
266
276
|
|
|
267
|
-
const Router = ({ path, component }) => {
|
|
277
|
+
const Router = ({ path, component, children }) => {
|
|
268
278
|
const [currentPath, setCurrentPath] = useStore(window.location.pathname);
|
|
269
279
|
|
|
270
280
|
useEffect(() => {
|
|
@@ -277,13 +287,15 @@
|
|
|
277
287
|
window.addEventListener('popstate', onLocationChange);
|
|
278
288
|
|
|
279
289
|
return () => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
290
|
+
setTimeout(() => {
|
|
291
|
+
window.removeEventListener('navigate', onLocationChange);
|
|
292
|
+
window.removeEventListener('pushsatate', onLocationChange);
|
|
293
|
+
window.removeEventListener('popstate', onLocationChange);
|
|
294
|
+
}, 100);
|
|
283
295
|
}
|
|
284
296
|
}, [currentPath]);
|
|
285
297
|
|
|
286
|
-
return currentPath === path
|
|
298
|
+
return currentPath === path ? component() : null
|
|
287
299
|
};
|
|
288
300
|
|
|
289
301
|
const Navigate = () => {
|
|
@@ -301,8 +313,9 @@
|
|
|
301
313
|
*/
|
|
302
314
|
const push = (to, state = {}) => {
|
|
303
315
|
if (window.location.pathname === to) return
|
|
316
|
+
|
|
304
317
|
window.history.pushState(state, '', to);
|
|
305
|
-
const navigationEvent = new
|
|
318
|
+
const navigationEvent = new PopStateEvent('popstate');
|
|
306
319
|
window.dispatchEvent(navigationEvent);
|
|
307
320
|
};
|
|
308
321
|
|
|
@@ -329,6 +342,10 @@
|
|
|
329
342
|
throw new Error("Missig 'to' param.")
|
|
330
343
|
}
|
|
331
344
|
const preventReload = (event) => {
|
|
345
|
+
if (event.metaKey || event.ctrlKey) {
|
|
346
|
+
return
|
|
347
|
+
}
|
|
348
|
+
|
|
332
349
|
event.preventDefault();
|
|
333
350
|
const { push } = Navigate();
|
|
334
351
|
push(props.to);
|
|
@@ -394,11 +411,22 @@
|
|
|
394
411
|
.filter(isNew(prevProps, nextProps))
|
|
395
412
|
.forEach((name) => {
|
|
396
413
|
if (name === STRINGS.style) {
|
|
414
|
+
DomStyle(dom, nextProps['ryunix-style']);
|
|
415
|
+
} else if (name === OLD_STRINGS.style) {
|
|
397
416
|
DomStyle(dom, nextProps.style);
|
|
398
417
|
} else if (name === STRINGS.className) {
|
|
418
|
+
if (nextProps['ryunix-class'] === '') {
|
|
419
|
+
throw new Error('data-class cannot be empty.')
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
prevProps['ryunix-class'] &&
|
|
423
|
+
dom.classList.remove(...prevProps['ryunix-class'].split(/\s+/));
|
|
424
|
+
dom.classList.add(...nextProps['ryunix-class'].split(/\s+/));
|
|
425
|
+
} else if (name === OLD_STRINGS.className) {
|
|
399
426
|
if (nextProps.className === '') {
|
|
400
427
|
throw new Error('className cannot be empty.')
|
|
401
428
|
}
|
|
429
|
+
|
|
402
430
|
prevProps.className &&
|
|
403
431
|
dom.classList.remove(...prevProps.className.split(/\s+/));
|
|
404
432
|
dom.classList.add(...nextProps.className.split(/\s+/));
|