@pacem/pacem-core 1.0.0-abel
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/LICENSE +191 -0
- package/NOTICE +4 -0
- package/dist/browser/pacem-core.js +9099 -0
- package/dist/browser/pacem-core.js.map +1 -0
- package/dist/browser/pacem-core.min.js +2 -0
- package/dist/browser/pacem-core.min.js.map +1 -0
- package/dist/bundle/pacem-core.min.mjs +3 -0
- package/dist/bundle/pacem-core.mjs +8479 -0
- package/dist/bundle/pacem-core.mjs.map +7 -0
- package/dist/esm/adapter.js +7 -0
- package/dist/esm/command.js +10 -0
- package/dist/esm/comparers.js +8 -0
- package/dist/esm/converters.js +70 -0
- package/dist/esm/decorators-next.js +783 -0
- package/dist/esm/decorators.js +736 -0
- package/dist/esm/defaults.js +5 -0
- package/dist/esm/events.js +89 -0
- package/dist/esm/eventtarget.js +131 -0
- package/dist/esm/expression.js +228 -0
- package/dist/esm/index-animations.js +1 -0
- package/dist/esm/index-behaviors.js +1 -0
- package/dist/esm/index-components.js +1 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index-logging.js +1 -0
- package/dist/esm/index-net.js +1 -0
- package/dist/esm/index-root.js +20 -0
- package/dist/esm/index-ui.js +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/logger.js +11 -0
- package/dist/esm/prefix.js +6 -0
- package/dist/esm/promise.js +34 -0
- package/dist/esm/regex.js +22 -0
- package/dist/esm/storage.js +56 -0
- package/dist/esm/template.js +4 -0
- package/dist/esm/transforms.js +248 -0
- package/dist/esm/types.js +10 -0
- package/dist/esm/utils-customelement.js +524 -0
- package/dist/esm/utils-customevent.js +60 -0
- package/dist/esm/utils.js +1073 -0
- package/package.json +37 -0
- package/typings/index.d.ts +2521 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference path="utils-customevent.ts" />
|
|
2
|
+
import { Utils } from './utils';
|
|
3
|
+
import { CustomEventUtils } from './utils-customevent';
|
|
4
|
+
// namespace Pacem {
|
|
5
|
+
export class CustomTypedEvent extends CustomEvent /* new in TypeScript v2.7.1 -> */ {
|
|
6
|
+
constructor(type, detail, eventInit) {
|
|
7
|
+
super(type, Utils.extend({ detail: detail }, eventInit || {}));
|
|
8
|
+
CustomEventUtils.fixEdgeCustomEventSubClassInstance(this, this.constructor);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function isEventInit(obj) {
|
|
12
|
+
if ('detail' in obj) {
|
|
13
|
+
// must provide a detail
|
|
14
|
+
for (let prop in obj) {
|
|
15
|
+
if (prop !== 'bubbles' && prop !== 'cancelable' && prop !== 'composed' && prop !== 'detail') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
// TODO: make inherit from CustomTypedEvent
|
|
24
|
+
export class CustomUIEvent extends CustomEvent {
|
|
25
|
+
constructor(type, detail, eventInit, orig) {
|
|
26
|
+
super(type, Utils.extend((isEventInit(detail || {}) ? detail : { detail: detail }), (!(eventInit instanceof Event) && eventInit) || {}));
|
|
27
|
+
const originalEvent = orig || eventInit;
|
|
28
|
+
if (originalEvent instanceof Event) {
|
|
29
|
+
this.#originalEvent = originalEvent;
|
|
30
|
+
this.#modifiers = CustomEventUtils.getEventKeyModifiers(originalEvent);
|
|
31
|
+
if (originalEvent instanceof MouseEvent || originalEvent instanceof TouchEvent) {
|
|
32
|
+
this.#coords = CustomEventUtils.getEventCoordinates(originalEvent);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
CustomEventUtils.fixEdgeCustomEventSubClassInstance(this, this.constructor);
|
|
36
|
+
}
|
|
37
|
+
#originalEvent;
|
|
38
|
+
#modifiers;
|
|
39
|
+
#coords;
|
|
40
|
+
get originalEvent() {
|
|
41
|
+
return this.#originalEvent;
|
|
42
|
+
}
|
|
43
|
+
get which() {
|
|
44
|
+
return this.#modifiers?.which;
|
|
45
|
+
}
|
|
46
|
+
get altKey() {
|
|
47
|
+
return this.#modifiers?.altKey;
|
|
48
|
+
}
|
|
49
|
+
get shiftKey() {
|
|
50
|
+
return this.#modifiers?.shiftKey;
|
|
51
|
+
}
|
|
52
|
+
get ctrlKey() {
|
|
53
|
+
return this.#modifiers?.ctrlKey;
|
|
54
|
+
}
|
|
55
|
+
get metaKey() {
|
|
56
|
+
return this.#modifiers?.metaKey;
|
|
57
|
+
}
|
|
58
|
+
get pageX() {
|
|
59
|
+
return this.#coords?.page.x;
|
|
60
|
+
}
|
|
61
|
+
get pageY() {
|
|
62
|
+
return this.#coords?.page.y;
|
|
63
|
+
}
|
|
64
|
+
get clientX() {
|
|
65
|
+
return this.#coords?.client.x;
|
|
66
|
+
}
|
|
67
|
+
get clientY() {
|
|
68
|
+
return this.#coords?.client.y;
|
|
69
|
+
}
|
|
70
|
+
get screenX() {
|
|
71
|
+
return this.#coords?.screen.x;
|
|
72
|
+
}
|
|
73
|
+
get screenY() {
|
|
74
|
+
return this.#coords?.screen.y;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export const AttributeChangeEventName = 'attributechange';
|
|
78
|
+
export class AttributeChangeEvent extends CustomTypedEvent {
|
|
79
|
+
constructor(args) {
|
|
80
|
+
super(AttributeChangeEventName, args);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const PropertyChangeEventName = 'propertychange';
|
|
84
|
+
export class PropertyChangeEvent extends CustomTypedEvent {
|
|
85
|
+
constructor(args) {
|
|
86
|
+
super(PropertyChangeEventName, args);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/// <reference path="converters.ts" />
|
|
2
|
+
/// <reference path="decorators.ts" />
|
|
3
|
+
/// <reference path="logger.ts" />
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
import { Expression } from './expression';
|
|
11
|
+
import { LogLevel } from './logger';
|
|
12
|
+
import { INSTANCE_SCOPE_VAR } from './types';
|
|
13
|
+
import { Utils } from './utils';
|
|
14
|
+
import { CustomElementUtils } from './utils-customelement';
|
|
15
|
+
import { Watch } from './decorators';
|
|
16
|
+
import { PropertyConverters } from './converters';
|
|
17
|
+
//namespace Pacem.Components {
|
|
18
|
+
export class PacemEventTarget extends HTMLElement {
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this._isReady = false;
|
|
22
|
+
this.emitHandler = (evt) => {
|
|
23
|
+
// no handlers processed if the element is disabled.
|
|
24
|
+
if (!this.disabled) {
|
|
25
|
+
this.emit(evt);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Executes the relevant handler defined in the `on-{evt.type}` attribute, if any.
|
|
31
|
+
* @param evt {Event} the event to be fired
|
|
32
|
+
*/
|
|
33
|
+
emit(evt) {
|
|
34
|
+
if (evt.defaultPrevented) {
|
|
35
|
+
// skip if evt was canceled
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this._emitCore(evt);
|
|
39
|
+
}
|
|
40
|
+
_emitCore(evt) {
|
|
41
|
+
var attrName = `on-${evt.type.toLowerCase()}`;
|
|
42
|
+
if (attrName in this.attributes) {
|
|
43
|
+
this.log(LogLevel.Debug, `Calling ${attrName} handler for event ${evt.type}`);
|
|
44
|
+
var attrBody = this.attributes[attrName].value;
|
|
45
|
+
var expression = Expression.parse(attrBody, this);
|
|
46
|
+
if (!Utils.isNull(expression) && expression.pending !== true) {
|
|
47
|
+
expression.evaluatePlus({ '$event': evt });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
handle(evt, detail) {
|
|
52
|
+
if (typeof evt === 'string') {
|
|
53
|
+
evt = Utils.isNull(detail) ? new Event(evt, { cancelable: false }) : new CustomEvent(evt, { cancelable: false, detail });
|
|
54
|
+
}
|
|
55
|
+
this.emit(evt);
|
|
56
|
+
}
|
|
57
|
+
/** Gets whether the element has been completely loaded alongside with the other pieces of the DOM. */
|
|
58
|
+
get isReady() {
|
|
59
|
+
return this._isReady;
|
|
60
|
+
}
|
|
61
|
+
connectedCallback() {
|
|
62
|
+
CustomElementUtils.setAttachedPropertyValue(this, INSTANCE_SCOPE_VAR, CustomElementUtils.findScopeContext(this));
|
|
63
|
+
this.log(LogLevel.Debug, `Connected.`);
|
|
64
|
+
}
|
|
65
|
+
disconnectedCallback() {
|
|
66
|
+
this._isReady = false;
|
|
67
|
+
this.dispatchEvent(new Event('unload'));
|
|
68
|
+
CustomElementUtils.deleteAttachedPropertyValue(this, INSTANCE_SCOPE_VAR);
|
|
69
|
+
this.log(LogLevel.Debug, `Disconnected.`);
|
|
70
|
+
}
|
|
71
|
+
viewActivatedCallback() {
|
|
72
|
+
this._isReady = true;
|
|
73
|
+
this.log(LogLevel.Debug, `Loaded (view activated).`);
|
|
74
|
+
this.dispatchEvent(new Event('load'));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Manages the value change of a watched property.
|
|
78
|
+
* @param name {string} property name
|
|
79
|
+
* @param old {any} former property value
|
|
80
|
+
* @param val {any} new/current property value
|
|
81
|
+
* @param first {boolean} whether is the first change (right before view activation) or not
|
|
82
|
+
*/
|
|
83
|
+
propertyChangedCallback(name, old, val, first) {
|
|
84
|
+
if (first)
|
|
85
|
+
this.log(LogLevel.Log, `Property "${name}" changed at start-up`);
|
|
86
|
+
else
|
|
87
|
+
this.log(LogLevel.Log, `Property "${name}" changed from ${old} to ${val}`);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Wraps the native dispatchEvent in order to emit `on-{evt-type}` handler, if any.
|
|
91
|
+
* @param evt {Event} the event to be fired
|
|
92
|
+
*/
|
|
93
|
+
dispatchEvent(evt) {
|
|
94
|
+
// no events dispatched if the element is disabled.
|
|
95
|
+
if (this.disabled) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
this.log(LogLevel.Log, `Dispatching event "${evt.type}"`);
|
|
99
|
+
const ret = super.dispatchEvent(evt);
|
|
100
|
+
this.emit(evt);
|
|
101
|
+
return ret;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Logs a message if a logger is available.
|
|
105
|
+
* @param level {LogLevel} Level of log
|
|
106
|
+
* @param message {String} Content
|
|
107
|
+
* @param category {String} Grouping category
|
|
108
|
+
*/
|
|
109
|
+
log(level, message, category = this.localName + (this.id ? '#' + this.id : '')) {
|
|
110
|
+
this.logger && typeof this.logger.log === 'function' && this.logger.log(level, message, category);
|
|
111
|
+
}
|
|
112
|
+
/** Refreshes all the properties corresponding to explicit binding attributes. */
|
|
113
|
+
refreshBindings() {
|
|
114
|
+
// refresh all the bindings
|
|
115
|
+
for (let j = 0; j < this.attributes.length; j++) {
|
|
116
|
+
let attr = this.attributes.item(j), isBinding = CustomElementUtils.isBindingAttribute(attr.value);
|
|
117
|
+
if (!isBinding)
|
|
118
|
+
continue;
|
|
119
|
+
let prop = CustomElementUtils.kebabToCamel(attr.name);
|
|
120
|
+
let binding = CustomElementUtils.parseBindingAttribute(attr.value, this);
|
|
121
|
+
this[prop] = binding.evaluate();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
__decorate([
|
|
126
|
+
Watch({ reflectBack: true, converter: PropertyConverters.Boolean })
|
|
127
|
+
], PacemEventTarget.prototype, "disabled", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
Watch({ emit: false, converter: PropertyConverters.Element })
|
|
130
|
+
], PacemEventTarget.prototype, "logger", void 0);
|
|
131
|
+
//}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/// <reference path="types.ts" />
|
|
2
|
+
/// <reference path="utils.ts" />
|
|
3
|
+
/// <reference path="utils-customelement.ts" />
|
|
4
|
+
import { DeferPromise } from './promise';
|
|
5
|
+
import { Utils } from './utils';
|
|
6
|
+
import { CustomElementUtils, Repeater } from './utils-customelement';
|
|
7
|
+
const CONTEXT_PREFIX = '__context_pacem';
|
|
8
|
+
/** the following pattern matches:
|
|
9
|
+
* -------------------------------
|
|
10
|
+
* ciao "a tutti \"quanti\" voi" -> "a tutti \"quanti\" voi"
|
|
11
|
+
* ciao 'a tutti "quanti" voi'+ mysel.value + 'e a nessun\' altra' -> 'a tutti "quanti" voi'
|
|
12
|
+
* 'e a nessun\' altra'
|
|
13
|
+
*/
|
|
14
|
+
const stringPattern = /'(\\'|[^'])*[^\\]?'|"(\\"|[^"])*[^\\]?"/g;
|
|
15
|
+
/** the following pattern matches:
|
|
16
|
+
* -------------------------------
|
|
17
|
+
* var l = new Date(); -> new
|
|
18
|
+
* window.eval( -> window.
|
|
19
|
+
* eval( -> eval(
|
|
20
|
+
* eval ( -> eval (
|
|
21
|
+
*/
|
|
22
|
+
const safetyPattern = /[^\w]new\s|[^\w]window\s*[\.\[]|[^\w]document\s*\.|[^\w]eval\s*\(/;
|
|
23
|
+
/** the following pattern matches:
|
|
24
|
+
* -------------------------------
|
|
25
|
+
* ^^^item.ciao -> ^^^item
|
|
26
|
+
* !ciao.value -> !ciao.
|
|
27
|
+
* :host.value -> :host.
|
|
28
|
+
* ::child.prop -> ::child.
|
|
29
|
+
* _connectTo(me.value) -> (me.
|
|
30
|
+
* 009.ciao ->
|
|
31
|
+
* this[that.value] -> [that.
|
|
32
|
+
*/
|
|
33
|
+
const variablePattern = /(^|[\s\(\[\+\-\*\/!])(:host\.|\^+item[\s\.,;\)\]]|\^+item$|\^+index[^\w\.]|\^+index$|\$?this[\.\s$]?|#[a-zA-Z_][\w]*|::[a-zA-Z_][\w]*)/g;
|
|
34
|
+
///** the following pattern tests:
|
|
35
|
+
// * -------------------------------
|
|
36
|
+
// * __context.$this.myself.value -> true
|
|
37
|
+
// * !__context.myelem.value -> false
|
|
38
|
+
// * fn(myelem.value) -> false
|
|
39
|
+
// * $this == that -> false
|
|
40
|
+
// * ...
|
|
41
|
+
// */
|
|
42
|
+
//const purePropertyPathPattern = /^[\w\.\$]+/;
|
|
43
|
+
export class Expression {
|
|
44
|
+
constructor() {
|
|
45
|
+
this._pending = false;
|
|
46
|
+
this._independent = false;
|
|
47
|
+
}
|
|
48
|
+
get dependencies() {
|
|
49
|
+
return this._dependencies;
|
|
50
|
+
}
|
|
51
|
+
get functionBody() {
|
|
52
|
+
return this._fnBody;
|
|
53
|
+
}
|
|
54
|
+
get voidBody() {
|
|
55
|
+
return this._voidBody;
|
|
56
|
+
}
|
|
57
|
+
get pending() {
|
|
58
|
+
return this._pending;
|
|
59
|
+
}
|
|
60
|
+
get independent() {
|
|
61
|
+
return this._independent;
|
|
62
|
+
}
|
|
63
|
+
evaluate() {
|
|
64
|
+
if (!this._fn) {
|
|
65
|
+
this._fn = new Function('$pacem', CONTEXT_PREFIX, this._fnBody);
|
|
66
|
+
}
|
|
67
|
+
return this._fn.apply(null, [Utils.core, this._args]);
|
|
68
|
+
}
|
|
69
|
+
evaluateAsync() {
|
|
70
|
+
const deferred = DeferPromise.defer();
|
|
71
|
+
if (!this._fn) {
|
|
72
|
+
this._fn = new Function('$pacem', CONTEXT_PREFIX, this._fnBody);
|
|
73
|
+
}
|
|
74
|
+
deferred.resolve(this._fn.apply(null, [Utils.core, this._args]));
|
|
75
|
+
return deferred.promise;
|
|
76
|
+
}
|
|
77
|
+
evaluatePlus(args = {}) {
|
|
78
|
+
if (!this._fn) {
|
|
79
|
+
let argNames = [CONTEXT_PREFIX];
|
|
80
|
+
for (var prop in args)
|
|
81
|
+
argNames.push(prop);
|
|
82
|
+
argNames.push('$pacem');
|
|
83
|
+
this._fn = new Function(argNames.join(', '), this._voidBody);
|
|
84
|
+
}
|
|
85
|
+
let argValues = [].concat(this._args);
|
|
86
|
+
for (var prop in args)
|
|
87
|
+
argValues.push(args[prop]);
|
|
88
|
+
argValues.push(Utils.core);
|
|
89
|
+
return this._fn.apply(null, argValues);
|
|
90
|
+
}
|
|
91
|
+
static { this._pendingExpression = null; }
|
|
92
|
+
static _getPendingExpressionSingleton() {
|
|
93
|
+
if (Expression._pendingExpression == null) {
|
|
94
|
+
let xpr = new Expression();
|
|
95
|
+
xpr._pending = true;
|
|
96
|
+
xpr._dependencies = [];
|
|
97
|
+
Expression._pendingExpression = xpr;
|
|
98
|
+
}
|
|
99
|
+
return Expression._pendingExpression;
|
|
100
|
+
}
|
|
101
|
+
static parse(expression, element) {
|
|
102
|
+
var context = CustomElementUtils.findScopeContext(element);
|
|
103
|
+
var args = { '$this': element };
|
|
104
|
+
var dependencies = [];
|
|
105
|
+
var expr = '';
|
|
106
|
+
var independent = true;
|
|
107
|
+
//1. remove strings
|
|
108
|
+
var strings = [], stringMatches, index = 0, trunks = [];
|
|
109
|
+
while ((stringMatches = stringPattern.exec(expression)) != null) {
|
|
110
|
+
trunks.push(expression.substr(index, stringMatches.index - index));
|
|
111
|
+
let length = stringMatches[0].length;
|
|
112
|
+
strings.push({ start: stringMatches.index, length: length });
|
|
113
|
+
index = stringMatches.index + length;
|
|
114
|
+
}
|
|
115
|
+
if (index < expression.length)
|
|
116
|
+
trunks.push(expression.substr(index, expression.length - index));
|
|
117
|
+
//2. loop non string trunks
|
|
118
|
+
// trunks.length >= strings.length (more precisely, the following statemente is always `true`:
|
|
119
|
+
// trunks.length === strings.length || trunks.length === strings.length+1;
|
|
120
|
+
for (var j = 0; j < trunks.length; j++) {
|
|
121
|
+
let trunk = trunks[j];
|
|
122
|
+
if (safetyPattern.test(trunk))
|
|
123
|
+
throw `Unsafe expression detected: "${trunk}".`;
|
|
124
|
+
if (context == null) {
|
|
125
|
+
// context is null, means viewActivated event still to be fired.
|
|
126
|
+
// check whether this is a constant expression (then no need to instantiate actual binding listeners)
|
|
127
|
+
// or not.
|
|
128
|
+
if (new RegExp(variablePattern).test(trunk) === true) {
|
|
129
|
+
independent = false;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
let processedTrunk = trunk.replace(variablePattern, (mwhole, mstart, melem, index, input) => {
|
|
135
|
+
independent = false;
|
|
136
|
+
const cmpRef = `__host_pacem`;
|
|
137
|
+
// default initialization := assumes `this`
|
|
138
|
+
let retval = CONTEXT_PREFIX + '.$this' + (melem.endsWith('.') ? '.' : ''), el = element, dotIndex = input.indexOf('.', index), furtherParts = dotIndex > index ? input.substr(dotIndex + 1).trim() : '', pathRegexArray = /^[\w\.\$]+/.exec(furtherParts), path = pathRegexArray && pathRegexArray.length > 0 && pathRegexArray[0], propArray, prop = path && (propArray = path.split('.')).length > 0 && propArray[0];
|
|
139
|
+
if (melem === ':host.') {
|
|
140
|
+
el = args[cmpRef] = args[cmpRef] || CustomElementUtils.findHostContext(element);
|
|
141
|
+
retval = `${CONTEXT_PREFIX}.${cmpRef}.`;
|
|
142
|
+
}
|
|
143
|
+
else if (melem.endsWith('^item') || melem.substr(0, melem.length - 1).endsWith('^item')) {
|
|
144
|
+
let lastChar = melem.endsWith('^item') ? '' : melem.substr(melem.length - 1, 1);
|
|
145
|
+
let upLevels = melem.length - (lastChar.length > 0 ? 6 : 5); // 5 = 'item'.length + 1 (zero-based)
|
|
146
|
+
let itemRef = `__item_${upLevels}_up_pacem`;
|
|
147
|
+
let item = Repeater.findItemContext(element, upLevels);
|
|
148
|
+
el = args[itemRef] = args[itemRef] || (item && item.placeholder);
|
|
149
|
+
path = 'item' + (path ? ('.' + path) : '');
|
|
150
|
+
prop = 'item';
|
|
151
|
+
retval = `${CONTEXT_PREFIX}.${itemRef}.item${lastChar}`;
|
|
152
|
+
}
|
|
153
|
+
else if (melem.endsWith('^index') || melem.substr(0, melem.length - 1).endsWith('^index')) {
|
|
154
|
+
let lastChar = melem.endsWith('^index') ? '' : melem.substr(melem.length - 1, 1);
|
|
155
|
+
let upLevels = melem.length - (lastChar.length > 0 ? 7 : 6); // 6 = 'index'.length + 1 (zero-based)
|
|
156
|
+
let itemRef = `__item_${upLevels}_up_pacem`;
|
|
157
|
+
let item = Repeater.findItemContext(element, upLevels);
|
|
158
|
+
el = args[itemRef] = args[itemRef] || (item && item.placeholder);
|
|
159
|
+
path = 'index';
|
|
160
|
+
prop = 'index';
|
|
161
|
+
retval = `${CONTEXT_PREFIX}.${itemRef}.index${lastChar}`;
|
|
162
|
+
}
|
|
163
|
+
else if (melem.startsWith('::')) {
|
|
164
|
+
let melem0 = melem.substr(2, melem.length - 2);
|
|
165
|
+
let host = args[cmpRef] = args[cmpRef] || CustomElementUtils.findHostContext(element);
|
|
166
|
+
if (!Utils.isNull(host)) {
|
|
167
|
+
el = host[melem0];
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
el = null;
|
|
171
|
+
}
|
|
172
|
+
retval = `${CONTEXT_PREFIX}.${cmpRef}.${melem0}`;
|
|
173
|
+
}
|
|
174
|
+
else if (melem.startsWith('#')) {
|
|
175
|
+
let melem0 = melem.substr(1, melem.length - 1);
|
|
176
|
+
el = args[melem0] = args[melem0] || context.querySelector('#' + melem0);
|
|
177
|
+
retval = `${CONTEXT_PREFIX}.${melem0}`;
|
|
178
|
+
}
|
|
179
|
+
// merge dependencies
|
|
180
|
+
if (prop && el && prop in el
|
|
181
|
+
// && it is not a direct method call (which means that the 'prop' isn't in fact a 'func')
|
|
182
|
+
&& typeof el[prop] !== 'function' //!isMethodCall
|
|
183
|
+
// && does not already exist as a dependency
|
|
184
|
+
&& dependencies.find(d => d.element === el && d.property == prop) == null) {
|
|
185
|
+
dependencies.push({ element: el, property: prop, path: path, twowayAllowed: false });
|
|
186
|
+
}
|
|
187
|
+
// return value
|
|
188
|
+
return mstart + retval;
|
|
189
|
+
});
|
|
190
|
+
expr += processedTrunk;
|
|
191
|
+
if (j < strings.length) {
|
|
192
|
+
const s = strings[j];
|
|
193
|
+
expr += expression.substr(s.start, s.length);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (independent) {
|
|
198
|
+
// constant expression
|
|
199
|
+
var constexpr = new Expression();
|
|
200
|
+
constexpr._independent = true;
|
|
201
|
+
constexpr._fnBody = `return ${expression};`;
|
|
202
|
+
constexpr._voidBody = expression;
|
|
203
|
+
constexpr._dependencies = [];
|
|
204
|
+
return constexpr;
|
|
205
|
+
}
|
|
206
|
+
if (context == null) {
|
|
207
|
+
return this._getPendingExpressionSingleton();
|
|
208
|
+
}
|
|
209
|
+
// if some dependency elements aren't available yet, then postpone...
|
|
210
|
+
for (var elem in args) {
|
|
211
|
+
if (args[elem] == null)
|
|
212
|
+
return Expression._getPendingExpressionSingleton();
|
|
213
|
+
}
|
|
214
|
+
if (dependencies.length == 1
|
|
215
|
+
// := && trimmed expression contains only letters, figures, underscores, dots, and '$'...
|
|
216
|
+
&& /[^\w\.\$]+/.test(expr.trim()) !== true) {
|
|
217
|
+
// ...then 'twoway' binding might be applied/accepted
|
|
218
|
+
dependencies[0].twowayAllowed = true;
|
|
219
|
+
}
|
|
220
|
+
var retexpr = new Expression();
|
|
221
|
+
retexpr._args = args;
|
|
222
|
+
retexpr._fnBody = `try{ var ___$$$r = ${expr}; return ___$$$r; }catch(e){ }`;
|
|
223
|
+
retexpr._voidBody = `try{ ${expr} }catch(e){ }`;
|
|
224
|
+
retexpr._dependencies = dependencies;
|
|
225
|
+
return retexpr;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './animations';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components/index.behaviors';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './net';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './trees';
|
|
2
|
+
export * from './utils';
|
|
3
|
+
export * from './utils-customelement';
|
|
4
|
+
export * from './utils-customevent';
|
|
5
|
+
export * from './adapter';
|
|
6
|
+
export * from './command';
|
|
7
|
+
export * from './comparers';
|
|
8
|
+
export * from './converters';
|
|
9
|
+
export * from './decorators';
|
|
10
|
+
export * from './defaults';
|
|
11
|
+
export * from './events';
|
|
12
|
+
export * from './eventtarget';
|
|
13
|
+
export * from './expression';
|
|
14
|
+
export * from './prefix';
|
|
15
|
+
export * from './promise';
|
|
16
|
+
export * from './regex';
|
|
17
|
+
export * from './storage';
|
|
18
|
+
export * from './template';
|
|
19
|
+
export * from './transforms';
|
|
20
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ui';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as Animations from './index-animations';
|
|
2
|
+
export * as Net from './index-net';
|
|
3
|
+
export * as UI from './index-ui';
|
|
4
|
+
export * as Components from './index-components';
|
|
5
|
+
export * as Behaviors from './index-behaviors';
|
|
6
|
+
export * as Logging from './index-logging';
|
|
7
|
+
export * from './index-root';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//namespace Pacem.Logging {
|
|
2
|
+
export var LogLevel;
|
|
3
|
+
(function (LogLevel) {
|
|
4
|
+
LogLevel["Trace"] = "trace";
|
|
5
|
+
LogLevel["Debug"] = "debug";
|
|
6
|
+
LogLevel["Warn"] = "warn";
|
|
7
|
+
LogLevel["Error"] = "error";
|
|
8
|
+
LogLevel["Info"] = "info";
|
|
9
|
+
LogLevel["Log"] = "log";
|
|
10
|
+
})(LogLevel || (LogLevel = {}));
|
|
11
|
+
//}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//namespace Pacem {
|
|
2
|
+
export class DeferPromise {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.deferred = null;
|
|
5
|
+
var me = this;
|
|
6
|
+
me.promise = new Promise(function (resolve, reject) {
|
|
7
|
+
me.deferred = { 'resolve': resolve, 'reject': reject, 'promise': me };
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
then(onCompleted, onFailed) {
|
|
11
|
+
return this.promise.then(onCompleted, onFailed);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Occurs whenever the promise concludes (either after completion or error).
|
|
15
|
+
* @param {Function } callback
|
|
16
|
+
*/
|
|
17
|
+
finally(callback) {
|
|
18
|
+
this.promise.then(callback, callback);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
success(callback) {
|
|
22
|
+
this.promise.then(callback, null);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
error(callback) {
|
|
26
|
+
this.promise.then(null, callback);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
static defer() {
|
|
30
|
+
var q = new DeferPromise();
|
|
31
|
+
return q.deferred;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//namespace Pacem.RegularExpressions {
|
|
2
|
+
export const EMPTY_MATCHER = /a^/;
|
|
3
|
+
export class Regex {
|
|
4
|
+
/**
|
|
5
|
+
* Splits an input string into segments based on a matching pattern.
|
|
6
|
+
* @param input Input string
|
|
7
|
+
* @param pattern RegExp pattern
|
|
8
|
+
*/
|
|
9
|
+
static split(input, pattern) {
|
|
10
|
+
var matches, index = 0, trunks = [];
|
|
11
|
+
while ((matches = pattern.exec(input)) != null) {
|
|
12
|
+
trunks.push({ value: input.substr(index, matches.index - index), match: false, index: index });
|
|
13
|
+
let length = matches[0].length;
|
|
14
|
+
trunks.push({ value: input.substr(matches.index, length), match: true, index: matches.index });
|
|
15
|
+
index = matches.index + length;
|
|
16
|
+
}
|
|
17
|
+
if (index < input.length)
|
|
18
|
+
trunks.push({ value: input.substr(index, input.length - index), match: false, index: index });
|
|
19
|
+
return trunks;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Utils } from './utils';
|
|
2
|
+
//namespace Pacem {
|
|
3
|
+
const EXPIRATION_FIELD = '_exp';
|
|
4
|
+
export class Storage {
|
|
5
|
+
_getStorage(persistent) {
|
|
6
|
+
return !!persistent ? window.localStorage : window.sessionStorage;
|
|
7
|
+
}
|
|
8
|
+
_parseValue(storage, name) {
|
|
9
|
+
const value = storage.getItem(name);
|
|
10
|
+
if (Utils.isNullOrEmpty(value)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const output = Utils.Json.parse(value);
|
|
14
|
+
if (!Object.hasOwnProperty(EXPIRATION_FIELD)) {
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
const exp = output[EXPIRATION_FIELD];
|
|
18
|
+
if (exp < Date.now()) {
|
|
19
|
+
storage.removeItem(name);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return output['value'];
|
|
23
|
+
}
|
|
24
|
+
setPropertyValue(name, value, persistent) {
|
|
25
|
+
var storage = this._getStorage(persistent === true || (typeof persistent === 'number' && persistent > 0));
|
|
26
|
+
var storedValue = value;
|
|
27
|
+
// set cache timeout
|
|
28
|
+
if (typeof persistent === 'number' && persistent > 0) {
|
|
29
|
+
const exp = Date.now() + 1000 * persistent;
|
|
30
|
+
storedValue = { value: value };
|
|
31
|
+
storedValue[EXPIRATION_FIELD] = exp;
|
|
32
|
+
}
|
|
33
|
+
storage.setItem(name, Utils.Json.stringify(storedValue));
|
|
34
|
+
// delete omonymy
|
|
35
|
+
storage = this._getStorage(!persistent);
|
|
36
|
+
storage.removeItem(name);
|
|
37
|
+
}
|
|
38
|
+
getPropertyValue(name) {
|
|
39
|
+
return this._parseValue(this._getStorage(false), name)
|
|
40
|
+
|| this._parseValue(this._getStorage(true), name);
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
var storage = this._getStorage(true);
|
|
44
|
+
storage.clear();
|
|
45
|
+
storage = this._getStorage(false);
|
|
46
|
+
storage.clear();
|
|
47
|
+
}
|
|
48
|
+
;
|
|
49
|
+
removeProperty(name) {
|
|
50
|
+
var storage = this._getStorage(true);
|
|
51
|
+
storage.removeItem(name);
|
|
52
|
+
storage = this._getStorage(false);
|
|
53
|
+
storage.removeItem(name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//}
|