Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@udecode/plate-selection

Package Overview
Dependencies
Maintainers
3
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udecode/plate-selection - npm Package Compare versions

Comparing version 41.0.8 to 42.0.0

2

dist/index.d.ts

@@ -1,2 +0,2 @@

import { PlateEditor } from '@udecode/plate-common/react';
import { PlateEditor } from '@udecode/plate/react';

@@ -3,0 +3,0 @@ declare const extractSelectableIds: (els: Element[]) => any[];

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {

@@ -48,4 +31,4 @@ for (var name in all)

// src/index.ts
var src_exports = {};
__export(src_exports, {
var index_exports = {};
__export(index_exports, {
extractSelectableId: () => extractSelectableId,

@@ -57,3 +40,3 @@ extractSelectableIds: () => extractSelectableIds,

});
module.exports = __toCommonJS(src_exports);
module.exports = __toCommonJS(index_exports);

@@ -74,7 +57,4 @@ // src/lib/extractSelectableIds.ts

// src/lib/isSelecting.ts
var import_plate_common12 = require("@udecode/plate-common");
// src/react/BlockMenuPlugin.tsx
var import_react = require("@udecode/plate-common/react");
var import_react = require("@udecode/plate/react");
var BLOCK_CONTEXT_MENU_ID = "context";

@@ -112,4 +92,3 @@ var BlockMenuPlugin = (0, import_react.createTPlatePlugin)({

showContextMenu: (blockId, position) => {
var _a;
(_a = editor.getApi({ key: "blockSelection" }).blockSelection) == null ? void 0 : _a.addSelectedRow(blockId);
editor.getApi({ key: "blockSelection" }).blockSelection?.addSelectedRow(blockId);
api.blockMenu.show(BLOCK_CONTEXT_MENU_ID, position);

@@ -130,15 +109,14 @@ }

// src/react/BlockSelectionPlugin.tsx
var import_plate_common11 = require("@udecode/plate-common");
var import_react8 = require("@udecode/plate-common/react");
var import_plate8 = require("@udecode/plate");
var import_react7 = require("@udecode/plate/react");
// src/react/components/BlockSelectionAfterEditable.tsx
var import_react6 = __toESM(require("react"));
var import_react5 = __toESM(require("react"));
var import_react_dom = __toESM(require("react-dom"));
var import_plate_common5 = require("@udecode/plate-common");
var import_react7 = require("@udecode/plate-common/react");
var import_plate4 = require("@udecode/plate");
var import_react6 = require("@udecode/plate/react");
// src/react/hooks/useBlockSelectable.ts
var import_plate_common = require("@udecode/plate-common");
var import_react2 = require("@udecode/plate-common/react");
var import_slate = require("slate");
var import_plate = require("@udecode/plate");
var import_react2 = require("@udecode/plate/react");
var useBlockSelectable = () => {

@@ -148,3 +126,3 @@ const element = (0, import_react2.useElement)();

const { api, editor, getOption, getOptions } = (0, import_react2.useEditorPlugin)(BlockSelectionPlugin);
const id = element == null ? void 0 : element.id;
const id = element?.id;
return {

@@ -154,13 +132,12 @@ props: {

onContextMenu: (event) => {
var _a, _b;
if (!element || !path) return;
if (!element) return;
const { enableContextMenu } = getOptions();
if (!enableContextMenu) return;
if ((_a = editor.selection) == null ? void 0 : _a.focus) {
const nodeEntry = (0, import_plate_common.getAboveNode)(editor);
if (nodeEntry && import_slate.Path.isCommon(path, nodeEntry[1])) {
if (editor.selection?.focus) {
const nodeEntry = editor.api.above();
if (nodeEntry && import_plate.PathApi.isCommon(path, nodeEntry[1])) {
const id2 = nodeEntry[0].id;
const isSelected = getOption("isSelected", id2);
const isOpenAlways = ((_b = event.target.dataset) == null ? void 0 : _b.plateOpenContextMenu) === "true";
if (!isSelected && !(0, import_plate_common.isVoid)(editor, nodeEntry[0]) && !isOpenAlways) {
const isOpenAlways = event.target.dataset?.plateOpenContextMenu === "true";
if (!isSelected && !editor.isVoid(nodeEntry[0]) && !isOpenAlways) {
return event.stopPropagation();

@@ -172,3 +149,3 @@ }

api.blockSelection.addSelectedRow(id, {
clear: !(event == null ? void 0 : event.shiftKey)
clear: !event?.shiftKey
});

@@ -183,18 +160,15 @@ }

var import_react3 = __toESM(require("react"));
var import_react4 = require("@udecode/plate-common/react");
var import_react4 = require("@udecode/plate/react");
// src/internal/EventEmitter.ts
var EventTarget = class {
constructor() {
this._listeners = /* @__PURE__ */ new Map();
// eslint-disable-next-line @typescript-eslint/unbound-method
this.emit = this.dispatchEvent;
// eslint-disable-next-line @typescript-eslint/unbound-method
this.off = this.removeEventListener;
// eslint-disable-next-line @typescript-eslint/unbound-method
this.on = this.addEventListener;
}
_listeners = /* @__PURE__ */ new Map();
// eslint-disable-next-line @typescript-eslint/unbound-method
emit = this.dispatchEvent;
// eslint-disable-next-line @typescript-eslint/unbound-method
off = this.removeEventListener;
// eslint-disable-next-line @typescript-eslint/unbound-method
on = this.addEventListener;
addEventListener(event, cb) {
var _a;
const set = (_a = this._listeners.get(event)) != null ? _a : /* @__PURE__ */ new Set();
const set = this._listeners.get(event) ?? /* @__PURE__ */ new Set();
this._listeners.set(event, set);

@@ -206,5 +180,4 @@ set.add(cb);

dispatchEvent(event, ...data) {
var _a;
let ok = true;
for (const cb of (_a = this._listeners.get(event)) != null ? _a : []) {
for (const cb of this._listeners.get(event) ?? []) {
ok = cb(...data) !== false && ok;

@@ -215,4 +188,3 @@ }

removeEventListener(event, cb) {
var _a;
(_a = this._listeners.get(event)) == null ? void 0 : _a.delete(cb);
this._listeners.get(event)?.delete(cb);
return this;

@@ -252,3 +224,3 @@ }

for (const ev of events) {
el[method](ev, fn, __spreadValues({ capture: false }, options));
el[method](ev, fn, { capture: false, ...options });
}

@@ -262,4 +234,3 @@ }

var simplifyEvent = (evt) => {
var _a, _b;
const { clientX, clientY, target } = (_b = (_a = evt.touches) == null ? void 0 : _a[0]) != null ? _b : evt;
const { clientX, clientY, target } = evt.touches?.[0] ?? evt;
return { target, x: clientX, y: clientY };

@@ -269,3 +240,3 @@ };

// src/internal/utils/intersects.ts
function intersectsScroll(a, b, mode = "touch", container) {
function intersectsScroll(a, b, _ = "touch", container) {
const containerRect = container.getBoundingClientRect();

@@ -350,37 +321,44 @@ const scrollLeft = container.scrollLeft;

var SelectionArea = class extends EventTarget {
// Area element and clipping element
_area;
_areaClientLocation = { x1: 0, x2: 0, y1: 0, y2: 0 };
// Dynamically constructed area rect
_areaLocation = { x1: 0, x2: 0, y1: 0, y2: 0 };
// Caches the position of the selection-area
_areaRect = new DOMRect();
_container;
_containerRect;
_frame;
_initScrollDelta = { x: 0, y: 0 };
_latestElement;
// Options
_options;
// Is getting set on movement.
_scrollAvailable = true;
// The scroll distance of scrollElement (body or html) relative to the initial scroll position
_scrollDelta = { x: 0, y: 0 };
_scrollSpeed = { x: 0, y: 0 };
// If a single click is being performed.
_scrollingActive = false;
_selectables = [];
// Selection store
_selection = {
changed: {
added: [],
// Added elements since last selection
removed: []
// Removed elements since last selection
},
selected: [],
stored: [],
touched: []
};
// It's a single-click until the user dragged the mouse.
_singleClick = true;
wheelTimer = null;
disable = this._bindStartEvents.bind(this, false);
enable = this._bindStartEvents;
constructor(opt) {
var _a, _b, _c, _d, _e;
super();
this._areaClientLocation = { x1: 0, x2: 0, y1: 0, y2: 0 };
// Dynamically constructed area rect
this._areaLocation = { x1: 0, x2: 0, y1: 0, y2: 0 };
// Caches the position of the selection-area
this._areaRect = new DOMRect();
this._initScrollDelta = { x: 0, y: 0 };
// Is getting set on movement.
this._scrollAvailable = true;
// The scroll distance of scrollElement (body or html) relative to the initial scroll position
this._scrollDelta = { x: 0, y: 0 };
this._scrollSpeed = { x: 0, y: 0 };
// If a single click is being performed.
this._scrollingActive = false;
this._selectables = [];
// Selection store
this._selection = {
changed: {
added: [],
// Added elements since last selection
removed: []
// Removed elements since last selection
},
selected: [],
stored: [],
touched: []
};
// It's a single-click until the user dragged the mouse.
this._singleClick = true;
this.wheelTimer = null;
this.disable = this._bindStartEvents.bind(this, false);
this.enable = this._bindStartEvents;
this._options = __spreadProps(__spreadValues({
this._options = {
boundaries: ["html"],

@@ -391,31 +369,33 @@ container: "body",

selectionAreaClass: "selection-area",
startAreas: ["html"]
}, opt), {
behaviour: __spreadProps(__spreadValues({
startAreas: ["html"],
...opt,
behaviour: {
// TODO: not implemented
intersect: "touch",
overlap: "invert",
triggers: [0]
}, opt.behaviour), {
scrolling: __spreadProps(__spreadValues({
triggers: [0],
...opt.behaviour,
scrolling: {
manualSpeed: 750,
speedDivider: 0.7
}, (_a = opt.behaviour) == null ? void 0 : _a.scrolling), {
startScrollMargins: __spreadValues({
speedDivider: 0.7,
...opt.behaviour?.scrolling,
startScrollMargins: {
x: 20,
y: 40
}, (_c = (_b = opt.behaviour) == null ? void 0 : _b.scrolling) == null ? void 0 : _c.startScrollMargins)
}),
startThreshold: ((_d = opt.behaviour) == null ? void 0 : _d.startThreshold) ? typeof opt.behaviour.startThreshold === "number" ? opt.behaviour.startThreshold : __spreadValues({ x: 4, y: 4 }, opt.behaviour.startThreshold) : { x: 4, y: 4 }
}),
features: __spreadProps(__spreadValues({
y: 40,
...opt.behaviour?.scrolling?.startScrollMargins
}
},
startThreshold: opt.behaviour?.startThreshold ? typeof opt.behaviour.startThreshold === "number" ? opt.behaviour.startThreshold : { x: 4, y: 4, ...opt.behaviour.startThreshold } : { x: 4, y: 4 }
},
features: {
range: true,
touch: true
}, opt.features), {
singleTap: __spreadValues({
touch: true,
...opt.features,
singleTap: {
allow: true,
intersect: "native"
}, (_e = opt.features) == null ? void 0 : _e.singleTap)
})
});
intersect: "native",
...opt.features?.singleTap
}
}
};
for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(this))) {

@@ -647,3 +627,2 @@ if (typeof this[key] === "function") {

_onTapStart(evt, silent = false) {
var _a;
const { container, document: document2 } = this._options;

@@ -678,3 +657,3 @@ const { target, x, y } = simplifyEvent(evt);

this._areaClientLocation = { x1: x, x2: 0, y1: y, y2: 0 };
const scrollElement = (_a = document2.scrollingElement) != null ? _a : document2.body;
const scrollElement = document2.scrollingElement ?? document2.body;
this._initScrollDelta = {

@@ -693,3 +672,2 @@ x: scrollElement.scrollLeft,

_onTapStop(evt, silent) {
var _a;
const { document: document2, features } = this._options;

@@ -714,3 +692,3 @@ const { _singleClick } = this;

this._area.remove();
(_a = this._frame) == null ? void 0 : _a.cancel();
this._frame?.cancel();
css(this._area, "display", "none");

@@ -949,3 +927,3 @@ }

import_react3.default.useEffect(() => {
const selection = new SelectionArea(__spreadValues({
const selection = new SelectionArea({
boundaries: `#${editor.uid}`,

@@ -955,9 +933,10 @@ container: `#${editor.uid}`,

selectables: `#${editor.uid} .slate-selectable`,
selectionAreaClass: "slate-selection-area"
}, areaOptions)).on("beforestart", () => {
selectionAreaClass: "slate-selection-area",
...areaOptions
}).on("beforestart", () => {
setOption("isSelecting", false);
}).on("start", ({ event }) => {
setOption("isSelectionAreaVisible", true);
(0, import_react4.deselectEditor)(editor);
if (!(event == null ? void 0 : event.shiftKey)) {
editor.tf.deselect();
if (!event?.shiftKey) {
selection.clearSelection();

@@ -980,3 +959,2 @@ api.blockSelection.resetSelectedIds();

// src/react/utils/copySelectedBlocks.ts
var import_plate_common2 = require("@udecode/plate-common");
var import_copy_to_clipboard = __toESM(require("copy-to-clipboard"));

@@ -993,9 +971,9 @@ var copySelectedBlocks = (editor) => {

const div = document.createElement("div");
(0, import_plate_common2.withoutNormalizing)(editor, () => {
editor.tf.withoutNormalizing(() => {
selectedEntries.forEach(([, path]) => {
(0, import_plate_common2.select)(editor, {
anchor: (0, import_plate_common2.getStartPoint)(editor, path),
focus: (0, import_plate_common2.getEndPoint)(editor, path)
editor.tf.select({
anchor: editor.api.start(path),
focus: editor.api.end(path)
});
editor.setFragmentData(data);
editor.tf.setFragmentData(data);
textPlain += `${data.getData("text/plain")}

@@ -1007,3 +985,3 @@ `;

});
(0, import_plate_common2.deselect)(editor);
editor.tf.deselect();
editor.setOption(BlockSelectionPlugin, "selectedIds", selectedIds);

@@ -1023,13 +1001,11 @@ });

// src/react/utils/pasteSelectedBlocks.ts
var import_plate_common4 = require("@udecode/plate-common");
var import_react5 = require("@udecode/plate-common/react");
var import_slate2 = require("slate");
var import_plate3 = require("@udecode/plate");
// src/react/utils/selectInsertedBlocks.ts
var import_plate_common3 = require("@udecode/plate-common");
var import_plate2 = require("@udecode/plate");
var selectInsertedBlocks = (editor) => {
const { setOption } = (0, import_plate_common3.getEditorPlugin)(editor, BlockSelectionPlugin);
const { setOption } = (0, import_plate2.getEditorPlugin)(editor, BlockSelectionPlugin);
const ids = /* @__PURE__ */ new Set();
editor.operations.forEach((op) => {
if (op.type === "insert_node" && op.node.id && (0, import_plate_common3.isBlock)(editor, op.node)) {
if (op.type === "insert_node" && op.node.id && editor.api.isBlock(op.node)) {
ids.add(op.node.id);

@@ -1045,3 +1021,3 @@ }

var pasteSelectedBlocks = (editor, e) => {
const { api } = (0, import_plate_common4.getEditorPlugin)(editor, BlockSelectionPlugin);
const { api } = (0, import_plate3.getEditorPlugin)(editor, BlockSelectionPlugin);
const entries = api.blockSelection.getNodes();

@@ -1051,6 +1027,6 @@ if (entries.length > 0) {

const [node, path] = entry;
(0, import_react5.focusEditor)(editor, (0, import_plate_common4.getStartPoint)(editor, path));
if (!(0, import_plate_common4.isElementEmpty)(editor, node)) {
const at = import_slate2.Path.next(path);
(0, import_plate_common4.insertNodes)(editor, editor.api.create.block({}, at), {
editor.tf.focus({ at: path, edge: "start" });
if (!editor.api.isEmpty(node)) {
const at = import_plate3.PathApi.next(path);
editor.tf.insertNodes(editor.api.create.block({}, at), {
at,

@@ -1060,4 +1036,4 @@ select: true

}
(0, import_react5.insertData)(editor, e.clipboardData);
(0, import_plate_common4.deselect)(editor);
editor.tf.insertData(e.clipboardData);
editor.tf.deselect();
selectInsertedBlocks(editor);

@@ -1069,10 +1045,10 @@ }

var BlockSelectionAfterEditable = () => {
const editor = (0, import_react7.useEditorRef)();
const { api, getOption, getOptions, setOption, useOption } = (0, import_react7.useEditorPlugin)({ key: "blockSelection" });
const editor = (0, import_react6.useEditorRef)();
const { api, getOption, getOptions, setOption, useOption } = (0, import_react6.useEditorPlugin)({ key: "blockSelection" });
const isSelecting2 = useOption("isSelecting");
const selectedIds = useOption("selectedIds");
useSelectionArea();
const inputRef = import_react6.default.useRef(null);
const [isMounted, setIsMounted] = import_react6.default.useState(false);
import_react6.default.useEffect(() => {
const inputRef = import_react5.default.useRef(null);
const [isMounted, setIsMounted] = import_react5.default.useState(false);
import_react5.default.useEffect(() => {
setIsMounted(true);

@@ -1084,3 +1060,3 @@ setOption("shadowInputRef", inputRef);

}, [setOption]);
import_react6.default.useEffect(() => {
import_react5.default.useEffect(() => {
if (isSelecting2 && inputRef.current) {

@@ -1092,16 +1068,15 @@ inputRef.current.focus({ preventScroll: true });

}, [isSelecting2]);
const handleKeyDown = import_react6.default.useCallback(
const handleKeyDown = import_react5.default.useCallback(
(e) => {
var _a, _b;
const isReadonly = (0, import_react7.isEditorReadOnly)(editor);
(_b = (_a = getOptions()).onKeyDownSelecting) == null ? void 0 : _b.call(_a, e.nativeEvent);
const isReadonly = editor.api.isReadOnly();
getOptions().onKeyDownSelecting?.(e.nativeEvent);
if (!getOptions().isSelecting) return;
if ((0, import_plate_common5.isHotkey)("escape")(e)) {
if ((0, import_plate4.isHotkey)("escape")(e)) {
api.blockSelection.unselect();
}
if ((0, import_plate_common5.isHotkey)("mod+z")(e)) {
if ((0, import_plate4.isHotkey)("mod+z")(e)) {
editor.undo();
selectInsertedBlocks(editor);
}
if ((0, import_plate_common5.isHotkey)("mod+shift+z")(e)) {
if ((0, import_plate4.isHotkey)("mod+shift+z")(e)) {
editor.redo();

@@ -1111,4 +1086,4 @@ selectInsertedBlocks(editor);

if (!getOption("isSelectingSome")) return;
if ((0, import_plate_common5.isHotkey)("enter")(e)) {
const entry = (0, import_plate_common5.findNode)(editor, {
if ((0, import_plate4.isHotkey)("enter")(e)) {
const entry = editor.api.node({
at: [],

@@ -1119,8 +1094,8 @@ match: (n) => n.id && selectedIds.has(n.id)

const [, path] = entry;
(0, import_react7.focusEditor)(editor, (0, import_plate_common5.getEndPoint)(editor, path));
editor.tf.focus({ at: path, edge: "end" });
e.preventDefault();
}
}
if ((0, import_plate_common5.isHotkey)(["backspace", "delete"])(e) && !isReadonly) {
(0, import_plate_common5.removeNodes)(editor, {
if ((0, import_plate4.isHotkey)(["backspace", "delete"])(e) && !isReadonly) {
editor.tf.removeNodes({
at: [],

@@ -1130,24 +1105,24 @@ match: (n) => !!n.id && selectedIds.has(n.id)

}
if ((0, import_plate_common5.isHotkey)("up")(e)) {
if ((0, import_plate4.isHotkey)("up")(e)) {
const firstId = [...selectedIds][0];
const node = (0, import_plate_common5.findNode)(editor, {
const node = editor.api.node({
at: [],
match: (n) => n.id && n.id === firstId
});
const prev = (0, import_plate_common5.getPreviousNode)(editor, {
at: node == null ? void 0 : node[1]
const prev = editor.api.previous({
at: node?.[1]
});
const prevId = prev == null ? void 0 : prev[0].id;
const prevId = prev?.[0].id;
api.blockSelection.addSelectedRow(prevId);
}
if ((0, import_plate_common5.isHotkey)("down")(e)) {
if ((0, import_plate4.isHotkey)("down")(e)) {
const lastId = [...selectedIds].pop();
const node = (0, import_plate_common5.findNode)(editor, {
const node = editor.api.node({
at: [],
match: (n) => n.id && n.id === lastId
});
const next = (0, import_plate_common5.getNextNode)(editor, {
at: node == null ? void 0 : node[1]
const next = editor.api.next({
at: node?.[1]
});
const nextId = next == null ? void 0 : next[0].id;
const nextId = next?.[0].id;
api.blockSelection.addSelectedRow(nextId);

@@ -1158,3 +1133,3 @@ }

);
const handleCopy = import_react6.default.useCallback(
const handleCopy = import_react5.default.useCallback(
(e) => {

@@ -1168,3 +1143,3 @@ e.preventDefault();

);
const handleCut = import_react6.default.useCallback(
const handleCut = import_react5.default.useCallback(
(e) => {

@@ -1174,8 +1149,8 @@ e.preventDefault();

copySelectedBlocks(editor);
if (!(0, import_react7.isEditorReadOnly)(editor)) {
(0, import_plate_common5.removeNodes)(editor, {
if (!editor.api.isReadOnly()) {
editor.tf.removeNodes({
at: [],
match: (n) => selectedIds.has(n.id)
});
(0, import_react7.focusEditor)(editor);
editor.tf.focus();
}

@@ -1186,6 +1161,6 @@ }

);
const handlePaste = import_react6.default.useCallback(
const handlePaste = import_react5.default.useCallback(
(e) => {
e.preventDefault();
if (!(0, import_react7.isEditorReadOnly)(editor)) {
if (!editor.api.isReadOnly()) {
pasteSelectedBlocks(editor, e.nativeEvent);

@@ -1200,3 +1175,3 @@ }

return import_react_dom.default.createPortal(
/* @__PURE__ */ import_react6.default.createElement(
/* @__PURE__ */ import_react5.default.createElement(
"input",

@@ -1224,3 +1199,3 @@ {

// src/react/onKeyDownSelection.ts
var import_plate_common6 = require("@udecode/plate-common");
var import_plate5 = require("@udecode/plate");
var onKeyDownSelection = ({

@@ -1231,21 +1206,21 @@ api,

}) => {
if ((0, import_plate_common6.isHotkey)("mod+a", event)) {
if ((0, import_plate5.isHotkey)("mod+a", event)) {
if (event.defaultPrevented) return;
const ancestorNode = (0, import_plate_common6.getAncestorNode)(editor);
const ancestorNode = editor.api.block({ highest: true });
if (!ancestorNode) return;
const [, path] = ancestorNode;
if ((0, import_plate_common6.isSelectionCoverBlock)(editor)) {
if (editor.api.isAt({ block: true, end: true, start: true })) {
return api.blockSelection.selectedAll();
}
if (!(0, import_plate_common6.isRangeInSameBlock)(editor)) {
if (!editor.api.isAt({ block: true })) {
return api.blockSelection.selectedAll();
}
(0, import_plate_common6.select)(editor, path);
editor.tf.select(path);
event.preventDefault();
event.stopPropagation();
}
if ((0, import_plate_common6.isHotkey)("escape", event)) {
if ((0, import_plate5.isHotkey)("escape", event)) {
if (event.defaultPrevented) return;
const ancestorNode = (0, import_plate_common6.getAncestorNode)(editor);
const id = ancestorNode == null ? void 0 : ancestorNode[0].id;
const ancestorNode = editor.api.block({ highest: true });
const id = ancestorNode?.[0].id;
api.blockSelection.addSelectedRow(id);

@@ -1258,13 +1233,13 @@ event.preventDefault();

// src/react/transforms/duplicateBlockSelectionNodes.ts
var import_plate_common7 = require("@udecode/plate-common");
var import_slate3 = require("slate");
var duplicateBlockSelectionNodes = (editor, blocks) => {
(0, import_plate_common7.duplicateBlocks)(editor, blocks);
var import_plate6 = require("@udecode/plate");
var duplicateBlockSelectionNodes = (editor) => {
const blocks = editor.getApi(BlockSelectionPlugin).blockSelection.getNodes();
const lastBlock = blocks.at(-1);
if (!lastBlock) return;
const path = import_slate3.Path.next(lastBlock[1]);
editor.tf.duplicateNodes({ nodes: blocks });
const path = import_plate6.PathApi.next(lastBlock[1]);
const ids = blocks.map((_, index) => {
const targetPath = [path[0] + index];
const targetNode = (0, import_plate_common7.getNodeEntry)(editor, targetPath);
return targetNode == null ? void 0 : targetNode[0].id;
const targetNode = editor.api.node(targetPath);
return targetNode?.[0].id;
}).filter(Boolean);

@@ -1278,11 +1253,11 @@ const api = editor.getApi(BlockSelectionPlugin);

// src/react/transforms/insertBlocksAndSelect.ts
var import_plate_common8 = require("@udecode/plate-common");
var import_plate7 = require("@udecode/plate");
var insertBlocksAndSelect = (editor, nodes, { at }) => {
const ids = [];
nodes.forEach((node) => {
const id = (0, import_plate_common8.nanoid)();
const id = (0, import_plate7.nanoid)();
ids.push(id);
node.id = id;
});
(0, import_plate_common8.insertNodes)(editor, nodes, { at });
editor.tf.insertNodes(nodes, { at });
setTimeout(() => {

@@ -1297,3 +1272,3 @@ editor.getApi(BlockSelectionPlugin).blockSelection.setSelectedIds({ ids });

if (!selectedIds) return;
editor.removeNodes({
editor.tf.removeNodes({
at: [],

@@ -1305,7 +1280,7 @@ match: (n) => n.id && selectedIds.has(n.id)

// src/react/transforms/selectBlockSelectionNodes.ts
var import_plate_common9 = require("@udecode/plate-common");
var selectBlockSelectionNodes = (editor) => {
(0, import_plate_common9.selectNodes)(
editor,
editor.getApi(BlockSelectionPlugin).blockSelection.getNodes()
editor.tf.select(
editor.api.nodesRange(
editor.getApi(BlockSelectionPlugin).blockSelection.getNodes()
)
);

@@ -1316,10 +1291,10 @@ editor.getApi(BlockSelectionPlugin).blockSelection.resetSelectedIds();

// src/react/transforms/setBlockSelectionNodes.ts
var import_plate_common10 = require("@udecode/plate-common");
var setBlockSelectionNodes = (editor, props, options) => {
(0, import_plate_common10.withoutNormalizing)(editor, () => {
editor.tf.withoutNormalizing(() => {
const blocks = editor.getApi(BlockSelectionPlugin).blockSelection.getNodes();
blocks.forEach(([, path]) => {
(0, import_plate_common10.setNodes)(editor, props, __spreadProps(__spreadValues({}, options), {
editor.tf.setNodes(props, {
...options,
at: path
}));
});
});

@@ -1330,14 +1305,13 @@ });

const api = editor.getApi(BlockSelectionPlugin);
(0, import_plate_common10.withoutNormalizing)(editor, () => {
editor.tf.withoutNormalizing(() => {
const blocks = api.blockSelection.getNodes();
blocks.forEach(([node, path]) => {
var _a;
const prevIndent = (_a = node.indent) != null ? _a : 0;
const prevIndent = node.indent ?? 0;
const currentIndent = prevIndent + indent;
(0, import_plate_common10.setNodes)(
editor,
editor.tf.setNodes(
{ indent: currentIndent < 0 ? 0 : currentIndent },
__spreadProps(__spreadValues({}, options), {
{
...options,
at: path
})
}
);

@@ -1348,20 +1322,11 @@ });

var setBlockSelectionTexts = (editor, props, options) => {
setBlockSelectionNodes(editor, props, __spreadValues({
mode: "lowest"
}, options));
setBlockSelectionNodes(editor, props, {
mode: "lowest",
...options
});
};
// src/react/BlockSelectionPlugin.tsx
var BlockSelectionPlugin = (0, import_react8.createTPlatePlugin)({
var BlockSelectionPlugin = (0, import_react7.createTPlatePlugin)({
key: "blockSelection",
extendEditor: ({ api, editor, getOptions }) => {
const { setSelection } = editor;
editor.setSelection = (...args) => {
if (getOptions().selectedIds.size > 0 && !editor.getOption(BlockMenuPlugin, "openId")) {
api.blockSelection.unselect();
}
setSelection(...args);
};
return editor;
},
inject: {

@@ -1412,3 +1377,3 @@ isBlock: true,

const shadowInputRef = getOption("shadowInputRef");
if (shadowInputRef == null ? void 0 : shadowInputRef.current) {
if (shadowInputRef?.current) {
shadowInputRef.current.focus({ preventScroll: true });

@@ -1420,5 +1385,5 @@ }

return [
...(0, import_plate_common11.getNodeEntries)(editor, {
...editor.api.nodes({
at: [],
match: (n) => selectedIds == null ? void 0 : selectedIds.has(n.id)
match: (n) => selectedIds?.has(n.id)
})

@@ -1484,9 +1449,18 @@ ];

})).extendTransforms(({ editor }) => ({
duplicate: (0, import_plate_common11.bindFirst)(duplicateBlockSelectionNodes, editor),
insertBlocksAndSelect: (0, import_plate_common11.bindFirst)(insertBlocksAndSelect, editor),
removeNodes: (0, import_plate_common11.bindFirst)(removeBlockSelectionNodes, editor),
select: (0, import_plate_common11.bindFirst)(selectBlockSelectionNodes, editor),
setIndent: (0, import_plate_common11.bindFirst)(setBlockSelectionIndent, editor),
setNodes: (0, import_plate_common11.bindFirst)(setBlockSelectionNodes, editor),
setTexts: (0, import_plate_common11.bindFirst)(setBlockSelectionTexts, editor)
duplicate: (0, import_plate8.bindFirst)(duplicateBlockSelectionNodes, editor),
insertBlocksAndSelect: (0, import_plate8.bindFirst)(insertBlocksAndSelect, editor),
removeNodes: (0, import_plate8.bindFirst)(removeBlockSelectionNodes, editor),
select: (0, import_plate8.bindFirst)(selectBlockSelectionNodes, editor),
setIndent: (0, import_plate8.bindFirst)(setBlockSelectionIndent, editor),
setNodes: (0, import_plate8.bindFirst)(setBlockSelectionNodes, editor),
setTexts: (0, import_plate8.bindFirst)(setBlockSelectionTexts, editor)
})).overrideEditor(({ api, editor, getOptions, tf: { setSelection } }) => ({
transforms: {
setSelection(props) {
if (getOptions().selectedIds.size > 0 && !editor.getOption(BlockMenuPlugin, "openId")) {
api.blockSelection.unselect();
}
setSelection(props);
}
}
}));

@@ -1500,3 +1474,3 @@

);
const selectionExpanded = (0, import_plate_common12.isSelectionExpanded)(editor);
const selectionExpanded = editor.api.isExpanded();
return selectionExpanded || isSelectingSome;

@@ -1503,0 +1477,0 @@ };

import * as _udecode_plate_core_react from '@udecode/plate-core/react';
import { PluginConfig, TNodeEntry, TElement, UnknownObject, GetFragmentPropOptions, TEditor, SlateEditor, TNodeProps, SetNodesOptions, TText } from '@udecode/plate-common';
import { PluginConfig, NodeEntry, TElement, UnknownObject, TRange, EditorPropOptions, Editor, Path, SlateEditor, NodeProps, SetNodesOptions, TText } from '@udecode/plate';
import * as _udecode_slate from '@udecode/slate';
import * as slate from 'slate';
import { Range, Path } from 'slate';
import React, { CSSProperties } from 'react';
import { KeyboardHandler, EditableSiblingComponent, PlateEditor } from '@udecode/plate-common/react';
import { KeyboardHandler, EditableSiblingComponent, PlateEditor } from '@udecode/plate/react';

@@ -44,3 +42,3 @@ declare const BLOCK_CONTEXT_MENU_ID = "context";

type DeepPartial<T> = T extends (infer U)[] ? T : T extends HTMLElement ? T : {
type DeepPartial<T> = T extends unknown[] ? T : T extends HTMLElement ? T : {
[P in keyof T]?: DeepPartial<T[P]>;

@@ -130,3 +128,3 @@ };

focus: () => void;
getNodes: () => TNodeEntry[];
getNodes: () => NodeEntry[];
resetSelectedIds: () => void;

@@ -152,5 +150,5 @@ selectedAll: () => void;

} & Record<"blockSelection", Partial<BlockSelectionApi>>, Record<"blockSelection", {
duplicate: (blocks: TNodeEntry[]) => void;
duplicate: () => void;
insertBlocksAndSelect: (nodes: TElement[], args_1: {
at: slate.Path;
at: _udecode_slate.Path;
}) => void;

@@ -177,3 +175,3 @@ removeNodes: () => void;

id: any;
selection: Range | null;
selection: TRange | null;
data?: TCursorData;

@@ -218,5 +216,5 @@ };

declare function useBlockSelectionNodes(): _udecode_slate.TNodeEntry<TElement>[];
declare function useBlockSelectionNodes(): _udecode_slate.NodeEntry<TElement>[];
declare function useBlockSelectionFragment(): TElement[];
declare function useBlockSelectionFragmentProp(options?: GetFragmentPropOptions): string | undefined;
declare function useBlockSelectionFragmentProp(options?: Omit<EditorPropOptions, 'nodes'>): string | undefined;

@@ -247,3 +245,3 @@ type UseCursorOverlayOptions = {

interface UseRefreshOnResizeOptions {
selectionRectCache: React.MutableRefObject<WeakMap<Range, SelectionRect[]>>;
selectionRectCache: React.MutableRefObject<WeakMap<TRange, SelectionRect[]>>;
containerRef?: React.RefObject<HTMLElement>;

@@ -261,3 +259,3 @@ refreshOnResize?: boolean;

/** Get the caret position of a range from selectionRects. */
declare const getCaretPosition: (selectionRects: SelectionRect[], range: Range) => CaretPosition | null;
declare const getCaretPosition: (selectionRects: SelectionRect[], range: TRange) => CaretPosition | null;

@@ -270,4 +268,4 @@ /** Get cursor overlay state from selection rects. */

declare const getSelectionRects: (editor: TEditor, { range, xOffset, yOffset, }: {
range: Range;
declare const getSelectionRects: (editor: Editor, { range, xOffset, yOffset, }: {
range: TRange;
xOffset: number;

@@ -277,3 +275,3 @@ yOffset: number;

declare const duplicateBlockSelectionNodes: (editor: PlateEditor, blocks: TNodeEntry[]) => void;
declare const duplicateBlockSelectionNodes: (editor: PlateEditor) => void;

@@ -288,5 +286,5 @@ declare const insertBlocksAndSelect: (editor: PlateEditor, nodes: TElement[], { at }: {

declare const setBlockSelectionNodes: (editor: PlateEditor, props: Partial<TNodeProps<TElement>>, options?: SetNodesOptions) => void;
declare const setBlockSelectionNodes: (editor: PlateEditor, props: Partial<NodeProps<TElement>>, options?: SetNodesOptions) => void;
declare const setBlockSelectionIndent: (editor: PlateEditor, indent: number, options?: SetNodesOptions) => void;
declare const setBlockSelectionTexts: (editor: PlateEditor, props: Partial<TNodeProps<TText>>, options?: Omit<SetNodesOptions, "at">) => void;
declare const setBlockSelectionTexts: (editor: PlateEditor, props: Partial<NodeProps<TText>>, options?: Omit<SetNodesOptions, "at">) => void;

@@ -293,0 +291,0 @@ declare const copySelectedBlocks: (editor: SlateEditor) => void;

{
"name": "@udecode/plate-selection",
"version": "41.0.8",
"version": "42.0.0",
"description": "Plate selection plugins",

@@ -56,13 +56,8 @@ "keywords": [

"devDependencies": {
"@udecode/plate-common": "workspace:^"
"@udecode/plate": "workspace:^"
},
"peerDependencies": {
"@udecode/plate-common": ">=41.0.5",
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
"slate": ">=0.112.0",
"slate-dom": ">=0.111.0",
"slate-history": ">=0.93.0",
"slate-hyperscript": ">=0.66.0",
"slate-react": ">=0.111.0"
"@udecode/plate": ">=42.0.0",
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
},

@@ -69,0 +64,0 @@ "publishConfig": {

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc