@wistia/ui 3.8.2-beta.e1fdd4e3.a8dcec6 → 3.8.3

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*
3
- * @license @wistia/ui v3.8.2-beta.e1fdd4e3.a8dcec6
3
+ * @license @wistia/ui v3.8.3
4
4
  *
5
5
  * Copyright (c) 2024-2026, Wistia, Inc. and its affiliates.
6
6
  *
@@ -13131,68 +13131,64 @@ const EditableHeading = ({ children, onValueChange, onEditingChange, tooltipText
13131
13131
  }) })] });
13132
13132
  };
13133
13133
  // src/components/EditableText/EditableTextRoot.tsx
13134
- const SMALL_PADDING = "var(--wui-space-01)";
13135
13134
  const LARGE_PADDING = "var(--wui-space-02)";
13136
- const LARGE_PADDING_VARIANTS = /* @__PURE__ */ new Set([
13137
- "hero",
13138
- "heading1",
13139
- "heading2",
13140
- "heading3"
13141
- ]);
13142
- const getPaddingForVariant = (variant) => LARGE_PADDING_VARIANTS.has(variant) ? LARGE_PADDING : SMALL_PADDING;
13135
+ const SMALL_PADDING = "var(--wui-space-01)";
13136
+ const getPaddingForVariant = (variant) => {
13137
+ const largePaddingVariants = [
13138
+ "hero",
13139
+ "heading1",
13140
+ "heading2",
13141
+ "heading3",
13142
+ "body1",
13143
+ "label1",
13144
+ "body1Mono"
13145
+ ];
13146
+ const smallPaddingVariants = [
13147
+ "heading4",
13148
+ "heading5",
13149
+ "heading6",
13150
+ "body2",
13151
+ "body3",
13152
+ "body4",
13153
+ "label2",
13154
+ "label3",
13155
+ "label4",
13156
+ "body2Mono",
13157
+ "body3Mono",
13158
+ "body4Mono"
13159
+ ];
13160
+ if (largePaddingVariants.includes(variant)) return LARGE_PADDING;
13161
+ if (smallPaddingVariants.includes(variant)) return SMALL_PADDING;
13162
+ return SMALL_PADDING;
13163
+ };
13143
13164
  const StyledEditableTextRoot = styled.div`
13144
13165
  display: contents;
13145
13166
 
13146
13167
  --wui-editable-text-padding: ${({ $typographicVariant }) => getPaddingForVariant($typographicVariant)};
13147
13168
  --wui-editable-text-border-radius: var(--wui-border-radius-01);
13148
-
13149
- /* A negative margin that pulls the display and input out by their padding, so the text
13150
- * sits where it would without EditableText and doesn't move when editing starts. */
13151
- --wui-editable-text-bleed: ${({ $bleed }) => $bleed ? "calc(var(--wui-editable-text-padding) * -1)" : "0px"};
13152
13169
  `;
13153
13170
  const EditableTextContext = createContext(null);
