Skip to content

Commit

Permalink
Revert "Gdocs tables (#1726)"
Browse files Browse the repository at this point in the history
This reverts commit afe9ddd.
  • Loading branch information
colin-alexa authored Mar 21, 2024
1 parent afe9ddd commit eb0633d
Show file tree
Hide file tree
Showing 13 changed files with 627 additions and 11,721 deletions.
1 change: 0 additions & 1 deletion packages/@atjson/document/src/annotations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from "./inline";
export * from "./object";
export * from "./parse";
export * from "./slice";
export * from "./text";
export * from "./unknown";
12 changes: 0 additions & 12 deletions packages/@atjson/document/src/annotations/text.ts

This file was deleted.

8 changes: 1 addition & 7 deletions packages/@atjson/document/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Insertion,
ParseAnnotation,
SliceAnnotation,
TextAnnotation,
UnknownAnnotation,
} from "./internals";

Expand Down Expand Up @@ -736,12 +735,7 @@ export class Document {
annotation: Annotation<any> | AnnotationJSON
): Annotation<any> {
let DocumentClass = this.constructor as typeof Document;
let schema = [
...DocumentClass.schema,
ParseAnnotation,
SliceAnnotation,
TextAnnotation,
];
let schema = [...DocumentClass.schema, ParseAnnotation, SliceAnnotation];

if (annotation instanceof UnknownAnnotation) {
let KnownAnnotation = schema.find(function annotationMatchesClass(
Expand Down
2 changes: 0 additions & 2 deletions packages/@atjson/document/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ObjectAnnotation,
ParseAnnotation,
SliceAnnotation,
TextAnnotation,
UnknownAnnotation,
is,
deserialize,
Expand Down Expand Up @@ -47,7 +46,6 @@ export {
ObjectAnnotation,
ParseAnnotation,
SliceAnnotation,
TextAnnotation,
UnknownAnnotation,
is,
deserialize,
Expand Down
12 changes: 8 additions & 4 deletions packages/@atjson/document/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
JSONObject,
Annotation,
SliceAnnotation,
TextAnnotation,
UnknownAnnotation,
is,
withStableIds,
Expand Down Expand Up @@ -129,6 +128,11 @@ const START_TOKENS = [
TokenType.PARSE_START,
];

class Text extends BlockAnnotation {
static vendorPrefix = "atjson";
static type = "text";
}

class Root extends BlockAnnotation {
static vendorPrefix = "atjson";
static type = "root";
Expand Down Expand Up @@ -462,7 +466,7 @@ export function serialize(
}

// Insert text block
let text = new TextAnnotation({
let text = new Text({
start,
end,
});
Expand All @@ -473,15 +477,15 @@ export function serialize(
annotation: text,
selfClosing: false,
shared,
edgeBehaviour: TextAnnotation.edgeBehaviour,
edgeBehaviour: Text.edgeBehaviour,
});
tokens.splice(startIndex + 1, 0, {
type: TokenType.BLOCK_START,
index: text.start,
annotation: text,
selfClosing: false,
shared,
edgeBehaviour: TextAnnotation.edgeBehaviour,
edgeBehaviour: Text.edgeBehaviour,
});
}
textLength = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
AdjacentBoundaryBehaviour,
JSON,
SliceAnnotation,
compareAnnotations,
Annotation,
TextAnnotation,
} from "@atjson/document";

import OffsetSource, { DataSet, Table, ColumnType } from "../index";
Expand Down Expand Up @@ -106,12 +106,13 @@ export function convertHTMLTablesToDataSet(

if (headings.length) {
headings.sort(compareAnnotations).forEach((headCell, index) => {
doc.addAnnotations(
new TextAnnotation({
start: headCell.start,
end: headCell.end,
})
);
if (index !== 0) {
doc.insertText(
headCell.start,
" ",
AdjacentBoundaryBehaviour.preserveBoth
);
}

let slice = new SliceAnnotation({
...headCell,
Expand Down Expand Up @@ -153,6 +154,8 @@ export function convertHTMLTablesToDataSet(
);

tableRows.forEach((row) => {
doc.insertText(row.start, " ", AdjacentBoundaryBehaviour.preserveBoth);

let rowEntries: [string, { slice: string; jsonValue: JSON }][] = [];
doc
.where(
Expand All @@ -165,11 +168,10 @@ export function convertHTMLTablesToDataSet(
.sort(compareAnnotations)
.forEach((bodyCell, index) => {
if (index !== 0) {
doc.addAnnotations(
new TextAnnotation({
start: bodyCell.start,
end: bodyCell.end,
})
doc.insertText(
bodyCell.start,
" ",
AdjacentBoundaryBehaviour.preserveBoth
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@atjson/renderer-commonmark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ export default class CommonmarkRenderer extends Renderer {
}

*DataSet(): Generator<void, string, string[]> {
return (yield).join("");
return "";
}

*Table(
Expand All @@ -750,7 +750,7 @@ export default class CommonmarkRenderer extends Renderer {
return "";
}

const previousState = { ...this.state };
const previousState = this.state;
this.state.inlineOnly = true;

const dataSet = context.document.blocks.find(
Expand Down
4 changes: 2 additions & 2 deletions packages/@atjson/renderer-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export default class HTMLRenderer extends Renderer {
return `<pre>${codeSnippet}</pre>`;
}

*DataSet(): Iterator<void, string, string[]> {
return (yield).join("");
*DataSet() {
return "";
}

*Heading(heading: Block<Heading>) {
Expand Down
Loading

0 comments on commit eb0633d

Please sign in to comment.