@defold-typescript/types 0.23.0 → 0.25.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.
Files changed (38) hide show
  1. package/api-signatures.json +44 -44
  2. package/api-targets.json +57 -0
  3. package/generated/editor-vm/http.d.ts +56 -0
  4. package/generated/editor-vm/json.d.ts +10 -0
  5. package/generated/editor-vm/localization.d.ts +42 -0
  6. package/generated/editor-vm/tilemap_tiles.d.ts +80 -0
  7. package/generated/editor-vm/zip.d.ts +10 -0
  8. package/generated/editor-vm/zlib.d.ts +24 -0
  9. package/generated/editor.d.ts +1092 -0
  10. package/generated/go.d.ts +22 -22
  11. package/generated/kinds/editor-script.d.ts +13 -0
  12. package/generated/kinds/gui-script.d.ts +1 -0
  13. package/generated/kinds/render-script.d.ts +1 -0
  14. package/generated/kinds/script.d.ts +1 -0
  15. package/generated/versions/defold-1.12.4/go.d.ts +22 -22
  16. package/index.d.ts +6 -0
  17. package/package.json +9 -1
  18. package/scripts/materialize-version.ts +54 -13
  19. package/scripts/regen.ts +425 -42
  20. package/scripts/signature-store-fs.ts +2 -0
  21. package/scripts/sync-api-docs.ts +82 -6
  22. package/src/api-doc.ts +58 -0
  23. package/src/core-types.ts +18 -1
  24. package/src/doc-comment.ts +21 -3
  25. package/src/editor-overloads.d.ts +33 -0
  26. package/src/editor-vm-globals.d.ts +200 -0
  27. package/src/editor-vm-types.ts +44 -0
  28. package/src/editor.ts +117 -16
  29. package/src/emit-dts.ts +292 -79
  30. package/src/engine-globals.d.ts +2 -2
  31. package/src/go-overloads.d.ts +6 -6
  32. package/src/index.ts +12 -0
  33. package/src/library-signature.ts +11 -3
  34. package/src/msg-overloads.d.ts +3 -3
  35. package/src/scene-addresses.d.ts +62 -0
  36. package/src/script-api.ts +12 -2
  37. package/src/url-parameters.ts +174 -0
  38. package/url-parameters.json +285 -0
package/src/editor.ts CHANGED
@@ -3,36 +3,137 @@
3
3
  // makes them a fourth, disjoint script kind — lowered to a chunk-level
4
4
  // `return <hooks table>` rather than the runtime kinds' flat top-level globals.
5
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.
6
+ // The typed `editor.*` global (`get`/`transact`/`command`) and the walled
7
+ // `@defold-typescript/types/editor-script` entrypoint ship alongside this file,
8
+ // as do the editor VM's own `http`/`json`/`zip`/`zlib`/`tilemap.tiles`
9
+ // libraries and the `editor.ui.*`, `editor.prefs.*`, and `localization.*`
10
+ // surfaces.
11
+
12
+ import type { Opaque } from "./core-types";
13
+
14
+ /**
15
+ * What the editor addresses a node by: either a resource path (e.g.
16
+ * `"/main/game.script"`) or an internal node id the editor hands to the script.
17
+ * This is the argument `editor.get` and the `editor.tx.*` builders take.
18
+ */
19
+ export type EditorNode = string | Opaque<"userdata">;
20
+
21
+ /**
22
+ * Declares a command's context: what the editor resolves before calling the
23
+ * command's hooks, and therefore which members its opts bag carries. Both keys
24
+ * are optional; a command that declares neither receives an empty bag.
25
+ */
26
+ export interface EditorCommandQuery {
27
+ /**
28
+ * The current selection. `type` picks the selection source, `cardinality`
29
+ * picks between the first selected item and all of them.
30
+ */
31
+ selection?: { type: "resource" | "outline"; cardinality: "one" | "many" };
32
+ /** Requests the command argument. Declared as an empty table. */
33
+ argument?: Record<string, never>;
34
+ }
35
+
36
+ /**
37
+ * The opts bag the editor populates for a command whose query is `Q` — exactly
38
+ * the members `Q` declared, and no others.
39
+ *
40
+ * Each half branches on *key presence* (`"selection" extends keyof Q`) rather
41
+ * than on the property type: an optional property is still in `keyof`, so
42
+ * presence is what separates a declared query from the erased one. The
43
+ * cardinality test is wrapped in a one-tuple so a union (or `never`) does not
44
+ * distribute across the conditional.
45
+ */
46
+ export type EditorCommandOpts<Q extends EditorCommandQuery> = ("selection" extends keyof Q
47
+ ? {
48
+ selection: [NonNullable<Q["selection"]>["cardinality"]] extends ["many"]
49
+ ? EditorNode[]
50
+ : EditorNode;
51
+ }
52
+ : Record<never, never>) &
53
+ ("argument" extends keyof Q ? { argument: Record<string, unknown> } : Record<never, never>);
10
54
 
