Skip to content

Commit

Permalink
lnote-1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhwagk committed Dec 2, 2023
1 parent 6143c7f commit 699cebe
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lnote",
"displayName": "lnote",
"description": "A simple note-taking extension.",
"version": "1.0.7",
"version": "1.0.8",
"icon": "icon.png",
"publisher": "shinhwagk",
"preview": true,
Expand Down
219 changes: 218 additions & 1 deletion test-notesdata/@test/notes.json
Original file line number Diff line number Diff line change
@@ -1 +1,218 @@
{"4248d9":{"cts":1683016895402,"contents":[""],"mts":1683016895402,"gls":{"domain":["@test","ccc","x"],"##nb":["@test"]}},"31a707":{"cts":1683016902878,"contents":[""],"mts":1683016902878,"gls":{"domain":["@test","ccc","x"],"##nb":["@test"]}},"789efb":{"cts":1683016951732,"contents":[""],"mts":1683016951732,"gls":{"domain":["@test","ccc","x"],"##nb":["@test"]}},"a02543":{"cts":1683016954679,"contents":["2221"],"mts":1683019891261,"gls":{"domain":["@test","ccc","x"],"##nb":["@test"]}},"a78f93":{"cts":1683020138388,"contents":[""],"mts":1683020142147,"gls":{"##nb":["@test"],"domain":["@test","ccc","ff"]}}}
{
"149317": {
"cts": 1700981365156,
"contents": [
"333"
],
"mts": 1700981650585,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc",
"x"
]
}
},
"214242": {
"cts": 1700981754640,
"contents": [
"xxxx"
],
"mts": 1700981761228,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc"
]
}
},
"214471": {
"cts": 1700981313685,
"contents": [
"1"
],
"mts": 1700981319471,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc"
]
}
},
"860340": {
"cts": 1700982458556,
"contents": [
""
],
"mts": 1700982477583,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc",
"x"
]
}
},
"4248d9": {
"cts": 1683016895402,
"contents": [
""
],
"mts": 1683016895402,
"gls": {
"domain": [
"@test",
"ccc",
"x"
],
"##nb": [
"@test"
]
}
},
"31a707": {
"cts": 1683016902878,
"contents": [
"xxx"
],
"mts": 1700981881531,
"gls": {
"domain": [
"@test",
"ccc"
],
"##nb": [
"@test"
]
}
},
"789efb": {
"cts": 1683016951732,
"contents": [
""
],
"mts": 1700981679112,
"gls": {
"domain": [
"@test",
"ccc",
"ee"
],
"##nb": [
"@test"
]
}
},
"a02543": {
"cts": 1683016954679,
"contents": [
"2221"
],
"mts": 1683019891261,
"gls": {
"domain": [
"@test",
"ccc",
"x"
],
"##nb": [
"@test"
]
}
},
"a78f93": {
"cts": 1683020138388,
"contents": [
""
],
"mts": 1683020142147,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc",
"ff"
]
}
},
"df9730": {
"cts": 1700981321672,
"contents": [
""
],
"mts": 1700981321672,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc",
"x"
]
}
},
"61fcf9": {
"cts": 1700981333741,
"contents": [
"333"
],
"mts": 1700981346010,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc"
]
}
},
"892da5": {
"cts": 1700981658673,
"contents": [
""
],
"mts": 1700981661631,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc",
"tt"
]
}
},
"45df23": {
"cts": 1700981684637,
"contents": [
"sss"
],
"mts": 1700981689473,
"gls": {
"##nb": [
"@test"
],
"domain": [
"@test",
"ccc"
]
}
}
}
82 changes: 43 additions & 39 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const jointMark = '->';

const intersection = (array1: string[], array2: string[]) => array1.filter((e) => array2.indexOf(e) !== -1);

// const issubset = (child: string[], father: string[]) => child.filter((e) => father.indexOf(e) !== -1).length === child.length;
const issubset = (child: string[], father: string[]) => child.filter((e) => father.includes(e)).length === child.length;

const chaji = (child: string[], father: string[]) => child.filter((e) => !father.includes(e));

interface IData {
dn: string[];
Expand Down Expand Up @@ -157,7 +159,7 @@ function readerCategory(fdom: Element, als: string[], filter: string[]) {
// labelsOfCategory = labelsOfCategory === '' ? '---' : labelsOfCategory;
let nameOfCategory = arrayLabels2CategoryName(als); //labelsOfCategory.join(', ');

const _notes = gs.notes.filter(n => intersection(n.als, als).length === als.length);
// const _notes = gs.notes.filter(n => intersection(n.als, als).length === als.length);


// nameOfCategory = nameOfCategory === '' ? '---' : nameOfCategory;
Expand Down Expand Up @@ -200,6 +202,7 @@ function readerCategory(fdom: Element, als: string[], filter: string[]) {
// d_category_body.id = `category-body-${nameOfCategory.replace(/\s/g, '')}`;
d_category_body.className = 'grid-category-body';

const _notes = gs.kkk[als.join("|||")].map(nid => gs.allNotes.get(nid)!)
for (const n of _notes) {
if (filter.length >= 1) {
let pin = false;
Expand Down Expand Up @@ -252,7 +255,7 @@ function readerCategories(filter: string[] = []) {
// }
// }
// }
const issubset = (child:string[], father:string[]) => child.filter((e) => father.indexOf(e) !== -1).length === child.length;
// const issubset = (child: string[], father: string[]) => child.filter((e) => father.indexOf(e) !== -1).length === child.length;
// const allcategory = Array.from(labelsOfNotes.values())
// for (const cname of labelsOfNotes.values()) {
// for (const ac of allcategory){
Expand All @@ -262,19 +265,41 @@ function readerCategories(filter: string[] = []) {
// }
// }
// }
for (const a1 of Array.from(labelsOfNotes.values())) {
let f = true
for (const a2 of Array.from(labelsOfNotes.values())) {
if (a1 !== a2) {
if (issubset(a1.split("|||"), a2.split("|||"))) {
f = false
gs.kkk = {}

const _notesOfLabels = new Map<string, Set<string>>()

for (const n of gs.notes) {
if (labelsOfNotes.has(n.als.join("|||"))) {
if (_notesOfLabels.has(n.als.sort().join("|||"))) {
_notesOfLabels.get(n.als.sort().join("|||"))?.add(n.id);
} else {
_notesOfLabels.set(n.als.sort().join("|||"), new Set([n.id]));
}
}
}

for (const [k, v] of _notesOfLabels.entries()) {
gs.kkk[k] = Array.from(v)
}

for (const a1 of Object.keys(gs.kkk).map(f => f.split("|||"))) {
for (const a2 of Object.keys(gs.kkk).map(f => f.split("|||"))) {
if (a1.join("") !== a2.join("")) {
if (issubset(a1, a2)) {
const chaj = chaji(gs.kkk[a1.join("|||")], gs.kkk[a2.join("|||")])
gs.kkk[a1.join("|||")] = chaj
}
}
}
if (f) {
readerCategory(localDom, a1.split('|||'), filter);
if (gs.kkk[a1.join("|||")].length == 0) {
delete gs.kkk[a1.join("|||")]
}
}

for (const cname of Object.keys(gs.kkk)) {
readerCategory(localDom, cname.split('|||'), filter);
}
}

function readerLabels() {
Expand Down Expand Up @@ -433,6 +458,9 @@ class GlobalState {
// init once
allGroupLabels = new Map<string, Set<string>>();
allNotesOfLabels = new Map<string, Set<string>>();
allNotes = new Map<string, DataNote>()

kkk: { [k: string]: string[] } = {}

// domain only
dals: string[] = []; // domain arraylabels
Expand Down Expand Up @@ -519,8 +547,10 @@ function processNotes() {
gs.allArrayLabels.clear();
gs.allGroupLabels.clear();
gs.allNotesOfLabels.clear();
gs.allNotes.clear()

for (const n of gs.notes) {
gs.allNotes.set(n.id, n)
n.als.forEach(n => gs.allArrayLabels.add(n));
for (const label of n.als) {
const [g] = label.split(jointMark);
Expand All @@ -531,40 +561,14 @@ function processNotes() {
}
}

if (gs.allNotesOfLabels.has(n.als.sort().join("|||"))) {
gs.allNotesOfLabels.get(n.als.sort().join("|||"))?.add(n.id);
} else {
gs.allNotesOfLabels.set(n.als.sort().join("|||"), new Set([n.id]));
}


}
console.log(gs.allNotesOfLabels)
const issubset = (child:string[], father:string[]) => child.filter((e) => father.indexOf(e) !== -1).length === child.length;

const chaji = (child:string[], father:string[]) => child.filter((e) => father.indexOf(e) == -1);
// const intersections = (array1:string[], array2:string[]) => array1.filter((e) => array2.indexOf(e) !== -1);

const kkk:{[k:string]:string[]} = {}
// child 哪些不在father中的
// const intersections = (array1:string[], array2:string[]) => array1.filter((e) => array2.indexOf(e) !== -1);

for (const [k,v ]of gs.allNotesOfLabels.entries()){
kkk[k]=Array.from(v)
}

for (const a1 of Object.keys(kkk).map(f => f.split("|||"))) {
for (const a2 of Object.keys(kkk).map(f => f.split("|||"))) {
if (a1.join("") !== a2.join("")) {
if (issubset(a1, a2)) {
const chaj = chaji(kkk[a1.join("|||")], kkk[a2.join("|||")])
kkk[a1.join("|||")] = chaj
}
}
}
if (kkk[a1.join("|||")].length == 0) {
delete kkk[a1.join("|||")]
}
}
console.log(kkk)
}

function sendWebReady() {
Expand Down

0 comments on commit 699cebe

Please sign in to comment.