payload 3.40.0-internal.9e8d70e → 3.40.0-internal.c3af32e

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 (34) hide show
  1. package/dist/auth/executeAuthStrategies.d.ts.map +1 -1
  2. package/dist/auth/executeAuthStrategies.js +0 -2
  3. package/dist/auth/executeAuthStrategies.js.map +1 -1
  4. package/dist/auth/operations/auth.d.ts +0 -4
  5. package/dist/auth/operations/auth.d.ts.map +1 -1
  6. package/dist/auth/operations/auth.js +1 -2
  7. package/dist/auth/operations/auth.js.map +1 -1
  8. package/dist/auth/operations/local/auth.d.ts.map +1 -1
  9. package/dist/auth/operations/local/auth.js +0 -1
  10. package/dist/auth/operations/local/auth.js.map +1 -1
  11. package/dist/auth/types.d.ts +0 -4
  12. package/dist/auth/types.d.ts.map +1 -1
  13. package/dist/auth/types.js.map +1 -1
  14. package/dist/config/types.d.ts +2 -3
  15. package/dist/config/types.d.ts.map +1 -1
  16. package/dist/config/types.js.map +1 -1
  17. package/dist/query-presets/constraints.d.ts.map +1 -1
  18. package/dist/query-presets/constraints.js +24 -27
  19. package/dist/query-presets/constraints.js.map +1 -1
  20. package/dist/query-presets/types.d.ts +4 -5
  21. package/dist/query-presets/types.d.ts.map +1 -1
  22. package/dist/query-presets/types.js.map +1 -1
  23. package/dist/utilities/flattenTopLevelFields.d.ts +1 -1
  24. package/dist/utilities/flattenTopLevelFields.d.ts.map +1 -1
  25. package/dist/utilities/flattenTopLevelFields.js +49 -64
  26. package/dist/utilities/flattenTopLevelFields.js.map +1 -1
  27. package/dist/utilities/flattenTopLevelFields.spec.js +28 -205
  28. package/dist/utilities/flattenTopLevelFields.spec.js.map +1 -1
  29. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  30. package/dist/utilities/handleEndpoints.js +1 -1
  31. package/dist/utilities/handleEndpoints.js.map +1 -1
  32. package/dist/versions/payloadPackageList.js +1 -1
  33. package/dist/versions/payloadPackageList.js.map +1 -1
  34. package/package.json +2 -2
@@ -3,20 +3,6 @@ import { fieldAffectsData } from '../fields/config/types.js';
3
3
  import { toWords } from '../utilities/formatLabels.js';
4
4
  import { preventLockout } from './preventLockout.js';
5
5
  import { operations } from './types.js';
