@wistia/ui 0.14.10 → 0.14.11-beta.89cbbae6.bd1ca73

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.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*
3
- * @license @wistia/ui v0.14.10
3
+ * @license @wistia/ui v0.14.11-beta.89cbbae6.bd1ca73
4
4
  *
5
5
  * Copyright (c) 2024-2025, Wistia, Inc. and its affiliates.
6
6
  *
@@ -78,6 +78,14 @@ __export(index_exports, {
78
78
  DataCards: () => DataCards,
79
79
  Divider: () => Divider,
80
80
  EditableHeading: () => EditableHeading,
81
+ EditableText: () => EditableText,
82
+ EditableTextContext: () => EditableTextContext,
83
+ EditableTextDisplay: () => EditableTextDisplay,
84
+ EditableTextInput: () => EditableTextInput,
85
+ EditableTextLabel: () => EditableTextLabel,
86
+ EditableTextRoot: () => EditableTextRoot,
87
+ EditableTextSubmitButton: () => EditableTextSubmitButton,
88
+ EditableTextTrigger: () => EditableTextTrigger,
81
89
  Ellipsis: () => Ellipsis,
82
90
  FileAmountLimitValidator: () => import_validators.FileAmountLimitValidator,
83
91
  FileSizeValidator: () => import_validators.FileSizeValidator,
@@ -11338,6 +11346,7 @@ var Input = (0, import_react47.forwardRef)(
11338
11346
  {
11339
11347
  $fullWidth: fullWidth,
11340
11348
  $monospace: monospace,
11349
+ "data-wui-input-container": true,
11341
11350
  children: [
11342
11351
  leftIconToDisplay ?? null,
11343
11352
  type === "multiline" ? /* @__PURE__ */ (0, import_jsx_runtime247.jsx)(
@@ -13690,7 +13699,6 @@ var Menu = (0, import_react64.forwardRef)(
13690
13699
  isOpen,
13691
13700
  triggerProps = {},
13692
13701
  onOpenChange,
13693
- onInteractOutside,
13694
13702
  ...props
13695
13703
  }, ref) => {
13696
13704
  const contextValue = (0, import_react64.useMemo)(() => ({ compact }), [compact]);
@@ -17018,6 +17026,443 @@ var ContextMenu = ({
17018
17026
  }
17019
17027
  ) : null;
17020
17028
  };
17029
+
17030
+ // src/components/EditableText/EditableTextDisplay.tsx
17031
+ var import_react92 = require("react");
17032
+ var import_styled_components123 = __toESM(require("styled-components"));
17033
+
17034
+ // src/components/EditableText/EditableTextRoot.tsx
17035
+ var import_react91 = require("react");
17036
+ var import_type_guards72 = require("@wistia/type-guards");
17037
+ var import_styled_components121 = __toESM(require("styled-components"));
17038
+ var import_jsx_runtime317 = require("react/jsx-runtime");
17039
+ var StyledEditableTextRoot = import_styled_components121.default.div`
17040
+ display: contents;
17041
+
17042
+ /* Hide display components when editing */
17043
+ &[data-wui-editable-text-state='editing'] [data-wui-editable-text-display] {
17044
+ display: none;
17045
+ }
17046
+
17047
+ /* Hide input when not editing */
17048
+
17049
+ /* This is super hacky, not sure how to do this better */
17050
+ &[data-wui-editable-text-state='idle'] [data-wui-input-container],
17051
+ &[data-wui-editable-text-state='read-only'] [data-wui-input-container] {
17052
+ display: none;
17053
+ }
17054
+
17055
+ /* Hide trigger when editing or read-only */
17056
+ &[data-wui-editable-text-state='editing'] [data-wui-editable-text-trigger],
17057
+ &[data-wui-editable-text-state='read-only'] [data-wui-editable-text-trigger] {
17058
+ display: none;
17059
+ }
17060
+
17061
+ /* Hide submit button when not editing */
17062
+ &[data-wui-editable-text-state='idle'] [data-wui-editable-text-submit],
17063
+ &[data-wui-editable-text-state='read-only'] [data-wui-editable-text-submit] {
17064
+ display: none;
17065
+ }
17066
+
17067
+ /* Hide cancel button when not editing */
17068
+ &[data-wui-editable-text-state='idle'] [data-wui-editable-text-cancel],
17069
+ &[data-wui-editable-text-state='read-only'] [data-wui-editable-text-cancel] {
17070
+ display: none;
17071
+ }
17072
+
17073
+ [data-wui-editable-text-display='placeholder'] {
17074
+ color: var(--wui-color-text-secondary);
17075
+ }
17076
+ `;
17077
+ var EditableTextContext = (0, import_react91.createContext)(null);
17078
+ var EditableTextRoot = ({
17079
+ children,
17080
+ defaultValue = "",
17081
+ value: controlledValue,
17082
+ onValueChange,
17083
+ onValueCommit,
17084
+ onValueRevert,
17085
+ onEditingChange,
17086
+ typographicVariant = "body2",
17087
+ submitMode = "both",
17088
+ readOnly = false,
17089
+ id,
17090
+ label,
17091
+ placeholder = "Click to edit this text",
17092
+ minLines = 1,
17093
+ maxLines = "infinity",
17094
+ finalFocusEl,
17095
+ ...props
17096
+ }) => {
17097
+ const isControlled = controlledValue !== void 0;
17098
+ const [internalValue, setInternalValue] = (0, import_react91.useState)(defaultValue);
17099
+ const [originalValue, setOriginalValue] = (0, import_react91.useState)(defaultValue);
17100
+ const [isEditing, setIsEditing] = (0, import_react91.useState)(false);
17101
+ const value = isControlled ? controlledValue : internalValue;
17102
+ const generatedId = (0, import_react91.useId)();
17103
+ const computedId = (0, import_type_guards72.isNonEmptyString)(id) ? id : `wistia-ui-editable-text-${generatedId}`;
17104
+ const handleSetIsEditing = (0, import_react91.useCallback)(
17105
+ (editing) => {
17106
+ if (editing && !isEditing) {
17107
+ setOriginalValue(value);
17108
+ }
17109
+ setIsEditing(editing);
17110
+ onEditingChange?.(editing);
17111
+ },
17112
+ [isEditing, value, onEditingChange]
17113
+ );
17114
+ const setValue = (0, import_react91.useCallback)(
17115
+ (newValue) => {
17116
+ if (!isControlled) {
17117
+ setInternalValue(newValue);
17118
+ }
17119
+ onValueChange?.(newValue);
17120
+ },
17121
+ [isControlled, onValueChange]
17122
+ );
17123
+ const context = (0, import_react91.useMemo)(() => {
17124
+ return {
17125
+ isEditing,
17126
+ setIsEditing: handleSetIsEditing,
17127
+ value,
17128
+ setValue,
17129
+ originalValue,
17130
+ onValueCommit,
17131
+ onValueRevert,
17132
+ typographicVariant,
17133
+ submitMode,
17134
+ readOnly,
17135
+ id: computedId,
17136
+ label,
17137
+ placeholder,
17138
+ minLines,
17139
+ maxLines,
17140
+ finalFocusEl
17141
+ };
17142
+ }, [
17143
+ isEditing,
17144
+ handleSetIsEditing,
17145
+ value,
17146
+ setValue,
17147
+ originalValue,
17148
+ onValueCommit,
17149
+ onValueRevert,
17150
+ typographicVariant,
17151
+ submitMode,
17152
+ readOnly,
17153
+ computedId,
17154
+ label,
17155
+ placeholder,
17156
+ minLines,
17157
+ maxLines,
17158
+ finalFocusEl
17159
+ ]);
17160
+ const getState = () => {
17161
+ if (readOnly) {
17162
+ return "read-only";
17163
+ }
17164
+ if (isEditing) {
17165
+ return "editing";
17166
+ }
17167
+ return "idle";
17168
+ };
17169
+ return /* @__PURE__ */ (0, import_jsx_runtime317.jsx)(
17170
+ StyledEditableTextRoot,
17171
+ {
17172
+ "data-wui-editable-text-root": true,
17173
+ "data-wui-editable-text-state": getState(),
17174
+ ...props,
17175
+ children: /* @__PURE__ */ (0, import_jsx_runtime317.jsx)(EditableTextContext.Provider, { value: context, children })
17176
+ }
17177
+ );
17178
+ };
17179
+
17180
+ // src/private/helpers/getTypographicStyles/getTypographicStyles.ts
17181
+ var import_styled_components122 = require("styled-components");
17182
+ var typographicVariantStyleMap = { ...variantStyleMap2, ...variantStyleMap };
17183
+ var getTypographicStyles = (variant) => {
17184
+ return import_styled_components122.css`
17185
+ ${typographicVariantStyleMap[variant]}
17186
+ font-family: var(--font-family);
17187
+ font-size: var(--font-size);
17188
+ font-weight: var(--font-weight);
17189
+ line-height: var(--line-height);
17190
+ `;
17191
+ };
17192
+ var typographicVariantElementMap = { ...variantElementMap2, ...variantElementMap };
17193
+ var getDefaultTypographicElement = (variant) => {
17194
+ return typographicVariantElementMap[variant] ?? "span";
17195
+ };
17196
+
17197
+ // src/components/EditableText/EditableTextDisplay.tsx
17198
+ var import_jsx_runtime318 = require("react/jsx-runtime");
17199
+ var StyledEditableTextDisplay = import_styled_components123.default.div`
17200
+ ${({ $typographicVariant }) => getTypographicStyles($typographicVariant)}
17201
+ padding: var(--wui-space-01);
17202
+ border-radius: var(--wui-border-radius-01);
17203
+ margin: 0;
17204
+ transition: all var(--wui-motion-duration-02) var(--wui-motion-ease);
17205
+
17206
+ &:has(button) {
17207
+ user-select: none;
17208
+ cursor: pointer;
17209
+
17210
+ &:hover,
17211
+ &:focus-within {
17212
+ background-color: var(--wui-color-bg-surface-hover);
17213
+ }
17214
+ }
17215
+ `;
17216
+ var EditableTextDisplayComponent = (0, import_react92.forwardRef)(
17217
+ ({ asTrigger, renderAs, ...props }, ref) => {
17218
+ const context = (0, import_react92.useContext)(EditableTextContext);
17219
+ if (!context) {
17220
+ throw new Error("EditableTextDisplay must be used within an EditableTextRoot context");
17221
+ }
17222
+ const { value, typographicVariant, setIsEditing, placeholder } = context;
17223
+ const triggerButtonRef = (0, import_react92.useRef)(null);
17224
+ const handleTriggerClick = () => {
17225
+ setIsEditing(true);
17226
+ };
17227
+ const elementType = renderAs ?? getDefaultTypographicElement(typographicVariant);
17228
+ const displayText = value.length > 0 ? value : placeholder;
17229
+ const isPlaceholderVisible = value.length === 0 && !!placeholder;
17230
+ if (asTrigger && !context.readOnly) {
17231
+ return /* @__PURE__ */ (0, import_jsx_runtime318.jsx)(ClickRegion, { targetRef: triggerButtonRef, children: /* @__PURE__ */ (0, import_jsx_runtime318.jsxs)(
17232
+ StyledEditableTextDisplay,
17233
+ {
17234
+ ref,
17235
+ $typographicVariant: typographicVariant,
17236
+ as: elementType,
17237
+ "data-wui-editable-text-display": isPlaceholderVisible ? "placeholder" : "value",
17238
+ ...props,
17239
+ children: [
17240
+ displayText,
17241
+ /* @__PURE__ */ (0, import_jsx_runtime318.jsx)(
17242
+ "button",
17243
+ {
17244
+ ref: triggerButtonRef,
17245
+ onClick: handleTriggerClick,
17246
+ style: { ...visuallyHiddenStyle },
17247
+ type: "button",
17248
+ children: "Edit text"
17249
+ }
17250
+ )
17251
+ ]
17252
+ }
17253
+ ) });
17254
+ }
17255
+ return /* @__PURE__ */ (0, import_jsx_runtime318.jsx)(
17256
+ StyledEditableTextDisplay,
17257
+ {
17258
+ ref,
17259
+ $typographicVariant: typographicVariant,
17260
+ as: elementType,
17261
+ "data-placeholder-visible": isPlaceholderVisible || void 0,
17262
+ "data-wui-editable-text-display": true,
17263
+ ...props,
17264
+ children: displayText
17265
+ }
17266
+ );
17267
+ }
17268
+ );
17269
+ EditableTextDisplayComponent.displayName = "EditableTextDisplay_UI";
17270
+ var EditableTextDisplay = makePolymorphic(
17271
+ EditableTextDisplayComponent
17272
+ );
17273
+
17274
+ // src/components/EditableText/EditableTextInput.tsx
17275
+ var import_react93 = require("react");
17276
+ var import_styled_components124 = __toESM(require("styled-components"));
17277
+ var import_jsx_runtime319 = require("react/jsx-runtime");
17278
+ var StyledInput3 = (0, import_styled_components124.default)(Input)`
17279
+ && {
17280
+ --min-lines: ${({ $minLines }) => $minLines};
17281
+ --max-lines: ${({ $maxLines }) => $maxLines};
17282
+
17283
+ min-height: calc(var(--min-lines) * 1lh + calc(var(--wui-space-01) * 2));
17284
+ max-height: calc(var(--max-lines) * 1lh + calc(var(--wui-space-01) * 2));
17285
+ ${({ $typographicVariant }) => getTypographicStyles($typographicVariant)}
17286
+ padding: var(--wui-space-01);
17287
+ border-radius: var(--wui-border-radius-01);
17288
+ background-color: var(--wui-color-bg-surface);
17289
+ }
17290
+ `;
17291
+ var EditableTextInput = (props) => {
17292
+ const context = (0, import_react93.useContext)(EditableTextContext);
17293
+ if (!context) {
17294
+ throw new Error("EditableTextInput must be used within an EditableTextRoot context");
17295
+ }
17296
+ const {
17297
+ isEditing,
17298
+ value,
17299
+ setValue,
17300
+ onValueCommit,
17301
+ setIsEditing,
17302
+ typographicVariant,
17303
+ submitMode,
17304
+ originalValue,
17305
+ onValueRevert,
17306
+ id,
17307
+ placeholder,
17308
+ minLines,
17309
+ maxLines,
17310
+ finalFocusEl
17311
+ } = context;
17312
+ const inputRef = (0, import_react93.useRef)(null);
17313
+ (0, import_react93.useEffect)(() => {
17314
+ if (inputRef.current) {
17315
+ if (isEditing) {
17316
+ const element = inputRef.current;
17317
+ const { style } = element;
17318
+ style.height = "0px";
17319
+ const { scrollHeight } = element;
17320
+ style.height = `${scrollHeight}px`;
17321
+ }
17322
+ if (isEditing) {
17323
+ inputRef.current.focus();
17324
+ }
17325
+ }
17326
+ }, [value, isEditing]);
17327
+ const handleChange = (event) => {
17328
+ setValue(event.target.value);
17329
+ };
17330
+ const handleKeyDown = (event) => {
17331
+ if ((submitMode === "enter" || submitMode === "both") && event.key === "Enter" && !event.shiftKey) {
17332
+ event.preventDefault();
17333
+ onValueCommit?.(value);
17334
+ setIsEditing(false);
17335
+ setTimeout(() => {
17336
+ const element = finalFocusEl?.();
17337
+ if (element) {
17338
+ element.focus();
17339
+ }
17340
+ }, 0);
17341
+ }
17342
+ if (event.key === "Escape") {
17343
+ event.preventDefault();
17344
+ setValue(originalValue);
17345
+ onValueRevert?.(originalValue);
17346
+ setIsEditing(false);
17347
+ setTimeout(() => {
17348
+ const element = finalFocusEl?.();
17349
+ if (element) {
17350
+ element.focus();
17351
+ }
17352
+ }, 0);
17353
+ }
17354
+ };
17355
+ const handleBlur2 = () => {
17356
+ if (submitMode === "blur" || submitMode === "both") {
17357
+ onValueCommit?.(value);
17358
+ setIsEditing(false);
17359
+ setTimeout(() => {
17360
+ const element = finalFocusEl?.();
17361
+ if (element) {
17362
+ element.focus();
17363
+ }
17364
+ }, 0);
17365
+ }
17366
+ };
17367
+ return /* @__PURE__ */ (0, import_jsx_runtime319.jsx)(
17368
+ StyledInput3,
17369
+ {
17370
+ ref: inputRef,
17371
+ $maxLines: maxLines,
17372
+ $minLines: minLines,
17373
+ $typographicVariant: typographicVariant,
17374
+ "data-wui-editable-text-input": true,
17375
+ id,
17376
+ onBlur: handleBlur2,
17377
+ onChange: handleChange,
17378
+ onKeyDown: handleKeyDown,
17379
+ placeholder,
17380
+ type: "multiline",
17381
+ value,
17382
+ ...props
17383
+ }
17384
+ );
17385
+ };
17386
+
17387
+ // src/components/EditableText/EditableTextLabel.tsx
17388
+ var import_react94 = require("react");
17389
+ var import_jsx_runtime320 = require("react/jsx-runtime");
17390
+ var EditableTextLabel = ({ disabled, ...props }) => {
17391
+ const context = (0, import_react94.useContext)(EditableTextContext);
17392
+ if (!context) {
17393
+ throw new Error("EditableTextLabel must be used within an EditableTextRoot context");
17394
+ }
17395
+ const { id, readOnly, label } = context;
17396
+ return /* @__PURE__ */ (0, import_jsx_runtime320.jsx)(
17397
+ Label,
17398
+ {
17399
+ disabled: disabled ?? readOnly,
17400
+ htmlFor: id,
17401
+ ...props,
17402
+ children: label
17403
+ }
17404
+ );
17405
+ };
17406
+
17407
+ // src/components/EditableText/EditableText.tsx
17408
+ var import_jsx_runtime321 = require("react/jsx-runtime");
17409
+ var EditableText = ({ hideLabel = true, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime321.jsxs)(EditableTextRoot, { ...props, children: [
17410
+ /* @__PURE__ */ (0, import_jsx_runtime321.jsx)(EditableTextLabel, { screenReaderOnly: hideLabel }),
17411
+ /* @__PURE__ */ (0, import_jsx_runtime321.jsx)(EditableTextInput, {}),
17412
+ /* @__PURE__ */ (0, import_jsx_runtime321.jsx)(EditableTextDisplay, { asTrigger: true })
17413
+ ] });
17414
+ EditableText.displayName = "EditableText_UI";
17415
+
17416
+ // src/components/EditableText/EditableTextSubmitButton.tsx
17417
+ var import_react95 = require("react");
17418
+ var EditableTextSubmitButton = ({
17419
+ children
17420
+ }) => {
17421
+ const context = (0, import_react95.useContext)(EditableTextContext);
17422
+ if (!context) {
17423
+ throw new Error("EditableTextSubmitButton must be used within an EditableTextRoot context");
17424
+ }
17425
+ const { setIsEditing, value, onValueCommit, finalFocusEl } = context;
17426
+ const handleClick = () => {
17427
+ onValueCommit?.(value);
17428
+ setIsEditing(false);
17429
+ setTimeout(() => {
17430
+ const element = finalFocusEl?.();
17431
+ if (element) {
17432
+ element.focus();
17433
+ }
17434
+ }, 0);
17435
+ };
17436
+ const onlyChild = import_react95.Children.only(children);
17437
+ const triggerProps = {
17438
+ onClick: handleClick,
17439
+ "data-wui-editable-text-submit": true
17440
+ };
17441
+ return (0, import_react95.cloneElement)(onlyChild, triggerProps);
17442
+ };
17443
+
17444
+ // src/components/EditableText/EditableTextTrigger.tsx
17445
+ var import_react96 = require("react");
17446
+ var EditableTextTrigger = ({
17447
+ children,
17448
+ ...props
17449
+ }) => {
17450
+ const context = (0, import_react96.useContext)(EditableTextContext);
17451
+ if (!context) {
17452
+ throw new Error("EditableTextTrigger must be used within an EditableTextRoot context");
17453
+ }
17454
+ const { setIsEditing } = context;
17455
+ const handleClick = () => {
17456
+ setIsEditing(true);
17457
+ };
17458
+ const onlyChild = import_react96.Children.only(children);
17459
+ const triggerProps = {
17460
+ onClick: handleClick,
17461
+ "data-wui-editable-text-trigger": true,
17462
+ ...props
17463
+ };
17464
+ return (0, import_react96.cloneElement)(onlyChild, triggerProps);
17465
+ };
17021
17466
  // Annotate the CommonJS export names for ESM import in node:
17022
17467
  0 && (module.exports = {
17023
17468
  ActionButton,
@@ -17059,6 +17504,14 @@ var ContextMenu = ({
17059
17504
  DataCards,
17060
17505
  Divider,
17061
17506
  EditableHeading,
17507
+ EditableText,
17508
+ EditableTextContext,
17509
+ EditableTextDisplay,
17510
+ EditableTextInput,
17511
+ EditableTextLabel,
17512
+ EditableTextRoot,
17513
+ EditableTextSubmitButton,
17514
+ EditableTextTrigger,
17062
17515
  Ellipsis,
17063
17516
  FileAmountLimitValidator,
17064
17517
  FileSizeValidator,