@activecollab/components 2.0.363 → 2.0.365
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/presentation/shared/index.js +37 -1
- package/dist/cjs/presentation/shared/index.js.map +1 -1
- package/dist/cjs/presentation/shared/settings.js +91 -0
- package/dist/cjs/presentation/shared/settings.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/ImageCard.js +60 -0
- package/dist/cjs/presentation/stackedCard/content/ImageCard.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/LinkCard.js +348 -0
- package/dist/cjs/presentation/stackedCard/content/LinkCard.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/NoteCard.js +92 -0
- package/dist/cjs/presentation/stackedCard/content/NoteCard.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/SwatchCard.js +74 -0
- package/dist/cjs/presentation/stackedCard/content/SwatchCard.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/TaskCard.js +231 -0
- package/dist/cjs/presentation/stackedCard/content/TaskCard.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/index.js +83 -0
- package/dist/cjs/presentation/stackedCard/content/index.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/shared.js +144 -0
- package/dist/cjs/presentation/stackedCard/content/shared.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/unfurl.js +172 -0
- package/dist/cjs/presentation/stackedCard/content/unfurl.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/primitives.js +254 -0
- package/dist/cjs/presentation/stackedCard/primitives.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/resizePolicy.js +183 -0
- package/dist/cjs/presentation/stackedCard/resizePolicy.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/shell.js +165 -0
- package/dist/cjs/presentation/stackedCard/shell.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/storyScaffold.js +72 -0
- package/dist/cjs/presentation/stackedCard/storyScaffold.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/useInlineEdit.js +208 -0
- package/dist/cjs/presentation/stackedCard/useInlineEdit.js.map +1 -0
- package/dist/esm/presentation/shared/index.d.ts +2 -0
- package/dist/esm/presentation/shared/index.d.ts.map +1 -1
- package/dist/esm/presentation/shared/index.js +1 -0
- package/dist/esm/presentation/shared/index.js.map +1 -1
- package/dist/esm/presentation/shared/settings.d.ts +33 -0
- package/dist/esm/presentation/shared/settings.d.ts.map +1 -0
- package/dist/esm/presentation/shared/settings.js +84 -0
- package/dist/esm/presentation/shared/settings.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/ImageCard.d.ts +15 -0
- package/dist/esm/presentation/stackedCard/content/ImageCard.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/ImageCard.js +50 -0
- package/dist/esm/presentation/stackedCard/content/ImageCard.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/LinkCard.d.ts +28 -0
- package/dist/esm/presentation/stackedCard/content/LinkCard.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/LinkCard.js +336 -0
- package/dist/esm/presentation/stackedCard/content/LinkCard.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/NoteCard.d.ts +10 -0
- package/dist/esm/presentation/stackedCard/content/NoteCard.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/NoteCard.js +82 -0
- package/dist/esm/presentation/stackedCard/content/NoteCard.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/SwatchCard.d.ts +14 -0
- package/dist/esm/presentation/stackedCard/content/SwatchCard.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/SwatchCard.js +64 -0
- package/dist/esm/presentation/stackedCard/content/SwatchCard.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/TaskCard.d.ts +29 -0
- package/dist/esm/presentation/stackedCard/content/TaskCard.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/TaskCard.js +218 -0
- package/dist/esm/presentation/stackedCard/content/TaskCard.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/index.d.ts +8 -0
- package/dist/esm/presentation/stackedCard/content/index.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/index.js +8 -0
- package/dist/esm/presentation/stackedCard/content/index.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/shared.d.ts +46 -0
- package/dist/esm/presentation/stackedCard/content/shared.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/shared.js +134 -0
- package/dist/esm/presentation/stackedCard/content/shared.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/unfurl.d.ts +89 -0
- package/dist/esm/presentation/stackedCard/content/unfurl.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/unfurl.js +147 -0
- package/dist/esm/presentation/stackedCard/content/unfurl.js.map +1 -0
- package/dist/esm/presentation/stackedCard/primitives.d.ts +84 -0
- package/dist/esm/presentation/stackedCard/primitives.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/primitives.js +241 -0
- package/dist/esm/presentation/stackedCard/primitives.js.map +1 -0
- package/dist/esm/presentation/stackedCard/resizePolicy.d.ts +97 -0
- package/dist/esm/presentation/stackedCard/resizePolicy.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/resizePolicy.js +173 -0
- package/dist/esm/presentation/stackedCard/resizePolicy.js.map +1 -0
- package/dist/esm/presentation/stackedCard/shell.d.ts +46 -0
- package/dist/esm/presentation/stackedCard/shell.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/shell.js +156 -0
- package/dist/esm/presentation/stackedCard/shell.js.map +1 -0
- package/dist/esm/presentation/stackedCard/storyScaffold.d.ts +28 -0
- package/dist/esm/presentation/stackedCard/storyScaffold.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/storyScaffold.js +66 -0
- package/dist/esm/presentation/stackedCard/storyScaffold.js.map +1 -0
- package/dist/esm/presentation/stackedCard/useInlineEdit.d.ts +68 -0
- package/dist/esm/presentation/stackedCard/useInlineEdit.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/useInlineEdit.js +192 -0
- package/dist/esm/presentation/stackedCard/useInlineEdit.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["selected", "disabled", "pending", "isDragSource", "isDragPreview", "entered", "forceHover", "resizable", "priorityColor", "onResizeDelta", "children"];
|
|
4
|
+
import React, { useCallback, useRef } from "react";
|
|
5
|
+
import styled, { css } from "styled-components";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* StackedCard shell (story-local, presentation-only).
|
|
9
|
+
*
|
|
10
|
+
* The hollow frame every typed content component composes. Extracted from the
|
|
11
|
+
* concept spec story (task 2/8) so the StackedCard concept stories share one
|
|
12
|
+
* shell instead of re-declaring it. The rule the whole subsystem hangs on:
|
|
13
|
+
*
|
|
14
|
+
* THE SHELL STAYS HOLLOW.
|
|
15
|
+
*
|
|
16
|
+
* There is no `contentType` enum here, no per-type prop soup, no `if task …`.
|
|
17
|
+
* The shell owns only VISUAL STATES (selected, disabled, pending, priority,
|
|
18
|
+
* drag source/preview, entered) and the intent surface (`onResizeDelta`, the
|
|
19
|
+
* DOM props it forwards). Content — a task, a link, an image, a swatch, a note
|
|
20
|
+
* — is passed in as `children` and composes the layout primitives. A new
|
|
21
|
+
* content type later is a new wrapper, with ZERO changes in this file.
|
|
22
|
+
*
|
|
23
|
+
* Not exported from the design-system barrel; it lives here so the concept
|
|
24
|
+
* stories share one source of truth.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/* ------------------------------------------------------------------ */
|
|
28
|
+
/* Reference dimensions (from the concept) */
|
|
29
|
+
/* ------------------------------------------------------------------ */
|
|
30
|
+
|
|
31
|
+
export const CARD_WIDTH = 260;
|
|
32
|
+
export const CARD_RADIUS = 8;
|
|
33
|
+
|
|
34
|
+
/* Cover heights are reserved with aspect-ratio (width / height) so a late image
|
|
35
|
+
never reflows the card. Per-type ratios live with the shell so every content
|
|
36
|
+
component reserves the same space its skeleton does. */
|
|
37
|
+
export const COVER_RATIO = "260 / 132";
|
|
38
|
+
export const COVER_RATIO_HERO = "320 / 190";
|
|
39
|
+
export const COVER_RATIO_IMAGE = "260 / 168";
|
|
40
|
+
export const COVER_RATIO_SWATCH = "260 / 104";
|
|
41
|
+
|
|
42
|
+
/* ------------------------------------------------------------------ */
|
|
43
|
+
/* Shell chrome */
|
|
44
|
+
/* ------------------------------------------------------------------ */
|
|
45
|
+
|
|
46
|
+
const hoverStyle = css(["box-shadow:0 4px 12px rgba(0,0,0,0.12);border-color:var(--color-theme-500);"]);
|
|
47
|
+
|
|
48
|
+
/* Controls (cover + entity) share one reveal rule: hidden until the card is
|
|
49
|
+
hovered OR holds focus, so they are reachable by keyboard, not mouse-only.
|
|
50
|
+
The cover also reveals its own controls; `&&` gives the forced-on state the
|
|
51
|
+
specificity to win over that resting rule. */
|
|
52
|
+
const revealControls = css([".sc-control{opacity:0;transition:opacity 120ms ease;}&:hover .sc-control,&:focus-within .sc-control{opacity:1;}"]);
|
|
53
|
+
const StyledCard = styled.div.withConfig({
|
|
54
|
+
displayName: "shell__StyledCard",
|
|
55
|
+
componentId: "sc-nmi1iu-0"
|
|
56
|
+
})(["position:relative;display:flex;flex-direction:column;width:", "px;border-radius:", "px;background-color:var(--page-paper-main);border:1px solid var(--border-primary);box-shadow:0 1px 3px rgba(0,0,0,0.08);overflow:hidden;transition:box-shadow 150ms ease,border-color 150ms ease;", " &:hover{", "}&:focus-visible{outline:none;", " box-shadow:0 0 0 2px var(--sc-selection-ring);}", " ", " ", " ", " ", " ", " ", " ", ""], CARD_WIDTH, CARD_RADIUS, revealControls, hoverStyle, hoverStyle, _ref => {
|
|
57
|
+
let $forceHover = _ref.$forceHover;
|
|
58
|
+
return $forceHover && css(["", " && .sc-control{opacity:1;}"], hoverStyle);
|
|
59
|
+
}, _ref2 => {
|
|
60
|
+
let $priorityColor = _ref2.$priorityColor;
|
|
61
|
+
return $priorityColor && css(["&::before{content:\"\";position:absolute;top:0;bottom:0;left:0;width:4px;background:", ";z-index:2;}"], $priorityColor);
|
|
62
|
+
}, _ref3 => {
|
|
63
|
+
let $selected = _ref3.$selected;
|
|
64
|
+
return $selected && css(["border-color:var(--sc-selection-ring);box-shadow:0 0 0 2px var(--sc-selection-ring);"]);
|
|
65
|
+
}, _ref4 => {
|
|
66
|
+
let $disabled = _ref4.$disabled;
|
|
67
|
+
return $disabled && css(["opacity:0.5;pointer-events:none;"]);
|
|
68
|
+
}, _ref5 => {
|
|
69
|
+
let $pending = _ref5.$pending;
|
|
70
|
+
return $pending && css(["opacity:0.6;pointer-events:none;cursor:progress;"]);
|
|
71
|
+
}, _ref6 => {
|
|
72
|
+
let $isDragSource = _ref6.$isDragSource;
|
|
73
|
+
return $isDragSource && css(["background:transparent;border:1px dashed var(--color-theme-500);box-shadow:none;&:hover{box-shadow:none;border-color:var(--color-theme-500);}> *{visibility:hidden;}"]);
|
|
74
|
+
}, _ref7 => {
|
|
75
|
+
let $isDragPreview = _ref7.$isDragPreview;
|
|
76
|
+
return $isDragPreview && css(["box-shadow:0 12px 28px rgba(0,0,0,0.24);cursor:grabbing;"]);
|
|
77
|
+
}, _ref8 => {
|
|
78
|
+
let $entered = _ref8.$entered;
|
|
79
|
+
return $entered && css(["&&{border-color:var(--sc-selection-ring);box-shadow:inset 0 0 0 2px var(--sc-selection-ring),0 0 0 2px var(--sc-selection-ring);}"]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/* ------------------------------------------------------------------ */
|
|
83
|
+
/* Resize (opt-in): handle on hover, card reports deltas */
|
|
84
|
+
/* ------------------------------------------------------------------ */
|
|
85
|
+
|
|
86
|
+
const StyledResizeHandle = styled.span.withConfig({
|
|
87
|
+
displayName: "shell__StyledResizeHandle",
|
|
88
|
+
componentId: "sc-nmi1iu-1"
|
|
89
|
+
})(["position:absolute;right:2px;bottom:2px;width:14px;height:14px;cursor:nwse-resize;color:var(--color-theme-600);z-index:2;svg{display:block;}"]);
|
|
90
|
+
export const ResizeHandleGlyph = () => /*#__PURE__*/React.createElement("svg", {
|
|
91
|
+
width: "14",
|
|
92
|
+
height: "14",
|
|
93
|
+
viewBox: "0 0 14 14",
|
|
94
|
+
fill: "none",
|
|
95
|
+
"aria-hidden": "true"
|
|
96
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
97
|
+
d: "M12 6v6H6M12 9.5L9.5 12",
|
|
98
|
+
stroke: "currentColor",
|
|
99
|
+
strokeWidth: "1.5",
|
|
100
|
+
strokeLinecap: "round"
|
|
101
|
+
}));
|
|
102
|
+
/* The shell forwards its ref and spreads DOM props (tabIndex, role, aria-*, the
|
|
103
|
+
keyboard/click handlers) so the focus-model and open-vs-select demos can
|
|
104
|
+
drive it — but it owns NO drag, selection, or content logic itself. */
|
|
105
|
+
export const StackedCard = /*#__PURE__*/React.forwardRef((_ref9, ref) => {
|
|
106
|
+
let selected = _ref9.selected,
|
|
107
|
+
disabled = _ref9.disabled,
|
|
108
|
+
pending = _ref9.pending,
|
|
109
|
+
isDragSource = _ref9.isDragSource,
|
|
110
|
+
isDragPreview = _ref9.isDragPreview,
|
|
111
|
+
entered = _ref9.entered,
|
|
112
|
+
forceHover = _ref9.forceHover,
|
|
113
|
+
resizable = _ref9.resizable,
|
|
114
|
+
priorityColor = _ref9.priorityColor,
|
|
115
|
+
onResizeDelta = _ref9.onResizeDelta,
|
|
116
|
+
children = _ref9.children,
|
|
117
|
+
rest = _objectWithoutPropertiesLoose(_ref9, _excluded);
|
|
118
|
+
const dragOrigin = useRef(null);
|
|
119
|
+
const handlePointerDown = useCallback(e => {
|
|
120
|
+
dragOrigin.current = {
|
|
121
|
+
x: e.clientX,
|
|
122
|
+
y: e.clientY
|
|
123
|
+
};
|
|
124
|
+
e.target.setPointerCapture(e.pointerId);
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
}, []);
|
|
127
|
+
const handlePointerMove = useCallback(e => {
|
|
128
|
+
if (!dragOrigin.current || !onResizeDelta) return;
|
|
129
|
+
onResizeDelta(e.clientX - dragOrigin.current.x, e.clientY - dragOrigin.current.y);
|
|
130
|
+
dragOrigin.current = {
|
|
131
|
+
x: e.clientX,
|
|
132
|
+
y: e.clientY
|
|
133
|
+
};
|
|
134
|
+
}, [onResizeDelta]);
|
|
135
|
+
const handlePointerUp = useCallback(() => {
|
|
136
|
+
dragOrigin.current = null;
|
|
137
|
+
}, []);
|
|
138
|
+
return /*#__PURE__*/React.createElement(StyledCard, _extends({
|
|
139
|
+
ref: ref,
|
|
140
|
+
$selected: selected,
|
|
141
|
+
$disabled: disabled,
|
|
142
|
+
$pending: pending,
|
|
143
|
+
$isDragSource: isDragSource,
|
|
144
|
+
$isDragPreview: isDragPreview,
|
|
145
|
+
$entered: entered,
|
|
146
|
+
$forceHover: forceHover,
|
|
147
|
+
$priorityColor: priorityColor
|
|
148
|
+
}, rest), children, resizable ? /*#__PURE__*/React.createElement(StyledResizeHandle, {
|
|
149
|
+
className: "sc-control",
|
|
150
|
+
onPointerDown: handlePointerDown,
|
|
151
|
+
onPointerMove: handlePointerMove,
|
|
152
|
+
onPointerUp: handlePointerUp
|
|
153
|
+
}, /*#__PURE__*/React.createElement(ResizeHandleGlyph, null)) : null);
|
|
154
|
+
});
|
|
155
|
+
StackedCard.displayName = "StackedCard";
|
|
156
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","names":["React","useCallback","useRef","styled","css","CARD_WIDTH","CARD_RADIUS","COVER_RATIO","COVER_RATIO_HERO","COVER_RATIO_IMAGE","COVER_RATIO_SWATCH","hoverStyle","revealControls","StyledCard","div","withConfig","displayName","componentId","_ref","$forceHover","_ref2","$priorityColor","_ref3","$selected","_ref4","$disabled","_ref5","$pending","_ref6","$isDragSource","_ref7","$isDragPreview","_ref8","$entered","StyledResizeHandle","span","ResizeHandleGlyph","createElement","width","height","viewBox","fill","d","stroke","strokeWidth","strokeLinecap","StackedCard","forwardRef","_ref9","ref","selected","disabled","pending","isDragSource","isDragPreview","entered","forceHover","resizable","priorityColor","onResizeDelta","children","rest","_objectWithoutPropertiesLoose","_excluded","dragOrigin","handlePointerDown","e","current","x","clientX","y","clientY","target","setPointerCapture","pointerId","preventDefault","handlePointerMove","handlePointerUp","_extends","className","onPointerDown","onPointerMove","onPointerUp"],"sources":["../../../../src/presentation/stackedCard/shell.tsx"],"sourcesContent":["import React, { ReactElement, ReactNode, useCallback, useRef } from \"react\";\n\nimport styled, { css } from \"styled-components\";\n\n/**\n * StackedCard shell (story-local, presentation-only).\n *\n * The hollow frame every typed content component composes. Extracted from the\n * concept spec story (task 2/8) so the StackedCard concept stories share one\n * shell instead of re-declaring it. The rule the whole subsystem hangs on:\n *\n * THE SHELL STAYS HOLLOW.\n *\n * There is no `contentType` enum here, no per-type prop soup, no `if task …`.\n * The shell owns only VISUAL STATES (selected, disabled, pending, priority,\n * drag source/preview, entered) and the intent surface (`onResizeDelta`, the\n * DOM props it forwards). Content — a task, a link, an image, a swatch, a note\n * — is passed in as `children` and composes the layout primitives. A new\n * content type later is a new wrapper, with ZERO changes in this file.\n *\n * Not exported from the design-system barrel; it lives here so the concept\n * stories share one source of truth.\n */\n\n/* ------------------------------------------------------------------ */\n/* Reference dimensions (from the concept) */\n/* ------------------------------------------------------------------ */\n\nexport const CARD_WIDTH = 260;\nexport const CARD_RADIUS = 8;\n\n/* Cover heights are reserved with aspect-ratio (width / height) so a late image\n never reflows the card. Per-type ratios live with the shell so every content\n component reserves the same space its skeleton does. */\nexport const COVER_RATIO = \"260 / 132\";\nexport const COVER_RATIO_HERO = \"320 / 190\";\nexport const COVER_RATIO_IMAGE = \"260 / 168\";\nexport const COVER_RATIO_SWATCH = \"260 / 104\";\n\n/* ------------------------------------------------------------------ */\n/* Shell chrome */\n/* ------------------------------------------------------------------ */\n\ninterface StyledCardProps {\n $selected?: boolean;\n $disabled?: boolean;\n $pending?: boolean;\n $isDragSource?: boolean;\n $isDragPreview?: boolean;\n $entered?: boolean;\n $forceHover?: boolean;\n $priorityColor?: string;\n}\n\nconst hoverStyle = css`\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);\n border-color: var(--color-theme-500);\n`;\n\n/* Controls (cover + entity) share one reveal rule: hidden until the card is\n hovered OR holds focus, so they are reachable by keyboard, not mouse-only.\n The cover also reveals its own controls; `&&` gives the forced-on state the\n specificity to win over that resting rule. */\nconst revealControls = css`\n .sc-control {\n opacity: 0;\n transition: opacity 120ms ease;\n }\n\n &:hover .sc-control,\n &:focus-within .sc-control {\n opacity: 1;\n }\n`;\n\nconst StyledCard = styled.div<StyledCardProps>`\n position: relative;\n display: flex;\n flex-direction: column;\n width: ${CARD_WIDTH}px;\n border-radius: ${CARD_RADIUS}px;\n background-color: var(--page-paper-main);\n border: 1px solid var(--border-primary);\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);\n overflow: hidden;\n transition: box-shadow 150ms ease, border-color 150ms ease;\n\n ${revealControls}\n\n &:hover {\n ${hoverStyle}\n }\n\n &:focus-visible {\n outline: none;\n ${hoverStyle}\n box-shadow: 0 0 0 2px var(--sc-selection-ring);\n }\n\n ${({ $forceHover }) =>\n $forceHover &&\n css`\n ${hoverStyle}\n && .sc-control {\n opacity: 1;\n }\n `}\n\n ${({ $priorityColor }) =>\n $priorityColor &&\n css`\n &::before {\n content: \"\";\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n width: 4px;\n background: ${$priorityColor};\n z-index: 2;\n }\n `}\n\n ${({ $selected }) =>\n $selected &&\n css`\n border-color: var(--sc-selection-ring);\n box-shadow: 0 0 0 2px var(--sc-selection-ring);\n `}\n\n ${({ $disabled }) =>\n $disabled &&\n css`\n opacity: 0.5;\n pointer-events: none;\n `}\n\n /* Pending / optimistic — the card was just created or moved and the server\n has not confirmed it yet. Dimmed, non-interactive and NOT draggable, but\n distinct from disabled (it is a transient in-flight state, not a policy). */\n ${({ $pending }) =>\n $pending &&\n css`\n opacity: 0.6;\n pointer-events: none;\n cursor: progress;\n `}\n\n /* Drag SOURCE — full-size outline placeholder. Content is hidden but keeps\n its box (visibility, not display) so the card holds identical dimensions\n and the surrounding cards never move. */\n ${({ $isDragSource }) =>\n $isDragSource &&\n css`\n background: transparent;\n border: 1px dashed var(--color-theme-500);\n box-shadow: none;\n\n &:hover {\n box-shadow: none;\n border-color: var(--color-theme-500);\n }\n\n > * {\n visibility: hidden;\n }\n `}\n\n /* Drag PREVIEW — the 1:1 copy the host floats in the drag layer. Elevated\n shadow ONLY: no rotate, no scale, no translate. */\n ${({ $isDragPreview }) =>\n $isDragPreview &&\n css`\n box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);\n cursor: grabbing;\n `}\n\n /* Entered (focus model) — focus is on one of the card's inner controls. */\n ${({ $entered }) =>\n $entered &&\n css`\n && {\n border-color: var(--sc-selection-ring);\n box-shadow: inset 0 0 0 2px var(--sc-selection-ring),\n 0 0 0 2px var(--sc-selection-ring);\n }\n `}\n`;\n\n/* ------------------------------------------------------------------ */\n/* Resize (opt-in): handle on hover, card reports deltas */\n/* ------------------------------------------------------------------ */\n\nconst StyledResizeHandle = styled.span`\n position: absolute;\n right: 2px;\n bottom: 2px;\n width: 14px;\n height: 14px;\n cursor: nwse-resize;\n color: var(--color-theme-600);\n z-index: 2;\n\n svg {\n display: block;\n }\n`;\n\nexport const ResizeHandleGlyph = (): ReactElement => (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 14 14\"\n fill=\"none\"\n aria-hidden=\"true\"\n >\n <path\n d=\"M12 6v6H6M12 9.5L9.5 12\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n />\n </svg>\n);\n\nexport interface StackedCardProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onResize\"> {\n selected?: boolean;\n disabled?: boolean;\n /** Optimistic in-flight state — dimmed, non-interactive, not draggable. */\n pending?: boolean;\n /** Full-size outline placeholder left in the source position while dragging. */\n isDragSource?: boolean;\n /** The 1:1 elevated copy the host floats in the drag layer. */\n isDragPreview?: boolean;\n /** Focus model: the card has been entered and focus is on an inner control. */\n entered?: boolean;\n forceHover?: boolean;\n resizable?: boolean;\n priorityColor?: string;\n onResizeDelta?: (dx: number, dy: number) => void;\n children: ReactNode;\n}\n\n/* The shell forwards its ref and spreads DOM props (tabIndex, role, aria-*, the\n keyboard/click handlers) so the focus-model and open-vs-select demos can\n drive it — but it owns NO drag, selection, or content logic itself. */\nexport const StackedCard = React.forwardRef<HTMLDivElement, StackedCardProps>(\n (\n {\n selected,\n disabled,\n pending,\n isDragSource,\n isDragPreview,\n entered,\n forceHover,\n resizable,\n priorityColor,\n onResizeDelta,\n children,\n ...rest\n },\n ref\n ): ReactElement => {\n const dragOrigin = useRef<{ x: number; y: number } | null>(null);\n\n const handlePointerDown = useCallback((e: React.PointerEvent) => {\n dragOrigin.current = { x: e.clientX, y: e.clientY };\n (e.target as HTMLElement).setPointerCapture(e.pointerId);\n e.preventDefault();\n }, []);\n\n const handlePointerMove = useCallback(\n (e: React.PointerEvent) => {\n if (!dragOrigin.current || !onResizeDelta) return;\n onResizeDelta(\n e.clientX - dragOrigin.current.x,\n e.clientY - dragOrigin.current.y\n );\n dragOrigin.current = { x: e.clientX, y: e.clientY };\n },\n [onResizeDelta]\n );\n\n const handlePointerUp = useCallback(() => {\n dragOrigin.current = null;\n }, []);\n\n return (\n <StyledCard\n ref={ref}\n $selected={selected}\n $disabled={disabled}\n $pending={pending}\n $isDragSource={isDragSource}\n $isDragPreview={isDragPreview}\n $entered={entered}\n $forceHover={forceHover}\n $priorityColor={priorityColor}\n {...rest}\n >\n {children}\n {resizable ? (\n <StyledResizeHandle\n className=\"sc-control\"\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={handlePointerUp}\n >\n <ResizeHandleGlyph />\n </StyledResizeHandle>\n ) : null}\n </StyledCard>\n );\n }\n);\n\nStackedCard.displayName = \"StackedCard\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAA6BC,WAAW,EAAEC,MAAM,QAAQ,OAAO;AAE3E,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,OAAO,MAAMC,UAAU,GAAG,GAAG;AAC7B,OAAO,MAAMC,WAAW,GAAG,CAAC;;AAE5B;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG,WAAW;AACtC,OAAO,MAAMC,gBAAgB,GAAG,WAAW;AAC3C,OAAO,MAAMC,iBAAiB,GAAG,WAAW;AAC5C,OAAO,MAAMC,kBAAkB,GAAG,WAAW;;AAE7C;AACA;AACA;;AAaA,MAAMC,UAAU,GAAGP,GAAG,iFAGrB;;AAED;AACA;AACA;AACA;AACA,MAAMQ,cAAc,GAAGR,GAAG,qHAUzB;AAED,MAAMS,UAAU,GAAGV,MAAM,CAACW,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,waAIlBZ,UAAU,EACFC,WAAW,EAO1BM,cAAc,EAGZD,UAAU,EAKVA,UAAU,EAIZO,IAAA;EAAA,IAAGC,WAAW,GAAAD,IAAA,CAAXC,WAAW;EAAA,OACdA,WAAW,IACXf,GAAG,sCACCO,UAAU,CAIb;AAAA,GAEDS,KAAA;EAAA,IAAGC,cAAc,GAAAD,KAAA,CAAdC,cAAc;EAAA,OACjBA,cAAc,IACdjB,GAAG,2GAQeiB,cAAc,CAG/B;AAAA,GAEDC,KAAA;EAAA,IAAGC,SAAS,GAAAD,KAAA,CAATC,SAAS;EAAA,OACZA,SAAS,IACTnB,GAAG,0FAGF;AAAA,GAEDoB,KAAA;EAAA,IAAGC,SAAS,GAAAD,K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nE,KAAA,CAAAqC,aAAA,CAACxB,UAAU,EAAAiE,QAAA;IACT7B,GAAG,EAAEA,GAAI;IACT1B,SAAS,EAAE2B,QAAS;IACpBzB,SAAS,EAAE0B,QAAS;IACpBxB,QAAQ,EAAEyB,OAAQ;IAClBvB,aAAa,EAAEwB,YAAa;IAC5BtB,cAAc,EAAEuB,aAAc;IAC9BrB,QAAQ,EAAEsB,OAAQ;IAClBpC,WAAW,EAAEqC,UAAW;IACxBnC,cAAc,EAAEqC;EAAc,GAC1BG,IAAI,GAEPD,QAAQ,EACRH,SAAS,gBACRzD,KAAA,CAAAqC,aAAA,CAACH,kBAAkB;IACjB6C,SAAS,EAAC,YAAY;IACtBC,aAAa,EAAEf,iBAAkB;IACjCgB,aAAa,EAAEL,iBAAkB;IACjCM,WAAW,EAAEL;EAAgB,gBAE7B7E,KAAA,CAAAqC,aAAA,CAACD,iBAAiB,MAAE,CACF,CAAC,GACnB,IACM,CAAC;AAEjB,CACF,CAAC;AAEDU,WAAW,CAAC9B,WAAW,GAAG,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Shared spec-sheet scaffolding for the StackedCard concept stories (Sheet,
|
|
4
|
+
* Section, Labeled, Grid, Column) plus the DS token candidates the subsystem
|
|
5
|
+
* needs. Presentation-only; keeps the three StackedCard stories laying out the
|
|
6
|
+
* same way instead of each re-declaring the sheet chrome.
|
|
7
|
+
*
|
|
8
|
+
* The `--sc-*` variables are declared here as design-system PROPOSALS (a
|
|
9
|
+
* selection ring + a dark scrim family). The shell and primitives reference
|
|
10
|
+
* these only, so no rgba/hex is baked into a reusable style.
|
|
11
|
+
*/
|
|
12
|
+
export declare const StyledSheet: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
13
|
+
export declare const StyledGrid: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
14
|
+
export declare const StyledColumn: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
15
|
+
export declare const Labeled: ({ label, children, }: {
|
|
16
|
+
label: ReactNode;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}) => ReactElement;
|
|
19
|
+
export declare const Section: ({ caption, note, children, }: {
|
|
20
|
+
caption: string;
|
|
21
|
+
note?: ReactNode;
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}) => ReactElement;
|
|
24
|
+
export declare const SheetHeading: ({ title, children, }: {
|
|
25
|
+
title: string;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}) => ReactElement;
|
|
28
|
+
//# sourceMappingURL=storyScaffold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyScaffold.d.ts","sourceRoot":"","sources":["../../../../src/presentation/stackedCard/storyScaffold.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvD;;;;;;;;;GASG;AAEH,eAAO,MAAM,WAAW,oEAoBvB,CAAC;AAmBF,eAAO,MAAM,UAAU,oEAKtB,CAAC;AAEF,eAAO,MAAM,YAAY,oEAIxB,CAAC;AAcF,eAAO,MAAM,OAAO,GAAI,sBAGrB;IACD,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;CACrB,KAAG,YAOH,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,8BAIrB;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;CACrB,KAAG,YAYH,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,sBAG1B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB,KAAG,YAOH,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { Caption1, Title2 } from "../../components/Typography";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared spec-sheet scaffolding for the StackedCard concept stories (Sheet,
|
|
7
|
+
* Section, Labeled, Grid, Column) plus the DS token candidates the subsystem
|
|
8
|
+
* needs. Presentation-only; keeps the three StackedCard stories laying out the
|
|
9
|
+
* same way instead of each re-declaring the sheet chrome.
|
|
10
|
+
*
|
|
11
|
+
* The `--sc-*` variables are declared here as design-system PROPOSALS (a
|
|
12
|
+
* selection ring + a dark scrim family). The shell and primitives reference
|
|
13
|
+
* these only, so no rgba/hex is baked into a reusable style.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const StyledSheet = styled.div.withConfig({
|
|
17
|
+
displayName: "storyScaffold__StyledSheet",
|
|
18
|
+
componentId: "sc-7oxew-0"
|
|
19
|
+
})(["--sc-selection-ring:var(--color-primary-500,#2f6bff);--sc-scrim:rgba(0,0,0,0.55);--sc-scrim-strong:rgba(0,0,0,0.72);--sc-scrim-fg:#ffffff;--sc-completed-tint:rgba(72,201,176,0.16);min-height:100vh;padding:32px 40px 64px;background:var(--page-paper-dimmed,var(--color-theme-200));.sheet-title{margin-bottom:8px;}.sheet-lede{display:block;margin-bottom:24px;max-width:760px;}"]);
|
|
20
|
+
const StyledSection = styled.section.withConfig({
|
|
21
|
+
displayName: "storyScaffold__StyledSection",
|
|
22
|
+
componentId: "sc-7oxew-1"
|
|
23
|
+
})(["margin-top:40px;> .section-caption{display:block;margin-bottom:4px;text-transform:uppercase;letter-spacing:0.06em;}> .section-note{display:block;margin-bottom:16px;max-width:720px;}"]);
|
|
24
|
+
export const StyledGrid = styled.div.withConfig({
|
|
25
|
+
displayName: "storyScaffold__StyledGrid",
|
|
26
|
+
componentId: "sc-7oxew-2"
|
|
27
|
+
})(["display:flex;flex-wrap:wrap;gap:24px;align-items:flex-start;"]);
|
|
28
|
+
export const StyledColumn = styled.div.withConfig({
|
|
29
|
+
displayName: "storyScaffold__StyledColumn",
|
|
30
|
+
componentId: "sc-7oxew-3"
|
|
31
|
+
})(["display:flex;flex-direction:column;gap:12px;"]);
|
|
32
|
+
const StyledLabeled = styled.figure.withConfig({
|
|
33
|
+
displayName: "storyScaffold__StyledLabeled",
|
|
34
|
+
componentId: "sc-7oxew-4"
|
|
35
|
+
})(["margin:0;display:flex;flex-direction:column;gap:8px;> figcaption{order:-1;max-width:320px;}"]);
|
|
36
|
+
export const Labeled = _ref => {
|
|
37
|
+
let label = _ref.label,
|
|
38
|
+
children = _ref.children;
|
|
39
|
+
return /*#__PURE__*/React.createElement(StyledLabeled, null, /*#__PURE__*/React.createElement("figcaption", null, /*#__PURE__*/React.createElement(Caption1, {
|
|
40
|
+
color: "secondary"
|
|
41
|
+
}, label)), children);
|
|
42
|
+
};
|
|
43
|
+
export const Section = _ref2 => {
|
|
44
|
+
let caption = _ref2.caption,
|
|
45
|
+
note = _ref2.note,
|
|
46
|
+
children = _ref2.children;
|
|
47
|
+
return /*#__PURE__*/React.createElement(StyledSection, null, /*#__PURE__*/React.createElement(Caption1, {
|
|
48
|
+
weight: "bold",
|
|
49
|
+
color: "tertiary",
|
|
50
|
+
className: "section-caption"
|
|
51
|
+
}, caption), note ? /*#__PURE__*/React.createElement(Caption1, {
|
|
52
|
+
color: "tertiary",
|
|
53
|
+
className: "section-note"
|
|
54
|
+
}, note) : null, /*#__PURE__*/React.createElement(StyledGrid, null, children));
|
|
55
|
+
};
|
|
56
|
+
export const SheetHeading = _ref3 => {
|
|
57
|
+
let title = _ref3.title,
|
|
58
|
+
children = _ref3.children;
|
|
59
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Title2, {
|
|
60
|
+
className: "sheet-title"
|
|
61
|
+
}, title), /*#__PURE__*/React.createElement(Caption1, {
|
|
62
|
+
color: "tertiary",
|
|
63
|
+
className: "sheet-lede"
|
|
64
|
+
}, children));
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=storyScaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyScaffold.js","names":["React","styled","Caption1","Title2","StyledSheet","div","withConfig","displayName","componentId","StyledSection","section","StyledGrid","StyledColumn","StyledLabeled","figure","Labeled","_ref","label","children","createElement","color","Section","_ref2","caption","note","weight","className","SheetHeading","_ref3","title","Fragment"],"sources":["../../../../src/presentation/stackedCard/storyScaffold.tsx"],"sourcesContent":["import React, { ReactElement, ReactNode } from \"react\";\n\nimport styled from \"styled-components\";\n\nimport { Caption1, Title2 } from \"../../components/Typography\";\n\n/**\n * Shared spec-sheet scaffolding for the StackedCard concept stories (Sheet,\n * Section, Labeled, Grid, Column) plus the DS token candidates the subsystem\n * needs. Presentation-only; keeps the three StackedCard stories laying out the\n * same way instead of each re-declaring the sheet chrome.\n *\n * The `--sc-*` variables are declared here as design-system PROPOSALS (a\n * selection ring + a dark scrim family). The shell and primitives reference\n * these only, so no rgba/hex is baked into a reusable style.\n */\n\nexport const StyledSheet = styled.div`\n --sc-selection-ring: var(--color-primary-500, #2f6bff);\n --sc-scrim: rgba(0, 0, 0, 0.55);\n --sc-scrim-strong: rgba(0, 0, 0, 0.72);\n --sc-scrim-fg: #ffffff;\n --sc-completed-tint: rgba(72, 201, 176, 0.16);\n\n min-height: 100vh;\n padding: 32px 40px 64px;\n background: var(--page-paper-dimmed, var(--color-theme-200));\n\n .sheet-title {\n margin-bottom: 8px;\n }\n\n .sheet-lede {\n display: block;\n margin-bottom: 24px;\n max-width: 760px;\n }\n`;\n\nconst StyledSection = styled.section`\n margin-top: 40px;\n\n > .section-caption {\n display: block;\n margin-bottom: 4px;\n text-transform: uppercase;\n letter-spacing: 0.06em;\n }\n\n > .section-note {\n display: block;\n margin-bottom: 16px;\n max-width: 720px;\n }\n`;\n\nexport const StyledGrid = styled.div`\n display: flex;\n flex-wrap: wrap;\n gap: 24px;\n align-items: flex-start;\n`;\n\nexport const StyledColumn = styled.div`\n display: flex;\n flex-direction: column;\n gap: 12px;\n`;\n\nconst StyledLabeled = styled.figure`\n margin: 0;\n display: flex;\n flex-direction: column;\n gap: 8px;\n\n > figcaption {\n order: -1;\n max-width: 320px;\n }\n`;\n\nexport const Labeled = ({\n label,\n children,\n}: {\n label: ReactNode;\n children: ReactNode;\n}): ReactElement => (\n <StyledLabeled>\n <figcaption>\n <Caption1 color=\"secondary\">{label}</Caption1>\n </figcaption>\n {children}\n </StyledLabeled>\n);\n\nexport const Section = ({\n caption,\n note,\n children,\n}: {\n caption: string;\n note?: ReactNode;\n children: ReactNode;\n}): ReactElement => (\n <StyledSection>\n <Caption1 weight=\"bold\" color=\"tertiary\" className=\"section-caption\">\n {caption}\n </Caption1>\n {note ? (\n <Caption1 color=\"tertiary\" className=\"section-note\">\n {note}\n </Caption1>\n ) : null}\n <StyledGrid>{children}</StyledGrid>\n </StyledSection>\n);\n\nexport const SheetHeading = ({\n title,\n children,\n}: {\n title: string;\n children: ReactNode;\n}): ReactElement => (\n <>\n <Title2 className=\"sheet-title\">{title}</Title2>\n <Caption1 color=\"tertiary\" className=\"sheet-lede\">\n {children}\n </Caption1>\n </>\n);\n"],"mappings":"AAAA,OAAOA,KAAK,MAAmC,OAAO;AAEtD,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,SAASC,QAAQ,EAAEC,MAAM,QAAQ,6BAA6B;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,WAAW,GAAGH,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,6XAoBpC;AAED,MAAMC,aAAa,GAAGR,MAAM,CAACS,OAAO,CAAAJ,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,6LAenC;AAED,OAAO,MAAMG,UAAU,GAAGV,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,oEAKnC;AAED,OAAO,MAAMI,YAAY,GAAGX,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAA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ACuB,SAAS,EAAC;EAAa,GAAEG,KAAc,CAAC,eAChD7B,KAAA,CAAAmB,aAAA,CAACjB,QAAQ;IAACkB,KAAK,EAAC,UAAU;IAACM,SAAS,EAAC;EAAY,GAC9CR,QACO,CACV,CAAC;AAAA,CACJ","ignoreList":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent, KeyboardEvent } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* useInlineEdit — story-local click-to-edit state machine for StackedCard
|
|
4
|
+
* (task 4/8). Presentation-only; not exported from the design-system barrel.
|
|
5
|
+
*
|
|
6
|
+
* A card in preview/placeholder mode enters an EDITING state on click: a
|
|
7
|
+
* card-centered text field with confirm/cancel keyboard rules, an optional
|
|
8
|
+
* validator, and a single-line ↔ multi-line mode switch. The hook owns only the
|
|
9
|
+
* editing lifecycle (mode, working value, error, keyboard + outside-click); the
|
|
10
|
+
* card chrome and the async handoff after commit (e.g. the link unfurl ladder
|
|
11
|
+
* from task 3/8) live in the story that consumes it.
|
|
12
|
+
*
|
|
13
|
+
* ── The decided rules (AC task #454744) ──
|
|
14
|
+
* Single-line Enter confirms · click-outside confirms · Esc cancels + reverts
|
|
15
|
+
* Multi-line Enter = newline · Cmd/Ctrl+Enter saves · click-outside saves ·
|
|
16
|
+
* Esc cancels + reverts
|
|
17
|
+
* Validator validate(value) => true | errorMessage, run before every accept
|
|
18
|
+
* pass → commit + exit editing
|
|
19
|
+
* fail via a key → STAY editing, surface the message (retry)
|
|
20
|
+
* fail via outside → REVERT (acts as cancel) — user never trapped
|
|
21
|
+
*
|
|
22
|
+
* Keyboard is handled on the field's own keydown (never a global listener) and
|
|
23
|
+
* every keydown stops propagation, so the card focus model (task 2/8) can't
|
|
24
|
+
* swallow the Enter/Esc that belong to the editor.
|
|
25
|
+
*/
|
|
26
|
+
export type InlineEditValidator = (value: string) => true | string;
|
|
27
|
+
export interface UseInlineEditConfig {
|
|
28
|
+
/** Seed value for the first edit; also the revert target until first commit. */
|
|
29
|
+
initialValue?: string;
|
|
30
|
+
/** Multi-line mode: Enter inserts a newline, Cmd/Ctrl+Enter saves. */
|
|
31
|
+
multiline?: boolean;
|
|
32
|
+
/** Optional validator, run before every accept. `true` passes; a string fails. */
|
|
33
|
+
validate?: InlineEditValidator;
|
|
34
|
+
/** Called with the committed value when an accept passes validation. */
|
|
35
|
+
onCommit?: (value: string) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Props to spread onto the `<input>` or `<textarea>` while editing. */
|
|
38
|
+
export interface InlineEditBind {
|
|
39
|
+
/** Callback ref — assignable to both an input and a textarea. */
|
|
40
|
+
ref: (el: HTMLInputElement | HTMLTextAreaElement | null) => void;
|
|
41
|
+
value: string;
|
|
42
|
+
onChange: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
43
|
+
onKeyDown: (e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
44
|
+
onBlur: (e: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
45
|
+
"aria-invalid": boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface InlineEditController {
|
|
48
|
+
/** Whether the field is currently shown. */
|
|
49
|
+
editing: boolean;
|
|
50
|
+
/** The working value (the draft being typed). */
|
|
51
|
+
value: string;
|
|
52
|
+
/** The last committed value — what a revert restores. */
|
|
53
|
+
committed: string;
|
|
54
|
+
/** The current validation message, or null when valid / untouched. */
|
|
55
|
+
error: string | null;
|
|
56
|
+
/** Whether this editor is in multi-line mode. */
|
|
57
|
+
multiline: boolean;
|
|
58
|
+
/** Enter editing, loading the last committed value. */
|
|
59
|
+
begin: () => void;
|
|
60
|
+
/** Cancel + revert to the committed value (the Esc / invalid-outside path). */
|
|
61
|
+
cancel: () => void;
|
|
62
|
+
/** Force a committed value without going through the field (repeat demos). */
|
|
63
|
+
reset: (next?: string) => void;
|
|
64
|
+
/** Spread onto the field element while `editing`. */
|
|
65
|
+
bind: InlineEditBind;
|
|
66
|
+
}
|
|
67
|
+
export declare const useInlineEdit: ({ initialValue, multiline, validate, onCommit, }?: UseInlineEditConfig) => InlineEditController;
|
|
68
|
+
//# sourceMappingURL=useInlineEdit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInlineEdit.d.ts","sourceRoot":"","sources":["../../../../src/presentation/stackedCard/useInlineEdit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,aAAa,EAKd,MAAM,OAAO,CAAC;AAEf;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC;AAEnE,MAAM,WAAW,mBAAmB;IAClC,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,wEAAwE;IACxE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,GAAG,EAAE,CAAC,EAAE,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,IAAI,KAAK,IAAI,CAAC;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,IAAI,CAAC;IAC3E,SAAS,EAAE,CAAC,CAAC,EAAE,aAAa,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,IAAI,CAAC;IAC9E,MAAM,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACxE,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,iDAAiD;IACjD,SAAS,EAAE,OAAO,CAAC;IACnB,uDAAuD;IACvD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,8EAA8E;IAC9E,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,qDAAqD;IACrD,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,GAAI,mDAK3B,mBAAwB,KAAG,oBAgL7B,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* useInlineEdit — story-local click-to-edit state machine for StackedCard
|
|
5
|
+
* (task 4/8). Presentation-only; not exported from the design-system barrel.
|
|
6
|
+
*
|
|
7
|
+
* A card in preview/placeholder mode enters an EDITING state on click: a
|
|
8
|
+
* card-centered text field with confirm/cancel keyboard rules, an optional
|
|
9
|
+
* validator, and a single-line ↔ multi-line mode switch. The hook owns only the
|
|
10
|
+
* editing lifecycle (mode, working value, error, keyboard + outside-click); the
|
|
11
|
+
* card chrome and the async handoff after commit (e.g. the link unfurl ladder
|
|
12
|
+
* from task 3/8) live in the story that consumes it.
|
|
13
|
+
*
|
|
14
|
+
* ── The decided rules (AC task #454744) ──
|
|
15
|
+
* Single-line Enter confirms · click-outside confirms · Esc cancels + reverts
|
|
16
|
+
* Multi-line Enter = newline · Cmd/Ctrl+Enter saves · click-outside saves ·
|
|
17
|
+
* Esc cancels + reverts
|
|
18
|
+
* Validator validate(value) => true | errorMessage, run before every accept
|
|
19
|
+
* pass → commit + exit editing
|
|
20
|
+
* fail via a key → STAY editing, surface the message (retry)
|
|
21
|
+
* fail via outside → REVERT (acts as cancel) — user never trapped
|
|
22
|
+
*
|
|
23
|
+
* Keyboard is handled on the field's own keydown (never a global listener) and
|
|
24
|
+
* every keydown stops propagation, so the card focus model (task 2/8) can't
|
|
25
|
+
* swallow the Enter/Esc that belong to the editor.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** Props to spread onto the `<input>` or `<textarea>` while editing. */
|
|
29
|
+
|
|
30
|
+
export const useInlineEdit = function (_temp) {
|
|
31
|
+
let _ref = _temp === void 0 ? {} : _temp,
|
|
32
|
+
_ref$initialValue = _ref.initialValue,
|
|
33
|
+
initialValue = _ref$initialValue === void 0 ? "" : _ref$initialValue,
|
|
34
|
+
_ref$multiline = _ref.multiline,
|
|
35
|
+
multiline = _ref$multiline === void 0 ? false : _ref$multiline,
|
|
36
|
+
validate = _ref.validate,
|
|
37
|
+
onCommit = _ref.onCommit;
|
|
38
|
+
const _useState = useState(false),
|
|
39
|
+
editing = _useState[0],
|
|
40
|
+
setEditingState = _useState[1];
|
|
41
|
+
const _useState2 = useState(initialValue),
|
|
42
|
+
value = _useState2[0],
|
|
43
|
+
setValueState = _useState2[1];
|
|
44
|
+
const _useState3 = useState(initialValue),
|
|
45
|
+
committed = _useState3[0],
|
|
46
|
+
setCommittedState = _useState3[1];
|
|
47
|
+
const _useState4 = useState(null),
|
|
48
|
+
error = _useState4[0],
|
|
49
|
+
setError = _useState4[1];
|
|
50
|
+
|
|
51
|
+
// Refs mirror the state that the (stable) event handlers read, so the handlers
|
|
52
|
+
// never go stale and never need to be re-created as the value changes.
|
|
53
|
+
const elRef = useRef(null);
|
|
54
|
+
const valueRef = useRef(value);
|
|
55
|
+
const committedRef = useRef(committed);
|
|
56
|
+
const editingRef = useRef(editing);
|
|
57
|
+
// Set right before a programmatic exit so the blur that follows the field
|
|
58
|
+
// unmounting is ignored (it isn't a real click-outside).
|
|
59
|
+
const skipBlurRef = useRef(false);
|
|
60
|
+
const validateRef = useRef(validate);
|
|
61
|
+
const onCommitRef = useRef(onCommit);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
validateRef.current = validate;
|
|
64
|
+
onCommitRef.current = onCommit;
|
|
65
|
+
});
|
|
66
|
+
const setValue = useCallback(v => {
|
|
67
|
+
valueRef.current = v;
|
|
68
|
+
setValueState(v);
|
|
69
|
+
}, []);
|
|
70
|
+
const setCommitted = useCallback(v => {
|
|
71
|
+
committedRef.current = v;
|
|
72
|
+
setCommittedState(v);
|
|
73
|
+
}, []);
|
|
74
|
+
const setEditing = useCallback(v => {
|
|
75
|
+
editingRef.current = v;
|
|
76
|
+
setEditingState(v);
|
|
77
|
+
}, []);
|
|
78
|
+
const begin = useCallback(() => {
|
|
79
|
+
skipBlurRef.current = false;
|
|
80
|
+
setValue(committedRef.current);
|
|
81
|
+
setError(null);
|
|
82
|
+
setEditing(true);
|
|
83
|
+
}, [setValue, setEditing]);
|
|
84
|
+
const cancel = useCallback(() => {
|
|
85
|
+
skipBlurRef.current = true;
|
|
86
|
+
setValue(committedRef.current);
|
|
87
|
+
setError(null);
|
|
88
|
+
setEditing(false);
|
|
89
|
+
}, [setValue, setEditing]);
|
|
90
|
+
const reset = useCallback(function (next) {
|
|
91
|
+
if (next === void 0) {
|
|
92
|
+
next = initialValue;
|
|
93
|
+
}
|
|
94
|
+
skipBlurRef.current = true;
|
|
95
|
+
setCommitted(next);
|
|
96
|
+
setValue(next);
|
|
97
|
+
setError(null);
|
|
98
|
+
setEditing(false);
|
|
99
|
+
}, [initialValue, setCommitted, setValue, setEditing]);
|
|
100
|
+
const commit = useCallback(v => {
|
|
101
|
+
skipBlurRef.current = true;
|
|
102
|
+
setCommitted(v);
|
|
103
|
+
setValue(v);
|
|
104
|
+
setError(null);
|
|
105
|
+
setEditing(false);
|
|
106
|
+
onCommitRef.current == null || onCommitRef.current(v);
|
|
107
|
+
}, [setCommitted, setValue, setEditing]);
|
|
108
|
+
|
|
109
|
+
// Run the validator (if any) and accept, or handle the failure per source:
|
|
110
|
+
// a key retry keeps the user in the field with a message; an outside click
|
|
111
|
+
// reverts so the user is never trapped in an invalid editor.
|
|
112
|
+
const attempt = useCallback(source => {
|
|
113
|
+
const v = valueRef.current;
|
|
114
|
+
const result = validateRef.current ? validateRef.current(v) : true;
|
|
115
|
+
if (result === true) {
|
|
116
|
+
commit(v);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (source === "outside") {
|
|
120
|
+
cancel();
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
setError(result);
|
|
124
|
+
return false;
|
|
125
|
+
}, [commit, cancel]);
|
|
126
|
+
const onChange = useCallback(e => {
|
|
127
|
+
setValue(e.target.value);
|
|
128
|
+
// Clear a stale error as the user edits; the next accept re-validates.
|
|
129
|
+
setError(prev => prev == null ? prev : null);
|
|
130
|
+
}, [setValue]);
|
|
131
|
+
const onKeyDown = useCallback(e => {
|
|
132
|
+
// Keep Enter/Esc from reaching the card's own keyboard model (task 2/8).
|
|
133
|
+
e.stopPropagation();
|
|
134
|
+
if (e.key === "Escape") {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
cancel();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (e.key === "Enter") {
|
|
140
|
+
const withMeta = e.metaKey || e.ctrlKey;
|
|
141
|
+
// Multi-line: a bare Enter is a newline; only Cmd/Ctrl+Enter saves.
|
|
142
|
+
if (multiline && !withMeta) return;
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
attempt("key");
|
|
145
|
+
}
|
|
146
|
+
}, [attempt, cancel, multiline]);
|
|
147
|
+
const onBlur = useCallback(() => {
|
|
148
|
+
if (skipBlurRef.current) {
|
|
149
|
+
skipBlurRef.current = false;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (!editingRef.current) return;
|
|
153
|
+
attempt("outside");
|
|
154
|
+
}, [attempt]);
|
|
155
|
+
const setRef = useCallback(el => {
|
|
156
|
+
elRef.current = el;
|
|
157
|
+
}, []);
|
|
158
|
+
|
|
159
|
+
// On entering editing, focus the field and drop the caret at the end so the
|
|
160
|
+
// cursor is visible and existing text is ready to extend.
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (!editing) return;
|
|
163
|
+
const el = elRef.current;
|
|
164
|
+
if (!el) return;
|
|
165
|
+
el.focus();
|
|
166
|
+
const len = el.value.length;
|
|
167
|
+
try {
|
|
168
|
+
el.setSelectionRange(len, len);
|
|
169
|
+
} catch (_unused) {
|
|
170
|
+
/* some input types disallow setSelectionRange — harmless here. */
|
|
171
|
+
}
|
|
172
|
+
}, [editing]);
|
|
173
|
+
return {
|
|
174
|
+
editing,
|
|
175
|
+
value,
|
|
176
|
+
committed,
|
|
177
|
+
error,
|
|
178
|
+
multiline,
|
|
179
|
+
begin,
|
|
180
|
+
cancel,
|
|
181
|
+
reset,
|
|
182
|
+
bind: {
|
|
183
|
+
ref: setRef,
|
|
184
|
+
value,
|
|
185
|
+
onChange,
|
|
186
|
+
onKeyDown,
|
|
187
|
+
onBlur,
|
|
188
|
+
"aria-invalid": error != null
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
//# sourceMappingURL=useInlineEdit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInlineEdit.js","names":["useCallback","useEffect","useRef","useState","useInlineEdit","_temp","_ref","_ref$initialValue","initialValue","_ref$multiline","multiline","validate","onCommit","_useState","editing","setEditingState","_useState2","value","setValueState","_useState3","committed","setCommittedState","_useState4","error","setError","elRef","valueRef","committedRef","editingRef","skipBlurRef","validateRef","onCommitRef","current","setValue","v","setCommitted","setEditing","begin","cancel","reset","next","commit","attempt","source","result","onChange","e","target","prev","onKeyDown","stopPropagation","key","preventDefault","withMeta","metaKey","ctrlKey","onBlur","setRef","el","focus","len","length","setSelectionRange","_unused","bind","ref"],"sources":["../../../../src/presentation/stackedCard/useInlineEdit.ts"],"sourcesContent":["import {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\n\n/**\n * useInlineEdit — story-local click-to-edit state machine for StackedCard\n * (task 4/8). Presentation-only; not exported from the design-system barrel.\n *\n * A card in preview/placeholder mode enters an EDITING state on click: a\n * card-centered text field with confirm/cancel keyboard rules, an optional\n * validator, and a single-line ↔ multi-line mode switch. The hook owns only the\n * editing lifecycle (mode, working value, error, keyboard + outside-click); the\n * card chrome and the async handoff after commit (e.g. the link unfurl ladder\n * from task 3/8) live in the story that consumes it.\n *\n * ── The decided rules (AC task #454744) ──\n * Single-line Enter confirms · click-outside confirms · Esc cancels + reverts\n * Multi-line Enter = newline · Cmd/Ctrl+Enter saves · click-outside saves ·\n * Esc cancels + reverts\n * Validator validate(value) => true | errorMessage, run before every accept\n * pass → commit + exit editing\n * fail via a key → STAY editing, surface the message (retry)\n * fail via outside → REVERT (acts as cancel) — user never trapped\n *\n * Keyboard is handled on the field's own keydown (never a global listener) and\n * every keydown stops propagation, so the card focus model (task 2/8) can't\n * swallow the Enter/Esc that belong to the editor.\n */\n\nexport type InlineEditValidator = (value: string) => true | string;\n\nexport interface UseInlineEditConfig {\n /** Seed value for the first edit; also the revert target until first commit. */\n initialValue?: string;\n /** Multi-line mode: Enter inserts a newline, Cmd/Ctrl+Enter saves. */\n multiline?: boolean;\n /** Optional validator, run before every accept. `true` passes; a string fails. */\n validate?: InlineEditValidator;\n /** Called with the committed value when an accept passes validation. */\n onCommit?: (value: string) => void;\n}\n\n/** Props to spread onto the `<input>` or `<textarea>` while editing. */\nexport interface InlineEditBind {\n /** Callback ref — assignable to both an input and a textarea. */\n ref: (el: HTMLInputElement | HTMLTextAreaElement | null) => void;\n value: string;\n onChange: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n onKeyDown: (e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n onBlur: (e: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;\n \"aria-invalid\": boolean;\n}\n\nexport interface InlineEditController {\n /** Whether the field is currently shown. */\n editing: boolean;\n /** The working value (the draft being typed). */\n value: string;\n /** The last committed value — what a revert restores. */\n committed: string;\n /** The current validation message, or null when valid / untouched. */\n error: string | null;\n /** Whether this editor is in multi-line mode. */\n multiline: boolean;\n /** Enter editing, loading the last committed value. */\n begin: () => void;\n /** Cancel + revert to the committed value (the Esc / invalid-outside path). */\n cancel: () => void;\n /** Force a committed value without going through the field (repeat demos). */\n reset: (next?: string) => void;\n /** Spread onto the field element while `editing`. */\n bind: InlineEditBind;\n}\n\nexport const useInlineEdit = ({\n initialValue = \"\",\n multiline = false,\n validate,\n onCommit,\n}: UseInlineEditConfig = {}): InlineEditController => {\n const [editing, setEditingState] = useState(false);\n const [value, setValueState] = useState(initialValue);\n const [committed, setCommittedState] = useState(initialValue);\n const [error, setError] = useState<string | null>(null);\n\n // Refs mirror the state that the (stable) event handlers read, so the handlers\n // never go stale and never need to be re-created as the value changes.\n const elRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null);\n const valueRef = useRef(value);\n const committedRef = useRef(committed);\n const editingRef = useRef(editing);\n // Set right before a programmatic exit so the blur that follows the field\n // unmounting is ignored (it isn't a real click-outside).\n const skipBlurRef = useRef(false);\n const validateRef = useRef(validate);\n const onCommitRef = useRef(onCommit);\n\n useEffect(() => {\n validateRef.current = validate;\n onCommitRef.current = onCommit;\n });\n\n const setValue = useCallback((v: string) => {\n valueRef.current = v;\n setValueState(v);\n }, []);\n\n const setCommitted = useCallback((v: string) => {\n committedRef.current = v;\n setCommittedState(v);\n }, []);\n\n const setEditing = useCallback((v: boolean) => {\n editingRef.current = v;\n setEditingState(v);\n }, []);\n\n const begin = useCallback(() => {\n skipBlurRef.current = false;\n setValue(committedRef.current);\n setError(null);\n setEditing(true);\n }, [setValue, setEditing]);\n\n const cancel = useCallback(() => {\n skipBlurRef.current = true;\n setValue(committedRef.current);\n setError(null);\n setEditing(false);\n }, [setValue, setEditing]);\n\n const reset = useCallback(\n (next: string = initialValue) => {\n skipBlurRef.current = true;\n setCommitted(next);\n setValue(next);\n setError(null);\n setEditing(false);\n },\n [initialValue, setCommitted, setValue, setEditing]\n );\n\n const commit = useCallback(\n (v: string) => {\n skipBlurRef.current = true;\n setCommitted(v);\n setValue(v);\n setError(null);\n setEditing(false);\n onCommitRef.current?.(v);\n },\n [setCommitted, setValue, setEditing]\n );\n\n // Run the validator (if any) and accept, or handle the failure per source:\n // a key retry keeps the user in the field with a message; an outside click\n // reverts so the user is never trapped in an invalid editor.\n const attempt = useCallback(\n (source: \"key\" | \"outside\"): boolean => {\n const v = valueRef.current;\n const result = validateRef.current ? validateRef.current(v) : true;\n if (result === true) {\n commit(v);\n return true;\n }\n if (source === \"outside\") {\n cancel();\n return false;\n }\n setError(result);\n return false;\n },\n [commit, cancel]\n );\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setValue(e.target.value);\n // Clear a stale error as the user edits; the next accept re-validates.\n setError((prev) => (prev == null ? prev : null));\n },\n [setValue]\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n // Keep Enter/Esc from reaching the card's own keyboard model (task 2/8).\n e.stopPropagation();\n\n if (e.key === \"Escape\") {\n e.preventDefault();\n cancel();\n return;\n }\n\n if (e.key === \"Enter\") {\n const withMeta = e.metaKey || e.ctrlKey;\n // Multi-line: a bare Enter is a newline; only Cmd/Ctrl+Enter saves.\n if (multiline && !withMeta) return;\n e.preventDefault();\n attempt(\"key\");\n }\n },\n [attempt, cancel, multiline]\n );\n\n const onBlur = useCallback(() => {\n if (skipBlurRef.current) {\n skipBlurRef.current = false;\n return;\n }\n if (!editingRef.current) return;\n attempt(\"outside\");\n }, [attempt]);\n\n const setRef = useCallback(\n (el: HTMLInputElement | HTMLTextAreaElement | null) => {\n elRef.current = el;\n },\n []\n );\n\n // On entering editing, focus the field and drop the caret at the end so the\n // cursor is visible and existing text is ready to extend.\n useEffect(() => {\n if (!editing) return;\n const el = elRef.current;\n if (!el) return;\n el.focus();\n const len = el.value.length;\n try {\n el.setSelectionRange(len, len);\n } catch {\n /* some input types disallow setSelectionRange — harmless here. */\n }\n }, [editing]);\n\n return {\n editing,\n value,\n committed,\n error,\n multiline,\n begin,\n cancel,\n reset,\n bind: {\n ref: setRef,\n value,\n onChange,\n onKeyDown,\n onBlur,\n \"aria-invalid\": error != null,\n },\n };\n};\n"],"mappings":"AAAA,SAIEA,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;;AAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;;AAgCA,OAAO,MAAMC,aAAa,GAAG,SAAAA,CAAAC,KAAA,EAKyB;EAAA,IAAAC,IAAA,GAAAD,KAAA,cAA7B,CAAC,CAAC,GAAAA,KAAA;IAAAE,iBAAA,GAAAD,IAAA,CAJzBE,YAAY;IAAZA,YAAY,GAAAD,iBAAA,cAAG,EAAE,GAAAA,iBAAA;IAAAE,cAAA,GAAAH,IAAA,CACjBI,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,KAAK,GAAAA,cAAA;IACjBE,QAAQ,GAAAL,IAAA,CAARK,QAAQ;IACRC,QAAQ,GAAAN,IAAA,CAARM,QAAQ;EAER,MAAAC,SAAA,GAAmCV,QAAQ,CAAC,KAAK,CAAC;IAA3CW,OAAO,GAAAD,SAAA;IAAEE,eAAe,GAAAF,SAAA;EAC/B,MAAAG,UAAA,GAA+Bb,QAAQ,CAACK,YAAY,CAAC;IAA9CS,KAAK,GAAAD,UAAA;IAAEE,aAAa,GAAAF,UAAA;EAC3B,MAAAG,UAAA,GAAuChB,QAAQ,CAACK,YAAY,CAAC;IAAtDY,SA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