@sigx/lynx-markdown 0.4.7 → 0.4.9

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.
Files changed (41) hide show
  1. package/README.md +47 -17
  2. package/dist/ast.d.ts +18 -1
  3. package/dist/editor/MarkdownEditor.d.ts +73 -0
  4. package/dist/editor/MarkdownEditor.js +243 -0
  5. package/dist/editor/convert/docToMd.d.ts +24 -0
  6. package/dist/editor/convert/docToMd.js +224 -0
  7. package/dist/editor/convert/mdToDoc.d.ts +32 -0
  8. package/dist/editor/convert/mdToDoc.js +221 -0
  9. package/dist/editor/convert/overlap.d.ts +31 -0
  10. package/dist/editor/convert/overlap.js +70 -0
  11. package/dist/editor/plugin.d.ts +118 -0
  12. package/dist/editor/plugin.js +16 -0
  13. package/dist/editor/toolbar/Toolbar.d.ts +25 -0
  14. package/dist/editor/toolbar/Toolbar.js +51 -0
  15. package/dist/editor/toolbar/items.d.ts +35 -0
  16. package/dist/editor/toolbar/items.js +29 -0
  17. package/dist/editor/trigger/SuggestionPopup.d.ts +28 -0
  18. package/dist/editor/trigger/SuggestionPopup.js +77 -0
  19. package/dist/editor/trigger/position.d.ts +47 -0
  20. package/dist/editor/trigger/position.js +62 -0
  21. package/dist/editor/trigger/session.d.ts +49 -0
  22. package/dist/editor/trigger/session.js +162 -0
  23. package/dist/index.d.ts +19 -6
  24. package/dist/index.js +9 -3
  25. package/dist/parser/blocks.d.ts +2 -1
  26. package/dist/parser/blocks.js +13 -13
  27. package/dist/parser/extensions.d.ts +51 -0
  28. package/dist/parser/extensions.js +18 -0
  29. package/dist/parser/incremental.d.ts +10 -1
  30. package/dist/parser/incremental.js +5 -2
  31. package/dist/parser/inline.d.ts +15 -5
  32. package/dist/parser/inline.js +55 -9
  33. package/dist/render/MarkdownView.d.ts +10 -4
  34. package/dist/render/MarkdownView.js +13 -5
  35. package/dist/render/components.d.ts +13 -1
  36. package/dist/render/engine.js +11 -0
  37. package/package.json +18 -7
  38. package/dist/XMarkdown.d.ts +0 -36
  39. package/dist/XMarkdown.js +0 -36
  40. package/dist/jsx-augment.d.ts +0 -83
  41. package/dist/jsx-augment.js +0 -1
@@ -12,7 +12,7 @@
12
12
  * component only decides *what element to wrap children in*.
13
13
  */
14
14
  import type { JSXElement } from '@sigx/lynx';
15
- import type { BlockquoteBlock, CodeBlock, HeadingBlock, HeadingLevel, InlineAutolink, InlineCodeSpan, InlineDel, InlineEm, InlineImage, InlineLink, InlineStrong, ListBlock, ListItem, ParagraphBlock, TableAlign, TableBlock, ThematicBreakBlock } from '../ast.js';
15
+ import type { BlockquoteBlock, CodeBlock, HeadingBlock, HeadingLevel, InlineAutolink, InlineCodeSpan, InlineDel, InlineEm, InlineExtension, InlineImage, InlineLink, InlineStrong, ListBlock, ListItem, ParagraphBlock, TableAlign, TableBlock, ThematicBreakBlock } from '../ast.js';
16
16
  /** A renderable child: a JSX element or a raw string (for text/`<br>`). */
17
17
  export type MarkdownChild = JSXElement | string;
