VConfirmEdit.mjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { createVNode as _createVNode, mergeProps as _mergeProps, Fragment as _Fragment } from "vue";
  2. // Components
  3. import { VBtn } from "../VBtn/index.mjs"; // Composables
  4. import { useLocale } from "../../composables/index.mjs";
  5. import { useProxiedModel } from "../../composables/proxiedModel.mjs"; // Utilities
  6. import { computed, ref, toRaw, watchEffect } from 'vue';
  7. import { deepEqual, genericComponent, propsFactory, useRender } from "../../util/index.mjs"; // Types
  8. export const makeVConfirmEditProps = propsFactory({
  9. modelValue: null,
  10. color: String,
  11. cancelText: {
  12. type: String,
  13. default: '$vuetify.confirmEdit.cancel'
  14. },
  15. okText: {
  16. type: String,
  17. default: '$vuetify.confirmEdit.ok'
  18. }
  19. }, 'VConfirmEdit');
  20. export const VConfirmEdit = genericComponent()({
  21. name: 'VConfirmEdit',
  22. props: makeVConfirmEditProps(),
  23. emits: {
  24. cancel: () => true,
  25. save: value => true,
  26. 'update:modelValue': value => true
  27. },
  28. setup(props, _ref) {
  29. let {
  30. emit,
  31. slots
  32. } = _ref;
  33. const model = useProxiedModel(props, 'modelValue');
  34. const internalModel = ref();
  35. watchEffect(() => {
  36. internalModel.value = structuredClone(toRaw(model.value));
  37. });
  38. const {
  39. t
  40. } = useLocale();
  41. const isPristine = computed(() => {
  42. return deepEqual(model.value, internalModel.value);
  43. });
  44. function save() {
  45. model.value = internalModel.value;
  46. emit('save', internalModel.value);
  47. }
  48. function cancel() {
  49. internalModel.value = structuredClone(toRaw(model.value));
  50. emit('cancel');
  51. }
  52. function actions(actionsProps) {
  53. return _createVNode(_Fragment, null, [_createVNode(VBtn, _mergeProps({
  54. "disabled": isPristine.value,
  55. "variant": "text",
  56. "color": props.color,
  57. "onClick": cancel,
  58. "text": t(props.cancelText)
  59. }, actionsProps), null), _createVNode(VBtn, _mergeProps({
  60. "disabled": isPristine.value,
  61. "variant": "text",
  62. "color": props.color,
  63. "onClick": save,
  64. "text": t(props.okText)
  65. }, actionsProps), null)]);
  66. }
  67. let actionsUsed = false;
  68. useRender(() => {
  69. return _createVNode(_Fragment, null, [slots.default?.({
  70. model: internalModel,
  71. save,
  72. cancel,
  73. isPristine: isPristine.value,
  74. get actions() {
  75. actionsUsed = true;
  76. return actions;
  77. }
  78. }), !actionsUsed && actions()]);
  79. });
  80. return {
  81. save,
  82. cancel,
  83. isPristine
  84. };
  85. }
  86. });
  87. //# sourceMappingURL=VConfirmEdit.mjs.map