Skip to content

Commit 3b1210f

Browse files
committed
fix: Improve auto-generated typing and configuration typings
1 parent d818f21 commit 3b1210f

9 files changed

Lines changed: 371 additions & 224 deletions

File tree

dist/client.d.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,19 @@ declare function Watch(keys?: string | string[], immediate?: boolean): (target:
225225
*/
226226
declare const classes: (input: unknown, smart?: boolean) => string;
227227

228+
interface HTMLPlusElements {
229+
}
230+
type BreakpointConfig = {
231+
type: 'container' | 'media';
232+
min?: number;
233+
max?: number;
234+
};
228235
/**
229236
* TODO
230237
*/
231-
interface Config {
238+
type Config<Namespace extends string, Breakpoints extends string> = {
232239
breakpoints?: {
233-
[key: string]: {
234-
type: 'container' | 'media';
235-
min?: number;
236-
max?: number;
237-
};
240+
[key in Breakpoints]: BreakpointConfig;
238241
};
239242
event?: {
240243
resolver?: (parameters: unknown) => CustomEvent | undefined;
@@ -243,26 +246,24 @@ interface Config {
243246
[key: string]: unknown;
244247
};
245248
elements?: {
246-
[key: string]: {
249+
[K in keyof HTMLPlusElements as K extends `${Namespace}-${string}` ? K : never]?: {
247250
properties?: {
248-
[key: string]: {
249-
default?: unknown;
251+
[Prop in keyof HTMLPlusElements[K]['properties']]?: {
252+
default?: HTMLPlusElements[K]['properties'][Prop];
250253
};
251254
};
252255
variants?: {
253-
[key: string]: {
254-
properties: {
255-
[key: string]: unknown;
256-
};
256+
[M in HTMLPlusElements[K]['properties']['variant']]?: {
257+
properties?: Partial<HTMLPlusElements[K]['properties']>;
257258
};
258259
};
259260
};
260261
};
261-
}
262+
};
262263
/**
263264
* TODO
264265
*/
265-
interface ConfigOptions {
266+
type ConfigOptions = {
266267
/**
267268
* TODO
268269
*/
@@ -271,23 +272,23 @@ interface ConfigOptions {
271272
* TODO
272273
*/
273274
override?: boolean;
274-
}
275+
};
275276
/**
276277
* TODO
277278
*/
278-
declare const getConfig: (namespace: string) => Config;
279+
declare const getConfig: <N extends string, B extends string>(namespace: N) => Config<N, B>;
279280
/**
280281
* TODO
281282
*/
282-
declare const getConfigCreator: (namespace: string) => () => Config;
283+
declare const getConfigCreator: <N extends string, B extends string>(namespace: N) => () => Config<N, B>;
283284
/**
284285
* TODO
285286
*/
286-
declare const setConfig: (namespace: string, config: Config, options?: ConfigOptions) => void;
287+
declare const setConfig: <N extends string, B extends string>(namespace: N, config: Config<N, B>, options?: ConfigOptions) => void;
287288
/**
288289
* TODO
289290
*/
290-
declare const setConfigCreator: (namespace: string) => (config: Config, options?: ConfigOptions) => void;
291+
declare const setConfigCreator: <N extends string, B extends string>(namespace: N) => (config: Config<N, B>, options?: ConfigOptions) => void;
291292

292293
type Direction = 'ltr' | 'rtl';
293294
/**
@@ -382,4 +383,4 @@ type OverridableValue<Base, Overrides = unknown> = {
382383
} ? never : Unlisted<Base>);
383384

384385
export { Bind, Consumer, Debounce, Direction$1 as Direction, Element$1 as Element, Event, Host, IsRTL, Listen, Method, Overrides, Property, Provider, Query, QueryAll, Slots$1 as Slots, State, Style, Variant, Watch, _internal_a_, _internal_h_, _internal_s_, classes, direction, dispatch, getConfig, getConfigCreator, host, isCSSColor, isCSSUnit, isRTL, off, on, query, queryAll, setConfig, setConfigCreator, slots, toUnit };
385-
export type { Config, ConfigOptions, EventEmitter, EventOptions, ListenOptions, OverridableValue, OverridesConfig, PropertyOptions };
386+
export type { Config, ConfigOptions, EventEmitter, EventOptions, HTMLPlusElements, ListenOptions, OverridableValue, OverridesConfig, PropertyOptions };

dist/client.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ const isCSSColor = (input) => {
268268
};
269269

270270
const isCSSUnit = (input) => {
271-
return /^\d+(\.\d+)?(px|pt|cm|mm|in|em|rem|%|vw|vh)$/.test(input);
271+
const option = new Option();
272+
option.style.width = input;
273+
return option.style.width !== '';
272274
};
273275

274276
/**
@@ -1514,7 +1516,10 @@ const proxy = (constructor) => {
15141516
const properties = getConfig(namespace).elements?.[tag]?.properties;
15151517
if (!properties)
15161518
return;
1517-
const defaults = Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, value?.default]));
1519+
const defaults = Object.fromEntries(Object.entries(properties).map(([key, value]) => [
1520+
key,
1521+
value?.default
1522+
]));
15181523
Object.assign(this, defaults);
15191524
})();
15201525
// TODO

0 commit comments

Comments
 (0)