@uniformdev/mesh-sdk-react 18.35.1-alpha.12 → 18.35.1-alpha.26

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.d.ts CHANGED
@@ -7,6 +7,7 @@ import { DataVariableDefinition, DataResourceVariables } from '@uniformdev/canva
7
7
  import * as _uniformdev_mesh_sdk from '@uniformdev/mesh-sdk';
8
8
  import { MeshLocation, SetValueOptions, DataSourceLocationValue, DataTypeLocationValue } from '@uniformdev/mesh-sdk';
9
9
  export * from '@uniformdev/mesh-sdk';
10
+ import { Emitter } from 'mitt';
10
11
  import { BadgeThemeProps, InputSelectProps } from '@uniformdev/design-system';
11
12
  export { AddListButton, AddListButtonProps, Button, ButtonProps, Callout, CalloutProps, Heading, HeadingProps, Input, InputComboBox, InputComboBoxProps, InputKeywordSearch, InputProps, InputSelect, InputToggle, InputToggleProps, Label, LabelProps, LoadingIndicator, LoadingOverlay, Menu, MenuItem, MenuItemProps, MenuProps, ParameterGroup, ParameterGroupProps, ParameterImage, ParameterImageInner, ParameterImageProps, ParameterInput, ParameterInputInner, ParameterInputProps, ParameterLabel, ParameterLabelProps, ParameterMenuButton, ParameterMenuButtonProps, ParameterSelect, ParameterSelectInner, ParameterSelectProps, ParameterShell, ParameterShellContext, ParameterShellProps, ParameterTextarea, ParameterTextareaInner, ParameterTextareaProps, ParameterToggle, ParameterToggleInner, ParameterToggleProps, ScrollableList, ScrollableListItem, ScrollableListItemProps, ScrollableListProps, Switch, SwitchProps, Textarea, TextareaProps, Theme, ThemeProps, useParameterShell } from '@uniformdev/design-system';
12
13
 
@@ -440,11 +441,16 @@ type InputVariablesProps = {
440
441
  onChange: (newValue: string) => void;
441
442
  /** called when the field is pasted into */
442
443
  onPaste?: (newValue: string) => void;
444
+ /** Disables using variables in the input */
443
445
  disableVariables?: boolean;
444
- onVariableClick: (selectedVariable: string) => void;
446
+ /** Enables adding variables from the menu */
445
447
  showAddVariableMenuOption?: boolean;
448
+ /** Value prefix to trigger variable menu */
449
+ variablePrefix?: string;
450
+ /** Value suffix to use for variable values */
451
+ variableSuffix?: string;
446
452
  };
447
- declare function InputVariables({ 'aria-label': ariaLabel, value, onChange, onPaste, onVariableClick, showAddVariableMenuOption, ...inputProps }: InputVariablesProps): _emotion_react_types_jsx_namespace.EmotionJSX.Element;
453
+ declare function InputVariables({ 'aria-label': ariaLabel, value, disableVariables, onChange, onPaste, showAddVariableMenuOption, variablePrefix, variableSuffix, ...inputProps }: InputVariablesProps): _emotion_react_types_jsx_namespace.EmotionJSX.Element;
448
454
 
