@overmvp/kumi 0.4.0 → 0.5.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/builder/module-declarations.mjs +2 -2
- package/builder/module-declarations.test.mjs +4 -2
- package/package.json +1 -1
- package/router/router-view.ts +5 -3
- package/scripts/addon-build.mjs +2 -0
- package/scripts/kumi-cli.mjs +0 -0
- package/src/elements.ts +11 -1
- package/src/module-ui.ts +4 -0
- package/src/module.ts +14 -4
- package/templates/addon/src/app/app.module.ts +3 -5
- package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
- package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
- package/utils/format.ts +13 -0
- package/utils/index.ts +1 -1
- package/wow/animation.ts +16 -4
- package/wow/app-ui.ts +132 -22
- package/wow/aura-container.ts +132 -38
- package/wow/aura-countdown.ts +19 -3
- package/wow/aura-follower.ts +32 -0
- package/wow/aura-view.ts +49 -0
- package/wow/css-box.ts +7 -4
- package/wow/css-surfaces.ts +10 -4
- package/wow/frames.ts +2 -0
- package/wow/hooks.ts +17 -0
- package/wow/hotkeys.ts +221 -0
- package/wow/index.ts +9 -5
- package/wow/initial-view.ts +99 -0
- package/wow/layout-view.ts +1 -1
- package/wow/native.ts +1 -0
- package/wow/pixel.ts +25 -0
- package/wow/scroll-view.ts +5 -4
- package/wow/status-bar.ts +65 -0
- package/wow/unit-button.ts +25 -4
- package/wow/view-nodes.ts +11 -4
- package/wow/view.ts +113 -116
|
@@ -478,8 +478,8 @@ export function transformModuleDeclarations(ts, path, source, { program, rejectU
|
|
|
478
478
|
if (ts.getDecorators(node)?.length !== 1) error(decorator, "@Module must be the only decorator on its class");
|
|
479
479
|
const heritage = node.heritageClauses?.[0]?.types[0];
|
|
480
480
|
if (node.heritageClauses?.length !== 1 || node.heritageClauses[0].token !== ts.SyntaxKind.ExtendsKeyword || !heritage
|
|
481
|
-
|| marker(heritage.expression) !== "ModuleType" || heritage.typeArguments?.length
|
|
482
|
-
error(node, "Extend ModuleType
|
|
481
|
+
|| marker(heritage.expression) !== "ModuleType" || (heritage.typeArguments?.length ?? 0) > 1) {
|
|
482
|
+
error(node, "Extend ModuleType. Supply its metadata type when the module exports services");
|
|
483
483
|
}
|
|
484
484
|
if (node.typeParameters?.length || ts.getModifiers(node)?.some(modifier =>
|
|
485
485
|
modifier.kind !== ts.SyntaxKind.ExportKeyword && modifier.kind !== ts.SyntaxKind.DefaultKeyword)) {
|
|
@@ -11,7 +11,7 @@ declare module "@kumi/core" {
|
|
|
11
11
|
export interface RuntimeScope { readonly scope: true }
|
|
12
12
|
export const moduleScope: { readonly name: "module scope" };
|
|
13
13
|
export function Module(metadata: unknown): ClassDecorator;
|
|
14
|
-
export class ModuleType<T> {}
|
|
14
|
+
export class ModuleType<T = { exports: {} }> {}
|
|
15
15
|
export function Injectable(): ClassDecorator;
|
|
16
16
|
export function Inject(token: object): ParameterDecorator;
|
|
17
17
|
export function defineModule<Metadata>(metadata: Metadata): Metadata;
|
|
@@ -183,10 +183,12 @@ test("lowers an empty injectable constructor and preserves an undecorated no-arg
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
test("retains AST-only Vite module lowering and rejects unknown decorators in the checked transform", () => {
|
|
186
|
-
const source = 'import { Module, ModuleType } from "@kumi/core";\nclass Service {}\n'
|
|
186
|
+
const source = 'import { Module, ModuleType } from "@kumi/core";\nclass Service {}\n'
|
|
187
|
+
+ '@Module({ id: "fixture", providers: [Service], exports: {} })\nexport class Fixture extends ModuleType {}\n';
|
|
187
188
|
const output = viteModuleDeclarations(ts).transform(source, "/fixture.ts?source");
|
|
188
189
|
assert.match(output, /providers: \[Service\]/);
|
|
189
190
|
assert.match(output, /defineModule as __kumiDefineModule/);
|
|
191
|
+
assert.doesNotMatch(output, /@Module|extends ModuleType/);
|
|
190
192
|
const unknown = fixture({ "fixture.ts": source.replace("class Service", "@Unrelated()\nclass Service") });
|
|
191
193
|
assert.throws(() => unknown.transform("fixture.ts"), /fixture\.ts:2:1: Unsupported WoW decorator/);
|
|
192
194
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overmvp/kumi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "TypeScript and TSX framework with a native Lua 5.1 compiler for World of Warcraft Retail addons",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/OverMVP/kumi.git" },
|
package/router/router-view.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createContext } from "../src/context";
|
|
2
|
-
import { createElement, type UIElement } from "../src/elements";
|
|
2
|
+
import { createElement, type Element, type UIElement } from "../src/elements";
|
|
3
3
|
import { jsxMap } from "../src/keyed-list";
|
|
4
4
|
import type { ModulePage } from "../src/module-ui";
|
|
5
|
-
import { ownedArray, type OwnedArray, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
5
|
+
import { ownedArray, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord } from "../src/owned-collections";
|
|
6
6
|
import { computed, currentScope, withReactiveScope } from "../src/reactive-scope";
|
|
7
7
|
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
8
8
|
import { fail, formatFailure, ok, type Protect, type Result } from "../src/result";
|
|
@@ -127,8 +127,10 @@ export function RouterView(this: void, props: { readonly className?: ClassNames
|
|
|
127
127
|
if (!watched.ok) throw new Error(watched.reason);
|
|
128
128
|
owner.onDispose(() => { activity?.dispose(); });
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
const view = jsxMap(() => visits.value, entry => entry.path, entry => createElement("div", {
|
|
131
131
|
className: props.className,
|
|
132
132
|
shown: computed(() => host.navigation.path.value === entry.path),
|
|
133
133
|
}, entry.content));
|
|
134
|
+
// A cold window has one initial visit. Its native subtree can stage with the hidden window.
|
|
135
|
+
return { ...view as OwnedRecord<Element<"keyedList">>, props: { mount: view.props.mount, stageFirstRow: true } };
|
|
134
136
|
}
|
package/scripts/addon-build.mjs
CHANGED
|
@@ -351,6 +351,8 @@ export async function buildProject(workspace, project, interfaceVersion, pack) {
|
|
|
351
351
|
}
|
|
352
352
|
const assets = join(workspace, "Assets");
|
|
353
353
|
if (existsSync(assets)) cpSync(assets, join(main, "Assets"), { recursive: true });
|
|
354
|
+
const bindings = join(workspace, "Bindings.xml");
|
|
355
|
+
if (existsSync(bindings)) cpSync(bindings, join(main, "Bindings.xml"));
|
|
354
356
|
for (const [path, data] of project.styleMaskAssets ?? []) {
|
|
355
357
|
const destination = join(main, path);
|
|
356
358
|
mkdirSync(dirname(destination), { recursive: true });
|
package/scripts/kumi-cli.mjs
CHANGED
|
File without changes
|
package/src/elements.ts
CHANGED
|
@@ -158,6 +158,8 @@ interface NativeProps {
|
|
|
158
158
|
secureStateHandler?: true;
|
|
159
159
|
/** The native frame's own scale in parent coordinates. */
|
|
160
160
|
nativeScale?: Binding<number>;
|
|
161
|
+
/** Let a render-only frame anchor to a native aura container without observing its geometry. */
|
|
162
|
+
nativeAuraFollower?: true;
|
|
161
163
|
/** Lay out this keyed frame directly in its parent CSS container. */
|
|
162
164
|
directKeyedLayout?: true;
|
|
163
165
|
/** Decorative artwork for WoW, reconciled as a single layer without child frames. */
|
|
@@ -214,6 +216,8 @@ interface NativeProps {
|
|
|
214
216
|
max: Binding<StatusBarValue>;
|
|
215
217
|
value: Binding<StatusBarValue>;
|
|
216
218
|
smooth?: boolean;
|
|
219
|
+
/** Change the key when a new source owns the bar or an opaque range changes. */
|
|
220
|
+
resetKey?: Binding<number>;
|
|
217
221
|
ref?: ElementRef<"statusbar">;
|
|
218
222
|
};
|
|
219
223
|
button: ElementLayout<"button"> & ElementEvents & {
|
|
@@ -230,6 +234,10 @@ interface NativeProps {
|
|
|
230
234
|
secureAction?: Binding<ActionSlot | undefined>;
|
|
231
235
|
/** Macro text run by a hardware click. Use this in place of `secureAction`. */
|
|
232
236
|
secureMacro?: Binding<string | undefined>;
|
|
237
|
+
/** Select this unit on a left click. The client tracks unit visibility through combat. */
|
|
238
|
+
secureUnit?: string;
|
|
239
|
+
/** Open the client's unit menu from a secure right click. Requires secureUnit. */
|
|
240
|
+
secureUnitMenu?: true;
|
|
233
241
|
/** An anchored secure button keeps its identity and mounts paint and children on its first show. */
|
|
234
242
|
deferContentUntilShown?: true;
|
|
235
243
|
/** Lay out this keyed button directly in its parent CSS container. */
|
|
@@ -278,6 +286,8 @@ interface NativeProps {
|
|
|
278
286
|
onChange?(this: void, value: number): void;
|
|
279
287
|
/** Runs after a pointer adjustment that changed the value. */
|
|
280
288
|
onCommit?(this: void): void;
|
|
289
|
+
/** Discard an unfinished adjustment when the range control hides or becomes disabled. */
|
|
290
|
+
onCancel?(this: void): void;
|
|
281
291
|
};
|
|
282
292
|
listbox: ElementLayout<"listbox"> & {
|
|
283
293
|
value: Binding<string>;
|
|
@@ -328,7 +338,7 @@ export interface CustomElements {}
|
|
|
328
338
|
|
|
329
339
|
interface BuiltInProps extends NativeProps {
|
|
330
340
|
fragment: Record<never, never>;
|
|
331
|
-
keyedList: { mount: MountKeyedList };
|
|
341
|
+
keyedList: { mount: MountKeyedList; stageFirstRow?: true };
|
|
332
342
|
transition: TransitionOptions;
|
|
333
343
|
portal: { target?: KumiNode<"frame"> };
|
|
334
344
|
selectItem: { value: string; label: string };
|
package/src/module-ui.ts
CHANGED
|
@@ -48,6 +48,10 @@ export interface ModuleWindow {
|
|
|
48
48
|
readonly height: number;
|
|
49
49
|
/** The page to open first. Defaults to the first file route. */
|
|
50
50
|
readonly start?: string;
|
|
51
|
+
/** Build the first unprotected window across frames, then reveal it once layout is ready. */
|
|
52
|
+
readonly mount?: "staged";
|
|
53
|
+
/** Hide the window in combat and restore its previous page when combat ends. */
|
|
54
|
+
readonly suspendInCombat?: true;
|
|
51
55
|
/** `"DIALOG"` by default. */
|
|
52
56
|
readonly strata?: string;
|
|
53
57
|
}
|
package/src/module.ts
CHANGED
|
@@ -30,7 +30,8 @@ declare const moduleExports: unique symbol;
|
|
|
30
30
|
type DecoratedModule<Exports extends object> = abstract new () => { readonly [moduleExports]: Readonly<Exports> };
|
|
31
31
|
type ModuleDependency<Exports extends object> = ModuleDeclaration<Exports> | DecoratedModule<Exports>;
|
|
32
32
|
|
|
33
|
-
export declare abstract class ModuleType<Definition extends { readonly exports: ServiceExports }
|
|
33
|
+
export declare abstract class ModuleType<Definition extends { readonly exports: ServiceExports } =
|
|
34
|
+
{ readonly exports: Record<never, never> }> {
|
|
34
35
|
readonly [moduleExports]: PublicServices<Definition["exports"]>;
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -74,14 +75,23 @@ export interface Module<Exports extends object> {
|
|
|
74
75
|
readonly exports: Readonly<Exports>;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
/** Public metadata for a module declared with @Module. */
|
|
79
|
+
export interface ModuleMetadata extends ModuleUi {
|
|
80
|
+
/** Stable, unique identifier within the addon's module graph. */
|
|
79
81
|
readonly id: string;
|
|
80
82
|
readonly imports?: readonly ModuleDependency<object>[];
|
|
81
83
|
readonly feature?: boolean;
|
|
82
|
-
|
|
84
|
+
/** Services owned by the module. Use an empty array if it owns none. */
|
|
85
|
+
readonly providers: readonly ProviderDeclaration[];
|
|
83
86
|
/** Stores this module owns. They open when the module activates, and their setup can inject the module's services. */
|
|
84
87
|
readonly stores?: readonly AnyStoreFactory[];
|
|
88
|
+
/** Public service tokens. Use an empty object for a module without public services. */
|
|
89
|
+
readonly exports: ServiceExports;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface DeclarativeModuleOptions<Providers extends readonly ProviderDeclaration[], Exports extends ServiceExports,
|
|
93
|
+
InferConstructor extends boolean = false> extends ModuleMetadata {
|
|
94
|
+
readonly providers: Providers & NoInfer<CheckedProviders<Providers, InferConstructor>>;
|
|
85
95
|
readonly exports: Exports;
|
|
86
96
|
}
|
|
87
97
|
|
|
@@ -5,14 +5,12 @@ import { useCommands } from "./commands.store";
|
|
|
5
5
|
import { AppWindow } from "./layout/AppWindow";
|
|
6
6
|
|
|
7
7
|
// The root module: the core features, the addon window and app-wide stores.
|
|
8
|
-
|
|
8
|
+
@Module({
|
|
9
9
|
id: "app",
|
|
10
10
|
imports: [GreetingModule],
|
|
11
11
|
providers: [],
|
|
12
12
|
stores: [useCommands],
|
|
13
13
|
window: { routes: router, layout: AppWindow, width: 460, height: 360, start: "/home" },
|
|
14
14
|
exports: {},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@Module(metadata)
|
|
18
|
-
export class AppModule extends ModuleType<typeof metadata> {}
|
|
15
|
+
})
|
|
16
|
+
export class AppModule extends ModuleType {}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Module, ModuleType } from "@kumi/core";
|
|
1
|
+
import { Module, ModuleType, type ModuleMetadata } from "@kumi/core";
|
|
2
2
|
import { useGreetingStore } from "./model/greeting.store";
|
|
3
3
|
import { GreetingService } from "./services/greeting.service";
|
|
4
4
|
import { GreetingHud } from "./widgets/GreetingHud";
|
|
@@ -12,7 +12,7 @@ const metadata = {
|
|
|
12
12
|
stores: [useGreetingStore],
|
|
13
13
|
views: [GreetingHud],
|
|
14
14
|
exports: { greeting: GreetingService },
|
|
15
|
-
} as const;
|
|
15
|
+
} as const satisfies ModuleMetadata;
|
|
16
16
|
|
|
17
17
|
@Module(metadata)
|
|
18
18
|
export class GreetingModule extends ModuleType<typeof metadata> {}
|
|
@@ -5,14 +5,12 @@ import { PlaytimeBadge } from "./ui/PlaytimeBadge";
|
|
|
5
5
|
import { PlaytimePage } from "./widgets/PlaytimePage";
|
|
6
6
|
|
|
7
7
|
// A plugin: kumi.config.ts lists this module under plugins, so it builds as its own addon.
|
|
8
|
-
|
|
8
|
+
@Module({
|
|
9
9
|
id: "playtime",
|
|
10
10
|
providers: [PlaytimeService],
|
|
11
11
|
stores: [usePlaytimeStore],
|
|
12
12
|
extensions: { "hud.footer": PlaytimeBadge },
|
|
13
13
|
pages: [{ path: "/playtime", title: "Playtime", component: PlaytimePage, order: 20 }],
|
|
14
14
|
exports: {},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@Module(metadata)
|
|
18
|
-
export class PlaytimeModule extends ModuleType<typeof metadata> {}
|
|
15
|
+
})
|
|
16
|
+
export class PlaytimeModule extends ModuleType {}
|
package/utils/format.ts
CHANGED
|
@@ -23,6 +23,19 @@ export function formatDuration(this: void, seconds: number, rounding: DurationRo
|
|
|
23
23
|
return `${Math.floor(whole / 60)}:${remainder < 10 ? "0" : ""}${remainder}`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function twoDigits(this: void, value: number): string {
|
|
27
|
+
return (value < 10 ? "0" : "") + String(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Format elapsed time as MM:SS, adding hours when needed. */
|
|
31
|
+
export function formatClock(this: void, seconds: number): string {
|
|
32
|
+
const elapsed = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
|
|
33
|
+
const hours = Math.floor(elapsed / 3600);
|
|
34
|
+
const minutes = Math.floor(elapsed / 60) % 60;
|
|
35
|
+
const clock = twoDigits(minutes) + ":" + twoDigits(elapsed % 60);
|
|
36
|
+
return hours > 0 ? String(hours) + ":" + clock : clock;
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
export function formatInteger(this: void, value: number, separator = ","): string {
|
|
27
40
|
let remaining = Math.abs(value);
|
|
28
41
|
if (remaining > 9_007_199_254_740_991 || !Number.isInteger(remaining)) return String(value);
|
package/utils/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { colorContrast, contrastRatio, copyRGB, hexToRGB, isRGB, mixRGB, rgbaToHex, rgbToHex, type RGB, type RGBA } from "./colors";
|
|
2
|
-
export { formatCompactAmount, formatDuration, formatInteger, formatPercent, type DurationRounding } from "./format";
|
|
2
|
+
export { formatClock, formatCompactAmount, formatDuration, formatInteger, formatPercent, type DurationRounding } from "./format";
|
|
3
3
|
export { clamp, fromPercent, isFiniteNumber, toPercent } from "./number";
|
|
4
4
|
export { replaceFirst } from "./text";
|
package/wow/animation.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ownedArray, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord } from "../src/owned-collections";
|
|
2
2
|
import type { RuntimeScope } from "../src/runtime";
|
|
3
3
|
import { fail, ok, type Result } from "../src/result";
|
|
4
|
-
import { currentScope } from "../src/reactive-scope";
|
|
4
|
+
import { computed, currentScope, watch } from "../src/reactive-scope";
|
|
5
5
|
import { nativeSmoothing } from "../animation/ease";
|
|
6
6
|
import { isReducedMotion, type MotionMode } from "../animation/motion-policy";
|
|
7
7
|
import { finalAlpha, planAnimation, type AlphaStep, type AnimationPlan, type AnimationSpec, type AnimationStep, type FlipBookStep,
|
|
@@ -30,9 +30,9 @@ export { configureAnimations, type AnimationDefaults, type MotionMode } from "..
|
|
|
30
30
|
export interface NativeAnimationOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Stops the group and clears its script when the scope is disposed. Inside a component's setup the
|
|
33
|
-
* component's scope is used when this is left out.
|
|
33
|
+
* component's scope is used when this is left out. Pass false when an integration owns cleanup.
|
|
34
34
|
*/
|
|
35
|
-
scope?: RuntimeScope;
|
|
35
|
+
scope?: RuntimeScope | false;
|
|
36
36
|
/** Multiplies every move offset, for views that scale their art. */
|
|
37
37
|
distance?: number;
|
|
38
38
|
/** Native speed multiplier. */
|
|
@@ -158,7 +158,7 @@ export function createAnimation(this: void, target: AnimationTarget, spec: Regio
|
|
|
158
158
|
export function createAnimation(this: void, target: Texture, spec: AnimationSpec, options?: NativeAnimationOptions): Result<AnimationControl>;
|
|
159
159
|
export function createAnimation(this: void, target: AnimationTarget, spec: AnimationSpec,
|
|
160
160
|
options: NativeAnimationOptions = {}): Result<AnimationControl> {
|
|
161
|
-
return build(target, spec, options, options.scope ?? currentScope());
|
|
161
|
+
return build(target, spec, options, options.scope === false ? undefined : options.scope ?? currentScope());
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
function build(target: AnimationTarget, spec: AnimationSpec, options: Omit<NativeAnimationOptions, "scope">,
|
|
@@ -356,6 +356,18 @@ export function useAnimation<const Step extends AnimationStep>(this: void, spec:
|
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
/** Play a decorative animation while active, and hide its element when motion is reduced. */
|
|
360
|
+
export function useAnimationWhile<const Step extends AnimationStep>(this: void, spec: AnimationSpec<Step>,
|
|
361
|
+
active: (this: void) => boolean, offset?: number) {
|
|
362
|
+
const animation = useAnimation(spec);
|
|
363
|
+
const visible = () => active() && !isReducedMotion();
|
|
364
|
+
watch(visible, playing => {
|
|
365
|
+
if (playing) animation.play(offset === undefined ? undefined : { offset });
|
|
366
|
+
else animation.stop();
|
|
367
|
+
}, { immediate: true });
|
|
368
|
+
return { ref: animation.ref, shown: computed(visible) };
|
|
369
|
+
}
|
|
370
|
+
|
|
359
371
|
function lengthOf(spec: AnimationSpec) {
|
|
360
372
|
const plan = planAnimation(spec);
|
|
361
373
|
return plan.ok ? plan.value.length : 0;
|
package/wow/app-ui.ts
CHANGED
|
@@ -4,10 +4,11 @@ import { installModuleUi, modulePages, type ModulePage, type ModuleReplacement,
|
|
|
4
4
|
import type { OwnedReadonlyArray, OwnedRecord } from "../src/owned-collections";
|
|
5
5
|
import { computed } from "../src/reactive-scope";
|
|
6
6
|
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
7
|
-
import { fail, formatFailure, ok, type Result } from "../src/result";
|
|
7
|
+
import { fail, formatFailure, ok, type Failure, type Result } from "../src/result";
|
|
8
8
|
import type { Runtime, RuntimeScope } from "../src/runtime";
|
|
9
9
|
import { withRouterHost, type RoutePage, type RouterHost } from "../router/router-view";
|
|
10
10
|
import { defineStore, readonly } from "../state/setup-store";
|
|
11
|
+
import { unlockedActionSlot } from "./action-button";
|
|
11
12
|
import type { EventApi } from "./contract";
|
|
12
13
|
import type { FrameStrata } from "./frame-layer";
|
|
13
14
|
import { mountModuleReplacements } from "./module-replacements";
|
|
@@ -17,7 +18,7 @@ import type { NativeViewOptions } from "./view";
|
|
|
17
18
|
|
|
18
19
|
/** App-wide options for every view Kumi mounts: textures, fonts, control skins and media queries. */
|
|
19
20
|
export type AppTheme = Omit<NativeViewOptions, "rootLayer" | "bindings" | "manualTextBindings" | "layoutDiagnostics" | "regionsOnly"
|
|
20
|
-
| "rootBackdrop" | "rootScale" | "unanchoredRoot" | "portalRoot" | "unprotectedOnly">;
|
|
21
|
+
| "rootBackdrop" | "rootScale" | "unanchoredRoot" | "portalRoot" | "unprotectedOnly" | "completeStagedMount">;
|
|
21
22
|
|
|
22
23
|
interface FileRouter {
|
|
23
24
|
readonly pages: OwnedReadonlyArray<{ readonly path: string; readonly title?: string; readonly order?: number }>;
|
|
@@ -43,13 +44,18 @@ interface WindowState {
|
|
|
43
44
|
readonly config: ModuleWindow;
|
|
44
45
|
readonly router: FileRouter;
|
|
45
46
|
readonly owner: RuntimeScope;
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
panel?: WindowPanel;
|
|
48
|
+
opening?: RuntimeScope;
|
|
49
|
+
inCombat?: boolean;
|
|
50
|
+
resumePath?: string;
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
type WindowPanel = Extract<ReturnType<typeof createNativePanel>, { ok: true }>["value"];
|
|
54
|
+
|
|
50
55
|
let app: AppContext | undefined;
|
|
51
56
|
const windowState = ref<WindowState | undefined>(undefined);
|
|
52
57
|
const windowOpen = ref(false);
|
|
58
|
+
const windowOpening = ref(false);
|
|
53
59
|
const windowPath = ref<string | undefined>(undefined);
|
|
54
60
|
const viewContext = createContext<ViewHost>();
|
|
55
61
|
|
|
@@ -73,15 +79,16 @@ function firstPath(state: WindowState) {
|
|
|
73
79
|
return undefined;
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
function mountWindow(state: WindowState
|
|
82
|
+
function mountWindow(state: WindowState, owner: RuntimeScope,
|
|
83
|
+
complete?: NativeViewOptions["completeStagedMount"]): Result<WindowPanel> {
|
|
77
84
|
const context = app;
|
|
78
85
|
if (context === undefined) return fail("The addon window needs a running addon");
|
|
79
86
|
const { config } = state;
|
|
80
|
-
const panel = createNativePanel(
|
|
87
|
+
const panel = createNativePanel(owner, context.events, config.width, config.height,
|
|
81
88
|
(config.strata ?? "DIALOG") as FrameStrata, 0);
|
|
82
89
|
if (!panel.ok) return panel;
|
|
83
90
|
const host: RouterHost = {
|
|
84
|
-
navigation: { path: windowPath as ReadonlyRef<string | undefined>, navigate: path => {
|
|
91
|
+
navigation: { path: windowPath as ReadonlyRef<string | undefined>, navigate: path => { navigateSettings(path); } },
|
|
85
92
|
render: path => state.router.has(path) ? state.router.render(path, {}) : undefined,
|
|
86
93
|
modulePages: modulePages(),
|
|
87
94
|
};
|
|
@@ -91,12 +98,93 @@ function mountWindow(state: WindowState): Result<void> {
|
|
|
91
98
|
return layout.value;
|
|
92
99
|
}, {
|
|
93
100
|
cssFlow: true, initialLayout: "sync", ...context.theme as OwnedRecord<NativeViewOptions>,
|
|
101
|
+
completeStagedMount: complete, unprotectedOnly: complete === undefined ? undefined : true,
|
|
94
102
|
});
|
|
95
103
|
if (!mounted.ok) return mounted;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return
|
|
104
|
+
const cleanup = owner.onDispose(mounted.value.dispose);
|
|
105
|
+
if (cleanup.ok) return panel;
|
|
106
|
+
mounted.value.dispose();
|
|
107
|
+
return cleanup;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function cancelOpening(state: WindowState) {
|
|
111
|
+
const opening = state.opening;
|
|
112
|
+
state.opening = undefined;
|
|
113
|
+
windowOpening.value = false;
|
|
114
|
+
opening?.dispose();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function showWindow(panel: WindowPanel) {
|
|
118
|
+
panel.show();
|
|
119
|
+
windowOpen.value = panel.isShown();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function windowBlocked(state: WindowState): boolean {
|
|
123
|
+
return state.config.suspendInCombat === true && (state.inCombat === true || !unlockedActionSlot());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function hideWindow(state: WindowState) {
|
|
127
|
+
cancelOpening(state);
|
|
128
|
+
state.panel?.hide();
|
|
129
|
+
windowOpen.value = false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function suspendWindow(state: WindowState) {
|
|
133
|
+
if (!windowOpen.value && !windowOpening.value) return;
|
|
134
|
+
state.resumePath = windowPath.value;
|
|
135
|
+
hideWindow(state);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function installWindowCombat(state: WindowState, events: EventApi): Result<void> {
|
|
139
|
+
if (state.config.suspendInCombat !== true) return ok(undefined);
|
|
140
|
+
const entering = events.on(state.owner, "PLAYER_REGEN_DISABLED", () => {
|
|
141
|
+
state.inCombat = true;
|
|
142
|
+
suspendWindow(state);
|
|
143
|
+
});
|
|
144
|
+
if (!entering.ok) return entering;
|
|
145
|
+
const leaving = events.on(state.owner, "PLAYER_REGEN_ENABLED", () => {
|
|
146
|
+
state.inCombat = false;
|
|
147
|
+
state.owner.nextTick(() => {
|
|
148
|
+
const path = state.resumePath;
|
|
149
|
+
if (path === undefined || windowBlocked(state)) return;
|
|
150
|
+
state.resumePath = undefined;
|
|
151
|
+
const target = routeExists(path) ? path : firstPath(state);
|
|
152
|
+
if (target === undefined) return;
|
|
153
|
+
const opened = openWindow(target);
|
|
154
|
+
if (!opened.ok) return opened;
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return leaving.ok ? ok(undefined) : leaving;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function stageWindow(state: WindowState) {
|
|
161
|
+
const attempt = state.owner.fork();
|
|
162
|
+
const key = {};
|
|
163
|
+
let panel: WindowPanel | undefined;
|
|
164
|
+
state.opening = attempt;
|
|
165
|
+
windowOpening.value = true;
|
|
166
|
+
attempt.onDispose(() => { attempt.frameJobs.cancel(key); });
|
|
167
|
+
|
|
168
|
+
function finish(failure?: Failure) {
|
|
169
|
+
if (state.opening !== attempt) return;
|
|
170
|
+
if (windowBlocked(state)) { suspendWindow(state); return; }
|
|
171
|
+
if (failure !== undefined || panel === undefined) {
|
|
172
|
+
cancelOpening(state);
|
|
173
|
+
return failure ?? fail("The initial window mount did not create a panel");
|
|
174
|
+
}
|
|
175
|
+
state.panel = panel;
|
|
176
|
+
state.opening = undefined;
|
|
177
|
+
windowOpening.value = false;
|
|
178
|
+
showWindow(panel);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
attempt.frameJobs.queue(key, () => {
|
|
182
|
+
if (!attempt.isActive()) return;
|
|
183
|
+
const mounted = attempt.protect(() => mountWindow(state, attempt, finish));
|
|
184
|
+
const result = mounted.ok ? mounted.value : mounted;
|
|
185
|
+
if (!result.ok) return finish(result);
|
|
186
|
+
panel = result.value;
|
|
187
|
+
}, { lane: "user", label: "Prepare window JSX" });
|
|
100
188
|
}
|
|
101
189
|
|
|
102
190
|
function navigateWindow(path: string): Result<void> {
|
|
@@ -105,26 +193,45 @@ function navigateWindow(path: string): Result<void> {
|
|
|
105
193
|
return ok(undefined);
|
|
106
194
|
}
|
|
107
195
|
|
|
196
|
+
function navigateSettings(path: string): Result<void> {
|
|
197
|
+
const state = windowState.value;
|
|
198
|
+
if (state !== undefined && windowBlocked(state)) return ok(undefined);
|
|
199
|
+
return windowOpening.value ? openWindow(path) : navigateWindow(path);
|
|
200
|
+
}
|
|
201
|
+
|
|
108
202
|
function openWindow(path?: string): Result<void> {
|
|
109
203
|
const state = windowState.value;
|
|
110
204
|
if (state === undefined) return fail("The addon has no window. Declare window in the app module.");
|
|
111
205
|
if (!state.owner.isActive()) return fail("The addon window has closed");
|
|
206
|
+
if (windowBlocked(state)) return ok(undefined);
|
|
112
207
|
const target = path ?? windowPath.value ?? firstPath(state);
|
|
113
208
|
if (target === undefined) return fail("The addon window has no pages");
|
|
209
|
+
const previous = windowPath.value;
|
|
114
210
|
const navigated = navigateWindow(target);
|
|
115
211
|
if (!navigated.ok) return navigated;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
212
|
+
state.resumePath = undefined;
|
|
213
|
+
if (state.panel !== undefined) {
|
|
214
|
+
showWindow(state.panel);
|
|
215
|
+
return ok(undefined);
|
|
216
|
+
}
|
|
217
|
+
if (state.config.mount === "staged") {
|
|
218
|
+
if (state.opening !== undefined && target !== previous) cancelOpening(state);
|
|
219
|
+
if (state.opening === undefined) stageWindow(state);
|
|
220
|
+
return ok(undefined);
|
|
119
221
|
}
|
|
120
|
-
state.
|
|
121
|
-
|
|
222
|
+
const mounted = mountWindow(state, state.owner);
|
|
223
|
+
if (!mounted.ok) return mounted;
|
|
224
|
+
state.panel = mounted.value;
|
|
225
|
+
showWindow(mounted.value);
|
|
122
226
|
return ok(undefined);
|
|
123
227
|
}
|
|
124
228
|
|
|
125
229
|
function closeWindow() {
|
|
126
|
-
windowState.value
|
|
127
|
-
|
|
230
|
+
const state = windowState.value;
|
|
231
|
+
if (state !== undefined) {
|
|
232
|
+
state.resumePath = undefined;
|
|
233
|
+
hideWindow(state);
|
|
234
|
+
}
|
|
128
235
|
}
|
|
129
236
|
|
|
130
237
|
/**
|
|
@@ -154,7 +261,7 @@ export const useWindow = defineStore("kumi/window", () => {
|
|
|
154
261
|
}
|
|
155
262
|
|
|
156
263
|
function toggle(this: void, path?: string): Result<void> {
|
|
157
|
-
if (windowOpen.value && (path === undefined || path === windowPath.value)) {
|
|
264
|
+
if ((windowOpen.value || windowOpening.value) && (path === undefined || path === windowPath.value)) {
|
|
158
265
|
closeWindow();
|
|
159
266
|
return ok(undefined);
|
|
160
267
|
}
|
|
@@ -162,10 +269,10 @@ export const useWindow = defineStore("kumi/window", () => {
|
|
|
162
269
|
}
|
|
163
270
|
|
|
164
271
|
function navigate(this: void, path: string): Result<void> {
|
|
165
|
-
return
|
|
272
|
+
return navigateSettings(path);
|
|
166
273
|
}
|
|
167
274
|
|
|
168
|
-
return { isOpen: readonly(windowOpen), path: readonly(windowPath), pages, open, close, toggle, navigate };
|
|
275
|
+
return { isOpen: readonly(windowOpen), isOpening: readonly(windowOpening), path: readonly(windowPath), pages, open, close, toggle, navigate };
|
|
169
276
|
});
|
|
170
277
|
|
|
171
278
|
/** Inside a HUD view: refresh it now, or read the size of one physical pixel. */
|
|
@@ -202,7 +309,10 @@ function mountUi(id: string, ui: ModuleUi, scope: RuntimeScope): Result<void> {
|
|
|
202
309
|
return fail("Module " + id + ": window.routes must be the router from @kumi/routes");
|
|
203
310
|
}
|
|
204
311
|
if (!router.ok) return fail("Module " + id + ": " + router.reason);
|
|
205
|
-
|
|
312
|
+
const state: WindowState = { config: ui.window, router: router.value, owner: scope };
|
|
313
|
+
const combat = installWindowCombat(state, context.events);
|
|
314
|
+
if (!combat.ok) return combat;
|
|
315
|
+
windowState.value = state;
|
|
206
316
|
const released = scope.onDispose(() => {
|
|
207
317
|
closeWindow();
|
|
208
318
|
windowState.value = undefined;
|