diff --git a/docs/framework/public/components/jsonviewer.png b/docs/framework/public/components/jsonviewer.png new file mode 100644 index 000000000..2146de402 Binary files /dev/null and b/docs/framework/public/components/jsonviewer.png differ diff --git a/src/ui/src/core/templateMap.ts b/src/ui/src/core/templateMap.ts index b9a476552..6922c5a7f 100644 --- a/src/ui/src/core/templateMap.ts +++ b/src/ui/src/core/templateMap.ts @@ -14,6 +14,7 @@ import CoreLink from "../core_components/content/CoreLink.vue"; import CoreChatbot from "../core_components/content/CoreChatbot.vue"; import CoreTags from "../core_components/content/CoreTags.vue"; import CoreAvatar from "../core_components/content/CoreAvatar.vue"; +import CoreJsonViewer from "../core_components/content/CoreJsonViewer.vue"; // input import CoreCheckboxInput from "../core_components/input/CoreCheckboxInput.vue"; import CoreDateInput from "../core_components/input/CoreDateInput.vue"; @@ -115,12 +116,13 @@ const templateMap = { switchinput: CoreSwitchInput, reuse: CoreReuse, avatar: CoreAvatar, + jsonviewer: CoreJsonViewer, }; if (WRITER_LIVE_CCT === "yes") { /* Assigns the components in custom_components to the template map, - allowing for live updates when developing custom component templates. + allowing for live updates when developing custom component templates. */ const liveCCT: Record = (await import("../custom_components")) diff --git a/src/ui/src/core_components/base/BaseCollapsible.vue b/src/ui/src/core_components/base/BaseCollapsible.vue new file mode 100644 index 000000000..2a24dd1a8 --- /dev/null +++ b/src/ui/src/core_components/base/BaseCollapsible.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/src/ui/src/core_components/base/BaseJsonViewer.utils.ts b/src/ui/src/core_components/base/BaseJsonViewer.utils.ts new file mode 100644 index 000000000..c2bf3f615 --- /dev/null +++ b/src/ui/src/core_components/base/BaseJsonViewer.utils.ts @@ -0,0 +1,32 @@ +import type { + JsonData, + JsonValue, + JsonViewerTogglePayload, +} from "./BaseJsonViewer.vue"; + +export function isJSONValue(data: JsonData): data is JsonValue { + if (["string", "number", "boolean"].includes(typeof data)) return true; + if (data === null) return true; + return false; +} + +export function isJSONArray(data: JsonData): data is JsonData[] { + if (isJSONValue(data)) return false; + return Array.isArray(data); +} + +export function isJSONObject( + data: JsonData, +): data is { [x: string]: JsonData } { + return !isJSONArray(data) && typeof data === "object" && data !== null; +} + +export function getJSONLength(data: JsonData): number { + return isJSONValue(data) ? 1 : Object.keys(data).length; +} + +export function jsonViewerToggleEmitDefinition( + payload: JsonViewerTogglePayload, +) { + return typeof payload.open === "boolean" && Array.isArray(payload.path); +} diff --git a/src/ui/src/core_components/base/BaseJsonViewer.vue b/src/ui/src/core_components/base/BaseJsonViewer.vue new file mode 100644 index 000000000..51c499c69 --- /dev/null +++ b/src/ui/src/core_components/base/BaseJsonViewer.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/src/ui/src/core_components/base/BaseJsonViewerChildrenCounter.vue b/src/ui/src/core_components/base/BaseJsonViewerChildrenCounter.vue new file mode 100644 index 000000000..2b8ac462c --- /dev/null +++ b/src/ui/src/core_components/base/BaseJsonViewerChildrenCounter.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/src/ui/src/core_components/base/BaseJsonViewerCollapsible.vue b/src/ui/src/core_components/base/BaseJsonViewerCollapsible.vue new file mode 100644 index 000000000..caa0154f4 --- /dev/null +++ b/src/ui/src/core_components/base/BaseJsonViewerCollapsible.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/src/ui/src/core_components/base/BaseJsonViewerObject.vue b/src/ui/src/core_components/base/BaseJsonViewerObject.vue new file mode 100644 index 000000000..c49ffac1c --- /dev/null +++ b/src/ui/src/core_components/base/BaseJsonViewerObject.vue @@ -0,0 +1,123 @@ + + + + + diff --git a/src/ui/src/core_components/base/BaseJsonViewerValue.vue b/src/ui/src/core_components/base/BaseJsonViewerValue.vue new file mode 100644 index 000000000..12b0c819f --- /dev/null +++ b/src/ui/src/core_components/base/BaseJsonViewerValue.vue @@ -0,0 +1,21 @@ + + + + + diff --git a/src/ui/src/core_components/content/CoreJsonViewer.vue b/src/ui/src/core_components/content/CoreJsonViewer.vue new file mode 100644 index 000000000..f44c9b3d6 --- /dev/null +++ b/src/ui/src/core_components/content/CoreJsonViewer.vue @@ -0,0 +1,93 @@ + + + + + + +