-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace all control renderers with a cell equivalent.
also add a fix for #2156 at dateTimeCell: use v-model instead of value and add missing seconds at timeCell
- Loading branch information
Showing
24 changed files
with
291 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<input | ||
:id="cell.id + '-input'" | ||
type="checkbox" | ||
:class="styles.control.input" | ||
:checked="!!cell.data" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
:placeholder="appliedOptions.placeholder" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { CellProps, RankedTester } from '@jsonforms/core'; | ||
import { isBooleanControl, rankWith } from '@jsonforms/core'; | ||
import { useJsonFormsCell } from '@jsonforms/vue'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell( | ||
useJsonFormsCell(props), | ||
(target) => target.checked | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
defineOptions({ | ||
tester: rankWith(1, isBooleanControl) as RankedTester, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<input | ||
:id="cell.id + '-input'" | ||
type="date" | ||
:class="styles.control.input" | ||
:value="cell.data" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
:placeholder="appliedOptions.placeholder" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { CellProps, RankedTester } from '@jsonforms/core'; | ||
import { isDateControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell( | ||
useJsonFormsCell(props), | ||
(target) => target.value || undefined | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
defineOptions({ | ||
tester: rankWith(2, isDateControl) as RankedTester, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<template> | ||
<input | ||
:id="cell.id + '-input'" | ||
v-model="dataTime" | ||
type="datetime-local" | ||
:class="styles.control.input" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
:placeholder="appliedOptions.placeholder" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, watch } from 'vue'; | ||
import { useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { CellProps, RankedTester } from '@jsonforms/core'; | ||
import { isDateTimeControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell(useJsonFormsCell(props), (target) => | ||
'' !== target.value ? toISO(target.value) : undefined | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
const fromISO = (str: string | undefined) => str?.slice(0, 16); | ||
const toISO = (str: string) => str + ':00.000Z'; | ||
const dataTime = ref(); | ||
const setDateTime = (str: string | undefined) => { | ||
dataTime.value = fromISO(str); | ||
}; | ||
setDateTime(props.data.value); | ||
watch(() => props.data, setDateTime); | ||
defineOptions({ | ||
tester: rankWith(2, isDateTimeControl) as RankedTester, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<select | ||
:id="cell.id + '-select'" | ||
:class="styles.control.select" | ||
:value="cell.data" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
> | ||
<option key="empty" value="" :class="styles.control.option" /> | ||
<option | ||
v-for="optionElement in cell?.options" | ||
:key="optionElement.value" | ||
:value="optionElement.value" | ||
:label="optionElement.label" | ||
:class="styles.control.option" | ||
></option> | ||
</select> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useJsonFormsEnumCell } from '@jsonforms/vue'; | ||
import type { CellProps } from '@jsonforms/core'; | ||
import { isEnumControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell(useJsonFormsEnumCell(props), (target) => | ||
target.selectedIndex === 0 ? undefined : target.value | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
defineOptions({ | ||
tester: rankWith(2, isEnumControl), | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<select | ||
:id="cell.id + '-input'" | ||
:class="styles.control.select" | ||
:value="cell.data" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
> | ||
<option key="empty" value="" :class="styles.control.option" /> | ||
<option | ||
v-for="optionElement in cell.options" | ||
:key="optionElement.value" | ||
:value="optionElement.value" | ||
:label="optionElement.label" | ||
:class="styles.control.option" | ||
></option> | ||
</select> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useJsonFormsOneOfEnumCell } from '@jsonforms/vue'; | ||
import type { CellProps, RankedTester } from '@jsonforms/core'; | ||
import { isOneOfEnumControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell(useJsonFormsOneOfEnumCell(props), (target) => | ||
target.selectedIndex === 0 ? undefined : target.value | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
defineOptions({ | ||
tester: rankWith(5, isOneOfEnumControl) as RankedTester, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<textarea | ||
:id="cell.id + '-input'" | ||
:class="styles.control.textarea" | ||
:value="cell.data" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
:placeholder="appliedOptions.placeholder" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { CellProps, RankedTester } from '@jsonforms/core'; | ||
import { | ||
and, | ||
isMultiLineControl, | ||
isStringControl, | ||
rankWith, | ||
} from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell( | ||
useJsonFormsCell(props), | ||
(target) => target.value || undefined | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
defineOptions({ | ||
tester: rankWith(2, and(isStringControl, isMultiLineControl)) as RankedTester, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<input | ||
:id="cell.id + '-input'" | ||
type="time" | ||
:class="styles.control.input" | ||
:value="cell.data" | ||
:disabled="!cell.enabled" | ||
:autofocus="appliedOptions.focus" | ||
:placeholder="appliedOptions.placeholder" | ||
@change="onChange" | ||
@focus="isFocused = true" | ||
@blur="isFocused = false" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { CellProps, RankedTester } from '@jsonforms/core'; | ||
import { isTimeControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
const props = defineProps<CellProps>(); | ||
const input = useVanillaCell(useJsonFormsCell(props), (target) => | ||
appendSeconds(target.value || undefined) | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
const appendSeconds = (value: string | undefined) => | ||
value?.split(':').length === 2 ? value + ':00' : value; | ||
defineOptions({ | ||
tester: rankWith(2, isTimeControl) as RankedTester, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.