Skip to content

Commit

Permalink
refactor: add table row types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Dec 22, 2023
1 parent da310f9 commit f90e2ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions lib/block/gfm/table/row.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import Parent from '@muya/block/base/parent';
import ContainerQueryBlock from '@muya/block/mixins/containerQueryBlock';
import ScrollPage from '@muya/block/scrollPage';
import Muya from '@muya/index';
import { mixins } from '@muya/utils';
import { ITableRowState } from '../../../state/types';
import TableBodyCell from './cell';

@mixins(ContainerQueryBlock)
class TableRow extends Parent {
static blockName = 'table.row';

static create(muya, state) {
static create(muya: Muya, state: ITableRowState) {
const row = new TableRow(muya);

row.append(
Expand All @@ -27,7 +29,7 @@ class TableRow extends Parent {
return [...pPath, offset];
}

constructor(muya) {
constructor(muya: Muya) {
super(muya);
this.tagName = 'tr';

Expand All @@ -38,7 +40,7 @@ class TableRow extends Parent {
getState(): ITableRowState {
const state: ITableRowState = {
name: 'table.row',
children: this.map((node) => node.getState()),
children: this.map((node) => (node as TableBodyCell).getState()),
};

return state;
Expand Down
6 changes: 3 additions & 3 deletions lib/block/mixins/containerQueryBlock.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import type { Path } from 'ot-json1';
import Content from '../base/content';
import Parent from '../base/parent';
import { TBlockPath } from '../types';

interface ContainerQueryBlock {
find(p: number): Parent | Content;
}
class ContainerQueryBlock {
queryBlock(path: [string, ...Path]) {
if (/children|meta|align|type|lang/.test(path[0])) {
queryBlock(path: TBlockPath) {
if (typeof path[0] === 'string' && /children|meta|align|type|lang/.test(path[0])) {
path.shift();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/block/mixins/leafQueryBlock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Path } from 'ot-json1';
import { TBlockPath } from '../types';

class LeafQueryBlock {
public firstChild: unknown;

queryBlock(path: Path) {
queryBlock(path: TBlockPath) {
return path.length && path[0] === 'text' ? this.firstChild : this;
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/block/scrollPage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IBlurFocus {
}

class ScrollPage extends Parent {
private blurFocus: IBlurFocus = { blur: null, focus: null };
private _blurFocus: IBlurFocus = { blur: null, focus: null };

static blockName = 'scrollpage';

Expand Down Expand Up @@ -116,17 +116,17 @@ class ScrollPage extends Parent {
}

handleBlurFromContent(block: Content) {
this.blurFocus.blur = block;
this._blurFocus.blur = block;
requestAnimationFrame(this.updateActiveStatus);
}

handleFocusFromContent(block: Content) {
this.blurFocus.focus = block;
this._blurFocus.focus = block;
requestAnimationFrame(this.updateActiveStatus);
}

private updateActiveStatus = () => {
const { blur, focus } = this.blurFocus;
const { blur, focus } = this._blurFocus;

if (blur == null && focus == null) {
return;
Expand Down Expand Up @@ -161,7 +161,7 @@ class ScrollPage extends Parent {
});
}

this.blurFocus = {
this._blurFocus = {
blur: null,
focus: null,
};
Expand Down

0 comments on commit f90e2ca

Please sign in to comment.