@unsetsoft/ryunixjs 0.2.30 → 0.2.31-nightly.1

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
@@ -285,6 +285,64 @@
285
285
  return context;
286
286
  };
287
287
 
288
+ const Router = ({ path, component }) => {
289
+ const [currentPath, setCurrentPath] = useStore(window.location.pathname);
290
+
291
+ useEffect(() => {
292
+ const onLocationChange = () => {
293
+ setCurrentPath(() => window.location.pathname);
294
+ };
295
+
296
+ window.addEventListener("navigate", onLocationChange);
297
+ window.addEventListener("pushsatate", onLocationChange);
298
+ window.addEventListener("popstate", onLocationChange);
299
+
300
+ return () => {
301
+ window.removeEventListener("navigate", onLocationChange);
302
+ window.removeEventListener("pushsatate", onLocationChange);
303
+ window.removeEventListener("popstate", onLocationChange);
304
+ };
305
+ }, [currentPath]);
306
+
307
+ return currentPath === path ? component() : null;
308
+ };
309
+
310
+ const Navigate = (props) => {
311
+ if (props.style) {
312
+ throw new Error(
313
+ "The style attribute is not supported on internal components."
314
+ );
315
+ }
316
+ if (props.to === "") {
317
+ throw new Error("'to=' cannot be empty.");
318
+ }
319
+ if (props.className === "") {
320
+ throw new Error("className cannot be empty.");
321
+ }
322
+ if (props.label === "") {
323
+ throw new Error("'label=' cannot be empty.");
324
+ }
325
+
326
+ if (!props.label || !props.to) {
327
+ throw new Error("Missig component params.");
328
+ }
329
+ const preventReload = (event) => {
330
+ event.preventDefault();
331
+ if (window.location.pathname !== props.to) {
332
+ window.history.pushState({}, "", props.to);
333
+ const navigationEvent = new Event("pushsatate");
334
+ window.dispatchEvent(navigationEvent);
335
+ }
336
+ };
337
+
338
+ const anchor = {
339
+ href: props.to,
340
+ onClick: preventReload,
341
+ ...props,
342
+ };
343
+ return createElement("a", anchor, props.label);
344
+ };
345
+
288
346
  /**
289
347
  * The function creates a new DOM element based on the given fiber object and updates its properties.
290
348
  * @param fiber - The fiber parameter is an object that represents a node in the fiber tree. It
@@ -619,6 +677,8 @@
619
677
  window.Ryunix = Ryunix;
620
678
 
621
679
  exports.Fragments = Fragments;
680
+ exports.Navigate = Navigate;
681
+ exports.Router = Router;
622
682
  exports.createContext = createContext;
623
683
  exports.default = Ryunix;
624
684
  exports.useContext = useContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunixjs",
3
- "version": "0.2.30",
3
+ "version": "0.2.31-nightly.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/Ryunix.js",
6
6
  "private": false,
@@ -31,9 +31,12 @@
31
31
  "css-loader": "^6.8.1",
32
32
  "error-overlay-webpack-plugin": "^1.1.1",
33
33
  "file-loader": "^6.2.0",
34
+ "html-loader": "^4.2.0",
34
35
  "html-webpack-plugin": "^5.5.3",
35
36
  "image-webpack-loader": "8.1.0",
36
37
  "node-sass": "9.0.0",
38
+ "remark-html": "^15.0.2",
39
+ "remark-loader": "^5.0.0",
37
40
  "rollup": "3.24.0",
38
41
  "sass": "^1.66.1",
39
42
  "sass-loader": "^13.3.2",
package/webpack.config.js CHANGED
@@ -1,7 +1,8 @@
1
- const path = require("path");
2
- const HtmlWebpackPlugin = require("html-webpack-plugin");
3
- const ErrorOverlayPlugin = require("error-overlay-webpack-plugin");
4
- const { getPackageManager } = require("./utils");
1
+ import path from "path";
2
+ import HtmlWebpackPlugin from "html-webpack-plugin";
3
+ import ErrorOverlayPlugin from "error-overlay-webpack-plugin";
4
+ import { getPackageManager } from "./utils";
5
+ import RemarkHTML from "remark-html";
5
6
 
6
7
  let dir;
7
8
  const manager = getPackageManager();
@@ -88,6 +89,22 @@ module.exports = {
88
89
  loader: "url-loader",
89
90
  options: { limit: false },
90
91
  },
92
+ {
93
+ test: /\.md$/,
94
+ use: [
95
+ {
96
+ loader: "html-loader",
97
+ },
98
+ {
99
+ loader: "remark-loader",
100
+ options: {
101
+ remarkOptions: {
102
+ plugins: [RemarkHTML],
103
+ },
104
+ },
105
+ },
106
+ ],
107
+ },
91
108
  ],
92
109
  },
93
110
  resolve: {