@mrktg-common/internal-ui 1.14.0 → 1.16.0
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/CopyField.d.ts +7 -2
- package/dist/CopyField.js +32 -5
- package/dist/Menu.d.ts +3 -1
- package/dist/Menu.js +2 -2
- package/dist/Steps.d.ts +3 -1
- package/dist/Steps.js +2 -2
- package/dist/Toast.d.ts +6 -3
- package/dist/Toast.js +34 -17
- package/dist/components.css +9 -0
- package/package.json +4 -1
- package/tokens/tokens.json +1 -1
package/dist/CopyField.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface ICopyFieldProps {
|
|
|
5
5
|
/** Что копируется, для скринридера: «Copy address» → «Address copied». */
|
|
6
6
|
what?: string;
|
|
7
7
|
size?: 'sm' | 'md';
|
|
8
|
+
/**
|
|
9
|
+
* Команда терминала или короткий скрипт: значение видно целиком, перенос по пробелам, переводы строк
|
|
10
|
+
* сохраняются. Без Open: команда — не адрес. Для команд what="Command".
|
|
11
|
+
*/
|
|
12
|
+
multiline?: boolean;
|
|
8
13
|
/** Ссылка «Open» в новой вкладке; только для адресов. */
|
|
9
14
|
openHref?: string;
|
|
10
15
|
/** Адреса нет на сайте: зачёркнут, Open выключен с этой причиной, копировать можно. */
|
|
@@ -12,5 +17,5 @@ export interface ICopyFieldProps {
|
|
|
12
17
|
className?: string;
|
|
13
18
|
style?: CSSProperties;
|
|
14
19
|
}
|
|
15
|
-
/** Значение, которое копируют: адрес лендинга, id
|
|
16
|
-
export declare function CopyField({ value, what, size, openHref, offReason, className, style }: ICopyFieldProps): import("react").JSX.Element;
|
|
20
|
+
/** Значение, которое копируют: адрес лендинга, id запроса, команда. «Copied» с галочкой 2 с, нейтрально. */
|
|
21
|
+
export declare function CopyField({ value, what, size, multiline, openHref, offReason, className, style }: ICopyFieldProps): import("react").JSX.Element;
|
package/dist/CopyField.js
CHANGED
|
@@ -3,18 +3,45 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { Check, Copy, ExternalLink } from 'lucide-react';
|
|
5
5
|
import { cx } from './cx.js';
|
|
6
|
+
import { devError } from './devWarn.js';
|
|
6
7
|
export const COPIED_MS = 2000;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
function selectContents(element) {
|
|
9
|
+
const selection = window.getSelection();
|
|
10
|
+
if (element === null || selection === null)
|
|
11
|
+
return;
|
|
12
|
+
const range = document.createRange();
|
|
13
|
+
range.selectNodeContents(element);
|
|
14
|
+
selection.removeAllRanges();
|
|
15
|
+
selection.addRange(range);
|
|
16
|
+
}
|
|
17
|
+
/** Слово — одним куском (copy-word), пробелы и переводы строк остаются текстом между словами. */
|
|
18
|
+
function multilineWords(value) {
|
|
19
|
+
return value.split(/( |\n)/).map((part, index) => (part === ' ' || part === '\n' || part === '' ? part : _jsx("span", { className: "copy-word", children: part }, index)));
|
|
20
|
+
}
|
|
21
|
+
/** Значение, которое копируют: адрес лендинга, id запроса, команда. «Copied» с галочкой 2 с, нейтрально. */
|
|
22
|
+
export function CopyField({ value, what = 'Address', size = 'md', multiline = false, openHref, offReason, className, style }) {
|
|
9
23
|
const [copied, setCopied] = useState(false);
|
|
10
24
|
const timer = useRef(undefined);
|
|
25
|
+
const valueRef = useRef(null);
|
|
11
26
|
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (multiline && (openHref !== undefined || offReason !== undefined))
|
|
29
|
+
devError('CopyField: multiline has no Open, openHref and offReason are ignored');
|
|
30
|
+
}, [multiline, openHref, offReason]);
|
|
12
31
|
const copy = async () => {
|
|
13
|
-
|
|
32
|
+
try {
|
|
33
|
+
await navigator.clipboard.writeText(value);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Буфер недоступен: значение выделено, ⌘C скопирует его
|
|
37
|
+
selectContents(valueRef.current);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
14
40
|
setCopied(true);
|
|
15
41
|
window.clearTimeout(timer.current);
|
|
16
42
|
timer.current = window.setTimeout(() => setCopied(false), COPIED_MS);
|
|
17
43
|
};
|
|
18
|
-
const off = offReason !== undefined;
|
|
19
|
-
|
|
44
|
+
const off = !multiline && offReason !== undefined;
|
|
45
|
+
const open = multiline ? undefined : openHref;
|
|
46
|
+
return (_jsxs("div", { className: cx('copy', multiline ? 'copy-multi' : size === 'sm' && 'copy-sm', className), style: style, children: [multiline ? (_jsx("span", { ref: valueRef, className: "copy-url", children: multilineWords(value) })) : (_jsx("span", { ref: valueRef, className: cx('copy-url', off && 'is-off'), title: value, children: value })), open !== undefined && (off ? (_jsx("span", { className: "copy-act", role: "link", "aria-disabled": "true", "aria-label": offReason, title: offReason, children: _jsx(ExternalLink, { className: "ic ic-sm", "aria-hidden": true }) })) : (_jsx("a", { className: "copy-act", href: open, target: "_blank", rel: "noopener noreferrer", "aria-label": "Open in a new tab", title: "Open in a new tab", children: _jsx(ExternalLink, { className: "ic ic-sm", "aria-hidden": true }) }))), _jsxs("button", { type: "button", className: cx('copy-act', copied && 'is-done'), "aria-label": copied ? `${what} copied` : `Copy ${what.toLowerCase()}`, onClick: () => void copy(), children: [copied ? _jsx(Check, { className: "ic ic-sm", "aria-hidden": true }) : _jsx(Copy, { className: "ic ic-sm", "aria-hidden": true }), copied ? 'Copied' : 'Copy'] })] }));
|
|
20
47
|
}
|
package/dist/Menu.d.ts
CHANGED
|
@@ -27,9 +27,11 @@ export interface IMenuItemProps {
|
|
|
27
27
|
/** Справа серым: сочетание клавиш или значение. */
|
|
28
28
|
trailing?: ReactNode;
|
|
29
29
|
title?: string;
|
|
30
|
+
/** Пункт открывает окно или подменю: aria-haspopup, на экране ничего не меняется. */
|
|
31
|
+
hasPopup?: 'dialog' | 'menu';
|
|
30
32
|
children: ReactNode;
|
|
31
33
|
}
|
|
32
|
-
export declare function MenuItem({ icon: Icon, onSelect, href, danger, disabledReason, disabled, trailing, title, children }: IMenuItemProps): import("react").JSX.Element;
|
|
34
|
+
export declare function MenuItem({ icon: Icon, onSelect, href, danger, disabledReason, disabled, trailing, title, hasPopup, children }: IMenuItemProps): import("react").JSX.Element;
|
|
33
35
|
export declare function MenuSeparator(): import("react").JSX.Element;
|
|
34
36
|
export declare function MenuLabel({ children }: {
|
|
35
37
|
children: ReactNode;
|
package/dist/Menu.js
CHANGED
|
@@ -26,13 +26,13 @@ export function moveMenuFocus(event) {
|
|
|
26
26
|
export function Menu({ open, onClose, trigger, align, width, className, 'aria-label': label, children }) {
|
|
27
27
|
return (_jsx(Popover, { open: open, onClose: onClose, trigger: trigger, align: align, width: width, role: "menu", "aria-label": label, className: className, onKeyDown: moveMenuFocus, children: _jsx(MenuCloseContext.Provider, { value: onClose, children: children }) }));
|
|
28
28
|
}
|
|
29
|
-
export function MenuItem({ icon: Icon, onSelect, href, danger = false, disabledReason, disabled = false, trailing, title, children }) {
|
|
29
|
+
export function MenuItem({ icon: Icon, onSelect, href, danger = false, disabledReason, disabled = false, trailing, title, hasPopup, children }) {
|
|
30
30
|
const close = useContext(MenuCloseContext);
|
|
31
31
|
const hintId = useId();
|
|
32
32
|
const off = disabled || disabledReason !== undefined;
|
|
33
33
|
const className = cx('menu-item', danger && 'is-danger');
|
|
34
34
|
const content = (_jsxs(_Fragment, { children: [Icon && _jsx(Icon, { className: "ic", "aria-hidden": true }), _jsx("span", { className: "trunc", style: { flex: 1 }, children: children }), trailing !== undefined && _jsx("span", { className: "trail", children: trailing })] }));
|
|
35
|
-
return (_jsxs(_Fragment, { children: [href !== undefined && !off ? (_jsx("a", { className: className, role: "menuitem", href: href, title: title, onClick: close, children: content })) : (_jsx("button", { type: "button", role: "menuitem", className: className, "aria-disabled": off || undefined, "aria-describedby": disabledReason === undefined ? undefined : hintId, title: title, onClick: () => {
|
|
35
|
+
return (_jsxs(_Fragment, { children: [href !== undefined && !off ? (_jsx("a", { className: className, role: "menuitem", href: href, title: title, "aria-haspopup": hasPopup, onClick: close, children: content })) : (_jsx("button", { type: "button", role: "menuitem", className: className, "aria-disabled": off || undefined, "aria-describedby": disabledReason === undefined ? undefined : hintId, "aria-haspopup": hasPopup, title: title, onClick: () => {
|
|
36
36
|
if (off)
|
|
37
37
|
return;
|
|
38
38
|
close();
|
package/dist/Steps.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ export interface IStepProps {
|
|
|
11
11
|
time?: ReactNode;
|
|
12
12
|
/** Ошибка упавшего шага и что она значит для сайта. */
|
|
13
13
|
error?: ReactNode;
|
|
14
|
+
/** Блок под текстом шага (step-body): команда для копирования, кнопка, поле. */
|
|
15
|
+
children?: ReactNode;
|
|
14
16
|
}
|
|
15
17
|
/** Шаг долгой операции или пункт инструкции. Готовый шаг нейтральный: зелёный приходит с результатом. */
|
|
16
|
-
export declare function Step({ state, number, title, meta, time, error }: IStepProps): import("react").JSX.Element;
|
|
18
|
+
export declare function Step({ state, number, title, meta, time, error, children }: IStepProps): import("react").JSX.Element;
|
|
17
19
|
/** Этапы публикации или снятия либо нумерованная инструкция. */
|
|
18
20
|
export declare function Steps({ children, 'aria-label': label }: {
|
|
19
21
|
children: ReactNode;
|
package/dist/Steps.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Check, X } from 'lucide-react';
|
|
3
3
|
/** Шаг долгой операции или пункт инструкции. Готовый шаг нейтральный: зелёный приходит с результатом. */
|
|
4
|
-
export function Step({ state = 'wait', number, title, meta, time, error }) {
|
|
4
|
+
export function Step({ state = 'wait', number, title, meta, time, error, children }) {
|
|
5
5
|
const numbered = number !== undefined;
|
|
6
|
-
return (_jsxs("li", { className: numbered ? 'step is-num' : `step is-${state}`, "aria-current": !numbered && state === 'run' ? 'step' : undefined, children: [_jsx("span", { className: "step-ic", children: numbered ? number : state === 'done' ? _jsx(Check, { className: "ic ic-sm", "aria-hidden": true }) : state === 'fail' ? _jsx(X, { className: "ic ic-sm", "aria-hidden": true }) : state === 'run' ? _jsx("span", { className: "spin16", "aria-hidden": true }) : null }), _jsxs("div", { className: "col", children: [_jsx("span", { className: "step-title", children: title }), meta !== undefined && _jsx("span", { className: "step-meta", children: meta }), error !== undefined && _jsx("span", { className: "step-err", children: error })] }), _jsx("span", { className: "step-time", children: time })] }));
|
|
6
|
+
return (_jsxs("li", { className: numbered ? 'step is-num' : `step is-${state}`, "aria-current": !numbered && state === 'run' ? 'step' : undefined, children: [_jsx("span", { className: "step-ic", children: numbered ? number : state === 'done' ? _jsx(Check, { className: "ic ic-sm", "aria-hidden": true }) : state === 'fail' ? _jsx(X, { className: "ic ic-sm", "aria-hidden": true }) : state === 'run' ? _jsx("span", { className: "spin16", "aria-hidden": true }) : null }), _jsxs("div", { className: "col", children: [_jsx("span", { className: "step-title", children: title }), meta !== undefined && _jsx("span", { className: "step-meta", children: meta }), error !== undefined && _jsx("span", { className: "step-err", children: error }), children !== undefined && children !== null && children !== false && _jsx("div", { className: "step-body", children: children })] }), _jsx("span", { className: "step-time", children: time })] }));
|
|
7
7
|
}
|
|
8
8
|
/** Этапы публикации или снятия либо нумерованная инструкция. */
|
|
9
9
|
export function Steps({ children, 'aria-label': label }) {
|
package/dist/Toast.d.ts
CHANGED
|
@@ -29,8 +29,11 @@ export type TToastPatch = Partial<Pick<TToast, 'tone' | 'icon' | 'title' | 'desc
|
|
|
29
29
|
export type TToastApi = {
|
|
30
30
|
show: (toast: TToast) => number;
|
|
31
31
|
dismiss: (id: number) => void;
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Меняет показанный тост на месте и запускает его таймер заново. false — тоста уже нет (закрыли или
|
|
34
|
+
* вытеснили из стопки), ничего не изменилось: итог, который нужен человеку, продукт показывает новым тостом.
|
|
35
|
+
*/
|
|
36
|
+
update: (id: number, patch: TToastPatch) => boolean;
|
|
34
37
|
};
|
|
35
38
|
export declare const TOAST_MS = 6000;
|
|
36
39
|
export declare const TOAST_UNDO_MS = 10000;
|
|
@@ -44,7 +47,7 @@ export declare function useToast(): TToastApi;
|
|
|
44
47
|
export declare function useToastInsetEnd(width: number | null): void;
|
|
45
48
|
/**
|
|
46
49
|
* Что только что произошло: справа снизу, до трёх штук, новый внизу. Таймеры стоят, пока указатель
|
|
47
|
-
* над стопкой или фокус
|
|
50
|
+
* над стопкой или в ней фокус с клавиатуры, и пока идёт действие тоста. Закрыть можно всегда.
|
|
48
51
|
*/
|
|
49
52
|
export declare function ToastProvider({ children }: {
|
|
50
53
|
children: ReactNode;
|
package/dist/Toast.js
CHANGED
|
@@ -40,34 +40,51 @@ export function useToastInsetEnd(width) {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Что только что произошло: справа снизу, до трёх штук, новый внизу. Таймеры стоят, пока указатель
|
|
43
|
-
* над стопкой или фокус
|
|
43
|
+
* над стопкой или в ней фокус с клавиатуры, и пока идёт действие тоста. Закрыть можно всегда.
|
|
44
44
|
*/
|
|
45
45
|
export function ToastProvider({ children }) {
|
|
46
46
|
const [toasts, setToasts] = useState([]);
|
|
47
47
|
const [insetEnd, setInsetEnd] = useState(0);
|
|
48
48
|
const nextId = useRef(1);
|
|
49
|
-
|
|
49
|
+
// Зеркало состояния: update отвечает сразу, есть ли ещё тост, не дожидаясь рендера
|
|
50
|
+
const shown = useRef([]);
|
|
51
|
+
const commit = useCallback((next) => {
|
|
52
|
+
shown.current = next;
|
|
53
|
+
setToasts(next);
|
|
54
|
+
}, []);
|
|
55
|
+
const dismiss = useCallback((id) => {
|
|
56
|
+
if (shown.current.some((toast) => toast.id === id))
|
|
57
|
+
commit(shown.current.filter((toast) => toast.id !== id));
|
|
58
|
+
}, [commit]);
|
|
50
59
|
const show = useCallback((toast) => {
|
|
51
60
|
const id = nextId.current++;
|
|
52
|
-
|
|
61
|
+
commit([...shown.current, { ...toast, id, node: 0, revision: 0 }].slice(-MAX_TOASTS));
|
|
53
62
|
return id;
|
|
54
|
-
}, []);
|
|
63
|
+
}, [commit]);
|
|
55
64
|
const update = useCallback((id, patch) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
65
|
+
const current = shown.current.find((toast) => toast.id === id);
|
|
66
|
+
if (current === undefined)
|
|
67
|
+
return false;
|
|
68
|
+
const next = { ...current, ...patch, revision: current.revision + 1 };
|
|
69
|
+
// role="alert" читается, только если стоит на узле в момент появления: ошибка приходит новым тостом
|
|
70
|
+
if (next.tone === 'danger' && current.tone !== 'danger') {
|
|
71
|
+
commit([...shown.current.filter((toast) => toast !== current), { ...next, node: current.node + 1 }]);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
commit(shown.current.map((toast) => (toast === current ? next : toast)));
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}, [commit]);
|
|
68
78
|
const api = useMemo(() => ({ show, dismiss, update }), [show, dismiss, update]);
|
|
69
79
|
return (_jsx(ToastContext.Provider, { value: api, children: _jsxs(ToastInsetContext.Provider, { value: setInsetEnd, children: [children, _jsx(ToastStack, { toasts: toasts, insetEnd: insetEnd, onDismiss: dismiss })] }) }));
|
|
70
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Таймеры держит только фокус с клавиатуры. Фокус, который клик мышью оставил на кнопке (и который потом
|
|
83
|
+
* перешёл на Dismiss), не держит: пока указатель над стопкой, это уже делает наведение.
|
|
84
|
+
*/
|
|
85
|
+
function isKeyboardFocus(element) {
|
|
86
|
+
return element.matches(':focus-visible');
|
|
87
|
+
}
|
|
71
88
|
function ToastStack({ toasts, insetEnd, onDismiss }) {
|
|
72
89
|
const [hovered, setHovered] = useState(false);
|
|
73
90
|
const [focused, setFocused] = useState(false);
|
|
@@ -81,7 +98,7 @@ function ToastStack({ toasts, insetEnd, onDismiss }) {
|
|
|
81
98
|
if (toasts.length === 0)
|
|
82
99
|
return null;
|
|
83
100
|
const style = { '--toast-inset-end': `${insetEnd}px` };
|
|
84
|
-
return (_jsx(FixedPortal, { children: _jsx("div", { ref: stack, className: "toasts is-fixed", style: style, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onFocus: () => setFocused(
|
|
101
|
+
return (_jsx(FixedPortal, { children: _jsx("div", { ref: stack, className: "toasts is-fixed", style: style, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onFocus: (event) => setFocused(isKeyboardFocus(event.target)), onBlur: (event) => {
|
|
85
102
|
if (!event.currentTarget.contains(event.relatedTarget))
|
|
86
103
|
setFocused(false);
|
|
87
104
|
}, children: toasts.map((toast) => (_jsx(ToastItem, { toast: toast, paused: paused, onDismiss: () => onDismiss(toast.id) }, `${toast.id}:${toast.node}`))) }) }));
|
package/dist/components.css
CHANGED
|
@@ -408,6 +408,12 @@
|
|
|
408
408
|
/* Copied: neutral with a check; green is kept for Live. */
|
|
409
409
|
.copy-act.is-done, .app a.copy-act.is-done { color: var(--text); background: var(--bg-subtle); }
|
|
410
410
|
.copy-act:disabled, .copy-act[aria-disabled='true'] { opacity: 0.55; cursor: not-allowed; background: transparent; }
|
|
411
|
+
/* 1.16: multiline — a terminal command or a short script, shown whole. Wraps at spaces, a word moves as one piece
|
|
412
|
+
(copy-word), so “--flag” never splits on its hyphens; line breaks in the value stay. One line is 34, like md. */
|
|
413
|
+
.copy-multi { display: flex; width: 100%; height: auto; align-items: stretch; }
|
|
414
|
+
.copy-multi .copy-url { padding: 6px var(--space-3); font-size: var(--text-sm); line-height: 20px; white-space: pre-wrap; overflow: visible; text-overflow: clip; }
|
|
415
|
+
.copy-word { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
|
|
416
|
+
.copy-multi .copy-act { height: auto; min-height: 32px; padding: 0 var(--space-3); }
|
|
411
417
|
|
|
412
418
|
/* ---------- Modal ---------- */
|
|
413
419
|
/* Overlays and the toast stack are absolute inside an artboard; the app adds .is-fixed (portal to <body>). */
|
|
@@ -555,6 +561,9 @@
|
|
|
555
561
|
.step.is-fail .step-ic { background: var(--danger-soft); color: var(--danger-text); }
|
|
556
562
|
.step.is-fail .step-title { color: var(--danger-text); }
|
|
557
563
|
.step-err { margin-top: 2px; font-size: var(--text-sm); color: var(--danger-text); }
|
|
564
|
+
/* 1.16: a block under the step's text — a command to copy, a button, a field. */
|
|
565
|
+
.step-body { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); margin-top: 6px; min-width: 0; }
|
|
566
|
+
.step-body > .copy-multi { align-self: stretch; }
|
|
558
567
|
/* Numbered instructions (How translations work): the number on accent-soft. */
|
|
559
568
|
.step.is-num .step-ic { background: var(--accent-soft); color: var(--accent-text); }
|
|
560
569
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrktg-common/internal-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Общий интерфейс внутренних инструментов маркетинга (Landings Admin, LP Constructor): токены, классы компонентов и тонкие React-обёртки над ними.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,5 +65,8 @@
|
|
|
65
65
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
66
66
|
"typescript-eslint": "^8.70.0",
|
|
67
67
|
"vitest": "^4.1.11"
|
|
68
|
+
},
|
|
69
|
+
"overrides": {
|
|
70
|
+
"vite": "^8.3.8"
|
|
68
71
|
}
|
|
69
72
|
}
|