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