1 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2 |
|
3 | (function (global, factory) {
|
4 | (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.Oxe = factory());
|
5 | })(this, function () {
|
6 | 'use strict';
|
7 |
|
8 | var Utility = {
|
9 | PIPE: /\s?\|\s?/,
|
10 | PIPES: /\s?,\s?|\s+/,
|
11 | value: function value(element, model) {
|
12 | if (!model) throw new Error('Utility.value - requires model argument');
|
13 | if (!element) throw new Error('Utility.value - requires element argument');
|
14 | var type = this.type(element);
|
15 |
|
16 | if (type === 'radio' || type === 'checkbox') {
|
17 | var name = this.name(element);
|
18 | var query = 'input[type="' + type + '"][name="' + name + '"]';
|
19 | var form = this.form(element);
|
20 | var elements = form ? this.form(element).querySelectorAll(query) : [element];
|
21 | var multiple = elements.length > 1;
|
22 | var result = multiple ? [] : undefined;
|
23 |
|
24 | for (var i = 0, l = elements.length; i < l; i++) {
|
25 | var child = elements[i];
|
26 | var checked = this.checked(child);
|
27 | if (!checked) continue;
|
28 | var value = this.value(child, model);
|
29 |
|
30 | if (multiple) {
|
31 | result.push(value);
|
32 | } else {
|
33 | result = value;
|
34 | break;
|
35 | }
|
36 | }
|
37 |
|
38 | return result;
|
39 | } else if (type === 'select-one' || type === 'select-multiple') {
|
40 | var _multiple = this.multiple(element);
|
41 |
|
42 | var options = element.options;
|
43 |
|
44 | var _result = _multiple ? [] : undefined;
|
45 |
|
46 | for (var _i = 0, _l = options.length; _i < _l; _i++) {
|
47 | var option = options[_i];
|
48 | var selected = option.selected;
|
49 |
|
50 | var _value = this.value(option, model);
|
51 |
|
52 | var match = this[_multiple ? 'includes' : 'compare'](this.data, _value);
|
53 |
|
54 | if (selected && !match) {
|
55 | if (this.multiple) {
|
56 | _result.push(_value);
|
57 | } else {
|
58 | _result = _value;
|
59 | }
|
60 | } else if (!selected && match) {
|
61 | option.selected = true;
|
62 | }
|
63 | }
|
64 |
|
65 | return _result;
|
66 | } else {
|
67 | var attribute = element.attributes['o-value'];
|
68 |
|
69 | if (attribute) {
|
70 | var values = this.binderValues(attribute.value);
|
71 |
|
72 | var _value2 = this.getByPath(model, values);
|
73 |
|
74 | return _value2 || element.value;
|
75 | } else {
|
76 | return element.value;
|
77 | }
|
78 | }
|
79 | },
|
80 | form: function form(element) {
|
81 | if (element.form) {
|
82 | return element.form;
|
83 | } else {
|
84 | while (element = element.parentElement) {
|
85 | if (element.nodeName === 'FORM' || element.nodeName.indexOf('-FORM') !== -1) {
|
86 | return element;
|
87 | }
|
88 | }
|
89 | }
|
90 | },
|
91 | type: function type(element) {
|
92 | if (typeof element.type === 'string') {
|
93 | return element.type;
|
94 | } else {
|
95 | return element.getAttribute('type');
|
96 | }
|
97 | },
|
98 | name: function name(element) {
|
99 | if (typeof element.name === 'string') {
|
100 | return element.name;
|
101 | } else {
|
102 | return element.getAttribute('name');
|
103 | }
|
104 | },
|
105 | checked: function checked(element) {
|
106 | if (typeof element.checked === 'boolean') {
|
107 | return element.checked;
|
108 | } else {
|
109 | switch (element.getAttribute('checked')) {
|
110 | case undefined:
|
111 | return false;
|
112 |
|
113 | case 'true':
|
114 | return true;
|
115 |
|
116 | case null:
|
117 | return false;
|
118 |
|
119 | case '':
|
120 | return true;
|
121 |
|
122 | default:
|
123 | return false;
|
124 | }
|
125 | }
|
126 | },
|
127 | multiple: function multiple(element) {
|
128 | if (typeof element.multiple === 'boolean') {
|
129 | return element.multiple;
|
130 | } else {
|
131 | switch (element.getAttribute('multiple')) {
|
132 | case undefined:
|
133 | return false;
|
134 |
|
135 | case 'true':
|
136 | return true;
|
137 |
|
138 | case null:
|
139 | return false;
|
140 |
|
141 | case '':
|
142 | return true;
|
143 |
|
144 | default:
|
145 | return false;
|
146 | }
|
147 | }
|
148 | },
|
149 | disabled: function disabled(element) {
|
150 | if (typeof element.disabled === 'boolean') {
|
151 | return element.disabled;
|
152 | } else {
|
153 | switch (element.getAttribute('disabled')) {
|
154 | case undefined:
|
155 | return false;
|
156 |
|
157 | case 'true':
|
158 | return true;
|
159 |
|
160 | case null:
|
161 | return false;
|
162 |
|
163 | case '':
|
164 | return true;
|
165 |
|
166 | default:
|
167 | return false;
|
168 | }
|
169 | }
|
170 | },
|
171 | index: function index(items, item) {
|
172 | for (var i = 0, l = items.length; i < l; i++) {
|
173 | if (this.match(items[i], item)) {
|
174 | return i;
|
175 | }
|
176 | }
|
177 |
|
178 | return -1;
|
179 | },
|
180 | includes: function includes(items, item) {
|
181 | for (var i = 0, l = items.length; i < l; i++) {
|
182 | if (this.match(items[i], item)) {
|
183 | return true;
|
184 | }
|
185 | }
|
186 |
|
187 | return false;
|
188 | },
|
189 | match: function match(source, target) {
|
190 | if (source === target) {
|
191 | return true;
|
192 | }
|
193 |
|
194 | if (_typeof(source) !== _typeof(target)) {
|
195 | return false;
|
196 | }
|
197 |
|
198 | if (source.constructor !== target.constructor) {
|
199 | return false;
|
200 | }
|
201 |
|
202 | if (_typeof(source) !== 'object' || _typeof(target) !== 'object') {
|
203 | return source === target;
|
204 | }
|
205 |
|
206 | var sourceKeys = Object.keys(source);
|
207 | var targetKeys = Object.keys(target);
|
208 |
|
209 | if (sourceKeys.length !== targetKeys.length) {
|
210 | return false;
|
211 | }
|
212 |
|
213 | for (var i = 0, l = sourceKeys.length; i < l; i++) {
|
214 | var name = sourceKeys[i];
|
215 |
|
216 | if (!this.match(source[name], target[name])) {
|
217 | return false;
|
218 | }
|
219 | }
|
220 |
|
221 | return true;
|
222 | },
|
223 | binderNames: function binderNames(data) {
|
224 | data = data.split('o-')[1];
|
225 | return data ? data.split('-') : [];
|
226 | },
|
227 | binderValues: function binderValues(data) {
|
228 | data = data.split(this.PIPE)[0];
|
229 | return data ? data.split('.') : [];
|
230 | },
|
231 | binderPipes: function binderPipes(data) {
|
232 | data = data.split(this.PIPE)[1];
|
233 | return data ? data.split(this.PIPES) : [];
|
234 | },
|
235 | ensureElement: function ensureElement(data) {
|
236 | data.query = data.query || '';
|
237 | data.scope = data.scope || document.body;
|
238 | var element = data.scope.querySelector("".concat(data.name).concat(data.query));
|
239 |
|
240 | if (!element) {
|
241 | element = document.createElement(data.name);
|
242 |
|
243 | if (data.position === 'afterbegin') {
|
244 | data.scope.insertBefore(element, data.scope.firstChild);
|
245 | } else if (data.position === 'beforeend') {
|
246 | data.scope.appendChild(element);
|
247 | } else {
|
248 | data.scope.appendChild(element);
|
249 | }
|
250 | }
|
251 |
|
252 | for (var i = 0, l = data.attributes.length; i < l; i++) {
|
253 | var attribute = data.attributes[i];
|
254 | element.setAttribute(attribute.name, attribute.value);
|
255 | }
|
256 |
|
257 | return element;
|
258 | },
|
259 | setByPath: function setByPath(data, path, value) {
|
260 | var keys = typeof path === 'string' ? path.split('.') : path;
|
261 | var last = keys.length - 1;
|
262 |
|
263 | for (var i = 0; i < last; i++) {
|
264 | var key = keys[i];
|
265 |
|
266 | if (!(key in data)) {
|
267 | if (isNaN(keys[i + 1])) {
|
268 | data[key] = {};
|
269 | } else {
|
270 | data[key] = [];
|
271 | }
|
272 | }
|
273 |
|
274 | data = data[key];
|
275 | }
|
276 |
|
277 | return data[keys[last]] = value;
|
278 | },
|
279 | getByPath: function getByPath(data, path) {
|
280 | var keys = typeof path === 'string' ? path.split('.') : path;
|
281 | var last = keys.length - 1;
|
282 |
|
283 | if (keys[last] === '$key' || keys[last] === '$index') {
|
284 | return keys[last - 1];
|
285 | }
|
286 |
|
287 | for (var i = 0; i < last; i++) {
|
288 | var key = keys[i];
|
289 |
|
290 | if (key in data === false) {
|
291 | return undefined;
|
292 | } else {
|
293 | data = data[key];
|
294 | }
|
295 | }
|
296 |
|
297 | return data[keys[last]];
|
298 | },
|
299 | clone: function clone(source) {
|
300 | if (source === null || source === undefined || source.constructor !== Array && source.constructor !== Object) {
|
301 | return source;
|
302 | }
|
303 |
|
304 | var target = source.constructor();
|
305 |
|
306 | for (var name in source) {
|
307 | var descriptor = Object.getOwnPropertyDescriptor(source, name);
|
308 |
|
309 | if (descriptor) {
|
310 | if ('value' in descriptor) {
|
311 | descriptor.value = this.clone(descriptor.value);
|
312 | }
|
313 |
|
314 | Object.defineProperty(target, name, descriptor);
|
315 | }
|
316 | }
|
317 |
|
318 | return target;
|
319 | }
|
320 | };
|
321 | var Batcher = {
|
322 | reads: [],
|
323 | writes: [],
|
324 | time: 1000 / 30,
|
325 | pending: false,
|
326 | setup: function setup(options) {
|
327 | options = options || {};
|
328 | this.time = options.time || this.time;
|
329 | },
|
330 | tick: function tick(callback) {
|
331 | window.requestAnimationFrame(callback.bind(this, null));
|
332 | },
|
333 | schedule: function schedule() {
|
334 | if (this.pending) return;
|
335 | this.pending = true;
|
336 | this.tick(this.flush);
|
337 | },
|
338 | flush: function flush(time) {
|
339 | time = time || performance.now();
|
340 | var task;
|
341 |
|
342 | if (this.writes.length === 0) {
|
343 | while (task = this.reads.shift()) {
|
344 | if (task) {
|
345 | task();
|
346 | }
|
347 |
|
348 | if (performance.now() - time > this.time) {
|
349 | return this.tick(this.flush);
|
350 | }
|
351 | }
|
352 | }
|
353 |
|
354 | while (task = this.writes.shift()) {
|
355 | if (task) {
|
356 | task();
|
357 | }
|
358 |
|
359 | if (performance.now() - time > this.time) {
|
360 | return this.tick(this.flush);
|
361 | }
|
362 | }
|
363 |
|
364 | if (this.reads.length === 0 && this.writes.length === 0) {
|
365 | this.pending = false;
|
366 | } else if (performance.now() - time > this.time) {
|
367 | this.tick(this.flush);
|
368 | } else {
|
369 | this.flush(time);
|
370 | }
|
371 | },
|
372 | remove: function remove(tasks, task) {
|
373 | var index = tasks.indexOf(task);
|
374 | return !!~index && !!tasks.splice(index, 1);
|
375 | },
|
376 | clear: function clear(task) {
|
377 | return this.remove(this.reads, task) || this.remove(this.writes, task);
|
378 | },
|
379 | batch: function batch(data) {
|
380 | var self = this;
|
381 | if (!data) return;
|
382 | if (!data.read && !data.write) return;
|
383 | data.context = data.context || {};
|
384 |
|
385 | var read = function read() {
|
386 | var result;
|
387 |
|
388 | if (data.read) {
|
389 | result = data.read.call(data.context, data.context);
|
390 | }
|
391 |
|
392 | if (data.write && result !== false) {
|
393 | var write = data.write.bind(data.context, data.context);
|
394 | self.writes.push(write);
|
395 | }
|
396 | };
|
397 |
|
398 | self.reads.push(read);
|
399 | self.schedule();
|
400 | }
|
401 | };
|
402 |
|
403 | function Piper(binder, data) {
|
404 | if (binder.type === 'on') {
|
405 | return data;
|
406 | }
|
407 |
|
408 | if (!binder.pipes.length) {
|
409 | return data;
|
410 | }
|
411 |
|
412 | var methods = binder.container.methods;
|
413 |
|
414 | if (!methods) {
|
415 | return data;
|
416 | }
|
417 |
|
418 | for (var i = 0, l = binder.pipes.length; i < l; i++) {
|
419 | var name = binder.pipes[i];
|
420 |
|
421 | if (name in methods) {
|
422 | var method = methods[name];
|
423 |
|
424 | if (method && method.constructor === Function) {
|
425 | data = methods[name].call(binder.container, data);
|
426 | } else {
|
427 | console.warn("Oxe.piper - pipe ".concat(name, " invalid type"));
|
428 | }
|
429 | } else {
|
430 | console.warn("Oxe.piper - pipe ".concat(name, " not found"));
|
431 | }
|
432 | }
|
433 |
|
434 | return data;
|
435 | }
|
436 |
|
437 | function Class(binder) {
|
438 | return {
|
439 | read: function read() {
|
440 | this.data = binder.data;
|
441 |
|
442 | if (binder.names.length > 1) {
|
443 | this.name = binder.names.slice(1).join('-');
|
444 | }
|
445 | },
|
446 | write: function write() {
|
447 | if (this.name) {
|
448 | if (this.data === undefined || this.data === null) {
|
449 | binder.target.classList.remove(this.name);
|
450 | } else {
|
451 | binder.target.classList.toggle(this.name, this.data);
|
452 | }
|
453 | } else {
|
454 | if (this.data === undefined || this.data === null) {
|
455 | binder.target.setAttribute('class', '');
|
456 | } else {
|
457 | binder.target.setAttribute('class', this.data);
|
458 | }
|
459 | }
|
460 | }
|
461 | };
|
462 | }
|
463 |
|
464 | function Default(binder) {
|
465 | return {
|
466 | read: function read() {
|
467 | this.data = binder.data;
|
468 |
|
469 | if (this.data === undefined || this.data === null) {
|
470 | this.data = '';
|
471 | } else if (_typeof(this.data) === 'object') {
|
472 | this.data = JSON.stringify(this.data);
|
473 | } else if (typeof this.data !== 'string') {
|
474 | this.data = this.data.toString();
|
475 | }
|
476 |
|
477 | if (this.data === binder.target[binder.type]) {
|
478 | return false;
|
479 | }
|
480 | },
|
481 | write: function write() {
|
482 | binder.target[binder.type] = this.data;
|
483 | }
|
484 | };
|
485 | }
|
486 |
|
487 | function Disable(binder) {
|
488 | return {
|
489 | read: function read() {
|
490 | this.data = binder.data;
|
491 |
|
492 | if (this.data === binder.target.disabled) {
|
493 | return false;
|
494 | }
|
495 | },
|
496 | write: function write() {
|
497 | binder.target.disabled = this.data;
|
498 | }
|
499 | };
|
500 | }
|
501 |
|
502 | function Each(binder) {
|
503 | var self = this;
|
504 | var render = {
|
505 | read: function read() {
|
506 | this.data = binder.data || [];
|
507 |
|
508 | if (binder.meta.keys === undefined) {
|
509 | binder.meta.keys = [];
|
510 | binder.meta.pending = false;
|
511 | binder.meta.targetLength = 0;
|
512 | binder.meta.currentLength = 0;
|
513 |
|
514 | if (binder.target.firstElementChild) {
|
515 | binder.meta.template = binder.target.removeChild(binder.target.firstElementChild);
|
516 | } else {
|
517 | var element = document.createElement('div');
|
518 | var text = document.createTextNode("{{$".concat(binder.names[1], "}}"));
|
519 | element.appendChild(text);
|
520 | binder.meta.template = element;
|
521 | }
|
522 | }
|
523 |
|
524 | binder.meta.keys = Object.keys(this.data);
|
525 | binder.meta.targetLength = binder.meta.keys.length;
|
526 |
|
527 | if (binder.meta.currentLength === binder.meta.targetLength) {
|
528 | return false;
|
529 | }
|
530 | },
|
531 | write: function write() {
|
532 | if (binder.meta.currentLength === binder.meta.targetLength) {
|
533 | binder.meta.pending = false;
|
534 | return;
|
535 | }
|
536 |
|
537 | if (binder.meta.currentLength > binder.meta.targetLength) {
|
538 | var element = binder.target.lastElementChild;
|
539 | binder.target.removeChild(element);
|
540 | self.remove(element);
|
541 | binder.meta.currentLength--;
|
542 | } else if (binder.meta.currentLength < binder.meta.targetLength) {
|
543 | var _element = binder.meta.template.cloneNode(true);
|
544 |
|
545 | var _index = binder.meta.currentLength++;
|
546 |
|
547 | self.add(_element, {
|
548 | index: _index,
|
549 | path: binder.path,
|
550 | variable: binder.names[1],
|
551 | container: binder.container,
|
552 | scope: binder.container.scope,
|
553 | key: binder.meta.keys[_index]
|
554 | });
|
555 | binder.target.appendChild(_element);
|
556 | }
|
557 |
|
558 | if (binder.meta.pending && render.read) {
|
559 | return;
|
560 | } else {
|
561 | binder.meta.pending = true;
|
562 | }
|
563 |
|
564 | delete render.read;
|
565 | Batcher.batch(render);
|
566 | }
|
567 | };
|
568 | return render;
|
569 | }
|
570 |
|
571 | function Enable(binder) {
|
572 | return {
|
573 | read: function read() {
|
574 | this.data = !binder.data;
|
575 |
|
576 | if (this.data === binder.target.disabled) {
|
577 | return false;
|
578 | }
|
579 | },
|
580 | write: function write() {
|
581 | binder.target.disabled = this.data;
|
582 | }
|
583 | };
|
584 | }
|
585 |
|
586 | function Hide(binder) {
|
587 | return {
|
588 | read: function read() {
|
589 | this.data = binder.data;
|
590 |
|
591 | if (this.data === binder.target.hidden) {
|
592 | return false;
|
593 | }
|
594 | },
|
595 | write: function write() {
|
596 | binder.target.hidden = this.data;
|
597 | }
|
598 | };
|
599 | }
|
600 |
|
601 | function Href(binder) {
|
602 | return {
|
603 | read: function read() {
|
604 | this.data = binder.data || '';
|
605 |
|
606 | if (this.data === binder.target.href) {
|
607 | return false;
|
608 | }
|
609 | },
|
610 | write: function write() {
|
611 | binder.target.href = this.data;
|
612 | }
|
613 | };
|
614 | }
|
615 |
|
616 | function Html(binder) {
|
617 | var self = this;
|
618 | return {
|
619 | read: function read() {
|
620 | this.data = binder.data;
|
621 |
|
622 | if (this.data === undefined || this.data === null) {
|
623 | this.data = '';
|
624 | } else if (_typeof(this.data) === 'object') {
|
625 | this.data = JSON.stringify(this.data);
|
626 | } else if (typeof this.data !== 'string') {
|
627 | this.data = String(this.data);
|
628 | }
|
629 | },
|
630 | write: function write() {
|
631 | while (binder.target.firstChild) {
|
632 | var node = binder.target.removeNode(binder.target.firstChild);
|
633 | self.remove(node);
|
634 | }
|
635 |
|
636 | var fragment = document.createDocumentFragment();
|
637 | var parser = document.createElement('div');
|
638 | parser.innerHTML = this.data;
|
639 |
|
640 | while (parser.firstElementChild) {
|
641 | self.add(parser.firstElementChild, {
|
642 | container: binder.container,
|
643 | scope: binder.container.scope
|
644 | });
|
645 | fragment.appendChild(parser.firstElementChild);
|
646 | }
|
647 |
|
648 | binder.target.appendChild(fragment);
|
649 | }
|
650 | };
|
651 | }
|
652 |
|
653 | function Label(binder) {
|
654 | return {
|
655 | read: function read() {
|
656 | this.data = binder.data;
|
657 |
|
658 | if (this.data === undefined || this.data === null) {
|
659 | this.data = '';
|
660 | } else if (_typeof(this.data) === 'object') {
|
661 | this.data = JSON.stringify(this.data);
|
662 | } else if (typeof this.data !== 'string') {
|
663 | this.data = this.data.toString();
|
664 | }
|
665 |
|
666 | if (this.data === binder.target.getAttribute('label')) {
|
667 | return false;
|
668 | }
|
669 | },
|
670 | write: function write() {
|
671 | binder.target.setAttribute('label', this.data);
|
672 | }
|
673 | };
|
674 | }
|
675 |
|
676 | function On(binder) {
|
677 | return {
|
678 | read: function read(context) {
|
679 | context.data = binder.data;
|
680 |
|
681 | if (typeof context.data !== 'function') {
|
682 | console.warn("Oxe - binder o-on=\"".concat(binder.keys.join('.'), "\" invalid type function required"));
|
683 | return;
|
684 | }
|
685 |
|
686 | if (binder.meta.method) {
|
687 | binder.target.removeEventListener(binder.names[1], binder.meta.method);
|
688 | } else {
|
689 | binder.meta.method = function (events) {
|
690 | var parameters = [];
|
691 |
|
692 | for (var i = 0, l = binder.pipes.length; i < l; i++) {
|
693 | var keys = binder.pipes[i].split('.');
|
694 | var parameter = Utility.getByPath(binder.container.model, keys);
|
695 | parameters.push(parameter);
|
696 | }
|
697 |
|
698 | parameters.push(events);
|
699 | parameters.push(this);
|
700 | Promise.resolve(context.data.bind(binder.container).apply(null, parameters));
|
701 | };
|
702 | }
|
703 |
|
704 | binder.target.addEventListener(binder.names[1], binder.meta.method);
|
705 | }
|
706 | };
|
707 | }
|
708 |
|
709 | function Read(binder) {
|
710 | return {
|
711 | read: function read() {
|
712 | this.data = binder.data;
|
713 |
|
714 | if (this.data === binder.target.readOnly) {
|
715 | return false;
|
716 | }
|
717 | },
|
718 | write: function write() {
|
719 | binder.target.readOnly = this.data;
|
720 | }
|
721 | };
|
722 | }
|
723 |
|
724 | function Require(binder) {
|
725 | return {
|
726 | read: function read() {
|
727 | this.data = binder.data;
|
728 |
|
729 | if (this.data === binder.target.required) {
|
730 | return false;
|
731 | }
|
732 | },
|
733 | write: function write() {
|
734 | binder.target.required = this.data;
|
735 | }
|
736 | };
|
737 | }
|
738 |
|
739 | function Show(binder) {
|
740 | return {
|
741 | read: function read() {
|
742 | this.data = binder.data;
|
743 |
|
744 | if (!this.data === binder.target.hidden) {
|
745 | return false;
|
746 | }
|
747 | },
|
748 | write: function write() {
|
749 | binder.target.hidden = !this.data;
|
750 | }
|
751 | };
|
752 | }
|
753 |
|
754 | function Style(binder) {
|
755 | return {
|
756 | read: function read() {
|
757 | this.data = binder.data;
|
758 |
|
759 | if (binder.names.length > 1) {
|
760 | this.name = '';
|
761 | this.names = binder.names.slice(1);
|
762 |
|
763 | for (var i = 0, l = this.names.length; i < l; i++) {
|
764 | if (i === 0) {
|
765 | this.name = this.names[i].toLowerCase();
|
766 | } else {
|
767 | this.name += this.names[i].charAt(0).toUpperCase() + this.names[i].slice(1).toLowerCase();
|
768 | }
|
769 | }
|
770 | }
|
771 | },
|
772 | write: function write() {
|
773 | if (binder.names.length > 1) {
|
774 | if (this.data) {
|
775 | binder.target.style[this.name] = this.data;
|
776 | } else {
|
777 | binder.target.style[this.name] = '';
|
778 | }
|
779 | } else {
|
780 | if (this.data) {
|
781 | binder.target.style.cssText = this.data;
|
782 | } else {
|
783 | binder.target.style.cssText = '';
|
784 | }
|
785 | }
|
786 | }
|
787 | };
|
788 | }
|
789 |
|
790 | function Text(binder) {
|
791 | return {
|
792 | read: function read() {
|
793 | this.data = binder.data;
|
794 |
|
795 | if (this.data === undefined || this.data === null) {
|
796 | this.data = '';
|
797 | } else if (_typeof(this.data) === 'object') {
|
798 | this.data = JSON.stringify(this.data);
|
799 | } else if (typeof this.data !== 'string') {
|
800 | this.data = this.data.toString();
|
801 | }
|
802 |
|
803 | if (this.data === binder.target.textContent) {
|
804 | return false;
|
805 | }
|
806 | },
|
807 | write: function write() {
|
808 | binder.target.textContent = this.data;
|
809 | }
|
810 | };
|
811 | }
|
812 |
|
813 | function Value(binder, caller) {
|
814 | var self = this;
|
815 | var type = binder.target.type;
|
816 | if (binder.meta.busy) return;else binder.meta.busy = true;
|
817 |
|
818 | if (type === 'select-one' || type === 'select-multiple') {
|
819 | return {
|
820 | read: function read() {
|
821 | this.data = binder.data;
|
822 | this.model = binder.model;
|
823 | this.options = binder.target.options;
|
824 | this.multiple = Utility.multiple(binder.target);
|
825 |
|
826 | if (this.multiple && (!this.data || this.data.constructor !== Array)) {
|
827 | binder.meta.busy = false;
|
828 | throw new Error("Oxe - invalid o-value ".concat(binder.keys.join('.'), " multiple select requires array"));
|
829 | }
|
830 | },
|
831 | write: function write() {
|
832 | var fallback = false;
|
833 | var fallbackValue = this.multiple ? [] : null;
|
834 | var fallbackOption = this.multiple ? [] : null;
|
835 |
|
836 | for (var i = 0, l = this.options.length; i < l; i++) {
|
837 | var option = this.options[i];
|
838 | var selected = option.selected;
|
839 | var optionBinder = self.get('attribute', option, 'o-value');
|
840 | var optionValue = optionBinder ? optionBinder.data : option.value;
|
841 | var selectedAtrribute = option.hasAttribute('selected');
|
842 |
|
843 | if (this.multiple) {
|
844 | if (selectedAtrribute) {
|
845 | fallback = true;
|
846 | fallbackOption.push(option);
|
847 | fallbackValue.push(optionValue);
|
848 | }
|
849 | } else {
|
850 | if (i === 0 || selectedAtrribute) {
|
851 | fallback = true;
|
852 | fallbackOption = option;
|
853 | fallbackValue = optionValue;
|
854 | }
|
855 | }
|
856 |
|
857 | if (caller === 'view') {
|
858 | if (selected) {
|
859 | if (this.multiple) {
|
860 | var includes = Utility.includes(this.data, optionValue);
|
861 |
|
862 | if (!includes) {
|
863 | this.selected = true;
|
864 | binder.data.push(optionValue);
|
865 | }
|
866 | } else if (!this.selected) {
|
867 | this.selected = true;
|
868 | binder.data = optionValue;
|
869 | }
|
870 | } else {
|
871 | if (this.multiple) {
|
872 | var _index2 = Utility.index(this.data, optionValue);
|
873 |
|
874 | if (_index2 !== -1) {
|
875 | binder.data.splice(_index2, 1);
|
876 | }
|
877 | } else if (!this.selected && i === l - 1) {
|
878 | binder.data = null;
|
879 | }
|
880 | }
|
881 | } else {
|
882 | if (this.multiple) {
|
883 | var _includes = Utility.includes(this.data, optionValue);
|
884 |
|
885 | if (_includes) {
|
886 | this.selected = true;
|
887 | option.selected = true;
|
888 | } else {
|
889 | option.selected = false;
|
890 | }
|
891 | } else {
|
892 | if (!this.selected) {
|
893 | var match = Utility.match(this.data, optionValue);
|
894 |
|
895 | if (match) {
|
896 | this.selected = true;
|
897 | option.selected = true;
|
898 | } else {
|
899 | option.selected = false;
|
900 | }
|
901 | } else {
|
902 | option.selected = false;
|
903 | }
|
904 | }
|
905 | }
|
906 | }
|
907 |
|
908 | if (!this.selected && fallback) {
|
909 | if (this.multiple) {
|
910 | for (var _i2 = 0, _l2 = fallbackOption.length; _i2 < _l2; _i2++) {
|
911 | fallbackOption[_i2].selected = true;
|
912 | binder.data.push(fallbackValue[_i2]);
|
913 | }
|
914 | } else {
|
915 | binder.data = fallbackValue;
|
916 | fallbackOption.selected = true;
|
917 | }
|
918 | }
|
919 |
|
920 | binder.meta.busy = false;
|
921 | }
|
922 | };
|
923 | } else if (type === 'radio') {
|
924 | return {
|
925 | read: function read() {
|
926 | this.form = binder.target.form || binder.container;
|
927 | this.query = "input[type=\"radio\"][o-value=\"".concat(binder.value, "\"]");
|
928 | this.nodes = this.form.querySelectorAll(this.query);
|
929 | this.radios = Array.prototype.slice.call(this.nodes);
|
930 |
|
931 | if (caller === 'view') {
|
932 | binder.data = this.radios.indexOf(binder.target);
|
933 | binder.meta.busy = false;
|
934 | return false;
|
935 | }
|
936 |
|
937 | this.data = binder.data;
|
938 |
|
939 | if (typeof this.data !== 'number') {
|
940 | binder.meta.busy = false;
|
941 | return false;
|
942 | }
|
943 | },
|
944 | write: function write() {
|
945 | for (var i = 0, l = this.radios.length; i < l; i++) {
|
946 | var radio = this.radios[i];
|
947 |
|
948 | if (i === this.data) {
|
949 | radio.checked = true;
|
950 | } else {
|
951 | radio.checked = false;
|
952 | }
|
953 | }
|
954 |
|
955 | binder.meta.busy = false;
|
956 | }
|
957 | };
|
958 | } else if (type === 'checkbox') {
|
959 | return {
|
960 | read: function read() {
|
961 | if (caller === 'view') {
|
962 | binder.data = binder.target.checked;
|
963 | binder.meta.busy = false;
|
964 | return false;
|
965 | }
|
966 |
|
967 | this.data = binder.data;
|
968 |
|
969 | if (typeof this.data !== 'boolean') {
|
970 | binder.meta.busy = false;
|
971 | return false;
|
972 | }
|
973 | },
|
974 | write: function write() {
|
975 | binder.target.checked = this.data;
|
976 | binder.meta.busy = false;
|
977 | }
|
978 | };
|
979 | } else {
|
980 | return {
|
981 | read: function read() {
|
982 | if (caller === 'view') {
|
983 | binder.data = binder.target.value;
|
984 | binder.meta.busy = false;
|
985 | return false;
|
986 | }
|
987 |
|
988 | this.data = binder.data;
|
989 |
|
990 | if (this.data === binder.target.value) {
|
991 | binder.meta.busy = false;
|
992 | return false;
|
993 | }
|
994 | },
|
995 | write: function write() {
|
996 | binder.target.value = this.data === undefined || this.data === null ? '' : this.data;
|
997 | binder.meta.busy = false;
|
998 | }
|
999 | };
|
1000 | }
|
1001 | }
|
1002 |
|
1003 | function Write(binder) {
|
1004 | return {
|
1005 | read: function read() {
|
1006 | this.data = binder.data;
|
1007 |
|
1008 | if (!this.data === binder.target.readOnly) {
|
1009 | return false;
|
1010 | }
|
1011 | },
|
1012 | write: function write() {
|
1013 | binder.target.readOnly = !this.data;
|
1014 | }
|
1015 | };
|
1016 | }
|
1017 |
|
1018 | var DATA = new Map();
|
1019 | var BINDERS = {
|
1020 | class: Class,
|
1021 | css: Style,
|
1022 | default: Default,
|
1023 | disable: Disable,
|
1024 | disabled: Disable,
|
1025 | each: Each,
|
1026 | enable: Enable,
|
1027 | enabled: Enable,
|
1028 | hide: Hide,
|
1029 | hidden: Hide,
|
1030 | href: Href,
|
1031 | html: Html,
|
1032 | label: Label,
|
1033 | on: On,
|
1034 | read: Read,
|
1035 | require: Require,
|
1036 | required: Require,
|
1037 | show: Show,
|
1038 | showed: Show,
|
1039 | style: Style,
|
1040 | text: Text,
|
1041 | value: Value,
|
1042 | write: Write
|
1043 | };
|
1044 | var Binder = {
|
1045 | get data() {
|
1046 | return DATA;
|
1047 | },
|
1048 |
|
1049 | get binders() {
|
1050 | return BINDERS;
|
1051 | },
|
1052 |
|
1053 | setup: function setup(options) {
|
1054 | return new Promise(function ($return, $error) {
|
1055 | options = options || {};
|
1056 | this.data.set('location', new Map());
|
1057 | this.data.set('attribute', new Map());
|
1058 |
|
1059 | for (var name in this.binders) {
|
1060 | this.binders[name] = this.binders[name].bind(this);
|
1061 | }
|
1062 |
|
1063 | if (options.binders) {
|
1064 | for (var _name in options.binders) {
|
1065 | if (_name in this.binders === false) {
|
1066 | this.binders[_name] = options.binders[_name].bind(this);
|
1067 | }
|
1068 | }
|
1069 | }
|
1070 |
|
1071 | return $return();
|
1072 | }.bind(this));
|
1073 | },
|
1074 | get: function get(type) {
|
1075 | if (!type) throw new Error('Oxe.binder.get - type argument required');
|
1076 | var result = this.data.get(type);
|
1077 | if (!result) return result;
|
1078 |
|
1079 | for (var i = 1, l = arguments.length; i < l; i++) {
|
1080 | var argument = arguments[i];
|
1081 | result = result.get(argument);
|
1082 |
|
1083 | if (!result) {
|
1084 | return result;
|
1085 | }
|
1086 | }
|
1087 |
|
1088 | return result;
|
1089 | },
|
1090 | create: function create(data) {
|
1091 | if (data.name === undefined) throw new Error('Oxe.binder.create - missing name');
|
1092 | if (data.value === undefined) throw new Error('Oxe.binder.create - missing value');
|
1093 | if (data.target === undefined) throw new Error('Oxe.binder.create - missing target');
|
1094 | if (data.container === undefined) throw new Error('Oxe.binder.create - missing container');
|
1095 | var originalValue = data.value;
|
1096 |
|
1097 | if (data.value.slice(0, 2) === '{{' && data.value.slice(-2) === '}}') {
|
1098 | data.value = data.value.slice(2, -2);
|
1099 | }
|
1100 |
|
1101 | if (data.value.indexOf('$') !== -1 && data.context && data.context.variable && data.context.path && data.context.key) {
|
1102 | var pattern = new RegExp("\\$".concat(data.context.variable, "(,|\\s+|\\.|\\|)?(.*)?$"), 'ig');
|
1103 | data.value = data.value.replace(pattern, "".concat(data.context.path, ".").concat(data.context.key, "$1$2"));
|
1104 | }
|
1105 |
|
1106 | var scope = data.container.scope;
|
1107 | var names = data.names || Utility.binderNames(data.name);
|
1108 | var pipes = data.pipes || Utility.binderPipes(data.value);
|
1109 | var values = data.values || Utility.binderValues(data.value);
|
1110 | var type = names[0];
|
1111 | var path = values.join('.');
|
1112 | var keys = [scope].concat(values);
|
1113 | var location = keys.join('.');
|
1114 | var meta = data.meta || {};
|
1115 | var context = data.context || {};
|
1116 | var source = type === 'on' || type === 'submit' ? data.container.methods : data.container.model;
|
1117 | return {
|
1118 | get location() {
|
1119 | return location;
|
1120 | },
|
1121 |
|
1122 | get type() {
|
1123 | return type;
|
1124 | },
|
1125 |
|
1126 | get path() {
|
1127 | return path;
|
1128 | },
|
1129 |
|
1130 | get scope() {
|
1131 | return scope;
|
1132 | },
|
1133 |
|
1134 | get name() {
|
1135 | return data.name;
|
1136 | },
|
1137 |
|
1138 | get value() {
|
1139 | return data.value;
|
1140 | },
|
1141 |
|
1142 | get target() {
|
1143 | return data.target;
|
1144 | },
|
1145 |
|
1146 | get container() {
|
1147 | return data.container;
|
1148 | },
|
1149 |
|
1150 | get model() {
|
1151 | return data.container.model;
|
1152 | },
|
1153 |
|
1154 | get methods() {
|
1155 | return data.container.methods;
|
1156 | },
|
1157 |
|
1158 | get keys() {
|
1159 | return keys;
|
1160 | },
|
1161 |
|
1162 | get names() {
|
1163 | return names;
|
1164 | },
|
1165 |
|
1166 | get pipes() {
|
1167 | return pipes;
|
1168 | },
|
1169 |
|
1170 | get values() {
|
1171 | return values;
|
1172 | },
|
1173 |
|
1174 | get meta() {
|
1175 | return meta;
|
1176 | },
|
1177 |
|
1178 | get context() {
|
1179 | return context;
|
1180 | },
|
1181 |
|
1182 | get originalValue() {
|
1183 | return originalValue;
|
1184 | },
|
1185 |
|
1186 | get data() {
|
1187 | var data = Utility.getByPath(source, values);
|
1188 | return Piper(this, data);
|
1189 | },
|
1190 |
|
1191 | set data(value) {
|
1192 | return Utility.setByPath(source, values, value);
|
1193 | }
|
1194 |
|
1195 | };
|
1196 | },
|
1197 | render: function render(binder, caller) {
|
1198 | if (binder.type === 'submit') return;
|
1199 | var type = binder.type in this.binders ? binder.type : 'default';
|
1200 | var render = this.binders[type](binder, caller);
|
1201 | Batcher.batch(render);
|
1202 | },
|
1203 | unbind: function unbind(node) {
|
1204 | this.data.get('location').forEach(function (scopes) {
|
1205 | scopes.forEach(function (binders) {
|
1206 | binders.forEach(function (binder, index) {
|
1207 | if (binder.target === node) {
|
1208 | binders.splice(index, 1);
|
1209 | }
|
1210 | });
|
1211 | });
|
1212 | });
|
1213 | this.data.get('attribute').delete(node);
|
1214 | },
|
1215 | bind: function bind(node, name, value, context) {
|
1216 | if (value === "$".concat(context.variable, ".$key") || value === "{{$".concat(context.variable, ".$key}}")) {
|
1217 | return Batcher.batch({
|
1218 | write: function write() {
|
1219 | node.textContent = context.key;
|
1220 | }
|
1221 | });
|
1222 | }
|
1223 |
|
1224 | if (value === "$".concat(context.variable, ".$index") || value === "{{$".concat(context.variable, ".$index}}")) {
|
1225 | return Batcher.batch({
|
1226 | write: function write() {
|
1227 | node.textContent = context.index;
|
1228 | }
|
1229 | });
|
1230 | }
|
1231 |
|
1232 | var binder = this.create({
|
1233 | name: name,
|
1234 | value: value,
|
1235 | target: node,
|
1236 | context: context,
|
1237 | container: context.container,
|
1238 | scope: context.container.scope
|
1239 | });
|
1240 |
|
1241 | if (!this.data.get('attribute').has(binder.target)) {
|
1242 | this.data.get('attribute').set(binder.target, new Map());
|
1243 | }
|
1244 |
|
1245 | if (!this.data.get('location').has(binder.scope)) {
|
1246 | this.data.get('location').set(binder.scope, new Map());
|
1247 | }
|
1248 |
|
1249 | if (!this.data.get('location').get(binder.scope).has(binder.path)) {
|
1250 | this.data.get('location').get(binder.scope).set(binder.path, []);
|
1251 | }
|
1252 |
|
1253 | this.data.get('attribute').get(binder.target).set(binder.name, binder);
|
1254 | this.data.get('location').get(binder.scope).get(binder.path).push(binder);
|
1255 | this.render(binder);
|
1256 | },
|
1257 | remove: function remove(node) {
|
1258 | this.unbind(node);
|
1259 |
|
1260 | for (var i = 0; i < node.childNodes.length; i++) {
|
1261 | this.remove(node.childNodes[i]);
|
1262 | }
|
1263 | },
|
1264 | add: function add(node, context) {
|
1265 | if (node.nodeType === Node.TEXT_NODE) {
|
1266 | if (node.textContent.indexOf('{{') === -1 || node.textContent.indexOf('}}') === -1) {
|
1267 | return;
|
1268 | }
|
1269 |
|
1270 | var start = node.textContent.indexOf('{{');
|
1271 |
|
1272 | if (start !== -1 && start !== 0) {
|
1273 | node = node.splitText(start);
|
1274 | }
|
1275 |
|
1276 | var end = node.textContent.indexOf('}}');
|
1277 | var length = node.textContent.length;
|
1278 |
|
1279 | if (end !== -1 && end !== length - 2) {
|
1280 | var split = node.splitText(end + 2);
|
1281 | this.add(split, context);
|
1282 | }
|
1283 |
|
1284 | this.bind(node, 'o-text', node.textContent, context);
|
1285 | } else if (node.nodeType === Node.ELEMENT_NODE) {
|
1286 | var skipChildren = false;
|
1287 | var attributes = node.attributes;
|
1288 |
|
1289 | for (var i = 0, l = attributes.length; i < l; i++) {
|
1290 | var attribute = attributes[i];
|
1291 |
|
1292 | if (attribute.name === 'o-html' || attribute.name === 'o-scope' || attribute.name.indexOf('o-each') === 0) {
|
1293 | skipChildren = true;
|
1294 | }
|
1295 |
|
1296 | if (attribute.name === 'o-value' || attribute.name === 'o-scope' || attribute.name === 'o-reset' || attribute.name === 'o-action' || attribute.name === 'o-method' || attribute.name === 'o-enctype' || attribute.name.indexOf('o-') !== 0) {
|
1297 | continue;
|
1298 | }
|
1299 |
|
1300 | this.bind(node, attribute.name, attribute.value, context);
|
1301 | }
|
1302 |
|
1303 | if ('o-value' in attributes) {
|
1304 | this.bind(node, 'o-value', attributes['o-value'].value, context);
|
1305 | }
|
1306 |
|
1307 | if (skipChildren) return;
|
1308 |
|
1309 | for (var _i3 = 0; _i3 < node.childNodes.length; _i3++) {
|
1310 | this.add(node.childNodes[_i3], context);
|
1311 | }
|
1312 | }
|
1313 | }
|
1314 | };
|
1315 |
|
1316 | function Change(event) {
|
1317 | return new Promise(function ($return, $error) {
|
1318 | if ('attributes' in event.target && 'o-value' in event.target.attributes) {
|
1319 | var binder = Binder.get('attribute', event.target, 'o-value');
|
1320 | Binder.render(binder, 'view');
|
1321 | }
|
1322 |
|
1323 | return $return();
|
1324 | });
|
1325 | }
|
1326 |
|
1327 | var Fetcher = {
|
1328 | header: null,
|
1329 | method: 'get',
|
1330 | mime: {
|
1331 | xml: 'text/xml; charset=utf-8',
|
1332 | html: 'text/html; charset=utf-8',
|
1333 | text: 'text/plain; charset=utf-8',
|
1334 | json: 'application/json; charset=utf-8',
|
1335 | js: 'application/javascript; charset=utf-8'
|
1336 | },
|
1337 | setup: function setup(options) {
|
1338 | return new Promise(function ($return, $error) {
|
1339 | options = options || {};
|
1340 | this.path = options.path;
|
1341 | this.origin = options.origin;
|
1342 | this.request = options.request;
|
1343 | this.response = options.response;
|
1344 | this.acceptType = options.acceptType;
|
1345 | this.credentials = options.credentials;
|
1346 | this.contentType = options.contentType;
|
1347 | this.responseType = options.responseType;
|
1348 | this.method = options.method || this.method;
|
1349 | this.headers = options.headers || this.headers;
|
1350 | return $return();
|
1351 | }.bind(this));
|
1352 | },
|
1353 | serialize: function serialize(data) {
|
1354 | return new Promise(function ($return, $error) {
|
1355 | var query = '';
|
1356 |
|
1357 | for (var name in data) {
|
1358 | query = query.length > 0 ? query + '&' : query;
|
1359 | query = query + encodeURIComponent(name) + '=' + encodeURIComponent(data[name]);
|
1360 | }
|
1361 |
|
1362 | return $return(query);
|
1363 | });
|
1364 | },
|
1365 | fetch: function fetch(options) {
|
1366 | return new Promise(function ($return, $error) {
|
1367 | var data, copy, result, fetched, _copy, _result2;
|
1368 |
|
1369 | data = Object.assign({}, options);
|
1370 | data.path = data.path || this.path;
|
1371 | data.origin = data.origin || this.origin;
|
1372 | if (data.path && typeof data.path === 'string' && data.path.charAt(0) === '/') data.path = data.path.slice(1);
|
1373 | if (data.origin && typeof data.origin === 'string' && data.origin.charAt(data.origin.length - 1) === '/') data.origin = data.origin.slice(0, -1);
|
1374 | if (data.path && data.origin && !data.url) data.url = data.origin + '/' + data.path;
|
1375 | if (!data.method) return $error(new Error('Oxe.fetcher - requires method option'));
|
1376 | if (!data.url) return $error(new Error('Oxe.fetcher - requires url or origin and path option'));
|
1377 | if (!data.headers && this.headers) data.headers = this.headers;
|
1378 | if (typeof data.method === 'string') data.method = data.method.toUpperCase() || this.method;
|
1379 | if (!data.acceptType && this.acceptType) data.acceptType = this.acceptType;
|
1380 | if (!data.contentType && this.contentType) data.contentType = this.contentType;
|
1381 | if (!data.responseType && this.responseType) data.responseType = this.responseType;
|
1382 | if (!data.credentials && this.credentials) data.credentials = this.credentials;
|
1383 | if (!data.mode && this.mode) data.mode = this.mode;
|
1384 | if (!data.cache && this.cache) data.cahce = this.cache;
|
1385 | if (!data.redirect && this.redirect) data.redirect = this.redirect;
|
1386 | if (!data.referrer && this.referrer) data.referrer = this.referrer;
|
1387 | if (!data.referrerPolicy && this.referrerPolicy) data.referrerPolicy = this.referrerPolicy;
|
1388 | if (!data.signal && this.signal) data.signal = this.signal;
|
1389 | if (!data.integrity && this.integrity) data.integrity = this.integrity;
|
1390 | if (!data.keepAlive && this.keepAlive) data.keepAlive = this.keepAlive;
|
1391 |
|
1392 | if (data.contentType) {
|
1393 | data.headers = data.headers || {};
|
1394 |
|
1395 | switch (data.contentType) {
|
1396 | case 'js':
|
1397 | data.headers['Content-Type'] = this.mime.js;
|
1398 | break;
|
1399 |
|
1400 | case 'xml':
|
1401 | data.headers['Content-Type'] = this.mime.xml;
|
1402 | break;
|
1403 |
|
1404 | case 'html':
|
1405 | data.headers['Content-Type'] = this.mime.html;
|
1406 | break;
|
1407 |
|
1408 | case 'json':
|
1409 | data.headers['Content-Type'] = this.mime.json;
|
1410 | break;
|
1411 |
|
1412 | default:
|
1413 | data.headers['Content-Type'] = data.contentType;
|
1414 | }
|
1415 | }
|
1416 |
|
1417 | if (data.acceptType) {
|
1418 | data.headers = data.headers || {};
|
1419 |
|
1420 | switch (data.acceptType) {
|
1421 | case 'js':
|
1422 | data.headers['Accept'] = this.mime.js;
|
1423 | break;
|
1424 |
|
1425 | case 'xml':
|
1426 | data.headers['Accept'] = this.mime.xml;
|
1427 | break;
|
1428 |
|
1429 | case 'html':
|
1430 | data.headers['Accept'] = this.mime.html;
|
1431 | break;
|
1432 |
|
1433 | case 'json':
|
1434 | data.headers['Accept'] = this.mime.json;
|
1435 | break;
|
1436 |
|
1437 | default:
|
1438 | data.headers['Accept'] = data.acceptType;
|
1439 | }
|
1440 | }
|
1441 |
|
1442 | if (typeof this.request === 'function') {
|
1443 | copy = Object.assign({}, data);
|
1444 | return Promise.resolve(this.request(copy)).then(function ($await_40) {
|
1445 | try {
|
1446 | result = $await_40;
|
1447 |
|
1448 | if (result === false) {
|
1449 | return $return(data);
|
1450 | }
|
1451 |
|
1452 | if (_typeof(result) === 'object') {
|
1453 | Object.assign(data, result);
|
1454 | }
|
1455 |
|
1456 | return $If_1.call(this);
|
1457 | } catch ($boundEx) {
|
1458 | return $error($boundEx);
|
1459 | }
|
1460 | }.bind(this), $error);
|
1461 | }
|
1462 |
|
1463 | function $If_1() {
|
1464 | if (data.body) {
|
1465 | if (data.method === 'GET') {
|
1466 | return Promise.resolve(this.serialize(data.body)).then(function ($await_41) {
|
1467 | try {
|
1468 | data.url = data.url + '?' + $await_41;
|
1469 | return $If_5.call(this);
|
1470 | } catch ($boundEx) {
|
1471 | return $error($boundEx);
|
1472 | }
|
1473 | }.bind(this), $error);
|
1474 | } else {
|
1475 | if (data.contentType === 'json') {
|
1476 | data.body = JSON.stringify(data.body);
|
1477 | }
|
1478 |
|
1479 | return $If_5.call(this);
|
1480 | }
|
1481 |
|
1482 | function $If_5() {
|
1483 | return $If_2.call(this);
|
1484 | }
|
1485 | }
|
1486 |
|
1487 | function $If_2() {
|
1488 | return Promise.resolve(window.fetch(data.url, Object.assign({}, data))).then(function ($await_42) {
|
1489 | try {
|
1490 | fetched = $await_42;
|
1491 | data.code = fetched.status;
|
1492 | data.message = fetched.statusText;
|
1493 |
|
1494 | if (!data.responseType) {
|
1495 | data.body = fetched.body;
|
1496 | return $If_3.call(this);
|
1497 | } else {
|
1498 | return Promise.resolve(fetched[data.responseType === 'buffer' ? 'arrayBuffer' : data.responseType]()).then(function ($await_43) {
|
1499 | try {
|
1500 | data.body = $await_43;
|
1501 | return $If_3.call(this);
|
1502 | } catch ($boundEx) {
|
1503 | return $error($boundEx);
|
1504 | }
|
1505 | }.bind(this), $error);
|
1506 | }
|
1507 |
|
1508 | function $If_3() {
|
1509 | if (this.response) {
|
1510 | _copy = Object.assign({}, data);
|
1511 | return Promise.resolve(this.response(_copy)).then(function ($await_44) {
|
1512 | try {
|
1513 | _result2 = $await_44;
|
1514 |
|
1515 | if (_result2 === false) {
|
1516 | return $return(data);
|
1517 | }
|
1518 |
|
1519 | if (_typeof(_result2) === 'object') {
|
1520 | Object.assign(data, _result2);
|
1521 | }
|
1522 |
|
1523 | return $If_4.call(this);
|
1524 | } catch ($boundEx) {
|
1525 | return $error($boundEx);
|
1526 | }
|
1527 | }.bind(this), $error);
|
1528 | }
|
1529 |
|
1530 | function $If_4() {
|
1531 | return $return(data);
|
1532 | }
|
1533 |
|
1534 | return $If_4.call(this);
|
1535 | }
|
1536 | } catch ($boundEx) {
|
1537 | return $error($boundEx);
|
1538 | }
|
1539 | }.bind(this), $error);
|
1540 | }
|
1541 |
|
1542 | return $If_2.call(this);
|
1543 | }
|
1544 |
|
1545 | return $If_1.call(this);
|
1546 | }.bind(this));
|
1547 | },
|
1548 | post: function post(data) {
|
1549 | return new Promise(function ($return, $error) {
|
1550 | data = typeof data === 'string' ? {
|
1551 | url: data
|
1552 | } : data;
|
1553 | data.method = 'post';
|
1554 | return $return(this.fetch(data));
|
1555 | }.bind(this));
|
1556 | },
|
1557 | get: function get(data) {
|
1558 | return new Promise(function ($return, $error) {
|
1559 | data = typeof data === 'string' ? {
|
1560 | url: data
|
1561 | } : data;
|
1562 | data.method = 'get';
|
1563 | return $return(this.fetch(data));
|
1564 | }.bind(this));
|
1565 | },
|
1566 | put: function put(data) {
|
1567 | return new Promise(function ($return, $error) {
|
1568 | data = typeof data === 'string' ? {
|
1569 | url: data
|
1570 | } : data;
|
1571 | data.method = 'put';
|
1572 | return $return(this.fetch(data));
|
1573 | }.bind(this));
|
1574 | },
|
1575 | head: function head(data) {
|
1576 | return new Promise(function ($return, $error) {
|
1577 | data = typeof data === 'string' ? {
|
1578 | url: data
|
1579 | } : data;
|
1580 | data.method = 'head';
|
1581 | return $return(this.fetch(data));
|
1582 | }.bind(this));
|
1583 | },
|
1584 | patch: function patch(data) {
|
1585 | return new Promise(function ($return, $error) {
|
1586 | data = typeof data === 'string' ? {
|
1587 | url: data
|
1588 | } : data;
|
1589 | data.method = 'patch';
|
1590 | return $return(this.fetch(data));
|
1591 | }.bind(this));
|
1592 | },
|
1593 | delete: function _delete(data) {
|
1594 | return new Promise(function ($return, $error) {
|
1595 | data = typeof data === 'string' ? {
|
1596 | url: data
|
1597 | } : data;
|
1598 | data.method = 'delete';
|
1599 | return $return(this.fetch(data));
|
1600 | }.bind(this));
|
1601 | },
|
1602 | options: function options(data) {
|
1603 | return new Promise(function ($return, $error) {
|
1604 | data = typeof data === 'string' ? {
|
1605 | url: data
|
1606 | } : data;
|
1607 | data.method = 'options';
|
1608 | return $return(this.fetch(data));
|
1609 | }.bind(this));
|
1610 | },
|
1611 | connect: function connect(data) {
|
1612 | return new Promise(function ($return, $error) {
|
1613 | data = typeof data === 'string' ? {
|
1614 | url: data
|
1615 | } : data;
|
1616 | data.method = 'connect';
|
1617 | return $return(this.fetch(data));
|
1618 | }.bind(this));
|
1619 | }
|
1620 | };
|
1621 |
|
1622 | function Submit(event) {
|
1623 | return new Promise(function ($return, $error) {
|
1624 | var data, elements, i, l, element, type, binder, value, name, submit, options, result;
|
1625 |
|
1626 | if (event.target.hasAttribute('o-submit') === false) {
|
1627 | return $return();
|
1628 | }
|
1629 |
|
1630 | event.preventDefault();
|
1631 | data = {};
|
1632 | elements = event.target.querySelectorAll('*');
|
1633 |
|
1634 | for (i = 0, l = elements.length; i < l; i++) {
|
1635 | element = elements[i];
|
1636 | type = element.type;
|
1637 |
|
1638 | if (!type && name !== 'TEXTAREA' || type === 'submit' || type === 'button' || !type) {
|
1639 | continue;
|
1640 | }
|
1641 |
|
1642 | binder = Binder.get('attribute', element, 'o-value');
|
1643 | value = binder ? binder.data : element.value;
|
1644 | name = element.name || (binder ? binder.values[binder.values.length - 1] : i);
|
1645 | if (!name) continue;
|
1646 | data[name] = value;
|
1647 | }
|
1648 |
|
1649 | submit = Binder.get('attribute', event.target, 'o-submit');
|
1650 | return Promise.resolve(submit.data.call(submit.container, data, event)).then(function ($await_45) {
|
1651 | try {
|
1652 | options = $await_45;
|
1653 |
|
1654 | if (_typeof(options) === 'object') {
|
1655 | options.url = options.url || event.target.getAttribute('o-action');
|
1656 | options.method = options.method || event.target.getAttribute('o-method');
|
1657 | options.contentType = options.contentType || event.target.getAttribute('o-enctype');
|
1658 | return Promise.resolve(Fetcher.fetch(options)).then(function ($await_46) {
|
1659 | try {
|
1660 | result = $await_46;
|
1661 |
|
1662 | if (options.handler) {
|
1663 | return Promise.resolve(options.handler(result)).then(function ($await_47) {
|
1664 | try {
|
1665 | return $If_7.call(this);
|
1666 | } catch ($boundEx) {
|
1667 | return $error($boundEx);
|
1668 | }
|
1669 | }.bind(this), $error);
|
1670 | }
|
1671 |
|
1672 | function $If_7() {
|
1673 | return $If_6.call(this);
|
1674 | }
|
1675 |
|
1676 | return $If_7.call(this);
|
1677 | } catch ($boundEx) {
|
1678 | return $error($boundEx);
|
1679 | }
|
1680 | }.bind(this), $error);
|
1681 | }
|
1682 |
|
1683 | function $If_6() {
|
1684 | if (event.target.hasAttribute('o-reset') || _typeof(options) === 'object' && options.reset) {
|
1685 | event.target.reset();
|
1686 | }
|
1687 |
|
1688 | return $return();
|
1689 | }
|
1690 |
|
1691 | return $If_6.call(this);
|
1692 | } catch ($boundEx) {
|
1693 | return $error($boundEx);
|
1694 | }
|
1695 | }.bind(this), $error);
|
1696 | });
|
1697 | }
|
1698 |
|
1699 | function Input(event) {
|
1700 | return new Promise(function ($return, $error) {
|
1701 | if (event.target.type !== 'radio' && event.target.type !== 'option' && event.target.type !== 'checkbox' && event.target.type !== 'select-one' && event.target.type !== 'select-multiple' && 'attributes' in event.target && 'o-value' in event.target.attributes) {
|
1702 | var binder = Binder.get('attribute', event.target, 'o-value');
|
1703 | Binder.render(binder, 'view');
|
1704 | }
|
1705 |
|
1706 | return $return();
|
1707 | });
|
1708 | }
|
1709 |
|
1710 | function Reset(event) {
|
1711 | return new Promise(function ($return, $error) {
|
1712 | if (event.target.hasAttribute('o-reset') === false) {
|
1713 | return $return();
|
1714 | }
|
1715 |
|
1716 | event.preventDefault();
|
1717 | var elements = event.target.querySelectorAll('*');
|
1718 |
|
1719 | for (var i = 0, l = elements.length; i < l; i++) {
|
1720 | var element = elements[i];
|
1721 | var name = element.nodeName;
|
1722 | var type = element.type;
|
1723 |
|
1724 | if (!type && name !== 'TEXTAREA' || type === 'submit' || type === 'button' || !type) {
|
1725 | continue;
|
1726 | }
|
1727 |
|
1728 | var binder = Binder.get('attribute', element, 'o-value');
|
1729 |
|
1730 | if (!binder) {
|
1731 | if (type === 'select-one' || type === 'select-multiple') {
|
1732 | element.selectedIndex = null;
|
1733 | } else if (type === 'radio' || type === 'checkbox') {
|
1734 | element.checked = false;
|
1735 | } else {
|
1736 | element.value = null;
|
1737 | }
|
1738 | } else if (type === 'select-one') {
|
1739 | binder.data = null;
|
1740 | } else if (type === 'select-multiple') {
|
1741 | binder.data = [];
|
1742 | } else if (type === 'radio' || type === 'checkbox') {
|
1743 | binder.data = false;
|
1744 | } else {
|
1745 | binder.data = '';
|
1746 | }
|
1747 | }
|
1748 |
|
1749 | return $return();
|
1750 | });
|
1751 | }
|
1752 |
|
1753 | var BASE;
|
1754 | var Path = {
|
1755 | get base() {
|
1756 | if (!BASE) BASE = window.document.querySelector('base');
|
1757 | if (BASE) return BASE.href;
|
1758 | return window.location.origin + (window.location.pathname ? window.location.pathname : '/');
|
1759 | },
|
1760 |
|
1761 | setup: function setup(option) {
|
1762 | return new Promise(function ($return, $error) {
|
1763 | option = option || {};
|
1764 |
|
1765 | if (option.base) {
|
1766 | BASE = window.document.querySelector('base');
|
1767 |
|
1768 | if (!BASE) {
|
1769 | BASE = window.document.createElement('base');
|
1770 | window.document.head.insertBefore(BASE, window.document.head.firstElementChild);
|
1771 | }
|
1772 |
|
1773 | BASE.href = option.base;
|
1774 | }
|
1775 |
|
1776 | return $return();
|
1777 | });
|
1778 | },
|
1779 | extension: function extension(data) {
|
1780 | var position = data.lastIndexOf('.');
|
1781 | return position > 0 ? data.slice(position + 1) : '';
|
1782 | },
|
1783 | clean: function clean(data) {
|
1784 | var hash = window.location.hash;
|
1785 | var search = window.location.search;
|
1786 | var origin = window.location.origin;
|
1787 | var protocol = window.location.protocol + '//';
|
1788 |
|
1789 | if (data.slice(0, origin.length) === origin) {
|
1790 | data = data.slice(origin.length);
|
1791 | }
|
1792 |
|
1793 | if (data.slice(0, protocol.length) === protocol) {
|
1794 | data = data.slice(protocol.length);
|
1795 | }
|
1796 |
|
1797 | if (data.slice(-hash.length) === hash) {
|
1798 | data = data.slice(0, -hash.length);
|
1799 | }
|
1800 |
|
1801 | if (data.slice(-search.length) === search) {
|
1802 | data = data.slice(0, -search.length);
|
1803 | }
|
1804 |
|
1805 | return data || '/';
|
1806 | },
|
1807 | normalize: function normalize(data) {
|
1808 | var parser = window.document.createElement('a');
|
1809 | data = this.clean(data);
|
1810 | data = data.replace(/\/+/g, '/');
|
1811 | parser.href = data;
|
1812 | data = parser.pathname;
|
1813 | data = data ? data : '/';
|
1814 |
|
1815 | if (data !== '/' && data.slice(-1) === '/') {
|
1816 | data = data.slice(0, -1);
|
1817 | }
|
1818 |
|
1819 | return data;
|
1820 | },
|
1821 | join: function join() {
|
1822 | if (!arguments.length) {
|
1823 | throw new Error('Oxe.path.join - argument required');
|
1824 | }
|
1825 |
|
1826 | var result = [];
|
1827 |
|
1828 | for (var i = 0, l = arguments.length; i < l; i++) {
|
1829 | result.push(arguments[i]);
|
1830 | }
|
1831 |
|
1832 | return this.normalize(result.join('/'));
|
1833 | }
|
1834 | };
|
1835 | var Transformer = {
|
1836 | innerHandler: function innerHandler(character, index, string) {
|
1837 | if (string[index - 1] === '\\') return;
|
1838 | if (character === '\'') return '\\\'';
|
1839 | if (character === '\"') return '\\"';
|
1840 | if (character === '\t') return '\\t';
|
1841 | if (character === '\r') return '\\r';
|
1842 | if (character === '\n') return '\\n';
|
1843 | if (character === '\w') return '\\w';
|
1844 | if (character === '\b') return '\\b';
|
1845 | },
|
1846 | updateString: function updateString(value, index, string) {
|
1847 | return string.slice(0, index) + value + string.slice(index + 1);
|
1848 | },
|
1849 | updateIndex: function updateIndex(value, index) {
|
1850 | return index + value.length - 1;
|
1851 | },
|
1852 | template: function template(data) {
|
1853 | var first = data.indexOf('`');
|
1854 | var second = data.indexOf('`', first + 1);
|
1855 | if (first === -1 || second === -1) return data;
|
1856 | var value;
|
1857 | var ends = 0;
|
1858 | var starts = 0;
|
1859 | var string = data;
|
1860 | var isInner = false;
|
1861 |
|
1862 | for (var index = 0; index < string.length; index++) {
|
1863 | var character = string[index];
|
1864 |
|
1865 | if (character === '`' && string[index - 1] !== '\\') {
|
1866 | if (isInner) {
|
1867 | ends++;
|
1868 | value = '\'';
|
1869 | isInner = false;
|
1870 | string = this.updateString(value, index, string);
|
1871 | index = this.updateIndex(value, index);
|
1872 | } else {
|
1873 | starts++;
|
1874 | value = '\'';
|
1875 | isInner = true;
|
1876 | string = this.updateString(value, index, string);
|
1877 | index = this.updateIndex(value, index);
|
1878 | }
|
1879 | } else if (isInner) {
|
1880 | if (value = this.innerHandler(character, index, string)) {
|
1881 | string = this.updateString(value, index, string);
|
1882 | index = this.updateIndex(value, index);
|
1883 | }
|
1884 | }
|
1885 | }
|
1886 |
|
1887 | string = string.replace(/\${(.*?)}/g, '\'+$1+\'');
|
1888 |
|
1889 | if (starts === ends) {
|
1890 | return string;
|
1891 | } else {
|
1892 | throw new Error('import transformer missing backtick');
|
1893 | }
|
1894 | },
|
1895 | exp: /export\s+default\s*(var|let|const)?/,
|
1896 | imps: /import(?:\s+(?:\*\s+as\s+)?\w+\s+from)?\s+(?:'|").*?(?:'|");?\n?/g,
|
1897 | imp: /import(?:\s+(?:\*\s+as\s+)?(\w+)\s+from)?\s+(?:'|")(.*?)(?:'|");?\n?/,
|
1898 | module: function module(code, url) {
|
1899 | var before = 'return Promise.all([\n';
|
1900 | var after = ']).then(function ($MODULES) {\n';
|
1901 | var parentImport = url.slice(0, url.lastIndexOf('/') + 1);
|
1902 | var imps = code.match(this.imps) || [];
|
1903 |
|
1904 | for (var i = 0, l = imps.length; i < l; i++) {
|
1905 | var imp = imps[i].match(this.imp);
|
1906 | var rawImport = imp[0];
|
1907 | var nameImport = imp[1];
|
1908 | var pathImport = imp[2];
|
1909 |
|
1910 | if (pathImport.slice(0, 1) !== '/') {
|
1911 | pathImport = Path.normalize(parentImport + '/' + pathImport);
|
1912 | } else {
|
1913 | pathImport = Path.normalize(pathImport);
|
1914 | }
|
1915 |
|
1916 | before = before + '\t$LOADER.load("' + pathImport + '"),\n';
|
1917 | after = after + 'var ' + nameImport + ' = $MODULES[' + i + '].default;\n';
|
1918 | code = code.replace(rawImport, '');
|
1919 | }
|
1920 |
|
1921 | if (this.exp.test(code)) {
|
1922 | code = code.replace(this.exp, 'var $DEFAULT = ');
|
1923 | code = code + '\n\nreturn { default: $DEFAULT };\n';
|
1924 | }
|
1925 |
|
1926 | code = '"use strict";\n' + before + after + code + '});';
|
1927 | return code;
|
1928 | }
|
1929 | };
|
1930 | var Loader = {
|
1931 | data: {},
|
1932 | type: 'esm',
|
1933 | setup: function setup(options) {
|
1934 | return new Promise(function ($return, $error) {
|
1935 | var self = this;
|
1936 | options = options || {};
|
1937 | this.type = options.type || this.type;
|
1938 |
|
1939 | if (options.loads) {
|
1940 | return $return(Promise.all(options.loads.map(function (load) {
|
1941 | return self.load(load);
|
1942 | })));
|
1943 | }
|
1944 |
|
1945 | return $return();
|
1946 | }.bind(this));
|
1947 | },
|
1948 | fetch: function fetch(url, type) {
|
1949 | return new Promise(function ($return, $error) {
|
1950 | var data, code;
|
1951 | return Promise.resolve(window.fetch(url)).then(function ($await_48) {
|
1952 | try {
|
1953 | data = $await_48;
|
1954 |
|
1955 | if (data.status == 404) {
|
1956 | return $error(new Error('Oxe.loader.load - not found ' + url));
|
1957 | }
|
1958 |
|
1959 | if (data.status < 200 || data.status > 300 && data.status != 304) {
|
1960 | return $error(new Error(data.statusText));
|
1961 | }
|
1962 |
|
1963 | return Promise.resolve(data.text()).then(function ($await_49) {
|
1964 | try {
|
1965 | code = $await_49;
|
1966 |
|
1967 | if (type === 'es' || type === 'est') {
|
1968 | code = Transformer.template(code);
|
1969 | }
|
1970 |
|
1971 | if (type === 'es' || type === 'esm') {
|
1972 | code = Transformer.module(code, url);
|
1973 | }
|
1974 |
|
1975 | code = new Function('window', 'document', '$LOADER', code);
|
1976 | this.data[url] = code(window, window.document, this);
|
1977 | return $return(this.data[url]);
|
1978 | } catch ($boundEx) {
|
1979 | return $error($boundEx);
|
1980 | }
|
1981 | }.bind(this), $error);
|
1982 | } catch ($boundEx) {
|
1983 | return $error($boundEx);
|
1984 | }
|
1985 | }.bind(this), $error);
|
1986 | }.bind(this));
|
1987 | },
|
1988 | load: function load() {
|
1989 | var $args = arguments;
|
1990 | return new Promise(function ($return, $error) {
|
1991 | var url, type;
|
1992 |
|
1993 | if (_typeof($args[0]) === 'object') {
|
1994 | url = $args[0]['url'];
|
1995 | type = $args[0]['type'];
|
1996 | } else {
|
1997 | url = $args[0];
|
1998 | type = $args[1] || this.type;
|
1999 | }
|
2000 |
|
2001 | if (!url) {
|
2002 | return $error(new Error('Oxe.loader.load - url argument required'));
|
2003 | }
|
2004 |
|
2005 | url = Path.normalize(url);
|
2006 |
|
2007 | if (url in this.data === false) {
|
2008 | this.data[url] = this.fetch(url, type);
|
2009 | }
|
2010 |
|
2011 | return $return(this.data[url]);
|
2012 | }.bind(this));
|
2013 | }
|
2014 | };
|
2015 | var EVENTS = {};
|
2016 | var Events = {
|
2017 | get events() {
|
2018 | return EVENTS;
|
2019 | },
|
2020 |
|
2021 | on: function on(name, method) {
|
2022 | if (!(name in this.events)) {
|
2023 | this.events[name] = [];
|
2024 | }
|
2025 |
|
2026 | this.events[name].push(method);
|
2027 | },
|
2028 | off: function off(name, method) {
|
2029 | if (name in this.events) {
|
2030 | var _index3 = this.events[name].indexOf(method);
|
2031 |
|
2032 | if (_index3 !== -1) {
|
2033 | this.events[name].splice(_index3, 1);
|
2034 | }
|
2035 | }
|
2036 | },
|
2037 | emit: function emit(name) {
|
2038 | if (name in this.events) {
|
2039 | var methods = this.events[name];
|
2040 | var args = Array.prototype.slice.call(arguments, 1);
|
2041 |
|
2042 | for (var i = 0, l = methods.length; i < l; i++) {
|
2043 | methods[i].apply(this, args);
|
2044 | }
|
2045 | }
|
2046 | }
|
2047 | };
|
2048 | var DATA$1 = {};
|
2049 | var Methods = {
|
2050 | get data() {
|
2051 | return DATA$1;
|
2052 | },
|
2053 |
|
2054 | get: function get(path) {
|
2055 | return Utility.getByPath(this.data, path);
|
2056 | },
|
2057 | set: function set(path, data) {
|
2058 | return Utility.setByPath(this.data, path, data);
|
2059 | }
|
2060 | };
|
2061 | var Observer = {
|
2062 | splice: function splice() {
|
2063 | var self = this;
|
2064 | var startIndex = arguments[0];
|
2065 | var deleteCount = arguments[1];
|
2066 | var addCount = arguments.length > 2 ? arguments.length - 2 : 0;
|
2067 |
|
2068 | if (typeof startIndex !== 'number' || typeof deleteCount !== 'number') {
|
2069 | return [];
|
2070 | }
|
2071 |
|
2072 | if (startIndex < 0) {
|
2073 | startIndex = self.length + startIndex;
|
2074 | startIndex = startIndex > 0 ? startIndex : 0;
|
2075 | } else {
|
2076 | startIndex = startIndex < self.length ? startIndex : self.length;
|
2077 | }
|
2078 |
|
2079 | if (deleteCount < 0) {
|
2080 | deleteCount = 0;
|
2081 | } else if (deleteCount > self.length - startIndex) {
|
2082 | deleteCount = self.length - startIndex;
|
2083 | }
|
2084 |
|
2085 | var totalCount = self.$meta.length;
|
2086 | var argumentIndex = 2;
|
2087 | var argumentsCount = arguments.length - argumentIndex;
|
2088 | var result = self.slice(startIndex, deleteCount);
|
2089 | var updateCount = totalCount - 1 - startIndex;
|
2090 | var promises = [];
|
2091 | var length = self.length + addCount - deleteCount;
|
2092 |
|
2093 | if (self.length !== length) {
|
2094 | promises.push(self.$meta.listener.bind(null, self, self.$meta.path.slice(0, -1), 'length'));
|
2095 | }
|
2096 |
|
2097 | if (updateCount > 0) {
|
2098 | var value;
|
2099 | var _index4 = startIndex;
|
2100 |
|
2101 | while (updateCount--) {
|
2102 | var key = _index4++;
|
2103 |
|
2104 | if (argumentsCount && argumentIndex < argumentsCount) {
|
2105 | value = arguments[argumentIndex++];
|
2106 | } else {
|
2107 | value = self.$meta[_index4];
|
2108 | }
|
2109 |
|
2110 | self.$meta[key] = Observer.create(value, self.$meta.listener, self.$meta.path + key);
|
2111 | promises.push(self.$meta.listener.bind(null, self.$meta[key], self.$meta.path + key, key));
|
2112 | }
|
2113 | }
|
2114 |
|
2115 | if (addCount > 0) {
|
2116 | while (addCount--) {
|
2117 | var _key = self.length;
|
2118 |
|
2119 | if (_key in this === false) {
|
2120 | Object.defineProperty(this, _key, Observer.descriptor(_key));
|
2121 | }
|
2122 |
|
2123 | self.$meta[_key] = Observer.create(arguments[argumentIndex++], self.$meta.listener, self.$meta.path + _key);
|
2124 | promises.push(self.$meta.listener.bind(null, self.$meta[_key], self.$meta.path + _key, _key));
|
2125 | }
|
2126 | }
|
2127 |
|
2128 | if (deleteCount > 0) {
|
2129 | while (deleteCount--) {
|
2130 | self.$meta.length--;
|
2131 | self.length--;
|
2132 | var _key2 = self.length;
|
2133 | promises.push(self.$meta.listener.bind(null, undefined, self.$meta.path + _key2, _key2));
|
2134 | }
|
2135 | }
|
2136 |
|
2137 | Promise.resolve().then(function () {
|
2138 | promises.reduce(function (promise, item) {
|
2139 | return promise.then(item);
|
2140 | }, Promise.resolve());
|
2141 | }).catch(console.error);
|
2142 | return result;
|
2143 | },
|
2144 | arrayProperties: function arrayProperties() {
|
2145 | var self = this;
|
2146 | return {
|
2147 | push: {
|
2148 | value: function value() {
|
2149 | if (!arguments.length) return this.length;
|
2150 |
|
2151 | for (var i = 0, l = arguments.length; i < l; i++) {
|
2152 | self.splice.call(this, this.length, 0, arguments[i]);
|
2153 | }
|
2154 |
|
2155 | return this.length;
|
2156 | }
|
2157 | },
|
2158 | unshift: {
|
2159 | value: function value() {
|
2160 | if (!arguments.length) return this.length;
|
2161 |
|
2162 | for (var i = 0, l = arguments.length; i < l; i++) {
|
2163 | self.splice.call(this, 0, 0, arguments[i]);
|
2164 | }
|
2165 |
|
2166 | return this.length;
|
2167 | }
|
2168 | },
|
2169 | pop: {
|
2170 | value: function value() {
|
2171 | if (!this.length) return;
|
2172 | var result = self.splice.call(this, this.length - 1, 1);
|
2173 | return result[0];
|
2174 | }
|
2175 | },
|
2176 | shift: {
|
2177 | value: function value() {
|
2178 | if (!this.length) return;
|
2179 | var result = self.splice.call(this, 0, 1);
|
2180 | return result[0];
|
2181 | }
|
2182 | },
|
2183 | splice: {
|
2184 | value: self.splice
|
2185 | }
|
2186 | };
|
2187 | },
|
2188 | objectProperties: function objectProperties() {
|
2189 | var self = this;
|
2190 | return {
|
2191 | $get: {
|
2192 | value: function value(key) {
|
2193 | return this.$meta[key];
|
2194 | }
|
2195 | },
|
2196 | $set: {
|
2197 | value: function value(key, _value3) {
|
2198 | if (_value3 !== this.$meta[key]) {
|
2199 | if (key in this === false) {
|
2200 | Object.defineProperty(this, key, self.descriptor(key));
|
2201 | }
|
2202 |
|
2203 | this.$meta[key] = self.create(_value3, this.$meta.listener, this.$meta.path + key);
|
2204 | this.$meta.listener(this.$meta[key], this.$meta.path + key, key, this);
|
2205 | }
|
2206 | }
|
2207 | },
|
2208 | $remove: {
|
2209 | value: function value(key) {
|
2210 | if (key in this) {
|
2211 | if (this.constructor === Array) {
|
2212 | return self.splice.call(this, key, 1);
|
2213 | } else {
|
2214 | var result = this[key];
|
2215 | delete this.$meta[key];
|
2216 | delete this[key];
|
2217 | this.$meta.listener(undefined, this.$meta.path + key, key);
|
2218 | return result;
|
2219 | }
|
2220 | }
|
2221 | }
|
2222 | }
|
2223 | };
|
2224 | },
|
2225 | descriptor: function descriptor(key) {
|
2226 | var self = this;
|
2227 | return {
|
2228 | enumerable: true,
|
2229 | configurable: true,
|
2230 | get: function get() {
|
2231 | return this.$meta[key];
|
2232 | },
|
2233 | set: function set(value) {
|
2234 | if (value !== this.$meta[key]) {
|
2235 | this.$meta[key] = self.create(value, this.$meta.listener, this.$meta.path + key);
|
2236 | this.$meta.listener(this.$meta[key], this.$meta.path + key, key, this);
|
2237 | }
|
2238 | }
|
2239 | };
|
2240 | },
|
2241 | create: function create(source, listener, path) {
|
2242 | if (!source || source.constructor !== Object && source.constructor !== Array) {
|
2243 | return source;
|
2244 | }
|
2245 |
|
2246 | path = path ? path + '.' : '';
|
2247 | var type = source.constructor;
|
2248 | var target = source.constructor();
|
2249 | var descriptors = {};
|
2250 | descriptors.$meta = {
|
2251 | value: source.constructor()
|
2252 | };
|
2253 | descriptors.$meta.value.path = path;
|
2254 | descriptors.$meta.value.listener = listener;
|
2255 |
|
2256 | if (type === Array) {
|
2257 | for (var key = 0, length = source.length; key < length; key++) {
|
2258 | descriptors.$meta.value[key] = this.create(source[key], listener, path + key);
|
2259 | descriptors[key] = this.descriptor(key);
|
2260 | }
|
2261 | }
|
2262 |
|
2263 | if (type === Object) {
|
2264 | for (var _key3 in source) {
|
2265 | descriptors.$meta.value[_key3] = this.create(source[_key3], listener, path + _key3);
|
2266 | descriptors[_key3] = this.descriptor(_key3);
|
2267 | }
|
2268 | }
|
2269 |
|
2270 | Object.defineProperties(target, descriptors);
|
2271 | Object.defineProperties(target, this.objectProperties(source, listener, path));
|
2272 |
|
2273 | if (type === Array) {
|
2274 | Object.defineProperties(target, this.arrayProperties(source, listener, path));
|
2275 | }
|
2276 |
|
2277 | return target;
|
2278 | }
|
2279 | };
|
2280 | var Model = {
|
2281 | GET: 2,
|
2282 | SET: 3,
|
2283 | REMOVE: 4,
|
2284 | data: null,
|
2285 | tasks: [],
|
2286 | target: {},
|
2287 | setup: function setup(options) {
|
2288 | return new Promise(function ($return, $error) {
|
2289 | options = options || {};
|
2290 | this.target = options.target || this.target;
|
2291 | this.data = Observer.create(this.target, this.listener.bind(this));
|
2292 | return $return();
|
2293 | }.bind(this));
|
2294 | },
|
2295 | traverse: function traverse(type, keys, value) {
|
2296 | var result;
|
2297 |
|
2298 | if (typeof keys === 'string') {
|
2299 | keys = keys.split('.');
|
2300 | }
|
2301 |
|
2302 | var data = this.data;
|
2303 | var key = keys[keys.length - 1];
|
2304 |
|
2305 | for (var i = 0, l = keys.length - 1; i < l; i++) {
|
2306 | if (!(keys[i] in data)) {
|
2307 | if (type === this.GET || type === this.REMOVE) {
|
2308 | return undefined;
|
2309 | } else if (type === this.SET) {
|
2310 | data.$set(keys[i], isNaN(keys[i + 1]) ? {} : []);
|
2311 | }
|
2312 | }
|
2313 |
|
2314 | data = data[keys[i]];
|
2315 | }
|
2316 |
|
2317 | if (type === this.SET) {
|
2318 | result = data.$set(key, value);
|
2319 | } else if (type === this.GET) {
|
2320 | result = data[key];
|
2321 | } else if (type === this.REMOVE) {
|
2322 | result = data[key];
|
2323 | data.$remove(key);
|
2324 | }
|
2325 |
|
2326 | return result;
|
2327 | },
|
2328 | get: function get(keys) {
|
2329 | return this.traverse(this.GET, keys);
|
2330 | },
|
2331 | remove: function remove(keys) {
|
2332 | return this.traverse(this.REMOVE, keys);
|
2333 | },
|
2334 | set: function set(keys, value) {
|
2335 | return this.traverse(this.SET, keys, value);
|
2336 | },
|
2337 | listener: function listener(data, location, type) {
|
2338 | var parts = location.split('.');
|
2339 | var part = parts.slice(1).join('.');
|
2340 | var scope = parts.slice(0, 1).join('.');
|
2341 | var paths = Binder.get('location', scope);
|
2342 | if (!paths) return;
|
2343 | paths.forEach(function (binders, path) {
|
2344 | if (part === '' || path === part || type !== 'length' && path.indexOf(part + '.') === 0) {
|
2345 | binders.forEach(function (binder) {
|
2346 | Binder.render(binder);
|
2347 | });
|
2348 | }
|
2349 | });
|
2350 | }
|
2351 | };
|
2352 | var STYLE = document.createElement('style');
|
2353 | var SHEET = STYLE.sheet;
|
2354 | STYLE.setAttribute('title', 'oxe');
|
2355 | STYLE.setAttribute('type', 'text/css');
|
2356 | var Style$1 = {
|
2357 | get style() {
|
2358 | return STYLE;
|
2359 | },
|
2360 |
|
2361 | get sheet() {
|
2362 | return SHEET;
|
2363 | },
|
2364 |
|
2365 | add: function add(data) {
|
2366 | this.sheet.insertRule(data);
|
2367 | },
|
2368 | append: function append(data) {
|
2369 | this.style.appendChild(document.createTextNode(data));
|
2370 | },
|
2371 | setup: function setup() {
|
2372 | return new Promise(function ($return, $error) {
|
2373 | this.append("\n\t\t\t*[hidden] {\n\t\t\t\tdisplay: none !important;\n\t\t\t}\n\t\t\to-router, o-router > :first-child {\n\t\t\t\tdisplay: block;\n\t\t\t\tanimation: o-transition var(--o-transition) ease-in-out;\n\t\t\t}\n\t\t\t@keyframes o-transition {\n\t\t\t\t0% { opacity: 0; }\n\t\t\t\t100% { opacity: 1; }\n\t\t\t}\n\t\t");
|
2374 | document.head.appendChild(this.style);
|
2375 | return $return();
|
2376 | }.bind(this));
|
2377 | }
|
2378 | };
|
2379 | var Component = {
|
2380 | data: {},
|
2381 | compiled: false,
|
2382 | setup: function setup(options) {
|
2383 | return new Promise(function ($return, $error) {
|
2384 | var self, i, l, component, load;
|
2385 | self = this;
|
2386 | options = options || {};
|
2387 |
|
2388 | if (options.components) {
|
2389 | i = 0, l = options.components.length;
|
2390 | var $Loop_9_trampoline;
|
2391 |
|
2392 | function $Loop_9_step() {
|
2393 | i++;
|
2394 | return $Loop_9;
|
2395 | }
|
2396 |
|
2397 | function $Loop_9() {
|
2398 | if (i < l) {
|
2399 | component = options.components[i];
|
2400 |
|
2401 | if (typeof component === 'string') {
|
2402 | return Promise.resolve(Loader.load(component)).then(function ($await_50) {
|
2403 | try {
|
2404 | load = $await_50;
|
2405 | component = load.default;
|
2406 | return $If_11.call(this);
|
2407 | } catch ($boundEx) {
|
2408 | return $error($boundEx);
|
2409 | }
|
2410 | }.bind(this), $error);
|
2411 | }
|
2412 |
|
2413 | function $If_11() {
|
2414 | self.define(component);
|
2415 | return $Loop_9_step;
|
2416 | }
|
2417 |
|
2418 | return $If_11.call(this);
|
2419 | } else return [1];
|
2420 | }
|
2421 |
|
2422 | return ($Loop_9_trampoline = function (q) {
|
2423 | while (q) {
|
2424 | if (q.then) return void q.then($Loop_9_trampoline, $error);
|
2425 |
|
2426 | try {
|
2427 | if (q.pop) {
|
2428 | if (q.length) return q.pop() ? $Loop_9_exit.call(this) : q;else q = $Loop_9_step;
|
2429 | } else q = q.call(this);
|
2430 | } catch (_exception) {
|
2431 | return $error(_exception);
|
2432 | }
|
2433 | }
|
2434 | }.bind(this))($Loop_9);
|
2435 |
|
2436 | function $Loop_9_exit() {
|
2437 | return $If_8.call(this);
|
2438 | }
|
2439 | }
|
2440 |
|
2441 | function $If_8() {
|
2442 | return $return();
|
2443 | }
|
2444 |
|
2445 | return $If_8.call(this);
|
2446 | }.bind(this));
|
2447 | },
|
2448 | style: function style(_style, name) {
|
2449 | if (!window.CSS || !window.CSS.supports || !window.CSS.supports('(--t: black)')) {
|
2450 | var matches = _style.match(/--\w+(?:-+\w+)*:\s*.*?;/g) || [];
|
2451 |
|
2452 | for (var i = 0, l = matches.length; i < l; i++) {
|
2453 | var match = matches[i];
|
2454 | var rule = match.match(/(--\w+(?:-+\w+)*):\s*(.*?);/);
|
2455 | var pattern = new RegExp('var\\(' + rule[1] + '\\)', 'g');
|
2456 | _style = _style.replace(rule[0], '');
|
2457 | _style = _style.replace(pattern, rule[2]);
|
2458 | }
|
2459 | }
|
2460 |
|
2461 | if (!window.CSS || !window.CSS.supports || !window.CSS.supports(':host')) {
|
2462 | _style = _style.replace(/:host/g, name);
|
2463 | }
|
2464 |
|
2465 | return _style;
|
2466 | },
|
2467 | slot: function slot(element, fragment) {
|
2468 | var fragmentSlots = fragment.querySelectorAll('slot[name]');
|
2469 | var defaultSlot = fragment.querySelector('slot:not([name])');
|
2470 |
|
2471 | for (var i = 0, l = fragmentSlots.length; i < l; i++) {
|
2472 | var fragmentSlot = fragmentSlots[i];
|
2473 | var name = fragmentSlot.getAttribute('name');
|
2474 | var elementSlot = element.querySelector('[slot="' + name + '"]');
|
2475 |
|
2476 | if (elementSlot) {
|
2477 | fragmentSlot.parentNode.replaceChild(elementSlot, fragmentSlot);
|
2478 | } else {
|
2479 | fragmentSlot.parentNode.removeChild(fragmentSlot);
|
2480 | }
|
2481 | }
|
2482 |
|
2483 | if (defaultSlot) {
|
2484 | if (element.children.length) {
|
2485 | while (element.firstChild) {
|
2486 | defaultSlot.parentNode.insertBefore(element.firstChild, defaultSlot);
|
2487 | }
|
2488 | }
|
2489 |
|
2490 | defaultSlot.parentNode.removeChild(defaultSlot);
|
2491 | }
|
2492 | },
|
2493 | fragment: function fragment(element, options) {
|
2494 | var fragment = document.createDocumentFragment();
|
2495 | var clone = options.clone.cloneNode(true);
|
2496 |
|
2497 | while (clone.firstElementChild) {
|
2498 | if (!options.adopt) {
|
2499 | Binder.add(clone.firstElementChild, {
|
2500 | container: element,
|
2501 | scope: element.scope
|
2502 | });
|
2503 | }
|
2504 |
|
2505 | fragment.appendChild(clone.firstElementChild);
|
2506 | }
|
2507 |
|
2508 | return fragment;
|
2509 | },
|
2510 | render: function render(element, options) {
|
2511 | if (this.compiled && element.parentElement.nodeName === 'O-ROUTER') {
|
2512 | return;
|
2513 | }
|
2514 |
|
2515 | if (!options.template) {
|
2516 | return;
|
2517 | }
|
2518 |
|
2519 | var fragment;
|
2520 |
|
2521 | if (options.template) {
|
2522 | fragment = this.fragment(element, options);
|
2523 | }
|
2524 |
|
2525 | var root;
|
2526 |
|
2527 | if (options.shadow && 'attachShadow' in document.body) {
|
2528 | root = element.attachShadow({
|
2529 | mode: 'open'
|
2530 | });
|
2531 | } else if (options.shadow && 'createShadowRoot' in document.body) {
|
2532 | root = element.createShadowRoot();
|
2533 | } else {
|
2534 | if (fragment) {
|
2535 | this.slot(element, fragment);
|
2536 | }
|
2537 |
|
2538 | root = element;
|
2539 | }
|
2540 |
|
2541 | if (fragment) {
|
2542 | root.appendChild(fragment);
|
2543 | }
|
2544 |
|
2545 | if (options.adopt) {
|
2546 | var e = root.firstElementChild;
|
2547 |
|
2548 | while (e) {
|
2549 | Binder.add(e, {
|
2550 | container: element,
|
2551 | scope: element.scope
|
2552 | });
|
2553 | e = e.nextElementSibling;
|
2554 | }
|
2555 | }
|
2556 | },
|
2557 | define: function define(options) {
|
2558 | var self = this;
|
2559 |
|
2560 | if (_typeof(options) !== 'object') {
|
2561 | return console.warn('Oxe.component.define - invalid argument type');
|
2562 | }
|
2563 |
|
2564 | if (options.constructor === Array) {
|
2565 | for (var i = 0, l = options.length; i < l; i++) {
|
2566 | self.define(options[i]);
|
2567 | }
|
2568 |
|
2569 | return;
|
2570 | }
|
2571 |
|
2572 | if (!options.name) throw new Error('Oxe.component.define - requires name');
|
2573 | options.name = options.name.toLowerCase();
|
2574 | if (options.name in self.data) throw new Error('Oxe.component.define - component previously defined');
|
2575 | self.data[options.name] = options;
|
2576 | options.count = 0;
|
2577 | options.style = options.style || '';
|
2578 | options.model = options.model || {};
|
2579 | options.methods = options.methods || {};
|
2580 | options.adopt = options.adopt || false;
|
2581 | options.shadow = options.shadow || false;
|
2582 | options.template = options.template || '';
|
2583 | options.attributes = options.attributes || [];
|
2584 | options.properties = options.properties || {};
|
2585 |
|
2586 | if (options.style) {
|
2587 | var style = this.style(options.style, options.name);
|
2588 | Style$1.append(style);
|
2589 | }
|
2590 |
|
2591 | if (options.template) {
|
2592 | options.clone = document.createElement('div');
|
2593 | options.clone.innerHTML = options.template;
|
2594 | }
|
2595 |
|
2596 | var construct = function construct() {
|
2597 | var instance = window.Reflect.construct(HTMLElement, [], this.constructor);
|
2598 | var properties = Utility.clone(options.properties);
|
2599 | var methods = Utility.clone(options.methods);
|
2600 | var model = Utility.clone(options.model);
|
2601 | var scope = options.name + '-' + options.count++;
|
2602 | properties.created = {
|
2603 | value: false,
|
2604 | enumerable: true,
|
2605 | configurable: true
|
2606 | };
|
2607 | properties.scope = {
|
2608 | enumerable: true,
|
2609 | value: scope
|
2610 | };
|
2611 | properties.model = {
|
2612 | enumerable: true,
|
2613 | get: function get() {
|
2614 | return Model.get(scope);
|
2615 | },
|
2616 | set: function set(data) {
|
2617 | return Model.set(scope, data && _typeof(data) === 'object' ? data : {});
|
2618 | }
|
2619 | };
|
2620 | properties.methods = {
|
2621 | enumerable: true,
|
2622 | get: function get() {
|
2623 | return Methods.get(scope);
|
2624 | }
|
2625 | };
|
2626 | Object.defineProperties(instance, properties);
|
2627 | Methods.set(scope, methods);
|
2628 | Model.set(scope, model);
|
2629 | return instance;
|
2630 | };
|
2631 |
|
2632 | construct.observedAttributes = options.attributes;
|
2633 |
|
2634 | construct.prototype.attributeChangedCallback = function () {
|
2635 | if (options.attributed) options.attributed.apply(this, arguments);
|
2636 | };
|
2637 |
|
2638 | construct.prototype.adoptedCallback = function () {
|
2639 | if (options.adopted) options.adopted.call(this);
|
2640 | };
|
2641 |
|
2642 | construct.prototype.connectedCallback = function () {
|
2643 | if (!this.created) {
|
2644 | self.render(this, options);
|
2645 | Object.defineProperty(this, 'created', {
|
2646 | value: true,
|
2647 | enumerable: true,
|
2648 | configurable: false
|
2649 | });
|
2650 |
|
2651 | if (options.created) {
|
2652 | options.created.call(this);
|
2653 | }
|
2654 | }
|
2655 |
|
2656 | if (options.attached) {
|
2657 | options.attached.call(this);
|
2658 | }
|
2659 | };
|
2660 |
|
2661 | construct.prototype.disconnectedCallback = function () {
|
2662 | if (options.detached) {
|
2663 | options.detached.call(this);
|
2664 | }
|
2665 | };
|
2666 |
|
2667 | Object.setPrototypeOf(construct.prototype, HTMLElement.prototype);
|
2668 | Object.setPrototypeOf(construct, HTMLElement);
|
2669 | window.customElements.define(options.name, construct);
|
2670 | }
|
2671 | };
|
2672 | var Event = Object.create(Events);
|
2673 | var Router = {
|
2674 | on: Event.on.bind(Event),
|
2675 | off: Event.off.bind(Event),
|
2676 | emit: Event.emit.bind(Event),
|
2677 | data: [],
|
2678 | ran: false,
|
2679 | location: {},
|
2680 | mode: 'push',
|
2681 | target: null,
|
2682 | contain: false,
|
2683 | compiled: false,
|
2684 | folder: './routes',
|
2685 | setup: function setup(options) {
|
2686 | return new Promise(function ($return, $error) {
|
2687 | var ORouter;
|
2688 | options = options || {};
|
2689 | this.base = options.base === undefined ? this.base : options.base;
|
2690 | this.mode = options.mode === undefined ? this.mode : options.mode;
|
2691 | this.after = options.after === undefined ? this.after : options.after;
|
2692 | this.folder = options.folder === undefined ? this.folder : options.folder;
|
2693 | this.before = options.before === undefined ? this.before : options.before;
|
2694 | this.change = options.change === undefined ? this.change : options.change;
|
2695 | this.target = options.target === undefined ? this.target : options.target;
|
2696 | this.contain = options.contain === undefined ? this.contain : options.contain;
|
2697 | this.external = options.external === undefined ? this.external : options.external;
|
2698 |
|
2699 | if (!this.target || typeof this.target === 'string') {
|
2700 | this.target = document.body.querySelector(this.target || 'o-router');
|
2701 | }
|
2702 |
|
2703 | if (!this.target) return $error(new Error('Oxe.router.setup - target option required'));
|
2704 |
|
2705 | ORouter = function ORouter() {
|
2706 | return window.Reflect.construct(HTMLElement, [], this.constructor);
|
2707 | };
|
2708 |
|
2709 | Object.setPrototypeOf(ORouter.prototype, HTMLElement.prototype);
|
2710 | Object.setPrototypeOf(ORouter, HTMLElement);
|
2711 | window.customElements.define('o-router', ORouter);
|
2712 | return Promise.resolve(this.add(options.routes)).then(function ($await_51) {
|
2713 | try {
|
2714 | return Promise.resolve(this.route(window.location.href, {
|
2715 | mode: 'replace'
|
2716 | })).then(function ($await_52) {
|
2717 | try {
|
2718 | return $return();
|
2719 | } catch ($boundEx) {
|
2720 | return $error($boundEx);
|
2721 | }
|
2722 | }, $error);
|
2723 | } catch ($boundEx) {
|
2724 | return $error($boundEx);
|
2725 | }
|
2726 | }.bind(this), $error);
|
2727 | }.bind(this));
|
2728 | },
|
2729 | compareParts: function compareParts(routePath, userPath, split) {
|
2730 | var compareParts = [];
|
2731 | var routeParts = routePath.split(split);
|
2732 | var userParts = userPath.split(split);
|
2733 |
|
2734 | if (userParts.length > 1 && userParts[userParts.length - 1] === '') {
|
2735 | userParts.pop();
|
2736 | }
|
2737 |
|
2738 | if (routeParts.length > 1 && routeParts[routeParts.length - 1] === '') {
|
2739 | routeParts.pop();
|
2740 | }
|
2741 |
|
2742 | for (var i = 0, l = routeParts.length; i < l; i++) {
|
2743 | if (routeParts[i].slice(0, 1) === '(' && routeParts[i].slice(-1) === ')') {
|
2744 | if (routeParts[i] === '(~)') {
|
2745 | return true;
|
2746 | } else if (routeParts[i].indexOf('~') !== -1) {
|
2747 | if (userParts[i]) {
|
2748 | compareParts.push(userParts[i]);
|
2749 | }
|
2750 | } else {
|
2751 | compareParts.push(userParts[i]);
|
2752 | }
|
2753 | } else if (routeParts[i] !== userParts[i]) {
|
2754 | return false;
|
2755 | } else {
|
2756 | compareParts.push(routeParts[i]);
|
2757 | }
|
2758 | }
|
2759 |
|
2760 | if (compareParts.join(split) === userParts.join(split)) {
|
2761 | return true;
|
2762 | } else {
|
2763 | return false;
|
2764 | }
|
2765 | },
|
2766 | compare: function compare(routePath, userPath) {
|
2767 | var base = Path.normalize(Path.base);
|
2768 | userPath = Path.normalize(userPath);
|
2769 | routePath = Path.normalize(routePath);
|
2770 |
|
2771 | if (userPath.slice(0, base.length) !== base) {
|
2772 | userPath = Path.join(base, userPath);
|
2773 | }
|
2774 |
|
2775 | if (routePath.slice(0, base.length) !== base) {
|
2776 | routePath = Path.join(base, routePath);
|
2777 | }
|
2778 |
|
2779 | if (this.compareParts(routePath, userPath, '/')) {
|
2780 | return true;
|
2781 | }
|
2782 |
|
2783 | if (this.compareParts(routePath, userPath, '-')) {
|
2784 | return true;
|
2785 | }
|
2786 |
|
2787 | return false;
|
2788 | },
|
2789 | toParameterObject: function toParameterObject(routePath, userPath) {
|
2790 | var result = {};
|
2791 | if (!routePath || !userPath || routePath === '/' || userPath === '/') return result;
|
2792 | var userParts = userPath.split(/\/|-/);
|
2793 | var routeParts = routePath.split(/\/|-/);
|
2794 |
|
2795 | for (var i = 0, l = routeParts.length; i < l; i++) {
|
2796 | var part = routeParts[i];
|
2797 |
|
2798 | if (part.slice(0, 1) === '(' && part.slice(-1) === ')') {
|
2799 | var name = part.slice(1, part.length - 1).replace('~', '');
|
2800 | result[name] = userParts[i];
|
2801 | }
|
2802 | }
|
2803 |
|
2804 | return result;
|
2805 | },
|
2806 | toQueryString: function toQueryString(data) {
|
2807 | var result = '?';
|
2808 |
|
2809 | for (var key in data) {
|
2810 | var value = data[key];
|
2811 | result += key + '=' + value + '&';
|
2812 | }
|
2813 |
|
2814 | if (result.slice(-1) === '&') {
|
2815 | result = result.slice(0, -1);
|
2816 | }
|
2817 |
|
2818 | return result;
|
2819 | },
|
2820 | toQueryObject: function toQueryObject(path) {
|
2821 | var result = {};
|
2822 | if (path.indexOf('?') === 0) path = path.slice(1);
|
2823 | var queries = path.split('&');
|
2824 |
|
2825 | for (var i = 0, l = queries.length; i < l; i++) {
|
2826 | var query = queries[i].split('=');
|
2827 |
|
2828 | if (query[0] && query[1]) {
|
2829 | result[query[0]] = query[1];
|
2830 | }
|
2831 | }
|
2832 |
|
2833 | return result;
|
2834 | },
|
2835 | toLocationObject: function toLocationObject(href) {
|
2836 | var location = {};
|
2837 | var parser = document.createElement('a');
|
2838 | parser.href = href;
|
2839 | location.href = parser.href;
|
2840 | location.host = parser.host;
|
2841 | location.port = parser.port;
|
2842 | location.hash = parser.hash;
|
2843 | location.search = parser.search;
|
2844 | location.protocol = parser.protocol;
|
2845 | location.hostname = parser.hostname;
|
2846 | location.pathname = parser.pathname[0] === '/' ? parser.pathname : '/' + parser.pathname;
|
2847 | location.path = location.pathname + location.search + location.hash;
|
2848 | return location;
|
2849 | },
|
2850 | scroll: function scroll(x, y) {
|
2851 | window.scroll(x, y);
|
2852 | },
|
2853 | back: function back() {
|
2854 | window.history.back();
|
2855 | },
|
2856 | forward: function forward() {
|
2857 | window.history.forward();
|
2858 | },
|
2859 | redirect: function redirect(path) {
|
2860 | window.location.href = path;
|
2861 | },
|
2862 | add: function add(data) {
|
2863 | return new Promise(function ($return, $error) {
|
2864 | var path, load, i, l;
|
2865 |
|
2866 | if (!data) {
|
2867 | return $return();
|
2868 | } else {
|
2869 | if (data.constructor === String) {
|
2870 | path = data;
|
2871 |
|
2872 | if (path.slice(-3) === '.js') {
|
2873 | path = path.slice(0, -3);
|
2874 | }
|
2875 |
|
2876 | load = path;
|
2877 |
|
2878 | if (path.slice(-5) === 'index') {
|
2879 | path = path.slice(0, -5);
|
2880 | }
|
2881 |
|
2882 | if (path.slice(-6) === 'index/') {
|
2883 | path = path.slice(0, -6);
|
2884 | }
|
2885 |
|
2886 | if (path.slice(0, 2) === './') {
|
2887 | path = path.slice(2);
|
2888 | }
|
2889 |
|
2890 | if (path.slice(0, 1) !== '/') {
|
2891 | path = '/' + path;
|
2892 | }
|
2893 |
|
2894 | load = load + '.js';
|
2895 | load = Path.join(this.folder, load);
|
2896 | this.data.push({
|
2897 | path: path,
|
2898 | load: load
|
2899 | });
|
2900 | return $If_13.call(this);
|
2901 | } else {
|
2902 | if (data.constructor === Object) {
|
2903 | if (!data.path) {
|
2904 | return $error(new Error('Oxe.router.add - route path required'));
|
2905 | }
|
2906 |
|
2907 | if (!data.load && !data.component) {
|
2908 | return $error(new Error('Oxe.router.add - route.component or route.load required'));
|
2909 | }
|
2910 |
|
2911 | this.data.push(data);
|
2912 | return $If_14.call(this);
|
2913 | } else {
|
2914 | if (data.constructor === Array) {
|
2915 | i = 0, l = data.length;
|
2916 | var $Loop_16_trampoline;
|
2917 |
|
2918 | function $Loop_16_step() {
|
2919 | i++;
|
2920 | return $Loop_16;
|
2921 | }
|
2922 |
|
2923 | function $Loop_16() {
|
2924 | if (i < l) {
|
2925 | return Promise.resolve(this.add(data[i])).then(function ($await_53) {
|
2926 | try {
|
2927 | return $Loop_16_step;
|
2928 | } catch ($boundEx) {
|
2929 | return $error($boundEx);
|
2930 | }
|
2931 | }, $error);
|
2932 | } else return [1];
|
2933 | }
|
2934 |
|
2935 | return ($Loop_16_trampoline = function (q) {
|
2936 | while (q) {
|
2937 | if (q.then) return void q.then($Loop_16_trampoline, $error);
|
2938 |
|
2939 | try {
|
2940 | if (q.pop) {
|
2941 | if (q.length) return q.pop() ? $Loop_16_exit.call(this) : q;else q = $Loop_16_step;
|
2942 | } else q = q.call(this);
|
2943 | } catch (_exception) {
|
2944 | return $error(_exception);
|
2945 | }
|
2946 | }
|
2947 | }.bind(this))($Loop_16);
|
2948 |
|
2949 | function $Loop_16_exit() {
|
2950 | return $If_15.call(this);
|
2951 | }
|
2952 | }
|
2953 |
|
2954 | function $If_15() {
|
2955 | return $If_14.call(this);
|
2956 | }
|
2957 |
|
2958 | return $If_15.call(this);
|
2959 | }
|
2960 |
|
2961 | function $If_14() {
|
2962 | return $If_13.call(this);
|
2963 | }
|
2964 | }
|
2965 |
|
2966 | function $If_13() {
|
2967 | return $If_12.call(this);
|
2968 | }
|
2969 | }
|
2970 |
|
2971 | function $If_12() {
|
2972 | return $return();
|
2973 | }
|
2974 |
|
2975 | return $If_12.call(this);
|
2976 | }.bind(this));
|
2977 | },
|
2978 | load: function load(route) {
|
2979 | return new Promise(function ($return, $error) {
|
2980 | var load, _load;
|
2981 |
|
2982 | if (route.load) {
|
2983 | return Promise.resolve(Loader.load(route.load)).then(function ($await_54) {
|
2984 | try {
|
2985 | load = $await_54;
|
2986 | route = Object.assign({}, load.default, route);
|
2987 | return $If_18.call(this);
|
2988 | } catch ($boundEx) {
|
2989 | return $error($boundEx);
|
2990 | }
|
2991 | }.bind(this), $error);
|
2992 | }
|
2993 |
|
2994 | function $If_18() {
|
2995 | if (typeof route.component === 'string') {
|
2996 | route.load = route.component;
|
2997 | return Promise.resolve(Loader.load(route.load)).then(function ($await_55) {
|
2998 | try {
|
2999 | _load = $await_55;
|
3000 | route.component = _load.default;
|
3001 | return $If_19.call(this);
|
3002 | } catch ($boundEx) {
|
3003 | return $error($boundEx);
|
3004 | }
|
3005 | }.bind(this), $error);
|
3006 | }
|
3007 |
|
3008 | function $If_19() {
|
3009 | return $return(route);
|
3010 | }
|
3011 |
|
3012 | return $If_19.call(this);
|
3013 | }
|
3014 |
|
3015 | return $If_18.call(this);
|
3016 | });
|
3017 | },
|
3018 | remove: function remove(path) {
|
3019 | return new Promise(function ($return, $error) {
|
3020 | for (var i = 0, l = this.data.length; i < l; i++) {
|
3021 | if (this.data[i].path === path) {
|
3022 | this.data.splice(i, 1);
|
3023 | }
|
3024 | }
|
3025 |
|
3026 | return $return();
|
3027 | }.bind(this));
|
3028 | },
|
3029 | get: function get(path) {
|
3030 | return new Promise(function ($return, $error) {
|
3031 | var i, l;
|
3032 | i = 0, l = this.data.length;
|
3033 | var $Loop_20_trampoline;
|
3034 |
|
3035 | function $Loop_20_step() {
|
3036 | i++;
|
3037 | return $Loop_20;
|
3038 | }
|
3039 |
|
3040 | function $Loop_20() {
|
3041 | if (i < l) {
|
3042 | if (this.data[i].path === path) {
|
3043 | return Promise.resolve(this.load(this.data[i])).then(function ($await_56) {
|
3044 | try {
|
3045 | this.data[i] = $await_56;
|
3046 | return $return(this.data[i]);
|
3047 | } catch ($boundEx) {
|
3048 | return $error($boundEx);
|
3049 | }
|
3050 | }.bind(this), $error);
|
3051 | }
|
3052 |
|
3053 | return $Loop_20_step;
|
3054 | } else return [1];
|
3055 | }
|
3056 |
|
3057 | return ($Loop_20_trampoline = function (q) {
|
3058 | while (q) {
|
3059 | if (q.then) return void q.then($Loop_20_trampoline, $error);
|
3060 |
|
3061 | try {
|
3062 | if (q.pop) {
|
3063 | if (q.length) return q.pop() ? $Loop_20_exit.call(this) : q;else q = $Loop_20_step;
|
3064 | } else q = q.call(this);
|
3065 | } catch (_exception) {
|
3066 | return $error(_exception);
|
3067 | }
|
3068 | }
|
3069 | }.bind(this))($Loop_20);
|
3070 |
|
3071 | function $Loop_20_exit() {
|
3072 | return $return();
|
3073 | }
|
3074 | }.bind(this));
|
3075 | },
|
3076 | filter: function filter(path) {
|
3077 | return new Promise(function ($return, $error) {
|
3078 | var result, i, l;
|
3079 | result = [];
|
3080 | i = 0, l = this.data.length;
|
3081 | var $Loop_23_trampoline;
|
3082 |
|
3083 | function $Loop_23_step() {
|
3084 | i++;
|
3085 | return $Loop_23;
|
3086 | }
|
3087 |
|
3088 | function $Loop_23() {
|
3089 | if (i < l) {
|
3090 | if (this.compare(this.data[i].path, path)) {
|
3091 | return Promise.resolve(this.load(this.data[i])).then(function ($await_57) {
|
3092 | try {
|
3093 | this.data[i] = $await_57;
|
3094 | result.push(this.data[i]);
|
3095 | return $If_25.call(this);
|
3096 | } catch ($boundEx) {
|
3097 | return $error($boundEx);
|
3098 | }
|
3099 | }.bind(this), $error);
|
3100 | }
|
3101 |
|
3102 | function $If_25() {
|
3103 | return $Loop_23_step;
|
3104 | }
|
3105 |
|
3106 | return $If_25.call(this);
|
3107 | } else return [1];
|
3108 | }
|
3109 |
|
3110 | return ($Loop_23_trampoline = function (q) {
|
3111 | while (q) {
|
3112 | if (q.then) return void q.then($Loop_23_trampoline, $error);
|
3113 |
|
3114 | try {
|
3115 | if (q.pop) {
|
3116 | if (q.length) return q.pop() ? $Loop_23_exit.call(this) : q;else q = $Loop_23_step;
|
3117 | } else q = q.call(this);
|
3118 | } catch (_exception) {
|
3119 | return $error(_exception);
|
3120 | }
|
3121 | }
|
3122 | }.bind(this))($Loop_23);
|
3123 |
|
3124 | function $Loop_23_exit() {
|
3125 | return $return(result);
|
3126 | }
|
3127 | }.bind(this));
|
3128 | },
|
3129 | find: function find(path) {
|
3130 | return new Promise(function ($return, $error) {
|
3131 | var i, l;
|
3132 | i = 0, l = this.data.length;
|
3133 | var $Loop_26_trampoline;
|
3134 |
|
3135 | function $Loop_26_step() {
|
3136 | i++;
|
3137 | return $Loop_26;
|
3138 | }
|
3139 |
|
3140 | function $Loop_26() {
|
3141 | if (i < l) {
|
3142 | if (this.compare(this.data[i].path, path)) {
|
3143 | return Promise.resolve(this.load(this.data[i])).then(function ($await_58) {
|
3144 | try {
|
3145 | this.data[i] = $await_58;
|
3146 | return $return(this.data[i]);
|
3147 | } catch ($boundEx) {
|
3148 | return $error($boundEx);
|
3149 | }
|
3150 | }.bind(this), $error);
|
3151 | }
|
3152 |
|
3153 | return $Loop_26_step;
|
3154 | } else return [1];
|
3155 | }
|
3156 |
|
3157 | return ($Loop_26_trampoline = function (q) {
|
3158 | while (q) {
|
3159 | if (q.then) return void q.then($Loop_26_trampoline, $error);
|
3160 |
|
3161 | try {
|
3162 | if (q.pop) {
|
3163 | if (q.length) return q.pop() ? $Loop_26_exit.call(this) : q;else q = $Loop_26_step;
|
3164 | } else q = q.call(this);
|
3165 | } catch (_exception) {
|
3166 | return $error(_exception);
|
3167 | }
|
3168 | }
|
3169 | }.bind(this))($Loop_26);
|
3170 |
|
3171 | function $Loop_26_exit() {
|
3172 | return $return();
|
3173 | }
|
3174 | }.bind(this));
|
3175 | },
|
3176 | render: function render(route) {
|
3177 | return new Promise(function ($return, $error) {
|
3178 | if (!route) {
|
3179 | return $error(new Error('Oxe.render - route argument required. Missing object option.'));
|
3180 | }
|
3181 |
|
3182 | if (!route.component && !route.target) {
|
3183 | return $error(new Error('Oxe.render - route property required. Missing component or target option.'));
|
3184 | }
|
3185 |
|
3186 | if (route.title) {
|
3187 | document.title = route.title;
|
3188 | }
|
3189 |
|
3190 | if (route.description) {
|
3191 | Utility.ensureElement({
|
3192 | name: 'meta',
|
3193 | scope: document.head,
|
3194 | position: 'afterbegin',
|
3195 | query: '[name="description"]',
|
3196 | attributes: [{
|
3197 | name: 'name',
|
3198 | value: 'description'
|
3199 | }, {
|
3200 | name: 'content',
|
3201 | value: route.description
|
3202 | }]
|
3203 | });
|
3204 | }
|
3205 |
|
3206 | if (route.keywords) {
|
3207 | Utility.ensureElement({
|
3208 | name: 'meta',
|
3209 | scope: document.head,
|
3210 | position: 'afterbegin',
|
3211 | query: '[name="keywords"]',
|
3212 | attributes: [{
|
3213 | name: 'name',
|
3214 | value: 'keywords'
|
3215 | }, {
|
3216 | name: 'content',
|
3217 | value: route.keywords
|
3218 | }]
|
3219 | });
|
3220 | }
|
3221 |
|
3222 | if (!route.target) {
|
3223 | if (route.component.constructor === String) {
|
3224 | route.target = window.document.createElement(route.component);
|
3225 | } else if (route.component.constructor === Object) {
|
3226 | Component.define(route.component);
|
3227 |
|
3228 | if (this.compiled) {
|
3229 | route.target = this.target.firstElementChild;
|
3230 | this.scroll(0, 0);
|
3231 | return $return();
|
3232 | } else {
|
3233 | route.target = window.document.createElement(route.component.name);
|
3234 | }
|
3235 | }
|
3236 | }
|
3237 |
|
3238 | while (this.target.firstChild) {
|
3239 | this.target.removeChild(this.target.firstChild);
|
3240 | }
|
3241 |
|
3242 | this.target.appendChild(route.target);
|
3243 | this.scroll(0, 0);
|
3244 | return $return();
|
3245 | }.bind(this));
|
3246 | },
|
3247 | route: function route(path, options) {
|
3248 | return new Promise(function ($return, $error) {
|
3249 | var mode, location, route;
|
3250 | options = options || {};
|
3251 |
|
3252 | if (options.query) {
|
3253 | path += this.toQueryString(options.query);
|
3254 | }
|
3255 |
|
3256 | mode = options.mode || this.mode;
|
3257 | location = this.toLocationObject(path);
|
3258 | return Promise.resolve(this.find(location.pathname)).then(function ($await_59) {
|
3259 | try {
|
3260 | route = $await_59;
|
3261 |
|
3262 | if (!route) {
|
3263 | return $error(new Error("Oxe.router.route - missing route ".concat(location.pathname)));
|
3264 | }
|
3265 |
|
3266 | location.route = route;
|
3267 | location.title = location.route.title;
|
3268 | location.query = this.toQueryObject(location.search);
|
3269 | location.parameters = this.toParameterObject(location.route.path, location.pathname);
|
3270 |
|
3271 | if (location.route && location.route.handler) {
|
3272 | return Promise.resolve(location.route.handler(location)).then($return, $error);
|
3273 | }
|
3274 |
|
3275 | if (location.route && location.route.redirect) {
|
3276 | return Promise.resolve(this.redirect(location.route.redirect)).then($return, $error);
|
3277 | }
|
3278 |
|
3279 | function $If_30() {
|
3280 | if (typeof this.before === 'function') {
|
3281 | return Promise.resolve(this.before(location)).then(function ($await_62) {
|
3282 | try {
|
3283 | return $If_31.call(this);
|
3284 | } catch ($boundEx) {
|
3285 | return $error($boundEx);
|
3286 | }
|
3287 | }.bind(this), $error);
|
3288 | }
|
3289 |
|
3290 | function $If_31() {
|
3291 | this.emit('route:before', location);
|
3292 |
|
3293 | if (mode === 'href' || this.compiled) {
|
3294 | return $return(window.location.assign(location.path));
|
3295 | }
|
3296 |
|
3297 | window.history[mode + 'State']({
|
3298 | path: location.path
|
3299 | }, '', location.path);
|
3300 | this.location = location;
|
3301 | return Promise.resolve(this.render(location.route)).then(function ($await_63) {
|
3302 | try {
|
3303 | if (typeof this.after === 'function') {
|
3304 | return Promise.resolve(this.after(location)).then(function ($await_64) {
|
3305 | try {
|
3306 | return $If_32.call(this);
|
3307 | } catch ($boundEx) {
|
3308 | return $error($boundEx);
|
3309 | }
|
3310 | }.bind(this), $error);
|
3311 | }
|
3312 |
|
3313 | function $If_32() {
|
3314 | this.emit('route:after', location);
|
3315 | return $return();
|
3316 | }
|
3317 |
|
3318 | return $If_32.call(this);
|
3319 | } catch ($boundEx) {
|
3320 | return $error($boundEx);
|
3321 | }
|
3322 | }.bind(this), $error);
|
3323 | }
|
3324 |
|
3325 | return $If_31.call(this);
|
3326 | }
|
3327 |
|
3328 | if (typeof this.before === 'function') {
|
3329 | return Promise.resolve(this.before(location)).then(function ($await_62) {
|
3330 | try {
|
3331 | return $If_31.call(this);
|
3332 | } catch ($boundEx) {
|
3333 | return $error($boundEx);
|
3334 | }
|
3335 | }.bind(this), $error);
|
3336 | }
|
3337 |
|
3338 | function $If_31() {
|
3339 | this.emit('route:before', location);
|
3340 |
|
3341 | if (mode === 'href' || this.compiled) {
|
3342 | return $return(window.location.assign(location.path));
|
3343 | }
|
3344 |
|
3345 | window.history[mode + 'State']({
|
3346 | path: location.path
|
3347 | }, '', location.path);
|
3348 | this.location = location;
|
3349 | return Promise.resolve(this.render(location.route)).then(function ($await_63) {
|
3350 | try {
|
3351 | if (typeof this.after === 'function') {
|
3352 | return Promise.resolve(this.after(location)).then(function ($await_64) {
|
3353 | try {
|
3354 | return $If_32.call(this);
|
3355 | } catch ($boundEx) {
|
3356 | return $error($boundEx);
|
3357 | }
|
3358 | }.bind(this), $error);
|
3359 | }
|
3360 |
|
3361 | function $If_32() {
|
3362 | this.emit('route:after', location);
|
3363 | return $return();
|
3364 | }
|
3365 |
|
3366 | return $If_32.call(this);
|
3367 | } catch ($boundEx) {
|
3368 | return $error($boundEx);
|
3369 | }
|
3370 | }.bind(this), $error);
|
3371 | }
|
3372 |
|
3373 | return $If_31.call(this);
|
3374 | } catch ($boundEx) {
|
3375 | return $error($boundEx);
|
3376 | }
|
3377 | }.bind(this), $error);
|
3378 | }.bind(this));
|
3379 | }
|
3380 | };
|
3381 |
|
3382 | function Click(event) {
|
3383 | return new Promise(function ($return, $error) {
|
3384 | if (event.target.type || event.button !== 0 || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
|
3385 | return $return();
|
3386 | }
|
3387 |
|
3388 | var target = event.path ? event.path[0] : event.target;
|
3389 | var parent = target.parentElement;
|
3390 |
|
3391 | if (Router.contain) {
|
3392 | while (parent) {
|
3393 | if (parent.nodeName === 'O-ROUTER') {
|
3394 | break;
|
3395 | } else {
|
3396 | parent = parent.parentElement;
|
3397 | }
|
3398 | }
|
3399 |
|
3400 | if (parent.nodeName !== 'O-ROUTER') {
|
3401 | return $return();
|
3402 | }
|
3403 | }
|
3404 |
|
3405 | while (target && 'A' !== target.nodeName) {
|
3406 | target = target.parentElement;
|
3407 | }
|
3408 |
|
3409 | if (!target || 'A' !== target.nodeName) {
|
3410 | return $return();
|
3411 | }
|
3412 |
|
3413 | if (target.hasAttribute('download') || target.hasAttribute('external') || target.hasAttribute('o-external') || target.href.indexOf('tel:') === 0 || target.href.indexOf('ftp:') === 0 || target.href.indexOf('file:') === 0 || target.href.indexOf('mailto:') === 0 || target.href.indexOf(window.location.origin) !== 0 || target.hash !== '' && target.origin === window.location.origin && target.pathname === window.location.pathname) return $return();
|
3414 | if (Router.external && (Router.external.constructor === RegExp && Router.external.test(target.href) || Router.external.constructor === Function && Router.external(target.href) || Router.external.constructor === String && Router.external === target.href)) return $return();
|
3415 | event.preventDefault();
|
3416 |
|
3417 | if (Router.location.href !== target.href) {
|
3418 | Router.route(target.href);
|
3419 | }
|
3420 |
|
3421 | return $return();
|
3422 | });
|
3423 | }
|
3424 |
|
3425 | function State(event) {
|
3426 | return new Promise(function ($return, $error) {
|
3427 | var path = event && event.state ? event.state.path : window.location.href;
|
3428 | Router.route(path, {
|
3429 | mode: 'replace'
|
3430 | });
|
3431 | return $return();
|
3432 | });
|
3433 | }
|
3434 |
|
3435 | function Listener(option, method, event) {
|
3436 | var type = event.type;
|
3437 | var before;
|
3438 | var after;
|
3439 |
|
3440 | if (type in option.listener) {
|
3441 | before = typeof option.listener[type].before === 'function' ? option.listener[type].before.bind(null, event) : null;
|
3442 | after = typeof option.listener[type].after === 'function' ? option.listener[type].after.bind(null, event) : null;
|
3443 | }
|
3444 |
|
3445 | Promise.resolve().then(before).then(method.bind(null, event)).then(after);
|
3446 | }
|
3447 |
|
3448 | if (window.Reflect === undefined) {
|
3449 | window.Reflect = window.Reflect || {};
|
3450 |
|
3451 | window.Reflect.construct = function (parent, args, child) {
|
3452 | var target = child === undefined ? parent : child;
|
3453 | var prototype = target.prototype || Object.prototype;
|
3454 | var copy = Object.create(prototype);
|
3455 | return Function.prototype.apply.call(parent, copy, args) || copy;
|
3456 | };
|
3457 | }
|
3458 |
|
3459 | var oSetup = document.querySelector('script[o-setup]');
|
3460 |
|
3461 | if (oSetup) {
|
3462 | var options = oSetup.getAttribute('o-setup').split(/\s+|\s*,+\s*/);
|
3463 | var meta = document.querySelector('meta[name="oxe"]');
|
3464 |
|
3465 | if (meta && meta.getAttribute('content') === 'compiled') {
|
3466 | Router.compiled = true;
|
3467 | Component.compiled = true;
|
3468 | }
|
3469 |
|
3470 | if (!options[0]) {
|
3471 | throw new Error('Oxe - script attribute o-setup requires path');
|
3472 | }
|
3473 |
|
3474 | Loader.type = options[1] || 'esm';
|
3475 | Promise.resolve(Loader.load(options[0]));
|
3476 | }
|
3477 |
|
3478 | var SETUP = false;
|
3479 | var GLOBAL = {};
|
3480 | var index = {
|
3481 | get global() {
|
3482 | return GLOBAL;
|
3483 | },
|
3484 |
|
3485 | get window() {
|
3486 | return window;
|
3487 | },
|
3488 |
|
3489 | get document() {
|
3490 | return window.document;
|
3491 | },
|
3492 |
|
3493 | get body() {
|
3494 | return window.document.body;
|
3495 | },
|
3496 |
|
3497 | get head() {
|
3498 | return window.document.head;
|
3499 | },
|
3500 |
|
3501 | get location() {
|
3502 | return this.router.location;
|
3503 | },
|
3504 |
|
3505 | get currentScript() {
|
3506 | return window.document._currentScript || window.document.currentScript;
|
3507 | },
|
3508 |
|
3509 | get ownerDocument() {
|
3510 | return (window.document._currentScript || window.document.currentScript).ownerDocument;
|
3511 | },
|
3512 |
|
3513 | get component() {
|
3514 | return Component;
|
3515 | },
|
3516 |
|
3517 | get batcher() {
|
3518 | return Batcher;
|
3519 | },
|
3520 |
|
3521 | get fetcher() {
|
3522 | return Fetcher;
|
3523 | },
|
3524 |
|
3525 | get methods() {
|
3526 | return Methods;
|
3527 | },
|
3528 |
|
3529 | get utility() {
|
3530 | return Utility;
|
3531 | },
|
3532 |
|
3533 | get binder() {
|
3534 | return Binder;
|
3535 | },
|
3536 |
|
3537 | get loader() {
|
3538 | return Loader;
|
3539 | },
|
3540 |
|
3541 | get router() {
|
3542 | return Router;
|
3543 | },
|
3544 |
|
3545 | get model() {
|
3546 | return Model;
|
3547 | },
|
3548 |
|
3549 | get style() {
|
3550 | return Style$1;
|
3551 | },
|
3552 |
|
3553 | get path() {
|
3554 | return Path;
|
3555 | },
|
3556 |
|
3557 | setup: function setup(options) {
|
3558 | return new Promise(function ($return, $error) {
|
3559 | if (SETUP) return $return();else SETUP = true;
|
3560 | options = options || {};
|
3561 | options.listener = options.listener || {};
|
3562 | return Promise.resolve(this.style.setup(options.style)).then(function ($await_65) {
|
3563 | try {
|
3564 | return Promise.resolve(this.model.setup(options.model)).then(function ($await_66) {
|
3565 | try {
|
3566 | return Promise.resolve(this.binder.setup(options.binder)).then(function ($await_67) {
|
3567 | try {
|
3568 | document.addEventListener('click', Listener.bind(null, options, Click), true);
|
3569 | document.addEventListener('input', Listener.bind(null, options, Input), true);
|
3570 | document.addEventListener('reset', Listener.bind(null, options, Reset), true);
|
3571 | document.addEventListener('change', Listener.bind(null, options, Change), true);
|
3572 | document.addEventListener('submit', Listener.bind(null, options, Submit), true);
|
3573 | window.addEventListener('popstate', Listener.bind(null, options, State), true);
|
3574 |
|
3575 | if (options.listener.before) {
|
3576 | return Promise.resolve(options.listener.before()).then(function ($await_68) {
|
3577 | try {
|
3578 | return $If_33.call(this);
|
3579 | } catch ($boundEx) {
|
3580 | return $error($boundEx);
|
3581 | }
|
3582 | }.bind(this), $error);
|
3583 | }
|
3584 |
|
3585 | function $If_33() {
|
3586 | if (options.path) {
|
3587 | return Promise.resolve(this.path.setup(options.path)).then(function ($await_69) {
|
3588 | try {
|
3589 | return $If_34.call(this);
|
3590 | } catch ($boundEx) {
|
3591 | return $error($boundEx);
|
3592 | }
|
3593 | }.bind(this), $error);
|
3594 | }
|
3595 |
|
3596 | function $If_34() {
|
3597 | if (options.fetcher) {
|
3598 | return Promise.resolve(this.fetcher.setup(options.fetcher)).then(function ($await_70) {
|
3599 | try {
|
3600 | return $If_35.call(this);
|
3601 | } catch ($boundEx) {
|
3602 | return $error($boundEx);
|
3603 | }
|
3604 | }.bind(this), $error);
|
3605 | }
|
3606 |
|
3607 | function $If_35() {
|
3608 | if (options.loader) {
|
3609 | return Promise.resolve(this.loader.setup(options.loader)).then(function ($await_71) {
|
3610 | try {
|
3611 | return $If_36.call(this);
|
3612 | } catch ($boundEx) {
|
3613 | return $error($boundEx);
|
3614 | }
|
3615 | }.bind(this), $error);
|
3616 | }
|
3617 |
|
3618 | function $If_36() {
|
3619 | if (options.component) {
|
3620 | return Promise.resolve(this.component.setup(options.component)).then(function ($await_72) {
|
3621 | try {
|
3622 | return $If_37.call(this);
|
3623 | } catch ($boundEx) {
|
3624 | return $error($boundEx);
|
3625 | }
|
3626 | }.bind(this), $error);
|
3627 | }
|
3628 |
|
3629 | function $If_37() {
|
3630 | if (options.router) {
|
3631 | return Promise.resolve(this.router.setup(options.router)).then(function ($await_73) {
|
3632 | try {
|
3633 | return $If_38.call(this);
|
3634 | } catch ($boundEx) {
|
3635 | return $error($boundEx);
|
3636 | }
|
3637 | }.bind(this), $error);
|
3638 | }
|
3639 |
|
3640 | function $If_38() {
|
3641 | if (options.listener.after) {
|
3642 | return Promise.resolve(options.listener.after()).then(function ($await_74) {
|
3643 | try {
|
3644 | return $If_39.call(this);
|
3645 | } catch ($boundEx) {
|
3646 | return $error($boundEx);
|
3647 | }
|
3648 | }.bind(this), $error);
|
3649 | }
|
3650 |
|
3651 | function $If_39() {
|
3652 | return $return();
|
3653 | }
|
3654 |
|
3655 | return $If_39.call(this);
|
3656 | }
|
3657 |
|
3658 | return $If_38.call(this);
|
3659 | }
|
3660 |
|
3661 | return $If_37.call(this);
|
3662 | }
|
3663 |
|
3664 | return $If_36.call(this);
|
3665 | }
|
3666 |
|
3667 | return $If_35.call(this);
|
3668 | }
|
3669 |
|
3670 | return $If_34.call(this);
|
3671 | }
|
3672 |
|
3673 | return $If_33.call(this);
|
3674 | } catch ($boundEx) {
|
3675 | return $error($boundEx);
|
3676 | }
|
3677 | }.bind(this), $error);
|
3678 | } catch ($boundEx) {
|
3679 | return $error($boundEx);
|
3680 | }
|
3681 | }.bind(this), $error);
|
3682 | } catch ($boundEx) {
|
3683 | return $error($boundEx);
|
3684 | }
|
3685 | }.bind(this), $error);
|
3686 | }.bind(this));
|
3687 | }
|
3688 | };
|
3689 | return index;
|
3690 | }); |
\ | No newline at end of file |