pixelize-design-library 2.4.2-beta.58 → 2.4.2-beta.60
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/CHANGELOG.md +149 -5
- package/COMPONENT-GOTCHAS.md +205 -18
- package/DESIGN-GUIDE.md +43 -9
- package/dist/Components/AppSwitcher/AppSwitcher.js +5 -1
- package/dist/Components/AppSwitcher/AppSwitcherProps.d.ts +2 -0
- package/dist/Components/AppSwitcher/AppSwitcherProps.js +7 -4
- package/dist/Components/AudioRecorder/AudioRecorder.d.ts +8 -0
- package/dist/Components/AudioRecorder/AudioRecorder.js +169 -0
- package/dist/Components/AudioRecorder/AudioRecorderProps.d.ts +20 -0
- package/dist/Components/AudioRecorder/AudioRecorderProps.js +2 -0
- package/dist/Components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/dist/Components/Breadcrumbs/Breadcrumbs.js +33 -10
- package/dist/Components/Breadcrumbs/BreadcrumbsProps.d.ts +16 -2
- package/dist/Components/BulkSelectionBar/BulkSelectionBar.d.ts +3 -0
- package/dist/Components/BulkSelectionBar/BulkSelectionBar.js +43 -0
- package/dist/Components/BulkSelectionBar/BulkSelectionBarProps.d.ts +35 -0
- package/dist/Components/BulkSelectionBar/BulkSelectionBarProps.js +2 -0
- package/dist/Components/BulkSelectionBar/index.d.ts +2 -0
- package/dist/Components/BulkSelectionBar/index.js +8 -0
- package/dist/Components/CalendarGrid/CalendarGrid.d.ts +3 -0
- package/dist/Components/CalendarGrid/CalendarGrid.js +173 -0
- package/dist/Components/CalendarGrid/CalendarGridProps.d.ts +54 -0
- package/dist/Components/CalendarGrid/CalendarGridProps.js +2 -0
- package/dist/Components/CalendarGrid/calendarMath.d.ts +49 -0
- package/dist/Components/CalendarGrid/calendarMath.js +178 -0
- package/dist/Components/Card/Card.d.ts +3 -1
- package/dist/Components/Card/Card.js +12 -2
- package/dist/Components/Card/CardProps.d.ts +5 -1
- package/dist/Components/CircularProgress/CircularProgress.d.ts +4 -0
- package/dist/Components/CircularProgress/CircularProgress.js +39 -0
- package/dist/Components/CircularProgress/CircularProgressProps.d.ts +22 -0
- package/dist/Components/CircularProgress/CircularProgressProps.js +2 -0
- package/dist/Components/CircularProgress/arc.d.ts +12 -0
- package/dist/Components/CircularProgress/arc.js +16 -0
- package/dist/Components/Common/fieldStyles.d.ts +1 -0
- package/dist/Components/Common/fieldStyles.js +2 -1
- package/dist/Components/Drawer/Drawer.d.ts +1 -1
- package/dist/Components/Drawer/Drawer.js +4 -2
- package/dist/Components/Drawer/DrawerProps.d.ts +3 -1
- package/dist/Components/Editor/Editor.js +50 -2
- package/dist/Components/Editor/EditorFieldBar.d.ts +15 -0
- package/dist/Components/Editor/EditorFieldBar.js +19 -0
- package/dist/Components/Editor/EditorProps.d.ts +74 -1
- package/dist/Components/Editor/MakeDynamicDialog.d.ts +12 -0
- package/dist/Components/Editor/MakeDynamicDialog.js +59 -0
- package/dist/Components/Editor/editorLabels.d.ts +4 -0
- package/dist/Components/Editor/editorLabels.js +24 -0
- package/dist/Components/Editor/editorTokenStyles.d.ts +28 -0
- package/dist/Components/Editor/editorTokenStyles.js +30 -0
- package/dist/Components/Editor/editorTokens.d.ts +26 -0
- package/dist/Components/Editor/editorTokens.js +134 -0
- package/dist/Components/Editor/useEditorBridge.d.ts +40 -0
- package/dist/Components/Editor/useEditorBridge.js +141 -0
- package/dist/Components/EmptyState/EmptyState.js +2 -1
- package/dist/Components/EmptyState/EmptyStateProps.d.ts +2 -2
- package/dist/Components/FormDrawer/FormDrawer.d.ts +2 -0
- package/dist/Components/FormDrawer/FormDrawer.js +97 -0
- package/dist/Components/FormDrawer/FormDrawerProps.d.ts +55 -0
- package/dist/Components/FormDrawer/FormDrawerProps.js +2 -0
- package/dist/Components/Kbd/Kbd.d.ts +6 -0
- package/dist/Components/Kbd/Kbd.js +33 -0
- package/dist/Components/Kbd/KbdProps.d.ts +17 -0
- package/dist/Components/Kbd/KbdProps.js +2 -0
- package/dist/Components/LauncherTrigger/LauncherTrigger.d.ts +4 -0
- package/dist/Components/LauncherTrigger/LauncherTrigger.js +48 -0
- package/dist/Components/LauncherTrigger/LauncherTriggerProps.d.ts +18 -0
- package/dist/Components/LauncherTrigger/LauncherTriggerProps.js +2 -0
- package/dist/Components/Modal/Modal.d.ts +1 -1
- package/dist/Components/Modal/Modal.js +4 -2
- package/dist/Components/Modal/ModalProps.d.ts +3 -1
- package/dist/Components/Modal/warnDroppedSlotChildren.d.ts +2 -0
- package/dist/Components/Modal/warnDroppedSlotChildren.js +45 -0
- package/dist/Components/NavLauncher/NavLauncher.d.ts +3 -0
- package/dist/Components/NavLauncher/NavLauncher.js +452 -0
- package/dist/Components/NavLauncher/NavLauncherProps.d.ts +187 -0
- package/dist/Components/NavLauncher/NavLauncherProps.js +2 -0
- package/dist/Components/NavLauncher/NewTabLink.d.ts +3 -0
- package/dist/Components/NavLauncher/NewTabLink.js +14 -0
- package/dist/Components/NavLauncher/PinToggle.d.ts +3 -0
- package/dist/Components/NavLauncher/PinToggle.js +21 -0
- package/dist/Components/NavLauncher/launcherParts.d.ts +152 -0
- package/dist/Components/NavLauncher/launcherParts.js +212 -0
- package/dist/Components/NavLauncher/match.d.ts +53 -0
- package/dist/Components/NavLauncher/match.js +178 -0
- package/dist/Components/NavLauncher/revealStyles.d.ts +4 -0
- package/dist/Components/NavLauncher/revealStyles.js +19 -0
- package/dist/Components/NavigationBar/NavigationBar.d.ts +1 -1
- package/dist/Components/NavigationBar/NavigationBar.js +2 -2
- package/dist/Components/NavigationBar/NavigationBarProps.d.ts +2 -0
- package/dist/Components/PageHeader/PageHeader.d.ts +1 -1
- package/dist/Components/PageHeader/PageHeader.js +9 -2
- package/dist/Components/PageHeader/PageHeaderProps.d.ts +8 -0
- package/dist/Components/PdfViewer/PdfViewer.d.ts +21 -4
- package/dist/Components/PdfViewer/PdfViewer.js +124 -3
- package/dist/Components/ProfilePhotoViewer/ProfilePhotoViewer.js +5 -0
- package/dist/Components/ProfilePhotoViewer/ProfilePhotoViewerProps.d.ts +1 -1
- package/dist/Components/QueryState/QueryStateBoundary.d.ts +2 -2
- package/dist/Components/QueryState/QueryStateBoundary.js +9 -3
- package/dist/Components/QueryState/QueryStateProps.d.ts +19 -2
- package/dist/Components/Search/Search.js +2 -1
- package/dist/Components/SectionRail/SectionRail.d.ts +3 -0
- package/dist/Components/SectionRail/SectionRail.js +49 -0
- package/dist/Components/SectionRail/SectionRailProps.d.ts +23 -0
- package/dist/Components/SectionRail/SectionRailProps.js +2 -0
- package/dist/Components/SectionRail/index.d.ts +2 -0
- package/dist/Components/SectionRail/index.js +8 -0
- package/dist/Components/SegmentedControl/SegmentedControl.js +9 -14
- package/dist/Components/SegmentedControl/segmentedInk.d.ts +0 -2
- package/dist/Components/SegmentedControl/segmentedInk.js +1 -5
- package/dist/Components/SideBar/SecondaryBar.js +4 -3
- package/dist/Components/SideBar/SideBar.d.ts +1 -1
- package/dist/Components/SideBar/SideBar.js +30 -9
- package/dist/Components/SideBar/SideBarProps.d.ts +32 -0
- package/dist/Components/SideBar/components/MenuItemBox.d.ts +6 -0
- package/dist/Components/SideBar/components/MenuItemBox.js +8 -4
- package/dist/Components/SideBar/components/MenuPopoverContent.js +3 -2
- package/dist/Components/SideBar/components/OtherApps.js +2 -1
- package/dist/Components/SideBar/components/PinnedSection.d.ts +17 -0
- package/dist/Components/SideBar/components/PinnedSection.js +98 -0
- package/dist/Components/SideBar/sidebarFocus.d.ts +23 -0
- package/dist/Components/SideBar/sidebarFocus.js +20 -0
- package/dist/Components/StageProgress/StageProgress.js +2 -2
- package/dist/Components/StageProgress/StageProgressProps.d.ts +2 -0
- package/dist/Components/StageProgress/StepperStage.js +5 -2
- package/dist/Components/StatCard/StatCard.d.ts +1 -1
- package/dist/Components/StatCard/StatCard.js +6 -2
- package/dist/Components/StatCard/StatCardProps.d.ts +3 -0
- package/dist/Components/StatusTag/StatusTag.d.ts +4 -0
- package/dist/Components/StatusTag/StatusTag.js +24 -0
- package/dist/Components/StatusTag/StatusTagProps.d.ts +20 -0
- package/dist/Components/StatusTag/StatusTagProps.js +2 -0
- package/dist/Components/Table/Table.d.ts +1 -1
- package/dist/Components/Table/Table.js +6 -2
- package/dist/Components/Table/TableProps.d.ts +20 -0
- package/dist/Components/Table/components/TableBody.d.ts +1 -1
- package/dist/Components/Table/components/TableBody.js +43 -18
- package/dist/Components/Table/components/TableHeader.d.ts +1 -1
- package/dist/Components/Table/components/TableHeader.js +7 -5
- package/dist/Components/Table/components/rowDetail.d.ts +32 -0
- package/dist/Components/Table/components/rowDetail.js +20 -0
- package/dist/Components/Table/hooks/useRowExpansion.d.ts +7 -0
- package/dist/Components/Table/hooks/useRowExpansion.js +27 -0
- package/dist/Components/Tabs/Tabs.d.ts +1 -1
- package/dist/Components/Tabs/Tabs.js +15 -2
- package/dist/Components/Tabs/TabsProps.d.ts +6 -2
- package/dist/Components/Tabs/components/Tab.js +4 -33
- package/dist/Components/Tabs/components/TabLinkList.d.ts +7 -0
- package/dist/Components/Tabs/components/TabLinkList.js +34 -0
- package/dist/Components/Tabs/useTabAppearance.d.ts +17 -0
- package/dist/Components/Tabs/useTabAppearance.js +67 -0
- package/dist/Components/Tag/Tag.js +11 -1
- package/dist/Components/Tag/TagProps.d.ts +4 -0
- package/dist/Components/Tag/tagDot.d.ts +3 -0
- package/dist/Components/Tag/tagDot.js +21 -0
- package/dist/Components/WizardDialog/WizardDialog.d.ts +9 -0
- package/dist/Components/WizardDialog/WizardDialog.js +102 -0
- package/dist/Components/WizardDialog/WizardDialogProps.d.ts +48 -0
- package/dist/Components/WizardDialog/WizardDialogProps.js +2 -0
- package/dist/Components/WizardDialog/useWizardFlow.d.ts +22 -0
- package/dist/Components/WizardDialog/useWizardFlow.js +47 -0
- package/dist/Components/WizardDialog/wizardSteps.d.ts +31 -0
- package/dist/Components/WizardDialog/wizardSteps.js +40 -0
- package/dist/esm/Components/AppSwitcher/AppSwitcher.js +2 -1
- package/dist/esm/Components/AppSwitcher/AppSwitcherProps.js +5 -3
- package/dist/esm/Components/AudioRecorder/AudioRecorder.js +161 -0
- package/dist/esm/Components/AudioRecorder/AudioRecorderProps.js +1 -0
- package/dist/esm/Components/Breadcrumbs/Breadcrumbs.js +35 -12
- package/dist/esm/Components/BulkSelectionBar/BulkSelectionBar.js +38 -0
- package/dist/esm/Components/BulkSelectionBar/BulkSelectionBarProps.js +1 -0
- package/dist/esm/Components/BulkSelectionBar/index.js +1 -0
- package/dist/esm/Components/CalendarGrid/CalendarGrid.js +168 -0
- package/dist/esm/Components/CalendarGrid/CalendarGridProps.js +1 -0
- package/dist/esm/Components/CalendarGrid/calendarMath.js +155 -0
- package/dist/esm/Components/Card/Card.js +12 -2
- package/dist/esm/Components/CircularProgress/CircularProgress.js +37 -0
- package/dist/esm/Components/CircularProgress/CircularProgressProps.js +1 -0
- package/dist/esm/Components/CircularProgress/arc.js +11 -0
- package/dist/esm/Components/Common/fieldStyles.js +2 -1
- package/dist/esm/Components/Drawer/Drawer.js +4 -2
- package/dist/esm/Components/Editor/Editor.js +48 -3
- package/dist/esm/Components/Editor/EditorFieldBar.js +13 -0
- package/dist/esm/Components/Editor/MakeDynamicDialog.js +20 -0
- package/dist/esm/Components/Editor/editorLabels.js +20 -0
- package/dist/esm/Components/Editor/editorTokenStyles.js +25 -0
- package/dist/esm/Components/Editor/editorTokens.js +121 -0
- package/dist/esm/Components/Editor/useEditorBridge.js +138 -0
- package/dist/esm/Components/EmptyState/EmptyState.js +2 -1
- package/dist/esm/Components/FormDrawer/FormDrawer.js +58 -0
- package/dist/esm/Components/FormDrawer/FormDrawerProps.js +1 -0
- package/dist/esm/Components/Kbd/Kbd.js +28 -0
- package/dist/esm/Components/Kbd/KbdProps.js +1 -0
- package/dist/esm/Components/LauncherTrigger/LauncherTrigger.js +41 -0
- package/dist/esm/Components/LauncherTrigger/LauncherTriggerProps.js +1 -0
- package/dist/esm/Components/Modal/Modal.js +4 -2
- package/dist/esm/Components/Modal/warnDroppedSlotChildren.js +38 -0
- package/dist/esm/Components/NavLauncher/NavLauncher.js +413 -0
- package/dist/esm/Components/NavLauncher/NavLauncherProps.js +1 -0
- package/dist/esm/Components/NavLauncher/NewTabLink.js +11 -0
- package/dist/esm/Components/NavLauncher/PinToggle.js +18 -0
- package/dist/esm/Components/NavLauncher/launcherParts.js +187 -0
- package/dist/esm/Components/NavLauncher/match.js +172 -0
- package/dist/esm/Components/NavLauncher/revealStyles.js +15 -0
- package/dist/esm/Components/NavigationBar/NavigationBar.js +3 -3
- package/dist/esm/Components/PageHeader/PageHeader.js +9 -2
- package/dist/esm/Components/PdfViewer/PdfViewer.js +123 -2
- package/dist/esm/Components/ProfilePhotoViewer/ProfilePhotoViewer.js +5 -0
- package/dist/esm/Components/QueryState/QueryStateBoundary.js +10 -4
- package/dist/esm/Components/Search/Search.js +3 -2
- package/dist/esm/Components/SectionRail/SectionRail.js +44 -0
- package/dist/esm/Components/SectionRail/SectionRailProps.js +1 -0
- package/dist/esm/Components/SectionRail/index.js +1 -0
- package/dist/esm/Components/SegmentedControl/SegmentedControl.js +11 -16
- package/dist/esm/Components/SegmentedControl/segmentedInk.js +0 -3
- package/dist/esm/Components/SideBar/SecondaryBar.js +4 -3
- package/dist/esm/Components/SideBar/SideBar.js +31 -10
- package/dist/esm/Components/SideBar/components/MenuItemBox.js +4 -2
- package/dist/esm/Components/SideBar/components/MenuPopoverContent.js +3 -2
- package/dist/esm/Components/SideBar/components/OtherApps.js +2 -1
- package/dist/esm/Components/SideBar/components/PinnedSection.js +92 -0
- package/dist/esm/Components/SideBar/sidebarFocus.js +15 -0
- package/dist/esm/Components/StageProgress/StageProgress.js +2 -2
- package/dist/esm/Components/StageProgress/StepperStage.js +5 -2
- package/dist/esm/Components/StatCard/StatCard.js +6 -2
- package/dist/esm/Components/StatusTag/StatusTag.js +19 -0
- package/dist/esm/Components/StatusTag/StatusTagProps.js +1 -0
- package/dist/esm/Components/Table/Table.js +7 -3
- package/dist/esm/Components/Table/components/TableBody.js +43 -18
- package/dist/esm/Components/Table/components/TableHeader.js +7 -5
- package/dist/esm/Components/Table/components/rowDetail.js +14 -0
- package/dist/esm/Components/Table/hooks/useRowExpansion.js +23 -0
- package/dist/esm/Components/Tabs/Tabs.js +15 -2
- package/dist/esm/Components/Tabs/components/Tab.js +4 -33
- package/dist/esm/Components/Tabs/components/TabLinkList.js +29 -0
- package/dist/esm/Components/Tabs/useTabAppearance.js +63 -0
- package/dist/esm/Components/Tag/Tag.js +12 -2
- package/dist/esm/Components/Tag/tagDot.js +17 -0
- package/dist/esm/Components/WizardDialog/WizardDialog.js +58 -0
- package/dist/esm/Components/WizardDialog/WizardDialogProps.js +1 -0
- package/dist/esm/Components/WizardDialog/useWizardFlow.js +44 -0
- package/dist/esm/Components/WizardDialog/wizardSteps.js +35 -0
- package/dist/esm/index.js +14 -0
- package/dist/index.d.ts +35 -6
- package/dist/index.js +38 -4
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Flex, chakra } from "@chakra-ui/react";
|
|
3
|
+
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
4
|
+
import { resolveSoftTone, toneScale } from "../../Theme/tokens/builders/tone.js";
|
|
5
|
+
import { transitionFor } from "../../Theme/tokens/primitives/motion.js";
|
|
6
|
+
import { reducedMotionSx } from "../../Theme/chakra/motion.js";
|
|
7
|
+
import { arcGeometry, SIZE_PX, THICKNESS_PX } from "./arc.js";
|
|
8
|
+
const Circle = chakra("circle");
|
|
9
|
+
const LABEL_FONT = {
|
|
10
|
+
sm: "0.625rem",
|
|
11
|
+
md: "0.75rem",
|
|
12
|
+
lg: "1rem",
|
|
13
|
+
};
|
|
14
|
+
const scaleFor = (colors, tone) => tone === "info" ? colors.primary : toneScale(colors, tone);
|
|
15
|
+
/** Ring-shaped determinate progress with a centred label — for a linear bar use ProgressBar. */
|
|
16
|
+
const CircularProgress = ({ value, max = 100, size = "md", thickness, tone = "info", label, "aria-label": ariaLabel, "data-testid": testId, }) => {
|
|
17
|
+
const { colors } = useCustomTheme();
|
|
18
|
+
const diameter = SIZE_PX[size];
|
|
19
|
+
const stroke = thickness !== null && thickness !== void 0 ? thickness : THICKNESS_PX[size];
|
|
20
|
+
const { radius, circumference, fraction, clamped, safeMax, dashOffset } = arcGeometry(diameter, stroke, value, max);
|
|
21
|
+
const ink = resolveSoftTone(colors, scaleFor(colors, tone), colors.background[50]).fg;
|
|
22
|
+
const center = diameter / 2;
|
|
23
|
+
const valueText = typeof label === "string" || typeof label === "number" ? String(label) : undefined;
|
|
24
|
+
return (_jsxs(Box, { role: "progressbar", "aria-label": ariaLabel, "aria-valuenow": clamped, "aria-valuemin": 0, "aria-valuemax": safeMax, "aria-valuetext": valueText, "data-testid": testId, position: "relative", display: "inline-flex", flexShrink: 0, boxSize: `${diameter}px`, children: [_jsxs("svg", { width: diameter, height: diameter, viewBox: `0 0 ${diameter} ${diameter}`, "aria-hidden": true, focusable: "false", children: [_jsx(Circle, { cx: center, cy: center, r: radius, fill: "none", sx: { stroke: colors.backgroundColor.subtle, strokeWidth: stroke } }), _jsx(Circle, { cx: center, cy: center, r: radius, fill: "none", "data-testid": testId ? `${testId}-arc` : undefined, sx: {
|
|
25
|
+
stroke: ink,
|
|
26
|
+
strokeWidth: stroke,
|
|
27
|
+
strokeLinecap: "round",
|
|
28
|
+
strokeDasharray: circumference,
|
|
29
|
+
strokeDashoffset: dashOffset,
|
|
30
|
+
strokeOpacity: fraction > 0 ? 1 : 0,
|
|
31
|
+
transform: "rotate(-90deg)",
|
|
32
|
+
transformOrigin: "50% 50%",
|
|
33
|
+
transition: transitionFor(["stroke-dashoffset"]),
|
|
34
|
+
...reducedMotionSx(),
|
|
35
|
+
} })] }), label !== undefined && label !== null && (_jsx(Flex, { position: "absolute", inset: 0, align: "center", justify: "center", fontSize: LABEL_FONT[size], fontWeight: 600, lineHeight: 1, color: colors.header[900], sx: { fontVariantNumeric: "tabular-nums" }, children: label }))] }));
|
|
36
|
+
};
|
|
37
|
+
export default CircularProgress;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const SIZE_PX = { sm: 32, md: 48, lg: 72 };
|
|
2
|
+
export const THICKNESS_PX = { sm: 4, md: 5, lg: 7 };
|
|
3
|
+
export const clampValue = (value, max) => Number.isFinite(value) ? Math.min(Math.max(value, 0), max) : 0;
|
|
4
|
+
export const arcGeometry = (diameter, thickness, value, max) => {
|
|
5
|
+
const safeMax = max > 0 ? max : 100;
|
|
6
|
+
const clamped = clampValue(value, safeMax);
|
|
7
|
+
const radius = Math.max((diameter - thickness) / 2, 0);
|
|
8
|
+
const circumference = 2 * Math.PI * radius;
|
|
9
|
+
const fraction = clamped / safeMax;
|
|
10
|
+
return { radius, circumference, fraction, clamped, safeMax, dashOffset: circumference * (1 - fraction) };
|
|
11
|
+
};
|
|
@@ -5,7 +5,8 @@ import { AA_NON_TEXT, liftToContrast } from "../../Theme/tokens/builders/outline
|
|
|
5
5
|
import { fieldFocusVisible, focusGlowShadow } from "../../Theme/chakra/focusRing.styles.js";
|
|
6
6
|
export const FIELD_RADIUS = "lg";
|
|
7
7
|
export const FIELD_BORDER_WIDTH = "1px";
|
|
8
|
-
|
|
8
|
+
/** No box-shadow: the focus ring must be present the frame focus lands, not fade in. */
|
|
9
|
+
export const FIELD_TRANSITION = transitionFor(["border-color", "background-color"]);
|
|
9
10
|
/** Chakra `h`/`fontSize`/`px` for a field or select of this size. */
|
|
10
11
|
export const controlSizeStyles = (size) => {
|
|
11
12
|
const spec = CONTROL_SIZES[size];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
4
|
+
import { warnDroppedSlotChildren } from "../Modal/warnDroppedSlotChildren.js";
|
|
4
5
|
import { Drawer as ChakraDrawer, DrawerBody as ChakraDrawerBody, DrawerFooter as ChakraDrawerFooter, DrawerHeader as ChakraDrawerHeader, DrawerOverlay, DrawerContent, DrawerCloseButton, } from "@chakra-ui/react";
|
|
5
6
|
export const DrawerHeader = ({ children }) => {
|
|
6
7
|
return _jsx(_Fragment, { children: children });
|
|
@@ -27,11 +28,12 @@ const findSlot = (children, slot) => {
|
|
|
27
28
|
}
|
|
28
29
|
return undefined;
|
|
29
30
|
};
|
|
30
|
-
export default function Drawer({ isOpen, onClose, placement = "right", size = "xl", id, variant, vaiant, initialFocusRef, finalFocusRef, closeOnOverlayClick, closeOnEsc, contentProps, hideCloseButton, children, }) {
|
|
31
|
+
export default function Drawer({ isOpen, onClose, placement = "right", size = "xl", id, variant, vaiant, initialFocusRef, finalFocusRef, closeOnOverlayClick, closeOnEsc, contentProps, hideCloseButton, portalChildren, children, }) {
|
|
31
32
|
var _a, _b;
|
|
32
33
|
const { colors } = useCustomTheme();
|
|
33
34
|
const headerSlot = findSlot(children, DrawerHeader);
|
|
34
35
|
const bodySlot = findSlot(children, DrawerBody);
|
|
35
36
|
const footerSlot = findSlot(children, DrawerFooter);
|
|
36
|
-
|
|
37
|
+
warnDroppedSlotChildren("Drawer", children, [DrawerHeader, DrawerBody, DrawerFooter]);
|
|
38
|
+
return (_jsxs(ChakraDrawer, { isOpen: isOpen, placement: placement, onClose: onClose, size: size, variant: (_a = variant !== null && variant !== void 0 ? variant : vaiant) !== null && _a !== void 0 ? _a : "solid", id: id, initialFocusRef: initialFocusRef, finalFocusRef: finalFocusRef, closeOnOverlayClick: closeOnOverlayClick, closeOnEsc: closeOnEsc, children: [_jsx(DrawerOverlay, {}), _jsxs(DrawerContent, { ...contentProps, children: [!hideCloseButton && _jsx(DrawerCloseButton, {}), headerSlot && (_jsx(ChakraDrawerHeader, { borderBottomWidth: "1px", borderColor: colors.boxborder[200], ...headerSlot.props, children: headerSlot })), _jsx(ChakraDrawerBody, { ...((_b = bodySlot === null || bodySlot === void 0 ? void 0 : bodySlot.props) !== null && _b !== void 0 ? _b : {}), children: bodySlot }), footerSlot && (_jsx(ChakraDrawerFooter, { borderTopWidth: "1px", borderColor: colors.boxborder[200], ...footerSlot.props, children: footerSlot })), portalChildren] })] }));
|
|
37
39
|
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { Suspense, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { Box } from "@chakra-ui/react";
|
|
4
|
+
import FieldMessage from "../Common/FieldMessage.js";
|
|
5
|
+
import ErrorMessage from "../Common/ErrorMessage.js";
|
|
6
|
+
import { fieldLabelStyles } from "../Common/FormLabel.js";
|
|
7
|
+
import { useFieldIds } from "../Common/useFieldIds.js";
|
|
8
|
+
import EditorFieldBar from "./EditorFieldBar.js";
|
|
9
|
+
import MakeDynamicDialog from "./MakeDynamicDialog.js";
|
|
10
|
+
import { DEFAULT_TOKEN_SYNTAX, fieldOptions } from "./editorTokens.js";
|
|
11
|
+
import { chipStyles } from "./editorTokenStyles.js";
|
|
12
|
+
import { resolveEditorLabels } from "./editorLabels.js";
|
|
13
|
+
import { useEditorBridge } from "./useEditorBridge.js";
|
|
4
14
|
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
5
15
|
import { isDarkCanvas } from "../../Theme/tokens/builders/accentText.js";
|
|
6
16
|
import { getJoditThemeVars } from "./joditThemeVars.js";
|
|
@@ -13,8 +23,25 @@ const JoditEditor = React.lazy(async () => {
|
|
|
13
23
|
return { default: ((_a = mod.default) !== null && _a !== void 0 ? _a : mod) };
|
|
14
24
|
});
|
|
15
25
|
/** Lazy-loaded Jodit wrapper — a `config.theme` or `config.popupRoot` you pass overrides this library's own dark-mode/popup fix; omit both keys. */
|
|
16
|
-
const Editor = React.memo(function Editor({ value, key, config, editorRef, className, onChange, onBlur, }) {
|
|
26
|
+
const Editor = React.memo(function Editor({ value, key, config, editorRef, className, onChange, onBlur, label, isRequired, helperText, error, errorMessage, mergeFields, tokenSyntax = DEFAULT_TOKEN_SYNTAX, showMakeDynamic, toolbarButtons, onUnknownTokens, apiRef, onReady, labels, "data-testid": testId, }) {
|
|
17
27
|
const theme = useCustomTheme();
|
|
28
|
+
const text = useMemo(() => resolveEditorLabels(labels), [labels]);
|
|
29
|
+
const { joditValue, attachEditor, api, instance, unknown } = useEditorBridge({
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
onBlur,
|
|
33
|
+
mergeFields,
|
|
34
|
+
syntax: tokenSyntax,
|
|
35
|
+
chipLabel: text.fieldChip,
|
|
36
|
+
apiRef,
|
|
37
|
+
onReady,
|
|
38
|
+
onUnknownTokens,
|
|
39
|
+
});
|
|
40
|
+
const hasFields = mergeFields !== undefined;
|
|
41
|
+
const options = useMemo(() => fieldOptions(mergeFields !== null && mergeFields !== void 0 ? mergeFields : [], tokenSyntax),
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
[JSON.stringify(mergeFields), tokenSyntax.open, tokenSyntax.close]);
|
|
44
|
+
const [dynamicText, setDynamicText] = useState(null);
|
|
18
45
|
// Jodit portals dialogs/toolbar-dropdown popups (search & replace, image/link properties,
|
|
19
46
|
// font-size list, ...) to `document.body` by default (`Dialog.destination` /
|
|
20
47
|
// `getPopupViewRoot`), outside this wrapper's DOM subtree — so the CSS custom properties
|
|
@@ -49,6 +76,24 @@ const Editor = React.memo(function Editor({ value, key, config, editorRef, class
|
|
|
49
76
|
observer.observe(popupRoot, { childList: true, subtree: true });
|
|
50
77
|
return () => observer.disconnect();
|
|
51
78
|
}, [popupRoot]);
|
|
52
|
-
|
|
79
|
+
const unknownActive = hasFields && unknown.length > 0 && !(error && errorMessage);
|
|
80
|
+
const ids = useFieldIds(undefined, { error, errorMessage, helperText });
|
|
81
|
+
const describedBy = unknownActive ? ids.errorId : ids.describedBy;
|
|
82
|
+
const invalid = Boolean(error) || unknownActive;
|
|
83
|
+
const isReadOnly = Boolean(stableConfig === null || stableConfig === void 0 ? void 0 : stableConfig.readonly);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!instance)
|
|
86
|
+
return;
|
|
87
|
+
const el = instance.editor;
|
|
88
|
+
const set = (name, val) => val === undefined ? el.removeAttribute(name) : el.setAttribute(name, val);
|
|
89
|
+
set("role", "textbox");
|
|
90
|
+
set("aria-multiline", "true");
|
|
91
|
+
set("aria-labelledby", label ? ids.labelId : undefined);
|
|
92
|
+
set("aria-describedby", describedBy);
|
|
93
|
+
set("aria-invalid", invalid ? "true" : undefined);
|
|
94
|
+
set("aria-required", isRequired ? "true" : undefined);
|
|
95
|
+
}, [instance, label, ids.labelId, describedBy, invalid, isRequired]);
|
|
96
|
+
const showFieldBar = hasFields || Boolean(toolbarButtons === null || toolbarButtons === void 0 ? void 0 : toolbarButtons.length);
|
|
97
|
+
return (_jsxs(Box, { "data-testid": testId, children: [label && (_jsxs(Box, { as: "label", id: ids.labelId, display: "block", onClick: () => api.focus(), ...fieldLabelStyles(theme.colors), children: [label, isRequired && (_jsx("span", { "aria-hidden": true, style: { color: theme.colors.semanticText.error, marginLeft: "0.125rem" }, children: "*" }))] })), showFieldBar && (_jsx(EditorFieldBar, { options: options, labels: text, api: api, isDisabled: !instance || isReadOnly, showFieldMenu: hasFields, showMakeDynamic: hasFields && (showMakeDynamic !== null && showMakeDynamic !== void 0 ? showMakeDynamic : true), buttons: toolbarButtons !== null && toolbarButtons !== void 0 ? toolbarButtons : [], onMakeDynamic: () => setDynamicText(api.getSelectionText()) })), _jsx(Box, { ref: setPopupRoot, sx: { ...themeVars, ...chipStyles(theme.colors) }, children: _jsx(Suspense, { fallback: null, children: popupRoot && (_jsx(JoditEditor, { config: stableConfig, value: joditValue, ref: editorRef, editorRef: attachEditor, className: className }, key)) }) }), unknownActive ? (_jsx(ErrorMessage, { id: ids.errorId, errorMessage: text.unknownTokens(unknown.join(", ")) })) : (_jsx(FieldMessage, { error: error, errorMessage: errorMessage, helperText: helperText, helperId: ids.helperId, errorId: ids.errorId })), hasFields && (_jsx(MakeDynamicDialog, { selectedText: dynamicText, options: options, labels: text, countFor: api.countOccurrences, onReplace: api.replaceAll, onClose: () => setDynamicText(null) }))] }));
|
|
53
98
|
});
|
|
54
99
|
export default Editor;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Flex, Icon } from "@chakra-ui/react";
|
|
3
|
+
import { WandSparkles } from "lucide-react";
|
|
4
|
+
import Button from "../Button/Button.js";
|
|
5
|
+
import Select from "../Select/Select.js";
|
|
6
|
+
export default function EditorFieldBar({ options, labels, api, isDisabled, showFieldMenu, showMakeDynamic, buttons, onMakeDynamic, }) {
|
|
7
|
+
return (_jsxs(Flex, { role: "toolbar", "aria-label": labels.toolbar, gap: 2, wrap: "wrap", align: "center", mb: 2, children: [showFieldMenu && (_jsx(Box, { width: { base: "100%", sm: "16rem" }, children: _jsx(Select, { native: false, "aria-label": labels.insertField, placeholder: labels.insertField, options: options, value: "", noOptionsMessage: labels.noFields, isDisabled: isDisabled, onChange: (option) => {
|
|
8
|
+
if (!option)
|
|
9
|
+
return;
|
|
10
|
+
api.insertField(String(option.id));
|
|
11
|
+
window.setTimeout(api.focus, 0);
|
|
12
|
+
}, "data-testid": "editor-insert-field" }) })), showMakeDynamic && (_jsx(Button, { variant: "outline", colorScheme: "gray", leftIcon: _jsx(WandSparkles, { size: 16, "aria-hidden": true }), label: labels.makeDynamic, onClick: onMakeDynamic, isDisabled: isDisabled, "data-testid": "editor-make-dynamic" })), buttons.map((button) => (_jsx(Button, { variant: "ghost", colorScheme: "gray", leftIcon: button.icon ? _jsx(Icon, { as: button.icon, boxSize: 4, "aria-hidden": true }) : undefined, label: button.label, onClick: () => button.onClick(api), isDisabled: isDisabled || button.isDisabled, "data-testid": `editor-button-${button.id}` }, button.id)))] }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Box, Flex, Text } from "@chakra-ui/react";
|
|
4
|
+
import Button from "../Button/Button.js";
|
|
5
|
+
import Modal, { ModalBody, ModalFooter } from "../Modal/Modal.js";
|
|
6
|
+
import Select from "../Select/Select.js";
|
|
7
|
+
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
8
|
+
export default function MakeDynamicDialog({ selectedText, options, labels, countFor, onReplace, onClose, }) {
|
|
9
|
+
const { colors } = useCustomTheme();
|
|
10
|
+
const [path, setPath] = useState("");
|
|
11
|
+
const count = selectedText ? countFor(selectedText) : 0;
|
|
12
|
+
const close = () => {
|
|
13
|
+
setPath("");
|
|
14
|
+
onClose();
|
|
15
|
+
};
|
|
16
|
+
return (_jsxs(Modal, { isOpen: selectedText !== null, onClose: close, size: "md", isCentered: true, title: labels.dynamicTitle, children: [_jsx(ModalBody, { children: selectedText ? (_jsxs(Flex, { direction: "column", gap: 4, "data-testid": "editor-dynamic-dialog", children: [_jsxs(Box, { children: [_jsx(Text, { fontSize: "xs", color: colors.textMuted, children: labels.dynamicSelected }), _jsxs(Text, { fontSize: "sm", fontWeight: 500, color: colors.text[800], noOfLines: 3, children: ["\u201C", selectedText, "\u201D"] })] }), _jsx(Select, { native: false, label: labels.dynamicField, placeholder: labels.dynamicFieldPlaceholder, options: options, value: path, onChange: (option) => setPath(option ? String(option.id) : ""), "data-testid": "editor-dynamic-field" }), _jsx(Text, { fontSize: "sm", color: colors.textMuted, "aria-live": "polite", children: labels.dynamicCount(count) })] })) : (_jsx(Text, { fontSize: "sm", color: colors.text[800], "data-testid": "editor-dynamic-empty", children: labels.dynamicNoSelection })) }), _jsx(ModalFooter, { children: _jsxs(Flex, { gap: 2, justify: "flex-end", w: "100%", children: [_jsx(Button, { variant: "ghost", colorScheme: "gray", label: labels.cancel, onClick: close }), selectedText ? (_jsx(Button, { variant: "solid", colorScheme: "primary", label: labels.dynamicReplace, onClick: () => {
|
|
17
|
+
onReplace(selectedText, path);
|
|
18
|
+
close();
|
|
19
|
+
}, isDisabled: !path || count === 0, "data-testid": "editor-dynamic-apply" })) : null] }) })] }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const DEFAULT_EDITOR_LABELS = {
|
|
2
|
+
insertField: "Insert field",
|
|
3
|
+
noFields: "No fields",
|
|
4
|
+
makeDynamic: "Make dynamic",
|
|
5
|
+
dynamicTitle: "Make dynamic",
|
|
6
|
+
dynamicField: "Field",
|
|
7
|
+
dynamicFieldPlaceholder: "Choose a field",
|
|
8
|
+
dynamicCount: (n) => `${n} ${n === 1 ? "occurrence" : "occurrences"} will be replaced`,
|
|
9
|
+
dynamicReplace: "Replace",
|
|
10
|
+
dynamicNoSelection: "Select some text in the editor first.",
|
|
11
|
+
unknownTokens: (list) => `Unknown fields: ${list}`,
|
|
12
|
+
cancel: "Cancel",
|
|
13
|
+
dynamicSelected: "Selected text",
|
|
14
|
+
toolbar: "Template fields",
|
|
15
|
+
fieldChip: (label) => `Field: ${label}`,
|
|
16
|
+
};
|
|
17
|
+
export const resolveEditorLabels = (labels) => ({
|
|
18
|
+
...DEFAULT_EDITOR_LABELS,
|
|
19
|
+
...labels,
|
|
20
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CHIP_CLASS } from "./editorTokens.js";
|
|
2
|
+
export const chipColors = (colors) => ({
|
|
3
|
+
known: { bg: colors.primary.opacity[8], ink: colors.accentText },
|
|
4
|
+
unknown: { bg: "transparent", ink: colors.semanticText.error },
|
|
5
|
+
});
|
|
6
|
+
export const chipStyles = (colors) => {
|
|
7
|
+
const { known, unknown } = chipColors(colors);
|
|
8
|
+
return {
|
|
9
|
+
[`.${CHIP_CLASS}`]: {
|
|
10
|
+
display: "inline-block",
|
|
11
|
+
px: "0.25rem",
|
|
12
|
+
borderRadius: "sm",
|
|
13
|
+
border: "1px solid transparent",
|
|
14
|
+
bg: known.bg,
|
|
15
|
+
color: known.ink,
|
|
16
|
+
cursor: "default",
|
|
17
|
+
},
|
|
18
|
+
[`.${CHIP_CLASS}[data-known="false"]`]: {
|
|
19
|
+
bg: unknown.bg,
|
|
20
|
+
color: unknown.ink,
|
|
21
|
+
border: "1px dashed",
|
|
22
|
+
borderColor: unknown.ink,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const DEFAULT_TOKEN_SYNTAX = { open: "${", close: "}" };
|
|
2
|
+
export const CHIP_CLASS = "pxl-token";
|
|
3
|
+
const PATH_CHARS = "[A-Za-z0-9_.]+";
|
|
4
|
+
const TAG_SPLIT = /(<[^>]*>)/;
|
|
5
|
+
const CHIP_PATTERN = /<span\b([^>]*\bdata-field=(["'])([^"']*)\2[^>]*)>[^<]*<\/span>/g;
|
|
6
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7
|
+
const escapeHtml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
8
|
+
const escapeAttr = (text) => escapeHtml(text).replace(/"/g, """);
|
|
9
|
+
const patternsFor = ({ open, close }) => {
|
|
10
|
+
const o = escapeRegExp(open);
|
|
11
|
+
const c = escapeRegExp(close);
|
|
12
|
+
return {
|
|
13
|
+
match: new RegExp(`${o}(${PATH_CHARS})${c}`, "g"),
|
|
14
|
+
split: new RegExp(`(${o}(?:(?!${c})[\\s\\S])*${c})`),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const fieldToken = (path, syntax = DEFAULT_TOKEN_SYNTAX) => `${syntax.open}${path}${syntax.close}`;
|
|
18
|
+
export function fieldOptions(fields, syntax = DEFAULT_TOKEN_SYNTAX) {
|
|
19
|
+
const groups = [...new Set(fields.map((field) => field.group))];
|
|
20
|
+
return groups.flatMap((group) => fields
|
|
21
|
+
.filter((field) => field.group === group)
|
|
22
|
+
.map((field) => ({
|
|
23
|
+
id: field.path,
|
|
24
|
+
label: field.label,
|
|
25
|
+
group,
|
|
26
|
+
description: fieldToken(field.path, syntax),
|
|
27
|
+
})));
|
|
28
|
+
}
|
|
29
|
+
export function extractTokens(html, syntax = DEFAULT_TOKEN_SYNTAX) {
|
|
30
|
+
const { match } = patternsFor(syntax);
|
|
31
|
+
return [...new Set([...html.matchAll(match)].map((m) => m[1]))];
|
|
32
|
+
}
|
|
33
|
+
export function unknownTokens(html, fields, syntax = DEFAULT_TOKEN_SYNTAX) {
|
|
34
|
+
const known = new Set(fields.map((field) => field.path));
|
|
35
|
+
return extractTokens(html, syntax).filter((path) => !known.has(path));
|
|
36
|
+
}
|
|
37
|
+
function needlePattern(text) {
|
|
38
|
+
const words = text
|
|
39
|
+
.trim()
|
|
40
|
+
.split(/\s+/)
|
|
41
|
+
.map((word) => escapeRegExp(escapeHtml(word)));
|
|
42
|
+
return new RegExp(words.join("(?:\\s| |\\u00a0)+"), "g");
|
|
43
|
+
}
|
|
44
|
+
function mapTextOutsideTokens(html, syntax, mapText) {
|
|
45
|
+
const { split } = patternsFor(syntax);
|
|
46
|
+
return html
|
|
47
|
+
.split(TAG_SPLIT)
|
|
48
|
+
.map((segment) => segment.startsWith("<")
|
|
49
|
+
? segment
|
|
50
|
+
: segment
|
|
51
|
+
.split(split)
|
|
52
|
+
.map((part, i) => (i % 2 === 1 ? part : mapText(part)))
|
|
53
|
+
.join(""))
|
|
54
|
+
.join("");
|
|
55
|
+
}
|
|
56
|
+
/** Replaces every whitespace-insensitive occurrence of `selectedText` outside tags and tokens. */
|
|
57
|
+
export function makeDynamic(html, selectedText, path, syntax = DEFAULT_TOKEN_SYNTAX) {
|
|
58
|
+
if (!selectedText.trim())
|
|
59
|
+
return { html, count: 0 };
|
|
60
|
+
const pattern = needlePattern(selectedText);
|
|
61
|
+
let count = 0;
|
|
62
|
+
const next = mapTextOutsideTokens(html, syntax, (text) => text.replace(pattern, () => {
|
|
63
|
+
count += 1;
|
|
64
|
+
return fieldToken(path, syntax);
|
|
65
|
+
}));
|
|
66
|
+
return { html: next, count };
|
|
67
|
+
}
|
|
68
|
+
export function countOccurrences(html, selectedText, syntax = DEFAULT_TOKEN_SYNTAX) {
|
|
69
|
+
return makeDynamic(html, selectedText, "_", syntax).count;
|
|
70
|
+
}
|
|
71
|
+
export function chipHtml(path, { fields, syntax, chipLabel }) {
|
|
72
|
+
const field = fields.find((f) => f.path === path);
|
|
73
|
+
const text = field ? field.label : fieldToken(path, syntax);
|
|
74
|
+
const title = (field === null || field === void 0 ? void 0 : field.sample) ? ` title="${escapeAttr(field.sample)}"` : "";
|
|
75
|
+
return (`<span class="${CHIP_CLASS}" data-field="${escapeAttr(path)}" data-known="${field ? "true" : "false"}"` +
|
|
76
|
+
` contenteditable="false" role="img" aria-label="${escapeAttr(chipLabel(text))}"${title}>${escapeHtml(text)}</span>`);
|
|
77
|
+
}
|
|
78
|
+
/** Raw `${path}` tokens in text nodes become non-editable chip spans; tags are left alone. */
|
|
79
|
+
export function chipify(html, context) {
|
|
80
|
+
const { match } = patternsFor(context.syntax);
|
|
81
|
+
return html
|
|
82
|
+
.split(TAG_SPLIT)
|
|
83
|
+
.map((segment) => segment.startsWith("<") ? segment : segment.replace(match, (_t, path) => chipHtml(path, context)))
|
|
84
|
+
.join("");
|
|
85
|
+
}
|
|
86
|
+
/** Inverse of `chipify`: every chip span collapses back to its raw token. */
|
|
87
|
+
export function serializeChips(html, syntax = DEFAULT_TOKEN_SYNTAX) {
|
|
88
|
+
return html.replace(CHIP_PATTERN, (_m, _attrs, _q, path) => fieldToken(path, syntax));
|
|
89
|
+
}
|
|
90
|
+
const isChip = (node) => !!node && node.nodeType === 1 && node.hasAttribute("data-field");
|
|
91
|
+
const INVISIBLE = /[\u200b\ufeff]/g;
|
|
92
|
+
const isBlankText = (node) => !node.data.replace(INVISIBLE, "");
|
|
93
|
+
const skipEmptyText = (node, step) => {
|
|
94
|
+
let current = node;
|
|
95
|
+
while (current && current.nodeType === 3 && isBlankText(current))
|
|
96
|
+
current = current[step];
|
|
97
|
+
return current;
|
|
98
|
+
};
|
|
99
|
+
/** The chip a Backspace (backward) or Delete (forward) at a collapsed caret would eat, if any. */
|
|
100
|
+
export function adjacentChip(range, direction) {
|
|
101
|
+
var _a;
|
|
102
|
+
if (!range.collapsed)
|
|
103
|
+
return null;
|
|
104
|
+
const node = range.startContainer;
|
|
105
|
+
const offset = range.startOffset;
|
|
106
|
+
const step = direction === "backward" ? "previousSibling" : "nextSibling";
|
|
107
|
+
let candidate;
|
|
108
|
+
if (node.nodeType === 3) {
|
|
109
|
+
const text = node.data;
|
|
110
|
+
const beyond = direction === "backward" ? text.slice(0, offset) : text.slice(offset);
|
|
111
|
+
const atEdge = !beyond.replace(INVISIBLE, "");
|
|
112
|
+
if (!atEdge)
|
|
113
|
+
return null;
|
|
114
|
+
candidate = node[step];
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
candidate = (_a = node.childNodes[direction === "backward" ? offset - 1 : offset]) !== null && _a !== void 0 ? _a : null;
|
|
118
|
+
}
|
|
119
|
+
const found = skipEmptyText(candidate, step);
|
|
120
|
+
return isChip(found) ? found : null;
|
|
121
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { adjacentChip, chipHtml, chipify, countOccurrences, fieldToken, makeDynamic, serializeChips, unknownTokens, } from "./editorTokens.js";
|
|
3
|
+
export function useEditorBridge({ value, onChange, onBlur, mergeFields, syntax, chipLabel, apiRef, onReady, onUnknownTokens, }) {
|
|
4
|
+
const enabled = mergeFields !== undefined;
|
|
5
|
+
const fieldsKey = JSON.stringify(mergeFields);
|
|
6
|
+
const ctx = useMemo(() => ({ fields: mergeFields !== null && mergeFields !== void 0 ? mergeFields : [], syntax, chipLabel }),
|
|
7
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8
|
+
[fieldsKey, syntax.open, syntax.close, chipLabel]);
|
|
9
|
+
const joditRef = useRef(null);
|
|
10
|
+
const rangeRef = useRef(null);
|
|
11
|
+
const lastRef = useRef(null);
|
|
12
|
+
const appliedFieldsKey = useRef(fieldsKey);
|
|
13
|
+
const live = useRef({ enabled, ctx, onChange, onBlur, onReady, fieldsKey });
|
|
14
|
+
live.current = { enabled, ctx, onChange, onBlur, onReady, fieldsKey };
|
|
15
|
+
const [instance, setInstance] = useState(null);
|
|
16
|
+
const [raw, setRaw] = useState(value !== null && value !== void 0 ? value : "");
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (value !== undefined)
|
|
19
|
+
setRaw(value);
|
|
20
|
+
}, [value]);
|
|
21
|
+
const handleChange = useCallback((html) => {
|
|
22
|
+
const { enabled: on, ctx: c, onChange: emit } = live.current;
|
|
23
|
+
const next = on ? serializeChips(html, c.syntax) : html;
|
|
24
|
+
lastRef.current = { raw: next, jodit: html };
|
|
25
|
+
setRaw(next);
|
|
26
|
+
emit === null || emit === void 0 ? void 0 : emit(next);
|
|
27
|
+
}, []);
|
|
28
|
+
const handleBlur = useCallback((html, event) => {
|
|
29
|
+
const { enabled: on, ctx: c, onBlur: emit } = live.current;
|
|
30
|
+
emit === null || emit === void 0 ? void 0 : emit(on ? serializeChips(html, c.syntax) : html, event);
|
|
31
|
+
}, []);
|
|
32
|
+
const attachEditor = useCallback((jodit) => {
|
|
33
|
+
joditRef.current = jodit;
|
|
34
|
+
rangeRef.current = null;
|
|
35
|
+
appliedFieldsKey.current = live.current.fieldsKey;
|
|
36
|
+
const remember = () => {
|
|
37
|
+
if (jodit.s.isInsideArea)
|
|
38
|
+
rangeRef.current = jodit.s.range.cloneRange();
|
|
39
|
+
};
|
|
40
|
+
jodit.events.on("keyup mouseup touchend", remember);
|
|
41
|
+
jodit.events.on("change", handleChange);
|
|
42
|
+
jodit.events.on("blur", (event) => handleBlur(jodit.value, event));
|
|
43
|
+
const deleteChip = (event) => {
|
|
44
|
+
if (!live.current.enabled)
|
|
45
|
+
return false;
|
|
46
|
+
if (event.key !== "Backspace" && event.key !== "Delete")
|
|
47
|
+
return false;
|
|
48
|
+
const chip = adjacentChip(jodit.s.range, event.key === "Backspace" ? "backward" : "forward");
|
|
49
|
+
if (!chip)
|
|
50
|
+
return false;
|
|
51
|
+
chip.remove();
|
|
52
|
+
jodit.synchronizeValues();
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
56
|
+
jodit.events.on("keydown", ((event) => (deleteChip(event) ? false : undefined)));
|
|
57
|
+
jodit.editor.addEventListener("keydown", (event) => {
|
|
58
|
+
if (deleteChip(event))
|
|
59
|
+
event.stopImmediatePropagation();
|
|
60
|
+
}, true);
|
|
61
|
+
jodit.waitForReady().then(() => {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
if (joditRef.current !== jodit)
|
|
64
|
+
return;
|
|
65
|
+
setInstance(jodit);
|
|
66
|
+
(_b = (_a = live.current).onReady) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
67
|
+
});
|
|
68
|
+
}, [handleChange, handleBlur]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!instance || !enabled || appliedFieldsKey.current === fieldsKey)
|
|
71
|
+
return;
|
|
72
|
+
appliedFieldsKey.current = fieldsKey;
|
|
73
|
+
const html = chipify(serializeChips(instance.value, ctx.syntax), ctx);
|
|
74
|
+
instance.value = html;
|
|
75
|
+
lastRef.current = { raw: serializeChips(html, ctx.syntax), jodit: instance.value };
|
|
76
|
+
}, [instance, enabled, fieldsKey, ctx]);
|
|
77
|
+
const api = useMemo(() => {
|
|
78
|
+
const current = () => joditRef.current;
|
|
79
|
+
const currentRaw = (jodit) => live.current.enabled ? serializeChips(jodit.value, live.current.ctx.syntax) : jodit.value;
|
|
80
|
+
const insertHTML = (html) => {
|
|
81
|
+
const jodit = current();
|
|
82
|
+
if (!jodit)
|
|
83
|
+
return;
|
|
84
|
+
if (rangeRef.current)
|
|
85
|
+
jodit.s.selectRange(rangeRef.current, true);
|
|
86
|
+
jodit.s.insertHTML(html);
|
|
87
|
+
rangeRef.current = jodit.s.range.cloneRange();
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
insertHTML,
|
|
91
|
+
insertField: (path) => {
|
|
92
|
+
const { enabled: on, ctx: c } = live.current;
|
|
93
|
+
insertHTML(on ? chipHtml(path, c) : fieldToken(path, c.syntax));
|
|
94
|
+
},
|
|
95
|
+
getSelectionText: () => (rangeRef.current ? rangeRef.current.toString().trim() : ""),
|
|
96
|
+
replaceAll: (text, path) => {
|
|
97
|
+
const jodit = current();
|
|
98
|
+
if (!jodit)
|
|
99
|
+
return 0;
|
|
100
|
+
const { enabled: on, ctx: c, onChange: emit } = live.current;
|
|
101
|
+
const result = makeDynamic(currentRaw(jodit), text, path, c.syntax);
|
|
102
|
+
if (result.count === 0)
|
|
103
|
+
return 0;
|
|
104
|
+
jodit.value = on ? chipify(result.html, c) : result.html;
|
|
105
|
+
lastRef.current = { raw: result.html, jodit: jodit.value };
|
|
106
|
+
rangeRef.current = null;
|
|
107
|
+
setRaw(result.html);
|
|
108
|
+
emit === null || emit === void 0 ? void 0 : emit(result.html);
|
|
109
|
+
return result.count;
|
|
110
|
+
},
|
|
111
|
+
countOccurrences: (text) => {
|
|
112
|
+
const jodit = current();
|
|
113
|
+
return jodit ? countOccurrences(currentRaw(jodit), text, live.current.ctx.syntax) : 0;
|
|
114
|
+
},
|
|
115
|
+
focus: () => {
|
|
116
|
+
var _a;
|
|
117
|
+
(_a = current()) === null || _a === void 0 ? void 0 : _a.s.focus();
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}, []);
|
|
121
|
+
useImperativeHandle(apiRef, () => api, [api]);
|
|
122
|
+
const unknown = useMemo(() => (enabled ? unknownTokens(raw, ctx.fields, syntax) : []), [enabled, raw, ctx, syntax]);
|
|
123
|
+
const unknownKey = unknown.join("\n");
|
|
124
|
+
const reported = useRef("");
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (!enabled || reported.current === unknownKey)
|
|
127
|
+
return;
|
|
128
|
+
reported.current = unknownKey;
|
|
129
|
+
onUnknownTokens === null || onUnknownTokens === void 0 ? void 0 : onUnknownTokens(unknown);
|
|
130
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
131
|
+
}, [enabled, unknownKey]);
|
|
132
|
+
const last = lastRef.current;
|
|
133
|
+
let joditValue = value;
|
|
134
|
+
if (enabled && value !== undefined) {
|
|
135
|
+
joditValue = last && last.raw === value ? last.jodit : chipify(value, ctx);
|
|
136
|
+
}
|
|
137
|
+
return { joditValue, attachEditor, api, instance, raw, unknown, ctx };
|
|
138
|
+
}
|
|
@@ -24,6 +24,7 @@ const scaleFor = (colors, scheme) => scheme === "primary" || scheme === "seconda
|
|
|
24
24
|
const EmptyState = ({ title = "No data found", titleAs = "h3", description, icon: IconComp = Inbox, image, imageAlt = "", size = "md", colorScheme = "primary", variant = "default", action, animate = false, minH = "15rem", sx, }) => {
|
|
25
25
|
const theme = useCustomTheme();
|
|
26
26
|
const s = sizeMap[size];
|
|
27
|
+
const hasDescription = description !== undefined && description !== null && description !== false && description !== "";
|
|
27
28
|
const palette = scaleFor(theme.colors, colorScheme);
|
|
28
29
|
const tone = resolveSoftTone(theme.colors, palette, theme.colors.background[50]);
|
|
29
30
|
const accentSoft = tone.bg;
|
|
@@ -46,6 +47,6 @@ const EmptyState = ({ title = "No data found", titleAs = "h3", description, icon
|
|
|
46
47
|
bg: accentSoft,
|
|
47
48
|
opacity: HALO_OPACITY,
|
|
48
49
|
zIndex: -1,
|
|
49
|
-
}, sx: reducedMotionSx(), children: _jsx(IconComp, { size: s.icon, strokeWidth: 1.75, "aria-hidden": true }) })), _jsxs(Box, { children: [_jsx(Text, { as: titleAs, fontSize: s.title, fontWeight: 600, color: theme.colors.header[900], mt: 1, children: title }),
|
|
50
|
+
}, sx: reducedMotionSx(), children: _jsx(IconComp, { size: s.icon, strokeWidth: 1.75, "aria-hidden": true }) })), _jsxs(Box, { children: [_jsx(Text, { as: titleAs, fontSize: s.title, fontWeight: 600, color: theme.colors.header[900], mt: 1, children: title }), hasDescription && (_jsx(Text, { as: typeof description === "string" ? undefined : "div", fontSize: s.desc, color: theme.colors.textMuted, mt: 1, maxW: "23.75rem", children: description }))] }), action && (_jsx(Flex, { gap: 3, mt: 2, wrap: "wrap", justify: "center", children: action }))] }));
|
|
50
51
|
};
|
|
51
52
|
export default EmptyState;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { Alert, AlertDescription, AlertIcon, AlertTitle, Box, Divider, Flex, Heading, ListItem, Text, UnorderedList, } from "@chakra-ui/react";
|
|
4
|
+
import Drawer, { DrawerBody, DrawerFooter, DrawerHeader } from "../Drawer/Drawer.js";
|
|
5
|
+
import AlertDialog from "../AlertDialog/AlertDialog.js";
|
|
6
|
+
import Button from "../Button/Button.js";
|
|
7
|
+
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
8
|
+
const DEFAULT_LABELS = {
|
|
9
|
+
fixErrors: "Please fix the following before saving",
|
|
10
|
+
discardTitle: "Discard changes?",
|
|
11
|
+
discardBody: "You have unsaved changes. If you close now, they will be lost.",
|
|
12
|
+
discard: "Discard",
|
|
13
|
+
keepEditing: "Keep editing",
|
|
14
|
+
};
|
|
15
|
+
export default function FormDrawer({ isOpen, onClose, title, description, sections, errors = [], isDirty, onSubmit, isSubmitting = false, submitLabel = "Save", cancelLabel = "Cancel", secondaryAction, size = "md", labels, "data-testid": testId = "form-drawer", }) {
|
|
16
|
+
const { colors } = useCustomTheme();
|
|
17
|
+
const uid = useId();
|
|
18
|
+
const formId = `${uid}-form`;
|
|
19
|
+
const titleId = `${uid}-title`;
|
|
20
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
21
|
+
const [confirmDiscard, setConfirmDiscard] = useState(false);
|
|
22
|
+
const [attempt, setAttempt] = useState(0);
|
|
23
|
+
const keepEditingRef = useRef(null);
|
|
24
|
+
const summaryRef = useRef(null);
|
|
25
|
+
const focusPending = useRef(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isOpen)
|
|
28
|
+
setConfirmDiscard(false);
|
|
29
|
+
}, [isOpen]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
var _a;
|
|
32
|
+
if (!focusPending.current || isSubmitting)
|
|
33
|
+
return;
|
|
34
|
+
focusPending.current = false;
|
|
35
|
+
if (errors.length)
|
|
36
|
+
(_a = summaryRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
37
|
+
}, [attempt, errors, isSubmitting]);
|
|
38
|
+
const requestClose = () => {
|
|
39
|
+
if (isSubmitting)
|
|
40
|
+
return;
|
|
41
|
+
if (isDirty)
|
|
42
|
+
setConfirmDiscard(true);
|
|
43
|
+
else
|
|
44
|
+
onClose();
|
|
45
|
+
};
|
|
46
|
+
const submit = (event) => {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
if (isSubmitting)
|
|
49
|
+
return;
|
|
50
|
+
focusPending.current = true;
|
|
51
|
+
setAttempt((n) => n + 1);
|
|
52
|
+
onSubmit();
|
|
53
|
+
};
|
|
54
|
+
return (_jsxs(Drawer, { isOpen: isOpen, onClose: requestClose, size: size, closeOnEsc: !isSubmitting, closeOnOverlayClick: !isSubmitting, portalChildren: _jsx(AlertDialog, { isOpen: confirmDiscard, onClose: () => setConfirmDiscard(false), leastDestructiveRef: keepEditingRef, isCentered: true, tone: "danger", title: text.discardTitle, content: _jsx(Text, { fontSize: "sm", color: colors.text[800], children: text.discardBody }), cancelButtonText: text.keepEditing, confirmButtonText: text.discard, onConfirm: () => {
|
|
55
|
+
setConfirmDiscard(false);
|
|
56
|
+
onClose();
|
|
57
|
+
} }), children: [_jsxs(DrawerHeader, { children: [_jsx(Heading, { id: titleId, as: "h2", fontSize: "md", fontWeight: 600, color: colors.header[900], children: title }), description ? (_jsx(Text, { mt: 0.5, fontSize: "sm", fontWeight: 400, color: colors.textMuted, children: description })) : null] }), _jsx(DrawerBody, { children: _jsx(Box, { as: "form", id: formId, "aria-labelledby": titleId, onSubmit: submit, noValidate: true, "data-testid": testId, children: _jsxs(Flex, { direction: "column", gap: 5, pt: 2, children: [errors.length ? (_jsxs(Alert, { ref: summaryRef, tabIndex: -1, status: "error", variant: "subtle", borderRadius: "md", alignItems: "flex-start", "data-testid": `${testId}-errors`, children: [_jsx(AlertIcon, {}), _jsxs(Box, { children: [_jsx(AlertTitle, { fontSize: "sm", children: text.fixErrors }), _jsx(AlertDescription, { fontSize: "sm", children: _jsx(UnorderedList, { mt: 1, children: errors.map((message) => (_jsx(ListItem, { children: message }, message))) }) })] })] })) : null, sections.map((section, index) => (_jsxs(Fragment, { children: [index > 0 ? _jsx(Divider, { borderColor: colors.boxborder[200] }) : null, _jsxs(Flex, { as: "section", direction: "column", gap: 4, "aria-label": section.title, children: [section.title ? (_jsxs(Box, { children: [_jsx(Heading, { as: "h3", fontSize: "sm", fontWeight: 600, color: colors.header[900], children: section.title }), section.description ? (_jsx(Text, { mt: 0.5, fontSize: "xs", color: colors.textMuted, children: section.description })) : null] })) : null, section.content] })] }, section.id)))] }) }) }), _jsx(DrawerFooter, { children: _jsxs(Flex, { gap: 2, w: "100%", justify: "flex-end", wrap: "wrap", children: [secondaryAction, _jsx(Button, { variant: "ghost", colorScheme: "gray", onClick: requestClose, isDisabled: isSubmitting, label: cancelLabel }), _jsx(Button, { variant: "solid", colorScheme: "primary", type: "submit", form: formId, isLoading: isSubmitting, loadingText: submitLabel, label: submitLabel, "data-testid": `${testId}-submit` })] }) })] }));
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from "@chakra-ui/react";
|
|
3
|
+
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
4
|
+
import { shortcutKeys } from "../AppSwitcher/AppSwitcherProps.js";
|
|
5
|
+
const HEIGHT = { xs: "1rem", sm: "1.25rem" };
|
|
6
|
+
const SPOKEN = {
|
|
7
|
+
mod: "Command",
|
|
8
|
+
cmd: "Command",
|
|
9
|
+
ctrl: "Control",
|
|
10
|
+
alt: "Option",
|
|
11
|
+
shift: "Shift",
|
|
12
|
+
enter: "Enter",
|
|
13
|
+
esc: "Escape",
|
|
14
|
+
};
|
|
15
|
+
export const detectApple = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
|
16
|
+
/** One keyboard key cap; decorative hint rows should wrap it in `aria-hidden`. */
|
|
17
|
+
const Kbd = ({ children, size = "sm", "data-testid": testId }) => {
|
|
18
|
+
const { colors } = useCustomTheme();
|
|
19
|
+
return (_jsx(Box, { as: "kbd", "data-testid": testId, display: "inline-flex", alignItems: "center", justifyContent: "center", minW: HEIGHT[size], h: HEIGHT[size], px: 1.5, fontFamily: "inherit", fontSize: "0.6875rem", fontWeight: 600, lineHeight: 1, whiteSpace: "nowrap", borderWidth: "1px", borderColor: colors.boxborder[200], borderRadius: "base", bg: colors.backgroundColor.subtle, color: colors.textMuted, children: children }));
|
|
20
|
+
};
|
|
21
|
+
export const KbdShortcut = ({ shortcut, size, isApple, "data-testid": testId }) => {
|
|
22
|
+
const parts = shortcut.split("+").map((p) => p.trim()).filter(Boolean);
|
|
23
|
+
const apple = isApple !== null && isApple !== void 0 ? isApple : detectApple();
|
|
24
|
+
const spoken = parts.map((p) => { var _a; return (_a = SPOKEN[p.toLowerCase()]) !== null && _a !== void 0 ? _a : p.toUpperCase(); }).join(" ");
|
|
25
|
+
const keys = shortcutKeys(shortcut, apple);
|
|
26
|
+
return (_jsx(Box, { as: "span", display: "inline-flex", gap: 1, role: "img", "aria-label": spoken, "data-testid": testId, children: keys.map((key, i) => (_jsx(Kbd, { size: size, children: key }, `${key}-${i}`))) }));
|
|
27
|
+
};
|
|
28
|
+
export default Kbd;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|