bigpipe-util 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,3 +8,25 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
8
8
 
9
9
  ### Added
10
10
  - Part of BigPipe implementation for Webpack.
11
+
12
+ ## v0.1.2 - 2022-04-14
13
+
14
+ ### Added
15
+ - Dialogs support.
16
+
17
+ ## v0.1.3 - 2022-04-27
18
+
19
+ ### Added
20
+ - Method to close only current dialog
21
+
22
+ ### Fixed
23
+ - Dialog z-index
24
+
25
+ ## v0.1.4 - 2022-05-06
26
+
27
+ ### Added
28
+ - Async requests counter
29
+ - Support for extra arguments in dialog controller
30
+
31
+ ### Fixed
32
+ - Arguments for non-method require calls
package/README.md CHANGED
@@ -106,10 +106,6 @@ if (OH_NOES_WE_NEED_TO_CANCEL_RIGHT_NOW_OR_ELSE) {
106
106
  rel="dialog">Open Modal</a>
107
107
  ```
108
108
 
109
- ## Credits
110
-
111
- - [Richard Dobroň][link-author]
112
-
113
109
  ## Inspiration
114
110
 
115
111
  BigPipe is inspired by the concept behind Facebook's BigPipe. For more details
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bigpipe-util",
3
3
  "description": "This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.",
4
- "version": "0.1.1",
4
+ "version": "0.1.4",
5
5
  "keywords": [
6
6
  "bigpipe",
7
7
  "xhr",
@@ -19,6 +19,7 @@
19
19
  "bugs:": "https://github.com/richardDobron/bigpipe-util/issues",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "fbjs": "^3.0.4"
22
+ "fbjs": "^3.0.4",
23
+ "modal-vanilla": "^0.9.0"
23
24
  }
24
25
  }
package/src/Primer.js CHANGED
@@ -4,7 +4,7 @@ import {byTag} from "./core/Parent";
4
4
  export default function Primer() {
5
5
  const rootElement = document.documentElement;
6
6
 
7
- const RELATIONSHIP_REGEX = /async(?:-post)?/;
7
+ const RELATIONSHIP_REGEX = /async(?:-post)?|dialog/;
8
8
 
9
9
  rootElement.onclick = function (event) {
10
10
  event = event || window.event;
@@ -29,6 +29,14 @@ export default function Primer() {
29
29
  .setMethod(relationship === "async-post" ? "POST" : "GET")
30
30
  .send();
31
31
  break;
32
+ case "dialog":
33
+ event.preventDefault();
34
+
35
+ (new AsyncRequest(linkNodeOnClicked.getAttribute("ajaxify")))
36
+ .setRelative(linkNodeOnClicked)
37
+ .setMethod("POST")
38
+ .send();
39
+ break;
32
40
  }
33
41
  };
34
42
 
package/src/ServerJS.js CHANGED
@@ -29,8 +29,6 @@ export default class ServerJS {
29
29
 
30
30
  context[method].apply(context, marker || []);
31
31
  } else {
32
- marker = method;
33
-
34
32
  if (marker) {
35
33
  replaceTransportMarkers(this._relativeTo, marker);
36
34
  }
@@ -1,6 +1,8 @@
1
1
  import emptyFunction from "fbjs/lib/emptyFunction";
2
2
  import AsyncResponse from "./AsyncResponse";
3
3
 
4
+ let requests = 0;
5
+
4
6
  function serialize(obj, prefix) {
5
7
  const str = [];
6
8
  for(const p in obj) {
@@ -152,7 +154,13 @@ AsyncRequest.prototype.send = function () {
152
154
  };
153
155
 
154
156
  request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
155
- if (!(this.data instanceof FormData)) {
157
+
158
+ requests++;
159
+
160
+ if (this.data instanceof FormData) {
161
+ this.data.append('__req', requests);
162
+ } else {
163
+ data.__req = requests;
156
164
  data = serialize(data);
157
165
 
158
166
  if (method === "POST") {
@@ -0,0 +1,105 @@
1
+ import Modal from "modal-vanilla/lib/modal";
2
+ import DOM from "./DOM";
3
+
4
+ const DEFAULT_Z_INDEX = 1040;
5
+
6
+ const stack = [];
7
+ let modalId = 1;
8
+ let zIndex;
9
+ let originalBodyPad = null;
10
+
11
+ export default class Dialog {
12
+ close() {
13
+ stack.forEach((dialog) => dialog.hide())
14
+ }
15
+
16
+ closeCurrent() {
17
+ const dialog = stack[stack.length - 1];
18
+
19
+ if (dialog) {
20
+ dialog.hide();
21
+ }
22
+ }
23
+
24
+ render(options, args) {
25
+ DOM.appendContent(document.body, this._makeDialog(options.content));
26
+
27
+ modalId++;
28
+
29
+ const _dialog = this._show({
30
+ el: document.getElementById(this.id),
31
+ animate: false,
32
+ backdrop: options.backdrop ?? true,
33
+ transition: options.transition ?? 0,
34
+ backdropTransition: options.backdropTransition ?? 0,
35
+ }, options.controller, args);
36
+
37
+ stack.push(_dialog);
38
+ }
39
+
40
+ showFromModel(model, args) {
41
+ const _dialog = this._show({
42
+ title: model.title || '',
43
+ content: model.body,
44
+ footer: model.footer || false,
45
+ animate: false,
46
+ backdrop: model.backdrop ?? true,
47
+ transition: model.transition ?? 0,
48
+ backdropTransition: model.backdropTransition ?? 0,
49
+ }, model.controller, args);
50
+
51
+ stack.push(_dialog);
52
+ }
53
+
54
+ _show(options, controller, args) {
55
+ if (originalBodyPad === null) {
56
+ originalBodyPad = document.body.style.paddingRight;
57
+ }
58
+
59
+ const _modal = new Modal(options);
60
+
61
+ if (controller) {
62
+ (new (window.require(controller))(_modal, ...args));
63
+ }
64
+
65
+ const self = this;
66
+
67
+ return _modal.on('shown', function ({el}) {
68
+ zIndex = DEFAULT_Z_INDEX + (10 * stack.length);
69
+ el.style.zIndex = zIndex;
70
+ setTimeout(() => document.querySelector('.modal-backdrop').style.zIndex = zIndex - 1);
71
+ }).on('showBackdrop', this._fixBackdrop).on('hidden', function ({el}) {
72
+ stack.pop();
73
+
74
+ if (stack.length) {
75
+ document.body.classList.add('modal-open');
76
+ }
77
+
78
+ document.body.style.paddingRight = originalBodyPad;
79
+
80
+ zIndex -= 10;
81
+ self._fixBackdrop();
82
+ DOM.remove(el);
83
+ }).show();
84
+ }
85
+
86
+ _fixBackdrop(content) {
87
+ const backdrops = document.querySelectorAll('.modal-backdrop');
88
+
89
+ backdrops.forEach((backdrop, index) => {
90
+ if (index > 0 && index === backdrops.length - 1) {
91
+ backdrop.style.display = 'none';
92
+ } else {
93
+ backdrop.style.zIndex = zIndex - 1;
94
+ backdrop.style.display = '';
95
+ }
96
+ });
97
+ }
98
+
99
+ _makeDialog(content) {
100
+ this.id = `js_${modalId.toString(16)}`;
101
+ return `<div id="${this.id}" class="modal fade" tabindex="-1" role="dialog">
102
+ ${content}
103
+ </div>`;
104
+ }
105
+ }