@reiwuzen/blocky 1.4.4 → 1.4.6

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,
@@ -589,6 +590,20 @@ function applyMarkdownTransform(block, cursorOffset) {
589
590
  };
590
591
  return import_result4.Result.Ok({ block: converted, converted: true });
591
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 converted = {
600
+ id: block.id,
601
+ type: "code",
602
+ content: [{ type: "code", text: "" }],
603
+ meta: buildMetaForTarget("code")
604
+ };
605
+ return import_result4.Result.Ok({ block: converted, converted: true });
606
+ }
592
607
  function changeBlockType(block, targetType) {
593
608
  if (block.type === targetType) return import_result4.Result.Ok(block);
594
609
  const content = deriveContent(block, targetType);
@@ -884,6 +899,7 @@ var canRedo = (history) => history.future.length > 0;
884
899
  var currentBlocks = (history) => history.present.blocks;
885
900
  // Annotate the CommonJS export names for ESM import in node:
886
901
  0 && (module.exports = {
902
+ applyEnterTransform,
887
903
  applyMarkdownTransform,
888
904
  areBlocksSame,
889
905
  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
@@ -521,6 +521,20 @@ function applyMarkdownTransform(block, cursorOffset) {
521
521
  };
522
522
  return Result4.Ok({ block: converted, converted: true });
523
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 converted = {
531
+ id: block.id,
532
+ type: "code",
533
+ content: [{ type: "code", text: "" }],
534
+ meta: buildMetaForTarget("code")
535
+ };
536
+ return Result4.Ok({ block: converted, converted: true });
537
+ }
524
538
  function changeBlockType(block, targetType) {
525
539
  if (block.type === targetType) return Result4.Ok(block);
526
540
  const content = deriveContent(block, targetType);
@@ -815,6 +829,7 @@ var canUndo = (history) => history.past.length > 0;
815
829
  var canRedo = (history) => history.future.length > 0;
816
830
  var currentBlocks = (history) => history.present.blocks;
817
831
  export {
832
+ applyEnterTransform,
818
833
  applyMarkdownTransform,
819
834
  areBlocksSame,
820
835
  canRedo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reiwuzen/blocky",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
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",