ctrl-fx 0.1.0 → 0.1.2

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 (152) hide show
  1. package/README.md +13 -0
  2. package/dist/chunk-BDTTV33M.js +4050 -0
  3. package/dist/chunk-EKBLRHWK.js +916 -0
  4. package/dist/chunk-OSIRHKDB.js +1812 -0
  5. package/dist/chunk-PKBMQBKP.js +7 -0
  6. package/dist/chunk-XICUXW4T.js +252 -0
  7. package/dist/db/index.d.ts +218 -16
  8. package/dist/db/index.js +53 -19
  9. package/dist/dom/index.d.ts +2 -248
  10. package/dist/dom/index.js +30 -266
  11. package/dist/effects.d.ts +2 -580
  12. package/dist/effects.js +111 -1556
  13. package/dist/index-DeEjNrg-.d.ts +1399 -0
  14. package/dist/index.d.ts +2 -41
  15. package/dist/index.js +18 -78
  16. package/dist/router.d.ts +11 -12
  17. package/dist/router.js +57 -68
  18. package/dist/testing.d.ts +67 -60
  19. package/dist/testing.js +46 -158
  20. package/dist/webcomponent.d.ts +7 -4
  21. package/dist/webcomponent.js +48 -40
  22. package/package.json +4 -3
  23. package/dist/clipboard.d.ts +0 -7
  24. package/dist/clipboard.d.ts.map +0 -1
  25. package/dist/clipboard.js +0 -3
  26. package/dist/db/effects.d.ts +0 -78
  27. package/dist/db/effects.d.ts.map +0 -1
  28. package/dist/db/effects.js +0 -98
  29. package/dist/db/errors.d.ts +0 -21
  30. package/dist/db/errors.d.ts.map +0 -1
  31. package/dist/db/errors.js +0 -13
  32. package/dist/db/index.d.ts.map +0 -1
  33. package/dist/db/keypath.d.ts +0 -40
  34. package/dist/db/keypath.d.ts.map +0 -1
  35. package/dist/db/keypath.js +0 -20
  36. package/dist/db/setup.d.ts +0 -83
  37. package/dist/db/setup.d.ts.map +0 -1
  38. package/dist/db/setup.js +0 -100
  39. package/dist/db/testdb.d.ts +0 -19
  40. package/dist/db/testdb.d.ts.map +0 -1
  41. package/dist/db/testdb.js +0 -34
  42. package/dist/dom/attrs.d.ts +0 -67
  43. package/dist/dom/attrs.d.ts.map +0 -1
  44. package/dist/dom/attrs.js +0 -154
  45. package/dist/dom/components.d.ts +0 -43
  46. package/dist/dom/components.d.ts.map +0 -1
  47. package/dist/dom/components.js +0 -86
  48. package/dist/dom/elems.d.ts +0 -121
  49. package/dist/dom/elems.d.ts.map +0 -1
  50. package/dist/dom/elems.js +0 -52
  51. package/dist/dom/events.d.ts +0 -232
  52. package/dist/dom/events.d.ts.map +0 -1
  53. package/dist/dom/events.js +0 -289
  54. package/dist/dom/index.d.ts.map +0 -1
  55. package/dist/dom/nodeid.d.ts +0 -9
  56. package/dist/dom/nodeid.d.ts.map +0 -1
  57. package/dist/dom/nodeid.js +0 -27
  58. package/dist/dom/svg.d.ts +0 -23
  59. package/dist/dom/svg.d.ts.map +0 -1
  60. package/dist/dom/svg.js +0 -1
  61. package/dist/dom/views.d.ts +0 -60
  62. package/dist/dom/views.d.ts.map +0 -1
  63. package/dist/dom/views.js +0 -154
  64. package/dist/effects.d.ts.map +0 -1
  65. package/dist/index.d.ts.map +0 -1
  66. package/dist/internal/clipboard.d.ts +0 -5
  67. package/dist/internal/clipboard.d.ts.map +0 -1
  68. package/dist/internal/clipboard.js +0 -33
  69. package/dist/internal/cmpmgr.d.ts +0 -46
  70. package/dist/internal/cmpmgr.d.ts.map +0 -1
  71. package/dist/internal/cmpmgr.js +0 -561
  72. package/dist/internal/dbmgr.d.ts +0 -11
  73. package/dist/internal/dbmgr.d.ts.map +0 -1
  74. package/dist/internal/dbmgr.js +0 -200
  75. package/dist/internal/dominterpreter.d.ts +0 -5
  76. package/dist/internal/dominterpreter.d.ts.map +0 -1
  77. package/dist/internal/dominterpreter.js +0 -337
  78. package/dist/internal/eventmgr.d.ts +0 -41
  79. package/dist/internal/eventmgr.d.ts.map +0 -1
  80. package/dist/internal/eventmgr.js +0 -696
  81. package/dist/internal/index.d.ts +0 -19
  82. package/dist/internal/index.d.ts.map +0 -1
  83. package/dist/internal/index.js +0 -38
  84. package/dist/internal/interpreter.d.ts +0 -10
  85. package/dist/internal/interpreter.d.ts.map +0 -1
  86. package/dist/internal/interpreter.js +0 -1
  87. package/dist/internal/locutils.d.ts +0 -4
  88. package/dist/internal/locutils.d.ts.map +0 -1
  89. package/dist/internal/locutils.js +0 -22
  90. package/dist/internal/net.d.ts +0 -4
  91. package/dist/internal/net.d.ts.map +0 -1
  92. package/dist/internal/net.js +0 -64
  93. package/dist/internal/realdom.d.ts +0 -249
  94. package/dist/internal/realdom.d.ts.map +0 -1
  95. package/dist/internal/realdom.js +0 -1
  96. package/dist/internal/styleregistry.d.ts +0 -6
  97. package/dist/internal/styleregistry.d.ts.map +0 -1
  98. package/dist/internal/styleregistry.js +0 -18
  99. package/dist/internal/taskreg.d.ts +0 -9
  100. package/dist/internal/taskreg.d.ts.map +0 -1
  101. package/dist/internal/taskreg.js +0 -28
  102. package/dist/internal/testing.d.ts +0 -12
  103. package/dist/internal/testing.d.ts.map +0 -1
  104. package/dist/internal/testing.js +0 -974
  105. package/dist/internal/testinginterpreter.d.ts +0 -10
  106. package/dist/internal/testinginterpreter.d.ts.map +0 -1
  107. package/dist/internal/testinginterpreter.js +0 -646
  108. package/dist/internal/vdom.d.ts +0 -93
  109. package/dist/internal/vdom.d.ts.map +0 -1
  110. package/dist/internal/vdom.js +0 -470
  111. package/dist/json/index.d.ts +0 -5
  112. package/dist/json/index.d.ts.map +0 -1
  113. package/dist/json/index.js +0 -2
  114. package/dist/json/validation.d.ts +0 -28
  115. package/dist/json/validation.d.ts.map +0 -1
  116. package/dist/json/validation.js +0 -8
  117. package/dist/net/fragment.d.ts +0 -10
  118. package/dist/net/fragment.d.ts.map +0 -1
  119. package/dist/net/fragment.js +0 -27
  120. package/dist/net/index.d.ts +0 -42
  121. package/dist/net/index.d.ts.map +0 -1
  122. package/dist/net/index.js +0 -60
  123. package/dist/net/location.d.ts +0 -21
  124. package/dist/net/location.d.ts.map +0 -1
  125. package/dist/net/location.js +0 -41
  126. package/dist/net/path.d.ts +0 -12
  127. package/dist/net/path.d.ts.map +0 -1
  128. package/dist/net/path.js +0 -29
  129. package/dist/net/queryparam.d.ts +0 -10
  130. package/dist/net/queryparam.d.ts.map +0 -1
  131. package/dist/net/queryparam.js +0 -34
  132. package/dist/router.d.ts.map +0 -1
  133. package/dist/scroll.d.ts +0 -7
  134. package/dist/scroll.d.ts.map +0 -1
  135. package/dist/scroll.js +0 -3
  136. package/dist/testing.d.ts.map +0 -1
  137. package/dist/utils/apply.d.ts +0 -9
  138. package/dist/utils/apply.d.ts.map +0 -1
  139. package/dist/utils/apply.js +0 -10
  140. package/dist/utils/index.d.ts +0 -22
  141. package/dist/utils/index.d.ts.map +0 -1
  142. package/dist/utils/index.js +0 -138
  143. package/dist/utils/lens.d.ts +0 -18
  144. package/dist/utils/lens.d.ts.map +0 -1
  145. package/dist/utils/lens.js +0 -27
  146. package/dist/utils/match.d.ts +0 -17
  147. package/dist/utils/match.d.ts.map +0 -1
  148. package/dist/utils/match.js +0 -28
  149. package/dist/utils/result.d.ts +0 -47
  150. package/dist/utils/result.d.ts.map +0 -1
  151. package/dist/utils/result.js +0 -97
  152. package/dist/webcomponent.d.ts.map +0 -1
