@ghentcdh/json-forms-vue 0.7.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { PropType } from 'vue';
1
2
  declare function __VLS_template(): {
2
3
  attrs: Partial<{}>;
3
4
  slots: {
@@ -8,6 +9,10 @@ declare function __VLS_template(): {
8
9
  };
9
10
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
10
11
  declare const __VLS_component: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
12
+ modelValue: {
13
+ type: PropType<any>;
14
+ default: () => {};
15
+ };
11
16
  id: {
12
17
  type: StringConstructor;
13
18
  required: boolean;
@@ -20,10 +25,10 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
20
25
  type: StringConstructor;
21
26
  };
22
27
  schema: {
23
- type: import('vue').PropType<any>;
28
+ type: PropType<any>;
24
29
  };
25
30
  uiSchema: {
26
- type: import('vue').PropType<any>;
31
+ type: PropType<any>;
27
32
  };
28
33
  uri: {
29
34
  type: StringConstructor;
@@ -36,12 +41,11 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
36
41
  type: BooleanConstructor;
37
42
  default: boolean;
38
43
  };
44
+ }>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
39
45
  modelValue: {
40
- type: import('vue').PropType<any>;
46
+ type: PropType<any>;
47
+ default: () => {};
41
48
  };
42
- }>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
43
- "update:modelValue": (value: any) => void;
44
- }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
45
49
  id: {
46
50
  type: StringConstructor;
47
51
  required: boolean;
@@ -54,10 +58,10 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
54
58
  type: StringConstructor;
55
59
  };
56
60
  schema: {
57
- type: import('vue').PropType<any>;
61
+ type: PropType<any>;
58
62
  };
59
63
  uiSchema: {
60
- type: import('vue').PropType<any>;
64
+ type: PropType<any>;
61
65
  };
62
66
  uri: {
63
67
  type: StringConstructor;
@@ -70,12 +74,8 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
70
74
  type: BooleanConstructor;
71
75
  default: boolean;
72
76
  };
