@gravity-ui/markdown-editor 15.11.1 → 15.12.1
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/bundle/MarkdownEditorView.js +1 -1
- package/build/cjs/bundle/MarkdownEditorView.js.map +1 -1
- package/build/cjs/extensions/additional/GPT/MarkupGpt/popup.js +2 -1
- package/build/cjs/extensions/additional/GPT/MarkupGpt/popup.js.map +1 -1
- 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/bundle/MarkdownEditorView.js +1 -1
- package/build/esm/bundle/MarkdownEditorView.js.map +1 -1
- package/build/esm/extensions/additional/GPT/MarkupGpt/popup.js +2 -1
- package/build/esm/extensions/additional/GPT/MarkupGpt/popup.js.map +1 -1
- 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
|
@@ -88,7 +88,7 @@ const EditorWrapper = (0, react_1.forwardRef)(({ autofocus, editor, editorMode,
|
|
|
88
88
|
mode: 'preview',
|
|
89
89
|
md: editor.mdOptions,
|
|
90
90
|
directiveSyntax: editor.directiveSyntax,
|
|
91
|
-
}) }), (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: settingsVisibleProp })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [editorMode === 'wysiwyg' && ((0, jsx_runtime_1.jsx)(WysiwygEditorView_1.WysiwygEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: wysiwygToolbarConfig, toolbarVisible: editor.toolbarVisible, hiddenActionsConfig: wysiwygHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), editorMode === 'markup' && ((0, jsx_runtime_1.jsx)(MarkupEditorView_1.MarkupEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: markupToolbarConfig, toolbarVisible: editor.toolbarVisible, splitMode: editor.splitMode, splitModeEnabled: editor.splitModeEnabled, hiddenActionsConfig: markupHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: !editor.toolbarVisible && settingsVisibleProp, renderPreviewButton: !editor.toolbarVisible &&
|
|
91
|
+
}) }), (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: settingsVisibleProp })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [editorMode === 'wysiwyg' && ((0, jsx_runtime_1.jsx)(WysiwygEditorView_1.WysiwygEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: wysiwygToolbarConfig, toolbarVisible: editor.toolbarVisible, hiddenActionsConfig: wysiwygHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), editorMode === 'markup' && ((0, jsx_runtime_1.jsx)(MarkupEditorView_1.MarkupEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: markupToolbarConfig, toolbarVisible: editor.toolbarVisible, splitMode: editor.splitMode, splitModeEnabled: editor.splitModeEnabled, hiddenActionsConfig: markupHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), (0, jsx_runtime_1.jsx)(Settings, { ...settingsProps, settingsVisible: !editor.toolbarVisible && settingsVisibleProp, renderPreviewButton: !editor.toolbarVisible && canRenderPreview })] })) }));
|
|
92
92
|
});
|
|
93
93
|
EditorWrapper.displayName = 'EditorWrapper';
|
|
94
94
|
exports.MarkdownEditorView = (0, react_1.forwardRef)((props, ref) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownEditorView.js","sourceRoot":"../../../src","sources":["bundle/MarkdownEditorView.tsx"],"names":[],"mappings":";;;;AAAA,iCAQe;AAEf,6CAA2D;AAC3D,+DAAmD;AACnD,yCAAoE;AAEpE,+CAAqD;AACrD,oDAAoC;AACpC,yCAAuC;AAEvC,yDAA0D;AAC1D,6CAA+B;AAG/B,wDAAgD;AAChD,4DAAoD;AACpD,sDAA8C;AAC9C,8DAAsD;AACtD,0CAAmD;AACnD,kDAAuF;AACvF,8CAAkC;AAElC,wEAAmE;AAGnE,gCAA+B;AAC/B,oCAAmC,CAAC,mCAAmC;AAE1D,QAAA,iBAAiB,GAAG,IAAA,cAAE,EAAC,kBAAkB,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,yBAAiB,CAAC;AAU5B,MAAM,aAAa,GAAG,IAAA,kBAAU,EAC5B,CACI,EACI,SAAS,EACT,MAAM,EACN,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACtB,SAAS,EACT,yBAAyB,EAAE,gCAAgC,EAC3D,mBAAmB,EAAE,0BAA0B,EAC/C,EAAE,EACF,eAAe,EAAE,mBAAmB,EACpC,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,0BAA0B,EAAE,iCAAiC,EAC7D,oBAAoB,EAAE,2BAA2B,GACpD,EACD,GAAG,EACL,EAAE;IACA,MAAM,EACF,oBAAoB,EACpB,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,GAC5B,GAAG,IAAA,eAAO,EACP,GAAG,EAAE,CACD,IAAA,oCAAkB,EAAC;QACf,cAAc;QACd,KAAK,EAAE;YACH,oBAAoB,EAAE,2BAA2B;YACjD,mBAAmB,EAAE,0BAA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Q,CAAC,QAAQ,CAAC;oBACzB,WAAW,EAAE,KAAK,CAAC,iBAAiB;oBACpC,YAAY,EAAE,QAAQ;iBACzB,CAAC,aAEF,uBAAC,yBAAc,OAAK,KAAK,GAAI,EAC7B,uBAAC,kBAAkB,OAAK,KAAK,GAAI,IAC/B,GACJ,CACT,GACF,CACN,CAAC;AACN,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAgB;IACtC,MAAM,MAAM,GAAG,IAAA,aAAK,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,OAAO,MAAM,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;AACrD,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAuC;IAC7D,OAAO,QAAQ,CAAC,aAAa,KAAK,MAAM,CAAC,OAAO,CAAC;AACrD,CAAC;AAED,SAAS,eAAe,CAAC,CAAgB;IACrC,MAAM,MAAM,GAAG,IAAA,aAAK,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,OAAO,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;AACxC,CAAC","sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {type QAProps, useToaster} from '@gravity-ui/uikit';\nimport {ErrorBoundary} from 'react-error-boundary';\nimport {useEnsuredForwardedRef, useKey, useUpdate} from 'react-use';\n\nimport {type ClassNameProps, cn} from '../classname';\nimport {i18n} from '../i18n/bundle';\nimport {globalLogger} from '../logger';\nimport type {ToolbarsPreset} from '../modules/toolbars/types';\nimport {useBooleanState, useSticky} from '../react-utils';\nimport {isMac} from '../utils';\n\nimport type {Editor, EditorInt} from './Editor';\nimport {HorizontalDrag} from './HorizontalDrag';\nimport {MarkupEditorView} from './MarkupEditorView';\nimport {SplitModeView} from './SplitModeView';\nimport {WysiwygEditorView} from './WysiwygEditorView';\nimport {useMarkdownEditorContext} from './context';\nimport {EditorSettings, type EditorSettingsProps, type SettingItems} from './settings';\nimport {stickyCn} from './sticky';\nimport type {MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData} from './toolbar/types';\nimport {getToolbarsConfigs} from './toolbar/utils/toolbarsConfigs';\nimport type {MarkdownEditorMode} from './types';\n\nimport '../styles/styles.scss';\nimport './MarkdownEditorView.scss'; // eslint-disable-line import/order\n\nexport const cnEditorComponent = cn('editor-component');\nconst b = cnEditorComponent;\n\ninterface EditorWrapperProps extends QAProps, ToolbarConfigs, Omit<ViewProps, 'editor'> {\n editor: EditorInt;\n editorMode: MarkdownEditorMode;\n isFocused: boolean;\n showPreview: boolean;\n toggleShowPreview: () => void;\n unsetShowPreview: () => void;\n}\nconst EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(\n (\n {\n autofocus,\n editor,\n editorMode,\n enableSubmitInPreview,\n hidePreviewAfterSubmit,\n isFocused,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n qa,\n settingsVisible: settingsVisibleProp,\n showPreview,\n stickyToolbar,\n toggleShowPreview,\n toolbarsPreset,\n unsetShowPreview,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n },\n ref,\n ) => {\n const {\n wysiwygToolbarConfig,\n markupToolbarConfig,\n wysiwygHiddenActionsConfig,\n markupHiddenActionsConfig,\n } = useMemo(\n () =>\n getToolbarsConfigs({\n toolbarsPreset,\n props: {\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n },\n preset: editor.preset,\n }),\n [\n toolbarsPreset,\n initialWysiwygToolbarConfig,\n initialMarkupToolbarConfig,\n initialWysiwygHiddenActionsConfig,\n initialMarkupHiddenActionsConfig,\n editor.preset,\n ],\n );\n const onModeChange = useCallback(\n (type: MarkdownEditorMode) => {\n editor.changeEditorMode({mode: type, reason: 'settings'});\n unsetShowPreview();\n },\n [editor, unsetShowPreview],\n );\n const onToolbarVisibilityChange = useCallback(\n (visible: boolean) => {\n editor.changeToolbarVisibility({visible});\n },\n [editor],\n );\n const onSplitModeChange = useCallback(\n (splitModeEnabled: boolean) => {\n unsetShowPreview();\n editor.changeSplitModeEnabled({splitModeEnabled});\n },\n [editor, unsetShowPreview],\n );\n const onShowPreviewChange = useCallback(\n (showPreviewValue: boolean) => {\n editor.changeSplitModeEnabled({splitModeEnabled: false});\n if (showPreviewValue !== showPreview) toggleShowPreview();\n },\n [editor, showPreview, toggleShowPreview],\n );\n const canRenderPreview = Boolean(\n editor.renderPreview && editorMode === 'markup' && !editor.splitModeEnabled,\n );\n\n useKey(\n (e) => canRenderPreview && isPreviewKeyDown(e),\n (e) => {\n e.preventDefault();\n onShowPreviewChange(!showPreview);\n },\n {event: 'keydown'},\n [showPreview, editorMode, onShowPreviewChange, canRenderPreview],\n );\n\n useKey(\n (e) => Boolean(enableSubmitInPreview && showPreview && isFocused && isSubmitKeyDown(e)),\n () => {\n editor.emit('submit', null);\n\n if (hidePreviewAfterSubmit) {\n onShowPreviewChange(false);\n }\n },\n {event: 'keydown'},\n [hidePreviewAfterSubmit, enableSubmitInPreview, showPreview, showPreview],\n );\n\n const settingsProps = {\n mode: editorMode,\n onModeChange,\n onShowPreviewChange,\n onSplitModeChange,\n onToolbarVisibilityChange,\n renderPreviewButton: canRenderPreview,\n showPreview,\n splitMode: editor.splitMode,\n splitModeEnabled: editor.splitModeEnabled,\n stickyToolbar,\n toolbarVisibility: editor.toolbarVisible && !showPreview,\n };\n\n const areSettingsVisible =\n settingsVisibleProp === true ||\n (Array.isArray(settingsVisibleProp) && settingsVisibleProp.length > 0);\n\n return (\n <div\n className={b('editor-wrapper')}\n ref={ref}\n data-qa={qa}\n data-mode={editor.currentMode}\n >\n {showPreview ? (\n <>\n <div className={b('preview-wrapper')}>\n {editor.renderPreview?.({\n getValue: editor.getValue,\n mode: 'preview',\n md: editor.mdOptions,\n directiveSyntax: editor.directiveSyntax,\n })}\n </div>\n <Settings {...settingsProps} settingsVisible={settingsVisibleProp} />\n </>\n ) : (\n <>\n {editorMode === 'wysiwyg' && (\n <WysiwygEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={wysiwygToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n hiddenActionsConfig={wysiwygHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </WysiwygEditorView>\n )}\n {editorMode === 'markup' && (\n <MarkupEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={markupToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n splitMode={editor.splitMode}\n splitModeEnabled={editor.splitModeEnabled}\n hiddenActionsConfig={markupHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </MarkupEditorView>\n )}\n <Settings\n {...settingsProps}\n settingsVisible={!editor.toolbarVisible && settingsVisibleProp}\n renderPreviewButton={!editor.toolbarVisible && editorMode === 'markup'}\n />\n </>\n )}\n </div>\n );\n },\n);\n\nEditorWrapper.displayName = 'EditorWrapper';\n\ntype ToolbarConfigs = {\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupToolbarConfig?: MToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygToolbarConfig?: WToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupHiddenActionsConfig?: MToolbarItemData[];\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygHiddenActionsConfig?: WToolbarItemData[];\n};\n\ntype ViewProps = {\n editor?: Editor;\n autofocus?: boolean;\n // MAJOR: rename to settings\n /** @default true */\n settingsVisible?: boolean | SettingItems[];\n toolbarsPreset?: ToolbarsPreset;\n stickyToolbar: boolean;\n enableSubmitInPreview?: boolean;\n hidePreviewAfterSubmit?: boolean;\n};\n\nexport type MarkdownEditorViewProps = ClassNameProps & ToolbarConfigs & ViewProps & QAProps & {};\n\nexport const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewProps>(\n (props, ref) => {\n const divRef = useEnsuredForwardedRef(ref as React.MutableRefObject<HTMLDivElement>);\n const editorWrapperRef = useRef(null);\n const [showPreview, , unsetShowPreview, toggleShowPreview] = useBooleanState(false);\n\n const [isMounted, setIsMounted] = useState(false);\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n const context = useMarkdownEditorContext();\n const editor = (props.editor ?? context) as EditorInt;\n if (!editor)\n throw new Error(\n '[MarkdownEditorView]: an instance of the editor must be passed through the props or context',\n );\n\n const {\n autofocus,\n className,\n enableSubmitInPreview = true,\n hidePreviewAfterSubmit = false,\n markupHiddenActionsConfig,\n markupToolbarConfig,\n qa,\n settingsVisible = true,\n stickyToolbar,\n toolbarsPreset,\n wysiwygHiddenActionsConfig,\n wysiwygToolbarConfig,\n } = props;\n\n const rerender = useUpdate();\n useLayoutEffect(() => {\n editor.on('rerender', rerender);\n return () => {\n editor.off('rerender', rerender);\n };\n }, [editor, rerender]);\n\n const editorMode = editor.currentMode;\n const markupSplitMode =\n editor.splitModeEnabled && editor.splitMode && editorMode === 'markup';\n\n const splitModeViewWrapperRef = useRef(null);\n\n const toaster = useToaster();\n\n useEffect(() => {\n if (showPreview) {\n divRef.current.focus();\n }\n }, [divRef, showPreview]);\n\n const areSettingsVisible =\n settingsVisible === true ||\n (Array.isArray(settingsVisible) && settingsVisible.length > 0);\n\n return (\n <ErrorBoundary\n onError={(e) => {\n globalLogger.error(e);\n editor.logger.error(e);\n }}\n fallbackRender={({error, resetErrorBoundary}) => {\n toaster.add({\n theme: 'danger',\n name: 'g-md-editor-error',\n title: i18n('error-title'),\n content: error.message,\n });\n setTimeout(() => {\n resetErrorBoundary();\n editor.changeEditorMode({\n mode: 'markup',\n reason: 'error-boundary',\n emit: false,\n });\n });\n return null;\n }}\n >\n <div\n ref={divRef}\n data-qa={qa}\n className={b(\n {\n settings: areSettingsVisible,\n split: markupSplitMode && editor.splitMode,\n },\n [className],\n )}\n role=\"button\"\n tabIndex={0}\n >\n <EditorWrapper\n autofocus={autofocus}\n editor={editor}\n editorMode={editorMode}\n enableSubmitInPreview={enableSubmitInPreview}\n hidePreviewAfterSubmit={hidePreviewAfterSubmit}\n isFocused={isWrapperFocused(divRef)}\n markupHiddenActionsConfig={markupHiddenActionsConfig}\n markupToolbarConfig={markupToolbarConfig}\n qa=\"g-md-editor-mode\"\n ref={editorWrapperRef}\n settingsVisible={settingsVisible}\n showPreview={showPreview}\n stickyToolbar={stickyToolbar}\n toggleShowPreview={toggleShowPreview}\n toolbarsPreset={toolbarsPreset}\n unsetShowPreview={unsetShowPreview}\n wysiwygHiddenActionsConfig={wysiwygHiddenActionsConfig}\n wysiwygToolbarConfig={wysiwygToolbarConfig}\n />\n\n {markupSplitMode && (\n <>\n {editor.splitMode === 'horizontal' ? (\n <HorizontalDrag\n editor={editor}\n isMounted={isMounted}\n leftElRef={editorWrapperRef}\n rightElRef={splitModeViewWrapperRef}\n wrapperRef={divRef}\n />\n ) : (\n <div className={b('resizer')} />\n )}\n <SplitModeView editor={editor} ref={splitModeViewWrapperRef} />\n </>\n )}\n </div>\n </ErrorBoundary>\n );\n },\n);\nMarkdownEditorView.displayName = 'MarkdownEditorView';\n\ninterface MarkupSearchAnchorProps extends Pick<EditorSettingsProps, 'mode'> {}\n\nconst MarkupSearchAnchor: React.FC<MarkupSearchAnchorProps> = ({mode}) => (\n <>{mode === 'markup' && <div className=\"g-md-search-anchor\"></div>}</>\n);\n\nfunction Settings(props: EditorSettingsProps & {stickyToolbar: boolean}) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const isSticky = useSticky(wrapperRef) && props.toolbarVisibility && props.stickyToolbar;\n\n return (\n <>\n {(props.renderPreviewButton || props.settingsVisible) && (\n <div className={b('settings-wrapper')}>\n <div\n ref={wrapperRef}\n className={stickyCn.settings({\n withToolbar: props.toolbarVisibility,\n stickyActive: isSticky,\n })}\n >\n <EditorSettings {...props} />\n <MarkupSearchAnchor {...props} />\n </div>\n </div>\n )}\n </>\n );\n}\n\nfunction isPreviewKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.shiftKey && e.code === 'KeyP';\n}\n\nfunction isWrapperFocused(divRef: React.RefObject<HTMLDivElement>) {\n return document.activeElement === divRef.current;\n}\n\nfunction isSubmitKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.code === 'Enter';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MarkdownEditorView.js","sourceRoot":"../../../src","sources":["bundle/MarkdownEditorView.tsx"],"names":[],"mappings":";;;;AAAA,iCAQe;AAEf,6CAA2D;AAC3D,+DAAmD;AACnD,yCAAoE;AAEpE,+CAAqD;AACrD,oDAAoC;AACpC,yCAAuC;AAEvC,yDAA0D;AAC1D,6CAA+B;AAG/B,wDAAgD;AAChD,4DAAoD;AACpD,sDAA8C;AAC9C,8DAAsD;AACtD,0CAAmD;AACnD,kDAAuF;AACvF,8CAAkC;AAElC,wEAAmE;AAGnE,gCAA+B;AAC/B,oCAAmC,CAAC,mCAAmC;AAE1D,QAAA,iBAAiB,GAAG,IAAA,cAAE,EAAC,kBAAkB,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,yBAAiB,CAAC;AAU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CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,OAAO,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;AACxC,CAAC","sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {type QAProps, useToaster} from '@gravity-ui/uikit';\nimport {ErrorBoundary} from 'react-error-boundary';\nimport {useEnsuredForwardedRef, useKey, useUpdate} from 'react-use';\n\nimport {type ClassNameProps, cn} from '../classname';\nimport {i18n} from '../i18n/bundle';\nimport {globalLogger} from '../logger';\nimport type {ToolbarsPreset} from '../modules/toolbars/types';\nimport {useBooleanState, useSticky} from '../react-utils';\nimport {isMac} from '../utils';\n\nimport type {Editor, EditorInt} from './Editor';\nimport {HorizontalDrag} from './HorizontalDrag';\nimport {MarkupEditorView} from './MarkupEditorView';\nimport {SplitModeView} from './SplitModeView';\nimport {WysiwygEditorView} from './WysiwygEditorView';\nimport {useMarkdownEditorContext} from './context';\nimport {EditorSettings, type EditorSettingsProps, type SettingItems} from './settings';\nimport {stickyCn} from './sticky';\nimport type {MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData} from './toolbar/types';\nimport {getToolbarsConfigs} from './toolbar/utils/toolbarsConfigs';\nimport type {MarkdownEditorMode} from './types';\n\nimport '../styles/styles.scss';\nimport './MarkdownEditorView.scss'; // eslint-disable-line import/order\n\nexport const cnEditorComponent = cn('editor-component');\nconst b = cnEditorComponent;\n\ninterface EditorWrapperProps extends QAProps, ToolbarConfigs, Omit<ViewProps, 'editor'> {\n editor: EditorInt;\n editorMode: MarkdownEditorMode;\n isFocused: boolean;\n showPreview: boolean;\n toggleShowPreview: () => void;\n unsetShowPreview: () => void;\n}\nconst EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(\n (\n {\n autofocus,\n editor,\n editorMode,\n enableSubmitInPreview,\n hidePreviewAfterSubmit,\n isFocused,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n qa,\n settingsVisible: settingsVisibleProp,\n showPreview,\n stickyToolbar,\n toggleShowPreview,\n toolbarsPreset,\n unsetShowPreview,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n },\n ref,\n ) => {\n const {\n wysiwygToolbarConfig,\n markupToolbarConfig,\n wysiwygHiddenActionsConfig,\n markupHiddenActionsConfig,\n } = useMemo(\n () =>\n getToolbarsConfigs({\n toolbarsPreset,\n props: {\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n },\n preset: editor.preset,\n }),\n [\n toolbarsPreset,\n initialWysiwygToolbarConfig,\n initialMarkupToolbarConfig,\n initialWysiwygHiddenActionsConfig,\n initialMarkupHiddenActionsConfig,\n editor.preset,\n ],\n );\n const onModeChange = useCallback(\n (type: MarkdownEditorMode) => {\n editor.changeEditorMode({mode: type, reason: 'settings'});\n unsetShowPreview();\n },\n [editor, unsetShowPreview],\n );\n const onToolbarVisibilityChange = useCallback(\n (visible: boolean) => {\n editor.changeToolbarVisibility({visible});\n },\n [editor],\n );\n const onSplitModeChange = useCallback(\n (splitModeEnabled: boolean) => {\n unsetShowPreview();\n editor.changeSplitModeEnabled({splitModeEnabled});\n },\n [editor, unsetShowPreview],\n );\n const onShowPreviewChange = useCallback(\n (showPreviewValue: boolean) => {\n editor.changeSplitModeEnabled({splitModeEnabled: false});\n if (showPreviewValue !== showPreview) toggleShowPreview();\n },\n [editor, showPreview, toggleShowPreview],\n );\n const canRenderPreview = Boolean(\n editor.renderPreview && editorMode === 'markup' && !editor.splitModeEnabled,\n );\n\n useKey(\n (e) => canRenderPreview && isPreviewKeyDown(e),\n (e) => {\n e.preventDefault();\n onShowPreviewChange(!showPreview);\n },\n {event: 'keydown'},\n [showPreview, editorMode, onShowPreviewChange, canRenderPreview],\n );\n\n useKey(\n (e) => Boolean(enableSubmitInPreview && showPreview && isFocused && isSubmitKeyDown(e)),\n () => {\n editor.emit('submit', null);\n\n if (hidePreviewAfterSubmit) {\n onShowPreviewChange(false);\n }\n },\n {event: 'keydown'},\n [hidePreviewAfterSubmit, enableSubmitInPreview, showPreview, showPreview],\n );\n\n const settingsProps = {\n mode: editorMode,\n onModeChange,\n onShowPreviewChange,\n onSplitModeChange,\n onToolbarVisibilityChange,\n renderPreviewButton: canRenderPreview,\n showPreview,\n splitMode: editor.splitMode,\n splitModeEnabled: editor.splitModeEnabled,\n stickyToolbar,\n toolbarVisibility: editor.toolbarVisible && !showPreview,\n };\n\n const areSettingsVisible =\n settingsVisibleProp === true ||\n (Array.isArray(settingsVisibleProp) && settingsVisibleProp.length > 0);\n\n return (\n <div\n className={b('editor-wrapper')}\n ref={ref}\n data-qa={qa}\n data-mode={editor.currentMode}\n >\n {showPreview ? (\n <>\n <div className={b('preview-wrapper')}>\n {editor.renderPreview?.({\n getValue: editor.getValue,\n mode: 'preview',\n md: editor.mdOptions,\n directiveSyntax: editor.directiveSyntax,\n })}\n </div>\n <Settings {...settingsProps} settingsVisible={settingsVisibleProp} />\n </>\n ) : (\n <>\n {editorMode === 'wysiwyg' && (\n <WysiwygEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={wysiwygToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n hiddenActionsConfig={wysiwygHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </WysiwygEditorView>\n )}\n {editorMode === 'markup' && (\n <MarkupEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={markupToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n splitMode={editor.splitMode}\n splitModeEnabled={editor.splitModeEnabled}\n hiddenActionsConfig={markupHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </MarkupEditorView>\n )}\n <Settings\n {...settingsProps}\n settingsVisible={!editor.toolbarVisible && settingsVisibleProp}\n renderPreviewButton={!editor.toolbarVisible && canRenderPreview}\n />\n </>\n )}\n </div>\n );\n },\n);\n\nEditorWrapper.displayName = 'EditorWrapper';\n\ntype ToolbarConfigs = {\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupToolbarConfig?: MToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygToolbarConfig?: WToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupHiddenActionsConfig?: MToolbarItemData[];\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygHiddenActionsConfig?: WToolbarItemData[];\n};\n\ntype ViewProps = {\n editor?: Editor;\n autofocus?: boolean;\n // MAJOR: rename to settings\n /** @default true */\n settingsVisible?: boolean | SettingItems[];\n toolbarsPreset?: ToolbarsPreset;\n stickyToolbar: boolean;\n enableSubmitInPreview?: boolean;\n hidePreviewAfterSubmit?: boolean;\n};\n\nexport type MarkdownEditorViewProps = ClassNameProps & ToolbarConfigs & ViewProps & QAProps & {};\n\nexport const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewProps>(\n (props, ref) => {\n const divRef = useEnsuredForwardedRef(ref as React.MutableRefObject<HTMLDivElement>);\n const editorWrapperRef = useRef(null);\n const [showPreview, , unsetShowPreview, toggleShowPreview] = useBooleanState(false);\n\n const [isMounted, setIsMounted] = useState(false);\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n const context = useMarkdownEditorContext();\n const editor = (props.editor ?? context) as EditorInt;\n if (!editor)\n throw new Error(\n '[MarkdownEditorView]: an instance of the editor must be passed through the props or context',\n );\n\n const {\n autofocus,\n className,\n enableSubmitInPreview = true,\n hidePreviewAfterSubmit = false,\n markupHiddenActionsConfig,\n markupToolbarConfig,\n qa,\n settingsVisible = true,\n stickyToolbar,\n toolbarsPreset,\n wysiwygHiddenActionsConfig,\n wysiwygToolbarConfig,\n } = props;\n\n const rerender = useUpdate();\n useLayoutEffect(() => {\n editor.on('rerender', rerender);\n return () => {\n editor.off('rerender', rerender);\n };\n }, [editor, rerender]);\n\n const editorMode = editor.currentMode;\n const markupSplitMode =\n editor.splitModeEnabled && editor.splitMode && editorMode === 'markup';\n\n const splitModeViewWrapperRef = useRef(null);\n\n const toaster = useToaster();\n\n useEffect(() => {\n if (showPreview) {\n divRef.current.focus();\n }\n }, [divRef, showPreview]);\n\n const areSettingsVisible =\n settingsVisible === true ||\n (Array.isArray(settingsVisible) && settingsVisible.length > 0);\n\n return (\n <ErrorBoundary\n onError={(e) => {\n globalLogger.error(e);\n editor.logger.error(e);\n }}\n fallbackRender={({error, resetErrorBoundary}) => {\n toaster.add({\n theme: 'danger',\n name: 'g-md-editor-error',\n title: i18n('error-title'),\n content: error.message,\n });\n setTimeout(() => {\n resetErrorBoundary();\n editor.changeEditorMode({\n mode: 'markup',\n reason: 'error-boundary',\n emit: false,\n });\n });\n return null;\n }}\n >\n <div\n ref={divRef}\n data-qa={qa}\n className={b(\n {\n settings: areSettingsVisible,\n split: markupSplitMode && editor.splitMode,\n },\n [className],\n )}\n role=\"button\"\n tabIndex={0}\n >\n <EditorWrapper\n autofocus={autofocus}\n editor={editor}\n editorMode={editorMode}\n enableSubmitInPreview={enableSubmitInPreview}\n hidePreviewAfterSubmit={hidePreviewAfterSubmit}\n isFocused={isWrapperFocused(divRef)}\n markupHiddenActionsConfig={markupHiddenActionsConfig}\n markupToolbarConfig={markupToolbarConfig}\n qa=\"g-md-editor-mode\"\n ref={editorWrapperRef}\n settingsVisible={settingsVisible}\n showPreview={showPreview}\n stickyToolbar={stickyToolbar}\n toggleShowPreview={toggleShowPreview}\n toolbarsPreset={toolbarsPreset}\n unsetShowPreview={unsetShowPreview}\n wysiwygHiddenActionsConfig={wysiwygHiddenActionsConfig}\n wysiwygToolbarConfig={wysiwygToolbarConfig}\n />\n\n {markupSplitMode && (\n <>\n {editor.splitMode === 'horizontal' ? (\n <HorizontalDrag\n editor={editor}\n isMounted={isMounted}\n leftElRef={editorWrapperRef}\n rightElRef={splitModeViewWrapperRef}\n wrapperRef={divRef}\n />\n ) : (\n <div className={b('resizer')} />\n )}\n <SplitModeView editor={editor} ref={splitModeViewWrapperRef} />\n </>\n )}\n </div>\n </ErrorBoundary>\n );\n },\n);\nMarkdownEditorView.displayName = 'MarkdownEditorView';\n\ninterface MarkupSearchAnchorProps extends Pick<EditorSettingsProps, 'mode'> {}\n\nconst MarkupSearchAnchor: React.FC<MarkupSearchAnchorProps> = ({mode}) => (\n <>{mode === 'markup' && <div className=\"g-md-search-anchor\"></div>}</>\n);\n\nfunction Settings(props: EditorSettingsProps & {stickyToolbar: boolean}) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const isSticky = useSticky(wrapperRef) && props.toolbarVisibility && props.stickyToolbar;\n\n return (\n <>\n {(props.renderPreviewButton || props.settingsVisible) && (\n <div className={b('settings-wrapper')}>\n <div\n ref={wrapperRef}\n className={stickyCn.settings({\n withToolbar: props.toolbarVisibility,\n stickyActive: isSticky,\n })}\n >\n <EditorSettings {...props} />\n <MarkupSearchAnchor {...props} />\n </div>\n </div>\n )}\n </>\n );\n}\n\nfunction isPreviewKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.shiftKey && e.code === 'KeyP';\n}\n\nfunction isWrapperFocused(divRef: React.RefObject<HTMLDivElement>) {\n return document.activeElement === divRef.current;\n}\n\nfunction isSubmitKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.code === 'Enter';\n}\n"]}
|
|
@@ -4,11 +4,12 @@ exports.renderPopup = renderPopup;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
6
6
|
const GptDialog_1 = require("../GptDialog/GptDialog.js");
|
|
7
|
+
const constants_1 = require("../constants.js");
|
|
7
8
|
const view_1 = require("../gptExtension/view.js");
|
|
8
9
|
function renderPopup(anchor, props) {
|
|
9
10
|
return ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { className: (0, view_1.cnGptPopup)(), open: true, strategy: "absolute", onOpenChange: (open) => {
|
|
10
11
|
if (!open)
|
|
11
12
|
props.onClose();
|
|
12
|
-
}, anchorElement: anchor, children: (0, jsx_runtime_1.jsx)("div", { className: (0, view_1.cnGptPopup)('content'), children: (0, jsx_runtime_1.jsx)(GptDialog_1.GptDialog, { markup: props.markup, answerRender: props.answerRender, promptPresets: props.promptPresets, disablePromptPresets: props.disablePromptPresets, customPromptPlaceholder: props.customPromptPlaceholder, disabledPromptPlaceholder: props.disabledPromptPlaceholder, onApplyResult: props.onApplyResult, onCustomPromptApply: props.onCustomPromptApply, onPromptPresetClick: props.onPromptPresetClick, onTryAgain: props.onTryAgain, onLike: props.onLike, onDislike: props.onDislike, onClose: props.onClose, onUpdate: props.onUpdate, gptAlertProps: props.gptAlertProps }) }) }));
|
|
13
|
+
}, anchorElement: anchor, placement: constants_1.gptPopupPlacement, children: (0, jsx_runtime_1.jsx)("div", { className: (0, view_1.cnGptPopup)('content'), children: (0, jsx_runtime_1.jsx)(GptDialog_1.GptDialog, { markup: props.markup, answerRender: props.answerRender, promptPresets: props.promptPresets, disablePromptPresets: props.disablePromptPresets, customPromptPlaceholder: props.customPromptPlaceholder, disabledPromptPlaceholder: props.disabledPromptPlaceholder, onApplyResult: props.onApplyResult, onCustomPromptApply: props.onCustomPromptApply, onPromptPresetClick: props.onPromptPresetClick, onTryAgain: props.onTryAgain, onLike: props.onLike, onDislike: props.onDislike, onClose: props.onClose, onUpdate: props.onUpdate, gptAlertProps: props.gptAlertProps }) }) }));
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=popup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popup.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/GPT/MarkupGpt/popup.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"popup.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/GPT/MarkupGpt/popup.tsx"],"names":[],"mappings":";;AAcA,kCAoCC;;AAlDD,6CAAwC;AAGxC,yDAAsE;AACtE,+CAA+C;AAC/C,kDAAgD;AAShD,SAAgB,WAAW,CAGzB,MAAmB,EAAE,KAAoC;IACvD,OAAO,CACH,uBAAC,aAAK,IACF,SAAS,EAAE,IAAA,iBAAU,GAAE,EACvB,IAAI,QACJ,QAAQ,EAAC,UAAU,EACnB,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,CAAC,IAAI;gBAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC,EACD,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,6BAAiB,YAE5B,gCAAK,SAAS,EAAE,IAAA,iBAAU,EAAC,SAAS,CAAC,YACjC,uBAAC,qBAAS,IACN,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,oBAAoB,EAAE,KAAK,CAAC,oBAAoB,EAChD,uBAAuB,EAAE,KAAK,CAAC,uBAAuB,EACtD,yBAAyB,EAAE,KAAK,CAAC,yBAAyB,EAC1D,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,UAAU,EAAE,KAAK,CAAC,UAAU,EAC5B,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,aAAa,EAAE,KAAK,CAAC,aAAa,GACpC,GACA,GACF,CACX,CAAC;AACN,CAAC","sourcesContent":["import {Popup} from '@gravity-ui/uikit';\n\nimport type {CommonAnswer} from '../ErrorScreen/types';\nimport {GptDialog, type GptDialogProps} from '../GptDialog/GptDialog';\nimport {gptPopupPlacement} from '../constants';\nimport {cnGptPopup} from '../gptExtension/view';\n\ntype Props<AnswerData extends CommonAnswer = CommonAnswer, PromptData extends unknown = unknown> = {\n onClose: () => void;\n markup: string;\n onConfirmOk?: () => void;\n onConfirmCancel?: () => void;\n} & GptDialogProps<AnswerData, PromptData>;\n\nexport function renderPopup<\n AnswerData extends CommonAnswer = CommonAnswer,\n PromptData extends unknown = unknown,\n>(anchor: HTMLElement, props: Props<AnswerData, PromptData>) {\n return (\n <Popup\n className={cnGptPopup()}\n open\n strategy=\"absolute\"\n onOpenChange={(open) => {\n if (!open) props.onClose();\n }}\n anchorElement={anchor}\n placement={gptPopupPlacement}\n >\n <div className={cnGptPopup('content')}>\n <GptDialog\n markup={props.markup}\n answerRender={props.answerRender}\n promptPresets={props.promptPresets}\n disablePromptPresets={props.disablePromptPresets}\n customPromptPlaceholder={props.customPromptPlaceholder}\n disabledPromptPlaceholder={props.disabledPromptPlaceholder}\n onApplyResult={props.onApplyResult}\n onCustomPromptApply={props.onCustomPromptApply}\n onPromptPresetClick={props.onPromptPresetClick}\n onTryAgain={props.onTryAgain}\n onLike={props.onLike}\n onDislike={props.onDislike}\n onClose={props.onClose}\n onUpdate={props.onUpdate}\n gptAlertProps={props.gptAlertProps}\n />\n </div>\n </Popup>\n );\n}\n"]}
|
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.1' !== 'undefined' ? '15.12.1' : '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.1' !== 'undefined' ? '15.12.1' : '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,CAA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,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"]}
|
|
@@ -85,7 +85,7 @@ const EditorWrapper = forwardRef(({ autofocus, editor, editorMode, enableSubmitI
|
|
|
85
85
|
mode: 'preview',
|
|
86
86
|
md: editor.mdOptions,
|
|
87
87
|
directiveSyntax: editor.directiveSyntax,
|
|
88
|
-
}) }), _jsx(Settings, { ...settingsProps, settingsVisible: settingsVisibleProp })] })) : (_jsxs(_Fragment, { children: [editorMode === 'wysiwyg' && (_jsx(WysiwygEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: wysiwygToolbarConfig, toolbarVisible: editor.toolbarVisible, hiddenActionsConfig: wysiwygHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: _jsx(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), editorMode === 'markup' && (_jsx(MarkupEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: markupToolbarConfig, toolbarVisible: editor.toolbarVisible, splitMode: editor.splitMode, splitModeEnabled: editor.splitModeEnabled, hiddenActionsConfig: markupHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: _jsx(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), _jsx(Settings, { ...settingsProps, settingsVisible: !editor.toolbarVisible && settingsVisibleProp, renderPreviewButton: !editor.toolbarVisible &&
|
|
88
|
+
}) }), _jsx(Settings, { ...settingsProps, settingsVisible: settingsVisibleProp })] })) : (_jsxs(_Fragment, { children: [editorMode === 'wysiwyg' && (_jsx(WysiwygEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: wysiwygToolbarConfig, toolbarVisible: editor.toolbarVisible, hiddenActionsConfig: wysiwygHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: _jsx(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), editorMode === 'markup' && (_jsx(MarkupEditorView, { editor: editor, autofocus: autofocus, settingsVisible: areSettingsVisible, toolbarConfig: markupToolbarConfig, toolbarVisible: editor.toolbarVisible, splitMode: editor.splitMode, splitModeEnabled: editor.splitModeEnabled, hiddenActionsConfig: markupHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar, children: _jsx(Settings, { ...settingsProps, settingsVisible: editor.toolbarVisible && settingsVisibleProp }) })), _jsx(Settings, { ...settingsProps, settingsVisible: !editor.toolbarVisible && settingsVisibleProp, renderPreviewButton: !editor.toolbarVisible && canRenderPreview })] })) }));
|
|
89
89
|
});
|
|
90
90
|
EditorWrapper.displayName = 'EditorWrapper';
|
|
91
91
|
export const MarkdownEditorView = forwardRef((props, ref) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownEditorView.js","sourceRoot":"../../../src","sources":["bundle/MarkdownEditorView.tsx"],"names":[],"mappings":";AAAA,OAAO,EACH,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GACX,MAAM,OAAO,CAAC;AAEf,OAAO,EAAe,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,sBAAsB,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpE,OAAO,EAAsB,EAAE,EAAC,wBAAqB;AACrD,OAAO,EAAC,IAAI,EAAC,gCAAuB;AACpC,OAAO,EAAC,YAAY,EAAC,qBAAkB;AAEvC,OAAO,EAAC,eAAe,EAAE,SAAS,EAAC,gCAAuB;AAC1D,OAAO,EAAC,KAAK,EAAC,0BAAiB;AAG/B,OAAO,EAAC,cAAc,EAAC,4BAAyB;AAChD,OAAO,EAAC,gBAAgB,EAAC,8BAA2B;AACpD,OAAO,EAAC,aAAa,EAAC,2BAAwB;AAC9C,OAAO,EAAC,iBAAiB,EAAC,+BAA4B;AACtD,OAAO,EAAC,wBAAwB,EAAC,qBAAkB;AACnD,OAAO,EAAC,cAAc,EAA8C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SAAS,eAAe,CAAC,CAAgB;IACrC,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,OAAO,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;AACxC,CAAC","sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {type QAProps, useToaster} from '@gravity-ui/uikit';\nimport {ErrorBoundary} from 'react-error-boundary';\nimport {useEnsuredForwardedRef, useKey, useUpdate} from 'react-use';\n\nimport {type ClassNameProps, cn} from '../classname';\nimport {i18n} from '../i18n/bundle';\nimport {globalLogger} from '../logger';\nimport type {ToolbarsPreset} from '../modules/toolbars/types';\nimport {useBooleanState, useSticky} from '../react-utils';\nimport {isMac} from '../utils';\n\nimport type {Editor, EditorInt} from './Editor';\nimport {HorizontalDrag} from './HorizontalDrag';\nimport {MarkupEditorView} from './MarkupEditorView';\nimport {SplitModeView} from './SplitModeView';\nimport {WysiwygEditorView} from './WysiwygEditorView';\nimport {useMarkdownEditorContext} from './context';\nimport {EditorSettings, type EditorSettingsProps, type SettingItems} from './settings';\nimport {stickyCn} from './sticky';\nimport type {MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData} from './toolbar/types';\nimport {getToolbarsConfigs} from './toolbar/utils/toolbarsConfigs';\nimport type {MarkdownEditorMode} from './types';\n\nimport '../styles/styles.scss';\nimport './MarkdownEditorView.scss'; // eslint-disable-line import/order\n\nexport const cnEditorComponent = cn('editor-component');\nconst b = cnEditorComponent;\n\ninterface EditorWrapperProps extends QAProps, ToolbarConfigs, Omit<ViewProps, 'editor'> {\n editor: EditorInt;\n editorMode: MarkdownEditorMode;\n isFocused: boolean;\n showPreview: boolean;\n toggleShowPreview: () => void;\n unsetShowPreview: () => void;\n}\nconst EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(\n (\n {\n autofocus,\n editor,\n editorMode,\n enableSubmitInPreview,\n hidePreviewAfterSubmit,\n isFocused,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n qa,\n settingsVisible: settingsVisibleProp,\n showPreview,\n stickyToolbar,\n toggleShowPreview,\n toolbarsPreset,\n unsetShowPreview,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n },\n ref,\n ) => {\n const {\n wysiwygToolbarConfig,\n markupToolbarConfig,\n wysiwygHiddenActionsConfig,\n markupHiddenActionsConfig,\n } = useMemo(\n () =>\n getToolbarsConfigs({\n toolbarsPreset,\n props: {\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n },\n preset: editor.preset,\n }),\n [\n toolbarsPreset,\n initialWysiwygToolbarConfig,\n initialMarkupToolbarConfig,\n initialWysiwygHiddenActionsConfig,\n initialMarkupHiddenActionsConfig,\n editor.preset,\n ],\n );\n const onModeChange = useCallback(\n (type: MarkdownEditorMode) => {\n editor.changeEditorMode({mode: type, reason: 'settings'});\n unsetShowPreview();\n },\n [editor, unsetShowPreview],\n );\n const onToolbarVisibilityChange = useCallback(\n (visible: boolean) => {\n editor.changeToolbarVisibility({visible});\n },\n [editor],\n );\n const onSplitModeChange = useCallback(\n (splitModeEnabled: boolean) => {\n unsetShowPreview();\n editor.changeSplitModeEnabled({splitModeEnabled});\n },\n [editor, unsetShowPreview],\n );\n const onShowPreviewChange = useCallback(\n (showPreviewValue: boolean) => {\n editor.changeSplitModeEnabled({splitModeEnabled: false});\n if (showPreviewValue !== showPreview) toggleShowPreview();\n },\n [editor, showPreview, toggleShowPreview],\n );\n const canRenderPreview = Boolean(\n editor.renderPreview && editorMode === 'markup' && !editor.splitModeEnabled,\n );\n\n useKey(\n (e) => canRenderPreview && isPreviewKeyDown(e),\n (e) => {\n e.preventDefault();\n onShowPreviewChange(!showPreview);\n },\n {event: 'keydown'},\n [showPreview, editorMode, onShowPreviewChange, canRenderPreview],\n );\n\n useKey(\n (e) => Boolean(enableSubmitInPreview && showPreview && isFocused && isSubmitKeyDown(e)),\n () => {\n editor.emit('submit', null);\n\n if (hidePreviewAfterSubmit) {\n onShowPreviewChange(false);\n }\n },\n {event: 'keydown'},\n [hidePreviewAfterSubmit, enableSubmitInPreview, showPreview, showPreview],\n );\n\n const settingsProps = {\n mode: editorMode,\n onModeChange,\n onShowPreviewChange,\n onSplitModeChange,\n onToolbarVisibilityChange,\n renderPreviewButton: canRenderPreview,\n showPreview,\n splitMode: editor.splitMode,\n splitModeEnabled: editor.splitModeEnabled,\n stickyToolbar,\n toolbarVisibility: editor.toolbarVisible && !showPreview,\n };\n\n const areSettingsVisible =\n settingsVisibleProp === true ||\n (Array.isArray(settingsVisibleProp) && settingsVisibleProp.length > 0);\n\n return (\n <div\n className={b('editor-wrapper')}\n ref={ref}\n data-qa={qa}\n data-mode={editor.currentMode}\n >\n {showPreview ? (\n <>\n <div className={b('preview-wrapper')}>\n {editor.renderPreview?.({\n getValue: editor.getValue,\n mode: 'preview',\n md: editor.mdOptions,\n directiveSyntax: editor.directiveSyntax,\n })}\n </div>\n <Settings {...settingsProps} settingsVisible={settingsVisibleProp} />\n </>\n ) : (\n <>\n {editorMode === 'wysiwyg' && (\n <WysiwygEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={wysiwygToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n hiddenActionsConfig={wysiwygHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </WysiwygEditorView>\n )}\n {editorMode === 'markup' && (\n <MarkupEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={markupToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n splitMode={editor.splitMode}\n splitModeEnabled={editor.splitModeEnabled}\n hiddenActionsConfig={markupHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </MarkupEditorView>\n )}\n <Settings\n {...settingsProps}\n settingsVisible={!editor.toolbarVisible && settingsVisibleProp}\n renderPreviewButton={!editor.toolbarVisible && editorMode === 'markup'}\n />\n </>\n )}\n </div>\n );\n },\n);\n\nEditorWrapper.displayName = 'EditorWrapper';\n\ntype ToolbarConfigs = {\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupToolbarConfig?: MToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygToolbarConfig?: WToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupHiddenActionsConfig?: MToolbarItemData[];\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygHiddenActionsConfig?: WToolbarItemData[];\n};\n\ntype ViewProps = {\n editor?: Editor;\n autofocus?: boolean;\n // MAJOR: rename to settings\n /** @default true */\n settingsVisible?: boolean | SettingItems[];\n toolbarsPreset?: ToolbarsPreset;\n stickyToolbar: boolean;\n enableSubmitInPreview?: boolean;\n hidePreviewAfterSubmit?: boolean;\n};\n\nexport type MarkdownEditorViewProps = ClassNameProps & ToolbarConfigs & ViewProps & QAProps & {};\n\nexport const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewProps>(\n (props, ref) => {\n const divRef = useEnsuredForwardedRef(ref as React.MutableRefObject<HTMLDivElement>);\n const editorWrapperRef = useRef(null);\n const [showPreview, , unsetShowPreview, toggleShowPreview] = useBooleanState(false);\n\n const [isMounted, setIsMounted] = useState(false);\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n const context = useMarkdownEditorContext();\n const editor = (props.editor ?? context) as EditorInt;\n if (!editor)\n throw new Error(\n '[MarkdownEditorView]: an instance of the editor must be passed through the props or context',\n );\n\n const {\n autofocus,\n className,\n enableSubmitInPreview = true,\n hidePreviewAfterSubmit = false,\n markupHiddenActionsConfig,\n markupToolbarConfig,\n qa,\n settingsVisible = true,\n stickyToolbar,\n toolbarsPreset,\n wysiwygHiddenActionsConfig,\n wysiwygToolbarConfig,\n } = props;\n\n const rerender = useUpdate();\n useLayoutEffect(() => {\n editor.on('rerender', rerender);\n return () => {\n editor.off('rerender', rerender);\n };\n }, [editor, rerender]);\n\n const editorMode = editor.currentMode;\n const markupSplitMode =\n editor.splitModeEnabled && editor.splitMode && editorMode === 'markup';\n\n const splitModeViewWrapperRef = useRef(null);\n\n const toaster = useToaster();\n\n useEffect(() => {\n if (showPreview) {\n divRef.current.focus();\n }\n }, [divRef, showPreview]);\n\n const areSettingsVisible =\n settingsVisible === true ||\n (Array.isArray(settingsVisible) && settingsVisible.length > 0);\n\n return (\n <ErrorBoundary\n onError={(e) => {\n globalLogger.error(e);\n editor.logger.error(e);\n }}\n fallbackRender={({error, resetErrorBoundary}) => {\n toaster.add({\n theme: 'danger',\n name: 'g-md-editor-error',\n title: i18n('error-title'),\n content: error.message,\n });\n setTimeout(() => {\n resetErrorBoundary();\n editor.changeEditorMode({\n mode: 'markup',\n reason: 'error-boundary',\n emit: false,\n });\n });\n return null;\n }}\n >\n <div\n ref={divRef}\n data-qa={qa}\n className={b(\n {\n settings: areSettingsVisible,\n split: markupSplitMode && editor.splitMode,\n },\n [className],\n )}\n role=\"button\"\n tabIndex={0}\n >\n <EditorWrapper\n autofocus={autofocus}\n editor={editor}\n editorMode={editorMode}\n enableSubmitInPreview={enableSubmitInPreview}\n hidePreviewAfterSubmit={hidePreviewAfterSubmit}\n isFocused={isWrapperFocused(divRef)}\n markupHiddenActionsConfig={markupHiddenActionsConfig}\n markupToolbarConfig={markupToolbarConfig}\n qa=\"g-md-editor-mode\"\n ref={editorWrapperRef}\n settingsVisible={settingsVisible}\n showPreview={showPreview}\n stickyToolbar={stickyToolbar}\n toggleShowPreview={toggleShowPreview}\n toolbarsPreset={toolbarsPreset}\n unsetShowPreview={unsetShowPreview}\n wysiwygHiddenActionsConfig={wysiwygHiddenActionsConfig}\n wysiwygToolbarConfig={wysiwygToolbarConfig}\n />\n\n {markupSplitMode && (\n <>\n {editor.splitMode === 'horizontal' ? (\n <HorizontalDrag\n editor={editor}\n isMounted={isMounted}\n leftElRef={editorWrapperRef}\n rightElRef={splitModeViewWrapperRef}\n wrapperRef={divRef}\n />\n ) : (\n <div className={b('resizer')} />\n )}\n <SplitModeView editor={editor} ref={splitModeViewWrapperRef} />\n </>\n )}\n </div>\n </ErrorBoundary>\n );\n },\n);\nMarkdownEditorView.displayName = 'MarkdownEditorView';\n\ninterface MarkupSearchAnchorProps extends Pick<EditorSettingsProps, 'mode'> {}\n\nconst MarkupSearchAnchor: React.FC<MarkupSearchAnchorProps> = ({mode}) => (\n <>{mode === 'markup' && <div className=\"g-md-search-anchor\"></div>}</>\n);\n\nfunction Settings(props: EditorSettingsProps & {stickyToolbar: boolean}) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const isSticky = useSticky(wrapperRef) && props.toolbarVisibility && props.stickyToolbar;\n\n return (\n <>\n {(props.renderPreviewButton || props.settingsVisible) && (\n <div className={b('settings-wrapper')}>\n <div\n ref={wrapperRef}\n className={stickyCn.settings({\n withToolbar: props.toolbarVisibility,\n stickyActive: isSticky,\n })}\n >\n <EditorSettings {...props} />\n <MarkupSearchAnchor {...props} />\n </div>\n </div>\n )}\n </>\n );\n}\n\nfunction isPreviewKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.shiftKey && e.code === 'KeyP';\n}\n\nfunction isWrapperFocused(divRef: React.RefObject<HTMLDivElement>) {\n return document.activeElement === divRef.current;\n}\n\nfunction isSubmitKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.code === 'Enter';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MarkdownEditorView.js","sourceRoot":"../../../src","sources":["bundle/MarkdownEditorView.tsx"],"names":[],"mappings":";AAAA,OAAO,EACH,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GACX,MAAM,OAAO,CAAC;AAEf,OAAO,EAAe,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,sBAAsB,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpE,OAAO,EAAsB,EAAE,EAAC,wBAAqB;AACrD,OAAO,EAAC,IAAI,EAAC,gCAAuB;AACpC,OAAO,EAAC,YAAY,EAAC,qBAAkB;AAEvC,OAAO,EAAC,eAAe,EAAE,SAAS,EAAC,gCAAuB;AAC1D,OAAO,EAAC,KAAK,EAAC,0BAAiB;AAG/B,OAAO,EAAC,cAAc,EAAC,4BAAyB;AAChD,OAAO,EAAC,gBAAgB,EAAC,8BAA2B;AACpD,OAAO,EAAC,aAAa,EAAC,2BAAwB;AAC9C,OAAO,EAAC,iBAAiB,EAAC,+BAA4B;AACtD,OAAO,EAAC,wBAAwB,EAAC,qBAAkB;AACnD,OAAO,EAAC,cAAc,EAA8C,4BAAmB;AACvF,OAAO,EAAC,QAAQ,EAAC,0BAAiB;AAElC,OAAO,EAAC,kBAAkB,EAAC,2CAAwC;AAGnE,8BAA+B;AAC/B,kCAAmC,CAAC,mCAAmC;AAEvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC,kBAAkB,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,iBAAiB,CAAC;AAU5B,MAAM,aAAa,GAAG,UA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,\n} from 'react';\n\nimport {type QAProps, useToaster} from '@gravity-ui/uikit';\nimport {ErrorBoundary} from 'react-error-boundary';\nimport {useEnsuredForwardedRef, useKey, useUpdate} from 'react-use';\n\nimport {type ClassNameProps, cn} from '../classname';\nimport {i18n} from '../i18n/bundle';\nimport {globalLogger} from '../logger';\nimport type {ToolbarsPreset} from '../modules/toolbars/types';\nimport {useBooleanState, useSticky} from '../react-utils';\nimport {isMac} from '../utils';\n\nimport type {Editor, EditorInt} from './Editor';\nimport {HorizontalDrag} from './HorizontalDrag';\nimport {MarkupEditorView} from './MarkupEditorView';\nimport {SplitModeView} from './SplitModeView';\nimport {WysiwygEditorView} from './WysiwygEditorView';\nimport {useMarkdownEditorContext} from './context';\nimport {EditorSettings, type EditorSettingsProps, type SettingItems} from './settings';\nimport {stickyCn} from './sticky';\nimport type {MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData} from './toolbar/types';\nimport {getToolbarsConfigs} from './toolbar/utils/toolbarsConfigs';\nimport type {MarkdownEditorMode} from './types';\n\nimport '../styles/styles.scss';\nimport './MarkdownEditorView.scss'; // eslint-disable-line import/order\n\nexport const cnEditorComponent = cn('editor-component');\nconst b = cnEditorComponent;\n\ninterface EditorWrapperProps extends QAProps, ToolbarConfigs, Omit<ViewProps, 'editor'> {\n editor: EditorInt;\n editorMode: MarkdownEditorMode;\n isFocused: boolean;\n showPreview: boolean;\n toggleShowPreview: () => void;\n unsetShowPreview: () => void;\n}\nconst EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(\n (\n {\n autofocus,\n editor,\n editorMode,\n enableSubmitInPreview,\n hidePreviewAfterSubmit,\n isFocused,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n qa,\n settingsVisible: settingsVisibleProp,\n showPreview,\n stickyToolbar,\n toggleShowPreview,\n toolbarsPreset,\n unsetShowPreview,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n },\n ref,\n ) => {\n const {\n wysiwygToolbarConfig,\n markupToolbarConfig,\n wysiwygHiddenActionsConfig,\n markupHiddenActionsConfig,\n } = useMemo(\n () =>\n getToolbarsConfigs({\n toolbarsPreset,\n props: {\n wysiwygToolbarConfig: initialWysiwygToolbarConfig,\n markupToolbarConfig: initialMarkupToolbarConfig,\n wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,\n markupHiddenActionsConfig: initialMarkupHiddenActionsConfig,\n },\n preset: editor.preset,\n }),\n [\n toolbarsPreset,\n initialWysiwygToolbarConfig,\n initialMarkupToolbarConfig,\n initialWysiwygHiddenActionsConfig,\n initialMarkupHiddenActionsConfig,\n editor.preset,\n ],\n );\n const onModeChange = useCallback(\n (type: MarkdownEditorMode) => {\n editor.changeEditorMode({mode: type, reason: 'settings'});\n unsetShowPreview();\n },\n [editor, unsetShowPreview],\n );\n const onToolbarVisibilityChange = useCallback(\n (visible: boolean) => {\n editor.changeToolbarVisibility({visible});\n },\n [editor],\n );\n const onSplitModeChange = useCallback(\n (splitModeEnabled: boolean) => {\n unsetShowPreview();\n editor.changeSplitModeEnabled({splitModeEnabled});\n },\n [editor, unsetShowPreview],\n );\n const onShowPreviewChange = useCallback(\n (showPreviewValue: boolean) => {\n editor.changeSplitModeEnabled({splitModeEnabled: false});\n if (showPreviewValue !== showPreview) toggleShowPreview();\n },\n [editor, showPreview, toggleShowPreview],\n );\n const canRenderPreview = Boolean(\n editor.renderPreview && editorMode === 'markup' && !editor.splitModeEnabled,\n );\n\n useKey(\n (e) => canRenderPreview && isPreviewKeyDown(e),\n (e) => {\n e.preventDefault();\n onShowPreviewChange(!showPreview);\n },\n {event: 'keydown'},\n [showPreview, editorMode, onShowPreviewChange, canRenderPreview],\n );\n\n useKey(\n (e) => Boolean(enableSubmitInPreview && showPreview && isFocused && isSubmitKeyDown(e)),\n () => {\n editor.emit('submit', null);\n\n if (hidePreviewAfterSubmit) {\n onShowPreviewChange(false);\n }\n },\n {event: 'keydown'},\n [hidePreviewAfterSubmit, enableSubmitInPreview, showPreview, showPreview],\n );\n\n const settingsProps = {\n mode: editorMode,\n onModeChange,\n onShowPreviewChange,\n onSplitModeChange,\n onToolbarVisibilityChange,\n renderPreviewButton: canRenderPreview,\n showPreview,\n splitMode: editor.splitMode,\n splitModeEnabled: editor.splitModeEnabled,\n stickyToolbar,\n toolbarVisibility: editor.toolbarVisible && !showPreview,\n };\n\n const areSettingsVisible =\n settingsVisibleProp === true ||\n (Array.isArray(settingsVisibleProp) && settingsVisibleProp.length > 0);\n\n return (\n <div\n className={b('editor-wrapper')}\n ref={ref}\n data-qa={qa}\n data-mode={editor.currentMode}\n >\n {showPreview ? (\n <>\n <div className={b('preview-wrapper')}>\n {editor.renderPreview?.({\n getValue: editor.getValue,\n mode: 'preview',\n md: editor.mdOptions,\n directiveSyntax: editor.directiveSyntax,\n })}\n </div>\n <Settings {...settingsProps} settingsVisible={settingsVisibleProp} />\n </>\n ) : (\n <>\n {editorMode === 'wysiwyg' && (\n <WysiwygEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={wysiwygToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n hiddenActionsConfig={wysiwygHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </WysiwygEditorView>\n )}\n {editorMode === 'markup' && (\n <MarkupEditorView\n editor={editor}\n autofocus={autofocus}\n settingsVisible={areSettingsVisible}\n toolbarConfig={markupToolbarConfig}\n toolbarVisible={editor.toolbarVisible}\n splitMode={editor.splitMode}\n splitModeEnabled={editor.splitModeEnabled}\n hiddenActionsConfig={markupHiddenActionsConfig}\n className={b('editor', {mode: editorMode})}\n toolbarClassName={b('toolbar')}\n stickyToolbar={stickyToolbar}\n >\n <Settings\n {...settingsProps}\n settingsVisible={editor.toolbarVisible && settingsVisibleProp}\n />\n </MarkupEditorView>\n )}\n <Settings\n {...settingsProps}\n settingsVisible={!editor.toolbarVisible && settingsVisibleProp}\n renderPreviewButton={!editor.toolbarVisible && canRenderPreview}\n />\n </>\n )}\n </div>\n );\n },\n);\n\nEditorWrapper.displayName = 'EditorWrapper';\n\ntype ToolbarConfigs = {\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupToolbarConfig?: MToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygToolbarConfig?: WToolbarData;\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n markupHiddenActionsConfig?: MToolbarItemData[];\n /**\n * @deprecated use `toolbarsPreset` instead\n */\n wysiwygHiddenActionsConfig?: WToolbarItemData[];\n};\n\ntype ViewProps = {\n editor?: Editor;\n autofocus?: boolean;\n // MAJOR: rename to settings\n /** @default true */\n settingsVisible?: boolean | SettingItems[];\n toolbarsPreset?: ToolbarsPreset;\n stickyToolbar: boolean;\n enableSubmitInPreview?: boolean;\n hidePreviewAfterSubmit?: boolean;\n};\n\nexport type MarkdownEditorViewProps = ClassNameProps & ToolbarConfigs & ViewProps & QAProps & {};\n\nexport const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewProps>(\n (props, ref) => {\n const divRef = useEnsuredForwardedRef(ref as React.MutableRefObject<HTMLDivElement>);\n const editorWrapperRef = useRef(null);\n const [showPreview, , unsetShowPreview, toggleShowPreview] = useBooleanState(false);\n\n const [isMounted, setIsMounted] = useState(false);\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n const context = useMarkdownEditorContext();\n const editor = (props.editor ?? context) as EditorInt;\n if (!editor)\n throw new Error(\n '[MarkdownEditorView]: an instance of the editor must be passed through the props or context',\n );\n\n const {\n autofocus,\n className,\n enableSubmitInPreview = true,\n hidePreviewAfterSubmit = false,\n markupHiddenActionsConfig,\n markupToolbarConfig,\n qa,\n settingsVisible = true,\n stickyToolbar,\n toolbarsPreset,\n wysiwygHiddenActionsConfig,\n wysiwygToolbarConfig,\n } = props;\n\n const rerender = useUpdate();\n useLayoutEffect(() => {\n editor.on('rerender', rerender);\n return () => {\n editor.off('rerender', rerender);\n };\n }, [editor, rerender]);\n\n const editorMode = editor.currentMode;\n const markupSplitMode =\n editor.splitModeEnabled && editor.splitMode && editorMode === 'markup';\n\n const splitModeViewWrapperRef = useRef(null);\n\n const toaster = useToaster();\n\n useEffect(() => {\n if (showPreview) {\n divRef.current.focus();\n }\n }, [divRef, showPreview]);\n\n const areSettingsVisible =\n settingsVisible === true ||\n (Array.isArray(settingsVisible) && settingsVisible.length > 0);\n\n return (\n <ErrorBoundary\n onError={(e) => {\n globalLogger.error(e);\n editor.logger.error(e);\n }}\n fallbackRender={({error, resetErrorBoundary}) => {\n toaster.add({\n theme: 'danger',\n name: 'g-md-editor-error',\n title: i18n('error-title'),\n content: error.message,\n });\n setTimeout(() => {\n resetErrorBoundary();\n editor.changeEditorMode({\n mode: 'markup',\n reason: 'error-boundary',\n emit: false,\n });\n });\n return null;\n }}\n >\n <div\n ref={divRef}\n data-qa={qa}\n className={b(\n {\n settings: areSettingsVisible,\n split: markupSplitMode && editor.splitMode,\n },\n [className],\n )}\n role=\"button\"\n tabIndex={0}\n >\n <EditorWrapper\n autofocus={autofocus}\n editor={editor}\n editorMode={editorMode}\n enableSubmitInPreview={enableSubmitInPreview}\n hidePreviewAfterSubmit={hidePreviewAfterSubmit}\n isFocused={isWrapperFocused(divRef)}\n markupHiddenActionsConfig={markupHiddenActionsConfig}\n markupToolbarConfig={markupToolbarConfig}\n qa=\"g-md-editor-mode\"\n ref={editorWrapperRef}\n settingsVisible={settingsVisible}\n showPreview={showPreview}\n stickyToolbar={stickyToolbar}\n toggleShowPreview={toggleShowPreview}\n toolbarsPreset={toolbarsPreset}\n unsetShowPreview={unsetShowPreview}\n wysiwygHiddenActionsConfig={wysiwygHiddenActionsConfig}\n wysiwygToolbarConfig={wysiwygToolbarConfig}\n />\n\n {markupSplitMode && (\n <>\n {editor.splitMode === 'horizontal' ? (\n <HorizontalDrag\n editor={editor}\n isMounted={isMounted}\n leftElRef={editorWrapperRef}\n rightElRef={splitModeViewWrapperRef}\n wrapperRef={divRef}\n />\n ) : (\n <div className={b('resizer')} />\n )}\n <SplitModeView editor={editor} ref={splitModeViewWrapperRef} />\n </>\n )}\n </div>\n </ErrorBoundary>\n );\n },\n);\nMarkdownEditorView.displayName = 'MarkdownEditorView';\n\ninterface MarkupSearchAnchorProps extends Pick<EditorSettingsProps, 'mode'> {}\n\nconst MarkupSearchAnchor: React.FC<MarkupSearchAnchorProps> = ({mode}) => (\n <>{mode === 'markup' && <div className=\"g-md-search-anchor\"></div>}</>\n);\n\nfunction Settings(props: EditorSettingsProps & {stickyToolbar: boolean}) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const isSticky = useSticky(wrapperRef) && props.toolbarVisibility && props.stickyToolbar;\n\n return (\n <>\n {(props.renderPreviewButton || props.settingsVisible) && (\n <div className={b('settings-wrapper')}>\n <div\n ref={wrapperRef}\n className={stickyCn.settings({\n withToolbar: props.toolbarVisibility,\n stickyActive: isSticky,\n })}\n >\n <EditorSettings {...props} />\n <MarkupSearchAnchor {...props} />\n </div>\n </div>\n )}\n </>\n );\n}\n\nfunction isPreviewKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.shiftKey && e.code === 'KeyP';\n}\n\nfunction isWrapperFocused(divRef: React.RefObject<HTMLDivElement>) {\n return document.activeElement === divRef.current;\n}\n\nfunction isSubmitKeyDown(e: KeyboardEvent) {\n const modKey = isMac() ? e.metaKey : e.ctrlKey;\n return modKey && e.code === 'Enter';\n}\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Popup } from '@gravity-ui/uikit';
|
|
3
3
|
import { GptDialog } from "../GptDialog/GptDialog.js";
|
|
4
|
+
import { gptPopupPlacement } from "../constants.js";
|
|
4
5
|
import { cnGptPopup } from "../gptExtension/view.js";
|
|
5
6
|
export function renderPopup(anchor, props) {
|
|
6
7
|
return (_jsx(Popup, { className: cnGptPopup(), open: true, strategy: "absolute", onOpenChange: (open) => {
|
|
7
8
|
if (!open)
|
|
8
9
|
props.onClose();
|
|
9
|
-
}, anchorElement: anchor, children: _jsx("div", { className: cnGptPopup('content'), children: _jsx(GptDialog, { markup: props.markup, answerRender: props.answerRender, promptPresets: props.promptPresets, disablePromptPresets: props.disablePromptPresets, customPromptPlaceholder: props.customPromptPlaceholder, disabledPromptPlaceholder: props.disabledPromptPlaceholder, onApplyResult: props.onApplyResult, onCustomPromptApply: props.onCustomPromptApply, onPromptPresetClick: props.onPromptPresetClick, onTryAgain: props.onTryAgain, onLike: props.onLike, onDislike: props.onDislike, onClose: props.onClose, onUpdate: props.onUpdate, gptAlertProps: props.gptAlertProps }) }) }));
|
|
10
|
+
}, anchorElement: anchor, placement: gptPopupPlacement, children: _jsx("div", { className: cnGptPopup('content'), children: _jsx(GptDialog, { markup: props.markup, answerRender: props.answerRender, promptPresets: props.promptPresets, disablePromptPresets: props.disablePromptPresets, customPromptPlaceholder: props.customPromptPlaceholder, disabledPromptPlaceholder: props.disabledPromptPlaceholder, onApplyResult: props.onApplyResult, onCustomPromptApply: props.onCustomPromptApply, onPromptPresetClick: props.onPromptPresetClick, onTryAgain: props.onTryAgain, onLike: props.onLike, onDislike: props.onDislike, onClose: props.onClose, onUpdate: props.onUpdate, gptAlertProps: props.gptAlertProps }) }) }));
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=popup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popup.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/GPT/MarkupGpt/popup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAGxC,OAAO,EAAC,SAAS,EAAsB,kCAA+B;AACtE,OAAO,EAAC,UAAU,EAAC,gCAA6B;AAShD,MAAM,UAAU,WAAW,CAGzB,MAAmB,EAAE,KAAoC;IACvD,OAAO,CACH,KAAC,KAAK,IACF,SAAS,EAAE,UAAU,EAAE,EACvB,IAAI,QACJ,QAAQ,EAAC,UAAU,EACnB,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,CAAC,IAAI;gBAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC,EACD,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"popup.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/GPT/MarkupGpt/popup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAGxC,OAAO,EAAC,SAAS,EAAsB,kCAA+B;AACtE,OAAO,EAAC,iBAAiB,EAAC,wBAAqB;AAC/C,OAAO,EAAC,UAAU,EAAC,gCAA6B;AAShD,MAAM,UAAU,WAAW,CAGzB,MAAmB,EAAE,KAAoC;IACvD,OAAO,CACH,KAAC,KAAK,IACF,SAAS,EAAE,UAAU,EAAE,EACvB,IAAI,QACJ,QAAQ,EAAC,UAAU,EACnB,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,CAAC,IAAI;gBAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC,EACD,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,iBAAiB,YAE5B,cAAK,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,YACjC,KAAC,SAAS,IACN,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,oBAAoB,EAAE,KAAK,CAAC,oBAAoB,EAChD,uBAAuB,EAAE,KAAK,CAAC,uBAAuB,EACtD,yBAAyB,EAAE,KAAK,CAAC,yBAAyB,EAC1D,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,UAAU,EAAE,KAAK,CAAC,UAAU,EAC5B,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,aAAa,EAAE,KAAK,CAAC,aAAa,GACpC,GACA,GACF,CACX,CAAC;AACN,CAAC","sourcesContent":["import {Popup} from '@gravity-ui/uikit';\n\nimport type {CommonAnswer} from '../ErrorScreen/types';\nimport {GptDialog, type GptDialogProps} from '../GptDialog/GptDialog';\nimport {gptPopupPlacement} from '../constants';\nimport {cnGptPopup} from '../gptExtension/view';\n\ntype Props<AnswerData extends CommonAnswer = CommonAnswer, PromptData extends unknown = unknown> = {\n onClose: () => void;\n markup: string;\n onConfirmOk?: () => void;\n onConfirmCancel?: () => void;\n} & GptDialogProps<AnswerData, PromptData>;\n\nexport function renderPopup<\n AnswerData extends CommonAnswer = CommonAnswer,\n PromptData extends unknown = unknown,\n>(anchor: HTMLElement, props: Props<AnswerData, PromptData>) {\n return (\n <Popup\n className={cnGptPopup()}\n open\n strategy=\"absolute\"\n onOpenChange={(open) => {\n if (!open) props.onClose();\n }}\n anchorElement={anchor}\n placement={gptPopupPlacement}\n >\n <div className={cnGptPopup('content')}>\n <GptDialog\n markup={props.markup}\n answerRender={props.answerRender}\n promptPresets={props.promptPresets}\n disablePromptPresets={props.disablePromptPresets}\n customPromptPlaceholder={props.customPromptPlaceholder}\n disabledPromptPlaceholder={props.disabledPromptPlaceholder}\n onApplyResult={props.onApplyResult}\n onCustomPromptApply={props.onCustomPromptApply}\n onPromptPresetClick={props.onPromptPresetClick}\n onTryAgain={props.onTryAgain}\n onLike={props.onLike}\n onDislike={props.onDislike}\n onClose={props.onClose}\n onUpdate={props.onUpdate}\n gptAlertProps={props.gptAlertProps}\n />\n </div>\n </Popup>\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.1' !== 'undefined' ? '15.12.1' : '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.1' !== 'undefined' ? '15.12.1' : '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,KAAK,CAAC,MAAM,CAAC,OAAO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,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.1",
|
|
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",
|