@symbiotejs/symbiote 2.0.0-alpha.21 → 2.0.0-alpha.23
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/core/AppRouter.js +25 -14
- package/core/index.js +5 -1
- package/package.json +1 -1
- package/types/symbiote.d.ts +20 -13
package/core/AppRouter.js
CHANGED
|
@@ -2,6 +2,19 @@ import PubSub from './PubSub.js';
|
|
|
2
2
|
|
|
3
3
|
export class AppRouter {
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{title?: String, default?: Boolean, error?: Boolean}} RouteDescriptor
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @type {() => void} */
|
|
10
|
+
static #onPopstate;
|
|
11
|
+
/** @type {String} */
|
|
12
|
+
static #separator;
|
|
13
|
+
/** @type {String} */
|
|
14
|
+
static #routingEventName;
|
|
15
|
+
/** @type {Object<string, RouteDescriptor>} */
|
|
16
|
+
static appMap = Object.create(null);
|
|
17
|
+
|
|
5
18
|
static #print(msg) {
|
|
6
19
|
console.warn(msg);
|
|
7
20
|
}
|
|
@@ -26,12 +39,12 @@ export class AppRouter {
|
|
|
26
39
|
/** @param {String} name */
|
|
27
40
|
static set routingEventName(name) {
|
|
28
41
|
/** @private */
|
|
29
|
-
this
|
|
42
|
+
this.#routingEventName = name;
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
/** @returns {String} */
|
|
33
46
|
static get routingEventName() {
|
|
34
|
-
return this
|
|
47
|
+
return this.#routingEventName || 'sym-on-route';
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
static readAddressBar() {
|
|
@@ -116,17 +129,17 @@ export class AppRouter {
|
|
|
116
129
|
/** @param {String} char */
|
|
117
130
|
static setSeparator(char) {
|
|
118
131
|
/** @private */
|
|
119
|
-
this
|
|
132
|
+
this.#separator = char;
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
/** @returns {String} */
|
|
123
136
|
static get separator() {
|
|
124
|
-
return this
|
|
137
|
+
return this.#separator || '&';
|
|
125
138
|
}
|
|
126
139
|
|
|
127
140
|
/**
|
|
128
141
|
* @param {String} ctxName
|
|
129
|
-
* @param {Object<string,
|
|
142
|
+
* @param {Object<string, RouteDescriptor>} routingMap
|
|
130
143
|
* @returns {PubSub}
|
|
131
144
|
*/
|
|
132
145
|
static initRoutingCtx(ctxName, routingMap) {
|
|
@@ -141,33 +154,31 @@ export class AppRouter {
|
|
|
141
154
|
);
|
|
142
155
|
window.addEventListener(this.routingEventName, (/** @type {CustomEvent} */ e) => {
|
|
143
156
|
routingCtx.multiPub({
|
|
144
|
-
route: e.detail.route,
|
|
145
157
|
options: e.detail.options,
|
|
146
158
|
title: e.detail.options?.title || this.defaultTitle || '',
|
|
159
|
+
route: e.detail.route,
|
|
147
160
|
});
|
|
148
161
|
});
|
|
149
162
|
AppRouter.notify();
|
|
150
|
-
this
|
|
163
|
+
this.#initPopstateListener();
|
|
151
164
|
return routingCtx;
|
|
152
165
|
}
|
|
153
166
|
|
|
154
|
-
static initPopstateListener() {
|
|
155
|
-
if (this
|
|
167
|
+
static #initPopstateListener() {
|
|
168
|
+
if (this.#onPopstate) {
|
|
156
169
|
return;
|
|
157
170
|
}
|
|
158
171
|
/** @private */
|
|
159
172
|
this.__onPopstate = () => {
|
|
160
173
|
this.notify();
|
|
161
174
|
};
|
|
162
|
-
window.addEventListener('popstate', this
|
|
175
|
+
window.addEventListener('popstate', this.#onPopstate);
|
|
163
176
|
}
|
|
164
177
|
|
|
165
178
|
static removePopstateListener() {
|
|
166
|
-
window.removeEventListener('popstate', this
|
|
167
|
-
this
|
|
179
|
+
window.removeEventListener('popstate', this.#onPopstate);
|
|
180
|
+
this.#onPopstate = null;
|
|
168
181
|
}
|
|
169
182
|
}
|
|
170
183
|
|
|
171
|
-
AppRouter.appMap = Object.create(null);
|
|
172
|
-
|
|
173
184
|
export default AppRouter;
|
package/core/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import Symbiote from './Symbiote.js';
|
|
2
|
+
|
|
1
3
|
// Core modules:
|
|
2
|
-
export { Symbiote }
|
|
4
|
+
export { Symbiote };
|
|
3
5
|
export { html } from './html.js';
|
|
4
6
|
export { css } from './css.js';
|
|
5
7
|
export { PubSub } from './PubSub.js';
|
|
@@ -12,3 +14,5 @@ export { applyStyles } from '../utils/dom-helpers.js';
|
|
|
12
14
|
export { applyAttributes } from '../utils/dom-helpers.js';
|
|
13
15
|
export { create } from '../utils/dom-helpers.js';
|
|
14
16
|
export { kebabToCamel } from '../utils/kebabToCamel.js';
|
|
17
|
+
|
|
18
|
+
export default Symbiote;
|
package/package.json
CHANGED
package/types/symbiote.d.ts
CHANGED
|
@@ -161,6 +161,16 @@ declare module "core/Symbiote" {
|
|
|
161
161
|
}
|
|
162
162
|
declare module "core/AppRouter" {
|
|
163
163
|
export class AppRouter {
|
|
164
|
+
static "__#3@#onPopstate": () => void;
|
|
165
|
+
static "__#3@#separator": string;
|
|
166
|
+
static "__#3@#routingEventName": string;
|
|
167
|
+
static appMap: {
|
|
168
|
+
[x: string]: {
|
|
169
|
+
title?: string;
|
|
170
|
+
default?: boolean;
|
|
171
|
+
error?: boolean;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
164
174
|
static "__#3@#print"(msg: any): void;
|
|
165
175
|
static setDefaultTitle(title: string): void;
|
|
166
176
|
static setRoutingMap(map: {
|
|
@@ -181,21 +191,16 @@ declare module "core/AppRouter" {
|
|
|
181
191
|
}): void;
|
|
182
192
|
static setSeparator(char: string): void;
|
|
183
193
|
static get separator(): string;
|
|
184
|
-
static
|
|
185
|
-
[x: string]: {
|
|
194
|
+
static initRoutingCtx(ctxName: string, routingMap: {
|
|
195
|
+
[x: string]: {
|
|
196
|
+
title?: string;
|
|
197
|
+
default?: boolean;
|
|
198
|
+
error?: boolean;
|
|
199
|
+
};
|
|
186
200
|
}): PubSub<any>;
|
|
187
|
-
static initPopstateListener(): void;
|
|
201
|
+
static "__#3@#initPopstateListener"(): void;
|
|
188
202
|
static removePopstateListener(): void;
|
|
189
203
|
}
|
|
190
|
-
export namespace AppRouter {
|
|
191
|
-
const defaultTitle: string;
|
|
192
|
-
const defaultRoute: string;
|
|
193
|
-
const errorRoute: string;
|
|
194
|
-
const __routingEventName: string;
|
|
195
|
-
const _separator: string;
|
|
196
|
-
function __onPopstate(): void;
|
|
197
|
-
const appMap: any;
|
|
198
|
-
}
|
|
199
204
|
export default AppRouter;
|
|
200
205
|
import PubSub from "core/PubSub";
|
|
201
206
|
}
|
|
@@ -225,7 +230,7 @@ declare module "utils/kebabToCamel" {
|
|
|
225
230
|
export function kebabToCamel(string: string): string;
|
|
226
231
|
}
|
|
227
232
|
declare module "core/index" {
|
|
228
|
-
export { Symbiote }
|
|
233
|
+
export { Symbiote };
|
|
229
234
|
export { html } from "./html.js";
|
|
230
235
|
export { css } from "./css.js";
|
|
231
236
|
export { PubSub } from "./PubSub.js";
|
|
@@ -233,6 +238,8 @@ declare module "core/index" {
|
|
|
233
238
|
export { UID } from "../utils/UID.js";
|
|
234
239
|
export { setNestedProp } from "../utils/setNestedProp.js";
|
|
235
240
|
export { kebabToCamel } from "../utils/kebabToCamel.js";
|
|
241
|
+
export default Symbiote;
|
|
242
|
+
import Symbiote from "core/Symbiote";
|
|
236
243
|
export { applyStyles, applyAttributes, create } from "../utils/dom-helpers.js";
|
|
237
244
|
}
|
|
238
245
|
declare module "core/slotProcessor" {
|