@narrative.io/jsonforms-provider-protocols 3.0.0-beta.2 → 3.0.0-beta.21

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.
Files changed (124) hide show
  1. package/dist/core/initFormData.d.ts +17 -0
  2. package/dist/core/initFormData.d.ts.map +1 -0
  3. package/dist/core/initFormData.js +99 -0
  4. package/dist/core/initFormData.js.map +1 -0
  5. package/dist/core/projection.d.ts +4 -0
  6. package/dist/core/projection.d.ts.map +1 -1
  7. package/dist/core/projection.js +17 -14
  8. package/dist/core/projection.js.map +1 -1
  9. package/dist/core/refs.d.ts +58 -0
  10. package/dist/core/refs.d.ts.map +1 -0
  11. package/dist/core/refs.js +70 -0
  12. package/dist/core/refs.js.map +1 -0
  13. package/dist/core/resolveScope.d.ts +6 -0
  14. package/dist/core/resolveScope.d.ts.map +1 -1
  15. package/dist/core/resolveScope.js +14 -8
  16. package/dist/core/resolveScope.js.map +1 -1
  17. package/dist/core/transforms.d.ts.map +1 -1
  18. package/dist/core/transforms.js +3 -1
  19. package/dist/core/transforms.js.map +1 -1
  20. package/dist/core/types.d.ts +1 -0
  21. package/dist/core/types.d.ts.map +1 -1
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/jsonforms-provider-protocols.css +2 -2
  27. package/dist/no-eval-ajv.d.ts +70 -0
  28. package/dist/no-eval-ajv.d.ts.map +1 -0
  29. package/dist/no-eval-ajv.js +247 -0
  30. package/dist/no-eval-ajv.js.map +1 -0
  31. package/dist/vue/components/ProviderAutocomplete.vue.d.ts.map +1 -1
  32. package/dist/vue/components/ProviderAutocomplete.vue.js +10 -6
  33. package/dist/vue/components/ProviderAutocomplete.vue.js.map +1 -1
  34. package/dist/vue/components/ProviderMultiSelect.vue.d.ts.map +1 -1
  35. package/dist/vue/components/ProviderMultiSelect.vue.js +1 -1
  36. package/dist/vue/components/ProviderMultiSelect.vue2.js +17 -9
  37. package/dist/vue/components/ProviderMultiSelect.vue2.js.map +1 -1
  38. package/dist/vue/components/ProviderSelect.vue.d.ts.map +1 -1
  39. package/dist/vue/components/ProviderSelect.vue.js +1 -1
  40. package/dist/vue/components/ProviderSelect.vue2.js +19 -9
  41. package/dist/vue/components/ProviderSelect.vue2.js.map +1 -1
  42. package/dist/vue/composables/useDataLayer.d.ts +1 -0
  43. package/dist/vue/composables/useDataLayer.d.ts.map +1 -1
  44. package/dist/vue/composables/useDataLayer.js +1 -0
  45. package/dist/vue/composables/useDataLayer.js.map +1 -1
  46. package/dist/vue/composables/useDerive.d.ts +1 -1
  47. package/dist/vue/composables/useDerive.d.ts.map +1 -1
  48. package/dist/vue/composables/useDerive.js +19 -2
  49. package/dist/vue/composables/useDerive.js.map +1 -1
  50. package/dist/vue/composables/useDeriveInitialValue.d.ts +36 -0
  51. package/dist/vue/composables/useDeriveInitialValue.d.ts.map +1 -0
  52. package/dist/vue/composables/useDeriveInitialValue.js +125 -0
  53. package/dist/vue/composables/useDeriveInitialValue.js.map +1 -0
  54. package/dist/vue/composables/useDirtyValidation.d.ts +3 -3
  55. package/dist/vue/composables/useDirtyValidation.d.ts.map +1 -1
  56. package/dist/vue/composables/useDirtyValidation.js +2 -2
  57. package/dist/vue/composables/useDirtyValidation.js.map +1 -1
  58. package/dist/vue/composables/useProjection.d.ts +7 -0
  59. package/dist/vue/composables/useProjection.d.ts.map +1 -1
  60. package/dist/vue/composables/useProjection.js +87 -4
  61. package/dist/vue/composables/useProjection.js.map +1 -1
  62. package/dist/vue/composables/useProvider.d.ts +2 -2
  63. package/dist/vue/composables/useProvider.d.ts.map +1 -1
  64. package/dist/vue/composables/useProvider.js +14 -10
  65. package/dist/vue/composables/useProvider.js.map +1 -1
  66. package/dist/vue/index.d.ts +2 -0
  67. package/dist/vue/index.d.ts.map +1 -1
  68. package/dist/vue/index.js +30 -10
  69. package/dist/vue/index.js.map +1 -1
  70. package/dist/vue/primevue/JfBoolean.vue.d.ts.map +1 -1
  71. package/dist/vue/primevue/JfBoolean.vue.js +17 -6
  72. package/dist/vue/primevue/JfBoolean.vue.js.map +1 -1
  73. package/dist/vue/primevue/JfEnum.vue.d.ts.map +1 -1
  74. package/dist/vue/primevue/JfEnum.vue.js +22 -10
  75. package/dist/vue/primevue/JfEnum.vue.js.map +1 -1
  76. package/dist/vue/primevue/JfEnumArray.vue.d.ts.map +1 -1
  77. package/dist/vue/primevue/JfEnumArray.vue.js +20 -10
  78. package/dist/vue/primevue/JfEnumArray.vue.js.map +1 -1
  79. package/dist/vue/primevue/JfNumber.vue.d.ts.map +1 -1
  80. package/dist/vue/primevue/JfNumber.vue.js +18 -10
  81. package/dist/vue/primevue/JfNumber.vue.js.map +1 -1
  82. package/dist/vue/primevue/JfText.vue.d.ts.map +1 -1
  83. package/dist/vue/primevue/JfText.vue.js +27 -12
  84. package/dist/vue/primevue/JfText.vue.js.map +1 -1
  85. package/dist/vue/primevue/JfTextArea.vue.d.ts.map +1 -1
  86. package/dist/vue/primevue/JfTextArea.vue.js +15 -9
  87. package/dist/vue/primevue/JfTextArea.vue.js.map +1 -1
  88. package/dist/vue/primevue/index.d.ts.map +1 -1
  89. package/dist/vue/primevue/index.js +93 -16
  90. package/dist/vue/primevue/index.js.map +1 -1
  91. package/dist/vue/utils/autoSelect.js.map +1 -1
  92. package/dist/vue/utils/placeholder.d.ts +17 -0
  93. package/dist/vue/utils/placeholder.d.ts.map +1 -0
  94. package/dist/vue/utils/placeholder.js +17 -0
  95. package/dist/vue/utils/placeholder.js.map +1 -0
  96. package/package.json +10 -2
  97. package/src/core/initFormData.ts +208 -0
  98. package/src/core/projection.ts +33 -22
  99. package/src/core/refs.ts +166 -0
  100. package/src/core/resolveScope.ts +23 -8
  101. package/src/core/transforms.ts +33 -6
  102. package/src/core/types.ts +1 -0
  103. package/src/index.ts +14 -2
  104. package/src/no-eval-ajv.ts +381 -0
  105. package/src/vue/components/ProviderAutocomplete.vue +9 -7
  106. package/src/vue/components/ProviderMultiSelect.vue +20 -15
  107. package/src/vue/components/ProviderSelect.vue +21 -14
  108. package/src/vue/composables/useDataLayer.ts +1 -1
  109. package/src/vue/composables/useDerive.ts +46 -3
  110. package/src/vue/composables/useDeriveInitialValue.ts +195 -0
  111. package/src/vue/composables/useDirtyValidation.ts +8 -3
  112. package/src/vue/composables/useProjection.ts +172 -1
  113. package/src/vue/composables/useProvider.ts +28 -11
  114. package/src/vue/index.ts +28 -9
  115. package/src/vue/primevue/JfBoolean.vue +10 -5
  116. package/src/vue/primevue/JfEnum.vue +23 -14
  117. package/src/vue/primevue/JfEnumArray.vue +22 -17
  118. package/src/vue/primevue/JfNumber.vue +20 -12
  119. package/src/vue/primevue/JfText.vue +31 -16
  120. package/src/vue/primevue/JfTextArea.vue +15 -13
  121. package/src/vue/primevue/index.ts +104 -23
  122. package/src/vue/styles.css +26 -1
  123. package/src/vue/utils/autoSelect.ts +2 -2
  124. package/src/vue/utils/placeholder.ts +42 -0
