Skip to content

Commit 3787aef

Browse files
committed
fix #164; move things around
1 parent 0213492 commit 3787aef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+568
-270
lines changed

exampleVault/Advanced Examples/Activity Tracker.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
22
activities:
3-
- {}
3+
- activity: sudying
4+
status: 0
5+
from: 02:02
6+
to: 03:02
47
---
58

69
```js-engine
710
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
811
9-
const bindTarget = mb.createBindTarget('activities');
12+
const bindTarget = mb.createBindTarget('activities', context.file.path);
1013
const tableHead = ['From', 'To', 'Activity', 'Status'];
1114
const columns = [
12-
mb.inputField.createInputFieldDeclarationFromString('INPUT[time:^.from]'),
13-
mb.inputField.createInputFieldDeclarationFromString('INPUT[time:^.to]'),
14-
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(youtube), option(sudying), option(linch)):^.activity]'),
15-
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(-, unproductive), option(0, normal), option(+, productive)):^.status]')
15+
mb.inputField.createInputFieldDeclarationFromString('INPUT[time:scope^from]'),
16+
mb.inputField.createInputFieldDeclarationFromString('INPUT[time:scope^to]'),
17+
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(youtube), option(sudying), option(linch)):scope^activity]'),
18+
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(-, unproductive), option(0, normal), option(+, productive)):scope^status]')
1619
];
1720
1821

exampleVault/Examples.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ inlineSelect: 0
1212
こんにちは: hello
1313
nested:
1414
object: test
15+
number1: 2
16+
number2: 16
1517
---
1618

1719
## Fields Work Everywhere
@@ -92,6 +94,12 @@ Inline input fields should not cause line breaks.
9294

9395
Lorem ipsum dolor sit amet, `INPUT[date():other note#date]` consectetur adipiscing elit. Pellentesque sit amet porttitor arcu. Quisque scelerisque dolor augue, et posuere nulla bibendum nec. `INPUT[date():other note#date]` Curabitur sed rhoncus nisl. Maecenas nisi justo, viverra vel tempus vel, hendrerit at metus. `INPUT[datePicker():other note#date]` asdasd asdasdasd
9496

97+
98+
| test | table | |
99+
| ---- | ---- | ---- |
100+
| `INPUT[datePicker():other note#date]` | `VIEW[{other note#date}][text]` | |
101+
| `INPUT[number:number1]` | `VIEW[{slider1} * {number1}][math:number2]` | |
102+
95103
## Templates
96104

97105
For input fields, templates can be set in the plugin settings

exampleVault/Other Note.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
tags: test
33
title: test test
44
select: option a
5-
date: 2023-09-16
5+
date: 2023-09-22
66
time: 19:20
77
multi-select:
88
- option a

src/IPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type IAPI } from './api/IAPI';
22
import { type MetaBindPluginSettings } from './settings/Settings';
33
import { type MetadataManager } from './metadata/MetadataManager';
4-
import { type IInternalAPI } from './internalApi/IInternalAPI';
4+
import { type IInternalAPI } from './api/internalApi/IInternalAPI';
55

66
export interface IPlugin {
77
readonly api: IAPI;

src/api/API.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { InputFieldMDRC } from '../renderChildren/InputFieldMDRC';
22
import { ViewFieldParser } from '../parsers/viewFieldParser/ViewFieldParser';
3-
import { BindTargetParser } from '../parsers/BindTargetParser';
3+
import { BindTargetParser } from '../parsers/bindTargetParser/BindTargetParser';
44
import { ViewFieldMDRC } from '../renderChildren/ViewFieldMDRC';
55
import { JsViewFieldMDRC } from '../renderChildren/JsViewFieldMDRC';
66
import type MetaBindPlugin from '../main';
@@ -28,7 +28,7 @@ import { parsePropPath } from '../utils/prop/PropParser';
2828
import { RenderChildType } from '../config/FieldConfigs';
2929
import { type ButtonActionRunner } from '../fields/button/ButtonActionRunner';
3030
import { ButtonManager } from '../fields/button/ButtonManager';
31-
import { type BindTargetDeclaration, BindTargetStorageType } from '../parsers/BindTargetDeclaration';
31+
import { type BindTargetDeclaration, BindTargetStorageType } from '../parsers/bindTargetParser/BindTargetDeclaration';
3232
import { ObsidianButtonActionRunner } from '../fields/button/ObsidianButtonActionRunner';
3333
import { ButtonMDRC } from '../renderChildren/ButtonMDRC';
3434
import { InlineButtonMDRC } from '../renderChildren/InlineButtonMDRC';

src/api/IAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type InputFieldDeclarationParser } from '../parsers/inputFieldParser/InputFieldParser';
22
import { type ViewFieldParser } from '../parsers/viewFieldParser/ViewFieldParser';
3-
import { type BindTargetParser } from '../parsers/BindTargetParser';
3+
import { type BindTargetParser } from '../parsers/bindTargetParser/BindTargetParser';
44
import { type IPlugin } from '../IPlugin';
55
import { type InputFieldAPI } from './InputFieldAPI';
66
import { type InputFieldFactory } from '../fields/inputFields/InputFieldFactory';

