@actdim/dynstruct 1.1.2 → 1.1.4

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.
Files changed (48) hide show
  1. package/dist/appDomain/appContracts.d.ts +1 -1
  2. package/dist/appDomain/appContracts.d.ts.map +1 -1
  3. package/dist/appDomain/appContracts.es.js.map +1 -1
  4. package/dist/appDomain/security/securityContracts.d.ts +1 -1
  5. package/dist/appDomain/security/securityContracts.d.ts.map +1 -1
  6. package/dist/appDomain/security/securityContracts.es.js.map +1 -1
  7. package/dist/appDomain/security/securityProvider.d.ts +1 -1
  8. package/dist/appDomain/security/securityProvider.d.ts.map +1 -1
  9. package/dist/appDomain/security/securityProvider.es.js +62 -62
  10. package/dist/appDomain/security/securityProvider.es.js.map +1 -1
  11. package/dist/componentModel/DynamicContent.d.ts +2 -2
  12. package/dist/componentModel/DynamicContent.d.ts.map +1 -1
  13. package/dist/componentModel/DynamicContent.es.js +1 -1
  14. package/dist/componentModel/DynamicContent.es.js.map +1 -1
  15. package/dist/componentModel/adapters.d.ts +1 -1
  16. package/dist/componentModel/adapters.d.ts.map +1 -1
  17. package/dist/componentModel/adapters.es.js +7 -7
  18. package/dist/componentModel/adapters.es.js.map +1 -1
  19. package/dist/componentModel/componentContext.d.ts.map +1 -1
  20. package/dist/componentModel/componentContext.es.js +53 -46
  21. package/dist/componentModel/componentContext.es.js.map +1 -1
  22. package/dist/componentModel/contracts.d.ts +174 -4
  23. package/dist/componentModel/contracts.d.ts.map +1 -1
  24. package/dist/componentModel/contracts.es.js +11 -1
  25. package/dist/componentModel/contracts.es.js.map +1 -1
  26. package/dist/componentModel/core.d.ts +17 -0
  27. package/dist/componentModel/core.d.ts.map +1 -0
  28. package/dist/componentModel/core.es.js +162 -0
  29. package/dist/componentModel/core.es.js.map +1 -0
  30. package/dist/componentModel/react.d.ts +5 -0
  31. package/dist/componentModel/react.d.ts.map +1 -0
  32. package/dist/componentModel/react.es.js +200 -0
  33. package/dist/componentModel/react.es.js.map +1 -0
  34. package/dist/net/client.es.js +4 -4
  35. package/dist/net/client.es.js.map +1 -1
  36. package/dist/services/NavService.d.ts +1 -1
  37. package/dist/services/NavService.d.ts.map +1 -1
  38. package/dist/services/NavService.es.js +9 -9
  39. package/dist/services/NavService.es.js.map +1 -1
  40. package/dist/services/StorageService.d.ts +4 -3
  41. package/dist/services/StorageService.d.ts.map +1 -1
  42. package/dist/services/StorageService.es.js +15 -15
  43. package/dist/services/StorageService.es.js.map +1 -1
  44. package/package.json +8 -7
  45. package/dist/componentModel/componentModel.d.ts +0 -165
  46. package/dist/componentModel/componentModel.d.ts.map +0 -1
  47. package/dist/componentModel/componentModel.es.js +0 -343
  48. package/dist/componentModel/componentModel.es.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"adapters.es.js","sources":["../../src/componentModel/adapters.ts"],"sourcesContent":["import { ClientBase } from \"@/net/client\";\r\nimport { MsgBus, MsgStruct, MsgStructFactory } from \"@actdim/msgmesh/msgBusCore\";\r\nimport { AddPrefix, Diff, Filter, Func, KeysOf, RemoveSuffix, Skip, ToUpper } from \"@actdim/utico/typeCore\";\r\n\r\nconst getMethodNames = (client: any) => {\r\n // return new Set(...)\r\n return Object.getOwnPropertyNames(client).filter(\r\n (name) => name !== 'constructor' && typeof client[name] === 'function',\r\n );\r\n};\r\n\r\nconst baseMethodNames = getMethodNames(ClientBase.prototype);\r\n\r\n// ServiceMsgDispatcher\r\nexport type MsgProviderAdapter = {\r\n service: any;\r\n // channelResolver/channelMapper\r\n channelSelector: (service: any, methodName: string) => string;\r\n};\r\n\r\nexport function registerAdapters<TMsgStruct extends MsgStruct = MsgStruct>(msgBus: MsgBus<TMsgStruct>, adapters: MsgProviderAdapter[], abortSignal?: AbortSignal) {\r\n if (adapters) {\r\n for (const adapter of adapters) {\r\n const { service, channelSelector } = adapter;\r\n if (!service || !channelSelector) {\r\n throw new Error(\"Service and channelSelector are required for an adapter\")\r\n }\r\n for (const methodName of getMethodNames(Object.getPrototypeOf(service))) {\r\n const channel = channelSelector?.(service, methodName);\r\n if (channel) {\r\n msgBus.provide({\r\n channel: channel as keyof TMsgStruct,\r\n topic: '/.*/',\r\n callback: (msg) => {\r\n return (service[methodName] as Func)(...((msg.payload || []) as any[]));\r\n },\r\n config: {\r\n abortSignal: abortSignal\r\n }\r\n });\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport type BaseServiceSuffix = 'CLIENT' | 'API' | 'SERVICE' | 'FETCHER' | 'CONTROLLER' | 'LOADER' | 'REPOSITORY' | 'PROVIDER';\r\n\r\n// const suffixes = ['CLIENT', 'API', 'SERVICE'] satisfies Uppercase<BaseServiceSuffix>[];\r\n// runtime version: `${prefix}${removeSuffix(serviceName.toUpperCase(), suffixes)}_`\r\nexport type ToMsgChannelPrefix<\r\n TServiceName extends string,\r\n Prefix extends string,\r\n Suffix extends string = BaseServiceSuffix,\r\n> = `${Prefix}${RemoveSuffix<Uppercase<TServiceName>, Suffix>}_`;\r\n\r\ntype ToMsgStructSource<TService, TPrefix extends string, TSkip extends keyof TService = never> = Filter<\r\n ToUpper<AddPrefix<Skip<TService, TSkip>, TPrefix>>,\r\n Func\r\n>;\r\n\r\nexport type ToMsgStruct<TService, TPrefix extends string, TSkip extends keyof TService = never, TMsgStructSource = ToMsgStructSource<TService, TPrefix, TSkip>> = MsgStructFactory<{\r\n [K in keyof TMsgStructSource as TMsgStructSource[K] extends Func ? (Uppercase<K extends string ? K : never>) : never]: {\r\n in: TMsgStructSource[K] extends Func ? Parameters<TMsgStructSource[K]> : never;\r\n out: TMsgStructSource[K] extends Func ? ReturnType<TMsgStructSource[K]> : never;\r\n };\r\n}>;\r\n\r\nexport function getMsgChannelSelector<TTPrefix extends string>(\r\n services: Record<TTPrefix, any>,\r\n) {\r\n return (service: any, methodName: string) => {\r\n const entry = Object.entries(services).find((entry) => entry[1] === service);\r\n if (!entry) {\r\n return null;\r\n }\r\n return `${entry[0]}${methodName.toUpperCase()}`;\r\n };\r\n}"],"names":["getMethodNames","client","name","ClientBase","registerAdapters","msgBus","adapters","abortSignal","adapter","service","channelSelector","methodName","channel","msg","getMsgChannelSelector","services","entry"],"mappings":";AAIA,MAAMA,IAAiB,CAACC,MAEb,OAAO,oBAAoBA,CAAM,EAAE;AAAA,EACtC,CAACC,MAASA,MAAS,iBAAiB,OAAOD,EAAOC,CAAI,KAAM;AAAA;AAI5CF,EAAeG,EAAW,SAAS;AASpD,SAASC,EAA2DC,GAA4BC,GAAgCC,GAA2B;AAC9J,MAAID;AACA,eAAWE,KAAWF,GAAU;AAC5B,YAAM,EAAE,SAAAG,GAAS,iBAAAC,EAAA,IAAoBF;AACrC,UAAI,CAACC,KAAW,CAACC;AACb,cAAM,IAAI,MAAM,yDAAyD;AAE7E,iBAAWC,KAAcX,EAAe,OAAO,eAAeS,CAAO,CAAC,GAAG;AACrE,cAAMG,IAAUF,IAAkBD,GAASE,CAAU;AACrD,QAAIC,KACAP,EAAO,QAAQ;AAAA,UACX,SAAAO;AAAA,UACA,OAAO;AAAA,UACP,UAAU,CAACC,MACCJ,EAAQE,CAAU,EAAW,GAAKE,EAAI,WAAW,CAAA,CAAa;AAAA,UAE1E,QAAQ;AAAA,YACJ,aAAAN;AAAA,UAAA;AAAA,QACJ,CACH;AAAA,MAET;AAAA,IACJ;AAER;AAwBO,SAASO,EACZC,GACF;AACE,SAAO,CAACN,GAAcE,MAAuB;AACzC,UAAMK,IAAQ,OAAO,QAAQD,CAAQ,EAAE,KAAK,CAACC,MAAUA,EAAM,CAAC,MAAMP,CAAO;AAC3E,WAAKO,IAGE,GAAGA,EAAM,CAAC,CAAC,GAAGL,EAAW,aAAa,KAFlC;AAAA,EAGf;AACJ;"}
