alpaylan / tail

Tail, a typed and structured document editor
https://tail.rocks
87 stars 8 forks source link

cvdl-ts: Add proper structural typing #22

Open alpaylan opened 4 months ago

alpaylan commented 4 months ago

Currently, a DocumentDataType is a fixed set of choices. Below is the definition from DataSchema.ts

export type Date = { tag: "Date"; format: DateFormat.t };
export type URL = { tag: "Url" };
export type PureString = { tag: "String" };
export type MarkdownString = { tag: "MarkdownString" };
export type PureNumber = { tag: "Number" };
export type Type = { tag: "Type"; value: string };
export type List = { tag: "List"; value: DocumentDataType.t };
export type Types = { tag: "Types"; value: DocumentDataType.t[] };

export type t =
  | Date
  | PureString
  | MarkdownString
  | URL
  | PureNumber
  | Type
  | List
  | Types;

These types are used in conjunction with ItemContent, where each Item will have a datatype specified by its data schema

export type PureString = {
    tag: "String";
    value: string;
};

export type None = {
    tag: "None";
};

export type List = {
    tag: "List";
    value: PureString[];
}

export type Url = {
    tag: "Url";
    value: {
        url: string;
        text: string;
    };
};

export type t = PureString | None | List | Url;

This scheme is obviously very flawed and limited. A better option would be to NOT hardcode these types and design a new system that merges types and their editors, by most possibly using small set of primitives and some mechanisms to define discriminated unions to model sums and products.

alpaylan commented 4 months ago

There are three main things we need to have for a given type.

We also need a few base types, so that we can compose the others based on them.

GIven some type here, it's possible to construct an editor from scratch with a few small rules.

There are lots of nice things about this model. The first is that it kills the concept of a data schema. A data schema is now just a data type in a document. This also means that Layout Schemas are now just visual representations of data types, meaning I might finally use this as a building block to a more general format.