1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-11 10:18:07 +09:00
This commit is contained in:
Andrew Simachev 2023-11-07 21:49:51 +01:00
parent d97bc92721
commit 5385624b35
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
4 changed files with 28 additions and 20 deletions

3
dist/iframe.html vendored
View file

@ -36,12 +36,9 @@
document.head.appendChild(script);
script.onload = function (e) {
console.log(e, src);
if (list.length) {
loadScripts(list, callBack);
} else {
console.log('run app');
if (callBack) {
callBack();
};

View file

@ -524,9 +524,11 @@
"blockBookmarkError": "There was an error fetching the url",
"blockLatexPlaceholder": "Enter text in format LaTeX",
"blockLatexTemplate": "Template formula",
"blockLatexEmpty": "Here your equation will be rendered with <span class='icon text'></span>. Click to edit",
"blockEmbedLatexPlaceholder": "Enter text in format LaTeX",
"blockEmbedLatexTemplate": "Template formula",
"blockEmbedLatexEmpty": "Here your equation will be rendered with <span class='icon text'></span>. Click to edit",
"blockEmbedSource": "Source",
"blockTableOfContentsAdd": "Add headings to create a table of contents",

View file

@ -17,9 +17,15 @@
-webkit-user-modify: read-write-plaintext-only; display: none; border-radius: 4px; margin-top: 8px;
}
.button.source { position: absolute; top: 10px; right: 10px; display: none; }
iframe { width: 100%; height: 400px; }
}
.block.blockEmbed:hover {
.button.source { display: inline-flex; }
}
.block.blockEmbed.isLatex {
.wrap.isEditing {
.select { display: inline-block; }

View file

@ -4,7 +4,7 @@ import Prism from 'prismjs';
import raf from 'raf';
import mermaid from 'mermaid';
import { observer } from 'mobx-react';
import { Icon, Label } from 'Component';
import { Icon, Label, Button } from 'Component';
import { I, keyboard, UtilCommon, C, focus, Renderer, translate } from 'Lib';
import { menuStore, commonStore, blockStore } from 'Store';
import { getRange, setRange } from 'selection-ranges';
@ -51,19 +51,20 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
let select = null;
let empty = '';
let button = null;
switch (processor) {
case I.EmbedProcessor.Latex: {
select = (
<div className="selectWrap">
<div id="select" className="select" onClick={this.onTemplate}>
<div className="name">{translate('blockLatexTemplate')}</div>
<div className="name">{translate('blockEmbedLatexTemplate')}</div>
<Icon className="arrow light" />
</div>
</div>
);
empty = translate('blockLatexEmpty');
empty = translate('blockEmbedLatexEmpty');
break;
};
@ -72,6 +73,10 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
};
};
if (processor != I.EmbedProcessor.Latex) {
button = <Button className="source c28" text={translate('blockEmbedSource')} onClick={this.onEdit} />;
};
return (
<div
ref={node => this.node = node}
@ -82,6 +87,7 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
onFocus={this.onFocusBlock}
>
{select}
{button}
<div id="value" onClick={this.onEdit} />
<Label id="empty" className="empty" text={empty} onClick={this.onEdit} />
@ -90,7 +96,7 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
id="input"
contentEditable={!readonly}
suppressContentEditableWarning={true}
placeholder={translate('blockLatexPlaceholder')}
placeholder={translate('blockEmbedLatexPlaceholder')}
onSelect={this.onSelect}
onFocus={this.onFocusInput}
onBlur={this.onBlurInput}
@ -433,16 +439,17 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
this.text = String(text || '');
if (!this.text) {
this.value.html('');
return;
};
const { block } = this.props;
const { processor } = block.content;
const node = $(this.node);
switch (processor) {
default: {
if (!this.text) {
break;
};
let iframe = node.find('iframe');
const sandbox = [ 'allow-scripts' ];
@ -482,12 +489,12 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
};
case I.EmbedProcessor.Latex: {
this.value.html(this.text ? katex.renderToString(this.text, {
this.value.html(katex.renderToString(this.text, {
displayMode: true,
throwOnError: false,
output: 'html',
trust: (context: any) => [ '\\url', '\\href', '\\includegraphics' ].includes(context.command),
}) : '');
}));
this.value.find('a').each((i: number, item: any) => {
item = $(item);
@ -503,10 +510,6 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
};
case I.EmbedProcessor.Mermaid: {
if (!this.text) {
break;
};
mermaid.mermaidAPI.render(this.getContainerId(), this.text).then(res => {
this.value.html(res.svg || this.text);