jaxs 0.4.3 → 0.5.0

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 CHANGED
@@ -1,641 +1,966 @@
1
- declare module "state/is" {
2
- export const isBoolean: (value: any) => value is boolean;
3
- export const isNumber: (value: any) => value is number;
4
- export const isString: (value: any) => value is string;
5
- export const isArray: (value: any) => value is any[];
6
- export const isObject: (value: any) => boolean;
7
- }
8
- declare module "state/equality" {
9
- type Object = Record<string, any>;
10
- export const areElementsEqual: (oldValue: any, newValue: any) => boolean;
11
- export const areObjectsEqual: (oldValue: Object, newValue: Object) => any;
12
- export const areArraysEqual: (oldValue: any[], newValue: any[]) => any;
13
- export const areEqual: (oldValue: any, newValue: any) => any;
14
- }
15
- declare module "state/store-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
- reset(): void;
22
- get value(): T;
23
- addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T>): void;
24
- addUpdaterFunctions(updaters: StoreUpdatersCollection<T>): void;
25
- }
26
- }
27
- declare module "state/updaters/list" {
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;
32
- push(element: T): void;
33
- pop(): T;
34
- unshift(element: T): void;
35
- shift(): T;
36
- addSorter(name: string, sorter: StoreListSorterFunction<T>): void;
37
- sortBy(sorter: StoreListSorterFunction<T>): void;
38
- insertAt(index: number, item: T): void;
39
- }
40
- }
41
- declare module "state/store" {
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>;
47
- _value: T;
48
- initialState: T;
49
- constructor(options: StoreInitializationOptions<T>);
50
- get ['value'](): T;
51
- set ['value'](value: T);
52
- update(updater: StoreUpdaterOrValue<T>): void;
53
- updateValue(newValue: T): void;
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;
58
- }
59
- }
60
- declare module "state/updaters/boolean" {
61
- import { StoreUpdaterFunction } from "types";
62
- import { StoreUpdaterBase } from "state/store-updater";
63
- export class StoreUpdaterBoolean extends StoreUpdaterBase<boolean> {
64
- toggle(): void;
65
- setTrue(): void;
66
- setFalse(): void;
67
- addUpdaterFunction(name: string, updater: StoreUpdaterFunction<boolean>): void;
68
- }
69
- }
70
- declare module "state/updaters/object" {
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;
75
- updateAttribute(name: keyof T, value: T[keyof T]): void;
76
- }
77
- }
78
- declare module "state/index" {
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";
84
- export const eventName = "state";
85
- export class State {
86
- publisher: StatePublisher;
87
- stores: StoresCollection;
88
- eventNamePrefix: string;
89
- notifications: Set<string>;
90
- inTransaction: boolean;
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;
102
- publishAll(): void;
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;
227
- }
228
- }
229
- declare module "types" {
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>;
239
- export type TextValue = string | number;
240
- export interface JsxIded {
241
- __jsx?: string;
242
- }
243
- export type JsxChangeId = {
244
- element: JaxsNode;
245
- index: number;
246
- };
247
- export type EventMap = {
248
- domEvent: string;
249
- busEvent: string;
250
- listener: EventListener;
251
- };
252
- export type EventMaps = Record<string, EventMap>;
253
- interface JsxEventMapped {
254
- eventMaps: EventMaps;
255
- }
256
- export type JaxsElement = Element & JsxIded & JsxEventMapped;
257
- export type JaxsText = Text & JsxIded;
258
- export type JaxsSvgElement = SVGElement & JsxIded;
259
- export type JaxsNode = JaxsElement | JaxsText | JaxsSvgElement;
260
- export type JaxsNodes = JaxsNode[] | NodeListOf<JaxsNode>;
261
- export type JaxsInput = HTMLInputElement & JsxIded & JsxEventMapped;
262
- type NullValues = null | undefined;
263
- export type ReactSourceObject = {
264
- fileName: string;
265
- lineNumber: string;
266
- columnNumber: string;
267
- };
268
- interface SourceMap {
269
- __source?: ReactSourceObject;
270
- }
271
- export type Props<T> = Partial<{
272
- __source: ReactSourceObject;
273
- children: JsxCollection;
274
- }> & T;
275
- export type PropValue = TextValue | NullValues | boolean | ReactSourceObject | JsxCollection;
276
- export type TagAttributes = SourceMap & Record<string, string>;
277
- export type TagEventAttributes = Record<string, string>;
278
- export type TagAttributesAndEvents = {
279
- attributes: TagAttributes;
280
- events: TagEventAttributes;
281
- };
282
- export type DomPublish = (eventName: string, domEvent: Event) => void;
283
- export type Subscribe = (matcher: BusEventMatcher, listener: BusListener<any>) => void;
284
- export type RenderKit = {
285
- document: Document;
286
- window: Window;
287
- publish: DomPublish;
288
- subscribe: Subscribe;
289
- state: State;
290
- parent?: JaxsNode | null;
291
- };
292
- export interface Renderable {
293
- render: (renderKit: RenderKit, parentElement?: JaxsElement) => JaxsNode[];
294
- }
295
- export type StaticTemplate = () => Renderable;
296
- export type TypedTemplate<T> = (props: Props<T>) => Renderable;
297
- export type Template<T> = StaticTemplate | TypedTemplate<T>;
298
- export type JsxCollection = (Renderable | TextValue)[];
299
- export enum ChangeInstructionTypes {
300
- removeNode = 0,
301
- insertNode = 1,// can be to move an existing element in the dom, or to add one
302
- replaceNode = 2,
303
- removeAttribute = 3,
304
- addAttribute = 4,
305
- updateAttribute = 5,
306
- removeEvent = 6,
307
- addEvent = 7,
308
- updateEvent = 8,
309
- changeValue = 9,
310
- changeText = 10
311
- }
312
- export type RemoveInstructionData = {
313
- name: string;
314
- isSvg?: boolean;
315
- };
316
- export type AttributeInstructionData = {
317
- name: string;
318
- value: string;
319
- isSvg?: boolean;
320
- };
321
- export type EventInstructionData = {
322
- name: string;
323
- value: EventListener;
324
- };
325
- export type UpdateEventInstructionData = {
326
- name: string;
327
- sourceValue: EventListener;
328
- targetValue: EventListener;
329
- };
330
- export type InsertNodeData = {
331
- parent: JaxsElement;
332
- index: number;
333
- };
334
- type NullInstructionData = Record<string, never>;
335
- export type InstructionData = RemoveInstructionData | AttributeInstructionData | EventInstructionData | UpdateEventInstructionData | InsertNodeData | NullInstructionData;
336
- export type ChangeInstruction = {
337
- source: JaxsNode;
338
- target: JaxsNode;
339
- type: ChangeInstructionTypes;
340
- data: InstructionData;
341
- };
342
- export type ChangeInstructions = Array<ChangeInstruction>;
343
- export type InstructionsUpdater = (instruction: ChangeInstruction) => void;
344
- export type StoreValue = string | number | boolean | null | StoreValue[] | {
345
- [key: string]: StoreValue;
346
- };
347
- export type StoreMap = {
348
- [key: string]: StoreValue;
349
- };
350
- export type ViewModel<ATTRIBUTES, STORE_MAP> = (storeMap: STORE_MAP) => Partial<ATTRIBUTES>;
351
- export type BindSubscriptionList = string[];
352
- export type BindParams<T, U> = {
353
- Template: Template<T>;
354
- viewModel?: ViewModel<T, U>;
355
- subscriptions?: BindSubscriptionList;
356
- };
357
- export type AppAdditionListenerOptions = {
358
- state: State;
359
- document: Document;
360
- window: Window;
361
- };
362
- export type DefaultBusListenerOptions<T> = {
363
- publish: PublishFunction<T>;
364
- eventName: string;
365
- };
366
- export type BusOptions = AppAdditionListenerOptions & DefaultBusListenerOptions<any>;
367
- export type PublishFunction<T> = (event: string, payload: T) => void;
368
- export type BusListener<T> = (payload: T, listenerKit: BusOptions) => void;
369
- export type BusEventMatcher = string | RegExp;
370
- export type ExactSubscriptionData<T> = {
371
- listener: BusListener<T>;
372
- index: number;
373
- matcher: string;
374
- };
375
- export type FuzzySubscriptionData<T> = {
376
- listener: BusListener<T>;
377
- index: number;
378
- matcher: RegExp;
379
- };
380
- export type Unsubscribe = () => void;
381
- export type CreateAppBuilderArguments = {
382
- window?: Window;
383
- document?: Document;
384
- };
385
- export type RouteState = {
386
- host: string;
387
- path: string;
388
- query: Record<string, string>;
389
- };
390
- export type AttributesWithChildren<T> = Props<T> & {
391
- children?: JsxCollection;
392
- };
393
- export type DiffPair = {
394
- source: JaxsNode;
395
- target: JaxsNode;
396
- };
397
- export type CompileChildren = (sourceList: JaxsNodes, targetList: JaxsNodes, parent: JaxsElement) => ChangeInstructions;
398
- export type StatePublisher = (event: string, payload: any) => void;
399
- export type StateTransactionUpdater = (collection: StoresCollection) => void;
400
- export type StoresCollection = Record<string, Store<any>>;
401
- export type StoreInitializationOptions<T> = {
402
- name: string;
403
- parent: State;
404
- value: T;
405
- };
406
- export type StoreDataUpdater<T> = (originalValue: T) => T;
407
- export type UpdaterValue<T> = boolean | T | T[];
408
- export type StoreUpdaterOrValue<T> = UpdaterValue<T> | StoreDataUpdater<T>;
409
- export type StoreUpdaterFunction<T> = (value: UpdaterValue<T>, ...args: any[]) => T;
410
- export type StoreUpdatersCollection<T> = Record<string, StoreUpdaterFunction<T>>;
411
- export type StoreListSorterFunction<T> = (left: T, right: T) => number;
412
- }
413
- declare module "rendering/dom/tag" {
414
- import type { JaxsElement, TagAttributes, TagEventAttributes, DomPublish, RenderKit } from "types";
415
- export const createNode: (type: string, document: Document) => HTMLElement;
416
- export const setAttributesOnElement: (element: Element, attributes: TagAttributes) => void;
417
- export const setEventsOnElement: (element: JaxsElement, events: TagEventAttributes, publish: DomPublish) => void;
418
- export const createDecoratedNode: (type: string, attributes: TagAttributes, events: TagEventAttributes, renderKit: RenderKit) => JaxsElement;
419
- }
420
- declare module "rendering/dom/svg" {
421
- import type { TagAttributes, JaxsElement } from "types";
422
- export const namespace = "http://www.w3.org/2000/svg";
423
- export const isSvgTag: (tagType: string, attributeNamespace?: string) => boolean;
424
- export const createSvgNode: (type: string, attributes: TagAttributes, document: Document) => JaxsElement;
425
- export const elementIsSvg: (element: JaxsElement) => boolean;
426
- }
427
- declare module "rendering/dom/text" {
428
- export const createTextNode: (value: string, document: Document) => Text;
429
- }
430
- declare module "rendering/templates/text" {
431
- import { Renderable, TextValue, RenderKit } from "types";
432
- export class TextTemplate implements Renderable {
433
- value: string;
434
- constructor(content: TextValue);
435
- render(renderKit: RenderKit): Text[];
436
- }
437
- }
438
- declare module "rendering/templates/children/text" {
439
- import { TextValue, Renderable } from "types";
440
- import { TextTemplate } from "rendering/templates/text";
441
- export const isTextValue: <T>(child: TextValue | T) => child is string | number | (T & string) | (T & number);
442
- export const textNode: (content: TextValue) => TextTemplate;
443
- export const replaceTextNodes: (child: TextValue | Renderable) => Renderable | TextTemplate;
444
- }
445
- declare module "rendering/templates/children/normalize" {
446
- import { JsxCollection, AttributesWithChildren } from "types";
447
- export const normalizeJsxChildren: (jsxChildren: JsxCollection) => (import("types").Renderable | import("rendering/templates/text").TextTemplate)[];
448
- export const normalizeToArray: <T>(children: T | T[]) => T[];
449
- export const ensureJsxChildrenArray: <T>(maybeChildren?: JsxCollection, attributes?: AttributesWithChildren<T>) => JsxCollection;
450
- }
451
- declare module "rendering/templates/tag/attributes-and-events" {
452
- import type { Props, TagAttributesAndEvents, JsxCollection } from "types";
453
- export const separateAttrsAndEvents: <T>(props: Props<T>, defaultValue?: string) => TagAttributesAndEvents;
454
- export const packageJsxAttributes: <T>(maybeAttributes?: Props<T>, maybeChildren?: JsxCollection) => Props<T>;
455
- }
456
- declare module "rendering/templates/children/render" {
457
- import { Renderable, RenderKit, JaxsNode } from "types";
458
- export const recursiveRender: (children: Renderable[], renderKit: RenderKit, rendered?: JaxsNode[]) => JaxsNode[];
459
- }
460
- declare module "rendering/templates/children" {
461
- import { JaxsElement, Renderable, JsxCollection, RenderKit, JaxsNodes, JaxsNode } from "types";
462
- export class Children implements Renderable {
463
- collection: Renderable[];
464
- parentElement?: JaxsElement;
465
- constructor(jsxChildren: JsxCollection);
466
- render(renderKit: RenderKit, parentElement: JaxsElement | undefined): JaxsNode[];
467
- generateDom(renderKit: RenderKit): JaxsNode[];
468
- attachToParent(dom: JaxsNodes): void;
469
- }
470
- }
471
- declare module "rendering/templates/tag/jsx-key" {
472
- import { TagAttributes } from "types";
473
- export class JsxKey {
474
- attributes: TagAttributes;
475
- type: string;
476
- constructor(type: string, attributes: TagAttributes);
477
- generate(): string;
478
- sourceKey(): string;
479
- createKeyFromAttributes(): string;
480
- }
481
- }
482
- declare module "rendering/templates/tag" {
483
- import type { Props, JaxsNode, TagEventAttributes, Renderable, RenderKit, TagAttributes, JsxCollection } from "types";
484
- import { Children } from "rendering/templates/children";
485
- export class Tag<T> implements Renderable {
486
- type: string;
487
- events: TagEventAttributes;
488
- attributes: TagAttributes;
489
- props: Props<T>;
490
- children: Children;
491
- isSvg: boolean;
492
- constructor(tagType: string, props: Props<T>, children?: JsxCollection);
493
- render(renderKit: RenderKit): JaxsNode[];
494
- generateDom(renderKit: RenderKit): import("types").JaxsElement;
495
- generateHtmlDom(renderKit: RenderKit): import("types").JaxsElement;
496
- generateSvgDom(renderKit: RenderKit): import("types").JaxsElement;
497
- jsxKey(): string;
498
- }
499
- }
500
- declare module "rendering/jsx" {
501
- import type { JsxCollection, Props, Template, Renderable } from "types";
502
- import { Children } from "rendering/templates/children";
503
- const jsx: {
504
- <T>(type: string | Template<T>, attributes: Props<T>, ...children: JsxCollection): Renderable;
505
- fragment<T>(attributes: Props<T>, maybeChildren: JsxCollection): Children;
506
- };
507
- export { jsx };
508
- }
509
- declare module "app/builder" {
510
- import { App } from "app/index";
511
- import { JaxsBus } from "bus/index";
512
- import { State } from "state/index";
513
- import { PublishFunction, Subscribe, RenderKit, CreateAppBuilderArguments } from "types";
514
- class AppBuilder {
515
- window: Window;
516
- document: Document;
517
- publish: PublishFunction<any>;
518
- subscribe: Subscribe;
519
- bus: JaxsBus;
520
- state: State;
521
- renderKit: RenderKit;
522
- constructor(domEnvironment: CreateAppBuilderArguments);
523
- setup(): App;
524
- setupDomEnvironment(domEnvironment: CreateAppBuilderArguments): void;
525
- setupBus(): void;
526
- setupState(): void;
527
- addBusOptions(): void;
528
- setRenderKit(): void;
529
- }
530
- const createApp: (domEnvironment?: CreateAppBuilderArguments) => App;
531
- export { App, AppBuilder, createApp };
532
- }
533
- declare module "rendering/update/instructions/instructions" {
534
- import { JaxsInput, ChangeInstruction, JaxsElement, RemoveInstructionData, AttributeInstructionData, EventInstructionData, UpdateEventInstructionData, InsertNodeData } from "types";
535
- export const changeText: (source: Text, target: Text) => ChangeInstruction;
536
- export const replaceNode: (source: JaxsElement, target: JaxsElement) => ChangeInstruction;
537
- export const removeAttribute: (source: JaxsElement, target: JaxsElement, data: RemoveInstructionData) => ChangeInstruction;
538
- export const addAttribute: (source: JaxsElement, target: JaxsElement, data: AttributeInstructionData) => ChangeInstruction;
539
- export const updateAttribute: (source: JaxsElement, target: JaxsElement, data: AttributeInstructionData) => ChangeInstruction;
540
- export const removeEvent: (source: JaxsElement, target: JaxsElement, data: EventInstructionData) => ChangeInstruction;
541
- export const addEvent: (source: JaxsElement, target: JaxsElement, data: EventInstructionData) => ChangeInstruction;
542
- export const updateEvent: (source: JaxsElement, target: JaxsElement, data: UpdateEventInstructionData) => ChangeInstruction;
543
- export const removeNode: (source: JaxsElement) => ChangeInstruction;
544
- export const insertNode: (target: JaxsElement, data: InsertNodeData) => ChangeInstruction;
545
- export const changeValue: (source: JaxsInput, target: JaxsInput, data: AttributeInstructionData) => ChangeInstruction;
546
- export const instructionsSorter: (left: ChangeInstruction, right: ChangeInstruction) => 0 | 1 | -1;
547
- }
548
- declare module "rendering/update/instructions/id-map" {
549
- import type { JaxsNode, JaxsNodes, JsxChangeId } from "types";
550
- export class IdMap {
551
- map: Record<string, JsxChangeId[]>;
552
- constructor();
553
- populate(list: JaxsNodes): void;
554
- pullMatch(element: JaxsNode): JsxChangeId;
555
- clear(element: JaxsNode): void;
556
- check(element: JaxsNode): boolean;
557
- remaining(): JsxChangeId[];
558
- }
559
- export const createIdMap: (list: JaxsNodes) => IdMap;
560
- }
561
- declare module "rendering/update/instructions/nodes/element/attributes" {
562
- import type { JaxsElement, ChangeInstructions } from "types";
563
- export const compileForAttributes: (source: JaxsElement, target: JaxsElement, isSvg?: boolean) => ChangeInstructions;
564
- }
565
- declare module "rendering/update/instructions/nodes/element/events" {
566
- import type { JaxsElement, ChangeInstructions } from "types";
567
- export const compileForEvents: (source: JaxsElement, target: JaxsElement) => ChangeInstructions;
568
- }
569
- declare module "rendering/update/instructions/nodes/input" {
570
- import { ChangeInstructions, JaxsElement } from "types";
571
- export const compileForInputValue: (sourceElement: JaxsElement, targetElement: JaxsElement) => ChangeInstructions;
572
- }
573
- declare module "rendering/update/instructions/nodes/element" {
574
- import type { JaxsElement } from "types";
575
- export const compileForElement: (source: JaxsElement, target: JaxsElement) => import("types").ChangeInstruction[];
576
- }
577
- declare module "rendering/update/instructions/nodes/svg" {
578
- import { JaxsElement } from "types";
579
- export const compileForSvg: (source: JaxsElement, target: JaxsElement) => import("types").ChangeInstructions;
580
- }
581
- declare module "rendering/update/instructions/nodes/text" {
582
- import type { ChangeInstructions } from "types";
583
- export const compileForText: (source: Text, target: Text) => ChangeInstructions;
584
- }
585
- declare module "rendering/update/instructions/node" {
586
- import type { JaxsNode, ChangeInstructions, CompileChildren } from "types";
587
- export const compileForNode: (source: JaxsNode, target: JaxsNode, compileChildren: CompileChildren) => ChangeInstructions;
588
- }
589
- declare module "rendering/update/instructions/collection" {
590
- import type { JaxsElement, JaxsNodes } from "types";
591
- export const compileCollection: (sourceList: JaxsNodes, targetList: JaxsNodes, parent: JaxsElement) => import("types").ChangeInstruction[];
592
- }
593
- declare module "rendering/update/perform-change" {
594
- import type { JaxsElement, JaxsNodes } from "types";
595
- export const performChange: (source: JaxsNodes, target: JaxsNodes, parent: JaxsElement) => void;
596
- }
597
- declare module "rendering/templates/bound" {
598
- import { JaxsElement, JaxsNodes, Props, Template, RenderKit, ViewModel, BindParams, BindSubscriptionList } from "types";
599
- export class Bound<ATTRIBUTES, STATE_MAP> {
600
- Template: Template<ATTRIBUTES>;
601
- viewModel: ViewModel<ATTRIBUTES, STATE_MAP>;
602
- attributes: Partial<Props<ATTRIBUTES>>;
603
- subscriptions: BindSubscriptionList;
604
- dom: JaxsNodes;
605
- parentElement: JaxsElement | null;
606
- renderKit?: RenderKit;
607
- constructor({ Template, subscriptions, attributes, viewModel }: {
608
- Template: any;
609
- subscriptions: any;
610
- attributes: any;
611
- viewModel: any;
612
- });
613
- render(renderKit: RenderKit): import("types").JaxsNode[];
614
- generateDom(renderKit: RenderKit): import("types").JaxsNode[];
615
- rerender(): void;
616
- subscribeForRerender(): void;
617
- eventName(storeName: string): string;
618
- }
619
- export const bind: <ATTRIBUTES, STATE_MAP>({ Template, viewModel, subscriptions, }: BindParams<ATTRIBUTES, STATE_MAP>) => (attributes: Partial<Props<ATTRIBUTES>>) => Bound<unknown, unknown>;
620
- }
621
- declare module "navigation/index" {
622
- import * as events from "navigation/events";
623
- import { extractQueryParams } from "navigation/extract-query-params";
624
- import { findHref } from "navigation/find-href";
625
- import { navigate } from "navigation/navigate";
626
- import { onLinkClick } from "navigation/on-link-click";
627
- import { onLocationChange } from "navigation/on-location-change";
628
- import { createRouteState } from "navigation/route-state";
629
- import * as start from "navigation/start";
630
- export { events, extractQueryParams, findHref, navigate, onLinkClick, onLocationChange, createRouteState, start, };
631
- }
632
- declare module "jaxs" {
633
- export { jsx } from "rendering/jsx";
634
- export { createApp } from "app/builder";
635
- export { bind } from "rendering/templates/bound";
636
- export * as JaxsTypes from "types";
637
- export * as navigation from "navigation/index";
638
- export * as appBuilding from "app/index";
639
- export * as messageBus from "bus/index";
640
- export * as state from "state/index";
1
+ declare module 'state/is' {
2
+ export const isBoolean: (value: any) => value is boolean
3
+ export const isNumber: (value: any) => value is number
4
+ export const isString: (value: any) => value is string
5
+ export const isArray: (value: any) => value is any[]
6
+ export const isObject: (value: any) => boolean
7
+ }
8
+ declare module 'state/equality' {
9
+ type Object = Record<string, any>
10
+ export const areElementsEqual: (oldValue: any, newValue: any) => boolean
11
+ export const areObjectsEqual: (oldValue: Object, newValue: Object) => any
12
+ export const areArraysEqual: (oldValue: any[], newValue: any[]) => any
13
+ export const areEqual: (oldValue: any, newValue: any) => any
14
+ }
15
+ declare module 'state/store-updater' {
16
+ import type {
17
+ Store,
18
+ StoreUpdaterOrValue,
19
+ StoreUpdaterFunction,
20
+ StoreUpdatersCollection,
21
+ } from 'types'
22
+ export class StoreUpdaterBase<T> {
23
+ store: Store<T>
24
+ constructor(store: Store<T>)
25
+ update(updater: StoreUpdaterOrValue<T>): void
26
+ reset(): void
27
+ get value(): T
28
+ addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T>): void
29
+ addUpdaterFunctions(updaters: StoreUpdatersCollection<T>): void
30
+ }
31
+ }
32
+ declare module 'state/updaters/list' {
33
+ import { StoreListSorterFunction, StoreUpdaterFunction } from 'types'
34
+ import { StoreUpdaterBase } from 'state/store-updater'
35
+ export class StoreUpdaterList<T> extends StoreUpdaterBase<T[]> {
36
+ addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T[]>): void
37
+ push(element: T): void
38
+ pop(): T
39
+ unshift(element: T): void
40
+ shift(): T
41
+ addSorter(name: string, sorter: StoreListSorterFunction<T>): void
42
+ sortBy(sorter: StoreListSorterFunction<T>): void
43
+ insertAt(index: number, item: T): void
44
+ }
45
+ }
46
+ declare module 'state/store' {
47
+ import type {
48
+ State,
49
+ StoreDataUpdater,
50
+ StoreInitializationOptions,
51
+ StoreListSorterFunction,
52
+ StoreUpdaterFunction,
53
+ StoreUpdaterOrValue,
54
+ StoreUpdatersCollection,
55
+ StoreUpdater,
56
+ } from 'types'
57
+ export class Store<T> {
58
+ parent: State
59
+ name: string
60
+ updater: StoreUpdater<T>
61
+ _value: T
62
+ initialState: T
63
+ constructor(options: StoreInitializationOptions<T>)
64
+ get ['value'](): T
65
+ set ['value'](value: T)
66
+ update(updater: StoreUpdaterOrValue<T>): void
67
+ updateValue(newValue: T): void
68
+ getUpdatedValue(updater: StoreDataUpdater<T>): T
69
+ addUpdaters(updaters: StoreUpdatersCollection<any>): void
70
+ addUpdater(name: string, updater: StoreUpdaterFunction<any>): void
71
+ addSorter(name: string, sorter: StoreListSorterFunction<T>): void
72
+ }
73
+ }
74
+ declare module 'state/updaters/boolean' {
75
+ import { StoreUpdaterFunction } from 'types'
76
+ import { StoreUpdaterBase } from 'state/store-updater'
77
+ export class StoreUpdaterBoolean extends StoreUpdaterBase<boolean> {
78
+ toggle(): void
79
+ setTrue(): void
80
+ setFalse(): void
81
+ addUpdaterFunction(
82
+ name: string,
83
+ updater: StoreUpdaterFunction<boolean>,
84
+ ): void
85
+ }
86
+ }
87
+ declare module 'state/updaters/object' {
88
+ import { StoreUpdaterFunction } from 'types'
89
+ import { StoreUpdaterBase } from 'state/store-updater'
90
+ export class StoreUpdaterObject<T> extends StoreUpdaterBase<T> {
91
+ addUpdaterFunction(name: string, updater: StoreUpdaterFunction<T>): void
92
+ updateAttribute(name: keyof T, value: T[keyof T]): void
93
+ }
94
+ }
95
+ declare module 'state/index' {
96
+ import { Store } from 'state/store'
97
+ import { StoreUpdaterBoolean } from 'state/updaters/boolean'
98
+ import { StoreUpdaterList } from 'state/updaters/list'
99
+ import { StoreUpdaterObject } from 'state/updaters/object'
100
+ import type {
101
+ StatePublisher,
102
+ StateTransactionUpdater,
103
+ StoresCollection,
104
+ StoreValue,
105
+ } from 'types'
106
+ export const eventName = 'state'
107
+ export class State {
108
+ publisher: StatePublisher
109
+ stores: StoresCollection
110
+ eventNamePrefix: string
111
+ notifications: Set<string>
112
+ inTransaction: boolean
113
+ constructor(publisher: StatePublisher)
114
+ create<T>(name: string, initialState: T): Store<T>
115
+ createBoolean(name: string, initialState: boolean): Store<boolean>
116
+ createRecord<T>(name: string, initialState: T): Store<T>
117
+ createList<T>(name: string, initialState: T[]): Store<T[]>
118
+ store(name: string): Store<any>
119
+ get(name: string): StoreValue
120
+ getAll(names: string[]): {}
121
+ notify(name: string): void
122
+ update(name: string, newValue: any): void
123
+ transaction(updater: StateTransactionUpdater): void
124
+ publishAll(): void
125
+ publish(name: string): void
126
+ event(name: string): string
127
+ }
128
+ export const createState: (publisher: StatePublisher) => State
129
+ export { Store, StoreUpdaterBoolean, StoreUpdaterList, StoreUpdaterObject }
130
+ }
131
+ declare module 'bus/exact-subscriptions' {
132
+ import { ExactSubscriptionData, BusListener, Unsubscribe } from 'types'
133
+ export class ExactSubscriptions {
134
+ lookup: Record<string, ExactSubscriptionData<any>[]>
135
+ constructor()
136
+ add<T>(
137
+ matcher: string,
138
+ listener: BusListener<T>,
139
+ index: number,
140
+ ): Unsubscribe
141
+ remove<T>(subscription: ExactSubscriptionData<T>): void
142
+ matches(event: string): ExactSubscriptionData<any>[]
143
+ ensureArrayFor(matcher: string): void
144
+ }
145
+ }
146
+ declare module 'bus/fuzzy-subscriptions' {
147
+ import { FuzzySubscriptionData, BusListener, Unsubscribe } from 'types'
148
+ export class FuzzySubscriptions {
149
+ lookup: FuzzySubscriptionData<any>[]
150
+ constructor()
151
+ add<T>(
152
+ matcher: RegExp,
153
+ listener: BusListener<T>,
154
+ index: number,
155
+ ): Unsubscribe
156
+ remove<T>(subscription: FuzzySubscriptionData<T>): void
157
+ matches(event: string): FuzzySubscriptionData<any>[]
158
+ }
159
+ }
160
+ declare module 'bus/index' {
161
+ import {
162
+ BusEventMatcher,
163
+ BusListener,
164
+ Unsubscribe,
165
+ AppAdditionListenerOptions,
166
+ ListenerKit,
167
+ } from 'types'
168
+ import { ExactSubscriptions } from 'bus/exact-subscriptions'
169
+ import { FuzzySubscriptions } from 'bus/fuzzy-subscriptions'
170
+ class JaxsBus {
171
+ options?: AppAdditionListenerOptions
172
+ exactSubscriptions: ExactSubscriptions
173
+ fuzzySubscriptions: FuzzySubscriptions
174
+ currentIndex: number
175
+ constructor()
176
+ subscribe<T>(
177
+ matcher: BusEventMatcher,
178
+ listener: BusListener<T>,
179
+ ): Unsubscribe
180
+ publish<T>(event: string, payload: T): void
181
+ addListenerOptions(options: AppAdditionListenerOptions): void
182
+ listenerOptions(event: string): ListenerKit
183
+ }
184
+ const createBus: () => {
185
+ bus: JaxsBus
186
+ publish: (event: string, payload: any) => void
187
+ subscribe: (
188
+ matcher: BusEventMatcher,
189
+ listener: BusListener<any>,
190
+ ) => Unsubscribe
191
+ }
192
+ export { createBus, JaxsBus, ExactSubscriptions, FuzzySubscriptions }
193
+ }
194
+ declare module 'rendering/templates/root' {
195
+ import type {
196
+ JaxsElement,
197
+ JaxsNodes,
198
+ RenderKit,
199
+ Renderable,
200
+ JaxsNode,
201
+ } from 'types'
202
+ export class Root {
203
+ template: Renderable
204
+ selector: string
205
+ renderKit: RenderKit
206
+ dom: JaxsNodes
207
+ parentElement?: JaxsElement | null
208
+ constructor(template: Renderable, selector: string, renderKit: RenderKit)
209
+ renderAndAttach(renderKit: RenderKit): void
210
+ render(renderKit: RenderKit): JaxsNode[]
211
+ attach(): void
212
+ getParentElement(): Element
213
+ }
214
+ export const render: (
215
+ template: Renderable,
216
+ selector: string,
217
+ renderKit: RenderKit,
218
+ ) => Root
219
+ }
220
+ declare module 'navigation/events' {
221
+ export const linkNavigationEvent = 'go-to-href'
222
+ export const locationChangeEvent = 'navigation:location-change'
223
+ export const routeChangeEvent = 'navigation:route-change'
224
+ }
225
+ declare module 'navigation/route-state' {
226
+ import { State } from 'state/index'
227
+ export const createRouteState: (state: State) => void
228
+ }
229
+ declare module 'navigation/find-href' {
230
+ export const findHref: (node: HTMLElement) => string
231
+ }
232
+ declare module 'navigation/navigate' {
233
+ import { ListenerKit } from 'types'
234
+ export const navigate: (
235
+ path: string,
236
+ { publish, window }: ListenerKit,
237
+ ) => void
238
+ }
239
+ declare module 'navigation/on-link-click' {
240
+ import { ListenerKit } from 'types'
241
+ export const onLinkClick: (domEvent: MouseEvent, options: ListenerKit) => void
242
+ }
243
+ declare module 'navigation/extract-query-params' {
244
+ export const extractQueryParams: (queryString: string) => {}
245
+ }
246
+ declare module 'navigation/on-location-change' {
247
+ import { ListenerKit } from 'types'
248
+ export const onLocationChange: (_: null, listenerOptions: ListenerKit) => void
249
+ }
250
+ declare module 'navigation/start' {
251
+ import type { App } from 'app/index'
252
+ export const subscribeToNavigation: (app: App) => void
253
+ export const subscribeToHistoryChange: (app: App) => void
254
+ export const publishLocation: (app: App) => void
255
+ export const startNavigation: (app: App) => void
256
+ }
257
+ declare module 'app/index' {
258
+ import type { Renderable, RenderKit, Subscribe, PublishFunction } from 'types'
259
+ import type { State } from 'state/index'
260
+ import type { JaxsBus } from 'bus/index'
261
+ import { Root } from 'rendering/templates/root'
262
+ export class App {
263
+ window: Window
264
+ document: Document
265
+ publish: PublishFunction
266
+ subscribe: Subscribe
267
+ bus: JaxsBus
268
+ state: State
269
+ renderKit: RenderKit
270
+ roots: Root[]
271
+ constructor({
272
+ window,
273
+ document,
274
+ publish,
275
+ subscribe,
276
+ bus,
277
+ state,
278
+ renderKit,
279
+ }: {
280
+ window: any
281
+ document: any
282
+ publish: any
283
+ subscribe: any
284
+ bus: any
285
+ state: any
286
+ renderKit: any
287
+ })
288
+ render(template: Renderable, selector: string): Root
289
+ startNavigation(): void
290
+ }
291
+ }
292
+ declare module 'types' {
293
+ import type { State } from 'state/index'
294
+ import type { Store } from 'state/store'
295
+ import type { StoreUpdaterBase } from 'state/store-updater'
296
+ import type { StoreUpdaterBoolean } from 'state/updaters/boolean'
297
+ import type { StoreUpdaterList } from 'state/updaters/list'
298
+ import type { StoreUpdaterObject } from 'state/updaters/object'
299
+ export type { App } from 'app/index'
300
+ export {
301
+ State,
302
+ Store,
303
+ StoreUpdaterBase,
304
+ StoreUpdaterBoolean,
305
+ StoreUpdaterList,
306
+ StoreUpdaterObject,
307
+ }
308
+ export type StoreUpdater<T> =
309
+ | StoreUpdaterBase<T>
310
+ | StoreUpdaterObject<T>
311
+ | StoreUpdaterBoolean
312
+ | StoreUpdaterList<T>
313
+ export type TextValue = string | number
314
+ export interface JsxIded {
315
+ __jsx?: string
316
+ }
317
+ export type JsxChangeId = {
318
+ element: JaxsNode
319
+ index: number
320
+ }
321
+ export type EventMap = {
322
+ domEvent: string
323
+ busEvent: string
324
+ listener: EventListener
325
+ }
326
+ export type EventMaps = Record<string, EventMap>
327
+ interface JsxEventMapped {
328
+ eventMaps: EventMaps
329
+ }
330
+ export type JaxsElement = Element & JsxIded & JsxEventMapped
331
+ export type JaxsText = Text & JsxIded
332
+ export type JaxsSvgElement = SVGElement & JsxIded
333
+ export type JaxsNode = JaxsElement | JaxsText | JaxsSvgElement
334
+ export type JaxsNodes = JaxsNode[] | NodeListOf<JaxsNode>
335
+ export type JaxsInput = HTMLInputElement & JsxIded & JsxEventMapped
336
+ type NullValues = null | undefined
337
+ export type ReactSourceObject = {
338
+ fileName: string
339
+ lineNumber: string
340
+ columnNumber: string
341
+ }
342
+ interface SourceMap {
343
+ __source?: ReactSourceObject
344
+ }
345
+ export type Props<T> = Partial<{
346
+ __source: ReactSourceObject
347
+ children: JsxCollection
348
+ }> &
349
+ T
350
+ export type PropValue =
351
+ | TextValue
352
+ | NullValues
353
+ | boolean
354
+ | ReactSourceObject
355
+ | JsxCollection
356
+ export type TagAttributes = SourceMap & Record<string, string>
357
+ export type TagEventAttributes = Record<string, string>
358
+ export type TagAttributesAndEvents = {
359
+ attributes: TagAttributes
360
+ events: TagEventAttributes
361
+ }
362
+ export type DomPublish = (eventName: string, domEvent: Event) => void
363
+ export type Subscribe = (
364
+ matcher: BusEventMatcher,
365
+ listener: BusListener<any>,
366
+ ) => void
367
+ export type RenderKit = {
368
+ document: Document
369
+ window: Window
370
+ publish: DomPublish
371
+ subscribe: Subscribe
372
+ state: State
373
+ parent?: JaxsNode | null
374
+ }
375
+ export interface Renderable {
376
+ render: (renderKit: RenderKit, parentElement?: JaxsElement) => JaxsNode[]
377
+ }
378
+ export type StaticTemplate = () => Renderable
379
+ export type TypedTemplate<T> = (props: Props<T>) => Renderable
380
+ export type Template<T> = StaticTemplate | TypedTemplate<T>
381
+ export type JsxCollection = (Renderable | TextValue)[]
382
+ export enum ChangeInstructionTypes {
383
+ removeNode = 0,
384
+ insertNode = 1, // can be to move an existing element in the dom, or to add one
385
+ replaceNode = 2,
386
+ removeAttribute = 3,
387
+ addAttribute = 4,
388
+ updateAttribute = 5,
389
+ removeEvent = 6,
390
+ addEvent = 7,
391
+ updateEvent = 8,
392
+ changeValue = 9,
393
+ changeText = 10,
394
+ }
395
+ export type RemoveInstructionData = {
396
+ name: string
397
+ isSvg?: boolean
398
+ }
399
+ export type AttributeInstructionData = {
400
+ name: string
401
+ value: string
402
+ isSvg?: boolean
403
+ }
404
+ export type EventInstructionData = {
405
+ name: string
406
+ value: EventListener
407
+ }
408
+ export type UpdateEventInstructionData = {
409
+ name: string
410
+ sourceValue: EventListener
411
+ targetValue: EventListener
412
+ }
413
+ export type InsertNodeData = {
414
+ parent: JaxsElement
415
+ index: number
416
+ }
417
+ type NullInstructionData = Record<string, never>
418
+ export type InstructionData =
419
+ | RemoveInstructionData
420
+ | AttributeInstructionData
421
+ | EventInstructionData
422
+ | UpdateEventInstructionData
423
+ | InsertNodeData
424
+ | NullInstructionData
425
+ export type ChangeInstruction = {
426
+ source: JaxsNode
427
+ target: JaxsNode
428
+ type: ChangeInstructionTypes
429
+ data: InstructionData
430
+ }
431
+ export type ChangeInstructions = Array<ChangeInstruction>
432
+ export type InstructionsUpdater = (instruction: ChangeInstruction) => void
433
+ export type StoreValue =
434
+ | string
435
+ | number
436
+ | boolean
437
+ | null
438
+ | StoreValue[]
439
+ | {
440
+ [key: string]: StoreValue
441
+ }
442
+ export type StoreMap = {
443
+ [key: string]: StoreValue
444
+ }
445
+ export type ViewModel<ATTRIBUTES, STORE_MAP> = (
446
+ storeMap: STORE_MAP,
447
+ ) => Partial<ATTRIBUTES>
448
+ export type BindSubscriptionList = string[]
449
+ export type BindParams<T, U> = {
450
+ Template: Template<T>
451
+ viewModel?: ViewModel<T, U>
452
+ subscriptions?: BindSubscriptionList
453
+ }
454
+ export type AppAdditionListenerOptions = {
455
+ state: State
456
+ document: Document
457
+ window: Window
458
+ }
459
+ export type DefaultBusListenerOptions = {
460
+ publish: PublishFunction
461
+ eventName: string
462
+ }
463
+ export type ListenerKit = AppAdditionListenerOptions &
464
+ DefaultBusListenerOptions
465
+ export type PublishFunction = (event: string, payload: any) => void
466
+ export type BusListener<T> = (payload: T, listenerKit: ListenerKit) => void
467
+ export type BusEventMatcher = string | RegExp
468
+ export type ExactSubscriptionData<T> = {
469
+ listener: BusListener<T>
470
+ index: number
471
+ matcher: string
472
+ }
473
+ export type FuzzySubscriptionData<T> = {
474
+ listener: BusListener<T>
475
+ index: number
476
+ matcher: RegExp
477
+ }
478
+ export type Unsubscribe = () => void
479
+ export type CreateAppBuilderArguments = {
480
+ window?: Window
481
+ document?: Document
482
+ }
483
+ export type RouteState = {
484
+ host: string
485
+ path: string
486
+ query: Record<string, string>
487
+ }
488
+ export type AttributesWithChildren<T> = Props<T> & {
489
+ children?: JsxCollection
490
+ }
491
+ export type DiffPair = {
492
+ source: JaxsNode
493
+ target: JaxsNode
494
+ }
495
+ export type CompileChildren = (
496
+ sourceList: JaxsNodes,
497
+ targetList: JaxsNodes,
498
+ parent: JaxsElement,
499
+ ) => ChangeInstructions
500
+ export type StatePublisher = (event: string, payload: any) => void
501
+ export type StateTransactionUpdater = (collection: StoresCollection) => void
502
+ export type StoresCollection = Record<string, Store<any>>
503
+ export type StoreInitializationOptions<T> = {
504
+ name: string
505
+ parent: State
506
+ value: T
507
+ }
508
+ export type StoreDataUpdater<T> = (originalValue: T) => T
509
+ export type UpdaterValue<T> = boolean | T | T[]
510
+ export type StoreUpdaterOrValue<T> = UpdaterValue<T> | StoreDataUpdater<T>
511
+ export type StoreUpdaterFunction<T> = (
512
+ value: UpdaterValue<T>,
513
+ ...args: any[]
514
+ ) => T
515
+ export type StoreUpdatersCollection<T> = Record<
516
+ string,
517
+ StoreUpdaterFunction<T>
518
+ >
519
+ export type StoreListSorterFunction<T> = (left: T, right: T) => number
520
+ export type RouteMatcher = (routeState: RouteState) => boolean
521
+ export type RenderedRoute = {
522
+ Partial: StaticTemplate
523
+ match: RouteMatcher
524
+ }
525
+ }
526
+ declare module 'rendering/dom/tag' {
527
+ import type {
528
+ JaxsElement,
529
+ TagAttributes,
530
+ TagEventAttributes,
531
+ DomPublish,
532
+ RenderKit,
533
+ } from 'types'
534
+ export const createNode: (type: string, document: Document) => HTMLElement
535
+ export const setAttributesOnElement: (
536
+ element: Element,
537
+ attributes: TagAttributes,
538
+ ) => void
539
+ export const setEventsOnElement: (
540
+ element: JaxsElement,
541
+ events: TagEventAttributes,
542
+ publish: DomPublish,
543
+ ) => void
544
+ export const createDecoratedNode: (
545
+ type: string,
546
+ attributes: TagAttributes,
547
+ events: TagEventAttributes,
548
+ renderKit: RenderKit,
549
+ ) => JaxsElement
550
+ }
551
+ declare module 'rendering/dom/svg' {
552
+ import type { TagAttributes, JaxsElement } from 'types'
553
+ export const namespace = 'http://www.w3.org/2000/svg'
554
+ export const isSvgTag: (
555
+ tagType: string,
556
+ attributeNamespace?: string,
557
+ ) => boolean
558
+ export const createSvgNode: (
559
+ type: string,
560
+ attributes: TagAttributes,
561
+ document: Document,
562
+ ) => JaxsElement
563
+ export const elementIsSvg: (element: JaxsElement) => boolean
564
+ }
565
+ declare module 'rendering/dom/text' {
566
+ export const createTextNode: (value: string, document: Document) => Text
567
+ }
568
+ declare module 'rendering/templates/text' {
569
+ import { Renderable, TextValue, RenderKit } from 'types'
570
+ export class TextTemplate implements Renderable {
571
+ value: string
572
+ constructor(content: TextValue)
573
+ render(renderKit: RenderKit): Text[]
574
+ }
575
+ }
576
+ declare module 'rendering/templates/children/text' {
577
+ import { TextValue, Renderable } from 'types'
578
+ import { TextTemplate } from 'rendering/templates/text'
579
+ export const isTextValue: <T>(
580
+ child: TextValue | T,
581
+ ) => child is string | number | (T & string) | (T & number)
582
+ export const textNode: (content: TextValue) => TextTemplate
583
+ export const replaceTextNodes: (
584
+ child: TextValue | Renderable,
585
+ ) => Renderable | TextTemplate
586
+ }
587
+ declare module 'rendering/templates/children/normalize' {
588
+ import { JsxCollection, AttributesWithChildren } from 'types'
589
+ export const normalizeJsxChildren: (
590
+ jsxChildren: JsxCollection,
591
+ ) => (
592
+ | import('types').Renderable
593
+ | import('rendering/templates/text').TextTemplate
594
+ )[]
595
+ export const normalizeToArray: <T>(children: T | T[]) => T[]
596
+ export const ensureJsxChildrenArray: <T>(
597
+ maybeChildren?: JsxCollection,
598
+ attributes?: AttributesWithChildren<T>,
599
+ ) => JsxCollection
600
+ }
601
+ declare module 'rendering/templates/tag/attributes-and-events' {
602
+ import type { Props, TagAttributesAndEvents, JsxCollection } from 'types'
603
+ export const separateAttrsAndEvents: <T>(
604
+ props: Props<T>,
605
+ defaultValue?: string,
606
+ ) => TagAttributesAndEvents
607
+ export const packageJsxAttributes: <T>(
608
+ maybeAttributes?: Props<T>,
609
+ maybeChildren?: JsxCollection,
610
+ ) => Props<T>
611
+ }
612
+ declare module 'rendering/templates/children/render' {
613
+ import { Renderable, RenderKit, JaxsNode, JaxsElement } from 'types'
614
+ export const recursiveRender: (
615
+ children: Renderable[],
616
+ renderKit: RenderKit,
617
+ parentElement?: JaxsElement,
618
+ rendered?: JaxsNode[],
619
+ ) => JaxsNode[]
620
+ }
621
+ declare module 'rendering/templates/children' {
622
+ import {
623
+ JaxsElement,
624
+ Renderable,
625
+ JsxCollection,
626
+ RenderKit,
627
+ JaxsNodes,
628
+ JaxsNode,
629
+ } from 'types'
630
+ export class Children implements Renderable {
631
+ collection: Renderable[]
632
+ parentElement?: JaxsElement
633
+ constructor(jsxChildren: JsxCollection)
634
+ render(renderKit: RenderKit, parentElement?: JaxsElement): JaxsNode[]
635
+ generateDom(renderKit: RenderKit): JaxsNode[]
636
+ attachToParent(dom: JaxsNodes): void
637
+ }
638
+ }
639
+ declare module 'rendering/templates/tag/jsx-key' {
640
+ import { TagAttributes } from 'types'
641
+ export class JsxKey {
642
+ attributes: TagAttributes
643
+ type: string
644
+ constructor(type: string, attributes: TagAttributes)
645
+ generate(): string
646
+ sourceKey(): string
647
+ createKeyFromAttributes(): string
648
+ }
649
+ }
650
+ declare module 'rendering/templates/tag' {
651
+ import type {
652
+ Props,
653
+ JaxsNode,
654
+ TagEventAttributes,
655
+ Renderable,
656
+ RenderKit,
657
+ TagAttributes,
658
+ JsxCollection,
659
+ } from 'types'
660
+ import { Children } from 'rendering/templates/children'
661
+ export class Tag<T> implements Renderable {
662
+ type: string
663
+ events: TagEventAttributes
664
+ attributes: TagAttributes
665
+ props: Props<T>
666
+ children: Children
667
+ isSvg: boolean
668
+ constructor(tagType: string, props: Props<T>, children?: JsxCollection)
669
+ render(renderKit: RenderKit): JaxsNode[]
670
+ generateDom(renderKit: RenderKit): import('types').JaxsElement
671
+ generateHtmlDom(renderKit: RenderKit): import('types').JaxsElement
672
+ generateSvgDom(renderKit: RenderKit): import('types').JaxsElement
673
+ jsxKey(): string
674
+ }
675
+ }
676
+ declare module 'rendering/jsx' {
677
+ import type { JsxCollection, Props, Template, Renderable } from 'types'
678
+ import { Children } from 'rendering/templates/children'
679
+ const jsx: {
680
+ <T>(
681
+ type: string | Template<T>,
682
+ attributes: Props<T>,
683
+ ...children: JsxCollection
684
+ ): Renderable
685
+ fragment<T>(attributes: Props<T>, maybeChildren: JsxCollection): Children
686
+ }
687
+ export { jsx }
688
+ }
689
+ declare module 'app/builder' {
690
+ import { App } from 'app/index'
691
+ import { JaxsBus } from 'bus/index'
692
+ import { State } from 'state/index'
693
+ import {
694
+ PublishFunction,
695
+ Subscribe,
696
+ RenderKit,
697
+ CreateAppBuilderArguments,
698
+ } from 'types'
699
+ class AppBuilder {
700
+ window: Window
701
+ document: Document
702
+ publish: PublishFunction
703
+ subscribe: Subscribe
704
+ bus: JaxsBus
705
+ state: State
706
+ renderKit: RenderKit
707
+ constructor(domEnvironment: CreateAppBuilderArguments)
708
+ setup(): App
709
+ setupDomEnvironment(domEnvironment: CreateAppBuilderArguments): void
710
+ setupBus(): void
711
+ setupState(): void
712
+ addBusOptions(): void
713
+ setRenderKit(): void
714
+ }
715
+ const createApp: (domEnvironment?: CreateAppBuilderArguments) => App
716
+ export { App, AppBuilder, createApp }
717
+ }
718
+ declare module 'rendering/update/instructions/instructions' {
719
+ import {
720
+ JaxsInput,
721
+ ChangeInstruction,
722
+ JaxsElement,
723
+ RemoveInstructionData,
724
+ AttributeInstructionData,
725
+ EventInstructionData,
726
+ UpdateEventInstructionData,
727
+ InsertNodeData,
728
+ } from 'types'
729
+ export const changeText: (source: Text, target: Text) => ChangeInstruction
730
+ export const replaceNode: (
731
+ source: JaxsElement,
732
+ target: JaxsElement,
733
+ ) => ChangeInstruction
734
+ export const removeAttribute: (
735
+ source: JaxsElement,
736
+ target: JaxsElement,
737
+ data: RemoveInstructionData,
738
+ ) => ChangeInstruction
739
+ export const addAttribute: (
740
+ source: JaxsElement,
741
+ target: JaxsElement,
742
+ data: AttributeInstructionData,
743
+ ) => ChangeInstruction
744
+ export const updateAttribute: (
745
+ source: JaxsElement,
746
+ target: JaxsElement,
747
+ data: AttributeInstructionData,
748
+ ) => ChangeInstruction
749
+ export const removeEvent: (
750
+ source: JaxsElement,
751
+ target: JaxsElement,
752
+ data: EventInstructionData,
753
+ ) => ChangeInstruction
754
+ export const addEvent: (
755
+ source: JaxsElement,
756
+ target: JaxsElement,
757
+ data: EventInstructionData,
758
+ ) => ChangeInstruction
759
+ export const updateEvent: (
760
+ source: JaxsElement,
761
+ target: JaxsElement,
762
+ data: UpdateEventInstructionData,
763
+ ) => ChangeInstruction
764
+ export const removeNode: (source: JaxsElement) => ChangeInstruction
765
+ export const insertNode: (
766
+ target: JaxsElement,
767
+ data: InsertNodeData,
768
+ ) => ChangeInstruction
769
+ export const changeValue: (
770
+ source: JaxsInput,
771
+ target: JaxsInput,
772
+ data: AttributeInstructionData,
773
+ ) => ChangeInstruction
774
+ export const instructionsSorter: (
775
+ left: ChangeInstruction,
776
+ right: ChangeInstruction,
777
+ ) => 0 | 1 | -1
778
+ }
779
+ declare module 'rendering/update/instructions/id-map' {
780
+ import type { JaxsNode, JaxsNodes, JsxChangeId } from 'types'
781
+ export class IdMap {
782
+ map: Record<string, JsxChangeId[]>
783
+ constructor()
784
+ populate(list: JaxsNodes): void
785
+ pullMatch(element: JaxsNode): JsxChangeId
786
+ clear(element: JaxsNode): void
787
+ check(element: JaxsNode): boolean
788
+ remaining(): JsxChangeId[]
789
+ }
790
+ export const createIdMap: (list: JaxsNodes) => IdMap
791
+ }
792
+ declare module 'rendering/update/instructions/nodes/element/attributes' {
793
+ import type { JaxsElement, ChangeInstructions } from 'types'
794
+ export const compileForAttributes: (
795
+ source: JaxsElement,
796
+ target: JaxsElement,
797
+ isSvg?: boolean,
798
+ ) => ChangeInstructions
799
+ }
800
+ declare module 'rendering/update/instructions/nodes/element/events' {
801
+ import type { JaxsElement, ChangeInstructions } from 'types'
802
+ export const compileForEvents: (
803
+ source: JaxsElement,
804
+ target: JaxsElement,
805
+ ) => ChangeInstructions
806
+ }
807
+ declare module 'rendering/update/instructions/nodes/input' {
808
+ import { ChangeInstructions, JaxsElement } from 'types'
809
+ export const compileForInputValue: (
810
+ sourceElement: JaxsElement,
811
+ targetElement: JaxsElement,
812
+ ) => ChangeInstructions
813
+ }
814
+ declare module 'rendering/update/instructions/nodes/element' {
815
+ import type { JaxsElement } from 'types'
816
+ export const compileForElement: (
817
+ source: JaxsElement,
818
+ target: JaxsElement,
819
+ ) => import('types').ChangeInstruction[]
820
+ }
821
+ declare module 'rendering/update/instructions/nodes/svg' {
822
+ import { JaxsElement } from 'types'
823
+ export const compileForSvg: (
824
+ source: JaxsElement,
825
+ target: JaxsElement,
826
+ ) => import('types').ChangeInstructions
827
+ }
828
+ declare module 'rendering/update/instructions/nodes/text' {
829
+ import type { ChangeInstructions } from 'types'
830
+ export const compileForText: (
831
+ source: Text,
832
+ target: Text,
833
+ ) => ChangeInstructions
834
+ }
835
+ declare module 'rendering/update/instructions/node' {
836
+ import type { JaxsNode, ChangeInstructions, CompileChildren } from 'types'
837
+ export const compileForNode: (
838
+ source: JaxsNode,
839
+ target: JaxsNode,
840
+ compileChildren: CompileChildren,
841
+ ) => ChangeInstructions
842
+ }
843
+ declare module 'rendering/update/instructions/collection' {
844
+ import type { JaxsElement, JaxsNodes } from 'types'
845
+ export const compileCollection: (
846
+ sourceList: JaxsNodes,
847
+ targetList: JaxsNodes,
848
+ parent: JaxsElement,
849
+ ) => import('types').ChangeInstruction[]
850
+ }
851
+ declare module 'rendering/update/perform-change' {
852
+ import type { ChangeInstruction, JaxsElement, JaxsNodes } from 'types'
853
+ export const performChange: (
854
+ source: JaxsNodes,
855
+ target: JaxsNodes,
856
+ parent: JaxsElement,
857
+ ) => ChangeInstruction[]
858
+ }
859
+ declare module 'rendering/templates/bound/modify-dom-cache' {
860
+ import { ChangeInstructions, JaxsNode, JaxsElement } from 'types'
861
+ export const modifyDomCache: (
862
+ instructions: ChangeInstructions,
863
+ dom: JaxsNode[],
864
+ parentElement: JaxsElement,
865
+ ) => JaxsNode[]
866
+ }
867
+ declare module 'rendering/templates/bound' {
868
+ import {
869
+ JaxsElement,
870
+ Props,
871
+ Template,
872
+ RenderKit,
873
+ ViewModel,
874
+ BindParams,
875
+ BindSubscriptionList,
876
+ JaxsNode,
877
+ } from 'types'
878
+ export class Bound<ATTRIBUTES, STATE_MAP> {
879
+ Template: Template<ATTRIBUTES>
880
+ viewModel: ViewModel<ATTRIBUTES, STATE_MAP>
881
+ attributes: Partial<Props<ATTRIBUTES>>
882
+ subscriptions: BindSubscriptionList
883
+ dom: JaxsNode[]
884
+ parentElement: JaxsElement | null
885
+ renderKit?: RenderKit
886
+ constructor({
887
+ Template,
888
+ subscriptions,
889
+ attributes,
890
+ viewModel,
891
+ }: {
892
+ Template: any
893
+ subscriptions: any
894
+ attributes: any
895
+ viewModel: any
896
+ })
897
+ render(renderKit: RenderKit): JaxsNode[]
898
+ generateDom(renderKit: RenderKit): JaxsNode[]
899
+ rerender(): void
900
+ subscribeForRerender(): void
901
+ eventName(storeName: string): string
902
+ }
903
+ export const bind: <ATTRIBUTES, STATE_MAP>({
904
+ Template,
905
+ viewModel,
906
+ subscriptions,
907
+ }: BindParams<ATTRIBUTES, STATE_MAP>) => (
908
+ attributes: Partial<Props<ATTRIBUTES>>,
909
+ ) => Bound<unknown, unknown>
910
+ }
911
+ declare module 'navigation/index' {
912
+ import * as events from 'navigation/events'
913
+ import { extractQueryParams } from 'navigation/extract-query-params'
914
+ import { findHref } from 'navigation/find-href'
915
+ import { navigate } from 'navigation/navigate'
916
+ import { onLinkClick } from 'navigation/on-link-click'
917
+ import { onLocationChange } from 'navigation/on-location-change'
918
+ import { createRouteState } from 'navigation/route-state'
919
+ import * as start from 'navigation/start'
920
+ export {
921
+ events,
922
+ extractQueryParams,
923
+ findHref,
924
+ navigate,
925
+ onLinkClick,
926
+ onLocationChange,
927
+ createRouteState,
928
+ start,
929
+ }
930
+ }
931
+ declare module 'app/routing' {
932
+ import { RenderedRoute, RouteMatcher } from 'types'
933
+ export const exactPathMatch: (exactPath: string) => RouteMatcher
934
+ export const catchAll: RouteMatcher
935
+ export const buildRouter: (
936
+ pages: RenderedRoute[],
937
+ ) => ({ route }: { route: any }) => import('types').StaticTemplate
938
+ }
939
+ declare module 'rendering/null' {
940
+ import { RenderKit, JaxsElement, JaxsNode } from 'types'
941
+ export const NullTemplate: () => {
942
+ render: (renderKit: RenderKit, parentElement?: JaxsElement) => JaxsNode[]
943
+ }
944
+ }
945
+ declare module 'app/routed-view' {
946
+ import { RenderedRoute, RouteState } from 'types'
947
+ export const routedView: (routes: RenderedRoute[]) => (
948
+ attributes: Partial<
949
+ import('types').Props<{
950
+ route: RouteState
951
+ }>
952
+ >,
953
+ ) => import('rendering/templates/bound').Bound<unknown, unknown>
954
+ }
955
+ declare module 'jaxs' {
956
+ export { jsx } from 'rendering/jsx'
957
+ export { createApp } from 'app/builder'
958
+ export { bind } from 'rendering/templates/bound'
959
+ export * as JaxsTypes from 'types'
960
+ export * as navigation from 'navigation/index'
961
+ export * as appBuilding from 'app/index'
962
+ export * as messageBus from 'bus/index'
963
+ export * as state from 'state/index'
964
+ export * as routing from 'app/routing'
965
+ export { routedView } from 'app/routed-view'
641
966
  }