Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

maishu-chitu

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maishu-chitu - npm Package Compare versions

Comparing version 2.18.0 to 3.0.0

148

dist/index.es5.js
/*!
*
* maishu-chitu v2.18.0
* maishu-chitu v3.0.0
* https://github.com/ansiboy/chitu

@@ -220,6 +220,4 @@ *

_this = _possibleConstructorReturn(this, _getPrototypeOf(Application).call(this, (args || {}).container || document.body, (args || {}).parser));
_this = _possibleConstructorReturn(this, _getPrototypeOf(Application).call(this, Application.containers((args || {}).container), (args || {}).parser));
_this._runned = false;
_this.closeCurrentOnBack = null;
_this.tempPageData = undefined;
return _this;

@@ -262,3 +260,3 @@ }

_this2.showPageByUrl(url);
_this2.showPage(url);
};

@@ -278,38 +276,2 @@

}, {
key: "showPageByUrl",
value: function showPageByUrl(url) {
if (!url) throw Errors_1.Errors.argumentNull('url');
var tempPageData = this.fetchTemplatePageData();
var result = null;
if (this.closeCurrentOnBack == true) {
this.closeCurrentOnBack = null;
if (tempPageData == null) this.closeCurrentPage();else this.closeCurrentPage(tempPageData);
result = this.currentPage;
} else if (this.closeCurrentOnBack == false) {
this.closeCurrentOnBack = null;
var page = this.pageStack.pop();
if (page == null) throw new Error('page is null');
page.hide(this.currentPage);
result = this.currentPage;
}
if (result == null || result.url != url) {
result = this.showPage(url);
}
return result;
}
}, {
key: "fetchTemplatePageData",
value: function fetchTemplatePageData() {
if (this.tempPageData == null) {
return null;
}
var data = this.tempPageData;
this.tempPageData = undefined;
return data;
}
}, {
key: "setLocationHash",

@@ -324,3 +286,7 @@ value: function setLocationHash(pageUrl) {

if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl');
var page = this.showPage(pageUrl, args);
var routeData = _parseUrl(pageUrl);
var containerName = routeData.values.container || Application.DefaultContainerName;
var page = this.openPage(pageUrl, containerName, args);
var url = this.createUrl(page.name, page.data);

@@ -335,4 +301,8 @@ this.setLocationHash(url);

if (setUrl == null) setUrl = true;
var page = this.showPage(pageUrl, args, true);
var routeData = _parseUrl(pageUrl);
var containerName = routeData.values.container || Application.DefaultContainerName;
var page = this.openPage(pageUrl, containerName, args, true);
if (setUrl) {

@@ -353,13 +323,7 @@ var url = this.createUrl(page.name, page.data);

key: "back",
value: function back(closeCurrentPage, data) {
var closeCurrentPageDefault = true;
if (_typeof(closeCurrentPage) == 'object') {
data = closeCurrentPage;
closeCurrentPage = null;
}
this.closeCurrentOnBack = closeCurrentPage == null ? closeCurrentPageDefault : closeCurrentPage;
this.tempPageData = data;
history.back();
value: function back() {
this.closeCurrentPage();
setTimeout(function () {
history.back();
}, 100);
}

@@ -383,2 +347,21 @@ }, {

}
}], [{
key: "containers",
value: function containers(container) {
var r = {};
if (container == null) {
r[Application.DefaultContainerName] = document.body;
return r;
}
if (container.tagName) {
r[Application.DefaultContainerName] = container;
return r;
}
r = container;
if (!Application.DefaultContainerName) throw Errors_1.Errors.containerIsNotExists(Application.DefaultContainerName);
return r;
}
}]);

@@ -389,2 +372,3 @@

Application.DefaultContainerName = 'default';
exports.Application = Application;

@@ -577,2 +561,8 @@ }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),

}
}, {
key: "containerIsNotExists",
value: function containerIsNotExists(name) {
var msg = "Container '".concat(name, "' is not exists");
return new Error(msg);
}
}]);

@@ -634,2 +624,3 @@

this._url = params.url;
this._container = params.container;
}

@@ -735,2 +726,7 @@

}
}, {
key: "container",
get: function get() {
return this._container;
}
}]);

@@ -840,3 +836,3 @@

function () {
function PageMaster(container, parser) {
function PageMaster(containers, parser) {
_classCallCheck(this, PageMaster);

@@ -855,5 +851,5 @@

this.parser = parser || this.defaultPageNodeParser();
if (!container) throw Errors_1.Errors.argumentNull("container");
if (!containers) throw Errors_1.Errors.argumentNull("containers");
this.parser.actions = this.parser.actions || {};
this.container = container;
this.containers = containers;
}

@@ -962,6 +958,6 @@

key: "getPage",
value: function getPage(pageUrl, values) {
value: function getPage(pageUrl, containerName, values) {
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl');
values = values || {};
var cachePage = this.cachePages[pageUrl];
var cachePage = this.cachePages["".concat(containerName, "_").concat(pageUrl)];

@@ -976,3 +972,3 @@ if (cachePage != null) {

var page = this.createPage(pageUrl, values);
var page = this.createPage(pageUrl, containerName, values);
this.cachePages[pageUrl] = page;

@@ -987,9 +983,12 @@ this.on_pageCreated(page);

key: "createPage",
value: function createPage(pageUrl, values) {
value: function createPage(pageUrl, containerName, values) {
var _this3 = this;
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl');
if (!containerName) throw Errors_1.Errors.argumentNull('containerName');
values = values || {};
var element = this.createPageElement(pageUrl);
var element = this.createPageElement(pageUrl, containerName);
var displayer = new this.pageDisplayType(this);
var container = this.containers[containerName];
if (!container) throw Errors_1.Errors.containerIsNotExists(containerName);
console.assert(this.pageType != null);

@@ -1001,6 +1000,16 @@ var page = new this.pageType({

displayer: displayer,
element: element
element: element,
container: container
});
var showing = function showing(sender) {
for (var key in _this3.containers) {
if (_this3.containers[key] == sender.container) {
sender.container.style.removeProperty('display');
continue;
}
_this3.containers[key].style.display == 'none';
}
_this3.pageShowing.fire(_this3, sender);

@@ -1023,5 +1032,7 @@ };

key: "createPageElement",
value: function createPageElement(pageName) {
value: function createPageElement(pageName, containerName) {
var container = this.containers[containerName];
if (!container == null) throw Errors_1.Errors.containerIsNotExists(containerName);
var element = document.createElement(Page_1.Page.tagName);
this.container.appendChild(element);
container.appendChild(element);
return element;

@@ -1032,2 +1043,7 @@ }

value: function showPage(pageUrl, args, forceRender) {
return this.openPage(pageUrl, Application_1.Application.DefaultContainerName, args, forceRender);
}
}, {
key: "openPage",
value: function openPage(pageUrl, containerName, args, forceRender) {
args = args || {};

@@ -1038,3 +1054,3 @@ forceRender = forceRender == null ? false : true;

var _this$getPage = this.getPage(pageUrl, args),
var _this$getPage = this.getPage(pageUrl, containerName, args),
page = _this$getPage.page,

@@ -1041,0 +1057,0 @@ isNew = _this$getPage.isNew;

/*!
*
* maishu-chitu v2.18.0
* maishu-chitu v3.0.0
* https://github.com/ansiboy/chitu

@@ -168,7 +168,20 @@ *

constructor(args) {
super((args || {}).container || document.body, (args || {}).parser);
super(Application.containers((args || {}).container), (args || {}).parser);
this._runned = false;
this.closeCurrentOnBack = null;
this.tempPageData = undefined;
}
static containers(container) {
let r = {};
if (container == null) {
r[Application.DefaultContainerName] = document.body;
return r;
}
if (container.tagName) {
r[Application.DefaultContainerName] = container;
return r;
}
r = container;
if (!Application.DefaultContainerName)
throw Errors_1.Errors.containerIsNotExists(Application.DefaultContainerName);
return r;
}
parseUrl(url) {

@@ -196,3 +209,3 @@ if (!url)

}
this.showPageByUrl(url);
this.showPage(url);
};

@@ -209,36 +222,2 @@ showPage();

}
showPageByUrl(url) {
if (!url)
throw Errors_1.Errors.argumentNull('url');
let tempPageData = this.fetchTemplatePageData();
let result = null;
if (this.closeCurrentOnBack == true) {
this.closeCurrentOnBack = null;
if (tempPageData == null)
this.closeCurrentPage();
else
this.closeCurrentPage(tempPageData);
result = this.currentPage;
}
else if (this.closeCurrentOnBack == false) {
this.closeCurrentOnBack = null;
var page = this.pageStack.pop();
if (page == null)
throw new Error('page is null');
page.hide(this.currentPage);
result = this.currentPage;
}
if (result == null || result.url != url) {
result = this.showPage(url);
}
return result;
}
fetchTemplatePageData() {
if (this.tempPageData == null) {
return null;
}
let data = this.tempPageData;
this.tempPageData = undefined;
return data;
}
setLocationHash(pageUrl) {

@@ -254,3 +233,5 @@ this.location.hash = `#${pageUrl}`;

throw Errors_1.Errors.argumentNull('pageUrl');
let page = this.showPage(pageUrl, args);
let routeData = parseUrl(pageUrl);
let containerName = routeData.values.container || Application.DefaultContainerName;
let page = this.openPage(pageUrl, containerName, args);
let url = this.createUrl(page.name, page.data);

@@ -265,3 +246,5 @@ this.setLocationHash(url);

setUrl = true;
let page = this.showPage(pageUrl, args, true);
let routeData = parseUrl(pageUrl);
let containerName = routeData.values.container || Application.DefaultContainerName;
let page = this.openPage(pageUrl, containerName, args, true);
if (setUrl) {

@@ -277,11 +260,7 @@ let url = this.createUrl(page.name, page.data);

}
back(closeCurrentPage, data) {
const closeCurrentPageDefault = true;
if (typeof closeCurrentPage == 'object') {
data = closeCurrentPage;
closeCurrentPage = null;
}
this.closeCurrentOnBack = closeCurrentPage == null ? closeCurrentPageDefault : closeCurrentPage;
this.tempPageData = data;
history.back();
back() {
this.closeCurrentPage();
setTimeout(() => {
history.back();
}, 100);
}

@@ -297,2 +276,3 @@ createService(type) {

}
Application.DefaultContainerName = 'default';
exports.Application = Application;

@@ -415,2 +395,6 @@ }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),

}
static containerIsNotExists(name) {
let msg = `Container '${name}' is not exists`;
return new Error(msg);
}
}

@@ -450,2 +434,3 @@ exports.Errors = Errors;

this._url = params.url;
this._container = params.container;
}

@@ -515,2 +500,5 @@ on_showing() {

}
get container() {
return this._container;
}
}

@@ -561,3 +549,3 @@ Page.tagName = 'div';

class PageMaster {
constructor(container, parser) {
constructor(containers, parser) {
this.pageCreated = maishu_chitu_service_1.Callbacks();

@@ -574,6 +562,6 @@ this.pageShowing = maishu_chitu_service_1.Callbacks();

this.parser = parser || this.defaultPageNodeParser();
if (!container)
throw Errors_1.Errors.argumentNull("container");
if (!containers)
throw Errors_1.Errors.argumentNull("containers");
this.parser.actions = this.parser.actions || {};
this.container = container;
this.containers = containers;
}

@@ -634,7 +622,7 @@ defaultPageNodeParser() {

}
getPage(pageUrl, values) {
getPage(pageUrl, containerName, values) {
if (!pageUrl)
throw Errors_1.Errors.argumentNull('pageUrl');
values = values || {};
let cachePage = this.cachePages[pageUrl];
let cachePage = this.cachePages[`${containerName}_${pageUrl}`];
if (cachePage != null) {

@@ -644,3 +632,3 @@ cachePage.data = values || {};

}
let page = this.createPage(pageUrl, values);
let page = this.createPage(pageUrl, containerName, values);
this.cachePages[pageUrl] = page;

@@ -650,8 +638,13 @@ this.on_pageCreated(page);

}
createPage(pageUrl, values) {
createPage(pageUrl, containerName, values) {
if (!pageUrl)
throw Errors_1.Errors.argumentNull('pageUrl');
if (!containerName)
throw Errors_1.Errors.argumentNull('containerName');
values = values || {};
let element = this.createPageElement(pageUrl);
let element = this.createPageElement(pageUrl, containerName);
let displayer = new this.pageDisplayType(this);
let container = this.containers[containerName];
if (!container)
throw Errors_1.Errors.containerIsNotExists(containerName);
console.assert(this.pageType != null);

@@ -664,4 +657,12 @@ let page = new this.pageType({

element,
container,
});
let showing = (sender) => {
for (let key in this.containers) {
if (this.containers[key] == sender.container) {
sender.container.style.removeProperty('display');
continue;
}
this.containers[key].style.display == 'none';
}
this.pageShowing.fire(this, sender);

@@ -680,8 +681,14 @@ };

}
createPageElement(pageName) {
createPageElement(pageName, containerName) {
let container = this.containers[containerName];
if (!container == null)
throw Errors_1.Errors.containerIsNotExists(containerName);
let element = document.createElement(Page_1.Page.tagName);
this.container.appendChild(element);
container.appendChild(element);
return element;
}
showPage(pageUrl, args, forceRender) {
return this.openPage(pageUrl, Application_1.Application.DefaultContainerName, args, forceRender);
}
openPage(pageUrl, containerName, args, forceRender) {
args = args || {};

@@ -693,3 +700,3 @@ forceRender = forceRender == null ? false : true;

return this.currentPage;
let { page, isNew } = this.getPage(pageUrl, args);
let { page, isNew } = this.getPage(pageUrl, containerName, args);
if (isNew || forceRender) {

@@ -696,0 +703,0 @@ let action = this.findPageAction(pageUrl);

@@ -115,6 +115,4 @@ "use strict";

_this = _possibleConstructorReturn(this, _getPrototypeOf(Application).call(this, (args || {}).container || document.body, (args || {}).parser));
_this = _possibleConstructorReturn(this, _getPrototypeOf(Application).call(this, Application.containers((args || {}).container), (args || {}).parser));
_this._runned = false;
_this.closeCurrentOnBack = null;
_this.tempPageData = undefined;
return _this;

@@ -157,3 +155,3 @@ }

_this2.showPageByUrl(url);
_this2.showPage(url);
};

@@ -173,38 +171,2 @@

}, {
key: "showPageByUrl",
value: function showPageByUrl(url) {
if (!url) throw Errors_1.Errors.argumentNull('url');
var tempPageData = this.fetchTemplatePageData();
var result = null;
if (this.closeCurrentOnBack == true) {
this.closeCurrentOnBack = null;
if (tempPageData == null) this.closeCurrentPage();else this.closeCurrentPage(tempPageData);
result = this.currentPage;
} else if (this.closeCurrentOnBack == false) {
this.closeCurrentOnBack = null;
var page = this.pageStack.pop();
if (page == null) throw new Error('page is null');
page.hide(this.currentPage);
result = this.currentPage;
}
if (result == null || result.url != url) {
result = this.showPage(url);
}
return result;
}
}, {
key: "fetchTemplatePageData",
value: function fetchTemplatePageData() {
if (this.tempPageData == null) {
return null;
}
var data = this.tempPageData;
this.tempPageData = undefined;
return data;
}
}, {
key: "setLocationHash",

@@ -219,3 +181,7 @@ value: function setLocationHash(pageUrl) {

if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl');
var page = this.showPage(pageUrl, args);
var routeData = _parseUrl(pageUrl);
var containerName = routeData.values.container || Application.DefaultContainerName;
var page = this.openPage(pageUrl, containerName, args);
var url = this.createUrl(page.name, page.data);

@@ -230,4 +196,8 @@ this.setLocationHash(url);

if (setUrl == null) setUrl = true;
var page = this.showPage(pageUrl, args, true);
var routeData = _parseUrl(pageUrl);
var containerName = routeData.values.container || Application.DefaultContainerName;
var page = this.openPage(pageUrl, containerName, args, true);
if (setUrl) {

@@ -248,13 +218,7 @@ var url = this.createUrl(page.name, page.data);

key: "back",
value: function back(closeCurrentPage, data) {
var closeCurrentPageDefault = true;
if (_typeof(closeCurrentPage) == 'object') {
data = closeCurrentPage;
closeCurrentPage = null;
}
this.closeCurrentOnBack = closeCurrentPage == null ? closeCurrentPageDefault : closeCurrentPage;
this.tempPageData = data;
history.back();
value: function back() {
this.closeCurrentPage();
setTimeout(function () {
history.back();
}, 100);
}

@@ -278,2 +242,21 @@ }, {

}
}], [{
key: "containers",
value: function containers(container) {
var r = {};
if (container == null) {
r[Application.DefaultContainerName] = document.body;
return r;
}
if (container.tagName) {
r[Application.DefaultContainerName] = container;
return r;
}
r = container;
if (!Application.DefaultContainerName) throw Errors_1.Errors.containerIsNotExists(Application.DefaultContainerName);
return r;
}
}]);

@@ -284,4 +267,5 @@

Application.DefaultContainerName = 'default';
exports.Application = Application;
});
//# sourceMappingURL=Application.js.map

@@ -172,2 +172,8 @@ "use strict";

}
}, {
key: "containerIsNotExists",
value: function containerIsNotExists(name) {
var msg = "Container '".concat(name, "' is not exists");
return new Error(msg);
}
}]);

@@ -174,0 +180,0 @@

@@ -36,2 +36,3 @@ "use strict";

this._url = params.url;
this._container = params.container;
}

@@ -137,2 +138,7 @@

}
}, {
key: "container",
get: function get() {
return this._container;
}
}]);

@@ -139,0 +145,0 @@

@@ -47,3 +47,3 @@ "use strict";

function () {
function PageMaster(container, parser) {
function PageMaster(containers, parser) {
_classCallCheck(this, PageMaster);

@@ -62,5 +62,5 @@

this.parser = parser || this.defaultPageNodeParser();
if (!container) throw Errors_1.Errors.argumentNull("container");
if (!containers) throw Errors_1.Errors.argumentNull("containers");
this.parser.actions = this.parser.actions || {};
this.container = container;
this.containers = containers;
}

@@ -169,6 +169,6 @@

key: "getPage",
value: function getPage(pageUrl, values) {
value: function getPage(pageUrl, containerName, values) {
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl');
values = values || {};
var cachePage = this.cachePages[pageUrl];
var cachePage = this.cachePages["".concat(containerName, "_").concat(pageUrl)];

@@ -183,3 +183,3 @@ if (cachePage != null) {

var page = this.createPage(pageUrl, values);
var page = this.createPage(pageUrl, containerName, values);
this.cachePages[pageUrl] = page;

@@ -194,9 +194,12 @@ this.on_pageCreated(page);

key: "createPage",
value: function createPage(pageUrl, values) {
value: function createPage(pageUrl, containerName, values) {
var _this3 = this;
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl');
if (!containerName) throw Errors_1.Errors.argumentNull('containerName');
values = values || {};
var element = this.createPageElement(pageUrl);
var element = this.createPageElement(pageUrl, containerName);
var displayer = new this.pageDisplayType(this);
var container = this.containers[containerName];
if (!container) throw Errors_1.Errors.containerIsNotExists(containerName);
console.assert(this.pageType != null);

@@ -208,6 +211,16 @@ var page = new this.pageType({

displayer: displayer,
element: element
element: element,
container: container
});
var showing = function showing(sender) {
for (var key in _this3.containers) {
if (_this3.containers[key] == sender.container) {
sender.container.style.removeProperty('display');
continue;
}
_this3.containers[key].style.display == 'none';
}
_this3.pageShowing.fire(_this3, sender);

@@ -230,5 +243,7 @@ };

key: "createPageElement",
value: function createPageElement(pageName) {
value: function createPageElement(pageName, containerName) {
var container = this.containers[containerName];
if (!container == null) throw Errors_1.Errors.containerIsNotExists(containerName);
var element = document.createElement(Page_1.Page.tagName);
this.container.appendChild(element);
container.appendChild(element);
return element;

@@ -239,2 +254,7 @@ }

value: function showPage(pageUrl, args, forceRender) {
return this.openPage(pageUrl, Application_1.Application.DefaultContainerName, args, forceRender);
}
}, {
key: "openPage",
value: function openPage(pageUrl, containerName, args, forceRender) {
args = args || {};

@@ -245,3 +265,3 @@ forceRender = forceRender == null ? false : true;

var _this$getPage = this.getPage(pageUrl, args),
var _this$getPage = this.getPage(pageUrl, containerName, args),
page = _this$getPage.page,

@@ -248,0 +268,0 @@ isNew = _this$getPage.isNew;

@@ -27,8 +27,10 @@ import { IService, ServiceConstructor } from "maishu-chitu-service";

private _runned;
private closeCurrentOnBack;
private tempPageData;
static DefaultContainerName: string;
constructor(args?: {
parser?: PageNodeParser;
container?: HTMLElement;
container?: HTMLElement | {
[name: string]: HTMLElement;
};
});
private static containers;
parseUrl(url: string): {

@@ -40,14 +42,9 @@ pageName: string;

run(): void;
private showPageByUrl;
private fetchTemplatePageData;
private setLocationHash;
setLocationHash(pageUrl: string): void;
private readonly location;
redirect<T>(pageUrl: string, args?: object): Page;
forward(pageUrl: string, args?: object, setUrl?: boolean): Page;
reload(pageName: string, args?: object): Page;
redirect<T>(pageUrl: string, args?: PageData): Page;
forward(pageUrl: string, args?: PageData, setUrl?: boolean): Page;
reload(pageName: string, args?: PageData): Page;
back(): void;
back(closeCurrentPage: boolean): void;
back(data: any): void;
back<T>(closeCurrentPage?: boolean, data?: Pick<T, StringPropertyNames<T>>): void;
createService<T extends IService>(type?: ServiceConstructor<T>): T;
}

@@ -64,7 +64,20 @@ define(["require", "exports", "maishu-chitu-service", "./PageMaster", "./Errors"], function (require, exports, maishu_chitu_service_1, PageMaster_1, Errors_1) {

constructor(args) {
super((args || {}).container || document.body, (args || {}).parser);
super(Application.containers((args || {}).container), (args || {}).parser);
this._runned = false;
this.closeCurrentOnBack = null;
this.tempPageData = undefined;
}
static containers(container) {
let r = {};
if (container == null) {
r[Application.DefaultContainerName] = document.body;
return r;
}
if (container.tagName) {
r[Application.DefaultContainerName] = container;
return r;
}
r = container;
if (!Application.DefaultContainerName)
throw Errors_1.Errors.containerIsNotExists(Application.DefaultContainerName);
return r;
}
parseUrl(url) {

@@ -92,3 +105,3 @@ if (!url)

}
this.showPageByUrl(url);
this.showPage(url);
};

@@ -105,36 +118,2 @@ showPage();

}
showPageByUrl(url) {
if (!url)
throw Errors_1.Errors.argumentNull('url');
let tempPageData = this.fetchTemplatePageData();
let result = null;
if (this.closeCurrentOnBack == true) {
this.closeCurrentOnBack = null;
if (tempPageData == null)
this.closeCurrentPage();
else
this.closeCurrentPage(tempPageData);
result = this.currentPage;
}
else if (this.closeCurrentOnBack == false) {
this.closeCurrentOnBack = null;
var page = this.pageStack.pop();
if (page == null)
throw new Error('page is null');
page.hide(this.currentPage);
result = this.currentPage;
}
if (result == null || result.url != url) {
result = this.showPage(url);
}
return result;
}
fetchTemplatePageData() {
if (this.tempPageData == null) {
return null;
}
let data = this.tempPageData;
this.tempPageData = undefined;
return data;
}
setLocationHash(pageUrl) {

@@ -150,3 +129,5 @@ this.location.hash = `#${pageUrl}`;

throw Errors_1.Errors.argumentNull('pageUrl');
let page = this.showPage(pageUrl, args);
let routeData = parseUrl(pageUrl);
let containerName = routeData.values.container || Application.DefaultContainerName;
let page = this.openPage(pageUrl, containerName, args);
let url = this.createUrl(page.name, page.data);

@@ -161,3 +142,5 @@ this.setLocationHash(url);

setUrl = true;
let page = this.showPage(pageUrl, args, true);
let routeData = parseUrl(pageUrl);
let containerName = routeData.values.container || Application.DefaultContainerName;
let page = this.openPage(pageUrl, containerName, args, true);
if (setUrl) {

@@ -173,11 +156,7 @@ let url = this.createUrl(page.name, page.data);

}
back(closeCurrentPage, data) {
const closeCurrentPageDefault = true;
if (typeof closeCurrentPage == 'object') {
data = closeCurrentPage;
closeCurrentPage = null;
}
this.closeCurrentOnBack = closeCurrentPage == null ? closeCurrentPageDefault : closeCurrentPage;
this.tempPageData = data;
history.back();
back() {
this.closeCurrentPage();
setTimeout(() => {
history.back();
}, 100);
}

@@ -193,3 +172,4 @@ createService(type) {

}
Application.DefaultContainerName = 'default';
exports.Application = Application;
});

@@ -27,2 +27,3 @@ export declare class Errors {

static unexpectedNullValue(): Error;
static containerIsNotExists(name: string): Error;
}

@@ -104,4 +104,8 @@ define(["require", "exports"], function (require, exports) {

}
static containerIsNotExists(name) {
let msg = `Container '${name}' is not exists`;
return new Error(msg);
}
}
exports.Errors = Errors;
});

@@ -19,2 +19,3 @@ import { PageMaster } from "./PageMaster";

url: string;
container: HTMLElement;
}

@@ -27,2 +28,3 @@ export declare class Page {

private _url;
private _container;
static tagName: string;

@@ -51,2 +53,3 @@ data: PageData;

readonly app: PageMaster;
readonly container: HTMLElement;
}

@@ -53,0 +56,0 @@ export interface PageConstructor {

@@ -20,2 +20,3 @@ define(["require", "exports", "maishu-chitu-service", "./Errors", "./Application"], function (require, exports, maishu_chitu_service_1, Errors_1, Application_1) {

this._url = params.url;
this._container = params.container;
}

@@ -85,2 +86,5 @@ on_showing() {

}
get container() {
return this._container;
}
}

@@ -87,0 +91,0 @@ Page.tagName = 'div';

import { Callback1, Callback2 } from "maishu-chitu-service";
import { Page, PageConstructor, PageDisplayConstructor } from "./Page";
import { Page, PageConstructor, PageDisplayConstructor, PageData } from "./Page";
import { PageNodeParser, StringPropertyNames, Action } from "./Application";

@@ -12,3 +12,3 @@ export declare class PageMaster {

private page_stack;
private container;
private containers;
private nodes;

@@ -18,3 +18,5 @@ private MAX_PAGE_COUNT;

parser: PageNodeParser;
constructor(container: HTMLElement, parser?: PageNodeParser);
constructor(containers: {
[name: string]: HTMLElement;
}, parser?: PageNodeParser);
protected defaultPageNodeParser(): PageNodeParser;

@@ -26,5 +28,6 @@ protected createDefaultAction(url: string, loadjs: (path: string) => Promise<any>): Action;

private getPage;
protected createPage(pageUrl: string, values?: any): Page;
protected createPageElement(pageName: string): HTMLElement;
showPage(pageUrl: string, args?: object, forceRender?: boolean): Page;
protected createPage(pageUrl: string, containerName: string, values?: PageData): Page;
protected createPageElement(pageName: string, containerName: string): HTMLElement;
showPage(pageUrl: string, args?: PageData, forceRender?: boolean): Page;
openPage(pageUrl: string, containerName: string, args?: PageData, forceRender?: boolean): Page;
protected closePage(page: Page): void;

@@ -31,0 +34,0 @@ private pushPage;

@@ -13,3 +13,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

class PageMaster {
constructor(container, parser) {
constructor(containers, parser) {
this.pageCreated = maishu_chitu_service_1.Callbacks();

@@ -26,6 +26,6 @@ this.pageShowing = maishu_chitu_service_1.Callbacks();

this.parser = parser || this.defaultPageNodeParser();
if (!container)
throw Errors_1.Errors.argumentNull("container");
if (!containers)
throw Errors_1.Errors.argumentNull("containers");
this.parser.actions = this.parser.actions || {};
this.container = container;
this.containers = containers;
}

@@ -86,7 +86,7 @@ defaultPageNodeParser() {

}
getPage(pageUrl, values) {
getPage(pageUrl, containerName, values) {
if (!pageUrl)
throw Errors_1.Errors.argumentNull('pageUrl');
values = values || {};
let cachePage = this.cachePages[pageUrl];
let cachePage = this.cachePages[`${containerName}_${pageUrl}`];
if (cachePage != null) {

@@ -96,3 +96,3 @@ cachePage.data = values || {};

}
let page = this.createPage(pageUrl, values);
let page = this.createPage(pageUrl, containerName, values);
this.cachePages[pageUrl] = page;

@@ -102,8 +102,13 @@ this.on_pageCreated(page);

}
createPage(pageUrl, values) {
createPage(pageUrl, containerName, values) {
if (!pageUrl)
throw Errors_1.Errors.argumentNull('pageUrl');
if (!containerName)
throw Errors_1.Errors.argumentNull('containerName');
values = values || {};
let element = this.createPageElement(pageUrl);
let element = this.createPageElement(pageUrl, containerName);
let displayer = new this.pageDisplayType(this);
let container = this.containers[containerName];
if (!container)
throw Errors_1.Errors.containerIsNotExists(containerName);
console.assert(this.pageType != null);

@@ -116,4 +121,12 @@ let page = new this.pageType({

element,
container,
});
let showing = (sender) => {
for (let key in this.containers) {
if (this.containers[key] == sender.container) {
sender.container.style.removeProperty('display');
continue;
}
this.containers[key].style.display == 'none';
}
this.pageShowing.fire(this, sender);

@@ -132,8 +145,14 @@ };

}
createPageElement(pageName) {
createPageElement(pageName, containerName) {
let container = this.containers[containerName];
if (!container == null)
throw Errors_1.Errors.containerIsNotExists(containerName);
let element = document.createElement(Page_1.Page.tagName);
this.container.appendChild(element);
container.appendChild(element);
return element;
}
showPage(pageUrl, args, forceRender) {
return this.openPage(pageUrl, Application_1.Application.DefaultContainerName, args, forceRender);
}
openPage(pageUrl, containerName, args, forceRender) {
args = args || {};

@@ -145,3 +164,3 @@ forceRender = forceRender == null ? false : true;

return this.currentPage;
let { page, isNew } = this.getPage(pageUrl, args);
let { page, isNew } = this.getPage(pageUrl, containerName, args);
if (isNew || forceRender) {

@@ -148,0 +167,0 @@ let action = this.findPageAction(pageUrl);

@@ -36,3 +36,3 @@ {

},
"version": "2.18.0"
"version": "3.0.0"
}

@@ -105,5 +105,7 @@ import { IService, ServiceConstructor, Service } from "maishu-chitu-service";

private _runned: boolean = false;
private closeCurrentOnBack: boolean | null = null;
private tempPageData: PageData | undefined = undefined;
// private closeCurrentOnBack: boolean | null = null;
// private tempPageData: PageData | undefined = undefined;
static DefaultContainerName = 'default'
/**

@@ -114,6 +116,25 @@ * 构造函数

*/
constructor(args?: { parser?: PageNodeParser, container?: HTMLElement }) {
super((args || {}).container || document.body, (args || {}).parser);
constructor(args?: { parser?: PageNodeParser, container?: HTMLElement | { [name: string]: HTMLElement } }) {
super(Application.containers((args || {}).container), (args || {}).parser);
}
private static containers(container: HTMLElement | { [name: string]: HTMLElement } | undefined): { [name: string]: HTMLElement } {
let r: { [name: string]: HTMLElement } = {}
if (container == null) {
r[Application.DefaultContainerName] = document.body
return r
}
if ((container as HTMLElement).tagName) {
r[Application.DefaultContainerName] = container as HTMLElement
return r
}
r = container as { [name: string]: HTMLElement }
if (!Application.DefaultContainerName)
throw Errors.containerIsNotExists(Application.DefaultContainerName)
return r
}
/**

@@ -157,11 +178,8 @@ * 解释路由,将路由字符串解释为 RouteData 对象

}
this.showPageByUrl(url);
this.showPage(url);
}
showPage()
// window.addEventListener('popstate', () => {
// showPage()
// });
window.addEventListener('hashchange', () => {
if(this.location.skip){
if (this.location.skip) {
delete this.location.skip

@@ -176,60 +194,3 @@ return

/**
* 显示页面
* @param url 页面的路径
*/
private showPageByUrl(url: string): Page | null {
if (!url) throw Errors.argumentNull('url');
// var routeData = this.parseUrl(url);
// if (routeData == null) {
// throw Errors.noneRouteMatched(url);
// }
let tempPageData = this.fetchTemplatePageData();
let result: Page | null = null;
//==========================================
// closeCurrentOnBack != null 表示返回操作
if (this.closeCurrentOnBack == true) {
this.closeCurrentOnBack = null;
if (tempPageData == null)
this.closeCurrentPage()
else
this.closeCurrentPage(tempPageData);
result = this.currentPage;
}
else if (this.closeCurrentOnBack == false) {
this.closeCurrentOnBack = null;
var page = this.pageStack.pop();
if (page == null)
throw new Error('page is null');
page.hide(this.currentPage);
result = this.currentPage;
}
//==========================================
if (result == null || result.url != url) {
// let args = routeData.values || {};
// if (tempPageData) {
// args = Object.assign(args, tempPageData);
// }
result = this.showPage(url);
}
return result;
}
private fetchTemplatePageData() {
if (this.tempPageData == null) {
return null;
}
let data = this.tempPageData;
this.tempPageData = undefined;
return data;
}
private setLocationHash(pageUrl: string) {
// history.pushState(EmtpyStateData, "", url)
setLocationHash(pageUrl: string) {
this.location.hash = `#${pageUrl}`

@@ -249,6 +210,8 @@ this.location.skip = true

*/
public redirect<T>(pageUrl: string, args?: object): Page {
public redirect<T>(pageUrl: string, args?: PageData): Page {
if (!pageUrl) throw Errors.argumentNull('pageUrl')
let page = this.showPage(pageUrl, args);
let routeData = parseUrl(pageUrl)
let containerName = (routeData.values.container as string) || Application.DefaultContainerName
let page = this.openPage(pageUrl, containerName, args);
let url = this.createUrl(page.name, page.data);

@@ -266,3 +229,3 @@ this.setLocationHash(url);

*/
public forward(pageUrl: string, args?: object, setUrl?: boolean) {
public forward(pageUrl: string, args?: PageData, setUrl?: boolean) {
if (!pageUrl) throw Errors.argumentNull('pageNameOrUrl')

@@ -272,3 +235,5 @@ if (setUrl == null)

let page = this.showPage(pageUrl, args, true);
let routeData = parseUrl(pageUrl)
let containerName = (routeData.values.container as string) || Application.DefaultContainerName
let page = this.openPage(pageUrl, containerName, args, true);
if (setUrl) {

@@ -278,5 +243,2 @@ let url = this.createUrl(page.name, page.data);

}
// else {
// history.pushState(pageUrl, "", "")
// }

@@ -286,16 +248,3 @@ return page;

// private showPageByNameOrUrl(pageNameOrUrl: string, args?: object, rerender?: boolean) {
// // let pageName: string
// // if (pageNameOrUrl.indexOf('?') < 0) {
// // pageName = pageNameOrUrl
// // }
// // else {
// // let obj = this.parseUrl(pageNameOrUrl);
// // pageName = obj.pageName;
// // args = Object.assign(obj.values, args || {});
// // }
// return this.showPage(pageNameOrUrl, args, rerender);
// }
public reload(pageName: string, args?: object) {
public reload(pageName: string, args?: PageData) {
let result = this.showPage(pageName, args, true)

@@ -310,16 +259,7 @@ return result

*/
public back(): void
public back(closeCurrentPage: boolean): void
public back(data: any): void
public back<T>(closeCurrentPage?: boolean, data?: Pick<T, StringPropertyNames<T>>): void
public back<T>(closeCurrentPage?: any, data?: Pick<T, StringPropertyNames<T>>): void {
const closeCurrentPageDefault = true
if (typeof closeCurrentPage == 'object') {
data = closeCurrentPage;
closeCurrentPage = null;
}
this.closeCurrentOnBack = closeCurrentPage == null ? closeCurrentPageDefault : closeCurrentPage;
this.tempPageData = data as any;
history.back();
public back(): void {
this.closeCurrentPage()
setTimeout(() => {
history.back();
}, 100)
}

@@ -326,0 +266,0 @@

@@ -101,3 +101,7 @@ export class Errors {

}
static containerIsNotExists(name: string) {
let msg = `Container '${name}' is not exists`
return new Error(msg)
}
}

@@ -25,2 +25,3 @@ import { PageMaster } from "./PageMaster";

url: string
container: HTMLElement
}

@@ -39,2 +40,3 @@

private _url: string
private _container: HTMLElement

@@ -65,2 +67,3 @@ static tagName = 'div';

this._url = params.url
this._container = params.container
}

@@ -148,2 +151,6 @@ private on_showing() {

}
get container() {
return this._container
}
}

@@ -150,0 +157,0 @@

import { Callbacks, Callback1, Callback2 } from "maishu-chitu-service";
import { Page, PageConstructor, PageDisplayConstructor, PageDisplayerImplement } from "./Page";
import { PageNodeParser, PageNode, StringPropertyNames, Action, parseUrl } from "./Application";
import { Page, PageConstructor, PageDisplayConstructor, PageDisplayerImplement, PageData } from "./Page";
import { PageNodeParser, PageNode, StringPropertyNames, Action, parseUrl, Application } from "./Application";
import { Errors } from "./Errors";

@@ -27,6 +27,7 @@

private page_stack = new Array<Page>();
private container: HTMLElement;
private containers: { [name: string]: HTMLElement };
private nodes: { [name: string]: PageNode } = {}
private MAX_PAGE_COUNT = 100
/**

@@ -43,9 +44,9 @@ * 错误事件

*/
constructor(container: HTMLElement, parser?: PageNodeParser) {
constructor(containers: { [name: string]: HTMLElement }, parser?: PageNodeParser) {
this.parser = parser || this.defaultPageNodeParser();
if (!container)
throw Errors.argumentNull("container");
if (!containers)
throw Errors.argumentNull("containers");
this.parser.actions = this.parser.actions || {};
this.container = container;
this.containers = containers;
}

@@ -121,7 +122,7 @@

private getPage(pageUrl: string, values?: any): { page: Page, isNew: boolean } {
private getPage(pageUrl: string, containerName: string, values?: PageData): { page: Page, isNew: boolean } {
if (!pageUrl) throw Errors.argumentNull('pageUrl')
values = values || {};
let cachePage = this.cachePages[pageUrl];
let cachePage = this.cachePages[`${containerName}_${pageUrl}`];
if (cachePage != null) {

@@ -132,3 +133,3 @@ cachePage.data = values || {}

let page = this.createPage(pageUrl, values);
let page = this.createPage(pageUrl, containerName, values);
this.cachePages[pageUrl] = page;

@@ -140,7 +141,13 @@

protected createPage(pageUrl: string, values?: any): Page {
protected createPage(pageUrl: string, containerName: string, values?: PageData): Page {
if (!pageUrl) throw Errors.argumentNull('pageUrl')
if (!containerName) throw Errors.argumentNull('containerName')
values = values || {}
let element = this.createPageElement(pageUrl);
let element = this.createPageElement(pageUrl, containerName);
let displayer = new this.pageDisplayType(this);
let container = this.containers[containerName]
if (!container)
throw Errors.containerIsNotExists(containerName)

@@ -154,5 +161,13 @@ console.assert(this.pageType != null);

element,
container,
});
let showing = (sender: Page) => {
for (let key in this.containers) {
if (this.containers[key] == sender.container) {
sender.container.style.removeProperty('display')
continue
}
this.containers[key].style.display == 'none'
}
this.pageShowing.fire(this, sender)

@@ -174,5 +189,9 @@ }

protected createPageElement(pageName: string) {
protected createPageElement(pageName: string, containerName: string) {
let container = this.containers[containerName]
if (!container == null)
throw Errors.containerIsNotExists(containerName)
let element: HTMLElement = document.createElement(Page.tagName);
this.container.appendChild(element);
container.appendChild(element);
return element;

@@ -187,4 +206,7 @@ }

*/
public showPage(pageUrl: string, args?: object, forceRender?: boolean): Page {
public showPage(pageUrl: string, args?: PageData, forceRender?: boolean): Page {
return this.openPage(pageUrl, Application.DefaultContainerName, args, forceRender)
}
public openPage(pageUrl: string, containerName: string, args?: PageData, forceRender?: boolean) {
args = args || {}

@@ -198,3 +220,3 @@ forceRender = forceRender == null ? false : true

let { page, isNew } = this.getPage(pageUrl, args);
let { page, isNew } = this.getPage(pageUrl, containerName, args);
if (isNew || forceRender) {

@@ -201,0 +223,0 @@ let action = this.findPageAction(pageUrl)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc