@motifx/core 1.1.0 → 1.2.0-rc.1

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.
@@ -282,9 +282,17 @@ const motifMessages = {
282
282
  MJX121: (compiled, runtime) => `This code was compiled for compiler contract ${compiled}, but the @motifx/core runtime implements contract ${runtime}. Install matching versions of @motifx/compiler and @motifx/core, and rebuild packages that ship compiled JSX.`,
283
283
  MJX122: (hook) => `The component ${hook} hook threw.`,
284
284
  MJX123: (event) => `The '${event}' event handler threw.`,
285
- MJX124: () => `A spread object on a DOM tag cannot set innerHTML; the key was ignored. Use x-html for trusted HTML.`,
285
+ MJX124: (key) => `A spread object on a DOM tag cannot set ${key}; the key was ignored. Write it on the tag, or use x-html, for HTML you trust.`,
286
286
  MJX125: (key) => `A spread object on a DOM tag cannot set a javascript: URL on '${key}'; the value was ignored. Write the attribute on the tag if it is intended.`,
287
287
  MJX126: () => `Lazy: loading the component failed and no Fallbackview is set; the host was cleared.`,
288
+ MJX127: (got) => got === 'module'
289
+ ? `The loaded module has no default export. Export the component as default, or map it: () => import('./X').then(m => m.X).`
290
+ : `The loaded value is not a component (got ${got}). Return a component class, a function component, an Options API factory or a component instance.`,
291
+ MJX128: (cls, member, how) => how === 'method'
292
+ ? `${cls} overrides ${member} without calling super.${member}; MotifJS relies on this ComponentBase member. Rename your member, or call super.${member} in the override.`
293
+ : how === 'field'
294
+ ? `${cls} defines '${member}' as an instance field, which hides the ComponentBase member MotifJS relies on. Rename your field.`
295
+ : `${cls} replaces '${member}', which MotifJS created for the component (a class field or an assignment with that name). Rename your member.`,
288
296
  MJX201: () => `ListBinding: renderFn must return a component instance, a component class, or a factory function.`,
289
297
  MJX202: (key, index) => `ListBinding: duplicate key "${String(key)}" at index ${index}. Rows are matched by the item object, not by key, so rendering is not affected; keep keys unique so they identify items.`,
290
298
  MJX203: (max) => `An effect ran ${max} times in one flush and keeps triggering itself; it is skipped for the rest of this flush. It probably writes a value it reads (for example state.n++). Wrap the write in untracked(...).`,
@@ -1651,6 +1659,9 @@ function lazyBindMethods(proto, names) {
1651
1659
  }
1652
1660
  }
1653
1661
 
