@harnessio/yaml-editor 0.2.0
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 +1 -0
- package/dist/components/Problems.d.ts +23 -0
- package/dist/components/ProblemsPanel.d.ts +2 -0
- package/dist/components/YamlEditor.d.ts +21 -0
- package/dist/components/YamlProvider.d.ts +15 -0
- package/dist/hooks/useCodeLens.d.ts +12 -0
- package/dist/hooks/useProblems.d.ts +6 -0
- package/dist/hooks/useSchema.d.ts +11 -0
- package/dist/hooks/useTheme.d.ts +14 -0
- package/dist/hooks/utils.d.ts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/types/inline-actions.d.ts +9 -0
- package/dist/types/monaco.d.ts +10 -0
- package/dist/types/selectors.d.ts +17 -0
- package/dist/types/themes.d.ts +5 -0
- package/dist/utils/outline-model-to-path.d.ts +8 -0
- package/dist/utils/schema-utils.d.ts +4 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Yaml Editor
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare enum Severity {
|
|
3
|
+
ERROR = "error",
|
|
4
|
+
WARNING = "warning",
|
|
5
|
+
INFO = "info"
|
|
6
|
+
}
|
|
7
|
+
export interface Problem<T = unknown> {
|
|
8
|
+
severity: Severity;
|
|
9
|
+
message: string;
|
|
10
|
+
position: {
|
|
11
|
+
row: number;
|
|
12
|
+
column: number;
|
|
13
|
+
};
|
|
14
|
+
data?: T;
|
|
15
|
+
}
|
|
16
|
+
export interface ProblemsProps<T = unknown> {
|
|
17
|
+
problems: Problem<T>[];
|
|
18
|
+
onClick: (data: Problem<T>) => void;
|
|
19
|
+
/** Selected problem idx, for controlled mode*/
|
|
20
|
+
selectedProblemIdx?: number;
|
|
21
|
+
}
|
|
22
|
+
declare const Problems: <T>(props: ProblemsProps<T>) => React.ReactElement;
|
|
23
|
+
export { Problems };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PathSelector } from '../types/selectors';
|
|
3
|
+
import { InlineAction } from '../types/inline-actions';
|
|
4
|
+
import { ThemeDefinition } from '../types/themes';
|
|
5
|
+
export interface YamlEditorProps {
|
|
6
|
+
value: string;
|
|
7
|
+
schemaConfig?: {
|
|
8
|
+
schema: any;
|
|
9
|
+
uri: string;
|
|
10
|
+
};
|
|
11
|
+
inlineActions?: {
|
|
12
|
+
selectors: PathSelector[];
|
|
13
|
+
actions: InlineAction[];
|
|
14
|
+
}[];
|
|
15
|
+
themeConfig?: {
|
|
16
|
+
rootElementSelector: string;
|
|
17
|
+
defaultTheme?: string;
|
|
18
|
+
themes?: ThemeDefinition[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare function YamlEditor(props: YamlEditorProps): JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { editor } from 'monaco-editor';
|
|
3
|
+
export interface YamlEditorContextInterface {
|
|
4
|
+
markers: editor.IMarker[];
|
|
5
|
+
setMarkers: (markets: editor.IMarker[]) => void;
|
|
6
|
+
editor: editor.IEditor | null;
|
|
7
|
+
setEditor: (monacoEditor: editor.ICodeEditor) => void;
|
|
8
|
+
updateCursorPosition: (position: {
|
|
9
|
+
column: number;
|
|
10
|
+
lineNumber: number;
|
|
11
|
+
}) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const YamlEditorContext: React.Context<YamlEditorContextInterface>;
|
|
14
|
+
export declare function YamlEditorContextProvider({ children }: React.PropsWithChildren<{}>): React.ReactElement;
|
|
15
|
+
export declare function useYamlEditorContext(): YamlEditorContextInterface;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import * as monaco from 'monaco-editor';
|
|
3
|
+
import { PathSelector } from '../types/selectors';
|
|
4
|
+
import { InlineAction } from '../types/inline-actions';
|
|
5
|
+
export type UseCodeLenses = (arg: {
|
|
6
|
+
monacoRef: RefObject<typeof monaco | undefined>;
|
|
7
|
+
inlineActions?: {
|
|
8
|
+
selectors: PathSelector[];
|
|
9
|
+
actions: InlineAction[];
|
|
10
|
+
}[];
|
|
11
|
+
}) => void;
|
|
12
|
+
export declare const useCodeLenses: UseCodeLenses;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import * as monaco from "monaco-editor";
|
|
3
|
+
export type UseSchema = (arg: {
|
|
4
|
+
monacoRef: RefObject<typeof monaco | undefined>;
|
|
5
|
+
schemaConfig?: {
|
|
6
|
+
schema: any;
|
|
7
|
+
uri: string;
|
|
8
|
+
};
|
|
9
|
+
instanceId: string;
|
|
10
|
+
}) => void;
|
|
11
|
+
export declare const useSchema: UseSchema;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import * as monaco from 'monaco-editor';
|
|
3
|
+
import { ThemeDefinition } from '../types/themes';
|
|
4
|
+
export type UseTheme = (arg: {
|
|
5
|
+
monacoRef: RefObject<typeof monaco | undefined>;
|
|
6
|
+
themeConfig?: {
|
|
7
|
+
rootElementSelector: string;
|
|
8
|
+
defaultTheme?: string;
|
|
9
|
+
themes?: ThemeDefinition[];
|
|
10
|
+
};
|
|
11
|
+
}) => {
|
|
12
|
+
theme: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const useTheme: UseTheme;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as monaco from "monaco-editor";
|
|
2
|
+
import { PathSelector } from "../types/selectors";
|
|
3
|
+
import { InlineAction } from "../types/inline-actions";
|
|
4
|
+
export interface GetCodeLensProps {
|
|
5
|
+
pathSymbolMap: Map<string, monaco.languages.DocumentSymbol>;
|
|
6
|
+
inlineActions?: {
|
|
7
|
+
selectors: PathSelector[];
|
|
8
|
+
actions: InlineAction[];
|
|
9
|
+
}[];
|
|
10
|
+
commandId: string | any;
|
|
11
|
+
}
|
|
12
|
+
export declare function getCodeLens(props: GetCodeLensProps): monaco.languages.CodeLens[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { YamlEditorContext, YamlEditorContextInterface, YamlEditorContextProvider, useYamlEditorContext } from './components/YamlProvider';
|
|
2
|
+
export { YamlEditorContext, YamlEditorContextProvider, useYamlEditorContext };
|
|
3
|
+
export type { YamlEditorContextInterface };
|
|
4
|
+
import { YamlEditor, YamlEditorProps } from './components/YamlEditor';
|
|
5
|
+
export { YamlEditor };
|
|
6
|
+
export type { YamlEditorProps };
|
|
7
|
+
import { Problem, ProblemsProps } from './components/Problems';
|
|
8
|
+
export type { Problem, ProblemsProps };
|
|
9
|
+
import { ProblemsPanel } from './components/ProblemsPanel';
|
|
10
|
+
export { ProblemsPanel };
|
|
11
|
+
import { ThemeDefinition } from './types/themes';
|
|
12
|
+
export type { ThemeDefinition };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("monaco-editor"),require("monaco-yaml")):"function"==typeof define&&define.amd?define(["react","monaco-editor","monaco-yaml"],t):"object"==typeof exports?exports.YamlEditor=t(require("react"),require("monaco-editor"),require("monaco-yaml")):e.YamlEditor=t(e.react,e["monaco-editor"],e["monaco-yaml"])}(self,((e,t,r)=>(()=>{"use strict";var n={921:(e,t,r)=>{var n=r(155),o=Symbol.for("react.element"),i=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,a=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,r){var n,i={},l=null,s=null;for(n in void 0!==r&&(l=""+r),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(s=t.ref),t)c.call(t,n)&&!u.hasOwnProperty(n)&&(i[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===i[n]&&(i[n]=t[n]);return{$$typeof:o,type:e,key:l,ref:s,props:i,_owner:a.current}}t.Fragment=i,t.jsx=l,t.jsxs=l},723:(e,t,r)=>{e.exports=r(921)},839:e=>{e.exports=t},449:e=>{e.exports=r},155:t=>{t.exports=e}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,i),r.exports}i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var c={};i.r(c),i.d(c,{ProblemsPanel:()=>ke,YamlEditor:()=>ye,YamlEditorContext:()=>f,YamlEditorContextProvider:()=>d,useYamlEditorContext:()=>p});var a=i(723),u=i(155),l=i.n(u),s=function(){return s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},s.apply(this,arguments)},f=l().createContext({markers:[],setMarkers:function(){},editor:null,setEditor:function(e){},updateCursorPosition:function(e){}});function d(e){var t=e.children,r=(0,u.useState)([]),n=r[0],o=r[1],i=(0,u.useState)(null),c=i[0],l=i[1],d=(0,u.useCallback)((function(e){null==c||c.setPosition(e),null==c||c.focus()}),[c]);return(0,a.jsx)(f.Provider,s({value:{markers:n,setMarkers:o,editor:c,setEditor:l,updateCursorPosition:d}},{children:t}))}function p(){return l().useContext(f)}var g=i(839);function m(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){m(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function O(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function j(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?O(Object(r),!0).forEach((function(t){b(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):O(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function w(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return o.length>=e.length?e.apply(this,o):function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return t.apply(r,[].concat(o,n))}}}function E(e){return{}.toString.call(e).includes("Object")}function x(e){return"function"==typeof e}var M=w((function(e,t){throw new Error(e[t]||e.default)}))({initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"}),R=function(e,t){return E(t)||M("changeType"),Object.keys(t).some((function(t){return r=e,n=t,!Object.prototype.hasOwnProperty.call(r,n);var r,n}))&&M("changeField"),t},S=function(e){x(e)||M("selectorType")},P=function(e){x(e)||E(e)||M("handlerType"),E(e)&&Object.values(e).some((function(e){return!x(e)}))&&M("handlersType")},k=function(e){var t;e||M("initialIsRequired"),E(e)||M("initialType"),t=e,Object.keys(t).length||M("initialContent")};function C(e,t){return x(t)?t(e.current):t}function N(e,t){return e.current=j(j({},e.current),t),t}function I(e,t,r){return x(t)?t(e.current):Object.keys(r).forEach((function(r){var n;return null===(n=t[r])||void 0===n?void 0:n.call(t,e.current[r])})),r}const _=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};k(e),P(t);var r={current:e},n=w(I)(r,t),o=w(N)(r),i=w(R)(e),c=w(C)(r);return[function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(e){return e};return S(e),e(r.current)},function(e){!function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.reduceRight((function(e,t){return t(e)}),e)}}(n,o,i,c)(e)}]};var T,L={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:"Deprecation warning!\n You are using deprecated way of configuration.\n\n Instead of using\n monaco.config({ urls: { monacoBase: '...' } })\n use\n monaco.config({ paths: { vs: '...' } })\n\n For more please check the link https://github.com/suren-atoyan/monaco-loader#config\n "},A=(T=function(e,t){throw new Error(e[t]||e.default)},function e(){for(var t=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return n.length>=T.length?T.apply(this,n):function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];return e.apply(t,[].concat(n,o))}})(L);const D={config:function(e){return e||A("configIsRequired"),t=e,{}.toString.call(t).includes("Object")||A("configType"),e.urls?(console.warn(L.deprecation),{paths:{vs:e.urls.monacoBase}}):e;var t}},q=function e(t,r){return Object.keys(r).forEach((function(n){r[n]instanceof Object&&t[n]&&Object.assign(r[n],e(t[n],r[n]))})),h(h({},t),r)};var V={type:"cancelation",msg:"operation is manually canceled"};const F=function(e){var t=!1,r=new Promise((function(r,n){e.then((function(e){return t?n(V):r(e)})),e.catch(n)}));return r.cancel=function(){return t=!0},r};var Y,z=function(e){if(Array.isArray(e))return e}(Y=_({config:{paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.43.0/min/vs"}},isInitialized:!1,resolve:null,reject:null,monaco:null}))||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var t=[],r=!0,n=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(r=(i=c.next()).done)&&(t.push(i.value),2!==t.length);r=!0);}catch(e){n=!0,o=e}finally{try{r||null==c.return||c.return()}finally{if(n)throw o}}return t}}(Y)||function(e){if(e){if("string"==typeof e)return y(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?y(e,2):void 0}}(Y)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),U=z[0],W=z[1];function B(e){return document.body.appendChild(e)}function G(e){var t,r,n=U((function(e){return{config:e.config,reject:e.reject}})),o=(t="".concat(n.config.paths.vs,"/loader.js"),r=document.createElement("script"),t&&(r.src=t),r);return o.onload=function(){return e()},o.onerror=n.reject,o}function $(){var e=U((function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}})),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],(function(t){H(t),e.resolve(t)}),(function(t){e.reject(t)}))}function H(e){U().monaco||W({monaco:e})}var J=new Promise((function(e,t){return W({resolve:e,reject:t})})),K={config:function(e){var t=D.config(e),r=t.monaco,n=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["monaco"]);W((function(e){return{config:q(e.config,n),monaco:r}}))},init:function(){var e=U((function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}}));if(!e.isInitialized){if(W({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),F(J);if(window.monaco&&window.monaco.editor)return H(window.monaco),e.resolve(window.monaco),F(J);!function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.reduceRight((function(e,t){return t(e)}),e)}}(B,G)($)}return F(J)},__getMonacoInstance:function(){return U((function(e){return e.monaco}))}};const Q=K;var X={display:"flex",position:"relative",textAlign:"initial"},Z={width:"100%"},ee={display:"none"},te={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},re=function({children:e}){return u.createElement("div",{style:te.container},e)},ne=(0,u.memo)((function({width:e,height:t,isEditorReady:r,loading:n,_ref:o,className:i,wrapperProps:c}){return u.createElement("section",{style:{...X,width:e,height:t},...c},!r&&u.createElement(re,null,n),u.createElement("div",{ref:o,style:{...Z,...!r&&ee},className:i}))})),oe=function(e){(0,u.useEffect)(e,[])},ie=function(e,t,r=!0){let n=(0,u.useRef)(!0);(0,u.useEffect)(n.current||!r?()=>{n.current=!1}:e,t)};function ce(){}function ae(e,t,r,n){return function(e,t){return e.editor.getModel(ue(e,t))}(e,n)||function(e,t,r,n){return e.editor.createModel(t,r,n?ue(e,n):void 0)}(e,t,r,n)}function ue(e,t){return e.Uri.parse(t)}(0,u.memo)((function({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:i,modifiedModelPath:c,keepCurrentOriginalModel:a=!1,keepCurrentModifiedModel:l=!1,theme:s="light",loading:f="Loading...",options:d={},height:p="100%",width:g="100%",className:m,wrapperProps:v={},beforeMount:h=ce,onMount:y=ce}){let[b,O]=(0,u.useState)(!1),[j,w]=(0,u.useState)(!0),E=(0,u.useRef)(null),x=(0,u.useRef)(null),M=(0,u.useRef)(null),R=(0,u.useRef)(y),S=(0,u.useRef)(h),P=(0,u.useRef)(!1);oe((()=>{let e=Q.init();return e.then((e=>(x.current=e)&&w(!1))).catch((e=>"cancelation"!==e?.type&&console.error("Monaco initialization: error:",e))),()=>E.current?function(){let e=E.current?.getModel();a||e?.original?.dispose(),l||e?.modified?.dispose(),E.current?.dispose()}():e.cancel()})),ie((()=>{if(E.current&&x.current){let t=E.current.getOriginalEditor(),o=ae(x.current,e||"",n||r||"text",i||"");o!==t.getModel()&&t.setModel(o)}}),[i],b),ie((()=>{if(E.current&&x.current){let e=E.current.getModifiedEditor(),n=ae(x.current,t||"",o||r||"text",c||"");n!==e.getModel()&&e.setModel(n)}}),[c],b),ie((()=>{let e=E.current.getModifiedEditor();e.getOption(x.current.editor.EditorOption.readOnly)?e.setValue(t||""):t!==e.getValue()&&(e.executeEdits("",[{range:e.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),e.pushUndoStop())}),[t],b),ie((()=>{E.current?.getModel()?.original.setValue(e||"")}),[e],b),ie((()=>{let{original:e,modified:t}=E.current.getModel();x.current.editor.setModelLanguage(e,n||r||"text"),x.current.editor.setModelLanguage(t,o||r||"text")}),[r,n,o],b),ie((()=>{x.current?.editor.setTheme(s)}),[s],b),ie((()=>{E.current?.updateOptions(d)}),[d],b);let k=(0,u.useCallback)((()=>{if(!x.current)return;S.current(x.current);let a=ae(x.current,e||"",n||r||"text",i||""),u=ae(x.current,t||"",o||r||"text",c||"");E.current?.setModel({original:a,modified:u})}),[r,t,o,e,n,i,c]),C=(0,u.useCallback)((()=>{!P.current&&M.current&&(E.current=x.current.editor.createDiffEditor(M.current,{automaticLayout:!0,...d}),k(),x.current?.editor.setTheme(s),O(!0),P.current=!0)}),[d,s,k]);return(0,u.useEffect)((()=>{b&&R.current(E.current,x.current)}),[b]),(0,u.useEffect)((()=>{!j&&!b&&C()}),[j,b,C]),u.createElement(ne,{width:g,height:p,isEditorReady:b,loading:f,_ref:M,className:m,wrapperProps:v})}));var le=function(){let[e,t]=(0,u.useState)(Q.__getMonacoInstance());return oe((()=>{let r;return e||(r=Q.init(),r.then((e=>{t(e)}))),()=>r?.cancel()})),e},se=new Map,fe=(0,u.memo)((function({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:i,theme:c="light",line:a,loading:l="Loading...",options:s={},overrideServices:f={},saveViewState:d=!0,keepCurrentModel:p=!1,width:g="100%",height:m="100%",className:v,wrapperProps:h={},beforeMount:y=ce,onMount:b=ce,onChange:O,onValidate:j=ce}){let[w,E]=(0,u.useState)(!1),[x,M]=(0,u.useState)(!0),R=(0,u.useRef)(null),S=(0,u.useRef)(null),P=(0,u.useRef)(null),k=(0,u.useRef)(b),C=(0,u.useRef)(y),N=(0,u.useRef)(),I=(0,u.useRef)(n),_=function(e){let t=(0,u.useRef)();return(0,u.useEffect)((()=>{t.current=e}),[e]),t.current}(i),T=(0,u.useRef)(!1),L=(0,u.useRef)(!1);oe((()=>{let e=Q.init();return e.then((e=>(R.current=e)&&M(!1))).catch((e=>"cancelation"!==e?.type&&console.error("Monaco initialization: error:",e))),()=>S.current?(N.current?.dispose(),p?d&&se.set(i,S.current.saveViewState()):S.current.getModel()?.dispose(),void S.current.dispose()):e.cancel()})),ie((()=>{let c=ae(R.current,e||n||"",t||o||"",i||r||"");c!==S.current?.getModel()&&(d&&se.set(_,S.current?.saveViewState()),S.current?.setModel(c),d&&S.current?.restoreViewState(se.get(i)))}),[i],w),ie((()=>{S.current?.updateOptions(s)}),[s],w),ie((()=>{!S.current||void 0===n||(S.current.getOption(R.current.editor.EditorOption.readOnly)?S.current.setValue(n):n!==S.current.getValue()&&(L.current=!0,S.current.executeEdits("",[{range:S.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),S.current.pushUndoStop(),L.current=!1))}),[n],w),ie((()=>{let e=S.current?.getModel();e&&o&&R.current?.editor.setModelLanguage(e,o)}),[o],w),ie((()=>{void 0!==a&&S.current?.revealLine(a)}),[a],w),ie((()=>{R.current?.editor.setTheme(c)}),[c],w);let A=(0,u.useCallback)((()=>{if(P.current&&R.current&&!T.current){C.current(R.current);let u=i||r,l=ae(R.current,n||e||"",t||o||"",u||"");S.current=R.current?.editor.create(P.current,{model:l,automaticLayout:!0,...s},f),d&&S.current.restoreViewState(se.get(u)),R.current.editor.setTheme(c),void 0!==a&&S.current.revealLine(a),E(!0),T.current=!0}}),[e,t,r,n,o,i,s,f,d,c,a]);return(0,u.useEffect)((()=>{w&&k.current(S.current,R.current)}),[w]),(0,u.useEffect)((()=>{!x&&!w&&A()}),[x,w,A]),I.current=n,(0,u.useEffect)((()=>{w&&O&&(N.current?.dispose(),N.current=S.current?.onDidChangeModelContent((e=>{L.current||O(S.current.getValue(),e)})))}),[w,O]),(0,u.useEffect)((()=>{if(w){let e=R.current.editor.onDidChangeMarkers((e=>{let t=S.current.getModel()?.uri;if(t&&e.find((e=>e.path===t.path))){let e=R.current.editor.getModelMarkers({resource:t});j?.(e)}}));return()=>{e?.dispose()}}return()=>{}}),[w,j]),u.createElement(ne,{width:g,height:m,isEditorReady:w,loading:l,_ref:P,className:v,wrapperProps:h})})),de=function(e){var t=e.monacoRef,r=e.themeConfig,n=null!=r?r:{},o=(n.rootElementSelector,n.defaultTheme),i=(0,u.useState)(null!=o?o:"vs-dark"),c=i[0],a=i[1];return(0,u.useEffect)((function(){var e,n;if(t.current){var o=null===(e=t.current)||void 0===e?void 0:e.editor;null===(n=null==r?void 0:r.themes)||void 0===n||n.forEach((function(e){o.defineTheme(e.themeName,e.themeData)}))}}),[t]),(0,u.useEffect)((function(){var e;if((null===(e=t.current)||void 0===e?void 0:e.editor)&&(null==r?void 0:r.rootElementSelector)){var n=document.querySelector(r.rootElementSelector);if(n){var o=new MutationObserver((function(){var e,r=n.classList.contains("harness-dark")?"harness-dark":"harness-light";if(c!==r){a(r);var o=null===(e=t.current)||void 0===e?void 0:e.editor;null==o||o.setTheme(r)}}));return o.observe(n,{attributes:!0,childList:!1,subtree:!1}),function(){o.disconnect()}}}})),{theme:c}},pe=i(449);var ge=function(e){return g.Uri.parse("file://".concat(e)).toString()},me=function(){return me=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},me.apply(this,arguments)},ve=function(e){var t=e.monacoRef,r=e.schemaConfig,n=e.instanceId;(0,u.useEffect)((function(){t.current&&(null==r?void 0:r.schema)&&function(e,t){!function(e,t){(0,pe.configureMonacoYaml)(e,{hover:!0,completion:!0,enableSchemaRequest:!1,validate:!0,schemas:t})}(t,[e])}(me({fileMatch:[ge(n.toString())]},r),t.current)}),[t,r,n])},he=function(e){var t=e.monacoRef,r=p().setMarkers;(0,u.useEffect)((function(){var e,n=null===(e=t.current)||void 0===e?void 0:e.editor;if(n){var o=n.onDidChangeMarkers((function(e){var t=e[0],o=n.getModelMarkers({resource:t});r(o)}));return function(){o.dispose()}}}),[t])};function ye(e){var t=e.value,r=e.schemaConfig,n=(e.inlineActions,e.themeConfig),o=le(),i=(0,u.useState)(Math.random().toString())[0],c=p().setEditor,l=(0,u.useRef)();(0,u.useEffect)((function(){o&&!l.current&&(l.current=o,console.log(o.editor.getEditors()),setTimeout((function(){var e,t;console.log(null===(e=l.current)||void 0===e?void 0:e.editor.getEditors()),c(null===(t=l.current)||void 0===t?void 0:t.editor.getEditors()[0])}),100))}),[o]),ve({monacoRef:l,schemaConfig:r,instanceId:i});var s=de({monacoRef:l,themeConfig:n}).theme;return he({monacoRef:l}),(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(fe,{language:"yaml",theme:s,value:t,options:{selectOnLineNumbers:!0},path:ge(i.toString())})})}Q.config({monaco:g});var be,Oe=function(){return Oe=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Oe.apply(this,arguments)};!function(e){e.ERROR="error",e.WARNING="warning",e.INFO="info"}(be||(be={}));var je=function(e){switch(e){case be.ERROR:return(0,a.jsx)("div",Oe({className:"text-[#f76e6e]"},{children:"ERROR"}));case be.WARNING:return(0,a.jsx)("div",Oe({className:"text-[#E29B36]"},{children:"WARNING"}));case be.INFO:return(0,a.jsx)("div",Oe({className:"text-[#f76e6e]"},{children:"INFO"}))}},we=function(e){var t=e.children;return(0,a.jsx)("div",Oe({className:"text-[13px] text-[#c9c9cf] leading-[15px] min-h-12 bg-[#070709] overflow-scroll"},{children:t}))},Ee=function(e){var t=e.selected,r=e.onClick,n=e.children,o=t?"bg-gray-700 text-white":"";return(0,a.jsx)("div",Oe({onClick:r,className:"flex flex-1 items-center width-100 text-nowrap gap-2 py-[4px] cursor-pointer ".concat(o)},{children:n}))},xe=function(e){var t=e.severity;return(0,a.jsx)("div",Oe({className:"pl-2"},{children:je(t)}))},Me=function(e){var t=e.message;return(0,a.jsx)("div",Oe({className:"flex overflow-hidden items-center"},{children:(0,a.jsx)("span",Oe({className:"truncate"},{children:t}))}))},Re=function(e){var t=e.position;return(0,a.jsxs)("div",Oe({className:"text-nowrap pr-2 text-[#93939f]"},{children:["[",t.row,", ",t.column,"]"]}))},Se=function(e){var t=e.problems,r=e.onClick,n=e.selectedProblemIdx,o=(0,u.useState)(),i=o[0],c=o[1];return(0,a.jsx)(we,{children:t.map((function(e,t){var o=e.message,u=e.position,l=e.severity,s=(void 0!==n?n:i)===t;return(0,a.jsxs)(Ee,Oe({selected:s,onClick:function(){void 0===n&&c(t),r(e)}},{children:[(0,a.jsx)(xe,{severity:l}),(0,a.jsx)(Me,{message:o}),(0,a.jsx)(Re,{position:u})]}))}))})},Pe=function(e){switch(e){case g.MarkerSeverity.Error:return be.ERROR;case g.MarkerSeverity.Warning:return be.WARNING;case g.MarkerSeverity.Hint:case g.MarkerSeverity.Info:return be.INFO}};function ke(){var e=p(),t=e.markers,r=e.updateCursorPosition,n=t.map((function(e){return{message:e.message,position:{row:e.startLineNumber,column:e.startColumn},severity:Pe(e.severity),data:e}}));return(0,a.jsx)(Se,{problems:n,onClick:function(e){var t,n,o,i;(null===(t=e.data)||void 0===t?void 0:t.startLineNumber)&&(null===(n=e.data)||void 0===n?void 0:n.startColumn)&&r({lineNumber:null===(o=e.data)||void 0===o?void 0:o.startLineNumber,column:null===(i=e.data)||void 0===i?void 0:i.startColumn})}})}return c})()));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as monaco from "monaco-editor";
|
|
2
|
+
/** Internal structure of OutlineModel */
|
|
3
|
+
export interface OutlineModelValueInternal {
|
|
4
|
+
children: Map<string, OutlineModelValueInternal>;
|
|
5
|
+
symbol: monaco.languages.DocumentSymbol;
|
|
6
|
+
}
|
|
7
|
+
/** Internal structure of OutlineModel */
|
|
8
|
+
export interface RootOutlineModelInternal {
|
|
9
|
+
children: Map<string, OutlineModelValueInternal>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare enum SelectorType {
|
|
2
|
+
AbsolutePath = "AbsolutePath",
|
|
3
|
+
ContainsPath = "ContainsPath"
|
|
4
|
+
}
|
|
5
|
+
export interface ContainsPathSelector {
|
|
6
|
+
type: SelectorType.ContainsPath;
|
|
7
|
+
/** Path have to starts with `basePath`*/
|
|
8
|
+
basePath: string;
|
|
9
|
+
/** Path have to contains one of provided path. Base path is not included in match.*/
|
|
10
|
+
paths: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface AbsolutePathSelector {
|
|
13
|
+
type: SelectorType.AbsolutePath;
|
|
14
|
+
/** Path have to be equal with `absolutePaths`*/
|
|
15
|
+
absolutePaths: string[];
|
|
16
|
+
}
|
|
17
|
+
export type PathSelector = ContainsPathSelector | AbsolutePathSelector;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ILanguageFeaturesService } from 'monaco-editor/esm/vs/editor/common/services/languageFeatures.js';
|
|
2
|
+
import { OutlineModel } from 'monaco-editor/esm/vs/editor/contrib/documentSymbols/browser/outlineModel.js';
|
|
3
|
+
import { StandaloneServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
|
|
4
|
+
import { editor, languages } from 'monaco-editor';
|
|
5
|
+
import { RootOutlineModelInternal } from '../types/monaco';
|
|
6
|
+
export { ILanguageFeaturesService, OutlineModel, StandaloneServices };
|
|
7
|
+
export declare function getOutlineModel(model: editor.ITextModel): Promise<RootOutlineModelInternal>;
|
|
8
|
+
export declare function processOutlineModel(outlineModel: RootOutlineModelInternal): Map<string, languages.DocumentSymbol>;
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@harnessio/yaml-editor",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"author": "Harness Inc.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@monaco-editor/react": "4.6.0",
|
|
15
|
+
"monaco-editor": "0.50.0",
|
|
16
|
+
"monaco-yaml": "5.2.1",
|
|
17
|
+
"react": "^18.3.1",
|
|
18
|
+
"react-dom": "^18.3.1"
|
|
19
|
+
},
|
|
20
|
+
"eslintConfig": {
|
|
21
|
+
"extends": [
|
|
22
|
+
"react-app",
|
|
23
|
+
"react-app/jest"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"watch": "^1.0.2",
|
|
28
|
+
"@babel/core": "^7.24.7",
|
|
29
|
+
"@babel/preset-env": "^7.24.7",
|
|
30
|
+
"@babel/preset-react": "^7.24.7",
|
|
31
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
32
|
+
"@testing-library/jest-dom": "^5.17.0",
|
|
33
|
+
"@testing-library/react": "^13.4.0",
|
|
34
|
+
"@testing-library/user-event": "^13.5.0",
|
|
35
|
+
"@types/jest": "^27.5.2",
|
|
36
|
+
"@types/node": "^16.18.101",
|
|
37
|
+
"@types/react": "^18.3.3",
|
|
38
|
+
"@types/react-dom": "^18.3.0",
|
|
39
|
+
"babel-loader": "^9.1.3",
|
|
40
|
+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
|
41
|
+
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
42
|
+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
|
43
|
+
"css-loader": "^7.1.2",
|
|
44
|
+
"file-loader": "^6.2.0",
|
|
45
|
+
"html-webpack-plugin": "^5.6.0",
|
|
46
|
+
"mini-css-extract-plugin": "^2.9.0",
|
|
47
|
+
"monaco-editor-webpack-plugin": "^7.1.0",
|
|
48
|
+
"sass-loader": "^14.2.1",
|
|
49
|
+
"style-loader": "^4.0.0",
|
|
50
|
+
"ts-loader": "^9.5.1",
|
|
51
|
+
"typescript": "^4.9.5",
|
|
52
|
+
"url-loader": "^4.1.1",
|
|
53
|
+
"webpack": "^5.92.1",
|
|
54
|
+
"webpack-cli": "^5.1.4",
|
|
55
|
+
"webpack-dev-server": "^5.0.4"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"webpack": "webpack",
|
|
59
|
+
"build": "pnpm run webpack --config webpack.config.prod.js",
|
|
60
|
+
"watch:build": "watch 'pnpm build-yalc' ./src",
|
|
61
|
+
"build-yalc": "pnpm build && pnpm yalc-push",
|
|
62
|
+
"yalc-push": "yalc push"
|
|
63
|
+
}
|
|
64
|
+
}
|