@companix/uikit 0.1.11 → 0.1.13

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;
@@ -30,4 +31,9 @@ export declare class Editor {
30
31
  private checkContentChanged;
31
32
  private resolveDomPosition;
32
33
  }
34
+ interface TextChunk {
35
+ kind: 'Text';
36
+ text: string;
37
+ }
38
+ export declare const toTextChunksLite: (input: string) => TextChunk[];
33
39
  export {};
@@ -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,3 @@
1
- export declare const isTextNode: (node: Node) => node is Text;
2
- export declare const isElementNode: (node: Node) => node is Element;
3
1
  export declare const getNodeTextContent: (node: Node) => string;
4
2
  export declare const getEditorSelection: (root: HTMLElement) => {
5
3
  range: Range;
@@ -1,5 +1,7 @@
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 { escape as u, unescape as f, isElementNode as g } from "@companix/utils-browser";
2
+ import { onElementKeyDownFactory as v } from "./bundle.es71.js";
3
+ import { getEditorSelection as l, normalizeEditorText as a, getNodeTextContent as h, scrollSelectionIntoView as d, getTextSelectionOffsets as E } from "./bundle.es72.js";
4
+ class k {
3
5
  element;
4
6
  prevText = "";
5
7
  prevTextSelection = { from: 0, to: 0 };
@@ -19,15 +21,12 @@ class v {
19
21
  this.handlers.paste = void 0, this.element.removeEventListener("paste", this.handlePaste);
20
22
  };
21
23
  }
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
- // }
24
+ onKeyCombo(e) {
25
+ const t = v(e);
26
+ return this.element.addEventListener("keydown", t), this.handlers.keyCombo = e, () => {
27
+ this.handlers.keyCombo = void 0, this.element.removeEventListener("keydown", t);
28
+ };
29
+ }
31
30
  onFocusChange(e) {
32
31
  return this.handlers.focusChange || (this.element.addEventListener("focus", this.handleFocus), this.element.addEventListener("blur", this.handleBlur)), this.handlers.focusChange = e, () => {
33
32
  this.handlers.focusChange = void 0, this.element.removeEventListener("focus", this.handleFocus), this.element.removeEventListener("blur", this.handleBlur);
@@ -44,13 +43,18 @@ class v {
44
43
  };
45
44
  }
46
45
  setSelection(e) {
47
- const t = r(this.element);
46
+ const t = l(this.element);
48
47
  if (!("selection" in t)) return;
49
48
  const n = document.createRange(), s = this.resolveDomPosition(e.from), o = this.resolveDomPosition(e.to);
50
49
  n.setStart(s.container, s.offset), n.setEnd(o.container, o.offset), t.selection.removeAllRanges(), t.selection.addRange(n);
51
50
  }
51
+ // вставить переданный текст в текущую выделенную область/позицию курсора внутри contenteditable
52
52
  insertAtSelection(e, t) {
53
- t && this.setSelection(t), this.checkContentChanged();
53
+ t && this.setSelection(t);
54
+ const n = C(u(e));
55
+ for (const s of n)
56
+ s.kind === "Text" && document.execCommand("insertText", !1, f(s.text));
57
+ this.checkContentChanged();
54
58
  }
55
59
  removeFormat() {
56
60
  document.execCommand("removeFormat");
@@ -59,7 +63,7 @@ class v {
59
63
  const s = !this.isFocused() && !n;
60
64
  this.element.innerText = "";
61
65
  const o = document.activeElement, i = this.element.inputMode;
62
- s && (this.element.inputMode = "none"), this.element.focus(), document.execCommand("removeFormat"), t ? document.execCommand("inserthtml", !1, e) : this.insertAtSelection(l(e)), s && (this.element.blur(), this.element.inputMode = i, o?.focus?.()), this.checkContentChanged();
66
+ s && (this.element.inputMode = "none"), this.element.focus(), document.execCommand("removeFormat"), t ? document.execCommand("inserthtml", !1, e) : this.insertAtSelection(a(e)), s && (this.element.blur(), this.element.inputMode = i, o?.focus?.()), this.checkContentChanged();
63
67
  }
64
68
  getText() {
65
69
  let e = "";
@@ -69,7 +73,7 @@ class v {
69
73
  );
70
74
  for (; t.nextNode(); )
71
75
  e += h(t.currentNode);
72
- return l(e);
76
+ return a(e);
73
77
  }
74
78
  getHtml() {
75
79
  return this.element.innerHTML;
@@ -78,18 +82,18 @@ class v {
78
82
  const e = this.element.innerHTML, t = /<img class="Emoji .+?" src=".+?" alt=".+?">/, n = /alt=".+?"/, s = (o) => {
79
83
  const i = o.match(t);
80
84
  if (!i?.[0]) return o;
81
- const a = i[0].match(n);
82
- if (!a?.[0]) return o;
83
- const d = a[0].replace("alt=", "").replaceAll('"', "");
84
- return s(o.replace(i[0], d));
85
+ const c = i[0].match(n);
86
+ if (!c?.[0]) return o;
87
+ const m = c[0].replace("alt=", "").replaceAll('"', "");
88
+ return s(o.replace(i[0], m));
85
89
  };
86
90
  return s(e);
87
91
  }
88
92
  focus(e = !1) {
89
93
  if (this.isFocused()) return;
90
94
  this.element.focus();
91
- const t = r(this.element);
92
- "selection" in t && (t.selection.selectAllChildren(this.element), e ? t.selection.collapseToStart() : t.selection.collapseToEnd(), c());
95
+ const t = l(this.element);
96
+ "selection" in t && (t.selection.selectAllChildren(this.element), e ? t.selection.collapseToStart() : t.selection.collapseToEnd(), d());
93
97
  }
94
98
  isFocused() {
95
99
  return document.activeElement === this.element;
@@ -103,7 +107,7 @@ class v {
103
107
  if (!t) return;
104
108
  const n = t.getData("text");
105
109
  if (n) {
106
- this.insertAtSelection(n), c();
110
+ this.insertAtSelection(n), d();
107
111
  return;
108
112
  }
109
113
  };
@@ -119,9 +123,9 @@ class v {
119
123
  n && (t.selectNode(e.target), t.collapse(e.offsetX <= 8), n.removeAllRanges(), n.addRange(t));
120
124
  };
121
125
  checkContentChanged = () => {
122
- const e = l(this.getText()), t = r(this.element);
126
+ const e = a(this.getText()), t = l(this.element);
123
127
  if (!("range" in t)) return;
124
- const n = m(this.element, t.range);
128
+ const n = E(this.element, t.range);
125
129
  if (e === this.prevText && n.from === this.prevTextSelection.from && n.to === this.prevTextSelection.to)
126
130
  return;
127
131
  const s = e === `
@@ -141,7 +145,7 @@ class v {
141
145
  for (; t.nextNode(); ) {
142
146
  const s = t.currentNode, o = h(s).length;
143
147
  if (o >= n)
144
- return u(s) && s.nodeName === "BR" && (n -= 1), {
148
+ return g(s) && s.nodeName === "BR" && (n -= 1), {
145
149
  container: s,
146
150
  offset: Math.max(n, 0)
147
151
  };
@@ -153,6 +157,8 @@ class v {
153
157
  };
154
158
  }
155
159
  }
160
+ const C = (r) => r ? [{ kind: "Text", text: r }] : [];
156
161
  export {
157
- v as Editor
162
+ k as Editor,
163
+ C as toTextChunksLite
158
164
  };
@@ -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,43 @@
1
- const r = (e, o) => {
2
- let t;
3
- try {
4
- t = localStorage.getItem(e) || void 0;
5
- } catch {
1
+ import { isTextNode as s, isElementNode as i } from "@companix/utils-browser";
2
+ const a = (t) => s(t) ? t.nodeValue || "" : i(t) && t.nodeName === "IMG" ? t.getAttribute("alt") || "" : i(t) && t.nodeName === "DIV" || i(t) && t.nodeName === "BR" && !(t.parentElement && i(t.parentElement) && t.parentElement.nodeName === "DIV" && t.parentElement.getAttribute("contenteditable") !== "true") ? `
3
+ ` : "", m = (t) => {
4
+ const e = document.getSelection();
5
+ if (!e || e.rangeCount === 0)
6
+ return {};
7
+ const n = e.getRangeAt(0);
8
+ return n && t.contains(n.commonAncestorContainer) ? { range: n, selection: e } : {};
9
+ }, l = (t, e, n) => {
10
+ let r = n, o = e;
11
+ t === e && (r = 0, o = t.childNodes[n]);
12
+ const c = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
13
+ for (; c.nextNode(); ) {
14
+ if (c.currentNode === o)
15
+ return r;
16
+ r += a(c.currentNode).length;
6
17
  }
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
- };
18
+ return r;
19
+ }, f = (t, e) => {
20
+ const n = l(t, e.startContainer, e.startOffset);
21
+ return {
22
+ from: n,
23
+ to: e.collapsed ? n : l(t, e.endContainer, e.endOffset)
24
+ };
25
+ }, g = () => {
26
+ const t = window.getSelection();
27
+ if (!t || !t.rangeCount) return;
28
+ const e = t.getRangeAt(0);
29
+ if (e.commonAncestorContainer === document) return;
30
+ const n = e.commonAncestorContainer.parentElement;
31
+ if (!n) return;
32
+ const r = n.getBoundingClientRect(), o = e.getBoundingClientRect().bottom - r.bottom;
33
+ o > 0 && n.scrollBy({ top: o });
34
+ }, d = (t) => t.replace(/&nbsp;/gi, " ").replace(/<br\s*\/?>/gi, `
35
+ `);
13
36
  export {
14
- r as getColorScheme,
15
- m as getSystemColorScheme,
16
- s as updateDOM
37
+ m as getEditorSelection,
38
+ a as getNodeTextContent,
39
+ l as getPlainTextOffset,
40
+ f as getTextSelectionOffsets,
41
+ d as normalizeEditorText,
42
+ g as scrollSelectionIntoView
17
43
  };
@@ -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.13",
4
4
  "main": "./dist/bundle.es.js",
5
5
  "module": "./dist/bundle.es.js",
6
6
  "types": "./dist/index.d.ts",