@payloadcms/plugin-import-export 3.47.0-internal.b17506e → 3.47.0
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/components/ExportSaveButton/index.d.ts.map +1 -1
- package/dist/components/ExportSaveButton/index.js +21 -2
- package/dist/components/ExportSaveButton/index.js.map +1 -1
- package/dist/components/FieldsToExport/index.d.ts.map +1 -1
- package/dist/components/FieldsToExport/index.js +28 -41
- package/dist/components/FieldsToExport/index.js.map +1 -1
- package/dist/components/SelectionToUseField/index.d.ts +3 -0
- package/dist/components/SelectionToUseField/index.d.ts.map +1 -0
- package/dist/components/SelectionToUseField/index.js +128 -0
- package/dist/components/SelectionToUseField/index.js.map +1 -0
- package/dist/components/SortBy/index.js +3 -2
- package/dist/components/SortBy/index.js.map +1 -1
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +1 -2
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/flattenObject.d.ts.map +1 -1
- package/dist/export/flattenObject.js +48 -30
- package/dist/export/flattenObject.js.map +1 -1
- package/dist/export/getCustomFieldFunctions.d.ts +2 -3
- package/dist/export/getCustomFieldFunctions.d.ts.map +1 -1
- package/dist/export/getCustomFieldFunctions.js +3 -5
- package/dist/export/getCustomFieldFunctions.js.map +1 -1
- package/dist/export/getFields.d.ts.map +1 -1
- package/dist/export/getFields.js +15 -10
- package/dist/export/getFields.js.map +1 -1
- package/dist/exports/rsc.d.ts +1 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +1 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.d.ts.map +1 -1
- package/dist/utilities/getFlattenedFieldKeys.js +16 -5
- package/dist/utilities/getFlattenedFieldKeys.js.map +1 -1
- package/package.json +7 -7
- package/dist/components/WhereField/index.d.ts +0 -4
- package/dist/components/WhereField/index.d.ts.map +0 -1
- package/dist/components/WhereField/index.js +0 -72
- package/dist/components/WhereField/index.js.map +0 -1
- package/dist/components/WhereField/index.scss +0 -0
|
@@ -6,20 +6,30 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
6
6
|
if (Array.isArray(value)) {
|
|
7
7
|
value.forEach((item, index)=>{
|
|
8
8
|
if (typeof item === 'object' && item !== null) {
|
|
9
|
+
// Case: hasMany polymorphic relationships
|
|
10
|
+
if ('relationTo' in item && 'value' in item && typeof item.value === 'object' && item.value !== null) {
|
|
11
|
+
row[`${`${newKey}_${index}`}_relationTo`] = item.relationTo;
|
|
12
|
+
row[`${`${newKey}_${index}`}_id`] = item.value.id;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
9
15
|
flatten(item, `${newKey}_${index}`);
|
|
10
16
|
} else {
|
|
11
17
|
if (toCSVFunctions?.[newKey]) {
|
|
12
18
|
const columnName = `${newKey}_${index}`;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
try {
|
|
20
|
+
const result = toCSVFunctions[newKey]({
|
|
21
|
+
columnName,
|
|
22
|
+
data: row,
|
|
23
|
+
doc,
|
|
24
|
+
row,
|
|
25
|
+
siblingDoc,
|
|
26
|
+
value: item
|
|
27
|
+
});
|
|
28
|
+
if (typeof result !== 'undefined') {
|
|
29
|
+
row[columnName] = result;
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new Error(`Error in toCSVFunction for array item "${columnName}": ${JSON.stringify(item)}\n${error.message}`);
|
|
23
33
|
}
|
|
24
34
|
} else {
|
|
25
35
|
row[`${newKey}_${index}`] = item;
|
|
@@ -30,30 +40,38 @@ export const flattenObject = ({ doc, fields, prefix, toCSVFunctions })=>{
|
|
|
30
40
|
if (!toCSVFunctions?.[newKey]) {
|
|
31
41
|
flatten(value, newKey);
|
|
32
42
|
} else {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
try {
|
|
44
|
+
const result = toCSVFunctions[newKey]({
|
|
45
|
+
columnName: newKey,
|
|
46
|
+
data: row,
|
|
47
|
+
doc,
|
|
48
|
+
row,
|
|
49
|
+
siblingDoc,
|
|
50
|
+
value
|
|
51
|
+
});
|
|
52
|
+
if (typeof result !== 'undefined') {
|
|
53
|
+
row[newKey] = result;
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error(`Error in toCSVFunction for nested object "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
59
|
} else {
|
|
46
60
|
if (toCSVFunctions?.[newKey]) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
try {
|
|
62
|
+
const result = toCSVFunctions[newKey]({
|
|
63
|
+
columnName: newKey,
|
|
64
|
+
data: row,
|
|
65
|
+
doc,
|
|
66
|
+
row,
|
|
67
|
+
siblingDoc,
|
|
68
|
+
value
|
|
69
|
+
});
|
|
70
|
+
if (typeof result !== 'undefined') {
|
|
71
|
+
row[newKey] = result;
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error(`Error in toCSVFunction for field "${newKey}": ${JSON.stringify(value)}\n${error.message}`);
|
|
57
75
|
}
|
|
58
76
|
} else {
|
|
59
77
|
row[newKey] = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n const result = toCSVFunctions[newKey]({\n
|
|
1
|
+
{"version":3,"sources":["../../src/export/flattenObject.ts"],"sourcesContent":["import type { Document } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n doc: Document\n fields?: string[]\n prefix?: string\n toCSVFunctions: Record<string, ToCSVFunction>\n}\n\nexport const flattenObject = ({\n doc,\n fields,\n prefix,\n toCSVFunctions,\n}: Args): Record<string, unknown> => {\n const row: Record<string, unknown> = {}\n\n const flatten = (siblingDoc: Document, prefix?: string) => {\n Object.entries(siblingDoc).forEach(([key, value]) => {\n const newKey = prefix ? `${prefix}_${key}` : key\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (typeof item === 'object' && item !== null) {\n // Case: hasMany polymorphic relationships\n if (\n 'relationTo' in item &&\n 'value' in item &&\n typeof item.value === 'object' &&\n item.value !== null\n ) {\n row[`${`${newKey}_${index}`}_relationTo`] = item.relationTo\n row[`${`${newKey}_${index}`}_id`] = item.value.id\n return\n }\n\n flatten(item, `${newKey}_${index}`)\n } else {\n if (toCSVFunctions?.[newKey]) {\n const columnName = `${newKey}_${index}`\n try {\n const result = toCSVFunctions[newKey]({\n columnName,\n data: row,\n doc,\n row,\n siblingDoc,\n value: item,\n })\n if (typeof result !== 'undefined') {\n row[columnName] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for array item \"${columnName}\": ${JSON.stringify(item)}\\n${(error as Error).message}`,\n )\n }\n } else {\n row[`${newKey}_${index}`] = item\n }\n }\n })\n } else if (typeof value === 'object' && value !== null) {\n if (!toCSVFunctions?.[newKey]) {\n flatten(value, newKey)\n } else {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for nested object \"${newKey}\": ${JSON.stringify(value)}\\n${(error as Error).message}`,\n )\n }\n }\n } else {\n if (toCSVFunctions?.[newKey]) {\n try {\n const result = toCSVFunctions[newKey]({\n columnName: newKey,\n data: row,\n doc,\n row,\n siblingDoc,\n value,\n })\n if (typeof result !== 'undefined') {\n row[newKey] = result\n }\n } catch (error) {\n throw new Error(\n `Error in toCSVFunction for field \"${newKey}\": ${JSON.stringify(value)}\\n${(error as Error).message}`,\n )\n }\n } else {\n row[newKey] = value\n }\n }\n })\n }\n\n flatten(doc, prefix)\n\n if (Array.isArray(fields) && fields.length > 0) {\n const orderedResult: Record<string, unknown> = {}\n\n const fieldToRegex = (field: string): RegExp => {\n const parts = field.split('.').map((part) => `${part}(?:_\\\\d+)?`)\n const pattern = `^${parts.join('_')}`\n return new RegExp(pattern)\n }\n\n fields.forEach((field) => {\n if (row[field.replace(/\\./g, '_')]) {\n const sanitizedField = field.replace(/\\./g, '_')\n orderedResult[sanitizedField] = row[sanitizedField]\n } else {\n const regex = fieldToRegex(field)\n Object.keys(row).forEach((key) => {\n if (regex.test(key)) {\n orderedResult[key] = row[key]\n }\n })\n }\n })\n\n return orderedResult\n }\n\n return row\n}\n"],"names":["flattenObject","doc","fields","prefix","toCSVFunctions","row","flatten","siblingDoc","Object","entries","forEach","key","value","newKey","Array","isArray","item","index","relationTo","id","columnName","result","data","error","Error","JSON","stringify","message","length","orderedResult","fieldToRegex","field","parts","split","map","part","pattern","join","RegExp","replace","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A,OAAO0B,MAAM,GAAG,GAAG;QAC9C,MAAMC,gBAAyC,CAAC;QAEhD,MAAMC,eAAe,CAACC;YACpB,MAAMC,QAAQD,MAAME,KAAK,CAAC,KAAKC,GAAG,CAAC,CAACC,OAAS,GAAGA,KAAK,UAAU,CAAC;YAChE,MAAMC,UAAU,CAAC,CAAC,EAAEJ,MAAMK,IAAI,CAAC,MAAM;YACrC,OAAO,IAAIC,OAAOF;QACpB;QAEAlC,OAAOQ,OAAO,CAAC,CAACqB;YACd,IAAI1B,GAAG,CAAC0B,MAAMQ,OAAO,CAAC,OAAO,KAAK,EAAE;gBAClC,MAAMC,iBAAiBT,MAAMQ,OAAO,CAAC,OAAO;gBAC5CV,aAAa,CAACW,eAAe,GAAGnC,GAAG,CAACmC,eAAe;YACrD,OAAO;gBACL,MAAMC,QAAQX,aAAaC;gBAC3BvB,OAAOkC,IAAI,CAACrC,KAAKK,OAAO,CAAC,CAACC;oBACxB,IAAI8B,MAAME,IAAI,CAAChC,MAAM;wBACnBkB,aAAa,CAAClB,IAAI,GAAGN,GAAG,CAACM,IAAI;oBAC/B;gBACF;YACF;QACF;QAEA,OAAOkB;IACT;IAEA,OAAOxB;AACT,EAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type FlattenedField
|
|
1
|
+
import { type FlattenedField } from 'payload';
|
|
2
2
|
import type { ToCSVFunction } from '../types.js';
|
|
3
3
|
type Args = {
|
|
4
4
|
fields: FlattenedField[];
|
|
5
|
-
select: SelectIncludeType | undefined;
|
|
6
5
|
};
|
|
7
|
-
export declare const getCustomFieldFunctions: ({ fields
|
|
6
|
+
export declare const getCustomFieldFunctions: ({ fields }: Args) => Record<string, ToCSVFunction>;
|
|
8
7
|
export {};
|
|
9
8
|
//# sourceMappingURL=getCustomFieldFunctions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getCustomFieldFunctions.d.ts","sourceRoot":"","sources":["../../src/export/getCustomFieldFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+C,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,eAAgB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAwFtF,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { traverseFields } from 'payload';
|
|
2
|
-
export const getCustomFieldFunctions = ({ fields
|
|
2
|
+
export const getCustomFieldFunctions = ({ fields })=>{
|
|
3
3
|
const result = {};
|
|
4
4
|
const buildCustomFunctions = ({ field, parentRef, ref })=>{
|
|
5
5
|
// @ts-expect-error ref is untyped
|
|
@@ -33,7 +33,8 @@ export const getCustomFieldFunctions = ({ fields, select })=>{
|
|
|
33
33
|
data[`${ref.prefix}${field.name}_relationTo`] = relationTo;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return undefined
|
|
36
|
+
return undefined // prevents further flattening
|
|
37
|
+
;
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
} else {
|
|
@@ -64,9 +65,6 @@ export const getCustomFieldFunctions = ({ fields, select })=>{
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
// TODO: do this so we only return the functions needed based on the select used
|
|
68
|
-
////@ts-expect-error ref is untyped
|
|
69
|
-
// ref.select = typeof select !== 'undefined' || select[field.name] ? select : {}
|
|
70
68
|
};
|
|
71
69
|
traverseFields({
|
|
72
70
|
callback: buildCustomFunctions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/export/getCustomFieldFunctions.ts"],"sourcesContent":["import { type FlattenedField, traverseFields, type TraverseFieldsCallback } from 'payload'\n\nimport type { ToCSVFunction } from '../types.js'\n\ntype Args = {\n fields: FlattenedField[]\n}\n\nexport const getCustomFieldFunctions = ({ fields }: Args): Record<string, ToCSVFunction> => {\n const result: Record<string, ToCSVFunction> = {}\n\n const buildCustomFunctions: TraverseFieldsCallback = ({ field, parentRef, ref }) => {\n // @ts-expect-error ref is untyped\n ref.prefix = parentRef.prefix || ''\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}_`\n }\n\n if (typeof field.custom?.['plugin-import-export']?.toCSV === 'function') {\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = field.custom['plugin-import-export']?.toCSV\n } else if (field.type === 'relationship' || field.type === 'upload') {\n if (field.hasMany !== true) {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ value }) =>\n typeof value === 'object' && value && 'id' in value ? value.id : value\n } else {\n // polymorphic single\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({ data, value }) => {\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n const relationTo = (value as { relationTo: string; value: { id: number | string } })\n .relationTo\n const relatedDoc = (value as { relationTo: string; value: { id: number | string } })\n .value\n if (relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_relationTo`] = relationTo\n }\n }\n return undefined // prevents further flattening\n }\n }\n } else {\n if (!Array.isArray(field.relationTo)) {\n // monomorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n value,\n }: {\n value: Record<string, unknown>[]\n }) =>\n value.map((val: number | Record<string, unknown> | string) =>\n typeof val === 'object' ? val.id : val,\n )\n } else {\n // polymorphic many\n // @ts-expect-error ref is untyped\n result[`${ref.prefix}${field.name}`] = ({\n data,\n value,\n }: {\n data: Record<string, unknown>\n value: Array<Record<string, any>> | undefined\n }) => {\n if (Array.isArray(value)) {\n value.forEach((val, i) => {\n if (val && typeof val === 'object') {\n const relationTo = val.relationTo\n const relatedDoc = val.value\n if (relationTo && relatedDoc && typeof relatedDoc === 'object') {\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_id`] = relatedDoc.id\n // @ts-expect-error ref is untyped\n data[`${ref.prefix}${field.name}_${i}_relationTo`] = relationTo\n }\n }\n })\n }\n return undefined\n }\n }\n }\n }\n }\n\n traverseFields({ callback: buildCustomFunctions, fields })\n\n return result\n}\n"],"names":["traverseFields","getCustomFieldFunctions","fields","result","buildCustomFunctions","field","parentRef","ref","prefix","type","parentPrefix","name","custom","toCSV","hasMany","Array","isArray","relationTo","value","id","data","relatedDoc","undefined","map","val","forEach","i","callback"],"mappings":"AAAA,SAA8BA,cAAc,QAAqC,UAAS;AAQ1F,OAAO,MAAMC,0BAA0B,CAAC,EAAEC,MAAM,EAAQ;IACtD,MAAMC,SAAwC,CAAC;IAE/C,MAAMC,uBAA+C,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC7E,kCAAkC;QAClCA,IAAIC,MAAM,GAAGF,UAAUE,MAAM,IAAI;QACjC,IAAIH,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,OAAO;YAClD,kCAAkC;YAClC,MAAMC,eAAeJ,WAAWE,SAAS,GAAGF,UAAUE,MAAM,CAAC,CAAC,CAAC,GAAG;YAClE,kCAAkC;YAClCD,IAAIC,MAAM,GAAG,GAAGE,eAAeL,MAAMM,IAAI,CAAC,CAAC,CAAC;QAC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,CAAA;AAIzD,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../src/export/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAe,MAAM,SAAS,CAAA;AAIzD,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,KAAK,EA+M/C,CAAA"}
|
package/dist/export/getFields.js
CHANGED
|
@@ -114,12 +114,13 @@ export const getFields = (config)=>{
|
|
|
114
114
|
]
|
|
115
115
|
},
|
|
116
116
|
{
|
|
117
|
-
// virtual field for the UI component to modify the hidden `where` field
|
|
118
117
|
name: 'selectionToUse',
|
|
119
118
|
type: 'radio',
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
admin: {
|
|
120
|
+
components: {
|
|
121
|
+
Field: '@payloadcms/plugin-import-export/rsc#SelectionToUseField'
|
|
122
|
+
}
|
|
123
|
+
},
|
|
123
124
|
options: [
|
|
124
125
|
{
|
|
125
126
|
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
@@ -136,8 +137,7 @@ export const getFields = (config)=>{
|
|
|
136
137
|
label: ({ t })=>t('plugin-import-export:selectionToUse-allDocuments'),
|
|
137
138
|
value: 'all'
|
|
138
139
|
}
|
|
139
|
-
]
|
|
140
|
-
virtual: true
|
|
140
|
+
]
|
|
141
141
|
},
|
|
142
142
|
{
|
|
143
143
|
name: 'fields',
|
|
@@ -166,11 +166,16 @@ export const getFields = (config)=>{
|
|
|
166
166
|
name: 'where',
|
|
167
167
|
type: 'json',
|
|
168
168
|
admin: {
|
|
169
|
-
|
|
170
|
-
Field: '@payloadcms/plugin-import-export/rsc#WhereField'
|
|
171
|
-
}
|
|
169
|
+
hidden: true
|
|
172
170
|
},
|
|
173
|
-
defaultValue: {}
|
|
171
|
+
defaultValue: {},
|
|
172
|
+
hooks: {
|
|
173
|
+
beforeValidate: [
|
|
174
|
+
({ value })=>{
|
|
175
|
+
return value ?? {};
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
}
|
|
174
179
|
}
|
|
175
180
|
],
|
|
176
181
|
// @ts-expect-error - this is not correctly typed in plugins right now
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/export/getFields.ts"],"sourcesContent":["import type { Config, Field, SelectField } from 'payload'\n\nimport { getFilename } from './getFilename.js'\n\nexport const getFields = (config: Config): Field[] => {\n let localeField: SelectField | undefined\n if (config.localization) {\n localeField = {\n name: 'locale',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-locale-label'),\n options: [\n {\n label: ({ t }) => t('general:allLocales'),\n value: 'all',\n },\n ...config.localization.locales.map((locale) => ({\n label: typeof locale === 'string' ? locale : locale.label,\n value: typeof locale === 'string' ? locale : locale.code,\n })),\n ],\n }\n }\n\n return [\n {\n type: 'collapsible',\n fields: [\n {\n name: 'name',\n type: 'text',\n defaultValue: () => getFilename(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-name-label'),\n },\n {\n type: 'row',\n fields: [\n {\n name: 'format',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'csv',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-format-label'),\n options: [\n {\n label: 'CSV',\n value: 'csv',\n },\n {\n label: 'JSON',\n value: 'json',\n },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n placeholder: 'No limit',\n width: '33%',\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-limit-label'),\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SortBy',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-sort-label'),\n },\n ],\n },\n {\n type: 'row',\n fields: [\n ...(localeField ? [localeField] : []),\n {\n name: 'drafts',\n type: 'select',\n admin: {\n condition: (data) => {\n const collectionConfig = (config.collections ?? []).find(\n (collection) => collection.slug === data.collectionSlug,\n )\n return Boolean(\n typeof collectionConfig?.versions === 'object' &&\n collectionConfig?.versions?.drafts,\n )\n },\n width: '33%',\n },\n defaultValue: 'yes',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-drafts-label'),\n options: [\n {\n label: ({ t }) => t('general:yes'),\n value: 'yes',\n },\n {\n label: ({ t }) => t('general:no'),\n value: 'no',\n },\n ],\n },\n // {\n // name: 'depth',\n // type: 'number',\n // // @ts-expect-error - this is not correctly typed in plugins right now\n // label: ({ t }) => t('plugin-import-export:field-depth-label'),\n // admin: {\n // width: '33%',\n // },\n // defaultValue: 1,\n // required: true,\n // },\n ],\n },\n {\n // virtual field for the UI component to modify the hidden `where` field\n name: 'selectionToUse',\n type: 'radio',\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-selectionToUse-label'),\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ],\n virtual: true,\n },\n {\n name: 'fields',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport',\n },\n },\n hasMany: true,\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-fields-label'),\n },\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#CollectionField',\n },\n hidden: true,\n },\n required: true,\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#WhereField',\n },\n },\n defaultValue: {},\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:exportOptions'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#Preview',\n },\n },\n },\n ]\n}\n"],"names":["getFilename","getFields","config","localeField","localization","name","type","admin","width","defaultValue","label","t","options","value","locales","map","locale","code","fields","required","placeholder","components","Field","condition","data","collectionConfig","collections","find","collection","slug","collectionSlug","Boolean","versions","drafts","virtual","hasMany","hidden"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAY,CAACC;IACxB,IAAIC;IACJ,IAAID,OAAOE,YAAY,EAAE;QACvBD,cAAc;YACZE,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,OAAO;YACT;YACAC,cAAc;YACd,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBC,SAAS;gBACP;oBACEF,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;mBACGX,OAAOE,YAAY,CAACU,OAAO,CAACC,GAAG,CAAC,CAACC,SAAY,CAAA;wBAC9CN,OAAO,OAAOM,WAAW,WAAWA,SAASA,OAAON,KAAK;wBACzDG,OAAO,OAAOG,WAAW,WAAWA,SAASA,OAAOC,IAAI;oBAC1D,CAAA;aACD;QACH;IACF;IAEA,OAAO;QACL;YACEX,MAAM;YACNY,QAAQ;gBACN;oBACEb,MAAM;oBACNC,MAAM;oBACNG,cAAc,IAAMT;oBACpB,sEAAsE;oBACtEU,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;gBACtB;gBACA;oBACEL,MAAM;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BACH;qBAYD;gBACH;gBACA;oBACE,wEAAwE;oBACxER,MAAM;oBACNC,MAAM;oBACNG,cAAc;oBACd,sEAAsE;oBACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBC,SAAS;wBACP;4BACE,sEAAsE;4BACtEF,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;4BACpBE,OAAO;wBACT;wBACA;4BACE,sEAAsE;4BACtEH,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;4BACpBE,OAAO;wBACT;wBACA;4BACE,sEAAsE;4BACtEH,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;4BACpBE,OAAO;wBACT;qBACD;oBACDqB,SAAS;gBACX;gBACA;oBACE7B,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;oBACF;oBACAa,SAAS;oBACT,sEAAsE;oBACtEzB,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;gBACtB;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;wBACAc,QAAQ;oBACV;oBACAjB,UAAU;gBACZ;gBACA;oBACEd,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;oBACF;oBACAb,cAAc,CAAC;gBACjB;aACD;YACD,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;QACtB;QACA;YACEN,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLc,YAAY;oBACVC,OAAO;gBACT;YACF;QACF;KACD;AACH,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/export/getFields.ts"],"sourcesContent":["import type { Config, Field, SelectField } from 'payload'\n\nimport { getFilename } from './getFilename.js'\n\nexport const getFields = (config: Config): Field[] => {\n let localeField: SelectField | undefined\n if (config.localization) {\n localeField = {\n name: 'locale',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'all',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-locale-label'),\n options: [\n {\n label: ({ t }) => t('general:allLocales'),\n value: 'all',\n },\n ...config.localization.locales.map((locale) => ({\n label: typeof locale === 'string' ? locale : locale.label,\n value: typeof locale === 'string' ? locale : locale.code,\n })),\n ],\n }\n }\n\n return [\n {\n type: 'collapsible',\n fields: [\n {\n name: 'name',\n type: 'text',\n defaultValue: () => getFilename(),\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-name-label'),\n },\n {\n type: 'row',\n fields: [\n {\n name: 'format',\n type: 'select',\n admin: {\n width: '33%',\n },\n defaultValue: 'csv',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-format-label'),\n options: [\n {\n label: 'CSV',\n value: 'csv',\n },\n {\n label: 'JSON',\n value: 'json',\n },\n ],\n required: true,\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n placeholder: 'No limit',\n width: '33%',\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-limit-label'),\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SortBy',\n },\n },\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-sort-label'),\n },\n ],\n },\n {\n type: 'row',\n fields: [\n ...(localeField ? [localeField] : []),\n {\n name: 'drafts',\n type: 'select',\n admin: {\n condition: (data) => {\n const collectionConfig = (config.collections ?? []).find(\n (collection) => collection.slug === data.collectionSlug,\n )\n return Boolean(\n typeof collectionConfig?.versions === 'object' &&\n collectionConfig?.versions?.drafts,\n )\n },\n width: '33%',\n },\n defaultValue: 'yes',\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-drafts-label'),\n options: [\n {\n label: ({ t }) => t('general:yes'),\n value: 'yes',\n },\n {\n label: ({ t }) => t('general:no'),\n value: 'no',\n },\n ],\n },\n // {\n // name: 'depth',\n // type: 'number',\n // // @ts-expect-error - this is not correctly typed in plugins right now\n // label: ({ t }) => t('plugin-import-export:field-depth-label'),\n // admin: {\n // width: '33%',\n // },\n // defaultValue: 1,\n // required: true,\n // },\n ],\n },\n {\n name: 'selectionToUse',\n type: 'radio',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#SelectionToUseField',\n },\n },\n options: [\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentSelection'),\n value: 'currentSelection',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-currentFilters'),\n value: 'currentFilters',\n },\n {\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:selectionToUse-allDocuments'),\n value: 'all',\n },\n ],\n },\n {\n name: 'fields',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#FieldsToExport',\n },\n },\n hasMany: true,\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:field-fields-label'),\n },\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#CollectionField',\n },\n hidden: true,\n },\n required: true,\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n hidden: true,\n },\n defaultValue: {},\n hooks: {\n beforeValidate: [\n ({ value }) => {\n return value ?? {}\n },\n ],\n },\n },\n ],\n // @ts-expect-error - this is not correctly typed in plugins right now\n label: ({ t }) => t('plugin-import-export:exportOptions'),\n },\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: '@payloadcms/plugin-import-export/rsc#Preview',\n },\n },\n },\n ]\n}\n"],"names":["getFilename","getFields","config","localeField","localization","name","type","admin","width","defaultValue","label","t","options","value","locales","map","locale","code","fields","required","placeholder","components","Field","condition","data","collectionConfig","collections","find","collection","slug","collectionSlug","Boolean","versions","drafts","hasMany","hidden","hooks","beforeValidate"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAY,CAACC;IACxB,IAAIC;IACJ,IAAID,OAAOE,YAAY,EAAE;QACvBD,cAAc;YACZE,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,OAAO;YACT;YACAC,cAAc;YACd,sEAAsE;YACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;YACpBC,SAAS;gBACP;oBACEF,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;oBACpBE,OAAO;gBACT;mBACGX,OAAOE,YAAY,CAACU,OAAO,CAACC,GAAG,CAAC,CAACC,SAAY,CAAA;wBAC9CN,OAAO,OAAOM,WAAW,WAAWA,SAASA,OAAON,KAAK;wBACzDG,OAAO,OAAOG,WAAW,WAAWA,SAASA,OAAOC,IAAI;oBAC1D,CAAA;aACD;QACH;IACF;IAEA,OAAO;QACL;YACEX,MAAM;YACNY,QAAQ;gBACN;oBACEb,MAAM;oBACNC,MAAM;oBACNG,cAAc,IAAMT;oBACpB,sEAAsE;oBACtEU,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;gBACtB;gBACA;oBACEL,MAAM;oBACNY,QAAQ;wBACN;4BACEb,MAAM;4BACNC,MAAM;4BACNC,OAAO;gCACLC,OAAO;4BACT;4BACAC,cAAc;4BACd,sEAAsE;4BACtEC,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;4BACpBC,SAAS;gCACP;oCACEF,OAAO;oCACPG,OAAO;gCACT;gCACA;oCACEH,OAAO;oCACPG,OAAO;gCACT;6BACD;4BACDM,UAAU;wBACZ;wBACA;4BACEd,MAAM;4BACNC,MAAM;4BACNC,OAAO;gCACLa,aAAa;gCACbZ,OAAO;4BACT;4BACA,sEAAsE;4BACtE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ACpBE,OAAO;wBACT;qBACD;gBACH;gBACA;oBACER,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;oBACF;oBACAY,SAAS;oBACT,sEAAsE;oBACtExB,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;gBACtB;gBACA;oBACEN,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACLc,YAAY;4BACVC,OAAO;wBACT;wBACAa,QAAQ;oBACV;oBACAhB,UAAU;gBACZ;gBACA;oBACEd,MAAM;oBACNC,MAAM;oBACNC,OAAO;wBACL4B,QAAQ;oBACV;oBACA1B,cAAc,CAAC;oBACf2B,OAAO;wBACLC,gBAAgB;4BACd,CAAC,EAAExB,KAAK,EAAE;gCACR,OAAOA,SAAS,CAAC;4BACnB;yBACD;oBACH;gBACF;aACD;YACD,sEAAsE;YACtEH,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE;QACtB;QACA;YACEN,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLc,YAAY;oBACVC,OAAO;gBACT;YACF;QACF;KACD;AACH,EAAC"}
|
package/dist/exports/rsc.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export { ExportSaveButton } from '../components/ExportSaveButton/index.js';
|
|
|
4
4
|
export { FieldsToExport } from '../components/FieldsToExport/index.js';
|
|
5
5
|
export { ImportExportProvider } from '../components/ImportExportProvider/index.js';
|
|
6
6
|
export { Preview } from '../components/Preview/index.js';
|
|
7
|
+
export { SelectionToUseField } from '../components/SelectionToUseField/index.js';
|
|
7
8
|
export { SortBy } from '../components/SortBy/index.js';
|
|
8
|
-
export { WhereField } from '../components/WhereField/index.js';
|
|
9
9
|
//# sourceMappingURL=rsc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/exports/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/exports/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA"}
|
package/dist/exports/rsc.js
CHANGED
|
@@ -4,7 +4,7 @@ export { ExportSaveButton } from '../components/ExportSaveButton/index.js';
|
|
|
4
4
|
export { FieldsToExport } from '../components/FieldsToExport/index.js';
|
|
5
5
|
export { ImportExportProvider } from '../components/ImportExportProvider/index.js';
|
|
6
6
|
export { Preview } from '../components/Preview/index.js';
|
|
7
|
+
export { SelectionToUseField } from '../components/SelectionToUseField/index.js';
|
|
7
8
|
export { SortBy } from '../components/SortBy/index.js';
|
|
8
|
-
export { WhereField } from '../components/WhereField/index.js';
|
|
9
9
|
|
|
10
10
|
//# sourceMappingURL=rsc.js.map
|
package/dist/exports/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { CollectionField } from '../components/CollectionField/index.js'\nexport { ExportListMenuItem } from '../components/ExportListMenuItem/index.js'\nexport { ExportSaveButton } from '../components/ExportSaveButton/index.js'\nexport { FieldsToExport } from '../components/FieldsToExport/index.js'\nexport { ImportExportProvider } from '../components/ImportExportProvider/index.js'\nexport { Preview } from '../components/Preview/index.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { CollectionField } from '../components/CollectionField/index.js'\nexport { ExportListMenuItem } from '../components/ExportListMenuItem/index.js'\nexport { ExportSaveButton } from '../components/ExportSaveButton/index.js'\nexport { FieldsToExport } from '../components/FieldsToExport/index.js'\nexport { ImportExportProvider } from '../components/ImportExportProvider/index.js'\nexport { Preview } from '../components/Preview/index.js'\nexport { SelectionToUseField } from '../components/SelectionToUseField/index.js'\nexport { SortBy } from '../components/SortBy/index.js'\n"],"names":["CollectionField","ExportListMenuItem","ExportSaveButton","FieldsToExport","ImportExportProvider","Preview","SelectionToUseField","SortBy"],"mappings":"AAAA,SAASA,eAAe,QAAQ,yCAAwC;AACxE,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,gBAAgB,QAAQ,0CAAyC;AAC1E,SAASC,cAAc,QAAQ,wCAAuC;AACtE,SAASC,oBAAoB,QAAQ,8CAA6C;AAClF,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SAASC,mBAAmB,QAAQ,6CAA4C;AAChF,SAASC,MAAM,QAAQ,gCAA+B"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAA;AAKrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAA;AAKrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUzE,eAAO,MAAM,kBAAkB,iBACd,wBAAwB,cAC9B,MAAM,KAAG,MA6IjB,CAAA;AAEH,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,WAAW;QAC1B,sBAAsB,CAAC,EAAE;YACvB,KAAK,CAAC,EAAE,aAAa,CAAA;SACtB,CAAA;KACF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -84,8 +84,7 @@ export const importExportPlugin = (pluginConfig)=>(config)=>{
|
|
|
84
84
|
});
|
|
85
85
|
const docs = result.docs;
|
|
86
86
|
const toCSVFunctions = getCustomFieldFunctions({
|
|
87
|
-
fields: collection.config.fields
|
|
88
|
-
select
|
|
87
|
+
fields: collection.config.fields
|
|
89
88
|
});
|
|
90
89
|
const possibleKeys = getFlattenedFieldKeys(collection.config.fields);
|
|
91
90
|
const transformed = docs.map((doc)=>{
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, FlattenedField } from 'payload'\n\nimport { addDataAndFileToRequest, deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { flattenObject } from './export/flattenObject.js'\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js'\nimport { getSelect } from './export/getSelect.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\nimport { getFlattenedFieldKeys } from './utilities/getFlattenedFieldKeys.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n // Inject custom REST endpoints into the config\n config.endpoints = config.endpoints || []\n config.endpoints.push({\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n limit?: number\n locale?: string\n sort?: any\n where?: any\n }\n\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft: draft === 'yes',\n limit: limit && limit > 10 ? 10 : limit,\n locale,\n overrideAccess: false,\n req,\n select,\n sort,\n where,\n })\n\n const docs = result.docs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collection.config.fields as FlattenedField[],\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, FlattenedField } from 'payload'\n\nimport { addDataAndFileToRequest, deepMergeSimple } from 'payload'\n\nimport type { PluginDefaultTranslationsObject } from './translations/types.js'\nimport type { ImportExportPluginConfig, ToCSVFunction } from './types.js'\n\nimport { flattenObject } from './export/flattenObject.js'\nimport { getCreateCollectionExportTask } from './export/getCreateExportCollectionTask.js'\nimport { getCustomFieldFunctions } from './export/getCustomFieldFunctions.js'\nimport { getSelect } from './export/getSelect.js'\nimport { getExportCollection } from './getExportCollection.js'\nimport { translations } from './translations/index.js'\nimport { getFlattenedFieldKeys } from './utilities/getFlattenedFieldKeys.js'\n\nexport const importExportPlugin =\n (pluginConfig: ImportExportPluginConfig) =>\n (config: Config): Config => {\n const exportCollection = getExportCollection({ config, pluginConfig })\n if (config.collections) {\n config.collections.push(exportCollection)\n } else {\n config.collections = [exportCollection]\n }\n\n // inject custom import export provider\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.providers = config.admin.components.providers || []\n config.admin.components.providers.push(\n '@payloadcms/plugin-import-export/rsc#ImportExportProvider',\n )\n\n // inject the createExport job into the config\n ;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))\n\n let collectionsToUpdate = config.collections\n\n const usePluginCollections = pluginConfig.collections && pluginConfig.collections?.length > 0\n\n if (usePluginCollections) {\n collectionsToUpdate = config.collections?.filter((collection) => {\n return pluginConfig.collections?.includes(collection.slug)\n })\n }\n\n collectionsToUpdate.forEach((collection) => {\n if (!collection.admin) {\n collection.admin = { components: { listMenuItems: [] } }\n }\n const components = collection.admin.components || {}\n if (!components.listMenuItems) {\n components.listMenuItems = []\n }\n components.listMenuItems.push({\n clientProps: {\n exportCollectionSlug: exportCollection.slug,\n },\n path: '@payloadcms/plugin-import-export/rsc#ExportListMenuItem',\n })\n collection.admin.components = components\n })\n\n if (!config.i18n) {\n config.i18n = {}\n }\n\n // config.i18n.translations = deepMergeSimple(translations, config.i18n?.translations ?? {})\n\n // Inject custom REST endpoints into the config\n config.endpoints = config.endpoints || []\n config.endpoints.push({\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const { collectionSlug, draft, fields, limit, locale, sort, where } = req.data as {\n collectionSlug: string\n draft?: 'no' | 'yes'\n fields?: string[]\n limit?: number\n locale?: string\n sort?: any\n where?: any\n }\n\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n return Response.json(\n { error: `Collection with slug ${collectionSlug} not found` },\n { status: 400 },\n )\n }\n\n const select = Array.isArray(fields) && fields.length > 0 ? getSelect(fields) : undefined\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 1,\n draft: draft === 'yes',\n limit: limit && limit > 10 ? 10 : limit,\n locale,\n overrideAccess: false,\n req,\n select,\n sort,\n where,\n })\n\n const docs = result.docs\n\n const toCSVFunctions = getCustomFieldFunctions({\n fields: collection.config.fields as FlattenedField[],\n })\n\n const possibleKeys = getFlattenedFieldKeys(collection.config.fields as FlattenedField[])\n\n const transformed = docs.map((doc) => {\n const row = flattenObject({\n doc,\n fields,\n toCSVFunctions,\n })\n\n for (const key of possibleKeys) {\n if (!(key in row)) {\n row[key] = null\n }\n }\n\n return row\n })\n\n return Response.json({\n docs: transformed,\n totalDocs: result.totalDocs,\n })\n },\n method: 'post',\n path: '/preview-data',\n })\n\n /**\n * Merge plugin translations\n */\n const simplifiedTranslations = Object.entries(translations).reduce(\n (acc, [key, value]) => {\n acc[key] = value.translations\n return acc\n },\n {} as Record<string, PluginDefaultTranslationsObject>,\n )\n\n config.i18n = {\n ...config.i18n,\n translations: deepMergeSimple(simplifiedTranslations, config.i18n?.translations ?? {}),\n }\n\n return config\n }\n\ndeclare module 'payload' {\n export interface FieldCustom {\n 'plugin-import-export'?: {\n toCSV?: ToCSVFunction\n }\n }\n}\n"],"names":["addDataAndFileToRequest","deepMergeSimple","flattenObject","getCreateCollectionExportTask","getCustomFieldFunctions","getSelect","getExportCollection","translations","getFlattenedFieldKeys","importExportPlugin","pluginConfig","config","exportCollection","collections","push","admin","components","providers","jobs","tasks","collectionsToUpdate","usePluginCollections","length","filter","collection","includes","slug","forEach","listMenuItems","clientProps","exportCollectionSlug","path","i18n","endpoints","handler","req","collectionSlug","draft","fields","limit","locale","sort","where","data","payload","Response","json","error","status","select","Array","isArray","undefined","result","find","depth","overrideAccess","docs","toCSVFunctions","possibleKeys","transformed","map","doc","row","key","totalDocs","method","simplifiedTranslations","Object","entries","reduce","acc","value"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,eAAe,QAAQ,UAAS;AAKlE,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,uBAAuB,QAAQ,sCAAqC;AAC7E,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,qBAAqB,QAAQ,uCAAsC;AAE5E,OAAO,MAAMC,qBACX,CAACC,eACD,CAACC;QACC,MAAMC,mBAAmBN,oBAAoB;YAAEK;YAAQD;QAAa;QACpE,IAAIC,OAAOE,WAAW,EAAE;YACtBF,OAAOE,WAAW,CAACC,IAAI,CAACF;QAC1B,OAAO;YACLD,OAAOE,WAAW,GAAG;gBAACD;aAAiB;QACzC;QAEA,uCAAuC;QACvCD,OAAOI,KAAK,GAAGJ,OAAOI,KAAK,IAAI,CAAC;QAChCJ,OAAOI,KAAK,CAACC,UAAU,GAAGL,OAAOI,KAAK,CAACC,UAAU,IAAI,CAAC;QACtDL,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS,GAAGN,OAAOI,KAAK,CAACC,UAAU,CAACC,SAAS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CAACC,KAAK,CAACP,KAAKQ,MAAM;YAChBD,GAAG,CAACP,IAAI,GAAGQ,MAAMjE,YAAY;YAC7B,OAAOgE;QACT,GACA,CAAC;QAGH5D,OAAOqB,IAAI,GAAG;YACZ,GAAGrB,OAAOqB,IAAI;YACdzB,cAAcN,gBAAgBkE,wBAAwBxD,OAAOqB,IAAI,EAAEzB,gBAAgB,CAAC;QACtF;QAEA,OAAOI;IACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFlattenedFieldKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,KAAK,uBAAuB,GACxB;IACE,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,cAAc,EAAE,CAAA;QACxB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;IACH,IAAI,EAAE,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;CACrC,GACD,cAAc,CAAA;AAElB,eAAO,MAAM,qBAAqB,WAAY,uBAAuB,EAAE,sBAAgB,MAAM,
|
|
1
|
+
{"version":3,"file":"getFlattenedFieldKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,KAAK,uBAAuB,GACxB;IACE,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,cAAc,EAAE,CAAA;QACxB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;IACH,IAAI,EAAE,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;CACrC,GACD,cAAc,CAAA;AAElB,eAAO,MAAM,qBAAqB,WAAY,uBAAuB,EAAE,sBAAgB,MAAM,EA4E5F,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export const getFlattenedFieldKeys = (fields, prefix = '')=>{
|
|
2
2
|
const keys = [];
|
|
3
3
|
fields.forEach((field)=>{
|
|
4
|
-
|
|
4
|
+
const fieldHasToCSVFunction = 'custom' in field && typeof field.custom === 'object' && 'plugin-import-export' in field.custom && field.custom['plugin-import-export']?.toCSV;
|
|
5
|
+
if (!('name' in field) || typeof field.name !== 'string' || fieldHasToCSVFunction) {
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
8
|
const name = prefix ? `${prefix}_${field.name}` : field.name;
|
|
@@ -25,11 +26,21 @@ export const getFlattenedFieldKeys = (fields, prefix = '')=>{
|
|
|
25
26
|
break;
|
|
26
27
|
case 'relationship':
|
|
27
28
|
if (field.hasMany) {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (Array.isArray(field.relationTo)) {
|
|
30
|
+
// hasMany polymorphic
|
|
31
|
+
keys.push(`${name}_0_relationTo`, `${name}_0_id`);
|
|
32
|
+
} else {
|
|
33
|
+
// hasMany monomorphic
|
|
34
|
+
keys.push(`${name}_0`);
|
|
35
|
+
}
|
|
30
36
|
} else {
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
if (Array.isArray(field.relationTo)) {
|
|
38
|
+
// hasOne polymorphic
|
|
39
|
+
keys.push(`${name}_relationTo`, `${name}_id`);
|
|
40
|
+
} else {
|
|
41
|
+
// hasOne monomorphic
|
|
42
|
+
keys.push(name);
|
|
43
|
+
}
|
|
33
44
|
}
|
|
34
45
|
break;
|
|
35
46
|
case 'tabs':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"sourcesContent":["import { type FlattenedField } from 'payload'\n\ntype FieldWithPresentational =\n | {\n fields?: FlattenedField[]\n name?: string\n tabs?: {\n fields: FlattenedField[]\n name?: string\n }[]\n type: 'collapsible' | 'row' | 'tabs'\n }\n | FlattenedField\n\nexport const getFlattenedFieldKeys = (fields: FieldWithPresentational[], prefix = ''): string[] => {\n const keys: string[] = []\n\n fields.forEach((field) => {\n if (!('name' in field) || typeof field.name !== 'string') {\n return\n }\n\n const name = prefix ? `${prefix}_${field.name}` : field.name\n\n switch (field.type) {\n case 'array': {\n const subKeys = getFlattenedFieldKeys(field.fields as FlattenedField[], `${name}_0`)\n keys.push(...subKeys)\n break\n }\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKeys = getFlattenedFieldKeys(block.fields as FlattenedField[], `${name}_0`)\n keys.push(...blockKeys)\n })\n break\n case 'collapsible':\n case 'group':\n case 'row':\n keys.push(...getFlattenedFieldKeys(field.fields as FlattenedField[], name))\n break\n case 'relationship':\n if (field.hasMany) {\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getFlattenedFieldKeys.ts"],"sourcesContent":["import { type FlattenedField } from 'payload'\n\ntype FieldWithPresentational =\n | {\n fields?: FlattenedField[]\n name?: string\n tabs?: {\n fields: FlattenedField[]\n name?: string\n }[]\n type: 'collapsible' | 'row' | 'tabs'\n }\n | FlattenedField\n\nexport const getFlattenedFieldKeys = (fields: FieldWithPresentational[], prefix = ''): string[] => {\n const keys: string[] = []\n\n fields.forEach((field) => {\n const fieldHasToCSVFunction =\n 'custom' in field &&\n typeof field.custom === 'object' &&\n 'plugin-import-export' in field.custom &&\n field.custom['plugin-import-export']?.toCSV\n\n if (!('name' in field) || typeof field.name !== 'string' || fieldHasToCSVFunction) {\n return\n }\n\n const name = prefix ? `${prefix}_${field.name}` : field.name\n\n switch (field.type) {\n case 'array': {\n const subKeys = getFlattenedFieldKeys(field.fields as FlattenedField[], `${name}_0`)\n keys.push(...subKeys)\n break\n }\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKeys = getFlattenedFieldKeys(block.fields as FlattenedField[], `${name}_0`)\n keys.push(...blockKeys)\n })\n break\n case 'collapsible':\n case 'group':\n case 'row':\n keys.push(...getFlattenedFieldKeys(field.fields as FlattenedField[], name))\n break\n case 'relationship':\n if (field.hasMany) {\n if (Array.isArray(field.relationTo)) {\n // hasMany polymorphic\n keys.push(`${name}_0_relationTo`, `${name}_0_id`)\n } else {\n // hasMany monomorphic\n keys.push(`${name}_0`)\n }\n } else {\n if (Array.isArray(field.relationTo)) {\n // hasOne polymorphic\n keys.push(`${name}_relationTo`, `${name}_id`)\n } else {\n // hasOne monomorphic\n keys.push(name)\n }\n }\n break\n case 'tabs':\n if (field.tabs) {\n field.tabs.forEach((tab) => {\n if (tab.name) {\n const tabPrefix = prefix ? `${prefix}_${tab.name}` : tab.name\n keys.push(...getFlattenedFieldKeys(tab.fields, tabPrefix))\n } else {\n keys.push(...getFlattenedFieldKeys(tab.fields, prefix))\n }\n })\n }\n break\n default:\n if ('hasMany' in field && field.hasMany) {\n // Push placeholder for first index\n keys.push(`${name}_0`)\n } else {\n keys.push(name)\n }\n break\n }\n })\n\n return keys\n}\n"],"names":["getFlattenedFieldKeys","fields","prefix","keys","forEach","field","fieldHasToCSVFunction","custom","toCSV","name","type","subKeys","push","blocks","block","blockKeys","hasMany","Array","isArray","relationTo","tabs","tab","tabPrefix"],"mappings":"AAcA,OAAO,MAAMA,wBAAwB,CAACC,QAAmCC,SAAS,EAAE;IAClF,MAAMC,OAAiB,EAAE;IAEzBF,OAAOG,OAAO,CAAC,CAACC;QACd,MAAMC,wBACJ,YAAYD,SACZ,OAAOA,MAAME,MAAM,KAAK,YACxB,0BAA0BF,MAAME,MAAM,IACtCF,MAAME,MAAM,CAAC,uBAAuB,EAAEC;QAExC,IAAI,CAAE,CAAA,UAAUH,KAAI,KAAM,OAAOA,MAAMI,IAAI,KAAK,YAAYH,uBAAuB;YACjF;QACF;QAEA,MAAMG,OAAOP,SAAS,GAAGA,OAAO,CAAC,EAAEG,MAAMI,IAAI,EAAE,GAAGJ,MAAMI,IAAI;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BAAsBqB,IAAIpB,MAAM,EAAEqB;wBACjD,OAAO;4BACLnB,KAAKS,IAAI,IAAIZ,sBAAsBqB,IAAIpB,MAAM,EAAEC;wBACjD;oBACF;gBACF;gBACA;YACF;gBACE,IAAI,aAAaG,SAASA,MAAMW,OAAO,EAAE;oBACvC,mCAAmC;oBACnCb,KAAKS,IAAI,CAAC,GAAGH,KAAK,EAAE,CAAC;gBACvB,OAAO;oBACLN,KAAKS,IAAI,CAACH;gBACZ;gBACA;QACJ;IACF;IAEA,OAAON;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.47.0
|
|
3
|
+
"version": "3.47.0",
|
|
4
4
|
"description": "Import-Export plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"csv-parse": "^5.6.0",
|
|
65
65
|
"csv-stringify": "^6.5.2",
|
|
66
66
|
"qs-esm": "7.0.2",
|
|
67
|
-
"@payloadcms/translations": "3.47.0
|
|
68
|
-
"@payloadcms/ui": "3.47.0
|
|
67
|
+
"@payloadcms/translations": "3.47.0",
|
|
68
|
+
"@payloadcms/ui": "3.47.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@payloadcms/ui": "3.47.0-internal.b17506e",
|
|
72
71
|
"@payloadcms/eslint-config": "3.28.0",
|
|
73
|
-
"
|
|
72
|
+
"@payloadcms/ui": "3.47.0",
|
|
73
|
+
"payload": "3.47.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.47.0
|
|
77
|
-
"payload": "3.47.0
|
|
76
|
+
"@payloadcms/ui": "3.47.0",
|
|
77
|
+
"payload": "3.47.0"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/WhereField/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EA8D9B,CAAA"}
|