mnfst-types 0.1.7 → 0.1.9

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