ochre-sdk 1.0.14 → 1.0.15
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/parsers/string.mjs +15 -47
- package/dist/schemas.d.mts +1 -6
- package/dist/schemas.mjs +1 -10
- package/package.json +3 -3
package/dist/parsers/string.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TEXT_ANNOTATION_UUID } from "../constants.mjs";
|
|
2
2
|
import { serializeMDXText } from "./mdx.mjs";
|
|
3
3
|
import { MultilingualString } from "./multilingual.mjs";
|
|
4
|
-
import { renderOptionsSchema
|
|
4
|
+
import { renderOptionsSchema } from "../schemas.mjs";
|
|
5
5
|
import { getXMLSourceIndex } from "../xml/metadata.mjs";
|
|
6
6
|
import * as v from "valibot";
|
|
7
7
|
//#region src/parsers/string.ts
|
|
@@ -64,47 +64,18 @@ function applyMDXRenderElements(contentString, options) {
|
|
|
64
64
|
return result;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @param contentString - The string content to modify
|
|
70
|
-
* @param whitespace - Space-separated string of whitespace options
|
|
71
|
-
* @param rendering - Which text rendering to produce
|
|
72
|
-
* @returns String with whitespace modifications applied
|
|
73
|
-
*
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
function parseWhitespace(contentString, whitespace, rendering) {
|
|
77
|
-
let returnString = contentString;
|
|
78
|
-
const { success, output } = v.safeParse(whitespaceSchema, whitespace);
|
|
79
|
-
if (!success) return contentString;
|
|
80
|
-
for (const option of output) switch (option) {
|
|
81
|
-
case "newline":
|
|
82
|
-
if (rendering === "rich") returnString = returnString.trim() === "***" ? `${returnString}\n` : `<br />\n${returnString}`;
|
|
83
|
-
else returnString = `\n${returnString}`;
|
|
84
|
-
break;
|
|
85
|
-
case "trailing":
|
|
86
|
-
returnString = `${returnString} `;
|
|
87
|
-
break;
|
|
88
|
-
case "leading":
|
|
89
|
-
returnString = ` ${returnString}`;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return returnString.replaceAll("'", "'");
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Parses XML string into a formatted string with whitespace and rendering options
|
|
67
|
+
* Parses XML string into a formatted string with rendering options
|
|
96
68
|
*
|
|
97
69
|
* @param string - XML string to parse
|
|
98
70
|
* @param options - Options for parsing
|
|
99
71
|
* @param options.rendering - Which text rendering to produce
|
|
100
|
-
* @returns Formatted string with
|
|
72
|
+
* @returns Formatted string with rendering options
|
|
101
73
|
*
|
|
102
74
|
* @internal
|
|
103
75
|
*/
|
|
104
76
|
function parseXMLStringVariant(string, options) {
|
|
105
77
|
let returnString = parseXMLStringPayload(string, options);
|
|
106
78
|
if (string.rend != null) returnString = parseRenderOptions(returnString, string.rend, options.rendering);
|
|
107
|
-
if (string.whitespace != null) returnString = parseWhitespace(returnString, string.whitespace, options.rendering);
|
|
108
79
|
return returnString;
|
|
109
80
|
}
|
|
110
81
|
function parseXMLStringPayload(string, options) {
|
|
@@ -162,9 +133,6 @@ function createMDXStringAttribute(name, value) {
|
|
|
162
133
|
if (value == null || value === "") return "";
|
|
163
134
|
return ` ${name}=${MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX.test(value) ? `{${JSON.stringify(value)}}` : `"${value}"`}`;
|
|
164
135
|
}
|
|
165
|
-
function applyWhitespaceToResult(result, whitespace, rendering) {
|
|
166
|
-
return whitespace == null ? result : parseWhitespace(result, whitespace, rendering);
|
|
167
|
-
}
|
|
168
136
|
function getPropertyValueUuid(property) {
|
|
169
137
|
const value = property?.value?.[0];
|
|
170
138
|
return value?.uuid == null || value.uuid === "" ? null : value.uuid;
|
|
@@ -264,17 +232,17 @@ function hasRichTextEnvelope(item) {
|
|
|
264
232
|
return item.properties?.property[0] != null || getXMLRichTextLinks(item).length > 0;
|
|
265
233
|
}
|
|
266
234
|
function parseXMLStringItem(item, contentItem, options) {
|
|
267
|
-
if (!(item.payload != null || item.string != null) && getXMLRichTextLinks(item).length === 0) return
|
|
235
|
+
if (!(item.payload != null || item.string != null) && getXMLRichTextLinks(item).length === 0) return "";
|
|
268
236
|
if (hasRichTextEnvelope(item)) {
|
|
269
237
|
let linkString = item.payload != null ? parseXMLStringPayload(item, { rendering: options.rendering }) : parseNestedStringItems(item.string ?? [], contentItem, { ...options });
|
|
270
238
|
if (item.rend != null) linkString = parseRenderOptions(linkString, item.rend, options.rendering);
|
|
271
|
-
if (options.rendering === "plain") return
|
|
239
|
+
if (options.rendering === "plain") return linkString;
|
|
272
240
|
return renderRichTextItem(item, linkString, contentItem, options);
|
|
273
241
|
}
|
|
274
242
|
if (item.payload != null) return parseXMLStringVariant(item, { rendering: options.rendering });
|
|
275
243
|
let result = parseNestedStringItems(item.string ?? [], contentItem, options);
|
|
276
244
|
if (item.rend != null) result = parseRenderOptions(result, item.rend, options.rendering);
|
|
277
|
-
return
|
|
245
|
+
return result;
|
|
278
246
|
}
|
|
279
247
|
function parseNestedStringItems(items, contentItem, options) {
|
|
280
248
|
let result = "";
|
|
@@ -324,7 +292,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
324
292
|
const { languages, rendering } = options;
|
|
325
293
|
const annotationMetadata = extractAnnotationMetadata(item, { language: contentItem.lang });
|
|
326
294
|
const links = getXMLRichTextLinks(item);
|
|
327
|
-
if (links.length === 0) return
|
|
295
|
+
if (links.length === 0) return wrapWithTextStyling(linkString, annotationMetadata.textStyling);
|
|
328
296
|
let result = "";
|
|
329
297
|
for (const link of links) {
|
|
330
298
|
const linkContent = link.identification != null ? "content" in link.identification.label ? parseXMLContent(link.identification.label, { languages }) : MultilingualString.create(contentItem.lang, parseXMLString(link.identification.label), languages) : MultilingualString.create(contentItem.lang, "", languages);
|
|
@@ -341,7 +309,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
341
309
|
content: contentText,
|
|
342
310
|
text: linkString
|
|
343
311
|
});
|
|
344
|
-
result +=
|
|
312
|
+
result += component;
|
|
345
313
|
} else if (link.publicationDateTime != null) {
|
|
346
314
|
const component = createInternalLinkComponent({
|
|
347
315
|
uuid: getLinkStringProperty(link, "uuid"),
|
|
@@ -349,14 +317,14 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
349
317
|
content: contentText,
|
|
350
318
|
annotationMetadata
|
|
351
319
|
});
|
|
352
|
-
result +=
|
|
320
|
+
result += component;
|
|
353
321
|
} else {
|
|
354
322
|
const component = createMDXComponent("tooltipSpan", {
|
|
355
323
|
uuid: getLinkStringProperty(link, "uuid"),
|
|
356
324
|
text: linkString,
|
|
357
325
|
content: contentText
|
|
358
326
|
});
|
|
359
|
-
result +=
|
|
327
|
+
result += component;
|
|
360
328
|
}
|
|
361
329
|
break;
|
|
362
330
|
case "internalDocument": {
|
|
@@ -367,7 +335,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
367
335
|
annotationMetadata,
|
|
368
336
|
propertyMetadata: getFirstPropertyMetadata(item)
|
|
369
337
|
});
|
|
370
|
-
result +=
|
|
338
|
+
result += component;
|
|
371
339
|
break;
|
|
372
340
|
}
|
|
373
341
|
case "externalDocument": {
|
|
@@ -380,7 +348,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
380
348
|
text: linkString,
|
|
381
349
|
content: contentText
|
|
382
350
|
});
|
|
383
|
-
result +=
|
|
351
|
+
result += component;
|
|
384
352
|
break;
|
|
385
353
|
}
|
|
386
354
|
case "webpage": {
|
|
@@ -390,7 +358,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
390
358
|
text: linkString,
|
|
391
359
|
content: contentText
|
|
392
360
|
});
|
|
393
|
-
result +=
|
|
361
|
+
result += component;
|
|
394
362
|
break;
|
|
395
363
|
}
|
|
396
364
|
}
|
|
@@ -401,14 +369,14 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
401
369
|
content: contentText,
|
|
402
370
|
annotationMetadata
|
|
403
371
|
});
|
|
404
|
-
result +=
|
|
372
|
+
result += component;
|
|
405
373
|
} else {
|
|
406
374
|
const component = createMDXComponent("tooltipSpan", {
|
|
407
375
|
uuid: getLinkStringProperty(link, "uuid"),
|
|
408
376
|
text: linkString,
|
|
409
377
|
content: contentText
|
|
410
378
|
});
|
|
411
|
-
result +=
|
|
379
|
+
result += component;
|
|
412
380
|
}
|
|
413
381
|
}
|
|
414
382
|
return result;
|
package/dist/schemas.d.mts
CHANGED
|
@@ -32,11 +32,6 @@ declare const gallerySchema: v.ObjectSchema<{
|
|
|
32
32
|
* @internal
|
|
33
33
|
*/
|
|
34
34
|
declare const renderOptionsSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string[]>, v.ArraySchema<v.PicklistSchema<["bold", "italic", "underline"], undefined>, undefined>]>;
|
|
35
|
-
/**
|
|
36
|
-
* Schema for validating and parsing whitespace options
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
declare const whitespaceSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string[]>, v.ArraySchema<v.PicklistSchema<["newline", "trailing", "leading"], undefined>, undefined>]>;
|
|
40
35
|
/**
|
|
41
36
|
* Schema for validating the parameters for the Set property values fetching function
|
|
42
37
|
* @internal
|
|
@@ -81,4 +76,4 @@ declare const setItemsParamsSchema: v.ObjectSchema<{
|
|
|
81
76
|
readonly pageSize: v.OptionalSchema<v.GenericSchema<unknown, number>, 48>;
|
|
82
77
|
}, undefined>;
|
|
83
78
|
//#endregion
|
|
84
|
-
export { componentSchema, gallerySchema, iso639_3Schema, renderOptionsSchema, setItemsParamsSchema, setPropertyValuesParamsSchema, uuidSchema
|
|
79
|
+
export { componentSchema, gallerySchema, iso639_3Schema, renderOptionsSchema, setItemsParamsSchema, setPropertyValuesParamsSchema, uuidSchema };
|
package/dist/schemas.mjs
CHANGED
|
@@ -63,15 +63,6 @@ const renderOptionsSchema = v.pipe(v.string(), v.transform((str) => str.split("
|
|
|
63
63
|
"underline"
|
|
64
64
|
])));
|
|
65
65
|
/**
|
|
66
|
-
* Schema for validating and parsing whitespace options
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
const whitespaceSchema = v.pipe(v.string(), v.transform((str) => str.split(" ")), v.array(v.picklist([
|
|
70
|
-
"newline",
|
|
71
|
-
"trailing",
|
|
72
|
-
"leading"
|
|
73
|
-
])));
|
|
74
|
-
/**
|
|
75
66
|
* Schema for validating date data types
|
|
76
67
|
* @internal
|
|
77
68
|
*/
|
|
@@ -229,4 +220,4 @@ const setItemsParamsSchema = v.object({
|
|
|
229
220
|
pageSize: v.optional(positiveNumber("Page size must be positive"), 48)
|
|
230
221
|
});
|
|
231
222
|
//#endregion
|
|
232
|
-
export { componentSchema, gallerySchema, iso639_3Schema, renderOptionsSchema, setItemsParamsSchema, setPropertyValuesParamsSchema, uuidSchema
|
|
223
|
+
export { componentSchema, gallerySchema, iso639_3Schema, renderOptionsSchema, setItemsParamsSchema, setPropertyValuesParamsSchema, uuidSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"scripts": {
|
|
65
65
|
"dev": "tsdown src/index.ts --watch",
|
|
66
66
|
"build": "tsdown",
|
|
67
|
-
"lint": "knip
|
|
68
|
-
"lint:fix": "knip fix
|
|
67
|
+
"lint": "knip; eslint .",
|
|
68
|
+
"lint:fix": "knip --fix; eslint . --fix",
|
|
69
69
|
"format": "prettier --check .",
|
|
70
70
|
"format:fix": "prettier --write --list-different .",
|
|
71
71
|
"check-types": "tsc --noEmit",
|