18
18
  export interface RootProps {
@@ -111,6 +111,13 @@ export interface ImageProps {
111
111
  onImageTap?: (src: string) => void;
112
112
  node: InlineImage;
113
113
  }
114
+ export interface ExtensionProps {
115
+ name: string;
116
+ attrs: Record<string, string>;
117
+ /** Rendered `node.children`; `[]` for leaf extensions. */
118
+ children: MarkdownChild[];
119
+ node: InlineExtension;
120
+ }
114
121
  /**
115
122
  * Map of node type → render function. Pass a partial map to `<Markdown
116
123
  * components={…}>` to override any subset; unspecified types fall back to the
@@ -136,5 +143,10 @@ export interface MarkdownComponents {
136
143
  autolink(props: AutolinkProps): MarkdownChild;
137
144
  image(props: ImageProps): MarkdownChild;
138
145
  br(): MarkdownChild;
146
+ /**
147
+ * Renderers for plugin inline extensions, keyed by extension name. A node
148
+ * with no matching renderer falls back to its `raw` source as plain text.
149
+ */
150
+ extension?: Record<string, (props: ExtensionProps) => MarkdownChild>;
139
151
  }
140
152
  export declare const defaultComponents: MarkdownComponents;
@@ -141,5 +141,16 @@ function renderInlineNode(node, ctx) {
141
141
  onImageTap: ctx.onImageTap,
142
142
  node,
143
143
  });
144
+ case 'extension': {
145
+ const renderer = C.extension?.[node.name];
146
+ if (!renderer)
147
+ return node.raw; // no renderer registered → literal source
148
+ return renderer({
149
+ name: node.name,
150
+ attrs: node.attrs,
151
+ children: node.children ? renderInline(node.children, ctx) : [],
152
+ node,
153
+ });
154
+ }
144
155
  }
145
156
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sigx/lynx-markdown",
3
- "version": "0.4.7",
4
- "description": "SignalX-native streaming markdown renderer for Lynx. Parses markdown in JS (zero deps) and renders to native <view>/<text> primitives, with incremental streaming for AI output. Also ships XMarkdown, the native <x-markdown> wrapper.",
3
+ "version": "0.4.9",
4
+ "description": "SignalX-native streaming markdown renderer for Lynx. Parses markdown in JS (zero deps) and renders to native <view>/<text> primitives, with incremental streaming for AI output.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -19,13 +19,25 @@
19
19
  "LICENSE"
20
20
  ],
21
21
  "peerDependencies": {
22
- "@sigx/lynx": "^0.4.7"
22
+ "@sigx/lynx-keyboard": "^0.4.9",
23
+ "@sigx/lynx": "^0.4.9",
24
+ "@sigx/lynx-richtext": "^0.4.9"
25
+ },
26
+ "peerDependenciesMeta": {
27
+ "@sigx/lynx-keyboard": {
28
+ "optional": true
29
+ },
30
+ "@sigx/lynx-richtext": {
31
+ "optional": true
32
+ }
23
33
  },
24
34
  "devDependencies": {
25
35
  "@typescript/native-preview": "7.0.0-dev.20260521.1",
26
36
  "typescript": "^6.0.3",
27
- "@sigx/lynx": "^0.4.7",
28
- "@sigx/lynx-testing": "^0.4.7"
37
+ "@sigx/lynx": "^0.4.9",
38
+ "@sigx/lynx-keyboard": "^0.4.9",
39
+ "@sigx/lynx-richtext": "^0.4.9",
40
+ "@sigx/lynx-testing": "^0.4.9"
29
41
  },
30
42
  "author": "Andreas Ekdahl",
31
43
  "license": "MIT",
@@ -48,8 +60,7 @@
48
60
  "markdown",
49
61
  "native",
50
62
  "streaming",
51
- "ai",
52
- "x-markdown"
63
+ "ai"
53
64
  ],
