UNPKG

smart-compose-react

Version:

输入字符可以智能提醒,按一下 Tab 键位就可以快速输入智能提醒内容

28 lines (24 loc) 16.3 kB
(function(F,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],O):(F=typeof globalThis<"u"?globalThis:F||self,O(F.SmartComposeReact={},F.react))})(this,function(F,O){"use strict";const ae=(c=>c&&typeof c=="object"&&"default"in c?c:{default:c})(O);var N=function(){return N=Object.assign||function(m){for(var y,f=1,T=arguments.length;f<T;f++){y=arguments[f];for(var d in y)Object.prototype.hasOwnProperty.call(y,d)&&(m[d]=y[d])}return m},N.apply(this,arguments)};typeof SuppressedError=="function"&&SuppressedError;var G={exports:{}},Y={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var oe;function Ae(){if(oe)return Y;oe=1;var c=ae.default,m=Symbol.for("react.element"),y=Symbol.for("react.fragment"),f=Object.prototype.hasOwnProperty,T=c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,d={key:!0,ref:!0,__self:!0,__source:!0};function P(C,E,j){var _,w={},l=null,u=null;j!==void 0&&(l=""+j),E.key!==void 0&&(l=""+E.key),E.ref!==void 0&&(u=E.ref);for(_ in E)f.call(E,_)&&!d.hasOwnProperty(_)&&(w[_]=E[_]);if(C&&C.defaultProps)for(_ in E=C.defaultProps,E)w[_]===void 0&&(w[_]=E[_]);return{$$typeof:m,type:C,key:l,ref:u,props:w,_owner:T.current}}return Y.Fragment=y,Y.jsx=P,Y.jsxs=P,Y}var V={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ie;function Fe(){return ie||(ie=1,process.env.NODE_ENV!=="production"&&function(){var c=ae.default,m=Symbol.for("react.element"),y=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),T=Symbol.for("react.strict_mode"),d=Symbol.for("react.profiler"),P=Symbol.for("react.provider"),C=Symbol.for("react.context"),E=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),l=Symbol.for("react.lazy"),u=Symbol.for("react.offscreen"),b=Symbol.iterator,D="@@iterator";function A(e){if(e===null||typeof e!="object")return null;var r=b&&e[b]||e[D];return typeof r=="function"?r:null}var h=c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];We("error",e,t)}}function We(e,r,t){{var n=h.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var s=t.map(function(o){return String(o)});s.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,s)}}var Ne=!1,Ye=!1,Ve=!1,$e=!1,Me=!1,le;le=Symbol.for("react.module.reference");function Ue(e){return!!(typeof e=="string"||typeof e=="function"||e===f||e===d||Me||e===T||e===j||e===_||$e||e===u||Ne||Ye||Ve||typeof e=="object"&&e!==null&&(e.$$typeof===l||e.$$typeof===w||e.$$typeof===P||e.$$typeof===C||e.$$typeof===E||e.$$typeof===le||e.getModuleId!==void 0))}function Be(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function ce(e){return e.displayName||"Context"}function x(e){if(e==null)return null;if(typeof e.tag=="number"&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case f:return"Fragment";case y:return"Portal";case d:return"Profiler";case T:return"StrictMode";case j:return"Suspense";case _:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case C:var r=e;return ce(r)+".Consumer";case P:var t=e;return ce(t._context)+".Provider";case E:return Be(e,e.render,"ForwardRef");case w:var n=e.displayName||null;return n!==null?n:x(e.type)||"Memo";case l:{var i=e,s=i._payload,o=i._init;try{return x(o(s))}catch{return null}}}return null}var I=Object.assign,$=0,fe,de,ve,pe,ge,me,ye;function he(){}he.__reactDisabledLog=!0;function ze(){{if($===0){fe=console.log,de=console.info,ve=console.warn,pe=console.error,ge=console.group,me=console.groupCollapsed,ye=console.groupEnd;var e={configurable:!0,enumerable:!0,value:he,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}$++}}function Je(){{if($--,$===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:I({},e,{value:fe}),info:I({},e,{value:de}),warn:I({},e,{value:ve}),error:I({},e,{value:pe}),group:I({},e,{value:ge}),groupCollapsed:I({},e,{value:me}),groupEnd:I({},e,{value:ye})})}$<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var K=h.ReactCurrentDispatcher,X;function U(e,r,t){{if(X===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);X=n&&n[1]||""}return` `+X+e}}var Z=!1,B;{var qe=typeof WeakMap=="function"?WeakMap:Map;B=new qe}function Ee(e,r){if(!e||Z)return"";{var t=B.get(e);if(t!==void 0)return t}var n;Z=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=K.current,K.current=null,ze();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(k){n=k}Reflect.construct(e,[],o)}else{try{o.call()}catch(k){n=k}e.call(o.prototype)}}else{try{throw Error()}catch(k){n=k}e()}}catch(k){if(k&&n&&typeof k.stack=="string"){for(var a=k.stack.split(` `),R=n.stack.split(` `),p=a.length-1,g=R.length-1;p>=1&&g>=0&&a[p]!==R[g];)g--;for(;p>=1&&g>=0;p--,g--)if(a[p]!==R[g]){if(p!==1||g!==1)do if(p--,g--,g<0||a[p]!==R[g]){var S=` `+a[p].replace(" at new "," at ");return e.displayName&&S.includes("<anonymous>")&&(S=S.replace("<anonymous>",e.displayName)),typeof e=="function"&&B.set(e,S),S}while(p>=1&&g>=0);break}}}finally{Z=!1,K.current=s,Je(),Error.prepareStackTrace=i}var W=e?e.displayName||e.name:"",De=W?U(W):"";return typeof e=="function"&&B.set(e,De),De}function Ge(e,r,t){return Ee(e,!1)}function He(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function z(e,r,t){if(e==null)return"";if(typeof e=="function")return Ee(e,He(e));if(typeof e=="string")return U(e);switch(e){case j:return U("Suspense");case _:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case E:return Ge(e.render);case w:return z(e.type,r,t);case l:{var n=e,i=n._payload,s=n._init;try{return z(s(i),r,t)}catch{}}}return""}var J=Object.prototype.hasOwnProperty,_e={},be=h.ReactDebugCurrentFrame;function q(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);be.setExtraStackFrame(t)}else be.setExtraStackFrame(null)}function Ke(e,r,t,n,i){{var s=Function.call.bind(J);for(var o in e)if(s(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var R=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw R.name="Invariant Violation",R}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(p){a=p}a&&!(a instanceof Error)&&(q(i),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),q(null)),a instanceof Error&&!(a.message in _e)&&(_e[a.message]=!0,q(i),v("Failed %s type: %s",t,a.message),q(null))}}}var Xe=Array.isArray;function Q(e){return Xe(e)}function Ze(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Qe(e){try{return Re(e),!1}catch{return!0}}function Re(e){return""+e}function Te(e){if(Qe(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ze(e)),Re(e)}var M=h.ReactCurrentOwner,er={key:!0,ref:!0,__self:!0,__source:!0},Se,Ce,ee;ee={};function rr(e){if(J.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function tr(e){if(J.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function nr(e,r){if(typeof e.ref=="string"&&M.current&&r&&M.current.stateNode!==r){var t=x(M.current.type);ee[t]||(v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',x(M.current.type),e.ref),ee[t]=!0)}}function ar(e,r){{var t=function(){Se||(Se=!0,v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function or(e,r){{var t=function(){Ce||(Ce=!0,v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var ir=function(e,r,t,n,i,s,o){var a={$$typeof:m,type:e,key:r,ref:t,props:o,_owner:s};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ur(e,r,t,n,i){{var s,o={},a=null,R=null;t!==void 0&&(Te(t),a=""+t),tr(r)&&(Te(r.key),a=""+r.key),rr(r)&&(R=r.ref,nr(r,i));for(s in r)J.call(r,s)&&!er.hasOwnProperty(s)&&(o[s]=r[s]);if(e&&e.defaultProps){var p=e.defaultProps;for(s in p)o[s]===void 0&&(o[s]=p[s])}if(a||R){var g=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&ar(o,g),R&&or(o,g)}return ir(e,a,R,i,n,M.current,o)}}var re=h.ReactCurrentOwner,we=h.ReactDebugCurrentFrame;function L(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);we.setExtraStackFrame(t)}else we.setExtraStackFrame(null)}var te;te=!1;function ne(e){return typeof e=="object"&&e!==null&&e.$$typeof===m}function Oe(){{if(re.current){var e=x(re.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function sr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var Pe={};function lr(e){{var r=Oe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function je(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=lr(r);if(Pe[t])return;Pe[t]=!0;var n="";e&&e._owner&&e._owner!==re.current&&(n=" It was passed a child from "+x(e._owner.type)+"."),L(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),L(null)}}function xe(e,r){{if(typeof e!="object")return;if(Q(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&je(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var i=A(e);if(typeof i=="function"&&i!==e.entries)for(var s=i.call(e),o;!(o=s.next()).done;)ne(o.value)&&je(o.value,r)}}}function cr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===E||r.$$typeof===w))t=r.propTypes;else return;if(t){var n=x(r);Ke(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!te){te=!0;var i=x(r);v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function fr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){L(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),L(null);break}}e.ref!==null&&(L(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),L(null))}}function ke(e,r,t,n,i,s){{var o=Ue(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var R=sr(i);R?a+=R:a+=Oe();var p;e===null?p="null":Q(e)?p="array":e!==void 0&&e.$$typeof===m?(p="<"+(x(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):p=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",p,a)}var g=ur(e,r,t,i,s);if(g==null)return g;if(o){var S=r.children;if(S!==void 0)if(n)if(Q(S)){for(var W=0;W<S.length;W++)xe(S[W],e);Object.freeze&&Object.freeze(S)}else v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else xe(S,e)}return e===f?fr(g):cr(g),g}}function dr(e,r,t){return ke(e,r,t,!0)}function vr(e,r,t){return ke(e,r,t,!1)}var pr=vr,gr=dr;V.Fragment=f,V.jsx=pr,V.jsxs=gr}()),V}(function(c){process.env.NODE_ENV==="production"?c.exports=Ae():c.exports=Fe()})(G);const ue=G.exports.jsx,se=G.exports.jsxs,H={container:"_container_y1zdu_1",sugStyle:"_sugStyle_y1zdu_9"};function Ie(c,m){var y=m.selectionStart,f=m.selectionEnd,T=m.value,d=T.substring(0,y),P=T.substring(f,T.length),C=d+c+P;m.value=C,m.selectionStart=m.selectionEnd=y+c.length}var Le=function(c){var m=c.children,y=c.suggestion,f=c.onChange,T=c.sugStyle,d=O.useRef(null),P=O.useId(),C=O.useId();O.useEffect(function(){var l=document.querySelectorAll("textarea");return d.current=null,setTimeout(function(){for(var u=0;u<l.length;u++)l[u].addEventListener("focus",E(l[u]),!0),l[u].addEventListener("blur",j,!0)},200),function(){d.current=null;for(var u=0;u<l.length;u++)l[u].removeEventListener("focus",E(l[u]),!0),l[u].removeEventListener("blur",j,!0)}},[]);var E=function(l){return function(u){d.current=l,console.log("\u9009\u4E2D\u8BBE\u7F6E$textarea",d.current)}},j=function(l){d.current=null},_=function(l){var u,b,D;console.log("\u6309\u952E\u4E86",l.key);var A=document.getElementById(P),h=window.getSelection(),v=h==null?void 0:h.getRangeAt(0);A&&((u=A.parentNode)===null||u===void 0||u.removeChild(A)),l.key=="Tab"?y&&(console.log("$textarea.current:",d.current),d.current?Ie(y,d.current):w(y),l.preventDefault()):f&&(d.current?f(d.current.value):((b=h==null?void 0:h.focusNode)===null||b===void 0?void 0:b.nodeValue)&&v&&f((D=h==null?void 0:h.focusNode)===null||D===void 0?void 0:D.nodeValue))},w=function(l){var u=null,b;if(window.getSelection&&(u=window.getSelection(),(u==null?void 0:u.getRangeAt)&&u.rangeCount)){b=u.getRangeAt(0),b.deleteContents();var D=document.createElement("div");D.innerHTML=l;for(var A=document.createDocumentFragment(),h=void 0,v=void 0;h=D.firstChild;)v=A.appendChild(h);b.insertNode(A),v&&(b=b.cloneRange(),b.setStartAfter(v),b.collapse(!0),u.removeAllRanges(),u.addRange(b))}};return se("div",N({className:H.container},{children:[y&&se("div",N({className:T||H.sugStyle},{children:[ue("span",{children:" suggestion: "}),y]})),ue("div",N({className:H.children,id:C,onKeyDown:_},{children:m}))]}))};F.SmartCompose=Le,Object.defineProperties(F,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});