Skip to content

Commit 2c5ac0e

Browse files
committed
Inline worker
1 parent 1261998 commit 2c5ac0e

14 files changed

+888
-230
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ node_modules
99
/demo-dist
1010
/docs
1111
/docs-src
12+
/tools
1213

1314

README.md

+32-26
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ No dependencies, works directly on the DOM API. Runs in any modern browser and I
2222
test.ts
2323

2424
```typescript
25-
import { BigJsonViewer } from 'big-json-viewer';
26-
27-
document.body.appendChild(
28-
BigJsonViewer.elementFromData(
29-
JSON.stringify({
30-
test: 23,
31-
someArray: [45, 2, 5, true, false, null]
32-
})
33-
)
34-
);
25+
import { BigJsonViewerDom } from 'big-json-viewer';
26+
27+
BigJsonViewerDom.fromData(JSON.stringify({ test: 23 })).then(viewer => {
28+
const node = viewer.getRootElement();
29+
document.body.appendChild(node);
30+
node.openAll(1);
31+
});
3532
```
3633

3734
index.html
@@ -56,17 +53,18 @@ Example run with `parcel` (`npm install -D parce-bundler`);
5653

5754
## Getting started
5855

59-
You want to use the static method to display a JSON.
56+
You can use the following static method to get a new viewer instance:
6057

6158
```typescript
62-
BigJsonViewer.elementFromData(data: ArrayBuffer | string, options?: BigJsonViewerOptions): JsonNodeElement
59+
import { BigJsonViewerDom, BigJsonViewerOptions } from 'big-json-viewer';
60+
BigJsonViewerDom.fromData(data: ArrayBuffer | string, options?: BigJsonViewerOptions): Promise<BigJsonViewerDom>
6361
```
6462

65-
It returns a `JsonNodeElement` object, that is an `HTMLDivElement` with some extras. You can insert it anywhere in your DOM.
63+
It returns a `BigJsonViewerDom` instance. Call `getRootElement()` on it to get a `JsonNodeElement`, that is an `HTMLDivElement` with some extras. You can insert it anywhere in your DOM.
6664

6765
## Options
6866

69-
When calling `elementFromData`, you can provide an object matching the interface `BigJsonViewerOptions`.
67+
When calling `fromData`, you can provide an object matching the interface `BigJsonViewerOptions`.
7068

7169
Example:
7270

@@ -80,6 +78,26 @@ Example:
8078

8179
## API
8280

81+
## `BigJsonViewerDom` methods
82+
83+
#### `getRootElement()`
84+
85+
Returns the `JsonNodeElement` that can be appended to the DOM.
86+
87+
#### `destroy()`
88+
89+
Call this to free resources. It will terminate any by the instance started worker.
90+
91+
#### `openBySearch(pattern: RegExp, openLimit?: number, searchArea?: TreeSearchAreaOption): TreeSearchCursor;`
92+
93+
Searches the tree by the specified `pattern` and `searchArea`. Returns a `TreeSearchCursor`, which contains all matches and methods to jump the focus between the matches.
94+
95+
* `openLimit` is `1` by default. But can be `Infinity` or any number.
96+
* `searchArea` describes where the pattern should be searched. Has the following options:
97+
* `'all'` search in keys and values (default)
98+
* `'keys'` search only in keys
99+
* `'values'` search only in values
100+
83101
## `JsonNodeElement` methods
84102

85103
#### `openNode()`
@@ -115,16 +133,6 @@ Returns a list of opened paths.
115133

116134
When you have a limit of 50 nodes and you open the second stub `[50 ... 99]`, a path it retuned that contains the name of the first node in the stub.
117135

118-
#### `openBySearch(pattern: RegExp, openLimit?: number, searchArea?: TreeSearchAreaOption): TreeSearchCursor;`
119-
120-
Searches the tree by the specified `pattern` and `searchArea`. Returns a `TreeSearchCursor`, which contains all matches and methods to jump the focus between the matches.
121-
122-
* `openLimit` is `1` by default. But can be `Infinity` or any number.
123-
* `searchArea` describes where the pattern should be searched. Has the following options:
124-
* `'all'` search in keys and values (default)
125-
* `'keys'` search only in keys
126-
* `'values'` search only in values
127-
128136
### `JsonNodeElement` Events
129137

130138
The following events are being fired on the visible DOM elements. The events bubble up, so you just need a listener to your root element.
@@ -163,9 +171,7 @@ Fires when the user clicks on the Copy Path link of a node.
163171

164172
## Future TODOs
165173

166-
* Fix highlight all on search and not only the first
167174
* Improve display of large strings.
168-
* Run the parser in a WebWorker
169175
* Support JSON Schema. If provided show meta information from the schema definition.
170176

171177
## License

docs/big-json-viewer.worker.683ccf05.js

-12
This file was deleted.

docs/big-json-viewer.worker.6f419bb3.map

-1
This file was deleted.

0 commit comments

Comments
 (0)