Skip to content

Commit 867d515

Browse files
authored
feat: support readonly table (#6997)
* feat: support readonly table * fix: cannot preview pasted images * chore: remove http schema on android
1 parent 381d946 commit 867d515

File tree

11 files changed

+146
-75
lines changed

11 files changed

+146
-75
lines changed

frontend/appflowy_flutter/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
<data android:scheme="http" />
3737
<data android:scheme="https" />
3838
<data android:scheme="appflowy-flutter" />
39-
<data android:scheme="https" android:host="test.appflowy.io" />
40-
<data android:scheme="https" android:host="appflowy.io" />
41-
<data android:scheme="https" android:host="test.appflowy.com" />
42-
<data android:scheme="https" android:host="appflowy.com" />
4339
</intent-filter>
4440
</activity>
4541
<!--

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_image.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ extension PasteFromImage on EditorState {
101101
await File(copyToPath).writeAsBytes(imageBytes);
102102
final String? path;
103103

104+
CustomImageType type;
104105
if (isLocalMode) {
105106
path = await saveImageToLocalStorage(copyToPath);
107+
type = CustomImageType.local;
106108
} else {
107109
final result = await saveImageToCloudStorage(copyToPath, documentId);
108110

@@ -117,10 +119,11 @@ extension PasteFromImage on EditorState {
117119
}
118120

119121
path = result.$1;
122+
type = CustomImageType.internal;
120123
}
121124

122125
if (path != null) {
123-
await insertImageNode(path, selection: selection);
126+
await insertImageNode(path, selection: selection, type: type);
124127
}
125128

126129
return true;
@@ -140,6 +143,7 @@ extension PasteFromImage on EditorState {
140143
Future<void> insertImageNode(
141144
String src, {
142145
Selection? selection,
146+
required CustomImageType type,
143147
}) async {
144148
selection ??= this.selection;
145149
if (selection == null || !selection.isCollapsed) {
@@ -156,16 +160,18 @@ extension PasteFromImage on EditorState {
156160
transaction
157161
..insertNode(
158162
node.path,
159-
imageNode(
163+
customImageNode(
160164
url: src,
165+
type: type,
161166
),
162167
)
163168
..deleteNode(node);
164169
} else {
165170
transaction.insertNode(
166171
node.path.next,
167-
imageNode(
172+
customImageNode(
168173
url: src,
174+
type: type,
169175
),
170176
);
171177
}

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation.dart

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class _InlineMathEquationState extends State<InlineMathEquation> {
3636

3737
@override
3838
Widget build(BuildContext context) {
39-
final theme = Theme.of(context);
4039
return _IgnoreParentPointer(
4140
child: AppFlowyPopover(
4241
controller: popoverController,
@@ -60,33 +59,42 @@ class _InlineMathEquationState extends State<InlineMathEquation> {
6059
},
6160
offset: const Offset(0, 10),
6261
child: Padding(
63-
padding: const EdgeInsets.symmetric(vertical: 8.0),
62+
padding: const EdgeInsets.symmetric(vertical: 2.0),
6463
child: MouseRegion(
6564
cursor: SystemMouseCursors.click,
66-
child: Row(
67-
mainAxisSize: MainAxisSize.min,
68-
children: [
69-
const HSpace(2),
70-
Math.tex(
71-
widget.formula,
72-
options: MathOptions(
73-
style: MathStyle.text,
74-
mathFontOptions: const FontOptions(
75-
fontShape: FontStyle.italic,
76-
),
77-
fontSize: 14.0,
78-
color: widget.textStyle?.color ??
79-
theme.colorScheme.onSurface,
80-
),
81-
),
82-
const HSpace(2),
83-
],
84-
),
65+
child: _buildMathEquation(context),
8566
),
8667
),
8768
),
8869
);
8970
}
71+
72+
Widget _buildMathEquation(BuildContext context) {
73+
final theme = Theme.of(context);
74+
final longEq = Math.tex(
75+
widget.formula,
76+
textStyle: widget.textStyle,
77+
mathStyle: MathStyle.text,
78+
options: MathOptions(
79+
style: MathStyle.text,
80+
mathFontOptions: const FontOptions(
81+
fontShape: FontStyle.italic,
82+
),
83+
fontSize: 14.0,
84+
color: widget.textStyle?.color ?? theme.colorScheme.onSurface,
85+
),
86+
onErrorFallback: (errmsg) {
87+
return FlowyText(
88+
errmsg.message,
89+
);
90+
},
91+
);
92+
return Row(
93+
children: [
94+
longEq,
95+
],
96+
);
97+
}
9098
}
9199

92100
class MathInputTextField extends StatefulWidget {

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,30 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
124124
clipBehavior: Clip.none,
125125
children: [
126126
_buildCell(),
127-
if (node.columnIndex == 0)
127+
if (editorState.editable) ...[
128+
if (node.columnIndex == 0)
129+
Positioned(
130+
top: 0,
131+
bottom: 0,
132+
left: -SimpleTableConstants.tableLeftPadding,
133+
child: _buildRowMoreActionButton(),
134+
),
135+
if (node.rowIndex == 0)
136+
Positioned(
137+
left: 0,
138+
right: 0,
139+
child: _buildColumnMoreActionButton(),
140+
),
128141
Positioned(
129-
top: 0,
130-
bottom: 0,
131-
left: -SimpleTableConstants.tableLeftPadding,
132-
child: _buildRowMoreActionButton(),
133-
),
134-
if (node.rowIndex == 0)
135-
Positioned(
136-
left: 0,
137142
right: 0,
138-
child: _buildColumnMoreActionButton(),
139-
),
140-
Positioned(
141-
right: 0,
142-
top: node.rowIndex == 0 ? SimpleTableConstants.tableTopPadding : 0,
143-
bottom: 0,
144-
child: SimpleTableColumnResizeHandle(
145-
node: node,
143+
top:
144+
node.rowIndex == 0 ? SimpleTableConstants.tableTopPadding : 0,
145+
bottom: 0,
146+
child: SimpleTableColumnResizeHandle(
147+
node: node,
148+
),
146149
),
147-
),
150+
],
148151
],
149152
),
150153
);

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_border_builder.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';
22
import 'package:appflowy_editor/appflowy_editor.dart';
33
import 'package:flutter/material.dart';
4+
import 'package:provider/provider.dart';
45

56
class SimpleTableBorderBuilder {
67
SimpleTableBorderBuilder({
@@ -38,7 +39,13 @@ class SimpleTableBorderBuilder {
3839
// check if the cell is in the reordering column
3940
final isReordering = simpleTableContext.isReordering;
4041

41-
if (isReordering && (isCellInHoveringColumn || isCellInHoveringRow)) {
42+
final editorState = context.read<EditorState>();
43+
final editable = editorState.editable;
44+
45+
if (!editable) {
46+
return buildCellBorder();
47+
} else if (isReordering &&
48+
(isCellInHoveringColumn || isCellInHoveringRow)) {
4249
return buildReorderingBorder();
4350
} else if (simpleTableContext.isSelectingTable.value) {
4451
return buildSelectingTableBorder();

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_widget.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,23 @@ class _SimpleTableWidgetState extends State<SimpleTableWidget> {
130130
},
131131
child: child,
132132
),
133-
if (widget.enableAddColumnButton)
134-
SimpleTableAddColumnHoverButton(
135-
editorState: editorState,
136-
tableNode: widget.node,
137-
),
138-
if (widget.enableAddRowButton)
139-
SimpleTableAddRowHoverButton(
140-
editorState: editorState,
141-
tableNode: widget.node,
142-
),
143-
if (widget.enableAddColumnAndRowButton)
144-
SimpleTableAddColumnAndRowHoverButton(
145-
editorState: editorState,
146-
node: widget.node,
147-
),
133+
if (editorState.editable) ...[
134+
if (widget.enableAddColumnButton)
135+
SimpleTableAddColumnHoverButton(
136+
editorState: editorState,
137+
tableNode: widget.node,
138+
),
139+
if (widget.enableAddRowButton)
140+
SimpleTableAddRowHoverButton(
141+
editorState: editorState,
142+
tableNode: widget.node,
143+
),
144+
if (widget.enableAddColumnAndRowButton)
145+
SimpleTableAddColumnAndRowHoverButton(
146+
editorState: editorState,
147+
node: widget.node,
148+
),
149+
],
148150
],
149151
),
150152
),

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ class EditorStyleCustomizer {
359359
final formula = attributes[InlineMathEquationKeys.formula];
360360
if (formula is String) {
361361
return WidgetSpan(
362-
alignment: PlaceholderAlignment.middle,
362+
style: after.style,
363363
child: InlineMathEquation(
364364
node: node,
365365
index: index,
366366
formula: formula,
367-
textStyle: style().textStyleConfiguration.text,
367+
textStyle: after.style ?? style().textStyleConfiguration.text,
368368
),
369369
);
370370
}

frontend/appflowy_flutter/lib/workspace/presentation/widgets/image_viewer/image_provider.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import 'package:flutter/widgets.dart';
2-
31
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
42
import 'package:appflowy/shared/appflowy_network_image.dart';
3+
import 'package:appflowy/shared/patterns/common_patterns.dart';
54
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
5+
import 'package:flutter/widgets.dart';
66

77
/// Abstract class for providing images to the [InteractiveImageViewer].
88
///
@@ -54,7 +54,8 @@ class AFBlockImageProvider implements AFImageProvider {
5454
]) {
5555
final image = getImage(index);
5656

57-
if (image.type == CustomImageType.local) {
57+
if (image.type == CustomImageType.local &&
58+
localPathRegex.hasMatch(image.url)) {
5859
return Image(image: image.toImageProvider());
5960
}
6061

frontend/appflowy_flutter/lib/workspace/presentation/widgets/image_viewer/interactive_image_toolbar.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,13 @@ class InteractiveImageToolbar extends StatelessWidget {
218218
}
219219

220220
Future<void> _locateOrDownloadImage(BuildContext context) async {
221-
if (currentImage.isLocal) {
221+
if (currentImage.isLocal || currentImage.isNotInternal) {
222222
/// If the image type is local, we simply open the image
223-
await afLaunchUri(Uri.file(currentImage.url));
224-
} else if (currentImage.isNotInternal) {
225-
// In case of eg. Unsplash images (images without extension type in URL),
223+
///
224+
/// // In case of eg. Unsplash images (images without extension type in URL),
226225
// we don't know their mimetype. In the future we can write a parser
227226
// using the Mime package and read the image to get the proper extension.
228-
await afLaunchUri(Uri.parse(currentImage.url));
227+
await afLaunchUrlString(currentImage.url);
229228
} else {
230229
if (userProfile == null) {
231230
return showSnapBar(

frontend/appflowy_flutter/pubspec.lock

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,10 @@ packages:
803803
dependency: "direct main"
804804
description:
805805
name: flutter_math_fork
806-
sha256: "94bee4642892a94939af0748c6a7de0ff8318feee588379dcdfea7dc5cba06c8"
806+
sha256: "284bab89b2fbf1bc3a0baf13d011c1dd324d004e35d177626b77f2fc056366ac"
807807
url: "https://pub.dev"
808808
source: hosted
809-
version: "0.7.2"
809+
version: "0.7.3"
810810
flutter_plugin_android_lifecycle:
811811
dependency: transitive
812812
description:
@@ -860,6 +860,14 @@ packages:
860860
description: flutter
861861
source: sdk
862862
version: "0.0.0"
863+
flutter_tex:
864+
dependency: "direct main"
865+
description:
866+
name: flutter_tex
867+
sha256: "816074d8a49dd2301704aaf481f9b052b935b8790018a88b69a60d003d5e89e4"
868+
url: "https://pub.dev"
869+
source: hosted
870+
version: "4.0.9"
863871
flutter_web_plugins:
864872
dependency: transitive
865873
description: flutter
@@ -2306,6 +2314,46 @@ packages:
23062314
url: "https://pub.dev"
23072315
source: hosted
23082316
version: "1.2.1"
2317+
webview_flutter:
2318+
dependency: transitive
2319+
description:
2320+
name: webview_flutter
2321+
sha256: "6869c8786d179f929144b4a1f86e09ac0eddfe475984951ea6c634774c16b522"
2322+
url: "https://pub.dev"
2323+
source: hosted
2324+
version: "4.8.0"
2325+
webview_flutter_android:
2326+
dependency: transitive
2327+
description:
2328+
name: webview_flutter_android
2329+
sha256: ed021f27ae621bc97a6019fb601ab16331a3db4bf8afa305e9f6689bdb3edced
2330+
url: "https://pub.dev"
2331+
source: hosted
2332+
version: "3.16.8"
2333+
webview_flutter_platform_interface:
2334+
dependency: transitive
2335+
description:
2336+
name: webview_flutter_platform_interface
2337+
sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d
2338+
url: "https://pub.dev"
2339+
source: hosted
2340+
version: "2.10.0"
2341+
webview_flutter_plus:
2342+
dependency: transitive
2343+
description:
2344+
name: webview_flutter_plus
2345+
sha256: "57ec757eada4e23bfb015f5d5f84a45108cb2c29b1e77e23956768cd5e0c8468"
2346+
url: "https://pub.dev"
2347+
source: hosted
2348+
version: "0.4.7"
2349+
webview_flutter_wkwebview:
2350+
dependency: transitive
2351+
description:
2352+
name: webview_flutter_wkwebview
2353+
sha256: "9c62cc46fa4f2d41e10ab81014c1de470a6c6f26051a2de32111b2ee55287feb"
2354+
url: "https://pub.dev"
2355+
source: hosted
2356+
version: "3.14.0"
23092357
win32:
23102358
dependency: transitive
23112359
description:

0 commit comments

Comments
 (0)