citadel_cli 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/citadel.es.js +732 -1371
- package/dist/citadel.umd.js +15 -50
- package/package.json +1 -1
package/dist/citadel.umd.js
CHANGED
|
@@ -1,53 +1,17 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
|
|
3
|
-
* react-jsx-runtime.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Oe;function kn(){if(Oe)return Z;Oe=1;var o=i,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function d(h,u,f){var g,w={},j=null,k=null;f!==void 0&&(j=""+f),u.key!==void 0&&(j=""+u.key),u.ref!==void 0&&(k=u.ref);for(g in u)r.call(u,g)&&!l.hasOwnProperty(g)&&(w[g]=u[g]);if(h&&h.defaultProps)for(g in u=h.defaultProps,u)w[g]===void 0&&(w[g]=u[g]);return{$$typeof:n,type:h,key:j,ref:k,props:w,_owner:a.current}}return Z.Fragment=t,Z.jsx=d,Z.jsxs=d,Z}var ee={};/**
|
|
10
|
-
* @license React
|
|
11
|
-
* react-jsx-runtime.development.js
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Ie;function En(){return Ie||(Ie=1,process.env.NODE_ENV!=="production"&&function(){var o=i,n=Symbol.for("react.element"),t=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),d=Symbol.for("react.provider"),h=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),g=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),k=Symbol.for("react.offscreen"),H=Symbol.iterator,z="@@iterator";function m(e){if(e===null||typeof e!="object")return null;var s=H&&e[H]||e[z];return typeof s=="function"?s:null}var v=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(e){{for(var s=arguments.length,c=new Array(s>1?s-1:0),b=1;b<s;b++)c[b-1]=arguments[b];N("error",e,c)}}function N(e,s,c){{var b=v.ReactDebugCurrentFrame,S=b.getStackAddendum();S!==""&&(s+="%s",c=c.concat([S]));var E=c.map(function(C){return String(C)});E.unshift("Warning: "+s),Function.prototype.apply.call(console[e],console,E)}}var _=!1,P=!1,A=!1,$=!1,L=!1,oe;oe=Symbol.for("react.module.reference");function pe(e){return!!(typeof e=="string"||typeof e=="function"||e===r||e===l||L||e===a||e===f||e===g||$||e===k||_||P||A||typeof e=="object"&&e!==null&&(e.$$typeof===j||e.$$typeof===w||e.$$typeof===d||e.$$typeof===h||e.$$typeof===u||e.$$typeof===oe||e.getModuleId!==void 0))}function ae(e,s,c){var b=e.displayName;if(b)return b;var S=s.displayName||s.name||"";return S!==""?c+"("+S+")":c}function en(e){return e.displayName||"Context"}function Y(e){if(e==null)return null;if(typeof e.tag=="number"&&y("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 r:return"Fragment";case t:return"Portal";case l:return"Profiler";case a:return"StrictMode";case f:return"Suspense";case g:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case h:var s=e;return en(s)+".Consumer";case d:var c=e;return en(c._context)+".Provider";case u:return ae(e,e.render,"ForwardRef");case w:var b=e.displayName||null;return b!==null?b:Y(e.type)||"Memo";case j:{var S=e,E=S._payload,C=S._init;try{return Y(C(E))}catch{return null}}}return null}var B=Object.assign,se=0,nn,tn,rn,on,an,sn,ln;function cn(){}cn.__reactDisabledLog=!0;function Xn(){{if(se===0){nn=console.log,tn=console.info,rn=console.warn,on=console.error,an=console.group,sn=console.groupCollapsed,ln=console.groupEnd;var e={configurable:!0,enumerable:!0,value:cn,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}se++}}function Qn(){{if(se--,se===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:B({},e,{value:nn}),info:B({},e,{value:tn}),warn:B({},e,{value:rn}),error:B({},e,{value:on}),group:B({},e,{value:an}),groupCollapsed:B({},e,{value:sn}),groupEnd:B({},e,{value:ln})})}se<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Se=v.ReactCurrentDispatcher,ke;function he(e,s,c){{if(ke===void 0)try{throw Error()}catch(S){var b=S.stack.trim().match(/\n( *(at )?)/);ke=b&&b[1]||""}return`
|
|
18
|
-
`+ke+e}}var Ee=!1,ge;{var Zn=typeof WeakMap=="function"?WeakMap:Map;ge=new Zn}function un(e,s){if(!e||Ee)return"";{var c=ge.get(e);if(c!==void 0)return c}var b;Ee=!0;var S=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var E;E=Se.current,Se.current=null,Xn();try{if(s){var C=function(){throw Error()};if(Object.defineProperty(C.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(C,[])}catch(M){b=M}Reflect.construct(e,[],C)}else{try{C.call()}catch(M){b=M}e.call(C.prototype)}}else{try{throw Error()}catch(M){b=M}e()}}catch(M){if(M&&b&&typeof M.stack=="string"){for(var x=M.stack.split(`
|
|
19
|
-
`),F=b.stack.split(`
|
|
20
|
-
`),O=x.length-1,I=F.length-1;O>=1&&I>=0&&x[O]!==F[I];)I--;for(;O>=1&&I>=0;O--,I--)if(x[O]!==F[I]){if(O!==1||I!==1)do if(O--,I--,I<0||x[O]!==F[I]){var W=`
|
|
21
|
-
`+x[O].replace(" at new "," at ");return e.displayName&&W.includes("<anonymous>")&&(W=W.replace("<anonymous>",e.displayName)),typeof e=="function"&&ge.set(e,W),W}while(O>=1&&I>=0);break}}}finally{Ee=!1,Se.current=E,Qn(),Error.prepareStackTrace=S}var Q=e?e.displayName||e.name:"",q=Q?he(Q):"";return typeof e=="function"&&ge.set(e,q),q}function et(e,s,c){return un(e,!1)}function nt(e){var s=e.prototype;return!!(s&&s.isReactComponent)}function be(e,s,c){if(e==null)return"";if(typeof e=="function")return un(e,nt(e));if(typeof e=="string")return he(e);switch(e){case f:return he("Suspense");case g:return he("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case u:return et(e.render);case w:return be(e.type,s,c);case j:{var b=e,S=b._payload,E=b._init;try{return be(E(S),s,c)}catch{}}}return""}var ie=Object.prototype.hasOwnProperty,dn={},mn=v.ReactDebugCurrentFrame;function we(e){if(e){var s=e._owner,c=be(e.type,e._source,s?s.type:null);mn.setExtraStackFrame(c)}else mn.setExtraStackFrame(null)}function tt(e,s,c,b,S){{var E=Function.call.bind(ie);for(var C in e)if(E(e,C)){var x=void 0;try{if(typeof e[C]!="function"){var F=Error((b||"React class")+": "+c+" type `"+C+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[C]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw F.name="Invariant Violation",F}x=e[C](s,C,b,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(O){x=O}x&&!(x instanceof Error)&&(we(S),y("%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).",b||"React class",c,C,typeof x),we(null)),x instanceof Error&&!(x.message in dn)&&(dn[x.message]=!0,we(S),y("Failed %s type: %s",c,x.message),we(null))}}}var rt=Array.isArray;function _e(e){return rt(e)}function ot(e){{var s=typeof Symbol=="function"&&Symbol.toStringTag,c=s&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c}}function at(e){try{return fn(e),!1}catch{return!0}}function fn(e){return""+e}function pn(e){if(at(e))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ot(e)),fn(e)}var le=v.ReactCurrentOwner,st={key:!0,ref:!0,__self:!0,__source:!0},hn,gn,je;je={};function it(e){if(ie.call(e,"ref")){var s=Object.getOwnPropertyDescriptor(e,"ref").get;if(s&&s.isReactWarning)return!1}return e.ref!==void 0}function lt(e){if(ie.call(e,"key")){var s=Object.getOwnPropertyDescriptor(e,"key").get;if(s&&s.isReactWarning)return!1}return e.key!==void 0}function ct(e,s){if(typeof e.ref=="string"&&le.current&&s&&le.current.stateNode!==s){var c=Y(le.current.type);je[c]||(y('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',Y(le.current.type),e.ref),je[c]=!0)}}function ut(e,s){{var c=function(){hn||(hn=!0,y("%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)",s))};c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}}function dt(e,s){{var c=function(){gn||(gn=!0,y("%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)",s))};c.isReactWarning=!0,Object.defineProperty(e,"ref",{get:c,configurable:!0})}}var mt=function(e,s,c,b,S,E,C){var x={$$typeof:n,type:e,key:s,ref:c,props:C,_owner:E};return x._store={},Object.defineProperty(x._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(x,"_self",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.defineProperty(x,"_source",{configurable:!1,enumerable:!1,writable:!1,value:S}),Object.freeze&&(Object.freeze(x.props),Object.freeze(x)),x};function ft(e,s,c,b,S){{var E,C={},x=null,F=null;c!==void 0&&(pn(c),x=""+c),lt(s)&&(pn(s.key),x=""+s.key),it(s)&&(F=s.ref,ct(s,S));for(E in s)ie.call(s,E)&&!st.hasOwnProperty(E)&&(C[E]=s[E]);if(e&&e.defaultProps){var O=e.defaultProps;for(E in O)C[E]===void 0&&(C[E]=O[E])}if(x||F){var I=typeof e=="function"?e.displayName||e.name||"Unknown":e;x&&ut(C,I),F&&dt(C,I)}return mt(e,x,F,S,b,le.current,C)}}var Te=v.ReactCurrentOwner,bn=v.ReactDebugCurrentFrame;function X(e){if(e){var s=e._owner,c=be(e.type,e._source,s?s.type:null);bn.setExtraStackFrame(c)}else bn.setExtraStackFrame(null)}var Pe;Pe=!1;function Re(e){return typeof e=="object"&&e!==null&&e.$$typeof===n}function wn(){{if(Te.current){var e=Y(Te.current.type);if(e)return`
|
|
22
|
-
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function pt(e){return""}var yn={};function ht(e){{var s=wn();if(!s){var c=typeof e=="string"?e:e.displayName||e.name;c&&(s=`
|
|
24
|
-
|
|
25
|
-
Check the top-level render call using <`+c+">.")}return s}}function vn(e,s){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var c=ht(s);if(yn[c])return;yn[c]=!0;var b="";e&&e._owner&&e._owner!==Te.current&&(b=" It was passed a child from "+Y(e._owner.type)+"."),X(e),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',c,b),X(null)}}function xn(e,s){{if(typeof e!="object")return;if(_e(e))for(var c=0;c<e.length;c++){var b=e[c];Re(b)&&vn(b,s)}else if(Re(e))e._store&&(e._store.validated=!0);else if(e){var S=m(e);if(typeof S=="function"&&S!==e.entries)for(var E=S.call(e),C;!(C=E.next()).done;)Re(C.value)&&vn(C.value,s)}}}function gt(e){{var s=e.type;if(s==null||typeof s=="string")return;var c;if(typeof s=="function")c=s.propTypes;else if(typeof s=="object"&&(s.$$typeof===u||s.$$typeof===w))c=s.propTypes;else return;if(c){var b=Y(s);tt(c,e.props,"prop",b,e)}else if(s.PropTypes!==void 0&&!Pe){Pe=!0;var S=Y(s);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",S||"Unknown")}typeof s.getDefaultProps=="function"&&!s.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function bt(e){{for(var s=Object.keys(e.props),c=0;c<s.length;c++){var b=s[c];if(b!=="children"&&b!=="key"){X(e),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",b),X(null);break}}e.ref!==null&&(X(e),y("Invalid attribute `ref` supplied to `React.Fragment`."),X(null))}}var Cn={};function Sn(e,s,c,b,S,E){{var C=pe(e);if(!C){var x="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(x+=" 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 F=pt();F?x+=F:x+=wn();var O;e===null?O="null":_e(e)?O="array":e!==void 0&&e.$$typeof===n?(O="<"+(Y(e.type)||"Unknown")+" />",x=" Did you accidentally export a JSX literal instead of a component?"):O=typeof e,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",O,x)}var I=ft(e,s,c,S,E);if(I==null)return I;if(C){var W=s.children;if(W!==void 0)if(b)if(_e(W)){for(var Q=0;Q<W.length;Q++)xn(W[Q],e);Object.freeze&&Object.freeze(W)}else y("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 xn(W,e)}if(ie.call(s,"key")){var q=Y(e),M=Object.keys(s).filter(function(St){return St!=="key"}),Ae=M.length>0?"{key: someKey, "+M.join(": ..., ")+": ...}":"{key: someKey}";if(!Cn[q+Ae]){var Ct=M.length>0?"{"+M.join(": ..., ")+": ...}":"{}";y(`A props object containing a "key" prop is being spread into JSX:
|
|
26
|
-
let props = %s;
|
|
27
|
-
<%s {...props} />
|
|
28
|
-
React keys must be passed directly to JSX without using spread:
|
|
29
|
-
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Ae,q,Ct,q),Cn[q+Ae]=!0}}return e===r?bt(I):gt(I),I}}function wt(e,s,c){return Sn(e,s,c,!0)}function yt(e,s,c){return Sn(e,s,c,!1)}var vt=yt,xt=wt;ee.Fragment=r,ee.jsx=vt,ee.jsxs=xt}()),ee}process.env.NODE_ENV==="production"?ye.exports=kn():ye.exports=En();var p=ye.exports,ve,ce=J;if(process.env.NODE_ENV==="production")ve=ce.createRoot,ce.hydrateRoot;else{var Ne=ce.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;ve=function(o,n){Ne.usingClientEntryPoint=!0;try{return ce.createRoot(o,n)}finally{Ne.usingClientEntryPoint=!1}}}const _n=({onOpen:o,onClose:n,isVisible:t,showCitadelKey:r})=>{i.useEffect(()=>{const a=l=>{var d,h;!t&&l.key===r&&!["input","textarea"].includes(((h=(d=l.target)==null?void 0:d.tagName)==null?void 0:h.toLowerCase())||"")&&(l.preventDefault(),o()),t&&l.key==="Escape"&&(l.preventDefault(),n())};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[o,n,t,r])},De={container:"_container_141sr_3",innerContainer:"_innerContainer_141sr_19",inputSection:"_inputSection_141sr_28",resizeHandle:"_resizeHandle_141sr_35",citadel_slideUp:"_citadel_slideUp_141sr_64",citadel_slideDown:"_citadel_slideDown_141sr_68"},jn=o=>{const{isVisible:n,isClosing:t,onAnimationComplete:r}=o,a=i.useMemo(()=>n?t?De.slideDown:De.slideUp:"",[n,t]);return i.useEffect(()=>{if(r){const d=setTimeout(()=>{r()},200);return()=>clearTimeout(d)}},[t,r]),{style:i.useMemo(()=>({opacity:n?1:0,transform:n?"translateY(0)":t?"translateY(100%)":"translateY(-100%)",transition:"opacity 200ms ease-in-out, transform 200ms ease-in-out"}),[n,t]),animationClass:a}};var G=(o=>(o.Pending="pending",o.Success="success",o.Failure="failure",o.Timeout="timeout",o))(G||{});class V{constructor(n=Date.now()){R(this,"_status","pending");this.timestamp=n}get status(){return this._status}markSuccess(){this._status="success"}markFailure(){this._status="failure"}markTimeout(){this._status="timeout"}}class Tn extends V{constructor(n,t){super(t),this.data=n}render(){return p.jsx("pre",{className:"text-gray-200",children:JSON.stringify(this.data,null,2)})}}class xe extends V{constructor(n,t){super(t),this.text=n}render(){return p.jsx("div",{className:"text-gray-200 whitespace-pre font-mono",children:this.text})}}class ze extends V{constructor(n,t){super(t),this.error=n,this.markFailure()}render(){return p.jsx("div",{className:"mt-1 text-red-400",children:this.error})}}class Fe extends V{render(){return p.jsx("div",{className:"text-gray-400",children:"..."})}}class Pn extends V{constructor(n,t="",r){super(r),this.imageUrl=n,this.altText=t}render(){return p.jsx("div",{className:"my-2",children:p.jsx("img",{src:this.imageUrl,alt:this.altText,className:"max-w-[400px] max-h-[300px] h-auto rounded-lg object-contain"})})}}const Rn=o=>async function(){const n=o.commands.filter(t=>t.fullPath[0]!=="help").map(t=>`${t.segments.map(a=>a.type==="argument"?`<${a.name}>`:a.name).join(" ")} - ${t.description}`).sort();return n.push("help - Show available commands"),new xe(n.length>0?`Available Commands:
|
|
31
|
-
`+n.join(`
|
|
32
|
-
`):"No commands available yet. Add some commands to get started!")};var ue=(o=>(o[o.NONE=0]="NONE",o[o.ERROR=1]="ERROR",o[o.WARN=2]="WARN",o[o.INFO=3]="INFO",o[o.DEBUG=4]="DEBUG",o[o.TRACE=5]="TRACE",o))(ue||{});class D{static configure(n){this.level=n.level,this.prefix=n.prefix||"[Citadel]"}static trace(...n){this.level>=5&&process.env.NODE_ENV!=="production"&&console.trace(this.prefix,...n)}static debug(...n){this.level>=4&&process.env.NODE_ENV!=="production"&&console.debug(this.prefix,...n)}static info(...n){this.level>=3&&console.info(this.prefix,...n)}static warn(...n){this.level>=2&&console.warn(this.prefix,...n)}static error(...n){this.level>=1&&console.error(this.prefix,...n)}}R(D,"level",0),R(D,"prefix","");const U={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,initialHeight:"40vh",logLevel:process.env.NODE_ENV==="production"?ue.ERROR:ue.DEBUG,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,showCitadelKey:".",storage:{type:"localStorage",maxCommands:100}};class Ue{constructor(n){R(this,"config");this.config={type:"localStorage",maxCommands:100,...n}}async addStoredCommand(n){const t=await this.getStoredCommands();for(t.push(n);t.length>this.config.maxCommands;)t.shift();await this.saveCommands(t)}}class An extends Ue{constructor(t){super(t);R(this,"storageKey","citadel_command_history")}async getStoredCommands(){try{const t=window.localStorage.getItem(this.storageKey);return t?JSON.parse(t).map(a=>({commandSegments:a.commandSegments||[],timestamp:a.timestamp})):[]}catch(t){return console.warn("Failed to load commands from localStorage:",t),[]}}async clear(){try{window.localStorage.removeItem(this.storageKey)}catch(t){console.warn("Failed to clear localStorage:",t)}}async saveCommands(t){try{const r=t.map(a=>({commandSegments:Array.isArray(a.commandSegments)?[...a.commandSegments]:[],timestamp:a.timestamp}));window.localStorage.setItem(this.storageKey,JSON.stringify(r))}catch(r){throw console.warn("Failed to save commands to localStorage:",r),r}}}class On extends Ue{constructor(t){super(t);R(this,"storedCommands",[])}async getStoredCommands(){return this.storedCommands.map(t=>({commandSegments:Array.isArray(t.commandSegments)?[...t.commandSegments]:[],timestamp:t.timestamp}))}async clear(){this.storedCommands=[]}async saveCommands(t){this.storedCommands=t.map(r=>({commandSegments:Array.isArray(r.commandSegments)?[...r.commandSegments]:[],timestamp:r.timestamp}))}}const K=class K{constructor(){R(this,"currentStorage")}static getInstance(){return K.instance||(K.instance=new K),K.instance}initializeStorage(n){if(!this.currentStorage)try{this.currentStorage=new An(n)}catch(t){console.warn("Failed to create storage, falling back to memory storage:",t),this.currentStorage=new On(n)}}getStorage(){if(!this.currentStorage)throw new Error("Storage not initialized. Call initializeStorage first.");return this.currentStorage}};R(K,"instance");let de=K;const He=async()=>new xe("");class Ce{constructor(n,t,r){this.type=n,this.name=t,this.description=r}toString(){return this.name}}class Me extends Ce{constructor(){super("null",">null<","Empty segment")}}class In extends Ce{constructor(n,t){super("word",n,t)}}class Nn extends Ce{constructor(n,t,r,a){super("argument",n,t),this.value=r,this.valid=a}}class Dn{constructor(n,t,r=He){R(this,"_segments");R(this,"_description");R(this,"_handler");this._segments=n,this._description=t,this._handler=r}get segments(){return this._segments}get description(){return this._description}get handler(){return this._handler}get hasArguments(){return this.segments.some(n=>n.type==="argument")}get fullPath(){return this.segments.map(n=>n.name)}get fullPath_s(){return this.fullPath.join(" ")}equals(n){return this.fullPath.join(" ")===n.fullPath.join(" ")}}class me{constructor(){R(this,"_commands",[])}get commands(){return this._commands}addCommand(n,t,r=He){if(n===void 0||n.length===0)throw new Error("Command path cannot be empty");const a=new Dn(n,t,r),l=this._commands.find(d=>{const h=d.segments.map(f=>f.type==="argument"?"*":f.name).join(" "),u=n.map(f=>f.type==="argument"?"*":f.name).join(" ");return h===u});if(l)throw new Error(`Duplicate commands: '${l.fullPath_s}' and '${a.fullPath_s}'`);this._commands.push(a)}getCommand(n){return this._commands.find(t=>{const r=t.fullPath.join(" "),a=n.join(" ");return r===a})}commandExistsForPath(n){const t=this._commands.map(a=>a.segments.map(l=>l.type==="argument"?"*":l.name).join(" ")),r=n.map((a,l)=>this._commands.some(h=>{var u;return((u=h.segments[l])==null?void 0:u.type)==="argument"})?"*":a).join(" ");return t.includes(r)}getCompletions_s(n){return this.getCompletions(n).map(t=>t.name)}getCompletions(n){if(D.debug("[getCompletions] path: ",n),!n.length){const l=this._commands.map(u=>u.segments[0]),d=(u,f)=>u.type===f.type&&u.name===f.name;return l.filter((u,f,g)=>f===g.findIndex(w=>d(w,u)))}const t=n.length;return this._commands.filter(l=>{const d=l.segments;if(d.length<=t-1)return!1;for(let h=0;h<t;h++){const u=n[h],f=d[h];if(!(u==="*"&&f.type==="argument")&&u!==f.name)return!1}return!0}).filter(l=>l.segments.length>t).map(l=>{const d=l.segments[t],h=d.type==="argument"?Nn:In;return new h(d.name,d.description)}).filter((l,d,h)=>d===h.findIndex(u=>u.type===l.type&&u.name===l.name))}hasNextSegment(n){return this.getCompletions(n).length>0}}class $e{constructor(){R(this,"segments",[]);R(this,"nullSegment",new Me);R(this,"observers",[])}subscribe(n){this.observers.push(n)}unsubscribe(n){this.observers=this.observers.filter(t=>t!==n)}notifyObservers(){this.observers.forEach(n=>n.update())}clear(){this.segments=[],this.notifyObservers()}push(n){this.segments.push(n),this.notifyObservers()}pushAll(n){n.forEach(t=>this.push(t))}pop(){const n=this.segments.pop()||this.nullSegment;return this.notifyObservers(),n}peek(){return this.segments[this.segments.length-1]||this.nullSegment}size(){return this.segments.length}isEmpty(){return this.segments.length===0}get hasArguments(){return this.segments.some(n=>n.type==="argument")}get arguments(){return this.segments.filter(n=>n.type==="argument")}path(){return this.segments.map(n=>n.name)}toArray(){return[...this.segments]}}const zn={config:U,commands:new me,segmentStack:new $e},ne=i.createContext(zn),Fn=({config:o=U,commandRegistry:n,children:t})=>{const[r,a]=i.useState(),l={...U,...o,storage:{...U.storage,...o.storage},cursorType:o.cursorType??U.cursorType,cursorColor:o.cursorColor??U.cursorColor,cursorSpeed:o.cursorSpeed??U.cursorSpeed,showCitadelKey:o.showCitadelKey||"."};i.useEffect(()=>{de.getInstance().initializeStorage(l.storage??U.storage),a(de.getInstance().getStorage())},[]),i.useEffect(()=>{if(n&&l.includeHelpCommand&&!n.commandExistsForPath(["help"])){const h=Rn(n);n.addCommand([{type:"word",name:"help"}],"Show available commands",h)}},[n,l.includeHelpCommand]);const d={config:l,commands:n||new me,storage:r,segmentStack:new $e};return p.jsx(ne.Provider,{value:d,children:t})},te=()=>{const o=i.useContext(ne);if(o===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return o.config},fe=()=>{const o=i.useContext(ne);if(o===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return o.commands},We=()=>{const o=i.useContext(ne);if(o===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return o.storage},re=()=>{const o=i.useContext(ne);if(o===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return o.segmentStack};class Le{constructor(n,t){R(this,"timestamp");R(this,"command");R(this,"result");this.command=n.toArray().map(r=>r.type==="argument"?r.value||"":r.name),this.timestamp=Date.now(),this.result=t??new Fe}}function Un(o){return{commandSegments:o,timestamp:Date.now()}}function Ye(){const o=We(),[n,t]=i.useState({storedCommands:[],position:null}),r=i.useCallback(async h=>{if(o)try{const u=Un(h);await o.addStoredCommand(u),t(f=>({...f,storedCommands:[...f.storedCommands,u],position:null}))}catch(u){console.warn("Failed to save command to history:",u)}},[o]),a=i.useCallback(async()=>o?await o.getStoredCommands():[],[o]);i.useEffect(()=>{if(!o)return;(async()=>{try{const u=await o.getStoredCommands();return t(f=>({...f,storedCommands:u})),u}catch(u){console.warn("Failed to load command history:",u)}})()},[o]);const l=i.useCallback(async h=>{if((await a()).length===0)return{segments:null,position:null};let f=null;return h==="up"?n.position===null?f=n.storedCommands.length-1:n.position>0?f=n.position-1:f=0:n.position===null||n.position>=n.storedCommands.length-1?f=null:f=n.position+1,t(w=>({...w,position:f})),f===null?{segments:[],position:null}:{segments:f!==null?n.storedCommands[f].commandSegments:null,position:f}},[n,a]),d=i.useCallback(async()=>{try{if(!o)return;await o.clear(),t({storedCommands:[],position:null})}catch(h){console.warn("Failed to clear command history:",h)}},[o]);return{history:n,addStoredCommand:r,getStoredCommands:a,navigateHistory:l,clear:d}}const Ve=()=>{const o=te(),n=fe(),t=Ye(),r=re(),a=We(),[l,d]=i.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:a}});i.useEffect(()=>{},[a]),i.useEffect(()=>{d(g=>({...g,history:{commands:t.history.storedCommands,position:t.history.position,storage:a}}))},[t.history,a]);const h={setCurrentInput:i.useCallback(g=>{D.debug("[CitadelActions] setCurrentInput: ",g),d(w=>({...w,currentInput:g}))},[]),setIsEnteringArg:i.useCallback(g=>{D.debug("[CitadelActions] setIsEnteringArg: ",g),d(w=>({...w,isEnteringArg:g}))},[]),addOutput:i.useCallback(g=>{D.debug("[CitadelActions]addOutput: ",g),d(w=>({...w,output:[...w.output,g]}))},[]),executeCommand:i.useCallback(async()=>{const g=r.path(),w=n.getCommand(g);if(!w){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",g);return}const j=new Le(r);d(k=>({...k,output:[...k.output,j]}));try{const k=new Promise((m,v)=>{setTimeout(()=>{v(new Error("Request timed out"))},o.commandTimeoutMs)}),H=r.arguments.map(m=>m.value||""),z=await Promise.race([w.handler(H),k]);if(!(z instanceof V))throw new Error(`The ${g.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
|
|
1
|
+
(function(w,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react/jsx-runtime"),require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom/client"],i):(w=typeof globalThis<"u"?globalThis:w||self,i(w.Citadel={},w.jsxRuntime,w.React,w.client))})(this,function(w,i,s,me){"use strict";var je=Object.defineProperty;var Me=(w,i,s)=>i in w?je(w,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):w[i]=s;var y=(w,i,s)=>Me(w,typeof i!="symbol"?i+"":i,s);const ue=({onOpen:r,onClose:e,isVisible:n,showCitadelKey:t})=>{s.useEffect(()=>{const o=a=>{var c,m;!n&&a.key===t&&!["input","textarea"].includes(((m=(c=a.target)==null?void 0:c.tagName)==null?void 0:m.toLowerCase())||"")&&(a.preventDefault(),r()),n&&a.key==="Escape"&&(a.preventDefault(),e())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[r,e,n,t])},Y={container:"_container_141sr_3",innerContainer:"_innerContainer_141sr_19",inputSection:"_inputSection_141sr_28",resizeHandle:"_resizeHandle_141sr_35",citadel_slideUp:"_citadel_slideUp_141sr_64",citadel_slideDown:"_citadel_slideDown_141sr_68"},pe=r=>{const{isVisible:e,isClosing:n,onAnimationComplete:t}=r,o=s.useMemo(()=>e?n?Y.slideDown:Y.slideUp:"",[e,n]);return s.useEffect(()=>{if(t){const c=setTimeout(()=>{t()},200);return()=>clearTimeout(c)}},[n,t]),{style:s.useMemo(()=>({opacity:e?1:0,transform:e?"translateY(0)":n?"translateY(100%)":"translateY(-100%)",transition:"opacity 200ms ease-in-out, transform 200ms ease-in-out"}),[e,n]),animationClass:o}};var T=(r=>(r.Pending="pending",r.Success="success",r.Failure="failure",r.Timeout="timeout",r))(T||{});class H{constructor(e=Date.now()){y(this,"_status","pending");this.timestamp=e}get status(){return this._status}markSuccess(){this._status="success"}markFailure(){this._status="failure"}markTimeout(){this._status="timeout"}}class ge extends H{constructor(e,n){super(n),this.data=e}render(){return i.jsx("pre",{className:"text-gray-200",children:JSON.stringify(this.data,null,2)})}}class V extends H{constructor(e,n){super(n),this.text=e}render(){return i.jsx("div",{className:"text-gray-200 whitespace-pre font-mono",children:this.text})}}class B extends H{constructor(e,n){super(n),this.error=e,this.markFailure()}render(){return i.jsx("div",{className:"mt-1 text-red-400",children:this.error})}}class G extends H{render(){return i.jsx("div",{className:"text-gray-400",children:"..."})}}class he extends H{constructor(e,n="",t){super(t),this.imageUrl=e,this.altText=n}render(){return i.jsx("div",{className:"my-2",children:i.jsx("img",{src:this.imageUrl,alt:this.altText,className:"max-w-[400px] max-h-[300px] h-auto rounded-lg object-contain"})})}}const fe=r=>async function(){const e=r.commands.filter(n=>n.fullPath[0]!=="help").map(n=>`${n.segments.map(o=>o.type==="argument"?`<${o.name}>`:o.name).join(" ")} - ${n.description}`).sort();return e.push("help - Show available commands"),new V(e.length>0?`Available Commands:
|
|
2
|
+
`+e.join(`
|
|
3
|
+
`):"No commands available yet. Add some commands to get started!")};var $=(r=>(r[r.NONE=0]="NONE",r[r.ERROR=1]="ERROR",r[r.WARN=2]="WARN",r[r.INFO=3]="INFO",r[r.DEBUG=4]="DEBUG",r[r.TRACE=5]="TRACE",r))($||{});class S{static configure(e){this.level=e.level,this.prefix=e.prefix||"[Citadel]"}static trace(...e){this.level>=5&&process.env.NODE_ENV!=="production"&&console.trace(this.prefix,...e)}static debug(...e){this.level>=4&&process.env.NODE_ENV!=="production"&&console.debug(this.prefix,...e)}static info(...e){this.level>=3&&console.info(this.prefix,...e)}static warn(...e){this.level>=2&&console.warn(this.prefix,...e)}static error(...e){this.level>=1&&console.error(this.prefix,...e)}}y(S,"level",0),y(S,"prefix","");const N={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,initialHeight:"40vh",logLevel:process.env.NODE_ENV==="production"?$.ERROR:$.DEBUG,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,showCitadelKey:".",storage:{type:"localStorage",maxCommands:100}};class J{constructor(e){y(this,"config");this.config={type:"localStorage",maxCommands:100,...e}}async addStoredCommand(e){const n=await this.getStoredCommands();for(n.push(e);n.length>this.config.maxCommands;)n.shift();await this.saveCommands(n)}}class we extends J{constructor(n){super(n);y(this,"storageKey","citadel_command_history")}async getStoredCommands(){try{const n=window.localStorage.getItem(this.storageKey);return n?JSON.parse(n).map(o=>({commandSegments:o.commandSegments||[],timestamp:o.timestamp})):[]}catch(n){return console.warn("Failed to load commands from localStorage:",n),[]}}async clear(){try{window.localStorage.removeItem(this.storageKey)}catch(n){console.warn("Failed to clear localStorage:",n)}}async saveCommands(n){try{const t=n.map(o=>({commandSegments:Array.isArray(o.commandSegments)?[...o.commandSegments]:[],timestamp:o.timestamp}));window.localStorage.setItem(this.storageKey,JSON.stringify(t))}catch(t){throw console.warn("Failed to save commands to localStorage:",t),t}}}class be extends J{constructor(n){super(n);y(this,"storedCommands",[])}async getStoredCommands(){return this.storedCommands.map(n=>({commandSegments:Array.isArray(n.commandSegments)?[...n.commandSegments]:[],timestamp:n.timestamp}))}async clear(){this.storedCommands=[]}async saveCommands(n){this.storedCommands=n.map(t=>({commandSegments:Array.isArray(t.commandSegments)?[...t.commandSegments]:[],timestamp:t.timestamp}))}}const D=class D{constructor(){y(this,"currentStorage")}static getInstance(){return D.instance||(D.instance=new D),D.instance}initializeStorage(e){if(!this.currentStorage)try{this.currentStorage=new we(e)}catch(n){console.warn("Failed to create storage, falling back to memory storage:",n),this.currentStorage=new be(e)}}getStorage(){if(!this.currentStorage)throw new Error("Storage not initialized. Call initializeStorage first.");return this.currentStorage}};y(D,"instance");let K=D;const Q=async()=>new V("");class W{constructor(e,n,t){this.type=e,this.name=n,this.description=t}toString(){return this.name}}class X extends W{constructor(){super("null",">null<","Empty segment")}}class ye extends W{constructor(e,n){super("word",e,n)}}class xe extends W{constructor(e,n,t,o){super("argument",e,n),this.value=t,this.valid=o}}class Ce{constructor(e,n,t=Q){y(this,"_segments");y(this,"_description");y(this,"_handler");this._segments=e,this._description=n,this._handler=t}get segments(){return this._segments}get description(){return this._description}get handler(){return this._handler}get hasArguments(){return this.segments.some(e=>e.type==="argument")}get fullPath(){return this.segments.map(e=>e.name)}get fullPath_s(){return this.fullPath.join(" ")}equals(e){return this.fullPath.join(" ")===e.fullPath.join(" ")}}class L{constructor(){y(this,"_commands",[])}get commands(){return this._commands}addCommand(e,n,t=Q){if(e===void 0||e.length===0)throw new Error("Command path cannot be empty");const o=new Ce(e,n,t),a=this._commands.find(c=>{const m=c.segments.map(d=>d.type==="argument"?"*":d.name).join(" "),u=e.map(d=>d.type==="argument"?"*":d.name).join(" ");return m===u});if(a)throw new Error(`Duplicate commands: '${a.fullPath_s}' and '${o.fullPath_s}'`);this._commands.push(o)}getCommand(e){return this._commands.find(n=>{const t=n.fullPath.join(" "),o=e.join(" ");if(t===o)return!0;const c=n.segments.filter(m=>m.type==="word").map(m=>m.name);return c.length===e.length&&c.join(" ")===o})}commandExistsForPath(e){const n=this._commands.map(o=>o.segments.map(a=>a.type==="argument"?"*":a.name).join(" ")),t=e.map((o,a)=>this._commands.some(m=>{var u;return((u=m.segments[a])==null?void 0:u.type)==="argument"})?"*":o).join(" ");return n.includes(t)}getCompletions_s(e){return this.getCompletions(e).map(n=>n.name)}getCompletions(e){if(S.debug("[getCompletions] path: ",e),!e.length){const a=this._commands.map(u=>u.segments[0]),c=(u,d)=>u.type===d.type&&u.name===d.name;return a.filter((u,d,p)=>d===p.findIndex(g=>c(g,u)))}const n=e.length;return this._commands.filter(a=>{const c=a.segments;if(c.length<=n-1)return!1;for(let m=0;m<n;m++){const u=e[m],d=c[m];if(!(u==="*"&&d.type==="argument")&&u!==d.name)return!1}return!0}).filter(a=>a.segments.length>n).map(a=>{const c=a.segments[n],m=c.type==="argument"?xe:ye;return new m(c.name,c.description)}).filter((a,c,m)=>c===m.findIndex(u=>u.type===a.type&&u.name===a.name))}hasNextSegment(e){return this.getCompletions(e).length>0}}class Z{constructor(){y(this,"segments",[]);y(this,"nullSegment",new X);y(this,"observers",[])}subscribe(e){this.observers.push(e)}unsubscribe(e){this.observers=this.observers.filter(n=>n!==e)}notifyObservers(){this.observers.forEach(e=>e.update())}clear(){this.segments=[],this.notifyObservers()}push(e){this.segments.push(e),this.notifyObservers()}pushAll(e){e.forEach(n=>this.push(n))}pop(){const e=this.segments.pop()||this.nullSegment;return this.notifyObservers(),e}peek(){return this.segments[this.segments.length-1]||this.nullSegment}size(){return this.segments.length}isEmpty(){return this.segments.length===0}get hasArguments(){return this.segments.some(e=>e.type==="argument")}get arguments(){return this.segments.filter(e=>e.type==="argument")}path(){return this.segments.map(e=>e.name)}toArray(){return[...this.segments]}}const ve={config:N,commands:new L,segmentStack:new Z},U=s.createContext(ve),Se=({config:r=N,commandRegistry:e,children:n})=>{const[t,o]=s.useState(),a={...N,...r,storage:{...N.storage,...r.storage},cursorType:r.cursorType??N.cursorType,cursorColor:r.cursorColor??N.cursorColor,cursorSpeed:r.cursorSpeed??N.cursorSpeed,showCitadelKey:r.showCitadelKey||"."};s.useEffect(()=>{K.getInstance().initializeStorage(a.storage??N.storage),o(K.getInstance().getStorage())},[]),s.useEffect(()=>{if(e&&a.includeHelpCommand&&!e.commandExistsForPath(["help"])){const m=fe(e);e.addCommand([{type:"word",name:"help"}],"Show available commands",m)}},[e,a.includeHelpCommand]);const c={config:a,commands:e||new L,storage:t,segmentStack:new Z};return i.jsx(U.Provider,{value:c,children:n})},F=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return r.config},q=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return r.commands},R=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return r.storage},j=()=>{const r=s.useContext(U);if(r===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return r.segmentStack};class ee{constructor(e,n){y(this,"timestamp");y(this,"command");y(this,"result");this.command=e.toArray().map(t=>t.type==="argument"?t.value||"":t.name),this.timestamp=Date.now(),this.result=n??new G}}function ke(r){return{commandSegments:r,timestamp:Date.now()}}function ne(){const r=R(),[e,n]=s.useState({storedCommands:[],position:null}),t=s.useCallback(async m=>{if(r)try{const u=ke(m);await r.addStoredCommand(u),n(d=>({...d,storedCommands:[...d.storedCommands,u],position:null}))}catch(u){console.warn("Failed to save command to history:",u)}},[r]),o=s.useCallback(async()=>r?await r.getStoredCommands():[],[r]);s.useEffect(()=>{if(!r)return;(async()=>{try{const u=await r.getStoredCommands();return n(d=>({...d,storedCommands:u})),u}catch(u){console.warn("Failed to load command history:",u)}})()},[r]);const a=s.useCallback(async m=>{if((await o()).length===0)return{segments:null,position:null};let d=null;return m==="up"?e.position===null?d=e.storedCommands.length-1:e.position>0?d=e.position-1:d=0:e.position===null||e.position>=e.storedCommands.length-1?d=null:d=e.position+1,n(g=>({...g,position:d})),d===null?{segments:[],position:null}:{segments:d!==null?e.storedCommands[d].commandSegments:null,position:d}},[e,o]),c=s.useCallback(async()=>{try{if(!r)return;await r.clear(),n({storedCommands:[],position:null})}catch(m){console.warn("Failed to clear command history:",m)}},[r]);return{history:e,addStoredCommand:t,getStoredCommands:o,navigateHistory:a,clear:c}}const te=()=>{const r=F(),e=q(),n=ne(),t=j(),o=R(),[a,c]=s.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:o}});s.useEffect(()=>{},[o]),s.useEffect(()=>{c(p=>({...p,history:{commands:n.history.storedCommands,position:n.history.position,storage:o}}))},[n.history,o]);const m={setCurrentInput:s.useCallback(p=>{S.debug("[CitadelActions] setCurrentInput: ",p),c(g=>({...g,currentInput:p}))},[]),setIsEnteringArg:s.useCallback(p=>{S.debug("[CitadelActions] setIsEnteringArg: ",p),c(g=>({...g,isEnteringArg:p}))},[]),addOutput:s.useCallback(p=>{S.debug("[CitadelActions]addOutput: ",p),c(g=>({...g,output:[...g.output,p]}))},[]),executeCommand:s.useCallback(async()=>{const p=t.path(),g=e.getCommand(p);if(!g){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",p);return}const k=new ee(t);c(x=>({...x,output:[...x.output,k]}));try{const x=new Promise((l,h)=>{setTimeout(()=>{h(new Error("Request timed out"))},r.commandTimeoutMs)}),A=t.arguments.map(l=>l.value||""),_=await Promise.race([g.handler(A),x]);if(!(_ instanceof H))throw new Error(`The ${p.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
|
|
33
4
|
For example:
|
|
34
5
|
return new JsonCommandResult({ text: "Hello World" });
|
|
35
|
-
Check the definition of the ${
|
|
36
|
-
@keyframes
|
|
37
|
-
0%, 100% {
|
|
38
|
-
|
|
39
|
-
75% { transform: translateX(4px); }
|
|
40
|
-
}
|
|
41
|
-
@keyframes flashBorder {
|
|
42
|
-
0%, 100% { border-color: transparent; }
|
|
43
|
-
50% { border-color: rgb(239, 68, 68); }
|
|
6
|
+
Check the definition of the ${p.join(".")} command and update the return type for its handler.`);_.markSuccess(),c(l=>({...l,output:l.output.map(h=>h.timestamp===k.timestamp?{...h,result:_}:h)}))}catch(x){const A=new B(x instanceof Error?x.message:"Unknown error");A.markFailure(),c(_=>({..._,output:_.output.map(l=>l.timestamp===k.timestamp?{...l,result:A}:l)}))}},[e,r.commandTimeoutMs,t]),clearHistory:s.useCallback(async()=>{try{await n.clear()}catch(p){console.warn("Failed to clear history:",p)}},[n])},u=s.useCallback(()=>e.getCompletions_s(t.path()),[t,e]),d=s.useCallback(()=>e.getCompletions(t.path()),[t,e]);return{state:a,actions:m,getAvailableCommands_s:u,getAvailableCommandSegments:d}},re={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},oe=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],se=["|","/","-","\\"],Ee=({style:r={type:"blink"},isValid:e=!0,errorMessage:n})=>{const t=s.useMemo(()=>({...re[r.type],...r}),[r]),[o,a]=s.useState(!0),[c,m]=s.useState(0);s.useEffect(()=>{if(t.speed===0)return;const p=setInterval(()=>{t.type==="blink"?a(g=>!g):["spin","bbs"].includes(t.type)&&m(g=>(g+1)%(t.type==="bbs"?se.length:oe.length))},t.speed);return()=>clearInterval(p)},[t.type,t.speed]);const u=s.useMemo(()=>({color:e?t.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[e,t.color]),d=()=>!e&&n?"✗":["spin","bbs"].includes(t.type)?(t.type==="bbs"?se:oe)[c]:t.type==="solid"||o?t.character:" ";return i.jsx("div",{className:"relative inline-block",children:i.jsx("span",{className:`command-cursor ${e?"":"animate-shake"}`,style:u,title:n,children:d()})})};function _e(r,e){switch(e.type){case"set":return S.debug(`[inputStateReducer] InputState changing from ${r} to ${e.state}`),e.state;default:return r}}const Ne=()=>{const{state:r}=te(),e=q(),n=ne(),t=j(),[o,a]=s.useReducer(_e,"idle"),c=l=>{a({type:"set",state:l})},m=s.useCallback(()=>{const h=e.getCompletions(t.path())[0]||t.nullSegment;return S.debug("[getNextExpectedSegment] ",h),h},[e,t]),u=s.useCallback(()=>e.getCompletions_s(t.path()).map(h=>e.getCommand([...t.path(),h])).filter(h=>h!==void 0),[e,t]),d=s.useCallback((l,h)=>{if(!l)return h;const f=h.reduce((b,C)=>{const v=m();return(v==null?void 0:v.type)==="word"&&b.set(v.name,C),b},new Map);return Array.from(f.values()).filter(()=>{const b=m();return b.type!=="word"?!1:b.name.toLowerCase().startsWith(l.toLowerCase())})},[m]),p=s.useCallback(l=>{const f=e.getCompletions(t.path()).filter(E=>E.type==="word").filter(E=>E.name.toLowerCase().startsWith(l.toLowerCase()));return f.length===1?f[0]:t.nullSegment},[e,t]),g=s.useCallback(l=>{const h=t.path(),f=e.getCompletions(h);return f.length===0&&l?!1:f.some(b=>b.type==="argument")?!0:f.some(b=>b.type==="word"&&b.name.toLowerCase().startsWith(l.toLowerCase()))},[e,t]),k=s.useCallback(l=>{S.debug("[tryAutoComplete] input: ",l);const h=p(l);return!h||h.name===l?new X:(S.debug("[tryAutoComplete] result: ",h),h)},[p]),x=s.useCallback((l,h)=>{if(r.history.position===null){if(h.setCurrentInput(l),S.debug("[useCommandParser][handleInputChange] newValue: ",l),o==="entering_argument"){const f=ae(l);if(f.isQuoted)if(f.isComplete){const E=m();if(E.type==="argument"){const b=E;b.value=l.trim()||"",S.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",b),t.push(b),h.setCurrentInput(""),c("idle");return}}else return;else if(f.isComplete){const E=m();E.value=l.trim()||"",S.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",E),t.push(E),h.setCurrentInput(""),c("idle");return}else return}if(o=="entering_command"){const f=k(l);if(f.type==="word"){S.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",f),t.push(f),h.setCurrentInput(""),c("idle");return}}}},[k,r,m,o,t]),A=s.useCallback(l=>{l.setCurrentInput(""),l.setIsEnteringArg(!1),t.clear(),c("idle")},[t]),_=s.useCallback((l,h,f)=>{if(!(l.key==="Backspace"||l.key==="Enter"||l.key==="ArrowUp"||l.key==="ArrowDown"||l.key==="ArrowLeft"||l.key==="ArrowRight"||l.key==="Escape"||l.key==="Delete"||l.key==="Home"||l.key==="End"||l.key.length===1))return!0;const{currentInput:b,isEnteringArg:C}=h,v=ae(b);switch(l.key){case"Backspace":return b===""&&(l.preventDefault(),t.size()>0&&t.pop(),c("idle")),!0;case"Enter":{if(l.preventDefault(),v.isQuoted&&!v.isComplete)return!0;if(o==="entering_argument"||C&&b.trim()){const P=m();P.value=b,S.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",P),t.push(P)}const z=t.path(),I=e.getCommand(z);if(I){const M=I.segments.filter(O=>O.type==="argument"),P=t.arguments;if(M.length>P.length)return!1}return S.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",t),f.executeCommand(),n.addStoredCommand(t.toArray()),A(f),!0}case"ArrowUp":return l.preventDefault(),(async()=>{const z=await n.navigateHistory("up",t.toArray());return z.segments&&(t.clear(),t.pushAll(z.segments),f.setCurrentInput("")),!0})();case"ArrowDown":return l.preventDefault(),(async()=>{const z=await n.navigateHistory("down",t.toArray());return z.segments&&(t.clear(),t.pushAll(z.segments),f.setCurrentInput("")),!0})();default:{if(!C&&l.key.length===1){const z=b+l.key;if(!g(z))return l.preventDefault(),!1}return!0}}},[o,g,m,n,A,t]);return{handleInputChange:x,handleKeyDown:_,inputState:o,setInputStateWithLogging:c,findMatchingCommands:d,getAutocompleteSuggestion:p,getAvailableNodes:u,getNextExpectedSegment:m,isValidCommandInput:g}};function ae(r){const e=[];let n="",t=!1,o;for(let a=0;a<r.length;a++){const c=r[a];(c==='"'||c==="'")&&(!t||c===o)?t?(e.push(n),n="",t=!1,o=void 0):(n&&(e.push(n),n=""),t=!0,o=c):!t&&c===" "?n&&(e.push(n),n=""):n+=c}return{words:e,currentWord:n,isQuoted:t,quoteChar:o,isComplete:!t&&!n}}const Ae=()=>{const r=j(),[e,n]=s.useState(0);return s.useEffect(()=>{const t={update:()=>{n(o=>o+1)}};return r.subscribe(t),()=>{r.unsubscribe(t)}},[r]),e},ze=({state:r,actions:e})=>{const n=s.useRef(null),t=q(),o=j(),{handleKeyDown:a,handleInputChange:c,inputState:m,setInputStateWithLogging:u,getNextExpectedSegment:d}=Ne(),[p,g]=s.useState(!1),k=F(),x=Ae(),A=async C=>{const v=a(C,r,e);await Promise.resolve(v)===!1&&(g(!0),setTimeout(()=>g(!1),500))},_=C=>{c(C.target.value,e)},l=C=>{C.preventDefault();const v=C.clipboardData.getData("text");c(v,e)};s.useEffect(()=>{n.current&&n.current.focus(),m!=="entering_command"&&u("entering_command")},[m,u]),s.useEffect(()=>{if(m!=="idle")return;const C=d();let v="idle";switch(C.type){case"word":v="entering_command",e.setIsEnteringArg(!1);break;case"argument":v="entering_argument",e.setIsEnteringArg(!0);break}u(v)},[x,m,d,u,e]);const[h,f]=s.useState([]);s.useEffect(()=>{const C=[],v=o.toArray().map((I,M)=>{C.push(I.name);const P=t.hasNextSegment(C);if(I.type==="argument"){const O=I;return i.jsxs(s.Fragment,{children:[i.jsx("span",{className:"text-gray-200 whitespace-pre",children:O.value}),M<o.size()&&P&&i.jsx("span",{className:"text-gray-200 whitespace-pre",children:" "})]},"arg-"+O.name+O.value)}return i.jsxs(s.Fragment,{children:[i.jsx("span",{className:"text-blue-400 whitespace-pre",children:I.name}),M<o.size()&&P&&i.jsx("span",{className:"text-blue-400 whitespace-pre",children:" "})]},"word-"+I.name)});f([i.jsx("div",{className:"flex items-center gap-1","data-testid":"user-input-area",children:v},"{segmentStackVersion}")])},[x,t,o]);const[E,b]=s.useState("");return s.useEffect(()=>{const C=d();C.type==="argument"?b(C.name):b("")},[x,d]),i.jsxs("div",{className:"flex flex-col w-full bg-gray-900 rounded-lg p-4",children:[i.jsx("style",{children:`
|
|
7
|
+
@keyframes subtleGlow {
|
|
8
|
+
0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
|
|
9
|
+
50% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
|
|
44
10
|
}
|
|
45
11
|
.invalid-input-animation {
|
|
46
|
-
animation:
|
|
47
|
-
border-width: 1px;
|
|
48
|
-
border-style: solid;
|
|
12
|
+
animation: subtleGlow 0.4s ease-in-out;
|
|
49
13
|
}
|
|
50
|
-
`}),
|
|
14
|
+
`}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"text-gray-400 font-mono",children:">"}),i.jsxs("div",{className:"flex-1 font-mono flex items-center",children:[h,i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{ref:n,type:"text",role:"textbox",value:r.currentInput,onChange:_,onKeyDown:A,onPaste:l,"data-testid":"citadel-command-input",className:`w-full bg-transparent outline-none text-gray-200 caret-transparent ${p?"invalid-input-animation":""}`,spellCheck:!1,autoComplete:"off",placeholder:E}),i.jsx("div",{className:"absolute top-0 pointer-events-none",style:{left:`${r.currentInput.length}ch`,transition:"left 0.05s ease-out"},children:i.jsx(Ee,{style:{type:k.cursorType??N.cursorType,color:k.cursorColor||N.cursorColor,speed:k.cursorSpeed||N.cursorSpeed}})})]})]})]})]})},Ie=()=>i.jsx("div",{"data-testid":"spinner",className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"}),Pe=({command:r,timestamp:e,status:n})=>i.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm",children:[i.jsxs("span",{className:"text-gray-200",children:["> ",r.split(" ").map((t,o)=>{const a=t.startsWith("<")&&t.endsWith(">");return i.jsxs("span",{className:a?"text-green-400":"text-gray-200",children:[o>0?" ":"",t]},o)})]}),i.jsx("span",{className:"text-gray-400",children:"·"}),i.jsx("span",{className:"text-gray-500",children:e}),n===T.Pending&&i.jsx(Ie,{}),n===T.Success&&i.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-green-500"}),(n===T.Timeout||n===T.Failure)&&i.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-red-500"})]}),He=({output:r,outputRef:e})=>{const n=F(),t=s.useCallback(()=>{if(e.current){const o=e.current;requestAnimationFrame(()=>{o.scrollTop=o.scrollHeight})}},[e]);return s.useEffect(()=>{if(t(),e.current){const o=e.current.getElementsByTagName("img"),a=o[o.length-1];if(a&&!a.complete)return a.addEventListener("load",t),()=>a.removeEventListener("load",t)}},[r,t,e]),i.jsx("div",{ref:e,className:"h-full overflow-y-auto border border-gray-700 rounded-lg p-3 text-left",children:r.map((o,a)=>i.jsxs("div",{className:"mb-4 last:mb-0",children:[i.jsx(Pe,{command:o.command.join(" "),timestamp:new Date(o.timestamp).toLocaleTimeString(),status:o.result.status}),i.jsx("pre",{className:`text-gray-200 whitespace-pre font-mono ${n.outputFontSize}`,children:o.result.render()})]},a))})},De=()=>{const r=q(),e=F(),n=j(),t="h-12 mt-2 border-t border-gray-700 px-4",o="text-gray-300 pt-2",a=r.getCompletions(n.path());S.debug("[AvailableCommands] nextCommandSegments: ",a);const c=s.useMemo(()=>{if(e.includeHelpCommand){const d=a.filter(g=>g.name!=="help"),p=a.find(g=>g.name==="help");return[...d,...p?[p]:[]]}return a},[a,e.includeHelpCommand]),m=a.some(d=>d.type==="argument"),u=a[0];return i.jsx("div",{className:t,"data-testid":"available-commands",children:i.jsx("div",{className:o,children:m?a.length>0?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-blue-400",children:u.name}),u.description&&i.jsxs("span",{className:"text-gray-400 ml-2",children:["- ",u.description]})]}):null:i.jsx("div",{className:"flex flex-wrap gap-2",children:c==null?void 0:c.map(d=>{const p=c==null?void 0:c.reduce((g,k)=>{if(k===d)return g;let x=0;for(;x<d.name.length&&x<k.name.length&&d.name[x].toLowerCase()===k.name[x].toLowerCase();)x++;return Math.max(g,x+1)},1);return i.jsx("div",{className:"px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",children:i.jsxs("span",{className:"font-mono text-white",children:[i.jsx("strong",{className:"underline",children:d.name.slice(0,p)}),d.name.slice(p)]})},d.name)})})})})},ie=`:host {
|
|
51
15
|
--citadel-bg: rgb(17, 24, 39);
|
|
52
16
|
--citadel-text: rgba(255, 255, 255, 0.87);
|
|
53
17
|
--citadel-border: rgb(55, 65, 81);
|
|
@@ -67,6 +31,7 @@ Check the definition of the ${g.join(".")} command and update the return type fo
|
|
|
67
31
|
bottom: 0;
|
|
68
32
|
left: 0;
|
|
69
33
|
right: 0;
|
|
34
|
+
z-index: 2147483647; /* Maximum z-index value */
|
|
70
35
|
overflow: hidden;
|
|
71
36
|
|
|
72
37
|
pointer-events: auto;
|
|
@@ -136,7 +101,7 @@ a:hover {
|
|
|
136
101
|
text-align: left;
|
|
137
102
|
}
|
|
138
103
|
|
|
139
|
-
`,
|
|
104
|
+
`,le=`/* Keep only component-specific styles here */
|
|
140
105
|
|
|
141
106
|
.container {
|
|
142
107
|
position: fixed;
|
|
@@ -206,10 +171,10 @@ a:hover {
|
|
|
206
171
|
.citadel_slideDown {
|
|
207
172
|
animation: citadel_slideDown 0.2s ease-out forwards;
|
|
208
173
|
}
|
|
209
|
-
`,
|
|
174
|
+
`,ce=`@tailwind base;
|
|
210
175
|
@tailwind components;
|
|
211
176
|
@tailwind utilities;
|
|
212
|
-
`,
|
|
177
|
+
`,Te=`*, ::before, ::after {
|
|
213
178
|
--tw-border-spacing-x: 0;
|
|
214
179
|
--tw-border-spacing-y: 0;
|
|
215
180
|
--tw-translate-x: 0;
|
|
@@ -1026,5 +991,5 @@ video {
|
|
|
1026
991
|
.last\\:mr-0:last-child {
|
|
1027
992
|
margin-right: 0px;
|
|
1028
993
|
}
|
|
1029
|
-
`,
|
|
1030
|
-
`),
|
|
994
|
+
`,Ue=({config:r=N,commandRegistry:e=new L,containerId:n=null})=>(s.useEffect(()=>{S.configure({level:r.logLevel||N.logLevel||$.ERROR,prefix:"[Citadel]"});const t=new de(e,r),o=n?document.getElementById(n):document.body;return o?o.appendChild(t):(console.warn(`Container with id "${n}" not found, falling back to body`),document.body.appendChild(t)),()=>{var a;(a=t.parentElement)==null||a.removeChild(t)}},[e,n,r]),null);class de extends HTMLElement{constructor(n,t){super();y(this,"shadow");y(this,"root",null);y(this,"commandRegistry");y(this,"config");this.shadow=this.attachShadow({mode:"open"}),this.commandRegistry=n,this.config=t}connectedCallback(){try{const t=[ie,le,ce,Te].map(o=>{const a=new CSSStyleSheet;return a.replaceSync(o),a});this.shadow.adoptedStyleSheets=[...t]}catch{const t=[ie,le,ce].join(`
|
|
995
|
+
`),o=document.createElement("style");o.textContent=t,this.shadow.appendChild(o)}const n=document.createElement("div");n.id="citadel-root",this.shadow.appendChild(n),this.root=me.createRoot(n),this.root.render(i.jsx(Se,{config:this.config||N,commandRegistry:this.commandRegistry,children:i.jsx(Fe,{})}))}}customElements.define("citadel-element",de);const Fe=()=>{const[r,e]=s.useState(!1),[n,t]=s.useState(!1),o=F(),[a,c]=s.useState(()=>o.initialHeight||null),m=s.useRef(null),u=s.useRef(null),d=s.useRef(!1),p=s.useRef(0),g=s.useRef(0),{state:k,actions:x}=te();ue({onOpen:()=>e(!0),onClose:()=>t(!0),isVisible:r,showCitadelKey:o.showCitadelKey||"."});const A=s.useCallback(f=>{u.current&&(d.current=!0,p.current=f.clientY,g.current=u.current.offsetHeight,document.documentElement.style.userSelect="none",document.documentElement.style.webkitUserSelect="none",document.documentElement.style.mozUserSelect="none",document.documentElement.style.msUserSelect="none",document.addEventListener("mousemove",_),document.addEventListener("mouseup",l))},[]),_=s.useCallback(f=>{var v;if(!d.current)return;const E=f.clientY-p.current,b=(v=o.maxHeight)!=null&&v.endsWith("vh")?window.innerHeight*parseInt(o.maxHeight,10)/100:parseInt(o.maxHeight||"80vh",10),C=Math.min(Math.max(g.current-E,parseInt(o.minHeight||"200",10)),b);u.current&&(u.current.style.height=`${C}px`,u.current.style.bottom="0",c(`${C}px`))},[o.maxHeight,o.minHeight]),l=s.useCallback(()=>{d.current=!1,document.documentElement.style.userSelect="",document.documentElement.style.webkitUserSelect="",document.documentElement.style.mozUserSelect="",document.documentElement.style.msUserSelect="",document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",l)},[_]);s.useEffect(()=>()=>{document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",l)},[_,l]);const h=s.useCallback(()=>{n&&(e(!1),t(!1))},[n]);return pe({isVisible:r,isClosing:n,onAnimationComplete:h}),r?i.jsxs("div",{ref:u,className:`container ${r?"citadel_slideUp":""} ${n?"citadel_slideDown":""}`,style:{...a?{height:a}:void 0,maxHeight:o.maxHeight},children:[i.jsx("div",{className:"resizeHandle",onMouseDown:A}),i.jsxs("div",{className:"innerContainer",children:[i.jsx("div",{className:"flex-1 min-h-0 pt-3 px-4",children:i.jsx(He,{output:k.output,outputRef:m})}),i.jsxs("div",{children:[i.jsx(ze,{state:k,actions:x}),i.jsx(De,{})]})]})]}):null};w.Citadel=Ue,w.CommandRegistry=L,w.CommandResult=H,w.CommandStatus=T,w.DEFAULT_CURSOR_CONFIGS=re,w.ErrorCommandResult=B,w.ImageCommandResult=he,w.JsonCommandResult=ge,w.OutputItem=ee,w.PendingCommandResult=G,w.TextCommandResult=V,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|