54
65
  "scripts": {
55
66
  "build": "node ../../scripts/clean.mjs dist && tsgo",
@@ -1,36 +0,0 @@
1
- import { type Define } from '@sigx/lynx';
2
- import './jsx-augment.js';
3
- import type { MarkdownLinkEvent, MarkdownImageTapEvent, MarkdownParseEndEvent } from './jsx-augment.js';
4
- export type XMarkdownEffect = 'typewriter' | 'none' | (string & {});
5
- export type XMarkdownProps = Define.Prop<'value', string, false> & Define.Prop<'effect', XMarkdownEffect, false> & Define.Prop<'attachments', ReadonlyArray<unknown>, false> & Define.Prop<'class', string, false> & Define.Prop<'style', string | Record<string, string | number>, false> & Define.Prop<'onLink', (e: MarkdownLinkEvent) => void, false> & Define.Prop<'onImageTap', (e: MarkdownImageTapEvent) => void, false> & Define.Prop<'onParseEnd', (e: MarkdownParseEndEvent) => void, false>;
6
- /**
7
- * Render a markdown document using Lynx's native `<x-markdown>` XElement.
8
- *
9
- * This is the thin wrapper over the platform's native markdown element. It is
10
- * fast where available but platform-gated (Harmony 3.7.0+, Android 3.8.0-rc.0+,
11
- * iOS not yet in a tagged release) and opaque — the engine owns parsing and
12
- * styling. For a cross-platform, fully-controllable, streaming-aware renderer
13
- * built on Lynx `<view>`/`<text>` primitives, use {@link Markdown} instead.
14
- *
15
- * The markdown source is passed via the `value` prop; it is delivered to the
16
- * native element as a raw-text child (per the 3.7.0 "raw-text node
17
- * optimization" path). Event props use signalx's automatic
18
- * `onLink`→`bindlink` mapping in `nodeOps.parseEventProp`, so handlers wire
19
- * up without any per-event glue.
20
- *
21
- * @example
22
- * ```tsx
23
- * <XMarkdown
24
- * value={"# Hello\n\nThis is **markdown**."}
25
- * effect="typewriter"
26
- * onLink={(e) => console.log('tapped', e.detail.url)}
27
- * />
28
- * ```
29
- *
30
- * @remarks
31
- * Availability of the `<x-markdown>` element is platform-dependent — see
32
- * `jsx-augment.ts` for the per-platform schedule. On platforms where the
33
- * native element is not registered, the engine logs a warning and renders
34
- * no view; there is no JS-side feature gate.
35
- */
36
- export declare const XMarkdown: import("@sigx/runtime-core").ComponentFactory<XMarkdownProps, void, {}>;
package/dist/XMarkdown.js DELETED
@@ -1,36 +0,0 @@
1
- import { jsx as _jsx } from "@sigx/lynx/jsx-runtime";
2
- import { component } from '@sigx/lynx';
3
- import './jsx-augment.js';
4
- /**
5
- * Render a markdown document using Lynx's native `<x-markdown>` XElement.
6
- *
7
- * This is the thin wrapper over the platform's native markdown element. It is
8
- * fast where available but platform-gated (Harmony 3.7.0+, Android 3.8.0-rc.0+,
9
- * iOS not yet in a tagged release) and opaque — the engine owns parsing and
10
- * styling. For a cross-platform, fully-controllable, streaming-aware renderer
11
- * built on Lynx `<view>`/`<text>` primitives, use {@link Markdown} instead.
12
- *
13
- * The markdown source is passed via the `value` prop; it is delivered to the
14
- * native element as a raw-text child (per the 3.7.0 "raw-text node
15
- * optimization" path). Event props use signalx's automatic
16
- * `onLink`→`bindlink` mapping in `nodeOps.parseEventProp`, so handlers wire
17
- * up without any per-event glue.
18
- *
19
- * @example
20
- * ```tsx
21
- * <XMarkdown
22
- * value={"# Hello\n\nThis is **markdown**."}
23
- * effect="typewriter"
24
- * onLink={(e) => console.log('tapped', e.detail.url)}
25
- * />
26
- * ```
27
- *
28
- * @remarks
29
- * Availability of the `<x-markdown>` element is platform-dependent — see
30
- * `jsx-augment.ts` for the per-platform schedule. On platforms where the
31
- * native element is not registered, the engine logs a warning and renders
32
- * no view; there is no JS-side feature gate.
33
- */
34
- export const XMarkdown = component(({ props }) => {
35
- return () => (_jsx("x-markdown", { "markdown-effect": props.effect, "text-mark-attachments": props.attachments, class: props.class, style: props.style, bindlink: props.onLink, bindimageTap: props.onImageTap, bindparseEnd: props.onParseEnd, children: props.value ?? '' }));
36
- });
@@ -1,83 +0,0 @@
1
- /**
2
- * JSX intrinsic type augmentation for Lynx's `<x-markdown>` XElement.
3
- *
4
- * Importing this module registers `'x-markdown'` as a valid JSX intrinsic
5
- * with its 3.7.0+ attributes and events. Pulled in automatically by
6
- * `@sigx/lynx-markdown`'s entry point so consumers do not need to import
7
- * it directly.
8
- *
9
- * The native element ships per-platform on different schedules:
10
- * - Harmony: available since 3.7.0
11
- * - Android: available since 3.8.0-rc.0 (artifact `lynx_xelement_markdown`)
12
- * - iOS: not yet in any tagged release; lands on the main branch
13
- * post-3.8.0
14
- *
15
- * `<x-markdown>` props in JSX still type-check on every platform. At
16
- * runtime the SignalX renderer issues a `__CreateElement('x-markdown')`
17
- * op unconditionally; on platforms where the native element is not
18
- * registered, the underlying engine handles the unknown tag (today it
19
- * logs a warning and emits no view). There is no JS-side feature gate
20
- * in this package — once you upgrade to a Lynx release that ships the
21
- * element on your target platforms, rendering activates automatically.
22
- */
23
- import type { LynxCommonAttributes, LynxEventHandler } from '@sigx/lynx-runtime';
24
- /** Detail payload of `bindlink` — the engine ships `url` plus optional fields. */
25
- export interface MarkdownLinkEventDetail {
26
- url: string;
27
- [k: string]: unknown;
28
- }
29
- export interface MarkdownLinkEvent {
30
- type: 'link';
31
- detail: MarkdownLinkEventDetail;
32
- }
33
- /** Detail payload of `bindimageTap`. */
34
- export interface MarkdownImageTapEventDetail {
35
- src: string;
36
- [k: string]: unknown;
37
- }
38
- export interface MarkdownImageTapEvent {
39
- type: 'imageTap';
40
- detail: MarkdownImageTapEventDetail;
41
- }
42
- /** Detail payload of `bindparseEnd`. */
43
- export interface MarkdownParseEndEventDetail {
44
- [k: string]: unknown;
45
- }
46
- export interface MarkdownParseEndEvent {
47
- type: 'parseEnd';
48
- detail: MarkdownParseEndEventDetail;
49
- }
50
- export interface XMarkdownAttributes extends LynxCommonAttributes {
51
- /**
52
- * Raw markdown source. Lynx parses the first text child of
53
- * `<x-markdown>` per the 3.7.0 raw-text-node optimization. Passing a
54
- * single string here is the common path; JSX expressions resolving to
55
- * a string also work.
56
- */
57
- children?: any;
58
- /**
59
- * Render-time effect applied to the parsed markdown output.
60
- * Known values: `'typewriter'`, `'none'`. The engine treats unknown
61
- * strings as `'none'`.
62
- */
63
- 'markdown-effect'?: string;
64
- /**
65
- * Inline view attachments referenced by markdown text marks. Shape is
66
- * engine-defined; passed through as-is.
67
- */
68
- 'text-mark-attachments'?: ReadonlyArray<unknown>;
69
- /** Fires when the user taps an `[anchor](url)` link. */
70
- bindlink?: LynxEventHandler<MarkdownLinkEvent>;
71
- /** Fires when the user taps an inline image. */
72
- bindimageTap?: LynxEventHandler<MarkdownImageTapEvent>;
73
- /** Fires once the engine finishes parsing the source. */
74
- bindparseEnd?: LynxEventHandler<MarkdownParseEndEvent>;
75
- }
76
- declare global {
77
- namespace JSX {
78
- interface IntrinsicElements {
79
- 'x-markdown': XMarkdownAttributes;
80
- }
81
- }
82
- }
83
- export {};
@@ -1 +0,0 @@
1
- export {};