@payloadcms/next 3.20.0-canary.9f2bca1 → 3.20.0-canary.a40bec2
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/prod/styles.css +1 -1
- package/dist/views/Account/index.d.ts.map +1 -1
- package/dist/views/Account/index.js +2 -1
- package/dist/views/Account/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +4 -2
- package/dist/views/CreateFirstUser/index.client.js.map +1 -1
- package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.js +2 -1
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/dist/views/Document/getDocumentPermissions.js +2 -2
- package/dist/views/Document/getDocumentPermissions.js.map +1 -1
- package/dist/views/Document/index.d.ts.map +1 -1
- package/dist/views/Document/index.js +2 -1
- package/dist/views/Document/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +2 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -1
- package/dist/views/LivePreview/index.client.d.ts.map +1 -1
- package/dist/views/LivePreview/index.client.js +5 -2
- package/dist/views/LivePreview/index.client.js.map +1 -1
- package/dist/views/Version/Default/SelectedLocalesContext.d.ts +8 -0
- package/dist/views/Version/Default/SelectedLocalesContext.d.ts.map +1 -0
- package/dist/views/Version/Default/SelectedLocalesContext.js +10 -0
- package/dist/views/Version/Default/SelectedLocalesContext.js.map +1 -0
- package/dist/views/Version/Default/index.d.ts.map +1 -1
- package/dist/views/Version/Default/index.js +107 -159
- package/dist/views/Version/Default/index.js.map +1 -1
- package/dist/views/Version/Default/index.scss +5 -0
- package/dist/views/Version/Default/types.d.ts +5 -4
- package/dist/views/Version/Default/types.d.ts.map +1 -1
- package/dist/views/Version/Default/types.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.d.ts +27 -0
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.js +76 -0
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.scss +46 -0
- package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.d.ts +7 -0
- package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.js +74 -0
- package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.d.ts +31 -0
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.js +319 -0
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.d.ts +3 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.js +67 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.d.ts +4 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.js +69 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.scss +14 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.d.ts +3 -4
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js +100 -63
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.scss +3 -12
- package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.d.ts +2 -5
- package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.js +19 -19
- package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.d.ts +3 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.js +17 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/DiffViewer/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/DiffViewer/index.js +1 -2
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/DiffViewer/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.d.ts +2 -5
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js +56 -28
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.d.ts +3 -5
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.js +151 -41
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.scss +20 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/DiffViewer/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/DiffViewer/index.js +1 -2
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/DiffViewer/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.d.ts +2 -5
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js +71 -37
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/index.d.ts +2 -22
- package/dist/views/Version/RenderFieldsToDiff/fields/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/index.js +13 -9
- package/dist/views/Version/RenderFieldsToDiff/fields/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/styles.d.ts +3 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/styles.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/styles.js +3 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/styles.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/index.d.ts +2 -5
- package/dist/views/Version/RenderFieldsToDiff/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/index.js +8 -113
- package/dist/views/Version/RenderFieldsToDiff/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/index.scss +4 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.d.ts +21 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.js +197 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js +860 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.d.ts +2 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.js +4 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js +46 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.d.ts +27 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.js +30 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.d.ts +18 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.d.ts.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.js +44 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js +122 -0
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js.map +1 -0
- package/dist/views/Version/Restore/index.d.ts.map +1 -1
- package/dist/views/Version/Restore/index.js +2 -2
- package/dist/views/Version/Restore/index.js.map +1 -1
- package/dist/views/Version/SelectComparison/index.d.ts.map +1 -1
- package/dist/views/Version/SelectComparison/index.js +7 -3
- package/dist/views/Version/SelectComparison/index.js.map +1 -1
- package/dist/views/Version/SelectComparison/types.d.ts.map +1 -1
- package/dist/views/Version/SelectComparison/types.js.map +1 -1
- package/dist/views/Version/index.d.ts.map +1 -1
- package/dist/views/Version/index.js +120 -15
- package/dist/views/Version/index.js.map +1 -1
- package/dist/views/Versions/getLatestVersion.d.ts +4 -1
- package/dist/views/Versions/getLatestVersion.d.ts.map +1 -1
- package/dist/views/Versions/getLatestVersion.js +6 -0
- package/dist/views/Versions/getLatestVersion.js.map +1 -1
- package/package.json +8 -7
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.d.ts +0 -6
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.d.ts.map +0 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.js +0 -43
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.js.map +0 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.scss +0 -14
- package/dist/views/Version/RenderFieldsToDiff/fields/types.d.ts +0 -22
- package/dist/views/Version/RenderFieldsToDiff/fields/types.d.ts.map +0 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/types.js +0 -2
- package/dist/views/Version/RenderFieldsToDiff/fields/types.js.map +0 -1
- package/dist/views/Version/RenderFieldsToDiff/types.d.ts +0 -21
- package/dist/views/Version/RenderFieldsToDiff/types.d.ts.map +0 -1
- package/dist/views/Version/RenderFieldsToDiff/types.js +0 -2
- package/dist/views/Version/RenderFieldsToDiff/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/views/Version/Default/types.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/views/Version/Default/types.ts"],"sourcesContent":["import type { Document, OptionObject } from 'payload'\n\nexport type CompareOption = {\n label: React.ReactNode | string\n options?: CompareOption[]\n relationTo?: string\n value: string\n}\n\nexport type DefaultVersionsViewProps = {\n readonly canUpdate: boolean\n readonly doc: Document\n readonly latestDraftVersion?: string\n readonly latestPublishedVersion?: string\n modifiedOnly: boolean\n readonly RenderedDiff: React.ReactNode\n readonly selectedLocales: OptionObject[]\n readonly versionID?: string\n}\n"],"mappings":"AASA","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ClientField } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import './index.scss';
|
|
4
|
+
type Props = {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
comparison: unknown;
|
|
7
|
+
field?: never;
|
|
8
|
+
fields: ClientField[];
|
|
9
|
+
initCollapsed?: boolean;
|
|
10
|
+
isIterable?: false;
|
|
11
|
+
label: React.ReactNode;
|
|
12
|
+
locales: string[] | undefined;
|
|
13
|
+
version: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
comparison?: unknown;
|
|
17
|
+
field: ClientField;
|
|
18
|
+
fields?: never;
|
|
19
|
+
initCollapsed?: boolean;
|
|
20
|
+
isIterable: true;
|
|
21
|
+
label: React.ReactNode;
|
|
22
|
+
locales: string[] | undefined;
|
|
23
|
+
version: unknown;
|
|
24
|
+
};
|
|
25
|
+
export declare const DiffCollapser: React.FC<Props>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/views/Version/RenderFieldsToDiff/DiffCollapser/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,OAAO,cAAc,CAAA;AAKrB,KAAK,KAAK,GACN;IAEE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAA;CACjB,GACD;IAEE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,EAAE,WAAW,CAAA;IAClB,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAU,EAAE,IAAI,CAAA;IAChB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAEL,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA0EzC,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronIcon, Pill, useTranslation } from '@payloadcms/ui';
|
|
3
|
+
import { fieldIsArrayType, fieldIsBlockType } from 'payload/shared';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import Label from '../Label/index.js';
|
|
6
|
+
import { countChangedFields, countChangedFieldsInRows } from '../utilities/countChangedFields.js';
|
|
7
|
+
const baseClass = 'diff-collapser';
|
|
8
|
+
export const DiffCollapser = ({
|
|
9
|
+
children,
|
|
10
|
+
comparison,
|
|
11
|
+
field,
|
|
12
|
+
fields,
|
|
13
|
+
initCollapsed = false,
|
|
14
|
+
isIterable = false,
|
|
15
|
+
label,
|
|
16
|
+
locales,
|
|
17
|
+
version
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
t
|
|
21
|
+
} = useTranslation();
|
|
22
|
+
const [isCollapsed, setIsCollapsed] = useState(initCollapsed);
|
|
23
|
+
let changeCount = 0;
|
|
24
|
+
if (isIterable) {
|
|
25
|
+
if (!fieldIsArrayType(field) && !fieldIsBlockType(field)) {
|
|
26
|
+
throw new Error('DiffCollapser: field must be an array or blocks field when isIterable is true');
|
|
27
|
+
}
|
|
28
|
+
const comparisonRows = comparison ?? [];
|
|
29
|
+
const versionRows = version ?? [];
|
|
30
|
+
if (!Array.isArray(comparisonRows) || !Array.isArray(versionRows)) {
|
|
31
|
+
throw new Error('DiffCollapser: comparison and version must be arrays when isIterable is true');
|
|
32
|
+
}
|
|
33
|
+
changeCount = countChangedFieldsInRows({
|
|
34
|
+
comparisonRows,
|
|
35
|
+
field,
|
|
36
|
+
locales,
|
|
37
|
+
versionRows
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
changeCount = countChangedFields({
|
|
41
|
+
comparison,
|
|
42
|
+
fields,
|
|
43
|
+
locales,
|
|
44
|
+
version
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const contentClassNames = [`${baseClass}__content`, isCollapsed && `${baseClass}__content--is-collapsed`].filter(Boolean).join(' ');
|
|
48
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
49
|
+
className: baseClass,
|
|
50
|
+
children: [/*#__PURE__*/_jsxs(Label, {
|
|
51
|
+
children: [/*#__PURE__*/_jsx("button", {
|
|
52
|
+
"aria-label": isCollapsed ? 'Expand' : 'Collapse',
|
|
53
|
+
className: `${baseClass}__toggle-button`,
|
|
54
|
+
onClick: () => setIsCollapsed(!isCollapsed),
|
|
55
|
+
type: "button",
|
|
56
|
+
children: /*#__PURE__*/_jsx(ChevronIcon, {
|
|
57
|
+
direction: isCollapsed ? 'right' : 'down'
|
|
58
|
+
})
|
|
59
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
60
|
+
className: `${baseClass}__label`,
|
|
61
|
+
children: label
|
|
62
|
+
}), changeCount > 0 && /*#__PURE__*/_jsx(Pill, {
|
|
63
|
+
className: `${baseClass}__field-change-count`,
|
|
64
|
+
pillStyle: "light-gray",
|
|
65
|
+
size: "small",
|
|
66
|
+
children: t('version:changedFieldsCount', {
|
|
67
|
+
count: changeCount
|
|
68
|
+
})
|
|
69
|
+
})]
|
|
70
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
71
|
+
className: contentClassNames,
|
|
72
|
+
children: children
|
|
73
|
+
})]
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ChevronIcon","Pill","useTranslation","fieldIsArrayType","fieldIsBlockType","React","useState","Label","countChangedFields","countChangedFieldsInRows","baseClass","DiffCollapser","children","comparison","field","fields","initCollapsed","isIterable","label","locales","version","t","isCollapsed","setIsCollapsed","changeCount","Error","comparisonRows","versionRows","Array","isArray","contentClassNames","filter","Boolean","join","_jsxs","className","_jsx","onClick","type","direction","pillStyle","size","count"],"sources":["../../../../../src/views/Version/RenderFieldsToDiff/DiffCollapser/index.tsx"],"sourcesContent":["import type { ClientField } from 'payload'\n\nimport { ChevronIcon, Pill, useTranslation } from '@payloadcms/ui'\nimport { fieldIsArrayType, fieldIsBlockType } from 'payload/shared'\nimport React, { useState } from 'react'\n\nimport Label from '../Label/index.js'\nimport './index.scss'\nimport { countChangedFields, countChangedFieldsInRows } from '../utilities/countChangedFields.js'\n\nconst baseClass = 'diff-collapser'\n\ntype Props =\n | {\n // fields collapser\n children: React.ReactNode\n comparison: unknown\n field?: never\n fields: ClientField[]\n initCollapsed?: boolean\n isIterable?: false\n label: React.ReactNode\n locales: string[] | undefined\n version: unknown\n }\n | {\n // iterable collapser\n children: React.ReactNode\n comparison?: unknown\n field: ClientField\n fields?: never\n initCollapsed?: boolean\n isIterable: true\n label: React.ReactNode\n locales: string[] | undefined\n version: unknown\n }\n\nexport const DiffCollapser: React.FC<Props> = ({\n children,\n comparison,\n field,\n fields,\n initCollapsed = false,\n isIterable = false,\n label,\n locales,\n version,\n}) => {\n const { t } = useTranslation()\n const [isCollapsed, setIsCollapsed] = useState(initCollapsed)\n\n let changeCount = 0\n\n if (isIterable) {\n if (!fieldIsArrayType(field) && !fieldIsBlockType(field)) {\n throw new Error(\n 'DiffCollapser: field must be an array or blocks field when isIterable is true',\n )\n }\n const comparisonRows = comparison ?? []\n const versionRows = version ?? []\n\n if (!Array.isArray(comparisonRows) || !Array.isArray(versionRows)) {\n throw new Error(\n 'DiffCollapser: comparison and version must be arrays when isIterable is true',\n )\n }\n\n changeCount = countChangedFieldsInRows({\n comparisonRows,\n field,\n locales,\n versionRows,\n })\n } else {\n changeCount = countChangedFields({\n comparison,\n fields,\n locales,\n version,\n })\n }\n\n const contentClassNames = [\n `${baseClass}__content`,\n isCollapsed && `${baseClass}__content--is-collapsed`,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <div className={baseClass}>\n <Label>\n <button\n aria-label={isCollapsed ? 'Expand' : 'Collapse'}\n className={`${baseClass}__toggle-button`}\n onClick={() => setIsCollapsed(!isCollapsed)}\n type=\"button\"\n >\n <ChevronIcon direction={isCollapsed ? 'right' : 'down'} />\n </button>\n <span className={`${baseClass}__label`}>{label}</span>\n {changeCount > 0 && (\n <Pill className={`${baseClass}__field-change-count`} pillStyle=\"light-gray\" size=\"small\">\n {t('version:changedFieldsCount', { count: changeCount })}\n </Pill>\n )}\n </Label>\n <div className={contentClassNames}>{children}</div>\n </div>\n )\n}\n"],"mappings":";AAEA,SAASA,WAAW,EAAEC,IAAI,EAAEC,cAAc,QAAQ;AAClD,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ;AACnD,OAAOC,KAAA,IAASC,QAAQ,QAAQ;AAEhC,OAAOC,KAAA,MAAW;AAElB,SAASC,kBAAkB,EAAEC,wBAAwB,QAAQ;AAE7D,MAAMC,SAAA,GAAY;AA4BlB,OAAO,MAAMC,aAAA,GAAiCA,CAAC;EAC7CC,QAAQ;EACRC,UAAU;EACVC,KAAK;EACLC,MAAM;EACNC,aAAA,GAAgB,KAAK;EACrBC,UAAA,GAAa,KAAK;EAClBC,KAAK;EACLC,OAAO;EACPC;AAAO,CACR;EACC,MAAM;IAAEC;EAAC,CAAE,GAAGnB,cAAA;EACd,MAAM,CAACoB,WAAA,EAAaC,cAAA,CAAe,GAAGjB,QAAA,CAASU,aAAA;EAE/C,IAAIQ,WAAA,GAAc;EAElB,IAAIP,UAAA,EAAY;IACd,IAAI,CAACd,gBAAA,CAAiBW,KAAA,KAAU,CAACV,gBAAA,CAAiBU,KAAA,GAAQ;MACxD,MAAM,IAAIW,KAAA,CACR;IAEJ;IACA,MAAMC,cAAA,GAAiBb,UAAA,IAAc,EAAE;IACvC,MAAMc,WAAA,GAAcP,OAAA,IAAW,EAAE;IAEjC,IAAI,CAACQ,KAAA,CAAMC,OAAO,CAACH,cAAA,KAAmB,CAACE,KAAA,CAAMC,OAAO,CAACF,WAAA,GAAc;MACjE,MAAM,IAAIF,KAAA,CACR;IAEJ;IAEAD,WAAA,GAAcf,wBAAA,CAAyB;MACrCiB,cAAA;MACAZ,KAAA;MACAK,OAAA;MACAQ;IACF;EACF,OAAO;IACLH,WAAA,GAAchB,kBAAA,CAAmB;MAC/BK,UAAA;MACAE,MAAA;MACAI,OAAA;MACAC;IACF;EACF;EAEA,MAAMU,iBAAA,GAAoB,CACxB,GAAGpB,SAAA,WAAoB,EACvBY,WAAA,IAAe,GAAGZ,SAAA,yBAAkC,CACrD,CACEqB,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;EAER,oBACEC,KAAA,CAAC;IAAIC,SAAA,EAAWzB,SAAA;4BACdwB,KAAA,CAAC3B,KAAA;8BACC6B,IAAA,CAAC;QACC,cAAYd,WAAA,GAAc,WAAW;QACrCa,SAAA,EAAW,GAAGzB,SAAA,iBAA0B;QACxC2B,OAAA,EAASA,CAAA,KAAMd,cAAA,CAAe,CAACD,WAAA;QAC/BgB,IAAA,EAAK;kBAEL,aAAAF,IAAA,CAACpC,WAAA;UAAYuC,SAAA,EAAWjB,WAAA,GAAc,UAAU;;uBAElDc,IAAA,CAAC;QAAKD,SAAA,EAAW,GAAGzB,SAAA,SAAkB;kBAAGQ;UACxCM,WAAA,GAAc,kBACbY,IAAA,CAACnC,IAAA;QAAKkC,SAAA,EAAW,GAAGzB,SAAA,sBAA+B;QAAE8B,SAAA,EAAU;QAAaC,IAAA,EAAK;kBAC9EpB,CAAA,CAAE,8BAA8B;UAAEqB,KAAA,EAAOlB;QAAY;;qBAI5DY,IAAA,CAAC;MAAID,SAAA,EAAWL,iBAAA;gBAAoBlB;;;AAG1C","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@layer payload-default {
|
|
2
|
+
.diff-collapser {
|
|
3
|
+
&__toggle-button {
|
|
4
|
+
all: unset;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
// Align the chevron visually with the label text
|
|
7
|
+
vertical-align: 1px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&__label {
|
|
11
|
+
// Add space between label, chevron, and change count
|
|
12
|
+
margin: 0 calc(var(--base) * 0.25);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&__field-change-count {
|
|
16
|
+
// Reset the font weight of the change count to normal
|
|
17
|
+
font-weight: normal;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&__content {
|
|
21
|
+
[dir='ltr'] & {
|
|
22
|
+
// Vertical gutter
|
|
23
|
+
border-left: 3px solid var(--theme-elevation-50);
|
|
24
|
+
// Center-align the gutter with the chevron
|
|
25
|
+
margin-left: 3px;
|
|
26
|
+
// Content indentation
|
|
27
|
+
padding-left: calc(var(--base) * 0.5);
|
|
28
|
+
}
|
|
29
|
+
[dir='rtl'] & {
|
|
30
|
+
// Vertical gutter
|
|
31
|
+
border-right: 3px solid var(--theme-elevation-50);
|
|
32
|
+
// Center-align the gutter with the chevron
|
|
33
|
+
margin-right: 3px;
|
|
34
|
+
// Content indentation
|
|
35
|
+
padding-right: calc(var(--base) * 0.5);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&__content--is-collapsed {
|
|
40
|
+
// Hide the content when collapsed. We use display: none instead of
|
|
41
|
+
// conditional rendering to avoid loosing children's collapsed state when
|
|
42
|
+
// remounting.
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VersionField } from 'payload';
|
|
2
|
+
import './index.scss';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export declare const RenderVersionFieldsToDiff: ({ versionFields, }: {
|
|
5
|
+
versionFields: VersionField[];
|
|
6
|
+
}) => React.ReactNode;
|
|
7
|
+
//# sourceMappingURL=RenderVersionFieldsToDiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderVersionFieldsToDiff.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,cAAc,CAAA;AAGrB,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,eAAO,MAAM,yBAAyB,uBAEnC;IACD,aAAa,EAAE,YAAY,EAAE,CAAA;CAC9B,KAAG,KAAK,CAAC,SAgDT,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const baseClass = 'render-field-diffs';
|
|
6
|
+
import { ShimmerEffect } from '@payloadcms/ui';
|
|
7
|
+
import React, { Fragment, useEffect } from 'react';
|
|
8
|
+
export const RenderVersionFieldsToDiff = t0 => {
|
|
9
|
+
const $ = _c(5);
|
|
10
|
+
const {
|
|
11
|
+
versionFields
|
|
12
|
+
} = t0;
|
|
13
|
+
const [hasMounted, setHasMounted] = React.useState(false);
|
|
14
|
+
let t1;
|
|
15
|
+
let t2;
|
|
16
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
17
|
+
t1 = () => {
|
|
18
|
+
setHasMounted(true);
|
|
19
|
+
};
|
|
20
|
+
t2 = [];
|
|
21
|
+
$[0] = t1;
|
|
22
|
+
$[1] = t2;
|
|
23
|
+
} else {
|
|
24
|
+
t1 = $[0];
|
|
25
|
+
t2 = $[1];
|
|
26
|
+
}
|
|
27
|
+
useEffect(t1, t2);
|
|
28
|
+
let t3;
|
|
29
|
+
if ($[2] !== hasMounted || $[3] !== versionFields) {
|
|
30
|
+
t3 = _jsx("div", {
|
|
31
|
+
className: baseClass,
|
|
32
|
+
children: !hasMounted ? _jsx(Fragment, {
|
|
33
|
+
children: _jsx(ShimmerEffect, {
|
|
34
|
+
height: "8rem",
|
|
35
|
+
width: "100%"
|
|
36
|
+
})
|
|
37
|
+
}) : versionFields?.map(_temp)
|
|
38
|
+
});
|
|
39
|
+
$[2] = hasMounted;
|
|
40
|
+
$[3] = versionFields;
|
|
41
|
+
$[4] = t3;
|
|
42
|
+
} else {
|
|
43
|
+
t3 = $[4];
|
|
44
|
+
}
|
|
45
|
+
return t3;
|
|
46
|
+
};
|
|
47
|
+
function _temp(field, fieldIndex) {
|
|
48
|
+
if (field.fieldByLocale) {
|
|
49
|
+
const LocaleComponents = [];
|
|
50
|
+
for (const [locale, baseField] of Object.entries(field.fieldByLocale)) {
|
|
51
|
+
LocaleComponents.push(_jsx("div", {
|
|
52
|
+
className: `${baseClass}__locale`,
|
|
53
|
+
children: _jsx("div", {
|
|
54
|
+
className: `${baseClass}__locale-value`,
|
|
55
|
+
children: baseField.CustomComponent
|
|
56
|
+
})
|
|
57
|
+
}, [locale, fieldIndex].join("-")));
|
|
58
|
+
}
|
|
59
|
+
return _jsx("div", {
|
|
60
|
+
className: `${baseClass}__field`,
|
|
61
|
+
children: LocaleComponents
|
|
62
|
+
}, fieldIndex);
|
|
63
|
+
} else {
|
|
64
|
+
if (field.field) {
|
|
65
|
+
return _jsx("div", {
|
|
66
|
+
className: `${baseClass}__field field__${field.field.type}`,
|
|
67
|
+
"data-field-path": field.field.path,
|
|
68
|
+
children: field.field.CustomComponent
|
|
69
|
+
}, fieldIndex);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=RenderVersionFieldsToDiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderVersionFieldsToDiff.js","names":["c","_c","baseClass","ShimmerEffect","React","Fragment","useEffect","RenderVersionFieldsToDiff","t0","$","versionFields","hasMounted","setHasMounted","useState","t1","t2","Symbol","for","t3","_jsx","className","children","height","width","map","_temp","field","fieldIndex","fieldByLocale","LocaleComponents","locale","baseField","Object","entries","push","CustomComponent","join","type","path"],"sources":["../../../../src/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.tsx"],"sourcesContent":["'use client'\nconst baseClass = 'render-field-diffs'\nimport type { VersionField } from 'payload'\n\nimport './index.scss'\n\nimport { ShimmerEffect } from '@payloadcms/ui'\nimport React, { Fragment, useEffect } from 'react'\n\nexport const RenderVersionFieldsToDiff = ({\n versionFields,\n}: {\n versionFields: VersionField[]\n}): React.ReactNode => {\n const [hasMounted, setHasMounted] = React.useState(false)\n\n // defer rendering until after the first mount as the CSS is loaded with Emotion\n // this will ensure that the CSS is loaded before rendering the diffs and prevent CLS\n useEffect(() => {\n setHasMounted(true)\n }, [])\n\n return (\n <div className={baseClass}>\n {!hasMounted ? (\n <Fragment>\n <ShimmerEffect height=\"8rem\" width=\"100%\" />\n </Fragment>\n ) : (\n versionFields?.map((field, fieldIndex) => {\n if (field.fieldByLocale) {\n const LocaleComponents: React.ReactNode[] = []\n for (const [locale, baseField] of Object.entries(field.fieldByLocale)) {\n LocaleComponents.push(\n <div className={`${baseClass}__locale`} key={[locale, fieldIndex].join('-')}>\n <div className={`${baseClass}__locale-value`}>{baseField.CustomComponent}</div>\n </div>,\n )\n }\n return (\n <div className={`${baseClass}__field`} key={fieldIndex}>\n {LocaleComponents}\n </div>\n )\n } else if (field.field) {\n return (\n <div\n className={`${baseClass}__field field__${field.field.type}`}\n data-field-path={field.field.path}\n key={fieldIndex}\n >\n {field.field.CustomComponent}\n </div>\n )\n }\n\n return null\n })\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,MAAMC,SAAA,GAAY;AAKlB,SAASC,aAAa,QAAQ;AAC9B,OAAOC,KAAA,IAASC,QAAQ,EAAEC,SAAS,QAAQ;AAE3C,OAAO,MAAMC,yBAAA,GAA4BC,EAAA;EAAA,MAAAC,CAAA,GAAAR,EAAA;EAAC;IAAAS;EAAA,IAAAF,EAIzC;EACC,OAAAG,UAAA,EAAAC,aAAA,IAAoCR,KAAA,CAAAS,QAAA,MAAe;EAAA,IAAAC,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAN,CAAA,QAAAO,MAAA,CAAAC,GAAA;IAIzCH,EAAA,GAAAA,CAAA;MACRF,aAAA,KAAc;IAAA;IACbG,EAAA;IAAEN,CAAA,MAAAK,EAAA;IAAAL,CAAA,MAAAM,EAAA;EAAA;IAAAD,EAAA,GAAAL,CAAA;IAAAM,EAAA,GAAAN,CAAA;EAAA;EAFLH,SAAA,CAAUQ,EAEV,EAAGC,EAAE;EAAA,IAAAG,EAAA;EAAA,IAAAT,CAAA,QAAAE,UAAA,IAAAF,CAAA,QAAAC,aAAA;IAGHQ,EAAA,GAAAC,IAAA,CAAC;MAAAC,SAAA,EAAAlB,SAAA;MAAAmB,QAAA,EACE,CAACV,UAAA,GACAQ,IAAA,CAAAd,QAAA;QAAAgB,QAAA,EACEF,IAAA,CAAAhB,aAAA;UAAAmB,MAAA,EAAsB;UAAAC,KAAA,EAAa;QAAA,C;WAGrCb,aAAA,EAAAc,GAAA,CAAAC,KAAA;IA4BA,C;;;;;;;SAlCJP,E;CAsCJ;AApDyC,SAAAO,MAAAC,KAAA,EAAAC,UAAA;EAAA,IAqB3BD,KAAA,CAAAE,aAAA;IACF,MAAAC,gBAAA;IAA8C,KACzC,OAAAC,MAAA,EAAAC,SAAA,CAAyB,IAAIC,MAAA,CAAAC,OAAA,CAAeP,KAAA,CAAAE,aAAmB;MAClEC,gBAAA,CAAAK,IAAA,CACEf,IAAA,CAAC;QAAAC,SAAA,EAAe,GAAAlB,SAAA,UAAsB;QAAAmB,QAAA,EACpCF,IAAA,CAAC;UAAAC,SAAA,EAAe,GAAAlB,SAAA,gBAA4B;UAAAmB,QAAA,EAAGU,SAAA,CAAAI;QAAA,C;SADJ,CAACL,MAAA,EAAQH,UAAA,EAAAS,IAAA,CAAiB;IAAA;IAAA,OAMzEjB,IAAA,CAAC;MAAAC,SAAA,EAAe,GAAAlB,SAAA,SAAqB;MAAAmB,QAAA,EAClCQ;IAAA,GADyCF,UAAA;EAAA;IAAA,IAIrCD,KAAA,CAAAA,KAAA;MAAA,OAEPP,IAAA,CAAC;QAAAC,SAAA,EACY,GAAAlB,SAAA,kBAA8BwB,KAAA,CAAAA,KAAA,CAAAW,IAAA,EAAkB;QAAA,mBAC1CX,KAAA,CAAAA,KAAA,CAAAY,IAAA;QAAAjB,QAAA,EAGhBK,KAAA,CAAAA,KAAA,CAAAS;MAAA,GAFIR,UAAA;IAAA;EAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { I18nClient } from '@payloadcms/translations';
|
|
2
|
+
import type { ClientFieldSchemaMap, Field, FieldDiffClientProps, FieldDiffServerProps, FieldTypes, PayloadComponent, PayloadRequest, SanitizedFieldPermissions, VersionField } from 'payload';
|
|
3
|
+
export type BuildVersionFieldsArgs = {
|
|
4
|
+
clientSchemaMap: ClientFieldSchemaMap;
|
|
5
|
+
comparisonSiblingData: object;
|
|
6
|
+
customDiffComponents: Partial<Record<FieldTypes, PayloadComponent<FieldDiffServerProps, FieldDiffClientProps>>>;
|
|
7
|
+
entitySlug: string;
|
|
8
|
+
fieldPermissions: {
|
|
9
|
+
[key: string]: SanitizedFieldPermissions;
|
|
10
|
+
} | true;
|
|
11
|
+
fields: Field[];
|
|
12
|
+
i18n: I18nClient;
|
|
13
|
+
modifiedOnly: boolean;
|
|
14
|
+
parentIndexPath: string;
|
|
15
|
+
parentPath: string;
|
|
16
|
+
parentSchemaPath: string;
|
|
17
|
+
req: PayloadRequest;
|
|
18
|
+
selectedLocales: string[];
|
|
19
|
+
versionSiblingData: object;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Build up an object that contains rendered diff components for each field.
|
|
23
|
+
* This is then sent to the client to be rendered.
|
|
24
|
+
*
|
|
25
|
+
* Here, the server is responsible for traversing through the document data and building up this
|
|
26
|
+
* version state object.
|
|
27
|
+
*/
|
|
28
|
+
export declare const buildVersionFields: ({ clientSchemaMap, comparisonSiblingData, customDiffComponents, entitySlug, fieldPermissions, fields, i18n, modifiedOnly, parentIndexPath, parentPath, parentSchemaPath, req, selectedLocales, versionSiblingData, }: BuildVersionFieldsArgs) => {
|
|
29
|
+
versionFields: VersionField[];
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=buildVersionFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildVersionFields.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/RenderFieldsToDiff/buildVersionFields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAGV,oBAAoB,EACpB,KAAK,EACL,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,yBAAyB,EACzB,YAAY,EACb,MAAM,SAAS,CAAA;AAWhB,MAAM,MAAM,sBAAsB,GAAG;IACnC,eAAe,EAAE,oBAAoB,CAAA;IACrC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,oBAAoB,EAAE,OAAO,CAC3B,MAAM,CAAC,UAAU,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC,CACjF,CAAA;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EACZ;QACE,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAA;KACzC,GACD,IAAI,CAAA;IACR,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,UAAU,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,yNAe5B,sBAAsB,KAAG;IAC1B,aAAa,EAAE,YAAY,EAAE,CAAA;CAqG9B,CAAA"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
|
|
2
|
+
import { dequal } from 'dequal/lite';
|
|
3
|
+
import { fieldIsID, getUniqueListBy, tabHasName } from 'payload/shared';
|
|
4
|
+
import { diffMethods } from './fields/diffMethods.js';
|
|
5
|
+
import { diffComponents } from './fields/index.js';
|
|
6
|
+
import { getFieldPathsModified } from './utilities/getFieldPathsModified.js';
|
|
7
|
+
/**
|
|
8
|
+
* Build up an object that contains rendered diff components for each field.
|
|
9
|
+
* This is then sent to the client to be rendered.
|
|
10
|
+
*
|
|
11
|
+
* Here, the server is responsible for traversing through the document data and building up this
|
|
12
|
+
* version state object.
|
|
13
|
+
*/
|
|
14
|
+
export const buildVersionFields = ({
|
|
15
|
+
clientSchemaMap,
|
|
16
|
+
comparisonSiblingData,
|
|
17
|
+
customDiffComponents,
|
|
18
|
+
entitySlug,
|
|
19
|
+
fieldPermissions,
|
|
20
|
+
fields,
|
|
21
|
+
i18n,
|
|
22
|
+
modifiedOnly,
|
|
23
|
+
parentIndexPath,
|
|
24
|
+
parentPath,
|
|
25
|
+
parentSchemaPath,
|
|
26
|
+
req,
|
|
27
|
+
selectedLocales,
|
|
28
|
+
versionSiblingData
|
|
29
|
+
}) => {
|
|
30
|
+
const versionFields = [];
|
|
31
|
+
let fieldIndex = -1;
|
|
32
|
+
for (const field of fields) {
|
|
33
|
+
fieldIndex++;
|
|
34
|
+
if (fieldIsID(field)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
indexPath,
|
|
39
|
+
path,
|
|
40
|
+
schemaPath
|
|
41
|
+
} = getFieldPathsModified({
|
|
42
|
+
field,
|
|
43
|
+
index: fieldIndex,
|
|
44
|
+
parentIndexPath: 'name' in field ? '' : parentIndexPath,
|
|
45
|
+
parentPath,
|
|
46
|
+
parentSchemaPath
|
|
47
|
+
});
|
|
48
|
+
const clientField = clientSchemaMap.get(entitySlug + '.' + schemaPath);
|
|
49
|
+
if (!clientField) {
|
|
50
|
+
req.payload.logger.error({
|
|
51
|
+
clientFieldKey: entitySlug + '.' + schemaPath,
|
|
52
|
+
clientSchemaMapKeys: Array.from(clientSchemaMap.keys()),
|
|
53
|
+
msg: 'No client field found for ' + entitySlug + '.' + schemaPath,
|
|
54
|
+
parentPath,
|
|
55
|
+
parentSchemaPath,
|
|
56
|
+
path,
|
|
57
|
+
schemaPath
|
|
58
|
+
});
|
|
59
|
+
throw new Error('No client field found for ' + entitySlug + '.' + schemaPath);
|
|
60
|
+
}
|
|
61
|
+
const versionField = {};
|
|
62
|
+
const isLocalized = 'localized' in field && field.localized;
|
|
63
|
+
const fieldName = 'name' in field ? field.name : null;
|
|
64
|
+
const versionValue = fieldName ? versionSiblingData?.[fieldName] : versionSiblingData;
|
|
65
|
+
const comparisonValue = fieldName ? comparisonSiblingData?.[fieldName] : comparisonSiblingData;
|
|
66
|
+
if (isLocalized) {
|
|
67
|
+
versionField.fieldByLocale = {};
|
|
68
|
+
for (const locale of selectedLocales) {
|
|
69
|
+
versionField.fieldByLocale[locale] = buildVersionField({
|
|
70
|
+
clientField: clientField,
|
|
71
|
+
clientSchemaMap,
|
|
72
|
+
comparisonValue: comparisonValue?.[locale],
|
|
73
|
+
customDiffComponents,
|
|
74
|
+
entitySlug,
|
|
75
|
+
field,
|
|
76
|
+
fieldPermissions,
|
|
77
|
+
i18n,
|
|
78
|
+
indexPath,
|
|
79
|
+
locale,
|
|
80
|
+
modifiedOnly,
|
|
81
|
+
parentPath,
|
|
82
|
+
parentSchemaPath,
|
|
83
|
+
path,
|
|
84
|
+
req,
|
|
85
|
+
schemaPath,
|
|
86
|
+
selectedLocales,
|
|
87
|
+
versionValue: versionValue?.[locale]
|
|
88
|
+
});
|
|
89
|
+
if (!versionField.fieldByLocale[locale]) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
versionField.field = buildVersionField({
|
|
95
|
+
clientField: clientField,
|
|
96
|
+
clientSchemaMap,
|
|
97
|
+
comparisonValue,
|
|
98
|
+
customDiffComponents,
|
|
99
|
+
entitySlug,
|
|
100
|
+
field,
|
|
101
|
+
fieldPermissions,
|
|
102
|
+
i18n,
|
|
103
|
+
indexPath,
|
|
104
|
+
modifiedOnly,
|
|
105
|
+
parentPath,
|
|
106
|
+
parentSchemaPath,
|
|
107
|
+
path,
|
|
108
|
+
req,
|
|
109
|
+
schemaPath,
|
|
110
|
+
selectedLocales,
|
|
111
|
+
versionValue
|
|
112
|
+
});
|
|
113
|
+
if (!versionField.field) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
versionFields.push(versionField);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
versionFields
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const buildVersionField = ({
|
|
124
|
+
clientField,
|
|
125
|
+
clientSchemaMap,
|
|
126
|
+
comparisonValue,
|
|
127
|
+
customDiffComponents,
|
|
128
|
+
entitySlug,
|
|
129
|
+
field,
|
|
130
|
+
fieldPermissions,
|
|
131
|
+
i18n,
|
|
132
|
+
indexPath,
|
|
133
|
+
locale,
|
|
134
|
+
modifiedOnly,
|
|
135
|
+
parentPath,
|
|
136
|
+
parentSchemaPath,
|
|
137
|
+
path,
|
|
138
|
+
req,
|
|
139
|
+
schemaPath,
|
|
140
|
+
selectedLocales,
|
|
141
|
+
versionValue
|
|
142
|
+
}) => {
|
|
143
|
+
const fieldName = 'name' in field ? field.name : null;
|
|
144
|
+
const diffMethod = diffMethods[field.type] || 'CHARS';
|
|
145
|
+
const hasPermission = fieldPermissions === true || !fieldName || fieldPermissions?.[fieldName] === true || fieldPermissions?.[fieldName]?.read;
|
|
146
|
+
const subFieldPermissions = fieldPermissions === true || !fieldName || fieldPermissions?.[fieldName] === true || fieldPermissions?.[fieldName]?.fields;
|
|
147
|
+
if (!hasPermission) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if (modifiedOnly && dequal(versionValue, comparisonValue)) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const CustomComponent = field?.admin?.components?.Diff ?? customDiffComponents?.[field.type];
|
|
154
|
+
const DefaultComponent = diffComponents?.[field.type];
|
|
155
|
+
const baseVersionField = {
|
|
156
|
+
type: field.type,
|
|
157
|
+
fields: [],
|
|
158
|
+
path,
|
|
159
|
+
schemaPath
|
|
160
|
+
};
|
|
161
|
+
if (field.type === 'tabs' && 'tabs' in field) {
|
|
162
|
+
baseVersionField.tabs = [];
|
|
163
|
+
let tabIndex = -1;
|
|
164
|
+
for (const tab of field.tabs) {
|
|
165
|
+
tabIndex++;
|
|
166
|
+
const isNamedTab = tabHasName(tab);
|
|
167
|
+
const {
|
|
168
|
+
indexPath: tabIndexPath,
|
|
169
|
+
path: tabPath,
|
|
170
|
+
schemaPath: tabSchemaPath
|
|
171
|
+
} = getFieldPathsModified({
|
|
172
|
+
field: {
|
|
173
|
+
...tab,
|
|
174
|
+
type: 'tab'
|
|
175
|
+
},
|
|
176
|
+
index: tabIndex,
|
|
177
|
+
parentIndexPath: indexPath,
|
|
178
|
+
parentPath,
|
|
179
|
+
parentSchemaPath
|
|
180
|
+
});
|
|
181
|
+
baseVersionField.tabs.push({
|
|
182
|
+
name: 'name' in tab ? tab.name : null,
|
|
183
|
+
fields: buildVersionFields({
|
|
184
|
+
clientSchemaMap,
|
|
185
|
+
comparisonSiblingData: 'name' in tab ? comparisonValue?.[tab.name] : comparisonValue,
|
|
186
|
+
customDiffComponents,
|
|
187
|
+
entitySlug,
|
|
188
|
+
fieldPermissions,
|
|
189
|
+
fields: tab.fields,
|
|
190
|
+
i18n,
|
|
191
|
+
modifiedOnly,
|
|
192
|
+
parentIndexPath: isNamedTab ? '' : tabIndexPath,
|
|
193
|
+
parentPath: tabPath,
|
|
194
|
+
parentSchemaPath: tabSchemaPath,
|
|
195
|
+
req,
|
|
196
|
+
selectedLocales,
|
|
197
|
+
versionSiblingData: 'name' in tab ? versionValue?.[tab.name] : versionValue
|
|
198
|
+
}).versionFields,
|
|
199
|
+
label: tab.label
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
} else if ('fields' in field) {
|
|
203
|
+
if (field.type === 'array') {
|
|
204
|
+
if (!Array.isArray(versionValue)) {
|
|
205
|
+
throw new Error('Expected versionValue to be an array');
|
|
206
|
+
}
|
|
207
|
+
baseVersionField.rows = [];
|
|
208
|
+
for (let i = 0; i < versionValue.length; i++) {
|
|
209
|
+
const comparisonRow = comparisonValue?.[i] || {};
|
|
210
|
+
const versionRow = versionValue?.[i] || {};
|
|
211
|
+
baseVersionField.rows[i] = buildVersionFields({
|
|
212
|
+
clientSchemaMap,
|
|
213
|
+
comparisonSiblingData: comparisonRow,
|
|
214
|
+
customDiffComponents,
|
|
215
|
+
entitySlug,
|
|
216
|
+
fieldPermissions,
|
|
217
|
+
fields: field.fields,
|
|
218
|
+
i18n,
|
|
219
|
+
modifiedOnly,
|
|
220
|
+
parentIndexPath: 'name' in field ? '' : indexPath,
|
|
221
|
+
parentPath: path + '.' + i,
|
|
222
|
+
parentSchemaPath: schemaPath,
|
|
223
|
+
req,
|
|
224
|
+
selectedLocales,
|
|
225
|
+
versionSiblingData: versionRow
|
|
226
|
+
}).versionFields;
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
baseVersionField.fields = buildVersionFields({
|
|
230
|
+
clientSchemaMap,
|
|
231
|
+
comparisonSiblingData: comparisonValue,
|
|
232
|
+
customDiffComponents,
|
|
233
|
+
entitySlug,
|
|
234
|
+
fieldPermissions,
|
|
235
|
+
fields: field.fields,
|
|
236
|
+
i18n,
|
|
237
|
+
modifiedOnly,
|
|
238
|
+
parentIndexPath: 'name' in field ? '' : indexPath,
|
|
239
|
+
parentPath: path,
|
|
240
|
+
parentSchemaPath: schemaPath,
|
|
241
|
+
req,
|
|
242
|
+
selectedLocales,
|
|
243
|
+
versionSiblingData: versionValue
|
|
244
|
+
}).versionFields;
|
|
245
|
+
}
|
|
246
|
+
} else if (field.type === 'blocks') {
|
|
247
|
+
baseVersionField.rows = [];
|
|
248
|
+
if (!Array.isArray(versionValue)) {
|
|
249
|
+
throw new Error('Expected versionValue to be an array');
|
|
250
|
+
}
|
|
251
|
+
for (let i = 0; i < versionValue.length; i++) {
|
|
252
|
+
const comparisonRow = comparisonValue?.[i] || {};
|
|
253
|
+
const versionRow = versionValue[i] || {};
|
|
254
|
+
const versionBlock = field.blocks.find(block => block.slug === versionRow.blockType);
|
|
255
|
+
let fields = [];
|
|
256
|
+
if (versionRow.blockType === comparisonRow.blockType) {
|
|
257
|
+
fields = versionBlock.fields;
|
|
258
|
+
} else {
|
|
259
|
+
const comparisonBlock = field.blocks.find(block => block.slug === comparisonRow.blockType);
|
|
260
|
+
if (comparisonBlock) {
|
|
261
|
+
fields = getUniqueListBy([...versionBlock.fields, ...comparisonBlock.fields], 'name');
|
|
262
|
+
} else {
|
|
263
|
+
fields = versionBlock.fields;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
baseVersionField.rows[i] = buildVersionFields({
|
|
267
|
+
clientSchemaMap,
|
|
268
|
+
comparisonSiblingData: comparisonRow,
|
|
269
|
+
customDiffComponents,
|
|
270
|
+
entitySlug,
|
|
271
|
+
fieldPermissions,
|
|
272
|
+
fields,
|
|
273
|
+
i18n,
|
|
274
|
+
modifiedOnly,
|
|
275
|
+
parentIndexPath: 'name' in field ? '' : indexPath,
|
|
276
|
+
parentPath: path + '.' + i,
|
|
277
|
+
parentSchemaPath: schemaPath + '.' + versionBlock.slug,
|
|
278
|
+
req,
|
|
279
|
+
selectedLocales,
|
|
280
|
+
versionSiblingData: versionRow
|
|
281
|
+
}).versionFields;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const clientCellProps = {
|
|
285
|
+
baseVersionField: {
|
|
286
|
+
...baseVersionField,
|
|
287
|
+
CustomComponent: undefined
|
|
288
|
+
},
|
|
289
|
+
comparisonValue,
|
|
290
|
+
diffMethod,
|
|
291
|
+
field: clientField,
|
|
292
|
+
fieldPermissions: subFieldPermissions,
|
|
293
|
+
versionValue
|
|
294
|
+
};
|
|
295
|
+
const serverCellProps = {
|
|
296
|
+
...clientCellProps,
|
|
297
|
+
clientField,
|
|
298
|
+
field,
|
|
299
|
+
i18n,
|
|
300
|
+
req,
|
|
301
|
+
selectedLocales
|
|
302
|
+
};
|
|
303
|
+
baseVersionField.CustomComponent = RenderServerComponent({
|
|
304
|
+
clientProps: locale ? {
|
|
305
|
+
...clientCellProps,
|
|
306
|
+
locale
|
|
307
|
+
} : clientCellProps,
|
|
308
|
+
Component: CustomComponent,
|
|
309
|
+
Fallback: DefaultComponent,
|
|
310
|
+
importMap: req.payload.importMap,
|
|
311
|
+
key: 'diff component',
|
|
312
|
+
serverProps: locale ? {
|
|
313
|
+
...serverCellProps,
|
|
314
|
+
locale
|
|
315
|
+
} : serverCellProps
|
|
316
|
+
});
|
|
317
|
+
return baseVersionField;
|
|
318
|
+
};
|
|
319
|
+
//# sourceMappingURL=buildVersionFields.js.map
|