@nice2dev/ui 1.3.6 → 1.3.8
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/CHANGELOG.md +54 -0
- package/dist/NiceCodeEditor-B5YtKZOe.js +1222 -0
- package/dist/NiceCodeEditor-D0QZW88r.cjs +268 -0
- package/dist/NiceColorPicker-Bzvei7D6.cjs +1 -0
- package/dist/NiceColorPicker-DzzJhSXT.js +552 -0
- package/dist/NiceDataGrid-BSaBBoNr.js +2267 -0
- package/dist/NiceDataGrid-C_E6zIGS.cjs +10 -0
- package/dist/NiceForm-D2P6XuaT.cjs +1 -0
- package/dist/NiceForm-_kaB4Ikt.js +5017 -0
- package/dist/NiceHtmlEditor-CBCJdjmy.cjs +10 -0
- package/dist/NiceHtmlEditor-DfkdSxL3.js +901 -0
- package/dist/NiceLoginForm-BFvbroGJ.js +820 -0
- package/dist/NiceLoginForm-FGf32sro.cjs +1 -0
- package/dist/NiceMention-CctjYriS.cjs +430 -0
- package/dist/NiceMention-umOghLCf.js +11653 -0
- package/dist/NiceModal-BRVzjuUN.cjs +1 -0
- package/dist/NiceModal-CU9FqzIH.js +83 -0
- package/dist/NiceModuleLifecyclePanel-DQT_forg.js +7404 -0
- package/dist/NiceModuleLifecyclePanel-DtOlPChV.cjs +1 -0
- package/dist/NicePagination-CK4ZJgu4.cjs +1 -0
- package/dist/NicePagination-flHgG-FT.js +200 -0
- package/dist/NicePivotGrid-99ZeQ9j6.js +1180 -0
- package/dist/NicePivotGrid-CpsBxUhq.cjs +152 -0
- package/dist/NiceSavedQueryPanel-Br1LQR7u.js +5311 -0
- package/dist/NiceSavedQueryPanel-C4SU6W22.cjs +586 -0
- package/dist/NiceScheduler-CeYqH0Ux.cjs +5 -0
- package/dist/NiceScheduler-yTpVRxfe.js +1710 -0
- package/dist/NiceSelect-C3NqDYwR.js +495 -0
- package/dist/NiceSelect-CTwSAb8G.cjs +1 -0
- package/dist/charts-B0tHOpJ7.cjs +768 -0
- package/dist/charts-C3u-VyJj.js +5019 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.mjs +1 -1
- package/dist/core-lazy-Bglo0hFt.cjs +1 -0
- package/dist/core-lazy-CRBgQkQl.js +351 -0
- package/dist/data.cjs +1 -1
- package/dist/data.mjs +3 -3
- package/dist/devops-Bzp3ZqZ3.cjs +18 -0
- package/dist/devops-fLElpPvD.js +9128 -0
- package/dist/devops.cjs +1 -1
- package/dist/devops.mjs +1 -1
- package/dist/editors.cjs +1 -1
- package/dist/editors.d.ts +5 -0
- package/dist/editors.mjs +7 -7
- package/dist/feedback.cjs +1 -1
- package/dist/feedback.mjs +3 -3
- package/dist/index.cjs +251 -251
- package/dist/index.d.ts +76 -9
- package/dist/index.mjs +15550 -15248
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.mjs +18 -18
- package/dist/navigation.cjs +1 -1
- package/dist/navigation.d.ts +42 -3
- package/dist/navigation.mjs +2 -2
- package/dist/no-code-Bt7SWzsN.js +8318 -0
- package/dist/no-code-DnT061qn.cjs +331 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.mjs +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),h=require("@nice2dev/ui-core"),n=require("react"),ue=require("./injectStyleOnce-DeWaxcdf.cjs"),qe=[{target:".nice-code-editor-wrap",titleKey:"tutorial.codeEditor.intro.title",title:"Code editor",contentKey:"tutorial.codeEditor.intro.content",content:"Edit code with syntax highlighting, IntelliSense and the toolbar. Ctrl+S saves; the status bar shows the cursor position and any problems.",placement:"auto"}];let G=null,ne=null;const He="0.45.0",Ee=`https://cdn.jsdelivr.net/npm/monaco-editor@${He}/min`,de=`${Ee}/vs`,we=15e3;function _e(){const s=window;if(s.MonacoEnvironment?.getWorkerUrl)return;const l=`self.MonacoEnvironment={baseUrl:'${Ee}/'};importScripts('${de}/base/worker/workerMain.js');`,g=URL.createObjectURL(new Blob([l],{type:"text/javascript"}));s.MonacoEnvironment={getWorkerUrl:()=>g}}function X(s){if(s!=="auto")return s;if(typeof document>"u")return"vs";const l=document.documentElement.dataset.theme;return l==="dark"?"vs-dark":l==="light"?"vs":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"vs-dark":"vs"}function Be(s){if(!s)return"";try{return JSON.stringify([s.url,s.language,s.initOptions??null])}catch{return JSON.stringify([s.url,s.language])}}function Se(){return ne?Promise.resolve(ne):G||(G=new Promise((s,l)=>{if(window.monaco){_e(),ne=window.monaco,s(ne);return}let g=!1;const o=window.setTimeout(()=>{g||(g=!0,G=null,l(new Error(`Monaco editor failed to load within ${we}ms`)))},we),x=document.createElement("script");x.src=`${de}/loader.min.js`,x.async=!0,x.onload=()=>{const F=window.require;F.config({paths:{vs:de}}),_e(),F(["vs/editor/editor.main"],O=>{g||(g=!0,window.clearTimeout(o),ne=O,s(O))})},x.onerror=()=>{g||(g=!0,window.clearTimeout(o),G=null,l(new Error("Failed to load Monaco Editor loader script")))},document.head.appendChild(x)}),G)}function je(s){n.useEffect(()=>{const l=s.current;if(!l)return;const g=h.createTabEscape(),o=x=>{g(x)&&x.stopPropagation()};return l.addEventListener("keydown",o,!0),()=>l.removeEventListener("keydown",o,!0)},[s])}const Ue=n.forwardRef(function(l,g){const{t:o}=h.useNiceTranslation();ue.injectStyleOnce(me,pe);const{value:x,defaultValue:F,onChange:O,language:b="plaintext",theme:_="auto",options:a={},height:ee=400,width:$="100%",markers:T=[],decorations:q=[],completionProvider:v,onMount:I,onCursorPositionChange:E,onSelectionChange:j,onSave:H,loading:P,disabled:A=!1,showToolbar:Y=!1,showStatusBar:D=!1,editorSize:B="standard",className:J,"data-testid":z,lsp:M,extraLibs:S,tutorial:Z}=l,[N,W,u]=h.useControllableState({value:x,defaultValue:F,fallbackValue:"",onChange:O,componentName:"NiceCodeEditor"}),m=n.useRef(W);m.current=W;const C=n.useRef(N);C.current=N;const f=n.useRef(!1),k=n.useRef(null);je(k);const i=n.useRef(null),w=n.useRef(null),R=n.useRef([]),V=n.useRef(null),[U,fe]=n.useState(!0),[ie,Me]=n.useState(null),[ge,Re]=n.useState({lineNumber:1,column:1}),[he,Le]=n.useState(""),[ce,Oe]=n.useState(a.wordWrap==="on"),re=n.useMemo(()=>({automaticLayout:!0,readOnly:A||a.readOnly,minimap:{enabled:a.minimap??!0},lineNumbers:a.lineNumbers??"on",wordWrap:a.wordWrap??"off",tabSize:a.tabSize??2,insertSpaces:a.insertSpaces??!0,fontSize:a.fontSize??14,fontFamily:a.fontFamily??"'Fira Code', 'Consolas', 'Monaco', monospace",fontLigatures:a.fontLigatures??!0,cursorStyle:a.cursorStyle??"line",cursorBlinking:a.cursorBlinking??"blink",autoClosingBrackets:a.autoClosingBrackets??"languageDefined",autoClosingQuotes:a.autoClosingQuotes??"languageDefined",formatOnPaste:a.formatOnPaste??!1,formatOnType:a.formatOnType??!1,renderWhitespace:a.renderWhitespace??"selection",renderControlCharacters:a.renderControlCharacters??!1,scrollBeyondLastLine:a.scrollBeyondLastLine??!0,smoothScrolling:a.smoothScrolling??!0,folding:a.folding??!0,showFoldingControls:a.showFoldingControls??"mouseover","bracketPairColorization.enabled":a.bracketPairColorization??!0,guides:a.guides??{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:a.stickyScroll??!1},quickSuggestions:a.quickSuggestions??!0,suggestOnTriggerCharacters:a.suggestOnTriggerCharacters??!0,acceptSuggestionOnEnter:a.acceptSuggestionOnEnter??"on",inlayHints:{enabled:a.inlayHints?"on":"off"}}),[a,A]),te=n.useRef({onCursorPositionChange:E,onSelectionChange:j,onSave:H,onMount:I});te.current={onCursorPositionChange:E,onSelectionChange:j,onSave:H,onMount:I};const be=n.useRef({language:b,theme:_,editorOptions:re});be.current={language:b,theme:_,editorOptions:re};const ve=n.useRef(M);ve.current=M;const Te=Be(M),ke=n.useRef(o);ke.current=o,n.useEffect(()=>{if(!k.current)return;let e=!0;const c=ve.current;return Se().then(async r=>{if(!e||!k.current)return;w.current=r;const p=be.current,y=r.editor.create(k.current,{value:C.current,language:p.language,theme:X(p.theme),...p.editorOptions});if(i.current=y,fe(!1),y.onDidChangeModelContent(()=>{f.current||m.current(y.getValue())}),y.onDidChangeCursorPosition(d=>{Re({lineNumber:d.position.lineNumber,column:d.position.column}),te.current.onCursorPositionChange?.({lineNumber:d.position.lineNumber,column:d.position.column})}),y.onDidChangeCursorSelection(d=>{const L=d.selection,Q=y.getModel()?.getValueInRange(L)??"";Le(Q),te.current.onSelectionChange?.({startLineNumber:L.startLineNumber,startColumn:L.startColumn,endLineNumber:L.endLineNumber,endColumn:L.endColumn})}),y.addCommand(r.KeyMod.CtrlCmd|r.KeyCode.KeyS,()=>{te.current.onSave?.(y.getValue())}),c&&typeof window<"u")try{await oe("https://cdn.jsdelivr.net/npm/vscode-ws-jsonrpc@1.0.2/lib/browser/index.min.js"),await oe("https://cdn.jsdelivr.net/npm/monaco-languageclient@0.15.0/lib/monaco-languageclient.min.js");const d=window,L=d.ReconnectingWebSocket,{MonacoLanguageClient:Q,CloseAction:Ae,ErrorAction:De,createConnection:ye}=d.monacoLanguageClient||{};if(Q&&ye){const ze=c.url,We=c.language,xe=new L(ze),Ve=new d.VSCodeWebSocketMessageReader(xe),Fe=new d.VSCodeWebSocketMessageWriter(xe),$e=ye(Ve,Fe),Ce=new Q({name:"LSP Client",clientOptions:{documentSelector:[We],initializationOptions:c.initOptions,errorHandler:{error:()=>De.Continue,closed:()=>Ae.Restart}},connectionProvider:{get:()=>Promise.resolve($e)}});Ce.start(),i.current.__lspClient=Ce}}catch(d){console.warn("LSP bridge failed to load:",d)}te.current.onMount?.(y,r)}).catch(r=>{e&&(Me(r.message??ke.current("codeEditor.failedToLoadEditor","Failed to load editor")),fe(!1))}),()=>{if(e=!1,i.current?.dispose(),V.current?.dispose(),i.current&&i.current.__lspClient)try{i.current.__lspClient.stop()}catch{}}},[Te]),n.useEffect(()=>{const e=i.current;if(!u||!e||N===e.getValue())return;const c=e.getPosition();f.current=!0;try{e.setValue(N)}finally{f.current=!1}c&&e.setPosition(c)},[N,u]),n.useEffect(()=>{const e=i.current,c=w.current;if(e&&c){const r=e.getModel();r&&c.editor.setModelLanguage(r,b)}},[b]),n.useEffect(()=>{const e=w.current;if(!e||U||!S||S.length===0||b!=="javascript"&&b!=="typescript")return;const c=e.languages?.typescript;if(!c)return;const r=[];try{S.forEach((p,y)=>{const d=p.filePath??`inmemory://model/nice-extralib-${y}.d.ts`,L=c.typescriptDefaults?.addExtraLib(p.content,d);L&&r.push(L);const Q=c.javascriptDefaults?.addExtraLib(p.content,d);Q&&r.push(Q)})}catch(p){console.warn("Failed to register extraLibs:",p)}return()=>{r.forEach(p=>{try{p.dispose()}catch{}})}},[S,b,U]),n.useEffect(()=>{const e=w.current;if(!e||(e.editor.setTheme(X(_)),_!=="auto"||typeof document>"u"))return;const c=()=>{w.current?.editor.setTheme(X("auto"))},r=new MutationObserver(c);r.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const p=window.matchMedia?.("(prefers-color-scheme: dark)");return p?.addEventListener?.("change",c),()=>{r.disconnect(),p?.removeEventListener?.("change",c)}},[_]),n.useEffect(()=>{const e=i.current;e&&e.updateOptions(re)},[re]),n.useEffect(()=>{const e=i.current,c=w.current;if(e&&c){const r=e.getModel();if(r){const p=T.map(y=>({startLineNumber:y.startLineNumber,startColumn:y.startColumn,endLineNumber:y.endLineNumber,endColumn:y.endColumn,message:y.message,severity:y.severity}));c.editor.setModelMarkers(r,"owner",p)}}},[T]),n.useEffect(()=>{const e=i.current;if(e&&q.length>0){const c=q.map(r=>({range:{startLineNumber:r.range.startLineNumber,startColumn:r.range.startColumn,endLineNumber:r.range.endLineNumber,endColumn:r.range.endColumn},options:{className:r.className,glyphMarginClassName:r.glyphMarginClassName,hoverMessage:r.hoverMessage?{value:r.hoverMessage}:void 0,isWholeLine:r.isWholeLine}}));R.current=e.deltaDecorations(R.current,c)}},[q]),n.useEffect(()=>{const e=w.current;if(!e||!v)return;V.current?.dispose();const c={text:0,method:1,function:2,constructor:3,field:4,variable:5,class:6,interface:7,module:8,property:9,keyword:13,snippet:14,color:15,file:16,reference:17,folder:18};return V.current=e.languages.registerCompletionItemProvider(b,{provideCompletionItems:async(r,p)=>({suggestions:(await v(r,p)).map(d=>({label:d.label,kind:c[d.kind]??0,insertText:d.insertText,insertTextRules:d.insertTextRules==="insertAsSnippet"?4:void 0,documentation:d.documentation,detail:d.detail,range:{startLineNumber:p.lineNumber,startColumn:p.column,endLineNumber:p.lineNumber,endColumn:p.column}}))})}),()=>{V.current?.dispose()}},[b,v]),n.useImperativeHandle(g,()=>({getEditor:()=>i.current,getMonaco:()=>w.current,focus:()=>i.current?.focus(),getValue:()=>i.current?.getValue()??"",setValue:e=>i.current?.setValue(e),getSelection:()=>{const e=i.current;if(!e)return"";const c=e.getSelection();return c?e.getModel()?.getValueInRange(c)??"":""},insertText:e=>{const c=i.current;if(!c)return;const r=c.getSelection();r&&c.executeEdits("",[{range:r,text:e}])},formatDocument:()=>{i.current?.getAction("editor.action.formatDocument")?.run()},goToLine:(e,c=1)=>{const r=i.current;r&&(r.setPosition({lineNumber:e,column:c}),r.revealLineInCenter(e),r.focus())},findReplace:()=>{i.current?.getAction("editor.action.startFindReplaceAction")?.run()},undo:()=>{i.current?.trigger("keyboard","undo",null)},redo:()=>{i.current?.trigger("keyboard","redo",null)},getCursorPosition:()=>{const e=i.current?.getPosition();return{lineNumber:e?.lineNumber??1,column:e?.column??1}},setMarkers:e=>{const c=i.current,r=w.current;if(c&&r){const p=c.getModel();if(p){const y=e.map(d=>({startLineNumber:d.startLineNumber,startColumn:d.startColumn,endLineNumber:d.endLineNumber,endColumn:d.endColumn,message:d.message,severity:d.severity}));r.editor.setModelMarkers(p,"owner",y)}}}}),[]);const K=n.useMemo(()=>({format:()=>i.current?.getAction("editor.action.formatDocument")?.run(),undo:()=>i.current?.trigger("keyboard","undo",null),redo:()=>i.current?.trigger("keyboard","redo",null),find:()=>i.current?.getAction("editor.action.startFindReplaceAction")?.run(),toggleWordWrap:()=>{const e=!ce;Oe(e),i.current?.updateOptions({wordWrap:e?"on":"off"})},toggleMinimap:()=>{const e=i.current?.getOption?.(w.current?.editor?.EditorOption?.minimap);i.current?.updateOptions({minimap:{enabled:!e?.enabled}})},foldAll:()=>i.current?.getAction("editor.foldAll")?.run(),unfoldAll:()=>i.current?.getAction("editor.unfoldAll")?.run()}),[ce]),Ie=N.split(`
|
|
2
|
+
`).length,Pe=N.length;return t.jsxs("div",{className:`nice-code-editor-wrap nice-editor--${B} ${J??""}`,style:{height:ee,width:$,display:"flex",flexDirection:"column",position:"relative"},"data-testid":z,children:[t.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:t.jsx(h.NiceTutorialButton,{steps:h.resolveTutorial(Z,qe)})}),ie&&t.jsxs("div",{className:"nice-code-editor__error",style:{position:"absolute",inset:0,zIndex:2,background:"var(--nice-bg-primary, #fff)"},children:[t.jsxs("span",{children:[t.jsx(h.NiceIcon,{name:"warning",size:16})," ",ie]}),t.jsx("textarea",{value:N,onChange:e=>W(e.target.value),readOnly:A||a.readOnly,style:{width:"100%",height:"100%",fontFamily:"monospace"}})]}),U&&!ie&&t.jsx("div",{className:"nice-code-editor__loader-overlay",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)"},children:P??t.jsx("div",{className:"nice-code-editor__loader",children:o("codeEditor.loadingEditor","Loading editor...")})}),Y&&t.jsxs("div",{className:"nice-code-editor__toolbar",children:[t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.undo,title:o("codeEditor.undoCtrlZ","Undo (Ctrl+Z)"),"aria-label":o("codeEditor.undo","Undo"),children:t.jsx(h.NiceIcon,{name:"reply",size:16})}),t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.redo,title:o("codeEditor.redoCtrlY","Redo (Ctrl+Y)"),"aria-label":o("codeEditor.redo","Redo"),children:t.jsx(h.NiceIcon,{name:"forward",size:16})}),t.jsx("span",{className:"nice-code-editor__toolbar-sep"}),t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.format,title:o("codeEditor.formatShiftAltF","Format (Shift+Alt+F)"),"aria-label":o("codeEditor.format","Format"),children:t.jsx(h.NiceIcon,{name:"type",size:16})}),t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.find,title:o("codeEditor.findReplaceCtrlH","Find & Replace (Ctrl+H)"),"aria-label":o("codeEditor.findReplace","Find & Replace"),children:t.jsx(h.NiceIcon,{name:"search",size:16})}),t.jsx("span",{className:"nice-code-editor__toolbar-sep"}),t.jsx("button",{className:`nice-code-editor__toolbar-btn${ce?" nice-code-editor__toolbar-btn--active":""}`,onClick:K.toggleWordWrap,title:o("codeEditor.toggleWordWrap","Toggle Word Wrap"),"aria-label":o("codeEditor.toggleWordWrap","Toggle Word Wrap"),children:t.jsx(h.NiceIcon,{name:"align-left",size:16})}),t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.toggleMinimap,title:o("codeEditor.toggleMinimap","Toggle Minimap"),"aria-label":o("codeEditor.toggleMinimap","Toggle Minimap"),children:t.jsx(h.NiceIcon,{name:"columns",size:16})}),t.jsx("span",{className:"nice-code-editor__toolbar-sep"}),t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.foldAll,title:o("codeEditor.foldAll","Fold All"),"aria-label":o("codeEditor.foldAll","Fold All"),children:t.jsx(h.NiceIcon,{name:"collapse",size:16})}),t.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:K.unfoldAll,title:o("codeEditor.unfoldAll","Unfold All"),"aria-label":o("codeEditor.unfoldAll","Unfold All"),children:t.jsx(h.NiceIcon,{name:"expand",size:16})})]}),t.jsx("div",{ref:k,className:"nice-code-editor",style:{flex:1,minHeight:0}}),D&&t.jsxs("div",{className:"nice-code-editor__statusbar",children:[t.jsx("span",{children:o("codeEditor.lnCol","Ln {lineNumber}, Col {column}").replace("{lineNumber}",String(ge.lineNumber)).replace("{column}",String(ge.column))}),he.length>0&&t.jsx("span",{children:o("codeEditor.selected","({selectionText} selected)").replace("{selectionText}",String(he.length))}),t.jsx("span",{className:"nice-code-editor__statusbar-spacer"}),t.jsx("span",{children:o("codeEditor.linesChars","{lineCount} lines · {charCount} chars").replace("{lineCount}",String(Ie)).replace("{charCount}",String(Pe))}),t.jsx("span",{className:"nice-code-editor__statusbar-lang",children:b}),T.length>0&&t.jsxs("span",{className:"nice-code-editor__statusbar-markers",children:[t.jsx(h.NiceIcon,{name:"warning",size:14})," ",T.length]})]})]})});function Ke(s){const{t:l}=h.useNiceTranslation();ue.injectStyleOnce(me,pe);const{original:g,defaultOriginal:o,modified:x,defaultModified:F,language:O="plaintext",theme:b="auto",height:_=400,width:a="100%",inline:ee=!1,renderSideBySide:$=!0,originalEditable:T=!1,modifiedEditable:q=!1,onOriginalChange:v,onModifiedChange:I,loading:E,className:j,"data-testid":H}=s,[P,A,Y]=h.useControllableState({value:g,defaultValue:o,fallbackValue:"",onChange:v,componentName:"NiceCodeDiffEditor.original"}),[D,B,J]=h.useControllableState({value:x,defaultValue:F,fallbackValue:"",onChange:I,componentName:"NiceCodeDiffEditor.modified"}),z=n.useRef({currentOriginal:P,currentModified:D,setOriginal:A,setModified:B});z.current={currentOriginal:P,currentModified:D,setOriginal:A,setModified:B};const M=n.useRef(!1),S=n.useRef(null);je(S);const Z=n.useRef(null),N=n.useRef(null),[W,u]=n.useState(!0),[m,C]=n.useState(null);return n.useEffect(()=>{if(!S.current)return;let f=!0;return Se().then(k=>{if(!f||!S.current)return;N.current=k;const{currentOriginal:i,currentModified:w}=z.current,R=k.editor.createModel(i,O),V=k.editor.createModel(w,O),U=k.editor.createDiffEditor(S.current,{automaticLayout:!0,theme:X(b),renderSideBySide:!ee&&$,originalEditable:T,readOnly:!q});U.setModel({original:R,modified:V}),Z.current=U,u(!1),T&&R.onDidChangeContent(()=>{M.current||z.current.setOriginal(R.getValue())}),q&&V.onDidChangeContent(()=>{M.current||z.current.setModified(V.getValue())})}).catch(k=>{f&&(C(k.message??l("codeEditor.failedToLoadDiffEditor","Failed to load diff editor")),u(!1))}),()=>{f=!1,Z.current?.dispose()}},[l]),n.useEffect(()=>{const f=Z.current?.getModel();if(f){M.current=!0;try{Y&&f.original.getValue()!==P&&f.original.setValue(P),J&&f.modified.getValue()!==D&&f.modified.setValue(D)}finally{M.current=!1}}},[P,D,Y,J]),n.useEffect(()=>{const f=N.current;if(!f||(f.editor.setTheme(X(b)),b!=="auto"||typeof document>"u"))return;const k=()=>{N.current?.editor.setTheme(X("auto"))},i=new MutationObserver(k);i.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const w=window.matchMedia?.("(prefers-color-scheme: dark)");return w?.addEventListener?.("change",k),()=>{i.disconnect(),w?.removeEventListener?.("change",k)}},[b,W]),m?t.jsx("div",{className:`nice-code-diff-editor nice-code-diff-editor--error ${j??""}`,style:{height:_,width:a},"data-testid":H,children:t.jsx("div",{className:"nice-code-editor__error",children:t.jsxs("span",{children:[t.jsx(h.NiceIcon,{name:"warning",size:16})," ",m]})})}):t.jsxs("div",{className:`nice-code-diff-editor ${j??""}`,style:{height:_,width:a,position:"relative"},"data-testid":H,children:[t.jsx("div",{ref:S,style:{position:"absolute",inset:0}}),W&&t.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)",zIndex:2},children:E??t.jsx("div",{className:"nice-code-editor__loader",children:l("codeEditor.loadingDiffEditor","Loading diff editor...")})})]})}const Ye="1.29.0",Ne=`https://cdn.jsdelivr.net/npm/prismjs@${Ye}`;let ae=null;const le={javascript:"javascript",typescript:"typescript",json:"json",html:"markup",css:"css",scss:"scss",less:"less",markdown:"markdown",xml:"markup",yaml:"yaml",sql:"sql",python:"python",csharp:"csharp",java:"java",cpp:"cpp",c:"c",go:"go",rust:"rust",php:"php",ruby:"ruby",shell:"bash",powershell:"powershell",plaintext:"plain"};function oe(s){return new Promise((l,g)=>{if(document.querySelector(`script[data-prism-src="${s}"]`)){l();return}const o=document.createElement("script");o.src=s,o.async=!0,o.dataset.prismSrc=s,o.onload=()=>l(),o.onerror=()=>g(new Error(`Failed to load ${s}`)),document.head.appendChild(o)})}function Je(s){if(typeof window>"u")return Promise.resolve(null);const l=window,g=le[s]??"plain",o=async()=>{if(g!=="plain"&&!l.Prism?.languages?.[g])try{await oe(`${Ne}/components/prism-${g}.min.js`)}catch{}};return l.Prism?.languages?o().then(()=>l.Prism):(ae||(ae=(async()=>(window.Prism={manual:!0},await oe(`${Ne}/prism.min.js`),window.Prism))()),ae.then(async()=>(await o(),window.Prism)))}function se(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Qe(s){ue.injectStyleOnce(me,pe);const{value:l,defaultValue:g,onChange:o,language:x="plaintext",height:F=300,width:O="100%",readOnly:b=!1,tabSize:_=2,lineNumbers:a=!0,placeholder:ee,theme:$="auto",className:T,"data-testid":q}=s,[v,I]=h.useControllableState({value:l,defaultValue:g,fallbackValue:"",onChange:o,componentName:"NiceSimpleCodeEditor"}),E=n.useRef(null),j=n.useRef(null),H=n.useRef(null),{t:P}=h.useNiceTranslation(),A=n.useId(),[Y]=n.useState(h.createTabEscape),[D,B]=n.useState(()=>se(v)),[J,z]=n.useState("light");n.useEffect(()=>{const u=()=>{if($!=="auto")return $;if(typeof document>"u")return"light";const k=document.documentElement.dataset.theme;return k==="dark"?"dark":k==="light"?"light":window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light"};if(z(u()),$!=="auto"||typeof document>"u")return;const m=()=>z(u()),C=new MutationObserver(m);C.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const f=window.matchMedia?.("(prefers-color-scheme: dark)");return f?.addEventListener?.("change",m),()=>{C.disconnect(),f?.removeEventListener?.("change",m)}},[$]),n.useEffect(()=>{let u=!0;return Je(x).then(m=>{if(!u)return;const C=le[x]??"plain";if(m?.languages?.[C])try{const f=m.highlight(v,m.languages[C],C);B(f);return}catch{}B(se(v))}).catch(()=>{u&&B(se(v))}),()=>{u=!1}},[v,x]);const M=n.useCallback(()=>{if(!j.current||!E.current)return;j.current.scrollTop=E.current.scrollTop,j.current.scrollLeft=E.current.scrollLeft;const u=H.current;if(u){const m=E.current.offsetHeight-E.current.clientHeight;u.style.paddingBottom=`calc(var(--nice-space-2, 8px) + ${m}px)`,u.scrollTop=E.current.scrollTop}},[]),S=n.useCallback(u=>{if(!Y(u)&&u.key==="Tab"&&!b){u.preventDefault();const m=u.currentTarget,C=m.selectionStart,f=m.selectionEnd,k=" ".repeat(_);if(u.shiftKey){const R=v.substring(0,C).lastIndexOf(`
|
|
3
|
+
`)+1;if((v.substring(R,C).match(/^(\s*)/)?.[1]??"").length>=_){const U=v.substring(0,R)+v.substring(R+_);I(U),setTimeout(()=>{m.selectionStart=m.selectionEnd=C-_},0)}}else{const i=v.substring(0,C)+k+v.substring(f);I(i),setTimeout(()=>{m.selectionStart=m.selectionEnd=C+_},0)}}},[v,I,_,Y,b]),N=v.split(`
|
|
4
|
+
`).length,W=le[x]??"plain";return t.jsxs("div",{className:`nice-simple-code-editor nice-simple-code-editor--${J} ${T??""}`,style:{height:F,width:O},"data-testid":q,"data-language":x,"data-theme":J,children:[a&&t.jsx("div",{ref:H,className:"nice-simple-code-editor__line-numbers",children:Array.from({length:N},(u,m)=>t.jsx("div",{className:"nice-simple-code-editor__line-number",children:m+1},m))}),t.jsxs("div",{className:"nice-simple-code-editor__editor-area",children:[t.jsx("pre",{ref:j,"aria-hidden":"true",className:`nice-simple-code-editor__highlight language-${W}`,children:t.jsx("code",{className:`language-${W}`,dangerouslySetInnerHTML:{__html:D+(v.endsWith(`
|
|
5
|
+
`)?`
|
|
6
|
+
`:"")}})}),t.jsx("textarea",{ref:E,className:"nice-simple-code-editor__textarea",value:v,onChange:u=>I(u.target.value),onKeyDown:S,onScroll:M,readOnly:b,placeholder:ee,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off","aria-describedby":b?void 0:A}),!b&&t.jsx("span",{id:A,className:"nice-sr-only",children:P("input.tabEscapeHint","Tab indents. To leave the editor, press Escape, then Tab.")})]})]})}const me="nice-code-editor-styles",pe=`
|
|
7
|
+
.nice-code-editor,
|
|
8
|
+
.nice-code-diff-editor {
|
|
9
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
10
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.nice-code-editor--loading,
|
|
15
|
+
.nice-code-editor--error,
|
|
16
|
+
.nice-code-diff-editor--loading {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
background: var(--nice-bg-tertiary, #f5f5f5);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.nice-code-editor__loader {
|
|
24
|
+
color: var(--nice-text-secondary, #666);
|
|
25
|
+
font-size: 14px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.nice-code-editor__error {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 100%;
|
|
33
|
+
padding: var(--nice-space-2, 8px);
|
|
34
|
+
gap: var(--nice-space-2, 8px);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.nice-code-editor__error span {
|
|
38
|
+
color: var(--nice-error, #d32f2f);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* Simple code editor */
|
|
42
|
+
.nice-simple-code-editor {
|
|
43
|
+
display: flex;
|
|
44
|
+
border: 1px solid var(--nice-border-color, var(--nice-border, #e0e0e0));
|
|
45
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
48
|
+
font-size: 14px;
|
|
49
|
+
line-height: 1.5;
|
|
50
|
+
background: var(--nice-bg-primary, var(--nice-bg-surface, #fff));
|
|
51
|
+
color: var(--nice-text-primary, var(--nice-text-primary, #333));
|
|
52
|
+
}
|
|
53
|
+
.nice-simple-code-editor--dark {
|
|
54
|
+
background: var(--nice-bg, #1e1e1e);
|
|
55
|
+
color: var(--nice-text, #d4d4d4);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.nice-simple-code-editor__line-numbers {
|
|
59
|
+
padding: var(--nice-space-2, 8px) 0;
|
|
60
|
+
background: var(--nice-bg-secondary, var(--nice-bg-tertiary, #f5f5f5));
|
|
61
|
+
border-right: 1px solid var(--nice-border-color, var(--nice-border, #e0e0e0));
|
|
62
|
+
user-select: none;
|
|
63
|
+
text-align: right;
|
|
64
|
+
color: var(--nice-text-secondary, var(--nice-text-secondary, #999));
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
}
|
|
67
|
+
.nice-simple-code-editor--dark .nice-simple-code-editor__line-numbers {
|
|
68
|
+
background: var(--nice-bg-secondary, #252526);
|
|
69
|
+
border-right-color: var(--nice-border, #3c3c3c);
|
|
70
|
+
color: var(--nice-text-muted, #858585);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.nice-simple-code-editor__line-number {
|
|
74
|
+
padding: 0 var(--nice-space-3, 12px);
|
|
75
|
+
min-width: 40px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.nice-simple-code-editor__editor-area {
|
|
79
|
+
position: relative;
|
|
80
|
+
flex: 1;
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.nice-simple-code-editor__highlight,
|
|
85
|
+
.nice-simple-code-editor__textarea {
|
|
86
|
+
position: absolute;
|
|
87
|
+
inset: 0;
|
|
88
|
+
margin: 0;
|
|
89
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
90
|
+
border: 0;
|
|
91
|
+
font: inherit;
|
|
92
|
+
line-height: inherit;
|
|
93
|
+
white-space: pre;
|
|
94
|
+
overflow: auto;
|
|
95
|
+
tab-size: 2;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.nice-simple-code-editor__highlight {
|
|
99
|
+
pointer-events: none;
|
|
100
|
+
background: transparent;
|
|
101
|
+
color: inherit;
|
|
102
|
+
}
|
|
103
|
+
.nice-simple-code-editor__highlight code {
|
|
104
|
+
font: inherit;
|
|
105
|
+
background: transparent;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.nice-simple-code-editor__textarea {
|
|
109
|
+
background: transparent;
|
|
110
|
+
color: transparent;
|
|
111
|
+
caret-color: var(--nice-text-primary, var(--nice-text-primary, #333));
|
|
112
|
+
resize: none;
|
|
113
|
+
outline: none;
|
|
114
|
+
-webkit-text-fill-color: transparent;
|
|
115
|
+
}
|
|
116
|
+
.nice-simple-code-editor--dark .nice-simple-code-editor__textarea {
|
|
117
|
+
caret-color: var(--nice-text, #d4d4d4);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.nice-simple-code-editor__textarea::placeholder {
|
|
121
|
+
color: var(--nice-text-secondary, var(--nice-text-secondary, #999));
|
|
122
|
+
-webkit-text-fill-color: var(--nice-text-secondary, var(--nice-text-secondary, #999));
|
|
123
|
+
}
|
|
124
|
+
.nice-simple-code-editor--dark .nice-simple-code-editor__textarea::placeholder {
|
|
125
|
+
color: var(--nice-text-muted, #858585);
|
|
126
|
+
-webkit-text-fill-color: var(--nice-text-muted, #858585);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* Prism token colors — light */
|
|
130
|
+
.nice-simple-code-editor .token.comment,
|
|
131
|
+
.nice-simple-code-editor .token.prolog,
|
|
132
|
+
.nice-simple-code-editor .token.doctype,
|
|
133
|
+
.nice-simple-code-editor .token.cdata { color: #6a737d; font-style: italic; }
|
|
134
|
+
.nice-simple-code-editor .token.punctuation { color: #586069; }
|
|
135
|
+
.nice-simple-code-editor .token.property,
|
|
136
|
+
.nice-simple-code-editor .token.tag,
|
|
137
|
+
.nice-simple-code-editor .token.boolean,
|
|
138
|
+
.nice-simple-code-editor .token.number,
|
|
139
|
+
.nice-simple-code-editor .token.constant,
|
|
140
|
+
.nice-simple-code-editor .token.symbol,
|
|
141
|
+
.nice-simple-code-editor .token.deleted { color: #005cc5; }
|
|
142
|
+
.nice-simple-code-editor .token.selector,
|
|
143
|
+
.nice-simple-code-editor .token.attr-name,
|
|
144
|
+
.nice-simple-code-editor .token.string,
|
|
145
|
+
.nice-simple-code-editor .token.char,
|
|
146
|
+
.nice-simple-code-editor .token.builtin,
|
|
147
|
+
.nice-simple-code-editor .token.inserted { color: #032f62; }
|
|
148
|
+
.nice-simple-code-editor .token.operator,
|
|
149
|
+
.nice-simple-code-editor .token.entity,
|
|
150
|
+
.nice-simple-code-editor .token.url,
|
|
151
|
+
.nice-simple-code-editor .token.variable { color: var(--nice-danger, #d73a49); }
|
|
152
|
+
.nice-simple-code-editor .token.atrule,
|
|
153
|
+
.nice-simple-code-editor .token.attr-value,
|
|
154
|
+
.nice-simple-code-editor .token.keyword { color: var(--nice-danger, #d73a49); font-weight: 600; }
|
|
155
|
+
.nice-simple-code-editor .token.function,
|
|
156
|
+
.nice-simple-code-editor .token.class-name { color: #6f42c1; }
|
|
157
|
+
.nice-simple-code-editor .token.regex,
|
|
158
|
+
.nice-simple-code-editor .token.important { color: #e36209; }
|
|
159
|
+
|
|
160
|
+
/* Prism token colors — dark */
|
|
161
|
+
.nice-simple-code-editor--dark .token.comment,
|
|
162
|
+
.nice-simple-code-editor--dark .token.prolog,
|
|
163
|
+
.nice-simple-code-editor--dark .token.doctype,
|
|
164
|
+
.nice-simple-code-editor--dark .token.cdata { color: var(--nice-success, #6a9955); font-style: italic; }
|
|
165
|
+
.nice-simple-code-editor--dark .token.punctuation { color: var(--nice-text, #d4d4d4); }
|
|
166
|
+
.nice-simple-code-editor--dark .token.property,
|
|
167
|
+
.nice-simple-code-editor--dark .token.tag,
|
|
168
|
+
.nice-simple-code-editor--dark .token.boolean,
|
|
169
|
+
.nice-simple-code-editor--dark .token.number,
|
|
170
|
+
.nice-simple-code-editor--dark .token.constant,
|
|
171
|
+
.nice-simple-code-editor--dark .token.symbol,
|
|
172
|
+
.nice-simple-code-editor--dark .token.deleted { color: var(--nice-success-light, #b5cea8); }
|
|
173
|
+
.nice-simple-code-editor--dark .token.selector,
|
|
174
|
+
.nice-simple-code-editor--dark .token.attr-name,
|
|
175
|
+
.nice-simple-code-editor--dark .token.string,
|
|
176
|
+
.nice-simple-code-editor--dark .token.char,
|
|
177
|
+
.nice-simple-code-editor--dark .token.builtin,
|
|
178
|
+
.nice-simple-code-editor--dark .token.inserted { color: var(--nice-warning, #ce9178); }
|
|
179
|
+
.nice-simple-code-editor--dark .token.operator,
|
|
180
|
+
.nice-simple-code-editor--dark .token.entity,
|
|
181
|
+
.nice-simple-code-editor--dark .token.url,
|
|
182
|
+
.nice-simple-code-editor--dark .token.variable { color: var(--nice-primary, #569cd6); }
|
|
183
|
+
.nice-simple-code-editor--dark .token.atrule,
|
|
184
|
+
.nice-simple-code-editor--dark .token.attr-value,
|
|
185
|
+
.nice-simple-code-editor--dark .token.keyword { color: #c586c0; font-weight: 600; }
|
|
186
|
+
.nice-simple-code-editor--dark .token.function,
|
|
187
|
+
.nice-simple-code-editor--dark .token.class-name { color: #dcdcaa; }
|
|
188
|
+
.nice-simple-code-editor--dark .token.regex,
|
|
189
|
+
.nice-simple-code-editor--dark .token.important { color: #d7ba7d; }
|
|
190
|
+
|
|
191
|
+
/* Toolbar */
|
|
192
|
+
.nice-code-editor-wrap {
|
|
193
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
194
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
195
|
+
overflow: hidden;
|
|
196
|
+
}
|
|
197
|
+
.nice-code-editor-wrap .nice-code-editor {
|
|
198
|
+
border: none;
|
|
199
|
+
border-radius: 0;
|
|
200
|
+
}
|
|
201
|
+
/* The editing surface draws no outline: while it has focus, the frame shows the ring
|
|
202
|
+
(TODO_1.3.0 I4). */
|
|
203
|
+
.nice-code-editor-wrap:has(.nice-code-editor:focus-within),
|
|
204
|
+
.nice-code-diff-editor:focus-within,
|
|
205
|
+
.nice-simple-code-editor:focus-within {
|
|
206
|
+
border-color: var(--nice-color-primary, #3b82f6);
|
|
207
|
+
box-shadow: var(--nice-focus-ring, 0 0 0 2px var(--nice-color-primary, #3b82f6));
|
|
208
|
+
}
|
|
209
|
+
.nice-code-editor__toolbar {
|
|
210
|
+
display: flex;
|
|
211
|
+
align-items: center;
|
|
212
|
+
gap: var(--nice-space-0-5, 2px);
|
|
213
|
+
padding: var(--nice-space-0-75, 3px) var(--nice-space-1-5, 6px);
|
|
214
|
+
background: var(--nice-bg-tertiary, #f5f5f5);
|
|
215
|
+
border-bottom: 1px solid var(--nice-border, #e0e0e0);
|
|
216
|
+
}
|
|
217
|
+
.nice-code-editor__toolbar-btn {
|
|
218
|
+
display: inline-flex;
|
|
219
|
+
align-items: center;
|
|
220
|
+
justify-content: center;
|
|
221
|
+
width: 26px;
|
|
222
|
+
height: 26px;
|
|
223
|
+
border: none;
|
|
224
|
+
border-radius: var(--nice-radius-sm, 3px);
|
|
225
|
+
background: transparent;
|
|
226
|
+
color: var(--nice-text-secondary, #666);
|
|
227
|
+
cursor: pointer;
|
|
228
|
+
font-size: 14px;
|
|
229
|
+
transition: background 0.15s, color 0.15s;
|
|
230
|
+
}
|
|
231
|
+
.nice-code-editor__toolbar-btn:hover {
|
|
232
|
+
background: var(--nice-hover-bg, #e0e0e0);
|
|
233
|
+
color: var(--nice-text-primary, #333);
|
|
234
|
+
}
|
|
235
|
+
.nice-code-editor__toolbar-btn--active {
|
|
236
|
+
background: var(--nice-accent, #1976d2);
|
|
237
|
+
color: var(--nice-text-on-primary, #FFF);
|
|
238
|
+
}
|
|
239
|
+
.nice-code-editor__toolbar-sep {
|
|
240
|
+
width: 1px;
|
|
241
|
+
height: 18px;
|
|
242
|
+
background: var(--nice-border, #e0e0e0);
|
|
243
|
+
margin: 0 var(--nice-space-1, 4px);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/* Status bar */
|
|
247
|
+
.nice-code-editor__statusbar {
|
|
248
|
+
display: flex;
|
|
249
|
+
align-items: center;
|
|
250
|
+
gap: var(--nice-space-3, 12px);
|
|
251
|
+
padding: var(--nice-space-0-5, 2px) var(--nice-space-2-5, 10px);
|
|
252
|
+
background: var(--nice-bg-tertiary, #f5f5f5);
|
|
253
|
+
border-top: 1px solid var(--nice-border, #e0e0e0);
|
|
254
|
+
font-size: 12px;
|
|
255
|
+
color: var(--nice-text-secondary, #666);
|
|
256
|
+
user-select: none;
|
|
257
|
+
}
|
|
258
|
+
.nice-code-editor__statusbar-spacer { flex: 1; }
|
|
259
|
+
.nice-code-editor__statusbar-lang {
|
|
260
|
+
text-transform: uppercase;
|
|
261
|
+
font-weight: 600;
|
|
262
|
+
font-size: 11px;
|
|
263
|
+
}
|
|
264
|
+
.nice-code-editor__statusbar-markers {
|
|
265
|
+
color: var(--nice-warning, #f39c12);
|
|
266
|
+
font-weight: 600;
|
|
267
|
+
}
|
|
268
|
+
`;exports.NiceCodeDiffEditor=Ke;exports.NiceCodeEditor=Ue;exports.NiceSimpleCodeEditor=Qe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),P=require("@nice2dev/ui-core"),k=require("react"),me=require("react-dom"),he=require("./devops-Bzp3ZqZ3.cjs"),fe=["#ef4444","#f97316","#f59e0b","#84cc16","#10b981","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#ec4899","#64748b","#1e293b"];function ge(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ve(a){const u=/^#?([0-9a-f]{6})$/i.exec(a.trim());if(!u)return{r:0,g:0,b:0};const h=parseInt(u[1],16);return{r:h>>16&255,g:h>>8&255,b:h&255}}function be(a,u,h){const p=r=>Math.max(0,Math.min(255,Math.round(r))).toString(16).padStart(2,"0");return`#${p(a)}${p(u)}${p(h)}`}function xe(a,u,h){const p=a/255,r=u/255,i=h/255,n=Math.max(p,r,i),b=Math.min(p,r,i),d=(n+b)/2;let o=0,c=0;if(n!==b){const _=n-b;switch(c=d>.5?_/(2-n-b):_/(n+b),n){case p:o=(r-i)/_+(r<i?6:0);break;case r:o=(i-p)/_+2;break;case i:o=(p-r)/_+4;break}o*=60}return{h:Math.round(o),s:Math.round(c*100),l:Math.round(d*100)}}function _e(a,u,h){const p=u/100,r=h/100,i=(1-Math.abs(2*r-1))*p,n=i*(1-Math.abs(a/60%2-1)),b=r-i/2;let d=0,o=0,c=0;return a<60?[d,o,c]=[i,n,0]:a<120?[d,o,c]=[n,i,0]:a<180?[d,o,c]=[0,i,n]:a<240?[d,o,c]=[0,n,i]:a<300?[d,o,c]=[n,0,i]:[d,o,c]=[i,0,n],{r:Math.round((d+b)*255),g:Math.round((o+b)*255),b:Math.round((c+b)*255)}}function ke(a,u,h){const p=a/255,r=u/255,i=h/255,n=Math.max(p,r,i),b=Math.min(p,r,i),d=n-b;let o=0;d!==0&&(n===p?o=(r-i)/d%6:n===r?o=(i-p)/d+2:o=(p-r)/d+4,o*=60,o<0&&(o+=360));const c=n===0?0:d/n;return{h:Math.round(o),s:Math.round(c*100),v:Math.round(n*100)}}function ye(a,u,h){const p=u/100,r=h/100,i=r*p,n=i*(1-Math.abs(a/60%2-1)),b=r-i;let d=0,o=0,c=0;return a<60?[d,o,c]=[i,n,0]:a<120?[d,o,c]=[n,i,0]:a<180?[d,o,c]=[0,i,n]:a<240?[d,o,c]=[0,n,i]:a<300?[d,o,c]=[n,0,i]:[d,o,c]=[i,0,n],{r:Math.round((d+b)*255),g:Math.round((o+b)*255),b:Math.round((c+b)*255)}}function Ne(a){let u=a.trim();const h=/var\([^,]+,\s*(#[0-9a-fA-F]{3,8})\s*\)/.exec(u);h&&(u=h[1]);const p=/^#?([0-9a-f]{3})$/i.exec(u);p&&(u=`#${p[1].split("").map(n=>n+n).join("")}`);const r=/^#?([0-9a-f]{6})$/i.exec(u),i=/^#?([0-9a-f]{8})$/i.exec(u);if(i){const n=i[1];return{r:parseInt(n.slice(0,2),16),g:parseInt(n.slice(2,4),16),b:parseInt(n.slice(4,6),16),a:parseInt(n.slice(6,8),16)/255}}if(r){const n=parseInt(r[1],16);return{r:n>>16&255,g:n>>8&255,b:n&255,a:1}}return{r:0,g:0,b:0,a:1}}function je(a,u,h,p,r){const i=b=>Math.max(0,Math.min(255,Math.round(b))).toString(16).padStart(2,"0"),n=`#${i(a)}${i(u)}${i(h)}`;return r?`${n}${i(p*255)}`:n}const Me=Object.assign(k.forwardRef(({label:a,helperText:u,error:h,required:p,disabled:r,id:i,className:n,style:b,accessMode:d,displayStyle:o,value:c="#3b82f6",onChange:_,presets:B=fe,showInput:X=!1,showRandom:Y=!1,withAlpha:S=!1,compact:I=!1,showKeyboardHints:J,size:Q="md",labelPlacement:Z,errorPlacement:L,labelWidth:T,controlWidth:D,loading:O},F)=>{const A=P.useNiceAccessMode(d,i),W=A==="hidden";(A==="disabled"||A==="readOnly")&&(r=!0);const{t:v}=P.useNiceTranslation(),$=P.useControlId(i);P.useComponentDisplayClass("input",o);const ee=k.useCallback(()=>{r||_?.(ge())},[r,_]),[M,C]=k.useState(!1),[q,re]=k.useState(null),[K,ne]=k.useState(""),U=k.useRef(null),E=k.useRef(null);k.useLayoutEffect(()=>{if(!M||!E.current)return;ne(he.scopeThemeClass(E.current));const m=()=>{const l=E.current?.getBoundingClientRect();if(!l)return;const N=280,w=360;let x=l.left,j=l.bottom+6;x+N>window.innerWidth-8&&(x=Math.max(8,window.innerWidth-N-8)),j+w>window.innerHeight-8&&(j=Math.max(8,l.top-w-6)),re({left:x,top:j})};return m(),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[M]),k.useEffect(()=>{if(!M)return;const m=l=>{const N=l.target;U.current?.contains(N)||E.current?.contains(N)||C(!1)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[M]),P.useOverlayFocus(U,{open:M,modal:!1,onClose:()=>C(!1)});const V=k.useRef(null);P.useRovingFocus(V,{orientation:"grid",itemSelector:".nice-color-picker__preset",wrap:!0});const te=k.useMemo(()=>[{key:"Enter",description:v("shortcuts.openPicker","Open color picker")},{key:"Arrow keys",description:v("shortcuts.navigatePresets","Navigate presets")}],[v]);return W?null:t.jsxs("div",{className:`nice-field nice-field--${Q} ${Z==="left"?"nice-field--label-left":""} ${I?"nice-color-picker--compact":""} ${O?"nice-field--loading":""} ${n||""}`,style:{...b,...T!=null&&{"--nice-field-label-width":typeof T=="number"?`${T}px`:T},...D!=null&&{"--nice-field-control-width":typeof D=="number"?`${D}px`:D}},"aria-busy":O||void 0,children:[a&&t.jsxs("label",{htmlFor:$,className:`nice-field__label ${p?"nice-field__label--required":""}`,children:[a,J&&t.jsx(P.NiceKeyboardHint,{shortcuts:te,size:"sm"})]}),t.jsx("div",{className:"nice-field__control",children:t.jsxs("div",{className:"nice-color-picker",children:[t.jsxs("div",{className:"nice-color-picker__preview-row",children:[t.jsx("div",{ref:E,className:"nice-color-picker__swatch",id:$,style:{background:c},onClick:m=>{m.stopPropagation(),r||C(l=>!l)},onKeyDown:m=>{!r&&(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),C(l=>!l))},role:"button",tabIndex:r?-1:0,"aria-disabled":r||void 0,"aria-label":v("colorPicker.openPalette","Open color palette"),"aria-haspopup":"dialog","aria-expanded":M,children:t.jsx("input",{ref:m=>{typeof F=="function"?F(m):F&&(F.current=m)},type:"hidden",value:c,disabled:r,readOnly:!0})}),X&&t.jsx("div",{className:"nice-input nice-input--sm",style:I?{flex:1,minWidth:0}:{width:100},children:t.jsx("input",{className:"nice-input__native",type:"text",value:c,disabled:r,onChange:m=>_?.(m.target.value),maxLength:S?9:7,"aria-label":v("colorPicker.hexValue","Hex value")})}),Y&&!I&&t.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-color-picker__random",onClick:ee,disabled:r,title:v("colorPicker.random","Random"),"aria-label":v("colorPicker.random","Random"),style:{fontSize:"0.65rem",textTransform:"uppercase",letterSpacing:"0.05em"},children:v("colorPicker.random","Random")}),O&&t.jsx("span",{className:"nice-field__spinner",children:t.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),L==="right"&&h&&t.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:h}),L==="right"&&!h&&u&&t.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:u})]}),M&&q&&typeof document<"u"&&me.createPortal(t.jsx("div",{ref:U,className:`nice-color-picker__popup nice-color-picker__popup--portal ${K}`,"data-theme":K==="nice-dark"?"dark":K==="nice-light"?"light":void 0,role:"dialog","aria-label":v("colorPicker.palette","Color palette"),style:{position:"fixed",left:q.left,top:q.top},onClick:m=>m.stopPropagation(),children:(()=>{const m=Ne(c),l={r:m.r,g:m.g,b:m.b},N=S?m.a:1,w=xe(l.r,l.g,l.b),x=ke(l.r,l.g,l.b),j=(e,f,g,s=N)=>_?.(je(e,f,g,s,S)),ie=(e,f,g)=>j(e,f,g),oe=(e,f,g)=>{const s=_e(e,f,g);j(s.r,s.g,s.b)},z=(e,f,g)=>{const s=ye(e,f,g);j(s.r,s.g,s.b)},G=e=>j(l.r,l.g,l.b,e),se=e=>{if(r)return;const f=e.currentTarget,g=y=>{const R=f.getBoundingClientRect(),le=Math.max(0,Math.min(R.width,y.clientX-R.left)),ue=Math.max(0,Math.min(R.height,y.clientY-R.top)),pe=Math.round(le/R.width*100),de=100-Math.round(ue/R.height*100);z(x.h,pe,de)};g(e);const s=()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",s)};document.addEventListener("pointermove",g),document.addEventListener("pointerup",s)},ae=`hsl(${x.h}, 100%, 50%)`,ce=e=>{if(r)return;const f=e.shiftKey?10:1;let{s:g,v:s}=x;if(e.key==="ArrowLeft")g-=f;else if(e.key==="ArrowRight")g+=f;else if(e.key==="ArrowDown")s-=f;else if(e.key==="ArrowUp")s+=f;else if(e.key==="PageDown")s-=10;else if(e.key==="PageUp")s+=10;else if(e.key==="Home")g=0;else if(e.key==="End")g=100;else return;e.preventDefault(),z(x.h,Math.max(0,Math.min(100,g)),Math.max(0,Math.min(100,s)))},H={h:v("colorPicker.hue","Hue"),s:v("colorPicker.saturation","Saturation"),l:v("colorPicker.lightness","Lightness"),r:v("colorPicker.red","Red"),g:v("colorPicker.green","Green"),b:v("colorPicker.blue","Blue")};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"nice-color-picker__popup-header",children:t.jsx("input",{type:"text",className:"nice-input__native nice-color-picker__popup-hex",value:c,disabled:r,onChange:e=>_?.(e.target.value),maxLength:S?9:7,"aria-label":v("colorPicker.hexValue","Hex value")})}),t.jsx("input",{type:"range",min:0,max:360,value:x.h,disabled:r,onChange:e=>z(Number(e.target.value),x.s,x.v),className:"nice-color-picker__hue-slider","aria-label":v("colorPicker.hue","Hue")}),t.jsx("div",{className:"nice-color-picker__sv",style:{background:`linear-gradient(to top, var(--nice-text, #000), transparent), linear-gradient(to right, var(--nice-bg, #FFF), ${ae})`},onPointerDown:se,onKeyDown:ce,role:"slider",tabIndex:r?-1:0,"aria-label":v("colorPicker.svPalette","Saturation/value palette"),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":x.s,"aria-valuetext":`${H.s} ${x.s}%, ${v("colorPicker.brightness","Brightness")} ${x.v}%`,children:t.jsx("span",{className:"nice-color-picker__sv-marker",style:{left:`${x.s}%`,top:`${100-x.v}%`}})}),t.jsxs("div",{className:"nice-color-picker__sliders",children:[t.jsx("div",{className:"nice-color-picker__slider-col",children:["h","s","l"].map(e=>{const f=e==="h"?360:100,g=w[e],s=y=>oe(e==="h"?y:w.h,e==="s"?y:w.s,e==="l"?y:w.l);return t.jsxs("div",{className:"nice-color-picker__slider-row",children:[t.jsx("label",{className:"nice-color-picker__slider-label",children:e.toUpperCase()}),t.jsx("input",{type:"range",min:0,max:f,value:g,disabled:r,onChange:y=>s(Number(y.target.value)),"aria-label":H[e]}),t.jsx("input",{type:"number",min:0,max:f,value:g,disabled:r,onChange:y=>s(Number(y.target.value)||0),className:"nice-input__native nice-color-picker__slider-num","aria-label":H[e]})]},e)})}),t.jsx("div",{className:"nice-color-picker__slider-col",children:["r","g","b"].map(e=>{const f=l[e],g=s=>ie(e==="r"?s:l.r,e==="g"?s:l.g,e==="b"?s:l.b);return t.jsxs("div",{className:"nice-color-picker__slider-row",children:[t.jsx("label",{className:"nice-color-picker__slider-label",children:e.toUpperCase()}),t.jsx("input",{type:"range",min:0,max:255,value:f,disabled:r,onChange:s=>g(Number(s.target.value)),"aria-label":H[e]}),t.jsx("input",{type:"number",min:0,max:255,value:f,disabled:r,onChange:s=>g(Number(s.target.value)||0),className:"nice-input__native nice-color-picker__slider-num","aria-label":H[e]})]},e)})})]}),S&&t.jsxs("div",{className:"nice-color-picker__alpha-row",children:[t.jsx("label",{className:"nice-color-picker__slider-label",children:"A"}),t.jsx("input",{type:"range",min:0,max:100,value:Math.round(N*100),disabled:r,onChange:e=>G(Number(e.target.value)/100),className:"nice-color-picker__alpha-slider",style:{background:`linear-gradient(to right, transparent, rgb(${l.r},${l.g},${l.b}))`},"aria-label":v("colorPicker.alpha","Alpha")}),t.jsx("input",{type:"number",min:0,max:100,value:Math.round(N*100),disabled:r,onChange:e=>G((Number(e.target.value)||0)/100),className:"nice-input__native nice-color-picker__slider-num","aria-label":v("colorPicker.alpha","Alpha")})]}),B.length>0&&t.jsx("div",{ref:V,className:"nice-color-picker__popup-presets",role:"group","aria-label":v("colorPicker.presets","Preset colors"),children:B.map(e=>t.jsx("div",{className:`nice-color-picker__preset ${c===e?"nice-color-picker__preset--active":""}`,style:{background:e},onClick:()=>{_?.(e),C(!1)},role:"button","aria-label":e,"aria-pressed":c===e,onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),_?.(e),C(!1))}},e))})]})})()}),document.body)]})}),L!=="right"&&h&&t.jsx("div",{id:`${$}-error`,className:"nice-field__error",role:"alert",children:h}),L!=="right"&&!h&&u&&t.jsx("div",{id:`${$}-helper`,className:"nice-field__helper",children:u})]})}),{displayName:"NiceColorPicker"});exports.NiceColorPicker=Me;exports.hexToRgb=ve;exports.rgbToHex=be;
|