代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/Formula-Editor 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
公式编辑器借助 web-service 库,通过事件的触发和监听实现数据交互,有 webview 和 documentEvent 两种通信方式。下面的示例均以 documentEvent 作为通信通道,公式编辑器启用 documentEvent 需要在 url 中增加 protocol,详细请参照readme
格式如下
{
type: string; // 信令的类型
headers: {
reqId: string; // 信令的请求id,每次都随机
}
data: {
body: object, // body中存储具体数据
},
}
以导出公式-common.setFormula 为例,控制台输入如下调试语句:
document.addEventListener('documentMessage', (e) => {
console.log(e);
});
可以看到调试数据如下所示:
CustomEvent:
{
...
detail: {
type: 'common.setFormula',
headers: {
reqId: '......'
},
data: {
body: {
formula: '<>',
formulaSrc: 'data:image/png;base64,......'
}
}
}
}
1、关闭弹窗
document.addEventListener('documentMessage', (e) => {
const { type } = e?.detail;
const msg = e?.detail?.data?.body;
if (type !== 'common.closeModal') return;
console.log('关闭');
});
2、鼠标点击左侧 tab 切换事件
属性名 | 类型 | 默认值 | 备注 |
---|---|---|---|
type | 'common'|'algebra'|'geometry'|'letter'|'other' | 无 | 当前字符类型 |
document.addEventListener('documentMessage', (e) => {
const { type } = e?.detail;
const msg = e?.detail?.data?.body;
if (type !== 'common.setType') return;
console.log('msg', msg.type); // msg algebra
});
3、鼠标点击 latex 字符事件
属性名 | 类型 | 默认值 | 备注 |
---|---|---|---|
key | string | 无 | 键盘字符的 latex 值 |
document.addEventListener('documentMessage', (e) => {
const { type } = e?.detail;
const msg = e?.detail?.data?.body;
if (type !== 'common.selectKey') return;
console.log('msg', msg.key); // msg \delta
});
4、导出公式事件
属性名 | 类型 | 默认值 | 备注 |
---|---|---|---|
formula | string | 无 | 总 latex 值 |
formulaSrc | string | 无 | base64 格式的 url |
document.addEventListener('documentMessage', (e) => {
const { type } = e?.detail;
const msg = e?.detail?.data?.body;
if (type !== 'common.setFormula') return;
console.log('msg', msg.formula, msg.formulaSrc); // msg 123 data:image/png;......
});
5、初始化事件
document.addEventListener('documentMessage', (e) => {
const { type } = e?.detail;
const msg = e?.detail?.data?.body;
if (type !== 'common.ready') return;
console.log('已准备');
});
6、设置公式初始值
属性名 | 类型 | 默认值 | 备注 |
---|---|---|---|
formula | string | 无 | 总 latex 值 |
const event = new CustomEvent('documentMessage', {
detail: {
type: 'common.readFormula',
headers: {
reqId: 1,
},
data: {
body: {
formula: 'abc',
},
},
},
});
document.dispatchEvent(event);
7、清空公式编辑器
const event = new CustomEvent('documentMessage', {
detail: {
type: 'common.clearFormula',
headers: {
reqId: 2,
},
data: {
body: {},
},
},
});
document.dispatchEvent(event);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。