1ch 0.1.0 → 0.3.0

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
@@ -125,24 +125,62 @@ type Theme = {
125
125
  declare function isTableLine(line: Line): boolean;
126
126
  declare function preserveTableTag(source: Line, target: Line): void;
127
127
 
128
+ type ScrollRegionMeta = {
129
+ onScroll: (offset: number) => void;
130
+ totalLines: number;
131
+ maxHeight: number;
132
+ offset: number;
133
+ };
134
+
128
135
  declare function pad(s: string, w: number, right?: boolean): string;
129
136
  declare function hl(n: number): string;
130
137
  declare function bar(val: number, max: number, w: number): string;
131
138
  declare function spark(data: number[], w: number): string;
132
139
  declare function padLine(line: Line, w: number): Line;
140
+ declare function truncate(text: string, width: number, ellipsis?: string): string;
133
141
 
142
+ type BoxAction = {
143
+ label: string;
144
+ onClick: () => void;
145
+ color?: string;
146
+ };
134
147
  declare function lines(content: Line[] | ((w: number) => Line[])): LayoutFn;
135
148
  declare function box(content: LayoutFn, opts?: {
136
149
  title?: string;
137
150
  borderColor?: string;
151
+ action?: BoxAction;
138
152
  }): LayoutFn;
139
153
  declare function hstack(children: LayoutFn[], opts?: {
140
154
  gap?: number;
141
155
  widths?: number[];
142
156
  }): LayoutFn;
143
157
  declare function vstack(...children: LayoutFn[]): LayoutFn;
144
- declare function separator(color?: string): LayoutFn;
145
- declare function blank(): LayoutFn;
158
+ declare function separator(color?: string, char?: string): LayoutFn;
159
+ declare function blank(count?: number): LayoutFn;
160
+ declare function divider(label: string, opts?: {
161
+ color?: string;
162
+ char?: string;
163
+ labelColor?: string;
164
+ }): LayoutFn;
165
+ declare function grid(cells: LayoutFn[], opts: {
166
+ cols: number;
167
+ gap?: number;
168
+ rowGap?: number;
169
+ }): LayoutFn;
170
+ declare function scroll(content: LayoutFn, opts: {
171
+ maxHeight: number;
172
+ offset?: number;
173
+ scrollbarColor?: string;
174
+ onScroll?: (offset: number) => void;
175
+ }): LayoutFn;
176
+ declare function padding(content: LayoutFn, opts?: {
177
+ x?: number;
178
+ y?: number;
179
+ top?: number;
180
+ bottom?: number;
181
+ left?: number;
182
+ right?: number;
183
+ }): LayoutFn;
146
184
 
147
185
  type Column<T extends Record<string, unknown> = Record<string, unknown>> = {
148
186
  key: keyof T & string;
@@ -153,6 +191,7 @@ type Column<T extends Record<string, unknown> = Record<string, unknown>> = {
153
191
  headerBold?: boolean;
154
192
  color?: string | ((value: unknown, row: T) => string | undefined);
155
193
  dim?: boolean | ((value: unknown, row: T) => boolean);
194
+ onClick?: (value: unknown, row: T) => void;
156
195
  };
157
196
  declare function table<T extends Record<string, unknown>>(columns: Column<T>[], data: T[], opts?: {
158
197
  borderColor?: string;
@@ -181,6 +220,37 @@ declare function badge(label: string, opts?: {
181
220
  onClick?: () => void;
182
221
  theme?: Theme;
183
222
  }): Segment;
223
+ type KVPair = {
224
+ key: string;
225
+ value: string | Segment[];
226
+ keyColor?: string;
227
+ valueColor?: string;
228
+ onClick?: () => void;
229
+ };
230
+ declare function kv(pairs: KVPair[], opts?: {
231
+ separator?: string;
232
+ keyColor?: string;
233
+ valueColor?: string;
234
+ keyWidth?: number;
235
+ }): LayoutFn;
236
+ declare function callout(content: LayoutFn | string, opts?: {
237
+ color?: string;
238
+ accent?: string;
239
+ label?: string;
240
+ }): LayoutFn;
241
+ declare function checkbox(checked: boolean, label: string, opts?: {
242
+ color?: string;
243
+ checkColor?: string;
244
+ onClick?: () => void;
245
+ }): LayoutFn;
246
+ declare function inputField(value: string, opts?: {
247
+ placeholder?: string;
248
+ width?: number;
249
+ focused?: boolean;
250
+ color?: string;
251
+ borderColor?: string;
252
+ onClick?: () => void;
253
+ }): LayoutFn;
184
254
 
185
255
  type JsonNode = {
186
256
  type: "vstack";
@@ -237,6 +307,7 @@ declare function fromJsonNode(node: JsonNode): LayoutFn;
237
307
 
238
308
  type TreeNode = {
239
309
  label: string;
310
+ onClick?: () => void;
240
311
  children?: TreeNode[];
241
312
  };
242
313
  declare function tree(data: TreeNode[], opts?: {
@@ -244,7 +315,12 @@ declare function tree(data: TreeNode[], opts?: {
244
315
  branchColor?: string;
245
316
  leafColor?: string;
246
317
  }): LayoutFn;
247
- declare function list(items: string[], opts?: {
318
+ type ListItem = string | {
319
+ text: string;
320
+ color?: string;
321
+ onClick?: () => void;
322
+ };
323
+ declare function list(items: ListItem[], opts?: {
248
324
  ordered?: boolean;
249
325
  bulletColor?: string;
250
326
  color?: string;
@@ -263,14 +339,30 @@ declare function code(source: string, opts?: {
263
339
  title?: string;
264
340
  borderColor?: string;
265
341
  theme?: Theme;
342
+ copyable?: boolean;
343
+ action?: BoxAction;
344
+ }): LayoutFn;
345
+ declare function unifiedDiff(value: string, opts?: {
346
+ addColor?: string;
347
+ removeColor?: string;
348
+ metaColor?: string;
349
+ theme?: Theme;
266
350
  }): LayoutFn;
267
- declare function diff(value: string, opts?: {
351
+ declare function computeDiff(before: string, after: string, opts?: {
352
+ context?: number;
268
353
  addColor?: string;
269
354
  removeColor?: string;
270
355
  metaColor?: string;
271
356
  theme?: Theme;
272
357
  }): LayoutFn;
273
358
 
359
+ declare function chart(data: number[], opts?: {
360
+ height?: number;
361
+ color?: string;
362
+ axisColor?: string;
363
+ fill?: boolean;
364
+ }): LayoutFn;
365
+
274
366
  type DocumentSource = {
275
367
  format: "markdown";
276
368
  value: string;
@@ -397,9 +489,11 @@ type TBoxProps = BaseProps & {
397
489
  title?: string;
398
490
  borderColor?: string;
399
491
  gap?: number;
492
+ action?: BoxAction;
400
493
  };
401
494
  type TSeparatorProps = {
402
495
  color?: string;
496
+ char?: string;
403
497
  };
404
498
  type TRawProps = {
405
499
  text?: string;
@@ -463,6 +557,15 @@ type TSpanProps = {
463
557
  dim?: boolean;
464
558
  inverted?: boolean;
465
559
  blink?: boolean;
560
+ onClick?: () => void;
561
+ };
562
+ type TPadProps = BaseProps & {
563
+ x?: number;
564
+ y?: number;
565
+ top?: number;
566
+ bottom?: number;
567
+ left?: number;
568
+ right?: number;
466
569
  };
467
570
  type TLayoutProps = {
468
571
  layout: LayoutFn;
@@ -478,13 +581,23 @@ type TCodeProps = {
478
581
  language?: string;
479
582
  title?: string;
480
583
  borderColor?: string;
584
+ action?: BoxAction;
585
+ copyable?: boolean;
481
586
  };
482
- type TDiffProps = {
587
+ type TUnifiedDiffProps = {
483
588
  value: string;
484
589
  addColor?: string;
485
590
  removeColor?: string;
486
591
  metaColor?: string;
487
592
  };
593
+ type TDiffComputeProps = {
594
+ before: string;
595
+ after: string;
596
+ context?: number;
597
+ addColor?: string;
598
+ removeColor?: string;
599
+ metaColor?: string;
600
+ };
488
601
  type TBarProps = {
489
602
  label: string;
490
603
  value: number;
@@ -496,7 +609,7 @@ type TSparkProps = {
496
609
  color?: string;
497
610
  };
498
611
  type TListProps = {
499
- items: string[];
612
+ items: ListItem[];
500
613
  ordered?: boolean;
501
614
  bulletColor?: string;
502
615
  color?: string;
@@ -506,6 +619,8 @@ type TButtonProps = {
506
619
  onClick?: () => void;
507
620
  color?: string;
508
621
  bg?: string;
622
+ bold?: boolean;
623
+ dim?: boolean;
509
624
  };
510
625
  type RenderTermOptions = {
511
626
  theme?: Theme;
@@ -520,15 +635,34 @@ declare function THStack({ children, gap, widths }: THStackProps): react.ReactEl
520
635
  gap: number | undefined;
521
636
  widths: number[] | undefined;
522
637
  }, string | react.JSXElementConstructor<any>>;
523
- declare function TBox({ children, title, borderColor, gap }: TBoxProps): react.ReactElement<{
638
+ declare function TBox({ children, title, borderColor, gap, action }: TBoxProps): react.ReactElement<{
524
639
  title: string | undefined;
525
640
  borderColor: string | undefined;
526
641
  gap: number | undefined;
642
+ action: BoxAction | undefined;
527
643
  }, string | react.JSXElementConstructor<any>>;
528
- declare function TSeparator({ color }: TSeparatorProps): react.ReactElement<{
644
+ declare function TSeparator({ color, char }: TSeparatorProps): react.ReactElement<{
529
645
  color: string | undefined;
646
+ char: string | undefined;
530
647
  }, string | react.JSXElementConstructor<any>>;
531
- declare function TBlank(): react.DOMElement<{}, Element>;
648
+ type TBlankProps = {
649
+ lines?: number;
650
+ };
651
+ declare function TBlank({ lines }?: TBlankProps): react.ReactElement<{
652
+ lines: number | undefined;
653
+ }, string | react.JSXElementConstructor<any>>;
654
+ type TBadgeProps = {
655
+ label: string;
656
+ color?: string;
657
+ bg?: string;
658
+ onClick?: () => void;
659
+ };
660
+ declare function TBadge({ label, color, bg, onClick }: TBadgeProps): react.DOMElement<{
661
+ label: string;
662
+ color: string | undefined;
663
+ bg: string | undefined;
664
+ onClick: (() => void) | undefined;
665
+ }, Element>;
532
666
  declare function TRaw({ children, text, color, bg, bold, dim, blink, inverted, onClick }: TRawProps): react.DOMElement<{
533
667
  text: string | undefined;
534
668
  color: string | undefined;
@@ -577,7 +711,7 @@ declare function THtml({ value, themeOverrides }: THtmlProps): react.ReactElemen
577
711
  themeOverrides: Partial<ThemeMarkdown> | undefined;
578
712
  }, string | react.JSXElementConstructor<any>>;
579
713
  declare function TLine({ children }: TLineProps): react.DOMElement<{}, Element>;
580
- declare function TSpan({ children, text, color, bg, bold, dim, inverted, blink }: TSpanProps): react.ReactElement<{
714
+ declare function TSpan({ children, text, color, bg, bold, dim, inverted, blink, onClick }: TSpanProps): react.DOMElement<{
581
715
  text: string | undefined;
582
716
  color: string | undefined;
583
717
  bg: string | undefined;
@@ -585,6 +719,15 @@ declare function TSpan({ children, text, color, bg, bold, dim, inverted, blink }
585
719
  dim: boolean | undefined;
586
720
  inverted: boolean | undefined;
587
721
  blink: boolean | undefined;
722
+ onClick: (() => void) | undefined;
723
+ }, Element>;
724
+ declare function TPad({ children, x, y, top, bottom, left, right }: TPadProps): react.ReactElement<{
725
+ x: number | undefined;
726
+ y: number | undefined;
727
+ top: number | undefined;
728
+ bottom: number | undefined;
729
+ left: number | undefined;
730
+ right: number | undefined;
588
731
  }, string | react.JSXElementConstructor<any>>;
589
732
  declare function TLayout({ layout }: TLayoutProps): react.ReactElement<{
590
733
  layout: LayoutFn;
@@ -595,18 +738,28 @@ declare function TTree({ data, color, branchColor, leafColor }: TTreeProps): rea
595
738
  branchColor: string | undefined;
596
739
  leafColor: string | undefined;
597
740
  }, string | react.JSXElementConstructor<any>>;
598
- declare function TCode({ code, language, title, borderColor }: TCodeProps): react.ReactElement<{
741
+ declare function TCode({ code, language, title, borderColor, action, copyable }: TCodeProps): react.ReactElement<{
599
742
  code: string;
600
743
  language: string | undefined;
601
744
  title: string | undefined;
602
745
  borderColor: string | undefined;
746
+ action: BoxAction | undefined;
747
+ copyable: boolean | undefined;
603
748
  }, string | react.JSXElementConstructor<any>>;
604
- declare function TDiff({ value, addColor, removeColor, metaColor }: TDiffProps): react.ReactElement<{
749
+ declare function TUnifiedDiff({ value, addColor, removeColor, metaColor }: TUnifiedDiffProps): react.ReactElement<{
605
750
  value: string;
606
751
  addColor: string | undefined;
607
752
  removeColor: string | undefined;
608
753
  metaColor: string | undefined;
609
754
  }, string | react.JSXElementConstructor<any>>;
755
+ declare function TDiffCompute({ before, after, context, addColor, removeColor, metaColor }: TDiffComputeProps): react.ReactElement<{
756
+ before: string;
757
+ after: string;
758
+ context: number | undefined;
759
+ addColor: string | undefined;
760
+ removeColor: string | undefined;
761
+ metaColor: string | undefined;
762
+ }, string | react.JSXElementConstructor<any>>;
610
763
  declare function TBar({ label, value, max, color }: TBarProps): react.ReactElement<{
611
764
  label: string;
612
765
  value: number;
@@ -618,16 +771,128 @@ declare function TSpark({ data, color }: TSparkProps): react.ReactElement<{
618
771
  color: string | undefined;
619
772
  }, string | react.JSXElementConstructor<any>>;
620
773
  declare function TList({ items, ordered, bulletColor, color }: TListProps): react.ReactElement<{
621
- items: string[];
774
+ items: ListItem[];
622
775
  ordered: boolean | undefined;
623
776
  bulletColor: string | undefined;
624
777
  color: string | undefined;
625
778
  }, string | react.JSXElementConstructor<any>>;
626
- declare function TButton({ label, onClick, color, bg }: TButtonProps): react.DOMElement<{
779
+ declare function TButton({ label, onClick, color, bg, bold, dim }: TButtonProps): react.DOMElement<{
627
780
  label: string;
628
781
  onClick: (() => void) | undefined;
629
782
  color: string | undefined;
630
783
  bg: string | undefined;
784
+ bold: boolean | undefined;
785
+ dim: boolean | undefined;
786
+ }, Element>;
787
+ type TDividerProps = {
788
+ label: string;
789
+ color?: string;
790
+ char?: string;
791
+ labelColor?: string;
792
+ };
793
+ declare function TDivider({ label, color, char, labelColor }: TDividerProps): react.ReactElement<{
794
+ label: string;
795
+ color: string | undefined;
796
+ char: string | undefined;
797
+ labelColor: string | undefined;
798
+ }, string | react.JSXElementConstructor<any>>;
799
+ type TKVProps = {
800
+ pairs: KVPair[];
801
+ separator?: string;
802
+ keyColor?: string;
803
+ valueColor?: string;
804
+ keyWidth?: number;
805
+ };
806
+ declare function TKV({ pairs, separator, keyColor, valueColor, keyWidth }: TKVProps): react.ReactElement<{
807
+ pairs: KVPair[];
808
+ separator: string | undefined;
809
+ keyColor: string | undefined;
810
+ valueColor: string | undefined;
811
+ keyWidth: number | undefined;
812
+ }, string | react.JSXElementConstructor<any>>;
813
+ type TCalloutProps = BaseProps & {
814
+ text?: string;
815
+ color?: string;
816
+ accent?: string;
817
+ label?: string;
818
+ };
819
+ declare function TCallout({ children, text, color, accent, label }: TCalloutProps): react.ReactElement<{
820
+ text: string | undefined;
821
+ color: string | undefined;
822
+ accent: string | undefined;
823
+ label: string | undefined;
824
+ }, string | react.JSXElementConstructor<any>>;
825
+ type TChartProps = {
826
+ data: number[];
827
+ height?: number;
828
+ color?: string;
829
+ axisColor?: string;
830
+ fill?: boolean;
831
+ };
832
+ declare function TChart({ data, height, color, axisColor, fill }: TChartProps): react.ReactElement<{
833
+ data: number[];
834
+ height: number | undefined;
835
+ color: string | undefined;
836
+ axisColor: string | undefined;
837
+ fill: boolean | undefined;
838
+ }, string | react.JSXElementConstructor<any>>;
839
+ type TScrollProps = BaseProps & {
840
+ maxHeight: number;
841
+ offset?: number;
842
+ onScroll?: (offset: number) => void;
843
+ scrollbarColor?: string;
844
+ };
845
+ declare function TScroll({ children, maxHeight, offset: controlledOffset, onScroll: externalOnScroll, scrollbarColor }: TScrollProps): react.ReactElement<{
846
+ maxHeight: number;
847
+ offset: number;
848
+ scrollbarColor: string | undefined;
849
+ onScroll: (newOffset: number) => void;
850
+ }, string | react.JSXElementConstructor<any>>;
851
+ type TGridProps = BaseProps & {
852
+ cols: number;
853
+ gap?: number;
854
+ rowGap?: number;
855
+ };
856
+ declare function TGrid({ children, cols, gap, rowGap }: TGridProps): react.ReactElement<{
857
+ cols: number;
858
+ gap: number | undefined;
859
+ rowGap: number | undefined;
860
+ }, string | react.JSXElementConstructor<any>>;
861
+ type TCheckboxProps = {
862
+ checked: boolean;
863
+ label: string;
864
+ color?: string;
865
+ checkColor?: string;
866
+ onChange?: (checked: boolean) => void;
867
+ onClick?: () => void;
868
+ };
869
+ declare function TCheckbox({ checked, label, color, checkColor, onChange, onClick }: TCheckboxProps): react.ReactElement<{
870
+ checked: boolean;
871
+ label: string;
872
+ color: string | undefined;
873
+ checkColor: string | undefined;
874
+ onChange: ((checked: boolean) => void) | undefined;
875
+ onClick: (() => void) | undefined;
876
+ }, string | react.JSXElementConstructor<any>>;
877
+ type TInputProps = {
878
+ value: string;
879
+ onChange?: (value: string) => void;
880
+ onSubmit?: (value: string) => void;
881
+ placeholder?: string;
882
+ width?: number;
883
+ focused?: boolean;
884
+ color?: string;
885
+ borderColor?: string;
886
+ onClick?: () => void;
887
+ };
888
+ declare function TInput({ value, onChange, onSubmit, placeholder, width, focused: controlledFocused, color, borderColor, onClick }: TInputProps): react.DOMElement<{
889
+ value: string;
890
+ placeholder: string | undefined;
891
+ width: number | undefined;
892
+ focused: boolean;
893
+ color: string | undefined;
894
+ borderColor: string | undefined;
895
+ onClick: () => void;
631
896
  }, Element>;
632
897
  declare function renderTermReact(tree: ReactNode, opts?: RenderTermOptions): LayoutFn;
633
898
 
@@ -636,4 +901,4 @@ declare function useTick(ms?: number): number;
636
901
  declare function useTermWidth(ref: RefObject<HTMLElement | null>, fallback?: number): number;
637
902
  declare function useStreamingText(text: string, lerp?: number): string;
638
903
 
639
- export { type Block, type Column, type DocumentSource, type JsonNode, type LayoutFn, type Line, type MarkdownThemeOverrides, type RenderTermOptions, type Segment, type Style, TBar, type TBarProps, TBlank, TBox, type TBoxProps, TButton, type TButtonProps, TCode, type TCodeProps, TDiff, type TDiffProps, THStack, type THStackProps, THtml, type THtmlProps, TJson, type TJsonProps, TLayout, type TLayoutProps, TLine, type TLineProps, TList, type TListProps, TMarkdown, type TMarkdownProps, TRaw, type TRawProps, TSeparator, type TSeparatorProps, TSpan, type TSpanProps, TSpark, type TSparkProps, TStatusbar, type TStatusbarProps, TTab, type TTabProps, TTable, type TTableProps, TTabs, type TTabsProps, TTree, type TTreeProps, TVStack, type TVStackProps, TermDocument, type TermDocumentProps, type TermThemeContextValue, TermThemeProvider, type TermThemeProviderProps, TermUI, type TermUIProps, type Theme, type ThemeComponents, type ThemeMarkdown, type ThemeMode, type ThemeModeTokens, type ThemePalette, type ThemePreference, type ThemeSemantic, type ThemeSpec, type ThemeSyntax, type ThemeValidationIssue, type ThemeValidationResult, type Token, type TokenType, type TreeNode, badge, bar, blank, box, builtinThemes, code, dark, defaultThemeSpec, diff, fromDocument, fromHtml, fromJson, fromJsonNode, fromMarkdown, hl, hstack, isTableLine, light, lines, list, pad, padLine, parseThemeSpec, preserveTableTag, renderTermReact, resolveTheme, resolveThemeMode, separator, spark, statusbar, table, tabs, themeToCssVars, tokenColor, tokenize, tree, useSpinner, useStreamingText, useTermTheme, useTermWidth, useTick, validateThemeSpec, vstack };
904
+ export { type Block, type BoxAction, type Column, type DocumentSource, type JsonNode, type KVPair, type LayoutFn, type Line, type ListItem, type MarkdownThemeOverrides, type RenderTermOptions, type ScrollRegionMeta, type Segment, type Style, TBadge, type TBadgeProps, TBar, type TBarProps, TBlank, type TBlankProps, TBox, type TBoxProps, TButton, type TButtonProps, TCallout, type TCalloutProps, TChart, type TChartProps, TCheckbox, type TCheckboxProps, TCode, type TCodeProps, TDiffCompute, type TDiffComputeProps, TDivider, type TDividerProps, TGrid, type TGridProps, THStack, type THStackProps, THtml, type THtmlProps, TInput, type TInputProps, TJson, type TJsonProps, TKV, type TKVProps, TLayout, type TLayoutProps, TLine, type TLineProps, TList, type TListProps, TMarkdown, type TMarkdownProps, TPad, type TPadProps, TRaw, type TRawProps, TScroll, type TScrollProps, TSeparator, type TSeparatorProps, TSpan, type TSpanProps, TSpark, type TSparkProps, TStatusbar, type TStatusbarProps, TTab, type TTabProps, TTable, type TTableProps, TTabs, type TTabsProps, TTree, type TTreeProps, TUnifiedDiff, type TUnifiedDiffProps, TVStack, type TVStackProps, TermDocument, type TermDocumentProps, type TermThemeContextValue, TermThemeProvider, type TermThemeProviderProps, TermUI, type TermUIProps, type Theme, type ThemeComponents, type ThemeMarkdown, type ThemeMode, type ThemeModeTokens, type ThemePalette, type ThemePreference, type ThemeSemantic, type ThemeSpec, type ThemeSyntax, type ThemeValidationIssue, type ThemeValidationResult, type Token, type TokenType, type TreeNode, badge, bar, blank, box, builtinThemes, callout, chart, checkbox, code, computeDiff, dark, defaultThemeSpec, divider, fromDocument, fromHtml, fromJson, fromJsonNode, fromMarkdown, grid, hl, hstack, inputField, isTableLine, kv, light, lines, list, pad, padLine, padding, parseThemeSpec, preserveTableTag, renderTermReact, resolveTheme, resolveThemeMode, scroll, separator, spark, statusbar, table, tabs, themeToCssVars, tokenColor, tokenize, tree, truncate, unifiedDiff, useSpinner, useStreamingText, useTermTheme, useTermWidth, useTick, validateThemeSpec, vstack };