|
42 | 42 | import { rotate, rotateTo } from "@/form/components/fields/upload/util/rotate"; |
43 | 43 | import { createThumbnail } from "@/form/components/fields/upload/util/thumbnail"; |
44 | 44 | import { useFieldContainerData } from "@/form/useFieldContainerData"; |
| 45 | + import { useParentEditor } from "@/form/components/fields/editor/useParentEditor"; |
| 46 | + import { useParentListField } from "@/form/components/fields/list/useParentListField"; |
45 | 47 |
|
46 | 48 | const props = defineProps<FormFieldProps<FormUploadFieldData> & { |
47 | | - editorField?: FormEditorFieldData, |
48 | 49 | asEditorEmbed?: boolean, |
49 | 50 | legend?: string, |
50 | 51 | dropdownEditLabel?: string, |
|
68 | 69 | (e: 'edit', event: CustomEvent): void |
69 | 70 | }>(); |
70 | 71 | const form = useParentForm(); |
| 72 | + const parentEditor = useParentEditor(); |
| 73 | + const parentListField = useParentListField(); |
71 | 74 | const transformedImg = ref<string>(); |
72 | 75 | const persistedEditableImg = ref<string>(); |
73 | 76 | const playablePreviewUrl = ref<string>(); |
|
76 | 79 | return props.value && canTransform(props.value.name, props.value.mime_type) && !props.hasError |
77 | 80 | || !!props.dropdownEditLabel; |
78 | 81 | }); |
| 82 | + const fieldContainerData = useFieldContainerData(form); |
| 83 | + const uploadEndpoint = computed(() => { |
| 84 | + // we check form equality because the field may be in an editor embed |
| 85 | + // so parentEditor can be the embed parent editor and not an embed form field |
| 86 | + let uploadFieldKey = parentEditor && parentEditor.form === form |
| 87 | + ? parentEditor.props.field.key |
| 88 | + : props.field.key; |
| 89 | + if(parentListField && parentListField.form === form) { |
| 90 | + uploadFieldKey = `${parentListField.props.field.key}.${uploadFieldKey}`; |
| 91 | + } |
| 92 | + return route('code16.sharp.api.form.upload', { |
| 93 | + entityKey: form.entityKey, |
| 94 | + uploadFieldKey, |
| 95 | + ...fieldContainerData, |
| 96 | + }); |
| 97 | + }); |
79 | 98 | const uppy = new Uppy({ |
80 | 99 | id: props.fieldErrorKey, |
81 | 100 | restrictions: { |
|
95 | 114 | autoProceed: true, |
96 | 115 | }) |
97 | 116 | .use(XHRUpload, { |
98 | | - endpoint: route('code16.sharp.api.form.upload', { |
99 | | - entityKey: form.entityKey, |
100 | | - uploadFieldKey: props.parentListField |
101 | | - ? `${props.parentListField.key}.${props.editorField?.key ?? props.field.key}` |
102 | | - : props.editorField?.key ?? props.field.key, |
103 | | - ...useFieldContainerData(form), |
104 | | - }), |
| 117 | + endpoint: uploadEndpoint.value, |
105 | 118 | fieldName: 'file', |
106 | 119 | headers: { |
107 | 120 | 'Accept': 'application/json', |
|
0 commit comments