From dffc3d72fa2fb2190f400239dbfd230310f54861 Mon Sep 17 00:00:00 2001 From: Nageen Chand Date: Mon, 9 Oct 2023 14:24:13 +0530 Subject: [PATCH] remove default conditoin and update conditions as queryNode return true when query is undefined --- .../lib/plate/demo/plugins/deletePlugin.ts | 11 -------- .../default/example/playground-demo.tsx | 2 -- packages/select/src/withDelete.ts | 26 +++++++------------ .../utils/cleanDocxImageElements.ts | 5 +++- 4 files changed, 13 insertions(+), 31 deletions(-) delete mode 100644 apps/www/src/lib/plate/demo/plugins/deletePlugin.ts diff --git a/apps/www/src/lib/plate/demo/plugins/deletePlugin.ts b/apps/www/src/lib/plate/demo/plugins/deletePlugin.ts deleted file mode 100644 index 7920db2500..0000000000 --- a/apps/www/src/lib/plate/demo/plugins/deletePlugin.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { PlatePlugin } from '@udecode/plate-common'; -import { ELEMENT_PARAGRAPH } from '@udecode/plate-paragraph'; -import { DeletePlugin } from '@udecode/plate-select'; - -export const deletePlugin: Partial> = { - options: { - query: { - allow: [ELEMENT_PARAGRAPH], - }, - }, -}; diff --git a/apps/www/src/registry/default/example/playground-demo.tsx b/apps/www/src/registry/default/example/playground-demo.tsx index 4bf3f49f2f..dc4a55c784 100644 --- a/apps/www/src/registry/default/example/playground-demo.tsx +++ b/apps/www/src/registry/default/example/playground-demo.tsx @@ -92,7 +92,6 @@ import { HTML5Backend } from 'react-dnd-html5-backend'; import { ValueId } from '@/config/customizer-plugins'; import { captionPlugin } from '@/lib/plate/demo/plugins/captionPlugin'; -import { deletePlugin } from '@/lib/plate/demo/plugins/deletePlugin'; import { cn } from '@/lib/utils'; import { settingsStore } from '@/components/context/settings-store'; import { PlaygroundFixedToolbarButtons } from '@/components/plate-ui/playground-fixed-toolbar-buttons'; @@ -221,7 +220,6 @@ export const usePlaygroundPlugins = ({ enabled: !!enabled.selectOnBackspace, }), createDeletePlugin({ - ...deletePlugin, enabled: !!enabled.selectOnBackspace, }), createSingleLinePlugin({ diff --git a/packages/select/src/withDelete.ts b/packages/select/src/withDelete.ts index 5ffc49fcff..bee76837de 100644 --- a/packages/select/src/withDelete.ts +++ b/packages/select/src/withDelete.ts @@ -24,24 +24,16 @@ export const withDelete = < const { deleteForward } = editor; editor.deleteForward = (unit: 'character' | 'word' | 'line' | 'block') => { if (!editor.selection) return; - if (!isSelectionExpanded(editor) && isBlockAboveEmpty(editor)) { - // check when line is empty - const isValidNode = queryNode(getAboveNode(editor), query); - if (query) { - //is query is passed - if (isValidNode) { - // cursor is in query blocks - removeNodes(editor as any); - } else { - //fallback to default behaiour - deleteForward(unit); - } - } else { - // query is not passed, then plugin is active everywhere - removeNodes(editor as any); - } + const isValidNode = queryNode(getAboveNode(editor), query); + if ( + !isSelectionExpanded(editor) && + isBlockAboveEmpty(editor) && + isValidNode + ) { + // Cursor is in query blocks and line is empty + removeNodes(editor as any); } else { - // when line is not empty, fall back to default behavior + // When the line is not empty or other conditions are not met, fall back to default behavior deleteForward(unit); } }; diff --git a/packages/serializer-docx/src/docx-cleaner/utils/cleanDocxImageElements.ts b/packages/serializer-docx/src/docx-cleaner/utils/cleanDocxImageElements.ts index 904f679d5c..5a23399bbb 100644 --- a/packages/serializer-docx/src/docx-cleaner/utils/cleanDocxImageElements.ts +++ b/packages/serializer-docx/src/docx-cleaner/utils/cleanDocxImageElements.ts @@ -30,7 +30,10 @@ export const cleanDocxImageElements = ( const alt = element.getAttribute('alt'); - if (typeof alt === 'string' && validator.isURL(alt, { require_protocol: true })) { + if ( + typeof alt === 'string' && + validator.isURL(alt, { require_protocol: true }) + ) { element.setAttribute('src', alt); return true; }