mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
iframely, transclusion wrap default
This commit is contained in:
@@ -74,10 +74,10 @@ export const REGEX_LINK = {
|
||||
? parts.value[5]
|
||||
: parts.value[6];
|
||||
},
|
||||
getWrapLength: (parts: IteratorResult<RegExpMatchArray, any>): number => {
|
||||
getWrapLength: (parts: IteratorResult<RegExpMatchArray, any>, defaultWrap:number): number => {
|
||||
const len = parseInt(parts.value[8]);
|
||||
if (isNaN(len)) {
|
||||
return null;
|
||||
return defaultWrap > 0 ? defaultWrap : null;
|
||||
}
|
||||
return len;
|
||||
},
|
||||
@@ -762,7 +762,7 @@ export class ExcalidrawData {
|
||||
text.substring(position, parts.value.index) +
|
||||
wrapText(
|
||||
contents,
|
||||
REGEX_LINK.getWrapLength(parts),
|
||||
REGEX_LINK.getWrapLength(parts,this.plugin.settings.wordWrappingDefault),
|
||||
this.plugin.settings.forceWrap,
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
Notice,
|
||||
Menu,
|
||||
MarkdownView,
|
||||
request,
|
||||
} from "obsidian";
|
||||
import * as React from "react";
|
||||
import * as ReactDOM from "react-dom";
|
||||
@@ -1120,7 +1121,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
},
|
||||
files: excalidrawData.files,
|
||||
commitToHistory: true,
|
||||
});
|
||||
},justloaded);
|
||||
if (
|
||||
this.app.workspace.activeLeaf === this.leaf &&
|
||||
this.excalidrawWrapperRef
|
||||
@@ -1557,7 +1558,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
return { id: imageElement[0].id, fileId: imageElement[0].fileId }; //return image element fileId
|
||||
};
|
||||
|
||||
this.addText = (text: string, fontFamily?: 1 | 2 | 3 | 4) => {
|
||||
this.addText = async (text: string, fontFamily?: 1 | 2 | 3 | 4):Promise<string> => {
|
||||
if (!excalidrawRef?.current) {
|
||||
return;
|
||||
}
|
||||
@@ -1569,8 +1570,9 @@ export default class ExcalidrawView extends TextFileView {
|
||||
ea.style.fontFamily = fontFamily ?? st.currentItemFontFamily ?? 1;
|
||||
ea.style.fontSize = st.currentItemFontSize ?? 20;
|
||||
ea.style.textAlign = st.currentItemTextAlign ?? "left";
|
||||
ea.addText(currentPosition.x, currentPosition.y, text);
|
||||
this.addElements(ea.getElements(), false, true);
|
||||
const id = ea.addText(currentPosition.x, currentPosition.y, text);
|
||||
await this.addElements(ea.getElements(), false, true);
|
||||
return id;
|
||||
};
|
||||
|
||||
this.addElements = async (
|
||||
@@ -2230,39 +2232,25 @@ export default class ExcalidrawView extends TextFileView {
|
||||
this.plugin.settings.iframelyAllowed &&
|
||||
text.match(/^https?:\/\/\S*$/)
|
||||
) {
|
||||
let linkAdded = false;
|
||||
const self = this;
|
||||
ajaxPromise({
|
||||
url: `http://iframely.server.crestify.com/iframely?url=${text}`,
|
||||
}).then(
|
||||
(res) => {
|
||||
if (!res || linkAdded) {
|
||||
return false;
|
||||
}
|
||||
linkAdded = true;
|
||||
const data = JSON.parse(res);
|
||||
if (!data || !data.meta?.title) {
|
||||
this.addText(text);
|
||||
return false;
|
||||
}
|
||||
this.addText(`[${data.meta.title}](${text})`);
|
||||
(async () => {
|
||||
const id = await this.addText(text);
|
||||
const url = `http://iframely.server.crestify.com/iframely?url=${text}`;
|
||||
const data = JSON.parse(await request({url}));
|
||||
if (!data || data.error || !data.meta?.title) {
|
||||
return false;
|
||||
},
|
||||
() => {
|
||||
if (linkAdded) {
|
||||
return false;
|
||||
}
|
||||
linkAdded = true;
|
||||
self.addText(text);
|
||||
},
|
||||
);
|
||||
setTimeout(() => {
|
||||
if (linkAdded) {
|
||||
return;
|
||||
}
|
||||
linkAdded = true;
|
||||
self.addText(text);
|
||||
}, 600);
|
||||
const ea = this.plugin.ea;
|
||||
ea.reset();
|
||||
ea.setView(this);
|
||||
const el = ea.getViewElements().filter((el)=>el.id===id);
|
||||
if(el.length===1) {
|
||||
//@ts-ignore
|
||||
el[0].text = el[0].originalText = el[0].rawText = `[${data.meta.title}](${text})`;
|
||||
ea.copyViewElementsToEAforEditing(el);
|
||||
ea.addElementsToView(false, false, false);
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
return false;
|
||||
}
|
||||
this.addText(text.replace(/(!\[\[.*#[^\]]*\]\])/g, "$1{40}"));
|
||||
@@ -2669,9 +2657,9 @@ export default class ExcalidrawView extends TextFileView {
|
||||
appState?: any,
|
||||
files?: any,
|
||||
commitToHistory?: boolean,
|
||||
}) {
|
||||
}, restore: boolean = false) {
|
||||
if(!this.excalidrawAPI) return;
|
||||
if(scene.elements) {
|
||||
if(scene.elements && restore) {
|
||||
scene.elements = this.excalidrawAPI.restore(scene).elements;
|
||||
}
|
||||
this.excalidrawAPI.updateScene(scene);
|
||||
|
||||
@@ -210,6 +210,11 @@ export default {
|
||||
"Number specifies the character count where the text should be wrapped. " +
|
||||
"Set the text wrapping behavior of transcluded text. Turn this ON to force-wrap " +
|
||||
"text (i.e. no overflow), or OFF to soft-wrap text (at the nearest whitespace).",
|
||||
TRANSCLUSION_DEFAULT_WRAP_NAME: "Transclusion word wrap default",
|
||||
TRANSCLUSION_DEFAULT_WRAP_DESC:
|
||||
"You can set manually set/override word wrapping length using the `![[page#^block]]{NUMBER}` format. " +
|
||||
"Normally you will not want to set a default, because if you transclude text inside a sticky note, then Excalidraw will automatically take care of word wrapping. " +
|
||||
"Set this value to `0` if you do not want to set a default. ",
|
||||
PAGE_TRANSCLUSION_CHARCOUNT_NAME: "Page transclusion max char count",
|
||||
PAGE_TRANSCLUSION_CHARCOUNT_DESC:
|
||||
"The maximum number of characters to display from the page when transcluding an entire page with the " +
|
||||
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
VIRGIL_FONT,
|
||||
VIRGIL_DATAURL,
|
||||
} from "./Constants";
|
||||
import ExcalidrawView, { ExportSettings, TextMode } from "./ExcalidrawView";
|
||||
import ExcalidrawView, { TextMode } from "./ExcalidrawView";
|
||||
import {
|
||||
changeThemeOfExcalidrawMD,
|
||||
getMarkdownDrawingSection,
|
||||
|
||||
@@ -41,6 +41,7 @@ export interface ExcalidrawSettings {
|
||||
allowCtrlClick: boolean; //if disabled only the link button in the view header will open links
|
||||
forceWrap: boolean;
|
||||
pageTransclusionCharLimit: number;
|
||||
wordWrappingDefault: number;
|
||||
iframelyAllowed: boolean;
|
||||
pngExportScale: number;
|
||||
exportWithTheme: boolean;
|
||||
@@ -109,6 +110,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
allowCtrlClick: true,
|
||||
forceWrap: false,
|
||||
pageTransclusionCharLimit: 200,
|
||||
wordWrappingDefault: 0,
|
||||
iframelyAllowed: true,
|
||||
pngExportScale: 1,
|
||||
exportWithTheme: true,
|
||||
@@ -636,6 +638,35 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("TRANSCLUSION_DEFAULT_WRAP_NAME"))
|
||||
.setDesc(fragWithHTML(t("TRANSCLUSION_DEFAULT_WRAP_DESC")))
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("Enter a number")
|
||||
.setValue(this.plugin.settings.wordWrappingDefault.toString())
|
||||
.onChange(async (value) => {
|
||||
const intVal = parseInt(value);
|
||||
if (isNaN(intVal) && value !== "") {
|
||||
text.setValue(
|
||||
this.plugin.settings.wordWrappingDefault.toString(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.requestEmbedUpdate = true;
|
||||
if (value === "") {
|
||||
this.plugin.settings.wordWrappingDefault = 0;
|
||||
this.applySettingsUpdate(true);
|
||||
return;
|
||||
}
|
||||
this.plugin.settings.wordWrappingDefault = intVal;
|
||||
text.setValue(
|
||||
this.plugin.settings.wordWrappingDefault.toString(),
|
||||
);
|
||||
this.applySettingsUpdate(true);
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t("GET_URL_TITLE_NAME"))
|
||||
.setDesc(fragWithHTML(t("GET_URL_TITLE_DESC")))
|
||||
|
||||
Reference in New Issue
Block a user