@payloadcms/next 3.0.0-beta.95 → 3.0.0-beta.96
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/DocumentHeader/Tabs/index.d.ts.map +1 -1
- package/dist/elements/DocumentHeader/Tabs/index.js +7 -1
- package/dist/elements/DocumentHeader/Tabs/index.js.map +1 -1
- package/dist/elements/DocumentHeader/Tabs/tabs/VersionsPill/index.d.ts.map +1 -1
- package/dist/elements/DocumentHeader/Tabs/tabs/VersionsPill/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.d.ts.map +1 -1
- 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 +3 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js.map +1 -1
- package/dist/elements/Nav/index.client.d.ts.map +1 -1
- package/dist/elements/Nav/index.client.js +1 -1
- package/dist/elements/Nav/index.client.js.map +1 -1
- package/dist/fetchAPI-multipart/fileFactory.d.ts +2 -1
- package/dist/fetchAPI-multipart/fileFactory.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/fileFactory.js.map +1 -1
- package/dist/fetchAPI-multipart/handlers.d.ts +1 -1
- package/dist/fetchAPI-multipart/handlers.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/handlers.js +3 -1
- package/dist/fetchAPI-multipart/handlers.js.map +1 -1
- package/dist/fetchAPI-multipart/index.d.ts +1 -101
- package/dist/fetchAPI-multipart/index.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/index.js.map +1 -1
- package/dist/fetchAPI-multipart/processMultipart.d.ts +2 -1
- package/dist/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/processMultipart.js +2 -0
- package/dist/fetchAPI-multipart/processMultipart.js.map +1 -1
- package/dist/fetchAPI-multipart/processNested.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/processNested.js +6 -2
- package/dist/fetchAPI-multipart/processNested.js.map +1 -1
- package/dist/fetchAPI-multipart/uploadTimer.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/uploadTimer.js +3 -1
- package/dist/fetchAPI-multipart/uploadTimer.js.map +1 -1
- package/dist/fetchAPI-multipart/utilities.d.ts +1 -1
- package/dist/fetchAPI-multipart/utilities.d.ts.map +1 -1
- package/dist/fetchAPI-multipart/utilities.js +32 -12
- package/dist/fetchAPI-multipart/utilities.js.map +1 -1
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/rest/collections/updateByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/updateByID.js +6 -2
- package/dist/routes/rest/collections/updateByID.js.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.d.ts.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.js +3 -1
- package/dist/routes/rest/files/checkFileAccess.js.map +1 -1
- package/dist/routes/rest/files/getFile.d.ts.map +1 -1
- package/dist/routes/rest/files/getFile.js +6 -2
- package/dist/routes/rest/files/getFile.js.map +1 -1
- package/dist/routes/rest/globals/update.d.ts.map +1 -1
- package/dist/routes/rest/globals/update.js +6 -2
- package/dist/routes/rest/globals/update.js.map +1 -1
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +42 -14
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts.map +1 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.js +6 -2
- package/dist/routes/rest/utilities/sanitizeCollectionID.js.map +1 -1
- package/dist/templates/Default/Wrapper/index.scss +0 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/addLocalesToRequest.d.ts.map +1 -1
- package/dist/utilities/addLocalesToRequest.js +6 -2
- package/dist/utilities/addLocalesToRequest.js.map +1 -1
- package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequest.js +9 -3
- package/dist/utilities/createPayloadRequest.js.map +1 -1
- package/dist/utilities/initPage/handleAuthRedirect.d.ts.map +1 -1
- package/dist/utilities/initPage/handleAuthRedirect.js +3 -1
- package/dist/utilities/initPage/handleAuthRedirect.js.map +1 -1
- package/dist/utilities/initPage/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js +3 -1
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/utilities/timestamp.d.ts.map +1 -1
- package/dist/utilities/timestamp.js +3 -1
- package/dist/utilities/timestamp.js.map +1 -1
- package/dist/views/Account/index.d.ts.map +1 -1
- package/dist/views/Account/index.js.map +1 -1
- package/dist/views/Edit/Default/SetDocumentStepNav/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/SetDocumentStepNav/index.js.map +1 -1
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +6 -2
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/List/Default/index.d.ts.map +1 -1
- package/dist/views/List/Default/index.js +94 -84
- package/dist/views/List/Default/index.js.map +1 -1
- package/dist/views/LivePreview/Context/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Context/index.js +3 -1
- package/dist/views/LivePreview/Context/index.js.map +1 -1
- package/dist/views/LivePreview/Device/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Device/index.js +5 -1
- package/dist/views/LivePreview/Device/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/SizeInput/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Toolbar/SizeInput/index.js.map +1 -1
- package/dist/views/Login/LoginForm/index.d.ts.map +1 -1
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/dist/views/Root/isPathMatchingRoute.d.ts.map +1 -1
- package/dist/views/Root/isPathMatchingRoute.js +6 -2
- package/dist/views/Root/isPathMatchingRoute.js.map +1 -1
- package/dist/views/Verify/index.d.ts.map +1 -1
- package/dist/views/Verify/index.js +6 -4
- package/dist/views/Verify/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js +3 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js +3 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js +9 -3
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/index.js +6 -2
- package/dist/views/Version/RenderFieldsToDiff/index.js.map +1 -1
- package/dist/views/Version/SelectComparison/index.d.ts.map +1 -1
- package/dist/views/Version/SelectComparison/index.js +3 -1
- package/dist/views/Version/SelectComparison/index.js.map +1 -1
- package/dist/views/Version/SelectLocales/index.d.ts.map +1 -1
- package/dist/views/Version/SelectLocales/index.js.map +1 -1
- package/dist/views/Versions/cells/CreatedAt/index.d.ts.map +1 -1
- package/dist/views/Versions/cells/CreatedAt/index.js.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/DocumentHeader/Tabs/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,OAAO,cAAc,CAAA;AAKrB,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,YAAY,EAAE,qBAAqB,CAAA;IACnC,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;CACzB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/DocumentHeader/Tabs/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,OAAO,cAAc,CAAA;AAKrB,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,YAAY,EAAE,qBAAqB,CAAA;IACnC,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;CACzB,CAwGA,CAAA"}
|
|
@@ -30,7 +30,13 @@ export const DocumentTabs = props => {
|
|
|
30
30
|
children: /*#__PURE__*/_jsxs("ul", {
|
|
31
31
|
className: `${baseClass}__tabs`,
|
|
32
32
|
children: [Object.entries(defaultTabs)?.sort(([, a], [, b]) => {
|
|
33
|
-
if (a.order === undefined && b.order === undefined)
|
|
33
|
+
if (a.order === undefined && b.order === undefined) {
|
|
34
|
+
return 0;
|
|
35
|
+
} else if (a.order === undefined) {
|
|
36
|
+
return 1;
|
|
37
|
+
} else if (b.order === undefined) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
34
40
|
return a.order - b.order;
|
|
35
41
|
})?.map(([name, tab], index) => {
|
|
36
42
|
const viewConfig = getViewConfig({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["RenderComponent","getCreateMappedComponent","React","ShouldRenderTabs","DocumentTab","getCustomViews","getViewConfig","tabs","defaultTabs","baseClass","DocumentTabs","props","collectionConfig","globalConfig","i18n","payload","permissions","config","customViews","_jsx","className","_jsxs","Object","entries","sort","a","b","order","undefined","map","name","tab","index","viewConfig","tabFromConfig","condition","meetsCondition","Boolean","CustomView","path","Component","createMappedComponent","importMap","serverProps","key","mappedTab","clientProps","mappedComponent"],"sources":["../../../../src/elements/DocumentHeader/Tabs/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type {\n Payload,\n Permissions,\n SanitizedCollectionConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport { RenderComponent, getCreateMappedComponent } from '@payloadcms/ui/shared'\nimport React from 'react'\n\nimport { ShouldRenderTabs } from './ShouldRenderTabs.js'\nimport { DocumentTab } from './Tab/index.js'\nimport { getCustomViews } from './getCustomViews.js'\nimport { getViewConfig } from './getViewConfig.js'\nimport './index.scss'\nimport { tabs as defaultTabs } from './tabs/index.js'\n\nconst baseClass = 'doc-tabs'\n\nexport const DocumentTabs: React.FC<{\n collectionConfig: SanitizedCollectionConfig\n globalConfig: SanitizedGlobalConfig\n i18n: I18n\n payload: Payload\n permissions: Permissions\n}> = (props) => {\n const { collectionConfig, globalConfig, i18n, payload, permissions } = props\n const { config } = payload\n\n const customViews = getCustomViews({ collectionConfig, globalConfig })\n\n return (\n <ShouldRenderTabs>\n <div className={baseClass}>\n <div className={`${baseClass}__tabs-container`}>\n <ul className={`${baseClass}__tabs`}>\n {Object.entries(defaultTabs)\n // sort `defaultViews` based on `order` property from smallest to largest\n // if no `order`, append the view to the end\n // TODO: open `order` to the config and merge `defaultViews` with `customViews`\n ?.sort(([, a], [, b]) => {\n if (a.order === undefined && b.order === undefined) return 0\n else if (a.order === undefined) return 1\n else if (b.order === undefined) return -1\n return a.order - b.order\n })\n ?.map(([name, tab], index) => {\n const viewConfig = getViewConfig({ name, collectionConfig, globalConfig })\n const tabFromConfig = viewConfig && 'tab' in viewConfig ? viewConfig.tab : undefined\n\n const { condition } = tabFromConfig || {}\n\n const meetsCondition =\n !condition ||\n (condition &&\n Boolean(condition({ collectionConfig, config, globalConfig, permissions })))\n\n if (meetsCondition) {\n return (\n <DocumentTab\n key={`tab-${index}`}\n {...{\n ...props,\n ...(tab || {}),\n ...(tabFromConfig || {}),\n }}\n />\n )\n }\n\n return null\n })}\n {customViews?.map((CustomView, index) => {\n if ('tab' in CustomView) {\n const { path, tab } = CustomView\n\n if (tab.Component) {\n const createMappedComponent = getCreateMappedComponent({\n importMap: payload.importMap,\n serverProps: {\n i18n,\n payload,\n permissions,\n ...props,\n key: `tab-custom-${index}`,\n path,\n },\n })\n\n const mappedTab = createMappedComponent(\n tab.Component,\n undefined,\n undefined,\n 'tab.Component',\n )\n\n return (\n <RenderComponent\n clientProps={{\n key: `tab-custom-${index}`,\n path,\n }}\n key={`tab-custom-${index}`}\n mappedComponent={mappedTab}\n />\n )\n }\n\n return (\n <DocumentTab\n key={`tab-custom-${index}`}\n {...{\n ...props,\n ...tab,\n }}\n />\n )\n }\n return null\n })}\n </ul>\n </div>\n </div>\n </ShouldRenderTabs>\n )\n}\n"],"mappings":";AAQA,SAASA,eAAe,EAAEC,wBAAwB,QAAQ;AAC1D,OAAOC,KAAA,MAAW;AAElB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ;AAE9B,SAASC,IAAA,IAAQC,WAAW,QAAQ;AAEpC,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,YAAA,GAMPC,KAAA;EACJ,MAAM;IAAEC,gBAAgB;IAAEC,YAAY;IAAEC,IAAI;IAAEC,OAAO;IAAEC;EAAW,CAAE,GAAGL,KAAA;EACvE,MAAM;IAAEM;EAAM,CAAE,GAAGF,OAAA;EAEnB,MAAMG,WAAA,GAAcb,cAAA,CAAe;IAAEO,gBAAA;IAAkBC;EAAa;EAEpE,oBACEM,IAAA,CAAChB,gBAAA;cACC,aAAAgB,IAAA,CAAC;MAAIC,SAAA,EAAWX,SAAA;gBACd,aAAAU,IAAA,CAAC;QAAIC,SAAA,EAAW,GAAGX,SAAA,kBAA2B;kBAC5C,aAAAY,KAAA,CAAC;UAAGD,SAAA,EAAW,GAAGX,SAAA,QAAiB;qBAChCa,MAAA,CAAOC,OAAO,CAACf,WAAA,GAIZgB,IAAA,CAAK,CAAC,GAAGC,CAAA,CAAE,EAAE,GAAGC,CAAA,CAAE;YAClB,IAAID,CAAA,CAAEE,KAAK,KAAKC,SAAA,IAAaF,CAAA,CAAEC,KAAK,KAAKC,SAAA,EAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","names":["RenderComponent","getCreateMappedComponent","React","ShouldRenderTabs","DocumentTab","getCustomViews","getViewConfig","tabs","defaultTabs","baseClass","DocumentTabs","props","collectionConfig","globalConfig","i18n","payload","permissions","config","customViews","_jsx","className","_jsxs","Object","entries","sort","a","b","order","undefined","map","name","tab","index","viewConfig","tabFromConfig","condition","meetsCondition","Boolean","CustomView","path","Component","createMappedComponent","importMap","serverProps","key","mappedTab","clientProps","mappedComponent"],"sources":["../../../../src/elements/DocumentHeader/Tabs/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type {\n Payload,\n Permissions,\n SanitizedCollectionConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport { RenderComponent, getCreateMappedComponent } from '@payloadcms/ui/shared'\nimport React from 'react'\n\nimport { ShouldRenderTabs } from './ShouldRenderTabs.js'\nimport { DocumentTab } from './Tab/index.js'\nimport { getCustomViews } from './getCustomViews.js'\nimport { getViewConfig } from './getViewConfig.js'\nimport './index.scss'\nimport { tabs as defaultTabs } from './tabs/index.js'\n\nconst baseClass = 'doc-tabs'\n\nexport const DocumentTabs: React.FC<{\n collectionConfig: SanitizedCollectionConfig\n globalConfig: SanitizedGlobalConfig\n i18n: I18n\n payload: Payload\n permissions: Permissions\n}> = (props) => {\n const { collectionConfig, globalConfig, i18n, payload, permissions } = props\n const { config } = payload\n\n const customViews = getCustomViews({ collectionConfig, globalConfig })\n\n return (\n <ShouldRenderTabs>\n <div className={baseClass}>\n <div className={`${baseClass}__tabs-container`}>\n <ul className={`${baseClass}__tabs`}>\n {Object.entries(defaultTabs)\n // sort `defaultViews` based on `order` property from smallest to largest\n // if no `order`, append the view to the end\n // TODO: open `order` to the config and merge `defaultViews` with `customViews`\n ?.sort(([, a], [, b]) => {\n if (a.order === undefined && b.order === undefined) {\n return 0\n } else if (a.order === undefined) {\n return 1\n } else if (b.order === undefined) {\n return -1\n }\n return a.order - b.order\n })\n ?.map(([name, tab], index) => {\n const viewConfig = getViewConfig({ name, collectionConfig, globalConfig })\n const tabFromConfig = viewConfig && 'tab' in viewConfig ? viewConfig.tab : undefined\n\n const { condition } = tabFromConfig || {}\n\n const meetsCondition =\n !condition ||\n (condition &&\n Boolean(condition({ collectionConfig, config, globalConfig, permissions })))\n\n if (meetsCondition) {\n return (\n <DocumentTab\n key={`tab-${index}`}\n {...{\n ...props,\n ...(tab || {}),\n ...(tabFromConfig || {}),\n }}\n />\n )\n }\n\n return null\n })}\n {customViews?.map((CustomView, index) => {\n if ('tab' in CustomView) {\n const { path, tab } = CustomView\n\n if (tab.Component) {\n const createMappedComponent = getCreateMappedComponent({\n importMap: payload.importMap,\n serverProps: {\n i18n,\n payload,\n permissions,\n ...props,\n key: `tab-custom-${index}`,\n path,\n },\n })\n\n const mappedTab = createMappedComponent(\n tab.Component,\n undefined,\n undefined,\n 'tab.Component',\n )\n\n return (\n <RenderComponent\n clientProps={{\n key: `tab-custom-${index}`,\n path,\n }}\n key={`tab-custom-${index}`}\n mappedComponent={mappedTab}\n />\n )\n }\n\n return (\n <DocumentTab\n key={`tab-custom-${index}`}\n {...{\n ...props,\n ...tab,\n }}\n />\n )\n }\n return null\n })}\n </ul>\n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Q,eAAA,EAAiBF;mBADZ,cAAcb,KAAA,EAAO;cAIhC;cAEA,oBACEb,IAAA,CAACf,WAAA;gBAGG,GAAGO,KAAK;gBACR,GAAGoB;iBAHA,cAAcC,KAAA,EAAO;YAOhC;YACA,OAAO;UACT;;;;;AAMZ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/elements/DocumentHeader/Tabs/tabs/VersionsPill/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/elements/DocumentHeader/Tabs/tabs/VersionsPill/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAmBhC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useDocumentInfo","React","baseClass","VersionsPill","$","versions","hasVersions","totalDocs","t0","t1","filter","Boolean","t2","join","t3","_jsx","className","children","toString"],"sources":["../../../../../../src/elements/DocumentHeader/Tabs/tabs/VersionsPill/index.tsx"],"sourcesContent":["'use client'\nimport { useDocumentInfo } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { baseClass } from '../../Tab/index.js'\n\nexport const VersionsPill: React.FC = () => {\n const { versions } = useDocumentInfo()\n\n // To prevent CLS (versions are currently loaded client-side), render non-breaking space if there are no versions\n // The pill is already conditionally rendered to begin with based on whether the document is version-enabled\n // documents that are version enabled _always_ have at least one version\n const hasVersions = versions?.totalDocs > 0\n\n if (hasVersions)\n return (\n <span\n className={[`${baseClass}__count`, hasVersions ? `${baseClass}__count--has-count` : '']\n .filter(Boolean)\n .join(' ')}\n >\n {versions.totalDocs.toString()}\n </span>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,eAAe,QAAQ;AAChC,OAAOC,KAAA,MAAW;AAElB,SAASC,SAAS,QAAQ;AAE1B,OAAO,MAAMC,YAAA,GAAyBA,CAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EACpC;IAAAM;EAAA,IAAqBL,eAAA;EAKrB,MAAAM,WAAA,GAAoBD,QAAA,EAAAE,SAAA,IAAsB;EAAA,IAEtCD,WAAA;IAGqC,MAAAE,EAAA,GAAAF,WAAA,GAAc,GAAAJ,SAAA,oBAAgC,GAAG;IAAA,IAAAO,EAAA;IAAA,IAAAL,CAAA,QAAAI,EAAA;MAAzEC,EAAA,IAAC,GAAAP,SAAA,SAAqB,EAAEM,EAAiD,EAAAE,MAAA,CAAAC,OAC1E;MAAAP,CAAA,MAAAI,EAAA;MAAAJ,CAAA,MAAAK,EAAA;IAAA;MAAAA,EAAA,GAAAL,CAAA;IAAA;IADC,MAAAQ,EAAA,GAAAH,EACD,CAAAI,IAAA,CACF;IAAA,IAAAC,EAAA;IAAA,IAAAV,CAAA,QAAAC,QAAA,CAAAE,SAAA,IAAAH,CAAA,QAAAQ,EAAA;MAHVE,EAAA,GAAAC,IAAA,CAAC;QAAAC,SAAA,EACYJ,EAEH;QAAAK,QAAA,EAEPZ,QAAA,CAAAE,SAAA,CAAAW,QAAA,CAA2B;MAAA,C;;;;;;;WAL9BJ,E;;
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useDocumentInfo","React","baseClass","VersionsPill","$","versions","hasVersions","totalDocs","t0","t1","filter","Boolean","t2","join","t3","_jsx","className","children","toString"],"sources":["../../../../../../src/elements/DocumentHeader/Tabs/tabs/VersionsPill/index.tsx"],"sourcesContent":["'use client'\nimport { useDocumentInfo } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { baseClass } from '../../Tab/index.js'\n\nexport const VersionsPill: React.FC = () => {\n const { versions } = useDocumentInfo()\n\n // To prevent CLS (versions are currently loaded client-side), render non-breaking space if there are no versions\n // The pill is already conditionally rendered to begin with based on whether the document is version-enabled\n // documents that are version enabled _always_ have at least one version\n const hasVersions = versions?.totalDocs > 0\n\n if (hasVersions) {\n return (\n <span\n className={[`${baseClass}__count`, hasVersions ? `${baseClass}__count--has-count` : '']\n .filter(Boolean)\n .join(' ')}\n >\n {versions.totalDocs.toString()}\n </span>\n )\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,eAAe,QAAQ;AAChC,OAAOC,KAAA,MAAW;AAElB,SAASC,SAAS,QAAQ;AAE1B,OAAO,MAAMC,YAAA,GAAyBA,CAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EACpC;IAAAM;EAAA,IAAqBL,eAAA;EAKrB,MAAAM,WAAA,GAAoBD,QAAA,EAAAE,SAAA,IAAsB;EAAA,IAEtCD,WAAA;IAGqC,MAAAE,EAAA,GAAAF,WAAA,GAAc,GAAAJ,SAAA,oBAAgC,GAAG;IAAA,IAAAO,EAAA;IAAA,IAAAL,CAAA,QAAAI,EAAA;MAAzEC,EAAA,IAAC,GAAAP,SAAA,SAAqB,EAAEM,EAAiD,EAAAE,MAAA,CAAAC,OAC1E;MAAAP,CAAA,MAAAI,EAAA;MAAAJ,CAAA,MAAAK,EAAA;IAAA;MAAAA,EAAA,GAAAL,CAAA;IAAA;IADC,MAAAQ,EAAA,GAAAH,EACD,CAAAI,IAAA,CACF;IAAA,IAAAC,EAAA;IAAA,IAAAV,CAAA,QAAAC,QAAA,CAAAE,SAAA,IAAAH,CAAA,QAAAQ,EAAA;MAHVE,EAAA,GAAAC,IAAA,CAAC;QAAAC,SAAA,EACYJ,EAEH;QAAAK,QAAA,EAEPZ,QAAA,CAAAE,SAAA,CAAAW,QAAA,CAA2B;MAAA,C;;;;;;;WAL9BJ,E;;CASN","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAErD,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAErD,OAAO,cAAc,CAAA;AAkDrB,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EA8BtC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","Button","Modal","useAuth","useFormModified","useModal","useTranslation","React","useCallback","useEffect","usePreventLeave","modalSlug","baseClass","Component","t0","$","isActive","onCancel","onConfirm","closeModal","openModal","t","t1","t2","t3","_jsx","className","onClose","slug","children","_jsxs","buttonStyle","onClick","size","LeaveWithoutSaving","modified","user","show","setShow","useState","hasAccepted","setHasAccepted","prevent","Boolean","Symbol","for","onPrevent","handleAccept","onAccept","t4","t5"],"sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"sourcesContent":["'use client'\nimport { Button, Modal, useAuth, useFormModified, useModal, useTranslation } from '@payloadcms/ui'\nimport React, { useCallback, useEffect } from 'react'\n\nimport './index.scss'\nimport { usePreventLeave } from './usePreventLeave.js'\n\nconst modalSlug = 'leave-without-saving'\n\nconst baseClass = 'leave-without-saving'\n\nconst Component: React.FC<{\n isActive: boolean\n onCancel: () => void\n onConfirm: () => void\n}> = ({ isActive, onCancel, onConfirm }) => {\n const { closeModal, modalState, openModal } = useModal()\n const { t } = useTranslation()\n\n // Manually check for modal state as 'esc' key will not trigger the nav inactivity\n // useEffect(() => {\n // if (!modalState?.[modalSlug]?.isOpen && isActive) {\n // onCancel()\n // }\n // }, [modalState, isActive, onCancel])\n\n useEffect(() => {\n if (isActive) openModal(modalSlug)\n else closeModal(modalSlug)\n }, [isActive, openModal, closeModal])\n\n return (\n <Modal className={baseClass} onClose={onCancel} slug={modalSlug}>\n <div className={`${baseClass}__wrapper`}>\n <div className={`${baseClass}__content`}>\n <h1>{t('general:leaveWithoutSaving')}</h1>\n <p>{t('general:changesNotSaved')}</p>\n </div>\n <div className={`${baseClass}__controls`}>\n <Button buttonStyle=\"secondary\" onClick={onCancel} size=\"large\">\n {t('general:stayOnThisPage')}\n </Button>\n <Button onClick={onConfirm} size=\"large\">\n {t('general:leaveAnyway')}\n </Button>\n </div>\n </div>\n </Modal>\n )\n}\n\nexport const LeaveWithoutSaving: React.FC = () => {\n const { closeModal } = useModal()\n const modified = useFormModified()\n const { user } = useAuth()\n const [show, setShow] = React.useState(false)\n const [hasAccepted, setHasAccepted] = React.useState(false)\n\n const prevent = Boolean(modified && user)\n\n const onPrevent = useCallback(() => {\n setShow(true)\n }, [])\n\n const handleAccept = useCallback(() => {\n closeModal(modalSlug)\n }, [closeModal])\n\n usePreventLeave({ hasAccepted, onAccept: handleAccept, onPrevent, prevent })\n\n return (\n <Component\n isActive={show}\n onCancel={() => {\n setShow(false)\n }}\n onConfirm={() => {\n setHasAccepted(true)\n }}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,cAAc,QAAQ;AAClF,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,QAAQ;AAG9C,SAASC,eAAe,QAAQ;AAEhC,MAAMC,SAAA,GAAY;AAElB,MAAMC,SAAA,GAAY;AAElB,MAAMC,SAAA,GAIDC,EAAA;EAAA,MAAAC,CAAA,GAAAf,EAAA;EAAC;IAAAgB,QAAA;IAAAC,QAAA;IAAAC;EAAA,IAAAJ,EAAiC;EACrC;IAAAK,UAAA;IAAAC;EAAA,IAA8Cf,QAAA;EAC9C;IAAAgB;EAAA,IAAcf,cAAA;EAAA,IAAAgB,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,QAAA,IAAAD,CAAA,QAAAK,SAAA,IAAAL,CAAA,QAAAI,UAAA;IASJG,EAAA,GAAAA,CAAA;MAAA,IACJN,QAAA;
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","Button","Modal","useAuth","useFormModified","useModal","useTranslation","React","useCallback","useEffect","usePreventLeave","modalSlug","baseClass","Component","t0","$","isActive","onCancel","onConfirm","closeModal","openModal","t","t1","t2","t3","_jsx","className","onClose","slug","children","_jsxs","buttonStyle","onClick","size","LeaveWithoutSaving","modified","user","show","setShow","useState","hasAccepted","setHasAccepted","prevent","Boolean","Symbol","for","onPrevent","handleAccept","onAccept","t4","t5"],"sources":["../../../src/elements/LeaveWithoutSaving/index.tsx"],"sourcesContent":["'use client'\nimport { Button, Modal, useAuth, useFormModified, useModal, useTranslation } from '@payloadcms/ui'\nimport React, { useCallback, useEffect } from 'react'\n\nimport './index.scss'\nimport { usePreventLeave } from './usePreventLeave.js'\n\nconst modalSlug = 'leave-without-saving'\n\nconst baseClass = 'leave-without-saving'\n\nconst Component: React.FC<{\n isActive: boolean\n onCancel: () => void\n onConfirm: () => void\n}> = ({ isActive, onCancel, onConfirm }) => {\n const { closeModal, modalState, openModal } = useModal()\n const { t } = useTranslation()\n\n // Manually check for modal state as 'esc' key will not trigger the nav inactivity\n // useEffect(() => {\n // if (!modalState?.[modalSlug]?.isOpen && isActive) {\n // onCancel()\n // }\n // }, [modalState, isActive, onCancel])\n\n useEffect(() => {\n if (isActive) {\n openModal(modalSlug)\n } else {\n closeModal(modalSlug)\n }\n }, [isActive, openModal, closeModal])\n\n return (\n <Modal className={baseClass} onClose={onCancel} slug={modalSlug}>\n <div className={`${baseClass}__wrapper`}>\n <div className={`${baseClass}__content`}>\n <h1>{t('general:leaveWithoutSaving')}</h1>\n <p>{t('general:changesNotSaved')}</p>\n </div>\n <div className={`${baseClass}__controls`}>\n <Button buttonStyle=\"secondary\" onClick={onCancel} size=\"large\">\n {t('general:stayOnThisPage')}\n </Button>\n <Button onClick={onConfirm} size=\"large\">\n {t('general:leaveAnyway')}\n </Button>\n </div>\n </div>\n </Modal>\n )\n}\n\nexport const LeaveWithoutSaving: React.FC = () => {\n const { closeModal } = useModal()\n const modified = useFormModified()\n const { user } = useAuth()\n const [show, setShow] = React.useState(false)\n const [hasAccepted, setHasAccepted] = React.useState(false)\n\n const prevent = Boolean(modified && user)\n\n const onPrevent = useCallback(() => {\n setShow(true)\n }, [])\n\n const handleAccept = useCallback(() => {\n closeModal(modalSlug)\n }, [closeModal])\n\n usePreventLeave({ hasAccepted, onAccept: handleAccept, onPrevent, prevent })\n\n return (\n <Component\n isActive={show}\n onCancel={() => {\n setShow(false)\n }}\n onConfirm={() => {\n setHasAccepted(true)\n }}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,cAAc,QAAQ;AAClF,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,QAAQ;AAG9C,SAASC,eAAe,QAAQ;AAEhC,MAAMC,SAAA,GAAY;AAElB,MAAMC,SAAA,GAAY;AAElB,MAAMC,SAAA,GAIDC,EAAA;EAAA,MAAAC,CAAA,GAAAf,EAAA;EAAC;IAAAgB,QAAA;IAAAC,QAAA;IAAAC;EAAA,IAAAJ,EAAiC;EACrC;IAAAK,UAAA;IAAAC;EAAA,IAA8Cf,QAAA;EAC9C;IAAAgB;EAAA,IAAcf,cAAA;EAAA,IAAAgB,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,QAAA,IAAAD,CAAA,QAAAK,SAAA,IAAAL,CAAA,QAAAI,UAAA;IASJG,EAAA,GAAAA,CAAA;MAAA,IACJN,QAAA;QACFI,SAAA,CAAAT,SAAU;MAAA;QAEVQ,UAAA,CAAAR,SAAW;MAAA;IAAA;IAEZY,EAAA,IAACP,QAAA,EAAUI,SAAA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,GAAAA,CAAA;MACRc,OAAA,MAAQ;IAAA;IAECW,EAAA,GAAAA,CAAA;MACTR,cAAA,KAAe;IAAA;IACjB1B,CAAA,MAAAS,EAAA;IAAAT,CAAA,MAAAkC,EAAA;EAAA;IAAAzB,EAAA,GAAAT,CAAA;IAAAkC,EAAA,GAAAlC,CAAA;EAAA;EAAA,IAAAmC,EAAA;EAAA,IAAAnC,CAAA,QAAAsB,IAAA;IAPFa,EAAA,GAAAzB,IAAA,CAAAZ,SAAA;MAAAG,QAAA,EACYqB,IAAA;MAAApB,QAAA,EACAO,EAEV;MAAAN,SAAA,EACW+B;IAEX,C;;;;;;SAPFC,E;CAUJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreventLeave.d.ts","sourceRoot":"","sources":["../../../src/elements/LeaveWithoutSaving/usePreventLeave.tsx"],"names":[],"mappings":"AA0BA,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":"AA0BA,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,SAkFA,CAAA"}
|
|
@@ -126,7 +126,9 @@ export const usePreventLeave = ({
|
|
|
126
126
|
}, [onPrevent, prevent, message]);
|
|
127
127
|
useEffect(() => {
|
|
128
128
|
if (hasAccepted && cancelledURL.current) {
|
|
129
|
-
if (onAccept)
|
|
129
|
+
if (onAccept) {
|
|
130
|
+
onAccept();
|
|
131
|
+
}
|
|
130
132
|
router.push(cancelledURL.current);
|
|
131
133
|
}
|
|
132
134
|
}, [hasAccepted, onAccept, router]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreventLeave.js","names":["c","_c","useRouter","useCallback","useEffect","useRef","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","router","cancelledURL","isAnchorOfCurrentUrl","currentUrl","newUrl","currentUrlObj","URL","newUrlObj","hostname","pathname","search","currentHash","hash","newHash","href","replace","findClosestAnchor","element","tagName","toLowerCase","parentElement","handleClick","target","anchor","location","isAnchor","isDownloadLink","download","isPageLeaving","confirm","current","stopPropagation","err","alert","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\nfunction on<T extends Document | EventTarget | HTMLElement | Window>(\n obj: T | null,\n ...args: [string, Function | 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: T | null,\n ...args: [string, Function | 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\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 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 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 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\n const isPageLeaving = !(newUrl === currentUrl || isAnchor || isDownloadLink)\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 alert(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) onAccept()\n router.push(cancelledURL.current)\n }\n }, [hasAccepted, onAccept, router])\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,GACPC,GAAa,EACb,GAAGC,IAA2E;EAE9E,IAAID,GAAA,IAAOA,GAAA,CAAIE,gBAAgB,EAAE;IAC/BF,GAAA,CAAIE,gBAAgB,IAAKD,IAAA;EAC3B;AACF;AAEA,SAASE,IACPH,GAAa,EACb,GAAGC,IAA8E;EAEjF,IAAID,GAAA,IAAOA,GAAA,CAAII,mBAAmB,EAAE;IAClCJ,GAAA,CAAII,mBAAmB,IAAKH,IAAA;EAC9B;AACF;AAEA,OAAO,MAAMI,eAAA,GAAkBA,CAAAC,EAAA,EAAAC,OAAA;EAAA,MAAAC,CAAA,GAA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C,QAAA;UAClD,MAAMsB,cAAA,GAAiBH,MAAA,CAAOI,QAAQ,KAAK;UAE3C,MAAMC,aAAA,GAAgB,EAAExB,QAAA,KAAWD,YAAA,IAAcsB,QAAA,IAAYC,cAAa;UAE1E,IAAIE,aAAA,IAAiB7B,OAAA,KAAY,CAACD,SAAA,GAAY,CAACJ,MAAA,CAAOmC,OAAO,CAAC/C,OAAA,IAAW,IAAG,GAAI;YAC9E;YACAmB,YAAA,CAAa6B,OAAO,GAAG1B,QAAA;YAEvB;YACAjB,KAAA,CAAME,cAAc;YACpBF,KAAA,CAAM4C,eAAe;YAErB,IAAI,OAAOjC,SAAA,KAAc,YAAY;cACnCA,SAAA;YACF;UACF;QACF;MACF,EAAE,OAAOkC,GAAA,EAAK;QACZC,KAAA,CAAMD,GAAA;MACR;IACF;IAEA;IACAE,QAAA,CAASzD,gBAAgB,CAAC,SAAS4C,WAAA,EAAa;IAEhD;IACA,OAAO;MACLa,QAAA,CAASvD,mBAAmB,CAAC,SAAS0C,WAAA,EAAa;IACrD;EACF,GAAG,CAACvB,SAAA,EAAWC,OAAA,EAASjB,OAAA,CAAQ;EAEhCV,SAAA,CAAU;IACR,IAAIwB,WAAA,IAAeK,YAAA,CAAa6B,OAAO,EAAE;MACvC,IAAIjC,QAAA,
|
|
1
|
+
{"version":3,"file":"usePreventLeave.js","names":["c","_c","useRouter","useCallback","useEffect","useRef","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","router","cancelledURL","isAnchorOfCurrentUrl","currentUrl","newUrl","currentUrlObj","URL","newUrlObj","hostname","pathname","search","currentHash","hash","newHash","href","replace","findClosestAnchor","element","tagName","toLowerCase","parentElement","handleClick","target","anchor","location","isAnchor","isDownloadLink","download","isPageLeaving","confirm","current","stopPropagation","err","alert","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\nfunction on<T extends Document | EventTarget | HTMLElement | Window>(\n obj: T | null,\n ...args: [string, Function | 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: T | null,\n ...args: [string, Function | 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\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 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 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 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\n const isPageLeaving = !(newUrl === currentUrl || isAnchor || isDownloadLink)\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 alert(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 router.push(cancelledURL.current)\n }\n }, [hasAccepted, onAccept, router])\n}\n"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,SAAS,QAAQ;AAC1B,SAASC,WAAW,EAA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;MACF;MACAG,MAAA,CAAOmC,IAAI,CAAClC,YAAA,CAAa6B,OAAO;IAClC;EACF,GAAG,CAAClC,WAAA,EAAaC,QAAA,EAAUG,MAAA,CAAO;AACpC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/elements/Nav/index.client.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAIvC,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/elements/Nav/index.client.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAIvC,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EA4FpC,CAAA"}
|
|
@@ -103,7 +103,7 @@ export const DefaultNavClient = () => {
|
|
|
103
103
|
}
|
|
104
104
|
const Link = LinkWithDefault.default || LinkWithDefault;
|
|
105
105
|
const LinkElement = Link || "a";
|
|
106
|
-
const activeCollection = pathname.startsWith(href);
|
|
106
|
+
const activeCollection = pathname.startsWith(href) && ["/", undefined].includes(pathname[href.length]);
|
|
107
107
|
return _jsxs(LinkElement, {
|
|
108
108
|
className: [`${baseClass}__link`, activeCollection && `active`].filter(Boolean).join(" "),
|
|
109
109
|
href,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.js","names":["c","_c","getTranslation","NavGroup","useAuth","useConfig","useEntityVisibility","useNav","useTranslation","EntityType","formatAdminURL","groupNavItems","LinkWithDefault","usePathname","React","Fragment","baseClass","DefaultNavClient","$","permissions","isEntityVisible","pathname","config","t0","collections","globals","routes","t1","admin","adminRoute","i18n","navOpen","t2","t3","t4","slug","collectionSlug","t5","slug_0","globalSlug","groups","filter","map","_temp","_temp2","t6","key","entities","label","_jsx","children","t7","i","type","entity","entityLabel","href","id","collection","labels","plural","global","Link","default","LinkElement","activeCollection","startsWith","_jsxs","className","Boolean","join","tabIndex","
|
|
1
|
+
{"version":3,"file":"index.client.js","names":["c","_c","getTranslation","NavGroup","useAuth","useConfig","useEntityVisibility","useNav","useTranslation","EntityType","formatAdminURL","groupNavItems","LinkWithDefault","usePathname","React","Fragment","baseClass","DefaultNavClient","$","permissions","isEntityVisible","pathname","config","t0","collections","globals","routes","t1","admin","adminRoute","i18n","navOpen","t2","t3","t4","slug","collectionSlug","t5","slug_0","globalSlug","groups","filter","map","_temp","_temp2","t6","key","entities","label","_jsx","children","t7","i","type","entity","entityLabel","href","id","collection","labels","plural","global","Link","default","LinkElement","activeCollection","startsWith","undefined","includes","length","_jsxs","className","Boolean","join","tabIndex","entityToGroup","entityToGroup_0"],"sources":["../../../src/elements/Nav/index.client.tsx"],"sourcesContent":["'use client'\n\nimport type { EntityToGroup } from '@payloadcms/ui/shared'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n ChevronIcon,\n NavGroup,\n useAuth,\n useConfig,\n useEntityVisibility,\n useNav,\n useTranslation,\n} from '@payloadcms/ui'\nimport { EntityType, formatAdminURL, groupNavItems } from '@payloadcms/ui/shared'\nimport LinkWithDefault from 'next/link.js'\nimport { usePathname } from 'next/navigation.js'\nimport React, { Fragment } from 'react'\n\nconst baseClass = 'nav'\n\nexport const DefaultNavClient: React.FC = () => {\n const { permissions } = useAuth()\n const { isEntityVisible } = useEntityVisibility()\n const pathname = usePathname()\n\n const {\n config: {\n collections,\n globals,\n routes: { admin: adminRoute },\n },\n } = useConfig()\n\n const { i18n } = useTranslation()\n const { navOpen } = useNav()\n\n const groups = groupNavItems(\n [\n ...collections\n .filter(({ slug }) => isEntityVisible({ collectionSlug: slug }))\n .map((collection) => {\n const entityToGroup: EntityToGroup = {\n type: EntityType.collection,\n entity: collection,\n }\n\n return entityToGroup\n }),\n ...globals\n .filter(({ slug }) => isEntityVisible({ globalSlug: slug }))\n .map((global) => {\n const entityToGroup: EntityToGroup = {\n type: EntityType.global,\n entity: global,\n }\n\n return entityToGroup\n }),\n ],\n permissions,\n i18n,\n )\n\n return (\n <Fragment>\n {groups.map(({ entities, label }, key) => {\n return (\n <NavGroup key={key} label={label}>\n {entities.map(({ type, entity }, i) => {\n let entityLabel: string\n let href: string\n let id: string\n\n if (type === EntityType.collection) {\n href = formatAdminURL({ adminRoute, path: `/collections/${entity.slug}` })\n entityLabel = getTranslation(entity.labels.plural, i18n)\n id = `nav-${entity.slug}`\n }\n\n if (type === EntityType.global) {\n href = formatAdminURL({ adminRoute, path: `/globals/${entity.slug}` })\n entityLabel = getTranslation(entity.label, i18n)\n id = `nav-global-${entity.slug}`\n }\n\n const Link = (LinkWithDefault.default ||\n LinkWithDefault) as typeof LinkWithDefault.default\n\n const LinkElement = Link || 'a'\n const activeCollection =\n pathname.startsWith(href) && ['/', undefined].includes(pathname[href.length])\n\n return (\n <LinkElement\n className={[`${baseClass}__link`, activeCollection && `active`]\n .filter(Boolean)\n .join(' ')}\n href={href}\n id={id}\n key={i}\n tabIndex={!navOpen ? -1 : undefined}\n >\n {activeCollection && <div className={`${baseClass}__link-indicator`} />}\n <span className={`${baseClass}__link-label`}>{entityLabel}</span>\n </LinkElement>\n )\n })}\n </NavGroup>\n )\n })}\n </Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,cAAc,QAAQ;AAC/B,SAEEC,QAAQ,EACRC,OAAO,EACPC,SAAS,EACTC,mBAAmB,EACnBC,MAAM,EACNC,cAAc,QACT;AACP,SAASC,UAAU,EAAEC,cAAc,EAAEC,aAAa,QAAQ;AAC1D,OAAOC,eAAA,MAAqB;AAC5B,SAASC,WAAW,QAAQ;AAC5B,OAAOC,KAAA,IAASC,QAAQ,QAAQ;AAEhC,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,gBAAA,GAA6BA,CAAA;EAAA,MAAAC,CAAA,GAAAjB,EAAA;EACxC;IAAAkB;EAAA,IAAwBf,OAAA;EACxB;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AP,MAAA,EAEUO;EAAA;EACV,OAEOc,eAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileFactory.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/fileFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"fileFactory.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/fileFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAmC3C,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AACD,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,kBAAkB,EAC3B,iBAAiB,EAAE,yBAAyB,KACzC,SAAS,CAAA;AACd,eAAO,MAAM,WAAW,EAAE,WA4BzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileFactory.js","names":["checkAndMakeDir","debugLog","isFunc","moveFile","promiseCallback","saveBufferToFile","moveFromTemp","filePath","options","fileUploadOptions","resolve","reject","tempFilePath","moveFromBuffer","buffer","fileFactory","name","data","encoding","md5","hash","mimetype","mv","callback","moveFunc","useTempFiles","defaultReject","undefined","Promise","size","truncated"],"sources":["../../src/fetchAPI-multipart/fileFactory.ts"],"sourcesContent":["import type { FetchAPIFileUploadOptions
|
|
1
|
+
{"version":3,"file":"fileFactory.js","names":["checkAndMakeDir","debugLog","isFunc","moveFile","promiseCallback","saveBufferToFile","moveFromTemp","filePath","options","fileUploadOptions","resolve","reject","tempFilePath","moveFromBuffer","buffer","fileFactory","name","data","encoding","md5","hash","mimetype","mv","callback","moveFunc","useTempFiles","defaultReject","undefined","Promise","size","truncated"],"sources":["../../src/fetchAPI-multipart/fileFactory.ts"],"sourcesContent":["import type { FetchAPIFileUploadOptions } from 'payload'\n\nimport type { FileShape } from './index.js'\n\nimport {\n checkAndMakeDir,\n debugLog,\n isFunc,\n moveFile,\n promiseCallback,\n saveBufferToFile,\n} from './utilities.js'\n\ntype MoveFile = (\n filePath: string,\n options: FileFactoryOptions,\n fileUploadOptions: FetchAPIFileUploadOptions,\n) => (resolve: () => void, reject: () => void) => void\n\n/**\n * Returns Local function that moves the file to a different location on the filesystem\n * which takes two function arguments to make it compatible w/ Promise or Callback APIs\n */\nconst moveFromTemp: MoveFile = (filePath, options, fileUploadOptions) => (resolve, reject) => {\n debugLog(fileUploadOptions, `Moving temporary file ${options.tempFilePath} to ${filePath}`)\n moveFile(options.tempFilePath, filePath, promiseCallback(resolve, reject))\n}\n\n/**\n * Returns Local function that moves the file from buffer to a different location on the filesystem\n * which takes two function arguments to make it compatible w/ Promise or Callback APIs\n */\nconst moveFromBuffer: MoveFile = (filePath, options, fileUploadOptions) => (resolve, reject) => {\n debugLog(fileUploadOptions, `Moving uploaded buffer to ${filePath}`)\n saveBufferToFile(options.buffer, filePath, promiseCallback(resolve, reject))\n}\n\ntype FileFactoryOptions = {\n buffer: Buffer\n encoding: string\n hash: Buffer | string\n mimetype: string\n name: string\n size: number\n tempFilePath: string\n truncated: boolean\n}\ntype FileFactory = (\n options: FileFactoryOptions,\n fileUploadOptions: FetchAPIFileUploadOptions,\n) => FileShape\nexport const fileFactory: FileFactory = (options, fileUploadOptions) => {\n // see: https://github.com/richardgirges/express-fileupload/issues/14\n // firefox uploads empty file in case of cache miss when f5ing page.\n // resulting in unexpected behavior. if there is no file data, the file is invalid.\n // if (!fileUploadOptions.useTempFiles && !options.buffer.length) return;\n\n // Create and return file object.\n return {\n name: options.name,\n data: options.buffer,\n encoding: options.encoding,\n md5: options.hash,\n mimetype: options.mimetype,\n mv: (filePath: string, callback) => {\n // Define a proper move function.\n const moveFunc = fileUploadOptions.useTempFiles\n ? moveFromTemp(filePath, options, fileUploadOptions)\n : moveFromBuffer(filePath, options, fileUploadOptions)\n // Create a folder for a file.\n checkAndMakeDir(fileUploadOptions, filePath)\n // If callback is passed in, use the callback API, otherwise return a promise.\n const defaultReject = () => undefined\n return isFunc(callback) ? moveFunc(callback, defaultReject) : new Promise(moveFunc)\n },\n size: options.size,\n tempFilePath: options.tempFilePath,\n truncated: options.truncated,\n }\n}\n"],"mappings":"AAIA,SACEA,eAAe,EACfC,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,eAAe,EACfC,gBAAgB,QACX;AAQP;;;;AAIA,MAAMC,YAAA,GAAyBA,CAACC,QAAA,EAAUC,OAAA,EAASC,iBAAA,KAAsB,CAACC,OAAA,EAASC,MAAA;EACjFV,QAAA,CAASQ,iBAAA,EAAmB,yBAAyBD,OAAA,CAAQI,YAAY,OAAOL,QAAA,EAAU;EAC1FJ,QAAA,CAASK,OAAA,CAAQI,YAAY,EAAEL,QAAA,EAAUH,eAAA,CAAgBM,OAAA,EAASC,MAAA;AACpE;AAEA;;;;AAIA,MAAME,cAAA,GAA2BA,CAACN,QAAA,EAAUC,OAAA,EAASC,iBAAA,KAAsB,CAACC,OAAA,EAASC,MAAA;EACnFV,QAAA,CAASQ,iBAAA,EAAmB,6BAA6BF,QAAA,EAAU;EACnEF,gBAAA,CAAiBG,OAAA,CAAQM,MAAM,EAAEP,QAAA,EAAUH,eAAA,CAAgBM,OAAA,EAASC,MAAA;AACtE;AAgBA,OAAO,MAAMI,WAAA,GAA2BA,CAACP,OAAA,EAASC,iBAAA;EAChD;EACA;EACA;EACA;EAEA;EACA,OAAO;IACLO,IAAA,EAAMR,OAAA,CAAQQ,IAAI;IAClBC,IAAA,EAAMT,OAAA,CAAQM,MAAM;IACpBI,QAAA,EAAUV,OAAA,CAAQU,QAAQ;IAC1BC,GAAA,EAAKX,OAAA,CAAQY,IAAI;IACjBC,QAAA,EAAUb,OAAA,CAAQa,QAAQ;IAC1BC,EAAA,EAAIA,CAACf,QAAA,EAAkBgB,QAAA;MACrB;MACA,MAAMC,QAAA,GAAWf,iBAAA,CAAkBgB,YAAY,GAC3CnB,YAAA,CAAaC,QAAA,EAAUC,OAAA,EAASC,iBAAA,IAChCI,cAAA,CAAeN,QAAA,EAAUC,OAAA,EAASC,iBAAA;MACtC;MACAT,eAAA,CAAgBS,iBAAA,EAAmBF,QAAA;MACnC;MACA,MAAMmB,aAAA,GAAgBA,CAAA,KAAMC,SAAA;MAC5B,OAAOzB,MAAA,CAAOqB,QAAA,IAAYC,QAAA,CAASD,QAAA,EAAUG,aAAA,IAAiB,IAAIE,OAAA,CAAQJ,QAAA;IAC5E;IACAK,IAAA,EAAMrB,OAAA,CAAQqB,IAAI;IAClBjB,YAAA,EAAcJ,OAAA,CAAQI,YAAY;IAClCkB,SAAA,EAAWtB,OAAA,CAAQsB;EACrB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAQxD,KAAK,OAAO,GAAG,CACb,OAAO,EAAE,yBAAyB,EAClC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,KACb;IACH,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,QAAQ,EAAE,MAAM,MAAM,CAAA;IACtB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,WAAW,EAAE,MAAM,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,MAAM,CAAA;IACzB,OAAO,EAAE,MAAM,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,OAwD7B,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,OAgCxB,CAAA"}
|
|
@@ -31,7 +31,9 @@ export const tempFileHandler = (options, fieldname, filename) => {
|
|
|
31
31
|
complete: () => {
|
|
32
32
|
completed = true;
|
|
33
33
|
debugLog(options, `Upload ${fieldname}->${filename} completed, bytes:${fileSize}.`);
|
|
34
|
-
if (writeStream instanceof WriteStream)
|
|
34
|
+
if (writeStream instanceof WriteStream) {
|
|
35
|
+
writeStream.end();
|
|
36
|
+
}
|
|
35
37
|
// Return empty buff since data was uploaded into a temp file.
|
|
36
38
|
return Buffer.concat([]);
|
|
37
39
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","names":["crypto","fs","WriteStream","path","checkAndMakeDir","debugLog","deleteFile","getTempFilename","tempFileHandler","options","fieldname","filename","dir","normalize","tempFileDir","tempFilePath","join","process","cwd","createParentPath","hash","createHash","fileSize","completed","writeStream","createWriteStream","writePromise","Promise","resolve","reject","on","err","cleanup","end","complete","Buffer","concat","dataHandler","data","write","update","length","getFilePath","getFileSize","getHash","digest","getWritePromise","memHandler","buffers","getBuffer","push"],"sources":["../../src/fetchAPI-multipart/handlers.ts"],"sourcesContent":["import crypto from 'crypto'\nimport fs, { WriteStream } from 'fs'\nimport path from 'path'\n\nimport
|
|
1
|
+
{"version":3,"file":"handlers.js","names":["crypto","fs","WriteStream","path","checkAndMakeDir","debugLog","deleteFile","getTempFilename","tempFileHandler","options","fieldname","filename","dir","normalize","tempFileDir","tempFilePath","join","process","cwd","createParentPath","hash","createHash","fileSize","completed","writeStream","createWriteStream","writePromise","Promise","resolve","reject","on","err","cleanup","end","complete","Buffer","concat","dataHandler","data","write","update","length","getFilePath","getFileSize","getHash","digest","getWritePromise","memHandler","buffers","getBuffer","push"],"sources":["../../src/fetchAPI-multipart/handlers.ts"],"sourcesContent":["import type { FetchAPIFileUploadOptions } from 'payload'\n\nimport crypto from 'crypto'\nimport fs, { WriteStream } from 'fs'\nimport path from 'path'\n\nimport { checkAndMakeDir, debugLog, deleteFile, getTempFilename } from './utilities.js'\n\ntype Handler = (\n options: FetchAPIFileUploadOptions,\n fieldname: string,\n filename: string,\n) => {\n cleanup: () => void\n complete: () => Buffer\n dataHandler: (data: Buffer) => void\n getFilePath: () => string\n getFileSize: () => number\n getHash: () => string\n getWritePromise: () => Promise<boolean>\n}\n\nexport const tempFileHandler: Handler = (options, fieldname, filename) => {\n const dir = path.normalize(options.tempFileDir)\n const tempFilePath = path.join(process.cwd(), dir, getTempFilename())\n checkAndMakeDir({ createParentPath: true }, tempFilePath)\n\n debugLog(options, `Temporary file path is ${tempFilePath}`)\n\n const hash = crypto.createHash('md5')\n let fileSize = 0\n let completed = false\n\n debugLog(options, `Opening write stream for ${fieldname}->${filename}...`)\n const writeStream = fs.createWriteStream(tempFilePath)\n const writePromise = new Promise<boolean>((resolve, reject) => {\n writeStream.on('finish', () => resolve(true))\n writeStream.on('error', (err) => {\n debugLog(options, `Error write temp file: ${err}`)\n reject(err)\n })\n })\n\n return {\n cleanup: () => {\n completed = true\n debugLog(options, `Cleaning up temporary file ${tempFilePath}...`)\n writeStream.end()\n deleteFile(tempFilePath, (err) =>\n err\n ? debugLog(options, `Cleaning up temporary file ${tempFilePath} failed: ${err}`)\n : debugLog(options, `Cleaning up temporary file ${tempFilePath} done.`),\n )\n },\n complete: () => {\n completed = true\n debugLog(options, `Upload ${fieldname}->${filename} completed, bytes:${fileSize}.`)\n if (writeStream instanceof WriteStream) {\n writeStream.end()\n }\n // Return empty buff since data was uploaded into a temp file.\n return Buffer.concat([])\n },\n dataHandler: (data) => {\n if (completed === true) {\n debugLog(options, `Error: got ${fieldname}->${filename} data chunk for completed upload!`)\n return\n }\n writeStream.write(data)\n hash.update(data)\n fileSize += data.length\n debugLog(options, `Uploading ${fieldname}->${filename}, bytes:${fileSize}...`)\n },\n getFilePath: () => tempFilePath,\n getFileSize: () => fileSize,\n getHash: () => hash.digest('hex'),\n getWritePromise: () => writePromise,\n }\n}\n\nexport const memHandler: Handler = (options, fieldname, filename) => {\n const buffers: Buffer[] = []\n const hash = crypto.createHash('md5')\n let fileSize = 0\n let completed = false\n\n const getBuffer = () => Buffer.concat(buffers, fileSize)\n\n return {\n cleanup: () => {\n completed = true\n },\n complete: () => {\n debugLog(options, `Upload ${fieldname}->${filename} completed, bytes:${fileSize}.`)\n completed = true\n return getBuffer()\n },\n dataHandler: (data) => {\n if (completed === true) {\n debugLog(options, `Error: got ${fieldname}->${filename} data chunk for completed upload!`)\n return\n }\n buffers.push(data)\n hash.update(data)\n fileSize += data.length\n debugLog(options, `Uploading ${fieldname}->${filename}, bytes:${fileSize}...`)\n },\n getFilePath: () => '',\n getFileSize: () => fileSize,\n getHash: () => hash.digest('hex'),\n getWritePromise: () => Promise.resolve(true),\n }\n}\n"],"mappings":"AAEA,OAAOA,MAAA,MAAY;AACnB,OAAOC,EAAA,IAAMC,WAAW,QAAQ;AAChC,OAAOC,IAAA,MAAU;AAEjB,SAASC,eAAe,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,eAAe,QAAQ;AAgBvE,OAAO,MAAMC,eAAA,GAA2BA,CAACC,OAAA,EAASC,SAAA,EAAWC,QAAA;EAC3D,MAAMC,GAAA,GAAMT,IAAA,CAAKU,SAAS,CAACJ,OAAA,CAAQK,WAAW;EAC9C,MAAMC,YAAA,GAAeZ,IAAA,CAAKa,IAAI,CAACC,OAAA,CAAQC,GAAG,IAAIN,GAAA,EAAKL,eAAA;EACnDH,eAAA,CAAgB;IAAEe,gBAAA,EAAkB;EAAK,GAAGJ,YAAA;EAE5CV,QAAA,CAAS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QAAA,WAAmBW,QAAA,KAAa;IAC/E;IACAoB,WAAA,EAAaA,CAAA,KAAM;IACnBC,WAAA,EAAaA,CAAA,KAAMrB,QAAA;IACnBsB,OAAA,EAASA,CAAA,KAAMxB,IAAA,CAAKyB,MAAM,CAAC;IAC3BC,eAAA,EAAiBA,CAAA,KAAMnB,OAAA,CAAQC,OAAO,CAAC;EACzC;AACF","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FetchAPIFileUploadOptions } from 'payload';
|
|
2
2
|
import { APIError } from 'payload';
|
|
3
3
|
export type FileShape = {
|
|
4
4
|
data: Buffer;
|
|
@@ -11,106 +11,6 @@ export type FileShape = {
|
|
|
11
11
|
tempFilePath: string;
|
|
12
12
|
truncated: boolean;
|
|
13
13
|
};
|
|
14
|
-
export type FetchAPIFileUploadOptions = {
|
|
15
|
-
/**
|
|
16
|
-
* Returns a HTTP 413 when the file is bigger than the size limit if `true`.
|
|
17
|
-
* Otherwise, it will add a `truncated = true` to the resulting file structure.
|
|
18
|
-
* @default false
|
|
19
|
-
*/
|
|
20
|
-
abortOnLimit?: boolean | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Automatically creates the directory path specified in `.mv(filePathName)`
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
createParentPath?: boolean | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Turn on/off upload process logging. Can be useful for troubleshooting.
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
debug?: boolean | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* User defined limit handler which will be invoked if the file is bigger than configured limits.
|
|
33
|
-
* @default false
|
|
34
|
-
*/
|
|
35
|
-
limitHandler?: ((args: {
|
|
36
|
-
request: Request;
|
|
37
|
-
size: number;
|
|
38
|
-
}) => void) | boolean | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* By default, `req.body` and `req.files` are flattened like this:
|
|
41
|
-
* `{'name': 'John', 'hobbies[0]': 'Cinema', 'hobbies[1]': 'Bike'}
|
|
42
|
-
*
|
|
43
|
-
* When this option is enabled they are parsed in order to be nested like this:
|
|
44
|
-
* `{'name': 'John', 'hobbies': ['Cinema', 'Bike']}`
|
|
45
|
-
* @default false
|
|
46
|
-
*/
|
|
47
|
-
parseNested?: boolean | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Preserves filename extension when using `safeFileNames` option.
|
|
50
|
-
* If set to `true`, will default to an extension length of `3`.
|
|
51
|
-
* If set to `number`, this will be the max allowable extension length.
|
|
52
|
-
* If an extension is smaller than the extension length, it remains untouched. If the extension is longer,
|
|
53
|
-
* it is shifted.
|
|
54
|
-
* @default false
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* // true
|
|
58
|
-
* app.use(fileUpload({ safeFileNames: true, preserveExtension: true }));
|
|
59
|
-
* // myFileName.ext --> myFileName.ext
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* // max extension length 2, extension shifted
|
|
63
|
-
* app.use(fileUpload({ safeFileNames: true, preserveExtension: 2 }));
|
|
64
|
-
* // myFileName.ext --> myFileNamee.xt
|
|
65
|
-
*/
|
|
66
|
-
preserveExtension?: boolean | number | undefined;
|
|
67
|
-
/**
|
|
68
|
-
* Response which will be send to client if file size limit exceeded when `abortOnLimit` set to `true`.
|
|
69
|
-
* @default 'File size limit has been reached'
|
|
70
|
-
*/
|
|
71
|
-
responseOnLimit?: string | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Strips characters from the upload's filename.
|
|
74
|
-
* You can use custom regex to determine what to strip.
|
|
75
|
-
* If set to `true`, non-alphanumeric characters _except_ dashes and underscores will be stripped.
|
|
76
|
-
* This option is off by default.
|
|
77
|
-
* @default false
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* // strip slashes from file names
|
|
81
|
-
* app.use(fileUpload({ safeFileNames: /\\/g }))
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* app.use(fileUpload({ safeFileNames: true }))
|
|
85
|
-
*/
|
|
86
|
-
safeFileNames?: RegExp | boolean | undefined;
|
|
87
|
-
/**
|
|
88
|
-
* Path to store temporary files.
|
|
89
|
-
* Used along with the `useTempFiles` option. By default this module uses `'tmp'` folder
|
|
90
|
-
* in the current working directory.
|
|
91
|
-
* You can use trailing slash, but it is not necessary.
|
|
92
|
-
* @default './tmp'
|
|
93
|
-
*/
|
|
94
|
-
tempFileDir?: string | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* This defines how long to wait for data before aborting. Set to `0` if you want to turn off timeout checks.
|
|
97
|
-
* @default 60_000
|
|
98
|
-
*/
|
|
99
|
-
uploadTimeout?: number | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* Applies uri decoding to file names if set `true`.
|
|
102
|
-
* @default false
|
|
103
|
-
*/
|
|
104
|
-
uriDecodeFileNames?: boolean | undefined;
|
|
105
|
-
/**
|
|
106
|
-
* By default this module uploads files into RAM.
|
|
107
|
-
* Setting this option to `true` turns on using temporary files instead of utilising RAM.
|
|
108
|
-
* This avoids memory overflow issues when uploading large files or in case of uploading
|
|
109
|
-
* lots of files at same time.
|
|
110
|
-
* @default false
|
|
111
|
-
*/
|
|
112
|
-
useTempFiles?: boolean | undefined;
|
|
113
|
-
} & Partial<BusboyConfig>;
|
|
114
14
|
type FetchAPIFileUploadResponseFile = {
|
|
115
15
|
data: Buffer;
|
|
116
16
|
mimetype: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAsBlC,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,EAAE,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACpE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,8BAA8B,GAAG;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAA;CACtD,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,IAAI,EAAE;IAC/B,OAAO,CAAC,EAAE,yBAAyB,CAAA;IACnC,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzC,eAAO,MAAM,kBAAkB,EAAE,kBAYhC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["path","APIError","isEligibleRequest","processMultipart","debugLog","DEFAULT_OPTIONS","abortOnLimit","createParentPath","debug","fileHandler","limitHandler","parseNested","preserveExtension","responseOnLimit","safeFileNames","tempFileDir","join","process","cwd","uploadTimeout","uriDecodeFileNames","useTempFiles","fetchAPIFileUpload","options","request","uploadOptions","error","fields","undefined","files"],"sources":["../../src/fetchAPI-multipart/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.js","names":["path","APIError","isEligibleRequest","processMultipart","debugLog","DEFAULT_OPTIONS","abortOnLimit","createParentPath","debug","fileHandler","limitHandler","parseNested","preserveExtension","responseOnLimit","safeFileNames","tempFileDir","join","process","cwd","uploadTimeout","uriDecodeFileNames","useTempFiles","fetchAPIFileUpload","options","request","uploadOptions","error","fields","undefined","files"],"sources":["../../src/fetchAPI-multipart/index.ts"],"sourcesContent":["import type { FetchAPIFileUploadOptions } from 'payload'\n\nimport path from 'path'\nimport { APIError } from 'payload'\n\nimport { isEligibleRequest } from './isEligibleRequest.js'\nimport { processMultipart } from './processMultipart.js'\nimport { debugLog } from './utilities.js'\n\nconst DEFAULT_OPTIONS = {\n abortOnLimit: false,\n createParentPath: false,\n debug: false,\n fileHandler: false,\n limitHandler: false,\n parseNested: false,\n preserveExtension: false,\n responseOnLimit: 'File size limit has been reached',\n safeFileNames: false,\n tempFileDir: path.join(process.cwd(), 'tmp'),\n uploadTimeout: 60000,\n uriDecodeFileNames: false,\n useTempFiles: false,\n}\n\nexport type FileShape = {\n data: Buffer\n encoding: string\n md5: Buffer | string\n mimetype: string\n mv: (filePath: string, callback: () => void) => Promise<void> | void\n name: string\n size: number\n tempFilePath: string\n truncated: boolean\n}\n\ntype FetchAPIFileUploadResponseFile = {\n data: Buffer\n mimetype: string\n name: string\n size: number\n tempFilePath?: string\n}\n\nexport type FetchAPIFileUploadResponse = {\n error?: APIError\n fields: Record<string, string>\n files: Record<string, FetchAPIFileUploadResponseFile>\n}\n\ntype FetchAPIFileUpload = (args: {\n options?: FetchAPIFileUploadOptions\n request: Request\n}) => Promise<FetchAPIFileUploadResponse>\nexport const fetchAPIFileUpload: FetchAPIFileUpload = async ({ options, request }) => {\n const uploadOptions: FetchAPIFileUploadOptions = { ...DEFAULT_OPTIONS, ...options }\n if (!isEligibleRequest(request)) {\n debugLog(uploadOptions, 'Request is not eligible for file upload!')\n return {\n error: new APIError('Request is not eligible for file upload', 500),\n fields: undefined,\n files: undefined,\n }\n } else {\n return processMultipart({ options: uploadOptions, request })\n }\n}\n"],"mappings":"AAEA,OAAOA,IAAA,MAAU;AACjB,SAASC,QAAQ,QAAQ;AAEzB,SAASC,iBAAiB,QAAQ;AAClC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,QAAQ,QAAQ;AAEzB,MAAMC,eAAA,GAAkB;EACtBC,YAAA,EAAc;EACdC,gBAAA,EAAkB;EAClBC,KAAA,EAAO;EACPC,WAAA,EAAa;EACbC,YAAA,EAAc;EACdC,WAAA,EAAa;EACbC,iBAAA,EAAmB;EACnBC,eAAA,EAAiB;EACjBC,aAAA,EAAe;EACfC,WAAA,EAAaf,IAAA,CAAKgB,IAAI,CAACC,OAAA,CAAQC,GAAG,IAAI;EACtCC,aAAA,EAAe;EACfC,kBAAA,EAAoB;EACpBC,YAAA,EAAc;AAChB;AAgCA,OAAO,MAAMC,kBAAA,GAAyC,MAAAA,CAAO;EAAEC,OAAO;EAAEC;AAAO,CAAE;EAC/E,MAAMC,aAAA,GAA2C;IAAE,GAAGpB,eAAe;IAAE,GAAGkB;EAAQ;EAClF,IAAI,CAACrB,iBAAA,CAAkBsB,OAAA,GAAU;IAC/BpB,QAAA,CAASqB,aAAA,EAAe;IACxB,OAAO;MACLC,KAAA,EAAO,IAAIzB,QAAA,CAAS,2CAA2C;MAC/D0B,MAAA,EAAQC,SAAA;MACRC,KAAA,EAAOD;IACT;EACF,OAAO;IACL,OAAOzB,gBAAA,CAAiB;MAAEoB,OAAA,EAASE,aAAA;MAAeD;IAAQ;EAC5D;AACF","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { FetchAPIFileUploadOptions
|
|
1
|
+
import type { FetchAPIFileUploadOptions } from 'payload';
|
|
2
|
+
import type { FetchAPIFileUploadResponse } from './index.js';
|
|
2
3
|
type ProcessMultipart = (args: {
|
|
3
4
|
options: FetchAPIFileUploadOptions;
|
|
4
5
|
request: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processMultipart.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/processMultipart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"processMultipart.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/processMultipart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAOxD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAU5D,KAAK,gBAAgB,GAAG,CAAC,IAAI,EAAE;IAC7B,OAAO,EAAE,yBAAyB,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzC,eAAO,MAAM,gBAAgB,EAAE,gBAsM9B,CAAA"}
|
|
@@ -133,6 +133,8 @@ export const processMultipart = async ({
|
|
|
133
133
|
debugLog(options, `New upload started ${field}->${filename}, bytes:${getFileSize()}`);
|
|
134
134
|
uploadTimer.set();
|
|
135
135
|
});
|
|
136
|
+
// TODO: Valid eslint error - this will likely be a floating promise. Evaluate if we need to handle this differently.
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
136
138
|
busboy.on('finish', async () => {
|
|
137
139
|
debugLog(options, `Busboy finished parsing request.`);
|
|
138
140
|
if (options.parseNested) {
|