@companix/uikit 0.1.11 → 0.1.12

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.
@@ -10,6 +10,7 @@ export declare class Editor {
10
10
  constructor(element: HTMLSpanElement);
11
11
  getElement(): HTMLSpanElement;
12
12
  onPaste(handler: (files: File[]) => void): () => void;
13
+ onKeyCombo(handler: (combo: string | null, event: KeyboardEvent) => void): () => void;
13
14
  onFocusChange(handler: (focused: boolean) => void): () => void;
14
15
  onContentChange(handler: (text: string, selection: TextSelection) => void): () => void;
15
16
  onMouseDown(): () => void;
@@ -0,0 +1,16 @@
1
+ export declare enum Modifier {
2
+ Mod = "Mod",
3
+ Alt = "Alt",
4
+ Shift = "Shift",
5
+ Meta = "Meta"
6
+ }
7
+ export interface KeyCombo {
8
+ key: string;
9
+ code: string;
10
+ }
11
+ declare const MODULE_KEY_COMBOS: readonly [Modifier.Shift, Modifier.Mod, "ArrowDown", "ArrowUp", "Mod+ArrowDown", "Mod+ArrowUp", "Enter", "Escape", "Backspace", "Shift+Enter", "Mod+Enter", "ArrowLeft", "ArrowRight", "Tab", "Shift+Tab", "Space", "Mod+B", "Mod+U", "Mod+I", "Mod+S", "Mod+K", "Mod+Equal", "Mod+Shift+Equal", "Mod+Minus", "Mod+Shift+Minus", "PageUp", "PageDown", "Home", "End"];
12
+ export type ComboKeys = (typeof MODULE_KEY_COMBOS)[number];
13
+ export declare const getKeyCombo: (event: KeyboardEvent) => KeyCombo | undefined;
14
+ export declare const getModuleKeyCombo: (event: KeyboardEvent) => string | null;
15
+ declare const onElementKeyDownFactory: (handler: (combo: string | null, event: KeyboardEvent) => void) => (event: KeyboardEvent) => void;
16
+ export { onElementKeyDownFactory };
@@ -1,5 +1,6 @@
1
- import { getEditorSelection as r, normalizeEditorText as l, getNodeTextContent as h, scrollSelectionIntoView as c, getTextSelectionOffsets as m, isElementNode as u } from "./bundle.es71.js";
2
- class v {
1
+ import { onElementKeyDownFactory as m } from "./bundle.es71.js";
2
+ import { getEditorSelection as r, normalizeEditorText as l, getNodeTextContent as h, scrollSelectionIntoView as c, getTextSelectionOffsets as u, isElementNode as f } from "./bundle.es72.js";
3
+ class C {
3
4
  element;
4
5
  prevText = "";
5
6
  prevTextSelection = { from: 0, to: 0 };
@@ -19,15 +20,12 @@ class v {
19
20
  this.handlers.paste = void 0, this.element.removeEventListener("paste", this.handlePaste);
20
21
  };
21
22
  }
22
- // onKeyCombo(handler: (combo: string, event: KeyboardEvent) => void): () => void {
23
- // const listener = onElementKeyDownFactory(handler) as EventListener
24
- // this.element.addEventListener('keydown', listener)
25
- // this.handlers.keyCombo = handler
26
- // return () => {
27
- // this.handlers.keyCombo = undefined
28
- // this.element.removeEventListener('keydown', listener)
29
- // }
30
- // }
23
+ onKeyCombo(e) {
24
+ const t = m(e);
25
+ return this.element.addEventListener("keydown", t), this.handlers.keyCombo = e, () => {
26
+ this.handlers.keyCombo = void 0, this.element.removeEventListener("keydown", t);
27
+ };
28
+ }
31
29
  onFocusChange(e) {
32
30
  return this.handlers.focusChange || (this.element.addEventListener("focus", this.handleFocus), this.element.addEventListener("blur", this.handleBlur)), this.handlers.focusChange = e, () => {
33
31
  this.handlers.focusChange = void 0, this.element.removeEventListener("focus", this.handleFocus), this.element.removeEventListener("blur", this.handleBlur);
@@ -121,7 +119,7 @@ class v {
121
119
  checkContentChanged = () => {
122
120
  const e = l(this.getText()), t = r(this.element);
123
121
  if (!("range" in t)) return;
124
- const n = m(this.element, t.range);
122
+ const n = u(this.element, t.range);
125
123
  if (e === this.prevText && n.from === this.prevTextSelection.from && n.to === this.prevTextSelection.to)
126
124
  return;
127
125
  const s = e === `
@@ -141,7 +139,7 @@ class v {
141
139
  for (; t.nextNode(); ) {
142
140
  const s = t.currentNode, o = h(s).length;
143
141
  if (o >= n)
144
- return u(s) && s.nodeName === "BR" && (n -= 1), {
142
+ return f(s) && s.nodeName === "BR" && (n -= 1), {
145
143
  container: s,
146
144
  offset: Math.max(n, 0)
147
145
  };
@@ -154,5 +152,5 @@ class v {
154
152
  }
155
153
  }
156
154
  export {
157
- v as Editor
155
+ C as Editor
158
156
  };
@@ -1,6 +1,6 @@
1
1
  import { jsx as u } from "react/jsx-runtime";
2
2
  import { useState as h, useEffect as c, createContext as f, useContext as w } from "react";
3
- import { getColorScheme as v, updateDOM as m } from "./bundle.es72.js";
3
+ import { getColorScheme as v, updateDOM as m } from "./bundle.es73.js";
4
4
  const i = f({
5
5
  setColorScheme: () => {
6
6
  }
@@ -1,7 +1,7 @@
1
1
  import { jsx as i } from "react/jsx-runtime";
2
2
  import { hash as m } from "@companix/utils-js";
3
3
  import { useRef as n, useMemo as s } from "react";
4
- import { Viewport as p } from "./bundle.es73.js";
4
+ import { Viewport as p } from "./bundle.es74.js";
5
5
  const a = (t = {}) => {
6
6
  const e = {
7
7
  emit: (r) => {
@@ -1,6 +1,6 @@
1
1
  import { jsx as t } from "react/jsx-runtime";
2
2
  import { hash as r } from "@companix/utils-js";
3
- import { Viewport as a } from "./bundle.es74.js";
3
+ import { Viewport as a } from "./bundle.es75.js";
4
4
  import { useRef as c, useMemo as h } from "react";
5
5
  const m = (i = {}) => {
6
6
  const o = {
@@ -2,7 +2,7 @@ import { jsxs as b, jsx as o } from "react/jsx-runtime";
2
2
  import h from "classnames";
3
3
  import { attr as e } from "@companix/utils-browser";
4
4
  import { forwardRef as x } from "react";
5
- import { useInputPadding as N } from "./bundle.es77.js";
5
+ import { useInputPadding as N } from "./bundle.es78.js";
6
6
  const v = x(
7
7
  ({
8
8
  required: s,
@@ -1,7 +1,7 @@
1
1
  import { jsxs as D, jsx as t } from "react/jsx-runtime";
2
2
  import { dateToFormat as $, weeks as g, createVoids as p, getDayIndex as b, getFirstDay as u, getMonthMaxDay as k } from "./bundle.es64.js";
3
- import { CalendarHeader as F } from "./bundle.es75.js";
4
- import { useCalendar as j } from "./bundle.es76.js";
3
+ import { CalendarHeader as F } from "./bundle.es76.js";
4
+ import { useCalendar as j } from "./bundle.es77.js";
5
5
  import { attr as m } from "@companix/utils-browser";
6
6
  import { isSameDate as f } from "./bundle.es58.js";
7
7
  import { useLayoutEffect as I } from "react";
@@ -1,44 +1,68 @@
1
- const l = (e) => e.nodeType === Node.TEXT_NODE, c = (e) => e.nodeType === Node.ELEMENT_NODE, a = (e) => l(e) ? e.nodeValue || "" : c(e) && e.nodeName === "IMG" ? e.getAttribute("alt") || "" : c(e) && e.nodeName === "DIV" || c(e) && e.nodeName === "BR" && !(e.parentElement && c(e.parentElement) && e.parentElement.nodeName === "DIV" && e.parentElement.getAttribute("contenteditable") !== "true") ? `
2
- ` : "", u = (e) => {
3
- const t = document.getSelection();
4
- if (!t || t.rangeCount === 0)
5
- return {};
6
- const n = t.getRangeAt(0);
7
- return n && e.contains(n.commonAncestorContainer) ? { range: n, selection: t } : {};
8
- }, s = (e, t, n) => {
9
- let r = n, o = t;
10
- e === t && (r = 0, o = e.childNodes[n]);
11
- const i = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
12
- for (; i.nextNode(); ) {
13
- if (i.currentNode === o)
14
- return r;
15
- r += a(i.currentNode).length;
1
+ var a = /* @__PURE__ */ ((o) => (o.Mod = "Mod", o.Alt = "Alt", o.Shift = "Shift", o.Meta = "Meta", o))(a || {});
2
+ const l = [
3
+ "Shift",
4
+ "Mod",
5
+ "ArrowDown",
6
+ "ArrowUp",
7
+ "Mod+ArrowDown",
8
+ "Mod+ArrowUp",
9
+ "Enter",
10
+ "Escape",
11
+ "Backspace",
12
+ "Shift+Enter",
13
+ "Mod+Enter",
14
+ "ArrowLeft",
15
+ "ArrowRight",
16
+ "Tab",
17
+ "Shift+Tab",
18
+ "Space",
19
+ "Mod+B",
20
+ "Mod+U",
21
+ "Mod+I",
22
+ "Mod+S",
23
+ "Mod+K",
24
+ "Mod+Equal",
25
+ "Mod+Shift+Equal",
26
+ "Mod+Minus",
27
+ "Mod+Shift+Minus",
28
+ "PageUp",
29
+ "PageDown",
30
+ "Home",
31
+ "End"
32
+ ], c = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform), d = (o) => o.key === "Meta" || o.metaKey, s = (o) => o.key === "Control" || o.ctrlKey, M = {
33
+ Mod: (o) => c ? d(o) : s(o),
34
+ Alt: (o) => o.key === "Alt" || o.altKey,
35
+ Shift: (o) => o.key === "Shift" || o.shiftKey,
36
+ Meta: (o) => c ? s(o) : d(o)
37
+ }, f = (o) => {
38
+ try {
39
+ const t = [];
40
+ for (const e of Object.values(a))
41
+ M[e](o) && t.push(e);
42
+ if (["Meta", "Control", "Alt", "Shift"].includes(o.key)) {
43
+ const e = t.join("+");
44
+ return { key: e, code: e };
45
+ }
46
+ const r = ["Key", "Digit", "Numpad"].find((e) => o.code.startsWith(e)), n = r ? o.code.slice(r.length) : o.code, i = o.key.length === 1 ? o.key.toUpperCase() : o.key;
47
+ return {
48
+ key: [...t, i].join("+"),
49
+ code: [...t, n].join("+")
50
+ };
51
+ } catch {
52
+ return;
16
53
  }
17
- return r;
18
- }, m = (e, t) => {
19
- const n = s(e, t.startContainer, t.startOffset);
20
- return {
21
- from: n,
22
- to: t.collapsed ? n : s(e, t.endContainer, t.endOffset)
23
- };
24
- }, f = () => {
25
- const e = window.getSelection();
26
- if (!e || !e.rangeCount) return;
27
- const t = e.getRangeAt(0);
28
- if (t.commonAncestorContainer === document) return;
29
- const n = t.commonAncestorContainer.parentElement;
30
- if (!n) return;
31
- const r = n.getBoundingClientRect(), o = t.getBoundingClientRect().bottom - r.bottom;
32
- o > 0 && n.scrollBy({ top: o });
33
- }, d = (e) => e.replace(/&nbsp;/gi, " ").replace(/<br\s*\/?>/gi, `
34
- `);
54
+ }, y = (o) => {
55
+ const t = f(o);
56
+ if (!t)
57
+ return null;
58
+ const { key: r, code: n } = t;
59
+ return [r, n].find((i) => l.includes(i)) ?? null;
60
+ }, u = (o) => (t) => {
61
+ o(y(t), t);
62
+ };
35
63
  export {
36
- u as getEditorSelection,
37
- a as getNodeTextContent,
38
- s as getPlainTextOffset,
39
- m as getTextSelectionOffsets,
40
- c as isElementNode,
41
- l as isTextNode,
42
- d as normalizeEditorText,
43
- f as scrollSelectionIntoView
64
+ a as Modifier,
65
+ f as getKeyCombo,
66
+ y as getModuleKeyCombo,
67
+ u as onElementKeyDownFactory
44
68
  };
@@ -1,17 +1,44 @@
1
- const r = (e, o) => {
2
- let t;
3
- try {
4
- t = localStorage.getItem(e) || void 0;
5
- } catch {
1
+ const l = (e) => e.nodeType === Node.TEXT_NODE, c = (e) => e.nodeType === Node.ELEMENT_NODE, a = (e) => l(e) ? e.nodeValue || "" : c(e) && e.nodeName === "IMG" ? e.getAttribute("alt") || "" : c(e) && e.nodeName === "DIV" || c(e) && e.nodeName === "BR" && !(e.parentElement && c(e.parentElement) && e.parentElement.nodeName === "DIV" && e.parentElement.getAttribute("contenteditable") !== "true") ? `
2
+ ` : "", u = (e) => {
3
+ const t = document.getSelection();
4
+ if (!t || t.rangeCount === 0)
5
+ return {};
6
+ const n = t.getRangeAt(0);
7
+ return n && e.contains(n.commonAncestorContainer) ? { range: n, selection: t } : {};
8
+ }, s = (e, t, n) => {
9
+ let r = n, o = t;
10
+ e === t && (r = 0, o = e.childNodes[n]);
11
+ const i = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
12
+ for (; i.nextNode(); ) {
13
+ if (i.currentNode === o)
14
+ return r;
15
+ r += a(i.currentNode).length;
6
16
  }
7
- return t ?? o;
8
- }, m = (e) => (e || (e = window.matchMedia("(prefers-color-scheme: dark)")), e.matches ? "dark" : "light"), s = (e) => {
9
- const [o, t] = ["theme-light", "theme-dark"];
10
- let c = e;
11
- e === "system" && (c = m()), document.documentElement.classList.remove(o, t), document.documentElement.classList.add(c === "dark" ? t : o), document.documentElement.style.colorScheme = c;
12
- };
17
+ return r;
18
+ }, m = (e, t) => {
19
+ const n = s(e, t.startContainer, t.startOffset);
20
+ return {
21
+ from: n,
22
+ to: t.collapsed ? n : s(e, t.endContainer, t.endOffset)
23
+ };
24
+ }, f = () => {
25
+ const e = window.getSelection();
26
+ if (!e || !e.rangeCount) return;
27
+ const t = e.getRangeAt(0);
28
+ if (t.commonAncestorContainer === document) return;
29
+ const n = t.commonAncestorContainer.parentElement;
30
+ if (!n) return;
31
+ const r = n.getBoundingClientRect(), o = t.getBoundingClientRect().bottom - r.bottom;
32
+ o > 0 && n.scrollBy({ top: o });
33
+ }, d = (e) => e.replace(/&nbsp;/gi, " ").replace(/<br\s*\/?>/gi, `
34
+ `);
13
35
  export {
14
- r as getColorScheme,
15
- m as getSystemColorScheme,
16
- s as updateDOM
36
+ u as getEditorSelection,
37
+ a as getNodeTextContent,
38
+ s as getPlainTextOffset,
39
+ m as getTextSelectionOffsets,
40
+ c as isElementNode,
41
+ l as isTextNode,
42
+ d as normalizeEditorText,
43
+ f as scrollSelectionIntoView
17
44
  };
@@ -1,34 +1,17 @@
1
- import { jsx as s, Fragment as p } from "react/jsx-runtime";
2
- import { forwardRef as f, useState as c, useImperativeHandle as u } from "react";
3
- import { AlertDialog as x } from "./bundle.es25.js";
4
- const g = f((l, a) => {
5
- const [i, o] = c([]);
6
- u(
7
- a,
8
- () => ({
9
- showAlert: (e) => {
10
- o((t) => [...t, e]);
11
- }
12
- }),
13
- []
14
- );
15
- const d = (e) => {
16
- o((t) => {
17
- const r = [...t], n = r.findIndex((m) => m.id === e);
18
- return n !== -1 && r.splice(n, 1), r;
19
- });
20
- };
21
- return /* @__PURE__ */ s(p, { children: i.map(({ id: e, ...t }) => /* @__PURE__ */ s(
22
- x,
23
- {
24
- defaultOpen: !0,
25
- onClosed: () => d(e),
26
- ...l,
27
- ...t
28
- },
29
- `alert-${e}`
30
- )) });
31
- });
1
+ const r = (e, o) => {
2
+ let t;
3
+ try {
4
+ t = localStorage.getItem(e) || void 0;
5
+ } catch {
6
+ }
7
+ return t ?? o;
8
+ }, m = (e) => (e || (e = window.matchMedia("(prefers-color-scheme: dark)")), e.matches ? "dark" : "light"), s = (e) => {
9
+ const [o, t] = ["theme-light", "theme-dark"];
10
+ let c = e;
11
+ e === "system" && (c = m()), document.documentElement.classList.remove(o, t), document.documentElement.classList.add(c === "dark" ? t : o), document.documentElement.style.colorScheme = c;
12
+ };
32
13
  export {
33
- g as Viewport
14
+ r as getColorScheme,
15
+ m as getSystemColorScheme,
16
+ s as updateDOM
34
17
  };
@@ -1,72 +1,34 @@
1
- import { jsxs as y, jsx as I } from "react/jsx-runtime";
2
- import { forwardRef as $, useState as b, useMemo as C, useImperativeHandle as w, useCallback as P, createElement as j } from "react";
3
- import * as c from "@radix-ui/react-toast";
4
- import { customCSS as k } from "@companix/utils-browser";
5
- import { Toast as E } from "./bundle.es53.js";
6
- var u = /* @__PURE__ */ ((r) => (r["top-center"] = "up", r["top-left"] = "left", r["top-right"] = "right", r["bottom-center"] = "down", r["bottom-left"] = "left", r["bottom-right"] = "right", r))(u || {});
7
- const M = $((r, h) => {
8
- const { side: l = "top", align: f = "center", gap: d = 14, duration: g, swipeThreshold: x, closeIcon: T } = r, [i, p] = b([]), a = C(() => ({}), []);
9
- w(
10
- h,
1
+ import { jsx as s, Fragment as p } from "react/jsx-runtime";
2
+ import { forwardRef as f, useState as c, useImperativeHandle as u } from "react";
3
+ import { AlertDialog as x } from "./bundle.es25.js";
4
+ const g = f((l, a) => {
5
+ const [i, o] = c([]);
6
+ u(
7
+ a,
11
8
  () => ({
12
- showToast: (t) => {
13
- p((o) => {
14
- const e = [...o], n = o.findIndex((s) => s.id === t.id);
15
- return n === -1 ? e.push(t) : e[n] = t, e;
16
- });
9
+ showAlert: (e) => {
10
+ o((t) => [...t, e]);
17
11
  }
18
12
  }),
19
13
  []
20
14
  );
21
- const m = P((t) => {
22
- t.forEach(({ id: o }, e) => {
23
- let n = 0;
24
- for (let s = e + 1; s < t.length; s++)
25
- a[t[s].id] && (n += a[t[s].id].clientHeight + d);
26
- a[o] && a[o].style.setProperty("--offset", `${n}px`);
27
- });
28
- }, []), v = (t) => {
29
- p((o) => {
30
- const e = [...o], n = e.findIndex((s) => s.id === t);
31
- return n !== -1 && e.splice(n, 1), e;
15
+ const d = (e) => {
16
+ o((t) => {
17
+ const r = [...t], n = r.findIndex((m) => m.id === e);
18
+ return n !== -1 && r.splice(n, 1), r;
32
19
  });
33
20
  };
34
- return /* @__PURE__ */ y(
35
- c.Provider,
21
+ return /* @__PURE__ */ s(p, { children: i.map(({ id: e, ...t }) => /* @__PURE__ */ s(
22
+ x,
36
23
  {
37
- swipeThreshold: x,
38
- swipeDirection: u[`${l}-${f}`],
39
- children: [
40
- i.map(({ id: t, ...o }) => /* @__PURE__ */ j(
41
- E,
42
- {
43
- ...o,
44
- id: t,
45
- key: `toaster-${t}`,
46
- duration: o.duration ?? g,
47
- closeIcon: T,
48
- onInitialized: (e) => {
49
- a[t] = e, m(i);
50
- },
51
- onClosing: () => {
52
- delete a[t], m(i);
53
- },
54
- onClosed: () => v(t)
55
- }
56
- )),
57
- /* @__PURE__ */ I(
58
- c.Viewport,
59
- {
60
- "data-side": l,
61
- "data-align": f,
62
- className: "toaster-viewport",
63
- style: k({ "--toasters-gap": `${d}px` })
64
- }
65
- )
66
- ]
67
- }
68
- );
24
+ defaultOpen: !0,
25
+ onClosed: () => d(e),
26
+ ...l,
27
+ ...t
28
+ },
29
+ `alert-${e}`
30
+ )) });
69
31
  });
70
32
  export {
71
- M as Viewport
33
+ g as Viewport
72
34
  };
@@ -1,77 +1,72 @@
1
- import { jsxs as d, jsx as o } from "react/jsx-runtime";
2
- import { useCallback as u, useMemo as h } from "react";
3
- import { Select as p } from "./bundle.es13.js";
4
- import { getMonths as k, getYears as z, DEFAULT_MAX_YEAR as f, DEFAULT_MIN_YEAR as g } from "./bundle.es64.js";
5
- import { Icon as C } from "./bundle.es35.js";
6
- import { faChevronLeft as E, faChevronRight as T } from "@companix/icons-solid";
7
- import { setMonth as _, setYear as F } from "./bundle.es58.js";
8
- const y = ({
9
- viewDate: n,
10
- onChange: c,
11
- isMonthDisabled: a,
12
- isYearDisabled: m,
13
- onNextMonth: N,
14
- onPrevMonth: v
15
- }) => {
16
- const e = n.getFullYear(), r = n.getMonth(), s = "ru", M = u(
17
- (t) => {
18
- c(_(n, t));
19
- },
20
- [c, n]
21
- ), x = u(
22
- (t) => {
23
- c(F(n, t));
24
- },
25
- [c, n]
26
- ), A = h(() => k(s).map((t) => ({
27
- ...t,
28
- className: "capitalize",
29
- disabled: a && a(t.value)
30
- })), [s, a]), Y = h(() => z(e, 100).map((t) => ({
31
- ...t,
32
- disabled: m && m(t.value)
33
- })), [e, m]);
34
- let l = r === 11 && e === f;
35
- a && !l && (l = a(
36
- r === 11 ? 0 : r + 1,
37
- r === 11 ? Math.min(e + 1, f) : e
38
- ));
39
- let i = r === 0 && e === g;
40
- return a && !i && (i = a(
41
- r === 0 ? 11 : r - 1,
42
- r === 0 ? Math.max(e - 1, g) : e
43
- )), /* @__PURE__ */ d("div", { className: "calendar-header", children: [
44
- !i && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "left", onClick: v, children: /* @__PURE__ */ o(C, { icon: E }) }),
45
- /* @__PURE__ */ d("div", { className: "calendar-pickers", children: [
46
- /* @__PURE__ */ o(
47
- p,
48
- {
49
- fill: !0,
50
- options: Y,
51
- size: "sm",
52
- value: e,
53
- minimalOptions: !0,
54
- matchTarget: "min-width",
55
- onChange: (t) => x(t)
56
- }
57
- ),
58
- /* @__PURE__ */ o(
59
- p,
60
- {
61
- fill: !0,
62
- options: A,
63
- size: "sm",
64
- className: "capitalize",
65
- value: r,
66
- minimalOptions: !0,
67
- matchTarget: "min-width",
68
- onChange: (t) => M(t)
69
- }
70
- )
71
- ] }),
72
- !l && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "right", onClick: N, children: /* @__PURE__ */ o(C, { icon: T }) })
73
- ] });
74
- };
1
+ import { jsxs as y, jsx as I } from "react/jsx-runtime";
2
+ import { forwardRef as $, useState as b, useMemo as C, useImperativeHandle as w, useCallback as P, createElement as j } from "react";
3
+ import * as c from "@radix-ui/react-toast";
4
+ import { customCSS as k } from "@companix/utils-browser";
5
+ import { Toast as E } from "./bundle.es53.js";
6
+ var u = /* @__PURE__ */ ((r) => (r["top-center"] = "up", r["top-left"] = "left", r["top-right"] = "right", r["bottom-center"] = "down", r["bottom-left"] = "left", r["bottom-right"] = "right", r))(u || {});
7
+ const M = $((r, h) => {
8
+ const { side: l = "top", align: f = "center", gap: d = 14, duration: g, swipeThreshold: x, closeIcon: T } = r, [i, p] = b([]), a = C(() => ({}), []);
9
+ w(
10
+ h,
11
+ () => ({
12
+ showToast: (t) => {
13
+ p((o) => {
14
+ const e = [...o], n = o.findIndex((s) => s.id === t.id);
15
+ return n === -1 ? e.push(t) : e[n] = t, e;
16
+ });
17
+ }
18
+ }),
19
+ []
20
+ );
21
+ const m = P((t) => {
22
+ t.forEach(({ id: o }, e) => {
23
+ let n = 0;
24
+ for (let s = e + 1; s < t.length; s++)
25
+ a[t[s].id] && (n += a[t[s].id].clientHeight + d);
26
+ a[o] && a[o].style.setProperty("--offset", `${n}px`);
27
+ });
28
+ }, []), v = (t) => {
29
+ p((o) => {
30
+ const e = [...o], n = e.findIndex((s) => s.id === t);
31
+ return n !== -1 && e.splice(n, 1), e;
32
+ });
33
+ };
34
+ return /* @__PURE__ */ y(
35
+ c.Provider,
36
+ {
37
+ swipeThreshold: x,
38
+ swipeDirection: u[`${l}-${f}`],
39
+ children: [
40
+ i.map(({ id: t, ...o }) => /* @__PURE__ */ j(
41
+ E,
42
+ {
43
+ ...o,
44
+ id: t,
45
+ key: `toaster-${t}`,
46
+ duration: o.duration ?? g,
47
+ closeIcon: T,
48
+ onInitialized: (e) => {
49
+ a[t] = e, m(i);
50
+ },
51
+ onClosing: () => {
52
+ delete a[t], m(i);
53
+ },
54
+ onClosed: () => v(t)
55
+ }
56
+ )),
57
+ /* @__PURE__ */ I(
58
+ c.Viewport,
59
+ {
60
+ "data-side": l,
61
+ "data-align": f,
62
+ className: "toaster-viewport",
63
+ style: k({ "--toasters-gap": `${d}px` })
64
+ }
65
+ )
66
+ ]
67
+ }
68
+ );
69
+ });
75
70
  export {
76
- y as CalendarHeader
71
+ M as Viewport
77
72
  };
@@ -1,51 +1,77 @@
1
- import { subMonths as L, addMonths as N, useDayDisableCheker as R } from "./bundle.es58.js";
2
- import { DEFAULT_MIN_YEAR as w, DEFAULT_MAX_YEAR as A } from "./bundle.es64.js";
3
- import { useState as U, useCallback as M } from "react";
4
- const X = ({
5
- value: p,
6
- disablePast: r,
7
- disableFuture: c,
8
- shouldDisableDate: E,
9
- minDateTime: l,
10
- maxDateTime: s
1
+ import { jsxs as d, jsx as o } from "react/jsx-runtime";
2
+ import { useCallback as u, useMemo as h } from "react";
3
+ import { Select as p } from "./bundle.es13.js";
4
+ import { getMonths as k, getYears as z, DEFAULT_MAX_YEAR as f, DEFAULT_MIN_YEAR as g } from "./bundle.es64.js";
5
+ import { Icon as C } from "./bundle.es35.js";
6
+ import { faChevronLeft as E, faChevronRight as T } from "@companix/icons-solid";
7
+ import { setMonth as _, setYear as F } from "./bundle.es58.js";
8
+ const y = ({
9
+ viewDate: n,
10
+ onChange: c,
11
+ isMonthDisabled: a,
12
+ isYearDisabled: m,
13
+ onNextMonth: N,
14
+ onPrevMonth: v
11
15
  }) => {
12
- const [e, u] = U(p || /* @__PURE__ */ new Date()), _ = M(() => {
13
- u(L(e, 1));
14
- }, [e]), C = M(() => {
15
- u(N(e, 1));
16
- }, [e]), D = R({
17
- disableFuture: c,
18
- disablePast: r,
19
- shouldDisableDate: E,
20
- minDateTime: l,
21
- maxDateTime: s
22
- }), k = M(
23
- (o, t) => {
24
- const n = /* @__PURE__ */ new Date();
25
- t = t || e.getFullYear();
26
- const h = l ? l.getMonth() : 0, Y = s ? s.getMonth() : 11, F = l?.getFullYear() || w, f = s?.getFullYear() || A;
27
- let g = t >= F && t <= f ? t === F && h > o || t === f && o > Y : !0;
28
- return c && (g = g || (t === n.getFullYear() ? o > n.getMonth() : t > n.getFullYear())), r && (g = g || (t === n.getFullYear() ? o < n.getMonth() : t < n.getFullYear())), g;
16
+ const e = n.getFullYear(), r = n.getMonth(), s = "ru", M = u(
17
+ (t) => {
18
+ c(_(n, t));
29
19
  },
30
- [c, r, e, l, s]
31
- ), v = M(
32
- (o) => {
33
- const t = /* @__PURE__ */ new Date(), n = l?.getFullYear() || w, h = s?.getFullYear() || A;
34
- let Y = n > o || o > h;
35
- return c && (Y = Y || o > t.getFullYear()), r && (Y = Y || o < t.getFullYear()), Y;
20
+ [c, n]
21
+ ), x = u(
22
+ (t) => {
23
+ c(F(n, t));
36
24
  },
37
- [c, r, l, s]
38
- );
39
- return {
40
- viewDate: e,
41
- setViewDate: u,
42
- setPrevMonth: _,
43
- setNextMonth: C,
44
- isDayDisabled: D,
45
- isMonthDisabled: k,
46
- isYearDisabled: v
47
- };
25
+ [c, n]
26
+ ), A = h(() => k(s).map((t) => ({
27
+ ...t,
28
+ className: "capitalize",
29
+ disabled: a && a(t.value)
30
+ })), [s, a]), Y = h(() => z(e, 100).map((t) => ({
31
+ ...t,
32
+ disabled: m && m(t.value)
33
+ })), [e, m]);
34
+ let l = r === 11 && e === f;
35
+ a && !l && (l = a(
36
+ r === 11 ? 0 : r + 1,
37
+ r === 11 ? Math.min(e + 1, f) : e
38
+ ));
39
+ let i = r === 0 && e === g;
40
+ return a && !i && (i = a(
41
+ r === 0 ? 11 : r - 1,
42
+ r === 0 ? Math.max(e - 1, g) : e
43
+ )), /* @__PURE__ */ d("div", { className: "calendar-header", children: [
44
+ !i && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "left", onClick: v, children: /* @__PURE__ */ o(C, { icon: E }) }),
45
+ /* @__PURE__ */ d("div", { className: "calendar-pickers", children: [
46
+ /* @__PURE__ */ o(
47
+ p,
48
+ {
49
+ fill: !0,
50
+ options: Y,
51
+ size: "sm",
52
+ value: e,
53
+ minimalOptions: !0,
54
+ matchTarget: "min-width",
55
+ onChange: (t) => x(t)
56
+ }
57
+ ),
58
+ /* @__PURE__ */ o(
59
+ p,
60
+ {
61
+ fill: !0,
62
+ options: A,
63
+ size: "sm",
64
+ className: "capitalize",
65
+ value: r,
66
+ minimalOptions: !0,
67
+ matchTarget: "min-width",
68
+ onChange: (t) => M(t)
69
+ }
70
+ )
71
+ ] }),
72
+ !l && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "right", onClick: N, children: /* @__PURE__ */ o(C, { icon: T }) })
73
+ ] });
48
74
  };
49
75
  export {
50
- X as useCalendar
76
+ y as CalendarHeader
51
77
  };
@@ -1,16 +1,51 @@
1
- import { useRef as l, useCallback as p } from "react";
2
- import { useEffectWithLayout as d } from "./bundle.es78.js";
3
- const g = (r, f) => {
4
- const c = l(null), i = l(null), o = { Right: c, Left: i }, u = p((t) => {
5
- if (r.current) {
6
- const n = r.current.style, e = o[t];
7
- e.current && e.current.clientWidth ? n[`padding${t}`] !== `${e.current.clientWidth}px` && (n[`padding${t}`] = `${e.current.clientWidth}px`) : n[`padding${t}`] && (n[`padding${t}`] = "");
8
- }
9
- }, []);
10
- return d(() => {
11
- u("Left"), u("Right");
12
- }, f), { rightRef: c, leftRef: i };
1
+ import { subMonths as L, addMonths as N, useDayDisableCheker as R } from "./bundle.es58.js";
2
+ import { DEFAULT_MIN_YEAR as w, DEFAULT_MAX_YEAR as A } from "./bundle.es64.js";
3
+ import { useState as U, useCallback as M } from "react";
4
+ const X = ({
5
+ value: p,
6
+ disablePast: r,
7
+ disableFuture: c,
8
+ shouldDisableDate: E,
9
+ minDateTime: l,
10
+ maxDateTime: s
11
+ }) => {
12
+ const [e, u] = U(p || /* @__PURE__ */ new Date()), _ = M(() => {
13
+ u(L(e, 1));
14
+ }, [e]), C = M(() => {
15
+ u(N(e, 1));
16
+ }, [e]), D = R({
17
+ disableFuture: c,
18
+ disablePast: r,
19
+ shouldDisableDate: E,
20
+ minDateTime: l,
21
+ maxDateTime: s
22
+ }), k = M(
23
+ (o, t) => {
24
+ const n = /* @__PURE__ */ new Date();
25
+ t = t || e.getFullYear();
26
+ const h = l ? l.getMonth() : 0, Y = s ? s.getMonth() : 11, F = l?.getFullYear() || w, f = s?.getFullYear() || A;
27
+ let g = t >= F && t <= f ? t === F && h > o || t === f && o > Y : !0;
28
+ return c && (g = g || (t === n.getFullYear() ? o > n.getMonth() : t > n.getFullYear())), r && (g = g || (t === n.getFullYear() ? o < n.getMonth() : t < n.getFullYear())), g;
29
+ },
30
+ [c, r, e, l, s]
31
+ ), v = M(
32
+ (o) => {
33
+ const t = /* @__PURE__ */ new Date(), n = l?.getFullYear() || w, h = s?.getFullYear() || A;
34
+ let Y = n > o || o > h;
35
+ return c && (Y = Y || o > t.getFullYear()), r && (Y = Y || o < t.getFullYear()), Y;
36
+ },
37
+ [c, r, l, s]
38
+ );
39
+ return {
40
+ viewDate: e,
41
+ setViewDate: u,
42
+ setPrevMonth: _,
43
+ setNextMonth: C,
44
+ isDayDisabled: D,
45
+ isMonthDisabled: k,
46
+ isYearDisabled: v
47
+ };
13
48
  };
14
49
  export {
15
- g as useInputPadding
50
+ X as useCalendar
16
51
  };
@@ -1,16 +1,16 @@
1
- import { useRef as f, useLayoutEffect as u, useEffect as s } from "react";
2
- const o = (t, r) => {
3
- const e = f(!1);
4
- u(() => {
5
- e.current = !0, t();
6
- }, []), s(() => {
7
- if (e.current) {
8
- e.current = !1;
9
- return;
1
+ import { useRef as l, useCallback as p } from "react";
2
+ import { useEffectWithLayout as d } from "./bundle.es79.js";
3
+ const g = (r, f) => {
4
+ const c = l(null), i = l(null), o = { Right: c, Left: i }, u = p((t) => {
5
+ if (r.current) {
6
+ const n = r.current.style, e = o[t];
7
+ e.current && e.current.clientWidth ? n[`padding${t}`] !== `${e.current.clientWidth}px` && (n[`padding${t}`] = `${e.current.clientWidth}px`) : n[`padding${t}`] && (n[`padding${t}`] = "");
10
8
  }
11
- t();
12
- }, r);
9
+ }, []);
10
+ return d(() => {
11
+ u("Left"), u("Right");
12
+ }, f), { rightRef: c, leftRef: i };
13
13
  };
14
14
  export {
15
- o as useEffectWithLayout
15
+ g as useInputPadding
16
16
  };
@@ -0,0 +1,16 @@
1
+ import { useRef as f, useLayoutEffect as u, useEffect as s } from "react";
2
+ const o = (t, r) => {
3
+ const e = f(!1);
4
+ u(() => {
5
+ e.current = !0, t();
6
+ }, []), s(() => {
7
+ if (e.current) {
8
+ e.current = !1;
9
+ return;
10
+ }
11
+ t();
12
+ }, r);
13
+ };
14
+ export {
15
+ o as useEffectWithLayout
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companix/uikit",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "main": "./dist/bundle.es.js",
5
5
  "module": "./dist/bundle.es.js",
6
6
  "types": "./dist/index.d.ts",