tsondb 0.19.18 → 0.20.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.
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { NodeKind } from "../../../../shared/schema/Node.js";
|
|
2
|
+
import type { MarkdownStringOption } from "../../../../shared/schema/types/StringType.ts";
|
|
2
3
|
import type { StringConstraints } from "../../../../shared/validation/string.ts";
|
|
3
4
|
import type { Node } from "../index.ts";
|
|
4
5
|
import type { BaseType } from "./Type.ts";
|
|
5
6
|
export interface StringType extends BaseType, StringConstraints {
|
|
6
7
|
kind: NodeKind["StringType"];
|
|
7
8
|
pattern?: RegExp;
|
|
8
|
-
|
|
9
|
+
markdown?: MarkdownStringOption;
|
|
9
10
|
}
|
|
10
11
|
export declare const StringType: (options?: {
|
|
11
12
|
minLength?: number;
|
|
12
13
|
maxLength?: number;
|
|
13
14
|
pattern?: RegExp;
|
|
14
|
-
|
|
15
|
+
markdown?: MarkdownStringOption;
|
|
15
16
|
}) => StringType;
|
|
16
17
|
export { StringType as String };
|
|
17
18
|
export declare const isStringType: (node: Node) => node is StringType;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { sortObjectKeys, sortObjectKeysByIndex } from "@elyukai/utils/object";
|
|
1
|
+
import { mapObject, sortObjectKeys, sortObjectKeysByIndex } from "@elyukai/utils/object";
|
|
2
2
|
import { assertExhaustive } from "@elyukai/utils/typeSafety";
|
|
3
3
|
import { ENUM_DISCRIMINATOR_KEY } from "../../../shared/schema/declarations/EnumDecl.js";
|
|
4
4
|
import { NodeKind } from "../../../shared/schema/Node.js";
|
|
5
|
-
import { isObjectType } from "../dsl/types/ObjectType.js";
|
|
6
5
|
const formatTranslationObjectValue = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
7
6
|
? sortObjectKeysByIndex(Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
8
7
|
key,
|
|
@@ -18,36 +17,14 @@ export const formatValue = (type, value) => {
|
|
|
18
17
|
return Array.isArray(value) ? value.map(item => formatValue(type.items, item)) : value;
|
|
19
18
|
case NodeKind.ObjectType:
|
|
20
19
|
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
21
|
-
? sortObjectKeysByIndex(
|
|
22
|
-
key,
|
|
23
|
-
type.properties[key] ? formatValue(type.properties[key].type, item) : item,
|
|
24
|
-
])), Object.keys(type.properties))
|
|
20
|
+
? sortObjectKeysByIndex(mapObject(value, (item, key) => type.properties[key] ? formatValue(type.properties[key].type, item) : item), Object.keys(type.properties))
|
|
25
21
|
: value;
|
|
26
|
-
case NodeKind.BooleanType:
|
|
27
|
-
return value;
|
|
28
|
-
case NodeKind.DateType:
|
|
29
|
-
return value;
|
|
30
|
-
case NodeKind.FloatType:
|
|
31
|
-
return value;
|
|
32
|
-
case NodeKind.IntegerType:
|
|
33
|
-
return value;
|
|
34
|
-
case NodeKind.StringType:
|
|
35
|
-
return value;
|
|
36
|
-
case NodeKind.TypeArgumentType:
|
|
37
|
-
return value;
|
|
38
22
|
case NodeKind.IncludeIdentifierType:
|
|
39
23
|
return formatValue(type.reference.type.value, value);
|
|
40
24
|
case NodeKind.NestedEntityMapType:
|
|
41
|
-
return
|
|
42
|
-
?
|
|
43
|
-
|
|
44
|
-
key,
|
|
45
|
-
formatValue(type.type.value, item),
|
|
46
|
-
])))
|
|
47
|
-
: value
|
|
48
|
-
: formatValue(type.type.value, value);
|
|
49
|
-
case NodeKind.ReferenceIdentifierType:
|
|
50
|
-
return value;
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
26
|
+
? sortObjectKeys(mapObject(value, item => formatValue(type.type.value, item)))
|
|
27
|
+
: value;
|
|
51
28
|
case NodeKind.EnumType: {
|
|
52
29
|
if (typeof value === "object" &&
|
|
53
30
|
value !== null &&
|
|
@@ -70,6 +47,14 @@ export const formatValue = (type, value) => {
|
|
|
70
47
|
return Array.isArray(value) ? value.toSorted() : value;
|
|
71
48
|
case NodeKind.TranslationObjectType:
|
|
72
49
|
return formatTranslationObjectValue(type.properties, value);
|
|
50
|
+
case NodeKind.BooleanType:
|
|
51
|
+
case NodeKind.DateType:
|
|
52
|
+
case NodeKind.FloatType:
|
|
53
|
+
case NodeKind.IntegerType:
|
|
54
|
+
case NodeKind.StringType:
|
|
55
|
+
case NodeKind.TypeArgumentType:
|
|
56
|
+
case NodeKind.ReferenceIdentifierType:
|
|
57
|
+
return value;
|
|
73
58
|
default:
|
|
74
59
|
return assertExhaustive(type);
|
|
75
60
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { StringConstraints } from "../../validation/string.ts";
|
|
2
2
|
import type { GetReferencesSerialized, NodeKind, SerializedTypeArgumentsResolver } from "../Node.ts";
|
|
3
3
|
import type { SerializedBaseType } from "./Type.ts";
|
|
4
|
+
export type MarkdownStringOption = "block" | "inline";
|
|
4
5
|
export interface SerializedStringType extends SerializedBaseType, StringConstraints {
|
|
5
6
|
kind: NodeKind["StringType"];
|
|
6
7
|
pattern?: string;
|
|
7
|
-
|
|
8
|
+
markdown?: MarkdownStringOption;
|
|
8
9
|
}
|
|
9
10
|
export declare const resolveTypeArgumentsInSerializedStringType: SerializedTypeArgumentsResolver<SerializedStringType>;
|
|
10
11
|
export declare const getReferencesForSerializedStringType: GetReferencesSerialized<SerializedStringType>;
|
package/dist/src/web/488.js
CHANGED
|
@@ -2867,6 +2867,8 @@ const Layout = ({ breadcrumbs, children })=>{
|
|
|
2867
2867
|
]
|
|
2868
2868
|
});
|
|
2869
2869
|
};
|
|
2870
|
+
const isEmpty = (arr)=>0 === arr.length;
|
|
2871
|
+
const isNotEmpty = (arr)=>!isEmpty(arr);
|
|
2870
2872
|
class Parser {
|
|
2871
2873
|
#fn;
|
|
2872
2874
|
constructor(fn){
|
|
@@ -3147,6 +3149,13 @@ const isNaturalNumber = (test)=>naturalNumberPattern.test(test);
|
|
|
3147
3149
|
function typeSafety_assertExhaustive(_x, msg = "The switch is not exhaustive.") {
|
|
3148
3150
|
throw new Error(msg);
|
|
3149
3151
|
}
|
|
3152
|
+
const trySafe = (f, defaultValue)=>{
|
|
3153
|
+
try {
|
|
3154
|
+
return f();
|
|
3155
|
+
} catch {
|
|
3156
|
+
return defaultValue;
|
|
3157
|
+
}
|
|
3158
|
+
};
|
|
3150
3159
|
const reduceSyntaxNodes = (nodes)=>nodes.reduce((reducedNodes, node, index)=>{
|
|
3151
3160
|
const lastNode = index > 0 ? reducedNodes[reducedNodes.length - 1] : void 0;
|
|
3152
3161
|
const newLastNode = lastNode ? mergeSyntaxNodes(lastNode, node) : null;
|
|
@@ -3412,8 +3421,18 @@ const inlineNode = combineParsers([
|
|
|
3412
3421
|
leafParser(defaultInlineSyntaxStartSequences)
|
|
3413
3422
|
]);
|
|
3414
3423
|
const inlineMarkdown = inlineNode.many();
|
|
3415
|
-
const
|
|
3416
|
-
const
|
|
3424
|
+
const _parseInlineMarkdown = (syntax, keepSyntax = false)=>{
|
|
3425
|
+
const results = inlineMarkdown.evalT({
|
|
3426
|
+
indentation: 0,
|
|
3427
|
+
keepSyntax
|
|
3428
|
+
}).parse(syntax);
|
|
3429
|
+
if (!isNotEmpty(results)) throw new Error("Failed to parse");
|
|
3430
|
+
const [result, remaining] = results[0];
|
|
3431
|
+
if (remaining.length > 0) throw new Error(`Failed to parse the entire string. Remaining: "${remaining}"`);
|
|
3432
|
+
return result;
|
|
3433
|
+
};
|
|
3434
|
+
const parseInlineMarkdown = (syntax)=>_parseInlineMarkdown(syntax, false);
|
|
3435
|
+
const parseInlineMarkdownForSyntaxHighlighting = (syntax)=>_parseInlineMarkdown(syntax, true);
|
|
3417
3436
|
const isNullish = (value)=>null == value;
|
|
3418
3437
|
const isNotNullish = (value)=>!isNullish(value);
|
|
3419
3438
|
const sortObjectKeysByIndex = (obj, keys)=>Object.fromEntries([
|
|
@@ -3792,7 +3811,7 @@ const parseBlockMarkdown = (syntax)=>{
|
|
|
3792
3811
|
indentation: 0,
|
|
3793
3812
|
keepSyntax: false
|
|
3794
3813
|
}).parse(syntax);
|
|
3795
|
-
if (!
|
|
3814
|
+
if (!isNotEmpty(results)) throw new Error("Failed to parse");
|
|
3796
3815
|
const [result = [], remaining] = results[0];
|
|
3797
3816
|
if (remaining.length > 0) return [
|
|
3798
3817
|
...result,
|
|
@@ -3813,7 +3832,7 @@ const parseBlockMarkdownForSyntaxHighlighting = (syntax)=>{
|
|
|
3813
3832
|
indentation: 0,
|
|
3814
3833
|
keepSyntax: true
|
|
3815
3834
|
}).parse(syntax);
|
|
3816
|
-
if (!
|
|
3835
|
+
if (!isNotEmpty(results)) throw new Error("Failed to parse");
|
|
3817
3836
|
const [result, remaining] = results[0];
|
|
3818
3837
|
if (remaining.length > 0) return [
|
|
3819
3838
|
...result,
|
|
@@ -3986,7 +4005,7 @@ const BlockMarkdown = ({ node, outerHeadingLevel = 0, insertBefore, footnoteLabe
|
|
|
3986
4005
|
insertBefore,
|
|
3987
4006
|
/*#__PURE__*/ jsxRuntime_module_u("table", {
|
|
3988
4007
|
children: [
|
|
3989
|
-
void 0 !== node.caption &&
|
|
4008
|
+
void 0 !== node.caption && isNotEmpty(node.caption) && /*#__PURE__*/ jsxRuntime_module_u("caption", {
|
|
3990
4009
|
children: node.caption.length > 1 ? node.caption.map((captionLine, cli)=>/*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
3991
4010
|
children: captionLine.map((inline, ci)=>/*#__PURE__*/ jsxRuntime_module_u(InlineMarkdown, {
|
|
3992
4011
|
node: inline
|
|
@@ -4123,19 +4142,25 @@ const TableRow = ({ columns, cells, cellType = "td" })=>{
|
|
|
4123
4142
|
])[0]
|
|
4124
4143
|
});
|
|
4125
4144
|
};
|
|
4126
|
-
const Markdown = ({ class: className, string, outerHeadingLevel, footnoteLabelSuffix })=>{
|
|
4127
|
-
const
|
|
4128
|
-
|
|
4129
|
-
|
|
4145
|
+
const Markdown = ({ class: className, string, outerHeadingLevel, footnoteLabelSuffix, inline })=>{
|
|
4146
|
+
const elements = inline ? trySafe(()=>parseInlineMarkdown(string), [
|
|
4147
|
+
{
|
|
4148
|
+
type: "text",
|
|
4149
|
+
content: string
|
|
4150
|
+
}
|
|
4151
|
+
]).map((node, i)=>/*#__PURE__*/ jsxRuntime_module_u(InlineMarkdown, {
|
|
4152
|
+
node: node
|
|
4153
|
+
}, `md-inline-${i.toString()}`)) : parseBlockMarkdown(string).map((node, i)=>/*#__PURE__*/ jsxRuntime_module_u(BlockMarkdown, {
|
|
4154
|
+
node: node,
|
|
4130
4155
|
outerHeadingLevel: outerHeadingLevel,
|
|
4131
4156
|
footnoteLabelSuffix: footnoteLabelSuffix
|
|
4132
4157
|
}, `md-block-${i.toString()}`));
|
|
4133
4158
|
if (className) return /*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
4134
4159
|
class: className,
|
|
4135
|
-
children:
|
|
4160
|
+
children: elements
|
|
4136
4161
|
});
|
|
4137
4162
|
return /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
|
|
4138
|
-
children:
|
|
4163
|
+
children: elements
|
|
4139
4164
|
});
|
|
4140
4165
|
};
|
|
4141
4166
|
const homeTitle = "Entities";
|
|
@@ -4504,7 +4529,7 @@ const isSinglularInputFieldType = (getDeclFromDeclName, type)=>{
|
|
|
4504
4529
|
return secondaryDecl ? isSinglularInputFieldType(getDeclFromDeclName, secondaryDecl.type) : false;
|
|
4505
4530
|
}
|
|
4506
4531
|
case "StringType":
|
|
4507
|
-
return !(type.
|
|
4532
|
+
return !(type.markdown ?? false);
|
|
4508
4533
|
default:
|
|
4509
4534
|
return typeSafety_assertExhaustive(type);
|
|
4510
4535
|
}
|
|
@@ -5481,8 +5506,13 @@ const BlockMarkdownHighlighting = ({ node })=>{
|
|
|
5481
5506
|
return typeSafety_assertExhaustive(node.blockType);
|
|
5482
5507
|
}
|
|
5483
5508
|
};
|
|
5484
|
-
const MarkdownHighlighting = ({ class: className, string })=>{
|
|
5485
|
-
const blocks =
|
|
5509
|
+
const MarkdownHighlighting = ({ class: className, string, inline })=>{
|
|
5510
|
+
const blocks = inline ? trySafe(()=>parseInlineMarkdownForSyntaxHighlighting(string), [
|
|
5511
|
+
{
|
|
5512
|
+
type: "text",
|
|
5513
|
+
content: string
|
|
5514
|
+
}
|
|
5515
|
+
]) : parseBlockMarkdownForSyntaxHighlighting(string);
|
|
5486
5516
|
const blockElements = blocks.map((block, i)=>/*#__PURE__*/ jsxRuntime_module_u(BlockMarkdownHighlighting, {
|
|
5487
5517
|
node: block
|
|
5488
5518
|
}, `md-block-${i.toString()}`));
|
|
@@ -5499,8 +5529,9 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5499
5529
|
expected: "string",
|
|
5500
5530
|
actual: value
|
|
5501
5531
|
});
|
|
5502
|
-
const { minLength, maxLength, pattern,
|
|
5532
|
+
const { minLength, maxLength, pattern, markdown } = type;
|
|
5503
5533
|
const errors = validateStringConstraints(type, value);
|
|
5534
|
+
const preparedPattern = void 0 === pattern ? void 0 : pattern.startsWith("^(?:") && pattern.endsWith(")$") ? pattern.slice(4, -2) : `.*${pattern}.*`;
|
|
5504
5535
|
return /*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
5505
5536
|
class: "field field--string",
|
|
5506
5537
|
children: inTranslationObject ? /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
|
|
@@ -5533,7 +5564,7 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5533
5564
|
})
|
|
5534
5565
|
]
|
|
5535
5566
|
})
|
|
5536
|
-
}) :
|
|
5567
|
+
}) : void 0 !== markdown ? /*#__PURE__*/ jsxRuntime_module_u(preact_module_k, {
|
|
5537
5568
|
children: [
|
|
5538
5569
|
/*#__PURE__*/ jsxRuntime_module_u("div", {
|
|
5539
5570
|
class: "editor editor--markdown",
|
|
@@ -5555,7 +5586,7 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5555
5586
|
/*#__PURE__*/ jsxRuntime_module_u("p", {
|
|
5556
5587
|
class: "help",
|
|
5557
5588
|
children: [
|
|
5558
|
-
"This
|
|
5589
|
+
"This text field supports",
|
|
5559
5590
|
" ",
|
|
5560
5591
|
/*#__PURE__*/ jsxRuntime_module_u("a", {
|
|
5561
5592
|
href: "https://www.markdownguide.org/getting-started/",
|
|
@@ -5568,7 +5599,8 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5568
5599
|
}),
|
|
5569
5600
|
/*#__PURE__*/ jsxRuntime_module_u(MarkdownHighlighting, {
|
|
5570
5601
|
class: "textarea-grow-wrap__mirror editor-highlighting",
|
|
5571
|
-
string: value + " "
|
|
5602
|
+
string: value + " ",
|
|
5603
|
+
inline: "inline" === markdown
|
|
5572
5604
|
})
|
|
5573
5605
|
]
|
|
5574
5606
|
}),
|
|
@@ -5582,7 +5614,8 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5582
5614
|
class: "preview",
|
|
5583
5615
|
children: /*#__PURE__*/ jsxRuntime_module_u(Markdown, {
|
|
5584
5616
|
string: value,
|
|
5585
|
-
outerHeadingLevel: 2
|
|
5617
|
+
outerHeadingLevel: 2,
|
|
5618
|
+
inline: "inline" === markdown
|
|
5586
5619
|
})
|
|
5587
5620
|
})
|
|
5588
5621
|
]
|
|
@@ -5594,7 +5627,7 @@ const StringTypeInput = ({ type, value, disabled, onChange, inTranslationObject
|
|
|
5594
5627
|
value: value,
|
|
5595
5628
|
minLength: minLength,
|
|
5596
5629
|
maxLength: maxLength,
|
|
5597
|
-
pattern:
|
|
5630
|
+
pattern: preparedPattern,
|
|
5598
5631
|
onInput: (event)=>{
|
|
5599
5632
|
onChange(event.currentTarget.value);
|
|
5600
5633
|
},
|