@joplo-app/core 0.2.2 → 0.2.5

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/schema.d.ts CHANGED
@@ -6,6 +6,9 @@
6
6
  */
7
7
  import { z } from 'zod';
8
8
  import { COMPONENT_TYPES } from './catalog.js';
9
+ /** 层级标签的预设图标(标签压窄时靠它认出是哪一层)。不写时:手机视口 mobile,其余 window。 */
10
+ export declare const LAYER_ICONS: readonly ["window", "browser", "mobile", "desktop", "terminal", "chat", "agent", "server", "data", "email", "doc", "flow"];
11
+ export type LayerIcon = (typeof LAYER_ICONS)[number];
9
12
  export declare const SCHEMA_VERSION: 2;
10
13
  /** 作者可写的 ID(对象键、元素 id)。 */
11
14
  export declare const Id: z.ZodString;
@@ -203,12 +206,12 @@ export declare const Step: z.ZodObject<{
203
206
  caption: z.ZodString;
204
207
  captionAuto: z.ZodOptional<z.ZodObject<{
205
208
  kind: z.ZodEnum<{
209
+ check: "check";
206
210
  click: "click";
207
211
  type: "type";
208
212
  select: "select";
209
213
  press: "press";
210
214
  back: "back";
211
- check: "check";
212
215
  uncheck: "uncheck";
213
216
  switch_on: "switch_on";
214
217
  switch_off: "switch_off";
@@ -347,12 +350,12 @@ export declare const Scenario: z.ZodObject<{
347
350
  caption: z.ZodString;
348
351
  captionAuto: z.ZodOptional<z.ZodObject<{
349
352
  kind: z.ZodEnum<{
353
+ check: "check";
350
354
  click: "click";
351
355
  type: "type";
352
356
  select: "select";
353
357
  press: "press";
354
358
  back: "back";
355
- check: "check";
356
359
  uncheck: "uncheck";
357
360
  switch_on: "switch_on";
358
361
  switch_off: "switch_off";
@@ -527,6 +530,20 @@ export declare const Option: z.ZodObject<{
527
530
  title: z.ZodString;
528
531
  sceneId: z.ZodString;
529
532
  role: z.ZodOptional<z.ZodString>;
533
+ icon: z.ZodOptional<z.ZodEnum<{
534
+ terminal: "terminal";
535
+ data: "data";
536
+ desktop: "desktop";
537
+ mobile: "mobile";
538
+ window: "window";
539
+ browser: "browser";
540
+ chat: "chat";
541
+ agent: "agent";
542
+ server: "server";
543
+ email: "email";
544
+ doc: "doc";
545
+ flow: "flow";
546
+ }>>;
530
547
  }, z.core.$strict>>>;
531
548
  source: z.ZodOptional<z.ZodString>;
532
549
  }, z.core.$strict>;
@@ -575,8 +592,9 @@ export declare const Project: z.ZodObject<{
575
592
  theme: z.ZodDefault<z.ZodString>;
576
593
  themes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
577
594
  mode: z.ZodEnum<{
578
- dev: "dev";
579
595
  publish: "publish";
596
+ dev: "dev";
597
+ review: "review";
580
598
  }>;
581
599
  routes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
582
600
  path: z.ZodString;
@@ -606,6 +624,7 @@ export declare const Project: z.ZodObject<{
606
624
  pick: z.ZodDefault<z.ZodNullable<z.ZodString>>;
607
625
  source: z.ZodOptional<z.ZodString>;
608
626
  }, z.core.$strict>>>;
627
+ featureIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
609
628
  cases: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
610
629
  id: z.ZodString;
611
630
  featureId: z.ZodString;
@@ -656,6 +675,20 @@ export declare const Project: z.ZodObject<{
656
675
  title: z.ZodString;
657
676
  sceneId: z.ZodString;
658
677
  role: z.ZodOptional<z.ZodString>;
678
+ icon: z.ZodOptional<z.ZodEnum<{
679
+ terminal: "terminal";
680
+ data: "data";
681
+ desktop: "desktop";
682
+ mobile: "mobile";
683
+ window: "window";
684
+ browser: "browser";
685
+ chat: "chat";
686
+ agent: "agent";
687
+ server: "server";
688
+ email: "email";
689
+ doc: "doc";
690
+ flow: "flow";
691
+ }>>;
659
692
  }, z.core.$strict>>>;
660
693
  source: z.ZodOptional<z.ZodString>;
661
694
  }, z.core.$strict>>>;
@@ -755,12 +788,12 @@ export declare const Project: z.ZodObject<{
755
788
  caption: z.ZodString;
756
789
  captionAuto: z.ZodOptional<z.ZodObject<{
757
790
  kind: z.ZodEnum<{
791
+ check: "check";
758
792
  click: "click";
759
793
  type: "type";
760
794
  select: "select";
761
795
  press: "press";
762
796
  back: "back";
763
- check: "check";
764
797
  uncheck: "uncheck";
765
798
  switch_on: "switch_on";
766
799
  switch_off: "switch_off";
package/dist/schema.js CHANGED
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import { z } from 'zod';
8
8
  import { COMPONENT_TYPES } from "./catalog.js";
9
+ /** 层级标签的预设图标(标签压窄时靠它认出是哪一层)。不写时:手机视口 mobile,其余 window。 */
10
+ export const LAYER_ICONS = ['window', 'browser', 'mobile', 'desktop', 'terminal', 'chat', 'agent', 'server', 'data', 'email', 'doc', 'flow'];
9
11
  export const SCHEMA_VERSION = 2;
10
12
  /** 作者可写的 ID(对象键、元素 id)。 */
11
13
  export const Id = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/, 'ID must start with a letter and contain only letters, digits, underscores, and hyphens');
@@ -186,7 +188,8 @@ export const Option = z.strictObject({
186
188
  routes: z.array(z.string()).default([]),
187
189
  coverage: z.record(Qid, Coverage).default({}),
188
190
  /** 层级(视角):键 → 标题与这一层自己的画面(完全独立的页面)。演示信息,发布站保留。 */
189
- layers: z.record(Id, z.strictObject({ title: z.string().min(1), sceneId: Qid, role: Id.optional() })).default({}),
191
+ /** icon:作者显式选的预设图标(层级标签用);不写时由 layersOf 按视口补默认。 */
192
+ layers: z.record(Id, z.strictObject({ title: z.string().min(1), sceneId: Qid, role: Id.optional(), icon: z.enum(LAYER_ICONS).optional() })).default({}),
190
193
  source: Source,
191
194
  });
192
195
  export const RULE_ORIGINS = ['user', 'project_material', 'ai_assumption', 'code_observed', 'feedback'];
@@ -221,14 +224,22 @@ export const Project = z.strictObject({
221
224
  theme: z.string().min(1).default('sketch'),
222
225
  /** 作者主题(D51):主题名 → CSS 原文(themes/<name>.css);渲染时自动限定在舞台范围内。发布站同样打包。 */
223
226
  themes: z.record(z.string(), z.string()).default({}),
224
- /** dev = 含全部方案(本地看板);publish = 只含选定方案,且去掉创作侧信息(D33)。 */
225
- mode: z.enum(['dev', 'publish']),
227
+ /** dev = 含全部方案(本地看板);publish = 只含选定方案,且去掉创作侧信息(D33);review = 评审版:全部方案,同样去掉创作侧信息(D63)。 */
228
+ mode: z.enum(['dev', 'publish', 'review']),
226
229
  routes: z.record(z.string(), Route).default({}),
227
230
  features: z.record(Id, Feature).default({}),
231
+ /** 编译器决定的演示顺序,发布时保留。旧 IR 可省略,读取时沿用其已有顺序。 */
232
+ featureIds: z.array(Id).optional(),
228
233
  cases: z.record(Qid, Case).default({}),
229
234
  options: z.record(Qid, Option).default({}),
230
235
  rules: z.record(Qid, Rule).default({}),
231
236
  scenes: z.record(Qid, Scene).default({}),
232
237
  scenarios: z.record(Qid, Scenario).default({}),
233
238
  issues: z.record(Qid, Issue).default({}),
239
+ }).superRefine((p, ctx) => {
240
+ if (!p.featureIds)
241
+ return;
242
+ const ids = new Set(p.featureIds);
243
+ if (ids.size !== p.featureIds.length || ids.size !== Object.keys(p.features).length || p.featureIds.some(id => !p.features[id]))
244
+ ctx.addIssue({ code: 'custom', path: ['featureIds'], message: 'featureIds must list every feature exactly once' });
234
245
  });
package/dist/validate.js CHANGED
@@ -1,7 +1,9 @@
1
+ import { orderedFeatures } from "./features.js";
1
2
  import { Project } from "./schema.js";
2
3
  import { CAPTION_MAX, EXPLAIN_MAX, INTERACTIVE_TYPES, captionLength } from "./catalog.js";
3
4
  import { walkNodes, findNode, replay } from "./player.js";
4
5
  import { JoploError } from "./result.js";
6
+ import { schemaDiagnostics } from "./schema-issues.js";
5
7
  /** IR v2 的确定性校验。源位置缺失(例如手工构造/发布 IR)时回退到配置文件。 */
6
8
  export function validate(project, opts = { mode: 'all' }) {
7
9
  if (!['structure', 'replay', 'all'].includes(opts.mode))
@@ -25,20 +27,9 @@ export function validate(project, opts = { mode: 'all' }) {
25
27
  } });
26
28
  const parsed = Project.safeParse(project);
27
29
  if (!parsed.success) {
28
- for (const issue of parsed.error.issues) {
29
- let value = project;
30
- let at;
31
- for (const key of issue.path) {
32
- if (value && typeof value === 'object') {
33
- if ('source' in value && typeof value.source === 'string')
34
- at = value.source;
35
- value = value[key];
36
- }
37
- else
38
- break;
39
- }
40
- emit('error', 'INVALID_SCHEMA', `${issue.path.join('.') || 'project'}: ${issue.message}`, at, undefined, 'schema');
41
- }
30
+ // 与编译器同一套:定位到最近的作者元素,同一根因合并成一条(schema-issues.ts)
31
+ for (const d of schemaDiagnostics(project, parsed.error.issues))
32
+ diagnostics.push({ ...d, at: d.at ?? 'joplo.config.ts:1:1' });
42
33
  return report();
43
34
  }
44
35
  const p = parsed.data;
@@ -64,7 +55,7 @@ export function validate(project, opts = { mode: 'all' }) {
64
55
  for (const c of Object.values(p.cases).filter(c => !opts.optionId || c.featureId === p.options[opts.optionId]?.featureId)) {
65
56
  ref(p.features[c.featureId]?.caseIds.includes(c.id), `Case feature does not exist or does not list the case: ${c.featureId}`, c, 'case');
66
57
  }
67
- for (const f of Object.values(p.features).filter(f => !opts.optionId || f.optionIds.includes(opts.optionId))) {
58
+ for (const f of orderedFeatures(p).filter(f => !opts.optionId || f.optionIds.includes(opts.optionId))) {
68
59
  for (const id of f.caseIds)
69
60
  ref(p.cases[id]?.featureId === f.id, `Feature case is missing or belongs to another feature: ${id}`, f, 'feature');
70
61
  for (const id of f.optionIds)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.2.2",
3
+ "version": "0.2.5",
4
4
  "description": "Joplo 编译器、校验器与播放器(IR v2)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@joplo-app/kit": "0.2.2",
22
+ "@joplo-app/kit": "0.2.5",
23
23
  "zod": "4.6.7"
24
24
  },
25
25
  "engines": {