@yuntijs/ui
Version:
☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps
100 lines (99 loc) • 3.78 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import { DecoratorNode } from 'lexical';
import React from 'react';
// import type { MentionsOptionsMap } from '../../types';
import { MentionNodeComponent } from "./component";
import { jsx as _jsx } from "react/jsx-runtime";
export var MentionNode = /*#__PURE__*/function (_DecoratorNode) {
_inherits(MentionNode, _DecoratorNode);
var _super = _createSuper(MentionNode);
// constructor(variable: string, optionsMap?: MentionsOptionsMap, key?: NodeKey) {
function MentionNode(variable, key) {
var _this;
_classCallCheck(this, MentionNode);
_this = _super.call(this, key);
_defineProperty(_assertThisInitialized(_this), "__variable", void 0);
_this.__variable = variable;
return _this;
}
_createClass(MentionNode, [{
key: "isInline",
value: function isInline() {
return true;
}
}, {
key: "createDOM",
value: function createDOM() {
var div = document.createElement('div');
div.style.display = 'inline-flex';
div.style.alignItems = 'center';
div.style.verticalAlign = 'middle';
return div;
}
}, {
key: "updateDOM",
value: function updateDOM() {
return false;
}
}, {
key: "decorate",
value: function decorate() {
return /*#__PURE__*/_jsx(MentionNodeComponent, {
nodeKey: this.getKey(),
variable: this.__variable
});
}
}, {
key: "exportJSON",
value: function exportJSON() {
return {
type: 'mention-node',
version: 1,
variable: this.getVariable()
};
}
}, {
key: "getVariable",
value: function getVariable() {
var self = this.getLatest();
return self.__variable;
}
}, {
key: "getTextContent",
value: function getTextContent() {
return "{{".concat(this.getVariable(), "}}");
}
}], [{
key: "getType",
value: function getType() {
return 'mention-node';
}
}, {
key: "clone",
value: function clone(node) {
return new MentionNode(node.__variable, node.__key);
}
}, {
key: "importJSON",
value: function importJSON(serializedNode) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
var node = $createMentionNode(serializedNode.variable);
return node;
}
}]);
return MentionNode;
}(DecoratorNode);
export function $createMentionNode(variable) {
return new MentionNode(variable);
}
export function $isMentionNode(node) {
return node instanceof MentionNode;
}