@joplo-app/kit 0.2.17 → 0.3.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/asset.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** 单个文件的上限:再大会拖慢看板加载并撑大发布包,应先压缩。 */
2
2
  export declare const ASSET_MAX_BYTES: number;
3
- /** 读入一张图片,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
3
+ /** 读入图片或二进制资源,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
4
4
  export declare function asset(path: string, from?: string): string;
package/dist/asset.js CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
- * asset('./photo.jpg'):把项目里的图片读成 data URI,内嵌进演示(本地看板、build、share 都带着它,不依赖外网)。
2
+ * asset('./photo.jpg'):把项目里的图片、GLB 或音频读成 data URI,内嵌进演示(本地看板、build、share 都带着它,不依赖外网)。
3
3
  * 路径相对于调用 asset() 的源文件,和 import 一样。作者模块在 Node 里执行,这里按需取 node:fs,
4
4
  * 不在模块顶层静态导入,免得别处只为类型引用 kit 时牵出 Node 依赖。
5
5
  */
6
6
  import { callsite } from "./node.js";
7
7
  const MIME = {
8
+ glb: 'model/gltf-binary',
9
+ mp3: 'audio/mpeg', wav: 'audio/wav', ogg: 'audio/ogg', m4a: 'audio/mp4', flac: 'audio/flac',
8
10
  jpg: 'image/jpeg',
9
11
  jpeg: 'image/jpeg',
10
12
  png: 'image/png',
@@ -21,7 +23,7 @@ function builtin(name) {
21
23
  throw new Error('asset() runs while Joplo loads the project in Node (22.3 or newer)');
22
24
  return get(name);
23
25
  }
24
- /** 读入一张图片,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
26
+ /** 读入图片或二进制资源,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
25
27
  export function asset(path, from) {
26
28
  const fs = builtin('node:fs');
27
29
  const p = builtin('node:path');
@@ -31,7 +33,7 @@ export function asset(path, from) {
31
33
  const ext = p.extname(file).slice(1).toLowerCase();
32
34
  const mime = MIME[ext];
33
35
  if (!mime)
34
- throw new Error(`asset("${path}"): unsupported image type ".${ext}" (use ${Object.keys(MIME).join(', ')})`);
36
+ throw new Error(`asset("${path}"): unsupported asset type ".${ext}" (use ${Object.keys(MIME).join(', ')})`);
35
37
  let size;
36
38
  try {
37
39
  const st = fs.statSync(file);
@@ -42,7 +44,8 @@ export function asset(path, from) {
42
44
  catch {
43
45
  throw new Error(`asset("${path}"): file not found at ${file} (paths are relative to the file that calls asset())`);
44
46
  }
45
- if (size > ASSET_MAX_BYTES)
46
- throw new Error(`asset("${path}"): ${Math.round(size / 1024)} KB is over the ${ASSET_MAX_BYTES / 1024 / 1024} MB limit; compress or resize the image first`);
47
+ const limit = mime.startsWith('image/') ? ASSET_MAX_BYTES : 50 * 1024 * 1024;
48
+ if (size > limit)
49
+ throw new Error(`asset("${path}"): ${Math.round(size / 1024)} KB is over the ${limit / 1024 / 1024} MB limit; compress or resize the asset first`);
47
50
  return `data:${mime};base64,${Buffer.from(fs.readFileSync(file)).toString('base64')}`;
48
51
  }
package/dist/index.d.ts CHANGED
@@ -10,9 +10,11 @@
10
10
  * 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
11
11
  */
12
12
  import { type Bind, type CondExpr, type JNode } from './node.js';
13
- export { $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from './node.js';
13
+ export { Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from './node.js';
14
14
  export type { Bind, CondExpr, JNode } from './node.js';
15
15
  export { asset } from './asset.js';
16
+ import type { PluginDef } from './plugin.js';
17
+ export type { PluginDef } from './plugin.js';
16
18
  type Json = string | number | boolean | null | Json[] | {
17
19
  [k: string]: Json;
18
20
  };
@@ -46,6 +48,7 @@ export type VoiceConfig = {
46
48
  * locales(D84):内容语言,第一个是源文件的语言(默认语言),其余的译文在 locales/<语言>.json(原文 → 译文)。
47
49
  * 可选:en、zh-CN、zh-TW、ja、ko、es、fr、de、pt-BR、ru。加一种语言:npx joplo i18n add <语言>。
48
50
  */
51
+ /** plugins(D86):启用的插件(npm 包的默认导出,`plugins: [scene3d]`(包 @joplo-app/plugin-3d 的默认导出));用法见 npx joplo skill <插件 id>。 */
49
52
  export type ConfigDef = {
50
53
  kind: 'config';
51
54
  name: string;
@@ -56,6 +59,7 @@ export type ConfigDef = {
56
59
  autoFocus?: boolean;
57
60
  voice?: VoiceConfig;
58
61
  locales?: string[];
62
+ plugins?: PluginDef[];
59
63
  source?: string;
60
64
  };
61
65
  export declare const config: (c: Omit<ConfigDef, "kind" | "source">) => ConfigDef;
@@ -195,12 +199,7 @@ export type EffectDef = {
195
199
  kind: 'effect';
196
200
  type: 'explain';
197
201
  text: string;
198
- } | {
199
- kind: 'effect';
200
- type: 'trace';
201
- ids: string[];
202
- mode: 'ok' | 'fail' | 'skip';
203
- } | {
202
+ } | import('./plugin.js').PluginEffectDef | {
204
203
  kind: 'effect';
205
204
  type: 'stream';
206
205
  path: string;
@@ -243,6 +242,8 @@ export type EffectDef = {
243
242
  /** 标注气泡放在目标的哪一侧;不写时自动选画面里放得下的一侧(右、左、下、上)。 */
244
243
  export type CalloutSide = 'top' | 'right' | 'bottom' | 'left';
245
244
  export declare const set: (target: Bind, value: Json) => EffectDef;
245
+ /** Several ordinary set effects. Values replace whole nested objects; accepts the namespace or a nested bind. */
246
+ export declare const patch: (target: Bind | Record<string, unknown>, values: Record<string, Json>) => EffectDef[];
246
247
  export declare const push: (target: Bind, value: Json) => EffectDef;
247
248
  /** 与 sonner 一致:toast('…')、toast.success('…')、toast.error('…')。 */
248
249
  export declare const toast: ((text: string) => EffectDef) & {
@@ -331,20 +332,6 @@ export declare const callout: (target: string, text: string, opts?: {
331
332
  * .system('对比两种结果', '左边是旧流程,右边是新流程', hold(5))
332
333
  */
333
334
  export declare const hold: (seconds: number) => EffectDef;
334
- /**
335
- * 调用链(D48):这一步沿 Diagram 的连线走了哪条路径。节点与连线的 state 由每一步的 trace 自动推算,不用再手写 set / state 绑定:
336
- * 本步 trace 到的是 active,之前 trace 过、本步没再 trace 的是 ok,trace.fail 的是 error(保持到之后又被 trace 成功),
337
- * trace.skip 的是 dim,从未涉及的是 idle;节点或连线上显式写的 state 优先。
338
- * 参数是节点 id 或连线 id:trace('brain', 'biz', 'local') 是 brain→biz、biz→local 两段;每段要有对应的连线,
339
- * 方向 from→to 或 to→from 都算(反向时流动的小点逆向走);同一方向有多条连线时写连线 id:trace('e_brain_biz')。
340
- * trace 同时相当于一个 shot(节点作为镜头目标,顺序有意义);同一步再写 shot 时两者合并。
341
- */
342
- export declare const trace: ((...ids: string[]) => EffectDef) & {
343
- /** 这段失败:连线和终点节点标为 error(保持到场景结束,除非之后又被 trace 成功)。 */
344
- fail: (...ids: string[]) => EffectDef;
345
- /** 这次没被调用:节点(以及它们之间的连线)标为 dim;不移动镜头。 */
346
- skip: (...ids: string[]) => EffectDef;
347
- };
348
335
  /**
349
336
  * 层级(视角,D43 / T-layers):一个完全独立的画面,有自己的 JSX 树,单独渲染、按自己的布局占满舞台。
350
337
  * 各层共享同一份场景状态(ui / data / inputs),切层时步骤不变。需要全景就自己声明一个 overview 层。
@@ -367,8 +354,9 @@ export declare const layer: (title: string, tree: JNode | JNode[], opts?: {
367
354
  role?: string;
368
355
  icon?: LayerIcon;
369
356
  }) => LayerDef;
370
- /** 步骤参数:字符串是字幕(可省略,省略时自动生成),其余是效果。 */
371
- export type StepArg = string | EffectDef;
357
+ /** 步骤参数:字幕、效果,或一组效果(patch() 返回数组,直接传入即可)。 */
358
+ /** Helpers can compose other helpers (for example patch plus timing effects). */
359
+ export type StepArg = string | EffectDef | readonly StepArg[];
372
360
  /**
373
361
  * 过渡卡(D56)的内容:整屏一句大字,用于开场、收尾、时间跳跃(「3 天后」)和换人。
374
362
  * sub:小一号的补充;points:收尾时列几条要点;role:换到哪个人(feature.roles 的键),卡片显示这个人,
@@ -379,6 +367,7 @@ export type CardOpts = {
379
367
  points?: string[];
380
368
  role?: string;
381
369
  };
370
+ export type CardArg = CardOpts | EffectDef | readonly CardArg[];
382
371
  export type StepDef = {
383
372
  /** Stable identity within this scenario; independent of the playback position. */
384
373
  key?: string;
@@ -386,6 +375,29 @@ export type StepDef = {
386
375
  action: {
387
376
  type: 'click';
388
377
  target: string;
378
+ } | {
379
+ type: 'drag';
380
+ target: string;
381
+ to: string | {
382
+ x: number;
383
+ y: number;
384
+ };
385
+ } | {
386
+ type: 'hover';
387
+ target: string;
388
+ ms: number;
389
+ } | {
390
+ type: 'scroll';
391
+ target: string;
392
+ to: string | {
393
+ x: number;
394
+ y: number;
395
+ };
396
+ } | {
397
+ type: 'plugin';
398
+ name: string;
399
+ target: string;
400
+ data: Record<string, unknown>;
389
401
  } | {
390
402
  type: 'type';
391
403
  target: string;
@@ -415,6 +427,8 @@ export type StepDef = {
415
427
  source?: string;
416
428
  };
417
429
  export type FlowOpts = {
430
+ /** Cross-scenario action confirmation lands before the match by default; after consumes it once. */
431
+ actionEntry?: 'before' | 'after';
418
432
  /** 覆盖的情况(feature.cases 的键)。 */
419
433
  cases?: string[];
420
434
  /** 模拟结果标签,例如“模拟失败”。缺省按 outcome 生成。 */
@@ -424,6 +438,15 @@ export type FlowOpts = {
424
438
  start?: string;
425
439
  /** 在 option.state 之上覆盖的初始状态。 */
426
440
  state?: StateInit;
441
+ /**
442
+ * 接着另一个场景演(同一方案的场景键):初始状态 = 那个场景最后一步之后的状态(路径、ui / data / inputs、导演层),
443
+ * 再叠上这里的 state。讲解片的章节、长流程的分段都用它,每一段从上一段结尾的画面开始,不用手抄状态。
444
+ */
445
+ from?: string;
446
+ /** false:保留手动/分支访问,但从发布站连续播放序列中排除;该场景播完停下。 */
447
+ autoplay?: boolean;
448
+ /** 从哪一层开始(layers 的键);缺省为第一层,写了 from 时为那个场景结尾的导演层。 */
449
+ layer?: string;
427
450
  description?: string;
428
451
  expected?: string;
429
452
  };
@@ -438,6 +461,17 @@ export declare class Flow {
438
461
  /** Give the preceding step a stable key. Keep it when editing or moving the same action. */
439
462
  key(key: string): this;
440
463
  click(target: string, ...args: StepArg[]): this;
464
+ drag(target: string, to: string | {
465
+ x: number;
466
+ y: number;
467
+ }, ...args: StepArg[]): this;
468
+ hover(target: string, ms?: number, ...args: StepArg[]): this;
469
+ scroll(target: string, to: string | {
470
+ x: number;
471
+ y: number;
472
+ }, ...args: StepArg[]): this;
473
+ /** Namespaced plugin action; payload and matching are declared by its plugin. */
474
+ act(name: string, target: string, data: Record<string, unknown>, ...args: StepArg[]): this;
441
475
  type(target: string, value: string, ...args: StepArg[]): this;
442
476
  select(target: string, value: string, ...args: StepArg[]): this;
443
477
  toggle(target: string, value: boolean, ...args: StepArg[]): this;
@@ -451,12 +485,28 @@ export declare class Flow {
451
485
  * .card('出发前一天', set($.data.weather, 'rain'))
452
486
  * .card('这个方案确认了', { points: ['行程单可以分享', '天气变了会主动提醒'] })
453
487
  */
454
- card(title: string, ...args: (CardOpts | EffectDef)[]): this;
488
+ card(title: string, ...rest: CardArg[]): this;
455
489
  /** 系统事件,例如“请求成功(模拟)”。 */
456
490
  system(name: string, ...args: StepArg[]): this;
457
491
  }
458
492
  /** 一条演示路径。 */
459
493
  export declare const flow: (name: string, opts?: FlowOpts) => Flow;
494
+ export declare const free: {
495
+ click: (target: string, ...args: StepArg[]) => StepDef;
496
+ type: (target: string, value: string, ...args: StepArg[]) => StepDef;
497
+ select: (target: string, value: string, ...args: StepArg[]) => StepDef;
498
+ toggle: (target: string, value: boolean, ...args: StepArg[]) => StepDef;
499
+ drag: (target: string, to: string | {
500
+ x: number;
501
+ y: number;
502
+ }, ...args: StepArg[]) => StepDef;
503
+ hover: (target: string, ms?: number, ...args: StepArg[]) => StepDef;
504
+ scroll: (target: string, to: string | {
505
+ x: number;
506
+ y: number;
507
+ }, ...args: StepArg[]) => StepDef;
508
+ act: (name: string, target: string, data: Record<string, unknown>, ...args: StepArg[]) => StepDef;
509
+ };
460
510
  export type OptionDef = {
461
511
  kind: 'option';
462
512
  name: string;
@@ -474,8 +524,10 @@ export type OptionDef = {
474
524
  coverage?: Record<string, CoverageDecl>;
475
525
  /** 层级(视角):每层一个独立画面 { client: layer('客户端视角', <ClientView />), backend: layer('后端流转', <Arch />) }。 */
476
526
  layers?: Record<string, LayerDef>;
527
+ free?: Record<string, StepDef>;
477
528
  scenarios: Record<string, Flow>;
478
529
  source?: string;
479
530
  };
480
531
  export declare const option: (o: Omit<OptionDef, "kind" | "source">) => OptionDef;
481
532
  export type { CondExpr as Condition };
533
+ export type { JoploProps } from './props.js';
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
11
11
  */
12
12
  import { bindPath, callsite, isBind } from "./node.js";
13
- export { $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from "./node.js";
13
+ export { Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from "./node.js";
14
14
  export { asset } from "./asset.js";
15
15
  export const config = (c) => ({ kind: 'config', ...c, source: callsite() });
16
16
  export const layout = (tree) => ({ kind: 'layout', tree, source: callsite() });
@@ -46,6 +46,8 @@ export const notApplicable = (reason) => ({ kind: 'coverage', status: 'not_appli
46
46
  export const excluded = (reason) => ({ kind: 'coverage', status: 'excluded', reason });
47
47
  const pathOf = (b) => (isBind(b) ? bindPath(b) : b);
48
48
  export const set = (target, value) => ({ kind: 'effect', type: 'set', path: pathOf(target), value });
49
+ /** Several ordinary set effects. Values replace whole nested objects; accepts the namespace or a nested bind. */
50
+ export const patch = (target, values) => Object.entries(values).map(([key, value]) => ({ kind: 'effect', type: 'set', path: `${pathOf(target)}.${key}`, value }));
49
51
  export const push = (target, value) => ({ kind: 'effect', type: 'append', path: pathOf(target), value });
50
52
  /** 与 sonner 一致:toast('…')、toast.success('…')、toast.error('…')。 */
51
53
  export const toast = Object.assign((text) => ({ kind: 'effect', type: 'toast', text, tone: 'info' }), {
@@ -132,22 +134,9 @@ export const callout = (target, text, opts = {}) => ({ kind: 'effect', type: 'ca
132
134
  * .system('对比两种结果', '左边是旧流程,右边是新流程', hold(5))
133
135
  */
134
136
  export const hold = (seconds) => ({ kind: 'effect', type: 'hold', seconds });
135
- /**
136
- * 调用链(D48):这一步沿 Diagram 的连线走了哪条路径。节点与连线的 state 由每一步的 trace 自动推算,不用再手写 set / state 绑定:
137
- * 本步 trace 到的是 active,之前 trace 过、本步没再 trace 的是 ok,trace.fail 的是 error(保持到之后又被 trace 成功),
138
- * trace.skip 的是 dim,从未涉及的是 idle;节点或连线上显式写的 state 优先。
139
- * 参数是节点 id 或连线 id:trace('brain', 'biz', 'local') 是 brain→biz、biz→local 两段;每段要有对应的连线,
140
- * 方向 from→to 或 to→from 都算(反向时流动的小点逆向走);同一方向有多条连线时写连线 id:trace('e_brain_biz')。
141
- * trace 同时相当于一个 shot(节点作为镜头目标,顺序有意义);同一步再写 shot 时两者合并。
142
- */
143
- export const trace = Object.assign((...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'ok' }), {
144
- /** 这段失败:连线和终点节点标为 error(保持到场景结束,除非之后又被 trace 成功)。 */
145
- fail: (...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'fail' }),
146
- /** 这次没被调用:节点(以及它们之间的连线)标为 dim;不移动镜头。 */
147
- skip: (...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'skip' }),
148
- });
149
137
  /** opts.role:这一层是谁的画面(feature.roles 的键,D56);画面角落显示这个人的名牌,层级标签带上头像。 */
150
138
  export const layer = (title, tree, opts = {}) => ({ kind: 'layer', title, tree, ...opts, source: callsite() });
139
+ const flattenArgs = (args) => args.flat(Infinity);
151
140
  export class Flow {
152
141
  name;
153
142
  opts;
@@ -160,8 +149,9 @@ export class Flow {
160
149
  this.source = callsite(4);
161
150
  }
162
151
  add(kind, action, args) {
163
- const caption = args.find((a) => typeof a === 'string');
164
- const effects = args.filter((a) => typeof a !== 'string');
152
+ const flat = flattenArgs(args);
153
+ const caption = flat.find((a) => typeof a === 'string');
154
+ const effects = flat.filter((a) => typeof a !== 'string');
165
155
  this.steps.push({ kind, action, ...(caption ? { caption } : {}), effects, source: callsite(4) });
166
156
  return this;
167
157
  }
@@ -178,6 +168,19 @@ export class Flow {
178
168
  click(target, ...args) {
179
169
  return this.add('user', { type: 'click', target }, args);
180
170
  }
171
+ drag(target, to, ...args) {
172
+ return this.add('user', { type: 'drag', target, to }, args);
173
+ }
174
+ hover(target, ms = 500, ...args) {
175
+ return this.add('user', { type: 'hover', target, ms }, args);
176
+ }
177
+ scroll(target, to, ...args) {
178
+ return this.add('user', { type: 'scroll', target, to }, args);
179
+ }
180
+ /** Namespaced plugin action; payload and matching are declared by its plugin. */
181
+ act(name, target, data, ...args) {
182
+ return this.add('user', { type: 'plugin', name, target, data }, args);
183
+ }
181
184
  type(target, value, ...args) {
182
185
  return this.add('user', { type: 'type', target, value }, args);
183
186
  }
@@ -201,7 +204,8 @@ export class Flow {
201
204
  * .card('出发前一天', set($.data.weather, 'rain'))
202
205
  * .card('这个方案确认了', { points: ['行程单可以分享', '天气变了会主动提醒'] })
203
206
  */
204
- card(title, ...args) {
207
+ card(title, ...rest) {
208
+ const args = flattenArgs(rest);
205
209
  const effects = args.filter((a) => a.kind === 'effect');
206
210
  const opts = Object.assign({}, ...args.filter((a) => a.kind !== 'effect'));
207
211
  const { sub, points, role } = opts;
@@ -216,4 +220,16 @@ export class Flow {
216
220
  }
217
221
  /** 一条演示路径。 */
218
222
  export const flow = (name, opts = {}) => new Flow(name, opts);
223
+ /** Unordered local reactions; the compiler permits only local state effects. */
224
+ const reaction = (build) => ({ ...build(new Flow('free', {})).steps[0], source: callsite(4) });
225
+ export const free = {
226
+ click: (target, ...args) => reaction(f => f.click(target, ...args)),
227
+ type: (target, value, ...args) => reaction(f => f.type(target, value, ...args)),
228
+ select: (target, value, ...args) => reaction(f => f.select(target, value, ...args)),
229
+ toggle: (target, value, ...args) => reaction(f => f.toggle(target, value, ...args)),
230
+ drag: (target, to, ...args) => reaction(f => f.drag(target, to, ...args)),
231
+ hover: (target, ms = 500, ...args) => reaction(f => f.hover(target, ms, ...args)),
232
+ scroll: (target, to, ...args) => reaction(f => f.scroll(target, to, ...args)),
233
+ act: (name, target, data, ...args) => reaction(f => f.act(name, target, data, ...args)),
234
+ };
219
235
  export const option = (o) => ({ kind: 'option', ...o, source: callsite() });
package/dist/node.d.ts CHANGED
@@ -14,6 +14,8 @@ export type CondExpr = {
14
14
  export type JNode = {
15
15
  readonly [NODE]: true;
16
16
  type: string;
17
+ /** Author-only package provenance for missing-plugin diagnostics. */
18
+ packageName?: string;
17
19
  props: Record<string, unknown>;
18
20
  children: JChild[];
19
21
  /** jsxDEV 提供的源位置(绝对路径:行:列),编译器会改成项目相对路径。 */
@@ -23,12 +25,14 @@ export type JChild = JNode | string | number | boolean | null | undefined | Bind
23
25
  /** 目录组件的标记函数。 */
24
26
  export type ComponentMarker = ((props: Record<string, unknown>) => never) & {
25
27
  readonly [COMPONENT]: string;
28
+ readonly packageName?: string;
26
29
  };
27
- export declare function component(name: string): ComponentMarker;
30
+ export declare function component(name: string, packageName?: string): ComponentMarker;
28
31
  export declare const isNode: (v: unknown) => v is JNode;
29
32
  export declare const isBind: (v: unknown) => v is Bind;
30
33
  export declare const bindPath: (b: Bind) => string;
31
34
  export declare const Fragment: ComponentMarker;
35
+ export declare const Custom: ComponentMarker;
32
36
  /** 布局或页面中的插槽:方案把元素堆叠到这里。 */
33
37
  export declare const Slot: (props: {
34
38
  name: string;
package/dist/node.js CHANGED
@@ -5,18 +5,21 @@
5
5
  export const NODE = Symbol.for('joplo.node');
6
6
  export const COMPONENT = Symbol.for('joplo.component');
7
7
  export const BIND = Symbol.for('joplo.bind');
8
- export function component(name) {
8
+ export function component(name, packageName) {
9
9
  const fn = (() => {
10
10
  throw new Error(`${name} is a Joplo component marker and can only be used in JSX`);
11
11
  });
12
12
  Object.defineProperty(fn, COMPONENT, { value: name });
13
13
  Object.defineProperty(fn, 'displayName', { value: name });
14
+ if (packageName)
15
+ Object.defineProperty(fn, 'packageName', { value: packageName });
14
16
  return fn;
15
17
  }
16
18
  export const isNode = (v) => typeof v === 'object' && v !== null && v[NODE] === true;
17
19
  export const isBind = (v) => (typeof v === 'object' || typeof v === 'function') && v !== null && typeof v[BIND] === 'string';
18
20
  export const bindPath = (b) => b[BIND];
19
21
  export const Fragment = component('#fragment');
22
+ export const Custom = component('Custom');
20
23
  /** 布局或页面中的插槽:方案把元素堆叠到这里。 */
21
24
  export const Slot = component('#slot');
22
25
  /** 布局中页面内容的位置。 */
@@ -31,7 +34,7 @@ export function createNode(type, rawProps, source) {
31
34
  if (typeof type === 'function') {
32
35
  const name = type[COMPONENT];
33
36
  if (name)
34
- return mk(name, props, children, src);
37
+ return { ...mk(name, props, children, src), ...(type.packageName ? { packageName: type.packageName } : {}) };
35
38
  // 作者自定义的函数组件:收集时展开
36
39
  const out = type({ ...props, children });
37
40
  if (isNode(out)) {