@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
|
@@ -5,7 +5,7 @@ import { Activity } from '../../src/core/Activity.js'
|
|
|
5
5
|
import { Application } from '../../src/core/Application.js'
|
|
6
6
|
import {
|
|
7
7
|
ActivityManager,
|
|
8
|
-
|
|
8
|
+
ActivityLifecycle,
|
|
9
9
|
IntentFlags,
|
|
10
10
|
IntentResult,
|
|
11
11
|
type Intent,
|
|
@@ -41,7 +41,7 @@ class TestActivity extends Activity {
|
|
|
41
41
|
this.setResult.resetHistory()
|
|
42
42
|
this.getResult.resetHistory()
|
|
43
43
|
this.hasRequestCode.resetHistory()
|
|
44
|
-
this.
|
|
44
|
+
this.lifecycle = ActivityLifecycle.Initialized
|
|
45
45
|
this.pendingRequestCodes.length = 0
|
|
46
46
|
this.exitCode = IntentResult.RESULT_CANCELED
|
|
47
47
|
this.resultData = undefined
|
|
@@ -114,7 +114,7 @@ describe('ActivityManager', () => {
|
|
|
114
114
|
assert.equal(manager['activityStack'].length, 1)
|
|
115
115
|
const entry = manager['activityStack'][0]
|
|
116
116
|
assert.instanceOf(entry.activity, TestActivity)
|
|
117
|
-
assert.equal(entry.activity.
|
|
117
|
+
assert.equal(entry.activity.lifecycle, ActivityLifecycle.Initialized)
|
|
118
118
|
assert.strictEqual(entry.intent, intent)
|
|
119
119
|
assert.isUndefined(manager.getCurrentActivity())
|
|
120
120
|
})
|
|
@@ -142,7 +142,7 @@ describe('ActivityManager', () => {
|
|
|
142
142
|
assert.isTrue((entry.activity as TestActivity).onCreate.calledOnceWith(intent))
|
|
143
143
|
assert.isTrue((entry.activity as TestActivity).onStart.calledOnce)
|
|
144
144
|
assert.isTrue((entry.activity as TestActivity).onResume.calledOnce)
|
|
145
|
-
assert.equal(entry.activity.
|
|
145
|
+
assert.equal(entry.activity.lifecycle, ActivityLifecycle.Resumed)
|
|
146
146
|
// assert.isFalse(navigateScreenStub.called) // No URI in intent
|
|
147
147
|
})
|
|
148
148
|
|
|
@@ -162,12 +162,12 @@ describe('ActivityManager', () => {
|
|
|
162
162
|
await manager.startActivity(intent2)
|
|
163
163
|
const activity2 = manager.getCurrentActivity() as TestActivity
|
|
164
164
|
assert.isTrue(activity1.onPause.calledOnce, 'activity1 onPause should be called once')
|
|
165
|
-
assert.equal(activity1.
|
|
165
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Paused, 'activity1 should be paused')
|
|
166
166
|
|
|
167
167
|
assert.isTrue(activity2.onCreate.calledOnceWith(intent2), 'activity2 onCreate should be called with intent')
|
|
168
168
|
assert.isTrue(activity2.onStart.calledOnce, 'activity2 onStart should be called once')
|
|
169
169
|
assert.isTrue(activity2.onResume.calledOnce, 'activity2 onResume should be called once')
|
|
170
|
-
assert.equal(activity2.
|
|
170
|
+
assert.equal(activity2.lifecycle, ActivityLifecycle.Resumed, 'activity2 should be resumed')
|
|
171
171
|
assert.equal(manager['activityStack'].length, 2, 'activity stack should have 2 activities')
|
|
172
172
|
})
|
|
173
173
|
|
|
@@ -182,8 +182,8 @@ describe('ActivityManager', () => {
|
|
|
182
182
|
const activity2 = manager.getCurrentActivity() as TestActivity
|
|
183
183
|
|
|
184
184
|
// activity1 is now paused, activity2 is resumed
|
|
185
|
-
assert.equal(activity1.
|
|
186
|
-
assert.equal(activity2.
|
|
185
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Paused, 'activity1 should be paused')
|
|
186
|
+
assert.equal(activity2.lifecycle, ActivityLifecycle.Resumed, 'activity2 should be resumed')
|
|
187
187
|
|
|
188
188
|
const newIntentForActivity1: Intent = { action: TestActivity.action, data: { updated: true } }
|
|
189
189
|
await manager.startActivity(newIntentForActivity1)
|
|
@@ -191,10 +191,10 @@ describe('ActivityManager', () => {
|
|
|
191
191
|
assert.strictEqual(manager.getCurrentActivity(), activity1)
|
|
192
192
|
assert.isTrue(activity1.onNewIntent.calledOnceWith(newIntentForActivity1), 'activity1 called with new intent')
|
|
193
193
|
assert.isTrue(activity1.onResume.calledOnce, 'activity1 onResume called once') // Should be resumed
|
|
194
|
-
assert.equal(activity1.
|
|
194
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Resumed, 'activity1 should be resumed')
|
|
195
195
|
|
|
196
196
|
assert.isTrue(activity2.onPause.calledOnce, 'activity2 paused once') // activity2 should be paused
|
|
197
|
-
assert.equal(activity2.
|
|
197
|
+
assert.equal(activity2.lifecycle, ActivityLifecycle.Paused, 'activity2 should be paused')
|
|
198
198
|
|
|
199
199
|
assert.equal(manager['activityStack'].length, 2, 'activityStack is the same') // Stack size remains the same
|
|
200
200
|
assert.strictEqual(manager['activityStack'][1].activity, activity1) // activity1 is now at the top
|
|
@@ -214,14 +214,14 @@ describe('ActivityManager', () => {
|
|
|
214
214
|
assert.strictEqual(manager['modalActivityStack'][0].activity, modalActivity)
|
|
215
215
|
|
|
216
216
|
assert.isTrue(activity1.onPause.calledOnce)
|
|
217
|
-
assert.equal(activity1.
|
|
217
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Paused)
|
|
218
218
|
// For modal, currentActivity in manager should still be the underlying one
|
|
219
219
|
assert.strictEqual(manager.getCurrentActivity(), activity1)
|
|
220
220
|
|
|
221
221
|
assert.isTrue(modalActivity.onCreate.calledOnceWith(modalIntent))
|
|
222
222
|
assert.isTrue(modalActivity.onStart.calledOnce)
|
|
223
223
|
assert.isTrue(modalActivity.onResume.calledOnce)
|
|
224
|
-
assert.equal(modalActivity.
|
|
224
|
+
assert.equal(modalActivity.lifecycle, ActivityLifecycle.Resumed)
|
|
225
225
|
})
|
|
226
226
|
|
|
227
227
|
it('throws if activity class is not registered', async () => {
|
|
@@ -301,11 +301,11 @@ describe('ActivityManager', () => {
|
|
|
301
301
|
assert.isTrue(activity2.onPause.calledOnce, 'activity2 onPause should be called once')
|
|
302
302
|
assert.isTrue(activity2.onStop.calledOnce, 'activity2 onStop should be called once')
|
|
303
303
|
assert.isTrue(activity2.onDestroy.calledOnce, 'activity2 onDestroy should be called once')
|
|
304
|
-
assert.equal(activity2.
|
|
304
|
+
assert.equal(activity2.lifecycle, ActivityLifecycle.Destroyed, 'activity2 should be destroyed')
|
|
305
305
|
|
|
306
306
|
assert.strictEqual(manager.getCurrentActivity(), activity1)
|
|
307
307
|
assert.isTrue(activity1.onResume.calledOnce, 'activity1 onResume should be called once')
|
|
308
|
-
assert.equal(activity1.
|
|
308
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Resumed, 'activity1 should be resumed')
|
|
309
309
|
assert.equal(manager['activityStack'].length, 1, 'activity stack should have 1 activity')
|
|
310
310
|
assert.isTrue(app.requestUpdateSpy.called, 'Application should request update after finishing activity')
|
|
311
311
|
})
|
|
@@ -325,12 +325,12 @@ describe('ActivityManager', () => {
|
|
|
325
325
|
assert.isTrue(modalActivity.onPause.calledOnce)
|
|
326
326
|
assert.isTrue(modalActivity.onStop.calledOnce)
|
|
327
327
|
assert.isTrue(modalActivity.onDestroy.calledOnce)
|
|
328
|
-
assert.equal(modalActivity.
|
|
328
|
+
assert.equal(modalActivity.lifecycle, ActivityLifecycle.Destroyed)
|
|
329
329
|
assert.equal(manager['modalActivityStack'].length, 0)
|
|
330
330
|
|
|
331
331
|
assert.strictEqual(manager.getCurrentActivity(), activity1) // Current activity should be the underlying one
|
|
332
332
|
assert.isTrue(activity1.onResume.calledOnce)
|
|
333
|
-
assert.equal(activity1.
|
|
333
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Resumed)
|
|
334
334
|
assert.equal(manager['activityStack'].length, 1)
|
|
335
335
|
})
|
|
336
336
|
|
|
@@ -362,13 +362,13 @@ describe('ActivityManager', () => {
|
|
|
362
362
|
|
|
363
363
|
it('handles finishing an activity that was only created (not fully started)', async () => {
|
|
364
364
|
const activity = new TestActivity(app)
|
|
365
|
-
activity.
|
|
365
|
+
activity.lifecycle = ActivityLifecycle.Created // Manually set for test
|
|
366
366
|
|
|
367
367
|
await manager.finishActivity(activity)
|
|
368
368
|
|
|
369
369
|
assert.isTrue(activity.onStop.calledOnce, 'onStop should be called for created activity')
|
|
370
370
|
assert.isTrue(activity.onDestroy.calledOnce, 'onDestroy should be called')
|
|
371
|
-
assert.equal(activity.
|
|
371
|
+
assert.equal(activity.lifecycle, ActivityLifecycle.Destroyed)
|
|
372
372
|
assert.isUndefined(manager.getCurrentActivity()) // Assuming no other activities
|
|
373
373
|
})
|
|
374
374
|
|
|
@@ -380,7 +380,7 @@ describe('ActivityManager', () => {
|
|
|
380
380
|
await manager.finishActivity(activity1)
|
|
381
381
|
|
|
382
382
|
assert.isTrue(activity1.onDestroy.calledOnce)
|
|
383
|
-
assert.equal(activity1.
|
|
383
|
+
assert.equal(activity1.lifecycle, ActivityLifecycle.Destroyed)
|
|
384
384
|
assert.isUndefined(manager.getCurrentActivity())
|
|
385
385
|
assert.equal(manager['activityStack'].length, 0)
|
|
386
386
|
})
|
|
@@ -394,11 +394,11 @@ describe('ActivityManager', () => {
|
|
|
394
394
|
it('returns the top resumed regular activity', async () => {
|
|
395
395
|
await manager.startActivity({ action: TestActivity.action })
|
|
396
396
|
const activity1 = manager['activityStack'][0].activity
|
|
397
|
-
activity1.
|
|
397
|
+
activity1.lifecycle = ActivityLifecycle.Resumed // Ensure it's resumed
|
|
398
398
|
|
|
399
399
|
await manager.startActivity({ action: TestActivity2.action })
|
|
400
400
|
const activity2 = manager['activityStack'][1].activity
|
|
401
|
-
activity2.
|
|
401
|
+
activity2.lifecycle = ActivityLifecycle.Resumed // Ensure it's resumed
|
|
402
402
|
|
|
403
403
|
assert.strictEqual(manager.getTopActivity(), activity2)
|
|
404
404
|
})
|
|
@@ -406,11 +406,11 @@ describe('ActivityManager', () => {
|
|
|
406
406
|
it('returns the top resumed modal activity if present', async () => {
|
|
407
407
|
await manager.startActivity({ action: TestActivity.action }) // Regular activity
|
|
408
408
|
const regularActivity = manager['activityStack'][0].activity
|
|
409
|
-
regularActivity.
|
|
409
|
+
regularActivity.lifecycle = ActivityLifecycle.Resumed
|
|
410
410
|
|
|
411
411
|
await manager.startActivity({ action: TestActivity2.action, flags: IntentFlags.Modal })
|
|
412
412
|
const modalActivity = manager['modalActivityStack'][0].activity
|
|
413
|
-
modalActivity.
|
|
413
|
+
modalActivity.lifecycle = ActivityLifecycle.Resumed // Ensure it's resumed
|
|
414
414
|
|
|
415
415
|
assert.strictEqual(manager.getTopActivity(), modalActivity)
|
|
416
416
|
})
|
|
@@ -421,8 +421,8 @@ describe('ActivityManager', () => {
|
|
|
421
421
|
|
|
422
422
|
await manager.startActivity({ action: TestActivity2.action, flags: IntentFlags.Modal })
|
|
423
423
|
const modalActivity = manager['modalActivityStack'][0].activity
|
|
424
|
-
modalActivity.
|
|
425
|
-
regularActivity.
|
|
424
|
+
modalActivity.lifecycle = ActivityLifecycle.Paused // Not resumed
|
|
425
|
+
regularActivity.lifecycle = ActivityLifecycle.Resumed
|
|
426
426
|
assert.strictEqual(manager.getTopActivity(), regularActivity)
|
|
427
427
|
})
|
|
428
428
|
})
|
|
@@ -3,7 +3,7 @@ import sinon from 'sinon'
|
|
|
3
3
|
import { fixture, html } from '@open-wc/testing'
|
|
4
4
|
import { Application, type UpdateRequest } from '../../src/core/Application.js'
|
|
5
5
|
import { Activity } from '../../src/core/Activity.js'
|
|
6
|
-
import { ActivityManager,
|
|
6
|
+
import { ActivityManager, ActivityLifecycle } from '../../src/core/ActivityManager.js'
|
|
7
7
|
import { ApplicationRenderer } from '../../src/core/renderer/ApplicationRenderer.js'
|
|
8
8
|
import { ThemeManager } from '../../src/core/ThemeManager.js'
|
|
9
9
|
import { nothing } from 'lit'
|
|
@@ -136,12 +136,12 @@ describe('Application', () => {
|
|
|
136
136
|
await app.run() // This calls onStart which registers TestActivity
|
|
137
137
|
await app.manager.startActivity({ action: TestActivity.action })
|
|
138
138
|
const activity = app.getCurrentActivity() as TestActivity
|
|
139
|
-
activity.
|
|
139
|
+
activity.lifecycle = ActivityLifecycle.Started // Ensure state
|
|
140
140
|
|
|
141
141
|
app.render()
|
|
142
142
|
assert.isTrue(activity.renderSpy.calledOnce)
|
|
143
143
|
|
|
144
|
-
activity.
|
|
144
|
+
activity.lifecycle = ActivityLifecycle.Resumed // Ensure state
|
|
145
145
|
activity.renderSpy.resetHistory()
|
|
146
146
|
app.render()
|
|
147
147
|
assert.isTrue(activity.renderSpy.calledOnce)
|
|
@@ -5,7 +5,7 @@ import { Fragment } from '../../src/core/Fragment.js'
|
|
|
5
5
|
import { Activity } from '../../src/core/Activity.js'
|
|
6
6
|
import { Application } from '../../src/core/Application.js'
|
|
7
7
|
import { FragmentState, FragmentManager } from '../../src/core/FragmentManager.js'
|
|
8
|
-
import { IntentResult, type Intent,
|
|
8
|
+
import { IntentResult, type Intent, ActivityLifecycle } from '../../src/core/ActivityManager.js'
|
|
9
9
|
import { FragmentRenderer } from '../../src/core/renderer/FragmentRenderer.js'
|
|
10
10
|
import { EventTypes } from '../../src/events/EventTypes.js'
|
|
11
11
|
import { nothing } from 'lit'
|
|
@@ -107,7 +107,7 @@ describe('Fragment', () => {
|
|
|
107
107
|
app = new TestApplication(renderRoot)
|
|
108
108
|
await app.run() // To register activity
|
|
109
109
|
activity = new TestActivity(app) // Parent for the fragment
|
|
110
|
-
activity.
|
|
110
|
+
activity.lifecycle = ActivityLifecycle.Resumed // Mock activity as active
|
|
111
111
|
fragment = new TestFragment({ parent: activity })
|
|
112
112
|
})
|
|
113
113
|
|
|
@@ -61,10 +61,40 @@ describe('LiveData Basic', () => {
|
|
|
61
61
|
|
|
62
62
|
liveData.value.items.push('orange')
|
|
63
63
|
|
|
64
|
-
assert.equal(spy.callCount, 1)
|
|
64
|
+
assert.equal(spy.callCount, 1, 'called once for the push')
|
|
65
65
|
const args = spy.args[0][0].detail
|
|
66
|
-
assert.equal(args.path, 'items.2')
|
|
67
|
-
assert.equal(args.value, 'orange')
|
|
66
|
+
assert.equal(args.path, 'items.2', 'path is correct')
|
|
67
|
+
assert.equal(args.value, 'orange', 'value is correct')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should handle sets', () => {
|
|
71
|
+
const data = { set: new Set(['apple', 'banana']) }
|
|
72
|
+
const liveData = new LiveData(data)
|
|
73
|
+
|
|
74
|
+
const spy = sinon.spy()
|
|
75
|
+
liveData.addEventListener('update', spy)
|
|
76
|
+
|
|
77
|
+
liveData.value.set.add('orange')
|
|
78
|
+
|
|
79
|
+
assert.equal(spy.callCount, 1, 'called once for the add')
|
|
80
|
+
const args = spy.args[0][0].detail
|
|
81
|
+
assert.equal(args.path, 'set', 'path is correct')
|
|
82
|
+
assert.deepEqual(args.value, data.set, 'value is correct')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should handle maps', () => {
|
|
86
|
+
const data = { map: new Map([['a', 'b']]) }
|
|
87
|
+
const liveData = new LiveData(data)
|
|
88
|
+
|
|
89
|
+
const spy = sinon.spy()
|
|
90
|
+
liveData.addEventListener('update', spy)
|
|
91
|
+
|
|
92
|
+
liveData.value.map.set('c', 'd')
|
|
93
|
+
|
|
94
|
+
assert.equal(spy.callCount, 1, 'called once for the add')
|
|
95
|
+
const args = spy.args[0][0].detail
|
|
96
|
+
assert.equal(args.path, 'map', 'path is correct')
|
|
97
|
+
assert.deepEqual(args.value, data.map, 'value is correct')
|
|
68
98
|
})
|
|
69
99
|
|
|
70
100
|
it('should handle arrays with array index', () => {
|
|
@@ -73,11 +73,8 @@ describe('DataTable', () => {
|
|
|
73
73
|
describe('Basic tests', () => {
|
|
74
74
|
it('renders the table with correct number of rows and columns', async () => {
|
|
75
75
|
const items = generateItems(3)
|
|
76
|
-
// console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
77
76
|
const element = await basicFixture<TestItem>(items)
|
|
78
|
-
// console.log('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
|
|
79
77
|
await nextFrame()
|
|
80
|
-
// console.log('ccccccccccccccccccccccccccccccccccc')
|
|
81
78
|
const rows = element.shadowRoot!.querySelectorAll('tr')
|
|
82
79
|
assert.equal(rows.length, items.value.length + 1, 'has all rows') // +1 for header row
|
|
83
80
|
|