@mulsense/xnew 0.6.6 → 0.6.7

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/xnew.d.ts CHANGED
@@ -57,16 +57,21 @@ interface Snapshot {
57
57
  }
58
58
  interface Internal {
59
59
  parent: Unit | null;
60
+ ancestors: Unit[];
61
+ children: Unit[];
60
62
  state: string;
61
63
  tostart: boolean;
62
64
  protected: boolean;
65
+ promises: UnitPromise[];
66
+ results: Record<string, any>;
67
+ defines: Record<string, any>;
68
+ systems: Record<string, {
69
+ listener: Function;
70
+ execute: Function;
71
+ }[]>;
63
72
  currentElement: UnitElement;
64
73
  currentContext: Context;
65
74
  currentComponent: Function | null;
66
- ancestors: Unit[];
67
- children: Unit[];
68
- promises: UnitPromise[];
69
- results: Record<string, any>;
70
75
  nestElements: {
71
76
  element: UnitElement;
72
77
  owned: boolean;
@@ -77,11 +82,6 @@ interface Internal {
77
82
  Component: Function | null;
78
83
  execute: Function;
79
84
  }>;
80
- defines: Record<string, any>;
81
- systems: Record<string, {
82
- listener: Function;
83
- execute: Function;
84
- }[]>;
85
85
  eventor: Eventor;
86
86
  }
87
87
  declare class Unit {
@@ -208,7 +208,7 @@ interface PanelOptions {
208
208
  open?: boolean;
209
209
  params?: Record<string, any>;
210
210
  }
211
- declare function Panel(unit: Unit, { name, open, params }: PanelOptions): {
211
+ declare function Panel(unit: Unit, { params }: PanelOptions): {
212
212
  group({ name, open, params }: PanelOptions, inner: Function): Unit;
213
213
  button(key: string): Unit;
214
214
  select(key: string, { value, items }?: {
@@ -227,6 +227,12 @@ declare function Panel(unit: Unit, { name, open, params }: PanelOptions): {
227
227
  separator(): void;
228
228
  };
229
229
 
230
+ declare function Flow(unit: Unit): {
231
+ get scene(): Unit | null;
232
+ set scene(value: Unit);
233
+ next(Component: Function, props?: any): void;
234
+ };
235
+
230
236
  type SynthesizerOptions = {
231
237
  oscillator: OscillatorOptions;
232
238
  amp: AmpOptions;
@@ -276,15 +282,14 @@ declare const xnew: CreateUnit & {
276
282
  extend(Component: Function, props?: Object): {
277
283
  [key: string]: any;
278
284
  };
279
- context(component: Function): any;
285
+ context(key: any): any;
280
286
  promise(promise: Function | Promise<any> | Unit): UnitPromise;
281
287
  then(callback: Function): UnitPromise;
282
288
  catch(callback: Function): UnitPromise;
283
- resolve(value?: any): void;
284
- reject(reason?: any): void;
289
+ commit(object?: Record<string, any>): void;
285
290
  finally(callback: Function): UnitPromise;
286
291
  scope(callback: any): any;
287
- find(component: Function): Unit[];
292
+ find(Component: Function): Unit[];
288
293
  emit(type: string, ...args: any[]): void;
289
294
  timeout(callback: Function, duration?: number): UnitTimer;
290
295
  interval(callback: Function, duration: number, iterations?: number): UnitTimer;
@@ -299,6 +304,7 @@ declare const xnew: CreateUnit & {
299
304
  Panel: typeof Panel;
300
305
  Accordion: typeof Accordion;
301
306
  Popup: typeof Popup;
307
+ Flow: typeof Flow;
302
308
  };
303
309
  audio: {
304
310
  load(path: string): UnitPromise;
package/dist/xnew.js CHANGED
@@ -621,7 +621,6 @@
621
621
  });
622
622
  Unit.unit2Contexts.delete(unit);
623
623
  unit._.currentContext = { previous: null };
624
- // reset defines
625
624
  Object.keys(unit._.defines).forEach((key) => {
626
625
  delete unit[key];
627
626
  });
@@ -663,6 +662,10 @@
663
662
  else {
664
663
  const backupComponent = unit._.currentComponent;
665
664
  unit._.currentComponent = Component;
665
+ if (unit._.parent !== null) {
666
+ Unit.addContext(unit._.parent, unit, Component, unit);
667
+ }
668
+ Unit.addContext(unit, unit, Component, unit);
666
669
  const defines = (_a = Component(unit, props !== null && props !== void 0 ? props : {})) !== null && _a !== void 0 ? _a : {};
667
670
  unit._.currentComponent = backupComponent;
668
671
  Unit.component2units.add(Component, unit);
@@ -766,6 +769,8 @@
766
769
  }
767
770
  static getContext(unit, key) {
768
771
  for (let context = unit._.currentContext; context.previous !== null; context = context.previous) {
772
+ if (context.value === Unit.currentUnit && key === Unit.currentUnit._.currentComponent)
773
+ continue;
769
774
  if (context.key === key)
770
775
  return context.value;
771
776
  }
@@ -934,7 +939,6 @@
934
939
  const Component = args.shift();
935
940
  const props = args.shift();
936
941
  const unit = new Unit(Unit.currentUnit, target, Component, props);
937
- Unit.addContext(Unit.currentUnit, unit, Component, unit);
938
942
  return unit;
939
943
  }, {
940
944
  /**
@@ -973,7 +977,6 @@
973
977
  throw new Error('xnew.extend can not be called after initialized.');
974
978
  }
975
979
  const defines = Unit.extend(Unit.currentUnit, Component, props);
976
- Unit.addContext(Unit.currentUnit, Unit.currentUnit, Component, Unit.currentUnit);
977
980
  return defines;
978
981
  }
979
982
  catch (error) {
@@ -1014,9 +1017,8 @@
1014
1017
  const Component = Unit.currentUnit._.currentComponent;
1015
1018
  let unitPromise;
1016
1019
  if (promise instanceof Unit) {
1017
- const unit = promise;
1018
- unitPromise = new UnitPromise(Promise.all(unit._.promises.map(p => p.promise)), Component)
1019
- .then(() => unit._.results);
1020
+ unitPromise = new UnitPromise(Promise.all(promise._.promises.map(p => p.promise)), Component)
1021
+ .then(() => promise._.results);
1020
1022
  }
1021
1023
  else if (promise instanceof Promise) {
1022
1024
  unitPromise = new UnitPromise(promise, Component);
@@ -1042,12 +1044,8 @@
1042
1044
  then(callback) {
1043
1045
  try {
1044
1046
  const currentUnit = Unit.currentUnit;
1045
- const Component = Unit.currentUnit._.currentComponent;
1046
- const promises = Unit.currentUnit._.promises;
1047
- return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1048
- .then(() => {
1049
- callback(currentUnit._.results);
1050
- });
1047
+ return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
1048
+ .then(() => callback(currentUnit._.results));
1051
1049
  }
1052
1050
  catch (error) {
1053
1051
  console.error('xnew.then(callback: Function): ', error);
@@ -1063,8 +1061,7 @@
1063
1061
  */
1064
1062
  catch(callback) {
1065
1063
  try {
1066
- const promises = Unit.currentUnit._.promises;
1067
- return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1064
+ return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
1068
1065
  .catch(callback);
1069
1066
  }
1070
1067
  catch (error) {
@@ -1073,18 +1070,18 @@
1073
1070
  }
1074
1071
  },
1075
1072
  /**
1076
- * Assigns a value to the current unit's promise
1077
- * @param object - object to assign to the promise
1073
+ * Commits a value to the current unit's promise results
1074
+ * @param object - object to commit to the promise
1078
1075
  * @returns void
1079
1076
  * @example
1080
- * xnew.assign({ data: 123});
1077
+ * xnew.commit({ data: 123});
1081
1078
  */
1082
- assign(object) {
1079
+ commit(object) {
1083
1080
  try {
1084
1081
  Object.assign(Unit.currentUnit._.results, object);
1085
1082
  }
1086
1083
  catch (error) {
1087
- console.error('xnew.assign(object?: Record<string, any>): ', error);
1084
+ console.error('xnew.commit(object?: Record<string, any>): ', error);
1088
1085
  throw error;
1089
1086
  }
1090
1087
  },
@@ -1097,8 +1094,7 @@
1097
1094
  */
1098
1095
  finally(callback) {
1099
1096
  try {
1100
- const promises = Unit.currentUnit._.promises;
1101
- return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1097
+ return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
1102
1098
  .finally(callback);
1103
1099
  }
1104
1100
  catch (error) {
@@ -1389,13 +1385,13 @@
1389
1385
 
1390
1386
  const currentColorA = 'color-mix(in srgb, currentColor 70%, transparent)';
1391
1387
  const currentColorB = 'color-mix(in srgb, currentColor 10%, transparent)';
1392
- function Panel(unit, { name, open = false, params }) {
1388
+ function Panel(unit, { params }) {
1393
1389
  const object = params !== null && params !== void 0 ? params : {};
1394
- xnew$1.extend(Group, { name, open });
1395
1390
  return {
1396
1391
  group({ name, open, params }, inner) {
1397
1392
  const group = xnew$1((unit) => {
1398
- xnew$1.extend(Panel, { name, open, params: params !== null && params !== void 0 ? params : object });
1393
+ xnew$1.extend(Group, { name, open });
1394
+ xnew$1.extend(Panel, { params: params !== null && params !== void 0 ? params : object });
1399
1395
  inner(unit);
1400
1396
  });
1401
1397
  return group;
@@ -1437,7 +1433,7 @@
1437
1433
  unit.on('click', () => group.toggle());
1438
1434
  xnew$1('<svg viewBox="0 0 12 12" style="width: 1em; height: 1em; margin-right: 0.25em;" fill="none" stroke="currentColor">', (unit) => {
1439
1435
  xnew$1('<path d="M6 2 10 6 6 10" />');
1440
- group.on('-transition', ({ state }) => unit.element.style.transform = `rotate(${state * 90}deg)`);
1436
+ group.on('-transition', ({ value }) => unit.element.style.transform = `rotate(${value * 90}deg)`);
1441
1437
  });
1442
1438
  xnew$1('<div>', name);
1443
1439
  });
@@ -1560,6 +1556,24 @@
1560
1556
  }
1561
1557
  }
1562
1558
 
1559
+ function Flow(unit) {
1560
+ let scene = null;
1561
+ return {
1562
+ set scene(value) {
1563
+ scene = value;
1564
+ },
1565
+ get scene() {
1566
+ return scene;
1567
+ },
1568
+ next(Component, props) {
1569
+ var _a;
1570
+ // scene change
1571
+ (_a = unit.scene) === null || _a === void 0 ? void 0 : _a.finalize();
1572
+ unit.scene = xnew$1(Component, props);
1573
+ }
1574
+ };
1575
+ }
1576
+
1563
1577
  const context = new window.AudioContext();
1564
1578
  const master = context.createGain();
1565
1579
  //----------------------------------------------------------------------------------------------------
@@ -1792,6 +1806,7 @@
1792
1806
  Panel,
1793
1807
  Accordion,
1794
1808
  Popup,
1809
+ Flow,
1795
1810
  };
1796
1811
  const audio = {
1797
1812
  load(path) {
package/dist/xnew.mjs CHANGED
@@ -615,7 +615,6 @@ class Unit {
615
615
  });
616
616
  Unit.unit2Contexts.delete(unit);
617
617
  unit._.currentContext = { previous: null };
618
- // reset defines
619
618
  Object.keys(unit._.defines).forEach((key) => {
620
619
  delete unit[key];
621
620
  });
@@ -657,6 +656,10 @@ class Unit {
657
656
  else {
658
657
  const backupComponent = unit._.currentComponent;
659
658
  unit._.currentComponent = Component;
659
+ if (unit._.parent !== null) {
660
+ Unit.addContext(unit._.parent, unit, Component, unit);
661
+ }
662
+ Unit.addContext(unit, unit, Component, unit);
660
663
  const defines = (_a = Component(unit, props !== null && props !== void 0 ? props : {})) !== null && _a !== void 0 ? _a : {};
661
664
  unit._.currentComponent = backupComponent;
662
665
  Unit.component2units.add(Component, unit);
@@ -760,6 +763,8 @@ class Unit {
760
763
  }
761
764
  static getContext(unit, key) {
762
765
  for (let context = unit._.currentContext; context.previous !== null; context = context.previous) {
766
+ if (context.value === Unit.currentUnit && key === Unit.currentUnit._.currentComponent)
767
+ continue;
763
768
  if (context.key === key)
764
769
  return context.value;
765
770
  }
@@ -928,7 +933,6 @@ const xnew$1 = Object.assign(function (...args) {
928
933
  const Component = args.shift();
929
934
  const props = args.shift();
930
935
  const unit = new Unit(Unit.currentUnit, target, Component, props);
931
- Unit.addContext(Unit.currentUnit, unit, Component, unit);
932
936
  return unit;
933
937
  }, {
934
938
  /**
@@ -967,7 +971,6 @@ const xnew$1 = Object.assign(function (...args) {
967
971
  throw new Error('xnew.extend can not be called after initialized.');
968
972
  }
969
973
  const defines = Unit.extend(Unit.currentUnit, Component, props);
970
- Unit.addContext(Unit.currentUnit, Unit.currentUnit, Component, Unit.currentUnit);
971
974
  return defines;
972
975
  }
973
976
  catch (error) {
@@ -1008,9 +1011,8 @@ const xnew$1 = Object.assign(function (...args) {
1008
1011
  const Component = Unit.currentUnit._.currentComponent;
1009
1012
  let unitPromise;
1010
1013
  if (promise instanceof Unit) {
1011
- const unit = promise;
1012
- unitPromise = new UnitPromise(Promise.all(unit._.promises.map(p => p.promise)), Component)
1013
- .then(() => unit._.results);
1014
+ unitPromise = new UnitPromise(Promise.all(promise._.promises.map(p => p.promise)), Component)
1015
+ .then(() => promise._.results);
1014
1016
  }
1015
1017
  else if (promise instanceof Promise) {
1016
1018
  unitPromise = new UnitPromise(promise, Component);
@@ -1036,12 +1038,8 @@ const xnew$1 = Object.assign(function (...args) {
1036
1038
  then(callback) {
1037
1039
  try {
1038
1040
  const currentUnit = Unit.currentUnit;
1039
- const Component = Unit.currentUnit._.currentComponent;
1040
- const promises = Unit.currentUnit._.promises;
1041
- return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1042
- .then(() => {
1043
- callback(currentUnit._.results);
1044
- });
1041
+ return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
1042
+ .then(() => callback(currentUnit._.results));
1045
1043
  }
1046
1044
  catch (error) {
1047
1045
  console.error('xnew.then(callback: Function): ', error);
@@ -1057,8 +1055,7 @@ const xnew$1 = Object.assign(function (...args) {
1057
1055
  */
1058
1056
  catch(callback) {
1059
1057
  try {
1060
- const promises = Unit.currentUnit._.promises;
1061
- return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1058
+ return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
1062
1059
  .catch(callback);
1063
1060
  }
1064
1061
  catch (error) {
@@ -1067,18 +1064,18 @@ const xnew$1 = Object.assign(function (...args) {
1067
1064
  }
1068
1065
  },
1069
1066
  /**
1070
- * Assigns a value to the current unit's promise
1071
- * @param object - object to assign to the promise
1067
+ * Commits a value to the current unit's promise results
1068
+ * @param object - object to commit to the promise
1072
1069
  * @returns void
1073
1070
  * @example
1074
- * xnew.assign({ data: 123});
1071
+ * xnew.commit({ data: 123});
1075
1072
  */
1076
- assign(object) {
1073
+ commit(object) {
1077
1074
  try {
1078
1075
  Object.assign(Unit.currentUnit._.results, object);
1079
1076
  }
1080
1077
  catch (error) {
1081
- console.error('xnew.assign(object?: Record<string, any>): ', error);
1078
+ console.error('xnew.commit(object?: Record<string, any>): ', error);
1082
1079
  throw error;
1083
1080
  }
1084
1081
  },
@@ -1091,8 +1088,7 @@ const xnew$1 = Object.assign(function (...args) {
1091
1088
  */
1092
1089
  finally(callback) {
1093
1090
  try {
1094
- const promises = Unit.currentUnit._.promises;
1095
- return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1091
+ return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
1096
1092
  .finally(callback);
1097
1093
  }
1098
1094
  catch (error) {
@@ -1383,13 +1379,13 @@ function DPad(unit, { diagonal = true, stroke = 'currentColor', strokeOpacity =
1383
1379
 
1384
1380
  const currentColorA = 'color-mix(in srgb, currentColor 70%, transparent)';
1385
1381
  const currentColorB = 'color-mix(in srgb, currentColor 10%, transparent)';
1386
- function Panel(unit, { name, open = false, params }) {
1382
+ function Panel(unit, { params }) {
1387
1383
  const object = params !== null && params !== void 0 ? params : {};
1388
- xnew$1.extend(Group, { name, open });
1389
1384
  return {
1390
1385
  group({ name, open, params }, inner) {
1391
1386
  const group = xnew$1((unit) => {
1392
- xnew$1.extend(Panel, { name, open, params: params !== null && params !== void 0 ? params : object });
1387
+ xnew$1.extend(Group, { name, open });
1388
+ xnew$1.extend(Panel, { params: params !== null && params !== void 0 ? params : object });
1393
1389
  inner(unit);
1394
1390
  });
1395
1391
  return group;
@@ -1431,7 +1427,7 @@ function Group(group, { name, open = false }) {
1431
1427
  unit.on('click', () => group.toggle());
1432
1428
  xnew$1('<svg viewBox="0 0 12 12" style="width: 1em; height: 1em; margin-right: 0.25em;" fill="none" stroke="currentColor">', (unit) => {
1433
1429
  xnew$1('<path d="M6 2 10 6 6 10" />');
1434
- group.on('-transition', ({ state }) => unit.element.style.transform = `rotate(${state * 90}deg)`);
1430
+ group.on('-transition', ({ value }) => unit.element.style.transform = `rotate(${value * 90}deg)`);
1435
1431
  });
1436
1432
  xnew$1('<div>', name);
1437
1433
  });
@@ -1554,6 +1550,24 @@ function Select(_, { key = '', value, items = [] } = {}) {
1554
1550
  }
1555
1551
  }
1556
1552
 
1553
+ function Flow(unit) {
1554
+ let scene = null;
1555
+ return {
1556
+ set scene(value) {
1557
+ scene = value;
1558
+ },
1559
+ get scene() {
1560
+ return scene;
1561
+ },
1562
+ next(Component, props) {
1563
+ var _a;
1564
+ // scene change
1565
+ (_a = unit.scene) === null || _a === void 0 ? void 0 : _a.finalize();
1566
+ unit.scene = xnew$1(Component, props);
1567
+ }
1568
+ };
1569
+ }
1570
+
1557
1571
  const context = new window.AudioContext();
1558
1572
  const master = context.createGain();
1559
1573
  //----------------------------------------------------------------------------------------------------
@@ -1786,6 +1800,7 @@ const basics = {
1786
1800
  Panel,
1787
1801
  Accordion,
1788
1802
  Popup,
1803
+ Flow,
1789
1804
  };
1790
1805
  const audio = {
1791
1806
  load(path) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "Component-Oriented Programming"
6
6
  ],
7
- "version": "0.6.6",
7
+ "version": "0.6.7",
8
8
  "main": "dist/xnew.js",
9
9
  "module": "dist/xnew.mjs",
10
10
  "types": "dist/xnew.d.ts",