@e280/sly 0.2.0-21 → 0.2.0-22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/sly",
3
- "version": "0.2.0-21",
3
+ "version": "0.2.0-22",
4
4
  "description": "web shadow views",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@e280/strata": "^0.2.0-14",
27
- "@e280/stz": "^0.2.6"
27
+ "@e280/stz": "^0.2.7"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@e280/science": "^0.1.2",
package/s/view/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  export * from "./utils/parts/chain.js"
3
3
  export * from "./utils/parts/sly-view.js"
4
+ export * from "./utils/contextualize.js"
4
5
  export * from "./types.js"
5
6
  export * from "./view.js"
6
7
 
package/s/view/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import {TemplateResult} from "lit"
3
- import {Constructor} from "@e280/stz"
3
+ import {Constructor, DropFirst} from "@e280/stz"
4
4
  import {DirectiveResult} from "lit/directive.js"
5
5
 
6
6
  import {Use} from "../base/use.js"
@@ -0,0 +1,45 @@
1
+
2
+ import {DropFirst, ob} from "@e280/stz"
3
+ import {ComponentClass, View, ViewProps} from "../types.js"
4
+
5
+ export function contextualizeView<C, V extends View<any[]>>(
6
+ context: C,
7
+ view: V,
8
+ ): View<DropFirst<ViewProps<V>>> {
9
+ return view.transmute((...p: any[]) => [context, ...p]) as any
10
+ }
11
+
12
+ export function contextualizeViews<C, Vs extends Record<string, View<any[]>>>(
13
+ context: C,
14
+ views: Vs,
15
+ ): {[K in keyof Vs]: View<DropFirst<ViewProps<Vs[K]>>>} {
16
+
17
+ return ob(views)
18
+ .map(view => contextualizeView(context, view))
19
+ }
20
+
21
+ export function getViews<
22
+ Cs extends Record<string, ComponentClass<any, any>>
23
+ >(components: Cs) {
24
+
25
+ return ob(components).map(C => C.view as any) as {
26
+ [K in keyof Cs]: View<DropFirst<ViewProps<Cs[K]["view"]>>>
27
+ }
28
+ }
29
+
30
+ export function contextualizeComponents<
31
+ C,
32
+ Cs extends Record<string, ComponentClass<any, any>>
33
+ >(context: C, originalComponents: Cs) {
34
+
35
+ return ob(originalComponents).map((Cons: any) => class extends Cons {
36
+ context = context
37
+ static view = contextualizeView(context, super.view) as any
38
+ }) as any as {
39
+ [K in keyof Cs]: ComponentClass<
40
+ Cs[K],
41
+ DropFirst<ViewProps<Cs[K]["view"]>>
42
+ >
43
+ }
44
+ }
45
+
package/x/index.html CHANGED
@@ -131,7 +131,7 @@ body {
131
131
  <img class=icon alt="" src="/assets/favicon.png"/>
132
132
  <h1>sly testing page</h1>
133
133
  <p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
134
- <p class=lil>v0.2.0-21</p>
134
+ <p class=lil>v0.2.0-22</p>
135
135
 
136
136
  <fastcount-element></fastcount-element>
137
137
  <counter-component start=280 step=2>component</counter-component>
package/x/view/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./utils/parts/chain.js";
2
2
  export * from "./utils/parts/sly-view.js";
3
+ export * from "./utils/contextualize.js";
3
4
  export * from "./types.js";
4
5
  export * from "./view.js";
package/x/view/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./utils/parts/chain.js";
2
2
  export * from "./utils/parts/sly-view.js";
3
+ export * from "./utils/contextualize.js";
3
4
  export * from "./types.js";
4
5
  export * from "./view.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/view/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/view/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { DropFirst } from "@e280/stz";
2
+ import { ComponentClass, View, ViewProps } from "../types.js";
3
+ export declare function contextualizeView<C, V extends View<any[]>>(context: C, view: V): View<DropFirst<ViewProps<V>>>;
4
+ export declare function contextualizeViews<C, Vs extends Record<string, View<any[]>>>(context: C, views: Vs): {
5
+ [K in keyof Vs]: View<DropFirst<ViewProps<Vs[K]>>>;
6
+ };
7
+ export declare function getViews<Cs extends Record<string, ComponentClass<any, any>>>(components: Cs): { [K in keyof Cs]: View<DropFirst<ViewProps<Cs[K]["view"]>>>; };
8
+ export declare function contextualizeComponents<C, Cs extends Record<string, ComponentClass<any, any>>>(context: C, originalComponents: Cs): { [K in keyof Cs]: ComponentClass<Cs[K], DropFirst<ViewProps<Cs[K]["view"]>>>; };
@@ -0,0 +1,18 @@
1
+ import { ob } from "@e280/stz";
2
+ export function contextualizeView(context, view) {
3
+ return view.transmute((...p) => [context, ...p]);
4
+ }
5
+ export function contextualizeViews(context, views) {
6
+ return ob(views)
7
+ .map(view => contextualizeView(context, view));
8
+ }
9
+ export function getViews(components) {
10
+ return ob(components).map(C => C.view);
11
+ }
12
+ export function contextualizeComponents(context, originalComponents) {
13
+ return ob(originalComponents).map((Cons) => class extends Cons {
14
+ context = context;
15
+ static view = contextualizeView(context, super.view);
16
+ });
17
+ }
18
+ //# sourceMappingURL=contextualize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../../s/view/utils/contextualize.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,EAAE,EAAC,MAAM,WAAW,CAAA;AAGvC,MAAM,UAAU,iBAAiB,CAC/B,OAAU,EACV,IAAO;IAER,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAQ,CAAA;AAC/D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAAU,EACV,KAAS;IAGV,OAAO,EAAE,CAAC,KAAK,CAAC;SACd,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;AAChD,CAAC;AAED,MAAM,UAAU,QAAQ,CAErB,UAAc;IAEhB,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAW,CAE3C,CAAA;AACF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAGpC,OAAU,EAAE,kBAAsB;IAEpC,OAAO,EAAE,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,KAAM,SAAQ,IAAI;QAClE,OAAO,GAAG,OAAO,CAAA;QACjB,MAAM,CAAC,IAAI,GAAG,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAQ,CAAA;KAC3D,CAKA,CAAA;AACF,CAAC"}