@intable/react 0.0.15 → 0.0.17

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
@@ -1,23 +1,26 @@
1
1
  import { createRoot, flushSync } from "./utils.js";
2
+ import { solidComponent } from "./utils2.js";
2
3
  import './style.css';/* empty css */
3
4
  import { createElement, useEffect, useRef } from "react";
4
5
  import "intable/wc";
5
6
  import { createComputed, onCleanup } from "solid-js";
6
7
  const Intable = (e) => {
7
- let a = useRef(null);
8
+ let o = useRef(null);
8
9
  return useEffect(() => {
9
- a.current && (a.current.options = {
10
+ o.current && (o.current.options = {
10
11
  class: e.className,
11
12
  ...e,
12
13
  renderer: component
13
14
  });
14
15
  }, [e]), createElement("wc-table", {
15
- ref: a,
16
+ ref: o,
16
17
  style: { display: "contents" }
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;
21
- };
19
+ }, component = (c) => solidComponent((s) => {
20
+ let l = document.createElement("div");
21
+ l.style.display = "contents";
22
+ let u = createRoot(l);
23
+ return createComputed(() => flushSync(() => u.render(typeof c == "function" ? createElement(c, s) : c))), onCleanup(() => u.unmount()), l;
24
+ });
22
25
  var src_default = Intable;
23
26
  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: {
@@ -49,6 +50,11 @@ export interface Plugin {
49
50
  }
50
51
  export type Plugin$0 = Plugin | ((store: TableStore) => Plugin);
51
52
  export interface TableProps {
53
+ store?: {
54
+ value: TableStore;
55
+ } | {
56
+ current: TableStore;
57
+ } | ((store: TableStore) => void);
52
58
  columns?: TableColumn[];
53
59
  data?: any[];
54
60
  index?: boolean;
@@ -4,6 +4,7 @@ declare module '../index' {
4
4
  }
5
5
  interface TableStore {
6
6
  commands: Commands;
7
+ scrollToCell?: (x: number | object, y: number | object, opt?: ScrollIntoViewOptions) => void;
7
8
  }
8
9
  interface Plugin {
9
10
  commands?: (store: TableStore, commands: Partial<Commands>) => Partial<Commands> & Record<string, any>;
@@ -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,25 @@
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
+ validateRow: (data: any) => Promise<void>;
13
+ validate: () => Promise<void>;
14
+ clearCellValidation: (data: any, col: TableColumn) => void;
15
+ clearRowValidation: (data: any) => void;
16
+ clearValidation: () => void;
17
+ cellValidationErrors: {
18
+ [row: Key]: {
19
+ [col: Key]: string | null;
20
+ } | null;
21
+ };
22
+ }
23
+ }
24
+ export declare const ValidatorPlugin: Plugin;
25
+ 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 };
@@ -1,7 +1,7 @@
1
1
  import { type FC } from 'react';
2
- import { type TableProps } from 'intable';
3
2
  import '../../intable/src/wc';
4
3
  import 'intable/wc';
4
+ import { type TableProps } from 'intable';
5
5
  import './style.scss';
6
6
  export declare const Intable: FC<TableProps>;
7
7
  export declare const component: <T extends Record<string, any>>(Comp: FC<T>) => (props: T) => HTMLDivElement;
@@ -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/dist/utils2.js ADDED
@@ -0,0 +1,5 @@
1
+ import "solid-js/web";
2
+ function solidComponent(e) {
3
+ return e.__solid = 1, e;
4
+ }
5
+ export { solidComponent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intable/react",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
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.17"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0",