@frogbotai/plugin-import-export 0.39.0 → 0.41.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/README.md +4 -0
- package/dist/client/ImportColumnsField.d.ts +12 -0
- package/dist/client/ImportColumnsField.d.ts.map +1 -0
- package/dist/client/ImportColumnsField.js +403 -0
- package/dist/client/ImportColumnsField.js.map +1 -0
- package/dist/client/styles.css +72 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +3 -0
- package/dist/client.js.map +1 -0
- package/dist/columns/columnMap.d.ts +32 -0
- package/dist/columns/columnMap.d.ts.map +1 -0
- package/dist/columns/columnMap.js +67 -0
- package/dist/columns/columnMap.js.map +1 -0
- package/dist/columns/rewrite.d.ts +13 -0
- package/dist/columns/rewrite.d.ts.map +1 -0
- package/dist/columns/rewrite.js +155 -0
- package/dist/columns/rewrite.js.map +1 -0
- package/dist/columns/suggest.d.ts +52 -0
- package/dist/columns/suggest.d.ts.map +1 -0
- package/dist/columns/suggest.js +204 -0
- package/dist/columns/suggest.js.map +1 -0
- package/dist/endpoints/importColumns.d.ts +24 -0
- package/dist/endpoints/importColumns.d.ts.map +1 -0
- package/dist/endpoints/importColumns.js +71 -0
- package/dist/endpoints/importColumns.js.map +1 -0
- package/dist/endpoints/parseFile.d.ts +12 -0
- package/dist/endpoints/parseFile.d.ts.map +1 -0
- package/dist/endpoints/parseFile.js +57 -0
- package/dist/endpoints/parseFile.js.map +1 -0
- package/dist/endpoints/request.d.ts +26 -0
- package/dist/endpoints/request.d.ts.map +1 -0
- package/dist/endpoints/request.js +57 -0
- package/dist/endpoints/request.js.map +1 -0
- package/dist/endpoints/suggestColumns.d.ts +19 -0
- package/dist/endpoints/suggestColumns.d.ts.map +1 -0
- package/dist/endpoints/suggestColumns.js +117 -0
- package/dist/endpoints/suggestColumns.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +131 -6
- package/dist/index.js.map +1 -1
- package/dist/relationships.d.ts +27 -0
- package/dist/relationships.d.ts.map +1 -0
- package/dist/relationships.js +114 -0
- package/dist/relationships.js.map +1 -0
- package/package.json +19 -7
package/README.md
CHANGED
|
@@ -13,3 +13,7 @@ export default buildConfig({
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
It supports the collection, import, export, limit, hook, and override options that fit FrogBot's collection, admin component, i18n, and jobs config surfaces.
|
|
16
|
+
|
|
17
|
+
The import form maps each file column to a field, links relationship columns to existing records by name or another field, and can create the missing ones. It reuses the mapping of your last import with the same headers and, when an AI model is configured, can suggest the rest. Importers that read another tool's API can link records the same way with `resolveRelationship`.
|
|
18
|
+
|
|
19
|
+
See the [import and export documentation](https://docs.frogbot.ai/plugins/import-export).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import './styles.css';
|
|
2
|
+
import type { JSONFieldClientProps } from 'payload';
|
|
3
|
+
import type { ImportColumnsFieldClientProps } from '../columns/columnMap.js';
|
|
4
|
+
export type ImportColumnsFieldProps = JSONFieldClientProps & Partial<ImportColumnsFieldClientProps>;
|
|
5
|
+
/**
|
|
6
|
+
* The import form's Columns section. After a file is chosen it lists each file column next to a
|
|
7
|
+
* field picker, started from the last matching import or from header names, and writes the
|
|
8
|
+
* mapping to `columnMap`. Relationship columns add a match-by picker and a create-missing switch.
|
|
9
|
+
* A saved import shows its mapping read-only.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ImportColumnsField({ ai, field, path, readOnly }: ImportColumnsFieldProps): import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
//# sourceMappingURL=ImportColumnsField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportColumnsField.d.ts","sourceRoot":"","sources":["../../src/client/ImportColumnsField.tsx"],"names":[],"mappings":"AAEA,OAAO,cAAc,CAAC;AAoBtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,KAAK,EAGV,6BAA6B,EAC9B,MAAM,yBAAyB,CAAC;AAKjC,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAkBpG;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAU,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,uBAAuB,kDAiLhG"}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import './styles.css';
|
|
4
|
+
import { Alert, AlertDescription, Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch } from '@frogbotai/ui';
|
|
5
|
+
import { FieldLabel, useConfig, useDocumentInfo, useField, useFormFields } from '@frogbotai/ui/admin';
|
|
6
|
+
import { useEffect, useRef, useState } from 'react';
|
|
7
|
+
const skip = '__skip';
|
|
8
|
+
const baseClass = 'import-columns';
|
|
9
|
+
const rootClass = `field-type ${baseClass}`;
|
|
10
|
+
/**
|
|
11
|
+
* The import form's Columns section. After a file is chosen it lists each file column next to a
|
|
12
|
+
* field picker, started from the last matching import or from header names, and writes the
|
|
13
|
+
* mapping to `columnMap`. Relationship columns add a match-by picker and a create-missing switch.
|
|
14
|
+
* A saved import shows its mapping read-only.
|
|
15
|
+
*/ export function ImportColumnsField({ ai = false, field, path, readOnly }) {
|
|
16
|
+
const fieldPath = path ?? field.name;
|
|
17
|
+
const { config } = useConfig();
|
|
18
|
+
const { id, collectionSlug: importsSlug } = useDocumentInfo();
|
|
19
|
+
const { value, setValue } = useField({
|
|
20
|
+
path: fieldPath
|
|
21
|
+
});
|
|
22
|
+
const { value: collectionSlug } = useField({
|
|
23
|
+
path: 'collectionSlug'
|
|
24
|
+
});
|
|
25
|
+
const file = useFormFields(([fields])=>fields?.file?.value);
|
|
26
|
+
const [load, setLoad] = useState({
|
|
27
|
+
status: 'idle'
|
|
28
|
+
});
|
|
29
|
+
const [suggesting, setSuggesting] = useState(false);
|
|
30
|
+
const [notice, setNotice] = useState();
|
|
31
|
+
const saved = id !== undefined && id !== null;
|
|
32
|
+
const endpoint = `${config.routes.api}/${importsSlug}`;
|
|
33
|
+
const setMapping = useRef(setValue);
|
|
34
|
+
setMapping.current = setValue;
|
|
35
|
+
useEffect(()=>{
|
|
36
|
+
if (saved || readOnly) return;
|
|
37
|
+
if (!(file instanceof File) || !collectionSlug) {
|
|
38
|
+
setLoad({
|
|
39
|
+
status: 'idle'
|
|
40
|
+
});
|
|
41
|
+
setMapping.current(null, true);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
setLoad({
|
|
46
|
+
status: 'loading'
|
|
47
|
+
});
|
|
48
|
+
setNotice(undefined);
|
|
49
|
+
void loadColumns({
|
|
50
|
+
endpoint,
|
|
51
|
+
collectionSlug,
|
|
52
|
+
file,
|
|
53
|
+
signal: controller.signal
|
|
54
|
+
}).then(({ columns, headers, ...loaded })=>{
|
|
55
|
+
setLoad({
|
|
56
|
+
status: 'ready',
|
|
57
|
+
...loaded
|
|
58
|
+
});
|
|
59
|
+
setMapping.current({
|
|
60
|
+
headers,
|
|
61
|
+
columns
|
|
62
|
+
});
|
|
63
|
+
}).catch((error)=>{
|
|
64
|
+
if (controller.signal.aborted) return;
|
|
65
|
+
setLoad({
|
|
66
|
+
status: 'error',
|
|
67
|
+
message: messageOf(error)
|
|
68
|
+
});
|
|
69
|
+
setMapping.current(null, true);
|
|
70
|
+
});
|
|
71
|
+
return ()=>controller.abort();
|
|
72
|
+
}, [
|
|
73
|
+
collectionSlug,
|
|
74
|
+
endpoint,
|
|
75
|
+
file,
|
|
76
|
+
readOnly,
|
|
77
|
+
saved
|
|
78
|
+
]);
|
|
79
|
+
if (saved || readOnly) {
|
|
80
|
+
return value?.columns?.length ? /*#__PURE__*/ _jsxs("div", {
|
|
81
|
+
className: rootClass,
|
|
82
|
+
children: [
|
|
83
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
84
|
+
label: field.label ?? 'Columns'
|
|
85
|
+
}),
|
|
86
|
+
/*#__PURE__*/ _jsx("ul", {
|
|
87
|
+
className: `${baseClass}__summary`,
|
|
88
|
+
children: value.columns.map((column)=>/*#__PURE__*/ _jsxs("li", {
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ _jsx("span", {
|
|
91
|
+
className: `${baseClass}__header`,
|
|
92
|
+
children: column.header
|
|
93
|
+
}),
|
|
94
|
+
' → ',
|
|
95
|
+
describeColumn(column)
|
|
96
|
+
]
|
|
97
|
+
}, column.header))
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
}) : null;
|
|
101
|
+
}
|
|
102
|
+
if (load.status === 'idle') return null;
|
|
103
|
+
if (load.status === 'loading') {
|
|
104
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
105
|
+
className: rootClass,
|
|
106
|
+
children: [
|
|
107
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
108
|
+
label: field.label ?? 'Columns'
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ _jsx("p", {
|
|
111
|
+
className: `${baseClass}__description`,
|
|
112
|
+
children: "Reading the file's columns…"
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (load.status === 'error') {
|
|
118
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
119
|
+
className: rootClass,
|
|
120
|
+
children: [
|
|
121
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
122
|
+
label: field.label ?? 'Columns'
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ _jsx(Alert, {
|
|
125
|
+
variant: "destructive",
|
|
126
|
+
children: /*#__PURE__*/ _jsx(AlertDescription, {
|
|
127
|
+
children: load.message
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const columns = value?.columns ?? [];
|
|
134
|
+
const headers = value?.headers ?? columns.map(({ header })=>header);
|
|
135
|
+
const skipped = columns.some((column)=>column.field === null);
|
|
136
|
+
function update(index, column) {
|
|
137
|
+
setValue({
|
|
138
|
+
headers,
|
|
139
|
+
columns: columns.map((current, at)=>at === index ? column : current)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async function suggest(ready) {
|
|
143
|
+
setSuggesting(true);
|
|
144
|
+
setNotice(undefined);
|
|
145
|
+
try {
|
|
146
|
+
const response = await fetch(`${endpoint}/suggest-columns`, {
|
|
147
|
+
method: 'POST',
|
|
148
|
+
credentials: 'include',
|
|
149
|
+
headers: {
|
|
150
|
+
'Content-Type': 'application/json'
|
|
151
|
+
},
|
|
152
|
+
body: JSON.stringify({
|
|
153
|
+
collectionSlug,
|
|
154
|
+
fileData: ready.fileData,
|
|
155
|
+
format: ready.format,
|
|
156
|
+
columns
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
const result = await response.json();
|
|
160
|
+
if (!response.ok || !result.columns) {
|
|
161
|
+
setNotice({
|
|
162
|
+
error: true,
|
|
163
|
+
text: result.error ?? 'AI suggestion failed.'
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
setValue({
|
|
168
|
+
headers,
|
|
169
|
+
columns: result.columns
|
|
170
|
+
});
|
|
171
|
+
setNotice({
|
|
172
|
+
error: false,
|
|
173
|
+
text: suggestedText(result.suggested ?? 0)
|
|
174
|
+
});
|
|
175
|
+
} catch (error) {
|
|
176
|
+
setNotice({
|
|
177
|
+
error: true,
|
|
178
|
+
text: `AI suggestion failed: ${messageOf(error)}`
|
|
179
|
+
});
|
|
180
|
+
} finally{
|
|
181
|
+
setSuggesting(false);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
185
|
+
className: rootClass,
|
|
186
|
+
children: [
|
|
187
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
188
|
+
className: `${baseClass}__heading`,
|
|
189
|
+
children: [
|
|
190
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
191
|
+
label: field.label ?? 'Columns'
|
|
192
|
+
}),
|
|
193
|
+
ai && /*#__PURE__*/ _jsx(Button, {
|
|
194
|
+
disabled: suggesting || !skipped,
|
|
195
|
+
size: "sm",
|
|
196
|
+
type: "button",
|
|
197
|
+
variant: "outline",
|
|
198
|
+
onClick: ()=>void suggest(load),
|
|
199
|
+
children: suggesting ? 'Suggesting…' : 'Suggest with AI'
|
|
200
|
+
})
|
|
201
|
+
]
|
|
202
|
+
}),
|
|
203
|
+
/*#__PURE__*/ _jsx("p", {
|
|
204
|
+
className: `${baseClass}__description`,
|
|
205
|
+
children: load.source === 'previous' ? 'Started from your last import with these columns.' : 'Columns were matched to fields by name. Check them before importing.'
|
|
206
|
+
}),
|
|
207
|
+
notice && /*#__PURE__*/ _jsx(Alert, {
|
|
208
|
+
variant: notice.error ? 'destructive' : 'default',
|
|
209
|
+
children: /*#__PURE__*/ _jsx(AlertDescription, {
|
|
210
|
+
children: notice.text
|
|
211
|
+
})
|
|
212
|
+
}),
|
|
213
|
+
/*#__PURE__*/ _jsxs("table", {
|
|
214
|
+
className: `${baseClass}__table`,
|
|
215
|
+
children: [
|
|
216
|
+
/*#__PURE__*/ _jsx("thead", {
|
|
217
|
+
children: /*#__PURE__*/ _jsxs("tr", {
|
|
218
|
+
children: [
|
|
219
|
+
/*#__PURE__*/ _jsx("th", {
|
|
220
|
+
scope: "col",
|
|
221
|
+
children: "File column"
|
|
222
|
+
}),
|
|
223
|
+
/*#__PURE__*/ _jsx("th", {
|
|
224
|
+
scope: "col",
|
|
225
|
+
children: "Field"
|
|
226
|
+
}),
|
|
227
|
+
/*#__PURE__*/ _jsx("th", {
|
|
228
|
+
scope: "col",
|
|
229
|
+
children: "Match by"
|
|
230
|
+
}),
|
|
231
|
+
/*#__PURE__*/ _jsx("th", {
|
|
232
|
+
scope: "col",
|
|
233
|
+
children: "Create missing"
|
|
234
|
+
})
|
|
235
|
+
]
|
|
236
|
+
})
|
|
237
|
+
}),
|
|
238
|
+
/*#__PURE__*/ _jsx("tbody", {
|
|
239
|
+
children: columns.map((column, index)=>/*#__PURE__*/ _jsx(ColumnRow, {
|
|
240
|
+
column: column,
|
|
241
|
+
columns: columns,
|
|
242
|
+
samples: load.samples[column.header] ?? [],
|
|
243
|
+
targets: load.targets,
|
|
244
|
+
onChange: (next)=>update(index, next)
|
|
245
|
+
}, column.header))
|
|
246
|
+
})
|
|
247
|
+
]
|
|
248
|
+
})
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function ColumnRow({ column, columns, samples, targets, onChange }) {
|
|
253
|
+
const target = targets.find(({ field })=>field === column.field);
|
|
254
|
+
const relationship = target?.relationship;
|
|
255
|
+
const used = new Set(columns.filter((other)=>other !== column).map(({ field })=>field));
|
|
256
|
+
const exported = column.field !== null && !target;
|
|
257
|
+
function choose(field) {
|
|
258
|
+
const chosen = targets.find((candidate)=>candidate.field === field);
|
|
259
|
+
if (field === skip || !chosen) {
|
|
260
|
+
onChange({
|
|
261
|
+
header: column.header,
|
|
262
|
+
field: field === skip ? null : field
|
|
263
|
+
});
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
onChange(chosen.relationship ? {
|
|
267
|
+
header: column.header,
|
|
268
|
+
field,
|
|
269
|
+
matchBy: chosen.relationship.defaultMatchBy,
|
|
270
|
+
createMissing: false
|
|
271
|
+
} : {
|
|
272
|
+
header: column.header,
|
|
273
|
+
field
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
return /*#__PURE__*/ _jsxs("tr", {
|
|
277
|
+
children: [
|
|
278
|
+
/*#__PURE__*/ _jsxs("th", {
|
|
279
|
+
scope: "row",
|
|
280
|
+
children: [
|
|
281
|
+
/*#__PURE__*/ _jsx("span", {
|
|
282
|
+
className: `${baseClass}__header`,
|
|
283
|
+
children: column.header
|
|
284
|
+
}),
|
|
285
|
+
samples.length > 0 && /*#__PURE__*/ _jsx("span", {
|
|
286
|
+
className: `${baseClass}__samples`,
|
|
287
|
+
children: samples.map(String).join(', ')
|
|
288
|
+
})
|
|
289
|
+
]
|
|
290
|
+
}),
|
|
291
|
+
/*#__PURE__*/ _jsx("td", {
|
|
292
|
+
children: /*#__PURE__*/ _jsxs(Select, {
|
|
293
|
+
value: column.field ?? skip,
|
|
294
|
+
onValueChange: choose,
|
|
295
|
+
children: [
|
|
296
|
+
/*#__PURE__*/ _jsx(SelectTrigger, {
|
|
297
|
+
"aria-label": `Field for "${column.header}"`,
|
|
298
|
+
children: /*#__PURE__*/ _jsx(SelectValue, {})
|
|
299
|
+
}),
|
|
300
|
+
/*#__PURE__*/ _jsxs(SelectContent, {
|
|
301
|
+
children: [
|
|
302
|
+
/*#__PURE__*/ _jsx(SelectItem, {
|
|
303
|
+
value: skip,
|
|
304
|
+
children: "Skip"
|
|
305
|
+
}),
|
|
306
|
+
exported && /*#__PURE__*/ _jsx(SelectItem, {
|
|
307
|
+
value: column.field,
|
|
308
|
+
children: column.field
|
|
309
|
+
}),
|
|
310
|
+
targets.map((option)=>/*#__PURE__*/ _jsx(SelectItem, {
|
|
311
|
+
disabled: used.has(option.field),
|
|
312
|
+
value: option.field,
|
|
313
|
+
children: option.label
|
|
314
|
+
}, option.field))
|
|
315
|
+
]
|
|
316
|
+
})
|
|
317
|
+
]
|
|
318
|
+
})
|
|
319
|
+
}),
|
|
320
|
+
/*#__PURE__*/ _jsx("td", {
|
|
321
|
+
children: relationship && /*#__PURE__*/ _jsxs(Select, {
|
|
322
|
+
value: column.matchBy ?? relationship.defaultMatchBy,
|
|
323
|
+
onValueChange: (matchBy)=>onChange({
|
|
324
|
+
...column,
|
|
325
|
+
matchBy,
|
|
326
|
+
createMissing: matchBy !== 'id' && column.createMissing === true
|
|
327
|
+
}),
|
|
328
|
+
children: [
|
|
329
|
+
/*#__PURE__*/ _jsx(SelectTrigger, {
|
|
330
|
+
"aria-label": `Match "${column.header}" by`,
|
|
331
|
+
children: /*#__PURE__*/ _jsx(SelectValue, {})
|
|
332
|
+
}),
|
|
333
|
+
/*#__PURE__*/ _jsx(SelectContent, {
|
|
334
|
+
children: relationship.matchBy.map((option)=>/*#__PURE__*/ _jsx(SelectItem, {
|
|
335
|
+
value: option.field,
|
|
336
|
+
children: option.label
|
|
337
|
+
}, option.field))
|
|
338
|
+
})
|
|
339
|
+
]
|
|
340
|
+
})
|
|
341
|
+
}),
|
|
342
|
+
/*#__PURE__*/ _jsx("td", {
|
|
343
|
+
children: relationship && /*#__PURE__*/ _jsx(Switch, {
|
|
344
|
+
"aria-label": `Create missing for "${column.header}"`,
|
|
345
|
+
checked: column.createMissing === true,
|
|
346
|
+
disabled: column.matchBy === 'id',
|
|
347
|
+
size: "sm",
|
|
348
|
+
onCheckedChange: (createMissing)=>onChange({
|
|
349
|
+
...column,
|
|
350
|
+
createMissing
|
|
351
|
+
})
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
]
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
async function loadColumns({ endpoint, collectionSlug, file, signal }) {
|
|
358
|
+
const format = file.type === 'text/csv' || file.name.endsWith('.csv') ? 'csv' : 'json';
|
|
359
|
+
const fileData = toBase64(await file.arrayBuffer());
|
|
360
|
+
const response = await fetch(`${endpoint}/import-columns`, {
|
|
361
|
+
method: 'POST',
|
|
362
|
+
credentials: 'include',
|
|
363
|
+
headers: {
|
|
364
|
+
'Content-Type': 'application/json'
|
|
365
|
+
},
|
|
366
|
+
body: JSON.stringify({
|
|
367
|
+
collectionSlug,
|
|
368
|
+
fileData,
|
|
369
|
+
format
|
|
370
|
+
}),
|
|
371
|
+
signal
|
|
372
|
+
});
|
|
373
|
+
const result = await response.json();
|
|
374
|
+
if (!response.ok) throw new Error(result.error ?? "Could not read the file's columns.");
|
|
375
|
+
return {
|
|
376
|
+
...result,
|
|
377
|
+
fileData,
|
|
378
|
+
format
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function toBase64(buffer) {
|
|
382
|
+
const bytes = new Uint8Array(buffer);
|
|
383
|
+
const chunk = 0x8000;
|
|
384
|
+
let binary = '';
|
|
385
|
+
for(let index = 0; index < bytes.length; index += chunk){
|
|
386
|
+
binary += String.fromCharCode(...bytes.subarray(index, index + chunk));
|
|
387
|
+
}
|
|
388
|
+
return btoa(binary);
|
|
389
|
+
}
|
|
390
|
+
function describeColumn({ field, matchBy, createMissing }) {
|
|
391
|
+
if (!field) return 'Skip';
|
|
392
|
+
if (!matchBy) return field;
|
|
393
|
+
return `${field}, matched by ${matchBy}${createMissing ? ', create missing' : ''}`;
|
|
394
|
+
}
|
|
395
|
+
function suggestedText(count) {
|
|
396
|
+
if (count === 0) return 'AI found no more columns to map.';
|
|
397
|
+
return `AI mapped ${count} ${count === 1 ? 'column' : 'columns'}. Check them before importing.`;
|
|
398
|
+
}
|
|
399
|
+
function messageOf(error) {
|
|
400
|
+
return error instanceof Error ? error.message : String(error);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//# sourceMappingURL=ImportColumnsField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/ImportColumnsField.tsx"],"names":["Alert","AlertDescription","Button","Select","SelectContent","SelectItem","SelectTrigger","SelectValue","Switch","FieldLabel","useConfig","useDocumentInfo","useField","useFormFields","useEffect","useRef","useState","skip","baseClass","rootClass","ImportColumnsField","ai","field","path","readOnly","fieldPath","name","config","id","collectionSlug","importsSlug","value","setValue","file","fields","load","setLoad","status","suggesting","setSuggesting","notice","setNotice","saved","undefined","endpoint","routes","api","setMapping","current","File","controller","AbortController","loadColumns","signal","then","columns","headers","loaded","catch","error","aborted","message","messageOf","abort","length","div","className","label","ul","map","column","li","span","header","describeColumn","p","variant","skipped","some","update","index","at","suggest","ready","response","fetch","method","credentials","body","JSON","stringify","fileData","format","result","json","ok","text","suggestedText","suggested","disabled","size","type","onClick","source","table","thead","tr","th","scope","tbody","ColumnRow","samples","targets","onChange","next","target","find","relationship","used","Set","filter","other","exported","choose","chosen","candidate","matchBy","defaultMatchBy","createMissing","String","join","td","onValueChange","aria-label","option","has","checked","onCheckedChange","endsWith","toBase64","arrayBuffer","Error","buffer","bytes","Uint8Array","chunk","binary","fromCharCode","subarray","btoa","count"],"mappings":"AAAA;;AAEA,OAAO,eAAe;AAEtB,SACEA,KAAK,EACLC,gBAAgB,EAChBC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,UAAU,EACVC,aAAa,EACbC,WAAW,EACXC,MAAM,QACD,gBAAgB;AACvB,SACEC,UAAU,EACVC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,QACR,sBAAsB;AAE7B,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAuBpD,MAAMC,OAAO;AAEb,MAAMC,YAAY;AAElB,MAAMC,YAAY,CAAC,WAAW,EAAED,WAAW;AAE3C;;;;;CAKC,GACD,OAAO,SAASE,mBAAmB,EAAEC,KAAK,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAEC,QAAQ,EAA2B;IAC/F,MAAMC,YAAYF,QAAQD,MAAMI,IAAI;IACpC,MAAM,EAAEC,MAAM,EAAE,GAAGjB;IACnB,MAAM,EAAEkB,EAAE,EAAEC,gBAAgBC,WAAW,EAAE,GAAGnB;IAC5C,MAAM,EAAEoB,KAAK,EAAEC,QAAQ,EAAE,GAAGpB,SAAiC;QAAEW,MAAME;IAAU;IAC/E,MAAM,EAAEM,OAAOF,cAAc,EAAE,GAAGjB,SAAiB;QAAEW,MAAM;IAAiB;IAC5E,MAAMU,OAAOpB,cAAc,CAAC,CAACqB,OAAO,GAAKA,QAAQD,MAAMF;IACvD,MAAM,CAACI,MAAMC,QAAQ,GAAGpB,SAAoB;QAAEqB,QAAQ;IAAO;IAC7D,MAAM,CAACC,YAAYC,cAAc,G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AAOI,KAAKH;AACd;AAEA,SAASxE,eAAe,EAAEpD,KAAK,EAAEwG,OAAO,EAAEE,aAAa,EAAgB;IACrE,IAAI,CAAC1G,OAAO,OAAO;IAEnB,IAAI,CAACwG,SAAS,OAAOxG;IAErB,OAAO,GAAGA,MAAM,aAAa,EAAEwG,UAAUE,gBAAgB,qBAAqB,IAAI;AACpF;AAEA,SAAS/B,cAAcqD,KAAa;IAClC,IAAIA,UAAU,GAAG,OAAO;IAExB,OAAO,CAAC,UAAU,EAAEA,MAAM,CAAC,EAAEA,UAAU,IAAI,WAAW,UAAU,8BAA8B,CAAC;AACjG;AAEA,SAASxF,UAAUH,KAAc;IAC/B,OAAOA,iBAAiBkF,QAAQlF,MAAME,OAAO,GAAGoE,OAAOtE;AACzD","file":"ImportColumnsField.js"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
@layer frogbot {
|
|
2
|
+
.import-columns {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: 0.75rem;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.import-columns__heading {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: space-between;
|
|
12
|
+
gap: 1rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.import-columns__description {
|
|
16
|
+
margin: 0;
|
|
17
|
+
color: var(--color-text-secondary);
|
|
18
|
+
font-size: var(--fb-text-sm);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.import-columns__table {
|
|
22
|
+
width: 100%;
|
|
23
|
+
border-collapse: collapse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.import-columns__table th,
|
|
27
|
+
.import-columns__table td {
|
|
28
|
+
padding: 0.5rem 0.75rem 0.5rem 0;
|
|
29
|
+
border-bottom: 1px solid var(--color-border);
|
|
30
|
+
text-align: left;
|
|
31
|
+
vertical-align: middle;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.import-columns__table thead th {
|
|
35
|
+
color: var(--color-text-secondary);
|
|
36
|
+
font-size: var(--fb-text-sm);
|
|
37
|
+
font-weight: 500;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.import-columns__table tbody th {
|
|
41
|
+
font-weight: 400;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.import-columns__header {
|
|
45
|
+
display: block;
|
|
46
|
+
color: var(--color-text);
|
|
47
|
+
font-weight: 500;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.import-columns__samples {
|
|
51
|
+
display: block;
|
|
52
|
+
max-width: 18rem;
|
|
53
|
+
overflow: hidden;
|
|
54
|
+
color: var(--color-text-secondary);
|
|
55
|
+
font-size: var(--fb-text-sm);
|
|
56
|
+
text-overflow: ellipsis;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.import-columns__summary {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
gap: 0.25rem;
|
|
64
|
+
margin: 0;
|
|
65
|
+
padding: 0;
|
|
66
|
+
list-style: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.import-columns__summary .import-columns__header {
|
|
70
|
+
display: inline;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":["ImportColumnsField"],"mappings":"AAAA,SAASA,kBAAkB,QAAsC,iCAAiC","file":"client.js"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
|
+
/** One file column and the field it imports into. */
|
|
3
|
+
export type ImportColumn = {
|
|
4
|
+
/** The header in the file, exactly as written. */
|
|
5
|
+
header: string;
|
|
6
|
+
/** The target field's path, such as `name` or `address.city`, or `null` to skip the column. */
|
|
7
|
+
field: string | null;
|
|
8
|
+
/** For a relationship, the related collection's field the cell is matched against. */
|
|
9
|
+
matchBy?: string;
|
|
10
|
+
/** For a relationship, create the related record when no record matches. */
|
|
11
|
+
createMissing?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** The column mapping stored on an import. */
|
|
14
|
+
export type ImportColumnMap = {
|
|
15
|
+
headers: string[];
|
|
16
|
+
columns: ImportColumn[];
|
|
17
|
+
};
|
|
18
|
+
export declare const columnMapFieldName = "columnMap";
|
|
19
|
+
export declare const headerKeyFieldName = "headerKey";
|
|
20
|
+
/** Identifies a header set regardless of order, so a later import can reuse its mapping. */
|
|
21
|
+
export declare function toHeaderKey(headers: string[]): string;
|
|
22
|
+
/** Reads a stored or submitted mapping, or `undefined` when there is none or it is malformed. */
|
|
23
|
+
export declare function readColumnMap(value: unknown): ImportColumnMap | undefined;
|
|
24
|
+
/** Props the Columns field component receives from the config. */
|
|
25
|
+
export type ImportColumnsFieldClientProps = {
|
|
26
|
+
/** Shows **Suggest with AI**; set when an AI model is configured. */
|
|
27
|
+
ai: boolean;
|
|
28
|
+
};
|
|
29
|
+
export declare const importColumnsFieldPath = "@frogbotai/plugin-import-export/client#ImportColumnsField";
|
|
30
|
+
/** The `columnMap` field, edited by the Columns component, and its hidden `headerKey`. */
|
|
31
|
+
export declare function columnMapFields({ ai }: ImportColumnsFieldClientProps): Field[];
|
|
32
|
+
//# sourceMappingURL=columnMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnMap.d.ts","sourceRoot":"","sources":["../../src/columns/columnMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,SAAS,CAAC;AAEhD,qDAAqD;AACrD,MAAM,MAAM,YAAY,GAAG;IACzB,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,+FAA+F;IAC/F,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,8CAA8C;AAC9C,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAErD;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAYzE;AAQD,kEAAkE;AAClE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,qEAAqE;IACrE,EAAE,EAAE,OAAO,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,sBAAsB,8DAA8D,CAAC;AAElG,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,6BAA6B,GAAG,KAAK,EAAE,CAuB9E"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export const columnMapFieldName = 'columnMap';
|
|
2
|
+
export const headerKeyFieldName = 'headerKey';
|
|
3
|
+
/** Identifies a header set regardless of order, so a later import can reuse its mapping. */ export function toHeaderKey(headers) {
|
|
4
|
+
return JSON.stringify(headers.map((header)=>header.trim()).sort());
|
|
5
|
+
}
|
|
6
|
+
/** Reads a stored or submitted mapping, or `undefined` when there is none or it is malformed. */ export function readColumnMap(value) {
|
|
7
|
+
const parsed = typeof value === 'string' ? parseJSON(value) : value;
|
|
8
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.columns)) return undefined;
|
|
9
|
+
const columns = parsed.columns.filter(isColumn);
|
|
10
|
+
const headers = Array.isArray(parsed.headers) ? parsed.headers.filter((header)=>typeof header === 'string') : columns.map(({ header })=>header);
|
|
11
|
+
return {
|
|
12
|
+
headers,
|
|
13
|
+
columns
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const writeHeaderKey = ({ siblingData })=>{
|
|
17
|
+
const columnMap = readColumnMap(siblingData[columnMapFieldName]);
|
|
18
|
+
return columnMap ? toHeaderKey(columnMap.headers) : undefined;
|
|
19
|
+
};
|
|
20
|
+
export const importColumnsFieldPath = '@frogbotai/plugin-import-export/client#ImportColumnsField';
|
|
21
|
+
/** The `columnMap` field, edited by the Columns component, and its hidden `headerKey`. */ export function columnMapFields({ ai }) {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
name: columnMapFieldName,
|
|
25
|
+
type: 'json',
|
|
26
|
+
label: 'Columns',
|
|
27
|
+
admin: {
|
|
28
|
+
components: {
|
|
29
|
+
Field: {
|
|
30
|
+
path: importColumnsFieldPath,
|
|
31
|
+
clientProps: {
|
|
32
|
+
ai
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: headerKeyFieldName,
|
|
40
|
+
type: 'text',
|
|
41
|
+
index: true,
|
|
42
|
+
admin: {
|
|
43
|
+
hidden: true
|
|
44
|
+
},
|
|
45
|
+
hooks: {
|
|
46
|
+
beforeChange: [
|
|
47
|
+
writeHeaderKey
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
function isColumn(value) {
|
|
54
|
+
return isRecord(value) && typeof value.header === 'string' && (value.field === null || typeof value.field === 'string') && (value.matchBy === undefined || typeof value.matchBy === 'string') && (value.createMissing === undefined || typeof value.createMissing === 'boolean');
|
|
55
|
+
}
|
|
56
|
+
function isRecord(value) {
|
|
57
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
function parseJSON(value) {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(value);
|
|
62
|
+
} catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=columnMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/columns/columnMap.ts"],"names":["columnMapFieldName","headerKeyFieldName","toHeaderKey","headers","JSON","stringify","map","header","trim","sort","readColumnMap","value","parsed","parseJSON","isRecord","Array","isArray","columns","undefined","filter","isColumn","writeHeaderKey","siblingData","columnMap","importColumnsFieldPath","columnMapFields","ai","name","type","label","admin","components","Field","path","clientProps","index","hidden","hooks","beforeChange","field","matchBy","createMissing","parse"],"mappings":"AAoBA,OAAO,MAAMA,qBAAqB,YAAY;AAE9C,OAAO,MAAMC,qBAAqB,YAAY;AAE9C,0FAA0F,GAC1F,OAAO,SAASC,YAAYC,OAAiB;IAC3C,OAAOC,KAAKC,SAAS,CAACF,QAAQG,GAAG,CAAC,CAACC,SAAWA,OAAOC,IAAI,IAAIC,IAAI;AACnE;AAEA,+FAA+F,GAC/F,OAAO,SAASC,cAAcC,KAAc;IAC1C,MAAMC,SAAS,OAAOD,UAAU,WAAWE,UAAUF,SAASA;IAE9D,IAAI,CAACG,SAASF,WAAW,CAACG,MAAMC,OAAO,CAACJ,OAAOK,OAAO,GAAG,OAAOC;IAEhE,MAAMD,UAAUL,OAAOK,OAAO,CAACE,MAAM,CAACC;IAEtC,MAAMjB,UAAUY,MAAMC,OAAO,CAACJ,OAAOT,OAAO,IACxCS,OAAOT,OAAO,CAACgB,MAAM,CAAC,CAACZ,SAA6B,OAAOA,WAAW,YACtEU,QAAQX,GAAG,CAAC,CAAC,EAAEC,MAAM,EAAE,GAAKA;IAEhC,OAAO;QAAEJ;QAASc;IAAQ;AAC5B;AAEA,MAAMI,iBAA4B,CAAC,EAAEC,WAAW,EAAE;IAChD,MAAMC,YAAYb,cAAcY,WAAW,CAACtB,mBAAmB;IAE/D,OAAOuB,YAAYrB,YAAYqB,UAAUpB,OAAO,IAAIe;AACtD;AAQA,OAAO,MAAMM,yBAAyB,4DAA4D;AAElG,wFAAwF,GACxF,OAAO,SAASC,gBAAgB,EAAEC,EAAE,EAAiC;IACnE,OAAO;QACL;YACEC,MAAM3B;YACN4B,MAAM;YACNC,OAAO;YACPC,OAAO;gBACLC,YAAY;oBACVC,OAAO;wBACLC,MAAMT;wBACNU,aAAa;4BAAER;wBAAG;oBACpB;gBACF;YACF;QACF;QACA;YACEC,MAAM1B;YACN2B,MAAM;YACNO,OAAO;YACPL,OAAO;gBAAEM,QAAQ;YAAK;YACtBC,OAAO;gBAAEC,cAAc;oBAACjB;iBAAe;YAAC;QAC1C;KACD;AACH;AAEA,SAASD,SAAST,KAAc;IAC9B,OACEG,SAASH,UACT,OAAOA,MAAMJ,MAAM,KAAK,YACvBI,CAAAA,MAAM4B,KAAK,KAAK,QAAQ,OAAO5B,MAAM4B,KAAK,KAAK,QAAO,KACtD5B,CAAAA,MAAM6B,OAAO,KAAKtB,aAAa,OAAOP,MAAM6B,OAAO,KAAK,QAAO,KAC/D7B,CAAAA,MAAM8B,aAAa,KAAKvB,aAAa,OAAOP,MAAM8B,aAAa,KAAK,SAAQ;AAEjF;AAEA,SAAS3B,SAASH,KAAc;IAC9B,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACI,MAAMC,OAAO,CAACL;AACvE;AAEA,SAASE,UAAUF,KAAa;IAC9B,IAAI;QACF,OAAOP,KAAKsC,KAAK,CAAC/B;IACpB,EAAE,OAAM;QACN,OAAOO;IACT;AACF","file":"columnMap.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ImportBeforeHook } from '@payloadcms/plugin-import-export/types';
|
|
2
|
+
import type { FlattenedField } from 'payload';
|
|
3
|
+
/** The row key that carries a lookup failure to the row's create or update, which then fails. */
|
|
4
|
+
export declare const importErrorKey = "__frogbotImportError";
|
|
5
|
+
/**
|
|
6
|
+
* Builds the batch `hooks.before` that rewrites rows from the import's stored `columnMap`: renamed
|
|
7
|
+
* columns are read from the raw row, relationship cells are linked by their match-by field, and
|
|
8
|
+
* unmapped columns are dropped. Without a `columnMap` the rows pass through untouched.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createColumnRewrite(collectionSlug: string): ImportBeforeHook;
|
|
11
|
+
/** Finds a top-level, group or named-tab field by its dotted path. */
|
|
12
|
+
export declare function findField(fields: FlattenedField[], path: string): FlattenedField | undefined;
|
|
13
|
+
//# sourceMappingURL=rewrite.d.ts.map
|