stash
This commit is contained in:
parent
9c9f0f2d9b
commit
6a9ed35bcd
11 changed files with 166 additions and 186 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import {loadAnyDCode} from "../vendor/anyd-qr.js";
|
||||
import {encodeHandleForUrl} from "@/router"
|
||||
import {drawPixelText, preloadPixelFontRenderer} from "@/pixel-font.js";
|
||||
import {DERIVED_VARS} from "@/label-layouts.js";
|
||||
import {DERIVED_VARS, CONTENT_KINDS_BY_ID} from "@/label-layouts.js";
|
||||
|
||||
// Re-exported so every caller can preload both the QR encoder and the bitmap-font rasterizer
|
||||
// (see fontTierFor's `pixel` tiers below) the same way, alongside this file's own preloadQrEncoder.
|
||||
|
|
@ -568,28 +567,17 @@ export function drawFallbackLabel(canvas, content, orientation = "along") {
|
|||
return {textSizesPx, warnings, qrInfo, textInfo};
|
||||
}
|
||||
|
||||
// Turns a {kind, components} prefill (see Print.vue's `prefill` prop) into the literal string a
|
||||
// print label should show/encode; keyed by `kind` so each kind's format is defined in one place.
|
||||
export const LABEL_CONTENT_BUILDERS = {
|
||||
// The self-contained Item URL (see docs/design-in-progress/items-labels.md), built from just
|
||||
// the prefill's {userHandle, item}; the short link (Print.vue's `shortUrl`) needs an async store
|
||||
// lookup, so it stays a separate field/template rather than being baked in here.
|
||||
"item": ({userHandle, item}) => `${window.location.origin}/i/${encodeHandleForUrl(userHandle)}/${item}`,
|
||||
// Storage locations have no long-form URL route yet (see router.js), so `text` starts blank;
|
||||
// the short link and any future location template still work via the base vars below.
|
||||
};
|
||||
|
||||
// Turns a {kind, components} prefill (see Print.vue's `prefill` prop) into the literal string a print label should show/encode, via that kind's CONTENT_KINDS_BY_ID entry.
|
||||
export function buildLabelContent(prefill) {
|
||||
if (!prefill) {
|
||||
const entry = prefill && CONTENT_KINDS_BY_ID[prefill.kind];
|
||||
const {userHandle, id} = prefill?.components ?? {};
|
||||
if (!entry?.buildUrl || !userHandle || !id) {
|
||||
return "";
|
||||
}
|
||||
const build = LABEL_CONTENT_BUILDERS[prefill.kind];
|
||||
return build ? build(prefill.components) : "";
|
||||
return entry.buildUrl({origin: window.location.origin, userHandle, id});
|
||||
}
|
||||
|
||||
// Splits a prefill's {userHandle, item/location} into label-layouts.js's user/domain base vars (the same way
|
||||
// store.js's lookupServer does), tagging on whichever id field the resource's templates key
|
||||
// required_vars by.
|
||||
// Splits a prefill's {userHandle, id} into label-layouts.js's user/domain base vars (the same way store.js's lookupServer does).
|
||||
function splitUserHandle(userHandle) {
|
||||
if (!userHandle) {
|
||||
return null;
|
||||
|
|
@ -601,32 +589,17 @@ function splitUserHandle(userHandle) {
|
|||
};
|
||||
}
|
||||
|
||||
// Seeds label-layouts.js's BASE_VARS, keyed by `kind`; derived vars (userHandle, itemUrl, …) are
|
||||
// computed live elsewhere (see DERIVED_VARS, Print.vue's `shortUrl`), and omitting a field
|
||||
// (rather than leaving it present-but-empty) signals "not available" to contentIsAvailable.
|
||||
const LABEL_FIELD_BUILDERS = {
|
||||
"item": ({userHandle, item}) => {
|
||||
const split = splitUserHandle(userHandle);
|
||||
if (!split || !item) {
|
||||
return {};
|
||||
}
|
||||
return {...split, itemId: String(item)};
|
||||
},
|
||||
"storage-location": ({userHandle, location}) => {
|
||||
const split = splitUserHandle(userHandle);
|
||||
if (!split || !location) {
|
||||
return {};
|
||||
}
|
||||
return {...split, locationId: String(location)};
|
||||
},
|
||||
};
|
||||
|
||||
// Seeds label-layouts.js's BASE_VARS from a {kind, components: {userHandle, id}} prefill - one generic function suffices now that every kind's prefill shares this shape (see CONTENT_KINDS_BY_ID).
|
||||
export function buildLabelFields(prefill) {
|
||||
if (!prefill) {
|
||||
if (!prefill || !(prefill.kind in CONTENT_KINDS_BY_ID)) {
|
||||
return {};
|
||||
}
|
||||
const build = LABEL_FIELD_BUILDERS[prefill.kind];
|
||||
return build ? build(prefill.components) : {};
|
||||
const {userHandle, id} = prefill.components ?? {};
|
||||
const split = splitUserHandle(userHandle);
|
||||
if (!split || !id) {
|
||||
return {};
|
||||
}
|
||||
return {...split, kind: prefill.kind, id: String(id)};
|
||||
}
|
||||
|
||||
// Runs each DERIVED_VARS calc against `fields`, adding the result wherever its inputs are
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue