Skip to content

Commit dc7dac0

Browse files
committed
good thing i don't listen to sail, because this works fine
1 parent d13865d commit dc7dac0

File tree

23 files changed

+173
-96
lines changed

23 files changed

+173
-96
lines changed

exampleVault/Input Fields/List.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ list:
44
- banana
55
- berries
66
- https://github.com/
7-
- "[[test]]"
87
list2:
98
- "[[Other/Example Notes/Example Note with Image.md|Example Note with Image]]"
109
- "[[Other/Example Notes/Example Note with Callouts.md|Example Note with Callouts]]"

exampleVault/examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
slider1: 6
2+
slider1: 3
33
suggest: test
44
toggle1: false
55
Domestic_tasks:
@@ -8,10 +8,10 @@ Meditate: 100
88
Slept: 00:00
99
select: option d
1010
toggle: false
11-
nested:
12-
object: asd
1311
inlineSelect: 0
1412
こんにちは: hello
13+
nested:
14+
object: test
1515
---
1616

1717
## In callouts

src/api/API.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '../parsers/viewFieldParser/ViewFieldDeclaration';
2626
import { ViewFieldFactory } from '../viewFields/ViewFieldFactory';
2727
import { getUUID } from '../utils/Utils';
28+
import { parsePropPath } from '../utils/prop/PropParser';
2829

