@servicetitan/confirm-navigation 31.2.0 → 32.0.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.
@@ -1,12 +1,25 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
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 (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;
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
- var __metadata = (this && this.__metadata) || function (k, v) {
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, }) => (_jsx(Dialog, { negative: true, open: isOpen, title: title, onPrimaryActionClick: onConfirm, primaryActionName: "Leave", onSecondaryActionClick: onCancel, secondaryActionName: "Stay", onClose: onCancel, children: description }));
19
- let ConfirmNavigationUnwrapped = class ConfirmNavigationUnwrapped extends Component {
20
- constructor(props) {
21
- super(props);
22
- Object.defineProperty(this, "isOpen", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: false
27
- });
28
- Object.defineProperty(this, "isRedirecting", {
29
- enumerable: true,
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 _a, _b;
49
+ var _window_App_Instance, _window_App;
142
50
  this.block();
143
- if ((_b = (_a = window.App) === null || _a === void 0 ? void 0 : _a.Instance) === null || _b === void 0 ? void 0 : _b.before) {
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 _a, _b;
64
+ var _window_App_Instance, _window_App;
157
65
  this.unblock();
158
- if ((_b = (_a = window.App) === null || _a === void 0 ? void 0 : _a.Instance) === null || _b === void 0 ? void 0 : _b.befores) {
159
- window.App.Instance.befores = window.App.Instance.befores.filter(([, callback]) => callback !== this.onBefore);
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 (_jsx(Component, { isOpen: this.isOpen, title: title, description: description, onConfirm: this.handleConfirm, onCancel: this.handleCancel }));
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
- Object.defineProperty(ConfirmNavigationUnwrapped, "defaultProps", {
168
- enumerable: true,
169
- configurable: true,
170
- writable: true,
171
- value: {
172
- title: 'Are you sure you want to leave?',
173
- description: "You'll lose all your changes if you do.",
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
- __decorate([
149
+ _ts_decorate([
177
150
  optional(),
178
151
  injectDependency(HistoryManager),
179
- __metadata("design:type", HistoryManager)
152
+ _ts_metadata("design:type", typeof HistoryManager === "undefined" ? Object : HistoryManager)
180
153
  ], ConfirmNavigationUnwrapped.prototype, "historyManager", void 0);
181
- __decorate([
182
- observable,
183
- __metadata("design:type", Object)
154
+ _ts_decorate([
155
+ observable
184
156
  ], ConfirmNavigationUnwrapped.prototype, "isOpen", void 0);
185
- __decorate([
157
+ _ts_decorate([
186
158
  action,
187
- __metadata("design:type", Function),
188
- __metadata("design:paramtypes", []),
189
- __metadata("design:returntype", void 0)
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 = __decorate([
163
+ ConfirmNavigationUnwrapped = _ts_decorate([
192
164
  observer,
193
- __metadata("design:paramtypes", [Object])
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 }) => when ? _jsx(ConfirmNavigationUnwrapped, { ...props }) : null);
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,MA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EAAE,IAAI,CAAC,YAAY,GAC7B,CACL,CAAC;IACN,CAAC;;AA9JM;;;;WAAgD;QACnD,KAAK,EAAE,iCAAiC;QACxC,WAAW,EAAE,yCAAyC;KACzD;EAHkB,CAGjB;AAIM;IAFP,QAAQ,EAAE;IACV,gBAAgB,CAAC,cAAc,CAAC;8BACR,cAAc;kEAAC;AAE5B;IAAX,UAAU;;0DAAgB;AAkB3B;IADC,MAAM;;;;uDAKN;AAhCC,0BAA0B;IAD/B,QAAQ;;GACH,0BAA0B,CAgK/B;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,KAAK,EAA0B,EAAE,EAAE,CAC9F,IAAI,CAAC,CAAC,CAAC,KAAC,0BAA0B,OAAK,KAAK,GAAI,CAAC,CAAC,CAAC,IAAI,CAC1D,CAAC"}
1
+ {"version":3,"sources":["../src/confirm-navigation.tsx"],"sourcesContent":["import { Component, ComponentType, FC } 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,sBAAsBJ;QACtBK,mBAAkB;QAClBC,wBAAwBL;QACxBM,qBAAoB;QACpBC,SAASP;kBAERH;;AAIT,MACMW,mCAAmCzB;IA4BrC0B,QAAQ;QACJ,IAAI,CAACX,MAAM,GAAG;QACd,IAAI,CAACY,aAAa,GAAG;QACrB,IAAI,CAACC,SAAS,GAAGC;IACrB;IAEAC,oBAAoB;YAGZC,sBAAAA;QAFJ,IAAI,CAACC,KAAK;QAEV,KAAID,cAAAA,OAAOE,GAAG,cAAVF,mCAAAA,uBAAAA,YAAYG,QAAQ,cAApBH,2CAAAA,qBAAsBI,MAAM,EAAE;YAC9BJ,OAAOE,GAAG,CAACC,QAAQ,CAACC,MAAM,CAAC,IAAI,CAACC,QAAQ;QAC5C;IACJ;IAEAC,mBAAmBC,SAA8B,EAAE;QAC/C,MAAM,EAAEC,SAASC,WAAW,EAAE,GAAGF;QACjC,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI,CAACE,KAAK;QAE9B,IAAI,CAACpC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C5DL,QAAQ+B,OAAO,CAACf,gBAAgBC,QAAQ,GAAGD,gBAAgBM,MAAM;YACjEtB,QAAQgC,IAAI,CAACb;QACjB,IAEAN,uBAAAA,gBAAe;YACX,IAAI,CAAC,IAAI,CAACxB,SAAS,EAAE;gBACjB;YACJ;YAEA,MAAM,EAAEW,OAAO,EAAEgB,eAAe,EAAE,GAAG,IAAI,CAAC3B,SAAS;YAEnD,IAAI,CAACF,KAAK;YAEV,IAAI,CAACkB,OAAO;YACZ,4DAA4D;YAC5DL,QAAQ+B,OAAO,CAACf,gBAAgBC,QAAQ,GAAGD,gBAAgBM,MAAM;YACjE,IAAI,CAAC7B,KAAK;QACd;QAzHI1B,eAAe,IAAI;IACvB;AAuIJ;AA/JI,iBADEmB,4BACK+C,gBAAgD;IACnD3D,OAAO;IACPC,aAAa;AACjB;;;;;;;;;;;;;;;;;;;;;;AA8JJ,OAAO,MAAM2D,oBAAoBxE,WAAW,CAAC,EAAEyE,OAAO,IAAI,EAAE,GAAGjC,OAA+B,GAC1FiC,qBAAO,KAACjD;QAA4B,GAAGgB,KAAK;SAAO,MACrD"}
@@ -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 (_jsxs(Fragment, { children: [_jsx(Checkbox, { label: "Confirm Navigation?", checked: confirm, onChange: handleChange }), _jsx(ConfirmNavigation, { when: confirm })] }));
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
@@ -1 +1 @@
1
- {"version":3,"file":"basic.js","sourceRoot":"","sources":["../../src/demo/basic.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAM,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAEvC,MAAM,CAAC,MAAM,YAAY,GAAO,GAAG,EAAE;IACjC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,YAAY,GAAG,CAAC,EAAS,EAAE,OAAgB,EAAE,EAAE;QACjD,UAAU,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,OAAO,CACH,MAAC,QAAQ,eACL,KAAC,QAAQ,IAAC,KAAK,EAAC,qBAAqB,EAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAI,EAElF,KAAC,iBAAiB,IAAC,IAAI,EAAE,OAAO,GAAI,IAC7B,CACd,CAAC;AACN,CAAC,CAAC"}
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"}
@@ -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 (_jsxs(Fragment, { children: [_jsx(Checkbox, { label: "Confirm Navigation?", checked: confirm, onChange: handleChange }), _jsx(ConfirmNavigation, { when: confirm, title: "Are you sure you want to leave?", description: "If you leave all changes will be lost.", component: ({ isOpen, onCancel, onConfirm, title, description }) => {
11
- return (_jsx(Modal, { open: isOpen, onClose: onCancel, title: title, footer: _jsxs(ButtonGroup, { children: [_jsx(Button, { onClick: onCancel, children: "No, stay" }), _jsx(Button, { onClick: onConfirm, color: "negative", children: "Yes, leave" })] }), children: _jsx(BodyText, { subdued: true, children: description }) }));
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
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/demo/custom.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAM,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAEvC,MAAM,CAAC,MAAM,aAAa,GAAO,GAAG,EAAE;IAClC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,YAAY,GAAG,CAAC,EAAS,EAAE,OAAgB,EAAE,EAAE;QACjD,UAAU,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,OAAO,CACH,MAAC,QAAQ,eACL,KAAC,QAAQ,IAAC,KAAK,EAAC,qBAAqB,EAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAI,EAElF,KAAC,iBAAiB,IACd,IAAI,EAAE,OAAO,EACb,KAAK,EAAC,iCAAiC,EACvC,WAAW,EAAC,wCAAwC,EACpD,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE;oBAC/D,OAAO,CACH,KAAC,KAAK,IACF,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,KAAK,EACZ,MAAM,EACF,MAAC,WAAW,eACR,KAAC,MAAM,IAAC,OAAO,EAAE,QAAQ,yBAAmB,EAC5C,KAAC,MAAM,IAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAC,UAAU,2BAEnC,IACC,YAGlB,KAAC,QAAQ,IAAC,OAAO,kBAAE,WAAW,GAAY,GACtC,CACX,CAAC;gBACN,CAAC,GACH,IACK,CACd,CAAC;AACN,CAAC,CAAC"}
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 (_jsxs(Fragment, { children: [_jsx(Checkbox, { label: "Confirm Navigation?", checked: confirm, onChange: handleConfirmChange }), _jsx(Checkbox, { label: "Ignore search changes?", checked: ignoreSearch, onChange: handleIgnoreSearchChange }), _jsx(ConfirmNavigation, { when: confirm, ignoreSearchChanges: ignoreSearch }), _jsx(AdvancedUrlChange, {})] }));
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 (_jsxs(ButtonGroup, { children: [_jsx(Link, { to: newPath, children: _jsx(Button, { primary: true, className: "m-t-2", children: "Change path" }) }), _jsx(Link, { to: location.pathname + newSearch, children: _jsx(Button, { primary: true, className: "m-t-2", children: "Change only search" }) })] }));
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,"file":"ignore-search-changes-example.js","sourceRoot":"","sources":["../../src/demo/ignore-search-changes-example.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAM,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvC,EAAE;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAO,GAAG,EAAE;IAC/C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,mBAAmB,GAAG,CAAC,EAAS,EAAE,OAAgB,EAAE,EAAE;QACxD,UAAU,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,wBAAwB,GAAG,CAAC,EAAS,EAAE,OAAgB,EAAE,EAAE;QAC7D,eAAe,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,OAAO,CACH,MAAC,QAAQ,eACL,KAAC,QAAQ,IACL,KAAK,EAAC,qBAAqB,EAC3B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,mBAAmB,GAC/B,EACF,KAAC,QAAQ,IACL,KAAK,EAAC,wBAAwB,EAC9B,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,wBAAwB,GACpC,EAEF,KAAC,iBAAiB,IAAC,IAAI,EAAE,OAAO,EAAE,mBAAmB,EAAE,YAAY,GAAI,EAEvE,KAAC,iBAAiB,KAAG,IACd,CACd,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC3B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,OAAO,GACT,QAAQ,CAAC,QAAQ,KAAK,kBAAkB,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAC1F,MAAM,SAAS,GACX,QAAQ,CAAC,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,gBAAgB,CAAC;IACnF,OAAO,CACH,MAAC,WAAW,eACR,KAAC,IAAI,IAAC,EAAE,EAAE,OAAO,YACb,KAAC,MAAM,IAAC,OAAO,QAAC,SAAS,EAAC,OAAO,4BAExB,GACN,EACP,KAAC,IAAI,IAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,SAAS,YACnC,KAAC,MAAM,IAAC,OAAO,QAAC,SAAS,EAAC,OAAO,mCAExB,GACN,IACG,CACjB,CAAC;AACN,CAAC,CAAC"}
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"}
@@ -1,4 +1,5 @@
1
1
  export * from './basic';
2
2
  export * from './custom';
3
3
  export * from './ignore-search-changes-example';
4
+
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/demo/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,iCAAiC,CAAC"}
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
@@ -1,2 +1,3 @@
1
1
  export * from './confirm-navigation';
2
+
2
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
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.2.0",
3
+ "version": "32.0.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": "^30.0.0",
21
- "@servicetitan/react-ioc": "^30.0.0",
22
- "@servicetitan/web-components": "^30.0.0",
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": "~9.0.2",
29
- "react": "~18.2.0",
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": "03cfa4dc1e3cb374c8593f568ae47d0996ac7bae"
49
+ "gitHead": "511315cbee77cc7c60f20d0d86d24f69779c85ed"
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"}