@unsetsoft/ryunixjs 0.4.13-nightly.3 → 0.4.13-nightly.30

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 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({
@@ -286,7 +291,30 @@
286
291
  return currentPath === path ? component() : null
287
292
  };
288
293
 
289
- const Navigate = (props) => {
294
+ const Navigate = () => {
295
+ /**
296
+ * The function `push` is used to push a new state to the browser's history and trigger a custom
297
+ * event called 'pushstate'.
298
+ * @param to - The `to` parameter is a string representing the URL path to which you want to
299
+ * navigate.
300
+ * @param [state] - The `state` parameter is an optional object that represents the state associated
301
+ * with the new history entry. It can be used to store any data that you want to associate with the
302
+ * new URL. When you navigate back or forward in the browser history, this state object will be
303
+ * passed to the `popstate
304
+ * @returns The function `push` does not have a return statement, so it returns `undefined` by
305
+ * default.
306
+ */
307
+ const push = (to, state = {}) => {
308
+ if (window.location.pathname === to) return
309
+ window.history.pushState(state, '', to);
310
+ const navigationEvent = new Event('pushsatate');
311
+ window.dispatchEvent(navigationEvent);
312
+ };
313
+
314
+ return { push }
315
+ };
316
+
317
+ const Link = (props) => {
290
318
  if (props.style) {
291
319
  throw new Error(
292
320
  'The style attribute is not supported on internal components, use className.',
@@ -307,11 +335,8 @@
307
335
  }
308
336
  const preventReload = (event) => {
309
337
  event.preventDefault();
310
- if (window.location.pathname !== props.to) {
311
- window.history.pushState({}, '', props.to);
312
- const navigationEvent = new Event('pushsatate');
313
- window.dispatchEvent(navigationEvent);
314
- }
338
+ const { push } = Navigate();
339
+ push(props.to);
315
340
  };
316
341
 
317
342
  const anchor = {
@@ -374,11 +399,22 @@
374
399
  .filter(isNew(prevProps, nextProps))
375
400
  .forEach((name) => {
376
401
  if (name === STRINGS.style) {
402
+ DomStyle(dom, nextProps['ryunix-style']);
403
+ } else if (name === OLD_STRINGS.style) {
377
404
  DomStyle(dom, nextProps.style);
378
405
  } else if (name === STRINGS.className) {
406
+ if (nextProps['ryunix-class'] === '') {
407
+ throw new Error('data-class cannot be empty.')
408
+ }
409
+
410
+ prevProps['ryunix-class'] &&
411
+ dom.classList.remove(...prevProps['ryunix-class'].split(/\s+/));
412
+ dom.classList.add(...nextProps['ryunix-class'].split(/\s+/));
413
+ } else if (name === OLD_STRINGS.className) {
379
414
  if (nextProps.className === '') {
380
415
  throw new Error('className cannot be empty.')
381
416
  }
417
+
382
418
  prevProps.className &&
383
419
  dom.classList.remove(...prevProps.className.split(/\s+/));
384
420
  dom.classList.add(...nextProps.className.split(/\s+/));
@@ -659,6 +695,7 @@
659
695
  window.Ryunix = Ryunix;
660
696
 
661
697
  exports.Fragments = Fragments;
698
+ exports.Link = Link;
662
699
  exports.Navigate = Navigate;
663
700
  exports.Router = Router;
664
701
  exports.default = Ryunix;