intable 0.0.36 → 0.0.38

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/utils.js CHANGED
@@ -2,62 +2,62 @@ import { useMemoAsync } from "./hooks/index.js";
2
2
  import { tree_exports } from "./tree.js";
3
3
  import { delay, isFunction, isPlainObject, isPromise } from "es-toolkit";
4
4
  function file2base64(e) {
5
- return new Promise((x, S) => {
6
- let C = new FileReader();
7
- C.readAsDataURL(e), C.onload = () => x(C.result);
5
+ return new Promise((S, C) => {
6
+ let w = new FileReader();
7
+ w.readAsDataURL(e), w.onload = () => S(w.result);
8
8
  });
9
9
  }
10
10
  function chooseFile(e) {
11
- return new Promise((x, S) => {
12
- let C = document.createElement("input");
13
- C.type = "file", C.accept = e?.accept, C.multiple = e?.multiple, C.onchange = () => {
14
- C.files && C.files.length > 0 && x(C.multiple ? [...C.files] : C.files[0]);
15
- }, C.oncancel = S, C.click();
11
+ return new Promise((S, C) => {
12
+ let w = document.createElement("input");
13
+ w.type = "file", w.accept = e?.accept, w.multiple = e?.multiple, w.onchange = () => {
14
+ w.files && w.files.length > 0 && S(w.multiple ? [...w.files] : w.files[0]);
15
+ }, w.oncancel = C, w.click();
16
16
  });
17
17
  }
18
18
  function chooseImage() {
19
19
  return chooseFile({ accept: "image/*" });
20
20
  }
21
21
  async function print(e) {
22
- let x = document.createElement("iframe");
23
- x.srcdoc = `${[...document.querySelectorAll("style"), ...document.querySelectorAll("link[rel=\"stylesheet\"]")].map((e) => e.outerHTML).join("\n")}\n\n${e}`, Object.assign(x.style, {
22
+ let S = document.createElement("iframe");
23
+ S.srcdoc = `${[...document.querySelectorAll("style"), ...document.querySelectorAll("link[rel=\"stylesheet\"]")].map((e) => e.outerHTML).join("\n")}\n\n${e}`, Object.assign(S.style, {
24
24
  position: "fixed",
25
25
  display: "none"
26
- }), document.body.append(x), await new Promise((e) => x.contentWindow.addEventListener("load", e, { once: !0 })), await delay(300), x.contentWindow.print(), x.remove();
26
+ }), document.body.append(S), await new Promise((e) => S.contentWindow.addEventListener("load", e, { once: !0 })), await delay(300), S.contentWindow.print(), S.remove();
27
27
  }
28
- function mergeRect(e, x) {
28
+ function mergeRect(e, S) {
29
29
  return DOMRect.fromRect({
30
- x: Math.min(e.x, x.x),
31
- y: Math.min(e.y, x.y),
32
- width: Math.max(e.right, x.right) - Math.min(e.x, x.x),
33
- height: Math.max(e.bottom, x.bottom) - Math.min(e.y, x.y)
30
+ x: Math.min(e.x, S.x),
31
+ y: Math.min(e.y, S.y),
32
+ width: Math.max(e.right, S.right) - Math.min(e.x, S.x),
33
+ height: Math.max(e.bottom, S.bottom) - Math.min(e.y, S.y)
34
34
  });
35
35
  }
36
36
  function getStyles(e = document) {
37
37
  return [...e.querySelectorAll("style"), ...e.querySelectorAll("link[rel=\"stylesheet\"]")].map((e) => e.outerHTML).join("\n");
38
38
  }
39
- const unFn = (e, ...x) => typeof e == "function" ? e(...x) : e, log = (...e) => (console.log(...e), e[0]), toArr = (e) => Array.isArray(e) ? e : e == null ? [] : [e], isEmpty = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0 || typeof e == "object" && Object.keys(e).length === 0, parseStyle = (e) => e ? e.split(";").reduce((e, x) => ((([x, S]) => e[x.trim()] = S.trim())(x.split(":")), e), {}) : {};
40
- function findret(e, x) {
41
- for (let S = 0; S < e.length; S++) {
42
- let C = x(e[S], S);
43
- if (C != null) return C;
39
+ const unFn = (e, ...S) => typeof e == "function" ? e(...S) : e, log = (...e) => (console.log(...e), e[0]), toArr = (e) => Array.isArray(e) ? e : e == null ? [] : [e], isEmpty = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0 || typeof e == "object" && Object.keys(e).length === 0, parseStyle = (e) => e ? e.split(";").reduce((e, S) => ((([S, C]) => e[S.trim()] = C.trim())(S.split(":")), e), {}) : {};
40
+ function findret(e, S) {
41
+ for (let C = 0; C < e.length; C++) {
42
+ let w = S(e[C], C);
43
+ if (w != null) return w;
44
44
  }
45
45
  }
46
46
  function emptyObject(e) {
47
- for (let x of Object.keys(e)) delete e[x];
47
+ for (let S of Object.keys(e)) delete e[S];
48
48
  return e;
49
49
  }
50
- async function findAsync(e, x) {
51
- for (let S = 0; S < e.length; S++) if (await x(e[S], S)) return e[S];
50
+ async function findAsync(e, S) {
51
+ for (let C = 0; C < e.length; C++) if (await S(e[C], C)) return e[C];
52
52
  }
53
53
  var cache = /* @__PURE__ */ new WeakMap();
54
- function resolveOptions(x) {
55
- let S = x;
56
- return isFunction(S) && (S = S()), isPromise(S) ? (cache.has(S) || cache.set(S, useMemoAsync(() => S.then((e) => e.map((e) => resolveOptions(e))))), cache.get(S)()) : (isPlainObject(S) && (S = Object.entries(S).map(([e, x]) => ({
54
+ function resolveOptions(S) {
55
+ let C = S;
56
+ return isFunction(C) && (C = C()), isPromise(C) ? (cache.has(C) || cache.set(C, useMemoAsync(() => C.then((e) => e.map((e) => resolveOptions(e))))), cache.get(C)()) : (isPlainObject(C) && (C = Object.entries(C).map(([e, S]) => ({
57
57
  value: e,
58
- label: x,
59
- ...x
60
- }))), S?.map((e) => resolveOpt(e)) || []);
58
+ label: S,
59
+ ...S
60
+ }))), C?.map((e) => resolveOpt(e)) || []);
61
61
  }
62
62
  function resolveOpt(e) {
63
63
  return isPlainObject(e) ? e : Array.isArray(e) ? {
@@ -69,14 +69,18 @@ function resolveOpt(e) {
69
69
  };
70
70
  }
71
71
  function throttlePromise(e) {
72
- let x = !1, S;
72
+ let S = !1, C;
73
73
  return () => {
74
- let C = new Promise(function(e) {
75
- S = e;
74
+ let w = new Promise(function(e) {
75
+ C = e;
76
76
  });
77
- return x ? C : (x = !0, e(() => {
78
- S(), x = !1, S = null;
79
- }), C);
77
+ return S ? w : (S = !0, e(() => {
78
+ C(), S = !1, C = null;
79
+ }), w);
80
80
  };
81
81
  }
82
- export { chooseFile, chooseImage, emptyObject, file2base64, findAsync, findret, getStyles, isEmpty, log, mergeRect, parseStyle, print, resolveOptions, throttlePromise, toArr, tree_exports as tree, unFn };
82
+ function change2(e, S) {
83
+ for (let C in e) C in S || delete e[C];
84
+ return Object.assign(e, S), e;
85
+ }
86
+ export { change2, chooseFile, chooseImage, emptyObject, file2base64, findAsync, findret, getStyles, isEmpty, log, mergeRect, parseStyle, print, resolveOptions, throttlePromise, toArr, tree_exports as tree, unFn };
package/dist/wc.js CHANGED
@@ -1,7 +1,9 @@
1
- import { useMemoState } from "./hooks/index.js";
1
+ import { createShallowState, useMemoState } from "./hooks/index.js";
2
+ import { change2 } from "./utils.js";
2
3
  import { Intable } from "./index.js";
3
4
  import { createComponent } from "solid-js/web";
4
- import { createEffect, createSignal } from "solid-js";
5
+ import { createEffect, createSignal, getOwner, runWithOwner } from "solid-js";
6
+ import { isPlainObject, mapValues } from "es-toolkit";
5
7
  import { customElement, noShadowDOM } from "solid-element";
6
8
  const TableElement = customElement("wc-table", {
7
9
  options: {},
@@ -13,9 +15,9 @@ const TableElement = customElement("wc-table", {
13
15
  },
14
16
  theme: "",
15
17
  noShadow: !0
16
- }, (a, { element: o }) => {
17
- a.noShadow && noShadowDOM();
18
- let s = useMemoState(() => a.options);
19
- return createComponent(Intable, s);
18
+ }, (u, { element: d }) => {
19
+ u.noShadow && noShadowDOM();
20
+ let f = getOwner(), p = {}, m = useMemoState(() => mapValues(u.options, (c, l) => isPlainObject(c) ? (runWithOwner(f, () => p[l] ??= createShallowState({})), change2(p[l], c)) : c));
21
+ return createComponent(Intable, m);
20
22
  });
21
23
  export { TableElement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intable",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [