tsondb 0.11.0 → 0.11.2
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.
|
@@ -583,10 +583,21 @@ const parseActiveBlockRule = (rule, res) => [
|
|
|
583
583
|
rule.map(res),
|
|
584
584
|
];
|
|
585
585
|
const parseActiveBlockSyntaxRule = (rule, res) => rule.mapHighlighting(res);
|
|
586
|
-
const
|
|
586
|
+
const leadingNewlinesPattern = /^((?:[ \t]*\n)*)/;
|
|
587
|
+
const parseForBlockRules = (rules, text, ruleParser, trimLeadingWhitespace, remainingRules = rules) => {
|
|
587
588
|
if (text.length === 0 || remainingRules[0] === undefined) {
|
|
588
589
|
return [];
|
|
589
590
|
}
|
|
591
|
+
else if (trimLeadingWhitespace === true) {
|
|
592
|
+
return parseForBlockRules(rules, text.replace(leadingNewlinesPattern, ""), ruleParser, undefined, remainingRules);
|
|
593
|
+
}
|
|
594
|
+
else if (trimLeadingWhitespace) {
|
|
595
|
+
const matchedText = text.match(leadingNewlinesPattern)?.[0];
|
|
596
|
+
return [
|
|
597
|
+
...(matchedText ? trimLeadingWhitespace(matchedText) : []),
|
|
598
|
+
...parseForBlockRules(rules, text.replace(leadingNewlinesPattern, ""), ruleParser, undefined, remainingRules),
|
|
599
|
+
];
|
|
600
|
+
}
|
|
590
601
|
const activeRule = remainingRules[0];
|
|
591
602
|
const res = activeRule.pattern.exec(text);
|
|
592
603
|
if (res && (activeRule.predicate?.(res) ?? true)) {
|
|
@@ -598,11 +609,11 @@ const parseForBlockRules = (rules, text, ruleParser, remainingRules = rules) =>
|
|
|
598
609
|
];
|
|
599
610
|
}
|
|
600
611
|
else {
|
|
601
|
-
return parseForBlockRules(rules, text, ruleParser, remainingRules.slice(1));
|
|
612
|
+
return parseForBlockRules(rules, text, ruleParser, trimLeadingWhitespace, remainingRules.slice(1));
|
|
602
613
|
}
|
|
603
614
|
};
|
|
604
|
-
export const parseBlockMarkdown = (text) => parseForBlockRules(blockRules, text, parseActiveBlockRule);
|
|
605
|
-
export const parseBlockMarkdownForSyntaxHighlighting = (text) => reduceSyntaxNodes(parseForBlockRules(blockRules, text, parseActiveBlockSyntaxRule));
|
|
615
|
+
export const parseBlockMarkdown = (text) => parseForBlockRules(blockRules, text, parseActiveBlockRule, true);
|
|
616
|
+
export const parseBlockMarkdownForSyntaxHighlighting = (text) => reduceSyntaxNodes(parseForBlockRules(blockRules, text, parseActiveBlockSyntaxRule, text => [textNode(text)]));
|
|
606
617
|
export const reduceSyntaxNodes = (nodes) => nodes.reduce((reducedNodes, node, index) => {
|
|
607
618
|
const lastNode = index > 0 ? reducedNodes[reducedNodes.length - 1] : undefined;
|
|
608
619
|
const newLastNode = lastNode ? mergeSyntaxNodes(lastNode, node) : null;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
2
|
import { useLocation, useRoute } from "preact-iso";
|
|
3
3
|
import { useCallback, useContext, useEffect, useMemo, useState } from "preact/hooks";
|
|
4
|
-
import { removeAt } from "../../shared/utils/array.js";
|
|
5
4
|
import { deepEqual } from "../../shared/utils/compare.js";
|
|
6
5
|
import { getSerializedDisplayNameFromEntityInstance } from "../../shared/utils/displayName.js";
|
|
7
6
|
import { toTitleCase } from "../../shared/utils/string.js";
|
|
@@ -154,18 +153,6 @@ export const InstanceRouteSkeleton = ({ mode, buttons, init, titleBuilder, onSub
|
|
|
154
153
|
});
|
|
155
154
|
}
|
|
156
155
|
};
|
|
157
|
-
const handleOnChildChange = useCallback((index, value) => {
|
|
158
|
-
setChildInstances(old => old[index] ? old.with(index, { ...old[index], content: value }) : old);
|
|
159
|
-
}, []);
|
|
160
|
-
const handleOnChildAdd = useCallback((entityName, value) => {
|
|
161
|
-
setChildInstances(old => [
|
|
162
|
-
...old,
|
|
163
|
-
{ entityName, childInstances: [], id: undefined, content: value },
|
|
164
|
-
]);
|
|
165
|
-
}, []);
|
|
166
|
-
const handleOnChildRemove = useCallback((index) => {
|
|
167
|
-
setChildInstances(old => removeAt(old, index));
|
|
168
|
-
}, []);
|
|
169
156
|
if (!name || (mode === "edit" && !id)) {
|
|
170
157
|
return _jsx(NotFound, {});
|
|
171
158
|
}
|
|
@@ -199,5 +186,5 @@ export const InstanceRouteSkeleton = ({ mode, buttons, init, titleBuilder, onSub
|
|
|
199
186
|
}
|
|
200
187
|
}, children: "Delete" }))] }), !id && isLocaleEntity && (_jsxs("div", { class: "field field--id", children: [_jsx("label", { htmlFor: "id", children: "ID" }), _jsx("p", { className: "comment", children: "The instance\u2019s identifier. An IETF language tag (BCP47)." }), _jsx("input", { type: "text", id: "id", value: customId, required: true, pattern: "[a-z]{2,3}(-[A-Z]{2,3})?", placeholder: "en-US, de-DE, \u2026", onInput: event => {
|
|
201
188
|
setCustomId(event.currentTarget.value);
|
|
202
|
-
}, "aria-invalid": idErrors.length > 0 }), _jsx(ValidationErrors, { errors: idErrors })] })), _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TypeInput, { type: entity.type, value: instanceContent, path: undefined, instanceNamesByEntity: instanceNamesByEntity, childInstances: childInstances, getDeclFromDeclName: getDeclFromDeclName, onChange: setInstanceContent,
|
|
189
|
+
}, "aria-invalid": idErrors.length > 0 }), _jsx(ValidationErrors, { errors: idErrors })] })), _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TypeInput, { type: entity.type, value: instanceContent, path: undefined, instanceNamesByEntity: instanceNamesByEntity, childInstances: childInstances, getDeclFromDeclName: getDeclFromDeclName, onChange: setInstanceContent, setChildInstances: setChildInstances, checkIsLocaleEntity: checkIsLocaleEntity }), _jsx("div", { class: "form-footer btns", children: buttons.map(button => (_jsx("button", { type: "submit", name: button.name, class: button.primary ? "primary" : undefined, disabled: !hasUnsavedChanges, children: button.label }, button.name))) })] })] }));
|
|
203
190
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useCallback } from "preact/hooks";
|
|
2
3
|
import { isSerializedEntityDecl } from "../../../shared/schema/declarations/EntityDecl.js";
|
|
4
|
+
import { removeAt } from "../../../shared/utils/array.js";
|
|
3
5
|
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
4
6
|
import { TypeInput } from "./TypeInput.js";
|
|
5
7
|
export const ChildEntitiesTypeInput = props => {
|
|
6
|
-
const { type, path, childInstances, disabled, getDeclFromDeclName,
|
|
8
|
+
const { type, path, childInstances, disabled, getDeclFromDeclName, setChildInstances } = props;
|
|
7
9
|
const childEntity = getDeclFromDeclName(type.entity);
|
|
8
10
|
const childInstancesForEntity = childInstances
|
|
9
11
|
.map((childInstance, index) => [
|
|
@@ -11,6 +13,26 @@ export const ChildEntitiesTypeInput = props => {
|
|
|
11
13
|
index,
|
|
12
14
|
])
|
|
13
15
|
.filter(([childInstance]) => childInstance.entityName === type.entity);
|
|
16
|
+
const onChildChange = useCallback((index, value) => {
|
|
17
|
+
setChildInstances(old => old[index] ? old.with(index, { ...old[index], content: value }) : old);
|
|
18
|
+
}, [setChildInstances]);
|
|
19
|
+
const onGrandChildrenChange = useCallback((index, newChildren) => {
|
|
20
|
+
setChildInstances(old => old[index]
|
|
21
|
+
? old.with(index, {
|
|
22
|
+
...old[index],
|
|
23
|
+
childInstances: newChildren(old[index].childInstances),
|
|
24
|
+
})
|
|
25
|
+
: old);
|
|
26
|
+
}, [setChildInstances]);
|
|
27
|
+
const onChildAdd = useCallback((entityName, value) => {
|
|
28
|
+
setChildInstances(old => [
|
|
29
|
+
...old,
|
|
30
|
+
{ entityName, childInstances: [], id: undefined, content: value },
|
|
31
|
+
]);
|
|
32
|
+
}, [setChildInstances]);
|
|
33
|
+
const onChildRemove = useCallback((index) => {
|
|
34
|
+
setChildInstances(old => removeAt(old, index));
|
|
35
|
+
}, [setChildInstances]);
|
|
14
36
|
if (childEntity === undefined || !isSerializedEntityDecl(childEntity)) {
|
|
15
37
|
return (_jsxs("div", { role: "alert", children: ["Unresolved entity declaration identifier ", _jsx("code", { children: type.entity })] }));
|
|
16
38
|
}
|
|
@@ -21,7 +43,9 @@ export const ChildEntitiesTypeInput = props => {
|
|
|
21
43
|
onChildRemove(i);
|
|
22
44
|
}, disabled: disabled, children: "Delete Item" })] }), _jsx(TypeInput, { ...props, type: childEntity.type, value: item.content, parentKey: childEntity.parentReferenceKey, onChange: newItem => {
|
|
23
45
|
onChildChange(originalIndex, newItem);
|
|
24
|
-
}, childInstances: item.childInstances
|
|
46
|
+
}, childInstances: item.childInstances, setChildInstances: newChildInstances => {
|
|
47
|
+
onGrandChildrenChange(originalIndex, newChildInstances);
|
|
48
|
+
} })] }, i))) })) : (_jsx("p", { class: "empty", children: "No child entities" })), _jsx("div", { class: "add-item-container", children: _jsx("button", { onClick: () => {
|
|
25
49
|
onChildAdd(type.entity, createTypeSkeleton(getDeclFromDeclName, childEntity.type));
|
|
26
50
|
}, disabled: disabled, children: "Add Item" }) })] }));
|
|
27
51
|
};
|
|
@@ -13,9 +13,7 @@ export type TypeInputProps<T, V = unknown> = {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
getDeclFromDeclName: GetDeclFromDeclName;
|
|
15
15
|
onChange: (value: V) => void;
|
|
16
|
-
|
|
17
|
-
onChildAdd: (entityName: string, value: unknown) => void;
|
|
18
|
-
onChildRemove: (index: number) => void;
|
|
16
|
+
setChildInstances: (newInstances: (oldInstances: UnsafeEntityTaggedInstanceContainerWithChildInstances[]) => UnsafeEntityTaggedInstanceContainerWithChildInstances[]) => void;
|
|
19
17
|
checkIsLocaleEntity: (entityName: string) => boolean;
|
|
20
18
|
};
|
|
21
19
|
type Props = TypeInputProps<SerializedType>;
|