@notectl/core 0.0.8 → 0.0.10

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 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](http://localhost:4321/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. */
@@ -699,6 +705,12 @@ export declare interface InlineNodeSpec<T extends string = string> {
699
705
  readonly attrs?: Readonly<Record<string, AttrSpec>>;
700
706
  /** Group membership (default: 'inline'). For content rules. */
701
707
  readonly group?: string;
708
+ /** Serializes the inline node to an HTML string. */
709
+ readonly toHTMLString?: (node: InlineNode) => string;
710
+ /** Rules for matching HTML elements to this inline node type during parsing. */
711
+ readonly parseHTML?: readonly ParseRule[];
712
+ /** Tags and attributes this spec needs through DOMPurify sanitization. */
713
+ readonly sanitize?: SanitizeConfig;
702
714
  }
703
715
 
704
716
  export declare function inlineType(name: string): InlineTypeName;
@@ -920,6 +932,12 @@ export declare interface MarkSpec<T extends string = string> {
920
932
  /** Nesting priority — lower rank renders closer to the text content. */
921
933
  readonly rank?: number;
922
934
  readonly attrs?: Readonly<Record<string, AttrSpec>>;
935
+ /** Serializes the mark as an HTML wrapper. `content` is the pre-serialized inner HTML. */
936
+ readonly toHTMLString?: (mark: Mark, content: string) => string;
937
+ /** Rules for matching HTML elements to this mark type during parsing. */
938
+ readonly parseHTML?: readonly ParseRule[];
939
+ /** Tags and attributes this spec needs through DOMPurify sanitization. */
940
+ readonly sanitize?: SanitizeConfig;
923
941
  }
924
942
 
925
943
  /** @deprecated Use {@link MarkTypeName} for new code. */
@@ -993,6 +1011,14 @@ export declare interface NodeSpec<T extends string = string> {
993
1011
  readonly group?: string;
994
1012
  /** If true, selection cannot cross this node's boundary (e.g. table_cell). */
995
1013
  readonly isolating?: boolean;
1014
+ /** If true, node can be selected as an object via mouse interaction. */
1015
+ readonly selectable?: boolean;
1016
+ /** Serializes the block to an HTML string. `content` is the pre-serialized inline children. */
1017
+ readonly toHTML?: (node: BlockNode, content: string) => string;
1018
+ /** Rules for matching HTML elements to this block type during parsing. */
1019
+ readonly parseHTML?: readonly ParseRule[];
1020
+ /** Tags and attributes this spec needs through DOMPurify sanitization. */
1021
+ readonly sanitize?: SanitizeConfig;
996
1022
  }
997
1023
 
998
1024
  /** @deprecated Use {@link NodeTypeName} for new code. */
@@ -1109,10 +1135,10 @@ export declare class NotectlEditor extends HTMLElement {
1109
1135
  private updateEmptyState;
1110
1136
  private announceFormatChange;
1111
1137
  private replaceState;
1112
- private blockToHTML;
1113
- private textNodeToHTML;
1138
+ private serializeBlock;
1139
+ private serializeInlineContent;
1140
+ private serializeTextNode;
1114
1141
  private getMarkOrder;
1115
- private escapeHTML;
1116
1142
  private parseHTMLToDocument;
1117
1143
  private parseElementToTextNodes;
1118
1144
  private walkElement;
@@ -1134,6 +1160,17 @@ export declare interface NotectlEditorConfig {
1134
1160
  maxHistoryDepth?: number;
1135
1161
  }
1136
1162
 
1163
+ /**
1164
+ * ParseRule: describes how an HTML element maps to a document node or mark.
1165
+ * Used by plugins to declare their HTML parsing behavior.
1166
+ */
1167
+ export declare interface ParseRule {
1168
+ readonly tag: string;
1169
+ readonly getAttrs?: (el: HTMLElement) => Record<string, unknown> | false;
1170
+ /** Higher priority rules are matched first. Default: 50. */
1171
+ readonly priority?: number;
1172
+ }
1173
+
1137
1174
  declare interface Plugin_2<TConfig extends Record<string, unknown> = Record<string, unknown>> {
1138
1175
  readonly id: string;
1139
1176
  readonly name: string;
@@ -1300,6 +1337,15 @@ export declare function resolveParentByPath(doc: Document_2, path: readonly stri
1300
1337
  index: number;
1301
1338
  } | undefined;
1302
1339
 
1340
+ /**
1341
+ * SanitizeConfig: declares which HTML tags and attributes a spec needs
1342
+ * to survive DOMPurify sanitization.
1343
+ */
1344
+ export declare interface SanitizeConfig {
1345
+ readonly tags?: readonly string[];
1346
+ readonly attrs?: readonly string[];
1347
+ }
1348
+
1303
1349
  export declare interface Schema {
1304
1350
  readonly nodeTypes: readonly string[];
1305
1351
  readonly markTypes: readonly string[];
@@ -1350,6 +1396,25 @@ export declare class SchemaRegistry {
1350
1396
  getFileHandlers(): readonly FileHandlerEntry[];
1351
1397
  matchFileHandlers(mimeType: string): FileHandler[];
1352
1398
  removeFileHandler(handler: FileHandler): void;
1399
+ /** Returns all NodeSpec parseHTML rules, sorted by priority descending. */
1400
+ getBlockParseRules(): readonly {
1401
+ readonly rule: ParseRule;
1402
+ readonly type: string;
1403
+ }[];
1404
+ /** Returns all InlineNodeSpec parseHTML rules, sorted by priority descending. */
1405
+ getInlineParseRules(): readonly {
1406
+ readonly rule: ParseRule;
1407
+ readonly type: string;
1408
+ }[];
1409
+ /** Returns all MarkSpec parseHTML rules, sorted by priority descending. */
1410
+ getMarkParseRules(): readonly {
1411
+ readonly rule: ParseRule;
1412
+ readonly type: string;
1413
+ }[];
1414
+ /** Returns all allowed HTML tags from base defaults + all spec sanitize configs. */
1415
+ getAllowedTags(): string[];
1416
+ /** Returns all allowed HTML attributes from base defaults + all spec sanitize configs. */
1417
+ getAllowedAttrs(): string[];
1353
1418
  clear(): void;
1354
1419
  }
1355
1420