1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00
This commit is contained in:
Andrew Simachev 2021-11-03 22:42:50 +03:00
commit b8eb81745a
29 changed files with 114 additions and 112 deletions

View file

@ -539,7 +539,6 @@ function menuInit () {
mw: 'Middleware',
th: 'Threads',
an: 'Analytics',
dm: 'Dark Mode',
js: 'JSON',
};
const flagMenu = [];
@ -558,15 +557,6 @@ function menuInit () {
});
};
/*
flagMenu.push({
label: 'Dark mode', type: 'checkbox', checked: nativeTheme.shouldUseDarkColors,
click: () => {
nativeTheme.themeSource = !nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
}
});
*/
menuParam.push({
label: 'Debug',
submenu: [

View file

@ -77,13 +77,6 @@
background-size: 24px 28px; background-position: 24px center;
}
.icon.play:hover { background-color: rgba(255,255,255,0.9); }
.speed {
@include text-very-small; position: absolute; right: 2px; top: 2px; background-color: rgba(0,0,0,0.5); color: #fff;
border-radius: 2px; cursor: pointer; width: 20px; height: 20px; text-align: center; line-height: 20px; font-weight: 600;
opacity: 0; transition: $transitionFast;
}
.speed:hover { background-color: rgba(0,0,0,0.9); }
}
.icon.dots {
@ -100,7 +93,6 @@
.block.blockMedia:hover {
.icon.resize { opacity: 1; }
.icon.dots { opacity: 1; }
.speed { opacity: 1; }
}
.block.blockMedia > .wrapContent > .selectable.isSelected > .dropTarget > .focusable > .wrap {

View file

@ -24,6 +24,7 @@
.block.blockCover { top: 38px; }
/* Set */
.editorWrapper.isSet { width: calc(100% - 96px); }
.editorWrapper.isSet {
.block.blockCover {

View file

@ -4,7 +4,7 @@ $colorDarker: #444;
$colorMediumGrey: $colorWhite;
/*@media (prefers-color-scheme: dark) {*/
html.dark {
html.themeDark {
body { background: $colorBlack; color: white; }
.frame { background: $colorBlack; }
@ -34,6 +34,10 @@ html.dark {
}
.pageMainIndex {
.cover::after {
content: ""; background: rgba(0,0,0,0.3); width: 100%; height: 100%; position: fixed; top: 0px; left: 0px;
}
#documents {
.item { background: $colorBlack; }
}

View file

@ -135,7 +135,8 @@ import 'scss/menu/dataview/view.scss';
import 'scss/menu/dataview/source.scss';
import 'scss/media/print.scss';
import 'scss/media/dark.scss';
import 'scss/theme/dark/common.scss';
interface RouteElement { path: string; };
interface Props {};

View file

@ -161,10 +161,14 @@ const BlockDataview = observer(class BlockDataview extends React.Component<Props
getRecord (index: number) {
const { rootId, block } = this.props;
const data = dbStore.getData(rootId, block.id);
const item = data[index] || {};
if (index > data.length - 1) {
return {};
};
const item = data[index] || {};
if (item.layout == I.ObjectLayout.Note) {
item.name = item.snippet;
item.name = String(item.snippet || '').replace(/\n/g, ' ');
};
return item;
};

View file

@ -205,6 +205,7 @@ class Cell extends React.Component<Props, {}> {
};
};
let ret = false;
let param: I.MenuParam = {
element: `#${cellId} .cellContent`,
horizontal: I.MenuDirection.Center,
@ -316,6 +317,9 @@ class Cell extends React.Component<Props, {}> {
if (e.shiftKey && value) {
const scheme = DataUtil.getRelationUrlScheme(relation.format, value);
ipcRenderer.send('urlOpen', scheme + value);
ret = true;
break;
};
param.data = Object.assign(param.data, {
@ -347,10 +351,15 @@ class Cell extends React.Component<Props, {}> {
break;
case I.RelationType.Checkbox:
cell.removeClass('isEditing');
ret = true;
break;
};
if (ret) {
cell.removeClass('isEditing');
return;
};
if (menuId) {
menuStore.closeAll(Constant.menuIds.cell);
window.clearTimeout(this.timeout);

View file

@ -17,9 +17,10 @@ const ItemObject = observer(class ItemObject extends React.Component<Props, {}>
render () {
const { rootId, id, iconSize, relation, elementMapper, onClick } = this.props;
let object = detailStore.get(rootId, id, []);
if (object._empty_) {
let { _empty_, name } = object;
if (_empty_) {
return null;
};
@ -27,9 +28,8 @@ const ItemObject = observer(class ItemObject extends React.Component<Props, {}>
object = elementMapper(relation, object);
};
let name = object.name || DataUtil.defaultName('page');
if (object.layout == I.ObjectLayout.Note) {
name = object.snippet ? object.snippet : <span className="empty">Empty</span>;
name = object.snippet || <span className="empty">Empty</span>;
};
return (

View file

@ -20,20 +20,21 @@ const Card = observer(class Card extends React.Component<Props, {}> {
render () {
const { rootId, block, index, getView, getRecord, onRef, style } = this.props;
const view = getView();
const { cardSize, coverFit, hideIcon } = view;
const relations = view.relations.filter((it: any) => {
return it.isVisible && dbStore.getRelation(rootId, block.id, it.relationKey);
});
const idPrefix = 'dataviewCell';
const record = getRecord(index);
const cn = [ 'card', DataUtil.layoutClass(record.id, record.layout), DataUtil.cardSizeClass(view.cardSize) ];
const cn = [ 'card', DataUtil.layoutClass(record.id, record.layout), DataUtil.cardSizeClass(cardSize) ];
//const readonly = this.props.readonly || record.isReadonly;
const readonly = true;
if (view.coverFit) {
if (coverFit) {
cn.push('coverFit');
};
let BlankCover = (item: any) => (
const BlankCover = (item: any) => (
<div className={[ 'cover', 'type0', (!readonly ? 'canEdit' : '') ].join(' ')}>
<div className="inner">
{!readonly ? (

View file

@ -49,7 +49,7 @@ const BlockRelation = observer(class BlockRelation extends React.Component<Props
</div>
<div
id={id}
className={[ 'cell', DataUtil.relationClass(relation.format), (allowedValue ? 'canEdit' : '') ].join(' ')}
className={[ 'cell', DataUtil.relationClass(relation.format), (!readonly && allowedValue ? 'canEdit' : '') ].join(' ')}
onClick={this.onCellClick}
>
<Cell
@ -60,7 +60,7 @@ const BlockRelation = observer(class BlockRelation extends React.Component<Props
relationKey={relation.relationKey}
getRecord={() => { return detailStore.get(rootId, rootId, [ relation.relationKey ], true); }}
viewType={I.ViewType.Grid}
readonly={!allowedValue}
readonly={readonly || !allowedValue}
index={0}
idPrefix={idPrefix}
menuClassName="fromBlock"
@ -141,7 +141,11 @@ const BlockRelation = observer(class BlockRelation extends React.Component<Props
};
onCellClick (e: any) {
const { block } = this.props;
const { block, readonly } = this.props;
if (readonly) {
return;
};
if (this.refCell) {
this.refCell.onClick(e);

View file

@ -614,7 +614,7 @@ const BlockText = observer(class BlockText extends React.Component<Props, {}> {
ret = true;
});
keyboard.shortcut(`${cmd}+shift+arrowup, ${cmd}+shift+arrowdown, ${cmd}+c, ${cmd}+x, ${cmd}+d`, e, (pressed: string) => {
keyboard.shortcut(`${cmd}+shift+arrowup, ${cmd}+shift+arrowdown, ${cmd}+c, ${cmd}+x, ${cmd}+d, ${cmd}+a`, e, (pressed: string) => {
e.preventDefault();
DataUtil.blockSetText(rootId, block, value, this.marks, true, () => {
@ -1095,7 +1095,7 @@ const BlockText = observer(class BlockText extends React.Component<Props, {}> {
const currentFrom = range.from;
const currentTo = range.to;
if (!currentTo || (currentFrom == currentTo) || (from == currentFrom && to == currentTo) || !block.canHaveMarks() || ids.length) {
if (!currentTo || (currentFrom == currentTo) || !block.canHaveMarks() || ids.length) {
if (!keyboard.isContextDisabled) {
menuStore.close('blockContext');
};

View file

@ -235,6 +235,7 @@ const BlockType = observer(class BlockType extends React.Component<Props, State>
type: I.BlockType.Text,
style: I.TextStyle.Paragraph,
};
const namespace = isPopup ? '.popup' : '';
this.getScrollContainer().scrollTop(0);
Storage.setScroll('editor' + (isPopup ? 'Popup' : ''), rootId, 0);
@ -249,6 +250,8 @@ const BlockType = observer(class BlockType extends React.Component<Props, State>
focus.set(first.id, { from: l, to: l });
focus.apply();
$(window).trigger('resize.editor' + namespace);
};
};

View file

@ -29,7 +29,6 @@ const BlockVideo = observer(class BlockVideo extends React.Component<Props, {}>
this.onResizeEnd = this.onResizeEnd.bind(this);
this.onResizeInit = this.onResizeInit.bind(this);
this.onPlay = this.onPlay.bind(this);
this.onSpeed = this.onSpeed.bind(this);
};
render () {
@ -77,7 +76,6 @@ const BlockVideo = observer(class BlockVideo extends React.Component<Props, {}>
<div className="wrap resizable" style={css}>
<video className="media" controls={false} preload="auto" src={commonStore.fileUrl(hash)} />
<div className="videoControls">
<div id="speed" className="speed" onClick={this.onSpeed}>x{this.speed}</div>
<Icon className="play" onClick={this.onPlay} />
<Icon className="resize" onMouseDown={(e: any) => { this.onResizeStart(e, false); }} />
</div>
@ -202,21 +200,6 @@ const BlockVideo = observer(class BlockVideo extends React.Component<Props, {}>
});
};
onSpeed () {
const node = $(ReactDOM.findDOMNode(this));
const video = node.find('video');
const speed = node.find('#speed');
const el = video.get(0);
this.speed += 1;
if (this.speed > 4) {
this.speed = 1;
};
speed.text('x' + this.speed);
el.playbackRate = this.speed;
};
onResizeInit () {
if (!this._isMounted) {
return;

View file

@ -10,7 +10,8 @@ interface Props extends RouteComponentProps<any> {
rootId: string;
isPopup?: boolean;
dataset?: any;
}
resize?: () => void;
};
const { dialog } = window.require('@electron/remote');
const Constant = require('json/constant.json');
@ -91,11 +92,15 @@ const Controls = observer(class Controls extends React.Component<Props, {}> {
componentDidMount () {
this._isMounted = true;
};
componentDidUpdate () {
this.props.resize();
};
componentWillUnmount () {
this._isMounted = false;
};
onIcon (e: any) {
const { rootId } = this.props;
const root = blockStore.getLeaf(rootId, rootId);

View file

@ -65,6 +65,7 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
this.blockCreate = this.blockCreate.bind(this);
this.getWrapper = this.getWrapper.bind(this);
this.getWrapperWidth = this.getWrapperWidth.bind(this);
this.resize = this.resize.bind(this);
};
render () {
@ -91,7 +92,7 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
return (
<div id="editorWrapper">
<Controls key="editorControls" {...this.props} />
<Controls key="editorControls" {...this.props} resize={this.resize} />
<div id={'editor-' + rootId} className="editor">
<div className="blocks">
@ -163,6 +164,8 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
this.resize();
win.on('resize.editor' + namespace, (e: any) => { this.resize(); });
console.log('resize.editor' + namespace);
this.getScrollContainer().on('scroll.editor' + namespace, (e: any) => { this.onScroll(e); });
Storage.set('askSurvey', 1);
@ -760,6 +763,14 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
});
});
// Select all
keyboard.shortcut(`${cmd}+a`, e, (pressed: string) => {
focus.set(block.id, { from: 0, to: length });
focus.apply();
//$('.focusable.c' + block.id).trigger('select');
});
// Open action menu
keyboard.shortcut(`${cmd}+/, ctrl+shift+/`, e, (pressed: string) => {
menuStore.close('blockContext', () => {
@ -1665,6 +1676,8 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
};
resize () {
console.log('RESIZE');
if (this.loading || !this._isMounted) {
return;
};

View file

@ -50,15 +50,10 @@ const ListIndex = observer(class ListIndex extends React.Component<Props, {}> {
targetId = item.id;
};
const { _empty_, layout, iconEmoji, iconImage, snippet } = object;
const type = dbStore.getObjectType(object.type);
const cn = [ 'item' ];
let { _empty_, layout, name, iconEmoji, iconImage, snippet } = object;
let type = dbStore.getObjectType(object.type);
let cn = [ 'item' ];
let name: any = object.name || DataUtil.defaultName('page');
if (!object.name && (layout == I.ObjectLayout.Note)) {
name = <div className="empty">Empty</div>;
};
if (_empty_) {
return (
<div className="item isLoading" data-target-id={targetId}>
@ -69,6 +64,10 @@ const ListIndex = observer(class ListIndex extends React.Component<Props, {}> {
);
};
if (layout == I.ObjectLayout.Note) {
name = object.snippet || <span className="empty">Empty</span>;
};
if (layout == I.ObjectLayout.Task) {
cn.push('isTask');
icon = <IconObject size={18} object={object} canEdit={true} onCheckbox={(e: any) => { this.onCheckbox(e, object); }} />;

View file

@ -23,7 +23,6 @@ const MenuBlockLatex = observer(class MenuBlockLatex extends React.Component<Pro
_isMounted: boolean = false;
emptyLength: number = 0;
refFilter: any = null;
refList: any = null;
cache: any = {};
n: number = 0;
@ -138,12 +137,12 @@ const MenuBlockLatex = observer(class MenuBlockLatex extends React.Component<Pro
const { param } = this.props;
const { data } = param;
const { isTemplate } = data;
const items = this.getItems(true);
this._isMounted = true;
this.rebind();
this.resize();
let items = this.getItems(true);
this.cache = new CellMeasurerCache({
fixedWidth: true,
defaultHeight: (isTemplate ? HEIGHT_ITEM_BIG : HEIGHT_ITEM_SMALL),
@ -172,14 +171,12 @@ const MenuBlockLatex = observer(class MenuBlockLatex extends React.Component<Pro
};
this.resize();
this.rebind();
this.props.position();
this.props.setActive();
this.onOver(null, items[this.n]);
menuStore.close('previewLatex');
window.setTimeout(() => {
this.props.setActive();
this.onOver(null, items[this.n]);
}, 15);
};
componentWillUnmount () {
@ -314,6 +311,7 @@ const MenuBlockLatex = observer(class MenuBlockLatex extends React.Component<Pro
const items = this.getItems(true);
const obj = $(`#${getId()} .content`);
const offset = 16;
const ih = isTemplate ? HEIGHT_ITEM_BIG : HEIGHT_ITEM_SMALL;
let height = offset;
@ -321,7 +319,7 @@ const MenuBlockLatex = observer(class MenuBlockLatex extends React.Component<Pro
height += this.getItemHeight(item);
};
height = Math.max((isTemplate ? HEIGHT_ITEM_BIG : HEIGHT_ITEM_SMALL) + offset, Math.min(280, height));
height = Math.max(ih + offset, Math.min(ih * 10, height));
if (!items.length) {
height = 44;

View file

@ -66,7 +66,7 @@ const MenuBlockLink = observer(class MenuBlockLink extends React.Component<Props
let name = item.name || DataUtil.defaultName('page');
if (item.layout == I.ObjectLayout.Note) {
name = item.snippet ? item.snippet : <span className="empty">Empty</span>;
name = item.snippet || <span className="empty">Empty</span>;
};
let content = null;

View file

@ -49,7 +49,7 @@ const MenuBlockMention = observer(class MenuBlockMention extends React.Component
let name = item.name || DataUtil.defaultName('page');
if (item.layout == I.ObjectLayout.Note) {
name = item.snippet ? item.snippet : <span className="empty">Empty</span>;
name = item.snippet || <span className="empty">Empty</span>;
};
return (

View file

@ -359,12 +359,6 @@ const MenuDataviewFilterValues = observer(class MenuDataviewFilterValues extends
item.condition = conditions.length ? conditions[0].id : I.FilterCondition.None;
item.value = DataUtil.formatRelationValue(relation, null, false);
view.filters = view.filters.filter((it: I.Filter, i: number) => {
return (i == v) ||
(it.relationKey != v) ||
((it.relationKey == v) && (it.condition != item.condition));
});
};
if (k == 'value') {
@ -375,12 +369,6 @@ const MenuDataviewFilterValues = observer(class MenuDataviewFilterValues extends
if ([ I.FilterCondition.None, I.FilterCondition.Empty, I.FilterCondition.NotEmpty ].indexOf(v) >= 0) {
item.value = DataUtil.formatRelationValue(relation, null, false);
};
view.filters = view.filters.filter((it: I.Filter, i: number) => {
return (i == itemId) ||
(it.relationKey != item.relationKey) ||
((it.relationKey == item.relationKey) && (it.condition != v));
});
};
view.setFilter(itemId, item);

View file

@ -45,7 +45,7 @@ const MenuObjectValues = observer(class MenuObjectValues extends React.Component
let name = item.name || DataUtil.defaultName('page');
if (item.layout == I.ObjectLayout.Note) {
name = item.snippet ? item.snippet : <span className="empty">Empty</span>;
name = item.snippet || <span className="empty">Empty</span>;
};
return (

View file

@ -698,8 +698,6 @@ const Menu = observer(class Menu extends React.Component<Props, State> {
this.ref.n = items.findIndex((it: any) => { return it.id == item.id; });
};
this.setHover(items[this.ref.n], scroll);
if (this.ref.refList && scroll) {
let idx = this.ref.n;
if (this.ref.recalcIndex) {
@ -707,6 +705,8 @@ const Menu = observer(class Menu extends React.Component<Props, State> {
};
this.ref.refList.scrollToRow(Math.max(0, idx));
};
this.setHover(items[this.ref.n], scroll);
};
setHover (item?: any, scroll?: boolean) {

View file

@ -74,7 +74,7 @@ const MenuSearchObject = observer(class MenuSearchObject extends React.Component
let name = item.name || DataUtil.defaultName('page');
if (item.layout == I.ObjectLayout.Note) {
name = item.snippet ? item.snippet : <span className="empty">Empty</span>;
name = item.snippet || <span className="empty">Empty</span>;
};
const props = {

View file

@ -315,6 +315,7 @@ const PageMainIndex = observer(class PageMainIndex extends React.Component<Props
if (tab.id == I.TabIndex.Shared) {
filters.push({ operator: I.FilterOperator.And, relationKey: 'type', condition: I.FilterCondition.NotEqual, value: Constant.typeId.space });
filters.push({ operator: I.FilterOperator.And, relationKey: 'workspaceId', condition: I.FilterCondition.NotEmpty, value: null });
filters.push({ operator: I.FilterOperator.And, relationKey: 'isHighlighted', condition: I.FilterCondition.Equal, value: true });
};
if (!config.debug.ho) {

View file

@ -148,6 +148,7 @@ const PageMainNavigation = observer(class PageMainNavigation extends React.Compo
{icon}
<div className="name">{name}</div>
<div className="descr">{item.snippet}</div>
{coverId && coverType ? <Cover type={coverType} id={coverId} image={coverId} className={coverId} x={coverX} y={coverY} scale={coverScale} withScale={withScale} /> : ''}
{withButtons ? (
@ -514,11 +515,7 @@ const PageMainNavigation = observer(class PageMainNavigation extends React.Compo
getPage (page: any): I.PageInfo {
page.details.name = String(page.details.name || DataUtil.defaultName('page'));
return {
...page,
text: [ page.details.name, page.snippet ].join(' '),
};
return page;
};
getRootId () {

View file

@ -81,7 +81,7 @@ const PopupSearch = observer(class PopupSearch extends React.Component<Props, St
let name = item.name || DataUtil.defaultName('page');
if (item.layout == I.ObjectLayout.Note) {
name = item.snippet ? item.snippet : <span className="empty">Empty</span>;
name = item.snippet || <span className="empty">Empty</span>;
} else {
description = item.description || item.snippet;
};

View file

@ -5,6 +5,7 @@ const EmojiData = require('json/emoji.json');
const MAX_SIZE = 0x4000;
const SKINS = [ '1F3FA', '1F3FB', '1F3FC', '1F3FD', '1F3FE', '1F3FF' ];
const DIV = 65039;
const CAP = 8419;
const DIV_UNI = '-200d-';
const Mapping = {
@ -162,11 +163,24 @@ class SmileUtil {
return this.cache[icon];
};
let cp = [];
for (let i = 0; i < icon.length; ++i) {
cp.push(icon.charCodeAt(i));
};
if (!cp.includes(DIV) && (cp[cp.length - 1] == CAP)) {
cp.pop();
cp.push(DIV);
cp.push(CAP);
icon = cp.map((it: number) => { return String.fromCharCode(it); }).join('');
};
let data: any = null;
try {
data = getEmojiDataFromNative(icon, 'apple', EmojiData);
// Try to get emoji with divider byte
if (!data) {
data = getEmojiDataFromNative(icon + String.fromCharCode(DIV), 'apple', EmojiData);
@ -174,10 +188,7 @@ class SmileUtil {
} catch (e) {};
if (data) {
this.cache[icon] = {
colons: data.colons,
skin: data.skin
};
this.cache[icon] = { colons: data.colons, skin: data.skin };
return this.cache[icon];
} else {
return {};

View file

@ -449,16 +449,12 @@ class BlockStore {
const { from, to } = mark.range;
const object = detailStore.get(rootId, mark.param, []);
const old = text.substr(from, to - from);
const name = Util.shorten(object.name, 30);
if (object._empty_) {
continue;
};
let name = (object.name || DataUtil.defaultName('page'));
if (object.layout == I.ObjectLayout.Note) {
name = object.snippet || name;
};
if (old != name) {
const d = String(old || '').length - String(name || '').length;

View file

@ -1,5 +1,5 @@
import { observable, action, set, intercept, makeObservable } from 'mobx';
import { I, DataUtil, translate } from 'ts/lib';
import { I, Util, DataUtil, translate } from 'ts/lib';
const Constant = require('json/constant.json');
@ -125,7 +125,8 @@ class DetailStore {
};
let layout = Number(object.layout) || I.ObjectLayout.Page;
let name = String(object.name || DataUtil.defaultName('page'))
let name = String(object.name || DataUtil.defaultName('page'));
let snippet = String(object.snippet || '').replace(/\n/g, ' ');
if (layout == I.ObjectLayout.Note) {
object.coverType = I.CoverType.None;
@ -133,7 +134,7 @@ class DetailStore {
object.iconEmoji = '';
object.iconImage = '';
name = object.snippet;
name = snippet;
};
if (object.isDeleted) {
@ -142,11 +143,12 @@ class DetailStore {
return {
...object,
id: id,
name: name,
id,
name,
layout,
snippet,
type: DataUtil.convertRelationValueToString(object.type),
iconImage: DataUtil.convertRelationValueToString(object.iconImage),
layout: layout,
layoutAlign: Number(object.layoutAlign) || I.BlockAlign.Left,
recommendedLayout: Number(object.recommendedLayout) || I.ObjectLayout.Page,
coverX: Number(object.coverX) || 0,