native-document 1.0.214 → 1.0.216

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/components.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { default as BaseComponent } from './src/components/BaseComponent';
1
2
  export * from './src/components/accordion/index';
2
3
  export * from './src/components/alert/index';
3
4
  export * from './src/components/avatar/index';
@@ -13,6 +14,7 @@ export * from './src/components/form/index';
13
14
  export * from './src/components/list/index';
14
15
  export * from './src/components/menu/index';
15
16
  export * from './src/components/modal/index';
17
+ export * from './src/components/modal/createModal';
16
18
  export * from './src/components/pagination/index';
17
19
  export * from './src/components/popover/index';
18
20
  export * from './src/components/progress/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.214",
3
+ "version": "1.0.216",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -76,6 +76,8 @@ export default function Modal(content, props = {}) {
76
76
  BaseComponent.extends(Modal);
77
77
  BaseComponent.use(Modal, HasEventEmitter, HasDraggable, HasResizable);
78
78
 
79
+ Modal.prototype.__$isModal = true;
80
+
79
81
  // Theming
80
82
  Modal.defaultTemplate = null;
81
83
 
@@ -0,0 +1,61 @@
1
+ import { $ } from '../../core/data/Observable';
2
+ import {createPortal} from '../../core/elements/anchor/anchor';
3
+ import Modal from './Modal';
4
+
5
+ export function createModal(builder) {
6
+ return Cache.once(() => {
7
+
8
+ const $modalRef = $.ref();
9
+ let currentOnSelect = null;
10
+ let selectedValue = null;
11
+ const events = { onOpen: null, onClose: null };
12
+
13
+ const finish = (value = null) => {
14
+ currentOnSelect && currentOnSelect(value ?? selectedValue);
15
+ currentOnSelect = null;
16
+ };
17
+
18
+ const content = builder({
19
+ resolve: (value) => {
20
+ selectedValue = value;
21
+ $modalRef.close();
22
+ },
23
+ reject: () => {
24
+ selectedValue = null;
25
+ $modalRef.close();
26
+ },
27
+ onOpen: (onOpen) => {
28
+ events.onOpen = onOpen;
29
+ },
30
+ onClose: (onClose) => {
31
+ events.onClose = onClose;
32
+ }
33
+ });
34
+
35
+ const modal = (content?.__$isModal) ? content : Modal(content);
36
+
37
+ createPortal(
38
+ modal
39
+ .onClose(() => {
40
+ finish(null);
41
+ events.onClose && events.onClose();
42
+ })
43
+ .ref($modalRef),
44
+ );
45
+
46
+ return {
47
+ open: (params) => {
48
+ if (currentOnSelect) {
49
+ finish(null);
50
+ }
51
+ $modalRef.open();
52
+ events.onOpen?.(params);
53
+ return new Promise((resolve) => {
54
+ currentOnSelect = resolve;
55
+ });
56
+ },
57
+ close: () => $modalRef.close(),
58
+ instance: $modalRef,
59
+ };
60
+ });
61
+ }
@@ -26,7 +26,7 @@ export type ModalDescription = {
26
26
  props: GlobalAttributes;
27
27
  };
28
28
 
29
- export interface ModalInterface extends BaseComponent {
29
+ export interface ModalInterface extends Omit<BaseComponent, 'onDrag' | 'onDragEnd' | 'onDragStart' | 'onResize'> {
30
30
  trigger(trigger: HTMLElement): HTMLElement;
31
31
  open(): void;
32
32
  close(): void;