@sofereditor/core 0.9.0 → 0.10.1

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
@@ -123,8 +123,10 @@ __export(index_exports, {
123
123
  sliceToText: () => sliceToText,
124
124
  spanOf: () => spanOf,
125
125
  splitCell: () => splitCell,
126
+ splitDeltaByLines: () => splitDeltaByLines,
126
127
  splitListItem: () => splitListItem,
127
128
  splitUnderscoreRuns: () => splitUnderscoreRuns,
129
+ stripFontFamilyMarks: () => stripFontFamilyMarks,
128
130
  styleToCssText: () => styleToCssText,
129
131
  tableLocationOf: () => tableLocationOf,
130
132
  tableRectSelection: () => tableRectSelection,
@@ -862,6 +864,25 @@ function sameMarkValue(a, b) {
862
864
  }
863
865
  return false;
864
866
  }
867
+ function splitDeltaByLines(delta) {
868
+ const lines = [[]];
869
+ for (const op of delta) {
870
+ if (typeof op.insert !== "string") {
871
+ lines[lines.length - 1].push(op);
872
+ continue;
873
+ }
874
+ const parts = op.insert.split("\n");
875
+ for (let i = 0; i < parts.length; i++) {
876
+ if (i > 0) lines.push([]);
877
+ const part = parts[i];
878
+ if (part.length === 0) continue;
879
+ lines[lines.length - 1].push(
880
+ op.attributes ? { insert: part, attributes: op.attributes } : { insert: part }
881
+ );
882
+ }
883
+ }
884
+ return lines;
885
+ }
865
886
 
866
887
  // src/decorations.ts
867
888
  var BLANK_MIN_RUN = 3;
@@ -1485,7 +1506,12 @@ function mergeWithPrevious(ctx, blockIndex) {
1485
1506
  function toggleList(ctx, kind) {
1486
1507
  transact(ctx.doc, () => {
1487
1508
  const sel = ctx.getSelection();
1488
- if (sel.anchor.cellIndex != null || sel.focus.cellIndex != null) return;
1509
+ if (sel.anchor.cellIndex != null || sel.focus.cellIndex != null) {
1510
+ const real = sel.focus.cellIndex != null ? ctx.doc.realCellIndex(sel.focus.blockIndex, sel.focus.cellIndex) : void 0;
1511
+ const atual = real != null ? ctx.doc.getCellAttrs(sel.focus.blockIndex, real).listKind : void 0;
1512
+ setCellAttr(ctx, "listKind", atual === kind ? null : kind);
1513
+ return;
1514
+ }
1489
1515
  const indices = selectedBlockIndices(sel, ctx.doc.blockCount());
1490
1516
  const allMatching = indices.every((i) => {
1491
1517
  const block = ctx.doc.getBlock(i);
@@ -2428,6 +2454,45 @@ var EditorHistory = class {
2428
2454
  this.undoManager.destroy();
2429
2455
  }
2430
2456
  };
2457
+
2458
+ // src/migrations.ts
2459
+ function coletar(yText, alvos) {
2460
+ if (!yText) return 0;
2461
+ const delta = yText.toDelta();
2462
+ const ranges = [];
2463
+ let index = 0;
2464
+ for (const op of delta) {
2465
+ const len = typeof op.insert === "string" ? op.insert.length : 1;
2466
+ if (typeof op.insert === "string" && op.attributes && "fontFamily" in op.attributes) {
2467
+ ranges.push([index, len]);
2468
+ }
2469
+ index += len;
2470
+ }
2471
+ if (ranges.length > 0) alvos.push({ yText, ranges });
2472
+ return ranges.length;
2473
+ }
2474
+ function stripFontFamilyMarks(doc, opts) {
2475
+ const alvos = [];
2476
+ let total = 0;
2477
+ for (let i = 0; i < doc.blockCount(); i++) {
2478
+ total += coletar(doc.getBlockText(i), alvos);
2479
+ const cells = doc.getCells(i);
2480
+ if (cells) {
2481
+ for (let c = 0; c < cells.length; c++) {
2482
+ total += coletar(doc.getCellText(i, c), alvos);
2483
+ }
2484
+ }
2485
+ }
2486
+ if (total === 0 || opts?.dryRun) return total;
2487
+ doc.ydoc.transact(() => {
2488
+ for (const { yText, ranges } of alvos) {
2489
+ for (const [index, length] of ranges) {
2490
+ yText.format(index, length, { fontFamily: null });
2491
+ }
2492
+ }
2493
+ }, "migration");
2494
+ return total;
2495
+ }
2431
2496
  // Annotate the CommonJS export names for ESM import in node:
2432
2497
  0 && (module.exports = {
2433
2498
  ANSWER_LINE_COLOR,
@@ -2523,8 +2588,10 @@ var EditorHistory = class {
2523
2588
  sliceToText,
2524
2589
  spanOf,
2525
2590
  splitCell,
2591
+ splitDeltaByLines,
2526
2592
  splitListItem,
2527
2593
  splitUnderscoreRuns,
2594
+ stripFontFamilyMarks,
2528
2595
  styleToCssText,
2529
2596
  tableLocationOf,
2530
2597
  tableRectSelection,