@evergis/react 4.0.139 → 4.0.141

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.
@@ -23,7 +23,8 @@ export declare const VoteVariantHead: import('styled-components').StyledComponen
23
23
  export declare const VoteVariantText: import('styled-components').StyledComponent<"span", any, {}, never>;
24
24
  export declare const VoteVariantCount: import('styled-components').StyledComponent<"span", any, {}, never>;
25
25
  export declare const VoteAcceptedBadge: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps, never>;
26
- export declare const VoteAuthHint: import('styled-components').StyledComponent<"div", any, {}, never>;
26
+ /** Мелкая серая подпись под контролами: почему нельзя голосовать или почему кнопка неактивна. */
27
+ export declare const VoteHint: import('styled-components').StyledComponent<"div", any, {}, never>;
27
28
  export declare const VoteEditLink: import('styled-components').StyledComponent<"button", any, {}, never>;
28
29
  export declare const VoteShareBlock: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps, never>;
29
30
  export declare const VoteShareChips: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps, never>;
package/dist/index.js CHANGED
@@ -6250,7 +6250,6 @@ const useMapImages = ({ images }) => {
6250
6250
  const { map, loaded: mapLoaded } = useMapContext();
6251
6251
  const [loaded, setLoaded] = React.useState(false);
6252
6252
  const [errors, setErrors] = React.useState({});
6253
- const loadedImagesRef = React.useRef(new Set());
6254
6253
  const previouslyLoadedImages = React.useRef([]);
6255
6254
  const hasImage = React.useCallback((name) => {
6256
6255
  if (!map?.current) {
@@ -6264,7 +6263,6 @@ const useMapImages = ({ images }) => {
6264
6263
  }
6265
6264
  if (map.current.hasImage(name)) {
6266
6265
  map.current.removeImage(name);
6267
- loadedImagesRef.current.delete(name);
6268
6266
  }
6269
6267
  }, [map]);
6270
6268
  const addImage = React.useCallback(async (config) => {
@@ -6285,7 +6283,6 @@ const useMapImages = ({ images }) => {
6285
6283
  sdf,
6286
6284
  pixelRatio,
6287
6285
  });
6288
- loadedImagesRef.current.add(config.name);
6289
6286
  }
6290
6287
  catch (error) {
6291
6288
  const message = error instanceof Error ? error.message : "Unknown error";
@@ -6301,7 +6298,6 @@ const useMapImages = ({ images }) => {
6301
6298
  sdf,
6302
6299
  pixelRatio,
6303
6300
  });
6304
- loadedImagesRef.current.add(config.name);
6305
6301
  }
6306
6302
  catch (error) {
6307
6303
  const message = error instanceof Error ? error.message : "Unknown error";
@@ -6318,7 +6314,6 @@ const useMapImages = ({ images }) => {
6318
6314
  sdf,
6319
6315
  pixelRatio,
6320
6316
  });
6321
- loadedImagesRef.current.add(config.name);
6322
6317
  resolve();
6323
6318
  }
