-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2682 from nextcloud/feat/neon_rich_text
feat(neon_rich_text): Init
- Loading branch information
Showing
39 changed files
with
1,119 additions
and
950 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../assets/AGPL-3.0.txt |
5 changes: 5 additions & 0 deletions
5
packages/neon_framework/packages/neon_rich_text/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include: package:neon_lints/flutter.yaml | ||
|
||
custom_lint: | ||
rules: | ||
- avoid_exports: false |
5 changes: 5 additions & 0 deletions
5
packages/neon_framework/packages/neon_rich_text/lib/neon_rich_text.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export 'src/rich_objects/deck_card.dart'; | ||
export 'src/rich_objects/fallback.dart'; | ||
export 'src/rich_objects/file.dart'; | ||
export 'src/rich_objects/mention.dart'; | ||
export 'src/rich_text.dart'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions
47
packages/neon_framework/packages/neon_rich_text/lib/src/rich_objects/rich_objects.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:neon_rich_text/src/rich_objects/deck_card.dart'; | ||
import 'package:neon_rich_text/src/rich_objects/fallback.dart'; | ||
import 'package:neon_rich_text/src/rich_objects/file.dart'; | ||
import 'package:neon_rich_text/src/rich_objects/mention.dart'; | ||
import 'package:nextcloud/core.dart' as core; | ||
|
||
/// Renders a rich object [parameter] to be interactive. | ||
@internal | ||
InlineSpan buildRichObjectParameter({ | ||
required core.RichObjectParameter parameter, | ||
required TextStyle? textStyle, | ||
required bool isPreview, | ||
}) { | ||
if (isPreview) { | ||
return TextSpan( | ||
text: parameter.name, | ||
style: textStyle, | ||
); | ||
} | ||
|
||
return WidgetSpan( | ||
alignment: PlaceholderAlignment.middle, | ||
child: switch (parameter.type) { | ||
core.RichObjectParameter_Type.user || | ||
core.RichObjectParameter_Type.call || | ||
core.RichObjectParameter_Type.guest || | ||
core.RichObjectParameter_Type.userGroup => | ||
NeonRichObjectMention( | ||
parameter: parameter, | ||
textStyle: textStyle, | ||
), | ||
core.RichObjectParameter_Type.file => NeonRichObjectFile( | ||
parameter: parameter, | ||
textStyle: textStyle, | ||
), | ||
core.RichObjectParameter_Type.deckCard => NeonRichObjectDeckCard( | ||
parameter: parameter, | ||
), | ||
_ => NeonRichObjectFallback( | ||
parameter: parameter, | ||
textStyle: textStyle, | ||
), | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/neon_framework/packages/neon_rich_text/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: neon_rich_text | ||
description: A package for rendering rich text from Nextcloud | ||
version: 0.1.0 | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ^3.0.0 | ||
flutter: ^3.22.0 | ||
|
||
dependencies: | ||
built_collection: ^5.0.0 | ||
built_value: ^8.9.0 | ||
flutter: | ||
sdk: flutter | ||
flutter_material_design_icons: ^1.1.7296 | ||
intersperse: ^2.0.0 | ||
meta: ^1.0.0 | ||
neon_framework: | ||
git: | ||
url: https://github.com/nextcloud/neon | ||
path: packages/neon_framework | ||
nextcloud: ^8.1.0 | ||
|
||
dev_dependencies: | ||
custom_lint: ^0.7.0 | ||
flutter_test: | ||
sdk: flutter | ||
mocktail: ^1.0.4 | ||
neon_lints: | ||
git: | ||
url: https://github.com/nextcloud/neon | ||
path: packages/neon_lints | ||
provider: ^6.1.2 | ||
rxdart: ^0.28.0 | ||
url_launcher_platform_interface: ^2.3.2 | ||
|
||
flutter: | ||
uses-material-design: true |
22 changes: 22 additions & 0 deletions
22
packages/neon_framework/packages/neon_rich_text/pubspec_overrides.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# melos_managed_dependency_overrides: account_repository,cookie_store,dynamite_runtime,interceptor_http_client,neon_framework,neon_http_client,neon_lints,nextcloud,notifications_push_repository,sort_box | ||
dependency_overrides: | ||
account_repository: | ||
path: ../account_repository | ||
cookie_store: | ||
path: ../../../cookie_store | ||
dynamite_runtime: | ||
path: ../../../dynamite/packages/dynamite_runtime | ||
interceptor_http_client: | ||
path: ../../../interceptor_http_client | ||
neon_framework: | ||
path: ../.. | ||
neon_http_client: | ||
path: ../neon_http_client | ||
neon_lints: | ||
path: ../../../neon_lints | ||
nextcloud: | ||
path: ../../../nextcloud | ||
notifications_push_repository: | ||
path: ../notifications_push_repository | ||
sort_box: | ||
path: ../sort_box |
59 changes: 59 additions & 0 deletions
59
packages/neon_framework/packages/neon_rich_text/test/rich_objects/deck_card_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:neon_framework/models.dart'; | ||
import 'package:neon_framework/testing.dart'; | ||
import 'package:neon_rich_text/neon_rich_text.dart'; | ||
import 'package:nextcloud/core.dart' as core; | ||
import 'package:provider/provider.dart'; | ||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
|
||
void main() { | ||
late MockUrlLauncher urlLauncher; | ||
late Account account; | ||
|
||
setUpAll(() { | ||
FakeNeonStorage.setup(); | ||
|
||
registerFallbackValue(const LaunchOptions()); | ||
|
||
urlLauncher = MockUrlLauncher(); | ||
// ignore: discarded_futures | ||
when(() => urlLauncher.launchUrl(any(), any())).thenAnswer((_) async => true); | ||
|
||
UrlLauncherPlatform.instance = urlLauncher; | ||
}); | ||
|
||
setUp(() { | ||
account = MockAccount(); | ||
}); | ||
|
||
testWidgets('Deck card', (tester) async { | ||
await tester.pumpWidgetWithAccessibility( | ||
TestApp( | ||
providers: [ | ||
Provider<Account>.value(value: account), | ||
], | ||
child: NeonRichObjectDeckCard( | ||
parameter: core.RichObjectParameter( | ||
(b) => b | ||
..type = core.RichObjectParameter_Type.deckCard | ||
..id = '' | ||
..name = 'name' | ||
..boardname = 'boardname' | ||
..stackname = 'stackname' | ||
..link = '/link', | ||
), | ||
), | ||
), | ||
); | ||
expect(find.text('name'), findsOne); | ||
expect(find.text('boardname: stackname'), findsOne); | ||
await expectLater( | ||
find.byType(NeonRichObjectDeckCard), | ||
matchesGoldenFile('goldens/rich_text_object_deck_card.png'), | ||
); | ||
|
||
await tester.tap(find.byType(NeonRichObjectDeckCard)); | ||
verify(() => urlLauncher.launchUrl('https://cloud.example.com:8443/link', any())).called(1); | ||
}); | ||
} |
103 changes: 103 additions & 0 deletions
103
packages/neon_framework/packages/neon_rich_text/test/rich_objects/fallback_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:neon_framework/models.dart'; | ||
import 'package:neon_framework/testing.dart'; | ||
import 'package:neon_framework/widgets.dart'; | ||
import 'package:neon_rich_text/neon_rich_text.dart'; | ||
import 'package:nextcloud/core.dart' as core; | ||
import 'package:provider/provider.dart'; | ||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
|
||
void main() { | ||
late MockUrlLauncher urlLauncher; | ||
late Account account; | ||
|
||
setUpAll(() { | ||
FakeNeonStorage.setup(); | ||
|
||
registerFallbackValue(const LaunchOptions()); | ||
|
||
urlLauncher = MockUrlLauncher(); | ||
// ignore: discarded_futures | ||
when(() => urlLauncher.launchUrl(any(), any())).thenAnswer((_) async => true); | ||
|
||
UrlLauncherPlatform.instance = urlLauncher; | ||
}); | ||
|
||
setUp(() { | ||
account = MockAccount(); | ||
}); | ||
|
||
group('Fallback', () { | ||
testWidgets('Opens link', (tester) async { | ||
await tester.pumpWidgetWithAccessibility( | ||
TestApp( | ||
providers: [ | ||
Provider<Account>.value(value: account), | ||
], | ||
child: NeonRichObjectFallback( | ||
parameter: core.RichObjectParameter( | ||
(b) => b | ||
..type = core.RichObjectParameter_Type.calendarEvent | ||
..id = '' | ||
..name = 'name' | ||
..link = '/link', | ||
), | ||
textStyle: null, | ||
), | ||
), | ||
); | ||
|
||
await tester.tap(find.byType(NeonRichObjectFallback)); | ||
verify(() => urlLauncher.launchUrl('https://cloud.example.com:8443/link', any())).called(1); | ||
}); | ||
|
||
testWidgets('Without icon', (tester) async { | ||
await tester.pumpWidgetWithAccessibility( | ||
TestApp( | ||
child: NeonRichObjectFallback( | ||
parameter: core.RichObjectParameter( | ||
(b) => b | ||
..type = core.RichObjectParameter_Type.addressbook | ||
..id = '' | ||
..name = 'name', | ||
), | ||
textStyle: null, | ||
), | ||
), | ||
); | ||
expect(find.byType(NeonUriImage), findsNothing); | ||
expect(find.text('name'), findsOne); | ||
await expectLater( | ||
find.byType(NeonRichObjectFallback), | ||
matchesGoldenFile('goldens/rich_text_object_fallback_without_icon.png'), | ||
); | ||
}); | ||
|
||
testWidgets('With icon', (tester) async { | ||
await tester.pumpWidgetWithAccessibility( | ||
TestApp( | ||
providers: [ | ||
Provider<Account>.value(value: account), | ||
], | ||
child: NeonRichObjectFallback( | ||
parameter: core.RichObjectParameter( | ||
(b) => b | ||
..type = core.RichObjectParameter_Type.addressbook | ||
..id = '' | ||
..name = 'name' | ||
..iconUrl = '', | ||
), | ||
textStyle: null, | ||
), | ||
), | ||
); | ||
expect(find.byType(NeonUriImage), findsOne); | ||
expect(find.text('name'), findsOne); | ||
await expectLater( | ||
find.byType(NeonRichObjectFallback), | ||
matchesGoldenFile('goldens/rich_text_object_fallback_with_icon.png'), | ||
); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.