@valu/block-components 0.3.1 → 0.4.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/README.md +4 -0
- package/dist/components/document-picker/index.cjs +151 -10
- package/dist/components/document-picker/index.cjs.map +1 -1
- package/dist/components/document-picker/index.d.cts +16 -1
- package/dist/components/document-picker/index.d.ts +16 -1
- package/dist/components/document-picker/index.js +152 -11
- package/dist/components/document-picker/index.js.map +1 -1
- package/dist/index.cjs +151 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +152 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2852,6 +2852,54 @@ var DocMetaInline = styled__default.default.div`
|
|
|
2852
2852
|
white-space: nowrap;
|
|
2853
2853
|
}
|
|
2854
2854
|
`;
|
|
2855
|
+
var ReorderButtons = styled__default.default.span`
|
|
2856
|
+
display: none;
|
|
2857
|
+
|
|
2858
|
+
@container valu-dp-row (min-width: 340px) {
|
|
2859
|
+
display: inline-flex;
|
|
2860
|
+
}
|
|
2861
|
+
`;
|
|
2862
|
+
var LabelEditBody = styled__default.default.div`
|
|
2863
|
+
flex: 1;
|
|
2864
|
+
min-width: 0;
|
|
2865
|
+
display: flex;
|
|
2866
|
+
flex-direction: column;
|
|
2867
|
+
gap: 2px;
|
|
2868
|
+
padding: 4px 0;
|
|
2869
|
+
|
|
2870
|
+
.components-base-control,
|
|
2871
|
+
.components-text-control__input {
|
|
2872
|
+
width: 100%;
|
|
2873
|
+
min-width: 0;
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
/* __nextHasNoMarginBottom is not honored by every bundled
|
|
2877
|
+
wp-components version — enforce the no-margin layout here. */
|
|
2878
|
+
.components-base-control.components-base-control {
|
|
2879
|
+
margin-bottom: 0;
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
/* Doubled class beats wp-components' own input rules regardless of
|
|
2883
|
+
stylesheet order (the emotion cache may be prepended). */
|
|
2884
|
+
.components-text-control__input.components-text-control__input {
|
|
2885
|
+
font-size: ${tokens.fontSizeBody};
|
|
2886
|
+
height: 28px;
|
|
2887
|
+
min-height: 28px;
|
|
2888
|
+
padding: 2px 8px;
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
@container valu-dp-row (min-width: ${WIDE_ROW}) {
|
|
2892
|
+
flex-direction: row;
|
|
2893
|
+
align-items: center;
|
|
2894
|
+
gap: ${tokens.spaceMd};
|
|
2895
|
+
|
|
2896
|
+
.components-base-control {
|
|
2897
|
+
flex: 0 1 340px;
|
|
2898
|
+
min-width: 180px;
|
|
2899
|
+
width: auto;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
`;
|
|
2855
2903
|
var Root3 = styled__default.default.div`
|
|
2856
2904
|
color: ${tokens.fg};
|
|
2857
2905
|
font-size: ${tokens.fontSizeBody};
|
|
@@ -3012,6 +3060,7 @@ var mapMediaToDocumentItem = (raw) => {
|
|
|
3012
3060
|
raw
|
|
3013
3061
|
};
|
|
3014
3062
|
};
|
|
3063
|
+
var displayTitle = (item) => item.label?.trim() || item.title;
|
|
3015
3064
|
var dedupeAgainst2 = (items, value, enabled) => {
|
|
3016
3065
|
if (!enabled || value.length === 0) return items;
|
|
3017
3066
|
const ids = new Set(value.map((v) => v.id));
|
|
@@ -3903,6 +3952,8 @@ var SelectedItem2 = ({
|
|
|
3903
3952
|
onRemove,
|
|
3904
3953
|
onMoveUp,
|
|
3905
3954
|
onMoveDown,
|
|
3955
|
+
enableLabelEdit = false,
|
|
3956
|
+
onLabelChange,
|
|
3906
3957
|
render
|
|
3907
3958
|
}) => {
|
|
3908
3959
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = sortable.useSortable({
|
|
@@ -3916,22 +3967,46 @@ var SelectedItem2 = ({
|
|
|
3916
3967
|
};
|
|
3917
3968
|
const isMissing = item.missing === "deleted";
|
|
3918
3969
|
const missingLabel = labels.missing ?? i18n.__("This document is no longer available.", "valu-block-components");
|
|
3970
|
+
const displayName = displayTitle(item);
|
|
3919
3971
|
const removeLabel = labels.remove ? labels.remove : i18n.sprintf(
|
|
3920
3972
|
/* translators: %s: document title */
|
|
3921
3973
|
i18n.__("Remove %s", "valu-block-components"),
|
|
3922
|
-
|
|
3974
|
+
displayName
|
|
3923
3975
|
);
|
|
3924
3976
|
const moveUpLabel = labels.moveUp ? labels.moveUp : i18n.sprintf(
|
|
3925
3977
|
/* translators: %s: document title */
|
|
3926
3978
|
i18n.__("Move %s up", "valu-block-components"),
|
|
3927
|
-
|
|
3979
|
+
displayName
|
|
3928
3980
|
);
|
|
3929
3981
|
const moveDownLabel = labels.moveDown ? labels.moveDown : i18n.sprintf(
|
|
3930
3982
|
/* translators: %s: document title */
|
|
3931
3983
|
i18n.__("Move %s down", "valu-block-components"),
|
|
3932
|
-
|
|
3984
|
+
displayName
|
|
3933
3985
|
);
|
|
3934
3986
|
const modified = showModifiedDate ? formatModified(item.modified) : "";
|
|
3987
|
+
const isLabelEdit = enableLabelEdit && !isMissing && Boolean(onLabelChange);
|
|
3988
|
+
const [labelDraft, setLabelDraft] = react$1.useState(null);
|
|
3989
|
+
const commitTimer = react$1.useRef(null);
|
|
3990
|
+
react$1.useEffect(
|
|
3991
|
+
() => () => {
|
|
3992
|
+
if (commitTimer.current) {
|
|
3993
|
+
clearTimeout(commitTimer.current);
|
|
3994
|
+
}
|
|
3995
|
+
},
|
|
3996
|
+
[]
|
|
3997
|
+
);
|
|
3998
|
+
const normalizeLabel = (value) => {
|
|
3999
|
+
const trimmed = value.trim();
|
|
4000
|
+
return trimmed === "" || trimmed === item.title ? "" : value;
|
|
4001
|
+
};
|
|
4002
|
+
const itemLabelText = labels.itemLabel ?? i18n.__("Display name", "valu-block-components");
|
|
4003
|
+
const metaParts = [item.filename];
|
|
4004
|
+
if (showFileSize && item.fileSize) {
|
|
4005
|
+
metaParts.push(formatFileSize(item.fileSize));
|
|
4006
|
+
}
|
|
4007
|
+
if (modified) {
|
|
4008
|
+
metaParts.push(modified);
|
|
4009
|
+
}
|
|
3935
4010
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3936
4011
|
SelectedRow2,
|
|
3937
4012
|
{
|
|
@@ -3953,9 +4028,45 @@ var SelectedItem2 = ({
|
|
|
3953
4028
|
}
|
|
3954
4029
|
) : null,
|
|
3955
4030
|
isMissing ? /* @__PURE__ */ jsxRuntime.jsx(components.Icon, { icon: icons.caution, size: 20 }) : showExtensionBadge ? /* @__PURE__ */ jsxRuntime.jsx(ExtensionBadge, { extension: item.extension }) : null,
|
|
3956
|
-
render ? render(item) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4031
|
+
render ? render(item) : isLabelEdit ? /* @__PURE__ */ jsxRuntime.jsxs(LabelEditBody, { children: [
|
|
4032
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4033
|
+
components.TextControl,
|
|
4034
|
+
{
|
|
4035
|
+
__nextHasNoMarginBottom: true,
|
|
4036
|
+
__next40pxDefaultSize: false,
|
|
4037
|
+
"aria-label": i18n.sprintf(
|
|
4038
|
+
/* translators: 1: display-name field label, 2: filename */
|
|
4039
|
+
"%1$s: %2$s",
|
|
4040
|
+
itemLabelText,
|
|
4041
|
+
item.filename
|
|
4042
|
+
),
|
|
4043
|
+
value: labelDraft ?? item.label ?? item.title,
|
|
4044
|
+
onChange: (value) => {
|
|
4045
|
+
setLabelDraft(value);
|
|
4046
|
+
if (commitTimer.current) {
|
|
4047
|
+
clearTimeout(commitTimer.current);
|
|
4048
|
+
}
|
|
4049
|
+
commitTimer.current = setTimeout(() => {
|
|
4050
|
+
commitTimer.current = null;
|
|
4051
|
+
onLabelChange?.(normalizeLabel(value));
|
|
4052
|
+
}, 300);
|
|
4053
|
+
},
|
|
4054
|
+
onBlur: () => {
|
|
4055
|
+
if (commitTimer.current) {
|
|
4056
|
+
clearTimeout(commitTimer.current);
|
|
4057
|
+
commitTimer.current = null;
|
|
4058
|
+
if (labelDraft !== null) {
|
|
4059
|
+
onLabelChange?.(normalizeLabel(labelDraft));
|
|
4060
|
+
}
|
|
4061
|
+
}
|
|
4062
|
+
setLabelDraft(null);
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
),
|
|
4066
|
+
/* @__PURE__ */ jsxRuntime.jsx(FilenameText, { title: item.filename, children: metaParts.join(" \xB7 ") })
|
|
4067
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3957
4068
|
/* @__PURE__ */ jsxRuntime.jsxs(DocRowBody, { children: [
|
|
3958
|
-
/* @__PURE__ */ jsxRuntime.jsx(PrimaryText, { muted: isMissing, title:
|
|
4069
|
+
/* @__PURE__ */ jsxRuntime.jsx(PrimaryText, { muted: isMissing, title: displayName, children: isMissing ? missingLabel : displayName }),
|
|
3959
4070
|
!isMissing ? /* @__PURE__ */ jsxRuntime.jsx(FilenameText, { title: item.filename, children: item.filename }) : null
|
|
3960
4071
|
] }),
|
|
3961
4072
|
!isMissing && (showFileSize || modified) ? /* @__PURE__ */ jsxRuntime.jsxs(DocMetaInline, { children: [
|
|
@@ -3964,7 +4075,7 @@ var SelectedItem2 = ({
|
|
|
3964
4075
|
] }) : null
|
|
3965
4076
|
] }),
|
|
3966
4077
|
/* @__PURE__ */ jsxRuntime.jsxs(ActionColumn, { children: [
|
|
3967
|
-
orderable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4078
|
+
orderable ? /* @__PURE__ */ jsxRuntime.jsxs(ReorderButtons, { children: [
|
|
3968
4079
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3969
4080
|
components.Button,
|
|
3970
4081
|
{
|
|
@@ -4056,7 +4167,8 @@ var SelectedList2 = ({
|
|
|
4056
4167
|
showHeader = true,
|
|
4057
4168
|
showExtensionBadge,
|
|
4058
4169
|
showFileSize,
|
|
4059
|
-
showModifiedDate
|
|
4170
|
+
showModifiedDate,
|
|
4171
|
+
enableItemLabels = false
|
|
4060
4172
|
}) => {
|
|
4061
4173
|
const resolved = useResolvedDocuments(value);
|
|
4062
4174
|
const [activeKey, setActiveKey] = react$1.useState(null);
|
|
@@ -4071,6 +4183,22 @@ var SelectedList2 = ({
|
|
|
4071
4183
|
(key) => onChange(value.filter((i) => i.key !== key)),
|
|
4072
4184
|
[value, onChange]
|
|
4073
4185
|
);
|
|
4186
|
+
const setLabel = react$1.useCallback(
|
|
4187
|
+
(key, label) => onChange(
|
|
4188
|
+
value.map((i) => {
|
|
4189
|
+
if (i.key !== key) {
|
|
4190
|
+
return i;
|
|
4191
|
+
}
|
|
4192
|
+
if (label === "") {
|
|
4193
|
+
const rest = { ...i };
|
|
4194
|
+
delete rest.label;
|
|
4195
|
+
return rest;
|
|
4196
|
+
}
|
|
4197
|
+
return { ...i, label };
|
|
4198
|
+
})
|
|
4199
|
+
),
|
|
4200
|
+
[value, onChange]
|
|
4201
|
+
);
|
|
4074
4202
|
const reorder = react$1.useCallback(
|
|
4075
4203
|
(from, to) => {
|
|
4076
4204
|
if (from === to) return;
|
|
@@ -4119,6 +4247,10 @@ var SelectedList2 = ({
|
|
|
4119
4247
|
onRemove: () => remove(item.key),
|
|
4120
4248
|
...index > 0 ? { onMoveUp: () => reorder(index, index - 1) } : {},
|
|
4121
4249
|
...index < resolved.length - 1 ? { onMoveDown: () => reorder(index, index + 1) } : {},
|
|
4250
|
+
...enableItemLabels ? {
|
|
4251
|
+
enableLabelEdit: true,
|
|
4252
|
+
onLabelChange: (label) => setLabel(item.key, label)
|
|
4253
|
+
} : {},
|
|
4122
4254
|
...renderSelected ? { render: renderSelected } : {}
|
|
4123
4255
|
},
|
|
4124
4256
|
item.key
|
|
@@ -4141,7 +4273,7 @@ var SelectedList2 = ({
|
|
|
4141
4273
|
onDragCancel: () => setActiveKey(null),
|
|
4142
4274
|
children: [
|
|
4143
4275
|
/* @__PURE__ */ jsxRuntime.jsx(sortable.SortableContext, { items: ids, strategy: sortable.verticalListSortingStrategy, children: /* @__PURE__ */ jsxRuntime.jsx(SelectedListEl, { role: "list", children: rows }) }),
|
|
4144
|
-
/* @__PURE__ */ jsxRuntime.jsx(core.DragOverlay, { dropAnimation: core.defaultDropAnimation, children: activeItem ? /* @__PURE__ */ jsxRuntime.jsx(DragChip, { title: activeItem
|
|
4276
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.DragOverlay, { dropAnimation: core.defaultDropAnimation, children: activeItem ? /* @__PURE__ */ jsxRuntime.jsx(DragChip, { title: displayTitle(activeItem) }) : null })
|
|
4145
4277
|
]
|
|
4146
4278
|
}
|
|
4147
4279
|
)
|
|
@@ -4172,6 +4304,7 @@ var DocumentPicker = ({
|
|
|
4172
4304
|
fetchOnOpen = false,
|
|
4173
4305
|
uniqueItems = true,
|
|
4174
4306
|
enableMediaLibrary = true,
|
|
4307
|
+
enableItemLabels = false,
|
|
4175
4308
|
showExtensionBadge = true,
|
|
4176
4309
|
showFileSize = true,
|
|
4177
4310
|
showModifiedDate = false,
|
|
@@ -4263,7 +4396,14 @@ var DocumentPicker = ({
|
|
|
4263
4396
|
...allowedExtensions !== void 0 ? { allowedExtensions } : {},
|
|
4264
4397
|
multiple: false,
|
|
4265
4398
|
value,
|
|
4266
|
-
onSelect: (items) =>
|
|
4399
|
+
onSelect: (items) => {
|
|
4400
|
+
const next = items[items.length - 1];
|
|
4401
|
+
const prev = value[0];
|
|
4402
|
+
const keepLabel = prev?.id === next.id && prev.label !== void 0;
|
|
4403
|
+
handleChange([
|
|
4404
|
+
keepLabel ? { ...next, label: prev.label } : next
|
|
4405
|
+
]);
|
|
4406
|
+
},
|
|
4267
4407
|
labels,
|
|
4268
4408
|
variant: "tertiary",
|
|
4269
4409
|
label: labels.replace
|
|
@@ -4281,7 +4421,8 @@ var DocumentPicker = ({
|
|
|
4281
4421
|
showHeader: value.length > 0,
|
|
4282
4422
|
showExtensionBadge,
|
|
4283
4423
|
showFileSize,
|
|
4284
|
-
showModifiedDate
|
|
4424
|
+
showModifiedDate,
|
|
4425
|
+
enableItemLabels
|
|
4285
4426
|
}
|
|
4286
4427
|
)
|
|
4287
4428
|
] }) }) });
|