citadel_cli 1.1.0 → 1.1.3
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/README.md +17 -19
- package/dist/App.d.ts +2 -0
- package/dist/citadel.css +1 -1
- package/dist/citadel.es.js +825 -812
- package/dist/citadel.umd.js +30 -15
- package/dist/{src/components → components}/Citadel/Citadel.d.ts +1 -1
- package/dist/{src/components → components}/Citadel/config/CitadelConfigContext.d.ts +9 -5
- package/dist/components/Citadel/config/hooks.d.ts +4 -0
- package/dist/{src/components → components}/Citadel/hooks/useCommandParser.d.ts +1 -1
- package/dist/{src/components → components}/Citadel/types/command-registry.d.ts +5 -1
- package/dist/{src/components → components}/Citadel/types/command-results.d.ts +2 -2
- package/dist/{src/components → components}/Citadel/types/help-command.d.ts +1 -1
- package/dist/{src/components → components}/Citadel/utils/logger.d.ts +5 -5
- package/dist/index.d.ts +4 -2
- package/package.json +10 -3
- package/dist/command_examples/basic-commands.d.ts +0 -2
- package/dist/dist/styles.css +0 -789
- package/dist/src/App.d.ts +0 -4
- package/dist/src/components/Citadel/commands/history-commands.d.ts +0 -2
- package/dist/src/components/Citadel/hooks/__tests__/useCommandTrie.test.d.ts +0 -1
- package/dist/src/components/Citadel/hooks/useCommandTrie.d.ts +0 -2
- package/dist/src/components/Citadel/types/__tests__/command-trie.test.d.ts +0 -1
- package/dist/src/components/Citadel/types/command-context.d.ts +0 -4
- package/dist/src/components/Citadel/types/command-trie.d.ts +0 -84
- package/dist/src/components/Citadel/utils/keySimulation.d.ts +0 -2
- package/dist/src/index.d.ts +0 -3
- /package/dist/{src/__test-utils__ → __test-utils__}/factories.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/Cursor.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/__tests__/Citadel.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/AvailableCommands.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/CommandInput.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/CommandOutput.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/CommandOutputLine.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/Spinner.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/__tests__/AvailableCommands.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/__tests__/CommandInput.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/__tests__/CommandOutput.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/__tests__/CommandOutputLine.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/components/__tests__/Spinner.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/config/__tests__/CitadelConfigContext.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/config/defaults.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/config/types.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/__tests__/useCitadelState.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/__tests__/useCommandHistory.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/__tests__/useCommandParser.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/useCitadelState.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/useCommandHistory.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/useGlobalShortcut.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/useSegmentStack.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/useSegmentStackVersion.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/hooks/useSlideAnimation.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/index.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/services/HistoryService.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/storage/BaseStorage.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/storage/LocalStorage.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/storage/MemoryStorage.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/storage/StorageFactory.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/storage/__tests__/LocalStorage.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/storage/__tests__/MemoryStorage.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/__tests__/command-registry.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/__tests__/segment-stack.test.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/cursor.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/index.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/segment-stack.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/state.d.ts +0 -0
- /package/dist/{src/components → components}/Citadel/types/storage.d.ts +0 -0
- /package/dist/{src/main.d.ts → main.d.ts} +0 -0
- /package/dist/{src/test → test}/setup.d.ts +0 -0
package/dist/citadel.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(T,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],i):(T=typeof globalThis<"u"?globalThis:T||self,i(T.Citadel={},T.React,T.ReactDOM))})(this,function(T,i,J){"use strict";var kt=Object.defineProperty;var Et=(T,i,J)=>i in T?kt(T,i,{enumerable:!0,configurable:!0,writable:!0,value:J}):T[i]=J;var R=(T,i,J)=>Et(T,typeof i!="symbol"?i+"":i,J);var ye={exports:{}},Z={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Oe;function kn(){if(Oe)return
|
|
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
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,25 +14,40 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
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=
|
|
18
|
-
`+ke+e}}var Ee=!1,ge;{var
|
|
19
|
-
`),F=
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
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
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
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
24
|
|
|
25
|
-
Check the top-level render call using <`+c+">.")}return
|
|
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
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,
|
|
31
|
-
`+
|
|
32
|
-
`):"No commands available yet. Add some commands to get started!")};var de=(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))(de||{});class I{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)}}A(I,"level",0),A(I,"prefix","");const U={commandTimeoutMs:1e4,cursorColor:"var(--cursor-color, #fff)",cursorSpeed:530,cursorType:"blink",includeHelpCommand:!0,initialHeight:"40vh",logLevel:process.env.NODE_ENV==="production"?de.ERROR:de.DEBUG,maxHeight:"80vh",minHeight:"200",outputFontSize:"0.875rem",resetStateOnHide:!1,showCitadelKey:".",storage:{type:"localStorage",maxCommands:100}};class Ue{constructor(n){A(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 Rn extends Ue{constructor(t){super(t);A(this,"storageKey","citadel_command_history")}async getStoredCommands(){try{const t=window.localStorage.getItem(this.storageKey);return t?JSON.parse(t).map(l=>({commandSegments:l.commandSegments||[],timestamp:l.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(l=>({commandSegments:Array.isArray(l.commandSegments)?[...l.commandSegments]:[],timestamp:l.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);A(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 B=class B{constructor(){A(this,"currentStorage")}static getInstance(){return B.instance||(B.instance=new B),B.instance}initializeStorage(n){if(!this.currentStorage)try{this.currentStorage=new Rn(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}};A(B,"instance");let me=B;const Me=async o=>new ve("");class xe{constructor(n,t,r){this.type=n,this.name=t,this.description=r}toString(){return this.name}}class He extends xe{constructor(){super("null",">null<","Empty segment")}}class In extends xe{constructor(n,t){super("word",n,t)}}class Nn extends xe{constructor(n,t,r,l){super("argument",n,t),this.value=r,this.valid=l}}class Dn{constructor(n,t,r=Me){A(this,"_segments");A(this,"_description");A(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 Ce{constructor(){A(this,"_commands",[])}get commands(){return this._commands}addCommand(n,t,r=Me){if(n===void 0||n.length===0)throw new Error("Command path cannot be empty");const l=new Dn(n,t,r),i=this._commands.find(p=>{const m=p.segments.map(g=>g.type==="argument"?"*":g.name).join(" "),d=n.map(g=>g.type==="argument"?"*":g.name).join(" ");return m===d});if(i)throw new Error(`Duplicate commands: '${i.fullPath_s}' and '${l.fullPath_s}'`);this._commands.push(l)}getCommand(n){return this._commands.find(t=>{const r=t.fullPath.join(" "),l=n.join(" ");return r===l})}commandExistsForPath(n){const t=this._commands.map(l=>l.segments.map(i=>i.type==="argument"?"*":i.name).join(" ")),r=n.map((l,i)=>this._commands.some(m=>{var d;return((d=m.segments[i])==null?void 0:d.type)==="argument"})?"*":l).join(" ");return t.includes(r)}getCompletions_s(n){return this.getCompletions(n).map(t=>t.name)}getCompletions(n){if(I.debug("[getCompletions] path: ",n),!n.length){const i=this._commands.map(d=>d.segments[0]),p=(d,g)=>d.type===g.type&&d.name===g.name;return i.filter((d,g,y)=>g===y.findIndex(h=>p(h,d)))}const t=n.length;return this._commands.filter(i=>{const p=i.segments;if(p.length<=t-1)return!1;for(let m=0;m<t;m++){const d=n[m],g=p[m];if(!(d==="*"&&g.type==="argument")&&d!==g.name)return!1}return!0}).filter(i=>i.segments.length>t).map(i=>{const p=i.segments[t],m=p.type==="argument"?Nn:In;return new m(p.name,p.description)}).filter((i,p,m)=>p===m.findIndex(d=>d.type===i.type&&d.name===i.name))}hasNextSegment(n){return this.getCompletions(n).length>0}}class $e{constructor(){A(this,"segments",[]);A(this,"nullSegment",new He);A(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 Ce,segmentStack:new $e},te=s.createContext(zn),Fn=({config:o=U,commands:n,children:t})=>{const[r,l]=s.useState(),i={...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||"."};s.useEffect(()=>{me.getInstance().initializeStorage(i.storage??U.storage),l(me.getInstance().getStorage())},[]),s.useEffect(()=>{if(n&&i.includeHelpCommand&&!n.commandExistsForPath(["help"])){const m=An(n);n.addCommand([{type:"word",name:"help"}],"Show available commands",m)}},[n,i.includeHelpCommand]);const p={config:i,commands:n||new Ce,storage:r,segmentStack:new $e};return f.jsx(te.Provider,{value:p,children:t})},re=()=>{const o=s.useContext(te);if(o===void 0)throw new Error("useCitadelConfig must be used within a CitadelConfigProvider");return o.config},fe=()=>{const o=s.useContext(te);if(o===void 0)throw new Error("useCitadelCommands must be used within a CitadelConfigProvider");return o.commands},We=()=>{const o=s.useContext(te);if(o===void 0)throw new Error("useCitadelStorage must be used within a CitadelConfigProvider");return o.storage},oe=()=>{const o=s.useContext(te);if(o===void 0)throw new Error("useSegmentStack must be used within a CitadelConfigProvider");return o.segmentStack};class Le{constructor(n,t){A(this,"timestamp");A(this,"command");A(this,"result");this.command=n.toArray().map(r=>r.type==="argument"?r.value||"":r.name),this.timestamp=Date.now(),this.result=t??new Fe}}const ae=()=>{const o=oe(),[n,t]=s.useState(0);return s.useEffect(()=>{const r={update:()=>{t(l=>l+1)}};return o.subscribe(r),()=>{o.unsubscribe(r)}},[o]),n};function Un(o){return{commandSegments:o,timestamp:Date.now()}}function Ye(){const o=We(),[n,t]=s.useState({storedCommands:[],position:null}),r=s.useCallback(async m=>{if(o)try{const d=Un(m);await o.addStoredCommand(d),t(g=>({...g,storedCommands:[...g.storedCommands,d],position:null}))}catch(d){console.warn("Failed to save command to history:",d)}},[o]),l=s.useCallback(async()=>o?await o.getStoredCommands():[],[o]);s.useEffect(()=>{if(!o)return;(async()=>{try{const d=await o.getStoredCommands();return t(g=>({...g,storedCommands:d})),d}catch(d){console.warn("Failed to load command history:",d)}})()},[o]);const i=s.useCallback(async m=>{if((await l()).length===0)return{segments:null,position:null};let g=null;return m==="up"?n.position===null?g=n.storedCommands.length-1:n.position>0?g=n.position-1:g=0:n.position===null||n.position>=n.storedCommands.length-1?g=null:g=n.position+1,t(h=>({...h,position:g})),g===null?{segments:[],position:null}:{segments:g!==null?n.storedCommands[g].commandSegments:null,position:g}},[n,ae]),p=s.useCallback(async()=>{try{if(!o)return;await o.clear(),t({storedCommands:[],position:null})}catch(m){console.warn("Failed to clear command history:",m)}},[o]);return{history:n,addStoredCommand:r,getStoredCommands:l,navigateHistory:i,clear:p}}const Ve=()=>{const o=re(),n=fe(),t=Ye(),r=oe(),l=ae(),i=We(),[p,m]=s.useState({currentInput:"",isEnteringArg:!1,output:[],history:{commands:[],position:null,storage:i}});s.useEffect(()=>{},[i]),s.useEffect(()=>{m(h=>({...h,history:{commands:t.history.storedCommands,position:t.history.position,storage:i}}))},[t.history,i]);const d={setCurrentInput:s.useCallback(h=>{I.debug("[CitadelActions] setCurrentInput: ",h),m(x=>({...x,currentInput:h}))},[]),setIsEnteringArg:s.useCallback(h=>{I.debug("[CitadelActions] setIsEnteringArg: ",h),m(x=>({...x,isEnteringArg:h}))},[]),addOutput:s.useCallback(h=>{I.debug("[CitadelActions]addOutput: ",h),m(x=>({...x,output:[...x.output,h]}))},[]),executeCommand:s.useCallback(async()=>{const h=r.path(),x=n.getCommand(h);if(!x){console.error("[CitadelActions][executeCommand] Cannot execute command because no command was found for the given path: ",h);return}const N=new Le(r);m(T=>({...T,output:[...T.output,N]}));try{const T=new Promise((u,b)=>{setTimeout(()=>{b(new Error("Request timed out"))},o.commandTimeoutMs)}),D=r.arguments.map(u=>u.value||""),M=await Promise.race([x.handler(D),T]);if(!(M instanceof K))throw new Error(`The ${h.join(".")} command returned an invalid result type. Commands must return an instance of a CommandResult.
|
|
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.
|
|
33
33
|
For example:
|
|
34
34
|
return new JsonCommandResult({ text: "Hello World" });
|
|
35
|
-
Check the definition of the ${h.join(".")} command and update the return type for its handler.`);M.markSuccess(),m(u=>({...u,output:u.output.map(b=>b.timestamp===N.timestamp?{...b,result:M}:b)}))}catch(T){const D=new ze(T instanceof Error?T.message:"Unknown error");D.markFailure(),m(M=>({...M,output:M.output.map(u=>u.timestamp===N.timestamp?{...u,result:D}:u)}))}},[n,o.commandTimeoutMs,l]),clearHistory:s.useCallback(async()=>{try{await t.clear()}catch(h){console.warn("Failed to clear history:",h)}},[t])},g=s.useCallback(()=>n.getCompletions_s(r.path()),[r,n]),y=s.useCallback(()=>n.getCompletions(r.path()),[r,n]);return{state:p,actions:d,getAvailableCommands_s:g,getAvailableCommandSegments:y}},Ke={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},Be=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],qe=["|","/","-","\\"],Mn=({style:o={type:"blink"},isValid:n=!0,errorMessage:t})=>{const r=s.useMemo(()=>({...Ke[o.type],...o}),[o]),[l,i]=s.useState(!0),[p,m]=s.useState(0);s.useEffect(()=>{if(r.speed===0)return;const y=setInterval(()=>{r.type==="blink"?i(h=>!h):["spin","bbs"].includes(r.type)&&m(h=>(h+1)%(r.type==="bbs"?qe.length:Be.length))},r.speed);return()=>clearInterval(y)},[r.type,r.speed]);const d=s.useMemo(()=>({color:n?r.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[n,r.color]),g=()=>!n&&t?"✗":["spin","bbs"].includes(r.type)?(r.type==="bbs"?qe:Be)[p]:r.type==="solid"||l?r.character:" ";return f.jsx("div",{className:"relative inline-block",children:f.jsx("span",{className:`command-cursor ${n?"":"animate-shake"}`,style:d,title:t,children:g()})})};function Hn(o,n){switch(n.type){case"set":return I.debug(`[inputStateReducer] InputState changing from ${o} to ${n.state}`),n.state;default:return o}}const $n=()=>{const{state:o}=Ve(),n=fe(),t=Ye(),r=oe(),l=ae(),[i,p]=s.useReducer(Hn,"idle"),m=u=>{p({type:"set",state:u})},d=()=>{const b=n.getCompletions(r.path())[0]||r.nullSegment;return I.debug("[getNextExpectedSegment] ",b),b},g=s.useCallback(()=>n.getCompletions_s(r.path()).map(b=>n.getCommand([...r.path(),b])).filter(b=>b!==void 0),[n]),y=s.useCallback((u,b)=>{if(!u)return b;const _=b.reduce((P,Y)=>{const z=d();return(z==null?void 0:z.type)==="word"&&P.set(z.name,Y),P},new Map);return Array.from(_.values()).filter(P=>{const Y=d();return Y.type!=="word"?!1:Y.name.toLowerCase().startsWith(u.toLowerCase())})},[]),h=s.useCallback(u=>{const _=n.getCompletions(r.path()).filter(C=>C.type==="word").filter(C=>C.name.toLowerCase().startsWith(u.toLowerCase()));return _.length===1?_[0]:r.nullSegment},[y]),x=s.useCallback(u=>{const b=r.path(),_=n.getCompletions(b);return _.length===0&&u?!1:_.some(C=>C.type==="argument")?!0:_.some(C=>C.type==="word"&&C.name.toLowerCase().startsWith(u.toLowerCase()))},[n]),N=s.useCallback(u=>{I.debug("[tryAutoComplete] input: ",u);const b=h(u);return!b||b.name===u?new He:(I.debug("[tryAutoComplete] result: ",b),b)},[g,h,r,n,d]),T=s.useCallback((u,b)=>{if(o.history.position===null){if(b.setCurrentInput(u),I.debug("[useCommandParser][handleInputChange] newValue: ",u),i==="entering_argument"){const _=Je(u);if(_.isQuoted)if(_.isComplete){const C=d();if(C.type==="argument"){const P=C;P.value=u.trim()||"",I.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",P),r.push(P),b.setCurrentInput(""),m("idle");return}}else return;else if(_.isComplete){const C=d();C.value=u.trim()||"",I.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",C),r.push(C),b.setCurrentInput(""),m("idle");return}else return}if(i=="entering_command"){const _=N(u);if(_.type==="word"){I.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",_),r.push(_),b.setCurrentInput(""),m("idle");return}}}},[N,l,o]),D=s.useCallback(async(u,b,_)=>{if(!(u.key==="Backspace"||u.key==="Enter"||u.key==="ArrowUp"||u.key==="ArrowDown"||u.key==="ArrowLeft"||u.key==="ArrowRight"||u.key==="Escape"||u.key==="Delete"||u.key==="Home"||u.key==="End"||u.key.length===1))return;const{currentInput:P,isEnteringArg:Y}=b,z=Je(P);switch(u.key){case"Backspace":{P===""&&(u.preventDefault(),r.size()>0&&r.pop(),m("idle"));return}case"Enter":{if(u.preventDefault(),z.isQuoted&&!z.isComplete)return;if(i==="entering_argument"){const V=d();V.value=P,I.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",V),r.push(V)}I.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",r),_.executeCommand(),t.addStoredCommand(r.toArray()),M(_);return}case"ArrowUp":{u.preventDefault();const $=await t.navigateHistory("up",r.toArray());$.segments&&(r.clear(),r.pushAll($.segments),_.setCurrentInput(""));return}case"ArrowDown":{u.preventDefault();const $=await t.navigateHistory("down",r.toArray());$.segments&&(r.clear(),r.pushAll($.segments),_.setCurrentInput(""));return}default:if(!Y&&u.key.length===1){const $=P+u.key;if(!x($)){u.preventDefault();return}}}},[n,y,g,h,i,x,l]),M=s.useCallback(u=>{u.setCurrentInput(""),u.setIsEnteringArg(!1),r.clear(),m("idle")},[]);return{handleInputChange:T,handleKeyDown:D,inputState:i,setInputStateWithLogging:m,findMatchingCommands:y,getAutocompleteSuggestion:h,getAvailableNodes:g,getNextExpectedSegment:d,isValidCommandInput:x}};function Je(o){const n=[];let t="",r=!1,l;for(let i=0;i<o.length;i++){const p=o[i];(p==='"'||p==="'")&&(!r||p===l)?r?(n.push(t),t="",r=!1,l=void 0):(t&&(n.push(t),t=""),r=!0,l=p):!r&&p===" "?t&&(n.push(t),t=""):t+=p}return{words:n,currentWord:t,isQuoted:r,quoteChar:l,isComplete:!r&&!t}}const Wn={invalidInput:"_invalidInput_e9b9w_12",shake:"_shake_e9b9w_1",flashBorder:"_flashBorder_e9b9w_1"},Ln=({state:o,actions:n})=>{const t=s.useRef(null),r=fe(),l=oe(),{handleKeyDown:i,handleInputChange:p,inputState:m,setInputStateWithLogging:d,getNextExpectedSegment:g}=$n(),[y]=s.useState(!1),h=re(),x=ae(),N=C=>{i(C,o,n)},T=C=>{p(C.target.value,n)},D=C=>{C.preventDefault();const P=C.clipboardData.getData("text");p(P,n)};s.useEffect(()=>{t.current&&t.current.focus(),m!=="entering_command"&&d("entering_command")},[]),s.useEffect(()=>{if(m!=="idle")return;const C=g();let P="idle";switch(C.type){case"word":P="entering_command",n.setIsEnteringArg(!1);break;case"argument":P="entering_argument",n.setIsEnteringArg(!0);break}I.debug(`[CommandInput] changing inputState to '${P}'`),d(P)},[x]);const[M,u]=s.useState([]);s.useEffect(()=>{const C=[],P=l.toArray().map((z,$)=>{C.push(z.name);const V=r.hasNextSegment(C);if(z.type==="argument"){let se=z;return f.jsxs(s.Fragment,{children:[f.jsx("span",{className:"text-gray-200 whitespace-pre",children:se.value}),$<l.size()&&V&&f.jsx("span",{className:"text-gray-200 whitespace-pre",children:" "})]},"arg-"+se.name+se.value)}return f.jsxs(s.Fragment,{children:[f.jsx("span",{className:"text-blue-400 whitespace-pre",children:z.name}),$<l.size()&&V&&f.jsx("span",{className:"text-blue-400 whitespace-pre",children:" "})]},"word-"+z.name)});u([f.jsx("div",{className:"flex items-center gap-1","data-testid":"user-input-area",children:P},"{segmentStackVersion}")])},[x]);const[b,_]=s.useState("");return s.useEffect(()=>{const C=g();C.type==="argument"?_(C.name):_("")},[x]),f.jsx("div",{className:"flex flex-col w-full bg-gray-900 rounded-lg p-4",children:f.jsxs("div",{className:"flex items-center gap-2",children:[f.jsx("div",{className:"text-gray-400 font-mono",children:">"}),f.jsxs("div",{className:"flex-1 font-mono flex items-center",children:[M,f.jsxs("div",{className:"relative flex-1",children:[f.jsx("input",{ref:t,type:"text",role:"textbox",value:o.currentInput,onChange:T,onKeyDown:N,onPaste:D,"data-testid":"citadel-command-input",className:`w-full bg-transparent outline-none text-gray-200 caret-transparent ${y?Wn.invalidInput:""}`,spellCheck:!1,autoComplete:"off",placeholder:b}),f.jsx("div",{className:"absolute top-0 pointer-events-none",style:{left:`${o.currentInput.length}ch`,transition:"left 0.05s ease-out"},children:f.jsx(Mn,{style:{type:h.cursorType??U.cursorType,color:h.cursorColor||U.cursorColor,speed:h.cursorSpeed||U.cursorSpeed}})})]})]})]})})},Yn=()=>f.jsx("div",{"data-testid":"spinner",className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"}),Vn=({command:o,timestamp:n,status:t})=>f.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm",children:[f.jsxs("span",{className:"text-gray-200",children:["> ",o.split(" ").map((r,l)=>{const i=r.startsWith("<")&&r.endsWith(">");return f.jsxs("span",{className:i?"text-green-400":"text-gray-200",children:[l>0?" ":"",r]},l)})]}),f.jsx("span",{className:"text-gray-400",children:"·"}),f.jsx("span",{className:"text-gray-500",children:n}),t===X.Pending&&f.jsx(Yn,{}),t===X.Success&&f.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-green-500"}),(t===X.Timeout||t===X.Failure)&&f.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-red-500"})]}),Kn=({output:o,outputRef:n})=>{const t=re(),r=s.useCallback(()=>{if(n.current){const l=n.current;requestAnimationFrame(()=>{l.scrollTop=l.scrollHeight})}},[n]);return s.useEffect(()=>{if(r(),n.current){const l=n.current.getElementsByTagName("img"),i=l[l.length-1];if(i&&!i.complete)return i.addEventListener("load",r),()=>i.removeEventListener("load",r)}},[o,r]),f.jsx("div",{ref:n,className:"h-full overflow-y-auto border border-gray-700 rounded-lg p-3 text-left",children:o.map((l,i)=>f.jsxs("div",{className:"mb-4 last:mb-0",children:[f.jsx(Vn,{command:l.command.join(" "),timestamp:new Date(l.timestamp).toLocaleTimeString(),status:l.result.status}),f.jsx("pre",{className:`text-gray-200 whitespace-pre font-mono ${t.outputFontSize}`,children:l.result.render()})]},i))})},Bn=()=>{const o=fe(),n=re(),t=oe(),r=ae(),l="h-12 mt-2 border-t border-gray-700 px-4",i="text-gray-300 pt-2",p=o.getCompletions(t.path());I.debug("[AvailableCommands] nextCommandSegments: ",p);const m=s.useMemo(()=>{if(n.includeHelpCommand){const y=p.filter(x=>x.name!=="help"),h=p.find(x=>x.name==="help");return[...y,...h?[h]:[]]}return p},[p,r,n.includeHelpCommand]),d=p.some(y=>y.type==="argument"),g=p[0];return f.jsx("div",{className:l,"data-testid":"available-commands",children:f.jsx("div",{className:i,children:d?p.length>0?f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"text-blue-400",children:g.name}),g.description&&f.jsxs("span",{className:"text-gray-400 ml-2",children:["- ",g.description]})]}):null:f.jsx("div",{className:"flex flex-wrap gap-2",children:m==null?void 0:m.map(y=>{const h=m==null?void 0:m.reduce((x,N)=>{if(N===y)return x;let T=0;for(;T<y.name.length&&T<N.name.length&&y.name[T].toLowerCase()===N.name[T].toLowerCase();)T++;return Math.max(x,T+1)},1);return f.jsx("div",{className:"px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",children:f.jsxs("span",{className:"font-mono text-white",children:[f.jsx("strong",{className:"underline",children:y.name.slice(0,h)}),y.name.slice(h)]})},y.name)})})})})},Ge=`:host {
|
|
35
|
+
Check the definition of the ${g.join(".")} command and update the return type for its handler.`);z.markSuccess(),d(m=>({...m,output:m.output.map(v=>v.timestamp===j.timestamp?{...v,result:z}:v)}))}catch(k){const H=new ze(k instanceof Error?k.message:"Unknown error");H.markFailure(),d(z=>({...z,output:z.output.map(m=>m.timestamp===j.timestamp?{...m,result:H}:m)}))}},[n,o.commandTimeoutMs,r]),clearHistory:i.useCallback(async()=>{try{await t.clear()}catch(g){console.warn("Failed to clear history:",g)}},[t])},u=i.useCallback(()=>n.getCompletions_s(r.path()),[r,n]),f=i.useCallback(()=>n.getCompletions(r.path()),[r,n]);return{state:l,actions:h,getAvailableCommands_s:u,getAvailableCommandSegments:f}},Ke={blink:{character:"▋",speed:530,color:"#fff"},spin:{character:"⠋",speed:120,color:"#fff"},solid:{character:"▋",speed:0,color:"#fff"},bbs:{character:"|",speed:120,color:"#fff"}},Be=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],qe=["|","/","-","\\"],Hn=({style:o={type:"blink"},isValid:n=!0,errorMessage:t})=>{const r=i.useMemo(()=>({...Ke[o.type],...o}),[o]),[a,l]=i.useState(!0),[d,h]=i.useState(0);i.useEffect(()=>{if(r.speed===0)return;const g=setInterval(()=>{r.type==="blink"?l(w=>!w):["spin","bbs"].includes(r.type)&&h(w=>(w+1)%(r.type==="bbs"?qe.length:Be.length))},r.speed);return()=>clearInterval(g)},[r.type,r.speed]);const u=i.useMemo(()=>({color:n?r.color:"#ff4444",transition:"color 0.15s ease-in-out"}),[n,r.color]),f=()=>!n&&t?"✗":["spin","bbs"].includes(r.type)?(r.type==="bbs"?qe:Be)[d]:r.type==="solid"||a?r.character:" ";return p.jsx("div",{className:"relative inline-block",children:p.jsx("span",{className:`command-cursor ${n?"":"animate-shake"}`,style:u,title:t,children:f()})})};function Mn(o,n){switch(n.type){case"set":return D.debug(`[inputStateReducer] InputState changing from ${o} to ${n.state}`),n.state;default:return o}}const $n=()=>{const{state:o}=Ve(),n=fe(),t=Ye(),r=re(),[a,l]=i.useReducer(Mn,"idle"),d=m=>{l({type:"set",state:m})},h=i.useCallback(()=>{const v=n.getCompletions(r.path())[0]||r.nullSegment;return D.debug("[getNextExpectedSegment] ",v),v},[n,r]),u=i.useCallback(()=>n.getCompletions_s(r.path()).map(v=>n.getCommand([...r.path(),v])).filter(v=>v!==void 0),[n,r]),f=i.useCallback((m,v)=>{if(!m)return v;const y=v.reduce((_,P)=>{const A=h();return(A==null?void 0:A.type)==="word"&&_.set(A.name,P),_},new Map);return Array.from(y.values()).filter(()=>{const _=h();return _.type!=="word"?!1:_.name.toLowerCase().startsWith(m.toLowerCase())})},[h]),g=i.useCallback(m=>{const y=n.getCompletions(r.path()).filter(N=>N.type==="word").filter(N=>N.name.toLowerCase().startsWith(m.toLowerCase()));return y.length===1?y[0]:r.nullSegment},[n,r]),w=i.useCallback(m=>{const v=r.path(),y=n.getCompletions(v);return y.length===0&&m?!1:y.some(_=>_.type==="argument")?!0:y.some(_=>_.type==="word"&&_.name.toLowerCase().startsWith(m.toLowerCase()))},[n,r]),j=i.useCallback(m=>{D.debug("[tryAutoComplete] input: ",m);const v=g(m);return!v||v.name===m?new Me:(D.debug("[tryAutoComplete] result: ",v),v)},[g]),k=i.useCallback((m,v)=>{if(o.history.position===null){if(v.setCurrentInput(m),D.debug("[useCommandParser][handleInputChange] newValue: ",m),a==="entering_argument"){const y=Je(m);if(y.isQuoted)if(y.isComplete){const N=h();if(N.type==="argument"){const _=N;_.value=m.trim()||"",D.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",_),r.push(_),v.setCurrentInput(""),d("idle");return}}else return;else if(y.isComplete){const N=h();N.value=m.trim()||"",D.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",N),r.push(N),v.setCurrentInput(""),d("idle");return}else return}if(a=="entering_command"){const y=j(m);if(y.type==="word"){D.debug("[useCommandParser][handleInputChange][entering_command] pushing: ",y),r.push(y),v.setCurrentInput(""),d("idle");return}}}},[j,o,h,a,r]),H=i.useCallback(m=>{m.setCurrentInput(""),m.setIsEnteringArg(!1),r.clear(),d("idle")},[r]),z=i.useCallback((m,v,y)=>{if(!(m.key==="Backspace"||m.key==="Enter"||m.key==="ArrowUp"||m.key==="ArrowDown"||m.key==="ArrowLeft"||m.key==="ArrowRight"||m.key==="Escape"||m.key==="Delete"||m.key==="Home"||m.key==="End"||m.key.length===1))return!0;const{currentInput:_,isEnteringArg:P}=v,A=Je(_);switch(m.key){case"Backspace":return _===""&&(m.preventDefault(),r.size()>0&&r.pop(),d("idle")),!0;case"Enter":{if(m.preventDefault(),A.isQuoted&&!A.isComplete)return!0;if(a==="entering_argument"){const L=h();L.value=_,D.debug("[handleKeyDown][Enter]['entering_argument'] pushing: ",L),r.push(L)}return D.debug("[handleKeyDown][Enter] calling actions.executeCommand. segmentStack: ",r),y.executeCommand(),t.addStoredCommand(r.toArray()),H(y),!0}case"ArrowUp":return m.preventDefault(),(async()=>{const $=await t.navigateHistory("up",r.toArray());return $.segments&&(r.clear(),r.pushAll($.segments),y.setCurrentInput("")),!0})();case"ArrowDown":return m.preventDefault(),(async()=>{const $=await t.navigateHistory("down",r.toArray());return $.segments&&(r.clear(),r.pushAll($.segments),y.setCurrentInput("")),!0})();default:{if(!P&&m.key.length===1){const $=_+m.key;if(!w($))return m.preventDefault(),!1}return!0}}},[a,w,h,t,H,r]);return{handleInputChange:k,handleKeyDown:z,inputState:a,setInputStateWithLogging:d,findMatchingCommands:f,getAutocompleteSuggestion:g,getAvailableNodes:u,getNextExpectedSegment:h,isValidCommandInput:w}};function Je(o){const n=[];let t="",r=!1,a;for(let l=0;l<o.length;l++){const d=o[l];(d==='"'||d==="'")&&(!r||d===a)?r?(n.push(t),t="",r=!1,a=void 0):(t&&(n.push(t),t=""),r=!0,a=d):!r&&d===" "?t&&(n.push(t),t=""):t+=d}return{words:n,currentWord:t,isQuoted:r,quoteChar:a,isComplete:!r&&!t}}const Wn=()=>{const o=re(),[n,t]=i.useState(0);return i.useEffect(()=>{const r={update:()=>{t(a=>a+1)}};return o.subscribe(r),()=>{o.unsubscribe(r)}},[o]),n},Ln=({state:o,actions:n})=>{const t=i.useRef(null),r=fe(),a=re(),{handleKeyDown:l,handleInputChange:d,inputState:h,setInputStateWithLogging:u,getNextExpectedSegment:f}=$n(),[g,w]=i.useState(!1),j=te(),k=Wn(),H=async P=>{const A=l(P,o,n);await Promise.resolve(A)===!1&&(w(!0),setTimeout(()=>w(!1),500))},z=P=>{d(P.target.value,n)},m=P=>{P.preventDefault();const A=P.clipboardData.getData("text");d(A,n)};i.useEffect(()=>{t.current&&t.current.focus(),h!=="entering_command"&&u("entering_command")},[h,u]),i.useEffect(()=>{if(h!=="idle")return;const P=f();let A="idle";switch(P.type){case"word":A="entering_command",n.setIsEnteringArg(!1);break;case"argument":A="entering_argument",n.setIsEnteringArg(!0);break}u(A)},[k,h,f,u,n]);const[v,y]=i.useState([]);i.useEffect(()=>{const P=[],A=a.toArray().map((L,oe)=>{P.push(L.name);const pe=r.hasNextSegment(P);if(L.type==="argument"){const ae=L;return p.jsxs(i.Fragment,{children:[p.jsx("span",{className:"text-gray-200 whitespace-pre",children:ae.value}),oe<a.size()&&pe&&p.jsx("span",{className:"text-gray-200 whitespace-pre",children:" "})]},"arg-"+ae.name+ae.value)}return p.jsxs(i.Fragment,{children:[p.jsx("span",{className:"text-blue-400 whitespace-pre",children:L.name}),oe<a.size()&&pe&&p.jsx("span",{className:"text-blue-400 whitespace-pre",children:" "})]},"word-"+L.name)});y([p.jsx("div",{className:"flex items-center gap-1","data-testid":"user-input-area",children:A},"{segmentStackVersion}")])},[k,r,a]);const[N,_]=i.useState("");return i.useEffect(()=>{const P=f();P.type==="argument"?_(P.name):_("")},[k,f]),p.jsxs("div",{className:"flex flex-col w-full bg-gray-900 rounded-lg p-4",children:[p.jsx("style",{children:`
|
|
36
|
+
@keyframes shake {
|
|
37
|
+
0%, 100% { transform: translateX(0); }
|
|
38
|
+
25% { transform: translateX(-4px); }
|
|
39
|
+
75% { transform: translateX(4px); }
|
|
40
|
+
}
|
|
41
|
+
@keyframes flashBorder {
|
|
42
|
+
0%, 100% { border-color: transparent; }
|
|
43
|
+
50% { border-color: rgb(239, 68, 68); }
|
|
44
|
+
}
|
|
45
|
+
.invalid-input-animation {
|
|
46
|
+
animation: shake 0.2s ease-in-out, flashBorder 0.3s ease-in-out;
|
|
47
|
+
border-width: 1px;
|
|
48
|
+
border-style: solid;
|
|
49
|
+
}
|
|
50
|
+
`}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("div",{className:"text-gray-400 font-mono",children:">"}),p.jsxs("div",{className:"flex-1 font-mono flex items-center",children:[v,p.jsxs("div",{className:"relative flex-1",children:[p.jsx("input",{ref:t,type:"text",role:"textbox",value:o.currentInput,onChange:z,onKeyDown:H,onPaste:m,"data-testid":"citadel-command-input",className:`w-full bg-transparent outline-none text-gray-200 caret-transparent ${g?"invalid-input-animation":""}`,spellCheck:!1,autoComplete:"off",placeholder:N}),p.jsx("div",{className:"absolute top-0 pointer-events-none",style:{left:`${o.currentInput.length}ch`,transition:"left 0.05s ease-out"},children:p.jsx(Hn,{style:{type:j.cursorType??U.cursorType,color:j.cursorColor||U.cursorColor,speed:j.cursorSpeed||U.cursorSpeed}})})]})]})]})]})},Yn=()=>p.jsx("div",{"data-testid":"spinner",className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-gray-600"}),Vn=({command:o,timestamp:n,status:t})=>p.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm",children:[p.jsxs("span",{className:"text-gray-200",children:["> ",o.split(" ").map((r,a)=>{const l=r.startsWith("<")&&r.endsWith(">");return p.jsxs("span",{className:l?"text-green-400":"text-gray-200",children:[a>0?" ":"",r]},a)})]}),p.jsx("span",{className:"text-gray-400",children:"·"}),p.jsx("span",{className:"text-gray-500",children:n}),t===G.Pending&&p.jsx(Yn,{}),t===G.Success&&p.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-green-500"}),(t===G.Timeout||t===G.Failure)&&p.jsx("div",{"data-testid":"success-indicator",className:"w-4 h-4 rounded-full bg-red-500"})]}),Kn=({output:o,outputRef:n})=>{const t=te(),r=i.useCallback(()=>{if(n.current){const a=n.current;requestAnimationFrame(()=>{a.scrollTop=a.scrollHeight})}},[n]);return i.useEffect(()=>{if(r(),n.current){const a=n.current.getElementsByTagName("img"),l=a[a.length-1];if(l&&!l.complete)return l.addEventListener("load",r),()=>l.removeEventListener("load",r)}},[o,r,n]),p.jsx("div",{ref:n,className:"h-full overflow-y-auto border border-gray-700 rounded-lg p-3 text-left",children:o.map((a,l)=>p.jsxs("div",{className:"mb-4 last:mb-0",children:[p.jsx(Vn,{command:a.command.join(" "),timestamp:new Date(a.timestamp).toLocaleTimeString(),status:a.result.status}),p.jsx("pre",{className:`text-gray-200 whitespace-pre font-mono ${t.outputFontSize}`,children:a.result.render()})]},l))})},Bn=()=>{const o=fe(),n=te(),t=re(),r="h-12 mt-2 border-t border-gray-700 px-4",a="text-gray-300 pt-2",l=o.getCompletions(t.path());D.debug("[AvailableCommands] nextCommandSegments: ",l);const d=i.useMemo(()=>{if(n.includeHelpCommand){const f=l.filter(w=>w.name!=="help"),g=l.find(w=>w.name==="help");return[...f,...g?[g]:[]]}return l},[l,n.includeHelpCommand]),h=l.some(f=>f.type==="argument"),u=l[0];return p.jsx("div",{className:r,"data-testid":"available-commands",children:p.jsx("div",{className:a,children:h?l.length>0?p.jsxs(p.Fragment,{children:[p.jsx("span",{className:"text-blue-400",children:u.name}),u.description&&p.jsxs("span",{className:"text-gray-400 ml-2",children:["- ",u.description]})]}):null:p.jsx("div",{className:"flex flex-wrap gap-2",children:d==null?void 0:d.map(f=>{const g=d==null?void 0:d.reduce((w,j)=>{if(j===f)return w;let k=0;for(;k<f.name.length&&k<j.name.length&&f.name[k].toLowerCase()===j.name[k].toLowerCase();)k++;return Math.max(w,k+1)},1);return p.jsx("div",{className:"px-2 py-1 rounded bg-gray-800 mr-2 last:mr-0",children:p.jsxs("span",{className:"font-mono text-white",children:[p.jsx("strong",{className:"underline",children:f.name.slice(0,g)}),f.name.slice(g)]})},f.name)})})})})},Ge=`:host {
|
|
36
51
|
--citadel-bg: rgb(17, 24, 39);
|
|
37
52
|
--citadel-text: rgba(255, 255, 255, 0.87);
|
|
38
53
|
--citadel-border: rgb(55, 65, 81);
|
|
@@ -1011,5 +1026,5 @@ video {
|
|
|
1011
1026
|
.last\\:mr-0:last-child {
|
|
1012
1027
|
margin-right: 0px;
|
|
1013
1028
|
}
|
|
1014
|
-
`,Jn=({config:o=U,commandRegistry:n=new
|
|
1015
|
-
`),
|
|
1029
|
+
`,Jn=({config:o=U,commandRegistry:n=new me,containerId:t=null})=>(i.useEffect(()=>{D.configure({level:o.logLevel||U.logLevel||ue.ERROR,prefix:"[Citadel]"});const r=new Ze(n,o),a=t?document.getElementById(t):document.body;return a?a.appendChild(r):(console.warn(`Container with id "${t}" not found, falling back to body`),document.body.appendChild(r)),()=>{var l;(l=r.parentElement)==null||l.removeChild(r)}},[n,t,o]),null);class Ze extends HTMLElement{constructor(t,r){super();R(this,"shadow");R(this,"root",null);R(this,"commandRegistry");R(this,"config");this.shadow=this.attachShadow({mode:"open"}),this.commandRegistry=t,this.config=r}connectedCallback(){try{const r=[Ge,Xe,Qe,qn].map(a=>{const l=new CSSStyleSheet;return l.replaceSync(a),l});this.shadow.adoptedStyleSheets=[...r]}catch{const r=[Ge,Xe,Qe].join(`
|
|
1030
|
+
`),a=document.createElement("style");a.textContent=r,this.shadow.appendChild(a)}const t=document.createElement("div");t.id="citadel-root",this.shadow.appendChild(t),this.root=ve(t),this.root.render(p.jsx(Fn,{config:this.config||U,commandRegistry:this.commandRegistry,children:p.jsx(Gn,{})}))}}customElements.define("citadel-element",Ze);const Gn=()=>{const[o,n]=i.useState(!1),[t,r]=i.useState(!1),a=te(),[l,d]=i.useState(()=>a.initialHeight||null),h=i.useRef(null),u=i.useRef(null),f=i.useRef(!1),g=i.useRef(0),w=i.useRef(0),{state:j,actions:k}=Ve();_n({onOpen:()=>n(!0),onClose:()=>r(!0),isVisible:o,showCitadelKey:a.showCitadelKey||"."});const H=i.useCallback(y=>{u.current&&(f.current=!0,g.current=y.clientY,w.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",z),document.addEventListener("mouseup",m))},[]),z=i.useCallback(y=>{var A;if(!f.current)return;const N=y.clientY-g.current,_=(A=a.maxHeight)!=null&&A.endsWith("vh")?window.innerHeight*parseInt(a.maxHeight,10)/100:parseInt(a.maxHeight||"80vh",10),P=Math.min(Math.max(w.current-N,parseInt(a.minHeight||"200",10)),_);u.current&&(u.current.style.height=`${P}px`,u.current.style.bottom="0",d(`${P}px`))},[a.maxHeight,a.minHeight]),m=i.useCallback(()=>{f.current=!1,document.documentElement.style.userSelect="",document.documentElement.style.webkitUserSelect="",document.documentElement.style.mozUserSelect="",document.documentElement.style.msUserSelect="",document.removeEventListener("mousemove",z),document.removeEventListener("mouseup",m)},[z]);i.useEffect(()=>()=>{document.removeEventListener("mousemove",z),document.removeEventListener("mouseup",m)},[z,m]);const v=i.useCallback(()=>{t&&(n(!1),r(!1))},[t]);return jn({isVisible:o,isClosing:t,onAnimationComplete:v}),o?p.jsxs("div",{ref:u,className:`container ${o?"citadel_slideUp":""} ${t?"citadel_slideDown":""}`,style:{...l?{height:l}:void 0,maxHeight:a.maxHeight},children:[p.jsx("div",{className:"resizeHandle",onMouseDown:H}),p.jsxs("div",{className:"innerContainer",children:[p.jsx("div",{className:"flex-1 min-h-0 pt-3 px-4",children:p.jsx(Kn,{output:j.output,outputRef:h})}),p.jsxs("div",{children:[p.jsx(Ln,{state:j,actions:k}),p.jsx(Bn,{})]})]})]}):null};T.Citadel=Jn,T.CommandRegistry=me,T.CommandResult=V,T.CommandStatus=G,T.DEFAULT_CURSOR_CONFIGS=Ke,T.ErrorCommandResult=ze,T.ImageCommandResult=Pn,T.JsonCommandResult=Tn,T.OutputItem=Le,T.PendingCommandResult=Fe,T.TextCommandResult=xe,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -8,7 +8,7 @@ export declare const Citadel: ({ config, commandRegistry, containerId }: {
|
|
|
8
8
|
export declare class CitadelElement extends HTMLElement {
|
|
9
9
|
private shadow;
|
|
10
10
|
private root;
|
|
11
|
-
private
|
|
11
|
+
private commandRegistry?;
|
|
12
12
|
private config?;
|
|
13
13
|
constructor(commandRegistry: CommandRegistry, config?: CitadelConfig);
|
|
14
14
|
connectedCallback(): void;
|
|
@@ -3,12 +3,16 @@ import { CitadelConfig } from './types';
|
|
|
3
3
|
import { CommandStorage } from '../types/storage';
|
|
4
4
|
import { CommandRegistry } from '../types/command-registry';
|
|
5
5
|
import { SegmentStack } from '../types/segment-stack';
|
|
6
|
+
interface CitadelContextValue {
|
|
7
|
+
config: CitadelConfig;
|
|
8
|
+
commands: CommandRegistry;
|
|
9
|
+
storage?: CommandStorage;
|
|
10
|
+
segmentStack: SegmentStack;
|
|
11
|
+
}
|
|
12
|
+
declare const CitadelConfigContext: React.Context<CitadelContextValue>;
|
|
13
|
+
export { CitadelConfigContext };
|
|
6
14
|
export declare const CitadelConfigProvider: React.FC<{
|
|
7
15
|
config?: CitadelConfig;
|
|
8
|
-
|
|
16
|
+
commandRegistry?: CommandRegistry;
|
|
9
17
|
children: React.ReactNode;
|
|
10
18
|
}>;
|
|
11
|
-
export declare const useCitadelConfig: () => CitadelConfig;
|
|
12
|
-
export declare const useCitadelCommands: () => CommandRegistry;
|
|
13
|
-
export declare const useCitadelStorage: () => CommandStorage | undefined;
|
|
14
|
-
export declare const useSegmentStack: () => SegmentStack;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const useCitadelConfig: () => import('./types').CitadelConfig;
|
|
2
|
+
export declare const useCitadelCommands: () => import('../types/command-registry').CommandRegistry;
|
|
3
|
+
export declare const useCitadelStorage: () => import('../types/storage').CommandStorage | undefined;
|
|
4
|
+
export declare const useSegmentStack: () => import('../types/segment-stack').SegmentStack;
|
|
@@ -3,7 +3,7 @@ import { CitadelState, CitadelActions } from '../types/state';
|
|
|
3
3
|
export type InputState = 'idle' | 'entering_command' | 'entering_argument';
|
|
4
4
|
export declare const useCommandParser: () => {
|
|
5
5
|
handleInputChange: (newValue: string, actions: CitadelActions) => void;
|
|
6
|
-
handleKeyDown: (e: KeyboardEvent | React.KeyboardEvent, state: CitadelState, actions: CitadelActions) => Promise<
|
|
6
|
+
handleKeyDown: (e: KeyboardEvent | React.KeyboardEvent, state: CitadelState, actions: CitadelActions) => boolean | Promise<boolean>;
|
|
7
7
|
inputState: InputState;
|
|
8
8
|
setInputStateWithLogging: (newState: InputState) => void;
|
|
9
9
|
findMatchingCommands: (input: string, availableNodes: CommandNode[]) => CommandNode[];
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { CommandResult } from './command-results';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A callback function that executes a command and returns a Promise of CommandResult.
|
|
4
|
+
* Similar to a lambda in Ruby, this is a first-class function that can be passed
|
|
5
|
+
* as an argument and stored as a variable.
|
|
6
|
+
*/
|
|
3
7
|
export type CommandHandler = (args: string[]) => Promise<CommandResult>;
|
|
4
8
|
/**
|
|
5
9
|
* A no-op handler that returns an empty string. Used as the default handler
|
|
@@ -16,8 +16,8 @@ export declare abstract class CommandResult {
|
|
|
16
16
|
abstract render(): React.ReactNode;
|
|
17
17
|
}
|
|
18
18
|
export declare class JsonCommandResult extends CommandResult {
|
|
19
|
-
readonly data:
|
|
20
|
-
constructor(data:
|
|
19
|
+
readonly data: unknown;
|
|
20
|
+
constructor(data: unknown, timestamp?: number);
|
|
21
21
|
render(): React.ReactNode;
|
|
22
22
|
}
|
|
23
23
|
export declare class TextCommandResult extends CommandResult {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { CommandRegistry } from './command-registry';
|
|
2
2
|
import { TextCommandResult } from './command-results';
|
|
3
|
-
export declare const createHelpHandler: (cmdRegistry: CommandRegistry) => (
|
|
3
|
+
export declare const createHelpHandler: (cmdRegistry: CommandRegistry) => () => Promise<TextCommandResult>;
|
|
@@ -13,9 +13,9 @@ export declare class Logger {
|
|
|
13
13
|
level: LogLevel;
|
|
14
14
|
prefix?: string;
|
|
15
15
|
}): void;
|
|
16
|
-
static trace(...args:
|
|
17
|
-
static debug(...args:
|
|
18
|
-
static info(...args:
|
|
19
|
-
static warn(...args:
|
|
20
|
-
static error(...args:
|
|
16
|
+
static trace(...args: unknown[]): void;
|
|
17
|
+
static debug(...args: unknown[]): void;
|
|
18
|
+
static info(...args: unknown[]): void;
|
|
19
|
+
static warn(...args: unknown[]): void;
|
|
20
|
+
static error(...args: unknown[]): void;
|
|
21
21
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {}
|
|
1
|
+
export { Citadel } from './components/Citadel/Citadel';
|
|
2
|
+
export { CommandRegistry } from './components/Citadel/types/command-registry';
|
|
3
|
+
export type { CitadelConfig } from './components/Citadel/config/types';
|
|
4
|
+
export * from './components/Citadel/types';
|
package/package.json
CHANGED
|
@@ -8,19 +8,24 @@
|
|
|
8
8
|
"interface",
|
|
9
9
|
"console"
|
|
10
10
|
],
|
|
11
|
-
"author":
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "James Childers",
|
|
13
|
+
"email": "james.childers@gmail.com"
|
|
14
|
+
},
|
|
12
15
|
"license": "MIT",
|
|
13
16
|
"repository": {
|
|
14
17
|
"type": "git",
|
|
15
18
|
"url": "git+https://github.com/jchilders/citadel_cli.git"
|
|
16
19
|
},
|
|
17
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.3",
|
|
18
21
|
"type": "module",
|
|
19
22
|
"scripts": {
|
|
20
23
|
"build": "tsc && vite build",
|
|
21
24
|
"dev": "vite",
|
|
22
25
|
"lint": "eslint .",
|
|
26
|
+
"lint:fix": "eslint . --fix",
|
|
23
27
|
"preview": "vite preview",
|
|
28
|
+
"push": "NODE_ENV=production && npm run build && npm push",
|
|
24
29
|
"test": "vitest --run",
|
|
25
30
|
"coverage": "vitest run --coverage"
|
|
26
31
|
},
|
|
@@ -41,7 +46,9 @@
|
|
|
41
46
|
"dist"
|
|
42
47
|
],
|
|
43
48
|
"dependencies": {
|
|
44
|
-
"lucide-react": "^0.460.0"
|
|
49
|
+
"lucide-react": "^0.460.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
45
52
|
"react": "^18.2.0",
|
|
46
53
|
"react-dom": "^18.2.0"
|
|
47
54
|
},
|