@overmvp/kumi 0.1.0 → 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/README.md +59 -6
- package/builder/css-v1.mjs +54 -1
- package/builder/css-v1.test.mjs +40 -0
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +180 -8
- package/builder/src/main.rs +19 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +93 -0
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +9 -2
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +2 -2
- package/src/css-tokens.ts +16 -11
- package/src/css-v1.ts +10 -0
- package/src/elements.ts +26 -0
- package/src/frame-scheduler.ts +3 -1
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +8 -5
- package/src/module-ui.ts +147 -0
- package/src/module.ts +42 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +28 -7
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/state/index.ts +6 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store.ts +2 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/_tokens.scss +12 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +219 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +36 -0
- package/wow/app-ui.ts +221 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +40 -6
- package/wow/css-surfaces.ts +229 -24
- package/wow/cursor.ts +45 -0
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +18 -4
- package/wow/layout-view.ts +26 -14
- package/wow/locale-font.ts +15 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +33 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/view.ts +201 -83
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
package/builder/src/routes.rs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
use std::collections::BTreeMap;
|
|
2
2
|
use std::fs;
|
|
3
3
|
use std::io;
|
|
4
|
-
use std::path::{
|
|
4
|
+
use std::path::{Path, PathBuf};
|
|
5
|
+
|
|
6
|
+
pub const SOURCE_DIRECTORY: &str = "src/app/routes";
|
|
5
7
|
|
|
6
8
|
fn files(root: &Path, dir: &Path, found: &mut Vec<PathBuf>) -> io::Result<()> {
|
|
7
9
|
for entry in fs::read_dir(dir)? {
|
|
@@ -39,23 +41,18 @@ fn slash(path: &Path) -> Result<String, Box<dyn std::error::Error>> {
|
|
|
39
41
|
|
|
40
42
|
pub fn generate(
|
|
41
43
|
workspace: &Path,
|
|
42
|
-
root: &Path,
|
|
43
44
|
output: &Path,
|
|
44
45
|
check: bool,
|
|
45
46
|
) -> Result<(), Box<dyn std::error::Error>> {
|
|
46
|
-
let base =
|
|
47
|
-
|
|
48
|
-
.map_err(|_| "The route directory must be inside the workspace")?;
|
|
49
|
-
if base
|
|
50
|
-
.components()
|
|
51
|
-
.any(|part| !matches!(part, Component::Normal(_)))
|
|
52
|
-
{
|
|
53
|
-
return Err(
|
|
54
|
-
"The route directory must use a workspace-relative path without parent segments".into(),
|
|
55
|
-
);
|
|
56
|
-
}
|
|
47
|
+
let base = Path::new(SOURCE_DIRECTORY);
|
|
48
|
+
let root = workspace.join(base);
|
|
57
49
|
let mut found = Vec::new();
|
|
58
|
-
files(root, root, &mut found)
|
|
50
|
+
files(&root, &root, &mut found).map_err(|error| {
|
|
51
|
+
io::Error::new(
|
|
52
|
+
error.kind(),
|
|
53
|
+
format!("Cannot discover routes in {}: {error}", root.display()),
|
|
54
|
+
)
|
|
55
|
+
})?;
|
|
59
56
|
found.sort();
|
|
60
57
|
let mut routes = BTreeMap::new();
|
|
61
58
|
let mut pages = Vec::new();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
local function setupStoreView(fields, accessors)
|
|
2
|
+
return setmetatable(fields, {
|
|
3
|
+
__index = function(_, key)
|
|
4
|
+
local accessor = accessors[key]
|
|
5
|
+
if accessor ~= nil then return (accessor.get()) end
|
|
6
|
+
end,
|
|
7
|
+
__newindex = function(store, key, value)
|
|
8
|
+
local accessor = accessors[key]
|
|
9
|
+
if accessor == nil then
|
|
10
|
+
rawset(store, key, value)
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
local write = accessor.set
|
|
14
|
+
if write == nil then error("Cannot assign readonly store field " .. tostring(key), 2) end
|
|
15
|
+
write(value)
|
|
16
|
+
end,
|
|
17
|
+
})
|
|
18
|
+
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
faac38b892cdbd3155b8fb05608b1e76e561bb056076bfad110ee59f477c30ca
|
package/builder/src/ts-lower.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve } from "node:path";
|
|
|
5
5
|
export const signalIntrinsic = {
|
|
6
6
|
file: "src/signal-kernel.ts",
|
|
7
7
|
module: "src/signal-kernel",
|
|
8
|
-
operation: "
|
|
8
|
+
operation: "SignalFactoryV3",
|
|
9
9
|
abi: "createSignalFactory\tno-self\t3\tscalar",
|
|
10
10
|
fingerprint: readFileSync(new URL("./signal-kernel.fingerprint", import.meta.url), "utf8").trim(),
|
|
11
11
|
};
|
|
@@ -46,7 +46,7 @@ export function lowerSignalFactory(ts, program, sdkRoot, input = resolve(sdkRoot
|
|
|
46
46
|
const printer = ts.createPrinter({ removeComments: true, newLine: ts.NewLineKind.LineFeed });
|
|
47
47
|
const fingerprint = sha256(printer.printFile(file));
|
|
48
48
|
if (fingerprint !== signalIntrinsic.fingerprint) {
|
|
49
|
-
invalid(declaration, `
|
|
49
|
+
invalid(declaration, `SignalFactoryV3 source changed (${fingerprint}); review the native lowering`);
|
|
50
50
|
}
|
|
51
51
|
const source = sha256(file.text);
|
|
52
52
|
const start = file.getLineAndCharacterOfPosition(declaration.getStart(file));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
local function wowReadable(value)
|
|
2
|
+
local secret = issecretvalue
|
|
3
|
+
if secret ~= nil and secret(value) == true then return nil end
|
|
4
|
+
return value
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
local function wowReadableSecond(_, value)
|
|
8
|
+
local secret = issecretvalue
|
|
9
|
+
if secret ~= nil and secret(value) == true then return nil end
|
|
10
|
+
return value
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
local function wowReadableThird(_, _, value)
|
|
14
|
+
local secret = issecretvalue
|
|
15
|
+
if secret ~= nil and secret(value) == true then return nil end
|
|
16
|
+
return value
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
local function wowOptionalReadable(read, ...)
|
|
20
|
+
if read == nil then return nil end
|
|
21
|
+
return wowReadable((read(...)))
|
|
22
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { compileCssDeclarations } from "./css-v1.mjs";
|
|
2
|
+
import { assertMediaProperties, compareStyleStates, parseLocalStyleSelector, parseMediaQuery } from "./style-states.mjs";
|
|
3
|
+
|
|
4
|
+
function declarations(rule) {
|
|
5
|
+
return rule.nodes.filter(node => {
|
|
6
|
+
if (node.type === "decl") return true;
|
|
7
|
+
if (node.type === "comment") return false;
|
|
8
|
+
throw node.error("Expected a style declaration");
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function readStyleBreakpoints(root) {
|
|
13
|
+
const rules = root.nodes.filter(node => node.type !== "comment");
|
|
14
|
+
if (rules.length !== 1 || rules[0].type !== "rule" || rules[0].selector !== ":export") {
|
|
15
|
+
throw root.error("Expected one :export rule for style breakpoints");
|
|
16
|
+
}
|
|
17
|
+
const names = new Set();
|
|
18
|
+
const widths = new Map();
|
|
19
|
+
for (const { prop, value } of declarations(rules[0])) {
|
|
20
|
+
const width = Number(value);
|
|
21
|
+
if (!/^[a-z][a-zA-Z0-9]*$/u.test(prop) || !/^\d+$/u.test(value) || !Number.isSafeInteger(width)) {
|
|
22
|
+
throw rules[0].error("Expected a named breakpoint with a nonnegative integer width", { word: prop });
|
|
23
|
+
}
|
|
24
|
+
if (widths.has(width) || names.has(prop)) throw rules[0].error(`Duplicate breakpoint ${prop}`, { word: prop });
|
|
25
|
+
names.add(prop);
|
|
26
|
+
widths.set(width, prop);
|
|
27
|
+
}
|
|
28
|
+
if (widths.get(0) !== "base") throw rules[0].error("The base breakpoint must be 0");
|
|
29
|
+
return widths;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function compileLocalStyleModule(root, breakpoints) {
|
|
33
|
+
const classes = Object.create(null);
|
|
34
|
+
const rules = new Map();
|
|
35
|
+
const states = new Map();
|
|
36
|
+
const media = new Map();
|
|
37
|
+
|
|
38
|
+
function classFor(name) {
|
|
39
|
+
return classes[name] ??= { className: name };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function compileRule(node, query) {
|
|
43
|
+
if (node.type === "comment") return;
|
|
44
|
+
if (node.type !== "rule") throw node.error("Expected a local style rule");
|
|
45
|
+
const contents = declarations(node);
|
|
46
|
+
for (const selector of node.selectors) {
|
|
47
|
+
let selected;
|
|
48
|
+
try { selected = parseLocalStyleSelector(selector); }
|
|
49
|
+
catch (error) { throw node.error(error.message, { word: selector }); }
|
|
50
|
+
const { name, when } = selected;
|
|
51
|
+
if (query !== undefined) {
|
|
52
|
+
if (when.length !== 0) throw node.error("Media queries require a plain local class");
|
|
53
|
+
assertMediaProperties(contents);
|
|
54
|
+
if (!media.has(name)) media.set(name, []);
|
|
55
|
+
media.get(name).push({ when: query, style: compileCssDeclarations(contents) });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const key = name + ":" + when.join(":");
|
|
60
|
+
if (!rules.has(key)) rules.set(key, { name, when, contents: new Map() });
|
|
61
|
+
const merged = rules.get(key).contents;
|
|
62
|
+
for (const declaration of contents) {
|
|
63
|
+
// Preserve the last declaration's position relative to shorthands.
|
|
64
|
+
merged.delete(declaration.prop);
|
|
65
|
+
merged.set(declaration.prop, declaration);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const node of root.nodes) {
|
|
71
|
+
if (node.type !== "atrule") {
|
|
72
|
+
compileRule(node);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (node.name !== "media" || node.nodes === undefined) throw node.error("Expected a local style rule or media block");
|
|
76
|
+
let query;
|
|
77
|
+
try { query = parseMediaQuery(node.params, breakpoints); }
|
|
78
|
+
catch (error) { throw node.error(error.message); }
|
|
79
|
+
for (const child of node.nodes) compileRule(child, query);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const { name, when, contents } of rules.values()) {
|
|
83
|
+
const style = compileCssDeclarations([...contents.values()], { state: when.length !== 0 });
|
|
84
|
+
if (when.length === 0) Object.assign(classFor(name), style);
|
|
85
|
+
else {
|
|
86
|
+
if (!states.has(name)) states.set(name, []);
|
|
87
|
+
states.get(name).push({ when, paint: style });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const [name, variants] of states) classFor(name).stateStyles = variants.sort(compareStyleStates);
|
|
91
|
+
for (const [name, variants] of media) classFor(name).mediaStyles = variants;
|
|
92
|
+
return classes;
|
|
93
|
+
}
|
package/config.ts
CHANGED
|
@@ -1,17 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Types for `kumi.config.ts`. Write the config as a plain object:
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import type { KumiConfig } from "@overmvp/kumi/config";
|
|
6
|
+
*
|
|
7
|
+
* export default {
|
|
8
|
+
* addon: { name: "MyAddon", title: "My Addon", savedVariables: "MyAddonDB" },
|
|
9
|
+
* } satisfies KumiConfig;
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface KumiConfig {
|
|
13
|
+
/** The main addon. Kumi writes its TOC from these fields. */
|
|
14
|
+
readonly addon: AddonConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Optional parts that players turn on or off in the addon list, keyed by plugin ID
|
|
17
|
+
* (lowercase letters, digits and dashes). Each plugin is built as its own addon folder, `<name>_<id>`.
|
|
18
|
+
*/
|
|
19
|
+
readonly plugins?: Readonly<Record<string, PluginConfig>>;
|
|
20
|
+
/** Whether turning a plugin on or off applies to the current character or to every character. Defaults to `"account"`. */
|
|
21
|
+
readonly pluginState?: "account" | "character";
|
|
6
22
|
}
|
|
7
23
|
|
|
8
|
-
export interface
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
export interface AddonConfig {
|
|
25
|
+
/** Folder and TOC name: a letter followed by letters, digits, `_` or `-`. */
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** The title shown in the addon list. */
|
|
28
|
+
readonly title: string;
|
|
29
|
+
readonly notes?: string;
|
|
30
|
+
readonly author?: string;
|
|
31
|
+
readonly version?: string;
|
|
32
|
+
/** A texture inside the addon folder, such as `Assets/Art/Icon.tga`. Plugins reuse it. */
|
|
33
|
+
readonly icon?: string;
|
|
34
|
+
/** Interface numbers per client. `kumi build --target` picks one. Kumi has defaults for both clients. */
|
|
35
|
+
readonly interface?: { readonly retail?: number | readonly number[]; readonly forever?: number | readonly number[] };
|
|
36
|
+
/** Account-wide SavedVariables global. Persisted stores save under their ID here unless they pass a storage. */
|
|
37
|
+
readonly savedVariables?: string;
|
|
38
|
+
/** Per-character SavedVariables global. */
|
|
39
|
+
readonly savedVariablesPerCharacter?: string;
|
|
40
|
+
/** Addons that load before this one when they are installed. */
|
|
41
|
+
readonly optionalDependencies?: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PluginConfig {
|
|
45
|
+
/** The plugin's module file under `src`, for example `src/modules/history/history.module.ts`. */
|
|
46
|
+
readonly module: string;
|
|
47
|
+
/** The name of the exported `@Module` class. Needed only when the file exports more than one module. */
|
|
48
|
+
readonly export?: string;
|
|
49
|
+
/** The plugin's name in the addon list and in `usePlugins()`. */
|
|
50
|
+
readonly title: string;
|
|
51
|
+
readonly notes?: string;
|
|
52
|
+
/**
|
|
53
|
+
* `"startup"` (default): WoW loads the plugin with the addon while it is enabled.
|
|
54
|
+
* `"demand"`: the plugin loads the first time the addon calls `load()` for it.
|
|
55
|
+
*/
|
|
56
|
+
readonly load?: "startup" | "demand";
|
|
57
|
+
/** Whether the plugin starts enabled on a fresh install. Defaults to `true`. */
|
|
58
|
+
readonly enabled?: boolean;
|
|
17
59
|
}
|
package/eslint.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Kumi's project rules: the layer order inside a feature, public module APIs and the WoW boundary.
|
|
2
|
+
//
|
|
3
|
+
// import ts from "@typescript-eslint/eslint-plugin";
|
|
4
|
+
// import parser from "@typescript-eslint/parser";
|
|
5
|
+
// import { kumiRules } from "<kumi package>/eslint.mjs";
|
|
6
|
+
// export default kumiRules({ parser, plugin: ts });
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
|
|
9
|
+
const sdkPackage = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).name;
|
|
10
|
+
|
|
11
|
+
const NATIVE_NAMES = ["api", "readableApi", "rawField", "setRawField", "createFrame", "reveal", "isSecret", "savedVariablesStorage"];
|
|
12
|
+
const GAME_GLOBALS = ["_G", "CreateFrame", "UIParent", "GameTooltip", "InCombatLockdown", "GetTime", "GetMoney", "GetCursorInfo",
|
|
13
|
+
"ClearCursor", "C_Container", "C_Item", "C_Spell", "C_SpellBook", "C_ToyBox", "C_AddOns", "C_Timer", "SlashCmdList", "geterrorhandler"];
|
|
14
|
+
|
|
15
|
+
const messages = {
|
|
16
|
+
deep: "Import Kumi through its @kumi/* paths. Deep package imports skip the project's rules.",
|
|
17
|
+
native: "Call WoW in the feature's api/ layer. Other layers use the api functions, services or hooks.",
|
|
18
|
+
module: "Use another feature through its <feature>.module.ts file, its public API.",
|
|
19
|
+
decorators: "Declare modules with @Module and services with @Injectable.",
|
|
20
|
+
shared: "Shared code is reusable: it does not import app or feature code.",
|
|
21
|
+
api: "api/ wraps WoW calls. It takes plain values and returns plain values; it does not import services, stores or UI.",
|
|
22
|
+
services: "services/ hold logic. They use the feature's api/ and never stores or UI.",
|
|
23
|
+
model: "Stores call services, never api/ directly, and do not import UI.",
|
|
24
|
+
ui: "Components read stores and render. Call services and WoW through stores.",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const deepImports = { group: [sdkPackage + "/*", "**/node_modules/**"], message: messages.deep };
|
|
28
|
+
const nativeImport = { name: "@kumi/wow", importNames: NATIVE_NAMES, message: messages.native };
|
|
29
|
+
const generated = { name: "@kumi/wow-generated", message: messages.native };
|
|
30
|
+
const legacyModule = { name: "@kumi/core", importNames: ["defineModule"], message: messages.decorators };
|
|
31
|
+
// `../other/model/x` from a module file or `../../other/ui/x` from a layer. `shared/` and the own layers stay allowed.
|
|
32
|
+
const otherFeatureDeep = { regex: "^(?:\\.\\./)+(?!shared/|app/)[^/.][^/]*/(?:api|services|model|ui|widgets)(?:/|$)", message: messages.module };
|
|
33
|
+
|
|
34
|
+
function restrict(patterns, native) {
|
|
35
|
+
const paths = [legacyModule];
|
|
36
|
+
if (!native) paths.push(nativeImport, generated);
|
|
37
|
+
return ["error", { paths, patterns: [deepImports, ...patterns] }];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Flat ESLint config for a Kumi project. Pass the project's TypeScript ESLint parser and plugin. */
|
|
41
|
+
export function kumiRules({ parser, plugin, files = ["src/**/*.{ts,tsx}"] }) {
|
|
42
|
+
const layer = (folder, patterns, native = false) => ({
|
|
43
|
+
files: ["src/modules/*/" + folder + "/**/*.{ts,tsx}"],
|
|
44
|
+
rules: { "no-restricted-imports": restrict(patterns, native) },
|
|
45
|
+
});
|
|
46
|
+
return [{
|
|
47
|
+
files,
|
|
48
|
+
languageOptions: { parser },
|
|
49
|
+
plugins: { "@typescript-eslint": plugin },
|
|
50
|
+
rules: {
|
|
51
|
+
"no-debugger": "error",
|
|
52
|
+
"no-restricted-globals": ["error", ...GAME_GLOBALS.map(name => ({ name, message: messages.native }))],
|
|
53
|
+
"no-restricted-imports": restrict([otherFeatureDeep], false),
|
|
54
|
+
"no-restricted-syntax": ["error", {
|
|
55
|
+
selector: "CallExpression[callee.type='MemberExpression'][callee.property.name=/^(CreateFrame|CreateTexture|SetTexture|SetAttribute|SetVertexColor|SetPoint|SetScript)$/]",
|
|
56
|
+
message: "Declare frames, textures and scripts in JSX, or use a typed SDK helper.",
|
|
57
|
+
}],
|
|
58
|
+
"@typescript-eslint/consistent-type-imports": "error",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
layer("api", [{ regex: "^(?:\\.\\./)+(?:services|model|ui|widgets)(?:/|$)", message: messages.api }, otherFeatureDeep], true),
|
|
62
|
+
layer("services", [{ regex: "^(?:\\.\\./)+(?:model|ui|widgets)(?:/|$)", message: messages.services }, otherFeatureDeep]),
|
|
63
|
+
layer("model", [{ regex: "^(?:\\.\\./)+(?:api|ui|widgets)(?:/|$)", message: messages.model }, otherFeatureDeep]),
|
|
64
|
+
layer("ui", [{ regex: "^(?:\\.\\./)+(?:api|services|widgets)(?:/|$)", message: messages.ui }, otherFeatureDeep]),
|
|
65
|
+
layer("widgets", [{ regex: "^(?:\\.\\./)+(?:api|services)(?:/|$)", message: messages.ui }, otherFeatureDeep]),
|
|
66
|
+
{
|
|
67
|
+
files: ["src/shared/**/*.{ts,tsx}"],
|
|
68
|
+
rules: { "no-restricted-imports": restrict([{ regex: "^(?:\\.\\./)+(?:app|modules)(?:/|$)", message: messages.shared }], false) },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
files: ["src/shared/api/**/*.{ts,tsx}"],
|
|
72
|
+
rules: { "no-restricted-imports": restrict([{ regex: "^(?:\\.\\./)+(?:app|modules)(?:/|$)", message: messages.shared }], true) },
|
|
73
|
+
}];
|
|
74
|
+
}
|
package/form/index.ts
CHANGED
|
@@ -41,11 +41,13 @@ export type FormValueFields<State extends object> = {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export type FormValueStore<State extends object> = Pick<StateStore<State>, "field" | "patch">;
|
|
44
|
+
export type FormValueCommit<State extends object> = (this: void, patch: Partial<State>) => Result<void>;
|
|
44
45
|
export type FormValidationMode = "onChange" | "onBlur" | "onSubmit";
|
|
45
46
|
|
|
46
47
|
export type FormValueOptions<State extends object> =
|
|
47
|
-
| { values?: FormValuesSource<State> | FormValueStore<State>; fields?: never }
|
|
48
|
-
| {
|
|
48
|
+
| { values?: FormValuesSource<State> | FormValueStore<State>; fields?: never; commit?: never }
|
|
49
|
+
| { values: Readonly<State>; commit: FormValueCommit<State>; fields?: never }
|
|
50
|
+
| { fields: FormValueFields<State>; values?: never; commit?: never };
|
|
49
51
|
|
|
50
52
|
export interface FormBinding<Value, Name extends string = string> {
|
|
51
53
|
readonly name: Name;
|
|
@@ -78,7 +80,7 @@ export function createForm<State extends object>(defaults: State, validate?: For
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
export function useForm<State extends object>({ defaultValues, validator, validate, protect = direct, mode = "onBlur",
|
|
81
|
-
values: source, fields: bindings }: FormOptions<State>) {
|
|
83
|
+
values: source, fields: bindings, commit }: FormOptions<State>) {
|
|
82
84
|
const initial = Object.fromEntries(Object.entries(defaultValues).filter(([, value]) => value != null)) as State;
|
|
83
85
|
const issues = ref<readonly FormIssue[]>([]);
|
|
84
86
|
let validationIssues: readonly FormIssue[] = [];
|
|
@@ -101,11 +103,13 @@ export function useForm<State extends object>({ defaultValues, validator, valida
|
|
|
101
103
|
|
|
102
104
|
const keys = Object.keys(initial) as Key<State>[];
|
|
103
105
|
const writable = new Set(keys);
|
|
104
|
-
const store = source && "patch" in source ? source : undefined;
|
|
105
|
-
const adapter = source && "get" in source ? source : undefined;
|
|
106
|
+
const store = commit === undefined && source && "patch" in source ? source : undefined;
|
|
107
|
+
const adapter = commit === undefined && source && "get" in source ? source : undefined;
|
|
108
|
+
const save = commit ?? store?.patch;
|
|
106
109
|
const linked = source !== undefined || bindings !== undefined;
|
|
107
110
|
|
|
108
111
|
function read<K extends Key<State>>(key: K): State[K] | undefined {
|
|
112
|
+
if (commit !== undefined) return source[key];
|
|
109
113
|
if (store) return store.field(key).value;
|
|
110
114
|
return bindings ? bindings[key].get() : adapter?.get(key);
|
|
111
115
|
}
|
|
@@ -226,7 +230,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
|
|
|
226
230
|
return next.length === 0;
|
|
227
231
|
}
|
|
228
232
|
|
|
229
|
-
function applyStore(
|
|
233
|
+
function applyStore(commitValues: FormValueCommit<State>, patch: Partial<State>, changed: readonly Key<State>[]) {
|
|
230
234
|
if (validateSnapshot) {
|
|
231
235
|
// Validate the proposed saved values. An unrelated invalid draft stays local.
|
|
232
236
|
const candidate = { ...initial, ...patch };
|
|
@@ -245,7 +249,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
|
|
|
245
249
|
return fail(errors[0].message);
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
|
-
const saved =
|
|
252
|
+
const saved = commitValues(patch);
|
|
249
253
|
if (!saved.ok) {
|
|
250
254
|
for (const key of changed) {
|
|
251
255
|
field(key);
|
|
@@ -270,7 +274,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
|
|
|
270
274
|
if (existing) return existing.field as FormField<State[K]>;
|
|
271
275
|
const current = () => readCurrent(key);
|
|
272
276
|
const cached = ref<State[K]>(current());
|
|
273
|
-
const draft =
|
|
277
|
+
const draft = save ? ref<State[K] | undefined>(undefined) : undefined;
|
|
274
278
|
const value = linked ? new LinkedField(cached, () => {
|
|
275
279
|
const edited = draft?.value;
|
|
276
280
|
if (edited != null) return edited;
|
|
@@ -349,7 +353,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
|
|
|
349
353
|
}
|
|
350
354
|
|
|
351
355
|
function applyValues(patch: Partial<State>, changed: readonly Key<State>[]): Result<void> {
|
|
352
|
-
if (
|
|
356
|
+
if (save) return applyStore(save, patch, changed);
|
|
353
357
|
if (linked && changed.length > 1) return fail("Atomic edits require a reactive form store");
|
|
354
358
|
for (const key of changed) {
|
|
355
359
|
field(key);
|
|
@@ -414,8 +418,8 @@ export function useForm<State extends object>({ defaultValues, validator, valida
|
|
|
414
418
|
}
|
|
415
419
|
|
|
416
420
|
function reset(): Result<void> {
|
|
417
|
-
if (
|
|
418
|
-
const saved = applyStore(
|
|
421
|
+
if (save) {
|
|
422
|
+
const saved = applyStore(save, initial, keys);
|
|
419
423
|
if (!saved.ok) return saved;
|
|
420
424
|
for (const state of fields.values()) state.clear();
|
|
421
425
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overmvp/kumi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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" },
|
|
@@ -8,17 +8,21 @@
|
|
|
8
8
|
"engines": { "node": ">=24" },
|
|
9
9
|
"bin": { "kumi": "scripts/kumi-cli.mjs" },
|
|
10
10
|
"files": [
|
|
11
|
-
"animation", "builder", "config.ts", "form", "motion", "router", "src", "state", "styles", "translate", "utils", "validate", "wow",
|
|
12
|
-
"scripts/kumi-cli.mjs", "scripts/link-addons.mjs", "templates/addon"
|
|
11
|
+
"animation", "builder", "config.ts", "eslint.mjs", "form", "motion", "router", "src", "state", "styles", "translate", "utils", "validate", "wow",
|
|
12
|
+
"scripts/kumi-cli.mjs", "scripts/addon-project.mjs", "scripts/addon-build.mjs", "scripts/link-addons.mjs", "templates/addon"
|
|
13
13
|
],
|
|
14
14
|
"publishConfig": { "access": "public" },
|
|
15
15
|
"scripts": {
|
|
16
|
-
"check": "tsc -p tsconfig.json
|
|
16
|
+
"check": "tsc -p tsconfig.json",
|
|
17
17
|
"check:starter": "node scripts/check-starter.mjs",
|
|
18
|
-
"test:lua": "node scripts/lua-tests.mjs"
|
|
18
|
+
"test:lua": "node scripts/lua-tests.mjs",
|
|
19
|
+
"test:unit": "node --import ./tests/support/ts-resolve.mjs --test builder/*.test.mjs tests/*.test.mjs scripts/*.test.mjs"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"postcss": "8.5.6",
|
|
23
|
+
"sass": "1.108.2"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
|
-
"typescript": "6.0.2"
|
|
22
|
-
"typescript-to-lua": "1.37.1"
|
|
26
|
+
"typescript": "6.0.2"
|
|
23
27
|
}
|
|
24
28
|
}
|
package/router/index.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { UIElement } from "../src/elements";
|
|
2
2
|
import { fail, ok } from "@kumi/core";
|
|
3
|
-
import { ownedMap } from "../src/owned-collections";
|
|
3
|
+
import { ownedArray, ownedMap } from "../src/owned-collections";
|
|
4
4
|
import { collectRoutes, renderRoute, type RouteLayoutProps } from "./routes";
|
|
5
5
|
|
|
6
6
|
export type { RouteContext, RouteLayoutProps } from "./routes";
|
|
7
|
+
export { useNavigation, withNavigation, type Navigation } from "./navigation";
|
|
8
|
+
export { RouterView, onActivated, onDeactivated, withRouterHost, type RoutePage, type RouterHost } from "./router-view";
|
|
7
9
|
|
|
8
10
|
type PageFactory<Context> = (this: void, context: Context) => UIElement;
|
|
9
|
-
|
|
11
|
+
/** A page file: its default export renders the page. `title` and `order` describe its tab. */
|
|
12
|
+
type PageModule = { default: PageFactory<never> | { render: PageFactory<never> }; title?: string; order?: number };
|
|
10
13
|
type ContextReader<Definition> = Definition extends PageFactory<infer Context> ? PageFactory<Context>
|
|
11
14
|
: Definition extends { render: PageFactory<infer Context> } ? PageFactory<Context> : never;
|
|
12
15
|
type PageContext<Page extends PageModule> = ContextReader<Page["default"]> extends PageFactory<infer Context> ? Context : never;
|
|
@@ -20,16 +23,20 @@ export function createRouter<Page extends PageModule, Path extends string = stri
|
|
|
20
23
|
const registry = collectRoutes(files);
|
|
21
24
|
if (!registry.ok) return registry;
|
|
22
25
|
const routes = ownedMap<Path, NonNullable<ReturnType<typeof registry.value.get>>>();
|
|
26
|
+
const pages = ownedArray<{ readonly path: Path; readonly title?: string; readonly order?: number }>();
|
|
23
27
|
const paths = files.paths ?? Array.from(registry.value.keys()) as Path[];
|
|
24
28
|
for (const path of paths) {
|
|
25
29
|
const route = registry.value.get(path);
|
|
26
30
|
if (!route || routes.has(path)) return fail(`Invalid generated route: ${path}`);
|
|
27
31
|
routes.set(path, route);
|
|
32
|
+
pages.push({ path, title: route.page.title, order: route.page.order });
|
|
28
33
|
}
|
|
29
34
|
if (routes.size !== registry.value.size) return fail("Generated routes are missing paths");
|
|
30
35
|
|
|
31
36
|
return ok({
|
|
32
37
|
entries: () => routes.entries(),
|
|
38
|
+
/** The file routes with the `title` and `order` their page files export. */
|
|
39
|
+
pages,
|
|
33
40
|
match: (path: string) => routes.get(path as Path),
|
|
34
41
|
has: (path: string): path is Path => routes.has(path as Path),
|
|
35
42
|
render(this: void, path: Path, context: PageContext<Page>) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext } from "../src/context";
|
|
2
|
+
import type { ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { fail, ok, type Protect, type Result } from "../src/result";
|
|
4
|
+
|
|
5
|
+
export interface Navigation<Path extends string = string> {
|
|
6
|
+
readonly path: ReadonlyRef<Path | undefined>;
|
|
7
|
+
navigate(this: void, path: Path): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const context = createContext<unknown>();
|
|
11
|
+
const missingNavigation = fail("Navigation requires a router context");
|
|
12
|
+
|
|
13
|
+
/** Run view setup with the navigation state of its host. */
|
|
14
|
+
export function withNavigation<Path extends string, View>(this: void, navigation: Navigation<Path>,
|
|
15
|
+
render: (this: void) => View, protect: Protect): Result<View> {
|
|
16
|
+
return context.run(navigation, render, protect);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useNavigation<Path extends string = string>(this: void): Result<Navigation<Path>> {
|
|
20
|
+
const navigation = context.use();
|
|
21
|
+
return navigation === undefined ? missingNavigation : ok(navigation as Navigation<Path>);
|
|
22
|
+
}
|