jsonforms-nuxt-ui-renderers 0.2.2 → 0.2.4

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.
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ import { DispatchRenderer, rendererProps, useJsonFormsArrayControl } from "@json
29
29
  import { computed as computed2, defineComponent, h as h2, resolveComponent } from "vue";
30
30
 
31
31
  // src/renderers/util.ts
32
+ import { hasEnableRule } from "@jsonforms/core";
32
33
  import { h } from "vue";
33
34
  import { computed } from "vue";
34
35
  function getDocsPathFromSchema(schema) {
@@ -69,6 +70,37 @@ function controlDescription(control) {
69
70
  const sd = control.schema?.description;
70
71
  return typeof sd === "string" && sd.trim() ? sd.trim() : void 0;
71
72
  }
73
+ function isSchemaReadOnly(schema) {
74
+ if (!schema || typeof schema !== "object" || Array.isArray(schema)) return false;
75
+ return schema.readOnly === true;
76
+ }
77
+ function controlTextInputAttrs(control, jsonforms) {
78
+ const schemaRO = isSchemaReadOnly(control.schema);
79
+ if (!schemaRO) {
80
+ return { readonly: false, disabled: !control.enabled };
81
+ }
82
+ if (jsonforms?.readonly === true) {
83
+ return { readonly: false, disabled: !control.enabled };
84
+ }
85
+ const ui = control.uischema;
86
+ if (typeof ui?.options?.readonly === "boolean" && ui.options.readonly) {
87
+ return { readonly: false, disabled: !control.enabled };
88
+ }
89
+ if (typeof ui?.options?.readOnly === "boolean" && ui.options.readOnly) {
90
+ return { readonly: false, disabled: !control.enabled };
91
+ }
92
+ const cfg = control.config;
93
+ if (typeof cfg?.readonly === "boolean" && cfg.readonly) {
94
+ return { readonly: false, disabled: !control.enabled };
95
+ }
96
+ if (typeof cfg?.readOnly === "boolean" && cfg.readOnly) {
97
+ return { readonly: false, disabled: !control.enabled };
98
+ }
99
+ if (ui && hasEnableRule(ui) && !control.enabled) {
100
+ return { readonly: false, disabled: true };
101
+ }
102
+ return { readonly: true, disabled: false };
103
+ }
72
104
 
73
105
  // src/renderers/complex/NuxtUiArrayListRenderer.ts
74
106
  function createNuxtUiArrayListRenderer(theme) {
@@ -444,7 +476,7 @@ var NuxtUiEnumControl = defineComponent4({
444
476
 
445
477
  // src/renderers/controls/NuxtUiIntegerControl.ts
446
478
  import { rendererProps as rendererProps5, useJsonFormsControl as useJsonFormsControl3 } from "@jsonforms/vue";
447
- import { computed as computed6, defineComponent as defineComponent5, h as h6, resolveComponent as resolveComponent4 } from "vue";
479
+ import { computed as computed6, defineComponent as defineComponent5, h as h6, inject, resolveComponent as resolveComponent4 } from "vue";
448
480
  var NuxtUiIntegerControl = defineComponent5({
449
481
  name: "NuxtUiIntegerControl",
450
482
  props: rendererProps5(),
@@ -452,13 +484,14 @@ var NuxtUiIntegerControl = defineComponent5({
452
484
  const { control, handleChange } = useJsonFormsControl3(
453
485
  props
454
486
  );
487
+ const jsonforms = inject("jsonforms");
455
488
  const errorMessage = computed6(() => trimmedOrUndefined(control.value.errors));
456
489
  const modelValue = computed6(() => {
457
490
  const v = control.value.data;
458
491
  return v === null || v === void 0 ? "" : String(v);
459
492
  });
460
- function onUpdate(raw) {
461
- const trimmed = String(raw ?? "").trim();
493
+ function applyRawString(raw) {
494
+ const trimmed = raw.trim();
462
495
  if (trimmed === "") {
463
496
  handleChange(control.value.path, void 0);
464
497
  return;
@@ -469,7 +502,7 @@ var NuxtUiIntegerControl = defineComponent5({
469
502
  return () => {
470
503
  if (!control.value.visible) return null;
471
504
  const UFormField = resolveComponent4("UFormField");
472
- const UInput = resolveComponent4("UInput");
505
+ const { readonly, disabled } = controlTextInputAttrs(control.value, jsonforms);
473
506
  return h6(
474
507
  "div",
475
508
  {},
@@ -482,15 +515,21 @@ var NuxtUiIntegerControl = defineComponent5({
482
515
  error: errorMessage.value
483
516
  },
484
517
  {
485
- default: () => h6(UInput, {
518
+ default: () => h6("input", {
486
519
  type: "number",
487
520
  inputmode: "numeric",
488
521
  step: "1",
489
- modelValue: modelValue.value,
490
- disabled: !control.value.enabled,
491
- color: errorMessage.value ? "error" : void 0,
522
+ class: [
523
+ "jf-input-native",
524
+ errorMessage.value ? "jf-input-native--error" : ""
525
+ ].filter(Boolean).join(" "),
526
+ value: modelValue.value,
527
+ readonly,
528
+ disabled,
492
529
  "aria-invalid": Boolean(errorMessage.value),
493
- "onUpdate:modelValue": onUpdate
530
+ onInput: (e) => {
531
+ applyRawString(e.target.value);
532
+ }
494
533
  })
495
534
  }
496
535
  )
@@ -581,7 +620,7 @@ var NuxtUiMultiEnumControl = defineComponent6({
581
620
 
582
621
  // src/renderers/controls/NuxtUiNumberControl.ts
583
622
  import { rendererProps as rendererProps7, useJsonFormsControl as useJsonFormsControl5 } from "@jsonforms/vue";
584
- import { computed as computed8, defineComponent as defineComponent7, h as h8, resolveComponent as resolveComponent6 } from "vue";
623
+ import { computed as computed8, defineComponent as defineComponent7, h as h8, inject as inject2, resolveComponent as resolveComponent6 } from "vue";
585
624
  var NuxtUiNumberControl = defineComponent7({
586
625
  name: "NuxtUiNumberControl",
587
626
  props: rendererProps7(),
@@ -589,13 +628,14 @@ var NuxtUiNumberControl = defineComponent7({
589
628
  const { control, handleChange } = useJsonFormsControl5(
590
629
  props
591
630
  );
631
+ const jsonforms = inject2("jsonforms");
592
632
  const errorMessage = computed8(() => trimmedOrUndefined(control.value.errors));
593
633
  const modelValue = computed8(() => {
594
634
  const v = control.value.data;
595
635
  return v === null || v === void 0 ? "" : String(v);
596
636
  });
597
- function onUpdate(raw) {
598
- const trimmed = String(raw ?? "").trim();
637
+ function applyRawString(raw) {
638
+ const trimmed = raw.trim();
599
639
  if (trimmed === "") {
600
640
  handleChange(control.value.path, void 0);
601
641
  return;
@@ -606,7 +646,7 @@ var NuxtUiNumberControl = defineComponent7({
606
646
  return () => {
607
647
  if (!control.value.visible) return null;
608
648
  const UFormField = resolveComponent6("UFormField");
609
- const UInput = resolveComponent6("UInput");
649
+ const { readonly, disabled } = controlTextInputAttrs(control.value, jsonforms);
610
650
  return h8(
611
651
  "div",
612
652
  {},
@@ -619,14 +659,20 @@ var NuxtUiNumberControl = defineComponent7({
619
659
  error: errorMessage.value
620
660
  },
621
661
  {
622
- default: () => h8(UInput, {
662
+ default: () => h8("input", {
623
663
  type: "number",
624
664
  inputmode: "decimal",
625
- modelValue: modelValue.value,
626
- disabled: !control.value.enabled,
627
- color: errorMessage.value ? "error" : void 0,
665
+ class: [
666
+ "jf-input-native",
667
+ errorMessage.value ? "jf-input-native--error" : ""
668
+ ].filter(Boolean).join(" "),
669
+ value: modelValue.value,
670
+ readonly,
671
+ disabled,
628
672
  "aria-invalid": Boolean(errorMessage.value),
629
- "onUpdate:modelValue": onUpdate
673
+ onInput: (e) => {
674
+ applyRawString(e.target.value);
675
+ }
630
676
  })
631
677
  }
632
678
  )
@@ -637,7 +683,7 @@ var NuxtUiNumberControl = defineComponent7({
637
683
 
638
684
  // src/renderers/controls/NuxtUiPasswordControl.ts
639
685
  import { rendererProps as rendererProps8, useJsonFormsControl as useJsonFormsControl6 } from "@jsonforms/vue";
640
- import { computed as computed9, defineComponent as defineComponent8, h as h9, ref, resolveComponent as resolveComponent7 } from "vue";
686
+ import { computed as computed9, defineComponent as defineComponent8, h as h9, inject as inject3, ref, resolveComponent as resolveComponent7 } from "vue";
641
687
  var NuxtUiPasswordControl = defineComponent8({
642
688
  name: "NuxtUiPasswordControl",
643
689
  props: rendererProps8(),
@@ -645,6 +691,7 @@ var NuxtUiPasswordControl = defineComponent8({
645
691
  const { control, handleChange } = useJsonFormsControl6(
646
692
  props
647
693
  );
694
+ const jsonforms = inject3("jsonforms");
648
695
  const errorMessage = computed9(() => trimmedOrUndefined(control.value.errors));
649
696
  const showPassword = ref(false);
650
697
  const inputType = computed9(() => showPassword.value ? "text" : "password");
@@ -653,6 +700,7 @@ var NuxtUiPasswordControl = defineComponent8({
653
700
  const UFormField = resolveComponent7("UFormField");
654
701
  const UInput = resolveComponent7("UInput");
655
702
  const UButton = resolveComponent7("UButton");
703
+ const { readonly, disabled } = controlTextInputAttrs(control.value, jsonforms);
656
704
  return h9(
657
705
  "div",
658
706
  {},
@@ -672,7 +720,8 @@ var NuxtUiPasswordControl = defineComponent8({
672
720
  class: "w-full",
673
721
  type: inputType.value,
674
722
  autocomplete: "current-password",
675
- disabled: !control.value.enabled,
723
+ readonly,
724
+ disabled,
676
725
  color: errorMessage.value ? "error" : void 0,
677
726
  "aria-invalid": Boolean(errorMessage.value),
678
727
  "onUpdate:modelValue": (v) => handleChange(control.value.path, v)
@@ -686,7 +735,7 @@ var NuxtUiPasswordControl = defineComponent8({
686
735
  icon: showPassword.value ? "i-heroicons-eye-slash" : "i-heroicons-eye",
687
736
  "aria-pressed": showPassword.value,
688
737
  "aria-label": showPassword.value ? "Hide password" : "Show password",
689
- disabled: !control.value.enabled,
738
+ disabled,
690
739
  onClick: () => {
691
740
  showPassword.value = !showPassword.value;
692
741
  }
@@ -706,6 +755,7 @@ import {
706
755
  computed as computed10,
707
756
  defineComponent as defineComponent9,
708
757
  h as h10,
758
+ inject as inject4,
709
759
  resolveComponent as resolveComponent8
710
760
  } from "vue";
711
761
  function createNuxtUiStringControl(docsUrl) {
@@ -716,6 +766,7 @@ function createNuxtUiStringControl(docsUrl) {
716
766
  const { control, handleChange } = useJsonFormsControl7(
717
767
  props
718
768
  );
769
+ const jsonforms = inject4("jsonforms");
719
770
  const errorMessage = computed10(
720
771
  () => trimmedOrUndefined(control.value.errors)
721
772
  );
@@ -723,11 +774,16 @@ function createNuxtUiStringControl(docsUrl) {
723
774
  if (!control.value.visible) return null;
724
775
  const UFormField = resolveComponent8("UFormField");
725
776
  const UInput = resolveComponent8("UInput");
777
+ const { readonly, disabled } = controlTextInputAttrs(
778
+ control.value,
779
+ jsonforms
780
+ );
726
781
  const slots = {
727
782
  default: () => h10(UInput, {
728
783
  modelValue: control.value.data ?? "",
729
784
  class: "w-full",
730
- disabled: !control.value.enabled,
785
+ readonly,
786
+ disabled,
731
787
  color: errorMessage.value ? "error" : void 0,
732
788
  "aria-invalid": Boolean(errorMessage.value),
733
789
  "onUpdate:modelValue": (v) => handleChange(control.value.path, v)
@@ -757,7 +813,7 @@ function createNuxtUiStringControl(docsUrl) {
757
813
 
758
814
  // src/renderers/controls/NuxtUiTextareaControl.ts
759
815
  import { rendererProps as rendererProps10, useJsonFormsControl as useJsonFormsControl8 } from "@jsonforms/vue";
760
- import { computed as computed11, defineComponent as defineComponent10, h as h11, resolveComponent as resolveComponent9 } from "vue";
816
+ import { computed as computed11, defineComponent as defineComponent10, h as h11, inject as inject5, resolveComponent as resolveComponent9 } from "vue";
761
817
  var NuxtUiTextareaControl = defineComponent10({
762
818
  name: "NuxtUiTextareaControl",
763
819
  props: rendererProps10(),
@@ -765,11 +821,13 @@ var NuxtUiTextareaControl = defineComponent10({
765
821
  const { control, handleChange } = useJsonFormsControl8(
766
822
  props
767
823
  );
824
+ const jsonforms = inject5("jsonforms");
768
825
  const errorMessage = computed11(() => trimmedOrUndefined(control.value.errors));
769
826
  return () => {
770
827
  if (!control.value.visible) return null;
771
828
  const UFormField = resolveComponent9("UFormField");
772
829
  const UTextarea = resolveComponent9("UTextarea");
830
+ const { readonly, disabled } = controlTextInputAttrs(control.value, jsonforms);
773
831
  return h11(
774
832
  "div",
775
833
  {},
@@ -785,7 +843,8 @@ var NuxtUiTextareaControl = defineComponent10({
785
843
  default: () => h11(UTextarea, {
786
844
  modelValue: control.value.data ?? "",
787
845
  class: "w-full",
788
- disabled: !control.value.enabled,
846
+ readonly,
847
+ disabled,
789
848
  color: errorMessage.value ? "error" : void 0,
790
849
  "aria-invalid": Boolean(errorMessage.value),
791
850
  rows: 5,