simplyview 3.1.4 → 3.4.0
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/simply.app.js +205 -41
- package/dist/simply.app.min.js +1 -1
- package/dist/simply.app.min.js.map +4 -4
- package/dist/simply.everything.js +232 -47
- package/dist/simply.everything.min.js +1 -1
- package/dist/simply.everything.min.js.map +4 -4
- package/package.json +1 -1
- package/src/action.mjs +52 -19
- package/src/activate.mjs +24 -2
- package/src/app.mjs +159 -14
- package/src/highlight.mjs +11 -0
- package/src/route.mjs +20 -20
package/src/route.mjs
CHANGED
|
@@ -12,7 +12,7 @@ class SimplyRoute
|
|
|
12
12
|
{
|
|
13
13
|
constructor(options={})
|
|
14
14
|
{
|
|
15
|
-
this.
|
|
15
|
+
this.baseURL = options.baseURL || '/'
|
|
16
16
|
this.app = options.app || {}
|
|
17
17
|
this.addMissingSlash = !!options.addMissingSlash
|
|
18
18
|
this.matchExact = !!options.matchExact
|
|
@@ -63,7 +63,7 @@ class SimplyRoute
|
|
|
63
63
|
matches = route.match.exec(path+'/')
|
|
64
64
|
if (matches) {
|
|
65
65
|
path+='/'
|
|
66
|
-
history.replaceState({}, '', getURL(path, this.
|
|
66
|
+
history.replaceState({}, '', getURL(path, this.baseURL))
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -91,7 +91,7 @@ class SimplyRoute
|
|
|
91
91
|
|
|
92
92
|
runListeners(action, params)
|
|
93
93
|
{
|
|
94
|
-
if (!Object.keys(this.listeners[action])) {
|
|
94
|
+
if (!this.listeners[action] || !Object.keys(this.listeners[action])) {
|
|
95
95
|
return
|
|
96
96
|
}
|
|
97
97
|
Object.keys(this.listeners[action]).forEach((route) => {
|
|
@@ -112,8 +112,8 @@ class SimplyRoute
|
|
|
112
112
|
handleEvents()
|
|
113
113
|
{
|
|
114
114
|
globalThis.addEventListener('popstate', () => {
|
|
115
|
-
if (this.match(getPath(document.location.pathname + document.location.hash, this.
|
|
116
|
-
this.match(getPath(document.location.pathname, this.
|
|
115
|
+
if (this.match(getPath(document.location.pathname + document.location.hash, this.baseURL)) === false) {
|
|
116
|
+
this.match(getPath(document.location.pathname, this.baseURL))
|
|
117
117
|
}
|
|
118
118
|
})
|
|
119
119
|
this.app.container.addEventListener('click', (evt) => {
|
|
@@ -136,7 +136,7 @@ class SimplyRoute
|
|
|
136
136
|
let check = [link.hash, link.pathname+link.hash, link.pathname]
|
|
137
137
|
let path
|
|
138
138
|
do {
|
|
139
|
-
path = getPath(check.shift(), this.
|
|
139
|
+
path = getPath(check.shift(), this.baseURL);
|
|
140
140
|
} while(check.length && !this.has(path))
|
|
141
141
|
if ( this.has(path) ) {
|
|
142
142
|
let params = this.runListeners('goto', { path: path});
|
|
@@ -154,13 +154,13 @@ class SimplyRoute
|
|
|
154
154
|
|
|
155
155
|
goto(path)
|
|
156
156
|
{
|
|
157
|
-
history.pushState({},'',getURL(path, this.
|
|
157
|
+
history.pushState({},'',getURL(path, this.baseURL))
|
|
158
158
|
return this.match(path)
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
has(path)
|
|
162
162
|
{
|
|
163
|
-
path = getPath(path, this.
|
|
163
|
+
path = getPath(path, this.baseURL)
|
|
164
164
|
for (let route of this.routeInfo) {
|
|
165
165
|
var matches = route.match.exec(path)
|
|
166
166
|
if (matches && matches.length) {
|
|
@@ -196,22 +196,22 @@ class SimplyRoute
|
|
|
196
196
|
|
|
197
197
|
init(options)
|
|
198
198
|
{
|
|
199
|
-
if (options.
|
|
200
|
-
this.
|
|
199
|
+
if (options.baseURL) {
|
|
200
|
+
this.baseURL = options.baseURL
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
function getPath(path,
|
|
205
|
+
function getPath(path, baseURL='/')
|
|
206
206
|
{
|
|
207
|
-
if (path.substring(0,
|
|
207
|
+
if (path.substring(0,baseURL.length)==baseURL
|
|
208
208
|
||
|
|
209
|
-
(
|
|
210
|
-
&& path.length==(
|
|
211
|
-
&& path ==
|
|
209
|
+
( baseURL[baseURL.length-1]=='/'
|
|
210
|
+
&& path.length==(baseURL.length-1)
|
|
211
|
+
&& path == baseURL.substring(0,path.length)
|
|
212
212
|
)
|
|
213
213
|
) {
|
|
214
|
-
path = path.substring(
|
|
214
|
+
path = path.substring(baseURL.length)
|
|
215
215
|
}
|
|
216
216
|
if (path[0]!='/' && path[0]!='#') {
|
|
217
217
|
path = '/'+path
|
|
@@ -219,16 +219,16 @@ function getPath(path, root='/')
|
|
|
219
219
|
return path
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
function getURL(path,
|
|
222
|
+
function getURL(path, baseURL)
|
|
223
223
|
{
|
|
224
|
-
path = getPath(path,
|
|
225
|
-
if (
|
|
224
|
+
path = getPath(path, baseURL)
|
|
225
|
+
if (baseURL[baseURL.length-1]==='/' && path[0]==='/') {
|
|
226
226
|
path = path.substring(1)
|
|
227
227
|
}
|
|
228
228
|
if (path[0]=='#') {
|
|
229
229
|
return path
|
|
230
230
|
}
|
|
231
|
-
return
|
|
231
|
+
return baseURL + path
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
function getRegexpFromRoute(route, exact=false)
|