-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-crdt-extensions): 🎸 define Peritext extension
- Loading branch information
Showing
10 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './mval'; | ||
export * from './cnt'; | ||
export * from './peritext'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {NodeApi} from '../../json-crdt/model/api/nodes'; | ||
import type {PeritextNode} from './PeritextNode'; | ||
import type {ExtensionApi} from '../../json-crdt'; | ||
|
||
export class PeritextApi extends NodeApi<PeritextNode> implements ExtensionApi<PeritextNode> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {printTree} from 'tree-dump/lib/printTree'; | ||
import {MNEMONIC} from './constants'; | ||
import type {ITimestampStruct} from '../../json-crdt-patch/clock'; | ||
import type {ExtensionJsonNode, JsonNode} from '../../json-crdt'; | ||
import type {Printable} from 'tree-dump/lib/types'; | ||
import type {PeritextDataNode} from './types'; | ||
|
||
export class PeritextNode implements ExtensionJsonNode, Printable { | ||
public readonly id: ITimestampStruct; | ||
|
||
constructor(public readonly data: PeritextDataNode) { | ||
this.id = data.id; | ||
} | ||
|
||
// -------------------------------------------------------- ExtensionJsonNode | ||
|
||
public name(): string { | ||
return MNEMONIC; | ||
} | ||
|
||
public view(): string { | ||
const str = this.data.get(0)!; | ||
return str.view(); | ||
} | ||
|
||
public children(callback: (node: JsonNode) => void): void {} | ||
|
||
public child?(): PeritextDataNode { | ||
return this.data; | ||
} | ||
|
||
public container(): JsonNode | undefined { | ||
return this.data.container(); | ||
} | ||
|
||
public api: undefined | unknown = undefined; | ||
|
||
// ---------------------------------------------------------------- Printable | ||
|
||
public toString(tab?: string): string { | ||
return this.name() + printTree(tab, [(tab) => this.data.toString(tab)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
import {nodes, s} from "../../json-crdt-patch"; | ||
import {ExtensionId, ExtensionName} from "../constants"; | ||
import {SliceSchema} from "./slice/types"; | ||
|
||
export const enum Chars { | ||
BlockSplitSentinel = '\n', | ||
} | ||
|
||
export const MNEMONIC = ExtensionName[ExtensionId.peritext]; | ||
|
||
export const BUILD_SCHEMA = (text: string) => ( | ||
s.vec<[ | ||
/** | ||
* The text of the node. All rich-text textual data is stored in this node. | ||
*/ | ||
str: nodes.str<string>, | ||
|
||
/** | ||
* The slices of the node. All rich-text annotations are stored in this | ||
* node. | ||
*/ | ||
slices: nodes.arr<SliceSchema>, | ||
]>( | ||
s.str<string>(text), | ||
s.arr<SliceSchema>([]), | ||
) | ||
); | ||
|
||
export const SCHEMA = BUILD_SCHEMA(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {ext} from '../../json-crdt/extensions'; | ||
import {ExtensionId} from '../constants'; | ||
import {PeritextNode} from './PeritextNode'; | ||
import {PeritextApi} from './PeritextApi'; | ||
import {BUILD_SCHEMA, MNEMONIC} from './constants'; | ||
import type {PeritextDataNode} from './types'; | ||
import type {ExtensionDefinition} from '../../json-crdt'; | ||
|
||
export const PeritextExt: ExtensionDefinition<PeritextDataNode, PeritextNode, PeritextApi> = { | ||
id: ExtensionId.peritext, | ||
name: MNEMONIC, | ||
new: (text: string) => ext(ExtensionId.peritext, BUILD_SCHEMA(text)), | ||
Node: PeritextNode, | ||
Api: PeritextApi, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters