@reiwuzen/blocky 1.4.3 → 1.4.5
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 +15 -9
- package/dist/index.d.cts +29 -18
- package/dist/index.d.ts +29 -18
- package/dist/index.js +15 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -546,12 +546,14 @@ 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" },
|
|
556
|
+
"```": { type: "code" }
|
|
555
557
|
};
|
|
556
558
|
function getRawText(block) {
|
|
557
559
|
const first = block.content[0];
|
|
@@ -574,13 +576,17 @@ function applyMarkdownTransform(block, cursorOffset) {
|
|
|
574
576
|
return import_result4.Result.Ok({ block, converted: false });
|
|
575
577
|
if (cursorOffset < match.length)
|
|
576
578
|
return import_result4.Result.Ok({ block, converted: false });
|
|
577
|
-
const
|
|
579
|
+
const spec = TRIGGERS[match];
|
|
578
580
|
const strippedContent = stripPrefix(block, match);
|
|
581
|
+
const baseMeta = buildMetaForTarget(spec.type);
|
|
579
582
|
const converted = {
|
|
580
583
|
id: block.id,
|
|
581
|
-
type:
|
|
584
|
+
type: spec.type,
|
|
582
585
|
content: strippedContent,
|
|
583
|
-
meta:
|
|
586
|
+
meta: {
|
|
587
|
+
...baseMeta,
|
|
588
|
+
...spec.meta ?? {}
|
|
589
|
+
}
|
|
584
590
|
};
|
|
585
591
|
return import_result4.Result.Ok({ block: converted, converted: true });
|
|
586
592
|
}
|
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,14 @@ 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" },
|
|
488
|
+
"```": { type: "code" }
|
|
487
489
|
};
|
|
488
490
|
function getRawText(block) {
|
|
489
491
|
const first = block.content[0];
|
|
@@ -506,13 +508,17 @@ function applyMarkdownTransform(block, cursorOffset) {
|
|
|
506
508
|
return Result4.Ok({ block, converted: false });
|
|
507
509
|
if (cursorOffset < match.length)
|
|
508
510
|
return Result4.Ok({ block, converted: false });
|
|
509
|
-
const
|
|
511
|
+
const spec = TRIGGERS[match];
|
|
510
512
|
const strippedContent = stripPrefix(block, match);
|
|
513
|
+
const baseMeta = buildMetaForTarget(spec.type);
|
|
511
514
|
const converted = {
|
|
512
515
|
id: block.id,
|
|
513
|
-
type:
|
|
516
|
+
type: spec.type,
|
|
514
517
|
content: strippedContent,
|
|
515
|
-
meta:
|
|
518
|
+
meta: {
|
|
519
|
+
...baseMeta,
|
|
520
|
+
...spec.meta ?? {}
|
|
521
|
+
}
|
|
516
522
|
};
|
|
517
523
|
return Result4.Ok({ block: converted, converted: true });
|
|
518
524
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reiwuzen/blocky",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
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",
|