Skip to content

Commit

Permalink
Fix disabling images in fields.markdoc and fields.mdx (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Jun 19, 2024
1 parent aa1d092 commit 41679be
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-seahorses-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystatic/core': patch
---

Fix disabling images in `fields.markdoc` and `fields.mdx`
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const Toolbar = memo(function Toolbar(
</Tooltip>
</TooltipTrigger>
)}
<ImageToolbarButton />
{nodes.image && <ImageToolbarButton />}
</EditorToolbarGroup>
</EditorToolbar>
</ToolbarScrollArea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export function getCustomNodeSpecs(
};
} else if (component.kind === 'inline') {
spec = {
group: 'inline inline_component',
group: 'inline',
inline: true,
attrs: {
props: {
Expand Down
5 changes: 2 additions & 3 deletions packages/keystatic/src/form/fields/markdoc/editor/images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function getSrcPrefixForImageBlock(
}

export function imageDropPlugin(schema: EditorSchema) {
if (!schema.nodes.image) return new Plugin({});
const imageType = schema.nodes.image;
return new Plugin({
props: {
Expand Down Expand Up @@ -69,7 +68,7 @@ export function imageDropPlugin(schema: EditorSchema) {
})();
return true;
}
if (file.type.startsWith('image/')) {
if (file.type.startsWith('image/') && imageType) {
(async () => {
const slice = Slice.maxOpen(
Fragment.from(
Expand Down Expand Up @@ -109,7 +108,7 @@ export function imageDropPlugin(schema: EditorSchema) {
})();
return true;
}
if (file.type.startsWith('image/')) {
if (file.type.startsWith('image/') && imageType) {
(async () => {
view.dispatch(
view.state.tr.replaceSelectionWith(
Expand Down
4 changes: 2 additions & 2 deletions packages/keystatic/src/form/fields/markdoc/editor/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export type EditorNodeSpec = NodeSpec &
WithInsertMenuNodeSpec &
WithReactNodeViewSpec;

const inlineContent = `(text | inline_component | hard_break)*`;
const inlineContent = `inline*`;

const levelsMeta = [
{ description: 'Use this for a top level heading', icon: heading1Icon },
Expand Down Expand Up @@ -310,7 +310,7 @@ const nodeSpecs = {
},
image: {
content: '',
group: 'inline inline_component',
group: 'inline',
inline: true,
attrs: {
src: {},
Expand Down

0 comments on commit 41679be

Please sign in to comment.