-
Notifications
You must be signed in to change notification settings - Fork 396
Cell renderer set for vue vanilla (work in progress) #2279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
davewwww
wants to merge
5
commits into
eclipsesource:master
Choose a base branch
from
davewwww:feature/cell-render-set
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4baa52
rebase onto master
davewwww 6a52e77
create useVanillaCell function and use it instead of useVanillaContro…
davewwww 8c09746
replace all control renderers with a cell equivalent.
davewwww 029308e
use rendererProps() for defineProps(), use input.cell.value.data inst…
davewwww 893774b
hand over only some keys instead of binding control
davewwww File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,40 @@ | ||
<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 { ControlElement, RankedTester } from '@jsonforms/core'; | ||
import { isBooleanControl, rankWith } from '@jsonforms/core'; | ||
import { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
const input = useVanillaCell( | ||
useJsonFormsCell(props), | ||
(target) => target.checked | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
|
||
/** | ||
* JUST AN PROPOSAL!!! | ||
* @see https://github.com/eclipsesource/jsonforms/pull/2279#discussion_r1528101480 | ||
*/ | ||
defineOptions( | ||
((): { tester: RankedTester } => { | ||
const tester: RankedTester = rankWith(1, isBooleanControl); | ||
return { tester }; | ||
})() | ||
); | ||
</script> |
This file contains hidden or 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 { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { ControlElement, RankedTester } from '@jsonforms/core'; | ||
import { isDateControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
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 hidden or 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 { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { RankedTester, ControlElement } from '@jsonforms/core'; | ||
import { isDateTimeControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
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(input.cell.value.data); | ||
watch(() => input.cell.value.data, setDateTime); | ||
|
||
defineOptions({ | ||
tester: rankWith(2, isDateTimeControl) as RankedTester, | ||
}); | ||
</script> |
This file contains hidden or 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 { rendererProps, useJsonFormsEnumCell } from '@jsonforms/vue'; | ||
import type { ControlElement } from '@jsonforms/core'; | ||
import { isEnumControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
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 hidden or 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 { rendererProps, useJsonFormsOneOfEnumCell } from '@jsonforms/vue'; | ||
import type { RankedTester, ControlElement } from '@jsonforms/core'; | ||
import { isOneOfEnumControl, rankWith } from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
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 hidden or 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="number" | ||
:step="1" | ||
: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 type { RankedTester, ControlElement } from '@jsonforms/core'; | ||
import { isIntegerControl, rankWith } from '@jsonforms/core'; | ||
import { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
const input = useVanillaCell(useJsonFormsCell(props), (target) => | ||
target.value === '' ? undefined : parseInt(target.value, 10) | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
|
||
defineOptions({ | ||
tester: rankWith(1, isIntegerControl) as RankedTester, | ||
}); | ||
</script> |
This file contains hidden or 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> | ||
<input | ||
:id="cell.id + '-input'" | ||
type="number" | ||
:step="step" | ||
: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 { computed } from 'vue'; | ||
import type { ControlElement, RankedTester } from '@jsonforms/core'; | ||
import { isNumberControl, rankWith } from '@jsonforms/core'; | ||
import { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
const input = useVanillaCell(useJsonFormsCell(props), (target) => | ||
target.value === '' ? undefined : Number(target.value) | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
|
||
const step = computed(() => { | ||
const options: any = appliedOptions; | ||
return options.step ?? 0.1; | ||
}); | ||
|
||
defineOptions({ | ||
tester: rankWith(1, isNumberControl) as RankedTester, | ||
}); | ||
</script> |
This file contains hidden or 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,32 @@ | ||
<template> | ||
<input | ||
:id="cell.id + '-input'" | ||
: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 type { ControlElement, RankedTester } from '@jsonforms/core'; | ||
import { isStringControl, rankWith } from '@jsonforms/core'; | ||
import { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
const input = useVanillaCell( | ||
useJsonFormsCell(props), | ||
(target) => target.value || undefined | ||
); | ||
const { styles, cell, appliedOptions, onChange, isFocused } = input; | ||
|
||
defineOptions({ | ||
tester: rankWith(1, isStringControl) as RankedTester, | ||
}); | ||
</script> |
This file contains hidden or 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 { rendererProps, useJsonFormsCell } from '@jsonforms/vue'; | ||
import type { ControlElement, RankedTester } from '@jsonforms/core'; | ||
import { | ||
and, | ||
isMultiLineControl, | ||
isStringControl, | ||
rankWith, | ||
} from '@jsonforms/core'; | ||
import { useVanillaCell } from '../util'; | ||
|
||
const props = defineProps(rendererProps<ControlElement>()); | ||
|
||
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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.