@dmitryvim/form-builder 0.2.14 → 0.2.16
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/browser/formbuilder.min.js +65 -69
- package/dist/browser/formbuilder.v0.2.16.min.js +358 -0
- package/dist/cjs/index.cjs +34 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +33 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +65 -69
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.14.min.js +0 -362
package/dist/cjs/index.cjs
CHANGED
|
@@ -1589,8 +1589,7 @@ function renderLocalVideoPreview(container, file, videoType, resourceId, state,
|
|
|
1589
1589
|
}
|
|
1590
1590
|
newContainer.innerHTML = `
|
|
1591
1591
|
<div class="relative group h-full">
|
|
1592
|
-
<video class="w-full h-full object-contain" controls preload="auto" muted>
|
|
1593
|
-
<source src="${videoUrl}" type="${videoType}">
|
|
1592
|
+
<video class="w-full h-full object-contain" controls preload="auto" muted src="${videoUrl}">
|
|
1594
1593
|
${escapeHtml(t("videoNotSupported", state))}
|
|
1595
1594
|
</video>
|
|
1596
1595
|
<div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
|
|
@@ -1652,16 +1651,13 @@ function handleVideoDelete(container, resourceId, state, deps) {
|
|
|
1652
1651
|
</div>
|
|
1653
1652
|
`;
|
|
1654
1653
|
}
|
|
1655
|
-
function renderUploadedVideoPreview(container, thumbnailUrl,
|
|
1654
|
+
function renderUploadedVideoPreview(container, thumbnailUrl, _videoType, state) {
|
|
1656
1655
|
const video = document.createElement("video");
|
|
1657
1656
|
video.className = "w-full h-full object-contain";
|
|
1658
1657
|
video.controls = true;
|
|
1659
1658
|
video.preload = "metadata";
|
|
1660
1659
|
video.muted = true;
|
|
1661
|
-
|
|
1662
|
-
source.src = thumbnailUrl;
|
|
1663
|
-
source.type = videoType;
|
|
1664
|
-
video.appendChild(source);
|
|
1660
|
+
video.src = thumbnailUrl;
|
|
1665
1661
|
video.appendChild(
|
|
1666
1662
|
document.createTextNode(t("videoNotSupported", state))
|
|
1667
1663
|
);
|
|
@@ -1813,8 +1809,7 @@ async function renderFilePreviewReadonly(resourceId, state, fileName) {
|
|
|
1813
1809
|
if (videoUrl) {
|
|
1814
1810
|
previewContainer.innerHTML = `
|
|
1815
1811
|
<div class="relative group">
|
|
1816
|
-
<video class="w-full h-auto" controls preload="auto" muted>
|
|
1817
|
-
<source src="${videoUrl}" type="${(meta == null ? void 0 : meta.type) || "video/mp4"}">
|
|
1812
|
+
<video class="w-full h-auto" controls preload="auto" muted src="${videoUrl}">
|
|
1818
1813
|
${escapeHtml(t("videoNotSupported", state))}
|
|
1819
1814
|
</video>
|
|
1820
1815
|
<div class="absolute inset-0 bg-black bg-opacity-20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
|
|
@@ -2038,8 +2033,7 @@ async function renderThumbnailForResource(slot, rid, meta, state) {
|
|
|
2038
2033
|
const videoUrl = URL.createObjectURL(meta.file);
|
|
2039
2034
|
slot.innerHTML = `
|
|
2040
2035
|
<div class="relative group h-full w-full">
|
|
2041
|
-
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
2042
|
-
<source src="${videoUrl}" type="${meta.type}">
|
|
2036
|
+
<video class="w-full h-full object-contain" preload="metadata" muted src="${videoUrl}">
|
|
2043
2037
|
</video>
|
|
2044
2038
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
2045
2039
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -2056,8 +2050,7 @@ async function renderThumbnailForResource(slot, rid, meta, state) {
|
|
|
2056
2050
|
if (videoUrl) {
|
|
2057
2051
|
slot.innerHTML = `
|
|
2058
2052
|
<div class="relative group h-full w-full">
|
|
2059
|
-
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
2060
|
-
<source src="${videoUrl}" type="${meta.type}">
|
|
2053
|
+
<video class="w-full h-full object-contain" preload="metadata" muted src="${videoUrl}">
|
|
2061
2054
|
</video>
|
|
2062
2055
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
2063
2056
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -3746,6 +3739,18 @@ function updateSliderField(element, fieldPath, value, context) {
|
|
|
3746
3739
|
}
|
|
3747
3740
|
|
|
3748
3741
|
// src/components/container.ts
|
|
3742
|
+
function extractChildDefaults(elements) {
|
|
3743
|
+
const defaults = {};
|
|
3744
|
+
for (const child of elements) {
|
|
3745
|
+
if ("default" in child && child.default !== void 0) {
|
|
3746
|
+
defaults[child.key] = child.default;
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
return defaults;
|
|
3750
|
+
}
|
|
3751
|
+
function mergeWithDefaults(prefill, defaults) {
|
|
3752
|
+
return { ...defaults, ...prefill };
|
|
3753
|
+
}
|
|
3749
3754
|
function extractRootFormData(formRoot) {
|
|
3750
3755
|
const data = {};
|
|
3751
3756
|
const inputs = formRoot.querySelectorAll(
|
|
@@ -3821,10 +3826,13 @@ function renderSingleContainerElement(element, ctx, wrapper, pathKey) {
|
|
|
3821
3826
|
containerWrap.appendChild(hintsElement);
|
|
3822
3827
|
}
|
|
3823
3828
|
}
|
|
3829
|
+
const childDefaults = extractChildDefaults(element.elements);
|
|
3830
|
+
const containerPrefill = ((_a = ctx.prefill) == null ? void 0 : _a[element.key]) || {};
|
|
3831
|
+
const mergedPrefill = mergeWithDefaults(containerPrefill, childDefaults);
|
|
3824
3832
|
const subCtx = {
|
|
3825
3833
|
path: pathJoin(ctx.path, element.key),
|
|
3826
|
-
prefill:
|
|
3827
|
-
//
|
|
3834
|
+
prefill: mergedPrefill,
|
|
3835
|
+
// Merged prefill with defaults for enableIf evaluation
|
|
3828
3836
|
formData: (_b = ctx.formData) != null ? _b : ctx.prefill,
|
|
3829
3837
|
// Complete root data for enableIf evaluation
|
|
3830
3838
|
state: ctx.state
|
|
@@ -3855,6 +3863,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3855
3863
|
const min = (_a = element.minCount) != null ? _a : 0;
|
|
3856
3864
|
const max = (_b = element.maxCount) != null ? _b : Infinity;
|
|
3857
3865
|
const pre = Array.isArray((_c = ctx.prefill) == null ? void 0 : _c[element.key]) ? ctx.prefill[element.key] : null;
|
|
3866
|
+
const childDefaults = extractChildDefaults(element.elements);
|
|
3858
3867
|
const countItems = () => itemsWrap.querySelectorAll(":scope > .containerItem").length;
|
|
3859
3868
|
const createAddButton = () => {
|
|
3860
3869
|
const add = document.createElement("button");
|
|
@@ -3881,7 +3890,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3881
3890
|
const subCtx = {
|
|
3882
3891
|
state: ctx.state,
|
|
3883
3892
|
path: pathJoin(ctx.path, `${element.key}[${idx}]`),
|
|
3884
|
-
prefill:
|
|
3893
|
+
prefill: childDefaults,
|
|
3894
|
+
// Defaults for enableIf evaluation
|
|
3885
3895
|
formData: currentFormData
|
|
3886
3896
|
// Current root data from DOM for enableIf
|
|
3887
3897
|
};
|
|
@@ -3945,10 +3955,12 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3945
3955
|
if (pre && Array.isArray(pre)) {
|
|
3946
3956
|
pre.forEach((prefillObj, idx) => {
|
|
3947
3957
|
var _a2;
|
|
3958
|
+
const mergedPrefill = mergeWithDefaults(prefillObj || {}, childDefaults);
|
|
3948
3959
|
const subCtx = {
|
|
3949
3960
|
state: ctx.state,
|
|
3950
3961
|
path: pathJoin(ctx.path, `${element.key}[${idx}]`),
|
|
3951
|
-
prefill:
|
|
3962
|
+
prefill: mergedPrefill,
|
|
3963
|
+
// Merged prefill with defaults for enableIf
|
|
3952
3964
|
formData: (_a2 = ctx.formData) != null ? _a2 : ctx.prefill
|
|
3953
3965
|
// Complete root data for enableIf
|
|
3954
3966
|
};
|
|
@@ -4000,7 +4012,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
4000
4012
|
const subCtx = {
|
|
4001
4013
|
state: ctx.state,
|
|
4002
4014
|
path: pathJoin(ctx.path, `${element.key}[${idx}]`),
|
|
4003
|
-
prefill:
|
|
4015
|
+
prefill: childDefaults,
|
|
4016
|
+
// Defaults for enableIf evaluation
|
|
4004
4017
|
formData: (_d = ctx.formData) != null ? _d : ctx.prefill
|
|
4005
4018
|
// Complete root data for enableIf
|
|
4006
4019
|
};
|
|
@@ -4355,13 +4368,14 @@ if (typeof document !== "undefined") {
|
|
|
4355
4368
|
});
|
|
4356
4369
|
}
|
|
4357
4370
|
function shouldDisableElement(element, ctx) {
|
|
4358
|
-
var _a, _b;
|
|
4371
|
+
var _a, _b, _c;
|
|
4359
4372
|
if (!element.enableIf) {
|
|
4360
4373
|
return false;
|
|
4361
4374
|
}
|
|
4362
4375
|
try {
|
|
4363
4376
|
const rootFormData = (_b = (_a = ctx.formData) != null ? _a : ctx.prefill) != null ? _b : {};
|
|
4364
|
-
const
|
|
4377
|
+
const scope = (_c = element.enableIf.scope) != null ? _c : "relative";
|
|
4378
|
+
const containerData = scope === "relative" && ctx.path ? ctx.prefill : void 0;
|
|
4365
4379
|
const shouldEnable = evaluateEnableCondition(
|
|
4366
4380
|
element.enableIf,
|
|
4367
4381
|
rootFormData,
|