@formancy/react 0.3.0 → 0.5.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/dist/index.d.mts CHANGED
@@ -1,12 +1,29 @@
1
1
  import { ComponentType, ReactElement, ReactNode } from "react";
2
2
  import { ControlProps, FieldSnapshot, FormEngine, Path } from "@formancy/core";
3
+ import { FormText, FormText as FormText$1, FormWordId, FormWordValues, FormWords, FormWordsByLocale, FormWordsByLocale as FormWordsByLocale$1 } from "@formancy/core/words";
3
4
  import { FieldType, RemoteOption, RichCommand } from "@formancy/spec";
4
5
  //#region src/context.d.ts
5
- export declare function FormancyProvider({ engine, children }: {
6
+ export declare function FormancyProvider({ engine, words, children }: {
6
7
  engine: FormEngine;
8
+ /**
9
+ * Languages a host adds, and words it changes, by locale: `{ it: { 'form.next':
10
+ * 'Avanti' } }`, or `{ en: { 'form.submit': 'Send' } }`. Read in the language the
11
+ * questions are, a word at a time, and English for the rest. A constant, as any context
12
+ * value should be: a new object on every render is a new language for every control below.
13
+ */
14
+ words?: FormWordsByLocale$1;
7
15
  children?: ReactNode;
8
16
  }): import("react").JSX.Element;
9
17
  export declare function useFormEngine(): FormEngine;
18
+ /**
19
+ * The form's words, in the language the reader chose for it.
20
+ *
21
+ * English outside a `FormancyProvider`, which has no engine to take a language from — a
22
+ * resume notice a host draws beside the form rather than inside its provider. Never the
23
+ * browser's language: the form's is the one the reader chose, and the browser's is the
24
+ * one their machine came with.
25
+ */
26
+ export declare function useFormText(): FormText$1;
10
27
  //#endregion
11
28
  //#region src/use-field.d.ts
12
29
  interface FieldBinding extends FieldSnapshot {
@@ -339,6 +356,25 @@ interface StoredFile {
339
356
  /** Where the bytes are, in whatever the host's storage calls a location. */
340
357
  storageKey: string;
341
358
  }
359
+ /**
360
+ * What the field tells an uploader about the file it is sending.
361
+ *
362
+ * An uploader that reads none of it still works — a function of the file alone is an
363
+ * `Uploader` — and the field then shows the file as uploading with no figure, and a
364
+ * cancel that stops waiting for it rather than stopping the transfer
365
+ * ([0130](../../../docs/decisions/0130-each-file-is-its-own-upload.md)).
366
+ */
367
+ interface UploadOptions {
368
+ /**
369
+ * The field the file is for, at the data path a server reads — `items[].receipt` for
370
+ * a file field in a repeater row, whichever row it is.
371
+ */
372
+ field: string;
373
+ /** Aborted when the person cancels this file. Hand it to `fetch` and the transfer stops. */
374
+ signal: AbortSignal;
375
+ /** Bytes sent so far, of how many. `fetch` cannot report an upload's progress; XHR can. */
376
+ onProgress(sent: number, total: number): void;
377
+ }
342
378
  /**
343
379
  * Uploads one file and reports what was stored.
344
380
  *
@@ -346,7 +382,7 @@ interface StoredFile {
346
382
  * file, because a submission somebody believes carries their evidence and does not is
347
383
  * the worst outcome available here.
348
384
  */
349
- type Uploader = (file: File) => Promise<StoredFile>;
385
+ type Uploader = (file: File, options: UploadOptions) => Promise<StoredFile>;
350
386
  export declare const UploaderProvider: import("react").Provider<Uploader | undefined>;
351
387
  /**
352
388
  * The host's uploader, or undefined when there is none.
@@ -453,6 +489,9 @@ export declare function useRichTextEditorFactory(): RichTextEditorFactory | unde
453
489
  * **A library cannot make a host render it.** Resuming a draft is the host's call, so
454
490
  * this component exists and is documented, and showing it is the deployment's
455
491
  * responsibility. `SAFETY-ANALYSIS.md` says so rather than claiming a guarantee.
492
+ *
493
+ * **It speaks the form's language inside the form's `FormancyProvider`**, and English
494
+ * outside one, where there is no engine to take a language from (0171).
456
495
  */
457
496
  /** What `resumeDraft` reports. Structural, so a host need not import a type. */
458
497
  interface ResumeMigration {
@@ -470,5 +509,5 @@ interface ResumeNoticeProps {
470
509
  }
471
510
  export declare function ResumeNotice({ migration, labels }: ResumeNoticeProps): ReactElement | null;
472
511
  //#endregion
473
- export type { ErrorSummaryProps, FieldBinding, FieldComponent, FieldComponentProps, FormancyFormProps, OptionsRequest, OptionsSource, OptionsSources, Registry, RepeaterBinding, ResumeMigration, ResumeNoticeProps, RichTextEditorFactory, RichTextEditorHandle, RichTextEditorMount, ScanRequest, Scanner, StoredFile, SubmitOutcome, Uploader, WizardBinding };
512
+ export type { ErrorSummaryProps, FieldBinding, FieldComponent, FieldComponentProps, FormText, FormWordId, FormWordValues, FormWords, FormWordsByLocale, FormancyFormProps, OptionsRequest, OptionsSource, OptionsSources, Registry, RepeaterBinding, ResumeMigration, ResumeNoticeProps, RichTextEditorFactory, RichTextEditorHandle, RichTextEditorMount, ScanRequest, Scanner, StoredFile, SubmitOutcome, UploadOptions, Uploader, WizardBinding };
474
513
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/context.tsx","../src/use-field.ts","../src/use-repeater.ts","../src/use-wizard.ts","../src/use-submit.ts","../src/fields/internals.tsx","../src/form.tsx","../src/error-summary.tsx","../src/rich-text.tsx","../src/options-source.ts","../src/scanning.ts","../src/uploads.ts","../src/rich-text-editor.ts","../src/resume-notice.tsx"],"mappings":";;;;wBAYgB,mBAAmB,QAAQ;EAAc,QAAQ;EAAY,WAAW;oBAAW,IAAA;wBAInF,iBAAiB;;;UCXhB,qBAAqB;EACpC,SAAS;EACT;;EAEA,cAAc;;EAEd;IAAc;IAAY;;;EAE1B;IAAc;;;;;;;;;;;;;wBAaA,SAAS,eAAe,OAAO;;;UCrB9B;EACf;;EAEA;EACA;EACA,UAAU;;EAEV,QAAQ,cAAc;;;;;;;wBAQR,YAAY,eAAe,OAAO;;;UCjBjC;EACf;EACA;;;EAGA;EACA;;EAEA,QAAQ;EACR;;EAEA,KAAK;;;;;;;wBAQS,aAAa;;;;;;;;;;;wBCTb;EAAqB;EAAa,QAAQ;;;;;;;;;;;;;;;;;UCOzC;EACf;EACA;;KAGU,iBAAiB,cAAc;UAE1B;EACf,SAAS,QAAQ,OAAO,WAAW;EACnC,SAAS,eAAe;;UAGT;EACf;EACA,QAAQ;;EAER;;UAGe;;;;;;;EAOf,SAAS;EACT,WAAW;;;;;;;EAOX;EACA;EACA,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;wBCHP,aAAa,OAAO,oCAAiB,IAAA;;;UChDpC;EACf,SAAS;;;;;;;;;;;wBAYK,eAAe,UAAU,oCAAiB,IAAA;;;;;;;;;;;;;;;;;;;;wBCI1C,WAAW;EAAY;IAAmB;;;;;;;;;;UCZzC;;;;;EAKf;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;EASA;;EAEA;;EAEA,QAAQ;;;;;;;;;;;UAYO;EACf,QAAQ,SAAS,iBAAiB,iBAAiB;;EAEnD;;EAEA;;EAEA;;;;;;;;;;;;;KAcU,iBAAiB,SAAS,eAAe;qBAIxC,wCAAsB,SAAA,SAAA,eAAA;;;;;;;;;wBAUnB,qBAAqB;;;;;;;;;;;;UCxEpB;;EAEf;;EAEA;;;;;;;;;;;;;;;;;;;KAoBU,WAAW,SAAS,gBAAgB;qBAInC,iCAAe,SAAA;;;;;;;;wBASZ,cAAc;;;;;;;;;;;;;UCpCb;;EAEf;EACA;EACA;EACA;;EAEA;;;;;;;;;KAUU,YAAY,MAAM,SAAS,QAAQ;qBAIlC,kCAAgB,SAAA;;;;;;;;;wBAUb,eAAe;;;;;;;;;;;;;;;;;;;;;UCtBd;;EAEf;;EAEA,WAAW;;;;;;;;;;;;;EAaX,MAAM,SAAS,aAAa;;EAE5B,WAAW,SAAS;EACpB;;UAGe;;WAEN,SAAS;;WAET;;WAEA,WAAW;WACX;;;;;;;;;;WAUA,YAAY,SAAS;;KAGpB,yBAAyB,OAAO,wBAAwB;qBAIvD,wCAAsB,SAAA;;;;;;;;;wBAUnB,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;UClD3B;WACN;WACA,SAAS;aAAyB;aAAuB;;;UAGnD;;WAEN,YAAY;;WAEZ,SAAS,SAAS;;wBAGb,eAAe,WAAW,UAAU,oBAAoB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/context.tsx","../src/use-field.ts","../src/use-repeater.ts","../src/use-wizard.ts","../src/use-submit.ts","../src/fields/internals.tsx","../src/form.tsx","../src/error-summary.tsx","../src/rich-text.tsx","../src/options-source.ts","../src/scanning.ts","../src/uploads.ts","../src/rich-text-editor.ts","../src/resume-notice.tsx"],"mappings":";;;;;wBAsBgB,mBACd,QACA,OACA;EAEA,QAAQ;;;;;;;EAOR,QAAQ;EACR,WAAW;oBACZ,IAAA;wBAsBe,iBAAiB;;;;;;;;;wBAkBjB,eAAe;;;UCvEd,qBAAqB;EACpC,SAAS;EACT;;EAEA,cAAc;;EAEd;IAAc;IAAY;;;EAE1B;IAAc;;;;;;;;;;;;;wBAaA,SAAS,eAAe,OAAO;;;UCrB9B;EACf;;EAEA;EACA;EACA,UAAU;;EAEV,QAAQ,cAAc;;;;;;;wBAQR,YAAY,eAAe,OAAO;;;UCjBjC;EACf;EACA;;;EAGA;EACA;;EAEA,QAAQ;EACR;;EAEA,KAAK;;;;;;;wBAQS,aAAa;;;;;;;;;;;wBCTb;EAAqB;EAAa,QAAQ;;;;;;;;;;;;;;;;;UCQzC;EACf;EACA;;KAGU,iBAAiB,cAAc;UAE1B;EACf,SAAS,QAAQ,OAAO,WAAW;EACnC,SAAS,eAAe;;UAGT;EACf;EACA,QAAQ;;EAER;;UAGe;;;;;;;EAOf,SAAS;EACT,WAAW;;;;;;;EAOX;EACA;EACA,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;wBCAP,aAAa,OAAO,oCAAiB,IAAA;;;UCpDpC;EACf,SAAS;;;;;;;;;;;wBAYK,eAAe,UAAU,oCAAiB,IAAA;;;;;;;;;;;;;;;;;;;;wBCI1C,WAAW;EAAY;IAAmB;;;;;;;;;;UCZzC;;;;;EAKf;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;EASA;;EAEA;;EAEA,QAAQ;;;;;;;;;;;UAYO;EACf,QAAQ,SAAS,iBAAiB,iBAAiB;;EAEnD;;EAEA;;EAEA;;;;;;;;;;;;;KAcU,iBAAiB,SAAS,eAAe;qBAIxC,wCAAsB,SAAA,SAAA,eA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