@payloadcms/next 3.19.0 → 3.20.0-canary.0e01b65

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.
Files changed (135) hide show
  1. package/dist/prod/styles.css +1 -1
  2. package/dist/views/Account/index.d.ts.map +1 -1
  3. package/dist/views/Account/index.js +2 -1
  4. package/dist/views/Account/index.js.map +1 -1
  5. package/dist/views/CreateFirstUser/index.client.d.ts.map +1 -1
  6. package/dist/views/CreateFirstUser/index.client.js +4 -2
  7. package/dist/views/CreateFirstUser/index.client.js.map +1 -1
  8. package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
  9. package/dist/views/CreateFirstUser/index.js +2 -1
  10. package/dist/views/CreateFirstUser/index.js.map +1 -1
  11. package/dist/views/Document/getDocumentPermissions.js +2 -2
  12. package/dist/views/Document/getDocumentPermissions.js.map +1 -1
  13. package/dist/views/Document/index.d.ts.map +1 -1
  14. package/dist/views/Document/index.js +2 -1
  15. package/dist/views/Document/index.js.map +1 -1
  16. package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -1
  17. package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +2 -0
  18. package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -1
  19. package/dist/views/LivePreview/index.client.d.ts.map +1 -1
  20. package/dist/views/LivePreview/index.client.js +5 -2
  21. package/dist/views/LivePreview/index.client.js.map +1 -1
  22. package/dist/views/Version/Default/SelectedLocalesContext.d.ts +8 -0
  23. package/dist/views/Version/Default/SelectedLocalesContext.d.ts.map +1 -0
  24. package/dist/views/Version/Default/SelectedLocalesContext.js +10 -0
  25. package/dist/views/Version/Default/SelectedLocalesContext.js.map +1 -0
  26. package/dist/views/Version/Default/index.d.ts.map +1 -1
  27. package/dist/views/Version/Default/index.js +89 -159
  28. package/dist/views/Version/Default/index.js.map +1 -1
  29. package/dist/views/Version/Default/types.d.ts +4 -4
  30. package/dist/views/Version/Default/types.d.ts.map +1 -1
  31. package/dist/views/Version/Default/types.js.map +1 -1
  32. package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.d.ts +27 -0
  33. package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.d.ts.map +1 -0
  34. package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.js +76 -0
  35. package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.js.map +1 -0
  36. package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.scss +46 -0
  37. package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.d.ts +6 -0
  38. package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.d.ts.map +1 -0
  39. package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.js +36 -0
  40. package/dist/views/Version/RenderFieldsToDiff/RenderVersionFieldsToDiff.js.map +1 -0
  41. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.d.ts +30 -0
  42. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.d.ts.map +1 -0
  43. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.js +300 -0
  44. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.js.map +1 -0
  45. package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.d.ts +4 -0
  46. package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.d.ts.map +1 -0
  47. package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.js +64 -0
  48. package/dist/views/Version/RenderFieldsToDiff/fields/Collapsible/index.js.map +1 -0
  49. package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.d.ts +5 -0
  50. package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.d.ts.map +1 -0
  51. package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.js +69 -0
  52. package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.js.map +1 -0
  53. package/dist/views/Version/RenderFieldsToDiff/fields/Group/index.scss +14 -0
  54. package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.d.ts +3 -4
  55. package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.d.ts.map +1 -1
  56. package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js +100 -63
  57. package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js.map +1 -1
  58. package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.scss +3 -12
  59. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.d.ts +2 -4
  60. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.d.ts.map +1 -1
  61. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.js +18 -17
  62. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.js.map +1 -1
  63. package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.d.ts +4 -0
  64. package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.d.ts.map +1 -0
  65. package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.js +17 -0
  66. package/dist/views/Version/RenderFieldsToDiff/fields/Row/index.js.map +1 -0
  67. package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.d.ts +2 -4
  68. package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.d.ts.map +1 -1
  69. package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js +56 -28
  70. package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js.map +1 -1
  71. package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.d.ts +3 -4
  72. package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.d.ts.map +1 -1
  73. package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.js +146 -42
  74. package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.js.map +1 -1
  75. package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.scss +20 -0
  76. package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.d.ts +2 -4
  77. package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.d.ts.map +1 -1
  78. package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js +71 -37
  79. package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js.map +1 -1
  80. package/dist/views/Version/RenderFieldsToDiff/fields/index.d.ts +2 -22
  81. package/dist/views/Version/RenderFieldsToDiff/fields/index.d.ts.map +1 -1
  82. package/dist/views/Version/RenderFieldsToDiff/fields/index.js +13 -9
  83. package/dist/views/Version/RenderFieldsToDiff/fields/index.js.map +1 -1
  84. package/dist/views/Version/RenderFieldsToDiff/index.d.ts +2 -5
  85. package/dist/views/Version/RenderFieldsToDiff/index.d.ts.map +1 -1
  86. package/dist/views/Version/RenderFieldsToDiff/index.js +8 -113
  87. package/dist/views/Version/RenderFieldsToDiff/index.js.map +1 -1
  88. package/dist/views/Version/RenderFieldsToDiff/types.d.ts +2 -20
  89. package/dist/views/Version/RenderFieldsToDiff/types.d.ts.map +1 -1
  90. package/dist/views/Version/RenderFieldsToDiff/types.js.map +1 -1
  91. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.d.ts +21 -0
  92. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.d.ts.map +1 -0
  93. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.js +194 -0
  94. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.js.map +1 -0
  95. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js +860 -0
  96. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js.map +1 -0
  97. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.d.ts +2 -0
  98. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.d.ts.map +1 -0
  99. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.js +4 -0
  100. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.js.map +1 -0
  101. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js +46 -0
  102. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js.map +1 -0
  103. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.d.ts +27 -0
  104. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.d.ts.map +1 -0
  105. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.js +30 -0
  106. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldPathsModified.js.map +1 -0
  107. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.d.ts +18 -0
  108. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.d.ts.map +1 -0
  109. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.js +44 -0
  110. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.js.map +1 -0
  111. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js +122 -0
  112. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js.map +1 -0
  113. package/dist/views/Version/Restore/index.d.ts.map +1 -1
  114. package/dist/views/Version/Restore/index.js +2 -2
  115. package/dist/views/Version/Restore/index.js.map +1 -1
  116. package/dist/views/Version/SelectComparison/index.d.ts.map +1 -1
  117. package/dist/views/Version/SelectComparison/index.js +7 -3
  118. package/dist/views/Version/SelectComparison/index.js.map +1 -1
  119. package/dist/views/Version/index.d.ts.map +1 -1
  120. package/dist/views/Version/index.js +117 -15
  121. package/dist/views/Version/index.js.map +1 -1
  122. package/dist/views/Versions/getLatestVersion.d.ts +4 -1
  123. package/dist/views/Versions/getLatestVersion.d.ts.map +1 -1
  124. package/dist/views/Versions/getLatestVersion.js +6 -0
  125. package/dist/views/Versions/getLatestVersion.js.map +1 -1
  126. package/package.json +8 -8
  127. package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.d.ts +0 -6
  128. package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.d.ts.map +0 -1
  129. package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.js +0 -43
  130. package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.js.map +0 -1
  131. package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.scss +0 -14
  132. package/dist/views/Version/RenderFieldsToDiff/fields/types.d.ts +0 -22
  133. package/dist/views/Version/RenderFieldsToDiff/fields/types.d.ts.map +0 -1
  134. package/dist/views/Version/RenderFieldsToDiff/fields/types.js +0 -2
  135. package/dist/views/Version/RenderFieldsToDiff/fields/types.js.map +0 -1
@@ -1,29 +1,33 @@
1
- import Iterable from './Iterable/index.js';
2
- import Nested from './Nested/index.js';
3
- import Relationship from './Relationship/index.js';
4
- import Select from './Select/index.js';
5
- import Tabs from './Tabs/index.js';
6
- import Text from './Text/index.js';
1
+ import { Collapsible } from './Collapsible/index.js';
2
+ import { Group } from './Group/index.js';
3
+ import { Iterable } from './Iterable/index.js';
4
+ import { Relationship } from './Relationship/index.js';
5
+ import { Row } from './Row/index.js';
6
+ import { Select } from './Select/index.js';
7
+ import { Tabs } from './Tabs/index.js';
8
+ import { Text } from './Text/index.js';
7
9
  export const diffComponents = {
8
10
  array: Iterable,
9
11
  blocks: Iterable,
10
12
  checkbox: Text,
11
13
  code: Text,
12
- collapsible: Nested,
14
+ collapsible: Collapsible,
13
15
  date: Text,
14
16
  email: Text,
15
- group: Nested,
17
+ group: Group,
18
+ join: null,
16
19
  json: Text,
17
20
  number: Text,
18
21
  point: Text,
19
22
  radio: Select,
20
23
  relationship: Relationship,
21
24
  richText: Text,
22
- row: Nested,
25
+ row: Row,
23
26
  select: Select,
24
27
  tabs: Tabs,
25
28
  text: Text,
26
29
  textarea: Text,
30
+ ui: null,
27
31
  upload: Relationship
28
32
  };
29
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Iterable","Nested","Relationship","Select","Tabs","Text","diffComponents","array","blocks","checkbox","code","collapsible","date","email","group","json","number","point","radio","relationship","richText","row","select","tabs","text","textarea","upload"],"sources":["../../../../../src/views/Version/RenderFieldsToDiff/fields/index.tsx"],"sourcesContent":["import Iterable from './Iterable/index.js'\nimport Nested from './Nested/index.js'\nimport Relationship from './Relationship/index.js'\nimport Select from './Select/index.js'\nimport Tabs from './Tabs/index.js'\nimport Text from './Text/index.js'\n\nexport const diffComponents = {\n array: Iterable,\n blocks: Iterable,\n checkbox: Text,\n code: Text,\n collapsible: Nested,\n date: Text,\n email: Text,\n group: Nested,\n json: Text,\n number: Text,\n point: Text,\n radio: Select,\n relationship: Relationship,\n richText: Text,\n row: Nested,\n select: Select,\n tabs: Tabs,\n text: Text,\n textarea: Text,\n upload: Relationship,\n}\n"],"mappings":"AAAA,OAAOA,QAAA,MAAc;AACrB,OAAOC,MAAA,MAAY;AACnB,OAAOC,YAAA,MAAkB;AACzB,OAAOC,MAAA,MAAY;AACnB,OAAOC,IAAA,MAAU;AACjB,OAAOC,IAAA,MAAU;AAEjB,OAAO,MAAMC,cAAA,GAAiB;EAC5BC,KAAA,EAAOP,QAAA;EACPQ,MAAA,EAAQR,QAAA;EACRS,QAAA,EAAUJ,IAAA;EACVK,IAAA,EAAML,IAAA;EACNM,WAAA,EAAaV,MAAA;EACbW,IAAA,EAAMP,IAAA;EACNQ,KAAA,EAAOR,IAAA;EACPS,KAAA,EAAOb,MAAA;EACPc,IAAA,EAAMV,IAAA;EACNW,MAAA,EAAQX,IAAA;EACRY,KAAA,EAAOZ,IAAA;EACPa,KAAA,EAAOf,MAAA;EACPgB,YAAA,EAAcjB,YAAA;EACdkB,QAAA,EAAUf,IAAA;EACVgB,GAAA,EAAKpB,MAAA;EACLqB,MAAA,EAAQnB,MAAA;EACRoB,IAAA,EAAMnB,IAAA;EACNoB,IAAA,EAAMnB,IAAA;EACNoB,QAAA,EAAUpB,IAAA;EACVqB,MAAA,EAAQxB;AACV","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Collapsible","Group","Iterable","Relationship","Row","Select","Tabs","Text","diffComponents","array","blocks","checkbox","code","collapsible","date","email","group","join","json","number","point","radio","relationship","richText","row","select","tabs","text","textarea","ui","upload"],"sources":["../../../../../src/views/Version/RenderFieldsToDiff/fields/index.tsx"],"sourcesContent":["import type { DiffComponentProps, FieldTypes } from 'payload'\n\nimport { Collapsible } from './Collapsible/index.js'\nimport { Group } from './Group/index.js'\nimport { Iterable } from './Iterable/index.js'\nimport { Relationship } from './Relationship/index.js'\nimport { Row } from './Row/index.js'\nimport { Select } from './Select/index.js'\nimport { Tabs } from './Tabs/index.js'\nimport { Text } from './Text/index.js'\n\nexport const diffComponents: Record<FieldTypes, React.FC<DiffComponentProps>> = {\n array: Iterable,\n blocks: Iterable,\n checkbox: Text,\n code: Text,\n collapsible: Collapsible,\n date: Text,\n email: Text,\n group: Group,\n join: null,\n json: Text,\n number: Text,\n point: Text,\n radio: Select,\n relationship: Relationship,\n richText: Text,\n row: Row,\n select: Select,\n tabs: Tabs,\n text: Text,\n textarea: Text,\n ui: null,\n upload: Relationship,\n}\n"],"mappings":"AAEA,SAASA,WAAW,QAAQ;AAC5B,SAASC,KAAK,QAAQ;AACtB,SAASC,QAAQ,QAAQ;AACzB,SAASC,YAAY,QAAQ;AAC7B,SAASC,GAAG,QAAQ;AACpB,SAASC,MAAM,QAAQ;AACvB,SAASC,IAAI,QAAQ;AACrB,SAASC,IAAI,QAAQ;AAErB,OAAO,MAAMC,cAAA,GAAmE;EAC9EC,KAAA,EAAOP,QAAA;EACPQ,MAAA,EAAQR,QAAA;EACRS,QAAA,EAAUJ,IAAA;EACVK,IAAA,EAAML,IAAA;EACNM,WAAA,EAAab,WAAA;EACbc,IAAA,EAAMP,IAAA;EACNQ,KAAA,EAAOR,IAAA;EACPS,KAAA,EAAOf,KAAA;EACPgB,IAAA,EAAM;EACNC,IAAA,EAAMX,IAAA;EACNY,MAAA,EAAQZ,IAAA;EACRa,KAAA,EAAOb,IAAA;EACPc,KAAA,EAAOhB,MAAA;EACPiB,YAAA,EAAcnB,YAAA;EACdoB,QAAA,EAAUhB,IAAA;EACViB,GAAA,EAAKpB,GAAA;EACLqB,MAAA,EAAQpB,MAAA;EACRqB,IAAA,EAAMpB,IAAA;EACNqB,IAAA,EAAMpB,IAAA;EACNqB,QAAA,EAAUrB,IAAA;EACVsB,EAAA,EAAI;EACJC,MAAA,EAAQ3B;AACV","ignoreList":[]}
@@ -1,6 +1,3 @@
1
- import React from 'react';
2
- import type { Props } from './types.js';
3
- import './index.scss';
4
- declare const RenderFieldsToDiff: React.FC<Props>;
5
- export default RenderFieldsToDiff;
1
+ import { type BuildVersionFieldsArgs } from './buildVersionFields.js';
2
+ export declare const RenderDiff: (args: BuildVersionFieldsArgs) => React.ReactNode;
6
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/RenderFieldsToDiff/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAkB,KAAK,EAAE,MAAM,YAAY,CAAA;AAIvD,OAAO,cAAc,CAAA;AAIrB,QAAA,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA0IvC,CAAA;AAED,eAAe,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/RenderFieldsToDiff/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAGzF,eAAO,MAAM,UAAU,SAAU,sBAAsB,KAAG,KAAK,CAAC,SAI/D,CAAA"}
@@ -1,117 +1,12 @@
1
- 'use client';
2
-
3
1
  import { jsx as _jsx } from "react/jsx-runtime";
