@sofereditor/core 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -895,8 +895,8 @@ function kebab(prop) {
895
895
  // src/table-borders.ts
896
896
  var TABLE_BORDER_COLOR = "#cbd5e1";
897
897
  var TABLE_GUIDE_COLOR = "var(--ed-guide-color, transparent)";
898
- function cellBorderColors(preset, pos, variant) {
899
- const on = TABLE_BORDER_COLOR;
898
+ function cellBorderColors(preset, pos, variant, color) {
899
+ const on = color && color.length > 0 ? color : TABLE_BORDER_COLOR;
900
900
  const off = variant === "screen" ? TABLE_GUIDE_COLOR : "transparent";
901
901
  switch (preset ?? "all") {
902
902
  case "horizontal":
@@ -922,8 +922,8 @@ function cellBorderColors(preset, pos, variant) {
922
922
  return { top: on, right: on, bottom: on, left: on };
923
923
  }
924
924
  }
925
- function cellBorderStyle(preset, pos, variant) {
926
- const c = cellBorderColors(preset, pos, variant);
925
+ function cellBorderStyle(preset, pos, variant, color) {
926
+ const c = cellBorderColors(preset, pos, variant, color);
927
927
  return {
928
928
  borderTopColor: c.top,
929
929
  borderRightColor: c.right,
@@ -1317,6 +1317,34 @@ function insertSlice(ctx, slice) {
1317
1317
  const tailDelta = sliceDelta(full, offset, deltaLength(full));
1318
1318
  targetText.delete(offset, targetText.length - offset);
1319
1319
  const blocks = slice.blocks;
1320
+ if (blocks.length === 1 && slice.blockLevel) {
1321
+ const originalType2 = ctx.doc.getBlockType(blockIndex);
1322
+ const originalAttrs2 = ctx.doc.getBlockAttrs(blockIndex);
1323
+ let hostIndex = blockIndex;
1324
+ if (offset === 0) {
1325
+ const blk = ctx.doc.blocks.get(blockIndex);
1326
+ blk.set("type", blocks[0].type);
1327
+ const am = blk.get("attrs");
1328
+ am.clear();
1329
+ for (const [k, v] of Object.entries(blocks[0].attrs)) {
1330
+ if (v !== void 0) am.set(k, v);
1331
+ }
1332
+ writeDeltaInto(targetText, 0, blocks[0].delta);
1333
+ } else {
1334
+ hostIndex = blockIndex + 1;
1335
+ const b = createBlock(blocks[0].type, "", blocks[0].attrs);
1336
+ ctx.doc.blocks.insert(hostIndex, [b]);
1337
+ writeDeltaInto(b.get("text"), 0, blocks[0].delta);
1338
+ }
1339
+ const caretPos = ctx.doc.getBlockText(hostIndex).length;
1340
+ if (tailDelta.length > 0) {
1341
+ const tb = createBlock(originalType2 ?? "paragraph", "", originalAttrs2);
1342
+ ctx.doc.blocks.insert(hostIndex + 1, [tb]);
1343
+ writeDeltaInto(tb.get("text"), 0, tailDelta);
1344
+ }
1345
+ ctx.setSelection(collapsedSelection({ blockIndex: hostIndex, offset: caretPos }));
1346
+ return;
1347
+ }
1320
1348
  if (blocks.length === 1) {
1321
1349
  const afterS0 = writeDeltaInto(targetText, offset, blocks[0].delta);
1322
1350
  writeDeltaInto(targetText, afterS0, tailDelta);