@intable/react 0.0.16 → 0.0.18

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,25 +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");
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;
23
- };
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
+ });
24
25
  var src_default = Intable;
25
26
  export { Intable, component, src_default as default };
@@ -50,6 +50,11 @@ export interface Plugin {
50
50
  }
51
51
  export type Plugin$0 = Plugin | ((store: TableStore) => Plugin);
52
52
  export interface TableProps {
53
+ store?: {
54
+ value: TableStore;
55
+ } | {
56
+ current: TableStore;
57
+ } | ((store: TableStore) => void);
53
58
  columns?: TableColumn[];
54
59
  data?: any[];
55
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>;
@@ -9,7 +9,11 @@ declare module '../index' {
9
9
  }
10
10
  interface TableStore {
11
11
  validateCell: (value: any, data: any, col: TableColumn) => Promise<void>;
12
+ validateRow: (data: any) => Promise<void>;
13
+ validate: () => Promise<void>;
12
14
  clearCellValidation: (data: any, col: TableColumn) => void;
15
+ clearRowValidation: (data: any) => void;
16
+ clearValidation: () => void;
13
17
  cellValidationErrors: {
14
18
  [row: Key]: {
15
19
  [col: Key]: string | null;
@@ -1,64 +1,86 @@
1
1
  import { createRoot } from "../utils.js";
2
2
  import { createElement, useEffect, useRef, useState } from "react";
3
3
  import { resolveOptions } from "intable/utils";
4
- import { Checkbox, ColorPicker, DatePicker, Input, InputNumber, Rate, Select, Switch, TimePicker } from "antd";
4
+ import { Checkbox, ColorPicker, DatePicker, Input, InputNumber, Rate, Select, Switch, TimePicker, version as version$1 } from "antd";
5
5
  import dayjs from "dayjs";
6
+ import weekday from "dayjs/plugin/weekday";
7
+ import localeData from "dayjs/plugin/localeData";
8
+ dayjs.extend(weekday), dayjs.extend(localeData);
6
9
  const AntdPlugin = {
7
10
  name: "antd",
8
11
  store(e) {
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) => ({
12
+ e.editors.text = editor(Input), e.editors.textarea = editor(Input.TextArea, (e) => ({ ...e })), e.editors.number = editor(InputNumber), e.editors.rate = editor(Rate), e.editors.switch = editor(Switch), e.editors.checkbox = editor(Checkbox, (e) => ({
10
13
  ...e,
11
14
  checked: e.value,
12
- onChange: (i) => e.onChange(i.target.checked)
15
+ onChange: (a) => e.onChange(a.target.checked)
13
16
  })), e.editors.color = selector(ColorPicker, (e) => ({
14
17
  ...e,
15
18
  onChange: void 0,
16
- onChangeComplete: (i) => e.onChange(i?.toHexString?.() || i)
17
- })), e.editors.select = selector(Select), e.editors.date = selector(DatePicker, (e) => ({
19
+ onChangeComplete: (a) => e.onChange(a?.toHexString?.() || a)
20
+ })), e.editors.select = selector(Select, (e) => ({
21
+ style: { width: "100%" },
22
+ ...e
23
+ })), e.editors.date = selector(DatePicker, (e) => ({
18
24
  ...e,
19
25
  value: e.value && dayjs(e.value),
20
- onChange: (i, a) => e.onChange(a)
26
+ onChange: (a, o) => e.onChange(o)
21
27
  })), e.editors.time = selector(TimePicker, (e) => ({
22
28
  ...e,
23
29
  value: e.value && dayjs(e.value, "HH:mm:ss"),
24
- onChange: (i, a) => e.onChange(a)
30
+ onChange: (a, o) => e.onChange(o)
25
31
  })), e.editors.datetime = selector(DatePicker, (e) => ({
26
32
  ...e,
27
33
  showTime: !0,
28
34
  value: e.value && dayjs(e.value),
29
- onChange: (i, a) => e.onChange(a)
35
+ onChange: (a, o) => e.onChange(o)
30
36
  }));
31
37
  },
32
38
  rewriteProps: { class: ({ class: e }) => `antd ${e}` }
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);
39
+ }, createEditor = (s, c = (e) => e, l) => (f) => {
40
+ let { eventKey: p, value: m, col: h, ok: g, cancel: _, props: v } = f, y = document.createElement("div");
41
+ y.style.display = "contents";
42
+ let b = createRoot(y), x = [
43
+ Input,
44
+ InputNumber,
45
+ Input.TextArea
46
+ ].includes(s) && p || m, S, C = () => {
47
+ let [e, u] = useState(x), [d, f] = useState(p), m = useRef(null);
39
48
  return useEffect(() => {
40
- y = u.current, u.current?.focus?.();
41
- }, []), createElement(o, s({
42
- ref: u,
49
+ S = m.current, m.current?.focus?.();
50
+ }, []), createElement(s, c({
51
+ ref: m,
43
52
  value: e,
44
53
  onChange: (e) => {
45
- v = e.target instanceof Node ? e.target.value : e, l(v), c && !Array.isArray(v) && setTimeout(p, 100);
54
+ x = e.target instanceof Node ? e.target.value : e, u(x), l && !Array.isArray(x) && setTimeout(g, 100);
46
55
  },
47
56
  onPointerDown: (e) => e.stopPropagation(),
48
57
  onKeyDown: (e) => {
49
- e.stopPropagation(), e.key === "Enter" && p(), e.key === "Escape" && m();
58
+ e.stopPropagation(), e.key === "Enter" && !e.shiftKey && g(), e.key === "Escape" && _();
50
59
  },
51
60
  open: !0,
52
- ...f?.enum && { options: resolveOptions(f.enum) },
53
- ...h
61
+ ...+version$1.split(".")[0] <= 5 ? {
62
+ showSearch: !0,
63
+ optionFilterProp: "label",
64
+ searchValue: d,
65
+ onSearch: f
66
+ } : { showSearch: {
67
+ optionFilterProp: "label",
68
+ searchValue: d,
69
+ onSearch: f
70
+ } },
71
+ ...h?.enum && { options: resolveOptions(h.enum) },
72
+ ...v
54
73
  }));
55
- })), {
56
- el: g,
57
- getValue: () => v,
58
- destroy: () => _.unmount(),
59
- focus: () => y?.focus?.(),
60
- blur: () => y?.blur?.()
74
+ };
75
+ return setTimeout(() => {
76
+ b.render(createElement(C));
77
+ }, 0), {
78
+ el: y,
79
+ getValue: () => x,
80
+ destroy: () => b.unmount(),
81
+ focus: () => S?.focus?.(),
82
+ blur: () => S?.blur?.()
61
83
  };
62
84
  };
63
- var editor = (e, i) => createEditor(e, i, !1), selector = (e, i) => createEditor(e, i, !0);
85
+ var editor = (e, a) => createEditor(e, a, !1), selector = (e, a) => createEditor(e, a, !0);
64
86
  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;
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.16",
3
+ "version": "0.0.18",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "dayjs": "^1.11.20",
21
21
  "solid-js": "^1.9.9",
22
- "intable": "^0.0.16"
22
+ "intable": "^0.0.18"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0",