You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
11 KiB

/*
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
*/
'use strict';
var obsidian = require('obsidian');
//string to array of classes
const arrayToClasses = (input) => {
input = input.trim();
if (input[0] != "[" || input[input.length - 1] != "]")
return [];
return input
.substring(1, input.length - 1)
.trim()
.split(/\s*,\s*/);
};
class EventFactory {
constructor(root, sourcePath) {
this.root = root;
this.sourcePath = sourcePath;
}
//remove first child's top margin and last child's bottom margin
regulate(component) {
let aux = component.lastChild;
aux.style.marginBottom = "0";
aux = component.firstChild;
aux.style.marginTop = "0";
}
create(time, title, description) {
let timeEl = this.root.createDiv({ cls: "time" });
let infoEl = this.root.createDiv({ cls: "info" });
let titleEl = infoEl.createDiv({ cls: "title" });
let descriptionEl = infoEl.createDiv({ cls: "description" });
obsidian.MarkdownRenderer.renderMarkdown(time, timeEl, this.sourcePath, null);
obsidian.MarkdownRenderer.renderMarkdown(title, titleEl, this.sourcePath, null);
obsidian.MarkdownRenderer.renderMarkdown(description, descriptionEl, this.sourcePath, null);
this.regulate(descriptionEl);
this.regulate(timeEl);
this.regulate(titleEl);
}
}
const codeBlockHandler = (source, el, ctx) => {
//Initial State
el.addClass("timeline");
let ef = new EventFactory(el, ctx.sourcePath);
//source to events
const events = source
.split(/^\s*\+ ?/gm)
.map((event) => (event.trim().length != 0 ? event : "\u200B"));
for (let elClass of arrayToClasses(events[0]))
el.addClass(elClass);
const incompleteCounter = (events.length - 1) % 3;
const completeCounter = events.length - 1 - incompleteCounter;
//build it
el.createDiv({
cls: "main-line",
attr: {
style: `grid-row-end: ${completeCounter / 3 + 1 + (incompleteCounter != 0 ? 1 : 0)}`,
},
});
for (let i = 1; i < completeCounter; i += 3) {
ef.create(events[i], events[i + 1], events[i + 2]);
}
switch (incompleteCounter) {
case 1:
ef.create(events[completeCounter + 1], "", "");
return;
case 2:
ef.create(events[completeCounter + 1], events[completeCounter + 2], "");
return;
default:
return;
}
};
class MyPlugin extends obsidian.Plugin {
onload() {
this.registerMarkdownCodeBlockProcessor("timeline", codeBlockHandler);
}
}
module.exports = MyPlugin;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibWFpbi50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQge1xyXG5cdFBsdWdpbixcclxuXHRNYXJrZG93blBvc3RQcm9jZXNzb3JDb250ZXh0LFxyXG5cdE1hcmtkb3duUmVuZGVyZXIsXHJcbn0gZnJvbSBcIm9ic2lkaWFuXCI7XHJcblxyXG4vL3N0cmluZyB0byBhcnJheSBvZiBjbGFzc2VzXHJcbmNvbnN0IGFycmF5VG9DbGFzc2VzID0gKGlucHV0OiBzdHJpbmcpOiBzdHJpbmdbXSA9PiB7XHJcblx0aW5wdXQgPSBpbnB1dC50cmltKCk7XHJcblx0aWYgKGlucHV0WzBdICE9IFwiW1wiIHx8IGlucHV0W2lucHV0Lmxlbmd0aCAtIDFdICE9IFwiXVwiKSByZXR1cm4gW107XHJcblxyXG5cdHJldHVybiBpbnB1dFxyXG5cdFx0LnN1YnN0cmluZygxLCBpbnB1dC5sZW5ndGggLSAxKVxyXG5cdFx0LnRyaW0oKVxyXG5cdFx0LnNwbGl0KC9cXHMqLFxccyovKTtcclxufTtcclxuXHJcbmNsYXNzIEV2ZW50RmFjdG9yeSB7XHJcblx0cm9vdDogSFRNTEVsZW1lbnQ7XHJcblx0c291cmNlUGF0aDogc3RyaW5nO1xyXG5cclxuXHRjb25zdHJ1Y3Rvcihyb290OiBIVE1MRWxlbWVudCwgc291cmNlUGF0aDogc3RyaW5nKSB7XHJcblx0XHR0aGlzLnJvb3QgPSByb290O1xyXG5cdFx0dGhpcy5zb3VyY2VQYXRoID0gc291cmNlUGF0aDtcclxuXHR9XHJcblxyXG5cdC8vcmVtb3ZlIGZpcnN0IGNoaW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