@arcgis/lumina 4.31.0-next.90 → 4.31.0-next.91

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.
@@ -1,8 +1,9 @@
1
1
  import type { CSSResultGroup, CSSResultOrNative, PropertyValues } from "lit";
2
2
  import { LitElement as OriginalLitElement } from "lit";
3
- import type { LitElementPropertyDeclaration } from "@arcgis/components-controllers";
3
+ import type { LuminaPropertyDeclaration } from "@arcgis/components-controllers";
4
4
  import type { Runtime } from "./runtime";
5
5
  import type { ProxyComponent } from "./lazyLoad";
6
+ import type { ToElement } from "./jsx/jsx";
6
7
  type ComponentLifecycle = {
7
8
  connectedCallback?: () => void;
8
9
  disconnectedCallback?: () => void;
@@ -38,13 +39,13 @@ export declare class LitElement extends OriginalLitElement implements ComponentL
38
39
  static finalizeStyles(styles?: CSSResultGroup): CSSResultOrNative[];
39
40
  static createProperty(name: PropertyKey,
40
41
  /**
41
- * While in vanilla Lit this type is always LitElementPropertyDeclaration,
42
+ * While in vanilla Lit this type is always LuminaPropertyDeclaration,
42
43
  * in Lumina it is always number or
43
- * [number,LitElementPropertyDeclaration], so we don't even check for the
44
- * LitElementPropertyDeclaration case. LitElementPropertyDeclaration is here
44
+ * [number,LuminaPropertyDeclaration], so we don't even check for the
45
+ * LuminaPropertyDeclaration case. LuminaPropertyDeclaration is here
45
46
  * only to satisfy the type checker.
46
47
  */
47
- options?: LitElementPropertyDeclaration | number | [number, LitElementPropertyDeclaration]): void;
48
+ options?: LuminaPropertyDeclaration | number | [number, LuminaPropertyDeclaration]): void;
48
49
  /**
49
50
  * Since we can't pass arguments to web component constructor, before lazy
50
51
  * loading logic calls document.createElement(), it temporary sets this static
@@ -74,7 +75,7 @@ export declare class LitElement extends OriginalLitElement implements ComponentL
74
75
  * const isLazy = this.el !== this;
75
76
  * ```
76
77
  */
77
- el: HTMLElement;
78
+ el: ToElement<this>;
78
79
  /**
79
80
  * Controller Manager orchestrates all components used by this component,
80
81
  * connecting their lifecycle hooks and providing context information.
@@ -194,7 +195,7 @@ export declare class LitElement extends OriginalLitElement implements ComponentL
194
195
  listenOn<Name extends keyof HTMLElementEventMap>(target: HTMLElement, name: Name, listener: Listener<this, HTMLElementEventMap[Name] & {
195
196
  currentTarget: HTMLElement;
196
197
  }>, options?: AddEventListenerOptions | boolean): void;
197
- listenOn<EventType extends Event = CustomEvent<"Provide type like this.listenOn<CustomEvent<MyType>>() to get type-checked payload type">, Target = EventTarget>(target: Target, name: string, listener: Listener<this, EventType & {
198
+ listenOn<EventType extends Event = CustomEvent<"Provide type like this.listenOn<ToEvents<ArcgisCounter>['arcgisClick']>() to get type-checked payload type">, Target = EventTarget>(target: Target, name: string, listener: Listener<this, EventType & {
198
199
  currentTarget: Target;
199
200
  }>, options?: AddEventListenerOptions | boolean): void;
200
201
  /**
@@ -1,9 +1,4 @@
1
- /**
2
- * An event emitter object
3
- */
4
- export type EventEmitter<T = undefined> = {
5
- emit(payload: T extends undefined ? void : T): CustomEvent<T>;
6
- };
1
+ import type { EventEmitter } from "@arcgis/components-controllers";
7
2
  export type EventOptions = {
8
3
  /**
9
4
  * A Boolean indicating whether the event bubbles up through the DOM or not.
@@ -27,27 +22,7 @@ export type EventOptions = {
27
22
  */
28
23
  composed?: boolean;
29
24
  };
