PHP 8.2.30
Preview: nodePasteRule.ts Size: 1.36 KB
/home/byroehnu/easepaybiz.easetack.com/node_modules/@tiptap/core/src/pasteRules/nodePasteRule.ts

import { NodeType } from '@tiptap/pm/model'

import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
import { ExtendedRegExpMatchArray, JSONContent } from '../types.js'
import { callOrReturn } from '../utilities/index.js'

/**
 * Build an paste rule that adds a node when the
 * matched text is pasted into it.
 * @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#paste-rules
 */
export function nodePasteRule(config: {
  find: PasteRuleFinder
  type: NodeType
  getAttributes?:
    | Record<string, any>
    | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
    | false
    | null
  getContent?:
    | JSONContent[]
    | ((attrs: Record<string, any>) => JSONContent[])
    | false
    | null
}) {
  return new PasteRule({
    find: config.find,
    handler({
      match, chain, range, pasteEvent,
    }) {
      const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
      const content = callOrReturn(config.getContent, undefined, attributes)

      if (attributes === false || attributes === null) {
        return null
      }

      const node = { type: config.type.name, attrs: attributes } as JSONContent

      if (content) {
        node.content = content
      }

      if (match.input) {
        chain().deleteRange(range).insertContentAt(range.from, node)
      }
    },
  })
}

Directory Contents

Dirs: 0 × Files: 5

Name Size Perms Modified Actions
127 B lr--r--r-- 2026-03-14 01:49:07
Edit Download
105 B lrw-r--r-- 2026-03-05 00:20:23
Edit Download
2.13 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
1.36 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
916 B lrw-r--r-- 2026-03-05 00:20:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).