@surrealdb/ui 1.2.22 → 1.2.24

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 (4) hide show
  1. package/dist/ui.d.ts +122 -3
  2. package/dist/ui.js +13090 -12987
  3. package/dist/ui.js.map +1 -1
  4. package/package.json +1 -1
package/dist/ui.d.ts CHANGED
@@ -431,19 +431,82 @@ export declare interface CodeEditorProps extends BoxProps {
431
431
  withPadding?: boolean;
432
432
  }
433
433
 
434
+ /** Value of a single fenced-code info attribute. Loose flags resolve to `true`. */
435
+ export declare type CodeInfoAttributeValue = string | boolean;
436
+
437
+ /** Read a string-valued attribute, or `undefined` when absent or a loose flag. */
438
+ export declare function codeInfoString(parsed: ParsedCodeInfo, key: string): string | undefined;
439
+
434
440
  /** React component keyed by lower-cased fenced-code info string. */
435
441
  export declare type CodeRenderer = ComponentType<CodeRendererProps>;
436
442
 
443
+ /**
444
+ * A renderer registration: either a bare component, or a config object that
445
+ * also declares how the block hosting it behaves.
446
+ *
447
+ * Every field is optional and defaults to the behaviour a bare component gets,
448
+ * so `{ mermaid: MermaidCodeRenderer }` and
449
+ * `{ mermaid: { component: MermaidCodeRenderer } }` are equivalent.
450
+ */
451
+ export declare interface CodeRendererConfig {
452
+ component: CodeRenderer;
453
+ /**
454
+ * Derives a stable widget identity from the block body.
455
+ *
456
+ * Widget identity is positional by default, so a block's widget is rebuilt
457
+ * whenever an edit above it shifts its offsets - which remounts the React
458
+ * subtree and loses whatever state it held. Return something drawn from the
459
+ * body instead and the widget is reused, so React reconciles. Return
460
+ * `undefined` to fall back to the positional id.
461
+ */
462
+ identify?: (code: string, language: string) => string | undefined;
463
+ /**
464
+ * Keeps the block rendered even while the selection touches it.
465
+ *
466
+ * A block yields to its raw source when the selection intersects any line it
467
+ * spans, which arrow keys and `Mod+A` both do. Set this where the body is
468
+ * machine-written and there is nothing to edit by hand; `mode="source"`
469
+ * remains the way to reach it.
470
+ */
471
+ alwaysRendered?: boolean;
472
+ /**
473
+ * Draws the block without the wrapper's own frame.
474
+ *
475
+ * The wrapper gives a rendered block a padded, bordered card, which is right
476
+ * for a diagram or a preview sitting in prose. A renderer that draws its own
477
+ * container - a panel, a card of its own - otherwise sits inside a second one,
478
+ * held away from its own edges by padding it did not ask for.
479
+ */
480
+ bare?: boolean;
481
+ /**
482
+ * Height in pixels to assume before the block has been measured.
483
+ *
484
+ * CodeMirror's height map treats an unmeasured widget as one line tall, so a
485
+ * document of tall blocks has the wrong scroll height on first paint. Supply
486
+ * this where the rendered height is known up front.
487
+ */
488
+ estimatedHeight?: number;
489
+ }
490
+
491
+ /** A registered renderer is either a bare component or a config object. */
492
+ export declare type CodeRendererDef = CodeRenderer | CodeRendererConfig;
493
+
437
494
  /** Props for a custom fenced-code-block renderer (inactive block / viewer). */
438
495
  export declare interface CodeRendererProps {
439
496
  /** The code body verbatim (CodeText slice, fences excluded). */
440
497
  code: string;
441
498
  /** The (lower-cased) info string from the opening fence, e.g. `mermaid`. */
442
499
  language: string;
500
+ /** Start of the whole fenced block in the document, fences included. */
501
+ from?: number;
502
+ /** End of the whole fenced block in the document, fences included. */
503
+ to?: number;
504
+ /** Attributes parsed from the info string, e.g. ```` ```mermaid theme="dark" ````. */
505
+ attributes?: Readonly<Record<string, CodeInfoAttributeValue>>;
443
506
  }
444
507
 
445
- /** Map of lower-cased fenced-code info string to renderer component. */
446
- declare type CodeRenderers = Record<string, CodeRenderer>;
508
+ /** Map of lower-cased fenced-code info string to renderer registration. */
509
+ export declare type CodeRenderers = Record<string, CodeRendererDef>;
447
510
 
448
511
  export declare type ColorScheme = keyof ThemeConfig;
449
512
 
