@reiwuzen/blocky 1.4.5 → 1.4.7

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
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ applyEnterTransform: () => applyEnterTransform,
23
24
  applyMarkdownTransform: () => applyMarkdownTransform,
24
25
  areBlocksSame: () => areBlocksSame,
25
26
  canRedo: () => canRedo,
@@ -552,8 +553,7 @@ var TRIGGERS = {
552
553
  "[x]": { type: "todo", meta: { depth: 0, checked: true } },
553
554
  "#": { type: "heading1" },
554
555
  "##": { type: "heading2" },
555
- "###": { type: "heading3" },
556
- "```": { type: "code" }
556
+ "###": { type: "heading3" }
557
557
  };
558
558
  function getRawText(block) {
559
559
  const first = block.content[0];
@@ -590,6 +590,21 @@ function applyMarkdownTransform(block, cursorOffset) {
590
590
  };
591
591
  return import_result4.Result.Ok({ block: converted, converted: true });
592
592
  }
593
+ function applyEnterTransform(block) {
594
+ if (block.type !== "paragraph")
595
+ return import_result4.Result.Ok({ block, converted: false });
596
+ const text = getRawText(block);
597
+ if (text !== "```")
598
+ return import_result4.Result.Ok({ block, converted: false });
599
+ const strippedContent = stripPrefix(block, "```");
600
+ const converted = {
601
+ id: block.id,
602
+ type: "code",
603
+ content: strippedContent,
604
+ meta: buildMetaForTarget("code")
605
+ };
606
+ return import_result4.Result.Ok({ block: converted, converted: true });
607
+ }
593
608
  function changeBlockType(block, targetType) {
594
609
  if (block.type === targetType) return import_result4.Result.Ok(block);
595
610
  const content = deriveContent(block, targetType);
@@ -885,6 +900,7 @@ var canRedo = (history) => history.future.length > 0;
885
900
  var currentBlocks = (history) => history.present.blocks;
886
901
  // Annotate the CommonJS export names for ESM import in node:
887
902
  0 && (module.exports = {
903
+ applyEnterTransform,
888
904
  applyMarkdownTransform,
889
905
  areBlocksSame,
890
906
  canRedo,
package/dist/index.d.cts CHANGED
@@ -157,6 +157,22 @@ type TransformResult = {
157
157
  * The original block object is never mutated.
158
158
  */
159
159
  declare function applyMarkdownTransform(block: AnyBlock, cursorOffset: number): Result<TransformResult>;
160
+ /**
161
+ * Attempt to convert a paragraph into a code block when the user presses Enter.
162
+ *
163
+ * Trigger:
164
+ * ``` + Enter
165
+ *
166
+ * Guards:
167
+ * 1. Block must be a paragraph
168
+ * 2. Paragraph text must exactly equal "```"
169
+ *
170
+ * Result:
171
+ * paragraph → code block
172
+ * content → empty code node
173
+ * meta → { language?: string }
174
+ */
175
+ declare function applyEnterTransform(block: AnyBlock): Result<TransformResult>;
160
176
  /**
161
177
  * Convert a block to a new type, preserving content and meta where possible.
162
178
  *
@@ -333,4 +349,4 @@ declare function duplicateBlockAfter(blocks: AnyBlock[], id: string, newId?: str
333
349
  */
334
350
  declare function moveBlock(blocks: AnyBlock[], id: string, direction: "up" | "down"): Result<AnyBlock[], string>;
335
351
 
336
- export { type AnyBlock, type Block, type BlockContent, type BlockMeta, type BlockType, type History, type HistoryEntry, type Node, type NodeSelection, applyMarkdownTransform, areBlocksSame, canRedo, canUndo, changeBlockType, createBlock, createBlockAfter, createHistory, currentBlocks, deleteBlock, deleteLastChar, deleteRange, deserialize, deserializeNodes, duplicateBlock, duplicateBlockAfter, formatNodes, generateId, indentBlock, insertAt, insertBlockAfter, mergeAdjacentNodes, mergeBlocks, moveBlock, outdentBlock, push, redo, removeLink, replaceRange, serialize, serializeNodes, setLink, splitBlock, toMarkdown, toPlainText, toggleBold, toggleColor, toggleHighlight, toggleItalic, toggleStrikethrough, toggleTodo, toggleUnderline, undo };
352
+ export { type AnyBlock, type Block, type BlockContent, type BlockMeta, type BlockType, type History, type HistoryEntry, type Node, type NodeSelection, applyEnterTransform, applyMarkdownTransform, areBlocksSame, canRedo, canUndo, changeBlockType, createBlock, createBlockAfter, createHistory, currentBlocks, deleteBlock, deleteLastChar, deleteRange, deserialize, deserializeNodes, duplicateBlock, duplicateBlockAfter, formatNodes, generateId, indentBlock, insertAt, insertBlockAfter, mergeAdjacentNodes, mergeBlocks, moveBlock, outdentBlock, push, redo, removeLink, replaceRange, serialize, serializeNodes, setLink, splitBlock, toMarkdown, toPlainText, toggleBold, toggleColor, toggleHighlight, toggleItalic, toggleStrikethrough, toggleTodo, toggleUnderline, undo };
package/dist/index.d.ts CHANGED
@@ -157,6 +157,22 @@ type TransformResult = {
157
157
  * The original block object is never mutated.
158
158
  */
159
159
  declare function applyMarkdownTransform(block: AnyBlock, cursorOffset: number): Result<TransformResult>;
160
+ /**
161
+ * Attempt to convert a paragraph into a code block when the user presses Enter.
162
+ *
163
+ * Trigger:
164
+ * ``` + Enter
165
+ *
166
+ * Guards:
167
+ * 1. Block must be a paragraph
168
+ * 2. Paragraph text must exactly equal "```"
169
+ *
170
+ * Result:
171
+ * paragraph → code block
172
+ * content → empty code node
173
+ * meta → { language?: string }
174
+ */
175
+ declare function applyEnterTransform(block: AnyBlock): Result<TransformResult>;
160
176
  /**
161
177
  * Convert a block to a new type, preserving content and meta where possible.
162
178
  *
@@ -333,4 +349,4 @@ declare function duplicateBlockAfter(blocks: AnyBlock[], id: string, newId?: str
333
349
  */
334
350
  declare function moveBlock(blocks: AnyBlock[], id: string, direction: "up" | "down"): Result<AnyBlock[], string>;
335
351
 
336
- export { type AnyBlock, type Block, type BlockContent, type BlockMeta, type BlockType, type History, type HistoryEntry, type Node, type NodeSelection, applyMarkdownTransform, areBlocksSame, canRedo, canUndo, changeBlockType, createBlock, createBlockAfter, createHistory, currentBlocks, deleteBlock, deleteLastChar, deleteRange, deserialize, deserializeNodes, duplicateBlock, duplicateBlockAfter, formatNodes, generateId, indentBlock, insertAt, insertBlockAfter, mergeAdjacentNodes, mergeBlocks, moveBlock, outdentBlock, push, redo, removeLink, replaceRange, serialize, serializeNodes, setLink, splitBlock, toMarkdown, toPlainText, toggleBold, toggleColor, toggleHighlight, toggleItalic, toggleStrikethrough, toggleTodo, toggleUnderline, undo };
352
+ export { type AnyBlock, type Block, type BlockContent, type BlockMeta, type BlockType, type History, type HistoryEntry, type Node, type NodeSelection, applyEnterTransform, applyMarkdownTransform, areBlocksSame, canRedo, canUndo, changeBlockType, createBlock, createBlockAfter, createHistory, currentBlocks, deleteBlock, deleteLastChar, deleteRange, deserialize, deserializeNodes, duplicateBlock, duplicateBlockAfter, formatNodes, generateId, indentBlock, insertAt, insertBlockAfter, mergeAdjacentNodes, mergeBlocks, moveBlock, outdentBlock, push, redo, removeLink, replaceRange, serialize, serializeNodes, setLink, splitBlock, toMarkdown, toPlainText, toggleBold, toggleColor, toggleHighlight, toggleItalic, toggleStrikethrough, toggleTodo, toggleUnderline, undo };
package/dist/index.js CHANGED
@@ -484,8 +484,7 @@ var TRIGGERS = {
484
484
  "[x]": { type: "todo", meta: { depth: 0, checked: true } },
485
485
  "#": { type: "heading1" },
486
486
  "##": { type: "heading2" },
487
- "###": { type: "heading3" },
488
- "```": { type: "code" }
487
+ "###": { type: "heading3" }
489
488
  };
490
489
  function getRawText(block) {
491
490
  const first = block.content[0];
@@ -522,6 +521,21 @@ function applyMarkdownTransform(block, cursorOffset) {
522
521
  };
523
522
  return Result4.Ok({ block: converted, converted: true });
524
523
  }
524
+ function applyEnterTransform(block) {
525
+ if (block.type !== "paragraph")
526
+ return Result4.Ok({ block, converted: false });
527
+ const text = getRawText(block);
528
+ if (text !== "```")
529
+ return Result4.Ok({ block, converted: false });
530
+ const strippedContent = stripPrefix(block, "```");
531
+ const converted = {
532
+ id: block.id,
533
+ type: "code",
534
+ content: strippedContent,
535
+ meta: buildMetaForTarget("code")
536
+ };
537
+ return Result4.Ok({ block: converted, converted: true });
538
+ }
525
539
  function changeBlockType(block, targetType) {
526
540
  if (block.type === targetType) return Result4.Ok(block);
527
541
  const content = deriveContent(block, targetType);
@@ -816,6 +830,7 @@ var canUndo = (history) => history.past.length > 0;
816
830
  var canRedo = (history) => history.future.length > 0;
817
831
  var currentBlocks = (history) => history.present.blocks;
818
832
  export {
833
+ applyEnterTransform,
819
834
  applyMarkdownTransform,
820
835
  areBlocksSame,
821
836
  canRedo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reiwuzen/blocky",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
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",