@sectile/core 0.2.1 → 0.3.0

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.
@@ -0,0 +1,24 @@
1
+ import type { Result } from './shared.js';
2
+ import { type PopupEvent } from './internal/composites/popup.js';
3
+ export type DrawerSide = 'top' | 'right' | 'bottom' | 'left';
4
+ export interface DrawerState {
5
+ readonly open: boolean;
6
+ readonly side: DrawerSide;
7
+ }
8
+ export type DrawerEvent = PopupEvent | {
9
+ readonly type: 'set-side';
10
+ readonly side: DrawerSide;
11
+ };
12
+ export type DrawerCommand = {
13
+ readonly type: 'request-initial-focus';
14
+ } | {
15
+ readonly type: 'request-focus-restore';
16
+ };
17
+ export interface DrawerUpdate {
18
+ readonly state: DrawerState;
19
+ readonly commands: readonly DrawerCommand[];
20
+ }
21
+ export declare function createDrawerState(open?: boolean, side?: DrawerSide): DrawerState;
22
+ export declare function tryCreateDrawerState(open?: boolean, side?: DrawerSide): Result<DrawerState>;
23
+ export declare function applyDrawerEvent(state: DrawerState, event: DrawerEvent): Result<DrawerUpdate>;
24
+ //# sourceMappingURL=drawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drawer.d.ts","sourceRoot":"","sources":["../src/drawer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAEL,KAAK,UAAU,EAChB,MAAM,gCAAgC,CAAC;AAIxC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAA;CAAE,CAAC;AACpH,MAAM,WAAW,YAAY;IAAG,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE;AAE1G,wBAAgB,iBAAiB,CAAC,IAAI,UAAQ,EAAE,IAAI,GAAE,UAAqB,GAAG,WAAW,CAExF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,UAAQ,EAAE,IAAI,GAAE,UAAqB,GAAG,MAAM,CAAC,WAAW,CAAC,CAInG;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,CAkB7F"}
package/dist/drawer.js ADDED
@@ -0,0 +1,36 @@
1
+ import { unwrap } from './result.js';
2
+ import { applyPopupEvent, } from './internal/composites/popup.js';
3
+ import { fail, ok } from './internal/kernel/foundation.js';
4
+ import { createMachineUpdate } from './internal/kernel/machine.js';
5
+ export function createDrawerState(open = false, side = 'bottom') {
6
+ return unwrap(tryCreateDrawerState(open, side));
7
+ }
8
+ export function tryCreateDrawerState(open = false, side = 'bottom') {
9
+ if (typeof open !== 'boolean')
10
+ return fail('construction', 'invalid-drawer-open', 'Drawer open state must be boolean.');
11
+ if (!isDrawerSide(side))
12
+ return fail('construction', 'invalid-drawer-side', 'Drawer side must be top, right, bottom, or left.');
13
+ return ok(Object.freeze({ open, side }));
14
+ }
15
+ export function applyDrawerEvent(state, event) {
16
+ const valid = tryCreateDrawerState(state.open, state.side);
17
+ if (!valid.ok)
18
+ return fail('transition-rejection', valid.error.code, valid.error.message);
19
+ if (typeof event === 'object' && event.type === 'set-side') {
20
+ if (!isDrawerSide(event.side))
21
+ return fail('transition-rejection', 'invalid-drawer-side', 'Drawer side must be top, right, bottom, or left.');
22
+ if (event.side === state.side)
23
+ return createMachineUpdate(state);
24
+ return createMachineUpdate(Object.freeze({ open: state.open, side: event.side }));
25
+ }
26
+ const result = applyPopupEvent({ open: state.open }, event);
27
+ if (!result.ok)
28
+ return result;
29
+ return createMachineUpdate(Object.freeze({ open: result.value.state.open, side: state.side }), result.value.commands.map((command) => ({
30
+ type: command.type === 'popup-opened' ? 'request-initial-focus' : 'request-focus-restore',
31
+ })));
32
+ }
33
+ function isDrawerSide(value) {
34
+ return value === 'top' || value === 'right' || value === 'bottom' || value === 'left';
35
+ }
36
+ //# sourceMappingURL=drawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drawer.js","sourceRoot":"","sources":["../src/drawer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,eAAe,GAEhB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAanE,MAAM,UAAU,iBAAiB,CAAC,IAAI,GAAG,KAAK,EAAE,IAAI,GAAe,QAAQ;IACzE,OAAO,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAI,GAAG,KAAK,EAAE,IAAI,GAAe,QAAQ;IAC5E,IAAI,OAAO,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,cAAc,EAAE,qBAAqB,EAAE,oCAAoC,CAAC,CAAC;IACxH,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,cAAc,EAAE,qBAAqB,EAAE,kDAAkD,CAAC,CAAC;IAChI,OAAO,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,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AC,CAAC;QACtC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,uBAAgC,CAAC,CAAC,CAAC,uBAAgC;KAC5G,CAAC,CAAC,CACJ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,MAAM,CAAC;AACxF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sectile/core",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Renderer-neutral interaction semantics with explicit laws, failures, and costs.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -258,6 +258,11 @@
258
258
  "import": "./dist/dialog.js",
259
259
  "default": "./dist/dialog.js"
260
260
  },
261
+ "./drawer": {
262
+ "types": "./dist/drawer.d.ts",
263
+ "import": "./dist/drawer.js",
264
+ "default": "./dist/drawer.js"
265
+ },
261
266
  "./popover": {
262
267
  "types": "./dist/popover.d.ts",
263
268
  "import": "./dist/popover.js",
@@ -380,7 +385,7 @@
380
385
  "build": "node scripts/build.mjs production",
381
386
  "build:verification": "node scripts/build.mjs verification",
382
387
  "typecheck": "tsc --project tsconfig.json --pretty false",
383
- "test": "pnpm --silent run build:verification && node --test tests/*/*.test.mjs",
388
+ "test": "pnpm --silent run build:verification && node --test --test-concurrency=1 tests/*/*.test.mjs",
384
389
  "benchmark": "pnpm run build && node benchmarks/structures.mjs",
385
390
  "verify:theory": "node scripts/verify-theory.mjs",
386
391
  "verify:reproducible-build": "node scripts/check-reproducible-build.mjs",