@seed-hypermedia/client 0.0.3 → 0.0.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/blocks-to-markdown.d.ts +27 -0
- package/dist/{chunk-X57BIZUK.mjs → chunk-YIND2WNJ.mjs} +5 -1
- package/dist/editor-types.d.ts +157 -0
- package/dist/editorblock-to-hmblock.d.ts +12 -0
- package/dist/hm-types.d.ts +123 -0
- package/dist/hm-types.mjs +1 -1
- package/dist/hmblock-to-editorblock.d.ts +23 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +689 -1
- package/dist/markdown-to-blocks.d.ts +10 -1
- package/dist/unicode.d.ts +35 -0
- package/package.json +1 -1
- package/src/index.ts +41 -2
|
@@ -31,3 +31,30 @@ export declare function emitFrontmatter(metadata: HMMetadata): string;
|
|
|
31
31
|
* as placeholder links (not resolved).
|
|
32
32
|
*/
|
|
33
33
|
export declare function blocksToMarkdown(doc: HMDocument, options?: BlocksToMarkdownOptions): string;
|
|
34
|
+
/**
|
|
35
|
+
* Convert a title string into a URL-safe slug.
|
|
36
|
+
*
|
|
37
|
+
* - Lowercases the string
|
|
38
|
+
* - Replaces non-alphanumeric characters with hyphens
|
|
39
|
+
* - Trims leading/trailing hyphens
|
|
40
|
+
* - Truncates to 60 characters
|
|
41
|
+
*/
|
|
42
|
+
export declare function slugify(title: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Build a draft filename from a slug and nanoid.
|
|
45
|
+
* Format: `<slug>_<nanoid>.md` — human-readable + collision-safe.
|
|
46
|
+
* If the slug is empty, the filename is just `<nanoid>.md`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function draftFilename(slug: string, id: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Extract the draft ID (nanoid) from a draft filename.
|
|
51
|
+
*
|
|
52
|
+
* Handles both formats:
|
|
53
|
+
* - `<slug>_<nanoid>.md` → returns the nanoid part
|
|
54
|
+
* - `<nanoid>.md` → returns the nanoid (legacy/no-slug)
|
|
55
|
+
* - `<nanoid>.json` → returns the nanoid (legacy JSON)
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseDraftFilename(filename: string): {
|
|
58
|
+
id: string;
|
|
59
|
+
ext: string;
|
|
60
|
+
};
|
|
@@ -604,7 +604,11 @@ var HMDraftMetaBaseSchema = z.object({
|
|
|
604
604
|
editUid: z.string().optional(),
|
|
605
605
|
editPath: z.array(z.string()).optional(),
|
|
606
606
|
metadata: HMDocumentMetadataSchema,
|
|
607
|
-
visibility: HMResourceVisibilitySchema.optional().default("PUBLIC")
|
|
607
|
+
visibility: HMResourceVisibilitySchema.optional().default("PUBLIC"),
|
|
608
|
+
// deps and navigation live in the index entry for .md drafts
|
|
609
|
+
// (for .json drafts they come from the content file for backwards compat)
|
|
610
|
+
deps: z.array(z.string().min(1)).default([]),
|
|
611
|
+
navigation: z.array(HMNavigationItemSchema).optional()
|
|
608
612
|
});
|
|
609
613
|
var draftLocationRefinement = (data) => data.editUid || data.locationUid;
|
|
610
614
|
var HMDraftMetaSchema = HMDraftMetaBaseSchema.refine(draftLocationRefinement, {
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { HMBlockChildrenType } from './hm-types';
|
|
2
|
+
export type EditorBlock = EditorParagraphBlock | EditorHeadingBlock | EditorCodeBlock | EditorImageBlock | EditorVideoBlock | EditorFileBlock | EditorButtonBlock | EditorEmbedBlock | EditorWebEmbedBlock | EditorMathBlock | EditorNostrBlock | EditorQueryBlock | EditorUnknownBlock;
|
|
3
|
+
export type HMInlineContent = EditorText | EditorInlineEmbed | EditorLink;
|
|
4
|
+
export interface EditorBaseBlock {
|
|
5
|
+
id: string;
|
|
6
|
+
props: EditorBlockProps;
|
|
7
|
+
children: Array<EditorBlock>;
|
|
8
|
+
}
|
|
9
|
+
export interface EditorBlockProps {
|
|
10
|
+
childrenType?: HMBlockChildrenType;
|
|
11
|
+
columnCount?: string;
|
|
12
|
+
listLevel?: string;
|
|
13
|
+
level?: number | string;
|
|
14
|
+
ref?: string;
|
|
15
|
+
revision?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface EditorParagraphBlock extends EditorBaseBlock {
|
|
18
|
+
type: 'paragraph';
|
|
19
|
+
content: Array<HMInlineContent>;
|
|
20
|
+
}
|
|
21
|
+
export interface EditorHeadingBlock extends EditorBaseBlock {
|
|
22
|
+
type: 'heading';
|
|
23
|
+
content: Array<HMInlineContent>;
|
|
24
|
+
}
|
|
25
|
+
export interface EditorCodeBlock extends EditorBaseBlock {
|
|
26
|
+
type: 'code-block';
|
|
27
|
+
content: Array<HMInlineContent>;
|
|
28
|
+
props: EditorBlockProps & {
|
|
29
|
+
language?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface DraftMediaRef {
|
|
33
|
+
draftId: string;
|
|
34
|
+
mediaId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
mime: string;
|
|
37
|
+
size: number;
|
|
38
|
+
}
|
|
39
|
+
export interface MediaBlockProps extends EditorBlockProps {
|
|
40
|
+
url?: string;
|
|
41
|
+
src?: string;
|
|
42
|
+
displaySrc?: string;
|
|
43
|
+
fileBinary?: Uint8Array | number[];
|
|
44
|
+
mediaRef?: DraftMediaRef;
|
|
45
|
+
name?: string;
|
|
46
|
+
width?: string;
|
|
47
|
+
defaultOpen?: string;
|
|
48
|
+
size?: string;
|
|
49
|
+
alignment?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface EditorImageBlock extends EditorBaseBlock {
|
|
52
|
+
type: 'image';
|
|
53
|
+
props: MediaBlockProps;
|
|
54
|
+
content: Array<HMInlineContent>;
|
|
55
|
+
}
|
|
56
|
+
export interface EditorVideoBlock extends EditorBaseBlock {
|
|
57
|
+
type: 'video';
|
|
58
|
+
props: MediaBlockProps;
|
|
59
|
+
content: Array<HMInlineContent>;
|
|
60
|
+
}
|
|
61
|
+
export interface EditorFileBlock extends EditorBaseBlock {
|
|
62
|
+
type: 'file';
|
|
63
|
+
props: MediaBlockProps;
|
|
64
|
+
content: Array<HMInlineContent>;
|
|
65
|
+
}
|
|
66
|
+
export interface EditorButtonBlock extends EditorBaseBlock {
|
|
67
|
+
type: 'button';
|
|
68
|
+
props: MediaBlockProps;
|
|
69
|
+
content: Array<HMInlineContent>;
|
|
70
|
+
}
|
|
71
|
+
export interface EditorEmbedBlock extends EditorBaseBlock {
|
|
72
|
+
type: 'embed';
|
|
73
|
+
props: EditorBlockProps & {
|
|
74
|
+
view: 'Content' | 'Card';
|
|
75
|
+
url: string;
|
|
76
|
+
};
|
|
77
|
+
content: Array<HMInlineContent>;
|
|
78
|
+
}
|
|
79
|
+
export interface EditorMathBlock extends EditorBaseBlock {
|
|
80
|
+
type: 'math';
|
|
81
|
+
content: Array<HMInlineContent>;
|
|
82
|
+
}
|
|
83
|
+
export type EditorWebEmbedBlock = EditorBaseBlock & {
|
|
84
|
+
type: 'web-embed';
|
|
85
|
+
props: EditorBlockProps & {
|
|
86
|
+
url?: string;
|
|
87
|
+
};
|
|
88
|
+
content: Array<HMInlineContent>;
|
|
89
|
+
};
|
|
90
|
+
export type EditorNostrBlock = EditorBaseBlock & {
|
|
91
|
+
type: 'nostr';
|
|
92
|
+
props: EditorBlockProps & {
|
|
93
|
+
name?: string;
|
|
94
|
+
url?: string;
|
|
95
|
+
text?: string;
|
|
96
|
+
size?: string;
|
|
97
|
+
};
|
|
98
|
+
content: Array<HMInlineContent>;
|
|
99
|
+
};
|
|
100
|
+
export type EditorQueryBlock = EditorBaseBlock & {
|
|
101
|
+
type: 'query';
|
|
102
|
+
props: EditorBlockProps & {
|
|
103
|
+
style: 'Card' | 'List';
|
|
104
|
+
columnCount?: '1' | '2' | '3';
|
|
105
|
+
queryLimit?: string;
|
|
106
|
+
queryIncludes?: string;
|
|
107
|
+
querySort?: string;
|
|
108
|
+
banner?: 'true' | 'false';
|
|
109
|
+
};
|
|
110
|
+
content: Array<HMInlineContent>;
|
|
111
|
+
};
|
|
112
|
+
export type EditorUnknownBlock = EditorBaseBlock & {
|
|
113
|
+
type: 'unknown';
|
|
114
|
+
props: EditorBlockProps & {
|
|
115
|
+
originalType: string;
|
|
116
|
+
originalData: string;
|
|
117
|
+
};
|
|
118
|
+
content: Array<HMInlineContent>;
|
|
119
|
+
};
|
|
120
|
+
export interface EditorText {
|
|
121
|
+
type: 'text';
|
|
122
|
+
text: string;
|
|
123
|
+
styles: EditorInlineStyles;
|
|
124
|
+
}
|
|
125
|
+
export interface EditorLink {
|
|
126
|
+
type: 'link';
|
|
127
|
+
href: string;
|
|
128
|
+
content: Array<HMInlineContent>;
|
|
129
|
+
}
|
|
130
|
+
export interface EditorInlineEmbed {
|
|
131
|
+
type: 'inline-embed';
|
|
132
|
+
link: string;
|
|
133
|
+
styles: EditorInlineStyles | {};
|
|
134
|
+
}
|
|
135
|
+
export interface EditorInlineStyles {
|
|
136
|
+
bold?: boolean;
|
|
137
|
+
italic?: boolean;
|
|
138
|
+
underline?: boolean;
|
|
139
|
+
strike?: boolean;
|
|
140
|
+
code?: boolean;
|
|
141
|
+
math?: boolean;
|
|
142
|
+
range?: boolean;
|
|
143
|
+
}
|
|
144
|
+
export type EditorAnnotationType = 'bold' | 'italic' | 'underline' | 'strike' | 'code' | 'link' | 'inline-embed' | 'range';
|
|
145
|
+
export type EditorBlockType = EditorBlock['type'];
|
|
146
|
+
export type SearchResult = {
|
|
147
|
+
key: string;
|
|
148
|
+
title: string;
|
|
149
|
+
subtitle?: string;
|
|
150
|
+
icon?: string;
|
|
151
|
+
path?: string[] | null;
|
|
152
|
+
versionTime?: string;
|
|
153
|
+
searchQuery?: string;
|
|
154
|
+
onSelect?: () => void | Promise<void>;
|
|
155
|
+
onFocus: () => void;
|
|
156
|
+
onMouseEnter: () => void;
|
|
157
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EditorBlock } from './editor-types';
|
|
2
|
+
import { HMBlock, HMBlockNode } from './hm-types';
|
|
3
|
+
/** Convert a single BlockNote EditorBlock into an HMBlock. */
|
|
4
|
+
export declare function editorBlockToHMBlock(editorBlock: EditorBlock): HMBlock;
|
|
5
|
+
/**
|
|
6
|
+
* Convert an array of BlockNote EditorBlocks into an HMBlockNode tree.
|
|
7
|
+
*
|
|
8
|
+
* This is the tree-level wrapper around `editorBlockToHMBlock` that recursively
|
|
9
|
+
* converts children. Useful when serializing editor content to the HM block format
|
|
10
|
+
* (e.g. for saving drafts as markdown or publishing documents).
|
|
11
|
+
*/
|
|
12
|
+
export declare function editorBlocksToHMBlockNodes(editorBlocks: EditorBlock[]): HMBlockNode[];
|
package/dist/hm-types.d.ts
CHANGED
|
@@ -12314,6 +12314,23 @@ export declare const HMDraftMetaSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12314
12314
|
importTags?: string | undefined;
|
|
12315
12315
|
}>;
|
|
12316
12316
|
visibility: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "PUBLIC" | "PRIVATE", string | number>>>;
|
|
12317
|
+
deps: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
12318
|
+
navigation: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12319
|
+
type: z.ZodLiteral<"Link">;
|
|
12320
|
+
id: z.ZodString;
|
|
12321
|
+
text: z.ZodString;
|
|
12322
|
+
link: z.ZodString;
|
|
12323
|
+
}, "strip", z.ZodTypeAny, {
|
|
12324
|
+
link: string;
|
|
12325
|
+
type: "Link";
|
|
12326
|
+
id: string;
|
|
12327
|
+
text: string;
|
|
12328
|
+
}, {
|
|
12329
|
+
link: string;
|
|
12330
|
+
type: "Link";
|
|
12331
|
+
id: string;
|
|
12332
|
+
text: string;
|
|
12333
|
+
}>, "many">>;
|
|
12317
12334
|
}, "strip", z.ZodTypeAny, {
|
|
12318
12335
|
id: string;
|
|
12319
12336
|
visibility: "PUBLIC" | "PRIVATE";
|
|
@@ -12338,6 +12355,13 @@ export declare const HMDraftMetaSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12338
12355
|
importCategories?: string | undefined;
|
|
12339
12356
|
importTags?: string | undefined;
|
|
12340
12357
|
};
|
|
12358
|
+
deps: string[];
|
|
12359
|
+
navigation?: {
|
|
12360
|
+
link: string;
|
|
12361
|
+
type: "Link";
|
|
12362
|
+
id: string;
|
|
12363
|
+
text: string;
|
|
12364
|
+
}[] | undefined;
|
|
12341
12365
|
locationUid?: string | undefined;
|
|
12342
12366
|
locationPath?: string[] | undefined;
|
|
12343
12367
|
editUid?: string | undefined;
|
|
@@ -12366,6 +12390,13 @@ export declare const HMDraftMetaSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12366
12390
|
importTags?: string | undefined;
|
|
12367
12391
|
};
|
|
12368
12392
|
visibility?: string | number | undefined;
|
|
12393
|
+
deps?: string[] | undefined;
|
|
12394
|
+
navigation?: {
|
|
12395
|
+
link: string;
|
|
12396
|
+
type: "Link";
|
|
12397
|
+
id: string;
|
|
12398
|
+
text: string;
|
|
12399
|
+
}[] | undefined;
|
|
12369
12400
|
locationUid?: string | undefined;
|
|
12370
12401
|
locationPath?: string[] | undefined;
|
|
12371
12402
|
editUid?: string | undefined;
|
|
@@ -12394,6 +12425,13 @@ export declare const HMDraftMetaSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12394
12425
|
importCategories?: string | undefined;
|
|
12395
12426
|
importTags?: string | undefined;
|
|
12396
12427
|
};
|
|
12428
|
+
deps: string[];
|
|
12429
|
+
navigation?: {
|
|
12430
|
+
link: string;
|
|
12431
|
+
type: "Link";
|
|
12432
|
+
id: string;
|
|
12433
|
+
text: string;
|
|
12434
|
+
}[] | undefined;
|
|
12397
12435
|
locationUid?: string | undefined;
|
|
12398
12436
|
locationPath?: string[] | undefined;
|
|
12399
12437
|
editUid?: string | undefined;
|
|
@@ -12422,6 +12460,13 @@ export declare const HMDraftMetaSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12422
12460
|
importTags?: string | undefined;
|
|
12423
12461
|
};
|
|
12424
12462
|
visibility?: string | number | undefined;
|
|
12463
|
+
deps?: string[] | undefined;
|
|
12464
|
+
navigation?: {
|
|
12465
|
+
link: string;
|
|
12466
|
+
type: "Link";
|
|
12467
|
+
id: string;
|
|
12468
|
+
text: string;
|
|
12469
|
+
}[] | undefined;
|
|
12425
12470
|
locationUid?: string | undefined;
|
|
12426
12471
|
locationPath?: string[] | undefined;
|
|
12427
12472
|
editUid?: string | undefined;
|
|
@@ -12433,6 +12478,8 @@ type HMDraftMetaBase = {
|
|
|
12433
12478
|
editPath?: string[];
|
|
12434
12479
|
metadata: HMMetadata;
|
|
12435
12480
|
visibility: HMResourceVisibility;
|
|
12481
|
+
deps: string[];
|
|
12482
|
+
navigation?: HMNavigationItem[];
|
|
12436
12483
|
};
|
|
12437
12484
|
export type HMDraftMeta = HMDraftMetaBase & ({
|
|
12438
12485
|
editUid: string;
|
|
@@ -12513,6 +12560,23 @@ export declare const HMListedDraftSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12513
12560
|
importTags?: string | undefined;
|
|
12514
12561
|
}>;
|
|
12515
12562
|
visibility: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "PUBLIC" | "PRIVATE", string | number>>>;
|
|
12563
|
+
deps: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
12564
|
+
navigation: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12565
|
+
type: z.ZodLiteral<"Link">;
|
|
12566
|
+
id: z.ZodString;
|
|
12567
|
+
text: z.ZodString;
|
|
12568
|
+
link: z.ZodString;
|
|
12569
|
+
}, "strip", z.ZodTypeAny, {
|
|
12570
|
+
link: string;
|
|
12571
|
+
type: "Link";
|
|
12572
|
+
id: string;
|
|
12573
|
+
text: string;
|
|
12574
|
+
}, {
|
|
12575
|
+
link: string;
|
|
12576
|
+
type: "Link";
|
|
12577
|
+
id: string;
|
|
12578
|
+
text: string;
|
|
12579
|
+
}>, "many">>;
|
|
12516
12580
|
} & {
|
|
12517
12581
|
lastUpdateTime: z.ZodNumber;
|
|
12518
12582
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -12540,6 +12604,13 @@ export declare const HMListedDraftSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12540
12604
|
importTags?: string | undefined;
|
|
12541
12605
|
};
|
|
12542
12606
|
lastUpdateTime: number;
|
|
12607
|
+
deps: string[];
|
|
12608
|
+
navigation?: {
|
|
12609
|
+
link: string;
|
|
12610
|
+
type: "Link";
|
|
12611
|
+
id: string;
|
|
12612
|
+
text: string;
|
|
12613
|
+
}[] | undefined;
|
|
12543
12614
|
locationUid?: string | undefined;
|
|
12544
12615
|
locationPath?: string[] | undefined;
|
|
12545
12616
|
editUid?: string | undefined;
|
|
@@ -12569,6 +12640,13 @@ export declare const HMListedDraftSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12569
12640
|
};
|
|
12570
12641
|
lastUpdateTime: number;
|
|
12571
12642
|
visibility?: string | number | undefined;
|
|
12643
|
+
deps?: string[] | undefined;
|
|
12644
|
+
navigation?: {
|
|
12645
|
+
link: string;
|
|
12646
|
+
type: "Link";
|
|
12647
|
+
id: string;
|
|
12648
|
+
text: string;
|
|
12649
|
+
}[] | undefined;
|
|
12572
12650
|
locationUid?: string | undefined;
|
|
12573
12651
|
locationPath?: string[] | undefined;
|
|
12574
12652
|
editUid?: string | undefined;
|
|
@@ -12598,6 +12676,13 @@ export declare const HMListedDraftSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12598
12676
|
importTags?: string | undefined;
|
|
12599
12677
|
};
|
|
12600
12678
|
lastUpdateTime: number;
|
|
12679
|
+
deps: string[];
|
|
12680
|
+
navigation?: {
|
|
12681
|
+
link: string;
|
|
12682
|
+
type: "Link";
|
|
12683
|
+
id: string;
|
|
12684
|
+
text: string;
|
|
12685
|
+
}[] | undefined;
|
|
12601
12686
|
locationUid?: string | undefined;
|
|
12602
12687
|
locationPath?: string[] | undefined;
|
|
12603
12688
|
editUid?: string | undefined;
|
|
@@ -12627,6 +12712,13 @@ export declare const HMListedDraftSchema: z.ZodEffects<z.ZodObject<{
|
|
|
12627
12712
|
};
|
|
12628
12713
|
lastUpdateTime: number;
|
|
12629
12714
|
visibility?: string | number | undefined;
|
|
12715
|
+
deps?: string[] | undefined;
|
|
12716
|
+
navigation?: {
|
|
12717
|
+
link: string;
|
|
12718
|
+
type: "Link";
|
|
12719
|
+
id: string;
|
|
12720
|
+
text: string;
|
|
12721
|
+
}[] | undefined;
|
|
12630
12722
|
locationUid?: string | undefined;
|
|
12631
12723
|
locationPath?: string[] | undefined;
|
|
12632
12724
|
editUid?: string | undefined;
|
|
@@ -12704,6 +12796,23 @@ export declare const HMListedDraftReadSchema: z.ZodObject<{
|
|
|
12704
12796
|
importTags?: string | undefined;
|
|
12705
12797
|
}>;
|
|
12706
12798
|
visibility: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "PUBLIC" | "PRIVATE", string | number>>>;
|
|
12799
|
+
deps: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
12800
|
+
navigation: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12801
|
+
type: z.ZodLiteral<"Link">;
|
|
12802
|
+
id: z.ZodString;
|
|
12803
|
+
text: z.ZodString;
|
|
12804
|
+
link: z.ZodString;
|
|
12805
|
+
}, "strip", z.ZodTypeAny, {
|
|
12806
|
+
link: string;
|
|
12807
|
+
type: "Link";
|
|
12808
|
+
id: string;
|
|
12809
|
+
text: string;
|
|
12810
|
+
}, {
|
|
12811
|
+
link: string;
|
|
12812
|
+
type: "Link";
|
|
12813
|
+
id: string;
|
|
12814
|
+
text: string;
|
|
12815
|
+
}>, "many">>;
|
|
12707
12816
|
} & {
|
|
12708
12817
|
lastUpdateTime: z.ZodNumber;
|
|
12709
12818
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -12731,6 +12840,13 @@ export declare const HMListedDraftReadSchema: z.ZodObject<{
|
|
|
12731
12840
|
importTags?: string | undefined;
|
|
12732
12841
|
};
|
|
12733
12842
|
lastUpdateTime: number;
|
|
12843
|
+
deps: string[];
|
|
12844
|
+
navigation?: {
|
|
12845
|
+
link: string;
|
|
12846
|
+
type: "Link";
|
|
12847
|
+
id: string;
|
|
12848
|
+
text: string;
|
|
12849
|
+
}[] | undefined;
|
|
12734
12850
|
locationUid?: string | undefined;
|
|
12735
12851
|
locationPath?: string[] | undefined;
|
|
12736
12852
|
editUid?: string | undefined;
|
|
@@ -12760,6 +12876,13 @@ export declare const HMListedDraftReadSchema: z.ZodObject<{
|
|
|
12760
12876
|
};
|
|
12761
12877
|
lastUpdateTime: number;
|
|
12762
12878
|
visibility?: string | number | undefined;
|
|
12879
|
+
deps?: string[] | undefined;
|
|
12880
|
+
navigation?: {
|
|
12881
|
+
link: string;
|
|
12882
|
+
type: "Link";
|
|
12883
|
+
id: string;
|
|
12884
|
+
text: string;
|
|
12885
|
+
}[] | undefined;
|
|
12763
12886
|
locationUid?: string | undefined;
|
|
12764
12887
|
locationPath?: string[] | undefined;
|
|
12765
12888
|
editUid?: string | undefined;
|
package/dist/hm-types.mjs
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EditorBlock } from './editor-types';
|
|
2
|
+
import { HMBlock, HMBlockChildrenType, HMBlockNode } from './hm-types';
|
|
3
|
+
import type { SpanAnnotation } from './unicode';
|
|
4
|
+
type ServerToEditorRecursiveOpts = {
|
|
5
|
+
level?: number;
|
|
6
|
+
};
|
|
7
|
+
/** Convert an array of HMBlockNode trees into BlockNote EditorBlock arrays. */
|
|
8
|
+
export declare function hmBlocksToEditorContent(blocks: HMBlockNode[], opts?: ServerToEditorRecursiveOpts & {
|
|
9
|
+
childrenType?: HMBlockChildrenType;
|
|
10
|
+
listLevel?: string;
|
|
11
|
+
start?: string;
|
|
12
|
+
}): Array<EditorBlock>;
|
|
13
|
+
/** Convert a single HMBlock into a BlockNote EditorBlock. */
|
|
14
|
+
export declare function hmBlockToEditorBlock(block: HMBlock): EditorBlock;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a position expressed in code points is within any span
|
|
17
|
+
* of this annotation.
|
|
18
|
+
*
|
|
19
|
+
* Assumes starts and ends arrays are sorted (binary search).
|
|
20
|
+
* Returns the index of the matching span, or -1.
|
|
21
|
+
*/
|
|
22
|
+
export declare function annotationContains(annotation: SpanAnnotation, pos: number): number;
|
|
23
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export { codePointLength, entityQueryPathToHmIdPath, getHMQueryString, hmIdPathT
|
|
|
24
24
|
export type { HMRequest, HMSigner, UnpackedHypermediaId } from './hm-types';
|
|
25
25
|
export { fileToIpfsBlobs, filesToIpfsBlobs, resolveFileLinksInBlocks, hasFileLinks } from './file-to-ipfs';
|
|
26
26
|
export type { CollectedBlob } from './file-to-ipfs';
|
|
27
|
-
export { parseMarkdown, flattenToOperations, parseInlineFormatting, parseFrontmatter } from './markdown-to-blocks';
|
|
27
|
+
export { parseMarkdown, flattenToOperations, parseInlineFormatting, parseFrontmatter, markdownBlockNodesToHMBlockNodes, } from './markdown-to-blocks';
|
|
28
28
|
export type { BlockNode, SeedBlock, Annotation } from './markdown-to-blocks';
|
|
29
|
-
export { blocksToMarkdown, emitFrontmatter } from './blocks-to-markdown';
|
|
29
|
+
export { blocksToMarkdown, emitFrontmatter, slugify, draftFilename, parseDraftFilename } from './blocks-to-markdown';
|
|
30
30
|
export type { BlocksToMarkdownOptions } from './blocks-to-markdown';
|
|
31
31
|
export { createBlocksMap, matchBlockIds, computeReplaceOps, hmBlockNodeToBlockNode } from './block-diff';
|
|
32
32
|
export type { APIBlockNode, APIBlock } from './block-diff';
|
|
@@ -34,3 +34,8 @@ export { autoLinkChildToParent, createAutoLinkOps, documentContainsLinkToChild,
|
|
|
34
34
|
export type { AutoLinkChildToParentOptions } from './auto-link';
|
|
35
35
|
export { resolveDocumentState } from './document-state';
|
|
36
36
|
export type { DocumentState } from './document-state';
|
|
37
|
+
export { editorBlockToHMBlock, editorBlocksToHMBlockNodes } from './editorblock-to-hmblock';
|
|
38
|
+
export { hmBlocksToEditorContent, hmBlockToEditorBlock, annotationContains } from './hmblock-to-editorblock';
|
|
39
|
+
export { AnnotationSet, addSpanToAnnotation, pushSpanToAnnotation } from './unicode';
|
|
40
|
+
export type { MutableAnnotation, SpanAnnotation } from './unicode';
|
|
41
|
+
export type { EditorBlock, EditorBaseBlock, EditorBlockProps, EditorBlockType, EditorParagraphBlock, EditorHeadingBlock, EditorCodeBlock, EditorImageBlock, EditorVideoBlock, EditorFileBlock, EditorButtonBlock, EditorEmbedBlock, EditorWebEmbedBlock, EditorMathBlock, EditorNostrBlock, EditorQueryBlock, EditorUnknownBlock, EditorText, EditorLink, EditorInlineEmbed, EditorInlineStyles, EditorAnnotationType, HMInlineContent, MediaBlockProps, DraftMediaRef, SearchResult, } from './editor-types';
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HMActionSchema,
|
|
3
|
+
HMBlockButtonAlignmentSchema,
|
|
4
|
+
HMBlockSchema,
|
|
3
5
|
HMRequestSchema,
|
|
4
6
|
HYPERMEDIA_SCHEME,
|
|
5
7
|
codePointLength,
|
|
@@ -12,8 +14,9 @@ import {
|
|
|
12
14
|
parseCustomURL,
|
|
13
15
|
parseFragment,
|
|
14
16
|
serializeBlockRange,
|
|
17
|
+
toNumber,
|
|
15
18
|
unpackHmId
|
|
16
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-YIND2WNJ.mjs";
|
|
17
20
|
|
|
18
21
|
// src/capability.ts
|
|
19
22
|
import { encode as cborEncode2 } from "@ipld/dag-cbor";
|
|
@@ -2517,6 +2520,37 @@ function parseMarkdown(markdown) {
|
|
|
2517
2520
|
}
|
|
2518
2521
|
return { tree: rootNodes, metadata };
|
|
2519
2522
|
}
|
|
2523
|
+
function markdownBlockNodesToHMBlockNodes(nodes) {
|
|
2524
|
+
return nodes.map((node) => {
|
|
2525
|
+
const { block } = node;
|
|
2526
|
+
const attributes = {};
|
|
2527
|
+
if (block.childrenType !== void 0) {
|
|
2528
|
+
attributes.childrenType = block.childrenType;
|
|
2529
|
+
}
|
|
2530
|
+
if (block.language !== void 0) {
|
|
2531
|
+
attributes.language = block.language;
|
|
2532
|
+
}
|
|
2533
|
+
const hmBlock = {
|
|
2534
|
+
type: block.type,
|
|
2535
|
+
id: block.id,
|
|
2536
|
+
text: block.text,
|
|
2537
|
+
annotations: block.annotations.map((a) => ({
|
|
2538
|
+
type: a.type,
|
|
2539
|
+
starts: a.starts,
|
|
2540
|
+
ends: a.ends,
|
|
2541
|
+
...a.link !== void 0 ? { link: a.link } : {}
|
|
2542
|
+
})),
|
|
2543
|
+
attributes
|
|
2544
|
+
};
|
|
2545
|
+
if (block.link !== void 0) {
|
|
2546
|
+
hmBlock.link = block.link;
|
|
2547
|
+
}
|
|
2548
|
+
return {
|
|
2549
|
+
block: hmBlock,
|
|
2550
|
+
children: node.children.length > 0 ? markdownBlockNodesToHMBlockNodes(node.children) : void 0
|
|
2551
|
+
};
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2520
2554
|
function flattenToOperations(tree, parentId = "") {
|
|
2521
2555
|
const ops = [];
|
|
2522
2556
|
const blockIds = [];
|
|
@@ -2777,6 +2811,23 @@ function formatMediaUrl(url, useGateway) {
|
|
|
2777
2811
|
function indent(depth) {
|
|
2778
2812
|
return " ".repeat(depth);
|
|
2779
2813
|
}
|
|
2814
|
+
function slugify(title) {
|
|
2815
|
+
return title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
|
|
2816
|
+
}
|
|
2817
|
+
function draftFilename(slug, id) {
|
|
2818
|
+
if (!slug) return `${id}.md`;
|
|
2819
|
+
return `${slug}_${id}.md`;
|
|
2820
|
+
}
|
|
2821
|
+
function parseDraftFilename(filename) {
|
|
2822
|
+
const lastDot = filename.lastIndexOf(".");
|
|
2823
|
+
const ext = lastDot >= 0 ? filename.slice(lastDot) : "";
|
|
2824
|
+
const base = lastDot >= 0 ? filename.slice(0, lastDot) : filename;
|
|
2825
|
+
const lastUnderscore = base.lastIndexOf("_");
|
|
2826
|
+
if (lastUnderscore >= 0 && ext === ".md") {
|
|
2827
|
+
return { id: base.slice(lastUnderscore + 1), ext };
|
|
2828
|
+
}
|
|
2829
|
+
return { id: base, ext };
|
|
2830
|
+
}
|
|
2780
2831
|
|
|
2781
2832
|
// src/block-diff.ts
|
|
2782
2833
|
function createBlocksMap(nodes, parentId = "") {
|
|
@@ -3140,12 +3191,640 @@ function generateBlockId5() {
|
|
|
3140
3191
|
}
|
|
3141
3192
|
return id;
|
|
3142
3193
|
}
|
|
3194
|
+
|
|
3195
|
+
// src/unicode.ts
|
|
3196
|
+
var AnnotationSet = class {
|
|
3197
|
+
annotations;
|
|
3198
|
+
constructor() {
|
|
3199
|
+
this.annotations = /* @__PURE__ */ new Map();
|
|
3200
|
+
}
|
|
3201
|
+
addSpan(type, attributes, start, end) {
|
|
3202
|
+
const id = this._annotationId(type, attributes);
|
|
3203
|
+
let annotation = this.annotations.get(id);
|
|
3204
|
+
if (!annotation) {
|
|
3205
|
+
const annAttrs = attributes ? { ...attributes } : {};
|
|
3206
|
+
let link;
|
|
3207
|
+
if (type == "Link" || type == "Embed") {
|
|
3208
|
+
link = attributes == null ? void 0 : attributes.link;
|
|
3209
|
+
delete annAttrs.link;
|
|
3210
|
+
}
|
|
3211
|
+
annotation = {
|
|
3212
|
+
type,
|
|
3213
|
+
attributes: annAttrs,
|
|
3214
|
+
link: link || "",
|
|
3215
|
+
starts: [],
|
|
3216
|
+
ends: []
|
|
3217
|
+
};
|
|
3218
|
+
this.annotations.set(id, annotation);
|
|
3219
|
+
}
|
|
3220
|
+
addSpanToAnnotation(annotation, start, end);
|
|
3221
|
+
}
|
|
3222
|
+
_annotationId(type, attributes) {
|
|
3223
|
+
if (attributes) {
|
|
3224
|
+
if (attributes.link) {
|
|
3225
|
+
return `${type}-${attributes.link}`;
|
|
3226
|
+
}
|
|
3227
|
+
if (attributes.href) {
|
|
3228
|
+
return `${type}-${attributes.href}`;
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return type;
|
|
3232
|
+
}
|
|
3233
|
+
list() {
|
|
3234
|
+
const keys = Array.from(this.annotations.keys()).sort();
|
|
3235
|
+
let out = new Array(keys.length);
|
|
3236
|
+
for (let i in keys) {
|
|
3237
|
+
const annotation = this.annotations.get(keys[i]);
|
|
3238
|
+
if (annotation) out[i] = annotation;
|
|
3239
|
+
}
|
|
3240
|
+
out = out.sort((a, b) => {
|
|
3241
|
+
let startA = a.starts[0];
|
|
3242
|
+
let startB = b.starts[0];
|
|
3243
|
+
return (startA || 0) - (startB || 0);
|
|
3244
|
+
});
|
|
3245
|
+
return out;
|
|
3246
|
+
}
|
|
3247
|
+
};
|
|
3248
|
+
function addSpanToAnnotation(annotation, start, end) {
|
|
3249
|
+
if (!annotation.starts) {
|
|
3250
|
+
annotation.starts = [];
|
|
3251
|
+
}
|
|
3252
|
+
if (!annotation.ends) {
|
|
3253
|
+
annotation.ends = [];
|
|
3254
|
+
}
|
|
3255
|
+
if (annotation.starts.length == 0) {
|
|
3256
|
+
pushSpanToAnnotation(annotation, start, end);
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
const lastIdx = annotation.starts.length - 1;
|
|
3260
|
+
if (annotation.ends[lastIdx] == start) {
|
|
3261
|
+
annotation.ends[lastIdx] = end;
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
pushSpanToAnnotation(annotation, start, end);
|
|
3265
|
+
}
|
|
3266
|
+
function pushSpanToAnnotation(annotation, start, end) {
|
|
3267
|
+
annotation.starts.push(start);
|
|
3268
|
+
annotation.ends.push(end);
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
// src/editorblock-to-hmblock.ts
|
|
3272
|
+
function toHMBlockType(editorBlockType) {
|
|
3273
|
+
if (editorBlockType === "heading") return "Heading";
|
|
3274
|
+
if (editorBlockType === "paragraph") return "Paragraph";
|
|
3275
|
+
if (editorBlockType === "code-block") return "Code";
|
|
3276
|
+
if (editorBlockType === "math") return "Math";
|
|
3277
|
+
if (editorBlockType === "image") return "Image";
|
|
3278
|
+
if (editorBlockType === "video") return "Video";
|
|
3279
|
+
if (editorBlockType === "file") return "File";
|
|
3280
|
+
if (editorBlockType === "button") return "Button";
|
|
3281
|
+
if (editorBlockType === "embed") return "Embed";
|
|
3282
|
+
if (editorBlockType === "web-embed") return "WebEmbed";
|
|
3283
|
+
if (editorBlockType === "query") return "Query";
|
|
3284
|
+
return void 0;
|
|
3285
|
+
}
|
|
3286
|
+
function editorBlockToHMBlock(editorBlock) {
|
|
3287
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3288
|
+
const blockType = toHMBlockType(editorBlock.type);
|
|
3289
|
+
if (!blockType) throw new Error("Unsupported block type " + editorBlock.type);
|
|
3290
|
+
let block = {
|
|
3291
|
+
id: editorBlock.id,
|
|
3292
|
+
type: blockType,
|
|
3293
|
+
attributes: {},
|
|
3294
|
+
text: "",
|
|
3295
|
+
annotations: []
|
|
3296
|
+
};
|
|
3297
|
+
let leaves = flattenLeaves(editorBlock.content);
|
|
3298
|
+
if (editorBlock.props.childrenType == "Group") {
|
|
3299
|
+
block.attributes.childrenType = "Group";
|
|
3300
|
+
} else if (editorBlock.props.childrenType == "Unordered") {
|
|
3301
|
+
block.attributes.childrenType = "Unordered";
|
|
3302
|
+
} else if (editorBlock.props.childrenType == "Ordered") {
|
|
3303
|
+
block.attributes.childrenType = "Ordered";
|
|
3304
|
+
} else if (editorBlock.props.childrenType == "Blockquote") {
|
|
3305
|
+
block.attributes.childrenType = "Blockquote";
|
|
3306
|
+
} else if (editorBlock.props.childrenType == "Grid") {
|
|
3307
|
+
block.attributes.childrenType = "Grid";
|
|
3308
|
+
if (editorBlock.props.columnCount) {
|
|
3309
|
+
block.attributes.columnCount = Number(editorBlock.props.columnCount);
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
const annotations = new AnnotationSet();
|
|
3313
|
+
let pos = 0;
|
|
3314
|
+
for (let leaf of leaves) {
|
|
3315
|
+
const start = pos;
|
|
3316
|
+
const charCount = codePointLength(leaf.text);
|
|
3317
|
+
const end = start + charCount;
|
|
3318
|
+
if ((_a = leaf.styles) == null ? void 0 : _a.bold) {
|
|
3319
|
+
annotations.addSpan("Bold", null, start, end);
|
|
3320
|
+
}
|
|
3321
|
+
if ((_b = leaf.styles) == null ? void 0 : _b.italic) {
|
|
3322
|
+
annotations.addSpan("Italic", null, start, end);
|
|
3323
|
+
}
|
|
3324
|
+
if ((_c = leaf.styles) == null ? void 0 : _c.underline) {
|
|
3325
|
+
annotations.addSpan("Underline", null, start, end);
|
|
3326
|
+
}
|
|
3327
|
+
if ((_d = leaf.styles) == null ? void 0 : _d.strike) {
|
|
3328
|
+
annotations.addSpan("Strike", null, start, end);
|
|
3329
|
+
}
|
|
3330
|
+
if ((_e = leaf.styles) == null ? void 0 : _e.code) {
|
|
3331
|
+
annotations.addSpan("Code", null, start, end);
|
|
3332
|
+
}
|
|
3333
|
+
if ((_f = leaf.styles) == null ? void 0 : _f.math) {
|
|
3334
|
+
annotations.addSpan("Math", null, start, end);
|
|
3335
|
+
}
|
|
3336
|
+
if (leaf.type == "inline-embed") {
|
|
3337
|
+
annotations.addSpan("Embed", { link: leaf.link }, start, end);
|
|
3338
|
+
}
|
|
3339
|
+
if (leaf.type == "link") {
|
|
3340
|
+
annotations.addSpan("Link", { link: leaf.href }, start, end);
|
|
3341
|
+
}
|
|
3342
|
+
block.text += leaf.text;
|
|
3343
|
+
pos += charCount;
|
|
3344
|
+
}
|
|
3345
|
+
let outAnnotations = annotations.list();
|
|
3346
|
+
if (outAnnotations) {
|
|
3347
|
+
block.annotations = outAnnotations;
|
|
3348
|
+
}
|
|
3349
|
+
const blockCode = block.type === "Code" ? block : void 0;
|
|
3350
|
+
if (blockCode && editorBlock.type == "code-block") {
|
|
3351
|
+
blockCode.attributes.language = editorBlock.props.language;
|
|
3352
|
+
}
|
|
3353
|
+
const blockImage = block.type === "Image" ? block : void 0;
|
|
3354
|
+
if (blockImage && editorBlock.type == "image") {
|
|
3355
|
+
if (editorBlock.props.url && !editorBlock.props.mediaRef) {
|
|
3356
|
+
blockImage.link = editorBlock.props.url;
|
|
3357
|
+
} else if (editorBlock.props.mediaRef) {
|
|
3358
|
+
blockImage.link = "";
|
|
3359
|
+
} else if (editorBlock.props.displaySrc) {
|
|
3360
|
+
blockImage.link = editorBlock.props.displaySrc;
|
|
3361
|
+
} else if (editorBlock.props.src) {
|
|
3362
|
+
blockImage.link = editorBlock.props.src;
|
|
3363
|
+
} else {
|
|
3364
|
+
blockImage.link = "";
|
|
3365
|
+
}
|
|
3366
|
+
const width = toNumber(editorBlock.props.width);
|
|
3367
|
+
if (width) {
|
|
3368
|
+
blockImage.attributes.width = width;
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
const blockVideo = block.type === "Video" ? block : void 0;
|
|
3372
|
+
if (blockVideo && editorBlock.type == "video") {
|
|
3373
|
+
blockVideo.text = "";
|
|
3374
|
+
if (editorBlock.props.url && !editorBlock.props.mediaRef) {
|
|
3375
|
+
blockVideo.link = editorBlock.props.url;
|
|
3376
|
+
} else if (editorBlock.props.mediaRef) {
|
|
3377
|
+
blockVideo.link = "";
|
|
3378
|
+
}
|
|
3379
|
+
const width = toNumber(editorBlock.props.width);
|
|
3380
|
+
if (width) blockVideo.attributes.width = width;
|
|
3381
|
+
if (editorBlock.props.name) {
|
|
3382
|
+
blockVideo.attributes.name = editorBlock.props.name;
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
const blockFile = block.type === "File" ? block : void 0;
|
|
3386
|
+
if (blockFile && editorBlock.type == "file") {
|
|
3387
|
+
if (editorBlock.props.url && !editorBlock.props.mediaRef) {
|
|
3388
|
+
blockFile.link = editorBlock.props.url;
|
|
3389
|
+
} else if (editorBlock.props.mediaRef) {
|
|
3390
|
+
blockFile.link = "";
|
|
3391
|
+
}
|
|
3392
|
+
if (editorBlock.props.name) blockFile.attributes.name = editorBlock.props.name;
|
|
3393
|
+
const size = toNumber(editorBlock.props.size);
|
|
3394
|
+
if (size) blockFile.attributes.size = size;
|
|
3395
|
+
}
|
|
3396
|
+
const blockButton = block.type === "Button" ? block : void 0;
|
|
3397
|
+
if (blockButton && editorBlock.type == "button") {
|
|
3398
|
+
if (editorBlock.props.url) blockButton.link = editorBlock.props.url;
|
|
3399
|
+
if (editorBlock.props.name) blockButton.attributes.name = editorBlock.props.name;
|
|
3400
|
+
if (editorBlock.props.alignment)
|
|
3401
|
+
blockButton.attributes.alignment = HMBlockButtonAlignmentSchema.parse(editorBlock.props.alignment);
|
|
3402
|
+
}
|
|
3403
|
+
const blockWebEmbed = block.type === "WebEmbed" ? block : void 0;
|
|
3404
|
+
if (blockWebEmbed && editorBlock.type == "web-embed" && editorBlock.props.url) {
|
|
3405
|
+
blockWebEmbed.link = editorBlock.props.url;
|
|
3406
|
+
}
|
|
3407
|
+
const blockEmbed = block.type === "Embed" ? block : void 0;
|
|
3408
|
+
if (blockEmbed && editorBlock.type == "embed") {
|
|
3409
|
+
block.text = "";
|
|
3410
|
+
if (editorBlock.props.url) blockEmbed.link = editorBlock.props.url;
|
|
3411
|
+
if (editorBlock.props.view) blockEmbed.attributes.view = editorBlock.props.view;
|
|
3412
|
+
}
|
|
3413
|
+
const blockQuery = block.type === "Query" ? block : void 0;
|
|
3414
|
+
if (blockQuery && editorBlock.type == "query") {
|
|
3415
|
+
blockQuery.attributes.style = editorBlock.props.style;
|
|
3416
|
+
blockQuery.attributes.columnCount = Number(editorBlock.props.columnCount);
|
|
3417
|
+
const query = {
|
|
3418
|
+
includes: [],
|
|
3419
|
+
sort: []
|
|
3420
|
+
};
|
|
3421
|
+
if (editorBlock.props.queryIncludes) query.includes = JSON.parse(editorBlock.props.queryIncludes);
|
|
3422
|
+
if (editorBlock.props.querySort) query.sort = JSON.parse(editorBlock.props.querySort);
|
|
3423
|
+
if (editorBlock.props.queryLimit) query.limit = Number(editorBlock.props.queryLimit);
|
|
3424
|
+
blockQuery.attributes.query = query;
|
|
3425
|
+
blockQuery.attributes.banner = editorBlock.props.banner == "true";
|
|
3426
|
+
}
|
|
3427
|
+
const blockParse = HMBlockSchema.safeParse(block);
|
|
3428
|
+
if (blockParse.success) {
|
|
3429
|
+
return blockParse.data;
|
|
3430
|
+
}
|
|
3431
|
+
const failedParse = blockParse;
|
|
3432
|
+
console.error("Failed to validate block for writing", block, failedParse.error);
|
|
3433
|
+
throw new Error("Failed to validate block for writing " + JSON.stringify(failedParse.error));
|
|
3434
|
+
}
|
|
3435
|
+
function editorBlocksToHMBlockNodes(editorBlocks) {
|
|
3436
|
+
return editorBlocks.map((block) => {
|
|
3437
|
+
var _a, _b;
|
|
3438
|
+
try {
|
|
3439
|
+
return {
|
|
3440
|
+
block: editorBlockToHMBlock(block),
|
|
3441
|
+
children: ((_a = block.children) == null ? void 0 : _a.length) ? editorBlocksToHMBlockNodes(block.children) : void 0
|
|
3442
|
+
};
|
|
3443
|
+
} catch {
|
|
3444
|
+
return {
|
|
3445
|
+
block: {
|
|
3446
|
+
id: block.id || "unknown",
|
|
3447
|
+
type: "Paragraph",
|
|
3448
|
+
text: `[Unsupported block type: ${block.type}]`,
|
|
3449
|
+
annotations: [],
|
|
3450
|
+
attributes: {}
|
|
3451
|
+
},
|
|
3452
|
+
children: ((_b = block.children) == null ? void 0 : _b.length) ? editorBlocksToHMBlockNodes(block.children) : void 0
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
}).filter(Boolean);
|
|
3456
|
+
}
|
|
3457
|
+
function flattenLeaves(content) {
|
|
3458
|
+
let result = [];
|
|
3459
|
+
for (let i = 0; i < content.length; i++) {
|
|
3460
|
+
const leaf = content[i];
|
|
3461
|
+
if (!leaf) continue;
|
|
3462
|
+
if (leaf.type == "link") {
|
|
3463
|
+
let nestedLeaves = flattenLeaves(leaf.content).map(
|
|
3464
|
+
(l) => ({
|
|
3465
|
+
...l,
|
|
3466
|
+
href: leaf.href,
|
|
3467
|
+
type: "link"
|
|
3468
|
+
})
|
|
3469
|
+
);
|
|
3470
|
+
result.push(...nestedLeaves);
|
|
3471
|
+
}
|
|
3472
|
+
if (leaf.type == "inline-embed") {
|
|
3473
|
+
result.push({
|
|
3474
|
+
...leaf,
|
|
3475
|
+
text: "\uFFFC",
|
|
3476
|
+
link: leaf.link
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3479
|
+
if (leaf.type == "text") {
|
|
3480
|
+
result.push(leaf);
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
return result;
|
|
3484
|
+
}
|
|
3485
|
+
|
|
3486
|
+
// src/hmblock-to-editorblock.ts
|
|
3487
|
+
function toEditorBlockType(hmBlockType) {
|
|
3488
|
+
if (hmBlockType === "Heading") return "heading";
|
|
3489
|
+
if (hmBlockType === "Paragraph") return "paragraph";
|
|
3490
|
+
if (hmBlockType === "Code") return "code-block";
|
|
3491
|
+
if (hmBlockType === "Math") return "math";
|
|
3492
|
+
if (hmBlockType === "Image") return "image";
|
|
3493
|
+
if (hmBlockType === "Video") return "video";
|
|
3494
|
+
if (hmBlockType === "File") return "file";
|
|
3495
|
+
if (hmBlockType === "Button") return "button";
|
|
3496
|
+
if (hmBlockType === "Embed") return "embed";
|
|
3497
|
+
if (hmBlockType === "WebEmbed") return "web-embed";
|
|
3498
|
+
if (hmBlockType === "Nostr") return "nostr";
|
|
3499
|
+
if (hmBlockType === "Query") return "query";
|
|
3500
|
+
return "unknown";
|
|
3501
|
+
}
|
|
3502
|
+
function hmBlocksToEditorContent(blocks, opts = { level: 1 }) {
|
|
3503
|
+
const childRecursiveOpts = {
|
|
3504
|
+
level: opts.level || 0
|
|
3505
|
+
};
|
|
3506
|
+
return blocks.map((hmBlock) => {
|
|
3507
|
+
var _a, _b, _c;
|
|
3508
|
+
let res = hmBlock.block ? hmBlockToEditorBlock(hmBlock.block) : null;
|
|
3509
|
+
if (res && ((_a = hmBlock.children) == null ? void 0 : _a.length)) {
|
|
3510
|
+
const childrenType = (_c = ((_b = hmBlock.block) == null ? void 0 : _b.attributes) || {}) == null ? void 0 : _c.childrenType;
|
|
3511
|
+
const validChildrenType = childrenType === "Group" || childrenType === "Ordered" || childrenType === "Unordered" || childrenType === "Blockquote" || childrenType === "Grid" ? childrenType : "Group";
|
|
3512
|
+
res.children = hmBlocksToEditorContent(hmBlock.children, {
|
|
3513
|
+
level: childRecursiveOpts.level ? childRecursiveOpts.level + 1 : 1,
|
|
3514
|
+
childrenType: validChildrenType
|
|
3515
|
+
});
|
|
3516
|
+
}
|
|
3517
|
+
return res;
|
|
3518
|
+
}).filter((block) => block !== null);
|
|
3519
|
+
}
|
|
3520
|
+
function hmBlockToEditorBlock(block) {
|
|
3521
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
3522
|
+
const blockType = toEditorBlockType(block.type);
|
|
3523
|
+
if (blockType === "unknown") {
|
|
3524
|
+
return {
|
|
3525
|
+
id: block.id,
|
|
3526
|
+
type: "unknown",
|
|
3527
|
+
content: [],
|
|
3528
|
+
props: {
|
|
3529
|
+
revision: block.revision,
|
|
3530
|
+
originalType: block.type,
|
|
3531
|
+
originalData: JSON.stringify(block)
|
|
3532
|
+
},
|
|
3533
|
+
children: []
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
let out = {
|
|
3537
|
+
id: block.id,
|
|
3538
|
+
type: blockType,
|
|
3539
|
+
content: [],
|
|
3540
|
+
props: {
|
|
3541
|
+
revision: block.revision
|
|
3542
|
+
},
|
|
3543
|
+
children: []
|
|
3544
|
+
};
|
|
3545
|
+
const attributes = block.attributes || {};
|
|
3546
|
+
if ("childrenType" in attributes && attributes.childrenType) {
|
|
3547
|
+
const childrenType = attributes.childrenType;
|
|
3548
|
+
if (childrenType === "Group" || childrenType === "Ordered" || childrenType === "Unordered" || childrenType === "Blockquote" || childrenType === "Grid") {
|
|
3549
|
+
;
|
|
3550
|
+
out.props.childrenType = childrenType;
|
|
3551
|
+
}
|
|
3552
|
+
if (childrenType === "Grid" && attributes.columnCount != null) {
|
|
3553
|
+
;
|
|
3554
|
+
out.props.columnCount = String(attributes.columnCount);
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
if (["code-block", "video", "image", "file", "button", "embed", "web-embed", "math", "nostr"].includes(blockType)) {
|
|
3558
|
+
if (block.link) {
|
|
3559
|
+
;
|
|
3560
|
+
out.props.url = block.link;
|
|
3561
|
+
}
|
|
3562
|
+
if (blockType == "code-block") {
|
|
3563
|
+
out.type = "code-block";
|
|
3564
|
+
}
|
|
3565
|
+
if (block.attributes) {
|
|
3566
|
+
Object.entries(block.attributes).forEach(([key, value]) => {
|
|
3567
|
+
if (value !== void 0) {
|
|
3568
|
+
if (key == "width" || key == "size") {
|
|
3569
|
+
if (typeof value == "number") {
|
|
3570
|
+
;
|
|
3571
|
+
out.props[key] = String(value);
|
|
3572
|
+
}
|
|
3573
|
+
} else {
|
|
3574
|
+
;
|
|
3575
|
+
out.props[key] = value;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
});
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
if (block.type === "Query") {
|
|
3582
|
+
const queryProps = out.props;
|
|
3583
|
+
queryProps.style = (_a = block.attributes) == null ? void 0 : _a.style;
|
|
3584
|
+
queryProps.columnCount = String(((_b = block.attributes) == null ? void 0 : _b.columnCount) || "");
|
|
3585
|
+
queryProps.queryIncludes = JSON.stringify(((_d = (_c = block.attributes) == null ? void 0 : _c.query) == null ? void 0 : _d.includes) || []);
|
|
3586
|
+
queryProps.querySort = JSON.stringify(((_f = (_e = block.attributes) == null ? void 0 : _e.query) == null ? void 0 : _f.sort) || {});
|
|
3587
|
+
queryProps.banner = ((_g = block.attributes) == null ? void 0 : _g.banner) ? "true" : "false";
|
|
3588
|
+
queryProps.queryLimit = String(((_i = (_h = block.attributes) == null ? void 0 : _h.query) == null ? void 0 : _i.limit) || "");
|
|
3589
|
+
}
|
|
3590
|
+
const blockText = block.text || "";
|
|
3591
|
+
const leaves = out.content;
|
|
3592
|
+
let leaf = null;
|
|
3593
|
+
let inlineBlockContent = null;
|
|
3594
|
+
let textStart = 0;
|
|
3595
|
+
let i = 0;
|
|
3596
|
+
const stopPoint = block.text ? block.text.length - 1 : 0;
|
|
3597
|
+
let pos = 0;
|
|
3598
|
+
const leafAnnotations = /* @__PURE__ */ new Set();
|
|
3599
|
+
if (blockText == "") {
|
|
3600
|
+
leaves.push({ type: "text", text: blockText, styles: {} });
|
|
3601
|
+
return out;
|
|
3602
|
+
}
|
|
3603
|
+
while (i < blockText.length) {
|
|
3604
|
+
let ul = 1;
|
|
3605
|
+
let annotationsChanged = trackPosAnnotations(pos);
|
|
3606
|
+
let surrogate = isSurrogate(blockText, i);
|
|
3607
|
+
if (surrogate) {
|
|
3608
|
+
ul++;
|
|
3609
|
+
let onlyOneSurrogate = pos + ul;
|
|
3610
|
+
if (onlyOneSurrogate == blockText.length) {
|
|
3611
|
+
if (!leaf) {
|
|
3612
|
+
startLeaf(leafAnnotations);
|
|
3613
|
+
}
|
|
3614
|
+
finishLeaf(textStart, i + 2);
|
|
3615
|
+
if (inlineBlockContent) {
|
|
3616
|
+
const lastLeaf = leaves[leaves.length - 1];
|
|
3617
|
+
if (lastLeaf && !isText(lastLeaf)) {
|
|
3618
|
+
}
|
|
3619
|
+
leaves.push(inlineBlockContent);
|
|
3620
|
+
inlineBlockContent = null;
|
|
3621
|
+
}
|
|
3622
|
+
return out;
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
if (stopPoint < 0) {
|
|
3626
|
+
console.warn("STOP IS LESS THAN ZERO", block);
|
|
3627
|
+
}
|
|
3628
|
+
if (i == stopPoint) {
|
|
3629
|
+
if (annotationsChanged) {
|
|
3630
|
+
if (leaf) {
|
|
3631
|
+
finishLeaf(textStart, i);
|
|
3632
|
+
}
|
|
3633
|
+
startLeaf(leafAnnotations);
|
|
3634
|
+
} else {
|
|
3635
|
+
startLeaf(leafAnnotations);
|
|
3636
|
+
}
|
|
3637
|
+
finishLeaf(textStart, i + 1);
|
|
3638
|
+
if (inlineBlockContent) {
|
|
3639
|
+
const lastLeaf = leaves[leaves.length - 1];
|
|
3640
|
+
if (lastLeaf && !isText(lastLeaf)) {
|
|
3641
|
+
}
|
|
3642
|
+
leaves.push(inlineBlockContent);
|
|
3643
|
+
inlineBlockContent = null;
|
|
3644
|
+
}
|
|
3645
|
+
return out;
|
|
3646
|
+
}
|
|
3647
|
+
if (!leaf) {
|
|
3648
|
+
startLeaf(leafAnnotations);
|
|
3649
|
+
advance(ul);
|
|
3650
|
+
continue;
|
|
3651
|
+
}
|
|
3652
|
+
if (annotationsChanged) {
|
|
3653
|
+
finishLeaf(textStart, i);
|
|
3654
|
+
startLeaf(leafAnnotations);
|
|
3655
|
+
}
|
|
3656
|
+
advance(ul);
|
|
3657
|
+
if (i == blockText.length) {
|
|
3658
|
+
finishLeaf(textStart, i);
|
|
3659
|
+
return out;
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
throw Error("BUG: should not get here");
|
|
3663
|
+
function advance(codeUnits) {
|
|
3664
|
+
pos++;
|
|
3665
|
+
i += codeUnits;
|
|
3666
|
+
}
|
|
3667
|
+
function startLeaf(posAnnotations) {
|
|
3668
|
+
const newLeaf = {
|
|
3669
|
+
type: "text",
|
|
3670
|
+
text: "",
|
|
3671
|
+
styles: {}
|
|
3672
|
+
};
|
|
3673
|
+
leaf = newLeaf;
|
|
3674
|
+
let linkAnnotation = null;
|
|
3675
|
+
for (const l of Array.from(posAnnotations)) {
|
|
3676
|
+
const annotationData = l;
|
|
3677
|
+
if (annotationData.type === "Link") {
|
|
3678
|
+
linkAnnotation = {
|
|
3679
|
+
type: "Link",
|
|
3680
|
+
href: annotationData.link || ""
|
|
3681
|
+
};
|
|
3682
|
+
}
|
|
3683
|
+
if (annotationData.type === "Embed") {
|
|
3684
|
+
linkAnnotation = {
|
|
3685
|
+
type: "Embed",
|
|
3686
|
+
link: annotationData.link || ""
|
|
3687
|
+
};
|
|
3688
|
+
}
|
|
3689
|
+
if (["Bold", "Italic", "Strike", "Underline", "Code", "Range"].includes(annotationData.type)) {
|
|
3690
|
+
const styleKey = annotationData.type.toLowerCase();
|
|
3691
|
+
newLeaf.styles[styleKey] = true;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
if (linkAnnotation) {
|
|
3695
|
+
if (linkAnnotation.type === "Embed") {
|
|
3696
|
+
leaves.push({
|
|
3697
|
+
type: "inline-embed",
|
|
3698
|
+
styles: {},
|
|
3699
|
+
link: linkAnnotation.link || ""
|
|
3700
|
+
});
|
|
3701
|
+
textStart = i + 1;
|
|
3702
|
+
} else if (inlineBlockContent) {
|
|
3703
|
+
if (linkChangedIdentity(linkAnnotation)) {
|
|
3704
|
+
leaves.push(inlineBlockContent);
|
|
3705
|
+
if (linkAnnotation.type === "Link") {
|
|
3706
|
+
inlineBlockContent = {
|
|
3707
|
+
type: "link",
|
|
3708
|
+
content: [],
|
|
3709
|
+
href: linkAnnotation.href || ""
|
|
3710
|
+
};
|
|
3711
|
+
} else {
|
|
3712
|
+
inlineBlockContent = {
|
|
3713
|
+
type: "inline-embed",
|
|
3714
|
+
styles: {},
|
|
3715
|
+
link: linkAnnotation.link || ""
|
|
3716
|
+
};
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
} else {
|
|
3720
|
+
if (linkAnnotation.type === "Link") {
|
|
3721
|
+
inlineBlockContent = {
|
|
3722
|
+
type: "link",
|
|
3723
|
+
content: [],
|
|
3724
|
+
href: linkAnnotation.href || ""
|
|
3725
|
+
};
|
|
3726
|
+
} else {
|
|
3727
|
+
inlineBlockContent = {
|
|
3728
|
+
type: "inline-embed",
|
|
3729
|
+
styles: {},
|
|
3730
|
+
link: linkAnnotation.link || ""
|
|
3731
|
+
};
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
} else {
|
|
3735
|
+
if (inlineBlockContent) {
|
|
3736
|
+
leaves.push(inlineBlockContent);
|
|
3737
|
+
inlineBlockContent = null;
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
function linkChangedIdentity(annotation) {
|
|
3742
|
+
if (!inlineBlockContent) return false;
|
|
3743
|
+
let currentLink = inlineBlockContent.link || inlineBlockContent.href;
|
|
3744
|
+
return currentLink != annotation.link && currentLink != annotation.href;
|
|
3745
|
+
}
|
|
3746
|
+
function finishLeaf(low, high) {
|
|
3747
|
+
let newValue = blockText.substring(low, high);
|
|
3748
|
+
if (leaf) leaf.text = newValue;
|
|
3749
|
+
textStart = high;
|
|
3750
|
+
if (inlineBlockContent) {
|
|
3751
|
+
if (leaf && inlineBlockContent.type == "link") {
|
|
3752
|
+
;
|
|
3753
|
+
inlineBlockContent.content.push(leaf);
|
|
3754
|
+
} else if (inlineBlockContent.type == "inline-embed" && leaf) {
|
|
3755
|
+
} else if (leaf) {
|
|
3756
|
+
const typedLeaf = {
|
|
3757
|
+
type: "text",
|
|
3758
|
+
text: "",
|
|
3759
|
+
styles: leaf.styles
|
|
3760
|
+
};
|
|
3761
|
+
inlineBlockContent.content.push(typedLeaf);
|
|
3762
|
+
}
|
|
3763
|
+
} else {
|
|
3764
|
+
if (leaf && !(leaf.type === "text" && leaf.text === "" && Object.keys(leaf.styles).length === 0)) {
|
|
3765
|
+
leaves.push(leaf);
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
function trackPosAnnotations(pos2) {
|
|
3770
|
+
let annotationsChanged = false;
|
|
3771
|
+
if (!block.annotations) {
|
|
3772
|
+
return false;
|
|
3773
|
+
}
|
|
3774
|
+
const blockAnnotations = block.annotations;
|
|
3775
|
+
blockAnnotations.forEach((l) => {
|
|
3776
|
+
let spanIdx = annotationContains(l, pos2);
|
|
3777
|
+
if (spanIdx === -1) {
|
|
3778
|
+
if (leafAnnotations.delete(l)) {
|
|
3779
|
+
annotationsChanged = true;
|
|
3780
|
+
}
|
|
3781
|
+
return;
|
|
3782
|
+
}
|
|
3783
|
+
if (leafAnnotations.has(l)) {
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3786
|
+
leafAnnotations.add(l);
|
|
3787
|
+
annotationsChanged = true;
|
|
3788
|
+
});
|
|
3789
|
+
return annotationsChanged;
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
function annotationContains(annotation, pos) {
|
|
3793
|
+
let low = 0;
|
|
3794
|
+
let high = annotation.starts.length - 1;
|
|
3795
|
+
let mid = 0;
|
|
3796
|
+
while (low <= high) {
|
|
3797
|
+
mid = Math.floor((low + high) / 2);
|
|
3798
|
+
const endAtMid = annotation.ends[mid];
|
|
3799
|
+
if (endAtMid === void 0) break;
|
|
3800
|
+
if (endAtMid <= pos) {
|
|
3801
|
+
low = mid + 1;
|
|
3802
|
+
} else {
|
|
3803
|
+
high = mid - 1;
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
if (low == annotation.starts.length) {
|
|
3807
|
+
return -1;
|
|
3808
|
+
}
|
|
3809
|
+
const startAtLow = annotation.starts[low];
|
|
3810
|
+
const endAtLow = annotation.ends[low];
|
|
3811
|
+
if (startAtLow !== void 0 && endAtLow !== void 0 && startAtLow <= pos && pos < endAtLow) {
|
|
3812
|
+
return low;
|
|
3813
|
+
}
|
|
3814
|
+
return -1;
|
|
3815
|
+
}
|
|
3816
|
+
function isText(entry) {
|
|
3817
|
+
return (entry == null ? void 0 : entry.type) && entry.type == "text" && typeof entry.text == "string";
|
|
3818
|
+
}
|
|
3143
3819
|
export {
|
|
3820
|
+
AnnotationSet,
|
|
3144
3821
|
DEFAULT_GROBID_URL,
|
|
3145
3822
|
HYPERMEDIA_SCHEME,
|
|
3146
3823
|
SeedClientError,
|
|
3147
3824
|
SeedNetworkError,
|
|
3148
3825
|
SeedValidationError,
|
|
3826
|
+
addSpanToAnnotation,
|
|
3827
|
+
annotationContains,
|
|
3149
3828
|
autoLinkChildToParent,
|
|
3150
3829
|
blocksToMarkdown,
|
|
3151
3830
|
codePointLength,
|
|
@@ -3170,6 +3849,9 @@ export {
|
|
|
3170
3849
|
deleteContact,
|
|
3171
3850
|
documentContainsLinkToChild,
|
|
3172
3851
|
documentHasSelfQuery,
|
|
3852
|
+
draftFilename,
|
|
3853
|
+
editorBlockToHMBlock,
|
|
3854
|
+
editorBlocksToHMBlockNodes,
|
|
3173
3855
|
embeddedPdfToBlocks,
|
|
3174
3856
|
emitFrontmatter,
|
|
3175
3857
|
entityQueryPathToHmIdPath,
|
|
@@ -3179,25 +3861,31 @@ export {
|
|
|
3179
3861
|
getHMQueryString,
|
|
3180
3862
|
hasFileLinks,
|
|
3181
3863
|
hmBlockNodeToBlockNode,
|
|
3864
|
+
hmBlockToEditorBlock,
|
|
3865
|
+
hmBlocksToEditorContent,
|
|
3182
3866
|
hmIdPathToEntityQueryPath,
|
|
3183
3867
|
isGrobidAvailable,
|
|
3184
3868
|
isSurrogate,
|
|
3869
|
+
markdownBlockNodesToHMBlockNodes,
|
|
3185
3870
|
matchBlockIds,
|
|
3186
3871
|
packBaseId,
|
|
3187
3872
|
packHmId,
|
|
3188
3873
|
parseCustomURL,
|
|
3874
|
+
parseDraftFilename,
|
|
3189
3875
|
parseFragment,
|
|
3190
3876
|
parseFrontmatter,
|
|
3191
3877
|
parseInlineFormatting,
|
|
3192
3878
|
parseMarkdown,
|
|
3193
3879
|
pdfToBlocks,
|
|
3194
3880
|
processFulltextDocument,
|
|
3881
|
+
pushSpanToAnnotation,
|
|
3195
3882
|
resolveDocumentState,
|
|
3196
3883
|
resolveFileLinksInBlocks,
|
|
3197
3884
|
serializeBlockRange,
|
|
3198
3885
|
shouldAutoLinkParent,
|
|
3199
3886
|
signDocumentChange,
|
|
3200
3887
|
signPreparedChange,
|
|
3888
|
+
slugify,
|
|
3201
3889
|
teiToBlocks,
|
|
3202
3890
|
trimTrailingEmptyBlocks,
|
|
3203
3891
|
unpackHmId,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - Block ID preservation via <!-- id:XXXXXXXX --> HTML comments
|
|
14
14
|
* - `title:` as backward-compatible alias for `name:` in frontmatter
|
|
15
15
|
*/
|
|
16
|
-
import type { HMMetadata } from './hm-types';
|
|
16
|
+
import type { HMBlockNode, HMMetadata } from './hm-types';
|
|
17
17
|
import type { DocumentOperation } from './change';
|
|
18
18
|
export type Annotation = {
|
|
19
19
|
type: string;
|
|
@@ -74,6 +74,15 @@ export declare function parseMarkdown(markdown: string): {
|
|
|
74
74
|
tree: BlockNode[];
|
|
75
75
|
metadata: HMMetadata;
|
|
76
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Convert the markdown parser's BlockNode tree into HMBlockNode tree.
|
|
79
|
+
*
|
|
80
|
+
* Maps flat SeedBlock properties (childrenType, language) into the
|
|
81
|
+
* HMBlock attributes object, and annotations into the HMAnnotation shape.
|
|
82
|
+
* The resulting tree can be fed into `hmBlocksToEditorContent()` to get
|
|
83
|
+
* BlockNote editor blocks.
|
|
84
|
+
*/
|
|
85
|
+
export declare function markdownBlockNodesToHMBlockNodes(nodes: BlockNode[]): HMBlockNode[];
|
|
77
86
|
/**
|
|
78
87
|
* Flattens a block tree into Seed document operations.
|
|
79
88
|
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HMAnnotations } from './hm-types';
|
|
2
|
+
/**
|
|
3
|
+
* Mutable annotation shape used during construction.
|
|
4
|
+
* Structurally compatible with HMAnnotation but uses plain objects
|
|
5
|
+
* instead of protobuf classes.
|
|
6
|
+
*/
|
|
7
|
+
export interface MutableAnnotation {
|
|
8
|
+
type: string;
|
|
9
|
+
link?: string;
|
|
10
|
+
attributes?: Record<string, unknown>;
|
|
11
|
+
starts: number[];
|
|
12
|
+
ends: number[];
|
|
13
|
+
}
|
|
14
|
+
/** Minimal annotation shape required by span-position helpers. */
|
|
15
|
+
export interface SpanAnnotation {
|
|
16
|
+
starts: number[];
|
|
17
|
+
ends: number[];
|
|
18
|
+
}
|
|
19
|
+
export declare class AnnotationSet {
|
|
20
|
+
annotations: Map<string, MutableAnnotation>;
|
|
21
|
+
constructor();
|
|
22
|
+
addSpan(type: string, attributes: {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
} | null, start: number, end: number): void;
|
|
25
|
+
_annotationId(type: string, attributes: {
|
|
26
|
+
[key: string]: string;
|
|
27
|
+
} | null): string;
|
|
28
|
+
list(): HMAnnotations;
|
|
29
|
+
}
|
|
30
|
+
/** Append a span to an annotation, merging with the previous span if adjacent. */
|
|
31
|
+
export declare function addSpanToAnnotation(annotation: SpanAnnotation, start: number, end: number): void;
|
|
32
|
+
/** Push a span to an annotation without checking adjacency. */
|
|
33
|
+
export declare function pushSpanToAnnotation(annotation: SpanAnnotation, start: number, end: number): void;
|
|
34
|
+
/** @deprecated Import from `@seed-hypermedia/client/hm-types` instead. */
|
|
35
|
+
export { codePointLength, isSurrogate } from './hm-types';
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -54,9 +54,15 @@ export type {HMRequest, HMSigner, UnpackedHypermediaId} from './hm-types'
|
|
|
54
54
|
export {fileToIpfsBlobs, filesToIpfsBlobs, resolveFileLinksInBlocks, hasFileLinks} from './file-to-ipfs'
|
|
55
55
|
export type {CollectedBlob} from './file-to-ipfs'
|
|
56
56
|
|
|
57
|
-
export {
|
|
57
|
+
export {
|
|
58
|
+
parseMarkdown,
|
|
59
|
+
flattenToOperations,
|
|
60
|
+
parseInlineFormatting,
|
|
61
|
+
parseFrontmatter,
|
|
62
|
+
markdownBlockNodesToHMBlockNodes,
|
|
63
|
+
} from './markdown-to-blocks'
|
|
58
64
|
export type {BlockNode, SeedBlock, Annotation} from './markdown-to-blocks'
|
|
59
|
-
export {blocksToMarkdown, emitFrontmatter} from './blocks-to-markdown'
|
|
65
|
+
export {blocksToMarkdown, emitFrontmatter, slugify, draftFilename, parseDraftFilename} from './blocks-to-markdown'
|
|
60
66
|
export type {BlocksToMarkdownOptions} from './blocks-to-markdown'
|
|
61
67
|
|
|
62
68
|
export {createBlocksMap, matchBlockIds, computeReplaceOps, hmBlockNodeToBlockNode} from './block-diff'
|
|
@@ -72,3 +78,36 @@ export {
|
|
|
72
78
|
export type {AutoLinkChildToParentOptions} from './auto-link'
|
|
73
79
|
export {resolveDocumentState} from './document-state'
|
|
74
80
|
export type {DocumentState} from './document-state'
|
|
81
|
+
|
|
82
|
+
export {editorBlockToHMBlock, editorBlocksToHMBlockNodes} from './editorblock-to-hmblock'
|
|
83
|
+
export {hmBlocksToEditorContent, hmBlockToEditorBlock, annotationContains} from './hmblock-to-editorblock'
|
|
84
|
+
export {AnnotationSet, addSpanToAnnotation, pushSpanToAnnotation} from './unicode'
|
|
85
|
+
export type {MutableAnnotation, SpanAnnotation} from './unicode'
|
|
86
|
+
export type {
|
|
87
|
+
EditorBlock,
|
|
88
|
+
EditorBaseBlock,
|
|
89
|
+
EditorBlockProps,
|
|
90
|
+
EditorBlockType,
|
|
91
|
+
EditorParagraphBlock,
|
|
92
|
+
EditorHeadingBlock,
|
|
93
|
+
EditorCodeBlock,
|
|
94
|
+
EditorImageBlock,
|
|
95
|
+
EditorVideoBlock,
|
|
96
|
+
EditorFileBlock,
|
|
97
|
+
EditorButtonBlock,
|
|
98
|
+
EditorEmbedBlock,
|
|
99
|
+
EditorWebEmbedBlock,
|
|
100
|
+
EditorMathBlock,
|
|
101
|
+
EditorNostrBlock,
|
|
102
|
+
EditorQueryBlock,
|
|
103
|
+
EditorUnknownBlock,
|
|
104
|
+
EditorText,
|
|
105
|
+
EditorLink,
|
|
106
|
+
EditorInlineEmbed,
|
|
107
|
+
EditorInlineStyles,
|
|
108
|
+
EditorAnnotationType,
|
|
109
|
+
HMInlineContent,
|
|
110
|
+
MediaBlockProps,
|
|
111
|
+
DraftMediaRef,
|
|
112
|
+
SearchResult,
|
|
113
|
+
} from './editor-types'
|