intable 0.0.4 → 0.0.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.
- package/README.md +261 -15
- package/dist/__uno.css +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +97 -87
- package/dist/hooks/useSelector.d.ts +16 -0
- package/dist/hooks/useSelector.js +35 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.js +184 -153
- package/dist/plugins/CellSelectionPlugin.js +2 -1
- package/dist/plugins/CommandPlugin.js +11 -5
- package/dist/plugins/CopyPastePlugin.js +1 -0
- package/dist/plugins/EditablePlugin.js +1 -0
- package/dist/plugins/ExpandPlugin.d.ts +3 -5
- package/dist/plugins/ExpandPlugin.js +40 -42
- package/dist/plugins/MenuPlugin.js +3 -2
- package/dist/plugins/RenderPlugin/index.js +1 -0
- package/dist/plugins/ResizePlugin.js +1 -0
- package/dist/plugins/RowGroupPlugin.js +4 -4
- package/dist/plugins/RowSelectionPlugin.d.ts +3 -15
- package/dist/plugins/RowSelectionPlugin.js +15 -31
- package/dist/style.css +2 -2
- package/dist/theme/element-plus.scss +5 -0
- package/dist/wc.js +6 -9
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: intable
|
|
3
|
+
description: A high-performance, plugin-based Excel-like table component for SolidJS with virtual scroll, cell editing, validation, copy/paste, row grouping, tree data, column/row drag, merge cells, diff view, and multi-framework support (Vue, React).
|
|
4
|
+
---
|
|
5
|
+
|
|
1
6
|
# intable
|
|
2
7
|
|
|
3
8
|
## 特征
|
|
@@ -10,6 +15,7 @@
|
|
|
10
15
|
- 虚拟滚动
|
|
11
16
|
- 数据分组
|
|
12
17
|
- 行展开
|
|
18
|
+
- 树嵌套
|
|
13
19
|
- 插件易扩展
|
|
14
20
|
- 多框架支持(Vue、React)
|
|
15
21
|
- 多 UI库支持(Antd、ElementPlus)
|
|
@@ -28,7 +34,6 @@ pnpm add intable
|
|
|
28
34
|
**使用**
|
|
29
35
|
|
|
30
36
|
```jsx
|
|
31
|
-
import { render } from 'solid-js/web'
|
|
32
37
|
import Intable from 'intable'
|
|
33
38
|
|
|
34
39
|
const App = () => {
|
|
@@ -47,8 +52,6 @@ const App = () => {
|
|
|
47
52
|
|
|
48
53
|
return <Intable data={data} columns={columns} />
|
|
49
54
|
}
|
|
50
|
-
|
|
51
|
-
render(() => <App />)
|
|
52
55
|
```
|
|
53
56
|
</details>
|
|
54
57
|
|
|
@@ -58,14 +61,14 @@ render(() => <App />)
|
|
|
58
61
|
**安装**
|
|
59
62
|
|
|
60
63
|
```sh
|
|
61
|
-
pnpm add @intable/
|
|
64
|
+
pnpm add @intable/vue
|
|
62
65
|
```
|
|
63
66
|
|
|
64
67
|
**使用**
|
|
65
68
|
|
|
66
69
|
```html
|
|
67
70
|
<template>
|
|
68
|
-
<Intable data=
|
|
71
|
+
<Intable :data="data" :columns="columns" />
|
|
69
72
|
</template>
|
|
70
73
|
|
|
71
74
|
<script setup>
|
|
@@ -99,7 +102,7 @@ pnpm add @intable/react
|
|
|
99
102
|
**使用**
|
|
100
103
|
|
|
101
104
|
```jsx
|
|
102
|
-
import Intable from 'intable'
|
|
105
|
+
import Intable from '@intable/react'
|
|
103
106
|
|
|
104
107
|
const App = () => {
|
|
105
108
|
const columns = [
|
|
@@ -122,12 +125,255 @@ const App = () => {
|
|
|
122
125
|
|
|
123
126
|
## Props
|
|
124
127
|
|
|
125
|
-
| 属性名 | 描述 | 类型 | 默认值
|
|
126
|
-
| ------------ | ------------ | ------------------------------- |
|
|
127
|
-
| data | 数据 | any[] |
|
|
128
|
-
| columns | 展示列 | Column[] |
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
128
|
+
| 属性名 | 描述 | 类型 | 默认值 |
|
|
129
|
+
| ------------ | ------------ | ------------------------------- | ------- |
|
|
130
|
+
| data | 数据 | any[] | |
|
|
131
|
+
| columns | 展示列 | Column[] | |
|
|
132
|
+
| rowKey | 行唯一键字段 | string | `'id'` |
|
|
133
|
+
| index | 显示序号 | boolean | false |
|
|
134
|
+
| border | 显示纵向边框 | boolean | false |
|
|
135
|
+
| stickyHeader | 表头吸顶 | boolean | false |
|
|
136
|
+
| size | 尺寸 | `'large' \| 'default' \| 'small'` | — |
|
|
137
|
+
| plugins | 插件列表 | Plugin[] | `[]` |
|
|
138
|
+
|
|
139
|
+
## Column
|
|
140
|
+
|
|
141
|
+
| 属性名 | 描述 | 类型 |
|
|
142
|
+
| -------- | ---------------------- | ----------------------------- |
|
|
143
|
+
| id | 字段名,对应数据 key | string \| symbol |
|
|
144
|
+
| name | 表头显示名称 | string |
|
|
145
|
+
| width | 列宽(px) | number |
|
|
146
|
+
| fixed | 固定列 | `'left' \| 'right'` |
|
|
147
|
+
| render | 自定义渲染器 | `string \| Render` |
|
|
148
|
+
| enum | 枚举映射(用于渲染) | `Record<string,any> \| {label?,value}[]` |
|
|
149
|
+
| editable | 是否可编辑 | boolean |
|
|
150
|
+
| editor | 编辑器类型或自定义实现 | `string \| Editor` |
|
|
151
|
+
| resizable| 是否允许调整列宽 | boolean |
|
|
152
|
+
|
|
153
|
+
## 插件
|
|
154
|
+
|
|
155
|
+
插件通过 `plugins` 属性传入,部分插件需从对应路径手动引入。
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### VirtualScrollPlugin — 虚拟滚动
|
|
160
|
+
|
|
161
|
+
大数据量下只渲染可见行列,显著提升性能。
|
|
162
|
+
|
|
163
|
+
```jsx
|
|
164
|
+
import { VirtualScrollPlugin } from 'intable/plugins/VirtualScrollPlugin'
|
|
165
|
+
|
|
166
|
+
<Intable
|
|
167
|
+
plugins={[VirtualScrollPlugin]}
|
|
168
|
+
virtual={{
|
|
169
|
+
y: { estimateSize: () => 40, overscan: 10 }, // 行虚拟化参数
|
|
170
|
+
x: { overscan: 5 }, // 列虚拟化参数
|
|
171
|
+
}}
|
|
172
|
+
/>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### EditablePlugin — 单元格编辑
|
|
178
|
+
|
|
179
|
+
在 Column 上设置 `editable: true` 开启单元格编辑,双击或输入字符进入编辑状态。
|
|
180
|
+
|
|
181
|
+
```jsx
|
|
182
|
+
const columns = [
|
|
183
|
+
{ id: 'name', name: '姓名', editable: true },
|
|
184
|
+
{ id: 'age', name: '年龄', editable: true, editor: 'number' },
|
|
185
|
+
{ id: 'type', name: '类型', editable: true, editor: 'select', enum: { 1: 'A', 2: 'B' } },
|
|
186
|
+
{ id: 'date', name: '日期', editable: true, editor: 'date' },
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
<Intable columns={columns} onDataChange={setData} />
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
内置编辑器类型:`text`(默认)、`number`、`select`、`date`、`time`、`datetime`、`switch`、`checkbox`、`rate`、`color`、`file`。
|
|
193
|
+
|
|
194
|
+
搭配 UI 库插件可直接使用对应组件:
|
|
195
|
+
- **Antd**:`import { AntdPlugin } from '@intable/react/plugins/antd'`
|
|
196
|
+
- **Element Plus**:`import { ElementPlusPlugin } from '@intable/vue/plugins/element-plus'`
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
### RowSelectionPlugin — 行选择
|
|
201
|
+
|
|
202
|
+
```jsx
|
|
203
|
+
<Intable
|
|
204
|
+
rowSelection={{
|
|
205
|
+
enable: true,
|
|
206
|
+
multiple: true, // 多选,默认 true
|
|
207
|
+
value: selectedRows, // 受控选中值
|
|
208
|
+
selectable: row => row.age > 18, // 可选条件
|
|
209
|
+
onChange: rows => setSelected(rows),
|
|
210
|
+
}}
|
|
211
|
+
/>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### ExpandPlugin — 行展开
|
|
217
|
+
|
|
218
|
+
点击行首箭头展开自定义内容区域。
|
|
219
|
+
|
|
220
|
+
```jsx
|
|
221
|
+
<Intable
|
|
222
|
+
expand={{
|
|
223
|
+
enable: true,
|
|
224
|
+
render: ({ data, y }) => <div>详情:{data.name}</div>,
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
### RowGroupPlugin — 行分组
|
|
232
|
+
|
|
233
|
+
按指定字段对行进行分级树形分组,支持展开/折叠。
|
|
234
|
+
|
|
235
|
+
```jsx
|
|
236
|
+
<Intable
|
|
237
|
+
rowGroup={{ fields: ['type', 'subType'] }}
|
|
238
|
+
/>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### TreePlugin — 树形数据
|
|
244
|
+
|
|
245
|
+
渲染嵌套 `children` 字段的树状数据,支持展开/折叠,自动缩进。
|
|
246
|
+
|
|
247
|
+
```jsx
|
|
248
|
+
const data = [
|
|
249
|
+
{ id: 1, name: '总部', children: [
|
|
250
|
+
{ id: 2, name: '研发部' },
|
|
251
|
+
{ id: 3, name: '产品部', children: [
|
|
252
|
+
{ id: 4, name: '设计组' },
|
|
253
|
+
]},
|
|
254
|
+
]},
|
|
255
|
+
]
|
|
256
|
+
|
|
257
|
+
<Intable
|
|
258
|
+
tree={{ children: 'children' }} // 子节点字段名,默认 'children'
|
|
259
|
+
data={data}
|
|
260
|
+
columns={[{ id: 'name', name: '名称' }]}
|
|
261
|
+
/>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
### ResizePlugin — 调整列宽 / 行高
|
|
267
|
+
|
|
268
|
+
拖动表头右侧边框调整列宽,拖动行底部边框调整行高。
|
|
269
|
+
|
|
270
|
+
```jsx
|
|
271
|
+
<Intable
|
|
272
|
+
resizable={{
|
|
273
|
+
col: { enable: true, min: 60, max: 600 },
|
|
274
|
+
row: { enable: true, min: 28, max: 200 },
|
|
275
|
+
}}
|
|
276
|
+
onColumnsChange={cols => setColumns(cols)}
|
|
277
|
+
/>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
也可在单列上单独控制:
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
{ id: 'name', name: '姓名', resizable: false } // 禁止该列拖拽
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
### DragPlugin — 列 / 行拖拽排序
|
|
289
|
+
|
|
290
|
+
长按后拖拽列标题或行首单元格可重新排序。
|
|
291
|
+
|
|
292
|
+
```jsx
|
|
293
|
+
<Intable
|
|
294
|
+
colDrag={true} // 开启列拖拽
|
|
295
|
+
rowDrag={true} // 开启行拖拽
|
|
296
|
+
onColumnsChange={cols => setColumns(cols)}
|
|
297
|
+
/>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
### HistoryPlugin — 撤销 / 重做
|
|
303
|
+
|
|
304
|
+
记录数据变更历史,支持 `Ctrl+Z` / `Ctrl+Y`。
|
|
305
|
+
|
|
306
|
+
```jsx
|
|
307
|
+
import { HistoryPlugin } from 'intable/plugins/HistoryPlugin'
|
|
308
|
+
|
|
309
|
+
<Intable plugins={[HistoryPlugin]} />
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
通过命令调用:
|
|
313
|
+
```js
|
|
314
|
+
store.history.undo()
|
|
315
|
+
store.history.redo()
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
### DiffPlugin — 数据差异对比
|
|
321
|
+
|
|
322
|
+
将当前数据与快照进行比较,高亮新增/删除/修改行,支持提交。
|
|
323
|
+
|
|
324
|
+
```jsx
|
|
325
|
+
import { DiffPlugin } from 'intable/plugins/DiffPlugin'
|
|
326
|
+
|
|
327
|
+
<Intable
|
|
328
|
+
plugins={[DiffPlugin]}
|
|
329
|
+
diff={{
|
|
330
|
+
added: true, // 高亮新增行,默认 true
|
|
331
|
+
removed: true, // 高亮删除行,默认 true
|
|
332
|
+
changed: true, // 高亮修改行,默认 true
|
|
333
|
+
onCommit: (data, { added, removed, changed }) => save(data),
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
`Ctrl+S` 触发提交,或通过命令:
|
|
339
|
+
```js
|
|
340
|
+
store.commands.diffCommit()
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### CellMergePlugin — 单元格合并
|
|
346
|
+
|
|
347
|
+
通过 `merge` 回调或 Column 的 `mergeRow` 快捷属性合并相邻单元格。
|
|
348
|
+
|
|
349
|
+
```jsx
|
|
350
|
+
// 方式一:全局 merge 回调
|
|
351
|
+
<Intable
|
|
352
|
+
merge={(row, col, y, x) => {
|
|
353
|
+
if (col.id === 'name') {
|
|
354
|
+
let rowspan = 1
|
|
355
|
+
while (data[y + rowspan]?.name === row.name) rowspan++
|
|
356
|
+
return rowspan > 1 ? { rowspan } : null
|
|
357
|
+
}
|
|
358
|
+
}}
|
|
359
|
+
/>
|
|
360
|
+
|
|
361
|
+
// 方式二:列级 mergeRow 快捷属性(自动合并相邻等值行)
|
|
362
|
+
const columns = [
|
|
363
|
+
{ id: 'type', name: '类型', mergeRow: true },
|
|
364
|
+
{ id: 'name', name: '名称' },
|
|
365
|
+
]
|
|
366
|
+
<Intable columns={columns} />
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
### CellSelectionPlugin — 单元格多选
|
|
372
|
+
|
|
373
|
+
鼠标拖拽或 `Shift+点击` 选择矩形区域,箭头键移动焦点。
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
### CopyPastePlugin — 复制粘贴
|
|
378
|
+
|
|
379
|
+
`Ctrl+C` 复制选中区域为 TSV 格式,`Ctrl+V` 粘贴。
|
package/dist/__uno.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--un-bg-opacity:100%;--un-content:"";--un-translate-x:initial;--un-translate-y:initial;--un-translate-z:initial;--un-text-opacity:100%;--un-border-opacity:100%;--un-space-y-reverse:initial;--un-space-x-reverse:initial;--un-outline-style:solid;--un-outline-opacity:100%;--un-leading:initial}}@property --un-leading{syntax:"*";inherits:false}@property --un-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --un-outline-opacity{syntax:"<percentage>";inherits:false;initial-value:100%}@property --un-bg-opacity{syntax:"<percentage>";inherits:false;initial-value:100%}@property --un-translate-x{syntax:"*";inherits:false;initial-value:0}@property --un-translate-y{syntax:"*";inherits:false;initial-value:0}@property --un-translate-z{syntax:"*";inherits:false;initial-value:0}:root,:host{--spacing:.25rem;--colors-gray-DEFAULT:#99a1af;--text-sm-fontSize:.875rem;--text-sm-lineHeight:1.25rem;--radius-sm:.25rem;--colors-blue-DEFAULT:#54a2ff;--font-sans:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--default-font-family:var(--font-sans);--default-monoFont-family:var(--font-mono)}@supports (color:lab(0% 0 0)){:root,:host{--colors-gray-DEFAULT:lab(65.9269% -.832707 -8.17474);--colors-blue-DEFAULT:lab(65.0361% -1.42062 -56.9803)}}*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-featureSettings,normal);font-variation-settings:var(--default-font-variationSettings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-monoFont-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-monoFont-featureSettings,normal);font-variation-settings:var(--default-monoFont-variationSettings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden~=until-found])){display:none!important}.container{width:100%}.aic{align-items:center}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.text-3\.5{font-size:.875rem}.lh-\[1\]{--un-leading:1;line-height:1}.m9{margin:36px}.mx-1{margin-inline:4px}.mx-3\!{margin-inline:12px!important}.my-1{margin-block:4px}.ml{margin-left:16px}.ml-\.5{margin-left:2px}.ml-1{margin-left:4px}.mr--1{margin-right:-4px}.mr-1{margin-right:4px}.mr-2{margin-right:8px}.mr-2\.5{margin-right:10px}.p-1{padding:4px}.px,.px-4{padding-inline:16px}.px-2{padding-inline:8px}.py-1{padding-block:4px}.py-2{padding-block:8px}.pl-1{padding-left:4px}.pr-4{padding-right:16px}.ps{padding-inline-start:16px}.outline-0{outline-style:var(--un-outline-style);outline-width:0}.outline-2{outline-style:var(--un-outline-style);outline-width:2px}.outline-blue{outline-color:color-mix(in srgb,var(--colors-blue-DEFAULT)var(--un-outline-opacity),transparent)}.b{border-width:1px}.rd-2{border-radius:.5rem}.rd-sm{border-radius:var(--radius-sm)}.bg-\#dafaea{background-color:color-mix(in oklab,#dafaea var(--un-bg-opacity),transparent)}.bg-\#ffe8e8{background-color:color-mix(in oklab,#ffe8e8 var(--un-bg-opacity),transparent)}.bg-\#fff{background-color:color-mix(in oklab,#fff var(--un-bg-opacity),transparent)}.bg-gray\/20{background-color:color-mix(in srgb,var(--colors-gray-DEFAULT)20%,transparent)}.op-75{opacity:.75}.op40{opacity:.4}.flex{display:flex}.flex-shrink-0{flex-shrink:0}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.gap-2{gap:8px}.size-4\!{width:16px!important;height:16px!important}.size-full{width:100%;height:100%}.h-1\!{height:4px!important}.h-a\!{height:auto!important}.h-full{height:100%}.max-h-100{max-height:400px}.min-h-40{min-height:160px}.min-h-a\!{min-height:auto!important}.w-10px\!{width:10px!important}.after\:h-1:after{height:4px}.after\:w-1:after{width:4px}.inline{display:inline}.block{display:block}.cursor-s-resize{cursor:s-resize}.cursor-w-resize{cursor:w-resize}.resize-none{resize:none}.select-none{-webkit-user-select:none;user-select:none}.translate-x-1\/2{--un-translate-x:50%;translate:var(--un-translate-x)var(--un-translate-y)}.transform{transform:var(--un-rotate-x)var(--un-rotate-y)var(--un-rotate-z)var(--un-skew-x)var(--un-skew-y)}.items-center{align-items:center}.box-border{box-sizing:border-box}.bottom-0{bottom:0}.left-0{left:0}.right-0{right:0}.top-0{top:0}.justify-end\!{justify-content:flex-end!important}.justify-center{justify-content:center}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.z-1{z-index:1}.z-9{z-index:9}.overflow-auto{overflow:auto}.table{display:table}.table-cell{display:table-cell}@supports (color:color-mix(in lab, red, red)){.outline-blue{outline-color:color-mix(in oklab,var(--colors-blue-DEFAULT)var(--un-outline-opacity),transparent)}.bg-gray\/20{background-color:color-mix(in oklab,var(--colors-gray-DEFAULT)20%,transparent)}}
|
|
1
|
+
@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--un-bg-opacity:100%;--un-content:"";--un-translate-x:initial;--un-translate-y:initial;--un-translate-z:initial;--un-text-opacity:100%;--un-border-opacity:100%;--un-space-y-reverse:initial;--un-space-x-reverse:initial;--un-outline-style:solid;--un-outline-opacity:100%;--un-leading:initial}}@property --un-leading{syntax:"*";inherits:false}@property --un-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --un-outline-opacity{syntax:"<percentage>";inherits:false;initial-value:100%}@property --un-bg-opacity{syntax:"<percentage>";inherits:false;initial-value:100%}@property --un-translate-x{syntax:"*";inherits:false;initial-value:0}@property --un-translate-y{syntax:"*";inherits:false;initial-value:0}@property --un-translate-z{syntax:"*";inherits:false;initial-value:0}:root,:host{--spacing:.25rem;--colors-gray-DEFAULT:#99a1af;--text-sm-fontSize:.875rem;--text-sm-lineHeight:1.25rem;--radius-sm:.25rem;--colors-blue-DEFAULT:#54a2ff;--font-sans:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--default-font-family:var(--font-sans);--default-monoFont-family:var(--font-mono)}@supports (color:lab(0% 0 0)){:root,:host{--colors-gray-DEFAULT:lab(65.9269% -.832707 -8.17474);--colors-blue-DEFAULT:lab(65.0361% -1.42062 -56.9803)}}*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-featureSettings,normal);font-variation-settings:var(--default-font-variationSettings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-monoFont-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-monoFont-featureSettings,normal);font-variation-settings:var(--default-monoFont-variationSettings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden~=until-found])){display:none!important}.container{width:100%}.aic{align-items:center}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.text-3\.5{font-size:.875rem}.lh-\[1\]{--un-leading:1;line-height:1}.m9{margin:36px}.mx-1{margin-inline:4px}.mx-3\!{margin-inline:12px!important}.my-1{margin-block:4px}.ml{margin-left:16px}.ml-\.5{margin-left:2px}.ml-1{margin-left:4px}.mr--1{margin-right:-4px}.mr-1{margin-right:4px}.mr-2{margin-right:8px}.mr-2\.5{margin-right:10px}.p-1{padding:4px}.px,.px-4{padding-inline:16px}.px-2{padding-inline:8px}.py-1{padding-block:4px}.py-2{padding-block:8px}.pl-1{padding-left:4px}.pr-4{padding-right:16px}.ps{padding-inline-start:16px}.outline-0{outline-style:var(--un-outline-style);outline-width:0}.outline-2{outline-style:var(--un-outline-style);outline-width:2px}.outline-blue{outline-color:color-mix(in srgb,var(--colors-blue-DEFAULT)var(--un-outline-opacity),transparent)}.b{border-width:1px}.rd-2{border-radius:.5rem}.rd-sm{border-radius:var(--radius-sm)}.bg-\#dafaea{background-color:color-mix(in oklab,#dafaea var(--un-bg-opacity),transparent)}.bg-\#ffe8e8{background-color:color-mix(in oklab,#ffe8e8 var(--un-bg-opacity),transparent)}.bg-\#fff{background-color:color-mix(in oklab,#fff var(--un-bg-opacity),transparent)}.bg-gray\/20{background-color:color-mix(in srgb,var(--colors-gray-DEFAULT)20%,transparent)}.op-75{opacity:.75}.op40{opacity:.4}.flex{display:flex}.flex-shrink-0{flex-shrink:0}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.gap-2{gap:8px}.size-4\!{width:16px!important;height:16px!important}.size-full{width:100%;height:100%}.h-1\!{height:4px!important}.h-a\!{height:auto!important}.h-full{height:100%}.max-h-100{max-height:400px}.min-h-40{min-height:160px}.min-h-a\!{min-height:auto!important}.w-10px\!{width:10px!important}.after\:h-1:after{height:4px}.after\:w-1:after{width:4px}.inline{display:inline}.block{display:block}.cursor-s-resize{cursor:s-resize}.cursor-w-resize{cursor:w-resize}.resize{resize:both}.resize-none{resize:none}.select-none{-webkit-user-select:none;user-select:none}.translate-x-1\/2{--un-translate-x:50%;translate:var(--un-translate-x)var(--un-translate-y)}.transform{transform:var(--un-rotate-x)var(--un-rotate-y)var(--un-rotate-z)var(--un-skew-x)var(--un-skew-y)}.items-center{align-items:center}.box-border{box-sizing:border-box}.bottom-0{bottom:0}.left-0{left:0}.right-0{right:0}.top-0{top:0}.justify-end\!{justify-content:flex-end!important}.justify-center{justify-content:center}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.z-1{z-index:1}.z-9{z-index:9}.overflow-auto{overflow:auto}.table{display:table}.table-cell{display:table-cell}@supports (color:color-mix(in lab, red, red)){.outline-blue{outline-color:color-mix(in oklab,var(--colors-blue-DEFAULT)var(--un-outline-opacity),transparent)}.bg-gray\/20{background-color:color-mix(in oklab,var(--colors-gray-DEFAULT)20%,transparent)}}
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { unFn } from "../utils.js";
|
|
2
|
-
import { $PROXY, createComputed, createEffect, createMemo, createRenderEffect, createRoot, createSignal, mergeProps, on, onCleanup, untrack } from "solid-js";
|
|
2
|
+
import { $PROXY, batch, createComputed, createEffect, createMemo, createRenderEffect, createRoot, createSignal, mergeProps, on, onCleanup, untrack } from "solid-js";
|
|
3
3
|
import { $RAW, createMutable } from "solid-js/store";
|
|
4
4
|
import { isFunction, isPromise, mapValues } from "es-toolkit";
|
|
5
5
|
import { createEventListener, createEventListenerMap } from "@solid-primitives/event-listener";
|
|
@@ -9,139 +9,149 @@ import { makePersisted, storageSync } from "@solid-primitives/storage";
|
|
|
9
9
|
import { createMutationObserver } from "@solid-primitives/mutation-observer";
|
|
10
10
|
import { castArray } from "es-toolkit/compat";
|
|
11
11
|
import { createKeybindingsHandler } from "tinykeys";
|
|
12
|
-
function usePointerDrag(
|
|
13
|
-
|
|
14
|
-
target:
|
|
12
|
+
function usePointerDrag(h, L) {
|
|
13
|
+
L = mergeProps({ preventDefault: !0 }, L), createPointerListeners({
|
|
14
|
+
target: h,
|
|
15
15
|
passive: !1,
|
|
16
|
-
onDown(
|
|
17
|
-
|
|
18
|
-
let [
|
|
19
|
-
|
|
16
|
+
onDown(h) {
|
|
17
|
+
L.preventDefault && h.preventDefault();
|
|
18
|
+
let [R, z] = [h.x, h.y], B, V;
|
|
19
|
+
L.start?.(h, (h) => B = h, (h) => V = h), createRoot((L) => {
|
|
20
20
|
createPointerListeners({
|
|
21
21
|
target: document,
|
|
22
|
-
onMove(
|
|
23
|
-
let [
|
|
24
|
-
|
|
25
|
-
sx:
|
|
26
|
-
sy:
|
|
27
|
-
ox:
|
|
28
|
-
oy:
|
|
22
|
+
onMove(h) {
|
|
23
|
+
let [L, V] = [h.x - R, h.y - z];
|
|
24
|
+
B?.(h, {
|
|
25
|
+
sx: R,
|
|
26
|
+
sy: z,
|
|
27
|
+
ox: L,
|
|
28
|
+
oy: V
|
|
29
29
|
});
|
|
30
30
|
},
|
|
31
31
|
onUp() {
|
|
32
|
-
|
|
32
|
+
V?.(h), L(), B = void 0, V = void 0;
|
|
33
33
|
}
|
|
34
|
-
}), createEventListenerMap(document, { drop:
|
|
34
|
+
}), createEventListenerMap(document, { drop: L });
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
function model(
|
|
40
|
-
let [
|
|
41
|
-
createRenderEffect(() =>
|
|
39
|
+
function model(h, L) {
|
|
40
|
+
let [R, z] = L();
|
|
41
|
+
createRenderEffect(() => h.value = R()), h.addEventListener("input", (h) => z(h.target.value));
|
|
42
42
|
}
|
|
43
|
-
function toSignle(
|
|
44
|
-
return [() =>
|
|
43
|
+
function toSignle(h, L) {
|
|
44
|
+
return [() => h[L], (R) => h[L] = R];
|
|
45
45
|
}
|
|
46
46
|
function useDark() {
|
|
47
|
-
let
|
|
47
|
+
let h = (h) => h == "dark" || R() && !h, L = (h) => h ? "dark" : "light", R = () => window.matchMedia("(prefers-color-scheme: dark)").matches, z = makePersisted(createSignal(R()), {
|
|
48
48
|
name: "color-schema",
|
|
49
49
|
storage: localStorage,
|
|
50
50
|
sync: storageSync,
|
|
51
|
-
serialize:
|
|
52
|
-
deserialize:
|
|
51
|
+
serialize: L,
|
|
52
|
+
deserialize: h
|
|
53
53
|
});
|
|
54
|
-
return createEffect(() => document.documentElement.classList[
|
|
54
|
+
return createEffect(() => document.documentElement.classList[z[0]() ? "add" : "remove"]("dark")), createEffect(() => window.dispatchEvent(new StorageEvent("storage", {
|
|
55
55
|
key: "color-schema",
|
|
56
|
-
newValue:
|
|
57
|
-
}))),
|
|
56
|
+
newValue: L(z[0]())
|
|
57
|
+
}))), z;
|
|
58
58
|
}
|
|
59
|
-
function useMemoAsync(
|
|
60
|
-
let
|
|
59
|
+
function useMemoAsync(h, L) {
|
|
60
|
+
let R = Symbol(), [B, V] = createSignal(L);
|
|
61
61
|
return createComputed(async () => {
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
}) :
|
|
65
|
-
|
|
66
|
-
}),
|
|
62
|
+
let L = h(untrack(B)), z = L instanceof Promise ? await new Promise((h) => {
|
|
63
|
+
L.then(h), onCleanup(() => h(R));
|
|
64
|
+
}) : L;
|
|
65
|
+
z == R || V(() => z);
|
|
66
|
+
}), B;
|
|
67
67
|
}
|
|
68
|
-
function useSignle2(
|
|
69
|
-
let
|
|
70
|
-
let
|
|
71
|
-
return isPromise(
|
|
72
|
-
},
|
|
73
|
-
if (isFunction(
|
|
74
|
-
let
|
|
75
|
-
createComputed(() =>
|
|
68
|
+
function useSignle2(h, L) {
|
|
69
|
+
let R = createSignal(isFunction(h) ? void 0 : h), B = (h) => {
|
|
70
|
+
let R = L?.before?.(h);
|
|
71
|
+
return isPromise(R) ? R.then((L) => L === void 0 ? h : L) : R ?? h;
|
|
72
|
+
}, V = useMemoAsync(() => B(R[0]()));
|
|
73
|
+
if (isFunction(h)) {
|
|
74
|
+
let L = useMemoAsync(() => B(h()));
|
|
75
|
+
createComputed(() => R[1](L()));
|
|
76
76
|
}
|
|
77
|
-
return [
|
|
77
|
+
return [V, R[1]];
|
|
78
78
|
}
|
|
79
79
|
var $MEMO = Symbol();
|
|
80
|
-
function toReactive(
|
|
81
|
-
let
|
|
80
|
+
function toReactive(R) {
|
|
81
|
+
let z = () => unFn(R), B = () => !0, V = (h) => ((h) => typeof h == "function" && $MEMO in h ? h() : h)(z()[h]);
|
|
82
82
|
return new Proxy(Object.create(null), {
|
|
83
|
-
get: (
|
|
84
|
-
set:
|
|
85
|
-
defineProperty: (
|
|
86
|
-
deleteProperty:
|
|
87
|
-
getPrototypeOf: () => Object.getPrototypeOf(
|
|
88
|
-
has: (
|
|
89
|
-
ownKeys: (
|
|
90
|
-
getOwnPropertyDescriptor: (
|
|
83
|
+
get: (h, R, B) => R == $PROXY || R == $RAW ? B : ((h) => typeof h == "function" && $MEMO in h ? h() : h)(z()[R]),
|
|
84
|
+
set: B,
|
|
85
|
+
defineProperty: (h, L, R) => Object.defineProperty(z(), L, R),
|
|
86
|
+
deleteProperty: B,
|
|
87
|
+
getPrototypeOf: () => Object.getPrototypeOf(z()),
|
|
88
|
+
has: (h, R) => R == $PROXY || R in z(),
|
|
89
|
+
ownKeys: (h) => Object.keys(z()),
|
|
90
|
+
getOwnPropertyDescriptor: (h, L) => ({
|
|
91
91
|
enumerable: !0,
|
|
92
92
|
configurable: !0,
|
|
93
93
|
get() {
|
|
94
|
-
return
|
|
94
|
+
return V(L);
|
|
95
95
|
},
|
|
96
|
-
set:
|
|
96
|
+
set: B
|
|
97
97
|
})
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
function useMemo(
|
|
101
|
-
let
|
|
102
|
-
return
|
|
100
|
+
function useMemo(h) {
|
|
101
|
+
let L = createMemo(h);
|
|
102
|
+
return L[$MEMO] = 1, L;
|
|
103
103
|
}
|
|
104
|
-
function useHover(
|
|
105
|
-
let [
|
|
106
|
-
return createEventListener(
|
|
104
|
+
function useHover(h) {
|
|
105
|
+
let [L, R] = createSignal(!1);
|
|
106
|
+
return createEventListener(h, "pointerenter", () => R(!0)), createEventListener(h, "pointerleave", () => R(!1)), L;
|
|
107
107
|
}
|
|
108
|
-
function useMouseDown(
|
|
109
|
-
let [
|
|
110
|
-
return createEventListener(
|
|
108
|
+
function useMouseDown(h) {
|
|
109
|
+
let [L, R] = createSignal(!1);
|
|
110
|
+
return createEventListener(h, "pointerdown", () => R(!0)), createEventListener(document.body, "pointerup", () => R(!1)), L;
|
|
111
111
|
}
|
|
112
|
-
function useClicked(
|
|
113
|
-
let [
|
|
114
|
-
return createEventListener(() =>
|
|
112
|
+
function useClicked(h) {
|
|
113
|
+
let [L, R] = createSignal(!1), z = () => castArray(access(h));
|
|
114
|
+
return createEventListener(() => z().map((h) => h?.getRootNode()), "click", (h) => R(z().some((L) => L?.contains(h.target)))), L;
|
|
115
115
|
}
|
|
116
|
-
function useMutation(
|
|
117
|
-
let
|
|
118
|
-
return createMutationObserver(
|
|
116
|
+
function useMutation(h, L, R) {
|
|
117
|
+
let z = createSignal(R());
|
|
118
|
+
return createMutationObserver(h, L, (h) => z[1](R())), z[0];
|
|
119
119
|
}
|
|
120
|
-
function useTinykeys(
|
|
121
|
-
createEventListener(
|
|
122
|
-
|
|
120
|
+
function useTinykeys(h, L) {
|
|
121
|
+
createEventListener(h, "keydown", createKeybindingsHandler({ ...mapValues(L, (h) => (L) => {
|
|
122
|
+
L.preventDefault(), h(L);
|
|
123
123
|
}) }));
|
|
124
124
|
}
|
|
125
|
-
function useHistory([
|
|
126
|
-
let
|
|
125
|
+
function useHistory([h, L]) {
|
|
126
|
+
let R = 1, z = createMutable({
|
|
127
127
|
index: -1,
|
|
128
128
|
history: []
|
|
129
|
-
}),
|
|
130
|
-
return createRenderEffect(on(
|
|
131
|
-
if (
|
|
132
|
-
if (!
|
|
133
|
-
|
|
129
|
+
}), B = () => (z.index = 0, z.history = [h()]), V = () => z.index > 0, H = () => z.index < z.history.length - 1;
|
|
130
|
+
return createRenderEffect(on(h, (h) => {
|
|
131
|
+
if (h != null) {
|
|
132
|
+
if (!R) return R = 1;
|
|
133
|
+
H() && (z.history = z.history.slice(0, z.index + 1)), z.history[++z.index] = h;
|
|
134
134
|
}
|
|
135
135
|
})), {
|
|
136
|
-
undo: () =>
|
|
137
|
-
redo: () =>
|
|
138
|
-
clear:
|
|
136
|
+
undo: () => V() && ((R = 0) || L(z.history[--z.index])),
|
|
137
|
+
redo: () => H() && ((R = 0) || L(z.history[++z.index])),
|
|
138
|
+
clear: B,
|
|
139
139
|
get index() {
|
|
140
|
-
return
|
|
140
|
+
return z.index;
|
|
141
141
|
},
|
|
142
142
|
get history() {
|
|
143
|
-
return
|
|
143
|
+
return z.history;
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
function useMemoState(h) {
|
|
148
|
+
let L = createMutable({});
|
|
149
|
+
return createComputed(() => {
|
|
150
|
+
let z = h();
|
|
151
|
+
untrack(() => batch(() => {
|
|
152
|
+
for (let h in L) h in z || delete L[h];
|
|
153
|
+
Object.assign(L, z);
|
|
154
|
+
}));
|
|
155
|
+
}), L;
|
|
156
|
+
}
|
|
157
|
+
export { model, toReactive, toSignle, useClicked, useDark, useHistory, useHover, useMemo, useMemoAsync, useMemoState, useMouseDown, useMutation, usePointerDrag, useSignle2, useTinykeys };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface UseSelectorOpt<T> {
|
|
2
|
+
value?: T;
|
|
3
|
+
onChange?: (v: T) => void;
|
|
4
|
+
multiple?: boolean;
|
|
5
|
+
selectable?: (v: any) => boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function useSelector<T = any>(opt: UseSelectorOpt<T>): {
|
|
8
|
+
clear: () => void;
|
|
9
|
+
set: (v: T) => void;
|
|
10
|
+
has: (key: T | Set<T>) => boolean;
|
|
11
|
+
add: (v: T) => void;
|
|
12
|
+
del: (v: T) => void;
|
|
13
|
+
toggle: (v: T) => void;
|
|
14
|
+
readonly value: any;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createMemo, createSelector, createSignal } from "solid-js";
|
|
2
|
+
function useSelector(r) {
|
|
3
|
+
let { value: i, onChange: a, multiple: o = !1, selectable: s } = r, [c, l] = createSignal((() => o ? i ? new Set(Array.isArray(i) ? i : [i]) : /* @__PURE__ */ new Set() : i)()), u = (e) => s ? s(e) : !0, d = () => {
|
|
4
|
+
o ? (l(/* @__PURE__ */ new Set()), a?.([])) : (l(void 0), a?.(void 0));
|
|
5
|
+
}, f = (e) => {
|
|
6
|
+
if (u(e)) if (o) {
|
|
7
|
+
let n = new Set(Array.isArray(e) ? e : [e]);
|
|
8
|
+
l(n), a?.(Array.from(n));
|
|
9
|
+
} else l(e), a?.(e);
|
|
10
|
+
}, p = createSelector(c, (e, n) => o ? n.has(e) : e === n), m = (e) => {
|
|
11
|
+
if (u(e)) if (o) {
|
|
12
|
+
let n = new Set(c());
|
|
13
|
+
n.add(e), l(n), a?.(Array.from(n));
|
|
14
|
+
} else l(e), a?.(e);
|
|
15
|
+
}, h = (e) => {
|
|
16
|
+
if (o) {
|
|
17
|
+
let n = new Set(c());
|
|
18
|
+
n.delete(e), l(n), a?.(Array.from(n));
|
|
19
|
+
} else c() === e && (l(void 0), a?.(void 0));
|
|
20
|
+
}, g = (e) => {
|
|
21
|
+
p(e) ? h(e) : m(e);
|
|
22
|
+
}, _ = createMemo(() => o ? Array.from(c()) : c());
|
|
23
|
+
return {
|
|
24
|
+
clear: d,
|
|
25
|
+
set: f,
|
|
26
|
+
has: p,
|
|
27
|
+
add: m,
|
|
28
|
+
del: h,
|
|
29
|
+
toggle: g,
|
|
30
|
+
get value() {
|
|
31
|
+
return _();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { useSelector };
|