@servicetitan/confirm-navigation 31.2.0 → 31.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/dist/confirm-navigation.js +126 -148
- package/dist/confirm-navigation.js.map +1 -1
- package/dist/demo/basic.js +15 -3
- package/dist/demo/basic.js.map +1 -1
- package/dist/demo/custom.js +41 -5
- package/dist/demo/custom.js.map +1 -1
- package/dist/demo/ignore-search-changes-example.js +44 -6
- package/dist/demo/ignore-search-changes-example.js.map +1 -1
- package/dist/demo/index.js +1 -0
- package/dist/demo/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/confirm-navigation.stories.js +0 -17
- package/dist/confirm-navigation.stories.js.map +0 -1
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
8
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
22
|
+
}
|
|
10
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
24
|
import { Component } from 'react';
|
|
12
25
|
import { withRouter } from 'react-router-dom';
|
|
@@ -15,132 +28,27 @@ import { observer } from 'mobx-react';
|
|
|
15
28
|
import { Dialog } from '@servicetitan/design-system';
|
|
16
29
|
import { injectDependency, optional } from '@servicetitan/react-ioc';
|
|
17
30
|
import { HistoryManager } from '@servicetitan/web-components';
|
|
18
|
-
const DefaultConfirmComponent = ({ title, description, isOpen, onConfirm, onCancel
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: false
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(this, "suspended", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
value: void 0
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(this, "unblock", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true,
|
|
44
|
-
value: void 0
|
|
45
|
-
});
|
|
46
|
-
// We should terminate Sammy navigation and fix URL of the current page
|
|
47
|
-
Object.defineProperty(this, "onBefore", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true,
|
|
51
|
-
value: () => {
|
|
52
|
-
if (this.isOpen && this.suspended) {
|
|
53
|
-
this.isRedirecting = true;
|
|
54
|
-
window.App.Instance.setLocation('#' + this.suspended.currentLocation.pathname);
|
|
55
|
-
}
|
|
56
|
-
return !this.isOpen;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(this, "block", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: () => {
|
|
64
|
-
var _a, _b;
|
|
65
|
-
const getTransitionHook = (history) => {
|
|
66
|
-
return (targetLocation) => {
|
|
67
|
-
// We shouldn't memorize new locations if it is navigation just for fix URL of the current page
|
|
68
|
-
if (this.isRedirecting) {
|
|
69
|
-
this.isRedirecting = false;
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
const hasChanged = history.location.pathname !== targetLocation.pathname ||
|
|
73
|
-
(!this.props.ignoreSearchChanges &&
|
|
74
|
-
history.location.search !== targetLocation.search);
|
|
75
|
-
if (hasChanged) {
|
|
76
|
-
runInAction(() => {
|
|
77
|
-
this.isOpen = true;
|
|
78
|
-
this.suspended = {
|
|
79
|
-
history,
|
|
80
|
-
targetLocation,
|
|
81
|
-
currentLocation: history.location,
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
const { history } = this.props;
|
|
89
|
-
const unblock = history.block(getTransitionHook(history));
|
|
90
|
-
const restUnblocks = Array.from((_b = (_a = this.historyManager) === null || _a === void 0 ? void 0 : _a.storage.keys()) !== null && _b !== void 0 ? _b : [])
|
|
91
|
-
.filter(item => item !== history)
|
|
92
|
-
.map(history => history.block(getTransitionHook(history)));
|
|
93
|
-
this.unblock = () => {
|
|
94
|
-
for (const unblock of restUnblocks) {
|
|
95
|
-
unblock();
|
|
96
|
-
}
|
|
97
|
-
unblock();
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(this, "handleConfirm", {
|
|
102
|
-
enumerable: true,
|
|
103
|
-
configurable: true,
|
|
104
|
-
writable: true,
|
|
105
|
-
value: () => {
|
|
106
|
-
if (!this.suspended) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const { history, currentLocation, targetLocation } = this.suspended;
|
|
110
|
-
this.reset();
|
|
111
|
-
this.unblock();
|
|
112
|
-
// Fixing URL of the current page if it was changed manually
|
|
113
|
-
history.replace(currentLocation.pathname + currentLocation.search);
|
|
114
|
-
history.push(targetLocation);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(this, "handleCancel", {
|
|
118
|
-
enumerable: true,
|
|
119
|
-
configurable: true,
|
|
120
|
-
writable: true,
|
|
121
|
-
value: () => {
|
|
122
|
-
if (!this.suspended) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const { history, currentLocation } = this.suspended;
|
|
126
|
-
this.reset();
|
|
127
|
-
this.unblock();
|
|
128
|
-
// Fixing URL of the current page if it was changed manually
|
|
129
|
-
history.replace(currentLocation.pathname + currentLocation.search);
|
|
130
|
-
this.block();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
makeObservable(this);
|
|
134
|
-
}
|
|
31
|
+
const DefaultConfirmComponent = ({ title, description, isOpen, onConfirm, onCancel })=>/*#__PURE__*/ _jsx(Dialog, {
|
|
32
|
+
negative: true,
|
|
33
|
+
open: isOpen,
|
|
34
|
+
title: title,
|
|
35
|
+
onPrimaryActionClick: onConfirm,
|
|
36
|
+
primaryActionName: "Leave",
|
|
37
|
+
onSecondaryActionClick: onCancel,
|
|
38
|
+
secondaryActionName: "Stay",
|
|
39
|
+
onClose: onCancel,
|
|
40
|
+
children: description
|
|
41
|
+
});
|
|
42
|
+
class ConfirmNavigationUnwrapped extends Component {
|
|
135
43
|
reset() {
|
|
136
44
|
this.isOpen = false;
|
|
137
45
|
this.isRedirecting = false;
|
|
138
46
|
this.suspended = undefined;
|
|
139
47
|
}
|
|
140
48
|
componentDidMount() {
|
|
141
|
-
var
|
|
49
|
+
var _window_App_Instance, _window_App;
|
|
142
50
|
this.block();
|
|
143
|
-
if ((
|
|
51
|
+
if ((_window_App = window.App) === null || _window_App === void 0 ? void 0 : (_window_App_Instance = _window_App.Instance) === null || _window_App_Instance === void 0 ? void 0 : _window_App_Instance.before) {
|
|
144
52
|
window.App.Instance.before(this.onBefore);
|
|
145
53
|
}
|
|
146
54
|
}
|
|
@@ -153,44 +61,114 @@ let ConfirmNavigationUnwrapped = class ConfirmNavigationUnwrapped extends Compon
|
|
|
153
61
|
}
|
|
154
62
|
}
|
|
155
63
|
componentWillUnmount() {
|
|
156
|
-
var
|
|
64
|
+
var _window_App_Instance, _window_App;
|
|
157
65
|
this.unblock();
|
|
158
|
-
if ((
|
|
159
|
-
window.App.Instance.befores = window.App.Instance.befores.filter(([, callback])
|
|
66
|
+
if ((_window_App = window.App) === null || _window_App === void 0 ? void 0 : (_window_App_Instance = _window_App.Instance) === null || _window_App_Instance === void 0 ? void 0 : _window_App_Instance.befores) {
|
|
67
|
+
window.App.Instance.befores = window.App.Instance.befores.filter(([, callback])=>callback !== this.onBefore);
|
|
160
68
|
}
|
|
161
69
|
}
|
|
162
70
|
render() {
|
|
163
71
|
const { title, description, component: Component = DefaultConfirmComponent } = this.props;
|
|
164
|
-
return
|
|
72
|
+
return /*#__PURE__*/ _jsx(Component, {
|
|
73
|
+
isOpen: this.isOpen,
|
|
74
|
+
title: title,
|
|
75
|
+
description: description,
|
|
76
|
+
onConfirm: this.handleConfirm,
|
|
77
|
+
onCancel: this.handleCancel
|
|
78
|
+
});
|
|
165
79
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
80
|
+
constructor(props){
|
|
81
|
+
super(props), _define_property(this, "isOpen", false), _define_property(this, "isRedirecting", false), _define_property(this, "suspended", void 0), _define_property(this, "unblock", void 0), // We should terminate Sammy navigation and fix URL of the current page
|
|
82
|
+
_define_property(this, "onBefore", ()=>{
|
|
83
|
+
if (this.isOpen && this.suspended) {
|
|
84
|
+
this.isRedirecting = true;
|
|
85
|
+
window.App.Instance.setLocation('#' + this.suspended.currentLocation.pathname);
|
|
86
|
+
}
|
|
87
|
+
return !this.isOpen;
|
|
88
|
+
}), _define_property(this, "block", ()=>{
|
|
89
|
+
var _this_historyManager;
|
|
90
|
+
const getTransitionHook = (history)=>{
|
|
91
|
+
return (targetLocation)=>{
|
|
92
|
+
// We shouldn't memorize new locations if it is navigation just for fix URL of the current page
|
|
93
|
+
if (this.isRedirecting) {
|
|
94
|
+
this.isRedirecting = false;
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
const hasChanged = history.location.pathname !== targetLocation.pathname || !this.props.ignoreSearchChanges && history.location.search !== targetLocation.search;
|
|
98
|
+
if (hasChanged) {
|
|
99
|
+
runInAction(()=>{
|
|
100
|
+
this.isOpen = true;
|
|
101
|
+
this.suspended = {
|
|
102
|
+
history,
|
|
103
|
+
targetLocation,
|
|
104
|
+
currentLocation: history.location
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const { history } = this.props;
|
|
112
|
+
const unblock = history.block(getTransitionHook(history));
|
|
113
|
+
var _this_historyManager_storage_keys;
|
|
114
|
+
const restUnblocks = Array.from((_this_historyManager_storage_keys = (_this_historyManager = this.historyManager) === null || _this_historyManager === void 0 ? void 0 : _this_historyManager.storage.keys()) !== null && _this_historyManager_storage_keys !== void 0 ? _this_historyManager_storage_keys : []).filter((item)=>item !== history).map((history)=>history.block(getTransitionHook(history)));
|
|
115
|
+
this.unblock = ()=>{
|
|
116
|
+
for (const unblock of restUnblocks){
|
|
117
|
+
unblock();
|
|
118
|
+
}
|
|
119
|
+
unblock();
|
|
120
|
+
};
|
|
121
|
+
}), _define_property(this, "handleConfirm", ()=>{
|
|
122
|
+
if (!this.suspended) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { history, currentLocation, targetLocation } = this.suspended;
|
|
126
|
+
this.reset();
|
|
127
|
+
this.unblock();
|
|
128
|
+
// Fixing URL of the current page if it was changed manually
|
|
129
|
+
history.replace(currentLocation.pathname + currentLocation.search);
|
|
130
|
+
history.push(targetLocation);
|
|
131
|
+
}), _define_property(this, "handleCancel", ()=>{
|
|
132
|
+
if (!this.suspended) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { history, currentLocation } = this.suspended;
|
|
136
|
+
this.reset();
|
|
137
|
+
this.unblock();
|
|
138
|
+
// Fixing URL of the current page if it was changed manually
|
|
139
|
+
history.replace(currentLocation.pathname + currentLocation.search);
|
|
140
|
+
this.block();
|
|
141
|
+
});
|
|
142
|
+
makeObservable(this);
|
|
174
143
|
}
|
|
144
|
+
}
|
|
145
|
+
_define_property(ConfirmNavigationUnwrapped, "defaultProps", {
|
|
146
|
+
title: 'Are you sure you want to leave?',
|
|
147
|
+
description: "You'll lose all your changes if you do."
|
|
175
148
|
});
|
|
176
|
-
|
|
149
|
+
_ts_decorate([
|
|
177
150
|
optional(),
|
|
178
151
|
injectDependency(HistoryManager),
|
|
179
|
-
|
|
152
|
+
_ts_metadata("design:type", typeof HistoryManager === "undefined" ? Object : HistoryManager)
|
|
180
153
|
], ConfirmNavigationUnwrapped.prototype, "historyManager", void 0);
|
|
181
|
-
|
|
182
|
-
observable
|
|
183
|
-
__metadata("design:type", Object)
|
|
154
|
+
_ts_decorate([
|
|
155
|
+
observable
|
|
184
156
|
], ConfirmNavigationUnwrapped.prototype, "isOpen", void 0);
|
|
185
|
-
|
|
157
|
+
_ts_decorate([
|
|
186
158
|
action,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
159
|
+
_ts_metadata("design:type", Function),
|
|
160
|
+
_ts_metadata("design:paramtypes", []),
|
|
161
|
+
_ts_metadata("design:returntype", void 0)
|
|
190
162
|
], ConfirmNavigationUnwrapped.prototype, "reset", null);
|
|
191
|
-
ConfirmNavigationUnwrapped =
|
|
163
|
+
ConfirmNavigationUnwrapped = _ts_decorate([
|
|
192
164
|
observer,
|
|
193
|
-
|
|
165
|
+
_ts_metadata("design:type", Function),
|
|
166
|
+
_ts_metadata("design:paramtypes", [
|
|
167
|
+
typeof ConfirmNavigationProps === "undefined" ? Object : ConfirmNavigationProps
|
|
168
|
+
])
|
|
194
169
|
], ConfirmNavigationUnwrapped);
|
|
195
|
-
export const ConfirmNavigation = withRouter(({ when = true, ...props })
|
|
170
|
+
export const ConfirmNavigation = withRouter(({ when = true, ...props })=>when ? /*#__PURE__*/ _jsx(ConfirmNavigationUnwrapped, {
|
|
171
|
+
...props
|
|
172
|
+
}) : null);
|
|
173
|
+
|
|
196
174
|
//# sourceMappingURL=confirm-navigation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirm-navigation.js","sourceRoot":"","sources":["../src/confirm-navigation.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AA2B9D,MAAM,uBAAuB,GAAqC,CAAC,EAC/D,KAAK,EACL,WAAW,EACX,MAAM,EACN,SAAS,EACT,QAAQ,GACX,EAAE,EAAE,CAAC,CACF,KAAC,MAAM,IACH,QAAQ,QACR,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,EACZ,oBAAoB,EAAE,SAAS,EAC/B,iBAAiB,EAAC,OAAO,EACzB,sBAAsB,EAAE,QAAQ,EAChC,mBAAmB,EAAC,MAAM,EAC1B,OAAO,EAAE,QAAQ,YAEhB,WAAW,GAC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} from 'react';\nimport { withRouter, RouteComponentProps } from 'react-router-dom';\n\nimport { observable, action, runInAction, comparer, makeObservable } from 'mobx';\nimport { observer } from 'mobx-react';\n\nimport { History, Location, UnregisterCallback } from 'history';\n\nimport { Dialog } from '@servicetitan/design-system';\n\nimport { injectDependency, optional } from '@servicetitan/react-ioc';\nimport { HistoryManager } from '@servicetitan/web-components';\n\n// TODO: refactor this. External package should not do any assumptions about window.App.\ndeclare global {\n export interface Window {\n App: any;\n }\n}\n\ninterface ConfirmNavigationRenderProps {\n isOpen: boolean;\n title?: string;\n description?: string;\n onConfirm(): void;\n onCancel(): void;\n}\n\nexport interface ConfirmNavigationOwnProps {\n when?: boolean;\n ignoreSearchChanges?: boolean;\n title?: string;\n description?: string;\n component?: ComponentType<ConfirmNavigationRenderProps> | FC<ConfirmNavigationRenderProps>;\n}\n\nexport type ConfirmNavigationProps = ConfirmNavigationOwnProps & RouteComponentProps;\n\nconst DefaultConfirmComponent: FC<ConfirmNavigationRenderProps> = ({\n title,\n description,\n isOpen,\n onConfirm,\n onCancel,\n}) => (\n <Dialog\n negative\n open={isOpen}\n title={title}\n onPrimaryActionClick={onConfirm}\n primaryActionName=\"Leave\"\n onSecondaryActionClick={onCancel}\n secondaryActionName=\"Stay\"\n onClose={onCancel}\n >\n {description}\n </Dialog>\n);\n\n@observer\nclass ConfirmNavigationUnwrapped extends Component<ConfirmNavigationProps> {\n static defaultProps: Partial<ConfirmNavigationProps> = {\n title: 'Are you sure you want to leave?',\n description: \"You'll lose all your changes if you do.\",\n };\n\n @optional()\n @injectDependency(HistoryManager)\n declare historyManager?: HistoryManager;\n\n @observable isOpen = false;\n\n isRedirecting = false;\n\n suspended?: {\n history: History;\n currentLocation: Location;\n targetLocation: Location;\n };\n\n unblock!: UnregisterCallback;\n\n constructor(props: ConfirmNavigationProps) {\n super(props);\n makeObservable(this);\n }\n\n @action\n reset() {\n this.isOpen = false;\n this.isRedirecting = false;\n this.suspended = undefined;\n }\n\n componentDidMount() {\n this.block();\n\n if (window.App?.Instance?.before) {\n window.App.Instance.before(this.onBefore);\n }\n }\n\n componentDidUpdate(prevProps: RouteComponentProps) {\n const { history: prevHistory } = prevProps;\n const { history } = this.props;\n\n if (!comparer.structural(prevHistory.location, history.location)) {\n this.unblock();\n this.block();\n }\n }\n\n componentWillUnmount() {\n this.unblock();\n\n if (window.App?.Instance?.befores) {\n window.App.Instance.befores = window.App.Instance.befores.filter(\n ([, callback]: [any, Function]) => callback !== this.onBefore\n );\n }\n }\n\n // We should terminate Sammy navigation and fix URL of the current page\n onBefore = () => {\n if (this.isOpen && this.suspended) {\n this.isRedirecting = true;\n window.App.Instance.setLocation('#' + this.suspended.currentLocation.pathname);\n }\n\n return !this.isOpen;\n };\n\n block = () => {\n const getTransitionHook = (history: History) => {\n return (targetLocation: Location) => {\n // We shouldn't memorize new locations if it is navigation just for fix URL of the current page\n if (this.isRedirecting) {\n this.isRedirecting = false;\n return false;\n }\n\n const hasChanged =\n history.location.pathname !== targetLocation.pathname ||\n (!this.props.ignoreSearchChanges &&\n history.location.search !== targetLocation.search);\n\n if (hasChanged) {\n runInAction(() => {\n this.isOpen = true;\n this.suspended = {\n history,\n targetLocation,\n currentLocation: history.location,\n };\n });\n\n return false;\n }\n };\n };\n\n const { history } = this.props;\n\n const unblock = history.block(getTransitionHook(history));\n const restUnblocks = Array.from(this.historyManager?.storage.keys() ?? [])\n .filter(item => item !== history)\n .map(history => history.block(getTransitionHook(history)));\n\n this.unblock = () => {\n for (const unblock of restUnblocks) {\n unblock();\n }\n\n unblock();\n };\n };\n\n handleConfirm = () => {\n if (!this.suspended) {\n return;\n }\n\n const { history, currentLocation, targetLocation } = this.suspended;\n\n this.reset();\n\n this.unblock();\n // Fixing URL of the current page if it was changed manually\n history.replace(currentLocation.pathname + currentLocation.search);\n history.push(targetLocation);\n };\n\n handleCancel = () => {\n if (!this.suspended) {\n return;\n }\n\n const { history, currentLocation } = this.suspended;\n\n this.reset();\n\n this.unblock();\n // Fixing URL of the current page if it was changed manually\n history.replace(currentLocation.pathname + currentLocation.search);\n this.block();\n };\n\n render() {\n const { title, description, component: Component = DefaultConfirmComponent } = this.props;\n\n return (\n <Component\n isOpen={this.isOpen}\n title={title}\n description={description}\n onConfirm={this.handleConfirm}\n onCancel={this.handleCancel}\n />\n );\n }\n}\n\nexport const ConfirmNavigation = withRouter(({ when = true, ...props }: ConfirmNavigationProps) =>\n when ? <ConfirmNavigationUnwrapped {...props} /> : null\n);\n"],"names":["Component","withRouter","observable","action","runInAction","comparer","makeObservable","observer","Dialog","injectDependency","optional","HistoryManager","DefaultConfirmComponent","title","description","isOpen","onConfirm","onCancel","negative","open","onPrimaryActionClick","primaryActionName","onSecondaryActionClick","secondaryActionName","onClose","ConfirmNavigationUnwrapped","reset","isRedirecting","suspended","undefined","componentDidMount","window","block","App","Instance","before","onBefore","componentDidUpdate","prevProps","history","prevHistory","props","structural","location","unblock","componentWillUnmount","befores","filter","callback","render","component","handleConfirm","handleCancel","constructor","setLocation","currentLocation","pathname","getTransitionHook","targetLocation","hasChanged","ignoreSearchChanges","search","restUnblocks","Array","from","historyManager","storage","keys","item","map","replace","push","defaultProps","ConfirmNavigation","when"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,SAAS,QAA2B,QAAQ;AACrD,SAASC,UAAU,QAA6B,mBAAmB;AAEnE,SAASC,UAAU,EAAEC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,OAAO;AACjF,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,MAAM,QAAQ,8BAA8B;AAErD,SAASC,gBAAgB,EAAEC,QAAQ,QAAQ,0BAA0B;AACrE,SAASC,cAAc,QAAQ,+BAA+B;AA2B9D,MAAMC,0BAA4D,CAAC,EAC/DC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,SAAS,EACTC,QAAQ,EACX,iBACG,KAACT;QACGU,QAAQ;QACRC,MAAMJ;QACNF,OAAOA;QACPO,sBAA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GAAGjC,OAA+B,GAC1FiC,qBAAO,KAACjD;QAA4B,GAAGgB,KAAK;SAAO,MACrD"}
|
package/dist/demo/basic.js
CHANGED
|
@@ -2,11 +2,23 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState, Fragment } from 'react';
|
|
3
3
|
import { Checkbox } from '@servicetitan/design-system';
|
|
4
4
|
import { ConfirmNavigation } from '..';
|
|
5
|
-
export const BasicExample = ()
|
|
5
|
+
export const BasicExample = ()=>{
|
|
6
6
|
const [confirm, setConfirm] = useState(true);
|
|
7
|
-
const handleChange = (_0, checked)
|
|
7
|
+
const handleChange = (_0, checked)=>{
|
|
8
8
|
setConfirm(checked);
|
|
9
9
|
};
|
|
10
|
-
return
|
|
10
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
11
|
+
children: [
|
|
12
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
13
|
+
label: "Confirm Navigation?",
|
|
14
|
+
checked: confirm,
|
|
15
|
+
onChange: handleChange
|
|
16
|
+
}),
|
|
17
|
+
/*#__PURE__*/ _jsx(ConfirmNavigation, {
|
|
18
|
+
when: confirm
|
|
19
|
+
})
|
|
20
|
+
]
|
|
21
|
+
});
|
|
11
22
|
};
|
|
23
|
+
|
|
12
24
|
//# sourceMappingURL=basic.js.map
|
package/dist/demo/basic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/demo/basic.tsx"],"sourcesContent":["import { useState, Fragment, FC } from 'react';\n\nimport { Checkbox } from '@servicetitan/design-system';\n\nimport { ConfirmNavigation } from '..';\n\nexport const BasicExample: FC = () => {\n const [confirm, setConfirm] = useState(true);\n\n const handleChange = (_0: never, checked: boolean) => {\n setConfirm(checked);\n };\n\n return (\n <Fragment>\n <Checkbox label=\"Confirm Navigation?\" checked={confirm} onChange={handleChange} />\n\n <ConfirmNavigation when={confirm} />\n </Fragment>\n );\n};\n"],"names":["useState","Fragment","Checkbox","ConfirmNavigation","BasicExample","confirm","setConfirm","handleChange","_0","checked","label","onChange","when"],"mappings":";AAAA,SAASA,QAAQ,EAAEC,QAAQ,QAAY,QAAQ;AAE/C,SAASC,QAAQ,QAAQ,8BAA8B;AAEvD,SAASC,iBAAiB,QAAQ,KAAK;AAEvC,OAAO,MAAMC,eAAmB;IAC5B,MAAM,CAACC,SAASC,WAAW,GAAGN,SAAS;IAEvC,MAAMO,eAAe,CAACC,IAAWC;QAC7BH,WAAWG;IACf;IAEA,qBACI,MAACR;;0BACG,KAACC;gBAASQ,OAAM;gBAAsBD,SAASJ;gBAASM,UAAUJ;;0BAElE,KAACJ;gBAAkBS,MAAMP;;;;AAGrC,EAAE"}
|
package/dist/demo/custom.js
CHANGED
|
@@ -2,13 +2,49 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState, Fragment } from 'react';
|
|
3
3
|
import { Checkbox, Modal, ButtonGroup, Button, BodyText } from '@servicetitan/design-system';
|
|
4
4
|
import { ConfirmNavigation } from '..';
|
|
5
|
-
export const CustomExample = ()
|
|
5
|
+
export const CustomExample = ()=>{
|
|
6
6
|
const [confirm, setConfirm] = useState(true);
|
|
7
|
-
const handleChange = (_0, checked)
|
|
7
|
+
const handleChange = (_0, checked)=>{
|
|
8
8
|
setConfirm(checked);
|
|
9
9
|
};
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
11
|
+
children: [
|
|
12
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
13
|
+
label: "Confirm Navigation?",
|
|
14
|
+
checked: confirm,
|
|
15
|
+
onChange: handleChange
|
|
16
|
+
}),
|
|
17
|
+
/*#__PURE__*/ _jsx(ConfirmNavigation, {
|
|
18
|
+
when: confirm,
|
|
19
|
+
title: "Are you sure you want to leave?",
|
|
20
|
+
description: "If you leave all changes will be lost.",
|
|
21
|
+
component: ({ isOpen, onCancel, onConfirm, title, description })=>{
|
|
22
|
+
return /*#__PURE__*/ _jsx(Modal, {
|
|
23
|
+
open: isOpen,
|
|
24
|
+
onClose: onCancel,
|
|
25
|
+
title: title,
|
|
26
|
+
footer: /*#__PURE__*/ _jsxs(ButtonGroup, {
|
|
27
|
+
children: [
|
|
28
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
29
|
+
onClick: onCancel,
|
|
30
|
+
children: "No, stay"
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
33
|
+
onClick: onConfirm,
|
|
34
|
+
color: "negative",
|
|
35
|
+
children: "Yes, leave"
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
}),
|
|
39
|
+
children: /*#__PURE__*/ _jsx(BodyText, {
|
|
40
|
+
subdued: true,
|
|
41
|
+
children: description
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
]
|
|
47
|
+
});
|
|
13
48
|
};
|
|
49
|
+
|
|
14
50
|
//# sourceMappingURL=custom.js.map
|
package/dist/demo/custom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/demo/custom.tsx"],"sourcesContent":["import { useState, Fragment, FC } from 'react';\n\nimport { Checkbox, Modal, ButtonGroup, Button, BodyText } from '@servicetitan/design-system';\n\nimport { ConfirmNavigation } from '..';\n\nexport const CustomExample: FC = () => {\n const [confirm, setConfirm] = useState(true);\n\n const handleChange = (_0: never, checked: boolean) => {\n setConfirm(checked);\n };\n\n return (\n <Fragment>\n <Checkbox label=\"Confirm Navigation?\" checked={confirm} onChange={handleChange} />\n\n <ConfirmNavigation\n when={confirm}\n title=\"Are you sure you want to leave?\"\n description=\"If you leave all changes will be lost.\"\n component={({ isOpen, onCancel, onConfirm, title, description }) => {\n return (\n <Modal\n open={isOpen}\n onClose={onCancel}\n title={title}\n footer={\n <ButtonGroup>\n <Button onClick={onCancel}>No, stay</Button>\n <Button onClick={onConfirm} color=\"negative\">\n Yes, leave\n </Button>\n </ButtonGroup>\n }\n >\n <BodyText subdued>{description}</BodyText>\n </Modal>\n );\n }}\n />\n </Fragment>\n );\n};\n"],"names":["useState","Fragment","Checkbox","Modal","ButtonGroup","Button","BodyText","ConfirmNavigation","CustomExample","confirm","setConfirm","handleChange","_0","checked","label","onChange","when","title","description","component","isOpen","onCancel","onConfirm","open","onClose","footer","onClick","color","subdued"],"mappings":";AAAA,SAASA,QAAQ,EAAEC,QAAQ,QAAY,QAAQ;AAE/C,SAASC,QAAQ,EAAEC,KAAK,EAAEC,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,8BAA8B;AAE7F,SAASC,iBAAiB,QAAQ,KAAK;AAEvC,OAAO,MAAMC,gBAAoB;IAC7B,MAAM,CAACC,SAASC,WAAW,GAAGV,SAAS;IAEvC,MAAMW,eAAe,CAACC,IAAWC;QAC7BH,WAAWG;IACf;IAEA,qBACI,MAACZ;;0BACG,KAACC;gBAASY,OAAM;gBAAsBD,SAASJ;gBAASM,UAAUJ;;0BAElE,KAACJ;gBACGS,MAAMP;gBACNQ,OAAM;gBACNC,aAAY;gBACZC,WAAW,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAEL,KAAK,EAAEC,WAAW,EAAE;oBAC3D,qBACI,KAACf;wBACGoB,MAAMH;wBACNI,SAASH;wBACTJ,OAAOA;wBACPQ,sBACI,MAACrB;;8CACG,KAACC;oCAAOqB,SAASL;8CAAU;;8CAC3B,KAAChB;oCAAOqB,SAASJ;oCAAWK,OAAM;8CAAW;;;;kCAMrD,cAAA,KAACrB;4BAASsB,OAAO;sCAAEV;;;gBAG/B;;;;AAIhB,EAAE"}
|
|
@@ -4,21 +4,59 @@ import { Link, useLocation } from 'react-router-dom';
|
|
|
4
4
|
import { Button, ButtonGroup, Checkbox } from '@servicetitan/design-system';
|
|
5
5
|
import { ConfirmNavigation } from '..';
|
|
6
6
|
//
|
|
7
|
-
export const IgnoreSearchChangesExample = ()
|
|
7
|
+
export const IgnoreSearchChangesExample = ()=>{
|
|
8
8
|
const [confirm, setConfirm] = useState(true);
|
|
9
|
-
const handleConfirmChange = (_0, checked)
|
|
9
|
+
const handleConfirmChange = (_0, checked)=>{
|
|
10
10
|
setConfirm(checked);
|
|
11
11
|
};
|
|
12
12
|
const [ignoreSearch, setIgnoreSearch] = useState(true);
|
|
13
|
-
const handleIgnoreSearchChange = (_0, checked)
|
|
13
|
+
const handleIgnoreSearchChange = (_0, checked)=>{
|
|
14
14
|
setIgnoreSearch(checked);
|
|
15
15
|
};
|
|
16
|
-
return
|
|
16
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
19
|
+
label: "Confirm Navigation?",
|
|
20
|
+
checked: confirm,
|
|
21
|
+
onChange: handleConfirmChange
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
24
|
+
label: "Ignore search changes?",
|
|
25
|
+
checked: ignoreSearch,
|
|
26
|
+
onChange: handleIgnoreSearchChange
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ _jsx(ConfirmNavigation, {
|
|
29
|
+
when: confirm,
|
|
30
|
+
ignoreSearchChanges: ignoreSearch
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ _jsx(AdvancedUrlChange, {})
|
|
33
|
+
]
|
|
34
|
+
});
|
|
17
35
|
};
|
|
18
|
-
const AdvancedUrlChange = ()
|
|
36
|
+
const AdvancedUrlChange = ()=>{
|
|
19
37
|
const location = useLocation();
|
|
20
38
|
const newPath = location.pathname === '/some-new-path-1' ? '/another-new-path-2' : '/some-new-path-1';
|
|
21
39
|
const newSearch = location.search === '?newParam=true' ? '?anotherParam=true' : '?newParam=true';
|
|
22
|
-
return
|
|
40
|
+
return /*#__PURE__*/ _jsxs(ButtonGroup, {
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ _jsx(Link, {
|
|
43
|
+
to: newPath,
|
|
44
|
+
children: /*#__PURE__*/ _jsx(Button, {
|
|
45
|
+
primary: true,
|
|
46
|
+
className: "m-t-2",
|
|
47
|
+
children: "Change path"
|
|
48
|
+
})
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ _jsx(Link, {
|
|
51
|
+
to: location.pathname + newSearch,
|
|
52
|
+
children: /*#__PURE__*/ _jsx(Button, {
|
|
53
|
+
primary: true,
|
|
54
|
+
className: "m-t-2",
|
|
55
|
+
children: "Change only search"
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
23
60
|
};
|
|
61
|
+
|
|
24
62
|
//# sourceMappingURL=ignore-search-changes-example.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/demo/ignore-search-changes-example.tsx"],"sourcesContent":["import { useState, Fragment, FC } from 'react';\nimport { Link, useLocation } from 'react-router-dom';\n\nimport { Button, ButtonGroup, Checkbox } from '@servicetitan/design-system';\n\nimport { ConfirmNavigation } from '..';\n//\n\nexport const IgnoreSearchChangesExample: FC = () => {\n const [confirm, setConfirm] = useState(true);\n const handleConfirmChange = (_0: never, checked: boolean) => {\n setConfirm(checked);\n };\n\n const [ignoreSearch, setIgnoreSearch] = useState(true);\n const handleIgnoreSearchChange = (_0: never, checked: boolean) => {\n setIgnoreSearch(checked);\n };\n\n return (\n <Fragment>\n <Checkbox\n label=\"Confirm Navigation?\"\n checked={confirm}\n onChange={handleConfirmChange}\n />\n <Checkbox\n label=\"Ignore search changes?\"\n checked={ignoreSearch}\n onChange={handleIgnoreSearchChange}\n />\n\n <ConfirmNavigation when={confirm} ignoreSearchChanges={ignoreSearch} />\n\n <AdvancedUrlChange />\n </Fragment>\n );\n};\n\nconst AdvancedUrlChange = () => {\n const location = useLocation();\n const newPath =\n location.pathname === '/some-new-path-1' ? '/another-new-path-2' : '/some-new-path-1';\n const newSearch =\n location.search === '?newParam=true' ? '?anotherParam=true' : '?newParam=true';\n return (\n <ButtonGroup>\n <Link to={newPath}>\n <Button primary className=\"m-t-2\">\n Change path\n </Button>\n </Link>\n <Link to={location.pathname + newSearch}>\n <Button primary className=\"m-t-2\">\n Change only search\n </Button>\n </Link>\n </ButtonGroup>\n );\n};\n"],"names":["useState","Fragment","Link","useLocation","Button","ButtonGroup","Checkbox","ConfirmNavigation","IgnoreSearchChangesExample","confirm","setConfirm","handleConfirmChange","_0","checked","ignoreSearch","setIgnoreSearch","handleIgnoreSearchChange","label","onChange","when","ignoreSearchChanges","AdvancedUrlChange","location","newPath","pathname","newSearch","search","to","primary","className"],"mappings":";AAAA,SAASA,QAAQ,EAAEC,QAAQ,QAAY,QAAQ;AAC/C,SAASC,IAAI,EAAEC,WAAW,QAAQ,mBAAmB;AAErD,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,8BAA8B;AAE5E,SAASC,iBAAiB,QAAQ,KAAK;AACvC,EAAE;AAEF,OAAO,MAAMC,6BAAiC;IAC1C,MAAM,CAACC,SAASC,WAAW,GAAGV,SAAS;IACvC,MAAMW,sBAAsB,CAACC,IAAWC;QACpCH,WAAWG;IACf;IAEA,MAAM,CAACC,cAAcC,gBAAgB,GAAGf,SAAS;IACjD,MAAMgB,2BAA2B,CAACJ,IAAWC;QACzCE,gBAAgBF;IACpB;IAEA,qBACI,MAACZ;;0BACG,KAACK;gBACGW,OAAM;gBACNJ,SAASJ;gBACTS,UAAUP;;0BAEd,KAACL;gBACGW,OAAM;gBACNJ,SAASC;gBACTI,UAAUF;;0BAGd,KAACT;gBAAkBY,MAAMV;gBAASW,qBAAqBN;;0BAEvD,KAACO;;;AAGb,EAAE;AAEF,MAAMA,oBAAoB;IACtB,MAAMC,WAAWnB;IACjB,MAAMoB,UACFD,SAASE,QAAQ,KAAK,qBAAqB,wBAAwB;IACvE,MAAMC,YACFH,SAASI,MAAM,KAAK,mBAAmB,uBAAuB;IAClE,qBACI,MAACrB;;0BACG,KAACH;gBAAKyB,IAAIJ;0BACN,cAAA,KAACnB;oBAAOwB,OAAO;oBAACC,WAAU;8BAAQ;;;0BAItC,KAAC3B;gBAAKyB,IAAIL,SAASE,QAAQ,GAAGC;0BAC1B,cAAA,KAACrB;oBAAOwB,OAAO;oBAACC,WAAU;8BAAQ;;;;;AAMlD"}
|
package/dist/demo/index.js
CHANGED
package/dist/demo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/demo/index.ts"],"sourcesContent":["export * from './basic';\nexport * from './custom';\nexport * from './ignore-search-changes-example';\n"],"names":[],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,WAAW;AACzB,cAAc,kCAAkC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './confirm-navigation';\n"],"names":[],"mappings":"AAAA,cAAc,uBAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/confirm-navigation",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/confirm-navigation",
|
|
6
6
|
"repository": {
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@servicetitan/design-system": "~14.5.1",
|
|
20
|
-
"@servicetitan/log-service": "^
|
|
21
|
-
"@servicetitan/react-ioc": "^
|
|
22
|
-
"@servicetitan/web-components": "^
|
|
20
|
+
"@servicetitan/log-service": "^31.3.2",
|
|
21
|
+
"@servicetitan/react-ioc": "^31.3.2",
|
|
22
|
+
"@servicetitan/web-components": "^31.3.2",
|
|
23
23
|
"@types/history": "~4.7.10",
|
|
24
24
|
"@types/react": "~18.2.55",
|
|
25
25
|
"@types/react-router": "~5.1.17",
|
|
26
26
|
"history": "~4.10.1",
|
|
27
27
|
"mobx": "~6.10.2",
|
|
28
|
-
"mobx-react": "
|
|
29
|
-
"react": "
|
|
28
|
+
"mobx-react": "^9.2.0",
|
|
29
|
+
"react": "^18.2.0",
|
|
30
30
|
"react-router-dom": "~5.3.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"cli": {
|
|
47
47
|
"webpack": false
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7fc7b9cbf766fe23879ae81831f28bdd96559bce"
|
|
50
50
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button } from '@servicetitan/design-system';
|
|
3
|
-
import { BrowserRouter, Link } from 'react-router-dom';
|
|
4
|
-
import { BasicExample, CustomExample, IgnoreSearchChangesExample } from './demo';
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Confirm Navigation/Demos',
|
|
7
|
-
};
|
|
8
|
-
export const Basic = () => {
|
|
9
|
-
return (_jsxs(BrowserRouter, { children: [_jsx(BasicExample, {}), _jsx(Link, { to: "/some-new-path", children: _jsx(Button, { primary: true, className: "m-t-2", children: "Try" }) })] }));
|
|
10
|
-
};
|
|
11
|
-
export const Custom = () => {
|
|
12
|
-
return (_jsxs(BrowserRouter, { children: [_jsx(CustomExample, {}), _jsx(Link, { to: "/some-new-path", children: _jsx(Button, { primary: true, className: "m-t-2", children: "Try" }) })] }));
|
|
13
|
-
};
|
|
14
|
-
export const IgnoreSearchChanges = () => {
|
|
15
|
-
return (_jsx(BrowserRouter, { children: _jsx(IgnoreSearchChangesExample, {}) }));
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=confirm-navigation.stories.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirm-navigation.stories.js","sourceRoot":"","sources":["../src/confirm-navigation.stories.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAEjF,eAAe;IACX,KAAK,EAAE,0BAA0B;CACpC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE;IACtB,OAAO,CACH,MAAC,aAAa,eACV,KAAC,YAAY,KAAG,EAEhB,KAAC,IAAI,IAAC,EAAE,EAAC,gBAAgB,YACrB,KAAC,MAAM,IAAC,OAAO,QAAC,SAAS,EAAC,OAAO,oBAExB,GACN,IACK,CACnB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,EAAE;IACvB,OAAO,CACH,MAAC,aAAa,eACV,KAAC,aAAa,KAAG,EAEjB,KAAC,IAAI,IAAC,EAAE,EAAC,gBAAgB,YACrB,KAAC,MAAM,IAAC,OAAO,QAAC,SAAS,EAAC,OAAO,oBAExB,GACN,IACK,CACnB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACpC,OAAO,CACH,KAAC,aAAa,cACV,KAAC,0BAA0B,KAAG,GAClB,CACnB,CAAC;AACN,CAAC,CAAC"}
|