Skip to content

Commit

Permalink
Revert "Merge branch 'main' into updateAttributes"
Browse files Browse the repository at this point in the history
This reverts commit 8a16bbe, reversing
changes made to 90a5a7b.
  • Loading branch information
silenius committed May 17, 2024
1 parent 8a16bbe commit 359b309
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 294 deletions.
3 changes: 0 additions & 3 deletions docs/collaboration/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Several `key` settings can be adjusted dynamically:
- **webhook_url**: Optional webhook URL for receiving callbacks.
- **authentication_disabled**: Toggle for enabling/disabling authentication (1 for disabled, 0 for enabled, with the default being 0).
- **name**: Optional instance name.
- **webhook_version**: The webhook version
- **default_auto_versioning**: Turn auto versioning on or off by default (1 for enabled, 0 for off).
- **default_auto_versioning_interval**: Default versioning interval (default is 30 seconds)

## Managing Settings via API

Expand Down
28 changes: 16 additions & 12 deletions packages/extension-code-block/src/code-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,25 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
return false
}

const { tr, schema } = view.state
const { tr } = view.state

// create an empty code block´
// if the cursor is at the absolute end of the document, insert the code block before the cursor instead
// of replacing the selection as the replaceSelectionWith function will cause the insertion to
// happen at the previous node
if (view.state.selection.from === view.state.doc.nodeSize - (1 + (view.state.selection.$to.depth * 2))) {
tr.insert(view.state.selection.from - 1, this.type.create({ language }))
} else {
tr.replaceSelectionWith(this.type.create({ language }))
}

// put cursor inside the newly created code block
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))))

// prepare a text node
// add text to code block
// strip carriage return chars from text pasted as code
// see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd
const textNode = schema.text(text.replace(/\r\n?/g, '\n'))

// create a code block with the text node
// replace selection with the code block
tr.replaceSelectionWith(this.type.create({ language }, textNode))

if (tr.selection.$from.parent.type !== this.type) {
// put cursor inside the newly created code block
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))))
}
tr.insertText(text.replace(/\r\n?/g, '\n'))

// store meta information
// this is useful for other plugins that depends on the paste event
Expand Down
28 changes: 4 additions & 24 deletions packages/extension-link/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ declare module '@tiptap/core' {
}
}

// From DOMPurify
// https://github.com/cure53/DOMPurify/blob/main/src/regexp.js
const ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
const IS_ALLOWED_URI = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape

function isAllowedUri(uri: string | undefined) {
return !uri || uri.replace(ATTR_WHITESPACE, '').match(IS_ALLOWED_URI)
}

/**
* This extension allows you to create links.
* @see https://www.tiptap.dev/api/marks/link
Expand Down Expand Up @@ -166,27 +157,16 @@ export const Link = Mark.create<LinkOptions>({
},

parseHTML() {
return [{
tag: 'a[href]',
getAttrs: dom => {
const href = (dom as HTMLElement).getAttribute('href')

// prevent XSS attacks
if (!href || !isAllowedUri(href)) {
return false
}
return { href }
},
}]
return [{ tag: 'a[href]:not([href *= "javascript:" i])' }]
},

renderHTML({ HTMLAttributes }) {
// prevent XSS attacks
if (!isAllowedUri(HTMLAttributes.href)) {
// False positive; we're explicitly checking for javascript: links to ignore them
// eslint-disable-next-line no-script-url
if (HTMLAttributes.href?.startsWith('javascript:')) {
// strip out the href
return ['a', mergeAttributes(this.options.HTMLAttributes, { ...HTMLAttributes, href: '' }), 0]
}

return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
},

Expand Down
24 changes: 5 additions & 19 deletions packages/extension-mention/src/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,7 @@ import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
import { PluginKey } from '@tiptap/pm/state'
import Suggestion, { SuggestionOptions } from '@tiptap/suggestion'

// See `addAttributes` below
export interface MentionNodeAttrs {
/**
* The identifier for the selected item that was mentioned, stored as a `data-id`
* attribute.
*/
id: string | null;
/**
* The label to be rendered by the editor as the displayed text for this mentioned
* item, if provided. Stored as a `data-label` attribute. See `renderLabel`.
*/
label?: string | null;
}

