arrowjs-aluminum 0.10.0 → 1.0.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/ArrowElementGenerator.d.ts +16 -32
- package/dist/ArrowElementGenerator.d.ts.map +1 -1
- package/dist/ArrowElementGenerator.js +11 -36
- package/dist/ArrowElementGenerator.js.map +1 -1
- package/dist/Router.d.ts +8 -3
- package/dist/Router.d.ts.map +1 -1
- package/dist/Router.js +26 -20
- package/dist/Router.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,10 +5,10 @@ import { type ArrowTemplate } from "@arrow-js/core";
|
|
|
5
5
|
export declare class ArrowElementGenerator<T> {
|
|
6
6
|
readonly type: string;
|
|
7
7
|
protected readonly attributes: {
|
|
8
|
-
[attribute: string]:
|
|
8
|
+
[attribute: string]: any;
|
|
9
9
|
};
|
|
10
10
|
protected readonly createTransform: (args: T, currentAttributes: {
|
|
11
|
-
[attribute: string]:
|
|
11
|
+
[attribute: string]: any;
|
|
12
12
|
}) => void;
|
|
13
13
|
/**
|
|
14
14
|
* Creates an ArrowElement
|
|
@@ -17,50 +17,34 @@ export declare class ArrowElementGenerator<T> {
|
|
|
17
17
|
* @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
|
|
18
18
|
*/
|
|
19
19
|
constructor(type: string, attributes: {
|
|
20
|
-
[attribute: string]:
|
|
20
|
+
[attribute: string]: any;
|
|
21
21
|
}, createTransform: (args: T, currentAttributes: {
|
|
22
|
-
[attribute: string]:
|
|
22
|
+
[attribute: string]: any;
|
|
23
23
|
}) => void);
|
|
24
24
|
/**
|
|
25
25
|
* Creates a new template from this generator, optionally adding some additional attributes
|
|
26
|
-
* @param contents The contents of this template (the stuff between the tags)
|
|
27
26
|
* @param requiredValue The value you need to pass into this generator, specified when the generator was created (the `createTransform`)
|
|
28
27
|
* @param attributes Additional attributes to add to this template
|
|
29
28
|
* @return A renderable {@link ArrowTemplate}
|
|
30
29
|
*/
|
|
31
|
-
create(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
replace?: {
|
|
36
|
-
[attribute: string]: string | (() => string);
|
|
37
|
-
};
|
|
38
|
-
transform?: {
|
|
39
|
-
[attribute: string]: (previousValue: (string | undefined | (() => string))) => string;
|
|
40
|
-
};
|
|
41
|
-
}): ArrowTemplate;
|
|
30
|
+
create(requiredValue: T, attributes?: {
|
|
31
|
+
[attribute: string]: (previousValue: any) => any;
|
|
32
|
+
}): (strings: TemplateStringsArray, ...expSlots: any[]) => ArrowTemplate;
|
|
42
33
|
/**
|
|
43
34
|
* Creates a new generator based on this one
|
|
44
|
-
* @param attributes
|
|
35
|
+
* @param attributes An object of callbacks, where each callback takes the old attribute and returns the new attribute.
|
|
36
|
+
* If a value is passed in instead of a callback, the new value will overwrite the old value.
|
|
45
37
|
* @param newCreateTransform Takes the `requiredValue` from {@link create} and the attributes of this generator,
|
|
46
38
|
* and applies the `requiredValue` to the attributes
|
|
47
39
|
* @param type The node type of this template. Optional, will inherit from parent if not specified
|
|
48
40
|
* @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
|
|
49
41
|
*/
|
|
50
42
|
extend<T2>(attributes: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
replace?: {
|
|
55
|
-
[attribute: string]: string | (() => string);
|
|
56
|
-
};
|
|
57
|
-
transform?: {
|
|
58
|
-
[attribute: string]: (previousValue: (string | undefined | (() => string))) => string;
|
|
59
|
-
};
|
|
60
|
-
}, newCreateTransform: (superTransform: (args: T, currentAttributes: {
|
|
61
|
-
[attribute: string]: string | (() => string);
|
|
43
|
+
[attribute: string]: any;
|
|
44
|
+
} | undefined, newCreateTransform: (superTransform: (args: T, currentAttributes: {
|
|
45
|
+
[attribute: string]: any;
|
|
62
46
|
}) => void) => (args: T2, currentAttributes: {
|
|
63
|
-
[attribute: string]:
|
|
47
|
+
[attribute: string]: any;
|
|
64
48
|
}) => void, type?: string): ArrowElementGenerator<T2>;
|
|
65
49
|
}
|
|
66
50
|
/**
|
|
@@ -70,9 +54,9 @@ export declare class ArrowElementGenerator<T> {
|
|
|
70
54
|
* @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
|
|
71
55
|
* @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
|
|
72
56
|
*/
|
|
73
|
-
export default function createGenerator<T>(type: string, attributes
|
|
74
|
-
[attribute: string]:
|
|
57
|
+
export default function createGenerator<T>(type: string, attributes?: {
|
|
58
|
+
[attribute: string]: any;
|
|
75
59
|
}, createTransform?: (args: T, currentAttributes: {
|
|
76
|
-
[attribute: string]:
|
|
60
|
+
[attribute: string]: any;
|
|
77
61
|
}) => void): ArrowElementGenerator<T>;
|
|
78
62
|
//# sourceMappingURL=ArrowElementGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrowElementGenerator.d.ts","sourceRoot":"","sources":["../src/ArrowElementGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,aAAa,EAAO,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ArrowElementGenerator.d.ts","sourceRoot":"","sources":["../src/ArrowElementGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,aAAa,EAAO,MAAM,gBAAgB,CAAC;AAUxD;;GAEG;AACH,qBAAa,qBAAqB,CAAC,CAAC;IAChC,SAAgB,IAAI,SAAC;IACrB,SAAS,CAAC,QAAQ,CAAC,UAAU;;MAAC;IAC9B,SAAS,CAAC,QAAQ,CAAC,eAAe,SASA,CAAC,qBAAoB;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,KAAG,IAAI,CATnD;IAEnC;;;;;OAKG;gBACS,IAAI,EAAC,MAAM,EAAE,UAAU,EAAC;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,EAChD,eAAe,EAAC,CAAC,IAAI,EAAC,CAAC,EAAE,iBAAiB,EAAC;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,KAAG,IAAI;IAMtF;;;;;OAKG;IACH,MAAM,CAAC,aAAa,EAAC,CAAC,EAAE,UAAU,GAAC;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,CAAC,aAAa,EAAC,GAAG,KAAG,GAAG,CAAA;KAAI,IAavE,SAAQ,oBAAoB,EAAE,GAAG,UAAU,GAAG,EAAE;IAI5D;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,UAAU,EAAC;QAAC,CAAC,SAAS,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,YAAG,EACzC,kBAAkB,EAAC,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,iBAAiB,EAAE;QAC7D,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAA;KAC3B,KAAK,IAAI,KACN,CAAC,IAAI,EAAC,EAAE,EAAE,iBAAiB,EAAC;QACxB,CAAC,SAAS,EAAC,MAAM,GAAG,GAAG,CAAA;KAC1B,KAAK,IAAI,EACd,IAAI,CAAC,EAAC,MAAM;CAMvB;AAGD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,CAAC,EAAE,IAAI,EAAC,MAAM,EAAE,UAAU,GAAC;IAAC,CAAC,SAAS,EAAC,MAAM,GAAE,GAAG,CAAA;CAAI,EACtF,eAAe,GAAE,CAAC,IAAI,EAAC,CAAC,EAAE,iBAAiB,EAAC;IACxC,CAAC,SAAS,EAAC,MAAM,GAAE,GAAG,CAAA;CACzB,KAAG,IAAa,4BAIxB"}
|
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import { html } from "@arrow-js/core";
|
|
2
|
-
function extendAttributes(originalAttrs, transformers) {
|
|
2
|
+
function extendAttributes(originalAttrs, transformers = {}) {
|
|
3
3
|
const newAttributes = { ...originalAttrs };
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (newAttributes[attribute] === undefined)
|
|
7
|
-
newAttributes[attribute] = addValue;
|
|
8
|
-
else if (typeof addValue === "string") {
|
|
9
|
-
if (typeof newAttributes[attribute] === "string")
|
|
10
|
-
newAttributes[attribute] += " " + addValue;
|
|
11
|
-
else {
|
|
12
|
-
const old = newAttributes[attribute];
|
|
13
|
-
newAttributes[attribute] = () => old() + " " + addValue;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
const old = newAttributes[attribute];
|
|
18
|
-
if (typeof old === "function")
|
|
19
|
-
newAttributes[attribute] = () => old() + " " + addValue();
|
|
20
|
-
else
|
|
21
|
-
newAttributes[attribute] = () => addValue() + " " + old;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (transformers.replace !== undefined)
|
|
26
|
-
Object.assign(newAttributes, transformers.replace);
|
|
27
|
-
if (transformers.transform !== undefined) {
|
|
28
|
-
for (const [attribute, transformer] of Object.entries(transformers.transform)) {
|
|
29
|
-
newAttributes[attribute] = transformer(newAttributes[attribute]);
|
|
30
|
-
}
|
|
4
|
+
for (const [attribute, transformer] of Object.entries(transformers)) {
|
|
5
|
+
newAttributes[attribute] = transformer(newAttributes[attribute]);
|
|
31
6
|
}
|
|
32
7
|
return newAttributes;
|
|
33
8
|
}
|
|
@@ -51,12 +26,11 @@ export class ArrowElementGenerator {
|
|
|
51
26
|
}
|
|
52
27
|
/**
|
|
53
28
|
* Creates a new template from this generator, optionally adding some additional attributes
|
|
54
|
-
* @param contents The contents of this template (the stuff between the tags)
|
|
55
29
|
* @param requiredValue The value you need to pass into this generator, specified when the generator was created (the `createTransform`)
|
|
56
30
|
* @param attributes Additional attributes to add to this template
|
|
57
31
|
* @return A renderable {@link ArrowTemplate}
|
|
58
32
|
*/
|
|
59
|
-
create(
|
|
33
|
+
create(requiredValue, attributes = {}) {
|
|
60
34
|
const newAttributes = { ...this.attributes };
|
|
61
35
|
this.createTransform(requiredValue, newAttributes);
|
|
62
36
|
const newerAttributes = extendAttributes(newAttributes, attributes);
|
|
@@ -66,18 +40,19 @@ export class ArrowElementGenerator {
|
|
|
66
40
|
...(orderedContents.length > 0 ? ['">'] : []), `</${this.type}>`];
|
|
67
41
|
// @ts-ignore
|
|
68
42
|
staticStringContents.raw = [...staticStringContents];
|
|
69
|
-
return html(staticStringContents, ...[...orderedContents.map(data => data[1]),
|
|
43
|
+
return (strings, ...expSlots) => html(staticStringContents, ...[...orderedContents.map(data => data[1]), html(strings, ...expSlots)]);
|
|
70
44
|
}
|
|
71
45
|
/**
|
|
72
46
|
* Creates a new generator based on this one
|
|
73
|
-
* @param attributes
|
|
47
|
+
* @param attributes An object of callbacks, where each callback takes the old attribute and returns the new attribute.
|
|
48
|
+
* If a value is passed in instead of a callback, the new value will overwrite the old value.
|
|
74
49
|
* @param newCreateTransform Takes the `requiredValue` from {@link create} and the attributes of this generator,
|
|
75
50
|
* and applies the `requiredValue` to the attributes
|
|
76
51
|
* @param type The node type of this template. Optional, will inherit from parent if not specified
|
|
77
52
|
* @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
|
|
78
53
|
*/
|
|
79
|
-
extend(attributes, newCreateTransform, type) {
|
|
80
|
-
return new ArrowElementGenerator(type || this.type, extendAttributes(this.attributes, attributes), newCreateTransform(this.createTransform));
|
|
54
|
+
extend(attributes = {}, newCreateTransform, type) {
|
|
55
|
+
return new ArrowElementGenerator(type || this.type, extendAttributes(this.attributes, Object.fromEntries(Object.entries(attributes).map(([k, v]) => [k, typeof v === "function" ? v : () => v]))), newCreateTransform(this.createTransform));
|
|
81
56
|
}
|
|
82
57
|
}
|
|
83
58
|
const defaultGenerator = new ArrowElementGenerator("", {}, () => { });
|
|
@@ -88,7 +63,7 @@ const defaultGenerator = new ArrowElementGenerator("", {}, () => { });
|
|
|
88
63
|
* @param createTransform A function that gets run when {@link create} is called. See {@link create} for more info
|
|
89
64
|
* @return A new {@link ArrowElementGenerator} with the specified attributes, type, and transform function
|
|
90
65
|
*/
|
|
91
|
-
export default function createGenerator(type, attributes, createTransform = () => { }) {
|
|
92
|
-
return defaultGenerator.extend(
|
|
66
|
+
export default function createGenerator(type, attributes = {}, createTransform = () => { }) {
|
|
67
|
+
return defaultGenerator.extend(Object.fromEntries(Object.entries(attributes).map(([k, v]) => [k, () => v])), () => createTransform, type);
|
|
93
68
|
}
|
|
94
69
|
//# sourceMappingURL=ArrowElementGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrowElementGenerator.js","sourceRoot":"","sources":["../src/ArrowElementGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAExD,SAAS,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"ArrowElementGenerator.js","sourceRoot":"","sources":["../src/ArrowElementGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAExD,SAAS,gBAAgB,CAAC,aAAsC,EAAC,eAA2D,EAAE;IAC1H,MAAM,aAAa,GAAG,EAAC,GAAG,aAAa,EAAC,CAAC;IACzC,KAAI,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAC,CAAC;QAChE,aAAa,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,aAAa,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACd,IAAI,CAAC;IACF,UAAU,CAAC;IACX,eAAe,CAAC;IAEnC;;;;;OAKG;IACH,YAAY,IAAW,EAAE,UAAmC,EAChD,eAA0E;QAClF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAC,eAAe,CAAC;IACzC,CAAC;IAED;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Y;QAEhB,OAAO,IAAI,qBAAqB,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAChF,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,EAAC,EAAE,CACvD,CAAC,CAAC,EAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAE,EAAE,CAAA,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IAClG,CAAC;CACJ;AAED,MAAM,gBAAgB,GAAG,IAAI,qBAAqB,CAAC,EAAE,EAAC,EAAE,EAAE,GAAE,EAAE,GAAC,CAAC,CAAC,CAAC;AAClE;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAI,IAAW,EAAE,aAAoC,EAAE,EACtF,kBAEW,GAAE,EAAE,GAAC,CAAC;IACrB,OAAO,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAC5E,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAE,EAAE,CAAA,CAAC,CAAC,CAAC,CAAC,EACxB,GAAE,EAAE,CAAA,eAAe,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/Router.d.ts
CHANGED
|
@@ -77,15 +77,20 @@ export declare class PageAttachedRouter extends Router {
|
|
|
77
77
|
}) => ArrowTemplate);
|
|
78
78
|
/**
|
|
79
79
|
* Rerenders the page
|
|
80
|
+
* @return this for chaining
|
|
80
81
|
*/
|
|
81
|
-
rerender():
|
|
82
|
+
rerender(): this;
|
|
82
83
|
/**
|
|
83
84
|
* Updates the window's `location` and rerenders the page
|
|
84
85
|
* @param newLocation The new url
|
|
85
86
|
* @param replace Whether this new url should replace the current url in history or be a new entry
|
|
86
|
-
* @return
|
|
87
|
+
* @return this for chaining
|
|
87
88
|
*/
|
|
88
|
-
redirect(newLocation?: string, replace?:
|
|
89
|
+
redirect(newLocation?: string, replace?: boolean): this;
|
|
90
|
+
/**
|
|
91
|
+
* An ArrowTemplateGenerator that creates links that work with this router
|
|
92
|
+
*/
|
|
93
|
+
readonly link: import("./ArrowElementGenerator.js").ArrowElementGenerator<string>;
|
|
89
94
|
}
|
|
90
95
|
export {};
|
|
91
96
|
//# sourceMappingURL=Router.d.ts.map
|
package/dist/Router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,aAAa,EAAO,MAAM,gBAAgB,CAAC;AAMxD,KAAK,QAAQ,GAAG,CAAC,SAAS,EAAC;IAAC,CAAC,YAAY,EAAC,MAAM,GAAE,MAAM,CAAA;CAAC,KAAG,aAAa,CAAC;AAC1E,KAAK,SAAS,GAAG;IAAC,CAAC,OAAO,EAAC,MAAM,GAAE,SAAS,CAAC;IAAC,CAAC,gBAAgB,EAAC,MAAM,GAAE,QAAQ,GAAC,MAAM,CAAA;CAAC,CAAC;AAIzF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACvB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAC,SAAS,CAAI;IACvC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAC,aAAa,CAAC;IAC1C,SAAS,CAAC,QAAQ,CAAC,oBAAoB,aAOwC,aAAa,QAAO;QAAC,CAAC,YAAY,EAAC,MAAM,GAAE,MAAM,CAAA;KAAC,KA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erator from "./ArrowElementGenerator.js";
|
|
3
4
|
const getRouteSymbol = Symbol("getRoute");
|
|
4
5
|
const routerSymbol = Symbol("router");
|
|
5
6
|
const default404 = html `404`;
|
|
@@ -120,7 +121,7 @@ export default class Router {
|
|
|
120
121
|
return toReturn;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
|
-
const
|
|
124
|
+
const hrefResolver = document.createElement("a");
|
|
124
125
|
/**
|
|
125
126
|
* A router that can manages the web page based on the page's url
|
|
126
127
|
*/
|
|
@@ -138,12 +139,13 @@ export class PageAttachedRouter extends Router {
|
|
|
138
139
|
this.rootElement = attachTo;
|
|
139
140
|
this.location.$on(() => this.rerender());
|
|
140
141
|
window.addEventListener("popstate", e => {
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
this.redirect(window.location.pathname);
|
|
143
|
+
e.preventDefault();
|
|
143
144
|
}); //back button handling
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
146
147
|
* Rerenders the page
|
|
148
|
+
* @return this for chaining
|
|
147
149
|
*/
|
|
148
150
|
rerender() {
|
|
149
151
|
const path = this.getPath(this.location.value.join("/"));
|
|
@@ -151,30 +153,34 @@ export class PageAttachedRouter extends Router {
|
|
|
151
153
|
this.rootElement.replaceChildren();
|
|
152
154
|
path(this.rootElement);
|
|
153
155
|
}
|
|
156
|
+
return this;
|
|
154
157
|
}
|
|
155
158
|
/**
|
|
156
159
|
* Updates the window's `location` and rerenders the page
|
|
157
160
|
* @param newLocation The new url
|
|
158
161
|
* @param replace Whether this new url should replace the current url in history or be a new entry
|
|
159
|
-
* @return
|
|
162
|
+
* @return this for chaining
|
|
160
163
|
*/
|
|
161
164
|
redirect(newLocation = window.location.pathname, replace) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.location.value = this.location.value.concat(newLocation.split("/"));
|
|
168
|
-
// modalContents.val=undefined;
|
|
169
|
-
const newPath = newLocation.split("/");
|
|
170
|
-
if (newPath[0] === "") {
|
|
171
|
-
this.location.value = newPath.slice(1);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
this.location.value = this.location.value.concat(newPath);
|
|
165
|
+
hrefResolver.href = newLocation;
|
|
166
|
+
const url = URL.parse(hrefResolver.href);
|
|
167
|
+
if (url.host !== window.location.host) {
|
|
168
|
+
window.location.href = url.href + url.search + url.hash;
|
|
169
|
+
return this;
|
|
175
170
|
}
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
this.location.value = url.pathname.split("/").slice(1);
|
|
172
|
+
window.history[replace ? "replaceState" : "pushState"](null, "", "/" + this.location.value.join("/") + url.search + url.hash);
|
|
173
|
+
return this;
|
|
178
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* An ArrowTemplateGenerator that creates links that work with this router
|
|
177
|
+
*/
|
|
178
|
+
link = createGenerator("a", { href: "#" }, (href, attrs) => {
|
|
179
|
+
attrs["@click"] = (e) => {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
this.redirect(href);
|
|
182
|
+
};
|
|
183
|
+
attrs.href = href;
|
|
184
|
+
});
|
|
179
185
|
}
|
|
180
186
|
//# sourceMappingURL=Router.js.map
|
package/dist/Router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAC,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,eAAe,MAAM,4BAA4B,CAAC;AAEzD,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC1C,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAItC,MAAM,UAAU,GAAG,IAAI,CAAA,KA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