Skip to content

Commit b7e4612

Browse files
authored
small refactor to group component files together and separate out types (#33)
1 parent 962fc85 commit b7e4612

File tree

6 files changed

+37
-30
lines changed

6 files changed

+37
-30
lines changed

projects/ngx-json-treeview/src/lib/ngx-json-treeview.component.ts renamed to projects/ngx-json-treeview/src/lib/ngx-json-treeview/ngx-json-treeview.component.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
11
import { Component, computed, inject, input, output } from '@angular/core';
2-
import { ID_GENERATOR } from './services/id-generator';
3-
import { decycle, previewString } from './util';
4-
5-
/**
6-
* Represents a segment (node) within the JSON tree structure.
7-
* Each segment corresponds to a key-value pair in an object, an item in an
8-
* array, or the root value itself, providing context and state for rendering.
9-
*/
10-
export interface Segment {
11-
/** The key (for objects) or index (for arrays). */
12-
key: string;
13-
/** The actual JavaScript value represented by this segment. */
14-
value: any;
15-
/** The JavaScript data type of the value. */
16-
type?: string;
17-
/** A string representation of the value, used for display purposes. */
18-
description: string;
19-
/** Indicates whether the segment is expanded in the UI. */
20-
expanded: boolean;
21-
/** A reference to the parent segment in the JSON tree. Undefined for root. */
22-
parent?: Segment;
23-
/**
24-
* A dot/bracket notation path string to this specific segment
25-
* (e.g., 'settings.notifications.email', 'items[1].value').
26-
*/
27-
path: string;
28-
}
29-
30-
export type IsClickableValueFn = (segment: Segment) => boolean;
2+
import { ID_GENERATOR } from '../services/id-generator';
3+
import { IsClickableValueFn, Segment } from '../types';
4+
import { decycle, previewString } from '../util';
315

326
/**
337
* Renders JSON data in an expandable and collapsible tree structure.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Represents a segment (node) within the JSON tree structure.
3+
* Each segment corresponds to a key-value pair in an object, an item in an
4+
* array, or the root value itself, providing context and state for rendering.
5+
*/
6+
export interface Segment {
7+
/** The key (for objects) or index (for arrays). */
8+
key: string;
9+
/** The actual JavaScript value represented by this segment. */
10+
value: any;
11+
/** The JavaScript data type of the value. */
12+
type?: string;
13+
/** A string representation of the value, used for display purposes. */
14+
description: string;
15+
/** Indicates whether the segment is expanded in the UI. */
16+
expanded: boolean;
17+
/** A reference to the parent segment in the JSON tree. Undefined for root. */
18+
parent?: Segment;
19+
/**
20+
* A dot/bracket notation path string to this specific segment
21+
* (e.g., 'settings.notifications.email', 'items[1].value').
22+
*/
23+
path: string;
24+
}
25+
26+
/**
27+
* A function that determines whether a given segment's value should be
28+
* clickable.
29+
* @param segment The segment to evaluate.
30+
* @returns `true` if the value is clickable, `false` otherwise.
31+
*/
32+
export type IsClickableValueFn = (segment: Segment) => boolean;

projects/ngx-json-treeview/src/public-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* Public API Surface of ngx-json-treeview
33
*/
44

5-
export * from './lib/ngx-json-treeview.component';
5+
export * from './lib/ngx-json-treeview/ngx-json-treeview.component';
6+
export * from './lib/types';

0 commit comments

Comments
 (0)