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

@prosekit/extensions

Package Overview
Dependencies
Maintainers
0
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prosekit/extensions - npm Package Compare versions

Comparing version 0.7.21 to 0.7.22

dist/chunk-HHZL6V6B.js

17

dist/prosekit-extensions-placeholder.js

@@ -0,1 +1,5 @@

import {
findTable
} from "./chunk-HHZL6V6B.js";
// src/placeholder/index.ts

@@ -16,8 +20,6 @@ import { definePlugin, isInCodeBlock, maybeRun } from "@prosekit/core";

decorations: (state) => {
if (strategy === "doc" && !isDocEmpty(state.doc)) {
const strategyFn = typeof strategy === "function" ? strategy : strategy === "doc" ? docStrategy : defaultStrategy;
if (!strategyFn(state)) {
return null;
}
if (isInCodeBlock(state.selection)) {
return null;
}
const placeholderText = maybeRun(placeholder, state);

@@ -33,2 +35,8 @@ const deco = createPlaceholderDecoration(state, placeholderText);

}
function defaultStrategy(state) {
return !isInCodeBlock(state.selection) && !findTable(state.selection.$from);
}
function docStrategy(state) {
return isDocEmpty(state.doc) && defaultStrategy(state);
}
function isDocEmpty(doc) {

@@ -39,2 +47,3 @@ var _a;

function createPlaceholderDecoration(state, placeholderText) {
if (!placeholderText) return null;
const { selection } = state;

@@ -41,0 +50,0 @@ if (!selection.empty) return null;

@@ -26,1 +26,2 @@ export { defineTable } from './_tsup-dts-rollup.js';

export { isCellSelection } from './_tsup-dts-rollup.js';
export { findTable } from './_tsup-dts-rollup.js';

@@ -1,278 +0,18 @@

// src/table/table.ts
import { union } from "@prosekit/core";
// src/table/table-commands.ts
import {
defaultBlockAt,
defineCommands,
getNodeType,
insertNode
} from "@prosekit/core";
import { TextSelection } from "@prosekit/pm/state";
import {
addColumnAfter,
addColumnBefore,
addRowAfter,
addRowBefore,
CellSelection as CellSelection2,
deleteCellSelection,
deleteColumn,
deleteRow,
deleteTable,
mergeCells,
splitCell,
TableMap
} from "prosemirror-tables";
// src/table/table-utils.ts
import { findParentNode } from "@prosekit/core";
import {
cellAround,
cellNear,
CellSelection,
inSameTable
} from "prosemirror-tables";
function isCellSelection(value) {
return value instanceof CellSelection;
}
function findTable($pos) {
return findParentNode((node) => node.type.spec.tableRole === "table", $pos);
}
function findCellRange(selection, anchorHit, headHit) {
var _a, _b;
if (anchorHit == null && headHit == null && isCellSelection(selection)) {
return [selection.$anchorCell, selection.$headCell];
}
const anchor = (_a = anchorHit != null ? anchorHit : headHit) != null ? _a : selection.anchor;
const head = (_b = headHit != null ? headHit : anchorHit) != null ? _b : selection.head;
const doc = selection.$head.doc;
const $anchorCell = findCellPos(doc, anchor);
const $headCell = findCellPos(doc, head);
if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) {
return [$anchorCell, $headCell];
}
}
function findCellPos(doc, pos) {
const $pos = doc.resolve(pos);
return cellAround($pos) || cellNear($pos);
}
// src/table/table-commands.ts
function createEmptyTable(schema, row, col, header) {
const tableType = getNodeType(schema, "table");
const tableRowType = getNodeType(schema, "tableRow");
const tableCellType = getNodeType(schema, "tableCell");
const tableHeaderCellType = getNodeType(schema, "tableHeaderCell");
if (header) {
const headerCell = tableHeaderCellType.createAndFill();
const headerCells = repeat(headerCell, col);
const headerRow = tableRowType.createAndFill(null, headerCells);
const bodyCell = tableCellType.createAndFill();
const bodyCells = repeat(bodyCell, col);
const bodyRow = tableRowType.createAndFill(null, bodyCells);
const bodyRows = repeat(bodyRow, row - 1);
return tableType.createAndFill(null, [headerRow, ...bodyRows]);
} else {
const bodyCell = tableCellType.createAndFill();
const bodyCells = repeat(bodyCell, col);
const bodyRow = tableRowType.createAndFill(null, bodyCells);
const bodyRows = repeat(bodyRow, row);
return tableType.createAndFill(null, bodyRows);
}
}
function repeat(node, length) {
return Array(length).fill(node);
}
function insertTable(options) {
return (state, dispatch, view) => {
const { row, col, header } = options;
const table = createEmptyTable(state.schema, row, col, header);
return insertNode({ node: table })(state, dispatch, view);
};
}
var exitTable = (state, dispatch) => {
const { $head, $anchor } = state.selection;
if (!$head.sameParent($anchor)) {
return false;
}
let tableStart = -1;
let tableDepth = -1;
for (let depth = $head.depth; depth >= 0; depth--) {
const node2 = $head.node(depth);
if (node2.type.spec.tableRole === "table") {
tableStart = $head.before(depth);
tableDepth = depth;
}
}
if (tableStart < 0 || tableDepth <= 0) {
return false;
}
const above = $head.node(tableDepth - 1);
const after = $head.indexAfter(tableDepth - 1);
const type = defaultBlockAt(above.contentMatchAt(after));
const node = type == null ? void 0 : type.createAndFill();
if (!type || !node || !above.canReplaceWith(after, after, type)) {
return false;
}
if (dispatch) {
const pos = $head.after(tableDepth);
const tr = state.tr.replaceWith(pos, pos, node);
tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
dispatch(tr.scrollIntoView());
}
return true;
};
function selectTableColumn(options) {
return (state, dispatch) => {
const range = findCellRange(state.selection, options == null ? void 0 : options.anchor, options == null ? void 0 : options.head);
if (!range) {
return false;
}
if (dispatch) {
const [$anchorCell, $headCell] = range;
const selection = CellSelection2.colSelection($anchorCell, $headCell);
dispatch(state.tr.setSelection(selection));
}
return true;
};
}
function selectTableRow(options) {
return (state, dispatch) => {
const range = findCellRange(state.selection, options == null ? void 0 : options.anchor, options == null ? void 0 : options.head);
if (!range) {
return false;
}
if (dispatch) {
const [$anchorCell, $headCell] = range;
const selection = CellSelection2.rowSelection($anchorCell, $headCell);
dispatch(state.tr.setSelection(selection));
}
return true;
};
}
function selectTableCell(options) {
return (state, dispatch) => {
var _a;
const $cellPos = findCellPos(
state.doc,
(_a = options == null ? void 0 : options.pos) != null ? _a : state.selection.anchor
);
if (!$cellPos) {
return false;
}
if (dispatch) {
const selection = new CellSelection2($cellPos);
dispatch(state.tr.setSelection(selection));
}
return true;
};
}
function selectTable(options) {
return (state, dispatch) => {
const $pos = (options == null ? void 0 : options.pos) ? state.doc.resolve(options.pos) : state.selection.$anchor;
const table = findTable($pos);
if (!table) {
return false;
}
const map = TableMap.get(table.node);
if (map.map.length === 0) {
return false;
}
if (dispatch) {
let tr = state.tr;
const firstCellPosInTable = map.map[0];
const lastCellPosInTable = map.map[map.map.length - 1];
const firstCellPos = table.pos + firstCellPosInTable + 1;
const lastCellPos = table.pos + lastCellPosInTable + 1;
const $firstCellPos = tr.doc.resolve(firstCellPos);
const $lastCellPos = tr.doc.resolve(lastCellPos);
const selection = new CellSelection2($firstCellPos, $lastCellPos);
tr = tr.setSelection(selection);
dispatch == null ? void 0 : dispatch(tr);
}
return true;
};
}
function defineTableCommands() {
return defineCommands({
insertTable,
exitTable: () => exitTable,
selectTable,
selectTableCell,
selectTableColumn,
selectTableRow,
addTableColumnBefore: () => addColumnBefore,
addTableColumnAfter: () => addColumnAfter,
addTableRowAbove: () => addRowBefore,
addTableRowBelow: () => addRowAfter,
deleteTable: () => deleteTable,
deleteTableColumn: () => deleteColumn,
deleteTableRow: () => deleteRow,
deleteCellSelection: () => deleteCellSelection,
mergeTableCells: () => mergeCells,
splitTableCell: () => splitCell
});
}
// src/table/table-plugins.ts
import { definePlugin } from "@prosekit/core";
import { tableEditing, columnResizing } from "prosemirror-tables";
function defineTablePlugins() {
return definePlugin([tableEditing(), columnResizing()]);
}
// src/table/table-spec.ts
import { defineNodeSpec } from "@prosekit/core";
import { tableNodes } from "prosemirror-tables";
var cellContent = "block+";
var cellAttrs = {
colspan: { default: 1 },
rowspan: { default: 1 },
colwidth: { default: null }
};
var specs = tableNodes({
tableGroup: "block",
cellContent,
cellAttributes: {}
});
function defineTableSpec() {
return defineNodeSpec({
...specs["table"],
content: "tableRow+",
name: "table"
});
}
function defineTableRowSpec() {
return defineNodeSpec({
...specs["table_row"],
content: "(tableCell | tableHeaderCell)*",
name: "tableRow"
});
}
function defineTableCellSpec() {
return defineNodeSpec({
...specs["table_cell"],
name: "tableCell",
attrs: cellAttrs
});
}
function defineTableHeaderCellSpec() {
return defineNodeSpec({
...specs["table_header"],
name: "tableHeaderCell",
attrs: cellAttrs
});
}
// src/table/table.ts
function defineTable() {
return union(
defineTableSpec(),
defineTableRowSpec(),
defineTableCellSpec(),
defineTableHeaderCellSpec(),
defineTablePlugins(),
defineTableCommands()
);
}
defineTable,
defineTableCellSpec,
defineTableCommands,
defineTableHeaderCellSpec,
defineTablePlugins,
defineTableRowSpec,
defineTableSpec,
exitTable,
findTable,
insertTable,
isCellSelection,
selectTable,
selectTableCell,
selectTableColumn,
selectTableRow
} from "./chunk-HHZL6V6B.js";
export {

@@ -287,2 +27,3 @@ defineTable,

exitTable,
findTable,
insertTable,

@@ -289,0 +30,0 @@ isCellSelection,

{
"name": "@prosekit/extensions",
"type": "module",
"version": "0.7.21",
"version": "0.7.22",
"private": false,

@@ -221,6 +221,6 @@ "author": {

"prosemirror-search": "^1.0.0",
"prosemirror-tables": "^1.6.0",
"shiki": "^1.22.2",
"@prosekit/core": "^0.7.12",
"@prosekit/pm": "^0.1.8"
"prosemirror-tables": "^1.6.1",
"shiki": "^1.24.0",
"@prosekit/core": "^0.7.13",
"@prosekit/pm": "^0.1.9"
},

@@ -248,11 +248,11 @@ "peerDependencies": {

"devDependencies": {
"@vitest/browser": "^2.1.4",
"@vitest/browser": "^2.1.6",
"just-pick": "^4.2.0",
"loro-crdt": "^1.0.7",
"loro-prosemirror": "^0.1.0",
"loro-crdt": "^1.1.4",
"loro-prosemirror": "^0.2.0",
"tsup": "^8.3.5",
"type-fest": "^4.26.1",
"typescript": "^5.6.3",
"vitest": "^2.1.4",
"y-prosemirror": "^1.2.12",
"vitest": "^2.1.6",
"y-prosemirror": "^1.2.13",
"y-protocols": "^1.0.6",

@@ -259,0 +259,0 @@ "yjs": "^13.6.20",

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

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