@pitaya-components/app
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -6,3 +6,3 @@ export interface PitayaConfigurationObject | ||
scrollHistory: { | ||
mode: "always" | "never" | "onlyBack"; | ||
mode: "always" | "never" | "onlyUp"; | ||
}; | ||
@@ -9,0 +9,0 @@ } |
@@ -7,3 +7,3 @@ "use strict"; | ||
scrollHistory: { | ||
mode: "onlyBack" | ||
mode: "onlyUp" | ||
} | ||
@@ -10,0 +10,0 @@ }; |
import { NavigationInstruction, PipelineResult } from "aurelia-router"; | ||
export declare class NavigationLevelHistory | ||
{ | ||
get current(): number | undefined; | ||
get previous(): number | undefined; | ||
} | ||
export declare class PiApp | ||
@@ -42,10 +35,2 @@ { | ||
/** | ||
* Holds information regarding the navigation level of recent route changes | ||
*/ | ||
public navigationLevel: { | ||
current: number | ||
previous: number; | ||
}; | ||
/** | ||
* Navigates to another view/route. | ||
@@ -52,0 +37,0 @@ */ |
@@ -27,2 +27,4 @@ "use strict"; | ||
const aurelia_typed_observable_plugin_1 = require("aurelia-typed-observable-plugin"); | ||
const controllers_1 = require("../controllers/controllers"); | ||
const pi_app_controller_1 = require("../controllers/pi-app-controller"); | ||
const utils_1 = require("../helpers/utils"); | ||
@@ -32,5 +34,9 @@ aurelia_typed_observable_plugin_1.usePropertyTypeForBindable(true); | ||
const META_THEME_COLOR_SELECTOR = "meta[name=theme-color]"; | ||
const META_THEME_COLOR_ELEMENT_STRING = "<meta name='theme-color' value='#FFFFFF'>"; | ||
const logger = aurelia_framework_1.LogManager.getLogger("Pitaya:App"); | ||
const META_THEME_COLOR_ELEMENT_STRING = "<meta name='theme-color'>"; | ||
let currentInstance; | ||
const ViewAnimationClasses = { | ||
lowerToHigher: "pi-app--transition-lower-to-higher", | ||
higherToLower: "pi-app--transition-higher-to-lower", | ||
equal: "pi-app--transition-equal" | ||
}; | ||
const navigationLevel = { | ||
@@ -40,17 +46,8 @@ current: undefined, | ||
}; | ||
class NavigationLevelHistory { | ||
get current() { | ||
return navigationLevel.current; | ||
} | ||
get previous() { | ||
return navigationLevel.previous; | ||
} | ||
} | ||
exports.NavigationLevelHistory = NavigationLevelHistory; | ||
let PiApp = class PiApp { | ||
constructor(_eventAggregator, _router, _routerConfiguration) { | ||
constructor(_rootElement, _eventAggregator, _router) { | ||
this._rootElement = _rootElement; | ||
this._eventAggregator = _eventAggregator; | ||
this._router = _router; | ||
this._routerConfiguration = _routerConfiguration; | ||
this._transitionAnimationClass = "pi-app--transition-equal-to-equal"; | ||
this._transitionAnimationClass = ViewAnimationClasses.equal; | ||
this._isOnline = navigator.onLine; | ||
@@ -94,14 +91,8 @@ this._scopedOnlineMethod = this._onOnline.bind(this); | ||
currentInstance = this; | ||
this._routeProcessingSubscribtion = this._eventAggregator.subscribe("router:navigation:processing", this._handleRouteProcessing.bind(this)); | ||
this._routingProcessingSubscription = this._eventAggregator.subscribe("router:navigation:processing", this._handleRouteProcessing.bind(this)); | ||
controllers_1.Controllers.register(this, this._controller = new pi_app_controller_1.PiAppController()); | ||
} | ||
bind() { | ||
this.statusBarColorChanged(this.statusBarColor); | ||
const metaElement = document.querySelector(META_THEME_COLOR_SELECTOR); | ||
if (!metaElement) { | ||
this._themeColorMetaElement = metaElement ? metaElement : document.head.appendChild(utils_1.createElement(META_THEME_COLOR_ELEMENT_STRING)); | ||
this.statusBarColor && this.statusBarColorChanged(this.statusBarColor); | ||
return; | ||
} | ||
this._themeColorMetaElement = metaElement; | ||
!metaElement.hasAttribute("value") && this.statusBarColorChanged(this.statusBarColor || "#FFFFFF"); | ||
this._initializeMetaElement(); | ||
this._populateController(); | ||
} | ||
@@ -117,3 +108,3 @@ attached() { | ||
unbind() { | ||
this._routeProcessingSubscribtion.dispose(); | ||
this._routingProcessingSubscription.dispose(); | ||
currentInstance = undefined; | ||
@@ -133,26 +124,29 @@ } | ||
} | ||
_initializeMetaElement() { | ||
const metaElement = (document.querySelector(META_THEME_COLOR_SELECTOR) || document.head.appendChild(utils_1.createElement(META_THEME_COLOR_ELEMENT_STRING))); | ||
this._themeColorMetaElement = metaElement; | ||
this.statusBarColor && this.statusBarColorChanged(this.statusBarColor); | ||
} | ||
_handleRouteProcessing({ instruction }) { | ||
var _a, _b, _c, _d; | ||
const isFirstRoute = !instruction.previousInstruction; | ||
const nextLevel = (((_b = (_a = instruction.config) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.level) || 0); | ||
navigationLevel.current = nextLevel; | ||
if (isFirstRoute) { | ||
const nextLevel = (instruction.config.navModel.settings.level || 0); | ||
navigationLevel.current = nextLevel; | ||
return; | ||
} | ||
try { | ||
const previousLevel = (instruction.previousInstruction.config.navModel.settings.level || 0); | ||
const nextLevel = (instruction.config.navModel.settings.level || 0); | ||
navigationLevel.previous = previousLevel; | ||
navigationLevel.current = nextLevel; | ||
if (previousLevel > nextLevel) { | ||
return this._transitionAnimationClass = "pi-app--transition-lower-to-higher"; | ||
} | ||
else if (previousLevel < nextLevel) { | ||
return this._transitionAnimationClass = "pi-app--transition-higher-to-lower"; | ||
} | ||
this._transitionAnimationClass = "pi-app--transition-equal-to-equal"; | ||
} | ||
catch (error) { | ||
logger.error(`Route '${instruction.config.route}' has not been found or has false configuration.`, `Original error: ${error}`); | ||
} | ||
const previousLevel = (((_d = (_c = instruction.previousInstruction.config) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.level) || 0); | ||
const direction = previousLevel > nextLevel ? "lowerToHigher" : previousLevel < nextLevel ? "higherToLower" : "equal"; | ||
navigationLevel.previous = previousLevel; | ||
this._transitionAnimationClass = ViewAnimationClasses[direction]; | ||
} | ||
_cleanUpAnimation() { | ||
this._transitionAnimationClass = ""; | ||
} | ||
_populateController() { | ||
this._controller.navigationLevelHistory = navigationLevel; | ||
this._controller.themeColorMetaElement = this._themeColorMetaElement; | ||
this._controller.cleanUpAnimation = this._cleanUpAnimation.bind(this); | ||
this._controller.initialized = true; | ||
} | ||
}; | ||
@@ -178,5 +172,5 @@ __decorate([ | ||
aurelia_framework_1.viewResources(aurelia_pal_1.PLATFORM.moduleName("./pi-app.css")), | ||
__metadata("design:paramtypes", [aurelia_event_aggregator_1.EventAggregator, | ||
aurelia_router_1.Router, | ||
aurelia_router_1.RouterConfiguration]) | ||
__metadata("design:paramtypes", [Element, | ||
aurelia_event_aggregator_1.EventAggregator, | ||
aurelia_router_1.Router]) | ||
], PiApp); | ||
@@ -183,0 +177,0 @@ exports.PiApp = PiApp; |
@@ -46,8 +46,2 @@ export interface ViewScrollOptions | ||
/** | ||
* Inner HTML element which holds the actual content. | ||
* Also the <slot> content gets projected there. | ||
*/ | ||
get innerElement(): HTMLElement; | ||
/** | ||
* The navigation level of the view component. | ||
@@ -54,0 +48,0 @@ * Depends on the route configuration settings (settings.level) |
@@ -25,13 +25,13 @@ "use strict"; | ||
const aurelia_typed_observable_plugin_1 = require("aurelia-typed-observable-plugin"); | ||
const pi_view_controller_1 = require("../controllers/pi-view-controller"); | ||
const configuration_1 = require("../configuration"); | ||
const controllers_1 = require("../controllers/controllers"); | ||
const pi_app_1 = require("../elements/pi-app"); | ||
aurelia_typed_observable_plugin_1.usePropertyTypeForBindable(true); | ||
aurelia_typed_observable_plugin_1.usePropertyTypeForObservable(true); | ||
const VIEW_ACTIVE_LEAVE_CLASS = "au-leave-active"; | ||
const scrollHistory = new Map(); | ||
let PiView = class PiView { | ||
constructor(_rootElement, _levelHistory, _queue, _router, _config) { | ||
var _a, _b, _c, _d; | ||
constructor(_rootElement, _queue, _router, _config) { | ||
var _a, _b, _c; | ||
this._rootElement = _rootElement; | ||
this._levelHistory = _levelHistory; | ||
this._queue = _queue; | ||
@@ -44,4 +44,5 @@ this._router = _router; | ||
this._scopedOfflineMethod = this._onOffline.bind(this); | ||
this._routeFragment = ((_a = this._router.currentInstruction) === null || _a === void 0 ? void 0 : _a.fragment) || ""; | ||
this._level = ((_d = (_c = (_b = this._router.currentInstruction) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.level) || 0; | ||
this._appController = controllers_1.getControllerOf(pi_app_1.PiApp.instance); | ||
this._routeFragment = (_a = this._router.currentInstruction) === null || _a === void 0 ? void 0 : _a.fragment; | ||
this._level = ((_c = (_b = this._router.currentInstruction) === null || _b === void 0 ? void 0 : _b.config.settings) === null || _c === void 0 ? void 0 : _c.level) || 0; | ||
} | ||
@@ -51,5 +52,2 @@ get level() { | ||
} | ||
get innerElement() { | ||
return this._innerElement; | ||
} | ||
get scrollTop() { | ||
@@ -70,3 +68,7 @@ return this._rootElement.scrollTop; | ||
this._setOnBeforeDetachedListener(owningView); | ||
controllers_1.Controllers.register(this, this._controller = new pi_view_controller_1.PiViewController()); | ||
} | ||
bind() { | ||
this._populateController(); | ||
} | ||
attached() { | ||
@@ -76,3 +78,2 @@ this._handleScrollHistory(); | ||
window.addEventListener("offline", this._scopedOfflineMethod); | ||
this._setAnimationListener(); | ||
this._queue.queueMicroTask(() => { | ||
@@ -82,2 +83,3 @@ var _a; | ||
}); | ||
this._setAnimationListener(); | ||
} | ||
@@ -91,2 +93,3 @@ detached() { | ||
_handleScrollHistory() { | ||
var _a; | ||
const { scrollHistoryMode } = this._config; | ||
@@ -97,7 +100,4 @@ const scrollHeight = scrollHistory.get(this._routeFragment); | ||
} | ||
if (scrollHistoryMode === "onlyBack") { | ||
const higherToLower = this._levelHistory.previous < this._level; | ||
if (higherToLower) { | ||
return; | ||
} | ||
if (scrollHistoryMode === "onlyUp" && ((_a = this._appController) === null || _a === void 0 ? void 0 : _a.navigationLevelHistory.previous) < this._level) { | ||
return; | ||
} | ||
@@ -108,11 +108,3 @@ this.scrollTo(scrollHeight, { | ||
} | ||
_willBeAnimated() { | ||
const siblings = [...this._rootElement.parentElement.children]; | ||
return siblings.some(sibling => sibling !== this._rootElement && sibling.classList.contains(VIEW_ACTIVE_LEAVE_CLASS)); | ||
} | ||
_setAnimationListener() { | ||
if (!this._willBeAnimated()) { | ||
this._onAnimationEnd(); | ||
return; | ||
} | ||
this._rootElement.addEventListener("animationend", this._onAnimationEnd.bind(this), { once: true }); | ||
@@ -129,3 +121,6 @@ } | ||
_onAnimationEnd() { | ||
var _a; | ||
this._animationReady = true; | ||
this._controller.animationReady = true; | ||
(_a = this._appController) === null || _a === void 0 ? void 0 : _a.cleanUpAnimation(); | ||
this.onAnimated && this.onAnimated({ component: this }); | ||
@@ -145,2 +140,8 @@ } | ||
} | ||
_populateController() { | ||
this._controller.innerElement = this._innerElement; | ||
this._controller.routeFragment = this._routeFragment; | ||
this._controller.scrollHistory = scrollHistory; | ||
this._controller.initialized = true; | ||
} | ||
}; | ||
@@ -179,3 +180,2 @@ __decorate([ | ||
__metadata("design:paramtypes", [Element, | ||
pi_app_1.NavigationLevelHistory, | ||
aurelia_framework_1.TaskQueue, | ||
@@ -182,0 +182,0 @@ aurelia_router_1.Router, |
@@ -7,5 +7,5 @@ import { NavigationOptions } from "aurelia-history"; | ||
type OnlyIfFunctions = { | ||
"online": OnlyIfFunction; | ||
"offline": OnlyIfFunction; | ||
"under development": OnlyIfFunction; | ||
online: OnlyIfFunction; | ||
offline: OnlyIfFunction; | ||
development: OnlyIfFunction; | ||
[ key: string ]: OnlyIfFunction; | ||
@@ -63,2 +63,7 @@ }; | ||
/** | ||
* Lets you add a custom "onlyIf" condition, which can then be used as the string parameter when defining the "@onlyIf.is()" decorator method | ||
*/ | ||
export declare function addOnlyIfCondition( name: string, condition: OnlyIfFunction ): void; | ||
export interface RouterDecoratorConfig | ||
@@ -69,3 +74,3 @@ { | ||
unknownRoutes?: RouteConfigSpecifier; | ||
callback?: ( config: RouterConfiguration ) => void; | ||
configure?: ( config: RouterConfiguration ) => void; | ||
} | ||
@@ -72,0 +77,0 @@ |
@@ -19,9 +19,9 @@ "use strict"; | ||
exports.onlyIfFunctions = { | ||
"online"() { | ||
online() { | ||
return navigator.onLine; | ||
}, | ||
"offline"() { | ||
offline() { | ||
return !navigator.onLine; | ||
}, | ||
"under development"() { | ||
development() { | ||
return aurelia_framework_1.Container.instance.get(configuration_1.PitayaComponentConfiguration).developmentEnabled; | ||
@@ -79,3 +79,3 @@ } | ||
exports.app = { | ||
router({ title, routesConfig, unknownRoutes, callback }) { | ||
router({ title, routesConfig, unknownRoutes, configure }) { | ||
return function (constructor) { | ||
@@ -90,3 +90,3 @@ return class extends constructor { | ||
config.mapUnknownRoutes(mainRoute.moduleId); | ||
callback && callback(config); | ||
configure && configure(config); | ||
}); | ||
@@ -108,3 +108,7 @@ } | ||
}; | ||
function addOnlyIfCondition(name, condition) { | ||
exports.onlyIfFunctions[name] = condition; | ||
} | ||
exports.addOnlyIfCondition = addOnlyIfCondition; | ||
//# sourceMappingURL=decorators.js.map |
@@ -8,4 +8,8 @@ import { FrameworkConfiguration } from "aurelia-framework"; | ||
export * from "./elements/pi-view"; | ||
export * from "./controllers/controllers"; | ||
export * from "./controllers/pi-controller"; | ||
export * from "./controllers/pi-app-controller"; | ||
export * from "./controllers/pi-view-controller"; | ||
export * from "./helpers/decorators"; | ||
export * from "./helpers/utils"; | ||
export * from "./configuration"; |
@@ -46,2 +46,6 @@ "use strict"; | ||
__export(require("./elements/pi-view")); | ||
__export(require("./controllers/controllers")); | ||
__export(require("./controllers/pi-controller")); | ||
__export(require("./controllers/pi-app-controller")); | ||
__export(require("./controllers/pi-view-controller")); | ||
__export(require("./helpers/decorators")); | ||
@@ -48,0 +52,0 @@ __export(require("./helpers/utils")); |
@@ -6,3 +6,3 @@ export interface PitayaConfigurationObject | ||
scrollHistory: { | ||
mode: "always" | "never" | "onlyBack"; | ||
mode: "always" | "never" | "onlyUp"; | ||
}; | ||
@@ -9,0 +9,0 @@ } |
@@ -5,3 +5,3 @@ const config = { | ||
scrollHistory: { | ||
mode: "onlyBack" | ||
mode: "onlyUp" | ||
} | ||
@@ -8,0 +8,0 @@ }; |
import { NavigationInstruction, PipelineResult } from "aurelia-router"; | ||
export declare class NavigationLevelHistory | ||
{ | ||
get current(): number | undefined; | ||
get previous(): number | undefined; | ||
} | ||
export declare class PiApp | ||
@@ -42,10 +35,2 @@ { | ||
/** | ||
* Holds information regarding the navigation level of recent route changes | ||
*/ | ||
public navigationLevel: { | ||
current: number | ||
previous: number; | ||
}; | ||
/** | ||
* Navigates to another view/route. | ||
@@ -52,0 +37,0 @@ */ |
@@ -21,6 +21,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
import { EventAggregator } from "aurelia-event-aggregator"; | ||
import { LogManager, viewResources } from "aurelia-framework"; | ||
import { viewResources } from "aurelia-framework"; | ||
import { PLATFORM } from "aurelia-pal"; | ||
import { Router, RouterConfiguration } from "aurelia-router"; | ||
import { Router } from "aurelia-router"; | ||
import { bindable, usePropertyTypeForBindable, usePropertyTypeForObservable } from "aurelia-typed-observable-plugin"; | ||
import { Controllers } from "../controllers/controllers"; | ||
import { PiAppController } from "../controllers/pi-app-controller"; | ||
import { createElement } from "../helpers/utils"; | ||
@@ -30,5 +32,9 @@ usePropertyTypeForBindable(true); | ||
const META_THEME_COLOR_SELECTOR = "meta[name=theme-color]"; | ||
const META_THEME_COLOR_ELEMENT_STRING = "<meta name='theme-color' value='#FFFFFF'>"; | ||
const logger = LogManager.getLogger("Pitaya:App"); | ||
const META_THEME_COLOR_ELEMENT_STRING = "<meta name='theme-color'>"; | ||
let currentInstance; | ||
const ViewAnimationClasses = { | ||
lowerToHigher: "pi-app--transition-lower-to-higher", | ||
higherToLower: "pi-app--transition-higher-to-lower", | ||
equal: "pi-app--transition-equal" | ||
}; | ||
const navigationLevel = { | ||
@@ -38,16 +44,8 @@ current: undefined, | ||
}; | ||
export class NavigationLevelHistory { | ||
get current() { | ||
return navigationLevel.current; | ||
} | ||
get previous() { | ||
return navigationLevel.previous; | ||
} | ||
} | ||
let PiApp = class PiApp { | ||
constructor(_eventAggregator, _router, _routerConfiguration) { | ||
constructor(_rootElement, _eventAggregator, _router) { | ||
this._rootElement = _rootElement; | ||
this._eventAggregator = _eventAggregator; | ||
this._router = _router; | ||
this._routerConfiguration = _routerConfiguration; | ||
this._transitionAnimationClass = "pi-app--transition-equal-to-equal"; | ||
this._transitionAnimationClass = ViewAnimationClasses.equal; | ||
this._isOnline = navigator.onLine; | ||
@@ -91,14 +89,8 @@ this._scopedOnlineMethod = this._onOnline.bind(this); | ||
currentInstance = this; | ||
this._routeProcessingSubscribtion = this._eventAggregator.subscribe("router:navigation:processing", this._handleRouteProcessing.bind(this)); | ||
this._routingProcessingSubscription = this._eventAggregator.subscribe("router:navigation:processing", this._handleRouteProcessing.bind(this)); | ||
Controllers.register(this, this._controller = new PiAppController()); | ||
} | ||
bind() { | ||
this.statusBarColorChanged(this.statusBarColor); | ||
const metaElement = document.querySelector(META_THEME_COLOR_SELECTOR); | ||
if (!metaElement) { | ||
this._themeColorMetaElement = metaElement ? metaElement : document.head.appendChild(createElement(META_THEME_COLOR_ELEMENT_STRING)); | ||
this.statusBarColor && this.statusBarColorChanged(this.statusBarColor); | ||
return; | ||
} | ||
this._themeColorMetaElement = metaElement; | ||
!metaElement.hasAttribute("value") && this.statusBarColorChanged(this.statusBarColor || "#FFFFFF"); | ||
this._initializeMetaElement(); | ||
this._populateController(); | ||
} | ||
@@ -114,3 +106,3 @@ attached() { | ||
unbind() { | ||
this._routeProcessingSubscribtion.dispose(); | ||
this._routingProcessingSubscription.dispose(); | ||
currentInstance = undefined; | ||
@@ -130,26 +122,29 @@ } | ||
} | ||
_initializeMetaElement() { | ||
const metaElement = (document.querySelector(META_THEME_COLOR_SELECTOR) || document.head.appendChild(createElement(META_THEME_COLOR_ELEMENT_STRING))); | ||
this._themeColorMetaElement = metaElement; | ||
this.statusBarColor && this.statusBarColorChanged(this.statusBarColor); | ||
} | ||
_handleRouteProcessing({ instruction }) { | ||
var _a, _b, _c, _d; | ||
const isFirstRoute = !instruction.previousInstruction; | ||
const nextLevel = (((_b = (_a = instruction.config) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.level) || 0); | ||
navigationLevel.current = nextLevel; | ||
if (isFirstRoute) { | ||
const nextLevel = (instruction.config.navModel.settings.level || 0); | ||
navigationLevel.current = nextLevel; | ||
return; | ||
} | ||
try { | ||
const previousLevel = (instruction.previousInstruction.config.navModel.settings.level || 0); | ||
const nextLevel = (instruction.config.navModel.settings.level || 0); | ||
navigationLevel.previous = previousLevel; | ||
navigationLevel.current = nextLevel; | ||
if (previousLevel > nextLevel) { | ||
return this._transitionAnimationClass = "pi-app--transition-lower-to-higher"; | ||
} | ||
else if (previousLevel < nextLevel) { | ||
return this._transitionAnimationClass = "pi-app--transition-higher-to-lower"; | ||
} | ||
this._transitionAnimationClass = "pi-app--transition-equal-to-equal"; | ||
} | ||
catch (error) { | ||
logger.error(`Route '${instruction.config.route}' has not been found or has false configuration.`, `Original error: ${error}`); | ||
} | ||
const previousLevel = (((_d = (_c = instruction.previousInstruction.config) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.level) || 0); | ||
const direction = previousLevel > nextLevel ? "lowerToHigher" : previousLevel < nextLevel ? "higherToLower" : "equal"; | ||
navigationLevel.previous = previousLevel; | ||
this._transitionAnimationClass = ViewAnimationClasses[direction]; | ||
} | ||
_cleanUpAnimation() { | ||
this._transitionAnimationClass = ""; | ||
} | ||
_populateController() { | ||
this._controller.navigationLevelHistory = navigationLevel; | ||
this._controller.themeColorMetaElement = this._themeColorMetaElement; | ||
this._controller.cleanUpAnimation = this._cleanUpAnimation.bind(this); | ||
this._controller.initialized = true; | ||
} | ||
}; | ||
@@ -175,5 +170,5 @@ __decorate([ | ||
viewResources(PLATFORM.moduleName("./pi-app.css")), | ||
__metadata("design:paramtypes", [EventAggregator, | ||
Router, | ||
RouterConfiguration]) | ||
__metadata("design:paramtypes", [Element, | ||
EventAggregator, | ||
Router]) | ||
], PiApp); | ||
@@ -180,0 +175,0 @@ export { PiApp }; |
@@ -46,8 +46,2 @@ export interface ViewScrollOptions | ||
/** | ||
* Inner HTML element which holds the actual content. | ||
* Also the <slot> content gets projected there. | ||
*/ | ||
get innerElement(): HTMLElement; | ||
/** | ||
* The navigation level of the view component. | ||
@@ -54,0 +48,0 @@ * Depends on the route configuration settings (settings.level) |
@@ -23,13 +23,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
import { bindable, usePropertyTypeForBindable, usePropertyTypeForObservable } from "aurelia-typed-observable-plugin"; | ||
import { PiViewController } from "../controllers/pi-view-controller"; | ||
import { PitayaComponentConfiguration } from "../configuration"; | ||
import { NavigationLevelHistory } from "../elements/pi-app"; | ||
import { Controllers, getControllerOf } from "../controllers/controllers"; | ||
import { PiApp } from "../elements/pi-app"; | ||
usePropertyTypeForBindable(true); | ||
usePropertyTypeForObservable(true); | ||
const VIEW_ACTIVE_LEAVE_CLASS = "au-leave-active"; | ||
const scrollHistory = new Map(); | ||
let PiView = class PiView { | ||
constructor(_rootElement, _levelHistory, _queue, _router, _config) { | ||
var _a, _b, _c, _d; | ||
constructor(_rootElement, _queue, _router, _config) { | ||
var _a, _b, _c; | ||
this._rootElement = _rootElement; | ||
this._levelHistory = _levelHistory; | ||
this._queue = _queue; | ||
@@ -42,4 +42,5 @@ this._router = _router; | ||
this._scopedOfflineMethod = this._onOffline.bind(this); | ||
this._routeFragment = ((_a = this._router.currentInstruction) === null || _a === void 0 ? void 0 : _a.fragment) || ""; | ||
this._level = ((_d = (_c = (_b = this._router.currentInstruction) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.level) || 0; | ||
this._appController = getControllerOf(PiApp.instance); | ||
this._routeFragment = (_a = this._router.currentInstruction) === null || _a === void 0 ? void 0 : _a.fragment; | ||
this._level = ((_c = (_b = this._router.currentInstruction) === null || _b === void 0 ? void 0 : _b.config.settings) === null || _c === void 0 ? void 0 : _c.level) || 0; | ||
} | ||
@@ -49,5 +50,2 @@ get level() { | ||
} | ||
get innerElement() { | ||
return this._innerElement; | ||
} | ||
get scrollTop() { | ||
@@ -68,3 +66,7 @@ return this._rootElement.scrollTop; | ||
this._setOnBeforeDetachedListener(owningView); | ||
Controllers.register(this, this._controller = new PiViewController()); | ||
} | ||
bind() { | ||
this._populateController(); | ||
} | ||
attached() { | ||
@@ -74,3 +76,2 @@ this._handleScrollHistory(); | ||
window.addEventListener("offline", this._scopedOfflineMethod); | ||
this._setAnimationListener(); | ||
this._queue.queueMicroTask(() => { | ||
@@ -80,2 +81,3 @@ var _a; | ||
}); | ||
this._setAnimationListener(); | ||
} | ||
@@ -89,2 +91,3 @@ detached() { | ||
_handleScrollHistory() { | ||
var _a; | ||
const { scrollHistoryMode } = this._config; | ||
@@ -95,7 +98,4 @@ const scrollHeight = scrollHistory.get(this._routeFragment); | ||
} | ||
if (scrollHistoryMode === "onlyBack") { | ||
const higherToLower = this._levelHistory.previous < this._level; | ||
if (higherToLower) { | ||
return; | ||
} | ||
if (scrollHistoryMode === "onlyUp" && ((_a = this._appController) === null || _a === void 0 ? void 0 : _a.navigationLevelHistory.previous) < this._level) { | ||
return; | ||
} | ||
@@ -106,11 +106,3 @@ this.scrollTo(scrollHeight, { | ||
} | ||
_willBeAnimated() { | ||
const siblings = [...this._rootElement.parentElement.children]; | ||
return siblings.some(sibling => sibling !== this._rootElement && sibling.classList.contains(VIEW_ACTIVE_LEAVE_CLASS)); | ||
} | ||
_setAnimationListener() { | ||
if (!this._willBeAnimated()) { | ||
this._onAnimationEnd(); | ||
return; | ||
} | ||
this._rootElement.addEventListener("animationend", this._onAnimationEnd.bind(this), { once: true }); | ||
@@ -127,3 +119,6 @@ } | ||
_onAnimationEnd() { | ||
var _a; | ||
this._animationReady = true; | ||
this._controller.animationReady = true; | ||
(_a = this._appController) === null || _a === void 0 ? void 0 : _a.cleanUpAnimation(); | ||
this.onAnimated && this.onAnimated({ component: this }); | ||
@@ -143,2 +138,8 @@ } | ||
} | ||
_populateController() { | ||
this._controller.innerElement = this._innerElement; | ||
this._controller.routeFragment = this._routeFragment; | ||
this._controller.scrollHistory = scrollHistory; | ||
this._controller.initialized = true; | ||
} | ||
}; | ||
@@ -177,3 +178,2 @@ __decorate([ | ||
__metadata("design:paramtypes", [Element, | ||
NavigationLevelHistory, | ||
TaskQueue, | ||
@@ -180,0 +180,0 @@ Router, |
@@ -7,5 +7,5 @@ import { NavigationOptions } from "aurelia-history"; | ||
type OnlyIfFunctions = { | ||
"online": OnlyIfFunction; | ||
"offline": OnlyIfFunction; | ||
"under development": OnlyIfFunction; | ||
online: OnlyIfFunction; | ||
offline: OnlyIfFunction; | ||
development: OnlyIfFunction; | ||
[ key: string ]: OnlyIfFunction; | ||
@@ -63,2 +63,7 @@ }; | ||
/** | ||
* Lets you add a custom "onlyIf" condition, which can then be used as the string parameter when defining the "@onlyIf.is()" decorator method | ||
*/ | ||
export declare function addOnlyIfCondition( name: string, condition: OnlyIfFunction ): void; | ||
export interface RouterDecoratorConfig | ||
@@ -69,3 +74,3 @@ { | ||
unknownRoutes?: RouteConfigSpecifier; | ||
callback?: ( config: RouterConfiguration ) => void; | ||
configure?: ( config: RouterConfiguration ) => void; | ||
} | ||
@@ -72,0 +77,0 @@ |
@@ -17,9 +17,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
export const onlyIfFunctions = { | ||
"online"() { | ||
online() { | ||
return navigator.onLine; | ||
}, | ||
"offline"() { | ||
offline() { | ||
return !navigator.onLine; | ||
}, | ||
"under development"() { | ||
development() { | ||
return Container.instance.get(PitayaComponentConfiguration).developmentEnabled; | ||
@@ -77,3 +77,3 @@ } | ||
export const app = { | ||
router({ title, routesConfig, unknownRoutes, callback }) { | ||
router({ title, routesConfig, unknownRoutes, configure }) { | ||
return function (constructor) { | ||
@@ -88,3 +88,3 @@ return class extends constructor { | ||
config.mapUnknownRoutes(mainRoute.moduleId); | ||
callback && callback(config); | ||
configure && configure(config); | ||
}); | ||
@@ -106,3 +106,6 @@ } | ||
}; | ||
export function addOnlyIfCondition(name, condition) { | ||
onlyIfFunctions[name] = condition; | ||
} | ||
//# sourceMappingURL=decorators.js.map |
@@ -8,4 +8,8 @@ import { FrameworkConfiguration } from "aurelia-framework"; | ||
export * from "./elements/pi-view"; | ||
export * from "./controllers/controllers"; | ||
export * from "./controllers/pi-controller"; | ||
export * from "./controllers/pi-app-controller"; | ||
export * from "./controllers/pi-view-controller"; | ||
export * from "./helpers/decorators"; | ||
export * from "./helpers/utils"; | ||
export * from "./configuration"; |
@@ -40,2 +40,6 @@ import { Container, PLATFORM } from "aurelia-framework"; | ||
export * from "./elements/pi-view"; | ||
export * from "./controllers/controllers"; | ||
export * from "./controllers/pi-controller"; | ||
export * from "./controllers/pi-app-controller"; | ||
export * from "./controllers/pi-view-controller"; | ||
export * from "./helpers/decorators"; | ||
@@ -42,0 +46,0 @@ export * from "./helpers/utils"; |
{ | ||
"name": "@pitaya-components/app", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "Aurelia plugin which helps building faster views and provides additional utility functionality.", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138005
84
1942