weifuwu 0.33.4 → 0.33.6

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.
@@ -13,13 +13,338 @@ import type { WfuiContext } from './types.ts';
13
13
  declare global {
14
14
  namespace JSX {
15
15
  interface IntrinsicElements {
16
- [tag: string]: any;
16
+ div: HtmlDiv;
17
+ span: HtmlSpan;
18
+ p: HtmlP;
19
+ h1: HtmlH1;
20
+ h2: HtmlH2;
21
+ h3: HtmlH3;
22
+ h4: HtmlH4;
23
+ h5: HtmlH5;
24
+ h6: HtmlH6;
25
+ header: HtmlHeader;
26
+ footer: HtmlFooter;
27
+ nav: HtmlNav;
28
+ main: HtmlMain;
29
+ section: HtmlSection;
30
+ article: HtmlArticle;
31
+ aside: HtmlAside;
32
+ pre: HtmlPre;
33
+ blockquote: HtmlBlockquote;
34
+ figure: HtmlFigure;
35
+ address: HtmlAddress;
36
+ ul: HtmlUl;
37
+ ol: HtmlOl;
38
+ li: HtmlLi;
39
+ dl: HtmlDl;
40
+ dt: HtmlDt;
41
+ dd: HtmlDd;
42
+ table: HtmlTable;
43
+ thead: HtmlThead;
44
+ tbody: HtmlTbody;
45
+ tr: HtmlTr;
46
+ th: HtmlTh;
47
+ td: HtmlTd;
48
+ form: HtmlForm;
49
+ input: HtmlInput;
50
+ button: HtmlButton;
51
+ select: HtmlSelect;
52
+ option: HtmlOption;
53
+ textarea: HtmlTextarea;
54
+ label: HtmlLabel;
55
+ fieldset: HtmlFieldset;
56
+ legend: HtmlLegend;
57
+ img: HtmlImg;
58
+ video: HtmlVideo;
59
+ audio: HtmlAudio;
60
+ canvas: HtmlCanvas;
61
+ svg: HtmlSvg;
62
+ a: HtmlA;
63
+ link: HtmlLink;
64
+ strong: HtmlStrong;
65
+ em: HtmlEm;
66
+ b: HtmlB;
67
+ i: HtmlI;
68
+ u: HtmlU;
69
+ s: HtmlS;
70
+ mark: HtmlMark;
71
+ code: HtmlCode;
72
+ small: HtmlSmall;
73
+ sub: HtmlSub;
74
+ sup: HtmlSup;
75
+ abbr: HtmlAbbr;
76
+ time: HtmlTime;
77
+ br: HtmlBr;
78
+ hr: HtmlHr;
79
+ wbr: HtmlWbr;
80
+ style: HtmlStyle;
81
+ script: HtmlScript;
82
+ template: HtmlTemplate;
83
+ slot: HtmlSlot;
84
+ details: HtmlDetails;
85
+ summary: HtmlSummary;
86
+ dialog: HtmlDialog;
87
+ iframe: HtmlIframe;
17
88
  }
89
+ interface WfuiAttributes<T> {
90
+ class?: string | Signal<string>;
91
+ className?: string | Signal<string>;
92
+ id?: string;
93
+ style?: Record<string, string | undefined>;
94
+ title?: string;
95
+ lang?: string;
96
+ dir?: string;
97
+ hidden?: boolean | Signal<boolean>;
98
+ tabindex?: number;
99
+ accesskey?: string;
100
+ draggable?: boolean;
101
+ contenteditable?: boolean;
102
+ slot?: string;
103
+ spellcheck?: boolean;
104
+ ref?: (el: T) => void;
105
+ onClick?: (e: MouseEvent) => void;
106
+ onDblClick?: (e: MouseEvent) => void;
107
+ onMouseDown?: (e: MouseEvent) => void;
108
+ onMouseUp?: (e: MouseEvent) => void;
109
+ onMouseMove?: (e: MouseEvent) => void;
110
+ onMouseEnter?: (e: MouseEvent) => void;
111
+ onMouseLeave?: (e: MouseEvent) => void;
112
+ onKeyDown?: (e: KeyboardEvent) => void;
113
+ onKeyUp?: (e: KeyboardEvent) => void;
114
+ onKeyPress?: (e: KeyboardEvent) => void;
115
+ onFocus?: (e: FocusEvent) => void;
116
+ onBlur?: (e: FocusEvent) => void;
117
+ onInput?: (e: Event) => void;
118
+ onChange?: (e: Event) => void;
119
+ onSubmit?: (e: Event) => void;
120
+ onScroll?: (e: Event) => void;
121
+ onWheel?: (e: WheelEvent) => void;
122
+ onTouchStart?: (e: TouchEvent) => void;
123
+ onTouchEnd?: (e: TouchEvent) => void;
124
+ onTouchMove?: (e: TouchEvent) => void;
125
+ onLoad?: (e: Event) => void;
126
+ onError?: (e: Event) => void;
127
+ onAnimationEnd?: (e: AnimationEvent) => void;
128
+ onTransitionEnd?: (e: TransitionEvent) => void;
129
+ [data: string]: unknown;
130
+ }
131
+ type HtmlDiv = WfuiAttributes<HTMLDivElement>;
132
+ type HtmlSpan = WfuiAttributes<HTMLSpanElement>;
133
+ type HtmlP = WfuiAttributes<HTMLParagraphElement>;
134
+ type HtmlH1 = WfuiAttributes<HTMLHeadingElement>;
135
+ type HtmlH2 = WfuiAttributes<HTMLHeadingElement>;
136
+ type HtmlH3 = WfuiAttributes<HTMLHeadingElement>;
137
+ type HtmlH4 = WfuiAttributes<HTMLHeadingElement>;
138
+ type HtmlH5 = WfuiAttributes<HTMLHeadingElement>;
139
+ type HtmlH6 = WfuiAttributes<HTMLHeadingElement>;
140
+ type HtmlHeader = WfuiAttributes<HTMLElement>;
141
+ type HtmlFooter = WfuiAttributes<HTMLElement>;
142
+ type HtmlNav = WfuiAttributes<HTMLElement>;
143
+ type HtmlMain = WfuiAttributes<HTMLElement>;
144
+ type HtmlSection = WfuiAttributes<HTMLElement>;
145
+ type HtmlArticle = WfuiAttributes<HTMLElement>;
146
+ type HtmlAside = WfuiAttributes<HTMLElement>;
147
+ type HtmlPre = WfuiAttributes<HTMLPreElement>;
148
+ type HtmlBlockquote = WfuiAttributes<HTMLQuoteElement>;
149
+ type HtmlFigure = WfuiAttributes<HTMLElement>;
150
+ type HtmlAddress = WfuiAttributes<HTMLElement>;
151
+ type HtmlUl = WfuiAttributes<HTMLUListElement>;
152
+ type HtmlOl = WfuiAttributes<HTMLOListElement>;
153
+ type HtmlLi = WfuiAttributes<HTMLLIElement>;
154
+ type HtmlDl = WfuiAttributes<HTMLDListElement>;
155
+ type HtmlDt = WfuiAttributes<HTMLElement>;
156
+ type HtmlDd = WfuiAttributes<HTMLElement>;
157
+ type HtmlTable = WfuiAttributes<HTMLTableElement>;
158
+ type HtmlThead = WfuiAttributes<HTMLTableSectionElement>;
159
+ type HtmlTbody = WfuiAttributes<HTMLTableSectionElement>;
160
+ type HtmlTr = WfuiAttributes<HTMLTableRowElement>;
161
+ type HtmlTh = WfuiAttributes<HTMLTableCellElement>;
162
+ type HtmlTd = WfuiAttributes<HTMLTableCellElement>;
163
+ interface HtmlForm extends WfuiAttributes<HTMLFormElement> {
164
+ action?: string;
165
+ method?: string;
166
+ enctype?: string;
167
+ novalidate?: boolean;
168
+ target?: string;
169
+ }
170
+ interface HtmlInput extends WfuiAttributes<HTMLInputElement> {
171
+ type?: string;
172
+ value?: string | Signal<string>;
173
+ placeholder?: string;
174
+ checked?: boolean | Signal<boolean>;
175
+ disabled?: boolean | Signal<boolean>;
176
+ readonly?: boolean;
177
+ required?: boolean;
178
+ autofocus?: boolean;
179
+ autocomplete?: string;
180
+ name?: string;
181
+ min?: string | number;
182
+ max?: string | number;
183
+ step?: number;
184
+ pattern?: string;
185
+ accept?: string;
186
+ multiple?: boolean;
187
+ src?: string;
188
+ alt?: string;
189
+ }
190
+ interface HtmlButton extends WfuiAttributes<HTMLButtonElement> {
191
+ type?: 'button' | 'submit' | 'reset';
192
+ disabled?: boolean | Signal<boolean>;
193
+ name?: string;
194
+ value?: string;
195
+ }
196
+ interface HtmlSelect extends WfuiAttributes<HTMLSelectElement> {
197
+ value?: string | Signal<string>;
198
+ disabled?: boolean;
199
+ name?: string;
200
+ required?: boolean;
201
+ multiple?: boolean;
202
+ }
203
+ interface HtmlOption extends WfuiAttributes<HTMLOptionElement> {
204
+ value?: string;
205
+ selected?: boolean;
206
+ disabled?: boolean;
207
+ label?: string;
208
+ }
209
+ interface HtmlTextarea extends WfuiAttributes<HTMLTextAreaElement> {
210
+ value?: string | Signal<string>;
211
+ placeholder?: string;
212
+ disabled?: boolean;
213
+ readonly?: boolean;
214
+ required?: boolean;
215
+ rows?: number;
216
+ cols?: number;
217
+ autofocus?: boolean;
218
+ name?: string;
219
+ }
220
+ interface HtmlLabel extends WfuiAttributes<HTMLLabelElement> {
221
+ htmlFor?: string;
222
+ }
223
+ interface HtmlFieldset extends WfuiAttributes<HTMLFieldSetElement> {
224
+ disabled?: boolean;
225
+ name?: string;
226
+ }
227
+ type HtmlLegend = WfuiAttributes<HTMLLegendElement>;
228
+ interface HtmlA extends WfuiAttributes<HTMLAnchorElement> {
229
+ href?: string;
230
+ target?: string;
231
+ rel?: string;
232
+ download?: string;
233
+ }
234
+ interface HtmlImg extends WfuiAttributes<HTMLImageElement> {
235
+ src?: string | Signal<string>;
236
+ alt?: string;
237
+ width?: number | string;
238
+ height?: number | string;
239
+ loading?: 'lazy' | 'eager';
240
+ srcset?: string;
241
+ sizes?: string;
242
+ }
243
+ interface HtmlVideo extends WfuiAttributes<HTMLVideoElement> {
244
+ src?: string;
245
+ controls?: boolean;
246
+ autoplay?: boolean;
247
+ loop?: boolean;
248
+ muted?: boolean;
249
+ poster?: string;
250
+ width?: number | string;
251
+ height?: number | string;
252
+ }
253
+ interface HtmlAudio extends WfuiAttributes<HTMLAudioElement> {
254
+ src?: string;
255
+ controls?: boolean;
256
+ autoplay?: boolean;
257
+ loop?: boolean;
258
+ muted?: boolean;
259
+ }
260
+ type HtmlCanvas = WfuiAttributes<HTMLCanvasElement> & {
261
+ width?: number;
262
+ height?: number;
263
+ };
264
+ type HtmlSvg = WfuiAttributes<SVGSVGElement> & {
265
+ viewBox?: string;
266
+ xmlns?: string;
267
+ fill?: string;
268
+ width?: string | number;
269
+ height?: string | number;
270
+ };
271
+ interface HtmlLink extends WfuiAttributes<HTMLLinkElement> {
272
+ rel?: string;
273
+ href?: string;
274
+ type?: string;
275
+ media?: string;
276
+ }
277
+ interface HtmlStyle extends WfuiAttributes<HTMLStyleElement> {
278
+ scoped?: boolean;
279
+ media?: string;
280
+ }
281
+ interface HtmlScript extends WfuiAttributes<HTMLScriptElement> {
282
+ src?: string;
283
+ type?: string;
284
+ async?: boolean;
285
+ defer?: boolean;
286
+ }
287
+ type HtmlStrong = WfuiAttributes<HTMLElement>;
288
+ type HtmlEm = WfuiAttributes<HTMLElement>;
289
+ type HtmlB = WfuiAttributes<HTMLElement>;
290
+ type HtmlI = WfuiAttributes<HTMLElement>;
291
+ type HtmlU = WfuiAttributes<HTMLElement>;
292
+ type HtmlS = WfuiAttributes<HTMLElement>;
293
+ type HtmlMark = WfuiAttributes<HTMLElement>;
294
+ type HtmlCode = WfuiAttributes<HTMLElement>;
295
+ type HtmlSmall = WfuiAttributes<HTMLElement>;
296
+ type HtmlSub = WfuiAttributes<HTMLElement>;
297
+ type HtmlSup = WfuiAttributes<HTMLElement>;
298
+ type HtmlAbbr = WfuiAttributes<HTMLElement>;
299
+ type HtmlTime = WfuiAttributes<HTMLElement> & {
300
+ datetime?: string;
301
+ };
302
+ type HtmlBr = WfuiAttributes<HTMLBRElement>;
303
+ type HtmlHr = WfuiAttributes<HTMLHRElement>;
304
+ type HtmlWbr = WfuiAttributes<HTMLElement>;
305
+ type HtmlTemplate = WfuiAttributes<HTMLTemplateElement>;
306
+ type HtmlSlot = WfuiAttributes<HTMLSlotElement>;
307
+ type HtmlDetails = WfuiAttributes<HTMLDetailsElement>;
308
+ type HtmlSummary = WfuiAttributes<HTMLElement>;
309
+ type HtmlDialog = WfuiAttributes<HTMLDialogElement>;
310
+ type HtmlIframe = WfuiAttributes<HTMLIFrameElement> & {
311
+ src?: string;
312
+ name?: string;
313
+ width?: string;
314
+ height?: string;
315
+ };
18
316
  }
19
317
  }