@@ -19,13 +19,38 @@ const injectLayoutStyles = () => {
19
19
  display: flex;
20
20
  flex-direction: column;
21
21
  align-items: flex-start;
22
- gap: 1rem;
22
+ gap: 24px;
23
23
  width: 100%;
24
24
  }
25
25
 
26
26
  .vertical-layout-item {
27
27
  width: 100%;
28
28
  }
29
+
30
+ /* Form control wrapper */
31
+ .jf-control {
32
+ display: flex;
33
+ flex-direction: column;
34
+ gap: 12px;
35
+ }
36
+
37
+ /* Form control label typography */
38
+ .jf-label {
39
+ font-weight: 600;
40
+ font-size: 14px;
41
+ line-height: 14px;
42
+ color: #031553;
43
+ text-align: left;
44
+ }
45
+
46
+ /* Form control description typography */
47
+ .jf-description {
48
+ font-weight: 400;
49
+ font-size: 14px;
50
+ line-height: 14px;
51
+ color: #415290;
52
+ text-align: left;
53
+ }
29
54
  `;
30
55
  document.head.appendChild(style);
31
56
  }
@@ -102,47 +127,103 @@ export function registerPrimevueRenderers(jsonformsCore: any): unknown[] {
102
127
 
103
128
  // Projection-aware schema check: when options.projection is set,
104
129
  // resolve the projected schema and test against it instead of the original
105
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
- const projectedSchemaMatches = (check: (schema: any) => boolean) =>
107
- (uischema: unknown, schema: unknown): boolean => {
108
- const ui = uischema as { type?: string; scope?: string; options?: { projection?: string } };
109
- const projection = ui?.options?.projection;
110
- if (!projection || ui?.type !== "Control" || !ui?.scope) return false;
111
-
112
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
- const propertySchema = resolveScopeSchema(ui.scope, schema as Record<string, any>);
114
- if (!propertySchema) return false;
115
-
116
- return check(getProjectedSchema(propertySchema, projection));
117
- };
130
+
131
+ const projectedSchemaMatches =
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ (check: (schema: any) => boolean) =>
134
+ (uischema: unknown, schema: unknown): boolean => {
135
+ const ui = uischema as {
136
+ type?: string;
137
+ scope?: string;
138
+ options?: { projection?: string };
139
+ };
140
+ const projection = ui?.options?.projection;
141
+ if (!projection || ui?.type !== "Control" || !ui?.scope) return false;
142
+
143
+ const propertySchema = resolveScopeSchema(
144
+ ui.scope,
145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
+ schema as Record<string, any>,
147
+ );
148
+ if (!propertySchema) return false;
149
+
150
+ return check(getProjectedSchema(propertySchema, projection));
151
+ };
118
152
 
119
153
  const isMultilineProjection = (uischema: unknown, schema: unknown) => {
120
154
  const ui = uischema as { options?: { multi?: boolean } };
121
- return ui?.options?.multi === true &&
122
- projectedSchemaMatches((s) => s?.type === "string")(uischema, schema);
155
+ return (
156
+ ui?.options?.multi === true &&
157
+ projectedSchemaMatches((s) => s?.type === "string")(uischema, schema)
158
+ );
123
159
  };
124
160
 
125
161
  const renderers = [
126
162
  // Multiline text has higher priority than regular text
127
- { tester: rankWith(PRIME + 4, or(isMultilineString, isMultilineProjection)), renderer: JfTextArea },
128
- { tester: rankWith(PRIME + 3, or(isStringControl, projectedSchemaMatches((s) => s?.type === "string"))), renderer: JfText },
129
163
  {
130
- tester: rankWith(PRIME + 6, or(isIntegerControl, projectedSchemaMatches((s) => s?.type === "integer"))),
164
+ tester: rankWith(PRIME + 4, or(isMultilineString, isMultilineProjection)),
165
+ renderer: JfTextArea,
166
+ },
167
+ {
168
+ tester: rankWith(
169
+ PRIME + 3,
170
+ or(
171
+ isStringControl,
172
+ projectedSchemaMatches((s) => s?.type === "string"),
173
+ ),
174
+ ),
175
+ renderer: JfText,
176
+ },
177
+ {
178
+ tester: rankWith(
179
+ PRIME + 6,
180
+ or(
181
+ isIntegerControl,
182
+ projectedSchemaMatches((s) => s?.type === "integer"),
183
+ ),
184
+ ),
131
185
  renderer: JfNumber,
132
186
  },
133
187
  {
134
- tester: rankWith(PRIME + 4, or(isNumberControl, projectedSchemaMatches((s) => s?.type === "number"))),
188
+ tester: rankWith(
189
+ PRIME + 4,
190
+ or(
191
+ isNumberControl,
192
+ projectedSchemaMatches((s) => s?.type === "number"),
193
+ ),
194
+ ),
135
195
  renderer: JfNumber,
136
196
  },
137
197
  {
138
- tester: rankWith(PRIME + 7, or(and(isControl, schemaMatches(isScalarEnum)), and(isControl, projectedSchemaMatches(isScalarEnum)))),
198
+ tester: rankWith(
199
+ PRIME + 7,
200
+ or(
201
+ and(isControl, schemaMatches(isScalarEnum)),
202
+ and(isControl, projectedSchemaMatches(isScalarEnum)),
203
+ ),
204
+ ),
139
205
  renderer: JfEnum,
140
206
  },
141
207
  {
142
- tester: rankWith(PRIME + 8, or(and(isControl, schemaMatches(isEnumArray)), and(isControl, projectedSchemaMatches(isEnumArray)))),
208
+ tester: rankWith(
209
+ PRIME + 8,
210
+ or(
211
+ and(isControl, schemaMatches(isEnumArray)),
212
+ and(isControl, projectedSchemaMatches(isEnumArray)),
213
+ ),
214
+ ),
143
215
  renderer: JfEnumArray,
144
216
  },
145
- { tester: rankWith(PRIME + 3, or(isBooleanControl, projectedSchemaMatches((s) => s?.type === "boolean"))), renderer: JfBoolean },
217
+ {
218
+ tester: rankWith(
219
+ PRIME + 3,
220
+ or(
221
+ isBooleanControl,
222
+ projectedSchemaMatches((s) => s?.type === "boolean"),
223
+ ),
224
+ ),
225
+ renderer: JfBoolean,
226
+ },
146
227
  ];
147
228
 
148
229
  // Update the exported array
@@ -5,7 +5,7 @@
5
5
  display: flex;
6
6
  flex-direction: column;
7
7
  align-items: flex-start;
8
- gap: 1rem;
8
+ gap: 24px;
9
9
  width: 100%;
10
10
  }
11
11
 
@@ -14,6 +14,31 @@
14
14
  width: 100%;
15
15
  }
16
16
 
17
+ /* Form control wrapper */
18
+ .jf-control {
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: 12px;
22
+ }
23
+
24
+ /* Form control label typography */
25
+ .jf-label {
26
+ font-weight: 600;
27
+ font-size: 14px;
28
+ line-height: 14px;
29
+ color: #031553;
30
+ text-align: left;
31
+ }
32
+
33
+ /* Form control description typography */
34
+ .jf-description {
35
+ font-weight: 400;
36
+ font-size: 14px;
37
+ line-height: 14px;
38
+ color: #415290;
39
+ text-align: left;
40
+ }
41
+
17
42
  /* PrimeVue dropdown text alignment fix */
18
43
  .p-dropdown-label {
19
44
  text-align: left !important;
@@ -57,7 +57,7 @@ export interface AutoSelectMultiParams {
57
57
  * - Current value is empty array OR current selection is not in the current options
58
58
  */
59
59
  export function shouldAutoSelectMulti(
60
- params: AutoSelectMultiParams
60
+ params: AutoSelectMultiParams,
61
61
  ): unknown[] | null {
62
62
  const { autoSelectSingle, isLoading, items, currentValue } = params;
63
63
 
@@ -73,7 +73,7 @@ export function shouldAutoSelectMulti(
73
73
  const currentArray = Array.isArray(currentValue) ? currentValue : [];
74
74
  const isValueEmpty = currentArray.length === 0;
75
75
  const hasValidSelection = currentArray.some((val) =>
76
- items.some((item) => item.value === val)
76
+ items.some((item) => item.value === val),
77
77
  );
78
78
 
79
79
  if (isValueEmpty || !hasValidSelection) {
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Placeholder resolution for form controls.
3
+ *
4
+ * Precedence:
5
+ * 1. `uischema.options.placeholder` (explicit author intent — always wins)
6
+ * 2. `Select ${label}` or `Enter ${label}` when a label is resolvable
7
+ * 3. Kind-appropriate bare fallback
8
+ *
9
+ * Never falls back to `schema.description` — descriptions are rendered as
10
+ * prose above the field by our renderers, so re-using them as placeholder
11
+ * produces a duplicated, truncated string inside the input.
12
+ */
13
+
14
+ export type PlaceholderKind = "select" | "input";
15
+
16
+ /**
17
+ * Strip a trailing required-indicator asterisk (" *" or "*") that `resolveLabel`
18
+ * appends for required fields, so composed placeholders read naturally.
19
+ */
20
+ function stripRequiredMarker(label: string): string {
21
+ return label.replace(/\s*\*\s*$/, "").trim();
22
+ }
23
+
24
+ export function resolvePlaceholder(
25
+ uischema: { options?: unknown } | undefined,
26
+ resolvedLabel: string | undefined,
27
+ kind: PlaceholderKind,
28
+ ): string | undefined {
29
+ const options = uischema?.options;
30
+ const explicit =
31
+ options && typeof options === "object"
32
+ ? (options as Record<string, unknown>).placeholder
33
+ : undefined;
34
+ if (typeof explicit === "string" && explicit.length > 0) return explicit;
35
+
36
+ const label = resolvedLabel ? stripRequiredMarker(resolvedLabel) : "";
37
+ if (label) {
38
+ return kind === "select" ? `Select ${label}` : `Enter ${label}`;
39
+ }
40
+
41
+ return kind === "select" ? "Select…" : undefined;
42
+ }