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