-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch-relation-input.js
More file actions
53 lines (48 loc) · 2.64 KB
/
Copy pathpatch-relation-input.js
File metadata and controls
53 lines (48 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require('fs');
let file = 'c:/Users/admin/Dropbox/Apps/remotely-save/Croptop/.obsidian/plugins/proxima/src/modals/Modals.ts';
let content = fs.readFileSync(file, 'utf8');
const relationOld = ` const renderRelation = () => {
tWrap.empty();
localVals.forEach(val => {
const pill = tWrap.createEl('span', { cls: 'pos-tag-pill', text: String(val).replace(/\\[\\[|\\]\\]/g, '') });
const xBtn = pill.createEl('span', { cls: 'pos-tag-pill-remove', text: 'x', attr: { style: 'margin-left: 4px;' } });
xBtn.addEventListener('click', () => {
localVals = localVals.filter(t => t !== val);
customPropValues[schema.id] = localVals;
renderRelation();
});
});
};
renderRelation();`;
const relationNew = ` const renderRelation = () => {
tWrap.empty();
localVals.forEach(val => {
const pill = tWrap.createEl('span', { cls: 'pos-tag-pill', text: String(val).replace(/\\[\\[|\\]\\]/g, '') });
const xBtn = pill.createEl('span', { cls: 'pos-tag-pill-remove', text: 'x', attr: { style: 'margin-left: 4px; cursor: pointer;' } });
xBtn.addEventListener('click', () => {
localVals = localVals.filter(t => t !== val);
customPropValues[schema.id] = localVals;
renderRelation();
});
});
const inp = tWrap.createEl('input', { type: 'text', cls: 'pos-modal-input', attr: { placeholder: 'Link to note...', style: 'border: none; padding: 2px 4px; min-width: 100px; flex: 1; background: transparent; outline: none; box-shadow: none;' } });
inp.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
let val = inp.value.trim();
if (val) {
if (!val.startsWith('[[')) val = '[[' + val;
if (!val.endsWith(']]')) val = val + ']]';
if (!localVals.includes(val)) {
localVals.push(val);
customPropValues[schema.id] = localVals;
renderRelation();
}
}
}
});
};
renderRelation();`;
content = content.replace(relationOld, relationNew);
fs.writeFileSync(file, content);
console.log('Patched Modals.ts relation input');