Skip to content

Commit f4b6d44

Browse files
committed
fix meta bind table bug
1 parent e0c8209 commit f4b6d44

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

exampleVault/Advanced Examples/PF2e Encounter Calculator.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ Player Level: `INPUT[number:playerLevel]`
3434
```js-engine
3535
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
3636
37-
const bindTarget = mb.createBindTarget('enemy');
37+
const bindTarget = mb.createBindTarget('enemy', context.file.path);
3838
const tableHead = ['Name', 'Level', 'Variant', 'Count'];
3939
const columns = [
40-
mb.inputField.createInputFieldDeclarationFromString('INPUT[text:^.name]'),
41-
mb.inputField.createInputFieldDeclarationFromString('INPUT[number(class(meta-bind-small-width)):^.level]'),
42-
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(-1, weak), option(0, normal), option(1, elite)):^.variant]'),
43-
mb.inputField.createInputFieldDeclarationFromString('INPUT[number(class(meta-bind-small-width)):^.count]')
40+
mb.inputField.createInputFieldDeclarationFromString('INPUT[text:scope^name]'),
41+
mb.inputField.createInputFieldDeclarationFromString('INPUT[number(class(meta-bind-small-width)):scope^level]'),
42+
mb.inputField.createInputFieldDeclarationFromString('INPUT[inlineSelect(option(-1, weak), option(0, normal), option(1, elite)):scope^variant]'),
43+
mb.inputField.createInputFieldDeclarationFromString('INPUT[number(class(meta-bind-small-width)):scope^count]')
4444
];
4545
4646
mb.createTable(container, context.file.path, component, bindTarget, tableHead, columns);

src/fields/metaBindTable/MetaBindTable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class MetaBindTable extends AbstractMDRC {
117117

118118
const cells = this.columns.map(x => {
119119
if ('inputFieldType' in x) {
120+
console.log('validate', x, this.filePath, scope);
120121
return this.plugin.api.inputFieldParser.validateDeclaration(x, this.filePath, scope);
121122
} else {
122123
return this.plugin.api.viewFieldParser.validateDeclaration(x, this.filePath, scope);

src/metadata/MetadataManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class MetadataManager {
112112
return;
113113
}
114114

115-
if (subscription.bindTarget?.storageType === BindTargetStorageType.LOCAL) {
115+
if (subscription.bindTarget?.storageType === BindTargetStorageType.SCOPE) {
116116
// local scope should be resolved by the time the subscription is created
117117
throw new MetaBindInternalError({
118118
errorLevel: ErrorLevel.CRITICAL,

src/parsers/BindTargetDeclaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export enum BindTargetStorageType {
2525
FRONTMATTER = 'frontmatter',
2626
MEMORY = 'memory',
2727
GLOBAL_MEMORY = 'globalMemory',
28-
LOCAL = 'localScope',
28+
SCOPE = 'scope',
2929
}

src/parsers/BindTargetParser.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class BindTargetParser {
3939
): BindTargetDeclaration {
4040
const bindTargetDeclaration: BindTargetDeclaration = {} as BindTargetDeclaration;
4141

42+
bindTargetDeclaration.storageProp = new PropPath(
43+
unvalidatedBindTargetDeclaration.storageProp.map(x => new PropAccess(x.type, x.prop.value)),
44+
);
45+
4246
if (unvalidatedBindTargetDeclaration.storageType === undefined) {
4347
bindTargetDeclaration.storageType = BindTargetStorageType.FRONTMATTER;
4448
} else {
@@ -83,22 +87,20 @@ export class BindTargetParser {
8387
);
8488
}
8589
bindTargetDeclaration.storagePath = '';
86-
} else if (bindTargetDeclaration.storageType === BindTargetStorageType.LOCAL) {
90+
} else if (bindTargetDeclaration.storageType === BindTargetStorageType.SCOPE) {
8791
if (unvalidatedBindTargetDeclaration.storagePath !== undefined) {
8892
throw new ParsingValidationError(
8993
ErrorLevel.ERROR,
9094
'Bind Target Validator',
91-
`Failed to parse bind target. Bind target storage type LOCAL does not support a storage path.`,
95+
`Failed to parse bind target. Bind target storage type SCOPE does not support a storage path.`,
9296
fullDeclaration,
9397
unvalidatedBindTargetDeclaration.storagePath.position,
9498
);
9599
}
100+
bindTargetDeclaration.storagePath = '';
96101
this.resolveScope(bindTargetDeclaration, scope);
97102
}
98103

99-
bindTargetDeclaration.storageProp = new PropPath(
100-
unvalidatedBindTargetDeclaration.storageProp.map(x => new PropAccess(x.type, x.prop.value)),
101-
);
102104
bindTargetDeclaration.listenToChildren = unvalidatedBindTargetDeclaration.listenToChildren;
103105

104106
return bindTargetDeclaration;
@@ -115,6 +117,8 @@ export class BindTargetParser {
115117
'Failed to resolve bind target scope, no scope provided',
116118
);
117119
} else {
120+
console.log('resolve scope', bindTarget, scope.scope);
121+
118122
bindTarget.storageType = scope.scope.storageType;
119123
bindTarget.storagePath = scope.scope.storagePath;
120124
bindTarget.storageProp = scope.scope.storageProp.concat(bindTarget.storageProp);

src/utils/prop/PropPath.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class PropPath {
2525
try {
2626
return this.get(obj);
2727
} catch (e) {
28-
console.error(e);
2928
return undefined;
3029
}
3130
}

0 commit comments

Comments
 (0)