Skip to content

Commit 6819822

Browse files
committed
disable mathjs for testing
1 parent 4648d98 commit 6819822

File tree

4 files changed

+83
-58
lines changed

4 files changed

+83
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ data.json
2323

2424
obsidian.css
2525
tmp.txt
26+
meta.txt
2627

2728
!exampleVault/.obsidian
2829

esbuild.config.mjs

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import esbuild from 'esbuild';
1+
import esbuild, { analyzeMetafile } from 'esbuild';
22
import process from 'process';
33
import builtins from 'builtin-modules';
44
import esbuildSvelte from 'esbuild-svelte';
@@ -18,48 +18,54 @@ if you want to view the source, please visit the github repository of this plugi
1818
*/
1919
`;
2020

21-
esbuild
22-
.build({
23-
banner: {
24-
js: banner,
25-
},
26-
entryPoints: ['src/main.ts'],
27-
bundle: true,
28-
external: [
29-
'obsidian',
30-
'electron',
31-
'@codemirror/autocomplete',
32-
'@codemirror/collab',
33-
'@codemirror/commands',
34-
'@codemirror/language',
35-
'@codemirror/lint',
36-
'@codemirror/search',
37-
'@codemirror/state',
38-
'@codemirror/view',
39-
'@lezer/common',
40-
'@lezer/highlight',
41-
'@lezer/lr',
42-
...builtins,
43-
],
44-
format: 'cjs',
45-
target: 'es2018',
46-
logLevel: 'info',
47-
sourcemap: false,
48-
treeShaking: true,
49-
outfile: 'main.js',
50-
minify: true,
51-
define: {
52-
MB_GLOBAL_CONFIG_DEV_BUILD: 'false',
53-
},
54-
plugins: [
55-
esbuildSvelte({
56-
compilerOptions: { css: 'injected' },
57-
preprocess: sveltePreprocess(),
58-
filterWarnings: warning => {
59-
// we don't want warnings from node modules that we can do nothing about
60-
return !warning.filename.includes('node_modules');
61-
},
62-
}),
63-
],
64-
})
65-
.catch(() => process.exit(1));
21+
const context = await esbuild.context({
22+
banner: {
23+
js: banner,
24+
},
25+
entryPoints: ['src/main.ts'],
26+
bundle: true,
27+
external: [
28+
'obsidian',
29+
'electron',
30+
'@codemirror/autocomplete',
31+
'@codemirror/collab',
32+
'@codemirror/commands',
33+
'@codemirror/language',
34+
'@codemirror/lint',
35+
'@codemirror/search',
36+
'@codemirror/state',
37+
'@codemirror/view',
38+
'@lezer/common',
39+
'@lezer/highlight',
40+
'@lezer/lr',
41+
...builtins,
42+
],
43+
format: 'cjs',
44+
target: 'es2018',
45+
logLevel: 'info',
46+
sourcemap: false,
47+
treeShaking: true,
48+
outfile: 'main.js',
49+
minify: true,
50+
metafile: true,
51+
define: {
52+
MB_GLOBAL_CONFIG_DEV_BUILD: 'false',
53+
},
54+
plugins: [
55+
esbuildSvelte({
56+
compilerOptions: { css: 'injected' },
57+
preprocess: sveltePreprocess(),
58+
filterWarnings: warning => {
59+
// we don't want warnings from node modules that we can do nothing about
60+
return !warning.filename.includes('node_modules');
61+
},
62+
}),
63+
],
64+
});
65+
66+
const build = await context.rebuild();
67+
console.log(await analyzeMetafile(build.metafile));
68+
69+
const file = Bun.file('meta.txt')
70+
await Bun.write(file, JSON.stringify(build.metafile, null, '\t'));
71+
process.exit(0)

exampleVault/Advanced Examples/Using JS Engine for Complex things.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
text: asd
2+
text: aaa
33
locked: false
44
---
55

@@ -29,3 +29,20 @@ signal.registerListener({
2929
return reactive;
3030
```
3131

32+
```js-engine
33+
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
34+
35+
const signal = mb.createSignal(undefined)
36+
component.register(mb.listenToMetadata(signal, context.file.path, ['text']))
37+
38+
function onUpdate(value) {
39+
return value.toString()
40+
}
41+
42+
const reactive = engine.reactive(onUpdate, signal.get())
43+
signal.registerListener({
44+
callback: (v) => reactive.refresh(v),
45+
})
46+
47+
return reactive;
48+
```

src/fields/viewFields/fields/MathVF.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { AbstractViewField } from '../AbstractViewField';
22
import { type ViewFieldDeclaration } from '../../../parsers/viewFieldParser/ViewFieldDeclaration';
33
import { type ViewFieldMDRC, type ViewFieldVariable } from '../../../renderChildren/ViewFieldMDRC';
44
import { ErrorLevel, MetaBindExpressionError } from '../../../utils/errors/MetaBindErrors';
5-
import * as MathJs from 'mathjs';
5+
// import { type EvalFunction, compile as MathJsCompile } from 'mathjs';
66
import { Signal } from '../../../utils/Signal';
77
import { getUUID } from '../../../utils/Utils';
88

99
export class MathVF extends AbstractViewField {
1010
container?: HTMLElement;
11-
expression?: MathJs.EvalFunction;
11+
// expression?: EvalFunction;
1212
expressionStr?: string;
1313

1414
hidden: boolean;
@@ -43,7 +43,7 @@ export class MathVF extends AbstractViewField {
4343
}
4444
}
4545

46-
this.expression = MathJs.compile(this.expressionStr);
46+
// this.expression = MathJsCompile(this.expressionStr);
4747

4848
return variables;
4949
}
@@ -71,17 +71,18 @@ export class MathVF extends AbstractViewField {
7171
}
7272

7373
async computeValue(variables: ViewFieldVariable[]): Promise<string> {
74-
if (!this.expression) {
75-
throw new MetaBindExpressionError({
76-
errorLevel: ErrorLevel.ERROR,
77-
effect: 'failed to evaluate expression',
78-
cause: 'expression is undefined',
79-
});
80-
}
74+
// if (!this.expression) {
75+
// throw new MetaBindExpressionError({
76+
// errorLevel: ErrorLevel.ERROR,
77+
// effect: 'failed to evaluate expression',
78+
// cause: 'expression is undefined',
79+
// });
80+
// }
8181

8282
const context = this.buildContext(variables);
8383
try {
84-
return this.expression.evaluate(context) as Promise<string>;
84+
// return this.expression.evaluate(context) as Promise<string>;
85+
return 'mathjs is disabled';
8586
} catch (e) {
8687
if (e instanceof Error) {
8788
throw new MetaBindExpressionError({

0 commit comments

Comments
 (0)