import React, {useState} from 'react';
import {Node} from '@tiptap/core';
import {NodeViewWrapper, ReactNodeViewRenderer} from '@tiptap/react';
// What each size looks like, as a tiny picture, so it never rests on words alone.
const SIZES = [
['wide', 'Wide', ],
['half', 'Half', [
,
,
]],
['pair', 'Side by side', [
,
,
]],
];
//  or , alone on its line, as
// the server reads it (see Haml::Filters::GrowstuffMarkdown).
const PATTERN = /^!\[([^[\]]*)\]\(photo:(\d+)(?:\/(wide|half|pair))?\)[ \t]*(?:\n|$)/;
const clean = (caption) => String(caption || '').replace(/[[\]\r\n]+/g, ' ').trim();
// The photo in the text, with the controls beside it: caption, size, which
// photo stands for the post, and removing it from the text.
function PhotoFigureView({node, updateAttributes, deleteNode, selected, extension}) {
const {getPhoto, getCardPhotoId, setCardPhoto} = extension.options;
const {photoId, caption, size} = node.attrs;
const photo = getPhoto(photoId);
const [cardPhotoId, setCardPhotoId] = useState(getCardPhotoId());
const isCard = cardPhotoId === photoId;
async function makeCard() {
if (await setCardPhoto(photoId)) setCardPhotoId(photoId);
}
return (
{photo
?
:
Photo {photoId}
}
{caption}
How big in the post
{SIZES.map(([value, label, shapes]) => (
))}
Side by side sits this photo next to the one after it.