intable 0.0.1
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/README.md +22 -0
- package/dist/chevron-right.js +8 -0
- package/dist/components/Columns.d.ts +3 -0
- package/dist/components/Columns.js +105 -0
- package/dist/components/DocTree.d.ts +4 -0
- package/dist/components/DocTree.js +40 -0
- package/dist/components/Menu.d.ts +1 -0
- package/dist/components/Menu.js +131 -0
- package/dist/components/Popover.d.ts +14 -0
- package/dist/components/Popover.js +49 -0
- package/dist/components/Render.d.ts +4 -0
- package/dist/components/Render.js +21 -0
- package/dist/components/Split.d.ts +15 -0
- package/dist/components/Split.js +88 -0
- package/dist/components/Tree.d.ts +37 -0
- package/dist/components/Tree.js +101 -0
- package/dist/components/utils.d.ts +3 -0
- package/dist/components/utils.js +10 -0
- package/dist/demo.d.ts +2 -0
- package/dist/demo.js +64 -0
- package/dist/hooks/index.d.ts +38 -0
- package/dist/hooks/index.js +182 -0
- package/dist/hooks/useDir.d.ts +11 -0
- package/dist/hooks/useDir.js +59 -0
- package/dist/hooks/useVirtualizer.d.ts +25 -0
- package/dist/hooks/useVirtualizer.js +92 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +348 -0
- package/dist/intable.css +277 -0
- package/dist/loading.js +8 -0
- package/dist/plugins/CellChangeHighlightPlugin.d.ts +2 -0
- package/dist/plugins/CellChangeHighlightPlugin.js +4 -0
- package/dist/plugins/CellSelectionPlugin.d.ts +15 -0
- package/dist/plugins/CellSelectionPlugin.js +150 -0
- package/dist/plugins/CommandPlugin.d.ts +14 -0
- package/dist/plugins/CommandPlugin.js +9 -0
- package/dist/plugins/CopyPastePlugin.d.ts +14 -0
- package/dist/plugins/CopyPastePlugin.js +54 -0
- package/dist/plugins/DiffPlugin.d.ts +23 -0
- package/dist/plugins/DiffPlugin.js +68 -0
- package/dist/plugins/DragColumnPlugin.d.ts +2 -0
- package/dist/plugins/DragColumnPlugin.js +4 -0
- package/dist/plugins/EditablePlugin.d.ts +49 -0
- package/dist/plugins/EditablePlugin.js +191 -0
- package/dist/plugins/ExpandPlugin.d.ts +20 -0
- package/dist/plugins/ExpandPlugin.js +56 -0
- package/dist/plugins/HistoryPlugin.d.ts +10 -0
- package/dist/plugins/HistoryPlugin.js +35 -0
- package/dist/plugins/MenuPlugin.d.ts +18 -0
- package/dist/plugins/MenuPlugin.js +131 -0
- package/dist/plugins/RenderPlugin/components.d.ts +5 -0
- package/dist/plugins/RenderPlugin/components.js +105 -0
- package/dist/plugins/RenderPlugin/index.d.ts +30 -0
- package/dist/plugins/RenderPlugin/index.js +61 -0
- package/dist/plugins/ResizePlugin.d.ts +27 -0
- package/dist/plugins/ResizePlugin.js +103 -0
- package/dist/plugins/RowGroupPlugin.d.ts +17 -0
- package/dist/plugins/RowGroupPlugin.js +99 -0
- package/dist/plugins/RowSelectionPlugin.d.ts +32 -0
- package/dist/plugins/RowSelectionPlugin.js +69 -0
- package/dist/plugins/VirtualScrollPlugin.d.ts +15 -0
- package/dist/plugins/VirtualScrollPlugin.js +121 -0
- package/dist/plus.js +8 -0
- package/dist/types/auto-imports.d.js +0 -0
- package/dist/utils.d.ts +29 -0
- package/dist/utils.js +88 -0
- package/dist/vite.svg +1 -0
- package/dist/wc.d.ts +1 -0
- package/dist/wc.js +24 -0
- package/dist/web-component.d.ts +1 -0
- package/dist/web-component.js +2 -0
- package/dist/x.js +8 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 huodoushigemi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# intable
|
|
2
|
+
|
|
3
|
+
## 特征
|
|
4
|
+
|
|
5
|
+
- 类似 Excel 的表格组件
|
|
6
|
+
- 单元格多选、复制、粘贴
|
|
7
|
+
- 单元格编辑、数据校验
|
|
8
|
+
- 列宽、行高可拖动
|
|
9
|
+
- 虚拟滚动
|
|
10
|
+
- 历史回滚
|
|
11
|
+
<!-- - 合并单元格 -->
|
|
12
|
+
<!-- - 表头分组 -->
|
|
13
|
+
- 数据分组
|
|
14
|
+
- 行展开
|
|
15
|
+
<!-- - tree -->
|
|
16
|
+
<!-- - 过滤、排序 -->
|
|
17
|
+
- Diff 数据对比
|
|
18
|
+
<!-- - 导出 Excel -->
|
|
19
|
+
- 插件易扩展
|
|
20
|
+
- 多框架支持(Vue、React)
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { spread, template } from "solid-js/web";
|
|
2
|
+
var _tmpl$ = /* @__PURE__ */ template(`<svg viewBox="0 0 24 24"width=1.2em height=1.2em><path fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=2 d="m9 18l6-6l-6-6">`);
|
|
3
|
+
var chevron_right_default = (props = {}) => (() => {
|
|
4
|
+
var _el$ = _tmpl$();
|
|
5
|
+
spread(_el$, props, true, true);
|
|
6
|
+
return _el$;
|
|
7
|
+
})();
|
|
8
|
+
export { chevron_right_default as default };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { usePointerDrag } from "../hooks/index.js";
|
|
2
|
+
import { addEventListener, createComponent, delegateEvents, effect, insert, memo, mergeProps, render, spread, style, template, use } from "solid-js/web";
|
|
3
|
+
import { createEffect, createMemo, createSignal, mergeProps as mergeProps$1, onCleanup, onMount, splitProps } from "solid-js";
|
|
4
|
+
import { clamp, sum } from "es-toolkit";
|
|
5
|
+
import { createMutationObserver } from "@solid-primitives/mutation-observer";
|
|
6
|
+
import { createElementBounds } from "@solid-primitives/bounds";
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div style=position:absolute;z-index:1>`), _tmpl$2 = /* @__PURE__ */ template(`<div>`), _tmpl$3 = /* @__PURE__ */ template(`<div class=col-hand contenteditable=false>`), _tmpl$4 = /* @__PURE__ */ template(`<div class=dot>`);
|
|
8
|
+
const Columns = (attrs) => {
|
|
9
|
+
const [_, props] = splitProps(mergeProps$1({ gap: 0 }, attrs), ["children"]);
|
|
10
|
+
let ref;
|
|
11
|
+
const [children$1, setChildren] = createSignal([]);
|
|
12
|
+
const cols = createMemo(() => children$1().length);
|
|
13
|
+
const update = () => setChildren([...ref.querySelectorAll("& > [tiptap-is=\"column\"]")]);
|
|
14
|
+
onMount(() => update());
|
|
15
|
+
createMutationObserver(() => ref, { childList: true }, () => {
|
|
16
|
+
update();
|
|
17
|
+
container.parentElement || ref.insertBefore(container, ref.firstChild);
|
|
18
|
+
});
|
|
19
|
+
const container = _tmpl$();
|
|
20
|
+
const bounds2 = createElementBounds(() => container, { trackScroll: false });
|
|
21
|
+
createEffect(() => {
|
|
22
|
+
ref.insertBefore(container, ref.firstChild);
|
|
23
|
+
onCleanup(() => container.remove());
|
|
24
|
+
});
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
children$1().forEach((el, i) => {
|
|
27
|
+
if (i == children$1().length - 1) return;
|
|
28
|
+
const dispose = render(() => createComponent(Hand, {
|
|
29
|
+
index: i,
|
|
30
|
+
get gap() {
|
|
31
|
+
return props.gap;
|
|
32
|
+
},
|
|
33
|
+
reference: el,
|
|
34
|
+
bounds2,
|
|
35
|
+
get onAdd() {
|
|
36
|
+
return props.onAdd;
|
|
37
|
+
}
|
|
38
|
+
}), container);
|
|
39
|
+
onCleanup(dispose);
|
|
40
|
+
});
|
|
41
|
+
const cw = ref.offsetWidth;
|
|
42
|
+
const tgap = (cols() - 1) * props.gap;
|
|
43
|
+
const meanw = (cw - tgap) / cols();
|
|
44
|
+
children$1().forEach((el) => el.style.width ||= `${meanw}px`);
|
|
45
|
+
const ws = children$1().map((el) => el.offsetWidth);
|
|
46
|
+
const sumw = sum(ws) + tgap;
|
|
47
|
+
const sgap = tgap / cols();
|
|
48
|
+
children$1().forEach((el, i) => el.style.width = `calc(${(ws[i] + sgap) / sumw * 100}% - ${sgap}px)`);
|
|
49
|
+
});
|
|
50
|
+
return (() => {
|
|
51
|
+
var _el$2 = _tmpl$2();
|
|
52
|
+
var _ref$ = ref;
|
|
53
|
+
typeof _ref$ === "function" ? use(_ref$, _el$2) : ref = _el$2;
|
|
54
|
+
spread(_el$2, mergeProps({ get style() {
|
|
55
|
+
return `display: flex; gap: ${props.gap}px;`;
|
|
56
|
+
} }, props, { get cols() {
|
|
57
|
+
return cols();
|
|
58
|
+
} }), false, true);
|
|
59
|
+
insert(_el$2, () => attrs.children);
|
|
60
|
+
return _el$2;
|
|
61
|
+
})();
|
|
62
|
+
};
|
|
63
|
+
var Hand = (props) => {
|
|
64
|
+
const bounds = createElementBounds(props.reference, { trackScroll: false });
|
|
65
|
+
const style$1 = createMemo(() => `
|
|
66
|
+
position: absolute;
|
|
67
|
+
width: ${props.gap}px;
|
|
68
|
+
height: ${bounds.height}px;
|
|
69
|
+
transform: translate(${bounds.right - props.bounds2.left}px, ${bounds.top - props.bounds2.top}px);
|
|
70
|
+
`);
|
|
71
|
+
let el;
|
|
72
|
+
usePointerDrag(() => el, { start(e, move) {
|
|
73
|
+
const col = props.reference;
|
|
74
|
+
const container = col.parentElement, cw = container.offsetWidth;
|
|
75
|
+
const [cols, gap] = [+container.getAttribute("cols"), +container.getAttribute("gap")];
|
|
76
|
+
const [left, right] = [col, col.nextElementSibling];
|
|
77
|
+
const [lw, rw] = [left?.offsetWidth || 0, right?.offsetWidth || 0];
|
|
78
|
+
const minw = cw * .05, maxw = lw + rw - minw;
|
|
79
|
+
const sgap = (cols - 1) * gap / cols;
|
|
80
|
+
move((e$1, { ox }) => {
|
|
81
|
+
left && (left.style.width = `calc(${(clamp(lw + ox, minw, maxw) + sgap) / cw * 100}% - ${sgap}px)`);
|
|
82
|
+
right && (right.style.width = `calc(${(clamp(rw - ox, minw, maxw) + sgap) / cw * 100}% - ${sgap}px)`);
|
|
83
|
+
});
|
|
84
|
+
} });
|
|
85
|
+
return (() => {
|
|
86
|
+
var _el$3 = _tmpl$3();
|
|
87
|
+
var _ref$3 = props.ref;
|
|
88
|
+
typeof _ref$3 === "function" ? use(_ref$3, _el$3) : props.ref = _el$3;
|
|
89
|
+
var _ref$2 = el;
|
|
90
|
+
typeof _ref$2 === "function" ? use(_ref$2, _el$3) : el = _el$3;
|
|
91
|
+
insert(_el$3, (() => {
|
|
92
|
+
var _c$ = memo(() => !!props.onAdd);
|
|
93
|
+
return () => _c$() && (() => {
|
|
94
|
+
var _el$4 = _tmpl$4();
|
|
95
|
+
addEventListener(_el$4, "pointerdown", { handleEvent: (e) => e.stopPropagation() });
|
|
96
|
+
_el$4.$$click = () => props.onAdd(props.index);
|
|
97
|
+
return _el$4;
|
|
98
|
+
})();
|
|
99
|
+
})());
|
|
100
|
+
effect((_$p) => style(_el$3, style$1(), _$p));
|
|
101
|
+
return _el$3;
|
|
102
|
+
})();
|
|
103
|
+
};
|
|
104
|
+
delegateEvents(["click"]);
|
|
105
|
+
export { Columns };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useMemoAsync } from "../hooks/index.js";
|
|
2
|
+
import { Tree } from "./Tree.js";
|
|
3
|
+
import { createComponent, insert, spread, template } from "solid-js/web";
|
|
4
|
+
import { createEffect, createMemo, createSignal, splitProps } from "solid-js";
|
|
5
|
+
import { delay } from "es-toolkit";
|
|
6
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div class=doc-tree>`);
|
|
7
|
+
function DocTree(_) {
|
|
8
|
+
const [props, attrs] = splitProps(_, ["editor"]);
|
|
9
|
+
const [count, setCount] = createSignal(0);
|
|
10
|
+
createEffect(() => props.editor.on("update", () => setCount((v) => ++v)));
|
|
11
|
+
const json = useMemoAsync(() => (count(), delay(300).then(() => props.editor.getJSON())), {});
|
|
12
|
+
const headings = createMemo(() => {
|
|
13
|
+
return function walker(node, queue = [], queue2 = []) {
|
|
14
|
+
if (node.type === "heading") {
|
|
15
|
+
let i = queue.length;
|
|
16
|
+
while (i--) if (queue[i].level < node.attrs.level) break;
|
|
17
|
+
const item = {
|
|
18
|
+
label: node.content?.map((e) => e.text).join(""),
|
|
19
|
+
level: node.attrs.level
|
|
20
|
+
};
|
|
21
|
+
queue.push(item);
|
|
22
|
+
if (i > -1) (queue[i].children ??= []).push(item);
|
|
23
|
+
else queue2.push(item);
|
|
24
|
+
} else node.content?.forEach((e) => walker(e, queue, queue2));
|
|
25
|
+
return queue2;
|
|
26
|
+
}(json());
|
|
27
|
+
});
|
|
28
|
+
return (() => {
|
|
29
|
+
var _el$ = _tmpl$();
|
|
30
|
+
spread(_el$, attrs, false, true);
|
|
31
|
+
insert(_el$, createComponent(Tree, {
|
|
32
|
+
get data() {
|
|
33
|
+
return headings();
|
|
34
|
+
},
|
|
35
|
+
"class": "min-h-40 max-h-100 overflow-auto"
|
|
36
|
+
}));
|
|
37
|
+
return _el$;
|
|
38
|
+
})();
|
|
39
|
+
}
|
|
40
|
+
export { DocTree };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Menu(props: any): import("solid-js").JSX.Element;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { unFn } from "../utils.js";
|
|
2
|
+
import { useSignle2 } from "../hooks/index.js";
|
|
3
|
+
import { createRender } from "./Render.js";
|
|
4
|
+
import { VDir } from "../hooks/useDir.js";
|
|
5
|
+
import { Popover } from "./Popover.js";
|
|
6
|
+
import loading_default from "../loading.js";
|
|
7
|
+
import { className, createComponent, effect, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
8
|
+
import { children, createContext, createEffect, createMemo, createSignal, onMount, splitProps, useContext } from "solid-js";
|
|
9
|
+
import { createMutable } from "solid-js/store";
|
|
10
|
+
import { delay } from "es-toolkit";
|
|
11
|
+
import { combineProps } from "@solid-primitives/props";
|
|
12
|
+
import { pointerHover } from "@solid-primitives/pointer";
|
|
13
|
+
import { isEmpty } from "es-toolkit/compat";
|
|
14
|
+
import { autoUpdate, createFloating, offset } from "floating-ui-solid";
|
|
15
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div><div>`), _tmpl$2 = /* @__PURE__ */ template(`<div>`), _tmpl$3 = /* @__PURE__ */ template(`<div class="px-4 py-2 op40">无内容`);
|
|
16
|
+
function Menu(props) {
|
|
17
|
+
const MenuCtx = createContext({ deep: 0 });
|
|
18
|
+
const _Li = (_e) => {
|
|
19
|
+
const ctx = useContext(MenuCtx);
|
|
20
|
+
const [e, attrs] = splitProps(_e, [
|
|
21
|
+
"children",
|
|
22
|
+
"label",
|
|
23
|
+
"icon",
|
|
24
|
+
"isActive",
|
|
25
|
+
"cb",
|
|
26
|
+
"menu",
|
|
27
|
+
"popover"
|
|
28
|
+
]);
|
|
29
|
+
const x = createMemo(() => props.x && ctx.deep == 1);
|
|
30
|
+
let el;
|
|
31
|
+
const [floating, setFloating] = createSignal();
|
|
32
|
+
const [hover, setHover] = useSignle2(false, { before: () => delay(100) });
|
|
33
|
+
const style$1 = createMemo(() => floating() ? createFloating({
|
|
34
|
+
strategy: "fixed",
|
|
35
|
+
placement: x() ? "bottom-start" : "right-start",
|
|
36
|
+
...e.menu,
|
|
37
|
+
elements: {
|
|
38
|
+
reference: () => el,
|
|
39
|
+
floating
|
|
40
|
+
},
|
|
41
|
+
whileElementsMounted(ref, float, update) {
|
|
42
|
+
return autoUpdate(ref, float, update, {
|
|
43
|
+
ancestorResize: true,
|
|
44
|
+
elementResize: true,
|
|
45
|
+
layoutShift: true,
|
|
46
|
+
ancestorScroll: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}).floatingStyles : void 0);
|
|
50
|
+
createEffect(() => {
|
|
51
|
+
floating() && Object.assign(floating().style, style$1()?.() ?? {});
|
|
52
|
+
});
|
|
53
|
+
const req = createMutable({ loading: false });
|
|
54
|
+
async function onClick() {
|
|
55
|
+
if (req.loading) return;
|
|
56
|
+
const ret = e.cb?.();
|
|
57
|
+
if (ret instanceof Promise) try {
|
|
58
|
+
await ret;
|
|
59
|
+
req.loading = true;
|
|
60
|
+
} finally {
|
|
61
|
+
req.loading = false;
|
|
62
|
+
props.onAction?.(e);
|
|
63
|
+
}
|
|
64
|
+
else props.onAction?.(e);
|
|
65
|
+
}
|
|
66
|
+
onMount(() => {
|
|
67
|
+
createComponent(Popover, mergeProps({
|
|
68
|
+
strategy: "fixed",
|
|
69
|
+
reference: el,
|
|
70
|
+
portal: el
|
|
71
|
+
}, () => _e.popover, { get middleware() {
|
|
72
|
+
return [offset({ mainAxis: 4 })];
|
|
73
|
+
} }));
|
|
74
|
+
});
|
|
75
|
+
children(() => e.children);
|
|
76
|
+
return (() => {
|
|
77
|
+
var _el$ = _tmpl$(), _el$2 = _el$.firstChild;
|
|
78
|
+
use(pointerHover, _el$, () => setHover);
|
|
79
|
+
var _ref$ = el;
|
|
80
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : el = _el$;
|
|
81
|
+
spread(_el$, mergeProps(() => combineProps({ class: `li flex aic rd-2 ${x() ? "my-1 p-1" : "mx-1 pl-1 pr-4 py-1"} ${unFn(e.isActive) && "active"}` }, attrs), { "on:click": onClick }), false, true);
|
|
82
|
+
insert(_el$2, (() => {
|
|
83
|
+
var _c$ = memo(() => !!req.loading);
|
|
84
|
+
return () => _c$() ? createComponent(loading_default, {}) : e.icon;
|
|
85
|
+
})());
|
|
86
|
+
insert(_el$, () => e.label, null);
|
|
87
|
+
insert(_el$, (() => {
|
|
88
|
+
var _c$2 = memo(() => !!(hover() && e.children));
|
|
89
|
+
return () => _c$2() && createComponent(_Menu, {
|
|
90
|
+
ref: setFloating,
|
|
91
|
+
"class": "z-1",
|
|
92
|
+
get children() {
|
|
93
|
+
return e.children;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
})(), null);
|
|
97
|
+
effect(() => className(_el$2, `flex aic ${x() ? "" : props.density == "comfortable" ? "ml-1 mr-2.5" : "ml-.5 mr-1"} `));
|
|
98
|
+
return _el$;
|
|
99
|
+
})();
|
|
100
|
+
};
|
|
101
|
+
const Li = createRender({
|
|
102
|
+
is: _Li,
|
|
103
|
+
processProps: (props$1) => {
|
|
104
|
+
let i = 0;
|
|
105
|
+
Array.isArray(props$1.children) && props$1.children.forEach((e) => !e.is && typeof e == "object" && (e["data-index"] = i++));
|
|
106
|
+
return props$1;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const _Menu = (e) => {
|
|
110
|
+
const parent = useContext(MenuCtx);
|
|
111
|
+
const ctx = createMutable({ deep: parent.deep + 1 });
|
|
112
|
+
return createComponent(MenuCtx.Provider, {
|
|
113
|
+
value: ctx,
|
|
114
|
+
get children() {
|
|
115
|
+
var _el$3 = _tmpl$2();
|
|
116
|
+
use(VDir, _el$3, () => e.usedir);
|
|
117
|
+
spread(_el$3, mergeProps(() => combineProps({ class: `${props.x && ctx.deep == 1 ? "tt-menu-x flex" : "tt-menu max-h-100"} overflow-auto` }, e), { "on:click": (e$1) => e$1.stopPropagation() }), false, true);
|
|
118
|
+
insert(_el$3, () => ((el) => isEmpty(el) ? _tmpl$3() : el)(e.children));
|
|
119
|
+
return _el$3;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
return createComponent(Li, mergeProps(() => combineProps({}, props), {
|
|
124
|
+
is: _Menu,
|
|
125
|
+
items: null,
|
|
126
|
+
get children() {
|
|
127
|
+
return props.items;
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
export { Menu };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type JSX } from 'solid-js';
|
|
2
|
+
import { type createFloatingProps, type ReferenceType } from 'floating-ui-solid';
|
|
3
|
+
import type { AutoUpdateOptions } from '@floating-ui/dom';
|
|
4
|
+
export declare function Popover(attrs: FloatingProps): JSX.Element;
|
|
5
|
+
type FloatingProps = {
|
|
6
|
+
reference: ReferenceType;
|
|
7
|
+
floating?: JSX.Element | (() => JSX.Element);
|
|
8
|
+
portal?: HTMLElement;
|
|
9
|
+
trigger?: 'click' | 'hover';
|
|
10
|
+
} & createFloatingProps;
|
|
11
|
+
export declare function Floating(attrs: FloatingProps & {
|
|
12
|
+
update?: Partial<AutoUpdateOptions>;
|
|
13
|
+
}): JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useClicked, useHover, useMemoAsync } from "../hooks/index.js";
|
|
2
|
+
import { Portal, createComponent, memo, mergeProps } from "solid-js/web";
|
|
3
|
+
import { children, createEffect, createMemo, splitProps } from "solid-js";
|
|
4
|
+
import { delay } from "es-toolkit";
|
|
5
|
+
import { autoUpdate, createFloating } from "floating-ui-solid";
|
|
6
|
+
function Popover(attrs) {
|
|
7
|
+
const [_, props] = splitProps(attrs, ["reference", "floating"]);
|
|
8
|
+
const show = (attrs.trigger == "click" ? useClicked : useHover)(() => [reference(), floating()].filter((e) => e));
|
|
9
|
+
const show2 = useMemoAsync(() => attrs.trigger == "click" ? show() : show() ? delay(100).then(() => true) : delay(200).then(() => false));
|
|
10
|
+
const reference = children(() => attrs.reference);
|
|
11
|
+
const floating = children(() => show2() ? attrs.floating : void 0);
|
|
12
|
+
return createComponent(Floating, mergeProps(props, {
|
|
13
|
+
reference,
|
|
14
|
+
floating
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
function Floating(attrs) {
|
|
18
|
+
const [_, props] = splitProps(attrs, ["reference", "floating"]);
|
|
19
|
+
const reference = children(() => attrs.reference);
|
|
20
|
+
const floating = children(() => attrs.floating);
|
|
21
|
+
const style$1 = createMemo(() => floating() ? createFloating({
|
|
22
|
+
whileElementsMounted(ref, float, update) {
|
|
23
|
+
return autoUpdate(ref, float, update, {
|
|
24
|
+
ancestorResize: true,
|
|
25
|
+
elementResize: true,
|
|
26
|
+
layoutShift: true,
|
|
27
|
+
ancestorScroll: true,
|
|
28
|
+
...attrs.update
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
...props,
|
|
32
|
+
elements: {
|
|
33
|
+
reference,
|
|
34
|
+
floating
|
|
35
|
+
}
|
|
36
|
+
}).floatingStyles : void 0);
|
|
37
|
+
createEffect(() => {
|
|
38
|
+
floating() && Object.assign(floating().style, style$1()?.() ?? {});
|
|
39
|
+
});
|
|
40
|
+
return [memo(reference), memo(() => memo(() => !!(props.portal && floating()))() ? createComponent(Portal, {
|
|
41
|
+
get mount() {
|
|
42
|
+
return props.portal;
|
|
43
|
+
},
|
|
44
|
+
get children() {
|
|
45
|
+
return floating();
|
|
46
|
+
}
|
|
47
|
+
}) : floating())];
|
|
48
|
+
}
|
|
49
|
+
export { Floating, Popover };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dynamic, createComponent, memo, mergeProps } from "solid-js/web";
|
|
2
|
+
import { splitProps } from "solid-js";
|
|
3
|
+
var unFn = (fn, ...arg) => typeof fn == "function" ? fn(...arg) : fn;
|
|
4
|
+
function createRender({ is, processProps = (e) => e } = {}) {
|
|
5
|
+
const Render$1 = (props) => {
|
|
6
|
+
const [reserve, attrs] = splitProps(processProps?.(props), [
|
|
7
|
+
"is",
|
|
8
|
+
"vIf",
|
|
9
|
+
"children"
|
|
10
|
+
]);
|
|
11
|
+
return memo(() => memo(() => !!(!("vIf" in reserve) || !!unFn(reserve.vIf)))() && createComponent(Dynamic, mergeProps({ get component() {
|
|
12
|
+
return reserve.is ?? is;
|
|
13
|
+
} }, attrs, { get children() {
|
|
14
|
+
return List(reserve.children);
|
|
15
|
+
} })));
|
|
16
|
+
};
|
|
17
|
+
const List = (children$1) => Array.isArray(children$1) ? children$1.map((e) => typeof e == "object" ? Render$1(e) : e) : children$1;
|
|
18
|
+
return Render$1;
|
|
19
|
+
}
|
|
20
|
+
const Render = createRender({ is: "div" });
|
|
21
|
+
export { Render, createRender };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type JSXElement } from 'solid-js';
|
|
2
|
+
type SplitProps = {
|
|
3
|
+
container?: Element;
|
|
4
|
+
cells: () => Element[];
|
|
5
|
+
handle?: (i: number) => JSXElement;
|
|
6
|
+
size?: number;
|
|
7
|
+
dir?: 'x' | 'y';
|
|
8
|
+
leading?: boolean;
|
|
9
|
+
trailing?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const Split: (props: SplitProps & {
|
|
12
|
+
children?: JSXElement;
|
|
13
|
+
}) => import("solid-js").JSX.Element;
|
|
14
|
+
export declare const useSplit: (props: SplitProps) => void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { unFn } from "../utils.js";
|
|
2
|
+
import { Portal, createComponent, effect, insert, memo, spread, style, template, use } from "solid-js/web";
|
|
3
|
+
import { For, children, createEffect, mapArray, mergeProps as mergeProps$1, onMount } from "solid-js";
|
|
4
|
+
import { createElementBounds } from "@solid-primitives/bounds";
|
|
5
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div class=relative>`), _tmpl$2 = /* @__PURE__ */ template(`<div class="absolute z-1">`);
|
|
6
|
+
const Split = (props) => {
|
|
7
|
+
let el;
|
|
8
|
+
const child = children(() => props.children);
|
|
9
|
+
onMount(() => {
|
|
10
|
+
useSplit({
|
|
11
|
+
...props,
|
|
12
|
+
container: el,
|
|
13
|
+
cells: () => props.cells ? props.cells() : child()
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return (() => {
|
|
17
|
+
var _el$ = _tmpl$();
|
|
18
|
+
var _ref$ = el;
|
|
19
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : el = _el$;
|
|
20
|
+
spread(_el$, props, false, true);
|
|
21
|
+
insert(_el$, child);
|
|
22
|
+
return _el$;
|
|
23
|
+
})();
|
|
24
|
+
};
|
|
25
|
+
const useSplit = (props) => {
|
|
26
|
+
props = mergeProps$1({
|
|
27
|
+
dir: "x",
|
|
28
|
+
size: 4
|
|
29
|
+
}, props);
|
|
30
|
+
let el;
|
|
31
|
+
const bounds = mapArray(() => props.cells(), (el$1) => createElementBounds(el$1));
|
|
32
|
+
const rect = createElementBounds(() => el);
|
|
33
|
+
createEffect(() => el.style.position = "absolute");
|
|
34
|
+
const style$1 = (e, bool) => props.dir == "x" ? `transform: translate(${(bool ? e.left + e.width : e.left) - props.size / 2}px, ${e.top}px); width: ${props.size}px; height: ${e.height}px;` : `transform: translate(${e.left}px, ${(bool ? e.top + e.height : e.top) - props.size / 2}px); width: ${e.width}px; height: ${props.size}px;`;
|
|
35
|
+
const Handle = (e) => (() => {
|
|
36
|
+
var _el$2 = _tmpl$2();
|
|
37
|
+
insert(_el$2, () => props.handle?.(e.i));
|
|
38
|
+
effect((_$p) => style(_el$2, style$1({
|
|
39
|
+
...e.e,
|
|
40
|
+
left: e.e.left - rect.left,
|
|
41
|
+
top: e.e.top - rect.top
|
|
42
|
+
}, e.bool), _$p));
|
|
43
|
+
return _el$2;
|
|
44
|
+
})();
|
|
45
|
+
createComponent(Portal, {
|
|
46
|
+
ref(r$) {
|
|
47
|
+
var _ref$2 = el;
|
|
48
|
+
typeof _ref$2 === "function" ? _ref$2(r$) : el = r$;
|
|
49
|
+
},
|
|
50
|
+
get mount() {
|
|
51
|
+
return props.container || document.body;
|
|
52
|
+
},
|
|
53
|
+
get children() {
|
|
54
|
+
return [
|
|
55
|
+
createComponent(For, {
|
|
56
|
+
get each() {
|
|
57
|
+
return bounds().slice(0, -1);
|
|
58
|
+
},
|
|
59
|
+
children: (e, i) => createComponent(Handle, {
|
|
60
|
+
get e() {
|
|
61
|
+
return unFn(e);
|
|
62
|
+
},
|
|
63
|
+
bool: 1,
|
|
64
|
+
get i() {
|
|
65
|
+
return unFn(i);
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
memo(() => memo(() => !!(!!bounds().length && props.leading))() && createComponent(Handle, {
|
|
70
|
+
get e() {
|
|
71
|
+
return bounds()[0];
|
|
72
|
+
},
|
|
73
|
+
i: -1
|
|
74
|
+
})),
|
|
75
|
+
memo(() => memo(() => !!(!!bounds().length && props.trailing))() && createComponent(Handle, {
|
|
76
|
+
get e() {
|
|
77
|
+
return bounds()[bounds().length - 1];
|
|
78
|
+
},
|
|
79
|
+
bool: 1,
|
|
80
|
+
get i() {
|
|
81
|
+
return bounds().length - 1;
|
|
82
|
+
}
|
|
83
|
+
}))
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
export { Split, useSplit };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare abstract class $Node {
|
|
2
|
+
data: any;
|
|
3
|
+
constructor(data: any);
|
|
4
|
+
get label(): any;
|
|
5
|
+
abstract getChildren(): $Node[] | undefined;
|
|
6
|
+
children: $Node[] | undefined;
|
|
7
|
+
$children: import("solid-js").Accessor<$Node[] | undefined>;
|
|
8
|
+
parent: $Node | undefined;
|
|
9
|
+
$parent: import("solid-js").Signal<unknown>;
|
|
10
|
+
deep: number;
|
|
11
|
+
$deep: import("solid-js").Accessor<number>;
|
|
12
|
+
index: number;
|
|
13
|
+
$index: import("solid-js").Accessor<number | undefined>;
|
|
14
|
+
prev: $Node | undefined;
|
|
15
|
+
$prev: import("solid-js").Accessor<$Node | undefined>;
|
|
16
|
+
next: $Node | undefined;
|
|
17
|
+
$next: import("solid-js").Accessor<$Node | undefined>;
|
|
18
|
+
root: $Node;
|
|
19
|
+
$root: any;
|
|
20
|
+
path: $Node[];
|
|
21
|
+
$path: import("solid-js").Accessor<$Node[]>;
|
|
22
|
+
get descendants(): $Node[];
|
|
23
|
+
contains(node: $Node): boolean;
|
|
24
|
+
remove(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class $TreeItem extends $Node {
|
|
27
|
+
get is(): any;
|
|
28
|
+
get props(): any;
|
|
29
|
+
get id(): any;
|
|
30
|
+
getChildren(): any;
|
|
31
|
+
}
|
|
32
|
+
export declare function Tree(_: {
|
|
33
|
+
data: any;
|
|
34
|
+
Node: {
|
|
35
|
+
new (data: any): $TreeItem;
|
|
36
|
+
};
|
|
37
|
+
}): import("solid-js").JSX.Element;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Dynamic, createComponent, insert, mergeProps, spread, template } from "solid-js/web";
|
|
2
|
+
import { Index, createEffect, createMemo, createSignal, onCleanup, splitProps } from "solid-js";
|
|
3
|
+
import { combineProps } from "@solid-primitives/props";
|
|
4
|
+
import { castArray } from "es-toolkit/compat";
|
|
5
|
+
import { createLazyMemo } from "@solid-primitives/memo";
|
|
6
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
7
|
+
function define(that, key) {
|
|
8
|
+
const signal = createSignal();
|
|
9
|
+
Object.defineProperty(that, key, {
|
|
10
|
+
get() {
|
|
11
|
+
return signal[0]();
|
|
12
|
+
},
|
|
13
|
+
set(v) {
|
|
14
|
+
signal[1](v);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return signal;
|
|
18
|
+
}
|
|
19
|
+
function memo$1(that, key, fn) {
|
|
20
|
+
const signal = createLazyMemo(fn);
|
|
21
|
+
Object.defineProperty(that, key, { get() {
|
|
22
|
+
return signal();
|
|
23
|
+
} });
|
|
24
|
+
return signal;
|
|
25
|
+
}
|
|
26
|
+
var $Node = class {
|
|
27
|
+
constructor(data) {
|
|
28
|
+
this.$children = memo$1(this, "children", () => this.getChildren());
|
|
29
|
+
this.$parent = define(this, "parent");
|
|
30
|
+
this.$deep = memo$1(this, "deep", () => this.parent ? this.parent.deep + 1 : 0);
|
|
31
|
+
this.$index = memo$1(this, "index", () => this.parent?.children?.indexOf(this));
|
|
32
|
+
this.$prev = memo$1(this, "prev", () => this.parent?.children?.[this.index - 1]);
|
|
33
|
+
this.$next = memo$1(this, "next", () => this.parent?.children?.[this.index + 1]);
|
|
34
|
+
this.$root = memo$1(this, "root", () => this.parent ? this.parent.root : this);
|
|
35
|
+
this.$path = memo$1(this, "path", () => {
|
|
36
|
+
const ret = [this];
|
|
37
|
+
let e = this;
|
|
38
|
+
while (e.parent) ret.push(e = e.parent);
|
|
39
|
+
return ret.reverse();
|
|
40
|
+
});
|
|
41
|
+
this.data = data;
|
|
42
|
+
createEffect(() => {
|
|
43
|
+
const children$1 = this.children;
|
|
44
|
+
children$1?.map((e) => e.parent = this);
|
|
45
|
+
onCleanup(() => children$1?.map((e) => e.parent = void 0));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
get label() {
|
|
49
|
+
return this.data.label;
|
|
50
|
+
}
|
|
51
|
+
get descendants() {
|
|
52
|
+
return this.children?.flatMap((e) => [e, ...e.descendants]) || [];
|
|
53
|
+
}
|
|
54
|
+
contains(node) {
|
|
55
|
+
return node.path.includes(this);
|
|
56
|
+
}
|
|
57
|
+
remove() {}
|
|
58
|
+
};
|
|
59
|
+
var $TreeItem = class $TreeItem extends $Node {
|
|
60
|
+
get is() {
|
|
61
|
+
return this.data.is;
|
|
62
|
+
}
|
|
63
|
+
get props() {
|
|
64
|
+
return this.data;
|
|
65
|
+
}
|
|
66
|
+
get id() {
|
|
67
|
+
return this.data.id;
|
|
68
|
+
}
|
|
69
|
+
getChildren() {
|
|
70
|
+
return this.data.children?.map((e) => new $TreeItem(e));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
function Tree(_) {
|
|
74
|
+
const [props, attrs] = splitProps(_, ["data", "Node"]);
|
|
75
|
+
const Node = props.Node ?? $TreeItem;
|
|
76
|
+
const root = createMemo(() => new class extends Node {
|
|
77
|
+
getChildren() {
|
|
78
|
+
return castArray(this.data || []).map((e) => new Node(e));
|
|
79
|
+
}
|
|
80
|
+
}(props.data));
|
|
81
|
+
const flated = createMemo(() => root().descendants);
|
|
82
|
+
return (() => {
|
|
83
|
+
var _el$ = _tmpl$();
|
|
84
|
+
spread(_el$, mergeProps(() => combineProps({ class: "tt-menu" }, attrs)), false, true);
|
|
85
|
+
insert(_el$, createComponent(Index, {
|
|
86
|
+
get each() {
|
|
87
|
+
return flated();
|
|
88
|
+
},
|
|
89
|
+
children: (node, index) => createComponent(Dynamic, mergeProps({ get component() {
|
|
90
|
+
return node().is ?? "div";
|
|
91
|
+
} }, () => combineProps({
|
|
92
|
+
class: "li py-1 px-4",
|
|
93
|
+
style: `padding-left: ${node().deep * 16}px`
|
|
94
|
+
}, node().props), { get children() {
|
|
95
|
+
return node().label;
|
|
96
|
+
} }))
|
|
97
|
+
}));
|
|
98
|
+
return _el$;
|
|
99
|
+
})();
|
|
100
|
+
}
|
|
101
|
+
export { $Node, $TreeItem, Tree };
|