effect-ui-tsx 0.0.0-stage → 0.1.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.
@@ -0,0 +1,148 @@
1
+ import type { Component, Mount, Renderer, View } from "@effect/ui";
2
+ import type { Html } from "@effect/ui/html";
3
+ declare const actionBrand: unique symbol;
4
+ /** A message produced by a feature's own action constructors. The brand exists only in the types. */
5
+ export interface ActionMessage {
6
+ readonly _tag: string;
7
+ readonly [actionBrand]: true;
8
+ }
9
+ export type Host = Html.H<ActionMessage>;
10
+ export type Tag = keyof Html.Tags<ActionMessage>;
11
+ type EventsOf<K extends Tag> = K extends Html.ContainerTag | Html.VoidTag ? Html.EventsOf<K> : Html.SvgEvents;
12
+ type EventName<K extends Tag = Tag> = K extends Tag ? keyof EventsOf<K> & string : never;
13
+ type Listener<Payload> = View.Handler<ActionMessage, Payload> | readonly [View.Handler<ActionMessage, Payload>, View.EventOptions];
14
+ type Letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
15
+ type AttributeName = `${Exclude<Letter, "o">}${string}` | `o${Exclude<Letter, "n">}${string}`;
16
+ type ReactSvgName = "strokeWidth" | "strokeLinecap" | "strokeLinejoin" | "strokeDasharray" | "strokeDashoffset" | "strokeOpacity" | "fillOpacity" | "fillRule" | "clipRule" | "clipPath" | "fontSize" | "fontFamily" | "fontWeight" | "textAnchor" | "dominantBaseline" | "stopColor" | "stopOpacity";
17
+ type Hyphenated<Name extends string> = Name extends `${infer Head}${infer Tail}` ? `${Head extends Lowercase<Head> ? Head : `-${Lowercase<Head>}`}${Hyphenated<Tail>}` : Name;
18
+ type SvgHints = {
19
+ [Name in ReactSvgName]?: `Write ${Hyphenated<Name>} instead of ${Name}`;
20
+ };
21
+ type ElementState<K extends Tag> = (K extends "input" | "textarea" | "select" ? {
22
+ /** The field's value, set on every render. Pair it with `onInput`, or typing is undone. */
23
+ value?: string | undefined;
24
+ } : {}) & (K extends "input" ? {
25
+ checked?: boolean | undefined;
26
+ /** The value the field starts with. After that the field keeps what the user types. */
27
+ defaultValue?: string | undefined;
28
+ /** Whether the box starts checked. After that it keeps what the user chooses. */
29
+ defaultChecked?: boolean | undefined;
30
+ } : {}) & (K extends "option" ? {
31
+ selected?: boolean | undefined;
32
+ } : {}) & (K extends "details" | "dialog" ? {
33
+ open?: boolean | undefined;
34
+ } : {}) & (K extends "dialog" ? {
35
+ modal?: boolean | undefined;
36
+ } : {});
37
+ type Arguments<K extends Tag, Method extends string> = Host[K] extends {
38
+ [M in Method]: (...args: infer A) => unknown;
39
+ } ? A : never;
40
+ type NodeOf<K extends Tag> = Arguments<K, "ref">[0] extends Renderer.Ref<infer Node> ? Node : never;
41
+ type BuilderProps<K extends Tag> = {
42
+ /**
43
+ * Applies a part of a headless component to the element, which gives the element the
44
+ * attributes and handlers the part holds. A list applies several.
45
+ */
46
+ apply?: ((builder: Host[K]) => unknown) | ReadonlyArray<(builder: Host[K]) => unknown> | undefined;
47
+ /** A handle on the element's node, made with `Renderer.ref`. */
48
+ ref?: Arguments<K, "ref">[0] | undefined;
49
+ /**
50
+ * Work that needs the element's node, such as drawing a chart or moving focus: a mount made with
51
+ * `Mount.make` and issued with its args. Map its result to an action with `Mount.map`, or end
52
+ * its body with `Component.noop`. An element takes one mount.
53
+ */
54
+ onMount?: Mount.Issued<ActionMessage | Component.Noop, never, NodeOf<K>, never> | undefined;
55
+ /** The data a drag of this element carries, or `[data, options]`. */
56
+ draggable?: Arguments<K, "draggable">[0] | Arguments<K, "draggable"> | undefined;
57
+ /** Makes the element accept drops of the listed kinds. Handle them with `onDrop`. */
58
+ dropTarget?: Arguments<K, "dropTarget">[0] | undefined;
59
+ };
60
+ type EventHandlers<Events> = {
61
+ [E in Events as E extends {
62
+ readonly _tag: infer Name extends string;
63
+ } ? `on${Capitalize<Name>}` : never]?: (event: E) => ActionMessage;
64
+ };
65
+ type Failure = Parameters<NonNullable<View.Child.Options<unknown, never, never>["onFailure"]>>[0];
66
+ type ChildOptions = {
67
+ /**
68
+ * Shown in the child's place if it fails, until its key changes. Without it, the child is blank.
69
+ * Effect UI shows one node here, so return one element or text.
70
+ */
71
+ fallback?: (failure: Failure) => JSX.Element | string;
72
+ /** Tells this view's feature that the child failed. */
73
+ onFailure?: (failure: Failure) => ActionMessage | undefined;
74
+ /**
75
+ * Keeps the child's state, commands and typed input while this view does not show it, such as
76
+ * a tab that is not selected. Without it, a child that leaves the view starts over.
77
+ */
78
+ keepAlive?: boolean;
79
+ };
80
+ type SlotContent<Slot extends string> = ([Slot] extends [never] ? {} : {
81
+ /** Content for the slots the child declares. It belongs to this view, not to the child. */
82
+ slots?: {
83
+ [Name in Slot]?: JSX.Child;
84
+ };
85
+ }) & ("children" extends Slot ? {
86
+ children?: JSX.Child;
87
+ } : {});
88
+ type Provided<Requirements, Props> = [Requirements] extends [never] ? Props : {
89
+ "Provide this component's Layers with Component.provide before using it as a tag": never;
90
+ };
91
+ type ChildProps<C> = C extends Component.Headless<infer Props, infer Events, infer Parts, infer Requirements, infer _Receives, infer _Shares, infer _SharedValue, infer _Reports, infer _Keys> ? Provided<Requirements, Props & EventHandlers<Events> & ChildOptions & {
92
+ /** Draws the component from its parts. Apply a part to an element with `apply`. */
93
+ view: (parts: Parts) => JSX.Child;
94
+ }> : C extends Component.Lazy<infer Props, infer Events, infer Requirements, infer Slot> ? Provided<Requirements, Props & EventHandlers<Events> & ChildOptions & SlotContent<Slot>> : C extends Component.Component<infer _Name, infer Props, infer _Model, infer _Message, infer Events, infer Requirements, infer _Elements, infer _Queries, infer Slot> ? Provided<Requirements, Props & EventHandlers<Events> & ChildOptions & SlotContent<Slot>> : never;
95
+ export declare namespace JSX {
96
+ /** A view awaiting its host. Write one by hand to reach the Effect UI builder directly. */
97
+ type Element = (host: Host, key?: string) => unknown;
98
+ type Child = Element | View.Outlet | string | number | boolean | null | undefined | ReadonlyArray<Child>;
99
+ /**
100
+ * A tag, a function view or an Effect UI component. A function view returns anything a child
101
+ * can be, or nothing.
102
+ */
103
+ type ElementType = Tag | `${string}-${string}` | ((props: any) => Child) | Component.Any | Component.Headless.Any | Component.Lazy.Any;
104
+ /** A component takes its own props, and an on… handler for each event it reports. */
105
+ type LibraryManagedAttributes<C, P> = C extends Component.Any | Component.Headless.Any | Component.Lazy.Any ? ChildProps<C> : P;
106
+ interface ElementChildrenAttribute {
107
+ children: unknown;
108
+ }
109
+ interface IntrinsicAttributes {
110
+ key?: string | number;
111
+ }
112
+ interface Attributes extends SvgHints {
113
+ class?: Html.ClassToken | ReadonlyArray<Html.ClassToken> | undefined;
114
+ style?: Html.Style | string | undefined;
115
+ disabled?: boolean | undefined;
116
+ popover?: readonly [mode: Html.PopoverMode, open: boolean] | undefined;
117
+ /** Effect UI uses HTML's own attribute names. */
118
+ className?: "Write class instead of className";
119
+ htmlFor?: "Write for instead of htmlFor";
120
+ /** DOM properties, each set with the builder's `prop(name, value)`. */
121
+ properties?: Readonly<Record<string, unknown>> | undefined;
122
+ /** Attributes passed to the builder as written. */
123
+ attrs?: Readonly<Record<string, string | undefined>> | undefined;
124
+ [attribute: AttributeName]: unknown;
125
+ }
126
+ type Events<K extends Tag> = {
127
+ [E in EventName as `on${Capitalize<E>}`]?: E extends keyof EventsOf<K> ? Listener<EventsOf<K>[E]> | undefined : never;
128
+ };
129
+ /** The props of each tag in the Effect UI vocabulary. */
130
+ type Elements = {
131
+ [K in Tag]: Attributes & ElementState<K> & BuilderProps<K> & Events<K> & {
132
+ children?: K extends Html.VoidTag ? never : Child;
133
+ };
134
+ };
135
+ type IntrinsicElements = Elements & {
136
+ [custom: `${string}-${string}`]: {
137
+ id?: string;
138
+ class?: string;
139
+ style?: string;
140
+ properties?: Readonly<Record<string, unknown>>;
141
+ attrs?: Readonly<Record<string, string | undefined>>;
142
+ children?: Child;
143
+ [attribute: AttributeName]: unknown;
144
+ [event: `on${string}`]: Listener<any> | undefined;
145
+ };
146
+ };
147
+ }
148
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jsx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx.js","sourceRoot":"","sources":["../../src/runtime/jsx.ts"],"names":[],"mappings":"","sourcesContent":["import type { Component, Mount, Renderer, View } from \"@effect/ui\"\nimport type { Html } from \"@effect/ui/html\"\n\ndeclare const actionBrand: unique symbol\n/** A message produced by a feature's own action constructors. The brand exists only in the types. */\nexport interface ActionMessage {\n readonly _tag: string\n readonly [actionBrand]: true\n}\n\nexport type Host = Html.H<ActionMessage>\nexport type Tag = keyof Html.Tags<ActionMessage>\ntype EventsOf<K extends Tag> = K extends Html.ContainerTag | Html.VoidTag\n ? Html.EventsOf<K>\n : Html.SvgEvents\ntype EventName<K extends Tag = Tag> = K extends Tag ? keyof EventsOf<K> & string : never\ntype Listener<Payload> =\n | View.Handler<ActionMessage, Payload>\n | readonly [View.Handler<ActionMessage, Payload>, View.EventOptions]\n\n// Any attribute name that does not start with \"on\". Those are events, which are checked by name, so\n// that onClik or React's onKeyDown is an error instead of a listener that never fires.\ntype Letter =\n | \"a\"\n | \"b\"\n | \"c\"\n | \"d\"\n | \"e\"\n | \"f\"\n | \"g\"\n | \"h\"\n | \"i\"\n | \"j\"\n | \"k\"\n | \"l\"\n | \"m\"\n | \"n\"\n | \"o\"\n | \"p\"\n | \"q\"\n | \"r\"\n | \"s\"\n | \"t\"\n | \"u\"\n | \"v\"\n | \"w\"\n | \"x\"\n | \"y\"\n | \"z\"\ntype AttributeName = `${Exclude<Letter, \"o\">}${string}` | `o${Exclude<Letter, \"n\">}${string}`\n\n// Presentation attributes that React spells in camelCase. SVG itself spells them with hyphens.\ntype ReactSvgName =\n | \"strokeWidth\"\n | \"strokeLinecap\"\n | \"strokeLinejoin\"\n | \"strokeDasharray\"\n | \"strokeDashoffset\"\n | \"strokeOpacity\"\n | \"fillOpacity\"\n | \"fillRule\"\n | \"clipRule\"\n | \"clipPath\"\n | \"fontSize\"\n | \"fontFamily\"\n | \"fontWeight\"\n | \"textAnchor\"\n | \"dominantBaseline\"\n | \"stopColor\"\n | \"stopOpacity\"\ntype Hyphenated<Name extends string> = Name extends `${infer Head}${infer Tail}`\n ? `${Head extends Lowercase<Head> ? Head : `-${Lowercase<Head>}`}${Hyphenated<Tail>}`\n : Name\ntype SvgHints = { [Name in ReactSvgName]?: `Write ${Hyphenated<Name>} instead of ${Name}` }\n\n// The properties Effect UI sets through a dedicated builder method on particular elements.\ntype ElementState<K extends Tag> = (K extends \"input\" | \"textarea\" | \"select\"\n ? {\n /** The field's value, set on every render. Pair it with `onInput`, or typing is undone. */\n value?: string | undefined\n }\n : {}) &\n (K extends \"input\"\n ? {\n checked?: boolean | undefined\n /** The value the field starts with. After that the field keeps what the user types. */\n defaultValue?: string | undefined\n /** Whether the box starts checked. After that it keeps what the user chooses. */\n defaultChecked?: boolean | undefined\n }\n : {}) &\n (K extends \"option\" ? { selected?: boolean | undefined } : {}) &\n (K extends \"details\" | \"dialog\" ? { open?: boolean | undefined } : {}) &\n (K extends \"dialog\" ? { modal?: boolean | undefined } : {})\n\ntype Arguments<K extends Tag, Method extends string> = Host[K] extends {\n [M in Method]: (...args: infer A) => unknown\n}\n ? A\n : never\n// The DOM node an element is drawn as, which a mount or a ref receives.\ntype NodeOf<K extends Tag> = Arguments<K, \"ref\">[0] extends Renderer.Ref<infer Node> ? Node : never\n// What Effect UI sets through a builder method that takes more than text.\ntype BuilderProps<K extends Tag> = {\n /**\n * Applies a part of a headless component to the element, which gives the element the\n * attributes and handlers the part holds. A list applies several.\n */\n apply?: ((builder: Host[K]) => unknown) | ReadonlyArray<(builder: Host[K]) => unknown> | undefined\n /** A handle on the element's node, made with `Renderer.ref`. */\n ref?: Arguments<K, \"ref\">[0] | undefined\n /**\n * Work that needs the element's node, such as drawing a chart or moving focus: a mount made with\n * `Mount.make` and issued with its args. Map its result to an action with `Mount.map`, or end\n * its body with `Component.noop`. An element takes one mount.\n */\n onMount?: Mount.Issued<ActionMessage | Component.Noop, never, NodeOf<K>, never> | undefined\n /** The data a drag of this element carries, or `[data, options]`. */\n draggable?: Arguments<K, \"draggable\">[0] | Arguments<K, \"draggable\"> | undefined\n /** Makes the element accept drops of the listed kinds. Handle them with `onDrop`. */\n dropTarget?: Arguments<K, \"dropTarget\">[0] | undefined\n}\n\n// Each event a child component reports becomes an on… prop, named like a DOM event.\ntype EventHandlers<Events> = {\n [\n E in Events as E extends { readonly _tag: infer Name extends string }\n ? `on${Capitalize<Name>}`\n : never\n ]?: (event: E) => ActionMessage\n}\ntype Failure = Parameters<NonNullable<View.Child.Options<unknown, never, never>[\"onFailure\"]>>[0]\n// What Effect UI takes for any child, next to its props and events.\ntype ChildOptions = {\n /**\n * Shown in the child's place if it fails, until its key changes. Without it, the child is blank.\n * Effect UI shows one node here, so return one element or text.\n */\n fallback?: (failure: Failure) => JSX.Element | string\n /** Tells this view's feature that the child failed. */\n onFailure?: (failure: Failure) => ActionMessage | undefined\n /**\n * Keeps the child's state, commands and typed input while this view does not show it, such as\n * a tab that is not selected. Without it, a child that leaves the view starts over.\n */\n keepAlive?: boolean\n}\ntype SlotContent<Slot extends string> = ([Slot] extends [never]\n ? {}\n : {\n /** Content for the slots the child declares. It belongs to this view, not to the child. */\n slots?: { [Name in Slot]?: JSX.Child }\n }) &\n // A slot named children is filled by the tag's own children.\n (\"children\" extends Slot ? { children?: JSX.Child } : {})\n// A component is only a tag once nothing is left for its parent to provide.\ntype Provided<Requirements, Props> = [Requirements] extends [never]\n ? Props\n : { \"Provide this component's Layers with Component.provide before using it as a tag\": never }\n\ntype ChildProps<C> =\n // A headless component has no markup of its own. Its tag takes a view that draws its parts.\n C extends Component.Headless<\n infer Props,\n infer Events,\n infer Parts,\n infer Requirements,\n infer _Receives,\n infer _Shares,\n infer _SharedValue,\n infer _Reports,\n infer _Keys\n >\n ? Provided<\n Requirements,\n Props &\n EventHandlers<Events> &\n ChildOptions & {\n /** Draws the component from its parts. Apply a part to an element with `apply`. */\n view: (parts: Parts) => JSX.Child\n }\n >\n : // A component loaded from a chunk of its own, made with `Component.lazy`.\n C extends Component.Lazy<infer Props, infer Events, infer Requirements, infer Slot>\n ? Provided<Requirements, Props & EventHandlers<Events> & ChildOptions & SlotContent<Slot>>\n : C extends Component.Component<\n infer _Name,\n infer Props,\n infer _Model,\n infer _Message,\n infer Events,\n infer Requirements,\n infer _Elements,\n infer _Queries,\n infer Slot\n >\n ? Provided<Requirements, Props & EventHandlers<Events> & ChildOptions & SlotContent<Slot>>\n : never\n\nexport declare namespace JSX {\n /** A view awaiting its host. Write one by hand to reach the Effect UI builder directly. */\n type Element = (host: Host, key?: string) => unknown\n type Child =\n | Element\n // The place a feature's view puts one of its slots.\n | View.Outlet\n | string\n | number\n | boolean\n | null\n | undefined\n | ReadonlyArray<Child>\n /**\n * A tag, a function view or an Effect UI component. A function view returns anything a child\n * can be, or nothing.\n */\n type ElementType =\n | Tag\n | `${string}-${string}`\n | ((props: any) => Child)\n | Component.Any\n | Component.Headless.Any\n | Component.Lazy.Any\n /** A component takes its own props, and an on… handler for each event it reports. */\n type LibraryManagedAttributes<C, P> = C extends\n | Component.Any\n | Component.Headless.Any\n | Component.Lazy.Any\n ? ChildProps<C>\n : P\n interface ElementChildrenAttribute {\n children: unknown\n }\n interface IntrinsicAttributes {\n key?: string | number\n }\n interface Attributes extends SvgHints {\n class?: Html.ClassToken | ReadonlyArray<Html.ClassToken> | undefined\n style?: Html.Style | string | undefined\n disabled?: boolean | undefined\n popover?: readonly [mode: Html.PopoverMode, open: boolean] | undefined\n /** Effect UI uses HTML's own attribute names. */\n className?: \"Write class instead of className\"\n htmlFor?: \"Write for instead of htmlFor\"\n /** DOM properties, each set with the builder's `prop(name, value)`. */\n properties?: Readonly<Record<string, unknown>> | undefined\n /** Attributes passed to the builder as written. */\n attrs?: Readonly<Record<string, string | undefined>> | undefined\n // ponytail: attribute names are open, as in Effect UI's attr(name, value). Derive per-tag names\n // from the DOM lib if misspelled attributes become a problem.\n [attribute: AttributeName]: unknown\n }\n // An event another element emits is rejected here, and so is a name Effect UI does not know.\n type Events<K extends Tag> = {\n [E in EventName as `on${Capitalize<E>}`]?: E extends keyof EventsOf<K>\n ? Listener<EventsOf<K>[E]> | undefined\n : never\n }\n /** The props of each tag in the Effect UI vocabulary. */\n type Elements = {\n [K in Tag]: Attributes &\n ElementState<K> &\n BuilderProps<K> &\n Events<K> & { children?: K extends Html.VoidTag ? never : Child }\n }\n type IntrinsicElements = Elements & {\n // A custom element. Its attributes, properties and events are open: on… listens for the\n // event of that name in lower case, and the handler receives what Effect UI reads from it.\n // Its class and style are plain text, since Effect UI builds it without the HTML helpers.\n [custom: `${string}-${string}`]: {\n id?: string\n class?: string\n style?: string\n properties?: Readonly<Record<string, unknown>>\n attrs?: Readonly<Record<string, string | undefined>>\n children?: Child\n [attribute: AttributeName]: unknown\n [event: `on${string}`]: Listener<any> | undefined\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "effect-ui-tsx",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Write Effect UI components as a model, a controller and a plain TSX view.",
5
+ "keywords": [
6
+ "effect",
7
+ "effect-ui",
8
+ "elm-architecture",
9
+ "jsx",
10
+ "tsx"
11
+ ],
12
+ "homepage": "https://github.com/priemskiyyy/effect-ui-tsx#readme",
13
+ "bugs": "https://github.com/priemskiyyy/effect-ui-tsx/issues",
14
+ "license": "MIT",
15
+ "repository": "github:priemskiyyy/effect-ui-tsx",
16
+ "files": [
17
+ "dist",
18
+ "!dist/.tsbuildinfo"
19
+ ],
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ },
27
+ "./jsx-runtime": {
28
+ "types": "./dist/runtime/jsx-runtime.d.ts",
29
+ "import": "./dist/runtime/jsx-runtime.js"
30
+ },
31
+ "./jsx-dev-runtime": {
32
+ "types": "./dist/runtime/jsx-dev-runtime.d.ts",
33
+ "import": "./dist/runtime/jsx-dev-runtime.js"
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "@effect/ui": "https://pkg.pr.new/Effect-TS/ui/@effect/ui@df04560",
38
+ "effect": "4.1.7"
39
+ },
40
+ "peerDependencies": {
41
+ "@effect/ui": "0.0.0",
42
+ "effect": "^4.1.7"
43
+ },
44
+ "scripts": {}
6
45
  }