6324
6319
  }).catch(error => {
@@ -6359,16 +6354,19 @@ const useMapImages = ({ images }) => {
6359
6354
  if (!mapLoaded) {
6360
6355
  return;
6361
6356
  }
6362
- map.current.on("styleimagemissing", async (e) => {
6363
- const missingImage = images.find(item => item.name === e.id);
6364
- if (missingImage && !map.current.hasImage(e.id)) {
6357
+ map.current.on("style.load", async () => {
6358
+ if (previouslyLoadedImages.current.length === 0) {
6359
+ return;
6360
+ }
6361
+ const loadPromises = previouslyLoadedImages.current.map(async (config) => {
6365
6362
  try {
6366
- await addImage(missingImage);
6363
+ await addImage(config);
6367
6364
  }
6368
6365
  catch {
6369
6366
  // Ошибка уже записана в errors
6370
6367
  }
6371
- }
6368
+ });
6369
+ await Promise.all(loadPromises);
6372
6370
  });
6373
6371
  }, [mapLoaded]);
6374
6372
  return { loaded, errors, addImage, removeImage, hasImage };
@@ -11908,7 +11906,8 @@ const VoteAcceptedBadge = styled(uilibGl.Flex).withConfig({ displayName: "VoteAc
11908
11906
  color: #ffffff;
11909
11907
  font-size: 0.875rem;
11910
11908
  `;
11911
- const VoteAuthHint = styled.div.withConfig({ displayName: "VoteAuthHint", componentId: "sc-8uftsh" }) `
11909
+ /** Мелкая серая подпись под контролами: почему нельзя голосовать или почему кнопка неактивна. */
11910
+ const VoteHint = styled.div.withConfig({ displayName: "VoteHint", componentId: "sc-li8usz" }) `
11912
11911
  font-size: 0.8125rem;
11913
11912
  color: ${({ theme: { palette } }) => palette.textSecondary};
11914
11913
  `;
@@ -12010,8 +12009,18 @@ const useVoteForm = (initialValues) => {
12010
12009
  const removeVariant = React.useCallback((index) => {
12011
12010
  setVariants(prev => prev.filter((_, itemIndex) => itemIndex !== index));
12012
12011
  }, []);
12013
- const isValid = React.useMemo(() => Boolean(categoryId && text.trim() && variants.length >= MIN_VARIANTS), [categoryId, text, variants.length]);
12014
- const values = React.useMemo(() => ({ categoryId, text: text.trim(), multiSelect, variants }), [categoryId, text, multiSelect, variants]);
12012
+ /**
12013
+ * Варианты вместе с недобавленным черновиком.
12014
+ *
12015
+ * Последний вариант часто набирают и жмут «Создать», не нажав Enter: чипсом он ещё не стал, но
12016
+ * пользователь его уже ввёл. Считать такой текст вариантом честнее, чем гасить кнопку и молчать.
12017
+ */
12018
+ const allVariants = React.useMemo(() => {
12019
+ const pending = draft.trim();
12020
+ return pending ? [...variants, { text: pending }] : variants;
12021
+ }, [variants, draft]);
12022
+ const isValid = React.useMemo(() => Boolean(categoryId && text.trim() && allVariants.length >= MIN_VARIANTS), [categoryId, text, allVariants.length]);
12023
+ const values = React.useMemo(() => ({ categoryId, text: text.trim(), multiSelect, variants: allVariants }), [categoryId, text, multiSelect, allVariants]);
12015
12024
  return {
12016
12025
  categoryId,
12017
12026
  setCategoryId,
@@ -12041,7 +12050,10 @@ const VoteCreateForm = ({ categories, initialValues, isEditing, canDelete, submi
12041
12050
  }
12042
12051
  } }), jsxRuntime.jsxs(uilibGl.Flex, { alignItems: "center", justifyContent: "space-between", children: [jsxRuntime.jsx(VoteSectionLabel, { children: t("vote.multiSelect", { ns: VOTE_NS, defaultValue: "Множественный выбор" }) }), jsxRuntime.jsx(uilibGl.Switch, { checked: multiSelect, onChange: () => setMultiSelect(prev => !prev) })] }), jsxRuntime.jsx(uilibGl.RaisedButton, { primary: true, disabled: !isValid || submitting, onClick: () => onSubmit(values), children: isEditing
12043
12052
  ? t("vote.save", { ns: VOTE_NS, defaultValue: "Сохранить" })
12044
- : t("vote.create", { ns: VOTE_NS, defaultValue: "Создать голосование" }) }), isEditing && (jsxRuntime.jsxs(uilibGl.Flex, { alignItems: "center", justifyContent: "space-between", children: [onCancel && (jsxRuntime.jsx(VoteEditLink, { onClick: onCancel, children: t("vote.cancel", { ns: VOTE_NS, defaultValue: "Отмена" }) })), canDelete && onDelete && (jsxRuntime.jsx(uilibGl.RaisedButton, { error: true, disabled: submitting, onClick: onDelete, children: t("vote.delete", { ns: VOTE_NS, defaultValue: "Удалить голосование" }) }))] }))] }));
12053
+ : t("vote.create", { ns: VOTE_NS, defaultValue: "Создать голосование" }) }), !isValid && (jsxRuntime.jsx(VoteHint, { children: t("vote.formHint", {
12054
+ ns: VOTE_NS,
12055
+ defaultValue: "Нужны категория, вопрос и минимум два варианта ответа",
12056
+ }) })), isEditing && (jsxRuntime.jsxs(uilibGl.Flex, { alignItems: "center", justifyContent: "space-between", children: [onCancel && (jsxRuntime.jsx(VoteEditLink, { onClick: onCancel, children: t("vote.cancel", { ns: VOTE_NS, defaultValue: "Отмена" }) })), canDelete && onDelete && (jsxRuntime.jsx(uilibGl.RaisedButton, { error: true, disabled: submitting, onClick: onDelete, children: t("vote.delete", { ns: VOTE_NS, defaultValue: "Удалить голосование" }) }))] }))] }));
12045
12057
  };
