UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

73 lines (72 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.REACT_COMPONENT_NODE_NAME = void 0; var _core = require("@tiptap/core"); var _react = require("@tiptap/react"); var _component = _interopRequireDefault(require("./component")); var _utils = require("@douyinfe/semi-foundation/lib/cjs/aiChatInput/utils"); var _plugins = require("../plugins"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const REACT_COMPONENT_NODE_NAME = exports.REACT_COMPONENT_NODE_NAME = 'inputSlot'; var _default = exports.default = _core.Node.create({ name: 'inputSlot', group: 'inline', inline: true, // Allow text and other inline nodes inside content: 'inline*', // Allow editing atom: false, selectable: true, draggable: false, parseHTML() { return [{ tag: 'input-slot', getAttrs: element => ({ placeholder: element.getAttribute('placeholder') }) }]; }, renderHTML(_ref) { let { HTMLAttributes } = _ref; return ['input-slot', (0, _core.mergeAttributes)(HTMLAttributes), 0]; }, addAttributes() { return { placeholder: { default: '', parseHTML: element => element.getAttribute('placeholder') || '', renderHTML: attributes => ({ 'placeholder': attributes.placeholder }) }, isCustomSlot: (0, _utils.getCustomSlotAttribute)() }; }, addNodeView() { return (0, _react.ReactNodeViewRenderer)(_component.default, { update: _ref2 => { let { oldNode, newNode, updateProps } = _ref2; if (newNode.type !== oldNode.type) { return false; } if (this.editor.view.composing) { // Keep the live composition DOM untouched while IME is active. return true; } updateProps(); return true; } }); }, addProseMirrorPlugins() { return [(0, _plugins.ensureTrailingText)(this.editor.schema), (0, _plugins.keyDownHandlePlugin)(this.editor.schema)]; } });