`paragraph-${props.paragraph.paper_template_filed_
:class="{ 'is-indented': line.indent }"
>
+
+
+
+
+ {{ item.figure.alt }}
+
+
+
`paragraph-${props.paragraph.paper_template_filed_
「(本段暂无内容)」 into a paper puts words there that the paper did
not ask for, and on export they would go with it. The blank body is
the honest rendering of a blank paragraph. -->
+
+
+
@@ -346,6 +407,44 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_
text-align: right;
}
+/* A figure: the picture centred on its own line, its 图注 under it. Sized by its
+ natural width unless the writer asked for `{width=…}` — an experiment figure
+ is usually already cropped to what it should show, and stretching it to the
+ full column would only make the axes bigger. */
+.sentence--figure {
+ display: block;
+ text-indent: 0;
+ text-align: center;
+ margin: 10px 0 6px;
+ white-space: normal;
+}
+
+.figure-image {
+ max-width: 100%;
+ height: auto;
+ border-radius: 4px;
+ cursor: zoom-in;
+ vertical-align: middle;
+}
+
+.figure-caption {
+ display: block;
+ margin-top: 6px;
+ font-size: 13px;
+ line-height: 1.7;
+ color: var(--el-text-color-regular);
+}
+
+/* An image inside a run of text — not a figure, so it sits on the line with the
+ words. Its height is capped because a line of a paragraph is not a place to
+ discover that someone pasted a screenshot. */
+.paragraph-body :deep(.rich-image) {
+ max-width: 100%;
+ max-height: 12em;
+ vertical-align: middle;
+ cursor: zoom-in;
+}
+
/* The fallback when KaTeX cannot read a formula: the source, in red, so it can
be found and fixed instead of silently vanishing. */
.paragraph-body :deep(.math-error) {
diff --git a/frontend/src/components/papers/ParagraphEditDialog.vue b/frontend/src/components/papers/ParagraphEditDialog.vue
index 9d31a84..abe0d38 100644
--- a/frontend/src/components/papers/ParagraphEditDialog.vue
+++ b/frontend/src/components/papers/ParagraphEditDialog.vue
@@ -21,12 +21,21 @@
* The optional 「所属段落」 select moves the whole paragraph to another position,
* appending after whatever that paragraph already holds. That is the manual
* form of what switching the paper's template does by itself.
+ *
+ * 「插入图片」 uploads a picture and appends the sentence that shows it — a
+ * screenshot does not go through the clipboard, and an experiment figure belongs
+ * on its own line with its 图注 under it, which is exactly what a sentence
+ * holding nothing but an image renders as. The row then shows the picture, not
+ * just the path to it, because checking that the right curve went into the right
+ * paragraph is the whole reason one look at the editor is worth more than three
+ * reads of a URL.
*/
import { computed, reactive, ref, watch } from 'vue'
-import { ArrowDown, ArrowUp, Delete, Plus, Refresh } from '@element-plus/icons-vue'
+import { ArrowDown, ArrowUp, Delete, Picture, Plus, Refresh } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { errorMessage } from '@/api/client'
+import { IMAGE_ACCEPT, imageRejection, uploadImage } from '@/api/images'
import {
FORMULA_ALIGN_OPTIONS,
getParagraph,
@@ -37,7 +46,7 @@ import {
type SentenceInput,
} from '@/api/papers'
import { PARAGRAPH_UNSET_LABEL, foldWhitespace } from '@/utils/format'
-import { hasDisplayMath } from '@/utils/math'
+import { hasDisplayMath, imagesOf, type ImageSegment } from '@/utils/rich'
const props = defineProps<{
/** Visibility, used with `v-model`. */
@@ -175,6 +184,71 @@ function removeSentence(key: number): void {
rows.value = rows.value.filter((row) => row.key !== key)
}
+/** The pictures a row shows, so the editor can print them and not just their URLs. */
+function rowImages(row: SentenceDraft): ImageSegment[] {
+ return imagesOf(row.content)
+}
+
+// --- images ---------------------------------------------------------------
+
+/** The hidden file picker the 「插入图片」 button drives. */
+const fileInput = ref(null)
+/** How many uploads are in flight, so the button can say so. */
+const uploading = ref(0)
+
+function pickImage(): void {
+ fileInput.value?.click()
+}
+
+async function onFilePicked(event: Event): Promise {
+ const input = event.target as HTMLInputElement
+ const files = Array.from(input.files ?? [])
+ // Cleared straight away: without it, picking the same file twice in a row
+ // fires no `change` event the second time and the upload looks broken.
+ input.value = ''
+ await insertImages(files)
+}
+
+/** Drop a file anywhere in the dialog to insert it. */
+async function onDrop(event: DragEvent): Promise {
+ const files = Array.from(event.dataTransfer?.files ?? [])
+ if (files.length) await insertImages(files)
+}
+
+/**
+ * Upload each picture and append the sentence that shows it.
+ *
+ * One row per image, with 另起一行 set: a figure on a line of its own is what an
+ * experiment picture is for, and the writer who wants it inline instead is one
+ * text edit away from it.
+ */
+async function insertImages(files: File[]): Promise {
+ for (const file of files) {
+ const rejection = imageRejection(file)
+ if (rejection) {
+ ElMessage.warning(`${file.name}:${rejection}`)
+ continue
+ }
+
+ uploading.value += 1
+ try {
+ const stored = await uploadImage(file)
+ rows.value.push({
+ key: nextKey++,
+ sort: nextSort(),
+ content: stored.markdown,
+ lineBreak: true,
+ align: 'center',
+ citations: [],
+ })
+ } catch (error) {
+ ElMessage.error(errorMessage(error))
+ } finally {
+ uploading.value -= 1
+ }
+ }
+}
+
function addCitation(row: SentenceDraft): void {
row.citations.push({ key: nextKey++, reference_id: null, quote: '' })
}
@@ -307,7 +381,22 @@ async function submit(): Promise {