src/api/InputFieldAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../parsers/inputFieldParser/InputFieldDeclaration';
88
import { type InputFieldArgumentType, type InputFieldType } from '../config/FieldConfigs';
99
import { PROP_ACCESS_TYPE } from '../utils/prop/PropAccess';
10-
import { type UnvalidatedBindTargetDeclaration } from '../parsers/BindTargetDeclaration';
10+
import { type UnvalidatedBindTargetDeclaration } from '../parsers/bindTargetParser/BindTargetDeclaration';
1111

1212
export class InputFieldAPI {
1313
private readonly api: IAPI;

src/api/SyntaxHighlightingAPI.ts

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,17 @@
1-
import { type ParsingPosition, type ParsingRange } from '@lemons_dev/parsinom/lib/HelperTypes';
21
import { ParsingError, runParser } from '../parsers/ParsingError';
3-
import {
4-
BIND_TARGET_HLP,
5-
INLINE_BUTTON_DECLARATION_HLP,
6-
INPUT_FIELD_DECLARATION_HLP,
7-
VIEW_FIELD_DECLARATION_HLP,
8-
} from '../parsers/HLPUtils';
92
import { InlineMDRCType } from '../utils/InlineMDRCUtils';
103
import { type IPlugin } from '../IPlugin';
114
import { type IAPI } from './IAPI';
125
import { P_UTILS } from '@lemons_dev/parsinom/lib/ParserUtils';
136
import { type Parser } from '@lemons_dev/parsinom/lib/Parser';
14-
15-
export class Highlight {
16-
range: ParsingRange;
17-
tokenClass: string;
18-
19-
constructor(range: ParsingRange, tokenClass: string) {
20-
this.range = range;
21-
this.tokenClass = tokenClass;
22-
}
23-
}
24-
25-
export class SyntaxHighlighting {
26-
str: string;
27-
highlights: Highlight[];
28-
parsingError?: ParsingError;
29-
30-
constructor(str: string, highlights: Highlight[], parsingError?: ParsingError) {
31-
this.str = str;
32-
this.highlights = highlights.filter(x => x.range.from.index !== x.range.to.index);
33-
this.parsingError = parsingError;
34-
}
35-
36-
getHighlights(): Highlight[] {
37-
if (this.parsingError === undefined) {
38-
return this.highlights;
39-
}
40-
41-
let errorTo: ParsingPosition;
42-
43-
if (this.str[this.parsingError.parseFailure.furthest.index] === '\n') {
44-
errorTo = {
45-
index: this.parsingError.parseFailure.furthest.index + 1,
46-
column: 1,
47-
line: this.parsingError.parseFailure.furthest.line + 1,
48-
};
49-
} else {
50-
errorTo = {
51-
index: this.parsingError.parseFailure.furthest.index + 1,
52-
column: this.parsingError.parseFailure.furthest.column + 1,
53-
line: this.parsingError.parseFailure.furthest.line,
54-
};
55-
}
56-
57-
return [
58-
new Highlight(
59-
{
60-
from: this.parsingError.parseFailure.furthest,
61-
to: errorTo,
62-
},
63-
'error',
64-
),
65-
];
66-
}
67-
}
7+
import { SyntaxHighlighting } from '../parsers/syntaxHighlighting/SyntaxHighlighting';
8+
import { type Highlight } from '../parsers/syntaxHighlighting/Highlight';
9+
import {
10+
BIND_TARGET_HLP,
11+
INLINE_BUTTON_DECLARATION_HLP,
12+
INPUT_FIELD_DECLARATION_HLP,
13+
VIEW_FIELD_DECLARATION_HLP,
14+
} from '../parsers/syntaxHighlighting/HLPs';
6815

6916
export class SyntaxHighlightingAPI {
7017
public readonly api: IAPI;

src/internalApi/IInternalAPI.ts renamed to src/api/internalApi/IInternalAPI.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { type SuggesterLikeIFP, type SuggesterOption } from '../fields/inputFields/fields/Suggester/SuggesterHelper';
2-
import { type MBLiteral } from '../utils/Literal';
3-
import { type ImageSuggesterIPF } from '../fields/inputFields/fields/ImageSuggester/ImageSuggesterIPF';
4-
import { type DatePickerIPF } from '../fields/inputFields/fields/DatePicker/DatePickerIPF';
1+
import { type SuggesterLikeIFP, type SuggesterOption } from '../../fields/inputFields/fields/Suggester/SuggesterHelper';
2+
import { type MBLiteral } from '../../utils/Literal';
3+
import { type ImageSuggesterIPF } from '../../fields/inputFields/fields/ImageSuggester/ImageSuggesterIPF';
4+
import { type DatePickerIPF } from '../../fields/inputFields/fields/DatePicker/DatePickerIPF';
55

66
export interface IInternalAPI {
77
openTextPromptModal(

src/internalApi/ObsidianAPIAdapter.ts renamed to src/api/internalApi/ObsidianAPIAdapter.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { type IInternalAPI } from './IInternalAPI';
2-
import type MetaBindPlugin from '../main';
2+
import type MetaBindPlugin from '../../main';
33
import { type App, Component, MarkdownRenderer, TFile } from 'obsidian';
4-
import { type DatePickerIPF } from '../fields/inputFields/fields/DatePicker/DatePickerIPF';
5-
import { type ImageSuggesterIPF } from '../fields/inputFields/fields/ImageSuggester/ImageSuggesterIPF';
6-
import { type SuggesterLikeIFP, type SuggesterOption } from '../fields/inputFields/fields/Suggester/SuggesterHelper';
7-
import { type MBLiteral } from '../utils/Literal';
8-
import { TextPromptModal } from '../utils/modals/TextPromptModal';
9-
import { openSuggesterModalForInputField } from '../fields/inputFields/fields/Suggester/SuggesterModalHelper';
10-
import { openImageSuggesterModalForInputField } from '../fields/inputFields/fields/ImageSuggester/ImageSuggesterModalHelper';
11-
import { DatePickerInputModal } from '../fields/inputFields/fields/DatePicker/DatePickerInputModal';
12-
import { type API as JsEngineAPI } from 'jsEngine/api/API';
13-
import type JsEnginePlugin from 'jsEngine/main';
14-
15-
function getJsEngineAPI(app: App): JsEngineAPI | undefined {
16-
return (app.plugins.getPlugin('js-engine') as JsEnginePlugin | undefined)?.api;
17-
}
4+
import { type DatePickerIPF } from '../../fields/inputFields/fields/DatePicker/DatePickerIPF';
5+
import { type ImageSuggesterIPF } from '../../fields/inputFields/fields/ImageSuggester/ImageSuggesterIPF';
6+
import { type SuggesterLikeIFP, type SuggesterOption } from '../../fields/inputFields/fields/Suggester/SuggesterHelper';
7+
import { type MBLiteral } from '../../utils/Literal';
8+
import { TextPromptModal } from '../../utils/modals/TextPromptModal';
9+
import { openSuggesterModalForInputField } from '../../fields/inputFields/fields/Suggester/SuggesterModalHelper';
10+
import { openImageSuggesterModalForInputField } from '../../fields/inputFields/fields/ImageSuggester/ImageSuggesterModalHelper';
11+
import { DatePickerInputModal } from '../../fields/inputFields/fields/DatePicker/DatePickerInputModal';
12+
import { getJsEnginePluginAPI } from '../../utils/ObsUtils';
1813

1914
export class ObsidianAPIAdapter implements IInternalAPI {
2015
readonly plugin: MetaBindPlugin;
@@ -66,10 +61,7 @@ export class ObsidianAPIAdapter implements IInternalAPI {
6661
callingFilePath: string,
6762
container?: HTMLElement,
6863
): Promise<() => void> {
69-
const jsEngineAPI = getJsEngineAPI(this.app);
70-
if (!jsEngineAPI) {
71-
throw new Error('js-engine plugin not found');
72-
}
64+
const jsEngineAPI = getJsEnginePluginAPI(this.plugin);
7365

7466
const callingFile = this.app.vault.getAbstractFileByPath(callingFilePath);
7567
if (!callingFile || !(callingFile instanceof TFile)) {
@@ -92,10 +84,7 @@ export class ObsidianAPIAdapter implements IInternalAPI {
9284
}
9385

9486
public async jsEngineRunCode(code: string, callingFilePath: string, container?: HTMLElement): Promise<() => void> {
95-
const jsEngineAPI = getJsEngineAPI(this.app);
96-
if (!jsEngineAPI) {
97-
throw new Error('js-engine plugin not found');
98-
}
87+
const jsEngineAPI = getJsEnginePluginAPI(this.plugin);
9988

10089
const callingFile = this.app.vault.getAbstractFileByPath(callingFilePath);
10190
if (!callingFile || !(callingFile instanceof TFile)) {

0 commit comments

Comments
 (0)