73
- modelValue: {
74
- type: import('vue').PropType<any>;
75
- };
76
- }>> & Readonly<{
77
- "onUpdate:modelValue"?: ((value: any) => any) | undefined;
78
- }>, {
77
+ }>> & Readonly<{}>, {
78
+ modelValue: any;
79
79
  scrollable: boolean;
80
80
  fullHeight: boolean;
81
81
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, HTMLDivElement>;
package/index.js CHANGED
@@ -128,7 +128,9 @@ const FormWithTableEmits = [
128
128
  /** Emitted after a record is successfully deleted. Payload: the deleted record. */
129
129
  "delete",
130
130
  /** Forwarded form events dispatched by custom renderers inside the modal (e.g. "create"). Payload: `FormEventPayload`. */
131
- "events"
131
+ "events",
132
+ "custom:edit",
133
+ "custom:create"
132
134
  ];
133
135
  const createFormEvents = (dispatch) => ({
134
136
  dispatch
@@ -1014,13 +1016,26 @@ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
1014
1016
  store = new FormStore(uri ?? "");
1015
1017
  });
1016
1018
  const hasEdit = ui.hasCustomEventListener("editData");
1019
+ const customEdit = ui.hasCustomEventListener("custom:edit");
1020
+ const customCreate = ui.hasCustomEventListener("custom:create");
1017
1021
  const edit = (data) => {
1022
+ if (customEdit) {
1023
+ emit("custom:edit", data);
1024
+ return;
1025
+ }
1018
1026
  if (hasEdit) {
1019
1027
  emit("editData", data);
1020
1028
  return;
1021
1029
  }
1022
1030
  openModal(data);
1023
1031
  };
1032
+ const create = () => {
1033
+ if (customCreate) {
1034
+ emit("custom:create");
1035
+ return;
1036
+ }
1037
+ openModal();
1038
+ };
1024
1039
  const deleteFn = (data) => {
1025
1040
  ui.ModalService.showConfirm({
1026
1041
  title: "Delete record",
@@ -1063,7 +1078,7 @@ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
1063
1078
  vue.createVNode(vue.unref(ui.Btn), {
1064
1079
  icon: vue.unref(ui.IconEnum).Plus,
1065
1080
  outline: true,
1066
- onClick: openModal
1081
+ onClick: create
1067
1082
  }, {
1068
1083
  default: vue.withCtx(() => [..._cache[0] || (_cache[0] = [
1069
1084
  vue.createTextVNode(" Add new record ", -1)
@@ -8143,22 +8158,34 @@ const _hoisted_1 = { class: "flex justify-end gap-2 p-2 mt-2 border-t border-gra
8143
8158
  const _hoisted_2 = { class: "flex justify-end gap-2" };
8144
8159
  const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
8145
8160
  __name: "form-with-actions.component",
8146
- props: /* @__PURE__ */ vue.mergeModels(FormWithActionsProperties, {
8147
- "modelValue": {},
8148
- "modelModifiers": {}
8149
- }),
8150
- emits: /* @__PURE__ */ vue.mergeModels(FormWithActionsEmits, ["update:modelValue"]),
8161
+ props: {
8162
+ ...FormWithActionsProperties,
8163
+ modelValue: { type: Object, default: () => ({}) }
8164
+ },
8165
+ emits: FormWithActionsEmits,
8151
8166
  setup(__props, { emit: __emit }) {
8152
8167
  const properties = __props;
8153
8168
  const emits = __emit;
8154
- const formData = vue.useModel(__props, "modelValue");
8169
+ const formData = vue.ref(properties.modelValue);
8170
+ const initialFormData = vue.ref(structuredClone(vue.toRaw(properties.modelValue)));
8171
+ const recordId = vue.ref(properties.modelValue?.id ?? null);
8155
8172
  const valid = vue.ref(false);
8156
8173
  const submitted = vue.ref(false);
8174
+ vue.watch(
8175
+ () => properties.modelValue,
8176
+ (newValue, oldValue) => {
8177
+ if (newValue === formData.value) return;
8178
+ recordId.value = newValue?.id ?? null;
8179
+ initialFormData.value = structuredClone(vue.toRaw(newValue));
8180
+ formData.value = newValue;
8181
+ }
8182
+ );
8157
8183
  const store = vue.computed(
8158
8184
  () => properties.uri ? new FormStore(properties.uri) : null
8159
8185
  );
8160
8186
  const updateValue = (data) => {
8161
8187
  formData.value = data;
8188
+ emits("update:modelValue", data);
8162
8189
  };
8163
8190
  const save = () => {
8164
8191
  submitted.value = true;
@@ -8166,7 +8193,7 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
8166
8193
  return;
8167
8194
  }
8168
8195
  if (store.value) {
8169
- store.value.save(formData.value.id, formData.value).then(() => {
8196
+ store.value.save(recordId.value, formData.value).then(() => {
8170
8197
  emits("success");
8171
8198
  });
8172
8199
  } else {
@@ -8176,9 +8203,12 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
8176
8203
  const clear = () => {
8177
8204
  formData.value = { id: null };
8178
8205
  submitted.value = false;
8206
+ emits("update:modelValue", formData.value);
8179
8207
  };
8180
8208
  const cancel = () => {
8209
+ formData.value = structuredClone(vue.toRaw(initialFormData.value));
8181
8210
  submitted.value = false;
8211
+ emits("update:modelValue", formData.value);
8182
8212
  emits("cancel");
8183
8213
  };
8184
8214
  const onValid = (v) => {
@@ -8188,7 +8218,7 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
8188
8218
  };
8189
8219
  const title = vue.computed(() => {
8190
8220
  if (!properties.updateTitle) return properties.createTitle;
8191
- return formData.value?.id ? properties.updateTitle : properties.createTitle;
8221
+ return recordId.value ? properties.updateTitle : properties.createTitle;
8192
8222
  });
8193
8223
  return (_ctx, _cache) => {
8194
8224
  return vue.openBlock(), vue.createBlock(vue.unref(ui.Collapse), {
@@ -8224,26 +8254,25 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
8224
8254
  ]),
8225
8255
  vue.createElementVNode("div", _hoisted_2, [
8226
8256
  vue.renderSlot(_ctx.$slots, "actions"),
8227
- !formData.value.id ? (vue.openBlock(), vue.createBlock(vue.unref(ui.Btn), {
8257
+ recordId.value ? (vue.openBlock(), vue.createBlock(vue.unref(ui.Btn), {
8228
8258
  key: 0,
8229
8259
  outline: true,
8230
- onClick: clear
8260
+ onClick: cancel
8231
8261
  }, {
8232
8262
  default: vue.withCtx(() => [..._cache[3] || (_cache[3] = [
8233
- vue.createTextVNode(" Clear ", -1)
8263
+ vue.createTextVNode(" Cancel ", -1)
8234
8264
  ])]),
8235
8265
  _: 1
8236
- })) : vue.createCommentVNode("", true),
8237
- formData.value.id ? (vue.openBlock(), vue.createBlock(vue.unref(ui.Btn), {
8266
+ })) : (vue.openBlock(), vue.createBlock(vue.unref(ui.Btn), {
8238
8267
  key: 1,
8239
8268
  outline: true,
8240
- onClick: cancel
8269
+ onClick: clear
8241
8270
  }, {
8242
8271
  default: vue.withCtx(() => [..._cache[4] || (_cache[4] = [
8243
- vue.createTextVNode(" Cancel ", -1)
8272
+ vue.createTextVNode(" Clear ", -1)
8244
8273
  ])]),
8245
8274
  _: 1
8246
- })) : vue.createCommentVNode("", true),
8275
+ })),
8247
8276
  vue.createVNode(vue.unref(ui.Btn), {
8248
8277
  color: vue.unref(ui.Color).primary,
8249
8278
  disabled: submitted.value,
package/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useApi, Debugger } from "@ghentcdh/tools-vue";
2
2
  import { NotificationService, Autocomplete, Checkbox, InputNumber, Markdown, MultiSelect, SelectComponent, Input, Textarea, Btn, IconEnum, Collapse, BtnBadge, TextCell, Table, hasCustomEventListener, Card, ModalService, myStyles, Alert, Color, Modal } from "@ghentcdh/ui";
3
3
  import { uiTypeIs, rankWith, isNumberControl, isIntegerControl, createDefaultValue, composePaths } from "@jsonforms/core";
4
- import { inject, provide, ref, computed, defineComponent, openBlock, createBlock, unref, mergeProps, createElementBlock, createElementVNode, normalizeClass, Fragment, renderList, createVNode, createCommentVNode, withCtx, createTextVNode, normalizeStyle, watch, toDisplayString, withModifiers, useModel, renderSlot, mergeModels } from "vue";
4
+ import { inject, provide, ref, computed, defineComponent, openBlock, createBlock, unref, mergeProps, createElementBlock, createElementVNode, normalizeClass, Fragment, renderList, createVNode, createCommentVNode, withCtx, createTextVNode, normalizeStyle, watch, toDisplayString, withModifiers, toRaw, renderSlot, useModel, mergeModels } from "vue";
5
5
  import { useJsonFormsControl, rendererProps, useJsonFormsArrayControl, DispatchRenderer, useJsonFormsLayout, JsonForms } from "@jsonforms/vue";
6
6
  import axios from "axios";
7
7
  import { useVanillaControl, useVanillaArrayControl, vanillaRenderers } from "@jsonforms/vue-vanilla";
@@ -126,7 +126,9 @@ const FormWithTableEmits = [
126
126
  /** Emitted after a record is successfully deleted. Payload: the deleted record. */
127
127
  "delete",
128
128
  /** Forwarded form events dispatched by custom renderers inside the modal (e.g. "create"). Payload: `FormEventPayload`. */
129
- "events"
129
+ "events",
130
+ "custom:edit",
131
+ "custom:create"
130
132
  ];
131
133
  const createFormEvents = (dispatch) => ({
132
134
  dispatch
@@ -1012,13 +1014,26 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1012
1014
  store = new FormStore(uri ?? "");
1013
1015
  });
1014
1016
  const hasEdit = hasCustomEventListener("editData");
1017
+ const customEdit = hasCustomEventListener("custom:edit");
1018
+ const customCreate = hasCustomEventListener("custom:create");
1015
1019
  const edit = (data) => {
1020
+ if (customEdit) {
1021
+ emit("custom:edit", data);
1022
+ return;
1023
+ }
1016
1024
  if (hasEdit) {
1017
1025
  emit("editData", data);
1018
1026
  return;
1019
1027
  }
1020
1028
  openModal(data);
1021
1029
  };
1030
+ const create = () => {
1031
+ if (customCreate) {
1032
+ emit("custom:create");
1033
+ return;
1034
+ }
1035
+ openModal();
1036
+ };
1022
1037
  const deleteFn = (data) => {
1023
1038
  ModalService.showConfirm({
1024
1039
  title: "Delete record",
@@ -1061,7 +1076,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1061
1076
  createVNode(unref(Btn), {
1062
1077
  icon: unref(IconEnum).Plus,
1063
1078
  outline: true,
1064
- onClick: openModal
1079
+ onClick: create
1065
1080
  }, {
1066
1081
  default: withCtx(() => [..._cache[0] || (_cache[0] = [
1067
1082
  createTextVNode(" Add new record ", -1)
@@ -8141,22 +8156,34 @@ const _hoisted_1 = { class: "flex justify-end gap-2 p-2 mt-2 border-t border-gra
8141
8156
  const _hoisted_2 = { class: "flex justify-end gap-2" };
8142
8157
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
8143
8158
  __name: "form-with-actions.component",
8144
- props: /* @__PURE__ */ mergeModels(FormWithActionsProperties, {
8145
- "modelValue": {},
8146
- "modelModifiers": {}
8147
- }),
8148
- emits: /* @__PURE__ */ mergeModels(FormWithActionsEmits, ["update:modelValue"]),
8159
+ props: {
8160
+ ...FormWithActionsProperties,
8161
+ modelValue: { type: Object, default: () => ({}) }
8162
+ },
8163
+ emits: FormWithActionsEmits,
8149
8164
  setup(__props, { emit: __emit }) {
8150
8165
  const properties = __props;
8151
8166
  const emits = __emit;
8152
- const formData = useModel(__props, "modelValue");
8167
+ const formData = ref(properties.modelValue);
8168
+ const initialFormData = ref(structuredClone(toRaw(properties.modelValue)));
8169
+ const recordId = ref(properties.modelValue?.id ?? null);
8153
8170
  const valid = ref(false);
8154
8171
  const submitted = ref(false);
8172
+ watch(
8173
+ () => properties.modelValue,
8174
+ (newValue, oldValue) => {
8175
+ if (newValue === formData.value) return;
8176
+ recordId.value = newValue?.id ?? null;
8177
+ initialFormData.value = structuredClone(toRaw(newValue));
8178
+ formData.value = newValue;
8179
+ }
8180
+ );
8155
8181
  const store = computed(
8156
8182
  () => properties.uri ? new FormStore(properties.uri) : null
8157
8183
  );
8158
8184
  const updateValue = (data) => {
8159
8185
  formData.value = data;
8186
+ emits("update:modelValue", data);
8160
8187
  };
8161
8188
  const save = () => {
8162
8189
  submitted.value = true;
@@ -8164,7 +8191,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
8164
8191
  return;
8165
8192
  }
8166
8193
  if (store.value) {
8167
- store.value.save(formData.value.id, formData.value).then(() => {
8194
+ store.value.save(recordId.value, formData.value).then(() => {
8168
8195
  emits("success");
8169
8196
  });
8170
8197
  } else {
@@ -8174,9 +8201,12 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
8174
8201
  const clear = () => {
8175
8202
  formData.value = { id: null };
8176
8203
  submitted.value = false;
8204
+ emits("update:modelValue", formData.value);
8177
8205
  };
8178
8206
  const cancel = () => {
8207
+ formData.value = structuredClone(toRaw(initialFormData.value));
8179
8208
  submitted.value = false;
8209
+ emits("update:modelValue", formData.value);
8180
8210
  emits("cancel");
8181
8211
  };
8182
8212
  const onValid = (v) => {
@@ -8186,7 +8216,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
8186
8216
  };
8187
8217
  const title = computed(() => {
8188
8218
  if (!properties.updateTitle) return properties.createTitle;
8189
- return formData.value?.id ? properties.updateTitle : properties.createTitle;
8219
+ return recordId.value ? properties.updateTitle : properties.createTitle;
8190
8220
  });
8191
8221
  return (_ctx, _cache) => {
8192
8222
  return openBlock(), createBlock(unref(Collapse), {
@@ -8222,26 +8252,25 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
8222
8252
  ]),
8223
8253
  createElementVNode("div", _hoisted_2, [
8224
8254
  renderSlot(_ctx.$slots, "actions"),
8225
- !formData.value.id ? (openBlock(), createBlock(unref(Btn), {
8255
+ recordId.value ? (openBlock(), createBlock(unref(Btn), {
8226
8256
  key: 0,
8227
8257
  outline: true,
8228
- onClick: clear
8258
+ onClick: cancel
8229
8259
  }, {
8230
8260
  default: withCtx(() => [..._cache[3] || (_cache[3] = [
8231
- createTextVNode(" Clear ", -1)
8261
+ createTextVNode(" Cancel ", -1)
8232
8262
  ])]),
8233
8263
  _: 1
8234
- })) : createCommentVNode("", true),
8235
- formData.value.id ? (openBlock(), createBlock(unref(Btn), {
8264
+ })) : (openBlock(), createBlock(unref(Btn), {
8236
8265
  key: 1,
8237
8266
  outline: true,
8238
- onClick: cancel
8267
+ onClick: clear
8239
8268
  }, {
8240
8269
  default: withCtx(() => [..._cache[4] || (_cache[4] = [
8241
- createTextVNode(" Cancel ", -1)
8270
+ createTextVNode(" Clear ", -1)
8242
8271
  ])]),
8243
8272
  _: 1
8244
- })) : createCommentVNode("", true),
8273
+ })),
8245
8274
  createVNode(unref(Btn), {
8246
8275
  color: unref(Color).primary,
8247
8276
  disabled: submitted.value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghentcdh/json-forms-vue",
3
- "version": "0.7.0",
3
+ "version": "0.8.2",
4
4
  "main": "./index.js",
5
5
  "module": "./index.mjs",
6
6
  "types": "./index.d.ts",