30
- /**
31
- * While we don't actually return CustomEvent<T>, only EventEmitter<T>, claiming
32
- * that we return CustomElement<T> simplifies typing.
33
- *
34
- * See:
35
- * ```ts
36
- * handleClick(event: ArcgisCounter['arcgisClick']): void {
37
- * }
38
- * ```
39
- *
40
- * Without it, you would have to do:
41
- * ```ts
42
- * handleClick(event: ReturnType<ArcgisCounter['arcgisClick']['emit']>): void {
43
- * }
44
- * ```
45
- *
46
- * It also simplifies the work for Lumina - having property claim to
47
- * be an even makes it easy to find event properties to provide JSX type-checking,
48
- * and to find events when doing docs generation.
49
- */
50
- export declare const createEventFactory: <T = undefined>(eventName?: string, options?: EventOptions, component?: import("@arcgis/components-controllers").BaseComponent) => CustomEvent<T> & EventEmitter<T>;
25
+ export declare const createEventFactory: <T = undefined>(eventName?: string, options?: EventOptions, component?: import("@arcgis/components-controllers").BaseComponent) => EventEmitter<T>;
51
26
  /**
52
27
  * Creates an event emitter.
53
28
  * Events emitted by your component will be included in the documentation.
@@ -62,4 +37,4 @@ export declare const createEventFactory: <T = undefined>(eventName?: string, opt
62
37
  * ```
63
38
  *
64
39
  */
65
- export declare const createEvent: <T = undefined>(options?: EventOptions) => CustomEvent<T> & EventEmitter<T>;
40
+ export declare const createEvent: <T = undefined>(options?: EventOptions) => EventEmitter<T>;
@@ -1,4 +1,4 @@
1
- import type { LitElementPropertyDeclaration } from "@arcgis/components-controllers";
1
+ import type { LuminaPropertyDeclaration } from "@arcgis/components-controllers";
2
2
  export { state } from "@lit/reactive-element/decorators/state.js";
3
3
  /**
4
4
  * A class field or accessor decorator which creates a reactive property that
@@ -41,7 +41,7 @@ export { state } from "@lit/reactive-element/decorators/state.js";
41
41
  * }
42
42
  * ```
43
43
  */