@@ -670,6 +733,10 @@ export declare interface EditorOptions {
670
733
  extensions?: Extension;
671
734
  /**
672
735
  * The language to use for the editor.
736
+ *
737
+ * Not applied by this hook. Pass the language's extension through
738
+ * {@link EditorOptions.extensions} instead, which is what the reconfigure
739
+ * effect reads.
673
740
  */
674
741
  language?: Language;
675
742
  /**
@@ -1285,6 +1352,16 @@ export declare interface LiveMarkdownEditorOptions {
1285
1352
  */
1286
1353
  export declare const MANTINE_THEME: MantineThemeOverride;
1287
1354
 
1355
+ /** What a renderer can reach about the block hosting it. */
1356
+ export declare interface MarkdownBlockContextValue {
1357
+ /** The editor the block belongs to, for dispatching a change to its own range. */
1358
+ view: EditorView;
1359
+ from: number;
1360
+ to: number;
1361
+ language: string;
1362
+ code: string;
1363
+ }
1364
+
1288
1365
  /**
1289
1366
  * Configuration for a single `<Component />` registered in {@link MarkdownComponents}.
1290
1367
  * Set `block: true` to opt into the block-rendering path (own line, hover
@@ -1368,7 +1445,7 @@ export declare interface MarkdownEditorProps extends Omit<EditorOptions, "langua
1368
1445
  */
1369
1446
  autoFocus?: boolean;
1370
1447
  /**
1371
- * The placeholder text to display in the editor when it is empty.
1448
+ * Placeholder text shown on the caret's line whenever that line is empty.
1372
1449
  */
1373
1450
  placeholder?: string;
1374
1451
  /**
@@ -1417,6 +1494,12 @@ export declare const markdownEditorReadyField: StateField<boolean>;
1417
1494
  */
1418
1495
  export declare const markdownModeField: StateField<MarkdownEditMode>;
1419
1496
 
1497
+ /**
1498
+ * Shows `text` on the caret's line whenever that line is empty, rather than only
1499
+ * while the whole document is.
1500
+ */
1501
+ export declare function markdownPlaceholder(text: string): Extension;
1502
+
1420
1503
  /**
1421
1504
  * Bundles the slash session {@link slashSessionField} with a `ViewPlugin` that
1422
1505
  * mirrors the active session and caret into the given {@link SlashStore}, which
@@ -1727,6 +1810,27 @@ declare interface OptionalNode {
1727
1810
  child: RailroadNode;
1728
1811
  }
1729
1812
 
1813
+ /**
1814
+ * Parse a fenced code info string such as `surql runnable="SELECT 1"`,
1815
+ * `js title="Example"`, or `ts runnable` into a language plus an attribute map.
1816
+ *
1817
+ * Loose attributes (no `=value`) resolve to `true`; quoted, braced, and bare
1818
+ * values keep their literal string. The first whitespace-delimited token is the
1819
+ * language (lower-cased).
1820
+ */
1821
+ export declare function parseCodeInfo(info: string): ParsedCodeInfo;
1822
+
1823
+ /** Parsed language and attribute map from a fenced-code info line. */
1824
+ export declare interface ParsedCodeInfo {
1825
+ /** Primary language identifier (first token, lower-cased). */
1826
+ language: string;
1827
+ /**
1828
+ * Attributes following the language. Key/value pairs (`title="value"`) keep
1829
+ * their string value; loose flags (`runnable`) resolve to `true`.
1830
+ */
1831
+ attributes: Record<string, CodeInfoAttributeValue>;
1832
+ }
1833
+
1730
1834
  declare interface ParsedHeadingTitle {
1731
1835
  /** Visible title text (custom id suffix removed). */
1732
1836
  text: string;
@@ -3271,6 +3375,12 @@ export declare interface RailroadDiagramProps extends BoxProps {
3271
3375
 
3272
3376
  export declare type RailroadNode = DiagramNode | SequenceNode | TerminalNode | NonTerminalNode | OptionalNode | ChoiceNode | OneOrMoreNode | ZeroOrMoreNode | CommentNode;
3273
3377
 
3378
+ /**
3379
+ * Normalises a renderer registration, so a bare component and a config object
3380
+ * are handled identically downstream.
3381
+ */
3382
+ export declare function resolveCodeRenderer(def: CodeRendererDef | undefined): CodeRendererConfig | undefined;
3383
+
3274
3384
  /** Resolve heading `id` from `{#custom}` suffix or slugged plain title. */
3275
3385
  export declare function resolveHeadingId(node: SyntaxNode, source: MarkdownSource, slugger: default_2): string | undefined;
3276
3386
 
@@ -4031,6 +4141,15 @@ export declare function useKeyNavigation<T extends Identified>(items: T[], onSub
4031
4141
  */
4032
4142
  export declare function useLater<T extends unknown[]>(doLater: (...args: T) => unknown): (...args: T) => void;
4033
4143
 
4144
+ /**
4145
+ * The block a custom code renderer is rendering, or `null` outside one.
4146
+ *
4147
+ * A renderer reaches this to act on its own source - to replace, duplicate or
4148
+ * delete the fence it was built from - which needs both the editor and the
4149
+ * range the block occupies.
4150
+ */
4151
+ export declare function useMarkdownBlock(): MarkdownBlockContextValue | null;
4152
+
4034
4153
  /**
4035
4154
  * Hook returning a stable {@link SlashStore} for the lifetime of the calling
4036
4155
  * component. Pair with {@link SlashCommandMenu} and pass the same store into