@cisri/json-schema-ui-core 1.0.0

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.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(e){if(e.enum)return"select";switch(e.type){case"number":case"integer":return"updown";case"boolean":return"checkbox";case"string":default:return"text"}}function o(e){const r={};if(e.type==="object"&&e.properties){const t=Object.keys(e.properties);t.length>0&&(r["ui:order"]=t);for(const[n,i]of Object.entries(e.properties))r[n]=o(i)}else e.type==="array"&&e.items?r.items=o(e.items):r["ui:widget"]=s(e);return r}function f(e,r){let t=e;for(const n of r){if(t==null||typeof t!="object")return;t=t[n]}return t}function u(e,r,t){if(r.length===0)return{...e,...t};const[n,...i]=r,l=e[n]??{};return{...e,[n]:u(l,i,t)}}exports.generateDefaultUiSchema=o;exports.getUiField=f;exports.setUiField=u;
@@ -0,0 +1,3 @@
1
+ export type { UiWidget, UiSchema } from './types';
2
+ export { generateDefaultUiSchema, getUiField, setUiField } from './utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ function f(e) {
2
+ if (e.enum) return "select";
3
+ switch (e.type) {
4
+ case "number":
5
+ case "integer":
6
+ return "updown";
7
+ case "boolean":
8
+ return "checkbox";
9
+ case "string":
10
+ default:
11
+ return "text";
12
+ }
13
+ }
14
+ function o(e) {
15
+ const r = {};
16
+ if (e.type === "object" && e.properties) {
17
+ const t = Object.keys(e.properties);
18
+ t.length > 0 && (r["ui:order"] = t);
19
+ for (const [n, i] of Object.entries(e.properties))
20
+ r[n] = o(i);
21
+ } else e.type === "array" && e.items ? r.items = o(e.items) : r["ui:widget"] = f(e);
22
+ return r;
23
+ }
24
+ function l(e, r) {
25
+ let t = e;
26
+ for (const n of r) {
27
+ if (t == null || typeof t != "object") return;
28
+ t = t[n];
29
+ }
30
+ return t;
31
+ }
32
+ function s(e, r, t) {
33
+ if (r.length === 0) return { ...e, ...t };
34
+ const [n, ...i] = r, u = e[n] ?? {};
35
+ return { ...e, [n]: s(u, i, t) };
36
+ }
37
+ export {
38
+ o as generateDefaultUiSchema,
39
+ l as getUiField,
40
+ s as setUiField
41
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 表单 widget 标识(RJSF 核心子集)。
3
+ */
4
+ export type UiWidget = 'text' | 'textarea' | 'password' | 'color' | 'date' | 'updown' | 'range' | 'checkbox' | 'radio' | 'select' | 'hidden';
5
+ /**
6
+ * uiSchema:与 JsonSchema 并行的 UI 提示(RJSF 风格 ui:* 键)。
7
+ * 嵌套:object 各 property 名 → UiSchema;array 的 'items' → UiSchema。
8
+ */
9
+ export interface UiSchema {
10
+ 'ui:widget'?: UiWidget;
11
+ 'ui:options'?: Record<string, unknown>;
12
+ 'ui:label'?: string | false;
13
+ 'ui:help'?: string;
14
+ 'ui:placeholder'?: string;
15
+ 'ui:order'?: string[];
16
+ 'ui:hidden'?: boolean;
17
+ 'ui:disabled'?: boolean;
18
+ 'ui:readonly'?: boolean;
19
+ 'ui:classNames'?: string;
20
+ 'ui:autofocus'?: boolean;
21
+ [property: string]: unknown;
22
+ }
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,UAAU,GACV,UAAU,GACV,OAAO,GACP,MAAM,GACN,QAAQ,GACR,OAAO,GACP,UAAU,GACV,OAAO,GACP,QAAQ,GACR,QAAQ,CAAC;AAEb;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B"}
@@ -0,0 +1,6 @@
1
+ import type { JsonSchema } from '@cisri/json-schema-core';
2
+ import type { UiSchema } from './types';
3
+ export declare function generateDefaultUiSchema(schema: JsonSchema): UiSchema;
4
+ export declare function getUiField(uiSchema: UiSchema | undefined, path: string[]): UiSchema | undefined;
5
+ export declare function setUiField(uiSchema: UiSchema, path: string[], patch: Partial<UiSchema>): UiSchema;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,SAAS,CAAC;AAgBlD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAcpE;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,IAAI,EAAE,MAAM,EAAE,GACb,QAAQ,GAAG,SAAS,CAOtB;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvB,QAAQ,CAKV"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@cisri/json-schema-ui-core",
3
+ "version": "1.0.0",
4
+ "description": "Shared uiSchema types and utilities for @cisri business components",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "sideEffects": false,
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "dependencies": {
24
+ "@cisri/json-schema-core": "1.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "typescript": "^5.4.5",
28
+ "vite": "^5.2.11",
29
+ "vitest": "^1.6.0"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc && vite build",
33
+ "test": "vitest run",
34
+ "test:watch": "vitest"
35
+ }
36
+ }