@amplifyup/sdk 0.1.59 → 0.1.61
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/AmplifyRenderer.js +16 -3
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +16 -3
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -3
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +90 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +90 -5
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -2349,12 +2349,17 @@ Available Console Commands:
|
|
|
2349
2349
|
}
|
|
2350
2350
|
try {
|
|
2351
2351
|
if (event.data?.type === "AMPLIFYUP_RICHTEXT_EDITING") {
|
|
2352
|
-
document.querySelectorAll(".amplifyup-richtext-editing").forEach((el) =>
|
|
2352
|
+
document.querySelectorAll(".amplifyup-richtext-editing").forEach((el) => {
|
|
2353
|
+
el.classList.remove("amplifyup-richtext-editing");
|
|
2354
|
+
el.style.minHeight = "";
|
|
2355
|
+
el.style.height = "";
|
|
2356
|
+
el.style.display = "";
|
|
2357
|
+
});
|
|
2353
2358
|
if (event.data.active && event.data.fieldName) {
|
|
2354
2359
|
if (!document.getElementById("amplifyup-richtext-editing-style")) {
|
|
2355
2360
|
const style = document.createElement("style");
|
|
2356
2361
|
style.id = "amplifyup-richtext-editing-style";
|
|
2357
|
-
style.textContent = "[data-amplifyup-field].amplifyup-richtext-editing{outline:none!important;visibility:hidden!important;}";
|
|
2362
|
+
style.textContent = "[data-amplifyup-field].amplifyup-richtext-editing{outline:none!important;visibility:hidden!important;display:block!important;box-sizing:border-box!important;}";
|
|
2358
2363
|
document.head.appendChild(style);
|
|
2359
2364
|
}
|
|
2360
2365
|
const editRoot = event.data.layoutNodeId ? document.querySelector(
|
|
@@ -2363,7 +2368,15 @@ Available Console Commands:
|
|
|
2363
2368
|
const editField = editRoot.querySelector(
|
|
2364
2369
|
`[data-amplifyup-field="${event.data.fieldName}"]`
|
|
2365
2370
|
);
|
|
2366
|
-
if (editField)
|
|
2371
|
+
if (editField) {
|
|
2372
|
+
editField.classList.add("amplifyup-richtext-editing");
|
|
2373
|
+
const editHeight = Number(event.data.height) || 0;
|
|
2374
|
+
if (editHeight > 0) {
|
|
2375
|
+
editField.style.display = "block";
|
|
2376
|
+
editField.style.minHeight = `${editHeight}px`;
|
|
2377
|
+
editField.style.height = `${editHeight}px`;
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2367
2380
|
}
|
|
2368
2381
|
return;
|
|
2369
2382
|
}
|
|
@@ -3727,6 +3740,20 @@ function canInlineEditRichText(name, value) {
|
|
|
3727
3740
|
}
|
|
3728
3741
|
return true;
|
|
3729
3742
|
}
|
|
3743
|
+
function isLikelyImagePropName(name) {
|
|
3744
|
+
const n = name.toLowerCase();
|
|
3745
|
+
return n.includes("image") || n.includes("thumbnail") || n.includes("photo") || n.includes("avatar") || n.includes("poster") || n.includes("logo") || n.endsWith("img") || n.endsWith("_src") || n.endsWith("Src");
|
|
3746
|
+
}
|
|
3747
|
+
function portableImageUrl(value) {
|
|
3748
|
+
if (typeof value === "string") return value.trim();
|
|
3749
|
+
if (value && typeof value === "object" && !Array.isArray(value) && "url" in value) {
|
|
3750
|
+
const url = value.url;
|
|
3751
|
+
if (url == null) return "";
|
|
3752
|
+
if (typeof url === "string") return url.trim();
|
|
3753
|
+
return null;
|
|
3754
|
+
}
|
|
3755
|
+
return null;
|
|
3756
|
+
}
|
|
3730
3757
|
function inferEditName(explicitName, contextProps, sourceValue) {
|
|
3731
3758
|
if (explicitName) return explicitName;
|
|
3732
3759
|
if (!contextProps) return "";
|
|
@@ -3734,6 +3761,22 @@ function inferEditName(explicitName, contextProps, sourceValue) {
|
|
|
3734
3761
|
(key) => Object.is(contextProps[key], sourceValue)
|
|
3735
3762
|
);
|
|
3736
3763
|
if (keys.length === 1) return keys[0];
|
|
3764
|
+
const srcUrl = portableImageUrl(sourceValue);
|
|
3765
|
+
if (srcUrl !== null) {
|
|
3766
|
+
const byUrl = Object.keys(contextProps).filter((key) => {
|
|
3767
|
+
const other = portableImageUrl(contextProps[key]);
|
|
3768
|
+
return other !== null && other === srcUrl;
|
|
3769
|
+
});
|
|
3770
|
+
if (byUrl.length === 1) return byUrl[0];
|
|
3771
|
+
if (srcUrl === "") {
|
|
3772
|
+
const emptyImageKeys = Object.keys(contextProps).filter((key) => {
|
|
3773
|
+
if (!isLikelyImagePropName(key)) return false;
|
|
3774
|
+
const other = portableImageUrl(contextProps[key]);
|
|
3775
|
+
return other === "" || contextProps[key] == null;
|
|
3776
|
+
});
|
|
3777
|
+
if (emptyImageKeys.length === 1) return emptyImageKeys[0];
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3737
3780
|
if (keys.length === 0 || isComposerEmptyText(sourceValue)) return "";
|
|
3738
3781
|
return keys[0];
|
|
3739
3782
|
}
|
|
@@ -3897,6 +3940,7 @@ function ComposerInlineField({
|
|
|
3897
3940
|
ref: elRef,
|
|
3898
3941
|
className,
|
|
3899
3942
|
"data-amplifyup-field": name,
|
|
3943
|
+
"data-amplifyup-field-type": rich ? "richtext" : "text",
|
|
3900
3944
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3901
3945
|
"data-amplifyup-empty-hint": showHint ? "true" : void 0,
|
|
3902
3946
|
contentEditable: !rich && !showRendered,
|
|
@@ -3992,6 +4036,7 @@ function ComposerInlineHtml({
|
|
|
3992
4036
|
ref: elRef,
|
|
3993
4037
|
className,
|
|
3994
4038
|
"data-amplifyup-field": name,
|
|
4039
|
+
"data-amplifyup-field-type": "richtext",
|
|
3995
4040
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3996
4041
|
dangerouslySetInnerHTML: { __html: html },
|
|
3997
4042
|
onMouseDown: (event) => {
|
|
@@ -4242,6 +4287,8 @@ function Image(props) {
|
|
|
4242
4287
|
inferEditName(name, context?.props, sourceValue),
|
|
4243
4288
|
sourceValue
|
|
4244
4289
|
);
|
|
4290
|
+
const composerEdit = useComposerEditMode();
|
|
4291
|
+
const editName = inferEditName(name, context?.props, sourceValue);
|
|
4245
4292
|
warnProjectionProps("Image", name, hasExplicitValue);
|
|
4246
4293
|
if (!context && !hasExplicitValue) {
|
|
4247
4294
|
console.warn(
|
|
@@ -4250,20 +4297,58 @@ function Image(props) {
|
|
|
4250
4297
|
return null;
|
|
4251
4298
|
}
|
|
4252
4299
|
const src = imageSrc(fieldValue);
|
|
4253
|
-
if (!src) return null;
|
|
4254
4300
|
const portable = isPortableImageValue(fieldValue) ? fieldValue : null;
|
|
4255
4301
|
const alt = altProp ?? portable?.alt ?? "";
|
|
4256
4302
|
const width = widthProp ?? portable?.width;
|
|
4257
4303
|
const height = heightProp ?? portable?.height;
|
|
4304
|
+
const fieldAttrs = composerEdit && editName ? {
|
|
4305
|
+
"data-amplifyup-field": editName,
|
|
4306
|
+
"data-amplifyup-field-type": "image",
|
|
4307
|
+
"data-amplifyup-node-id": context?.layoutNodeId || void 0
|
|
4308
|
+
} : null;
|
|
4309
|
+
if (composerEdit && !editName && (hasExplicitValue || name)) {
|
|
4310
|
+
console.warn(
|
|
4311
|
+
'[AmplifyUp SDK] Image could not infer a Composer field name from value={\u2026}. Pass name="yourProp" (same as the component prop) so the image can be selected.'
|
|
4312
|
+
);
|
|
4313
|
+
}
|
|
4314
|
+
if (!src) {
|
|
4315
|
+
if (!composerEdit || !fieldAttrs) return null;
|
|
4316
|
+
return /* @__PURE__ */ jsx(
|
|
4317
|
+
"span",
|
|
4318
|
+
{
|
|
4319
|
+
...fieldAttrs,
|
|
4320
|
+
className,
|
|
4321
|
+
role: "img",
|
|
4322
|
+
"aria-label": alt || editName || "Image",
|
|
4323
|
+
style: {
|
|
4324
|
+
display: "block",
|
|
4325
|
+
boxSizing: "border-box",
|
|
4326
|
+
minWidth: width ? void 0 : 120,
|
|
4327
|
+
minHeight: height ? void 0 : 80,
|
|
4328
|
+
width: width || "100%",
|
|
4329
|
+
height: height || void 0,
|
|
4330
|
+
background: "color-mix(in srgb, currentColor 8%, transparent)",
|
|
4331
|
+
outline: "2px dashed hsl(82 100% 45%)",
|
|
4332
|
+
outlineOffset: 2,
|
|
4333
|
+
cursor: "pointer"
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
);
|
|
4337
|
+
}
|
|
4258
4338
|
return /* @__PURE__ */ jsx(
|
|
4259
4339
|
"img",
|
|
4260
4340
|
{
|
|
4261
4341
|
...imgProps,
|
|
4342
|
+
...fieldAttrs,
|
|
4262
4343
|
src,
|
|
4263
4344
|
alt,
|
|
4264
4345
|
className,
|
|
4265
4346
|
width,
|
|
4266
|
-
height
|
|
4347
|
+
height,
|
|
4348
|
+
style: {
|
|
4349
|
+
...typeof imgProps.style === "object" && imgProps.style ? imgProps.style : {},
|
|
4350
|
+
...composerEdit && fieldAttrs ? { cursor: "pointer" } : null
|
|
4351
|
+
}
|
|
4267
4352
|
}
|
|
4268
4353
|
);
|
|
4269
4354
|
}
|