44
- export declare const property: (options?: Omit<LitElementPropertyDeclaration, "state">) => PropertyDecorator;
44
+ export declare const property: (options?: Omit<LuminaPropertyDeclaration, "state">) => PropertyDecorator;
45
45
  declare type CustomMethodDecorator<T> = (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
46
46
  /**
47
47
  * The `@method()` decorator is used to expose methods on the public API.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { EventEmitter, EventOptions } from "./createEvent";
1
+ export type { EventOptions } from "./createEvent";
2
2
  export { createEvent } from "./createEvent";
3
3
  export { state, property, method } from "./decorators";
4
4
  export type { HmrComponentMeta } from "./hmrSupport";
package/dist/index.js CHANGED
@@ -707,7 +707,7 @@ var LitElement = class _LitElement extends OriginalLitElement {
707
707
  return this;
708
708
  }
709
709
  };
710
- LitElement.createEvent = createEventFactory;
710
+ LitElement.$createEvent = createEventFactory;
711
711
  if (process.env.NODE_ENV !== "production") {
712
712
  const globalWithLit = globalThis;
713
713
  globalWithLit.litIssuedWarnings ??= /* @__PURE__ */ new Set();
package/dist/jsx/jsx.d.ts CHANGED
@@ -21,7 +21,7 @@ import type { DirectiveClass } from "lit/directive.js";
21
21
  */
22
22
  export declare namespace h {
23
23
  export function h(sel: any, data?: any, text?: any): TemplateResult;
24
- export type { LitJsx as JSX };
24
+ export type { LuminaJsx as JSX };
25
25
  }
26
26
  /**
27
27
  * Fragment
@@ -175,6 +175,8 @@ export declare const bindEvent: <T>(descriptor: T | (AddEventListenerOptions & {
175
175
  handleEvent: T;
176
176
  })) => T;
177
177
  export type JsxNode = DirectiveResult<any> | JsxNodeArray | Node | TemplateResult | boolean | number | (NonNullable<unknown> & string) | null | undefined;
178
+ interface JsxNodeArray extends Array<JsxNode> {
179
+ }
178
180
  /**
179
181
  * Equivalent to Lit's "nothing", but has type "never" to allow it to be set as a
180
182
  * value for any JSX attribute.
@@ -213,8 +215,93 @@ export declare const noChange: never;
213
215
  * "never" to allow it be set as a value for any JSX attribute.
214
216
  */
215
217
  export declare const directive: <C extends DirectiveClass>(c: C) => (...values: Parameters<InstanceType<C>["render"]>) => never;
216
- interface JsxNodeArray extends Array<JsxNode> {
217
- }
218
+ /**
219
+ * this.el property on a component only has the public properties of the
220
+ * component. All internal methods, properties, as well as LitElement methods
221
+ * are excluded. This type approximates what the public API of the component
222
+ * looks like.
223
+ *
224
+ * @example
225
+ * Usually, you don't need to use this type directly. If you have an
226
+ * `ArcgisCounter` element, you can get it's el type by using
227
+ * `ArcgisCounter["el"]`
228
+ *
229
+ * @remarks
230
+ * By using Omit<>, TypeScript also "forgets" all private members of the
231
+ * passed in type, which is convenient for us.
232
+ */
233
+ export type ToElement<Component> = Omit<Component, LuminaJsx.ExcludedProperties>;
234
+ /**
235
+ * Utility type for getting the JSX prop types for a given component. In particular:
236
+ *
237
+ * - Excludes LitElement properties that should not be exposed to the end-user
238
+ * - Converts event .emit() properties into event callbacks
239
+ * - Replaces original HTMLElement property typings with the ones we provide for
240
+ * greater type-safety and control
241
+ * - For native events listeners, makes currentTarget equal to the component's
242
+ * HTML instance
243
+ *
244
+ * We mark all component properties as optional because there is no easy
245
+ * way for us to differentiate between public component properties and just
246
+ * regular members that don't have `@property()` decorator (presence or
247
+ * absence of decorator does not change the type). Thus, if we don't mark all
248
+ * properties as optional, TypeScript will force us to provide a value for all
249
+ * methods, and regular properties component may have.
250
+ */
251
+ export type ToJsx<Component extends {
252
+ el: unknown;
253
+ }> = LuminaJsx.HTMLAttributes<Component["el"]> & LuminaJsx.RemapEvents<Component> & Partial<Omit<Component, LuminaJsx.ExcludedProperties | keyof HTMLElement | keyof LuminaJsx.RemapEvents<Component>>>;
254
+ /**
255
+ * Get the type of all events for a given component. Includes native DOM events
256
+ * and custom events.
257
+ *
258
+ * @example
259
+ * ```tsx
260
+ * render() {
261
+ * return <arcgis-counter onArcgisOverflow={this._handleOverflow} />
262
+ * }
263
+ * _handleOverflow(event: ToEvents<ArcgisCounter>["arcgisOverflow"]) {
264
+ * // event.detail
265
+ * // event.currentTarget
266
+ * }
267
+ * ```
268
+ *
269
+ * @remarks
270
+ * Alternative implementation of this type that is simpler, and potentially
271
+ * more performant, but looses "go to definition" information.
272
+ *
273
+ * ```tsx
274
+ * export type ToEvents<Component extends { el: unknown }> = {
275
+ * [Key in keyof ToJsx<Component> as Key extends `on${infer EventName}`
276
+ * ? Uncapitalize<EventName>
277
+ * : never]-?: ListenerToPayloadType<ToJsx<Component>[Key]>;
278
+ * };
279
+ *
280
+ * type ListenerToPayloadType<Listener> = Listener extends (event: infer EventType) => unknown ? EventType : never;
281
+ * ```
282
+ *
283
+ * TypeScript issues that may fix this:
284
+ * - https://github.com/microsoft/TypeScript/issues/49909
285
+ * - https://github.com/microsoft/TypeScript/issues/50715
286
+ */
287
+ export type ToEvents<Component> = GlobalEventTypes<MaybeEl<Component>> & {
288
+ [Key in keyof Component as ListenerToPayloadType<Component[Key]> extends CustomEvent ? Key : never]-?: ListenerToPayloadType<Component[Key]> & {
289
+ currentTarget: MaybeEl<Component>;
290
+ };
291
+ };
292
+ type MaybeEl<Component> = Component extends {
293
+ el: unknown;
294
+ } ? Component["el"] : Component;
295
+ /**
296
+ * From "GlobalEventHandlersCamelCase" extract event names and their payloads.
297
+ * Not using "HTMLElementEventMap" because that map has all events in lowercase.
298
+ */
299
+ type GlobalEventTypes<Target = HTMLElement> = {
300
+ [Key in keyof LuminaJsx.GlobalEventHandlersCamelCase<Target> as Key extends `on${infer EventName}` ? Uncapitalize<EventName> : never]-?: Parameters<NonNullable<LuminaJsx.GlobalEventHandlersCamelCase<Target>[Key]>>[0];
301
+ };
302
+ type ListenerToPayloadType<Listener> = unknown extends Listener ? void : Listener extends {
303
+ emit: (...rest: never[]) => infer PayloadType;
304
+ } ? PayloadType : Listener extends CustomEvent ? Listener : void;
218
305
  /**
219
306
  * These typings are based on dom-expressions typings:
220
307
  * https://github.com/ryansolid/dom-expressions/blob/main/packages/dom-expressions/src/jsx.d.ts
@@ -227,7 +314,7 @@ interface JsxNodeArray extends Array<JsxNode> {
227
314
  * https://www.typescriptlang.org/docs/handbook/jsx.html
228
315
  */
229
316
  type DOMElement = Element;
230
- export declare namespace LitJsx {
317
+ export declare namespace LuminaJsx {
231
318
  /**
232
319
  * Whether to pick TemplateResult or JsxNode here is a compromise.
233
320
  *
@@ -292,35 +379,24 @@ export declare namespace LitJsx {
292
379
  * information and can generate the typings that expose only the actual
293
380
  * properties component declared.
294
381
  */
295
- type ExcludedProperties = "renderRoot" | "isUpdatePending" | "hasUpdated" | "addController" | "removeController" | "connectedCallback" | "disconnectedCallback" | "attributeChangedCallback" | "requestUpdate" | "updateComplete" | "el" | "manager" | "componentOnReady" | "listen" | "load" | "loaded" | "willUpdate" | "updated" | "render" | "renderOptions";
382
+ type ExcludedProperties = "renderRoot" | "isUpdatePending" | "hasUpdated" | "addController" | "removeController" | "connectedCallback" | "disconnectedCallback" | "attributeChangedCallback" | "requestUpdate" | "updateComplete" | "el" | "componentOnReady" | "listen" | "load" | "loaded" | "willUpdate" | "updated" | "render" | "renderOptions";
296
383
  type ReMappedComponents<Components> = {
297
- [Key in keyof Components]: ComponentProps<Components[Key]>;
384
+ [Key in keyof Components]: Components[Key] extends {
385
+ el: unknown;
386
+ } ? ToJsx<Components[Key]> : never;
298
387
  };
299
388
  /**
300
- * * A utility type for getting the JSX prop types for a given component
301
- *
302
- * - Exclude LitElement properties that should not be exposed to the end-user
303
- * - Convert event .emit() properties into event callbacks
304
- * - Replace original HTMLElement property typings with the ones we provide for
305
- * greater type-safety and control
306
- * - For native events listeners, make currentTarget equal to the component's
307
- * HTML instance
308
- *
309
- * We mark all component properties as optional because there is no easy
310
- * way for us to differentiate between public component properties and just
311
- * regular members that don't have `@property()` decorator (presence or
312
- * absence of decorator does not change the type). Thus, if we don't mark all
313
- * properties as optional, TypeScript will force us to provide a value for all
314
- * methods, and regular properties component may have.
389
+ * From event emitters create event listener callbacks
315
390
  */
316
- type ComponentProps<Component> = Partial<Omit<Component, FindEventProperties<Component> | ExcludedProperties | keyof HTMLElement>> & {
317
- [Key in FindEventProperties<Component> as `on${Key & string}`]?: (event: Omit<Component[Key], "emit"> & {
318
- currentTarget: Component;
319
- }) => void;
320
- } & HTMLAttributes<Component>;
321
- type FindEventProperties<Component> = {
322
- [Key in keyof Component]: Component[Key] extends CustomEvent ? unknown extends Component[Key] ? never : Key : never;
323
- }[keyof Component];
391
+ type RemapEvents<Component extends {
392
+ el: unknown;
393
+ }> = {
394
+ [Key in keyof Component as `on${Key & string}`]?: unknown extends Component[Key] ? never : Component[Key] extends {
395
+ emit: (...rest: never[]) => infer PayloadType;
396
+ } ? (event: PayloadType & {
397
+ currentTarget: Component["el"];
398
+ }) => void : never;
399
+ };
324
400
  /**
325
401
  * - Make ref prop return HTMLElement rather than Stencil element type
326
402
  * - Uncapitalize the event properties to match the syntax of React 19,
@@ -656,6 +732,11 @@ export declare namespace LitJsx {
656
732
  ariaControlsElements?: HTMLElement[];
657
733
  /** Indicates the element that represents the current item within a container or set of related elements. */
658
734
  ariaCurrent?: boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time";
735
+ /**
736
+ * Defines a string value that describes or annotates the current element.
737
+ * @see aria-describedby
738
+ */
739
+ ariaDescription?: string;
659
740
  /**
660
741
  * Identifies the element (or elements) that describes the object.
661
742
  * @see aria-labelledby
@@ -14,7 +14,10 @@ declare global {
14
14
  */
15
15
  export interface DeclareElements {
16
16
  }
17
- interface HTMLElementTagNameMap extends DeclareElements {
17
+ type ReMappedDeclareElements = {
18
+ [TagName in keyof DeclareElements]: DeclareElements[TagName]["el"];
19
+ };
20
+ interface HTMLElementTagNameMap extends ReMappedDeclareElements {
18
21
  }
19
22
  /**
20
23
  * Extend this interface with Stencil web components that you wish to use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/lumina",
3
- "version": "4.31.0-next.90",
3
+ "version": "4.31.0-next.91",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -29,8 +29,8 @@
29
29
  "clean": "rimraf ./dist ./build ./turbo ./node_modules"
30
30
  },
31
31
  "dependencies": {
32
- "@arcgis/components-controllers": "4.31.0-next.90",
33
- "@arcgis/components-utils": "4.31.0-next.90",
32
+ "@arcgis/components-controllers": "4.31.0-next.91",
33
+ "@arcgis/components-utils": "4.31.0-next.91",
34
34
  "@lit-labs/ssr": "^3.2.2",
35
35
  "@lit-labs/ssr-client": "^1.1.7",
36
36
  "csstype": "^3.1.3",
@@ -38,12 +38,12 @@
38
38
  "tslib": "^2.7.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@arcgis/typescript-config": "4.31.0-next.90",
41
+ "@arcgis/typescript-config": "4.31.0-next.91",
42
42
  "@types/node": "^20.2.5",
43
43
  "eslint": "^8.55.0",
44
44
  "rimraf": "^5.0.0",
45
45
  "tsup": "^8.1.0",
46
46
  "typescript": "~5.4.0"
47
47
  },
48
- "gitHead": "a9a0d57b58ffabca05a7c03a2d0516b7174cf939"
48
+ "gitHead": "c06a24c15d739911e39eb09ff59eeb895c478e7a"
49
49
  }