@lisergia/core 25.0.0 → 26.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/App.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { type IArrayDidChange, type IValueDidChange } from 'mobx';
2
1
  import { Component, type ComponentParameters } from './Component.js';
3
2
  import { Links } from './Links.js';
4
3
  import type { Page, PageParameters } from './Page.js';
@@ -26,7 +25,6 @@ export declare class ApplicationManager extends Component {
26
25
  initComponents(components: Array<ApplicationComponentData>): void;
27
26
  addComponent(component: Component): void;
28
27
  removeComponent(component: Component): void;
29
- onComponentChange(_event: IArrayDidChange<Component>): void;
30
28
  datasets: Array<ApplicationComponentDatasetData>;
31
29
  initDatasets(datasets: Array<ApplicationComponentDatasetData>): void;
32
30
  pages: Map<string, new (args: PageParameters) => Page>;
@@ -41,9 +39,10 @@ export declare class ApplicationManager extends Component {
41
39
  destroyPage(): void;
42
40
  route: string;
43
41
  routeHistory: Array<string>;
44
- routeRequestEnabled: boolean;
45
- routePushState: boolean;
46
- onRouteChange({ newValue }: IValueDidChange<string>): void;
42
+ setRoute(route: string): boolean;
43
+ navigate(href: string, { pushState }?: {
44
+ pushState?: boolean;
45
+ }): void;
47
46
  onRouteChangeRequest({ href, pushState }: {
48
47
  href: string;
49
48
  pushState: boolean;
@@ -60,6 +59,7 @@ export declare class ApplicationManager extends Component {
60
59
  }): Promise<void>;
61
60
  onPopState(): void;
62
61
  get scroll(): number;
62
+ onResize(): void;
63
63
  addEventListeners(): void;
64
64
  removeEventListeners(): void;
65
65
  }
package/dist/App.js CHANGED
@@ -1,4 +1,3 @@
1
- import { autorun, computed, makeObservable, observable, observe, } from 'mobx';
2
1
  import { Component } from './Component.js';
3
2
  import { Links } from './Links.js';
4
3
  export class ApplicationManager extends Component {
@@ -8,28 +7,6 @@ export class ApplicationManager extends Component {
8
7
  autoListeners: false,
9
8
  element: '.app',
10
9
  });
11
- makeObservable(this, {
12
- // Application DOM Element.
13
- element: observable,
14
- // Components.
15
- canvas: observable,
16
- components: observable,
17
- transition: observable,
18
- // Page Information.
19
- currentPage: observable,
20
- nextPage: observable,
21
- // Route Information.
22
- route: observable,
23
- routeHistory: observable,
24
- // Template Information.
25
- template: observable,
26
- // Page Scroll.
27
- scroll: computed,
28
- });
29
- observe(this.components, this.onComponentChange);
30
- observe(this, 'route', this.onRouteChange);
31
- autorun(this.onTitleUpdate);
32
- autorun(this.onTemplateUpdate);
33
10
  this.addEventListeners();
34
11
  }
35
12
  onTitleUpdate() {
@@ -71,7 +48,6 @@ export class ApplicationManager extends Component {
71
48
  this.components.splice(index, 1);
72
49
  }
73
50
  }
74
- onComponentChange(_event) { }
75
51
  //
76
52
  // Datasets.
77
53
  //
@@ -131,6 +107,7 @@ export class ApplicationManager extends Component {
131
107
  });
132
108
  this.currentPage = page;
133
109
  this.currentPage.create();
110
+ this.fire('page', page);
134
111
  }
135
112
  destroyPage() {
136
113
  if (this.currentPage) {
@@ -142,21 +119,27 @@ export class ApplicationManager extends Component {
142
119
  //
143
120
  route = `${window.location.pathname}${window.location.search}${window.location.hash}`;
144
121
  routeHistory = [this.route];
145
- routeRequestEnabled = true;
146
- routePushState = true;
147
- onRouteChange({ newValue }) {
148
- if (!this.routeRequestEnabled) {
149
- return;
122
+ setRoute(route) {
123
+ if (route === this.route) {
124
+ return false;
150
125
  }
151
- const url = new URL(newValue, window.location.href);
126
+ this.route = route;
127
+ this.fire('route', route);
128
+ return true;
129
+ }
130
+ navigate(href, { pushState = true } = {}) {
131
+ const url = new URL(href, window.location.href);
152
132
  if (url.origin !== window.location.origin) {
153
133
  window.location.assign(url.href);
154
134
  return;
155
135
  }
156
- const href = `${url.pathname}${url.search}${url.hash}`;
136
+ const route = `${url.pathname}${url.search}${url.hash}`;
137
+ if (!this.setRoute(route)) {
138
+ return;
139
+ }
157
140
  void this.onRouteChangeRequest({
158
- href,
159
- pushState: this.routePushState,
141
+ href: route,
142
+ pushState,
160
143
  });
161
144
  }
162
145
  async onRouteChangeRequest({ href, pushState = true }) {
@@ -201,6 +184,8 @@ export class ApplicationManager extends Component {
201
184
  template,
202
185
  title: dom.title || document.title,
203
186
  };
187
+ this.onTitleUpdate();
188
+ this.onTemplateUpdate();
204
189
  if (this.transition) {
205
190
  await this.transition.onTransition?.(this);
206
191
  }
@@ -222,15 +207,12 @@ export class ApplicationManager extends Component {
222
207
  const route = `${document.location.pathname}${document.location.search}${document.location.hash}`;
223
208
  const currentUrl = new URL(this.route, window.location.origin);
224
209
  const nextUrl = new URL(route, window.location.origin);
210
+ // Hash-only change: update the route without requesting a new page.
225
211
  if (currentUrl.pathname === nextUrl.pathname && currentUrl.search === nextUrl.search) {
226
- this.routeRequestEnabled = false;
227
- this.route = route;
228
- this.routeRequestEnabled = true;
212
+ this.setRoute(route);
229
213
  return;
230
214
  }
231
- this.routePushState = false;
232
- this.route = route;
233
- this.routePushState = true;
215
+ this.navigate(route, { pushState: false });
234
216
  }
235
217
  //
236
218
  // Scroll.
@@ -239,13 +221,21 @@ export class ApplicationManager extends Component {
239
221
  return this.currentPage.scroll ?? 0;
240
222
  }
241
223
  //
224
+ // Resize.
225
+ //
226
+ onResize() {
227
+ this.fire('resize');
228
+ }
229
+ //
242
230
  // Listeners.
243
231
  //
244
232
  addEventListeners() {
245
233
  window.addEventListener('popstate', this.onPopState);
234
+ window.addEventListener('resize', this.onResize);
246
235
  }
247
236
  removeEventListeners() {
248
237
  window.removeEventListener('popstate', this.onPopState);
238
+ window.removeEventListener('resize', this.onResize);
249
239
  }
250
240
  }
251
241
  export const Application = new ApplicationManager();
@@ -40,5 +40,7 @@ export declare class Component extends EventEmitter {
40
40
  destroyDisposers(): void;
41
41
  addEventListeners(): void;
42
42
  removeEventListeners(): void;
43
+ onResize(): void;
44
+ onScroll(_scroll: number): void;
43
45
  destroy(): void;
44
46
  }
package/dist/Component.js CHANGED
@@ -19,6 +19,14 @@ export class Component extends EventEmitter {
19
19
  this.selector = element;
20
20
  this.selectors = elements;
21
21
  this.id = id;
22
+ if (this.application) {
23
+ this.application.on('scroll', this.onScroll);
24
+ this.application.on('resize', this.onResize);
25
+ this.addDisposer(() => {
26
+ this.application?.off('scroll', this.onScroll);
27
+ this.application?.off('resize', this.onResize);
28
+ });
29
+ }
22
30
  if (this.autoMount) {
23
31
  this.create();
24
32
  }
@@ -98,6 +106,14 @@ export class Component extends EventEmitter {
98
106
  }
99
107
  addEventListeners() { }
100
108
  removeEventListeners() { }
109
+ //
110
+ // Hooks.
111
+ //
112
+ // Called whenever the application page scrolls or resizes. Wired automatically
113
+ // when the component receives an `application`; override in subclasses.
114
+ //
115
+ onResize() { }
116
+ onScroll(_scroll) { }
101
117
  destroy() {
102
118
  this.destroyDisposers();
103
119
  super.destroy();
package/dist/Links.d.ts CHANGED
@@ -8,4 +8,5 @@ export declare class Links extends EventEmitter {
8
8
  addEventListeners(): void;
9
9
  onLinkClick(href: string): void;
10
10
  refresh(): void;
11
+ destroy(): void;
11
12
  }
package/dist/Links.js CHANGED
@@ -1,11 +1,11 @@
1
- import { reaction } from 'mobx';
2
1
  import { EventEmitter } from './EventEmitter.js';
3
2
  import { Link } from './Link.js';
4
3
  export class Links extends EventEmitter {
5
4
  constructor(application) {
6
5
  super();
7
6
  this.application = application;
8
- reaction(() => application.currentPage, () => this.refresh(), { fireImmediately: true });
7
+ this.application.on('page', this.refresh);
8
+ this.refresh();
9
9
  }
10
10
  addEventListeners() {
11
11
  this.links?.forEach((link) => {
@@ -21,10 +21,16 @@ export class Links extends EventEmitter {
21
21
  });
22
22
  }
23
23
  onLinkClick(href) {
24
- const url = new URL(href, window.location.href);
25
- this.application.route = `${url.pathname}${url.search}${url.hash}`;
24
+ this.application.navigate(href);
26
25
  }
27
26
  refresh() {
28
27
  this.addEventListeners();
29
28
  }
29
+ destroy() {
30
+ this.application.off('page', this.refresh);
31
+ this.links?.forEach((link) => {
32
+ link.destroy();
33
+ });
34
+ super.destroy();
35
+ }
30
36
  }
package/dist/Page.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import Lenis from 'lenis';
2
- import { makeObservable, observable } from 'mobx';
3
2
  import Tempus from 'tempus';
4
3
  import { Component } from './Component.js';
5
4
  export class Page extends Component {
@@ -19,12 +18,6 @@ export class Page extends Component {
19
18
  this.datasets = datasets;
20
19
  this.scrollEnabled = scrollEnabled;
21
20
  this.scrollOptions = scrollOptions;
22
- makeObservable(this, {
23
- element: observable,
24
- elements: observable,
25
- components: observable,
26
- scroll: observable,
27
- });
28
21
  }
29
22
  create() {
30
23
  super.create();
@@ -98,15 +91,17 @@ export class Page extends Component {
98
91
  //
99
92
  onResize() {
100
93
  this.lenis?.resize();
94
+ this.application.fire('resize');
101
95
  }
102
96
  onRAF({ time }) {
103
97
  this.lenis?.raf(time);
104
98
  }
105
99
  onScroll(scroll) {
106
100
  this.scroll = scroll;
101
+ this.application.fire('scroll', scroll);
107
102
  }
108
103
  onScrollFallback() {
109
- this.scroll = this.element.scrollTop;
104
+ this.onScroll(this.element.scrollTop);
110
105
  this.emitter.emit('scroll', { scroll: this.scroll });
111
106
  }
112
107
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lisergia/core",
3
- "version": "25.0.0",
3
+ "version": "26.0.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -12,10 +12,9 @@
12
12
  "dev": "tsc --build --watch"
13
13
  },
14
14
  "dependencies": {
15
- "@lisergia/config-tsconfig": "25.0.0",
15
+ "@lisergia/config-tsconfig": "26.0.0",
16
16
  "auto-bind": "^5.0.1",
17
17
  "lenis": "^1.3.26",
18
- "mobx": "^7.0.3",
19
18
  "nanoevents": "^10.0.0",
20
19
  "tempus": "^1.0.0"
21
20
  }