11
55
  /**
12
56
  * A single command an editor script contributes: a label, the editor UI
13
57
  * locations it appears in (e.g. `"Edit"`, `"Assets"`, `"Outline"`, `"View"`),
14
- * and optional `active`/`run` hooks the editor calls with a command-context bag.
58
+ * and optional `active`/`run` hooks the editor calls with the context bag its
59
+ * own `query` declared.
60
+ *
61
+ * The editor calls `active`/`run` as plain functions, so they must emit no
62
+ * leading self parameter. `@noSelf` has to sit here, on the enclosing
63
+ * interface: TSTL resolves a hook's self context from its contextual signature,
64
+ * and the property-signature branch consults only this interface — it returns
65
+ * before `noImplicitSelf` or a file-level `@noSelfInFile` is ever considered.
66
+ *
67
+ * @noSelf
15
68
  */
16
- export interface EditorCommand {
69
+ export interface EditorCommand<Q extends EditorCommandQuery = EditorCommandQuery> {
17
70
  /** Menu/label text shown for the command. */
18
71
  label: string;
19
72
  /** Editor UI locations the command is offered in. */
20
73
  locations: string[];
21
74
  /**
22
75
  * Declares the command's context arguments; the editor passes the resolved
23
- * values to `active`/`run`. Loosely typed until the `editor.*` slice lands.
76
+ * values to `active`/`run` as exactly the matching opts members.
24
77
  */
25
- query?: Record<string, unknown>;
78
+ query?: Q;
26
79
  /**
27
80
  * 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.
81
+ * enable. Should be fast the editor may call it on key/mouse events.
34
82
  */
35
- run?: (opts: Record<string, unknown>) => void;
83
+ active?: (opts: EditorCommandOpts<Q>) => boolean;
84
+ /** Called when the user invokes the command. */
85
+ run?: (opts: EditorCommandOpts<Q>) => void;
86
+ }
87
+
88
+ /**
89
+ * A command as it sits in a `get_commands` list: the same shape with its query
90
+ * erased. The hooks take `never`, the one parameter type every concrete opts
91
+ * bag is assignable *from* under parameter contravariance — so a `"one"` and a
92
+ * `"many"` command coexist in a single array while each keeps its own precise
93
+ * typing at its `defineEditorCommand` call site.
94
+ */
95
+ export interface EditorCommandEntry {
96
+ /** Menu/label text shown for the command. */
97
+ label: string;
98
+ /** Editor UI locations the command is offered in. */
99
+ locations: string[];
100
+ /** Declares the command's context arguments. */
101
+ query?: EditorCommandQuery;
102
+ /** Called to decide whether the command is currently enabled. */
103
+ active?: (opts: never) => boolean;
104
+ /** Called when the user invokes the command. */
105
+ run?: (opts: never) => void;
106
+ }
107
+
108
+ /**
109
+ * Type a single editor command so its `active`/`run` hooks receive exactly the
110
+ * opts members its own `query` declared. At runtime this is an identity
111
+ * function — it returns `command` unchanged; its only job is typing, and the
112
+ * transpiler emits the table literal it wraps.
113
+ *
114
+ * @param command - the command to type and return.
115
+ * @returns the same `command`, typed as a query-erased list entry.
116
+ * @example
117
+ * ```ts
118
+ * export default defineEditorScript({
119
+ * get_commands: () => [
120
+ * defineEditorCommand({
121
+ * label: "Git History",
122
+ * locations: ["Assets"],
123
+ * query: { selection: { type: "resource", cardinality: "one" } },
124
+ * run: (opts) => print(editor.get(opts.selection, "path")),
125
+ * }),
126
+ * ],
127
+ * });
128
+ * ```
129
+ */
130
+ // The `Record<never, never>` default (not `Record<string, never>`, whose `keyof`
131
+ // is `string` and would match every presence test) gives a command that declares
132
+ // no query an empty opts bag.
133
+ export function defineEditorCommand<const Q extends EditorCommandQuery = Record<never, never>>(
134
+ command: EditorCommand<Q>,
135
+ ): EditorCommandEntry {
136
+ return command as EditorCommandEntry;
36
137
  }
37
138
 
38
139
  /**
@@ -41,7 +142,7 @@ export interface EditorCommand {
41
142
  */
42
143
  export interface EditorScriptModule {
43
144
  /** Returns the commands this script contributes to the editor. */
44
- get_commands?: () => EditorCommand[];
145
+ get_commands?: () => EditorCommandEntry[];
45
146
  /** Returns language-server descriptors this script contributes. */
46
147
  get_language_servers?: () => unknown[];
47
148
  }