Refactoring round 8: hide data files, safe saves, Esc as Cancel (#85)
Recurring cleanup round over the code since round 7 (bc688f3). The
issue now also asks to fix bugs and small inconsistencies found on the
way, so unlike the rounds before, this one changes behaviour in a few
places. Duplicated code in api went from 23 clones with 228 lines to
none (jscpd, at least 50 tokens). In src it stays at 22 clones with
271 lines, the same before and after.
Bugs:
- nginx served project and snapshot files as they were, so anyone who
knew a project id could read it without signing in. Every file the
API writes now goes through AtomicFile (temp file, mode, rename).
Projects, snapshots, releases, accounts and sessions are 0640, and
nginx answers 403 for them.
- Any signed-in account could delete a shared image, font or sound,
which projects of other accounts may wear. Deleting one is now for
administrators only. The editor never deleted a file, so the
client's delete is gone.
- Two saves of one project could run at once. The lock file was
removed after each save, so a waiting save and the next one locked
different files. The lock file now stays, and deleting a project
takes the lock as well.
- Bytes that are no picture got a 500 instead of a 422, because the
error handler also threw for warnings silenced with @.
- A session file was rewritten in place. A request reading it at that
moment found it empty and was signed out. It is replaced atomically.
- Delete did nothing for a shape picked in the vector art list. Delete
now goes through removeSelection, one case per kind of selection,
and a kind without a case fails the type check.
Inconsistencies:
- Escape on a question does what its Cancel does. Cancel on "Delete
project?" and "Restore snapshot?" leads back to the picker or the
list like the other questions did, and so does deleting a project.
- Editor texts use American spelling throughout, like the port names:
48 British spellings in 45 lines (colour, centre, initialised).
- objectName and groupName replace eleven copies of "own name, else
the asset's" and three of "Group". One copy fell back to the object
id instead of "?".
Duplicates, dead code, comments:
- routeFiles serves images, fonts and sounds instead of three copies.
HashedFileStore holds what the three stores shared: keeping a file
under its hash with its name, listing and deleting. The stores keep
only which bytes they take and what a record says.
- AtomicFile replaces nine copies of temp file plus rename.
- removeShapes is the one way the canvas, the inspector button and
Delete take shapes out.
- GraphInterpreter.fire was called by tests only. The 54 calls use a
helper in tests/helpers.ts now.
- FileStore.delete, HttpFileStore.delete and the PluginApi type were
unused. A doc comment in actions.ts sat above the wrong function.
Checked and left as is:
- solidCells is used by tests only. It is the per-cell view before the
merge into rectangles, the one place the largest-scale rule shows.
- An undo checker ran all 124 commands of the unit tests and compared
the project before and after undo. The only differences are empty
ports, groups and notes lists where there were none, which the file
format drops anyway.
Docs:
- README: the check sum.
- Wiki, own commit: API (admin-only deletes, 422, file modes, lock
file), Home (the "Not yet" list named three things that exist),
Concepts, Keyboard, Vector art, Architecture and Development, and
the 38 characters Gitea flagged as ambiguous on eight pages.
- .gitignore: the lock files, and pasted-*.png in any folder, which
keeps the screenshot archive out.
Tests:
- ./check.sh: 195 files, 2817 tests, exit 0 (+2 for the name helpers).
- PHP: accounts 52 in the web container and 53 in the CI image with
the race test (+2), snapshots 15 (+1), releases 20.
- Full e2e run: ALL PASSED, 1586 checks (+6 in 12, 47, 49 and 50).
- Smokes jumprun, tetris, actor: 24, 19 and 21 checks. The example
project files were restored byte for byte afterwards.
- The file stores of HEAD and of this commit give byte-identical
output for the live folders and for store, list and delete in a
throwaway folder.
- Counter-checks, all fail as expected: a 500 for bad bytes fails 12,
no admin check fails 49, removing the lock file again loses saves
in 3 of 3 runs (151 to 170 of 321), Delete ignoring shapes fails 47,
Escape that only closes fails 50, and dropping the shape case fails
the type check (TS2366).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bc688f3efc
commit
14972d057f
81 files changed
+663
-577
No files matched your search
@@ -49,7 +49,7 @@ export function buildAnnotationSection(host: InspectorHost, assetId: string, ann
|
||||
);
|
||||
addNote(
|
||||
host,
|
||||
'The text is drawn black or white, whichever reads better on this colour – so any colour stays legible.',
|
||||
'The text is drawn black or white, whichever reads better on this color – so any color stays legible.',
|
||||
'small',
|
||||
);
|
||||
if (annotation.color !== undefined)
|
||||
@@ -103,7 +103,7 @@ function addRow(
|
||||
|
||||
function describe(kind: AnnotationKind): string {
|
||||
return kind === 'group'
|
||||
? 'Nodes whose centre lies in the box move with it. Deleting the group leaves them where they are.'
|
||||
? 'Nodes whose center lies in the box move with it. Deleting the group leaves them where they are.'
|
||||
: 'A comment is read, not run: it frames nothing and moves alone.';
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
import { type ObjectChoice, objectChoices } from '../../core/model/objectRefs';
|
||||
import { type PropertyValue, textOf } from '../../core/model/Properties';
|
||||
import { findAsset, findObjectHolder, type Project } from '../../core/model/Project';
|
||||
import type { SceneObject } from '../../core/model/SceneObject';
|
||||
import { objectName, type SceneObject } from '../../core/model/SceneObject';
|
||||
import {
|
||||
COMMON_PROPS,
|
||||
isCommonProp,
|
||||
@@ -120,7 +120,7 @@ export function buildObjectsSection(host: InspectorHost, holderId: string, objec
|
||||
for (const id of objectIds) {
|
||||
const object = findObject(view, id);
|
||||
const asset = object && findAsset(host.state.project, object.assetId);
|
||||
if (object && asset) addNote(host, `${object.name || asset.name} · ${asset.type}`);
|
||||
if (object && asset) addNote(host, `${objectName(object, asset)} · ${asset.type}`);
|
||||
}
|
||||
addGap(host);
|
||||
addNote(host, 'Ctrl-click adds or removes objects.', 'small');
|
||||
@@ -136,7 +136,7 @@ export function buildObjectsSection(host: InspectorHost, holderId: string, objec
|
||||
new Button('Create container', { onClick: () => createContainer(host.state, holderId, objectIds) }),
|
||||
);
|
||||
addNote(host, 'Groups the selection into a reusable container', 'small');
|
||||
addNote(host, 'asset placed at its centre (Ctrl+G).', 'small');
|
||||
addNote(host, 'asset placed at its center (Ctrl+G).', 'small');
|
||||
addGap(host);
|
||||
host.body.add(
|
||||
new Button('Remove', {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SetParentCommand } from '../../core/commands/sceneObjectCommands';
|
||||
import { findObject, isSelfOrAncestor, treeOrder } from '../../core/model/hierarchy';
|
||||
import { findAsset, type ObjectHolder } from '../../core/model/Project';
|
||||
import type { SceneObject } from '../../core/model/SceneObject';
|
||||
import { objectName, type SceneObject } from '../../core/model/SceneObject';
|
||||
import { Dropdown, Label, Menu, type MenuItem } from '../../ui';
|
||||
import { labelledRow } from './fieldFactory';
|
||||
import type { InspectorHost } from './host';
|
||||
@@ -14,7 +14,7 @@ import { viewOf } from './objectQueries';
|
||||
*/
|
||||
export function parentRow(host: InspectorHost, holder: ObjectHolder, object: SceneObject, fixed: boolean) {
|
||||
const { row } = labelledRow('Parent');
|
||||
const nameOf = (o: SceneObject) => o.name || findAsset(host.state.project, o.assetId)?.name || '?';
|
||||
const nameOf = (o: SceneObject) => objectName(o, findAsset(host.state.project, o.assetId));
|
||||
const parent = findObject(holder, object.parentId);
|
||||
const name = parent ? nameOf(parent) : 'None';
|
||||
if (fixed) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
DuplicateVectorShapeCommand,
|
||||
MoveVectorShapeCommand,
|
||||
RemoveVectorShapeCommand,
|
||||
RemoveVectorShapesCommand,
|
||||
RenameVectorShapeCommand,
|
||||
SetVectorShapeStyleCommand,
|
||||
} from '../../core/commands/vectorArtCommands';
|
||||
@@ -52,6 +51,7 @@ import {
|
||||
} from '../../core/model/vectorPaint';
|
||||
import type { PropertyDef } from '../../core/properties/PropertySchema';
|
||||
import { Button, HStack, Theme } from '../../ui';
|
||||
import { removeShapes } from '../actions';
|
||||
import { type EditorState, shapeSelection } from '../state';
|
||||
import { GradientBar } from '../vectorart/GradientBar';
|
||||
import { ShapeList } from '../vectorart/ShapeList';
|
||||
@@ -74,7 +74,7 @@ interface PreviewStyle {
|
||||
export type PaintPart = 'fill' | 'stroke';
|
||||
|
||||
const FILL_KIND_LABELS: Record<FillKind, string> = {
|
||||
solid: 'Solid colour',
|
||||
solid: 'Solid color',
|
||||
linear: 'Linear gradient',
|
||||
radial: 'Radial gradient',
|
||||
texture: 'Texture',
|
||||
@@ -112,7 +112,7 @@ const TEXTURE_DEF: PropertyDef = {
|
||||
function stopDefs(part: PaintPart): { color: PropertyDef; alpha: PropertyDef; offset: PropertyDef } {
|
||||
const prefix = part === 'fill' ? 'fillStop' : 'lineStop';
|
||||
return {
|
||||
color: { key: `${prefix}Color`, label: 'Stop colour', kind: 'color', default: 0xffffff },
|
||||
color: { key: `${prefix}Color`, label: 'Stop color', kind: 'color', default: 0xffffff },
|
||||
alpha: {
|
||||
key: `${prefix}Alpha`,
|
||||
label: 'Stop opacity',
|
||||
@@ -187,7 +187,7 @@ const OPACITY_DEF: PropertyDef = {
|
||||
const OUTLINE_DEF: PropertyDef = { key: 'outline', label: 'Outline', kind: 'boolean', default: false };
|
||||
const STROKE_COLOR_DEF: PropertyDef = {
|
||||
key: 'strokeColor',
|
||||
label: 'Line colour',
|
||||
label: 'Line color',
|
||||
kind: 'color',
|
||||
default: DEFAULT_STROKE.color,
|
||||
};
|
||||
@@ -303,7 +303,7 @@ export function buildShapeSection(
|
||||
STROKE_COLOR_DEF,
|
||||
(s) => s.stroke?.color ?? DEFAULT_STROKE.color,
|
||||
(input, s) => ({ stroke: { ...strokeOf(s), color: Number(input) } }),
|
||||
'Set line colour',
|
||||
'Set line color',
|
||||
);
|
||||
else gradientRows(host, assetId, shapeId, 'stroke');
|
||||
styleRow(
|
||||
@@ -323,10 +323,7 @@ export function buildShapeSection(
|
||||
host.body.add(
|
||||
new Button('Delete shapes', {
|
||||
variant: 'danger',
|
||||
onClick: () => {
|
||||
host.state.execute(new RemoveVectorShapesCommand(assetId, shapeIds));
|
||||
host.state.select({ kind: 'asset', assetId });
|
||||
},
|
||||
onClick: () => removeShapes(host.state, assetId, shapeIds),
|
||||
}),
|
||||
);
|
||||
host.body.add(addShapeButton(host, assetId));
|
||||
@@ -683,9 +680,9 @@ function gradientRows(host: InspectorHost, assetId: string, shapeId: string, par
|
||||
},
|
||||
label,
|
||||
);
|
||||
stopRow(defs.color, (stop) => stop.color, 'color', 'Set stop colour');
|
||||
stopRow(defs.color, (stop) => stop.color, 'color', 'Set stop color');
|
||||
stopRow(defs.alpha, (stop) => stop.alpha, 'alpha', 'Set stop opacity');
|
||||
stopRow(defs.offset, (stop) => stop.offset, 'offset', 'Move colour stop');
|
||||
stopRow(defs.offset, (stop) => stop.offset, 'offset', 'Move color stop');
|
||||
|
||||
const remove = new Button('Remove stop', {
|
||||
variant: 'ghost',
|
||||
@@ -701,7 +698,7 @@ function gradientRows(host: InspectorHost, assetId: string, shapeId: string, par
|
||||
assetId,
|
||||
shapeId,
|
||||
withGradient(shape, part, next),
|
||||
'Remove colour stop',
|
||||
'Remove color stop',
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user