mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
84e18e4954
Paste style wrote the copied fields straight onto the element, although a pasted look is meant to be the style operation the assistant sends. It now runs the engine's own restyle (bookElementStyled): a colour or face pasted by hand takes the element off the theme, so the next theme applied no longer brings the old colour back; a plain fill replaces the paint of the shape it lands on instead of staying hidden under it; and a line takes another line's look without its points, which are its course, not its look. A background picked by hand in the inspector kept the page's link to the theme, so the next theme applied set the page back to the theme's colour. The picker and the background operation now paint through one helper that takes the link away (withSpreadPaintByHand). Giving one page's background to every page carries that page's link along, or takes the others' away when it was painted by hand. A built-in layout, a book's own layout and laying a page out again from its entry ignored locks in the Studio: a locked shape was dropped and a locked photo poured into a slot unlocked, while the assistant's layout operation left both where they were. All four now lay a page out around its locked elements through one function (layoutAroundLocks), which the engine's layout operation uses too. Fill page and fill spread kept the photo in its group, so the background picture was selected and dragged with its caption and listed under the group at the front. It leaves its group as the engine's fill does, and a group left with one member goes.
72 lines
3.2 KiB
TypeScript
72 lines
3.2 KiB
TypeScript
import { bookElementStyle, bookStyleKeys, pastableStyle } from './book-style-copy';
|
|
import {
|
|
bookIconElementSchema,
|
|
bookLineElementSchema,
|
|
bookListElementSchema,
|
|
bookShapeElementSchema,
|
|
bookTextElementSchema,
|
|
type BookElement,
|
|
} from './book.schema';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/** Copy and paste style: the look `style` may set, carried onto any kind that takes it. */
|
|
|
|
const frame = { x: 0, y: 0, w: 40, h: 20 };
|
|
const text = (over = {}) =>
|
|
bookTextElementSchema.parse({ id: 't', kind: 'text', frame, text: 'Hi', ...over }) as BookElement;
|
|
const icon = (over = {}) =>
|
|
bookIconElementSchema.parse({ id: 'i', kind: 'icon', frame, name: 'Sun', ...over }) as BookElement;
|
|
const shape = (over = {}) =>
|
|
bookShapeElementSchema.parse({ id: 's', kind: 'shape', frame, shape: 'rect', ...over }) as BookElement;
|
|
|
|
describe('copy style', () => {
|
|
it('BKSTY-001: takes the look of an element and none of what it says or where it is', () => {
|
|
const style = bookElementStyle(text({ size: 24, color: '#ff0000', weight: 700, opacity: 0.5 }));
|
|
expect(style.kind).toBe('text');
|
|
expect(style.props).toMatchObject({ size: 24, color: '#ff0000', weight: 700, opacity: 0.5 });
|
|
expect(style.props).not.toHaveProperty('text');
|
|
expect(style.props).not.toHaveProperty('frame');
|
|
});
|
|
|
|
it('BKSTY-002: leaves out the props of `style` that are words rather than looks', () => {
|
|
const list = bookListElementSchema.parse({ id: 'l', kind: 'list', frame, proLabel: 'Good' }) as BookElement;
|
|
expect(bookStyleKeys('list')).not.toContain('proLabel');
|
|
expect(bookElementStyle(list).props).not.toHaveProperty('proLabel');
|
|
expect(bookStyleKeys('stats')).not.toContain('metrics');
|
|
});
|
|
|
|
it("BKSTY-005: takes a line's look and never its points, which are where it runs", () => {
|
|
const route = bookLineElementSchema.parse({
|
|
id: 'r',
|
|
kind: 'line',
|
|
frame,
|
|
points: [
|
|
{ x: 0, y: 1 },
|
|
{ x: 0.5, y: 0 },
|
|
{ x: 1, y: 1 },
|
|
],
|
|
stroke: '#c2410c',
|
|
dash: 'dashed',
|
|
}) as BookElement;
|
|
expect(bookStyleKeys('line')).not.toContain('points');
|
|
expect(bookElementStyle(route).props).toMatchObject({ stroke: '#c2410c', dash: 'dashed' });
|
|
expect(bookElementStyle(route).props).not.toHaveProperty('points');
|
|
});
|
|
|
|
it('BKSTY-003: pastes all of it onto the same kind, and what both have onto another', () => {
|
|
const style = bookElementStyle(text({ size: 24, color: '#ff0000', opacity: 0.5 }));
|
|
expect(pastableStyle(style, 'text')).toMatchObject({ kind: 'text', size: 24, color: '#ff0000' });
|
|
// An icon has a colour and an opacity, no type size.
|
|
const onIcon = pastableStyle(style, 'icon');
|
|
expect(onIcon).toEqual({ kind: 'icon', color: '#ff0000', opacity: 0.5 });
|
|
});
|
|
|
|
it('BKSTY-004: answers null when the two kinds share nothing that was set', () => {
|
|
const style = { kind: 'icon' as const, props: { lineWidth: 2 } };
|
|
expect(pastableStyle(style, 'shape')).toBeNull();
|
|
expect(pastableStyle(bookElementStyle(shape({ fill: '#00ff00' })), 'shape')).toMatchObject({ fill: '#00ff00' });
|
|
expect(pastableStyle(bookElementStyle(icon({ color: '#123456' })), 'icon')).toMatchObject({ color: '#123456' });
|
|
});
|
|
});
|