@wistia/ui 3.8.3 → 3.8.4-beta.07a22427.7fda68d

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.3
3
+ * @license @wistia/ui v3.8.4-beta.07a22427.7fda68d
4
4
  *
5
5
  * Copyright (c) 2024-2026, Wistia, Inc. and its affiliates.
6
6
  *
@@ -1547,8 +1547,8 @@ const LINK_ATTRIBUTES = [
1547
1547
  "aria-owns",
1548
1548
  "id"
1549
1549
  ];
1550
- const createAriaHider = (containerNode, selector = "body > :not(script)") => {
1551
- const candidates = [...document.querySelectorAll(selector)];
1550
+ const createAriaHider = (containerNode) => {
1551
+ const candidates = [...document.querySelectorAll("body > :not(script)")];
1552
1552
  const heldNodes = /* @__PURE__ */ new Set();
1553
1553
  const update = () => {
1554
1554
  const regions = getTrapRegions(containerNode);
@@ -13131,64 +13131,68 @@ const EditableHeading = ({ children, onValueChange, onEditingChange, tooltipText
13131
13131
  }) })] });
13132
13132
  };
13133
13133
  // src/components/EditableText/EditableTextRoot.tsx
13134
- const LARGE_PADDING = "var(--wui-space-02)";
13135
13134
  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
- };
13135
+ 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;
13164
13143
  const StyledEditableTextRoot = styled.div`
13165
13144
  display: contents;
13166
13145
 
13167
13146
  --wui-editable-text-padding: ${({ $typographicVariant }) => getPaddingForVariant($typographicVariant)};
13168
13147
  --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"};
13169
13152
  `;
13170
13153
  const EditableTextContext = createContext(null);
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 }) => {
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 }) => {
13172
13163
  const isControlled = controlledValue !== void 0;
13173
13164
  const [internalValue, setInternalValue] = useState(defaultValue);
13174
13165
  const [originalValue, setOriginalValue] = useState(defaultValue);
13175
13166
  const [isEditing, setIsEditing] = useState(false);
13176
13167
  const value = isControlled ? controlledValue : internalValue;
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
- }, [
13168
+ return {
13184
13169
  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
+ ]),
13185
13179
  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,
13186
13192
  onEditingChange
