mount-observer 0.1.24 → 0.1.25

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/nudge.js ADDED
@@ -0,0 +1,23 @@
1
+ import { arr } from './arr.js';
2
+ /**
3
+ * Decrement "disabled" counter, remove when reaches 0
4
+ * @param el
5
+ * Optional select the attribute or attributes to remove or decrement
6
+ * @param attr
7
+ */
8
+ export function nudge(el, attr = 'disabled') {
9
+ const attrs = arr(attr);
10
+ for (const attr of attrs) {
11
+ const da = el.getAttribute(attr);
12
+ if (da !== null) {
13
+ if (da.length === 0 || da === "1") {
14
+ el.removeAttribute(attr);
15
+ if (attr === 'disabled')
16
+ el.disabled = false;
17
+ }
18
+ else {
19
+ el.setAttribute(attr, (parseInt(da) - 1).toString());
20
+ }
21
+ }
22
+ }
23
+ }
package/nudge.ts ADDED
@@ -0,0 +1,23 @@
1
+ import {arr} from './arr.js';
2
+ /**
3
+ * Decrement "disabled" counter, remove when reaches 0
4
+ * @param el
5
+ * Optional select the attribute or attributes to remove or decrement
6
+ * @param attr
7
+ */
8
+ export function nudge(el: Element, attr: string | Array<string> = 'disabled') { //TODO: Share with be-observant
9
+ const attrs = arr(attr);
10
+ for(const attr of attrs){
11
+ const da = el.getAttribute(attr);
12
+ if (da !== null) {
13
+ if (da.length === 0 || da === "1") {
14
+ el.removeAttribute(attr);
15
+ if(attr === 'disabled') (<any>el).disabled = false;
16
+ }
17
+ else {
18
+ el.setAttribute(attr, (parseInt(da) - 1).toString());
19
+ }
20
+ }
21
+ }
22
+
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
@@ -9,7 +9,7 @@
9
9
  "id-generation": "0.0.4"
10
10
  },
11
11
  "devDependencies": {
12
- "@playwright/test": "1.59.0-alpha-2026-02-28",
12
+ "@playwright/test": "1.59.1",
13
13
  "spa-ssi": "0.0.27"
14
14
  },
15
15
  "exports": {
@@ -33,6 +33,10 @@
33
33
  "default": "./arr.js",
34
34
  "types": "./arr.ts"
35
35
  },
