-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.js
More file actions
66 lines (58 loc) · 1.76 KB
/
Copy pathRenderer.js
File metadata and controls
66 lines (58 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { Component } from "react";
import { AsabReactJson } from "../components/AsabReactJson/AsabReactJson.jsx";
import { RendererWrapper } from '../components/RendererWrapper/RendererWrapper.jsx';
import './Renderer.scss';
export class Renderer extends Component {
// Renderer defaults
constructor(app) {
super(); // Call super() for React component initialization
this.App = app;
}
render(key, value, schemaField, params = undefined) {
// Render ReactJson component if value is a object
if (typeof value === 'object') {
return (
<AsabReactJson
src={value}
name={false}
collapsed={false}
displayDataTypes={false}
displayArrayKey={false}
quotesOnKeys={false}
enableClipboard={false}
indentWidth={8}
/>
)
}
// Convert bigint to string (to preserve precision and to display the value when no other renderer is applied)
if (typeof value === "bigint") {
value = value.toString();
}
// Render span with value inside as a default
return (
<RendererWrapper
data-value={value} // Passing value (to eventually work with in the external wrapper)
data-key={key} // Passing key (to eventually work with in the external wrapper)
component={params?.WrapperComponent || "span"}
>
{value}
</RendererWrapper>
);
}
plain(key, value, schemaField) {
// Render stringified component if value is a object
if (typeof value === 'object') {
try {
return JSON.stringify(value);
} catch(e) {
console.warn('Failed to stringify the renderer value:', value, e);
return value;
}
}
// Convert bigint to string (to preserve precision and to display the value when no other renderer is applied)
if (typeof value === "bigint") {
value = value.toString();
}
return value;
}
}