@motifx/core 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -159,6 +159,8 @@ interface TransitionProps {
159
159
  leaveToClass?: string;
160
160
  }
161
161
 
162
+ type TransitionMode = 'concurrent' | 'out-in' | 'in-out';
163
+
162
164
  interface IHtmlElement extends HTMLElement {
163
165
  }
164
166
  interface IElement extends Node {
@@ -197,6 +199,7 @@ interface ComponentBaseOptions<TProps> {
197
199
  out: CSSTransitionInfo;
198
200
  };
199
201
  name: string;
202
+ mode?: TransitionMode;
200
203
  classes?: TransitionProps;
201
204
  activeCssCancel: (() => void) | null;
202
205
  activeCssPhase: 'enter' | 'leave' | null;
@@ -229,9 +232,11 @@ type HtmlElementEvents = {
229
232
  type ElementTypes = Node | Element | HTMLElement | Text | DocumentFragment | Comment | HTMLDivElement;
230
233
  declare class controlAttribute<ElementType extends ElementTypes> implements IAttribute<ComponentBase<ElementType, any>> {
231
234
  private _parent;
232
- private _attrMap;
233
- private _watchers;
235
+ private _attrMapStore?;
236
+ private _watchersStore?;
234
237
  constructor(parent: ComponentBase<ElementType, any>);
238
+ private get _attrMap();
239
+ private get _watchers();
235
240
  /** @deprecated Tek kaynak `_attrMap`; geriye dönük okuma için türetilmiş görünüm. */
236
241
  get attributes(): {
237
242
  name: string;
@@ -311,6 +316,13 @@ interface IDisposeOptions {
311
316
  deep?: boolean;
312
317
  skipLeaveTransition?: boolean;
313
318
  }
319
+ interface SiblingsApi {
320
+ all: () => ComponentBase[] | undefined;
321
+ next: () => ComponentBase | undefined;
322
+ prev: () => ComponentBase | undefined;
323
+ nextAll: () => any;
324
+ prevAll: () => any;
325
+ }
314
326
  declare abstract class ComponentBase<TElement extends ElementType = any, TProps extends object = any> extends Disposable {
315
327
  readonly motif: ComponentMotif<this, TProps>;
316
328
  element: TElement;
@@ -375,16 +387,13 @@ declare abstract class ComponentBase<TElement extends ElementType = any, TProps
375
387
  dispose(options?: IDisposeOptions): Promise<void>;
376
388
  private _disposeCore;
377
389
  disposeAsync(options?: IDisposeOptions): Promise<void>;
378
- private _disposeAsyncCore;
379
390
  using<T>(waitable: Promise<any>, onfulfilled?: ((value: T) => T | PromiseLike<T>) | undefined | null, onrejected?: ((reason: any) => never | PromiseLike<never>) | undefined | null): void;
380
391
  doWork<T>(waitable: Promise<T> | PromiseLike<T>): Promise<T>;
381
- siblings: {
382
- all: () => ComponentBase<any, any>[] | undefined;
383
- next: () => ComponentBase<any, any> | undefined;
384
- prev: () => ComponentBase<any, any> | undefined;
385
- nextAll: () => any;
386
- prevAll: () => any;
387
- };
392
+ private _siblingsApi?;
393
+ private _siblingsSet?;
394
+ get siblings(): SiblingsApi;
395
+ set siblings(value: SiblingsApi);
396
+ private _createSiblingsApi;
388
397
  get serviceProvider(): ServiceProvider | null;
389
398
  getService<T = any>(token: any): T | null;
390
399
  $(selector: string): {
@@ -439,7 +448,7 @@ declare class Frame extends Component {
439
448
  current: ComponentBase | ComponentBase[] | null;
440
449
  isBusy: boolean;
441
450
  constructor(props?: any);
442
- dispose(): Promise<void>;
451
+ dispose(options?: IDisposeOptions): Promise<void>;
443
452
  flush(): Promise<void>;
444
453
  previouspage: any;
445
454
  navigate(page: ComponentBase | ComponentBase[], keepOldControl?: boolean): Promise<void>;
@@ -487,10 +496,12 @@ declare class TransportTo extends Component<any, {
487
496
  private _slotRegisteredListener?;
488
497
  private _slotUnregisteredListener?;
489
498
  private _transported;
499
+ private _countedLive;
490
500
  constructor(props: {
491
501
  name: string;
492
502
  });
493
503
  private _handleSlotChange;
504
+ private _rememberTransported;
494
505
  private _clearChildrenFromSlot;
495
506
  initializeComponent(sender: ComponentBase): void;
496
507
  onDisposing(sender: ComponentBase, e: EventArgs): void;
@@ -638,6 +649,7 @@ declare class ControlCollection {
638
649
  add(...control: ComponentBase[]): ComponentBase[];
639
650
  add(index?: number, ...control: ComponentBase[]): ComponentBase[];
640
651
  insert(index?: number, ...controls: ComponentBase[]): ComponentBase[];
652
+ private _insertOne;
641
653
  remove(control: ComponentBase): void;
642
654
  detach(control: ComponentBase): Promise<void>;
643
655
  silentDetach(control: ComponentBase, unlinkOnly?: boolean): void;
@@ -809,6 +821,9 @@ declare const motifMessages: {
809
821
  MJX121: (compiled: number, runtime: number) => string;
810
822
  MJX122: (hook: string) => string;
811
823
  MJX123: (event: string) => string;
824
+ MJX124: () => string;
825
+ MJX125: (key: string) => string;
826
+ MJX126: () => string;
812
827
  MJX201: () => string;
813
828
  MJX202: (key: unknown, index: number) => string;
814
829
  MJX203: (max: number) => string;
@@ -1355,6 +1370,9 @@ declare class Application {
1355
1370
  detach(component: Component): void;
1356
1371
  appendToMainHost(component: Node): void;
1357
1372
  dispose(): void;
1373
+ useTransitions(options: {
1374
+ mode?: TransitionMode;
1375
+ }): Application;
1358
1376
  use(callback: (ctx: RouteResolveContext, next: () => Promise<void>) => any): Application;
1359
1377
  useGuard(guard: NavigationGuard): Application;
1360
1378
  private urlRoutingModule;
@@ -1413,13 +1431,15 @@ declare function Injectable(options?: {
1413
1431
  declare function FromService<T = any>(token: any): T;
1414
1432
 
1415
1433
  type AsyncOrSync<T> = Promise<T> | T;
1416
- interface Context {
1434
+ interface ResilienceContext {
1417
1435
  [key: string]: any;
1418
1436
  }
1419
- type Action<T> = (ctx?: Context) => AsyncOrSync<T>;
1437
+ type Context = ResilienceContext;
1438
+ type ResilienceAction<T> = (ctx?: ResilienceContext) => AsyncOrSync<T>;
1439
+ type Action<T> = ResilienceAction<T>;
1420
1440
  type ShouldHandlePredicate = (err: any) => boolean;
1421
- declare abstract class Policy {
1422
- abstract execute<T>(action: Action<T>, ctx?: Context): Promise<T>;
1441
+ interface ResiliencePolicy {
1442
+ execute<T>(action: ResilienceAction<T>, ctx?: ResilienceContext): Promise<T>;
1423
1443
  }
1424
1444
  interface RetryOptions {
1425
1445
  retries?: number;
@@ -1453,8 +1473,8 @@ interface FallbackOptions<T> {
1453
1473
  fallback: (err: any, ctx?: Context) => AsyncOrSync<T>;
1454
1474
  shouldHandle?: ShouldHandlePredicate;
1455
1475
  }
1456
- declare function decorate<T>(policy: Policy, fn: Action<T>): (ctx?: Context) => Promise<T>;
1457
- declare class Resilience {
1476
+ declare function decorate<T>(policy: ResiliencePolicy, fn: ResilienceAction<T>): (ctx?: ResilienceContext) => Promise<T>;
1477
+ declare class Resilience implements ResiliencePolicy {
1458
1478
  static get create(): Resilience;
1459
1479
  private resiliences;
1460
1480
  retry: (opts?: RetryOptions) => Resilience;
@@ -1467,4 +1487,4 @@ declare class Resilience {
1467
1487
  }
1468
1488
 
1469
1489
  export { Application, ApplicationBuilder, Component, ComponentBase, ComponentMotif, Computed, ContentBlock, ContentBody, ControlCollection, Dictionary, Disposable, DisposableStore, Emitter, ErrorHandler, FNComponent, FragmentNode, Frame, FromService, Injectable, Lazy, LazyComputed, LinkedList, List, MotifError, NameValuePair, NodeTypes, Query, Resilience, RouterLink, RouterView, ServiceCollection, ServiceProvider, Signal, Transport, TransportTo, Transporter, Virtualization, asyncTracking, clearModel, configureReactivityLeakMonitor, createComputed, createLazyComputed, createSignal, decorate, deepClone, disposableCore, dom, effect, errorHandler, inject, motifCompiled, motifComponent, motifFragment, preProcessing, reactive, read, safeCall, safeCallAsync, safeCallSilent, setUnexpectedErrorHandler, toDisposable, toGetter, untracked, useApplication, useModel, useNavigation };
1470
- export type { AnyEvents, AppLifecycleEventArgs, AppLifecycleState, AsyncTrackingToken, Bind, CSSTransitionInfo, ComponentBaseOptions, CustomParameters, EffectFn, ElementType, Event$1 as Event, EventArgs, Group, HtmlElementEvents, IAttribute, IBaseProp, IClass, IDisposable, IDisposableTracker, IDisposeOptions, IElement, IHtmlElement, IsOptional, LazyOptions, LazyRetryOptions, MotifErrorCode, NavigationDirection, NavigationGuard, NavigationGuardContext, NavigationOptions, OptionalParams, ReadonlySignal, RedirectTarget, ResolveResult, RouteControl, RouteInfo, RouteItem, RouteItemBase, RouteRedirect, RouteResolveContext, Router, RouterClassingSettings, RouterEvents, RouterNavigatedEventArgs, RouterOptions, RouterValidateEventArgs, RouterViewProps, ScrollMemoryOptions, ServiceDescriptor, ServiceLifetime, StackEntryInfo, StackOptions, StackSwipeBackOptions, StackTransitionContext, TransitionProps, TransportOptions, VirtualizationDataRequest, VirtualizationDataResponse, VirtualizationProps, VirtualizationState };
1490
+ export type { AnyEvents, AppLifecycleEventArgs, AppLifecycleState, AsyncTrackingToken, Bind, BulkheadOptions, CSSTransitionInfo, CircuitBreakerOptions, CircuitState, ComponentBaseOptions, CustomParameters, EffectFn, ElementType, Event$1 as Event, EventArgs, FallbackOptions, Group, HtmlElementEvents, IAttribute, IBaseProp, IClass, IDisposable, IDisposableTracker, IDisposeOptions, IElement, IHtmlElement, IsOptional, LazyOptions, LazyRetryOptions, MotifErrorCode, NavigationDirection, NavigationGuard, NavigationGuardContext, NavigationOptions, OptionalParams, RateLimiterOptions, ReadonlySignal, RedirectTarget, ResilienceAction, ResilienceContext, ResiliencePolicy, ResolveResult, RetryOptions, RouteControl, RouteInfo, RouteItem, RouteItemBase, RouteRedirect, RouteResolveContext, Router, RouterClassingSettings, RouterEvents, RouterNavigatedEventArgs, RouterOptions, RouterValidateEventArgs, RouterViewProps, ScrollMemoryOptions, ServiceDescriptor, ServiceLifetime, StackEntryInfo, StackOptions, StackSwipeBackOptions, StackTransitionContext, TimeoutOptions, TransitionMode, TransitionProps, TransportOptions, VirtualizationDataRequest, VirtualizationDataResponse, VirtualizationProps, VirtualizationState };
package/dist/index.esm.js CHANGED
@@ -1,7 +1,5 @@
1
- import { C as Component, A as Application, f as findAppendableComponent, a as ComponentBase, n as notifyDeactivated, b as autoRegistry } from './chunks/core-DxINgP83.esm.js';
2
- export { c as ApplicationBuilder, d as ComponentMotif, e as ControlCollection, D as Disposable, h as DisposableStore, E as Emitter, F as FNComponent, i as FragmentNode, j as Frame, L as Lazy, R as RouterView, S as ServiceCollection, p as ServiceProvider, g as disposableCore, k as inject, m as motifCompiled, l as motifComponent, o as motifFragment, t as toDisposable, u as useApplication, q as useNavigation } from './chunks/core-DxINgP83.esm.js';
3
- import { m as motifError, r as reportWarning, u as untracked, e as effect, a as reportError, M as MotifError, f as formatMotifMessage } from './chunks/core-BDvHkZLQ.esm.js';
4
- export { C as Computed, E as ErrorHandler, L as LazyComputed, n as LinkedList, N as NodeTypes, S as Signal, b as asyncTracking, c as clearModel, d as configureReactivityLeakMonitor, g as createComputed, h as createLazyComputed, i as createSignal, j as deepClone, k as dom, l as errorHandler, o as reactive, s as safeCall, p as safeCallAsync, q as safeCallSilent, t as setUnexpectedErrorHandler, v as useModel } from './chunks/core-BDvHkZLQ.esm.js';
1
+ import { m as motifError, C as Component, r as reportWarning, A as Application, c as contentBlocks, f as findAppendableComponent, u as untracked, e as effect, a as reportError, b as ComponentBase, n as notifyDeactivated, d as autoRegistry, M as MotifError, g as formatMotifMessage } from './chunks/core-BGdhUeHu.esm.js';
2
+ export { h as ApplicationBuilder, k as ComponentMotif, l as Computed, p as ControlCollection, D as Disposable, x as DisposableStore, E as Emitter, B as ErrorHandler, F as FNComponent, G as FragmentNode, H as Frame, L as Lazy, J as LazyComputed, K as LinkedList, Q as NodeTypes, S as RouterView, W as ServiceCollection, X as ServiceProvider, Z as Signal, i as asyncTracking, j as clearModel, o as configureReactivityLeakMonitor, q as createComputed, s as createLazyComputed, t as createSignal, v as deepClone, w as disposableCore, y as dom, z as errorHandler, I as inject, N as motifCompiled, O as motifComponent, P as motifFragment, R as reactive, T as safeCall, U as safeCallAsync, V as safeCallSilent, Y as setUnexpectedErrorHandler, _ as toDisposable, $ as useApplication, a0 as useModel, a1 as useNavigation } from './chunks/core-BGdhUeHu.esm.js';
5
3
 
6
4
  class NameValuePair {
7
5
  Key;
@@ -56,10 +54,11 @@ class List {
56
54
  }
57
55
  ;
58
56
  remove(item) {
57
+ const index = this.__list.indexOf(item);
58
+ if (index === -1)
59
+ return [];
59
60
  this._map.delete(item);
60
- this.__list.splice(this.__list.indexOf(item), 1);
61
- item = null;
62
- return [];
61
+ return this.__list.splice(index, 1);
63
62
  }
64
63
  ;
65
64
  indexOf(item) {
@@ -86,7 +85,7 @@ class List {
86
85
  this.__list?.forEach(callbackfn);
87
86
  }
88
87
  ReverseClone() {
89
- return this.__list.reverse();
88
+ return this.__list.slice().reverse();
90
89
  }
91
90
  filter(callbackfn) {
92
91
  return this.__list.filter(callbackfn);
@@ -113,8 +112,7 @@ class Dictionary {
113
112
  }
114
113
  OnItemAdded;
115
114
  removeIndex(index) {
116
- var i = this.__values.removeIndex(index - 1);
117
- return i;
115
+ return this.__values.removeIndex(index);
118
116
  }
119
117
  ;
120
118
  remove(Key) {
@@ -244,20 +242,16 @@ class ContentBlock extends Component {
244
242
  // } else {
245
243
  // var cb = ContentBodyCollectionHandable.get(props.target);
246
244
  // if (cb) {
247
- this.controls.onAdd = (control) => {
248
- var cb = ContentBodyCollectionHandable.get(this.props.target);
249
- if (cb) {
250
- control.motif.options["ownerContentBlock"] = this;
251
- cb.controls.add(control);
252
- }
253
- };
254
- this.controls.onAddBeforeBuild = (control) => {
245
+ const forward = (control) => {
246
+ this.motif.trigger('controladded', { control });
255
247
  var cb = ContentBodyCollectionHandable.get(this.props.target);
256
248
  if (cb) {
257
249
  control.motif.options["ownerContentBlock"] = this;
258
250
  cb.controls.add(control);
259
251
  }
260
252
  };
253
+ this.controls.onAdd = forward;
254
+ this.controls.onAddBeforeBuild = forward;
261
255
  if (this.childs) {
262
256
  this.controls.add(...this.childs);
263
257
  }
@@ -301,7 +295,9 @@ class ContentBody extends Component {
301
295
  this.context.fire(changeBodyCollectionHandler);
302
296
  }
303
297
  ondisposing(sender) {
304
- ContentBodyCollectionHandable.delete(this.props.name);
298
+ if (ContentBodyCollectionHandable.get(this.props.name) === this) {
299
+ ContentBodyCollectionHandable.delete(this.props.name);
300
+ }
305
301
  }
306
302
  }
307
303
 
@@ -333,7 +329,7 @@ class Transport extends Component {
333
329
  initializeComponent(sender) {
334
330
  TransportRegistry.registerSlot(this.props.name, this);
335
331
  this.onDisposing = () => {
336
- (this.controls.items || []).forEach(child => {
332
+ [...(this.controls.items || [])].forEach(child => {
337
333
  this.controls.remove(child);
338
334
  child.dispose?.();
339
335
  });
@@ -341,7 +337,7 @@ class Transport extends Component {
341
337
  };
342
338
  }
343
339
  clearSlot() {
344
- (this.controls.items || []).forEach(child => {
340
+ [...(this.controls.items || [])].forEach(child => {
345
341
  this.controls.remove(child);
346
342
  child.dispose?.();
347
343
  });
@@ -355,7 +351,7 @@ class Transporter {
355
351
  if (child.parent === newParent && newParent.controls.items.includes(child))
356
352
  return;
357
353
  if (child.parent && child.parent !== newParent) {
358
- child.parent.controls.remove(child);
354
+ child.parent.controls.silentDetach(child, true);
359
355
  }
360
356
  if (options.owner) {
361
357
  child.motif.options.ownerTransporter = options.owner;
@@ -418,8 +414,11 @@ class TransportTo extends Component {
418
414
  _slotRegisteredListener;
419
415
  _slotUnregisteredListener;
420
416
  _transported = [];
417
+ _countedLive = false;
421
418
  constructor(props) {
422
419
  super('div', props);
420
+ contentBlocks.live++;
421
+ this._countedLive = true;
423
422
  }
424
423
  _handleSlotChange = (eventArgs) => {
425
424
  if (eventArgs.name === this.props.name) {
@@ -429,9 +428,17 @@ class TransportTo extends Component {
429
428
  }
430
429
  const all = [...(this.childs || []), ...this.controls.items];
431
430
  Transporter.transportMany(all, slot);
432
- this._transported = all;
431
+ this._rememberTransported(all);
433
432
  }
434
433
  };
434
+ _rememberTransported(children) {
435
+ const kept = this._transported.filter(c => !c.isDisposed);
436
+ for (const child of children) {
437
+ if (!kept.includes(child))
438
+ kept.push(child);
439
+ }
440
+ this._transported = kept;
441
+ }
435
442
  _clearChildrenFromSlot = (slot) => {
436
443
  (this.childs || []).forEach(child => {
437
444
  slot.controls.remove(child);
@@ -450,7 +457,7 @@ class TransportTo extends Component {
450
457
  }
451
458
  const all = [...(this.childs || []), ...this.controls.items];
452
459
  Transporter.transportMany(all, slot);
453
- this._transported = all;
460
+ this._rememberTransported(all);
454
461
  }
455
462
  this._slotRegisteredListener = Application.main.on(SLOT_REGISTERED_EVENT, this._handleSlotChange);
456
463
  this._slotUnregisteredListener = Application.main.on(SLOT_UNREGISTERED_EVENT, (eventArgs) => {
@@ -459,9 +466,11 @@ class TransportTo extends Component {
459
466
  }
460
467
  });
461
468
  this._onAddRef = (child) => {
469
+ this.motif.trigger('controladded', { control: child });
462
470
  const currentSlot = TransportRegistry.getSlot(this.props.name);
463
471
  if (currentSlot) {
464
472
  Transporter.transport(child, currentSlot);
473
+ this._rememberTransported([child]);
465
474
  }
466
475
  };
467
476
  this._onRemoveRef = (child) => {
@@ -469,17 +478,20 @@ class TransportTo extends Component {
469
478
  if (currentSlot) {
470
479
  currentSlot.controls.remove(child);
471
480
  }
481
+ this._transported = this._transported.filter(c => c !== child);
472
482
  };
473
483
  this.controls.onAdd = this._onAddRef;
474
484
  this.controls.onRemove = this._onRemoveRef;
475
485
  }
476
486
  onDisposing(sender, e) {
487
+ if (this._countedLive) {
488
+ this._countedLive = false;
489
+ contentBlocks.live--;
490
+ }
477
491
  const currentSlot = TransportRegistry.getSlot(this.props.name);
478
- if (currentSlot) {
479
- (this._transported || []).forEach(child => {
480
- currentSlot.controls.remove(child);
481
- child.dispose();
482
- });
492
+ for (const child of this._transported || []) {
493
+ currentSlot?.controls.remove(child);
494
+ child.dispose();
483
495
  }
484
496
  if (this._slotRegisteredListener) {
485
497
  Application.main.off(SLOT_REGISTERED_EVENT, this._handleSlotChange);
@@ -1343,7 +1355,7 @@ class RateLimiterPolicy extends Policy {
1343
1355
  super();
1344
1356
  this.tokensPerInterval = opts.tokensPerInterval ?? 1;
1345
1357
  this.intervalMs = opts.intervalMs ?? 1000;
1346
- this.capacity = opts.capacity ?? 1000;
1358
+ this.capacity = opts.capacity ?? this.tokensPerInterval;
1347
1359
  this.tokens = this.capacity;
1348
1360
  this.lastRefill = Date.now();
1349
1361
  }