Socket
Socket
Sign inDemoInstall

codejar

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.6.0 to 3.7.0

6

codejar.d.ts

@@ -1,2 +0,2 @@

declare type Options = {
type Options = {
tab: string;

@@ -12,3 +12,3 @@ indentOn: RegExp;

};
export declare type Position = {
export type Position = {
start: number;

@@ -18,3 +18,3 @@ end: number;

};
export declare type CodeJar = ReturnType<typeof CodeJar>;
export type CodeJar = ReturnType<typeof CodeJar>;
export declare function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement, pos?: Position) => void, opt?: Partial<Options>): {

@@ -21,0 +21,0 @@ updateOptions(newOptions: Partial<Options>): void;

@@ -66,3 +66,3 @@ const globalWindow = window;

}
if (isLegacy)
if (isLegacy && !isCopy(event))
restore(save());

@@ -100,2 +100,10 @@ });

throw 'error1';
// If the anchor and focus are the editor element, return either a full
// highlight or a start/end cursor position depending on the selection
if (anchorNode === editor && focusNode === editor) {
pos.start = (anchorOffset > 0 && editor.textContent) ? editor.textContent.length : 0;
pos.end = (focusOffset > 0 && editor.textContent) ? editor.textContent.length : 0;
pos.dir = (focusOffset >= anchorOffset) ? '->' : '<-';
return pos;
}
// Selection anchor and focus are expected to be text nodes,

@@ -384,7 +392,16 @@ // so normalize them.

function isUndo(event) {
return isCtrl(event) && !event.shiftKey && event.code === 'KeyZ';
return isCtrl(event) && !event.shiftKey && getKeyCode(event) === 'Z';
}
function isRedo(event) {
return isCtrl(event) && event.shiftKey && event.code === 'KeyZ';
return isCtrl(event) && event.shiftKey && getKeyCode(event) === 'Z';
}
function isCopy(event) {
return isCtrl(event) && getKeyCode(event) === 'C';
}
function getKeyCode(event) {
let key = event.key || event.keyCode || event.which;
if (!key)
return undefined;
return (typeof key === 'string' ? key : String.fromCharCode(key)).toUpperCase();
}
function insert(text) {

@@ -391,0 +408,0 @@ text = text

@@ -107,3 +107,3 @@ const globalWindow = window

if (isLegacy) restore(save())
if (isLegacy && !isCopy(event)) restore(save())
})

@@ -142,2 +142,11 @@

// If the anchor and focus are the editor element, return either a full
// highlight or a start/end cursor position depending on the selection
if (anchorNode === editor && focusNode === editor) {
pos.start = (anchorOffset > 0 && editor.textContent) ? editor.textContent.length : 0
pos.end = (focusOffset > 0 && editor.textContent) ? editor.textContent.length : 0
pos.dir = (focusOffset >= anchorOffset) ? '->' : '<-'
return pos
}
// Selection anchor and focus are expected to be text nodes,

@@ -446,9 +455,19 @@ // so normalize them.

function isUndo(event: KeyboardEvent) {
return isCtrl(event) && !event.shiftKey && event.code === 'KeyZ'
return isCtrl(event) && !event.shiftKey && getKeyCode(event) === 'Z'
}
function isRedo(event: KeyboardEvent) {
return isCtrl(event) && event.shiftKey && event.code === 'KeyZ'
return isCtrl(event) && event.shiftKey && getKeyCode(event) === 'Z'
}
function isCopy(event: KeyboardEvent) {
return isCtrl(event) && getKeyCode(event) === 'C'
}
function getKeyCode(event: KeyboardEvent): string | undefined {
let key = event.key || event.keyCode || event.which
if (!key) return undefined
return (typeof key === 'string' ? key : String.fromCharCode(key)).toUpperCase()
}
function insert(text: string) {

@@ -455,0 +474,0 @@ text = text

@@ -1,2 +0,2 @@

declare type Position = {
type Position = {
top: string;

@@ -3,0 +3,0 @@ left: string;

@@ -1,2 +0,2 @@

declare type Options = {
type Options = {
class: string;

@@ -3,0 +3,0 @@ wrapClass: string;

{
"name": "codejar",
"version": "3.6.0",
"version": "3.7.0",
"description": "An embeddable code editor for the browser",

@@ -22,6 +22,6 @@ "license": "MIT",

"devDependencies": {
"babel-minify": "^0.5.1",
"gzip-size-cli": "^3.0.0",
"release-it": "^14.5.1",
"typescript": "^4.2.3"
"babel-minify": "^0.5.2",
"gzip-size-cli": "^5.1.0",
"release-it": "^15.6.0",
"typescript": "^4.9.5"
},

@@ -28,0 +28,0 @@ "release-it": {

@@ -37,7 +37,7 @@ <p align="center"><a href="https://medv.io/codejar/"><img src="https://medv.io/assets/codejar.svg" width="72"></a></p>

<script>
let jar = CodeJar(document.querySelector('.editor'), Prism.highlightElement)
let jar = CodeJar(document.querySelector('.editor'), hljs.highlightElement)
</script>
```
Second argument to `CodeJar` is a highlighting function (in this example [PrismJS](https://prismjs.com)), but any function may be used:
Second argument to `CodeJar` is a highlighting function (in this example [highlight.js](https://highlightjs.org)), but any function may be used:

@@ -44,0 +44,0 @@ ```ts

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc