mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
d8213bfa42
Elements can be grouped on a page and picked, moved, resized, aligned and restacked as one. A layers panel lists the page front to back with lock, visibility, rename and drag to restack. The sheet gains marquee selection, arrow-key nudge, one box that resizes a multi-selection with Shift holding the proportions, and the design-tool shortcuts. The inspector lines a selection up and spaces it out, and copies and pastes a style. The assistant gets the same through the group, ungroup, name and hide operations, and describe_book_page lists the groups. The format gains the optional group, name and hidden fields and a spread's group names, so BOOK_SCHEMA_REV goes to 2.
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { bookElementIdSchema } from './book-op-ids';
|
|
import { BOOK_LAYER_NAME_MAX } from './book.schema';
|
|
|
|
import { z } from 'zod';
|
|
|
|
/**
|
|
* The layer operations of a book page: group, ungroup, name and hide. They
|
|
* join the page operations of book-ops.schema.ts beside the element ones, run
|
|
* in the one engine (book-ops-groups.ts) the Studio's layers panel and its
|
|
* Ctrl+G use too.
|
|
*/
|
|
|
|
/** A group's id as the page has it (`g-...`), never invented. */
|
|
export const bookGroupIdSchema = z.string().regex(/^[\w-]{1,40}$/);
|
|
|
|
const layerName = z.string().max(BOOK_LAYER_NAME_MAX);
|
|
|
|
export const BOOK_GROUP_OP_SCHEMAS = [
|
|
/**
|
|
* Make two or more elements one group, picked, moved, aligned and arranged
|
|
* as one. Elements already in a group leave it for the new one.
|
|
*/
|
|
z.strictObject({
|
|
op: z.literal('group'),
|
|
elementIds: z.array(bookElementIdSchema).min(2).max(30),
|
|
name: layerName
|
|
.describe('What the group is called in the layers panel, such as "Title lockup". Optional.')
|
|
.optional(),
|
|
}),
|
|
/** Put a group's members back on their own, where they are. */
|
|
z.strictObject({ op: z.literal('ungroup'), groupId: bookGroupIdSchema }),
|
|
/** Name an element or a group in the layers panel; an empty name clears it. */
|
|
z
|
|
.strictObject({
|
|
op: z.literal('name'),
|
|
elementId: bookElementIdSchema.optional(),
|
|
groupId: bookGroupIdSchema.optional(),
|
|
name: layerName,
|
|
})
|
|
.refine((v) => (v.elementId === undefined) !== (v.groupId === undefined), {
|
|
message: 'name an elementId or a groupId, not both',
|
|
}),
|
|
/** Hide elements (kept on the page's layer list, left out of the page and its print) or show them again. */
|
|
z.strictObject({
|
|
op: z.literal('hide'),
|
|
elementIds: z.array(bookElementIdSchema).min(1).max(30),
|
|
hidden: z.boolean(),
|
|
}),
|
|
] as const;
|