6
- const defaultConstraintOptions = [
7
- {
8
- label: 'Everyone',
9
- value: 'everyone'
10
- },
11
- {
12
- label: 'Only Me',
13
- value: 'onlyMe'
14
- },
15
- {
16
- label: 'Specific Users',
17
- value: 'specificUsers'
18
- }
19
- ];
20
6
  export const getConstraints = (config)=>({
21
7
  name: 'access',
22
8
  type: 'group',
@@ -26,11 +12,11 @@ export const getConstraints = (config)=>({
26
12
  },
27
13
  condition: (data)=>Boolean(data?.isShared)
28
14
  },
29
- fields: operations.map((constraintOperation)=>({
15
+ fields: operations.map((operation)=>({
30
16
  type: 'collapsible',
31
17
  fields: [
32
18
  {
33
- name: constraintOperation,
19
+ name: operation,
34
20
  type: 'group',
35
21
  admin: {
36
22
  hideGutter: true
@@ -40,11 +26,21 @@ export const getConstraints = (config)=>({
40
26
  name: 'constraint',
41
27
  type: 'select',
42
28
  defaultValue: 'onlyMe',
43
- filterOptions: (args)=>typeof config?.queryPresets?.filterConstraints === 'function' ? config.queryPresets.filterConstraints(args) : args.options,
44
- label: ({ i18n })=>`Specify who can ${constraintOperation} this ${getTranslation(config.queryPresets?.labels?.singular || 'Preset', i18n)}`,
29
+ label: ({ i18n })=>`Specify who can ${operation} this ${getTranslation(config.queryPresets?.labels?.singular || 'Preset', i18n)}`,
45
30
  options: [
46
- ...defaultConstraintOptions,
47
- ...config?.queryPresets?.constraints?.[constraintOperation]?.map((option)=>({
31
+ {
32
+ label: 'Everyone',
33
+ value: 'everyone'
34
+ },
35
+ {
36
+ label: 'Only Me',
37
+ value: 'onlyMe'
38
+ },
39
+ {
40
+ label: 'Specific Users',
41
+ value: 'specificUsers'
42
+ },
43
+ ...config?.queryPresets?.constraints?.[operation]?.map((option)=>({
48
44
  label: option.label,
49
45
  value: option.value
50
46
  })) || []
@@ -54,29 +50,30 @@ export const getConstraints = (config)=>({
54
50
  name: 'users',
55
51
  type: 'relationship',
56
52
  admin: {
57
- condition: (data)=>Boolean(data?.access?.[constraintOperation]?.constraint === 'specificUsers')
53
+ condition: (data)=>Boolean(data?.access?.[operation]?.constraint === 'specificUsers')
58
54
  },
59
55
  hasMany: true,
60
56
  hooks: {
61
57
  beforeChange: [
62
58
  ({ data, req })=>{
63
- if (data?.access?.[constraintOperation]?.constraint === 'onlyMe' && req.user) {
59
+ if (data?.access?.[operation]?.constraint === 'onlyMe' && req.user) {
64
60
  return [
65
61
  req.user.id
66
62
  ];
67
63
  }
68
- if (data?.access?.[constraintOperation]?.constraint === 'specificUsers' && req.user) {
64
+ if (data?.access?.[operation]?.constraint === 'specificUsers' && req.user) {
69
65
  return [
70
- ...data?.access?.[constraintOperation]?.users || [],
66
+ ...data?.access?.[operation]?.users || [],
71
67
  req.user.id
72
68
  ];
73
69
  }
70
+ return data?.access?.[operation]?.users;
74
71
  }
75
72
  ]
76
73
  },
77
74
  relationTo: config.admin?.user ?? 'users'
78
75
  },
79
- ...config?.queryPresets?.constraints?.[constraintOperation]?.reduce((acc, option)=>{
76
+ ...config?.queryPresets?.constraints?.[operation]?.reduce((acc, option)=>{
80
77
  option.fields?.forEach((field, index)=>{
81
78
  acc.push({
82
79
  ...field
@@ -84,7 +81,7 @@ export const getConstraints = (config)=>({
84
81
  if (fieldAffectsData(field)) {
85
82
  acc[index].admin = {
86
83
  ...acc[index]?.admin || {},
87
- condition: (data)=>Boolean(data?.access?.[constraintOperation]?.constraint === option.value)
84
+ condition: (data)=>Boolean(data?.access?.[operation]?.constraint === option.value)
88
85
  };
89
86
  }
90
87
  });
@@ -94,7 +91,7 @@ export const getConstraints = (config)=>({
94
91
  label: false
95
92
  }
96
93
  ],
97
- label: ()=>toWords(constraintOperation)
94
+ label: ()=>toWords(operation)
98
95
  })),
99
96
  label: 'Sharing settings',
100
97
  validate: preventLockout
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/query-presets/constraints.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\n\nimport type { Config } from '../config/types.js'\nimport type { Field, Option } from '../fields/config/types.js'\nimport type { QueryPresetConstraint } from './types.js'\n\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { toWords } from '../utilities/formatLabels.js'\nimport { preventLockout } from './preventLockout.js'\nimport { operations } from './types.js'\n\nconst defaultConstraintOptions: Option[] = [\n {\n label: 'Everyone',\n value: 'everyone',\n },\n {\n label: 'Only Me',\n value: 'onlyMe',\n },\n {\n label: 'Specific Users',\n value: 'specificUsers',\n },\n]\n\nexport const getConstraints = (config: Config): Field => ({\n name: 'access',\n type: 'group',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsAccessCell',\n },\n condition: (data) => Boolean(data?.isShared),\n },\n fields: operations.map((constraintOperation) => ({\n type: 'collapsible',\n fields: [\n {\n name: constraintOperation,\n type: 'group',\n admin: {\n hideGutter: true,\n },\n fields: [\n {\n name: 'constraint',\n type: 'select',\n defaultValue: 'onlyMe',\n filterOptions: (args) =>\n typeof config?.queryPresets?.filterConstraints === 'function'\n ? config.queryPresets.filterConstraints(args)\n : args.options,\n label: ({ i18n }) =>\n `Specify who can ${constraintOperation} this ${getTranslation(config.queryPresets?.labels?.singular || 'Preset', i18n)}`,\n options: [\n ...defaultConstraintOptions,\n ...(config?.queryPresets?.constraints?.[constraintOperation]?.map(\n (option: QueryPresetConstraint) => ({\n label: option.label,\n value: option.value,\n }),\n ) || []),\n ],\n },\n {\n name: 'users',\n type: 'relationship',\n admin: {\n condition: (data) =>\n Boolean(data?.access?.[constraintOperation]?.constraint === 'specificUsers'),\n },\n hasMany: true,\n hooks: {\n beforeChange: [\n ({ data, req }) => {\n if (data?.access?.[constraintOperation]?.constraint === 'onlyMe' && req.user) {\n return [req.user.id]\n }\n\n if (\n data?.access?.[constraintOperation]?.constraint === 'specificUsers' &&\n req.user\n ) {\n return [...(data?.access?.[constraintOperation]?.users || []), req.user.id]\n }\n },\n ],\n },\n relationTo: config.admin?.user ?? 'users', // TODO: remove this fallback when the args are properly typed as `SanitizedConfig`\n },\n ...(config?.queryPresets?.constraints?.[constraintOperation]?.reduce(\n (acc: Field[], option: QueryPresetConstraint) => {\n option.fields?.forEach((field, index) => {\n acc.push({ ...field })\n\n if (fieldAffectsData(field)) {\n acc[index].admin = {\n ...(acc[index]?.admin || {}),\n condition: (data) =>\n Boolean(data?.access?.[constraintOperation]?.constraint === option.value),\n }\n }\n })\n\n return acc\n },\n [] as Field[],\n ) || []),\n ],\n label: false,\n },\n ],\n label: () => toWords(constraintOperation),\n })),\n label: 'Sharing settings',\n validate: preventLockout,\n})\n"],"names":["getTranslation","fieldAffectsData","toWords","preventLockout","operations","defaultConstraintOptions","label","value","getConstraints","config","name","type","admin","components","Cell","condition","data","Boolean","isShared","fields","map","constraintOperation","hideGutter","defaultValue","filterOptions","args","queryPresets","filterConstraints","options","i18n","labels","singular","constraints","option","access","constraint","hasMany","hooks","beforeChange","req","user","id","users","relationTo","reduce","acc","forEach","field","index","push","validate"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AAMzD,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,OAAO,QAAQ,+BAA8B;AACtD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,UAAU,QAAQ,aAAY;AAEvC,MAAMC,2BAAqC;IACzC;QACEC,OAAO;QACPC,OAAO;IACT;IACA;QACED,OAAO;QACPC,OAAO;IACT;IACA;QACED,OAAO;QACPC,OAAO;IACT;CACD;AAED,OAAO,MAAMC,iBAAiB,CAACC,SAA2B,CAAA;QACxDC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,MAAM;YACR;YACAC,WAAW,CAACC,OAASC,QAAQD,MAAME;QACrC;QACAC,QAAQf,WAAWgB,GAAG,CAAC,CAACC,sBAAyB,CAAA;gBAC/CV,MAAM;gBACNQ,QAAQ;oB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B,QAAQiB,cAAcM,aAAa,CAACX,oBAAoB,EAAEuB,OAC5D,CAACC,KAAcZ;gCACbA,OAAOd,MAAM,EAAE2B,QAAQ,CAACC,OAAOC;oCAC7BH,IAAII,IAAI,CAAC;wCAAE,GAAGF,KAAK;oCAAC;oCAEpB,IAAI9C,iBAAiB8C,QAAQ;wCAC3BF,GAAG,CAACG,MAAM,CAACpC,KAAK,GAAG;4CACjB,GAAIiC,GAAG,CAACG,MAAM,EAAEpC,SAAS,CAAC,CAAC;4CAC3BG,WAAW,CAACC,OACVC,QAAQD,MAAMkB,QAAQ,CAACb,oBAAoB,EAAEc,eAAeF,OAAO1B,KAAK;wCAC5E;oCACF;gCACF;gCAEA,OAAOsC;4BACT,GACA,EAAE,KACC,EAAE;yBACR;wBACDvC,OAAO;oBACT;iBACD;gBACDA,OAAO,IAAMJ,QAAQmB;YACvB,CAAA;QACAf,OAAO;QACP4C,UAAU/C;IACZ,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/query-presets/constraints.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\n\nimport type { Config } from '../config/types.js'\nimport type { Field } from '../fields/config/types.js'\n\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { toWords } from '../utilities/formatLabels.js'\nimport { preventLockout } from './preventLockout.js'\nimport { operations, type QueryPresetConstraint } from './types.js'\n\nexport const getConstraints = (config: Config): Field => ({\n name: 'access',\n type: 'group',\n admin: {\n components: {\n Cell: '@payloadcms/ui#QueryPresetsAccessCell',\n },\n condition: (data) => Boolean(data?.isShared),\n },\n fields: operations.map((operation) => ({\n type: 'collapsible',\n fields: [\n {\n name: operation,\n type: 'group',\n admin: {\n hideGutter: true,\n },\n fields: [\n {\n name: 'constraint',\n type: 'select',\n defaultValue: 'onlyMe',\n label: ({ i18n }) =>\n `Specify who can ${operation} this ${getTranslation(config.queryPresets?.labels?.singular || 'Preset', i18n)}`,\n options: [\n {\n label: 'Everyone',\n value: 'everyone',\n },\n {\n label: 'Only Me',\n value: 'onlyMe',\n },\n {\n label: 'Specific Users',\n value: 'specificUsers',\n },\n ...(config?.queryPresets?.constraints?.[operation]?.map(\n (option: QueryPresetConstraint) => ({\n label: option.label,\n value: option.value,\n }),\n ) || []),\n ],\n },\n {\n name: 'users',\n type: 'relationship',\n admin: {\n condition: (data) =>\n Boolean(data?.access?.[operation]?.constraint === 'specificUsers'),\n },\n hasMany: true,\n hooks: {\n beforeChange: [\n ({ data, req }) => {\n if (data?.access?.[operation]?.constraint === 'onlyMe' && req.user) {\n return [req.user.id]\n }\n\n if (data?.access?.[operation]?.constraint === 'specificUsers' && req.user) {\n return [...(data?.access?.[operation]?.users || []), req.user.id]\n }\n\n return data?.access?.[operation]?.users\n },\n ],\n },\n relationTo: config.admin?.user ?? 'users', // TODO: remove this fallback when the args are properly typed as `SanitizedConfig`\n },\n ...(config?.queryPresets?.constraints?.[operation]?.reduce(\n (acc: Field[], option: QueryPresetConstraint) => {\n option.fields?.forEach((field, index) => {\n acc.push({ ...field })\n\n if (fieldAffectsData(field)) {\n acc[index].admin = {\n ...(acc[index]?.admin || {}),\n condition: (data) =>\n Boolean(data?.access?.[operation]?.constraint === option.value),\n }\n }\n })\n\n return acc\n },\n [] as Field[],\n ) || []),\n ],\n label: false,\n },\n ],\n label: () => toWords(operation),\n })),\n label: 'Sharing settings',\n validate: preventLockout,\n})\n"],"names":["getTranslation","fieldAffectsData","toWords","preventLockout","operations","getConstraints","config","name","type","admin","components","Cell","condition","data","Boolean","isShared","fields","map","operation","hideGutter","defaultValue","label","i18n","queryPresets","labels","singular","options","value","constraints","option","access","constraint","hasMany","hooks","beforeChange","req","user","id","users","relationTo","reduce","acc","forEach","field","index","push","validate"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AAKzD,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,OAAO,QAAQ,+BAA8B;AACtD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,UAAU,QAAoC,aAAY;A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IC,IAAI,EAAE;gDACzE,OAAO;uDAAKvB,MAAMiB,QAAQ,CAACZ,UAAU,EAAEoB,SAAS,EAAE;oDAAGH,IAAIC,IAAI,CAACC,EAAE;iDAAC;4CACnE;4CAEA,OAAOxB,MAAMiB,QAAQ,CAACZ,UAAU,EAAEoB;wCACpC;qCACD;gCACH;gCACAC,YAAYjC,OAAOG,KAAK,EAAE2B,QAAQ;4BACpC;+BACI9B,QAAQiB,cAAcK,aAAa,CAACV,UAAU,EAAEsB,OAClD,CAACC,KAAcZ;gCACbA,OAAOb,MAAM,EAAE0B,QAAQ,CAACC,OAAOC;oCAC7BH,IAAII,IAAI,CAAC;wCAAE,GAAGF,KAAK;oCAAC;oCAEpB,IAAI1C,iBAAiB0C,QAAQ;wCAC3BF,GAAG,CAACG,MAAM,CAACnC,KAAK,GAAG;4CACjB,GAAIgC,GAAG,CAACG,MAAM,EAAEnC,SAAS,CAAC,CAAC;4CAC3BG,WAAW,CAACC,OACVC,QAAQD,MAAMiB,QAAQ,CAACZ,UAAU,EAAEa,eAAeF,OAAOF,KAAK;wCAClE;oCACF;gCACF;gCAEA,OAAOc;4BACT,GACA,EAAE,KACC,EAAE;yBACR;wBACDpB,OAAO;oBACT;iBACD;gBACDA,OAAO,IAAMnB,QAAQgB;YACvB,CAAA;QACAG,OAAO;QACPyB,UAAU3C;IACZ,CAAA,EAAE"}
@@ -3,13 +3,11 @@ import type { Access, CollectionSlug } from '../index.js';
3
3
  import type { ListPreferences } from '../preferences/types.js';
4
4
  import type { Where } from '../types/index.js';
5
5
  export declare const operations: readonly ["read", "update", "delete"];
6
- export type ConstraintOperation = (typeof operations)[number];
7
- export type DefaultConstraint = 'everyone' | 'onlyMe' | 'specificUsers';
8
- export type Constraint = DefaultConstraint | string;
6
+ type Operation = (typeof operations)[number];
9
7
  export type QueryPreset = {
10
8
  access: {
11
- [operation in ConstraintOperation]: {
12
- constraint: DefaultConstraint;
9
+ [operation in Operation]: {
10
+ constraint: 'everyone' | 'onlyMe' | 'specificUsers';
13
11
  users?: string[];
14
12
  };
15
13
  };
@@ -27,4 +25,5 @@ export type QueryPresetConstraint = {
27
25
  value: string;
28
26
  };
29
27
  export type QueryPresetConstraints = QueryPresetConstraint[];
28
+ export {};
30
29
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/query-presets/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,eAAO,MAAM,UAAU,uCAAwC,CAAA;AAE/D,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,eAAe,CAAA;AAEvE,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,MAAM,CAAA;AAEnD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE;SACL,SAAS,IAAI,mBAAmB,GAAG;YAClC,UAAU,EAAE,iBAAiB,CAAA;YAC7B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;SACjB;KACF,CAAA;IACD,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IACnC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,iBAAiB,EAAE,cAAc,CAAA;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAA;I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qB,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/query-presets/types.ts"],"sourcesContent":["import type { Field } from '../fields/config/types.js'\nimport type { Access, CollectionSlug } from '../index.js'\nimport type { ListPreferences } from '../preferences/types.js'\nimport type { Where } from '../types/index.js'\n\n// Note: order matters here as it will change the rendered order in the UI\nexport const operations = ['read', 'update', 'delete'] as const\n\nexport type ConstraintOperation = (typeof operations)[number]\n\nexport type DefaultConstraint = 'everyone' | 'onlyMe' | 'specificUsers'\n\nexport type Constraint = DefaultConstraint | string // TODO: type `string` as the custom constraints provided by the config\n\nexport type QueryPreset = {\n access: {\n [operation in ConstraintOperation]: {\n constraint: DefaultConstraint\n users?: string[]\n }\n }\n columns: ListPreferences['columns']\n id: number | string\n isShared: boolean\n relatedCollection: CollectionSlug\n title: string\n where: Where\n}\n\nexport type QueryPresetConstraint = {\n access: Access<QueryPreset>\n fields?: Field[]\n label: string\n value: string\n}\n\nexport type QueryPresetConstraints = QueryPresetConstraint[]\n"],"names":["operations"],"mappings":"AAKA,0EAA0E;AAC1E,OAAO,MAAMA,aAAa;IAAC;IAAQ;IAAU;CAAS,CAAS"}
1
+ {"version":3,"sources":["../../src/query-presets/types.ts"],"sourcesContent":["import type { Field } from '../fields/config/types.js'\nimport type { Access, CollectionSlug } from '../index.js'\nimport type { ListPreferences } from '../preferences/types.js'\nimport type { Where } from '../types/index.js'\n\n// Note: order matters here as it will change the rendered order in the UI\nexport const operations = ['read', 'update', 'delete'] as const\n\ntype Operation = (typeof operations)[number]\n\nexport type QueryPreset = {\n access: {\n [operation in Operation]: {\n constraint: 'everyone' | 'onlyMe' | 'specificUsers'\n users?: string[]\n }\n }\n columns: ListPreferences['columns']\n id: number | string\n isShared: boolean\n relatedCollection: CollectionSlug\n title: string\n where: Where\n}\n\nexport type QueryPresetConstraint = {\n access: Access<QueryPreset>\n fields?: Field[]\n label: string\n value: string\n}\n\nexport type QueryPresetConstraints = QueryPresetConstraint[]\n"],"names":["operations"],"mappings":"AAKA,0EAA0E;AAC1E,OAAO,MAAMA,aAAa;IAAC;IAAQ;IAAU;CAAS,CAAS"}
@@ -28,7 +28,7 @@ type FlattenFieldsOptions = {
28
28
  */
29
29
  labelPrefix?: string;
30
30
  /**
31
- * If true, nested fields inside `group` & `tabs` fields will be lifted to the top level
31
+ * If true, nested fields inside `group` fields will be lifted to the top level
32
32
  * and given contextual `accessor` and `labelWithPrefix` values.
33
33
  * Default: false.
34
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"flattenTopLevelFields.d.ts","sourceRoot":"","sources":["../../src/utilities/flattenTopLevelFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAK1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,6BAA6B,EAE9B,MAAM,2BAA2B,CAAA;AASlC,KAAK,cAAc,CAAC,MAAM,IAAI,MAAM,SAAS,WAAW,GACpD;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,CAC9C,wBAAwB,GACxB,6BAA6B,CAChC,GACD;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,CAAC,kBAAkB,GAAG,uBAAuB,CAAC,CAAA;AAIpG;;GAEG;AACH,KAAK,oBAAoB,GAAG;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAA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G,KAAK,EACvD,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,cAAc,CAAC,MAAM,CAAC,EAAE,CAwG1B;AAED,eAAe,aAAa,CAAA"}
@@ -13,72 +13,34 @@ import { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly, tabHasN
13
13
  } : options ?? {};
14
14
  const { i18n, keepPresentationalFields, labelPrefix, moveSubFieldsToTop = false, pathPrefix } = normalizedOptions;
15
15
  return fields.reduce((acc, field)=>{
16
- if (field.type === 'group' && 'fields' in field) {
17
- if (moveSubFieldsToTop) {
18
- const isNamedGroup = 'name' in field && typeof field.name === 'string' && !!field.name;
19
- const groupName = 'name' in field ? field.name : undefined;
20
- const translatedLabel = 'label' in field && field.label && i18n ? getTranslation(field.label, i18n) : undefined;
21
- const labelWithPrefix = labelPrefix ? `${labelPrefix} > ${translatedLabel ?? groupName}` : translatedLabel ?? groupName;
22
- const nameWithPrefix = 'name' in field && field.name ? pathPrefix ? `${pathPrefix}-${field.name}` : field.name : pathPrefix;
23
- acc.push(// Need to include the top-level group field when hoisting its subfields,
24
- // so that `buildColumnState` can detect and render a column if the group
25
- // has a custom admin Cell component defined in its configuration.
26
- // See: packages/ui/src/providers/TableColumns/buildColumnState/index.tsx
27
- field, ...flattenFields(field.fields, {
28
- i18n,
29
- keepPresentationalFields,
30
- labelPrefix: isNamedGroup ? labelWithPrefix : labelPrefix,
31
- moveSubFieldsToTop,
32
- pathPrefix: isNamedGroup ? nameWithPrefix : pathPrefix
33
- }));
16
+ if (fieldHasSubFields(field)) {
17
+ if (field.type === 'group') {
18
+ if (moveSubFieldsToTop && 'fields' in field) {
19
+ const isNamedGroup = 'name' in field && typeof field.name === 'string' && !!field.name;
20
+ const translatedLabel = 'label' in field && field.label && i18n ? getTranslation(field.label, i18n) : undefined;
21
+ const labelWithPrefix = isNamedGroup && labelPrefix && translatedLabel ? `${labelPrefix} > ${translatedLabel}` : labelPrefix ?? translatedLabel;
22
+ const nameWithPrefix = isNamedGroup && field.name ? pathPrefix ? `${pathPrefix}-${field.name}` : field.name : pathPrefix;
23
+ acc.push(...flattenFields(field.fields, {
24
+ i18n,
25
+ keepPresentationalFields,
26
+ labelPrefix: isNamedGroup ? labelWithPrefix : labelPrefix,
27
+ moveSubFieldsToTop,
28
+ pathPrefix: isNamedGroup ? nameWithPrefix : pathPrefix
29
+ }));
30
+ } else {
31
+ // Just keep the group as-is
32
+ acc.push(field);
33
+ }
34
+ } else if ([
35
+ 'collapsible',
36
+ 'row'
37
+ ].includes(field.type)) {
38
+ // Recurse into row and collapsible
39
+ acc.push(...flattenFields(field.fields, options));
34
40
  } else {
35
- // Hoisting diabled - keep as top level field
41
+ // Do not hoist fields from arrays & blocks
36
42
  acc.push(field);
37
43
  }
38
- } else if (field.type === 'tabs' && 'tabs' in field) {
39
- return [
40
- ...acc,
41
- ...field.tabs.reduce((tabFields, tab)=>{
42
- if (tabHasName(tab)) {
43
- if (moveSubFieldsToTop) {
44
- const translatedLabel = 'label' in tab && tab.label && i18n ? getTranslation(tab.label, i18n) : undefined;
45
- const labelWithPrefixForTab = labelPrefix ? `${labelPrefix} > ${translatedLabel ?? tab.name}` : translatedLabel ?? tab.name;
46
- const pathPrefixForTab = tab.name ? pathPrefix ? `${pathPrefix}-${tab.name}` : tab.name : pathPrefix;
47
- return [
48
- ...tabFields,
49
- ...flattenFields(tab.fields, {
50
- i18n,
51
- keepPresentationalFields,
52
- labelPrefix: labelWithPrefixForTab,
53
- moveSubFieldsToTop,
54
- pathPrefix: pathPrefixForTab
55
- })
56
- ];
57
- } else {
58
- // Named tab, hoisting disabled: keep as top-level field
59
- return [
60
- ...tabFields,
61
- {
62
- ...tab,
63
- type: 'tab'
64
- }
65
- ];
66
- }
67
- } else {
68
- // Unnamed tab: always hoist its fields
69
- return [
70
- ...tabFields,
71
- ...flattenFields(tab.fields, options)
72
- ];
73
- }
74
- }, [])
75
- ];
76
- } else if (fieldHasSubFields(field) && [
77
- 'collapsible',
78
- 'row'
79
- ].includes(field.type)) {
80
- // Recurse into row and collapsible
81
- acc.push(...flattenFields(field.fields, options));
82
44
  } else if (fieldAffectsData(field) || keepPresentationalFields && fieldIsPresentationalOnly(field)) {
83
45
  // Ignore nested `id` fields when inside nested structure
84
46
  if (field.name === 'id' && labelPrefix !== undefined) {
@@ -91,9 +53,32 @@ import { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly, tabHasN
91
53
  ...field,
92
54
  ...moveSubFieldsToTop && isHoistingFromGroup && {
93
55
  accessor: pathPrefix && name ? `${pathPrefix}-${name}` : name ?? '',
94
- labelWithPrefix: labelPrefix ? `${labelPrefix} > ${translatedLabel ?? name}` : translatedLabel ?? name
56
+ labelWithPrefix: labelPrefix && translatedLabel ? `${labelPrefix} > ${translatedLabel}` : labelPrefix ?? translatedLabel
95
57
  }
96
58
  });
59
+ } else if (field.type === 'tabs' && 'tabs' in field) {
60
+ return [
61
+ ...acc,
62
+ ...field.tabs.reduce((tabFields, tab)=>{
63
+ if (tabHasName(tab)) {
64
+ return [
65
+ ...tabFields,
66
+ {
67
+ ...tab,
68
+ type: 'tab',
69
+ ...moveSubFieldsToTop && {
70
+ labelPrefix
71
+ }
72
+ }
73
+ ];
74
+ } else {
75
+ return [
76
+ ...tabFields,
77
+ ...flattenFields(tab.fields, options)
78
+ ];
79
+ }
80
+ }, [])
81
+ ];
97
82
  }
98
83
  return acc;
99
84
  }, []);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/flattenTopLevelFields.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { ClientTab } from '../admin/fields/Tabs.js'\nimport type { ClientField } from '../fields/config/client.js'\nimport type {\n Field,\n FieldAffectingData,\n FieldAffectingDataClient,\n FieldPresentationalOnly,\n FieldPresentationalOnlyClient,\n Tab,\n} from '../fields/config/types.js'\n\nimport {\n fieldAffectsData,\n fieldHasSubFields,\n fieldIsPresentationalOnly,\n tabHasName,\n} from '../fields/config/types.js'\n\ntype FlattenedField<TField> = TField extends ClientField\n ? { accessor?: string; labelWithPrefix?: string } & (\n | FieldAffectingDataClient\n | FieldPresentationalOnlyClient\n )\n : { accessor?: string; labelWithPrefix?: string } & (FieldAffectingData | FieldPresentationalOnly)\n\ntype TabType<TField> = TField extends ClientField ? ClientTab : Tab\n\n/**\n * Options to control how fields are flattened.\n */\ntype FlattenFieldsOptions = {\n /**\n * i18n context used for translating `label` values via `getTranslation`.\n */\n i18n?: I18nClient\n /**\n * If true, presentational-only fields (like UI fields) will be included\n * in the output. Otherwise, they will be skipped.\n * Default: false.\n */\n keepPresentationalFields?: boolean\n /**\n * A label prefix to prepend to translated labels when building `labelWithPrefix`.\n * Used recursively when flattening nested fields.\n */\n labelPrefix?: string\n /**\n * If true, nested fields inside `group` & `tabs` fields will be lifted to the top level\n * and given contextual `accessor` and `labelWithPrefix` values.\n * Default: false.\n */\n moveSubFieldsToTop?: boolean\n /**\n * A path prefix to prepend to field names when building the `accessor`.\n * Used recursively when flattening nested fields.\n */\n pathPrefix?: string\n}\n\n/**\n * Flattens a collection's fields into a single array of fields, optionally\n * extracting nested fields in group fields.\n *\n * @param fields - Array of fields to flatten\n * @param options - Options to control the flattening behavior\n */\nfunction flattenFields<TField extends ClientField | Field>(\n fields: TField[],\n options?: boolean | FlattenFieldsOptions,\n): FlattenedField<TField>[] {\n const normalizedOptions: FlattenFieldsOptions =\n typeof options === 'boolean' ? { keepPresentationalFields: options } : (options ?? {})\n\n const {\n i18n,\n keepPresentationalFields,\n labelPrefix,\n moveSubFieldsToTop = false,\n pathPrefix,\n } = normalizedOptions\n\n return fields.reduce<FlattenedField<TField>[]>((acc, field) => {\n if (field.type === 'group' && 'fields' in field) {\n if (moveSubFieldsToTop) {\n const isNamedGroup = 'name' in field && typeof field.name === 'string' && !!field.name\n const groupName = 'name' in field ? field.name : undefined\n\n const translatedLabel =\n 'label' in field && field.label && i18n\n ? getTranslation(field.label as string, i18n)\n : undefined\n\n const labelWithPrefix = labelPrefix\n ? `${labelPrefix} > ${translatedLabel ?? groupName}`\n : (translatedLabel ?? groupName)\n\n const nameWithPrefix =\n 'name' in field && field.name\n ? pathPrefix\n ? `${pathPrefix}-${field.name}`\n : field.name\n : pathPrefix\n\n acc.push(\n // Need to include the top-level group field when hoisting its subfields,\n // so that `buildColumnState` can detect and render a column if the group\n // has a custom admin Cell component defined in its configuration.\n // See: packages/ui/src/providers/TableColumns/buildColumnState/index.tsx\n field as FlattenedField<TField>,\n ...flattenFields(field.fields as TField[], {\n i18n,\n keepPresentationalFields,\n labelPrefix: isNamedGroup ? labelWithPrefix : labelPrefix,\n moveSubFieldsToTop,\n pathPrefix: isNamedGroup ? nameWithPrefix : pathPrefix,\n }),\n )\n } else {\n // Hoisting diabled - keep as top level field\n acc.push(field as FlattenedField<TField>)\n }\n } else if (field.type === 'tabs' && 'tabs' in field) {\n return [\n ...acc,\n ...field.tabs.reduce<FlattenedField<TField>[]>((tabFields, tab: TabType<TField>) => {\n if (tabHasName(tab)) {\n if (moveSubFieldsToTop) {\n const translatedLabel =\n 'label' in tab && tab.label && i18n ? getTranslation(tab.label, i18n) : undefined\n\n const labelWithPrefixForTab = labelPrefix\n ? `${labelPrefix} > ${translatedLabel ?? tab.name}`\n : (translatedLabel ?? tab.name)\n\n const pathPrefixForTab = tab.name\n ? pathPrefix\n ? `${pathPrefix}-${tab.name}`\n : tab.name\n : pathPrefix\n\n return [\n ...tabFields,\n ...flattenFields(tab.fields as TField[], {\n i18n,\n keepPresentationalFields,\n labelPrefix: labelWithPrefixForTab,\n moveSubFieldsToTop,\n pathPrefix: pathPrefixForTab,\n }),\n ]\n } else {\n // Named tab, hoisting disabled: keep as top-level field\n return [\n ...tabFields,\n {\n ...tab,\n type: 'tab',\n } as unknown as FlattenedField<TField>,\n ]\n }\n } else {\n // Unnamed tab: always hoist its fields\n return [...tabFields, ...flattenFields<TField>(tab.fields as TField[], options)]\n }\n }, []),\n ]\n } else if (fieldHasSubFields(field) && ['collapsible', 'row'].includes(field.type)) {\n // Recurse into row and collapsible\n acc.push(...flattenFields(field.fields as TField[], options))\n } else if (\n fieldAffectsData(field) ||\n (keepPresentationalFields && fieldIsPresentationalOnly(field))\n ) {\n // Ignore nested `id` fields when inside nested structure\n if (field.name === 'id' && labelPrefix !== undefined) {\n return acc\n }\n\n const translatedLabel =\n 'label' in field && field.label && i18n ? getTranslation(field.label, i18n) : undefined\n\n const name = 'name' in field ? field.name : undefined\n\n const isHoistingFromGroup = pathPrefix !== undefined || labelPrefix !== undefined\n\n acc.push({\n ...(field as FlattenedField<TField>),\n ...(moveSubFieldsToTop &&\n isHoistingFromGroup && {\n accessor: pathPrefix && name ? `${pathPrefix}-${name}` : (name ?? ''),\n labelWithPrefix: labelPrefix\n ? `${labelPrefix} > ${translatedLabel ?? name}`\n : (translatedLabel ?? name),\n }),\n })\n }\n\n return acc\n }, [])\n}\n\nexport default flattenFields\n"],"names":["getTranslation","fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","tabHasName","flattenFields","fields","options","normalizedOptions","keepPresentationalFields","i18n","labelPrefix","moveSubFieldsToTop","pathPrefix","reduce","acc","field","type","isNamedGroup","name","groupName","undefined","translatedLabel","label","labelWithPrefix","nameWithPrefix","push","tabs","tabFields","tab","labelWithPrefixForTab","pathPrefixForTab","includes","isHoistingFromGroup","accessor"],"mappings":"AAAA,oBAAoB;AAGpB,SAASA,cAAc,QAAQ,2BAA0B;AAazD,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,yBAAyB,EACzBC,UAAU,QACL,4BAA2B;AA2ClC;;;;;;CAMC,GACD,SAASC,cACPC,MAAgB,EAChBC,OAAwC;IAExC,MAAMC,oBACJ,OAAOD,YAAY,YAAY;QAAEE,0BAA0BF;IAAQ,IAAKA,WAAW,CAAC;IAEtF,MAAM,EACJG,IAAI,EACJD,wBAAwB,EACxBE,WAAW,EACXC,qB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;oBAClEK,iBAAiBb,cACb,GAAGA,YAAY,GAAG,EAAEW,mBAAmBH,MAAM,GAC5CG,mBAAmBH;gBAC1B,CAAC;YACL;QACF;QAEA,OAAOJ;IACT,GAAG,EAAE;AACP;AAEA,eAAeV,cAAa"}
1
+ {"version":3,"sources":["../../src/utilities/flattenTopLevelFields.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { ClientTab } from '../admin/fields/Tabs.js'\nimport type { ClientField } from '../fields/config/client.js'\nimport type {\n Field,\n FieldAffectingData,\n FieldAffectingDataClient,\n FieldPresentationalOnly,\n FieldPresentationalOnlyClient,\n Tab,\n} from '../fields/config/types.js'\n\nimport {\n fieldAffectsData,\n fieldHasSubFields,\n fieldIsPresentationalOnly,\n tabHasName,\n} from '../fields/config/types.js'\n\ntype FlattenedField<TField> = TField extends ClientField\n ? { accessor?: string; labelWithPrefix?: string } & (\n | FieldAffectingDataClient\n | FieldPresentationalOnlyClient\n )\n : { accessor?: string; labelWithPrefix?: string } & (FieldAffectingData | FieldPresentationalOnly)\n\ntype TabType<TField> = TField extends ClientField ? ClientTab : Tab\n\n/**\n * Options to control how fields are flattened.\n */\ntype FlattenFieldsOptions = {\n /**\n * i18n context used for translating `label` values via `getTranslation`.\n */\n i18n?: I18nClient\n /**\n * If true, presentational-only fields (like UI fields) will be included\n * in the output. Otherwise, they will be skipped.\n * Default: false.\n */\n keepPresentationalFields?: boolean\n /**\n * A label prefix to prepend to translated labels when building `labelWithPrefix`.\n * Used recursively when flattening nested fields.\n */\n labelPrefix?: string\n /**\n * If true, nested fields inside `group` fields will be lifted to the top level\n * and given contextual `accessor` and `labelWithPrefix` values.\n * Default: false.\n */\n moveSubFieldsToTop?: boolean\n /**\n * A path prefix to prepend to field names when building the `accessor`.\n * Used recursively when flattening nested fields.\n */\n pathPrefix?: string\n}\n\n/**\n * Flattens a collection's fields into a single array of fields, optionally\n * extracting nested fields in group fields.\n *\n * @param fields - Array of fields to flatten\n * @param options - Options to control the flattening behavior\n */\nfunction flattenFields<TField extends ClientField | Field>(\n fields: TField[],\n options?: boolean | FlattenFieldsOptions,\n): FlattenedField<TField>[] {\n const normalizedOptions: FlattenFieldsOptions =\n typeof options === 'boolean' ? { keepPresentationalFields: options } : (options ?? {})\n\n const {\n i18n,\n keepPresentationalFields,\n labelPrefix,\n moveSubFieldsToTop = false,\n pathPrefix,\n } = normalizedOptions\n\n return fields.reduce<FlattenedField<TField>[]>((acc, field) => {\n if (fieldHasSubFields(field)) {\n if (field.type === 'group') {\n if (moveSubFieldsToTop && 'fields' in field) {\n const isNamedGroup = 'name' in field && typeof field.name === 'string' && !!field.name\n\n const translatedLabel =\n 'label' in field && field.label && i18n\n ? getTranslation(field.label as string, i18n)\n : undefined\n\n const labelWithPrefix =\n isNamedGroup && labelPrefix && translatedLabel\n ? `${labelPrefix} > ${translatedLabel}`\n : (labelPrefix ?? translatedLabel)\n\n const nameWithPrefix =\n isNamedGroup && field.name\n ? pathPrefix\n ? `${pathPrefix}-${field.name as string}`\n : (field.name as string)\n : pathPrefix\n\n acc.push(\n ...flattenFields(field.fields as TField[], {\n i18n,\n keepPresentationalFields,\n labelPrefix: isNamedGroup ? labelWithPrefix : labelPrefix,\n moveSubFieldsToTop,\n pathPrefix: isNamedGroup ? nameWithPrefix : pathPrefix,\n }),\n )\n } else {\n // Just keep the group as-is\n acc.push(field as FlattenedField<TField>)\n }\n } else if (['collapsible', 'row'].includes(field.type)) {\n // Recurse into row and collapsible\n acc.push(...flattenFields(field.fields as TField[], options))\n } else {\n // Do not hoist fields from arrays & blocks\n acc.push(field as FlattenedField<TField>)\n }\n } else if (\n fieldAffectsData(field) ||\n (keepPresentationalFields && fieldIsPresentationalOnly(field))\n ) {\n // Ignore nested `id` fields when inside nested structure\n if (field.name === 'id' && labelPrefix !== undefined) {\n return acc\n }\n\n const translatedLabel =\n 'label' in field && field.label && i18n ? getTranslation(field.label, i18n) : undefined\n\n const name = 'name' in field ? field.name : undefined\n\n const isHoistingFromGroup = pathPrefix !== undefined || labelPrefix !== undefined\n\n acc.push({\n ...(field as FlattenedField<TField>),\n ...(moveSubFieldsToTop &&\n isHoistingFromGroup && {\n accessor: pathPrefix && name ? `${pathPrefix}-${name}` : (name ?? ''),\n labelWithPrefix:\n labelPrefix && translatedLabel\n ? `${labelPrefix} > ${translatedLabel}`\n : (labelPrefix ?? translatedLabel),\n }),\n })\n } else if (field.type === 'tabs' && 'tabs' in field) {\n return [\n ...acc,\n ...field.tabs.reduce<FlattenedField<TField>[]>((tabFields, tab: TabType<TField>) => {\n if (tabHasName(tab)) {\n return [\n ...tabFields,\n {\n ...tab,\n type: 'tab',\n ...(moveSubFieldsToTop && { labelPrefix }),\n } as unknown as FlattenedField<TField>,\n ]\n } else {\n return [...tabFields, ...flattenFields<TField>(tab.fields as TField[], options)]\n }\n }, []),\n ]\n }\n\n return acc\n }, [])\n}\n\nexport default flattenFields\n"],"names":["getTranslation","fieldAffectsData","fieldHasSubFields","fieldIsPresentationalOnly","tabHasName","flattenFields","fields","options","normalizedOptions","keepPresentationalFields","i18n","labelPrefix","moveSubFieldsToTop","pathPrefix","reduce","acc","field","type","isNamedGroup","name","translatedLabel","label","undefined","labelWithPrefix","nameWithPrefix","push","includes","isHoistingFromGroup","accessor","tabs","tabFields","tab"],"mappings":"AAAA,oBAAoB;AAGpB,SAASA,cAAc,QAAQ,2BAA0B;AAazD,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,yBAAyB,EACzBC,UAAU,QACL,4BAA2B;AA2ClC;;;;;;CAMC,GACD,SAASC,cACPC,MAAgB,EAChBC,OAAwC;IAExC,MAAMC,oBACJ,OAAOD,YAAY,YAAY;QAAEE,0BAA0BF;IAAQ,IAAKA,WAAW,CAAC;IAEtF,MAAM,EACJG,IAAI,EACJD,wBAAwB,EACxBE,WAAW,EACXC,qBAAqB,KAAK,EAC1BC,UAAU,EACX,GAAGL;IAEJ,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