arc-ux 0.0.11 → 0.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arc-ux",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "A purely functional router for independently evaluating a path against a list of routes",
5
5
  "main": "src/ArcUX.js",
6
6
  "type": "module",
package/src/ArcUX.js CHANGED
@@ -1,4 +1,4 @@
1
- import {ArcRouter, ArcEvents, is} from "arc-lib";
1
+ import {ArcRouter, ArcEvents, is, Log} from "arc-lib";
2
2
  import {createRoot} from "react-dom/client";
3
3
  import React from "react";
4
4
  import Html from "./Html.js";
@@ -146,6 +146,22 @@ class ArcUX {
146
146
  this.setKeyVal('route', `${this.#rootPath}${_route}`, _suppressEmit);
147
147
  }
148
148
 
149
+ pushURI(_newURI, _replace) {
150
+ const fullHistoryString = decodeURI(_newURI);
151
+
152
+ const routeData = this.#RouteRenderer.travel(fullHistoryString)
153
+ Log.info('Push uri', [fullHistoryString, routeData]);
154
+ if(routeData.match){
155
+ this.setKeyVal('route', fullHistoryString, true);
156
+ this.setKeyVal('routeData', routeData, true);
157
+ }
158
+
159
+ if (_replace) {
160
+ return window.history.replaceState({ code: fullHistoryString }, "", fullHistoryString);
161
+ }
162
+ return window.history.pushState({ code: fullHistoryString }, "", fullHistoryString);
163
+ }
164
+
149
165
  renderModal(_Modal, _props) {
150
166
  this.emit('modal', [_Modal, _props || {}]);
151
167
  }
@@ -24,7 +24,13 @@ class App extends React.Component {
24
24
  async componentDidMount() {
25
25
  const initialRoute = this.props.ArcUX.getKeyVal('route');
26
26
 
27
- this.props.ArcUX.emit('log', {message: `Our initial route is ${initialRoute}`})
27
+ window.onpopstate = (_event) => {
28
+ if (_event.state) {
29
+ this.props.ArcUX.loadPage(_event.state.code);
30
+ }
31
+ };
32
+
33
+ Log.info( `Our initial route is ${initialRoute}`);
28
34
  const match = this.props.ArcUX.renderRoute(initialRoute);
29
35
  if(match){
30
36
  this.setState({
@@ -52,7 +58,7 @@ class App extends React.Component {
52
58
  const RoutedComponent = this.state.target;
53
59
 
54
60
  if(!RoutedComponent){
55
- this.props.ArcUX.emit('log', {message: "Could not render anything. No AppLoader. No route matched. No NotFound handler. Returning null."})
61
+ Log.info("Could not render anything. No AppLoader. No route matched. No NotFound handler. Returning null.")
56
62
  return null;
57
63
  }
58
64
 
@@ -75,10 +81,10 @@ class App extends React.Component {
75
81
  }
76
82
 
77
83
  loadRoute(_newRoute) {
78
- this.props.ArcUX.emit('log', [{message: `New route called:`, data: [_newRoute]}])
84
+ Log.info(`New route called:`, [_newRoute]);
79
85
  const match = this.props.ArcUX.renderRoute(_newRoute);
80
86
  if(!match){
81
- this.props.ArcUX.emit('log', [{message: 'Not Found handler missing'}]);
87
+ Log.warning(`Not found handler missing`);
82
88
  return;
83
89
  }
84
90
  const fullHistoryString = decodeURI(_newRoute);