4
- import { fieldAffectsData, fieldIsID } from 'payload/shared';
5
- import React from 'react';
6
- import { diffMethods } from './fields/diffMethods.js';
7
- import Nested from './fields/Nested/index.js';
8
- const baseClass = 'render-field-diffs';
9
- const RenderFieldsToDiff = ({
10
- comparison,
11
- diffComponents: __diffComponents,
12
- fieldPermissions,
13
- fields,
14
- i18n,
15
- locales,
16
- version
17
- }) => {
18
- // typing it as `as typeof _diffComponents` here ensures the TField generics of DiffComponentProps are respected.
19
- // Without it, you could pass a UI field to the Tabs component, without it erroring
20
- const diffComponents = __diffComponents;
21
- return /*#__PURE__*/_jsx("div", {
22
- className: baseClass,
23
- children: fields?.map((field, i) => {
24
- if (fieldIsID(field)) {
25
- return null;
26
- }
27
- const Component = diffComponents[field.type];
28
- const isRichText = field.type === 'richText';
29
- const diffMethod = diffMethods[field.type] || 'CHARS';
30
- if (Component) {
31
- if (fieldAffectsData(field)) {
32
- const fieldName = field.name;
33
- const valueIsObject = field.type === 'code' || field.type === 'json';
34
- const versionValue = valueIsObject ? JSON.stringify(version?.[fieldName]) : version?.[fieldName];
35
- const comparisonValue = valueIsObject ? JSON.stringify(comparison?.[fieldName]) : comparison?.[fieldName];
36
- const hasPermission = fieldPermissions === true || fieldPermissions?.[fieldName] === true || fieldPermissions?.[fieldName]?.read;
37
- const subFieldPermissions = fieldPermissions === true || fieldPermissions?.[fieldName] === true || fieldPermissions?.[fieldName]?.fields;
38
- if (!hasPermission) {
39
- return null;
40
- }
41
- const baseCellProps = {
42
- comparison: comparisonValue,
43
- diffComponents,
44
- diffMethod,
45
- field,
46
- fieldPermissions: subFieldPermissions,
47
- fields: 'fields' in field ? field?.fields : fields,
48
- i18n,
49
- isRichText,
50
- locales,
51
- version: versionValue
52
- };
53
- if (field.localized) {
54
- return /*#__PURE__*/_jsx("div", {
55
- className: `${baseClass}__field`,
56
- children: locales.map((locale, index) => {
57
- const versionLocaleValue = versionValue?.[locale];
58
- const comparisonLocaleValue = comparisonValue?.[locale];
59
- const cellProps = {
60
- ...baseCellProps,
61
- comparison: comparisonLocaleValue,
62
- version: versionLocaleValue
63
- };
64
- return /*#__PURE__*/_jsx("div", {
65
- className: `${baseClass}__locale`,
66
- children: /*#__PURE__*/_jsx("div", {
67
- className: `${baseClass}__locale-value`,
68
- children: /*#__PURE__*/_jsx(Component, {
69
- ...cellProps,
70
- locale: locale
71
- })
72
- })
73
- }, [locale, index].join('-'));
74
- })
75
- }, i);
76
- }
77
- return /*#__PURE__*/_jsx("div", {
78
- className: `${baseClass}__field`,
79
- children: /*#__PURE__*/_jsx(Component, {
80
- ...baseCellProps
81
- })
82
- }, i);
83
- }
84
- if (field.type === 'tabs' && 'tabs' in field) {
85
- const Tabs = diffComponents.tabs;
86
- return /*#__PURE__*/_jsx(Tabs, {
87
- comparison: comparison,
88
- diffComponents: diffComponents,
89
- field: field,
90
- fieldPermissions: fieldPermissions,
91
- fields: [],
92
- i18n: i18n,
93
- locales: locales,
94
- version: version
95
- }, i);
96
- }
97
- // At this point, we are dealing with a `row`, etc
98
- if ('fields' in field) {
99
- return /*#__PURE__*/_jsx(Nested, {
100
- comparison: comparison,
101
- diffComponents: diffComponents,
102
- disableGutter: true,
103
- field: field,
104
- fieldPermissions: fieldPermissions,
105
- fields: field.fields,
106
- i18n: i18n,
107
- locales: locales,
108
- version: version
109
- }, i);
110
- }
111
- }
112
- return null;
113
- })
2
+ import { buildVersionFields } from './buildVersionFields.js';
3
+ import { RenderVersionFieldsToDiff } from './RenderVersionFieldsToDiff.js';
4
+ export const RenderDiff = args => {
5
+ const {
6
+ versionFields
7
+ } = buildVersionFields(args);
8
+ return /*#__PURE__*/_jsx(RenderVersionFieldsToDiff, {
9
+ versionFields: versionFields
114
10
  });
115
11
  };
116
- export default RenderFieldsToDiff;
117
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["fieldAffectsData","fieldIsID","React","diffMethods","Nested","baseClass","RenderFieldsToDiff","comparison","diffComponents","__diffComponents","fieldPermissions","fields","i18n","locales","version","_jsx","className","map","field","i","Component","type","isRichText","diffMethod","fieldName","name","valueIsObject","versionValue","JSON","stringify","comparisonValue","hasPermission","read","subFieldPermissions","baseCellProps","localized","locale","index","versionLocaleValue","comparisonLocaleValue","cellProps","join","Tabs","tabs","disableGutter"],"sources":["../../../../src/views/Version/RenderFieldsToDiff/index.tsx"],"sourcesContent":["'use client'\nimport type { DiffMethod } from 'react-diff-viewer-continued'\n\nimport { fieldAffectsData, fieldIsID } from 'payload/shared'\nimport React from 'react'\n\nimport type { diffComponents as _diffComponents } from './fields/index.js'\nimport type { FieldDiffProps, Props } from './types.js'\n\nimport { diffMethods } from './fields/diffMethods.js'\nimport Nested from './fields/Nested/index.js'\nimport './index.scss'\n\nconst baseClass = 'render-field-diffs'\n\nconst RenderFieldsToDiff: React.FC<Props> = ({\n comparison,\n diffComponents: __diffComponents,\n fieldPermissions,\n fields,\n i18n,\n locales,\n version,\n}) => {\n // typing it as `as typeof _diffComponents` here ensures the TField generics of DiffComponentProps are respected.\n // Without it, you could pass a UI field to the Tabs component, without it erroring\n const diffComponents: typeof _diffComponents = __diffComponents as typeof _diffComponents\n\n return (\n <div className={baseClass}>\n {fields?.map((field, i) => {\n if (fieldIsID(field)) {\n return null\n }\n\n const Component = diffComponents[field.type]\n\n const isRichText = field.type === 'richText'\n const diffMethod: DiffMethod = diffMethods[field.type] || 'CHARS'\n\n if (Component) {\n if (fieldAffectsData(field)) {\n const fieldName = field.name\n const valueIsObject = field.type === 'code' || field.type === 'json'\n\n const versionValue = valueIsObject\n ? JSON.stringify(version?.[fieldName])\n : version?.[fieldName]\n\n const comparisonValue = valueIsObject\n ? JSON.stringify(comparison?.[fieldName])\n : comparison?.[fieldName]\n\n const hasPermission =\n fieldPermissions === true ||\n fieldPermissions?.[fieldName] === true ||\n fieldPermissions?.[fieldName]?.read\n\n const subFieldPermissions =\n fieldPermissions === true ||\n fieldPermissions?.[fieldName] === true ||\n fieldPermissions?.[fieldName]?.fields\n\n if (!hasPermission) {\n return null\n }\n\n const baseCellProps: FieldDiffProps = {\n comparison: comparisonValue,\n diffComponents,\n diffMethod,\n field,\n fieldPermissions: subFieldPermissions,\n fields: 'fields' in field ? field?.fields : fields,\n i18n,\n isRichText,\n locales,\n version: versionValue,\n }\n\n if (field.localized) {\n return (\n <div className={`${baseClass}__field`} key={i}>\n {locales.map((locale, index) => {\n const versionLocaleValue = versionValue?.[locale]\n const comparisonLocaleValue = comparisonValue?.[locale]\n\n const cellProps = {\n ...baseCellProps,\n comparison: comparisonLocaleValue,\n version: versionLocaleValue,\n }\n\n return (\n <div className={`${baseClass}__locale`} key={[locale, index].join('-')}>\n <div className={`${baseClass}__locale-value`}>\n <Component {...cellProps} locale={locale} />\n </div>\n </div>\n )\n })}\n </div>\n )\n }\n\n return (\n <div className={`${baseClass}__field`} key={i}>\n <Component {...baseCellProps} />\n </div>\n )\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n const Tabs = diffComponents.tabs\n\n return (\n <Tabs\n comparison={comparison}\n diffComponents={diffComponents}\n field={field}\n fieldPermissions={fieldPermissions}\n fields={[]}\n i18n={i18n}\n key={i}\n locales={locales}\n version={version}\n />\n )\n }\n\n // At this point, we are dealing with a `row`, etc\n if ('fields' in field) {\n return (\n <Nested\n comparison={comparison}\n diffComponents={diffComponents}\n disableGutter\n field={field}\n fieldPermissions={fieldPermissions}\n fields={field.fields}\n i18n={i18n}\n key={i}\n locales={locales}\n version={version}\n />\n )\n }\n }\n\n return null\n })}\n </div>\n )\n}\n\nexport default RenderFieldsToDiff\n"],"mappings":"AAAA;;;AAGA,SAASA,gBAAgB,EAAEC,SAAS,QAAQ;AAC5C,OAAOC,KAAA,MAAW;AAKlB,SAASC,WAAW,QAAQ;AAC5B,OAAOC,MAAA,MAAY;AAGnB,MAAMC,SAAA,GAAY;AAElB,MAAMC,kBAAA,GAAsCA,CAAC;EAC3CC,UAAU;EACVC,cAAA,EAAgBC,gBAAgB;EAChCC,gBAAgB;EAChBC,MAAM;EACNC,IAAI;EACJC,OAAO;EACPC;AAAO,CACR;EACC;EACA;EACA,MAAMN,cAAA,GAAyCC,gBAAA;EAE/C,oBACEM,IAAA,CAAC;IAAIC,SAAA,EAAW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EAAMA,IAAA;YAENC,OAAA,EAASA,OAAA;YACTC,OAAA,EAASA;aAFJK,CAAA;QAKX;QAEA;QACA,IAAI,YAAYD,KAAA,EAAO;UACrB,oBACEH,IAAA,CAACX,MAAA;YACCG,UAAA,EAAYA,UAAA;YACZC,cAAA,EAAgBA,cAAA;YAChBoC,aAAa;YACb1B,KAAA,EAAOA,KAAA;YACPR,gBAAA,EAAkBA,gBAAA;YAClBC,MAAA,EAAQO,KAAA,CAAMP,MAAM;YACpBC,IAAA,EAAMA,IAAA;YAENC,OAAA,EAASA,OAAA;YACTC,OAAA,EAASA;aAFJK,CAAA;QAKX;MACF;MAEA,OAAO;IACT;;AAGN;AAEA,eAAeb,kBAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["buildVersionFields","RenderVersionFieldsToDiff","RenderDiff","args","versionFields","_jsx"],"sources":["../../../../src/views/Version/RenderFieldsToDiff/index.tsx"],"sourcesContent":["import { buildVersionFields, type BuildVersionFieldsArgs } from './buildVersionFields.js'\nimport { RenderVersionFieldsToDiff } from './RenderVersionFieldsToDiff.js'\n\nexport const RenderDiff = (args: BuildVersionFieldsArgs): React.ReactNode => {\n const { versionFields } = buildVersionFields(args)\n\n return <RenderVersionFieldsToDiff versionFields={versionFields} />\n}\n"],"mappings":";AAAA,SAASA,kBAAkB,QAAqC;AAChE,SAASC,yBAAyB,QAAQ;AAE1C,OAAO,MAAMC,UAAA,GAAcC,IAAA;EACzB,MAAM;IAAEC;EAAa,CAAE,GAAGJ,kBAAA,CAAmBG,IAAA;EAE7C,oBAAOE,IAAA,CAACJ,yBAAA;IAA0BG,aAAA,EAAeA;;AACnD","ignoreList":[]}
@@ -1,21 +1,3 @@
1
- import type { I18nClient } from '@payloadcms/translations';
2
- import type { ClientField, SanitizedFieldPermissions } from 'payload';
3
- import type { DiffMethod } from 'react-diff-viewer-continued';
4
- import type { DiffComponents } from './fields/types.js';
5
- export type Props = {
6
- readonly comparison: Record<string, any>;
7
- readonly diffComponents: DiffComponents;
8
- readonly fieldPermissions: {
9
- [key: string]: SanitizedFieldPermissions;
10
- } | true;
11
- readonly fields: ClientField[];
12
- readonly i18n: I18nClient;
13
- readonly locales: string[];
14
- readonly version: Record<string, any>;
15
- };
16
- export type FieldDiffProps = {
17
- diffMethod: DiffMethod;
18
- field: ClientField;
19
- isRichText: boolean;
20
- } & Props;
1
+ import type { DiffComponentProps } from 'payload';
2
+ export type DiffComponents = Record<string, React.FC<DiffComponentProps>>;
21
3
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/RenderFieldsToDiff/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAA;IACvC,QAAQ,CAAC,gBAAgB,EACrB;QACE,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAA;KACzC,GACD,IAAI,CAAA;IACR,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,CAAA;IAC9B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,WAAW,CAAA;IAClB,UAAU,EAAE,OAAO,CAAA;CACpB,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/RenderFieldsToDiff/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEjD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../src/views/Version/RenderFieldsToDiff/types.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { ClientField, SanitizedFieldPermissions } from 'payload'\nimport type { DiffMethod } from 'react-diff-viewer-continued'\n\nimport type { DiffComponents } from './fields/types.js'\n\nexport type Props = {\n readonly comparison: Record<string, any>\n readonly diffComponents: DiffComponents\n readonly fieldPermissions:\n | {\n [key: string]: SanitizedFieldPermissions\n }\n | true\n readonly fields: ClientField[]\n readonly i18n: I18nClient\n readonly locales: string[]\n readonly version: Record<string, any>\n}\n\nexport type FieldDiffProps = {\n diffMethod: DiffMethod\n field: ClientField\n isRichText: boolean\n} & Props\n"],"mappings":"AAoBA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../src/views/Version/RenderFieldsToDiff/types.ts"],"sourcesContent":["import type { DiffComponentProps } from 'payload'\n\nexport type DiffComponents = Record<string, React.FC<DiffComponentProps>>\n"],"mappings":"AAEA","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import type { ArrayFieldClient, BlocksFieldClient, ClientField } from 'payload';
2
+ type Args = {
3
+ comparison: unknown;
4
+ fields: ClientField[];
5
+ locales: string[] | undefined;
6
+ version: unknown;
7
+ };
8
+ /**
9
+ * Recursively counts the number of changed fields between comparison and
10
+ * version data for a given set of fields.
11
+ */
12
+ export declare function countChangedFields({ comparison, fields, locales, version }: Args): number;
13
+ type countChangedFieldsInRowsArgs = {
14
+ comparisonRows: unknown[];
15
+ field: ArrayFieldClient | BlocksFieldClient;
16
+ locales: string[] | undefined;
17
+ versionRows: unknown[];
18
+ };
19
+ export declare function countChangedFieldsInRows({ comparisonRows, field, locales, versionRows, }: countChangedFieldsInRowsArgs): number;
20
+ export {};
21
+ //# sourceMappingURL=countChangedFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countChangedFields.d.ts","sourceRoot":"","sources":["../../../../../src/views/Version/RenderFieldsToDiff/utilities/countChangedFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK/E,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,OAAO,CAAA;IACnB,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,UA8IhF;AAED,KAAK,4BAA4B,GAAG;IAClC,cAAc,EAAE,OAAO,EAAE,CAAA;IACzB,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAAA;IAC3C,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC7B,WAAW,EAAE,OAAO,EAAE,CAAA;CACvB,CAAA;AAED,wBAAgB,wBAAwB,CAAC,EACvC,cAAmB,EACnB,KAAK,EACL,OAAO,EACP,WAAgB,GACjB,EAAE,4BAA4B,UA0B9B"}
@@ -0,0 +1,194 @@
1
+ import { fieldHasChanges } from './fieldHasChanges.js';
2
+ import { getFieldsForRowComparison } from './getFieldsForRowComparison.js';
3
+ /**
4
+ * Recursively counts the number of changed fields between comparison and
5
+ * version data for a given set of fields.
6
+ */
7
+ export function countChangedFields({
8
+ comparison,
9
+ fields,
10
+ locales,
11
+ version
12
+ }) {
13
+ let count = 0;
14
+ fields.forEach(field => {
15
+ // Don't count the id field since it is not displayed in the UI
16
+ if ('name' in field && field.name === 'id') {
17
+ return;
18
+ }
19
+ const fieldType = field.type;
20
+ switch (fieldType) {
21
+ // Iterable fields are arrays and blocks fields. We iterate over each row and
22
+ // count the number of changed fields in each.
23
+ case 'array':
24
+ case 'blocks':
25
+ {
26
+ if (locales && field.localized) {
27
+ locales.forEach(locale => {
28
+ const comparisonRows = comparison?.[field.name]?.[locale] ?? [];
29
+ const versionRows = version?.[field.name]?.[locale] ?? [];
30
+ count += countChangedFieldsInRows({
31
+ comparisonRows,
32
+ field,
33
+ locales,
34
+ versionRows
35
+ });
36
+ });
37
+ } else {
38
+ const comparisonRows = comparison?.[field.name] ?? [];
39
+ const versionRows = version?.[field.name] ?? [];
40
+ count += countChangedFieldsInRows({
41
+ comparisonRows,
42
+ field,
43
+ locales,
44
+ versionRows
45
+ });
46
+ }
47
+ break;
48
+ }
49
+ // Regular fields without nested fields.
50
+ case 'checkbox':
51
+ case 'code':
52
+ case 'date':
53
+ case 'email':
54
+ case 'join':
55
+ case 'json':
56
+ case 'number':
57
+ case 'point':
58
+ case 'radio':
59
+ case 'relationship':
60
+ case 'richText':
61
+ case 'select':
62
+ case 'text':
63
+ case 'textarea':
64
+ case 'upload':
65
+ {
66
+ // Fields that have a name and contain data. We can just check if the data has changed.
67
+ if (locales && field.localized) {
68
+ locales.forEach(locale => {
69
+ if (fieldHasChanges(version?.[field.name]?.[locale], comparison?.[field.name]?.[locale])) {
70
+ count++;
71
+ }
72
+ });
73
+ } else if (fieldHasChanges(version?.[field.name], comparison?.[field.name])) {
74
+ count++;
75
+ }
76
+ break;
77
+ }
78
+ // Fields that have nested fields, but don't nest their fields' data.
79
+ case 'collapsible':
80
+ case 'row':
81
+ {
82
+ count += countChangedFields({
83
+ comparison,
84
+ fields: field.fields,
85
+ locales,
86
+ version
87
+ });
88
+ break;
89
+ }
90
+ // Fields that have nested fields and nest their fields' data.
91
+ case 'group':
92
+ {
93
+ if (locales && field.localized) {
94
+ locales.forEach(locale => {
95
+ count += countChangedFields({
96
+ comparison: comparison?.[field.name]?.[locale],
97
+ fields: field.fields,
98
+ locales,
99
+ version: version?.[field.name]?.[locale]
100
+ });
101
+ });
102
+ } else {
103
+ count += countChangedFields({
104
+ comparison: comparison?.[field.name],
105
+ fields: field.fields,
106
+ locales,
107
+ version: version?.[field.name]
108
+ });
109
+ }
110
+ break;
111
+ }
112
+ // Each tab in a tabs field has nested fields. The fields data may be
113
+ // nested or not depending on the existence of a name property.
114
+ case 'tabs':
115
+ {
116
+ field.tabs.forEach(tab => {
117
+ if ('name' in tab && locales && tab.localized) {
118
+ // Named localized tab
119
+ locales.forEach(locale => {
120
+ count += countChangedFields({
121
+ comparison: comparison?.[tab.name]?.[locale],
122
+ fields: tab.fields,
123
+ locales,
124
+ version: version?.[tab.name]?.[locale]
125
+ });
126
+ });
127
+ } else if ('name' in tab) {
128
+ // Named tab
129
+ count += countChangedFields({
130
+ comparison: comparison?.[tab.name],
131
+ fields: tab.fields,
132
+ locales,
133
+ version: version?.[tab.name]
134
+ });
135
+ } else {
136
+ // Unnamed tab
137
+ count += countChangedFields({
138
+ comparison,
139
+ fields: tab.fields,
140
+ locales,
141
+ version
142
+ });
143
+ }
144
+ });
145
+ break;
146
+ }
147
+ // UI fields don't have data and are not displayed in the version view
148
+ // so we can ignore them.
149
+ case 'ui':
150
+ {
151
+ break;
152
+ }
153
+ default:
154
+ {
155
+ const _exhaustiveCheck = fieldType;
156
+ throw new Error(`Unexpected field.type in countChangedFields : ${String(fieldType)}`);
157
+ }
158
+ }
159
+ });
160
+ return count;
161
+ }
162
+ export function countChangedFieldsInRows({
163
+ comparisonRows = [],
164
+ field,
165
+ locales,
166
+ versionRows = []
167
+ }) {
168
+ let count = 0;
169
+ let i = 0;
170
+ while (comparisonRows[i] || versionRows[i]) {
171
+ const comparisonRow = comparisonRows?.[i] || {};
172
+ const versionRow = versionRows?.[i] || {};
173
+ const {
174
+ fields: rowFields
175
+ } = getFieldsForRowComparison({
176
+ baseVersionField: {
177
+ fields: []
178
+ },
179
+ comparisonRow,
180
+ field,
181
+ row: i,
182
+ versionRow
183
+ });
184
+ count += countChangedFields({
185
+ comparison: comparisonRow,
186
+ fields: rowFields,
187
+ locales,
188
+ version: versionRow
189
+ });
190
+ i++;
191
+ }
192
+ return count;
193
+ }
194
+ //# sourceMappingURL=countChangedFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countChangedFields.js","names":["fieldHasChanges","getFieldsForRowComparison","countChangedFields","comparison","fields","locales","version","count","forEach","field","name","fieldType","type","localized","locale","comparisonRows","versionRows","countChangedFieldsInRows","tabs","tab","_exhaustiveCheck","Error","String","i","comparisonRow","versionRow","rowFields","baseVersionField","row"],"sources":["../../../../../src/views/Version/RenderFieldsToDiff/utilities/countChangedFields.ts"],"sourcesContent":["import type { ArrayFieldClient, BlocksFieldClient, ClientField } from 'payload'\n\nimport { fieldHasChanges } from './fieldHasChanges.js'\nimport { getFieldsForRowComparison } from './getFieldsForRowComparison.js'\n\ntype Args = {\n comparison: unknown\n fields: ClientField[]\n locales: string[] | undefined\n version: unknown\n}\n\n/**\n * Recursively counts the number of changed fields between comparison and\n * version data for a given set of fields.\n */\nexport function countChangedFields({ comparison, fields, locales, version }: Args) {\n let count = 0\n\n fields.forEach((field) => {\n // Don't count the id field since it is not displayed in the UI\n if ('name' in field && field.name === 'id') {\n return\n }\n const fieldType = field.type\n switch (fieldType) {\n // Iterable fields are arrays and blocks fields. We iterate over each row and\n // count the number of changed fields in each.\n case 'array':\n case 'blocks': {\n if (locales && field.localized) {\n locales.forEach((locale) => {\n const comparisonRows = comparison?.[field.name]?.[locale] ?? []\n const versionRows = version?.[field.name]?.[locale] ?? []\n count += countChangedFieldsInRows({ comparisonRows, field, locales, versionRows })\n })\n } else {\n const comparisonRows = comparison?.[field.name] ?? []\n const versionRows = version?.[field.name] ?? []\n count += countChangedFieldsInRows({ comparisonRows, field, locales, versionRows })\n }\n break\n }\n\n // Regular fields without nested fields.\n case 'checkbox':\n case 'code':\n case 'date':\n case 'email':\n case 'join':\n case 'json':\n case 'number':\n case 'point':\n case 'radio':\n case 'relationship':\n case 'richText':\n case 'select':\n case 'text':\n case 'textarea':\n case 'upload': {\n // Fields that have a name and contain data. We can just check if the data has changed.\n if (locales && field.localized) {\n locales.forEach((locale) => {\n if (\n fieldHasChanges(version?.[field.name]?.[locale], comparison?.[field.name]?.[locale])\n ) {\n count++\n }\n })\n } else if (fieldHasChanges(version?.[field.name], comparison?.[field.name])) {\n count++\n }\n break\n }\n // Fields that have nested fields, but don't nest their fields' data.\n case 'collapsible':\n case 'row': {\n count += countChangedFields({\n comparison,\n fields: field.fields,\n locales,\n version,\n })\n\n break\n }\n\n // Fields that have nested fields and nest their fields' data.\n case 'group': {\n if (locales && field.localized) {\n locales.forEach((locale) => {\n count += countChangedFields({\n comparison: comparison?.[field.name]?.[locale],\n fields: field.fields,\n locales,\n version: version?.[field.name]?.[locale],\n })\n })\n } else {\n count += countChangedFields({\n comparison: comparison?.[field.name],\n fields: field.fields,\n locales,\n version: version?.[field.name],\n })\n }\n break\n }\n\n // Each tab in a tabs field has nested fields. The fields data may be\n // nested or not depending on the existence of a name property.\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if ('name' in tab && locales && tab.localized) {\n // Named localized tab\n locales.forEach((locale) => {\n count += countChangedFields({\n comparison: comparison?.[tab.name]?.[locale],\n fields: tab.fields,\n locales,\n version: version?.[tab.name]?.[locale],\n })\n })\n } else if ('name' in tab) {\n // Named tab\n count += countChangedFields({\n comparison: comparison?.[tab.name],\n fields: tab.fields,\n locales,\n version: version?.[tab.name],\n })\n } else {\n // Unnamed tab\n count += countChangedFields({\n comparison,\n fields: tab.fields,\n locales,\n version,\n })\n }\n })\n break\n }\n\n // UI fields don't have data and are not displayed in the version view\n // so we can ignore them.\n case 'ui': {\n break\n }\n\n default: {\n const _exhaustiveCheck: never = fieldType\n throw new Error(`Unexpected field.type in countChangedFields : ${String(fieldType)}`)\n }\n }\n })\n\n return count\n}\n\ntype countChangedFieldsInRowsArgs = {\n comparisonRows: unknown[]\n field: ArrayFieldClient | BlocksFieldClient\n locales: string[] | undefined\n versionRows: unknown[]\n}\n\nexport function countChangedFieldsInRows({\n comparisonRows = [],\n field,\n locales,\n versionRows = [],\n}: countChangedFieldsInRowsArgs) {\n let count = 0\n let i = 0\n\n while (comparisonRows[i] || versionRows[i]) {\n const comparisonRow = comparisonRows?.[i] || {}\n const versionRow = versionRows?.[i] || {}\n\n const { fields: rowFields } = getFieldsForRowComparison({\n baseVersionField: { fields: [] },\n comparisonRow,\n field,\n row: i,\n versionRow,\n })\n\n count += countChangedFields({\n comparison: comparisonRow,\n fields: rowFields,\n locales,\n version: versionRow,\n })\n\n i++\n }\n return count\n}\n"],"mappings":"AAEA,SAASA,eAAe,QAAQ;AAChC,SAASC,yBAAyB,QAAQ;AAS1C;;;;AAIA,OAAO,SAASC,mBAAmB;EAAEC,UAAU;EAAEC,MAAM;EAAEC,OAAO;EAAEC;AAAO,CAAQ;EAC/E,IAAIC,KAAA,GAAQ;EAEZH,MAAA,CAAOI,OAAO,CAAEC,KAAA;IACd;IACA,IAAI,UAAUA,KAAA,IAASA,KAAA,CAAMC,IAAI,KAAK,MAAM;MAC1C;IACF;IACA,MAAMC,SAAA,GAAYF,KAAA,CAAMG,IAAI;IAC5B,QAAQD,SAAA;MACN;MACA;MACA,KAAK;MACL,KAAK;QAAU;UACb,IAAIN,OAAA,IAAWI,KAAA,CAAMI,SAAS,EAAE;YAC9BR,OAAA,CAAQG,OAAO,CAAEM,MAAA;cACf,MAAMC,cAAA,GAAiBZ,UAAA,GAAaM,KAAA,CAAMC,IAAI,CAAC,GAAGI,MAAA,CAAO,IAAI,EAAE;cAC/D,MAAME,WAAA,GAAcV,OAAA,GAAUG,KAAA,CAAMC,IAAI,CAAC,GAA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