This commit is contained in:
Oscar Plaisant
2025-03-16 18:05:45 +01:00
parent 29453462f9
commit f91c506a9e
572 changed files with 233842 additions and 19574 deletions

View File

@@ -110,6 +110,7 @@ var require_kind_of = __commonJS({
return "symbol";
case "Promise":
return "promise";
// Set, Map, WeakSet, WeakMap
case "WeakMap":
return "weakmap";
case "WeakSet":
@@ -118,16 +119,19 @@ var require_kind_of = __commonJS({
return "map";
case "Set":
return "set";
// 8-bit typed arrays
case "Int8Array":
return "int8array";
case "Uint8Array":
return "uint8array";
case "Uint8ClampedArray":
return "uint8clampedarray";
// 16-bit typed arrays
case "Int16Array":
return "int16array";
case "Uint16Array":
return "uint16array";
// 32-bit typed arrays
case "Int32Array":
return "int32array";
case "Uint32Array":
@@ -144,6 +148,7 @@ var require_kind_of = __commonJS({
switch (type) {
case "[object Object]":
return "object";
// iterators
case "[object Map Iterator]":
return "mapiterator";
case "[object Set Iterator]":
@@ -6698,7 +6703,7 @@ function legacyRestEndpointMethods(octokit) {
legacyRestEndpointMethods.VERSION = VERSION7;
// node_modules/@octokit/rest/dist-src/version.js
var VERSION8 = "21.0.1";
var VERSION8 = "21.0.2";
// node_modules/@octokit/rest/dist-src/index.js
var Octokit2 = Octokit.plugin(requestLog, legacyRestEndpointMethods, paginateRest).defaults(
@@ -6740,6 +6745,16 @@ var upsertSharedGistForFile = (sharedGist, fileContents) => {
return import_gray_matter.default.stringify(content, updatedData);
}
};
var removeSharedGistForFile = (sharedGist, fileContents) => {
const { data, content } = (0, import_gray_matter.default)(fileContents);
const existingSharedGists = data.gists || [];
const sharedGistsWithGistRemoved = existingSharedGists.filter(
(existingSharedGist) => existingSharedGist.id !== sharedGist.id
);
const updatedData = __spreadProps(__spreadValues({}, data), { gists: sharedGistsWithGistRemoved });
if (sharedGistsWithGistRemoved.length === 0) delete updatedData.gists;
return import_gray_matter.default.stringify(content, updatedData);
};
// src/storage.ts
var DOTCOM_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "share_as_gist_dotcom_access_token";
@@ -6806,6 +6821,39 @@ var updateGist = (opts) => __async(void 0, null, function* () {
};
}
});
var deleteGist = (opts) => __async(void 0, null, function* () {
const { sharedGist } = opts;
const baseUrl = getBaseUrlForSharedGist(sharedGist);
const accessToken = getAccessTokenForBaseUrl(baseUrl);
if (!accessToken) {
return {
status: "failed" /* Failed */,
errorMessage: `No access token found for the ${baseUrl} target.`
};
}
try {
const octokit = new Octokit2({
auth: accessToken,
baseUrl
});
yield octokit.rest.gists.delete({
gist_id: sharedGist.id
});
return {
status: "succeeded" /* Succeeded */,
errorMessage: null
};
} catch (e) {
let errorMessage = "An unknown error occurred.";
if (e instanceof Error) {
errorMessage = e.message;
}
return {
status: "failed" /* Failed */,
errorMessage
};
}
});
var createGist = (opts) => __async(void 0, null, function* () {
try {
const { content, description, filename, isPublic, target } = opts;
@@ -6928,6 +6976,59 @@ var openGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
window.open(sharedGist.url, "_blank");
}
});
var deleteGistEditorCallback = (opts) => () => __async(void 0, null, function* () {
const { app, plugin } = opts;
const view = app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
if (!view) {
return new import_obsidian.Notice("No active file");
}
const editor = view.editor;
const originalContent = editor.getValue();
const existingSharedGists = getSharedGistsForFile(originalContent);
if (existingSharedGists.length === 0) {
const { enableUpdatingGistsAfterCreation } = yield getLatestSettings(plugin);
if (!enableUpdatingGistsAfterCreation) {
return new import_obsidian.Notice(
"You need to enable 'Update gists after creation' in Settings to use this command."
);
} else {
return new import_obsidian.Notice("There are no gists associated with this note.");
}
}
if (existingSharedGists.length > 1) {
new SelectExistingGistModal(
app,
existingSharedGists,
false,
(sharedGist) => __async(void 0, null, function* () {
const result = yield deleteGist({ sharedGist });
if (result.status === "succeeded" /* Succeeded */) {
const updatedContent = removeSharedGistForFile(
sharedGist,
originalContent
);
editor.setValue(updatedContent);
new import_obsidian.Notice("Gist deleted");
} else {
new import_obsidian.Notice(`Error: ${result.errorMessage}`);
}
})
).open();
} else {
const sharedGist = existingSharedGists[0];
const result = yield deleteGist({ sharedGist });
if (result.status === "succeeded" /* Succeeded */) {
const updatedContent = removeSharedGistForFile(
sharedGist,
originalContent
);
editor.setValue(updatedContent);
new import_obsidian.Notice("Gist deleted");
} else {
new import_obsidian.Notice(`Error: ${result.errorMessage}`);
}
}
});
var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* () {
const { isPublic, app, plugin, target } = opts;
const { enableUpdatingGistsAfterCreation, includeFrontMatter } = yield getLatestSettings(plugin);
@@ -7136,6 +7237,15 @@ var ShareAsGistPlugin = class extends import_obsidian.Plugin {
}),
performCheck: hasAtLeastOneSharedGist
});
this.addEditorCommandWithCheck({
id: "delete-gist",
name: "Delete gist",
callback: deleteGistEditorCallback({
plugin: this,
app: this.app
}),
performCheck: hasAtLeastOneSharedGist
});
}
addModifyCallback() {
const previousContents = {};