12046
12058
 
12047
12059
  /** Блок «Поделиться в соцсетях» — пока только вёрстка, без рабочих ссылок. */
@@ -12065,7 +12077,7 @@ const VoteResults = ({ question, category, results, screen, isOwner, hasAnswers,
12065
12077
  }, [question.multiSelect]);
12066
12078
  const canSubmit = React.useMemo(() => selected.length > 0 && !submitting, [selected.length, submitting]);
12067
12079
  return (jsxRuntime.jsxs(VoteWrapper, { children: [category && jsxRuntime.jsx(VoteCategoryLabel, { children: category.name }), jsxRuntime.jsx(VoteQuestionText, { children: question.text }), jsxRuntime.jsx(VoteVariantList, { column: true, value: selected[0] ?? "", children: results.map(({ id, text, count, percent }) => (jsxRuntime.jsxs(VoteVariantRow, { children: [jsxRuntime.jsxs(VoteVariantHead, { children: [showControls &&
12068
- (question.multiSelect ? (jsxRuntime.jsx(uilibGl.Checkbox, { checked: selected.includes(id), onChange: () => toggle(id) })) : (jsxRuntime.jsx(uilibGl.Radio, { value: id, checked: selected.includes(id), onChange: () => toggle(id) }))), jsxRuntime.jsx(VoteVariantText, { children: text }), jsxRuntime.jsx(VoteVariantCount, { children: count })] }), jsxRuntime.jsx(uilibGl.LinearProgress, { done: percent })] }, id))) }), screen === "unauthenticated" && (jsxRuntime.jsx(VoteAuthHint, { children: t("vote.authHint", { ns: VOTE_NS, defaultValue: "Чтобы проголосовать, пожалуйста, авторизуйтесь" }) })), screen === "voted" && (jsxRuntime.jsxs(VoteAcceptedBadge, { children: [jsxRuntime.jsx(uilibGl.Icon, { kind: "success" }), t("vote.accepted", { ns: VOTE_NS, defaultValue: "Ваш ответ принят" })] })), showControls && (jsxRuntime.jsx(uilibGl.RaisedButton, { primary: true, disabled: !canSubmit, onClick: () => onSubmit(selected), children: t("vote.submit", { ns: VOTE_NS, defaultValue: "Отправить ответ" }) })), canEdit && onEdit && (jsxRuntime.jsx(uilibGl.Flex, { children: jsxRuntime.jsx(VoteEditLink, { onClick: onEdit, children: t("vote.edit", { ns: VOTE_NS, defaultValue: "Редактировать" }) }) })), showShare && jsxRuntime.jsx(VoteShare, {})] }));
12080
+ (question.multiSelect ? (jsxRuntime.jsx(uilibGl.Checkbox, { checked: selected.includes(id), onChange: () => toggle(id) })) : (jsxRuntime.jsx(uilibGl.Radio, { value: id, checked: selected.includes(id), onChange: () => toggle(id) }))), jsxRuntime.jsx(VoteVariantText, { children: text }), jsxRuntime.jsx(VoteVariantCount, { children: count })] }), jsxRuntime.jsx(uilibGl.LinearProgress, { done: percent })] }, id))) }), screen === "unauthenticated" && (jsxRuntime.jsx(VoteHint, { children: t("vote.authHint", { ns: VOTE_NS, defaultValue: "Чтобы проголосовать, пожалуйста, авторизуйтесь" }) })), screen === "voted" && (jsxRuntime.jsxs(VoteAcceptedBadge, { children: [jsxRuntime.jsx(uilibGl.Icon, { kind: "success" }), t("vote.accepted", { ns: VOTE_NS, defaultValue: "Ваш ответ принят" })] })), showControls && (jsxRuntime.jsx(uilibGl.RaisedButton, { primary: true, disabled: !canSubmit, onClick: () => onSubmit(selected), children: t("vote.submit", { ns: VOTE_NS, defaultValue: "Отправить ответ" }) })), canEdit && onEdit && (jsxRuntime.jsx(uilibGl.Flex, { children: jsxRuntime.jsx(VoteEditLink, { onClick: onEdit, children: t("vote.edit", { ns: VOTE_NS, defaultValue: "Редактировать" }) }) })), showShare && jsxRuntime.jsx(VoteShare, {})] }));
12069
12081
  };
12070
12082
 
12071
12083
  /**