@fieldia/viewer 0.1.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.
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@fieldia/viewer",
3
+ "version": "0.1.0",
4
+ "description": "Mount a Fieldia page in any web page: plain DOM, no framework.",
5
+ "license": "MIT",
6
+ "homepage": "https://fieldia.dev",
7
+ "type": "commonjs",
8
+ "main": "./src/index.js",
9
+ "module": "./src/index.mjs",
10
+ "types": "./src/index.d.ts",
11
+ "unpkg": "./bundle/fieldia.js",
12
+ "jsdelivr": "./bundle/fieldia.js",
13
+ "exports": {
14
+ ".": {
15
+ "types": {
16
+ "import": "./src/index.d.mts",
17
+ "require": "./src/index.d.ts"
18
+ },
19
+ "import": "./src/index.mjs",
20
+ "require": "./src/index.js",
21
+ "default": "./src/index.js"
22
+ },
23
+ "./bundle/fieldia.js": "./bundle/fieldia.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "dependencies": {
27
+ "@fieldia/core": "0.1.0",
28
+ "@fieldia/widgets": "0.1.0",
29
+ "tslib": "^2.8.1"
30
+ },
31
+ "sideEffects": false,
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/fieldia-dev/fieldia",
35
+ "directory": "libs/viewer"
36
+ },
37
+ "files": [
38
+ "src",
39
+ "bundle",
40
+ "README.md",
41
+ "LICENSE"
42
+ ]
43
+ }
@@ -0,0 +1 @@
1
+ export * from './lib/viewer.mjs';
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/viewer';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/viewer"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/viewer/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B"}
package/src/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/viewer.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../libs/viewer/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { type Form, type FormOptions, type Page, type Locale } from '@fieldia/core';
2
+ import { type WidgetFactory } from '@fieldia/widgets';
3
+ export type Skin = 'underline' | 'outlined';
4
+ /** Every word the viewer shows, so a page can be translated. `{n}`, `{total}` and `{time}` are filled in. */
5
+ export interface ViewerLabels {
6
+ save: string;
7
+ discard: string;
8
+ saving: string;
9
+ saved: string;
10
+ submit: string;
11
+ next: string;
12
+ back: string;
13
+ stepOf: string;
14
+ submitted: string;
15
+ submitAnother: string;
16
+ draftFound: string;
17
+ restore: string;
18
+ discardDraft: string;
19
+ ok: string;
20
+ cancel: string;
21
+ loading: string;
22
+ }
23
+ export declare const VIEWER_LABELS: Record<Locale, ViewerLabels>;
24
+ /** English, kept under its old name. */
25
+ export declare const DEFAULT_LABELS: ViewerLabels;
26
+ /** Fill a slot with the app's own content. Return a function to clean up. */
27
+ export type SlotRenderer = (element: HTMLElement, context: {
28
+ form: Form;
29
+ name: string;
30
+ }) => void | (() => void);
31
+ export interface ViewerOptions extends Omit<FormOptions, 'page'> {
32
+ page: Page;
33
+ /** A form made elsewhere, to share one record between two views. */
34
+ form?: Form;
35
+ skin?: Skin;
36
+ /** Widgets that replace or add to the built-in ones, by `type` or `type.widget`. */
37
+ widgets?: Record<string, WidgetFactory>;
38
+ slots?: Record<string, SlotRenderer>;
39
+ /** The page's language: viewer labels, validation messages and widget words. Arabic runs right to left. */
40
+ locale?: Locale;
41
+ /** Labels that win over the language's defaults. */
42
+ labels?: Partial<ViewerLabels>;
43
+ dir?: 'ltr' | 'rtl';
44
+ /** How to ask before a button with `confirm` runs. Defaults to a small dialog. */
45
+ confirm?: (message: string) => Promise<boolean>;
46
+ }
47
+ export interface ViewerHandle {
48
+ readonly form: Form;
49
+ readonly element: HTMLElement;
50
+ setSkin(skin: Skin): void;
51
+ destroy(): void;
52
+ }
53
+ /**
54
+ * Render a page into `host` and keep it in step with its form. Plain DOM: the
55
+ * React, Angular and Vue bindings are thin shells around this function.
56
+ * Throws when the page does not validate, listing every problem.
57
+ */
58
+ export declare function mountViewer(host: HTMLElement, options: ViewerOptions): ViewerHandle;
@@ -0,0 +1,58 @@
1
+ import { type Form, type FormOptions, type Page, type Locale } from '@fieldia/core';
2
+ import { type WidgetFactory } from '@fieldia/widgets';
3
+ export type Skin = 'underline' | 'outlined';
4
+ /** Every word the viewer shows, so a page can be translated. `{n}`, `{total}` and `{time}` are filled in. */
5
+ export interface ViewerLabels {
6
+ save: string;
7
+ discard: string;
8
+ saving: string;
9
+ saved: string;
10
+ submit: string;
11
+ next: string;
12
+ back: string;
13
+ stepOf: string;
14
+ submitted: string;
15
+ submitAnother: string;
16
+ draftFound: string;
17
+ restore: string;
18
+ discardDraft: string;
19
+ ok: string;
20
+ cancel: string;
21
+ loading: string;
22
+ }
23
+ export declare const VIEWER_LABELS: Record<Locale, ViewerLabels>;
24
+ /** English, kept under its old name. */
25
+ export declare const DEFAULT_LABELS: ViewerLabels;
26
+ /** Fill a slot with the app's own content. Return a function to clean up. */
27
+ export type SlotRenderer = (element: HTMLElement, context: {
28
+ form: Form;
29
+ name: string;
30
+ }) => void | (() => void);
31
+ export interface ViewerOptions extends Omit<FormOptions, 'page'> {
32
+ page: Page;
33
+ /** A form made elsewhere, to share one record between two views. */
34
+ form?: Form;
35
+ skin?: Skin;
36
+ /** Widgets that replace or add to the built-in ones, by `type` or `type.widget`. */
37
+ widgets?: Record<string, WidgetFactory>;
38
+ slots?: Record<string, SlotRenderer>;
39
+ /** The page's language: viewer labels, validation messages and widget words. Arabic runs right to left. */
40
+ locale?: Locale;
41
+ /** Labels that win over the language's defaults. */
42
+ labels?: Partial<ViewerLabels>;
43
+ dir?: 'ltr' | 'rtl';
44
+ /** How to ask before a button with `confirm` runs. Defaults to a small dialog. */
45
+ confirm?: (message: string) => Promise<boolean>;
46
+ }
47
+ export interface ViewerHandle {
48
+ readonly form: Form;
49
+ readonly element: HTMLElement;
50
+ setSkin(skin: Skin): void;
51
+ destroy(): void;
52
+ }
53
+ /**
54
+ * Render a page into `host` and keep it in step with its form. Plain DOM: the
55
+ * React, Angular and Vue bindings are thin shells around this function.
56
+ * Throws when the page does not validate, listing every problem.
57
+ */
58
+ export declare function mountViewer(host: HTMLElement, options: ViewerOptions): ViewerHandle;