20
318
  export declare function setCtx(ctx: WfuiContext | null): void;
21
319
  export declare function getCtx(): WfuiContext | null;
22
320
  export type Component<P = {}> = (props: P, ctx: WfuiContext) => Node;
321
+ /**
322
+ * 包装第三方库为组件 — 元素挂载后执行 setup,返回函数在元素移除时自动清理。
323
+ *
324
+ * 自动创建容器元素 + 自动管理生命周期。
325
+ * 返回标准的 (props, ctx) => Node 组件。
326
+ *
327
+ * ```tsx
328
+ * const PieChart = wrap('div', (el, props: { data: any }, ctx) => {
329
+ * el.style.cssText = 'width:100%;height:300px'
330
+ * const chart = echarts.init(el)
331
+ * chart.setOption(props.data)
332
+ * effect(() => chart.setOption(props.data))
333
+ * return () => chart.dispose()
334
+ * })
335
+ *
336
+ * const CanvasChart = wrap('canvas', (el, props, ctx) => {
337
+ * const chart = new Chart(el, { type: 'line', data: props.data })
338
+ * return () => chart.destroy()
339
+ * })
340
+ *
341
+ * // 在 JSX 中使用
342
+ * function Dashboard() {
343
+ * return <div><PieChart data={salesData} /><CanvasChart data={trendData} /></div>
344
+ * }
345
+ * ```
346
+ */
347
+ export declare function wrap<P = {}>(tagName: string, setup: (el: HTMLElement, props: P, ctx: WfuiContext) => (() => void) | void): Component<P>;
23
348
  export declare function jsx(type: string | Component, props: Record<string, unknown> | null, ...children: unknown[]): Node;
