PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.27.7
Code Block Pro – Beautiful Syntax Highlighting v1.27.7
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / build / shiki / node_modules / jsonc-parser / lib / umd / impl / edit.js

edit.js in Code Block Pro – Beautiful Syntax Highlighting 1.27.7, at build/shiki/node_modules/jsonc-parser/lib/umd/impl/edit.js

1 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 !function(e){if("object"==typeof module&&"object"==typeof module.exports){var t=e(require,exports);void 0!==t&&(module.exports=t)}else"function"==typeof define&&define.amd&&define(["require","exports","./format","./parser"],e)}((function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isWS=t.applyEdit=t.setProperty=t.removeProperty=void 0;const n=e("./format"),o=e("./parser");function r(e,t,n,r){const i=t.slice(),l=(0,o.parseTree)(e,[]);let s,h;for(;i.length>0&&(h=i.pop(),s=(0,o.findNodeAtLocation)(l,i),void 0===s&&void 0!==n);)n="string"==typeof h?{[h]:n}:[n];if(s){if("object"===s.type&&"string"==typeof h&&Array.isArray(s.children)){const t=(0,o.findNodeAtLocation)(s,[h]);if(void 0!==t){if(void 0===n){if(!t.parent)throw new Error("Malformed AST");const n=s.children.indexOf(t.parent);let o,i=t.parent.offset+t.parent.length;if(n>0){let e=s.children[n-1];o=e.offset+e.length}else o=s.offset+1,s.children.length>1&&(i=s.children[1].offset);return f(e,{offset:o,length:i-o,content:""},r)}return f(e,{offset:t.offset,length:t.length,content:JSON.stringify(n)},r)}{if(void 0===n)return[];const t=`${JSON.stringify(h)}: ${JSON.stringify(n)}`,o=r.getInsertionIndex?r.getInsertionIndex(s.children.map((e=>e.children[0].value))):s.children.length;let i;if(o>0){let e=s.children[o-1];i={offset:e.offset+e.length,length:0,content:","+t}}else i=0===s.children.length?{offset:s.offset+1,length:0,content:t}:{offset:s.offset+1,length:0,content:t+","};return f(e,i,r)}}if("array"===s.type&&"number"==typeof h&&Array.isArray(s.children)){const t=h;if(-1===t){const t=`${JSON.stringify(n)}`;let o;if(0===s.children.length)o={offset:s.offset+1,length:0,content:t};else{const e=s.children[s.children.length-1];o={offset:e.offset+e.length,length:0,content:","+t}}return f(e,o,r)}if(void 0===n&&s.children.length>=0){const t=h,n=s.children[t];let o;if(1===s.children.length)o={offset:s.offset+1,length:s.length-2,content:""};else if(s.children.length-1===t){let e=s.children[t-1],n=e.offset+e.length;o={offset:n,length:s.offset+s.length-2-n,content:""}}else o={offset:n.offset,length:s.children[t+1].offset-n.offset,content:""};return f(e,o,r)}if(void 0!==n){let t;const o=`${JSON.stringify(n)}`;if(!r.isArrayInsertion&&s.children.length>h){const e=s.children[h];t={offset:e.offset,length:e.length,content:o}}else if(0===s.children.length||0===h)t={offset:s.offset+1,length:0,content:0===s.children.length?o:o+","};else{const e=h>s.children.length?s.children.length:h,n=s.children[e-1];t={offset:n.offset+n.length,length:0,content:","+o}}return f(e,t,r)}throw new Error(`Can not ${void 0===n?"remove":r.isArrayInsertion?"insert":"modify"} Array index ${t} as length is not sufficient`)}throw new Error(`Can not add ${"number"!=typeof h?"index":"property"} to parent of type ${s.type}`)}if(void 0===n)throw new Error("Can not delete in empty document");return f(e,{offset:l?l.offset:0,length:l?l.length:0,content:JSON.stringify(n)},r)}function f(e,t,o){if(!o.formattingOptions)return[t];let r=i(e,t),f=t.offset,l=t.offset+t.content.length;if(0===t.length||0===t.content.length){for(;f>0&&!(0,n.isEOL)(r,f-1);)f--;for(;l<r.length&&!(0,n.isEOL)(r,l);)l++}const s=(0,n.format)(r,{offset:f,length:l-f},{...o.formattingOptions,keepLines:!1});for(let e=s.length-1;e>=0;e--){const t=s[e];r=i(r,t),f=Math.min(f,t.offset),l=Math.max(l,t.offset+t.length),l+=t.content.length-t.length}return[{offset:f,length:e.length-(r.length-l)-f,content:r.substring(f,l)}]}function i(e,t){return e.substring(0,t.offset)+t.content+e.substring(t.offset+t.length)}t.removeProperty=function(e,t,n){return r(e,t,void 0,n)},t.setProperty=r,t.applyEdit=i,t.isWS=function(e,t){return-1!=="\r\n \t".indexOf(e.charAt(t))}}));