@treeviz/gedcom-parser 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/index.js +202 -6
- package/dist/classes/indi.d.ts +7 -2
- package/dist/classes/indi.d.ts.map +1 -1
- package/dist/cli/index.js +466 -268
- package/dist/constants/index.js +201 -5
- package/dist/factories/index.js +201 -5
- package/dist/index.js +809 -386
- package/dist/interfaces/indi.d.ts +8 -3
- package/dist/interfaces/indi.d.ts.map +1 -1
- package/dist/kinship-translator/index.js +201 -5
- package/dist/utils/family-edit.d.ts +81 -2
- package/dist/utils/family-edit.d.ts.map +1 -1
- package/dist/utils/index.js +428 -7
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import type { Individuals } from "../classes/indis";
|
|
|
6
6
|
import type { List } from "../classes/list";
|
|
7
7
|
import type { ObjeType } from "../classes/obje";
|
|
8
8
|
import type { CommonNote } from "../classes/note";
|
|
9
|
-
import type { IndiKey, ObjeKey, RelationType, SnoteKey } from "../types/types";
|
|
9
|
+
import type { IndiKey, FamKey, ObjeKey, RelationType, SnoteKey } from "../types/types";
|
|
10
10
|
import type { AttachMultimediaOptions, CreateMultimediaInput } from "../utils/multimedia";
|
|
11
11
|
import type { AddFactInput, AddNonEventInput } from "../utils/fact-edit";
|
|
12
12
|
export type GeneratorKey = `${"2nd" | "3rd" | `${4 | 5 | 6 | 7 | 8 | 9}th`}`;
|
|
@@ -38,8 +38,13 @@ interface IIndi extends Common<string, IndiKey> {
|
|
|
38
38
|
isSiblingInLawOf: (indi?: IndiKey | IndiType) => IndiKey | boolean;
|
|
39
39
|
toFamilies: (list?: List) => Families;
|
|
40
40
|
addSpouse: (other: IndiType) => FamType | undefined;
|
|
41
|
-
addChild: (child: IndiType, pedigree?: string | RelationType
|
|
42
|
-
|
|
41
|
+
addChild: (child: IndiType, pedigree?: string | RelationType, options?: {
|
|
42
|
+
reuseParentFamilies?: boolean;
|
|
43
|
+
targetFamilyId?: FamKey;
|
|
44
|
+
}) => FamType | undefined;
|
|
45
|
+
addParent: (parent: IndiType, pedigree?: string | RelationType, options?: {
|
|
46
|
+
targetFamilyId?: FamKey;
|
|
47
|
+
}) => FamType | undefined;
|
|
43
48
|
attachMultimedia: (objeOrKey: ObjeType | ObjeKey, options?: AttachMultimediaOptions) => ObjeType | undefined;
|
|
44
49
|
detachMultimedia: (objeKey: ObjeKey) => void;
|
|
45
50
|
attachMediaFromUrl: (url: string, options?: CreateMultimediaInput & AttachMultimediaOptions) => ObjeType | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indi.d.ts","sourceRoot":"","sources":["../../src/interfaces/indi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"indi.d.ts","sourceRoot":"","sources":["../../src/interfaces/indi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAA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AAE,MAAM,WAAW,CAAC;IAEpC,YAAY,EAAE,MAAM,WAAW,CAAC;IAEhC,iBAAiB,EAAE,MAAM,WAAW,CAAC;IAErC,gBAAgB,EAAE,MAAM,WAAW,CAAC;IAEpC,gBAAgB,EAAE,MAAM,WAAW,CAAC;IAEpC,eAAe,EAAE,MAAM,WAAW,CAAC;CACnC;AAED,eAAe,KAAK,CAAC"}
|
|
@@ -3435,6 +3435,10 @@ var storeCache = {
|
|
|
3435
3435
|
}
|
|
3436
3436
|
}, 100)
|
|
3437
3437
|
};
|
|
3438
|
+
var resetRelativesCache = () => {
|
|
3439
|
+
caches.relativesOnDegreeCache = {};
|
|
3440
|
+
caches.relativesOnLevelCache = {};
|
|
3441
|
+
};
|
|
3438
3442
|
var relativesCache = (cacheKey) => (gedcom, key, subKey, value) => {
|
|
3439
3443
|
const gedcomId = getGedcomId(gedcom);
|
|
3440
3444
|
const fullKey = `${gedcomId}:${key}`;
|
|
@@ -3700,6 +3704,28 @@ var addNonEvent = (owner, input) => {
|
|
|
3700
3704
|
};
|
|
3701
3705
|
|
|
3702
3706
|
// src/utils/family-edit.ts
|
|
3707
|
+
var refTypeForTag = (tag) => {
|
|
3708
|
+
if (tag === "FAMS" || tag === "FAMC") return "FAM";
|
|
3709
|
+
return "INDI";
|
|
3710
|
+
};
|
|
3711
|
+
var normalizeSinglePointer = (owner, tag) => {
|
|
3712
|
+
const node = owner.get(tag);
|
|
3713
|
+
if (!node) return;
|
|
3714
|
+
if (node instanceof List && node.length === 1) {
|
|
3715
|
+
const only = node.index(0);
|
|
3716
|
+
if (only) {
|
|
3717
|
+
owner.set(tag, only);
|
|
3718
|
+
return;
|
|
3719
|
+
}
|
|
3720
|
+
const raw = node.values()[0];
|
|
3721
|
+
if (typeof raw === "string") {
|
|
3722
|
+
const gedcom = owner.getGedcom?.();
|
|
3723
|
+
if (gedcom) {
|
|
3724
|
+
owner.set(tag, makePointer(gedcom, owner, raw, refTypeForTag(tag)));
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
};
|
|
3703
3729
|
var PEDIGREE_VALUES = [
|
|
3704
3730
|
"birth" /* BIRTH */,
|
|
3705
3731
|
"adopted" /* ADOPTED */,
|
|
@@ -3807,6 +3833,9 @@ var attachSpouseToFamily = (fam, indi) => {
|
|
|
3807
3833
|
fam.set(tag, makePointer(gedcom, fam, indi.id, "INDI"));
|
|
3808
3834
|
}
|
|
3809
3835
|
indi.assign("FAMS", makePointer(gedcom, indi, fam.id, "FAM"), true);
|
|
3836
|
+
normalizeSinglePointer(indi, "FAMS");
|
|
3837
|
+
normalizeSinglePointer(fam, spouseTagFor(indi, fam));
|
|
3838
|
+
resetRelativesCache();
|
|
3810
3839
|
return true;
|
|
3811
3840
|
};
|
|
3812
3841
|
var attachChildToFamily = (fam, child, pedigree, parent) => {
|
|
@@ -3822,14 +3851,122 @@ var attachChildToFamily = (fam, child, pedigree, parent) => {
|
|
|
3822
3851
|
child.assign("FAMC", makePointer(gedcom, child, fam.id, "FAM"), true);
|
|
3823
3852
|
}
|
|
3824
3853
|
setChildPedigree(fam, child, pedigree, parent);
|
|
3854
|
+
normalizeSinglePointer(child, "FAMC");
|
|
3855
|
+
normalizeSinglePointer(fam, "CHIL");
|
|
3856
|
+
resetRelativesCache();
|
|
3825
3857
|
return true;
|
|
3826
3858
|
};
|
|
3827
|
-
var
|
|
3859
|
+
var removePointerByValue = (owner, tag, targetId) => {
|
|
3860
|
+
const node = owner.get(tag);
|
|
3861
|
+
if (!node) {
|
|
3862
|
+
return false;
|
|
3863
|
+
}
|
|
3864
|
+
if (node instanceof List) {
|
|
3865
|
+
const keysToRemove = [];
|
|
3866
|
+
node.entries().forEach(([key, item]) => {
|
|
3867
|
+
if (item?.toValue?.() === targetId || item?.id === targetId || String(key) === targetId) {
|
|
3868
|
+
keysToRemove.push(key);
|
|
3869
|
+
}
|
|
3870
|
+
});
|
|
3871
|
+
keysToRemove.forEach((key) => {
|
|
3872
|
+
node.removeItem(key);
|
|
3873
|
+
});
|
|
3874
|
+
if (node.length === 0) {
|
|
3875
|
+
owner.remove(tag);
|
|
3876
|
+
}
|
|
3877
|
+
return keysToRemove.length > 0;
|
|
3878
|
+
}
|
|
3879
|
+
if (node.toValue?.() === targetId) {
|
|
3880
|
+
owner.remove(tag);
|
|
3881
|
+
return true;
|
|
3882
|
+
}
|
|
3883
|
+
const asList = node.toList?.();
|
|
3884
|
+
if (asList && asList.length > 0) {
|
|
3885
|
+
const keysToRemove = [];
|
|
3886
|
+
asList.entries().forEach(([key, item]) => {
|
|
3887
|
+
if (item?.toValue?.() === targetId || item?.id === targetId) {
|
|
3888
|
+
keysToRemove.push(key);
|
|
3889
|
+
}
|
|
3890
|
+
});
|
|
3891
|
+
if (keysToRemove.length === asList.length) {
|
|
3892
|
+
owner.remove(tag);
|
|
3893
|
+
return true;
|
|
3894
|
+
}
|
|
3895
|
+
if (keysToRemove.length > 0) {
|
|
3896
|
+
const remaining = asList.values().filter((item) => item?.toValue?.() !== targetId);
|
|
3897
|
+
if (remaining.length === 1 && remaining[0]) {
|
|
3898
|
+
owner.set(tag, remaining[0]);
|
|
3899
|
+
} else {
|
|
3900
|
+
owner.set(tag, new List(remaining));
|
|
3901
|
+
}
|
|
3902
|
+
return true;
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
return false;
|
|
3906
|
+
};
|
|
3907
|
+
var familyMemberCount = (fam) => {
|
|
3908
|
+
let count = 0;
|
|
3909
|
+
if (firstPointerId(fam.get("HUSB"))) {
|
|
3910
|
+
count += 1;
|
|
3911
|
+
}
|
|
3912
|
+
if (firstPointerId(fam.get("WIFE"))) {
|
|
3913
|
+
count += 1;
|
|
3914
|
+
}
|
|
3915
|
+
count += pointerIds(fam.get("CHIL")).length;
|
|
3916
|
+
return count;
|
|
3917
|
+
};
|
|
3918
|
+
var isDegenerateFamily = (fam) => familyMemberCount(fam) <= 1;
|
|
3919
|
+
var pruneEmptyFamilies = (gedcom) => {
|
|
3920
|
+
const emptyIds = [];
|
|
3921
|
+
gedcom.fams()?.forEach((fam, id) => {
|
|
3922
|
+
if (fam && isDegenerateFamily(fam) && id) {
|
|
3923
|
+
emptyIds.push(id);
|
|
3924
|
+
}
|
|
3925
|
+
});
|
|
3926
|
+
if (emptyIds.length === 0) {
|
|
3927
|
+
return [];
|
|
3928
|
+
}
|
|
3929
|
+
gedcom.indis()?.forEach((indi) => {
|
|
3930
|
+
if (!indi) {
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3933
|
+
emptyIds.forEach((famId) => {
|
|
3934
|
+
removePointerByValue(indi, "FAMS", famId);
|
|
3935
|
+
removePointerByValue(indi, "FAMC", famId);
|
|
3936
|
+
});
|
|
3937
|
+
});
|
|
3938
|
+
emptyIds.forEach((famId) => {
|
|
3939
|
+
gedcom.fams()?.removeItem(famId);
|
|
3940
|
+
});
|
|
3941
|
+
return emptyIds;
|
|
3942
|
+
};
|
|
3943
|
+
var findSharedSpouseFamily = (parent, coParentId) => {
|
|
3944
|
+
let found;
|
|
3945
|
+
parent.getFamilies("FAMS")?.forEach((fam) => {
|
|
3946
|
+
if (!found && fam && familyHasParent(fam, coParentId)) {
|
|
3947
|
+
found = fam;
|
|
3948
|
+
}
|
|
3949
|
+
});
|
|
3950
|
+
return found;
|
|
3951
|
+
};
|
|
3952
|
+
var findReusableParentChildFamily = (parent, child, options) => {
|
|
3828
3953
|
if (!parent.id || !child.id) {
|
|
3829
3954
|
return void 0;
|
|
3830
3955
|
}
|
|
3956
|
+
const reuseParentFamilies = options?.reuseParentFamilies !== false;
|
|
3957
|
+
const gedcom = parent.getGedcom() ?? child.getGedcom();
|
|
3831
3958
|
let reusableFamc;
|
|
3959
|
+
let coupleFam;
|
|
3832
3960
|
let already = false;
|
|
3961
|
+
const noteCoupleWith = (coParentId) => {
|
|
3962
|
+
if (!coParentId || coParentId === parent.id || coupleFam || !parent.id) {
|
|
3963
|
+
return;
|
|
3964
|
+
}
|
|
3965
|
+
const shared = findSharedSpouseFamily(parent, coParentId);
|
|
3966
|
+
if (shared) {
|
|
3967
|
+
coupleFam = shared;
|
|
3968
|
+
}
|
|
3969
|
+
};
|
|
3833
3970
|
child.getFamilies("FAMC")?.forEach((fam) => {
|
|
3834
3971
|
if (!fam) {
|
|
3835
3972
|
return;
|
|
@@ -3838,6 +3975,8 @@ var findReusableParentChildFamily = (parent, child) => {
|
|
|
3838
3975
|
already = true;
|
|
3839
3976
|
return;
|
|
3840
3977
|
}
|
|
3978
|
+
pointerIds(fam.get("HUSB")).forEach(noteCoupleWith);
|
|
3979
|
+
pointerIds(fam.get("WIFE")).forEach(noteCoupleWith);
|
|
3841
3980
|
if (!reusableFamc && canAttachAsSpouse(fam, parent)) {
|
|
3842
3981
|
reusableFamc = fam;
|
|
3843
3982
|
}
|
|
@@ -3845,9 +3984,21 @@ var findReusableParentChildFamily = (parent, child) => {
|
|
|
3845
3984
|
if (already) {
|
|
3846
3985
|
return "already";
|
|
3847
3986
|
}
|
|
3987
|
+
if (coupleFam) {
|
|
3988
|
+
return coupleFam;
|
|
3989
|
+
}
|
|
3848
3990
|
if (reusableFamc) {
|
|
3849
3991
|
return reusableFamc;
|
|
3850
3992
|
}
|
|
3993
|
+
if (options?.targetFamilyId && gedcom) {
|
|
3994
|
+
const target = gedcom.fam(options.targetFamilyId);
|
|
3995
|
+
if (target && (familyHasParent(target, parent.id) || canAttachAsSpouse(target, parent))) {
|
|
3996
|
+
return target;
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
if (!reuseParentFamilies) {
|
|
4000
|
+
return void 0;
|
|
4001
|
+
}
|
|
3851
4002
|
const parentFams = [];
|
|
3852
4003
|
parent.getFamilies("FAMS")?.forEach((fam) => {
|
|
3853
4004
|
if (fam) {
|
|
@@ -3859,6 +4010,41 @@ var findReusableParentChildFamily = (parent, child) => {
|
|
|
3859
4010
|
}
|
|
3860
4011
|
return void 0;
|
|
3861
4012
|
};
|
|
4013
|
+
var consolidateChildIntoFamily = (child, keep) => {
|
|
4014
|
+
if (!child.id || !keep.id) {
|
|
4015
|
+
return [];
|
|
4016
|
+
}
|
|
4017
|
+
const keepParentIds = /* @__PURE__ */ new Set([
|
|
4018
|
+
...pointerIds(keep.get("HUSB")),
|
|
4019
|
+
...pointerIds(keep.get("WIFE"))
|
|
4020
|
+
]);
|
|
4021
|
+
const removed = [];
|
|
4022
|
+
child.getFamilies("FAMC")?.forEach((fam) => {
|
|
4023
|
+
if (!fam?.id || fam.id === keep.id) {
|
|
4024
|
+
return;
|
|
4025
|
+
}
|
|
4026
|
+
const famParentIds = [
|
|
4027
|
+
...pointerIds(fam.get("HUSB")),
|
|
4028
|
+
...pointerIds(fam.get("WIFE"))
|
|
4029
|
+
];
|
|
4030
|
+
if (famParentIds.length === 0 || !famParentIds.every((id) => keepParentIds.has(id))) {
|
|
4031
|
+
return;
|
|
4032
|
+
}
|
|
4033
|
+
removePointerByValue(fam, "CHIL", child.id);
|
|
4034
|
+
normalizeSinglePointer(fam, "CHIL");
|
|
4035
|
+
removePointerByValue(child, "FAMC", fam.id);
|
|
4036
|
+
normalizeSinglePointer(child, "FAMC");
|
|
4037
|
+
removed.push(fam.id);
|
|
4038
|
+
});
|
|
4039
|
+
const gedcom = child.getGedcom() ?? keep.getGedcom();
|
|
4040
|
+
if (gedcom && removed.length > 0) {
|
|
4041
|
+
pruneEmptyFamilies(gedcom);
|
|
4042
|
+
}
|
|
4043
|
+
if (removed.length > 0) {
|
|
4044
|
+
resetRelativesCache();
|
|
4045
|
+
}
|
|
4046
|
+
return removed;
|
|
4047
|
+
};
|
|
3862
4048
|
|
|
3863
4049
|
// src/utils/get-places.ts
|
|
3864
4050
|
var getPlaces = (common, type = ["ALL" /* All */], maxLevel = 1, level = 0, mainKey) => {
|
|
@@ -5882,13 +6068,17 @@ var Indi = class extends Common {
|
|
|
5882
6068
|
}
|
|
5883
6069
|
return fam;
|
|
5884
6070
|
}
|
|
5885
|
-
addChild(child, pedigree) {
|
|
6071
|
+
addChild(child, pedigree, options) {
|
|
5886
6072
|
if (!this.id || !child?.id || this.id === child.id || !this._gedcom) {
|
|
5887
6073
|
return void 0;
|
|
5888
6074
|
}
|
|
5889
6075
|
const existing = findReusableParentChildFamily(
|
|
5890
6076
|
this,
|
|
5891
|
-
child
|
|
6077
|
+
child,
|
|
6078
|
+
{
|
|
6079
|
+
reuseParentFamilies: options?.reuseParentFamilies,
|
|
6080
|
+
targetFamilyId: options?.targetFamilyId
|
|
6081
|
+
}
|
|
5892
6082
|
);
|
|
5893
6083
|
if (existing === "already") {
|
|
5894
6084
|
const fam2 = child.getFamilies("FAMC")?.find(
|
|
@@ -5911,10 +6101,16 @@ var Indi = class extends Common {
|
|
|
5911
6101
|
if (!fam.addChild(child, pedigree, this)) {
|
|
5912
6102
|
return void 0;
|
|
5913
6103
|
}
|
|
6104
|
+
if (existing) {
|
|
6105
|
+
consolidateChildIntoFamily(child, fam);
|
|
6106
|
+
}
|
|
5914
6107
|
return fam;
|
|
5915
6108
|
}
|
|
5916
|
-
addParent(parent, pedigree) {
|
|
5917
|
-
return parent.addChild(this, pedigree
|
|
6109
|
+
addParent(parent, pedigree, options) {
|
|
6110
|
+
return parent.addChild(this, pedigree, {
|
|
6111
|
+
reuseParentFamilies: false,
|
|
6112
|
+
targetFamilyId: options?.targetFamilyId
|
|
6113
|
+
});
|
|
5918
6114
|
}
|
|
5919
6115
|
/**
|
|
5920
6116
|
* Link an existing top-level OBJE record to this individual (`1 OBJE @On@`).
|
|
@@ -4,7 +4,7 @@ import type { GedComType } from "../classes/gedcom";
|
|
|
4
4
|
import type { IndiType } from "../classes/indi";
|
|
5
5
|
import { List } from "../classes/list";
|
|
6
6
|
import { RelationType } from "../types/types";
|
|
7
|
-
import type { IndiKey } from "../types/types";
|
|
7
|
+
import type { FamKey, IndiKey, MultiTag } from "../types/types";
|
|
8
8
|
export declare const PEDIGREE_VALUES: readonly [RelationType.BIRTH, RelationType.ADOPTED, RelationType.FOSTER, RelationType.STEP, RelationType.SEALING];
|
|
9
9
|
export type PedigreeValue = (typeof PEDIGREE_VALUES)[number];
|
|
10
10
|
export declare const toGedcomPedigree: (value?: string | RelationType) => PedigreeValue;
|
|
@@ -19,5 +19,84 @@ export declare const canAttachAsSpouse: (fam: FamType, indi: IndiType) => boolea
|
|
|
19
19
|
export declare const setChildPedigree: (fam: FamType, child: IndiType, pedigree?: string | RelationType, parent?: IndiType) => void;
|
|
20
20
|
export declare const attachSpouseToFamily: (fam: FamType, indi: IndiType) => boolean;
|
|
21
21
|
export declare const attachChildToFamily: (fam: FamType, child: IndiType, pedigree?: string | RelationType, parent?: IndiType) => boolean;
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Remove a pointer (`FAMC` / `FAMS` / `CHIL` / …) whose value equals `targetId`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const removePointerByValue: (owner: Common, tag: MultiTag, targetId: string) => boolean;
|
|
26
|
+
/** True when the FAM has fewer than two people (empty or lone individual). */
|
|
27
|
+
export declare const isDegenerateFamily: (fam: FamType) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Drop families with fewer than two members (not a real family unit);
|
|
30
|
+
* clear dangling FAMS/FAMC. Returns removed FAM ids.
|
|
31
|
+
*/
|
|
32
|
+
export declare const pruneEmptyFamilies: (gedcom: GedComType) => FamKey[];
|
|
33
|
+
/** Degenerate FAMs linked to this person via FAMS or FAMC. */
|
|
34
|
+
export declare const findDegenerateFamiliesForIndi: (indi: IndiType) => FamType[];
|
|
35
|
+
/**
|
|
36
|
+
* Stable key for a two-parent couple (order-independent). Undefined if the FAM
|
|
37
|
+
* does not have both HUSB and WIFE.
|
|
38
|
+
*/
|
|
39
|
+
export declare const coupleKeyForFam: (fam: FamType) => string | undefined;
|
|
40
|
+
export type DuplicateCoupleGroup = {
|
|
41
|
+
key: string;
|
|
42
|
+
families: FamType[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* FAMs that share the same HUSB+WIFE pair and are relevant to this person
|
|
46
|
+
* (linked via FAMS/FAMC, or elsewhere in the file with the same couple key).
|
|
47
|
+
*/
|
|
48
|
+
export declare const findDuplicateCoupleFamiliesForIndi: (indi: IndiType) => DuplicateCoupleGroup[];
|
|
49
|
+
/**
|
|
50
|
+
* Merge FAMs that represent the same couple into one: keep the FAM with the
|
|
51
|
+
* most children (tie-break by id), move CHILs, drop extras and clear pointers.
|
|
52
|
+
*/
|
|
53
|
+
export declare const mergeDuplicateCoupleFamilies: (gedcom: GedComType, families: FamType[]) => FamType | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Remove specific degenerate families (and clear INDI pointers). Returns
|
|
56
|
+
* how many were removed.
|
|
57
|
+
*/
|
|
58
|
+
export declare const pruneFamiliesByIds: (gedcom: GedComType, famIds: FamKey[]) => number;
|
|
59
|
+
export type UnlinkRelativeKind = "parent" | "spouse" | "child" | "sibling";
|
|
60
|
+
/**
|
|
61
|
+
* Unlink `relative` from `anchor` for the given role. Does not delete either
|
|
62
|
+
* INDI record — only family pointers. Creates no new families.
|
|
63
|
+
*/
|
|
64
|
+
export declare const unlinkRelative: (anchor: IndiType, relative: IndiType, kind: UnlinkRelativeKind) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Permanently remove an individual from the GEDCOM and clean family links.
|
|
67
|
+
*/
|
|
68
|
+
export declare const deleteIndividual: (gedcom: GedComType, indiId: IndiKey) => boolean;
|
|
69
|
+
export type FindReusableParentChildFamilyOptions = {
|
|
70
|
+
/**
|
|
71
|
+
* When true (default), a parent with exactly one FAMS may receive the
|
|
72
|
+
* child there (normal "add child to my marriage").
|
|
73
|
+
* When false (add-parent flows), only the child's existing FAMC families
|
|
74
|
+
* are considered — never an unrelated spouse family of the new parent
|
|
75
|
+
* unless `targetFamilyId` is set.
|
|
76
|
+
*/
|
|
77
|
+
reuseParentFamilies?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Explicit FAM to use (e.g. user picked a spouse family of the new
|
|
80
|
+
* parent). Takes priority after "already linked" / fillable FAMC checks.
|
|
81
|
+
*/
|
|
82
|
+
targetFamilyId?: FamKey;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Prefer an existing family for a parent↔child link.
|
|
86
|
+
* - Always reuse a child's FAMC if the parent is already there, or can join
|
|
87
|
+
* as the missing spouse.
|
|
88
|
+
* - Prefer an existing FAMS the parent already shares with a co-parent of the
|
|
89
|
+
* child (same couple must not get a second FAM).
|
|
90
|
+
* - If `targetFamilyId` is set, use that FAM when the parent can attach.
|
|
91
|
+
* - Optionally reuse the parent's sole FAMS (add-child). Skip that for
|
|
92
|
+
* add-parent so an extra parent gets a new family when they are not already
|
|
93
|
+
* in the child's family.
|
|
94
|
+
*/
|
|
95
|
+
export declare const findReusableParentChildFamily: (parent: IndiType, child: IndiType, options?: FindReusableParentChildFamilyOptions) => FamType | "already" | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* After attaching a child to `keep`, drop redundant FAMC links whose parents
|
|
98
|
+
* are already covered by `keep` (e.g. father-only FAMC once mother joined the
|
|
99
|
+
* couple family). Prunes families left with ≤1 member.
|
|
100
|
+
*/
|
|
101
|
+
export declare const consolidateChildIntoFamily: (child: IndiType, keep: FamType) => FamKey[];
|
|
23
102
|
//# sourceMappingURL=family-edit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"family-edit.d.ts","sourceRoot":"","sources":["../../src/utils/family-edit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C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