2022-12-06 03:50:06 -08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed } from 'vue';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { INodeUi, Schema } from '@/Interface';
|
2023-11-28 03:15:08 -08:00
|
|
|
import { checkExhaustive } from '@/utils/typeGuards';
|
|
|
|
import { shorten } from '@/utils/typesUtils';
|
2023-01-30 03:42:08 -08:00
|
|
|
import { getMappedExpression } from '@/utils/mappingUtils';
|
2023-12-22 06:03:40 -08:00
|
|
|
import TextWithHighlights from './TextWithHighlights.vue';
|
2022-12-06 03:50:06 -08:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
schema: Schema;
|
|
|
|
level: number;
|
|
|
|
parent: Schema | null;
|
|
|
|
subKey: string;
|
2023-03-16 02:19:12 -07:00
|
|
|
paneType: 'input' | 'output';
|
2022-12-06 03:50:06 -08:00
|
|
|
mappingEnabled: boolean;
|
|
|
|
draggingPath: string;
|
|
|
|
distanceFromActive: number;
|
|
|
|
node: INodeUi | null;
|
2023-11-15 07:19:48 -08:00
|
|
|
search: string;
|
2022-12-06 03:50:06 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const props = defineProps<Props>();
|
|
|
|
|
|
|
|
const isSchemaValueArray = computed(() => Array.isArray(props.schema.value));
|
|
|
|
const isSchemaParentTypeArray = computed(() => props.parent?.type === 'array');
|
|
|
|
const isFlat = computed(
|
|
|
|
() =>
|
|
|
|
props.level === 0 &&
|
|
|
|
Array.isArray(props.schema.value) &&
|
|
|
|
props.schema.value.every((v) => !Array.isArray(v.value)),
|
|
|
|
);
|
2023-11-15 07:19:48 -08:00
|
|
|
const key = computed((): string | undefined => {
|
2023-12-22 06:03:40 -08:00
|
|
|
return isSchemaParentTypeArray.value ? `[${props.schema.key}]` : props.schema.key;
|
2023-11-15 07:19:48 -08:00
|
|
|
});
|
2022-12-06 03:50:06 -08:00
|
|
|
const schemaName = computed(() =>
|
|
|
|
isSchemaParentTypeArray.value ? `${props.schema.type}[${props.schema.key}]` : props.schema.key,
|
|
|
|
);
|
|
|
|
const text = computed(() =>
|
|
|
|
Array.isArray(props.schema.value) ? '' : shorten(props.schema.value, 600, 0),
|
2022-12-14 01:04:10 -08:00
|
|
|
);
|
2022-12-06 03:50:06 -08:00
|
|
|
|
2024-03-13 04:57:08 -07:00
|
|
|
const dragged = computed(() => props.draggingPath === props.schema.path);
|
|
|
|
|
2022-12-06 03:50:06 -08:00
|
|
|
const getJsonParameterPath = (path: string): string =>
|
2023-01-30 03:42:08 -08:00
|
|
|
getMappedExpression({
|
|
|
|
nodeName: props.node!.name,
|
|
|
|
distanceFromActive: props.distanceFromActive,
|
|
|
|
path,
|
|
|
|
});
|
|
|
|
|
2022-12-06 03:50:06 -08:00
|
|
|
const transitionDelay = (i: number) => `${i * 0.033}s`;
|
|
|
|
|
|
|
|
const getIconBySchemaType = (type: Schema['type']): string => {
|
|
|
|
switch (type) {
|
|
|
|
case 'object':
|
|
|
|
return 'cube';
|
|
|
|
case 'array':
|
|
|
|
return 'list';
|
|
|
|
case 'string':
|
|
|
|
case 'null':
|
|
|
|
return 'font';
|
|
|
|
case 'number':
|
|
|
|
return 'hashtag';
|
|
|
|
case 'boolean':
|
|
|
|
return 'check-square';
|
|
|
|
case 'function':
|
|
|
|
return 'code';
|
|
|
|
case 'bigint':
|
|
|
|
return 'calculator';
|
|
|
|
case 'symbol':
|
|
|
|
return 'sun';
|
|
|
|
case 'undefined':
|
|
|
|
return 'ban';
|
|
|
|
}
|
|
|
|
|
|
|
|
checkExhaustive(type);
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-03-16 02:19:12 -07:00
|
|
|
<div :class="$style.item" data-test-id="run-data-schema-item">
|
2022-12-06 03:50:06 -08:00
|
|
|
<div
|
|
|
|
v-if="level > 0 || (level === 0 && !isSchemaValueArray)"
|
|
|
|
:title="schema.type"
|
|
|
|
:class="{
|
|
|
|
[$style.pill]: true,
|
|
|
|
[$style.mappable]: mappingEnabled,
|
2024-03-13 04:57:08 -07:00
|
|
|
[$style.highlight]: dragged,
|
2022-12-06 03:50:06 -08:00
|
|
|
}"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
:class="$style.label"
|
|
|
|
:data-value="getJsonParameterPath(schema.path)"
|
|
|
|
:data-name="schemaName"
|
|
|
|
:data-path="schema.path"
|
|
|
|
:data-depth="level"
|
|
|
|
data-target="mappable"
|
|
|
|
>
|
|
|
|
<font-awesome-icon :icon="getIconBySchemaType(schema.type)" size="sm" />
|
2023-12-22 06:03:40 -08:00
|
|
|
<TextWithHighlights
|
|
|
|
v-if="isSchemaParentTypeArray"
|
|
|
|
:content="props.parent?.key"
|
|
|
|
:search="props.search"
|
|
|
|
/>
|
|
|
|
<TextWithHighlights
|
|
|
|
v-if="key"
|
|
|
|
:class="{ [$style.arrayIndex]: isSchemaParentTypeArray }"
|
|
|
|
:content="key"
|
|
|
|
:search="props.search"
|
|
|
|
/>
|
2022-12-06 03:50:06 -08:00
|
|
|
</span>
|
|
|
|
</div>
|
2023-07-19 07:51:49 -07:00
|
|
|
<span v-if="text" :class="$style.text">{{ text }}</span>
|
2022-12-13 05:00:20 -08:00
|
|
|
<input v-if="level > 0 && isSchemaValueArray" :id="subKey" type="checkbox" checked />
|
2022-12-06 03:50:06 -08:00
|
|
|
<label v-if="level > 0 && isSchemaValueArray" :class="$style.toggle" :for="subKey">
|
|
|
|
<font-awesome-icon icon="angle-up" />
|
|
|
|
</label>
|
|
|
|
<div v-if="isSchemaValueArray" :class="{ [$style.sub]: true, [$style.flat]: isFlat }">
|
|
|
|
<run-data-schema-item
|
|
|
|
v-for="(s, i) in schema.value"
|
|
|
|
:key="`${s.type}-${level}-${i}`"
|
|
|
|
:schema="s"
|
|
|
|
:level="level + 1"
|
|
|
|
:parent="schema"
|
2023-12-28 00:49:58 -08:00
|
|
|
:pane-type="paneType"
|
|
|
|
:sub-key="`${paneType}_${s.type}-${level}-${i}`"
|
|
|
|
:mapping-enabled="mappingEnabled"
|
|
|
|
:dragging-path="draggingPath"
|
|
|
|
:distance-from-active="distanceFromActive"
|
2022-12-06 03:50:06 -08:00
|
|
|
:node="node"
|
|
|
|
:style="{ transitionDelay: transitionDelay(i) }"
|
2023-11-15 07:19:48 -08:00
|
|
|
:search="search"
|
2022-12-06 03:50:06 -08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2023-12-29 02:13:24 -08:00
|
|
|
@import '@/styles/variables';
|
2022-12-06 03:50:06 -08:00
|
|
|
|
|
|
|
.item {
|
|
|
|
display: block;
|
|
|
|
position: relative;
|
|
|
|
transition: all 0.3s $ease-out-expo;
|
|
|
|
|
|
|
|
.item {
|
|
|
|
padding-top: var(--spacing-2xs);
|
|
|
|
padding-left: var(--spacing-l);
|
|
|
|
}
|
|
|
|
|
|
|
|
input {
|
|
|
|
position: absolute;
|
|
|
|
left: -100%;
|
|
|
|
|
|
|
|
~ .sub {
|
|
|
|
height: 0;
|
|
|
|
|
|
|
|
> .item {
|
|
|
|
transform: translateX(-100%);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:checked {
|
|
|
|
~ .toggle svg {
|
|
|
|
transform: rotate(180deg);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ .sub {
|
|
|
|
height: auto;
|
|
|
|
|
|
|
|
> .item {
|
|
|
|
transform: translateX(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
content: '';
|
|
|
|
display: block;
|
|
|
|
clear: both;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.sub {
|
|
|
|
display: block;
|
|
|
|
overflow: hidden;
|
|
|
|
transition: all 0.2s $ease-out-expo;
|
|
|
|
clear: both;
|
|
|
|
|
|
|
|
&.flat {
|
|
|
|
> .item {
|
|
|
|
padding-left: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:nth-of-type(1) {
|
|
|
|
> .item:nth-of-type(1) {
|
|
|
|
padding-top: 0;
|
|
|
|
|
|
|
|
.toggle {
|
|
|
|
top: -2px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-13 04:57:08 -07:00
|
|
|
:global(.highlightSchema) {
|
|
|
|
.pill.mappable {
|
|
|
|
&,
|
|
|
|
&:hover,
|
|
|
|
span,
|
|
|
|
&:hover span span {
|
|
|
|
color: var(--color-primary);
|
|
|
|
border-color: var(--color-primary-tint-1);
|
|
|
|
background-color: var(--color-primary-tint-3);
|
|
|
|
|
|
|
|
svg {
|
|
|
|
path {
|
|
|
|
fill: var(--color-primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 03:50:06 -08:00
|
|
|
.pill {
|
|
|
|
float: left;
|
|
|
|
display: inline-flex;
|
|
|
|
height: 24px;
|
|
|
|
padding: 0 var(--spacing-3xs);
|
|
|
|
border: 1px solid var(--color-foreground-light);
|
|
|
|
border-radius: 4px;
|
2022-12-14 05:43:02 -08:00
|
|
|
background-color: var(--color-background-xlight);
|
2022-12-06 03:50:06 -08:00
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
color: var(--color-text-dark);
|
|
|
|
|
|
|
|
span {
|
|
|
|
display: flex;
|
|
|
|
height: 100%;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
svg {
|
|
|
|
path {
|
|
|
|
fill: var(--color-text-light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.mappable {
|
|
|
|
cursor: grab;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
&,
|
|
|
|
span span {
|
|
|
|
background-color: var(--color-background-light);
|
|
|
|
border-color: var(--color-foreground-base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
|
|
|
> span {
|
|
|
|
margin-left: var(--spacing-3xs);
|
|
|
|
padding-left: var(--spacing-3xs);
|
|
|
|
border-left: 1px solid var(--color-foreground-light);
|
|
|
|
|
|
|
|
&.arrayIndex {
|
|
|
|
border: 0;
|
|
|
|
padding-left: 0;
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.text {
|
|
|
|
display: block;
|
|
|
|
padding-top: var(--spacing-4xs);
|
|
|
|
padding-left: var(--spacing-2xs);
|
|
|
|
font-weight: var(--font-weight-normal);
|
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
overflow: hidden;
|
|
|
|
word-break: break-word;
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle {
|
|
|
|
display: flex;
|
|
|
|
position: absolute;
|
|
|
|
padding: var(--spacing-2xs);
|
|
|
|
left: 0;
|
|
|
|
top: 5px;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
cursor: pointer;
|
|
|
|
user-select: none;
|
|
|
|
font-weight: normal;
|
|
|
|
font-size: var(--font-size-s);
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
svg {
|
|
|
|
transition: all 0.3s $ease-out-expo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|