p-elements-core 1.2.0-rc7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +29 -0
- package/demo/sample.js +20 -0
- package/{screen.css → demo/screen.css} +0 -0
- package/{theme.css → demo/theme.css} +0 -0
- package/dist/p-elements-core-modern.js +3 -4
- package/dist/p-elements-core.js +3 -14
- package/index.html +9 -9
- package/older-browsers-webpack.config.js +60 -0
- package/p-elements-core.d.ts +70 -20
- package/package.json +22 -46
- package/src/cache.ts +34 -0
- package/src/custom-element.ts +303 -0
- package/src/custom-style-element.ts +38 -20
- package/src/dom.ts +133 -0
- package/src/h.ts +86 -0
- package/src/index.ts +40 -0
- package/src/interfaces.ts +15 -0
- package/src/mapping.ts +79 -0
- package/src/projection.ts +730 -0
- package/src/projector.ts +110 -0
- package/src/sample.tsx +112 -50
- package/tsconfig.json +1 -1
- package/webpack.config.js +52 -162
- package/dist/sample.js +0 -2
- package/global.js +0 -1
- package/karma.conf.js +0 -32
- package/src/commonjs.js +0 -182
- package/src/custom-event-polyfill.js +0 -78
- package/src/index.tsx +0 -23
- package/src/sample.css +0 -20
- package/src/sample.spec.ts +0 -112
- package/src/utils/custom-element.ts +0 -241
- package/src/utils/maquette.ts +0 -1328
- package/types/custom-style-element.d.ts +0 -3
- package/types/index.d.ts +0 -1
- package/types/sample.d.ts +0 -1
- package/types/utils/custom-element.d.ts +0 -29
- package/types/utils/maquette.d.ts +0 -521
- package/webpack.config.karma.js +0 -35
package/src/commonjs.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sample
|
|
3
|
-
* <script src="./common-js.js" id="common-js" data-main-path="/demo/" defer></script>
|
|
4
|
-
* Promise.all([
|
|
5
|
-
* module.import("jquery"), // main file from the latest module version from unpkg cdn
|
|
6
|
-
* module.import("./sample-module"), // file from data-module location
|
|
7
|
-
* module.import("@pggm/p-age-picker@=1.0.11/dist/p-age-picker.js"), // a file from a specific module version from pggmlab
|
|
8
|
-
* module.import("@pggm/p-ajax-form/dist/p-ajax-form") // a file from the latest module version from pggmlab
|
|
9
|
-
* ]);
|
|
10
|
-
*
|
|
11
|
-
* */
|
|
12
|
-
(function CommonJS(info, el) {
|
|
13
|
-
var mainPath = document.querySelector("script[data-main-path]");
|
|
14
|
-
if (!mainPath) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var protoPath = /^(?:[a-z]+:)?\/\//;
|
|
19
|
-
var npmPath = /^[@a-zA-Z_-]/;
|
|
20
|
-
var __filename = info._ || el && el.getAttribute('data-main-path');
|
|
21
|
-
|
|
22
|
-
var normalize = function (url) {
|
|
23
|
-
if (protoPath.test(url)) {
|
|
24
|
-
return url;
|
|
25
|
-
}
|
|
26
|
-
if (npmPath.test(url)) {
|
|
27
|
-
var ret = gModule._path(url);
|
|
28
|
-
return ret;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var path = __filename.slice(0, __filename.lastIndexOf('/'));
|
|
32
|
-
var length = url.length;
|
|
33
|
-
var c;
|
|
34
|
-
var i = 0;
|
|
35
|
-
|
|
36
|
-
for (var p = 0; i < length; p = i + 1) {
|
|
37
|
-
i = url.indexOf('/', p);
|
|
38
|
-
if (i < 0) {
|
|
39
|
-
i = length;
|
|
40
|
-
path += '/' + url.slice(p);
|
|
41
|
-
if (!/\.js$/i.test(path)) {
|
|
42
|
-
path += '.js';
|
|
43
|
-
}
|
|
44
|
-
} else if (i === 0) {
|
|
45
|
-
path = '';
|
|
46
|
-
} else {
|
|
47
|
-
c = p;
|
|
48
|
-
p = i;
|
|
49
|
-
while (p && url.charAt(p - 1) === '.') --p;
|
|
50
|
-
switch (i - p) {
|
|
51
|
-
case 0:
|
|
52
|
-
path += '/' + url.slice(c, i);
|
|
53
|
-
break;
|
|
54
|
-
case 1:
|
|
55
|
-
break;
|
|
56
|
-
case 2:
|
|
57
|
-
path = path.slice(0, path.lastIndexOf('/'));
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return path;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
var onload = function (xhr, path, resolve) {
|
|
66
|
-
var html = document.documentElement;
|
|
67
|
-
var script = document.createElement('script');
|
|
68
|
-
script.setAttribute('nonce', gModule._nonce);
|
|
69
|
-
script.textContent = 'module.$(function(){' +
|
|
70
|
-
'var module=' + gModule._cjs + '(arguments[0]),' +
|
|
71
|
-
'__filename=module.filename,' +
|
|
72
|
-
'__dirname=__filename.slice(0,__filename.lastIndexOf("/")),' +
|
|
73
|
-
'require=module.require,' +
|
|
74
|
-
'exports=module.exports;(function(){"use strict";\n' +
|
|
75
|
-
xhr.responseText +
|
|
76
|
-
';\n}.call(exports));return module.exports;' +
|
|
77
|
-
'}(module));';
|
|
78
|
-
gModule._ = path;
|
|
79
|
-
gModule.$ = function (exports) {
|
|
80
|
-
resolve(gModule._cache[path] = exports);
|
|
81
|
-
};
|
|
82
|
-
setTimeout(function () {
|
|
83
|
-
html.removeChild(script);
|
|
84
|
-
}, 1);
|
|
85
|
-
html.appendChild(script);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
var error = function (path, xhr) {
|
|
89
|
-
throw (gModule._cache[path] = new Error(xhr.statusText));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
var load = function (path) {
|
|
93
|
-
var remote = path;
|
|
94
|
-
var m = /^((?:[a-z]+?:\/\/)?[^/]+)\/([^@]+)@latest(\/.*)?$/.exec(path);
|
|
95
|
-
|
|
96
|
-
var resolve = function (exports) {
|
|
97
|
-
module = exports;
|
|
98
|
-
};
|
|
99
|
-
var xhr;
|
|
100
|
-
var module;
|
|
101
|
-
if (m || path.indexOf('@') === 0) {
|
|
102
|
-
xhr = new XMLHttpRequest();
|
|
103
|
-
//todo: implement this in pggmlab
|
|
104
|
-
var npmurl = 'https://pggmlab.azurewebsites.net/latest/' + m[2];
|
|
105
|
-
xhr.open('GET', npmurl, false);
|
|
106
|
-
xhr.send(null);
|
|
107
|
-
if (xhr.status < 400) {
|
|
108
|
-
module = JSON.parse(xhr.responseText);
|
|
109
|
-
} else {
|
|
110
|
-
return error(path, xhr);
|
|
111
|
-
}
|
|
112
|
-
remote = m[1] + '/' + m[2] + '@' + module.version + (m[3] || '');
|
|
113
|
-
}
|
|
114
|
-
xhr = new XMLHttpRequest();
|
|
115
|
-
xhr.open('GET', remote, false);
|
|
116
|
-
xhr.send(module = null);
|
|
117
|
-
if (xhr.status < 400) {
|
|
118
|
-
onload(xhr, path, resolve);
|
|
119
|
-
} else {
|
|
120
|
-
error(path, xhr);
|
|
121
|
-
}
|
|
122
|
-
return module;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
var exports = {};
|
|
126
|
-
var module = {
|
|
127
|
-
filename: __filename,
|
|
128
|
-
exports: exports,
|
|
129
|
-
require: function (url) {
|
|
130
|
-
var path = normalize(url);
|
|
131
|
-
return gModule._cache[path] || load(path);
|
|
132
|
-
},
|
|
133
|
-
import: function (url) {
|
|
134
|
-
var path = normalize(url);
|
|
135
|
-
return Promise.resolve(
|
|
136
|
-
gModule._cache[path] ||
|
|
137
|
-
(gModule._cache[path] = new Promise(
|
|
138
|
-
function (resolve, reject) {
|
|
139
|
-
var xhr = new XMLHttpRequest();
|
|
140
|
-
xhr.open('GET', path, true);
|
|
141
|
-
xhr.onreadystatechange = function () {
|
|
142
|
-
if (xhr.readyState == 4) {
|
|
143
|
-
if (xhr.status < 400) onload(xhr, path, resolve);
|
|
144
|
-
else reject(new Error(xhr.statusText));
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
xhr.send(null);
|
|
148
|
-
}
|
|
149
|
-
))
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
var gModule = window.module || module;
|
|
155
|
-
if (gModule === module) {
|
|
156
|
-
window.global = window;
|
|
157
|
-
window.module = module;
|
|
158
|
-
window.process = {
|
|
159
|
-
browser: true
|
|
160
|
-
};
|
|
161
|
-
module._cache = Object.create(null);
|
|
162
|
-
module._nonce = el ? el.getAttribute('nonce') : null;
|
|
163
|
-
module._cjs = '' + CommonJS;
|
|
164
|
-
module._path = function (url) {
|
|
165
|
-
var i = url.indexOf('/');
|
|
166
|
-
if(url[0] === "@") {
|
|
167
|
-
i = url.split('/', 2).join('/').length;
|
|
168
|
-
}
|
|
169
|
-
var npmCdn = 'https://unpkg.com/';
|
|
170
|
-
if(url.indexOf('@pggm/') === 0) {
|
|
171
|
-
npmCdn = 'https://pggmlab.azurewebsites.net/unpkg/';
|
|
172
|
-
}
|
|
173
|
-
var length = url.length;
|
|
174
|
-
var u = url.slice(0, i < 0 ? length : i).substring(1).split('@');
|
|
175
|
-
var version = u.length > 1 ? '' : "@latest";
|
|
176
|
-
return npmCdn + url.slice(0, i < 0 ? length : i) + version + (i < 0 ? '' : url.slice(i));
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return module;
|
|
180
|
-
}({
|
|
181
|
-
_: ''
|
|
182
|
-
}, document.querySelector("script[data-main-path]")));
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// defaultPrevented is broken in IE.
|
|
2
|
-
// https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
|
|
3
|
-
|
|
4
|
-
var workingDefaultPrevented = (function() {
|
|
5
|
-
var e = document.createEvent('Event');
|
|
6
|
-
e.initEvent('foo', true, true);
|
|
7
|
-
e.preventDefault();
|
|
8
|
-
return e.defaultPrevented;
|
|
9
|
-
})();
|
|
10
|
-
|
|
11
|
-
if (!workingDefaultPrevented) {
|
|
12
|
-
var origPreventDefault = Event.prototype.preventDefault;
|
|
13
|
-
Event.prototype.preventDefault = function() {
|
|
14
|
-
if (!this.cancelable) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
origPreventDefault.call(this);
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(this, 'defaultPrevented', {
|
|
21
|
-
get: function() {
|
|
22
|
-
return true;
|
|
23
|
-
},
|
|
24
|
-
configurable: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var isIE = /Trident/.test(navigator.userAgent);
|
|
30
|
-
|
|
31
|
-
// CustomEvent constructor shim
|
|
32
|
-
if (!window.CustomEvent || isIE && (typeof window.CustomEvent !== 'function')) {
|
|
33
|
-
window.CustomEvent = function(inType, params) {
|
|
34
|
-
params = params || {};
|
|
35
|
-
var e = document.createEvent('CustomEvent');
|
|
36
|
-
e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
|
|
37
|
-
return e;
|
|
38
|
-
};
|
|
39
|
-
window.CustomEvent.prototype = window.Event.prototype;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Event constructor shim
|
|
43
|
-
if (!window.Event || isIE && (typeof window.Event !== 'function')) {
|
|
44
|
-
var origEvent = window.Event;
|
|
45
|
-
window.Event = function(inType, params) {
|
|
46
|
-
params = params || {};
|
|
47
|
-
var e = document.createEvent('Event');
|
|
48
|
-
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
|
|
49
|
-
return e;
|
|
50
|
-
};
|
|
51
|
-
if (origEvent) {
|
|
52
|
-
for (var i in origEvent) {
|
|
53
|
-
window.Event[i] = origEvent[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
window.Event.prototype = origEvent.prototype;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!window.MouseEvent || isIE && (typeof window.MouseEvent !== 'function')) {
|
|
60
|
-
var origMouseEvent = window.MouseEvent;
|
|
61
|
-
window.MouseEvent = function(inType, params) {
|
|
62
|
-
params = params || {};
|
|
63
|
-
var e = document.createEvent('MouseEvent');
|
|
64
|
-
e.initMouseEvent(inType,
|
|
65
|
-
Boolean(params.bubbles), Boolean(params.cancelable),
|
|
66
|
-
params.view || window, params.detail,
|
|
67
|
-
params.screenX, params.screenY, params.clientX, params.clientY,
|
|
68
|
-
params.ctrlKey, params.altKey, params.shiftKey, params.metaKey,
|
|
69
|
-
params.button, params.relatedTarget);
|
|
70
|
-
return e;
|
|
71
|
-
};
|
|
72
|
-
if (origMouseEvent) {
|
|
73
|
-
for (var i in origMouseEvent) {
|
|
74
|
-
window.MouseEvent[i] = origMouseEvent[i];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
window.MouseEvent.prototype = origMouseEvent.prototype;
|
|
78
|
-
}
|
package/src/index.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {Bind, CustomElement, CustomElementConfig, PropertyRenderOnSet} from "./utils/custom-element";
|
|
2
|
-
import {CustomStyleElement} from "./custom-style-element"
|
|
3
|
-
|
|
4
|
-
import * as _ from "underscore";
|
|
5
|
-
import * as anime from "animejs";
|
|
6
|
-
import * as Maquette from "./utils/maquette";
|
|
7
|
-
|
|
8
|
-
((window) => {
|
|
9
|
-
|
|
10
|
-
window._ = _;
|
|
11
|
-
(window as any).Maquette = Maquette;
|
|
12
|
-
(window as any).h = Maquette.h;
|
|
13
|
-
(window as any).anime = anime;
|
|
14
|
-
window.customElements.whenDefined("custom-style").then(() => {
|
|
15
|
-
document.body.parentElement.classList.add("custom-style-defined")
|
|
16
|
-
});
|
|
17
|
-
window.CustomElement = CustomElement;
|
|
18
|
-
window.CustomElementConfig = CustomElementConfig;
|
|
19
|
-
window.CustomStyleElement = CustomStyleElement;
|
|
20
|
-
window.PropertyRenderOnSet = PropertyRenderOnSet;
|
|
21
|
-
window.RenderOnSet = PropertyRenderOnSet;
|
|
22
|
-
window.Bind = Bind;
|
|
23
|
-
})(window as any);
|
package/src/sample.css
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
:host{
|
|
2
|
-
/* display: none; */
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.root {
|
|
6
|
-
display: flex;
|
|
7
|
-
padding: 10px;
|
|
8
|
-
flex-direction: row;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
#Foo {
|
|
12
|
-
@apply --mixin-sample;
|
|
13
|
-
text-decoration: underline;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
#SlotContainer ::slotted(*) {
|
|
17
|
-
font-weight: bold;
|
|
18
|
-
color: green;
|
|
19
|
-
font-size: 1.5em;
|
|
20
|
-
}
|
package/src/sample.spec.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
describe("my-greetings custom element", () => {
|
|
2
|
-
|
|
3
|
-
it("Should be defined", (done) => {
|
|
4
|
-
let elementIsDefined = false;
|
|
5
|
-
customElements.whenDefined("my-greetings").then(() => {
|
|
6
|
-
elementIsDefined = true;
|
|
7
|
-
expect(elementIsDefined).toBe(true);
|
|
8
|
-
done();
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("Should have shadow root", (done) => {
|
|
13
|
-
const element = document.createElement("my-greetings");
|
|
14
|
-
document.body.appendChild(element);
|
|
15
|
-
expect(typeof element.shadowRoot).toBe("object");
|
|
16
|
-
element.parentNode.removeChild(element);
|
|
17
|
-
done();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("Should have shadow root child element with text 'Hello!!'", (done) => {
|
|
21
|
-
const element = document.createElement("my-greetings");
|
|
22
|
-
document.body.appendChild(element);
|
|
23
|
-
expect( (element.shadowRoot.querySelector(".sample") as HTMLElement).innerText).toBe("Hello!!");
|
|
24
|
-
element.parentNode.removeChild(element);
|
|
25
|
-
done();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("Should display heading with text typed in input", (done) => {
|
|
29
|
-
const element = document.createElement("my-greetings");
|
|
30
|
-
document.body.appendChild(element);
|
|
31
|
-
const inputElement = element.shadowRoot.querySelector("input");
|
|
32
|
-
|
|
33
|
-
inputElement.value = "Lorem ipsum Dolar sit";
|
|
34
|
-
inputElement.dispatchEvent(new Event("input"));
|
|
35
|
-
|
|
36
|
-
setTimeout(() => {
|
|
37
|
-
expect( element.shadowRoot.querySelector(".title").innerHTML).toBe(inputElement.value);
|
|
38
|
-
element.parentNode.removeChild(element);
|
|
39
|
-
done();
|
|
40
|
-
}, 100)
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("Should display heading with the same text as element attribute name", (done) => {
|
|
44
|
-
const element = document.createElement("my-greetings");
|
|
45
|
-
element.setAttribute("name", "Arnold");
|
|
46
|
-
document.body.appendChild(element);
|
|
47
|
-
expect( element.shadowRoot.querySelector(".title").innerHTML).toBe("Arnold");
|
|
48
|
-
element.parentNode.removeChild(element);
|
|
49
|
-
done();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("Should display heading with the same text as element attribute name after changing the attribute", (done) => {
|
|
53
|
-
const element = document.createElement("my-greetings");
|
|
54
|
-
element.setAttribute("name", "Arnold");
|
|
55
|
-
document.body.appendChild(element);
|
|
56
|
-
element.setAttribute("name", "Kees");
|
|
57
|
-
expect( element.shadowRoot.querySelector(".title").innerHTML).toBe("Kees");
|
|
58
|
-
element.parentNode.removeChild(element);
|
|
59
|
-
done();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("Should display heading with the same text as element propery", (done) => {
|
|
63
|
-
const element = document.createElement("my-greetings") as any;
|
|
64
|
-
element.name = "Arie";
|
|
65
|
-
document.body.appendChild(element);
|
|
66
|
-
expect( element.shadowRoot.querySelector(".title").innerHTML).toBe("Arie");
|
|
67
|
-
element.parentNode.removeChild(element);
|
|
68
|
-
done();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("Should display heading with the same text as element property name after changing the property", (done) => {
|
|
72
|
-
const element = document.createElement("my-greetings") as any;
|
|
73
|
-
element.name = "Jeffreyd";
|
|
74
|
-
document.body.appendChild(element);
|
|
75
|
-
element.name = "Martijn";
|
|
76
|
-
expect( element.shadowRoot.querySelector(".title").innerHTML).toBe("Martijn");
|
|
77
|
-
element.parentNode.removeChild(element);
|
|
78
|
-
done();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// betty BOOP => Brilliant Online Objects Programmers
|
|
82
|
-
it("Should display BB when property name is 'Peter'", (done) => {
|
|
83
|
-
const element = document.createElement("my-greetings") as any;
|
|
84
|
-
element.name = "Peter";
|
|
85
|
-
document.body.appendChild(element);
|
|
86
|
-
expect( typeof element.shadowRoot.querySelector(".is-peter--image")).toBe("object");
|
|
87
|
-
element.parentNode.removeChild(element);
|
|
88
|
-
done();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe("super-a custom element extends a", () => {
|
|
94
|
-
|
|
95
|
-
it("Should be defined", (done) => {
|
|
96
|
-
let elementIsDefined = false;
|
|
97
|
-
customElements.whenDefined("super-a").then(() => {
|
|
98
|
-
elementIsDefined = true;
|
|
99
|
-
expect(elementIsDefined).toBe(true);
|
|
100
|
-
done();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("Should be red", (done) => {
|
|
105
|
-
const element = (document as any).createElement("a", {is: "super-a"});
|
|
106
|
-
document.body.appendChild(element);
|
|
107
|
-
expect(element.style.color).toBe("red");
|
|
108
|
-
element.parentNode.removeChild(element);
|
|
109
|
-
done();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
});
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { Projector, VNode } from "./maquette";
|
|
2
|
-
|
|
3
|
-
declare var HTMLElement: {
|
|
4
|
-
prototype: HTMLElement;
|
|
5
|
-
new(param?): HTMLElement;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export interface IElementConfig {
|
|
9
|
-
tagName: string;
|
|
10
|
-
options?: {
|
|
11
|
-
extends: string;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const cssMap = new Map();
|
|
16
|
-
|
|
17
|
-
export const Bind = (target, key, descriptor) => {
|
|
18
|
-
let fn = descriptor.value;
|
|
19
|
-
|
|
20
|
-
if (typeof fn !== 'function') {
|
|
21
|
-
throw new Error(`@Bind decorator can only be applied to methods not: ${typeof fn}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// In IE11 calling Object.defineProperty has a side-effect of evaluating the
|
|
25
|
-
// getter for the property which is being replaced. This causes infinite
|
|
26
|
-
// recursion and an "Out of stack space" error.
|
|
27
|
-
let definingProperty = false;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
configurable: true,
|
|
31
|
-
get() {
|
|
32
|
-
if (definingProperty || this === target.prototype || this.hasOwnProperty(key)
|
|
33
|
-
|| typeof fn !== 'function') {
|
|
34
|
-
return fn;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let boundFn = fn.bind(this);
|
|
38
|
-
definingProperty = true;
|
|
39
|
-
Object.defineProperty(this, key, {
|
|
40
|
-
configurable: true,
|
|
41
|
-
get() {
|
|
42
|
-
return boundFn;
|
|
43
|
-
},
|
|
44
|
-
set(value) {
|
|
45
|
-
fn = value;
|
|
46
|
-
delete this[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
definingProperty = false;
|
|
50
|
-
return boundFn;
|
|
51
|
-
},
|
|
52
|
-
set(value) {
|
|
53
|
-
fn = value;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const CustomElementConfig = (config: IElementConfig) => {
|
|
59
|
-
return (Element) => {
|
|
60
|
-
setTimeout(() => {
|
|
61
|
-
customElements.define(config.tagName, Element, config.options);
|
|
62
|
-
}, 10);
|
|
63
|
-
const camelCased = config.tagName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
64
|
-
(<any>window)[camelCased.charAt(0).toUpperCase() + camelCased.slice(1)] = Element;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export function PropertyRenderOnSet(target, key) {
|
|
69
|
-
|
|
70
|
-
if (!Reflect.get(target, "_dp_" + key)) {
|
|
71
|
-
Reflect.defineProperty(target, "_dp_" + key, {
|
|
72
|
-
configurable: true,
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function() {
|
|
75
|
-
return this["_" + key + "_value"];
|
|
76
|
-
},
|
|
77
|
-
set: function(value) {
|
|
78
|
-
this["_" + key + "_value"] = value;
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!target["_dp_setters_" + key]) {
|
|
84
|
-
target["_dp_setters_" + key] = [];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const propertyRenderOnSetFunction = (o, v) => {
|
|
88
|
-
if (o && o.renderNow) {
|
|
89
|
-
o.renderNow();
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
target["_dp_setters_" + key].push(propertyRenderOnSetFunction);
|
|
94
|
-
|
|
95
|
-
const getter = function() {
|
|
96
|
-
return this["_" + key + "_value"];
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const setter = function(newVal) {
|
|
100
|
-
this["_dp_" + key] = newVal;
|
|
101
|
-
if (target["_dp_setters_" + key]) {
|
|
102
|
-
target["_dp_setters_" + key].forEach((fn) => {
|
|
103
|
-
fn(this, newVal);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
Object.defineProperty(target, key, {
|
|
109
|
-
configurable: true,
|
|
110
|
-
enumerable: true,
|
|
111
|
-
get: getter,
|
|
112
|
-
set: setter,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
declare var HTMLElement: {
|
|
117
|
-
prototype: HTMLElement;
|
|
118
|
-
new(arg?: any): HTMLElement;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const installCE = require("document-register-element/pony");
|
|
122
|
-
const isNative = (fn) => {
|
|
123
|
-
return (/\{\s*\[native code\]\s*\}/).test("" + fn);
|
|
124
|
-
};
|
|
125
|
-
if (!isNative((document as any).registerElement)) {
|
|
126
|
-
installCE(window, "auto");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export abstract class CustomElement extends HTMLElement {
|
|
130
|
-
|
|
131
|
-
constructor(self) {
|
|
132
|
-
self = super(self);
|
|
133
|
-
if (typeof (this as any).init === "function") {
|
|
134
|
-
(this as any).init();
|
|
135
|
-
}
|
|
136
|
-
return self;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private _projector: Projector;
|
|
140
|
-
|
|
141
|
-
protected templateFromString(html: string): any {
|
|
142
|
-
if (!this.shadowRoot) {
|
|
143
|
-
this.attachShadow({ mode: "open" });
|
|
144
|
-
}
|
|
145
|
-
this.shadowRoot.innerHTML = "";
|
|
146
|
-
|
|
147
|
-
let style = "<style></style>";
|
|
148
|
-
const styleMatch = html.match(/<style[^>]*>([\s\S]*?)<\/style>/);
|
|
149
|
-
if (styleMatch) {
|
|
150
|
-
style = styleMatch[0];
|
|
151
|
-
if (cssMap.has(this.tagName)){
|
|
152
|
-
html = html.replace(styleMatch[0], `<link rel="stylesheet" href="${cssMap.get(this.tagName)}">`);
|
|
153
|
-
} else {
|
|
154
|
-
const blob = new Blob([styleMatch[1]], {type: 'text/css'});
|
|
155
|
-
html = html.replace(styleMatch[0], `<link rel="stylesheet" href="${URL.createObjectURL(blob)}" data-tmp="true">`);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let myElementTemplate = document.createElement('template');
|
|
161
|
-
myElementTemplate.innerHTML = html;
|
|
162
|
-
let template = document.importNode(myElementTemplate.content, true);
|
|
163
|
-
|
|
164
|
-
const creatObjectUrlForShadyStyle = () => {
|
|
165
|
-
if (cssMap.has(this.tagName)){
|
|
166
|
-
return cssMap.get(this.tagName);
|
|
167
|
-
}
|
|
168
|
-
const t = document.createElement("template");
|
|
169
|
-
t.innerHTML = style;
|
|
170
|
-
const p = (window as any).ShadyCSS.prepareTemplate(t, "x-tmp");
|
|
171
|
-
const c = t.content.cloneNode(true);
|
|
172
|
-
const cssTxt = (c as any).querySelector("style").textContent;
|
|
173
|
-
const blob = new Blob([cssTxt], {type: 'text/css'});
|
|
174
|
-
const url = URL.createObjectURL(blob);
|
|
175
|
-
cssMap.set(this.tagName, url);
|
|
176
|
-
return url;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
window.addEventListener('customStyleConnected', () => {
|
|
180
|
-
setTimeout(() => {
|
|
181
|
-
const link = this.shadowRoot.querySelector("link");
|
|
182
|
-
if (link) {
|
|
183
|
-
if (link.hasAttribute("data-tmp")) {
|
|
184
|
-
URL.revokeObjectURL(link.href);
|
|
185
|
-
link.removeAttribute("data-tmp")
|
|
186
|
-
}
|
|
187
|
-
link.href = creatObjectUrlForShadyStyle();
|
|
188
|
-
}
|
|
189
|
-
}, 1)
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
setTimeout(() => {
|
|
193
|
-
const link = this.shadowRoot.querySelector("link");
|
|
194
|
-
if (link) {
|
|
195
|
-
if (link.hasAttribute("data-tmp")) {
|
|
196
|
-
URL.revokeObjectURL(link.href);
|
|
197
|
-
link.removeAttribute("data-tmp")
|
|
198
|
-
}
|
|
199
|
-
link.href = creatObjectUrlForShadyStyle();
|
|
200
|
-
}
|
|
201
|
-
}, 1)
|
|
202
|
-
return template;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
protected createProjector(element: Element, render: () => VNode): Promise<Projector> {
|
|
207
|
-
|
|
208
|
-
return new Promise<Projector>((resolve, reject) => {
|
|
209
|
-
let projector: Projector;
|
|
210
|
-
let time = 1;
|
|
211
|
-
const isIE = (navigator.userAgent.indexOf("Trident") != -1);
|
|
212
|
-
if(isIE) {
|
|
213
|
-
time = 400;
|
|
214
|
-
} else {
|
|
215
|
-
const iOS = parseFloat(
|
|
216
|
-
('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1])
|
|
217
|
-
.replace('undefined', '3_2').replace('_', '.').replace('_', '')
|
|
218
|
-
) || false;
|
|
219
|
-
time = (iOS !== false && iOS < 10.4) ? 1500 : time;
|
|
220
|
-
time = (iOS !== false && iOS < 10) ? 2000 : time;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
setTimeout(() => {
|
|
224
|
-
projector = (window as any).Maquette.createProjector();
|
|
225
|
-
projector.append(element, render);
|
|
226
|
-
this._projector = projector;
|
|
227
|
-
resolve(projector);
|
|
228
|
-
this.dispatchEvent(new CustomEvent("firstRender", {}));
|
|
229
|
-
}, time);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
protected renderNow() {
|
|
236
|
-
if (this._projector) {
|
|
237
|
-
this._projector.renderNow();
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
}
|