change h5 to web
This commit is contained in:
36
doric-web/src/navigate/NavigationElement.ts
Normal file
36
doric-web/src/navigate/NavigationElement.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { DoricElement } from "../DoricElement"
|
||||
|
||||
export class NavigationElement extends HTMLElement {
|
||||
|
||||
elementStack: DoricElement[] = []
|
||||
|
||||
get currentNode() {
|
||||
for (let i = 0; i < this.childNodes.length; i++) {
|
||||
if (this.childNodes[i] instanceof DoricElement) {
|
||||
return this.childNodes[i] as DoricElement
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
push(element: DoricElement) {
|
||||
const currentNode = this.currentNode
|
||||
if (currentNode) {
|
||||
this.elementStack.push(currentNode)
|
||||
this.replaceChild(element, currentNode)
|
||||
} else {
|
||||
this.appendChild(element)
|
||||
}
|
||||
}
|
||||
|
||||
pop() {
|
||||
const lastElement = this.elementStack.pop()
|
||||
const currentNode = this.currentNode
|
||||
if (lastElement && currentNode) {
|
||||
this.replaceChild(lastElement, currentNode)
|
||||
currentNode.onDestroy()
|
||||
} else {
|
||||
window.history.back()
|
||||
}
|
||||
}
|
||||
}
|
34
doric-web/src/navigate/NavigatorPlugin.ts
Normal file
34
doric-web/src/navigate/NavigatorPlugin.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { DoricPlugin } from "../DoricPlugin";
|
||||
import { DoricElement } from "../DoricElement";
|
||||
import { NavigationElement } from "./NavigationElement";
|
||||
|
||||
export class NavigatorPlugin extends DoricPlugin {
|
||||
navigation: NavigationElement | undefined = document.getElementsByTagName('doric-navigation')[0] as (NavigationElement | undefined)
|
||||
|
||||
push(args: {
|
||||
scheme: string,
|
||||
config?: {
|
||||
alias?: string,
|
||||
extra?: string,
|
||||
}
|
||||
}) {
|
||||
if (this.navigation) {
|
||||
const div = new DoricElement
|
||||
div.src = args.scheme
|
||||
div.alias = args.config?.alias || args.scheme
|
||||
this.navigation.push(div)
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
return Promise.reject('Not implemented')
|
||||
}
|
||||
}
|
||||
|
||||
pop() {
|
||||
if (this.navigation) {
|
||||
this.navigation.pop()
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
return Promise.reject('Not implemented')
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user