flarp 2.0.1 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -251
- package/package.json +2 -2
- package/src/components/index.js +3 -1
- package/src/dom/find.js +5 -5
- package/src/index.js +24 -12
- package/src/sync/Store.js +633 -0
- package/src/sync/Sync.js +369 -0
- package/src/sync/index.js +3 -1
- package/src/xml/Node.js +8 -1
- package/src/components/FStore.js +0 -332
package/src/dom/find.js
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
* Find nearest store by searching up the DOM tree
|
|
9
9
|
*
|
|
10
10
|
* @param {Element} element - Starting element
|
|
11
|
-
* @param {string} selector - Store selector (default: 'f-
|
|
11
|
+
* @param {string} selector - Store selector (default: 'f-store')
|
|
12
12
|
* @returns {Element|null}
|
|
13
13
|
*
|
|
14
14
|
* Search order:
|
|
15
15
|
* 1. Explicit store="id" attribute
|
|
16
16
|
* 2. Scoped store from f-each
|
|
17
|
-
* 3. Nearest f-
|
|
17
|
+
* 3. Nearest f-store in same container hierarchy
|
|
18
18
|
* 4. Document-level fallback by ID proximity
|
|
19
19
|
*/
|
|
20
|
-
export function findStore(element, selector = 'f-
|
|
20
|
+
export function findStore(element, selector = 'f-store') {
|
|
21
21
|
// 1. Check explicit reference
|
|
22
22
|
const ref = element.getAttribute('store');
|
|
23
23
|
if (ref) {
|
|
@@ -34,7 +34,7 @@ export function findStore(element, selector = 'f-state') {
|
|
|
34
34
|
let current = element.parentElement;
|
|
35
35
|
|
|
36
36
|
while (current) {
|
|
37
|
-
// Search for f-
|
|
37
|
+
// Search for f-store within this ancestor (but not within nested components)
|
|
38
38
|
const store = current.querySelector(selector);
|
|
39
39
|
if (store) {
|
|
40
40
|
return store;
|
|
@@ -52,7 +52,7 @@ export function findStore(element, selector = 'f-state') {
|
|
|
52
52
|
* @param {string} selector
|
|
53
53
|
* @returns {Element[]}
|
|
54
54
|
*/
|
|
55
|
-
export function findAllStores(element, selector = 'f-
|
|
55
|
+
export function findAllStores(element, selector = 'f-store') {
|
|
56
56
|
const stores = [];
|
|
57
57
|
const seen = new Set();
|
|
58
58
|
let current = element.parentElement;
|
package/src/index.js
CHANGED
|
@@ -3,29 +3,40 @@
|
|
|
3
3
|
*
|
|
4
4
|
* XML is state. Signals are reactive. The DOM is the runtime.
|
|
5
5
|
*
|
|
6
|
+
* ## Multi-Master Sync
|
|
7
|
+
*
|
|
8
|
+
* All browser tabs are equal peers. No single source of truth.
|
|
9
|
+
* Conflicts are resolved deterministically - all tabs agree independently.
|
|
10
|
+
*
|
|
6
11
|
* @example
|
|
7
12
|
* ```html
|
|
8
|
-
* <f-
|
|
9
|
-
* <
|
|
13
|
+
* <f-store key="myapp" autosave="500">
|
|
14
|
+
* <user>
|
|
10
15
|
* <n>Alice</n>
|
|
11
|
-
* <
|
|
12
|
-
* </
|
|
13
|
-
* </f-
|
|
16
|
+
* <role>Developer</role>
|
|
17
|
+
* </user>
|
|
18
|
+
* </f-store>
|
|
14
19
|
*
|
|
15
|
-
* <
|
|
16
|
-
*
|
|
17
|
-
* <f-field path="User.Role"></f-field>
|
|
18
|
-
* </main>
|
|
20
|
+
* <f-text path="user.name"></f-text>
|
|
21
|
+
* <f-field path="user.role"></f-field>
|
|
19
22
|
*
|
|
20
23
|
* <script type="module">
|
|
21
24
|
* import 'flarp';
|
|
22
25
|
*
|
|
23
|
-
* const store = document.querySelector('f-
|
|
26
|
+
* const store = document.querySelector('f-store');
|
|
24
27
|
*
|
|
25
28
|
* store.state.when('ready', () => {
|
|
26
|
-
* const name = store.at('
|
|
29
|
+
* const name = store.at('user.name');
|
|
27
30
|
* name.subscribe(v => console.log('Name:', v));
|
|
28
31
|
* });
|
|
32
|
+
*
|
|
33
|
+
* // Handle conflicts
|
|
34
|
+
* store.onConflict(({ uuid, winner }) => {
|
|
35
|
+
* console.log(`Conflict: ${winner} won`);
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Apply external update (from server, WebSocket, etc.)
|
|
39
|
+
* store.applyRemote('<n uuid="..." rev="5-abc">Bob</n>');
|
|
29
40
|
* </script>
|
|
30
41
|
* ```
|
|
31
42
|
*/
|
|
@@ -42,6 +53,7 @@ export * as Path from './xml/Path.js';
|
|
|
42
53
|
// Sync utilities
|
|
43
54
|
export * as Persist from './sync/Persist.js';
|
|
44
55
|
export { default as Channel, Protocol } from './sync/Channel.js';
|
|
56
|
+
export { default as Sync, parseRev, createRev, compareRevisions } from './sync/Sync.js';
|
|
45
57
|
|
|
46
58
|
// DOM utilities
|
|
47
59
|
export { findStore, findAllStores, whenReady, scopedStore } from './dom/find.js';
|
|
@@ -60,4 +72,4 @@ export {
|
|
|
60
72
|
} from './components/index.js';
|
|
61
73
|
|
|
62
74
|
// Version
|
|
63
|
-
export const VERSION = '2.
|
|
75
|
+
export const VERSION = '2.1.0';
|