}
* @memberof LeafView
*/
draw() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (this.plugin.settings.showRibbon) {
this.containerEl.show();
(_a = this.content) === null || _a === void 0 ? void 0 : _a.$destroy();
this.content = new AmazingMarvinTasks({
target: this.contentEl,
props: {
query: this.plugin.settings.ribbonQuery,
getData: this.plugin.amazingMarvinApi.getData.bind(this.plugin.amazingMarvinApi),
api: this.plugin.amazingMarvinApi.getApiFromType(this.plugin.settings.ribbonQuery.type),
openOrCreateDailyNote: this.plugin.fileManager.openOrCreateDailyNote.bind(this.plugin.fileManager),
},
});
}
else {
this.containerEl.hide();
}
});
}
}
/* src/ui/DailyNoteCommand.svelte generated by Svelte v3.41.0 */
function create_else_block(ctx) {
let t;
return {
c() {
t = text("Create");
},
m(target, anchor) {
insert(target, t, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(t);
}
};
}
// (29:4) {#if isCreating}
function create_if_block(ctx) {
let icon;
let t;
let current;
icon = new Icon({
props: {
class: "icon daily-note",
data: faSyncAlt,
spin: true
}
});
return {
c() {
create_component(icon.$$.fragment);
t = text("\n Creating, please wait");
},
m(target, anchor) {
mount_component(icon, target, anchor);
insert(target, t, anchor);
current = true;
},
p: noop,
i(local) {
if (current) return;
transition_in(icon.$$.fragment, local);
current = true;
},
o(local) {
transition_out(icon.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component(icon, detaching);
if (detaching) detach(t);
}
};
}
function create_fragment$2(ctx) {
let h2;
let t1;
let select;
let option0;
let option1;
let t4;
let div;
let button0;
let t6;
let button1;
let current_block_type_index;
let if_block;
let current;
let mounted;
let dispose;
const if_block_creators = [create_if_block, create_else_block];
const if_blocks = [];
function select_block_type(ctx, dirty) {
if (/*isCreating*/ ctx[1]) return 0;
return 1;
}
current_block_type_index = select_block_type(ctx);
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
return {
c() {
h2 = element("h2");
h2.textContent = "Add to daily note";
t1 = space();
select = element("select");
option0 = element("option");
option0.textContent = "Scheduled Today";
option1 = element("option");
option1.textContent = "Due Today";
t4 = space();
div = element("div");
button0 = element("button");
button0.textContent = "Cancel";
t6 = space();
button1 = element("button");
if_block.c();
option0.__value = "todayItems";
option0.value = option0.__value;
option1.__value = "dueItems";
option1.value = option1.__value;
if (/*api*/ ctx[2] === void 0) add_render_callback(() => /*select_change_handler*/ ctx[5].call(select));
attr(div, "class", "modal-button-container");
},
m(target, anchor) {
insert(target, h2, anchor);
insert(target, t1, anchor);
insert(target, select, anchor);
append(select, option0);
append(select, option1);
select_option(select, /*api*/ ctx[2]);
insert(target, t4, anchor);
insert(target, div, anchor);
append(div, button0);
append(div, t6);
append(div, button1);
if_blocks[current_block_type_index].m(button1, null);
current = true;
if (!mounted) {
dispose = [
listen(select, "change", /*select_change_handler*/ ctx[5]),
listen(button0, "click", /*click_handler*/ ctx[6]),
listen(button1, "click", /*click_handler_1*/ ctx[7])
];
mounted = true;
}
},
p(ctx, [dirty]) {
if (dirty & /*api*/ 4) {
select_option(select, /*api*/ ctx[2]);
}
let previous_block_index = current_block_type_index;
current_block_type_index = select_block_type(ctx);
if (current_block_type_index === previous_block_index) {
if_blocks[current_block_type_index].p(ctx, dirty);
} else {
group_outros();
transition_out(if_blocks[previous_block_index], 1, 1, () => {
if_blocks[previous_block_index] = null;
});
check_outros();
if_block = if_blocks[current_block_type_index];
if (!if_block) {
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
if_block.c();
} else {
if_block.p(ctx, dirty);
}
transition_in(if_block, 1);
if_block.m(button1, null);
}
},
i(local) {
if (current) return;
transition_in(if_block);
current = true;
},
o(local) {
transition_out(if_block);
current = false;
},
d(detaching) {
if (detaching) detach(h2);
if (detaching) detach(t1);
if (detaching) detach(select);
if (detaching) detach(t4);
if (detaching) detach(div);
if_blocks[current_block_type_index].d();
mounted = false;
run_all(dispose);
}
};
}
function instance($$self, $$props, $$invalidate) {
let { handleCancel } = $$props;
let { handleCreate } = $$props;
let isCreating = false;
const query = Object.assign({}, DEFAULT_APP_SETTINGS.ribbonQuery);
let api = 'dueItems';
function create() {
return __awaiter(this, void 0, void 0, function* () {
$$invalidate(1, isCreating = true);
query.type = api === 'todayItems' ? 'today' : 'due-today';
yield handleCreate(query, api).finally;
$$invalidate(1, isCreating = false);
});
}
function select_change_handler() {
api = select_value(this);
$$invalidate(2, api);
}
const click_handler = () => handleCancel();
const click_handler_1 = () => create();
$$self.$$set = $$props => {
if ('handleCancel' in $$props) $$invalidate(0, handleCancel = $$props.handleCancel);
if ('handleCreate' in $$props) $$invalidate(4, handleCreate = $$props.handleCreate);
};
return [
handleCancel,
isCreating,
api,
create,
handleCreate,
select_change_handler,
click_handler,
click_handler_1
];
}
class DailyNoteCommand extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment$2, safe_not_equal, { handleCancel: 0, handleCreate: 4 });
}
}
/**
* @class SampleModal
* @extends {Modal}
*/
class DailyNoteModal extends require$$0.Modal {
/**
* Creates an instance of DailyNoteModal.
* @param {AmazingMarvinPlugin} plugin
* @memberof DailyNoteModal
*/
constructor(plugin) {
super(plugin.app);
this.plugin = plugin;
}
/**
* @memberof SampleModal
*/
onOpen() {
const { contentEl } = this;
new DailyNoteCommand({
target: contentEl,
props: {
handleCancel: this.close,
handleCreate: (query, api) => __awaiter(this, void 0, void 0, function* () {
yield this.plugin.fileManager.openOrCreateDailyNote(moment(), query, api);
this.close();
}),
},
});
}
/**
* @memberof SampleModal
*/
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}
/* src/ui/settings/Footer.svelte generated by Svelte v3.41.0 */
function create_fragment$1(ctx) {
let div;
return {
c() {
div = element("div");
div.innerHTML = `If this plugin adds value for you and you would like to help support continued development, please buyer me a
coffee:
`;
attr(div, "class", "amazing-marvin-setting-footer");
},
m(target, anchor) {
insert(target, div, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
}
};
}
class Footer extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment$1, safe_not_equal, {});
}
}
/* src/ui/settings/Header.svelte generated by Svelte v3.41.0 */
function create_fragment(ctx) {
let div;
return {
c() {
div = element("div");
div.innerHTML = `Amazing Marvin Plugin Settings
Configure API tokens to interact with Amazing Marvin API.
For more information, you can read more on Amazing Marvin API Github`;
attr(div, "class", "amazing-marvin-setting-header");
},
m(target, anchor) {
insert(target, div, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
}
};
}
class Header extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment, safe_not_equal, {});
}
}
/**
* @class SettingTab
* @extends {PluginSettingTab}
*/
class SettingTab extends require$$0.PluginSettingTab {
/**
* Creates an instance of SettingTab.
* @param {App} app
* @param {AmazingMarvinPlugin} plugin
* @memberof SettingTab
*/
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
/**
* @memberof SettingTab
*/
display() {
const { containerEl } = this;
containerEl.empty();
new Header({ target: containerEl });
new require$$0.Setting(containerEl)
.setName('apiToken')
.setDesc('The API token needed to interact with Amazing Marvin')
.addText(text => {
text.inputEl.type = 'password';
text
.setPlaceholder('Enter your apiToken')
.setValue(this.plugin.settings.apiToken)
.onChange((apiToken) => __awaiter(this, void 0, void 0, function* () {
const apiTokenTrimmed = apiToken.trim();
this.plugin.settings.apiToken = apiTokenTrimmed;
this.plugin.amazingMarvinApi.changeToken(apiTokenTrimmed);
yield this.plugin.saveSettings();
}));
});
new require$$0.Setting(containerEl)
.setName('Show ribbon')
.setDesc('Show plugin ribbon on the left sidebar')
.addToggle(toggle => {
toggle.setValue(this.plugin.settings.showRibbon).onChange((isShowRibbon) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.showRibbon = isShowRibbon;
this.plugin.showRibbon(isShowRibbon);
isShowRibbon ? ribbonQuerySetting.settingEl.show() : ribbonQuerySetting.settingEl.hide();
yield this.plugin.saveSettings();
}));
});
const ribbonQuerySetting = new require$$0.Setting(containerEl).setName("Ribbon's Query").setDesc('The query for the ribbon');
this.plugin.settings.showRibbon ? ribbonQuerySetting.settingEl.show() : ribbonQuerySetting.settingEl.hide();
ribbonQuerySetting.controlEl.style.display = 'inline';
new require$$0.Setting(ribbonQuerySetting.controlEl.createDiv('amazing-marvin-ribbon-query-setting-dropdown'))
.setName('type')
.addDropdown(dropdown => {
dropdown
.addOptions({
today: 'Scheduled today',
'due-today': 'Due today',
})
.setValue(this.plugin.settings.ribbonQuery.type)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.ribbonQuery = Object.assign(Object.assign({}, this.plugin.settings.ribbonQuery), { type: value });
this.isRibbonSettingChanged = true;
yield this.plugin.saveSettings();
}));
});
Object.entries(this.plugin.settings.ribbonQuery).forEach(([name, value]) => {
if (typeof value === 'boolean') {
const parent = ribbonQuerySetting.controlEl.createDiv('amazing-marvin-ribbon-query-setting-toggle');
parent.style.color = this.plugin.settings.showRibbon ? undefined : 'gray';
parent.style.display = 'block';
new require$$0.Setting(parent).setName(name).addToggle(toggle => {
toggle.setDisabled(!this.plugin.settings.showRibbon);
toggle.setValue(value).onChange((newValue) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.ribbonQuery = Object.assign(Object.assign({}, this.plugin.settings.ribbonQuery), { [name]: newValue });
this.isRibbonSettingChanged = true;
yield this.plugin.saveSettings();
}));
});
}
});
new Footer({ target: containerEl });
}
/**
* @memberof SettingTab
*/
hide() {
super.hide();
if (this.isRibbonSettingChanged) {
this.plugin.leafView.draw();
this.isRibbonSettingChanged = false;
}
}
}
/**
* @export
* @class AmazingMarvinPlugin
* @extends {Plugin}
*/
class MyPlugin extends require$$0.Plugin {
/**
* Creates an instance of MyPlugin.
* @param {App} app
* @param {PluginManifest} manifest
* @memberof MyPlugin
*/
constructor(app, manifest) {
super(app, manifest);
this.amazingMarvinApi = new AmazingMarvinApi();
this.fileManager = new FileManager(this);
}
/**
* @memberof AmazingMarvinPlugin
*/
onload() {
return __awaiter(this, void 0, void 0, function* () {
yield this.loadSettings();
this.amazingMarvinApi.changeToken(this.settings.apiToken);
this.registerView(LeafViewType, leaf => (this.leafView = new LeafView(leaf, this)));
this.registerMarkdownPostProcessor(this.amazingMarvinApi.parseCodeblock.bind(this.amazingMarvinApi));
this.addSettingTab(new SettingTab(this.app, this));
this.addCommand({
id: 'scheduled-daily-note',
name: 'Add scheduled tasks to daily note',
checkCallback: (checking) => {
if (!checking) {
this.settings.showRibbon
? new DailyNoteModal(this).open()
: new require$$0.Notice('Please enable ribbon to use this command!');
}
return checking;
},
});
require$$0.addIcon('amazing-marvin-ribbon', icons.ribbon);
this.showRibbon(this.settings.showRibbon);
console.log('Amazing Marvin plugin loaded');
});
}
/**
* @memberof AmazingMarvinPlugin
*/
onunload() {
console.log('Amazing Marvin plugin unloaded');
}
/**
* @memberof AmazingMarvinPlugin
*/
loadSettings() {
return __awaiter(this, void 0, void 0, function* () {
this.settings = Object.assign({}, DEFAULT_APP_SETTINGS, yield this.loadData());
});
}
/**
* @memberof AmazingMarvinPlugin
*/
saveSettings() {
return __awaiter(this, void 0, void 0, function* () {
yield this.saveData(this.settings);
});
}
/**
* @param {boolean} value
* @memberof AmazingMarvinPlugin
*/
showRibbon(value) {
if (value) {
this.ribbon = this.addRibbonIcon('amazing-marvin-ribbon', 'Amazing Marvin', () => this.toggleLeafView());
}
else if (this.ribbon) {
this.ribbon.remove();
}
}
/**
* @private
* @return {Promise}
* @memberof MyPlugin
*/
toggleLeafView() {
return __awaiter(this, void 0, void 0, function* () {
const existing = this.app.workspace.getLeavesOfType(LeafViewType);
if (existing.length) {
this.app.workspace.revealLeaf(existing[0]);
return;
}
yield this.app.workspace.getRightLeaf(false).setViewState({
type: LeafViewType,
active: true,
});
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(LeafViewType)[0]);
});
}
}
module.exports = MyPlugin;
/* nosourcemap */