Skip to content

Commit 0677ac8

Browse files
committedFeb 15, 2024
create useVanillaCell function and use it instead of useVanillaControl at Cells. adjusted DispatchCell props.
1 parent e108203 commit 0677ac8

File tree

5 files changed

+60
-35
lines changed

5 files changed

+60
-35
lines changed
 

‎packages/vue-vanilla/src/cells/IntegerCell.vue

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<input
3-
:id="control.id + '-input'"
3+
:id="cell.id + '-input'"
44
type="number"
55
:step="1"
66
:class="styles.control.input"
7-
:value="control.data"
8-
:disabled="!control.enabled"
7+
:value="cell.data"
8+
:disabled="!cell.enabled"
99
:autofocus="appliedOptions.focus"
1010
:placeholder="appliedOptions.placeholder"
1111
@change="onChange"
@@ -16,20 +16,19 @@
1616

1717
<script setup lang="ts">
1818
import {
19-
ControlElement,
19+
CellProps,
2020
isIntegerControl,
2121
type RankedTester,
2222
rankWith,
2323
} from '@jsonforms/core';
24-
import { rendererProps, useJsonFormsControl } from '@jsonforms/vue';
25-
import { useVanillaControl } from '../util';
24+
import { useJsonFormsCell } from '@jsonforms/vue';
25+
import { useVanillaCell } from '../util';
2626
27-
const props = defineProps(rendererProps<ControlElement>());
28-
29-
const input = useVanillaControl(useJsonFormsControl(props), (target) =>
27+
const props = defineProps<CellProps>();
28+
const input = useVanillaCell(useJsonFormsCell(props), (target) =>
3029
target.value === '' ? undefined : parseInt(target.value, 10)
3130
);
32-
const { styles, control, appliedOptions, onChange, isFocused } = input;
31+
const { styles, cell, appliedOptions, onChange, isFocused } = input;
3332
3433
defineOptions({
3534
tester: rankWith(1, isIntegerControl) as RankedTester,

‎packages/vue-vanilla/src/cells/NumberCell.vue

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<input
3-
:id="control.id + '-input'"
3+
:id="cell.id + '-input'"
44
type="number"
55
:step="step"
66
:class="styles.control.input"
7-
:value="control.data"
8-
:disabled="!control.enabled"
7+
:value="cell.data"
8+
:disabled="!cell.enabled"
99
:autofocus="appliedOptions.focus"
1010
:placeholder="appliedOptions.placeholder"
1111
@change="onChange"
@@ -16,21 +16,20 @@
1616

1717
<script setup lang="ts">
1818
import {
19-
ControlElement,
19+
CellProps,
2020
isNumberControl,
2121
type RankedTester,
2222
rankWith,
2323
} from '@jsonforms/core';
24-
import { rendererProps, useJsonFormsControl } from '@jsonforms/vue';
25-
import { useVanillaControl } from '../util';
24+
import { useJsonFormsCell } from '@jsonforms/vue';
25+
import { useVanillaCell } from '../util';
2626
import { computed } from 'vue';
2727
28-
const props = defineProps(rendererProps<ControlElement>());
29-
30-
const input = useVanillaControl(useJsonFormsControl(props), (target) =>
28+
const props = defineProps<CellProps>();
29+
const input = useVanillaCell(useJsonFormsCell(props), (target) =>
3130
target.value === '' ? undefined : Number(target.value)
3231
);
33-
const { styles, control, appliedOptions, onChange, isFocused } = input;
32+
const { styles, cell, appliedOptions, onChange, isFocused } = input;
3433
3534
const step = computed(() => {
3635
const options: any = appliedOptions;

‎packages/vue-vanilla/src/cells/TextCell.vue

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<input
3-
:id="control.id + '-input'"
3+
:id="cell.id + '-input'"
44
:class="styles.control.input"
5-
:value="control.data"
6-
:disabled="!control.enabled"
5+
:value="cell.data"
6+
:disabled="!cell.enabled"
77
:autofocus="appliedOptions.focus"
88
:placeholder="appliedOptions.placeholder"
99
@change="onChange"
@@ -14,21 +14,21 @@
1414

1515
<script setup lang="ts">
1616
import {
17-
ControlElement,
17+
CellProps,
1818
isStringControl,
1919
type RankedTester,
2020
rankWith,
2121
} from '@jsonforms/core';
22-
import { rendererProps, useJsonFormsControl } from '@jsonforms/vue';
23-
import { useVanillaControl } from '../util';
22+
import { useJsonFormsCell } from '@jsonforms/vue';
23+
import { useVanillaCell } from '../util';
2424
25-
const props = defineProps(rendererProps<ControlElement>());
25+
const props = defineProps<CellProps>();
2626
27-
const input = useVanillaControl(
28-
useJsonFormsControl(props),
27+
const input = useVanillaCell(
28+
useJsonFormsCell(props),
2929
(target) => target.value || undefined
3030
);
31-
const { styles, control, appliedOptions, onChange, isFocused } = input;
31+
const { styles, cell, appliedOptions, onChange, isFocused } = input;
3232
3333
defineOptions({
3434
tester: rankWith(1, isStringControl) as RankedTester,

‎packages/vue-vanilla/src/controls/InputControlRenderer.vue

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
:applied-options="appliedOptions"
77
>
88
<DispatchCell
9-
:id="control.id + '-input'"
10-
:schema="schema"
11-
:uischema="uischema"
12-
:path="path"
13-
:enabled="enabled"
9+
v-bind="control"
10+
:id="controlWrapper.id"
11+
:handle-change="handleChange"
1412
/>
1513
</control-wrapper>
1614
</template>

‎packages/vue-vanilla/src/util/composition.ts

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ import {
99
Resolve,
1010
} from '@jsonforms/core';
1111

12+
/**
13+
* Adds styles, isFocused, appliedOptions and onChange
14+
*/
15+
export const useVanillaCell = <I extends { cell: any; handleChange: any }>(
16+
input: I,
17+
adaptTarget: (target: any) => any = (v) => v.value
18+
) => {
19+
const appliedOptions = computed(() =>
20+
merge(
21+
{},
22+
cloneDeep(input.cell.value.config),
23+
cloneDeep(input.cell.value.uischema.options)
24+
)
25+
);
26+
27+
const isFocused = ref(false);
28+
const onChange = (event: Event) => {
29+
input.handleChange(input.cell.value.path, adaptTarget(event.target));
30+
};
31+
32+
return {
33+
...input,
34+
styles: useStyles(input.cell.value.uischema),
35+
isFocused,
36+
appliedOptions,
37+
onChange,
38+
};
39+
};
40+
1241
/**
1342
* Adds styles, isFocused, appliedOptions and onChange
1443
*/

0 commit comments

Comments
 (0)
Failed to load comments.