mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-09-22 23:17:41 +00:00
feat: auto calculate the column width when resizing (#7448)
* feat: calculate the column width auto * fix: ai writer table issue
This commit is contained in:
parent
637c043f5b
commit
3bf4f080c5
@ -190,9 +190,10 @@ class _DocumentPageState extends State<DocumentPage>
|
|||||||
),
|
),
|
||||||
header: buildCoverAndIcon(context, state),
|
header: buildCoverAndIcon(context, state),
|
||||||
initialSelection: initialSelection,
|
initialSelection: initialSelection,
|
||||||
placeholderText: (node) => node.type == ParagraphBlockKeys.type
|
placeholderText: (node) =>
|
||||||
? LocaleKeys.editor_slashPlaceHolder.tr()
|
node.type == ParagraphBlockKeys.type && !node.isInTable
|
||||||
: '',
|
? LocaleKeys.editor_slashPlaceHolder.tr()
|
||||||
|
: '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -162,13 +162,12 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
|
|||||||
|
|
||||||
editorLaunchUrl = (url) {
|
editorLaunchUrl = (url) {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
afLaunchUrlString(url);
|
afLaunchUrlString(url, addingHttpSchemeWhenFailed: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Future.value(true);
|
return Future.value(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
effectiveScrollController = widget.scrollController ?? ScrollController();
|
effectiveScrollController = widget.scrollController ?? ScrollController();
|
||||||
// disable the color parse in the HTML decoder.
|
// disable the color parse in the HTML decoder.
|
||||||
DocumentHTMLDecoder.enableColorParse = false;
|
DocumentHTMLDecoder.enableColorParse = false;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/columns/simple_columns_block_constant.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
@ -51,17 +52,36 @@ Future<void> dragToMoveNode(
|
|||||||
final transaction = editorState.transaction;
|
final transaction = editorState.transaction;
|
||||||
final targetNodeParent = targetNode.parentColumnsBlock;
|
final targetNodeParent = targetNode.parentColumnsBlock;
|
||||||
if (targetNodeParent != null) {
|
if (targetNodeParent != null) {
|
||||||
|
final length = targetNodeParent.children.length;
|
||||||
final columnNode = simpleColumnNode(
|
final columnNode = simpleColumnNode(
|
||||||
children: [node.deepCopy()],
|
children: [node.deepCopy()],
|
||||||
|
width: (node.rect.width * 1 / (length + 1)).clamp(
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth,
|
||||||
|
double.infinity,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for (final column in targetNodeParent.children) {
|
||||||
|
final width =
|
||||||
|
column.attributes[SimpleColumnBlockKeys.width]?.toDouble() ??
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth;
|
||||||
|
transaction.updateNode(column, {
|
||||||
|
...column.attributes,
|
||||||
|
SimpleColumnBlockKeys.width: (width * length / (length + 1)).clamp(
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth,
|
||||||
|
double.infinity,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
transaction.insertNode(targetNode.path.next, columnNode);
|
transaction.insertNode(targetNode.path.next, columnNode);
|
||||||
transaction.deleteNode(node);
|
transaction.deleteNode(node);
|
||||||
} else {
|
} else {
|
||||||
|
final width = targetNode.rect.width / 2 - 16;
|
||||||
final columnsNode = simpleColumnsNode(
|
final columnsNode = simpleColumnsNode(
|
||||||
children: [
|
children: [
|
||||||
simpleColumnNode(children: [targetNode.deepCopy()]),
|
simpleColumnNode(children: [targetNode.deepCopy()], width: width),
|
||||||
simpleColumnNode(children: [node.deepCopy()]),
|
simpleColumnNode(children: [node.deepCopy()], width: width),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -82,14 +102,28 @@ Future<void> dragToMoveNode(
|
|||||||
final targetNodeParent = targetNode.parentColumnsBlock;
|
final targetNodeParent = targetNode.parentColumnsBlock;
|
||||||
if (targetNodeParent != null) {
|
if (targetNodeParent != null) {
|
||||||
// find the previous sibling node of the target node
|
// find the previous sibling node of the target node
|
||||||
final width = (node.rect.width /
|
final length = targetNodeParent.children.length;
|
||||||
(targetNode.parentColumnsBlock?.children.length ?? 2)) -
|
|
||||||
16;
|
|
||||||
final columnNode = simpleColumnNode(
|
final columnNode = simpleColumnNode(
|
||||||
children: [node.deepCopy()],
|
children: [node.deepCopy()],
|
||||||
width: width,
|
width: (node.rect.width * 1 / (length + 1)).clamp(
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth,
|
||||||
|
double.infinity,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for (final column in targetNodeParent.children) {
|
||||||
|
final width =
|
||||||
|
column.attributes[SimpleColumnBlockKeys.width]?.toDouble() ??
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth;
|
||||||
|
transaction.updateNode(column, {
|
||||||
|
...column.attributes,
|
||||||
|
SimpleColumnBlockKeys.width: (width * length / (length + 1)).clamp(
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth,
|
||||||
|
double.infinity,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
transaction.insertNode(targetNode.path.previous, columnNode);
|
transaction.insertNode(targetNode.path.previous, columnNode);
|
||||||
transaction.deleteNode(node);
|
transaction.deleteNode(node);
|
||||||
} else {
|
} else {
|
||||||
|
@ -235,7 +235,7 @@ class MarkdownTextRobot {
|
|||||||
List<Node>? children;
|
List<Node>? children;
|
||||||
if (node.children.isNotEmpty) {
|
if (node.children.isNotEmpty) {
|
||||||
children = node.children
|
children = node.children
|
||||||
.map((child) => _styleDelta(node: node, attributes: attributes))
|
.map((child) => _styleDelta(node: child, attributes: attributes))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,13 +88,12 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>
|
|||||||
|
|
||||||
late final EditorState editorState = context.read<EditorState>();
|
late final EditorState editorState = context.read<EditorState>();
|
||||||
|
|
||||||
@override
|
final ScrollController scrollController = ScrollController();
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
scrollController.dispose();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +101,7 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget child = SingleChildScrollView(
|
Widget child = SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
|
controller: scrollController,
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: _buildChildren(),
|
children: _buildChildren(),
|
||||||
@ -111,6 +111,7 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>
|
|||||||
if (UniversalPlatform.isDesktop) {
|
if (UniversalPlatform.isDesktop) {
|
||||||
// only show the scrollbar on desktop
|
// only show the scrollbar on desktop
|
||||||
child = Scrollbar(
|
child = Scrollbar(
|
||||||
|
controller: scrollController,
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -149,8 +150,9 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>
|
|||||||
final children = <Widget>[];
|
final children = <Widget>[];
|
||||||
for (var i = 0; i < node.children.length; i++) {
|
for (var i = 0; i < node.children.length; i++) {
|
||||||
final childNode = node.children[i];
|
final childNode = node.children[i];
|
||||||
final width = childNode.attributes[SimpleColumnBlockKeys.width] ??
|
final width =
|
||||||
SimpleColumnsBlockConstants.minimumColumnWidth;
|
childNode.attributes[SimpleColumnBlockKeys.width]?.toDouble() ??
|
||||||
|
SimpleColumnsBlockConstants.minimumColumnWidth;
|
||||||
Widget child = editorState.renderer.build(context, childNode);
|
Widget child = editorState.renderer.build(context, childNode);
|
||||||
|
|
||||||
child = SizedBox(
|
child = SizedBox(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class SimpleColumnsBlockConstants {
|
class SimpleColumnsBlockConstants {
|
||||||
const SimpleColumnsBlockConstants._();
|
const SimpleColumnsBlockConstants._();
|
||||||
|
|
||||||
static const double minimumColumnWidth = 128;
|
static const double minimumColumnWidth = 128.0;
|
||||||
static const bool enableDebugBorder = false;
|
static const bool enableDebugBorder = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user