@intable/react 0.0.14 → 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
@@ -1,24 +1,25 @@
1
+ import { createRoot, flushSync } from "./utils.js";
1
2
  import './style.css';/* empty css */
2
3
  import { createElement, useEffect, useRef } from "react";
3
- import { createRoot } from "react-dom/client";
4
- import { flushSync } from "react-dom";
5
4
  import "intable/wc";
6
5
  import { createComputed, onCleanup } from "solid-js";
7
- const Intable = (o) => {
8
- let s = useRef(null);
6
+ const Intable = (e) => {
7
+ let a = useRef(null);
9
8
  return useEffect(() => {
10
- s.current && (s.current.options = {
11
- class: o.className,
12
- ...o,
9
+ a.current && (a.current.options = {
10
+ class: e.className,
11
+ ...e,
13
12
  renderer: component
14
13
  });
15
- }, [o]), createElement("wc-table", {
16
- ref: s,
14
+ }, [e]), createElement("wc-table", {
15
+ ref: a,
17
16
  style: { display: "contents" }
18
17
  });
19
- }, component = (i) => (a) => {
20
- let c = document.createElement("div"), l = createRoot(c);
21
- return createComputed(() => flushSync(() => l.render(createElement(i, a)))), onCleanup(() => l.unmount()), c;
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;
22
23
  };
23
24
  var src_default = Intable;
24
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 {};
@@ -1,10 +1,64 @@
1
+ import { createRoot } from "../utils.js";
2
+ import { createElement, useEffect, useRef, useState } from "react";
3
+ import { resolveOptions } from "intable/utils";
1
4
  import { Checkbox, ColorPicker, DatePicker, Input, InputNumber, Rate, Select, Switch, TimePicker } from "antd";
5
+ import dayjs from "dayjs";
2
6
  const AntdPlugin = {
3
7
  name: "antd",
4
- store(d) {
5
- d.editors.text = editor(Input), d.editors.number = editor(InputNumber), d.editors.rate = editor(Rate), d.editors.switch = editor(Switch), d.editors.checkbox = editor(Checkbox), d.editors.color = selector(ColorPicker, { transform: (e) => e?.toHexString?.() || e }), d.editors.select = selector(Select), d.editors.date = selector(DatePicker), d.editors.time = selector(TimePicker), d.editors.datetime = selector(DatePicker, { showTime: !0 });
8
+ 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) => ({
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
+ }));
6
31
  },
7
32
  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
+ return useEffect(() => {
40
+ y = u.current, u.current?.focus?.();
41
+ }, []), createElement(o, s({
42
+ ref: u,
43
+ value: e,
44
+ onChange: (e) => {
45
+ v = e.target instanceof Node ? e.target.value : e, l(v), c && !Array.isArray(v) && setTimeout(p, 100);
46
+ },
47
+ onPointerDown: (e) => e.stopPropagation(),
48
+ onKeyDown: (e) => {
49
+ e.stopPropagation(), e.key === "Enter" && p(), e.key === "Escape" && m();
50
+ },
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?.()
61
+ };
8
62
  };
9
- var editor = (e, u = {}) => createEditor(e, u, !1), selector = (e, u = {}) => createEditor(e, u, !0);
10
- export { AntdPlugin };
63
+ var editor = (e, i) => createEditor(e, i, !1), selector = (e, i) => createEditor(e, i, !0);
64
+ export { AntdPlugin, createEditor };
@@ -1,2 +1,5 @@
1
1
  import type { Plugin } from 'intable';
2
+ import type { Editor } from 'intable/plugins/EditablePlugin';
3
+ import { type FC } from 'react';
2
4
  export declare const AntdPlugin: Plugin;
5
+ export declare const createEditor: (Comp: FC<any>, opts?: (v: any) => any, isSelector?: boolean) => Editor;
@@ -0,0 +1,5 @@
1
+ export declare function createRoot(container: HTMLElement): {
2
+ render: (element: any) => any;
3
+ unmount: () => any;
4
+ };
5
+ export declare function flushSync(fn: any): any;
package/dist/utils.js ADDED
@@ -0,0 +1,13 @@
1
+ import { version } from "react";
2
+ import * as Client from "react-dom/client";
3
+ import ReactDom from "react-dom";
4
+ function createRoot(i) {
5
+ return version.startsWith("16.") || version.startsWith("17.") ? {
6
+ render: (e) => ReactDom.render(e, i),
7
+ unmount: () => ReactDom.unmountComponentAtNode(i)
8
+ } : Client.createRoot(i);
9
+ }
10
+ function flushSync(r) {
11
+ return version.startsWith("16.") || version.startsWith("17.") ? r() : ReactDom.flushSync(r);
12
+ }
13
+ export { createRoot, flushSync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intable/react",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,12 +17,13 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
+ "dayjs": "^1.11.20",
20
21
  "solid-js": "^1.9.9",
21
- "intable": "^0.0.14"
22
+ "intable": "^0.0.16"
22
23
  },
23
24
  "peerDependencies": {
24
- "react": "^18.0.0 || ^19.0.0 || ^20.0.0",
25
- "react-dom": "^18.0.0 || ^19.0.0 || ^20.0.0"
25
+ "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0",
26
+ "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@types/react": "^18",