@sigil-dev/types 0.9.17 → 0.9.19

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 CHANGED
@@ -1,3 +1,9 @@
1
1
  # @sigil-dev/types
2
2
 
3
- TypeScript type definitions for Sigil's compile-time primitives: `$state`, `$derived`, `$effect`, and the `Component` type.
3
+ TypeScript types for [Sigil](https://sigil.cane1712.dev): the JSX namespace and the compile-time macros `$state`, `$derived` and `$effect`, plus the `Component` type. Projects made with `sigil create` already have it; install it yourself only when setting up a project by hand.
4
+
5
+ ```sh
6
+ bun add -d @sigil-dev/types
7
+ ```
8
+
9
+ **Docs:** [sigil.cane1712.dev/docs/reference/macros](https://sigil.cane1712.dev/docs/reference/macros)
package/index.d.ts CHANGED
@@ -47,27 +47,58 @@ declare namespace $effect {
47
47
  */
48
48
  declare function $inspect(...vals: unknown[]): void;
49
49
 
50
+ /** `use={fn}`: called with the element when it is created; may return a cleanup. */
51
+ type SigilDirective = (element: any, ...args: any[]) => unknown;
52
+
50
53
  interface SigilBaseProps {
51
54
  class?: string;
52
55
  style?: React.CSSProperties | string;
53
- children?: SigilNode;
56
+ /** Anything renderable: nodes, text, numbers, arrays, nothing. */
57
+ children?: unknown;
58
+ /** Identifies an item in a list, so it is moved rather than rebuilt. */
59
+ key?: string | number;
60
+ /** `use={fn}`, `use={[fn, options]}`, or several: `use={[a, [b, options]]}`. */
61
+ use?: SigilDirective | readonly unknown[];
62
+ /** The element itself, assigned to a `$state`. */
63
+ "bind:this"?: unknown;
54
64
  bindThis?: unknown;
65
+ /** An animation played when the element appears and disappears. */
66
+ [transition: `transition:${string}`]: unknown;
67
+ [enter: `in:${string}`]: unknown;
68
+ [leave: `out:${string}`]: unknown;
55
69
  }
56
70
 
57
71
  interface SigilBindProps {
72
+ "bind:value"?: unknown;
73
+ "bind:checked"?: unknown;
74
+ "bind:group"?: unknown;
58
75
  bindValue?: string | number;
59
76
  bindChecked?: boolean;
60
77
  }
61
78
 
79
+ /**
80
+ * Sigil hands a handler the browser's own event, not a React synthetic one:
81
+ * `onClick={(e: MouseEvent) => …}`, with `currentTarget` typed as the element.
82
+ */
83
+ type NativeHandler<H> = H extends ((event: infer E) => unknown) | undefined
84
+ ? E extends React.SyntheticEvent<infer Target, infer Native>
85
+ ? ((event: Native & { currentTarget: Target }) => unknown) | undefined
86
+ : H
87
+ : H;
88
+
89
+ type NativeHandlers<T> = {
90
+ [K in keyof T]: K extends `on${string}` ? NativeHandler<T[K]> : T[K];
91
+ };
92
+
62
93
  type LowercaseHandlers<T> = {
63
94
  [K in keyof T as K extends `on${string}`
64
95
  ? Lowercase<K & string>
65
- : never]?: T[K];
96
+ : never]?: NativeHandler<T[K]>;
66
97
  };
67
98
 
68
99
  type SigilIntrinsicElements = {
69
100
  [K in keyof React.JSX.IntrinsicElements]: Omit<
70
- React.JSX.IntrinsicElements[K],
101
+ NativeHandlers<React.JSX.IntrinsicElements[K]>,
71
102
  "style" | "children"
72
103
  > &
73
104
  SigilBaseProps &
@@ -105,6 +136,14 @@ interface Window {
105
136
 
106
137
  declare namespace JSX {
107
138
  type Element = React.JSX.Element;
139
+ /**
140
+ * What may be used as a component. A Sigil component returns DOM nodes,
141
+ * text or nothing rather than a React element, so any function counts.
142
+ */
143
+ type ElementType =
144
+ | keyof IntrinsicElements
145
+ | ((props: any) => unknown)
146
+ | (new (props: any) => unknown);
108
147
  interface ElementClass extends React.JSX.ElementClass {}
109
148
  interface ElementAttributesProperty
110
149
  extends React.JSX.ElementAttributesProperty {}
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@sigil-dev/types",
3
- "description": "JSX/runtime sigil types",
4
- "version": "0.9.17",
3
+ "description": "TypeScript types for Sigil's JSX and compile-time macros ($state, $derived, $effect)",
4
+ "license": "MIT",
5
+ "homepage": "https://sigil.cane1712.dev/docs/reference/macros",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://git.cane1712.dev/sigil/sigil.git",
9
+ "directory": "packages/types"
10
+ },
11
+ "version": "0.9.19",
5
12
  "type": "module",
6
13
  "exports": {
7
14
  ".": "./index.d.ts"
package/sigil-node.d.ts CHANGED
@@ -7,5 +7,3 @@ type SigilNode =
7
7
  | undefined
8
8
  | SigilNode[]
9
9
  | JSX.Element;
10
-
11
- export type { SigilNode };