@jsonschema-editor/vue-extensions 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JSON Schema Editor Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @jsonschema-editor/vue-extensions
2
+
3
+ Vue form field renderers for extended JSON Schema string formats (`email`, `uri`, `phone`).
4
+
5
+ Works with `@jsonschema-editor/json-schema-extensions` on the schema side and registers custom controls via `@jsonschema-editor/vue` extension API.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @jsonschema-editor/vue-extensions @jsonschema-editor/vue vue
11
+ ```
12
+
13
+ Peer dependencies: `@jsonschema-editor/vue`, `@jsonschema-editor/json-schema-extensions`, `vue@^3.5`.
14
+
15
+ ## Register at app startup
16
+
17
+ ```ts
18
+ import { registerDefaultVueExtensions } from "@jsonschema-editor/vue-extensions";
19
+
20
+ registerDefaultVueExtensions();
21
+ ```
22
+
23
+ Or pass extensions to `install()` / form components:
24
+
25
+ ```ts
26
+ import { install } from "@jsonschema-editor/vue";
27
+ import { formatFieldsExtension } from "@jsonschema-editor/vue-extensions";
28
+
29
+ install(app, { extensions: [formatFieldsExtension] });
30
+ ```
31
+
32
+ ```vue
33
+ <JsonSchemaFormEditor
34
+ :extensions="[formatFieldsExtension]"
35
+ ...
36
+ />
37
+ ```
38
+
39
+ ## Custom extensions
40
+
41
+ Use matchers from `@jsonschema-editor/vue`:
42
+
43
+ ```ts
44
+ import {
45
+ registerVueExtension,
46
+ matchStringFormat,
47
+ matchPropertyName,
48
+ type JseVueExtension,
49
+ } from "@jsonschema-editor/vue";
50
+
51
+ const myExtension: JseVueExtension = {
52
+ id: "my-app-fields",
53
+ formFields: [
54
+ {
55
+ id: "price-input",
56
+ priority: 30,
57
+ match: (schema, ctx) =>
58
+ schema.kind === "number" && ctx.propertyName === "price",
59
+ component: MyPriceInput,
60
+ },
61
+ ],
62
+ };
63
+
64
+ registerVueExtension(myExtension);
65
+ ```
66
+
67
+ ## License
68
+
69
+ MIT — see [LICENSE](../LICENSE) in the repository root.
@@ -0,0 +1,52 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { DefineComponent } from 'vue';
4
+ import { JseVueExtension } from '@jsonschema-editor/vue';
5
+ import { PublicProps } from 'vue';
6
+ import { SchemaNode } from '@jsonschema-editor/json-schema';
7
+
8
+ declare type __VLS_Props = {
9
+ schema: SchemaNode;
10
+ scope: string;
11
+ label?: string;
12
+ i18nKey?: string;
13
+ readonly?: boolean;
14
+ };
15
+
16
+ declare type __VLS_Props_2 = {
17
+ schema: SchemaNode;
18
+ scope: string;
19
+ label?: string;
20
+ i18nKey?: string;
21
+ readonly?: boolean;
22
+ };
23
+
24
+ declare type __VLS_PublicProps = {
25
+ modelValue: Record<string, unknown>;
26
+ } & __VLS_Props;
27
+
28
+ declare type __VLS_PublicProps_2 = {
29
+ modelValue: Record<string, unknown>;
30
+ } & __VLS_Props_2;
31
+
32
+ export declare const ExtendedFormatFormField: DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
33
+ "update:modelValue": (value: Record<string, unknown>) => any;
34
+ }, string, PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
35
+ "onUpdate:modelValue"?: ((value: Record<string, unknown>) => any) | undefined;
36
+ }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
37
+
38
+ /** Matches `email`, `uri` (URL), and custom `phone` string formats from json-schema-extensions. */
39
+ export declare const formatFieldsExtension: JseVueExtension;
40
+
41
+ export declare function registerDefaultVueExtensions(): void;
42
+
43
+ /** Example extension: select values from a static list or an external API endpoint. */
44
+ export declare const valuesSourceExtension: JseVueExtension;
45
+
46
+ export declare const ValuesSourceFormField: DefineComponent<__VLS_PublicProps_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
47
+ "update:modelValue": (value: Record<string, unknown>) => any;
48
+ }, string, PublicProps, Readonly<__VLS_PublicProps_2> & Readonly<{
49
+ "onUpdate:modelValue"?: ((value: Record<string, unknown>) => any) | undefined;
50
+ }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
51
+
52
+ export { }
@@ -0,0 +1,266 @@
1
+ import { useScopedField as $, useFormFieldLabel as D, JseSchemaFormField as I, JseInput as Y, matchStringFormat as k, JseSelect as Z, matchCustomAttribute as ee, registerVueExtension as K } from "@jsonschema-editor/vue";
2
+ import { StringSchema as _ } from "@jsonschema-editor/json-schema";
3
+ import { jsonSchemaFormatExtensions as te, createStringSchemaWithFormat as le, URL_FORMAT as ae, PHONE_FORMAT as oe, readValuesSourceConfig as J, isStaticValuesSource as N, isFetchValuesSource as P, createStaticValuesSourceSchema as re, createFetchValuesSourceSchema as se, VALUES_SOURCE_ATTRIBUTE as ne } from "@jsonschema-editor/json-schema-extensions";
4
+ import { defineComponent as q, toRef as v, useModel as H, computed as S, openBlock as d, createBlock as W, unref as n, withCtx as O, createVNode as z, createElementBlock as b, toDisplayString as B, createCommentVNode as C, mergeModels as G, ref as T, watch as ie, Fragment as ue, renderList as ce } from "vue";
5
+ const de = ["href"], L = /* @__PURE__ */ q({
6
+ __name: "ExtendedFormatFormField",
7
+ props: /* @__PURE__ */ G({
8
+ schema: {},
9
+ scope: {},
10
+ label: {},
11
+ i18nKey: {},
12
+ readonly: { type: Boolean }
13
+ }, {
14
+ modelValue: { required: !0 },
15
+ modelModifiers: {}
16
+ }),
17
+ emits: ["update:modelValue"],
18
+ setup(e) {
19
+ const l = e, i = v(l, "schema"), V = v(l, "label"), E = v(l, "i18nKey"), x = H(e, "modelValue"), { fieldSchema: j, value: m } = $(i, x, l.scope), { resolvedSchema: F, displayLabel: w, description: A } = D(
20
+ i,
21
+ l.scope,
22
+ V,
23
+ j,
24
+ E
25
+ ), r = S(() => {
26
+ const s = F.value;
27
+ return s instanceof _ ? s.format : void 0;
28
+ }), p = S(() => {
29
+ switch (r.value) {
30
+ case "email":
31
+ return "email";
32
+ case "uri":
33
+ return "url";
34
+ case "phone":
35
+ return "tel";
36
+ default:
37
+ return "text";
38
+ }
39
+ }), u = S(() => {
40
+ switch (r.value) {
41
+ case "email":
42
+ return "email";
43
+ case "uri":
44
+ return "url";
45
+ case "phone":
46
+ return "tel";
47
+ default:
48
+ return;
49
+ }
50
+ }), h = S(() => {
51
+ if (r.value !== "uri") return null;
52
+ const s = m.value;
53
+ if (typeof s != "string" || s.length === 0) return null;
54
+ try {
55
+ const c = new URL(s);
56
+ if (c.protocol === "http:" || c.protocol === "https:") return s;
57
+ } catch {
58
+ return null;
59
+ }
60
+ return null;
61
+ });
62
+ return (s, c) => (d(), W(n(I), {
63
+ label: n(w),
64
+ description: n(A),
65
+ scope: e.scope
66
+ }, {
67
+ default: O(() => [
68
+ z(n(Y), {
69
+ "model-value": n(m),
70
+ class: "jse-field__input jse-field__input--format",
71
+ type: p.value,
72
+ autocomplete: u.value,
73
+ disabled: e.readonly,
74
+ "onUpdate:modelValue": c[0] || (c[0] = (t) => m.value = t)
75
+ }, null, 8, ["model-value", "type", "autocomplete", "disabled"]),
76
+ h.value ? (d(), b("a", {
77
+ key: 0,
78
+ class: "jse-field__link",
79
+ href: h.value,
80
+ target: "_blank",
81
+ rel: "noopener noreferrer"
82
+ }, B(h.value), 9, de)) : C("", !0)
83
+ ]),
84
+ _: 1
85
+ }, 8, ["label", "description", "scope"]));
86
+ }
87
+ }), me = {
88
+ id: "jsonschema-editor-format-fields",
89
+ formFields: [
90
+ {
91
+ id: "vue-ext-email",
92
+ priority: 20,
93
+ match: k("email"),
94
+ component: L
95
+ },
96
+ {
97
+ id: "vue-ext-uri",
98
+ priority: 20,
99
+ match: k(ae),
100
+ component: L
101
+ },
102
+ {
103
+ id: "vue-ext-phone",
104
+ priority: 20,
105
+ match: k(oe),
106
+ component: L
107
+ }
108
+ ],
109
+ schemaTypes: te.map((e) => ({
110
+ id: e.id,
111
+ label: e.id,
112
+ create: () => le(e.id),
113
+ match: (l) => l instanceof _ && l.format === e.format
114
+ }))
115
+ }, pe = {
116
+ key: 0,
117
+ disabled: "",
118
+ value: ""
119
+ }, fe = ["value"], ve = {
120
+ key: 0,
121
+ class: "jse-field__hint jse-field__hint--error"
122
+ }, he = /* @__PURE__ */ q({
123
+ __name: "ValuesSourceFormField",
124
+ props: /* @__PURE__ */ G({
125
+ schema: {},
126
+ scope: {},
127
+ label: {},
128
+ i18nKey: {},
129
+ readonly: { type: Boolean }
130
+ }, {
131
+ modelValue: { required: !0 },
132
+ modelModifiers: {}
133
+ }),
134
+ emits: ["update:modelValue"],
135
+ setup(e) {
136
+ const l = e, i = v(l, "schema"), V = v(l, "label"), E = v(l, "i18nKey"), x = H(e, "modelValue"), { fieldSchema: j, value: m } = $(i, x, l.scope), { resolvedSchema: F, displayLabel: w, description: A } = D(
137
+ i,
138
+ l.scope,
139
+ V,
140
+ j,
141
+ E
142
+ ), r = T([]), p = T(!1), u = T(null), h = S(
143
+ () => F.value ? J(F.value) : void 0
144
+ );
145
+ function s(t, a) {
146
+ if (Array.isArray(t)) return t;
147
+ if (!a.itemsPath) return [];
148
+ const o = a.itemsPath.split(".").reduce((f, R) => {
149
+ if (f && typeof f == "object")
150
+ return f[R];
151
+ }, t);
152
+ return Array.isArray(o) ? o : [];
153
+ }
154
+ async function c(t) {
155
+ if (N(t)) {
156
+ r.value = t.values.map((a) => ({ value: a, label: a })), u.value = null;
157
+ return;
158
+ }
159
+ if (!P(t)) {
160
+ r.value = [];
161
+ return;
162
+ }
163
+ p.value = !0, u.value = null;
164
+ try {
165
+ const a = await fetch(t.url);
166
+ if (!a.ok)
167
+ throw new Error(`${a.status} ${a.statusText}`);
168
+ const o = await a.json(), f = s(o, t);
169
+ if (!Array.isArray(f))
170
+ throw new Error("Response does not contain an option list");
171
+ const R = t.valueField ?? "id", Q = t.labelField ?? "name";
172
+ r.value = f.map((y) => {
173
+ if (y && typeof y == "object") {
174
+ const U = y, g = U[R], X = U[Q] ?? g;
175
+ return {
176
+ value: String(g ?? ""),
177
+ label: String(X ?? g ?? "")
178
+ };
179
+ }
180
+ return { value: String(y), label: String(y) };
181
+ });
182
+ } catch (a) {
183
+ r.value = [], u.value = a instanceof Error ? a.message : "Failed to load options";
184
+ } finally {
185
+ p.value = !1;
186
+ }
187
+ }
188
+ return ie(
189
+ h,
190
+ (t) => {
191
+ if (!t) {
192
+ r.value = [], u.value = null;
193
+ return;
194
+ }
195
+ c(t);
196
+ },
197
+ { immediate: !0 }
198
+ ), (t, a) => (d(), W(n(I), {
199
+ label: n(w),
200
+ description: n(A),
201
+ scope: e.scope
202
+ }, {
203
+ default: O(() => [
204
+ z(n(Z), {
205
+ "model-value": n(m),
206
+ class: "jse-field__input",
207
+ disabled: e.readonly || p.value,
208
+ "onUpdate:modelValue": a[0] || (a[0] = (o) => m.value = o)
209
+ }, {
210
+ default: O(() => [
211
+ p.value ? (d(), b("option", pe, "…")) : C("", !0),
212
+ (d(!0), b(ue, null, ce(r.value, (o) => (d(), b("option", {
213
+ key: `${o.value}-${o.label}`,
214
+ value: o.value
215
+ }, B(o.label), 9, fe))), 128))
216
+ ]),
217
+ _: 1
218
+ }, 8, ["model-value", "disabled"]),
219
+ u.value ? (d(), b("p", ve, B(u.value), 1)) : C("", !0)
220
+ ]),
221
+ _: 1
222
+ }, 8, ["label", "description", "scope"]));
223
+ }
224
+ });
225
+ function M(e, l) {
226
+ const i = J(e);
227
+ return l === "static" ? N(i) : P(i);
228
+ }
229
+ const ye = {
230
+ id: "jsonschema-editor-values-source",
231
+ formFields: [
232
+ {
233
+ id: "vue-ext-values-source",
234
+ priority: 25,
235
+ match: ee(ne),
236
+ component: he
237
+ }
238
+ ],
239
+ schemaTypes: [
240
+ {
241
+ id: "select-list",
242
+ label: "select-list",
243
+ create: () => re(["Option A", "Option B", "Option C"]),
244
+ match: (e) => e instanceof _ && M(e, "static")
245
+ },
246
+ {
247
+ id: "select-api",
248
+ label: "select-api",
249
+ create: () => se("https://jsonplaceholder.typicode.com/users", {
250
+ valueField: "id",
251
+ labelField: "name"
252
+ }),
253
+ match: (e) => e instanceof _ && M(e, "fetch")
254
+ }
255
+ ]
256
+ };
257
+ function Ve() {
258
+ K(me), K(ye);
259
+ }
260
+ export {
261
+ L as ExtendedFormatFormField,
262
+ he as ValuesSourceFormField,
263
+ me as formatFieldsExtension,
264
+ Ve as registerDefaultVueExtensions,
265
+ ye as valuesSourceExtension
266
+ };
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@jsonschema-editor/vue-extensions",
3
+ "version": "0.1.4",
4
+ "description": "Vue form field renderers for JSON Schema format extensions (email, url, phone)",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "JSON Schema Editor Contributors",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/eumicro/jsonschema-editor.git",
11
+ "directory": "jsonschema-editor-vue-extensions"
12
+ },
13
+ "homepage": "https://github.com/eumicro/jsonschema-editor/tree/main/jsonschema-editor-vue-extensions#readme",
14
+ "bugs": "https://github.com/eumicro/jsonschema-editor/issues",
15
+ "keywords": [
16
+ "vue",
17
+ "json-schema",
18
+ "form",
19
+ "extensions",
20
+ "email",
21
+ "url",
22
+ "phone"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "main": "./dist/jsonschema-editor-vue-extensions.js",
31
+ "module": "./dist/jsonschema-editor-vue-extensions.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/jsonschema-editor-vue-extensions.js"
37
+ }
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md"
42
+ ],
43
+ "sideEffects": false,
44
+ "peerDependencies": {
45
+ "vue": "^3.5.0",
46
+ "@jsonschema-editor/json-schema": "0.1.4",
47
+ "@jsonschema-editor/vue": "0.1.4",
48
+ "@jsonschema-editor/json-schema-extensions": "0.1.4"
49
+ },
50
+ "devDependencies": {
51
+ "@vitejs/plugin-vue": "^5.2.4",
52
+ "typescript": "^5.8.3",
53
+ "vite": "^6.3.5",
54
+ "vite-plugin-dts": "^4.5.4",
55
+ "vue": "^3.5.16",
56
+ "vue-tsc": "^2.2.10",
57
+ "@jsonschema-editor/json-schema": "0.1.4",
58
+ "@jsonschema-editor/vue": "0.1.4",
59
+ "@jsonschema-editor/json-schema-extensions": "0.1.4"
60
+ },
61
+ "scripts": {
62
+ "prebuild": "node --input-type=module -e \"import fs from 'node:fs'; fs.rmSync('dist',{recursive:true,force:true})\"",
63
+ "build": "vue-tsc -p tsconfig.json --noEmit && vite build",
64
+ "typecheck": "vue-tsc -p tsconfig.json --noEmit"
65
+ }
66
+ }