aberdeen 1.0.8 → 1.0.11

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.
@@ -66,8 +66,9 @@ export type SortKeyType = number | string | Array<number | string> | undefined;
66
66
  * @see {@link onEach} for usage with sorting.
67
67
  */
68
68
  export declare function invertString(input: string): string;
69
- export declare function onEach<T>(target: Array<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, key: any) => SortKeyType): void;
70
- export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: K) => void, makeKey?: (value: T, key: K) => SortKeyType): void;
69
+ type KeyToString<K> = K extends number ? string : K extends string | symbol ? K : K extends number | infer U ? string | U : K;
70
+ export declare function onEach<T>(target: ReadonlyArray<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, index: number) => SortKeyType): void;
71
+ export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: KeyToString<K>) => void, makeKey?: (value: T, index: KeyToString<K>) => SortKeyType): void;
71
72
  /**
72
73
  * Reactively checks if an observable array or object is empty.
73
74
  *
@@ -306,7 +307,7 @@ export declare function ref<T extends TargetType, K extends keyof T>(target: T,
306
307
  * This is often used together with {@link ref}, in order to use properties other than `.value`.
307
308
  * - `{text: string|number}`: Add the value as a `TextNode` to the *current* element.
308
309
  * - `{html: string}`: Add the value as HTML to the *current* element. This should only be used in exceptional situations. And of course, beware of XSS.
309
- * - `{element: Node}`: Add a pre-existing HTML `Node` to the *current* element.
310
+ - `Node`: If a DOM Node (Element or TextNode) is passed in, it is added as a child to the *current* element. If the Node is an Element, it becomes the new *current* element for the rest of this `$` function execution.
310
311
  *
311
312
  * @returns The most inner DOM element that was created (not counting text nodes nor elements created by content functions),
312
313
  * or undefined if no elements were created.
@@ -685,7 +686,7 @@ export declare function unmountAll(): void;
685
686
  */
686
687
  export declare function peek<T>(func: () => T): T;
687
688
  /** When using an object as `source`. */
688
- export declare function map<IN, OUT>(source: Record<string | symbol, IN>, func: (value: IN, index: string | symbol) => undefined | OUT): Record<string | symbol, OUT>;
689
+ export declare function map<IN, const IN_KEY extends string | number | symbol, OUT>(source: Record<IN_KEY, IN>, func: (value: IN, index: KeyToString<IN_KEY>) => undefined | OUT): Record<string | symbol, OUT>;
689
690
  /** When using an array as `source`. */
690
691
  export declare function map<IN, OUT>(source: Array<IN>, func: (value: IN, index: number) => undefined | OUT): Array<OUT>;
691
692
  /** When using an array as `source`. */
@@ -695,7 +696,7 @@ export declare function multiMap<IN, OUT extends {
695
696
  /** When using an object as `source`. */
696
697
  export declare function multiMap<K extends string | number | symbol, IN, OUT extends {
697
698
  [key: string | symbol]: DatumType;
698
- }>(source: Record<K, IN>, func: (value: IN, index: K) => OUT | undefined): OUT;
699
+ }>(source: Record<K, IN>, func: (value: IN, index: KeyToString<K>) => OUT | undefined): OUT;
699
700
  /** When using an object as `array`. */
700
701
  export declare function partition<OUT_K extends string | number | symbol, IN_V>(source: IN_V[], func: (value: IN_V, key: number) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<number, IN_V>>;
701
702
  /** When using an object as `source`. */
@@ -728,3 +729,4 @@ export declare function partition<IN_K extends string | number | symbol, OUT_K e
728
729
  * ```
729
730
  */
730
731
  export declare function dump<T>(data: T): T;
732
+ export {};
package/dist/aberdeen.js CHANGED
@@ -138,7 +138,7 @@ function partToStr(part) {
138
138
  let num = Math.abs(Math.round(part));
139
139
  const negative = part < 0;
140
140
  while (num > 0) {
141
- result += String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533);
141
+ result = String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533) + result;
142
142
  num = Math.floor(num / 65533);
143
143
  }
144
144
  return String.fromCharCode(128 + (negative ? -result.length : result.length)) + result;
@@ -910,9 +910,9 @@ var SPECIAL_PROPS = {
910
910
  addNode(document.createTextNode(value));
911
911
  },
912
912
  element: (value) => {
913
- if (!(value instanceof Node))
914
- throw new Error(`Unexpected element-argument: ${JSON.parse(value)}`);
913
+ console.log("Aberdeen: $({element: myElement}) is deprecated, use $(myElement) instead");
915
914
  addNode(value);
915
+ SPECIAL_PROPS.element = addNode;
916
916
  }
917
917
  };
918
918
  function $(...args) {
@@ -974,12 +974,23 @@ function $(...args) {
974
974
  }
975
975
  } else if (typeof arg === "object") {
976
976
  if (arg.constructor !== Object) {
977
- err = `Unexpected argument: ${arg}`;
978
- break;
979
- }
980
- for (const key in arg) {
981
- const val = arg[key];
982
- applyArg(key, val);
977
+ if (arg instanceof Node) {
978
+ addNode(arg);
979
+ if (arg instanceof Element) {
980
+ if (!savedCurrentScope)
981
+ savedCurrentScope = currentScope;
982
+ currentScope = new ChainedScope(arg, true);
983
+ currentScope.lastChild = arg.lastChild || undefined;
984
+ }
985
+ } else {
986
+ err = `Unexpected argument: ${arg}`;
987
+ break;
988
+ }
989
+ } else {
990
+ for (const key in arg) {
991
+ const val = arg[key];
992
+ applyArg(key, val);
993
+ }
983
994
  }
984
995
  } else if (typeof arg === "function") {
985
996
  new RegularScope(currentScope.parentElement, arg);
@@ -1217,5 +1228,5 @@ export {
1217
1228
  $
1218
1229
  };
1219
1230
 
1220
- //# debugId=E7B46BDF501F944C64756E2164756E21
1231
+ //# debugId=4D9B4C45440E57B664756E2164756E21
1221
1232
  //# sourceMappingURL=aberdeen.js.map