@defold-typescript/types 0.21.0 → 0.22.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/index.d.ts CHANGED
@@ -87,6 +87,11 @@ export {
87
87
  htmlToDocText,
88
88
  renderDocComment,
89
89
  } from "./src/doc-comment";
90
+ export {
91
+ defineEditorScript,
92
+ type EditorCommand,
93
+ type EditorScriptModule,
94
+ } from "./src/editor";
90
95
  export {
91
96
  type EmitOptions,
92
97
  emitDeclarations,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/editor.ts ADDED
@@ -0,0 +1,75 @@
1
+ // Editor scripts are loaded by the Defold *editor*, not the runtime engine: the
2
+ // editor `require`s the emitted chunk and reads the hooks table it returns. That
3
+ // makes them a fourth, disjoint script kind — lowered to a chunk-level
4
+ // `return <hooks table>` rather than the runtime kinds' flat top-level globals.
5
+ //
6
+ // This is the keystone surface only. The full typed `editor.*` global
7
+ // (`get`/`transact`/`command` + the editor-VM `http`/`json`/`zip`) and the
8
+ // per-kind API walls are a later slice, so a command's `run`/`active` receive a
9
+ // loosely-typed opts bag for now.
10
+
11
+ /**
12
+ * A single command an editor script contributes: a label, the editor UI
13
+ * locations it appears in (e.g. `"Edit"`, `"Assets"`, `"Outline"`, `"View"`),
14
+ * and optional `active`/`run` hooks the editor calls with a command-context bag.
15
+ */
16
+ export interface EditorCommand {
17
+ /** Menu/label text shown for the command. */
18
+ label: string;
19
+ /** Editor UI locations the command is offered in. */
20
+ locations: string[];
21
+ /**
22
+ * Declares the command's context arguments; the editor passes the resolved
23
+ * values to `active`/`run`. Loosely typed until the `editor.*` slice lands.
24
+ */
25
+ query?: Record<string, unknown>;
26
+ /**
27
+ * Called to decide whether the command is currently enabled. Omit to always
28
+ * enable. The opts bag is loosely typed until the `editor.*` slice lands.
29
+ */
30
+ active?: (opts: Record<string, unknown>) => boolean;
31
+ /**
32
+ * Called when the command is invoked. The opts bag is loosely typed until the
33
+ * `editor.*` slice lands.
34
+ */
35
+ run?: (opts: Record<string, unknown>) => void;
36
+ }
37
+
38
+ /**
39
+ * The hooks table an editor script returns. Every hook is optional; the editor
40
+ * calls the ones present. Only the keystone hooks are typed here.
41
+ */
42
+ export interface EditorScriptModule {
43
+ /** Returns the commands this script contributes to the editor. */
44
+ get_commands?: () => EditorCommand[];
45
+ /** Returns language-server descriptors this script contributes. */
46
+ get_language_servers?: () => unknown[];
47
+ }
48
+
49
+ /**
50
+ * Type an editor script's hooks table. At runtime this is an identity function —
51
+ * it returns `module` unchanged; its only job is typing. The transpiler's
52
+ * `editor-script-erasure` pass rewrites the top-level `export default
53
+ * defineEditorScript({...})` into a chunk-level `return { ... }` (the shape the
54
+ * editor loads) and erases this import — zero runtime cost.
55
+ *
56
+ * @param module - the editor-script hooks table to type and return.
57
+ * @returns the same `module` object, now typed (identity at runtime).
58
+ * @example
59
+ * ```ts
60
+ * export default defineEditorScript({
61
+ * get_commands: () => [
62
+ * { label: "Say Hi", locations: ["Edit"], run: () => print("hi") },
63
+ * ],
64
+ * });
65
+ * ```
66
+ */
67
+ export function defineEditorScript<T extends EditorScriptModule>(
68
+ // Intersecting the non-module keys with `never` rejects an unknown hook key on
69
+ // a fresh object literal, while the `T` return keeps the call an identity over
70
+ // its exact argument type (a bare `<T extends ...>` would silently absorb the
71
+ // extra key into `T` and accept it).
72
+ module: T & Record<Exclude<keyof T, keyof EditorScriptModule>, never>,
73
+ ): T {
74
+ return module;
75
+ }
package/src/index.ts CHANGED
@@ -37,6 +37,11 @@ export {
37
37
  htmlToDocText,
38
38
  renderDocComment,
39
39
  } from "./doc-comment";
40
+ export {
41
+ defineEditorScript,
42
+ type EditorCommand,
43
+ type EditorScriptModule,
44
+ } from "./editor";
40
45
  export {
41
46
  type EmitOptions,
42
47
  emitDeclarations,