export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, any> = MentionNodeAttrs> = {
export type MentionOptions = {
/**
* The HTML attributes for a mention node.
* @default {}
Expand All @@ -32,23 +18,23 @@ export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, an
* @returns The label
* @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
*/
renderLabel?: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => string
renderLabel?: (props: { options: MentionOptions; node: ProseMirrorNode }) => string

/**
* A function to render the text of a mention.
* @param props The render props
* @returns The text
* @example ({ options, node }) => `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
*/
renderText: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => string
renderText: (props: { options: MentionOptions; node: ProseMirrorNode }) => string

/**
* A function to render the HTML of a mention.
* @param props The render props
* @returns The HTML as a ProseMirror DOM Output Spec
* @example ({ options, node }) => ['span', { 'data-type': 'mention' }, `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`]
*/
renderHTML: (props: { options: MentionOptions<SuggestionItem, Attrs>; node: ProseMirrorNode }) => DOMOutputSpec
renderHTML: (props: { options: MentionOptions; node: ProseMirrorNode }) => DOMOutputSpec

/**
* Whether to delete the trigger character with backspace.
Expand All @@ -61,7 +47,7 @@ export type MentionOptions<SuggestionItem = any, Attrs extends Record<string, an
* @default {}
* @example { char: '@', pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { ... } }
*/
suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>
suggestion: Omit<SuggestionOptions, 'editor'>
}

/**
Expand Down
26 changes: 13 additions & 13 deletions packages/suggestion/src/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view'

import { findSuggestionMatch as defaultFindSuggestionMatch } from './findSuggestionMatch.js'

export interface SuggestionOptions<I = any, TSelected = any> {
export interface SuggestionOptions<I = any> {
/**
* The plugin key for the suggestion plugin.
* @default 'suggestion'
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface SuggestionOptions<I = any, TSelected = any> {
* @returns void
* @example ({ editor, range, props }) => { props.command(props.props) }
*/
command?: (props: { editor: Editor; range: Range; props: TSelected }) => void
command?: (props: { editor: Editor; range: Range; props: I }) => void

/**
* A function that returns the suggestion items in form of an array.
Expand All @@ -86,12 +86,12 @@ export interface SuggestionOptions<I = any, TSelected = any> {
* @returns An object with render functions.
*/
render?: () => {
onBeforeStart?: (props: SuggestionProps<I, TSelected>) => void;
onStart?: (props: SuggestionProps<I, TSelected>) => void;
onBeforeUpdate?: (props: SuggestionProps<I, TSelected>) => void;
onUpdate?: (props: SuggestionProps<I, TSelected>) => void;
onExit?: (props: SuggestionProps<I, TSelected>) => void;
onKeyDown?: (props: SuggestionKeyDownProps) => boolean;
onBeforeStart?: (props: SuggestionProps<I>) => void
onStart?: (props: SuggestionProps<I>) => void
onBeforeUpdate?: (props: SuggestionProps<I>) => void
onUpdate?: (props: SuggestionProps<I>) => void
onExit?: (props: SuggestionProps<I>) => void
onKeyDown?: (props: SuggestionKeyDownProps) => boolean
}

/**
Expand All @@ -103,7 +103,7 @@ export interface SuggestionOptions<I = any, TSelected = any> {
findSuggestionMatch?: typeof defaultFindSuggestionMatch
}

export interface SuggestionProps<I = any, TSelected = any> {
export interface SuggestionProps<I = any> {
/**
* The editor instance.
*/
Expand Down Expand Up @@ -134,7 +134,7 @@ export interface SuggestionProps<I = any, TSelected = any> {
* @param props The props object.
* @returns void
*/
command: (props: TSelected) => void
command: (props: I) => void

/**
* The decoration node HTML element
Expand Down Expand Up @@ -162,7 +162,7 @@ export const SuggestionPluginKey = new PluginKey('suggestion')
* This utility allows you to create suggestions.
* @see https://tiptap.dev/api/utilities/suggestion
*/
export function Suggestion<I = any, TSelected = any>({
export function Suggestion<I = any>({
pluginKey = SuggestionPluginKey,
editor,
char = '@',
Expand All @@ -176,8 +176,8 @@ export function Suggestion<I = any, TSelected = any>({
render = () => ({}),
allow = () => true,
findSuggestionMatch = defaultFindSuggestionMatch,
}: SuggestionOptions<I, TSelected>) {
let props: SuggestionProps<I, TSelected> | undefined
}: SuggestionOptions<I>) {
let props: SuggestionProps<I> | undefined
const renderer = render?.()

const plugin: Plugin<any> = new Plugin({
Expand Down
Loading

0 comments on commit 359b309

Please sign in to comment.