13187
- ]);
13188
- const setValue = useCallback((newValue) => {
13189
- if (!isControlled) setInternalValue(newValue);
13190
- onValueChange?.(newValue);
13191
- }, [isControlled, onValueChange]);
13193
+ });
13194
+ const generatedId = useId();
13195
+ const computedId = isNonEmptyString(id) ? id : `wistia-ui-editable-text-${generatedId}`;
13192
13196
  const context = useMemo(() => {
13193
13197
  return {
13194
13198
  isEditing,
@@ -13226,16 +13230,13 @@ const EditableTextRoot = ({ children, defaultValue = "", value: controlledValue,
13226
13230
  maxLines,
13227
13231
  finalFocusEl
13228
13232
  ]);
13229
- const getState = () => {
13230
- if (readOnly) return "read-only";
13231
- if (isEditing) return "editing";
13232
- return "idle";
13233
- };
13234
13233
  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,
13237
13238
  "data-wui-editable-text-root": true,
13238
- "data-wui-editable-text-state": getState(),
13239
+ "data-wui-editable-text-state": getEditableTextState(readOnly, isEditing),
13239
13240
  ...props,
13240
13241
  children: /* @__PURE__ */ jsx(EditableTextContext, {
13241
13242
  value: context,
@@ -13245,9 +13246,11 @@ const EditableTextRoot = ({ children, defaultValue = "", value: controlledValue,
13245
13246
  };
13246
13247
  const PolymorphicStyledEditableTextDisplay = withPolymorphicAs(styled.div`
13247
13248
  ${({ $typographicVariant }) => getTypographicStyles($typographicVariant)}
13248
- padding: var(--wui-editable-text-padding);
13249
+ padding-block: var(--wui-editable-text-padding);
13250
+ padding-inline: var(--wui-editable-text-padding);
13249
13251
  border-radius: var(--wui-editable-text-border-radius);
13250
- margin: 0;
13252
+ margin-block: var(--wui-editable-text-bleed, 0);
13253
+ margin-inline: var(--wui-editable-text-bleed, 0);
13251
13254
  transition: all var(--wui-motion-duration-02) var(--wui-motion-ease);
13252
13255
  ${({ $maxLines }) => {
13253
13256
  if (isNotNil($maxLines)) return css`
@@ -13320,88 +13323,209 @@ const EditableTextDisplayComponent = ({ ref, asTrigger, renderAs, ...props }) =>
13320
13323
  };
13321
13324
  const EditableTextDisplay = makePolymorphic(EditableTextDisplayComponent);
13322
13325
  // 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
+ `;
13323
13335
  const StyledInput = styled(Input)`
13324
13336
  && {
13325
13337
  ${({ $minLines }) => isNotNil($minLines) && `min-height: calc(${$minLines}lh + calc(var(--wui-editable-text-padding) * 2));`}
13326
13338
  ${({ $maxLines }) => isNotNil($maxLines) && `max-height: calc(${$maxLines}lh + calc(var(--wui-editable-text-padding) * 2));`}
13327
13339
  ${({ $typographicVariant }) => getTypographicStyles($typographicVariant)}
13328
- background-color: var(--wui-color-bg-surface);
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;
13329
13346
  border-radius: var(--wui-editable-text-border-radius);
13330
- padding: var(--wui-editable-text-padding);
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));
13331
13352
  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;
13332
13402
  }
13333
13403
  `;
13334
- const EditableTextInput = (props) => {
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 }) => {
13335
13421
  const context = useContext(EditableTextContext);
13336
13422
  if (!context) throw new Error("EditableTextInput must be used within an EditableTextRoot context");
13337
13423
  const { isEditing, value, setValue, onValueCommit, setIsEditing, typographicVariant, submitMode, originalValue, onValueRevert, id, placeholder, minLines, maxLines, finalFocusEl } = context;
13338
13424
  const inputRef = useRef(null);
13425
+ const isEnteringRef = useRef(false);
13426
+ useEffect(() => {
13427
+ isEnteringRef.current = isEditing;
13428
+ }, [isEditing]);
13339
13429
  useEffect(() => {
13340
13430
  if (inputRef.current) {
13341
- if (isEditing) {
13431
+ if (isEditing && !supportsFieldSizing()) {
13342
13432
  const element = inputRef.current;
13343
13433
  const { style } = element;
13344
13434
  style.height = "0px";
13345
13435
  const { scrollHeight } = element;
13346
13436
  style.height = `${scrollHeight}px`;
13347
13437
  }
13348
- if (isEditing) inputRef.current.focus();
13438
+ if (isEditing) {
13439
+ inputRef.current.focus();
13440
+ isEnteringRef.current = false;
13441
+ }
13349
13442
  }
13350
13443
  }, [value, isEditing]);
13444
+ const isSingleLine = maxLines === 1;
13445
+ const fieldValue = isSingleLine ? toSingleLine(value) : value;
13351
13446
  const handleChange = (event) => {
13352
- setValue(event.target.value);
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);
13353
13466
  };
13354
13467
  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
- }
13364
13468
  if (event.key === "Escape") {
13365
13469
  event.preventDefault();
13366
13470
  setValue(originalValue);
13367
13471
  onValueRevert?.(originalValue);
13368
- setIsEditing(false);
13369
- setTimeout(() => {
13370
- const element = finalFocusEl?.();
13371
- if (element) element.focus();
13372
- }, 0);
13472
+ closeAndRestoreFocus();
13473
+ return;
13474
+ }
13475
+ if (isCommitEnter(event, submitMode)) {
13476
+ event.preventDefault();
13477
+ onValueCommit?.(fieldValue);
13478
+ closeAndRestoreFocus();
13479
+ return;
13373
13480
  }
13481
+ if (isSingleLine && event.key === "Enter") event.preventDefault();
13374
13482
  };
13375
13483
  const handleBlur = () => {
13376
13484
  if (submitMode === "blur" || submitMode === "both") {
13377
- onValueCommit?.(value);
13378
- setIsEditing(false);
13379
- setTimeout(() => {
13380
- const element = finalFocusEl?.();
13381
- if (element) element.focus();
13382
- }, 0);
13485
+ onValueCommit?.(fieldValue);
13486
+ closeAndRestoreFocus();
13383
13487
  }
13384
13488
  };
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
+ };
13385
13503
  if (!isEditing) return null;
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
- });
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
+ })] });
13405
13529
  };
13406
13530
  // src/components/EditableText/EditableTextLabel.tsx
13407
13531
  const EditableTextLabel = ({ ...props }) => {
@@ -17217,13 +17341,11 @@ const ThumbnailImage = ({ thumbnailImageType, thumbnailUrl }) => {
17217
17341
  if (thumbnailImageType === "wide") return /* @__PURE__ */ jsx(WideThumbnailImage, {
17218
17342
  alt: "",
17219
17343
  draggable: false,
17220
- role: "img",
17221
17344
  src: thumbnailUrl
17222
17345
  });
17223
17346
  return /* @__PURE__ */ jsx(SquareThumbnailImage, {
17224
17347
  alt: "",
17225
17348
  draggable: false,
17226
- role: "img",
17227
17349
  src: thumbnailUrl
17228
17350
  });
17229
17351
  };