36
+ "./nudge.js": {
37
+ "default": "./nudge.js",
38
+ "types": "./nudge.ts"
39
+ },
36
40
  "./EvtRt.js": {
37
41
  "default": "./EvtRt.js",
38
42
  "types": "./EvtRt.ts"
@@ -0,0 +1,26 @@
1
+ export interface EndUserProps{
2
+ to: string;
3
+ nudges: boolean;
4
+ on: string;
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps {
8
+ enhancedElement: Element;
9
+ resolved: boolean;
10
+ }
11
+
12
+ export type AP = AllProps;
13
+
14
+ export type PAP = Partial<AP>;
15
+
16
+ export type ProPAP = Promise<PAP>;
17
+
18
+ export type BAP = AllProps // & BEAllProps & RoundaboutReady;
19
+
20
+ export interface Actions{
21
+
22
+ hydrate(self: BAP): ProPAP;
23
+ init(self: BAP, initVals: PAP): Promise<void>
24
+ // findTarget(self: this): Promise<void>;
25
+ // handleCommit(self: this, e: KeyboardEvent): Promise<void>;
26
+ }
@@ -1,6 +1,6 @@
1
1
  // Core types for MountObserver v2 - Polyfill Supported Scenario I
2
2
 
3
- import {Spawner, EnhancementConfigBase, EnhKey} from '../assign-gingerly/types';
3
+ import {Spawner, EnhancementConfigBase, EnhKey, AttrPatterns} from '../assign-gingerly/types';
4
4
 
5
5
  export type Constructor = new (...args: any[]) => any;
6
6
 
@@ -53,7 +53,7 @@ export interface EnhConfig<T = any, Obj = Element> extends EnhancementConfigBase
53
53
  *
54
54
  * @template TKeys - String literal type for sub-observer keys when using the `with` property
55
55
  */
56
- export interface MountConfig<TKeys extends string = string> {
56
+ export interface MountConfig<TKeys extends string = string, TCustomData = unknown> {
57
57
  /**
58
58
  * CSS selector string to match elements.
59
59
  * Only elements matching this selector will be considered for mounting.
@@ -216,7 +216,7 @@ export interface MountConfig<TKeys extends string = string> {
216
216
  * Allows handlers to receive additional context-specific information.
217
217
  * Not used by MountObserver itself, but available in MountContext.
218
218
  */
219
- customData?: unknown;
219
+ customData?: TCustomData;
220
220
 
221
221
  /**
222
222
  * Sub-observer configurations for hierarchical composition.
@@ -246,8 +246,8 @@ export interface MountConfig<TKeys extends string = string> {
246
246
 
247
247
  export interface EMC<
248
248
  TKeys extends string = string,
249
- T = any, Obj = Element
250
- > extends MountConfig<TKeys>{
249
+ T = unknown, Obj = Element, TCustomData = unknown
250
+ > extends MountConfig<TKeys, TCustomData>{
251
251
  enhConfig: EnhConfig<T, Obj>
252
252
  }
253
253
 
@@ -0,0 +1,150 @@
1
+ export type Key<T = any> = keyof T & string;
2
+
3
+ export type Keysh<T = any> = Key<T> | Array<Key<T>>;
4
+
5
+ type PropsToProps<Props> = (x: Props) => (Promise<Partial<Props>> | Partial<Props>)
6
+
7
+ export interface LogicOp<Props = any, TActions = Props>{
8
+ /**
9
+ * Supported by trans-render
10
+ */
11
+ ifAllOf?: Keysh<Props>,
12
+
13
+ ifKeyIn?: Keysh<Props>,
14
+
15
+ ifNoneOf?: Keysh<Props>,
16
+
17
+ ifEquals?: Array<Key<Props>>,
18
+
19
+ ifAtLeastOneOf?: Keysh<Props>,
20
+
21
+ ifNotAllOf?: Keysh<Props>,
22
+
23
+ debug?: boolean,
24
+
25
+ delay?: number,
26
+
27
+ do?:
28
+ | Function
29
+ | (keyof TActions & string)
30
+ | PropsToProps<Props>
31
+
32
+ }
33
+
34
+ export type Actions<TProps = any, TActions = TProps> =
35
+ Partial<{[key in keyof TActions & string]: LogicOp<TProps>}>
36
+ //& Partial<{[key in `do_${keyof TActions & string}_on`]: Key<TActions> | Array<Key<TActions>> }>
37
+ ;
38
+
39
+ export type Compacts<TProps = any, TActions = TProps> =
40
+ //| Partial<{[key in `${keyof TProps & string}_to_${keyof TProps & string}` & string]: Operation<TProps> }>
41
+ | Partial<{[key in `negate_${keyof TProps & string}_to_${keyof TProps & string}`]: number}>
42
+ | Partial<{[key in `pass_length_of_${keyof TProps & string}_to_${keyof TProps & string}`]: number}>
43
+ | Partial<{[key in `echo_${keyof TProps & string}_to_${keyof TProps & string}`]: number}>
44
+ | Partial<{[key in `echo_${keyof TProps & string}_to_${keyof TProps & string}_after`]: keyof TProps}>
45
+ | Partial<{[key in `when_${keyof TProps & string}_changes_call_${keyof TActions & string}`]: number}>
46
+ | Partial<{[key in `when_${keyof TProps & string}_changes_toggle_${keyof TProps & string}`]: number}>
47
+ | Partial<{[key in `when_${keyof TProps & string}_changes_inc_${keyof TProps & string}_by`]: number}>
48
+ | Partial<{[key in `when_${keyof TProps & string}_changes_dispatch`]: string}> //TODO
49
+ ;
50
+
51
+ export type Hitches<TProps = any, TActions = TProps> =
52
+ | Partial<{[key in `when_${keyof TProps & string}_emits_${keyof TProps & string}_inc_${keyof TProps & string}_by`]: number}>
53
+ ;
54
+
55
+ export type Handlers<ETProps = any, TActions = ETProps> =
56
+ | Partial<{[key in `${keyof ETProps & string}_to_${keyof TActions & string}_on` & string]: string }>;
57
+
58
+ export type Positractions<TProps = any, TActions = TProps> =
59
+ | Array<Positraction<TProps, TActions>>;
60
+
61
+ export interface Positraction<TProps = any, TActions = TProps> extends LogicOp<TProps, TActions> {
62
+ do:
63
+ | Function
64
+ | (keyof TActions & string)
65
+ | PropsToProps<TProps>
66
+ ifKeyIn?: Array<keyof TProps & string>,
67
+ ifAllOf?: Array<keyof TProps & string>,
68
+ //ifNoneOf: Array<keyof TProps & string>,
69
+
70
+ pass?: Array<(keyof TProps & string) | number | boolean | '$0' | '$0+' | `\`${string}\``>,
71
+ assignTo?: Array<null | (keyof TProps & string)>
72
+ }
73
+
74
+ export interface RAConfig<TProps = unknown, TActions = TProps, ETProps = TProps> {
75
+ actions?: Actions<TProps,TActions>,
76
+ compacts?: Compacts<TProps, TActions>,
77
+ //onsets?: Onsets<TProps, TActions>,
78
+ handlers?: Handlers<ETProps, TActions>,
79
+ hitch?: Hitches<TProps, TActions>,
80
+ positractions?: Positractions<TProps>,
81
+ }
82
+
83
+ export interface RoundaboutOptions<TProps = unknown, TActions = TProps, ETProps = TProps> extends RAConfig<TProps, TActions, ETProps> {
84
+ vm?: TProps & TActions & RoundaboutReady,
85
+ //for enhanced elements, pass in the container, referenced via $0.
86
+ container?: EventTarget,
87
+ propagate?: keyof TProps & string | Array<keyof TProps & string>,
88
+
89
+ //mountObservers?: Set<IMountObserver>
90
+
91
+ /**
92
+ * Enable internal routing optimization for actions (default: false)
93
+ *
94
+ * When true: Action results are batched and cascaded before firing events.
95
+ * - Eliminates redundant action calls in diamond dependency patterns
96
+ * - More predictable: actions run once per logical change
97
+ * - Best for: Complex cascades, multiple properties returned from actions
98
+ *
99
+ * When false: Uses traditional approach with immediate event firing.
100
+ * - Simpler execution model, easier to debug
101
+ * - Slightly faster for simple linear cascades
102
+ * - Best for: Simple cascades, performance-critical paths
103
+ *
104
+ * Enable if you have:
105
+ * - Actions that return multiple properties
106
+ * - Multiple actions monitoring the same properties
107
+ * - Diamond dependencies (A→B, A→C, B→D, C→D)
108
+ */
109
+ internalRouting?: boolean,
110
+ }
111
+
112
+ export interface RoundaboutReady{
113
+ /**
114
+ * Allow for assigning to read only props via the "backdoor"
115
+ * Bypasses getters / setters, sets directly to (private) memory slots
116
+ * Doesn't do any notification
117
+ * Allows for nested property setting
118
+ */
119
+ covertAssignment(obj: any): Promise<void>;
120
+
121
+ /**
122
+ * fires event with name matching the name of the property when the value changes (but not via covertAssignment)
123
+ * when property is set via public interface, not (immediately) via an action method's return object
124
+ */
125
+ readonly propagator : EventTarget | undefined;
126
+
127
+ /**
128
+ *
129
+ * https://github.com/whatwg/dom/issues/1296
130
+ */
131
+ //readonly disconnectedSignal: AbortSignal
132
+
133
+ RAController: AbortController;
134
+
135
+ /**
136
+ * During this time, queues/buses continue to perform "bookkeeping"
137
+ * but doesn't process the queue until sleep property becomes falsy.
138
+ * If truthy, can call await awake() before processing should resume
139
+ * [TODO]
140
+ */
141
+ readonly sleep?: number | undefined;
142
+
143
+ awake(): Promise<void>;
144
+
145
+ //make the value sleep 1 step closer to be falsy
146
+ nudge(): void;
147
+
148
+ //make the value of sleep 1 step further away from being falsy
149
+ rock(): void;
150
+ }