1
+ {"version":3,"file":"adapters.es.js","sources":["../../src/componentModel/adapters.ts"],"sourcesContent":["import { ClientBase } from \"@/net/client\";\r\nimport { MsgBus, MsgStruct, MsgStructFactory } from \"@actdim/msgmesh/contracts\";\r\nimport { AddPrefix, Diff, Filter, Func, KeysOf, RemoveSuffix, Skip, ToUpper } from \"@actdim/utico/typeCore\";\r\n\r\nconst getMethodNames = (client: any) => {\r\n // return new Set(...)\r\n return Object.getOwnPropertyNames(client).filter(\r\n (name) => name !== 'constructor' && typeof client[name] === 'function',\r\n );\r\n};\r\n\r\nconst baseMethodNames = getMethodNames(ClientBase.prototype);\r\n\r\n// ServiceMsgDispatcher\r\nexport type MsgProviderAdapter = {\r\n service: any;\r\n // channelResolver/channelMapper\r\n channelSelector: (service: any, methodName: string) => string;\r\n};\r\n\r\nexport function registerAdapters<TMsgStruct extends MsgStruct = MsgStruct>(msgBus: MsgBus<TMsgStruct>, adapters: MsgProviderAdapter[], abortSignal?: AbortSignal) {\r\n if (adapters) {\r\n for (const adapter of adapters) {\r\n const { service, channelSelector } = adapter;\r\n if (!service || !channelSelector) {\r\n throw new Error(\"Service and channelSelector are required for an adapter\")\r\n }\r\n for (const methodName of getMethodNames(Object.getPrototypeOf(service))) {\r\n const channel = channelSelector?.(service, methodName);\r\n if (channel) {\r\n msgBus.provide({\r\n channel: channel as keyof TMsgStruct,\r\n topic: '/.*/',\r\n callback: (msg) => {\r\n return (service[methodName] as Func)(...((msg.payload || []) as any[]));\r\n },\r\n options: {\r\n abortSignal: abortSignal\r\n }\r\n });\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport type BaseServiceSuffix = 'CLIENT' | 'API' | 'SERVICE' | 'FETCHER' | 'CONTROLLER' | 'LOADER' | 'REPOSITORY' | 'PROVIDER';\r\n\r\n// const suffixes = ['CLIENT', 'API', 'SERVICE'] satisfies Uppercase<BaseServiceSuffix>[];\r\n// runtime version: `${prefix}${removeSuffix(serviceName.toUpperCase(), suffixes)}_`\r\nexport type ToMsgChannelPrefix<\r\n TServiceName extends string,\r\n Prefix extends string,\r\n Suffix extends string = BaseServiceSuffix,\r\n> = `${Prefix}${RemoveSuffix<Uppercase<TServiceName>, Suffix>}_`;\r\n\r\ntype ToMsgStructSource<TService, TPrefix extends string, TSkip extends keyof TService = never> = Filter<\r\n ToUpper<AddPrefix<Skip<TService, TSkip>, TPrefix>>,\r\n Func\r\n>;\r\n\r\nexport type ToMsgStruct<TService, TPrefix extends string, TSkip extends keyof TService = never, TMsgStructSource = ToMsgStructSource<TService, TPrefix, TSkip>> = MsgStructFactory<{\r\n [K in keyof TMsgStructSource as TMsgStructSource[K] extends Func ? (Uppercase<K extends string ? K : never>) : never]: {\r\n in: TMsgStructSource[K] extends Func ? Parameters<TMsgStructSource[K]> : never;\r\n out: TMsgStructSource[K] extends Func ? ReturnType<TMsgStructSource[K]> : never;\r\n };\r\n}>;\r\n\r\nexport function getMsgChannelSelector<TTPrefix extends string>(\r\n services: Record<TTPrefix, any>,\r\n) {\r\n return (service: any, methodName: string) => {\r\n const entry = Object.entries(services).find((entry) => entry[1] === service);\r\n if (!entry) {\r\n return null;\r\n }\r\n return `${entry[0]}${methodName.toUpperCase()}`;\r\n };\r\n}\r\n\r\n// TODO:\r\n// export type PublicKeys<T> = {\r\n// [K in keyof T]: K extends `_${string}` ? never : K;\r\n// }[keyof T];\r\n"],"names":["getMethodNames","client","name","ClientBase","registerAdapters","msgBus","adapters","abortSignal","adapter","service","channelSelector","methodName","channel","msg","getMsgChannelSelector","services","entry"],"mappings":";AAIA,MAAMA,IAAiB,CAACC,MAEb,OAAO,oBAAoBA,CAAM,EAAE;AAAA,EACtC,CAACC,MAASA,MAAS,iBAAiB,OAAOD,EAAOC,CAAI,KAAM;AAAA;AAI5CF,EAAeG,EAAW,SAAS;AASpD,SAASC,EAA2DC,GAA4BC,GAAgCC,GAA2B;AAC9J,MAAID;AACA,eAAWE,KAAWF,GAAU;AAC5B,YAAM,EAAE,SAAAG,GAAS,iBAAAC,EAAA,IAAoBF;AACrC,UAAI,CAACC,KAAW,CAACC;AACb,cAAM,IAAI,MAAM,yDAAyD;AAE7E,iBAAWC,KAAcX,EAAe,OAAO,eAAeS,CAAO,CAAC,GAAG;AACrE,cAAMG,IAAUF,IAAkBD,GAASE,CAAU;AACrD,QAAIC,KACAP,EAAO,QAAQ;AAAA,UACX,SAAAO;AAAA,UACA,OAAO;AAAA,UACP,UAAU,CAACC,MACCJ,EAAQE,CAAU,EAAW,GAAKE,EAAI,WAAW,CAAA,CAAa;AAAA,UAE1E,SAAS;AAAA,YACL,aAAAN;AAAA,UAAA;AAAA,QACJ,CACH;AAAA,MAET;AAAA,IACJ;AAER;AAwBO,SAASO,EACZC,GACF;AACE,SAAO,CAACN,GAAcE,MAAuB;AACzC,UAAMK,IAAQ,OAAO,QAAQD,CAAQ,EAAE,KAAK,CAACC,MAAUA,EAAM,CAAC,MAAMP,CAAO;AAC3E,WAAKO,IAGE,GAAGA,EAAM,CAAC,CAAC,GAAGL,EAAW,aAAa,KAFlC;AAAA,EAGf;AACJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"componentContext.d.ts","sourceRoot":"","sources":["../../src/componentModel/componentContext.tsx"],"names":[],"mappings":"AAIA,OAAc,EAAiB,iBAAiB,EAAsB,MAAM,OAAO,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAsC,MAAM,aAAa,CAAC;AAEvF,eAAO,MAAM,qBAAqB,KAAqD,CAAC;AAGxF,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,iBAAiB,CAAC;IACrB,KAAK,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC,OAgKL;AAGD,wBAAgB,mBAAmB,QASlC"}
1
+ {"version":3,"file":"componentContext.d.ts","sourceRoot":"","sources":["../../src/componentModel/componentContext.tsx"],"names":[],"mappings":"AAIA,OAAc,EAAiB,iBAAiB,EAAsB,MAAM,OAAO,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAA+C,MAAM,aAAa,CAAC;AAGhG,eAAO,MAAM,qBAAqB,KAAqD,CAAC;AAGxF,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,iBAAiB,CAAC;IACrB,KAAK,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC,OA2LL;AAGD,wBAAgB,mBAAmB,QASlC"}
@@ -1,77 +1,84 @@
1
- import P, { createContext as R, useRef as i, useContext as k } from "react";
2
- const f = R(void 0);
3
- function E(o) {
4
- let h;
5
- const c = i(/* @__PURE__ */ new Map()), u = i([]), g = () => u.current[u.current.length - 1], d = (e, t) => {
6
- let n = c.current.get(e);
7
- if (n ? n.parentId = t : (n = {
1
+ import R, { createContext as k, useContext as E, useRef as i } from "react";
2
+ import { toHtmlId as I } from "./core.es.js";
3
+ const g = k(void 0);
4
+ function H(s) {
5
+ let f;
6
+ const o = i(/* @__PURE__ */ new Map()), u = i([]), l = i(/* @__PURE__ */ new Map()), C = (e) => {
7
+ let t = 1;
8
+ return l.current.has(e) && (t = l.current.get(e)), l.current.set(e, t + 1), `${I(e)}#${t}`;
9
+ }, x = () => u.current[u.current.length - 1], m = (e, t, n) => {
10
+ let r = o.current.get(e);
11
+ if (r ? (r.parentId = n, r.regType = t) : (r = {
8
12
  id: e,
9
- parentId: t,
10
- children: /* @__PURE__ */ new Set()
11
- }, c.current.set(e, n)), t) {
12
- let r = c.current.get(t);
13
- r || (r = {
14
- id: t,
15
- children: /* @__PURE__ */ new Set()
16
- }, c.current.set(t, r)), r.children.has(e) || r.children.add(e);
13
+ parentId: n,
14
+ children: /* @__PURE__ */ new Set(),
15
+ regType: t
16
+ }, o.current.set(e, r)), n) {
17
+ let c = o.current.get(n);
18
+ c || (c = {
19
+ id: n,
20
+ children: /* @__PURE__ */ new Set(),
21
+ regType: void 0
22
+ }, o.current.set(n, c)), c.children.has(e) || c.children.add(e);
17
23
  }
18
24
  u.current.push(e);
19
- }, a = (e) => {
20
- const t = c.current.get(e);
25
+ }, p = (e) => {
26
+ const t = o.current.get(e);
21
27
  if (!t)
22
28
  return;
23
- t.parentId && c.current.get(t.parentId)?.children.delete(e), t.children.forEach((r) => a(r)), c.current.delete(e);
29
+ t.parentId && o.current.get(t.parentId)?.children.delete(e), t.children.forEach((r) => p(r)), o.current.delete(e);
24
30
  const n = u.current.lastIndexOf(e);
25
31
  n >= 0 && u.current.splice(n, 1);
26
- }, s = (e) => c.current.get(e)?.parentId, p = (e) => Array.from(c.current.get(e)?.children ?? []), C = (e) => {
32
+ }, a = (e) => o.current.get(e)?.parentId, d = (e) => Array.from(o.current.get(e)?.children ?? []), w = (e) => {
27
33
  const t = [];
28
34
  let n = e;
29
35
  for (; ; ) {
30
- const r = s(n);
36
+ const r = a(n);
31
37
  if (!r)
32
38
  break;
33
39
  t.push(r), n = r;
34
40
  }
35
41
  return t;
36
- }, x = (e) => {
42
+ }, v = (e) => {
37
43
  const t = [], n = [e];
38
44
  for (; n.length > 0; ) {
39
- const r = n.pop(), v = p(r);
40
- for (const l of v)
41
- t.includes(l) || (t.push(l), n.push(l));
45
+ const r = n.pop(), c = d(r);
46
+ for (const h of c)
47
+ t.includes(h) || (t.push(h), n.push(h));
42
48
  }
43
49
  return t;
44
- }, w = (e) => {
45
- e || (e = g());
50
+ }, P = (e) => {
51
+ e || (e = x());
46
52
  const t = [];
47
53
  let n = e;
48
54
  for (; n; )
49
- t.push(n), n = s(n);
55
+ t.push(n), n = a(n);
50
56
  return t.reverse().join("/");
51
- }, m = () => c.current;
52
- return h = i({
53
- ...o.value,
54
- register: d,
55
- unregister: a,
56
- getParent: s,
57
- getChildren: p,
58
- getChainUp: C,
59
- getChainDown: x,
60
- getHierarchyPath: w,
61
- getNodeMap: m
62
- }), /* @__PURE__ */ P.createElement(f.Provider, { value: h.current }, o.children);
57
+ }, M = () => o.current;
58
+ return f = i({
59
+ ...s.value,
60
+ register: m,
61
+ unregister: p,
62
+ getParent: a,
63
+ getChildren: d,
64
+ getChainUp: w,
65
+ getChainDown: v,
66
+ getHierarchyPath: P,
67
+ getNodeMap: M,
68
+ getNextId: C
69
+ }), /* @__PURE__ */ R.createElement(g.Provider, { value: f.current }, s.children);
63
70
  }
64
- function S() {
65
- const o = k(f);
66
- if (!o)
71
+ function $() {
72
+ const s = E(g);
73
+ if (!s)
67
74
  throw new Error(
68
75
  "Can't resolve ComponentContext. Please wrap your component tree with <ComponentContextProvider>."
69
76
  );
70
- return o;
77
+ return s;
71
78
  }
72
79
  export {
73
- E as ComponentContextProvider,
74
- f as ReactComponentContext,
75
- S as useComponentContext
80
+ H as ComponentContextProvider,
81
+ g as ReactComponentContext,
82
+ $ as useComponentContext
76
83
  };
77
84
  //# sourceMappingURL=componentContext.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"componentContext.es.js","sources":["../../src/componentModel/componentContext.tsx"],"sourcesContent":["//##############################################################################\r\n//# Copyright (c) Pavel Borodaev #\r\n//##############################################################################\r\n\r\nimport React, { createContext, PropsWithChildren, useContext, useRef } from 'react';\r\nimport { BaseComponentContext, ComponentRegistryContext, TreeNode } from './contracts';\r\n\r\nexport const ReactComponentContext = createContext<ComponentRegistryContext>(undefined);\r\n\r\n// ComponentRegistry(Context)Provider\r\nexport function ComponentContextProvider(\r\n props: PropsWithChildren<{\r\n value?: BaseComponentContext;\r\n }>,\r\n) {\r\n let context: React.RefObject<ComponentRegistryContext>;\r\n const treeRef = useRef(new Map<string, TreeNode>());\r\n // idStack\r\n const regStack = useRef([]);\r\n\r\n const getCurrentId = () => {\r\n return regStack.current[regStack.current.length - 1];\r\n };\r\n\r\n const register = (id: string, parentId?: string) => {\r\n let node = treeRef.current.get(id);\r\n\r\n if (!node) {\r\n node = {\r\n id,\r\n parentId,\r\n children: new Set(),\r\n };\r\n treeRef.current.set(id, node);\r\n } else {\r\n node.parentId = parentId;\r\n }\r\n\r\n if (parentId) {\r\n let parentNode = treeRef.current.get(parentId);\r\n if (!parentNode) {\r\n parentNode = {\r\n id: parentId,\r\n children: new Set(),\r\n };\r\n treeRef.current.set(parentId, parentNode);\r\n }\r\n if (!parentNode.children.has(id)) {\r\n parentNode.children.add(id);\r\n }\r\n }\r\n\r\n regStack.current.push(id);\r\n };\r\n\r\n const unregister = (id: string) => {\r\n const node = treeRef.current.get(id);\r\n if (!node) {\r\n return;\r\n }\r\n\r\n if (node.parentId) {\r\n const parent = treeRef.current.get(node.parentId);\r\n parent?.children.delete(id);\r\n }\r\n\r\n node.children.forEach((childId) => unregister(childId));\r\n treeRef.current.delete(id);\r\n\r\n const index = regStack.current.lastIndexOf(id);\r\n if (index >= 0) {\r\n regStack.current.splice(index, 1);\r\n }\r\n };\r\n\r\n const getParent = (id: string) => {\r\n return treeRef.current.get(id)?.parentId;\r\n };\r\n const getChildren = (id: string) => {\r\n return Array.from(treeRef.current.get(id)?.children ?? []) as string[];\r\n };\r\n\r\n const getChainUp = (id: string): string[] => {\r\n const result: string[] = [];\r\n let current = id;\r\n while (true) {\r\n const parent = getParent(current);\r\n if (!parent) {\r\n break;\r\n }\r\n result.push(parent);\r\n current = parent;\r\n }\r\n return result;\r\n };\r\n\r\n const getChainDown = (id: string): string[] => {\r\n const result: string[] = [];\r\n const stack: string[] = [id];\r\n while (stack.length > 0) {\r\n const current = stack.pop();\r\n const children = getChildren(current)!;\r\n for (const child of children) {\r\n if (!result.includes(child)) {\r\n result.push(child);\r\n stack.push(child);\r\n }\r\n }\r\n // result.push(...children);\r\n // stack.push(...children);\r\n }\r\n return result;\r\n };\r\n\r\n const getHierarchy = (rootId: string) => {\r\n const buildNode = (id: string): TreeNode => {\r\n const childrenIds = getChildren(id) || [];\r\n return {\r\n id,\r\n parentId: getParent(id),\r\n children: childrenIds.map(buildNode),\r\n } as TreeNode & { children: TreeNode[] };\r\n };\r\n return buildNode(rootId);\r\n };\r\n\r\n const getSiblings = (id: string) => {\r\n const parent = getParent(id);\r\n if (!parent) {\r\n return [];\r\n }\r\n const children = getChildren(parent);\r\n if (!children) {\r\n return [];\r\n }\r\n return children.filter((child) => child !== id);\r\n };\r\n\r\n const getHierarchyPath = (id: string): string => {\r\n if (!id) {\r\n id = getCurrentId();\r\n }\r\n const path: string[] = [];\r\n let current = id;\r\n\r\n while (current) {\r\n path.push(current);\r\n current = getParent(current);\r\n }\r\n\r\n return path.reverse().join('/');\r\n };\r\n\r\n // getNodes\r\n const getNodeMap = () => treeRef.current;\r\n\r\n context = useRef({\r\n ...props.value,\r\n register,\r\n unregister,\r\n getParent,\r\n getChildren,\r\n getChainUp,\r\n getChainDown,\r\n getHierarchyPath,\r\n getNodeMap,\r\n });\r\n\r\n return (\r\n <ReactComponentContext.Provider value={context.current}>\r\n {props.children}\r\n </ReactComponentContext.Provider>\r\n );\r\n}\r\n\r\n// useComponentRegistry(Context)\r\nexport function useComponentContext() {\r\n const context = useContext(ReactComponentContext);\r\n if (!context) {\r\n // useComponentContext must be used within a ComponentContextProvider\r\n throw new Error(\r\n \"Can't resolve ComponentContext. Please wrap your component tree with <ComponentContextProvider>.\",\r\n );\r\n }\r\n return context;\r\n}\r\n"],"names":["ReactComponentContext","createContext","ComponentContextProvider","props","context","treeRef","useRef","regStack","getCurrentId","register","id","parentId","node","parentNode","unregister","childId","index","getParent","getChildren","getChainUp","result","current","parent","getChainDown","stack","children","child","getHierarchyPath","path","getNodeMap","React","useComponentContext","useContext"],"mappings":";AAOO,MAAMA,IAAwBC,EAAwC,MAAS;AAG/E,SAASC,EACZC,GAGF;AACE,MAAIC;AACJ,QAAMC,IAAUC,EAAO,oBAAI,KAAuB,GAE5CC,IAAWD,EAAO,EAAE,GAEpBE,IAAe,MACVD,EAAS,QAAQA,EAAS,QAAQ,SAAS,CAAC,GAGjDE,IAAW,CAACC,GAAYC,MAAsB;AAChD,QAAIC,IAAOP,EAAQ,QAAQ,IAAIK,CAAE;AAajC,QAXKE,IAQDA,EAAK,WAAWD,KAPhBC,IAAO;AAAA,MACH,IAAAF;AAAA,MACA,UAAAC;AAAA,MACA,8BAAc,IAAA;AAAA,IAAI,GAEtBN,EAAQ,QAAQ,IAAIK,GAAIE,CAAI,IAK5BD,GAAU;AACV,UAAIE,IAAaR,EAAQ,QAAQ,IAAIM,CAAQ;AAC7C,MAAKE,MACDA,IAAa;AAAA,QACT,IAAIF;AAAA,QACJ,8BAAc,IAAA;AAAA,MAAI,GAEtBN,EAAQ,QAAQ,IAAIM,G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AmB,CAACjB,MAAuB;AAC7C,IAAKA,MACDA,IAAKF,EAAA;AAET,UAAMoB,IAAiB,CAAA;AACvB,QAAIP,IAAUX;AAEd,WAAOW;AACH,MAAAO,EAAK,KAAKP,CAAO,GACjBA,IAAUJ,EAAUI,CAAO;AAG/B,WAAOO,EAAK,UAAU,KAAK,GAAG;AAAA,EAClC,GAGMC,IAAa,MAAMxB,EAAQ;AAEjC,SAAAD,IAAUE,EAAO;AAAA,IACb,GAAGH,EAAM;AAAA,IACT,UAAAM;AAAA,IACA,YAAAK;AAAA,IACA,WAAAG;AAAA,IACA,aAAAC;AAAA,IACA,YAAAC;AAAA,IACA,cAAAI;AAAA,IACA,kBAAAI;AAAA,IACA,YAAAE;AAAA,EAAA,CACH,GAGG,gBAAAC,EAAA,cAAC9B,EAAsB,UAAtB,EAA+B,OAAOI,EAAQ,QAAA,GAC1CD,EAAM,QACX;AAER;AAGO,SAAS4B,IAAsB;AAClC,QAAM3B,IAAU4B,EAAWhC,CAAqB;AAChD,MAAI,CAACI;AAED,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAGR,SAAOA;AACX;"}
1
+ {"version":3,"file":"componentContext.es.js","sources":["../../src/componentModel/componentContext.tsx"],"sourcesContent":["//##############################################################################\r\n//# Copyright (c) Pavel Borodaev #\r\n//##############################################################################\r\n\r\nimport React, { createContext, PropsWithChildren, useContext, useRef } from 'react';\r\nimport { BaseComponentContext, ComponentRegistryContext, ComponentTreeNode } from './contracts';\r\nimport { toHtmlId } from './core';\r\n\r\nexport const ReactComponentContext = createContext<ComponentRegistryContext>(undefined);\r\n\r\n// ComponentRegistry(Context)Provider\r\nexport function ComponentContextProvider(\r\n props: PropsWithChildren<{\r\n value?: BaseComponentContext;\r\n }>,\r\n) {\r\n let context: React.RefObject<ComponentRegistryContext>;\r\n const treeRef = useRef(new Map<string, ComponentTreeNode>());\r\n // idStack\r\n const regStack = useRef([]);\r\n\r\n const seqMap = useRef(new Map<string, number>());\r\n\r\n const getNextId = (regType: string) => {\r\n let index = 1;\r\n if (seqMap.current.has(regType)) {\r\n index = seqMap.current.get(regType);\r\n }\r\n seqMap.current.set(regType, index + 1);\r\n return `${toHtmlId(regType)}#${index}`;\r\n };\r\n\r\n const getCurrentId = () => {\r\n return regStack.current[regStack.current.length - 1];\r\n };\r\n\r\n const register = (id: string, regType: string, parentId?: string) => {\r\n let node = treeRef.current.get(id);\r\n\r\n if (!node) {\r\n node = {\r\n id,\r\n parentId,\r\n children: new Set(),\r\n regType: regType,\r\n };\r\n treeRef.current.set(id, node);\r\n } else {\r\n node.parentId = parentId;\r\n node.regType = regType;\r\n }\r\n\r\n if (parentId) {\r\n let parentNode = treeRef.current.get(parentId);\r\n if (!parentNode) {\r\n parentNode = {\r\n id: parentId,\r\n children: new Set(),\r\n regType: undefined,\r\n };\r\n treeRef.current.set(parentId, parentNode);\r\n }\r\n if (!parentNode.children.has(id)) {\r\n parentNode.children.add(id);\r\n }\r\n }\r\n\r\n regStack.current.push(id);\r\n };\r\n\r\n const unregister = (id: string) => {\r\n const node = treeRef.current.get(id);\r\n if (!node) {\r\n return;\r\n }\r\n\r\n if (node.parentId) {\r\n const parent = treeRef.current.get(node.parentId);\r\n parent?.children.delete(id);\r\n }\r\n\r\n node.children.forEach((childId) => unregister(childId));\r\n treeRef.current.delete(id);\r\n\r\n const index = regStack.current.lastIndexOf(id);\r\n if (index >= 0) {\r\n regStack.current.splice(index, 1);\r\n }\r\n };\r\n\r\n const getParent = (id: string) => {\r\n return treeRef.current.get(id)?.parentId;\r\n };\r\n const getChildren = (id: string) => {\r\n return Array.from(treeRef.current.get(id)?.children ?? []) as string[];\r\n };\r\n\r\n const getChainUp = (id: string): string[] => {\r\n const result: string[] = [];\r\n let current = id;\r\n while (true) {\r\n const parent = getParent(current);\r\n if (!parent) {\r\n break;\r\n }\r\n result.push(parent);\r\n current = parent;\r\n }\r\n return result;\r\n };\r\n\r\n const getRootId = (id: string) => {\r\n let current = id;\r\n while (true) {\r\n const parent = getParent(current);\r\n if (!parent) {\r\n break;\r\n }\r\n current = parent;\r\n }\r\n return current;\r\n };\r\n\r\n const getChainDown = (id: string): string[] => {\r\n const result: string[] = [];\r\n const stack: string[] = [id];\r\n while (stack.length > 0) {\r\n const current = stack.pop();\r\n const children = getChildren(current)!;\r\n for (const child of children) {\r\n if (!result.includes(child)) {\r\n result.push(child);\r\n stack.push(child);\r\n }\r\n }\r\n // result.push(...children);\r\n // stack.push(...children);\r\n }\r\n return result;\r\n };\r\n\r\n const getHierarchy = (rootId: string) => {\r\n const buildNode = (id: string): ComponentTreeNode => {\r\n const childIds = getChildren(id) || [];\r\n return {\r\n id,\r\n parentId: getParent(id),\r\n children: childIds.map(buildNode),\r\n } as ComponentTreeNode & { children: ComponentTreeNode[] };\r\n };\r\n return buildNode(rootId);\r\n };\r\n\r\n const getSiblings = (id: string) => {\r\n const parent = getParent(id);\r\n if (!parent) {\r\n return [];\r\n }\r\n const children = getChildren(parent);\r\n if (!children) {\r\n return [];\r\n }\r\n return children.filter((child) => child !== id);\r\n };\r\n\r\n const getHierarchyPath = (id: string): string => {\r\n if (!id) {\r\n id = getCurrentId();\r\n }\r\n const path: string[] = [];\r\n let current = id;\r\n\r\n while (current) {\r\n path.push(current);\r\n current = getParent(current);\r\n }\r\n\r\n return path.reverse().join('/');\r\n };\r\n\r\n // getNodes\r\n const getNodeMap = () => treeRef.current;\r\n\r\n context = useRef({\r\n ...props.value,\r\n register,\r\n unregister,\r\n getParent,\r\n getChildren,\r\n getChainUp,\r\n getChainDown,\r\n getHierarchyPath,\r\n getNodeMap,\r\n getNextId,\r\n });\r\n\r\n return (\r\n <ReactComponentContext.Provider value={context.current}>\r\n {props.children}\r\n </ReactComponentContext.Provider>\r\n );\r\n}\r\n\r\n// useComponentRegistry(Context)\r\nexport function useComponentContext() {\r\n const context = useContext(ReactComponentContext);\r\n if (!context) {\r\n // useComponentContext must be used within a ComponentContextProvider\r\n throw new Error(\r\n \"Can't resolve ComponentContext. Please wrap your component tree with <ComponentContextProvider>.\",\r\n );\r\n }\r\n return context;\r\n}\r\n"],"names":["ReactComponentContext","createContext","ComponentContextProvider","props","context","treeRef","useRef","regStack","seqMap","getNextId","regType","index","toHtmlId","getCurrentId","register","id","parentId","node","parentNode","unregister","childId","getParent","getChildren","getChainUp","result","current","parent","getChainDown","stack","children","child","getHierarchyPath","path","getNodeMap","React","useComponentContext","useContext"],"mappings":";;AAQO,MAAMA,IAAwBC,EAAwC,MAAS;AAG/E,SAASC,EACZC,GAGF;AACE,MAAIC;AACJ,QAAMC,IAAUC,EAAO,oBAAI,KAAgC,GAErDC,IAAWD,EAAO,EAAE,GAEpBE,IAASF,EAAO,oBAAI,KAAqB,GAEzCG,IAAY,CAACC,MAAoB;AACnC,QAAIC,IAAQ;AACZ,WAAIH,EAAO,QAAQ,IAAIE,CAAO,MAC1BC,IAAQH,EAAO,QAAQ,IAAIE,CAAO,IAEtCF,EAAO,QAAQ,IAAIE,GAASC,IAAQ,CAAC,GAC9B,GAAGC,EAASF,CAAO,CAAC,IAAIC,CAAK;AAAA,EACxC,GAEME,IAAe,MACVN,EAAS,QAAQA,EAAS,QAAQ,SAAS,CAAC,GAGjDO,IAAW,CAACC,GAAYL,GAAiBM,MAAsB;AACjE,QAAIC,IAAOZ,EAAQ,QAAQ,IAAIU,CAAE;AAejC,QAbKE,KASDA,EAAK,WAAWD,GAChBC,EAAK,UAAUP,MATfO,IAAO;AAAA,MACH,IAAAF;AAAA,MACA,UAAAC;AAAA,MACA,8BAAc,IAAA;AAAA,MACd,SAAAN;AAAA,IAAA,GAEJL,EAAQ,QAAQ,IAAIU,GAAIE,CAAI,IAM5BD,GAAU;AACV,UAAIE,IAAab,EAAQ,QAAQ,IAAIW,CAAQ;AAC7C,MAAKE,MACDA,IAAa;AAAA,QACT,IAAIF;AAAA,QACJ,8BAAc,IAAA;AAAA,QACd,SAAS;AAAA,MAAA,GAEbX,EAAQ,QAAQ,IAAIW,GAAUE,CAAU,IAEvCA,EAAW,S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B;AAC7C,IAAKA,MACDA,IAAKF,EAAA;AAET,UAAMmB,IAAiB,CAAA;AACvB,QAAIP,IAAUV;AAEd,WAAOU;AACH,MAAAO,EAAK,KAAKP,CAAO,GACjBA,IAAUJ,EAAUI,CAAO;AAG/B,WAAOO,EAAK,UAAU,KAAK,GAAG;AAAA,EAClC,GAGMC,IAAa,MAAM5B,EAAQ;AAEjC,SAAAD,IAAUE,EAAO;AAAA,IACb,GAAGH,EAAM;AAAA,IACT,UAAAW;AAAA,IACA,YAAAK;AAAA,IACA,WAAAE;AAAA,IACA,aAAAC;AAAA,IACA,YAAAC;AAAA,IACA,cAAAI;AAAA,IACA,kBAAAI;AAAA,IACA,YAAAE;AAAA,IACA,WAAAxB;AAAA,EAAA,CACH,GAGG,gBAAAyB,EAAA,cAAClC,EAAsB,UAAtB,EAA+B,OAAOI,EAAQ,QAAA,GAC1CD,EAAM,QACX;AAER;AAGO,SAASgC,IAAsB;AAClC,QAAM/B,IAAUgC,EAAWpC,CAAqB;AAChD,MAAI,CAACI;AAED,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAGR,SAAOA;AACX;"}
@@ -1,22 +1,192 @@
1
- import { MsgBus, MsgHeaders, MsgStruct } from '@actdim/msgmesh/msgBusCore';
1
+ import { $CG_IN, $CG_OUT, Msg, MsgBus, MsgHeaders, MsgProviderParams, MsgStruct, MsgSubParams, OutStruct } from '@actdim/msgmesh/contracts';
2
+ import { HasKeys, MaybeKeyOf, MaybePromise, Require, Skip } from '@actdim/utico/typeCore';
3
+ import { FC, PropsWithChildren, ReactNode } from 'react';
2
4
  export type BaseComponentContext<TMsgStruct extends MsgStruct = MsgStruct> = {
3
5
  msgBus: MsgBus<TMsgStruct>;
4
6
  currentId?: string;
5
7
  };
6
- export type TreeNode = {
8
+ export type ComponentTreeNode = {
7
9
  id: string;
10
+ regType: string;
8
11
  parentId?: string;
9
12
  children: Set<string>;
10
13
  };
11
14
  export type ComponentRegistryContext<TMsgStruct extends MsgStruct = MsgStruct> = BaseComponentContext<TMsgStruct> & {
12
- register: (id: string, parentId?: string) => void;
15
+ register: (id: string, regType: string, parentId?: string) => void;
13
16
  unregister: (id: string) => void;
14
17
  getParent: (id: string) => string | undefined;
15
18
  getChildren: (id: string) => string[];
16
19
  getChainUp: (id: string) => string[];
17
20
  getChainDown: (id: string) => string[];
18
21
  getHierarchyPath: (id: string) => string;
19
- getNodeMap: () => Map<string, TreeNode>;
22
+ getNextId: (regType: string) => string;
23
+ getNodeMap: () => Map<string, ComponentTreeNode>;
20
24
  };
21
25
  export type ComponentMsgHeaders = MsgHeaders & {};
26
+ export declare enum ComponentMsgFilter {
27
+ None = 0,
28
+ FromAncestors = 1,
29
+ FromDescendants = 2
30
+ }
31
+ export type MsgChannelGroupProviderParams<TStruct extends MsgStruct = MsgStruct, TChannel extends keyof TStruct = keyof TStruct, TGroup extends keyof TStruct[TChannel] = typeof $CG_IN, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders, TScope = any> = Skip<MsgProviderParams<TStruct, TChannel, TGroup>, 'channel' | 'group' | 'callback' | 'filter'> & {
32
+ callback?: (msgIn: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, headers: TMsgHeaders, scope: TScope) => MaybePromise<OutStruct<TStruct, TChannel>>;
33
+ filter?: (msg: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, scope: TScope) => boolean;
34
+ componentFilter?: ComponentMsgFilter;
35
+ };
36
+ export type MsgChannelGroupSubscriberParams<TStruct extends MsgStruct = MsgStruct, TChannel extends keyof TStruct = keyof TStruct, TGroup extends keyof TStruct[TChannel] = typeof $CG_IN, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders, TScope = any> = Skip<MsgSubParams<TStruct, TChannel, TGroup>, 'channel' | 'group' | 'callback' | 'filter'> & {
37
+ callback?: (msg: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, scope: TScope) => void;
38
+ filter?: (msg: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, scope: TScope) => boolean;
39
+ componentFilter?: ComponentMsgFilter;
40
+ };
41
+ export type MsgBrokerScope<TStruct extends MsgStruct, TKeysToProvide extends keyof TStruct = keyof TStruct, TKeysToSubscribe extends keyof TStruct = keyof TStruct, TKeysToPublish extends keyof TStruct = keyof TStruct> = {
42
+ provide?: TKeysToProvide;
43
+ subscribe?: TKeysToSubscribe;
44
+ publish?: TKeysToPublish;
45
+ };
46
+ export type ComponentPropStruct = Record<string, any>;
47
+ export type ComponentMethodStruct = Record<string, Function>;
48
+ export type ComponentRefStruct = {
49
+ [name: string]: ComponentStruct | ((params: any) => ComponentStruct);
50
+ };
51
+ export type ComponentStructBase<TMsgStruct extends MsgStruct = MsgStruct, TPropStruct extends ComponentPropStruct = ComponentPropStruct, TMsgScope extends MsgBrokerScope<TMsgStruct> = MsgBrokerScope<TMsgStruct>> = {
52
+ props?: TPropStruct;
53
+ actions?: ComponentMethodStruct;
54
+ effects?: string[] | string | undefined;
55
+ children?: ComponentRefStruct;
56
+ msgScope?: TMsgScope;
57
+ };
58
+ export type ComponentStruct<TMsgStruct extends MsgStruct = MsgStruct, T extends ComponentStructBase<TMsgStruct> = ComponentStructBase<TMsgStruct>> = T & {
59
+ msg: TMsgStruct;
60
+ };
61
+ export type MsgBroker<TStructToProvide extends MsgStruct = MsgStruct, TStructToSubscribe extends MsgStruct = MsgStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders, TScope = any> = Require<{
62
+ provide?: Require<{
63
+ [TChannel in keyof TStructToProvide]: {
64
+ [TGroup in keyof Skip<TStructToProvide[TChannel], typeof $CG_OUT>]?: MsgChannelGroupProviderParams<TStructToProvide, TChannel, TGroup, TMsgHeaders, TScope>;
65
+ };
66
+ }, HasKeys<TStructToProvide>>;
67
+ subscribe?: Require<{
68
+ [TChannel in keyof TStructToSubscribe]: {
69
+ [TGroup in keyof TStructToSubscribe[TChannel]]?: MsgChannelGroupSubscriberParams<TStructToSubscribe, TChannel, TGroup, TMsgHeaders, TScope>;
70
+ };
71
+ }, HasKeys<TStructToSubscribe>>;
72
+ abortController?: AbortController;
73
+ }, HasKeys<TStructToProvide & TStructToSubscribe>>;
74
+ export type ValueConverter<TTo, TFrom> = {
75
+ convert(value: TFrom): TTo;
76
+ convertBack(value: TTo): TFrom;
77
+ };
78
+ export type ValidationResult = {
79
+ valid: boolean;
80
+ message: string;
81
+ };
82
+ export type Validator<T> = {
83
+ options: {
84
+ blur: boolean;
85
+ };
86
+ validate: (value: T) => MaybePromise<ValidationResult>;
87
+ };
88
+ export declare const $isBinding: unique symbol;
89
+ export type Binding<T = any, TFrom = any> = {
90
+ readonly get: () => T;
91
+ readonly set?: (value: T) => void;
92
+ readonly converter?: ValueConverter<T, TFrom>;
93
+ readonly validator?: Validator<T>;
94
+ readonly readOnly?: boolean;
95
+ [$isBinding]: boolean;
96
+ };
97
+ export type ComponentPropSource<T> = T | Binding<T>;
98
+ export type ComponentPropParams<TPropStruct extends ComponentPropStruct> = {
99
+ [P in keyof TPropStruct]?: ComponentPropSource<TPropStruct[P]>;
100
+ };
101
+ export declare const $ON_GET: "onGet";
102
+ export declare const $ON_CHANGING: "onChanging";
103
+ export declare const $ON_CHANGE: "onChange";
104
+ export type PropValueChangingHandler<TProp = PropertyKey> = (prop: TProp, oldValue: any, newValue: any) => boolean;
105
+ export type PropValueChangeHandler<TProp = PropertyKey> = (prop: TProp, value: any) => void;
106
+ export type ValueChangingHandler<T = any> = (oldValue: T, newValue: T) => boolean;
107
+ export type ValueChangeHandler<T = any> = (value: T) => void;
108
+ export type ComponentEvents<TStruct extends ComponentStruct = ComponentStruct> = {
109
+ onPropChanging?: PropValueChangingHandler<keyof TStruct['props']>;
110
+ onPropChange?: PropValueChangeHandler<keyof TStruct['props']>;
111
+ onInit?: (component: Component<TStruct>) => void;
112
+ onLayout?: (component: Component<TStruct>) => void;
113
+ onReady?: (component: Component<TStruct>) => void;
114
+ onLayoutDestroy?: (component: Component<TStruct>) => void;
115
+ onDestroy?: (component: Component<TStruct>) => void;
116
+ onError?: (component: Component<TStruct>, error: any) => void;
117
+ } & {
118
+ [P in keyof TStruct['props'] as `${typeof $ON_GET}${Capitalize<P & string>}`]?: () => TStruct['props'][P];
119
+ } & {
120
+ [P in keyof TStruct['props'] as `${typeof $ON_CHANGING}${Capitalize<P & string>}`]?: ValueChangingHandler<TStruct['props']>;
121
+ } & {
122
+ [P in keyof TStruct['props'] as `${typeof $ON_CHANGE}${Capitalize<P & string>}`]?: ValueChangeHandler<TStruct['props']>;
123
+ };
124
+ export type ComponentViewProps = {
125
+ render?: boolean;
126
+ } & PropsWithChildren;
127
+ export type ComponentViewImplFn<TStruct extends ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders> = (props: ComponentViewProps, component?: Component<TStruct, TMsgHeaders>) => ReactNode;
128
+ export type ComponentViewFn = (props: ComponentViewProps) => ReactNode;
129
+ export type ComponentMsgBroker<TStruct extends ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders> = MsgBroker<Pick<TStruct['msg'], MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['provide']>>, Pick<TStruct['msg'], MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['subscribe']>>, TMsgHeaders, Component<TStruct, TMsgHeaders>>;
130
+ export type EffectFn<TStruct extends ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders> = (component: Component<TStruct, TMsgHeaders>) => void | (() => void);
131
+ export type ComponentDef<TStruct extends ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders> = {
132
+ regType?: string;
133
+ props?: Require<TStruct['props'], HasKeys<TStruct['props']>>;
134
+ actions?: Require<TStruct['actions'], HasKeys<TStruct['actions']>>;
135
+ effects?: keyof TStruct['effects'] extends never ? never : Record<TStruct['effects'] extends string ? TStruct['effects'] : TStruct['effects'][number], EffectFn<TStruct, TMsgHeaders>>;
136
+ children?: ComponentDefChildren<TStruct['children']>;
137
+ events?: ComponentEvents<TStruct>;
138
+ msgBroker?: ComponentMsgBroker<TStruct, TMsgHeaders>;
139
+ msgBus?: MsgBus<TStruct['msg'], TMsgHeaders>;
140
+ view?: ComponentViewImplFn<TStruct, TMsgHeaders>;
141
+ };
142
+ export type ComponentDefChildren<TRefStruct extends ComponentRefStruct> = Require<{
143
+ [P in keyof TRefStruct]: TRefStruct[P] extends (params: infer TParams) => infer T ? T extends ComponentStruct ? (params: TParams) => Component<T> : never : TRefStruct[P] extends ComponentStruct ? Component<TRefStruct[P]> : never;
144
+ }, HasKeys<TRefStruct>>;
145
+ export type ComponentChildren<TRefStruct extends ComponentRefStruct> = {
146
+ [P in keyof TRefStruct as TRefStruct[P] extends Function ? `${Capitalize<P & string>}` : P]: TRefStruct[P] extends (params: infer TParams) => infer T ? T extends ComponentStruct ? FC<ComponentParams<T> & TParams> : never : TRefStruct[P] extends ComponentStruct ? Component<TRefStruct[P]> : never;
147
+ };
148
+ export type ComponentMsgStruct<TStruct extends ComponentStruct = ComponentStruct> = Pick<TStruct['msg'], MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['provide']> | MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['subscribe']> | MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['publish']>>;
149
+ export type ComponentBase<TStruct extends ComponentStruct = ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders> = {
150
+ id: string;
151
+ key: string;
152
+ regType: string;
153
+ parentId: string;
154
+ getHierarchyId(): string;
155
+ getParent(): string | undefined;
156
+ getChildren(): string[];
157
+ getChainUp(): string[];
158
+ getChainDown(): string[];
159
+ getNodeMap(): Map<string, ComponentTreeNode>;
160
+ bindings: Map<PropertyKey, Binding>;
161
+ msgBus: MsgBus<ComponentMsgStruct<TStruct>, TMsgHeaders>;
162
+ msgBroker: ComponentMsgBroker<TStruct>;
163
+ effects: Record<string, EffectController>;
164
+ View: ComponentViewFn;
165
+ };
166
+ export declare const $id: unique symbol;
167
+ export declare const $key: unique symbol;
168
+ export type ComponentModel<TStruct extends ComponentStruct = ComponentStruct> = TStruct['props'] & Readonly<TStruct['actions']> & {
169
+ readonly [$id]?: string;
170
+ readonly [$key]?: string;
171
+ };
172
+ export type Component<TStruct extends ComponentStruct = ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders> = {
173
+ readonly model: ComponentModel<TStruct>;
174
+ readonly children: Readonly<ComponentChildren<TStruct['children']>>;
175
+ } & Readonly<ComponentBase<TStruct, TMsgHeaders>>;
176
+ export type PropEventHandlers = {
177
+ onGet?: () => any;
178
+ onChanging?: (oldValue: any, newValue: any) => boolean;
179
+ onChange?: (value: any) => void;
180
+ };
181
+ export type ComponentParams<TStruct extends ComponentStruct = ComponentStruct> = ComponentPropParams<TStruct['props']> & ComponentEvents<TStruct> & {
182
+ [$id]?: string;
183
+ [$key]?: string;
184
+ };
185
+ export type EffectController = {
186
+ start: () => void;
187
+ pause: () => void;
188
+ resume: () => void;
189
+ stop: () => void;
190
+ restart: () => void;
191
+ };
22
192
  //# sourceMappingURL=contracts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/componentModel/contracts.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,MAAM,oBAAoB,CAAC,UAAU,SAAS,SAAS,GAAG,SAAS,IAAI;IACzE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACzB,CAAC;AAGF,MAAM,MAAM,wBAAwB,CAAC,UAAU,SAAS,SAAS,GAAG,SAAS,IACzE,oB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 0] = "None", n[n.FromAncestors = 1] = "FromAncestors", n[n.FromDescendants = 2] = "FromDescendants", n))(o || {});
2
+ const s = Symbol("$isBinding"), c = "onGet", $ = "onChanging", N = "onChange", d = Symbol("$id"), a = Symbol("$key");
3
+ export {
4
+ N as $ON_CHANGE,
5
+ $ as $ON_CHANGING,
6
+ c as $ON_GET,
7
+ d as $id,
8
+ s as $isBinding,
9
+ a as $key,
10
+ o as ComponentMsgFilter
11
+ };
2
12
  //# sourceMappingURL=contracts.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"contracts.es.js","sources":["../../src/componentModel/contracts.tsx"],"sourcesContent":["import {\r\n $CG_IN,\r\n $CG_OUT,\r\n Msg,\r\n MsgBus,\r\n MsgHeaders,\r\n MsgProviderParams,\r\n MsgStruct,\r\n MsgSubParams,\r\n OutStruct,\r\n} from '@actdim/msgmesh/contracts';\r\nimport { HasKeys, MaybeKeyOf, MaybePromise, Require, Skip } from '@actdim/utico/typeCore';\r\nimport { FC, PropsWithChildren, ReactNode } from 'react';\r\n\r\nexport type BaseComponentContext<TMsgStruct extends MsgStruct = MsgStruct> = {\r\n msgBus: MsgBus<TMsgStruct>;\r\n currentId?: string;\r\n};\r\n\r\nexport type ComponentTreeNode = {\r\n id: string;\r\n regType: string;\r\n parentId?: string;\r\n children: Set<string>;\r\n};\r\n\r\n// ComponentContext\r\nexport type ComponentRegistryContext<TMsgStruct extends MsgStruct = MsgStruct> =\r\n BaseComponentContext<TMsgStruct> & {\r\n register: (id: string, regType: string, parentId?: string) => void;\r\n unregister: (id: string) => void;\r\n getParent: (id: string) => string | undefined;\r\n getChildren: (id: string) => string[];\r\n getChainUp: (id: string) => string[];\r\n getChainDown: (id: string) => string[];\r\n getHierarchyPath: (id: string) => string;\r\n getNextId: (regType: string) => string;\r\n getNodeMap: () => Map<string, ComponentTreeNode>;\r\n };\r\n\r\nexport type ComponentMsgHeaders = MsgHeaders & {};\r\n\r\nexport enum ComponentMsgFilter {\r\n None = 0,\r\n // AcceptFrom...\r\n FromAncestors = 1 << 0,\r\n FromDescendants = 1 << 1,\r\n}\r\n\r\nexport type MsgChannelGroupProviderParams<\r\n TStruct extends MsgStruct = MsgStruct,\r\n TChannel extends keyof TStruct = keyof TStruct,\r\n TGroup extends keyof TStruct[TChannel] = typeof $CG_IN, // keyof TStruct[TChannel]\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n TScope = any,\r\n> = Skip<\r\n MsgProviderParams<TStruct, TChannel, TGroup>,\r\n 'channel' | 'group' | 'callback' | 'filter'\r\n> & {\r\n // resolve\r\n callback?: (\r\n msgIn: Msg<TStruct, TChannel, TGroup, TMsgHeaders>,\r\n headers: TMsgHeaders,\r\n scope: TScope,\r\n ) => MaybePromise<OutStruct<TStruct, TChannel>>;\r\n filter?: (msg: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, scope: TScope) => boolean;\r\n componentFilter?: ComponentMsgFilter;\r\n};\r\n\r\nexport type MsgChannelGroupSubscriberParams<\r\n TStruct extends MsgStruct = MsgStruct,\r\n TChannel extends keyof TStruct = keyof TStruct,\r\n TGroup extends keyof TStruct[TChannel] = typeof $CG_IN, // keyof TStruct[TChannel]\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n TScope = any,\r\n> = Skip<MsgSubParams<TStruct, TChannel, TGroup>, 'channel' | 'group' | 'callback' | 'filter'> & {\r\n callback?: (msg: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, scope: TScope) => void;\r\n filter?: (msg: Msg<TStruct, TChannel, TGroup, TMsgHeaders>, scope: TScope) => boolean;\r\n componentFilter?: ComponentMsgFilter;\r\n};\r\n\r\n// MsgScope\r\nexport type MsgBrokerScope<\r\n TStruct extends MsgStruct /*= MsgStruct*/,\r\n TKeysToProvide extends keyof TStruct = keyof TStruct,\r\n TKeysToSubscribe extends keyof TStruct = keyof TStruct,\r\n TKeysToPublish extends keyof TStruct = keyof TStruct,\r\n> = {\r\n provide?: TKeysToProvide;\r\n // consume\r\n subscribe?: TKeysToSubscribe;\r\n // produce\r\n publish?: TKeysToPublish;\r\n};\r\n\r\nexport type ComponentPropStruct = Record<string, any>;\r\n// export type ComponentPropStruct = {\r\n// [prop: string]: any;\r\n// };\r\n\r\nexport type ComponentMethodStruct = Record<string, Function>;\r\n// export type ComponentMethodStruct = {\r\n// [action: string]: Function;\r\n// };\r\n\r\n// export type ComponentRefStruct = Record<string, ComponentStruct<TMsgStruct, T>>;\r\nexport type ComponentRefStruct = {\r\n [name: string]: ComponentStruct | ((params: any) => ComponentStruct);\r\n};\r\n\r\nexport type ComponentStructBase<\r\n TMsgStruct extends MsgStruct = MsgStruct,\r\n TPropStruct extends ComponentPropStruct = ComponentPropStruct,\r\n TMsgScope extends MsgBrokerScope<TMsgStruct> = MsgBrokerScope<TMsgStruct>,\r\n> = {\r\n props?: TPropStruct;\r\n actions?: ComponentMethodStruct;\r\n effects?: string[] | string | undefined;\r\n children?: ComponentRefStruct;\r\n // msgs?\r\n msgScope?: TMsgScope;\r\n};\r\n\r\n// ComponentShape\r\nexport type ComponentStruct<\r\n TMsgStruct extends MsgStruct = MsgStruct,\r\n T extends ComponentStructBase<TMsgStruct> = ComponentStructBase<TMsgStruct>,\r\n> = T & {\r\n msg: TMsgStruct;\r\n};\r\n\r\nexport type MsgBroker<\r\n TStructToProvide extends MsgStruct = MsgStruct,\r\n TStructToSubscribe extends MsgStruct = MsgStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n TScope = any,\r\n> = Require<\r\n {\r\n // providers\r\n provide?: Require<\r\n {\r\n [TChannel in keyof TStructToProvide]: {\r\n [TGroup in keyof Skip<\r\n TStructToProvide[TChannel],\r\n typeof $CG_OUT\r\n >]?: MsgChannelGroupProviderParams<\r\n TStructToProvide,\r\n TChannel,\r\n TGroup,\r\n TMsgHeaders,\r\n TScope\r\n >;\r\n };\r\n },\r\n HasKeys<TStructToProvide>\r\n >;\r\n // subscribers\r\n subscribe?: Require<\r\n {\r\n [TChannel in keyof TStructToSubscribe]: {\r\n [TGroup in keyof TStructToSubscribe[TChannel]]?: MsgChannelGroupSubscriberParams<\r\n TStructToSubscribe,\r\n TChannel,\r\n TGroup,\r\n TMsgHeaders,\r\n TScope\r\n >;\r\n };\r\n },\r\n HasKeys<TStructToSubscribe>\r\n >;\r\n abortController?: AbortController;\r\n },\r\n HasKeys<TStructToProvide & TStructToSubscribe>\r\n>;\r\n\r\nexport type ValueConverter<TTo, TFrom> = {\r\n // ConvertFrom\r\n convert(value: TFrom): TTo;\r\n // ConvertTo\r\n convertBack(value: TTo): TFrom;\r\n};\r\n\r\nexport type ValidationResult = {\r\n valid: boolean;\r\n message: string;\r\n};\r\n\r\nexport type Validator<T> = {\r\n options: {\r\n blur: boolean;\r\n };\r\n validate: (value: T) => MaybePromise<ValidationResult>;\r\n};\r\n\r\nexport const $isBinding = Symbol('$isBinding'); // brand\r\n\r\nexport type Binding<T = any, TFrom = any> = {\r\n // getter\r\n readonly get: () => T;\r\n // setter\r\n readonly set?: (value: T) => void;\r\n readonly converter?: ValueConverter<T, TFrom>;\r\n readonly validator?: Validator<T>;\r\n readonly readOnly?: boolean;\r\n [$isBinding]: boolean;\r\n};\r\n\r\nexport type ComponentPropSource<T> = T | Binding<T>;\r\n\r\nexport type ComponentPropParams<TPropStruct extends ComponentPropStruct> = {\r\n [P in keyof TPropStruct]?: ComponentPropSource<TPropStruct[P]>;\r\n};\r\n\r\n// export const $ON_PROP_CHANGING = \"onPropChanging\" as const;\r\n// export const $ON_PROP_CHANGE = \"onPropChange\" as const;\r\n\r\nexport const $ON_GET = 'onGet' as const;\r\n// export const $ON_BEFORE_SET = \"onBeforeSet\" as const;\r\nexport const $ON_CHANGING = 'onChanging' as const;\r\nexport const $ON_CHANGE = 'onChange' as const;\r\n// export const $ON_SET = \"onSet\" as const;\r\n\r\nexport type PropValueChangingHandler<TProp = PropertyKey> = (\r\n prop: TProp,\r\n oldValue: any,\r\n newValue: any,\r\n) => boolean;\r\n\r\nexport type PropValueChangeHandler<TProp = PropertyKey> = (prop: TProp, value: any) => void;\r\n\r\n// BeforeValueSetHandler\r\nexport type ValueChangingHandler<T = any> = (oldValue: T, newValue: T) => boolean;\r\n// ValueSetHandler\r\nexport type ValueChangeHandler<T = any> = (value: T) => void;\r\n\r\nexport type ComponentEvents<TStruct extends ComponentStruct = ComponentStruct> = {\r\n onPropChanging?: PropValueChangingHandler<keyof TStruct['props']>;\r\n onPropChange?: PropValueChangeHandler<keyof TStruct['props']>;\r\n onInit?: (component: Component<TStruct>) => void;\r\n onLayout?: (component: Component<TStruct>) => void;\r\n onReady?: (component: Component<TStruct>) => void;\r\n onLayoutDestroy?: (component: Component<TStruct>) => void; // onLayoutCleanup\r\n onDestroy?: (component: Component<TStruct>) => void; // onDispose/onCleanup\r\n onError?: (component: Component<TStruct>, error: any) => void;\r\n} & {\r\n [P in keyof TStruct['props'] as `${typeof $ON_GET}${Capitalize<P & string>}`]?: () => TStruct['props'][P];\r\n} & {\r\n [P in keyof TStruct['props'] as `${typeof $ON_CHANGING}${Capitalize<P & string>}`]?: ValueChangingHandler<\r\n TStruct['props']\r\n >;\r\n} & {\r\n [P in keyof TStruct['props'] as `${typeof $ON_CHANGE}${Capitalize<P & string>}`]?: ValueChangeHandler<\r\n TStruct['props']\r\n >;\r\n};\r\n\r\n// AllHTMLAttributes<JSX.Element>\r\n\r\nexport type ComponentViewProps = {\r\n render?: boolean;\r\n} & PropsWithChildren;\r\n\r\n// ComponentRenderImplFn\r\nexport type ComponentViewImplFn<\r\n TStruct extends ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n> = (props: ComponentViewProps, component?: Component<TStruct, TMsgHeaders>) => ReactNode; // JSX.Element\r\n\r\n// ComponentRenderFn\r\nexport type ComponentViewFn = (props: ComponentViewProps) => ReactNode; // JSX.Element\r\n\r\nexport type ComponentMsgBroker<\r\n TStruct extends ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n> = MsgBroker<\r\n Pick<TStruct['msg'], MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['provide']>>,\r\n Pick<TStruct['msg'], MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['subscribe']>>,\r\n TMsgHeaders,\r\n Component<TStruct, TMsgHeaders>\r\n>;\r\n\r\nexport type EffectFn<\r\n TStruct extends ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n> = (component: Component<TStruct, TMsgHeaders>) => void | (() => void);\r\n\r\nexport type ComponentDef<\r\n TStruct extends ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n> = {\r\n // typeId\r\n regType?: string;\r\n props?: Require<TStruct['props'], HasKeys<TStruct['props']>>;\r\n actions?: Require<TStruct['actions'], HasKeys<TStruct['actions']>>;\r\n effects?: keyof TStruct['effects'] extends never\r\n ? never\r\n : Record<\r\n TStruct['effects'] extends string ? TStruct['effects'] : TStruct['effects'][number],\r\n EffectFn<TStruct, TMsgHeaders>\r\n >;\r\n children?: ComponentDefChildren<TStruct['children']>;\r\n events?: ComponentEvents<TStruct>;\r\n // msgs?\r\n msgBroker?: ComponentMsgBroker<TStruct, TMsgHeaders>;\r\n msgBus?: MsgBus<TStruct['msg'], TMsgHeaders>;\r\n view?: ComponentViewImplFn<TStruct, TMsgHeaders>;\r\n};\r\n\r\nexport type ComponentDefChildren<TRefStruct extends ComponentRefStruct> = Require<\r\n {\r\n [P in keyof TRefStruct]: TRefStruct[P] extends (params: infer TParams) => infer T\r\n ? T extends ComponentStruct\r\n ? (params: TParams) => Component<T>\r\n : never\r\n : TRefStruct[P] extends ComponentStruct\r\n ? Component<TRefStruct[P]>\r\n : never;\r\n },\r\n HasKeys<TRefStruct>\r\n>;\r\n\r\nexport type ComponentChildren<TRefStruct extends ComponentRefStruct> = {\r\n [P in keyof TRefStruct as TRefStruct[P] extends Function\r\n ? `${Capitalize<P & string>}`\r\n : P]: TRefStruct[P] extends (params: infer TParams) => infer T\r\n ? T extends ComponentStruct\r\n ? FC<ComponentParams<T> & TParams>\r\n : never\r\n : TRefStruct[P] extends ComponentStruct\r\n ? Component<TRefStruct[P]>\r\n : never;\r\n};\r\n\r\nexport type ComponentMsgStruct<TStruct extends ComponentStruct = ComponentStruct> = Pick<\r\n TStruct['msg'],\r\n | MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['provide']>\r\n | MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['subscribe']>\r\n | MaybeKeyOf<TStruct['msg'], TStruct['msgScope']['publish']>\r\n>;\r\n\r\n// style?: CSSProperties;\r\n// classNames?: string[];\r\nexport type ComponentBase<\r\n TStruct extends ComponentStruct = ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n> = {\r\n id: string;\r\n key: string;\r\n regType: string;\r\n parentId: string;\r\n // getHierarchyPath?\r\n getHierarchyId(): string;\r\n getParent(): string | undefined;\r\n getChildren(): string[];\r\n getChainUp(): string[];\r\n getChainDown(): string[];\r\n getNodeMap(): Map<string, ComponentTreeNode>;\r\n bindings: Map<PropertyKey, Binding>;\r\n msgBus: MsgBus<ComponentMsgStruct<TStruct>, TMsgHeaders>;\r\n msgBroker: ComponentMsgBroker<TStruct>;\r\n effects: Record<string, EffectController>;\r\n View: ComponentViewFn;\r\n};\r\n\r\nexport const $id = Symbol('$id');\r\nexport const $key = Symbol('$key');\r\n\r\nexport type ComponentModel<TStruct extends ComponentStruct = ComponentStruct> = TStruct['props'] &\r\n Readonly<TStruct['actions']> & {\r\n readonly [$id]?: string;\r\n readonly [$key]?: string;\r\n };\r\n\r\nexport type Component<\r\n TStruct extends ComponentStruct = ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n> = {\r\n readonly model: ComponentModel<TStruct>;\r\n readonly children: Readonly<ComponentChildren<TStruct['children']>>;\r\n} & Readonly<ComponentBase<TStruct, TMsgHeaders>>;\r\n\r\nexport type PropEventHandlers = {\r\n onGet?: () => any;\r\n onChanging?: (oldValue: any, newValue: any) => boolean;\r\n onChange?: (value: any) => void;\r\n};\r\n\r\nexport type ComponentParams<TStruct extends ComponentStruct = ComponentStruct> =\r\n ComponentPropParams<TStruct['props']> &\r\n ComponentEvents<TStruct> & {\r\n [$id]?: string;\r\n [$key]?: string;\r\n }; // & PropsWithChildren?\r\n\r\nexport type EffectController = {\r\n start: () => void;\r\n pause: () => void;\r\n resume: () => void;\r\n stop: () => void;\r\n restart: () => void;\r\n};\r\n"],"names":["ComponentMsgFilter","$isBinding","$ON_GET","$ON_CHANGING","$ON_CHANGE","$id","$key"],"mappings":"AA0CO,IAAKA,sBAAAA,OACRA,EAAAA,EAAA,OAAO,CAAA,IAAP,QAEAA,EAAAA,EAAA,gBAAgB,CAAA,IAAhB,iBACAA,EAAAA,EAAA,kBAAkB,CAAA,IAAlB,mBAJQA,IAAAA,KAAA,CAAA,CAAA;AAyJL,MAAMC,IAAa,OAAO,YAAY,GAsBhCC,IAAU,SAEVC,IAAe,cACfC,IAAa,YAiJbC,IAAM,OAAO,KAAK,GAClBC,IAAO,OAAO,MAAM;"}
@@ -0,0 +1,17 @@
1
+ import { MsgBus } from '@actdim/msgmesh/contracts';
2
+ import { Binding, Component, ComponentMsgHeaders, ComponentStruct, EffectController, EffectFn, PropEventHandlers, PropValueChangeHandler, PropValueChangingHandler, Validator, ValueConverter } from './contracts';
3
+ export declare function isBinding(obj: any): obj is Binding;
4
+ export declare function bind<T, TFrom = any>(get: () => T, set?: (value: T) => void, converter?: ValueConverter<T, TFrom>, validator?: Validator<T>): Binding;
5
+ export declare function bindProp<T extends object, P extends keyof T>(target: () => T, prop: P): Binding;
6
+ export type ProxyEventHandlers = {
7
+ onPropChanging?: PropValueChangingHandler<PropertyKey>;
8
+ onPropChange?: PropValueChangeHandler<PropertyKey>;
9
+ } & Record<PropertyKey, PropEventHandlers>;
10
+ export declare function createRecursiveProxy(target: any, bindings: Map<PropertyKey, Binding>, handlers: ProxyEventHandlers): any;
11
+ export declare function toHtmlId(url: string): string;
12
+ export declare function getComponentSourceByCaller(depth?: number): string | null;
13
+ export declare function getComponentNameByCaller(depth?: number): string | null;
14
+ export declare function registerMsgBroker<TStruct extends ComponentStruct = ComponentStruct>(component: Component<TStruct>): void;
15
+ export declare function getComponentMsgBus<TStruct extends ComponentStruct = ComponentStruct>(msgBus: MsgBus<TStruct['msg']>, headerSetter: (headers?: ComponentMsgHeaders) => void): MsgBus<TStruct["msg"]>;
16
+ export declare function createEffect<TStruct extends ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders>(component: Component<TStruct, TMsgHeaders>, name: string, fn: EffectFn<TStruct, TMsgHeaders>): EffectController;
17
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/componentModel/core.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,OAAO,KAAK,EACR,OAAO,EACP,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EAGR,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,SAAS,EACT,cAAc,EACjB,MAAM,aAAa,CAAC;AAMrB,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,OAAO,CAElD;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,GAAG,GAAG,EAC/B,GAAG,EAAE,MAAM,CAAC,EACZ,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EACxB,SAAS,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,EACpC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAC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