mnfst-types 0.1.7 → 0.1.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-types",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Generate TypeScript types for a Manifest project from manifest.json and sample data",
5
5
  "type": "module",
6
6
  "bin": {
@@ -184,8 +184,8 @@ export interface ManifestUrl {
184
184
  [param: string]: ManifestUrlParam;
185
185
  }
186
186
 
187
- /** `$route` magic — true if the current route matches the given pattern. */
188
- export type ManifestRoute = (pattern: string) => boolean;
187
+ /** `$route` magic — the current route path (e.g. '/docs/elements'). */
188
+ export type ManifestRoute = string;
189
189
 
190
190
  /**
191
191
  * `$modify('attr')` — exposed in component HTML. Returns the value of an
@@ -268,7 +268,17 @@ export type ManifestExport = (opts?: {
268
268
  [extra: string]: unknown;
269
269
  }) => Promise<unknown>;
270
270
 
271
- /** `$device` from the utilities plugin (enriched by the native plugin when present). */
271
+ /** `$import(opts)` from the import plugin — pick a local file and parse it (json/csv). Resolves the parsed data, or null when the dialog is dismissed. */
272
+ export type ManifestImport = (opts?: {
273
+ format?: 'json' | 'csv';
274
+ /** Data source to replace with the parsed content. */
275
+ source?: string;
276
+ /** Override the file input's accept list. */
277
+ accept?: string;
278
+ [extra: string]: unknown;
279
+ }) => Promise<unknown>;
280
+
281
+ /** `$device` from the utilities plugin (enriched by the device plugin when present). */
272
282
  export interface ManifestDevice {
273
283
  readonly os: string;
274
284
  readonly touch: boolean;
@@ -278,18 +288,25 @@ export interface ManifestDevice {
278
288
  readonly platform: string;
279
289
  }
280
290
 
281
- /** `$share` from the native plugin — native sheet, web share, or clipboard fallback. */
291
+ /** `$share` from the device plugin — native sheet, web share, or clipboard fallback. */
282
292
  export type ManifestShare = (opts?: { title?: string; text?: string; url?: string }) =>
283
293
  Promise<{ shared: boolean; method: string; cancelled?: boolean }>;
284
294
 
285
- /** `$push` from the native plugin — push/notification permissions and token. */
295
+ /** `$push` from the device plugin — push/notification permissions and token. */
286
296
  export interface ManifestPush {
287
- request(): Promise<string>;
297
+ /** Ask for permission, on your schedule (never prompted on load). */
298
+ request(): Promise<'granted' | 'denied' | 'prompt' | 'unsupported' | string>;
299
+ /** Register with the platform push service (no-op on the web). */
300
+ register(): Promise<unknown>;
301
+ onToken(handler: (token: string) => void): void;
302
+ onReceive(handler: (notification: unknown) => void): void;
303
+ onTap(handler: (notification: unknown) => void): void;
288
304
  readonly permission: string;
305
+ readonly token: string | null;
289
306
  [extra: string]: unknown;
290
307
  }
291
308
 
292
- /** `$secure` from the native plugin — secure key-value storage (native keychain or fallback). */
309
+ /** `$secure` from the device plugin — secure key-value storage (native keychain or fallback). */
293
310
  export interface ManifestSecure {
294
311
  get(key: string): Promise<string | null>;
295
312
  set(key: string, value: string): Promise<void>;
@@ -299,38 +316,244 @@ export interface ManifestSecure {
299
316
  use(adapter: unknown): void;
300
317
  }
301
318
 
302
- /** `$links` from the native plugin — deep/universal link handling. */
319
+ /** `$links` from the device plugin — deep/universal link handling. */
303
320
  export interface ManifestLinks {
304
- on(handler: (url: string) => void): void;
321
+ /** Take over an inbound link: link.url is the full URL, link.path the route it maps to. */
322
+ on(handler: (link: { url: string; path: string }) => void): void;
305
323
  open(url: string): void;
306
324
  readonly last: string | null;
307
325
  }
308
326
 
309
- /** `$app` from the native plugin — foreground/background state. */
327
+ /** `$app` from the device plugin — foreground/background state. */
310
328
  export interface ManifestApp {
311
329
  readonly active: boolean;
312
330
  onChange(handler: (active: boolean) => void): void;
313
331
  }
314
332
 
315
- /** `$haptics` from the native plugin — haptic feedback with web vibration fallback. */
333
+ /** `$haptics` from the device plugin — haptic feedback with web vibration fallback. */
316
334
  export interface ManifestHaptics {
317
- impact(style?: string): Promise<unknown>;
318
- notification(type?: string): Promise<unknown>;
335
+ impact(style?: 'LIGHT' | 'MEDIUM' | 'HEAVY' | string): Promise<unknown>;
336
+ notification(type?: 'SUCCESS' | 'WARNING' | 'ERROR' | string): Promise<unknown>;
337
+ selection(): Promise<unknown>;
338
+ vibrate(ms?: number): Promise<unknown> | unknown;
319
339
  [extra: string]: unknown;
320
340
  }
321
341
 
322
- /** `$biometric` from the native plugin. */
342
+ /** `$biometric` from the device plugin. */
323
343
  export interface ManifestBiometric {
324
344
  available(): Promise<boolean>;
325
345
  verify(opts?: Record<string, unknown>): Promise<unknown>;
326
346
  }
327
347
 
328
- /** `$camera` from the native plugin. */
348
+ /** `$camera` from the device plugin. */
329
349
  export interface ManifestCamera {
330
350
  photo(opts?: Record<string, unknown>): Promise<unknown>;
331
351
  pick(opts?: Record<string, unknown>): Promise<unknown>;
332
352
  }
333
353
 
354
+ /** Edit action names for `$edit.can()` and per-action locks. */
355
+ export type ManifestEditAction = 'move' | 'remove' | 'duplicate' | 'text' | 'attrs' | 'size';
356
+ /** `can()` also answers 'class' (the class list; component nodes allow only this) and copy/cut/paste. */
357
+
358
+ /** Class controls on `$edit.classes`. `el` defaults to `$edit.target`. */
359
+ export interface ManifestEditClasses {
360
+ add(cls: string, el?: Element): boolean;
361
+ remove(cls: string, el?: Element): boolean;
362
+ toggle(cls: string, el?: Element, force?: boolean): boolean;
363
+ has(cls: string, el?: Element): boolean;
364
+ /** Replace the static class list. */
365
+ set(value: string, el?: Element): boolean;
366
+ /** The static classes (bound :class classes excluded). */
367
+ list(el?: Element): string[];
368
+ }
369
+
370
+ /** Element editor (`x-edit`) — opt-in plugin. Modifiers: `.text` `.move` `.size`
371
+ * `.data` (default text + move), `.lock[.action]`, `.gated`, `.persist`, `.bare`,
372
+ * `.theme`, `.cssvar`. Every edit is logged; actions default to `$edit.target`. */
373
+ export interface ManifestEdit {
374
+ /** True while `.gated` areas are editable. */
375
+ active: boolean;
376
+ canUndo: boolean;
377
+ canRedo: boolean;
378
+ /** Bumps on every change to the log or target; read it to make a binding re-evaluate. */
379
+ version: number;
380
+ /** Set a handler to route patches somewhere other than the dev server. */
381
+ onPublish: ((patches: unknown[], state: { log: unknown[]; cursor: number }) => unknown) | null;
382
+ toggle(): void;
383
+ on(): void;
384
+ off(): void;
385
+ undo(): Promise<void>;
386
+ redo(): Promise<void>;
387
+ /** Source files that changed since the page loaded, from the last refused publish (also an
388
+ * `edit:stale` event on document, detail `{ files }`), or a reload held back because it
389
+ * would lose unpublished edits. */
390
+ stale: string[];
391
+ /** Edits that could not be applied because the source changed under them (also an
392
+ * `edit:conflict` event on document, detail `{ conflicts }`, and a console warning).
393
+ * `element` names what was edited (tag and opening text, or the region for layout);
394
+ * `value` what the edit held; `reason` says what happened in words.
395
+ * - A text or attribute edit whose element changed: `prop` is the edited property.
396
+ * - Layout (`prop: 'structure'`): kept when only unmoved children changed text in place;
397
+ * dropped when a moved, added or removed child changed, with `value`
398
+ * `{ changed: [{ was, now }], moved: [...], copies: [{ of, html, text }] }` so typed
399
+ * content can be recovered. */
400
+ conflicts: Array<{ region: string; key: string; element: string; prop: string; value: unknown; before: unknown; reason: string }>;
401
+ /** Empty `conflicts`. Those of `.persist` regions are kept across reloads until this is called. */
402
+ clearConflicts(): void;
403
+ /** Send every area's patches; on success the history is cleared (the source now holds it).
404
+ * `rebase: true` takes the current source as the base (writes over external changes). */
405
+ publish(opts?: { rebase?: boolean }): Promise<unknown>;
406
+ /** The resolved source patches for every area, without sending them. */
407
+ patches(): unknown[];
408
+ /** The raw delta log — persist it yourself to move edits between devices. */
409
+ export(): { log: unknown[]; cursor: number };
410
+ /** The piece a right-click landed on (set before any menu opens), or assignable. */
411
+ target: Element | null;
412
+ /** Whether an action applies to `el` (default `$edit.target`): capability and locks. */
413
+ can(action: ManifestEditAction | 'class' | 'copy' | 'cut' | 'paste', el?: Element | null): boolean;
414
+ /** Lock `el` and its subtree for one action, or all when omitted. Logged. A component host
415
+ * (see `block`) locks by its host key, for all its roots and what is in them. */
416
+ lock(el?: Element | null, action?: ManifestEditAction): boolean;
417
+ unlock(el?: Element | null, action?: ManifestEditAction): boolean;
418
+ copy(el?: Element): boolean;
419
+ cut(el?: Element): boolean;
420
+ paste(el?: Element): boolean;
421
+ duplicate(el?: Element): boolean;
422
+ remove(el?: Element): boolean;
423
+ /** Move a piece into a container (element or area key), before `before` or at the end. */
424
+ move(el: Element | null, dest: Element | string, before?: Element | null): boolean;
425
+ /** Nest a piece into the container before it. */
426
+ nest(el?: Element): boolean;
427
+ /** Move a piece out of its container, after it. */
428
+ unnest(el?: Element): boolean;
429
+ /** The piece containing a node, or null. In a static area a component instance is one
430
+ * piece, its host (its first rendered root; the rest follow it): it moves, duplicates
431
+ * (a new instance) and is removed as one, and its markup is not edited from here. */
432
+ block(node: Element): Element | null;
433
+ /** Set an attribute: a string sets it, `true` sets it empty, `null`/`false` removes it. */
434
+ attr(name: string, value: string | boolean | null, el?: Element): boolean;
435
+ classes: ManifestEditClasses;
436
+ /** Component scope of `el`'s area (default `$edit.target`): `scope(el)` reads it.
437
+ * Instance overrides apply to an area that wraps exactly one component with no x-edit region
438
+ * of its own; a component among other content is a host piece of a static area instead, and
439
+ * a component's own region is edited in its own file. */
440
+ scope(el?: Element | null): 'instance' | 'main' | null;
441
+ /** Set the component scope of `el`'s area (default `$edit.target`); false if it has none. */
442
+ scope(value: 'instance' | 'main', el?: Element | null): boolean;
443
+ /** Revert a component element's instance overrides (the area element reverts all). */
444
+ revert(el?: Element): boolean;
445
+ }
446
+
447
+ /** Rich text editor (`x-rich-text`): the area this element sits in, or the last focused one. */
448
+ export interface ManifestRichText {
449
+ /** The stored value, in the area's format. Assigning replaces the document and resets undo history. */
450
+ value: string;
451
+ focus(): void;
452
+ /** The href at the caret; assign to set it, assign '' to unlink. */
453
+ link: string;
454
+ /** Document-wide styles (font, size, leading, align, color, background) as CSS custom
455
+ * properties on the area; not part of the stored value. Assign `{}` to clear. */
456
+ all: Record<string, string>;
457
+ /** Select the whole document. */
458
+ selectAll(): void;
459
+ /** The current selection and its geometry, or null. Also emitted as a `rich-text:selection`
460
+ * event and as --rich-text-selection-* custom properties. */
461
+ selection: {
462
+ collapsed: boolean; text: string;
463
+ x: number; y: number; width: number; height: number;
464
+ top: number; bottom: number; left: number; right: number;
465
+ } | null;
466
+ /** Apply a command. Commands are HTML tag names ('strong', 'h2', 'ul', 'a', 'table', …) plus
467
+ * 'indent', 'outdent', 'align', 'color', 'background', 'font', 'size', 'leading', 'checklist',
468
+ * 'unlink', 'clear', 'undo', 'redo', 'block' and the table operations. Every command is also
469
+ * a method: `$rich.strong()`, `$rich.table(3, 2)` (columns, rows). */
470
+ run(command: string, arg?: unknown): void;
471
+ /** Whether that command is active at the caret. */
472
+ active(command: string): boolean;
473
+ /** Whether that command is available here (format, .inline, caret). */
474
+ can(command: string): boolean;
475
+ /** Read the content as markdown regardless of the storage format. */
476
+ markdown(): string;
477
+ /** Read the content as sanitized HTML regardless of the storage format. */
478
+ html(): string;
479
+
480
+ // Inline tags: toggle on the selection, or arm for the next typed text
481
+ strong(): void; b(): void; em(): void; i(): void; s(): void; del(): void; code(): void;
482
+ bdi(): void; cite(): void; ins(): void; kbd(): void; mark(): void; q(): void; samp(): void;
483
+ small(): void; span(): void; sub(): void; sup(): void; u(): void; var(): void;
484
+ /** `title` attribute (html only). */
485
+ abbr(title?: string): void;
486
+ /** `title` attribute (html only). */
487
+ dfn(title?: string): void;
488
+ /** Direction, default 'rtl' (html only). */
489
+ bdo(dir?: 'ltr' | 'rtl' | 'auto'): void;
490
+ /** Machine-readable `value` (html only). */
491
+ data(value?: string): void;
492
+ /** `datetime` attribute (html only). */
493
+ time(datetime?: string): void;
494
+ /** Link the selection; '' unlinks. */
495
+ a(href?: string): void;
496
+ unlink(): void;
497
+ br(): void;
498
+ /** Break opportunity (html only). */
499
+ wbr(): void;
500
+ img(src: string, alt?: string): void;
501
+
502
+ // Block tags: convert the block (again returns to p)
503
+ p(): void; h1(): void; h2(): void; h3(): void; h4(): void; h5(): void; h6(): void;
504
+ blockquote(): void; pre(): void; address(): void;
505
+ ul(): void; ol(): void; li(): void; checklist(): void; hr(): void;
506
+ figure(): void; figcaption(): void; dl(): void; dt(): void; dd(): void;
507
+ /** Any block tag by name, e.g. block('h2'). */
508
+ block(tag: string): void;
509
+
510
+ /** Insert a columns × rows table (default 3 × 3). */
511
+ table(columns?: number, rows?: number): void;
512
+ 'row-before'(): void; 'row-after'(): void; 'row-remove'(): void;
513
+ 'column-before'(): void; 'column-after'(): void; 'column-remove'(): void;
514
+ 'table-remove'(): void; 'table-header'(): void; merge(): void; split(): void;
515
+
516
+ indent(): void; outdent(): void;
517
+ align(value?: 'start' | 'center' | 'end' | 'justify' | string): void;
518
+ leading(value: string): void;
519
+ color(value: string): void;
520
+ background(value: string): void;
521
+ font(value: string): void;
522
+ size(value: string | number): void;
523
+ clear(): void;
524
+ undo(): void;
525
+ redo(): void;
526
+ }
527
+
528
+ /** Options for `ManifestRichText.attach()`. */
529
+ export interface ManifestRichTextAttachOptions {
530
+ /** 'block' (default) or 'inline' (single line: no block commands, Enter fires `rich-text:enter`). */
531
+ mode?: 'block' | 'inline';
532
+ /** Inline html only: `<br>` line breaks are kept, Shift+Enter inserts one, pasted blocks become lines. */
533
+ breaks?: boolean;
534
+ /** 'break': Enter inserts a line break too, instead of firing `rich-text:enter`. Needs `breaks` and the 'html' format. */
535
+ enter?: 'break';
536
+ /** false: `.all` controls and `$rich.all` are unavailable (no area-wide --rich-text-* styles). Default true. */
537
+ all?: boolean;
538
+ /** Storage format: 'markdown' (default), 'html' or 'plain'. */
539
+ format?: 'markdown' | 'html' | 'plain';
540
+ /** Initial value; omitted, the element's existing markup is the content. */
541
+ value?: string;
542
+ /** No markdown autoformat while typing. */
543
+ literal?: boolean;
544
+ /** Called with the stored value after every change. */
545
+ onChange?(value: string): void;
546
+ }
547
+
548
+ /** Returned by `ManifestRichText.attach()`: the `$rich` surface plus detach(). */
549
+ export interface ManifestRichTextHandle extends ManifestRichText {
550
+ el: Element;
551
+ /** Remove editing and restore the element's own contenteditable/role/aria-multiline. */
552
+ detach(): void;
553
+ /** Markup of the newest step in the field's undo history (a pending typing burst is recorded first). */
554
+ newest(): string;
555
+ }
556
+
334
557
  /**
335
558
  * Manifest's custom-element/attribute authoring surface (documentation aid —
336
559
  * these are HTML attributes, not JS globals). Element styles pair with most.
@@ -338,9 +561,10 @@ export interface ManifestCamera {
338
561
  export type ManifestDirective =
339
562
  | 'x-route' | 'x-anchors'
340
563
  | 'x-icon' | 'x-svg' | 'x-markdown' | 'x-code' | 'x-code-group'
341
- | 'x-toast' | 'x-tooltip' | 'x-carousel' | 'x-virtual' | 'x-resize'
564
+ | 'x-toast' | 'x-tooltip' | 'x-carousel' | 'x-virtual' | 'x-computed' | 'x-defer'
342
565
  | 'x-chart' | 'x-date' | 'x-color' | 'x-colorpicker' | 'x-combobox'
343
- | 'x-export' | 'x-pay' | 'x-files' | 'x-data-files';
566
+ | 'x-export' | 'x-import' | 'x-pay' | 'x-files' | 'x-data-files'
567
+ | 'x-edit' | 'x-rich-text';
344
568
 
345
569
  // ---------------------------------------------------------------------------
346
570
  // Global declarations (what Alpine exposes inside `x-data`, `x-show`, etc.)
@@ -349,12 +573,17 @@ export type ManifestDirective =
349
573
  declare global {
350
574
  /** Project data sources registered in manifest.json. */
351
575
  const $x: ManifestSources;
352
- /** Match the current route against a pattern (e.g. `$route('/about')`). */
576
+ /** The current route path (compare or .startsWith against it). */
353
577
  const $route: ManifestRoute;
354
578
  /** Read a parent component attribute (Manifest's prop mechanism). */
355
579
  const $modify: ManifestModify;
356
580
  /** Run a callback safely, returning undefined on error. */
357
581
  const $try: ManifestTry;
582
+ /**
583
+ * Cached derivation for `x-data` / `Alpine.data` scopes: `rows: $computed(function () { return this.items.filter(…) })`.
584
+ * Recomputed once per flush when a tracked dependency changes; reads as a plain property with a stable identity in between.
585
+ */
586
+ const $computed: <T>(fn: (this: any) => T) => T;
358
587
  /** Appwrite auth plugin (present when the plugin is loaded). */
359
588
  const $auth: ManifestAuth;
360
589
  /** Localization plugin. */
@@ -381,23 +610,29 @@ declare global {
381
610
  const $chart: ManifestChart;
382
611
  /** Export plugin. */
383
612
  const $export: ManifestExport;
384
- /** Device/platform info (utilities; enriched by the native plugin). */
613
+ /** Import plugin. */
614
+ const $import: ManifestImport;
615
+ /** Element editor (edit plugin; opt-in). */
616
+ const $edit: ManifestEdit;
617
+ /** Rich text editor (rich-text plugin; loaded on use). */
618
+ const $rich: ManifestRichText;
619
+ /** Device/platform info (utilities; enriched by the device plugin). */
385
620
  const $device: ManifestDevice;
386
- /** Native share (native plugin). */
621
+ /** Native share (device plugin). */
387
622
  const $share: ManifestShare;
388
- /** Push permissions (native plugin). */
623
+ /** Push permissions (device plugin). */
389
624
  const $push: ManifestPush;
390
- /** Secure storage (native plugin). */
625
+ /** Secure storage (device plugin). */
391
626
  const $secure: ManifestSecure;
392
- /** Deep links (native plugin). */
627
+ /** Deep links (device plugin). */
393
628
  const $links: ManifestLinks;
394
- /** App foreground state (native plugin). */
629
+ /** App foreground state (device plugin). */
395
630
  const $app: ManifestApp;
396
- /** Haptics (native plugin). */
631
+ /** Haptics (device plugin). */
397
632
  const $haptics: ManifestHaptics;
398
- /** Biometric auth (native plugin). */
633
+ /** Biometric auth (device plugin). */
399
634
  const $biometric: ManifestBiometric;
400
- /** Camera (native plugin). */
635
+ /** Camera (device plugin). */
401
636
  const $camera: ManifestCamera;
402
637
 
403
638
  /** Window-level Manifest namespace exposed by the loader. */
@@ -406,9 +641,34 @@ declare global {
406
641
  loadPlugin(name: string, version?: string): Promise<unknown>;
407
642
  loadTailwind(version?: string): Promise<unknown>;
408
643
  getPluginUrl(name: string, version?: string): string;
644
+ /** Defer a closed container built at runtime (call before Alpine.initTree). */
645
+ defer?(el: Element): unknown;
646
+ /** App-shell service worker diagnostics; kill() unregisters and clears its caches. */
647
+ sw?: { registered: boolean; version: string | null; kill(): Promise<void> };
648
+ /** The two-line same-origin /sw.js stub pinned to a framework version. */
649
+ swStub?(version?: string): string;
409
650
  };
410
651
  Alpine?: unknown;
411
652
  __manifestLoaded?: unknown;
653
+ /** Rich text engine (rich-text plugin). */
654
+ ManifestRichText?: {
655
+ attach(el: Element, options?: ManifestRichTextAttachOptions): ManifestRichTextHandle | null;
656
+ toMarkdown(root: Element): string;
657
+ fromMarkdown(markdown: string): string;
658
+ sanitize(html: string, allowBlocks?: boolean, keepStyle?: boolean): string;
659
+ commands(): string[];
660
+ };
661
+ }
662
+
663
+ /**
664
+ * Fired when the utilities runtime sees a class the baked sheet (and
665
+ * `manifest.json`'s `utilities.safelist`/`patterns`) doesn't cover, after
666
+ * publish stamped that sheet as covering every class — see
667
+ * manifest.utilities.static.js. `engineLoaded` is true once the lazily
668
+ * loaded Tailwind engine has taken over, false if that load failed.
669
+ */
670
+ interface WindowEventMap {
671
+ 'manifest:utilities-uncovered': CustomEvent<{ classes: string[]; engineLoaded: boolean }>;
412
672
  }
413
673
  }
414
674