diff --git a/package.json b/package.json index 9fccfea5..4d7c4145 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matters/matters-editor", - "version": "0.2.1-alpha.1", + "version": "0.2.0", "description": "Editor for matters.news", "author": "https://github.com/thematters", "homepage": "https://github.com/thematters/matters-editor", diff --git a/src/editors/Article.tsx b/src/editors/Article.tsx index de260e05..3e32f77a 100644 --- a/src/editors/Article.tsx +++ b/src/editors/Article.tsx @@ -14,17 +14,12 @@ export const useArticleEdtor = ({ content, placeholder, mentionSuggestion, - maxCaptionLength, ...editorProps }: UseArticleEditorProps) => { const { extensions, ...restProps } = editorProps const editor = useEditor({ extensions: [ - ...makeArticleEditorExtensions({ - placeholder, - mentionSuggestion, - maxCaptionLength, - }), + ...makeArticleEditorExtensions({ placeholder, mentionSuggestion }), ...(extensions || []), ], content, diff --git a/src/editors/extensions/figureAudio.ts b/src/editors/extensions/figureAudio.ts index b597a63e..64f92213 100644 --- a/src/editors/extensions/figureAudio.ts +++ b/src/editors/extensions/figureAudio.ts @@ -44,13 +44,9 @@ declare module '@tiptap/core' { } } -type FigureAudioOptions = { - maxCaptionLength?: number -} - const pluginName = 'figureAudio' -export const FigureAudio = Node.create({ +export const FigureAudio = Node.create({ name: pluginName, group: 'block', content: 'text*', @@ -60,12 +56,6 @@ export const FigureAudio = Node.create({ // disallows all marks for figcaption marks: '', - addOptions() { - return { - maxCaptionLength: undefined, - } - }, - addAttributes() { return { src: { @@ -223,24 +213,6 @@ export const FigureAudio = Node.create({ return html }, }, - filterTransaction: (transaction, state) => { - // Nothing has changed, ignore it. - if (!transaction.docChanged || !this.options.maxCaptionLength) { - return true - } - - try { - const anchorParent = transaction.selection.$anchor.parent - const figcaptionText = anchorParent.content.child(0).text || '' - if (figcaptionText.length > this.options.maxCaptionLength) { - return false - } - } catch (e) { - console.error(e) - } - - return true - }, }), ] }, diff --git a/src/editors/extensions/figureEmbed.ts b/src/editors/extensions/figureEmbed.ts index 6e61f411..5af25494 100644 --- a/src/editors/extensions/figureEmbed.ts +++ b/src/editors/extensions/figureEmbed.ts @@ -34,10 +34,6 @@ declare module '@tiptap/core' { } } -type FigureEmbedOptions = { - maxCaptionLength?: number -} - type NormalizeEmbedURLReturn = { url: string provider?: @@ -253,7 +249,7 @@ const normalizeEmbedURL = (url: string): NormalizeEmbedURLReturn => { const pluginName = 'figureEmbed' -export const FigureEmbed = Node.create({ +export const FigureEmbed = Node.create({ name: pluginName, group: 'block', content: 'text*', @@ -263,12 +259,6 @@ export const FigureEmbed = Node.create({ // disallows all marks for figcaption marks: '', - addOptions() { - return { - maxCaptionLength: undefined, - } - }, - addAttributes() { return { class: { @@ -314,6 +304,8 @@ export const FigureEmbed = Node.create({ ...(isCode ? [`embed-code`] : []), ].join(' ') + console.log({ url }) + return [ 'figure', { class: className, ...(provider ? { 'data-provider': provider } : {}) }, @@ -427,24 +419,6 @@ export const FigureEmbed = Node.create({ return html }, }, - filterTransaction: (transaction, state) => { - // Nothing has changed, ignore it. - if (!transaction.docChanged || !this.options.maxCaptionLength) { - return true - } - - try { - const anchorParent = transaction.selection.$anchor.parent - const figcaptionText = anchorParent.content.child(0).text || '' - if (figcaptionText.length > this.options.maxCaptionLength) { - return false - } - } catch (e) { - console.error(e) - } - - return true - }, }), ] }, diff --git a/src/editors/extensions/figureImage.ts b/src/editors/extensions/figureImage.ts index fce834cd..6e526b70 100644 --- a/src/editors/extensions/figureImage.ts +++ b/src/editors/extensions/figureImage.ts @@ -26,13 +26,9 @@ declare module '@tiptap/core' { } } -type FigureImageOptions = { - maxCaptionLength?: number -} - const pluginName = 'figureImage' -export const FigureImage = Node.create({ +export const FigureImage = Node.create({ name: pluginName, group: 'block', content: 'text*', @@ -42,12 +38,6 @@ export const FigureImage = Node.create({ // disallows all marks for figcaption marks: '', - addOptions() { - return { - maxCaptionLength: undefined, - } - }, - addAttributes() { return { class: { @@ -175,24 +165,6 @@ export const FigureImage = Node.create({ return html }, }, - filterTransaction: (transaction, state) => { - // Nothing has changed, ignore it. - if (!transaction.docChanged || !this.options.maxCaptionLength) { - return true - } - - try { - const anchorParent = transaction.selection.$anchor.parent - const figcaptionText = anchorParent.content.child(0).text || '' - if (figcaptionText.length > this.options.maxCaptionLength) { - return false - } - } catch (e) { - console.error(e) - } - - return true - }, }), ] }, diff --git a/src/editors/extensions/index.ts b/src/editors/extensions/index.ts index 80ba5153..797e681d 100644 --- a/src/editors/extensions/index.ts +++ b/src/editors/extensions/index.ts @@ -77,19 +77,17 @@ const baseArticleExtensions = (placeholder?: string) => [ export type MakeArticleEditorExtensionsProps = { placeholder?: string mentionSuggestion?: MentionSuggestion - maxCaptionLength?: number } export const makeArticleEditorExtensions = ({ placeholder, mentionSuggestion, - maxCaptionLength, }: MakeArticleEditorExtensionsProps) => { const extensions = [ ...baseArticleExtensions(placeholder), - FigureImage.configure({ maxCaptionLength }), - FigureAudio.configure({ maxCaptionLength }), - FigureEmbed.configure({ maxCaptionLength }), + FigureImage, + FigureAudio, + FigureEmbed, ] if (mentionSuggestion) { @@ -102,13 +100,12 @@ export const makeArticleEditorExtensions = ({ export const makeEditArticleEditorExtensions = ({ placeholder, mentionSuggestion, - maxCaptionLength, }: MakeArticleEditorExtensionsProps) => { const extensions = [ ...baseArticleExtensions(placeholder), - ReadOnlyFigureImage.configure({ maxCaptionLength }), - ReadOnlyFigureAudio.configure({ maxCaptionLength }), - ReadOnlyFigureEmbed.configure({ maxCaptionLength }), + ReadOnlyFigureImage, + ReadOnlyFigureAudio, + ReadOnlyFigureEmbed, ] if (mentionSuggestion) { diff --git a/src/editors/extensions/readOnlyFigureEmbed.ts b/src/editors/extensions/readOnlyFigureEmbed.ts index 1287e867..35eeaf23 100644 --- a/src/editors/extensions/readOnlyFigureEmbed.ts +++ b/src/editors/extensions/readOnlyFigureEmbed.ts @@ -278,6 +278,7 @@ export const ReadOnlyFigureEmbed = Node.create({ ...(isCode ? [`embed-code`] : []), ].join(' ') + console.log({ url }) return [ 'figure',