@case-framework/survey-core 0.4.1 → 0.5.0
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/build/editor/colors.d.mts +12 -0
- package/build/editor/colors.d.mts.map +1 -0
- package/build/editor/colors.mjs +25 -0
- package/build/editor/colors.mjs.map +1 -0
- package/build/editor.d.mts +5 -80
- package/build/editor.d.mts.map +1 -1
- package/build/editor.mjs +68 -312
- package/build/editor.mjs.map +1 -1
- package/build/index.d.mts +33 -2
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +177 -2
- package/build/index.mjs.map +1 -1
- package/build/package.json +5 -1
- package/build/{survey-BV8YHc3J.d.mts → survey-DZ3RHkd2.d.mts} +10 -1
- package/build/{survey-BV8YHc3J.d.mts.map → survey-DZ3RHkd2.d.mts.map} +1 -1
- package/build/{survey-DnLtf19j.mjs → survey-Dxt6iolo.mjs} +23 -1
- package/build/{survey-DnLtf19j.mjs.map → survey-Dxt6iolo.mjs.map} +1 -1
- package/package.json +5 -1
package/build/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { $ as generateId, A as DurationUnits, B as ConstExpression, C as ReservedSurveyItemTypes, D as deserializeSurveyItemPrefill, E as SurveyItemPrefillTargetType, F as TemplateDefTypes, G as FunctionExpression, H as ContextVariableType, I as deserializeTemplateValue, J as ReferenceUsageType, K as FunctionExpressionNames, L as deserializeTemplateValues, M as ValueType, N as assertResponseValue, O as prefillTargetsEqual, P as isResponseValue, Q as generateCodingKey, R as serializeTemplateValue, S as SurveyItemKey, T as SurveyItemPrefillApplyMode, U as Expression, V as ContextVariableExpression, W as ExpressionType, X as ValueReferenceMethod, Y as ValueReference, Z as createSeededRandom, _ as toItemTypeDefinitionRegistry, a as getContentPlainText, b as builtInItemCoreRegistry, c as hasRenderableRichTextContent, d as SurveyTranslations, et as shuffleArray, f as validateLocale, g as createItemTypeDefinitionRegistry, h as createItemCore, i as getAssetUsagesFromContent, j as NumberPrecision, k as serializeSurveyItemPrefill, l as isContentEmpty, m as createFullRegistry, n as ContentType, nt as structuredCloneMethod, o as getPlainTextFromRichTextContent, p as CURRENT_SURVEY_SCHEMA, q as ResponseVariableExpression, r as createRichTextContent, s as hasRenderableRichTextBlock, t as Survey, tt as shuffleIndices, u as SurveyItemTranslations, v as GroupItemCore, w as SurveyItemCore, x as isBuiltInItemType, y as PageBreakItemCore, z as serializeTemplateValues } from "./survey-
|
|
1
|
+
import { $ as generateId, A as DurationUnits, B as ConstExpression, C as ReservedSurveyItemTypes, D as deserializeSurveyItemPrefill, E as SurveyItemPrefillTargetType, F as TemplateDefTypes, G as FunctionExpression, H as ContextVariableType, I as deserializeTemplateValue, J as ReferenceUsageType, K as FunctionExpressionNames, L as deserializeTemplateValues, M as ValueType, N as assertResponseValue, O as prefillTargetsEqual, P as isResponseValue, Q as generateCodingKey, R as serializeTemplateValue, S as SurveyItemKey, T as SurveyItemPrefillApplyMode, U as Expression, V as ContextVariableExpression, W as ExpressionType, X as ValueReferenceMethod, Y as ValueReference, Z as createSeededRandom, _ as toItemTypeDefinitionRegistry, a as getContentPlainText, b as builtInItemCoreRegistry, c as hasRenderableRichTextContent, d as SurveyTranslations, et as shuffleArray, f as validateLocale, g as createItemTypeDefinitionRegistry, h as createItemCore, i as getAssetUsagesFromContent, j as NumberPrecision, k as serializeSurveyItemPrefill, l as isContentEmpty, m as createFullRegistry, n as ContentType, nt as structuredCloneMethod, o as getPlainTextFromRichTextContent, p as CURRENT_SURVEY_SCHEMA, q as ResponseVariableExpression, r as createRichTextContent, s as hasRenderableRichTextBlock, t as Survey, tt as shuffleIndices, u as SurveyItemTranslations, v as GroupItemCore, w as SurveyItemCore, x as isBuiltInItemType, y as PageBreakItemCore, z as serializeTemplateValues } from "./survey-Dxt6iolo.mjs";
|
|
2
|
+
import { SURVEY_EDITOR_ITEM_COLORS } from "./editor/colors.mjs";
|
|
2
3
|
import { format } from "date-fns";
|
|
3
4
|
import { enUS } from "date-fns/locale";
|
|
4
5
|
//#region src/to_mirgrate/data_types/legacy-types.ts
|
|
@@ -1654,6 +1655,180 @@ const flattenTree = (itemTree) => {
|
|
|
1654
1655
|
return flatTree;
|
|
1655
1656
|
};
|
|
1656
1657
|
//#endregion
|
|
1658
|
+
//#region src/json-patch.ts
|
|
1659
|
+
var JsonPatchError = class extends Error {
|
|
1660
|
+
constructor(message, code, path, operationIndex) {
|
|
1661
|
+
super(message);
|
|
1662
|
+
this.code = code;
|
|
1663
|
+
this.path = path;
|
|
1664
|
+
this.operationIndex = operationIndex;
|
|
1665
|
+
this.name = "JsonPatchError";
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
1669
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1670
|
+
const assertValidPointerSegment = (segment, pointer) => {
|
|
1671
|
+
if (/~(?![01])/.test(segment)) throw new JsonPatchError(`Invalid JSON pointer segment "${segment}" in "${pointer}". Only "~0" and "~1" escapes are allowed.`, "invalid-json-pointer", pointer);
|
|
1672
|
+
};
|
|
1673
|
+
const decodeJsonPointerSegment = (segment) => {
|
|
1674
|
+
assertValidPointerSegment(segment, segment);
|
|
1675
|
+
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
1676
|
+
};
|
|
1677
|
+
const encodeJsonPointerSegment = (segment) => segment.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
1678
|
+
const parseJsonPointer = (pointer) => {
|
|
1679
|
+
if (pointer === "") return [];
|
|
1680
|
+
if (!pointer.startsWith("/")) throw new JsonPatchError(`Invalid JSON pointer "${pointer}". It must be empty or start with "/".`, "invalid-json-pointer", pointer);
|
|
1681
|
+
return pointer.slice(1).split("/").map((segment) => {
|
|
1682
|
+
assertValidPointerSegment(segment, pointer);
|
|
1683
|
+
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
1684
|
+
});
|
|
1685
|
+
};
|
|
1686
|
+
const parseArrayIndex = ({ segment, arrayLength, allowAppend, allowEnd, path }) => {
|
|
1687
|
+
if (segment === "-") {
|
|
1688
|
+
if (allowAppend) return arrayLength;
|
|
1689
|
+
throw new JsonPatchError(`JSON pointer "${path}" uses "-" where an existing array index is required.`, "invalid-array-index", path);
|
|
1690
|
+
}
|
|
1691
|
+
if (!/^(0|[1-9][0-9]*)$/.test(segment)) throw new JsonPatchError(`JSON pointer "${path}" uses invalid array index "${segment}".`, "invalid-array-index", path);
|
|
1692
|
+
const index = Number(segment);
|
|
1693
|
+
const maximum = allowEnd ? arrayLength : arrayLength - 1;
|
|
1694
|
+
if (index < 0 || index > maximum) throw new JsonPatchError(`JSON pointer "${path}" array index ${index} is out of bounds.`, "array-index-out-of-bounds", path);
|
|
1695
|
+
return index;
|
|
1696
|
+
};
|
|
1697
|
+
const getValueAtSegments = (document, segments, path) => {
|
|
1698
|
+
let current = document;
|
|
1699
|
+
for (const segment of segments) {
|
|
1700
|
+
if (Array.isArray(current)) {
|
|
1701
|
+
const index = parseArrayIndex({
|
|
1702
|
+
segment,
|
|
1703
|
+
arrayLength: current.length,
|
|
1704
|
+
allowAppend: false,
|
|
1705
|
+
allowEnd: false,
|
|
1706
|
+
path
|
|
1707
|
+
});
|
|
1708
|
+
current = current[index];
|
|
1709
|
+
continue;
|
|
1710
|
+
}
|
|
1711
|
+
if (!isRecord(current) || !hasOwn(current, segment)) throw new JsonPatchError(`JSON pointer "${path}" does not exist.`, "path-not-found", path);
|
|
1712
|
+
current = current[segment];
|
|
1713
|
+
}
|
|
1714
|
+
return current;
|
|
1715
|
+
};
|
|
1716
|
+
const getValueAtJsonPointer = (document, pointer) => {
|
|
1717
|
+
return getValueAtSegments(document, parseJsonPointer(pointer), pointer);
|
|
1718
|
+
};
|
|
1719
|
+
const deepEqualJson = (left, right) => {
|
|
1720
|
+
if (left === right) return true;
|
|
1721
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
1722
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
1723
|
+
return left.every((entry, index) => deepEqualJson(entry, right[index]));
|
|
1724
|
+
}
|
|
1725
|
+
if (isRecord(left) || isRecord(right)) {
|
|
1726
|
+
if (!isRecord(left) || !isRecord(right)) return false;
|
|
1727
|
+
const leftKeys = Object.keys(left).sort();
|
|
1728
|
+
const rightKeys = Object.keys(right).sort();
|
|
1729
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
1730
|
+
return leftKeys.every((key, index) => key === rightKeys[index] && deepEqualJson(left[key], right[key]));
|
|
1731
|
+
}
|
|
1732
|
+
return false;
|
|
1733
|
+
};
|
|
1734
|
+
const applyAdd = (document, path, value) => {
|
|
1735
|
+
const segments = parseJsonPointer(path);
|
|
1736
|
+
if (segments.length === 0) return structuredCloneMethod(value);
|
|
1737
|
+
const parentSegments = segments.slice(0, -1);
|
|
1738
|
+
const key = segments[segments.length - 1];
|
|
1739
|
+
const parent = getValueAtSegments(document, parentSegments, path);
|
|
1740
|
+
if (Array.isArray(parent)) {
|
|
1741
|
+
const index = parseArrayIndex({
|
|
1742
|
+
segment: key,
|
|
1743
|
+
arrayLength: parent.length,
|
|
1744
|
+
allowAppend: true,
|
|
1745
|
+
allowEnd: true,
|
|
1746
|
+
path
|
|
1747
|
+
});
|
|
1748
|
+
parent.splice(index, 0, structuredCloneMethod(value));
|
|
1749
|
+
return document;
|
|
1750
|
+
}
|
|
1751
|
+
if (!isRecord(parent)) throw new JsonPatchError(`JSON pointer "${path}" parent is not an object or array.`, "invalid-target-parent", path);
|
|
1752
|
+
parent[key] = structuredCloneMethod(value);
|
|
1753
|
+
return document;
|
|
1754
|
+
};
|
|
1755
|
+
const applyRemove = (document, path) => {
|
|
1756
|
+
const segments = parseJsonPointer(path);
|
|
1757
|
+
if (segments.length === 0) throw new JsonPatchError("Removing the document root is not supported.", "remove-root", path);
|
|
1758
|
+
const parentSegments = segments.slice(0, -1);
|
|
1759
|
+
const key = segments[segments.length - 1];
|
|
1760
|
+
const parent = getValueAtSegments(document, parentSegments, path);
|
|
1761
|
+
if (Array.isArray(parent)) {
|
|
1762
|
+
const index = parseArrayIndex({
|
|
1763
|
+
segment: key,
|
|
1764
|
+
arrayLength: parent.length,
|
|
1765
|
+
allowAppend: false,
|
|
1766
|
+
allowEnd: false,
|
|
1767
|
+
path
|
|
1768
|
+
});
|
|
1769
|
+
const [removedValue] = parent.splice(index, 1);
|
|
1770
|
+
return {
|
|
1771
|
+
document,
|
|
1772
|
+
removedValue
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
if (!isRecord(parent) || !hasOwn(parent, key)) throw new JsonPatchError(`JSON pointer "${path}" does not exist.`, "path-not-found", path);
|
|
1776
|
+
const removedValue = parent[key];
|
|
1777
|
+
delete parent[key];
|
|
1778
|
+
return {
|
|
1779
|
+
document,
|
|
1780
|
+
removedValue
|
|
1781
|
+
};
|
|
1782
|
+
};
|
|
1783
|
+
const applyReplace = (document, path, value) => {
|
|
1784
|
+
const segments = parseJsonPointer(path);
|
|
1785
|
+
if (segments.length === 0) return structuredCloneMethod(value);
|
|
1786
|
+
getValueAtSegments(document, segments, path);
|
|
1787
|
+
applyRemove(document, path);
|
|
1788
|
+
return applyAdd(document, path, value);
|
|
1789
|
+
};
|
|
1790
|
+
const assertMoveTargetIsNotDescendant = (from, path) => {
|
|
1791
|
+
if (from === "" || path === from || !path.startsWith(`${from}/`)) return;
|
|
1792
|
+
throw new JsonPatchError(`JSON Patch cannot move "${from}" into its own descendant "${path}".`, "move-into-descendant", path);
|
|
1793
|
+
};
|
|
1794
|
+
const applyJsonPatch = (document, operations) => {
|
|
1795
|
+
let patchedDocument = structuredCloneMethod(document);
|
|
1796
|
+
operations.forEach((operation, operationIndex) => {
|
|
1797
|
+
try {
|
|
1798
|
+
switch (operation.op) {
|
|
1799
|
+
case "add":
|
|
1800
|
+
patchedDocument = applyAdd(patchedDocument, operation.path, operation.value);
|
|
1801
|
+
break;
|
|
1802
|
+
case "remove":
|
|
1803
|
+
patchedDocument = applyRemove(patchedDocument, operation.path).document;
|
|
1804
|
+
break;
|
|
1805
|
+
case "replace":
|
|
1806
|
+
patchedDocument = applyReplace(patchedDocument, operation.path, operation.value);
|
|
1807
|
+
break;
|
|
1808
|
+
case "move": {
|
|
1809
|
+
assertMoveTargetIsNotDescendant(operation.from, operation.path);
|
|
1810
|
+
if (operation.from === operation.path) break;
|
|
1811
|
+
const { document: withoutValue, removedValue } = applyRemove(patchedDocument, operation.from);
|
|
1812
|
+
patchedDocument = applyAdd(withoutValue, operation.path, removedValue);
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1815
|
+
case "copy": {
|
|
1816
|
+
const value = getValueAtJsonPointer(patchedDocument, operation.from);
|
|
1817
|
+
patchedDocument = applyAdd(patchedDocument, operation.path, value);
|
|
1818
|
+
break;
|
|
1819
|
+
}
|
|
1820
|
+
case "test":
|
|
1821
|
+
if (!deepEqualJson(getValueAtJsonPointer(patchedDocument, operation.path), operation.value)) throw new JsonPatchError(`JSON Patch test failed at "${operation.path}".`, "test-failed", operation.path);
|
|
1822
|
+
break;
|
|
1823
|
+
}
|
|
1824
|
+
} catch (error) {
|
|
1825
|
+
if (error instanceof JsonPatchError) throw new JsonPatchError(error.message, error.code, error.path, operationIndex);
|
|
1826
|
+
throw error;
|
|
1827
|
+
}
|
|
1828
|
+
});
|
|
1829
|
+
return patchedDocument;
|
|
1830
|
+
};
|
|
1831
|
+
//#endregion
|
|
1657
1832
|
//#region src/response-exporter/types.ts
|
|
1658
1833
|
/** Meta column keys in fixed order (common attributes first). */
|
|
1659
1834
|
const META_COLUMN_ORDER = [
|
|
@@ -2006,6 +2181,6 @@ function generateCodebook(survey, options) {
|
|
|
2006
2181
|
};
|
|
2007
2182
|
}
|
|
2008
2183
|
//#endregion
|
|
2009
|
-
export { AndExpressionEditor, CURRENT_SURVEY_SCHEMA, ConstBooleanEditor, ConstDateArrayEditor, ConstDateEditor, ConstExpression, ConstNumberArrayEditor, ConstNumberEditor, ConstStringArrayEditor, ConstStringEditor, ContentType, ContextVariableExpression, ContextVariableType, CtxCustomExpressionEditor, CtxCustomValueEditor, CtxLocaleEditor, CtxPFlagDateEditor, CtxPFlagIsDefinedEditor, CtxPFlagNumEditor, CtxPFlagStringEditor, DEFAULT_TRANSFORM, DurationUnits, EXPORT_COLUMN_SLOT_SEPARATOR, EqExpressionEditor, Expression, ExpressionEditor, ExpressionEvaluator, ExpressionType, FunctionExpression, FunctionExpressionNames, GroupItemCore, GtExpressionEditor, GteExpressionEditor, InRangeExpressionEditor, LtExpressionEditor, LteExpressionEditor, META_COLUMN_ORDER, MaxExpressionEditor, MinExpressionEditor, NumberPrecision, OrExpressionEditor, PageBreakItemCore, ReferenceUsageType, ReservedSurveyItemTypes, ResponseItem, ResponseVariableEditor, ResponseVariableExpression, SURVEY_RESPONSE_SCHEMA_VERSION, SlotTransformMode, StrEqExpressionEditor, StrListContainsExpressionEditor, SumExpressionEditor, Survey, SurveyEngineCore, SurveyEventTypes, SurveyItemCore, SurveyItemKey, SurveyItemPrefillApplyMode, SurveyItemPrefillTargetType, SurveyItemResponse, SurveyItemTranslations, SurveyResponse, SurveyResponseExporter, SurveyTranslations, TemplateDefTypes, ValueReference, ValueReferenceMethod, ValueType, and, assertResponseValue, buildItemExpression, builtInItemCoreRegistry, const_boolean, const_date, const_date_array, const_number, const_number_array, const_string, const_string_array, createFullRegistry, createItemCore, createItemTypeDefinitionRegistry, createRichTextContent, createSeededRandom, ctx_custom_expression, ctx_custom_value, ctx_locale, ctx_pflag_date, ctx_pflag_is_defined, ctx_pflag_num, ctx_pflag_string, deserializeSurveyItemPrefill, deserializeTemplateValue, deserializeTemplateValues, eq, escapeCsvCell, exportSingleResponseSlot, flattenTree, generateCodebook, generateCodingKey, generateId, getAssetUsagesFromContent, getContentPlainText, getItemExpressionDefinition, getPlainTextFromRichTextContent, gt, gte, hasRenderableRichTextBlock, hasRenderableRichTextContent, in_range, initValueForType, isBuiltInItemType, isContentEmpty, isLegacyItemGroupComponent, isLegacySurveyGroupItem, isResponseValue, lt, lte, max, min, or, prefillTargetsEqual, response_boolean, response_date, response_date_array, response_number, response_number_array, response_string, response_string_array, serializeSurveyItemPrefill, serializeTemplateValue, serializeTemplateValues, serializeToCsv, shuffleArray, shuffleIndices, str_eq, str_list_contains, structuredCloneMethod, sum, toItemTypeDefinitionRegistry, validateLocale };
|
|
2184
|
+
export { AndExpressionEditor, CURRENT_SURVEY_SCHEMA, ConstBooleanEditor, ConstDateArrayEditor, ConstDateEditor, ConstExpression, ConstNumberArrayEditor, ConstNumberEditor, ConstStringArrayEditor, ConstStringEditor, ContentType, ContextVariableExpression, ContextVariableType, CtxCustomExpressionEditor, CtxCustomValueEditor, CtxLocaleEditor, CtxPFlagDateEditor, CtxPFlagIsDefinedEditor, CtxPFlagNumEditor, CtxPFlagStringEditor, DEFAULT_TRANSFORM, DurationUnits, EXPORT_COLUMN_SLOT_SEPARATOR, EqExpressionEditor, Expression, ExpressionEditor, ExpressionEvaluator, ExpressionType, FunctionExpression, FunctionExpressionNames, GroupItemCore, GtExpressionEditor, GteExpressionEditor, InRangeExpressionEditor, JsonPatchError, LtExpressionEditor, LteExpressionEditor, META_COLUMN_ORDER, MaxExpressionEditor, MinExpressionEditor, NumberPrecision, OrExpressionEditor, PageBreakItemCore, ReferenceUsageType, ReservedSurveyItemTypes, ResponseItem, ResponseVariableEditor, ResponseVariableExpression, SURVEY_EDITOR_ITEM_COLORS, SURVEY_RESPONSE_SCHEMA_VERSION, SlotTransformMode, StrEqExpressionEditor, StrListContainsExpressionEditor, SumExpressionEditor, Survey, SurveyEngineCore, SurveyEventTypes, SurveyItemCore, SurveyItemKey, SurveyItemPrefillApplyMode, SurveyItemPrefillTargetType, SurveyItemResponse, SurveyItemTranslations, SurveyResponse, SurveyResponseExporter, SurveyTranslations, TemplateDefTypes, ValueReference, ValueReferenceMethod, ValueType, and, applyJsonPatch, assertResponseValue, buildItemExpression, builtInItemCoreRegistry, const_boolean, const_date, const_date_array, const_number, const_number_array, const_string, const_string_array, createFullRegistry, createItemCore, createItemTypeDefinitionRegistry, createRichTextContent, createSeededRandom, ctx_custom_expression, ctx_custom_value, ctx_locale, ctx_pflag_date, ctx_pflag_is_defined, ctx_pflag_num, ctx_pflag_string, decodeJsonPointerSegment, deserializeSurveyItemPrefill, deserializeTemplateValue, deserializeTemplateValues, encodeJsonPointerSegment, eq, escapeCsvCell, exportSingleResponseSlot, flattenTree, generateCodebook, generateCodingKey, generateId, getAssetUsagesFromContent, getContentPlainText, getItemExpressionDefinition, getPlainTextFromRichTextContent, getValueAtJsonPointer, gt, gte, hasRenderableRichTextBlock, hasRenderableRichTextContent, in_range, initValueForType, isBuiltInItemType, isContentEmpty, isLegacyItemGroupComponent, isLegacySurveyGroupItem, isResponseValue, lt, lte, max, min, or, parseJsonPointer, prefillTargetsEqual, response_boolean, response_date, response_date_array, response_number, response_number_array, response_string, response_string_array, serializeSurveyItemPrefill, serializeTemplateValue, serializeTemplateValues, serializeToCsv, shuffleArray, shuffleIndices, str_eq, str_list_contains, structuredCloneMethod, sum, toItemTypeDefinitionRegistry, validateLocale };
|
|
2010
2185
|
|
|
2011
2186
|
//# sourceMappingURL=index.mjs.map
|