@@ -1,33 +0,0 @@
1
- import { clipboardError } from '../clipboard';
2
- import { failure, success } from '../utils/result';
3
- export function writeClipboard(text, callback) {
4
- if (!globalThis.navigator?.clipboard?.writeText) {
5
- callback(failure(clipboardError('NotSupported', 'Clipboard API not available')));
6
- return;
7
- }
8
- globalThis.navigator.clipboard
9
- .writeText(text)
10
- .then(() => callback(success(undefined)))
11
- .catch((err) => callback(failure(toClipboardError(err))));
12
- }
13
- export function readClipboard(callback) {
14
- if (!globalThis.navigator?.clipboard?.readText) {
15
- callback(failure(clipboardError('NotSupported', 'Clipboard API not available')));
16
- return;
17
- }
18
- globalThis.navigator.clipboard
19
- .readText()
20
- .then(text => callback(success(text)))
21
- .catch((err) => callback(failure(toClipboardError(err))));
22
- }
23
- function toClipboardError(err) {
24
- if (err instanceof DOMException && err.name === 'NotAllowedError') {
25
- return clipboardError('NotAllowed', err.message);
26
- }
27
- else if (err instanceof Error) {
28
- return clipboardError('UnexpectedError', err.message);
29
- }
30
- else {
31
- return clipboardError('UnexpectedError', `Unexpected clipboard error: ${err}`);
32
- }
33
- }
@@ -1,46 +0,0 @@
1
- import { type ComponentPath } from ".";
2
- import { type Component } from "../dom/components";
3
- import type { Effect } from "../effects";
4
- import type { Interpreter } from "./interpreter";
5
- import type { RealElement, RealWindow } from "./realdom";
6
- import type { StyleRegistry } from "./styleregistry";
7
- import { type ComponentState, type InternalNode } from "./vdom";
8
- export declare function manageComponent<State, Params, Event>(component: Component<State, Params, Event>, mountId: string, window: RealWindow, interpreter: Interpreter, styleRegistry: StyleRegistry): {
9
- dispatchEffect: (effect: Effect<State, Event, void>) => void;
10
- };
11
- export declare class ComponentManager {
12
- private rootCompPath;
13
- private components;
14
- private removedComponents;
15
- private addedComponents;
16
- private interpreter;
17
- private window;
18
- private document;
19
- private eventManager;
20
- private taskRegistry;
21
- private styleRegistry;
22
- private onRootEvent;
23
- constructor(component: Component<unknown, unknown, unknown>, mountNode: RealElement, window: RealWindow, interpreter: Interpreter, styleRegistry: StyleRegistry, onRootEvent?: (event: unknown) => void);
24
- private injectComponentCss;
25
- getRootState(): ComponentState;
26
- dispatchEffect(effect: Effect<unknown, unknown, void>): void;
27
- destroy(): void;
28
- private runEffect;
29
- private renderComponent;
30
- private compareNodeSequences;
31
- private removeNode;
32
- private compareNodes;
33
- private convertNodeToInternalNode;
34
- /**
35
- * Return an old node that can be compared to `newNode`.
36
- *
37
- * If the old node represent the same node as `newNode`, return it.
38
- *
39
- * If the same node isn't found, return the first node if it is `comparable`,
40
- * otherwise return undefined. (We don't move nodes if they are comparable but
41
- * not the same).
42
- */
43
- private findCorrespondingOldNode;
44
- }
45
- export declare function foldTree<A>(root: InternalNode, ancestorComponentPath: ComponentPath, init: A, f: (node: InternalNode, ancestorComponentId: ComponentPath, acc: A) => A): A;
46
- //# sourceMappingURL=cmpmgr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cmpmgr.d.ts","sourceRoot":"","sources":["../../src/internal/cmpmgr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,GAAG,CAAC;AAGtD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAgB,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAYL,KAAK,cAAc,EACnB,KAAK,YAAY,EAGlB,MAAM,QAAQ,CAAC;AAIhB,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAClD,SAAS,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAC1C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC3B;IAAE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAA;CAAE,CAkBlE;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,YAAY,CAAgB;IAEpC,OAAO,CAAC,UAAU,CAEX;IAEP,OAAO,CAAC,iBAAiB,CAElB;IAEP,OAAO,CAAC,eAAe,CAAuB;IAE9C,OAAO,CAAC,WAAW,CAAc;IAEjC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,QAAQ,CAAe;IAE/B,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,YAAY,CAAoC;IACxD,OAAO,CAAC,aAAa,CAAgB;IAErC,OAAO,CAAC,WAAW,CAAyC;gBAG1D,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAC/C,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;IAqCxC,OAAO,CAAC,kBAAkB;IAW1B,YAAY,IAAI,cAAc;IAQ9B,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,IAAI;IAI5D,OAAO,IAAI,IAAI;IAIf,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,oBAAoB;IA6C5B,OAAO,CAAC,UAAU;IAiDlB,OAAO,CAAC,YAAY;IAqJpB,OAAO,CAAC,yBAAyB;IAwIjC;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;CAgCjC;AAoED,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,YAAY,EAClB,qBAAqB,EAAE,aAAa,EACpC,IAAI,EAAE,CAAC,EACP,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,GACvE,CAAC,CA+CH"}
@@ -1,561 +0,0 @@
1
- import { componentPath } from ".";
2
- import { foldNode } from "../dom";
3
- import { getId } from "../dom/attrs";
4
- import {} from "../dom/components";
5
- import { nodeId } from "../dom/nodeid";
6
- import { eq, exhaustivenessCheck } from "../utils";
7
- import { EventManager } from "./eventmgr";
8
- import { TaskRegistry } from "./taskreg";
9
- import { closestComponentPath, componentNode, detach, internalElementNode, internalTextNode, rootNode, updateAttrs, updateProps, updateText, viewNode, } from "./vdom";
10
- let mountCount = 0;
11
- export function manageComponent(component, mountId, window, interpreter, styleRegistry) {
12
- const mountNode = window.document.getElementById(mountId);
13
- if (!mountNode) {
14
- throw new Error(`Cannot attach component tree. Root node with id ${mountId} not found`);
15
- }
16
- const mgr = new ComponentManager(component, mountNode, window, interpreter, styleRegistry);
17
- return {
18
- dispatchEffect: (effect) => mgr.dispatchEffect(effect),
19
- };
20
- }
21
- export class ComponentManager {
22
- constructor(component, mountNode, window, interpreter, styleRegistry, onRootEvent) {
23
- Object.defineProperty(this, "rootCompPath", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: void 0
28
- });
29
- Object.defineProperty(this, "components", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: {}
34
- });
35
- Object.defineProperty(this, "removedComponents", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: {}
40
- });
41
- Object.defineProperty(this, "addedComponents", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: []
46
- });
47
- Object.defineProperty(this, "interpreter", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: void 0
52
- });
53
- Object.defineProperty(this, "window", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: void 0
58
- });
59
- Object.defineProperty(this, "document", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- Object.defineProperty(this, "eventManager", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
70
- });
71
- Object.defineProperty(this, "taskRegistry", {
72
- enumerable: true,
73
- configurable: true,
74
- writable: true,
75
- value: new TaskRegistry()
76
- });
77
- Object.defineProperty(this, "styleRegistry", {
78
- enumerable: true,
79
- configurable: true,
80
- writable: true,
81
- value: void 0
82
- });
83
- Object.defineProperty(this, "onRootEvent", {
84
- enumerable: true,
85
- configurable: true,
86
- writable: true,
87
- value: void 0
88
- });
89
- this.window = window;
90
- this.document = this.window.document;
91
- this.interpreter = interpreter;
92
- this.styleRegistry = styleRegistry;
93
- this.onRootEvent = onRootEvent;
94
- this.eventManager = new EventManager(this.window, (effect, node, onResult) => {
95
- const componentPath = closestComponentPath(node);
96
- if (componentPath) {
97
- this.runEffect(effect, componentPath, onResult);
98
- }
99
- });
100
- const rootCompPath = componentPath(nodeId(`__root_component:${++mountCount}`));
101
- this.rootCompPath = rootCompPath;
102
- const compNode = componentNode(component, rootCompPath.nodeId);
103
- const root = rootNode(mountNode);
104
- root.append(compNode);
105
- this.components[componentPath(compNode.nodeId, undefined).format()] =
106
- compNode;
107
- this.injectComponentCss(component);
108
- const initStateEffect = component.initialState(component.params);
109
- this.runEffect(initStateEffect, rootCompPath, (state) => {
110
- this.renderComponent(rootCompPath, state);
111
- });
112
- }
113
- injectComponentCss(component) {
114
- if (!component.css)
115
- return;
116
- const css = typeof component.css === "function"
117
- ? component.css(component.params)
118
- : component.css;
119
- this.styleRegistry.injectStyle(css);
120
- }
121
- getRootState() {
122
- return (this.components[this.rootCompPath.format()]?.state ?? {
123
- _type: "Uninitialized",
124
- });
125
- }
126
- dispatchEffect(effect) {
127
- this.runEffect(effect, this.rootCompPath, () => { });
128
- }
129
- destroy() {
130
- this.taskRegistry.cancelAll();
131
- }
132
- runEffect(effect, componentPath, f) {
133
- // eslint-disable-next-line @typescript-eslint/no-this-alias
134
- const that = this;
135
- this.interpreter(effect, {
136
- onComplete: f,
137
- onFireEvent: (event) => {
138
- const component = this.components[componentPath.format()];
139
- if (component) {
140
- const parentCompPath = componentPath.parentComponentPath;
141
- if (parentCompPath) {
142
- component.componentEventListeners.forEach((listener) => {
143
- const effect = listener(event);
144
- this.runEffect(effect, parentCompPath, () => { });
145
- });
146
- }
147
- else {
148
- this.onRootEvent?.(event);
149
- }
150
- }
151
- },
152
- getState: () => {
153
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
- return that.components[componentPath.format()].state.value;
155
- },
156
- setState: (state) => {
157
- that.renderComponent(componentPath, state);
158
- },
159
- }, this.taskRegistry);
160
- }
161
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
- renderComponent(componentPath, state) {
163
- const component = this.components[componentPath.format()];
164
- if (!component) {
165
- return;
166
- }
167
- // if state hasn't changed, nothing to do
168
- if (component.state._type === "Ready" && eq(component.state.value, state)) {
169
- return;
170
- }
171
- component.state = { _type: "Ready", value: state };
172
- const newNodeGroup = component.component.view(state, component.component.params);
173
- component.containerListeners = newNodeGroup.containerListeners;
174
- this.eventManager.setContainerListeners(component);
175
- const oldNodes = component.firstChild;
176
- this.compareNodeSequences(oldNodes, newNodeGroup.nodes, component, componentPath);
177
- const added = this.addedComponents.splice(0);
178
- added.forEach((childPath) => {
179
- const cNode = this.components[childPath.format()];
180
- if (cNode) {
181
- const initEffect = cNode.component.initialState(cNode.component.params);
182
- this.runEffect(initEffect, childPath, (state) => {
183
- this.renderComponent(childPath, state);
184
- });
185
- }
186
- });
187
- }
188
- compareNodeSequences(oldNodes, newNodes, parent, ancestorComponentPath) {
189
- const mutNewNodes = [...newNodes];
190
- while (mutNewNodes.length > 0) {
191
- const newNode = mutNewNodes.shift();
192
- const correspondingOldNode = this.findCorrespondingOldNode(newNode, oldNodes, ancestorComponentPath);
193
- if (correspondingOldNode) {
194
- if (correspondingOldNode !== oldNodes) {
195
- oldNodes?.before(correspondingOldNode);
196
- }
197
- this.compareNodes(correspondingOldNode, newNode, ancestorComponentPath);
198
- oldNodes = correspondingOldNode.nextSibling;
199
- }
200
- else {
201
- const newInternalNode = this.convertNodeToInternalNode(newNode, ancestorComponentPath);
202
- if (oldNodes) {
203
- oldNodes.before(newInternalNode);
204
- }
205
- else {
206
- parent.append(newInternalNode);
207
- }
208
- }
209
- }
210
- let oldNode = oldNodes;
211
- while (oldNode) {
212
- const next = oldNode.nextSibling;
213
- this.removeNode(oldNode, ancestorComponentPath);
214
- oldNode = next;
215
- }
216
- }
217
- removeNode(oldNode, ancestorComponentPath) {
218
- detach(oldNode);
219
- // TODO: event listeners
220
- // eslint-disable-next-line @typescript-eslint/no-this-alias
221
- const that = this;
222
- function removeNodeRecords(node, ancestorComponentPath) {
223
- switch (node._type) {
224
- case "InternalTextNode":
225
- return;
226
- case "InternalElementNode": {
227
- that.eventManager.setElementListeners(node);
228
- return;
229
- }
230
- case "ViewNode": {
231
- that.eventManager.setContainerListeners(node);
232
- return;
233
- }
234
- case "ComponentNode": {
235
- that.eventManager.setContainerListeners(node);
236
- const compPath = componentPath(node.nodeId, ancestorComponentPath).format();
237
- delete that.components[compPath];
238
- that.removedComponents[compPath] = node;
239
- return;
240
- }
241
- }
242
- }
243
- foldTree(oldNode, ancestorComponentPath, undefined, (node, ancestorComponentId) => {
244
- removeNodeRecords(node, ancestorComponentId);
245
- });
246
- }
247
- compareNodes(oldNode, newNode, ancestorComponentPath) {
248
- const parent = oldNode.parent;
249
- const removeOldAndAddNew = () => {
250
- const nextSibling = oldNode.nextSibling;
251
- this.removeNode(oldNode, ancestorComponentPath);
252
- const newInternalNode = this.convertNodeToInternalNode(newNode, ancestorComponentPath);
253
- if (nextSibling) {
254
- nextSibling.after(newInternalNode);
255
- }
256
- else if (parent) {
257
- parent.append(newInternalNode);
258
- }
259
- };
260
- // eslint-disable-next-line @typescript-eslint/no-this-alias
261
- const that = this;
262
- foldNode(newNode, {
263
- onText(text) {
264
- if (oldNode._type !== "InternalTextNode") {
265
- removeOldAndAddNew();
266
- return;
267
- }
268
- updateText(oldNode, text);
269
- },
270
- onVoidElement(elem) {
271
- if (oldNode._type !== "InternalElementNode" ||
272
- oldNode.tag !== elem.tag) {
273
- removeOldAndAddNew();
274
- return;
275
- }
276
- updateAttrs(oldNode, elem.attrs);
277
- updateProps(oldNode, elem.props);
278
- if (oldNode.eventListeners.length > 0 ||
279
- elem.eventListeners.length > 0) {
280
- oldNode.eventListeners = elem.eventListeners;
281
- that.eventManager.setElementListeners(oldNode);
282
- }
283
- },
284
- onNonVoidElement(elem) {
285
- if (oldNode._type !== "InternalElementNode" ||
286
- oldNode.tag !== elem.tag) {
287
- removeOldAndAddNew();
288
- return;
289
- }
290
- updateAttrs(oldNode, elem.attrs);
291
- updateProps(oldNode, elem.props);
292
- if (oldNode.eventListeners.length > 0) {
293
- oldNode.eventListeners = elem.eventListeners;
294
- that.eventManager.setElementListeners(oldNode);
295
- }
296
- that.compareNodeSequences(oldNode.firstChild, elem.children, oldNode, ancestorComponentPath);
297
- },
298
- onView(view) {
299
- if (oldNode._type !== "ViewNode" || !oldNode.nodeId.eq(view.nodeId)) {
300
- removeOldAndAddNew();
301
- return;
302
- }
303
- if (eq(oldNode.params, view.params)) {
304
- return;
305
- }
306
- const newNodeGroup = view.nodes(view.params);
307
- oldNode.params = view.params;
308
- oldNode.containerListeners = newNodeGroup.containerListeners;
309
- that.eventManager.setContainerListeners(oldNode);
310
- that.compareNodeSequences(oldNode.firstChild, newNodeGroup.nodes, oldNode, ancestorComponentPath);
311
- },
312
- onComponent(comp) {
313
- if (oldNode._type !== "ComponentNode" ||
314
- !oldNode.nodeId.eq(comp.nodeId)) {
315
- removeOldAndAddNew();
316
- return;
317
- }
318
- if (oldNode.state._type === "Ready") {
319
- if (oldNode.componentEventListeners.length > 0 ||
320
- comp.componentEventListeners.length > 0) {
321
- oldNode.componentEventListeners = comp.componentEventListeners;
322
- that.eventManager.setContainerListeners(oldNode);
323
- }
324
- if (eq(oldNode.component.params, comp.component.params)) {
325
- oldNode.component = comp.component;
326
- }
327
- else {
328
- that.injectComponentCss(comp.component);
329
- const newNodeGroup = comp.component.view(oldNode.state.value, comp.component.params);
330
- oldNode.containerListeners = newNodeGroup.containerListeners;
331
- that.eventManager.setContainerListeners(oldNode);
332
- oldNode.component = comp.component;
333
- that.compareNodeSequences(oldNode.firstChild, newNodeGroup.nodes, oldNode, componentPath(comp.nodeId, ancestorComponentPath));
334
- }
335
- }
336
- else {
337
- oldNode.component = comp.component;
338
- }
339
- },
340
- });
341
- }
342
- convertNodeToInternalNode(node, ancestorComponentId) {
343
- // eslint-disable-next-line @typescript-eslint/no-this-alias
344
- const that = this;
345
- return foldNode(node, {
346
- onText(text) {
347
- return internalTextNode(that.document, text);
348
- },
349
- onVoidElement(elem) {
350
- const internalElem = internalElementNode(that.document, elem.tag, elem.nodeId, elem.attrs, elem.eventListeners, elem.props);
351
- if (elem.eventListeners.length > 0) {
352
- that.eventManager.setElementListeners(internalElem);
353
- }
354
- return internalElem;
355
- },
356
- onNonVoidElement(elem) {
357
- const internalElement = internalElementNode(that.document, elem.tag, elem.nodeId, elem.attrs, elem.eventListeners, elem.props);
358
- if (elem.eventListeners.length > 0) {
359
- that.eventManager.setElementListeners(internalElement);
360
- }
361
- elem.children.forEach((childNode) => {
362
- internalElement.append(that.convertNodeToInternalNode(childNode, ancestorComponentId));
363
- });
364
- return internalElement;
365
- },
366
- onView(view) {
367
- const vNode = viewNode(view);
368
- const nodeGroup = view.nodes(view.params);
369
- vNode.params = view.params;
370
- vNode.containerListeners = nodeGroup.containerListeners;
371
- nodeGroup.nodes.forEach((childNode) => {
372
- vNode.append(that.convertNodeToInternalNode(childNode, ancestorComponentId));
373
- });
374
- that.eventManager.setContainerListeners(vNode);
375
- return vNode;
376
- },
377
- onComponent(comp) {
378
- const compId = componentPath(comp.nodeId, ancestorComponentId).format();
379
- const existingComp = that.components[compId];
380
- if (existingComp) {
381
- detach(existingComp);
382
- that.compareNodes(existingComp, comp, ancestorComponentId);
383
- return existingComp;
384
- }
385
- const cNode = componentNode(comp.component, comp.nodeId);
386
- if (comp.componentEventListeners.length > 0) {
387
- cNode.componentEventListeners = comp.componentEventListeners;
388
- that.eventManager.setContainerListeners(cNode);
389
- }
390
- that.injectComponentCss(comp.component);
391
- that.components[compId] = cNode;
392
- that.addedComponents.push(componentPath(comp.nodeId, ancestorComponentId));
393
- return cNode;
394
- },
395
- });
396
- }
397
- // private compareNodes(
398
- // oldNode: InternalNode,
399
- // newNode: Node<unknown, unknown>,
400
- // parent: RealElement,
401
- // prevSibling: RealNode | null,
402
- // ancestorComponentId: ComponentId
403
- // ): RealNode | null {
404
- // if (typeof (newNode) === 'string') {
405
- // if (oldNode._type === 'InternalTextNode') {
406
- // if (oldNode.text !== newNode) {
407
- // oldNode.realNode.nodeValue = newNode
408
- // }
409
- // return oldNode.realNode
410
- // }
411
- // this.removeNode(oldNode)
412
- // return this.addNode1(newNode, parent, prevSibling, ancestorComponentId)
413
- // }
414
- // switch (newNode._type) {
415
- // case 'Element': {
416
- // if (
417
- // oldNode._type === 'InternalElementNode' &&
418
- // newNode.tag === oldNode.tag
419
- // ) {
420
- // this.compareElements(oldNode, newNode)
421
- // return oldNode.realNode
422
- // } else {
423
- // this.removeNode(oldNode)
424
- // return this.addNode1(newNode, parent, prevSibling, ancestorComponentId)
425
- // }
426
- // }
427
- // case 'Component': {
428
- // return todo()
429
- // }
430
- // case 'View': {
431
- // return todo()
432
- // }
433
- // }
434
- // }
435
- /**
436
- * Return an old node that can be compared to `newNode`.
437
- *
438
- * If the old node represent the same node as `newNode`, return it.
439
- *
440
- * If the same node isn't found, return the first node if it is `comparable`,
441
- * otherwise return undefined. (We don't move nodes if they are comparable but
442
- * not the same).
443
- */
444
- findCorrespondingOldNode(newNode, oldNodes, ancestorComponentPath) {
445
- if (typeof newNode !== "string" && newNode._type === "Component") {
446
- const registeredComponent = this.components[componentPath(newNode.nodeId, ancestorComponentPath).format()];
447
- if (registeredComponent) {
448
- return registeredComponent;
449
- }
450
- }
451
- let next = oldNodes;
452
- while (next) {
453
- if (getNodesRelationship(next, newNode) === "same") {
454
- return next;
455
- }
456
- next = next.nextSibling;
457
- }
458
- if (oldNodes) {
459
- if (getNodesRelationship(oldNodes, newNode) === "comparable") {
460
- return oldNodes;
461
- }
462
- }
463
- return undefined;
464
- }
465
- }
466
- // private removeNode(_node: InternalNode): void {
467
- // }
468
- // private compareElements(
469
- // _oldNode: InternalElementNode,
470
- // _newNode: Element<unknown, unknown>
471
- // ): void { }
472
- // }
473
- function getNodesRelationship(oldNode, newNode) {
474
- if (typeof newNode === "string") {
475
- return oldNode._type === "InternalTextNode" ? "comparable" : "unrelated";
476
- }
477
- if (oldNode._type === "InternalTextNode") {
478
- return "unrelated";
479
- }
480
- switch (newNode._type) {
481
- case "Element": {
482
- if (oldNode._type === "InternalElementNode") {
483
- if (newNode.nodeId) {
484
- if (oldNode.nodeId) {
485
- return newNode.nodeId.eq(oldNode.nodeId) ? "same" : "unrelated";
486
- }
487
- }
488
- else if (oldNode.nodeId) {
489
- return "unrelated";
490
- }
491
- const oldId = getId(oldNode.attrs);
492
- const newId = getId(newNode.attrs);
493
- if (newId) {
494
- if (oldId) {
495
- return oldId === newId ? "same" : "unrelated";
496
- }
497
- else {
498
- return "unrelated";
499
- }
500
- }
501
- else if (oldId) {
502
- return "unrelated";
503
- }
504
- return oldNode.tag === newNode.tag ? "comparable" : "unrelated";
505
- }
506
- else {
507
- return "unrelated";
508
- }
509
- }
510
- case "View":
511
- if (oldNode._type === "ViewNode") {
512
- return newNode.nodeId.eq(oldNode.nodeId) ? "same" : "unrelated";
513
- }
514
- else {
515
- return "unrelated";
516
- }
517
- case "Component":
518
- if (oldNode._type === "ComponentNode") {
519
- return newNode.nodeId.eq(oldNode.nodeId) ? "same" : "unrelated";
520
- }
521
- else {
522
- return "unrelated";
523
- }
524
- }
525
- }
526
- export function foldTree(root, ancestorComponentPath, init, f) {
527
- let acc = init;
528
- function visit(n, ancestorComponentPath, moveThroushSiblings) {
529
- acc = f(n, ancestorComponentPath, acc);
530
- switch (n._type) {
531
- case "InternalTextNode": {
532
- break;
533
- }
534
- case "InternalElementNode":
535
- case "ViewNode": {
536
- if (n.firstChild) {
537
- visit(n.firstChild, ancestorComponentPath, true);
538
- }
539
- break;
540
- }
541
- case "ComponentNode": {
542
- if (n.firstChild) {
543
- visit(n.firstChild, componentPath(n.nodeId, ancestorComponentPath), true);
544
- }
545
- break;
546
- }
547
- default: {
548
- exhaustivenessCheck(n);
549
- }
550
- }
551
- if (moveThroushSiblings) {
552
- let next = n.nextSibling;
553
- while (next) {
554
- visit(next, ancestorComponentPath, false);
555
- next = next.nextSibling;
556
- }
557
- }
558
- }
559
- visit(root, ancestorComponentPath, false);
560
- return acc;
561
- }
@@ -1,11 +0,0 @@
1
- import { type DbName, type DbVersion, type ObjectStore } from '../db';
2
- import type { DbEffect } from '../db/effects';
3
- import { type DbError } from '../db/errors';
4
- import type { DbSetupEffect } from '../db/setup';
5
- import { type Result } from '../utils/result';
6
- export declare class DbManager {
7
- private openDatabases;
8
- open(db: DbName, version: DbVersion, setup: (oldVersion: DbVersion) => DbSetupEffect<void>, callback: (result: Result<void, DbError>) => void): void;
9
- runTransaction(db: DbName, objectStores: readonly ObjectStore[], mode: 'readonly' | 'readwrite', effect: DbEffect<void>, callback: (result: Result<void, DbError>) => void): void;
10
- }
11
- //# sourceMappingURL=dbmgr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dbmgr.d.ts","sourceRoot":"","sources":["../../src/internal/dbmgr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,OAAO,CAAA;AAChF,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAA;AAC1D,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,aAAa,CAAA;AAGlE,OAAO,EAAoB,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE/D,qBAAa,SAAS;IACpB,OAAO,CAAC,aAAa,CAAiC;IAEtD,IAAI,CACF,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,CAAC,UAAU,EAAE,SAAS,KAAK,aAAa,CAAC,IAAI,CAAC,EACrD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,IAAI,GAChD,IAAI;IA4DP,cAAc,CACZ,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,SAAS,WAAW,EAAE,EACpC,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EACtB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,IAAI,GAChD,IAAI;CAoCR"}