jaxs 0.4.0 → 0.4.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.
- package/dist/jaxs.d.ts +246 -232
- package/dist/jaxs.js +94 -77
- package/dist/jaxs.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/jaxs.d.ts
CHANGED
|
@@ -13,112 +13,229 @@ declare module "state/equality" {
|
|
|
13
13
|
export const areEqual: (oldValue: any, newValue: any) => any;
|
|
14
14
|
}
|
|
15
15
|
declare module "state/store-updater" {
|
|
16
|
-
import type {
|
|
17
|
-
export class
|
|
18
|
-
store:
|
|
19
|
-
constructor(store:
|
|
20
|
-
update(updater:
|
|
16
|
+
import type { Store, StoreUpdaterOrValue, StoreUpdaterFunction, StoreUpdatersCollection } from "types";
|
|
17
|
+
export class StoreUpdaterBase<T> {
|
|
18
|
+
store: Store<T>;
|
|
19
|
+
constructor(store: Store<T>);
|
|
20
|
+
update(updater: StoreUpdaterOrValue<T>): void;
|
|
21
21
|
reset(): void;
|
|
22
22
|
get value(): T;
|
|
23
|
-
addUpdaterFunction(name: string, updater:
|
|
24
|
-
addUpdaterFunctions(updaters:
|
|
23
|
+
addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T>): void;
|
|
24
|
+
addUpdaterFunctions(updaters: StoreUpdatersCollection<T>): void;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
declare module "state/updaters/list" {
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
export class
|
|
28
|
+
import { StoreListSorterFunction, StoreUpdaterFunction } from "types";
|
|
29
|
+
import { StoreUpdaterBase } from "state/store-updater";
|
|
30
|
+
export class StoreUpdaterList<T> extends StoreUpdaterBase<T[]> {
|
|
31
|
+
addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T[]>): void;
|
|
31
32
|
push(element: T): void;
|
|
32
33
|
pop(): T;
|
|
33
34
|
unshift(element: T): void;
|
|
34
35
|
shift(): T;
|
|
35
|
-
addSorter(name: string, sorter:
|
|
36
|
-
sortBy(sorter:
|
|
36
|
+
addSorter(name: string, sorter: StoreListSorterFunction<T>): void;
|
|
37
|
+
sortBy(sorter: StoreListSorterFunction<T>): void;
|
|
37
38
|
insertAt(index: number, item: T): void;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
declare module "state/store" {
|
|
41
|
-
import type {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
parent: JaxsState;
|
|
47
|
-
value: T;
|
|
48
|
-
};
|
|
49
|
-
type JaxsStoreDataUpdater<T> = (originalValue: T) => T;
|
|
50
|
-
export type JaxsStoreUpdateValue<T> = T | JaxsStoreDataUpdater<T>;
|
|
51
|
-
export type JaxsStoreUpdaterFunction<T> = (value: T, ...args: any[]) => T;
|
|
52
|
-
export type JaxStoreUpdatersCollection<T> = Record<string, JaxsStoreUpdaterFunction<T>>;
|
|
53
|
-
export class JaxsStore<T> {
|
|
54
|
-
parent: JaxsState;
|
|
55
|
-
name: JaxsStoreName;
|
|
56
|
-
updater: JaxsStoreUpdater<T>;
|
|
42
|
+
import type { State, StoreDataUpdater, StoreInitializationOptions, StoreListSorterFunction, StoreUpdaterFunction, StoreUpdaterOrValue, StoreUpdatersCollection, StoreUpdater } from "types";
|
|
43
|
+
export class Store<T> {
|
|
44
|
+
parent: State;
|
|
45
|
+
name: string;
|
|
46
|
+
updater: StoreUpdater<T>;
|
|
57
47
|
_value: T;
|
|
58
48
|
initialState: T;
|
|
59
|
-
constructor(options:
|
|
49
|
+
constructor(options: StoreInitializationOptions<T>);
|
|
60
50
|
get ['value'](): T;
|
|
61
51
|
set ['value'](value: T);
|
|
62
|
-
update(updater:
|
|
52
|
+
update(updater: StoreUpdaterOrValue<T>): void;
|
|
63
53
|
updateValue(newValue: T): void;
|
|
64
|
-
getUpdatedValue(updater:
|
|
65
|
-
addUpdaters(updaters:
|
|
66
|
-
addUpdater(name: string, updater:
|
|
67
|
-
addSorter(name: string, sorter:
|
|
54
|
+
getUpdatedValue(updater: StoreDataUpdater<T>): T;
|
|
55
|
+
addUpdaters(updaters: StoreUpdatersCollection<any>): void;
|
|
56
|
+
addUpdater(name: string, updater: StoreUpdaterFunction<any>): void;
|
|
57
|
+
addSorter(name: string, sorter: StoreListSorterFunction<T>): void;
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
declare module "state/updaters/boolean" {
|
|
71
|
-
import {
|
|
72
|
-
|
|
61
|
+
import { StoreUpdaterFunction } from "types";
|
|
62
|
+
import { StoreUpdaterBase } from "state/store-updater";
|
|
63
|
+
export class StoreUpdaterBoolean extends StoreUpdaterBase<boolean> {
|
|
73
64
|
toggle(): void;
|
|
74
65
|
setTrue(): void;
|
|
75
66
|
setFalse(): void;
|
|
67
|
+
addUpdaterFunction(name: string, updater: StoreUpdaterFunction<boolean>): void;
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
declare module "state/updaters/object" {
|
|
79
|
-
import {
|
|
80
|
-
|
|
71
|
+
import { StoreUpdaterFunction } from "types";
|
|
72
|
+
import { StoreUpdaterBase } from "state/store-updater";
|
|
73
|
+
export class StoreUpdaterObject<T> extends StoreUpdaterBase<T> {
|
|
74
|
+
addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T>): void;
|
|
81
75
|
updateAttribute(name: keyof T, value: T[keyof T]): void;
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
declare module "state/index" {
|
|
85
|
-
import {
|
|
86
|
-
import {
|
|
87
|
-
import {
|
|
88
|
-
import {
|
|
89
|
-
import type { StoreValue } from "types";
|
|
90
|
-
export { JaxsStoreUpdater } from "state/store-updater";
|
|
91
|
-
export type JaxsStatePublisher = (event: string, payload: any) => void;
|
|
92
|
-
export type JaxsStateTransactionUpdater = (collection: JaxsStoresCollection) => void;
|
|
93
|
-
export type JaxsStoreName = string;
|
|
94
|
-
type JaxsStoresCollection = Record<string, JaxsStore<any>>;
|
|
79
|
+
import { Store } from "state/store";
|
|
80
|
+
import { StoreUpdaterBoolean } from "state/updaters/boolean";
|
|
81
|
+
import { StoreUpdaterList } from "state/updaters/list";
|
|
82
|
+
import { StoreUpdaterObject } from "state/updaters/object";
|
|
83
|
+
import type { StatePublisher, StateTransactionUpdater, StoresCollection, StoreValue } from "types";
|
|
95
84
|
export const eventName = "state";
|
|
96
|
-
export class
|
|
97
|
-
publisher:
|
|
98
|
-
stores:
|
|
85
|
+
export class State {
|
|
86
|
+
publisher: StatePublisher;
|
|
87
|
+
stores: StoresCollection;
|
|
99
88
|
eventNamePrefix: string;
|
|
100
|
-
notifications: Set<
|
|
89
|
+
notifications: Set<string>;
|
|
101
90
|
inTransaction: boolean;
|
|
102
|
-
constructor(publisher:
|
|
103
|
-
create<T>(name:
|
|
104
|
-
createBoolean(name:
|
|
105
|
-
createRecord<T>(name:
|
|
106
|
-
createList<T>(name:
|
|
107
|
-
store(name:
|
|
108
|
-
get(name:
|
|
109
|
-
getAll(names:
|
|
110
|
-
notify(name:
|
|
111
|
-
update(name:
|
|
112
|
-
transaction(updater:
|
|
91
|
+
constructor(publisher: StatePublisher);
|
|
92
|
+
create<T>(name: string, initialState: T): Store<T>;
|
|
93
|
+
createBoolean(name: string, initialState: boolean): Store<boolean>;
|
|
94
|
+
createRecord<T>(name: string, initialState: T): Store<T>;
|
|
95
|
+
createList<T>(name: string, initialState: T[]): Store<T[]>;
|
|
96
|
+
store(name: string): Store<any>;
|
|
97
|
+
get(name: string): StoreValue;
|
|
98
|
+
getAll(names: string[]): {};
|
|
99
|
+
notify(name: string): void;
|
|
100
|
+
update(name: string, newValue: any): void;
|
|
101
|
+
transaction(updater: StateTransactionUpdater): void;
|
|
113
102
|
publishAll(): void;
|
|
114
|
-
publish(name:
|
|
115
|
-
event(name:
|
|
103
|
+
publish(name: string): void;
|
|
104
|
+
event(name: string): string;
|
|
105
|
+
}
|
|
106
|
+
export const createState: (publisher: StatePublisher) => State;
|
|
107
|
+
export { Store, StoreUpdaterBoolean, StoreUpdaterList, StoreUpdaterObject };
|
|
108
|
+
}
|
|
109
|
+
declare module "bus/exact-subscriptions" {
|
|
110
|
+
import { ExactSubscriptionData, BusListener, Unsubscribe } from "types";
|
|
111
|
+
export class ExactSubscriptions {
|
|
112
|
+
lookup: Record<string, ExactSubscriptionData<any>[]>;
|
|
113
|
+
constructor();
|
|
114
|
+
add<T>(matcher: string, listener: BusListener<T>, index: number): Unsubscribe;
|
|
115
|
+
remove<T>(subscription: ExactSubscriptionData<T>): void;
|
|
116
|
+
matches(event: string): ExactSubscriptionData<any>[];
|
|
117
|
+
ensureArrayFor(matcher: string): void;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
declare module "bus/fuzzy-subscriptions" {
|
|
121
|
+
import { FuzzySubscriptionData, BusListener, Unsubscribe } from "types";
|
|
122
|
+
export class FuzzySubscriptions {
|
|
123
|
+
lookup: FuzzySubscriptionData<any>[];
|
|
124
|
+
constructor();
|
|
125
|
+
add<T>(matcher: RegExp, listener: BusListener<T>, index: number): Unsubscribe;
|
|
126
|
+
remove<T>(subscription: FuzzySubscriptionData<T>): void;
|
|
127
|
+
matches(event: string): FuzzySubscriptionData<any>[];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
declare module "bus/index" {
|
|
131
|
+
import { BusEventMatcher, BusListener, Unsubscribe, AppAdditionListenerOptions, BusOptions } from "types";
|
|
132
|
+
import { ExactSubscriptions } from "bus/exact-subscriptions";
|
|
133
|
+
import { FuzzySubscriptions } from "bus/fuzzy-subscriptions";
|
|
134
|
+
class JaxsBus {
|
|
135
|
+
options?: AppAdditionListenerOptions;
|
|
136
|
+
exactSubscriptions: ExactSubscriptions;
|
|
137
|
+
fuzzySubscriptions: FuzzySubscriptions;
|
|
138
|
+
currentIndex: number;
|
|
139
|
+
constructor();
|
|
140
|
+
subscribe<T>(matcher: BusEventMatcher, listener: BusListener<T>): Unsubscribe;
|
|
141
|
+
publish<T>(event: string, payload: T): void;
|
|
142
|
+
addListenerOptions(options: AppAdditionListenerOptions): void;
|
|
143
|
+
listenerOptions(event: string): BusOptions;
|
|
144
|
+
}
|
|
145
|
+
const createBus: () => {
|
|
146
|
+
bus: JaxsBus;
|
|
147
|
+
publish: (event: string, payload: any) => void;
|
|
148
|
+
subscribe: (matcher: BusEventMatcher, listener: BusListener<any>) => Unsubscribe;
|
|
149
|
+
};
|
|
150
|
+
export { createBus, JaxsBus, ExactSubscriptions, FuzzySubscriptions };
|
|
151
|
+
}
|
|
152
|
+
declare module "rendering/templates/root" {
|
|
153
|
+
import type { JaxsElement, JaxsNodes, RenderKit, Renderable, JaxsNode } from "types";
|
|
154
|
+
export class Root {
|
|
155
|
+
template: Renderable;
|
|
156
|
+
selector: string;
|
|
157
|
+
renderKit: RenderKit;
|
|
158
|
+
dom: JaxsNodes;
|
|
159
|
+
parentElement?: JaxsElement | null;
|
|
160
|
+
constructor(template: Renderable, selector: string, renderKit: RenderKit);
|
|
161
|
+
renderAndAttach(renderKit: RenderKit): void;
|
|
162
|
+
render(renderKit: RenderKit): JaxsNode[];
|
|
163
|
+
attach(): void;
|
|
164
|
+
getParentElement(): Element;
|
|
165
|
+
}
|
|
166
|
+
export const render: (template: Renderable, selector: string, renderKit: RenderKit) => Root;
|
|
167
|
+
}
|
|
168
|
+
declare module "navigation/events" {
|
|
169
|
+
export const linkNavigationEvent = "go-to-href";
|
|
170
|
+
export const locationChangeEvent = "navigation:location-change";
|
|
171
|
+
export const routeChangeEvent = "navigation:route-change";
|
|
172
|
+
}
|
|
173
|
+
declare module "navigation/route-state" {
|
|
174
|
+
import { State } from "state/index";
|
|
175
|
+
export const createRouteState: (state: State) => void;
|
|
176
|
+
}
|
|
177
|
+
declare module "navigation/find-href" {
|
|
178
|
+
export const findHref: (node: HTMLElement) => string;
|
|
179
|
+
}
|
|
180
|
+
declare module "navigation/navigate" {
|
|
181
|
+
import { BusOptions } from "types";
|
|
182
|
+
export const navigate: (path: string, { publish, window }: BusOptions) => void;
|
|
183
|
+
}
|
|
184
|
+
declare module "navigation/on-link-click" {
|
|
185
|
+
import { BusOptions } from "types";
|
|
186
|
+
export const onLinkClick: (domEvent: MouseEvent, options: BusOptions) => void;
|
|
187
|
+
}
|
|
188
|
+
declare module "navigation/extract-query-params" {
|
|
189
|
+
export const extractQueryParams: (queryString: string) => {};
|
|
190
|
+
}
|
|
191
|
+
declare module "navigation/on-location-change" {
|
|
192
|
+
import { BusOptions } from "types";
|
|
193
|
+
export const onLocationChange: (_: null, listenerOptions: BusOptions) => void;
|
|
194
|
+
}
|
|
195
|
+
declare module "navigation/start" {
|
|
196
|
+
import type { App } from "app/index";
|
|
197
|
+
export const subscribeToNavigation: (app: App) => void;
|
|
198
|
+
export const subscribeToHistoryChange: (app: App) => void;
|
|
199
|
+
export const publishLocation: (app: App) => void;
|
|
200
|
+
export const startNavigation: (app: App) => void;
|
|
201
|
+
}
|
|
202
|
+
declare module "app/index" {
|
|
203
|
+
import type { Renderable, RenderKit, Subscribe, PublishFunction } from "types";
|
|
204
|
+
import type { State } from "state/index";
|
|
205
|
+
import type { JaxsBus } from "bus/index";
|
|
206
|
+
import { Root } from "rendering/templates/root";
|
|
207
|
+
export class App {
|
|
208
|
+
window: Window;
|
|
209
|
+
document: Document;
|
|
210
|
+
publish: PublishFunction<any>;
|
|
211
|
+
subscribe: Subscribe;
|
|
212
|
+
bus: JaxsBus;
|
|
213
|
+
state: State;
|
|
214
|
+
renderKit: RenderKit;
|
|
215
|
+
roots: Root[];
|
|
216
|
+
constructor({ window, document, publish, subscribe, bus, state, renderKit }: {
|
|
217
|
+
window: any;
|
|
218
|
+
document: any;
|
|
219
|
+
publish: any;
|
|
220
|
+
subscribe: any;
|
|
221
|
+
bus: any;
|
|
222
|
+
state: any;
|
|
223
|
+
renderKit: any;
|
|
224
|
+
});
|
|
225
|
+
render(template: Renderable, selector: string): Root;
|
|
226
|
+
startNavigation(): void;
|
|
116
227
|
}
|
|
117
|
-
export const createState: (publisher: JaxsStatePublisher) => JaxsState;
|
|
118
|
-
export { JaxsStore, BooleanUpdater, ListUpdater, ObjectUpdater };
|
|
119
228
|
}
|
|
120
229
|
declare module "types" {
|
|
121
|
-
import {
|
|
230
|
+
import type { State } from "state/index";
|
|
231
|
+
import type { Store } from "state/store";
|
|
232
|
+
import type { StoreUpdaterBase } from "state/store-updater";
|
|
233
|
+
import type { StoreUpdaterBoolean } from "state/updaters/boolean";
|
|
234
|
+
import type { StoreUpdaterList } from "state/updaters/list";
|
|
235
|
+
import type { StoreUpdaterObject } from "state/updaters/object";
|
|
236
|
+
export type { App } from "app/index";
|
|
237
|
+
export { State, Store, StoreUpdaterBase, StoreUpdaterBoolean, StoreUpdaterList, StoreUpdaterObject, };
|
|
238
|
+
export type StoreUpdater<T> = StoreUpdaterBase<T> | StoreUpdaterObject<T> | StoreUpdaterBoolean | StoreUpdaterList<T>;
|
|
122
239
|
export type TextValue = string | number;
|
|
123
240
|
export interface JsxIded {
|
|
124
241
|
__jsx?: string;
|
|
@@ -132,9 +249,9 @@ declare module "types" {
|
|
|
132
249
|
busEvent: string;
|
|
133
250
|
listener: EventListener;
|
|
134
251
|
};
|
|
135
|
-
export type
|
|
252
|
+
export type EventMaps = Record<string, EventMap>;
|
|
136
253
|
interface JsxEventMapped {
|
|
137
|
-
eventMaps:
|
|
254
|
+
eventMaps: EventMaps;
|
|
138
255
|
}
|
|
139
256
|
export type JaxsElement = Element & JsxIded & JsxEventMapped;
|
|
140
257
|
export type JaxsText = Text & JsxIded;
|
|
@@ -163,13 +280,13 @@ declare module "types" {
|
|
|
163
280
|
events: TagEventAttributes;
|
|
164
281
|
};
|
|
165
282
|
export type DomPublish = (eventName: string, domEvent: Event) => void;
|
|
166
|
-
export type Subscribe = (matcher:
|
|
283
|
+
export type Subscribe = (matcher: BusEventMatcher, listener: BusListener<any>) => void;
|
|
167
284
|
export type RenderKit = {
|
|
168
285
|
document: Document;
|
|
169
286
|
window: Window;
|
|
170
287
|
publish: DomPublish;
|
|
171
288
|
subscribe: Subscribe;
|
|
172
|
-
state:
|
|
289
|
+
state: State;
|
|
173
290
|
parent?: JaxsNode | null;
|
|
174
291
|
};
|
|
175
292
|
export interface Renderable {
|
|
@@ -178,7 +295,7 @@ declare module "types" {
|
|
|
178
295
|
}
|
|
179
296
|
export type StaticTemplate = () => Renderable;
|
|
180
297
|
export type TypedTemplate<T> = (props: Props<T>) => Renderable;
|
|
181
|
-
export type
|
|
298
|
+
export type Template<T> = StaticTemplate | TypedTemplate<T>;
|
|
182
299
|
export type JsxCollection = (Renderable | TextValue)[];
|
|
183
300
|
export enum ChangeInstructionTypes {
|
|
184
301
|
removeNode = 0,
|
|
@@ -215,8 +332,8 @@ declare module "types" {
|
|
|
215
332
|
parent: JaxsElement;
|
|
216
333
|
index: number;
|
|
217
334
|
};
|
|
218
|
-
type
|
|
219
|
-
export type InstructionData = RemoveInstructionData | AttributeInstructionData | EventInstructionData | UpdateEventInstructionData | InsertNodeData |
|
|
335
|
+
type NullInstructionData = Record<string, never>;
|
|
336
|
+
export type InstructionData = RemoveInstructionData | AttributeInstructionData | EventInstructionData | UpdateEventInstructionData | InsertNodeData | NullInstructionData;
|
|
220
337
|
export type ChangeInstruction = {
|
|
221
338
|
source: JaxsNode;
|
|
222
339
|
target: JaxsNode;
|
|
@@ -224,44 +341,75 @@ declare module "types" {
|
|
|
224
341
|
data: InstructionData;
|
|
225
342
|
};
|
|
226
343
|
export type ChangeInstructions = Array<ChangeInstruction>;
|
|
227
|
-
export type
|
|
344
|
+
export type InstructionsUpdater = (instruction: ChangeInstruction) => void;
|
|
228
345
|
export type StoreValue = string | number | boolean | null | StoreValue[] | {
|
|
229
346
|
[key: string]: StoreValue;
|
|
230
347
|
};
|
|
231
348
|
export type StoreMap = {
|
|
232
349
|
[key: string]: StoreValue;
|
|
233
350
|
};
|
|
234
|
-
export type
|
|
351
|
+
export type ViewModel<ATTRIBUTES, STORE_MAP> = (storeMap: STORE_MAP) => Partial<ATTRIBUTES>;
|
|
235
352
|
export type BindSubscriptionList = string[];
|
|
236
353
|
export type BindParams<T, U> = {
|
|
237
|
-
Template:
|
|
238
|
-
viewModel?:
|
|
354
|
+
Template: Template<T>;
|
|
355
|
+
viewModel?: ViewModel<T, U>;
|
|
239
356
|
subscriptions?: BindSubscriptionList;
|
|
240
357
|
};
|
|
241
358
|
export type AppAdditionListenerOptions = {
|
|
242
|
-
state:
|
|
359
|
+
state: State;
|
|
243
360
|
document: Document;
|
|
244
361
|
window: Window;
|
|
245
362
|
};
|
|
246
363
|
export type DefaultBusListenerOptions<T> = {
|
|
247
|
-
publish:
|
|
364
|
+
publish: PublishFunction<T>;
|
|
248
365
|
eventName: string;
|
|
249
366
|
};
|
|
250
|
-
export type
|
|
251
|
-
export type
|
|
252
|
-
export type
|
|
253
|
-
export type
|
|
367
|
+
export type BusOptions = AppAdditionListenerOptions & DefaultBusListenerOptions<any>;
|
|
368
|
+
export type PublishFunction<T> = (event: string, payload: T) => void;
|
|
369
|
+
export type BusListener<T> = (payload: T, listenerKit: BusOptions) => void;
|
|
370
|
+
export type BusEventMatcher = string | RegExp;
|
|
254
371
|
export type ExactSubscriptionData<T> = {
|
|
255
|
-
listener:
|
|
372
|
+
listener: BusListener<T>;
|
|
256
373
|
index: number;
|
|
257
374
|
matcher: string;
|
|
258
375
|
};
|
|
259
376
|
export type FuzzySubscriptionData<T> = {
|
|
260
|
-
listener:
|
|
377
|
+
listener: BusListener<T>;
|
|
261
378
|
index: number;
|
|
262
379
|
matcher: RegExp;
|
|
263
380
|
};
|
|
264
381
|
export type Unsubscribe = () => void;
|
|
382
|
+
export type CreateAppBuilderArguments = {
|
|
383
|
+
window?: Window;
|
|
384
|
+
document?: Document;
|
|
385
|
+
};
|
|
386
|
+
export type RouteState = {
|
|
387
|
+
host: string;
|
|
388
|
+
path: string;
|
|
389
|
+
query: Record<string, string>;
|
|
390
|
+
};
|
|
391
|
+
export type AttributesWithChildren<T> = Props<T> & {
|
|
392
|
+
children?: JsxCollection;
|
|
393
|
+
};
|
|
394
|
+
export type DiffPair = {
|
|
395
|
+
source: JaxsNode;
|
|
396
|
+
target: JaxsNode;
|
|
397
|
+
};
|
|
398
|
+
export type CompileChildren = (sourceList: JaxsNodes, targetList: JaxsNodes, parent: JaxsElement) => ChangeInstructions;
|
|
399
|
+
export type StatePublisher = (event: string, payload: any) => void;
|
|
400
|
+
export type StateTransactionUpdater = (collection: StoresCollection) => void;
|
|
401
|
+
export type StoresCollection = Record<string, Store<any>>;
|
|
402
|
+
export type StoreInitializationOptions<T> = {
|
|
403
|
+
name: string;
|
|
404
|
+
parent: State;
|
|
405
|
+
value: T;
|
|
406
|
+
};
|
|
407
|
+
export type StoreDataUpdater<T> = (originalValue: T) => T;
|
|
408
|
+
export type UpdaterValue<T> = boolean | T | T[];
|
|
409
|
+
export type StoreUpdaterOrValue<T> = UpdaterValue<T> | StoreDataUpdater<T>;
|
|
410
|
+
export type StoreUpdaterFunction<T> = (value: UpdaterValue<T>, ...args: any[]) => T;
|
|
411
|
+
export type StoreUpdatersCollection<T> = Record<string, StoreUpdaterFunction<T>>;
|
|
412
|
+
export type StoreListSorterFunction<T> = (left: T, right: T) => number;
|
|
265
413
|
}
|
|
266
414
|
declare module "rendering/dom/tag" {
|
|
267
415
|
import type { JaxsElement, TagAttributes, TagEventAttributes, DomPublish, RenderKit } from "types";
|
|
@@ -301,12 +449,9 @@ declare module "rendering/templates/children/svg" {
|
|
|
301
449
|
export const withSvgFlag: (isSvg: boolean) => (template: Renderable) => Renderable;
|
|
302
450
|
}
|
|
303
451
|
declare module "rendering/templates/children/normalize" {
|
|
304
|
-
import { JsxCollection, Renderable,
|
|
452
|
+
import { JsxCollection, Renderable, AttributesWithChildren } from "types";
|
|
305
453
|
export const normalizeJsxChildren: (jsxChildren: JsxCollection, isSvg: boolean) => Renderable[];
|
|
306
454
|
export const normalizeToArray: <T>(children: T | T[]) => T[];
|
|
307
|
-
type AttributesWithChildren<T> = Props<T> & {
|
|
308
|
-
children?: JsxCollection;
|
|
309
|
-
};
|
|
310
455
|
export const ensureJsxChildrenArray: <T>(maybeChildren?: JsxCollection, attributes?: AttributesWithChildren<T>) => JsxCollection;
|
|
311
456
|
}
|
|
312
457
|
declare module "rendering/templates/tag/attributes-and-events" {
|
|
@@ -360,155 +505,26 @@ declare module "rendering/templates/tag" {
|
|
|
360
505
|
}
|
|
361
506
|
}
|
|
362
507
|
declare module "rendering/jsx" {
|
|
363
|
-
import type { JsxCollection, Props,
|
|
508
|
+
import type { JsxCollection, Props, Template, Renderable } from "types";
|
|
364
509
|
import { Children } from "rendering/templates/children";
|
|
365
510
|
const jsx: {
|
|
366
|
-
<T>(type: string |
|
|
511
|
+
<T>(type: string | Template<T>, attributes: Props<T>, ...children: JsxCollection): Renderable;
|
|
367
512
|
fragment<T>(attributes: Props<T>, maybeChildren: JsxCollection): Children;
|
|
368
513
|
};
|
|
369
514
|
export { jsx };
|
|
370
515
|
}
|
|
371
|
-
declare module "bus/exact-subscriptions" {
|
|
372
|
-
import { ExactSubscriptionData, JaxsBusListener, Unsubscribe } from "types";
|
|
373
|
-
export class ExactSubscriptions {
|
|
374
|
-
lookup: Record<string, ExactSubscriptionData<any>[]>;
|
|
375
|
-
constructor();
|
|
376
|
-
add<T>(matcher: string, listener: JaxsBusListener<T>, index: number): Unsubscribe;
|
|
377
|
-
remove<T>(subscription: ExactSubscriptionData<T>): void;
|
|
378
|
-
matches(event: string): ExactSubscriptionData<any>[];
|
|
379
|
-
ensureArrayFor(matcher: string): void;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
declare module "bus/fuzzy-subscriptions" {
|
|
383
|
-
import { FuzzySubscriptionData, JaxsBusListener, Unsubscribe } from "types";
|
|
384
|
-
export class FuzzySubscriptions {
|
|
385
|
-
lookup: FuzzySubscriptionData<any>[];
|
|
386
|
-
constructor();
|
|
387
|
-
add<T>(matcher: RegExp, listener: JaxsBusListener<T>, index: number): Unsubscribe;
|
|
388
|
-
remove<T>(subscription: FuzzySubscriptionData<T>): void;
|
|
389
|
-
matches(event: string): FuzzySubscriptionData<any>[];
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
declare module "bus/index" {
|
|
393
|
-
import { JaxsBusEventMatcher, JaxsBusListener, Unsubscribe, AppAdditionListenerOptions, JaxsBusOptions } from "types";
|
|
394
|
-
import { ExactSubscriptions } from "bus/exact-subscriptions";
|
|
395
|
-
import { FuzzySubscriptions } from "bus/fuzzy-subscriptions";
|
|
396
|
-
class JaxsBus {
|
|
397
|
-
options?: AppAdditionListenerOptions;
|
|
398
|
-
exactSubscriptions: ExactSubscriptions;
|
|
399
|
-
fuzzySubscriptions: FuzzySubscriptions;
|
|
400
|
-
currentIndex: number;
|
|
401
|
-
constructor();
|
|
402
|
-
subscribe<T>(matcher: JaxsBusEventMatcher, listener: JaxsBusListener<T>): Unsubscribe;
|
|
403
|
-
publish<T>(event: string, payload: T): void;
|
|
404
|
-
addListenerOptions(options: AppAdditionListenerOptions): void;
|
|
405
|
-
listenerOptions(event: string): JaxsBusOptions;
|
|
406
|
-
}
|
|
407
|
-
const createBus: () => {
|
|
408
|
-
bus: JaxsBus;
|
|
409
|
-
publish: (event: string, payload: any) => void;
|
|
410
|
-
subscribe: (matcher: JaxsBusEventMatcher, listener: JaxsBusListener<any>) => Unsubscribe;
|
|
411
|
-
};
|
|
412
|
-
export { createBus, JaxsBus, ExactSubscriptions, FuzzySubscriptions };
|
|
413
|
-
}
|
|
414
|
-
declare module "rendering/templates/root" {
|
|
415
|
-
import type { JaxsElement, JaxsNodes, RenderKit, Renderable, JaxsNode } from "types";
|
|
416
|
-
export class Root {
|
|
417
|
-
template: Renderable;
|
|
418
|
-
selector: string;
|
|
419
|
-
renderKit: RenderKit;
|
|
420
|
-
dom: JaxsNodes;
|
|
421
|
-
parentElement?: JaxsElement | null;
|
|
422
|
-
constructor(template: Renderable, selector: string, renderKit: RenderKit);
|
|
423
|
-
renderAndAttach(renderKit: RenderKit): void;
|
|
424
|
-
render(renderKit: RenderKit): JaxsNode[];
|
|
425
|
-
attach(): void;
|
|
426
|
-
getParentElement(): Element;
|
|
427
|
-
}
|
|
428
|
-
export const render: (template: Renderable, selector: string, renderKit: RenderKit) => Root;
|
|
429
|
-
}
|
|
430
|
-
declare module "navigation/events" {
|
|
431
|
-
export const linkNavigationEvent = "go-to-href";
|
|
432
|
-
export const locationChangeEvent = "navigation:location-change";
|
|
433
|
-
export const routeChangeEvent = "navigation:route-change";
|
|
434
|
-
}
|
|
435
|
-
declare module "navigation/route-state" {
|
|
436
|
-
import { JaxsState } from "state/index";
|
|
437
|
-
export type RouteState = {
|
|
438
|
-
host: string;
|
|
439
|
-
path: string;
|
|
440
|
-
query: Record<string, string>;
|
|
441
|
-
};
|
|
442
|
-
export const createRouteState: (state: JaxsState) => void;
|
|
443
|
-
}
|
|
444
|
-
declare module "navigation/find-href" {
|
|
445
|
-
export const findHref: (node: HTMLElement) => string;
|
|
446
|
-
}
|
|
447
|
-
declare module "navigation/navigate" {
|
|
448
|
-
import { JaxsBusOptions } from "types";
|
|
449
|
-
export const navigate: (path: string, { publish, window }: JaxsBusOptions) => void;
|
|
450
|
-
}
|
|
451
|
-
declare module "navigation/on-link-click" {
|
|
452
|
-
import { JaxsBusOptions } from "types";
|
|
453
|
-
export const onLinkClick: (domEvent: MouseEvent, options: JaxsBusOptions) => void;
|
|
454
|
-
}
|
|
455
|
-
declare module "navigation/extract-query-params" {
|
|
456
|
-
export const extractQueryParams: (queryString: string) => {};
|
|
457
|
-
}
|
|
458
|
-
declare module "navigation/on-location-change" {
|
|
459
|
-
import { JaxsBusOptions } from "types";
|
|
460
|
-
export const onLocationChange: (_: null, listenerOptions: JaxsBusOptions) => void;
|
|
461
|
-
}
|
|
462
|
-
declare module "navigation/start" {
|
|
463
|
-
import type { App } from "app/index";
|
|
464
|
-
export const subscribeToNavigation: (app: App) => void;
|
|
465
|
-
export const subscribeToHistoryChange: (app: App) => void;
|
|
466
|
-
export const publishLocation: (app: App) => void;
|
|
467
|
-
export const startNavigation: (app: App) => void;
|
|
468
|
-
}
|
|
469
|
-
declare module "app/index" {
|
|
470
|
-
import type { Renderable, RenderKit, Subscribe, JaxsPublishFunction } from "types";
|
|
471
|
-
import type { JaxsState } from "state/index";
|
|
472
|
-
import type { JaxsBus } from "bus/index";
|
|
473
|
-
import { Root } from "rendering/templates/root";
|
|
474
|
-
export class App {
|
|
475
|
-
window: Window;
|
|
476
|
-
document: Document;
|
|
477
|
-
publish: JaxsPublishFunction<any>;
|
|
478
|
-
subscribe: Subscribe;
|
|
479
|
-
bus: JaxsBus;
|
|
480
|
-
state: JaxsState;
|
|
481
|
-
renderKit: RenderKit;
|
|
482
|
-
roots: Root[];
|
|
483
|
-
constructor({ window, document, publish, subscribe, bus, state, renderKit }: {
|
|
484
|
-
window: any;
|
|
485
|
-
document: any;
|
|
486
|
-
publish: any;
|
|
487
|
-
subscribe: any;
|
|
488
|
-
bus: any;
|
|
489
|
-
state: any;
|
|
490
|
-
renderKit: any;
|
|
491
|
-
});
|
|
492
|
-
render(template: Renderable, selector: string): Root;
|
|
493
|
-
startNavigation(): void;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
516
|
declare module "app/builder" {
|
|
497
517
|
import { App } from "app/index";
|
|
498
518
|
import { JaxsBus } from "bus/index";
|
|
499
|
-
import {
|
|
500
|
-
import {
|
|
501
|
-
type CreateAppBuilderArguments = {
|
|
502
|
-
window?: Window;
|
|
503
|
-
document?: Document;
|
|
504
|
-
};
|
|
519
|
+
import { State } from "state/index";
|
|
520
|
+
import { PublishFunction, Subscribe, RenderKit, CreateAppBuilderArguments } from "types";
|
|
505
521
|
class AppBuilder {
|
|
506
522
|
window: Window;
|
|
507
523
|
document: Document;
|
|
508
|
-
publish:
|
|
524
|
+
publish: PublishFunction<any>;
|
|
509
525
|
subscribe: Subscribe;
|
|
510
526
|
bus: JaxsBus;
|
|
511
|
-
state:
|
|
527
|
+
state: State;
|
|
512
528
|
renderKit: RenderKit;
|
|
513
529
|
constructor(domEnvironment: CreateAppBuilderArguments);
|
|
514
530
|
setup(): App;
|
|
@@ -574,8 +590,7 @@ declare module "rendering/update/instructions/nodes/text" {
|
|
|
574
590
|
export const compileForText: (source: Text, target: Text) => ChangeInstructions;
|
|
575
591
|
}
|
|
576
592
|
declare module "rendering/update/instructions/node" {
|
|
577
|
-
import type {
|
|
578
|
-
type CompileChildren = (sourceList: JaxsNodes, targetList: JaxsNodes, parent: JaxsElement) => ChangeInstructions;
|
|
593
|
+
import type { JaxsNode, ChangeInstructions, CompileChildren } from "types";
|
|
579
594
|
export const compileForNode: (source: JaxsNode, target: JaxsNode, compileChildren: CompileChildren) => ChangeInstructions;
|
|
580
595
|
}
|
|
581
596
|
declare module "rendering/update/instructions/collection" {
|
|
@@ -587,10 +602,10 @@ declare module "rendering/update/perform-change" {
|
|
|
587
602
|
export const performChange: (source: JaxsNodes, target: JaxsNodes, parent: JaxsElement) => void;
|
|
588
603
|
}
|
|
589
604
|
declare module "rendering/templates/bound" {
|
|
590
|
-
import { JaxsElement, JaxsNodes, Props,
|
|
605
|
+
import { JaxsElement, JaxsNodes, Props, Template, RenderKit, ViewModel, BindParams, BindSubscriptionList } from "types";
|
|
591
606
|
export class Bound<ATTRIBUTES, STATE_MAP> {
|
|
592
|
-
Template:
|
|
593
|
-
viewModel:
|
|
607
|
+
Template: Template<ATTRIBUTES>;
|
|
608
|
+
viewModel: ViewModel<ATTRIBUTES, STATE_MAP>;
|
|
594
609
|
attributes: Partial<Props<ATTRIBUTES>>;
|
|
595
610
|
subscriptions: BindSubscriptionList;
|
|
596
611
|
dom: JaxsNodes;
|
|
@@ -619,7 +634,6 @@ declare module "navigation/index" {
|
|
|
619
634
|
import { onLocationChange } from "navigation/on-location-change";
|
|
620
635
|
import { createRouteState } from "navigation/route-state";
|
|
621
636
|
import * as start from "navigation/start";
|
|
622
|
-
export type { RouteState } from "navigation/route-state";
|
|
623
637
|
export { events, extractQueryParams, findHref, navigate, onLinkClick, onLocationChange, createRouteState, start, };
|
|
624
638
|
}
|
|
625
639
|
declare module "jaxs" {
|
package/dist/jaxs.js
CHANGED
|
@@ -119,12 +119,12 @@ class Et {
|
|
|
119
119
|
return new yt(this.type, this.attributes).generate();
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
122
|
+
const At = (e, t, ...s) => typeof e == "string" ? new Et(e, t, s) : e(vt(t, s));
|
|
123
|
+
At.fragment = (e, t) => {
|
|
124
124
|
const s = j(t, e);
|
|
125
125
|
return new O(s);
|
|
126
126
|
};
|
|
127
|
-
class
|
|
127
|
+
class St {
|
|
128
128
|
constructor(t, s, n) {
|
|
129
129
|
this.template = t, this.selector = s, this.renderKit = n, this.dom = [];
|
|
130
130
|
}
|
|
@@ -143,10 +143,10 @@ class At {
|
|
|
143
143
|
return this.renderKit.document.querySelector(this.selector);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
const
|
|
147
|
-
const n = new
|
|
146
|
+
const xt = (e, t, s) => {
|
|
147
|
+
const n = new St(e, t, s);
|
|
148
148
|
return n.renderAndAttach(s), n;
|
|
149
|
-
}, $ = "go-to-href", m = "navigation:location-change", M = "navigation:route-change",
|
|
149
|
+
}, $ = "go-to-href", m = "navigation:location-change", M = "navigation:route-change", wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
150
150
|
__proto__: null,
|
|
151
151
|
linkNavigationEvent: $,
|
|
152
152
|
locationChangeEvent: m,
|
|
@@ -162,56 +162,56 @@ const St = (e, t, s) => {
|
|
|
162
162
|
return t && t.getAttribute("href") || "";
|
|
163
163
|
}, D = (e, { publish: t, window: s }) => {
|
|
164
164
|
s.history.pushState(null, "", e), t(m, null);
|
|
165
|
-
},
|
|
165
|
+
}, U = (e, t) => {
|
|
166
166
|
if (!e || !e.target) return;
|
|
167
167
|
e.preventDefault();
|
|
168
168
|
const s = T(e.target);
|
|
169
169
|
D(s, t);
|
|
170
|
-
},
|
|
170
|
+
}, z = (e) => e.replace(/^\?/, "").split("&").reduce((t, s) => {
|
|
171
171
|
if (!s) return t;
|
|
172
172
|
const n = s.split("=");
|
|
173
173
|
return t[n[0]] = n[1], t;
|
|
174
|
-
}, {}),
|
|
175
|
-
const { state: s, publish: n, window: r } = t, { host: o, pathname: a, search: h } = r.location, i = a, d =
|
|
174
|
+
}, {}), L = (e, t) => {
|
|
175
|
+
const { state: s, publish: n, window: r } = t, { host: o, pathname: a, search: h } = r.location, i = a, d = z(h), u = {
|
|
176
176
|
host: o,
|
|
177
177
|
path: i,
|
|
178
178
|
query: d
|
|
179
179
|
};
|
|
180
180
|
s.store("route").update(u), n(M, u);
|
|
181
|
-
}, U = (e) => {
|
|
182
|
-
const { subscribe: t } = e;
|
|
183
|
-
t($, z);
|
|
184
181
|
}, B = (e) => {
|
|
182
|
+
const { subscribe: t } = e;
|
|
183
|
+
t($, U);
|
|
184
|
+
}, P = (e) => {
|
|
185
185
|
const { publish: t, subscribe: s, state: n, window: r } = e;
|
|
186
|
-
F(n), r.addEventListener("popstate", () => t(m, null)), s(m,
|
|
187
|
-
}, K = (e) => {
|
|
188
|
-
setTimeout(() => e.publish(m, null), 0);
|
|
186
|
+
F(n), r.addEventListener("popstate", () => t(m, null)), s(m, L);
|
|
189
187
|
}, V = (e) => {
|
|
190
|
-
|
|
191
|
-
},
|
|
188
|
+
setTimeout(() => e.publish(m, null), 0);
|
|
189
|
+
}, K = (e) => {
|
|
190
|
+
P(e), B(e), V(e);
|
|
191
|
+
}, _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
192
192
|
__proto__: null,
|
|
193
|
-
publishLocation:
|
|
194
|
-
startNavigation:
|
|
195
|
-
subscribeToHistoryChange:
|
|
196
|
-
subscribeToNavigation:
|
|
193
|
+
publishLocation: V,
|
|
194
|
+
startNavigation: K,
|
|
195
|
+
subscribeToHistoryChange: P,
|
|
196
|
+
subscribeToNavigation: B
|
|
197
197
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
198
198
|
class R {
|
|
199
199
|
constructor({ window: t, document: s, publish: n, subscribe: r, bus: o, state: a, renderKit: h }) {
|
|
200
200
|
this.window = t, this.document = s, this.publish = n, this.subscribe = r, this.bus = o, this.state = a, this.renderKit = h, this.roots = [];
|
|
201
201
|
}
|
|
202
202
|
render(t, s) {
|
|
203
|
-
const n =
|
|
203
|
+
const n = xt(t, s, this.renderKit);
|
|
204
204
|
return this.roots.push(n), n;
|
|
205
205
|
}
|
|
206
206
|
startNavigation() {
|
|
207
|
-
|
|
207
|
+
K(this);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
211
211
|
__proto__: null,
|
|
212
212
|
App: R
|
|
213
213
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
214
|
-
class
|
|
214
|
+
class q {
|
|
215
215
|
constructor() {
|
|
216
216
|
this.lookup = {};
|
|
217
217
|
}
|
|
@@ -234,7 +234,7 @@ class J {
|
|
|
234
234
|
this.lookup[t] || (this.lookup[t] = []);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
class
|
|
237
|
+
class J {
|
|
238
238
|
constructor() {
|
|
239
239
|
this.lookup = [];
|
|
240
240
|
}
|
|
@@ -257,7 +257,7 @@ class q {
|
|
|
257
257
|
}
|
|
258
258
|
class H {
|
|
259
259
|
constructor() {
|
|
260
|
-
this.exactSubscriptions = new
|
|
260
|
+
this.exactSubscriptions = new q(), this.fuzzySubscriptions = new J(), this.currentIndex = 0;
|
|
261
261
|
}
|
|
262
262
|
subscribe(t, s) {
|
|
263
263
|
let n;
|
|
@@ -299,18 +299,18 @@ const I = () => {
|
|
|
299
299
|
};
|
|
300
300
|
}, me = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
301
301
|
__proto__: null,
|
|
302
|
-
ExactSubscriptions:
|
|
303
|
-
FuzzySubscriptions:
|
|
302
|
+
ExactSubscriptions: q,
|
|
303
|
+
FuzzySubscriptions: J,
|
|
304
304
|
JaxsBus: H,
|
|
305
305
|
createBus: I
|
|
306
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
306
|
+
}, Symbol.toStringTag, { value: "Module" })), b = (e) => Array.isArray(e), g = (e) => e !== null && !b(e) && typeof e == "object", Nt = (e, t) => e === t, jt = (e, t) => Object.keys(e).length === Object.keys(t).length, kt = (e, t) => !(g(e) && g(t)) || !jt(e, t) ? !1 : Object.keys(e).every((s) => {
|
|
307
307
|
const n = e[s], r = t[s];
|
|
308
308
|
return E(n, r);
|
|
309
|
-
}), Ot = (e, t) => !(
|
|
309
|
+
}), Ot = (e, t) => !(b(e) && b(t)) || e.length !== t.length ? !1 : e.every((s, n) => {
|
|
310
310
|
const r = t[n];
|
|
311
311
|
return E(s, r);
|
|
312
|
-
}), E = (e, t) => g(e) ? kt(e, t) :
|
|
313
|
-
class
|
|
312
|
+
}), E = (e, t) => g(e) ? kt(e, t) : b(e) ? Ot(e, t) : Nt(e, t);
|
|
313
|
+
class f {
|
|
314
314
|
constructor(t) {
|
|
315
315
|
this.store = t;
|
|
316
316
|
}
|
|
@@ -334,7 +334,13 @@ class b {
|
|
|
334
334
|
this.addUpdaterFunction(s, t[s]);
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
|
-
class
|
|
337
|
+
class A extends f {
|
|
338
|
+
addUpdaterFunction(t, s) {
|
|
339
|
+
this.constructor.prototype[t] = (...n) => {
|
|
340
|
+
const r = s(this.value, ...n);
|
|
341
|
+
this.update(r);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
338
344
|
push(t) {
|
|
339
345
|
const s = [...this.value, t];
|
|
340
346
|
this.update(s);
|
|
@@ -367,7 +373,7 @@ class x extends b {
|
|
|
367
373
|
}
|
|
368
374
|
class y {
|
|
369
375
|
constructor(t) {
|
|
370
|
-
this.name = t.name, this.parent = t.parent, this._value = t.value, this.initialState = structuredClone(t.value), this.updater = new
|
|
376
|
+
this.name = t.name, this.parent = t.parent, this._value = t.value, this.initialState = structuredClone(t.value), this.updater = new f(this);
|
|
371
377
|
}
|
|
372
378
|
get value() {
|
|
373
379
|
return this._value;
|
|
@@ -395,10 +401,10 @@ class y {
|
|
|
395
401
|
this.updater.addUpdaterFunction(t, s);
|
|
396
402
|
}
|
|
397
403
|
addSorter(t, s) {
|
|
398
|
-
this.updater instanceof
|
|
404
|
+
this.updater instanceof A && this.updater.addSorter(t, s);
|
|
399
405
|
}
|
|
400
406
|
}
|
|
401
|
-
class Q extends
|
|
407
|
+
class Q extends f {
|
|
402
408
|
toggle() {
|
|
403
409
|
const t = !this.value;
|
|
404
410
|
this.update(t);
|
|
@@ -409,17 +415,29 @@ class Q extends b {
|
|
|
409
415
|
setFalse() {
|
|
410
416
|
this.update(!1);
|
|
411
417
|
}
|
|
418
|
+
addUpdaterFunction(t, s) {
|
|
419
|
+
this.constructor.prototype[t] = (...n) => {
|
|
420
|
+
const r = s(this.value, ...n);
|
|
421
|
+
this.update(r);
|
|
422
|
+
};
|
|
423
|
+
}
|
|
412
424
|
}
|
|
413
|
-
class W extends
|
|
425
|
+
class W extends f {
|
|
426
|
+
addUpdaterFunction(t, s) {
|
|
427
|
+
this.constructor.prototype[t] = (...n) => {
|
|
428
|
+
const r = s(this.value, ...n);
|
|
429
|
+
this.update(r);
|
|
430
|
+
};
|
|
431
|
+
}
|
|
414
432
|
updateAttribute(t, s) {
|
|
415
433
|
const n = { ...this.value };
|
|
416
434
|
n[t] = s, this.update(n);
|
|
417
435
|
}
|
|
418
436
|
}
|
|
419
|
-
const
|
|
437
|
+
const S = "state";
|
|
420
438
|
class G {
|
|
421
439
|
constructor(t) {
|
|
422
|
-
this.publisher = t, this.stores = {}, this.eventNamePrefix =
|
|
440
|
+
this.publisher = t, this.stores = {}, this.eventNamePrefix = S, this.notifications = /* @__PURE__ */ new Set(), this.inTransaction = !1;
|
|
423
441
|
}
|
|
424
442
|
create(t, s) {
|
|
425
443
|
const n = new y({
|
|
@@ -439,7 +457,7 @@ class G {
|
|
|
439
457
|
}
|
|
440
458
|
createList(t, s) {
|
|
441
459
|
const n = this.create(t, s);
|
|
442
|
-
return n.updater = new
|
|
460
|
+
return n.updater = new A(n), n;
|
|
443
461
|
}
|
|
444
462
|
store(t) {
|
|
445
463
|
return this.stores[t] || new y({
|
|
@@ -480,14 +498,13 @@ class G {
|
|
|
480
498
|
}
|
|
481
499
|
const X = (e) => new G(e), be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
482
500
|
__proto__: null,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
ObjectUpdater: W,
|
|
501
|
+
State: G,
|
|
502
|
+
Store: y,
|
|
503
|
+
StoreUpdaterBoolean: Q,
|
|
504
|
+
StoreUpdaterList: A,
|
|
505
|
+
StoreUpdaterObject: W,
|
|
489
506
|
createState: X,
|
|
490
|
-
eventName:
|
|
507
|
+
eventName: S
|
|
491
508
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
492
509
|
class $t {
|
|
493
510
|
constructor(t) {
|
|
@@ -559,27 +576,27 @@ const ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
559
576
|
target: t,
|
|
560
577
|
data: s,
|
|
561
578
|
type: c.addAttribute
|
|
562
|
-
}),
|
|
579
|
+
}), Ut = (e, t, s) => ({
|
|
563
580
|
source: e,
|
|
564
581
|
target: t,
|
|
565
582
|
data: s,
|
|
566
583
|
type: c.updateAttribute
|
|
567
|
-
}),
|
|
584
|
+
}), zt = (e, t, s) => ({
|
|
568
585
|
source: e,
|
|
569
586
|
target: t,
|
|
570
587
|
data: s,
|
|
571
588
|
type: c.removeEvent
|
|
572
|
-
}),
|
|
589
|
+
}), Lt = (e, t, s) => ({
|
|
573
590
|
source: e,
|
|
574
591
|
target: t,
|
|
575
592
|
data: s,
|
|
576
593
|
type: c.addEvent
|
|
577
|
-
}),
|
|
594
|
+
}), Bt = (e, t, s) => ({
|
|
578
595
|
source: e,
|
|
579
596
|
target: t,
|
|
580
597
|
data: s,
|
|
581
598
|
type: c.updateEvent
|
|
582
|
-
}),
|
|
599
|
+
}), x = (e) => ({
|
|
583
600
|
source: e,
|
|
584
601
|
target: e,
|
|
585
602
|
// for type crap only
|
|
@@ -591,13 +608,13 @@ const ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
591
608
|
// for type crap only
|
|
592
609
|
type: c.insertNode,
|
|
593
610
|
data: t
|
|
594
|
-
}),
|
|
611
|
+
}), Pt = (e, t, s) => ({
|
|
595
612
|
source: e,
|
|
596
613
|
target: t,
|
|
597
614
|
type: c.changeValue,
|
|
598
615
|
data: s
|
|
599
|
-
}),
|
|
600
|
-
class
|
|
616
|
+
}), Vt = (e, t) => e.type > t.type ? 1 : e.type < t.type ? -1 : 0, w = { index: -1 };
|
|
617
|
+
class Kt {
|
|
601
618
|
constructor() {
|
|
602
619
|
this.map = {};
|
|
603
620
|
}
|
|
@@ -612,7 +629,7 @@ class Vt {
|
|
|
612
629
|
}
|
|
613
630
|
pullMatch(t) {
|
|
614
631
|
const s = t && t.__jsx;
|
|
615
|
-
return !s || !(this.map[s] && this.map[s].length) ?
|
|
632
|
+
return !s || !(this.map[s] && this.map[s].length) ? w : this.map[s].shift();
|
|
616
633
|
}
|
|
617
634
|
clear(t) {
|
|
618
635
|
const s = t && t.__jsx;
|
|
@@ -628,8 +645,8 @@ class Vt {
|
|
|
628
645
|
return Object.values(this.map).flat();
|
|
629
646
|
}
|
|
630
647
|
}
|
|
631
|
-
const
|
|
632
|
-
const t = new
|
|
648
|
+
const _ = (e) => {
|
|
649
|
+
const t = new Kt();
|
|
633
650
|
return t.populate(e), t;
|
|
634
651
|
}, Y = (e, t, s = !1) => {
|
|
635
652
|
const n = [], r = e.attributes, o = r.length, a = t.attributes, h = a.length;
|
|
@@ -646,7 +663,7 @@ const w = (e) => {
|
|
|
646
663
|
}
|
|
647
664
|
}
|
|
648
665
|
u ? l.value !== u.value && n.push(
|
|
649
|
-
|
|
666
|
+
Ut(e, t, {
|
|
650
667
|
name: l.name,
|
|
651
668
|
value: u.value,
|
|
652
669
|
isSvg: s
|
|
@@ -682,13 +699,13 @@ const w = (e) => {
|
|
|
682
699
|
return o.forEach((h) => {
|
|
683
700
|
const i = n[h], d = r[h];
|
|
684
701
|
d ? d.busEvent !== i.busEvent && s.push(
|
|
685
|
-
|
|
702
|
+
Bt(e, t, {
|
|
686
703
|
name: h,
|
|
687
704
|
targetValue: d.listener,
|
|
688
705
|
sourceValue: i.listener
|
|
689
706
|
})
|
|
690
707
|
) : s.push(
|
|
691
|
-
|
|
708
|
+
zt(e, t, {
|
|
692
709
|
name: i.domEvent,
|
|
693
710
|
value: i.listener
|
|
694
711
|
})
|
|
@@ -696,17 +713,17 @@ const w = (e) => {
|
|
|
696
713
|
}), a.forEach((h) => {
|
|
697
714
|
const i = n[h], d = r[h];
|
|
698
715
|
i || s.push(
|
|
699
|
-
|
|
716
|
+
Lt(e, t, {
|
|
700
717
|
name: d.domEvent,
|
|
701
718
|
value: d.listener
|
|
702
719
|
})
|
|
703
720
|
);
|
|
704
721
|
}), s;
|
|
705
|
-
},
|
|
706
|
-
if (
|
|
722
|
+
}, qt = (e) => e.tagName !== "INPUT", Jt = (e, t) => e.value === t.value, Ht = (e, t) => {
|
|
723
|
+
if (qt(e) || Jt(e, t))
|
|
707
724
|
return [];
|
|
708
725
|
const s = e, n = t;
|
|
709
|
-
return [
|
|
726
|
+
return [Pt(s, n, { name: "value", value: n.value })];
|
|
710
727
|
}, It = (e, t) => {
|
|
711
728
|
const s = Y(e, t), n = Rt(e, t), r = Ht(e, t);
|
|
712
729
|
return s.concat(n).concat(r);
|
|
@@ -729,7 +746,7 @@ const w = (e) => {
|
|
|
729
746
|
} else e.nodeType === 3 && (n = Wt(e, t));
|
|
730
747
|
return n;
|
|
731
748
|
}, Z = (e, t, s) => {
|
|
732
|
-
const n = [], r = Xt(e, t), o =
|
|
749
|
+
const n = [], r = Xt(e, t), o = _(e), a = _(t), h = [];
|
|
733
750
|
let i = 0;
|
|
734
751
|
for (; i < r; i++) {
|
|
735
752
|
const u = e[i], l = t[i];
|
|
@@ -750,10 +767,10 @@ const w = (e) => {
|
|
|
750
767
|
)) : n.push(
|
|
751
768
|
v(l, { parent: s, index: i })
|
|
752
769
|
);
|
|
753
|
-
} else u && o.pullMatch(u).element && n.push(
|
|
770
|
+
} else u && o.pullMatch(u).element && n.push(x(u));
|
|
754
771
|
}
|
|
755
772
|
o.remaining().forEach(({ element: u }) => {
|
|
756
|
-
n.push(
|
|
773
|
+
n.push(x(u));
|
|
757
774
|
});
|
|
758
775
|
const d = h.reduce(
|
|
759
776
|
(u, { source: l, target: p }) => u.concat(
|
|
@@ -761,7 +778,7 @@ const w = (e) => {
|
|
|
761
778
|
),
|
|
762
779
|
[]
|
|
763
780
|
);
|
|
764
|
-
return n.concat(d).sort(
|
|
781
|
+
return n.concat(d).sort(Vt);
|
|
765
782
|
}, Xt = (e, t) => {
|
|
766
783
|
const s = e.length, n = t.length;
|
|
767
784
|
return s > n ? s : n;
|
|
@@ -848,7 +865,7 @@ class le {
|
|
|
848
865
|
});
|
|
849
866
|
}
|
|
850
867
|
eventName(t) {
|
|
851
|
-
return `${
|
|
868
|
+
return `${S}:${t}`;
|
|
852
869
|
}
|
|
853
870
|
}
|
|
854
871
|
const de = (e) => e, ge = ({
|
|
@@ -858,20 +875,20 @@ const de = (e) => e, ge = ({
|
|
|
858
875
|
}) => (s = s || [], t = t || de, (n) => new le({ Template: e, viewModel: t, subscriptions: s, attributes: n })), ye = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
859
876
|
__proto__: null,
|
|
860
877
|
createRouteState: F,
|
|
861
|
-
events:
|
|
862
|
-
extractQueryParams:
|
|
878
|
+
events: wt,
|
|
879
|
+
extractQueryParams: z,
|
|
863
880
|
findHref: T,
|
|
864
881
|
navigate: D,
|
|
865
|
-
onLinkClick:
|
|
866
|
-
onLocationChange:
|
|
867
|
-
start:
|
|
882
|
+
onLinkClick: U,
|
|
883
|
+
onLocationChange: L,
|
|
884
|
+
start: _t
|
|
868
885
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
869
886
|
export {
|
|
870
887
|
ve as JaxsTypes,
|
|
871
888
|
pe as appBuilding,
|
|
872
889
|
ge as bind,
|
|
873
890
|
fe as createApp,
|
|
874
|
-
|
|
891
|
+
At as jsx,
|
|
875
892
|
me as messageBus,
|
|
876
893
|
ye as navigation,
|
|
877
894
|
be as state
|
package/dist/jaxs.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis<"u"?globalThis:m||self,b(m.jaxs={}))})(this,function(m){"use strict";const b=(e,t)=>t.createElement(e),nt=(e,t)=>{for(const s in t){if(s==="__self")continue;const n=t[s].toString();s==="value"?e.value=n:e.setAttribute(s,n)}},rt=(e,t,s)=>{const n={};for(const r in t){const o=t[r],c=h=>s(o,h);e.addEventListener(r,c),n[r]={domEvent:r,busEvent:o,listener:c}}e.eventMaps=n},ot=(e,t,s,n)=>{const r=b(e,n.document);return nt(r,t),rt(r,s,n.publish),r},w="http://www.w3.org/2000/svg",it=e=>e==="svg",at=(e,t,s)=>{const n=s.createElementNS(w,e);for(const r in t)r==="__self"||r==="xmlns"||n.setAttributeNS(null,r,t[r].toString());return n},ct=e=>e.namespaceURI===w,ut=(e,t)=>t.createTextNode(e);class ht{constructor(t){this.value=t.toString(),this.isSvg=!1}render(t){const s=ut(this.value,t.document);return s.__jsx="TextNode",[s]}}const lt=e=>typeof e=="string"||typeof e=="number",dt=e=>new ht(e),pt=e=>lt(e)?dt(e):e,mt=e=>t=>(t&&(t.isSvg=t.isSvg||e),t),bt=(e,t)=>ft(e).map(pt).flat().map(mt(t)),ft=e=>Array.isArray(e)?e.flat():e?[e]:[],N=(e,t={})=>e||t.children||[],vt=(e,t="")=>{const s={},n={};for(const r in e){const o=e[r];if(r.match(/^on.+/i)){const c=r.slice(2).toLowerCase();n[c]=o?o.toString():""}else{if(o===!1)continue;r==="__source"?s.__source=e.__source:s[r]=gt(r,o,t)}}return{attributes:s,events:n}},gt=(e,t,s="")=>t==null?s:t.toString(),yt=(e,t)=>{const s=e||{},n=N(t,s);return s.children=s.children||n,s},j=(e,t,s=[])=>e.reduce(Et(t),s).flat(),Et=e=>(t,s)=>s?Array.isArray(s)?j(s,e,t):(s.render(e).forEach(n=>t.push(n)),t):t;class k{constructor(t,s=!1){this.collection=bt(t,s),this.isSvg=s}render(t,s){this.parentElement=s;const n=this.generateDom(t);return this.attachToParent(n),n}generateDom(t){return j(this.collection,t)}attachToParent(t){if(this.parentElement===void 0)return;const s=this.parentElement;t.forEach(n=>s.appendChild(n))}}class At{constructor(t,s){this.type=t,this.attributes=s}generate(){return this.attributes.key||this.sourceKey()||this.createKeyFromAttributes()}sourceKey(){if(this.attributes.__source){const{fileName:t,lineNumber:s,columnNumber:n}=this.attributes.__source;return`${t}:${s}:${n}`}}createKeyFromAttributes(){const t=this.attributes.id?`#${this.attributes.id}`:"",s=this.attributes.type?`[type=${this.attributes.type}]`:"",n=this.attributes.name?`[name=${this.attributes.name}]`:"";return`${this.type}${t}${s}${n}`}}class St{constructor(t,s,n=[],r=!1){this.type=t;const{events:o,attributes:c}=vt(s);this.events=o,this.attributes=c,this.isSvg=r||it(this.type),this.children=new k(n,this.isSvg)}render(t){const s=this.generateDom(t);return s?(this.children.render(t,s),[s]):[]}generateDom(t){return this.isSvg?this.generateSvgDom(t):this.generateHtmlDom(t)}generateHtmlDom(t){const s=ot(this.type,this.attributes,this.events,t);return s.__jsx=this.jsxKey(),s}generateSvgDom(t){const s=at(this.type,this.attributes,t.document);return s.__jsx=this.jsxKey(),s}jsxKey(){return new At(this.type,this.attributes).generate()}}const O=(e,t,...s)=>typeof e=="string"?new St(e,t,s):e(yt(t,s));O.fragment=(e,t)=>{const s=N(t,e);return new k(s)};class xt{constructor(t,s,n){this.template=t,this.selector=s,this.renderKit=n,this.dom=[]}renderAndAttach(t){this.parentElement=this.getParentElement(),this.dom=this.render({...t,parent:this.parentElement}),this.parentElement&&this.attach()}render(t){return this.template.render(t)}attach(){this.parentElement&&(this.parentElement.innerHTML=""),this.dom.forEach(t=>{this.parentElement&&this.parentElement.appendChild(t)})}getParentElement(){return this.renderKit.document.querySelector(this.selector)}}const _t=(e,t,s)=>{const n=new xt(e,t,s);return n.renderAndAttach(s),n},$="go-to-href",f="navigation:location-change",M="navigation:route-change",wt=Object.freeze(Object.defineProperty({__proto__:null,linkNavigationEvent:$,locationChangeEvent:f,routeChangeEvent:M},Symbol.toStringTag,{value:"Module"})),T=e=>{e.createRecord("route",{host:"",path:"",query:{}})},F=e=>{const t=e.closest("[href]");return t&&t.getAttribute("href")||""},D=(e,{publish:t,window:s})=>{s.history.pushState(null,"",e),t(f,null)},z=(e,t)=>{if(!e||!e.target)return;e.preventDefault();const s=F(e.target);D(s,t)},L=e=>e.replace(/^\?/,"").split("&").reduce((t,s)=>{if(!s)return t;const n=s.split("=");return t[n[0]]=n[1],t},{}),P=(e,t)=>{const{state:s,publish:n,window:r}=t,{host:o,pathname:c,search:h}=r.location,i=c,d=L(h),u={host:o,path:i,query:d};s.store("route").update(u),n(M,u)},U=e=>{const{subscribe:t}=e;t($,z)},B=e=>{const{publish:t,subscribe:s,state:n,window:r}=e;T(n),r.addEventListener("popstate",()=>t(f,null)),s(f,P)},K=e=>{setTimeout(()=>e.publish(f,null),0)},V=e=>{B(e),U(e),K(e)},Nt=Object.freeze(Object.defineProperty({__proto__:null,publishLocation:K,startNavigation:V,subscribeToHistoryChange:B,subscribeToNavigation:U},Symbol.toStringTag,{value:"Module"}));class R{constructor({window:t,document:s,publish:n,subscribe:r,bus:o,state:c,renderKit:h}){this.window=t,this.document=s,this.publish=n,this.subscribe=r,this.bus=o,this.state=c,this.renderKit=h,this.roots=[]}render(t,s){const n=_t(t,s,this.renderKit);return this.roots.push(n),n}startNavigation(){V(this)}}const jt=Object.freeze(Object.defineProperty({__proto__:null,App:R},Symbol.toStringTag,{value:"Module"}));class J{constructor(){this.lookup={}}add(t,s,n){this.ensureArrayFor(t);const r={listener:s,index:n,matcher:t};return this.lookup[t].push(r),()=>this.remove(r)}remove(t){this.lookup[t.matcher]&&(this.lookup[t.matcher]=this.lookup[t.matcher].reduce((s,n)=>(n!==t&&s.push(n),s),[]))}matches(t){return this.lookup[t]||[]}ensureArrayFor(t){this.lookup[t]||(this.lookup[t]=[])}}class q{constructor(){this.lookup=[]}add(t,s,n){const r={listener:s,index:n,matcher:t};return this.lookup.push(r),()=>this.remove(r)}remove(t){this.lookup=this.lookup.reduce((s,n)=>(n!==t&&s.push(n),s),[])}matches(t){return this.lookup.filter(s=>s.matcher.test(t))}}class H{constructor(){this.exactSubscriptions=new J,this.fuzzySubscriptions=new q,this.currentIndex=0}subscribe(t,s){let n;return typeof t=="string"?n=this.exactSubscriptions.add(t,s,this.currentIndex):n=this.fuzzySubscriptions.add(t,s,this.currentIndex),this.currentIndex+=1,n}publish(t,s){[...this.exactSubscriptions.matches(t),...this.fuzzySubscriptions.matches(t)].sort((r,o)=>r.index-o.index).forEach(r=>{r.listener(s,this.listenerOptions(t))})}addListenerOptions(t){this.options=t}listenerOptions(t){return{eventName:t,...this.options,publish:this.publish.bind(this)}}}const I=()=>{const e=new H;return{bus:e,publish:(n,r)=>e.publish(n,r),subscribe:(n,r)=>e.subscribe(n,r)}},kt=Object.freeze(Object.defineProperty({__proto__:null,ExactSubscriptions:J,FuzzySubscriptions:q,JaxsBus:H,createBus:I},Symbol.toStringTag,{value:"Module"})),g=e=>Array.isArray(e),y=e=>e!==null&&!g(e)&&typeof e=="object",Ot=(e,t)=>e===t,$t=(e,t)=>Object.keys(e).length===Object.keys(t).length,Mt=(e,t)=>!(y(e)&&y(t))||!$t(e,t)?!1:Object.keys(e).every(s=>{const n=e[s],r=t[s];return E(n,r)}),Tt=(e,t)=>!(g(e)&&g(t))||e.length!==t.length?!1:e.every((s,n)=>{const r=t[n];return E(s,r)}),E=(e,t)=>y(e)?Mt(e,t):g(e)?Tt(e,t):Ot(e,t);class v{constructor(t){this.store=t}update(t){this.store.update(t)}reset(){this.store.update(this.store.initialState)}get value(){return this.store.value}addUpdaterFunction(t,s){this.constructor.prototype[t]=(...n)=>{const r=s(this.value,...n);this.update(r)}}addUpdaterFunctions(t){for(const s in t)this.addUpdaterFunction(s,t[s])}}class A extends v{push(t){const s=[...this.value,t];this.update(s)}pop(){const t=[...this.value],s=t.pop();return this.update(t),s}unshift(t){const s=[t,...this.value];this.update(s)}shift(){const t=[...this.value],s=t.shift();return this.update(t),s}addSorter(t,s){this[t]=()=>{this.sortBy(s)}}sortBy(t){const s=[...this.value];s.sort(t),this.update(s)}insertAt(t,s){const n=[...this.value];n.splice(t,0,s),this.update(n)}}class S{constructor(t){this.name=t.name,this.parent=t.parent,this._value=t.value,this.initialState=structuredClone(t.value),this.updater=new v(this)}get value(){return this._value}set value(t){throw new Error("Cannot set value directly. Use an updater!")}update(t){if(typeof t=="function"){const s=this.getUpdatedValue(t);this.updateValue(s)}else this.updateValue(t)}updateValue(t){E(this._value,t)||(this._value=t,this.parent.notify(this.name))}getUpdatedValue(t){return t(this.value)}addUpdaters(t){this.updater.addUpdaterFunctions(t)}addUpdater(t,s){this.updater.addUpdaterFunction(t,s)}addSorter(t,s){this.updater instanceof A&&this.updater.addSorter(t,s)}}class Q extends v{toggle(){const t=!this.value;this.update(t)}setTrue(){this.update(!0)}setFalse(){this.update(!1)}}class W extends v{updateAttribute(t,s){const n={...this.value};n[t]=s,this.update(n)}}const x="state";class G{constructor(t){this.publisher=t,this.stores={},this.eventNamePrefix=x,this.notifications=new Set,this.inTransaction=!1}create(t,s){const n=new S({name:t,parent:this,value:s});return this.stores[t]=n,n}createBoolean(t,s){const n=this.create(t,s);return n.updater=new Q(n),n}createRecord(t,s){const n=this.create(t,s);return n.updater=new W(n),n}createList(t,s){const n=this.create(t,s);return n.updater=new A(n),n}store(t){return this.stores[t]||new S({name:t,parent:this,value:void 0})}get(t){return this.store(t).value}getAll(t){return t.reduce((s,n)=>(s[n]=this.get(n),s),{})}notify(t){this.inTransaction?this.notifications.add(t):this.publish(t)}update(t,s){this.store(t).update(s)}transaction(t){this.inTransaction=!0,t(this.stores),this.inTransaction=!1,this.publishAll()}publishAll(){this.notifications.forEach(t=>{this.publish(t)}),this.notifications.clear()}publish(t){this.publisher(this.event(t),{state:this,store:this.store(t)})}event(t){return`${this.eventNamePrefix}:${t}`}}const X=e=>new G(e),Ft=Object.freeze(Object.defineProperty({__proto__:null,BooleanUpdater:Q,JaxsState:G,JaxsStore:S,JaxsStoreUpdater:v,ListUpdater:A,ObjectUpdater:W,createState:X,eventName:x},Symbol.toStringTag,{value:"Module"}));class Dt{constructor(t){this.setupDomEnvironment(t)}setup(){return this.setupBus(),this.setupState(),this.addBusOptions(),this.setRenderKit(),new R({window:this.window,document:this.document,publish:this.publish,subscribe:this.subscribe,bus:this.bus,state:this.state,renderKit:this.renderKit})}setupDomEnvironment(t){t.window?(this.window=t.window,this.document=this.window.document):t.document?(this.window=t.document.defaultView,this.document=t.document):(this.window=window,this.document=document)}setupBus(){const{publish:t,subscribe:s,bus:n}=I();this.publish=t,this.subscribe=s,this.bus=n}setupState(){this.state=X(this.publish)}addBusOptions(){this.bus.addListenerOptions({state:this.state,document:this.document,window:this.window})}setRenderKit(){this.renderKit={publish:this.publish,subscribe:this.subscribe,state:this.state,document:this.document,window:this.window}}}const zt=(e={})=>{const s=new Dt(e).setup();return s.startNavigation(),s};var a=(e=>(e[e.removeNode=0]="removeNode",e[e.insertNode=1]="insertNode",e[e.replaceNode=2]="replaceNode",e[e.removeAttribute=3]="removeAttribute",e[e.addAttribute=4]="addAttribute",e[e.updateAttribute=5]="updateAttribute",e[e.removeEvent=6]="removeEvent",e[e.addEvent=7]="addEvent",e[e.updateEvent=8]="updateEvent",e[e.changeValue=9]="changeValue",e[e.changeText=10]="changeText",e))(a||{});const Lt=Object.freeze(Object.defineProperty({__proto__:null,ChangeInstructionTypes:a},Symbol.toStringTag,{value:"Module"})),Pt=(e,t)=>({source:e,target:t,type:a.changeText,data:{}}),Ut=(e,t)=>({source:e,target:t,type:a.replaceNode,data:{}}),Bt=(e,t,s)=>({source:e,target:t,data:s,type:a.removeAttribute}),Kt=(e,t,s)=>({source:e,target:t,data:s,type:a.addAttribute}),Vt=(e,t,s)=>({source:e,target:t,data:s,type:a.updateAttribute}),Rt=(e,t,s)=>({source:e,target:t,data:s,type:a.removeEvent}),Jt=(e,t,s)=>({source:e,target:t,data:s,type:a.addEvent}),qt=(e,t,s)=>({source:e,target:t,data:s,type:a.updateEvent}),Y=e=>({source:e,target:e,type:a.removeNode,data:{}}),_=(e,t)=>({target:e,source:e,type:a.insertNode,data:t}),Ht=(e,t,s)=>({source:e,target:t,type:a.changeValue,data:s}),It=(e,t)=>e.type>t.type?1:e.type<t.type?-1:0,Z={index:-1};class Qt{constructor(){this.map={}}populate(t){t.forEach((s,n)=>{const r=s.__jsx;r&&(this.map[r]=this.map[r]||[],this.map[r].push({element:s,index:n}))})}pullMatch(t){const s=t&&t.__jsx;return!s||!(this.map[s]&&this.map[s].length)?Z:this.map[s].shift()}clear(t){const s=t&&t.__jsx;if(!(s&&this.map[s]&&this.map[s].length))return;const n=this.map[s];this.map[s]=n.reduce((r,o)=>(o.element!==t&&r.push(o),r),[])}check(t){const s=t&&t.__jsx;return s&&this.map[s]?this.map[s].length>0:!1}remaining(){return Object.values(this.map).flat()}}const C=e=>{const t=new Qt;return t.populate(e),t},tt=(e,t,s=!1)=>{const n=[],r=e.attributes,o=r.length,c=t.attributes,h=c.length;let i,d,u;for(i=0;i<o;i++){u=null;const l=r.item(i);if(l){for(d=0;d<h;d++){const p=c.item(d);if(p&&l.name==p.name){u=p;break}}u?l.value!==u.value&&n.push(Vt(e,t,{name:l.name,value:u.value,isSvg:s})):n.push(Bt(e,t,{name:l.name,isSvg:s}))}}for(i=0;i<h;i++){u=null;const l=c.item(i);if(l){for(d=0;d<o;d++){const p=r.item(d);if(p&&p.name==l.name){u=p;break}}u||n.push(Kt(e,t,{name:l.name,value:l.value,isSvg:s}))}}return n},Wt=(e,t)=>{const s=[],n=e.eventMaps,r=t.eventMaps,o=Object.keys(n),c=Object.keys(r);return o.forEach(h=>{const i=n[h],d=r[h];d?d.busEvent!==i.busEvent&&s.push(qt(e,t,{name:h,targetValue:d.listener,sourceValue:i.listener})):s.push(Rt(e,t,{name:i.domEvent,value:i.listener}))}),c.forEach(h=>{const i=n[h],d=r[h];i||s.push(Jt(e,t,{name:d.domEvent,value:d.listener}))}),s},Gt=e=>e.tagName!=="INPUT",Xt=(e,t)=>e.value===t.value,Yt=(e,t)=>{if(Gt(e)||Xt(e,t))return[];const s=e,n=t;return[Ht(s,n,{name:"value",value:n.value})]},Zt=(e,t)=>{const s=tt(e,t),n=Wt(e,t),r=Yt(e,t);return s.concat(n).concat(r)},Ct=(e,t)=>tt(e,t,!0),te=(e,t)=>e.textContent!==t.textContent?[Pt(e,t)]:[],ee=(e,t,s)=>{let n=[];if(e.nodeType===1&&ct(e)){const r=e,o=t,c=Ct(r,o),h=s(r.childNodes,o.childNodes,r);n=c.concat(h)}else if(e.nodeType===1){const r=e,o=t,c=Zt(r,o),h=s(r.childNodes,o.childNodes,r);n=c.concat(h)}else e.nodeType===3&&(n=te(e,t));return n},et=(e,t,s)=>{const n=[],r=se(e,t),o=C(e),c=C(t),h=[];let i=0;for(;i<r;i++){const u=e[i],l=t[i];if(l&&c.check(l)){const p=o.pullMatch(l);c.clear(l),p.element?(p.index!==i&&n.push(_(p.element,{parent:s,index:i})),h.push({source:p.element,target:l})):u?c.check(u)?n.push(_(l,{parent:s,index:i})):(o.clear(u),n.push(Ut(u,l))):n.push(_(l,{parent:s,index:i}))}else u&&o.pullMatch(u).element&&n.push(Y(u))}o.remaining().forEach(({element:u})=>{n.push(Y(u))});const d=h.reduce((u,{source:l,target:p})=>u.concat(ee(l,p,et)),[]);return n.concat(d).sort(It)},se=(e,t)=>{const s=e.length,n=t.length;return s>n?s:n},ne=(e,t,s)=>{et(e,t,s).forEach(r=>{re(r)})},re=e=>{(fe[e.type]||oe)(e)},oe=e=>{},ie=e=>{const{source:t,target:s}=e;t.nodeValue=s.textContent},ae=e=>{const{source:t}=e;t.remove()},ce=e=>{const{target:t,data:s}=e,{parent:n,index:r}=s,o=n.childNodes[r];o?o&&o!==t&&n.insertBefore(t,o):n.appendChild(t)},ue=e=>{const{source:t,target:s}=e;t.replaceWith(s)},he=e=>{const{source:t,data:s}=e,{name:n,isSvg:r}=s;r?t.removeAttributeNS(null,n):t.removeAttribute(n)},st=e=>{const{source:t,data:s}=e,{name:n,value:r,isSvg:o}=s;o?t.setAttributeNS(null,n,r):t.setAttribute(n,r)},le=e=>{st(e)},de=e=>{const t=e.data,s=e.source,{name:n,value:r}=t;s.removeEventListener(n,r)},pe=e=>{const t=e.data,s=e.source,{name:n,value:r}=t;s.addEventListener(n,r)},me=e=>{const t=e.data,s=e.source,{name:n,sourceValue:r,targetValue:o}=t;s.removeEventListener(n,r),s.addEventListener(n,o)},be=e=>{const t=e.data,s=e.source,{value:n}=t;s.value=n},fe={[a.changeText]:ie,[a.removeNode]:ae,[a.insertNode]:ce,[a.replaceNode]:ue,[a.removeAttribute]:he,[a.addAttribute]:st,[a.updateAttribute]:le,[a.removeEvent]:de,[a.addEvent]:pe,[a.updateEvent]:me,[a.changeValue]:be};class ve{constructor({Template:t,subscriptions:s,attributes:n,viewModel:r}){this.Template=t,this.viewModel=r,this.attributes=n,this.subscriptions=s,this.dom=[],this.parentElement=null}render(t){return this.parentElement=t.parent,this.renderKit=t,this.subscribeForRerender(),this.dom=this.generateDom(t),this.dom}generateDom(t){const s={...this.attributes,...this.viewModel(t.state.getAll(this.subscriptions))},n=this.Template(s);return n?n.render(t):[]}rerender(){if(!this.parentElement&&this.dom[0]){const s=this.dom[0].parentElement;this.parentElement=s}const t=this.generateDom(this.renderKit);ne(this.dom,t,this.parentElement),this.parentElement&&(this.dom=Array.from(this.parentElement.childNodes))}subscribeForRerender(){const{subscribe:t}=this.renderKit;this.subscriptions.forEach(s=>{t(this.eventName(s),()=>this.rerender())})}eventName(t){return`${x}:${t}`}}const ge=e=>e,ye=({Template:e,viewModel:t,subscriptions:s})=>(s=s||[],t=t||ge,n=>new ve({Template:e,viewModel:t,subscriptions:s,attributes:n})),Ee=Object.freeze(Object.defineProperty({__proto__:null,createRouteState:T,events:wt,extractQueryParams:L,findHref:F,navigate:D,onLinkClick:z,onLocationChange:P,start:Nt},Symbol.toStringTag,{value:"Module"}));m.JaxsTypes=Lt,m.appBuilding=jt,m.bind=ye,m.createApp=zt,m.jsx=O,m.messageBus=kt,m.navigation=Ee,m.state=Ft,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(m,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis<"u"?globalThis:m||self,b(m.jaxs={}))})(this,function(m){"use strict";const b=(e,t)=>t.createElement(e),nt=(e,t)=>{for(const s in t){if(s==="__self")continue;const n=t[s].toString();s==="value"?e.value=n:e.setAttribute(s,n)}},rt=(e,t,s)=>{const n={};for(const r in t){const o=t[r],c=h=>s(o,h);e.addEventListener(r,c),n[r]={domEvent:r,busEvent:o,listener:c}}e.eventMaps=n},ot=(e,t,s,n)=>{const r=b(e,n.document);return nt(r,t),rt(r,s,n.publish),r},x="http://www.w3.org/2000/svg",it=e=>e==="svg",at=(e,t,s)=>{const n=s.createElementNS(x,e);for(const r in t)r==="__self"||r==="xmlns"||n.setAttributeNS(null,r,t[r].toString());return n},ct=e=>e.namespaceURI===x,ut=(e,t)=>t.createTextNode(e);class ht{constructor(t){this.value=t.toString(),this.isSvg=!1}render(t){const s=ut(this.value,t.document);return s.__jsx="TextNode",[s]}}const lt=e=>typeof e=="string"||typeof e=="number",dt=e=>new ht(e),pt=e=>lt(e)?dt(e):e,mt=e=>t=>(t&&(t.isSvg=t.isSvg||e),t),bt=(e,t)=>ft(e).map(pt).flat().map(mt(t)),ft=e=>Array.isArray(e)?e.flat():e?[e]:[],N=(e,t={})=>e||t.children||[],vt=(e,t="")=>{const s={},n={};for(const r in e){const o=e[r];if(r.match(/^on.+/i)){const c=r.slice(2).toLowerCase();n[c]=o?o.toString():""}else{if(o===!1)continue;r==="__source"?s.__source=e.__source:s[r]=gt(r,o,t)}}return{attributes:s,events:n}},gt=(e,t,s="")=>t==null?s:t.toString(),yt=(e,t)=>{const s=e||{},n=N(t,s);return s.children=s.children||n,s},j=(e,t,s=[])=>e.reduce(Et(t),s).flat(),Et=e=>(t,s)=>s?Array.isArray(s)?j(s,e,t):(s.render(e).forEach(n=>t.push(n)),t):t;class k{constructor(t,s=!1){this.collection=bt(t,s),this.isSvg=s}render(t,s){this.parentElement=s;const n=this.generateDom(t);return this.attachToParent(n),n}generateDom(t){return j(this.collection,t)}attachToParent(t){if(this.parentElement===void 0)return;const s=this.parentElement;t.forEach(n=>s.appendChild(n))}}class St{constructor(t,s){this.type=t,this.attributes=s}generate(){return this.attributes.key||this.sourceKey()||this.createKeyFromAttributes()}sourceKey(){if(this.attributes.__source){const{fileName:t,lineNumber:s,columnNumber:n}=this.attributes.__source;return`${t}:${s}:${n}`}}createKeyFromAttributes(){const t=this.attributes.id?`#${this.attributes.id}`:"",s=this.attributes.type?`[type=${this.attributes.type}]`:"",n=this.attributes.name?`[name=${this.attributes.name}]`:"";return`${this.type}${t}${s}${n}`}}class At{constructor(t,s,n=[],r=!1){this.type=t;const{events:o,attributes:c}=vt(s);this.events=o,this.attributes=c,this.isSvg=r||it(this.type),this.children=new k(n,this.isSvg)}render(t){const s=this.generateDom(t);return s?(this.children.render(t,s),[s]):[]}generateDom(t){return this.isSvg?this.generateSvgDom(t):this.generateHtmlDom(t)}generateHtmlDom(t){const s=ot(this.type,this.attributes,this.events,t);return s.__jsx=this.jsxKey(),s}generateSvgDom(t){const s=at(this.type,this.attributes,t.document);return s.__jsx=this.jsxKey(),s}jsxKey(){return new St(this.type,this.attributes).generate()}}const O=(e,t,...s)=>typeof e=="string"?new At(e,t,s):e(yt(t,s));O.fragment=(e,t)=>{const s=N(t,e);return new k(s)};class wt{constructor(t,s,n){this.template=t,this.selector=s,this.renderKit=n,this.dom=[]}renderAndAttach(t){this.parentElement=this.getParentElement(),this.dom=this.render({...t,parent:this.parentElement}),this.parentElement&&this.attach()}render(t){return this.template.render(t)}attach(){this.parentElement&&(this.parentElement.innerHTML=""),this.dom.forEach(t=>{this.parentElement&&this.parentElement.appendChild(t)})}getParentElement(){return this.renderKit.document.querySelector(this.selector)}}const _t=(e,t,s)=>{const n=new wt(e,t,s);return n.renderAndAttach(s),n},T="go-to-href",f="navigation:location-change",$="navigation:route-change",xt=Object.freeze(Object.defineProperty({__proto__:null,linkNavigationEvent:T,locationChangeEvent:f,routeChangeEvent:$},Symbol.toStringTag,{value:"Module"})),M=e=>{e.createRecord("route",{host:"",path:"",query:{}})},F=e=>{const t=e.closest("[href]");return t&&t.getAttribute("href")||""},D=(e,{publish:t,window:s})=>{s.history.pushState(null,"",e),t(f,null)},U=(e,t)=>{if(!e||!e.target)return;e.preventDefault();const s=F(e.target);D(s,t)},z=e=>e.replace(/^\?/,"").split("&").reduce((t,s)=>{if(!s)return t;const n=s.split("=");return t[n[0]]=n[1],t},{}),L=(e,t)=>{const{state:s,publish:n,window:r}=t,{host:o,pathname:c,search:h}=r.location,i=c,d=z(h),u={host:o,path:i,query:d};s.store("route").update(u),n($,u)},P=e=>{const{subscribe:t}=e;t(T,U)},B=e=>{const{publish:t,subscribe:s,state:n,window:r}=e;M(n),r.addEventListener("popstate",()=>t(f,null)),s(f,L)},V=e=>{setTimeout(()=>e.publish(f,null),0)},K=e=>{B(e),P(e),V(e)},Nt=Object.freeze(Object.defineProperty({__proto__:null,publishLocation:V,startNavigation:K,subscribeToHistoryChange:B,subscribeToNavigation:P},Symbol.toStringTag,{value:"Module"}));class R{constructor({window:t,document:s,publish:n,subscribe:r,bus:o,state:c,renderKit:h}){this.window=t,this.document=s,this.publish=n,this.subscribe=r,this.bus=o,this.state=c,this.renderKit=h,this.roots=[]}render(t,s){const n=_t(t,s,this.renderKit);return this.roots.push(n),n}startNavigation(){K(this)}}const jt=Object.freeze(Object.defineProperty({__proto__:null,App:R},Symbol.toStringTag,{value:"Module"}));class q{constructor(){this.lookup={}}add(t,s,n){this.ensureArrayFor(t);const r={listener:s,index:n,matcher:t};return this.lookup[t].push(r),()=>this.remove(r)}remove(t){this.lookup[t.matcher]&&(this.lookup[t.matcher]=this.lookup[t.matcher].reduce((s,n)=>(n!==t&&s.push(n),s),[]))}matches(t){return this.lookup[t]||[]}ensureArrayFor(t){this.lookup[t]||(this.lookup[t]=[])}}class J{constructor(){this.lookup=[]}add(t,s,n){const r={listener:s,index:n,matcher:t};return this.lookup.push(r),()=>this.remove(r)}remove(t){this.lookup=this.lookup.reduce((s,n)=>(n!==t&&s.push(n),s),[])}matches(t){return this.lookup.filter(s=>s.matcher.test(t))}}class H{constructor(){this.exactSubscriptions=new q,this.fuzzySubscriptions=new J,this.currentIndex=0}subscribe(t,s){let n;return typeof t=="string"?n=this.exactSubscriptions.add(t,s,this.currentIndex):n=this.fuzzySubscriptions.add(t,s,this.currentIndex),this.currentIndex+=1,n}publish(t,s){[...this.exactSubscriptions.matches(t),...this.fuzzySubscriptions.matches(t)].sort((r,o)=>r.index-o.index).forEach(r=>{r.listener(s,this.listenerOptions(t))})}addListenerOptions(t){this.options=t}listenerOptions(t){return{eventName:t,...this.options,publish:this.publish.bind(this)}}}const I=()=>{const e=new H;return{bus:e,publish:(n,r)=>e.publish(n,r),subscribe:(n,r)=>e.subscribe(n,r)}},kt=Object.freeze(Object.defineProperty({__proto__:null,ExactSubscriptions:q,FuzzySubscriptions:J,JaxsBus:H,createBus:I},Symbol.toStringTag,{value:"Module"})),v=e=>Array.isArray(e),y=e=>e!==null&&!v(e)&&typeof e=="object",Ot=(e,t)=>e===t,Tt=(e,t)=>Object.keys(e).length===Object.keys(t).length,$t=(e,t)=>!(y(e)&&y(t))||!Tt(e,t)?!1:Object.keys(e).every(s=>{const n=e[s],r=t[s];return E(n,r)}),Mt=(e,t)=>!(v(e)&&v(t))||e.length!==t.length?!1:e.every((s,n)=>{const r=t[n];return E(s,r)}),E=(e,t)=>y(e)?$t(e,t):v(e)?Mt(e,t):Ot(e,t);class g{constructor(t){this.store=t}update(t){this.store.update(t)}reset(){this.store.update(this.store.initialState)}get value(){return this.store.value}addUpdaterFunction(t,s){this.constructor.prototype[t]=(...n)=>{const r=s(this.value,...n);this.update(r)}}addUpdaterFunctions(t){for(const s in t)this.addUpdaterFunction(s,t[s])}}class S extends g{addUpdaterFunction(t,s){this.constructor.prototype[t]=(...n)=>{const r=s(this.value,...n);this.update(r)}}push(t){const s=[...this.value,t];this.update(s)}pop(){const t=[...this.value],s=t.pop();return this.update(t),s}unshift(t){const s=[t,...this.value];this.update(s)}shift(){const t=[...this.value],s=t.shift();return this.update(t),s}addSorter(t,s){this[t]=()=>{this.sortBy(s)}}sortBy(t){const s=[...this.value];s.sort(t),this.update(s)}insertAt(t,s){const n=[...this.value];n.splice(t,0,s),this.update(n)}}class A{constructor(t){this.name=t.name,this.parent=t.parent,this._value=t.value,this.initialState=structuredClone(t.value),this.updater=new g(this)}get value(){return this._value}set value(t){throw new Error("Cannot set value directly. Use an updater!")}update(t){if(typeof t=="function"){const s=this.getUpdatedValue(t);this.updateValue(s)}else this.updateValue(t)}updateValue(t){E(this._value,t)||(this._value=t,this.parent.notify(this.name))}getUpdatedValue(t){return t(this.value)}addUpdaters(t){this.updater.addUpdaterFunctions(t)}addUpdater(t,s){this.updater.addUpdaterFunction(t,s)}addSorter(t,s){this.updater instanceof S&&this.updater.addSorter(t,s)}}class Q extends g{toggle(){const t=!this.value;this.update(t)}setTrue(){this.update(!0)}setFalse(){this.update(!1)}addUpdaterFunction(t,s){this.constructor.prototype[t]=(...n)=>{const r=s(this.value,...n);this.update(r)}}}class W extends g{addUpdaterFunction(t,s){this.constructor.prototype[t]=(...n)=>{const r=s(this.value,...n);this.update(r)}}updateAttribute(t,s){const n={...this.value};n[t]=s,this.update(n)}}const w="state";class G{constructor(t){this.publisher=t,this.stores={},this.eventNamePrefix=w,this.notifications=new Set,this.inTransaction=!1}create(t,s){const n=new A({name:t,parent:this,value:s});return this.stores[t]=n,n}createBoolean(t,s){const n=this.create(t,s);return n.updater=new Q(n),n}createRecord(t,s){const n=this.create(t,s);return n.updater=new W(n),n}createList(t,s){const n=this.create(t,s);return n.updater=new S(n),n}store(t){return this.stores[t]||new A({name:t,parent:this,value:void 0})}get(t){return this.store(t).value}getAll(t){return t.reduce((s,n)=>(s[n]=this.get(n),s),{})}notify(t){this.inTransaction?this.notifications.add(t):this.publish(t)}update(t,s){this.store(t).update(s)}transaction(t){this.inTransaction=!0,t(this.stores),this.inTransaction=!1,this.publishAll()}publishAll(){this.notifications.forEach(t=>{this.publish(t)}),this.notifications.clear()}publish(t){this.publisher(this.event(t),{state:this,store:this.store(t)})}event(t){return`${this.eventNamePrefix}:${t}`}}const X=e=>new G(e),Ft=Object.freeze(Object.defineProperty({__proto__:null,State:G,Store:A,StoreUpdaterBoolean:Q,StoreUpdaterList:S,StoreUpdaterObject:W,createState:X,eventName:w},Symbol.toStringTag,{value:"Module"}));class Dt{constructor(t){this.setupDomEnvironment(t)}setup(){return this.setupBus(),this.setupState(),this.addBusOptions(),this.setRenderKit(),new R({window:this.window,document:this.document,publish:this.publish,subscribe:this.subscribe,bus:this.bus,state:this.state,renderKit:this.renderKit})}setupDomEnvironment(t){t.window?(this.window=t.window,this.document=this.window.document):t.document?(this.window=t.document.defaultView,this.document=t.document):(this.window=window,this.document=document)}setupBus(){const{publish:t,subscribe:s,bus:n}=I();this.publish=t,this.subscribe=s,this.bus=n}setupState(){this.state=X(this.publish)}addBusOptions(){this.bus.addListenerOptions({state:this.state,document:this.document,window:this.window})}setRenderKit(){this.renderKit={publish:this.publish,subscribe:this.subscribe,state:this.state,document:this.document,window:this.window}}}const Ut=(e={})=>{const s=new Dt(e).setup();return s.startNavigation(),s};var a=(e=>(e[e.removeNode=0]="removeNode",e[e.insertNode=1]="insertNode",e[e.replaceNode=2]="replaceNode",e[e.removeAttribute=3]="removeAttribute",e[e.addAttribute=4]="addAttribute",e[e.updateAttribute=5]="updateAttribute",e[e.removeEvent=6]="removeEvent",e[e.addEvent=7]="addEvent",e[e.updateEvent=8]="updateEvent",e[e.changeValue=9]="changeValue",e[e.changeText=10]="changeText",e))(a||{});const zt=Object.freeze(Object.defineProperty({__proto__:null,ChangeInstructionTypes:a},Symbol.toStringTag,{value:"Module"})),Lt=(e,t)=>({source:e,target:t,type:a.changeText,data:{}}),Pt=(e,t)=>({source:e,target:t,type:a.replaceNode,data:{}}),Bt=(e,t,s)=>({source:e,target:t,data:s,type:a.removeAttribute}),Vt=(e,t,s)=>({source:e,target:t,data:s,type:a.addAttribute}),Kt=(e,t,s)=>({source:e,target:t,data:s,type:a.updateAttribute}),Rt=(e,t,s)=>({source:e,target:t,data:s,type:a.removeEvent}),qt=(e,t,s)=>({source:e,target:t,data:s,type:a.addEvent}),Jt=(e,t,s)=>({source:e,target:t,data:s,type:a.updateEvent}),Y=e=>({source:e,target:e,type:a.removeNode,data:{}}),_=(e,t)=>({target:e,source:e,type:a.insertNode,data:t}),Ht=(e,t,s)=>({source:e,target:t,type:a.changeValue,data:s}),It=(e,t)=>e.type>t.type?1:e.type<t.type?-1:0,Z={index:-1};class Qt{constructor(){this.map={}}populate(t){t.forEach((s,n)=>{const r=s.__jsx;r&&(this.map[r]=this.map[r]||[],this.map[r].push({element:s,index:n}))})}pullMatch(t){const s=t&&t.__jsx;return!s||!(this.map[s]&&this.map[s].length)?Z:this.map[s].shift()}clear(t){const s=t&&t.__jsx;if(!(s&&this.map[s]&&this.map[s].length))return;const n=this.map[s];this.map[s]=n.reduce((r,o)=>(o.element!==t&&r.push(o),r),[])}check(t){const s=t&&t.__jsx;return s&&this.map[s]?this.map[s].length>0:!1}remaining(){return Object.values(this.map).flat()}}const C=e=>{const t=new Qt;return t.populate(e),t},tt=(e,t,s=!1)=>{const n=[],r=e.attributes,o=r.length,c=t.attributes,h=c.length;let i,d,u;for(i=0;i<o;i++){u=null;const l=r.item(i);if(l){for(d=0;d<h;d++){const p=c.item(d);if(p&&l.name==p.name){u=p;break}}u?l.value!==u.value&&n.push(Kt(e,t,{name:l.name,value:u.value,isSvg:s})):n.push(Bt(e,t,{name:l.name,isSvg:s}))}}for(i=0;i<h;i++){u=null;const l=c.item(i);if(l){for(d=0;d<o;d++){const p=r.item(d);if(p&&p.name==l.name){u=p;break}}u||n.push(Vt(e,t,{name:l.name,value:l.value,isSvg:s}))}}return n},Wt=(e,t)=>{const s=[],n=e.eventMaps,r=t.eventMaps,o=Object.keys(n),c=Object.keys(r);return o.forEach(h=>{const i=n[h],d=r[h];d?d.busEvent!==i.busEvent&&s.push(Jt(e,t,{name:h,targetValue:d.listener,sourceValue:i.listener})):s.push(Rt(e,t,{name:i.domEvent,value:i.listener}))}),c.forEach(h=>{const i=n[h],d=r[h];i||s.push(qt(e,t,{name:d.domEvent,value:d.listener}))}),s},Gt=e=>e.tagName!=="INPUT",Xt=(e,t)=>e.value===t.value,Yt=(e,t)=>{if(Gt(e)||Xt(e,t))return[];const s=e,n=t;return[Ht(s,n,{name:"value",value:n.value})]},Zt=(e,t)=>{const s=tt(e,t),n=Wt(e,t),r=Yt(e,t);return s.concat(n).concat(r)},Ct=(e,t)=>tt(e,t,!0),te=(e,t)=>e.textContent!==t.textContent?[Lt(e,t)]:[],ee=(e,t,s)=>{let n=[];if(e.nodeType===1&&ct(e)){const r=e,o=t,c=Ct(r,o),h=s(r.childNodes,o.childNodes,r);n=c.concat(h)}else if(e.nodeType===1){const r=e,o=t,c=Zt(r,o),h=s(r.childNodes,o.childNodes,r);n=c.concat(h)}else e.nodeType===3&&(n=te(e,t));return n},et=(e,t,s)=>{const n=[],r=se(e,t),o=C(e),c=C(t),h=[];let i=0;for(;i<r;i++){const u=e[i],l=t[i];if(l&&c.check(l)){const p=o.pullMatch(l);c.clear(l),p.element?(p.index!==i&&n.push(_(p.element,{parent:s,index:i})),h.push({source:p.element,target:l})):u?c.check(u)?n.push(_(l,{parent:s,index:i})):(o.clear(u),n.push(Pt(u,l))):n.push(_(l,{parent:s,index:i}))}else u&&o.pullMatch(u).element&&n.push(Y(u))}o.remaining().forEach(({element:u})=>{n.push(Y(u))});const d=h.reduce((u,{source:l,target:p})=>u.concat(ee(l,p,et)),[]);return n.concat(d).sort(It)},se=(e,t)=>{const s=e.length,n=t.length;return s>n?s:n},ne=(e,t,s)=>{et(e,t,s).forEach(r=>{re(r)})},re=e=>{(fe[e.type]||oe)(e)},oe=e=>{},ie=e=>{const{source:t,target:s}=e;t.nodeValue=s.textContent},ae=e=>{const{source:t}=e;t.remove()},ce=e=>{const{target:t,data:s}=e,{parent:n,index:r}=s,o=n.childNodes[r];o?o&&o!==t&&n.insertBefore(t,o):n.appendChild(t)},ue=e=>{const{source:t,target:s}=e;t.replaceWith(s)},he=e=>{const{source:t,data:s}=e,{name:n,isSvg:r}=s;r?t.removeAttributeNS(null,n):t.removeAttribute(n)},st=e=>{const{source:t,data:s}=e,{name:n,value:r,isSvg:o}=s;o?t.setAttributeNS(null,n,r):t.setAttribute(n,r)},le=e=>{st(e)},de=e=>{const t=e.data,s=e.source,{name:n,value:r}=t;s.removeEventListener(n,r)},pe=e=>{const t=e.data,s=e.source,{name:n,value:r}=t;s.addEventListener(n,r)},me=e=>{const t=e.data,s=e.source,{name:n,sourceValue:r,targetValue:o}=t;s.removeEventListener(n,r),s.addEventListener(n,o)},be=e=>{const t=e.data,s=e.source,{value:n}=t;s.value=n},fe={[a.changeText]:ie,[a.removeNode]:ae,[a.insertNode]:ce,[a.replaceNode]:ue,[a.removeAttribute]:he,[a.addAttribute]:st,[a.updateAttribute]:le,[a.removeEvent]:de,[a.addEvent]:pe,[a.updateEvent]:me,[a.changeValue]:be};class ve{constructor({Template:t,subscriptions:s,attributes:n,viewModel:r}){this.Template=t,this.viewModel=r,this.attributes=n,this.subscriptions=s,this.dom=[],this.parentElement=null}render(t){return this.parentElement=t.parent,this.renderKit=t,this.subscribeForRerender(),this.dom=this.generateDom(t),this.dom}generateDom(t){const s={...this.attributes,...this.viewModel(t.state.getAll(this.subscriptions))},n=this.Template(s);return n?n.render(t):[]}rerender(){if(!this.parentElement&&this.dom[0]){const s=this.dom[0].parentElement;this.parentElement=s}const t=this.generateDom(this.renderKit);ne(this.dom,t,this.parentElement),this.parentElement&&(this.dom=Array.from(this.parentElement.childNodes))}subscribeForRerender(){const{subscribe:t}=this.renderKit;this.subscriptions.forEach(s=>{t(this.eventName(s),()=>this.rerender())})}eventName(t){return`${w}:${t}`}}const ge=e=>e,ye=({Template:e,viewModel:t,subscriptions:s})=>(s=s||[],t=t||ge,n=>new ve({Template:e,viewModel:t,subscriptions:s,attributes:n})),Ee=Object.freeze(Object.defineProperty({__proto__:null,createRouteState:M,events:xt,extractQueryParams:z,findHref:F,navigate:D,onLinkClick:U,onLocationChange:L,start:Nt},Symbol.toStringTag,{value:"Module"}));m.JaxsTypes=zt,m.appBuilding=jt,m.bind=ye,m.createApp=Ut,m.jsx=O,m.messageBus=kt,m.navigation=Ee,m.state=Ft,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|