@payloadcms/ui 3.61.0-internal.dd40839 → 3.61.1
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/elements/DocumentDrawer/DrawerHeader/index.d.ts.map +1 -1
- package/dist/elements/DocumentDrawer/DrawerHeader/index.js +49 -21
- package/dist/elements/DocumentDrawer/DrawerHeader/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.d.ts +8 -0
- package/dist/elements/LeaveWithoutSaving/index.d.ts.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.js +72 -46
- package/dist/elements/LeaveWithoutSaving/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.d.ts.map +1 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js +4 -2
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js.map +1 -1
- package/dist/elements/PreviewButton/index.d.ts.map +1 -1
- package/dist/elements/PreviewButton/index.js +21 -27
- package/dist/elements/PreviewButton/index.js.map +1 -1
- package/dist/elements/PublishButton/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/index.js +1 -0
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/QueryPresets/cells/WhereCell/index.d.ts.map +1 -1
- package/dist/elements/QueryPresets/cells/WhereCell/index.js +5 -1
- package/dist/elements/QueryPresets/cells/WhereCell/index.js.map +1 -1
- package/dist/elements/withMergedProps/index.d.ts +1 -1
- package/dist/elements/withMergedProps/index.js +1 -1
- package/dist/elements/withMergedProps/index.js.map +1 -1
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +1 -0
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +1 -0
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/exports/shared/index.js.map +1 -1
- package/dist/providers/LivePreview/context.d.ts +11 -0
- package/dist/providers/LivePreview/context.d.ts.map +1 -1
- package/dist/providers/LivePreview/context.js +18 -0
- package/dist/providers/LivePreview/context.js.map +1 -1
- package/dist/providers/LivePreview/index.d.ts +8 -0
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +6 -0
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts +2 -0
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +18 -0
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/buildTableState.js +6 -1
- package/dist/utilities/buildTableState.js.map +1 -1
- package/dist/utilities/handlePreview.d.ts +33 -0
- package/dist/utilities/handlePreview.d.ts.map +1 -0
- package/dist/utilities/handlePreview.js +71 -0
- package/dist/utilities/handlePreview.js.map +1 -0
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +29 -17
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/elements/PreviewButton/usePreviewURL.d.ts +0 -9
- package/dist/elements/PreviewButton/usePreviewURL.d.ts.map +0 -1
- package/dist/elements/PreviewButton/usePreviewURL.js +0 -86
- package/dist/elements/PreviewButton/usePreviewURL.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/DocumentDrawer/DrawerHeader/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/DocumentDrawer/DrawerHeader/index.tsx"],"names":[],"mappings":"AAeA,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAuCA,CAAA"}
|
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useCallback } from 'react';
|
|
5
6
|
import { Gutter } from '../../../elements/Gutter/index.js';
|
|
6
7
|
import { useModal } from '../../../elements/Modal/index.js';
|
|
7
8
|
import { RenderTitle } from '../../../elements/RenderTitle/index.js';
|
|
9
|
+
import { useFormModified } from '../../../forms/Form/index.js';
|
|
8
10
|
import { XIcon } from '../../../icons/X/index.js';
|
|
9
11
|
import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js';
|
|
10
12
|
import { useDocumentTitle } from '../../../providers/DocumentTitle/index.js';
|
|
11
13
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
12
14
|
import { IDLabel } from '../../IDLabel/index.js';
|
|
15
|
+
import { LeaveWithoutSavingModal } from '../../LeaveWithoutSaving/index.js';
|
|
13
16
|
import { documentDrawerBaseClass } from '../index.js';
|
|
14
17
|
import './index.scss';
|
|
18
|
+
const leaveWithoutSavingModalSlug = 'leave-without-saving-doc-drawer';
|
|
15
19
|
export const DocumentDrawerHeader = t0 => {
|
|
16
|
-
const $ = _c(
|
|
20
|
+
const $ = _c(15);
|
|
17
21
|
const {
|
|
18
22
|
AfterHeader,
|
|
19
23
|
drawerSlug,
|
|
@@ -21,23 +25,43 @@ export const DocumentDrawerHeader = t0 => {
|
|
|
21
25
|
} = t0;
|
|
22
26
|
const showDocumentID = t1 === undefined ? true : t1;
|
|
23
27
|
const {
|
|
24
|
-
closeModal
|
|
28
|
+
closeModal,
|
|
29
|
+
openModal
|
|
25
30
|
} = useModal();
|
|
26
31
|
const {
|
|
27
32
|
t
|
|
28
33
|
} = useTranslation();
|
|
34
|
+
const isModified = useFormModified();
|
|
29
35
|
let t2;
|
|
30
|
-
if ($[0] !==
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if ($[0] !== closeModal || $[1] !== drawerSlug || $[2] !== isModified || $[3] !== openModal) {
|
|
37
|
+
t2 = () => {
|
|
38
|
+
if (isModified) {
|
|
39
|
+
openModal(leaveWithoutSavingModalSlug);
|
|
40
|
+
} else {
|
|
41
|
+
closeModal(drawerSlug);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
$[0] = closeModal;
|
|
45
|
+
$[1] = drawerSlug;
|
|
46
|
+
$[2] = isModified;
|
|
47
|
+
$[3] = openModal;
|
|
48
|
+
$[4] = t2;
|
|
49
|
+
} else {
|
|
50
|
+
t2 = $[4];
|
|
51
|
+
}
|
|
52
|
+
const handleOnClose = t2;
|
|
53
|
+
let t3;
|
|
54
|
+
if ($[5] !== AfterHeader || $[6] !== closeModal || $[7] !== drawerSlug || $[8] !== handleOnClose || $[9] !== showDocumentID || $[10] !== t) {
|
|
55
|
+
let t4;
|
|
56
|
+
if ($[12] !== closeModal || $[13] !== drawerSlug) {
|
|
57
|
+
t4 = () => closeModal(drawerSlug);
|
|
58
|
+
$[12] = closeModal;
|
|
59
|
+
$[13] = drawerSlug;
|
|
60
|
+
$[14] = t4;
|
|
37
61
|
} else {
|
|
38
|
-
|
|
62
|
+
t4 = $[14];
|
|
39
63
|
}
|
|
40
|
-
|
|
64
|
+
t3 = _jsxs(Gutter, {
|
|
41
65
|
className: `${documentDrawerBaseClass}__header`,
|
|
42
66
|
children: [_jsxs("div", {
|
|
43
67
|
className: `${documentDrawerBaseClass}__header-content`,
|
|
@@ -49,25 +73,29 @@ export const DocumentDrawerHeader = t0 => {
|
|
|
49
73
|
}), _jsx("button", {
|
|
50
74
|
"aria-label": t("general:close"),
|
|
51
75
|
className: `${documentDrawerBaseClass}__header-close`,
|
|
52
|
-
onClick:
|
|
76
|
+
onClick: handleOnClose,
|
|
53
77
|
type: "button",
|
|
54
78
|
children: _jsx(XIcon, {})
|
|
55
79
|
})]
|
|
56
80
|
}), showDocumentID && _jsx(DocumentID, {}), AfterHeader ? _jsx("div", {
|
|
57
81
|
className: `${documentDrawerBaseClass}__after-header`,
|
|
58
82
|
children: AfterHeader
|
|
59
|
-
}) : null
|
|
83
|
+
}) : null, _jsx(LeaveWithoutSavingModal, {
|
|
84
|
+
modalSlug: leaveWithoutSavingModalSlug,
|
|
85
|
+
onConfirm: t4
|
|
86
|
+
})]
|
|
60
87
|
});
|
|
61
|
-
$[
|
|
62
|
-
$[
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
$[
|
|
66
|
-
$[
|
|
88
|
+
$[5] = AfterHeader;
|
|
89
|
+
$[6] = closeModal;
|
|
90
|
+
$[7] = drawerSlug;
|
|
91
|
+
$[8] = handleOnClose;
|
|
92
|
+
$[9] = showDocumentID;
|
|
93
|
+
$[10] = t;
|
|
94
|
+
$[11] = t3;
|
|
67
95
|
} else {
|
|
68
|
-
|
|
96
|
+
t3 = $[11];
|
|
69
97
|
}
|
|
70
|
-
return
|
|
98
|
+
return t3;
|
|
71
99
|
};
|
|
72
100
|
const DocumentID = () => {
|
|
73
101
|
const $ = _c(3);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","Gutter","useModal","RenderTitle","XIcon","useDocumentInfo","useDocumentTitle","useTranslation","IDLabel","documentDrawerBaseClass","DocumentDrawerHeader","t0","$","AfterHeader","drawerSlug","showDocumentID","t1","undefined","closeModal","t","t2","t3","_jsxs","className","children","_jsx","element","onClick","type","DocumentID","id","title","toString"],"sources":["../../../../src/elements/DocumentDrawer/DrawerHeader/index.tsx"],"sourcesContent":["'use client'\n\nimport { Gutter } from '../../../elements/Gutter/index.js'\nimport { useModal } from '../../../elements/Modal/index.js'\nimport { RenderTitle } from '../../../elements/RenderTitle/index.js'\nimport { XIcon } from '../../../icons/X/index.js'\nimport { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'\nimport { useDocumentTitle } from '../../../providers/DocumentTitle/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { IDLabel } from '../../IDLabel/index.js'\nimport { documentDrawerBaseClass } from '../index.js'\nimport './index.scss'\n\nexport const DocumentDrawerHeader: React.FC<{\n AfterHeader?: React.ReactNode\n drawerSlug: string\n showDocumentID?: boolean\n}> = ({ AfterHeader, drawerSlug, showDocumentID = true }) => {\n const { closeModal } = useModal()\n const { t } = useTranslation()\n\n return (\n <Gutter className={`${documentDrawerBaseClass}__header`}>\n <div className={`${documentDrawerBaseClass}__header-content`}>\n <h2 className={`${documentDrawerBaseClass}__header-text`}>\n {<RenderTitle element=\"span\" />}\n </h2>\n <button\n aria-label={t('general:close')}\n className={`${documentDrawerBaseClass}__header-close`}\n onClick={
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useCallback","Gutter","useModal","RenderTitle","useFormModified","XIcon","useDocumentInfo","useDocumentTitle","useTranslation","IDLabel","LeaveWithoutSavingModal","documentDrawerBaseClass","leaveWithoutSavingModalSlug","DocumentDrawerHeader","t0","$","AfterHeader","drawerSlug","showDocumentID","t1","undefined","closeModal","openModal","t","isModified","t2","handleOnClose","t3","t4","_jsxs","className","children","_jsx","element","onClick","type","DocumentID","modalSlug","onConfirm","id","title","toString"],"sources":["../../../../src/elements/DocumentDrawer/DrawerHeader/index.tsx"],"sourcesContent":["'use client'\n\nimport { useCallback } from 'react'\n\nimport { Gutter } from '../../../elements/Gutter/index.js'\nimport { useModal } from '../../../elements/Modal/index.js'\nimport { RenderTitle } from '../../../elements/RenderTitle/index.js'\nimport { useFormModified } from '../../../forms/Form/index.js'\nimport { XIcon } from '../../../icons/X/index.js'\nimport { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'\nimport { useDocumentTitle } from '../../../providers/DocumentTitle/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { IDLabel } from '../../IDLabel/index.js'\nimport { LeaveWithoutSavingModal } from '../../LeaveWithoutSaving/index.js'\nimport { documentDrawerBaseClass } from '../index.js'\nimport './index.scss'\n\nconst leaveWithoutSavingModalSlug = 'leave-without-saving-doc-drawer'\n\nexport const DocumentDrawerHeader: React.FC<{\n AfterHeader?: React.ReactNode\n drawerSlug: string\n showDocumentID?: boolean\n}> = ({ AfterHeader, drawerSlug, showDocumentID = true }) => {\n const { closeModal, openModal } = useModal()\n const { t } = useTranslation()\n const isModified = useFormModified()\n\n const handleOnClose = useCallback(() => {\n if (isModified) {\n openModal(leaveWithoutSavingModalSlug)\n } else {\n closeModal(drawerSlug)\n }\n }, [isModified, openModal, closeModal, drawerSlug])\n\n return (\n <Gutter className={`${documentDrawerBaseClass}__header`}>\n <div className={`${documentDrawerBaseClass}__header-content`}>\n <h2 className={`${documentDrawerBaseClass}__header-text`}>\n {<RenderTitle element=\"span\" />}\n </h2>\n <button\n aria-label={t('general:close')}\n className={`${documentDrawerBaseClass}__header-close`}\n onClick={handleOnClose}\n type=\"button\"\n >\n <XIcon />\n </button>\n </div>\n {showDocumentID && <DocumentID />}\n {AfterHeader ? (\n <div className={`${documentDrawerBaseClass}__after-header`}>{AfterHeader}</div>\n ) : null}\n\n <LeaveWithoutSavingModal\n modalSlug={leaveWithoutSavingModalSlug}\n onConfirm={() => closeModal(drawerSlug)}\n />\n </Gutter>\n )\n}\n\nconst DocumentID: React.FC = () => {\n const { id } = useDocumentInfo()\n const { title } = useDocumentTitle()\n return id && id !== title ? <IDLabel id={id.toString()} /> : null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,WAAW,QAAQ;AAE5B,SAASC,MAAM,QAAQ;AACvB,SAASC,QAAQ,QAAQ;AACzB,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,KAAK,QAAQ;AACtB,SAASC,eAAe,QAAQ;AAChC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,cAAc,QAAQ;AAC/B,SAASC,OAAO,QAAQ;AACxB,SAASC,uBAAuB,QAAQ;AACxC,SAASC,uBAAuB,QAAQ;AACxC,OAAO;AAEP,MAAMC,2BAAA,GA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EAAA;IAAAA,EAAA,GAAAC,CAAA;EAAA;EAAA,OAAtDD,EAAsD;AAAA,CAC/D","ignoreList":[]}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { OnCancel } from '../ConfirmationModal/index.js';
|
|
2
3
|
type LeaveWithoutSavingProps = {
|
|
4
|
+
disablePreventLeave?: boolean;
|
|
5
|
+
modalSlug?: string;
|
|
3
6
|
onConfirm?: () => Promise<void> | void;
|
|
4
7
|
onPrevent?: (nextHref: null | string) => void;
|
|
5
8
|
};
|
|
6
9
|
export declare const LeaveWithoutSaving: React.FC<LeaveWithoutSavingProps>;
|
|
10
|
+
export declare const LeaveWithoutSavingModal: ({ modalSlug, onCancel, onConfirm, }: {
|
|
11
|
+
modalSlug: string;
|
|
12
|
+
onCancel?: OnCancel;
|
|
13
|
+
onConfirm: () => Promise<void> | void;
|
|
14
|
+
}) => React.JSX.Element;
|
|
7
15
|
export {};
|
|
8
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAS7D,KAAK,uBAAuB,GAAG;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACtC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,GAAG,MAAM,KAAK,IAAI,CAAA;CAC9C,CAAA;AAID,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CA8ChE,CAAA;AAED,eAAO,MAAM,uBAAuB,wCAIjC;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACtC,sBAcA,CAAA"}
|
|
@@ -9,13 +9,16 @@ import { useTranslation } from '../../providers/Translation/index.js';
|
|
|
9
9
|
import { ConfirmationModal } from '../ConfirmationModal/index.js';
|
|
10
10
|
import { useModal } from '../Modal/index.js';
|
|
11
11
|
import { usePreventLeave } from './usePreventLeave.js';
|
|
12
|
-
const
|
|
12
|
+
const leaveWithoutSavingModalSlug = 'leave-without-saving';
|
|
13
13
|
export const LeaveWithoutSaving = t0 => {
|
|
14
|
-
const $ = _c(
|
|
14
|
+
const $ = _c(17);
|
|
15
15
|
const {
|
|
16
|
+
disablePreventLeave: t1,
|
|
16
17
|
onConfirm,
|
|
17
18
|
onPrevent
|
|
18
19
|
} = t0;
|
|
20
|
+
const disablePreventLeave = t1 === undefined ? false : t1;
|
|
21
|
+
const modalSlug = leaveWithoutSavingModalSlug;
|
|
19
22
|
const {
|
|
20
23
|
closeModal,
|
|
21
24
|
openModal
|
|
@@ -28,40 +31,37 @@ export const LeaveWithoutSaving = t0 => {
|
|
|
28
31
|
user
|
|
29
32
|
} = useAuth();
|
|
30
33
|
const [hasAccepted, setHasAccepted] = React.useState(false);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
} = useTranslation();
|
|
34
|
-
const prevent = Boolean((modified || !isValid) && user);
|
|
35
|
-
let t1;
|
|
34
|
+
const prevent = !disablePreventLeave && Boolean((modified || !isValid) && user);
|
|
35
|
+
let t2;
|
|
36
36
|
if ($[0] !== onPrevent || $[1] !== openModal) {
|
|
37
|
-
|
|
37
|
+
t2 = () => {
|
|
38
38
|
const activeHref = document.activeElement?.href || null;
|
|
39
39
|
if (onPrevent) {
|
|
40
40
|
onPrevent(activeHref);
|
|
41
41
|
}
|
|
42
|
-
openModal(
|
|
42
|
+
openModal(leaveWithoutSavingModalSlug);
|
|
43
43
|
};
|
|
44
44
|
$[0] = onPrevent;
|
|
45
45
|
$[1] = openModal;
|
|
46
|
-
$[2] =
|
|
46
|
+
$[2] = t2;
|
|
47
47
|
} else {
|
|
48
|
-
|
|
48
|
+
t2 = $[2];
|
|
49
49
|
}
|
|
50
|
-
const handlePrevent =
|
|
51
|
-
let
|
|
50
|
+
const handlePrevent = t2;
|
|
51
|
+
let t3;
|
|
52
52
|
if ($[3] !== closeModal) {
|
|
53
|
-
|
|
54
|
-
closeModal(
|
|
53
|
+
t3 = () => {
|
|
54
|
+
closeModal(leaveWithoutSavingModalSlug);
|
|
55
55
|
};
|
|
56
56
|
$[3] = closeModal;
|
|
57
|
-
$[4] =
|
|
57
|
+
$[4] = t3;
|
|
58
58
|
} else {
|
|
59
|
-
|
|
59
|
+
t3 = $[4];
|
|
60
60
|
}
|
|
61
|
-
const handleAccept =
|
|
62
|
-
let
|
|
61
|
+
const handleAccept = t3;
|
|
62
|
+
let t4;
|
|
63
63
|
if ($[5] !== handleAccept || $[6] !== handlePrevent || $[7] !== hasAccepted || $[8] !== prevent) {
|
|
64
|
-
|
|
64
|
+
t4 = {
|
|
65
65
|
hasAccepted,
|
|
66
66
|
onAccept: handleAccept,
|
|
67
67
|
onPrevent: handlePrevent,
|
|
@@ -71,60 +71,86 @@ export const LeaveWithoutSaving = t0 => {
|
|
|
71
71
|
$[6] = handlePrevent;
|
|
72
72
|
$[7] = hasAccepted;
|
|
73
73
|
$[8] = prevent;
|
|
74
|
-
$[9] =
|
|
74
|
+
$[9] = t4;
|
|
75
75
|
} else {
|
|
76
|
-
|
|
76
|
+
t4 = $[9];
|
|
77
77
|
}
|
|
78
|
-
usePreventLeave(
|
|
79
|
-
let
|
|
78
|
+
usePreventLeave(t4);
|
|
79
|
+
let t5;
|
|
80
80
|
if ($[10] !== closeModal) {
|
|
81
|
-
|
|
82
|
-
closeModal(
|
|
81
|
+
t5 = () => {
|
|
82
|
+
closeModal(leaveWithoutSavingModalSlug);
|
|
83
83
|
};
|
|
84
84
|
$[10] = closeModal;
|
|
85
|
-
$[11] =
|
|
85
|
+
$[11] = t5;
|
|
86
86
|
} else {
|
|
87
|
-
|
|
87
|
+
t5 = $[11];
|
|
88
88
|
}
|
|
89
|
-
const onCancel =
|
|
90
|
-
let
|
|
89
|
+
const onCancel = t5;
|
|
90
|
+
let t6;
|
|
91
91
|
if ($[12] !== onConfirm) {
|
|
92
|
-
|
|
92
|
+
t6 = async () => {
|
|
93
93
|
if (onConfirm) {
|
|
94
94
|
;
|
|
95
95
|
try {
|
|
96
96
|
await onConfirm();
|
|
97
|
-
} catch (
|
|
98
|
-
const err =
|
|
97
|
+
} catch (t7) {
|
|
98
|
+
const err = t7;
|
|
99
99
|
console.error("Error in LeaveWithoutSaving onConfirm:", err);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
setHasAccepted(true);
|
|
103
103
|
};
|
|
104
104
|
$[12] = onConfirm;
|
|
105
|
-
$[13] =
|
|
105
|
+
$[13] = t6;
|
|
106
106
|
} else {
|
|
107
|
-
|
|
107
|
+
t6 = $[13];
|
|
108
108
|
}
|
|
109
|
-
const handleConfirm =
|
|
110
|
-
let
|
|
111
|
-
if ($[14] !== handleConfirm || $[15] !== onCancel
|
|
112
|
-
|
|
109
|
+
const handleConfirm = t6;
|
|
110
|
+
let t7;
|
|
111
|
+
if ($[14] !== handleConfirm || $[15] !== onCancel) {
|
|
112
|
+
t7 = _jsx(LeaveWithoutSavingModal, {
|
|
113
|
+
modalSlug: leaveWithoutSavingModalSlug,
|
|
114
|
+
onCancel,
|
|
115
|
+
onConfirm: handleConfirm
|
|
116
|
+
});
|
|
117
|
+
$[14] = handleConfirm;
|
|
118
|
+
$[15] = onCancel;
|
|
119
|
+
$[16] = t7;
|
|
120
|
+
} else {
|
|
121
|
+
t7 = $[16];
|
|
122
|
+
}
|
|
123
|
+
return t7;
|
|
124
|
+
};
|
|
125
|
+
export const LeaveWithoutSavingModal = t0 => {
|
|
126
|
+
const $ = _c(5);
|
|
127
|
+
const {
|
|
128
|
+
modalSlug,
|
|
129
|
+
onCancel,
|
|
130
|
+
onConfirm
|
|
131
|
+
} = t0;
|
|
132
|
+
const {
|
|
133
|
+
t
|
|
134
|
+
} = useTranslation();
|
|
135
|
+
let t1;
|
|
136
|
+
if ($[0] !== modalSlug || $[1] !== onCancel || $[2] !== onConfirm || $[3] !== t) {
|
|
137
|
+
t1 = _jsx(ConfirmationModal, {
|
|
113
138
|
body: t("general:changesNotSaved"),
|
|
114
139
|
cancelLabel: t("general:stayOnThisPage"),
|
|
115
140
|
confirmLabel: t("general:leaveAnyway"),
|
|
116
141
|
heading: t("general:leaveWithoutSaving"),
|
|
117
142
|
modalSlug,
|
|
118
143
|
onCancel,
|
|
119
|
-
onConfirm
|
|
144
|
+
onConfirm
|
|
120
145
|
});
|
|
121
|
-
$[
|
|
122
|
-
$[
|
|
123
|
-
$[
|
|
124
|
-
$[
|
|
146
|
+
$[0] = modalSlug;
|
|
147
|
+
$[1] = onCancel;
|
|
148
|
+
$[2] = onConfirm;
|
|
149
|
+
$[3] = t;
|
|
150
|
+
$[4] = t1;
|
|
125
151
|
} else {
|
|
126
|
-
|
|
152
|
+
t1 = $[4];
|
|
127
153
|
}
|
|
128
|
-
return
|
|
154
|
+
return t1;
|
|
129
155
|
};
|
|
130
156
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","useCallback","useForm","useFormModified","useAuth","useTranslation","ConfirmationModal","useModal","usePreventLeave","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","useCallback","useForm","useFormModified","useAuth","useTranslation","ConfirmationModal","useModal","usePreventLeave","leaveWithoutSavingModalSlug","LeaveWithoutSaving","t0","$","disablePreventLeave","t1","onConfirm","onPrevent","undefined","modalSlug","closeModal","openModal","modified","isValid","user","hasAccepted","setHasAccepted","useState","prevent","Boolean","t2","activeHref","document","activeElement","href","handlePrevent","t3","handleAccept","t4","onAccept","t5","onCancel","t6","t7","err","console","error","handleConfirm","_jsx","LeaveWithoutSavingModal","t","body","cancelLabel","confirmLabel","heading"],"sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"sourcesContent":["'use client'\nimport React, { useCallback } from 'react'\n\nimport type { OnCancel } from '../ConfirmationModal/index.js'\n\nimport { useForm, useFormModified } from '../../forms/Form/index.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { ConfirmationModal } from '../ConfirmationModal/index.js'\nimport { useModal } from '../Modal/index.js'\nimport { usePreventLeave } from './usePreventLeave.js'\n\ntype LeaveWithoutSavingProps = {\n disablePreventLeave?: boolean\n modalSlug?: string\n onConfirm?: () => Promise<void> | void\n onPrevent?: (nextHref: null | string) => void\n}\n\nconst leaveWithoutSavingModalSlug = 'leave-without-saving'\n\nexport const LeaveWithoutSaving: React.FC<LeaveWithoutSavingProps> = ({\n disablePreventLeave = false,\n onConfirm,\n onPrevent,\n}) => {\n const modalSlug = leaveWithoutSavingModalSlug\n const { closeModal, openModal } = useModal()\n const modified = useFormModified()\n const { isValid } = useForm()\n const { user } = useAuth()\n const [hasAccepted, setHasAccepted] = React.useState(false)\n\n const prevent = !disablePreventLeave && Boolean((modified || !isValid) && user)\n\n const handlePrevent = useCallback(() => {\n const activeHref = (document.activeElement as HTMLAnchorElement)?.href || null\n if (onPrevent) {\n onPrevent(activeHref)\n }\n openModal(modalSlug)\n }, [openModal, onPrevent, modalSlug])\n\n const handleAccept = useCallback(() => {\n closeModal(modalSlug)\n }, [closeModal, modalSlug])\n\n usePreventLeave({ hasAccepted, onAccept: handleAccept, onPrevent: handlePrevent, prevent })\n\n const onCancel: OnCancel = useCallback(() => {\n closeModal(modalSlug)\n }, [closeModal, modalSlug])\n\n const handleConfirm = useCallback(async () => {\n if (onConfirm) {\n try {\n await onConfirm()\n } catch (err) {\n console.error('Error in LeaveWithoutSaving onConfirm:', err)\n }\n }\n setHasAccepted(true)\n }, [onConfirm])\n\n return (\n <LeaveWithoutSavingModal modalSlug={modalSlug} onCancel={onCancel} onConfirm={handleConfirm} />\n )\n}\n\nexport const LeaveWithoutSavingModal = ({\n modalSlug,\n onCancel,\n onConfirm,\n}: {\n modalSlug: string\n onCancel?: OnCancel\n onConfirm: () => Promise<void> | void\n}) => {\n const { t } = useTranslation()\n\n return (\n <ConfirmationModal\n body={t('general:changesNotSaved')}\n cancelLabel={t('general:stayOnThisPage')}\n confirmLabel={t('general:leaveAnyway')}\n heading={t('general:leaveWithoutSaving')}\n modalSlug={modalSlug}\n onCancel={onCancel}\n onConfirm={onConfirm}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,WAAW,QAAQ;AAInC,SAASC,OAAO,EAAEC,eAAe,QAAQ;AACzC,SAASC,OAAO,QAAQ;AACxB,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,QAAQ,QAAQ;AACzB,SAASC,eAAe,QAAQ;AAShC,MAAMC,2BAAA,GAA8B;AAEpC,OAAO,MAAMC,kBAAA,GAAwDC,EAAA;EAAA,MAAAC,CAAA,GAAAb,EAAA;EAAC;IAAAc,mBAAA,EAAAC,EAAA;IAAAC,SAAA;IAAAC;EAAA,IAAAL,EAIrE;EAHC,MAAAE,mBAAA,GAAAC,EAA2B,KAAAG,SAAA,WAA3BH,EAA2B;EAI3B,MAAAI,SAAA,GAAAT,2BAAA;EACA;IAAAU,UAAA;IAAAC;EAAA,IAAkCb,QAAA;EAClC,MAAAc,QAAA,GAAiBlB,eAAA;EACjB;IAAAmB;EAAA,IAAoBpB,OAAA;EACpB;IAAAqB;EAAA,IAAiBnB,OA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AAAqC,CAAA;IAGZnC,EAAA,GAAAiC,IAAA,CAAAzC,iBAAA;MAAA4C,IAAA,EACQD,CAAA,CAAE;MAAAE,WAAA,EACKF,CAAA,CAAE;MAAAG,YAAA,EACDH,CAAA,CAAE;MAAAI,OAAA,EACPJ,CAAA,CAAE;MAAA/B,SAAA;MAAAsB,QAAA;MAAAzB;IAAA,C;;;;;;;;;SAJbD,E;CAUJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreventLeave.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/usePreventLeave.tsx"],"names":[],"mappings":"AA4BA,eAAO,MAAM,eAAe,aAAa,CAAC,MAAM,OAAO,CAAC,GAAG,OAAO,YAAmB,MAAM,SA6B1F,CAAA;AAED,eAAO,MAAM,eAAe,4DAMzB;IACD,WAAW,EAAE,OAAO,CAAA;IAEpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IAErB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,EAAE,OAAO,CAAA;CACjB,
|
|
1
|
+
{"version":3,"file":"usePreventLeave.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/usePreventLeave.tsx"],"names":[],"mappings":"AA4BA,eAAO,MAAM,eAAe,aAAa,CAAC,MAAM,OAAO,CAAC,GAAG,OAAO,YAAmB,MAAM,SA6B1F,CAAA;AAED,eAAO,MAAM,eAAe,4DAMzB;IACD,WAAW,EAAE,OAAO,CAAA;IAEpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IAErB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,EAAE,OAAO,CAAA;CACjB,SA4FA,CAAA"}
|
|
@@ -126,8 +126,10 @@ export const usePreventLeave = ({
|
|
|
126
126
|
console.log('Unexpected exception thrown in LeaveWithoutSaving:usePreventLeave', err_0);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
if (prevent) {
|
|
130
|
+
// Add the global click event listener
|
|
131
|
+
document.addEventListener('click', handleClick, true);
|
|
132
|
+
}
|
|
131
133
|
// Clean up the global click event listener when the component is unmounted
|
|
132
134
|
return () => {
|
|
133
135
|
document.removeEventListener('click', handleClick, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreventLeave.js","names":["c","_c","useRouter","useCallback","useEffect","useRef","useRouteTransition","on","obj","args","addEventListener","off","removeEventListener","useBeforeUnload","t0","message","$","enabled","undefined","t1","event","finalEnabled","preventDefault","returnValue","handler","t2","t3","window","usePreventLeave","hasAccepted","onAccept","onPrevent","prevent","startRouteTransition","router","cancelledURL","isAnchorOfCurrentUrl","currentUrl","newUrl","currentUrlObj","URL","newUrlObj","hostname","pathname","search","currentHash","hash","newHash","href","replace","err","console","log","findClosestAnchor","element","tagName","toLowerCase","parentElement","handleClick","target","anchor","location","isAnchor","isDownloadLink","download","isNewTab","metaKey","ctrlKey","isPageLeaving","confirm","current","stopPropagation","document","push"],"sources":["../../../src/elements/LeaveWithoutSaving/usePreventLeave.tsx"],"sourcesContent":["'use client'\n// Credit: @Taiki92777\n// - Source: https://github.com/vercel/next.js/discussions/32231#discussioncomment-7284386\n// Credit: `react-use` maintainers\n// - Source: https://github.com/streamich/react-use/blob/ade8d3905f544305515d010737b4ae604cc51024/src/useBeforeUnload.ts#L2\nimport { useRouter } from 'next/navigation.js'\nimport { useCallback, useEffect, useRef } from 'react'\n\nimport { useRouteTransition } from '../../providers/RouteTransition/index.js'\n\nfunction on<T extends Document | EventTarget | HTMLElement | Window>(\n obj: null | T,\n ...args: [string, (() => void) | null, ...any] | Parameters<T['addEventListener']>\n): void {\n if (obj && obj.addEventListener) {\n obj.addEventListener(...(args as Parameters<HTMLElement['addEventListener']>))\n }\n}\n\nfunction off<T extends Document | EventTarget | HTMLElement | Window>(\n obj: null | T,\n ...args: [string, (() => void) | null, ...any] | Parameters<T['removeEventListener']>\n): void {\n if (obj && obj.removeEventListener) {\n obj.removeEventListener(...(args as Parameters<HTMLElement['removeEventListener']>))\n }\n}\n\nexport const useBeforeUnload = (enabled: (() => boolean) | boolean = true, message?: string) => {\n const handler = useCallback(\n (event: BeforeUnloadEvent) => {\n const finalEnabled = typeof enabled === 'function' ? enabled() : true\n\n if (!finalEnabled) {\n return\n }\n\n event.preventDefault()\n\n if (message) {\n event.returnValue = message\n }\n\n return message\n },\n [enabled, message],\n )\n\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n on(window, 'beforeunload', handler)\n\n return () => off(window, 'beforeunload', handler)\n }, [enabled, handler])\n}\n\nexport const usePreventLeave = ({\n hasAccepted = false,\n message = 'Are you sure want to leave this page?',\n onAccept,\n onPrevent,\n prevent = true,\n}: {\n hasAccepted: boolean\n // if no `onPrevent` is provided, the message will be displayed in a confirm dialog\n message?: string\n onAccept?: () => void\n // to use a custom confirmation dialog, provide a function that returns a boolean\n onPrevent?: () => void\n prevent: boolean\n}) => {\n // check when page is about to be reloaded\n useBeforeUnload(prevent, message)\n const { startRouteTransition } = useRouteTransition()\n\n const router = useRouter()\n const cancelledURL = useRef<string>('')\n\n // check when page is about to be changed\n useEffect(() => {\n function isAnchorOfCurrentUrl(currentUrl: string, newUrl: string) {\n try {\n const currentUrlObj = new URL(currentUrl)\n const newUrlObj = new URL(newUrl)\n // Compare hostname, pathname, and search parameters\n if (\n currentUrlObj.hostname === newUrlObj.hostname &&\n currentUrlObj.pathname === newUrlObj.pathname &&\n currentUrlObj.search === newUrlObj.search\n ) {\n // Check if the new URL is just an anchor of the current URL page\n const currentHash = currentUrlObj.hash\n const newHash = newUrlObj.hash\n return (\n currentHash !== newHash &&\n currentUrlObj.href.replace(currentHash, '') === newUrlObj.href.replace(newHash, '')\n )\n }\n } catch (err) {\n console.log('Unexpected exception thrown in LeaveWithoutSaving:isAnchorOfCurrentUrl', err)\n }\n return false\n }\n\n function findClosestAnchor(element: HTMLElement | null): HTMLAnchorElement | null {\n while (element && element.tagName.toLowerCase() !== 'a') {\n element = element.parentElement\n }\n return element as HTMLAnchorElement\n }\n\n function handleClick(event: MouseEvent) {\n try {\n const target = event.target as HTMLElement\n const anchor = findClosestAnchor(target)\n if (anchor) {\n const currentUrl = window.location.href\n const newUrl = anchor.href\n const isAnchor = isAnchorOfCurrentUrl(currentUrl, newUrl)\n const isDownloadLink = anchor.download !== ''\n const isNewTab = anchor.target === '_blank' || event.metaKey || event.ctrlKey\n\n const isPageLeaving = !(newUrl === currentUrl || isAnchor || isDownloadLink || isNewTab)\n\n if (isPageLeaving && prevent && (!onPrevent ? !window.confirm(message) : true)) {\n // Keep a reference of the href\n cancelledURL.current = newUrl\n\n // Cancel the route change\n event.preventDefault()\n event.stopPropagation()\n\n if (typeof onPrevent === 'function') {\n onPrevent()\n }\n }\n }\n } catch (err) {\n console.log('Unexpected exception thrown in LeaveWithoutSaving:usePreventLeave', err)\n }\n }\n\n // Add the global click event listener\n document.addEventListener('click', handleClick, true)\n\n // Clean up the global click event listener when the component is unmounted\n return () => {\n document.removeEventListener('click', handleClick, true)\n }\n }, [onPrevent, prevent, message])\n\n useEffect(() => {\n if (hasAccepted && cancelledURL.current) {\n if (onAccept) {\n onAccept()\n }\n\n startRouteTransition(() => router.push(cancelledURL.current))\n }\n }, [hasAccepted, onAccept, router, startRouteTransition])\n}\n"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,SAAS,QAAQ;AAC1B,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAE/C,SAASC,kBAAkB,QAAQ;AAEnC,SAASC,GACPC,GAAa,EACb,GAAGC,IAA+E;EAElF,IAAID,GAAA,IAAOA,GAAA,CAAIE,gBAAgB,EAAE;IAC/BF,GAAA,CAAIE,gBAAgB,IAAKD,IAAA;EAC3B;AACF;AA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EhCX,SAAA,CAAU;IACR,IAAIyB,WAAA,IAAeM,YAAA,CAAamC,OAAO,EAAE;MACvC,IAAIxC,QAAA,EAAU;QACZA,QAAA;MACF;MAEAG,oBAAA,CAAqB,MAAMC,MAAA,CAAOuC,IAAI,CAACtC,YAAA,CAAamC,OAAO;IAC7D;EACF,GAAG,CAACzC,WAAA,EAAaC,QAAA,EAAUI,MAAA,EAAQD,oBAAA,CAAqB;AAC1D","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"usePreventLeave.js","names":["c","_c","useRouter","useCallback","useEffect","useRef","useRouteTransition","on","obj","args","addEventListener","off","removeEventListener","useBeforeUnload","t0","message","$","enabled","undefined","t1","event","finalEnabled","preventDefault","returnValue","handler","t2","t3","window","usePreventLeave","hasAccepted","onAccept","onPrevent","prevent","startRouteTransition","router","cancelledURL","isAnchorOfCurrentUrl","currentUrl","newUrl","currentUrlObj","URL","newUrlObj","hostname","pathname","search","currentHash","hash","newHash","href","replace","err","console","log","findClosestAnchor","element","tagName","toLowerCase","parentElement","handleClick","target","anchor","location","isAnchor","isDownloadLink","download","isNewTab","metaKey","ctrlKey","isPageLeaving","confirm","current","stopPropagation","document","push"],"sources":["../../../src/elements/LeaveWithoutSaving/usePreventLeave.tsx"],"sourcesContent":["'use client'\n// Credit: @Taiki92777\n// - Source: https://github.com/vercel/next.js/discussions/32231#discussioncomment-7284386\n// Credit: `react-use` maintainers\n// - Source: https://github.com/streamich/react-use/blob/ade8d3905f544305515d010737b4ae604cc51024/src/useBeforeUnload.ts#L2\nimport { useRouter } from 'next/navigation.js'\nimport { useCallback, useEffect, useRef } from 'react'\n\nimport { useRouteTransition } from '../../providers/RouteTransition/index.js'\n\nfunction on<T extends Document | EventTarget | HTMLElement | Window>(\n obj: null | T,\n ...args: [string, (() => void) | null, ...any] | Parameters<T['addEventListener']>\n): void {\n if (obj && obj.addEventListener) {\n obj.addEventListener(...(args as Parameters<HTMLElement['addEventListener']>))\n }\n}\n\nfunction off<T extends Document | EventTarget | HTMLElement | Window>(\n obj: null | T,\n ...args: [string, (() => void) | null, ...any] | Parameters<T['removeEventListener']>\n): void {\n if (obj && obj.removeEventListener) {\n obj.removeEventListener(...(args as Parameters<HTMLElement['removeEventListener']>))\n }\n}\n\nexport const useBeforeUnload = (enabled: (() => boolean) | boolean = true, message?: string) => {\n const handler = useCallback(\n (event: BeforeUnloadEvent) => {\n const finalEnabled = typeof enabled === 'function' ? enabled() : true\n\n if (!finalEnabled) {\n return\n }\n\n event.preventDefault()\n\n if (message) {\n event.returnValue = message\n }\n\n return message\n },\n [enabled, message],\n )\n\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n on(window, 'beforeunload', handler)\n\n return () => off(window, 'beforeunload', handler)\n }, [enabled, handler])\n}\n\nexport const usePreventLeave = ({\n hasAccepted = false,\n message = 'Are you sure want to leave this page?',\n onAccept,\n onPrevent,\n prevent = true,\n}: {\n hasAccepted: boolean\n // if no `onPrevent` is provided, the message will be displayed in a confirm dialog\n message?: string\n onAccept?: () => void\n // to use a custom confirmation dialog, provide a function that returns a boolean\n onPrevent?: () => void\n prevent: boolean\n}) => {\n // check when page is about to be reloaded\n useBeforeUnload(prevent, message)\n const { startRouteTransition } = useRouteTransition()\n\n const router = useRouter()\n const cancelledURL = useRef<string>('')\n\n // check when page is about to be changed\n useEffect(() => {\n function isAnchorOfCurrentUrl(currentUrl: string, newUrl: string) {\n try {\n const currentUrlObj = new URL(currentUrl)\n const newUrlObj = new URL(newUrl)\n // Compare hostname, pathname, and search parameters\n if (\n currentUrlObj.hostname === newUrlObj.hostname &&\n currentUrlObj.pathname === newUrlObj.pathname &&\n currentUrlObj.search === newUrlObj.search\n ) {\n // Check if the new URL is just an anchor of the current URL page\n const currentHash = currentUrlObj.hash\n const newHash = newUrlObj.hash\n return (\n currentHash !== newHash &&\n currentUrlObj.href.replace(currentHash, '') === newUrlObj.href.replace(newHash, '')\n )\n }\n } catch (err) {\n console.log('Unexpected exception thrown in LeaveWithoutSaving:isAnchorOfCurrentUrl', err)\n }\n return false\n }\n\n function findClosestAnchor(element: HTMLElement | null): HTMLAnchorElement | null {\n while (element && element.tagName.toLowerCase() !== 'a') {\n element = element.parentElement\n }\n return element as HTMLAnchorElement\n }\n\n function handleClick(event: MouseEvent) {\n try {\n const target = event.target as HTMLElement\n const anchor = findClosestAnchor(target)\n if (anchor) {\n const currentUrl = window.location.href\n const newUrl = anchor.href\n const isAnchor = isAnchorOfCurrentUrl(currentUrl, newUrl)\n const isDownloadLink = anchor.download !== ''\n const isNewTab = anchor.target === '_blank' || event.metaKey || event.ctrlKey\n\n const isPageLeaving = !(newUrl === currentUrl || isAnchor || isDownloadLink || isNewTab)\n\n if (isPageLeaving && prevent && (!onPrevent ? !window.confirm(message) : true)) {\n // Keep a reference of the href\n cancelledURL.current = newUrl\n\n // Cancel the route change\n event.preventDefault()\n event.stopPropagation()\n\n if (typeof onPrevent === 'function') {\n onPrevent()\n }\n }\n }\n } catch (err) {\n console.log('Unexpected exception thrown in LeaveWithoutSaving:usePreventLeave', err)\n }\n }\n\n if (prevent) {\n // Add the global click event listener\n document.addEventListener('click', handleClick, true)\n }\n\n // Clean up the global click event listener when the component is unmounted\n return () => {\n document.removeEventListener('click', handleClick, true)\n }\n }, [onPrevent, prevent, message])\n\n useEffect(() => {\n if (hasAccepted && cancelledURL.current) {\n if (onAccept) {\n onAccept()\n }\n\n startRouteTransition(() => router.push(cancelledURL.current))\n }\n }, [hasAccepted, onAccept, router, startRouteTransition])\n}\n"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,SAAS,QAAQ;AAC1B,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAE/C,SAASC,kBAAkB,QAAQ;AAEnC,SAASC,GACPC,GAAa,EACb,GAAGC,IAA+E;EAElF,IAAID,GAAA,IAAOA,GAAA,CAAIE,gBAAgB,EAAE;IAC/BF,GAAA,CAAIE,gBAAgB,IAAKD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,CAAC3B,SAAA,EAAWC,OAAA,EAASjB,OAAA,CAAQ;EAEhCX,SAAA,CAAU;IACR,IAAIyB,WAAA,IAAeM,YAAA,CAAamC,OAAO,EAAE;MACvC,IAAIxC,QAAA,EAAU;QACZA,QAAA;MACF;MAEAG,oBAAA,CAAqB,MAAMC,MAAA,CAAOuC,IAAI,CAACtC,YAAA,CAAamC,OAAO;IAC7D;EACF,GAAG,CAACzC,WAAA,EAAaC,QAAA,EAAUI,MAAA,EAAQD,oBAAA,CAAqB;AAC1D","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/PreviewButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/PreviewButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,cAAc,CAAA;AAMrB,wBAAgB,aAAa,CAAC,KAAK,EAAE,wBAAwB,qBAoB5D"}
|
|
@@ -4,44 +4,38 @@ import { c as _c } from "react/compiler-runtime";
|
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { ExternalLinkIcon } from '../../icons/ExternalLink/index.js';
|
|
7
|
-
import { usePreviewURL } from './usePreviewURL.js';
|
|
8
7
|
import './index.scss';
|
|
8
|
+
import { usePreviewURL } from '../../providers/LivePreview/context.js';
|
|
9
|
+
import { useTranslation } from '../../providers/Translation/index.js';
|
|
9
10
|
const baseClass = 'preview-btn';
|
|
10
11
|
export function PreviewButton(props) {
|
|
11
|
-
const $ = _c(
|
|
12
|
+
const $ = _c(3);
|
|
12
13
|
const {
|
|
13
|
-
|
|
14
|
-
label
|
|
14
|
+
previewURL
|
|
15
15
|
} = usePreviewURL();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
$[0] = generatePreviewURL;
|
|
24
|
-
$[1] = t0;
|
|
25
|
-
} else {
|
|
26
|
-
t0 = $[1];
|
|
16
|
+
const {
|
|
17
|
+
t
|
|
18
|
+
} = useTranslation();
|
|
19
|
+
if (!previewURL) {
|
|
20
|
+
return null;
|
|
27
21
|
}
|
|
28
|
-
let
|
|
29
|
-
if ($[
|
|
30
|
-
|
|
31
|
-
"aria-label":
|
|
22
|
+
let t0;
|
|
23
|
+
if ($[0] !== previewURL || $[1] !== t) {
|
|
24
|
+
t0 = _jsx("a", {
|
|
25
|
+
"aria-label": t("version:preview"),
|
|
32
26
|
className: baseClass,
|
|
27
|
+
href: previewURL,
|
|
33
28
|
id: "preview-button",
|
|
34
|
-
|
|
35
|
-
title:
|
|
36
|
-
type: "button",
|
|
29
|
+
target: "_blank",
|
|
30
|
+
title: t("version:preview"),
|
|
37
31
|
children: _jsx(ExternalLinkIcon, {})
|
|
38
32
|
});
|
|
39
|
-
$[
|
|
40
|
-
$[
|
|
41
|
-
$[
|
|
33
|
+
$[0] = previewURL;
|
|
34
|
+
$[1] = t;
|
|
35
|
+
$[2] = t0;
|
|
42
36
|
} else {
|
|
43
|
-
|
|
37
|
+
t0 = $[2];
|
|
44
38
|
}
|
|
45
|
-
return
|
|
39
|
+
return t0;
|
|
46
40
|
}
|
|
47
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","ExternalLinkIcon","usePreviewURL","baseClass","PreviewButton","props","$","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","ExternalLinkIcon","usePreviewURL","useTranslation","baseClass","PreviewButton","props","$","previewURL","t","t0","_jsx","className","href","id","target","title","children"],"sources":["../../../src/elements/PreviewButton/index.tsx"],"sourcesContent":["'use client'\nimport type { PreviewButtonClientProps } from 'payload'\n\nimport React from 'react'\n\nimport { ExternalLinkIcon } from '../../icons/ExternalLink/index.js'\nimport './index.scss'\nimport { usePreviewURL } from '../../providers/LivePreview/context.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\n\nconst baseClass = 'preview-btn'\n\nexport function PreviewButton(props: PreviewButtonClientProps) {\n const { previewURL } = usePreviewURL()\n const { t } = useTranslation()\n\n if (!previewURL) {\n return null\n }\n\n return (\n <a\n aria-label={t('version:preview')}\n className={baseClass}\n href={previewURL}\n id=\"preview-button\"\n target=\"_blank\"\n title={t('version:preview')}\n >\n <ExternalLinkIcon />\n </a>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,OAAOC,KAAA,MAAW;AAElB,SAASC,gBAAgB,QAAQ;AACjC,OAAO;AACP,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAE/B,MAAMC,SAAA,GAAY;AAElB,OAAO,SAAAC,cAAAC,KAAA;EAAA,MAAAC,CAAA,GAAAR,EAAA;EACL;IAAAS;EAAA,IAAuBN,aAAA;EACvB;IAAAO;EAAA,IAAcN,cAAA;EAAA,KAETK,UAAA;IAAA;EAAA;EAAA,IAAAE,EAAA;EAAA,IAAAH,CAAA,QAAAC,UAAA,IAAAD,CAAA,QAAAE,CAAA;IAKHC,EAAA,GAAAC,IAAA,CAAC;MAAA,cACaF,CAAA,CAAE;MAAAG,SAAA,EAAAR,SAAA;MAAAS,IAAA,EAERL,UAAA;MAAAM,EAAA,EACH;MAAAC,MAAA,EACI;MAAAC,KAAA,EACAP,CAAA,CAAE;MAAAQ,QAAA,EAETN,IAAA,CAAAV,gBAAA,IAAC;IAAA,C;;;;;;;SARHS,E","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/PublishButton/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAA2C,MAAM,OAAO,CAAA;AAe/D,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,wBAAwB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/PublishButton/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAA2C,MAAM,OAAO,CAAA;AAe/D,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,wBAAwB,qBAwP3E"}
|
|
@@ -143,6 +143,7 @@ export function PublishButton({
|
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
const params = qs.stringify({
|
|
146
|
+
depth: 0,
|
|
146
147
|
publishSpecificLocale: locale
|
|
147
148
|
});
|
|
148
149
|
const action_0 = `${serverURL}${api}${globalSlug ? `/globals/${globalSlug}` : `/${collectionSlug}${id ? `/${id}` : ''}`}${params ? '?' + params : ''}`;
|