@reiwuzen/blocky 1.4.3 → 1.4.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 +14 -9
- package/dist/index.d.cts +29 -18
- package/dist/index.d.ts +29 -18
- package/dist/index.js +14 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -546,12 +546,13 @@ function replaceRange(block, startNodeIndex, startOffset, endNodeIndex, endOffse
|
|
|
546
546
|
// src/engine/transform.ts
|
|
547
547
|
var import_result4 = require("@reiwuzen/result");
|
|
548
548
|
var TRIGGERS = {
|
|
549
|
-
"-": "bullet",
|
|
550
|
-
"1.": "number",
|
|
551
|
-
"[]": "todo",
|
|
552
|
-
"
|
|
553
|
-
"
|
|
554
|
-
"
|
|
549
|
+
"-": { type: "bullet", meta: { depth: 0 } },
|
|
550
|
+
"1.": { type: "number", meta: { depth: 0 } },
|
|
551
|
+
"[]": { type: "todo", meta: { depth: 0, checked: false } },
|
|
552
|
+
"[x]": { type: "todo", meta: { depth: 0, checked: true } },
|
|
553
|
+
"#": { type: "heading1" },
|
|
554
|
+
"##": { type: "heading2" },
|
|
555
|
+
"###": { type: "heading3" }
|
|
555
556
|
};
|
|
556
557
|
function getRawText(block) {
|
|
557
558
|
const first = block.content[0];
|
|
@@ -574,13 +575,17 @@ function applyMarkdownTransform(block, cursorOffset) {
|
|
|
574
575
|
return import_result4.Result.Ok({ block, converted: false });
|
|
575
576
|
if (cursorOffset < match.length)
|
|
576
577
|
return import_result4.Result.Ok({ block, converted: false });
|
|
577
|
-
const
|
|
578
|
+
const spec = TRIGGERS[match];
|
|
578
579
|
const strippedContent = stripPrefix(block, match);
|
|
580
|
+
const baseMeta = buildMetaForTarget(spec.type);
|
|
579
581
|
const converted = {
|
|
580
582
|
id: block.id,
|
|
581
|
-
type:
|
|
583
|
+
type: spec.type,
|
|
582
584
|
content: strippedContent,
|
|
583
|
-
meta:
|
|
585
|
+
meta: {
|
|
586
|
+
...baseMeta,
|
|
587
|
+
...spec.meta ?? {}
|
|
588
|
+
}
|
|
584
589
|
};
|
|
585
590
|
return import_result4.Result.Ok({ block: converted, converted: true });
|
|
586
591
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -122,28 +122,39 @@ type TransformResult = {
|
|
|
122
122
|
* Attempt to convert a paragraph block into another type based on a
|
|
123
123
|
* Markdown-style prefix typed by the user.
|
|
124
124
|
*
|
|
125
|
-
*
|
|
125
|
+
* This transform is intended to be called by the UI **when the user presses
|
|
126
|
+
* space** inside a paragraph block.
|
|
126
127
|
*
|
|
127
|
-
*
|
|
128
|
+
* The engine itself does NOT check for the space character — the caller is
|
|
129
|
+
* responsible for invoking this function at the correct time.
|
|
128
130
|
*
|
|
129
|
-
*
|
|
130
|
-
* |----------|-------------|
|
|
131
|
-
* | `-` | bullet |
|
|
132
|
-
* | `1.` | number |
|
|
133
|
-
* | `[]` | todo |
|
|
134
|
-
* | `#` | heading1 |
|
|
135
|
-
* | `##` | heading2 |
|
|
136
|
-
* | `###` | heading3 |
|
|
131
|
+
* Supported triggers (must appear at position 0):
|
|
137
132
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
133
|
+
* | Typed | Converts to | Meta |
|
|
134
|
+
* |------|---------------|------|
|
|
135
|
+
* | `-` | bullet | `{ depth: 0 }` |
|
|
136
|
+
* | `1.` | number | `{ depth: 0 }` |
|
|
137
|
+
* | `[]` | todo | `{ depth: 0, checked: false }` |
|
|
138
|
+
* | `[x]` | todo | `{ depth: 0, checked: true }` |
|
|
139
|
+
* | `#` | heading1 | default meta |
|
|
140
|
+
* | `##` | heading2 | default meta |
|
|
141
|
+
* | `###` | heading3 | default meta |
|
|
144
142
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
143
|
+
* Guards — returns `{ converted: false }` without mutation if any fail:
|
|
144
|
+
*
|
|
145
|
+
* 1. `block.type` must be `"paragraph"`
|
|
146
|
+
* 2. The paragraph text must exactly match a trigger prefix
|
|
147
|
+
* 3. `cursorOffset` must be ≥ `trigger.length`
|
|
148
|
+
*
|
|
149
|
+
* On success:
|
|
150
|
+
*
|
|
151
|
+
* - The trigger prefix is stripped from the block content
|
|
152
|
+
* - A new block is returned with the target type
|
|
153
|
+
* - `meta` is constructed from:
|
|
154
|
+
*
|
|
155
|
+
* `buildMetaForTarget(type)` + trigger-specific overrides
|
|
156
|
+
*
|
|
157
|
+
* The original block object is never mutated.
|
|
147
158
|
*/
|
|
148
159
|
declare function applyMarkdownTransform(block: AnyBlock, cursorOffset: number): Result<TransformResult>;
|
|
149
160
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -122,28 +122,39 @@ type TransformResult = {
|
|
|
122
122
|
* Attempt to convert a paragraph block into another type based on a
|
|
123
123
|
* Markdown-style prefix typed by the user.
|
|
124
124
|
*
|
|
125
|
-
*
|
|
125
|
+
* This transform is intended to be called by the UI **when the user presses
|
|
126
|
+
* space** inside a paragraph block.
|
|
126
127
|
*
|
|
127
|
-
*
|
|
128
|
+
* The engine itself does NOT check for the space character — the caller is
|
|
129
|
+
* responsible for invoking this function at the correct time.
|
|
128
130
|
*
|
|
129
|
-
*
|
|
130
|
-
* |----------|-------------|
|
|
131
|
-
* | `-` | bullet |
|
|
132
|
-
* | `1.` | number |
|
|
133
|
-
* | `[]` | todo |
|
|
134
|
-
* | `#` | heading1 |
|
|
135
|
-
* | `##` | heading2 |
|
|
136
|
-
* | `###` | heading3 |
|
|
131
|
+
* Supported triggers (must appear at position 0):
|
|
137
132
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
133
|
+
* | Typed | Converts to | Meta |
|
|
134
|
+
* |------|---------------|------|
|
|
135
|
+
* | `-` | bullet | `{ depth: 0 }` |
|
|
136
|
+
* | `1.` | number | `{ depth: 0 }` |
|
|
137
|
+
* | `[]` | todo | `{ depth: 0, checked: false }` |
|
|
138
|
+
* | `[x]` | todo | `{ depth: 0, checked: true }` |
|
|
139
|
+
* | `#` | heading1 | default meta |
|
|
140
|
+
* | `##` | heading2 | default meta |
|
|
141
|
+
* | `###` | heading3 | default meta |
|
|
144
142
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
143
|
+
* Guards — returns `{ converted: false }` without mutation if any fail:
|
|
144
|
+
*
|
|
145
|
+
* 1. `block.type` must be `"paragraph"`
|
|
146
|
+
* 2. The paragraph text must exactly match a trigger prefix
|
|
147
|
+
* 3. `cursorOffset` must be ≥ `trigger.length`
|
|
148
|
+
*
|
|
149
|
+
* On success:
|
|
150
|
+
*
|
|
151
|
+
* - The trigger prefix is stripped from the block content
|
|
152
|
+
* - A new block is returned with the target type
|
|
153
|
+
* - `meta` is constructed from:
|
|
154
|
+
*
|
|
155
|
+
* `buildMetaForTarget(type)` + trigger-specific overrides
|
|
156
|
+
*
|
|
157
|
+
* The original block object is never mutated.
|
|
147
158
|
*/
|
|
148
159
|
declare function applyMarkdownTransform(block: AnyBlock, cursorOffset: number): Result<TransformResult>;
|
|
149
160
|
/**
|
package/dist/index.js
CHANGED
|
@@ -478,12 +478,13 @@ function replaceRange(block, startNodeIndex, startOffset, endNodeIndex, endOffse
|
|
|
478
478
|
// src/engine/transform.ts
|
|
479
479
|
import { Result as Result4 } from "@reiwuzen/result";
|
|
480
480
|
var TRIGGERS = {
|
|
481
|
-
"-": "bullet",
|
|
482
|
-
"1.": "number",
|
|
483
|
-
"[]": "todo",
|
|
484
|
-
"
|
|
485
|
-
"
|
|
486
|
-
"
|
|
481
|
+
"-": { type: "bullet", meta: { depth: 0 } },
|
|
482
|
+
"1.": { type: "number", meta: { depth: 0 } },
|
|
483
|
+
"[]": { type: "todo", meta: { depth: 0, checked: false } },
|
|
484
|
+
"[x]": { type: "todo", meta: { depth: 0, checked: true } },
|
|
485
|
+
"#": { type: "heading1" },
|
|
486
|
+
"##": { type: "heading2" },
|
|
487
|
+
"###": { type: "heading3" }
|
|
487
488
|
};
|
|
488
489
|
function getRawText(block) {
|
|
489
490
|
const first = block.content[0];
|
|
@@ -506,13 +507,17 @@ function applyMarkdownTransform(block, cursorOffset) {
|
|
|
506
507
|
return Result4.Ok({ block, converted: false });
|
|
507
508
|
if (cursorOffset < match.length)
|
|
508
509
|
return Result4.Ok({ block, converted: false });
|
|
509
|
-
const
|
|
510
|
+
const spec = TRIGGERS[match];
|
|
510
511
|
const strippedContent = stripPrefix(block, match);
|
|
512
|
+
const baseMeta = buildMetaForTarget(spec.type);
|
|
511
513
|
const converted = {
|
|
512
514
|
id: block.id,
|
|
513
|
-
type:
|
|
515
|
+
type: spec.type,
|
|
514
516
|
content: strippedContent,
|
|
515
|
-
meta:
|
|
517
|
+
meta: {
|
|
518
|
+
...baseMeta,
|
|
519
|
+
...spec.meta ?? {}
|
|
520
|
+
}
|
|
516
521
|
};
|
|
517
522
|
return Result4.Ok({ block: converted, converted: true });
|
|
518
523
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reiwuzen/blocky",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.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",
|