aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-05-14 12:06:31 -0400
committerbobzel <zzzman@gmail.com>2023-05-14 12:06:31 -0400
commitcfd353baf7356024dc88c61289755dd6699ae9fd (patch)
tree971b25f07ff19cde5b3f40dc440e6dfa02944e18 /src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
parent24f9e3ddefb1853cce3f3c51dfbe6183d88bce78 (diff)
parent42afc0250de658fc3e924864bfae5afb4edec335 (diff)
Merge branch 'master' into UI_Update_Eric_Ma
Diffstat (limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index a59d7e5a3..bcc2ca129 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -56,7 +56,8 @@ export class CollectionSchemaView extends CollectionSubView() {
private _documentOptions: DocumentOptions = new DocumentOptions();
private _tableContentRef: HTMLDivElement | null = null;
- public static _rowHeight: number = 50;
+ static _rowHeight: number = 50;
+ static _rowSingleLineHeight: number = 32;
public static _minColWidth: number = 25;
public static _rowMenuWidth: number = 60;
public static _previewDividerWidth: number = 4;
@@ -78,7 +79,7 @@ export class CollectionSchemaView extends CollectionSubView() {
@observable _selectedCell: [Doc, number] | undefined;
@computed get _selectedDocs() {
- return SelectionManager.Docs().filter(doc => Doc.AreProtosEqual(DocCast(doc.context), this.rootDoc));
+ return SelectionManager.Docs().filter(doc => Doc.AreProtosEqual(DocCast(doc.embedContainer), this.rootDoc));
}
@computed get documentKeys() {
@@ -86,7 +87,7 @@ export class CollectionSchemaView extends CollectionSubView() {
}
@computed get previewWidth() {
- return NumCast(this.layoutDoc.schemaPreviewWidth);
+ return NumCast(this.layoutDoc.schema_previewWidth);
}
@computed get tableWidth() {
@@ -94,12 +95,12 @@ export class CollectionSchemaView extends CollectionSubView() {
}
@computed get columnKeys() {
- return Cast(this.layoutDoc.columnKeys, listSpec('string'), defaultColumnKeys);
+ return Cast(this.layoutDoc.schema_columnKeys, listSpec('string'), defaultColumnKeys);
}
@computed get storedColumnWidths() {
const widths = NumListCast(
- this.layoutDoc.columnWidths,
+ this.layoutDoc.schema_columnWidths,
this.columnKeys.map(() => (this.tableWidth - CollectionSchemaView._rowMenuWidth) / this.columnKeys.length)
);
@@ -242,7 +243,7 @@ export class CollectionSchemaView extends CollectionSubView() {
let currKeys = [...this.columnKeys];
currKeys[index] = newKey;
- this.layoutDoc.columnKeys = new List<string>(currKeys);
+ this.layoutDoc.schema_columnKeys = new List<string>(currKeys);
};
@undoBatch
@@ -256,11 +257,11 @@ export class CollectionSchemaView extends CollectionSubView() {
const currWidths = this.storedColumnWidths.slice();
currWidths.splice(0, 0, newColWidth);
const newDesiredTableWidth = currWidths.reduce((w, cw) => w + cw, 0);
- this.layoutDoc.columnWidths = new List<number>(currWidths.map(w => (w / newDesiredTableWidth) * (this.tableWidth - CollectionSchemaView._rowMenuWidth)));
+ this.layoutDoc.schema_columnWidths = new List<number>(currWidths.map(w => (w / newDesiredTableWidth) * (this.tableWidth - CollectionSchemaView._rowMenuWidth)));
let currKeys = this.columnKeys.slice();
currKeys.splice(0, 0, key);
- this.layoutDoc.columnKeys = new List<string>(currKeys);
+ this.layoutDoc.schema_columnKeys = new List<string>(currKeys);
};
@action
@@ -273,11 +274,11 @@ export class CollectionSchemaView extends CollectionSubView() {
const currWidths = this.storedColumnWidths.slice();
currWidths.splice(index, 1);
const newDesiredTableWidth = currWidths.reduce((w, cw) => w + cw, 0);
- this.layoutDoc.columnWidths = new List<number>(currWidths.map(w => (w / newDesiredTableWidth) * (this.tableWidth - CollectionSchemaView._rowMenuWidth)));
+ this.layoutDoc.schema_columnWidths = new List<number>(currWidths.map(w => (w / newDesiredTableWidth) * (this.tableWidth - CollectionSchemaView._rowMenuWidth)));
let currKeys = this.columnKeys.slice();
currKeys.splice(index, 1);
- this.layoutDoc.columnKeys = new List<string>(currKeys);
+ this.layoutDoc.schema_columnKeys = new List<string>(currKeys);
};
@action
@@ -316,7 +317,7 @@ export class CollectionSchemaView extends CollectionSubView() {
@action
finishResize = () => {
- this.layoutDoc.columnWidths = new List<number>(this._displayColumnWidths);
+ this.layoutDoc.schema_columnWidths = new List<number>(this._displayColumnWidths);
this._displayColumnWidths = undefined;
};
@@ -325,11 +326,11 @@ export class CollectionSchemaView extends CollectionSubView() {
moveColumn = (fromIndex: number, toIndex: number) => {
let currKeys = this.columnKeys.slice();
currKeys.splice(toIndex, 0, currKeys.splice(fromIndex, 1)[0]);
- this.layoutDoc.columnKeys = new List<string>(currKeys);
+ this.layoutDoc.schema_columnKeys = new List<string>(currKeys);
let currWidths = this.storedColumnWidths.slice();
currWidths.splice(toIndex, 0, currWidths.splice(fromIndex, 1)[0]);
- this.layoutDoc.columnWidths = new List<number>(currWidths);
+ this.layoutDoc.schema_columnWidths = new List<number>(currWidths);
};
@action
@@ -479,14 +480,14 @@ export class CollectionSchemaView extends CollectionSubView() {
const maxWidth = 1000;
const movedWidth = this.props.ScreenToLocalTransform().transformDirection(nativeWidth.right - e.clientX, 0)[0];
const width = movedWidth < minWidth ? minWidth : movedWidth > maxWidth ? maxWidth : movedWidth;
- this.layoutDoc.schemaPreviewWidth = width;
+ this.layoutDoc.schema_previewWidth = width;
return false;
};
@action
addNewTextDoc = (value: string, shiftDown?: boolean, forceEmptyNote?: boolean) => {
if (!value && !forceEmptyNote) return false;
- const newDoc = Docs.Create.TextDocument(value, { title: value, _autoHeight: true });
+ const newDoc = Docs.Create.TextDocument(value, { title: value, _layout_autoHeight: true });
FormattedTextBox.SelectOnLoad = newDoc[Id];
FormattedTextBox.SelectOnLoadChar = forceEmptyNote ? '' : ' ';
return this.addRow(newDoc) || false;
@@ -499,7 +500,7 @@ export class CollectionSchemaView extends CollectionSubView() {
ContextMenu.Instance.setDefaultItem('::', (name: string): void => {
Doc.GetProto(this.props.Document)[name] = '';
- this.addRow(Docs.Create.TextDocument('', { title: name, _autoHeight: true }));
+ this.addRow(Docs.Create.TextDocument('', { title: name, _layout_autoHeight: true }));
});
ContextMenu.Instance.displayMenu(x, y, undefined, true);
};
@@ -515,9 +516,9 @@ export class CollectionSchemaView extends CollectionSubView() {
if (found) {
const rect = found.getBoundingClientRect();
const localRect = this.props.ScreenToLocalTransform().transformBounds(rect.left, rect.top, rect.width, rect.height);
- if (localRect.y < CollectionSchemaView._rowHeight || localRect.y + localRect.height > this.props.PanelHeight()) {
+ if (localRect.y < this.rowHeightFunc() || localRect.y + localRect.height > this.props.PanelHeight()) {
let focusSpeed = options.zoomTime ?? 50;
- smoothScroll(focusSpeed, this._tableContentRef!, localRect.y + this._tableContentRef!.scrollTop - CollectionSchemaView._rowHeight, options.easeFunc);
+ smoothScroll(focusSpeed, this._tableContentRef!, localRect.y + this._tableContentRef!.scrollTop - this.rowHeightFunc(), options.easeFunc);
return focusSpeed;
}
}
@@ -836,6 +837,7 @@ export class CollectionSchemaView extends CollectionSubView() {
});
return { docs };
}
+ rowHeightFunc = () => (BoolCast(this.layoutDoc._schema_singleLine) ? CollectionSchemaView._rowSingleLineHeight : CollectionSchemaView._rowHeight);
sortedDocsFunc = () => this.sortedDocs;
isContentActive = () => this.props.isSelected() || this.props.isContentActive();
screenToLocal = () => this.props.ScreenToLocalTransform().translate(-this.tableWidth, 0);
@@ -850,7 +852,7 @@ export class CollectionSchemaView extends CollectionSubView() {
// prevent wheel events from passively propagating up through containers
r?.addEventListener('wheel', (e: WheelEvent) => {}, { passive: false });
}}>
- <div className="schema-header-row" style={{ height: CollectionSchemaView._rowHeight }}>
+ <div className="schema-header-row" style={{ height: this.rowHeightFunc() }}>
<div className="row-menu" style={{ width: CollectionSchemaView._rowMenuWidth }}>
<div className="schema-header-button" onPointerDown={e => (this._columnMenuIndex === -1 ? this.closeColumnMenu() : this.openColumnMenu(-1, true))}>
<FontAwesomeIcon icon="plus" />
@@ -865,6 +867,7 @@ export class CollectionSchemaView extends CollectionSubView() {
sortField={this.sortField}
sortDesc={this.sortDesc}
setSort={this.setSort}
+ rowHeight={this.rowHeightFunc}
removeColumn={this.removeColumn}
resizeColumn={this.startResize}
openContextMenu={this.openContextMenu}
@@ -875,7 +878,7 @@ export class CollectionSchemaView extends CollectionSubView() {
</div>
{this._columnMenuIndex !== undefined && this.renderColumnMenu}
{this._filterColumnIndex !== undefined && this.renderFilterMenu}
- <CollectionSchemaViewDocs schema={this} childDocs={this.sortedDocsFunc} setRef={(ref: HTMLDivElement | null) => (this._tableContentRef = ref)} />
+ <CollectionSchemaViewDocs schema={this} childDocs={this.sortedDocsFunc} rowHeight={this.rowHeightFunc} setRef={(ref: HTMLDivElement | null) => (this._tableContentRef = ref)} />
<EditableView GetValue={returnEmptyString} SetValue={this.addNewTextDoc} placeholder={"Type ':' for commands"} contents={'+ New Node'} menuCallback={this.menuCallback} height={CollectionSchemaView._newNodeInputHeight} />
</div>
{this.previewWidth > 0 && <div className="schema-preview-divider" style={{ width: CollectionSchemaView._previewDividerWidth }} onPointerDown={this.onDividerDown}></div>}
@@ -922,20 +925,20 @@ interface CollectionSchemaViewDocsProps {
schema: CollectionSchemaView;
setRef: (ref: HTMLDivElement | null) => void;
childDocs: () => { docs: Doc[] };
+ rowHeight: () => number;
}
@observer
class CollectionSchemaViewDocs extends React.Component<CollectionSchemaViewDocsProps> {
tableWidthFunc = () => this.props.schema.tableWidth;
- rowHeightFunc = () => CollectionSchemaView._rowHeight;
- childScreenToLocal = computedFn((index: number) => () => this.props.schema.props.ScreenToLocalTransform().translate(0, -CollectionSchemaView._rowHeight - index * this.rowHeightFunc()));
+ childScreenToLocal = computedFn((index: number) => () => this.props.schema.props.ScreenToLocalTransform().translate(0, -this.props.rowHeight() - index * this.props.rowHeight()));
render() {
return (
- <div className="schema-table-content" ref={this.props.setRef} style={{ height: `calc(100% - ${CollectionSchemaView._newNodeInputHeight + CollectionSchemaView._rowHeight}px)` }}>
+ <div className="schema-table-content" ref={this.props.setRef} style={{ height: `calc(100% - ${CollectionSchemaView._newNodeInputHeight + this.props.rowHeight()}px)` }}>
{this.props.childDocs().docs.map((doc: Doc, index: number) => {
const dataDoc = !doc.isTemplateDoc && !doc.isTemplateForField ? undefined : this.props.schema.props.DataDoc;
return (
- <div className="schema-row-wrapper" style={{ height: CollectionSchemaView._rowHeight }}>
+ <div className="schema-row-wrapper" style={{ height: this.props.rowHeight() }}>
<DocumentView
key={doc[Id]}
{...this.props.schema.props}
@@ -945,7 +948,7 @@ class CollectionSchemaViewDocs extends React.Component<CollectionSchemaViewDocsP
DataDoc={dataDoc}
renderDepth={this.props.schema.props.renderDepth + 1}
PanelWidth={this.tableWidthFunc}
- PanelHeight={this.rowHeightFunc}
+ PanelHeight={this.props.rowHeight}
styleProvider={DefaultStyleProvider}
waitForDoubleClickToClick={returnNever}
defaultDoubleClick={returnIgnore}
@@ -965,7 +968,7 @@ class CollectionSchemaViewDocs extends React.Component<CollectionSchemaViewDocsP
hideTitle={true}
hideDocumentButtonBar={true}
hideLinkAnchors={true}
- fitWidth={returnTrue}
+ layout_fitWidth={returnTrue}
scriptContext={this}
canEmbedOnDrag={true}
/>