@gravity-ui/markdown-editor 15.4.2 → 15.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/bundle/MarkdownEditorView.d.ts +3 -2
- package/build/cjs/bundle/MarkdownEditorView.js +3 -3
- package/build/cjs/bundle/MarkdownEditorView.js.map +1 -1
- package/build/cjs/bundle/MarkupEditorView.d.ts +2 -1
- package/build/cjs/bundle/MarkupEditorView.js +2 -2
- package/build/cjs/bundle/MarkupEditorView.js.map +1 -1
- package/build/cjs/bundle/WysiwygEditorView.d.ts +2 -1
- package/build/cjs/bundle/WysiwygEditorView.js +2 -2
- package/build/cjs/bundle/WysiwygEditorView.js.map +1 -1
- package/build/cjs/bundle/config/action-names.d.ts +1 -1
- package/build/cjs/bundle/config/action-names.js +1 -0
- package/build/cjs/bundle/config/action-names.js.map +1 -1
- package/build/cjs/bundle/config/icons.d.ts +1 -1
- package/build/cjs/bundle/config/icons.js +1 -0
- package/build/cjs/bundle/config/icons.js.map +1 -1
- package/build/cjs/bundle/config/w-heading-config.js +1 -0
- package/build/cjs/bundle/config/w-heading-config.js.map +1 -1
- package/build/cjs/bundle/settings/index.js +3 -3
- package/build/cjs/bundle/settings/index.js.map +1 -1
- package/build/cjs/bundle/toolbar/utils/toolbarsConfigs.js +4 -1
- package/build/cjs/bundle/toolbar/utils/toolbarsConfigs.js.map +1 -1
- package/build/cjs/bundle/types.d.ts +6 -0
- package/build/cjs/bundle/types.js.map +1 -1
- package/build/cjs/bundle/useMarkdownEditor.js +1 -0
- package/build/cjs/bundle/useMarkdownEditor.js.map +1 -1
- package/build/cjs/bundle/wysiwyg-preset.d.ts +1 -0
- package/build/cjs/bundle/wysiwyg-preset.js +1 -0
- package/build/cjs/bundle/wysiwyg-preset.js.map +1 -1
- package/build/cjs/extensions/additional/QuoteLink/PlaceholderWidget/commands.d.ts +3 -0
- package/build/cjs/extensions/additional/QuoteLink/PlaceholderWidget/commands.js +10 -0
- package/build/cjs/extensions/additional/QuoteLink/PlaceholderWidget/commands.js.map +1 -0
- package/build/cjs/extensions/additional/QuoteLink/PlaceholderWidget/descriptor.d.ts +16 -0
- package/build/cjs/extensions/additional/QuoteLink/PlaceholderWidget/descriptor.js +72 -0
- package/build/cjs/extensions/additional/QuoteLink/PlaceholderWidget/descriptor.js.map +1 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/index.d.ts +10 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js +71 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js.map +1 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.d.ts +2 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.js +41 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.js.map +1 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.d.ts +6 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.js +24 -0
- package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.js.map +1 -0
- package/build/cjs/extensions/additional/QuoteLink/commands.d.ts +4 -0
- package/build/cjs/extensions/additional/QuoteLink/commands.js +45 -0
- package/build/cjs/extensions/additional/QuoteLink/commands.js.map +1 -0
- package/build/cjs/extensions/additional/QuoteLink/index.css +32 -0
- package/build/cjs/extensions/additional/QuoteLink/index.d.ts +16 -0
- package/build/cjs/extensions/additional/QuoteLink/index.js +42 -0
- package/build/cjs/extensions/additional/QuoteLink/index.js.map +1 -0
- package/build/cjs/extensions/additional/YfmHtmlBlock/utils.js +2 -12
- package/build/cjs/extensions/additional/YfmHtmlBlock/utils.js.map +1 -1
- package/build/cjs/extensions/behavior/Clipboard/utils.d.ts +8 -1
- package/build/cjs/extensions/behavior/Clipboard/utils.js +3 -3
- package/build/cjs/extensions/behavior/Clipboard/utils.js.map +1 -1
- package/build/cjs/extensions/markdown/Html/schema.js +3 -3
- package/build/cjs/extensions/markdown/Html/schema.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/actions.js +2 -2
- package/build/cjs/extensions/markdown/Lists/actions.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/commands.d.ts +2 -1
- package/build/cjs/extensions/markdown/Lists/commands.js +64 -0
- package/build/cjs/extensions/markdown/Lists/commands.js.map +1 -1
- package/build/cjs/extensions/markdown/Lists/index.js +2 -2
- package/build/cjs/extensions/markdown/Lists/index.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.d.ts +2 -0
- package/build/cjs/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.js +5 -2
- package/build/cjs/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +2 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js.map +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/markdown/heading-attrs.d.ts +9 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/markdown/heading-attrs.js +46 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/markdown/heading-attrs.js.map +1 -0
- package/build/cjs/i18n/menubar/en.json +1 -0
- package/build/cjs/i18n/menubar/index.d.ts +2 -1
- package/build/cjs/i18n/menubar/ru.json +1 -0
- package/build/cjs/icons/index.d.ts +1 -1
- package/build/cjs/icons/index.js +2 -1
- package/build/cjs/icons/index.js.map +1 -1
- package/build/cjs/markup/commands/blocks.d.ts +1 -0
- package/build/cjs/markup/commands/blocks.js +8 -1
- package/build/cjs/markup/commands/blocks.js.map +1 -1
- package/build/cjs/modules/toolbars/items.d.ts +3 -0
- package/build/cjs/modules/toolbars/items.js +23 -3
- package/build/cjs/modules/toolbars/items.js.map +1 -1
- package/build/cjs/modules/toolbars/types.d.ts +2 -0
- package/build/cjs/modules/toolbars/types.js.map +1 -1
- package/build/cjs/toolbar/ToolbarListButton.d.ts +1 -1
- package/build/cjs/toolbar/ToolbarListButton.js +6 -4
- package/build/cjs/toolbar/ToolbarListButton.js.map +1 -1
- package/build/cjs/toolbar/types.d.ts +2 -0
- package/build/cjs/toolbar/types.js.map +1 -1
- package/build/cjs/utils/getSanitize.d.ts +4 -0
- package/build/cjs/utils/getSanitize.js +16 -0
- package/build/cjs/utils/getSanitize.js.map +1 -0
- package/build/cjs/version.js +1 -1
- package/build/cjs/version.js.map +1 -1
- package/build/esm/bundle/MarkdownEditorView.d.ts +3 -2
- package/build/esm/bundle/MarkdownEditorView.js +3 -3
- package/build/esm/bundle/MarkdownEditorView.js.map +1 -1
- package/build/esm/bundle/MarkupEditorView.d.ts +2 -1
- package/build/esm/bundle/MarkupEditorView.js +2 -2
- package/build/esm/bundle/MarkupEditorView.js.map +1 -1
- package/build/esm/bundle/WysiwygEditorView.d.ts +2 -1
- package/build/esm/bundle/WysiwygEditorView.js +2 -2
- package/build/esm/bundle/WysiwygEditorView.js.map +1 -1
- package/build/esm/bundle/config/action-names.d.ts +1 -1
- package/build/esm/bundle/config/action-names.js +1 -0
- package/build/esm/bundle/config/action-names.js.map +1 -1
- package/build/esm/bundle/config/icons.d.ts +1 -1
- package/build/esm/bundle/config/icons.js +2 -1
- package/build/esm/bundle/config/icons.js.map +1 -1
- package/build/esm/bundle/config/w-heading-config.js +1 -0
- package/build/esm/bundle/config/w-heading-config.js.map +1 -1
- package/build/esm/bundle/settings/index.js +3 -3
- package/build/esm/bundle/settings/index.js.map +1 -1
- package/build/esm/bundle/toolbar/utils/toolbarsConfigs.js +4 -1
- package/build/esm/bundle/toolbar/utils/toolbarsConfigs.js.map +1 -1
- package/build/esm/bundle/types.d.ts +6 -0
- package/build/esm/bundle/types.js.map +1 -1
- package/build/esm/bundle/useMarkdownEditor.js +1 -0
- package/build/esm/bundle/useMarkdownEditor.js.map +1 -1
- package/build/esm/bundle/wysiwyg-preset.d.ts +1 -0
- package/build/esm/bundle/wysiwyg-preset.js +1 -0
- package/build/esm/bundle/wysiwyg-preset.js.map +1 -1
- package/build/esm/extensions/additional/QuoteLink/PlaceholderWidget/commands.d.ts +3 -0
- package/build/esm/extensions/additional/QuoteLink/PlaceholderWidget/commands.js +6 -0
- package/build/esm/extensions/additional/QuoteLink/PlaceholderWidget/commands.js.map +1 -0
- package/build/esm/extensions/additional/QuoteLink/PlaceholderWidget/descriptor.d.ts +16 -0
- package/build/esm/extensions/additional/QuoteLink/PlaceholderWidget/descriptor.js +67 -0
- package/build/esm/extensions/additional/QuoteLink/PlaceholderWidget/descriptor.js.map +1 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/index.d.ts +10 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js +66 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js.map +1 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.d.ts +2 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.js +37 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.js.map +1 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.d.ts +6 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.js +21 -0
- package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.js.map +1 -0
- package/build/esm/extensions/additional/QuoteLink/commands.d.ts +4 -0
- package/build/esm/extensions/additional/QuoteLink/commands.js +41 -0
- package/build/esm/extensions/additional/QuoteLink/commands.js.map +1 -0
- package/build/esm/extensions/additional/QuoteLink/index.css +32 -0
- package/build/esm/extensions/additional/QuoteLink/index.d.ts +16 -0
- package/build/esm/extensions/additional/QuoteLink/index.js +38 -0
- package/build/esm/extensions/additional/QuoteLink/index.js.map +1 -0
- package/build/esm/extensions/additional/YfmHtmlBlock/utils.js +2 -11
- package/build/esm/extensions/additional/YfmHtmlBlock/utils.js.map +1 -1
- package/build/esm/extensions/behavior/Clipboard/utils.d.ts +8 -1
- package/build/esm/extensions/behavior/Clipboard/utils.js +3 -3
- package/build/esm/extensions/behavior/Clipboard/utils.js.map +1 -1
- package/build/esm/extensions/markdown/Html/schema.js +2 -1
- package/build/esm/extensions/markdown/Html/schema.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/actions.js +4 -4
- package/build/esm/extensions/markdown/Lists/actions.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/commands.d.ts +2 -1
- package/build/esm/extensions/markdown/Lists/commands.js +63 -0
- package/build/esm/extensions/markdown/Lists/commands.js.map +1 -1
- package/build/esm/extensions/markdown/Lists/index.js +4 -4
- package/build/esm/extensions/markdown/Lists/index.js.map +1 -1
- package/build/esm/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.d.ts +2 -0
- package/build/esm/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.js +5 -2
- package/build/esm/extensions/yfm/YfmConfigs/YfmConfigsSpecs/index.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +2 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js.map +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/markdown/heading-attrs.d.ts +9 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/markdown/heading-attrs.js +42 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/markdown/heading-attrs.js.map +1 -0
- package/build/esm/i18n/menubar/en.json +1 -0
- package/build/esm/i18n/menubar/index.d.ts +2 -1
- package/build/esm/i18n/menubar/ru.json +1 -0
- package/build/esm/icons/index.d.ts +1 -1
- package/build/esm/icons/index.js +1 -1
- package/build/esm/icons/index.js.map +1 -1
- package/build/esm/markup/commands/blocks.d.ts +1 -0
- package/build/esm/markup/commands/blocks.js +6 -0
- package/build/esm/markup/commands/blocks.js.map +1 -1
- package/build/esm/modules/toolbars/items.d.ts +3 -0
- package/build/esm/modules/toolbars/items.js +21 -1
- package/build/esm/modules/toolbars/items.js.map +1 -1
- package/build/esm/modules/toolbars/types.d.ts +2 -0
- package/build/esm/modules/toolbars/types.js.map +1 -1
- package/build/esm/toolbar/ToolbarListButton.d.ts +1 -1
- package/build/esm/toolbar/ToolbarListButton.js +6 -4
- package/build/esm/toolbar/ToolbarListButton.js.map +1 -1
- package/build/esm/toolbar/types.d.ts +2 -0
- package/build/esm/toolbar/types.js.map +1 -1
- package/build/esm/utils/getSanitize.d.ts +4 -0
- package/build/esm/utils/getSanitize.js +11 -0
- package/build/esm/utils/getSanitize.js.map +1 -0
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/styles.css +32 -0
- package/package.json +9 -1
|
@@ -159,6 +159,12 @@ export type MarkdownEditorWysiwygConfig = {
|
|
|
159
159
|
extensionOptions?: ExtensionsOptions;
|
|
160
160
|
escapeConfig?: EscapeConfig;
|
|
161
161
|
placeholderOptions?: WysiwygPlaceholderOptions;
|
|
162
|
+
/**
|
|
163
|
+
* Disable the markdown-it-attrs plugin in the markup parser.
|
|
164
|
+
*
|
|
165
|
+
* Note: The use of the markdown-it-attrs plugin will be removed in the next major version.
|
|
166
|
+
*/
|
|
167
|
+
disableMarkdownAttrs?: boolean;
|
|
162
168
|
};
|
|
163
169
|
export type MarkdownEditorOptions = {
|
|
164
170
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"../../../src","sources":["bundle/types.ts"],"names":[],"mappings":";AAAA,mDAAmD","sourcesContent":["// public types, re-exported in src/bundle/index.ts\n\nimport type {ReactNode} from 'react';\n\nimport type {MarkupString} from '../common';\nimport type {EscapeConfig, Extension} from '../core';\nimport type {Logger2} from '../logger';\nimport type {CreateCodemirrorParams, YfmLangOptions} from '../markup';\nimport type {FileUploadHandler} from '../utils';\nimport type {DirectiveSyntaxContext, DirectiveSyntaxOption} from '../utils/directive';\n\nimport type {ChangeEditorModeOptions} from './Editor';\nimport type {ExtensionsOptions as WysiwygPresetExtensionsOptions} from './wysiwyg-preset';\n\nexport type {Editor as MarkdownEditorInstance} from './Editor';\nexport type MarkdownEditorMode = 'wysiwyg' | 'markup';\nexport type MarkdownEditorPreset = 'zero' | 'commonmark' | 'default' | 'yfm' | 'full';\nexport type MarkdownEditorSplitMode = false | 'horizontal' | 'vertical';\n\nexport type RenderPreviewParams = {\n getValue: () => MarkupString;\n mode: 'preview' | 'split';\n md: Readonly<MarkdownEditorMdOptions>;\n directiveSyntax: Pick<DirectiveSyntaxContext, 'option' | 'valueFor' | 'mdPluginValueFor'>;\n};\nexport type RenderPreview = (params: RenderPreviewParams) => ReactNode;\n\nexport type ParseInsertedUrlAsImage = (text: string) => {imageUrl: string; title?: string} | null;\n\nexport type WysiwygPlaceholderOptions = {\n value?: string | (() => string);\n /** Default – empty-doc\n Values:\n - 'empty-doc' – The placeholder will only be shown when the document is completely empty;\n - 'empty-row-top-level' – The placeholder will be displayed in an empty line that is at the top level of the document structure;\n - 'empty-row' – The placeholder will be shown in any empty line within the document, regardless of its nesting level.\n */\n behavior?: 'empty-doc' | 'empty-row-top-level' | 'empty-row';\n};\n\nexport type MarkdownEditorMdOptions = {\n html?: boolean;\n breaks?: boolean;\n linkify?: boolean;\n linkifyTlds?: string | string[];\n};\n\nexport type MarkdownEditorInitialOptions = {\n markup?: MarkupString;\n /** Default – wysiwyg */\n mode?: MarkdownEditorMode;\n /** Default – true */\n toolbarVisible?: boolean;\n /**\n * Default – false\n *\n * Note: has no effect if `MarkdownEditorMarkupConfig.splitMode` is set to false or is not set.\n */\n splitModeEnabled?: boolean;\n};\n\nexport type MarkdownEditorHandlers = {\n /** Pass this handler to allow uploading files from device. */\n uploadFile?: FileUploadHandler;\n};\n\nexport type MarkdownEditorExperimentalOptions = {\n /**\n * If we need to set dimensions for uploaded images\n *\n * @default false\n */\n needToSetDimensionsForUploadedImages?: boolean;\n /**\n * If we need to enable new image size calculations\n *\n * @default false\n */\n enableNewImageSizeCalculation?: boolean;\n /**\n * Called before switching from the markup editor to the wysiwyg editor.\n * You can use it to pre-process the value from the markup editor before it gets into the wysiwyg editor.\n */\n prepareRawMarkup?: (value: MarkupString) => MarkupString;\n beforeEditorModeChange?: (\n options: Pick<ChangeEditorModeOptions, 'mode' | 'reason'>,\n ) => boolean | undefined;\n /**\n * Enables support of directive syntax for diplodoc (YFM) extensions.\n *\n * **Note:** This setting affects parsing of markdown markup and serializing to markdown markup.\n * Be careful with it and use it in consistency with diplodoc/transform and diplodoc-extensions.\n *\n * Before enabling this option, make sure that appropriate versions of diplodoc/transform and diplodoc-extensions are installed.\n *\n * You can pass an object in `key:value` format to provide different behaviour for each extension individually.\n *\n * Values:\n * - 'disabled' – directive syntax is disabled;\n * - 'enabled' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using old syntax;\n * - 'preserve' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using directive syntax;\n * - 'overwrite' – existing blocks will be overwritten using directive syntax through serialization;\n * - 'only' – old syntax is disabled, only directive syntax available. Blocks in old syntax will not be parsed.\n *\n * Default value is 'disabled'.\n */\n directiveSyntax?: DirectiveSyntaxOption;\n /**\n * If we need support for empty strings\n *\n * @default false\n */\n preserveEmptyRows?: boolean;\n /**\n * Preserves the original formatting of unmodified blocks,\n * restoring their structure during serialization\n *\n * **Use case:** Maintain consistent markup when switching modes\n *\n * **Note:** Applies to tracked blocks: `yfm_table`\n *\n * @default false\n */\n preserveMarkupFormatting?: boolean;\n};\n\nexport type MarkdownEditorMarkupConfig = {\n /**\n * Pass the rendering function to preview the markdown content.\n *\n * It is also used for split view rendering.\n *\n * If false is passed, preview will be disabled.\n */\n renderPreview?: RenderPreview;\n /**\n * Pass position of split view.\n *\n * Note: for enable split view, you need to pass renderPreview function too.\n *\n * If false is passed, split view will be disabled.\n */\n splitMode?: MarkdownEditorSplitMode;\n /** Additional extensions for codemirror instance. */\n extensions?: CreateCodemirrorParams['extensions'];\n /** Can be used to disable some of the default extensions */\n disabledExtensions?: CreateCodemirrorParams['disabledExtensions'];\n /** Additional keymaps for codemirror instance */\n keymaps?: CreateCodemirrorParams['keymaps'];\n /** Overrides the default placeholder content. */\n placeholder?: CreateCodemirrorParams['placeholder'];\n /** Enable HTML parsing when pasting content. */\n parseHtmlOnPaste?: boolean;\n /**\n * Additional language data for markdown language in codemirror.\n * Can be used to configure additional autocompletions and others.\n * See more https://codemirror.net/docs/ref/#state.EditorState.languageDataAt\n */\n languageData?: YfmLangOptions['languageData'];\n /** Config for @codemirror/autocomplete https://codemirror.net/docs/ref/#autocomplete.autocompletion%5Econfig */\n autocompletion?: CreateCodemirrorParams['autocompletion'];\n /**\n * The function, used to determine if the pasted text is the image url and should be inserted as an image\n */\n parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;\n};\n\n// do not export this type\ntype ExtensionsOptions<T extends object = {}> = Omit<\n WysiwygPresetExtensionsOptions,\n 'reactRenderer'\n> &\n T;\n\nexport type MarkdownEditorWysiwygConfig = {\n /** Additional extensions */\n extensions?: Extension;\n extensionOptions?: ExtensionsOptions;\n escapeConfig?: EscapeConfig;\n placeholderOptions?: WysiwygPlaceholderOptions;\n};\n\nexport type MarkdownEditorOptions = {\n /**\n * A set of plug-in extensions.\n *\n * @default 'full'\n */\n preset?: MarkdownEditorPreset;\n /** Markdown parser options */\n md?: MarkdownEditorMdOptions;\n /** Initial values */\n initial?: MarkdownEditorInitialOptions;\n handlers?: MarkdownEditorHandlers;\n experimental?: MarkdownEditorExperimentalOptions;\n /** Options for markup mode */\n markupConfig?: MarkdownEditorMarkupConfig;\n /** Options for wysiwyg mode */\n wysiwygConfig?: MarkdownEditorWysiwygConfig;\n logger?: Logger2.ILogger;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../../../src","sources":["bundle/types.ts"],"names":[],"mappings":";AAAA,mDAAmD","sourcesContent":["// public types, re-exported in src/bundle/index.ts\n\nimport type {ReactNode} from 'react';\n\nimport type {MarkupString} from '../common';\nimport type {EscapeConfig, Extension} from '../core';\nimport type {Logger2} from '../logger';\nimport type {CreateCodemirrorParams, YfmLangOptions} from '../markup';\nimport type {FileUploadHandler} from '../utils';\nimport type {DirectiveSyntaxContext, DirectiveSyntaxOption} from '../utils/directive';\n\nimport type {ChangeEditorModeOptions} from './Editor';\nimport type {ExtensionsOptions as WysiwygPresetExtensionsOptions} from './wysiwyg-preset';\n\nexport type {Editor as MarkdownEditorInstance} from './Editor';\nexport type MarkdownEditorMode = 'wysiwyg' | 'markup';\nexport type MarkdownEditorPreset = 'zero' | 'commonmark' | 'default' | 'yfm' | 'full';\nexport type MarkdownEditorSplitMode = false | 'horizontal' | 'vertical';\n\nexport type RenderPreviewParams = {\n getValue: () => MarkupString;\n mode: 'preview' | 'split';\n md: Readonly<MarkdownEditorMdOptions>;\n directiveSyntax: Pick<DirectiveSyntaxContext, 'option' | 'valueFor' | 'mdPluginValueFor'>;\n};\nexport type RenderPreview = (params: RenderPreviewParams) => ReactNode;\n\nexport type ParseInsertedUrlAsImage = (text: string) => {imageUrl: string; title?: string} | null;\n\nexport type WysiwygPlaceholderOptions = {\n value?: string | (() => string);\n /** Default – empty-doc\n Values:\n - 'empty-doc' – The placeholder will only be shown when the document is completely empty;\n - 'empty-row-top-level' – The placeholder will be displayed in an empty line that is at the top level of the document structure;\n - 'empty-row' – The placeholder will be shown in any empty line within the document, regardless of its nesting level.\n */\n behavior?: 'empty-doc' | 'empty-row-top-level' | 'empty-row';\n};\n\nexport type MarkdownEditorMdOptions = {\n html?: boolean;\n breaks?: boolean;\n linkify?: boolean;\n linkifyTlds?: string | string[];\n};\n\nexport type MarkdownEditorInitialOptions = {\n markup?: MarkupString;\n /** Default – wysiwyg */\n mode?: MarkdownEditorMode;\n /** Default – true */\n toolbarVisible?: boolean;\n /**\n * Default – false\n *\n * Note: has no effect if `MarkdownEditorMarkupConfig.splitMode` is set to false or is not set.\n */\n splitModeEnabled?: boolean;\n};\n\nexport type MarkdownEditorHandlers = {\n /** Pass this handler to allow uploading files from device. */\n uploadFile?: FileUploadHandler;\n};\n\nexport type MarkdownEditorExperimentalOptions = {\n /**\n * If we need to set dimensions for uploaded images\n *\n * @default false\n */\n needToSetDimensionsForUploadedImages?: boolean;\n /**\n * If we need to enable new image size calculations\n *\n * @default false\n */\n enableNewImageSizeCalculation?: boolean;\n /**\n * Called before switching from the markup editor to the wysiwyg editor.\n * You can use it to pre-process the value from the markup editor before it gets into the wysiwyg editor.\n */\n prepareRawMarkup?: (value: MarkupString) => MarkupString;\n beforeEditorModeChange?: (\n options: Pick<ChangeEditorModeOptions, 'mode' | 'reason'>,\n ) => boolean | undefined;\n /**\n * Enables support of directive syntax for diplodoc (YFM) extensions.\n *\n * **Note:** This setting affects parsing of markdown markup and serializing to markdown markup.\n * Be careful with it and use it in consistency with diplodoc/transform and diplodoc-extensions.\n *\n * Before enabling this option, make sure that appropriate versions of diplodoc/transform and diplodoc-extensions are installed.\n *\n * You can pass an object in `key:value` format to provide different behaviour for each extension individually.\n *\n * Values:\n * - 'disabled' – directive syntax is disabled;\n * - 'enabled' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using old syntax;\n * - 'preserve' – directive syntax is enabled. Syntax of existing blocks is preserved. New blocks will be serialized using directive syntax;\n * - 'overwrite' – existing blocks will be overwritten using directive syntax through serialization;\n * - 'only' – old syntax is disabled, only directive syntax available. Blocks in old syntax will not be parsed.\n *\n * Default value is 'disabled'.\n */\n directiveSyntax?: DirectiveSyntaxOption;\n /**\n * If we need support for empty strings\n *\n * @default false\n */\n preserveEmptyRows?: boolean;\n /**\n * Preserves the original formatting of unmodified blocks,\n * restoring their structure during serialization\n *\n * **Use case:** Maintain consistent markup when switching modes\n *\n * **Note:** Applies to tracked blocks: `yfm_table`\n *\n * @default false\n */\n preserveMarkupFormatting?: boolean;\n};\n\nexport type MarkdownEditorMarkupConfig = {\n /**\n * Pass the rendering function to preview the markdown content.\n *\n * It is also used for split view rendering.\n *\n * If false is passed, preview will be disabled.\n */\n renderPreview?: RenderPreview;\n /**\n * Pass position of split view.\n *\n * Note: for enable split view, you need to pass renderPreview function too.\n *\n * If false is passed, split view will be disabled.\n */\n splitMode?: MarkdownEditorSplitMode;\n /** Additional extensions for codemirror instance. */\n extensions?: CreateCodemirrorParams['extensions'];\n /** Can be used to disable some of the default extensions */\n disabledExtensions?: CreateCodemirrorParams['disabledExtensions'];\n /** Additional keymaps for codemirror instance */\n keymaps?: CreateCodemirrorParams['keymaps'];\n /** Overrides the default placeholder content. */\n placeholder?: CreateCodemirrorParams['placeholder'];\n /** Enable HTML parsing when pasting content. */\n parseHtmlOnPaste?: boolean;\n /**\n * Additional language data for markdown language in codemirror.\n * Can be used to configure additional autocompletions and others.\n * See more https://codemirror.net/docs/ref/#state.EditorState.languageDataAt\n */\n languageData?: YfmLangOptions['languageData'];\n /** Config for @codemirror/autocomplete https://codemirror.net/docs/ref/#autocomplete.autocompletion%5Econfig */\n autocompletion?: CreateCodemirrorParams['autocompletion'];\n /**\n * The function, used to determine if the pasted text is the image url and should be inserted as an image\n */\n parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;\n};\n\n// do not export this type\ntype ExtensionsOptions<T extends object = {}> = Omit<\n WysiwygPresetExtensionsOptions,\n 'reactRenderer'\n> &\n T;\n\nexport type MarkdownEditorWysiwygConfig = {\n /** Additional extensions */\n extensions?: Extension;\n extensionOptions?: ExtensionsOptions;\n escapeConfig?: EscapeConfig;\n placeholderOptions?: WysiwygPlaceholderOptions;\n // MAJOR: remove markdown-it-attrs\n /**\n * Disable the markdown-it-attrs plugin in the markup parser.\n *\n * Note: The use of the markdown-it-attrs plugin will be removed in the next major version.\n */\n disableMarkdownAttrs?: boolean;\n};\n\nexport type MarkdownEditorOptions = {\n /**\n * A set of plug-in extensions.\n *\n * @default 'full'\n */\n preset?: MarkdownEditorPreset;\n /** Markdown parser options */\n md?: MarkdownEditorMdOptions;\n /** Initial values */\n initial?: MarkdownEditorInitialOptions;\n handlers?: MarkdownEditorHandlers;\n experimental?: MarkdownEditorExperimentalOptions;\n /** Options for markup mode */\n markupConfig?: MarkdownEditorMarkupConfig;\n /** Options for wysiwyg mode */\n wysiwygConfig?: MarkdownEditorWysiwygConfig;\n logger?: Logger2.ILogger;\n};\n"]}
|
|
@@ -32,6 +32,7 @@ function useMarkdownEditor(props, deps = []) {
|
|
|
32
32
|
editor.emit('submit', null);
|
|
33
33
|
return true;
|
|
34
34
|
},
|
|
35
|
+
disableMdAttrs: wysiwygConfig.disableMarkdownAttrs,
|
|
35
36
|
preserveEmptyRows: experimental.preserveEmptyRows,
|
|
36
37
|
placeholderOptions: wysiwygConfig.placeholderOptions,
|
|
37
38
|
mdBreaks: md.breaks,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMarkdownEditor.js","sourceRoot":"../../../src","sources":["bundle/useMarkdownEditor.ts"],"names":[],"mappings":";;AAmBA,
|
|
1
|
+
{"version":3,"file":"useMarkdownEditor.js","sourceRoot":"../../../src","sources":["bundle/useMarkdownEditor.ts"],"names":[],"mappings":";;AAmBA,8CAyFC;AA5GD,iCAA+C;AAG/C,gGAA0F;AAC1F,uDAAiD;AACjD,yCAAgD;AAChD,qDAA0D;AAE1D,wCAAoD;AAOpD,wDAA8C;AAI9C,SAAgB,iBAAiB,CAC7B,KAA6B,EAC7B,OAA6B,EAAE;IAE/B,MAAM,MAAM,GAAG,IAAA,eAAO,EAAY,GAAG,EAAE;QACnC,MAAM,EACF,EAAE,GAAG,EAAE,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C,6BAA6B;aAC5E,CAAC,CAAC;YACH,CAAC;gBACG,MAAM,eAAe,GAAG,aAAa,CAAC,UAAU,CAAC;gBACjD,IAAI,eAAe,EAAE,CAAC;oBAClB,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;gBACxE,CAAC;YACL,CAAC;QACL,CAAC,CAAC;QAEF,OAAO,IAAI,mBAAU,CAAC;YAClB,GAAG,KAAK;YACR,MAAM;YACN,MAAM;YACN,aAAa;YACb,eAAe;YACf,cAAc;YACd,EAAE;YACF,OAAO;YACP,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,aAAa,EAAE;gBACX,GAAG,aAAa;gBAChB,UAAU;aACb;SACJ,CAAC,CAAC;IACP,CAAC,EAAE,IAAI,CAAC,CAAC;IAET,IAAA,uBAAe,EAAC,GAAG,EAAE;QACjB,SAAS,eAAe,CAAC,EAAC,UAAU,EAAE,EAAE,EAA+C;YACnF,qBAAY,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;YACvE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;QAC7C,OAAO,GAAG,EAAE;YACR,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;YAC9C,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACb,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import {useLayoutEffect, useMemo} from 'react';\n\nimport type {Extension} from '../core';\nimport {getPMTransformers} from '../core/markdown/ProseMirrorTransformer/getTransformers';\nimport {ReactRenderStorage} from '../extensions';\nimport {Logger2, globalLogger} from '../logger';\nimport {DirectiveSyntaxContext} from '../utils/directive';\n\nimport {EditorImpl, type EditorInt} from './Editor';\nimport type {\n MarkdownEditorInstance,\n MarkdownEditorMode,\n MarkdownEditorOptions,\n MarkdownEditorPreset,\n} from './types';\nimport {BundlePreset} from './wysiwyg-preset';\n\nexport type UseMarkdownEditorProps = MarkdownEditorOptions;\n\nexport function useMarkdownEditor(\n props: UseMarkdownEditorProps,\n deps: React.DependencyList = [],\n): MarkdownEditorInstance {\n const editor = useMemo<EditorInt>(() => {\n const {\n md = {},\n initial = {},\n handlers = {},\n experimental = {},\n markupConfig = {},\n wysiwygConfig = {},\n logger = new Logger2(),\n } = props;\n\n const preset: MarkdownEditorPreset = props.preset ?? 'full';\n const renderStorage = new ReactRenderStorage();\n\n const pmTransformers = getPMTransformers({\n emptyRowTransformer: experimental.preserveEmptyRows,\n });\n\n const directiveSyntax = new DirectiveSyntaxContext(experimental.directiveSyntax);\n\n const extensions: Extension = (builder) => {\n const extensionOptions = wysiwygConfig.extensionOptions;\n\n builder.use(BundlePreset, {\n ...extensionOptions,\n directiveSyntax,\n preset,\n reactRenderer: renderStorage,\n onCancel: () => {\n editor.emit('cancel', null);\n return true;\n },\n onSubmit: () => {\n editor.emit('submit', null);\n return true;\n },\n disableMdAttrs: wysiwygConfig.disableMarkdownAttrs,\n preserveEmptyRows: experimental.preserveEmptyRows,\n placeholderOptions: wysiwygConfig.placeholderOptions,\n mdBreaks: md.breaks,\n fileUploadHandler: handlers.uploadFile,\n needToSetDimensionsForUploadedImages:\n experimental.needToSetDimensionsForUploadedImages,\n enableNewImageSizeCalculation: experimental.enableNewImageSizeCalculation,\n });\n {\n const extraExtensions = wysiwygConfig.extensions;\n if (extraExtensions) {\n builder.use(extraExtensions, props.wysiwygConfig?.extensionOptions);\n }\n }\n };\n\n return new EditorImpl({\n ...props,\n logger,\n preset,\n renderStorage,\n directiveSyntax,\n pmTransformers,\n md,\n initial,\n handlers,\n experimental,\n markupConfig,\n wysiwygConfig: {\n ...wysiwygConfig,\n extensions,\n },\n });\n }, deps);\n\n useLayoutEffect(() => {\n function onToolbarAction({editorMode, id}: {editorMode: MarkdownEditorMode; id: string}) {\n globalLogger.action({mode: editorMode, source: 'toolbar', action: id});\n editor.logger.action({mode: editorMode, source: 'toolbar', action: id});\n }\n\n editor.on('toolbar-action', onToolbarAction);\n return () => {\n editor.off('toolbar-action', onToolbarAction);\n editor.destroy();\n };\n }, [editor]);\n return editor;\n}\n"]}
|
|
@@ -20,6 +20,7 @@ export type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions &
|
|
|
20
20
|
needToSetDimensionsForUploadedImages?: boolean;
|
|
21
21
|
enableNewImageSizeCalculation?: boolean;
|
|
22
22
|
directiveSyntax: DirectiveSyntaxContext;
|
|
23
|
+
disableMdAttrs?: boolean;
|
|
23
24
|
};
|
|
24
25
|
declare global {
|
|
25
26
|
namespace WysiwygEditor {
|
|
@@ -94,6 +94,7 @@ const BundlePreset = (builder, opts) => {
|
|
|
94
94
|
};
|
|
95
95
|
const yfmOptions = {
|
|
96
96
|
...defaultOptions,
|
|
97
|
+
yfmConfigs: { disableAttrs: opts.disableMdAttrs, ...opts.yfmConfigs },
|
|
97
98
|
selectionContext: { config: wysiwyg_1.wSelectionMenuConfigByPreset.yfm, ...opts.selectionContext },
|
|
98
99
|
commandMenu: { actions: wysiwyg_1.wCommandMenuConfigByPreset.yfm, ...opts.commandMenu },
|
|
99
100
|
underline: { underlineKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Underline), ...opts.underline },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wysiwyg-preset.js","sourceRoot":"../../../src","sources":["bundle/wysiwyg-preset.ts"],"names":[],"mappings":";;;AAGA,8DAAkF;AAClF,uFAGiD;AACjD,kDAA0E;AAC1E,8DAA4D;AAC5D,yDAAqF;AACrF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G;YAAE,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,mCAAgB,EAAE;QAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,cAAc;KACjB,CAAC,CAAC;AACP,CAAC,CAAC;AAnNW,QAAA,YAAY,gBAmNvB","sourcesContent":["import type {Node} from 'prosemirror-model';\n\nimport type {ExtensionAuto} from '../core';\nimport {BehaviorPreset, type BehaviorPresetOptions} from '../extensions/behavior';\nimport {\n EditorModeKeymap,\n type EditorModeKeymapOptions,\n} from '../extensions/behavior/EditorModeKeymap';\nimport {BaseNode, YfmHeadingAttr, YfmNoteNode} from '../extensions/specs';\nimport {i18n as i18nPlaceholder} from '../i18n/placeholder';\nimport {CommonMarkPreset, type CommonMarkPresetOptions} from '../presets/commonmark';\nimport {DefaultPreset, type DefaultPresetOptions} from '../presets/default';\nimport {FullPreset, type FullPresetOptions} from '../presets/full';\nimport {YfmPreset, type YfmPresetOptions} from '../presets/yfm';\nimport {ZeroPreset, type ZeroPresetOptions} from '../presets/zero';\nimport {Action as A, formatter as f} from '../shortcuts';\nimport type {DirectiveSyntaxContext} from '../utils/directive';\nimport type {FileUploadHandler} from '../utils/upload';\n\nimport {wCommandMenuConfigByPreset, wSelectionMenuConfigByPreset} from './config/wysiwyg';\nimport {emojiDefs} from './emoji';\nimport type {MarkdownEditorPreset, WysiwygPlaceholderOptions} from './types';\n\nconst DEFAULT_IGNORED_KEYS = ['Tab', 'Shift-Tab'] as const;\n\nexport type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;\n\nexport type BundlePresetOptions = ExtensionsOptions &\n EditorModeKeymapOptions & {\n preset: MarkdownEditorPreset;\n mdBreaks?: boolean;\n preserveEmptyRows?: boolean;\n fileUploadHandler?: FileUploadHandler;\n placeholderOptions?: WysiwygPlaceholderOptions;\n /**\n * If we need to set dimensions for uploaded images\n *\n * @default false\n */\n needToSetDimensionsForUploadedImages?: boolean;\n enableNewImageSizeCalculation?: boolean;\n directiveSyntax: DirectiveSyntaxContext;\n };\n\ndeclare global {\n namespace WysiwygEditor {\n interface Context {\n directiveSyntax: DirectiveSyntaxContext;\n }\n }\n}\n\nexport const BundlePreset: ExtensionAuto<BundlePresetOptions> = (builder, opts) => {\n builder.context.set('directiveSyntax', opts.directiveSyntax);\n\n const dropCursor: NonNullable<BundlePresetOptions['cursor']>['dropOptions'] = {\n color: 'var(--g-color-line-brand)',\n width: 2,\n };\n\n const zeroOptions: BehaviorPresetOptions & ZeroPresetOptions = {\n ...opts,\n baseStyles: {\n attributes: {\n // for disable setting attrs inside pm-view from floating-ui from uikit\n // see https://github.com/floating-ui/floating-ui/discussions/3213\n // and https://github.com/floating-ui/floating-ui/pull/3202\n 'aria-live': '',\n ...opts.baseStyles?.attributes,\n },\n },\n cursor: {dropOptions: dropCursor},\n clipboard: {pasteFileHandler: opts.fileUploadHandler, ...opts.clipboard},\n selectionContext: {config: wSelectionMenuConfigByPreset.zero, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.zero, ...opts.commandMenu},\n history: {undoKey: f.toPM(A.Undo), redoKey: f.toPM(A.Redo), ...opts.history},\n baseSchema: {\n paragraphKey: f.toPM(A.Text),\n paragraphPlaceholder: (node: Node, parent?: Node | null) => {\n const {value, behavior} = opts.placeholderOptions || {};\n\n const emptyEntries = {\n 'empty-row': !node.text,\n 'empty-row-top-level': !node.text && parent?.type.name === BaseNode.Doc,\n 'empty-doc':\n !node.text && parent?.type.name === BaseNode.Doc && parent.childCount === 1,\n };\n\n const showPlaceholder = emptyEntries[behavior || 'empty-doc'];\n\n if (!showPlaceholder) return null;\n\n return typeof value === 'function'\n ? value()\n : value ?? i18nPlaceholder('doc_empty');\n },\n preserveEmptyRows: opts.preserveEmptyRows,\n ...opts.baseSchema,\n },\n };\n const commonMarkOptions: BehaviorPresetOptions & CommonMarkPresetOptions = {\n ...zeroOptions,\n selectionContext: {\n config: wSelectionMenuConfigByPreset.commonmark,\n ...opts.selectionContext,\n },\n commandMenu: {actions: wCommandMenuConfigByPreset.commonmark, ...opts.commandMenu},\n breaks: {\n preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') as 'soft' | 'hard',\n ...opts.breaks,\n },\n bold: {boldKey: f.toPM(A.Bold), ...opts.bold},\n italic: {italicKey: f.toPM(A.Italic), ...opts.italic},\n code: {codeKey: f.toPM(A.Code), ...opts.code},\n codeBlock: {\n codeBlockKey: f.toPM(A.CodeBlock),\n ...opts.codeBlock,\n },\n blockquote: {qouteKey: f.toPM(A.Quote), ...opts.blockquote},\n link: {linkKey: f.toPM(A.Link), ...opts.link},\n lists: {\n ulKey: f.toPM(A.BulletList),\n olKey: f.toPM(A.OrderedList),\n ulInputRules: {plus: false},\n ...opts.lists,\n },\n image: {\n parseInsertedUrlAsImage: opts.imgSize?.parseInsertedUrlAsImage,\n },\n };\n const defaultOptions: BehaviorPresetOptions & DefaultPresetOptions = {\n ...commonMarkOptions,\n selectionContext: {config: wSelectionMenuConfigByPreset.default, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.default, ...opts.commandMenu},\n strike: {strikeKey: f.toPM(A.Strike), ...opts.strike},\n };\n const yfmOptions: BehaviorPresetOptions & YfmPresetOptions = {\n ...defaultOptions,\n selectionContext: {config: wSelectionMenuConfigByPreset.yfm, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.yfm, ...opts.commandMenu},\n underline: {underlineKey: f.toPM(A.Underline), ...opts.underline},\n imgSize: {\n imageUploadHandler: opts.fileUploadHandler,\n needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages,\n enableNewImageSizeCalculation: opts.enableNewImageSizeCalculation,\n ...opts.imgSize,\n },\n checkbox: {checkboxLabelPlaceholder: () => i18nPlaceholder('checkbox'), ...opts.checkbox},\n deflist: {\n deflistTermPlaceholder: () => i18nPlaceholder('deflist_term'),\n deflistDescPlaceholder: () => i18nPlaceholder('deflist_desc'),\n },\n yfmCut: {\n yfmCutKey: f.toPM(A.Cut),\n yfmCutTitlePlaceholder: () => i18nPlaceholder('cut_title'),\n yfmCutContentPlaceholder: () => i18nPlaceholder('cut_content'),\n ...opts.yfmCut,\n },\n yfmNote: {\n yfmNoteKey: f.toPM(A.Note),\n yfmNoteTitlePlaceholder: () => i18nPlaceholder('note_title'),\n ...opts.yfmNote,\n },\n yfmTable: {yfmTableCellPlaceholder: () => i18nPlaceholder('table_cell'), ...opts.yfmTable},\n yfmFile: {\n fileUploadHandler: opts.fileUploadHandler,\n needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages,\n ...opts.yfmFile,\n },\n yfmHeading: {\n h1Key: f.toPM(A.Heading1),\n h2Key: f.toPM(A.Heading2),\n h3Key: f.toPM(A.Heading3),\n h4Key: f.toPM(A.Heading4),\n h5Key: f.toPM(A.Heading5),\n h6Key: f.toPM(A.Heading6),\n headingPlaceholder: (node: Node) =>\n `${i18nPlaceholder('heading')} ${node.attrs[YfmHeadingAttr.Level]}`, // todo: remove attrs import\n ...opts.yfmHeading,\n },\n placeholder: {\n [YfmNoteNode.NoteContent]: () => i18nPlaceholder('note_content'),\n },\n };\n const fullOptions: BehaviorPresetOptions & FullPresetOptions = {\n ...yfmOptions,\n selectionContext: {config: wSelectionMenuConfigByPreset.full, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.full, ...opts.commandMenu},\n emoji: {defs: emojiDefs, ...opts.emoji},\n };\n\n const zeroIgnoreActions = [A.Undo, A.Redo];\n const commonMarkIgnoreActions = zeroIgnoreActions.concat(\n A.Bold,\n A.Italic,\n A.Code,\n A.Link,\n\n A.Text,\n A.Heading1,\n A.Heading2,\n A.Heading3,\n A.Heading4,\n A.Heading5,\n A.Heading6,\n\n A.BulletList,\n A.OrderedList,\n\n A.Quote,\n A.CodeBlock,\n );\n const defaultIgnoreActions = commonMarkIgnoreActions.concat(A.Strike);\n const yfmIgnoreActions = defaultIgnoreActions.concat(\n A.Underline,\n\n A.Note,\n A.Cut,\n );\n const fullIgnoreActions = yfmIgnoreActions.concat();\n\n let ignoreActions;\n\n switch (opts.preset) {\n case 'zero': {\n ignoreActions = zeroIgnoreActions;\n builder.use(BehaviorPreset, zeroOptions).use(ZeroPreset, zeroOptions);\n break;\n }\n case 'commonmark': {\n ignoreActions = commonMarkIgnoreActions;\n builder.use(BehaviorPreset, commonMarkOptions).use(CommonMarkPreset, commonMarkOptions);\n break;\n }\n case 'default': {\n ignoreActions = defaultIgnoreActions;\n builder.use(BehaviorPreset, defaultOptions).use(DefaultPreset, defaultOptions);\n break;\n }\n case 'yfm': {\n ignoreActions = yfmIgnoreActions;\n builder.use(BehaviorPreset, yfmOptions).use(YfmPreset, yfmOptions);\n break;\n }\n default: {\n ignoreActions = fullIgnoreActions;\n builder.use(BehaviorPreset, fullOptions).use(FullPreset, fullOptions);\n break;\n }\n }\n\n const ignoreKeysList = opts.ignoreKeysList?.slice() ?? [];\n ignoreKeysList.push(...DEFAULT_IGNORED_KEYS);\n for (const action of ignoreActions) {\n const key = f.toPM(action);\n if (key) ignoreKeysList.push(key);\n }\n\n builder.use(EditorModeKeymap, {\n onSubmit: opts.onSubmit,\n onCancel: opts.onCancel,\n ignoreKeysList,\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"wysiwyg-preset.js","sourceRoot":"../../../src","sources":["bundle/wysiwyg-preset.ts"],"names":[],"mappings":";;;AAGA,8DAAkF;AAClF,uFAGiD;AACjD,kDAA0E;AAC1E,8DAA4D;AAC5D,yDAAqF;AACrF,mDAA4E;AAC5E,6CAAmE;AACnE,2CAAgE;AAChE,6CAAmE;AACnE,qDAAyD;AAIzD,iDAA0F;AAC1F,sCAAkC;AAGlC,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,WAAW,CAAU,CAAC;AA+BpD,MAAM,YAAY,GAAuC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IA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AAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,cAAc;KACjB,CAAC,CAAC;AACP,CAAC,CAAC;AApNW,QAAA,YAAY,gBAoNvB","sourcesContent":["import type {Node} from 'prosemirror-model';\n\nimport type {ExtensionAuto} from '../core';\nimport {BehaviorPreset, type BehaviorPresetOptions} from '../extensions/behavior';\nimport {\n EditorModeKeymap,\n type EditorModeKeymapOptions,\n} from '../extensions/behavior/EditorModeKeymap';\nimport {BaseNode, YfmHeadingAttr, YfmNoteNode} from '../extensions/specs';\nimport {i18n as i18nPlaceholder} from '../i18n/placeholder';\nimport {CommonMarkPreset, type CommonMarkPresetOptions} from '../presets/commonmark';\nimport {DefaultPreset, type DefaultPresetOptions} from '../presets/default';\nimport {FullPreset, type FullPresetOptions} from '../presets/full';\nimport {YfmPreset, type YfmPresetOptions} from '../presets/yfm';\nimport {ZeroPreset, type ZeroPresetOptions} from '../presets/zero';\nimport {Action as A, formatter as f} from '../shortcuts';\nimport type {DirectiveSyntaxContext} from '../utils/directive';\nimport type {FileUploadHandler} from '../utils/upload';\n\nimport {wCommandMenuConfigByPreset, wSelectionMenuConfigByPreset} from './config/wysiwyg';\nimport {emojiDefs} from './emoji';\nimport type {MarkdownEditorPreset, WysiwygPlaceholderOptions} from './types';\n\nconst DEFAULT_IGNORED_KEYS = ['Tab', 'Shift-Tab'] as const;\n\nexport type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;\n\nexport type BundlePresetOptions = ExtensionsOptions &\n EditorModeKeymapOptions & {\n preset: MarkdownEditorPreset;\n mdBreaks?: boolean;\n preserveEmptyRows?: boolean;\n fileUploadHandler?: FileUploadHandler;\n placeholderOptions?: WysiwygPlaceholderOptions;\n /**\n * If we need to set dimensions for uploaded images\n *\n * @default false\n */\n needToSetDimensionsForUploadedImages?: boolean;\n enableNewImageSizeCalculation?: boolean;\n directiveSyntax: DirectiveSyntaxContext;\n // MAJOR: remove markdown-it-attrs\n disableMdAttrs?: boolean;\n };\n\ndeclare global {\n namespace WysiwygEditor {\n interface Context {\n directiveSyntax: DirectiveSyntaxContext;\n }\n }\n}\n\nexport const BundlePreset: ExtensionAuto<BundlePresetOptions> = (builder, opts) => {\n builder.context.set('directiveSyntax', opts.directiveSyntax);\n\n const dropCursor: NonNullable<BundlePresetOptions['cursor']>['dropOptions'] = {\n color: 'var(--g-color-line-brand)',\n width: 2,\n };\n\n const zeroOptions: BehaviorPresetOptions & ZeroPresetOptions = {\n ...opts,\n baseStyles: {\n attributes: {\n // for disable setting attrs inside pm-view from floating-ui from uikit\n // see https://github.com/floating-ui/floating-ui/discussions/3213\n // and https://github.com/floating-ui/floating-ui/pull/3202\n 'aria-live': '',\n ...opts.baseStyles?.attributes,\n },\n },\n cursor: {dropOptions: dropCursor},\n clipboard: {pasteFileHandler: opts.fileUploadHandler, ...opts.clipboard},\n selectionContext: {config: wSelectionMenuConfigByPreset.zero, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.zero, ...opts.commandMenu},\n history: {undoKey: f.toPM(A.Undo), redoKey: f.toPM(A.Redo), ...opts.history},\n baseSchema: {\n paragraphKey: f.toPM(A.Text),\n paragraphPlaceholder: (node: Node, parent?: Node | null) => {\n const {value, behavior} = opts.placeholderOptions || {};\n\n const emptyEntries = {\n 'empty-row': !node.text,\n 'empty-row-top-level': !node.text && parent?.type.name === BaseNode.Doc,\n 'empty-doc':\n !node.text && parent?.type.name === BaseNode.Doc && parent.childCount === 1,\n };\n\n const showPlaceholder = emptyEntries[behavior || 'empty-doc'];\n\n if (!showPlaceholder) return null;\n\n return typeof value === 'function'\n ? value()\n : value ?? i18nPlaceholder('doc_empty');\n },\n preserveEmptyRows: opts.preserveEmptyRows,\n ...opts.baseSchema,\n },\n };\n const commonMarkOptions: BehaviorPresetOptions & CommonMarkPresetOptions = {\n ...zeroOptions,\n selectionContext: {\n config: wSelectionMenuConfigByPreset.commonmark,\n ...opts.selectionContext,\n },\n commandMenu: {actions: wCommandMenuConfigByPreset.commonmark, ...opts.commandMenu},\n breaks: {\n preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') as 'soft' | 'hard',\n ...opts.breaks,\n },\n bold: {boldKey: f.toPM(A.Bold), ...opts.bold},\n italic: {italicKey: f.toPM(A.Italic), ...opts.italic},\n code: {codeKey: f.toPM(A.Code), ...opts.code},\n codeBlock: {\n codeBlockKey: f.toPM(A.CodeBlock),\n ...opts.codeBlock,\n },\n blockquote: {qouteKey: f.toPM(A.Quote), ...opts.blockquote},\n link: {linkKey: f.toPM(A.Link), ...opts.link},\n lists: {\n ulKey: f.toPM(A.BulletList),\n olKey: f.toPM(A.OrderedList),\n ulInputRules: {plus: false},\n ...opts.lists,\n },\n image: {\n parseInsertedUrlAsImage: opts.imgSize?.parseInsertedUrlAsImage,\n },\n };\n const defaultOptions: BehaviorPresetOptions & DefaultPresetOptions = {\n ...commonMarkOptions,\n selectionContext: {config: wSelectionMenuConfigByPreset.default, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.default, ...opts.commandMenu},\n strike: {strikeKey: f.toPM(A.Strike), ...opts.strike},\n };\n const yfmOptions: BehaviorPresetOptions & YfmPresetOptions = {\n ...defaultOptions,\n yfmConfigs: {disableAttrs: opts.disableMdAttrs, ...opts.yfmConfigs},\n selectionContext: {config: wSelectionMenuConfigByPreset.yfm, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.yfm, ...opts.commandMenu},\n underline: {underlineKey: f.toPM(A.Underline), ...opts.underline},\n imgSize: {\n imageUploadHandler: opts.fileUploadHandler,\n needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages,\n enableNewImageSizeCalculation: opts.enableNewImageSizeCalculation,\n ...opts.imgSize,\n },\n checkbox: {checkboxLabelPlaceholder: () => i18nPlaceholder('checkbox'), ...opts.checkbox},\n deflist: {\n deflistTermPlaceholder: () => i18nPlaceholder('deflist_term'),\n deflistDescPlaceholder: () => i18nPlaceholder('deflist_desc'),\n },\n yfmCut: {\n yfmCutKey: f.toPM(A.Cut),\n yfmCutTitlePlaceholder: () => i18nPlaceholder('cut_title'),\n yfmCutContentPlaceholder: () => i18nPlaceholder('cut_content'),\n ...opts.yfmCut,\n },\n yfmNote: {\n yfmNoteKey: f.toPM(A.Note),\n yfmNoteTitlePlaceholder: () => i18nPlaceholder('note_title'),\n ...opts.yfmNote,\n },\n yfmTable: {yfmTableCellPlaceholder: () => i18nPlaceholder('table_cell'), ...opts.yfmTable},\n yfmFile: {\n fileUploadHandler: opts.fileUploadHandler,\n needToSetDimensionsForUploadedImages: opts.needToSetDimensionsForUploadedImages,\n ...opts.yfmFile,\n },\n yfmHeading: {\n h1Key: f.toPM(A.Heading1),\n h2Key: f.toPM(A.Heading2),\n h3Key: f.toPM(A.Heading3),\n h4Key: f.toPM(A.Heading4),\n h5Key: f.toPM(A.Heading5),\n h6Key: f.toPM(A.Heading6),\n headingPlaceholder: (node: Node) =>\n `${i18nPlaceholder('heading')} ${node.attrs[YfmHeadingAttr.Level]}`, // todo: remove attrs import\n ...opts.yfmHeading,\n },\n placeholder: {\n [YfmNoteNode.NoteContent]: () => i18nPlaceholder('note_content'),\n },\n };\n const fullOptions: BehaviorPresetOptions & FullPresetOptions = {\n ...yfmOptions,\n selectionContext: {config: wSelectionMenuConfigByPreset.full, ...opts.selectionContext},\n commandMenu: {actions: wCommandMenuConfigByPreset.full, ...opts.commandMenu},\n emoji: {defs: emojiDefs, ...opts.emoji},\n };\n\n const zeroIgnoreActions = [A.Undo, A.Redo];\n const commonMarkIgnoreActions = zeroIgnoreActions.concat(\n A.Bold,\n A.Italic,\n A.Code,\n A.Link,\n\n A.Text,\n A.Heading1,\n A.Heading2,\n A.Heading3,\n A.Heading4,\n A.Heading5,\n A.Heading6,\n\n A.BulletList,\n A.OrderedList,\n\n A.Quote,\n A.CodeBlock,\n );\n const defaultIgnoreActions = commonMarkIgnoreActions.concat(A.Strike);\n const yfmIgnoreActions = defaultIgnoreActions.concat(\n A.Underline,\n\n A.Note,\n A.Cut,\n );\n const fullIgnoreActions = yfmIgnoreActions.concat();\n\n let ignoreActions;\n\n switch (opts.preset) {\n case 'zero': {\n ignoreActions = zeroIgnoreActions;\n builder.use(BehaviorPreset, zeroOptions).use(ZeroPreset, zeroOptions);\n break;\n }\n case 'commonmark': {\n ignoreActions = commonMarkIgnoreActions;\n builder.use(BehaviorPreset, commonMarkOptions).use(CommonMarkPreset, commonMarkOptions);\n break;\n }\n case 'default': {\n ignoreActions = defaultIgnoreActions;\n builder.use(BehaviorPreset, defaultOptions).use(DefaultPreset, defaultOptions);\n break;\n }\n case 'yfm': {\n ignoreActions = yfmIgnoreActions;\n builder.use(BehaviorPreset, yfmOptions).use(YfmPreset, yfmOptions);\n break;\n }\n default: {\n ignoreActions = fullIgnoreActions;\n builder.use(BehaviorPreset, fullOptions).use(FullPreset, fullOptions);\n break;\n }\n }\n\n const ignoreKeysList = opts.ignoreKeysList?.slice() ?? [];\n ignoreKeysList.push(...DEFAULT_IGNORED_KEYS);\n for (const action of ignoreActions) {\n const key = f.toPM(action);\n if (key) ignoreKeysList.push(key);\n }\n\n builder.use(EditorModeKeymap, {\n onSubmit: opts.onSubmit,\n onCancel: opts.onCancel,\n ignoreKeysList,\n });\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addQuoteLinkPlaceholder = void 0;
|
|
4
|
+
const descriptor_1 = require("./descriptor.js");
|
|
5
|
+
const addQuoteLinkPlaceholder = (deps) => (state, dispatch) => {
|
|
6
|
+
dispatch?.((0, descriptor_1.addPlaceholder)(state.tr, deps).scrollIntoView());
|
|
7
|
+
return true;
|
|
8
|
+
};
|
|
9
|
+
exports.addQuoteLinkPlaceholder = addQuoteLinkPlaceholder;
|
|
10
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/QuoteLink/PlaceholderWidget/commands.ts"],"names":[],"mappings":";;;AAIA,gDAA4C;AAErC,MAAM,uBAAuB,GAChC,CAAC,IAAmB,EAAW,EAAE,CACjC,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IAChB,QAAQ,EAAE,CAAC,IAAA,2BAAc,EAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AALO,QAAA,uBAAuB,2BAK9B","sourcesContent":["import type {Command} from 'prosemirror-state';\n\nimport type {ExtensionDeps} from '#core';\n\nimport {addPlaceholder} from './descriptor';\n\nexport const addQuoteLinkPlaceholder =\n (deps: ExtensionDeps): Command =>\n (state, dispatch) => {\n dispatch?.(addPlaceholder(state.tr, deps).scrollIntoView());\n return true;\n };\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { Transaction } from 'prosemirror-state';
|
|
3
|
+
import type { EditorView } from 'prosemirror-view';
|
|
4
|
+
import type { ExtensionDeps } from "../../../../core/index.js";
|
|
5
|
+
import { ReactWidgetDescriptor } from "../../../index.js";
|
|
6
|
+
import { type LinkPlaceholderWidgetProps } from "../../../markdown/Link/PlaceholderWidget/widget.js";
|
|
7
|
+
export declare class QuoteLinkWidgetDescriptor extends ReactWidgetDescriptor {
|
|
8
|
+
#private;
|
|
9
|
+
private normalizeUrl;
|
|
10
|
+
constructor(initPos: number, deps: ExtensionDeps);
|
|
11
|
+
getDomElem(): HTMLElement;
|
|
12
|
+
renderReactElement(view: EditorView, getPos: () => number): React.ReactElement;
|
|
13
|
+
onCancel: LinkPlaceholderWidgetProps['onCancel'];
|
|
14
|
+
onSubmit: LinkPlaceholderWidgetProps['onSubmit'];
|
|
15
|
+
}
|
|
16
|
+
export declare const addPlaceholder: (tr: Transaction, deps: ExtensionDeps) => Transaction;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPlaceholder = exports.QuoteLinkWidgetDescriptor = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
// @ts-ignore // TODO: fix cjs build
|
|
7
|
+
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
8
|
+
const extensions_1 = require("../../../index.js");
|
|
9
|
+
const QuoteLinkSpecs_1 = require("../QuoteLinkSpecs/index.js");
|
|
10
|
+
const widget_1 = require("../../../markdown/Link/PlaceholderWidget/widget.js");
|
|
11
|
+
const utils_1 = require("../../../../utils/index.js");
|
|
12
|
+
class QuoteLinkWidgetDescriptor extends extensions_1.ReactWidgetDescriptor {
|
|
13
|
+
#domElem;
|
|
14
|
+
#view;
|
|
15
|
+
#getPos;
|
|
16
|
+
#schema;
|
|
17
|
+
normalizeUrl;
|
|
18
|
+
constructor(initPos, deps) {
|
|
19
|
+
super(initPos, 'quoteLink');
|
|
20
|
+
this.#domElem = document.createElement('span');
|
|
21
|
+
this.#schema = deps.schema;
|
|
22
|
+
this.normalizeUrl = (0, extensions_1.normalizeUrlFactory)(deps);
|
|
23
|
+
}
|
|
24
|
+
getDomElem() {
|
|
25
|
+
return this.#domElem;
|
|
26
|
+
}
|
|
27
|
+
renderReactElement(view, getPos) {
|
|
28
|
+
this.#view = view;
|
|
29
|
+
this.#getPos = getPos;
|
|
30
|
+
return (0, jsx_runtime_1.jsx)(widget_1.LinkPlaceholderWidget, { onCancel: this.onCancel, onSubmit: this.onSubmit });
|
|
31
|
+
}
|
|
32
|
+
onCancel = () => {
|
|
33
|
+
if (!this.#view)
|
|
34
|
+
return;
|
|
35
|
+
this.#view.dispatch((0, extensions_1.removeDecoration)(this.#view.state.tr, this.id));
|
|
36
|
+
this.#view.focus();
|
|
37
|
+
};
|
|
38
|
+
onSubmit = (params) => {
|
|
39
|
+
const normalizeResult = this.normalizeUrl(params.url);
|
|
40
|
+
if (!normalizeResult || !this.#view || !this.#getPos)
|
|
41
|
+
return;
|
|
42
|
+
let tr = this.#view.state.tr;
|
|
43
|
+
const { url } = normalizeResult;
|
|
44
|
+
const text = params.text.trim() || normalizeResult.text;
|
|
45
|
+
const from = this.#getPos();
|
|
46
|
+
const isAllSelected = from === 1 && (!(0, utils_1.isTextSelection)(tr.selection) || !tr.selection.$cursor);
|
|
47
|
+
const currentNodeWithPos = isAllSelected
|
|
48
|
+
? (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(this.#view.state.doc.resolve(4), (0, QuoteLinkSpecs_1.quoteLinkType)(this.#view.state.schema))
|
|
49
|
+
: (0, prosemirror_utils_1.findParentNodeOfType)((0, QuoteLinkSpecs_1.quoteLinkType)(this.#view.state.schema))(this.#view.state.selection);
|
|
50
|
+
if (currentNodeWithPos) {
|
|
51
|
+
let content = currentNodeWithPos.node.content;
|
|
52
|
+
let contentSize = currentNodeWithPos.node.nodeSize - 4;
|
|
53
|
+
if (currentNodeWithPos.node.nodeSize <= 4 && text) {
|
|
54
|
+
content = (0, extensions_1.pType)(this.#view.state.schema).create(null, this.#schema?.text(text));
|
|
55
|
+
contentSize = text.length;
|
|
56
|
+
}
|
|
57
|
+
tr = tr.replaceWith(currentNodeWithPos.pos, currentNodeWithPos.pos + currentNodeWithPos.node.nodeSize, (0, QuoteLinkSpecs_1.quoteLinkType)(this.#view.state.schema).create({
|
|
58
|
+
[QuoteLinkSpecs_1.QuoteLinkAttr.Cite]: url,
|
|
59
|
+
[QuoteLinkSpecs_1.QuoteLinkAttr.DataContent]: text,
|
|
60
|
+
}, content));
|
|
61
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, from + contentSize));
|
|
62
|
+
}
|
|
63
|
+
this.#view.dispatch(tr);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.QuoteLinkWidgetDescriptor = QuoteLinkWidgetDescriptor;
|
|
67
|
+
const addPlaceholder = (tr, deps) => {
|
|
68
|
+
const isAllSelected = tr.selection.from === 0 && (!(0, utils_1.isTextSelection)(tr.selection) || !tr.selection.$cursor);
|
|
69
|
+
return new QuoteLinkWidgetDescriptor(tr.selection.from + (isAllSelected ? 1 : 0), deps).applyTo(tr);
|
|
70
|
+
};
|
|
71
|
+
exports.addPlaceholder = addPlaceholder;
|
|
72
|
+
//# sourceMappingURL=descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/QuoteLink/PlaceholderWidget/descriptor.tsx"],"names":[],"mappings":";;;;AAIA,yDAAgD;AAChD,oCAAoC;AACpC,yDAAyF;AAIzF,kDAAmG;AACnG,+DAAgG;AAChG,+EAG+D;AAC/D,sDAA0C;AAE1C,MAAa,yBAA0B,SAAQ,kCAAqB;IAChE,QAAQ,CAAC;IACT,KAAK,CAAc;IACnB,OAAO,CAAgB;IACvB,OAAO,CAA2B;IAE1B,YAAY,CAAC;IAErB,YAAY,OAAe,EAAE,IAAmB;QAC5C,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAA,gCAAmB,EAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,UAAU;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,kBAAkB,CAAC,IAAgB,EAAE,MAAoB;QACrD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,OAAO,uBAAC,8BAAqB,IAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,E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,cAAc,GAAG,CAAC,EAAe,EAAE,IAAmB,EAAE,EAAE;IACnE,MAAM,aAAa,GACf,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAA,uBAAe,EAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzF,OAAO,IAAI,yBAAyB,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,OAAO,CAC3F,EAAE,CACL,CAAC;AACN,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB","sourcesContent":["import type React from 'react';\n\nimport type {Fragment, Node} from 'prosemirror-model';\nimport type {Transaction} from 'prosemirror-state';\nimport {TextSelection} from 'prosemirror-state';\n// @ts-ignore // TODO: fix cjs build\nimport {findParentNodeOfType, findParentNodeOfTypeClosestToPos} from 'prosemirror-utils';\nimport type {EditorView} from 'prosemirror-view';\n\nimport type {ExtensionDeps} from '#core';\nimport {ReactWidgetDescriptor, normalizeUrlFactory, pType, removeDecoration} from 'src/extensions';\nimport {QuoteLinkAttr, quoteLinkType} from 'src/extensions/additional/QuoteLink/QuoteLinkSpecs';\nimport {\n LinkPlaceholderWidget,\n type LinkPlaceholderWidgetProps,\n} from 'src/extensions/markdown/Link/PlaceholderWidget/widget';\nimport {isTextSelection} from 'src/utils';\n\nexport class QuoteLinkWidgetDescriptor extends ReactWidgetDescriptor {\n #domElem;\n #view?: EditorView;\n #getPos?: () => number;\n #schema?: ExtensionDeps['schema'];\n\n private normalizeUrl;\n\n constructor(initPos: number, deps: ExtensionDeps) {\n super(initPos, 'quoteLink');\n this.#domElem = document.createElement('span');\n this.#schema = deps.schema;\n this.normalizeUrl = normalizeUrlFactory(deps);\n }\n\n getDomElem(): HTMLElement {\n return this.#domElem;\n }\n\n renderReactElement(view: EditorView, getPos: () => number): React.ReactElement {\n this.#view = view;\n this.#getPos = getPos;\n return <LinkPlaceholderWidget onCancel={this.onCancel} onSubmit={this.onSubmit} />;\n }\n\n onCancel: LinkPlaceholderWidgetProps['onCancel'] = () => {\n if (!this.#view) return;\n\n this.#view.dispatch(removeDecoration(this.#view.state.tr, this.id));\n this.#view.focus();\n };\n\n onSubmit: LinkPlaceholderWidgetProps['onSubmit'] = (params) => {\n const normalizeResult = this.normalizeUrl(params.url);\n if (!normalizeResult || !this.#view || !this.#getPos) return;\n\n let tr = this.#view.state.tr;\n\n const {url} = normalizeResult;\n const text = params.text.trim() || normalizeResult.text;\n\n const from = this.#getPos();\n const isAllSelected =\n from === 1 && (!isTextSelection(tr.selection) || !tr.selection.$cursor);\n\n const currentNodeWithPos = isAllSelected\n ? findParentNodeOfTypeClosestToPos(\n this.#view.state.doc.resolve(4),\n quoteLinkType(this.#view.state.schema),\n )\n : findParentNodeOfType(quoteLinkType(this.#view.state.schema))(\n this.#view.state.selection,\n );\n\n if (currentNodeWithPos) {\n let content: Fragment | Node | undefined = currentNodeWithPos.node.content;\n let contentSize = currentNodeWithPos.node.nodeSize - 4;\n\n if (currentNodeWithPos.node.nodeSize <= 4 && text) {\n content = pType(this.#view.state.schema).create(null, this.#schema?.text(text));\n contentSize = text.length;\n }\n\n tr = tr.replaceWith(\n currentNodeWithPos.pos,\n currentNodeWithPos.pos + currentNodeWithPos.node.nodeSize,\n quoteLinkType(this.#view.state.schema).create(\n {\n [QuoteLinkAttr.Cite]: url,\n [QuoteLinkAttr.DataContent]: text,\n },\n content,\n ),\n );\n\n tr.setSelection(TextSelection.create(tr.doc, from + contentSize));\n }\n\n this.#view.dispatch(tr);\n };\n}\n\nexport const addPlaceholder = (tr: Transaction, deps: ExtensionDeps) => {\n const isAllSelected =\n tr.selection.from === 0 && (!isTextSelection(tr.selection) || !tr.selection.$cursor);\n return new QuoteLinkWidgetDescriptor(tr.selection.from + (isAllSelected ? 1 : 0), deps).applyTo(\n tr,\n );\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Node } from 'prosemirror-model';
|
|
2
|
+
import type { ExtensionAuto } from "../../../../core/index.js";
|
|
3
|
+
export declare const quoteLinkNodeName = "yfm_quote-link";
|
|
4
|
+
export declare const quoteLinkType: (schema: import("prosemirror-model").Schema) => import("prosemirror-model").NodeType;
|
|
5
|
+
export declare const isQuoteLinkNode: (node: Node) => boolean;
|
|
6
|
+
export declare enum QuoteLinkAttr {
|
|
7
|
+
Cite = "cite",
|
|
8
|
+
DataContent = "data-content"
|
|
9
|
+
}
|
|
10
|
+
export declare const QuoteLinkSpecs: ExtensionAuto;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuoteLinkSpecs = exports.QuoteLinkAttr = exports.isQuoteLinkNode = exports.quoteLinkType = exports.quoteLinkNodeName = void 0;
|
|
4
|
+
const quote_link_extension_1 = require("@diplodoc/quote-link-extension");
|
|
5
|
+
const utils_1 = require("../../../../utils/index.js");
|
|
6
|
+
const moveLinkToQuoteAttributes_1 = require("./md/moveLinkToQuoteAttributes.js");
|
|
7
|
+
exports.quoteLinkNodeName = 'yfm_quote-link';
|
|
8
|
+
exports.quoteLinkType = (0, utils_1.nodeTypeFactory)(exports.quoteLinkNodeName);
|
|
9
|
+
const isQuoteLinkNode = (node) => node.type.name === exports.quoteLinkNodeName;
|
|
10
|
+
exports.isQuoteLinkNode = isQuoteLinkNode;
|
|
11
|
+
var QuoteLinkAttr;
|
|
12
|
+
(function (QuoteLinkAttr) {
|
|
13
|
+
QuoteLinkAttr["Cite"] = "cite";
|
|
14
|
+
QuoteLinkAttr["DataContent"] = "data-content";
|
|
15
|
+
})(QuoteLinkAttr || (exports.QuoteLinkAttr = QuoteLinkAttr = {}));
|
|
16
|
+
const QuoteLinkSpecs = (builder) => {
|
|
17
|
+
builder
|
|
18
|
+
.configureMd((md) => md
|
|
19
|
+
.use((0, quote_link_extension_1.transform)({
|
|
20
|
+
bundle: false,
|
|
21
|
+
}))
|
|
22
|
+
.use(moveLinkToQuoteAttributes_1.moveLinkToQuoteAttributes))
|
|
23
|
+
.addNode(exports.quoteLinkNodeName, () => ({
|
|
24
|
+
spec: {
|
|
25
|
+
attrs: {
|
|
26
|
+
class: { default: 'yfm-quote-link' },
|
|
27
|
+
[QuoteLinkAttr.Cite]: { default: '' },
|
|
28
|
+
[QuoteLinkAttr.DataContent]: { default: '' },
|
|
29
|
+
},
|
|
30
|
+
content: 'block+',
|
|
31
|
+
group: 'block',
|
|
32
|
+
defining: true,
|
|
33
|
+
parseDOM: [
|
|
34
|
+
{
|
|
35
|
+
tag: '.yfm-quote-link',
|
|
36
|
+
getAttrs(dom) {
|
|
37
|
+
return {
|
|
38
|
+
[QuoteLinkAttr.Cite]: dom.getAttribute(QuoteLinkAttr.Cite),
|
|
39
|
+
[QuoteLinkAttr.DataContent]: dom.getAttribute(QuoteLinkAttr.DataContent),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
priority: builder.Priority.VeryHigh,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
toDOM(node) {
|
|
46
|
+
return ['blockquote', node.attrs, 0];
|
|
47
|
+
},
|
|
48
|
+
selectable: true,
|
|
49
|
+
},
|
|
50
|
+
fromMd: {
|
|
51
|
+
tokenSpec: {
|
|
52
|
+
name: exports.quoteLinkNodeName,
|
|
53
|
+
type: 'block',
|
|
54
|
+
getAttrs: (tok) => ({
|
|
55
|
+
[QuoteLinkAttr.Cite]: tok.attrGet('cite'),
|
|
56
|
+
[QuoteLinkAttr.DataContent]: tok.attrGet('data-content') || null,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
toMd: (state, node) => {
|
|
61
|
+
state.wrapBlock('> ', null, node, () => {
|
|
62
|
+
state.write(`[${node.attrs[QuoteLinkAttr.DataContent]}](${node.attrs[QuoteLinkAttr.Cite]}){data-quotelink=true}`);
|
|
63
|
+
state.write('\n');
|
|
64
|
+
state.write('\n');
|
|
65
|
+
state.renderContent(node);
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
exports.QuoteLinkSpecs = QuoteLinkSpecs;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/additional/QuoteLink/QuoteLinkSpecs/index.ts"],"names":[],"mappings":";;;AAAA,yEAAsE;AAItE,sDAA0C;AAE1C,iFAAyE;AAE5D,QAAA,iBAAiB,GAAG,gBAAgB,CAAC;AACrC,QAAA,aAAa,GAAG,IAAA,uBAAe,EAAC,yBAAiB,CAAC,CAAC;AACzD,MAAM,eAAe,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,yBAAiB,CAAC;AAAvE,QAAA,eAAe,mBAAwD;AAEpF,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,8BAAa,CAAA;IACb,6CAA4B,CAAA;AAChC,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAEM,MAAM,cAAc,GAAkB,CAAC,OAAO,EAAE,EAAE;IACrD,OAAO;SACF,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAChB,EAAE;SACG,GAAG,CACA,IAAA,gCAAS,EAAC;QACN,MAAM,EAAE,KAAK;KAChB,CAAC,CACL;SACA,GAAG,CAAC,qDAAyB,CAAC,CACtC;SACA,OAAO,CAAC,yBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/B,IAAI,EAAE;YACF,KAAK,EAAE;gBACH,KAAK,EAAE,EAAC,OAAO,EAAE,gBAAgB,EAAC;gBAClC,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAC,OAAO,EAAE,EAAE,EAAC;gBACnC,CAAC,aAAa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,CACjC,wBAAwB,CAC3B,CAAC;gBACF,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAClB,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAClB,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC;AAjEW,QAAA,cAAc,kBAiEzB","sourcesContent":["import {transform as quoteLink} from '@diplodoc/quote-link-extension';\nimport type {Node} from 'prosemirror-model';\n\nimport type {ExtensionAuto} from '#core';\nimport {nodeTypeFactory} from 'src/utils';\n\nimport {moveLinkToQuoteAttributes} from './md/moveLinkToQuoteAttributes';\n\nexport const quoteLinkNodeName = 'yfm_quote-link';\nexport const quoteLinkType = nodeTypeFactory(quoteLinkNodeName);\nexport const isQuoteLinkNode = (node: Node) => node.type.name === quoteLinkNodeName;\n\nexport enum QuoteLinkAttr {\n Cite = 'cite',\n DataContent = 'data-content',\n}\n\nexport const QuoteLinkSpecs: ExtensionAuto = (builder) => {\n builder\n .configureMd((md) =>\n md\n .use(\n quoteLink({\n bundle: false,\n }),\n )\n .use(moveLinkToQuoteAttributes),\n )\n .addNode(quoteLinkNodeName, () => ({\n spec: {\n attrs: {\n class: {default: 'yfm-quote-link'},\n [QuoteLinkAttr.Cite]: {default: ''},\n [QuoteLinkAttr.DataContent]: {default: ''},\n },\n content: 'block+',\n group: 'block',\n defining: true,\n parseDOM: [\n {\n tag: '.yfm-quote-link',\n getAttrs(dom) {\n return {\n [QuoteLinkAttr.Cite]: (dom as Element).getAttribute(\n QuoteLinkAttr.Cite,\n ),\n [QuoteLinkAttr.DataContent]: (dom as Element).getAttribute(\n QuoteLinkAttr.DataContent,\n ),\n };\n },\n priority: builder.Priority.VeryHigh,\n },\n ],\n toDOM(node) {\n return ['blockquote', node.attrs, 0];\n },\n selectable: true,\n },\n fromMd: {\n tokenSpec: {\n name: quoteLinkNodeName,\n type: 'block',\n getAttrs: (tok) => ({\n [QuoteLinkAttr.Cite]: tok.attrGet('cite'),\n [QuoteLinkAttr.DataContent]: tok.attrGet('data-content') || null,\n }),\n },\n },\n toMd: (state, node) => {\n state.wrapBlock('> ', null, node, () => {\n state.write(\n `[${node.attrs[QuoteLinkAttr.DataContent]}](${\n node.attrs[QuoteLinkAttr.Cite]\n }){data-quotelink=true}`,\n );\n state.write('\\n');\n state.write('\\n');\n state.renderContent(node);\n });\n },\n }));\n};\n"]}
|
package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moveLinkToQuoteAttributes = void 0;
|
|
4
|
+
const utils_1 = require("./utils.js");
|
|
5
|
+
const __1 = require("../index.js");
|
|
6
|
+
const moveLinkToQuoteAttributes = (md) => {
|
|
7
|
+
md.core.ruler.push('move-link-to-quote-attributes', (state) => {
|
|
8
|
+
const { tokens } = state;
|
|
9
|
+
let i = 0;
|
|
10
|
+
while (i < tokens.length) {
|
|
11
|
+
const token = tokens[i];
|
|
12
|
+
if (token.type === 'yfm_quote-link_open') {
|
|
13
|
+
const inlineToken = tokens[i + 2];
|
|
14
|
+
const linkMatch = (0, utils_1.matchLinkAtInlineStart)(inlineToken);
|
|
15
|
+
if (linkMatch?.openToken.attrIndex('data-quotelink') !== -1 &&
|
|
16
|
+
linkMatch?.closeTokenIndex) {
|
|
17
|
+
token.attrSet(__1.QuoteLinkAttr.Cite, linkMatch?.openToken.attrGet('href') ?? '');
|
|
18
|
+
const content = inlineToken.children
|
|
19
|
+
?.slice(1, linkMatch.closeTokenIndex)
|
|
20
|
+
.reduce((result, item) => result + item.content, '')
|
|
21
|
+
.trim();
|
|
22
|
+
if (content) {
|
|
23
|
+
token.attrSet(__1.QuoteLinkAttr.DataContent, content);
|
|
24
|
+
}
|
|
25
|
+
if (linkMatch.closeTokenIndex === (inlineToken.children?.length ?? 0) - 1) {
|
|
26
|
+
tokens.splice(i + 1, 3);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
inlineToken.children?.splice(0, linkMatch.closeTokenIndex + 1);
|
|
30
|
+
if (inlineToken.children?.every((childToken) => !childToken.content)) {
|
|
31
|
+
tokens.splice(i + 1, 3);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
i++;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
exports.moveLinkToQuoteAttributes = moveLinkToQuoteAttributes;
|
|
41
|
+
//# sourceMappingURL=moveLinkToQuoteAttributes.js.map
|
package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moveLinkToQuoteAttributes.js","sourceRoot":"../../../../../../../src","sources":["extensions/additional/QuoteLink/QuoteLinkSpecs/md/moveLinkToQuoteAttributes.ts"],"names":[],"mappings":";;;AAEA,sCAAmG;AAEnG,mCAAiC;AAE1B,MAAM,yBAAyB,GAAiB,CAAC,EAAE,EAAE,EAAE;IAC1D,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,+BAA+B,EAAE,CAAC,KAAK,EAAE,EAAE;QAC1D,MAAM,EAAC,MAAM,EAAC,GAAG,KAAK,CAAC;QAEvB,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gBACvC,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAClC,MAAM,SAAS,GAAG,IAAA,8B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;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAvCW,QAAA,yBAAyB,6BAuCpC","sourcesContent":["import type {PluginSimple} from 'markdown-it';\n\nimport {matchLinkAtInlineStart} from 'src/extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils';\n\nimport {QuoteLinkAttr} from '..';\n\nexport const moveLinkToQuoteAttributes: PluginSimple = (md) => {\n md.core.ruler.push('move-link-to-quote-attributes', (state) => {\n const {tokens} = state;\n\n let i = 0;\n\n while (i < tokens.length) {\n const token = tokens[i];\n if (token.type === 'yfm_quote-link_open') {\n const inlineToken = tokens[i + 2];\n const linkMatch = matchLinkAtInlineStart(inlineToken);\n\n if (\n linkMatch?.openToken.attrIndex('data-quotelink') !== -1 &&\n linkMatch?.closeTokenIndex\n ) {\n token.attrSet(QuoteLinkAttr.Cite, linkMatch?.openToken.attrGet('href') ?? '');\n const content = inlineToken.children\n ?.slice(1, linkMatch.closeTokenIndex)\n .reduce((result, item) => result + item.content, '')\n .trim();\n if (content) {\n token.attrSet(QuoteLinkAttr.DataContent, content);\n }\n\n if (linkMatch.closeTokenIndex === (inlineToken.children?.length ?? 0) - 1) {\n tokens.splice(i + 1, 3);\n } else {\n inlineToken.children?.splice(0, linkMatch.closeTokenIndex + 1);\n if (inlineToken.children?.every((childToken) => !childToken.content)) {\n tokens.splice(i + 1, 3);\n }\n }\n }\n }\n\n i++;\n }\n });\n};\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchLinkAtInlineStart = matchLinkAtInlineStart;
|
|
4
|
+
function matchLinkAtInlineStart(inlineToken) {
|
|
5
|
+
if (inlineToken.type !== 'inline' || !inlineToken.children?.length) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const { children: tokens } = inlineToken;
|
|
9
|
+
if (tokens[0].type !== 'link_open') {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
13
|
+
const token = tokens[i];
|
|
14
|
+
if (token.type === 'link_close') {
|
|
15
|
+
return {
|
|
16
|
+
openToken: tokens[0],
|
|
17
|
+
closeToken: token,
|
|
18
|
+
closeTokenIndex: i,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"../../../../../../../src","sources":["extensions/additional/QuoteLink/QuoteLinkSpecs/md/utils.ts"],"names":[],"mappings":";;AAEA,wDAsBC;AAtBD,SAAgB,sBAAsB,CAAC,WAAkB;IACrD,IAAI,WAAW,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAC,GAAG,WAAW,CAAC;IACvC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC9B,OAAO;gBACH,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;gBACpB,UAAU,EAAE,KAAK;gBACjB,eAAe,EAAE,CAAC;aACrB,CAAC;QACN,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import type Token from 'markdown-it/lib/token';\n\nexport function matchLinkAtInlineStart(inlineToken: Token) {\n if (inlineToken.type !== 'inline' || !inlineToken.children?.length) {\n return null;\n }\n\n const {children: tokens} = inlineToken;\n if (tokens[0].type !== 'link_open') {\n return null;\n }\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n if (token.type === 'link_close') {\n return {\n openToken: tokens[0],\n closeToken: token,\n closeTokenIndex: i,\n };\n }\n }\n\n return null;\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addQuoteLink = exports.toggleQuote = void 0;
|
|
4
|
+
const prosemirror_commands_1 = require("prosemirror-commands");
|
|
5
|
+
const utils_1 = require("../../../utils/index.js");
|
|
6
|
+
require("../../../types/spec.js");
|
|
7
|
+
const commands_1 = require("./PlaceholderWidget/commands.js");
|
|
8
|
+
const QuoteLinkSpecs_1 = require("./QuoteLinkSpecs/index.js");
|
|
9
|
+
const toggleQuote = (state, dispatch) => {
|
|
10
|
+
const { selection } = state;
|
|
11
|
+
const qType = (0, QuoteLinkSpecs_1.quoteLinkType)(state.schema);
|
|
12
|
+
if (!(0, utils_1.isTextSelection)(selection) || !selection.$cursor)
|
|
13
|
+
return (0, prosemirror_commands_1.wrapIn)(qType)(state, dispatch);
|
|
14
|
+
const { $cursor } = selection;
|
|
15
|
+
let { depth } = $cursor;
|
|
16
|
+
while (depth > 0) {
|
|
17
|
+
const node = $cursor.node(depth);
|
|
18
|
+
const nodeSpec = node.type.spec;
|
|
19
|
+
if (!nodeSpec.complex || nodeSpec.complex === 'root') {
|
|
20
|
+
const targetDepth = depth - 1;
|
|
21
|
+
const range = getBlockRange($cursor, depth);
|
|
22
|
+
let tr = state.tr;
|
|
23
|
+
if ((0, QuoteLinkSpecs_1.isQuoteLinkNode)($cursor.node(targetDepth))) {
|
|
24
|
+
tr = tr.lift(range, targetDepth - 1).scrollIntoView();
|
|
25
|
+
dispatch?.(tr);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
tr = tr.wrap(range, [{ type: qType }]).scrollIntoView();
|
|
29
|
+
dispatch?.(tr);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
depth--;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
exports.toggleQuote = toggleQuote;
|
|
38
|
+
function getBlockRange($pos, depth) {
|
|
39
|
+
const { doc } = $pos;
|
|
40
|
+
const $before = doc.resolve($pos.before(depth));
|
|
41
|
+
const $after = doc.resolve($pos.after(depth));
|
|
42
|
+
return $before.blockRange($after);
|
|
43
|
+
}
|
|
44
|
+
exports.addQuoteLink = commands_1.addQuoteLinkPlaceholder;
|
|
45
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"../../../../../src","sources":["extensions/additional/QuoteLink/commands.ts"],"names":[],"mappings":";;;AAAA,+DAA4C;AAI5C,mDAA0C;AAE1C,kCAA6B;AAE7B,8DAAqE;AACrE,8DAAgE;AAEzD,MAAM,WAAW,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IACpD,MAAM,EAAC,SAAS,EAAC,GAAG,KAAK,CAAC;IAC1B,MAAM,KAAK,GAAG,IAAA,8BAAa,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAA,uBAAe,EAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO;QAAE,OAAO,IAAA,6BAAM,EAAC,KAAK,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7F,MAAM,EAAC,OAAO,EAAC,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAC,KAAK,EAAC,GAAG,OAAO,CAAC;IACtB,OAAO,KAAK,GAAG,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,QAAQ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Y,QAAA,YAAY,GAAG,kCAAuB,CAAC","sourcesContent":["import {wrapIn} from 'prosemirror-commands';\nimport type {ResolvedPos} from 'prosemirror-model';\nimport type {Command} from 'prosemirror-state';\n\nimport {isTextSelection} from 'src/utils';\n\nimport '../../../types/spec';\n\nimport {addQuoteLinkPlaceholder} from './PlaceholderWidget/commands';\nimport {isQuoteLinkNode, quoteLinkType} from './QuoteLinkSpecs';\n\nexport const toggleQuote: Command = (state, dispatch) => {\n const {selection} = state;\n const qType = quoteLinkType(state.schema);\n if (!isTextSelection(selection) || !selection.$cursor) return wrapIn(qType)(state, dispatch);\n const {$cursor} = selection;\n let {depth} = $cursor;\n while (depth > 0) {\n const node = $cursor.node(depth);\n const nodeSpec = node.type.spec;\n if (!nodeSpec.complex || nodeSpec.complex === 'root') {\n const targetDepth = depth - 1;\n const range = getBlockRange($cursor, depth);\n let tr = state.tr;\n if (isQuoteLinkNode($cursor.node(targetDepth))) {\n tr = tr.lift(range!, targetDepth - 1).scrollIntoView();\n dispatch?.(tr);\n } else {\n tr = tr.wrap(range!, [{type: qType}]).scrollIntoView();\n dispatch?.(tr);\n }\n\n return true;\n }\n depth--;\n }\n\n return false;\n};\n\nfunction getBlockRange($pos: ResolvedPos, depth?: number) {\n const {doc} = $pos;\n const $before = doc.resolve($pos.before(depth));\n const $after = doc.resolve($pos.after(depth));\n return $before.blockRange($after);\n}\n\nexport const addQuoteLink = addQuoteLinkPlaceholder;\n"]}
|