@mvriu5/payload-ai 1.1.1 → 1.3.2

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 (55) hide show
  1. package/README.md +42 -0
  2. package/dist/components/Icons.d.ts +0 -8
  3. package/dist/components/Icons.js +4 -216
  4. package/dist/components/{ActionToast.d.ts → action-toast/ActionToast.d.ts} +2 -2
  5. package/dist/components/{ActionToast.js → action-toast/ActionToast.js} +27 -35
  6. package/dist/components/{ActionToast.module.css → action-toast/ActionToast.module.css} +0 -79
  7. package/dist/components/ai-input/AIInput.js +433 -0
  8. package/dist/components/{AIInput.module.css → ai-input/AIInput.module.css} +119 -42
  9. package/dist/components/ai-input/badge.d.ts +14 -0
  10. package/dist/components/ai-input/badge.js +85 -0
  11. package/dist/components/{AuditLogList.d.ts → audit-log-list/AuditLogList.d.ts} +4 -8
  12. package/dist/components/{AuditLogList.js → audit-log-list/AuditLogList.js} +49 -21
  13. package/dist/components/{AuditLogList.module.css → audit-log-list/AuditLogList.module.css} +11 -65
  14. package/dist/components/dashboard/Dashboard.d.ts +2 -0
  15. package/dist/components/dashboard/Dashboard.js +15 -0
  16. package/dist/components/dashboard/Dashboard.module.css +13 -0
  17. package/dist/components/{DiffDialog.d.ts → diff-dialog/DiffDialog.d.ts} +2 -2
  18. package/dist/components/{DiffDialog.js → diff-dialog/DiffDialog.js} +200 -189
  19. package/dist/components/{DiffDialog.module.css → diff-dialog/DiffDialog.module.css} +17 -35
  20. package/dist/components/hooks/useAIChatStream.d.ts +39 -0
  21. package/dist/components/hooks/useAIChatStream.js +217 -0
  22. package/dist/components/hooks/useAISettings.js +26 -25
  23. package/dist/components/hooks/useAuditLog.d.ts +11 -0
  24. package/dist/components/hooks/useAuditLog.js +41 -0
  25. package/dist/components/hooks/useDocumentMentionSuggestions.d.ts +1 -1
  26. package/dist/components/hooks/useDocumentMentionSuggestions.js +31 -27
  27. package/dist/components/hooks/useMentions.d.ts +58 -0
  28. package/dist/components/hooks/useMentions.js +276 -0
  29. package/dist/components/hooks/usePluginConfig.d.ts +52 -0
  30. package/dist/components/hooks/usePluginConfig.js +20 -0
  31. package/dist/components/{MentionPopover.d.ts → mention-popover/MentionPopover.d.ts} +2 -4
  32. package/dist/components/{MentionPopover.js → mention-popover/MentionPopover.js} +1 -8
  33. package/dist/components/{MentionPopover.module.css → mention-popover/MentionPopover.module.css} +1 -1
  34. package/dist/exports/client.d.ts +2 -2
  35. package/dist/exports/client.js +2 -2
  36. package/dist/handlers/applyActionHandler.js +341 -112
  37. package/dist/handlers/chatHandler.js +940 -84
  38. package/dist/handlers/mediaUploadHandler.d.ts +7 -0
  39. package/dist/handlers/mediaUploadHandler.js +99 -0
  40. package/dist/handlers/mentionSuggestionHandler.js +16 -14
  41. package/dist/handlers/proposalDiffHandler.js +117 -50
  42. package/dist/index.d.ts +6 -0
  43. package/dist/index.js +39 -7
  44. package/dist/payload/collectionPermissions.js +3 -1
  45. package/dist/payload/logging.d.ts +9 -0
  46. package/dist/payload/logging.js +14 -0
  47. package/dist/payload/normalizeData.d.ts +16 -12
  48. package/dist/payload/normalizeData.js +47 -14
  49. package/dist/payload/proposalData.d.ts +31 -0
  50. package/dist/payload/proposalData.js +578 -0
  51. package/dist/payload/schemaContext.d.ts +3 -7
  52. package/dist/payload/schemaContext.js +147 -66
  53. package/package.json +6 -6
  54. package/dist/components/AIInput.js +0 -747
  55. /package/dist/components/{AIInput.d.ts → ai-input/AIInput.d.ts} +0 -0
