@amplifyup/sdk 0.1.57 → 0.1.59
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 +19 -0
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +19 -0
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +94 -27
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +94 -27
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -2354,6 +2354,25 @@ Available Console Commands:
|
|
|
2354
2354
|
return;
|
|
2355
2355
|
}
|
|
2356
2356
|
try {
|
|
2357
|
+
if (event.data?.type === "AMPLIFYUP_RICHTEXT_EDITING") {
|
|
2358
|
+
document.querySelectorAll(".amplifyup-richtext-editing").forEach((el) => el.classList.remove("amplifyup-richtext-editing"));
|
|
2359
|
+
if (event.data.active && event.data.fieldName) {
|
|
2360
|
+
if (!document.getElementById("amplifyup-richtext-editing-style")) {
|
|
2361
|
+
const style = document.createElement("style");
|
|
2362
|
+
style.id = "amplifyup-richtext-editing-style";
|
|
2363
|
+
style.textContent = "[data-amplifyup-field].amplifyup-richtext-editing{outline:none!important;visibility:hidden!important;}";
|
|
2364
|
+
document.head.appendChild(style);
|
|
2365
|
+
}
|
|
2366
|
+
const editRoot = event.data.layoutNodeId ? document.querySelector(
|
|
2367
|
+
`[data-node-id="${event.data.layoutNodeId}"], [data-amplifyup-node-id="${event.data.layoutNodeId}"]`
|
|
2368
|
+
) || document : document;
|
|
2369
|
+
const editField = editRoot.querySelector(
|
|
2370
|
+
`[data-amplifyup-field="${event.data.fieldName}"]`
|
|
2371
|
+
);
|
|
2372
|
+
if (editField) editField.classList.add("amplifyup-richtext-editing");
|
|
2373
|
+
}
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2357
2376
|
if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
|
|
2358
2377
|
window.dispatchEvent(
|
|
2359
2378
|
new CustomEvent("amplifyup:field-patch", { detail: event.data })
|
|
@@ -3698,11 +3717,6 @@ function isReactNodeFallback(fallback) {
|
|
|
3698
3717
|
function classNameIsBlock(className) {
|
|
3699
3718
|
return /(?:^|\s)block(?:\s|$)/.test(className || "");
|
|
3700
3719
|
}
|
|
3701
|
-
function htmlHasVisualChrome(html) {
|
|
3702
|
-
return /<(input|button|select|textarea|form|svg|iframe|video|audio|img)\b/i.test(
|
|
3703
|
-
html
|
|
3704
|
-
);
|
|
3705
|
-
}
|
|
3706
3720
|
function canInlineEdit(name, value) {
|
|
3707
3721
|
if (!name || isLikelyNonTextFieldName(name)) return false;
|
|
3708
3722
|
if (value !== void 0 && value !== null && typeof value === "object") {
|
|
@@ -3771,6 +3785,36 @@ function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
|
3771
3785
|
"*"
|
|
3772
3786
|
);
|
|
3773
3787
|
}
|
|
3788
|
+
function looksLikeRichCanvasField(name) {
|
|
3789
|
+
const tokens = String(name || "").replace(/([a-z])([A-Z])/g, "$1 $2").split(/[._\-\s/]+/).map((s) => s.toLowerCase()).filter(Boolean);
|
|
3790
|
+
const last = tokens[tokens.length - 1] || "";
|
|
3791
|
+
return last === "body" || last === "content" || last === "copy" || last === "excerpt" || last === "markdown" || last === "richtext";
|
|
3792
|
+
}
|
|
3793
|
+
var lastRichTextRequestAt = 0;
|
|
3794
|
+
function requestCanvasRichTextEdit(opts) {
|
|
3795
|
+
if (typeof window === "undefined" || window.parent === window) return;
|
|
3796
|
+
if (!opts.name) return;
|
|
3797
|
+
const now = Date.now();
|
|
3798
|
+
if (now - lastRichTextRequestAt < 400) return;
|
|
3799
|
+
lastRichTextRequestAt = now;
|
|
3800
|
+
const rect = opts.el.getBoundingClientRect();
|
|
3801
|
+
window.parent.postMessage(
|
|
3802
|
+
{
|
|
3803
|
+
type: "AMPLIFYUP_RICHTEXT_EDIT",
|
|
3804
|
+
layoutNodeId: opts.layoutNodeId,
|
|
3805
|
+
componentId: opts.componentId,
|
|
3806
|
+
fieldName: opts.name,
|
|
3807
|
+
value: opts.value,
|
|
3808
|
+
bounds: {
|
|
3809
|
+
top: rect.top,
|
|
3810
|
+
left: rect.left,
|
|
3811
|
+
width: Math.max(rect.width, 240),
|
|
3812
|
+
height: Math.max(rect.height, 64)
|
|
3813
|
+
}
|
|
3814
|
+
},
|
|
3815
|
+
"*"
|
|
3816
|
+
);
|
|
3817
|
+
}
|
|
3774
3818
|
function placeCaret(el, atStart = false) {
|
|
3775
3819
|
const range = document.createRange();
|
|
3776
3820
|
range.selectNodeContents(el);
|
|
@@ -3786,7 +3830,8 @@ function ComposerInlineField({
|
|
|
3786
3830
|
className,
|
|
3787
3831
|
render,
|
|
3788
3832
|
layoutNodeId,
|
|
3789
|
-
componentId
|
|
3833
|
+
componentId,
|
|
3834
|
+
rich = false
|
|
3790
3835
|
}) {
|
|
3791
3836
|
const [editing, setEditing] = React.useState(false);
|
|
3792
3837
|
const [focused, setFocused] = React.useState(false);
|
|
@@ -3839,6 +3884,19 @@ function ComposerInlineField({
|
|
|
3839
3884
|
if (!text && !storedEmpty && next === fallbackText) return;
|
|
3840
3885
|
commitComposerField(layoutNodeId, componentId, name, next);
|
|
3841
3886
|
};
|
|
3887
|
+
const openRichEditor = (event) => {
|
|
3888
|
+
if (!isComposerEditMode() || !elRef.current) return;
|
|
3889
|
+
event?.preventDefault();
|
|
3890
|
+
event?.stopPropagation();
|
|
3891
|
+
const source = typeof value === "string" && !storedEmpty ? value : text || "";
|
|
3892
|
+
requestCanvasRichTextEdit({
|
|
3893
|
+
el: elRef.current,
|
|
3894
|
+
layoutNodeId,
|
|
3895
|
+
componentId,
|
|
3896
|
+
name,
|
|
3897
|
+
value: source
|
|
3898
|
+
});
|
|
3899
|
+
};
|
|
3842
3900
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3843
3901
|
"span",
|
|
3844
3902
|
{
|
|
@@ -3847,7 +3905,7 @@ function ComposerInlineField({
|
|
|
3847
3905
|
"data-amplifyup-field": name,
|
|
3848
3906
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3849
3907
|
"data-amplifyup-empty-hint": showHint ? "true" : void 0,
|
|
3850
|
-
contentEditable: !showRendered,
|
|
3908
|
+
contentEditable: !rich && !showRendered,
|
|
3851
3909
|
suppressContentEditableWarning: true,
|
|
3852
3910
|
role: "textbox",
|
|
3853
3911
|
tabIndex: 0,
|
|
@@ -3858,12 +3916,20 @@ function ComposerInlineField({
|
|
|
3858
3916
|
if (!isComposerEditMode()) return;
|
|
3859
3917
|
const link = event.target?.closest?.("a");
|
|
3860
3918
|
if (link) event.preventDefault();
|
|
3919
|
+
if (rich) {
|
|
3920
|
+
openRichEditor(event);
|
|
3921
|
+
return;
|
|
3922
|
+
}
|
|
3861
3923
|
if (render) {
|
|
3862
3924
|
setEditing(true);
|
|
3863
3925
|
}
|
|
3864
3926
|
},
|
|
3865
3927
|
onFocus: () => {
|
|
3866
3928
|
if (!isComposerEditMode()) return;
|
|
3929
|
+
if (rich) {
|
|
3930
|
+
openRichEditor();
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3867
3933
|
setFocused(true);
|
|
3868
3934
|
const el = elRef.current;
|
|
3869
3935
|
if (el && storedEmpty) {
|
|
@@ -3872,7 +3938,7 @@ function ComposerInlineField({
|
|
|
3872
3938
|
}
|
|
3873
3939
|
if (render) setEditing(true);
|
|
3874
3940
|
},
|
|
3875
|
-
onBlur: finishEdit,
|
|
3941
|
+
onBlur: rich ? void 0 : finishEdit,
|
|
3876
3942
|
onKeyDown: (event) => {
|
|
3877
3943
|
event.stopPropagation();
|
|
3878
3944
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
@@ -3904,43 +3970,40 @@ function ComposerInlineField({
|
|
|
3904
3970
|
function ComposerInlineHtml({
|
|
3905
3971
|
name,
|
|
3906
3972
|
html,
|
|
3973
|
+
sourceValue,
|
|
3907
3974
|
className,
|
|
3908
3975
|
Tag = "div",
|
|
3909
3976
|
layoutNodeId,
|
|
3910
3977
|
componentId
|
|
3911
3978
|
}) {
|
|
3912
3979
|
const elRef = React.useRef(null);
|
|
3913
|
-
const sourceTextRef = React.useRef("");
|
|
3914
3980
|
React.useEffect(() => {
|
|
3915
3981
|
const el = elRef.current;
|
|
3916
3982
|
if (!el) return;
|
|
3917
|
-
if (document.activeElement === el || el.contains(document.activeElement)) {
|
|
3918
|
-
return;
|
|
3919
|
-
}
|
|
3920
3983
|
if (el.innerHTML !== html) el.innerHTML = html;
|
|
3921
|
-
sourceTextRef.current = (el.innerText ?? "").replace(/\u00a0/g, " ").trim();
|
|
3922
3984
|
}, [html]);
|
|
3923
|
-
const
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3985
|
+
const openRichEditor = (event) => {
|
|
3986
|
+
if (!elRef.current) return;
|
|
3987
|
+
event.preventDefault();
|
|
3988
|
+
event.stopPropagation();
|
|
3989
|
+
requestCanvasRichTextEdit({
|
|
3990
|
+
el: elRef.current,
|
|
3991
|
+
layoutNodeId,
|
|
3992
|
+
componentId,
|
|
3993
|
+
name,
|
|
3994
|
+
value: sourceValue
|
|
3995
|
+
});
|
|
3931
3996
|
};
|
|
3932
3997
|
return React__default.default.createElement(Tag, {
|
|
3933
3998
|
ref: elRef,
|
|
3934
3999
|
className,
|
|
3935
4000
|
"data-amplifyup-field": name,
|
|
3936
4001
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3937
|
-
contentEditable: true,
|
|
3938
|
-
suppressContentEditableWarning: true,
|
|
3939
4002
|
dangerouslySetInnerHTML: { __html: html },
|
|
3940
4003
|
onMouseDown: (event) => {
|
|
3941
4004
|
event.stopPropagation();
|
|
3942
4005
|
},
|
|
3943
|
-
|
|
4006
|
+
onClick: openRichEditor,
|
|
3944
4007
|
style: {
|
|
3945
4008
|
cursor: "text",
|
|
3946
4009
|
outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
|
|
@@ -4036,7 +4099,8 @@ function Field(props) {
|
|
|
4036
4099
|
className,
|
|
4037
4100
|
render,
|
|
4038
4101
|
layoutNodeId: context.layoutNodeId,
|
|
4039
|
-
componentId: context.componentId
|
|
4102
|
+
componentId: context.componentId,
|
|
4103
|
+
rich: looksLikeRichCanvasField(editName)
|
|
4040
4104
|
}
|
|
4041
4105
|
);
|
|
4042
4106
|
}
|
|
@@ -4058,7 +4122,8 @@ function Field(props) {
|
|
|
4058
4122
|
fallback,
|
|
4059
4123
|
className,
|
|
4060
4124
|
layoutNodeId: context.layoutNodeId,
|
|
4061
|
-
componentId: context.componentId
|
|
4125
|
+
componentId: context.componentId,
|
|
4126
|
+
rich: looksLikeRichCanvasField(editName)
|
|
4062
4127
|
}
|
|
4063
4128
|
);
|
|
4064
4129
|
}
|
|
@@ -4117,7 +4182,8 @@ function RichText(props) {
|
|
|
4117
4182
|
fallback: typeof fallback === "string" || typeof fallback === "number" ? fallback : void 0,
|
|
4118
4183
|
className,
|
|
4119
4184
|
layoutNodeId: context?.layoutNodeId,
|
|
4120
|
-
componentId: context?.componentId
|
|
4185
|
+
componentId: context?.componentId,
|
|
4186
|
+
rich: true
|
|
4121
4187
|
}
|
|
4122
4188
|
);
|
|
4123
4189
|
}
|
|
@@ -4144,6 +4210,7 @@ function RichText(props) {
|
|
|
4144
4210
|
{
|
|
4145
4211
|
name: editName,
|
|
4146
4212
|
html,
|
|
4213
|
+
sourceValue: typeof fieldValue === "string" ? fieldValue : html,
|
|
4147
4214
|
className,
|
|
4148
4215
|
Tag,
|
|
4149
4216
|
layoutNodeId: context?.layoutNodeId,
|