@joplo-app/plugin-ui 0.0.0-stage → 0.4.1
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 +97 -0
- package/dist/catalog.d.ts +30 -0
- package/dist/catalog.js +271 -0
- package/dist/components.d.ts +154 -0
- package/dist/components.js +133 -0
- package/dist/guide.d.ts +3 -0
- package/dist/guide.js +190 -0
- package/dist/plugin.d.ts +5 -0
- package/dist/plugin.js +89 -0
- package/dist/runtime.d.ts +68 -0
- package/dist/runtime.js +1554 -0
- package/dist/story-data.d.ts +20 -0
- package/dist/story-data.js +46 -0
- package/dist/version.json +3 -0
- package/package.json +55 -3
- package/README.md +0 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type StateChange = {
|
|
2
|
+
path: string;
|
|
3
|
+
before: unknown;
|
|
4
|
+
after: unknown;
|
|
5
|
+
};
|
|
6
|
+
/** 匹配绑定本身、祖先替换及子字段变化;子字段变化聚合成局部前后值。 */
|
|
7
|
+
export declare function changeFor(value: unknown, changes: readonly StateChange[]): StateChange | null;
|
|
8
|
+
export declare function dataRows(value: unknown, fields: unknown, rawBinding: unknown, changes: readonly StateChange[]): {
|
|
9
|
+
value: unknown;
|
|
10
|
+
change: StateChange | null;
|
|
11
|
+
key: string;
|
|
12
|
+
label: any;
|
|
13
|
+
}[];
|
|
14
|
+
export declare function stateFlowItems(value: unknown, states: unknown, labels: unknown): {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
state: "done" | "current" | "todo";
|
|
18
|
+
}[];
|
|
19
|
+
export declare function displayData(v: unknown): string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const binding = (value) => typeof value === 'string' && /^\$(ui|data|inputs)(\.[A-Za-z0-9_-]+)*$/.test(value) ? value.slice(1) : null;
|
|
2
|
+
const at = (v, keys) => keys.reduce((o, k) => o && typeof o === 'object' ? o[k] : undefined, v);
|
|
3
|
+
/** 匹配绑定本身、祖先替换及子字段变化;子字段变化聚合成局部前后值。 */
|
|
4
|
+
export function changeFor(value, changes) {
|
|
5
|
+
const path = binding(value);
|
|
6
|
+
if (!path)
|
|
7
|
+
return null;
|
|
8
|
+
const exact = changes.find(c => c.path === path);
|
|
9
|
+
if (exact)
|
|
10
|
+
return exact;
|
|
11
|
+
const parent = changes.find(c => path.startsWith(`${c.path}.`));
|
|
12
|
+
if (parent) {
|
|
13
|
+
const keys = path.slice(parent.path.length + 1).split('.');
|
|
14
|
+
const before = at(parent.before, keys), after = at(parent.after, keys);
|
|
15
|
+
return JSON.stringify(before) === JSON.stringify(after) ? null : { path, before, after };
|
|
16
|
+
}
|
|
17
|
+
const children = changes.filter(c => c.path.startsWith(`${path}.`));
|
|
18
|
+
if (!children.length)
|
|
19
|
+
return null;
|
|
20
|
+
const before = {}, after = {};
|
|
21
|
+
const put = (o, keys, v) => {
|
|
22
|
+
for (const k of keys.slice(0, -1)) {
|
|
23
|
+
o[k] ??= {};
|
|
24
|
+
o = o[k];
|
|
25
|
+
}
|
|
26
|
+
o[keys.at(-1)] = v;
|
|
27
|
+
};
|
|
28
|
+
for (const c of children) {
|
|
29
|
+
const keys = c.path.slice(path.length + 1).split('.');
|
|
30
|
+
put(before, keys, c.before);
|
|
31
|
+
put(after, keys, c.after);
|
|
32
|
+
}
|
|
33
|
+
return { path, before, after };
|
|
34
|
+
}
|
|
35
|
+
export function dataRows(value, fields, rawBinding, changes) {
|
|
36
|
+
const obj = value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
37
|
+
const selected = Array.isArray(fields) ? fields.flatMap(f => f && typeof f === 'object' && typeof f.key === 'string' ? [{ key: f.key, label: typeof f.label === 'string' ? f.label : f.key }] : []) : Object.keys(obj).map(key => ({ key, label: key }));
|
|
38
|
+
return selected.map(f => ({ ...f, value: obj[f.key], change: binding(rawBinding) ? changeFor(`${rawBinding}.${f.key}`, changes) : null }));
|
|
39
|
+
}
|
|
40
|
+
export function stateFlowItems(value, states, labels) {
|
|
41
|
+
const list = Array.isArray(states) ? states.filter((v) => typeof v === 'string' && v.length > 0) : [];
|
|
42
|
+
const names = labels && typeof labels === 'object' ? labels : {};
|
|
43
|
+
const current = list.indexOf(String(value ?? ''));
|
|
44
|
+
return list.map((v, i) => ({ value: v, label: typeof names[v] === 'string' ? names[v] : v, state: i === current ? 'current' : current >= 0 && i < current ? 'done' : 'todo' }));
|
|
45
|
+
}
|
|
46
|
+
export function displayData(v) { return v === undefined || v === null || v === '' ? '—' : typeof v === 'object' ? JSON.stringify(v) : String(v); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/plugin-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"joplo": {
|
|
6
|
+
"api": 2
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/plugin.d.ts",
|
|
11
|
+
"default": "./dist/plugin.js"
|
|
12
|
+
},
|
|
13
|
+
"./runtime": {
|
|
14
|
+
"types": "./dist/runtime.d.ts",
|
|
15
|
+
"default": "./dist/runtime.js"
|
|
16
|
+
},
|
|
17
|
+
"./guide": {
|
|
18
|
+
"types": "./dist/guide.d.ts",
|
|
19
|
+
"default": "./dist/guide.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
"./catalog": {
|
|
23
|
+
"types": "./dist/catalog.d.ts",
|
|
24
|
+
"default": "./dist/catalog.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@joplo-app/kit": "0.4.1",
|
|
29
|
+
"react": "19.3.1",
|
|
30
|
+
"motion": "14.9.1",
|
|
31
|
+
"clsx": "2.1.1",
|
|
32
|
+
"tailwind-merge": "3.7.0",
|
|
33
|
+
"react-dom": "19.3.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^19.3.0",
|
|
37
|
+
"@types/react-dom": "^19.3.0"
|
|
38
|
+
},
|
|
39
|
+
"description": "Joplo first-party UI and HTML vocabulary",
|
|
40
|
+
"license": "PolyForm-Shield-1.0.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Joplo-app/Joplo.git",
|
|
44
|
+
"directory": "plugins/ui"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "node ../../scripts/build-package.mjs"
|
|
57
|
+
}
|
|
6
58
|
}
|
package/README.md
DELETED