2930
export class API implements IAPI {
3031
public plugin: MetaBindPlugin;
@@ -216,7 +217,7 @@ export class API implements IAPI {
216217
signal,
217218
{
218219
filePath: filePath,
219-
metadataPath: metadataPath,
220+
metadataPath: parsePropPath(metadataPath),
220221
listenToChildren: listenToChildren,
221222
boundToLocalScope: false,
222223
},

src/api/InputFieldAPI.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type UnvalidatedInputFieldDeclaration,
88
} from '../parsers/inputFieldParser/InputFieldDeclaration';
99
import { type InputFieldArgumentType, type InputFieldType } from '../parsers/GeneralConfigs';
10+
import { PROP_ACCESS_TYPE } from '../utils/prop/PropAccess';
1011

1112
export class InputFieldAPI {
1213
private readonly api: IAPI;
@@ -151,11 +152,17 @@ export class InputFieldAPI {
151152
}
152153

153154
if (unvalidatedDeclaration.bindTarget) {
154-
unvalidatedDeclaration.bindTarget.path = bindTargetMetadataField.map(x => ({ value: x }));
155+
unvalidatedDeclaration.bindTarget.path = bindTargetMetadataField.map(x => ({
156+
type: PROP_ACCESS_TYPE.OBJECT,
157+
prop: { value: x },
158+
}));
155159
} else {
156160
unvalidatedDeclaration.bindTarget = {
157161
file: undefined,
158-
path: bindTargetMetadataField.map(x => ({ value: x })),
162+
path: bindTargetMetadataField.map(x => ({
163+
type: PROP_ACCESS_TYPE.OBJECT,
164+
prop: { value: x },
165+
})),
159166
boundToLocalScope: false,
160167
listenToChildren: false,
161168
};

src/inputFields/fields/InlineList/InlineListComponent.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<script lang="ts">
22
import Icon from '../../../utils/components/Icon.svelte';
3-
import { isMdLink, parseMdLink } from '../../../parsers/MarkdownLinkParser';
4-
import LinkComponent from '../../../utils/components/LinkComponent.svelte';
53
import { MBLiteral } from '../../../utils/Literal';
64
import LiteralRenderComponent from '../../../utils/components/LiteralRenderComponent.svelte';
75

src/inputFields/fields/InlineListSuggester/InlineListSuggesterComponent.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<script lang="ts">
2-
import { Button } from 'obsidian-svelte';
32
import Icon from '../../../utils/components/Icon.svelte';
4-
import { isMdLink, parseMdLink } from '../../../parsers/MarkdownLinkParser';
5-
import LinkComponent from '../../../utils/components/LinkComponent.svelte';
63
import { MBLiteral } from '../../../utils/Literal';
74
import LiteralRenderComponent from '../../../utils/components/LiteralRenderComponent.svelte';
85

src/inputFields/fields/ListSuggester/ListSuggesterComponent.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<script lang="ts">
22
import { Button } from 'obsidian-svelte';
33
import Icon from '../../../utils/components/Icon.svelte';
4-
import { isMdLink, parseMdLink } from '../../../parsers/MarkdownLinkParser';
5-
import LinkComponent from '../../../utils/components/LinkComponent.svelte';
64
import { MBLiteral } from '../../../utils/Literal';
75
import LiteralRenderComponent from '../../../utils/components/LiteralRenderComponent.svelte';
86

src/metaBindTable/MetaBindTable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919

2020
import { type MetadataSubscription } from '../metadata/MetadataSubscription';
2121
import { type MBExtendedLiteral } from '../utils/Literal';
22+
import { parsePropPath } from '../utils/prop/PropParser';
2223

2324
export type MetaBindTableCell = InputFieldDeclaration | ViewFieldDeclaration;
2425

@@ -108,7 +109,7 @@ export class MetaBindTable extends AbstractMDRC {
108109
for (let i = 0; i < values.length; i++) {
109110
if (typeof values[i] === 'object') {
110111
const scope = new BindTargetScope({
111-
metadataPath: [...this.bindTarget.metadataPath, i.toString()],
112+
metadataPath: this.bindTarget.metadataPath.concat(parsePropPath([i.toString()])),
112113
filePath: this.bindTarget.filePath,
113114
listenToChildren: false,
114115
boundToLocalScope: false,

src/metadata/MetadataManager.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { areArraysEqual, arrayStartsWith, traverseObjectToParentByPath } from '../utils/Utils';
2-
import { traverseObjectByPath } from '@opd-libs/opd-utils-lib/lib/ObjectTraversalUtils';
1+
import { areArraysEqual, arrayStartsWith } from '../utils/Utils';
32
import { type Signal } from '../utils/Signal';
43
import { type Metadata, type MetadataManagerCacheItem } from './MetadataManagerCacheItem';
54
import { type FullBindTarget } from '../parsers/inputFieldParser/InputFieldDeclaration';
@@ -12,6 +11,8 @@ import {
1211
type ComputedSubscriptionDependency,
1312
type ComputeFunction,
1413
} from './ComputedMetadataSubscription';
14+
import { PropUtils } from '../utils/prop/PropUtils';
15+
import { type PropPath } from '../utils/prop/PropPath';
1516

1617
export const metadataCacheUpdateCycleThreshold = 5; // {syncInterval (200)} * 5 = 1s
1718
export const metadataCacheInactiveCycleThreshold = 5 * 60; // {syncInterval (200)} * 5 * 60 = 1 minute
@@ -31,7 +32,11 @@ function hasUpdateOverlap(a: FullBindTarget | undefined, b: FullBindTarget | und
3132
return false;
3233
}
3334

34-
return metadataPathHasUpdateOverlap(a.metadataPath, b.metadataPath, b.listenToChildren);
35+
return metadataPathHasUpdateOverlap(
36+
a.metadataPath.toStringArray(),
37+
b.metadataPath.toStringArray(),
38+
b.listenToChildren,
39+
);
3540
}
3641

3742
/**
@@ -62,7 +67,7 @@ function bindTargetToString(a: FullBindTarget | undefined): string {
6267
return 'undefined';
6368
}
6469

65-
return `${a.filePath}#${a.metadataPath}`;
70+
return `${a.filePath}#${a.metadataPath.toString()}`;
6671
}
6772

6873
export class MetadataManager {
@@ -97,17 +102,21 @@ export class MetadataManager {
97102

98103
if (fileCache) {
99104
console.debug(
100-
`meta-bind | MetadataManager >> registered ${subscription.uuid} to existing file cache ${subscription.bindTarget.filePath} -> ${subscription.bindTarget.metadataPath}`,
105+
`meta-bind | MetadataManager >> registered ${subscription.uuid} to existing file cache ${
106+
subscription.bindTarget.filePath
107+
} -> ${subscription.bindTarget.metadataPath.toString()}`,
101108
);
102109

103110
fileCache.inactive = false;
104111
fileCache.cyclesSinceInactive = 0;
105112
fileCache.listeners.push(subscription);
106113

107-
subscription.notify(traverseObjectByPath(subscription.bindTarget.metadataPath, fileCache.metadata));
114+
subscription.notify(PropUtils.tryGet(fileCache.metadata, subscription.bindTarget.metadataPath));
108115
} else {
109116
console.debug(
110-
`meta-bind | MetadataManager >> registered ${subscription.uuid} to newly created file cache ${subscription.bindTarget.filePath} -> ${subscription.bindTarget.metadataPath}`,
117+
`meta-bind | MetadataManager >> registered ${subscription.uuid} to newly created file cache ${
118+
subscription.bindTarget.filePath
119+
} -> ${subscription.bindTarget.metadataPath.toString()}`,
111120
);
112121

113122
// const file = this.plugin.app.vault.getAbstractFileByPath(subscription.bindTarget.filePath) as TFile;
@@ -129,7 +138,7 @@ export class MetadataManager {
129138
newCache.metadata,
130139
);
131140

132-
subscription.notify(traverseObjectByPath(subscription.bindTarget.metadataPath, newCache.metadata));
141+
subscription.notify(PropUtils.tryGet(newCache.metadata, subscription.bindTarget.metadataPath));
133142

134143
this.createCacheForFile(subscription.bindTarget.filePath, newCache);
135144
}
@@ -400,18 +409,8 @@ export class MetadataManager {
400409
return;
401410
}
402411

403-
const { parent, child } = traverseObjectToParentByPath(metadataPath, fileCache.metadata);
412+
PropUtils.setAndCreate(fileCache.metadata, metadataPath, value);
404413

405-
if (parent.value == null) {
406-
throw Error(
407-
`The parent of "${JSON.stringify(
408-
metadataPath,
409-
)}" does not exist in Object, please create the parent first`,
410-
);
411-
}
412-
413-
// @ts-ignore
414-
parent.value[child.key] = value;
415414
fileCache.cyclesSinceLastChange = 0;
416415
fileCache.changed = true;
417416

@@ -454,7 +453,7 @@ export class MetadataManager {
454453
*/
455454
notifyListeners(
456455
fileCache: MetadataManagerCacheItem,
457-
metadataPath?: string[] | undefined,
456+
metadataPath?: PropPath | undefined,
458457
exceptUuid?: string | undefined,
459458
): void {
460459
// console.log(fileCache);
@@ -471,20 +470,20 @@ export class MetadataManager {
471470
if (metadataPath) {
472471
if (
473472
metadataPathHasUpdateOverlap(
474-
metadataPath,
475-
listener.bindTarget.metadataPath,
473+
metadataPath.toStringArray(),
474+
listener.bindTarget.metadataPath.toStringArray(),
476475
listener.bindTarget.listenToChildren,
477476
)
478477
) {
479-
const value: unknown = traverseObjectByPath(listener.bindTarget.metadataPath, fileCache.metadata);
478+
const value: unknown = PropUtils.tryGet(fileCache.metadata, listener.bindTarget.metadataPath);
480479
console.debug(
481480
`meta-bind | MetadataManager >> notifying input field ${listener.uuid} of updated metadata value`,
482481
value,
483482
);
484483
listener.notify(value);
485484
}
486485
} else {
487-
const value: unknown = traverseObjectByPath(listener.bindTarget.metadataPath, fileCache.metadata);
486+
const value: unknown = PropUtils.tryGet(fileCache.metadata, listener.bindTarget.metadataPath);
488487
console.debug(
489488
`meta-bind | MetadataManager >> notifying input field ${listener.uuid} of updated metadata`,
490489
listener.bindTarget.metadataPath,

src/parsers/BindTargetParser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
type UnvalidatedBindTargetDeclaration,
99
} from './inputFieldParser/InputFieldDeclaration';
1010
import { type BindTargetScope } from '../metadata/BindTargetScope';
11+
import { PropAccess } from '../utils/prop/PropAccess';
12+
import { PropPath } from '../utils/prop/PropPath';
1113

1214
export class BindTargetParser {
1315
plugin: IPlugin;
@@ -56,7 +58,9 @@ export class BindTargetParser {
5658
}
5759
}
5860

59-
bindTargetDeclaration.metadataPath = unvalidatedBindTargetDeclaration.path.map(x => x.value);
61+
bindTargetDeclaration.metadataPath = new PropPath(
62+
unvalidatedBindTargetDeclaration.path.map(x => new PropAccess(x.type, x.prop.value)),
63+
);
6064
bindTargetDeclaration.boundToLocalScope = unvalidatedBindTargetDeclaration.boundToLocalScope;
6165
bindTargetDeclaration.listenToChildren = unvalidatedBindTargetDeclaration.listenToChildren;
6266

0 commit comments

Comments
 (0)