@fast-crud/editor-code 1.27.0 → 1.27.1
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 +4 -0
- package/dist/editor-code.mjs +1 -1
- package/dist/editor-code.umd.js +1 -1
- package/dist/editor-code.umd.js.map +1 -1
- package/dist/{index-5677963c.mjs → index-4cfdb04c.mjs} +31 -33
- package/dist/index-4cfdb04c.mjs.map +1 -0
- package/dist/{index-551dfd5e.mjs → index-c2ddaf47.mjs} +2 -2
- package/dist/{index-551dfd5e.mjs.map → index-c2ddaf47.mjs.map} +1 -1
- package/package.json +3 -3
- package/stats.html +1 -1
- package/dist/index-5677963c.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.27.1](https://github.com/fast-crud/fast-crud/compare/v1.27.0...v1.27.1) (2025-09-22)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @fast-crud/editor-code
|
|
9
|
+
|
|
6
10
|
# [1.27.0](https://github.com/fast-crud/fast-crud/compare/v1.26.6...v1.27.0) (2025-09-19)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @fast-crud/editor-code
|
package/dist/editor-code.mjs
CHANGED
package/dist/editor-code.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("monaco-editor"),require("lodash-es"),require("@fast-crud/fast-crud")):typeof define=="function"&&define.amd?define(["exports","vue","monaco-editor","lodash-es","@fast-crud/fast-crud"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.FsExtends={},a.Vue,a.monaco,a._,a.FastCrud))})(this,function(a,i,_,f,p){"use strict";function
|
|
1
|
+
(function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("monaco-editor"),require("lodash-es"),require("@fast-crud/fast-crud")):typeof define=="function"&&define.amd?define(["exports","vue","monaco-editor","lodash-es","@fast-crud/fast-crud"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.FsExtends={},a.Vue,a.monaco,a._,a.FastCrud))})(this,function(a,i,_,f,p){"use strict";function v(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(o,e,r.get?r:{enumerable:!0,get:()=>t[e]})}}return o.default=t,Object.freeze(o)}const c=v(_);async function b(){return await import("js-yaml")}async function j(){await import("monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution")}async function V(){await import("monaco-editor/esm/vs/language/json/monaco.contribution")}async function k(){await import("monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution")}async function E(){return await import("monaco-yaml")}const g=[];function C(t,o){g.push({worker:o,match:e=>{if(typeof t=="string")return t===e;for(const r of t)if(r==="*"||r===e)return!0;return!1}})}function y(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorker(t,o){for(const e of g)if(e.match(o))return new e.worker}})}const M=i.defineComponent({__name:"index",props:{language:{},modelValue:{},config:{},schema:{},debounce:{},init:{},readonly:{type:Boolean},disabled:{type:Boolean},id:{}},emits:["update:modelValue","change","ready"],setup(t,{emit:o}){const e=t;y();const r=i.ref();let u=null;function d(){u&&u.dispose()}i.onUnmounted(()=>{d()});const m=o,D=f.debounce(n=>{m("update:modelValue",n)},e.debounce||500);async function W(n){d();const s=c.editor.create(r.value,{automaticLayout:!0,value:e.modelValue,language:n.language,theme:"vs-dark",minimap:{enabled:!1},readOnly:e.readonly||e.disabled,hover:{enabled:!0},...n.config});return s.onDidChangeModelContent(w=>{const l=s.getValue();e.modelValue!==l&&(m("change",l),D(l))}),u=s,n.instance=s,m("ready",n),s}async function B(n){await k(),c.languages.register({id:"javascript"})}async function Y(n){await V(),c.languages.register({id:"json"});const s=[];n.schema&&s.push({uri:"http://myserver/foo-schema.json",fileMatch:["*"],schema:{...n.schema}}),c.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,enableSchemaRequest:!1,schemas:s})}async function x(n){await j();const{configureMonacoYaml:s}=await E();c.languages.register({id:"yaml"});let w=`fs-editor-code-yaml-${e.id||""}.yaml`;const l=[];n.schema&&l.push({fileMatch:["*"],schema:{...n.schema},uri:`http://myserver/${w}`}),s(c,{schemas:l,format:!0,hover:!0,completion:!0,validate:!0,isKubernetes:!1,enableSchemaRequest:!1})}async function h(){d();const n={monaco:c,language:e.language||"javascript",config:f.cloneDeep(e.config||{}),initialValue:e.modelValue||"",schema:e.schema};n.language==="javascript"?await B():n.language==="yaml"?await x(n):n.language==="json"&&await Y(n),await W(n)}return i.onMounted(async()=>{await h(),i.watch(()=>({language:e.language,config:e.config}),n=>{h()})}),i.watch(()=>e.modelValue,n=>{u&&u.getValue()!==n&&u.setValue(n)}),(n,s)=>(i.openBlock(),i.createElementBlock("div",{ref_key:"monacoRef",ref:r,class:"fs-editor-code"},null,512))}}),P="",O=Object.freeze(Object.defineProperty({__proto__:null,default:M},Symbol.toStringTag,{value:"Module"}));function S(){return{"editor-code":{form:{component:{name:"fs-editor-code"},col:{span:24}}}}}const R={install(t,o){const e=S(),{addTypes:r}=p.useTypes();r(e)}},T={jsonRule:{validator:async(t,o)=>{if(o)try{JSON.parse(o)}catch(e){throw console.error(e),new Error("json格式错误:"+e.message)}},message:"json格式错误"},yamlRule:{validator:async(t,o)=>{if(o)try{const e=await b();e.load(o,{schema:e.JSON_SCHEMA})}catch(e){throw console.error(e),new Error("yaml格式错误:"+e.message)}},message:"yaml格式错误"}},F=Object.assign({"./components/fs-editor-code/index.vue":O}),J={install(t){p.utils.vite.installSyncComponents(t,F,null,/^.*\/([^\/]+)\/.*.vue$/,null)}},q={install(t,o){t.use(R,o),t.use(J)}};a.FsEditorCode=q,a.FsEditorCodeValidators=T,a.initWorkers=y,a.registerWorker=C,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=editor-code.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-code.umd.js","sources":["../../src/editor/components/fs-editor-code/async-import.ts","../../src/editor/components/fs-editor-code/workers.ts","../src/editor/components/fs-editor-code/index.vue","../../src/editor/type/types.ts","../../src/editor/type/index.ts","../../src/editor/components/fs-editor-code/validators.ts","../../src/editor/index.umd.ts"],"sourcesContent":[null,null,"<template>\n <div ref=\"monacoRef\" class=\"fs-editor-code\"></div>\n</template>\n\n<script lang=\"ts\" setup>\nimport * as monaco from \"monaco-editor\";\n// import * as monaco from \"monaco-editor/esm/vs/editor/editor.api\";\nimport { onMounted, onUnmounted, ref, watch } from \"vue\";\nimport { cloneDeep, debounce as lodashDebounce } from \"lodash-es\";\nimport {\n importJavascriptContribution,\n importJsonContribution,\n importMonacoYaml,\n importYamlContribution\n} from \"./async-import\";\nimport { initWorkers } from \"./workers\";\n/**\n * config:\n * value: '', // 编辑器初始文本\n * language: 'javascript', // 语言\n * theme: 'vs', // 主题\n * readOnly: false, // 是否只读\n * minimap: { enabled: false }, // 是否启用小地图\n * fontSize: 14, // 字体大小\n * tabSize: 2, // tab缩进长度\n * automaticLayout: true, // 自动布局\n * lineNumbers: 'off', // 是否启用行号\n * contextmenu: true, // 是否启用上下文菜单\n * folding: true, // 是否启用代码折叠\n * foldingStrategy: 'auto', // 代码折叠策略\n * wordWrap: 'on', // 自动换行设置\n * wrappingIndent: 'indent', // 换行缩进\n * formatOnPaste: true, // 粘贴时是否自动格式化\n * formatOnType: true, // 输入时是否自动格式化\n * dragAndDrop: true, // 是否允许拖放\n * cursorStyle: 'line', // 光标样式\n * cursorBlinking: 'blink', // 光标闪烁方式\n * scrollbar: {\n * vertical: 'auto', // 垂直滚动条的显示方式\n * horizontal: 'auto', // 水平滚动条的显示方式\n * verticalScrollbarSize: 2, // 垂直滚动条的宽\n * horizontalScrollbarSize: 2, // 水平滚动条的高度\n * }\n */\nconst props = defineProps<{\n language?: string;\n modelValue?: string;\n config?: any;\n schema?: any;\n debounce?: number;\n init?: any;\n readonly?: boolean;\n disabled?: boolean;\n id?: string;\n}>();\n\nexport type EditorCodeCtx = {\n // monaco对象\n monaco: any;\n //语言\n language: string;\n //配置\n config: any;\n //editor实例对象\n instance?: any;\n\n schema?: any;\n\n initialValue?: any;\n};\ninitWorkers();\nconst monacoRef = ref();\n\nlet instanceRef: any = null;\n\nfunction disposeEditor() {\n if (instanceRef) {\n instanceRef.dispose(); //使用完成销毁实例\n }\n}\n\nonUnmounted(() => {\n disposeEditor();\n});\n\nconst emits = defineEmits([\"update:modelValue\", \"change\", \"ready\", \"blur\", \"blur2\"]);\n\nconst emitValue = lodashDebounce((value: any) => {\n emits(\"update:modelValue\", value);\n}, props.debounce || 500);\n\nasync function createEditor(ctx: EditorCodeCtx) {\n disposeEditor();\n const instance = monaco.editor.create(monacoRef.value, {\n automaticLayout: true,\n value: props.modelValue,\n language: ctx.language,\n theme: \"vs-dark\",\n minimap: { enabled: false },\n readOnly: props.readonly || props.disabled,\n hover: {\n enabled: true\n },\n ...ctx.config\n });\n\n // @event `change`\n instance.onDidChangeModelContent((event) => {\n const value = instance.getValue();\n if (props.modelValue !== value) {\n emits(\"change\", value);\n emitValue(value);\n }\n });\n\n instanceRef = instance;\n ctx.instance = instance;\n\n instance.onDidBlurEditorText(() => {\n console.error(\"onDidBlurEditorText\", ctx);\n emits(\"blur\", ctx);\n emits(\"blur2\", ctx);\n });\n\n emits(\"ready\", ctx);\n return instance;\n}\n\nasync function initJavascript(ctx: EditorCodeCtx) {\n await importJavascriptContribution();\n monaco.languages.register({ id: \"javascript\" });\n}\n\nasync function initJson(ctx: EditorCodeCtx) {\n await importJsonContribution();\n monaco.languages.register({ id: \"json\" });\n\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n uri: \"http://myserver/foo-schema.json\", // id of the first schema\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n }\n });\n }\n\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n validate: true,\n enableSchemaRequest: false,\n schemas\n });\n}\n\nasync function initYaml(ctx: EditorCodeCtx) {\n await importYamlContribution();\n const { configureMonacoYaml } = await importMonacoYaml();\n monaco.languages.register({ id: \"yaml\" });\n let id = `fs-editor-code-yaml-${props.id || \"\"}.yaml`;\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n },\n uri: `http://myserver/${id}`\n });\n }\n configureMonacoYaml(monaco, {\n schemas,\n format: true,\n hover: true,\n completion: true,\n validate: true,\n isKubernetes: false,\n enableSchemaRequest: false\n });\n\n // const uri = monaco.Uri.parse(id);\n // const oldModel = monaco.editor.getModel(uri);\n // if (oldModel) {\n // oldModel.dispose();\n // }\n // ctx.config.model = monaco.editor.createModel(props.modelValue, null, uri);\n}\n\nasync function doInit() {\n disposeEditor();\n const ctx: EditorCodeCtx = {\n monaco,\n language: props.language || \"javascript\",\n config: cloneDeep(props.config || {}),\n initialValue: props.modelValue || \"\",\n schema: props.schema\n };\n if (ctx.language === \"javascript\") {\n await initJavascript(ctx);\n } else if (ctx.language === \"yaml\") {\n await initYaml(ctx);\n } else if (ctx.language === \"json\") {\n await initJson(ctx);\n }\n\n await createEditor(ctx);\n}\n\nonMounted(async () => {\n await doInit();\n watch(\n () => {\n return {\n language: props.language,\n config: props.config\n };\n },\n (value: any) => {\n doInit();\n }\n );\n});\n\nwatch(\n () => {\n return props.modelValue;\n },\n (value: any) => {\n if (instanceRef && instanceRef.getValue() !== value) {\n instanceRef.setValue(value);\n }\n }\n);\n</script>\n\n<style lang=\"less\">\n.fs-editor-code {\n min-height: 100px;\n width: 100%;\n border: 1px solid #eee;\n border-radius: 5px;\n}\n\n.monaco-editor .hover-content {\n z-index: 10000 !important;\n}\n</style>\n",null,null,null,null],"names":["importJsYaml","importYamlContribution","importJsonContribution","importJavascriptContribution","importMonacoYaml","WorkerBucket","registerWorker","labels","worker","label","labelItem","initWorkers","_","workerLoader","props","__props","monacoRef","ref","instanceRef","disposeEditor","onUnmounted","emits","__emit","emitValue","lodashDebounce","value","createEditor","ctx","instance","monaco","event","initJavascript","initJson","schemas","initYaml","configureMonacoYaml","id","doInit","cloneDeep","onMounted","watch","types","FsExtendsModelType","app","options","newTypes","addTypes","useTypes","FsEditorCodeValidators","rule","yaml","modules","FsExtendsComponents","utils","FsEditorCode"],"mappings":"urBAAA,eAAsBA,GAAY,CACzB,OAAA,KAAM,QAAO,SAAS,CAC/B,CAEA,eAAsBC,GAAsB,CAC1C,KAAM,QAAO,6DAA6D,CAC5E,CAEA,eAAsBC,GAAsB,CAC1C,KAAM,QAAO,wDAAwD,CACvE,CAEA,eAAsBC,GAA4B,CAChD,KAAM,QAAO,yEAAyE,CACxF,CAEA,eAAsBC,GAAgB,CAC7B,OAAA,KAAM,QAAO,aAAa,CACnC,CCdA,MAAMC,EAA6B,CAAA,EAInB,SAAAC,EAAeC,EAA2BC,EAAW,CACnEH,EAAa,KAAK,CAChB,OAAAG,EACA,MAAQC,GAAiB,CACnB,GAAA,OAAOF,GAAW,SACpB,OAAOA,IAAWE,EAEpB,UAAWC,KAAaH,EAItB,GAHIG,IAAc,KAGdA,IAAcD,EACT,MAAA,GAGJ,MAAA,EACT,CAAA,CACD,CACH,UAEgBE,GAAW,CACrB,OAAO,oBAKX,OAAO,kBAAoB,CAEzB,UAAUC,EAAGH,EAAK,CAChB,UAAWI,KAAgBR,EACrB,GAAAQ,EAAa,MAAMJ,CAAK,EACnB,OAAA,IAAII,EAAa,MAG9B,CAAA,EAEJ,yPCAA,MAAMC,EAAQC,EA0BFJ,IACZ,MAAMK,EAAYC,EAAAA,MAElB,IAAIC,EAAmB,KAEvB,SAASC,GAAgB,CACnBD,GACFA,EAAY,QAAQ,CAExB,CAEAE,EAAAA,YAAY,IAAM,CACFD,GAAA,CACf,EAED,MAAME,EAAQ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AAAK,GAAaC,EAAAA,WACrBD,EAASD,CAAQ,CACnB,GCyBWG,EAAyB,CACpC,SAhCe,CACf,UAAW,MAAOC,EAAWxB,IAAc,CAEzC,GAAIA,EACE,GAAA,CACF,KAAK,MAAMA,CAAK,QACT,EAAQ,CACf,cAAQ,MAAM,CAAC,EACT,IAAI,MAAM,YAAc,EAAE,OAAO,CACxC,CAEL,EACA,QAAS,YAqBT,SAlBe,CACf,UAAW,MAAOwB,EAAWxB,IAAc,CAEzC,GAAIA,EACE,GAAA,CACI,MAAAyB,EAAO,MAAMlD,IACnBkD,EAAK,KAAKzB,EAAO,CAAE,OAAQyB,EAAK,YAAa,QACtC,EAAQ,CACf,cAAQ,MAAM,CAAC,EACT,IAAI,MAAM,YAAc,EAAE,OAAO,CACxC,CAEL,EACA,QAAS,aC1BLC,6DACAC,EAAsB,CAC1B,QAAQT,EAAQ,CACdU,QAAM,KAAK,sBAAsBV,EAAKQ,EAAS,KAAM,yBAA0B,IAAI,CACrF,GAGWG,EAAe,CAC1B,QAAQX,EAAUC,EAAY,CACxBD,EAAA,IAAID,EAAoBE,CAAO,EACnCD,EAAI,IAAIS,CAAmB,CAC7B"}
|
|
1
|
+
{"version":3,"file":"editor-code.umd.js","sources":["../../src/editor/components/fs-editor-code/async-import.ts","../../src/editor/components/fs-editor-code/workers.ts","../src/editor/components/fs-editor-code/index.vue","../../src/editor/type/types.ts","../../src/editor/type/index.ts","../../src/editor/components/fs-editor-code/validators.ts","../../src/editor/index.umd.ts"],"sourcesContent":[null,null,"<template>\n <div ref=\"monacoRef\" class=\"fs-editor-code\"></div>\n</template>\n\n<script lang=\"ts\" setup>\nimport * as monaco from \"monaco-editor\";\n// import * as monaco from \"monaco-editor/esm/vs/editor/editor.api\";\nimport { onMounted, onUnmounted, ref, watch } from \"vue\";\nimport { cloneDeep, debounce as lodashDebounce } from \"lodash-es\";\nimport {\n importJavascriptContribution,\n importJsonContribution,\n importMonacoYaml,\n importYamlContribution\n} from \"./async-import\";\nimport { initWorkers } from \"./workers\";\n/**\n * config:\n * value: '', // 编辑器初始文本\n * language: 'javascript', // 语言\n * theme: 'vs', // 主题\n * readOnly: false, // 是否只读\n * minimap: { enabled: false }, // 是否启用小地图\n * fontSize: 14, // 字体大小\n * tabSize: 2, // tab缩进长度\n * automaticLayout: true, // 自动布局\n * lineNumbers: 'off', // 是否启用行号\n * contextmenu: true, // 是否启用上下文菜单\n * folding: true, // 是否启用代码折叠\n * foldingStrategy: 'auto', // 代码折叠策略\n * wordWrap: 'on', // 自动换行设置\n * wrappingIndent: 'indent', // 换行缩进\n * formatOnPaste: true, // 粘贴时是否自动格式化\n * formatOnType: true, // 输入时是否自动格式化\n * dragAndDrop: true, // 是否允许拖放\n * cursorStyle: 'line', // 光标样式\n * cursorBlinking: 'blink', // 光标闪烁方式\n * scrollbar: {\n * vertical: 'auto', // 垂直滚动条的显示方式\n * horizontal: 'auto', // 水平滚动条的显示方式\n * verticalScrollbarSize: 2, // 垂直滚动条的宽\n * horizontalScrollbarSize: 2, // 水平滚动条的高度\n * }\n */\nconst props = defineProps<{\n language?: string;\n modelValue?: string;\n config?: any;\n schema?: any;\n debounce?: number;\n init?: any;\n readonly?: boolean;\n disabled?: boolean;\n id?: string;\n}>();\n\nexport type EditorCodeCtx = {\n // monaco对象\n monaco: any;\n //语言\n language: string;\n //配置\n config: any;\n //editor实例对象\n instance?: any;\n\n schema?: any;\n\n initialValue?: any;\n};\ninitWorkers();\nconst monacoRef = ref();\n\nlet instanceRef: any = null;\n\nfunction disposeEditor() {\n if (instanceRef) {\n instanceRef.dispose(); //使用完成销毁实例\n }\n}\n\nonUnmounted(() => {\n disposeEditor();\n});\n\nconst emits = defineEmits([\"update:modelValue\", \"change\", \"ready\"]);\n\nconst emitValue = lodashDebounce((value: any) => {\n emits(\"update:modelValue\", value);\n}, props.debounce || 500);\n\nasync function createEditor(ctx: EditorCodeCtx) {\n disposeEditor();\n const instance = monaco.editor.create(monacoRef.value, {\n automaticLayout: true,\n value: props.modelValue,\n language: ctx.language,\n theme: \"vs-dark\",\n minimap: { enabled: false },\n readOnly: props.readonly || props.disabled,\n hover: {\n enabled: true\n },\n ...ctx.config\n });\n\n // @event `change`\n instance.onDidChangeModelContent((event) => {\n const value = instance.getValue();\n if (props.modelValue !== value) {\n emits(\"change\", value);\n emitValue(value);\n }\n });\n\n instanceRef = instance;\n ctx.instance = instance;\n emits(\"ready\", ctx);\n return instance;\n}\n\nasync function initJavascript(ctx: EditorCodeCtx) {\n await importJavascriptContribution();\n monaco.languages.register({ id: \"javascript\" });\n}\n\nasync function initJson(ctx: EditorCodeCtx) {\n await importJsonContribution();\n monaco.languages.register({ id: \"json\" });\n\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n uri: \"http://myserver/foo-schema.json\", // id of the first schema\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n }\n });\n }\n\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n validate: true,\n enableSchemaRequest: false,\n schemas\n });\n}\n\nasync function initYaml(ctx: EditorCodeCtx) {\n await importYamlContribution();\n const { configureMonacoYaml } = await importMonacoYaml();\n monaco.languages.register({ id: \"yaml\" });\n let id = `fs-editor-code-yaml-${props.id || \"\"}.yaml`;\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n },\n uri: `http://myserver/${id}`\n });\n }\n configureMonacoYaml(monaco, {\n schemas,\n format: true,\n hover: true,\n completion: true,\n validate: true,\n isKubernetes: false,\n enableSchemaRequest: false\n });\n\n // const uri = monaco.Uri.parse(id);\n // const oldModel = monaco.editor.getModel(uri);\n // if (oldModel) {\n // oldModel.dispose();\n // }\n // ctx.config.model = monaco.editor.createModel(props.modelValue, null, uri);\n}\n\nasync function doInit() {\n disposeEditor();\n const ctx: EditorCodeCtx = {\n monaco,\n language: props.language || \"javascript\",\n config: cloneDeep(props.config || {}),\n initialValue: props.modelValue || \"\",\n schema: props.schema\n };\n if (ctx.language === \"javascript\") {\n await initJavascript(ctx);\n } else if (ctx.language === \"yaml\") {\n await initYaml(ctx);\n } else if (ctx.language === \"json\") {\n await initJson(ctx);\n }\n\n await createEditor(ctx);\n}\n\nonMounted(async () => {\n await doInit();\n watch(\n () => {\n return {\n language: props.language,\n config: props.config\n };\n },\n (value: any) => {\n doInit();\n }\n );\n});\n\nwatch(\n () => {\n return props.modelValue;\n },\n (value: any) => {\n if (instanceRef && instanceRef.getValue() !== value) {\n instanceRef.setValue(value);\n }\n }\n);\n</script>\n\n<style lang=\"less\">\n.fs-editor-code {\n min-height: 100px;\n width: 100%;\n border: 1px solid #eee;\n border-radius: 5px;\n}\n\n.monaco-editor .hover-content {\n z-index: 10000 !important;\n}\n</style>\n",null,null,null,null],"names":["importJsYaml","importYamlContribution","importJsonContribution","importJavascriptContribution","importMonacoYaml","WorkerBucket","registerWorker","labels","worker","label","labelItem","initWorkers","_","workerLoader","props","__props","monacoRef","ref","instanceRef","disposeEditor","onUnmounted","emits","__emit","emitValue","lodashDebounce","value","createEditor","ctx","instance","monaco","event","initJavascript","initJson","schemas","initYaml","configureMonacoYaml","id","doInit","cloneDeep","onMounted","watch","_createElementBlock","types","FsExtendsModelType","app","options","newTypes","addTypes","useTypes","FsEditorCodeValidators","rule","yaml","modules","FsExtendsComponents","utils","FsEditorCode"],"mappings":"urBAAA,eAAsBA,GAAY,CACzB,OAAA,KAAM,QAAO,SAAS,CAC/B,CAEA,eAAsBC,GAAsB,CAC1C,KAAM,QAAO,6DAA6D,CAC5E,CAEA,eAAsBC,GAAsB,CAC1C,KAAM,QAAO,wDAAwD,CACvE,CAEA,eAAsBC,GAA4B,CAChD,KAAM,QAAO,yEAAyE,CACxF,CAEA,eAAsBC,GAAgB,CAC7B,OAAA,KAAM,QAAO,aAAa,CACnC,CCdA,MAAMC,EAA6B,CAAA,EAInB,SAAAC,EAAeC,EAA2BC,EAAW,CACnEH,EAAa,KAAK,CAChB,OAAAG,EACA,MAAQC,GAA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{ defineComponent as b, ref as _, onUnmounted as V, onMounted as w, watch as m, openBlock as j, createElementBlock as
|
|
1
|
+
import { defineComponent as b, ref as _, onUnmounted as V, onMounted as w, watch as m, openBlock as j, createElementBlock as C } from "vue";
|
|
2
2
|
import * as t from "monaco-editor";
|
|
3
|
-
import { debounce as
|
|
4
|
-
import { i as
|
|
3
|
+
import { debounce as M, cloneDeep as k } from "lodash-es";
|
|
4
|
+
import { i as R, a as B, b as D, c as J, d as Y } from "./index-c2ddaf47.mjs";
|
|
5
5
|
import "@fast-crud/fast-crud";
|
|
6
|
-
const
|
|
6
|
+
const S = /* @__PURE__ */ b({
|
|
7
7
|
__name: "index",
|
|
8
8
|
props: {
|
|
9
9
|
language: {},
|
|
@@ -16,24 +16,24 @@ const T = /* @__PURE__ */ b({
|
|
|
16
16
|
disabled: { type: Boolean },
|
|
17
17
|
id: {}
|
|
18
18
|
},
|
|
19
|
-
emits: ["update:modelValue", "change", "ready"
|
|
19
|
+
emits: ["update:modelValue", "change", "ready"],
|
|
20
20
|
setup(d, { emit: f }) {
|
|
21
21
|
const a = d;
|
|
22
|
-
|
|
23
|
-
const
|
|
22
|
+
R();
|
|
23
|
+
const c = _();
|
|
24
24
|
let o = null;
|
|
25
|
-
function
|
|
25
|
+
function s() {
|
|
26
26
|
o && o.dispose();
|
|
27
27
|
}
|
|
28
28
|
V(() => {
|
|
29
|
-
|
|
29
|
+
s();
|
|
30
30
|
});
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const l = f, g = M((e) => {
|
|
32
|
+
l("update:modelValue", e);
|
|
33
33
|
}, a.debounce || 500);
|
|
34
34
|
async function p(e) {
|
|
35
|
-
|
|
36
|
-
const n = t.editor.create(
|
|
35
|
+
s();
|
|
36
|
+
const n = t.editor.create(c.value, {
|
|
37
37
|
automaticLayout: !0,
|
|
38
38
|
value: a.modelValue,
|
|
39
39
|
language: e.language,
|
|
@@ -45,18 +45,16 @@ const T = /* @__PURE__ */ b({
|
|
|
45
45
|
},
|
|
46
46
|
...e.config
|
|
47
47
|
});
|
|
48
|
-
return n.onDidChangeModelContent((
|
|
48
|
+
return n.onDidChangeModelContent((u) => {
|
|
49
49
|
const i = n.getValue();
|
|
50
|
-
a.modelValue !== i && (
|
|
51
|
-
}), o = n, e.instance = n,
|
|
52
|
-
console.error("onDidBlurEditorText", e), s("blur", e), s("blur2", e);
|
|
53
|
-
}), s("ready", e), n;
|
|
50
|
+
a.modelValue !== i && (l("change", i), g(i));
|
|
51
|
+
}), o = n, e.instance = n, l("ready", e), n;
|
|
54
52
|
}
|
|
55
53
|
async function h(e) {
|
|
56
|
-
await
|
|
54
|
+
await B(), t.languages.register({ id: "javascript" });
|
|
57
55
|
}
|
|
58
56
|
async function y(e) {
|
|
59
|
-
await
|
|
57
|
+
await D(), t.languages.register({ id: "json" });
|
|
60
58
|
const n = [];
|
|
61
59
|
e.schema && n.push({
|
|
62
60
|
uri: "http://myserver/foo-schema.json",
|
|
@@ -73,10 +71,10 @@ const T = /* @__PURE__ */ b({
|
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
73
|
async function v(e) {
|
|
76
|
-
await
|
|
77
|
-
const { configureMonacoYaml: n } = await
|
|
74
|
+
await J();
|
|
75
|
+
const { configureMonacoYaml: n } = await Y();
|
|
78
76
|
t.languages.register({ id: "yaml" });
|
|
79
|
-
let
|
|
77
|
+
let u = `fs-editor-code-yaml-${a.id || ""}.yaml`;
|
|
80
78
|
const i = [];
|
|
81
79
|
e.schema && i.push({
|
|
82
80
|
fileMatch: ["*"],
|
|
@@ -84,7 +82,7 @@ const T = /* @__PURE__ */ b({
|
|
|
84
82
|
schema: {
|
|
85
83
|
...e.schema
|
|
86
84
|
},
|
|
87
|
-
uri: `http://myserver/${
|
|
85
|
+
uri: `http://myserver/${u}`
|
|
88
86
|
}), n(t, {
|
|
89
87
|
schemas: i,
|
|
90
88
|
format: !0,
|
|
@@ -95,25 +93,25 @@ const T = /* @__PURE__ */ b({
|
|
|
95
93
|
enableSchemaRequest: !1
|
|
96
94
|
});
|
|
97
95
|
}
|
|
98
|
-
async function
|
|
99
|
-
|
|
96
|
+
async function r() {
|
|
97
|
+
s();
|
|
100
98
|
const e = {
|
|
101
99
|
monaco: t,
|
|
102
100
|
language: a.language || "javascript",
|
|
103
|
-
config:
|
|
101
|
+
config: k(a.config || {}),
|
|
104
102
|
initialValue: a.modelValue || "",
|
|
105
103
|
schema: a.schema
|
|
106
104
|
};
|
|
107
105
|
e.language === "javascript" ? await h() : e.language === "yaml" ? await v(e) : e.language === "json" && await y(e), await p(e);
|
|
108
106
|
}
|
|
109
107
|
return w(async () => {
|
|
110
|
-
await
|
|
108
|
+
await r(), m(
|
|
111
109
|
() => ({
|
|
112
110
|
language: a.language,
|
|
113
111
|
config: a.config
|
|
114
112
|
}),
|
|
115
113
|
(e) => {
|
|
116
|
-
|
|
114
|
+
r();
|
|
117
115
|
}
|
|
118
116
|
);
|
|
119
117
|
}), m(
|
|
@@ -121,14 +119,14 @@ const T = /* @__PURE__ */ b({
|
|
|
121
119
|
(e) => {
|
|
122
120
|
o && o.getValue() !== e && o.setValue(e);
|
|
123
121
|
}
|
|
124
|
-
), (e, n) => (j(),
|
|
122
|
+
), (e, n) => (j(), C("div", {
|
|
125
123
|
ref_key: "monacoRef",
|
|
126
|
-
ref:
|
|
124
|
+
ref: c,
|
|
127
125
|
class: "fs-editor-code"
|
|
128
126
|
}, null, 512));
|
|
129
127
|
}
|
|
130
128
|
});
|
|
131
129
|
export {
|
|
132
|
-
|
|
130
|
+
S as default
|
|
133
131
|
};
|
|
134
|
-
//# sourceMappingURL=index-
|
|
132
|
+
//# sourceMappingURL=index-4cfdb04c.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-4cfdb04c.mjs","sources":["../src/editor/components/fs-editor-code/index.vue"],"sourcesContent":["<template>\n <div ref=\"monacoRef\" class=\"fs-editor-code\"></div>\n</template>\n\n<script lang=\"ts\" setup>\nimport * as monaco from \"monaco-editor\";\n// import * as monaco from \"monaco-editor/esm/vs/editor/editor.api\";\nimport { onMounted, onUnmounted, ref, watch } from \"vue\";\nimport { cloneDeep, debounce as lodashDebounce } from \"lodash-es\";\nimport {\n importJavascriptContribution,\n importJsonContribution,\n importMonacoYaml,\n importYamlContribution\n} from \"./async-import\";\nimport { initWorkers } from \"./workers\";\n/**\n * config:\n * value: '', // 编辑器初始文本\n * language: 'javascript', // 语言\n * theme: 'vs', // 主题\n * readOnly: false, // 是否只读\n * minimap: { enabled: false }, // 是否启用小地图\n * fontSize: 14, // 字体大小\n * tabSize: 2, // tab缩进长度\n * automaticLayout: true, // 自动布局\n * lineNumbers: 'off', // 是否启用行号\n * contextmenu: true, // 是否启用上下文菜单\n * folding: true, // 是否启用代码折叠\n * foldingStrategy: 'auto', // 代码折叠策略\n * wordWrap: 'on', // 自动换行设置\n * wrappingIndent: 'indent', // 换行缩进\n * formatOnPaste: true, // 粘贴时是否自动格式化\n * formatOnType: true, // 输入时是否自动格式化\n * dragAndDrop: true, // 是否允许拖放\n * cursorStyle: 'line', // 光标样式\n * cursorBlinking: 'blink', // 光标闪烁方式\n * scrollbar: {\n * vertical: 'auto', // 垂直滚动条的显示方式\n * horizontal: 'auto', // 水平滚动条的显示方式\n * verticalScrollbarSize: 2, // 垂直滚动条的宽\n * horizontalScrollbarSize: 2, // 水平滚动条的高度\n * }\n */\nconst props = defineProps<{\n language?: string;\n modelValue?: string;\n config?: any;\n schema?: any;\n debounce?: number;\n init?: any;\n readonly?: boolean;\n disabled?: boolean;\n id?: string;\n}>();\n\nexport type EditorCodeCtx = {\n // monaco对象\n monaco: any;\n //语言\n language: string;\n //配置\n config: any;\n //editor实例对象\n instance?: any;\n\n schema?: any;\n\n initialValue?: any;\n};\ninitWorkers();\nconst monacoRef = ref();\n\nlet instanceRef: any = null;\n\nfunction disposeEditor() {\n if (instanceRef) {\n instanceRef.dispose(); //使用完成销毁实例\n }\n}\n\nonUnmounted(() => {\n disposeEditor();\n});\n\nconst emits = defineEmits([\"update:modelValue\", \"change\", \"ready\"]);\n\nconst emitValue = lodashDebounce((value: any) => {\n emits(\"update:modelValue\", value);\n}, props.debounce || 500);\n\nasync function createEditor(ctx: EditorCodeCtx) {\n disposeEditor();\n const instance = monaco.editor.create(monacoRef.value, {\n automaticLayout: true,\n value: props.modelValue,\n language: ctx.language,\n theme: \"vs-dark\",\n minimap: { enabled: false },\n readOnly: props.readonly || props.disabled,\n hover: {\n enabled: true\n },\n ...ctx.config\n });\n\n // @event `change`\n instance.onDidChangeModelContent((event) => {\n const value = instance.getValue();\n if (props.modelValue !== value) {\n emits(\"change\", value);\n emitValue(value);\n }\n });\n\n instanceRef = instance;\n ctx.instance = instance;\n emits(\"ready\", ctx);\n return instance;\n}\n\nasync function initJavascript(ctx: EditorCodeCtx) {\n await importJavascriptContribution();\n monaco.languages.register({ id: \"javascript\" });\n}\n\nasync function initJson(ctx: EditorCodeCtx) {\n await importJsonContribution();\n monaco.languages.register({ id: \"json\" });\n\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n uri: \"http://myserver/foo-schema.json\", // id of the first schema\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n }\n });\n }\n\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n validate: true,\n enableSchemaRequest: false,\n schemas\n });\n}\n\nasync function initYaml(ctx: EditorCodeCtx) {\n await importYamlContribution();\n const { configureMonacoYaml } = await importMonacoYaml();\n monaco.languages.register({ id: \"yaml\" });\n let id = `fs-editor-code-yaml-${props.id || \"\"}.yaml`;\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n },\n uri: `http://myserver/${id}`\n });\n }\n configureMonacoYaml(monaco, {\n schemas,\n format: true,\n hover: true,\n completion: true,\n validate: true,\n isKubernetes: false,\n enableSchemaRequest: false\n });\n\n // const uri = monaco.Uri.parse(id);\n // const oldModel = monaco.editor.getModel(uri);\n // if (oldModel) {\n // oldModel.dispose();\n // }\n // ctx.config.model = monaco.editor.createModel(props.modelValue, null, uri);\n}\n\nasync function doInit() {\n disposeEditor();\n const ctx: EditorCodeCtx = {\n monaco,\n language: props.language || \"javascript\",\n config: cloneDeep(props.config || {}),\n initialValue: props.modelValue || \"\",\n schema: props.schema\n };\n if (ctx.language === \"javascript\") {\n await initJavascript(ctx);\n } else if (ctx.language === \"yaml\") {\n await initYaml(ctx);\n } else if (ctx.language === \"json\") {\n await initJson(ctx);\n }\n\n await createEditor(ctx);\n}\n\nonMounted(async () => {\n await doInit();\n watch(\n () => {\n return {\n language: props.language,\n config: props.config\n };\n },\n (value: any) => {\n doInit();\n }\n );\n});\n\nwatch(\n () => {\n return props.modelValue;\n },\n (value: any) => {\n if (instanceRef && instanceRef.getValue() !== value) {\n instanceRef.setValue(value);\n }\n }\n);\n</script>\n\n<style lang=\"less\">\n.fs-editor-code {\n min-height: 100px;\n width: 100%;\n border: 1px solid #eee;\n border-radius: 5px;\n}\n\n.monaco-editor .hover-content {\n z-index: 10000 !important;\n}\n</style>\n"],"names":["props","__props","initWorkers","monacoRef","ref","instanceRef","disposeEditor","onUnmounted","emits","__emit","emitValue","lodashDebounce","value","createEditor","ctx","instance","monaco","event","initJavascript","importJavascriptContribution","initJson","importJsonContribution","schemas","initYaml","importYamlContribution","configureMonacoYaml","importMonacoYaml","id","doInit","cloneDeep","onMounted","watch","_createElementBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4CA,UAAMA,IAAQC;AA0BF,IAAAC;AACZ,UAAMC,IAAYC;AAElB,QAAIC,IAAmB;AAEvB,aAASC,IAAgB;AACvB,MAAID,KACFA,EAAY,QAAQ;AAAA,IAExB;AAEA,IAAAE,EAAY,MAAM;AACF,MAAAD;IAAA,CACf;AAED,UAAME,IAAQC,GAERC,IAAYC,EAAe,CAACC,MAAe;AAC/C,MAAAJ,EAAM,qBAAqBI,CAAK;AAAA,IAAA,GAC/BZ,EAAM,YAAY,GAAG;AAExB,mBA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AAzC;AAAA,MAAJ,KAAI7B;AAAA,MAAY,OAAM;AAAA,IAAA;;;"}
|
|
@@ -75,7 +75,7 @@ function k() {
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
const p = /* @__PURE__ */ Object.assign({ "./components/fs-editor-code/index.vue": () => import("./index-
|
|
78
|
+
const p = /* @__PURE__ */ Object.assign({ "./components/fs-editor-code/index.vue": () => import("./index-4cfdb04c.mjs") }), f = {
|
|
79
79
|
install(t) {
|
|
80
80
|
i.vite.installAsyncComponents(t, p, null, /^.*\/([^\/]+)\/.*.vue$/, null);
|
|
81
81
|
}
|
|
@@ -94,4 +94,4 @@ export {
|
|
|
94
94
|
k as i,
|
|
95
95
|
C as r
|
|
96
96
|
};
|
|
97
|
-
//# sourceMappingURL=index-
|
|
97
|
+
//# sourceMappingURL=index-c2ddaf47.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-c2ddaf47.mjs","sources":["../../src/editor/type/types.ts","../../src/editor/type/index.ts","../../src/editor/components/fs-editor-code/async-import.ts","../../src/editor/components/fs-editor-code/validators.ts","../../src/editor/components/fs-editor-code/workers.ts","../../src/editor/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["types","EcologyType","app","options","newTypes","addTypes","useTypes","importJsYaml","importYamlContribution","importJsonContribution","importJavascriptContribution","importMonacoYaml","jsonRule","rule","value","e","yamlRule","yaml","FsEditorCodeValidators","WorkerBucket","registerWorker","labels","worker","label","labelItem","initWorkers","_","workerLoader","asyncModules","FsExtendsComponents","utils","FsEditorCode"],"mappings":";AAAc,SAAAA,IAAA;AACL,SAAA;AAAA,IACL,eAAe;AAAA,MACb,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAkB,GAAE,KAAK,EAAE,MAAM,KAAM;AAAA,IACnE;AAAA,EAAA;AAEL;ACHA,MAAeC,IAAA;AAAA,EACb,QAAQC,GAAUC,GAAY;AA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AAW;AACzB,EAAI,OAAO,sBAKX,OAAO,oBAAoB;AAAA;AAAA,IAEzB,UAAUC,GAAGH,GAAK;AAChB,iBAAWI,KAAgBR;AACrB,YAAAQ,EAAa,MAAMJ,CAAK;AACnB,iBAAA,IAAII,EAAa;IAG9B;AAAA,EAAA;AAEJ;ACxCA,MAAMC,sHACAC,IAAsB;AAAA,EAC1B,QAAQ3B,GAAQ;AACd,IAAA4B,EAAM,KAAK,uBAAuB5B,GAAK0B,GAAc,MAAM,0BAA0B,IAAI;AAAA,EAC3F;GAGWG,IAAe;AAAA,EAC1B,QAAQ7B,GAAUC,GAAY;AACxB,IAAAD,EAAA,IAAID,GAAaE,CAAO,GAC5BD,EAAI,IAAI2B,CAAmB;AAAA,EAC7B;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fast-crud/editor-code",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/editor-code.umd.js",
|
|
6
6
|
"module": "./dist/editor-code.mjs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"monaco-yaml": "^5.3.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@fast-crud/fast-crud": "^1.27.
|
|
29
|
+
"@fast-crud/fast-crud": "^1.27.1",
|
|
30
30
|
"@ls-lint/ls-lint": "^2.0.1",
|
|
31
31
|
"@rollup/plugin-commonjs": "^25.0.3",
|
|
32
32
|
"@rollup/plugin-strip": "^3.0.2",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"vue-eslint-parser": "^9.3.1",
|
|
76
76
|
"vue-tsc": "^1.8.8"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "36c56ecb9ff89249650d2661cfcfa44de925dce2"
|
|
79
79
|
}
|
package/stats.html
CHANGED
|
@@ -4929,7 +4929,7 @@ var drawChart = (function (exports) {
|
|
|
4929
4929
|
</script>
|
|
4930
4930
|
<script>
|
|
4931
4931
|
/*<!--*/
|
|
4932
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"editor-code.mjs","uid":"
|
|
4932
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"editor-code.mjs","uid":"8a838400-1"},{"name":"index-c2ddaf47.mjs","children":[{"name":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src","children":[{"name":"editor","children":[{"name":"type","children":[{"uid":"8a838400-3","name":"types.ts"},{"uid":"8a838400-5","name":"index.ts"}]},{"name":"components/fs-editor-code","children":[{"uid":"8a838400-7","name":"async-import.ts"},{"uid":"8a838400-9","name":"validators.ts"},{"uid":"8a838400-11","name":"workers.ts"}]},{"uid":"8a838400-13","name":"index.ts"}]},{"uid":"8a838400-14","name":"index.ts"}]}]},{"name":"index-4cfdb04c.mjs","children":[{"name":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code","children":[{"uid":"8a838400-16","name":"index.vue?vue&type=script&setup=true&lang.ts"},{"uid":"8a838400-18","name":"index.vue?vue&type=style&index=0&lang.less"},{"uid":"8a838400-20","name":"index.vue"}]}]}],"isRoot":true},"nodeParts":{"8a838400-1":{"id":"editor-code.mjs","gzipLength":0,"brotliLength":0,"renderedLength":249,"metaUid":"8a838400-0"},"8a838400-3":{"renderedLength":136,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-2"},"8a838400-5":{"renderedLength":145,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-4"},"8a838400-7":{"renderedLength":525,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-6"},"8a838400-9":{"renderedLength":668,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-8"},"8a838400-11":{"renderedLength":735,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-10"},"8a838400-13":{"renderedLength":407,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-12"},"8a838400-14":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-0"},"8a838400-16":{"renderedLength":4185,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-15"},"8a838400-18":{"renderedLength":49,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-17"},"8a838400-20":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"8a838400-19"}},"nodeMetas":{"8a838400-0":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/index.ts","moduleParts":{"editor-code.mjs":"8a838400-1","index-c2ddaf47.mjs":"8a838400-14"},"imported":[{"uid":"8a838400-12"}],"importedBy":[],"isEntry":true},"8a838400-2":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/type/types.ts","moduleParts":{"index-c2ddaf47.mjs":"8a838400-3"},"imported":[],"importedBy":[{"uid":"8a838400-4"}]},"8a838400-4":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/type/index.ts","moduleParts":{"index-c2ddaf47.mjs":"8a838400-5"},"imported":[{"uid":"8a838400-22"},{"uid":"8a838400-2"}],"importedBy":[{"uid":"8a838400-12"},{"uid":"8a838400-21"}]},"8a838400-6":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code/async-import.ts","moduleParts":{"index-c2ddaf47.mjs":"8a838400-7"},"imported":[{"uid":"8a838400-26","dynamic":true},{"uid":"8a838400-27","dynamic":true},{"uid":"8a838400-28","dynamic":true},{"uid":"8a838400-29","dynamic":true},{"uid":"8a838400-30","dynamic":true}],"importedBy":[{"uid":"8a838400-8"},{"uid":"8a838400-15"}]},"8a838400-8":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code/validators.ts","moduleParts":{"index-c2ddaf47.mjs":"8a838400-9"},"imported":[{"uid":"8a838400-6"}],"importedBy":[{"uid":"8a838400-21"}]},"8a838400-10":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code/workers.ts","moduleParts":{"index-c2ddaf47.mjs":"8a838400-11"},"imported":[],"importedBy":[{"uid":"8a838400-21"},{"uid":"8a838400-15"}]},"8a838400-12":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/index.ts","moduleParts":{"index-c2ddaf47.mjs":"8a838400-13"},"imported":[{"uid":"8a838400-4"},{"uid":"8a838400-21"},{"uid":"8a838400-22"},{"uid":"8a838400-19","dynamic":true}],"importedBy":[{"uid":"8a838400-0"}]},"8a838400-15":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code/index.vue?vue&type=script&setup=true&lang.ts","moduleParts":{"index-4cfdb04c.mjs":"8a838400-16"},"imported":[{"uid":"8a838400-23"},{"uid":"8a838400-24"},{"uid":"8a838400-25"},{"uid":"8a838400-6"},{"uid":"8a838400-10"}],"importedBy":[{"uid":"8a838400-19"}]},"8a838400-17":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code/index.vue?vue&type=style&index=0&lang.less","moduleParts":{"index-4cfdb04c.mjs":"8a838400-18"},"imported":[],"importedBy":[{"uid":"8a838400-19"}]},"8a838400-19":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/components/fs-editor-code/index.vue","moduleParts":{"index-4cfdb04c.mjs":"8a838400-20"},"imported":[{"uid":"8a838400-15"},{"uid":"8a838400-17"}],"importedBy":[{"uid":"8a838400-12"}]},"8a838400-21":{"id":"D:/Codes/fast-crud/packages/fast-ecology/editor-code/src/editor/exports.ts","moduleParts":{},"imported":[{"uid":"8a838400-4"},{"uid":"8a838400-8"},{"uid":"8a838400-10"}],"importedBy":[{"uid":"8a838400-12"}]},"8a838400-22":{"id":"@fast-crud/fast-crud","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-12"},{"uid":"8a838400-4"}],"isExternal":true},"8a838400-23":{"id":"vue","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-15"}],"isExternal":true},"8a838400-24":{"id":"monaco-editor","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-15"}],"isExternal":true},"8a838400-25":{"id":"lodash-es","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-15"}],"isExternal":true},"8a838400-26":{"id":"js-yaml","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-6"}],"isExternal":true},"8a838400-27":{"id":"monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-6"}],"isExternal":true},"8a838400-28":{"id":"monaco-editor/esm/vs/language/json/monaco.contribution","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-6"}],"isExternal":true},"8a838400-29":{"id":"monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-6"}],"isExternal":true},"8a838400-30":{"id":"monaco-yaml","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a838400-6"}],"isExternal":true}},"env":{"rollup":"3.29.4"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};
|
|
4933
4933
|
|
|
4934
4934
|
const run = () => {
|
|
4935
4935
|
const width = window.innerWidth;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-5677963c.mjs","sources":["../src/editor/components/fs-editor-code/index.vue"],"sourcesContent":["<template>\n <div ref=\"monacoRef\" class=\"fs-editor-code\"></div>\n</template>\n\n<script lang=\"ts\" setup>\nimport * as monaco from \"monaco-editor\";\n// import * as monaco from \"monaco-editor/esm/vs/editor/editor.api\";\nimport { onMounted, onUnmounted, ref, watch } from \"vue\";\nimport { cloneDeep, debounce as lodashDebounce } from \"lodash-es\";\nimport {\n importJavascriptContribution,\n importJsonContribution,\n importMonacoYaml,\n importYamlContribution\n} from \"./async-import\";\nimport { initWorkers } from \"./workers\";\n/**\n * config:\n * value: '', // 编辑器初始文本\n * language: 'javascript', // 语言\n * theme: 'vs', // 主题\n * readOnly: false, // 是否只读\n * minimap: { enabled: false }, // 是否启用小地图\n * fontSize: 14, // 字体大小\n * tabSize: 2, // tab缩进长度\n * automaticLayout: true, // 自动布局\n * lineNumbers: 'off', // 是否启用行号\n * contextmenu: true, // 是否启用上下文菜单\n * folding: true, // 是否启用代码折叠\n * foldingStrategy: 'auto', // 代码折叠策略\n * wordWrap: 'on', // 自动换行设置\n * wrappingIndent: 'indent', // 换行缩进\n * formatOnPaste: true, // 粘贴时是否自动格式化\n * formatOnType: true, // 输入时是否自动格式化\n * dragAndDrop: true, // 是否允许拖放\n * cursorStyle: 'line', // 光标样式\n * cursorBlinking: 'blink', // 光标闪烁方式\n * scrollbar: {\n * vertical: 'auto', // 垂直滚动条的显示方式\n * horizontal: 'auto', // 水平滚动条的显示方式\n * verticalScrollbarSize: 2, // 垂直滚动条的宽\n * horizontalScrollbarSize: 2, // 水平滚动条的高度\n * }\n */\nconst props = defineProps<{\n language?: string;\n modelValue?: string;\n config?: any;\n schema?: any;\n debounce?: number;\n init?: any;\n readonly?: boolean;\n disabled?: boolean;\n id?: string;\n}>();\n\nexport type EditorCodeCtx = {\n // monaco对象\n monaco: any;\n //语言\n language: string;\n //配置\n config: any;\n //editor实例对象\n instance?: any;\n\n schema?: any;\n\n initialValue?: any;\n};\ninitWorkers();\nconst monacoRef = ref();\n\nlet instanceRef: any = null;\n\nfunction disposeEditor() {\n if (instanceRef) {\n instanceRef.dispose(); //使用完成销毁实例\n }\n}\n\nonUnmounted(() => {\n disposeEditor();\n});\n\nconst emits = defineEmits([\"update:modelValue\", \"change\", \"ready\", \"blur\", \"blur2\"]);\n\nconst emitValue = lodashDebounce((value: any) => {\n emits(\"update:modelValue\", value);\n}, props.debounce || 500);\n\nasync function createEditor(ctx: EditorCodeCtx) {\n disposeEditor();\n const instance = monaco.editor.create(monacoRef.value, {\n automaticLayout: true,\n value: props.modelValue,\n language: ctx.language,\n theme: \"vs-dark\",\n minimap: { enabled: false },\n readOnly: props.readonly || props.disabled,\n hover: {\n enabled: true\n },\n ...ctx.config\n });\n\n // @event `change`\n instance.onDidChangeModelContent((event) => {\n const value = instance.getValue();\n if (props.modelValue !== value) {\n emits(\"change\", value);\n emitValue(value);\n }\n });\n\n instanceRef = instance;\n ctx.instance = instance;\n\n instance.onDidBlurEditorText(() => {\n console.error(\"onDidBlurEditorText\", ctx);\n emits(\"blur\", ctx);\n emits(\"blur2\", ctx);\n });\n\n emits(\"ready\", ctx);\n return instance;\n}\n\nasync function initJavascript(ctx: EditorCodeCtx) {\n await importJavascriptContribution();\n monaco.languages.register({ id: \"javascript\" });\n}\n\nasync function initJson(ctx: EditorCodeCtx) {\n await importJsonContribution();\n monaco.languages.register({ id: \"json\" });\n\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n uri: \"http://myserver/foo-schema.json\", // id of the first schema\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n }\n });\n }\n\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n validate: true,\n enableSchemaRequest: false,\n schemas\n });\n}\n\nasync function initYaml(ctx: EditorCodeCtx) {\n await importYamlContribution();\n const { configureMonacoYaml } = await importMonacoYaml();\n monaco.languages.register({ id: \"yaml\" });\n let id = `fs-editor-code-yaml-${props.id || \"\"}.yaml`;\n const schemas = [];\n if (ctx.schema) {\n schemas.push({\n fileMatch: [\"*\"], // associate with our model\n schema: {\n ...ctx.schema\n },\n uri: `http://myserver/${id}`\n });\n }\n configureMonacoYaml(monaco, {\n schemas,\n format: true,\n hover: true,\n completion: true,\n validate: true,\n isKubernetes: false,\n enableSchemaRequest: false\n });\n\n // const uri = monaco.Uri.parse(id);\n // const oldModel = monaco.editor.getModel(uri);\n // if (oldModel) {\n // oldModel.dispose();\n // }\n // ctx.config.model = monaco.editor.createModel(props.modelValue, null, uri);\n}\n\nasync function doInit() {\n disposeEditor();\n const ctx: EditorCodeCtx = {\n monaco,\n language: props.language || \"javascript\",\n config: cloneDeep(props.config || {}),\n initialValue: props.modelValue || \"\",\n schema: props.schema\n };\n if (ctx.language === \"javascript\") {\n await initJavascript(ctx);\n } else if (ctx.language === \"yaml\") {\n await initYaml(ctx);\n } else if (ctx.language === \"json\") {\n await initJson(ctx);\n }\n\n await createEditor(ctx);\n}\n\nonMounted(async () => {\n await doInit();\n watch(\n () => {\n return {\n language: props.language,\n config: props.config\n };\n },\n (value: any) => {\n doInit();\n }\n );\n});\n\nwatch(\n () => {\n return props.modelValue;\n },\n (value: any) => {\n if (instanceRef && instanceRef.getValue() !== value) {\n instanceRef.setValue(value);\n }\n }\n);\n</script>\n\n<style lang=\"less\">\n.fs-editor-code {\n min-height: 100px;\n width: 100%;\n border: 1px solid #eee;\n border-radius: 5px;\n}\n\n.monaco-editor .hover-content {\n z-index: 10000 !important;\n}\n</style>\n"],"names":["props","__props","initWorkers","monacoRef","ref","instanceRef","disposeEditor","onUnmounted","emits","__emit","emitValue","lodashDebounce","value","createEditor","ctx","instance","monaco","event","initJavascript","importJavascriptContribution","initJson","importJsonContribution","schemas","initYaml","importYamlContribution","configureMonacoYaml","importMonacoYaml","id","doInit","cloneDeep","onMounted","watch"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4CA,UAAMA,IAAQC;AA0BF,IAAAC;AACZ,UAAMC,IAAYC;AAElB,QAAIC,IAAmB;AAEvB,aAASC,IAAgB;AACvB,MAAID,KACFA,EAAY,QAAQ;AAAA,IAExB;AAEA,IAAAE,EAAY,MAAM;AACF,MAAAD;IAAA,CACf;AAED,UAAME,IAAQC,GAERC,IAAYC,EAAe,CAACC,MAAe;AAC/C,MAAAJ,EAAM,qBAAqBI,CAAK;AAAA,IAAA,GAC/BZ,EAAM,YAAY,GAAG;AAExB,mBAAea,EAAaC,GAAoB;AAChC,MAAAR;AACd,YAAMS,IAAWC,EAAO,OAAO,OAAOb,EAAU,OAAO;AAAA,QACrD,iBAAiB;AAAA,QACjB,OAAOH,EAAM;AAAA,QACb,UAAUc,EAAI;AAAA,QACd,OAAO;AAAA,QACP,SAAS,EA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