intable 0.0.1 → 0.0.3

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 CHANGED
@@ -7,16 +7,126 @@
7
7
  - 单元格编辑、数据校验
8
8
  - 列宽、行高可拖动
9
9
  - 虚拟滚动
10
- - 历史回滚
11
- <!-- - 合并单元格 -->
12
- <!-- - 表头分组 -->
13
10
  - 数据分组
14
11
  - 行展开
15
- <!-- - tree -->
16
- <!-- - 过滤、排序 -->
17
- - Diff 数据对比
18
- <!-- - 导出 Excel -->
19
12
  - 插件易扩展
20
13
  - 多框架支持(Vue、React)
14
+ - 多 UI库支持(Antd、ElementPlus)
21
15
 
22
- ## 快速开始
16
+ ## 快速开始
17
+
18
+ <details>
19
+ <summary>solid-js</summary>
20
+
21
+ **安装**
22
+
23
+ ```sh
24
+ pnpm add intable
25
+ ```
26
+
27
+ **使用**
28
+
29
+ ```jsx
30
+ import { render } from 'solid-js/web'
31
+ import Intable from 'intable'
32
+
33
+ const App = () => {
34
+ const columns = [
35
+ { id: 'name', name: '名称' },
36
+ { id: 'date', name: '日期' },
37
+ { id: 'address', name: '地址' },
38
+ ]
39
+
40
+ const data = [
41
+ { date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
42
+ { date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
43
+ { date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
44
+ { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
45
+ ]
46
+
47
+ return <Intable data={data} columns={columns} />
48
+ }
49
+
50
+ render(() => <App />)
51
+ ```
52
+ </details>
53
+
54
+ <details>
55
+ <summary>vue</summary>
56
+
57
+ **安装**
58
+
59
+ ```sh
60
+ pnpm add @intable/react
61
+ ```
62
+
63
+ **使用**
64
+
65
+ ```html
66
+ <template>
67
+ <Intable data={data} columns={columns} />
68
+ </template>
69
+
70
+ <script setup>
71
+ import Intable from '@intable/vue'
72
+
73
+ const columns = [
74
+ { id: 'name', name: '名称' },
75
+ { id: 'date', name: '日期' },
76
+ { id: 'address', name: '地址' },
77
+ ]
78
+
79
+ const data = [
80
+ { date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
81
+ { date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
82
+ { date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
83
+ { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
84
+ ]
85
+ </script>
86
+ ```
87
+ </details>
88
+
89
+ <details>
90
+ <summary>react</summary>
91
+
92
+ **安装**
93
+
94
+ ```sh
95
+ pnpm add @intable/react
96
+ ```
97
+
98
+ **使用**
99
+
100
+ ```jsx
101
+ import Intable from 'intable'
102
+
103
+ const App = () => {
104
+ const columns = [
105
+ { id: 'name', name: '名称' },
106
+ { id: 'date', name: '日期' },
107
+ { id: 'address', name: '地址' },
108
+ ]
109
+
110
+ const data = [
111
+ { date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
112
+ { date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
113
+ { date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
114
+ { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles' },
115
+ ]
116
+
117
+ return <Intable data={data} columns={columns} />
118
+ }
119
+ ```
120
+ </details>
121
+
122
+ ## Props
123
+
124
+ | 属性名 | 描述 | 类型 | 默认值 |
125
+ | ------------ | ------------ | ------------------------------- | ------ |
126
+ | data | 数据 | any[] | |
127
+ | columns | 展示列 | Column[] | |
128
+ | index | 显示序号 | bool | false |
129
+ | border | 显示纵向边框 | bool | false |
130
+ | stickyHeader | 表头吸顶 | bool | false |
131
+ | size | 尺寸 | 'large' \| 'default' \| 'small' | false |
132
+ | rowSelection | 启用行选择 | [@see]() | false |
package/dist/__uno.css ADDED
@@ -0,0 +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: 0.25rem;--colors-gray-DEFAULT: oklch(70.7% 0.022 261.325);--text-sm-fontSize: 0.875rem;--text-sm-lineHeight: 1.25rem;--radius-sm: 0.25rem;--colors-blue-DEFAULT: oklch(70.7% 0.165 254.624);--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);}/* 1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4) 2. Remove default margins and padding 3. Reset all borders.*/*,::after,::before,::backdrop,::file-selector-button { box-sizing: border-box; /* 1 */ margin: 0; /* 2 */ padding: 0; /* 2 */ border: 0 solid; /* 3 */}/* 1. Use a consistent sensible line-height in all browsers. 2. Prevent adjustments of font size after orientation changes in iOS. 3. Use a more readable tab size. 4. Use the user's configured `sans` font-family by default. 5. Use the user's configured `sans` font-feature-settings by default. 6. Use the user's configured `sans` font-variation-settings by default. 7. Disable tap highlights on iOS.*/html,:host { line-height: 1.5; /* 1 */ -webkit-text-size-adjust: 100%; /* 2 */ tab-size: 4; /* 3 */ 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' ); /* 4 */ font-feature-settings: var(--default-font-featureSettings, normal); /* 5 */ font-variation-settings: var(--default-font-variationSettings, normal); /* 6 */ -webkit-tap-highlight-color: transparent; /* 7 */}/* 1. Add the correct height in Firefox. 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) 3. Reset the default border style to a 1px solid border.*/hr { height: 0; /* 1 */ color: inherit; /* 2 */ border-top-width: 1px; /* 3 */}/* Add the correct text decoration in Chrome, Edge, and Safari.*/abbr:where([title]) { -webkit-text-decoration: underline dotted; text-decoration: underline dotted;}/* Remove the default font size and weight for headings.*/h1,h2,h3,h4,h5,h6 { font-size: inherit; font-weight: inherit;}/* Reset links to optimize for opt-in styling instead of opt-out.*/a { color: inherit; -webkit-text-decoration: inherit; text-decoration: inherit;}/* Add the correct font weight in Edge and Safari.*/b,strong { font-weight: bolder;}/* 1. Use the user's configured `mono` font-family by default. 2. Use the user's configured `mono` font-feature-settings by default. 3. Use the user's configured `mono` font-variation-settings by default. 4. Correct the odd `em` font sizing in all browsers.*/code,kbd,samp,pre { font-family: var( --default-monoFont-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace ); /* 1 */ font-feature-settings: var(--default-monoFont-featureSettings, normal); /* 2 */ font-variation-settings: var(--default-monoFont-variationSettings, normal); /* 3 */ font-size: 1em; /* 4 */}/* Add the correct font size in all browsers.*/small { font-size: 80%;}/* Prevent `sub` and `sup` elements from affecting the line height in all browsers.*/sub,sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline;}sub { bottom: -0.25em;}sup { top: -0.5em;}/* 1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) 2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) 3. Remove gaps between table borders by default.*/table { text-indent: 0; /* 1 */ border-color: inherit; /* 2 */ border-collapse: collapse; /* 3 */}/* Use the modern Firefox focus style for all focusable elements.*/:-moz-focusring { outline: auto;}/* Add the correct vertical alignment in Chrome and Firefox.*/progress { vertical-align: baseline;}/* Add the correct display in Chrome and Safari.*/summary { display: list-item;}/* Make lists unstyled by default.*/ol,ul,menu { list-style: none;}/* 1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14) 2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210) This can trigger a poorly considered lint error in some tools but is included by design.*/img,svg,video,canvas,audio,iframe,embed,object { display: block; /* 1 */ vertical-align: middle; /* 2 */}/* Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)*/img,video { max-width: 100%; height: auto;}/* 1. Inherit font styles in all browsers. 2. Remove border radius in all browsers. 3. Remove background color in all browsers. 4. Ensure consistent opacity for disabled states in all browsers.*/button,input,select,optgroup,textarea,::file-selector-button { font: inherit; /* 1 */ font-feature-settings: inherit; /* 1 */ font-variation-settings: inherit; /* 1 */ letter-spacing: inherit; /* 1 */ color: inherit; /* 1 */ border-radius: 0; /* 2 */ background-color: transparent; /* 3 */ opacity: 1; /* 4 */}/* Restore default font weight.*/:where(select:is([multiple], [size])) optgroup { font-weight: bolder;}/* Restore indentation.*/:where(select:is([multiple], [size])) optgroup option { padding-inline-start: 20px;}/* Restore space after button.*/::file-selector-button { margin-inline-end: 4px;}/* Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)*/::placeholder { opacity: 1;}/* Set the default placeholder color to a semi-transparent version of the current text color in browsers that do not crash when using `color-mix(…)` with `currentcolor`. (https://github.com/tailwindlabs/tailwindcss/issues/17194)*/@supports (not (-webkit-appearance: -apple-pay-button)) /* Not Safari */ or (contain-intrinsic-size: 1px) /* Safari 17+ */ { ::placeholder { color: color-mix(in oklab, currentcolor 50%, transparent); }}/* Prevent resizing textareas horizontally by default.*/textarea { resize: vertical;}/* Remove the inner padding in Chrome and Safari on macOS.*/::-webkit-search-decoration { -webkit-appearance: none;}/* 1. Ensure date/time inputs have the same height when empty in iOS Safari. 2. Ensure text alignment can be changed on date/time inputs in iOS Safari.*/::-webkit-date-and-time-value { min-height: 1lh; /* 1 */ text-align: inherit; /* 2 */}/* Prevent height from changing on date/time inputs in macOS Safari when the input is set to `display: block`.*/::-webkit-datetime-edit { display: inline-flex;}/* Remove excess padding from pseudo-elements in date/time inputs to ensure consistent height across browsers.*/::-webkit-datetime-edit-fields-wrapper { padding: 0;}::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field { padding-block: 0;}/* Center dropdown marker shown on inputs with paired `<datalist>`s in Chrome. (https://github.com/tailwindlabs/tailwindcss/issues/18499)*/::-webkit-calendar-picker-indicator { line-height: 1;}/* Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)*/:-moz-ui-invalid { box-shadow: none;}/* Correct the inability to style the border radius in iOS Safari.*/button,input:where([type='button'], [type='reset'], [type='submit']),::file-selector-button { appearance: button;}/* Correct the cursor style of increment and decrement buttons in Safari.*/::-webkit-inner-spin-button,::-webkit-outer-spin-button { height: auto;}/* Make elements with the HTML hidden attribute stay hidden by default.*/[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:0.875rem;}.lh-\[1\]{--un-leading:1;line-height:1;}.m9{margin:calc(var(--spacing) * 9);}.mx-1{margin-inline:calc(var(--spacing) * 1);}.mx-3\!{margin-inline:calc(var(--spacing) * 3) !important;}.my-1{margin-block:calc(var(--spacing) * 1);}.ml{margin-left:calc(var(--spacing) * 4);}.ml-\.5{margin-left:calc(var(--spacing) * 0.5);}.ml-1{margin-left:calc(var(--spacing) * 1);}.mr--1{margin-right:calc(var(--spacing) * -1);}.mr-1{margin-right:calc(var(--spacing) * 1);}.mr-2{margin-right:calc(var(--spacing) * 2);}.mr-2\.5{margin-right:calc(var(--spacing) * 2.5);}.p-1{padding:calc(var(--spacing) * 1);}.px,.px-4{padding-inline:calc(var(--spacing) * 4);}.px-2{padding-inline:calc(var(--spacing) * 2);}.py-1{padding-block:calc(var(--spacing) * 1);}.py-2{padding-block:calc(var(--spacing) * 2);}.pl-1{padding-left:calc(var(--spacing) * 1);}.pr-4{padding-right:calc(var(--spacing) * 4);}.ps{padding-inline-start:calc(var(--spacing) * 4);}.outline-0{outline-style:var(--un-outline-style);outline-width:0px;}.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) /* oklch(70.7% 0.165 254.624) */;}.b{border-width:1px;}.rd-2{border-radius:0.5rem;}.rd-sm{border-radius:var(--radius-sm);}.bg-\#dafaea{background-color:color-mix(in oklab, #dafaea var(--un-bg-opacity), transparent) /* #dafaea */;}.bg-\#ffe8e8{background-color:color-mix(in oklab, #ffe8e8 var(--un-bg-opacity), transparent) /* #ffe8e8 */;}.bg-\#fff{background-color:color-mix(in oklab, #fff var(--un-bg-opacity), transparent) /* #fff */;}.bg-gray\/20{background-color:color-mix(in srgb, var(--colors-gray-DEFAULT) 20%, transparent) /* oklch(70.7% 0.022 261.325) */;}.op-75{opacity:75%;}.op40{opacity:40%;}.flex{display:flex;}.flex-shrink-0{flex-shrink:0;}.flex-col{flex-direction:column;}.flex-wrap{flex-wrap:wrap;}.gap-2{gap:calc(var(--spacing) * 2);}.size-4\!{width:calc(var(--spacing) * 4) !important;height:calc(var(--spacing) * 4) !important;}.size-full{width:100%;height:100%;}.h-1\!{height:calc(var(--spacing) * 1) !important;}.h-a\!{height:auto !important;}.h-full{height:100%;}.max-h-100{max-height:calc(var(--spacing) * 100);}.min-h-40{min-height:calc(var(--spacing) * 40);}.min-h-a\!{min-height:auto !important;}.w-10px\!{width:10px !important;}.after\:h-1::after{height:calc(var(--spacing) * 1);}.after\:w-1::after{width:calc(var(--spacing) * 1);}.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:calc(var(--spacing) * 0);}.left-0{left:calc(var(--spacing) * 0);}.right-0{right:calc(var(--spacing) * 0);}.top-0{top:calc(var(--spacing) * 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) /* oklch(70.7% 0.165 254.624) */;}.bg-gray\/20{background-color:color-mix(in oklab, var(--colors-gray-DEFAULT) 20%, transparent) /* oklch(70.7% 0.022 261.325) */;}}
@@ -7,8 +7,8 @@ import loading_default from "../loading.js";
7
7
  import { className, createComponent, effect, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
8
8
  import { children, createContext, createEffect, createMemo, createSignal, onMount, splitProps, useContext } from "solid-js";
9
9
  import { createMutable } from "solid-js/store";
10
- import { delay } from "es-toolkit";
11
10
  import { combineProps } from "@solid-primitives/props";
11
+ import { delay } from "es-toolkit";
12
12
  import { pointerHover } from "@solid-primitives/pointer";
13
13
  import { isEmpty } from "es-toolkit/compat";
14
14
  import { autoUpdate, createFloating, offset } from "floating-ui-solid";
@@ -1,4 +1,4 @@
1
1
  export declare function createRender({ is, processProps }?: {
2
- processProps?: ((e: any) => any) | undefined;
2
+ processProps?: (e: any) => any;
3
3
  }): (props: any) => import("solid-js").JSX.Element;
4
4
  export declare const Render: (props: any) => import("solid-js").JSX.Element;
@@ -4,17 +4,17 @@ export declare abstract class $Node {
4
4
  get label(): any;
5
5
  abstract getChildren(): $Node[] | undefined;
6
6
  children: $Node[] | undefined;
7
- $children: import("solid-js").Accessor<$Node[] | undefined>;
7
+ $children: import("solid-js").Accessor<$Node[]>;
8
8
  parent: $Node | undefined;
9
9
  $parent: import("solid-js").Signal<unknown>;
10
10
  deep: number;
11
11
  $deep: import("solid-js").Accessor<number>;
12
12
  index: number;
13
- $index: import("solid-js").Accessor<number | undefined>;
13
+ $index: import("solid-js").Accessor<number>;
14
14
  prev: $Node | undefined;
15
- $prev: import("solid-js").Accessor<$Node | undefined>;
15
+ $prev: import("solid-js").Accessor<$Node>;
16
16
  next: $Node | undefined;
17
- $next: import("solid-js").Accessor<$Node | undefined>;
17
+ $next: import("solid-js").Accessor<$Node>;
18
18
  root: $Node;
19
19
  $root: any;
20
20
  path: $Node[];
@@ -1,6 +1,7 @@
1
1
  import { type Signal } from 'solid-js';
2
2
  import { type Many, type MaybeAccessor } from '@solid-primitives/utils';
3
- interface UseDragOptions {
3
+ interface UseMoveOptions {
4
+ preventDefault?: boolean;
4
5
  start?(e: PointerEvent, move: (cb: MoveCB) => void, end: (cb: EndCb) => void): void;
5
6
  }
6
7
  type MoveCB = (e: PointerEvent, o: {
@@ -10,11 +11,11 @@ type MoveCB = (e: PointerEvent, o: {
10
11
  oy: number;
11
12
  }) => void;
12
13
  type EndCb = (e: PointerEvent) => void;
13
- export declare function usePointerDrag(el: MaybeAccessor<HTMLElement | undefined>, options: UseDragOptions): void;
14
+ export declare function usePointerDrag(el: MaybeAccessor<HTMLElement | undefined>, options: UseMoveOptions): void;
14
15
  export declare function model(el: any, value: () => [() => string, (v: string) => any]): void;
15
16
  export declare function toSignle<T extends Record<string, any>>(state: T, k: keyof T): ((v: any) => any)[];
16
- export declare function useDark(): [get: import("solid-js").Accessor<boolean>, set: import("solid-js").Setter<boolean>, init: string | Promise<string> | null];
17
- export declare function useMemoAsync<T>(fn: (prev?: T) => Promise<T> | T, init?: Awaited<T>): import("solid-js").Accessor<Awaited<T> | undefined>;
17
+ export declare function useDark(): [get: import("solid-js").Accessor<boolean>, set: import("solid-js").Setter<boolean>, init: string | Promise<string>];
18
+ export declare function useMemoAsync<T>(fn: (prev?: T) => Promise<T> | T, init?: Awaited<T>): import("solid-js").Accessor<Awaited<T>>;
18
19
  export declare function useSignle2<T>(v: T | (() => T), opt?: {
19
20
  before?: (v: T) => Promise<T | void> | T;
20
21
  }): Signal<T>;
@@ -1,8 +1,8 @@
1
1
  import { unFn } from "../utils.js";
2
- import { $PROXY, createComputed, createEffect, createMemo, createRenderEffect, createRoot, createSignal, on, onCleanup } from "solid-js";
2
+ import { $PROXY, 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
- import { createEventListener } from "@solid-primitives/event-listener";
5
+ import { createEventListener, createEventListenerMap } from "@solid-primitives/event-listener";
6
6
  import { createPointerListeners } from "@solid-primitives/pointer";
7
7
  import { access } from "@solid-primitives/utils";
8
8
  import { makePersisted, storageSync } from "@solid-primitives/storage";
@@ -10,11 +10,12 @@ import { createMutationObserver } from "@solid-primitives/mutation-observer";
10
10
  import { castArray } from "es-toolkit/compat";
11
11
  import { createKeybindingsHandler } from "tinykeys";
12
12
  function usePointerDrag(el, options) {
13
+ options = mergeProps({ preventDefault: true }, options);
13
14
  createPointerListeners({
14
15
  target: el,
15
16
  passive: false,
16
17
  onDown(e) {
17
- e.preventDefault();
18
+ options.preventDefault && e.preventDefault();
18
19
  const [sx, sy] = [e.x, e.y];
19
20
  let move;
20
21
  let end;
@@ -38,6 +39,7 @@ function usePointerDrag(el, options) {
38
39
  end = void 0;
39
40
  }
40
41
  });
42
+ createEventListenerMap(document, { drop: dispose });
41
43
  });
42
44
  }
43
45
  });
@@ -71,7 +73,7 @@ function useMemoAsync(fn, init) {
71
73
  const REJECT = Symbol();
72
74
  const [val, setVal] = createSignal(init);
73
75
  createComputed(async () => {
74
- const ret = fn(val());
76
+ const ret = fn(untrack(val));
75
77
  const v = ret instanceof Promise ? await new Promise((resolve) => {
76
78
  ret.then(resolve);
77
79
  onCleanup(() => resolve(REJECT));
@@ -0,0 +1,18 @@
1
+ import { type MaybeAccessor } from '@solid-primitives/utils';
2
+ type Awaitable<T> = T | Promise<T>;
3
+ interface UseSortOption {
4
+ enable?: boolean;
5
+ guideLine: any;
6
+ draggable: (el: HTMLElement) => Awaitable<boolean>;
7
+ dragover: (el: HTMLElement) => boolean;
8
+ children: (el: HTMLElement) => HTMLElement[];
9
+ dragend: () => void;
10
+ }
11
+ export declare const useSort: (el: MaybeAccessor<HTMLElement | undefined>, opt: UseSortOption) => {
12
+ style: any;
13
+ drag: any;
14
+ over: any;
15
+ rel: any;
16
+ type: string;
17
+ };
18
+ export {};
@@ -0,0 +1,106 @@
1
+ import { findAsync } from "../utils.js";
2
+ import { Portal, createComponent, memo, mergeProps, spread, template } from "solid-js/web";
3
+ import { createMutable, reconcile } from "solid-js/store";
4
+ import { createEventListenerMap } from "@solid-primitives/event-listener";
5
+ import { access } from "@solid-primitives/utils";
6
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
7
+ const useSort = (el, opt) => {
8
+ opt = mergeProps({ enable: true }, opt);
9
+ let count = 0;
10
+ createEventListenerMap(() => opt.enable ? access(el) : void 0, {
11
+ async pointerdown(e) {
12
+ const _c = count;
13
+ const drag = await findAsync(e.composedPath(), (e$1) => e$1 instanceof HTMLElement && opt.draggable(e$1));
14
+ if (_c != count) return;
15
+ if (!drag) return;
16
+ e.stopPropagation();
17
+ state.drag = drag;
18
+ state.drag?.setAttribute("draggable", "true");
19
+ },
20
+ pointerup() {
21
+ count++;
22
+ dragend();
23
+ },
24
+ pointermove() {
25
+ count++;
26
+ },
27
+ dragstart(e) {
28
+ e.dataTransfer.setDragImage(document.createElement("img"), 0, 0);
29
+ },
30
+ dragover(e) {
31
+ if (!state.drag) return;
32
+ const over = state.over = e.composedPath().filter((e$1) => e$1 instanceof HTMLElement).find((e$1) => opt.dragover(e$1)) ?? state.over;
33
+ if (!over) return;
34
+ e.preventDefault();
35
+ e.stopPropagation();
36
+ const children = opt.children(over);
37
+ if (children) {
38
+ let i = 0, d = Infinity, s = "";
39
+ children.forEach((el$1, ii) => {
40
+ const display = getComputedStyle(el$1).display;
41
+ const __ = ["table-cell", "inline"].some((e$1) => display.includes(e$1));
42
+ const rect = el$1.getBoundingClientRect();
43
+ if (__) {
44
+ let dd = Math.sqrt((e.clientX - rect.x) ** 2 + (e.clientY - rect.y + rect.height / 2) ** 2);
45
+ if (dd < d) i = ii, d = dd, s = "l";
46
+ dd = Math.sqrt((e.clientX - rect.right) ** 2 + (e.clientY - rect.y + rect.height / 2) ** 2);
47
+ if (dd < d) i = ii, d = dd, s = "r";
48
+ } else {
49
+ let dd = Math.sqrt((e.clientY - rect.y) ** 2 + (e.clientX - rect.x + rect.width / 2) ** 2);
50
+ if (dd < d) i = ii, d = dd, s = "t";
51
+ dd = Math.sqrt((e.clientY - rect.bottom) ** 2 + (e.clientX - rect.x + rect.width / 2) ** 2);
52
+ if (dd < d) i = ii, d = dd, s = "b";
53
+ }
54
+ });
55
+ const rect1 = children[i].getBoundingClientRect();
56
+ const x = s == "l" || s == "r", y = s == "t" || s == "b";
57
+ const size = 3;
58
+ state.style = {
59
+ width: `${y ? rect1.width : size}px`,
60
+ height: `${y ? size : rect1.height}px`,
61
+ translate: `${y ? rect1.x : (s == "l" ? rect1.x : rect1.right) - size / 2}px ${x ? rect1.y : (s == "t" ? rect1.y : rect1.bottom) - size / 2}px`
62
+ };
63
+ state.rel = children[i];
64
+ state.type = s == "l" || s == "t" ? "before" : "after";
65
+ } else {
66
+ const rect1 = over.getBoundingClientRect();
67
+ state.style = {
68
+ width: rect1.width,
69
+ height: rect1.height,
70
+ translate: `${rect1.x}px ${rect1.y}px`
71
+ };
72
+ state.rel = over;
73
+ state.type = "inner";
74
+ }
75
+ },
76
+ dragend() {
77
+ dragend();
78
+ }
79
+ });
80
+ function dragend() {
81
+ state.drag?.removeAttribute("draggable");
82
+ if (state.drag && state.rel) opt.dragend?.();
83
+ reconcile({})(state);
84
+ }
85
+ const state = createMutable({
86
+ style: void 0,
87
+ drag: void 0,
88
+ over: void 0,
89
+ rel: void 0,
90
+ type: ""
91
+ });
92
+ memo(() => memo(() => !!state.style)() && createComponent(Portal, {
93
+ get mount() {
94
+ return access(el);
95
+ },
96
+ get children() {
97
+ var _el$ = _tmpl$();
98
+ spread(_el$, mergeProps(() => opt.guideLine, { get style() {
99
+ return state.style;
100
+ } }), false, false);
101
+ return _el$;
102
+ }
103
+ }));
104
+ return state;
105
+ };
106
+ export { useSort };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { For, type JSX, type Component } from 'solid-js';
2
- import './styles/index.scss';
2
+ import 'virtual:uno.css';
3
+ import './style.scss';
3
4
  import './plugins/CellSelectionPlugin';
4
5
  import './plugins/CopyPastePlugin';
5
6
  import './plugins/EditablePlugin';
@@ -8,8 +9,10 @@ import './plugins/MenuPlugin';
8
9
  import './plugins/CommandPlugin';
9
10
  import './plugins/RowSelectionPlugin';
10
11
  import './plugins/ResizePlugin';
12
+ import './plugins/DragPlugin';
11
13
  export declare const Ctx: import("solid-js").Context<{
12
14
  props: TableProps2;
15
+ store: TableStore;
13
16
  }>;
14
17
  type Requireds<T, K extends keyof T> = Pri<Omit<T, K> & Required<Pick<T, K>>>;
15
18
  type Pri<T> = {
@@ -26,6 +29,7 @@ export interface Plugin {
26
29
  store?: (store: TableStore) => Partial<TableStore> | void;
27
30
  rewriteProps?: ProcessProps;
28
31
  layers?: Component<TableStore>[];
32
+ onMount?: (store: TableStore) => void;
29
33
  }
30
34
  export interface TableProps {
31
35
  columns?: TableColumn[];
@@ -50,22 +54,24 @@ export interface TableProps {
50
54
  }>;
51
55
  EachRows?: typeof For;
52
56
  EachCells?: typeof For<TableColumn[], JSX.Element>;
53
- cellClass?: ((props: Omit<TDProps, 'y'> & {
57
+ cellClass?: ((props: Omit<TDProps, 'y' | 'data'> & {
54
58
  y?: number;
59
+ data?: any;
55
60
  }) => string) | string;
56
- cellStyle?: ((props: Omit<TDProps, 'y'> & {
61
+ cellStyle?: ((props: Omit<TDProps, 'y' | 'data'> & {
57
62
  y?: number;
63
+ data?: any;
58
64
  }) => string) | string;
59
65
  renderer?: (comp: (props: any) => JSX.Element) => ((props: any) => JSX.Element);
60
66
  plugins?: Plugin[];
61
67
  onDataChange?: (data: any[]) => void;
62
68
  }
63
- type THProps = {
69
+ export type THProps = {
64
70
  x: number;
65
71
  col: TableColumn;
66
72
  children: JSX.Element;
67
73
  };
68
- type TDProps = {
74
+ export type TDProps = {
69
75
  x: number;
70
76
  y: number;
71
77
  data: any;
@@ -106,11 +112,12 @@ export interface TableStore extends Obj {
106
112
  height: number;
107
113
  }>[];
108
114
  internal: symbol;
115
+ raw: symbol;
109
116
  props?: TableProps2;
110
117
  rawProps: TableProps;
111
118
  plugins: Plugin[];
112
119
  }
113
- export declare const Table: (props: TableProps) => JSX.Element;
120
+ export declare const Intable: (props: TableProps) => JSX.Element;
121
+ export default Intable;
114
122
  export declare const ScrollPlugin: Plugin;
115
123
  export declare const defaultsPlugins: Plugin[];
116
- export {};
package/dist/index.js CHANGED
@@ -1,23 +1,30 @@
1
1
  import { unFn } from "./utils.js";
2
2
  import { toReactive, useMemo } from "./hooks/index.js";
3
- /* empty css */
3
+ import './style.css';;/* empty css */
4
+ /* empty css */
4
5
  import { CellSelectionPlugin } from "./plugins/CellSelectionPlugin.js";
5
6
  import { ClipboardPlugin } from "./plugins/CopyPastePlugin.js";
6
7
  import { EditablePlugin } from "./plugins/EditablePlugin.js";
7
8
  import { solidComponent } from "./components/utils.js";
8
9
  import { RenderPlugin } from "./plugins/RenderPlugin/index.js";
10
+ import { MenuPlugin } from "./plugins/MenuPlugin.js";
9
11
  import { CommandPlugin } from "./plugins/CommandPlugin.js";
10
12
  import { RowSelectionPlugin } from "./plugins/RowSelectionPlugin.js";
11
- import { createComponent, insert, mergeProps, spread, template, use } from "solid-js/web";
12
- import { For, createComputed, createContext, createEffect, createMemo, createSignal, getOwner, mapArray, mergeProps as mergeProps$1, on, onCleanup, runWithOwner, useContext } from "solid-js";
13
+ import { ResizePlugin } from "./plugins/ResizePlugin.js";
14
+ import { DragPlugin } from "./plugins/DragPlugin.js";
15
+ import { createComponent, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
16
+ import { For, batch, createComputed, createContext, createEffect, createMemo, createSignal, getOwner, mapArray, mergeProps as mergeProps$1, on, onCleanup, onMount, runWithOwner, untrack, useContext } from "solid-js";
13
17
  import { createMutable, reconcile } from "solid-js/store";
14
- import { difference, mapValues, sumBy } from "es-toolkit";
15
18
  import { combineProps } from "@solid-primitives/props";
16
- import { createElementSize } from "@solid-primitives/resize-observer";
19
+ import { difference, mapValues, sumBy } from "es-toolkit";
20
+ import { createElementSize, createResizeObserver } from "@solid-primitives/resize-observer";
17
21
  import { createScrollPosition } from "@solid-primitives/scroll";
18
22
  var _tmpl$ = /* @__PURE__ */ template(`<table>`), _tmpl$2 = /* @__PURE__ */ template(`<thead>`), _tmpl$3 = /* @__PURE__ */ template(`<tbody>`), _tmpl$4 = /* @__PURE__ */ template(`<tr>`), _tmpl$5 = /* @__PURE__ */ template(`<th>`), _tmpl$6 = /* @__PURE__ */ template(`<td>`), _tmpl$7 = /* @__PURE__ */ template(`<div><div class=data-table__layers></div><table class=data-table--table>`);
19
- const Ctx = createContext({ props: {} });
20
- const Table = (props) => {
23
+ const Ctx = createContext({
24
+ props: {},
25
+ store: {}
26
+ });
27
+ const Intable = (props) => {
21
28
  props = mergeProps$1({ rowKey: "id" }, props);
22
29
  const plugins = createMemo(() => [
23
30
  ...defaultsPlugins,
@@ -48,7 +55,13 @@ const Table = (props) => {
48
55
  }));
49
56
  const mProps = toReactive(() => pluginsProps()[pluginsProps().length - 1][0]());
50
57
  store.props = mProps;
51
- const ctx = createMutable({ props: mProps });
58
+ onMount(() => {
59
+ createEffect(mapArray(plugins, (e) => e.onMount?.(store)));
60
+ });
61
+ const ctx = createMutable({
62
+ props: mProps,
63
+ store
64
+ });
52
65
  window.store = store;
53
66
  window.ctx = ctx;
54
67
  return createComponent(Ctx.Provider, {
@@ -117,6 +130,7 @@ var TBody = () => {
117
130
  });
118
131
  } });
119
132
  };
133
+ var src_default = Intable;
120
134
  function BasePlugin() {
121
135
  const omits = {
122
136
  col: null,
@@ -159,13 +173,14 @@ function BasePlugin() {
159
173
  thSizes: [],
160
174
  trs: [],
161
175
  trSizes: [],
162
- internal: Symbol("internal")
176
+ internal: Symbol("internal"),
177
+ raw: Symbol("raw")
163
178
  }),
164
179
  rewriteProps: {
165
180
  data: ({ data = [] }) => data,
166
181
  columns: ({ columns = [] }) => columns,
167
182
  newRow: ({ newRow = () => ({}) }) => newRow,
168
- Table: ({ Table: Table$1 = table }, { store }) => (o) => {
183
+ Table: ({ Table = table }, { store }) => (o) => {
169
184
  const [el, setEl] = createSignal();
170
185
  const { props } = useContext(Ctx);
171
186
  o = combineProps({
@@ -177,7 +192,7 @@ function BasePlugin() {
177
192
  return props.style;
178
193
  }
179
194
  }, o);
180
- return createComponent(Table$1, o);
195
+ return createComponent(Table, o);
181
196
  },
182
197
  Thead: ({ Thead = thead }, { store }) => (o) => {
183
198
  o = combineProps({ ref: (el) => store.thead = el }, o);
@@ -266,7 +281,7 @@ var IndexPlugin = {
266
281
  width: 40,
267
282
  style: "text-align: center",
268
283
  class: "index",
269
- render: solidComponent((o) => o.y + 1)
284
+ render: solidComponent((o) => memo(() => o.y + 1))
270
285
  } }),
271
286
  rewriteProps: { columns: (props, { store }) => store.props?.index ? [store.$index, ...props.columns || []] : props.columns }
272
287
  };
@@ -286,23 +301,28 @@ var FixedColumnPlugin = { rewriteProps: {
286
301
  cellClass: ({ cellClass }) => (o) => (unFn(cellClass, o) || "") + (o.col.fixed ? ` fixed-${o.col.fixed}` : ""),
287
302
  cellStyle: ({ cellStyle }, { store }) => (o) => (unFn(cellStyle, o) || "") + (o.col.fixed ? `; ${o.col.fixed}: ${sumBy(store.thSizes.slice(o.col.fixed == "left" ? 0 : o.x + 1, o.col.fixed == "left" ? o.x : Infinity), (size) => size?.width || 0)}px` : "")
288
303
  } };
289
- var FitColWidthPlugin = { rewriteProps: {
290
- Table: (prev, { store }) => (o) => {
291
- const size1 = createElementSize(() => store.scroll_el);
292
- createEffect(on(() => [size1.width, prev.columns], async () => {
293
- const w = store.scroll_el.clientWidth;
294
- store._fit_col_width__cols_temp = null;
295
- await Promise.resolve();
296
- const gap = (w - store.table.offsetWidth) / store.props.columns.filter((e) => !e.width).length;
297
- store._fit_col_width__cols_temp = prev.columns.map((e, i) => ({ width: e.width ?? Math.max((store.thSizes[i]?.width || 0) + gap, 80) }));
298
- }));
299
- return createComponent(prev.Table, o);
300
- },
301
- columns: ({ columns }, { store }) => reconcile(columns.map((e, i) => ({
302
- ...e,
303
- ...store._fit_col_width__cols_temp?.[i]
304
- })))(store._fit_col_width__cols ??= [])
305
- } };
304
+ var FitColWidthPlugin = {
305
+ priority: -Infinity,
306
+ rewriteProps: {
307
+ Table: (prev, { store }) => (o) => {
308
+ const size = createMutable({ width: 0 });
309
+ createResizeObserver(() => store.scroll_el, (_, el, e) => size.width = e.contentBoxSize[0].inlineSize);
310
+ createEffect(on(() => [size.width, prev.columns.map((e) => e.width)], async () => {
311
+ if (!size.width) return;
312
+ store.__fit_col_width__cols_temp = null;
313
+ await Promise.resolve();
314
+ const gap = (size.width - store.table.getBoundingClientRect().width) / store.props.columns.filter((e) => !e.width).length;
315
+ store.__fit_col_width__cols_temp = store.props.columns.map((e, i) => e.width ? null : { width: Math.max((store.ths[i]?.getBoundingClientRect().width || 0) + gap, 80) });
316
+ }));
317
+ return createComponent(prev.Table, o);
318
+ },
319
+ columns: ({ columns }, { store }) => (columns = columns.map((e, i) => ({
320
+ ...e,
321
+ ...store.__fit_col_width__cols_temp?.[i],
322
+ [store.raw]: e[store.raw] ?? e
323
+ })), untrack(() => batch(() => reconcile(columns, { key: store.raw })(store.__fit_col_width__cols ??= []))))
324
+ }
325
+ };
306
326
  const ScrollPlugin = {
307
327
  priority: Infinity,
308
328
  rewriteProps: { Table: (prev, { store }) => (o) => {
@@ -336,13 +356,16 @@ const defaultsPlugins = [
336
356
  ScrollPlugin,
337
357
  BasePlugin(),
338
358
  CommandPlugin,
359
+ MenuPlugin,
339
360
  CellSelectionPlugin,
340
361
  RowSelectionPlugin,
341
362
  IndexPlugin,
342
363
  StickyHeaderPlugin,
343
364
  FixedColumnPlugin,
365
+ ResizePlugin,
366
+ DragPlugin,
344
367
  ClipboardPlugin,
345
368
  EditablePlugin,
346
369
  FitColWidthPlugin
347
370
  ];
348
- export { Ctx, ScrollPlugin, Table, defaultsPlugins };
371
+ export { Ctx, Intable, ScrollPlugin, src_default as default, defaultsPlugins };
@@ -0,0 +1,14 @@
1
+ import { type Plugin } from "../index";
2
+ declare module '../index' {
3
+ interface TableProps {
4
+ colDrag: boolean;
5
+ rowDrag: boolean;
6
+ }
7
+ interface TableColumn {
8
+ }
9
+ interface TableStore {
10
+ }
11
+ interface Commands {
12
+ }
13
+ }
14
+ export declare const CellMergePlugin: Plugin;
@@ -0,0 +1,2 @@
1
+ const CellMergePlugin = { rewriteProps: {} };
2
+ export { CellMergePlugin };