Skip to content

Commit

Permalink
Add initial documentation for the forms package and its patterns dire…
Browse files Browse the repository at this point in the history
…ctory
  • Loading branch information
danielnaab committed Nov 1, 2024
1 parent fd9fa10 commit 97a83b4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/forms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @atj/forms

This library includes all of the core business logic of the Forms Platform.

- [./src/services](./src/services): The public interface of the Forms Platform is implemented here
- [./src/patterns](./src/patterns/README.md): Form building blocks, aka "patterns"
- [./src/repository](./src/repository): Database routines
- [./src/documents](./src/documents): Document ingest and creation
- [./src/context](./src/context): Runtime contexts for the platform (testing, in-browser, server-side) are defined here
54 changes: 54 additions & 0 deletions packages/forms/src/patterns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Forms Platform - Patterns

Patterns are the Forms Platform's primary building block, a reusable module that may be configured via the no-code form builder to craft custom user experiences.

Patterns are stored on the form `Blueprint`'s pattern attribute.

## Pattern configuration

Each pattern must define a configuration object, which provides the definition of its behavior.

The `PatternConfig` type is defined in [../pattern.ts](../pattern.ts).

## Data structure

Patterns are defined by the generic `Pattern<C>` type in `pattern.ts`.

```typescript
export type Pattern<C = any> = {
type: string; // A string identifier for the pattern type
id: PatternId; // A unique identifier for the pattern instance
data: C; // The configuration data specific to the pattern type
};
```

Constructing patterns may be accomplished manually, or via `PatternBuilder` helper classes.

For example, an input pattern may be defined directly:

```typescript
const input: InputPattern = {
type: 'input',
id: 'my-input',
data: {
label: 'My input',
initial: '',
required: true,
maxLength: 64
},
}
```

```typescript
const input = new InputPatternBuilder();
const page1 = new Page({ title: 'Page 1', patterns: [input1.id] });
const pageSet = new PageSet({ pages: [page1.id] }, 'page-set');
const page2 = new Page({ title: 'Page 2', patterns: [input1.id] });
pageSet.addPage(page2)

// Construct the pattern objects
page1.toPattern();
page2.toPattern();
pageSet.toPattern();
```

0 comments on commit 97a83b4

Please sign in to comment.