@gravity-ui/markdown-editor 15.11.1 → 15.12.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.
- package/build/cjs/version.js +1 -1
- package/build/cjs/version.js.map +1 -1
- package/build/cjs/view/hooks/index.d.ts +1 -0
- package/build/cjs/view/hooks/index.js +1 -0
- package/build/cjs/view/hooks/index.js.map +1 -1
- package/build/cjs/view/hooks/useFilesGallery/constants.d.ts +4 -0
- package/build/cjs/view/hooks/useFilesGallery/constants.js +8 -0
- package/build/cjs/view/hooks/useFilesGallery/constants.js.map +1 -0
- package/build/cjs/view/hooks/useFilesGallery/index.d.ts +2 -0
- package/build/cjs/view/hooks/useFilesGallery/index.js +6 -0
- package/build/cjs/view/hooks/useFilesGallery/index.js.map +1 -0
- package/build/cjs/view/hooks/useFilesGallery/types.d.ts +4 -0
- package/build/cjs/view/hooks/useFilesGallery/types.js +3 -0
- package/build/cjs/view/hooks/useFilesGallery/types.js.map +1 -0
- package/build/cjs/view/hooks/useFilesGallery/useFilesGallery.d.ts +5 -0
- package/build/cjs/view/hooks/useFilesGallery/useFilesGallery.js +56 -0
- package/build/cjs/view/hooks/useFilesGallery/useFilesGallery.js.map +1 -0
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esm/view/hooks/index.d.ts +1 -0
- package/build/esm/view/hooks/index.js +1 -0
- package/build/esm/view/hooks/index.js.map +1 -1
- package/build/esm/view/hooks/useFilesGallery/constants.d.ts +4 -0
- package/build/esm/view/hooks/useFilesGallery/constants.js +5 -0
- package/build/esm/view/hooks/useFilesGallery/constants.js.map +1 -0
- package/build/esm/view/hooks/useFilesGallery/index.d.ts +2 -0
- package/build/esm/view/hooks/useFilesGallery/index.js +3 -0
- package/build/esm/view/hooks/useFilesGallery/index.js.map +1 -0
- package/build/esm/view/hooks/useFilesGallery/types.d.ts +4 -0
- package/build/esm/view/hooks/useFilesGallery/types.js +2 -0
- package/build/esm/view/hooks/useFilesGallery/types.js.map +1 -0
- package/build/esm/view/hooks/useFilesGallery/useFilesGallery.d.ts +5 -0
- package/build/esm/view/hooks/useFilesGallery/useFilesGallery.js +52 -0
- package/build/esm/view/hooks/useFilesGallery/useFilesGallery.js.map +1 -0
- package/package.json +9 -4
package/build/cjs/version.js
CHANGED
|
@@ -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.
|
|
5
|
+
exports.VERSION = typeof '15.12.0' !== 'undefined' ? '15.12.0' : 'unknown';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/build/cjs/version.js.map
CHANGED
|
@@ -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.
|
|
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.12.0' !== 'undefined' ? '15.12.0' : 'unknown';\n"]}
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./useYfmShowElemWithId/index.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./useFilesGallery/index.js"), exports);
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../src","sources":["view/hooks/index.ts"],"names":[],"mappings":";;;AAAA,0EAAuC","sourcesContent":["export * from './useYfmShowElemWithId';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../src","sources":["view/hooks/index.ts"],"names":[],"mappings":";;;AAAA,0EAAuC;AACvC,qEAAkC","sourcesContent":["export * from './useYfmShowElemWithId';\nexport * from './useFilesGallery';\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extensionRegex = exports.supportedExtensions = exports.supportedVideoExtensions = exports.supportedImageExtensions = void 0;
|
|
4
|
+
exports.supportedImageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'avif', 'bmp'];
|
|
5
|
+
exports.supportedVideoExtensions = ['mp4', 'webm', 'ogg'];
|
|
6
|
+
exports.supportedExtensions = [...exports.supportedImageExtensions, ...exports.supportedVideoExtensions];
|
|
7
|
+
exports.extensionRegex = /\w+?$/;
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,wBAAwB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEvF,QAAA,wBAAwB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAElD,QAAA,mBAAmB,GAAG,CAAC,GAAG,gCAAwB,EAAE,GAAG,gCAAwB,CAAC,CAAC;AAEjF,QAAA,cAAc,GAAG,OAAO,CAAC","sourcesContent":["export const supportedImageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'avif', 'bmp'];\n\nexport const supportedVideoExtensions = ['mp4', 'webm', 'ogg'];\n\nexport const supportedExtensions = [...supportedImageExtensions, ...supportedVideoExtensions];\n\nexport const extensionRegex = /\\w+?$/;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./useFilesGallery.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/index.ts"],"names":[],"mappings":";;;AAAA,+DAAkC;AAClC,qDAAwB","sourcesContent":["export * from './useFilesGallery';\nexport * from './types';\n"]}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFilesGallery = useFilesGallery;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const React = tslib_1.__importStar(require("react"));
|
|
6
|
+
const components_1 = require("@gravity-ui/components");
|
|
7
|
+
const constants_1 = require("./constants.js");
|
|
8
|
+
function useFilesGallery(customFiles) {
|
|
9
|
+
const { openGallery } = (0, components_1.useGallery)();
|
|
10
|
+
return {
|
|
11
|
+
openFilesGallery: React.useCallback((event) => {
|
|
12
|
+
if (event.target instanceof HTMLElement) {
|
|
13
|
+
let fileLink = '';
|
|
14
|
+
if (event.target.tagName === 'IMG' && !event.target.closest('a')) {
|
|
15
|
+
fileLink = event.target.getAttribute('src') ?? '';
|
|
16
|
+
}
|
|
17
|
+
else if (event.target.tagName === 'A') {
|
|
18
|
+
fileLink = event.target.getAttribute('href') ?? '';
|
|
19
|
+
}
|
|
20
|
+
if (!fileLink) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const filesFromContent = [
|
|
24
|
+
...(event.currentTarget?.querySelectorAll('img,a') ?? []),
|
|
25
|
+
].reduce((result, element) => {
|
|
26
|
+
const isImage = element.tagName === 'IMG';
|
|
27
|
+
const link = isImage
|
|
28
|
+
? element.getAttribute('src')
|
|
29
|
+
: element.getAttribute('href');
|
|
30
|
+
if (link && !customFiles?.some((item) => item.url === link)) {
|
|
31
|
+
const extension = link.match(constants_1.extensionRegex)?.[0] || '';
|
|
32
|
+
if (isImage || constants_1.supportedExtensions.includes(extension)) {
|
|
33
|
+
const name = (isImage
|
|
34
|
+
? element.getAttribute('alt')
|
|
35
|
+
: element.getAttribute('title')) || '';
|
|
36
|
+
result.push({
|
|
37
|
+
...(constants_1.supportedVideoExtensions.includes(extension)
|
|
38
|
+
? (0, components_1.getGalleryItemVideo)({ src: link, name: name })
|
|
39
|
+
: (0, components_1.getGalleryItemImage)({ src: link, name: name })),
|
|
40
|
+
url: link,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}, []);
|
|
46
|
+
const files = [...(customFiles ?? []), ...filesFromContent];
|
|
47
|
+
const initialItemIndex = files.findIndex((item) => item.url === fileLink);
|
|
48
|
+
if (initialItemIndex !== -1) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
openGallery(files, initialItemIndex);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [customFiles, openGallery]),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=useFilesGallery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFilesGallery.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/useFilesGallery.tsx"],"names":[],"mappings":";;AAOA,0CA6DC;;AApED,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,KAAK,CAAC,MAAM,YAAY,WAAW,EAAE,CAAC;gBACtC,IAAI,QAAQ,GAAG,EAAE,CAAC;gBAElB,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC/D,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;gBACtD,CAAC;qBAAM,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;oBACtC,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACvD,CAAC;gBAED,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACZ,OAAO;gBACX,CAAC;gBAED,MAAM,gBAAgB,GAAG;oBACrB,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;iBAC5D,CAAC,MAAM,CAA4B,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;oBACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC;oBAC1C,MAAM,IAAI,GAAG,OAAO;wBAChB,CAAC,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AQ,CAAC,CAAC;gBAE1E,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;oBAC1B,KAAK,CAAC,cAAc,EAAE,CAAC;oBACvB,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACzC,CAAC;YACL,CAAC;QACL,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 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;\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 }\n }\n },\n [customFiles, openGallery],\n ),\n };\n}\n"]}
|
package/build/esm/version.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** During build process, the current version will be injected here */
|
|
2
|
-
export const VERSION = typeof '15.
|
|
2
|
+
export const VERSION = typeof '15.12.0' !== 'undefined' ? '15.12.0' : 'unknown';
|
|
3
3
|
//# sourceMappingURL=version.js.map
|
package/build/esm/version.js.map
CHANGED
|
@@ -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.
|
|
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.12.0' !== 'undefined' ? '15.12.0' : 'unknown';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../../../../src","sources":["view/hooks/index.ts"],"names":[],"mappings":"AAAA,gDAAuC","sourcesContent":["export * from './useYfmShowElemWithId';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../src","sources":["view/hooks/index.ts"],"names":[],"mappings":"AAAA,gDAAuC;AACvC,2CAAkC","sourcesContent":["export * from './useYfmShowElemWithId';\nexport * from './useFilesGallery';\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const supportedImageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'avif', 'bmp'];
|
|
2
|
+
export const supportedVideoExtensions = ['mp4', 'webm', 'ogg'];
|
|
3
|
+
export const supportedExtensions = [...supportedImageExtensions, ...supportedVideoExtensions];
|
|
4
|
+
export const extensionRegex = /\w+?$/;
|
|
5
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEpG,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,wBAAwB,EAAE,GAAG,wBAAwB,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC","sourcesContent":["export const supportedImageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'avif', 'bmp'];\n\nexport const supportedVideoExtensions = ['mp4', 'webm', 'ogg'];\n\nexport const supportedExtensions = [...supportedImageExtensions, ...supportedVideoExtensions];\n\nexport const extensionRegex = /\\w+?$/;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["view/hooks/useFilesGallery/index.ts"],"names":[],"mappings":"AAAA,qCAAkC;AAClC,2BAAwB","sourcesContent":["export * from './useFilesGallery';\nexport * from './types';\n"]}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getGalleryItemImage, getGalleryItemVideo, useGallery } from '@gravity-ui/components';
|
|
3
|
+
import { extensionRegex, supportedExtensions, supportedVideoExtensions } from "./constants.js";
|
|
4
|
+
export function useFilesGallery(customFiles) {
|
|
5
|
+
const { openGallery } = useGallery();
|
|
6
|
+
return {
|
|
7
|
+
openFilesGallery: React.useCallback((event) => {
|
|
8
|
+
if (event.target instanceof HTMLElement) {
|
|
9
|
+
let fileLink = '';
|
|
10
|
+
if (event.target.tagName === 'IMG' && !event.target.closest('a')) {
|
|
11
|
+
fileLink = event.target.getAttribute('src') ?? '';
|
|
12
|
+
}
|
|
13
|
+
else if (event.target.tagName === 'A') {
|
|
14
|
+
fileLink = event.target.getAttribute('href') ?? '';
|
|
15
|
+
}
|
|
16
|
+
if (!fileLink) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const filesFromContent = [
|
|
20
|
+
...(event.currentTarget?.querySelectorAll('img,a') ?? []),
|
|
21
|
+
].reduce((result, element) => {
|
|
22
|
+
const isImage = element.tagName === 'IMG';
|
|
23
|
+
const link = isImage
|
|
24
|
+
? element.getAttribute('src')
|
|
25
|
+
: element.getAttribute('href');
|
|
26
|
+
if (link && !customFiles?.some((item) => item.url === link)) {
|
|
27
|
+
const extension = link.match(extensionRegex)?.[0] || '';
|
|
28
|
+
if (isImage || supportedExtensions.includes(extension)) {
|
|
29
|
+
const name = (isImage
|
|
30
|
+
? element.getAttribute('alt')
|
|
31
|
+
: element.getAttribute('title')) || '';
|
|
32
|
+
result.push({
|
|
33
|
+
...(supportedVideoExtensions.includes(extension)
|
|
34
|
+
? getGalleryItemVideo({ src: link, name: name })
|
|
35
|
+
: getGalleryItemImage({ src: link, name: name })),
|
|
36
|
+
url: link,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}, []);
|
|
42
|
+
const files = [...(customFiles ?? []), ...filesFromContent];
|
|
43
|
+
const initialItemIndex = files.findIndex((item) => item.url === fileLink);
|
|
44
|
+
if (initialItemIndex !== -1) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
openGallery(files, initialItemIndex);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [customFiles, openGallery]),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=useFilesGallery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAC,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAE5F,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAE,wBAAwB,EAAC,uBAAoB;AAG1F,MAAM,UAAU,eAAe,CAAC,WAAuC;IACnE,MAAM,EAAC,WAAW,EAAC,GAAG,UAAU,EAAE,CAAC;IAEnC,OAAO;QACH,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAC/B,CAAC,KAAuC,EAAE,EAAE;YACxC,IAAI,KAAK,CAAC,MAAM,YAAY,WAAW,EAAE,CAAC;gBACtC,IAAI,QAAQ,GAAG,EAAE,CAAC;gBAElB,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC/D,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;gBACtD,CAAC;qBAAM,IAAI,KA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AE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC;oCAC9C,CAAC,CAAC,mBAAmB,CAAC,EAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;gCACnD,GAAG,EAAE,IAAI;6BACZ,CAAC,CAAC;wBACP,CAAC;oBACL,CAAC;oBAED,OAAO,MAAM,CAAC;gBAClB,CAAC,EAAE,EAAE,CAAC,CAAC;gBAEP,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;gBAE5D,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC;gBAE1E,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;oBAC1B,KAAK,CAAC,cAAc,EAAE,CAAC;oBACvB,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACzC,CAAC;YACL,CAAC;QACL,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 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;\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 }\n }\n },\n [customFiles, openGallery],\n ),\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/markdown-editor",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.12.0",
|
|
4
4
|
"description": "Markdown wysiwyg and markup editor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -225,15 +225,16 @@
|
|
|
225
225
|
"@diplodoc/html-extension": "2.7.1",
|
|
226
226
|
"@diplodoc/latex-extension": "1.0.3",
|
|
227
227
|
"@diplodoc/mermaid-extension": "1.2.1",
|
|
228
|
-
"@diplodoc/quote-link-extension": "0.1.
|
|
228
|
+
"@diplodoc/quote-link-extension": "0.1.3",
|
|
229
229
|
"@diplodoc/tabs-extension": "^3.5.1",
|
|
230
230
|
"@diplodoc/transform": "^4.57.2",
|
|
231
|
+
"@gravity-ui/components": "4.2.2",
|
|
231
232
|
"@gravity-ui/eslint-config": "3.3.0",
|
|
232
233
|
"@gravity-ui/gulp-utils": "1.0.3",
|
|
233
234
|
"@gravity-ui/prettier-config": "1.1.0",
|
|
234
235
|
"@gravity-ui/stylelint-config": "4.0.1",
|
|
235
236
|
"@gravity-ui/tsconfig": "1.0.0",
|
|
236
|
-
"@gravity-ui/uikit": "7.
|
|
237
|
+
"@gravity-ui/uikit": "7.10.0",
|
|
237
238
|
"@playwright/experimental-ct-react": "1.49.0",
|
|
238
239
|
"@playwright/test": "1.49.0",
|
|
239
240
|
"@storybook/addon-docs": "8.4.1",
|
|
@@ -310,6 +311,9 @@
|
|
|
310
311
|
},
|
|
311
312
|
"lowlight": {
|
|
312
313
|
"optional": true
|
|
314
|
+
},
|
|
315
|
+
"@gravity-ui/components": {
|
|
316
|
+
"optional": true
|
|
313
317
|
}
|
|
314
318
|
},
|
|
315
319
|
"peerDependencies": {
|
|
@@ -319,9 +323,10 @@
|
|
|
319
323
|
"@diplodoc/html-extension": "^2.3.2",
|
|
320
324
|
"@diplodoc/latex-extension": "^1.0.3",
|
|
321
325
|
"@diplodoc/mermaid-extension": "^1.0.0",
|
|
322
|
-
"@diplodoc/quote-link-extension": "^0.1.
|
|
326
|
+
"@diplodoc/quote-link-extension": "^0.1.3",
|
|
323
327
|
"@diplodoc/tabs-extension": "^3.5.1",
|
|
324
328
|
"@diplodoc/transform": "^4.43.0",
|
|
329
|
+
"@gravity-ui/components": "^4.2.2",
|
|
325
330
|
"@gravity-ui/uikit": "^7.1.0",
|
|
326
331
|
"highlight.js": "^11.8.0",
|
|
327
332
|
"katex": "^0.16.9",
|