@nascentdigital/funnel-ui 4.5.2 → 4.5.3
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/dist/client/hooks/breakpoint/BreakpointContainer.d.ts +1 -1
- package/dist/client/hooks/breakpoint/BreakpointContainer.js +3 -1
- package/dist/client/interaction/index.d.ts +0 -6
- package/dist/client/interaction/index.js +0 -6
- package/dist/server/blocks/Block.js +2 -2
- package/dist/server/blocks/Message.js +2 -1
- package/dist/server/blocks/Testimonial.js +13 -10
- package/dist/server/blocks/Testimonials.d.ts +35 -35
- package/dist/server/blocks/Testimonials.js +21 -66
- package/dist/server/blocks/index.d.ts +1 -0
- package/dist/server/blocks/index.js +1 -0
- package/dist/server/fields/CallToActions.d.ts +12 -0
- package/dist/server/fields/CallToActions.js +27 -0
- package/dist/server/fields/index.d.ts +1 -0
- package/dist/server/fields/index.js +1 -0
- package/dist/server/panels/BlockPanel.js +1 -2
- package/dist/server/panels/MessagePanel.d.ts +2 -6
- package/dist/server/panels/MessagePanel.js +2 -9
- package/dist/server/panels/TestimonialPanel.d.ts +44 -18
- package/dist/server/panels/TestimonialPanel.js +44 -19
- package/dist/server/panels/VisualPanel.d.ts +1 -1
- package/package.json +2 -2
- package/dist/client/interaction/Popup.d.ts +0 -36
- package/dist/client/interaction/Popup.js +0 -244
- package/dist/client/interaction/Tooltip.d.ts +0 -16
- package/dist/client/interaction/Tooltip.js +0 -122
- package/dist/client/interaction/UILevel.d.ts +0 -1
- package/dist/client/interaction/UILevel.js +0 -2
- package/dist/client/interaction/backdrop/BackdropContainer.d.ts +0 -5
- package/dist/client/interaction/backdrop/BackdropContainer.js +0 -114
- package/dist/client/interaction/backdrop/BackdropContext.d.ts +0 -8
- package/dist/client/interaction/backdrop/BackdropContext.js +0 -6
- package/dist/client/interaction/backdrop/BackdropEvent.d.ts +0 -64
- package/dist/client/interaction/backdrop/BackdropEvent.js +0 -92
- package/dist/client/interaction/backdrop/index.d.ts +0 -4
- package/dist/client/interaction/backdrop/index.js +0 -20
- package/dist/client/interaction/backdrop/useBackdrop.d.ts +0 -13
- package/dist/client/interaction/backdrop/useBackdrop.js +0 -58
- package/dist/client/interaction/backdrop/useBackdropClick.d.ts +0 -2
- package/dist/client/interaction/backdrop/useBackdropClick.js +0 -21
- package/dist/client/interaction/backdrop/useBackdropVisible.d.ts +0 -1
- package/dist/client/interaction/backdrop/useBackdropVisible.js +0 -30
- package/dist/client/interaction/focus/FocusArea.d.ts +0 -10
- package/dist/client/interaction/focus/FocusArea.js +0 -38
- package/dist/client/interaction/focus/FocusContext.d.ts +0 -7
- package/dist/client/interaction/focus/FocusContext.js +0 -7
- package/dist/client/interaction/focus/FocusController.d.ts +0 -9
- package/dist/client/interaction/focus/FocusController.js +0 -40
- package/dist/client/interaction/focus/FocusService.d.ts +0 -20
- package/dist/client/interaction/focus/FocusService.js +0 -204
- package/dist/client/interaction/focus/LinkedList.d.ts +0 -18
- package/dist/client/interaction/focus/LinkedList.js +0 -122
- package/dist/client/interaction/focus/index.d.ts +0 -2
- package/dist/client/interaction/focus/index.js +0 -18
- package/dist/client/interaction/focus/useFocusService.d.ts +0 -2
- package/dist/client/interaction/focus/useFocusService.js +0 -14
- package/dist/client/interaction/modal/Modal.d.ts +0 -29
- package/dist/client/interaction/modal/Modal.js +0 -136
- package/dist/client/interaction/modal/ModalContainer.d.ts +0 -5
- package/dist/client/interaction/modal/ModalContainer.js +0 -104
- package/dist/client/interaction/modal/ModalContext.d.ts +0 -8
- package/dist/client/interaction/modal/ModalContext.js +0 -6
- package/dist/client/interaction/modal/ModalEvent.d.ts +0 -39
- package/dist/client/interaction/modal/ModalEvent.js +0 -53
- package/dist/client/interaction/modal/index.d.ts +0 -2
- package/dist/client/interaction/modal/index.js +0 -18
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SortedLinkedList = void 0;
|
|
4
|
-
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
-
// class
|
|
6
|
-
class SortedLinkedList {
|
|
7
|
-
constructor(list) {
|
|
8
|
-
// initialize instance variables
|
|
9
|
-
this._head = list === null || list === void 0 ? void 0 : list._head;
|
|
10
|
-
this._tail = list === null || list === void 0 ? void 0 : list._tail;
|
|
11
|
-
}
|
|
12
|
-
get head() {
|
|
13
|
-
return this._head;
|
|
14
|
-
}
|
|
15
|
-
get tail() {
|
|
16
|
-
return this._tail;
|
|
17
|
-
}
|
|
18
|
-
find(matches) {
|
|
19
|
-
// find the closest match
|
|
20
|
-
let node = this._head;
|
|
21
|
-
while (node && !matches(node)) {
|
|
22
|
-
node = node.next;
|
|
23
|
-
}
|
|
24
|
-
// return result
|
|
25
|
-
return node;
|
|
26
|
-
}
|
|
27
|
-
insert(node) {
|
|
28
|
-
// blow up if node is already connected
|
|
29
|
-
if (node.prev || node.next) {
|
|
30
|
-
throw new funnel_core_1.InvalidOperationError('Cannot connect node that is already bound to a list - call remove() first');
|
|
31
|
-
}
|
|
32
|
-
// find insertion target (node that comes AFTER the new node)
|
|
33
|
-
const { _head, _tail } = this;
|
|
34
|
-
let target = _head;
|
|
35
|
-
while (target && node.compareTo(target) > 0) {
|
|
36
|
-
target = target.next;
|
|
37
|
-
}
|
|
38
|
-
// handle case if we're at an extremity
|
|
39
|
-
if (!target) {
|
|
40
|
-
// make root if there's no head
|
|
41
|
-
if (!_head) {
|
|
42
|
-
this._head = node;
|
|
43
|
-
this._tail = node;
|
|
44
|
-
}
|
|
45
|
-
// or make the new tail
|
|
46
|
-
else if (_tail) {
|
|
47
|
-
_tail.next = node;
|
|
48
|
-
node.prev = _tail;
|
|
49
|
-
this._tail = node;
|
|
50
|
-
}
|
|
51
|
-
// or fail if the list is broken
|
|
52
|
-
else {
|
|
53
|
-
throw new funnel_core_1.IllegalStateError('[LinkedList.ts] list is broken');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// add before the first node if this is the new root
|
|
57
|
-
else if (!target.prev) {
|
|
58
|
-
target.prev = node;
|
|
59
|
-
node.next = target;
|
|
60
|
-
this._head = node;
|
|
61
|
-
}
|
|
62
|
-
// or add in between the list
|
|
63
|
-
else {
|
|
64
|
-
target.prev.next = node;
|
|
65
|
-
node.prev = target.prev;
|
|
66
|
-
target.prev = node;
|
|
67
|
-
node.next = target;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
remove(node) {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
const { _head, _tail } = this;
|
|
73
|
-
// blow up if the list is empty
|
|
74
|
-
if (!_head || !_tail) {
|
|
75
|
-
throw new funnel_core_1.InvalidOperationError('Cannot delete node from an empty list - call insert() first');
|
|
76
|
-
}
|
|
77
|
-
// handle if there is only one item in the list
|
|
78
|
-
if (_head === _tail) {
|
|
79
|
-
if (node === _head) {
|
|
80
|
-
delete this._head;
|
|
81
|
-
delete this._tail;
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// find deletion target
|
|
86
|
-
let target = this._head;
|
|
87
|
-
// traverse the list
|
|
88
|
-
while (target) {
|
|
89
|
-
if (target === node) {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
target = target.next;
|
|
93
|
-
}
|
|
94
|
-
if (!target) {
|
|
95
|
-
console.warn('[LinkedList]: Unable to find the node');
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// handle case if we're at an extremity
|
|
99
|
-
if (target === _head) {
|
|
100
|
-
this._head = (_a = this.head) === null || _a === void 0 ? void 0 : _a.next;
|
|
101
|
-
// if head is a node set the previous to undefined
|
|
102
|
-
if (this._head) {
|
|
103
|
-
delete this._head.prev;
|
|
104
|
-
}
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (target === _tail) {
|
|
108
|
-
this._tail = (_b = this.tail) === null || _b === void 0 ? void 0 : _b.prev;
|
|
109
|
-
delete this._tail.next;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
// or remove from in between the list
|
|
113
|
-
if (!target.prev || !target.next) {
|
|
114
|
-
throw new funnel_core_1.IllegalStateError('Node is not in between the list');
|
|
115
|
-
}
|
|
116
|
-
target.prev.next = target.next;
|
|
117
|
-
target.next.prev = target.prev;
|
|
118
|
-
delete target.next;
|
|
119
|
-
delete target.prev;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.SortedLinkedList = SortedLinkedList;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./FocusController"), exports);
|
|
18
|
-
__exportStar(require("./FocusArea"), exports);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFocusService = useFocusService;
|
|
4
|
-
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const FocusContext_1 = require("./FocusContext");
|
|
7
|
-
function useFocusService() {
|
|
8
|
-
const focusContext = (0, react_1.useContext)(FocusContext_1.FocusContext);
|
|
9
|
-
// throw if trying to access focus service outside the focus context
|
|
10
|
-
if (!focusContext.focusService) {
|
|
11
|
-
throw new funnel_core_1.IllegalStateError('[useFocusService] FocusService must be accessed within focus context');
|
|
12
|
-
}
|
|
13
|
-
return focusContext.focusService;
|
|
14
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Callback } from '@nascentdigital/funnel-core';
|
|
2
|
-
import { Variant } from 'framer-motion';
|
|
3
|
-
import { PropsWithChildren } from 'react';
|
|
4
|
-
import { BackdropEvent } from '../backdrop/BackdropEvent';
|
|
5
|
-
import { UILevel } from '../UILevel';
|
|
6
|
-
export declare function Modal({ className, level, animation, open, onOpened: onOpenedRaw, onActiveChanged: onActiveChangedRaw, onClose, onClosed: onClosedRaw, disableDismiss, children }: Modal.Props): import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
-
export declare namespace Modal {
|
|
8
|
-
type Id = BackdropEvent.DependantId;
|
|
9
|
-
type Props = PropsWithChildren & {
|
|
10
|
-
className?: string;
|
|
11
|
-
level?: UILevel;
|
|
12
|
-
animation?: Animation;
|
|
13
|
-
open?: boolean;
|
|
14
|
-
onOpened?: Callback.Void;
|
|
15
|
-
onActiveChanged?: Callback<boolean>;
|
|
16
|
-
onClose?: Callback.Void;
|
|
17
|
-
onClosed?: Callback.Void;
|
|
18
|
-
disableDismiss?: boolean;
|
|
19
|
-
};
|
|
20
|
-
type Animation = {
|
|
21
|
-
initial: Variant;
|
|
22
|
-
open: Variant;
|
|
23
|
-
close: Variant;
|
|
24
|
-
};
|
|
25
|
-
namespace Animation {
|
|
26
|
-
type Variant = keyof Animation;
|
|
27
|
-
const slideUp: Animation;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Modal = Modal;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
9
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
10
|
-
const framer_motion_1 = require("framer-motion");
|
|
11
|
-
const react_1 = require("react");
|
|
12
|
-
const react_dom_1 = require("react-dom");
|
|
13
|
-
const rxjs_1 = require("rxjs");
|
|
14
|
-
const backdrop_1 = require("../backdrop");
|
|
15
|
-
const ClickObserver_1 = require("../ClickObserver");
|
|
16
|
-
const ModalContext_1 = require("./ModalContext");
|
|
17
|
-
const ModalEvent_1 = require("./ModalEvent");
|
|
18
|
-
// component
|
|
19
|
-
function Modal({ className, level = 'l1', animation = Modal.Animation.slideUp, open = false, onOpened: onOpenedRaw = funnel_core_1.Fn.NoOp, onActiveChanged: onActiveChangedRaw = funnel_core_1.Fn.NoOp, onClose = funnel_core_1.Fn.NoOp, onClosed: onClosedRaw = funnel_core_1.Fn.NoOp, disableDismiss = false, children }) {
|
|
20
|
-
// bind context
|
|
21
|
-
const [active, setActive] = (0, react_1.useState)(false);
|
|
22
|
-
const { eventBus } = (0, react_1.useContext)(ModalContext_1.ModalContext);
|
|
23
|
-
const backdrop = (0, backdrop_1.useBackdrop)();
|
|
24
|
-
const openRef = (0, react_1.useRef)(false);
|
|
25
|
-
const onOpenedRef = (0, react_1.useRef)(onOpenedRaw);
|
|
26
|
-
onOpenedRef.current = onOpenedRaw;
|
|
27
|
-
const onActiveChangedRef = (0, react_1.useRef)(onActiveChangedRaw);
|
|
28
|
-
onActiveChangedRef.current = onActiveChangedRaw;
|
|
29
|
-
const onClosedRef = (0, react_1.useRef)(onClosedRaw);
|
|
30
|
-
onClosedRef.current = onClosedRaw;
|
|
31
|
-
// show/hide based on open change
|
|
32
|
-
(0, react_1.useEffect)(() => {
|
|
33
|
-
// raise open event
|
|
34
|
-
const { id } = backdrop;
|
|
35
|
-
if (open) {
|
|
36
|
-
// update ref
|
|
37
|
-
openRef.current = true;
|
|
38
|
-
// raise event
|
|
39
|
-
eventBus.next(ModalEvent_1.ModalEvent.Open.create(id, disableDismiss));
|
|
40
|
-
// raise backdrop event
|
|
41
|
-
backdrop.show({ level });
|
|
42
|
-
// activate
|
|
43
|
-
setActive(true);
|
|
44
|
-
}
|
|
45
|
-
// raise or close event (if it was actually opened)
|
|
46
|
-
else if (openRef.current) {
|
|
47
|
-
// deactivate
|
|
48
|
-
setActive(false);
|
|
49
|
-
// update ref
|
|
50
|
-
openRef.current = false;
|
|
51
|
-
// raise event
|
|
52
|
-
eventBus.next({
|
|
53
|
-
id,
|
|
54
|
-
action: 'close'
|
|
55
|
-
});
|
|
56
|
-
// raise backdrop event
|
|
57
|
-
backdrop.hide();
|
|
58
|
-
}
|
|
59
|
-
}, [eventBus, backdrop, level, open, disableDismiss]);
|
|
60
|
-
// listen to activations or dismiss
|
|
61
|
-
(0, react_1.useEffect)(() => {
|
|
62
|
-
// listen for events
|
|
63
|
-
const subscription = eventBus
|
|
64
|
-
// filter only relevant events
|
|
65
|
-
.pipe((0, rxjs_1.filter)(({ id, action }) => id === backdrop.id
|
|
66
|
-
&& (action === 'activate' || action === 'deactivate' || action === 'dismiss')))
|
|
67
|
-
.subscribe(({ action }) => {
|
|
68
|
-
// close on dismiss
|
|
69
|
-
if (action === 'dismiss') {
|
|
70
|
-
onClose();
|
|
71
|
-
}
|
|
72
|
-
// or activate/deactivate
|
|
73
|
-
else {
|
|
74
|
-
setActive(action === 'activate');
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
// unsubscribe on unmount
|
|
78
|
-
return () => subscription.unsubscribe();
|
|
79
|
-
}, [eventBus, backdrop, onClose]);
|
|
80
|
-
// raise activated event
|
|
81
|
-
(0, react_1.useEffect)(() => {
|
|
82
|
-
onActiveChangedRef.current(active);
|
|
83
|
-
}, [active]);
|
|
84
|
-
// skip for SSR
|
|
85
|
-
if (!funnel_core_1.Browser.available) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
// helpers
|
|
89
|
-
const onAnimationComplete = (definition) => {
|
|
90
|
-
if (definition === 'open') {
|
|
91
|
-
onOpenedRef.current();
|
|
92
|
-
}
|
|
93
|
-
else if (definition === 'close') {
|
|
94
|
-
onClosedRef.current();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
// render
|
|
98
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { mode: "wait", children: open &&
|
|
99
|
-
(0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { id: backdrop.id, className: (0, classnames_1.default)('Modal-wrap', {
|
|
100
|
-
'Modal-l1': level === 'l1',
|
|
101
|
-
'Modal-l2': level === 'l2',
|
|
102
|
-
'Modal-l3': level === 'l3',
|
|
103
|
-
}), variants: animation, initial: "initial", animate: "open", exit: "close", onAnimationComplete: definition => onAnimationComplete(definition), children: (0, jsx_runtime_1.jsx)(ClickObserver_1.ClickObserver, { disabled: disableDismiss, onClickOutside: onClose, children: (0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(className, 'Modal-root'), children: children }) }) }, backdrop.id) }), document.body) }));
|
|
104
|
-
}
|
|
105
|
-
// extension
|
|
106
|
-
(function (Modal) {
|
|
107
|
-
let Animation;
|
|
108
|
-
(function (Animation) {
|
|
109
|
-
// slide up
|
|
110
|
-
Animation.slideUp = {
|
|
111
|
-
initial: {
|
|
112
|
-
opacity: 0,
|
|
113
|
-
y: 100
|
|
114
|
-
},
|
|
115
|
-
open: {
|
|
116
|
-
opacity: 1,
|
|
117
|
-
y: 0,
|
|
118
|
-
transition: {
|
|
119
|
-
ease: 'easeIn',
|
|
120
|
-
duration: 0.3,
|
|
121
|
-
when: 'beforeChildren'
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
close: {
|
|
125
|
-
opacity: 0,
|
|
126
|
-
y: 50,
|
|
127
|
-
transition: {
|
|
128
|
-
ease: 'easeOut',
|
|
129
|
-
duration: 0.15,
|
|
130
|
-
bounce: 0,
|
|
131
|
-
when: 'afterChildren'
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
})(Animation = Modal.Animation || (Modal.Animation = {}));
|
|
136
|
-
})(Modal || (exports.Modal = Modal = {}));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
export declare function ModalContainer({ children }: ModalContainer.Props): string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
3
|
-
export declare namespace ModalContainer {
|
|
4
|
-
type Props = PropsWithChildren;
|
|
5
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModalContainer = ModalContainer;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const react_hotkeys_hook_1 = require("react-hotkeys-hook");
|
|
8
|
-
const rxjs_1 = require("rxjs");
|
|
9
|
-
const ModalContext_1 = require("./ModalContext");
|
|
10
|
-
const ModalEvent_1 = require("./ModalEvent");
|
|
11
|
-
// component
|
|
12
|
-
function ModalContainer({ children }) {
|
|
13
|
-
// bind context
|
|
14
|
-
const [modal, setModal] = (0, react_1.useState)();
|
|
15
|
-
const context = (0, react_1.useMemo)(() => ({
|
|
16
|
-
eventBus: new rxjs_1.Subject()
|
|
17
|
-
}), []);
|
|
18
|
-
const modalsRef = (0, react_1.useRef)([]);
|
|
19
|
-
// update modal state based on show/hide
|
|
20
|
-
(0, react_1.useEffect)(() => {
|
|
21
|
-
// subscribe to open/close events
|
|
22
|
-
const { eventBus } = context;
|
|
23
|
-
const subscription = eventBus
|
|
24
|
-
.pipe((0, rxjs_1.filter)(({ action }) => action === 'open' || action === 'close'))
|
|
25
|
-
.subscribe(event => {
|
|
26
|
-
// handle open
|
|
27
|
-
const { id: modalId, action } = event;
|
|
28
|
-
const modals = modalsRef.current;
|
|
29
|
-
if (ModalEvent_1.ModalEvent.Open.guard(event)) {
|
|
30
|
-
// deactivate current modal (if any)
|
|
31
|
-
const activeModal = getActiveModal(modals);
|
|
32
|
-
if (activeModal) {
|
|
33
|
-
eventBus.next(ModalEvent_1.ModalEvent.Deactivate.create(activeModal.id));
|
|
34
|
-
}
|
|
35
|
-
// track new modal
|
|
36
|
-
const config = {
|
|
37
|
-
id: modalId,
|
|
38
|
-
dismissible: !event.disableDismiss
|
|
39
|
-
};
|
|
40
|
-
modals.push(config);
|
|
41
|
-
// activate modal
|
|
42
|
-
setModal(config);
|
|
43
|
-
}
|
|
44
|
-
// handle close
|
|
45
|
-
else if (action === 'close') {
|
|
46
|
-
// find modal (fail if it's not tracked)
|
|
47
|
-
const modalIndex = modals.findIndex(({ id }) => id === modalId);
|
|
48
|
-
if (modalIndex < 0) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// untrack modal
|
|
52
|
-
modals.splice(modalIndex, 1);
|
|
53
|
-
// reactivate previous modal (if any)
|
|
54
|
-
const activeModal = getActiveModal(modals);
|
|
55
|
-
if (activeModal) {
|
|
56
|
-
// update state
|
|
57
|
-
setModal(activeModal);
|
|
58
|
-
// reactivate
|
|
59
|
-
eventBus.next(ModalEvent_1.ModalEvent.Activate.create(activeModal.id));
|
|
60
|
-
}
|
|
61
|
-
// or unlock ui
|
|
62
|
-
else {
|
|
63
|
-
setModal(undefined);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
// unmount
|
|
68
|
-
return () => subscription.unsubscribe();
|
|
69
|
-
}, [context]);
|
|
70
|
-
// handle lock/unlock of ui
|
|
71
|
-
(0, react_1.useEffect)(() => {
|
|
72
|
-
// handle ui lock
|
|
73
|
-
let unlock = undefined;
|
|
74
|
-
if (modal) {
|
|
75
|
-
unlock = funnel_core_1.Browser.lockFocus(`#${CSS.escape(modal.id)}`);
|
|
76
|
-
}
|
|
77
|
-
// unlock on unmount (if locked)
|
|
78
|
-
return () => unlock && unlock();
|
|
79
|
-
}, [modal]);
|
|
80
|
-
// close on escape
|
|
81
|
-
(0, react_hotkeys_hook_1.useHotkeys)('esc', () => {
|
|
82
|
-
// ignore if not dismissible
|
|
83
|
-
if (!modal || !modal.dismissible) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// send dismiss event (modal should dismiss via 'close' event)
|
|
87
|
-
context.eventBus.next(ModalEvent_1.ModalEvent.Dismiss.create(modal.id));
|
|
88
|
-
}, {
|
|
89
|
-
enabled: (modal === null || modal === void 0 ? void 0 : modal.dismissible) === true,
|
|
90
|
-
enableOnFormTags: ['input', 'textarea']
|
|
91
|
-
}, [modal]);
|
|
92
|
-
// skip for SSR
|
|
93
|
-
if (!funnel_core_1.Browser.available) {
|
|
94
|
-
return children;
|
|
95
|
-
}
|
|
96
|
-
// render
|
|
97
|
-
return ((0, jsx_runtime_1.jsx)(ModalContext_1.ModalContext.Provider, { value: context, children: children }));
|
|
98
|
-
}
|
|
99
|
-
function getActiveModal(modals) {
|
|
100
|
-
const modalCount = modals.length;
|
|
101
|
-
return modalCount > 0
|
|
102
|
-
? modals[modalCount - 1]
|
|
103
|
-
: undefined;
|
|
104
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Modal } from './Modal';
|
|
2
|
-
export type ModalEvent = ModalEvent.Open | ModalEvent.Activate | ModalEvent.Deactivate | ModalEvent.Dismiss | ModalEvent.Close;
|
|
3
|
-
export declare namespace ModalEvent {
|
|
4
|
-
export type Action = 'open' | 'activate' | 'deactivate' | 'dismiss' | 'close';
|
|
5
|
-
interface Base {
|
|
6
|
-
id: Modal.Id;
|
|
7
|
-
action: ModalEvent.Action;
|
|
8
|
-
}
|
|
9
|
-
export interface Open extends Base {
|
|
10
|
-
action: 'open';
|
|
11
|
-
disableDismiss: boolean;
|
|
12
|
-
}
|
|
13
|
-
export namespace Open {
|
|
14
|
-
function guard(event: ModalEvent): event is Open;
|
|
15
|
-
function create(id: Modal.Id, disableDismiss?: boolean): Open;
|
|
16
|
-
}
|
|
17
|
-
export interface Activate extends Base {
|
|
18
|
-
action: 'activate';
|
|
19
|
-
}
|
|
20
|
-
export namespace Activate {
|
|
21
|
-
function create(id: Modal.Id): Activate;
|
|
22
|
-
}
|
|
23
|
-
export interface Deactivate extends Base {
|
|
24
|
-
action: 'deactivate';
|
|
25
|
-
}
|
|
26
|
-
export namespace Deactivate {
|
|
27
|
-
function create(id: Modal.Id): Deactivate;
|
|
28
|
-
}
|
|
29
|
-
export interface Dismiss extends Base {
|
|
30
|
-
action: 'dismiss';
|
|
31
|
-
}
|
|
32
|
-
export namespace Dismiss {
|
|
33
|
-
function create(id: Modal.Id): Dismiss;
|
|
34
|
-
}
|
|
35
|
-
export interface Close extends Base {
|
|
36
|
-
action: 'close';
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
39
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModalEvent = void 0;
|
|
4
|
-
// extension
|
|
5
|
-
var ModalEvent;
|
|
6
|
-
(function (ModalEvent) {
|
|
7
|
-
let Open;
|
|
8
|
-
(function (Open) {
|
|
9
|
-
// helpers
|
|
10
|
-
function guard(event) {
|
|
11
|
-
return event.action === 'open';
|
|
12
|
-
}
|
|
13
|
-
Open.guard = guard;
|
|
14
|
-
function create(id, disableDismiss = false) {
|
|
15
|
-
return {
|
|
16
|
-
id,
|
|
17
|
-
action: 'open',
|
|
18
|
-
disableDismiss
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
Open.create = create;
|
|
22
|
-
})(Open = ModalEvent.Open || (ModalEvent.Open = {}));
|
|
23
|
-
let Activate;
|
|
24
|
-
(function (Activate) {
|
|
25
|
-
function create(id) {
|
|
26
|
-
return {
|
|
27
|
-
id,
|
|
28
|
-
action: 'activate'
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
Activate.create = create;
|
|
32
|
-
})(Activate = ModalEvent.Activate || (ModalEvent.Activate = {}));
|
|
33
|
-
let Deactivate;
|
|
34
|
-
(function (Deactivate) {
|
|
35
|
-
function create(id) {
|
|
36
|
-
return {
|
|
37
|
-
id,
|
|
38
|
-
action: 'deactivate'
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
Deactivate.create = create;
|
|
42
|
-
})(Deactivate = ModalEvent.Deactivate || (ModalEvent.Deactivate = {}));
|
|
43
|
-
let Dismiss;
|
|
44
|
-
(function (Dismiss) {
|
|
45
|
-
function create(id) {
|
|
46
|
-
return {
|
|
47
|
-
id,
|
|
48
|
-
action: 'dismiss'
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
Dismiss.create = create;
|
|
52
|
-
})(Dismiss = ModalEvent.Dismiss || (ModalEvent.Dismiss = {}));
|
|
53
|
-
})(ModalEvent || (exports.ModalEvent = ModalEvent = {}));
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Modal"), exports);
|
|
18
|
-
__exportStar(require("./ModalContainer"), exports);
|