@@ -6,7 +6,7 @@ const getNamedFields = (fields)=>{
6
6
  export const isAuthCollection = (collectionConfig)=>{
7
7
  return Boolean(collectionConfig?.auth);
8
8
  };
9
- export const getCollectionFields = (collectionConfig)=>{
9
+ const getCollectionFields = (collectionConfig)=>{
10
10
  const fields = [
11
11
  ...collectionConfig?.fields || []
12
12
  ];
@@ -21,10 +21,36 @@ export const getCollectionFields = (collectionConfig)=>{
21
21
  }
22
22
  return fields;
23
23
  };
24
- const createLexicalText = (value)=>{
24
+ export const hasDrafts = (collectionConfig)=>{
25
+ const versions = collectionConfig?.versions;
26
+ if (!versions || versions === true || !isRecord(versions)) return false;
27
+ return Boolean(versions.drafts);
28
+ };
29
+ export const getSchemaFields = (collectionConfig)=>{
30
+ const fields = getCollectionFields(collectionConfig);
31
+ if (hasDrafts(collectionConfig)) {
32
+ fields.push({
33
+ defaultValue: "draft",
34
+ name: "_status",
35
+ options: [
36
+ "draft",
37
+ "published"
38
+ ],
39
+ required: true,
40
+ type: "select"
41
+ });
42
+ }
43
+ return fields;
44
+ };
45
+ export const createLexicalText = (value)=>{
25
46
  if (isRecord(value) && isRecord(value.root)) return value;
26
47
  const text = Array.isArray(value) ? value.join("\n") : String(value || "");
27
- const lines = text.split("\n").map((line)=>line.trim()).filter(Boolean);
48
+ const lines = text.split("\n").flatMap((line)=>{
49
+ const trimmedLine = line.trim();
50
+ return trimmedLine ? [
51
+ trimmedLine
52
+ ] : [];
53
+ });
28
54
  return {
29
55
  root: {
30
56
  children: (lines.length ? lines : [
@@ -68,7 +94,12 @@ const normalizeArrayValue = (field, value)=>{
68
94
  });
69
95
  };
70
96
  const getOptionValues = (field)=>{
71
- return (field.options || []).map((option)=>typeof option === "string" ? option : option.value).filter((option)=>Boolean(option));
97
+ return (field.options || []).flatMap((option)=>{
98
+ const value = typeof option === "string" ? option : option.value;
99
+ return value ? [
100
+ value
101
+ ] : [];
102
+ });
72
103
  };
73
104
  const normalizeOptionValue = (field, value)=>{
74
105
  const optionValues = getOptionValues(field);
@@ -80,19 +111,21 @@ const normalizeOptionValue = (field, value)=>{
80
111
  };
81
112
  const normalizeBlocksValue = (field, value)=>{
82
113
  if (!Array.isArray(value)) return value;
83
- return value.map((item)=>{
84
- if (!isRecord(item)) return null;
114
+ return value.flatMap((item)=>{
115
+ if (!isRecord(item)) return [];
85
116
  const blockType = typeof item.blockType === "string" ? item.blockType : typeof item.type === "string" ? item.type : typeof item.slug === "string" ? item.slug : null;
86
- if (!blockType) return null;
117
+ if (!blockType) return [];
87
118
  const block = field.blocks?.find((candidate)=>candidate.slug === blockType);
88
- if (!block) return null;
119
+ if (!block) return [];
89
120
  const { blockType: _blockType, type: _type, slug: _slug, ...data } = item;
90
121
  const normalizedBlock = normalizeDataForFields(block.fields || [], data).data;
91
- return {
92
- ...normalizedBlock,
93
- blockType
94
- };
95
- }).filter(Boolean);
122
+ return [
123
+ {
124
+ ...normalizedBlock,
125
+ blockType
126
+ }
127
+ ];
128
+ });
96
129
  };
97
130
  const normalizeFieldValue = (field, value)=>{
98
131
  if (value === undefined) return value;
@@ -188,7 +221,7 @@ export const normalizeDataForFields = (fields, data)=>{
188
221
  droppedFields
189
222
  };
190
223
  };
191
- export const getLocalizedRequiredFallbackData = ({ fields, source, target })=>{
224
+ const getLocalizedRequiredFallbackData = ({ fields, source, target })=>{
192
225
  const fallbackData = {};
193
226
  for (const field of getNamedFields(fields)){
194
227
  const targetValue = target[field.name];
@@ -0,0 +1,31 @@
1
+ import { type LocalizedDataInput } from "./shared.js";
2
+ import { type CollectionConfig, type FieldConfig } from "./normalizeData.js";
3
+ type ProposalMode = "create" | "update";
4
+ export type ProposalValidationIssue = {
5
+ code: "empty_localized_data" | "invalid_array" | "invalid_block_type" | "invalid_blocks" | "invalid_checkbox" | "invalid_container" | "invalid_date" | "invalid_option" | "invalid_relationship" | "missing_required_field" | "non_localized_field_in_secondary_locale" | "unknown_field";
6
+ message: string;
7
+ path: string;
8
+ };
9
+ export type PreparedProposalData = {
10
+ coercedFields: string[];
11
+ data?: Record<string, unknown>;
12
+ issues: ProposalValidationIssue[];
13
+ localizedData?: LocalizedDataInput;
14
+ };
15
+ type PrepareProposalDataArgs = {
16
+ collectionConfig?: CollectionConfig;
17
+ data?: Record<string, unknown>;
18
+ inferenceText?: string;
19
+ label: string;
20
+ localizedData?: LocalizedDataInput;
21
+ mode: ProposalMode;
22
+ };
23
+ export declare const prepareProposalWriteData: ({ collectionConfig, data, inferenceText, label, localizedData, mode }: PrepareProposalDataArgs) => PreparedProposalData;
24
+ export declare const applyLocalizedRequiredFallbackToPreparedData: ({ fallbackSource, fields, preparedData, }: {
25
+ fallbackSource: Record<string, unknown>;
26
+ fields: readonly FieldConfig[];
27
+ preparedData: Record<string, unknown>;
28
+ }) => {
29
+ [x: string]: unknown;
30
+ };
31
+ export {};