@udecode/plate-selection
Advanced tools
Comparing version 34.0.0 to 34.1.0
@@ -8,2 +8,3 @@ import * as zustand_x from 'zustand-x'; | ||
import * as _udecode_plate_common from '@udecode/plate-common'; | ||
import { PlateEditor as PlateEditor$1 } from '@udecode/plate-common'; | ||
import * as React$1 from 'react'; | ||
@@ -202,6 +203,2 @@ import React__default from 'react'; | ||
/** | ||
* The show action has depend on blockSelection store a lot. should I move this | ||
* action into blockSelection store? | ||
*/ | ||
declare const blockContextMenuStore: zustand_x.StoreApi<"contextMenu", { | ||
@@ -358,3 +355,2 @@ action: { | ||
} | null) => void; | ||
setMarkSelection: (mark: string, value: string) => void; | ||
}; | ||
@@ -388,2 +384,4 @@ declare const useBlockContextMenu: ({ editor, }: ReturnType<typeof useBlockContextMenuState>) => { | ||
declare const openContextMenu: (editor: PlateEditor$1, e: any, selectedId?: string) => true | undefined; | ||
declare const pasteSelectedBlocks: <V extends Value>(editor: PlateEditor<V>, e: ClipboardEvent) => void; | ||
@@ -394,2 +392,2 @@ | ||
export { ACTION_COPY, ACTION_DELETE, BlockSelectable, type BlockSelectableOptions, BlockSelection, BlockSelectionArea, type BlockSelectionAreaProps, type BlockSelectionPlugin, BlockStartArea, type BlockStartAreaState, type CommandItem, KEY_BLOCK_SELECTION, type Menu, SelectionArea, type SelectionAreaProps, blockContextMenuActions, blockContextMenuSelectors, blockContextMenuStore, blockSelectionActions, blockSelectionSelectors, blockSelectionStore, copySelectedBlocks, createBlockSelectionPlugin, extractSelectableId, extractSelectableIds, getAllSelectableDomNode, getSelectedBlocks, getSelectedDomNode, isBlockSelected, onCloseBlockSelection, onKeyDownSelection, pasteSelectedBlocks, selectInsertedBlocks, useBlockContextMenu, useBlockContextMenuSelectors, useBlockContextMenuState, useBlockMenuItems, useBlockMenuItemsState, useBlockSelectable, useBlockSelectableState, useBlockSelected, useBlockSelectionArea, useBlockSelectionSelectors, useBlockStartArea, useHasBlockSelected, useHooksBlockSelection, withSelection }; | ||
export { ACTION_COPY, ACTION_DELETE, BlockSelectable, type BlockSelectableOptions, BlockSelection, BlockSelectionArea, type BlockSelectionAreaProps, type BlockSelectionPlugin, BlockStartArea, type BlockStartAreaState, type CommandItem, KEY_BLOCK_SELECTION, type Menu, SelectionArea, type SelectionAreaProps, blockContextMenuActions, blockContextMenuSelectors, blockContextMenuStore, blockSelectionActions, blockSelectionSelectors, blockSelectionStore, copySelectedBlocks, createBlockSelectionPlugin, extractSelectableId, extractSelectableIds, getAllSelectableDomNode, getSelectedBlocks, getSelectedDomNode, isBlockSelected, onCloseBlockSelection, onKeyDownSelection, openContextMenu, pasteSelectedBlocks, selectInsertedBlocks, useBlockContextMenu, useBlockContextMenuSelectors, useBlockContextMenuState, useBlockMenuItems, useBlockMenuItemsState, useBlockSelectable, useBlockSelectableState, useBlockSelected, useBlockSelectionArea, useBlockSelectionSelectors, useBlockStartArea, useHasBlockSelected, useHooksBlockSelection, withSelection }; |
@@ -83,2 +83,3 @@ "use strict"; | ||
onKeyDownSelection: () => onKeyDownSelection, | ||
openContextMenu: () => openContextMenu, | ||
pasteSelectedBlocks: () => pasteSelectedBlocks, | ||
@@ -223,19 +224,2 @@ selectInsertedBlocks: () => selectInsertedBlocks, | ||
const selectedBlocks = getSelectedBlocks(editor); | ||
const setMarkSelection = (0, import_react.useCallback)( | ||
(mark, value) => { | ||
selectedBlocks.forEach(([node, nodePath]) => { | ||
const _textEntry = (0, import_plate_common.getNodeTexts)(node); | ||
const textEntry = Array.from(_textEntry); | ||
textEntry.forEach(([_, textpath]) => { | ||
(0, import_plate_common.setNodes)( | ||
editor, | ||
{ [mark]: value }, | ||
{ at: [...nodePath, ...textpath] } | ||
); | ||
}); | ||
}); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[action] | ||
); | ||
return { | ||
@@ -247,4 +231,3 @@ action, | ||
selectedIds, | ||
setAction, | ||
setMarkSelection | ||
setAction | ||
}; | ||
@@ -293,4 +276,17 @@ }; | ||
// src/utils/openContextMenu.ts | ||
var import_plate_common3 = require("@udecode/plate-common"); | ||
var openContextMenu = (editor, e, selectedId) => { | ||
var _a; | ||
const id = selectedId != null ? selectedId : (_a = (0, import_plate_common3.getAncestorNode)(editor)) == null ? void 0 : _a[0].id; | ||
if (!id) | ||
return; | ||
blockSelectionActions.addSelectedRow(id); | ||
blockContextMenuActions.show(editor.id, e); | ||
(0, import_plate_common3.collapseSelection)(editor); | ||
return true; | ||
}; | ||
// src/utils/pasteSelectedBlocks.ts | ||
var import_plate_common3 = require("@udecode/plate-common"); | ||
var import_plate_common4 = require("@udecode/plate-common"); | ||
var import_server5 = require("@udecode/plate-common/server"); | ||
@@ -320,3 +316,3 @@ var import_slate = require("slate"); | ||
const [node, path] = entry; | ||
(0, import_plate_common3.focusEditor)(editor, (0, import_server5.getStartPoint)(editor, path)); | ||
(0, import_plate_common4.focusEditor)(editor, (0, import_server5.getStartPoint)(editor, path)); | ||
if (!(0, import_server5.isElementEmpty)(editor, node)) { | ||
@@ -329,3 +325,3 @@ const at = import_slate.Path.next(path); | ||
} | ||
(0, import_plate_common3.insertData)(editor, e.clipboardData); | ||
(0, import_plate_common4.insertData)(editor, e.clipboardData); | ||
(0, import_server5.deselect)(editor); | ||
@@ -393,3 +389,3 @@ selectInsertedBlocks(editor); | ||
var import_react2 = __toESM(require("react")); | ||
var import_plate_common4 = require("@udecode/plate-common"); | ||
var import_plate_common5 = require("@udecode/plate-common"); | ||
var import_server7 = require("@udecode/plate-common/server"); | ||
@@ -402,6 +398,6 @@ var import_slate2 = require("slate"); | ||
}) => { | ||
const editor = (0, import_plate_common4.useEditorRef)(); | ||
const editor = (0, import_plate_common5.useEditorRef)(); | ||
const ref = (0, import_react2.useRef)(null); | ||
const path = import_react2.default.useMemo( | ||
() => (0, import_plate_common4.findNodePath)(editor, element), | ||
() => (0, import_plate_common5.findNodePath)(editor, element), | ||
[editor, element] | ||
@@ -495,3 +491,3 @@ ); | ||
var import_react4 = __toESM(require("react")); | ||
var import_plate_common5 = require("@udecode/plate-common"); | ||
var import_plate_common6 = require("@udecode/plate-common"); | ||
@@ -560,5 +556,5 @@ // src/components/SelectionArea.tsx | ||
var useBlockSelectionArea = (props) => { | ||
const editor = (0, import_plate_common5.useEditorRef)(); | ||
const editor = (0, import_plate_common6.useEditorRef)(); | ||
const onStart = ({ event, selection }) => { | ||
(0, import_plate_common5.deselectEditor)(editor); | ||
(0, import_plate_common6.deselectEditor)(editor); | ||
if (!(event == null ? void 0 : event.shiftKey)) { | ||
@@ -602,3 +598,3 @@ selection.clearSelection(); | ||
// src/components/BlockStartArea.tsx | ||
var import_plate_common6 = require("@udecode/plate-common"); | ||
var import_plate_common7 = require("@udecode/plate-common"); | ||
var useBlockStartArea = ({ | ||
@@ -630,3 +626,3 @@ placement = "left", | ||
}; | ||
var BlockStartArea = (0, import_plate_common6.createPrimitiveComponent)("div")({ | ||
var BlockStartArea = (0, import_plate_common7.createPrimitiveComponent)("div")({ | ||
propsHook: useBlockStartArea | ||
@@ -701,3 +697,3 @@ }); | ||
var import_react6 = __toESM(require("react")); | ||
var import_plate_common7 = require("@udecode/plate-common"); | ||
var import_plate_common8 = require("@udecode/plate-common"); | ||
var import_server9 = require("@udecode/plate-common/server"); | ||
@@ -714,3 +710,3 @@ var useHooksBlockSelection = (editor, { options }) => { | ||
} | ||
const isReadonly = (0, import_plate_common7.isEditorReadOnly)(editor); | ||
const isReadonly = (0, import_plate_common8.isEditorReadOnly)(editor); | ||
if (isSelecting) { | ||
@@ -746,6 +742,5 @@ const input = document.createElement("input"); | ||
}); | ||
console.log(entry); | ||
if (entry) { | ||
const [, path] = entry; | ||
(0, import_plate_common7.focusEditor)(editor, (0, import_server9.getEndPoint)(editor, path)); | ||
(0, import_plate_common8.focusEditor)(editor, (0, import_server9.getEndPoint)(editor, path)); | ||
e.preventDefault(); | ||
@@ -800,3 +795,3 @@ } | ||
}); | ||
(0, import_plate_common7.focusEditor)(editor); | ||
(0, import_plate_common8.focusEditor)(editor); | ||
} | ||
@@ -828,5 +823,8 @@ } | ||
onChange: onCloseBlockSelection, | ||
// onFocus: onCloseBlockSelection, | ||
onKeyDown: onKeyDownSelection, | ||
onMouseDown: () => (e) => { | ||
onMouseDown: (editor) => (e) => { | ||
if (e.button === 0 && blockContextMenuSelectors.isOpen(editor.id)) { | ||
e.preventDefault(); | ||
blockContextMenuActions.hide(); | ||
} | ||
if (e.button === 2) | ||
@@ -932,2 +930,3 @@ e.preventDefault(); | ||
onKeyDownSelection, | ||
openContextMenu, | ||
pasteSelectedBlocks, | ||
@@ -934,0 +933,0 @@ selectInsertedBlocks, |
{ | ||
"name": "@udecode/plate-selection", | ||
"version": "34.0.0", | ||
"version": "34.1.0", | ||
"description": "Plate plugin to add a visual way of selecting blocks", | ||
@@ -49,3 +49,3 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"@udecode/plate-common": ">=34.0.0", | ||
"@udecode/plate-common": ">=34.0.5", | ||
"react": ">=16.8.0", | ||
@@ -52,0 +52,0 @@ "react-dom": ">=16.8.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187962
2134