@beinformed/ui 1.61.1 → 1.62.1
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/CHANGELOG.md +16 -0
- package/esm/constants/Settings.js +2 -1
- package/esm/constants/Settings.js.flow +2 -0
- package/esm/constants/Settings.js.map +1 -1
- package/esm/models/attributes/__tests__/AttributeContent.spec.js.flow +1 -1
- package/esm/models/concepts/ConceptIndexModel.js +1 -1
- package/esm/models/concepts/ConceptIndexModel.js.flow +3 -1
- package/esm/models/concepts/ConceptIndexModel.js.map +1 -1
- package/esm/models/concepts/ConceptLinkModel.d.ts +15 -0
- package/esm/models/concepts/ConceptLinkModel.js +14 -0
- package/esm/models/concepts/ConceptLinkModel.js.flow +21 -0
- package/esm/models/concepts/ConceptLinkModel.js.map +1 -1
- package/esm/models/concepts/SourceReferenceModel.d.ts +9 -0
- package/esm/models/concepts/SourceReferenceModel.js +16 -2
- package/esm/models/concepts/SourceReferenceModel.js.flow +22 -10
- package/esm/models/concepts/SourceReferenceModel.js.map +1 -1
- package/esm/models/concepts/__mock__/related_concepts.js.flow +12 -0
- package/esm/models/concepts/__tests__/RelatedConcepts.spec.js.flow +60 -0
- package/esm/models/concepts/__tests__/SourceReferenceModel.spec.js.flow +99 -0
- package/esm/models/content/ContentLinkModel.d.ts +8 -0
- package/esm/models/content/ContentLinkModel.js +31 -1
- package/esm/models/content/ContentLinkModel.js.flow +35 -1
- package/esm/models/content/ContentLinkModel.js.map +1 -1
- package/esm/models/content/ContentTOCModel.d.ts +3 -0
- package/esm/models/content/ContentTOCModel.js +6 -0
- package/esm/models/content/ContentTOCModel.js.flow +6 -0
- package/esm/models/content/ContentTOCModel.js.map +1 -1
- package/esm/models/content/__tests__/ContentIndexModel.spec.js.flow +3 -0
- package/esm/models/content/__tests__/ContentModel.spec.js.flow +5 -5
- package/esm/models/content/__tests__/Formalsource.spec.js.flow +4 -0
- package/esm/models/types.d.ts +6 -0
- package/esm/models/types.js.flow +7 -0
- package/esm/models/types.js.map +1 -1
- package/esm/utils/helpers/__tests__/createHash.spec.js.flow +5 -5
- package/esm/utils/helpers/createHash.d.ts +2 -1
- package/esm/utils/helpers/createHash.js +10 -9
- package/esm/utils/helpers/createHash.js.flow +10 -10
- package/esm/utils/helpers/createHash.js.map +1 -1
- package/lib/constants/Settings.js +2 -1
- package/lib/constants/Settings.js.map +1 -1
- package/lib/models/concepts/ConceptIndexModel.js +1 -1
- package/lib/models/concepts/ConceptIndexModel.js.map +1 -1
- package/lib/models/concepts/ConceptLinkModel.d.ts +15 -0
- package/lib/models/concepts/ConceptLinkModel.js +14 -0
- package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
- package/lib/models/concepts/SourceReferenceModel.d.ts +9 -0
- package/lib/models/concepts/SourceReferenceModel.js +16 -2
- package/lib/models/concepts/SourceReferenceModel.js.map +1 -1
- package/lib/models/content/ContentLinkModel.d.ts +8 -0
- package/lib/models/content/ContentLinkModel.js +31 -1
- package/lib/models/content/ContentLinkModel.js.map +1 -1
- package/lib/models/content/ContentTOCModel.d.ts +3 -0
- package/lib/models/content/ContentTOCModel.js +6 -0
- package/lib/models/content/ContentTOCModel.js.map +1 -1
- package/lib/models/types.d.ts +6 -0
- package/lib/models/types.js.map +1 -1
- package/lib/utils/helpers/createHash.d.ts +2 -1
- package/lib/utils/helpers/createHash.js +11 -9
- package/lib/utils/helpers/createHash.js.map +1 -1
- package/package.json +3 -1
- package/src/constants/Settings.js +2 -0
- package/src/models/attributes/__tests__/AttributeContent.spec.js +1 -1
- package/src/models/concepts/ConceptIndexModel.js +3 -1
- package/src/models/concepts/ConceptLinkModel.js +21 -0
- package/src/models/concepts/SourceReferenceModel.js +22 -10
- package/src/models/concepts/__mock__/related_concepts.js +12 -0
- package/src/models/concepts/__mock__/related_concepts_contributions.json +41 -0
- package/src/models/concepts/__mock__/related_concepts_data.json +2292 -0
- package/src/models/concepts/__tests__/RelatedConcepts.spec.js +60 -0
- package/src/models/concepts/__tests__/SourceReferenceModel.spec.js +99 -0
- package/src/models/content/ContentLinkModel.js +35 -1
- package/src/models/content/ContentTOCModel.js +6 -0
- package/src/models/content/__tests__/ContentIndexModel.spec.js +3 -0
- package/src/models/content/__tests__/ContentModel.spec.js +5 -5
- package/src/models/content/__tests__/Formalsource.spec.js +4 -0
- package/src/models/content/__tests__/content-index.json +1 -0
- package/src/models/content/__tests__/formalsource-complete.json +1 -0
- package/src/models/types.js +7 -0
- package/src/utils/helpers/__tests__/createHash.spec.js +5 -5
- package/src/utils/helpers/createHash.js +10 -10
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { relatedConcepts } from "../__mock__/related_concepts";
|
|
2
|
+
import ConceptIndexModel from "../ConceptIndexModel";
|
|
3
|
+
|
|
4
|
+
describe("Related concepts", () => {
|
|
5
|
+
it("Should be able to create a relatedConceptsModel from RelatedConcepts json", () => {
|
|
6
|
+
expect(relatedConcepts).toBeInstanceOf(ConceptIndexModel);
|
|
7
|
+
|
|
8
|
+
expect(relatedConcepts.label).toBe("Related concepts of content");
|
|
9
|
+
|
|
10
|
+
expect(relatedConcepts.label).toBe("Related concepts of content");
|
|
11
|
+
expect(relatedConcepts.selfhref.toString()).toBe(
|
|
12
|
+
"/content/bundle-com.beinformed.source.Highlevelrequirements/ResearchGrant/High%20level%20requirements.formalsource/relatedConcepts?entryDate=2025-06-03",
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(relatedConcepts.entryDate).toBe("2025-06-03");
|
|
16
|
+
expect(relatedConcepts.modelCategoryFilter.label).toBe("Model category");
|
|
17
|
+
|
|
18
|
+
expect(relatedConcepts.items.size).toBe(116);
|
|
19
|
+
|
|
20
|
+
const firstItem = relatedConcepts.items.first;
|
|
21
|
+
expect(firstItem.key).toBe(
|
|
22
|
+
"SystemMustSendAutomatedNotificationsForStatusChanges",
|
|
23
|
+
);
|
|
24
|
+
expect(firstItem.label).toBe(
|
|
25
|
+
"System must send automated notifications for status changes.",
|
|
26
|
+
);
|
|
27
|
+
expect(firstItem.modelCategory).toBe("Requirements");
|
|
28
|
+
expect(firstItem.selfhref.toString()).toBe(
|
|
29
|
+
"/concepts/bundle-com.beinformed.frames.ResearchGrantRequirements/frames.beimodel.json/SystemMustSendAutomatedNotificationsForStatusChanges?entryDate=2025-06-03",
|
|
30
|
+
);
|
|
31
|
+
expect(firstItem.conceptTypeLink.href.toString()).toBe(
|
|
32
|
+
"/concepttypes/bundle-com.beinformed.research.grant.metamodels/High%20level%20requirements.bixml/ArchitecturalSignificantRequirement",
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(firstItem.fragment.sectionId).toBe(
|
|
36
|
+
"AutomatedNotifications_Requirement",
|
|
37
|
+
);
|
|
38
|
+
expect(firstItem.fragment.text).toBeUndefined();
|
|
39
|
+
|
|
40
|
+
const secondItem = relatedConcepts.items.get(1);
|
|
41
|
+
|
|
42
|
+
expect(secondItem.key).toBe(
|
|
43
|
+
"n74UsersHaveMaximumFlexibilityWithinPolicyConstraints",
|
|
44
|
+
);
|
|
45
|
+
expect(secondItem.label).toBe(
|
|
46
|
+
"Users have maximum flexibility within policy constraints",
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(secondItem.modelCategory).toBe("Requirements");
|
|
50
|
+
|
|
51
|
+
expect(secondItem.fragment.sectionId).toBe(
|
|
52
|
+
"MaximumFlexibilityWithinPolicyConstraints",
|
|
53
|
+
);
|
|
54
|
+
expect(secondItem.fragment.text).toBe(
|
|
55
|
+
"<p>Users have maximum flexibility within policy constraints</p>",
|
|
56
|
+
);
|
|
57
|
+
expect(secondItem.fragment.startOffset).toBe(0);
|
|
58
|
+
expect(secondItem.fragment.endOffset).toBe(56);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import SourceReferenceModel from "../SourceReferenceModel";
|
|
2
|
+
import { setSetting } from "../../../constants/Settings";
|
|
3
|
+
|
|
4
|
+
const data = {
|
|
5
|
+
label: "4. Purpose of Grant",
|
|
6
|
+
type: "Reference",
|
|
7
|
+
sourceLabel: "Grant Funding Agreement - Terms and Conditions",
|
|
8
|
+
sourceAbbreviation: "GFA-TC-01",
|
|
9
|
+
_links: {
|
|
10
|
+
self: {
|
|
11
|
+
href: "/content/bundle-com.beinformed.source.GrantFundingAgreementTermsandConditions/Grant%20Funding%20Agreement.formalsource/Chapter4",
|
|
12
|
+
},
|
|
13
|
+
content: {
|
|
14
|
+
href: "/content/bundle-com.beinformed.source.GrantFundingAgreementTermsandConditions/Grant%20Funding%20Agreement.formalsource",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
sectionFragment: {
|
|
18
|
+
sectionId: "Chapter4",
|
|
19
|
+
text: "Research Grant",
|
|
20
|
+
startOffset: 32,
|
|
21
|
+
endOffset: 18,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
2
24
|
|
|
3
25
|
describe("sourceReferenceModel", () => {
|
|
4
26
|
it("should be able to create an empty SourceReferenceModel object", () => {
|
|
@@ -6,4 +28,81 @@ describe("sourceReferenceModel", () => {
|
|
|
6
28
|
|
|
7
29
|
expect(sourceReference).toBeInstanceOf(SourceReferenceModel);
|
|
8
30
|
});
|
|
31
|
+
|
|
32
|
+
it("can handle source reference data", () => {
|
|
33
|
+
const sourceReference = new SourceReferenceModel(data);
|
|
34
|
+
|
|
35
|
+
expect(sourceReference.label).toBe("4. Purpose of Grant");
|
|
36
|
+
expect(sourceReference.sourceLabel).toBe(
|
|
37
|
+
"Grant Funding Agreement - Terms and Conditions",
|
|
38
|
+
);
|
|
39
|
+
expect(sourceReference.type).toBe("Reference");
|
|
40
|
+
expect(sourceReference.sourceAbbreviation).toBe("GFA-TC-01");
|
|
41
|
+
expect(sourceReference.referenceHash).toBe(10443215482258);
|
|
42
|
+
expect(sourceReference.fragment.text).toBe("Research Grant");
|
|
43
|
+
expect(sourceReference.fragment.startOffset).toBe(32);
|
|
44
|
+
expect(sourceReference.fragment.endOffset).toBe(18);
|
|
45
|
+
|
|
46
|
+
expect(sourceReference.link.label).toBe("4. Purpose of Grant");
|
|
47
|
+
expect(sourceReference.link.sourceLabel).toBe(
|
|
48
|
+
"Grant Funding Agreement - Terms and Conditions",
|
|
49
|
+
);
|
|
50
|
+
expect(sourceReference.link.abbreviation).toBe("GFA-TC-01");
|
|
51
|
+
expect(sourceReference.link.selfhref.path).toBe(
|
|
52
|
+
"/content/bundle-com.beinformed.source.GrantFundingAgreementTermsandConditions/Grant%20Funding%20Agreement.formalsource/Chapter4",
|
|
53
|
+
);
|
|
54
|
+
expect(sourceReference.link.selfhref.toLocation()).toEqual({
|
|
55
|
+
hash: "",
|
|
56
|
+
pathname:
|
|
57
|
+
"/content/bundle-com.beinformed.source.GrantFundingAgreementTermsandConditions/Grant%20Funding%20Agreement.formalsource/Chapter4",
|
|
58
|
+
search: "",
|
|
59
|
+
state: {
|
|
60
|
+
contextPath: "/BeInformed",
|
|
61
|
+
fragment: {
|
|
62
|
+
endOffset: 18,
|
|
63
|
+
sectionId: "Chapter4",
|
|
64
|
+
startOffset: 32,
|
|
65
|
+
text: "Research Grant",
|
|
66
|
+
},
|
|
67
|
+
origin: "",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(sourceReference.link.fragment.text).toBe("Research Grant");
|
|
72
|
+
expect(sourceReference.link.fragment.startOffset).toBe(32);
|
|
73
|
+
expect(sourceReference.link.fragment.endOffset).toBe(18);
|
|
74
|
+
|
|
75
|
+
expect(sourceReference.link.selfhref.state.fragment.text).toBe(
|
|
76
|
+
"Research Grant",
|
|
77
|
+
);
|
|
78
|
+
expect(sourceReference.link.selfhref.state.fragment.startOffset).toBe(32);
|
|
79
|
+
expect(sourceReference.link.selfhref.state.fragment.endOffset).toBe(18);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("can handle source reference data complete source", () => {
|
|
83
|
+
setSetting("COMPLETE_SOURCE", true);
|
|
84
|
+
const sourceReference = new SourceReferenceModel(data);
|
|
85
|
+
|
|
86
|
+
expect(sourceReference.link.selfhref.path).toBe(
|
|
87
|
+
"/content/bundle-com.beinformed.source.GrantFundingAgreementTermsandConditions/Grant%20Funding%20Agreement.formalsource",
|
|
88
|
+
);
|
|
89
|
+
expect(sourceReference.link.selfhref.toLocation()).toEqual({
|
|
90
|
+
hash: "#Chapter4",
|
|
91
|
+
pathname:
|
|
92
|
+
"/content/bundle-com.beinformed.source.GrantFundingAgreementTermsandConditions/Grant%20Funding%20Agreement.formalsource",
|
|
93
|
+
search: "?complete=true",
|
|
94
|
+
state: {
|
|
95
|
+
contextPath: "/BeInformed",
|
|
96
|
+
fragment: {
|
|
97
|
+
endOffset: 18,
|
|
98
|
+
sectionId: "Chapter4",
|
|
99
|
+
startOffset: 32,
|
|
100
|
+
text: "Research Grant",
|
|
101
|
+
},
|
|
102
|
+
origin: "",
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
setSetting("COMPLETE_SOURCE", false);
|
|
107
|
+
});
|
|
9
108
|
});
|
|
@@ -4,6 +4,7 @@ import Href from "../href/Href";
|
|
|
4
4
|
import LinkModel from "../links/LinkModel";
|
|
5
5
|
import ContentTypeModel from "./ContentTypeModel";
|
|
6
6
|
import { TIMEVERSION_FILTER_NAME } from "../../constants/Constants";
|
|
7
|
+
import { getSetting } from "../../constants/Settings";
|
|
7
8
|
|
|
8
9
|
import LinkCollection from "../links/LinkCollection";
|
|
9
10
|
|
|
@@ -11,6 +12,7 @@ import type {
|
|
|
11
12
|
ModularUIModel,
|
|
12
13
|
IModelWithChildModels,
|
|
13
14
|
ModelOptions,
|
|
15
|
+
SectionFragment,
|
|
14
16
|
} from "../types";
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -107,6 +109,13 @@ export default class ContentLinkModel
|
|
|
107
109
|
return this.getData("sourceLabel");
|
|
108
110
|
}
|
|
109
111
|
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
get abbreviation(): string | null {
|
|
116
|
+
return this.getData("abbreviation") || this.getData("sourceAbbreviation");
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
/**
|
|
111
120
|
*/
|
|
112
121
|
createEncodedHref(): Href {
|
|
@@ -167,7 +176,18 @@ export default class ContentLinkModel
|
|
|
167
176
|
* Get self link of model
|
|
168
177
|
*/
|
|
169
178
|
get selflink(): LinkModel {
|
|
170
|
-
|
|
179
|
+
let selflink = this.links.getLinkByKey("self");
|
|
180
|
+
|
|
181
|
+
if (getSetting("COMPLETE_SOURCE", false)) {
|
|
182
|
+
if (this.links.hasLinkByKey("content")) {
|
|
183
|
+
selflink = this.links.getLinkByKey("content");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (selflink != null) {
|
|
187
|
+
selflink.href.addParameter("complete", "true");
|
|
188
|
+
selflink.href.hash = this.data.section;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
171
191
|
|
|
172
192
|
if (selflink === null) {
|
|
173
193
|
throw new Error(
|
|
@@ -177,6 +197,14 @@ export default class ContentLinkModel
|
|
|
177
197
|
);
|
|
178
198
|
}
|
|
179
199
|
|
|
200
|
+
if (!selflink.href.state) {
|
|
201
|
+
selflink.href.state = {
|
|
202
|
+
fragment: this.fragment,
|
|
203
|
+
};
|
|
204
|
+
} else {
|
|
205
|
+
selflink.href.state.fragment = this.fragment;
|
|
206
|
+
}
|
|
207
|
+
|
|
180
208
|
return selflink;
|
|
181
209
|
}
|
|
182
210
|
|
|
@@ -217,6 +245,12 @@ export default class ContentLinkModel
|
|
|
217
245
|
return null;
|
|
218
246
|
}
|
|
219
247
|
|
|
248
|
+
/**
|
|
249
|
+
*/
|
|
250
|
+
get fragment(): SectionFragment | void {
|
|
251
|
+
return this.data.sectionFragment;
|
|
252
|
+
}
|
|
253
|
+
|
|
220
254
|
/**
|
|
221
255
|
* Children of link model in TOC
|
|
222
256
|
*/
|
|
@@ -92,6 +92,12 @@ export default class ContentTOCModel extends ResourceModel {
|
|
|
92
92
|
return this.getData("label", "");
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
*/
|
|
97
|
+
get abbreviation(): string | null {
|
|
98
|
+
return this.getData("abbreviation");
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
/**
|
|
96
102
|
* Getting the self link of this list
|
|
97
103
|
*/
|
|
@@ -30,6 +30,9 @@ describe("content index model", () => {
|
|
|
30
30
|
const firstLink = contentIndexModel.items.first;
|
|
31
31
|
expect(firstLink).toBeInstanceOf(ContentLinkModel);
|
|
32
32
|
|
|
33
|
+
expect(firstLink.label).toBe("Another formal content");
|
|
34
|
+
expect(firstLink.abbreviation).toBe("AFC-01");
|
|
35
|
+
|
|
33
36
|
expect(firstLink.encodedHref.toString()).toBe(
|
|
34
37
|
"/content/Content%2FSources%2FFormal%2FAnother%2520formal%2520content.formalsource",
|
|
35
38
|
);
|
|
@@ -67,7 +67,7 @@ describe("contentmodel", () => {
|
|
|
67
67
|
expect(contentModel.relatedConceptsHref.href.toString()).toBe(
|
|
68
68
|
"/content/Incident/Business design/Content/Blaastest.bixml/67beed02/relatedConcepts?entryDate=2021-08-31",
|
|
69
69
|
);
|
|
70
|
-
expect(contentModel.referenceHash).toBe(
|
|
70
|
+
expect(contentModel.referenceHash).toBe(9969574676612);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("can handle content service with childsections", () => {
|
|
@@ -106,7 +106,7 @@ describe("contentmodel", () => {
|
|
|
106
106
|
expect(contentModel.relatedConceptsHref.href.toString()).toBe(
|
|
107
107
|
"/content/Incident/Business design/Content/Blaastest.textilesource/uitslag/relatedConcepts?entryDate=2021-08-31",
|
|
108
108
|
);
|
|
109
|
-
expect(contentModel.referenceHash).toBe(
|
|
109
|
+
expect(contentModel.referenceHash).toBe(8236987459042);
|
|
110
110
|
|
|
111
111
|
const firstChildSectionLink = contentModel.childSectionLinks[0];
|
|
112
112
|
expect(firstChildSectionLink instanceof ContentLinkModel).toBe(true);
|
|
@@ -174,7 +174,7 @@ describe("contentmodel", () => {
|
|
|
174
174
|
expect(contentModel.subSections).toHaveLength(4);
|
|
175
175
|
expect(contentModel.relatedConceptsHrefs).toHaveLength(4);
|
|
176
176
|
expect(contentModel.relatedConceptsHref).toBeNull();
|
|
177
|
-
expect(contentModel.referenceHash).toBe(
|
|
177
|
+
expect(contentModel.referenceHash).toBe(3949483866644);
|
|
178
178
|
|
|
179
179
|
const firstSubSection = contentModel.subSections[0];
|
|
180
180
|
expect(firstSubSection instanceof SubSectionModel).toBe(true);
|
|
@@ -199,8 +199,8 @@ describe("contentmodel", () => {
|
|
|
199
199
|
"/content/Incident/Business design/Content/Blaastest subsections.formalsource/Pass/relatedConcepts?entryDate=2021-08-31",
|
|
200
200
|
);
|
|
201
201
|
expect(firstSubSection.relatedConceptsHref.getReferenceHash()).toBe(
|
|
202
|
-
|
|
202
|
+
7092890320518,
|
|
203
203
|
);
|
|
204
|
-
expect(firstSubSection.referenceHash).toBe(
|
|
204
|
+
expect(firstSubSection.referenceHash).toBe(7092890320518);
|
|
205
205
|
});
|
|
206
206
|
});
|
|
@@ -55,6 +55,10 @@ describe("formalsource", () => {
|
|
|
55
55
|
expect(completeModel.sections[0].sections).toHaveLength(0);
|
|
56
56
|
expect(completeModel.sections[1].sections).toHaveLength(2);
|
|
57
57
|
|
|
58
|
+
expect(completeModel.label).toBe(
|
|
59
|
+
"Grant Funding Agreement - Terms and Conditions",
|
|
60
|
+
);
|
|
61
|
+
expect(completeModel.abbreviation).toBe("GFA-TC-01");
|
|
58
62
|
expect(completeModel.isCompleteSource).toBe(true);
|
|
59
63
|
|
|
60
64
|
const firstSection = completeModel.sections[0];
|
|
@@ -147,6 +147,7 @@
|
|
|
147
147
|
"content": {
|
|
148
148
|
"_id": "/Content/Sources/Formal/Another formal content.formalsource",
|
|
149
149
|
"label": "Another formal content",
|
|
150
|
+
"abbreviation": "AFC-01",
|
|
150
151
|
"_links": {
|
|
151
152
|
"self": {
|
|
152
153
|
"href": "/content/Content/Sources/Formal/Another%20formal%20content.formalsource"
|
package/src/models/types.js
CHANGED
|
@@ -262,6 +262,13 @@ export type ContentData = {
|
|
|
262
262
|
elements: Array<PropertyElement | TextFragmentElement | ContentElement>,
|
|
263
263
|
};
|
|
264
264
|
|
|
265
|
+
export type SectionFragment = {
|
|
266
|
+
sectionId?: string,
|
|
267
|
+
text: string,
|
|
268
|
+
startOffset: number,
|
|
269
|
+
endOffset: number,
|
|
270
|
+
};
|
|
271
|
+
|
|
265
272
|
export type ModelOptions = {
|
|
266
273
|
origin?: ?string,
|
|
267
274
|
contextPath?: ?string,
|
|
@@ -2,10 +2,10 @@ import { createHash } from "../createHash";
|
|
|
2
2
|
|
|
3
3
|
describe("createHash", () => {
|
|
4
4
|
it("creates hash from string", () => {
|
|
5
|
-
expect(createHash("")).toBe(
|
|
6
|
-
expect(createHash("abcdefgh")).toBe(
|
|
7
|
-
expect(createHash(123455)).toBe(
|
|
8
|
-
expect(createHash(null)).toBe(
|
|
9
|
-
expect(createHash()).toBe(
|
|
5
|
+
expect(createHash("")).toBe(729279156);
|
|
6
|
+
expect(createHash("abcdefgh")).toBe(17595859189820);
|
|
7
|
+
expect(createHash(123455)).toBe(15900277965517);
|
|
8
|
+
expect(createHash(null)).toBe(711079339769);
|
|
9
|
+
expect(createHash()).toBe(4721361581144);
|
|
10
10
|
});
|
|
11
11
|
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
// @flow
|
|
2
|
+
import hash from "hash-it";
|
|
3
|
+
|
|
2
4
|
import type Href from "../../models/href/Href";
|
|
5
|
+
import type { SectionFragment } from "../../models";
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
|
|
6
9
|
*/
|
|
7
10
|
const createHash = (str: string): number => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let hash = 0;
|
|
11
|
-
for (let i = 0; i < str.length; i++) {
|
|
12
|
-
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
13
|
-
hash = hash & hash;
|
|
14
|
-
}
|
|
15
|
-
return hash;
|
|
11
|
+
return hash(str);
|
|
16
12
|
};
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
*/
|
|
20
|
-
const createHashFromHref = (href: Href): number => {
|
|
16
|
+
const createHashFromHref = (href: Href, fragment?: SectionFragment): number => {
|
|
21
17
|
const hrefString = href.hash
|
|
22
18
|
? [href.toString(), href.hash].join("#")
|
|
23
19
|
: href.toString();
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
if (fragment) {
|
|
22
|
+
return hash({ hrefString, fragment });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return hash(hrefString);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export { createHash, createHashFromHref };
|