nudge-ui 0.2.2 → 0.2.4
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/README.md +164 -46
- package/dist/client.mjs +260 -61
- package/dist/css/value-semantics/colorSemantics.d.ts +4 -0
- package/dist/css/value-semantics/colorSemantics.js +17 -0
- package/dist/hosts/astro/astroRuntimeConfig.js +1 -0
- package/dist/hosts/astro/clientTransport.js +38 -32
- package/dist/hosts/astro/integration.js +5 -1
- package/dist/hosts/astro/markdownIdentity.d.ts +28 -0
- package/dist/hosts/astro/markdownIdentity.js +81 -0
- package/dist/hosts/next/manifest.js +1 -1
- package/dist/hosts/next/sidecar.js +5 -1
- package/dist/hosts/static/manifest.js +1 -1
- package/dist/hosts/static/server.js +3 -0
- package/dist/hosts/vite/vite.d.ts +3 -0
- package/dist/hosts/vite/vite.js +24 -4
- package/dist/inspector/agent/McpConnectionDialog.js +13 -19
- package/dist/inspector/agent/activity.d.ts +18 -0
- package/dist/inspector/agent/activity.js +70 -0
- package/dist/inspector/agent/client.d.ts +2 -0
- package/dist/inspector/agent/client.js +29 -1
- package/dist/inspector/agent/connectionStatus.js +1 -1
- package/dist/inspector/agent/httpTransport.js +9 -2
- package/dist/inspector/agent/protocol.d.ts +6 -3
- package/dist/inspector/agent/protocol.js +1 -1
- package/dist/inspector/agent/verification.d.ts +15 -7
- package/dist/inspector/agent/verification.js +113 -41
- package/dist/inspector/canvas/AgentActivityOverlay.d.ts +13 -0
- package/dist/inspector/canvas/AgentActivityOverlay.js +111 -0
- package/dist/inspector/canvas/CanvasCard.d.ts +9 -2
- package/dist/inspector/canvas/CanvasCard.js +135 -38
- package/dist/inspector/canvas/CanvasElementOverlay.js +166 -16
- package/dist/inspector/canvas/CanvasToolIcons.d.ts +10 -0
- package/dist/inspector/canvas/CanvasToolIcons.js +20 -0
- package/dist/inspector/canvas/CanvasToolbar.js +8 -4
- package/dist/inspector/canvas/CanvasWorkspace.js +270 -122
- package/dist/inspector/canvas/StaleChangeIndicator.js +3 -13
- package/dist/inspector/canvas/agentPresentation.d.ts +8 -8
- package/dist/inspector/canvas/agentPresentation.js +64 -52
- package/dist/inspector/canvas/canvasGestures.d.ts +1 -1
- package/dist/inspector/canvas/canvasGestures.js +1 -1
- package/dist/inspector/canvas/canvasStore.d.ts +46 -82
- package/dist/inspector/canvas/canvasStore.js +251 -284
- package/dist/inspector/canvas/frameContent.d.ts +21 -0
- package/dist/inspector/canvas/frameContent.js +44 -0
- package/dist/inspector/canvas/frameProtocol.d.ts +21 -4
- package/dist/inspector/canvas/frameProtocol.js +3 -3
- package/dist/inspector/canvas/frameScrollbarStyles.d.ts +3 -0
- package/dist/inspector/canvas/frameScrollbarStyles.js +21 -0
- package/dist/inspector/canvas/keyboardShortcuts.d.ts +3 -1
- package/dist/inspector/canvas/keyboardShortcuts.js +4 -4
- package/dist/inspector/canvas/layout.d.ts +52 -0
- package/dist/inspector/canvas/layout.js +106 -0
- package/dist/inspector/canvas/projection.d.ts +15 -5
- package/dist/inspector/canvas/projection.js +69 -13
- package/dist/inspector/canvas/rendererBootstrap.js +32 -4
- package/dist/inspector/canvas/rendererElementSelector.js +47 -6
- package/dist/inspector/canvas/rendererStylesheet.js +2 -2
- package/dist/inspector/canvas/resizeHandleScale.js +1 -1
- package/dist/inspector/canvas/sessionStore.d.ts +11 -26
- package/dist/inspector/canvas/sessionStore.js +43 -183
- package/dist/inspector/canvas/staleChangeDetector.js +9 -3
- package/dist/inspector/canvas/useCanvasLayoutAnimation.d.ts +5 -0
- package/dist/inspector/canvas/useCanvasLayoutAnimation.js +107 -0
- package/dist/inspector/canvas/viewStore.d.ts +38 -0
- package/dist/inspector/canvas/viewStore.js +104 -0
- package/dist/inspector/canvas/wheelPan.d.ts +8 -0
- package/dist/inspector/canvas/wheelPan.js +8 -0
- package/dist/inspector/changes/changesLog.d.ts +9 -6
- package/dist/inspector/changes/changesLog.js +48 -32
- package/dist/inspector/changes/codecs.d.ts +1 -0
- package/dist/inspector/changes/codecs.js +10 -1
- package/dist/inspector/changes/draftChanges.d.ts +58 -0
- package/dist/inspector/changes/draftChanges.js +304 -0
- package/dist/inspector/changes/editModel.d.ts +10 -0
- package/dist/inspector/changes/editModel.js +9 -2
- package/dist/inspector/changes/previewDiagnostics.d.ts +4 -2
- package/dist/inspector/changes/previewDiagnostics.js +11 -25
- package/dist/inspector/changes/types.d.ts +7 -0
- package/dist/inspector/clientManifest.d.ts +1 -1
- package/dist/inspector/comments/CommentsOverlay.d.ts +2 -0
- package/dist/inspector/comments/CommentsOverlay.js +250 -0
- package/dist/inspector/comments/element.d.ts +6 -0
- package/dist/inspector/comments/element.js +54 -0
- package/dist/inspector/comments/store.d.ts +29 -0
- package/dist/inspector/comments/store.js +121 -0
- package/dist/inspector/comments/verification.d.ts +5 -0
- package/dist/inspector/comments/verification.js +52 -0
- package/dist/inspector/componentSemantics/adapterRegistry.d.ts +6 -1
- package/dist/inspector/componentSemantics/adapterRegistry.js +23 -1
- package/dist/inspector/componentSemantics/reactRuntime.d.ts +2 -1
- package/dist/inspector/componentSemantics/reactRuntime.js +38 -0
- package/dist/inspector/componentSemantics/runtimeBridge.d.ts +4 -2
- package/dist/inspector/componentSemantics/runtimeBridge.js +17 -0
- package/dist/inspector/componentSemantics/types.d.ts +11 -0
- package/dist/inspector/drafts/model.d.ts +35 -0
- package/dist/inspector/drafts/model.js +45 -0
- package/dist/inspector/drafts/store.d.ts +28 -0
- package/dist/inspector/drafts/store.js +231 -0
- package/dist/inspector/index.js +20 -27
- package/dist/inspector/inline-text/inlineTextEditor.js +7 -0
- package/dist/inspector/inspection/useBrowserCssInspection.js +15 -1
- package/dist/inspector/iterations/capture.d.ts +2 -0
- package/dist/inspector/iterations/capture.js +174 -0
- package/dist/inspector/iterations/client.d.ts +7 -0
- package/dist/inspector/iterations/client.js +52 -0
- package/dist/inspector/iterations/coordinator.d.ts +15 -0
- package/dist/inspector/iterations/coordinator.js +130 -0
- package/dist/inspector/iterations/prompt.d.ts +3 -0
- package/dist/inspector/iterations/prompt.js +26 -0
- package/dist/inspector/overlay/DomNavigator.js +21 -15
- package/dist/inspector/overlay/interactionStyles.js +3 -1
- package/dist/inspector/overlay/spacingGestures.d.ts +13 -1
- package/dist/inspector/overlay/spacingGestures.js +82 -5
- package/dist/inspector/projection/{workspaceProjection.d.ts → draftProjection.d.ts} +6 -6
- package/dist/inspector/projection/{workspaceProjection.js → draftProjection.js} +4 -4
- package/dist/inspector/projection/renderedInstance.d.ts +17 -3
- package/dist/inspector/projection/renderedInstance.js +62 -11
- package/dist/inspector/projection/structuralProjection.d.ts +2 -1
- package/dist/inspector/projection/structuralProjection.js +21 -17
- package/dist/inspector/projection/textProjection.d.ts +2 -1
- package/dist/inspector/projection/textProjection.js +64 -15
- package/dist/inspector/prompt/PromptSettingsDialog.js +1 -5
- package/dist/inspector/prompt/clipboardHandoff.d.ts +15 -18
- package/dist/inspector/prompt/clipboardHandoff.js +97 -143
- package/dist/inspector/prompt/generatePrompt.d.ts +4 -1
- package/dist/inspector/prompt/generatePrompt.js +22 -17
- package/dist/inspector/runtime/runtimeConfig.d.ts +9 -0
- package/dist/inspector/runtime/runtimeConfig.js +24 -0
- package/dist/inspector/selection/sourceSite.d.ts +12 -0
- package/dist/inspector/selection/sourceSite.js +28 -0
- package/dist/inspector/settings/SettingsDialog.js +21 -8
- package/dist/inspector/shell/AgentStatusButton.d.ts +11 -0
- package/dist/inspector/shell/AgentStatusButton.js +36 -0
- package/dist/inspector/shell/AppShell.js +4 -2
- package/dist/inspector/shell/ChangesLog.js +46 -26
- package/dist/inspector/shell/CopyPromptButton.js +184 -93
- package/dist/inspector/shell/EmptyState.js +9 -8
- package/dist/inspector/shell/InspectorShell.js +13 -21
- package/dist/inspector/shell/PeekOriginalButton.js +24 -23
- package/dist/inspector/shell/originalPreview.js +5 -5
- package/dist/inspector/shell/shortcuts.d.ts +3 -0
- package/dist/inspector/shell/shortcuts.js +11 -0
- package/dist/inspector/sketch/SketchEditor.js +14 -14
- package/dist/inspector/sketch/SketchEntryButton.js +1 -1
- package/dist/inspector/sketch/SketchFrameOverlay.d.ts +3 -1
- package/dist/inspector/sketch/SketchFrameOverlay.js +11 -8
- package/dist/inspector/sketch/SketchLayersPanel.js +13 -5
- package/dist/inspector/sketch/SketchOverlay.js +7 -7
- package/dist/inspector/sketch/SketchWorkspace.js +18 -12
- package/dist/inspector/sketch/interaction.d.ts +1 -0
- package/dist/inspector/sketch/interaction.js +8 -4
- package/dist/inspector/sketch/model.d.ts +5 -0
- package/dist/inspector/sketch/model.js +6 -2
- package/dist/inspector/sketch/raster.d.ts +1 -2
- package/dist/inspector/sketch/raster.js +68 -4
- package/dist/inspector/styleEditors/BackgroundEditor.d.ts +4 -0
- package/dist/inspector/styleEditors/BackgroundEditor.js +195 -0
- package/dist/inspector/styleEditors/BorderEditor.js +49 -78
- package/dist/inspector/styleEditors/BorderRadiusEditor.js +6 -1
- package/dist/inspector/styleEditors/BoxShadowEditor.d.ts +1 -2
- package/dist/inspector/styleEditors/BoxShadowEditor.js +132 -4
- package/dist/inspector/styleEditors/ColorPicker.d.ts +5 -1
- package/dist/inspector/styleEditors/ColorPicker.js +10 -4
- package/dist/inspector/styleEditors/GapField.js +3 -5
- package/dist/inspector/styleEditors/GridChildSection.d.ts +1 -1
- package/dist/inspector/styleEditors/GridChildSection.js +18 -9
- package/dist/inspector/styleEditors/GridPicker.d.ts +1 -1
- package/dist/inspector/styleEditors/GridPicker.js +8 -2
- package/dist/inspector/styleEditors/GridSection.js +1 -1
- package/dist/inspector/styleEditors/GridValueField.js +19 -14
- package/dist/inspector/styleEditors/ImageBackgroundEditor.d.ts +18 -0
- package/dist/inspector/styleEditors/ImageBackgroundEditor.js +118 -0
- package/dist/inspector/styleEditors/LayoutBlockedIndicator.d.ts +2 -2
- package/dist/inspector/styleEditors/LayoutBlockedIndicator.js +3 -3
- package/dist/inspector/styleEditors/LayoutComboField.js +6 -4
- package/dist/inspector/styleEditors/LayoutDropdown.js +6 -3
- package/dist/inspector/styleEditors/LayoutSection.js +32 -11
- package/dist/inspector/styleEditors/SpacingBox.js +7 -5
- package/dist/inspector/styleEditors/Typography.js +11 -3
- package/dist/inspector/styleEditors/backgroundLayers.d.ts +24 -0
- package/dist/inspector/styleEditors/backgroundLayers.js +51 -0
- package/dist/inspector/styleEditors/gradientValue.d.ts +17 -0
- package/dist/inspector/styleEditors/gradientValue.js +114 -0
- package/dist/inspector/styleEditors/inlineAuthored.d.ts +10 -0
- package/dist/inspector/styleEditors/inlineAuthored.js +114 -0
- package/dist/inspector/styleEditors/layoutValue.d.ts +0 -8
- package/dist/inspector/styleEditors/layoutValue.js +0 -42
- package/dist/inspector/styleEditors/nudgeValue.d.ts +2 -2
- package/dist/inspector/styleEditors/nudgeValue.js +36 -8
- package/dist/inspector/tokens/TokenField.d.ts +7 -0
- package/dist/inspector/tokens/TokenField.js +35 -25
- package/dist/inspector/tokens/TokenLabel.js +5 -14
- package/dist/inspector/tokens/editActions.d.ts +1 -1
- package/dist/inspector/tokens/editActions.js +7 -1
- package/dist/inspector/ui/AtRuleContext.js +4 -6
- package/dist/inspector/ui/Button.d.ts +6 -2
- package/dist/inspector/ui/Button.js +4 -3
- package/dist/inspector/ui/ControlSurface.d.ts +2 -2
- package/dist/inspector/ui/ControlSurface.js +4 -3
- package/dist/inspector/ui/InlineStyleWarning.d.ts +11 -0
- package/dist/inspector/ui/InlineStyleWarning.js +13 -0
- package/dist/inspector/ui/InspectorPopover.d.ts +2 -1
- package/dist/inspector/ui/InspectorPopover.js +4 -5
- package/dist/inspector/ui/PopoverListbox.d.ts +2 -1
- package/dist/inspector/ui/PopoverListbox.js +8 -7
- package/dist/inspector/ui/SegmentedControl.d.ts +2 -1
- package/dist/inspector/ui/SegmentedControl.js +2 -2
- package/dist/inspector/ui/Select.d.ts +6 -1
- package/dist/inspector/ui/Select.js +7 -11
- package/dist/inspector/ui/SideValuesField.js +1 -1
- package/dist/inspector/ui/Tooltip.d.ts +26 -0
- package/dist/inspector/ui/Tooltip.js +32 -0
- package/dist/inspector/ui/classNames.d.ts +2 -0
- package/dist/inspector/ui/classNames.js +4 -0
- package/dist/inspector/ui/customCursors.d.ts +23 -0
- package/dist/inspector/ui/customCursors.js +122 -0
- package/dist/inspector/ui/dragCursor.d.ts +0 -2
- package/dist/inspector/ui/dragCursor.js +2 -10
- package/dist/inspector/ui/portalContainer.d.ts +2 -0
- package/dist/inspector/ui/portalContainer.js +6 -0
- package/dist/inspector/ui/styles.js +29 -21
- package/dist/inspector/workspace/commands.d.ts +9 -0
- package/dist/inspector/workspace/commands.js +82 -0
- package/dist/inspector/workspace/controller.d.ts +4 -0
- package/dist/inspector/workspace/controller.js +66 -0
- package/dist/inspector/workspace/handoff.d.ts +42 -0
- package/dist/inspector/workspace/handoff.js +115 -0
- package/dist/inspector/workspace/sentItems.d.ts +19 -0
- package/dist/inspector/workspace/sentItems.js +51 -0
- package/dist/inspector/workspace/timeline.d.ts +30 -0
- package/dist/inspector/workspace/timeline.js +108 -0
- package/dist/internal/agent-protocol.d.ts +19 -2
- package/dist/internal/agent-protocol.js +13 -0
- package/dist/nudge-ui.mjs +558 -311
- package/dist/project/artifacts.d.ts +13 -0
- package/dist/project/artifacts.js +253 -0
- package/dist/transport/artifacts.d.ts +8 -0
- package/dist/transport/artifacts.js +9 -0
- package/dist/transport/editor.js +3 -1
- package/dist/transport/routes.d.ts +2 -0
- package/dist/transport/routes.js +2 -0
- package/package.json +7 -3
- package/dist/inspector/changes/workspaceChanges.d.ts +0 -47
- package/dist/inspector/changes/workspaceChanges.js +0 -265
|
@@ -1,13 +1,66 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { IconBoxMargin, IconLetterX, IconLetterY, IconMinus, IconPlus } from "@tabler/icons-react";
|
|
4
|
+
import { splitTopLevel, splitTopLevelWhitespace } from "../../css/value-semantics/cssSyntax.js";
|
|
5
|
+
import { interpretTokenValue } from "../../css/value-semantics/tokenInterpretation.js";
|
|
6
|
+
import { applyColorOpacity, replaceColorPreservingOpacity, withColorOpacity } from "../../css/value-semantics/colorSemantics.js";
|
|
7
|
+
import { colorValueToHex, TokenField, TokenValueField } from "../tokens/TokenField.js";
|
|
8
|
+
import { setStyle } from "../tokens/editActions.js";
|
|
5
9
|
import { ControlSurface } from "../ui/ControlSurface.js";
|
|
6
10
|
import { getNudgeUiTokenEntries } from "../runtime/runtimeConfig.js";
|
|
7
11
|
import { IconButton } from "../ui/IconButton.js";
|
|
12
|
+
import { Tooltip } from "../ui/Tooltip.js";
|
|
8
13
|
import { getStateStyleValue } from "../shell/stateValue.js";
|
|
9
14
|
import { hasAuthoredProperty } from "./stylePresence.js";
|
|
10
15
|
import { useFieldVisibility } from "./useFieldVisibility.js";
|
|
16
|
+
import { inlineBlockedBy } from "./inlineAuthored.js";
|
|
17
|
+
import { metadataFor } from "./rowLookup.js";
|
|
18
|
+
import { completeCssValue } from "./completeCssValue.js";
|
|
19
|
+
import { valuePolicyFor } from "./valuePolicy.js";
|
|
20
|
+
const LENGTH = /^(?:[+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?(?:[a-z]+)?|(?:calc|min|max|clamp)\(.+\))$/i;
|
|
21
|
+
const DIMENSIONS = [
|
|
22
|
+
{ label: "X Offset", description: "X offset", Icon: IconLetterX },
|
|
23
|
+
{ label: "Y Offset", description: "Y offset", Icon: IconLetterY },
|
|
24
|
+
{ label: "Blur", description: "Blur", Icon: ShadowBlurIcon },
|
|
25
|
+
{ label: "Spread", description: "Spread", Icon: IconBoxMargin },
|
|
26
|
+
];
|
|
27
|
+
function ShadowBlurIcon({ size = 16 }) {
|
|
28
|
+
return (_jsxs("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "currentColor", stroke: "none", "aria-hidden": "true", children: [_jsx("circle", { opacity: "0.5", cx: "7.55555", cy: "3.11111", r: "1.11111" }), _jsx("circle", { cx: "7.55555", cy: "7.55555", r: "1.11111" }), _jsx("circle", { cx: "7.55555", cy: "12", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "7.55555", cy: "16.4444", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "7.55555", cy: "20.8889", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "12", cy: "3.11111", r: "1.11111" }), _jsx("circle", { cx: "12", cy: "7.55555", r: "1.11111" }), _jsx("circle", { cx: "12", cy: "12", r: "1.11111" }), _jsx("circle", { cx: "12", cy: "16.4444", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "12", cy: "20.8889", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "16.4444", cy: "3.11111", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "16.4444", cy: "7.55555", r: "1.11111" }), _jsx("circle", { cx: "16.4444", cy: "12", r: "1.11111" }), _jsx("circle", { cx: "16.4444", cy: "16.4444", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "16.4444", cy: "20.8889", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "20.8889", cy: "3.11111", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "20.8889", cy: "7.55555", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "20.8889", cy: "12", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "20.8889", cy: "16.4444", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "20.8889", cy: "20.8889", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "3.11111", cy: "3.11111", r: "1.11111" }), _jsx("circle", { opacity: "0.5", cx: "3.11111", cy: "7.55555", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "3.11111", cy: "12", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "3.11111", cy: "16.4444", r: "1.11111" }), _jsx("circle", { opacity: "0.3", cx: "3.11111", cy: "20.8889", r: "1.11111" })] }));
|
|
29
|
+
}
|
|
30
|
+
function defaultShadow() {
|
|
31
|
+
return { lengths: ["0", "2px", "3px", "0"], color: "rgb(0 0 0 / 20%)", inset: false };
|
|
32
|
+
}
|
|
33
|
+
function parseShadows(value, entries) {
|
|
34
|
+
if (!value || value === "none")
|
|
35
|
+
return [];
|
|
36
|
+
const result = [];
|
|
37
|
+
for (const layer of splitTopLevel(value, ",")) {
|
|
38
|
+
const parts = splitTopLevelWhitespace(layer.trim());
|
|
39
|
+
const isLength = (part) => LENGTH.test(resolveToken(part, entries));
|
|
40
|
+
const lengths = parts.filter(isLength);
|
|
41
|
+
const colors = parts.filter((part) => part !== "inset" && !isLength(part));
|
|
42
|
+
if (lengths.length < 2 || lengths.length > 4 || colors.length > 1)
|
|
43
|
+
return null;
|
|
44
|
+
result.push({
|
|
45
|
+
lengths: [lengths[0], lengths[1], lengths[2] ?? "0", lengths[3] ?? "0"],
|
|
46
|
+
color: colors[0] ?? "currentColor",
|
|
47
|
+
inset: parts.includes("inset"),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return result.length ? result : null;
|
|
51
|
+
}
|
|
52
|
+
function tokenName(value) {
|
|
53
|
+
return /^var\((--[\w-]+)\)$/.exec(value)?.[1] ?? null;
|
|
54
|
+
}
|
|
55
|
+
function resolveToken(value, entries) {
|
|
56
|
+
const name = tokenName(value);
|
|
57
|
+
return entries.find((entry) => entry.name === name)?.value ?? value;
|
|
58
|
+
}
|
|
59
|
+
function serializeShadows(layers) {
|
|
60
|
+
if (layers.length === 0)
|
|
61
|
+
return "none";
|
|
62
|
+
return layers.map((layer) => `${layer.inset ? "inset " : ""}${layer.lengths.join(" ")} ${layer.color}`).join(", ");
|
|
63
|
+
}
|
|
11
64
|
export function BoxShadowEditor(props) {
|
|
12
65
|
const { element, selection, entries, tokenRows = [], onAfterEdit } = props;
|
|
13
66
|
const el = element.domElement;
|
|
@@ -15,10 +68,85 @@ export function BoxShadowEditor(props) {
|
|
|
15
68
|
const allEntries = entries ?? getNudgeUiTokenEntries();
|
|
16
69
|
const tokenRow = tokenRows.find((row) => row.property === "box-shadow") ?? null;
|
|
17
70
|
const elements = selection?.domElements ?? [el];
|
|
71
|
+
const colorContext = { tokenTable: Object.fromEntries(allEntries.map((entry) => [entry.name, entry])) };
|
|
72
|
+
const computed = getStateStyleValue(el, "box-shadow");
|
|
73
|
+
const source = tokenRow?.authored ?? tokenRow?.declaredValue ?? computed;
|
|
74
|
+
const [draft, setDraft] = useState(null);
|
|
75
|
+
useEffect(() => setDraft(null), [el, source]);
|
|
76
|
+
const activeDraft = draft?.element === el && draft.source === source ? draft : null;
|
|
77
|
+
const value = activeDraft?.value ?? source;
|
|
78
|
+
// A row can reference a color or length token without the entire shadow being token-backed.
|
|
79
|
+
const wholeShadowToken = tokenRow?.tokenName
|
|
80
|
+
&& value.trim().startsWith("var(")
|
|
81
|
+
&& splitTopLevelWhitespace(value.trim()).length === 1;
|
|
82
|
+
const selectedProperty = selection && selection.elements.length > 1 ? selection.getProperty("box-shadow") : null;
|
|
83
|
+
const mixed = selectedProperty?.value.kind === "mixed";
|
|
84
|
+
const layers = mixed ? null : parseShadows(value, allEntries)
|
|
85
|
+
?? parseShadows(tokenRow?.resolvedValue ?? computed, allEntries);
|
|
86
|
+
const blockedBy = inlineBlockedBy(elements, "box-shadow");
|
|
18
87
|
const hasShadow = hasAuthoredProperty(selection, "box-shadow", tokenRow) || elements.some((element) => {
|
|
19
88
|
const value = getStateStyleValue(element, "box-shadow");
|
|
20
89
|
return value !== "" && value !== "none";
|
|
21
90
|
});
|
|
22
91
|
const visibility = useFieldVisibility(elements, "box-shadow", hasShadow);
|
|
23
|
-
|
|
92
|
+
function commitLayers(nextLayers) {
|
|
93
|
+
if (blockedBy)
|
|
94
|
+
return false;
|
|
95
|
+
const nextValue = serializeShadows(nextLayers);
|
|
96
|
+
if (!setStyle(editTarget, "box-shadow", nextValue, selection && selection.elements.length > 1 ? undefined : metadataFor(tokenRow)))
|
|
97
|
+
return false;
|
|
98
|
+
setDraft({ element: el, source, value: nextValue });
|
|
99
|
+
onAfterEdit?.();
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function commitLayer(index, next) {
|
|
103
|
+
if (!layers)
|
|
104
|
+
return;
|
|
105
|
+
commitLayers(layers.map((layer, layerIndex) => layerIndex === index ? next : layer));
|
|
106
|
+
}
|
|
107
|
+
function addShadow() {
|
|
108
|
+
if (!layers)
|
|
109
|
+
return;
|
|
110
|
+
if (commitLayers([...layers, defaultShadow()]))
|
|
111
|
+
visibility.show();
|
|
112
|
+
}
|
|
113
|
+
function removeShadow(index) {
|
|
114
|
+
if (!layers)
|
|
115
|
+
return;
|
|
116
|
+
const remaining = layers.filter((_, layerIndex) => layerIndex !== index);
|
|
117
|
+
if (commitLayers(remaining) && remaining.length === 0)
|
|
118
|
+
visibility.hide();
|
|
119
|
+
}
|
|
120
|
+
function commitColor(index, layer, color) {
|
|
121
|
+
const result = replaceColorPreservingOpacity(layer.color, color, colorContext);
|
|
122
|
+
if (result.ok)
|
|
123
|
+
commitLayer(index, { ...layer, color: result.value });
|
|
124
|
+
}
|
|
125
|
+
return (_jsxs("div", { className: "editor box-shadow-editor", "data-test": "box-shadow-editor", children: [_jsxs("div", { className: "editor__title-row", children: [_jsx("div", { className: "editor__title", children: "Box Shadow" }), _jsx(IconButton, { variant: "quiet", label: "Add Box Shadow", "data-test": "add-shadow", disabled: blockedBy !== null || layers === null, onClick: addShadow, children: _jsx(IconPlus, { size: 16, "aria-hidden": "true" }) })] }), visibility.visible ? _jsxs("div", { className: "box-shadow-editor__layers", children: [!layers || (wholeShadowToken && !activeDraft) ? _jsx(ControlSurface, { children: _jsx(TokenField, { property: "box-shadow", selection: selection, tokenRow: tokenRow, domElement: el, editTarget: editTarget, entries: allEntries, onAfterEdit: onAfterEdit, editMetadata: metadataFor(tokenRow) }) }) : null, layers?.map((layer, index) => {
|
|
126
|
+
const color = interpretTokenValue(layer.color, { table: colorContext.tokenTable });
|
|
127
|
+
const hex = color.tokenName && color.opacity ? colorValueToHex(color.resolvedValue) : null;
|
|
128
|
+
const previewResult = hex && color.opacity ? withColorOpacity(hex, color.opacity.value) : null;
|
|
129
|
+
const preview = previewResult?.ok ? previewResult.value : color.resolvedValue;
|
|
130
|
+
return (_jsxs("div", { className: "box-shadow-editor__layer", role: "group", "aria-label": `Shadow ${index + 1}`, children: [_jsx("div", { className: "box-shadow-editor__dimensions", children: DIMENSIONS.map(({ label, description, Icon }, dimension) => (_jsx(Tooltip, { content: description, disableFocus: true, children: _jsx(ControlSurface, { children: _jsx(TokenValueField, { property: "box-shadow", semanticSlot: "length", nudgeProperty: dimension === 2 ? "padding-top" : "margin-left", domElement: el, committedValue: layer.lengths[dimension].replace(/px$/i, ""), activeTokenName: tokenName(layer.lengths[dimension]), resolvedValue: resolveToken(layer.lengths[dimension], allEntries), entries: allEntries, blockedBy: blockedBy, label: label, inputDataTest: `shadow-${index}-${dimension}`, chipVariant: "small", leading: _jsx(Icon, { size: 16, stroke: 1.8, "aria-hidden": "true" }), formatRawValue: (raw) => completeCssValue(raw, valuePolicyFor("border-width")), onCommitRaw: (input) => {
|
|
131
|
+
const raw = completeCssValue(input, valuePolicyFor("border-width"));
|
|
132
|
+
if (!LENGTH.test(raw) || (dimension === 2 && /^-/.test(raw)))
|
|
133
|
+
return;
|
|
134
|
+
const lengths = [...layer.lengths];
|
|
135
|
+
lengths[dimension] = raw;
|
|
136
|
+
commitLayer(index, { ...layer, lengths });
|
|
137
|
+
}, onSelectToken: (token) => {
|
|
138
|
+
const lengths = [...layer.lengths];
|
|
139
|
+
lengths[dimension] = `var(${token.name})`;
|
|
140
|
+
commitLayer(index, { ...layer, lengths });
|
|
141
|
+
}, onUnlink: (raw) => {
|
|
142
|
+
const lengths = [...layer.lengths];
|
|
143
|
+
lengths[dimension] = raw;
|
|
144
|
+
commitLayer(index, { ...layer, lengths });
|
|
145
|
+
} }) }) }, label))) }), _jsx(IconButton, { variant: "quiet", className: "box-shadow-editor__remove", label: `Remove Shadow ${index + 1}`, "data-test": `remove-shadow-${index}`, disabled: blockedBy !== null, onClick: () => removeShadow(index), children: _jsx(IconMinus, { size: 16, "aria-hidden": "true" }) }), _jsx(Tooltip, { content: "Color and opacity", disableFocus: true, children: _jsx(ControlSurface, { className: "box-shadow-editor__color", children: _jsx(TokenValueField, { property: "box-shadow", semanticSlot: "color", domElement: el, isColor: true, committedValue: tokenName(layer.color) || layer.color === "currentColor" ? layer.color : colorValueToHex(layer.color) ?? layer.color, activeTokenName: color.tokenName, resolvedValue: preview, entries: allEntries, blockedBy: blockedBy, label: "Shadow Color", inputDataTest: `shadow-${index}-color`, opacity: color.opacity, onCommitRaw: (color) => commitColor(index, layer, color), onSelectToken: (token) => commitColor(index, layer, `var(${token.name})`), onUnlink: (color) => commitLayer(index, { ...layer, color }), onCommitOpacity: (opacity) => {
|
|
146
|
+
const result = applyColorOpacity(layer.color, opacity);
|
|
147
|
+
if (!result.ok)
|
|
148
|
+
return false;
|
|
149
|
+
commitLayer(index, { ...layer, color: result.value });
|
|
150
|
+
} }) }) })] }, index));
|
|
151
|
+
})] }) : null] }));
|
|
24
152
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { ReactElement } from "react";
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
2
|
import type { TokenEntry } from "../../css/model/index.js";
|
|
3
3
|
import type { SelectedElement } from "../selection/selectionStore.js";
|
|
4
4
|
import type { ResolvedProperty } from "../../css/model/index.js";
|
|
5
5
|
import type { StyleSelection } from "../selection/styleSelection.js";
|
|
6
6
|
export interface ColorPickerProps {
|
|
7
7
|
element: SelectedElement;
|
|
8
|
+
title?: string;
|
|
9
|
+
toolbar?: ReactNode;
|
|
10
|
+
/** Overrides initial presence for sections that use computed paint. */
|
|
11
|
+
present?: boolean;
|
|
8
12
|
selection?: StyleSelection | null;
|
|
9
13
|
property?: string;
|
|
10
14
|
entries?: TokenEntry[];
|
|
@@ -5,10 +5,13 @@ import { TokenField } from "../tokens/TokenField.js";
|
|
|
5
5
|
import { formatInspectorLabel } from "../ui/labels.js";
|
|
6
6
|
import { IconButton } from "../ui/IconButton.js";
|
|
7
7
|
import { ControlSurface } from "../ui/ControlSurface.js";
|
|
8
|
+
import { Tooltip } from "../ui/Tooltip.js";
|
|
8
9
|
import { setStyle } from "../tokens/editActions.js";
|
|
9
10
|
import { getNudgeUiTokenEntries } from "../runtime/runtimeConfig.js";
|
|
10
11
|
import { hasAuthoredProperty, isZeroCssValue } from "./stylePresence.js";
|
|
11
12
|
import { useFieldVisibility } from "./useFieldVisibility.js";
|
|
13
|
+
import { inlineBlockedBy } from "./inlineAuthored.js";
|
|
14
|
+
import { inlineStyleWarningContent } from "../ui/InlineStyleWarning.js";
|
|
12
15
|
function colorSectionTitle(property) {
|
|
13
16
|
if (property === "background-color")
|
|
14
17
|
return "Background Color";
|
|
@@ -30,19 +33,22 @@ export function isEmptyColorValue(value) {
|
|
|
30
33
|
&& isZeroCssValue(components[3]);
|
|
31
34
|
}
|
|
32
35
|
export function ColorPicker(props) {
|
|
33
|
-
const { element, selection, property = "color", entries, tokenRow, onAfterEdit } = props;
|
|
36
|
+
const { element, selection, property = "color", entries, tokenRow, onAfterEdit, title, toolbar, present } = props;
|
|
34
37
|
const el = element.domElement;
|
|
35
38
|
const selectedElements = selection?.domElements ?? [el];
|
|
36
39
|
const target = selection?.target ?? el;
|
|
40
|
+
const blockedBy = inlineBlockedBy(selectedElements, property);
|
|
37
41
|
const allEntries = entries ?? getNudgeUiTokenEntries();
|
|
38
|
-
const hasColor = hasAuthoredProperty(selection, property, tokenRow)
|
|
39
|
-
|| selectedElements.some((selected) => !isEmptyColorValue(getStateStyleValue(selected, property)));
|
|
42
|
+
const hasColor = present ?? (hasAuthoredProperty(selection, property, tokenRow)
|
|
43
|
+
|| selectedElements.some((selected) => !isEmptyColorValue(getStateStyleValue(selected, property))));
|
|
40
44
|
const visibility = useFieldVisibility(selectedElements, property, hasColor);
|
|
41
45
|
const showTokenField = visibility.visible;
|
|
42
46
|
function handleRemoveColor() {
|
|
47
|
+
if (blockedBy)
|
|
48
|
+
return;
|
|
43
49
|
setStyle(target, property, "transparent");
|
|
44
50
|
visibility.hide();
|
|
45
51
|
onAfterEdit?.();
|
|
46
52
|
}
|
|
47
|
-
return (_jsxs("div", { className: `editor`, "data-test": "color-picker", "data-property": property, children: [_jsxs("div", { className: "editor__title-row", children: [_jsx("div", { className: "editor__title", children: colorSectionTitle(property) }), showTokenField ? (_jsx(IconButton, { variant: "quiet", label: `Remove ${colorSectionTitle(property)}`, "data-test": "remove-color", className: "color__remove", onClick: handleRemoveColor, children: _jsx(IconMinus, { size: "var(--icon-size-small)", stroke: 1.8, "aria-hidden": "true" }) })) : (_jsx(IconButton, { variant: "quiet", label: `Add ${colorSectionTitle(property)}`, "data-test": "add-color", className: "color__add", onClick: visibility.show, children: _jsx(IconPlus, { size: "var(--icon-size-small)", stroke: 1.8, "aria-hidden": "true" }) }))] }), showTokenField && (_jsx("div", { className: "color", children: _jsx(ControlSurface, { children: _jsx(TokenField, { property: property, tokenRow: tokenRow, selection: selection, domElement: el, editTarget: target, entries: allEntries, onAfterEdit: onAfterEdit }) }) }))] }));
|
|
53
|
+
return (_jsxs("div", { className: `editor`, "data-test": "color-picker", "data-property": property, children: [_jsxs("div", { className: "editor__title-row", children: [_jsx("div", { className: "editor__title", children: title ?? colorSectionTitle(property) }), showTokenField ? (_jsx(Tooltip, { content: inlineStyleWarningContent(blockedBy), children: _jsx(IconButton, { variant: "quiet", label: `Remove ${colorSectionTitle(property)}`, "data-test": "remove-color", className: "color__remove", disabled: blockedBy !== null, onClick: handleRemoveColor, children: _jsx(IconMinus, { size: "var(--icon-size-small)", stroke: 1.8, "aria-hidden": "true" }) }) })) : (_jsx(IconButton, { variant: "quiet", label: `Add ${colorSectionTitle(property)}`, "data-test": "add-color", className: "color__add", onClick: visibility.show, children: _jsx(IconPlus, { size: "var(--icon-size-small)", stroke: 1.8, "aria-hidden": "true" }) }))] }), showTokenField && toolbar, showTokenField && (_jsx("div", { className: "color", children: _jsx(ControlSurface, { children: _jsx(TokenField, { property: property, tokenRow: tokenRow, selection: selection, domElement: el, editTarget: target, entries: allEntries, onAfterEdit: onAfterEdit }) }) }))] }));
|
|
48
54
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { TokenField } from "../tokens/TokenField.js";
|
|
3
3
|
import { formatInspectorLabel } from "../ui/labels.js";
|
|
4
|
-
import {
|
|
5
|
-
import { LayoutBlockedIndicator } from "./LayoutBlockedIndicator.js";
|
|
4
|
+
import { meaningfulLayoutValue } from "./layoutValue.js";
|
|
6
5
|
export const GAP_PRESETS = ["0", "0.25rem", "0.5rem", "0.75rem", "1rem", "1.5rem", "2rem", "3rem"];
|
|
7
6
|
/** Renders a gap value with a token chip or the legacy raw-value fallback. */
|
|
8
7
|
export function GapField({ property, domElement: el, editTarget, selection, entries, tokenRows, leading, onAfterEdit, }) {
|
|
9
8
|
const tokenRow = tokenRows.find((row) => row.property === property) ?? null;
|
|
10
|
-
|
|
11
|
-
return (_jsxs("span", { className: `layout-combo${blockedBy ? " layout-combo--blocked" : ""}`, "data-test": "layout-combo", "data-property": property, children: [_jsx(TokenField, { property: property, selection: selection, tokenRow: tokenRow, initialValue: meaningfulLayoutValue(el, property), domElement: el, editTarget: editTarget, entries: entries, suggestions: GAP_PRESETS, leading: leading, inputDataTest: `layout-combo-input-${property}`, label: formatInspectorLabel(property), chipVariant: "small", disabled: blockedBy !== null, onAfterEdit: onAfterEdit }), blockedBy ? _jsx(LayoutBlockedIndicator, { blockedBy: blockedBy }) : null] }));
|
|
9
|
+
return (_jsx("span", { className: "layout-combo", "data-test": "layout-combo", "data-property": property, children: _jsx(TokenField, { property: property, selection: selection, tokenRow: tokenRow, initialValue: meaningfulLayoutValue(el, property), domElement: el, editTarget: editTarget, entries: entries, suggestions: GAP_PRESETS, leading: leading, inputDataTest: `layout-combo-input-${property}`, label: formatInspectorLabel(property), chipVariant: "small", inlineWarningDataTest: "layout-combo-blocked", inlineWarningTooltipDataTest: "layout-combo-blocked-tooltip", onAfterEdit: onAfterEdit }) }));
|
|
12
10
|
}
|
|
@@ -5,11 +5,15 @@ import { ControlSurface } from "../ui/ControlSurface.js";
|
|
|
5
5
|
import { FieldRow } from "../ui/FieldRow.js";
|
|
6
6
|
import { SegmentedControl } from "../ui/SegmentedControl.js";
|
|
7
7
|
import { TextInput } from "../ui/TextInput.js";
|
|
8
|
+
import { InlineStyleWarning } from "../ui/InlineStyleWarning.js";
|
|
8
9
|
import { commitGridAxisPlacement, commitGridChildAlignment, readGridAxisPlacement, readGridChildAlignment, } from "./gridChildModel.js";
|
|
10
|
+
import { targetElements } from "../selection/editTarget.js";
|
|
11
|
+
import { inlineBlockedBy } from "./inlineAuthored.js";
|
|
9
12
|
function readAxis(el, axis) {
|
|
10
13
|
return { placement: readGridAxisPlacement(el, axis) };
|
|
11
14
|
}
|
|
12
|
-
function AxisPlacementRow({ axis, label, state, onStart }) {
|
|
15
|
+
function AxisPlacementRow({ axis, label, state, elements, onStart }) {
|
|
16
|
+
const blockedBy = inlineBlockedBy(elements, `grid-${axis}-start`, `grid-${axis}-end`);
|
|
13
17
|
const [draft, setDraft] = useState(state.placement.start);
|
|
14
18
|
const draftRef = useRef(draft);
|
|
15
19
|
useEffect(() => {
|
|
@@ -21,13 +25,15 @@ function AxisPlacementRow({ axis, label, state, onStart }) {
|
|
|
21
25
|
setDraft(next);
|
|
22
26
|
}
|
|
23
27
|
function commit() {
|
|
28
|
+
if (blockedBy)
|
|
29
|
+
return;
|
|
24
30
|
const next = draftRef.current.trim() || "auto";
|
|
25
31
|
updateDraft(next);
|
|
26
32
|
if (next !== state.placement.start)
|
|
27
33
|
onStart(next);
|
|
28
34
|
}
|
|
29
35
|
const AxisIcon = axis === "column" ? IconColumns2 : IconLayoutRows;
|
|
30
|
-
return (_jsx(FieldRow, { label: label, className: `field-row--stacked layout__grid-child-placement layout__grid-child-placement--${axis}`, "data-test": `layout-grid-child-${axis}`, children: _jsxs(ControlSurface, { children: [_jsx(AxisIcon, { className: "layout__grid-child-placement-icon", size: "var(--icon-size-small)", stroke: "var(--icon-stroke-width)", "aria-hidden": "true" }), _jsx(TextInput, { appearance: "embedded", value: draft, "data-test": `layout-grid-child-${axis}-start`, "aria-label": label, onChange: (event) => updateDraft(event.target.value), onBlur: commit, onKeyDown: (event) => {
|
|
36
|
+
return (_jsx(FieldRow, { label: label, className: `field-row--stacked layout__grid-child-placement layout__grid-child-placement--${axis}`, "data-test": `layout-grid-child-${axis}`, children: _jsxs(ControlSurface, { children: [_jsx(AxisIcon, { className: "layout__grid-child-placement-icon", size: "var(--icon-size-small)", stroke: "var(--icon-stroke-width)", "aria-hidden": "true" }), _jsx(TextInput, { appearance: "embedded", value: draft, "data-test": `layout-grid-child-${axis}-start`, "aria-label": label, disabled: blockedBy !== null, onChange: (event) => updateDraft(event.target.value), onBlur: commit, onKeyDown: (event) => {
|
|
31
37
|
if (event.key === "Escape") {
|
|
32
38
|
event.preventDefault();
|
|
33
39
|
updateDraft(state.placement.start);
|
|
@@ -37,10 +43,12 @@ function AxisPlacementRow({ axis, label, state, onStart }) {
|
|
|
37
43
|
event.preventDefault();
|
|
38
44
|
event.currentTarget.blur();
|
|
39
45
|
}
|
|
40
|
-
} })] }) }));
|
|
46
|
+
} }), _jsx(InlineStyleWarning, { blockedBy: blockedBy })] }) }));
|
|
41
47
|
}
|
|
42
|
-
function AlignmentControl({ axis, value, onChange }) {
|
|
48
|
+
function AlignmentControl({ axis, value, elements, onChange }) {
|
|
43
49
|
const horizontal = axis === "h";
|
|
50
|
+
const property = horizontal ? "justify-self" : "align-self";
|
|
51
|
+
const blockedBy = inlineBlockedBy(elements, property);
|
|
44
52
|
const options = horizontal
|
|
45
53
|
? [
|
|
46
54
|
{ value: "start", label: "Align left", icon: _jsx(IconAlignBoxLeftMiddle, { size: "var(--icon-size-small)", stroke: "var(--icon-stroke-width)", "aria-hidden": "true" }) },
|
|
@@ -54,10 +62,10 @@ function AlignmentControl({ axis, value, onChange }) {
|
|
|
54
62
|
{ value: "end", label: "Align bottom", icon: _jsx(IconAlignBoxCenterBottom, { size: "var(--icon-size-small)", stroke: "var(--icon-stroke-width)", "aria-hidden": "true" }) },
|
|
55
63
|
{ value: "stretch", label: "Stretch vertically", icon: _jsx(IconAlignBoxCenterStretch, { size: "var(--icon-size-small)", stroke: "var(--icon-stroke-width)", "aria-hidden": "true" }) },
|
|
56
64
|
];
|
|
57
|
-
return (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
return (_jsxs(FieldRow, { label: horizontal ? "Horizontal alignment" : "Vertical alignment", hideLabel: true, className: `field-row--stacked layout__grid-child-alignment layout__grid-child-alignment--${axis}`, "data-test": `layout-grid-child-align-${axis}`, children: [_jsx(SegmentedControl, { value: value === "auto" ? null : value, "aria-label": horizontal ? "Horizontal alignment" : "Vertical alignment", "data-test": `layout-grid-child-select-${property}`, className: "layout__grid-child-alignment-control", disabled: blockedBy !== null, options: options.map((option) => ({
|
|
66
|
+
...option,
|
|
67
|
+
testId: `layout-grid-child-align-${axis}-${option.value}`,
|
|
68
|
+
})), onChange: onChange, allowDeselect: true, onDeselect: () => onChange("auto") }), _jsx(InlineStyleWarning, { blockedBy: blockedBy })] }));
|
|
61
69
|
}
|
|
62
70
|
/**
|
|
63
71
|
* Grid child controls expose only placement starts and per-axis alignment.
|
|
@@ -66,6 +74,7 @@ function AlignmentControl({ axis, value, onChange }) {
|
|
|
66
74
|
*/
|
|
67
75
|
export function GridChildSection({ domElement: el, editTarget, revision = 0, onAfterEdit, }) {
|
|
68
76
|
const target = editTarget ?? el;
|
|
77
|
+
const elements = targetElements(target);
|
|
69
78
|
const [column, setColumn] = useState(() => readAxis(el, "column"));
|
|
70
79
|
const [row, setRow] = useState(() => readAxis(el, "row"));
|
|
71
80
|
const [alignH, setAlignH] = useState(() => readGridChildAlignment(el, "h"));
|
|
@@ -87,5 +96,5 @@ export function GridChildSection({ domElement: el, editTarget, revision = 0, onA
|
|
|
87
96
|
if (commitGridChildAlignment(target, axis, value).length > 0)
|
|
88
97
|
handleAfterEdit();
|
|
89
98
|
}
|
|
90
|
-
return (_jsxs("div", { className: "layout__group layout__grid-child", "data-test": "layout-grid-child", children: [_jsx("div", { className: "editor__title", children: "Grid Child" }), _jsxs("div", { className: "layout__grid-child-fields", "data-test": "layout-grid-child-fields", children: [_jsx(AxisPlacementRow, { axis: "column", label: "Column", state: column, onStart: (start) => handleStart("column", start) }), _jsx(AxisPlacementRow, { axis: "row", label: "Row", state: row, onStart: (start) => handleStart("row", start) }), _jsx(AlignmentControl, { axis: "v", value: alignV, onChange: (value) => handleAlignment("v", value) }), _jsx(AlignmentControl, { axis: "h", value: alignH, onChange: (value) => handleAlignment("h", value) })] })] }));
|
|
99
|
+
return (_jsxs("div", { className: "layout__group layout__grid-child", "data-test": "layout-grid-child", children: [_jsx("div", { className: "editor__title", children: "Grid Child" }), _jsxs("div", { className: "layout__grid-child-fields", "data-test": "layout-grid-child-fields", children: [_jsx(AxisPlacementRow, { axis: "column", label: "Column", state: column, elements: elements, onStart: (start) => handleStart("column", start) }), _jsx(AxisPlacementRow, { axis: "row", label: "Row", state: row, elements: elements, onStart: (start) => handleStart("row", start) }), _jsx(AlignmentControl, { axis: "v", value: alignV, elements: elements, onChange: (value) => handleAlignment("v", value) }), _jsx(AlignmentControl, { axis: "h", value: alignH, elements: elements, onChange: (value) => handleAlignment("h", value) })] })] }));
|
|
91
100
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type EditTarget } from "../selection/editTarget.js";
|
|
3
3
|
export declare const GRID_PICKER_MAX_COLUMNS = 12;
|
|
4
4
|
export declare const GRID_PICKER_MAX_ROWS = 8;
|
|
5
5
|
export interface GridPickerProps {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { getLayoutValue } from "./layoutValue.js";
|
|
4
|
+
import { inlineBlockedBy } from "./inlineAuthored.js";
|
|
4
5
|
import { setStyles } from "../tokens/editActions.js";
|
|
6
|
+
import { targetElements } from "../selection/editTarget.js";
|
|
7
|
+
import { InlineStyleWarning } from "../ui/InlineStyleWarning.js";
|
|
5
8
|
export const GRID_PICKER_MAX_COLUMNS = 12;
|
|
6
9
|
export const GRID_PICKER_MAX_ROWS = 8;
|
|
7
10
|
function clampDimension(value, max) {
|
|
@@ -96,6 +99,7 @@ export function GridPicker({ domElement: el, editTarget, revision = 0, onAfterEd
|
|
|
96
99
|
const [popoverPosition, setPopoverPosition] = useState(null);
|
|
97
100
|
const pickerRef = useRef(null);
|
|
98
101
|
const triggerRef = useRef(null);
|
|
102
|
+
const blockedBy = inlineBlockedBy(targetElements(editTarget ?? el), "grid-template-columns", "grid-template-rows");
|
|
99
103
|
useEffect(() => {
|
|
100
104
|
setDimensions(readDimensions(el));
|
|
101
105
|
setHovered(null);
|
|
@@ -143,6 +147,8 @@ export function GridPicker({ domElement: el, editTarget, revision = 0, onAfterEd
|
|
|
143
147
|
};
|
|
144
148
|
}, [open]);
|
|
145
149
|
function choose(columns, rows) {
|
|
150
|
+
if (blockedBy)
|
|
151
|
+
return;
|
|
146
152
|
const next = {
|
|
147
153
|
columns: clampDimension(columns, GRID_PICKER_MAX_COLUMNS),
|
|
148
154
|
rows: clampDimension(rows, GRID_PICKER_MAX_ROWS),
|
|
@@ -165,10 +171,10 @@ export function GridPicker({ domElement: el, editTarget, revision = 0, onAfterEd
|
|
|
165
171
|
setOpen(false);
|
|
166
172
|
setHovered(null);
|
|
167
173
|
}
|
|
168
|
-
}, children: [_jsx("button", { type: "button", className: "grid-picker__trigger", "data-test": "layout-grid-picker-trigger", ref: triggerRef, "aria-label": `Grid ${dimensions.columns} by ${dimensions.rows}`, "aria-expanded": open, "aria-haspopup": "dialog", onClick: () => {
|
|
174
|
+
}, children: [_jsx("button", { type: "button", className: "grid-picker__trigger", "data-test": "layout-grid-picker-trigger", ref: triggerRef, "aria-label": `Grid ${dimensions.columns} by ${dimensions.rows}`, "aria-expanded": open, "aria-haspopup": "dialog", disabled: blockedBy !== null, onClick: () => {
|
|
169
175
|
setPopoverPosition(null);
|
|
170
176
|
setOpen((current) => !current);
|
|
171
|
-
}, children: _jsxs("span", { className: "grid-picker__preview", style: gridStyle(dimensions.columns, dimensions.rows), "aria-hidden": "true", children: [previewCells.map(({ column, row }) => (_jsx("span", { className: "grid-picker__preview-cell" }, `${column}-${row}`))), _jsxs("span", { className: "grid-picker__preview-label", children: [dimensions.columns, " \u00D7 ", dimensions.rows] })] }) }), open ? (_jsxs("div", { className: "grid-picker__popover", "data-test": "layout-grid-picker-popover", role: "dialog", "aria-label": "Choose grid size", style: popoverPosition ? {
|
|
177
|
+
}, children: _jsxs("span", { className: "grid-picker__preview", style: gridStyle(dimensions.columns, dimensions.rows), "aria-hidden": "true", children: [previewCells.map(({ column, row }) => (_jsx("span", { className: "grid-picker__preview-cell" }, `${column}-${row}`))), _jsxs("span", { className: "grid-picker__preview-label", children: [dimensions.columns, " \u00D7 ", dimensions.rows] })] }) }), _jsx(InlineStyleWarning, { blockedBy: blockedBy }), open ? (_jsxs("div", { className: "grid-picker__popover", "data-test": "layout-grid-picker-popover", role: "dialog", "aria-label": "Choose grid size", style: popoverPosition ? {
|
|
172
178
|
left: popoverPosition.left,
|
|
173
179
|
top: popoverPosition.top,
|
|
174
180
|
visibility: "visible",
|
|
@@ -23,5 +23,5 @@ const GRID_CONTENT_ALIGNMENT_OPTIONS = [
|
|
|
23
23
|
const GRID_ITEM_ALIGNMENT_OPTIONS = ["normal", "stretch", "start", "end", "center", "self-start", "self-end"];
|
|
24
24
|
export function GridSection({ domElement: el, editTarget, selection, entries, tokenRows, showContainer, showChild, revision = 0, onAfterEdit, }) {
|
|
25
25
|
const [advancedOpen, setAdvancedOpen] = useState(false);
|
|
26
|
-
return (_jsxs(_Fragment, { children: [showContainer ? _jsx("div", { className: "layout__group layout__grid", "data-test": "layout-grid-container", children: _jsxs("div", { className: "layout__grid-primary", children: [_jsxs("div", { className: "layout__grid-picker-column", children: [_jsxs("div", { className: "layout__grid-heading", children: [_jsx("div", { className: "editor__title", children: "Grid" }), _jsx(InspectorPopover, { "data-test": "layout-grid-settings", side: "bottom", align: "end", triggerElement: (_jsx(IconButton, { variant: "quiet", size: "default", label: "Grid settings",
|
|
26
|
+
return (_jsxs(_Fragment, { children: [showContainer ? _jsx("div", { className: "layout__group layout__grid", "data-test": "layout-grid-container", children: _jsxs("div", { className: "layout__grid-primary", children: [_jsxs("div", { className: "layout__grid-picker-column", children: [_jsxs("div", { className: "layout__grid-heading", children: [_jsx("div", { className: "editor__title", children: "Grid" }), _jsx(InspectorPopover, { "data-test": "layout-grid-settings", side: "bottom", align: "end", triggerTooltip: "Grid settings", triggerElement: (_jsx(IconButton, { variant: "quiet", size: "default", label: "Grid settings", "data-active": advancedOpen, "data-test": "layout-grid-settings", children: _jsx(IconSettings, { size: 16, stroke: 1.8, "aria-hidden": "true" }) })), open: advancedOpen, onOpenChange: setAdvancedOpen, children: _jsxs("div", { className: "layout__grid-advanced", "data-test": "layout-grid-advanced", children: [_jsx("div", { className: "editor__title", children: "Advanced grid CSS" }), _jsxs("div", { className: "layout__grid-fields", children: [_jsx(GridValueField, { property: "grid-template-columns", domElement: el, editTarget: editTarget, selection: selection, revision: revision, onAfterEdit: onAfterEdit }), _jsx(GridValueField, { property: "grid-template-rows", domElement: el, editTarget: editTarget, selection: selection, revision: revision, onAfterEdit: onAfterEdit }), _jsx(LayoutDropdown, { property: "grid-auto-flow", options: GRID_AUTO_FLOW_OPTIONS, domElement: el, editTarget: editTarget, selection: selection, revision: revision, onAfterEdit: onAfterEdit }), _jsx(GridValueField, { property: "grid-auto-columns", domElement: el, editTarget: editTarget, selection: selection, revision: revision, onAfterEdit: onAfterEdit }), _jsx(GridValueField, { property: "grid-auto-rows", domElement: el, editTarget: editTarget, selection: selection, revision: revision, onAfterEdit: onAfterEdit })] }), _jsxs("div", { className: "layout__grid-alignment", "data-test": "layout-grid-alignment", children: [_jsx(LayoutDropdown, { property: "justify-content", options: GRID_CONTENT_ALIGNMENT_OPTIONS, domElement: el, editTarget: editTarget, selection: selection, stacked: true, revision: revision, onAfterEdit: onAfterEdit }), _jsx(LayoutDropdown, { property: "align-content", options: GRID_CONTENT_ALIGNMENT_OPTIONS, domElement: el, editTarget: editTarget, selection: selection, stacked: true, revision: revision, onAfterEdit: onAfterEdit }), _jsx(LayoutDropdown, { property: "justify-items", options: GRID_ITEM_ALIGNMENT_OPTIONS, domElement: el, editTarget: editTarget, selection: selection, stacked: true, revision: revision, onAfterEdit: onAfterEdit }), _jsx(LayoutDropdown, { property: "align-items", options: GRID_ITEM_ALIGNMENT_OPTIONS, domElement: el, editTarget: editTarget, selection: selection, stacked: true, revision: revision, onAfterEdit: onAfterEdit })] })] }) })] }), _jsx(GridPicker, { domElement: el, editTarget: editTarget, revision: revision, onAfterEdit: onAfterEdit })] }), _jsxs("div", { className: "layout__grid-gap", "data-test": "layout-grid-gap", children: [_jsx("div", { className: "layout__grid-heading", "data-test": "layout-grid-gap-heading", "aria-hidden": "true", children: _jsx("div", { className: "editor__title" }) }), _jsxs("div", { className: "layout__grid-gap-fields", children: [_jsx(ControlSurface, { className: "layout__spacing-field", "data-test": "layout-grid-row-gap", children: _jsx(GapField, { property: "row-gap", domElement: el, editTarget: editTarget, selection: selection, entries: entries, tokenRows: tokenRows, leading: (_jsx(IconSpacingVertical, { className: "layout__spacing-icon", size: "var(--icon-size-small)", stroke: 1.8, "aria-hidden": "true", "data-test": "layout-spacing-icon-row-gap" })), onAfterEdit: onAfterEdit }) }), _jsx(ControlSurface, { className: "layout__spacing-field", "data-test": "layout-grid-column-gap", children: _jsx(GapField, { property: "column-gap", domElement: el, editTarget: editTarget, selection: selection, entries: entries, tokenRows: tokenRows, leading: (_jsx(IconSpacingHorizontal, { className: "layout__spacing-icon", size: "var(--icon-size-small)", stroke: 1.8, "aria-hidden": "true", "data-test": "layout-spacing-icon-column-gap" })), onAfterEdit: onAfterEdit }) })] })] })] }) }) : null, showChild ? _jsx(GridChildSection, { domElement: el, editTarget: editTarget, revision: revision, onAfterEdit: onAfterEdit }) : null] }));
|
|
27
27
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { FieldRow } from "../ui/FieldRow.js";
|
|
4
4
|
import { TextInput } from "../ui/TextInput.js";
|
|
5
5
|
import { getLayoutValue } from "./layoutValue.js";
|
|
6
6
|
import { setStyle } from "../tokens/editActions.js";
|
|
7
7
|
import { useFieldAtRules } from "../ui/AtRuleContext.js";
|
|
8
|
+
import { InlineStyleWarning } from "../ui/InlineStyleWarning.js";
|
|
9
|
+
import { inlineBlockedBy } from "./inlineAuthored.js";
|
|
8
10
|
const DEFAULT_GRID_VALUES = {
|
|
9
11
|
"grid-template-columns": "none",
|
|
10
12
|
"grid-template-rows": "none",
|
|
@@ -21,6 +23,7 @@ const DEFAULT_GRID_VALUES = {
|
|
|
21
23
|
export function GridValueField({ property, domElement: el, editTarget, selection, revision = 0, onAfterEdit, }) {
|
|
22
24
|
const atRules = useFieldAtRules(property);
|
|
23
25
|
const mixed = selection?.getProperty(property)?.value.kind === "mixed";
|
|
26
|
+
const blockedBy = inlineBlockedBy(selection?.domElements ?? [el], property);
|
|
24
27
|
const readValue = () => {
|
|
25
28
|
const value = getLayoutValue(el, property);
|
|
26
29
|
return value.authored || value.computed || DEFAULT_GRID_VALUES[property] || "";
|
|
@@ -41,6 +44,8 @@ export function GridValueField({ property, domElement: el, editTarget, selection
|
|
|
41
44
|
setDraft(next);
|
|
42
45
|
}
|
|
43
46
|
function commit() {
|
|
47
|
+
if (blockedBy)
|
|
48
|
+
return;
|
|
44
49
|
const next = draftRef.current.trim();
|
|
45
50
|
if (!next) {
|
|
46
51
|
updateDraft(mixed ? "" : value);
|
|
@@ -54,17 +59,17 @@ export function GridValueField({ property, domElement: el, editTarget, selection
|
|
|
54
59
|
function cancel() {
|
|
55
60
|
updateDraft(mixed ? "" : value);
|
|
56
61
|
}
|
|
57
|
-
return (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
return (_jsxs(FieldRow, { label: property, property: property, atRules: atRules, "data-test": `layout-grid-${property}`, children: [_jsx(TextInput, { value: draft, placeholder: mixed ? "Mixed" : undefined, "data-test": `layout-grid-input-${property}`, "aria-label": property, disabled: blockedBy !== null, onChange: (event) => updateDraft(event.target.value), onBlur: () => {
|
|
63
|
+
commit();
|
|
64
|
+
}, onKeyDown: (event) => {
|
|
65
|
+
if (event.key === "Escape") {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
cancel();
|
|
68
|
+
event.currentTarget.blur();
|
|
69
|
+
}
|
|
70
|
+
else if (event.key === "Enter") {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
event.currentTarget.blur();
|
|
73
|
+
}
|
|
74
|
+
} }), _jsx(InlineStyleWarning, { blockedBy: blockedBy })] }));
|
|
70
75
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { StyleDeclaration } from "../tokens/editActions.js";
|
|
3
|
+
interface ImageBackgroundEditorProps {
|
|
4
|
+
element: HTMLElement;
|
|
5
|
+
elements: readonly HTMLElement[];
|
|
6
|
+
value: string;
|
|
7
|
+
mixed: boolean;
|
|
8
|
+
sizingValues?: {
|
|
9
|
+
size: string;
|
|
10
|
+
repeat: string;
|
|
11
|
+
};
|
|
12
|
+
onUpload(value: string): boolean;
|
|
13
|
+
onCss(value: string): boolean;
|
|
14
|
+
onSizing(declarations: StyleDeclaration[]): boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Preview uploaded images through the existing workspace style edits. */
|
|
17
|
+
export declare function ImageBackgroundEditor({ element, elements, value, mixed, sizingValues, onUpload, onCss, onSizing }: ImageBackgroundEditorProps): ReactElement;
|
|
18
|
+
export {};
|