@willwang-io/react-djot 0.1.5 → 0.1.6

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.d.ts CHANGED
@@ -2,6 +2,7 @@ import React from 'react';
2
2
 
3
3
  type DjotAttributes = Record<string, string>;
4
4
  interface DjotBaseNode {
5
+ autoAttributes?: DjotAttributes;
5
6
  attributes?: DjotAttributes;
6
7
  tag: string;
7
8
  }
@@ -9,13 +10,12 @@ interface DjotParentNode extends DjotBaseNode {
9
10
  children: DjotNode[];
10
11
  }
11
12
  interface DjotDocNode extends DjotParentNode {
12
- autoReferences?: Record<string, unknown>;
13
+ autoReferences?: Record<string, DjotReferenceNode>;
13
14
  footnotes?: Record<string, DjotFootnoteNode>;
14
- references?: Record<string, unknown>;
15
+ references?: Record<string, DjotReferenceNode>;
15
16
  tag: "doc";
16
17
  }
17
18
  interface DjotSectionNode extends DjotParentNode {
18
- autoAttributes?: DjotAttributes;
19
19
  tag: "section";
20
20
  }
21
21
  interface DjotDivNode extends DjotParentNode {
@@ -55,6 +55,9 @@ interface DjotInsertNode extends DjotParentNode {
55
55
  interface DjotDeleteNode extends DjotParentNode {
56
56
  tag: "delete";
57
57
  }
58
+ interface DjotSpanNode extends DjotParentNode {
59
+ tag: "span";
60
+ }
58
61
  type DjotTableAlignment = "default" | "left" | "right" | "center" | (string & {});
59
62
  interface DjotTableNode extends DjotParentNode {
60
63
  tag: "table";
@@ -108,24 +111,78 @@ interface DjotCodeBlockNode extends DjotBaseNode {
108
111
  tag: "code_block";
109
112
  text: string;
110
113
  }
111
- interface DjotLinkNode extends DjotParentNode {
114
+ interface DjotRawBlockNode extends DjotBaseNode {
115
+ format: string;
116
+ tag: "raw_block";
117
+ text: string;
118
+ }
119
+ interface DjotRawInlineNode extends DjotBaseNode {
120
+ format: string;
121
+ tag: "raw_inline";
122
+ text: string;
123
+ }
124
+ interface DjotSymbNode extends DjotBaseNode {
125
+ alias: string;
126
+ tag: "symb";
127
+ }
128
+ interface DjotUrlNode extends DjotBaseNode {
129
+ tag: "url";
130
+ text: string;
131
+ }
132
+ interface DjotEmailNode extends DjotBaseNode {
133
+ tag: "email";
134
+ text: string;
135
+ }
136
+ interface DjotReferenceNode extends DjotBaseNode {
112
137
  destination: string;
138
+ label: string;
139
+ tag: "reference";
140
+ }
141
+ interface DjotLinkNode extends DjotParentNode {
142
+ destination?: string;
143
+ reference?: string;
113
144
  tag: "link";
114
145
  }
115
146
  interface DjotImageNode extends DjotParentNode {
116
- destination: string;
147
+ destination?: string;
148
+ reference?: string;
117
149
  tag: "image";
118
150
  }
119
151
  interface DjotBulletListNode extends DjotParentNode {
152
+ tight?: boolean;
120
153
  tag: "bullet_list";
121
154
  }
155
+ type DjotOrderedListStyle = "1." | "1)" | "(1)" | "a." | "a)" | "(a)" | "A." | "A)" | "(A)" | "i." | "i)" | "(i)" | "I." | "I)" | "(I)" | (string & {});
122
156
  interface DjotOrderedListNode extends DjotParentNode {
123
157
  start?: number;
158
+ style?: DjotOrderedListStyle;
159
+ tight?: boolean;
124
160
  tag: "ordered_list";
125
161
  }
126
162
  interface DjotListItemNode extends DjotParentNode {
127
163
  tag: "list_item";
128
164
  }
165
+ interface DjotDefinitionListNode extends DjotParentNode {
166
+ tag: "definition_list";
167
+ }
168
+ interface DjotDefinitionListItemNode extends DjotParentNode {
169
+ tag: "definition_list_item";
170
+ }
171
+ interface DjotTermNode extends DjotParentNode {
172
+ tag: "term";
173
+ }
174
+ interface DjotDefinitionNode extends DjotParentNode {
175
+ tag: "definition";
176
+ }
177
+ type DjotCheckboxStatus = "checked" | "unchecked";
178
+ interface DjotTaskListNode extends DjotParentNode {
179
+ tag: "task_list";
180
+ tight?: boolean;
181
+ }
182
+ interface DjotTaskListItemNode extends DjotParentNode {
183
+ checkbox: DjotCheckboxStatus;
184
+ tag: "task_list_item";
185
+ }
129
186
  interface DjotBlockquoteNode extends DjotParentNode {
130
187
  tag: "blockquote";
131
188
  }
@@ -149,7 +206,10 @@ interface DjotSoftBreakNode extends DjotBaseNode {
149
206
  interface DjotHardBreakNode extends DjotBaseNode {
150
207
  tag: "hard_break" | "hardbreak";
151
208
  }
152
- type DjotNode = DjotDocNode | DjotSectionNode | DjotDivNode | DjotParaNode | DjotHeadingNode | DjotEmphNode | DjotStrongNode | DjotMarkNode | DjotHighlightedNode | DjotSuperscriptNode | DjotSupeNode | DjotSubscriptNode | DjotInsertNode | DjotDeleteNode | DjotTableNode | DjotCaptionNode | DjotRowNode | DjotCellNode | DjotFootnoteReferenceNode | DjotFootnoteNode | DjotDoubleQuotedNode | DjotSingleQuotedNode | DjotSmartPunctuationNode | DjotInlineMathNode | DjotDisplayMathNode | DjotCodeNode | DjotCodeBlockNode | DjotLinkNode | DjotImageNode | DjotBulletListNode | DjotOrderedListNode | DjotListItemNode | DjotBlockquoteNode | DjotBlockQuoteNode | DjotThematicBreakNode | DjotStrNode | DjotVerbatimNode | DjotSoftBreakNode | DjotHardBreakNode;
209
+ interface DjotNonBreakingSpaceNode extends DjotBaseNode {
210
+ tag: "non_breaking_space";
211
+ }
212
+ type DjotNode = DjotDocNode | DjotSectionNode | DjotDivNode | DjotParaNode | DjotHeadingNode | DjotEmphNode | DjotStrongNode | DjotMarkNode | DjotHighlightedNode | DjotSuperscriptNode | DjotSupeNode | DjotSubscriptNode | DjotInsertNode | DjotDeleteNode | DjotSpanNode | DjotTableNode | DjotCaptionNode | DjotRowNode | DjotCellNode | DjotFootnoteReferenceNode | DjotFootnoteNode | DjotDoubleQuotedNode | DjotSingleQuotedNode | DjotSmartPunctuationNode | DjotInlineMathNode | DjotDisplayMathNode | DjotCodeNode | DjotCodeBlockNode | DjotRawBlockNode | DjotRawInlineNode | DjotSymbNode | DjotUrlNode | DjotEmailNode | DjotLinkNode | DjotImageNode | DjotBulletListNode | DjotOrderedListNode | DjotListItemNode | DjotDefinitionListNode | DjotDefinitionListItemNode | DjotTermNode | DjotDefinitionNode | DjotTaskListNode | DjotTaskListItemNode | DjotBlockquoteNode | DjotBlockQuoteNode | DjotThematicBreakNode | DjotStrNode | DjotVerbatimNode | DjotNonBreakingSpaceNode | DjotSoftBreakNode | DjotHardBreakNode;
153
213
  type DjotNodeTag = DjotNode["tag"];
154
214
  type DjotNodeByTag<Tag extends DjotNodeTag> = Extract<DjotNode, {
155
215
  tag: Tag;
@@ -183,6 +243,7 @@ interface DjotComponentPropsMap {
183
243
  subscript: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"subscript">;
184
244
  insert: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"insert">;
185
245
  delete: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"delete">;
246
+ span: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"span">;
186
247
  table: React.TableHTMLAttributes<HTMLTableElement> & DjotNodePropsBase<"table">;
187
248
  caption: React.HTMLAttributes<HTMLTableCaptionElement> & DjotNodePropsBase<"caption">;
188
249
  row: React.HTMLAttributes<HTMLTableRowElement> & DjotNodePropsBase<"row"> & {
@@ -231,13 +292,50 @@ interface DjotComponentPropsMap {
231
292
  language?: string;
232
293
  value: string;
233
294
  };
295
+ raw_block: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"raw_block"> & {
296
+ format: string;
297
+ value: string;
298
+ };
299
+ raw_inline: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"raw_inline"> & {
300
+ format: string;
301
+ value: string;
302
+ };
303
+ symb: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"symb"> & {
304
+ alias: string;
305
+ value: string;
306
+ };
307
+ url: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"url"> & {
308
+ href: string;
309
+ value: string;
310
+ };
311
+ email: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"email"> & {
312
+ href: string;
313
+ value: string;
314
+ };
234
315
  link: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"link">;
235
316
  image: React.ImgHTMLAttributes<HTMLImageElement> & DjotNodePropsBase<"image"> & {
236
317
  alt?: string;
237
318
  };
238
- bullet_list: React.HTMLAttributes<HTMLUListElement> & DjotNodePropsBase<"bullet_list">;
239
- ordered_list: React.OlHTMLAttributes<HTMLOListElement> & DjotNodePropsBase<"ordered_list">;
240
- list_item: React.LiHTMLAttributes<HTMLLIElement> & DjotNodePropsBase<"list_item">;
319
+ bullet_list: React.HTMLAttributes<HTMLUListElement> & DjotNodePropsBase<"bullet_list"> & {
320
+ tight?: boolean;
321
+ };
322
+ ordered_list: React.OlHTMLAttributes<HTMLOListElement> & DjotNodePropsBase<"ordered_list"> & {
323
+ tight?: boolean;
324
+ };
325
+ list_item: React.LiHTMLAttributes<HTMLLIElement> & DjotNodePropsBase<"list_item"> & {
326
+ tight?: boolean;
327
+ };
328
+ definition_list: React.HTMLAttributes<HTMLDListElement> & DjotNodePropsBase<"definition_list">;
329
+ definition_list_item: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"definition_list_item">;
330
+ term: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"term">;
331
+ definition: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"definition">;
332
+ task_list: React.HTMLAttributes<HTMLUListElement> & DjotNodePropsBase<"task_list"> & {
333
+ tight?: boolean;
334
+ };
335
+ task_list_item: React.LiHTMLAttributes<HTMLLIElement> & DjotNodePropsBase<"task_list_item"> & {
336
+ checkbox: DjotCheckboxStatus;
337
+ tight?: boolean;
338
+ };
241
339
  blockquote: React.BlockquoteHTMLAttributes<HTMLQuoteElement> & Omit<DjotNodePropsBase<"blockquote">, "node"> & {
242
340
  node: DjotBlockquoteNode | DjotBlockQuoteNode;
243
341
  };
@@ -248,6 +346,9 @@ interface DjotComponentPropsMap {
248
346
  str: DjotNodePropsBase<"str"> & {
249
347
  value: string;
250
348
  };
349
+ non_breaking_space: DjotNodePropsBase<"non_breaking_space"> & {
350
+ value: string;
351
+ };
251
352
  soft_break: DjotNodePropsBase<"soft_break">;
252
353
  softbreak: DjotNodePropsBase<"softbreak">;
253
354
  hard_break: DjotNodePropsBase<"hard_break">;
@@ -256,24 +357,35 @@ interface DjotComponentPropsMap {
256
357
  type DjotComponents = Partial<{
257
358
  [K in keyof DjotComponentPropsMap]: React.ElementType<DjotComponentPropsMap[K]>;
258
359
  }>;
259
- interface DjotProps {
260
- children?: string | null | undefined;
360
+ interface DjotSharedProps {
261
361
  components?: DjotComponents | undefined;
262
362
  }
363
+ type DjotProps = (DjotSharedProps & {
364
+ ast?: never;
365
+ children?: string | null | undefined;
366
+ }) | (DjotSharedProps & {
367
+ ast: DjotNode;
368
+ children?: never;
369
+ });
263
370
 
264
- declare function Djot({ children, components }: DjotProps): React.ReactElement | null;
371
+ declare function compileDjot(source: string): DjotNode;
372
+ declare function Djot(props: DjotProps): React.ReactElement | null;
265
373
 
266
- interface RenderNodeOptions {
267
- components?: DjotComponents | undefined;
268
- footnoteState?: FootnoteState | undefined;
269
- key?: React.Key;
270
- }
271
374
  interface FootnoteState {
375
+ autoReferencesByLabel: Record<string, DjotReferenceNode>;
272
376
  firstRefIdByLabel: Map<string, string>;
273
377
  indexByLabel: Map<string, number>;
274
378
  order: string[];
379
+ referencesByLabel: Record<string, DjotReferenceNode>;
275
380
  refCountByLabel: Map<string, number>;
276
381
  }
382
+
383
+ interface RenderNodeOptions {
384
+ components?: DjotComponents | undefined;
385
+ footnoteState?: FootnoteState | undefined;
386
+ key?: React.Key;
387
+ listTight?: boolean | undefined;
388
+ }
277
389
  declare function renderNode(node: DjotNode, options?: RenderNodeOptions): React.ReactNode;
278
390
 
279
- export { Djot, type DjotComponentPropsMap, type DjotComponents, type DjotNode, type DjotNodeByTag, type DjotNodeTag, type DjotProps, Djot as default, renderNode };
391
+ export { Djot, type DjotComponentPropsMap, type DjotComponents, type DjotNode, type DjotNodeByTag, type DjotNodeTag, type DjotProps, compileDjot, Djot as default, renderNode };