@lemonadejs/modal 3.1.0 → 3.3.0

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/README.md CHANGED
@@ -121,7 +121,7 @@ Quick example with Vue
121
121
  </script>
122
122
  ```
123
123
 
124
- Programmatical - Quick example with Javascript
124
+ Programmatically - Quick example with Javascript
125
125
 
126
126
  ```html
127
127
  <html>
@@ -159,43 +159,58 @@ You can configure things such as position, size, and functionalities.
159
159
 
160
160
  ### Settings
161
161
 
162
- | Attribute | Type | Description |
163
- | --- | --- | --- |
164
- | title? | String | The header title of the modal. If empty, the header will be not displayed. |
165
- | height? | Number | The height of the modal in pixels. |
166
- | width? | Number | The width of the modal in pixels. |
167
- | top? | Number | The vertical position of the modal within its window in pixels. |
168
- | left? | Number | The horizontal position of the modal within its window in pixels. |
169
- | draggable? | Boolean | Determines if the modal can be dragged. `Default: false`. |
170
- | resizable? | Boolean | Determines if the modal can be resized. `Default: false`. |
171
- | closed? | Boolean | Controls the open and close state of the modal. `Default: false`. |
172
- | closable? | Boolean | Disables the ability to close the modal. `Default: false`. |
173
- | center? | Boolean | Enables rendering the modal in the center of its window. `Default: false`. |
174
- | url? | String | The URL from which to fetch and render content. |
175
- | auto-close? | Boolean | Close the modal when it loses the focus. `Default: false`. |
176
- | auto-adjust? | Boolean | Ensures modal will be visible on screen. `Default: false`. |
177
- | backdrop? | Boolean | Enables the backdrop when the modal is opened. |
178
- | minimizable? | Boolean | Modal can be minimized. `Default: false`. |
179
- | minimized? | Boolean | Current minimized state of the modal. |
180
- | position? | String | Modal is automatic align during initialization. |
181
- | title? | String | Title of the modal. |
182
- | responsive? | Boolean | Enables responsive mode. `Default: true`. |
183
- | layers? | Boolean | Bring to front on focus. |
184
- | focus? | Boolean | Focus on the modal when open it. `Default: true`. |
185
- | overflow? | Boolean | Create scroll when the content is larger than the modal. `Default: false`. |
162
+ | Attribute | Type | Description |
163
+ |--------------|---------|----------------------------------------------------------------------------|
164
+ | title? | String | The header title of the modal. If empty, the header will be not displayed. |
165
+ | height? | Number | The height of the modal in pixels. |
166
+ | width? | Number | The width of the modal in pixels. |
167
+ | top? | Number | The vertical position of the modal within its window in pixels. |
168
+ | left? | Number | The horizontal position of the modal within its window in pixels. |
169
+ | draggable? | Boolean | Determines if the modal can be dragged. `Default: false`. |
170
+ | resizable? | Boolean | Determines if the modal can be resized. `Default: false`. |
171
+ | closed? | Boolean | Controls the open and close state of the modal. `Default: false`. |
172
+ | closable? | Boolean | Disables the ability to close the modal. `Default: false`. |
173
+ | center? | Boolean | Enables rendering the modal in the center of its window. `Default: false`. |
174
+ | url? | String | The URL from which to fetch and render content. |
175
+ | auto-close? | Boolean | Close the modal when it loses the focus. `Default: false`. |
176
+ | auto-adjust? | Boolean | Ensures modal will be visible on screen. `Default: false`. |
177
+ | backdrop? | Boolean | Enables the backdrop when the modal is opened. |
178
+ | minimizable? | Boolean | Modal can be minimized. `Default: false`. |
179
+ | minimized? | Boolean | Current minimized state of the modal. |
180
+ | position? | String | Modal is automatic align during initialization. |
181
+ | title? | String | Title of the modal. |
182
+ | responsive? | Boolean | Enables responsive mode. `Default: true`. |
183
+ | layers? | Boolean | Bring to front on focus. |
184
+ | focus? | Boolean | Focus on the modal when open it. `Default: true`. |
185
+ | overflow? | Boolean | Create scroll when the content is larger than the modal. `Default: false`. |
186
186
 
