@api-client/ui 0.1.6 → 0.1.8
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/.vscode/settings.json +1 -0
- package/build/src/core/Activity.d.ts +2 -2
- package/build/src/core/Activity.d.ts.map +1 -1
- package/build/src/core/Activity.js +2 -2
- package/build/src/core/Activity.js.map +1 -1
- package/build/src/core/ActivityManager.d.ts +29 -1
- package/build/src/core/ActivityManager.d.ts.map +1 -1
- package/build/src/core/ActivityManager.js +69 -45
- package/build/src/core/ActivityManager.js.map +1 -1
- package/build/src/core/Application.d.ts.map +1 -1
- package/build/src/core/Application.js +2 -2
- package/build/src/core/Application.js.map +1 -1
- package/build/src/core/ModalActivity.js +1 -1
- package/build/src/core/ModalActivity.js.map +1 -1
- package/build/src/reactive/reactive.d.ts.map +1 -1
- package/build/src/reactive/reactive.js +43 -1
- package/build/src/reactive/reactive.js.map +1 -1
- package/demo/elements/md/notification/snack.html +1 -1
- package/demo/elements/user/user-avatar.ts +4 -0
- package/eslint.config.js +3 -0
- package/package.json +1 -1
- package/src/core/Activity.ts +2 -2
- package/src/core/ActivityManager.ts +60 -36
- package/src/core/Application.ts +2 -2
- package/src/core/ModalActivity.ts +1 -1
- package/src/reactive/reactive.ts +43 -1
- package/test/core/activity.spec.ts +2 -2
- package/test/core/activity_manager.spec.ts +25 -25
- package/test/core/application.spec.ts +3 -3
- package/test/core/fragment.spec.ts +2 -2
- package/test/core/live_data.spec.ts +33 -3
- package/test/elements/data-table/DataTable.browser.test.ts +0 -3
package/.vscode/settings.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nothing, TemplateResult } from 'lit';
|
|
2
|
-
import {
|
|
2
|
+
import { ActivityLifecycle, IntentResult, type Intent } 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';
|
|
@@ -31,7 +31,7 @@ export declare class Activity extends EventTarget {
|
|
|
31
31
|
* This way other activities/fragments can use it to call the activity.
|
|
32
32
|
*/
|
|
33
33
|
static action?: string;
|
|
34
|
-
|
|
34
|
+
lifecycle: ActivityLifecycle;
|
|
35
35
|
protected parent: Application;
|
|
36
36
|
/**
|
|
37
37
|
* The fragment manager that manages fragments in this activity.
|
|
@@ -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,
|
|
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;AACnF,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;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAS,SAAQ,WAAW;IACvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,WAAW,CAAA;IACxB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,SAAS,EAAE,iBAAiB,CAAgC;IACnE,SAAS,CAAC,MAAM,EAAE,WAAW,CAAA;IAC7B;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,eAAe,CAAA;IAClC,SAAS,CAAC,UAAU,CAAC,EAAE,OAAO,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AO,CAAC,IAAI,CAAC;IAI5D,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9C;;;OAGG;IACH,cAAc,IAAI,WAAW;IAI7B;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C;;;;OAIG;IACG,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ7D;;;OAGG;IACH,SAAS,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAKzD;;;;;;;;;;;;OAYG;IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBpG,WAAW,IAAI,QAAQ;IAIvB;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIrC,SAAS,IAAI,OAAO,GAAG,SAAS;IAIhC;;;;;;;;;;;;;;OAcG;IAEG,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc,GAAG,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAUtG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
import { nothing } from 'lit';
|
|
4
|
-
import {
|
|
4
|
+
import { ActivityLifecycle, IntentResult } from './ActivityManager.js';
|
|
5
5
|
import { FragmentManager } from './FragmentManager.js';
|
|
6
6
|
import { bound } from '../decorators/bound.js';
|
|
7
7
|
import { EventTypes } from '../events/EventTypes.js';
|
|
@@ -42,7 +42,7 @@ let Activity = (() => {
|
|
|
42
42
|
* This way other activities/fragments can use it to call the activity.
|
|
43
43
|
*/
|
|
44
44
|
static action;
|
|
45
|
-
|
|
45
|
+
lifecycle = ActivityLifecycle.Initialized;
|
|
46
46
|
parent;
|
|
47
47
|
/**
|
|
48
48
|
* The fragment manager that manages fragments in this activity.
|
|
@@ -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,aAAa,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAA;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD;;;;;;;;;;;;;GAaG;IACU,QAAQ;sBAAS,WAAW;;;iBAA5B,QAAS,SAAQ,WAAW;;;6CAuStC,KAAK;YACN,sMAAM,iBAAiB,6DAStB;;;QAhTD;;;;WAIG;QACH,UAAU,GANC,mDAAQ,CAMK;QACxB;;;;WAIG;QACH,MAAM,CAAC,MAAM,CAAS;QAEf,KAAK,GAAkB,aAAa,CAAC,WAAW,CAAA;QAC7C,MAAM,CAAa;QAC7B;;WAEG;QACO,OAAO,CAAiB;QACxB,UAAU,CAAU;QAEpB,QAAQ,GAAG,YAAY,CAAC,eAAe,CAAA;QAEjD,IAAI,UAAU;YACZ,OAAO,IAAI,CAAC,QAAQ,CAAA;QACtB,CAAC;QAED;;;;WAIG;QACO,mBAAmB,GAAa,EAAE,CAAA;QAE5C,YAAY,MAAmB;YAC7B,KAAK,EAAE,CAAA;YACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;YACpB,IAAI,CAAC,OAAO,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAA;QAC1C,CAAC;QAED;;;;;;;;;WASG;QACH,QAAQ,CAAC,MAAe;YACtB,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC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AAI,CAAC,CAAA;QAChD,CAAC;QAED,SAAS;YACP,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QAED;;;;;;;;;;;;;;WAcG;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,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAChD,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;;;SAjTU,QAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { nothing, TemplateResult } from 'lit'\nimport { ActivityState, 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\n/**\n * `Activity` is a crucial component of your app. An application sends an intent\n * to bring the activity. If it's found, the activity gets to the foreground and start its activity.\n *\n * **Lifecycle**\n *\n * - `onCreated()` - fires when the system first creates the activity.\n * - `onStart()` - the activity becomes visible to the user as the app prepares for\n * the activity to enter the foreground and become interactive.\n * - `onResume()` - the state in which the app interacts with the user.\n * - `onPause()` - the first indication that the user is leaving your activity.\n * - `onStop()` - your activity is no longer visible to the user.\n * - `onDestroy()`- is called before the activity is destroyed\n */\nexport class Activity extends EventTarget {\n /**\n * To be set by an activity to replace the default render root.\n * This is particularly useful when the activity is a modal dialog\n * and the content should be rendered outside the application's render root.\n */\n renderRoot?: HTMLElement\n /**\n * An activity can define its action name that does not change.\n * It then should be used as the activity registration key.\n * This way other activities/fragments can use it to call the activity.\n */\n static action?: string\n\n public state: ActivityState = ActivityState.Initialized\n protected parent: Application\n /**\n * The fragment manager that manages fragments in this activity.\n */\n protected manager: FragmentManager\n protected resultData?: unknown\n\n protected exitCode = IntentResult.RESULT_CANCELED\n\n get resultCode(): IntentResult {\n return this.exitCode\n }\n\n /**\n * When starting an new activity for result, we add the request code here\n * so that the manager can track which activity originally called the\n * activity for result.\n */\n protected pendingRequestCodes: number[] = []\n\n constructor(parent: Application) {\n super()\n this.parent = parent\n this.manager = new FragmentManager(this)\n }\n\n /**\n * Called when the activity is starting. This is where most initialization should go.\n * You can call `finish()` from within this function, in which case `onDestroy()` will be\n * immediately called after `onCreate()` without any of the rest of the activity lifecycle\n * (`onStart()`, `onResume()`, `onPause()`, etc) executing.\n *\n * In the `onCreate()` method, perform basic activity startup logic that happens only once\n * for the entire life of the activity.\n * @param intent Optional intent data.\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.\n * As `onCreate()` exits, the activity enters the `Started` state, and the activity becomes visible\n * to the user. This callback contains what amounts to the activity’s final preparations for coming\n * to the foreground and becoming interactive.\n *\n * Called after `onCreate()`. It will usually be followed by onResume().\n * This is a good place to begin running animations, etc.\n * You can call `finish()` from within this function, in which case `onStop()` will be\n * immediately called after `onStart()` without the lifecycle transitions\n * in-between (`onResume()`, `onPause()`, etc) executing.\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.\n * Called after the `onPause()`. This is usually a hint for your activity to start interacting\n * with the user, which is a good indicator that the activity became active and ready to receive input.\n * This sometimes could also be a transit state toward another resting state.\n * For instance, an activity may be relaunched to `onPause()` due to configuration changes and\n * the activity was visible, but wasn't the top-most activity of an activity task.\n * The `render()` function is always called after this callback.\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.\n * Called as part of the activity lifecycle when the user no longer actively interacts with the activity,\n * but it is still visible on screen. The counterpart to `onResume()`.\n *\n * When activity B is launched in front of activity A, this callback will be invoked on A.\n * B will not be created until A's `onPause()` returns, so be sure to not do anything lengthy here.\n *\n * This callback is mostly used for saving any persistent state the activity is editing,\n * to present a \"edit in place\" model to the user and making sure nothing is lost if there are\n * not enough resources to start the new activity without first killing this one.\n * This is also a good place to stop things that consume a noticeable amount of CPU in order\n * to make the switch to the next activity as fast as possible.\n */\n onPause(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:pause', { detail: null }))\n }\n\n /**\n * Called when you are no longer visible to the user.\n * You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity.\n * This is a good place to stop refreshing UI, running animations and other visual things.\n */\n onStop(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:stop', { detail: null }))\n }\n\n onRestart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:restart', { detail: null }))\n }\n\n /**\n * Perform any final cleanup before an activity is destroyed.\n * This can happen because the activity is finishing (someone called finish() on it).\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\n * @param intent New intent data.\n */\n onNewIntent(intent: Intent): void | Promise<void> {\n //\n }\n\n /**\n * Called by the renderer when the activity is rendered for the first time.\n */\n onFirstRender(): void {\n //\n }\n\n /**\n * A function called when it should render the view.\n */\n render(): TemplateResult | typeof nothing {\n return nothing\n }\n\n /**\n * Finishes the activity.\n */\n async finish(): Promise<void> {\n await this.getApplication().manager.finishActivity(this)\n }\n\n /**\n * When the activity changes its state it should call the\n * `requestUpdate()` method to inform the parent application to\n * perform the render operation.\n * The function dispatches the `activity:update` custom event\n * that is handled by the parent application.\n *\n * Note, the application may choose to not call the render procedure\n * (for example, when the activity is not visible). The rendering\n * function is asynchronous. The only way to know the activity is being rendered,\n * is when the `render()` method if called.\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.\n * @param key The name of the fragment\n * @param fragment The fragment to register.\n */\n async addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void> {\n await this.manager.attachFragment(key, fragment, this, data)\n }\n\n async showFragment(key: string, root?: HTMLElement): Promise<void> {\n await this.manager.showFragment(key, root)\n }\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 * Unifies Fragment and Activity interfaces.\n * @returns `this`\n */\n getApplication(): Application {\n return this.parent\n }\n\n /**\n * A shortcut to the `manager` function.\n * @param intent The intent to start\n */\n startActivity(intent: Intent): Promise<void> {\n return this.parent.manager.startActivity(intent)\n }\n\n /**\n * Starts a new activity for a result.\n * @param intent The intent that created this activity.\n * @returns The request code created with this call.\n */\n async startActivityForResult(intent: Intent): Promise<number> {\n const { manager } = this.getApplication()\n const code = manager.createRequestCode()\n this.pendingRequestCodes.push(code)\n await manager.startActivityForResult(intent, code)\n return code\n }\n\n /**\n * Call this method to return data to the activity that started this activity.\n * @param data The data to return.\n */\n setResult(resultCode: IntentResult, data?: unknown): void {\n this.exitCode = resultCode\n this.resultData = data\n }\n\n /**\n * Called when an activity you launched exits, giving you the `requestCode` you started it with,\n * the `resultCode` it returned, and any additional data from it. The `resultCode` will be `RESULT_CANCELED`\n * if the activity explicitly returned that, didn't return any result, or crashed during its operation.\n *\n * An activity can never receive a result in the resumed state. You can count on `onResume()` being called\n * after this method, though not necessarily immediately after. If the activity was resumed,\n * it will be paused and the result will be delivered, followed by `onResume()`.\n *\n * @param requestCode The request code passed to startActivityForResult.\n * @param data The result from the activity.\n * @param intent The intent that was used to start the activity.\n */\n async onActivityResult(requestCode: number, resultCode: IntentResult, intent: Intent): Promise<void> {\n const index = this.pendingRequestCodes.indexOf(requestCode)\n if (index !== -1) {\n this.pendingRequestCodes.splice(index, 1)\n }\n // First we check whether any of the fragments has the code.\n const fragment = this.manager.findByRequestCode(requestCode)\n if (fragment) {\n return fragment.onActivityResult(requestCode, resultCode, intent)\n }\n if (this.constructor === Activity) {\n // eslint-disable-next-line no-console\n console.info(\n `Activity#onActivityResult not implemented. Request code: ${requestCode}, result code: ${resultCode}`,\n intent\n )\n }\n }\n\n getActivity(): Activity {\n return this\n }\n\n /**\n * Checks whether this activity initiated the activity for result.\n * @param code The request code to look for.\n * @returns `true` if the activity has the request code.\n */\n hasRequestCode(code: number): boolean {\n return this.pendingRequestCodes.includes(code)\n }\n\n getResult(): unknown | undefined {\n return this.resultData\n }\n\n /**\n * A handler for the intent event dispatched by web components hosted by this activity.\n *\n * **Usage example:**\n *\n * ```ts\n * <custom-element @startactivity=\"${this.handleIntentEvent}\"></custom-element>\n * <custom-element @startactivityforresult=\"${this.handleIntentEvent}\"></custom-element>\n * ```\n *\n * @param event The event that was dispatched.\n * @returns A promise that resolves when the intent is handled.\n * @throws An error if the activity has no activity.\n * @throws An 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 await this.startActivityForResult(info.intent)\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/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C,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC;gBAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAkC,CAAA;gBACrD,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAChD,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;;;SAjTU,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\n/**\n * `Activity` is a crucial component of your app. An application sends an intent\n * to bring the activity. If it's found, the activity gets to the foreground and start its activity.\n *\n * **Lifecycle**\n *\n * - `onCreated()` - fires when the system first creates the activity.\n * - `onStart()` - the activity becomes visible to the user as the app prepares for\n * the activity to enter the foreground and become interactive.\n * - `onResume()` - the state in which the app interacts with the user.\n * - `onPause()` - the first indication that the user is leaving your activity.\n * - `onStop()` - your activity is no longer visible to the user.\n * - `onDestroy()`- is called before the activity is destroyed\n */\nexport class Activity extends EventTarget {\n /**\n * To be set by an activity to replace the default render root.\n * This is particularly useful when the activity is a modal dialog\n * and the content should be rendered outside the application's render root.\n */\n renderRoot?: HTMLElement\n /**\n * An activity can define its action name that does not change.\n * It then should be used as the activity registration key.\n * This way other activities/fragments can use it to call the activity.\n */\n static action?: string\n\n public lifecycle: ActivityLifecycle = ActivityLifecycle.Initialized\n protected parent: Application\n /**\n * The fragment manager that manages fragments in this activity.\n */\n protected manager: FragmentManager\n protected resultData?: unknown\n\n protected exitCode = IntentResult.RESULT_CANCELED\n\n get resultCode(): IntentResult {\n return this.exitCode\n }\n\n /**\n * When starting an new activity for result, we add the request code here\n * so that the manager can track which activity originally called the\n * activity for result.\n */\n protected pendingRequestCodes: number[] = []\n\n constructor(parent: Application) {\n super()\n this.parent = parent\n this.manager = new FragmentManager(this)\n }\n\n /**\n * Called when the activity is starting. This is where most initialization should go.\n * You can call `finish()` from within this function, in which case `onDestroy()` will be\n * immediately called after `onCreate()` without any of the rest of the activity lifecycle\n * (`onStart()`, `onResume()`, `onPause()`, etc) executing.\n *\n * In the `onCreate()` method, perform basic activity startup logic that happens only once\n * for the entire life of the activity.\n * @param intent Optional intent data.\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.\n * As `onCreate()` exits, the activity enters the `Started` state, and the activity becomes visible\n * to the user. This callback contains what amounts to the activity’s final preparations for coming\n * to the foreground and becoming interactive.\n *\n * Called after `onCreate()`. It will usually be followed by onResume().\n * This is a good place to begin running animations, etc.\n * You can call `finish()` from within this function, in which case `onStop()` will be\n * immediately called after `onStart()` without the lifecycle transitions\n * in-between (`onResume()`, `onPause()`, etc) executing.\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.\n * Called after the `onPause()`. This is usually a hint for your activity to start interacting\n * with the user, which is a good indicator that the activity became active and ready to receive input.\n * This sometimes could also be a transit state toward another resting state.\n * For instance, an activity may be relaunched to `onPause()` due to configuration changes and\n * the activity was visible, but wasn't the top-most activity of an activity task.\n * The `render()` function is always called after this callback.\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.\n * Called as part of the activity lifecycle when the user no longer actively interacts with the activity,\n * but it is still visible on screen. The counterpart to `onResume()`.\n *\n * When activity B is launched in front of activity A, this callback will be invoked on A.\n * B will not be created until A's `onPause()` returns, so be sure to not do anything lengthy here.\n *\n * This callback is mostly used for saving any persistent state the activity is editing,\n * to present a \"edit in place\" model to the user and making sure nothing is lost if there are\n * not enough resources to start the new activity without first killing this one.\n * This is also a good place to stop things that consume a noticeable amount of CPU in order\n * to make the switch to the next activity as fast as possible.\n */\n onPause(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:pause', { detail: null }))\n }\n\n /**\n * Called when you are no longer visible to the user.\n * You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity.\n * This is a good place to stop refreshing UI, running animations and other visual things.\n */\n onStop(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:stop', { detail: null }))\n }\n\n onRestart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:restart', { detail: null }))\n }\n\n /**\n * Perform any final cleanup before an activity is destroyed.\n * This can happen because the activity is finishing (someone called finish() on it).\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\n * @param intent New intent data.\n */\n onNewIntent(intent: Intent): void | Promise<void> {\n //\n }\n\n /**\n * Called by the renderer when the activity is rendered for the first time.\n */\n onFirstRender(): void {\n //\n }\n\n /**\n * A function called when it should render the view.\n */\n render(): TemplateResult | typeof nothing {\n return nothing\n }\n\n /**\n * Finishes the activity.\n */\n async finish(): Promise<void> {\n await this.getApplication().manager.finishActivity(this)\n }\n\n /**\n * When the activity changes its state it should call the\n * `requestUpdate()` method to inform the parent application to\n * perform the render operation.\n * The function dispatches the `activity:update` custom event\n * that is handled by the parent application.\n *\n * Note, the application may choose to not call the render procedure\n * (for example, when the activity is not visible). The rendering\n * function is asynchronous. The only way to know the activity is being rendered,\n * is when the `render()` method if called.\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.\n * @param key The name of the fragment\n * @param fragment The fragment to register.\n */\n async addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void> {\n await this.manager.attachFragment(key, fragment, this, data)\n }\n\n async showFragment(key: string, root?: HTMLElement): Promise<void> {\n await this.manager.showFragment(key, root)\n }\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 * Unifies Fragment and Activity interfaces.\n * @returns `this`\n */\n getApplication(): Application {\n return this.parent\n }\n\n /**\n * A shortcut to the `manager` function.\n * @param intent The intent to start\n */\n startActivity(intent: Intent): Promise<void> {\n return this.parent.manager.startActivity(intent)\n }\n\n /**\n * Starts a new activity for a result.\n * @param intent The intent that created this activity.\n * @returns The request code created with this call.\n */\n async startActivityForResult(intent: Intent): Promise<number> {\n const { manager } = this.getApplication()\n const code = manager.createRequestCode()\n this.pendingRequestCodes.push(code)\n await manager.startActivityForResult(intent, code)\n return code\n }\n\n /**\n * Call this method to return data to the activity that started this activity.\n * @param data The data to return.\n */\n setResult(resultCode: IntentResult, data?: unknown): void {\n this.exitCode = resultCode\n this.resultData = data\n }\n\n /**\n * Called when an activity you launched exits, giving you the `requestCode` you started it with,\n * the `resultCode` it returned, and any additional data from it. The `resultCode` will be `RESULT_CANCELED`\n * if the activity explicitly returned that, didn't return any result, or crashed during its operation.\n *\n * An activity can never receive a result in the resumed state. You can count on `onResume()` being called\n * after this method, though not necessarily immediately after. If the activity was resumed,\n * it will be paused and the result will be delivered, followed by `onResume()`.\n *\n * @param requestCode The request code passed to startActivityForResult.\n * @param data The result from the activity.\n * @param intent The intent that was used to start the activity.\n */\n async onActivityResult(requestCode: number, resultCode: IntentResult, intent: Intent): Promise<void> {\n const index = this.pendingRequestCodes.indexOf(requestCode)\n if (index !== -1) {\n this.pendingRequestCodes.splice(index, 1)\n }\n // First we check whether any of the fragments has the code.\n const fragment = this.manager.findByRequestCode(requestCode)\n if (fragment) {\n return fragment.onActivityResult(requestCode, resultCode, intent)\n }\n if (this.constructor === Activity) {\n // eslint-disable-next-line no-console\n console.info(\n `Activity#onActivityResult not implemented. Request code: ${requestCode}, result code: ${resultCode}`,\n intent\n )\n }\n }\n\n getActivity(): Activity {\n return this\n }\n\n /**\n * Checks whether this activity initiated the activity for result.\n * @param code The request code to look for.\n * @returns `true` if the activity has the request code.\n */\n hasRequestCode(code: number): boolean {\n return this.pendingRequestCodes.includes(code)\n }\n\n getResult(): unknown | undefined {\n return this.resultData\n }\n\n /**\n * A handler for the intent event dispatched by web components hosted by this activity.\n *\n * **Usage example:**\n *\n * ```ts\n * <custom-element @startactivity=\"${this.handleIntentEvent}\"></custom-element>\n * <custom-element @startactivityforresult=\"${this.handleIntentEvent}\"></custom-element>\n * ```\n *\n * @param event The event that was dispatched.\n * @returns A promise that resolves when the intent is handled.\n * @throws An error if the activity has no activity.\n * @throws An 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 await this.startActivityForResult(info.intent)\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,12 +1,40 @@
|
|
|
1
1
|
import type { Activity } from './Activity.js';
|
|
2
2
|
import type { Application } from './Application.js';
|
|
3
|
-
export declare enum
|
|
3
|
+
export declare enum ActivityLifecycle {
|
|
4
|
+
/**
|
|
5
|
+
* The activity is initialized, but not yet created.
|
|
6
|
+
* This is the initial state of the activity.
|
|
7
|
+
*/
|
|
4
8
|
Initialized = 0,
|
|
9
|
+
/**
|
|
10
|
+
* The activity is created, but not yet started.
|
|
11
|
+
* This is the state after the `onCreate()` method is called.
|
|
12
|
+
*/
|
|
5
13
|
Created = 1,
|
|
14
|
+
/**
|
|
15
|
+
* The activity is started, but not yet resumed.
|
|
16
|
+
* This is the state after the `onStart()` method is called.
|
|
17
|
+
*/
|
|
6
18
|
Started = 2,
|
|
19
|
+
/**
|
|
20
|
+
* The activity is resumed and visible to the user.
|
|
21
|
+
* This is the state after the `onResume()` method is called.
|
|
22
|
+
*/
|
|
7
23
|
Resumed = 3,
|
|
24
|
+
/**
|
|
25
|
+
* The activity is paused, but still visible to the user.
|
|
26
|
+
* This is the state after the `onPause()` method is called.
|
|
27
|
+
*/
|
|
8
28
|
Paused = 4,
|
|
29
|
+
/**
|
|
30
|
+
* The activity is stopped and no longer visible to the user.
|
|
31
|
+
* This is the state after the `onStop()` method is called.
|
|
32
|
+
*/
|
|
9
33
|
Stopped = 5,
|
|
34
|
+
/**
|
|
35
|
+
* The activity is destroyed and no longer exists.
|
|
36
|
+
* This is the state after the `onDestroy()` method is called.
|
|
37
|
+
*/
|
|
10
38
|
Destroyed = 6
|
|
11
39
|
}
|
|
12
40
|
export declare enum IntentFlags {
|
|
@@ -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,
|
|
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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Aa;IAgBrB;;;;;OAKG;IACG,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBhF,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAIxC;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;YAiCzC,oBAAoB;YAoBpB,wBAAwB;IAYtC,cAAc,IAAI,QAAQ,GAAG,SAAS;IAStC,kBAAkB,IAAI,QAAQ,GAAG,SAAS;IAI1C;;;;;;;OAOG;IACH,WAAW,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,IAAI;IAwB9D;;;;;;OAMG;YACW,qBAAqB;IAsEnC;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAQnC,iBAAiB,IAAI,MAAM;IAM3B,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;CAGzD"}
|
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
import { navigateScreen } from './ApplicationRoute.js';
|
|
2
|
-
export var
|
|
3
|
-
(function (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
export var ActivityLifecycle;
|
|
3
|
+
(function (ActivityLifecycle) {
|
|
4
|
+
/**
|
|
5
|
+
* The activity is initialized, but not yet created.
|
|
6
|
+
* This is the initial state of the activity.
|
|
7
|
+
*/
|
|
8
|
+
ActivityLifecycle[ActivityLifecycle["Initialized"] = 0] = "Initialized";
|
|
9
|
+
/**
|
|
10
|
+
* The activity is created, but not yet started.
|
|
11
|
+
* This is the state after the `onCreate()` method is called.
|
|
12
|
+
*/
|
|
13
|
+
ActivityLifecycle[ActivityLifecycle["Created"] = 1] = "Created";
|
|
14
|
+
/**
|
|
15
|
+
* The activity is started, but not yet resumed.
|
|
16
|
+
* This is the state after the `onStart()` method is called.
|
|
17
|
+
*/
|
|
18
|
+
ActivityLifecycle[ActivityLifecycle["Started"] = 2] = "Started";
|
|
19
|
+
/**
|
|
20
|
+
* The activity is resumed and visible to the user.
|
|
21
|
+
* This is the state after the `onResume()` method is called.
|
|
22
|
+
*/
|
|
23
|
+
ActivityLifecycle[ActivityLifecycle["Resumed"] = 3] = "Resumed";
|
|
24
|
+
/**
|
|
25
|
+
* The activity is paused, but still visible to the user.
|
|
26
|
+
* This is the state after the `onPause()` method is called.
|
|
27
|
+
*/
|
|
28
|
+
ActivityLifecycle[ActivityLifecycle["Paused"] = 4] = "Paused";
|
|
29
|
+
/**
|
|
30
|
+
* The activity is stopped and no longer visible to the user.
|
|
31
|
+
* This is the state after the `onStop()` method is called.
|
|
32
|
+
*/
|
|
33
|
+
ActivityLifecycle[ActivityLifecycle["Stopped"] = 5] = "Stopped";
|
|
34
|
+
/**
|
|
35
|
+
* The activity is destroyed and no longer exists.
|
|
36
|
+
* This is the state after the `onDestroy()` method is called.
|
|
37
|
+
*/
|
|
38
|
+
ActivityLifecycle[ActivityLifecycle["Destroyed"] = 6] = "Destroyed";
|
|
39
|
+
})(ActivityLifecycle || (ActivityLifecycle = {}));
|
|
12
40
|
export var IntentFlags;
|
|
13
41
|
(function (IntentFlags) {
|
|
14
42
|
/**
|
|
15
43
|
* Marks that the activity should be rendered as a modal.
|
|
16
44
|
*/
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member
|
|
18
45
|
IntentFlags[IntentFlags["Modal"] = 1] = "Modal";
|
|
19
46
|
/**
|
|
20
47
|
* The activity is started for result.
|
|
21
48
|
*/
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member
|
|
23
49
|
IntentFlags[IntentFlags["ForResult"] = 2] = "ForResult";
|
|
24
50
|
/**
|
|
25
51
|
* When set, the intent data is passed by reference.
|
|
@@ -27,7 +53,6 @@ export var IntentFlags;
|
|
|
27
53
|
* This is useful when the data is large and you want to avoid copying it
|
|
28
54
|
* or when you want to share the same data between activities.
|
|
29
55
|
*/
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member
|
|
31
56
|
IntentFlags[IntentFlags["ByReference"] = 4] = "ByReference";
|
|
32
57
|
})(IntentFlags || (IntentFlags = {}));
|
|
33
58
|
export var IntentResult;
|
|
@@ -129,14 +154,13 @@ export class ActivityManager {
|
|
|
129
154
|
await info.activity.onNewIntent(intent);
|
|
130
155
|
// TODO: Check if the activity is destroyed.
|
|
131
156
|
this.setupRoute(intent);
|
|
132
|
-
// this.currentActivity = info.activity
|
|
133
157
|
await this.updateCurrentActivity(info.activity, false);
|
|
134
158
|
return;
|
|
135
159
|
}
|
|
136
160
|
const activity = this.buildActivity(intent);
|
|
137
161
|
if (currentActivity) {
|
|
138
162
|
await currentActivity.onPause();
|
|
139
|
-
currentActivity.
|
|
163
|
+
currentActivity.lifecycle = ActivityLifecycle.Paused;
|
|
140
164
|
}
|
|
141
165
|
const activityId = this.generateActivityId();
|
|
142
166
|
const stackEntry = { activity, id: activityId, intent, action: intent.action };
|
|
@@ -155,7 +179,7 @@ export class ActivityManager {
|
|
|
155
179
|
// the activity finished and the manager already took care of this situation.
|
|
156
180
|
return;
|
|
157
181
|
}
|
|
158
|
-
activity.
|
|
182
|
+
activity.lifecycle = ActivityLifecycle.Created;
|
|
159
183
|
await this.updateCurrentActivity(activity, !!isModal);
|
|
160
184
|
if (this.isDestroyed(activity)) {
|
|
161
185
|
// the activity finished and the manager already took care of this situation.
|
|
@@ -203,7 +227,7 @@ export class ActivityManager {
|
|
|
203
227
|
await this.startActivity(deepCopy);
|
|
204
228
|
}
|
|
205
229
|
isDestroyed(activity) {
|
|
206
|
-
return activity.
|
|
230
|
+
return activity.lifecycle === ActivityLifecycle.Destroyed;
|
|
207
231
|
}
|
|
208
232
|
/**
|
|
209
233
|
* @param activity The activity to finish.
|
|
@@ -216,22 +240,22 @@ export class ActivityManager {
|
|
|
216
240
|
if (index !== -1) {
|
|
217
241
|
const stackEntry = stack.splice(index, 1)[0];
|
|
218
242
|
await stackEntry.activity.onPause();
|
|
219
|
-
stackEntry.activity.
|
|
243
|
+
stackEntry.activity.lifecycle = ActivityLifecycle.Paused;
|
|
220
244
|
await stackEntry.activity.onStop();
|
|
221
|
-
stackEntry.activity.
|
|
245
|
+
stackEntry.activity.lifecycle = ActivityLifecycle.Stopped;
|
|
222
246
|
await stackEntry.activity.onDestroy();
|
|
223
|
-
stackEntry.activity.
|
|
247
|
+
stackEntry.activity.lifecycle = ActivityLifecycle.Destroyed;
|
|
224
248
|
await this.manageActivityResult(stackEntry.activity, stackEntry.intent);
|
|
225
249
|
// Resume the previous activity
|
|
226
250
|
await this.bringLastActivityToFront();
|
|
227
251
|
}
|
|
228
252
|
else {
|
|
229
|
-
if (activity.
|
|
253
|
+
if (activity.lifecycle === ActivityLifecycle.Created) {
|
|
230
254
|
await activity.onStop();
|
|
231
|
-
activity.
|
|
255
|
+
activity.lifecycle = ActivityLifecycle.Stopped;
|
|
232
256
|
}
|
|
233
257
|
await activity.onDestroy();
|
|
234
|
-
activity.
|
|
258
|
+
activity.lifecycle = ActivityLifecycle.Destroyed;
|
|
235
259
|
// This can happen when an activity finishes in one of the callback methods,
|
|
236
260
|
// before it is added to the stack. In that case, we bring the last activity back to the front.
|
|
237
261
|
await this.bringLastActivityToFront();
|
|
@@ -244,12 +268,12 @@ export class ActivityManager {
|
|
|
244
268
|
const all = [...this.activityStack, ...this.modalActivityStack];
|
|
245
269
|
const target = all.find((entry) => entry.activity.hasRequestCode(requestCode));
|
|
246
270
|
if (target) {
|
|
247
|
-
if (target.activity.
|
|
271
|
+
if (target.activity.lifecycle === ActivityLifecycle.Destroyed) {
|
|
248
272
|
return;
|
|
249
273
|
}
|
|
250
|
-
if (target.activity.
|
|
274
|
+
if (target.activity.lifecycle === ActivityLifecycle.Resumed) {
|
|
251
275
|
await target.activity.onPause();
|
|
252
|
-
target.activity.
|
|
276
|
+
target.activity.lifecycle = ActivityLifecycle.Paused;
|
|
253
277
|
}
|
|
254
278
|
const intentCopy = structuredClone(intent);
|
|
255
279
|
intentCopy.data = activity.getResult();
|
|
@@ -271,11 +295,11 @@ export class ActivityManager {
|
|
|
271
295
|
}
|
|
272
296
|
}
|
|
273
297
|
getTopActivity() {
|
|
274
|
-
const topModal = this.modalActivityStack.findLast((a) => a.activity.
|
|
298
|
+
const topModal = this.modalActivityStack.findLast((a) => a.activity.lifecycle === ActivityLifecycle.Resumed);
|
|
275
299
|
if (topModal) {
|
|
276
300
|
return topModal.activity;
|
|
277
301
|
}
|
|
278
|
-
const top = this.activityStack.findLast((a) => a.activity.
|
|
302
|
+
const top = this.activityStack.findLast((a) => a.activity.lifecycle === ActivityLifecycle.Resumed);
|
|
279
303
|
return top ? top.activity : undefined;
|
|
280
304
|
}
|
|
281
305
|
getCurrentActivity() {
|
|
@@ -323,52 +347,52 @@ export class ActivityManager {
|
|
|
323
347
|
this.setupStyles(activity, this.currentActivity);
|
|
324
348
|
if (this.currentActivity &&
|
|
325
349
|
this.currentActivity !== activity &&
|
|
326
|
-
this.currentActivity.
|
|
350
|
+
this.currentActivity.lifecycle !== ActivityLifecycle.Destroyed &&
|
|
327
351
|
// Make sure we don't pause the current activity if it's already paused.
|
|
328
|
-
this.currentActivity.
|
|
352
|
+
this.currentActivity.lifecycle !== ActivityLifecycle.Paused) {
|
|
329
353
|
await this.currentActivity.onPause();
|
|
330
|
-
this.currentActivity.
|
|
354
|
+
this.currentActivity.lifecycle = ActivityLifecycle.Paused;
|
|
331
355
|
}
|
|
332
|
-
if (activity.
|
|
356
|
+
if (activity.lifecycle === ActivityLifecycle.Paused) {
|
|
333
357
|
await activity.onResume();
|
|
334
358
|
if (this.isDestroyed(activity)) {
|
|
335
359
|
return;
|
|
336
360
|
}
|
|
337
|
-
activity.
|
|
361
|
+
activity.lifecycle = ActivityLifecycle.Resumed;
|
|
338
362
|
activity.requestUpdate();
|
|
339
363
|
}
|
|
340
|
-
else if (activity.
|
|
364
|
+
else if (activity.lifecycle === ActivityLifecycle.Stopped) {
|
|
341
365
|
await activity.onRestart();
|
|
342
|
-
activity.
|
|
366
|
+
activity.lifecycle = ActivityLifecycle.Resumed;
|
|
343
367
|
}
|
|
344
|
-
else if (activity.
|
|
368
|
+
else if (activity.lifecycle === ActivityLifecycle.Destroyed) {
|
|
345
369
|
throw new Error(`Invalid state. The activity is already destroyed.`);
|
|
346
370
|
}
|
|
347
|
-
else if (activity.
|
|
371
|
+
else if (activity.lifecycle === ActivityLifecycle.Created) {
|
|
348
372
|
await activity.onStart();
|
|
349
373
|
if (this.isDestroyed(activity)) {
|
|
350
374
|
return;
|
|
351
375
|
}
|
|
352
|
-
activity.
|
|
376
|
+
activity.lifecycle = ActivityLifecycle.Started;
|
|
353
377
|
await activity.onResume();
|
|
354
378
|
if (this.isDestroyed(activity)) {
|
|
355
379
|
return;
|
|
356
380
|
}
|
|
357
|
-
activity.
|
|
381
|
+
activity.lifecycle = ActivityLifecycle.Resumed;
|
|
358
382
|
activity.requestUpdate();
|
|
359
383
|
}
|
|
360
|
-
else if (activity.
|
|
384
|
+
else if (activity.lifecycle === ActivityLifecycle.Started) {
|
|
361
385
|
await activity.onResume();
|
|
362
386
|
if (this.isDestroyed(activity)) {
|
|
363
387
|
return;
|
|
364
388
|
}
|
|
365
|
-
activity.
|
|
389
|
+
activity.lifecycle = ActivityLifecycle.Resumed;
|
|
366
390
|
activity.requestUpdate();
|
|
367
391
|
}
|
|
368
|
-
else if (activity.
|
|
392
|
+
else if (activity.lifecycle === ActivityLifecycle.Initialized) {
|
|
369
393
|
// TODO: Figure out intent passing here.
|
|
370
394
|
await activity.onCreate();
|
|
371
|
-
activity.
|
|
395
|
+
activity.lifecycle = ActivityLifecycle.Created;
|
|
372
396
|
if (this.isDestroyed(activity)) {
|
|
373
397
|
// the activity finished and the manager already took care of this situation.
|
|
374
398
|
return;
|
|
@@ -377,12 +401,12 @@ export class ActivityManager {
|
|
|
377
401
|
if (this.isDestroyed(activity)) {
|
|
378
402
|
return;
|
|
379
403
|
}
|
|
380
|
-
activity.
|
|
404
|
+
activity.lifecycle = ActivityLifecycle.Started;
|
|
381
405
|
await activity.onResume();
|
|
382
406
|
if (this.isDestroyed(activity)) {
|
|
383
407
|
return;
|
|
384
408
|
}
|
|
385
|
-
activity.
|
|
409
|
+
activity.lifecycle = ActivityLifecycle.Resumed;
|
|
386
410
|
activity.requestUpdate();
|
|
387
411
|
}
|
|
388
412
|
if (!isModal) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityManager.js","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,CAAN,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,+DAAW,CAAA;IACX,uDAAO,CAAA;IACP,uDAAO,CAAA;IACP,uDAAO,CAAA;IACP,qDAAM,CAAA;IACN,uDAAO,CAAA;IACP,2DAAS,CAAA;AACX,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB;AAED,MAAM,CAAN,IAAY,WAmBX;AAnBD,WAAY,WAAW;IACrB;;OAEG;IACH,yEAAyE;IACzE,+CAAc,CAAA;IACd;;OAEG;IACH,yEAAyE;IACzE,uDAAkB,CAAA;IAClB;;;;;OAKG;IACH,yEAAyE;IACzE,2DAAoB,CAAA;AACtB,CAAC,EAnBW,WAAW,KAAX,WAAW,QAmBtB;AAaD,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,qEAAe,CAAA;IACf,yDAAS,CAAA;AACX,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AA0BD;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAe;IAClB,eAAe,CAAW;IAElC;;OAEG;IACK,eAAe,GAAG,IAAI,GAAG,EAA2B,CAAA;IAE5D;;;O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AC,eAAe,GAAG,QAAQ,CAAA;QACjC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1D,6CAA6C;YAC7C,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACjD,CAAC;QACD,0DAA0D;IAC5D,CAAC;IAED,iBAAiB;QACf,MAAM,GAAG,GAAG,IAAI,CAAA;QAChB,MAAM,GAAG,GAAG,IAAI,CAAA;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAA;IACtD,CAAC;IAED,kBAAkB,CAAC,MAAc;QAC/B,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAA;IAC9E,CAAC;CACF","sourcesContent":["import type { Activity } from './Activity.js'\nimport type { Application } from './Application.js'\nimport { navigateScreen } from './ApplicationRoute.js'\n\nexport enum ActivityState {\n Initialized,\n Created,\n Started,\n Resumed,\n Paused,\n Stopped,\n Destroyed,\n}\n\nexport enum IntentFlags {\n /**\n * Marks that the activity should be rendered as a modal.\n */\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n Modal = 1 << 0,\n /**\n * The activity is started for result.\n */\n // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\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 // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member\n ByReference = 1 << 2,\n}\n\nexport interface Intent {\n action: string\n data?: unknown\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 * 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 * 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 registerActivity(action: string, activityClass: typeof Activity): void {\n if (this.activityClasses.has(action)) {\n // eslint-disable-next-line no-console\n console.warn(`Activity with action \"${action}\" already registered.`, new Error().stack)\n }\n this.activityClasses.set(action, activityClass)\n }\n\n // protected reflectEvent<T extends Event>(event: T): T {\n // const copy = Reflect.construct(event.constructor, [event.type, event])\n // const dispatched = this.#parent.events.dispatchEvent(copy)\n // if (!dispatched) {\n // event.preventDefault()\n // }\n // return copy\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<void> {\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 // this.currentActivity = info.activity\n await this.updateCurrentActivity(info.activity, false)\n return\n }\n const activity = this.buildActivity(intent)\n if (currentActivity) {\n await currentActivity.onPause()\n currentActivity.state = ActivityState.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\n }\n activity.state = ActivityState.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\n }\n this.setupRoute(intent)\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 * The result should be a unique number across the application.\n * @param intent The intent to start the activity.\n * @param requestCode The request code used to match the activity result.\n */\n async startActivityForResult(intent: Intent, requestCode: number): Promise<void> {\n intent.requestCode = requestCode\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 await this.startActivity(deepCopy)\n }\n\n isDestroyed(activity: Activity): boolean {\n return activity.state === ActivityState.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.state = ActivityState.Paused\n await stackEntry.activity.onStop()\n stackEntry.activity.state = ActivityState.Stopped\n await stackEntry.activity.onDestroy()\n stackEntry.activity.state = ActivityState.Destroyed\n\n await this.manageActivityResult(stackEntry.activity, stackEntry.intent)\n\n // Resume the previous activity\n await this.bringLastActivityToFront()\n } else {\n if (activity.state === ActivityState.Created) {\n await activity.onStop()\n activity.state = ActivityState.Stopped\n }\n await activity.onDestroy()\n activity.state = ActivityState.Destroyed\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 async manageActivityResult(activity: Activity, intent: Intent): Promise<void> {\n const { flags = 0, requestCode = -1 } = intent\n if (flags & IntentFlags.ForResult) {\n const all = [...this.activityStack, ...this.modalActivityStack]\n const target = all.find((entry) => entry.activity.hasRequestCode(requestCode))\n if (target) {\n if (target.activity.state === ActivityState.Destroyed) {\n return\n }\n if (target.activity.state === ActivityState.Resumed) {\n await target.activity.onPause()\n target.activity.state = ActivityState.Paused\n }\n const intentCopy = structuredClone(intent)\n intentCopy.data = activity.getResult()\n await target.activity.onActivityResult(requestCode, activity.resultCode, intentCopy)\n }\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)\n } else if (this.activityStack.length > 0) {\n const previousEntry = this.activityStack[this.activityStack.length - 1]\n await this.updateCurrentActivity(previousEntry.activity, false)\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.state === ActivityState.Resumed)\n if (topModal) {\n return topModal.activity\n }\n const top = this.activityStack.findLast((a) => a.activity.state === ActivityState.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): Promise<void> {\n this.setupStyles(activity, this.currentActivity)\n if (\n this.currentActivity &&\n this.currentActivity !== activity &&\n this.currentActivity.state !== ActivityState.Destroyed &&\n // Make sure we don't pause the current activity if it's already paused.\n this.currentActivity.state !== ActivityState.Paused\n ) {\n await this.currentActivity.onPause()\n this.currentActivity.state = ActivityState.Paused\n }\n if (activity.state === ActivityState.Paused) {\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.state = ActivityState.Resumed\n activity.requestUpdate()\n } else if (activity.state === ActivityState.Stopped) {\n await activity.onRestart()\n activity.state = ActivityState.Resumed\n } else if (activity.state === ActivityState.Destroyed) {\n throw new Error(`Invalid state. The activity is already destroyed.`)\n } else if (activity.state === ActivityState.Created) {\n await activity.onStart()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.state = ActivityState.Started\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.state = ActivityState.Resumed\n activity.requestUpdate()\n } else if (activity.state === ActivityState.Started) {\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.state = ActivityState.Resumed\n activity.requestUpdate()\n } else if (activity.state === ActivityState.Initialized) {\n // TODO: Figure out intent passing here.\n await activity.onCreate()\n activity.state = ActivityState.Created\n if (this.isDestroyed(activity)) {\n // the activity finished and the manager already took care of this situation.\n return\n }\n await activity.onStart()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.state = ActivityState.Started\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.state = ActivityState.Resumed\n activity.requestUpdate()\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 * 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 */\n async navigateBack(): Promise<void> {\n if (this.activityStack.length > 1 && this.currentActivity) {\n // Finish current, which will resume previous\n await this.finishActivity(this.currentActivity)\n }\n // Else do nothing (or display a message, or exit the app)\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"]}
|
|
1
|
+
{"version":3,"file":"ActivityManager.js","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,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,YA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M,QAAQ,CAAC,QAAQ,EAAE,CAAA;YACzB,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC/B,OAAM;YACR,CAAC;YACD,QAAQ,CAAC,SAAS,GAAG,iBAAiB,CAAC,OAAO,CAAA;YAC9C,QAAQ,CAAC,aAAa,EAAE,CAAA;QAC1B,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,iFAAiF;YACjF,wEAAwE;YACxE,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAA;QACjC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1D,6CAA6C;YAC7C,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACjD,CAAC;QACD,0DAA0D;IAC5D,CAAC;IAED,iBAAiB;QACf,MAAM,GAAG,GAAG,IAAI,CAAA;QAChB,MAAM,GAAG,GAAG,IAAI,CAAA;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAA;IACtD,CAAC;IAED,kBAAkB,CAAC,MAAc;QAC/B,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAA;IAC9E,CAAC;CACF","sourcesContent":["import type { Activity } from './Activity.js'\nimport type { Application } from './Application.js'\nimport { 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 {\n action: string\n data?: unknown\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 * 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 * 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 registerActivity(action: string, activityClass: typeof Activity): void {\n if (this.activityClasses.has(action)) {\n // eslint-disable-next-line no-console\n console.warn(`Activity with action \"${action}\" already registered.`, new Error().stack)\n }\n this.activityClasses.set(action, activityClass)\n }\n\n // protected reflectEvent<T extends Event>(event: T): T {\n // const copy = Reflect.construct(event.constructor, [event.type, event])\n // const dispatched = this.#parent.events.dispatchEvent(copy)\n // if (!dispatched) {\n // event.preventDefault()\n // }\n // return copy\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<void> {\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\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\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\n }\n this.setupRoute(intent)\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 * The result should be a unique number across the application.\n * @param intent The intent to start the activity.\n * @param requestCode The request code used to match the activity result.\n */\n async startActivityForResult(intent: Intent, requestCode: number): Promise<void> {\n intent.requestCode = requestCode\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 await this.startActivity(deepCopy)\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 await this.manageActivityResult(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 // 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 async manageActivityResult(activity: Activity, intent: Intent): Promise<void> {\n const { flags = 0, requestCode = -1 } = intent\n if (flags & IntentFlags.ForResult) {\n const all = [...this.activityStack, ...this.modalActivityStack]\n const target = all.find((entry) => entry.activity.hasRequestCode(requestCode))\n if (target) {\n if (target.activity.lifecycle === ActivityLifecycle.Destroyed) {\n return\n }\n if (target.activity.lifecycle === ActivityLifecycle.Resumed) {\n await target.activity.onPause()\n target.activity.lifecycle = ActivityLifecycle.Paused\n }\n const intentCopy = structuredClone(intent)\n intentCopy.data = activity.getResult()\n await target.activity.onActivityResult(requestCode, activity.resultCode, intentCopy)\n }\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)\n } else if (this.activityStack.length > 0) {\n const previousEntry = this.activityStack[this.activityStack.length - 1]\n await this.updateCurrentActivity(previousEntry.activity, false)\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): 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 if (activity.lifecycle === ActivityLifecycle.Paused) {\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n } else if (activity.lifecycle === ActivityLifecycle.Stopped) {\n await activity.onRestart()\n activity.lifecycle = ActivityLifecycle.Resumed\n } else if (activity.lifecycle === ActivityLifecycle.Destroyed) {\n throw new Error(`Invalid state. The activity is already destroyed.`)\n } else if (activity.lifecycle === ActivityLifecycle.Created) {\n await activity.onStart()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.lifecycle = ActivityLifecycle.Started\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n } else if (activity.lifecycle === ActivityLifecycle.Started) {\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\n } else if (activity.lifecycle === ActivityLifecycle.Initialized) {\n // TODO: Figure out intent passing here.\n await activity.onCreate()\n activity.lifecycle = ActivityLifecycle.Created\n if (this.isDestroyed(activity)) {\n // the activity finished and the manager already took care of this situation.\n return\n }\n await activity.onStart()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.lifecycle = ActivityLifecycle.Started\n await activity.onResume()\n if (this.isDestroyed(activity)) {\n return\n }\n activity.lifecycle = ActivityLifecycle.Resumed\n activity.requestUpdate()\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 * 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 */\n async navigateBack(): Promise<void> {\n if (this.activityStack.length > 1 && this.currentActivity) {\n // Finish current, which will resume previous\n await this.finishActivity(this.currentActivity)\n }\n // Else do nothing (or display a message, or exit the app)\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../../src/core/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAClD,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../../src/core/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAClD,OAAO,EAAE,eAAe,EAAqB,MAAM,sBAAsB,CAAA;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AACD;;;;;;;;;;;;;;;;;GAiBG;AACH,8BAAsB,WAAY,SAAQ,WAAW;;IACnD,OAAO,CAAC,sBAAsB,CAAuC;IAMrE;;OAEG;IACH,IAAI,KAAK,IAAI,YAAY,CAExB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,eAAe,CAE7B;IAID;;;;OAIG;IACH,IAAI,MAAM,IAAI,WAAW,CAExB;IAID,IAAI,QAAQ,IAAI,mBAAmB,CAElC;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAE9C;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED;;OAEG;gBACS,UAAU,EAAE,WAAW,GAAG,MAAM;IAY5C;;OAEG;IACI,aAAa,CAAC,UAAU,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI;IAI5D;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAExC;;;OAGG;IACH,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACH,aAAa,IAAI,IAAI;IAIrB;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;;;;;;OAOG;IACH,MAAM,IAAI,cAAc,GAAG,OAAO,OAAO;IASzC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;;OAGG;IACH,aAAa,CAAC,IAAI,GAAE,aAAkB,GAAG,IAAI;IAO7C;;OAEG;IACU,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC,kBAAkB,IAAI,QAAQ,GAAG,SAAS;IAI1C;;;OAGG;IACH,cAAc;IAId,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;CAGrD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nothing } from 'lit';
|
|
2
|
-
import { ActivityManager,
|
|
2
|
+
import { ActivityManager, ActivityLifecycle } from './ActivityManager.js';
|
|
3
3
|
import { ApplicationRenderer } from './renderer/ApplicationRenderer.js';
|
|
4
4
|
import { ThemeManager } from './ThemeManager.js';
|
|
5
5
|
/**
|
|
@@ -111,7 +111,7 @@ export class Application extends EventTarget {
|
|
|
111
111
|
render() {
|
|
112
112
|
const currentActivity = this.#activities.getCurrentActivity();
|
|
113
113
|
// Only render if started or beyond
|
|
114
|
-
if (currentActivity && currentActivity.
|
|
114
|
+
if (currentActivity && currentActivity.lifecycle >= ActivityLifecycle.Started) {
|
|
115
115
|
return currentActivity.render();
|
|
116
116
|
}
|
|
117
117
|
return nothing;
|