forked from FINAKON/HelpProject
1. Initial Commit - a boiler plate code and POC to realize the concept of context sensitive help 2. Frontend code written in ReactJS 3. Backend code written in Java, Spring Boot Framework 4. Frontend Start: pre-requisites : node, npm npm run dev ==> to start the frontend vite server 5. Backend Start: pre-requisites : java, mvn mvn spring-boot:run ==> to start the backend server 6. Visit http://localhost:5173/ for basic demo of help, press F1 in textboxes 7. Visit http://localhost:5173/editor and enter "admin123" to add/modify texts. Happy Coding !!! Thank you, Bhargava.
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import Text from './text';
|
|
import Parchment from 'parchment';
|
|
|
|
|
|
class Inline extends Parchment.Inline {
|
|
static compare(self, other) {
|
|
let selfIndex = Inline.order.indexOf(self);
|
|
let otherIndex = Inline.order.indexOf(other);
|
|
if (selfIndex >= 0 || otherIndex >= 0) {
|
|
return selfIndex - otherIndex;
|
|
} else if (self === other) {
|
|
return 0;
|
|
} else if (self < other) {
|
|
return -1;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
formatAt(index, length, name, value) {
|
|
if (Inline.compare(this.statics.blotName, name) < 0 && Parchment.query(name, Parchment.Scope.BLOT)) {
|
|
let blot = this.isolate(index, length);
|
|
if (value) {
|
|
blot.wrap(name, value);
|
|
}
|
|
} else {
|
|
super.formatAt(index, length, name, value);
|
|
}
|
|
}
|
|
|
|
optimize(context) {
|
|
super.optimize(context);
|
|
if (this.parent instanceof Inline &&
|
|
Inline.compare(this.statics.blotName, this.parent.statics.blotName) > 0) {
|
|
let parent = this.parent.isolate(this.offset(), this.length());
|
|
this.moveChildren(parent);
|
|
parent.wrap(this);
|
|
}
|
|
}
|
|
}
|
|
Inline.allowedChildren = [Inline, Parchment.Embed, Text];
|
|
// Lower index means deeper in the DOM tree, since not found (-1) is for embeds
|
|
Inline.order = [
|
|
'cursor', 'inline', // Must be lower
|
|
'underline', 'strike', 'italic', 'bold', 'script',
|
|
'link', 'code' // Must be higher
|
|
];
|
|
|
|
|
|
export default Inline;
|