vis-chronicle 1.2.1 → 1.2.3
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/package.json +1 -1
- package/src/fetch.js +1 -1
- package/src/relativeDates.js +18 -16
- package/src/render.js +22 -10
- package/src/wikidata.js +9 -6
package/package.json
CHANGED
package/src/fetch.js
CHANGED
package/src/relativeDates.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const moment = require('moment')
|
|
3
3
|
const { toJewishDate, toGregorianDate, getIndexByJewishMonth } = require("jewish-date");
|
|
4
|
+
const wikidata = require('./wikidata');
|
|
4
5
|
|
|
5
6
|
function momentToHDate(inMoment)
|
|
6
7
|
{
|
|
@@ -26,23 +27,19 @@ function durationToWikidataPrecision(duration)
|
|
|
26
27
|
// Flattens a relative date string into a hard date string
|
|
27
28
|
module.exports = function flattenRelativeDate(wikidataCache, dateString)
|
|
28
29
|
{
|
|
30
|
+
if (dateString == '') return null
|
|
31
|
+
|
|
29
32
|
// parse out relative date components
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
while (true)
|
|
33
|
+
var relSplit
|
|
34
|
+
var match = dateString.match(wikidata.pathQueryRegex)
|
|
35
|
+
if (match)
|
|
34
36
|
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
relSplit.push(dateString.substring(lastSep))
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
lastSep = match.index
|
|
37
|
+
relSplit = match.slice(1)
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
{
|
|
41
|
+
console.error(`Failed to parse relative date '${dateString}'.`)
|
|
42
|
+
return null
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
if (!relSplit[0])
|
|
@@ -70,7 +67,12 @@ module.exports = function flattenRelativeDate(wikidataCache, dateString)
|
|
|
70
67
|
for (var i = 1; i < relSplit.length; i++)
|
|
71
68
|
{
|
|
72
69
|
const component = relSplit[i]
|
|
73
|
-
if (component
|
|
70
|
+
if (!component)
|
|
71
|
+
{
|
|
72
|
+
// empty group from regex
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
else if (component[0] == "+")
|
|
74
76
|
{
|
|
75
77
|
const momentDelta = moment.duration(component.substring(1))
|
|
76
78
|
momentDate = momentDate.add(momentDelta)
|
package/src/render.js
CHANGED
|
@@ -35,6 +35,18 @@ function momentSafeMax(a, b)
|
|
|
35
35
|
return a ? (b ? moment.max(a, b) : a) : b
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// Copies properties that should be untouched by the renderer from 'from' to 'to'
|
|
39
|
+
function copyItemUntouchedProps(from, to)
|
|
40
|
+
{
|
|
41
|
+
to.align = from.align
|
|
42
|
+
to.selectable = from.selectable
|
|
43
|
+
to.style = from.style
|
|
44
|
+
to.title = from.title
|
|
45
|
+
to.limitSize = from.limitSize
|
|
46
|
+
to.editable = from.editable
|
|
47
|
+
to.wikidata = from.entity
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
const renderer = {}
|
|
39
51
|
|
|
40
52
|
renderer.getExpectation = function(item)
|
|
@@ -197,9 +209,9 @@ renderer.produceOutput = function(inputSpec, items)
|
|
|
197
209
|
content: item.label,
|
|
198
210
|
className: item.className,
|
|
199
211
|
comment: item.comment,
|
|
200
|
-
type: item.type
|
|
201
|
-
wikidata: item.entity
|
|
212
|
+
type: item.type
|
|
202
213
|
}
|
|
214
|
+
copyItemUntouchedProps(item, outputItem)
|
|
203
215
|
if (item.group)
|
|
204
216
|
{
|
|
205
217
|
outputItem.group = item.group
|
|
@@ -287,9 +299,9 @@ renderer.produceOutput = function(inputSpec, items)
|
|
|
287
299
|
start: uncertainMin,
|
|
288
300
|
end: item.end_max,
|
|
289
301
|
group: item.group,
|
|
290
|
-
subgroup: outputItem.subgroup
|
|
291
|
-
wikidata: item.entity
|
|
302
|
+
subgroup: outputItem.subgroup
|
|
292
303
|
}
|
|
304
|
+
copyItemUntouchedProps(item, uncertainElement)
|
|
293
305
|
outputObject.items.push(uncertainElement)
|
|
294
306
|
|
|
295
307
|
if (permitBgOverlay)
|
|
@@ -344,9 +356,9 @@ renderer.produceOutput = function(inputSpec, items)
|
|
|
344
356
|
start: outputItem.end,
|
|
345
357
|
end: tailEnd,
|
|
346
358
|
group: item.group,
|
|
347
|
-
subgroup: outputItem.subgroup
|
|
348
|
-
wikidata: item.entity
|
|
359
|
+
subgroup: outputItem.subgroup
|
|
349
360
|
})
|
|
361
|
+
copyItemUntouchedProps(item, outputObject)
|
|
350
362
|
|
|
351
363
|
outputItem.className = [ outputItem.className, 'visc-right-connection' ].join(' ')
|
|
352
364
|
}
|
|
@@ -367,9 +379,9 @@ renderer.produceOutput = function(inputSpec, items)
|
|
|
367
379
|
start: outputItem.end,
|
|
368
380
|
end: tailEnd,
|
|
369
381
|
group: item.group,
|
|
370
|
-
subgroup: outputItem.subgroup
|
|
371
|
-
wikidata: item.entity
|
|
382
|
+
subgroup: outputItem.subgroup
|
|
372
383
|
})
|
|
384
|
+
copyItemUntouchedProps(item, outputObject)
|
|
373
385
|
|
|
374
386
|
outputItem.className = [ outputItem.className, 'visc-right-connection' ].join(' ')
|
|
375
387
|
}
|
|
@@ -410,9 +422,9 @@ renderer.produceOutput = function(inputSpec, items)
|
|
|
410
422
|
start: item.start_min,
|
|
411
423
|
end: uncertainMax,
|
|
412
424
|
group: item.group,
|
|
413
|
-
subgroup: outputItem.subgroup
|
|
414
|
-
wikidata: item.entity
|
|
425
|
+
subgroup: outputItem.subgroup
|
|
415
426
|
}
|
|
427
|
+
copyItemUntouchedProps(item, uncertainElement)
|
|
416
428
|
outputObject.items.push(uncertainElement)
|
|
417
429
|
|
|
418
430
|
if (permitBgOverlay)
|
package/src/wikidata.js
CHANGED
|
@@ -41,6 +41,8 @@ const wikidata = module.exports = {
|
|
|
41
41
|
rankNormal: "http://wikiba.se/ontology#NormalRank",
|
|
42
42
|
rankPreferred: "http://wikiba.se/ontology#PreferredRank",
|
|
43
43
|
|
|
44
|
+
pathQueryRegex: /^(Q[0-9]+(?::P[0-9]+)?(?::Q[0-9]+:P[0-9]+)?)([\+>](?:[A-Za-z]+(?:![0-9]+)?|P\-?[0-9A-Z]+)+)*$/,
|
|
45
|
+
|
|
44
46
|
initialize: function()
|
|
45
47
|
{
|
|
46
48
|
const chroniclePackage = require("../package.json")
|
|
@@ -499,21 +501,22 @@ const wikidata = module.exports = {
|
|
|
499
501
|
const wdQualifiers = new Set()
|
|
500
502
|
for (const query of queries)
|
|
501
503
|
{
|
|
502
|
-
|
|
504
|
+
const match = query.match(/^(Q[0-9]+(?::P[0-9]+)?(?::Q[0-9]+:P[0-9]+)?)([\+>](?:[A-Za-z]+(?:![0-9]+)?|P\-?[0-9A-Z]+)+)*$/)
|
|
505
|
+
if (match && match[1])
|
|
503
506
|
{
|
|
504
|
-
const
|
|
505
|
-
const split =
|
|
507
|
+
const root = match[1]
|
|
508
|
+
const split = root.split(':')
|
|
506
509
|
if (split.length == 1)
|
|
507
510
|
{
|
|
508
|
-
wdStandaloneIds.add(
|
|
511
|
+
wdStandaloneIds.add(root)
|
|
509
512
|
}
|
|
510
513
|
else if (split.length == 2)
|
|
511
514
|
{
|
|
512
|
-
wdProperties.add(
|
|
515
|
+
wdProperties.add(root)
|
|
513
516
|
}
|
|
514
517
|
else if (split.length == 4)
|
|
515
518
|
{
|
|
516
|
-
wdQualifiers.add(
|
|
519
|
+
wdQualifiers.add(root)
|
|
517
520
|
}
|
|
518
521
|
else
|
|
519
522
|
{
|