@notectl/core 0.0.9 → 0.0.11
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/README.md +7 -0
- package/dist/index.d.ts +82 -3
- package/dist/notectl-core.js +11 -5
- package/dist/notectl-core.js.map +1 -1
- package/dist/notectl-core.mjs +1590 -1356
- package/dist/notectl-core.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,8 +32,15 @@ Most editors bolt formatting on top of `contenteditable` and hope for the best.
|
|
|
32
32
|
|
|
33
33
|
<br />
|
|
34
34
|
|
|
35
|
+
## Wanna try?
|
|
36
|
+
Check out the [live playground](https://samyssmile.github.io/notectl/playground/) — no install required.
|
|
37
|
+
|
|
38
|
+
## Wanna see full working example?
|
|
39
|
+
`examples/vanillajs/` is a great place to see everything in action.
|
|
40
|
+
|
|
35
41
|
## Quick Start
|
|
36
42
|
|
|
43
|
+
|
|
37
44
|
### Install
|
|
38
45
|
|
|
39
46
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -279,6 +279,12 @@ export declare class EditorState {
|
|
|
279
279
|
}, schema?: Schema): EditorState;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
/**
|
|
283
|
+
* HTML string escaping utilities shared across serialization and parsing.
|
|
284
|
+
*/
|
|
285
|
+
/** Escapes special HTML characters in text content. */
|
|
286
|
+
export declare function escapeHTML(text: string): string;
|
|
287
|
+
|
|
282
288
|
export declare class EventBus {
|
|
283
289
|
private readonly listeners;
|
|
284
290
|
/** Emits an event to all registered listeners. Errors are caught per listener. */
|
|
@@ -574,6 +580,16 @@ export declare class HeadingPlugin implements Plugin_2 {
|
|
|
574
580
|
*/
|
|
575
581
|
private toggleHeading;
|
|
576
582
|
private setBlockType;
|
|
583
|
+
/**
|
|
584
|
+
* Adds removeMark steps for each excluded mark type found
|
|
585
|
+
* on the block's inline text content.
|
|
586
|
+
*/
|
|
587
|
+
private stripExcludedMarks;
|
|
588
|
+
/**
|
|
589
|
+
* Clears excluded mark types from stored marks so that
|
|
590
|
+
* subsequent typing does not reintroduce them.
|
|
591
|
+
*/
|
|
592
|
+
private clearExcludedStoredMarks;
|
|
577
593
|
}
|
|
578
594
|
|
|
579
595
|
export declare interface HighlightConfig {
|
|
@@ -699,6 +715,12 @@ export declare interface InlineNodeSpec<T extends string = string> {
|
|
|
699
715
|
readonly attrs?: Readonly<Record<string, AttrSpec>>;
|
|
700
716
|
/** Group membership (default: 'inline'). For content rules. */
|
|
701
717
|
readonly group?: string;
|
|
718
|
+
/** Serializes the inline node to an HTML string. */
|
|
719
|
+
readonly toHTMLString?: (node: InlineNode) => string;
|
|
720
|
+
/** Rules for matching HTML elements to this inline node type during parsing. */
|
|
721
|
+
readonly parseHTML?: readonly ParseRule[];
|
|
722
|
+
/** Tags and attributes this spec needs through DOMPurify sanitization. */
|
|
723
|
+
readonly sanitize?: SanitizeConfig;
|
|
702
724
|
}
|
|
703
725
|
|
|
704
726
|
export declare function inlineType(name: string): InlineTypeName;
|
|
@@ -920,6 +942,12 @@ export declare interface MarkSpec<T extends string = string> {
|
|
|
920
942
|
/** Nesting priority — lower rank renders closer to the text content. */
|
|
921
943
|
readonly rank?: number;
|
|
922
944
|
readonly attrs?: Readonly<Record<string, AttrSpec>>;
|
|
945
|
+
/** Serializes the mark as an HTML wrapper. `content` is the pre-serialized inner HTML. */
|
|
946
|
+
readonly toHTMLString?: (mark: Mark, content: string) => string;
|
|
947
|
+
/** Rules for matching HTML elements to this mark type during parsing. */
|
|
948
|
+
readonly parseHTML?: readonly ParseRule[];
|
|
949
|
+
/** Tags and attributes this spec needs through DOMPurify sanitization. */
|
|
950
|
+
readonly sanitize?: SanitizeConfig;
|
|
923
951
|
}
|
|
924
952
|
|
|
925
953
|
/** @deprecated Use {@link MarkTypeName} for new code. */
|
|
@@ -995,6 +1023,18 @@ export declare interface NodeSpec<T extends string = string> {
|
|
|
995
1023
|
readonly isolating?: boolean;
|
|
996
1024
|
/** If true, node can be selected as an object via mouse interaction. */
|
|
997
1025
|
readonly selectable?: boolean;
|
|
1026
|
+
/**
|
|
1027
|
+
* Mark types that are incompatible with this block type.
|
|
1028
|
+
* When a block is converted to this type, marks listed here
|
|
1029
|
+
* are stripped from the block's inline content.
|
|
1030
|
+
*/
|
|
1031
|
+
readonly excludeMarks?: readonly string[];
|
|
1032
|
+
/** Serializes the block to an HTML string. `content` is the pre-serialized inline children. */
|
|
1033
|
+
readonly toHTML?: (node: BlockNode, content: string) => string;
|
|
1034
|
+
/** Rules for matching HTML elements to this block type during parsing. */
|
|
1035
|
+
readonly parseHTML?: readonly ParseRule[];
|
|
1036
|
+
/** Tags and attributes this spec needs through DOMPurify sanitization. */
|
|
1037
|
+
readonly sanitize?: SanitizeConfig;
|
|
998
1038
|
}
|
|
999
1039
|
|
|
1000
1040
|
/** @deprecated Use {@link NodeTypeName} for new code. */
|
|
@@ -1111,10 +1151,10 @@ export declare class NotectlEditor extends HTMLElement {
|
|
|
1111
1151
|
private updateEmptyState;
|
|
1112
1152
|
private announceFormatChange;
|
|
1113
1153
|
private replaceState;
|
|
1114
|
-
private
|
|
1115
|
-
private
|
|
1154
|
+
private serializeBlock;
|
|
1155
|
+
private serializeInlineContent;
|
|
1156
|
+
private serializeTextNode;
|
|
1116
1157
|
private getMarkOrder;
|
|
1117
|
-
private escapeHTML;
|
|
1118
1158
|
private parseHTMLToDocument;
|
|
1119
1159
|
private parseElementToTextNodes;
|
|
1120
1160
|
private walkElement;
|
|
@@ -1136,6 +1176,17 @@ export declare interface NotectlEditorConfig {
|
|
|
1136
1176
|
maxHistoryDepth?: number;
|
|
1137
1177
|
}
|
|
1138
1178
|
|
|
1179
|
+
/**
|
|
1180
|
+
* ParseRule: describes how an HTML element maps to a document node or mark.
|
|
1181
|
+
* Used by plugins to declare their HTML parsing behavior.
|
|
1182
|
+
*/
|
|
1183
|
+
export declare interface ParseRule {
|
|
1184
|
+
readonly tag: string;
|
|
1185
|
+
readonly getAttrs?: (el: HTMLElement) => Record<string, unknown> | false;
|
|
1186
|
+
/** Higher priority rules are matched first. Default: 50. */
|
|
1187
|
+
readonly priority?: number;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1139
1190
|
declare interface Plugin_2<TConfig extends Record<string, unknown> = Record<string, unknown>> {
|
|
1140
1191
|
readonly id: string;
|
|
1141
1192
|
readonly name: string;
|
|
@@ -1302,6 +1353,15 @@ export declare function resolveParentByPath(doc: Document_2, path: readonly stri
|
|
|
1302
1353
|
index: number;
|
|
1303
1354
|
} | undefined;
|
|
1304
1355
|
|
|
1356
|
+
/**
|
|
1357
|
+
* SanitizeConfig: declares which HTML tags and attributes a spec needs
|
|
1358
|
+
* to survive DOMPurify sanitization.
|
|
1359
|
+
*/
|
|
1360
|
+
export declare interface SanitizeConfig {
|
|
1361
|
+
readonly tags?: readonly string[];
|
|
1362
|
+
readonly attrs?: readonly string[];
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1305
1365
|
export declare interface Schema {
|
|
1306
1366
|
readonly nodeTypes: readonly string[];
|
|
1307
1367
|
readonly markTypes: readonly string[];
|
|
@@ -1352,6 +1412,25 @@ export declare class SchemaRegistry {
|
|
|
1352
1412
|
getFileHandlers(): readonly FileHandlerEntry[];
|
|
1353
1413
|
matchFileHandlers(mimeType: string): FileHandler[];
|
|
1354
1414
|
removeFileHandler(handler: FileHandler): void;
|
|
1415
|
+
/** Returns all NodeSpec parseHTML rules, sorted by priority descending. */
|
|
1416
|
+
getBlockParseRules(): readonly {
|
|
1417
|
+
readonly rule: ParseRule;
|
|
1418
|
+
readonly type: string;
|
|
1419
|
+
}[];
|
|
1420
|
+
/** Returns all InlineNodeSpec parseHTML rules, sorted by priority descending. */
|
|
1421
|
+
getInlineParseRules(): readonly {
|
|
1422
|
+
readonly rule: ParseRule;
|
|
1423
|
+
readonly type: string;
|
|
1424
|
+
}[];
|
|
1425
|
+
/** Returns all MarkSpec parseHTML rules, sorted by priority descending. */
|
|
1426
|
+
getMarkParseRules(): readonly {
|
|
1427
|
+
readonly rule: ParseRule;
|
|
1428
|
+
readonly type: string;
|
|
1429
|
+
}[];
|
|
1430
|
+
/** Returns all allowed HTML tags from base defaults + all spec sanitize configs. */
|
|
1431
|
+
getAllowedTags(): string[];
|
|
1432
|
+
/** Returns all allowed HTML attributes from base defaults + all spec sanitize configs. */
|
|
1433
|
+
getAllowedAttrs(): string[];
|
|
1355
1434
|
clear(): void;
|
|
1356
1435
|
}
|
|
1357
1436
|
|