ex4nicegui 0.2.16__tar.gz → 0.2.18__tar.gz

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.
Files changed (80) hide show
  1. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/PKG-INFO +1 -1
  2. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/__init__.py +1 -1
  3. ex4nicegui-0.2.18/ex4nicegui/experimental_/gridLayout/__init__.py +1 -0
  4. ex4nicegui-0.2.18/ex4nicegui/experimental_/gridLayout/index.py +181 -0
  5. ex4nicegui-0.2.18/ex4nicegui/layout/__init__.py +2 -0
  6. ex4nicegui-0.2.18/ex4nicegui/layout/gridFlex/GridFlex.js +156 -0
  7. ex4nicegui-0.2.18/ex4nicegui/layout/gridFlex/__init__.py +1 -0
  8. ex4nicegui-0.2.18/ex4nicegui/layout/gridFlex/gridFlex.py +276 -0
  9. ex4nicegui-0.2.18/ex4nicegui/layout/gridFlex/utils.py +48 -0
  10. ex4nicegui-0.2.18/ex4nicegui/layout/rxFlex/__init__.py +1 -0
  11. ex4nicegui-0.2.18/ex4nicegui/layout/rxFlex/index.py +121 -0
  12. ex4nicegui-0.2.18/ex4nicegui/layout/rxFlex/types.py +80 -0
  13. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/EChartsComponent/ECharts.js +14 -9
  14. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui.egg-info/PKG-INFO +1 -1
  15. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui.egg-info/SOURCES.txt +7 -1
  16. ex4nicegui-0.2.16/ex4nicegui/experimental_/gridLayout/__init__.py +0 -1
  17. ex4nicegui-0.2.16/ex4nicegui/experimental_/gridLayout/index.py +0 -76
  18. ex4nicegui-0.2.16/ex4nicegui/layout/__init__.py +0 -1
  19. ex4nicegui-0.2.16/ex4nicegui/layout/gridbox.py +0 -85
  20. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/LICENSE +0 -0
  21. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/README.md +0 -0
  22. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/experimental_/__init__.py +0 -0
  23. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/EChartsComponent/ECharts.py +0 -0
  24. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/EChartsComponent/__init__.py +0 -0
  25. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/UseDraggable/UseDraggable.js +0 -0
  26. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/UseDraggable/UseDraggable.py +0 -0
  27. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/UseDraggable/__init__.py +0 -0
  28. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/__index.py +0 -0
  29. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/__init__.py +0 -0
  30. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/drawer.py +0 -0
  31. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/dropZone/__init__.py +0 -0
  32. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/dropZone/dropZone.js +0 -0
  33. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/dropZone/dropZone.py +0 -0
  34. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/fileWatcher.py +0 -0
  35. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/local_file_picker.py +0 -0
  36. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/__init__.py +0 -0
  37. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/aggrid.py +0 -0
  38. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/base.py +0 -0
  39. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/button.py +0 -0
  40. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/card.py +0 -0
  41. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/checkbox.py +0 -0
  42. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/color_picker.py +0 -0
  43. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/column.py +0 -0
  44. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/date.py +0 -0
  45. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/drawer.py +0 -0
  46. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/echarts.py +0 -0
  47. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/expansion.py +0 -0
  48. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/grid.py +0 -0
  49. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/html.py +0 -0
  50. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/icon.py +0 -0
  51. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/image.py +0 -0
  52. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/input.py +0 -0
  53. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/label.py +0 -0
  54. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/number.py +0 -0
  55. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/radio.py +0 -0
  56. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/row.py +0 -0
  57. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/select.py +0 -0
  58. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/slider.py +0 -0
  59. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/switch.py +0 -0
  60. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/table.py +0 -0
  61. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/textarea.py +0 -0
  62. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/upload.py +0 -0
  63. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/officials/utils.py +0 -0
  64. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/q_pagination.py +0 -0
  65. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/rxui.py +0 -0
  66. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/useMouse/UseMouse.js +0 -0
  67. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/useMouse/UseMouse.py +0 -0
  68. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/useMouse/__init__.py +0 -0
  69. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/reactive/usePagination.py +0 -0
  70. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/tools/__init__.py +0 -0
  71. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/tools/debug.py +0 -0
  72. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/utils/__init__.py +0 -0
  73. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/utils/common.py +0 -0
  74. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui/utils/signals.py +0 -0
  75. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui.egg-info/dependency_links.txt +0 -0
  76. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui.egg-info/not-zip-safe +0 -0
  77. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui.egg-info/requires.txt +0 -0
  78. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/ex4nicegui.egg-info/top_level.txt +0 -0
  79. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/setup.cfg +0 -0
  80. {ex4nicegui-0.2.16 → ex4nicegui-0.2.18}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ex4nicegui
3
- Version: 0.2.16
3
+ Version: 0.2.18
4
4
  Summary: ...
5
5
  Home-page:
6
6
  Author: carson_jia
@@ -16,4 +16,4 @@ from signe import batch
16
16
  from ex4nicegui.experimental_ import gridLayout as exp_ui
17
17
 
18
18
 
19
- __version__ = "0.2.16"
19
+ __version__ = "0.2.18"
@@ -0,0 +1 @@
1
+ from .index import column, row, item, grid_flex
@@ -0,0 +1,181 @@
1
+ from nicegui import ui
2
+
3
+
4
+ from typing_extensions import Literal
5
+ from typing import Optional, Union
6
+
7
+ TBreakpoint = Literal[
8
+ "xs[0px]",
9
+ "sm[600px]",
10
+ "md[1024px]",
11
+ "lg[1440px]",
12
+ "xl[1920px]",
13
+ ">xs[0px]",
14
+ "<sm[600px]",
15
+ ">sm[600px]",
16
+ "<md[1024px]",
17
+ ">md[1024px]",
18
+ "<lg[1440px]",
19
+ ">lg[1440px]",
20
+ "<xl[1920px]",
21
+ ">xl[1920px]",
22
+ ]
23
+
24
+ Breakpoint_map = {
25
+ "xs[0px]": "xs",
26
+ "sm[600px]": "sm",
27
+ "md[1024px]": "md",
28
+ "lg[1440px]": "lg",
29
+ "xl[1920px]": "xl",
30
+ ">xs[0px]": "gt-xs",
31
+ "<sm[600px]": "lt-sm",
32
+ ">sm[600px]": "gt-sm",
33
+ "<md[1024px]": "lt-md",
34
+ ">md[1024px]": "gt-md",
35
+ "<lg[1440px]": "lt-lg",
36
+ ">lg[1440px]": "gt-lg",
37
+ "<xl[1920px]": "lt-xl",
38
+ ">xl[1920px]": "gt-xl",
39
+ }
40
+
41
+
42
+ def _gap_value(value: Union[str, float, int]):
43
+ if isinstance(value, (float, int)):
44
+ value = f"{value}rem"
45
+ return value
46
+
47
+
48
+ THorizontal = Literal["left", "center", "right", "stretch"]
49
+ Horizontal_map = {
50
+ "left": "start",
51
+ "center": "center",
52
+ "right": "end",
53
+ "stretch": "stretch",
54
+ }
55
+
56
+ TVertical = Literal["top", "center", "bottom", "stretch"]
57
+ Vertical_map = {
58
+ "top": "start",
59
+ "center": "center",
60
+ "bottom": "end",
61
+ "stretch": "stretch",
62
+ }
63
+
64
+ _TGrid_Type = Literal["row", "column"]
65
+
66
+
67
+ class GridFlex(ui.element):
68
+ def __init__(self) -> None:
69
+ """ """
70
+ super().__init__("div")
71
+ self._classes = ["grid"]
72
+
73
+ @staticmethod
74
+ def set_classes(
75
+ grid_flex: "GridFlex",
76
+ type: _TGrid_Type,
77
+ template: str,
78
+ horizontal: THorizontal = "stretch",
79
+ vertical: TVertical = "stretch",
80
+ gap: Union[str, float, int] = 1,
81
+ width_full=True,
82
+ break_point: Optional[TBreakpoint] = None,
83
+ ):
84
+ _template = template.strip().replace(" ", "_")
85
+ _type = f"{type}s"
86
+ _justify_items = f"justify-items-{Horizontal_map[horizontal]}"
87
+ _align_items = f"items-{Vertical_map[vertical]}"
88
+ _gap = f"gap-[{_gap_value(gap)}]"
89
+ _w_full = "w-full" if width_full else ""
90
+
91
+ class_names = [
92
+ f"grid-{_type}-[{_template}]",
93
+ _justify_items,
94
+ _align_items,
95
+ _gap,
96
+ _w_full,
97
+ ]
98
+
99
+ if break_point is not None:
100
+ class_names = [f"{Breakpoint_map[break_point]}-{n}" for n in class_names]
101
+
102
+ grid_flex.classes(" ".join(class_names))
103
+ return grid_flex
104
+
105
+ def grid_flex(
106
+ self,
107
+ type: _TGrid_Type,
108
+ template: str,
109
+ *,
110
+ horizontal: THorizontal = "stretch",
111
+ vertical: TVertical = "stretch",
112
+ gap: Union[str, float, int] = 1,
113
+ width_full=True,
114
+ break_point: Optional[TBreakpoint] = None,
115
+ ):
116
+ return GridFlex.set_classes(
117
+ self, type, template, horizontal, vertical, gap, width_full, break_point
118
+ )
119
+
120
+
121
+ def grid_flex(
122
+ type: _TGrid_Type,
123
+ template: str,
124
+ *,
125
+ horizontal: THorizontal = "stretch",
126
+ vertical: TVertical = "stretch",
127
+ gap: Union[str, float, int] = 1,
128
+ width_full=True,
129
+ break_point: Optional[TBreakpoint] = None,
130
+ ):
131
+ gf = GridFlex()
132
+
133
+ return GridFlex.set_classes(
134
+ gf, type, template, horizontal, vertical, gap, width_full, break_point
135
+ )
136
+
137
+
138
+ def column(
139
+ template: str,
140
+ horizontal: THorizontal = "stretch",
141
+ vertical: TVertical = "stretch",
142
+ gap: Union[str, float, int] = 1,
143
+ width_full=True,
144
+ ):
145
+ gap = f"gap-[{_gap_value(gap)}]"
146
+ w_full = "w-full" if width_full else ""
147
+
148
+ box = ui.element("div").classes(f"grid {gap} {w_full}")
149
+ box._style["grid-template-rows"] = template
150
+ box._style["justify-items"] = Horizontal_map[horizontal]
151
+ box._style["align-items"] = Vertical_map[vertical]
152
+ return box
153
+
154
+
155
+ def row(
156
+ template: str,
157
+ vertical: TVertical = "stretch",
158
+ horizontal: THorizontal = "stretch",
159
+ gap: Union[str, float, int] = 1,
160
+ width_full=True,
161
+ ):
162
+ gap = f"gap-[{_gap_value(gap)}]"
163
+ w_full = "w-full" if width_full else ""
164
+
165
+ box = ui.element("div").classes(f"grid {gap} {w_full}")
166
+ box._style["grid-template-columns"] = template
167
+ box._style["justify-items"] = Horizontal_map[horizontal]
168
+ box._style["align-items"] = Vertical_map[vertical]
169
+ return box
170
+
171
+
172
+ def item(
173
+ *, horizontal: Optional[THorizontal] = None, vertical: Optional[TVertical] = None
174
+ ):
175
+ res = []
176
+ if horizontal is not None:
177
+ res.append(f"justify-self-{Horizontal_map[horizontal]}")
178
+
179
+ if vertical is not None:
180
+ res.append(f"self-{Vertical_map[vertical]}")
181
+ return " ".join(res)
@@ -0,0 +1,2 @@
1
+ from .gridFlex import *
2
+ from .rxFlex import *
@@ -0,0 +1,156 @@
1
+ const M = Vue.getCurrentScope
2
+ const _ = Vue.onScopeDispose
3
+ const k = Vue.toRef
4
+ const q = Vue.readonly
5
+ const j = Vue.customRef
6
+ const d = Vue.ref
7
+ const m = Vue.computed
8
+ const B = Vue.watchEffect
9
+ const L = Vue.getCurrentInstance
10
+ const C = Vue.onMounted
11
+ const N = Vue.defineComponent
12
+ const R = Vue.openBlock
13
+ const G = Vue.createElementBlock
14
+ const W = Vue.normalizeStyle
15
+ const z = Vue.unref
16
+ const D = Vue.renderSlot
17
+ function F(n) {
18
+ return M() ? (_(n), !0) : !1;
19
+ }
20
+ const I = typeof window < "u", Q = () => {
21
+ };
22
+ function P(n, s) {
23
+ var r;
24
+ if (typeof n == "number")
25
+ return n + s;
26
+ const o = ((r = n.match(/^-?[0-9]+\.?[0-9]*/)) == null ? void 0 : r[0]) || "", l = n.slice(o.length), t = Number.parseFloat(o) + s;
27
+ return Number.isNaN(t) ? n : t + l;
28
+ }
29
+ function U(...n) {
30
+ if (n.length !== 1)
31
+ return k(...n);
32
+ const s = n[0];
33
+ return typeof s == "function" ? q(j(() => ({ get: s, set: Q }))) : d(s);
34
+ }
35
+ const p = I ? window : void 0;
36
+ function V() {
37
+ const n = d(!1);
38
+ return L() && C(() => {
39
+ n.value = !0;
40
+ }), n;
41
+ }
42
+ function A(n) {
43
+ const s = V();
44
+ return m(() => (s.value, !!n()));
45
+ }
46
+ function c(n, s = {}) {
47
+ const { window: r = p } = s, o = A(() => r && "matchMedia" in r && typeof r.matchMedia == "function");
48
+ let l;
49
+ const t = d(!1), i = () => {
50
+ l && ("removeEventListener" in l ? l.removeEventListener("change", e) : l.removeListener(e));
51
+ }, e = () => {
52
+ o.value && (i(), l = r.matchMedia(U(n).value), t.value = !!(l != null && l.matches), l && ("addEventListener" in l ? l.addEventListener("change", e) : l.addListener(e)));
53
+ };
54
+ return B(e), F(() => i()), t;
55
+ }
56
+ function H(n, s = {}) {
57
+ function r(e, u) {
58
+ let a = n[e];
59
+ return u != null && (a = P(a, u)), typeof a == "number" && (a = `${a}px`), a;
60
+ }
61
+ const { window: o = p } = s;
62
+ function l(e) {
63
+ return o ? o.matchMedia(e).matches : !1;
64
+ }
65
+ const t = (e) => c(`(min-width: ${r(e)})`, s), i = Object.keys(n).reduce((e, u) => (Object.defineProperty(e, u, {
66
+ get: () => t(u),
67
+ enumerable: !0,
68
+ configurable: !0
69
+ }), e), {});
70
+ return Object.assign(i, {
71
+ greater(e) {
72
+ return c(`(min-width: ${r(e, 0.1)})`, s);
73
+ },
74
+ greaterOrEqual: t,
75
+ smaller(e) {
76
+ return c(`(max-width: ${r(e, -0.1)})`, s);
77
+ },
78
+ smallerOrEqual(e) {
79
+ return c(`(max-width: ${r(e)})`, s);
80
+ },
81
+ between(e, u) {
82
+ return c(`(min-width: ${r(e)}) and (max-width: ${r(u, -0.1)})`, s);
83
+ },
84
+ isGreater(e) {
85
+ return l(`(min-width: ${r(e, 0.1)})`);
86
+ },
87
+ isGreaterOrEqual(e) {
88
+ return l(`(min-width: ${r(e)})`);
89
+ },
90
+ isSmaller(e) {
91
+ return l(`(max-width: ${r(e, -0.1)})`);
92
+ },
93
+ isSmallerOrEqual(e) {
94
+ return l(`(max-width: ${r(e)})`);
95
+ },
96
+ isInBetween(e, u) {
97
+ return l(`(min-width: ${r(e)}) and (max-width: ${r(u, -0.1)})`);
98
+ },
99
+ current() {
100
+ const e = Object.keys(n).map((u) => [u, t(u)]);
101
+ return m(() => e.filter(([, u]) => u.value).map(([u]) => u));
102
+ }
103
+ });
104
+ }
105
+ const T = /* @__PURE__ */ N({
106
+ __name: "GridFlex",
107
+ props: {
108
+ normalStyles: null,
109
+ breakpointStyleMap: null
110
+ },
111
+ setup(n) {
112
+ const s = n, r = m(() => new Map(
113
+ Object.entries(s.breakpointStyleMap)
114
+ ));
115
+ function o() {
116
+ const t = H({
117
+ sm: 600,
118
+ md: 1024,
119
+ lg: 1440,
120
+ xl: 1920
121
+ }), i = t.smaller("sm"), e = t.between("sm", "md"), u = t.between("md", "lg"), a = t.between("lg", "xl"), g = t.greaterOrEqual("xl"), h = t.smaller("sm"), w = t.smaller("md"), v = t.smaller("lg"), y = t.smaller("xl"), x = t.greaterOrEqual("sm"), b = t.greaterOrEqual("md"), O = t.greaterOrEqual("lg"), S = t.greaterOrEqual("xl"), E = {
122
+ xs: i,
123
+ sm: e,
124
+ md: u,
125
+ lg: a,
126
+ xl: g,
127
+ "lt-sm": h,
128
+ "lt-md": w,
129
+ "lt-lg": v,
130
+ "lt-xl": y,
131
+ "gt-xs": x,
132
+ "gt-sm": b,
133
+ "gt-md": O,
134
+ "gt-lg": S
135
+ };
136
+ return m(() => {
137
+ if (r.value.size === 0)
138
+ return s.normalStyles;
139
+ for (const [f, $] of Object.entries(E))
140
+ if ($.value && r.value.has(f))
141
+ return r.value.get(f);
142
+ return s.normalStyles;
143
+ });
144
+ }
145
+ const l = o();
146
+ return (t, i) => (R(), G("div", {
147
+ class: "grid",
148
+ style: W(z(l))
149
+ }, [
150
+ D(t.$slots, "default")
151
+ ], 4));
152
+ }
153
+ });
154
+ export {
155
+ T as default
156
+ };
@@ -0,0 +1 @@
1
+ from .gridFlex import grid_flex, grid_box, mark_area, item_position, GridFlex
@@ -0,0 +1,276 @@
1
+ from typing import Any, Callable, Dict, Optional, cast
2
+ from dataclasses import dataclass
3
+ from nicegui.dataclasses import KWONLY_SLOTS
4
+ from nicegui import ui, app
5
+ from nicegui.element import Element
6
+ from signe import createSignal, effect, batch
7
+ from ex4nicegui.utils.signals import ref_from_signal
8
+
9
+ from typing_extensions import Literal
10
+ from typing import Optional, Union
11
+ from . import utils
12
+
13
+
14
+ TBreakpoint = Literal[
15
+ "xs[0px-599.99px]",
16
+ "sm[600px-1023.99px]",
17
+ "md[1024px-1439.99px]",
18
+ "lg[1440px-1919.99px]",
19
+ "xl[1920px-Infinity]",
20
+ ">xs[600px-Infinity]",
21
+ "<sm[0-599.99px]",
22
+ ">sm[1024px-Infinity]",
23
+ "<md[0-1023.99px]",
24
+ ">md[1440px-Infinity]",
25
+ "<lg[0-1439.99px]",
26
+ ">lg[1920px-Infinity]",
27
+ "<xl[0-1919.99px]",
28
+ ]
29
+
30
+ Breakpoint_map = {
31
+ "xs[0px-599.99px]": "xs",
32
+ "sm[600px-1023.99px]": "sm",
33
+ "md[1024px-1439.99px]": "md",
34
+ "lg[1440px-1919.99px]": "lg",
35
+ "xl[1920px-Infinity]": "xl",
36
+ ">xs[600px-Infinity]": "gt-xs",
37
+ "<sm[0-599.99px]": "lt-sm",
38
+ ">sm[1024px-Infinity]": "gt-sm",
39
+ "<md[0-1023.99px]": "lt-md",
40
+ ">md[1440px-Infinity]": "gt-md",
41
+ "<lg[0-1439.99px]": "lt-lg",
42
+ ">lg[1920px-Infinity]": "gt-lg",
43
+ "<xl[0-1919.99px]": "lt-xl",
44
+ }
45
+
46
+
47
+ def _gap_value(value: Optional[Union[str, float, int]]):
48
+ if value is None:
49
+ return value
50
+
51
+ if isinstance(value, (float, int)):
52
+ value = f"{value}rem"
53
+ return value
54
+
55
+
56
+ THorizontal = Literal["left", "center", "right", "stretch"]
57
+ Horizontal_map = {
58
+ "left": "start",
59
+ "center": "center",
60
+ "right": "end",
61
+ "stretch": "stretch",
62
+ }
63
+
64
+ TVertical = Literal["top", "center", "bottom", "stretch"]
65
+ Vertical_map = {
66
+ "top": "start",
67
+ "center": "center",
68
+ "bottom": "end",
69
+ "stretch": "stretch",
70
+ }
71
+
72
+ _TGrid_Type = Literal["row", "column"]
73
+ Grid_Type_map = {
74
+ "row": "columns",
75
+ "column": "rows",
76
+ }
77
+
78
+
79
+ class GridFlex(Element, component="GridFlex.js"):
80
+ def __init__(self) -> None:
81
+ super().__init__()
82
+
83
+ self._props["normalStyles"] = {}
84
+ self._props["breakpointStyleMap"] = {}
85
+
86
+ self.__breakpointStyleMap = {}
87
+
88
+ @staticmethod
89
+ def _cleanStyle(styles: Dict):
90
+ return {k: v for k, v in styles.items() if v is not None}
91
+
92
+ @staticmethod
93
+ def to_styles(
94
+ type: _TGrid_Type,
95
+ template: str,
96
+ horizontal: THorizontal = "stretch",
97
+ vertical: TVertical = "stretch",
98
+ gap: Union[str, float, int] = 1,
99
+ width_full=True,
100
+ ):
101
+ styles = {
102
+ f"grid-template-{Grid_Type_map[type]}": template,
103
+ "justify-items": Horizontal_map[horizontal],
104
+ "align-items": Vertical_map[vertical],
105
+ "gap": _gap_value(gap),
106
+ }
107
+
108
+ if width_full:
109
+ styles.update({"width": "100%"})
110
+
111
+ return styles
112
+
113
+ def grid_flex(
114
+ self,
115
+ type: _TGrid_Type,
116
+ template: str,
117
+ *,
118
+ horizontal: THorizontal = "stretch",
119
+ vertical: TVertical = "stretch",
120
+ gap: Union[str, float, int] = 1,
121
+ width_full=True,
122
+ break_point: Optional[TBreakpoint] = None,
123
+ ):
124
+ styles = GridFlex.to_styles(
125
+ type, template, horizontal, vertical, gap, width_full
126
+ )
127
+
128
+ if break_point is None:
129
+ self._props["normalStyles"] = styles
130
+ else:
131
+ self.__breakpointStyleMap[Breakpoint_map[break_point]] = styles
132
+ self._props["breakpointStyleMap"] = self.__breakpointStyleMap
133
+
134
+ self.update()
135
+ return self
136
+
137
+ def grid_box(
138
+ self,
139
+ area: Optional[str] = None,
140
+ *,
141
+ template_rows: Optional[str] = None,
142
+ template_columns: Optional[str] = None,
143
+ horizontal: THorizontal = "stretch",
144
+ vertical: TVertical = "stretch",
145
+ gap: Optional[Union[str, float, int]] = 1,
146
+ width_full=True,
147
+ break_point: Optional[TBreakpoint] = None,
148
+ **kws,
149
+ ):
150
+ if area is not None and area.strip() != "":
151
+ areas_list = utils.areas_str2array(area)
152
+ area = utils.areas_array2str(areas_list)
153
+ areas_cols_len = max(map(len, areas_list))
154
+ areas_rows_len = len(areas_list)
155
+
156
+ template_columns = template_columns or f"repeat({areas_cols_len}, 1fr)"
157
+ template_rows = template_rows or f"repeat({areas_rows_len}, 1fr)"
158
+
159
+ styles = {
160
+ "grid-template-areas": area,
161
+ "grid-template-rows": template_rows,
162
+ "grid-template-columns": template_columns,
163
+ "justify-items": Horizontal_map[horizontal],
164
+ "align-items": Vertical_map[vertical],
165
+ "gap": _gap_value(gap),
166
+ }
167
+ styles.update(kws)
168
+
169
+ if width_full:
170
+ styles.update({"width": "100%"})
171
+
172
+ styles = GridFlex._cleanStyle(styles)
173
+
174
+ if break_point is None:
175
+ self._props["normalStyles"] = styles
176
+ else:
177
+ self.__breakpointStyleMap[Breakpoint_map[break_point]] = styles
178
+ self._props["breakpointStyleMap"] = self.__breakpointStyleMap
179
+
180
+ self.update()
181
+ return self
182
+
183
+
184
+ def grid_box(
185
+ area: Optional[str] = None,
186
+ *,
187
+ template_rows: Optional[str] = None,
188
+ template_columns: Optional[str] = None,
189
+ horizontal: THorizontal = "stretch",
190
+ vertical: TVertical = "stretch",
191
+ gap: Union[str, float, int] = 1,
192
+ width_full=True,
193
+ break_point: Optional[TBreakpoint] = None,
194
+ **kws,
195
+ ):
196
+ gf = GridFlex()
197
+
198
+ gf.grid_box(
199
+ area,
200
+ template_rows=template_rows,
201
+ template_columns=template_columns,
202
+ horizontal=horizontal,
203
+ vertical=vertical,
204
+ gap=gap,
205
+ width_full=width_full,
206
+ break_point=break_point,
207
+ **kws,
208
+ )
209
+
210
+ return gf
211
+
212
+
213
+ def grid_flex(
214
+ type: _TGrid_Type,
215
+ template: str,
216
+ *,
217
+ horizontal: THorizontal = "stretch",
218
+ vertical: TVertical = "stretch",
219
+ gap: Union[str, float, int] = 1,
220
+ width_full=True,
221
+ break_point: Optional[TBreakpoint] = None,
222
+ ):
223
+ gf = GridFlex()
224
+
225
+ gf.grid_flex(
226
+ type,
227
+ template,
228
+ horizontal=horizontal,
229
+ vertical=vertical,
230
+ gap=gap,
231
+ width_full=width_full,
232
+ break_point=break_point,
233
+ )
234
+
235
+ return gf
236
+
237
+
238
+ class MarkArea:
239
+ def __init__(self, mark: str) -> None:
240
+ self.mark = mark
241
+
242
+ def __radd__(self, other: ui.element):
243
+ other.style(f"grid-area:{self.mark}")
244
+ return other
245
+
246
+
247
+ def mark_area(mark: str):
248
+ return MarkArea(mark)
249
+
250
+
251
+ class ItemPosition:
252
+ def __init__(
253
+ self,
254
+ horizontal: Optional[THorizontal] = None,
255
+ vertical: Optional[TVertical] = None,
256
+ ) -> None:
257
+ self.horizontal = horizontal
258
+ self.vertical = vertical
259
+
260
+ def __radd__(self, other: ui.element):
261
+ res = []
262
+ if self.horizontal is not None:
263
+ res.append(f"justify-self-{Horizontal_map[self.horizontal]}")
264
+
265
+ if self.vertical is not None:
266
+ res.append(f"self-{Vertical_map[self.vertical]}")
267
+
268
+ other.classes(" ".join(res))
269
+
270
+ return other
271
+
272
+
273
+ def item_position(
274
+ *, horizontal: Optional[THorizontal] = None, vertical: Optional[TVertical] = None
275
+ ):
276
+ return ItemPosition(horizontal, vertical)
@@ -0,0 +1,48 @@
1
+ from typing import List
2
+
3
+
4
+ def areas_str2array(areas: str) -> List[List[str]]:
5
+ """
6
+ >>> input='''
7
+ sc1 sc2
8
+ sc3
9
+ table table table table
10
+ '''
11
+ >>> areas_str2array(input)
12
+ >>> [
13
+ ["sc1", "sc2"],
14
+ ["sc3"],
15
+ ["table", "table", "table", "table"]
16
+ ]
17
+ """
18
+ pass
19
+
20
+ lines = (line.strip() for line in areas.splitlines())
21
+ remove_empty_rows = (line for line in lines if len(line) > 0)
22
+ splie_space = (line.split() for line in remove_empty_rows)
23
+ return list(splie_space)
24
+
25
+
26
+ def areas_array2str(areas_array: List[List[str]]):
27
+ """
28
+ >>> input = [
29
+ ["sc1", "sc2"],
30
+ ["sc3"],
31
+ ["table"] * 4
32
+ ]
33
+ >>> areas_array2str(input)
34
+ >>> '"sc1 sc2 . ." "sc3 . . ." "table table table table"'
35
+ """
36
+ max_len = max(map(len, areas_array))
37
+
38
+ fix_empty = (
39
+ [*line, *(["."] * (max_len - len(line)))] if len(line) < max_len else line
40
+ for line in areas_array
41
+ )
42
+
43
+ line2str = (f'"{" ".join(line)}"' for line in fix_empty)
44
+ return " ".join(line2str)
45
+
46
+
47
+ def best_grid_template_columns(min_column_size: str):
48
+ return f"repeat(auto-fit,minmax(min({min_column_size},100%),1fr))"
@@ -0,0 +1 @@
1
+ from .index import rx_column, rx_row