1662
+ function resolveValue(value) {
1663
+ return typeof value === 'function' ? resolveValue(value()) : value;
1664
+ }
1654
1665
  function isWritablePathKey(target, key) {
1655
1666
  if (key === '__proto__')
1656
1667
  return false;
@@ -1734,7 +1745,7 @@ class BindingCollection {
1734
1745
  return binding;
1735
1746
  }
1736
1747
  display(predicate) {
1737
- const binding = new Binding(this._component, 'isWait', () => !predicate());
1748
+ const binding = new Binding(this._component, 'isWait', () => !resolveValue(predicate()));
1738
1749
  this._items.push(binding);
1739
1750
  if (this._component.isBuilt) {
1740
1751
  binding.activate();
@@ -4452,6 +4463,61 @@ function hasLifecycleHook(component, hook, listName, lowerName, legacyProp) {
4452
4463
  return true;
4453
4464
  return component._base.emiters.hasListeners(lowerName);
4454
4465
  }
4466
+ const RESERVED_METHODS = ['build', 'setState', 'reState', 'setText', 'style', 'dispose', 'disposeAsync', 'using', 'doWork', 'getService', '$', 'useModel', 'context', 'siblings', 'serviceProvider', 'isWait'];
4467
+ const checkedComponentClasses = new WeakSet();
4468
+ function callsSuper(fn, name) {
4469
+ if (typeof fn !== 'function')
4470
+ return false;
4471
+ const escaped = name.replace(/\$/g, '\\$');
4472
+ return new RegExp(`\\bsuper\\s*(\\.\\s*${escaped}(?![\\w$])|\\[)`).test(Function.prototype.toString.call(fn));
4473
+ }
4474
+ function reservedMemberProblems(c) {
4475
+ const problems = [];
4476
+ const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
4477
+ for (const name of RESERVED_METHODS) {
4478
+ if (own(c, name)) {
4479
+ problems.push([name, 'field']);
4480
+ continue;
4481
+ }
4482
+ for (let p = Object.getPrototypeOf(c); p && p !== ComponentBase.prototype; p = Object.getPrototypeOf(p)) {
4483
+ const d = Object.getOwnPropertyDescriptor(p, name);
4484
+ if (!d)
4485
+ continue;
4486
+ const fns = 'value' in d ? [d.value] : [d.get, d.set].filter(Boolean);
4487
+ if (!fns.some(fn => callsSuper(fn, name)))
4488
+ problems.push([name, 'method']);
4489
+ break;
4490
+ }
4491
+ }
4492
+ const anyC = c;
4493
+ if (!(anyC.motif instanceof ComponentMotif))
4494
+ problems.push(['motif', 'replaced']);
4495
+ if (!(anyC.controls instanceof ControlCollection))
4496
+ problems.push(['controls', 'replaced']);
4497
+ if (!(anyC.class instanceof controlClass))
4498
+ problems.push(['class', 'replaced']);
4499
+ if (!(anyC.attr instanceof controlAttribute))
4500
+ problems.push(['attr', 'replaced']);
4501
+ if (!(anyC.bindings instanceof BindingCollection))
4502
+ problems.push(['bindings', 'replaced']);
4503
+ if (anyC.element != null && typeof Node !== 'undefined' && !(anyC.element instanceof Node))
4504
+ problems.push(['element', 'replaced']);
4505
+ if (anyC.parent != null && !(anyC.parent instanceof ComponentBase))
4506
+ problems.push(['parent', 'replaced']);
4507
+ return problems;
4508
+ }
4509
+ function checkReservedMembers(c) {
4510
+ if (!isDevLike())
4511
+ return;
4512
+ const ctor = c?.constructor;
4513
+ if (typeof ctor !== 'function' || checkedComponentClasses.has(ctor))
4514
+ return;
4515
+ checkedComponentClasses.add(ctor);
4516
+ const name = ctor.name || 'An anonymous component class';
4517
+ for (const [member, how] of reservedMemberProblems(c)) {
4518
+ reportWarning('MJX128', [name, member, how]);
4519
+ }
4520
+ }
4455
4521
  const ComponentHelper = {
4456
4522
  callInitializeComponent(component) {
4457
4523
  const sender = component;
@@ -5022,7 +5088,7 @@ function removeComponentDom(c, node, alsoPlaceholder) {
5022
5088
  }
5023
5089
  function detachDomWithAnimation(c) {
5024
5090
  const node = c.element;
5025
- if (!node)
5091
+ if (!node || c._keepElementOnDispose === true)
5026
5092
  return;
5027
5093
  const opts = c.motif.options;
5028
5094
  const t = opts?.[TRANSITION_SLOT];
@@ -5052,7 +5118,7 @@ function detachDomWithAnimation(c) {
5052
5118
  }
5053
5119
  async function detachDomWithAnimationAsync(c) {
5054
5120
  const node = c.element;
5055
- if (!node)
5121
+ if (!node || c._keepElementOnDispose === true)
5056
5122
  return;
5057
5123
  const opts = c.motif.options;
5058
5124
  const t = opts?.[TRANSITION_SLOT];
@@ -5215,8 +5281,24 @@ function subtreeDisposesSync(c, root) {
5215
5281
  }
5216
5282
  return true;
5217
5283
  }
5284
+ const teardownApplications = new WeakMap();
5285
+ function owningApplication(c) {
5286
+ for (let p = c; p; p = p.parent) {
5287
+ if (p.application)
5288
+ return p.application;
5289
+ const recorded = teardownApplications.get(p);
5290
+ if (recorded)
5291
+ return recorded;
5292
+ }
5293
+ return Application.main ?? null;
5294
+ }
5218
5295
  function disposePrefix(c, options, asChild) {
5219
5296
  const ctx = asChild ? 'disposeAsync' : 'dispose';
5297
+ if (Application._disposingCount > 0) {
5298
+ const app = owningApplication(c);
5299
+ if (app && app.state === 'disposing')
5300
+ teardownApplications.set(c, app);
5301
+ }
5220
5302
  if (!asChild && options?.skipLeaveTransition) {
5221
5303
  c.motif.options.transition.skipNextLeave = true;
5222
5304
  }
@@ -5600,7 +5682,7 @@ class ComponentBase extends Disposable {
5600
5682
  _scopedContext;
5601
5683
  get context() {
5602
5684
  const parentCtx = this.parent?.context;
5603
- const app = parentCtx?.[RAW_APPLICATION] ?? parentCtx ?? Application.main;
5685
+ const app = parentCtx?.[RAW_APPLICATION] ?? parentCtx ?? teardownApplications.get(this) ?? Application.main;
5604
5686
  if (!app) {
5605
5687
  return app;
5606
5688
  }
@@ -5622,6 +5704,7 @@ class ComponentBase extends Disposable {
5622
5704
  return () => { this._disposables.detach(d); off(); };
5623
5705
  }
5624
5706
  build(building = true) {
5707
+ checkReservedMembers(this);
5625
5708
  ComponentHelper.callConfigured(this);
5626
5709
  this._base._activatePreBindings();
5627
5710
  if (this.isDisposed || !this.element || this.isWait) {
@@ -6096,7 +6179,7 @@ class ComponentBase extends Disposable {
6096
6179
  if (mods.includes("stop")) {
6097
6180
  stop();
6098
6181
  }
6099
- if (res === false || (res && res.cancel === true)) {
6182
+ if (res && res.cancel === true) {
6100
6183
  prevent();
6101
6184
  stop();
6102
6185
  }
@@ -6303,6 +6386,9 @@ class ComponentBase extends Disposable {
6303
6386
  const p = c.provider;
6304
6387
  if (p)
6305
6388
  return p;
6389
+ const recorded = teardownApplications.get(c);
6390
+ if (recorded)
6391
+ return recorded.state === 'disposed' ? null : recorded.provider;
6306
6392
  c = c.parent;
6307
6393
  }
6308
6394
  try {
@@ -6647,6 +6733,7 @@ const PLAIN_ELEMENT_SKIP = new Set([
6647
6733
  'ref', 'key', 'indexkey', 'inject', 'options', 'props', 'settings', 'isSvg',
6648
6734
  'childs', 'initializeComponent', 'runover', 'transition', 'preconfig', 'nodes', 'onElementCreating'
6649
6735
  ]);
6736
+ const SPREAD_HTML_KEYS = new Set(['innerhtml', 'srcdoc']);
6650
6737
  const SPREAD_URL_ATTRIBUTES = new Set(['href', 'src', 'action', 'formaction', 'xlink:href']);
6651
6738
  const JAVASCRIPT_URL = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;
6652
6739
  function isJavascriptUrl(value) {
@@ -6695,11 +6782,12 @@ function applyPlainElementProps(props, component) {
6695
6782
  }
6696
6783
  if (typeof v === 'function' && v.length > 0)
6697
6784
  continue;
6698
- if (key === 'innerHTML') {
6699
- reportWarning('MJX124', []);
6785
+ const lowerKey = key.toLowerCase();
6786
+ if (SPREAD_HTML_KEYS.has(lowerKey)) {
6787
+ reportWarning('MJX124', [key]);
6700
6788
  continue;
6701
6789
  }
6702
- if (SPREAD_URL_ATTRIBUTES.has(key.toLowerCase())) {
6790
+ if (SPREAD_URL_ATTRIBUTES.has(lowerKey)) {
6703
6791
  if (typeof v === 'function') {
6704
6792
  v = guardSpreadUrl(key, v);
6705
6793
  }
@@ -6888,6 +6976,9 @@ class Component extends ComponentBase {
6888
6976
  }
6889
6977
  if (elementOrParams instanceof Function) {
6890
6978
  elementOrParams = resolveComponent(elementOrParams, options);
6979
+ if (isOptionsObject(elementOrParams)) {
6980
+ return materializeOptionsObject(elementOrParams, options);
6981
+ }
6891
6982
  }
6892
6983
  if (Array.isArray(elementOrParams)) {
6893
6984
  const letter = CreateFragment();
@@ -7077,6 +7168,40 @@ function motifComponent(element, props) {
7077
7168
  }
7078
7169
  return new Component(element, props);
7079
7170
  }
7171
+ function isOptionsObject(value) {
7172
+ return typeof value == "object" && value !== null && !(value instanceof ComponentBase) && 'el' in value;
7173
+ }
7174
+ function unwrapModule(result) {
7175
+ if (result && typeof result === "object" && !(result instanceof ComponentBase) && result.default != null) {
7176
+ return result.default;
7177
+ }
7178
+ return result;
7179
+ }
7180
+ function describeLoaded(value) {
7181
+ if (value === null)
7182
+ return 'null';
7183
+ if (Array.isArray(value))
7184
+ return 'array';
7185
+ if (typeof value === "object" && (Object.prototype.toString.call(value) === '[object Module]' || value.__esModule))
7186
+ return 'module';
7187
+ return typeof value;
7188
+ }
7189
+ function assertLoadedComponent(value) {
7190
+ if (value === null || typeof value !== "object")
7191
+ return;
7192
+ if (value instanceof ComponentBase || Array.isArray(value) || value instanceof Node)
7193
+ return;
7194
+ if (typeof value.then === "function")
7195
+ return;
7196
+ throw motifError('MJX127', describeLoaded(value));
7197
+ }
7198
+ function resolveToComponent(input, props) {
7199
+ const resolved = resolveComponent(input, props);
7200
+ if (isOptionsObject(resolved)) {
7201
+ return materializeOptionsObject(resolved, undefined);
7202
+ }
7203
+ return resolved;
7204
+ }
7080
7205
  function materializeOptionsObject(spec, props) {
7081
7206
  const result = motifComponent(spec.el, props);
7082
7207
  Object.getOwnPropertyNames(spec).forEach(key => {
@@ -7311,6 +7436,7 @@ class ControlCollection {
7311
7436
  if (typeof control == 'string' || typeof control == 'number' || typeof control == 'boolean' || typeof control == 'bigint') {
7312
7437
  control = new Component(dom.createTextNode(control), null);
7313
7438
  }
7439
+ checkReservedMembers(control);
7314
7440
  if (control.parent) {
7315
7441
  control.parent.controls.detach(control);
7316
7442
  }
@@ -7682,10 +7808,7 @@ function normalizeRetry(retry) {
7682
7808
  return { count: 0, delayMs: 0, whenOnline: false };
7683
7809
  }
7684
7810
  function defaultMapper(result) {
7685
- if (result && typeof result === "object" && typeof result.default === "function") {
7686
- return result.default;
7687
- }
7688
- return result;
7811
+ return unwrapModule(result);
7689
7812
  }
7690
7813
  function Lazy(props) {
7691
7814
  const opts = (props && props.options) || {};
@@ -7714,7 +7837,7 @@ function Lazy(props) {
7714
7837
  catch { }
7715
7838
  const initial = opts.Placeholderview ?? opts.Loaderview;
7716
7839
  if (initial != null) {
7717
- frame.navigate(resolveComponent(initial));
7840
+ frame.navigate(resolveToComponent(initial));
7718
7841
  }
7719
7842
  const attemptLoad = () => {
7720
7843
  if (!opts.timeoutMs && !opts.signal) {
@@ -7840,6 +7963,36 @@ function Lazy(props) {
7840
7963
  };
7841
7964
  const loadPromise = retry.count > 0 ? loadWithRetry() : attemptLoad();
7842
7965
  const startTs = Date.now();
7966
+ const fail = (err) => {
7967
+ try {
7968
+ opts.onError?.(err);
7969
+ }
7970
+ catch { /* swallow */ }
7971
+ if (opts.signal?.aborted)
7972
+ return;
7973
+ if (opts.Fallbackview != null) {
7974
+ frame.navigate(resolveToComponent(opts.Fallbackview));
7975
+ }
7976
+ else {
7977
+ reportError('MJX126', err);
7978
+ try {
7979
+ frame.motif.clear().catch(() => { });
7980
+ }
7981
+ catch { }
7982
+ }
7983
+ };
7984
+ const place = (target) => {
7985
+ let component;
7986
+ try {
7987
+ component = resolveToComponent(target);
7988
+ assertLoadedComponent(component);
7989
+ }
7990
+ catch (err) {
7991
+ fail(err);
7992
+ return;
7993
+ }
7994
+ frame.navigate(component);
7995
+ };
7843
7996
  loadPromise
7844
7997
  .then((result) => {
7845
7998
  if (opts.signal?.aborted) {
@@ -7853,7 +8006,7 @@ function Lazy(props) {
7853
8006
  if (remaining > 0) {
7854
8007
  const id = trackTimer(setTimeout(() => {
7855
8008
  if (!opts.signal?.aborted) {
7856
- frame.navigate(resolveComponent(target));
8009
+ place(target);
7857
8010
  }
7858
8011
  }, remaining));
7859
8012
  if (opts.signal) {
@@ -7869,27 +8022,10 @@ function Lazy(props) {
7869
8022
  }
7870
8023
  }
7871
8024
  else {
7872
- frame.navigate(resolveComponent(target));
8025
+ place(target);
7873
8026
  }
7874
8027
  })
7875
- .catch((err) => {
7876
- try {
7877
- opts.onError?.(err);
7878
- }
7879
- catch { /* swallow */ }
7880
- if (opts.signal?.aborted)
7881
- return;
7882
- if (opts.Fallbackview != null) {
7883
- frame.navigate(resolveComponent(opts.Fallbackview));
7884
- }
7885
- else {
7886
- reportError('MJX126', err);
7887
- try {
7888
- frame.motif.clear().catch(() => { });
7889
- }
7890
- catch { }
7891
- }
7892
- });
8028
+ .catch(fail);
7893
8029
  return frame;
7894
8030
  }
7895
8031
 
@@ -8263,6 +8399,144 @@ class ArrayMethods {
8263
8399
  }
8264
8400
  }
8265
8401
 
8402
+ const KEYS_KEY = Symbol('');
8403
+ function changed(target, key, keysChanged) {
8404
+ trigger(target, key);
8405
+ trigger(target, ITERATE_KEY);
8406
+ if (keysChanged)
8407
+ trigger(target, KEYS_KEY);
8408
+ }
8409
+ function lookupKey(target, key) {
8410
+ return target.has(key) ? key : getRaw(key);
8411
+ }
8412
+ function wrapIterator(source, convert) {
8413
+ return {
8414
+ next() {
8415
+ const step = source.next();
8416
+ return step.done ? step : { value: convert(step.value), done: false };
8417
+ },
8418
+ [Symbol.iterator]() {
8419
+ return this;
8420
+ },
8421
+ };
8422
+ }
8423
+ function createCollectionMethods(engine) {
8424
+ const wrap = (value) => isObject(value) ? engine.reactive(value) : value;
8425
+ const wrapEntry = (target) => target instanceof Map
8426
+ ? ([key, value]) => [key, wrap(value)]
8427
+ : ([value]) => { const item = wrap(value); return [item, item]; };
8428
+ return {
8429
+ get(key) {
8430
+ const target = getRaw(this);
8431
+ const found = lookupKey(target, key);
8432
+ track(target, found);
8433
+ return wrap(target.get(found));
8434
+ },
8435
+ has(key) {
8436
+ const target = getRaw(this);
8437
+ const found = lookupKey(target, key);
8438
+ track(target, found);
8439
+ return target.has(found);
8440
+ },
8441
+ set(key, value) {
8442
+ const target = getRaw(this);
8443
+ const stored = lookupKey(target, key);
8444
+ const raw = getRaw(value);
8445
+ const existed = target.has(stored);
8446
+ const previous = target.get(stored);
8447
+ target.set(stored, raw);
8448
+ if (!existed)
8449
+ changed(target, stored, true);
8450
+ else if (!Object.is(previous, raw))
8451
+ changed(target, stored, false);
8452
+ return this;
8453
+ },
8454
+ add(value) {
8455
+ const target = getRaw(this);
8456
+ const stored = lookupKey(target, value);
8457
+ if (!target.has(stored)) {
8458
+ target.add(stored);
8459
+ changed(target, stored, true);
8460
+ }
8461
+ return this;
8462
+ },
8463
+ delete(key) {
8464
+ const target = getRaw(this);
8465
+ const found = lookupKey(target, key);
8466
+ const removed = target.delete(found);
8467
+ if (removed)
8468
+ changed(target, found, true);
8469
+ return removed;
8470
+ },
8471
+ clear() {
8472
+ const target = getRaw(this);
8473
+ if (target.size === 0)
8474
+ return;
8475
+ const keys = Array.from(target.keys());
8476
+ target.clear();
8477
+ for (const key of keys)
8478
+ trigger(target, key);
8479
+ trigger(target, ITERATE_KEY);
8480
+ trigger(target, KEYS_KEY);
8481
+ },
8482
+ forEach(callback, thisArg) {
8483
+ const target = getRaw(this);
8484
+ track(target, ITERATE_KEY);
8485
+ const owner = this;
8486
+ const isMap = target instanceof Map;
8487
+ target.forEach((value, key) => {
8488
+ const item = wrap(value);
8489
+ callback.call(thisArg, item, isMap ? key : item, owner);
8490
+ });
8491
+ },
8492
+ keys() {
8493
+ const target = getRaw(this);
8494
+ if (target instanceof Map) {
8495
+ track(target, KEYS_KEY);
8496
+ return target.keys();
8497
+ }
8498
+ track(target, ITERATE_KEY);
8499
+ return wrapIterator(target.keys(), wrap);
8500
+ },
8501
+ values() {
8502
+ const target = getRaw(this);
8503
+ track(target, ITERATE_KEY);
8504
+ return wrapIterator(target.values(), wrap);
8505
+ },
8506
+ entries() {
8507
+ const target = getRaw(this);
8508
+ track(target, ITERATE_KEY);
8509
+ return wrapIterator(target.entries(), wrapEntry(target));
8510
+ },
8511
+ [Symbol.iterator]() {
8512
+ const target = getRaw(this);
8513
+ track(target, ITERATE_KEY);
8514
+ return target instanceof Map
8515
+ ? wrapIterator(target.entries(), wrapEntry(target))
8516
+ : wrapIterator(target.values(), wrap);
8517
+ },
8518
+ };
8519
+ }
8520
+ function createCollectionHandler(engine) {
8521
+ const methods = createCollectionMethods(engine);
8522
+ return {
8523
+ get(target, key, receiver) {
8524
+ const meta = readMeta(engine, target, key, receiver);
8525
+ if (meta !== NOT_META)
8526
+ return meta;
8527
+ if (key === 'size') {
8528
+ track(target, ITERATE_KEY);
8529
+ return target.size;
8530
+ }
8531
+ if ((typeof key === 'string' || key === Symbol.iterator) && hasOwn(methods, key) && key in target) {
8532
+ return methods[key];
8533
+ }
8534
+ const value = Reflect.get(target, key, target);
8535
+ return typeof value === 'function' ? value.bind(target) : value;
8536
+ },
8537
+ };
8538
+ }
8539
+
8266
8540
  const ReactiveEngineMapper = new WeakSet();
8267
8541
  const AllreactiveMap = new WeakMap();
8268
8542
  function armgetter() { return AllreactiveMap; }
@@ -8301,12 +8575,13 @@ class ReactiveEngine {
8301
8575
  deleteProperty: createDelete(),
8302
8576
  ownKeys: createOwn()
8303
8577
  };
8578
+ collectionHandler = createCollectionHandler(this);
8304
8579
  reactive(model) {
8305
8580
  if (!isObject(model)) {
8306
8581
  model = { value: model };
8307
8582
  }
8308
8583
  const targetType = getTargetType(model);
8309
- if (targetType === 0 /* TargetType.SYSTEM */ || targetType === 2 /* TargetType.COLLECTION */ || 0 /* TargetType.INVALID */) {
8584
+ if (targetType === 0 /* TargetType.SYSTEM */ || 0 /* TargetType.INVALID */) {
8310
8585
  return model;
8311
8586
  }
8312
8587
  let existingProxy = AllreactiveMap.get(model);
@@ -8318,7 +8593,12 @@ class ReactiveEngine {
8318
8593
  return existingProxy;
8319
8594
  }
8320
8595
  // if (targetType === TargetType.INVALID) {
8321
- if (Array.isArray(model)) {
8596
+ if (targetType === 2 /* TargetType.COLLECTION */) {
8597
+ var proxy = new Proxy(model, this.collectionHandler);
8598
+ AllreactiveMap.set(model, proxy);
8599
+ return proxy;
8600
+ }
8601
+ else if (Array.isArray(model)) {
8322
8602
  var proxy = new Proxy(model, this.arrayHandler);
8323
8603
  // var original = Object.getPrototypeOf(proxy);
8324
8604
  // original["copy"] = () => { return model; }
@@ -10719,18 +10999,16 @@ class RoutingEngine {
10719
10999
  }
10720
11000
  let val = control;
10721
11001
  if (val instanceof Promise) {
10722
- val = await val.then((result) => {
10723
- return result.default ? result.default : result;
10724
- });
11002
+ val = unwrapModule(await val);
10725
11003
  }
10726
11004
  instance = this._construct(scope, route, () => this._resolveFrom(scope, val));
10727
11005
  if (instance) {
10728
11006
  return instance;
10729
11007
  }
10730
11008
  if (typeof val === 'function') {
10731
- return this.parseControl(this._construct(scope, route, () => resolveComponent(val, this.application)), scope, route);
11009
+ return this.parseControl(this._construct(scope, route, () => resolveToComponent(val, this.application)), scope, route);
10732
11010
  }
10733
- return val;
11011
+ return resolveToComponent(val);
10734
11012
  }
10735
11013
  _resolveFrom(scope, token) {
10736
11014
  const provider = scope ?? this._rootProvider();
@@ -10751,6 +11029,7 @@ class RoutingEngine {
10751
11029
  }
10752
11030
  async _instanceCreator(control, scope, route) {
10753
11031
  let val = await this.parseControl(control, scope, route);
11032
+ assertLoadedComponent(val);
10754
11033
  // if (val instanceof Promise) {
10755
11034
  // return result.default ? result.default : result;
10756
11035
  // if (typeof val === 'function') {
@@ -11747,10 +12026,11 @@ class UrlRoutingModule {
11747
12026
  catch { }
11748
12027
  this._scroll = null;
11749
12028
  this._historyStamp = null;
12029
+ let done = Promise.resolve();
11750
12030
  try {
11751
12031
  // keepAlive önbelleğindeki örnekleri bırak
11752
12032
  try {
11753
- void this.routingEngine.dispose();
12033
+ done = this.routingEngine.dispose();
11754
12034
  }
11755
12035
  catch { }
11756
12036
  if (this._navHandler) {
@@ -11770,6 +12050,7 @@ class UrlRoutingModule {
11770
12050
  }
11771
12051
  }
11772
12052
  catch { }
12053
+ return done;
11773
12054
  }
11774
12055
  }
11775
12056
 
@@ -11855,7 +12136,7 @@ let startedApplicationBuilder = false;
11855
12136
  class ApplicationBuilder {
11856
12137
  services = new ServiceCollection();
11857
12138
  constructor() {
11858
- if (_globalApplication || startedApplicationBuilder) {
12139
+ if ((_globalApplication && _globalApplication.state !== 'disposing') || startedApplicationBuilder) {
11859
12140
  throw new MotifError('MJX405', formatMotifMessage('MJX405'), { cause: _globalApplication });
11860
12141
  }
11861
12142
  startedApplicationBuilder = true;
@@ -11888,6 +12169,12 @@ class Application {
11888
12169
  constructor(provider) {
11889
12170
  this.provider = provider;
11890
12171
  }
12172
+ static _disposingCount = 0;
12173
+ _state = 'initializing';
12174
+ _disposing;
12175
+ get state() {
12176
+ return this._state;
12177
+ }
11891
12178
  _middlewares = [];
11892
12179
  _beforeEachGuards = [];
11893
12180
  _routerState = new RouterState();
@@ -11914,9 +12201,11 @@ class Application {
11914
12201
  target = host;
11915
12202
  }
11916
12203
  let rootInstance = appRoot;
12204
+ this._state = 'running';
11917
12205
  const AppShell = new Component(target);
11918
12206
  this.appShell = AppShell;
11919
12207
  safeCallSilent(() => {
12208
+ AppShell._keepElementOnDispose = true;
11920
12209
  AppShell.application = this;
11921
12210
  AppShell.provider = this.provider;
11922
12211
  }, 'Application.run.setupAppShell');
@@ -11951,10 +12240,14 @@ class Application {
11951
12240
  this.appShell.element?.appendChild(component);
11952
12241
  }
11953
12242
  dispose() {
12243
+ if (this._disposing)
12244
+ return this._disposing;
12245
+ this._state = 'disposing';
12246
+ Application._disposingCount++;
11954
12247
  startedApplicationBuilder = false;
12248
+ let routerDone;
11955
12249
  safeCallSilent(() => { this._removeLifecycleListeners(); }, 'Application.dispose.lifecycle');
11956
- safeCallSilent(() => { this.urlRoutingModule?.dispose?.(); }, 'Application.dispose.router');
11957
- safeCallSilent(() => { this.provider.dispose(); }, 'Application.dispose.preDispose');
12250
+ safeCallSilent(() => { routerDone = this.urlRoutingModule?.dispose?.(); }, 'Application.dispose.router');
11958
12251
  safeCallSilent(() => { engine.stopGc(); }, 'Application.dispose.gcStop');
11959
12252
  safeCallSilent(() => {
11960
12253
  try {
@@ -11967,7 +12260,31 @@ class Application {
11967
12260
  catch { /* ignore */ }
11968
12261
  }, 'Application.dispose.resetUrl');
11969
12262
  transitionSettings.mode = 'concurrent';
11970
- _globalApplication = null;
12263
+ const shell = this.appShell;
12264
+ return this._disposing = (async () => {
12265
+ try {
12266
+ await routerDone;
12267
+ }
12268
+ catch (error) {
12269
+ reportError('MJX307', error);
12270
+ }
12271
+ if (shell && !shell.isDisposed) {
12272
+ try {
12273
+ await shell.dispose();
12274
+ }
12275
+ catch (error) {
12276
+ reportError('MJX307', error);
12277
+ }
12278
+ }
12279
+ try {
12280
+ await this.provider.dispose();
12281
+ }
12282
+ catch { }
12283
+ if (_globalApplication === this)
12284
+ _globalApplication = null;
12285
+ this._state = 'disposed';
12286
+ Application._disposingCount--;
12287
+ })();
11971
12288
  }
11972
12289
  useTransitions(options) {
11973
12290
  if (isTransitionMode(options?.mode))
@@ -12277,4 +12594,4 @@ exports.untracked = untracked;
12277
12594
  exports.useApplication = useApplication;
12278
12595
  exports.useModel = useModel;
12279
12596
  exports.useNavigation = useNavigation;
12280
- //# sourceMappingURL=core-BI6Lk585.cjs.map
12597
+ //# sourceMappingURL=core-SS-LXi1V.cjs.map