449
455
  type DataVariableDefinitionWithName = {
450
456
  name: string;
@@ -479,9 +485,18 @@ type VariablesAction = {
479
485
  type: 'reorder';
480
486
  result: Record<string, DataVariableDefinitionWithName>;
481
487
  };
488
+ type VariablesEvents = {
489
+ update: string;
490
+ };
482
491
  type VariablesContext = {
492
+ /** Dispatch update events to the variables */
483
493
  dispatch: (event: VariablesAction) => void;
494
+ /** The current variables value */
484
495
  variables: Readonly<Record<string, DataVariableDefinition>>;
496
+ /** Whether the context is editing a variable value currently */
497
+ isEditing: boolean;
498
+ /** Add event handles (don't forget to unhook) */
499
+ events: Emitter<VariablesEvents>;
485
500
  };
486
501
  declare function VariablesProvider({ value, onChange, editVariableComponent, children, }: VariablesProviderProps): _emotion_react_types_jsx_namespace.EmotionJSX.Element;
487
502
  declare function useVariables(): VariablesContext;
@@ -982,7 +997,7 @@ declare function RequestUrl(): _emotion_react_types_jsx_namespace.EmotionJSX.Ele
982
997
  * Editor to modify the current URL of the request
983
998
  * Note: entering query string parameters automatically converts them and syncs the request state with them
984
999
  */
985
- declare function RequestUrlInput(props: Omit<InputVariablesProps, 'value' | 'onChange' | 'onVariableClick'>): _emotion_react_types_jsx_namespace.EmotionJSX.Element;
1000
+ declare function RequestUrlInput(props: Omit<InputVariablesProps, 'value' | 'onChange'>): _emotion_react_types_jsx_namespace.EmotionJSX.Element;
986
1001
 
987
1002
  declare function urlEncodeRequestUrl(url: string, varValues?: Record<string, DataVariableDefinition>): string;
988
1003
  declare function urlEncodeRequestParameter(parameter: RequestParameter, varValues?: Record<string, DataVariableDefinition>): RequestParameter;
@@ -1026,4 +1041,4 @@ declare function useUniformMeshSdk(): _uniformdev_mesh_sdk.UniformMeshSDK;
1026
1041
  */
1027
1042
  declare function createLocationValidator<TSetValue>(setValue: SetLocationValueDispatch<TSetValue>, validate: (newValue: TSetValue, currentResult: SetValueOptions | undefined) => SetValueOptions): SetLocationValueDispatch<TSetValue>;
1028
1043
 
1029
- export { BaseRequestData, Brand, DamItem, DamSelectedItem, DamSelectedItemProps, DataRefreshButton, DataRefreshButtonProps, DataResourceVariableRendererProps, DataResourceVariablesList, DataResourceVariablesListProps, DataSourceEditor, DataSourceEditorProps, DataTypeEditor, DataTypeEditorProps, DataVariableDefinitionWithName, DefaultSearchRow, DefaultSelectedItem, DispatchResult, EntrySearch, EntrySearchContentType, EntrySearchProps, EntrySearchQueryOptions, EntrySearchResult, EntrySearchRowProps, EntrySearchSelectedItemProps, GetProductOptions, GetProductsOptions, index as Icons, InputToken, InputVariables, InputVariablesProps, ItemListProps, LinkButton, MeshApp, MeshAppProps, NoResultsProps, ObjectSearchContainer, ObjectSearchContainerProps, ObjectSearchContextProps, ObjectSearchFilter, ObjectSearchFilterContainer, ObjectSearchFilterContainerProps, ObjectSearchFilterProps, ObjectSearchListItem, ObjectSearchListItemLoadingSkeleton, ObjectSearchListItemProps, ObjectSearchProvider, ObjectSearchProviderProps, ObjectSearchResultItem, ObjectSearchResultItemButton, ObjectSearchResultItemButtonProps, ObjectSearchResultItemProps, ObjectSearchResultList, ObjectSearchResultListProps, ProductCategory, ProductDynamicSelectorValue, ProductPreviewList, ProductQuery, ProductQueryCategory, ProductQueryContext, ProductQueryContextValue, ProductQueryProps, ProductSearch, ProductSearchContext, ProductSearchContextValue, ProductSearchProps, ProductSearchResult, ProductSearchResults, ProductSearchRow, ProductSelectedItem, QueryFilter, QueryFilterProps, QueryFilterSearchProps, RequestAction, RequestBody, RequestContext, RequestData, RequestHeaders, RequestMethodSelect, RequestParameter, RequestParameters, RequestParametersProps, RequestProvider, RequestProviderProps, RequestTypeContainer, RequestTypeContainerProps, RequestUrl, RequestUrlInput, ResolvableLoadingValue, SearchQueryProps, SelectedItemProps, SelectionField, SelectionFieldValue, SetLocationValueDispatch, SetLocationValueFunction, TextVariableRenderer, VariableEditor, VariableEditorProps, VariablesAction, VariablesContext, VariablesList, VariablesProvider, VariablesProviderProps, badgeIcon, createLocationValidator, damSelectItemImage, damSelectedItemContainer, damSelectedItemCopy, damSelectedItemDetails, damSelectedItemIcon, damSelectedItemInfoBtn, damSelectedItemInner, damSelectedItemLinkBtn, damSelectedItemLinkContainer, damSelectedItemMediaContainer, damSelectedItemPopover, damSelectedItemPopoverLabel, damSelectedItemSmallText, damSelectedItemTitle, draggableContainer, draggableIcon, draggableIconOffset, draggableIconWrapper, entrySearchBtn, entrySearchConfig, entrySearchConfigHidden, entrySearchLoadMoreBtn, entrySearchResultList, entrySearchSelectIcon, entrySearchSelectImg, entrySearchSelectInput, entrySearchSelectOption, entrySearchWrapper, productSearchRowActiveIcon, productSearchRowCategory, productSearchRowContainer, productSearchRowContent, productSearchRowContentActive, productSearchRowDetails, productSearchRowTitle, productSelectedItemContainer, productSelectedItemContent, productSelectedItemDetails, productSelectedItemIcon, productSelectedItemImage, productSelectedItemLinkContainer, productedSelectedItemLinkBtn, productedSelectedItemSmallText, searchRowBtn, searchRowContainer, searchRowContainerActive, searchRowContainerWithPopover, searchRowPopover, searchRowText, searchRowTextSmall, selectItemLinkBtn, selectItemLinkContainer, selectItemPopover, selectItemPopoverLabel, selectItemSmallText, selectedItemContainer, selectedItemCopy, selectedItemDetails, selectedItemIcon, selectedItemInner, selectedItemTitle, urlEncodeRequestParameter, urlEncodeRequestUrl, useMeshLocation, useObjectSearchContext, useProductQueryContext, useProductSearchContext, useRequest, useRequestHeader, useRequestParameter, useUniformMeshSdk, useVariables, variablesToList };
1044
+ export { BaseRequestData, Brand, DamItem, DamSelectedItem, DamSelectedItemProps, DataRefreshButton, DataRefreshButtonProps, DataResourceVariableRendererProps, DataResourceVariablesList, DataResourceVariablesListProps, DataSourceEditor, DataSourceEditorProps, DataTypeEditor, DataTypeEditorProps, DataVariableDefinitionWithName, DefaultSearchRow, DefaultSelectedItem, DispatchResult, EntrySearch, EntrySearchContentType, EntrySearchProps, EntrySearchQueryOptions, EntrySearchResult, EntrySearchRowProps, EntrySearchSelectedItemProps, GetProductOptions, GetProductsOptions, index as Icons, InputToken, InputVariables, InputVariablesProps, ItemListProps, LinkButton, MeshApp, MeshAppProps, NoResultsProps, ObjectSearchContainer, ObjectSearchContainerProps, ObjectSearchContextProps, ObjectSearchFilter, ObjectSearchFilterContainer, ObjectSearchFilterContainerProps, ObjectSearchFilterProps, ObjectSearchListItem, ObjectSearchListItemLoadingSkeleton, ObjectSearchListItemProps, ObjectSearchProvider, ObjectSearchProviderProps, ObjectSearchResultItem, ObjectSearchResultItemButton, ObjectSearchResultItemButtonProps, ObjectSearchResultItemProps, ObjectSearchResultList, ObjectSearchResultListProps, ProductCategory, ProductDynamicSelectorValue, ProductPreviewList, ProductQuery, ProductQueryCategory, ProductQueryContext, ProductQueryContextValue, ProductQueryProps, ProductSearch, ProductSearchContext, ProductSearchContextValue, ProductSearchProps, ProductSearchResult, ProductSearchResults, ProductSearchRow, ProductSelectedItem, QueryFilter, QueryFilterProps, QueryFilterSearchProps, RequestAction, RequestBody, RequestContext, RequestData, RequestHeaders, RequestMethodSelect, RequestParameter, RequestParameters, RequestParametersProps, RequestProvider, RequestProviderProps, RequestTypeContainer, RequestTypeContainerProps, RequestUrl, RequestUrlInput, ResolvableLoadingValue, SearchQueryProps, SelectedItemProps, SelectionField, SelectionFieldValue, SetLocationValueDispatch, SetLocationValueFunction, TextVariableRenderer, VariableEditor, VariableEditorProps, VariablesAction, VariablesContext, VariablesEvents, VariablesList, VariablesProvider, VariablesProviderProps, badgeIcon, createLocationValidator, damSelectItemImage, damSelectedItemContainer, damSelectedItemCopy, damSelectedItemDetails, damSelectedItemIcon, damSelectedItemInfoBtn, damSelectedItemInner, damSelectedItemLinkBtn, damSelectedItemLinkContainer, damSelectedItemMediaContainer, damSelectedItemPopover, damSelectedItemPopoverLabel, damSelectedItemSmallText, damSelectedItemTitle, draggableContainer, draggableIcon, draggableIconOffset, draggableIconWrapper, entrySearchBtn, entrySearchConfig, entrySearchConfigHidden, entrySearchLoadMoreBtn, entrySearchResultList, entrySearchSelectIcon, entrySearchSelectImg, entrySearchSelectInput, entrySearchSelectOption, entrySearchWrapper, productSearchRowActiveIcon, productSearchRowCategory, productSearchRowContainer, productSearchRowContent, productSearchRowContentActive, productSearchRowDetails, productSearchRowTitle, productSelectedItemContainer, productSelectedItemContent, productSelectedItemDetails, productSelectedItemIcon, productSelectedItemImage, productSelectedItemLinkContainer, productedSelectedItemLinkBtn, productedSelectedItemSmallText, searchRowBtn, searchRowContainer, searchRowContainerActive, searchRowContainerWithPopover, searchRowPopover, searchRowText, searchRowTextSmall, selectItemLinkBtn, selectItemLinkContainer, selectItemPopover, selectItemPopoverLabel, selectItemSmallText, selectedItemContainer, selectedItemCopy, selectedItemDetails, selectedItemIcon, selectedItemInner, selectedItemTitle, urlEncodeRequestParameter, urlEncodeRequestUrl, useMeshLocation, useObjectSearchContext, useProductQueryContext, useProductSearchContext, useRequest, useRequestHeader, useRequestParameter, useUniformMeshSdk, useVariables, variablesToList };
package/dist/index.esm.js CHANGED
@@ -2727,9 +2727,35 @@ function useMeshLocation(expectedLocation) {
2727
2727
  import { Input as Input3 } from "@uniformdev/design-system";
2728
2728
  import * as React11 from "react";
2729
2729
 
2730
+ // src/components/Variables/insertVariableIntoText.ts
2731
+ function insertVariableIntoText({
2732
+ variableName: variableName2,
2733
+ variablePrefix,
2734
+ variableSuffix = "",
2735
+ value,
2736
+ selectionStart = null,
2737
+ selectionEnd = null
2738
+ }) {
2739
+ const variableExpression = `${variablePrefix}${variableName2}${variableSuffix}`;
2740
+ if (selectionStart !== null && selectionEnd !== null && selectionStart !== selectionEnd) {
2741
+ return `${value.substring(0, selectionStart)}${variableExpression}${value.substring(selectionEnd)}`;
2742
+ }
2743
+ const hasCursorPosition = selectionStart !== null;
2744
+ let startOffset = 0;
2745
+ if (hasCursorPosition && value.substring(selectionStart - variablePrefix.length, selectionStart) === variablePrefix) {
2746
+ startOffset = variablePrefix.length;
2747
+ }
2748
+ if (hasCursorPosition) {
2749
+ return `${value.substring(0, selectionStart - startOffset)}${variableExpression}${value.substring(
2750
+ selectionStart
2751
+ )}`;
2752
+ }
2753
+ return `${value}${variableExpression}`;
2754
+ }
2755
+
2730
2756
  // src/components/Variables/InsertVariableMenu.tsx
2731
2757
  import { Icon as Icon5, Menu as Menu2, MenuItem as MenuItem2, MenuItemSeparator } from "@uniformdev/design-system";
2732
- import { useEffect as useEffect5, useRef as useRef8 } from "react";
2758
+ import { useEffect as useEffect6, useRef as useRef8, useState as useState8 } from "react";
2733
2759
 
2734
2760
  // src/components/Variables/styles/InsertVariableMenu.styles.ts
2735
2761
  import { css as css18 } from "@emotion/react";
@@ -2759,7 +2785,11 @@ var variablesTipText = css18`
2759
2785
  padding: 0 var(--spacing-sm);
2760
2786
  `;
2761
2787
 
2788
+ // src/components/Variables/useOnVariableUpdated.ts
2789
+ import { useEffect as useEffect5 } from "react";
2790
+
2762
2791
  // src/components/Variables/VariablesProvider.tsx
2792
+ import mitt from "mitt";
2763
2793
  import * as React10 from "react";
2764
2794
 
2765
2795
  // src/components/Variables/VariableEditor.tsx
@@ -2844,6 +2874,7 @@ function VariablesProvider({
2844
2874
  children
2845
2875
  }) {
2846
2876
  const [editing, setEditing] = React10.useState();
2877
+ const events = React10.useMemo(() => mitt(), []);
2847
2878
  const Editor = editVariableComponent != null ? editVariableComponent : VariableEditor;
2848
2879
  const contextValue = {
2849
2880
  dispatch: (event) => {
@@ -2865,7 +2896,9 @@ function VariablesProvider({
2865
2896
  throw new Error(`Unknown event ${JSON.stringify(event)}`);
2866
2897
  }
2867
2898
  },
2868
- variables: value
2899
+ variables: value,
2900
+ isEditing: typeof editing !== "undefined",
2901
+ events
2869
2902
  };
2870
2903
  return /* @__PURE__ */ jsxs17(VariablesContext.Provider, { value: contextValue, children: [
2871
2904
  children,
@@ -2876,6 +2909,7 @@ function VariablesProvider({
2876
2909
  setEditing(void 0);
2877
2910
  const { name, ...varValue } = val;
2878
2911
  onChange({ ...value, [name]: varValue });
2912
+ events.emit("update", name);
2879
2913
  },
2880
2914
  onCancel: () => setEditing(void 0),
2881
2915
  variable: editing
@@ -2891,51 +2925,106 @@ function useVariables() {
2891
2925
  return context;
2892
2926
  }
2893
2927
 
2928
+ // src/components/Variables/useOnVariableUpdated.ts
2929
+ function useOnVariableUpdated(fn, disabled) {
2930
+ const { variables, events } = useVariables();
2931
+ useEffect5(() => {
2932
+ if (disabled) {
2933
+ return;
2934
+ }
2935
+ events.on("update", fn);
2936
+ return () => events.off("update", fn);
2937
+ }, [disabled, events, fn, variables]);
2938
+ }
2939
+
2940
+ // src/components/Variables/variablesToList.ts
2941
+ function variablesToList(variables) {
2942
+ return Object.entries(variables || {}).sort(([aKey, a], [bKey, b]) => {
2943
+ var _a, _b;
2944
+ if (a.order && b.order) {
2945
+ return a.order - b.order;
2946
+ } else if (a.order) {
2947
+ return 1;
2948
+ } else if (b.order) {
2949
+ return -1;
2950
+ }
2951
+ return ((_a = a.displayName) != null ? _a : aKey).localeCompare((_b = b.displayName) != null ? _b : bKey);
2952
+ }).map(([name, definition]) => ({
2953
+ name,
2954
+ ...definition
2955
+ }));
2956
+ }
2957
+
2894
2958
  // src/components/Variables/InsertVariableMenu.tsx
2895
2959
  import { Fragment as Fragment4, jsx as jsx30, jsxs as jsxs18 } from "@emotion/react/jsx-runtime";
2896
2960
  var InsertVariableMenu = ({
2897
- onVariableClick,
2961
+ onSelectVariable,
2898
2962
  children,
2899
2963
  textValue,
2900
2964
  trigger = "${",
2901
- showAddVariableMenuOption = false
2965
+ showAddVariableMenuOption = false,
2966
+ disabled = false,
2967
+ forceVisible
2902
2968
  }) => {
2903
- const { variables, dispatch } = useVariables();
2969
+ const { variables, dispatch, isEditing } = useVariables();
2904
2970
  const btnRef = useRef8(null);
2905
- const tip = "Tip: access this list by typing ${";
2906
- useEffect5(() => {
2971
+ const tip = `Tip: access this list by typing ${trigger}`;
2972
+ useEffect6(() => {
2907
2973
  if (textValue === trigger && btnRef.current && btnRef.current.getAttribute("aria-expanded") === "false") {
2908
2974
  btnRef.current.click();
2909
2975
  }
2910
2976
  }, [textValue, btnRef, trigger]);
2977
+ const [openedAdd, setOpenedAdd] = useState8(false);
2978
+ useOnVariableUpdated((varName) => {
2979
+ onSelectVariable == null ? void 0 : onSelectVariable({ name: varName, default: "" });
2980
+ }, !openedAdd);
2981
+ useEffect6(() => {
2982
+ if (openedAdd && !isEditing) {
2983
+ setOpenedAdd(false);
2984
+ }
2985
+ }, [isEditing, openedAdd]);
2986
+ if (disabled) {
2987
+ return /* @__PURE__ */ jsx30(Fragment4, { children });
2988
+ }
2989
+ const variablesList = variablesToList(variables);
2911
2990
  return /* @__PURE__ */ jsxs18("div", { css: menuContainer, children: [
2912
2991
  children,
2913
2992
  /* @__PURE__ */ jsxs18(
2914
2993
  Menu2,
2915
2994
  {
2916
2995
  placement: "bottom-start",
2996
+ forceVisible,
2917
2997
  menuTrigger: /* @__PURE__ */ jsx30("button", { ref: btnRef, css: menuBtn, type: "button", title: "Insert variable", children: /* @__PURE__ */ jsx30(Icon5, { icon: "usb-c", iconColor: "currentColor" }) }),
2918
2998
  menuLabel: "Insert variable",
2919
2999
  children: [
2920
- Object.entries(variables).map(([key, value]) => {
2921
- const { helpText } = value;
3000
+ variablesList.map((variable) => {
3001
+ const { name, helpText } = variable;
2922
3002
  return /* @__PURE__ */ jsxs18(
2923
3003
  MenuItem2,
2924
3004
  {
2925
- id: key,
3005
+ id: name,
2926
3006
  css: menuItemTextGroup,
2927
- onClick: () => onVariableClick(decodeURI(`\${${key}}`)),
3007
+ onClick: () => onSelectVariable == null ? void 0 : onSelectVariable(variable),
2928
3008
  children: [
2929
- /* @__PURE__ */ jsx30("span", { children: key }),
3009
+ /* @__PURE__ */ jsx30("span", { children: name }),
2930
3010
  helpText ? /* @__PURE__ */ jsx30("small", { css: smallText, children: helpText }) : null
2931
3011
  ]
2932
3012
  },
2933
- key
3013
+ name
2934
3014
  );
2935
3015
  }),
2936
3016
  showAddVariableMenuOption ? /* @__PURE__ */ jsxs18(Fragment4, { children: [
2937
- /* @__PURE__ */ jsx30(MenuItemSeparator, {}),
2938
- /* @__PURE__ */ jsx30(MenuItem2, { onClick: () => dispatch({ type: "edit", variable: "" }), children: "Add Variable" })
3017
+ variablesList.length ? /* @__PURE__ */ jsx30(MenuItemSeparator, {}) : null,
3018
+ /* @__PURE__ */ jsx30(
3019
+ MenuItem2,
3020
+ {
3021
+ onClick: () => {
3022
+ setOpenedAdd(true);
3023
+ dispatch({ type: "edit", variable: "" });
3024
+ },
3025
+ children: "Add Variable"
3026
+ }
3027
+ )
2939
3028
  ] }) : null,
2940
3029
  Object.entries(variables).length || showAddVariableMenuOption ? /* @__PURE__ */ jsx30(MenuItemSeparator, {}) : null,
2941
3030
  /* @__PURE__ */ jsx30("i", { css: variablesTipText, children: tip })
@@ -2950,13 +3039,15 @@ import { jsx as jsx31 } from "@emotion/react/jsx-runtime";
2950
3039
  function InputVariables({
2951
3040
  "aria-label": ariaLabel,
2952
3041
  value,
2953
- // disableVariables,
3042
+ disableVariables,
2954
3043
  onChange,
2955
3044
  onPaste,
2956
- onVariableClick,
2957
3045
  showAddVariableMenuOption,
3046
+ variablePrefix = "${",
3047
+ variableSuffix = "}",
2958
3048
  ...inputProps
2959
3049
  }) {
3050
+ var _a, _b;
2960
3051
  const { variables, dispatch } = useVariables();
2961
3052
  const currentVariables = React11.useRef(variables);
2962
3053
  const currentDispatch = React11.useRef(dispatch);
@@ -2971,21 +3062,40 @@ function InputVariables({
2971
3062
  React11.useEffect(() => {
2972
3063
  currentSetValue.current = onChange;
2973
3064
  }, [onChange]);
2974
- React11.useEffect(() => {
2975
- var _a, _b;
2976
- if (((_a = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _a.value) && onPaste) {
2977
- onPaste((_b = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _b.value);
2978
- }
2979
- });
3065
+ const onPasteHandler = () => {
3066
+ setTimeout(() => {
3067
+ if (!inputRef.current) {
3068
+ return;
3069
+ }
3070
+ onPaste == null ? void 0 : onPaste(inputRef.current.value);
3071
+ });
3072
+ };
3073
+ const handleInsertVariable = (variable) => {
3074
+ var _a2, _b2;
3075
+ handleSetValue(
3076
+ insertVariableIntoText({
3077
+ variableName: variable.name,
3078
+ value,
3079
+ variablePrefix,
3080
+ variableSuffix,
3081
+ selectionEnd: (_a2 = inputRef.current) == null ? void 0 : _a2.selectionEnd,
3082
+ selectionStart: (_b2 = inputRef.current) == null ? void 0 : _b2.selectionStart
3083
+ })
3084
+ );
3085
+ };
2980
3086
  const handleSetValue = (rawValue) => {
2981
3087
  currentSetValue.current(rawValue);
2982
3088
  };
3089
+ const currentCursor = (_b = (_a = inputRef.current) == null ? void 0 : _a.selectionStart) != null ? _b : value.length;
3090
+ const forceMenu = value.substring(currentCursor - 2, currentCursor) === "${";
2983
3091
  return /* @__PURE__ */ jsx31(
2984
3092
  InsertVariableMenu,
2985
3093
  {
2986
3094
  showAddVariableMenuOption,
2987
3095
  textValue: value,
2988
- onVariableClick,
3096
+ onSelectVariable: handleInsertVariable,
3097
+ disabled: disableVariables,
3098
+ forceVisible: forceMenu || void 0,
2989
3099
  children: /* @__PURE__ */ jsx31(
2990
3100
  Input3,
2991
3101
  {
@@ -2994,6 +3104,7 @@ function InputVariables({
2994
3104
  showLabel: false,
2995
3105
  value,
2996
3106
  onChange: (e) => handleSetValue(e.currentTarget.value),
3107
+ onPaste: onPasteHandler,
2997
3108
  ...inputProps
2998
3109
  }
2999
3110
  )
@@ -3062,24 +3173,6 @@ var variableValue = css20`
3062
3173
  max-width: 20ch;
3063
3174
  `;
3064
3175
 
3065
- // src/components/Variables/variablesToList.ts
3066
- function variablesToList(variables) {
3067
- return Object.entries(variables || {}).sort(([aKey, a], [bKey, b]) => {
3068
- var _a, _b;
3069
- if (a.order && b.order) {
3070
- return a.order - b.order;
3071
- } else if (a.order) {
3072
- return 1;
3073
- } else if (b.order) {
3074
- return -1;
3075
- }
3076
- return ((_a = a.displayName) != null ? _a : aKey).localeCompare((_b = b.displayName) != null ? _b : bKey);
3077
- }).map(([name, definition]) => ({
3078
- name,
3079
- ...definition
3080
- }));
3081
- }
3082
-
3083
3176
  // src/components/Variables/VariablesList.tsx
3084
3177
  import { Fragment as Fragment5, jsx as jsx32, jsxs as jsxs19 } from "@emotion/react/jsx-runtime";
3085
3178
  function VariablesList() {
@@ -3246,7 +3339,7 @@ function TextVariableRenderer({ definition, value, setValue }) {
3246
3339
  // src/components/Request/RequestBody.tsx
3247
3340
  import { css as css23 } from "@emotion/react";
3248
3341
  import { InputSelect as InputSelect4, JsonEditor } from "@uniformdev/design-system";
3249
- import { useState as useState8 } from "react";
3342
+ import { useState as useState9 } from "react";
3250
3343
 
3251
3344
  // src/components/Request/RequestProvider.tsx
3252
3345
  import * as React12 from "react";
@@ -3372,7 +3465,7 @@ var LANGUAGE_TO_CONTENT_TYPE = {
3372
3465
  };
3373
3466
  function RequestBody() {
3374
3467
  const { request, dispatch } = useRequest();
3375
- const [language, setLanguage] = useState8("json");
3468
+ const [language, setLanguage] = useState9("json");
3376
3469
  return /* @__PURE__ */ jsxs21(
3377
3470
  "div",
3378
3471
  {
@@ -3500,7 +3593,8 @@ function RequestHeaders({ disableVariables }) {
3500
3593
  {
3501
3594
  value: header.value,
3502
3595
  onChange: (value) => handleUpdateParamFromMenu({ key: header.key, value, index }),
3503
- onVariableClick: (value) => handleUpdateParamFromMenu({ key: header.key, value, index }),
3596
+ disableVariables,
3597
+ showAddVariableMenuOption: true,
3504
3598
  "data-test-id": "header-value"
3505
3599
  }
3506
3600
  ) : null })
@@ -3608,12 +3702,9 @@ function RequestParameters({ disableVariables }) {
3608
3702
  value: selectedVariable,
3609
3703
  index
3610
3704
  }),
3611
- onVariableClick: (selectedVariable) => handleUpdateParamFromMenu({
3612
- key: parameter.key,
3613
- value: selectedVariable,
3614
- index
3615
- }),
3616
- "data-test-id": "parameter-value"
3705
+ disableVariables,
3706
+ "data-test-id": "parameter-value",
3707
+ showAddVariableMenuOption: true
3617
3708
  }
3618
3709
  ) : null })
3619
3710
  ] }, index);
@@ -3624,7 +3715,7 @@ function RequestParameters({ disableVariables }) {
3624
3715
 
3625
3716
  // src/components/Request/RequestUrl.tsx
3626
3717
  import { css as css24 } from "@emotion/react";
3627
- import { useMemo as useMemo6 } from "react";
3718
+ import { useMemo as useMemo7 } from "react";
3628
3719
 
3629
3720
  // src/components/Request/urlEncodeRequestParameter.ts
3630
3721
  function urlEncodeRequestUrl(url, varValues) {
@@ -3650,7 +3741,7 @@ function RequestUrl() {
3650
3741
  var _a, _b;
3651
3742
  const { variables } = useVariables();
3652
3743
  const { request } = useRequest();
3653
- const mergedParameters = useMemo6(() => {
3744
+ const mergedParameters = useMemo7(() => {
3654
3745
  var _a2;
3655
3746
  if (!((_a2 = request.baseRequest) == null ? void 0 : _a2.parameters)) {
3656
3747
  return request.parameters;
@@ -3720,9 +3811,6 @@ function RequestUrlInput(props) {
3720
3811
  onChange: (value) => {
3721
3812
  dispatch({ type: "setRelativeUrl", relativeUrl: value });
3722
3813
  },
3723
- onVariableClick: (selectedValue) => {
3724
- dispatch({ type: "setRelativeUrl", relativeUrl: request.relativeUrl.concat(selectedValue) });
3725
- },
3726
3814
  showAddVariableMenuOption: true
3727
3815
  }
3728
3816
  );
@@ -3875,12 +3963,12 @@ import { LoadingIndicator as LoadingIndicator2, Theme as Theme2 } from "@uniform
3875
3963
 
3876
3964
  // src/hooks/useInitializeUniformMeshSdk.ts
3877
3965
  import { initializeUniformMeshSDK } from "@uniformdev/mesh-sdk";
3878
- import { useEffect as useEffect7, useRef as useRef10, useState as useState9 } from "react";
3966
+ import { useEffect as useEffect8, useRef as useRef10, useState as useState10 } from "react";
3879
3967
  var useInitializeUniformMeshSdk = ({ autoResizingDisabled } = {}) => {
3880
- const [error, setError] = useState9();
3881
- const [sdk, setSdk] = useState9();
3968
+ const [error, setError] = useState10();
3969
+ const [sdk, setSdk] = useState10();
3882
3970
  const initializationInProgress = useRef10(false);
3883
- useEffect7(
3971
+ useEffect8(
3884
3972
  () => {
3885
3973
  if (typeof window === "undefined" || sdk) {
3886
3974
  return;
@@ -3979,10 +4067,10 @@ var ObjectSearchContainer = ({
3979
4067
 
3980
4068
  // src/components/ObjectSearch/ObjectSearchFilter.tsx
3981
4069
  import { InputKeywordSearch as InputKeywordSearch2, InputSelect as InputSelect6 } from "@uniformdev/design-system";
3982
- import { useState as useState11 } from "react";
4070
+ import { useState as useState12 } from "react";
3983
4071
 
3984
4072
  // src/components/ObjectSearch/hooks/ObjectSearchContext.tsx
3985
- import { createContext as createContext5, useCallback, useContext as useContext7, useDeferredValue, useState as useState10 } from "react";
4073
+ import { createContext as createContext5, useCallback, useContext as useContext7, useDeferredValue, useState as useState11 } from "react";
3986
4074
  import { jsx as jsx47 } from "@emotion/react/jsx-runtime";
3987
4075
  var ObjectSearchContext = createContext5({
3988
4076
  onSetQuery: () => {
@@ -4001,13 +4089,13 @@ var ObjectSearchContext = createContext5({
4001
4089
  }
4002
4090
  });
4003
4091
  var ObjectSearchProvider = ({ currentlySelectedItems, children }) => {
4004
- const [query, setQuery] = useState10({
4092
+ const [query, setQuery] = useState11({
4005
4093
  contentType: "",
4006
4094
  keyword: ""
4007
4095
  });
4008
4096
  const querySearchDeferred = useDeferredValue(query);
4009
- const [selectedItems, setSelectedItems] = useState10(currentlySelectedItems != null ? currentlySelectedItems : []);
4010
- const [list, setList] = useState10({});
4097
+ const [selectedItems, setSelectedItems] = useState11(currentlySelectedItems != null ? currentlySelectedItems : []);
4098
+ const [list, setList] = useState11({});
4011
4099
  const onSetQuery = useCallback(
4012
4100
  (value) => {
4013
4101
  if (Array.isArray(value.contentType) && value.contentType.length > 0) {
@@ -4098,7 +4186,7 @@ var ObjectSearchFilter = ({
4098
4186
  selectOptions
4099
4187
  }) => {
4100
4188
  const { query, onSetQuery } = useObjectSearchContext();
4101
- const [searchState, setSearchState] = useState11({
4189
+ const [searchState, setSearchState] = useState12({
4102
4190
  contentType: "",
4103
4191
  keyword: ""
4104
4192
  });
@@ -4536,7 +4624,7 @@ var ObjectSearchResultList = ({
4536
4624
 
4537
4625
  // src/components/ObjectSearch/QueryFilter.tsx
4538
4626
  import { Input as Input7, InputKeywordSearch as InputKeywordSearch3, InputSelect as InputSelect7 } from "@uniformdev/design-system";
4539
- import { useEffect as useEffect8, useState as useState12 } from "react";
4627
+ import { useEffect as useEffect9, useState as useState13 } from "react";
4540
4628
  import { jsx as jsx54, jsxs as jsxs34 } from "@emotion/react/jsx-runtime";
4541
4629
  var QueryFilter = ({
4542
4630
  requireContentType,
@@ -4567,7 +4655,7 @@ var QueryFilter = ({
4567
4655
  }) => {
4568
4656
  var _a, _b;
4569
4657
  const { query, onSetQuery } = useObjectSearchContext();
4570
- const [queryState, setQueryState] = useState12({
4658
+ const [queryState, setQueryState] = useState13({
4571
4659
  contentType: "",
4572
4660
  keyword: "",
4573
4661
  count: countValue != null ? countValue : 5,
@@ -4578,7 +4666,7 @@ var QueryFilter = ({
4578
4666
  setQueryState((prev) => ({ ...prev, ...value }));
4579
4667
  onSetQuery({ ...query, ...value });
4580
4668
  };
4581
- useEffect8(() => {
4669
+ useEffect9(() => {
4582
4670
  onSetQuery(queryState);
4583
4671
  }, [onSetQuery, queryState]);
4584
4672
  return /* @__PURE__ */ jsxs34("fieldset", { children: [