187
187
 
188
188
  ### Events
189
189
 
190
- | Event | Description |
191
- |------------------------------| --- |
192
- | onclose? | Called when modal closes. |
193
- | onopen? | Called when modal opens. |
190
+ | Event | Description |
191
+ |-----------|------------------------------------------|
192
+ | onload? | When the modal is ready. |
193
+ | onclose? | Called when modal closes. |
194
+ | onopen? | Called when modal opens. |
195
+ | onresize? | When the user resize the modal. |
196
+ | onmove? | When the user change the modal position. |
197
+
194
198
 
195
199
  ## License
196
200
 
197
201
  The LemonadeJS Modal is released under the MIT.
198
202
 
203
+
204
+ ## Changelog
205
+
206
+ ### 3.1.1
207
+
208
+ - Added new events: `onmove` and `onresize`.
209
+
210
+ ### 3.1.0
211
+
212
+ - Close modal using the keyboard by pressing `Shift + Tab` on the icon.
213
+
199
214
  ## Other Tools
200
215
 
201
216
  - [jSuites](https://jsuites.net/docs)
package/dist/index.d.ts CHANGED
@@ -54,6 +54,10 @@ declare namespace Modal {
54
54
  onclose?: (self: object) => void;
55
55
  /** onload event */
56
56
  onload?: (self: object) => void;
57
+ /** Move event */
58
+ onmove?: (self: object, x: number, y: number) => void;
59
+ /** Resize event */
60
+ onresize?: (self: object, w: number, h: number) => void;
57
61
  /** Import content from DOM reference */
58
62
  content?: HTMLElement;
59
63
  }
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * pin the modal to the left panel
3
3
  */
4
- if (!lemonade && typeof (require) === 'function') {
4
+ if (! lemonade && typeof (require) === 'function') {
5
5
  var lemonade = require('lemonadejs');
6
6
  }
7
7
 
@@ -188,9 +188,11 @@ if (!lemonade && typeof (require) === 'function') {
188
188
  }
189
189
 
190
190
  // Dispatcher
191
- const Dispatch = function(type, option){
191
+ const Dispatch = function(type){
192
192
  if (typeof this[type] === 'function') {
193
- this[type](this, option)
193
+ let args = Array.from(arguments);
194
+ args.shift();
195
+ this[type](...args)
194
196
  }
195
197
  }
196
198
 
@@ -433,18 +435,6 @@ if (!lemonade && typeof (require) === 'function') {
433
435
 
434
436
  // Native lemonade
435
437
  self.onload = function() {
436
- if (self.url) {
437
- fetch(self.url)
438
- .then(response => response.clone().body)
439
- .then(body => {
440
- let reader = body.getReader();
441
- reader.read().then(function pump({done, value}) {
442
- const decoder = new TextDecoder();
443
- template += decoder.decode(value.buffer);
444
- });
445
- });
446
- }
447
-
448
438
  // Dimensions
449
439
  if (self.width) {
450
440
  self.el.style.width = self.width + 'px';
@@ -497,7 +487,11 @@ if (!lemonade && typeof (require) === 'function') {
497
487
  backdrop.classList.add('lm-modal-backdrop');
498
488
  backdrop.addEventListener('click', function() {
499
489
  self.closed = true;
500
- })
490
+ });
491
+
492
+ if (self.closed === false) {
493
+ self.el.parentNode.insertBefore(backdrop, self.el);
494
+ }
501
495
  }
502
496
 
503
497
  // Bring to front on focus
@@ -507,7 +501,11 @@ if (!lemonade && typeof (require) === 'function') {
507
501
 
508
502
  // Import content from DOM
509
503
  if (self.content) {
510
- self.el.children[1].appendChild(self.content);
504
+ if (typeof(self.content) === 'string') {
505
+ self.root.appendChild(document.createTextNode(self.content));
506
+ } else if (typeof(self.content.tagName) === 'object' && self.content.tagName) {
507
+ self.root.appendChild(self.content);
508
+ }
511
509
  }
512
510
 
513
511
  // Focus out of the component
@@ -704,6 +702,8 @@ if (!lemonade && typeof (require) === 'function') {
704
702
  self.width = parseInt(item.style.width);
705
703
  self.height = parseInt(item.style.height);
706
704
  controls.e.classList.remove('action');
705
+ // Event
706
+ Dispatch.call(self, 'onresize', self, self.width, self.height);
707
707
  }
708
708
  controls.e.classList.add('action');
709
709
  } else if (isTrue(self.draggable) && y - rect.top < 40) {
@@ -712,6 +712,8 @@ if (!lemonade && typeof (require) === 'function') {
712
712
  self.top = parseInt(item.style.top);
713
713
  self.left = parseInt(item.style.left);
714
714
  controls.e.classList.remove('action');
715
+ // Event
716
+ Dispatch.call(self, 'onmove', self, self.top, self.left);
715
717
  }
716
718
  controls.e.classList.add('action');
717
719
  // Remove transform
@@ -747,22 +749,41 @@ if (!lemonade && typeof (require) === 'function') {
747
749
  }
748
750
  }
749
751
 
750
- if (! template) {
752
+ if (self.url) {
753
+ fetch(self.url)
754
+ .then(response => response.clone().body)
755
+ .then(body => {
756
+ let reader = body.getReader();
757
+ reader.read().then(function pump({done, value}) {
758
+ const decoder = new TextDecoder();
759
+ self.root.innerHTML = decoder.decode(value.buffer);
760
+ });
761
+ });
762
+ }
763
+
764
+ if (! template || typeof(template) !== 'string') {
751
765
  template = '';
752
766
  }
753
767
 
754
- return `<div class="lm-modal" animation="{{self.animation}}" position="{{self.position}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" overflow="{{self.overflow}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown" onmousemove="self.mousemove" onclick="self.click" tabindex="-1">
768
+ // Custom Root Configuration
769
+ self.settings = {
770
+ getRoot: function() {
771
+ return self.root;
772
+ }
773
+ }
774
+
775
+ return `<div class="lm-modal" animation="{{self.animation}}" position="{{self.position}}" closed="{{self.closed}}" closable="{{self.closable}}" minimizable="{{self.minimizable}}" minimized="{{self.minimized}}" overflow="{{self.overflow}}" :top="self.top" :left="self.left" :width="self.width" :height="self.height" onmousedown="self.mousedown" onmousemove="self.mousemove" onclick="self.click" tabindex="-1" role="modal">
755
776
  <div class="lm-modal-title" data-title="{{self.title}}" data-icon="{{self.icon}}"><div class="lm-modal-icon">{{self.icon}}</div><div>{{self.title}}</div><div class="lm-modal-icon lm-modal-minimize" tabindex="0"></div><div class="lm-modal-icon lm-modal-close" tabindex="0"></div></div>
756
- <div>${template}</div>
777
+ <div :ref="self.root">${template}</div>
757
778
  </div>`
758
779
  }
759
780
 
760
- const Component = function (root, options, template) {
781
+ const Component = function (root, options) {
761
782
  if (typeof(root) === 'object') {
762
783
  // Remove elements from the DOM
763
784
  let elements = removeElements(root);
764
785
  // Create the modal
765
- let e = lemonade.render(Modal, root, options, template);
786
+ let e = lemonade.render(Modal, root, options);
766
787
  // Add elements to the container
767
788
  appendElements(e.children[1], elements);
768
789
 
package/dist/style.css CHANGED
@@ -17,6 +17,10 @@
17
17
  color: var(--lm-font-color, #000);
18
18
  }
19
19
 
20
+ .lm-modal[closed="true"] {
21
+ display: none;
22
+ }
23
+
20
24
  .lm-modal.action {
21
25
  user-select: none;
22
26
  }
@@ -30,62 +34,58 @@
30
34
  line-height: 24px;
31
35
  user-select: none;
32
36
  display: flex;
33
- border-radius: 5px;
37
+ border-radius: 5px 5px 0 0;
34
38
  }
35
39
 
36
- .lm-modal .lm-modal-title {
40
+ .lm-modal > .lm-modal-title {
37
41
  display: none;
38
42
  }
39
43
 
40
- .lm-modal .lm-modal-title[data-icon],
41
- .lm-modal .lm-modal-title[data-title],
42
- .lm-modal[closable="true"] .lm-modal-title,
43
- .lm-modal[minimizable="true"] .lm-modal-title {
44
+ .lm-modal > .lm-modal-title[data-icon],
45
+ .lm-modal > .lm-modal-title[data-title],
46
+ .lm-modal[closable="true"] > .lm-modal-title,
47
+ .lm-modal[minimizable="true"] > .lm-modal-title {
44
48
  display: inherit;
45
49
  }
46
50
 
47
- .lm-modal-title > div:nth-child(2) {
51
+ .lm-modal > .lm-modal-title > div:nth-child(2) {
48
52
  flex: 1;
49
53
  }
50
54
 
51
- .lm-modal .lm-modal-icon {
55
+ .lm-modal > .lm-modal-title > .lm-modal-icon {
52
56
  width: 24px;
53
57
  height: 24px;
54
58
  font-size: 24px;
55
59
  cursor: pointer;
56
60
  font-family: "Material Icons";
57
61
  text-align: center;
62
+ margin-right: 5px;
58
63
  display: none;
59
64
  }
60
65
 
61
- .lm-modal .lm-modal-icon:not(:empty) {
66
+ .lm-modal > .lm-modal-title > .lm-modal-icon:not(:empty) {
62
67
  display: inherit;
63
68
  }
64
69
 
65
- .lm-modal .lm-modal-close::before {
70
+ .lm-modal > .lm-modal-title > .lm-modal-close::before {
66
71
  content: 'close';
67
72
  }
68
73
 
69
- .lm-modal .lm-modal-minimize::before {
74
+ .lm-modal > .lm-modal-title > .lm-modal-minimize::before {
70
75
  content: '\2500';
71
76
  }
72
77
 
73
- .lm-modal div[data-icon] .lm-modal-feature,
74
- .lm-modal[minimizable="true"] .lm-modal-minimize {
75
- margin-right: 5px;
76
- display: block;
78
+ .lm-modal[minimized="true"] > .lm-modal-title > .lm-modal-minimize::before {
79
+ content: '\e5d7';
77
80
  }
78
81
 
79
- .lm-modal[closable="true"] .lm-modal-close {
82
+ .lm-modal[minimizable="true"] > .lm-modal-title > .lm-modal-minimize {
80
83
  display: block;
81
84
  }
82
85
 
83
- .lm-modal[closed="true"] {
84
- display: none;
85
- }
86
-
87
- .lm-modal[minimized="true"] .lm-modal-minimize::before {
88
- content: '\e5d7';
86
+ .lm-modal[closable="true"] > .lm-modal-title > .lm-modal-close {
87
+ margin-right: 0;
88
+ display: block;
89
89
  }
90
90
 
91
91
  .lm-modal.hide {
@@ -111,7 +111,7 @@
111
111
  width: 100vw;
112
112
  height: 100vh;
113
113
  background-color: #00000020;
114
- z-index: 999;
114
+ z-index: 15;
115
115
  }
116
116
 
117
117
  .lm-modal > div:last-child {
package/package.json CHANGED
@@ -13,9 +13,9 @@
13
13
  "modal js"
14
14
  ],
15
15
  "dependencies": {
16
- "lemonadejs": "^4.3.2"
16
+ "lemonadejs": "^4.3.3"
17
17
  },
18
18
  "main": "dist/index.js",
19
19
  "types": "dist/index.d.ts",
20
- "version": "3.1.0"
20
+ "version": "3.3.0"
21
21
  }