@reiwuzen/blocky 1.3.2 → 1.3.4

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
@@ -565,15 +565,12 @@ function stripPrefix(block, prefix) {
565
565
  return [{ ...first, text: stripped }, ...block.content.slice(1)];
566
566
  }
567
567
  function applyMarkdownTransform(block, cursorOffset) {
568
- if (block.type !== "paragraph")
569
- return import_result4.Result.Ok({ block, converted: false });
568
+ if (block.type !== "paragraph") return import_result4.Result.Ok({ block, converted: false });
570
569
  const text = getRawText(block);
571
570
  const match = Object.keys(TRIGGERS).sort((a, b) => b.length - a.length).find((trigger) => text === trigger || text.startsWith(trigger + " "));
572
- if (!match)
573
- return import_result4.Result.Ok({ block, converted: false });
571
+ if (!match) return import_result4.Result.Ok({ block, converted: false });
574
572
  const triggerEnd = match.length + 1;
575
- if (cursorOffset < triggerEnd)
576
- return import_result4.Result.Ok({ block, converted: false });
573
+ if (cursorOffset < triggerEnd) return import_result4.Result.Ok({ block, converted: false });
577
574
  const targetType = TRIGGERS[match];
578
575
  const strippedContent = stripPrefix(block, match);
579
576
  const converted = {
@@ -585,10 +582,9 @@ function applyMarkdownTransform(block, cursorOffset) {
585
582
  return import_result4.Result.Ok({ block: converted, converted: true });
586
583
  }
587
584
  function changeBlockType(block, targetType) {
588
- if (block.type === targetType)
589
- return import_result4.Result.Ok(block);
585
+ if (block.type === targetType) return import_result4.Result.Ok(block);
590
586
  const content = deriveContent(block, targetType);
591
- const meta = buildMetaForTarget(targetType);
587
+ const meta = deriveMeta(block, targetType);
592
588
  return import_result4.Result.Ok({
593
589
  id: block.id,
594
590
  type: targetType,
@@ -598,7 +594,8 @@ function changeBlockType(block, targetType) {
598
594
  }
599
595
  function extractText(block) {
600
596
  if (block.type === "code") return block.content[0].text;
601
- if (block.type === "equation") return block.content[0].latex;
597
+ if (block.type === "equation")
598
+ return block.content[0].latex;
602
599
  return block.content.map((n) => {
603
600
  if (n.type === "text") return n.text;
604
601
  if (n.type === "code") return n.text;
@@ -608,8 +605,7 @@ function extractText(block) {
608
605
  }
609
606
  function deriveContent(block, targetType) {
610
607
  const text = extractText(block);
611
- if (targetType === "code")
612
- return [{ type: "code", text }];
608
+ if (targetType === "code") return [{ type: "code", text }];
613
609
  if (targetType === "equation")
614
610
  return [{ type: "equation", latex: text }];
615
611
  if (block.type === "code" || block.type === "equation") {
@@ -632,6 +628,11 @@ function buildMetaForTarget(targetType) {
632
628
  return {};
633
629
  }
634
630
  }
631
+ function deriveMeta(block, targetType) {
632
+ if (isList(block.type) && isList(targetType))
633
+ return block.meta;
634
+ return buildMetaForTarget(targetType);
635
+ }
635
636
  function toggleTodo(block) {
636
637
  if (block.type !== "todo")
637
638
  return import_result4.Result.Err(`toggleTodo expects a "todo" block, got "${block.type}"`);
@@ -644,9 +645,14 @@ var MAX_DEPTH = 6;
644
645
  function isIndentable(block) {
645
646
  return block.type === "bullet" || block.type === "number" || block.type === "todo";
646
647
  }
648
+ function isList(type) {
649
+ return type === "bullet" || type === "todo" || type === "number";
650
+ }
647
651
  function indentBlock(block) {
648
652
  if (!isIndentable(block))
649
- return import_result4.Result.Err(`indentBlock only supports bullet, number, todo \u2014 got "${block.type}"`);
653
+ return import_result4.Result.Err(
654
+ `indentBlock only supports bullet, number, todo \u2014 got "${block.type}"`
655
+ );
650
656
  if (block.meta.depth >= MAX_DEPTH)
651
657
  return import_result4.Result.Err(`already at max depth (${MAX_DEPTH})`);
652
658
  return import_result4.Result.Ok({
@@ -656,9 +662,10 @@ function indentBlock(block) {
656
662
  }
657
663
  function outdentBlock(block) {
658
664
  if (!isIndentable(block))
659
- return import_result4.Result.Err(`outdentBlock only supports bullet, number, todo \u2014 got "${block.type}"`);
660
- if (block.meta.depth <= 0)
661
- return import_result4.Result.Err(`already at min depth (0)`);
665
+ return import_result4.Result.Err(
666
+ `outdentBlock only supports bullet, number, todo \u2014 got "${block.type}"`
667
+ );
668
+ if (block.meta.depth <= 0) return import_result4.Result.Err(`already at min depth (0)`);
662
669
  return import_result4.Result.Ok({
663
670
  ...block,
664
671
  meta: { ...block.meta, depth: block.meta.depth - 1 }
package/dist/index.js CHANGED
@@ -498,15 +498,12 @@ function stripPrefix(block, prefix) {
498
498
  return [{ ...first, text: stripped }, ...block.content.slice(1)];
499
499
  }
500
500
  function applyMarkdownTransform(block, cursorOffset) {
501
- if (block.type !== "paragraph")
502
- return Result4.Ok({ block, converted: false });
501
+ if (block.type !== "paragraph") return Result4.Ok({ block, converted: false });
503
502
  const text = getRawText(block);
504
503
  const match = Object.keys(TRIGGERS).sort((a, b) => b.length - a.length).find((trigger) => text === trigger || text.startsWith(trigger + " "));
505
- if (!match)
506
- return Result4.Ok({ block, converted: false });
504
+ if (!match) return Result4.Ok({ block, converted: false });
507
505
  const triggerEnd = match.length + 1;
508
- if (cursorOffset < triggerEnd)
509
- return Result4.Ok({ block, converted: false });
506
+ if (cursorOffset < triggerEnd) return Result4.Ok({ block, converted: false });
510
507
  const targetType = TRIGGERS[match];
511
508
  const strippedContent = stripPrefix(block, match);
512
509
  const converted = {
@@ -518,10 +515,9 @@ function applyMarkdownTransform(block, cursorOffset) {
518
515
  return Result4.Ok({ block: converted, converted: true });
519
516
  }
520
517
  function changeBlockType(block, targetType) {
521
- if (block.type === targetType)
522
- return Result4.Ok(block);
518
+ if (block.type === targetType) return Result4.Ok(block);
523
519
  const content = deriveContent(block, targetType);
524
- const meta = buildMetaForTarget(targetType);
520
+ const meta = deriveMeta(block, targetType);
525
521
  return Result4.Ok({
526
522
  id: block.id,
527
523
  type: targetType,
@@ -531,7 +527,8 @@ function changeBlockType(block, targetType) {
531
527
  }
532
528
  function extractText(block) {
533
529
  if (block.type === "code") return block.content[0].text;
534
- if (block.type === "equation") return block.content[0].latex;
530
+ if (block.type === "equation")
531
+ return block.content[0].latex;
535
532
  return block.content.map((n) => {
536
533
  if (n.type === "text") return n.text;
537
534
  if (n.type === "code") return n.text;
@@ -541,8 +538,7 @@ function extractText(block) {
541
538
  }
542
539
  function deriveContent(block, targetType) {
543
540
  const text = extractText(block);
544
- if (targetType === "code")
545
- return [{ type: "code", text }];
541
+ if (targetType === "code") return [{ type: "code", text }];
546
542
  if (targetType === "equation")
547
543
  return [{ type: "equation", latex: text }];
548
544
  if (block.type === "code" || block.type === "equation") {
@@ -565,6 +561,11 @@ function buildMetaForTarget(targetType) {
565
561
  return {};
566
562
  }
567
563
  }
564
+ function deriveMeta(block, targetType) {
565
+ if (isList(block.type) && isList(targetType))
566
+ return block.meta;
567
+ return buildMetaForTarget(targetType);
568
+ }
568
569
  function toggleTodo(block) {
569
570
  if (block.type !== "todo")
570
571
  return Result4.Err(`toggleTodo expects a "todo" block, got "${block.type}"`);
@@ -577,9 +578,14 @@ var MAX_DEPTH = 6;
577
578
  function isIndentable(block) {
578
579
  return block.type === "bullet" || block.type === "number" || block.type === "todo";
579
580
  }
581
+ function isList(type) {
582
+ return type === "bullet" || type === "todo" || type === "number";
583
+ }
580
584
  function indentBlock(block) {
581
585
  if (!isIndentable(block))
582
- return Result4.Err(`indentBlock only supports bullet, number, todo \u2014 got "${block.type}"`);
586
+ return Result4.Err(
587
+ `indentBlock only supports bullet, number, todo \u2014 got "${block.type}"`
588
+ );
583
589
  if (block.meta.depth >= MAX_DEPTH)
584
590
  return Result4.Err(`already at max depth (${MAX_DEPTH})`);
585
591
  return Result4.Ok({
@@ -589,9 +595,10 @@ function indentBlock(block) {
589
595
  }
590
596
  function outdentBlock(block) {
591
597
  if (!isIndentable(block))
592
- return Result4.Err(`outdentBlock only supports bullet, number, todo \u2014 got "${block.type}"`);
593
- if (block.meta.depth <= 0)
594
- return Result4.Err(`already at min depth (0)`);
598
+ return Result4.Err(
599
+ `outdentBlock only supports bullet, number, todo \u2014 got "${block.type}"`
600
+ );
601
+ if (block.meta.depth <= 0) return Result4.Err(`already at min depth (0)`);
595
602
  return Result4.Ok({
596
603
  ...block,
597
604
  meta: { ...block.meta, depth: block.meta.depth - 1 }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reiwuzen/blocky",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Pure TypeScript block editor engine. Headless, framework-agnostic — content mutation, formatting, transforms, serialization, and history.",
5
5
  "author": "Rei WuZen",
6
6
  "license": "ISC",