@bigbinary/neeto-molecules 3.15.5 → 3.15.6

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.
@@ -1,7 +1,7 @@
1
1
  import { slugify, isPresent, noop } from '@bigbinary/neeto-cist';
2
2
  import { omit } from 'ramda';
3
3
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
- import React__default, { useRef, useEffect, useState, createElement } from 'react';
4
+ import React__default, { useRef, useCallback, useEffect, useState, createElement } from 'react';
5
5
  import ExternalLink from '@bigbinary/neeto-icons/ExternalLink';
6
6
  import Button from '@bigbinary/neetoui/Button';
7
7
  import { useTranslation, Trans } from 'react-i18next';
@@ -74,8 +74,16 @@ var getPathname = function getPathname(url) {
74
74
  var getPrefixFromUrl = function getPrefixFromUrl(url) {
75
75
  return "".concat(new URL(url).origin, "/");
76
76
  };
77
- var truncatePrefix = function truncatePrefix(url) {
78
- return url.length > MAX_PREFIX_SIZE ? "...".concat(url.slice(-MAX_PREFIX_SIZE)) : url;
77
+ var truncatePrefix = function truncatePrefix(inputElement, prefixText) {
78
+ var parentElement = inputElement.parentElement;
79
+ var prefixElement = parentElement.querySelector(".neeto-ui-input__prefix");
80
+ var _getComputedStyle = getComputedStyle(inputElement),
81
+ fontSize = _getComputedStyle.fontSize;
82
+ var averageCharWidth = parseFloat(fontSize) * 0.6;
83
+ var requiredInputWidth = inputElement.value.length * averageCharWidth;
84
+ var prefixWidth = parentElement.offsetWidth - requiredInputWidth;
85
+ var maxPrefixChars = Math.max(Math.floor(prefixWidth / averageCharWidth), 5);
86
+ prefixElement.textContent = maxPrefixChars < prefixText.length ? "...".concat(prefixText.slice(-maxPrefixChars)) : prefixText;
79
87
  };
80
88
 
81
89
  var SOCIAL_MEDIA_OPTIONS = {
@@ -98,7 +106,6 @@ var SOCIAL_MEDIA_OPTIONS = {
98
106
  var PATH_VALIDATION_SCHEMA = yup.object().shape({
99
107
  path: yup.string().required(t("neetoMolecules.shareViaLink.editUrl.validationError")).matches(/^[A-Za-z0-9]([\w/-])*$/, t("neetoMolecules.shareViaLink.editUrl.validationError"))
100
108
  });
101
- var MAX_PREFIX_SIZE = 30;
102
109
 
103
110
  var css = ".no-padding .neeto-ui-input.neeto-ui-input--medium input{padding:0}.no-padding .neeto-ui-input__prefix{color:rgb(var(--neeto-ui-gray-600))!important}";
104
111
  n(css,{});
@@ -117,6 +124,18 @@ var EditURL = function EditURL(_ref) {
117
124
  t = _useTranslation.t;
118
125
  var focusRef = useRef(null);
119
126
  var prevIsLoadingRef = useRef(isLoading);
127
+ var prefixText = (editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.prefix) || getPrefixFromUrl(url);
128
+ var observerRef = useRef(new ResizeObserver(function (_ref2) {
129
+ var _ref3 = _slicedToArray(_ref2, 1),
130
+ entry = _ref3[0];
131
+ return requestAnimationFrame(function () {
132
+ return truncatePrefix(entry.target, prefixText);
133
+ });
134
+ }));
135
+ var inputRef = useCallback(function (inputElement) {
136
+ focusRef.current = inputElement;
137
+ inputElement ? observerRef.current.observe(inputElement) : observerRef.current.disconnect();
138
+ }, []);
120
139
  useEffect(function () {
121
140
  if (prevIsLoadingRef.current && !isLoading) onClose();
122
141
  prevIsLoadingRef.current = isLoading;
@@ -140,13 +159,13 @@ var EditURL = function EditURL(_ref) {
140
159
  path: (editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.editablePath) || getPathname(url)
141
160
  },
142
161
  validationSchema: PATH_VALIDATION_SCHEMA,
143
- onSubmit: function onSubmit(_ref2) {
144
- var path = _ref2.path;
162
+ onSubmit: function onSubmit(_ref4) {
163
+ var path = _ref4.path;
145
164
  return handleEdit(path);
146
165
  },
147
- children: function children(_ref3) {
148
- var isSubmitting = _ref3.isSubmitting,
149
- dirty = _ref3.dirty;
166
+ children: function children(_ref5) {
167
+ var isSubmitting = _ref5.isSubmitting,
168
+ dirty = _ref5.dirty;
150
169
  return /*#__PURE__*/jsxs(Form, {
151
170
  children: [/*#__PURE__*/jsxs(Body, {
152
171
  className: "space-y-6",
@@ -156,8 +175,8 @@ var EditURL = function EditURL(_ref) {
156
175
  label: t("neetoMolecules.shareViaLink.editUrl.inputLabel"),
157
176
  maxLength: editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.maxLength,
158
177
  name: "path",
159
- ref: focusRef,
160
- prefix: truncatePrefix((editUrlProps === null || editUrlProps === void 0 ? void 0 : editUrlProps.prefix) || getPrefixFromUrl(url))
178
+ prefix: prefixText,
179
+ ref: inputRef
161
180
  }), /*#__PURE__*/jsx(Typography, {
162
181
  className: "neeto-ui-text-gray-700",
163
182
  lineHeight: "normal",