@bardway/trpg-notebook-native 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ MingriAgency TRPG Engine
2
+ Copyright (c) 2026 Lex
3
+
4
+ Portions extracted and adapted from MingriAgencyCOC,
5
+ Copyright (c) 2025 Lex, licensed under the MIT License.
6
+ Source: https://github.com/bardway/mingriAgency_COC
7
+ The complete source attribution and extraction mapping are maintained in
8
+ docs/architecture and docs/guidance in the Engine repository.
9
+
10
+ Third-party dependencies retain their own licenses and copyright notices.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @bardway/trpg-notebook-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Android 笔记 SQLite、WebView 阅读器及存储驱动适配。
4
+
5
+ 初始版本 `0.1.0`,提供 ESM JavaScript 和 TypeScript 声明。
6
+
7
+ ## 安装
8
+
9
+ ```sh
10
+ npm install --save-exact @bardway/trpg-notebook-native@0.1.0
11
+ ```
12
+
13
+ 需要对应 Expo/React Native peer 和 `/app.plugin` 配置。SQLite 与 Reader 原生模块提供 Android 实现;宿主配置实际字体资源。iOS 需要独立适配。
14
+
15
+ ## 公开入口
16
+
17
+ - `@bardway/trpg-notebook-native`
18
+ - `@bardway/trpg-notebook-native/storage-drivers`
19
+ - `@bardway/trpg-notebook-native/chunked-secure`
20
+ - `@bardway/trpg-notebook-native/app.plugin`
21
+
22
+ ## 平台依赖
23
+
24
+ - `expo@~55.0.0`
25
+ - `expo-document-picker@~55.0.17`
26
+ - `expo-file-system@~55.0.26`
27
+ - `react@19.2.0`
28
+ - `react-native@0.83.10`
29
+ - `react-native-webview@13.16.0`
30
+ - `@expo/config-plugins@55.0.11`(按使用入口安装)
31
+
32
+ 完整配置、示例和平台限制见[使用说明](https://github.com/bardway/mingriAgency_TRPGEngine/blob/main/docs/guidance/package-usage.md)。
33
+
34
+ MIT。保留随包分发的 LICENSE、NOTICE 和第三方许可。
@@ -0,0 +1,22 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'expo-module-gradle-plugin'
4
+ }
5
+
6
+ group = 'expo.modules.notebookstorage'
7
+ version = '0.1.0'
8
+
9
+ android {
10
+ namespace 'expo.modules.notebookstorage'
11
+ defaultConfig {
12
+ versionCode 1
13
+ versionName '0.1.0'
14
+ testInstrumentationRunner 'android.test.InstrumentationTestRunner'
15
+ testApplicationId 'org.bardway.trpg.notebook.tests'
16
+ }
17
+ }
18
+
19
+ dependencies {
20
+ // Android's built-in test APIs are optional SDK libraries on API 28+.
21
+ androidTestCompileOnly files("${android.sdkDirectory}/platforms/android-${android.compileSdk}/optional/android.test.base.jar")
22
+ }
@@ -0,0 +1 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,51 @@
1
+ package expo.modules.notebookstorage
2
+
3
+ import android.database.sqlite.SQLiteFullException
4
+ import android.database.sqlite.SQLiteDiskIOException
5
+ import android.database.sqlite.SQLiteReadOnlyDatabaseException
6
+ import android.database.sqlite.SQLiteCantOpenDatabaseException
7
+ import expo.modules.kotlin.modules.Module
8
+ import expo.modules.kotlin.modules.ModuleDefinition
9
+ import kotlinx.coroutines.CoroutineScope
10
+ import kotlinx.coroutines.SupervisorJob
11
+ import kotlinx.coroutines.asCoroutineDispatcher
12
+ import java.util.concurrent.Executors
13
+
14
+ class NotebookStorageModule : Module() {
15
+ private val executor = Executors.newSingleThreadExecutor()
16
+ private val dispatcher = executor.asCoroutineDispatcher()
17
+ private val scope = CoroutineScope(SupervisorJob() + dispatcher)
18
+ private val storeDelegate = lazy {
19
+ NotebookStore(requireNotNull(appContext.reactContext).applicationContext)
20
+ }
21
+ private val store get() = storeDelegate.value
22
+ private fun safeCall(block: () -> String): String = try { block() } catch (_: SQLiteFullException) {
23
+ throw IllegalStateException("设备存储空间不足,未提交的手记仍可重试")
24
+ } catch (_: SQLiteDiskIOException) {
25
+ throw IllegalStateException("设备存储读写失败,原有手记已保留,请重试")
26
+ } catch (_: SQLiteReadOnlyDatabaseException) {
27
+ throw IllegalStateException("手记本地存储不可写,未提交内容仍可重试")
28
+ } catch (_: SQLiteCantOpenDatabaseException) {
29
+ throw IllegalStateException("无法打开本地手记,请检查设备存储后重试")
30
+ }
31
+
32
+ override fun definition() = ModuleDefinition {
33
+ Name("NotebookStorage")
34
+ AsyncFunction("capabilities") { safeCall { store.capabilities() } }.runOnQueue(scope)
35
+ AsyncFunction("ensureWorkspace") { payload: String -> safeCall { store.ensureWorkspace(payload) } }.runOnQueue(scope)
36
+ AsyncFunction("readDocument") { payload: String -> safeCall { store.readDocument(payload) } }.runOnQueue(scope)
37
+ AsyncFunction("initializeMemoTemplate") { payload: String -> safeCall { store.initializeMemoTemplate(payload) } }.runOnQueue(scope)
38
+ AsyncFunction("importDocument") { payload: String -> safeCall { store.importDocument(payload) } }.runOnQueue(scope)
39
+ AsyncFunction("commitOperation") { payload: String -> safeCall { store.commitOperation(payload) } }.runOnQueue(scope)
40
+ AsyncFunction("saveViewport") { payload: String -> safeCall { store.saveViewport(payload) } }.runOnQueue(scope)
41
+ AsyncFunction("saveLayoutProfile") { payload: String -> safeCall { store.saveLayoutProfile(payload) } }.runOnQueue(scope)
42
+ AsyncFunction("setActiveDocument") { payload: String -> safeCall { store.setActiveDocument(payload) } }.runOnQueue(scope)
43
+ AsyncFunction("deleteSession") { payload: String -> safeCall { store.deleteSession(payload) } }.runOnQueue(scope)
44
+ AsyncFunction("readImport") { payload: String -> safeCall { store.readImport(payload) } }.runOnQueue(scope)
45
+ AsyncFunction("flush") { safeCall { store.flush() } }.runOnQueue(scope)
46
+ OnDestroy {
47
+ executor.execute { if (storeDelegate.isInitialized()) store.close() }
48
+ executor.shutdown()
49
+ }
50
+ }
51
+ }