13154
- const getEditableTextState = (readOnly, isEditing) => {
13155
- if (readOnly) return "read-only";
13156
- if (isEditing) return "editing";
13157
- return "idle";
13158
- };
13159
- /**
13160
- * Holds the value (controlled or uncontrolled), the value to revert to and the editing state.
13161
- */
13162
- const useEditableTextState = ({ controlledValue, defaultValue, onValueChange, onEditingChange }) => {
13171
+ const EditableTextRoot = ({ children, defaultValue = "", value: controlledValue, onValueChange, onValueCommit, onValueRevert, onEditingChange, typographicVariant = "body2", submitMode = "both", readOnly = false, id, label, placeholder = "Click to edit this text", minLines = 1, maxLines, finalFocusEl, ...props }) => {
13163
13172
  const isControlled = controlledValue !== void 0;
13164
13173
  const [internalValue, setInternalValue] = useState(defaultValue);
13165
13174
  const [originalValue, setOriginalValue] = useState(defaultValue);
13166
13175
  const [isEditing, setIsEditing] = useState(false);
13167
13176
  const value = isControlled ? controlledValue : internalValue;
13168
- return {
13177
+ const generatedId = useId();
13178
+ const computedId = isNonEmptyString(id) ? id : `wistia-ui-editable-text-${generatedId}`;
13179
+ const handleSetIsEditing = useCallback((editing) => {
13180
+ if (editing && !isEditing) setOriginalValue(value);
13181
+ setIsEditing(editing);
13182
+ onEditingChange?.(editing);
13183
+ }, [
13169
13184
  isEditing,
13170
- handleSetIsEditing: useCallback((editing) => {
13171
- if (editing && !isEditing) setOriginalValue(value);
13172
- setIsEditing(editing);
13173
- onEditingChange?.(editing);
13174
- }, [
13175
- isEditing,
13176
- value,
13177
- onEditingChange
13178
- ]),
13179
13185
  value,
13180
- setValue: useCallback((newValue) => {
13181
- if (!isControlled) setInternalValue(newValue);
13182
- onValueChange?.(newValue);
13183
- }, [isControlled, onValueChange]),
13184
- originalValue
13185
- };
13186
- };
13187
- const EditableTextRoot = ({ children, defaultValue = "", value: controlledValue, onValueChange, onValueCommit, onValueRevert, onEditingChange, typographicVariant = "body2", submitMode = "both", readOnly = false, id, label, placeholder = "Click to edit this text", minLines = 1, maxLines, finalFocusEl, bleed = false, ...props }) => {
13188
- const { isEditing, handleSetIsEditing, value, setValue, originalValue } = useEditableTextState({
13189
- controlledValue,
13190
- defaultValue,
13191
- onValueChange,
13192
13186
  onEditingChange
13193
- });
13194
- const generatedId = useId();
13195
- const computedId = isNonEmptyString(id) ? id : `wistia-ui-editable-text-${generatedId}`;
13187
+ ]);
13188
+ const setValue = useCallback((newValue) => {
13189
+ if (!isControlled) setInternalValue(newValue);
13190
+ onValueChange?.(newValue);
13191
+ }, [isControlled, onValueChange]);
13196
13192
  const context = useMemo(() => {
13197
13193
  return {
13198
13194
  isEditing,
@@ -13230,13 +13226,16 @@ const EditableTextRoot = ({ children, defaultValue = "", value: controlledValue,
13230
13226
  maxLines,
13231
13227
  finalFocusEl
13232
13228
  ]);
13229
+ const getState = () => {
13230
+ if (readOnly) return "read-only";
13231
+ if (isEditing) return "editing";
13232
+ return "idle";
13233
+ };
13233
13234
  return /* @__PURE__ */ jsx(StyledEditableTextRoot, {
13234
- $bleed: bleed,
13235
13235
  $typographicVariant: typographicVariant,
13236
13236
  "data-testid": "editable-text-root",
13237
- "data-wui-editable-text-bleed": bleed || void 0,
13238
13237
  "data-wui-editable-text-root": true,
13239
- "data-wui-editable-text-state": getEditableTextState(readOnly, isEditing),
13238
+ "data-wui-editable-text-state": getState(),
13240
13239
  ...props,
13241
13240
  children: /* @__PURE__ */ jsx(EditableTextContext, {
13242
13241
  value: context,
@@ -13246,11 +13245,9 @@ const EditableTextRoot = ({ children, defaultValue = "", value: controlledValue,
13246
13245
  };
13247
13246
  const PolymorphicStyledEditableTextDisplay = withPolymorphicAs(styled.div`
13248
13247
  ${({ $typographicVariant }) => getTypographicStyles($typographicVariant)}
13249
- padding-block: var(--wui-editable-text-padding);
13250
- padding-inline: var(--wui-editable-text-padding);
13248
+ padding: var(--wui-editable-text-padding);
13251
13249
  border-radius: var(--wui-editable-text-border-radius);
13252
- margin-block: var(--wui-editable-text-bleed, 0);
13253
- margin-inline: var(--wui-editable-text-bleed, 0);
13250
+ margin: 0;
13254
13251
  transition: all var(--wui-motion-duration-02) var(--wui-motion-ease);
13255
13252
  ${({ $maxLines }) => {
13256
13253
  if (isNotNil($maxLines)) return css`
@@ -13323,209 +13320,88 @@ const EditableTextDisplayComponent = ({ ref, asTrigger, renderAs, ...props }) =>
13323
13320
  };
13324
13321
  const EditableTextDisplay = makePolymorphic(EditableTextDisplayComponent);
13325
13322
  // src/components/EditableText/EditableTextInput.tsx
13326
- const StyledInputWrapper = styled.div`
13327
- display: flex;
13328
- min-width: 0;
13329
-
13330
- & > [data-wui-input-container] {
13331
- flex: 1 1 auto;
13332
- min-width: 0;
13333
- }
13334
- `;
13335
13323
  const StyledInput = styled(Input)`
13336
13324
  && {
13337
13325
  ${({ $minLines }) => isNotNil($minLines) && `min-height: calc(${$minLines}lh + calc(var(--wui-editable-text-padding) * 2));`}
13338
13326
  ${({ $maxLines }) => isNotNil($maxLines) && `max-height: calc(${$maxLines}lh + calc(var(--wui-editable-text-padding) * 2));`}
13339
13327
  ${({ $typographicVariant }) => getTypographicStyles($typographicVariant)}
13340
- /* No fill: the text sits on the page as it does when reading, and the ring marks the field */
13341
- background-color: transparent;
13342
-
13343
- /* With no fill of its own, the text takes the surrounding color and alignment, like the display */
13344
- color: inherit;
13345
- text-align: inherit;
13328
+ background-color: var(--wui-color-bg-surface);
13346
13329
  border-radius: var(--wui-editable-text-border-radius);
13347
- padding-block: var(--wui-editable-text-padding);
13348
- padding-inline: var(--wui-editable-text-padding);
13349
- margin-block: var(--wui-editable-text-bleed, 0);
13350
- margin-inline: var(--wui-editable-text-bleed, 0);
13351
- width: calc(100% - (var(--wui-editable-text-bleed, 0px) * 2));
13330
+ padding: var(--wui-editable-text-padding);
13352
13331
  resize: none;
13353
-
13354
- /*
13355
- * Size to the text, like the display, instead of the textarea's default 20-column width.
13356
- * Otherwise the field changes width when editing starts wherever its parent shrink-wraps.
13357
- */
13358
- field-sizing: content;
13359
-
13360
- /*
13361
- * maxLines={1}: behave like a single-line text input. The value stays on one line and
13362
- * scrolls sideways instead of wrapping and scrolling vertically inside a one-line box.
13363
- */
13364
- ${({ $maxLines }) => $maxLines === 1 && css`
13365
- white-space: pre;
13366
- overflow-x: auto;
13367
- overflow-y: hidden;
13368
- scrollbar-width: none;
13369
-
13370
- &::-webkit-scrollbar {
13371
- display: none;
13372
- }
13373
- `}
13374
-
13375
- /* Same color as the display's placeholder, so it doesn't change when editing starts */
13376
- &::placeholder {
13377
- color: var(--wui-color-text-secondary);
13378
- }
13379
-
13380
- /* Full-perimeter focus ring, inset like Input's so an overflow-hidden ancestor can't clip it */
13381
- &:focus {
13382
- outline: 2px solid var(--wui-color-focus-ring);
13383
- outline-offset: -2px;
13384
- }
13385
-
13386
- /*
13387
- * With submitMode "enter" or "none" the field stays open when focus moves to the
13388
- * save/cancel buttons. Keep a visible 1px boundary so it still meets non-text contrast.
13389
- */
13390
- &:not(:focus) {
13391
- outline: 1px solid var(--wui-color-border-secondary);
13392
- outline-offset: -1px;
13393
- }
13394
- }
13395
-
13396
- /*
13397
- * Input sets its textarea's height from the rows attribute, which would stop the field sizing
13398
- * to its text. The extra & outranks that rule.
13399
- */
13400
- &&& {
13401
- height: auto;
13402
13332
  }
13403
13333
  `;
13404
- const KEYBOARD_HINTS = {
13405
- both: "Press Enter to save or Escape to cancel. Changes also save when you leave the field.",
13406
- enter: "Press Enter to save or Escape to cancel.",
13407
- blur: "Changes save when you leave the field. Press Escape to cancel.",
13408
- none: "Press Escape to cancel."
13409
- };
13410
- /** Whether this key press submits: Enter without Shift, in a submit mode that uses Enter */
13411
- const isCommitEnter = (event, submitMode) => event.key === "Enter" && !event.shiftKey && (submitMode === "enter" || submitMode === "both");
13412
- /** A single-line field can't hold line breaks, so each one becomes a space */
13413
- const toSingleLine = (text) => text.replaceAll(/\r\n|\r|\n/g, " ");
13414
- /** Whether the browser sizes the textarea to its content itself (`field-sizing: content`) */
13415
- const supportsFieldSizing = () => typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("field-sizing", "content");
13416
- /** In a single-line field, scroll sideways so the end of the value (and a caret there) is visible */
13417
- const scrollToEnd = (element) => {
13418
- element.scrollLeft = element.scrollWidth;
13419
- };
13420
- const EditableTextInput = ({ autoSelect = false, ...props }) => {
13334
+ const EditableTextInput = (props) => {
13421
13335
  const context = useContext(EditableTextContext);
13422
13336
  if (!context) throw new Error("EditableTextInput must be used within an EditableTextRoot context");
13423
13337
  const { isEditing, value, setValue, onValueCommit, setIsEditing, typographicVariant, submitMode, originalValue, onValueRevert, id, placeholder, minLines, maxLines, finalFocusEl } = context;
13424
13338
  const inputRef = useRef(null);
13425
- const isEnteringRef = useRef(false);
13426
- useEffect(() => {
13427
- isEnteringRef.current = isEditing;
13428
- }, [isEditing]);
13429
13339
  useEffect(() => {
13430
13340
  if (inputRef.current) {
13431
- if (isEditing && !supportsFieldSizing()) {
13341
+ if (isEditing) {
13432
13342
  const element = inputRef.current;
13433
13343
  const { style } = element;
13434
13344
  style.height = "0px";
13435
13345
  const { scrollHeight } = element;
13436
13346
  style.height = `${scrollHeight}px`;
13437
13347
  }
13438
- if (isEditing) {
13439
- inputRef.current.focus();
13440
- isEnteringRef.current = false;
13441
- }
13348
+ if (isEditing) inputRef.current.focus();
13442
13349
  }
13443
13350
  }, [value, isEditing]);
13444
- const isSingleLine = maxLines === 1;
13445
- const fieldValue = isSingleLine ? toSingleLine(value) : value;
13446
13351
  const handleChange = (event) => {
13447
- const { target } = event;
13448
- const nextValue = target.value;
13449
- if (!isSingleLine) {
13450
- setValue(nextValue);
13451
- return;
13452
- }
13453
- const singleLineValue = toSingleLine(nextValue);
13454
- if (singleLineValue !== nextValue) {
13455
- const { selectionStart, selectionEnd } = target;
13456
- target.value = singleLineValue;
13457
- target.setSelectionRange(selectionStart, selectionEnd);
13458
- }
13459
- setValue(singleLineValue);
13460
- };
13461
- const closeAndRestoreFocus = () => {
13462
- setIsEditing(false);
13463
- setTimeout(() => {
13464
- finalFocusEl?.()?.focus();
13465
- }, 0);
13352
+ setValue(event.target.value);
13466
13353
  };
13467
13354
  const handleKeyDown = (event) => {
13355
+ if ((submitMode === "enter" || submitMode === "both") && event.key === "Enter" && !event.shiftKey) {
13356
+ event.preventDefault();
13357
+ onValueCommit?.(value);
13358
+ setIsEditing(false);
13359
+ setTimeout(() => {
13360
+ const element = finalFocusEl?.();
13361
+ if (element) element.focus();
13362
+ }, 0);
13363
+ }
13468
13364
  if (event.key === "Escape") {
13469
13365
  event.preventDefault();
13470
13366
  setValue(originalValue);
13471
13367
  onValueRevert?.(originalValue);
13472
- closeAndRestoreFocus();
13473
- return;
13474
- }
13475
- if (isCommitEnter(event, submitMode)) {
13476
- event.preventDefault();
13477
- onValueCommit?.(fieldValue);
13478
- closeAndRestoreFocus();
13479
- return;
13368
+ setIsEditing(false);
13369
+ setTimeout(() => {
13370
+ const element = finalFocusEl?.();
13371
+ if (element) element.focus();
13372
+ }, 0);
13480
13373
  }
13481
- if (isSingleLine && event.key === "Enter") event.preventDefault();
13482
13374
  };
13483
13375
  const handleBlur = () => {
13484
13376
  if (submitMode === "blur" || submitMode === "both") {
13485
- onValueCommit?.(fieldValue);
13486
- closeAndRestoreFocus();
13377
+ onValueCommit?.(value);
13378
+ setIsEditing(false);
13379
+ setTimeout(() => {
13380
+ const element = finalFocusEl?.();
13381
+ if (element) element.focus();
13382
+ }, 0);
13487
13383
  }
13488
13384
  };
13489
- const handleFocus = (event) => {
13490
- const element = event.currentTarget;
13491
- const shouldSelect = autoSelect && isEnteringRef.current;
13492
- isEnteringRef.current = false;
13493
- const { length } = element.value;
13494
- element.setSelectionRange(length, length);
13495
- if (isSingleLine) scrollToEnd(element);
13496
- if (!shouldSelect && !isSingleLine) return;
13497
- const valueOnFocus = element.value;
13498
- requestAnimationFrame(() => {
13499
- if (shouldSelect && element.value === valueOnFocus) element.select();
13500
- if (isSingleLine && element.selectionEnd === element.value.length) scrollToEnd(element);
13501
- });
13502
- };
13503
13385
  if (!isEditing) return null;
13504
- const keyboardHintId = `${id}-keyboard-hint`;
13505
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(StyledInputWrapper, {
13506
- "data-testid": "editable-text-input-wrapper",
13507
- children: /* @__PURE__ */ jsx(StyledInput, {
13508
- ref: inputRef,
13509
- $maxLines: maxLines ?? "infinity",
13510
- $minLines: minLines,
13511
- $typographicVariant: typographicVariant,
13512
- "aria-describedby": keyboardHintId,
13513
- "data-wui-editable-text-input": true,
13514
- id,
13515
- onBlur: handleBlur,
13516
- onChange: handleChange,
13517
- onFocus: handleFocus,
13518
- onKeyDown: handleKeyDown,
13519
- placeholder,
13520
- type: "multiline",
13521
- value: fieldValue,
13522
- ...props
13523
- })
13524
- }), /* @__PURE__ */ jsx(ScreenReaderOnly, {
13525
- "data-wui-editable-text-keyboard-hint": true,
13526
- id: keyboardHintId,
13527
- text: KEYBOARD_HINTS[submitMode]
13528
- })] });
13386
+ return /* @__PURE__ */ jsx(StyledInput, {
13387
+ ref: inputRef,
13388
+ $maxLines: maxLines ?? "infinity",
13389
+ $minLines: minLines,
13390
+ $typographicVariant: typographicVariant,
13391
+ "data-wui-editable-text-input": true,
13392
+ id,
13393
+ onBlur: handleBlur,
13394
+ onChange: handleChange,
13395
+ onFocus: (event) => {
13396
+ const { length } = event.currentTarget.value;
13397
+ event.currentTarget.setSelectionRange(length, length);
13398
+ },
13399
+ onKeyDown: handleKeyDown,
13400
+ placeholder,
13401
+ type: "multiline",
13402
+ value,
13403
+ ...props
13404
+ });
13529
13405
  };
13530
13406
  // src/components/EditableText/EditableTextLabel.tsx
13531
13407
  const EditableTextLabel = ({ ...props }) => {