bigpipe-util 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,53 +1,53 @@
1
- const _events = {};
2
-
3
- export default class Arbiter {
4
- constructor() {
5
- this._events = _events;
6
- }
7
-
8
- inform(what, ...args) {
9
- const list = [...this.getSubscribers(what)];
10
- for (let i = 0; i < list.length; i++) {
11
- if (list[i] === null) {
12
- continue;
13
- }
14
-
15
- try {
16
- list[i].apply(this, args);
17
- } catch (e) {
18
- window.setTimeout(() => {
19
- throw e;
20
- }, 0);
21
- }
22
- }
23
- return this;
24
- }
25
-
26
- getSubscribers(toWhat) {
27
- return this._events[toWhat] || (this._events[toWhat] = []);
28
- }
29
-
30
- clearSubscribers(toWhat) {
31
- if (toWhat) {
32
- this._events[toWhat] = [];
33
- }
34
- return this;
35
- }
36
-
37
- subscribe(toWhat, withWhat) {
38
- const list = this.getSubscribers(toWhat);
39
- list.push(withWhat);
40
- return this;
41
- }
42
-
43
- unsubscribe(toWhat, withWhat) {
44
- const list = this.getSubscribers(toWhat);
45
- for (let i = 0; i < list.length; i++) {
46
- if (list[i] === withWhat) {
47
- list.splice(i, 1);
48
- break;
49
- }
50
- }
51
- return this;
52
- }
53
- }
1
+ const _events = {};
2
+
3
+ export default class Arbiter {
4
+ constructor() {
5
+ this._events = _events;
6
+ }
7
+
8
+ inform(what, ...args) {
9
+ const list = [...this.getSubscribers(what)];
10
+ for (let i = 0; i < list.length; i++) {
11
+ if (list[i] === null) {
12
+ continue;
13
+ }
14
+
15
+ try {
16
+ list[i].apply(this, args);
17
+ } catch (e) {
18
+ window.setTimeout(() => {
19
+ throw e;
20
+ }, 0);
21
+ }
22
+ }
23
+ return this;
24
+ }
25
+
26
+ getSubscribers(toWhat) {
27
+ return this._events[toWhat] || (this._events[toWhat] = []);
28
+ }
29
+
30
+ clearSubscribers(toWhat) {
31
+ if (toWhat) {
32
+ this._events[toWhat] = [];
33
+ }
34
+ return this;
35
+ }
36
+
37
+ subscribe(toWhat, withWhat) {
38
+ const list = this.getSubscribers(toWhat);
39
+ list.push(withWhat);
40
+ return this;
41
+ }
42
+
43
+ unsubscribe(toWhat, withWhat) {
44
+ const list = this.getSubscribers(toWhat);
45
+ for (let i = 0; i < list.length; i++) {
46
+ if (list[i] === withWhat) {
47
+ list.splice(i, 1);
48
+ break;
49
+ }
50
+ }
51
+ return this;
52
+ }
53
+ }
package/src/core/DOM.js CHANGED
@@ -1,41 +1,41 @@
1
- function removeNode(node) {
2
- if (node.parentNode) {
3
- node.parentNode.removeChild(node);
4
- }
5
- }
6
-
7
- export default {
8
- prependContent(node, content) {
9
- node.insertAdjacentHTML("afterbegin", content);
10
- },
11
-
12
- insertAfter(node, content) {
13
- node.insertAdjacentHTML("afterend", content);
14
- },
15
-
16
- insertBefore(node, content) {
17
- node.insertAdjacentHTML("beforebegin", content);
18
- },
19
-
20
- setContent(node, content) {
21
- node.innerHTML = content;
22
- },
23
-
24
- appendContent(node, content) {
25
- node.insertAdjacentHTML("beforeend", content);
26
- },
27
-
28
- replace(node, content) {
29
- node.outerHTML = content;
30
- },
31
-
32
- remove(node) {
33
- removeNode(node);
34
- },
35
-
36
- empty(node) {
37
- while (node.firstChild) {
38
- removeNode(node.firstChild);
39
- }
40
- }
41
- }
1
+ function removeNode(node) {
2
+ if (node.parentNode) {
3
+ node.parentNode.removeChild(node);
4
+ }
5
+ }
6
+
7
+ export default {
8
+ prependContent(node, content) {
9
+ node.insertAdjacentHTML("afterbegin", content);
10
+ },
11
+
12
+ insertAfter(node, content) {
13
+ node.insertAdjacentHTML("afterend", content);
14
+ },
15
+
16
+ insertBefore(node, content) {
17
+ node.insertAdjacentHTML("beforebegin", content);
18
+ },
19
+
20
+ setContent(node, content) {
21
+ node.innerHTML = content;
22
+ },
23
+
24
+ appendContent(node, content) {
25
+ node.insertAdjacentHTML("beforeend", content);
26
+ },
27
+
28
+ replace(node, content) {
29
+ node.outerHTML = content;
30
+ },
31
+
32
+ remove(node) {
33
+ removeNode(node);
34
+ },
35
+
36
+ empty(node) {
37
+ while (node.firstChild) {
38
+ removeNode(node.firstChild);
39
+ }
40
+ }
41
+ }
@@ -1,129 +1,143 @@
1
- import Modal from "modal-vanilla/lib/modal";
2
- import DOM from "./DOM";
3
-
4
- const DEFAULT_Z_INDEX = 1040;
5
-
6
- let stack = [];
7
- let dialogId = 1;
8
- let zIndex;
9
- let originalBodyPad = null;
10
-
11
- Modal.prototype._handleKeydownEvent = function(event) {
12
- if (event.which === 27 && this._options.keyboard) {
13
- const currentModal = stack[stack.length - 1];
14
- if (currentModal.el.isEqualNode(this.el)) {
15
- this.emit('dismiss', this, event, null);
16
- this.hide();
17
- }
18
- }
19
- }
20
-
21
- export default class Dialog {
22
- close() {
23
- stack.forEach((dialog) => dialog.hide())
24
- }
25
-
26
- closeCurrent() {
27
- const dialog = stack[stack.length - 1];
28
-
29
- if (dialog) {
30
- dialog.hide();
31
- }
32
- }
33
-
34
- render(options, args) {
35
- DOM.appendContent(document.body, this._makeDialog(options.content));
36
-
37
- dialogId++;
38
-
39
- const dialog = this._show({
40
- el: document.getElementById(this.id),
41
- animate: false,
42
- keyboard: options.keyboard !== null && options.keyboard !== undefined ? options.keyboard : true,
43
- backdrop: options.backdrop !== null && options.backdrop !== undefined ? options.backdrop : true,
44
- transition: options.transition !== null && options.transition !== undefined ? options.transition : 0,
45
- backdropTransition: options.backdropTransition !== null && options.backdropTransition !== undefined ? options.backdropTransition : 0,
46
- }, options.controller, args);
47
-
48
- stack.push(dialog);
49
-
50
- return dialog;
51
- }
52
-
53
- showFromModel(model, args) {
54
- const dialog = this._show({
55
- title: model.title || '',
56
- content: model.body,
57
- footer: model.footer || false,
58
- animate: false,
59
- keyboard: model.keyboard !== null && model.keyboard !== undefined ? model.keyboard : true,
60
- backdrop: model.backdrop !== null && model.backdrop !== undefined ? model.backdrop : true,
61
- transition: model.transition !== null && model.transition !== undefined ? model.transition : 0,
62
- backdropTransition: model.backdropTransition !== null && model.backdropTransition !== undefined ? model.backdropTransition : 0,
63
- }, model.controller, args);
64
-
65
- stack.push(dialog);
66
-
67
- return dialog;
68
- }
69
-
70
- _show(options, controller, args) {
71
- if (originalBodyPad === null) {
72
- originalBodyPad = document.body.style.paddingRight;
73
- }
74
-
75
- const _modal = new Modal(options);
76
-
77
- if (controller) {
78
- if (typeof controller === 'string') {
79
- (new (window.require(controller))(_modal, ...args));
80
- } else if (typeof controller === 'function') {
81
- controller(_modal, ...args);
82
- }
83
- }
84
-
85
- const self = this;
86
-
87
- return _modal.on('shown', function ({el}) {
88
- zIndex = DEFAULT_Z_INDEX + (10 * stack.length);
89
- el.style.zIndex = zIndex;
90
- setTimeout(() => document.querySelector('.modal-backdrop').style.zIndex = zIndex - 1);
91
- }).on('showBackdrop', this._fixBackdrop).on('hidden', function ({el}) {
92
- stack = stack.filter((modal) => {
93
- return ! modal.el.isEqualNode(el);
94
- });
95
-
96
- if (stack.length) {
97
- document.body.classList.add('modal-open');
98
- }
99
-
100
- document.body.style.paddingRight = originalBodyPad;
101
-
102
- zIndex -= 10;
103
- self._fixBackdrop();
104
- DOM.remove(el);
105
- }).show();
106
- }
107
-
108
- _fixBackdrop() {
109
- const backdrops = document.querySelectorAll('.modal-backdrop');
110
- let shown = false;
111
-
112
- backdrops.forEach((backdrop, index) => {
113
- if (shown || index > 0 && index === backdrops.length - 1) {
114
- backdrop.style.display = 'none';
115
- } else {
116
- backdrop.style.zIndex = zIndex - 1;
117
- backdrop.style.display = '';
118
- shown = true;
119
- }
120
- });
121
- }
122
-
123
- _makeDialog(content) {
124
- this.id = `js_${dialogId.toString(16)}`;
125
- return `<div id="${this.id}" class="modal fade" tabindex="-1" role="dialog">
126
- ${content}
127
- </div>`;
128
- }
129
- }
1
+ import Modal from "modal-vanilla/lib/modal";
2
+ import DOM from "./DOM";
3
+
4
+ const DEFAULT_Z_INDEX = 1040;
5
+
6
+ let stack = [];
7
+ let dialogId = 1;
8
+ let zIndex;
9
+ let originalBodyPad = null;
10
+
11
+ Modal.prototype._handleKeydownEvent = function(event) {
12
+ if (event.which === 27 && this._options.keyboard) {
13
+ const currentModal = stack[stack.length - 1];
14
+ if (currentModal.el.isEqualNode(this.el)) {
15
+ this.emit('dismiss', this, event, null);
16
+ this.hide();
17
+ }
18
+ }
19
+ }
20
+
21
+ export default class Dialog {
22
+ close(limit = -1) {
23
+ let modals;
24
+ if (limit > -1) {
25
+ modals = stack.slice(-limit);
26
+ } else {
27
+ modals = stack
28
+ }
29
+ modals.forEach((dialog) => dialog.hide())
30
+ }
31
+
32
+ closeCurrent() {
33
+ const dialog = stack.pop();
34
+
35
+ if (dialog) {
36
+ dialog.hide();
37
+ }
38
+ }
39
+
40
+ render(options, args) {
41
+ DOM.appendContent(document.body, this._makeDialog(options.content, options.dialogClassName));
42
+
43
+ dialogId++;
44
+
45
+ const renderDialog = () => {
46
+ const dialog = this._show({
47
+ el: document.getElementById(this.id),
48
+ animate: options.animate !== null && options.animate !== undefined ? options.animate : false,
49
+ keyboard: options.keyboard !== null && options.keyboard !== undefined ? options.keyboard : true,
50
+ backdrop: options.backdrop !== null && options.backdrop !== undefined ? options.backdrop : true,
51
+ transition: options.transition !== null && options.transition !== undefined ? options.transition : 0,
52
+ backdropTransition: options.backdropTransition !== null && options.backdropTransition !== undefined ? options.backdropTransition : 0,
53
+ }, options.controller, args);
54
+
55
+ stack.push(dialog);
56
+
57
+ return dialog;
58
+ };
59
+
60
+ if (options.timeout && typeof options.timeout === 'number') {
61
+ return new Promise(resolve => setTimeout(() => resolve(renderDialog()), options.timeout));
62
+ }
63
+
64
+ return renderDialog();
65
+ }
66
+
67
+ showFromModel(model, args) {
68
+ const dialog = this._show({
69
+ title: model.title || '',
70
+ content: model.body,
71
+ footer: model.footer || false,
72
+ animate: model.animate !== null && model.animate !== undefined ? model.animate : false,
73
+ keyboard: model.keyboard !== null && model.keyboard !== undefined ? model.keyboard : true,
74
+ backdrop: model.backdrop !== null && model.backdrop !== undefined ? model.backdrop : true,
75
+ transition: model.transition !== null && model.transition !== undefined ? model.transition : 0,
76
+ backdropTransition: model.backdropTransition !== null && model.backdropTransition !== undefined ? model.backdropTransition : 0,
77
+ }, model.controller, args);
78
+
79
+ stack.push(dialog);
80
+
81
+ return dialog;
82
+ }
83
+
84
+ _show(options, controller, args) {
85
+ if (originalBodyPad === null) {
86
+ originalBodyPad = document.body.style.paddingRight;
87
+ }
88
+
89
+ const _modal = new Modal(options);
90
+
91
+ if (controller) {
92
+ if (typeof controller === 'string') {
93
+ (new (window.require(controller))(_modal, ...args));
94
+ } else if (typeof controller === 'function') {
95
+ controller(_modal, ...args);
96
+ }
97
+ }
98
+
99
+ const self = this;
100
+
101
+ return _modal.on('shown', function ({el}) {
102
+ zIndex = DEFAULT_Z_INDEX + (10 * stack.length);
103
+ el.style.zIndex = zIndex;
104
+ setTimeout(() => document.querySelector('.modal-backdrop').style.zIndex = zIndex - 1);
105
+ }).on('showBackdrop', this._fixBackdrop).on('hidden', function ({el}) {
106
+ stack = stack.filter((modal) => {
107
+ return ! modal.el.isEqualNode(el);
108
+ });
109
+
110
+ if (stack.length) {
111
+ document.body.classList.add('modal-open');
112
+ }
113
+
114
+ document.body.style.paddingRight = originalBodyPad;
115
+
116
+ zIndex -= 10;
117
+ self._fixBackdrop();
118
+ DOM.remove(el);
119
+ }).show();
120
+ }
121
+
122
+ _fixBackdrop() {
123
+ const backdrops = document.querySelectorAll('.modal-backdrop');
124
+ let shown = false;
125
+
126
+ backdrops.forEach((backdrop, index) => {
127
+ if (shown || index > 0 && index === backdrops.length - 1) {
128
+ backdrop.style.display = 'none';
129
+ } else {
130
+ backdrop.style.zIndex = zIndex - 1;
131
+ backdrop.style.display = '';
132
+ shown = true;
133
+ }
134
+ });
135
+ }
136
+
137
+ _makeDialog(content, dialogClassName) {
138
+ this.id = `js_${dialogId.toString(16)}`;
139
+ return `<div id="${this.id}" class="modal fade ${dialogClassName || ''}" tabindex="-1" role="dialog">
140
+ ${content}
141
+ </div>`;
142
+ }
143
+ }
@@ -1,38 +1,38 @@
1
- import CSSCore from "fbjs/lib/CSSCore";
2
-
3
- export function byTag(node, tagName) {
4
- tagName = tagName.toUpperCase();
5
- node = find(node, function (el) {
6
- return el.nodeName === tagName;
7
- });
8
-
9
- return node instanceof Element ? node : null;
10
- }
11
-
12
- export function byClass(node, className) {
13
- node = find(node, function (el) {
14
- return el instanceof Element && CSSCore.hasClass(el, className);
15
- });
16
-
17
- return node instanceof Element ? node : null;
18
- }
19
-
20
- export function byAttribute(node, attribute) {
21
- node = find(node, function (el) {
22
- return el instanceof Element && el.hasAttribute(attribute);
23
- });
24
-
25
- return node instanceof Element ? node : null;
26
- }
27
-
28
- export function find(node, callback) {
29
- while (node) {
30
- if (callback(node)) {
31
- return node;
32
- }
33
-
34
- node = node.parentNode;
35
- }
36
-
37
- return null;
38
- }
1
+ import CSSCore from "fbjs/lib/CSSCore";
2
+
3
+ export function byTag(node, tagName) {
4
+ tagName = tagName.toUpperCase();
5
+ node = find(node, function (el) {
6
+ return el.nodeName === tagName;
7
+ });
8
+
9
+ return node instanceof Element ? node : null;
10
+ }
11
+
12
+ export function byClass(node, className) {
13
+ node = find(node, function (el) {
14
+ return el instanceof Element && CSSCore.hasClass(el, className);
15
+ });
16
+
17
+ return node instanceof Element ? node : null;
18
+ }
19
+
20
+ export function byAttribute(node, attribute) {
21
+ node = find(node, function (el) {
22
+ return el instanceof Element && el.hasAttribute(attribute);
23
+ });
24
+
25
+ return node instanceof Element ? node : null;
26
+ }
27
+
28
+ export function find(node, callback) {
29
+ while (node) {
30
+ if (callback(node)) {
31
+ return node;
32
+ }
33
+
34
+ node = node.parentNode;
35
+ }
36
+
37
+ return null;
38
+ }
@@ -1,9 +1,9 @@
1
- export default class ReloadPage {
2
- now() {
3
- window.location.reload();
4
- }
5
-
6
- delay(delay) {
7
- setTimeout(this.now.bind(this), delay);
8
- }
9
- }
1
+ export default class ReloadPage {
2
+ now() {
3
+ window.location.reload();
4
+ }
5
+
6
+ delay(delay) {
7
+ setTimeout(this.now.bind(this), delay);
8
+ }
9
+ }
@@ -1,7 +1,7 @@
1
- export default class ServerRedirect {
2
- redirectPageTo(url, delay = 0) {
3
- setTimeout(function () {
4
- window.location = url;
5
- }, delay);
6
- }
7
- }
1
+ export default class ServerRedirect {
2
+ redirectPageTo(url, delay = 0) {
3
+ setTimeout(function () {
4
+ window.location = url;
5
+ }, delay);
6
+ }
7
+ }
@@ -1,46 +1,46 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule copyProperties
10
- */
11
- 'use strict';
12
-
13
- /**
14
- * Copy properties from one or more objects (up to 5) into the first object.
15
- * This is a shallow copy. It mutates the first object and also returns it.
16
- *
17
- * NOTE: `arguments` has a very significant performance penalty, which is why
18
- * we don't support unlimited arguments.
19
- */
20
- export default function copyProperties(obj, a, b, c, d, e, f) {
21
- obj = obj || {};
22
-
23
- if (__DEV__) {
24
- if (f) {
25
- throw new Error('Too many arguments passed to copyProperties');
26
- }
27
- }
28
-
29
- var args = [a, b, c, d, e];
30
- var ii = 0, v;
31
- while (args[ii]) {
32
- v = args[ii++];
33
- for (var k in v) {
34
- obj[k] = v[k];
35
- }
36
-
37
- // IE ignores toString in object iteration.. See:
38
- // webreflection.blogspot.com/2007/07/quick-fix-internet-explorer-and.html
39
- if (v.hasOwnProperty && v.hasOwnProperty('toString') &&
40
- (typeof v.toString !== 'undefined') && (obj.toString !== v.toString)) {
41
- obj.toString = v.toString;
42
- }
43
- }
44
-
45
- return obj;
46
- }
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule copyProperties
10
+ */
11
+ 'use strict';
12
+
13
+ /**
14
+ * Copy properties from one or more objects (up to 5) into the first object.
15
+ * This is a shallow copy. It mutates the first object and also returns it.
16
+ *
17
+ * NOTE: `arguments` has a very significant performance penalty, which is why
18
+ * we don't support unlimited arguments.
19
+ */
20
+ export default function copyProperties(obj, a, b, c, d, e, f) {
21
+ obj = obj || {};
22
+
23
+ if (__DEV__) {
24
+ if (f) {
25
+ throw new Error('Too many arguments passed to copyProperties');
26
+ }
27
+ }
28
+
29
+ var args = [a, b, c, d, e];
30
+ var ii = 0, v;
31
+ while (args[ii]) {
32
+ v = args[ii++];
33
+ for (var k in v) {
34
+ obj[k] = v[k];
35
+ }
36
+
37
+ // IE ignores toString in object iteration.. See:
38
+ // webreflection.blogspot.com/2007/07/quick-fix-internet-explorer-and.html
39
+ if (v.hasOwnProperty && v.hasOwnProperty('toString') &&
40
+ (typeof v.toString !== 'undefined') && (obj.toString !== v.toString)) {
41
+ obj.toString = v.toString;
42
+ }
43
+ }
44
+
45
+ return obj;
46
+ }