@valu/block-components 0.3.0 → 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/components/matrix/index.cjs +8 -1
- package/dist/components/matrix/index.cjs.map +1 -1
- package/dist/components/matrix/index.js +8 -1
- package/dist/components/matrix/index.js.map +1 -1
- package/dist/index.cjs +159 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +160 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2089,7 +2089,14 @@ var Table = styled__default.default.table`
|
|
|
2089
2089
|
border-collapse: separate;
|
|
2090
2090
|
border-spacing: 0;
|
|
2091
2091
|
width: 100%;
|
|
2092
|
-
|
|
2092
|
+
/*
|
|
2093
|
+
* Do NOT set \`min-width: max-content\` here. Combined with the
|
|
2094
|
+
* trailing FillerCell's \`width: 100%\`, Chrome's auto table layout
|
|
2095
|
+
* enters a feedback loop and blows the table up to ~1,000,000px,
|
|
2096
|
+
* producing a phantom horizontal scrollbar even when all content
|
|
2097
|
+
* fits. The per-cell min-widths (row header, master, leaf) already
|
|
2098
|
+
* prevent content from squishing, so this rule is unnecessary.
|
|
2099
|
+
*/
|
|
2093
2100
|
|
|
2094
2101
|
caption {
|
|
2095
2102
|
${visuallyHiddenCss2};
|
|
@@ -2845,6 +2852,54 @@ var DocMetaInline = styled__default.default.div`
|
|
|
2845
2852
|
white-space: nowrap;
|
|
2846
2853
|
}
|
|
2847
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
|
+
`;
|
|
2848
2903
|
var Root3 = styled__default.default.div`
|
|
2849
2904
|
color: ${tokens.fg};
|
|
2850
2905
|
font-size: ${tokens.fontSizeBody};
|
|
@@ -3005,6 +3060,7 @@ var mapMediaToDocumentItem = (raw) => {
|
|
|
3005
3060
|
raw
|
|
3006
3061
|
};
|
|
3007
3062
|
};
|
|
3063
|
+
var displayTitle = (item) => item.label?.trim() || item.title;
|
|
3008
3064
|
var dedupeAgainst2 = (items, value, enabled) => {
|
|
3009
3065
|
if (!enabled || value.length === 0) return items;
|
|
3010
3066
|
const ids = new Set(value.map((v) => v.id));
|
|
@@ -3896,6 +3952,8 @@ var SelectedItem2 = ({
|
|
|
3896
3952
|
onRemove,
|
|
3897
3953
|
onMoveUp,
|
|
3898
3954
|
onMoveDown,
|
|
3955
|
+
enableLabelEdit = false,
|
|
3956
|
+
onLabelChange,
|
|
3899
3957
|
render
|
|
3900
3958
|
}) => {
|
|
3901
3959
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = sortable.useSortable({
|
|
@@ -3909,22 +3967,46 @@ var SelectedItem2 = ({
|
|
|
3909
3967
|
};
|
|
3910
3968
|
const isMissing = item.missing === "deleted";
|
|
3911
3969
|
const missingLabel = labels.missing ?? i18n.__("This document is no longer available.", "valu-block-components");
|
|
3970
|
+
const displayName = displayTitle(item);
|
|
3912
3971
|
const removeLabel = labels.remove ? labels.remove : i18n.sprintf(
|
|
3913
3972
|
/* translators: %s: document title */
|
|
3914
3973
|
i18n.__("Remove %s", "valu-block-components"),
|
|
3915
|
-
|
|
3974
|
+
displayName
|
|
3916
3975
|
);
|
|
3917
3976
|
const moveUpLabel = labels.moveUp ? labels.moveUp : i18n.sprintf(
|
|
3918
3977
|
/* translators: %s: document title */
|
|
3919
3978
|
i18n.__("Move %s up", "valu-block-components"),
|
|
3920
|
-
|
|
3979
|
+
displayName
|
|
3921
3980
|
);
|
|
3922
3981
|
const moveDownLabel = labels.moveDown ? labels.moveDown : i18n.sprintf(
|
|
3923
3982
|
/* translators: %s: document title */
|
|
3924
3983
|
i18n.__("Move %s down", "valu-block-components"),
|
|
3925
|
-
|
|
3984
|
+
displayName
|
|
3926
3985
|
);
|
|
3927
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
|
+
}
|
|
3928
4010
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3929
4011
|
SelectedRow2,
|
|
3930
4012
|
{
|
|
@@ -3946,9 +4028,45 @@ var SelectedItem2 = ({
|
|
|
3946
4028
|
}
|
|
3947
4029
|
) : null,
|
|
3948
4030
|
isMissing ? /* @__PURE__ */ jsxRuntime.jsx(components.Icon, { icon: icons.caution, size: 20 }) : showExtensionBadge ? /* @__PURE__ */ jsxRuntime.jsx(ExtensionBadge, { extension: item.extension }) : null,
|
|
3949
|
-
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: [
|
|
3950
4068
|
/* @__PURE__ */ jsxRuntime.jsxs(DocRowBody, { children: [
|
|
3951
|
-
/* @__PURE__ */ jsxRuntime.jsx(PrimaryText, { muted: isMissing, title:
|
|
4069
|
+
/* @__PURE__ */ jsxRuntime.jsx(PrimaryText, { muted: isMissing, title: displayName, children: isMissing ? missingLabel : displayName }),
|
|
3952
4070
|
!isMissing ? /* @__PURE__ */ jsxRuntime.jsx(FilenameText, { title: item.filename, children: item.filename }) : null
|
|
3953
4071
|
] }),
|
|
3954
4072
|
!isMissing && (showFileSize || modified) ? /* @__PURE__ */ jsxRuntime.jsxs(DocMetaInline, { children: [
|
|
@@ -3957,7 +4075,7 @@ var SelectedItem2 = ({
|
|
|
3957
4075
|
] }) : null
|
|
3958
4076
|
] }),
|
|
3959
4077
|
/* @__PURE__ */ jsxRuntime.jsxs(ActionColumn, { children: [
|
|
3960
|
-
orderable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4078
|
+
orderable ? /* @__PURE__ */ jsxRuntime.jsxs(ReorderButtons, { children: [
|
|
3961
4079
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3962
4080
|
components.Button,
|
|
3963
4081
|
{
|
|
@@ -4049,7 +4167,8 @@ var SelectedList2 = ({
|
|
|
4049
4167
|
showHeader = true,
|
|
4050
4168
|
showExtensionBadge,
|
|
4051
4169
|
showFileSize,
|
|
4052
|
-
showModifiedDate
|
|
4170
|
+
showModifiedDate,
|
|
4171
|
+
enableItemLabels = false
|
|
4053
4172
|
}) => {
|
|
4054
4173
|
const resolved = useResolvedDocuments(value);
|
|
4055
4174
|
const [activeKey, setActiveKey] = react$1.useState(null);
|
|
@@ -4064,6 +4183,22 @@ var SelectedList2 = ({
|
|
|
4064
4183
|
(key) => onChange(value.filter((i) => i.key !== key)),
|
|
4065
4184
|
[value, onChange]
|
|
4066
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
|
+
);
|
|
4067
4202
|
const reorder = react$1.useCallback(
|
|
4068
4203
|
(from, to) => {
|
|
4069
4204
|
if (from === to) return;
|
|
@@ -4112,6 +4247,10 @@ var SelectedList2 = ({
|
|
|
4112
4247
|
onRemove: () => remove(item.key),
|
|
4113
4248
|
...index > 0 ? { onMoveUp: () => reorder(index, index - 1) } : {},
|
|
4114
4249
|
...index < resolved.length - 1 ? { onMoveDown: () => reorder(index, index + 1) } : {},
|
|
4250
|
+
...enableItemLabels ? {
|
|
4251
|
+
enableLabelEdit: true,
|
|
4252
|
+
onLabelChange: (label) => setLabel(item.key, label)
|
|
4253
|
+
} : {},
|
|
4115
4254
|
...renderSelected ? { render: renderSelected } : {}
|
|
4116
4255
|
},
|
|
4117
4256
|
item.key
|
|
@@ -4134,7 +4273,7 @@ var SelectedList2 = ({
|
|
|
4134
4273
|
onDragCancel: () => setActiveKey(null),
|
|
4135
4274
|
children: [
|
|
4136
4275
|
/* @__PURE__ */ jsxRuntime.jsx(sortable.SortableContext, { items: ids, strategy: sortable.verticalListSortingStrategy, children: /* @__PURE__ */ jsxRuntime.jsx(SelectedListEl, { role: "list", children: rows }) }),
|
|
4137
|
-
/* @__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 })
|
|
4138
4277
|
]
|
|
4139
4278
|
}
|
|
4140
4279
|
)
|
|
@@ -4165,6 +4304,7 @@ var DocumentPicker = ({
|
|
|
4165
4304
|
fetchOnOpen = false,
|
|
4166
4305
|
uniqueItems = true,
|
|
4167
4306
|
enableMediaLibrary = true,
|
|
4307
|
+
enableItemLabels = false,
|
|
4168
4308
|
showExtensionBadge = true,
|
|
4169
4309
|
showFileSize = true,
|
|
4170
4310
|
showModifiedDate = false,
|
|
@@ -4256,7 +4396,14 @@ var DocumentPicker = ({
|
|
|
4256
4396
|
...allowedExtensions !== void 0 ? { allowedExtensions } : {},
|
|
4257
4397
|
multiple: false,
|
|
4258
4398
|
value,
|
|
4259
|
-
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
|
+
},
|
|
4260
4407
|
labels,
|
|
4261
4408
|
variant: "tertiary",
|
|
4262
4409
|
label: labels.replace
|
|
@@ -4274,7 +4421,8 @@ var DocumentPicker = ({
|
|
|
4274
4421
|
showHeader: value.length > 0,
|
|
4275
4422
|
showExtensionBadge,
|
|
4276
4423
|
showFileSize,
|
|
4277
|
-
showModifiedDate
|
|
4424
|
+
showModifiedDate,
|
|
4425
|
+
enableItemLabels
|
|
4278
4426
|
}
|
|
4279
4427
|
)
|
|
4280
4428
|
] }) }) });
|