From 92bb351b6de18e33a70bf06524edaa80eb6e5d6f Mon Sep 17 00:00:00 2001 From: kudlajz Date: Mon, 26 Feb 2024 19:19:38 +0100 Subject: [PATCH 1/6] Implement GalleryBookmark extension --- .../GalleryBookmarkExtension.tsx | 7 + .../src/extensions/gallery-bookmark/index.ts | 2 + .../lib/createGalleryBookmark.ts | 26 ++++ .../extensions/gallery-bookmark/lib/index.ts | 1 + .../placeholders/PlaceholderNode.ts | 1 + .../placeholders/PlaceholdersExtension.tsx | 31 +++++ .../placeholders/PlaceholdersManager.ts | 4 + .../GalleryBookmarkPlaceholderElement.tsx | 131 ++++++++++++++++++ .../extensions/placeholders/elements/index.ts | 1 + .../removeDisabledPlaceholders.ts | 3 + .../src/modules/editor/Editor.tsx | 13 ++ .../modules/editor/getEnabledExtensions.ts | 13 ++ .../src/modules/editor/menuOptions.tsx | 13 ++ .../src/modules/editor/test-utils.ts | 4 + .../slate-editor/src/modules/editor/types.ts | 1 + .../slate-editor/src/modules/events/types.ts | 11 +- 16 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 packages/slate-editor/src/extensions/gallery-bookmark/GalleryBookmarkExtension.tsx create mode 100644 packages/slate-editor/src/extensions/gallery-bookmark/index.ts create mode 100644 packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts create mode 100644 packages/slate-editor/src/extensions/gallery-bookmark/lib/index.ts create mode 100644 packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx diff --git a/packages/slate-editor/src/extensions/gallery-bookmark/GalleryBookmarkExtension.tsx b/packages/slate-editor/src/extensions/gallery-bookmark/GalleryBookmarkExtension.tsx new file mode 100644 index 000000000..a5c027705 --- /dev/null +++ b/packages/slate-editor/src/extensions/gallery-bookmark/GalleryBookmarkExtension.tsx @@ -0,0 +1,7 @@ +import type { Extension } from '@prezly/slate-commons'; + +export const EXTENSION_ID = 'GalleryBookmarkExtension'; + +export const GalleryBookmarkExtension = (): Extension => ({ + id: EXTENSION_ID, +}); diff --git a/packages/slate-editor/src/extensions/gallery-bookmark/index.ts b/packages/slate-editor/src/extensions/gallery-bookmark/index.ts new file mode 100644 index 000000000..024dd235b --- /dev/null +++ b/packages/slate-editor/src/extensions/gallery-bookmark/index.ts @@ -0,0 +1,2 @@ +export { GalleryBookmarkExtension, EXTENSION_ID } from './GalleryBookmarkExtension'; +export { createGalleryBookmark } from './lib'; diff --git a/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts b/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts new file mode 100644 index 000000000..10a100ecf --- /dev/null +++ b/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts @@ -0,0 +1,26 @@ +import { BookmarkNode } from '@prezly/slate-types'; +import { v4 as uuidV4 } from 'uuid'; + +type RequiredProps = Pick; +type OptionalProps = Omit; + +function withoutExtraAttributes(node: T): BookmarkNode { + const { type, children, layout, new_tab, show_thumbnail, uuid, url, oembed, ...extra } = node; + if (Object.keys(extra).length === 0) { + return node; + } + + return { type, children, layout, new_tab, show_thumbnail, uuid, url, oembed }; +} + +export function createGalleryBookmark(props: RequiredProps & Partial): BookmarkNode { + return withoutExtraAttributes({ + layout: BookmarkNode.Layout.VERTICAL, + new_tab: false, + show_thumbnail: true, + uuid: uuidV4(), + ...props, + children: [{ text: '' }], + type: BookmarkNode.TYPE, + }); +} diff --git a/packages/slate-editor/src/extensions/gallery-bookmark/lib/index.ts b/packages/slate-editor/src/extensions/gallery-bookmark/lib/index.ts new file mode 100644 index 000000000..dba458d9d --- /dev/null +++ b/packages/slate-editor/src/extensions/gallery-bookmark/lib/index.ts @@ -0,0 +1 @@ +export * from './createGalleryBookmark'; diff --git a/packages/slate-editor/src/extensions/placeholders/PlaceholderNode.ts b/packages/slate-editor/src/extensions/placeholders/PlaceholderNode.ts index 6b24fe115..c8fea0ffe 100644 --- a/packages/slate-editor/src/extensions/placeholders/PlaceholderNode.ts +++ b/packages/slate-editor/src/extensions/placeholders/PlaceholderNode.ts @@ -42,6 +42,7 @@ export namespace PlaceholderNode { COVERAGE = 'placeholder:coverage', EMBED = 'placeholder:embed', GALLERY = 'placeholder:gallery', + GALLERY_BOOKMARK = 'placeholder:gallery-bookmark', IMAGE = 'placeholder:image', /** * Media placeholder allows to insert one of multiple types of media (image, video, and maybe embed?) diff --git a/packages/slate-editor/src/extensions/placeholders/PlaceholdersExtension.tsx b/packages/slate-editor/src/extensions/placeholders/PlaceholdersExtension.tsx index f1b32f76a..0ce56cde6 100644 --- a/packages/slate-editor/src/extensions/placeholders/PlaceholdersExtension.tsx +++ b/packages/slate-editor/src/extensions/placeholders/PlaceholdersExtension.tsx @@ -3,6 +3,7 @@ import React from 'react'; import type { Editor } from 'slate'; import { withPastedUrlsUnfurling } from './behaviour'; +import { GalleryBookmarkPlaceholderElement } from './elements'; import { AttachmentPlaceholderElement, ContactPlaceholderElement, @@ -58,6 +59,18 @@ export interface Parameters { >; withEmbedPlaceholders?: false | { fetchOembed: FetchOEmbedFn }; withGalleryPlaceholders?: boolean | { withMediaGalleryTab: WithMediaGalleryTab }; + withGalleryBookmarkPlaceholders?: + | false + | Pick< + GalleryBookmarkPlaceholderElement.Props, + | 'fetchOembed' + | 'getSuggestions' + | 'invalidateSuggestions' + | 'renderAddon' + | 'renderEmpty' + | 'renderSuggestion' + | 'renderSuggestionsFooter' + >; withImagePlaceholders?: | boolean | { withCaptions: boolean; withMediaGalleryTab: WithMediaGalleryTab }; @@ -112,6 +125,7 @@ export function PlaceholdersExtension({ withCoveragePlaceholders = false, withEmbedPlaceholders = false, withGalleryPlaceholders = false, + withGalleryBookmarkPlaceholders = false, withImagePlaceholders = false, withInlineContactPlaceholders = false, withMediaPlaceholders = false, @@ -142,6 +156,7 @@ export function PlaceholdersExtension({ withCoveragePlaceholders: Boolean(withCoveragePlaceholders), withEmbedPlaceholders: Boolean(withEmbedPlaceholders), withGalleryPlaceholders: Boolean(withGalleryPlaceholders), + withGalleryBookmarkPlaceholders: Boolean(withGalleryBookmarkPlaceholders), withImagePlaceholders: Boolean(withImagePlaceholders), withInlineContactPlaceholders: Boolean(withInlineContactPlaceholders), withMediaPlaceholders: Boolean(withMediaPlaceholders), @@ -269,6 +284,22 @@ export function PlaceholdersExtension({ ); } + if ( + withGalleryBookmarkPlaceholders && + isPlaceholderNode(element, PlaceholderNode.Type.GALLERY_BOOKMARK) + ) { + return ( + + {children} + + ); + } if (withMediaPlaceholders && isPlaceholderNode(element, PlaceholderNode.Type.MEDIA)) { const { withMediaGalleryTab = false, withCaptions = false } = withMediaPlaceholders === true ? {} : withMediaPlaceholders; diff --git a/packages/slate-editor/src/extensions/placeholders/PlaceholdersManager.ts b/packages/slate-editor/src/extensions/placeholders/PlaceholdersManager.ts index 5fc719ce7..b99e69d33 100644 --- a/packages/slate-editor/src/extensions/placeholders/PlaceholdersManager.ts +++ b/packages/slate-editor/src/extensions/placeholders/PlaceholdersManager.ts @@ -41,6 +41,10 @@ interface Data { gallery: GalleryNode; operation: 'add' | 'edit'; }; + [Type.GALLERY_BOOKMARK]: { + url: string; + oembed?: OEmbedInfo; // `oembed` is undefined if an error occurred + }; [Type.IMAGE]: { image: ImageNode; operation: 'add' | 'replace' | 'crop'; diff --git a/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx b/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx new file mode 100644 index 000000000..cdf68daa0 --- /dev/null +++ b/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx @@ -0,0 +1,131 @@ +import type { NewsroomGallery } from '@prezly/sdk'; +import type { BookmarkNode } from '@prezly/slate-types'; +import React from 'react'; +import { useSelected, useSlateStatic } from 'slate-react'; + +import { SearchInput } from '#components'; +import { PlaceholderGallery } from '#icons'; +import { useFunction } from '#lib'; + +import { EventsEditor } from '#modules/events'; + +import { createGalleryBookmark } from '../../gallery-bookmark'; +import type { Props as PlaceholderElementProps } from '../components/PlaceholderElement'; +import { + type Props as BaseProps, + SearchInputPlaceholderElement, +} from '../components/SearchInputPlaceholderElement'; +import { replacePlaceholder } from '../lib'; +import type { PlaceholderNode } from '../PlaceholderNode'; +import { PlaceholdersManager, usePlaceholderManagement } from '../PlaceholdersManager'; +import type { FetchOEmbedFn } from '../types'; + +export function GalleryBookmarkPlaceholderElement({ + children, + element, + fetchOembed, + format = 'card', + getSuggestions, + removable, + renderAddon, + renderEmpty, + renderSuggestion, + renderSuggestionsFooter, + ...props +}: GalleryBookmarkPlaceholderElement.Props) { + const editor = useSlateStatic(); + const isSelected = useSelected(); + + const handleTrigger = useFunction(() => { + PlaceholdersManager.activate(element); + }); + + const handleSelect = useFunction(async (uuid: string, { url }: NewsroomGallery) => { + EventsEditor.dispatchEvent(editor, 'gallery-bookmark-placeholder-submitted', { + gallery: { uuid }, + }); + + const loading = fetchOembed(url).then( + (oembed) => ({ oembed, url }), + () => ({ url }), // `oembed` is undefined if an error occurred + ); + + PlaceholdersManager.register(element.type, element.uuid, loading); + PlaceholdersManager.deactivateAll(); + }); + + const handleData = useFunction( + (data: { url: BookmarkNode['url']; oembed?: BookmarkNode['oembed'] }) => { + const { url, oembed } = data; + if (!oembed) { + EventsEditor.dispatchEvent(editor, 'notification', { + children: 'Provided URL does not exist or is not supported.', + type: 'error', + }); + return; + } + replacePlaceholder(editor, element, createGalleryBookmark({ url, oembed }), { + select: isSelected, + }); + }, + ); + + usePlaceholderManagement(element.type, element.uuid, { + onTrigger: handleTrigger, + onResolve: handleData, + }); + + return ( + + {...props} + element={element} + // Core + format={format} + icon={PlaceholderGallery} + title="Click to insert a media gallery bookmark" + description="Add a link to your media gallery" + // Input + getSuggestions={getSuggestions} + renderAddon={renderAddon} + renderEmpty={renderEmpty} + renderSuggestion={renderSuggestion} + renderSuggestions={(props) => ( + + {props.children} + + )} + inputTitle="Media gallery bookmark" + inputDescription="Add a media gallery card to your stories, campaigns and pitches" + inputPlaceholder="Search media galleries" + onSelect={handleSelect} + removable={removable} + > + {children} + + ); +} + +export namespace GalleryBookmarkPlaceholderElement { + export interface Props + extends Omit< + BaseProps, + | 'onSelect' + | 'icon' + | 'title' + | 'description' + | 'inputTitle' + | 'inputDescription' + | 'inputPlaceholder' + | 'renderSuggestions' + >, + Pick { + element: PlaceholderNode; + fetchOembed: FetchOEmbedFn; + renderSuggestionsFooter?: BaseProps['renderSuggestions']; + } +} diff --git a/packages/slate-editor/src/extensions/placeholders/elements/index.ts b/packages/slate-editor/src/extensions/placeholders/elements/index.ts index 104efdafa..69c9f1492 100644 --- a/packages/slate-editor/src/extensions/placeholders/elements/index.ts +++ b/packages/slate-editor/src/extensions/placeholders/elements/index.ts @@ -3,6 +3,7 @@ export { ContactPlaceholderElement } from './ContactPlaceholderElement'; export { CoveragePlaceholderElement } from './CoveragePlaceholderElement'; export { EmbedPlaceholderElement } from './EmbedPlaceholderElement'; export { GalleryPlaceholderElement } from './GalleryPlaceholderElement'; +export { GalleryBookmarkPlaceholderElement } from './GalleryBookmarkPlaceholderElement'; export { ImagePlaceholderElement } from './ImagePlaceholderElement'; export { InlineContactPlaceholderElement } from './InlineContactPlaceholderElement'; export { SocialPostPlaceholderElement } from './SocialPostPlaceholderElement'; diff --git a/packages/slate-editor/src/extensions/placeholders/normalization/removeDisabledPlaceholders.ts b/packages/slate-editor/src/extensions/placeholders/normalization/removeDisabledPlaceholders.ts index d5c6e6dc6..0184752bb 100644 --- a/packages/slate-editor/src/extensions/placeholders/normalization/removeDisabledPlaceholders.ts +++ b/packages/slate-editor/src/extensions/placeholders/normalization/removeDisabledPlaceholders.ts @@ -10,6 +10,7 @@ interface Parameters { withImagePlaceholders: boolean; withInlineContactPlaceholders: boolean; withGalleryPlaceholders: boolean; + withGalleryBookmarkPlaceholders: boolean; withEmbedPlaceholders: boolean; withMediaPlaceholders: boolean; withSocialPostPlaceholders: boolean; @@ -26,6 +27,7 @@ export function removeDisabledPlaceholders({ withImagePlaceholders, withInlineContactPlaceholders, withGalleryPlaceholders, + withGalleryBookmarkPlaceholders, withEmbedPlaceholders, withMediaPlaceholders, withSocialPostPlaceholders, @@ -40,6 +42,7 @@ export function removeDisabledPlaceholders({ [PlaceholderNode.Type.COVERAGE]: withCoveragePlaceholders, [PlaceholderNode.Type.IMAGE]: withImagePlaceholders, [PlaceholderNode.Type.GALLERY]: withGalleryPlaceholders, + [PlaceholderNode.Type.GALLERY_BOOKMARK]: withGalleryBookmarkPlaceholders, [PlaceholderNode.Type.EMBED]: withEmbedPlaceholders, [PlaceholderNode.Type.MEDIA]: withMediaPlaceholders, [PlaceholderNode.Type.SOCIAL_POST]: withSocialPostPlaceholders, diff --git a/packages/slate-editor/src/modules/editor/Editor.tsx b/packages/slate-editor/src/modules/editor/Editor.tsx index 40d0200ce..8b4ee07fe 100644 --- a/packages/slate-editor/src/modules/editor/Editor.tsx +++ b/packages/slate-editor/src/modules/editor/Editor.tsx @@ -93,6 +93,7 @@ export const Editor = forwardRef((props, forwardedRef) = withEntryPointsAroundBlocks = false, withFloatingAddMenu = false, withGalleries = false, + withGalleryBookmarks = false, withHeadings = false, withImages = false, withInlineContacts = false, @@ -152,6 +153,7 @@ export const Editor = forwardRef((props, forwardedRef) = withEmbeds, withFloatingAddMenu, withGalleries, + withGalleryBookmarks, withHeadings, withImages, withInlineContacts, @@ -318,6 +320,7 @@ export const Editor = forwardRef((props, forwardedRef) = withEmbedSocial: Boolean(withEmbeds), withEmbeds: Boolean(withEmbeds), withGalleries: Boolean(withGalleries), + withGalleryBookmarks: Boolean(withGalleryBookmarks), withHeadings, withImages: Boolean(withImages), withParagraphs: true, @@ -680,6 +683,16 @@ export const Editor = forwardRef((props, forwardedRef) = EditorCommands.selectNode(editor, placeholder); return; } + if (action === MenuAction.ADD_GALLERY_BOOKMARK && withGalleryBookmarks) { + const placeholder = insertPlaceholder( + editor, + { type: PlaceholderNode.Type.GALLERY_BOOKMARK }, + true, + ); + PlaceholdersManager.trigger(placeholder); + EditorCommands.selectNode(editor, placeholder); + return; + } if (action === MenuAction.ADD_IMAGE && withImages) { const placeholder = insertPlaceholder( editor, diff --git a/packages/slate-editor/src/modules/editor/getEnabledExtensions.ts b/packages/slate-editor/src/modules/editor/getEnabledExtensions.ts index a771e0f7a..ca35c868b 100644 --- a/packages/slate-editor/src/modules/editor/getEnabledExtensions.ts +++ b/packages/slate-editor/src/modules/editor/getEnabledExtensions.ts @@ -16,6 +16,7 @@ import { FileAttachmentExtension } from '#extensions/file-attachment'; import { FlashNodesExtension } from '#extensions/flash-nodes'; import { FloatingAddMenuExtension } from '#extensions/floating-add-menu'; import { GalleriesExtension } from '#extensions/galleries'; +import { GalleryBookmarkExtension } from '#extensions/gallery-bookmark'; import { HeadingExtension } from '#extensions/heading'; import { HotkeysExtension } from '#extensions/hotkeys'; import { HtmlExtension } from '#extensions/html'; @@ -71,6 +72,7 @@ type Parameters = { | 'withEmbeds' | 'withFloatingAddMenu' | 'withGalleries' + | 'withGalleryBookmarks' | 'withHeadings' | 'withImages' | 'withInlineContacts' @@ -104,6 +106,7 @@ export function* getEnabledExtensions(parameters: Parameters): Generator { @@ -374,6 +381,7 @@ function buildPlaceholdersExtensionConfiguration({ withCoverage, withEmbeds, withGalleries, + withGalleryBookmarks, withImages, withInlineContacts, withPlaceholders, @@ -421,6 +429,11 @@ function buildPlaceholdersExtensionConfiguration({ }, }; } + if (withGalleryBookmarks) { + yield { + withGalleryBookmarkPlaceholders: withGalleryBookmarks, + }; + } if (withInlineContacts) { yield { withInlineContactPlaceholders: withInlineContacts, diff --git a/packages/slate-editor/src/modules/editor/menuOptions.tsx b/packages/slate-editor/src/modules/editor/menuOptions.tsx index adcf31fd0..4cb64a624 100644 --- a/packages/slate-editor/src/modules/editor/menuOptions.tsx +++ b/packages/slate-editor/src/modules/editor/menuOptions.tsx @@ -34,6 +34,7 @@ export enum MenuAction { ADD_PINTEREST = 'add_pinterest', ADD_EMBED_SOCIAL = 'add_embed_social', ADD_GALLERY = 'add_gallery', + ADD_GALLERY_BOOKMARK = 'add_gallery_bookmark', ADD_HEADING_1 = 'add_heading_1', ADD_HEADING_2 = 'add_heading_2', ADD_IMAGE = 'add_image', @@ -65,6 +66,7 @@ interface Params { withEmbeds: boolean; withEmbedSocial: boolean; withGalleries: boolean; + withGalleryBookmarks: boolean; withHeadings: boolean; withImages: boolean; withParagraphs: boolean; @@ -110,6 +112,7 @@ function* generateOptions( withEmbeds, withEmbedSocial, withGalleries, + withGalleryBookmarks, withHeadings, withImages, withParagraphs, @@ -216,6 +219,16 @@ function* generateOptions( }; } + if (withGalleryBookmarks) { + yield { + action: MenuAction.ADD_GALLERY_BOOKMARK, + icon: Icons.ComponentGallery, + group: Group.MEDIA_CONTENT, + text: 'Media gallery bookmark', + description: 'Add a link to your media gallery', + }; + } + if (withVideos) { yield { action: MenuAction.ADD_VIDEO, diff --git a/packages/slate-editor/src/modules/editor/test-utils.ts b/packages/slate-editor/src/modules/editor/test-utils.ts index 337dc66f7..8e3dd727a 100644 --- a/packages/slate-editor/src/modules/editor/test-utils.ts +++ b/packages/slate-editor/src/modules/editor/test-utils.ts @@ -43,6 +43,10 @@ export function getAllExtensions() { }, withFloatingAddMenu: true, withGalleries: {}, + withGalleryBookmarks: { + fetchOembed, + getSuggestions: () => [], + }, withHeadings: true, withImages: { withCaptions: true, diff --git a/packages/slate-editor/src/modules/editor/types.ts b/packages/slate-editor/src/modules/editor/types.ts index 775a1c752..12394cc38 100644 --- a/packages/slate-editor/src/modules/editor/types.ts +++ b/packages/slate-editor/src/modules/editor/types.ts @@ -116,6 +116,7 @@ export interface EditorProps { withEntryPointsAroundBlocks?: boolean; withFloatingAddMenu?: boolean | FloatingAddMenuExtensionConfiguration; withGalleries?: false | GalleriesExtensionConfiguration; + withGalleryBookmarks?: false | PlaceholdersExtensionParameters['withGalleryBookmarkPlaceholders']; withHeadings?: boolean; withImages?: false | ImageExtensionConfiguration; withInlineContacts?: PlaceholdersExtensionParameters['withInlineContactPlaceholders']; diff --git a/packages/slate-editor/src/modules/events/types.ts b/packages/slate-editor/src/modules/events/types.ts index ce2394b79..b93d88aad 100644 --- a/packages/slate-editor/src/modules/events/types.ts +++ b/packages/slate-editor/src/modules/events/types.ts @@ -1,5 +1,11 @@ import type { Listener } from '@prezly/events'; -import type { CoverageEntry, NewsroomContact, OEmbedInfo, Story } from '@prezly/sdk'; +import type { + CoverageEntry, + NewsroomContact, + NewsroomGallery, + OEmbedInfo, + Story, +} from '@prezly/sdk'; import type { Node, TableHeader } from '@prezly/slate-types'; import type { ReactNode } from 'react'; @@ -78,6 +84,9 @@ export type EditorEventMap = { 'gallery-images-shuffled': { imagesCount: number; }; + 'gallery-bookmark-placeholder-submitted': { + gallery: Pick; + }; 'image-added': { description: string; isPasted: boolean; From 9a5e47119c3ab945341d089f5e1f366f57afaf47 Mon Sep 17 00:00:00 2001 From: kudlajz Date: Mon, 26 Feb 2024 19:22:03 +0100 Subject: [PATCH 2/6] Make prettier happy --- packages/slate-editor/src/modules/editor/types.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/slate-editor/src/modules/editor/types.ts b/packages/slate-editor/src/modules/editor/types.ts index 12394cc38..a3e0b7ce1 100644 --- a/packages/slate-editor/src/modules/editor/types.ts +++ b/packages/slate-editor/src/modules/editor/types.ts @@ -116,7 +116,9 @@ export interface EditorProps { withEntryPointsAroundBlocks?: boolean; withFloatingAddMenu?: boolean | FloatingAddMenuExtensionConfiguration; withGalleries?: false | GalleriesExtensionConfiguration; - withGalleryBookmarks?: false | PlaceholdersExtensionParameters['withGalleryBookmarkPlaceholders']; + withGalleryBookmarks?: + | false + | PlaceholdersExtensionParameters['withGalleryBookmarkPlaceholders']; withHeadings?: boolean; withImages?: false | ImageExtensionConfiguration; withInlineContacts?: PlaceholdersExtensionParameters['withInlineContactPlaceholders']; From 5374541782fbe6436423e41e4cfb70162a186918 Mon Sep 17 00:00:00 2001 From: kudlajz Date: Tue, 27 Feb 2024 13:29:00 +0100 Subject: [PATCH 3/6] Remove extra props --- .../lib/createGalleryBookmark.ts | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts b/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts index 10a100ecf..926bebe23 100644 --- a/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts +++ b/packages/slate-editor/src/extensions/gallery-bookmark/lib/createGalleryBookmark.ts @@ -2,25 +2,15 @@ import { BookmarkNode } from '@prezly/slate-types'; import { v4 as uuidV4 } from 'uuid'; type RequiredProps = Pick; -type OptionalProps = Omit; -function withoutExtraAttributes(node: T): BookmarkNode { - const { type, children, layout, new_tab, show_thumbnail, uuid, url, oembed, ...extra } = node; - if (Object.keys(extra).length === 0) { - return node; - } - - return { type, children, layout, new_tab, show_thumbnail, uuid, url, oembed }; -} - -export function createGalleryBookmark(props: RequiredProps & Partial): BookmarkNode { - return withoutExtraAttributes({ +export function createGalleryBookmark(props: RequiredProps): BookmarkNode { + return { + ...props, layout: BookmarkNode.Layout.VERTICAL, - new_tab: false, + new_tab: true, show_thumbnail: true, uuid: uuidV4(), - ...props, children: [{ text: '' }], type: BookmarkNode.TYPE, - }); + }; } From 1a64b39c1e2db143b533f2082a957b89517f3134 Mon Sep 17 00:00:00 2001 From: kudlajz Date: Tue, 27 Feb 2024 13:33:13 +0100 Subject: [PATCH 4/6] Update placeholder --- .../placeholders/elements/GalleryBookmarkPlaceholderElement.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx b/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx index cdf68daa0..822b73a3a 100644 --- a/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx +++ b/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx @@ -101,7 +101,7 @@ export function GalleryBookmarkPlaceholderElement({ )} inputTitle="Media gallery bookmark" inputDescription="Add a media gallery card to your stories, campaigns and pitches" - inputPlaceholder="Search media galleries" + inputPlaceholder="Search for media galleries" onSelect={handleSelect} removable={removable} > From f2ac5e86615915315b4b2b8e704f9c2aa6659858 Mon Sep 17 00:00:00 2001 From: kudlajz Date: Tue, 27 Feb 2024 14:45:07 +0100 Subject: [PATCH 5/6] Make the notification more clear --- .../placeholders/elements/GalleryBookmarkPlaceholderElement.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx b/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx index 822b73a3a..dce7dc62e 100644 --- a/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx +++ b/packages/slate-editor/src/extensions/placeholders/elements/GalleryBookmarkPlaceholderElement.tsx @@ -59,7 +59,7 @@ export function GalleryBookmarkPlaceholderElement({ const { url, oembed } = data; if (!oembed) { EventsEditor.dispatchEvent(editor, 'notification', { - children: 'Provided URL does not exist or is not supported.', + children: 'Selected gallery does not exist or is not supported.', type: 'error', }); return; From b0c55409fe801887750effe6171bc532dfcc4255 Mon Sep 17 00:00:00 2001 From: kudlajz Date: Tue, 27 Feb 2024 15:04:24 +0100 Subject: [PATCH 6/6] v0.104.0-alpha.0 --- lerna.json | 2 +- packages/slate-editor/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index 6fda74cc7..6a9c8ea04 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.103.2-alpha.0" + "version": "0.104.0-alpha.0" } diff --git a/packages/slate-editor/package.json b/packages/slate-editor/package.json index 847aecee2..8aeb9512f 100644 --- a/packages/slate-editor/package.json +++ b/packages/slate-editor/package.json @@ -1,6 +1,6 @@ { "name": "@prezly/slate-editor", - "version": "0.103.2-alpha.0", + "version": "0.104.0-alpha.0", "description": "The Prezly Slate Editor", "license": "MIT", "type": "module",