This document provides detailed information on the built-in core plugins for CodeJarPro, including how to use their APIs and all available configuration options.
Provides a powerful and adaptive line number display feature for the editor. It automatically handles inconsistencies in line height caused by code wrapping and editor resizing.
javascript import { LineNumbers } from 'codejarpro/plugins'; const lineNumbers = cjp.addPlugin(LineNumbers, { show: true });
config.show: boolean: Controls the visibility of the line numbers.true(default): Shows the line numbers.false: Hides the line numbers.
The plugin instance lineNumbers exposes the following methods:
-
lineNumbers.updateConfig(config)Dynamically updates the configuration of the line numbers plugin.
Example:
// Hide line numbers lineNumbers.updateConfig({ show: false });
Allows you to insert a visual marker at any row and column in the code, which is ideal for displaying syntax errors, warnings, or other informational messages.
This plugin does not require initial configuration.
import { InsertMark } from 'codejarpro/plugins';
const insertMark = cjp.addPlugin(InsertMark);The plugin instance insertMark exposes the following core methods:
-
insertMark.addMarker(info)Adds a marker at a specified position.
info: object: An object containing the marker's details:markerId: string: A unique ID for the marker.index?: number: The character position (starting from 0); priority higher thanlinecolumn.line?: number: The line number (starting from 1); priority lower thanindex.column?: number: The column number (starting from 1); priority lower thanindex.message?: string: A tooltip message to display when hovering over the marker.markerClass?: string: The CSS class name to apply to the marker's<span>element.markerStyle?: string: Inline styles to apply to the marker.
-
insertMark.removeMarker(markerId): Removes a specific marker by its ID. -
insertMark.removeAllMarkers(): Removes all markers created by this plugin.
// Assuming 'insertMark' is an instance of the InsertMark plugin
// and 'cjp' is the CodeJarPro instance.
const code = cjp.toString();
try {
JSON.parse(code);
// Parse successful, remove old error markers
insertMark.removeMarker('json-syntax-error');
} catch (e) {
// Parse failed, find error position
// (parseErrorPosition is a helper function you might need to write)
const pos = parseErrorPosition(e.message, code);
// Add marker at the error position
insertMark.addMarker({
markerId: 'json-syntax-error',
line: pos.line,
column: pos.column,
message: e.message,
markerClass: 'error-marker' // A CSS class for styling
});
}Automatically detects and marks JSON syntax errors in the editor, providing real-time JSON format validation.
import { JsonValidate } from 'codejarpro/plugins';
const jsonValidate = cjp.addPlugin(JsonValidate, {
enabled: true,
// Optional: custom styling
markerClass: 'json-error-marker',
// Optional: callback for errors
onError: (error, pos) => {
if (error) {
console.log(`JSON Error: ${error.message} at line ${pos.line}`);
} else {
console.log('JSON is valid!');
}
}
});config.enabled: boolean | ((code: string) => boolean): Controls whether the plugin is enabled. Can be a boolean or a function that returns a boolean. Default:false.config.ignoreEmpty?: boolean: Ignore empty values. Default:true.config.markerClass?: string: The CSS class name to apply to error markers.config.markerStyle?: string: Inline styles to apply to error markers.config.onBeforeValidate?: (code: string, options: PluginOptions) => boolean | void: Callback function before validation; returningfalsewill abort subsequent validation.config.onValidate?: (error: Error | false, code?: string, pos?: { line?: number; column?: number; index: number }) => void: Callback function when an error is found or cleared.error: Error | false: The error object if an error is found, orfalseif the code is valid.code?: string: The current code in the editor.pos?: { line?: number; column?: number; index: number }: The position of the error in the code.
jsonValidate.updateConfig(config): Dynamically updates the plugin configuration.jsonValidate.validate(code): Manually triggers a JSON validation. Returnstrueif an error is found.
Real-time counting of characters, words, and display of current cursor position (line and column numbers).
import { WordCounter } from 'codejarpro/plugins';
// Create a target element in your HTML: <div id="counter-display"></div>
const counterElement = document.getElementById('counter-display');
const wordCounter = cjp.addPlugin(WordCounter, {
show: true,
target: counterElement,
format: (info) => `Chars: ${info.chars} | Words: ${info.words} | Pos: ${info.row}:${info.col}`
});config.show?: boolean | ((code: string) => boolean): Controls whether the plugin is enabled. Can be a boolean or a function that returns a boolean. Default:true.config.target?: HTMLElement: The HTML element to display the counting information. If not provided, adivwill be created automatically.config.format?: (info) => string: A custom function to format the counting information.info.words: number: Number of words.info.chars: number: Number of characters.info.row: number: Current cursor line number.info.col: number: Current cursor column number.
wordCounter.updateConfig(config): Dynamically updates the plugin configuration.
The WordCounter module also exports a useful helper function:
getLineColumn(source: string, index: number): Gets the line and column number for a character at a specific index in a string.
import { getLineColumn } from 'codejarpro/plugins/wordCounter'; // Note the import path
const text = 'Hello\nWorld';
const position = getLineColumn(text, 7); // { line: 2, column: 2 }All plugins share the following common method:
plugin.enabled: Enables the plugin.plugin.updateConfig(config): Dynamically updates the plugin configuration.plugin.destroy(): Destroys the plugin instance, cleans up resources, and removes all related DOM elements.
// Destroy plugins that are no longer needed
lineNumbers.destroy();
jsonValidate.destroy();