@api-client/ui 0.6.5 → 0.6.6
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/build/src/core/Activity.d.ts +7 -5
- package/build/src/core/Activity.d.ts.map +1 -1
- package/build/src/core/Activity.js +6 -4
- package/build/src/core/Activity.js.map +1 -1
- package/build/src/core/ActivityManager.d.ts +35 -2
- package/build/src/core/ActivityManager.d.ts.map +1 -1
- package/build/src/core/ActivityManager.js +11 -0
- package/build/src/core/ActivityManager.js.map +1 -1
- package/build/src/core/Fragment.d.ts +12 -2
- package/build/src/core/Fragment.d.ts.map +1 -1
- package/build/src/core/Fragment.js +11 -2
- package/build/src/core/Fragment.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/Activity.ts +8 -6
- package/src/core/ActivityManager.ts +41 -6
- package/src/core/Fragment.ts +14 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nothing, TemplateResult } from 'lit';
|
|
2
|
-
import { ActivityLifecycle, IntentResult, type Intent } from './ActivityManager.js';
|
|
2
|
+
import { ActivityLifecycle, IntentResult, type Intent, type ResolvedIntent } from './ActivityManager.js';
|
|
3
3
|
import { FragmentManager } from './FragmentManager.js';
|
|
4
4
|
import type { Fragment } from './Fragment.js';
|
|
5
5
|
import type { Application, UpdateRequest } from './Application.js';
|
|
@@ -212,17 +212,19 @@ export declare class Activity extends EventTarget {
|
|
|
212
212
|
startActivity(intent: Intent): Promise<Activity>;
|
|
213
213
|
/**
|
|
214
214
|
* Starts a new activity for a result.
|
|
215
|
+
* @template T The type of the result data expected.
|
|
215
216
|
* @param intent The intent to start.
|
|
216
|
-
* @returns A promise that resolves when the started activity finishes, returning the result Intent
|
|
217
|
+
* @returns A promise that resolves when the started activity finishes, returning the result Intent with
|
|
218
|
+
* data of type T.
|
|
217
219
|
* @example
|
|
218
220
|
* ```typescript
|
|
219
|
-
* const resultIntent = await this.startActivityForResult({ action: '
|
|
221
|
+
* const resultIntent = await this.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
|
|
220
222
|
* if (resultIntent.resultCode === IntentResult.RESULT_OK) {
|
|
221
|
-
*
|
|
223
|
+
* console.log(resultIntent.data?.userId);
|
|
222
224
|
* }
|
|
223
225
|
* ```
|
|
224
226
|
*/
|
|
225
|
-
startActivityForResult(intent: Intent): Promise<
|
|
227
|
+
startActivityForResult<T>(intent: Intent): Promise<ResolvedIntent<T | undefined>>;
|
|
226
228
|
/**
|
|
227
229
|
* Sets the result to be returned to the calling activity.
|
|
228
230
|
* @param resultCode The result code.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAGzF,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,YAAY,CAAA;IACxB,IAAI,CAAC,EAAE,OAA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272,13 +272,15 @@ let Activity = (() => {
|
|
|
272
272
|
}
|
|
273
273
|
/**
|
|
274
274
|
* Starts a new activity for a result.
|
|
275
|
+
* @template T The type of the result data expected.
|
|
275
276
|
* @param intent The intent to start.
|
|
276
|
-
* @returns A promise that resolves when the started activity finishes, returning the result Intent
|
|
277
|
+
* @returns A promise that resolves when the started activity finishes, returning the result Intent with
|
|
278
|
+
* data of type T.
|
|
277
279
|
* @example
|
|
278
280
|
* ```typescript
|
|
279
|
-
* const resultIntent = await this.startActivityForResult({ action: '
|
|
281
|
+
* const resultIntent = await this.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
|
|
280
282
|
* if (resultIntent.resultCode === IntentResult.RESULT_OK) {
|
|
281
|
-
*
|
|
283
|
+
* console.log(resultIntent.data?.userId);
|
|
282
284
|
* }
|
|
283
285
|
* ```
|
|
284
286
|
*/
|
|
@@ -322,7 +324,7 @@ let Activity = (() => {
|
|
|
322
324
|
if (event.type === EventTypes.Intent.startActivityForResult) {
|
|
323
325
|
const info = event.detail;
|
|
324
326
|
const result = await this.startActivityForResult(info.intent);
|
|
325
|
-
info.onResult(
|
|
327
|
+
info.onResult(result.result, result);
|
|
326
328
|
}
|
|
327
329
|
else if (event.type === EventTypes.Intent.startActivity) {
|
|
328
330
|
await this.startActivity(event.detail.intent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Activity.js","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,OAAO,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AASpD;;;;;;;;;;;;;;;;;;;;;;;;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AED;;;;;;;;WAQG;QACH,SAAS,CAAC,UAAwB,EAAE,IAAc;YAChD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAA;YAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACxB,CAAC;QAED;;;WAGG;QACH,SAAS;YACP,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QAED;;;;;;;;;;;WAWG;QAEH,KAAK,CAAC,iBAAiB,CAAC,KAA6D;YACnF,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC;gBAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAkC,CAAA;gBACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAC7D,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;gBAC1D,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;;;SAtTU,QAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { nothing, TemplateResult } from 'lit'\nimport { ActivityLifecycle, IntentResult, type Intent } from './ActivityManager.js'\nimport { FragmentManager } from './FragmentManager.js'\nimport type { Fragment } from './Fragment.js'\nimport type { Application, UpdateRequest } from './Application.js'\nimport { bound } from '../decorators/bound.js'\nimport type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js'\nimport { EventTypes } from '../events/EventTypes.js'\n\nexport interface ActivityResult {\n requestCode: number\n resultCode: IntentResult\n data?: unknown\n intent: Intent\n}\n\n/**\n * ## Activity\n *\n * `Activity` is a core building block of your application, representing a single,\n * focused operation that a user can perform.\n * Activities manage their own lifecycle, UI, and fragments, and communicate with the application\n * and other activities via intents.\n *\n * Activities are managed by the application and can be started, paused, resumed, stopped,\n * and destroyed according to the app's navigation and user actions.\n * They can also start other activities for results, manage fragments, and handle intent\n * events dispatched by hosted web components.\n *\n * ### Lifecycle Methods\n * - `onCreate(intent?)` - Called when the activity is first created.\n * - `onStart()` - Called when the activity becomes visible to the user.\n * - `onResume()` - Called when the activity gains focus and becomes interactive.\n * - `onPause()` - Called when the activity loses focus but is still visible.\n * - `onStop()` - Called when the activity is no longer visible.\n * - `onDestroy()` - Called before the activity is destroyed.\n * - `onRestart()` - Called after the activity has been stopped, just prior to it being started again.\n *\n * ### Example\n * ```typescript\n * class MyActivity extends Activity {\n * async onCreate(intent?: Intent) {\n * super.onCreate(intent);\n * // Initialization logic here\n * }\n *\n * render() {\n * return html`<h1>Hello from MyActivity!</h1>`;\n * }\n * }\n * ```\n */\nexport class Activity extends EventTarget {\n /**\n * The root element where the activity's content should be rendered.\n * Set this if you want to render outside the application's default render root (e.g., for modals).\n */\n renderRoot?: HTMLElement\n\n /**\n * An optional static action name for the activity.\n * Use this as the registration key for referencing the activity in intents.\n *\n * @example\n * ```typescript\n * class LoginActivity extends Activity {\n * static action = 'login';\n * }\n * ```\n */\n static action?: string\n\n /** The current lifecycle state of the activity. */\n public lifecycle: ActivityLifecycle = ActivityLifecycle.Initialized\n\n /** The parent application instance. */\n protected parent: Application\n\n /** The fragment manager for managing fragments within this activity. */\n protected manager: FragmentManager\n\n /** Data to be returned as a result to the calling activity. */\n protected resultData?: unknown\n\n /** The exit code for the activity result. */\n protected exitCode = IntentResult.RESULT_CANCELED\n\n /** Gets the current result code for the activity. */\n get resultCode(): IntentResult {\n return this.exitCode\n }\n\n /**\n * Constructs a new Activity.\n * @param parent The parent application instance.\n */\n constructor(parent: Application) {\n super()\n this.parent = parent\n this.manager = new FragmentManager(this)\n }\n\n /**\n * Returns the current activity instance.\n * @returns This activity.\n */\n getActivity(): Activity {\n return this\n }\n\n /**\n * Checks if the activity is in the `Destroyed` state.\n * @returns `true` if destroyed, `false` otherwise.\n */\n isDestroyed(): boolean {\n return this.lifecycle === ActivityLifecycle.Destroyed\n }\n\n /**\n * Checks if the activity is in the `Resumed` state.\n * @returns `true` if resumed, `false` otherwise.\n */\n isResumed(): boolean {\n return this.lifecycle === ActivityLifecycle.Resumed\n }\n\n /**\n * Called when the activity is starting. Override to perform initialization logic.\n * @param intent Optional intent data.\n * @example\n * ```typescript\n * async onCreate(intent?: Intent) {\n * await fetchData();\n * }\n * ```\n */\n onCreate(intent?: Intent): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:create', { detail: intent }))\n }\n\n /**\n * Called when the activity becomes visible to the user.\n * Override to start animations or prepare UI.\n */\n onStart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:start', { detail: null }))\n }\n\n /**\n * Called when the activity gains focus and becomes interactive.\n * Override to start input handling or resume tasks.\n */\n onResume(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:resume', { detail: null }))\n }\n\n /**\n * Called when the activity loses focus but is still visible.\n * Override to pause ongoing tasks or save state.\n */\n onPause(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:pause', { detail: null }))\n }\n\n /**\n * Called when the activity is no longer visible to the user.\n * Override to stop UI updates or animations.\n */\n onStop(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:stop', { detail: null }))\n }\n\n /**\n * Called after the activity has been stopped, just prior to it being started again.\n */\n onRestart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:restart', { detail: null }))\n }\n\n /**\n * Called before the activity is destroyed. Override to clean up resources.\n */\n onDestroy(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:destroy', { detail: null }))\n this.manager.onDestroy()\n }\n\n /**\n * Called when a new intent is delivered to the activity.\n * Override to handle new intents.\n * @param intent New intent data.\n */\n onNewIntent(intent: Intent): void | Promise<void> {\n // Override in subclass if needed\n }\n\n /**\n * Called by the renderer when the activity is rendered for the first time.\n * Override to perform actions after first render.\n */\n onFirstRender(): void {\n // Override in subclass if needed\n }\n\n /**\n * Renders the activity's view. Override to provide UI.\n * @returns A Lit TemplateResult or `nothing` if nothing should be rendered.\n * @example\n * ```typescript\n * render() {\n * return html`<div>Hello, world!</div>`;\n * }\n * ```\n */\n render(): TemplateResult | typeof nothing {\n return nothing\n }\n\n /**\n * Finishes the activity and notifies the application.\n * @example\n * ```typescript\n * await this.finish();\n * ```\n */\n async finish(): Promise<void> {\n await this.getApplication().manager.finishActivity(this)\n }\n\n /**\n * Requests the parent application to update the UI.\n * @param opts Update options.\n * @example\n * ```typescript\n * this.requestUpdate();\n * ```\n */\n requestUpdate(opts: UpdateRequest = {}): void {\n const { activity = true } = opts\n if (activity) {\n this.manager.updateActiveFragments()\n }\n this.parent.requestUpdate(opts)\n }\n\n /**\n * Registers a new fragment with this activity.\n * @param key The fragment's key.\n * @param fragment The fragment instance.\n * @param data Optional data to pass to the fragment.\n * @example\n * ```typescript\n * await this.addFragment('profile', new ProfileFragment());\n * ```\n */\n async addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void> {\n await this.manager.attachFragment(key, fragment, this, data)\n }\n\n /**\n * Shows a registered fragment.\n * @param key The fragment's key.\n * @param root Optional root element to render into.\n */\n async showFragment(key: string, root?: HTMLElement): Promise<void> {\n await this.manager.showFragment(key, root)\n }\n\n /**\n * Hides a registered fragment.\n * @param key The fragment's key.\n */\n async hideFragment(key: string): Promise<void> {\n const fragment = this.manager.findFragment(key)\n if (fragment) {\n await this.manager.hideFragment(fragment)\n }\n }\n\n /**\n * Returns the parent application instance.\n * @returns The application.\n */\n getApplication(): Application {\n return this.parent\n }\n\n /**\n * Starts a new activity.\n * @param intent The intent to start.\n * @example\n * ```typescript\n * await this.startActivity({ action: 'login' });\n * ```\n */\n async startActivity(intent: Intent): Promise<Activity> {\n const { manager } = this.getApplication()\n return manager.startActivity(intent)\n }\n\n /**\n * Starts a new activity for a result.\n * @param intent The intent to start.\n * @returns A promise that resolves when the started activity finishes, returning the result Intent.\n * @example\n * ```typescript\n * const resultIntent = await this.startActivityForResult({ action: 'pickFile' });\n * if (resultIntent.resultCode === IntentResult.RESULT_OK) {\n * // handle result\n * }\n * ```\n */\n async startActivityForResult(intent: Intent): Promise<Intent> {\n const { manager } = this.getApplication()\n return manager.startActivityForResult(intent)\n }\n\n /**\n * Sets the result to be returned to the calling activity.\n * @param resultCode The result code.\n * @param data Optional result data.\n * @example\n * ```typescript\n * this.setResult(IntentResult.RESULT_OK, { userId: 123 });\n * ```\n */\n setResult(resultCode: IntentResult, data?: unknown): void {\n this.exitCode = resultCode\n this.resultData = data\n }\n\n /**\n * Gets the result data set by `setResult`.\n * @returns The result data or `undefined`.\n */\n getResult(): unknown | undefined {\n return this.resultData\n }\n\n /**\n * Handles intent events dispatched by web components hosted by this activity.\n *\n * Usage example:\n * ```html\n * <custom-element @startactivity=\"${this.handleIntentEvent}\"></custom-element>\n * <custom-element @startactivityforresult=\"${this.handleIntentEvent}\"></custom-element>\n * ```\n *\n * @param event The intent event.\n * @throws Error if the event type is not recognized.\n */\n @bound\n async handleIntentEvent(event: CustomEvent<ActivityDetail | ActivityWithResultDetail>): Promise<void> {\n if (event.type === EventTypes.Intent.startActivityForResult) {\n const info = event.detail as ActivityWithResultDetail\n const result = await this.startActivityForResult(info.intent)\n info.onResult(IntentResult.RESULT_OK, result)\n } else if (event.type === EventTypes.Intent.startActivity) {\n await this.startActivity(event.detail.intent)\n } else {\n throw new Error(`Unrecognized intent event: ${event.type}`)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Activity.js","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,OAAO,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,i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a,CAAC,MAAM,CAAC,CAAA;QACtC,CAAC;QAED;;;;;;;;;;;;;WAaG;QACH,KAAK,CAAC,sBAAsB,CAAI,MAAc;YAC5C,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;YACzC,OAAO,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAA;QAC/C,CAAC;QAED;;;;;;;;WAQG;QACH,SAAS,CAAC,UAAwB,EAAE,IAAc;YAChD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAA;YAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACxB,CAAC;QAED;;;WAGG;QACH,SAAS;YACP,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QAED;;;;;;;;;;;WAWG;QAEH,KAAK,CAAC,iBAAiB,CAAC,KAA6D;YACnF,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC;gBAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAkC,CAAA;gBACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAC7D,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YACtC,CAAC;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;gBAC1D,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;;;SAxTU,QAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { nothing, TemplateResult } from 'lit'\nimport { ActivityLifecycle, IntentResult, type Intent, type ResolvedIntent } from './ActivityManager.js'\nimport { FragmentManager } from './FragmentManager.js'\nimport type { Fragment } from './Fragment.js'\nimport type { Application, UpdateRequest } from './Application.js'\nimport { bound } from '../decorators/bound.js'\nimport type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js'\nimport { EventTypes } from '../events/EventTypes.js'\n\nexport interface ActivityResult {\n requestCode: number\n resultCode: IntentResult\n data?: unknown\n intent: Intent\n}\n\n/**\n * ## Activity\n *\n * `Activity` is a core building block of your application, representing a single,\n * focused operation that a user can perform.\n * Activities manage their own lifecycle, UI, and fragments, and communicate with the application\n * and other activities via intents.\n *\n * Activities are managed by the application and can be started, paused, resumed, stopped,\n * and destroyed according to the app's navigation and user actions.\n * They can also start other activities for results, manage fragments, and handle intent\n * events dispatched by hosted web components.\n *\n * ### Lifecycle Methods\n * - `onCreate(intent?)` - Called when the activity is first created.\n * - `onStart()` - Called when the activity becomes visible to the user.\n * - `onResume()` - Called when the activity gains focus and becomes interactive.\n * - `onPause()` - Called when the activity loses focus but is still visible.\n * - `onStop()` - Called when the activity is no longer visible.\n * - `onDestroy()` - Called before the activity is destroyed.\n * - `onRestart()` - Called after the activity has been stopped, just prior to it being started again.\n *\n * ### Example\n * ```typescript\n * class MyActivity extends Activity {\n * async onCreate(intent?: Intent) {\n * super.onCreate(intent);\n * // Initialization logic here\n * }\n *\n * render() {\n * return html`<h1>Hello from MyActivity!</h1>`;\n * }\n * }\n * ```\n */\nexport class Activity extends EventTarget {\n /**\n * The root element where the activity's content should be rendered.\n * Set this if you want to render outside the application's default render root (e.g., for modals).\n */\n renderRoot?: HTMLElement\n\n /**\n * An optional static action name for the activity.\n * Use this as the registration key for referencing the activity in intents.\n *\n * @example\n * ```typescript\n * class LoginActivity extends Activity {\n * static action = 'login';\n * }\n * ```\n */\n static action?: string\n\n /** The current lifecycle state of the activity. */\n public lifecycle: ActivityLifecycle = ActivityLifecycle.Initialized\n\n /** The parent application instance. */\n protected parent: Application\n\n /** The fragment manager for managing fragments within this activity. */\n protected manager: FragmentManager\n\n /** Data to be returned as a result to the calling activity. */\n protected resultData?: unknown\n\n /** The exit code for the activity result. */\n protected exitCode = IntentResult.RESULT_CANCELED\n\n /** Gets the current result code for the activity. */\n get resultCode(): IntentResult {\n return this.exitCode\n }\n\n /**\n * Constructs a new Activity.\n * @param parent The parent application instance.\n */\n constructor(parent: Application) {\n super()\n this.parent = parent\n this.manager = new FragmentManager(this)\n }\n\n /**\n * Returns the current activity instance.\n * @returns This activity.\n */\n getActivity(): Activity {\n return this\n }\n\n /**\n * Checks if the activity is in the `Destroyed` state.\n * @returns `true` if destroyed, `false` otherwise.\n */\n isDestroyed(): boolean {\n return this.lifecycle === ActivityLifecycle.Destroyed\n }\n\n /**\n * Checks if the activity is in the `Resumed` state.\n * @returns `true` if resumed, `false` otherwise.\n */\n isResumed(): boolean {\n return this.lifecycle === ActivityLifecycle.Resumed\n }\n\n /**\n * Called when the activity is starting. Override to perform initialization logic.\n * @param intent Optional intent data.\n * @example\n * ```typescript\n * async onCreate(intent?: Intent) {\n * await fetchData();\n * }\n * ```\n */\n onCreate(intent?: Intent): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:create', { detail: intent }))\n }\n\n /**\n * Called when the activity becomes visible to the user.\n * Override to start animations or prepare UI.\n */\n onStart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:start', { detail: null }))\n }\n\n /**\n * Called when the activity gains focus and becomes interactive.\n * Override to start input handling or resume tasks.\n */\n onResume(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:resume', { detail: null }))\n }\n\n /**\n * Called when the activity loses focus but is still visible.\n * Override to pause ongoing tasks or save state.\n */\n onPause(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:pause', { detail: null }))\n }\n\n /**\n * Called when the activity is no longer visible to the user.\n * Override to stop UI updates or animations.\n */\n onStop(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:stop', { detail: null }))\n }\n\n /**\n * Called after the activity has been stopped, just prior to it being started again.\n */\n onRestart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:restart', { detail: null }))\n }\n\n /**\n * Called before the activity is destroyed. Override to clean up resources.\n */\n onDestroy(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:destroy', { detail: null }))\n this.manager.onDestroy()\n }\n\n /**\n * Called when a new intent is delivered to the activity.\n * Override to handle new intents.\n * @param intent New intent data.\n */\n onNewIntent(intent: Intent): void | Promise<void> {\n // Override in subclass if needed\n }\n\n /**\n * Called by the renderer when the activity is rendered for the first time.\n * Override to perform actions after first render.\n */\n onFirstRender(): void {\n // Override in subclass if needed\n }\n\n /**\n * Renders the activity's view. Override to provide UI.\n * @returns A Lit TemplateResult or `nothing` if nothing should be rendered.\n * @example\n * ```typescript\n * render() {\n * return html`<div>Hello, world!</div>`;\n * }\n * ```\n */\n render(): TemplateResult | typeof nothing {\n return nothing\n }\n\n /**\n * Finishes the activity and notifies the application.\n * @example\n * ```typescript\n * await this.finish();\n * ```\n */\n async finish(): Promise<void> {\n await this.getApplication().manager.finishActivity(this)\n }\n\n /**\n * Requests the parent application to update the UI.\n * @param opts Update options.\n * @example\n * ```typescript\n * this.requestUpdate();\n * ```\n */\n requestUpdate(opts: UpdateRequest = {}): void {\n const { activity = true } = opts\n if (activity) {\n this.manager.updateActiveFragments()\n }\n this.parent.requestUpdate(opts)\n }\n\n /**\n * Registers a new fragment with this activity.\n * @param key The fragment's key.\n * @param fragment The fragment instance.\n * @param data Optional data to pass to the fragment.\n * @example\n * ```typescript\n * await this.addFragment('profile', new ProfileFragment());\n * ```\n */\n async addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void> {\n await this.manager.attachFragment(key, fragment, this, data)\n }\n\n /**\n * Shows a registered fragment.\n * @param key The fragment's key.\n * @param root Optional root element to render into.\n */\n async showFragment(key: string, root?: HTMLElement): Promise<void> {\n await this.manager.showFragment(key, root)\n }\n\n /**\n * Hides a registered fragment.\n * @param key The fragment's key.\n */\n async hideFragment(key: string): Promise<void> {\n const fragment = this.manager.findFragment(key)\n if (fragment) {\n await this.manager.hideFragment(fragment)\n }\n }\n\n /**\n * Returns the parent application instance.\n * @returns The application.\n */\n getApplication(): Application {\n return this.parent\n }\n\n /**\n * Starts a new activity.\n * @param intent The intent to start.\n * @example\n * ```typescript\n * await this.startActivity({ action: 'login' });\n * ```\n */\n async startActivity(intent: Intent): Promise<Activity> {\n const { manager } = this.getApplication()\n return manager.startActivity(intent)\n }\n\n /**\n * Starts a new activity for a result.\n * @template T The type of the result data expected.\n * @param intent The intent to start.\n * @returns A promise that resolves when the started activity finishes, returning the result Intent with\n * data of type T.\n * @example\n * ```typescript\n * const resultIntent = await this.startActivityForResult<{ userId: string }>({ action: 'pickUser' });\n * if (resultIntent.resultCode === IntentResult.RESULT_OK) {\n * console.log(resultIntent.data?.userId);\n * }\n * ```\n */\n async startActivityForResult<T>(intent: Intent): Promise<ResolvedIntent<T | undefined>> {\n const { manager } = this.getApplication()\n return manager.startActivityForResult(intent)\n }\n\n /**\n * Sets the result to be returned to the calling activity.\n * @param resultCode The result code.\n * @param data Optional result data.\n * @example\n * ```typescript\n * this.setResult(IntentResult.RESULT_OK, { userId: 123 });\n * ```\n */\n setResult(resultCode: IntentResult, data?: unknown): void {\n this.exitCode = resultCode\n this.resultData = data\n }\n\n /**\n * Gets the result data set by `setResult`.\n * @returns The result data or `undefined`.\n */\n getResult(): unknown | undefined {\n return this.resultData\n }\n\n /**\n * Handles intent events dispatched by web components hosted by this activity.\n *\n * Usage example:\n * ```html\n * <custom-element @startactivity=\"${this.handleIntentEvent}\"></custom-element>\n * <custom-element @startactivityforresult=\"${this.handleIntentEvent}\"></custom-element>\n * ```\n *\n * @param event The intent event.\n * @throws Error if the event type is not recognized.\n */\n @bound\n async handleIntentEvent(event: CustomEvent<ActivityDetail | ActivityWithResultDetail>): Promise<void> {\n if (event.type === EventTypes.Intent.startActivityForResult) {\n const info = event.detail as ActivityWithResultDetail\n const result = await this.startActivityForResult(info.intent)\n info.onResult(result.result, result)\n } else if (event.type === EventTypes.Intent.startActivity) {\n await this.startActivity(event.detail.intent)\n } else {\n throw new Error(`Unrecognized intent event: ${event.type}`)\n }\n }\n}\n"]}
|
|
@@ -55,15 +55,38 @@ export declare enum IntentFlags {
|
|
|
55
55
|
ByReference = 4
|
|
56
56
|
}
|
|
57
57
|
export interface Intent<T = unknown> {
|
|
58
|
+
/**
|
|
59
|
+
* The action name the activity is registered for.
|
|
60
|
+
*/
|
|
58
61
|
action: string;
|
|
62
|
+
/**
|
|
63
|
+
* The data passed to the activity.
|
|
64
|
+
*/
|
|
59
65
|
data?: T;
|
|
66
|
+
/**
|
|
67
|
+
* The category of the activity.
|
|
68
|
+
* Optional and currently not used.
|
|
69
|
+
*/
|
|
60
70
|
category?: string[];
|
|
71
|
+
/**
|
|
72
|
+
* The flags that control the behavior of the activity.
|
|
73
|
+
*/
|
|
61
74
|
flags?: number;
|
|
62
75
|
/**
|
|
63
76
|
* The request code used to distinguish between different activities.
|
|
64
77
|
*/
|
|
65
78
|
requestCode?: number;
|
|
66
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* An intent returned by an activity after the activity result is ready.
|
|
82
|
+
* This object is only created when the activity is started with the `ForResult` flag.
|
|
83
|
+
*/
|
|
84
|
+
export interface ResolvedIntent<T = unknown> extends Intent<T> {
|
|
85
|
+
/**
|
|
86
|
+
* The result code returned by the activity.
|
|
87
|
+
*/
|
|
88
|
+
result: IntentResult;
|
|
89
|
+
}
|
|
67
90
|
export declare enum IntentResult {
|
|
68
91
|
RESULT_CANCELED = 0,
|
|
69
92
|
RESULT_OK = 1
|
|
@@ -145,9 +168,19 @@ export declare class ActivityManager {
|
|
|
145
168
|
/**
|
|
146
169
|
* Starts an activity that should return a result to the calling activity.
|
|
147
170
|
*
|
|
171
|
+
* @template T The type of the result data expected.
|
|
148
172
|
* @param intent The intent to start the activity.
|
|
149
|
-
|
|
150
|
-
|
|
173
|
+
* @returns A promise that resolves when the started activity finishes, returning the result Intent with
|
|
174
|
+
* data of type T.
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const resultIntent = await mgr.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
|
|
178
|
+
* if (resultIntent.resultCode === IntentResult.RESULT_OK) {
|
|
179
|
+
* console.log(resultIntent.data?.userId);
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
startActivityForResult<T>(intent: Intent): Promise<ResolvedIntent<T | undefined>>;
|
|
151
184
|
isDestroyed(activity: Activity): boolean;
|
|
152
185
|
/**
|
|
153
186
|
* @param activity The activity to finish.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityManager.d.ts","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,oBAAY,iBAAiB;IAC3B;;;OAGG;IACH,WAAW,IAAA;IACX;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,MAAM,IAAA;IACN;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,SAAS,IAAA;CACV;AAED,oBAAY,WAAW;IACrB;;OAEG;IACH,KAAK,IAAS;IACd;;OAEG;IACH,SAAS,IAAS;IAClB;;;;;OAKG;IACH,WAAW,IAAS;CACrB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,CAAC,CAAA;IACR,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,oBAAY,YAAY;IACtB,eAAe,IAAA;IACf,SAAS,IAAA;CACV;AA0BD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAA;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAA;CAC7C;AAED;;;;;;;;;GASG;AACH,qBAAa,eAAe;;IAC1B,OAAO,CAAC,eAAe,CAAC,CAAU;IAElC;;OAEG;IACH,OAAO,CAAC,eAAe,CAAqC;IAE5D;;OAEG;IACH,OAAO,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"ActivityManager.d.ts","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,oBAAY,iBAAiB;IAC3B;;;OAGG;IACH,WAAW,IAAA;IACX;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,MAAM,IAAA;IACN;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,SAAS,IAAA;CACV;AAED,oBAAY,WAAW;IACrB;;OAEG;IACH,KAAK,IAAS;IACd;;OAEG;IACH,SAAS,IAAS;IAClB;;;;;OAKG;IACH,WAAW,IAAS;CACrB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IACjC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,CAAA;IACR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D;;;;OAIG;YACW,0BAA0B;IAgBxC;;;;OAIG;YACW,0BAA0B;IAUxC;;;;;OAKG;YACW,8BAA8B;IAU5C;;;OAGG;IACH,OAAO,CAAC,eAAe;IAevB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAsBhC;;;;OAIG;IACH,cAAc,IAAI;QAChB,eAAe,EAAE,MAAM,CAAA;QACvB,eAAe,EAAE,MAAM,CAAA;QACvB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,EAAE,MAAM,EAAE,CAAA;QACzB,oBAAoB,EAAE,MAAM,EAAE,CAAA;KAC/B;IAWD;;;OAGG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;;;OAIG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAG5C"}
|
|
@@ -212,7 +212,17 @@ export class ActivityManager {
|
|
|
212
212
|
/**
|
|
213
213
|
* Starts an activity that should return a result to the calling activity.
|
|
214
214
|
*
|
|
215
|
+
* @template T The type of the result data expected.
|
|
215
216
|
* @param intent The intent to start the activity.
|
|
217
|
+
* @returns A promise that resolves when the started activity finishes, returning the result Intent with
|
|
218
|
+
* data of type T.
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const resultIntent = await mgr.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
|
|
222
|
+
* if (resultIntent.resultCode === IntentResult.RESULT_OK) {
|
|
223
|
+
* console.log(resultIntent.data?.userId);
|
|
224
|
+
* }
|
|
225
|
+
* ```
|
|
216
226
|
*/
|
|
217
227
|
async startActivityForResult(intent) {
|
|
218
228
|
const byReference = (intent.flags ?? 0) & IntentFlags.ByReference;
|
|
@@ -290,6 +300,7 @@ export class ActivityManager {
|
|
|
290
300
|
const resultIntent = {
|
|
291
301
|
...originalIntent,
|
|
292
302
|
data: activity.getResult(),
|
|
303
|
+
result: activity.resultCode,
|
|
293
304
|
};
|
|
294
305
|
resolver(resultIntent);
|
|
295
306
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityManager.js","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAEA,yDAAyD;AAEzD,MAAM,CAAN,IAAY,iBAoCX;AApCD,WAAY,iBAAiB;IAC3B;;;OAGG;IACH,uEAAW,CAAA;IACX;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,6DAAM,CAAA;IACN;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,mEAAS,CAAA;AACX,CAAC,EApCW,iBAAiB,KAAjB,iBAAiB,QAoC5B;AAED,MAAM,CAAN,IAAY,WAgBX;AAhBD,WAAY,WAAW;IACrB;;OAEG;IACH,+CAAc,CAAA;IACd;;OAEG;IACH,uDAAkB,CAAA;IAClB;;;;;OAKG;IACH,2DAAoB,CAAA;AACtB,CAAC,EAhBW,WAAW,KAAX,WAAW,QAgBtB;AAaD,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,qEAAe,CAAA;IACf,yDAAS,CAAA;AACX,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AA4CD;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAe;IAClB,eAAe,CAAW;IAElC;;OAEG;IACK,eAAe,GAAG,IAAI,GAAG,EAA2B,CAAA;IAE5D;;OAEG;IACK,eAAe,GAAG,IAAI,GAAG,EAAoC,CAAA;IAErE;;;OAGG;IACK,aAAa,GAAyB,EAAE,CAAA;IAEhD;;;OAGG;IACK,kBAAkB,GAAyB,EAAE,CAAA;IAE7C,kBAAkB;QACxB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,CAAa;IAE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IACH,CAAC;IAED;;;OAGG;IACH,oBAAoB;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAA;IAChD,CAAC;IAED;;;;OAIG;IACH,kBAAkB,CAAC,MAAc;QAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CACF","sourcesContent":["import type { Activity } from './Activity.js'\nimport type { Application } from './Application.js'\n// import { navigateScreen } from './ApplicationRoute.js'\n\nexport enum ActivityLifecycle {\n /**\n * The activity is initialized, but not yet created.\n * This is the initial state of the activity.\n */\n Initialized,\n /**\n * The activity is created, but not yet started.\n * This is the state after the `onCreate()` method is called.\n */\n Created,\n /**\n * The activity is started, but not yet resumed.\n * This is the state after the `onStart()` method is called.\n */\n Started,\n /**\n * The activity is resumed and visible to the user.\n * This is the state after the `onResume()` method is called.\n */\n Resumed,\n /**\n * The activity is paused, but still visible to the user.\n * This is the state after the `onPause()` method is called.\n */\n Paused,\n /**\n * The activity is stopped and no longer visible to the user.\n * This is the state after the `onStop()` method is called.\n */\n Stopped,\n /**\n * The activity is destroyed and no longer exists.\n * This is the state after the `onDestroy()` method is called.\n */\n Destroyed,\n}\n\nexport enum IntentFlags {\n /**\n * Marks that the activity should be rendered as a modal.\n */\n Modal = 1 << 0,\n /**\n * The activity is started for result.\n */\n ForResult = 1 << 1,\n /**\n * When set, the intent data is passed by reference.\n * By default the activity manager makes a copy of the intent data.\n * This is useful when the data is large and you want to avoid copying it\n * or when you want to share the same data between activities.\n */\n ByReference = 1 << 2,\n}\n\nexport interface Intent<T = unknown> {\n action: string\n data?: T\n category?: string[]\n flags?: number\n /**\n * The request code used to distinguish between different activities.\n */\n requestCode?: number\n}\n\nexport enum IntentResult {\n RESULT_CANCELED,\n RESULT_OK,\n}\n\n/**\n * Defines the information stored for each activity on the stack:\n * the Activity instance, a unique id, and optionally the Intent that started the activity\n * (useful for restoring state).\n */\ninterface ActivityStackEntry {\n /**\n * The instance of the activity.\n */\n activity: Activity\n /**\n * Activity's unique ID.\n */\n id: string\n /**\n * The intent that started the activity.\n */\n intent: Intent\n /**\n * The action name the activity is registered for.\n */\n action: string\n}\n\n/**\n * Type for activity constructor with static action property.\n */\nexport interface ActivityConstructor {\n new (parent: Application): Activity\n action?: string\n}\n\n/**\n * Enhanced activity registration options.\n */\nexport interface ActivityRegistrationOptions {\n /** Whether to override existing registrations */\n override?: boolean\n /** Optional validation function for intents */\n validateIntent?: (intent: Intent) => boolean\n}\n\n/**\n * Manages application activities.\n *\n * An activity is a screen or a portion of a rendered screen that has its own\n * lifecycle methods and routing.\n *\n * An activity is registered by its class definition. Because of that, activities\n * cannot have constructors that require own parameters. Activities have to be\n * self contained or use the event system to request data.\n */\nexport class ActivityManager {\n private currentActivity?: Activity\n\n /**\n * Stores activity *classes* by unique ID (action name).\n */\n private activityClasses = new Map<string, typeof Activity>()\n\n /**\n * Stores the resolvers for activities started for result.\n */\n private resultResolvers = new Map<Intent, (intent: Intent) => void>()\n\n /**\n * Represents the activity stack. It is used to manage\n * the UI state after calling the back action.\n */\n private activityStack: ActivityStackEntry[] = []\n\n /**\n * A stack of activities that are rendered over other activities\n * in a dialog.\n */\n private modalActivityStack: ActivityStackEntry[] = []\n\n private generateActivityId(): string {\n return Math.random().toString(36).substring(2, 15)\n }\n\n #parent: Application\n\n constructor(parent: Application) {\n this.#parent = parent\n // this.reflectEvent = this.reflectEvent.bind(this)\n }\n\n /**\n * Registers an activity class with enhanced options.\n * @param action The action name to register the activity for.\n * @param activityClass The activity class constructor.\n * @param options Optional registration configuration.\n */\n registerActivity(\n action: string,\n activityClass: ActivityConstructor,\n options: ActivityRegistrationOptions = {}\n ): void {\n const { override = false } = options\n\n if (this.activityClasses.has(action) && !override) {\n // eslint-disable-next-line no-console\n console.warn(`Activity with action \"${action}\" already registered.`, new Error().stack)\n return\n }\n\n // Validate that the class extends Activity\n if (typeof activityClass !== 'function') {\n throw new Error(`Invalid activity class for action \"${action}\": must be a constructor function`)\n }\n\n this.activityClasses.set(action, activityClass as typeof Activity)\n }\n\n /**\n * Creates an activity and pushes it into the stack, but it does not initialize any of the lifecycle methods.\n * It is a way to put an activity at some place of the stack,\n * but it will be only initialized when other activities finis.\n *\n * Note, if you add an uninitialized activity and you won't add more activities then this activity may never run.\n * Make sure that there's always another activity.\n *\n * @param intent The intent that created this activity.\n */\n async createActivity(intent: Intent): Promise<void> {\n const activity = this.buildActivity(intent)\n const activityId = this.generateActivityId()\n const stackEntry: ActivityStackEntry = { activity, id: activityId, intent, action: intent.action }\n this.activityStack.push(stackEntry)\n }\n\n // setupRoute(intent: Intent): void {\n // if (intent.data) {\n // const typed = intent.data as { uri?: string }\n // if (typed.uri) {\n // navigateScreen(typed.uri)\n // }\n // }\n // }\n\n /**\n * Starts a new activity and brings it to the foreground.\n *\n * @param intent The intent that created this activity.\n */\n async startActivity(intent: Intent): Promise<Activity> {\n const { currentActivity, activityStack } = this\n const lastIndex = activityStack.findLastIndex((entry) => entry.action === intent.action)\n // if the activity is in the history list, we bring it up and update intent.\n if (lastIndex > -1) {\n const info = activityStack[lastIndex]\n activityStack.splice(lastIndex, 1)\n activityStack.push({\n id: info.id,\n activity: info.activity,\n action: info.action,\n intent,\n })\n await info.activity.onNewIntent(intent)\n // TODO: Check if the activity is destroyed.\n // this.setupRoute(intent)\n await this.updateCurrentActivity(info.activity, false)\n return info.activity\n }\n const activity = this.buildActivity(intent)\n if (currentActivity) {\n await currentActivity.onPause()\n currentActivity.lifecycle = ActivityLifecycle.Paused\n }\n\n const activityId = this.generateActivityId()\n const stackEntry: ActivityStackEntry = { activity, id: activityId, intent, action: intent.action }\n // Modal activities are pretty much the same as regular activities but are rendered on top\n // of other activities. We keep track of them on another stack as all modal activities must\n // finish before returning to the regular stack.\n const isModal = (intent.flags ?? 0) & IntentFlags.Modal\n if (isModal) {\n this.modalActivityStack.push(stackEntry)\n } else {\n this.activityStack.push(stackEntry)\n }\n await activity.onCreate(intent)\n if (this.isDestroyed(activity)) {\n // the activity finished and the manager already took care of this situation.\n return activity\n }\n activity.lifecycle = ActivityLifecycle.Created\n\n await this.updateCurrentActivity(activity, !!isModal)\n if (this.isDestroyed(activity)) {\n // the activity finished and the manager already took care of this situation.\n return activity\n }\n // this.setupRoute(intent)\n return activity\n }\n\n private buildActivity(intent: Intent): Activity {\n const action = intent.action\n if (!this.activityClasses.has(action)) {\n throw new Error(`No activity class registered for action: ${action}`)\n }\n\n const ActivityClass = this.activityClasses.get(action)\n if (!ActivityClass) {\n throw new Error(`No activity class registered for action: ${action}`)\n }\n\n // We use the container to resolve dependencies, if any.\n // const activity = (await container.make(ActivityClass, [this.#parent])) as Activity\n return new ActivityClass(this.#parent)\n }\n\n /**\n * Starts an activity that should return a result to the calling activity.\n *\n * @param intent The intent to start the activity.\n */\n async startActivityForResult(intent: Intent): Promise<Intent> {\n const byReference = (intent.flags ?? 0) & IntentFlags.ByReference\n const shallowCopy = { ...intent }\n const data = shallowCopy.data\n if (byReference) {\n delete shallowCopy.data\n }\n const deepCopy = structuredClone(shallowCopy)\n if (data && byReference) {\n deepCopy.data = data\n }\n if (deepCopy.flags) {\n deepCopy.flags = deepCopy.flags | IntentFlags.ForResult\n } else {\n deepCopy.flags = IntentFlags.ForResult\n }\n\n return new Promise<Intent>((resolve, reject) => {\n this.resultResolvers.set(deepCopy, resolve)\n this.startActivity(deepCopy).catch((e) => {\n this.resultResolvers.delete(deepCopy)\n reject(e)\n })\n })\n }\n\n isDestroyed(activity: Activity): boolean {\n return activity.lifecycle === ActivityLifecycle.Destroyed\n }\n\n /**\n * @param activity The activity to finish.\n */\n async finishActivity(activity: Activity): Promise<void> {\n this.setupStyles(undefined, activity)\n const isModal = this.modalActivityStack.some((entry) => entry.activity === activity)\n const stack = isModal ? this.modalActivityStack : this.activityStack\n const index = stack.findIndex((entry) => entry.activity === activity)\n if (index !== -1) {\n const stackEntry = stack.splice(index, 1)[0]\n\n await stackEntry.activity.onPause()\n stackEntry.activity.lifecycle = ActivityLifecycle.Paused\n await stackEntry.activity.onStop()\n stackEntry.activity.lifecycle = ActivityLifecycle.Stopped\n await stackEntry.activity.onDestroy()\n stackEntry.activity.lifecycle = ActivityLifecycle.Destroyed\n\n // Clean up resources to prevent memory leaks\n this.cleanupActivity(stackEntry.activity)\n\n this.resolveActivityResult(stackEntry.activity, stackEntry.intent)\n\n // Resume the previous activity\n await this.bringLastActivityToFront()\n } else {\n if (activity.lifecycle === ActivityLifecycle.Created) {\n await activity.onStop()\n activity.lifecycle = ActivityLifecycle.Stopped\n }\n await activity.onDestroy()\n activity.lifecycle = ActivityLifecycle.Destroyed\n\n this.resolveActivityResult(activity, { action: '' })\n\n // This can happen when an activity finishes in one of the callback methods,\n // before it is added to the stack. In that case, we bring the last activity back to the front.\n await this.bringLastActivityToFront()\n }\n this.#parent.requestUpdate()\n }\n\n private resolveActivityResult(activity: Activity, originalIntent: Intent): void {\n const resolver = this.resultResolvers.get(originalIntent)\n // The activity might have not been started with startActivityForResult.\n // A thing to consider for the future is whether we should throw an error in a case where\n // the activity was started for result but the resolver was not found.\n if (resolver) {\n this.resultResolvers.delete(originalIntent)\n // We construct the result intent.\n // Ideally we would like to preserve the original intent structure but with new data.\n const resultIntent: Intent = {\n ...originalIntent,\n data: activity.getResult(),\n }\n resolver(resultIntent)\n }\n }\n\n private async bringLastActivityToFront(): Promise<void> {\n if (this.modalActivityStack.length > 0) {\n const previousEntry = this.modalActivityStack[this.activityStack.length - 1]\n await this.updateCurrentActivity(previousEntry.activity, false, previousEntry.intent)\n } else if (this.activityStack.length > 0) {\n const previousEntry = this.activityStack[this.activityStack.length - 1]\n await this.updateCurrentActivity(previousEntry.activity, false, previousEntry.intent)\n } else {\n this.currentActivity = undefined // No more activities\n }\n }\n\n getTopActivity(): Activity | undefined {\n const topModal = this.modalActivityStack.findLast((a) => a.activity.lifecycle === ActivityLifecycle.Resumed)\n if (topModal) {\n return topModal.activity\n }\n const top = this.activityStack.findLast((a) => a.activity.lifecycle === ActivityLifecycle.Resumed)\n return top ? top.activity : undefined\n }\n\n getCurrentActivity(): Activity | undefined {\n return this.currentActivity\n }\n\n /**\n * Sets the styles for the current activity.\n * This method adds or removes CSS classes based on the activity's class name\n * and action, allowing for dynamic styling based on the active activity.\n * @param activity The activity to set styles for.\n * If not provided, it will not set any styles.\n * If the activity is the same as the current one, it does nothing.\n */\n setupStyles(activity?: Activity, oldActivity?: Activity): void {\n if (activity === oldActivity) {\n return\n }\n const root = document?.documentElement\n if (!root) {\n return\n }\n if (oldActivity) {\n const ctor = oldActivity.constructor as typeof Activity\n root.classList.remove(ctor.name.toLowerCase())\n if (ctor.action) {\n root.classList.remove(ctor.action.replace(/\\//g, '-'))\n }\n }\n if (activity) {\n const ctor = activity.constructor as typeof Activity\n root.classList.add(ctor.name.toLowerCase())\n if (ctor.action) {\n root.classList.add(ctor.action.replace(/\\//g, '-'))\n }\n }\n }\n\n /**\n * A helper method to handle the transition between activities, ensuring\n * lifecycle methods are called in the correct order (pause the previous activity,\n * then start/resume the new one). This centralizes lifecycle management.\n *\n * @param activity The activity to bring to the foreground.\n */\n private async updateCurrentActivity(activity: Activity, isModal: boolean, intent?: Intent): Promise<void> {\n this.setupStyles(activity, this.currentActivity)\n if (\n this.currentActivity &&\n this.currentActivity !== activity &&\n this.currentActivity.lifecycle !== ActivityLifecycle.Destroyed &&\n // Make sure we don't pause the current activity if it's already paused.\n this.currentActivity.lifecycle !== ActivityLifecycle.Paused\n ) {\n await this.currentActivity.onPause()\n this.currentActivity.lifecycle = ActivityLifecycle.Paused\n }\n switch (activity.lifecycle) {\n case ActivityLifecycle.Paused:\n if (!(await this.transitionStartedToResumed(activity))) {\n return\n }\n break\n\n case ActivityLifecycle.Stopped:\n await this.safeExecuteLifecycleMethod(() => activity.onRestart(), activity, 'onRestart')\n activity.lifecycle = ActivityLifecycle.Resumed\n break\n\n case ActivityLifecycle.Destroyed:\n throw new Error(`Invalid state. The activity is already destroyed.`)\n\n case ActivityLifecycle.Created:\n if (!(await this.transitionCreatedToResumed(activity))) {\n return\n }\n break\n\n case ActivityLifecycle.Started:\n if (!(await this.transitionStartedToResumed(activity))) {\n return\n }\n break\n\n case ActivityLifecycle.Initialized:\n if (!(await this.transitionInitializedToResumed(activity, intent))) {\n return\n }\n break\n }\n if (!isModal) {\n // With a modal activity, it renders directly to the `<body>` and renders outside\n // of the normal rendering flow. We keep the previous activity rendered.\n this.currentActivity = activity\n }\n }\n\n /**\n * Safely executes an async lifecycle method with error handling.\n * @param lifecycleMethod The lifecycle method to execute.\n * @param activity The activity instance.\n * @param methodName The name of the method for error reporting.\n * @returns Promise that resolves when the method completes or rejects with wrapped error.\n */\n private async safeExecuteLifecycleMethod(\n lifecycleMethod: () => void | Promise<void>,\n activity: Activity,\n methodName: string\n ): Promise<void> {\n try {\n await lifecycleMethod()\n } catch (error) {\n const activityName = activity.constructor.name\n const wrappedError = new Error(\n `Error in ${activityName}.${methodName}(): ${error instanceof Error ? error.message : String(error)}`\n )\n wrappedError.cause = error\n // Allow the activity to handle its own errors, but still propagate\n this.#parent.dispatchEvent(\n new CustomEvent('activity-lifecycle-error', {\n detail: { activity, methodName, error: wrappedError },\n })\n )\n throw wrappedError\n }\n }\n\n /**\n * Allows navigating back through the activity stack.\n * Call `ActivityManager.navigateBack()` when the user performs a back action\n * (e.g., clicks a back button).\n * @returns Promise that resolves to true if navigation was successful, false if at root.\n */\n async navigateBack(): Promise<boolean> {\n // Handle modal activities first\n if (this.modalActivityStack.length > 0) {\n const topModal = this.modalActivityStack[this.modalActivityStack.length - 1]\n await this.finishActivity(topModal.activity)\n return true\n }\n\n // Handle regular activities\n if (this.activityStack.length > 1 && this.currentActivity) {\n await this.finishActivity(this.currentActivity)\n return true\n }\n\n // At root, cannot navigate back\n return false\n }\n\n /**\n * Navigates to a specific activity in the stack, clearing activities above it.\n * @param action The action of the activity to navigate to.\n * @returns Promise that resolves to true if navigation was successful.\n */\n async navigateToActivity(action: string): Promise<boolean> {\n const index = this.activityStack.findIndex((entry) => entry.action === action)\n if (index === -1) {\n return false\n }\n\n // Finish all activities above the target\n const activitiesToFinish = this.activityStack.slice(index + 1)\n for (const entry of activitiesToFinish) {\n await this.finishActivity(entry.activity)\n }\n\n // Bring the target activity to the front\n const targetEntry = this.activityStack[index]\n await this.updateCurrentActivity(targetEntry.activity, false, targetEntry.intent)\n return true\n }\n\n /**\n * Clears the entire activity stack and starts a new root activity.\n * @param intent The intent for the new root activity.\n */\n async clearStackAndStart(intent: Intent): Promise<void> {\n // Finish all activities\n const allActivities = [...this.activityStack, ...this.modalActivityStack]\n for (const entry of allActivities) {\n if (entry.activity.lifecycle !== ActivityLifecycle.Destroyed) {\n await this.finishActivity(entry.activity)\n }\n }\n\n // Clear stacks\n this.activityStack.length = 0\n this.modalActivityStack.length = 0\n this.currentActivity = undefined\n\n // Start new root activity\n await this.startActivity(intent)\n }\n\n /**\n * Creates an intent with better type safety and validation.\n * @param action The action name.\n * @param data Optional intent data.\n * @param options Optional intent configuration.\n * @returns A properly formed intent.\n */\n createIntent<T = unknown>(\n action: string,\n data?: T,\n options: {\n category?: string[]\n flags?: number\n requestCode?: number\n } = {}\n ): Intent<T> {\n if (!this.isActionRegistered(action)) {\n throw new Error(`Cannot create intent for unregistered action: ${action}`)\n }\n\n return {\n action,\n data,\n ...options,\n }\n }\n\n createRequestCode(): number {\n const min = 1000\n const max = 9999\n return Math.floor(Math.random() * (max - min) + min)\n }\n\n findActiveActivity(action: string): Activity | undefined {\n return this.activityStack.find((entry) => entry.action === action)?.activity\n }\n\n /**\n * Transitions an activity from Created to Resumed state.\n * @param activity The activity to transition.\n * @returns true if successful, false if activity was destroyed during transition.\n */\n private async transitionCreatedToResumed(activity: Activity): Promise<boolean> {\n await this.safeExecuteLifecycleMethod(() => activity.onStart(), activity, 'onStart')\n if (this.isDestroyed(activity)) {\n return false\n }\n activity.lifecycle = ActivityLifecycle.Started\n\n await this.safeExecuteLifecycleMethod(() => activity.onResume(), activity, 'onResume')\n if (this.isDestroyed(activity)) {\n return false\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n return true\n }\n\n /**\n * Transitions an activity from Started to Resumed state.\n * @param activity The activity to transition.\n * @returns true if successful, false if activity was destroyed during transition.\n */\n private async transitionStartedToResumed(activity: Activity): Promise<boolean> {\n await this.safeExecuteLifecycleMethod(() => activity.onResume(), activity, 'onResume')\n if (this.isDestroyed(activity)) {\n return false\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n return true\n }\n\n /**\n * Transitions an activity from Initialized to Resumed state.\n * @param activity The activity to transition.\n * @param intent The intent used to create the activity.\n * @returns true if successful, false if activity was destroyed during transition.\n */\n private async transitionInitializedToResumed(activity: Activity, intent?: Intent): Promise<boolean> {\n await this.safeExecuteLifecycleMethod(() => activity.onCreate(intent), activity, 'onCreate')\n activity.lifecycle = ActivityLifecycle.Created\n if (this.isDestroyed(activity)) {\n return false\n }\n\n return await this.transitionCreatedToResumed(activity)\n }\n\n /**\n * Cleans up resources for destroyed activities to prevent memory leaks.\n * @param activity The activity to clean up.\n */\n private cleanupActivity(activity: Activity): void {\n // Remove any event listeners that might create memory leaks\n // This changes the entire prototype chain of the activity,\n // effectively making it a new object. We can't do that as the activity will loose some\n // of its properties, so we don't do it for now.\n // if (activity instanceof EventTarget) {\n // // Clear all event listeners by replacing the activity with a new EventTarget\n // // This is a defensive approach since we can't enumerate listeners\n // Object.setPrototypeOf(activity, EventTarget.prototype)\n // }\n\n // Clear any references that might prevent garbage collection\n activity.renderRoot = undefined\n }\n\n /**\n * Validates that an activity stack is in a consistent state.\n * @param stack The activity stack to validate.\n * @returns Array of validation errors, empty if valid.\n */\n private validateStackConsistency(stack: ActivityStackEntry[]): string[] {\n const errors: string[] = []\n const seenIds = new Set<string>()\n\n for (const entry of stack) {\n if (seenIds.has(entry.id)) {\n errors.push(`Duplicate activity ID found: ${entry.id}`)\n }\n seenIds.add(entry.id)\n\n if (!entry.activity || !entry.id || !entry.action) {\n errors.push(`Invalid stack entry: missing required properties`)\n }\n\n if (entry.activity.lifecycle === ActivityLifecycle.Destroyed) {\n errors.push(`Destroyed activity found in stack: ${entry.id}`)\n }\n }\n\n return errors\n }\n\n /**\n * Gets diagnostic information about the current state of the activity manager.\n * Useful for debugging and monitoring.\n * @returns Object containing current state information.\n */\n getDiagnostics(): {\n totalActivities: number\n modalActivities: number\n currentActivity?: string\n topActivity?: string\n stackValidation: string[]\n modalStackValidation: string[]\n } {\n return {\n totalActivities: this.activityStack.length,\n modalActivities: this.modalActivityStack.length,\n currentActivity: this.currentActivity?.constructor.name,\n topActivity: this.getTopActivity()?.constructor.name,\n stackValidation: this.validateStackConsistency(this.activityStack),\n modalStackValidation: this.validateStackConsistency(this.modalActivityStack),\n }\n }\n\n /**\n * Gets all registered activity actions.\n * @returns Array of registered action names.\n */\n getRegisteredActions(): string[] {\n return Array.from(this.activityClasses.keys())\n }\n\n /**\n * Checks if an action is registered.\n * @param action The action to check.\n * @returns true if the action is registered, false otherwise.\n */\n isActionRegistered(action: string): boolean {\n return this.activityClasses.has(action)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActivityManager.js","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAEA,yDAAyD;AAEzD,MAAM,CAAN,IAAY,iBAoCX;AApCD,WAAY,iBAAiB;IAC3B;;;OAGG;IACH,uEAAW,CAAA;IACX;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,6DAAM,CAAA;IACN;;;OAGG;IACH,+DAAO,CAAA;IACP;;;OAGG;IACH,mEAAS,CAAA;AACX,CAAC,EApCW,iBAAiB,KAAjB,iBAAiB,QAoC5B;AAED,MAAM,CAAN,IAAY,WAgBX;AAhBD,WAAY,WAAW;IACrB;;OAEG;IACH,+CAAc,CAAA;IACd;;OAEG;IACH,uDAA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,CAAC;gBAClD,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAA;YACjE,CAAC;YAED,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,KAAK,iBAAiB,CAAC,SAAS,EAAE,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,sCAAsC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;YAC/D,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;OAIG;IACH,cAAc;QAQZ,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM;YAC1C,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,MAAM;YAC/C,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,IAAI;YACvD,WAAW,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,WAAW,CAAC,IAAI;YACpD,eAAe,EAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,aAAa,CAAC;YAClE,oBAAoB,EAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,kBAAkB,CAAC;SAC7E,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,oBAAoB;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAA;IAChD,CAAC;IAED;;;;OAIG;IACH,kBAAkB,CAAC,MAAc;QAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CACF","sourcesContent":["import type { Activity } from './Activity.js'\nimport type { Application } from './Application.js'\n// import { navigateScreen } from './ApplicationRoute.js'\n\nexport enum ActivityLifecycle {\n /**\n * The activity is initialized, but not yet created.\n * This is the initial state of the activity.\n */\n Initialized,\n /**\n * The activity is created, but not yet started.\n * This is the state after the `onCreate()` method is called.\n */\n Created,\n /**\n * The activity is started, but not yet resumed.\n * This is the state after the `onStart()` method is called.\n */\n Started,\n /**\n * The activity is resumed and visible to the user.\n * This is the state after the `onResume()` method is called.\n */\n Resumed,\n /**\n * The activity is paused, but still visible to the user.\n * This is the state after the `onPause()` method is called.\n */\n Paused,\n /**\n * The activity is stopped and no longer visible to the user.\n * This is the state after the `onStop()` method is called.\n */\n Stopped,\n /**\n * The activity is destroyed and no longer exists.\n * This is the state after the `onDestroy()` method is called.\n */\n Destroyed,\n}\n\nexport enum IntentFlags {\n /**\n * Marks that the activity should be rendered as a modal.\n */\n Modal = 1 << 0,\n /**\n * The activity is started for result.\n */\n ForResult = 1 << 1,\n /**\n * When set, the intent data is passed by reference.\n * By default the activity manager makes a copy of the intent data.\n * This is useful when the data is large and you want to avoid copying it\n * or when you want to share the same data between activities.\n */\n ByReference = 1 << 2,\n}\n\nexport interface Intent<T = unknown> {\n /**\n * The action name the activity is registered for.\n */\n action: string\n /**\n * The data passed to the activity.\n */\n data?: T\n /**\n * The category of the activity.\n * Optional and currently not used.\n */\n category?: string[]\n /**\n * The flags that control the behavior of the activity.\n */\n flags?: number\n /**\n * The request code used to distinguish between different activities.\n */\n requestCode?: number\n}\n\n/**\n * An intent returned by an activity after the activity result is ready.\n * This object is only created when the activity is started with the `ForResult` flag.\n */\nexport interface ResolvedIntent<T = unknown> extends Intent<T> {\n /**\n * The result code returned by the activity.\n */\n result: IntentResult\n}\n\nexport enum IntentResult {\n RESULT_CANCELED,\n RESULT_OK,\n}\n\n/**\n * Defines the information stored for each activity on the stack:\n * the Activity instance, a unique id, and optionally the Intent that started the activity\n * (useful for restoring state).\n */\ninterface ActivityStackEntry {\n /**\n * The instance of the activity.\n */\n activity: Activity\n /**\n * Activity's unique ID.\n */\n id: string\n /**\n * The intent that started the activity.\n */\n intent: Intent\n /**\n * The action name the activity is registered for.\n */\n action: string\n}\n\n/**\n * Type for activity constructor with static action property.\n */\nexport interface ActivityConstructor {\n new (parent: Application): Activity\n action?: string\n}\n\n/**\n * Enhanced activity registration options.\n */\nexport interface ActivityRegistrationOptions {\n /** Whether to override existing registrations */\n override?: boolean\n /** Optional validation function for intents */\n validateIntent?: (intent: Intent) => boolean\n}\n\n/**\n * Manages application activities.\n *\n * An activity is a screen or a portion of a rendered screen that has its own\n * lifecycle methods and routing.\n *\n * An activity is registered by its class definition. Because of that, activities\n * cannot have constructors that require own parameters. Activities have to be\n * self contained or use the event system to request data.\n */\nexport class ActivityManager {\n private currentActivity?: Activity\n\n /**\n * Stores activity *classes* by unique ID (action name).\n */\n private activityClasses = new Map<string, typeof Activity>()\n\n /**\n * Stores the resolvers for activities started for result.\n */\n private resultResolvers = new Map<Intent, (intent: ResolvedIntent) => void>()\n\n /**\n * Represents the activity stack. It is used to manage\n * the UI state after calling the back action.\n */\n private activityStack: ActivityStackEntry[] = []\n\n /**\n * A stack of activities that are rendered over other activities\n * in a dialog.\n */\n private modalActivityStack: ActivityStackEntry[] = []\n\n private generateActivityId(): string {\n return Math.random().toString(36).substring(2, 15)\n }\n\n #parent: Application\n\n constructor(parent: Application) {\n this.#parent = parent\n // this.reflectEvent = this.reflectEvent.bind(this)\n }\n\n /**\n * Registers an activity class with enhanced options.\n * @param action The action name to register the activity for.\n * @param activityClass The activity class constructor.\n * @param options Optional registration configuration.\n */\n registerActivity(\n action: string,\n activityClass: ActivityConstructor,\n options: ActivityRegistrationOptions = {}\n ): void {\n const { override = false } = options\n\n if (this.activityClasses.has(action) && !override) {\n // eslint-disable-next-line no-console\n console.warn(`Activity with action \"${action}\" already registered.`, new Error().stack)\n return\n }\n\n // Validate that the class extends Activity\n if (typeof activityClass !== 'function') {\n throw new Error(`Invalid activity class for action \"${action}\": must be a constructor function`)\n }\n\n this.activityClasses.set(action, activityClass as typeof Activity)\n }\n\n /**\n * Creates an activity and pushes it into the stack, but it does not initialize any of the lifecycle methods.\n * It is a way to put an activity at some place of the stack,\n * but it will be only initialized when other activities finis.\n *\n * Note, if you add an uninitialized activity and you won't add more activities then this activity may never run.\n * Make sure that there's always another activity.\n *\n * @param intent The intent that created this activity.\n */\n async createActivity(intent: Intent): Promise<void> {\n const activity = this.buildActivity(intent)\n const activityId = this.generateActivityId()\n const stackEntry: ActivityStackEntry = { activity, id: activityId, intent, action: intent.action }\n this.activityStack.push(stackEntry)\n }\n\n // setupRoute(intent: Intent): void {\n // if (intent.data) {\n // const typed = intent.data as { uri?: string }\n // if (typed.uri) {\n // navigateScreen(typed.uri)\n // }\n // }\n // }\n\n /**\n * Starts a new activity and brings it to the foreground.\n *\n * @param intent The intent that created this activity.\n */\n async startActivity(intent: Intent): Promise<Activity> {\n const { currentActivity, activityStack } = this\n const lastIndex = activityStack.findLastIndex((entry) => entry.action === intent.action)\n // if the activity is in the history list, we bring it up and update intent.\n if (lastIndex > -1) {\n const info = activityStack[lastIndex]\n activityStack.splice(lastIndex, 1)\n activityStack.push({\n id: info.id,\n activity: info.activity,\n action: info.action,\n intent,\n })\n await info.activity.onNewIntent(intent)\n // TODO: Check if the activity is destroyed.\n // this.setupRoute(intent)\n await this.updateCurrentActivity(info.activity, false)\n return info.activity\n }\n const activity = this.buildActivity(intent)\n if (currentActivity) {\n await currentActivity.onPause()\n currentActivity.lifecycle = ActivityLifecycle.Paused\n }\n\n const activityId = this.generateActivityId()\n const stackEntry: ActivityStackEntry = { activity, id: activityId, intent, action: intent.action }\n // Modal activities are pretty much the same as regular activities but are rendered on top\n // of other activities. We keep track of them on another stack as all modal activities must\n // finish before returning to the regular stack.\n const isModal = (intent.flags ?? 0) & IntentFlags.Modal\n if (isModal) {\n this.modalActivityStack.push(stackEntry)\n } else {\n this.activityStack.push(stackEntry)\n }\n await activity.onCreate(intent)\n if (this.isDestroyed(activity)) {\n // the activity finished and the manager already took care of this situation.\n return activity\n }\n activity.lifecycle = ActivityLifecycle.Created\n\n await this.updateCurrentActivity(activity, !!isModal)\n if (this.isDestroyed(activity)) {\n // the activity finished and the manager already took care of this situation.\n return activity\n }\n // this.setupRoute(intent)\n return activity\n }\n\n private buildActivity(intent: Intent): Activity {\n const action = intent.action\n if (!this.activityClasses.has(action)) {\n throw new Error(`No activity class registered for action: ${action}`)\n }\n\n const ActivityClass = this.activityClasses.get(action)\n if (!ActivityClass) {\n throw new Error(`No activity class registered for action: ${action}`)\n }\n\n // We use the container to resolve dependencies, if any.\n // const activity = (await container.make(ActivityClass, [this.#parent])) as Activity\n return new ActivityClass(this.#parent)\n }\n\n /**\n * Starts an activity that should return a result to the calling activity.\n *\n * @template T The type of the result data expected.\n * @param intent The intent to start the activity.\n * @returns A promise that resolves when the started activity finishes, returning the result Intent with\n * data of type T.\n * @example\n * ```typescript\n * const resultIntent = await mgr.startActivityForResult<{ userId: string }>({ action: 'pickUser' });\n * if (resultIntent.resultCode === IntentResult.RESULT_OK) {\n * console.log(resultIntent.data?.userId);\n * }\n * ```\n */\n async startActivityForResult<T>(intent: Intent): Promise<ResolvedIntent<T | undefined>> {\n const byReference = (intent.flags ?? 0) & IntentFlags.ByReference\n const shallowCopy = { ...intent }\n const data = shallowCopy.data\n if (byReference) {\n delete shallowCopy.data\n }\n const deepCopy = structuredClone(shallowCopy)\n if (data && byReference) {\n deepCopy.data = data\n }\n if (deepCopy.flags) {\n deepCopy.flags = deepCopy.flags | IntentFlags.ForResult\n } else {\n deepCopy.flags = IntentFlags.ForResult\n }\n\n return new Promise<ResolvedIntent<T>>((resolve, reject) => {\n this.resultResolvers.set(deepCopy, resolve as (intent: ResolvedIntent<unknown>) => void)\n this.startActivity(deepCopy).catch((e) => {\n this.resultResolvers.delete(deepCopy)\n reject(e)\n })\n })\n }\n\n isDestroyed(activity: Activity): boolean {\n return activity.lifecycle === ActivityLifecycle.Destroyed\n }\n\n /**\n * @param activity The activity to finish.\n */\n async finishActivity(activity: Activity): Promise<void> {\n this.setupStyles(undefined, activity)\n const isModal = this.modalActivityStack.some((entry) => entry.activity === activity)\n const stack = isModal ? this.modalActivityStack : this.activityStack\n const index = stack.findIndex((entry) => entry.activity === activity)\n if (index !== -1) {\n const stackEntry = stack.splice(index, 1)[0]\n\n await stackEntry.activity.onPause()\n stackEntry.activity.lifecycle = ActivityLifecycle.Paused\n await stackEntry.activity.onStop()\n stackEntry.activity.lifecycle = ActivityLifecycle.Stopped\n await stackEntry.activity.onDestroy()\n stackEntry.activity.lifecycle = ActivityLifecycle.Destroyed\n\n // Clean up resources to prevent memory leaks\n this.cleanupActivity(stackEntry.activity)\n\n this.resolveActivityResult(stackEntry.activity, stackEntry.intent)\n\n // Resume the previous activity\n await this.bringLastActivityToFront()\n } else {\n if (activity.lifecycle === ActivityLifecycle.Created) {\n await activity.onStop()\n activity.lifecycle = ActivityLifecycle.Stopped\n }\n await activity.onDestroy()\n activity.lifecycle = ActivityLifecycle.Destroyed\n\n this.resolveActivityResult(activity, { action: '' })\n\n // This can happen when an activity finishes in one of the callback methods,\n // before it is added to the stack. In that case, we bring the last activity back to the front.\n await this.bringLastActivityToFront()\n }\n this.#parent.requestUpdate()\n }\n\n private resolveActivityResult(activity: Activity, originalIntent: Intent): void {\n const resolver = this.resultResolvers.get(originalIntent)\n // The activity might have not been started with startActivityForResult.\n // A thing to consider for the future is whether we should throw an error in a case where\n // the activity was started for result but the resolver was not found.\n if (resolver) {\n this.resultResolvers.delete(originalIntent)\n // We construct the result intent.\n // Ideally we would like to preserve the original intent structure but with new data.\n const resultIntent: ResolvedIntent = {\n ...originalIntent,\n data: activity.getResult(),\n result: activity.resultCode,\n }\n resolver(resultIntent)\n }\n }\n\n private async bringLastActivityToFront(): Promise<void> {\n if (this.modalActivityStack.length > 0) {\n const previousEntry = this.modalActivityStack[this.activityStack.length - 1]\n await this.updateCurrentActivity(previousEntry.activity, false, previousEntry.intent)\n } else if (this.activityStack.length > 0) {\n const previousEntry = this.activityStack[this.activityStack.length - 1]\n await this.updateCurrentActivity(previousEntry.activity, false, previousEntry.intent)\n } else {\n this.currentActivity = undefined // No more activities\n }\n }\n\n getTopActivity(): Activity | undefined {\n const topModal = this.modalActivityStack.findLast((a) => a.activity.lifecycle === ActivityLifecycle.Resumed)\n if (topModal) {\n return topModal.activity\n }\n const top = this.activityStack.findLast((a) => a.activity.lifecycle === ActivityLifecycle.Resumed)\n return top ? top.activity : undefined\n }\n\n getCurrentActivity(): Activity | undefined {\n return this.currentActivity\n }\n\n /**\n * Sets the styles for the current activity.\n * This method adds or removes CSS classes based on the activity's class name\n * and action, allowing for dynamic styling based on the active activity.\n * @param activity The activity to set styles for.\n * If not provided, it will not set any styles.\n * If the activity is the same as the current one, it does nothing.\n */\n setupStyles(activity?: Activity, oldActivity?: Activity): void {\n if (activity === oldActivity) {\n return\n }\n const root = document?.documentElement\n if (!root) {\n return\n }\n if (oldActivity) {\n const ctor = oldActivity.constructor as typeof Activity\n root.classList.remove(ctor.name.toLowerCase())\n if (ctor.action) {\n root.classList.remove(ctor.action.replace(/\\//g, '-'))\n }\n }\n if (activity) {\n const ctor = activity.constructor as typeof Activity\n root.classList.add(ctor.name.toLowerCase())\n if (ctor.action) {\n root.classList.add(ctor.action.replace(/\\//g, '-'))\n }\n }\n }\n\n /**\n * A helper method to handle the transition between activities, ensuring\n * lifecycle methods are called in the correct order (pause the previous activity,\n * then start/resume the new one). This centralizes lifecycle management.\n *\n * @param activity The activity to bring to the foreground.\n */\n private async updateCurrentActivity(activity: Activity, isModal: boolean, intent?: Intent): Promise<void> {\n this.setupStyles(activity, this.currentActivity)\n if (\n this.currentActivity &&\n this.currentActivity !== activity &&\n this.currentActivity.lifecycle !== ActivityLifecycle.Destroyed &&\n // Make sure we don't pause the current activity if it's already paused.\n this.currentActivity.lifecycle !== ActivityLifecycle.Paused\n ) {\n await this.currentActivity.onPause()\n this.currentActivity.lifecycle = ActivityLifecycle.Paused\n }\n switch (activity.lifecycle) {\n case ActivityLifecycle.Paused:\n if (!(await this.transitionStartedToResumed(activity))) {\n return\n }\n break\n\n case ActivityLifecycle.Stopped:\n await this.safeExecuteLifecycleMethod(() => activity.onRestart(), activity, 'onRestart')\n activity.lifecycle = ActivityLifecycle.Resumed\n break\n\n case ActivityLifecycle.Destroyed:\n throw new Error(`Invalid state. The activity is already destroyed.`)\n\n case ActivityLifecycle.Created:\n if (!(await this.transitionCreatedToResumed(activity))) {\n return\n }\n break\n\n case ActivityLifecycle.Started:\n if (!(await this.transitionStartedToResumed(activity))) {\n return\n }\n break\n\n case ActivityLifecycle.Initialized:\n if (!(await this.transitionInitializedToResumed(activity, intent))) {\n return\n }\n break\n }\n if (!isModal) {\n // With a modal activity, it renders directly to the `<body>` and renders outside\n // of the normal rendering flow. We keep the previous activity rendered.\n this.currentActivity = activity\n }\n }\n\n /**\n * Safely executes an async lifecycle method with error handling.\n * @param lifecycleMethod The lifecycle method to execute.\n * @param activity The activity instance.\n * @param methodName The name of the method for error reporting.\n * @returns Promise that resolves when the method completes or rejects with wrapped error.\n */\n private async safeExecuteLifecycleMethod(\n lifecycleMethod: () => void | Promise<void>,\n activity: Activity,\n methodName: string\n ): Promise<void> {\n try {\n await lifecycleMethod()\n } catch (error) {\n const activityName = activity.constructor.name\n const wrappedError = new Error(\n `Error in ${activityName}.${methodName}(): ${error instanceof Error ? error.message : String(error)}`\n )\n wrappedError.cause = error\n // Allow the activity to handle its own errors, but still propagate\n this.#parent.dispatchEvent(\n new CustomEvent('activity-lifecycle-error', {\n detail: { activity, methodName, error: wrappedError },\n })\n )\n throw wrappedError\n }\n }\n\n /**\n * Allows navigating back through the activity stack.\n * Call `ActivityManager.navigateBack()` when the user performs a back action\n * (e.g., clicks a back button).\n * @returns Promise that resolves to true if navigation was successful, false if at root.\n */\n async navigateBack(): Promise<boolean> {\n // Handle modal activities first\n if (this.modalActivityStack.length > 0) {\n const topModal = this.modalActivityStack[this.modalActivityStack.length - 1]\n await this.finishActivity(topModal.activity)\n return true\n }\n\n // Handle regular activities\n if (this.activityStack.length > 1 && this.currentActivity) {\n await this.finishActivity(this.currentActivity)\n return true\n }\n\n // At root, cannot navigate back\n return false\n }\n\n /**\n * Navigates to a specific activity in the stack, clearing activities above it.\n * @param action The action of the activity to navigate to.\n * @returns Promise that resolves to true if navigation was successful.\n */\n async navigateToActivity(action: string): Promise<boolean> {\n const index = this.activityStack.findIndex((entry) => entry.action === action)\n if (index === -1) {\n return false\n }\n\n // Finish all activities above the target\n const activitiesToFinish = this.activityStack.slice(index + 1)\n for (const entry of activitiesToFinish) {\n await this.finishActivity(entry.activity)\n }\n\n // Bring the target activity to the front\n const targetEntry = this.activityStack[index]\n await this.updateCurrentActivity(targetEntry.activity, false, targetEntry.intent)\n return true\n }\n\n /**\n * Clears the entire activity stack and starts a new root activity.\n * @param intent The intent for the new root activity.\n */\n async clearStackAndStart(intent: Intent): Promise<void> {\n // Finish all activities\n const allActivities = [...this.activityStack, ...this.modalActivityStack]\n for (const entry of allActivities) {\n if (entry.activity.lifecycle !== ActivityLifecycle.Destroyed) {\n await this.finishActivity(entry.activity)\n }\n }\n\n // Clear stacks\n this.activityStack.length = 0\n this.modalActivityStack.length = 0\n this.currentActivity = undefined\n\n // Start new root activity\n await this.startActivity(intent)\n }\n\n /**\n * Creates an intent with better type safety and validation.\n * @param action The action name.\n * @param data Optional intent data.\n * @param options Optional intent configuration.\n * @returns A properly formed intent.\n */\n createIntent<T = unknown>(\n action: string,\n data?: T,\n options: {\n category?: string[]\n flags?: number\n requestCode?: number\n } = {}\n ): Intent<T> {\n if (!this.isActionRegistered(action)) {\n throw new Error(`Cannot create intent for unregistered action: ${action}`)\n }\n\n return {\n action,\n data,\n ...options,\n }\n }\n\n createRequestCode(): number {\n const min = 1000\n const max = 9999\n return Math.floor(Math.random() * (max - min) + min)\n }\n\n findActiveActivity(action: string): Activity | undefined {\n return this.activityStack.find((entry) => entry.action === action)?.activity\n }\n\n /**\n * Transitions an activity from Created to Resumed state.\n * @param activity The activity to transition.\n * @returns true if successful, false if activity was destroyed during transition.\n */\n private async transitionCreatedToResumed(activity: Activity): Promise<boolean> {\n await this.safeExecuteLifecycleMethod(() => activity.onStart(), activity, 'onStart')\n if (this.isDestroyed(activity)) {\n return false\n }\n activity.lifecycle = ActivityLifecycle.Started\n\n await this.safeExecuteLifecycleMethod(() => activity.onResume(), activity, 'onResume')\n if (this.isDestroyed(activity)) {\n return false\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n return true\n }\n\n /**\n * Transitions an activity from Started to Resumed state.\n * @param activity The activity to transition.\n * @returns true if successful, false if activity was destroyed during transition.\n */\n private async transitionStartedToResumed(activity: Activity): Promise<boolean> {\n await this.safeExecuteLifecycleMethod(() => activity.onResume(), activity, 'onResume')\n if (this.isDestroyed(activity)) {\n return false\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n return true\n }\n\n /**\n * Transitions an activity from Initialized to Resumed state.\n * @param activity The activity to transition.\n * @param intent The intent used to create the activity.\n * @returns true if successful, false if activity was destroyed during transition.\n */\n private async transitionInitializedToResumed(activity: Activity, intent?: Intent): Promise<boolean> {\n await this.safeExecuteLifecycleMethod(() => activity.onCreate(intent), activity, 'onCreate')\n activity.lifecycle = ActivityLifecycle.Created\n if (this.isDestroyed(activity)) {\n return false\n }\n\n return await this.transitionCreatedToResumed(activity)\n }\n\n /**\n * Cleans up resources for destroyed activities to prevent memory leaks.\n * @param activity The activity to clean up.\n */\n private cleanupActivity(activity: Activity): void {\n // Remove any event listeners that might create memory leaks\n // This changes the entire prototype chain of the activity,\n // effectively making it a new object. We can't do that as the activity will loose some\n // of its properties, so we don't do it for now.\n // if (activity instanceof EventTarget) {\n // // Clear all event listeners by replacing the activity with a new EventTarget\n // // This is a defensive approach since we can't enumerate listeners\n // Object.setPrototypeOf(activity, EventTarget.prototype)\n // }\n\n // Clear any references that might prevent garbage collection\n activity.renderRoot = undefined\n }\n\n /**\n * Validates that an activity stack is in a consistent state.\n * @param stack The activity stack to validate.\n * @returns Array of validation errors, empty if valid.\n */\n private validateStackConsistency(stack: ActivityStackEntry[]): string[] {\n const errors: string[] = []\n const seenIds = new Set<string>()\n\n for (const entry of stack) {\n if (seenIds.has(entry.id)) {\n errors.push(`Duplicate activity ID found: ${entry.id}`)\n }\n seenIds.add(entry.id)\n\n if (!entry.activity || !entry.id || !entry.action) {\n errors.push(`Invalid stack entry: missing required properties`)\n }\n\n if (entry.activity.lifecycle === ActivityLifecycle.Destroyed) {\n errors.push(`Destroyed activity found in stack: ${entry.id}`)\n }\n }\n\n return errors\n }\n\n /**\n * Gets diagnostic information about the current state of the activity manager.\n * Useful for debugging and monitoring.\n * @returns Object containing current state information.\n */\n getDiagnostics(): {\n totalActivities: number\n modalActivities: number\n currentActivity?: string\n topActivity?: string\n stackValidation: string[]\n modalStackValidation: string[]\n } {\n return {\n totalActivities: this.activityStack.length,\n modalActivities: this.modalActivityStack.length,\n currentActivity: this.currentActivity?.constructor.name,\n topActivity: this.getTopActivity()?.constructor.name,\n stackValidation: this.validateStackConsistency(this.activityStack),\n modalStackValidation: this.validateStackConsistency(this.modalActivityStack),\n }\n }\n\n /**\n * Gets all registered activity actions.\n * @returns Array of registered action names.\n */\n getRegisteredActions(): string[] {\n return Array.from(this.activityClasses.keys())\n }\n\n /**\n * Checks if an action is registered.\n * @param action The action to check.\n * @returns true if the action is registered, false otherwise.\n */\n isActionRegistered(action: string): boolean {\n return this.activityClasses.has(action)\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { Activity } from './Activity.js';
|
|
|
3
3
|
import { FragmentState, type FragmentOptions, FragmentManager } from './FragmentManager.js';
|
|
4
4
|
import type { Application, UpdateRequest } from './Application.js';
|
|
5
5
|
import { FragmentRenderer } from './renderer/FragmentRenderer.js';
|
|
6
|
-
import { Intent } from './ActivityManager.js';
|
|
6
|
+
import { Intent, ResolvedIntent } from './ActivityManager.js';
|
|
7
7
|
import type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js';
|
|
8
8
|
import { type RefOrCallback } from 'lit/directives/ref.js';
|
|
9
9
|
/**
|
|
@@ -141,9 +141,19 @@ export declare class Fragment extends EventTarget {
|
|
|
141
141
|
getActivity(): Activity | undefined;
|
|
142
142
|
/**
|
|
143
143
|
* Starts an activity for result.
|
|
144
|
+
* @template T The type of the result data expected.
|
|
144
145
|
* @param intent The intent to start.
|
|
146
|
+
* @returns A promise that resolves when the started activity finishes, returning the result Intent with
|
|
147
|
+
* data of type T.
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const resultIntent = await this.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
|
|
151
|
+
* if (resultIntent.resultCode === IntentResult.RESULT_OK) {
|
|
152
|
+
* console.log(resultIntent.data?.userId);
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
145
155
|
*/
|
|
146
|
-
startActivityForResult(intent: Intent): Promise<
|
|
156
|
+
startActivityForResult<T>(intent: Intent): Promise<ResolvedIntent<T | undefined>>;
|
|
147
157
|
/**
|
|
148
158
|
* Starts another activity.
|
|
149
159
|
* @param intent The intent to start.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fragment.d.ts","sourceRoot":"","sources":["../../../src/core/Fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Fragment.d.ts","sourceRoot":"","sources":["../../../src/core/Fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,KAAK,E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AAC,IAAI,CAAC;IAgBrG;;;;OAIG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,YAAY,CAAC,EAAE,WAAW,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9G;;;OAGG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAe/D"}
|
|
@@ -2,7 +2,6 @@ import { __esDecorate, __runInitializers } from "tslib";
|
|
|
2
2
|
import { nothing } from 'lit';
|
|
3
3
|
import { FragmentState, FragmentManager } from './FragmentManager.js';
|
|
4
4
|
import { FragmentRenderer } from './renderer/FragmentRenderer.js';
|
|
5
|
-
import { IntentResult } from './ActivityManager.js';
|
|
6
5
|
import { bound } from '../decorators/bound.js';
|
|
7
6
|
import { EventTypes } from '../events/EventTypes.js';
|
|
8
7
|
/**
|
|
@@ -230,7 +229,17 @@ let Fragment = (() => {
|
|
|
230
229
|
}
|
|
231
230
|
/**
|
|
232
231
|
* Starts an activity for result.
|
|
232
|
+
* @template T The type of the result data expected.
|
|
233
233
|
* @param intent The intent to start.
|
|
234
|
+
* @returns A promise that resolves when the started activity finishes, returning the result Intent with
|
|
235
|
+
* data of type T.
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const resultIntent = await this.startActivityForResult<{ userId: string }>({ action: 'pickUser' });
|
|
239
|
+
* if (resultIntent.resultCode === IntentResult.RESULT_OK) {
|
|
240
|
+
* console.log(resultIntent.data?.userId);
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
234
243
|
*/
|
|
235
244
|
async startActivityForResult(intent) {
|
|
236
245
|
const activity = this.getActivity();
|
|
@@ -273,7 +282,7 @@ let Fragment = (() => {
|
|
|
273
282
|
if (event.type === EventTypes.Intent.startActivityForResult) {
|
|
274
283
|
const info = event.detail;
|
|
275
284
|
const result = await this.startActivityForResult(info.intent);
|
|
276
|
-
info.onResult(
|
|
285
|
+
info.onResult(result.result, result);
|
|
277
286
|
}
|
|
278
287
|
else if (event.type === EventTypes.Intent.startActivity) {
|
|
279
288
|
await activity.startActivity(event.detail.intent);
|