24
349
  export declare function jsxs(type: string | Component, props: Record<string, unknown> | null, ...children: unknown[]): Node;
25
350
  export declare function jsxDEV(type: string | Component, props: Record<string, unknown> | null, _key: string | null, _isStatic: boolean, _source: {
@@ -31,6 +356,42 @@ export declare function Fragment(props: Record<string, unknown> | null, ...child
31
356
  * 直接挂载 DOM(低层 API,一般用 createApp().mount())
32
357
  */
33
358
  export declare function domMount(root: string | Element, app: Node): void;
359
+ /**
360
+ * ErrorBoundary — 捕获子组件渲染时的异常。
361
+ *
362
+ * children 必须是 thunk(函数),延迟执行以便捕获错误。
363
+ *
364
+ * ```tsx
365
+ * <ErrorBoundary fallback={(e) => <p>出错了: {e.message}</p>}>
366
+ * {() => <Dashboard />}
367
+ * </ErrorBoundary>
368
+ * ```
369
+ */
370
+ export declare function ErrorBoundary({ fallback, children }: {
371
+ fallback: (error: Error) => Node;
372
+ children: () => Node;
373
+ }, _ctx: WfuiContext): Node;
374
+ /**
375
+ * Portal — 将组件渲染到父容器之外的 DOM 位置。
376
+ *
377
+ * 适用于 Modal、Dropdown、Tooltip 等需要突破 overflow / z-index 的场景。
378
+ *
379
+ * ```tsx
380
+ * import { createPortal } from 'weifuwu/client'
381
+ *
382
+ * function Modal({ show, children }) {
383
+ * return <Show when={show}>
384
+ * {createPortal(
385
+ * <div class="fixed inset-0 bg-black/50 flex items-center justify-center">
386
+ * {children}
387
+ * </div>,
388
+ * document.body
389
+ * )}
390
+ * </Show>
391
+ * }
392
+ * ```
393
+ */
394
+ export declare function createPortal(node: Node, target: Element): Node;
34
395
  /**
35
396
  * 条件渲染 — when 为 Signal 时响应式切换
36
397
  *