1ch 0.2.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/README.md CHANGED
@@ -54,7 +54,7 @@ Under the hood, 1ch uses a custom React reconciler that turns your component tre
54
54
 
55
55
  **Layout** - `TVStack`, `THStack`, `TBox`, `TSeparator`, `TBlank`, `TLine`, `TSpan`
56
56
 
57
- **Data** - `TTable`, `TTree`, `TList`, `TCode`, `TDiff`, `TBar`, `TSpark`
57
+ **Data** - `TTable`, `TTree`, `TList`, `TCode`, `TUnifiedDiff`, `TDiffCompute`, `TBar`, `TSpark`
58
58
 
59
59
  **Interactive** - `TTabs`, `TButton`, `TStatusbar`
60
60
 
package/dist/index.d.ts CHANGED
@@ -125,11 +125,19 @@ 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
 
134
142
  type BoxAction = {
135
143
  label: string;
@@ -147,8 +155,32 @@ declare function hstack(children: LayoutFn[], opts?: {
147
155
  widths?: number[];
148
156
  }): LayoutFn;
149
157
  declare function vstack(...children: LayoutFn[]): LayoutFn;
150
- declare function separator(color?: string): LayoutFn;
151
- 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;
152
184
 
153
185
  type Column<T extends Record<string, unknown> = Record<string, unknown>> = {
154
186
  key: keyof T & string;
@@ -159,6 +191,7 @@ type Column<T extends Record<string, unknown> = Record<string, unknown>> = {
159
191
  headerBold?: boolean;
160
192
  color?: string | ((value: unknown, row: T) => string | undefined);
161
193
  dim?: boolean | ((value: unknown, row: T) => boolean);
194
+ onClick?: (value: unknown, row: T) => void;
162
195
  };
163
196
  declare function table<T extends Record<string, unknown>>(columns: Column<T>[], data: T[], opts?: {
164
197
  borderColor?: string;
@@ -187,6 +220,37 @@ declare function badge(label: string, opts?: {
187
220
  onClick?: () => void;
188
221
  theme?: Theme;
189
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;
190
254
 
191
255
  type JsonNode = {
192
256
  type: "vstack";
@@ -243,6 +307,7 @@ declare function fromJsonNode(node: JsonNode): LayoutFn;
243
307
 
244
308
  type TreeNode = {
245
309
  label: string;
310
+ onClick?: () => void;
246
311
  children?: TreeNode[];
247
312
  };
248
313
  declare function tree(data: TreeNode[], opts?: {
@@ -250,7 +315,12 @@ declare function tree(data: TreeNode[], opts?: {
250
315
  branchColor?: string;
251
316
  leafColor?: string;
252
317
  }): LayoutFn;
253
- 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?: {
254
324
  ordered?: boolean;
255
325
  bulletColor?: string;
256
326
  color?: string;
@@ -272,12 +342,26 @@ declare function code(source: string, opts?: {
272
342
  copyable?: boolean;
273
343
  action?: BoxAction;
274
344
  }): LayoutFn;
275
- declare function diff(value: string, opts?: {
345
+ declare function unifiedDiff(value: string, opts?: {
276
346
  addColor?: string;
277
347
  removeColor?: string;
278
348
  metaColor?: string;
279
349
  theme?: Theme;
280
350
  }): LayoutFn;
351
+ declare function computeDiff(before: string, after: string, opts?: {
352
+ context?: number;
353
+ addColor?: string;
354
+ removeColor?: string;
355
+ metaColor?: string;
356
+ theme?: Theme;
357
+ }): LayoutFn;
358
+
359
+ declare function chart(data: number[], opts?: {
360
+ height?: number;
361
+ color?: string;
362
+ axisColor?: string;
363
+ fill?: boolean;
364
+ }): LayoutFn;
281
365
 
282
366
  type DocumentSource = {
283
367
  format: "markdown";
@@ -409,6 +493,7 @@ type TBoxProps = BaseProps & {
409
493
  };
410
494
  type TSeparatorProps = {
411
495
  color?: string;
496
+ char?: string;
412
497
  };
413
498
  type TRawProps = {
414
499
  text?: string;
@@ -472,6 +557,15 @@ type TSpanProps = {
472
557
  dim?: boolean;
473
558
  inverted?: boolean;
474
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;
475
569
  };
476
570
  type TLayoutProps = {
477
571
  layout: LayoutFn;
@@ -490,12 +584,20 @@ type TCodeProps = {
490
584
  action?: BoxAction;
491
585
  copyable?: boolean;
492
586
  };
493
- type TDiffProps = {
587
+ type TUnifiedDiffProps = {
494
588
  value: string;
495
589
  addColor?: string;
496
590
  removeColor?: string;
497
591
  metaColor?: string;
498
592
  };
593
+ type TDiffComputeProps = {
594
+ before: string;
595
+ after: string;
596
+ context?: number;
597
+ addColor?: string;
598
+ removeColor?: string;
599
+ metaColor?: string;
600
+ };
499
601
  type TBarProps = {
500
602
  label: string;
501
603
  value: number;
@@ -507,7 +609,7 @@ type TSparkProps = {
507
609
  color?: string;
508
610
  };
509
611
  type TListProps = {
510
- items: string[];
612
+ items: ListItem[];
511
613
  ordered?: boolean;
512
614
  bulletColor?: string;
513
615
  color?: string;
@@ -517,6 +619,8 @@ type TButtonProps = {
517
619
  onClick?: () => void;
518
620
  color?: string;
519
621
  bg?: string;
622
+ bold?: boolean;
623
+ dim?: boolean;
520
624
  };
521
625
  type RenderTermOptions = {
522
626
  theme?: Theme;
@@ -537,10 +641,28 @@ declare function TBox({ children, title, borderColor, gap, action }: TBoxProps):
537
641
  gap: number | undefined;
538
642
  action: BoxAction | undefined;
539
643
  }, string | react.JSXElementConstructor<any>>;
540
- declare function TSeparator({ color }: TSeparatorProps): react.ReactElement<{
644
+ declare function TSeparator({ color, char }: TSeparatorProps): react.ReactElement<{
541
645
  color: string | undefined;
646
+ char: string | undefined;
647
+ }, string | react.JSXElementConstructor<any>>;
648
+ type TBlankProps = {
649
+ lines?: number;
650
+ };
651
+ declare function TBlank({ lines }?: TBlankProps): react.ReactElement<{
652
+ lines: number | undefined;
542
653
  }, string | react.JSXElementConstructor<any>>;
543
- declare function TBlank(): react.DOMElement<{}, Element>;
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>;
544
666
  declare function TRaw({ children, text, color, bg, bold, dim, blink, inverted, onClick }: TRawProps): react.DOMElement<{
545
667
  text: string | undefined;
546
668
  color: string | undefined;
@@ -589,7 +711,7 @@ declare function THtml({ value, themeOverrides }: THtmlProps): react.ReactElemen
589
711
  themeOverrides: Partial<ThemeMarkdown> | undefined;
590
712
  }, string | react.JSXElementConstructor<any>>;
591
713
  declare function TLine({ children }: TLineProps): react.DOMElement<{}, Element>;
592
- 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<{
593
715
  text: string | undefined;
594
716
  color: string | undefined;
595
717
  bg: string | undefined;
@@ -597,6 +719,15 @@ declare function TSpan({ children, text, color, bg, bold, dim, inverted, blink }
597
719
  dim: boolean | undefined;
598
720
  inverted: boolean | undefined;
599
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;
600
731
  }, string | react.JSXElementConstructor<any>>;
601
732
  declare function TLayout({ layout }: TLayoutProps): react.ReactElement<{
602
733
  layout: LayoutFn;
@@ -615,12 +746,20 @@ declare function TCode({ code, language, title, borderColor, action, copyable }:
615
746
  action: BoxAction | undefined;
616
747
  copyable: boolean | undefined;
617
748
  }, string | react.JSXElementConstructor<any>>;
618
- declare function TDiff({ value, addColor, removeColor, metaColor }: TDiffProps): react.ReactElement<{
749
+ declare function TUnifiedDiff({ value, addColor, removeColor, metaColor }: TUnifiedDiffProps): react.ReactElement<{
619
750
  value: string;
620
751
  addColor: string | undefined;
621
752
  removeColor: string | undefined;
622
753
  metaColor: string | undefined;
623
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>>;
624
763
  declare function TBar({ label, value, max, color }: TBarProps): react.ReactElement<{
625
764
  label: string;
626
765
  value: number;
@@ -632,16 +771,128 @@ declare function TSpark({ data, color }: TSparkProps): react.ReactElement<{
632
771
  color: string | undefined;
633
772
  }, string | react.JSXElementConstructor<any>>;
634
773
  declare function TList({ items, ordered, bulletColor, color }: TListProps): react.ReactElement<{
635
- items: string[];
774
+ items: ListItem[];
636
775
  ordered: boolean | undefined;
637
776
  bulletColor: string | undefined;
638
777
  color: string | undefined;
639
778
  }, string | react.JSXElementConstructor<any>>;
640
- declare function TButton({ label, onClick, color, bg }: TButtonProps): react.DOMElement<{
779
+ declare function TButton({ label, onClick, color, bg, bold, dim }: TButtonProps): react.DOMElement<{
641
780
  label: string;
642
781
  onClick: (() => void) | undefined;
643
782
  color: string | undefined;
644
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;
645
896
  }, Element>;
646
897
  declare function renderTermReact(tree: ReactNode, opts?: RenderTermOptions): LayoutFn;
647
898
 
@@ -650,4 +901,4 @@ declare function useTick(ms?: number): number;
650
901
  declare function useTermWidth(ref: RefObject<HTMLElement | null>, fallback?: number): number;
651
902
  declare function useStreamingText(text: string, lerp?: number): string;
652
903
 
653
- export { type Block, type BoxAction, 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 };