@selkit/dom 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.
- package/LICENSE +21 -0
- package/dist/index.cjs +685 -0
- package/dist/index.d.cts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +653 -0
- package/package.json +49 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SelkitController, SelkitConfig, SelkitOption } from '@selkit/core';
|
|
2
|
+
|
|
3
|
+
interface SelkitDomConfig<T = unknown> extends SelkitConfig<T> {
|
|
4
|
+
/** class 前綴 預設 "selkit" */
|
|
5
|
+
classPrefix?: string;
|
|
6
|
+
/** 表單欄位名 設定後自動維護 hidden input 讓傳統表單 submit 帶值 */
|
|
7
|
+
name?: string;
|
|
8
|
+
/** 多選時於選項顯示打勾(checkbox 樣式)選項點擊改為 toggle 不隱藏已選 */
|
|
9
|
+
checkboxes?: boolean;
|
|
10
|
+
/** 輸入框寬度隨輸入字數增長(以 size 屬性近似)取代預設的 flex 撐滿 */
|
|
11
|
+
autogrow?: boolean;
|
|
12
|
+
/** 下拉寬度貼齊內容(至少與控制項同寬 可更寬)而非固定等寬 */
|
|
13
|
+
dropdownAutoWidth?: boolean;
|
|
14
|
+
/** 啟用虛擬捲動 大量選項時只渲染可視切片 僅在無分組的扁平清單生效 */
|
|
15
|
+
virtualScroll?: boolean;
|
|
16
|
+
/** 虛擬捲動的單列固定高度 px 預設 36 須與實際樣式高度一致 */
|
|
17
|
+
itemHeight?: number;
|
|
18
|
+
/** 把下拉浮層掛到指定容器(元素或選擇器)逃離 overflow/transform 祖先的裁切 常用 document.body */
|
|
19
|
+
dropdownParent?: HTMLElement | string;
|
|
20
|
+
/** 自訂已選顯示內容(tag 或單值) 回傳字串走 textContent 防 XSS 需 markup(icon 等)請回傳 Node */
|
|
21
|
+
templateSelection?: (option: SelkitOption<T>, meta: {
|
|
22
|
+
index: number;
|
|
23
|
+
multiple: boolean;
|
|
24
|
+
}) => string | Node;
|
|
25
|
+
/** 自訂下拉選項內容 回傳字串走 textContent 防 XSS 需 markup(icon 等)請回傳 Node */
|
|
26
|
+
templateOption?: (option: SelkitOption<T>, meta: {
|
|
27
|
+
index: number;
|
|
28
|
+
active: boolean;
|
|
29
|
+
selected: boolean;
|
|
30
|
+
}) => string | Node;
|
|
31
|
+
}
|
|
32
|
+
interface SelkitDomInstance<T = unknown> {
|
|
33
|
+
readonly controller: SelkitController<T>;
|
|
34
|
+
readonly element: HTMLElement;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
declare class SelkitDom<T> implements SelkitDomInstance<T> {
|
|
38
|
+
#private;
|
|
39
|
+
readonly controller: SelkitController<T>;
|
|
40
|
+
readonly element: HTMLElement;
|
|
41
|
+
constructor(target: HTMLElement | string, config: SelkitDomConfig<T>);
|
|
42
|
+
destroy(): void;
|
|
43
|
+
}
|
|
44
|
+
/** 在指定元素或 selector 對應的元素內建立並掛載一個 Selkit 下拉 */
|
|
45
|
+
declare function createSelkitDom<T = unknown>(host: HTMLElement | string, config?: SelkitDomConfig<T>): SelkitDomInstance<T>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @selkit/dom — 預設輕量定位器(零依賴)
|
|
49
|
+
*
|
|
50
|
+
* 計算邏輯與 DOM 套用分離:computePosition 為純函式(可單元測)
|
|
51
|
+
* attachPositioner 負責讀取 rect、套 style、監聽 scroll/resize
|
|
52
|
+
*/
|
|
53
|
+
type Placement = 'bottom' | 'top';
|
|
54
|
+
interface Rect {
|
|
55
|
+
top: number;
|
|
56
|
+
bottom: number;
|
|
57
|
+
left: number;
|
|
58
|
+
width: number;
|
|
59
|
+
}
|
|
60
|
+
interface PositionResult {
|
|
61
|
+
placement: Placement;
|
|
62
|
+
top: number;
|
|
63
|
+
left: number;
|
|
64
|
+
width: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 依觸發元件位置與下拉高度 決定放上方或下方(空間不足才翻轉)
|
|
68
|
+
* 並回傳套用座標 不做水平翻轉(select 下拉慣例對齊左緣、同寬)
|
|
69
|
+
*/
|
|
70
|
+
declare function computePosition(triggerRect: Rect, dropdownHeight: number, viewportHeight: number, gap?: number): PositionResult;
|
|
71
|
+
interface Positioner {
|
|
72
|
+
update(): void;
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
75
|
+
/** 將 dropdown 定位到 trigger 旁 並隨 scroll/resize 更新 */
|
|
76
|
+
declare function attachPositioner(trigger: HTMLElement, dropdown: HTMLElement, autoWidth?: boolean): Positioner;
|
|
77
|
+
|
|
78
|
+
export { type Placement, type PositionResult, type Positioner, type Rect, SelkitDom as Selkit, SelkitDom, type SelkitDomConfig, type SelkitDomInstance, attachPositioner, computePosition, createSelkitDom, createSelkitDom as sk };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SelkitController, SelkitConfig, SelkitOption } from '@selkit/core';
|
|
2
|
+
|
|
3
|
+
interface SelkitDomConfig<T = unknown> extends SelkitConfig<T> {
|
|
4
|
+
/** class 前綴 預設 "selkit" */
|
|
5
|
+
classPrefix?: string;
|
|
6
|
+
/** 表單欄位名 設定後自動維護 hidden input 讓傳統表單 submit 帶值 */
|
|
7
|
+
name?: string;
|
|
8
|
+
/** 多選時於選項顯示打勾(checkbox 樣式)選項點擊改為 toggle 不隱藏已選 */
|
|
9
|
+
checkboxes?: boolean;
|
|
10
|
+
/** 輸入框寬度隨輸入字數增長(以 size 屬性近似)取代預設的 flex 撐滿 */
|
|
11
|
+
autogrow?: boolean;
|
|
12
|
+
/** 下拉寬度貼齊內容(至少與控制項同寬 可更寬)而非固定等寬 */
|
|
13
|
+
dropdownAutoWidth?: boolean;
|
|
14
|
+
/** 啟用虛擬捲動 大量選項時只渲染可視切片 僅在無分組的扁平清單生效 */
|
|
15
|
+
virtualScroll?: boolean;
|
|
16
|
+
/** 虛擬捲動的單列固定高度 px 預設 36 須與實際樣式高度一致 */
|
|
17
|
+
itemHeight?: number;
|
|
18
|
+
/** 把下拉浮層掛到指定容器(元素或選擇器)逃離 overflow/transform 祖先的裁切 常用 document.body */
|
|
19
|
+
dropdownParent?: HTMLElement | string;
|
|
20
|
+
/** 自訂已選顯示內容(tag 或單值) 回傳字串走 textContent 防 XSS 需 markup(icon 等)請回傳 Node */
|
|
21
|
+
templateSelection?: (option: SelkitOption<T>, meta: {
|
|
22
|
+
index: number;
|
|
23
|
+
multiple: boolean;
|
|
24
|
+
}) => string | Node;
|
|
25
|
+
/** 自訂下拉選項內容 回傳字串走 textContent 防 XSS 需 markup(icon 等)請回傳 Node */
|
|
26
|
+
templateOption?: (option: SelkitOption<T>, meta: {
|
|
27
|
+
index: number;
|
|
28
|
+
active: boolean;
|
|
29
|
+
selected: boolean;
|
|
30
|
+
}) => string | Node;
|
|
31
|
+
}
|
|
32
|
+
interface SelkitDomInstance<T = unknown> {
|
|
33
|
+
readonly controller: SelkitController<T>;
|
|
34
|
+
readonly element: HTMLElement;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
declare class SelkitDom<T> implements SelkitDomInstance<T> {
|
|
38
|
+
#private;
|
|
39
|
+
readonly controller: SelkitController<T>;
|
|
40
|
+
readonly element: HTMLElement;
|
|
41
|
+
constructor(target: HTMLElement | string, config: SelkitDomConfig<T>);
|
|
42
|
+
destroy(): void;
|
|
43
|
+
}
|
|
44
|
+
/** 在指定元素或 selector 對應的元素內建立並掛載一個 Selkit 下拉 */
|
|
45
|
+
declare function createSelkitDom<T = unknown>(host: HTMLElement | string, config?: SelkitDomConfig<T>): SelkitDomInstance<T>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @selkit/dom — 預設輕量定位器(零依賴)
|
|
49
|
+
*
|
|
50
|
+
* 計算邏輯與 DOM 套用分離:computePosition 為純函式(可單元測)
|
|
51
|
+
* attachPositioner 負責讀取 rect、套 style、監聽 scroll/resize
|
|
52
|
+
*/
|
|
53
|
+
type Placement = 'bottom' | 'top';
|
|
54
|
+
interface Rect {
|
|
55
|
+
top: number;
|
|
56
|
+
bottom: number;
|
|
57
|
+
left: number;
|
|
58
|
+
width: number;
|
|
59
|
+
}
|
|
60
|
+
interface PositionResult {
|
|
61
|
+
placement: Placement;
|
|
62
|
+
top: number;
|
|
63
|
+
left: number;
|
|
64
|
+
width: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 依觸發元件位置與下拉高度 決定放上方或下方(空間不足才翻轉)
|
|
68
|
+
* 並回傳套用座標 不做水平翻轉(select 下拉慣例對齊左緣、同寬)
|
|
69
|
+
*/
|
|
70
|
+
declare function computePosition(triggerRect: Rect, dropdownHeight: number, viewportHeight: number, gap?: number): PositionResult;
|
|
71
|
+
interface Positioner {
|
|
72
|
+
update(): void;
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
75
|
+
/** 將 dropdown 定位到 trigger 旁 並隨 scroll/resize 更新 */
|
|
76
|
+
declare function attachPositioner(trigger: HTMLElement, dropdown: HTMLElement, autoWidth?: boolean): Positioner;
|
|
77
|
+
|
|
78
|
+
export { type Placement, type PositionResult, type Positioner, type Rect, SelkitDom as Selkit, SelkitDom, type SelkitDomConfig, type SelkitDomInstance, attachPositioner, computePosition, createSelkitDom, createSelkitDom as sk };
|