@gravity-ui/markdown-editor 15.18.0 → 15.19.0

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "link_copied": "The link copied",
3
+ "link_copy": "Copy link",
4
+ "file_download": "Download"
5
+ }
@@ -0,0 +1,7 @@
1
+ export declare const i18n: <G extends "link_copied" | "link_copy" | "file_download", S extends string>(key: G | (string extends S ? S : never), params?: {
2
+ [key: string]: any;
3
+ }) => S extends G ? {
4
+ link_copied: string;
5
+ link_copy: string;
6
+ file_download: string;
7
+ }[G] : string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18n = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const i18n_1 = require("../i18n.js");
6
+ const en_json_1 = tslib_1.__importDefault(require("./en.json"));
7
+ const ru_json_1 = tslib_1.__importDefault(require("./ru.json"));
8
+ const KEYSET = 'gallery';
9
+ exports.i18n = (0, i18n_1.registerKeyset)(KEYSET, { en: en_json_1.default, ru: ru_json_1.default });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../../src","sources":["i18n/gallery/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAuC;AAEvC,gEAA2B;AAC3B,gEAA2B;AAE3B,MAAM,MAAM,GAAG,SAAS,CAAC;AAEZ,QAAA,IAAI,GAAG,IAAA,qBAAc,EAAC,MAAM,EAAE,EAAC,EAAE,EAAF,iBAAE,EAAE,EAAE,EAAF,iBAAE,EAAC,CAAC,CAAC","sourcesContent":["import {registerKeyset} from '../i18n';\n\nimport en from './en.json';\nimport ru from './ru.json';\n\nconst KEYSET = 'gallery';\n\nexport const i18n = registerKeyset(KEYSET, {en, ru});\n"]}
@@ -0,0 +1,5 @@
1
+ {
2
+ "link_copied": "Ссылка скопирована",
3
+ "link_copy": "Скопировать ссылку",
4
+ "file_download": "Скачать"
5
+ }
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  /** During build process, the current version will be injected here */
5
- exports.VERSION = typeof '15.18.0' !== 'undefined' ? '15.18.0' : 'unknown';
5
+ exports.VERSION = typeof '15.19.0' !== 'undefined' ? '15.19.0' : 'unknown';
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACzD,QAAA,OAAO,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["/** During build process, the current version will be injected here */\nexport const VERSION = typeof '15.18.0' !== 'undefined' ? '15.18.0' : 'unknown';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACzD,QAAA,OAAO,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["/** During build process, the current version will be injected here */\nexport const VERSION = typeof '15.19.0' !== 'undefined' ? '15.19.0' : 'unknown';\n"]}
@@ -2,3 +2,9 @@ import type { GalleryItemProps } from '@gravity-ui/components';
2
2
  export type GalleryItemPropsWithUrl = GalleryItemProps & {
3
3
  url?: string;
4
4
  };
5
+ export type FilesGalleryItemType = 'image' | 'video';
6
+ export type UseFilesGalleryOptions = {
7
+ download?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;
8
+ copyUrl?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;
9
+ overrideItemProps?: (url: string, type: FilesGalleryItemType, element: Element, currentProps: GalleryItemProps) => GalleryItemProps;
10
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {GalleryItemProps} from '@gravity-ui/components';\n\nexport type GalleryItemPropsWithUrl = GalleryItemProps & {\n // pass the url to be able to exclude the items from content if they are found in the custom files\n url?: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {GalleryItemProps} from '@gravity-ui/components';\n\nexport type GalleryItemPropsWithUrl = GalleryItemProps & {\n // pass the url to be able to exclude the items from content if they are found in the custom files\n url?: string;\n};\n\nexport type FilesGalleryItemType = 'image' | 'video';\n\nexport type UseFilesGalleryOptions = {\n download?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;\n copyUrl?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;\n overrideItemProps?: (\n url: string,\n type: FilesGalleryItemType,\n element: Element,\n currentProps: GalleryItemProps,\n ) => GalleryItemProps;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { GalleryItemPropsWithUrl } from "./types.js";
3
- export declare function useFilesGallery(customFiles?: GalleryItemPropsWithUrl[]): {
2
+ import type { GalleryItemPropsWithUrl, UseFilesGalleryOptions } from "./types.js";
3
+ export declare function useFilesGallery(customFiles?: GalleryItemPropsWithUrl[], { download: getItemDownloladUrl, overrideItemProps, copyUrl: getItemCopyUrl, }?: UseFilesGalleryOptions): {
4
4
  openFilesGallery: (event: React.MouseEvent<HTMLDivElement>) => boolean;
5
5
  };
@@ -4,9 +4,12 @@ exports.useFilesGallery = useFilesGallery;
4
4
  const tslib_1 = require("tslib");
5
5
  const React = tslib_1.__importStar(require("react"));
6
6
  const components_1 = require("@gravity-ui/components");
7
+ const uikit_1 = require("@gravity-ui/uikit");
8
+ const gallery_1 = require("../../../i18n/gallery/index.js");
7
9
  const constants_1 = require("./constants.js");
8
- function useFilesGallery(customFiles) {
10
+ function useFilesGallery(customFiles, { download: getItemDownloladUrl, overrideItemProps, copyUrl: getItemCopyUrl, } = {}) {
9
11
  const { openGallery } = (0, components_1.useGallery)();
12
+ const toaster = (0, uikit_1.useToaster)();
10
13
  return {
11
14
  openFilesGallery: React.useCallback((event) => {
12
15
  if (!(event.target instanceof HTMLElement)) {
@@ -35,11 +38,36 @@ function useFilesGallery(customFiles) {
35
38
  const name = (isImage
36
39
  ? element.getAttribute('alt')
37
40
  : element.getAttribute('title')) || '';
38
- result.push({
39
- ...(constants_1.supportedVideoExtensions.includes(extension)
41
+ const filesGalleryItemType = constants_1.supportedVideoExtensions.includes(extension) ? 'video' : 'image';
42
+ const galleryItemActions = [];
43
+ const itemCopyUrl = getItemCopyUrl?.(link, filesGalleryItemType, element);
44
+ if (itemCopyUrl) {
45
+ const handleLinkCopied = () => {
46
+ toaster.add({
47
+ theme: 'success',
48
+ name: 'g-md-editor-gallery-copy-link',
49
+ title: (0, gallery_1.i18n)('link_copied'),
50
+ });
51
+ };
52
+ galleryItemActions.push((0, components_1.getGalleryItemCopyLinkAction)({
53
+ copyUrl: itemCopyUrl,
54
+ onCopy: handleLinkCopied,
55
+ }));
56
+ }
57
+ const downloadUrl = getItemDownloladUrl?.(link, filesGalleryItemType, element);
58
+ if (downloadUrl) {
59
+ galleryItemActions.push((0, components_1.getGalleryItemDownloadAction)({ downloadUrl }));
60
+ }
61
+ const galleryItemProps = {
62
+ ...(filesGalleryItemType === 'video'
40
63
  ? (0, components_1.getGalleryItemVideo)({ src: link, name: name })
41
64
  : (0, components_1.getGalleryItemImage)({ src: link, name: name })),
42
65
  url: link,
66
+ actions: galleryItemActions,
67
+ };
68
+ result.push({
69
+ ...galleryItemProps,
70
+ ...overrideItemProps?.(link, filesGalleryItemType, element, galleryItemProps),
43
71
  });
44
72
  }
45
73
  }
@@ -53,7 +81,14 @@ function useFilesGallery(customFiles) {
53
81
  return true;
54
82
  }
55
83
  return false;
56
- }, [customFiles, openGallery]),
84
+ }, [
85
+ customFiles,
86
+ getItemCopyUrl,
87
+ getItemDownloladUrl,
88
+ overrideItemProps,
89
+ toaster,
90
+ openGallery,
91
+ ]),
57
92
  };
58
93
  }
59
94
  //# sourceMappingURL=useFilesGallery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFilesGallery.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/useFilesGallery.tsx"],"names":[],"mappings":";;AAOA,0CAkEC;;AAzED,qDAA+B;AAE/B,uDAA4F;AAE5F,8CAA0F;AAG1F,SAAgB,eAAe,CAAC,WAAuC;IACnE,MAAM,EAAC,WAAW,EAAC,GAAG,IAAA,uBAAU,GAAE,CAAC;IAEnC,OAAO;QACH,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAC/B,CAAC,KAAuC,EAAE,EAAE;YACxC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE,CAAC;gBACzC,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,IAAI,QAAQ,GAAG,EAAE,CAAC;YAElB,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/D,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACtD,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;gBACtC,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACvD,CAAC;YAED,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACZ,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,MAAM,gBAAgB,GAAG;gBACrB,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;aAC5D,CAAC,MAAM,CAA4B,CAAC,MAAM,EAAE,OAAO,E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CAAC;YAE5D,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;YAE1E,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACrC,OAAO,IAAI,CAAC;YAChB,CAAC;YAED,OAAO,KAAK,CAAC;QACjB,CAAC,EACD,CAAC,WAAW,EAAE,WAAW,CAAC,CAC7B;KACJ,CAAC;AACN,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {getGalleryItemImage, getGalleryItemVideo, useGallery} from '@gravity-ui/components';\n\nimport {extensionRegex, supportedExtensions, supportedVideoExtensions} from './constants';\nimport type {GalleryItemPropsWithUrl} from './types';\n\nexport function useFilesGallery(customFiles?: GalleryItemPropsWithUrl[]) {\n const {openGallery} = useGallery();\n\n return {\n openFilesGallery: React.useCallback(\n (event: React.MouseEvent<HTMLDivElement>) => {\n if (!(event.target instanceof HTMLElement)) {\n return false;\n }\n\n let fileLink = '';\n\n if (event.target.tagName === 'IMG' && !event.target.closest('a')) {\n fileLink = event.target.getAttribute('src') ?? '';\n } else if (event.target.tagName === 'A') {\n fileLink = event.target.getAttribute('href') ?? '';\n }\n\n if (!fileLink) {\n return false;\n }\n\n const filesFromContent = [\n ...(event.currentTarget?.querySelectorAll('img,a') ?? []),\n ].reduce<GalleryItemPropsWithUrl[]>((result, element) => {\n const isImage = element.tagName === 'IMG';\n const link = isImage\n ? element.getAttribute('src')\n : element.getAttribute('href');\n\n if (link && !customFiles?.some((item) => item.url === link)) {\n const extension = link.match(extensionRegex)?.[0] || '';\n\n if (isImage || supportedExtensions.includes(extension)) {\n const name =\n (isImage\n ? element.getAttribute('alt')\n : element.getAttribute('title')) || '';\n\n result.push({\n ...(supportedVideoExtensions.includes(extension)\n ? getGalleryItemVideo({src: link, name: name})\n : getGalleryItemImage({src: link, name: name})),\n url: link,\n });\n }\n }\n\n return result;\n }, []);\n\n const files = [...(customFiles ?? []), ...filesFromContent];\n\n const initialItemIndex = files.findIndex((item) => item.url === fileLink);\n\n if (initialItemIndex !== -1) {\n event.preventDefault();\n openGallery(files, initialItemIndex);\n return true;\n }\n\n return false;\n },\n [customFiles, openGallery],\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"useFilesGallery.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/useFilesGallery.tsx"],"names":[],"mappings":";;AAiBA,0CAoIC;;AArJD,qDAA+B;AAE/B,uDAOgC;AAChC,6CAA6C;AAE7C,4DAAsC;AAEtC,8CAA0F;AAG1F,SAAgB,eAAe,CAC3B,WAAuC,EACvC,EACI,QAAQ,EAAE,mBAAmB,EAC7B,iBAAiB,EACjB,OAAO,EAAE,cAAc,MACC,EAAE;IAE9B,MAAM,EAAC,WAAW,EAAC,GAAG,IAAA,uBAAU,GAAE,CAAC;IAEnC,MAAM,OAAO,GAAG,IAAA,kBAAU,GAAE,CAAC;IAE7B,OAAO;QACH,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAC/B,CAAC,KAAuC,EAAE,EAAE;YACxC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE,CAAC;gBACzC,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,IAAI,QAAQ,GAAG,EAAE,CAAC;YAElB,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/D,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACtD,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;gBACtC,QAAQ,GAAG,KAA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YAEP,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;YAE5D,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;YAE1E,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACrC,OAAO,IAAI,CAAC;YAChB,CAAC;YAED,OAAO,KAAK,CAAC;QACjB,CAAC,EACD;YACI,WAAW;YACX,cAAc;YACd,mBAAmB;YACnB,iBAAiB;YACjB,OAAO;YACP,WAAW;SACd,CACJ;KACJ,CAAC;AACN,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {\n type GalleryItemAction,\n getGalleryItemCopyLinkAction,\n getGalleryItemDownloadAction,\n getGalleryItemImage,\n getGalleryItemVideo,\n useGallery,\n} from '@gravity-ui/components';\nimport {useToaster} from '@gravity-ui/uikit';\n\nimport {i18n} from 'src/i18n/gallery';\n\nimport {extensionRegex, supportedExtensions, supportedVideoExtensions} from './constants';\nimport type {FilesGalleryItemType, GalleryItemPropsWithUrl, UseFilesGalleryOptions} from './types';\n\nexport function useFilesGallery(\n customFiles?: GalleryItemPropsWithUrl[],\n {\n download: getItemDownloladUrl,\n overrideItemProps,\n copyUrl: getItemCopyUrl,\n }: UseFilesGalleryOptions = {},\n) {\n const {openGallery} = useGallery();\n\n const toaster = useToaster();\n\n return {\n openFilesGallery: React.useCallback(\n (event: React.MouseEvent<HTMLDivElement>) => {\n if (!(event.target instanceof HTMLElement)) {\n return false;\n }\n\n let fileLink = '';\n\n if (event.target.tagName === 'IMG' && !event.target.closest('a')) {\n fileLink = event.target.getAttribute('src') ?? '';\n } else if (event.target.tagName === 'A') {\n fileLink = event.target.getAttribute('href') ?? '';\n }\n\n if (!fileLink) {\n return false;\n }\n\n const filesFromContent = [\n ...(event.currentTarget?.querySelectorAll('img,a') ?? []),\n ].reduce<GalleryItemPropsWithUrl[]>((result, element) => {\n const isImage = element.tagName === 'IMG';\n const link = isImage\n ? element.getAttribute('src')\n : element.getAttribute('href');\n\n if (link && !customFiles?.some((item) => item.url === link)) {\n const extension = link.match(extensionRegex)?.[0] || '';\n\n if (isImage || supportedExtensions.includes(extension)) {\n const name =\n (isImage\n ? element.getAttribute('alt')\n : element.getAttribute('title')) || '';\n\n const filesGalleryItemType: FilesGalleryItemType =\n supportedVideoExtensions.includes(extension) ? 'video' : 'image';\n const galleryItemActions: GalleryItemAction[] = [];\n\n const itemCopyUrl = getItemCopyUrl?.(\n link,\n filesGalleryItemType,\n element,\n );\n\n if (itemCopyUrl) {\n const handleLinkCopied = () => {\n toaster.add({\n theme: 'success',\n name: 'g-md-editor-gallery-copy-link',\n title: i18n('link_copied'),\n });\n };\n\n galleryItemActions.push(\n getGalleryItemCopyLinkAction({\n copyUrl: itemCopyUrl,\n onCopy: handleLinkCopied,\n }),\n );\n }\n\n const downloadUrl = getItemDownloladUrl?.(\n link,\n filesGalleryItemType,\n element,\n );\n\n if (downloadUrl) {\n galleryItemActions.push(\n getGalleryItemDownloadAction({downloadUrl}),\n );\n }\n\n const galleryItemProps = {\n ...(filesGalleryItemType === 'video'\n ? getGalleryItemVideo({src: link, name: name})\n : getGalleryItemImage({src: link, name: name})),\n url: link,\n actions: galleryItemActions,\n };\n\n result.push({\n ...galleryItemProps,\n ...overrideItemProps?.(\n link,\n filesGalleryItemType,\n element,\n galleryItemProps,\n ),\n });\n }\n }\n\n return result;\n }, []);\n\n const files = [...(customFiles ?? []), ...filesFromContent];\n\n const initialItemIndex = files.findIndex((item) => item.url === fileLink);\n\n if (initialItemIndex !== -1) {\n event.preventDefault();\n openGallery(files, initialItemIndex);\n return true;\n }\n\n return false;\n },\n [\n customFiles,\n getItemCopyUrl,\n getItemDownloladUrl,\n overrideItemProps,\n toaster,\n openGallery,\n ],\n ),\n };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ {
2
+ "link_copied": "The link copied",
3
+ "link_copy": "Copy link",
4
+ "file_download": "Download"
5
+ }
@@ -0,0 +1,7 @@
1
+ export declare const i18n: <G extends "link_copied" | "link_copy" | "file_download", S extends string>(key: G | (string extends S ? S : never), params?: {
2
+ [key: string]: any;
3
+ }) => S extends G ? {
4
+ link_copied: string;
5
+ link_copy: string;
6
+ file_download: string;
7
+ }[G] : string;
@@ -0,0 +1,6 @@
1
+ import { registerKeyset } from "../i18n.js";
2
+ import en from "./en.json";
3
+ import ru from "./ru.json";
4
+ const KEYSET = 'gallery';
5
+ export const i18n = registerKeyset(KEYSET, { en, ru });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../../src","sources":["i18n/gallery/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,mBAAgB;AAEvC,OAAO,EAAE,kBAAkB;AAC3B,OAAO,EAAE,kBAAkB;AAE3B,MAAM,MAAM,GAAG,SAAS,CAAC;AAEzB,MAAM,CAAC,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,EAAE,EAAC,EAAE,EAAE,EAAE,EAAC,CAAC,CAAC","sourcesContent":["import {registerKeyset} from '../i18n';\n\nimport en from './en.json';\nimport ru from './ru.json';\n\nconst KEYSET = 'gallery';\n\nexport const i18n = registerKeyset(KEYSET, {en, ru});\n"]}
@@ -0,0 +1,5 @@
1
+ {
2
+ "link_copied": "Ссылка скопирована",
3
+ "link_copy": "Скопировать ссылку",
4
+ "file_download": "Скачать"
5
+ }
@@ -1,3 +1,3 @@
1
1
  /** During build process, the current version will be injected here */
2
- export const VERSION = typeof '15.18.0' !== 'undefined' ? '15.18.0' : 'unknown';
2
+ export const VERSION = typeof '15.19.0' !== 'undefined' ? '15.19.0' : 'unknown';
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["/** During build process, the current version will be injected here */\nexport const VERSION = typeof '15.18.0' !== 'undefined' ? '15.18.0' : 'unknown';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"../../src","sources":["version.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["/** During build process, the current version will be injected here */\nexport const VERSION = typeof '15.19.0' !== 'undefined' ? '15.19.0' : 'unknown';\n"]}
@@ -2,3 +2,9 @@ import type { GalleryItemProps } from '@gravity-ui/components';
2
2
  export type GalleryItemPropsWithUrl = GalleryItemProps & {
3
3
  url?: string;
4
4
  };
5
+ export type FilesGalleryItemType = 'image' | 'video';
6
+ export type UseFilesGalleryOptions = {
7
+ download?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;
8
+ copyUrl?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;
9
+ overrideItemProps?: (url: string, type: FilesGalleryItemType, element: Element, currentProps: GalleryItemProps) => GalleryItemProps;
10
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {GalleryItemProps} from '@gravity-ui/components';\n\nexport type GalleryItemPropsWithUrl = GalleryItemProps & {\n // pass the url to be able to exclude the items from content if they are found in the custom files\n url?: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {GalleryItemProps} from '@gravity-ui/components';\n\nexport type GalleryItemPropsWithUrl = GalleryItemProps & {\n // pass the url to be able to exclude the items from content if they are found in the custom files\n url?: string;\n};\n\nexport type FilesGalleryItemType = 'image' | 'video';\n\nexport type UseFilesGalleryOptions = {\n download?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;\n copyUrl?: (url: string, type: FilesGalleryItemType, element: Element) => string | undefined;\n overrideItemProps?: (\n url: string,\n type: FilesGalleryItemType,\n element: Element,\n currentProps: GalleryItemProps,\n ) => GalleryItemProps;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { GalleryItemPropsWithUrl } from "./types.js";
3
- export declare function useFilesGallery(customFiles?: GalleryItemPropsWithUrl[]): {
2
+ import type { GalleryItemPropsWithUrl, UseFilesGalleryOptions } from "./types.js";
3
+ export declare function useFilesGallery(customFiles?: GalleryItemPropsWithUrl[], { download: getItemDownloladUrl, overrideItemProps, copyUrl: getItemCopyUrl, }?: UseFilesGalleryOptions): {
4
4
  openFilesGallery: (event: React.MouseEvent<HTMLDivElement>) => boolean;
5
5
  };
@@ -1,8 +1,11 @@
1
1
  import * as React from 'react';
2
- import { getGalleryItemImage, getGalleryItemVideo, useGallery } from '@gravity-ui/components';
2
+ import { getGalleryItemCopyLinkAction, getGalleryItemDownloadAction, getGalleryItemImage, getGalleryItemVideo, useGallery, } from '@gravity-ui/components';
3
+ import { useToaster } from '@gravity-ui/uikit';
4
+ import { i18n } from "../../../i18n/gallery/index.js";
3
5
  import { extensionRegex, supportedExtensions, supportedVideoExtensions } from "./constants.js";
4
- export function useFilesGallery(customFiles) {
6
+ export function useFilesGallery(customFiles, { download: getItemDownloladUrl, overrideItemProps, copyUrl: getItemCopyUrl, } = {}) {
5
7
  const { openGallery } = useGallery();
8
+ const toaster = useToaster();
6
9
  return {
7
10
  openFilesGallery: React.useCallback((event) => {
8
11
  if (!(event.target instanceof HTMLElement)) {
@@ -31,11 +34,36 @@ export function useFilesGallery(customFiles) {
31
34
  const name = (isImage
32
35
  ? element.getAttribute('alt')
33
36
  : element.getAttribute('title')) || '';
34
- result.push({
35
- ...(supportedVideoExtensions.includes(extension)
37
+ const filesGalleryItemType = supportedVideoExtensions.includes(extension) ? 'video' : 'image';
38
+ const galleryItemActions = [];
39
+ const itemCopyUrl = getItemCopyUrl?.(link, filesGalleryItemType, element);
40
+ if (itemCopyUrl) {
41
+ const handleLinkCopied = () => {
42
+ toaster.add({
43
+ theme: 'success',
44
+ name: 'g-md-editor-gallery-copy-link',
45
+ title: i18n('link_copied'),
46
+ });
47
+ };
48
+ galleryItemActions.push(getGalleryItemCopyLinkAction({
49
+ copyUrl: itemCopyUrl,
50
+ onCopy: handleLinkCopied,
51
+ }));
52
+ }
53
+ const downloadUrl = getItemDownloladUrl?.(link, filesGalleryItemType, element);
54
+ if (downloadUrl) {
55
+ galleryItemActions.push(getGalleryItemDownloadAction({ downloadUrl }));
56
+ }
57
+ const galleryItemProps = {
58
+ ...(filesGalleryItemType === 'video'
36
59
  ? getGalleryItemVideo({ src: link, name: name })
37
60
  : getGalleryItemImage({ src: link, name: name })),
38
61
  url: link,
62
+ actions: galleryItemActions,
63
+ };
64
+ result.push({
65
+ ...galleryItemProps,
66
+ ...overrideItemProps?.(link, filesGalleryItemType, element, galleryItemProps),
39
67
  });
40
68
  }
41
69
  }
@@ -49,7 +77,14 @@ export function useFilesGallery(customFiles) {
49
77
  return true;
50
78
  }
51
79
  return false;
52
- }, [customFiles, openGallery]),
80
+ }, [
81
+ customFiles,
82
+ getItemCopyUrl,
83
+ getItemDownloladUrl,
84
+ overrideItemProps,
85
+ toaster,
86
+ openGallery,
87
+ ]),
53
88
  };
54
89
  }
55
90
  //# sourceMappingURL=useFilesGallery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFilesGallery.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/useFilesGallery.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KA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C,CAAC;YAE1E,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACrC,OAAO,IAAI,CAAC;YAChB,CAAC;YAED,OAAO,KAAK,CAAC;QACjB,CAAC,EACD,CAAC,WAAW,EAAE,WAAW,CAAC,CAC7B;KACJ,CAAC;AACN,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {getGalleryItemImage, getGalleryItemVideo, useGallery} from '@gravity-ui/components';\n\nimport {extensionRegex, supportedExtensions, supportedVideoExtensions} from './constants';\nimport type {GalleryItemPropsWithUrl} from './types';\n\nexport function useFilesGallery(customFiles?: GalleryItemPropsWithUrl[]) {\n const {openGallery} = useGallery();\n\n return {\n openFilesGallery: React.useCallback(\n (event: React.MouseEvent<HTMLDivElement>) => {\n if (!(event.target instanceof HTMLElement)) {\n return false;\n }\n\n let fileLink = '';\n\n if (event.target.tagName === 'IMG' && !event.target.closest('a')) {\n fileLink = event.target.getAttribute('src') ?? '';\n } else if (event.target.tagName === 'A') {\n fileLink = event.target.getAttribute('href') ?? '';\n }\n\n if (!fileLink) {\n return false;\n }\n\n const filesFromContent = [\n ...(event.currentTarget?.querySelectorAll('img,a') ?? []),\n ].reduce<GalleryItemPropsWithUrl[]>((result, element) => {\n const isImage = element.tagName === 'IMG';\n const link = isImage\n ? element.getAttribute('src')\n : element.getAttribute('href');\n\n if (link && !customFiles?.some((item) => item.url === link)) {\n const extension = link.match(extensionRegex)?.[0] || '';\n\n if (isImage || supportedExtensions.includes(extension)) {\n const name =\n (isImage\n ? element.getAttribute('alt')\n : element.getAttribute('title')) || '';\n\n result.push({\n ...(supportedVideoExtensions.includes(extension)\n ? getGalleryItemVideo({src: link, name: name})\n : getGalleryItemImage({src: link, name: name})),\n url: link,\n });\n }\n }\n\n return result;\n }, []);\n\n const files = [...(customFiles ?? []), ...filesFromContent];\n\n const initialItemIndex = files.findIndex((item) => item.url === fileLink);\n\n if (initialItemIndex !== -1) {\n event.preventDefault();\n openGallery(files, initialItemIndex);\n return true;\n }\n\n return false;\n },\n [customFiles, openGallery],\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"useFilesGallery.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/useFilesGallery.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAEH,4BAA4B,EAC5B,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAC,IAAI,EAAC,uCAAyB;AAEtC,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAE,wBAAwB,EAAC,uBAAoB;AAG1F,MAAM,UAAU,eAAe,CAC3B,WAAuC,EACvC,EACI,QAAQ,EAAE,mBAAmB,EAC7B,iBAAiB,EACjB,OAAO,EAAE,cAAc,MACC,EAAE;IAE9B,MAAM,EAAC,WAAW,EAAC,GAAG,UAAU,EAAE,CAAC;IAEnC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,OAAO;QACH,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAC/B,CAAC,KAAuC,EAAE,EAAE;YACxC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE,CAAC;gBACzC,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,IAAI,QAAQ,GAAG,EAAE,CAAC;YAElB,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/D,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACtD,CAAC;iBAAM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OAAO,MAAM,CAAC;YAClB,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;YAE5D,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;YAE1E,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACrC,OAAO,IAAI,CAAC;YAChB,CAAC;YAED,OAAO,KAAK,CAAC;QACjB,CAAC,EACD;YACI,WAAW;YACX,cAAc;YACd,mBAAmB;YACnB,iBAAiB;YACjB,OAAO;YACP,WAAW;SACd,CACJ;KACJ,CAAC;AACN,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {\n type GalleryItemAction,\n getGalleryItemCopyLinkAction,\n getGalleryItemDownloadAction,\n getGalleryItemImage,\n getGalleryItemVideo,\n useGallery,\n} from '@gravity-ui/components';\nimport {useToaster} from '@gravity-ui/uikit';\n\nimport {i18n} from 'src/i18n/gallery';\n\nimport {extensionRegex, supportedExtensions, supportedVideoExtensions} from './constants';\nimport type {FilesGalleryItemType, GalleryItemPropsWithUrl, UseFilesGalleryOptions} from './types';\n\nexport function useFilesGallery(\n customFiles?: GalleryItemPropsWithUrl[],\n {\n download: getItemDownloladUrl,\n overrideItemProps,\n copyUrl: getItemCopyUrl,\n }: UseFilesGalleryOptions = {},\n) {\n const {openGallery} = useGallery();\n\n const toaster = useToaster();\n\n return {\n openFilesGallery: React.useCallback(\n (event: React.MouseEvent<HTMLDivElement>) => {\n if (!(event.target instanceof HTMLElement)) {\n return false;\n }\n\n let fileLink = '';\n\n if (event.target.tagName === 'IMG' && !event.target.closest('a')) {\n fileLink = event.target.getAttribute('src') ?? '';\n } else if (event.target.tagName === 'A') {\n fileLink = event.target.getAttribute('href') ?? '';\n }\n\n if (!fileLink) {\n return false;\n }\n\n const filesFromContent = [\n ...(event.currentTarget?.querySelectorAll('img,a') ?? []),\n ].reduce<GalleryItemPropsWithUrl[]>((result, element) => {\n const isImage = element.tagName === 'IMG';\n const link = isImage\n ? element.getAttribute('src')\n : element.getAttribute('href');\n\n if (link && !customFiles?.some((item) => item.url === link)) {\n const extension = link.match(extensionRegex)?.[0] || '';\n\n if (isImage || supportedExtensions.includes(extension)) {\n const name =\n (isImage\n ? element.getAttribute('alt')\n : element.getAttribute('title')) || '';\n\n const filesGalleryItemType: FilesGalleryItemType =\n supportedVideoExtensions.includes(extension) ? 'video' : 'image';\n const galleryItemActions: GalleryItemAction[] = [];\n\n const itemCopyUrl = getItemCopyUrl?.(\n link,\n filesGalleryItemType,\n element,\n );\n\n if (itemCopyUrl) {\n const handleLinkCopied = () => {\n toaster.add({\n theme: 'success',\n name: 'g-md-editor-gallery-copy-link',\n title: i18n('link_copied'),\n });\n };\n\n galleryItemActions.push(\n getGalleryItemCopyLinkAction({\n copyUrl: itemCopyUrl,\n onCopy: handleLinkCopied,\n }),\n );\n }\n\n const downloadUrl = getItemDownloladUrl?.(\n link,\n filesGalleryItemType,\n element,\n );\n\n if (downloadUrl) {\n galleryItemActions.push(\n getGalleryItemDownloadAction({downloadUrl}),\n );\n }\n\n const galleryItemProps = {\n ...(filesGalleryItemType === 'video'\n ? getGalleryItemVideo({src: link, name: name})\n : getGalleryItemImage({src: link, name: name})),\n url: link,\n actions: galleryItemActions,\n };\n\n result.push({\n ...galleryItemProps,\n ...overrideItemProps?.(\n link,\n filesGalleryItemType,\n element,\n galleryItemProps,\n ),\n });\n }\n }\n\n return result;\n }, []);\n\n const files = [...(customFiles ?? []), ...filesFromContent];\n\n const initialItemIndex = files.findIndex((item) => item.url === fileLink);\n\n if (initialItemIndex !== -1) {\n event.preventDefault();\n openGallery(files, initialItemIndex);\n return true;\n }\n\n return false;\n },\n [\n customFiles,\n getItemCopyUrl,\n getItemDownloladUrl,\n overrideItemProps,\n toaster,\n openGallery,\n ],\n ),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/markdown-editor",
3
- "version": "15.18.0",
3
+ "version": "15.19.0",
4
4
  "description": "Markdown wysiwyg and markup editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -229,7 +229,7 @@
229
229
  "@diplodoc/quote-link-extension": "0.1.3",
230
230
  "@diplodoc/tabs-extension": "^3.5.1",
231
231
  "@diplodoc/transform": "^4.58.0",
232
- "@gravity-ui/components": "4.2.2",
232
+ "@gravity-ui/components": "4.10.0",
233
233
  "@gravity-ui/eslint-config": "3.3.0",
234
234
  "@gravity-ui/gulp-utils": "1.0.3",
235
235
  "@gravity-ui/prettier-config": "1.1.0",
@@ -327,7 +327,7 @@
327
327
  "@diplodoc/quote-link-extension": "^0.1.3",
328
328
  "@diplodoc/tabs-extension": "^3.5.1",
329
329
  "@diplodoc/transform": "^4.43.0",
330
- "@gravity-ui/components": "^4.2.2",
330
+ "@gravity-ui/components": "^4.10.0",
331
331
  "@gravity-ui/uikit": "^7.1.0",
332
332
  "highlight.js": "^11.8.0",
333
333
  "katex": "^0.16.9",