@joplo-app/kit 0.7.2 → 0.8.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.d.ts +30 -0
- package/dist/index.js +11 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -257,6 +257,10 @@ export type EffectDef = {
|
|
|
257
257
|
type: 'narrate';
|
|
258
258
|
text: string | false;
|
|
259
259
|
audio?: AudioSource;
|
|
260
|
+
} | {
|
|
261
|
+
kind: 'effect';
|
|
262
|
+
type: 'call';
|
|
263
|
+
mock: MockDef;
|
|
260
264
|
};
|
|
261
265
|
/** 标注气泡放在目标的哪一侧;不写时自动选画面里放得下的一侧(右、左、下、上)。 */
|
|
262
266
|
export type CalloutSide = 'top' | 'right' | 'bottom' | 'left';
|
|
@@ -487,7 +491,33 @@ export type FlowOpts = {
|
|
|
487
491
|
layer?: string;
|
|
488
492
|
description?: string;
|
|
489
493
|
expected?: string;
|
|
494
|
+
/**
|
|
495
|
+
* 写法 v2:这个切片里每个模拟请求依次用哪个结果,例如 { sendInvite: ['timeout', 'ok'] }(第一次超时、第二次成功)。
|
|
496
|
+
* 每次调用恰好用掉一个;没写的请求缺省用第一个结果。
|
|
497
|
+
*/
|
|
498
|
+
api?: Record<string, string[]>;
|
|
499
|
+
};
|
|
500
|
+
/** 模拟请求的一种结果:参数和 .system(name, ...args) 相同(字符串是说明,其余是效果),剧本里展开成一个系统步骤。 */
|
|
501
|
+
export type ResponseDef = {
|
|
502
|
+
kind: 'response';
|
|
503
|
+
name: string;
|
|
504
|
+
caption?: string;
|
|
505
|
+
effects: EffectDef[];
|
|
506
|
+
source?: string;
|
|
490
507
|
};
|
|
508
|
+
export declare const response: (name: string, ...args: StepArg[]) => ResponseDef;
|
|
509
|
+
/** 一个模拟请求和它的各种结果。名字在一件作品里唯一,flow({ api }) 用它选结果。 */
|
|
510
|
+
export type MockDef = {
|
|
511
|
+
name: string;
|
|
512
|
+
outcomes: Record<string, ResponseDef>;
|
|
513
|
+
source?: string;
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* 写法 v2:系统响应写一次。把返回值放进元素的 onClick 或步骤的效果里,表示“这里发出了这个请求”:
|
|
517
|
+
* 剧本里这一步之后自动接一个系统步骤(结果由 flow({ api }) 依次选,缺省第一个);观众接管时用第一个结果的本地效果。
|
|
518
|
+
* const sendInvite = mock('sendInvite', { ok: response('Request succeeded (mock)', set($.ui.sent, true)), timeout: response('Timed out (mock)', set($.ui.error, 'Timeout')) });
|
|
519
|
+
*/
|
|
520
|
+
export declare const mock: (name: string, outcomes: Record<string, ResponseDef>) => EffectDef;
|
|
491
521
|
export declare class Flow<Kind extends 'flow' | 'chapter' = 'flow'> {
|
|
492
522
|
readonly name: string;
|
|
493
523
|
readonly opts: FlowOpts;
|
package/dist/index.js
CHANGED
|
@@ -145,6 +145,17 @@ export function hold(source, audioOrOptions, opts = {}) {
|
|
|
145
145
|
/** opts.role:这一层是谁的画面(feature.roles 的键,D56);画面角落显示这个人的名牌,层级标签带上头像。 */
|
|
146
146
|
export const layer = (title, tree, opts = {}) => ({ kind: 'layer', title, tree, ...opts, source: callsite() });
|
|
147
147
|
const flattenArgs = (args) => args.flat(Infinity);
|
|
148
|
+
export const response = (name, ...args) => {
|
|
149
|
+
const flat = flattenArgs(args);
|
|
150
|
+
const caption = flat.find((a) => typeof a === 'string');
|
|
151
|
+
return { kind: 'response', name, ...(caption ? { caption } : {}), effects: flat.filter((a) => typeof a !== 'string'), source: callsite(3) };
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 写法 v2:系统响应写一次。把返回值放进元素的 onClick 或步骤的效果里,表示“这里发出了这个请求”:
|
|
155
|
+
* 剧本里这一步之后自动接一个系统步骤(结果由 flow({ api }) 依次选,缺省第一个);观众接管时用第一个结果的本地效果。
|
|
156
|
+
* const sendInvite = mock('sendInvite', { ok: response('Request succeeded (mock)', set($.ui.sent, true)), timeout: response('Timed out (mock)', set($.ui.error, 'Timeout')) });
|
|
157
|
+
*/
|
|
158
|
+
export const mock = (name, outcomes) => ({ kind: 'effect', type: 'call', mock: { name, outcomes, source: callsite(3) } });
|
|
148
159
|
export class Flow {
|
|
149
160
|
name;
|
|
150
161
|
opts;
|
package/package.json
CHANGED