@bison-lab/payload-core 4.12.0 → 4.12.1
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 +5 -0
- package/dist/admin.d.mts +6 -0
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +135 -36
- package/dist/admin.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -351,6 +351,11 @@ Turning a card off distinguishes published from draft:
|
|
|
351
351
|
transaction. Published versions are never written. Cancel leaves it on.
|
|
352
352
|
- **Unused** — off, no dialog.
|
|
353
353
|
|
|
354
|
+
Save leaves the form clean: the field reads each row from Payload's own
|
|
355
|
+
row fields and writes one column at a time, never the array path and never
|
|
356
|
+
on load, so after a Save the button disables again, leaving the page asks
|
|
357
|
+
nothing, and a switch flipped straight after a Save holds (BIS-135).
|
|
358
|
+
|
|
354
359
|
The server is the authority: the Save hook re-reads usage, refuses while
|
|
355
360
|
anything published holds the slug, and strips drafts otherwise, whether
|
|
356
361
|
the Save came from the admin or the API. The admin asks
|
package/dist/admin.d.mts
CHANGED
|
@@ -198,6 +198,12 @@ declare const FeaturesMatrixField: ArrayFieldClientComponent;
|
|
|
198
198
|
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
199
199
|
* while a published document holds it, and asks before a Save that strips
|
|
200
200
|
* it from drafts.
|
|
201
|
+
*
|
|
202
|
+
* Form contract (BIS-135): rows are read from Payload's per-row fields and
|
|
203
|
+
* written one column at a time. The field never writes the array path and
|
|
204
|
+
* never marks the form modified on its own; a catalogue entry the stored
|
|
205
|
+
* rows lack is added to local form state without that mark. So a Save
|
|
206
|
+
* leaves the form clean and the server's post-Save state is what shows.
|
|
201
207
|
*/
|
|
202
208
|
declare const BlockLibraryField: ArrayFieldClientComponent;
|
|
203
209
|
//#endregion
|
package/dist/admin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.mts","names":[],"sources":["../src/admin/color-field.tsx","../src/admin/color-scale-field.tsx","../src/admin/library-field.tsx","../src/admin/font-field.tsx","../src/admin/pairing-field.tsx","../src/admin/appearance-field.tsx","../src/admin/grey-scale-field.tsx","../src/admin/contrast-report.tsx","../src/admin/section-heading.tsx","../src/admin/publish-child.tsx","../src/admin/save-button.tsx","../src/admin/preview-mode.tsx","../src/admin/identity-fallback.tsx","../src/admin/look-field.tsx","../src/admin/roles-matrix-field.tsx","../src/admin/roles-row-label.tsx","../src/admin/role-slug-field.tsx","../src/admin/slug-field.tsx","../src/admin/page-title-cell.tsx","../src/admin/page-slug-cell.tsx","../src/admin/required-page-cell.tsx","../src/admin/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-field.tsx","../src/admin/block-library-field.tsx","../src/admin/document-title-actions.tsx","../src/admin/list-align-styles.tsx","../src/admin/document-create-new.tsx","../src/admin-nav/types.ts","../src/admin/admin-nav.tsx","../src/admin/admin-nav-row-label.tsx","../src/admin/admin-nav-item-row-label.tsx","../src/admin/admin-nav-entity-field.tsx","../src/taxonomy/facet-field.ts","../src/questions/types.ts","../src/admin/questions-list.tsx","../src/admin/media-alt-autofill.tsx","../src/admin/media-list-view.tsx"],"mappings":";;;;;;;;;;;cAWa,UAAA,EAAY,wBAAA;;;;;;;;cCuBZ,eAAA,EAAiB,yBAAA;;;;;;;;;cCMjB,YAAA,EAAc,yBAAA;;;;;;;;;cCtBd,SAAA,EAAW,0BAAA;;;;;;;cCNX,YAAA,EAAc,sBAAA;;;;;;;cCCd,eAAA,EAAiB,yBAAA;;;ALF9B;;;;AAAA,cM4Da,cAAA,EAAgB,0BAAA;;;;;;;cCnDhB,cAAA,EAAgB,sBAAA;;;;;;cCbhB,cAAA,EAAgB,sBAAA;;;cC0IhB,YAAA,EAAc,sBAAA;;;;;;;;iBCtIX,qBAAA,CAAA;;AVAhB;;;iBUQgB,eAAA,CAAA,GAAe,kBAAA,CAAA,GAAA,CAAA,OAAA;;iBA0Bf,gBAAA,CAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;KCpCpB,gBAAA;AAAA,iBAgDI,mBAAA,CAAoB,IAAA,EAAM,gBAAA;;;;;;;cCjD7B,gBAAA,EAAkB,sBAAA;;;;;;;cCIlB,SAAA,EAAW,wBAAA;;;;;;;;cCqBX,gBAAA,EAAkB,yBAAA;;;;;;iBC1Bf,aAAA,CAAA,GAAa,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;cCChB,aAAA,EAAe,wBAAA;;;;;;;;;cC4Bf,SAAA,EAAW,wBAAA;;;;;;;iBC3BR,aAAA,CAAc,KAAA,EAAO,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;iBCJ9C,YAAA,CAAA;EAAe,QAAA;EAAU;AAAA,GAAW,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;cCEhE,iBAAA,EAAmB,wBAAA;AAAA,iBAEhB,gBAAA,CAAA;EAAmB;AAAA,GAAW,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;cCA1D,aAAA,EAAe,wBAAA;;;;;;;;cC8Cf,UAAA,EAAY,0BAAA;;;;;;;;cCpBZ,gBAAA,EAAkB,wBAAA;;;;;;;;;AvBxB/B;;cwB2Ca,mBAAA,EAAqB,yBAAA;;;;;;;;;AxB3ClC
|
|
1
|
+
{"version":3,"file":"admin.d.mts","names":[],"sources":["../src/admin/color-field.tsx","../src/admin/color-scale-field.tsx","../src/admin/library-field.tsx","../src/admin/font-field.tsx","../src/admin/pairing-field.tsx","../src/admin/appearance-field.tsx","../src/admin/grey-scale-field.tsx","../src/admin/contrast-report.tsx","../src/admin/section-heading.tsx","../src/admin/publish-child.tsx","../src/admin/save-button.tsx","../src/admin/preview-mode.tsx","../src/admin/identity-fallback.tsx","../src/admin/look-field.tsx","../src/admin/roles-matrix-field.tsx","../src/admin/roles-row-label.tsx","../src/admin/role-slug-field.tsx","../src/admin/slug-field.tsx","../src/admin/page-title-cell.tsx","../src/admin/page-slug-cell.tsx","../src/admin/required-page-cell.tsx","../src/admin/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-field.tsx","../src/admin/block-library-field.tsx","../src/admin/document-title-actions.tsx","../src/admin/list-align-styles.tsx","../src/admin/document-create-new.tsx","../src/admin-nav/types.ts","../src/admin/admin-nav.tsx","../src/admin/admin-nav-row-label.tsx","../src/admin/admin-nav-item-row-label.tsx","../src/admin/admin-nav-entity-field.tsx","../src/taxonomy/facet-field.ts","../src/questions/types.ts","../src/admin/questions-list.tsx","../src/admin/media-alt-autofill.tsx","../src/admin/media-list-view.tsx"],"mappings":"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"}
|
package/dist/admin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { a as colorDocFromState, i as SYSTEM_COLOR_KEYS, n as pageEditorLooks, r as pageEditorTokens, s as stateFromColorDoc } from "./looks-BbL309kO.mjs";
|
|
3
|
-
import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAuth, useBulkUpload, useConfig, useEntityVisibility, useField, useForm, useFormFields, useListDrawerContext, useListQuery, useModal, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
|
|
3
|
+
import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAllFormFields, useAuth, useBulkUpload, useConfig, useEntityVisibility, useField, useForm, useFormFields, useListDrawerContext, useListQuery, useModal, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
|
|
4
4
|
import { GREY_SCALES, SHADE_STEPS, contrastForeground, contrastRatio, createColorScale, deriveDarkPalette, deriveLightPalette, hexToHSL, hslToString, includedShadeSteps, isThemeHex, presetHints, regenerateColorScale, setColorScaleInclude, updateColorScale } from "@bison-lab/tokens";
|
|
5
5
|
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -3928,7 +3928,7 @@ function isUsage(value) {
|
|
|
3928
3928
|
* publish without its hero). A disabled block keeps its ticks; they matter
|
|
3929
3929
|
* again when it is re-enabled.
|
|
3930
3930
|
*/
|
|
3931
|
-
function SectionControlTicks({ row,
|
|
3931
|
+
function SectionControlTicks({ row, write }) {
|
|
3932
3932
|
if (row.kind === "navbar") return null;
|
|
3933
3933
|
const controls = sectionControlsOf(row.sectionControls, defaultSectionControls(row.kind));
|
|
3934
3934
|
const locked = (key) => key === "hidden" && row.kind === "hero";
|
|
@@ -3943,12 +3943,9 @@ function SectionControlTicks({ row, onChange }) {
|
|
|
3943
3943
|
...locked(key) ? { "data-locked": "" } : {},
|
|
3944
3944
|
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
3945
3945
|
checked: locked(key) ? false : controls[key],
|
|
3946
|
-
disabled: locked(key),
|
|
3946
|
+
disabled: locked(key) || !write,
|
|
3947
3947
|
"aria-label": SECTION_CONTROL_LABELS[key],
|
|
3948
|
-
onCheckedChange: (checked) =>
|
|
3949
|
-
...controls,
|
|
3950
|
-
[key]: checked === true
|
|
3951
|
-
})
|
|
3948
|
+
onCheckedChange: (checked) => write?.(`sectionControls.${key}`, checked === true)
|
|
3952
3949
|
}), /* @__PURE__ */ jsx("span", {
|
|
3953
3950
|
"aria-hidden": true,
|
|
3954
3951
|
children: SECTION_CONTROL_LABELS[key]
|
|
@@ -3956,15 +3953,11 @@ function SectionControlTicks({ row, onChange }) {
|
|
|
3956
3953
|
}, key))]
|
|
3957
3954
|
});
|
|
3958
3955
|
}
|
|
3959
|
-
function LibraryCard({
|
|
3960
|
-
const { setValue: setEnabled } = useField({ path: `${path}.${index}.enabled` });
|
|
3956
|
+
function LibraryCard({ row, write, src, toggle, usageURL }) {
|
|
3961
3957
|
const [refusal, setRefusal] = useState(null);
|
|
3962
3958
|
const [drafts, setDrafts] = useState(null);
|
|
3963
3959
|
const [checking, setChecking] = useState(false);
|
|
3964
|
-
const apply = (enabled) =>
|
|
3965
|
-
setEnabled(enabled);
|
|
3966
|
-
setRow(index, { enabled });
|
|
3967
|
-
};
|
|
3960
|
+
const apply = (enabled) => write?.("enabled", enabled);
|
|
3968
3961
|
/**
|
|
3969
3962
|
* Off asks the server where the slug is used. Published refuses; drafts
|
|
3970
3963
|
* only ask first, because the Save that turns it off deletes those rows.
|
|
@@ -3990,7 +3983,7 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
3990
3983
|
children: [
|
|
3991
3984
|
/* @__PURE__ */ jsxs("header", { children: [/* @__PURE__ */ jsx("span", { children: row.label }), toggle ? /* @__PURE__ */ jsx(Switch, {
|
|
3992
3985
|
checked: row.enabled !== false,
|
|
3993
|
-
disabled: checking,
|
|
3986
|
+
disabled: checking || !write,
|
|
3994
3987
|
"aria-label": `Enable ${row.label}`,
|
|
3995
3988
|
onCheckedChange: (enabled) => {
|
|
3996
3989
|
if (enabled) {
|
|
@@ -4001,7 +3994,7 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
4001
3994
|
}) : null] }),
|
|
4002
3995
|
/* @__PURE__ */ jsx(SectionControlTicks, {
|
|
4003
3996
|
row,
|
|
4004
|
-
|
|
3997
|
+
write
|
|
4005
3998
|
}),
|
|
4006
3999
|
refusal ? /* @__PURE__ */ jsx("p", {
|
|
4007
4000
|
className: "bl-block-library__refusal",
|
|
@@ -4035,6 +4028,30 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
4035
4028
|
]
|
|
4036
4029
|
});
|
|
4037
4030
|
}
|
|
4031
|
+
function rowState(row) {
|
|
4032
|
+
const state = {};
|
|
4033
|
+
const put = (key, value) => {
|
|
4034
|
+
state[key] = {
|
|
4035
|
+
value,
|
|
4036
|
+
initialValue: value,
|
|
4037
|
+
valid: true
|
|
4038
|
+
};
|
|
4039
|
+
};
|
|
4040
|
+
put("id", row.id);
|
|
4041
|
+
put("slug", row.slug);
|
|
4042
|
+
put("label", row.label);
|
|
4043
|
+
put("category", row.category);
|
|
4044
|
+
put("enabled", row.enabled);
|
|
4045
|
+
put("kind", row.kind);
|
|
4046
|
+
for (const key of SECTION_CONTROL_KEYS) put(`sectionControls.${key}`, row.sectionControls[key]);
|
|
4047
|
+
return state;
|
|
4048
|
+
}
|
|
4049
|
+
/** The form index of the row holding `slug`, read off the fields as they are now. */
|
|
4050
|
+
function indexOfSlug(fields, path, slug) {
|
|
4051
|
+
const count = rowCount(fields, path);
|
|
4052
|
+
for (let i = 0; i < count; i += 1) if (fields[`${path}.${i}.slug`]?.value === slug) return i;
|
|
4053
|
+
return -1;
|
|
4054
|
+
}
|
|
4038
4055
|
function asRows(value) {
|
|
4039
4056
|
return Array.isArray(value) ? value : [];
|
|
4040
4057
|
}
|
|
@@ -4049,40 +4066,124 @@ function previewsOf(field) {
|
|
|
4049
4066
|
function seededRows(field) {
|
|
4050
4067
|
return asRows(customOf(field).rows);
|
|
4051
4068
|
}
|
|
4069
|
+
function isKind(value) {
|
|
4070
|
+
return value === "hero" || value === "section" || value === "navbar";
|
|
4071
|
+
}
|
|
4072
|
+
/**
|
|
4073
|
+
* How many rows the form holds. Payload keeps an array field's *count* at
|
|
4074
|
+
* its path (`blocks.value`), never the rows; each row's columns sit at
|
|
4075
|
+
* `blocks.<i>.<name>`. The count is read off `rows` when present, so a row
|
|
4076
|
+
* added client-side counts too.
|
|
4077
|
+
*/
|
|
4078
|
+
function rowCount(fields, path) {
|
|
4079
|
+
const field = fields[path];
|
|
4080
|
+
if (Array.isArray(field?.rows)) return field.rows.length;
|
|
4081
|
+
return typeof field?.value === "number" ? field.value : 0;
|
|
4082
|
+
}
|
|
4083
|
+
/**
|
|
4084
|
+
* The rows as the form holds them, read column by column. A column a
|
|
4085
|
+
* stored row lacks (the ticks, before the migration that added them)
|
|
4086
|
+
* takes the catalogue's seeded value for that slug. Reading never writes:
|
|
4087
|
+
* the stored values stand until an editor changes one.
|
|
4088
|
+
*/
|
|
4089
|
+
function rowsFromFields(fields, path, seeded) {
|
|
4090
|
+
const count = rowCount(fields, path);
|
|
4091
|
+
const rows = [];
|
|
4092
|
+
for (let i = 0; i < count; i += 1) {
|
|
4093
|
+
const read = (name) => fields[`${path}.${i}.${name}`]?.value;
|
|
4094
|
+
const slug = read("slug");
|
|
4095
|
+
if (typeof slug !== "string" || !slug) continue;
|
|
4096
|
+
const seed = seeded.find((entry) => entry.slug === slug);
|
|
4097
|
+
const kind = read("kind");
|
|
4098
|
+
const resolvedKind = isKind(kind) ? kind : seed?.kind ?? "section";
|
|
4099
|
+
const ticks = {};
|
|
4100
|
+
for (const key of SECTION_CONTROL_KEYS) ticks[key] = read(`sectionControls.${key}`);
|
|
4101
|
+
const label = read("label");
|
|
4102
|
+
const category = read("category");
|
|
4103
|
+
const enabled = read("enabled");
|
|
4104
|
+
const id = read("id");
|
|
4105
|
+
rows.push({
|
|
4106
|
+
id: typeof id === "string" ? id : slug,
|
|
4107
|
+
slug,
|
|
4108
|
+
label: typeof label === "string" ? label : seed?.label ?? slug,
|
|
4109
|
+
category: typeof category === "string" ? category : seed?.category ?? "content",
|
|
4110
|
+
enabled: typeof enabled === "boolean" ? enabled : true,
|
|
4111
|
+
kind: resolvedKind,
|
|
4112
|
+
sectionControls: sectionControlsOf(ticks, seed?.sectionControls ?? defaultSectionControls(resolvedKind))
|
|
4113
|
+
});
|
|
4114
|
+
}
|
|
4115
|
+
return rows;
|
|
4116
|
+
}
|
|
4052
4117
|
/**
|
|
4053
4118
|
* Category rail and a gallery of live islands. Each island is the sample
|
|
4054
4119
|
* at `previewPath(slug)` under the published theme (the route is SPI-53).
|
|
4055
4120
|
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
4056
4121
|
* while a published document holds it, and asks before a Save that strips
|
|
4057
4122
|
* it from drafts.
|
|
4123
|
+
*
|
|
4124
|
+
* Form contract (BIS-135): rows are read from Payload's per-row fields and
|
|
4125
|
+
* written one column at a time. The field never writes the array path and
|
|
4126
|
+
* never marks the form modified on its own; a catalogue entry the stored
|
|
4127
|
+
* rows lack is added to local form state without that mark. So a Save
|
|
4128
|
+
* leaves the form clean and the server's post-Save state is what shows.
|
|
4058
4129
|
*/
|
|
4059
4130
|
const BlockLibraryField = (props) => {
|
|
4060
|
-
const
|
|
4131
|
+
const [fields, dispatch] = useAllFormFields();
|
|
4132
|
+
const { setModified } = useForm();
|
|
4061
4133
|
const { config } = useConfig();
|
|
4062
4134
|
const usageURL = `${config.serverURL ?? ""}${config.routes?.api ?? "/api"}/globals/${BLOCK_LIBRARY_SLUG}/usage`;
|
|
4063
|
-
const loaded = asRows(value);
|
|
4064
4135
|
const seeded = seededRows(props.field);
|
|
4065
|
-
const
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4136
|
+
const loaded = useMemo(() => rowsFromFields(fields, props.path, seeded), [
|
|
4137
|
+
fields,
|
|
4138
|
+
props.path,
|
|
4139
|
+
seeded
|
|
4140
|
+
]);
|
|
4141
|
+
const fieldsRef = useRef(fields);
|
|
4142
|
+
fieldsRef.current = fields;
|
|
4143
|
+
const missing = useMemo(() => seeded.filter((entry) => !loaded.some((row) => row.slug === entry.slug)), [loaded, seeded]);
|
|
4144
|
+
const added = useRef(null);
|
|
4072
4145
|
useEffect(() => {
|
|
4073
|
-
if (
|
|
4146
|
+
if (missing.length === 0) return;
|
|
4147
|
+
const current = fields;
|
|
4148
|
+
const asked = added.current?.fields === current ? added.current.slugs : /* @__PURE__ */ new Set();
|
|
4149
|
+
for (const entry of missing) {
|
|
4150
|
+
if (asked.has(entry.slug)) continue;
|
|
4151
|
+
asked.add(entry.slug);
|
|
4152
|
+
dispatch({
|
|
4153
|
+
type: "ADD_ROW",
|
|
4154
|
+
path: props.path,
|
|
4155
|
+
subFieldState: rowState(entry)
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4158
|
+
added.current = {
|
|
4159
|
+
fields: current,
|
|
4160
|
+
slugs: asked
|
|
4161
|
+
};
|
|
4074
4162
|
}, [
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4163
|
+
dispatch,
|
|
4164
|
+
fields,
|
|
4165
|
+
missing,
|
|
4166
|
+
props.path
|
|
4078
4167
|
]);
|
|
4168
|
+
const writeRow = useCallback((slug) => (column, value) => {
|
|
4169
|
+
const index = indexOfSlug(fieldsRef.current, props.path, slug);
|
|
4170
|
+
if (index < 0) return;
|
|
4171
|
+
dispatch({
|
|
4172
|
+
type: "UPDATE",
|
|
4173
|
+
path: `${props.path}.${index}.${column}`,
|
|
4174
|
+
value
|
|
4175
|
+
});
|
|
4176
|
+
setModified(true);
|
|
4177
|
+
}, [
|
|
4178
|
+
dispatch,
|
|
4179
|
+
props.path,
|
|
4180
|
+
setModified
|
|
4181
|
+
]);
|
|
4182
|
+
const rows = [...loaded, ...missing];
|
|
4079
4183
|
const previews = previewsOf(props.field);
|
|
4080
4184
|
const [category, setCategory] = useState("hero");
|
|
4081
4185
|
const navbarCount = rows.filter((row) => row.kind === "navbar").length;
|
|
4082
|
-
const visible = rows.
|
|
4083
|
-
row,
|
|
4084
|
-
index
|
|
4085
|
-
})).filter(({ row }) => row.category === category);
|
|
4186
|
+
const visible = rows.filter((row) => row.category === category);
|
|
4086
4187
|
return /* @__PURE__ */ jsx(KitProvider, { children: /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsxs("div", {
|
|
4087
4188
|
className: "bl-block-library",
|
|
4088
4189
|
children: [
|
|
@@ -4102,11 +4203,9 @@ const BlockLibraryField = (props) => {
|
|
|
4102
4203
|
children: entry.label
|
|
4103
4204
|
}, entry.id))
|
|
4104
4205
|
}),
|
|
4105
|
-
/* @__PURE__ */ jsx("div", { children: visible.map((
|
|
4106
|
-
path: props.path,
|
|
4107
|
-
index,
|
|
4206
|
+
/* @__PURE__ */ jsx("div", { children: visible.map((row) => /* @__PURE__ */ jsx(LibraryCard, {
|
|
4108
4207
|
row,
|
|
4109
|
-
|
|
4208
|
+
write: loaded.some((entry) => entry.slug === row.slug) ? writeRow(row.slug) : null,
|
|
4110
4209
|
src: previews[row.slug] ?? "",
|
|
4111
4210
|
toggle: row.kind !== "navbar" || navbarCount > 1,
|
|
4112
4211
|
usageURL
|