@intable/react 0.0.15 → 0.0.16

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/dist/index.js CHANGED
@@ -16,8 +16,10 @@ const Intable = (e) => {
16
16
  style: { display: "contents" }
17
17
  });
18
18
  }, component = (o) => (s) => {
19
- let c = document.createElement("div"), l = createRoot(c);
20
- return createComputed(() => flushSync(() => l.render(createElement(o, s)))), onCleanup(() => l.unmount()), c;
19
+ let c = document.createElement("div");
20
+ c.style.display = "contents";
21
+ let l = createRoot(c);
22
+ return createComputed(() => flushSync(() => l.render(typeof o == "function" ? createElement(o, s) : o))), onCleanup(() => l.unmount()), c;
21
23
  };
22
24
  var src_default = Intable;
23
25
  export { Intable, component, src_default as default };
@@ -1,3 +1,4 @@
1
1
  import type { JSX } from 'solid-js';
2
+ import type { TableStore } from '..';
2
3
  export declare function solidComponent<T extends (...arg: any[]) => JSX.Element>(comp: T): T;
3
- export declare function renderComponent(Comp: any, props: any, renderer: any): JSX.Element;
4
+ export declare function renderComponent(Comp: any, props: any, store: TableStore): any;
@@ -15,6 +15,7 @@ import './plugins/ExpandPlugin';
15
15
  import './plugins/CellMergePlugin';
16
16
  import './plugins/TreePlugin';
17
17
  import './plugins/HeaderGroup';
18
+ import './plugins/ValidatorPlugin';
18
19
  export declare const Ctx: import("solid-js").Context<{
19
20
  props: TableProps2;
20
21
  store: TableStore;
@@ -26,7 +27,7 @@ type Pri<T> = {
26
27
  type TableProps2 = Requireds<TableProps, ('Table' | 'Thead' | 'Tbody' | 'Tr' | 'Th' | 'Td' | 'EachRows' | 'EachCells' | 'rowKey' | 'data' | 'columns' | 'newRow')>;
27
28
  type Each<T = any> = (props: {
28
29
  each: T[];
29
- children: (e: () => any, i: () => number) => JSX.Element;
30
+ children: (e: () => T, i: () => number) => JSX.Element;
30
31
  }) => JSX.Element;
31
32
  type ProcessProps = {
32
33
  [K in keyof TableProps]?: (prev: TableProps2, ctx: {
@@ -1,15 +1,11 @@
1
1
  import { type JSX } from 'solid-js';
2
2
  import { type Plugin, type TableColumn } from '..';
3
3
  declare module '../index' {
4
- interface TableProps {
5
- validator?: (value: any, data: any, col: TableColumn) => string | boolean | Promise<string | boolean>;
6
- }
7
4
  interface TableColumn {
8
5
  editable?: boolean;
9
6
  editor?: string | Editor;
10
7
  editorProps?: any;
11
8
  editorPopup?: boolean;
12
- validator?: (value: any, rowData: any, col: TableColumn) => boolean | string | Promise<boolean | string>;
13
9
  }
14
10
  interface TableStore {
15
11
  editors: {
@@ -0,0 +1,21 @@
1
+ import type { Plugin } from '..';
2
+ type Key = string | symbol;
3
+ declare module '../index' {
4
+ interface TableProps {
5
+ validator?: (value: any, data: any, col: TableColumn) => void | Promise<void>;
6
+ }
7
+ interface TableColumn {
8
+ validator?: (value: any, rowData: any, col: TableColumn) => void | Promise<void>;
9
+ }
10
+ interface TableStore {
11
+ validateCell: (value: any, data: any, col: TableColumn) => Promise<void>;
12
+ clearCellValidation: (data: any, col: TableColumn) => void;
13
+ cellValidationErrors: {
14
+ [row: Key]: {
15
+ [col: Key]: string | null;
16
+ } | null;
17
+ };
18
+ }
19
+ }
20
+ export declare const ValidatorPlugin: Plugin;
21
+ export {};
@@ -2,44 +2,63 @@ import { createRoot } from "../utils.js";
2
2
  import { createElement, useEffect, useRef, useState } from "react";
3
3
  import { resolveOptions } from "intable/utils";
4
4
  import { Checkbox, ColorPicker, DatePicker, Input, InputNumber, Rate, Select, Switch, TimePicker } from "antd";
5
+ import dayjs from "dayjs";
5
6
  const AntdPlugin = {
6
7
  name: "antd",
7
8
  store(e) {
8
- e.editors.text = editor(Input), e.editors.number = editor(InputNumber), e.editors.rate = editor(Rate), e.editors.switch = editor(Switch), e.editors.checkbox = editor(Checkbox), e.editors.color = selector(ColorPicker, { transform: (e) => e?.toHexString?.() || e }), e.editors.select = selector(Select), e.editors.date = selector(DatePicker), e.editors.time = selector(TimePicker), e.editors.datetime = selector(DatePicker, { showTime: !0 });
9
+ e.editors.text = editor(Input), e.editors.number = editor(InputNumber), e.editors.rate = editor(Rate), e.editors.switch = editor(Switch), e.editors.checkbox = editor(Checkbox, (e) => ({
10
+ ...e,
11
+ checked: e.value,
12
+ onChange: (i) => e.onChange(i.target.checked)
13
+ })), e.editors.color = selector(ColorPicker, (e) => ({
14
+ ...e,
15
+ onChange: void 0,
16
+ onChangeComplete: (i) => e.onChange(i?.toHexString?.() || i)
17
+ })), e.editors.select = selector(Select), e.editors.date = selector(DatePicker, (e) => ({
18
+ ...e,
19
+ value: e.value && dayjs(e.value),
20
+ onChange: (i, a) => e.onChange(a)
21
+ })), e.editors.time = selector(TimePicker, (e) => ({
22
+ ...e,
23
+ value: e.value && dayjs(e.value, "HH:mm:ss"),
24
+ onChange: (i, a) => e.onChange(a)
25
+ })), e.editors.datetime = selector(DatePicker, (e) => ({
26
+ ...e,
27
+ showTime: !0,
28
+ value: e.value && dayjs(e.value),
29
+ onChange: (i, a) => e.onChange(a)
30
+ }));
9
31
  },
10
32
  rewriteProps: { class: ({ class: e }) => `antd ${e}` }
11
- };
12
- var getEl = (e) => e && (e instanceof Text && (e = e.nextElementSibling), e?.querySelector("input") ?? e?.querySelector("button") ?? e?.querySelector("[class*=trigger]") ?? e);
13
- const createEditor = (s, c, l) => (u) => {
14
- let { eventKey: d, value: f, col: p, ok: m, cancel: h, props: g } = u, _ = document.createElement("div"), v = createRoot(_), y = d || f, b;
15
- v.render(createElement(() => {
16
- let [e, u] = useState(y), d = useRef(null);
33
+ }, createEditor = (o, s = (e) => e, c) => (l) => {
34
+ let { eventKey: u, value: d, col: f, ok: p, cancel: m, props: h } = l, g = document.createElement("div");
35
+ g.style.display = "contents";
36
+ let _ = createRoot(g), v = u || d, y;
37
+ return _.render(createElement(() => {
38
+ let [e, l] = useState(v), u = useRef(null);
17
39
  return useEffect(() => {
18
- b = d.current, l ? setTimeout(() => (getEl(d.current)?.click?.(), d.current?.focus?.()), 0) : d.current?.focus?.();
19
- }, []), createElement(s, {
20
- ref: d,
40
+ y = u.current, u.current?.focus?.();
41
+ }, []), createElement(o, s({
42
+ ref: u,
21
43
  value: e,
22
44
  onChange: (e) => {
23
- let o = e instanceof Event ? e.target?.value : e;
24
- y = c.transform ? c.transform(o) : o, u(y), l && !Array.isArray(y) && setTimeout(m, 100);
45
+ v = e.target instanceof Node ? e.target.value : e, l(v), c && !Array.isArray(v) && setTimeout(p, 100);
25
46
  },
26
47
  onPointerDown: (e) => e.stopPropagation(),
27
48
  onKeyDown: (e) => {
28
- e.stopPropagation(), e.key === "Enter" && m(), e.key === "Escape" && h();
49
+ e.stopPropagation(), e.key === "Enter" && p(), e.key === "Escape" && m();
29
50
  },
30
- ...p?.enum && { options: resolveOptions(p.enum) },
31
- ...c,
32
- ...g
33
- });
34
- }));
35
- let x = document.createDocumentFragment();
36
- return x.appendChild(_), {
37
- el: x,
38
- getValue: () => y,
39
- destroy: () => v.unmount(),
40
- focus: () => (l && getEl(b)?.click?.(), b?.focus?.()),
41
- blur: () => b?.blur?.()
51
+ open: !0,
52
+ ...f?.enum && { options: resolveOptions(f.enum) },
53
+ ...h
54
+ }));
55
+ })), {
56
+ el: g,
57
+ getValue: () => v,
58
+ destroy: () => _.unmount(),
59
+ focus: () => y?.focus?.(),
60
+ blur: () => y?.blur?.()
42
61
  };
43
62
  };
44
- var editor = (e, o = {}) => createEditor(e, o, !1), selector = (e, o = {}) => createEditor(e, o, !0);
63
+ var editor = (e, i) => createEditor(e, i, !1), selector = (e, i) => createEditor(e, i, !0);
45
64
  export { AntdPlugin, createEditor };
@@ -2,4 +2,4 @@ import type { Plugin } from 'intable';
2
2
  import type { Editor } from 'intable/plugins/EditablePlugin';
3
3
  import { type FC } from 'react';
4
4
  export declare const AntdPlugin: Plugin;
5
- export declare const createEditor: (Comp: FC<any>, opts: any, isSelector?: boolean) => Editor;
5
+ export declare const createEditor: (Comp: FC<any>, opts?: (v: any) => any, isSelector?: boolean) => Editor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intable/react",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,8 +17,9 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
+ "dayjs": "^1.11.20",
20
21
  "solid-js": "^1.9.9",
21
- "intable": "^0.0.15"
22
+ "intable": "^0.0.16"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0",