@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/esm/index.js
CHANGED
|
@@ -1567,8 +1567,7 @@ function renderLocalVideoPreview(container, file, videoType, resourceId, state,
|
|
|
1567
1567
|
}
|
|
1568
1568
|
newContainer.innerHTML = `
|
|
1569
1569
|
<div class="relative group h-full">
|
|
1570
|
-
<video class="w-full h-full object-contain" controls preload="auto" muted>
|
|
1571
|
-
<source src="${videoUrl}" type="${videoType}">
|
|
1570
|
+
<video class="w-full h-full object-contain" controls preload="auto" muted src="${videoUrl}">
|
|
1572
1571
|
${escapeHtml(t("videoNotSupported", state))}
|
|
1573
1572
|
</video>
|
|
1574
1573
|
<div class="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10 flex gap-1">
|
|
@@ -1629,16 +1628,13 @@ function handleVideoDelete(container, resourceId, state, deps) {
|
|
|
1629
1628
|
</div>
|
|
1630
1629
|
`;
|
|
1631
1630
|
}
|
|
1632
|
-
function renderUploadedVideoPreview(container, thumbnailUrl,
|
|
1631
|
+
function renderUploadedVideoPreview(container, thumbnailUrl, _videoType, state) {
|
|
1633
1632
|
const video = document.createElement("video");
|
|
1634
1633
|
video.className = "w-full h-full object-contain";
|
|
1635
1634
|
video.controls = true;
|
|
1636
1635
|
video.preload = "metadata";
|
|
1637
1636
|
video.muted = true;
|
|
1638
|
-
|
|
1639
|
-
source.src = thumbnailUrl;
|
|
1640
|
-
source.type = videoType;
|
|
1641
|
-
video.appendChild(source);
|
|
1637
|
+
video.src = thumbnailUrl;
|
|
1642
1638
|
video.appendChild(
|
|
1643
1639
|
document.createTextNode(t("videoNotSupported", state))
|
|
1644
1640
|
);
|
|
@@ -1788,8 +1784,7 @@ async function renderFilePreviewReadonly(resourceId, state, fileName) {
|
|
|
1788
1784
|
if (videoUrl) {
|
|
1789
1785
|
previewContainer.innerHTML = `
|
|
1790
1786
|
<div class="relative group">
|
|
1791
|
-
<video class="w-full h-auto" controls preload="auto" muted>
|
|
1792
|
-
<source src="${videoUrl}" type="${meta?.type || "video/mp4"}">
|
|
1787
|
+
<video class="w-full h-auto" controls preload="auto" muted src="${videoUrl}">
|
|
1793
1788
|
${escapeHtml(t("videoNotSupported", state))}
|
|
1794
1789
|
</video>
|
|
1795
1790
|
<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">
|
|
@@ -2011,8 +2006,7 @@ async function renderThumbnailForResource(slot, rid, meta, state) {
|
|
|
2011
2006
|
const videoUrl = URL.createObjectURL(meta.file);
|
|
2012
2007
|
slot.innerHTML = `
|
|
2013
2008
|
<div class="relative group h-full w-full">
|
|
2014
|
-
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
2015
|
-
<source src="${videoUrl}" type="${meta.type}">
|
|
2009
|
+
<video class="w-full h-full object-contain" preload="metadata" muted src="${videoUrl}">
|
|
2016
2010
|
</video>
|
|
2017
2011
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
2018
2012
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -2029,8 +2023,7 @@ async function renderThumbnailForResource(slot, rid, meta, state) {
|
|
|
2029
2023
|
if (videoUrl) {
|
|
2030
2024
|
slot.innerHTML = `
|
|
2031
2025
|
<div class="relative group h-full w-full">
|
|
2032
|
-
<video class="w-full h-full object-contain" preload="metadata" muted>
|
|
2033
|
-
<source src="${videoUrl}" type="${meta.type}">
|
|
2026
|
+
<video class="w-full h-full object-contain" preload="metadata" muted src="${videoUrl}">
|
|
2034
2027
|
</video>
|
|
2035
2028
|
<div class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center">
|
|
2036
2029
|
<div class="bg-white bg-opacity-90 rounded-full p-1">
|
|
@@ -3698,6 +3691,18 @@ function updateSliderField(element, fieldPath, value, context) {
|
|
|
3698
3691
|
}
|
|
3699
3692
|
|
|
3700
3693
|
// src/components/container.ts
|
|
3694
|
+
function extractChildDefaults(elements) {
|
|
3695
|
+
const defaults = {};
|
|
3696
|
+
for (const child of elements) {
|
|
3697
|
+
if ("default" in child && child.default !== void 0) {
|
|
3698
|
+
defaults[child.key] = child.default;
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
return defaults;
|
|
3702
|
+
}
|
|
3703
|
+
function mergeWithDefaults(prefill, defaults) {
|
|
3704
|
+
return { ...defaults, ...prefill };
|
|
3705
|
+
}
|
|
3701
3706
|
function extractRootFormData(formRoot) {
|
|
3702
3707
|
const data = {};
|
|
3703
3708
|
const inputs = formRoot.querySelectorAll(
|
|
@@ -3772,10 +3777,13 @@ function renderSingleContainerElement(element, ctx, wrapper, pathKey) {
|
|
|
3772
3777
|
containerWrap.appendChild(hintsElement);
|
|
3773
3778
|
}
|
|
3774
3779
|
}
|
|
3780
|
+
const childDefaults = extractChildDefaults(element.elements);
|
|
3781
|
+
const containerPrefill = ctx.prefill?.[element.key] || {};
|
|
3782
|
+
const mergedPrefill = mergeWithDefaults(containerPrefill, childDefaults);
|
|
3775
3783
|
const subCtx = {
|
|
3776
3784
|
path: pathJoin(ctx.path, element.key),
|
|
3777
|
-
prefill:
|
|
3778
|
-
//
|
|
3785
|
+
prefill: mergedPrefill,
|
|
3786
|
+
// Merged prefill with defaults for enableIf evaluation
|
|
3779
3787
|
formData: ctx.formData ?? ctx.prefill,
|
|
3780
3788
|
// Complete root data for enableIf evaluation
|
|
3781
3789
|
state: ctx.state
|
|
@@ -3805,6 +3813,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3805
3813
|
const min = element.minCount ?? 0;
|
|
3806
3814
|
const max = element.maxCount ?? Infinity;
|
|
3807
3815
|
const pre = Array.isArray(ctx.prefill?.[element.key]) ? ctx.prefill[element.key] : null;
|
|
3816
|
+
const childDefaults = extractChildDefaults(element.elements);
|
|
3808
3817
|
const countItems = () => itemsWrap.querySelectorAll(":scope > .containerItem").length;
|
|
3809
3818
|
const createAddButton = () => {
|
|
3810
3819
|
const add = document.createElement("button");
|
|
@@ -3831,7 +3840,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3831
3840
|
const subCtx = {
|
|
3832
3841
|
state: ctx.state,
|
|
3833
3842
|
path: pathJoin(ctx.path, `${element.key}[${idx}]`),
|
|
3834
|
-
prefill:
|
|
3843
|
+
prefill: childDefaults,
|
|
3844
|
+
// Defaults for enableIf evaluation
|
|
3835
3845
|
formData: currentFormData
|
|
3836
3846
|
// Current root data from DOM for enableIf
|
|
3837
3847
|
};
|
|
@@ -3894,10 +3904,12 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3894
3904
|
};
|
|
3895
3905
|
if (pre && Array.isArray(pre)) {
|
|
3896
3906
|
pre.forEach((prefillObj, idx) => {
|
|
3907
|
+
const mergedPrefill = mergeWithDefaults(prefillObj || {}, childDefaults);
|
|
3897
3908
|
const subCtx = {
|
|
3898
3909
|
state: ctx.state,
|
|
3899
3910
|
path: pathJoin(ctx.path, `${element.key}[${idx}]`),
|
|
3900
|
-
prefill:
|
|
3911
|
+
prefill: mergedPrefill,
|
|
3912
|
+
// Merged prefill with defaults for enableIf
|
|
3901
3913
|
formData: ctx.formData ?? ctx.prefill
|
|
3902
3914
|
// Complete root data for enableIf
|
|
3903
3915
|
};
|
|
@@ -3949,7 +3961,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3949
3961
|
const subCtx = {
|
|
3950
3962
|
state: ctx.state,
|
|
3951
3963
|
path: pathJoin(ctx.path, `${element.key}[${idx}]`),
|
|
3952
|
-
prefill:
|
|
3964
|
+
prefill: childDefaults,
|
|
3965
|
+
// Defaults for enableIf evaluation
|
|
3953
3966
|
formData: ctx.formData ?? ctx.prefill
|
|
3954
3967
|
// Complete root data for enableIf
|
|
3955
3968
|
};
|
|
@@ -4304,7 +4317,8 @@ function shouldDisableElement(element, ctx) {
|
|
|
4304
4317
|
}
|
|
4305
4318
|
try {
|
|
4306
4319
|
const rootFormData = ctx.formData ?? ctx.prefill ?? {};
|
|
4307
|
-
const
|
|
4320
|
+
const scope = element.enableIf.scope ?? "relative";
|
|
4321
|
+
const containerData = scope === "relative" && ctx.path ? ctx.prefill : void 0;
|
|
4308
4322
|
const shouldEnable = evaluateEnableCondition(
|
|
4309
4323
|
element.enableIf,
|
|
4310
4324
|
rootFormData,
|