jaxs 0.3.2 → 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 +648 -0
- package/dist/jaxs.js +810 -1071
- package/dist/jaxs.umd.cjs +1 -0
- package/package.json +41 -34
- package/.env +0 -1
- package/README.md +0 -15
- package/bun.lockb +0 -0
- package/bundle.ts +0 -5
- package/bunfig.toml +0 -0
- package/cypress/e2e/add-remove-nested-children.cy.js +0 -39
- package/cypress/e2e/add-remove-root-children.cy.js +0 -37
- package/cypress/e2e/svg-renders.cy.js +0 -10
- package/cypress/jaxs-apps/add-remove-nested-children.html +0 -12
- package/cypress/jaxs-apps/add-remove-nested-children.jsx +0 -85
- package/cypress/jaxs-apps/add-remove-root-children.html +0 -15
- package/cypress/jaxs-apps/add-remove-root-children.jsx +0 -54
- package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js +0 -1022
- package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-nested-children.html +0 -12
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js +0 -1665
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js +0 -1011
- package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-root-children.html +0 -15
- package/cypress/jaxs-apps/dist/svg.04290504.js +0 -644
- package/cypress/jaxs-apps/dist/svg.04290504.js.map +0 -1
- package/cypress/jaxs-apps/dist/svg.html +0 -11
- package/cypress/jaxs-apps/svg.html +0 -11
- package/cypress/jaxs-apps/svg.jsx +0 -15
- package/cypress/support/commands.js +0 -25
- package/cypress/support/e2e.js +0 -20
- package/cypress.config.js +0 -10
- package/src/app.ts +0 -84
- package/src/debugging.js +0 -5
- package/src/jaxs.ts +0 -7
- package/src/jsx.js +0 -27
- package/src/messageBus.ts +0 -70
- package/src/navigation/findHref.js +0 -10
- package/src/navigation/routeState.js +0 -15
- package/src/navigation/setupHistory.js +0 -38
- package/src/navigation/setupNavigation.js +0 -25
- package/src/navigation.ts +0 -2
- package/src/rendering/change/compile.ts +0 -1
- package/src/rendering/change/instructions/attributes.ts +0 -81
- package/src/rendering/change/instructions/children.ts +0 -127
- package/src/rendering/change/instructions/element.ts +0 -49
- package/src/rendering/change/instructions/events.ts +0 -51
- package/src/rendering/change/instructions/generate.ts +0 -122
- package/src/rendering/change/instructions/idMap.js +0 -55
- package/src/rendering/change/instructions/node.ts +0 -55
- package/src/rendering/change/instructions/text.ts +0 -10
- package/src/rendering/change.ts +0 -139
- package/src/rendering/dom/attributesAndEvents.ts +0 -33
- package/src/rendering/dom/create.ts +0 -66
- package/src/rendering/dom/svg.ts +0 -18
- package/src/rendering/templates/bound.js +0 -56
- package/src/rendering/templates/children.ts +0 -99
- package/src/rendering/templates/root.ts +0 -55
- package/src/rendering/templates/tag.ts +0 -92
- package/src/rendering/templates/text.ts +0 -17
- package/src/state/equality.js +0 -36
- package/src/state/stores.js +0 -63
- package/src/state/testingTypes.js +0 -6
- package/src/state.js +0 -89
- package/src/types.ts +0 -160
- package/src/views/conditionals.jsx +0 -18
- package/src/views/link.jsx +0 -5
- package/src/views.js +0 -7
- package/tsconfig.json +0 -26
package/dist/jaxs.d.ts
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
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
|
+
isSvg: boolean;
|
|
295
|
+
}
|
|
296
|
+
export type StaticTemplate = () => Renderable;
|
|
297
|
+
export type TypedTemplate<T> = (props: Props<T>) => Renderable;
|
|
298
|
+
export type Template<T> = StaticTemplate | TypedTemplate<T>;
|
|
299
|
+
export type JsxCollection = (Renderable | TextValue)[];
|
|
300
|
+
export enum ChangeInstructionTypes {
|
|
301
|
+
removeNode = 0,
|
|
302
|
+
insertNode = 1,// can be to move an existing element in the dom, or to add one
|
|
303
|
+
replaceNode = 2,
|
|
304
|
+
removeAttribute = 3,
|
|
305
|
+
addAttribute = 4,
|
|
306
|
+
updateAttribute = 5,
|
|
307
|
+
removeEvent = 6,
|
|
308
|
+
addEvent = 7,
|
|
309
|
+
updateEvent = 8,
|
|
310
|
+
changeValue = 9,
|
|
311
|
+
changeText = 10
|
|
312
|
+
}
|
|
313
|
+
export type RemoveInstructionData = {
|
|
314
|
+
name: string;
|
|
315
|
+
isSvg?: boolean;
|
|
316
|
+
};
|
|
317
|
+
export type AttributeInstructionData = {
|
|
318
|
+
name: string;
|
|
319
|
+
value: string;
|
|
320
|
+
isSvg?: boolean;
|
|
321
|
+
};
|
|
322
|
+
export type EventInstructionData = {
|
|
323
|
+
name: string;
|
|
324
|
+
value: EventListener;
|
|
325
|
+
};
|
|
326
|
+
export type UpdateEventInstructionData = {
|
|
327
|
+
name: string;
|
|
328
|
+
sourceValue: EventListener;
|
|
329
|
+
targetValue: EventListener;
|
|
330
|
+
};
|
|
331
|
+
export type InsertNodeData = {
|
|
332
|
+
parent: JaxsElement;
|
|
333
|
+
index: number;
|
|
334
|
+
};
|
|
335
|
+
type NullInstructionData = Record<string, never>;
|
|
336
|
+
export type InstructionData = RemoveInstructionData | AttributeInstructionData | EventInstructionData | UpdateEventInstructionData | InsertNodeData | NullInstructionData;
|
|
337
|
+
export type ChangeInstruction = {
|
|
338
|
+
source: JaxsNode;
|
|
339
|
+
target: JaxsNode;
|
|
340
|
+
type: ChangeInstructionTypes;
|
|
341
|
+
data: InstructionData;
|
|
342
|
+
};
|
|
343
|
+
export type ChangeInstructions = Array<ChangeInstruction>;
|
|
344
|
+
export type InstructionsUpdater = (instruction: ChangeInstruction) => void;
|
|
345
|
+
export type StoreValue = string | number | boolean | null | StoreValue[] | {
|
|
346
|
+
[key: string]: StoreValue;
|
|
347
|
+
};
|
|
348
|
+
export type StoreMap = {
|
|
349
|
+
[key: string]: StoreValue;
|
|
350
|
+
};
|
|
351
|
+
export type ViewModel<ATTRIBUTES, STORE_MAP> = (storeMap: STORE_MAP) => Partial<ATTRIBUTES>;
|
|
352
|
+
export type BindSubscriptionList = string[];
|
|
353
|
+
export type BindParams<T, U> = {
|
|
354
|
+
Template: Template<T>;
|
|
355
|
+
viewModel?: ViewModel<T, U>;
|
|
356
|
+
subscriptions?: BindSubscriptionList;
|
|
357
|
+
};
|
|
358
|
+
export type AppAdditionListenerOptions = {
|
|
359
|
+
state: State;
|
|
360
|
+
document: Document;
|
|
361
|
+
window: Window;
|
|
362
|
+
};
|
|
363
|
+
export type DefaultBusListenerOptions<T> = {
|
|
364
|
+
publish: PublishFunction<T>;
|
|
365
|
+
eventName: string;
|
|
366
|
+
};
|
|
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;
|
|
371
|
+
export type ExactSubscriptionData<T> = {
|
|
372
|
+
listener: BusListener<T>;
|
|
373
|
+
index: number;
|
|
374
|
+
matcher: string;
|
|
375
|
+
};
|
|
376
|
+
export type FuzzySubscriptionData<T> = {
|
|
377
|
+
listener: BusListener<T>;
|
|
378
|
+
index: number;
|
|
379
|
+
matcher: RegExp;
|
|
380
|
+
};
|
|
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;
|
|
413
|
+
}
|
|
414
|
+
declare module "rendering/dom/tag" {
|
|
415
|
+
import type { JaxsElement, TagAttributes, TagEventAttributes, DomPublish, RenderKit } from "types";
|
|
416
|
+
export const createNode: (type: string, document: Document) => HTMLElement;
|
|
417
|
+
export const setAttributesOnElement: (element: Element, attributes: TagAttributes) => void;
|
|
418
|
+
export const setEventsOnElement: (element: JaxsElement, events: TagEventAttributes, publish: DomPublish) => void;
|
|
419
|
+
export const createDecoratedNode: (type: string, attributes: TagAttributes, events: TagEventAttributes, renderKit: RenderKit) => JaxsElement;
|
|
420
|
+
}
|
|
421
|
+
declare module "rendering/dom/svg" {
|
|
422
|
+
import type { TagAttributes, JaxsElement } from "types";
|
|
423
|
+
export const namespace = "http://www.w3.org/2000/svg";
|
|
424
|
+
export const isSvgTag: (tagType: string) => tagType is "svg";
|
|
425
|
+
export const createSvgNode: (type: string, attributes: TagAttributes, document: Document) => JaxsElement;
|
|
426
|
+
export const elementIsSvg: (element: JaxsElement) => boolean;
|
|
427
|
+
}
|
|
428
|
+
declare module "rendering/dom/text" {
|
|
429
|
+
export const createTextNode: (value: string, document: Document) => Text;
|
|
430
|
+
}
|
|
431
|
+
declare module "rendering/templates/text" {
|
|
432
|
+
import { Renderable, TextValue, RenderKit } from "types";
|
|
433
|
+
export class TextTemplate implements Renderable {
|
|
434
|
+
value: string;
|
|
435
|
+
isSvg: boolean;
|
|
436
|
+
constructor(content: TextValue);
|
|
437
|
+
render(renderKit: RenderKit): Text[];
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
declare module "rendering/templates/children/text" {
|
|
441
|
+
import { TextValue, Renderable } from "types";
|
|
442
|
+
import { TextTemplate } from "rendering/templates/text";
|
|
443
|
+
export const isTextValue: <T>(child: TextValue | T) => child is string | number | (T & string) | (T & number);
|
|
444
|
+
export const textNode: (content: TextValue) => TextTemplate;
|
|
445
|
+
export const replaceTextNodes: (child: TextValue | Renderable) => Renderable | TextTemplate;
|
|
446
|
+
}
|
|
447
|
+
declare module "rendering/templates/children/svg" {
|
|
448
|
+
import { Renderable } from "types";
|
|
449
|
+
export const withSvgFlag: (isSvg: boolean) => (template: Renderable) => Renderable;
|
|
450
|
+
}
|
|
451
|
+
declare module "rendering/templates/children/normalize" {
|
|
452
|
+
import { JsxCollection, Renderable, AttributesWithChildren } from "types";
|
|
453
|
+
export const normalizeJsxChildren: (jsxChildren: JsxCollection, isSvg: boolean) => Renderable[];
|
|
454
|
+
export const normalizeToArray: <T>(children: T | T[]) => T[];
|
|
455
|
+
export const ensureJsxChildrenArray: <T>(maybeChildren?: JsxCollection, attributes?: AttributesWithChildren<T>) => JsxCollection;
|
|
456
|
+
}
|
|
457
|
+
declare module "rendering/templates/tag/attributes-and-events" {
|
|
458
|
+
import type { Props, TagAttributesAndEvents, JsxCollection } from "types";
|
|
459
|
+
export const separateAttrsAndEvents: <T>(props: Props<T>, defaultValue?: string) => TagAttributesAndEvents;
|
|
460
|
+
export const packageJsxAttributes: <T>(maybeAttributes?: Props<T>, maybeChildren?: JsxCollection) => Props<T>;
|
|
461
|
+
}
|
|
462
|
+
declare module "rendering/templates/children/render" {
|
|
463
|
+
import { Renderable, RenderKit, JaxsNode } from "types";
|
|
464
|
+
export const recursiveRender: (children: Renderable[], renderKit: RenderKit, rendered?: JaxsNode[]) => JaxsNode[];
|
|
465
|
+
}
|
|
466
|
+
declare module "rendering/templates/children" {
|
|
467
|
+
import { JaxsElement, Renderable, JsxCollection, RenderKit, JaxsNodes, JaxsNode } from "types";
|
|
468
|
+
export class Children implements Renderable {
|
|
469
|
+
collection: Renderable[];
|
|
470
|
+
parentElement?: JaxsElement;
|
|
471
|
+
isSvg: boolean;
|
|
472
|
+
constructor(jsxChildren: JsxCollection, isSvg?: boolean);
|
|
473
|
+
render(renderKit: RenderKit, parentElement: JaxsElement | undefined): JaxsNode[];
|
|
474
|
+
generateDom(renderKit: RenderKit): JaxsNode[];
|
|
475
|
+
attachToParent(dom: JaxsNodes): void;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
declare module "rendering/templates/tag/jsx-key" {
|
|
479
|
+
import { TagAttributes } from "types";
|
|
480
|
+
export class JsxKey {
|
|
481
|
+
attributes: TagAttributes;
|
|
482
|
+
type: string;
|
|
483
|
+
constructor(type: string, attributes: TagAttributes);
|
|
484
|
+
generate(): string;
|
|
485
|
+
sourceKey(): string;
|
|
486
|
+
createKeyFromAttributes(): string;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
declare module "rendering/templates/tag" {
|
|
490
|
+
import type { Props, JaxsNode, TagEventAttributes, Renderable, RenderKit, TagAttributes, JsxCollection } from "types";
|
|
491
|
+
import { Children } from "rendering/templates/children";
|
|
492
|
+
export class Tag<T> implements Renderable {
|
|
493
|
+
type: string;
|
|
494
|
+
events: TagEventAttributes;
|
|
495
|
+
attributes: TagAttributes;
|
|
496
|
+
props: Props<T>;
|
|
497
|
+
children: Children;
|
|
498
|
+
isSvg: boolean;
|
|
499
|
+
constructor(tagType: string, props: Props<T>, children?: JsxCollection, isSvg?: boolean);
|
|
500
|
+
render(renderKit: RenderKit): JaxsNode[];
|
|
501
|
+
generateDom(renderKit: RenderKit): import("types").JaxsElement;
|
|
502
|
+
generateHtmlDom(renderKit: RenderKit): import("types").JaxsElement;
|
|
503
|
+
generateSvgDom(renderKit: RenderKit): import("types").JaxsElement;
|
|
504
|
+
jsxKey(): string;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
declare module "rendering/jsx" {
|
|
508
|
+
import type { JsxCollection, Props, Template, Renderable } from "types";
|
|
509
|
+
import { Children } from "rendering/templates/children";
|
|
510
|
+
const jsx: {
|
|
511
|
+
<T>(type: string | Template<T>, attributes: Props<T>, ...children: JsxCollection): Renderable;
|
|
512
|
+
fragment<T>(attributes: Props<T>, maybeChildren: JsxCollection): Children;
|
|
513
|
+
};
|
|
514
|
+
export { jsx };
|
|
515
|
+
}
|
|
516
|
+
declare module "app/builder" {
|
|
517
|
+
import { App } from "app/index";
|
|
518
|
+
import { JaxsBus } from "bus/index";
|
|
519
|
+
import { State } from "state/index";
|
|
520
|
+
import { PublishFunction, Subscribe, RenderKit, CreateAppBuilderArguments } from "types";
|
|
521
|
+
class AppBuilder {
|
|
522
|
+
window: Window;
|
|
523
|
+
document: Document;
|
|
524
|
+
publish: PublishFunction<any>;
|
|
525
|
+
subscribe: Subscribe;
|
|
526
|
+
bus: JaxsBus;
|
|
527
|
+
state: State;
|
|
528
|
+
renderKit: RenderKit;
|
|
529
|
+
constructor(domEnvironment: CreateAppBuilderArguments);
|
|
530
|
+
setup(): App;
|
|
531
|
+
setupDomEnvironment(domEnvironment: CreateAppBuilderArguments): void;
|
|
532
|
+
setupBus(): void;
|
|
533
|
+
setupState(): void;
|
|
534
|
+
addBusOptions(): void;
|
|
535
|
+
setRenderKit(): void;
|
|
536
|
+
}
|
|
537
|
+
const createApp: (domEnvironment?: CreateAppBuilderArguments) => App;
|
|
538
|
+
export { App, AppBuilder, createApp };
|
|
539
|
+
}
|
|
540
|
+
declare module "rendering/update/instructions/instructions" {
|
|
541
|
+
import { JaxsInput, ChangeInstruction, JaxsElement, RemoveInstructionData, AttributeInstructionData, EventInstructionData, UpdateEventInstructionData, InsertNodeData } from "types";
|
|
542
|
+
export const changeText: (source: Text, target: Text) => ChangeInstruction;
|
|
543
|
+
export const replaceNode: (source: JaxsElement, target: JaxsElement) => ChangeInstruction;
|
|
544
|
+
export const removeAttribute: (source: JaxsElement, target: JaxsElement, data: RemoveInstructionData) => ChangeInstruction;
|
|
545
|
+
export const addAttribute: (source: JaxsElement, target: JaxsElement, data: AttributeInstructionData) => ChangeInstruction;
|
|
546
|
+
export const updateAttribute: (source: JaxsElement, target: JaxsElement, data: AttributeInstructionData) => ChangeInstruction;
|
|
547
|
+
export const removeEvent: (source: JaxsElement, target: JaxsElement, data: EventInstructionData) => ChangeInstruction;
|
|
548
|
+
export const addEvent: (source: JaxsElement, target: JaxsElement, data: EventInstructionData) => ChangeInstruction;
|
|
549
|
+
export const updateEvent: (source: JaxsElement, target: JaxsElement, data: UpdateEventInstructionData) => ChangeInstruction;
|
|
550
|
+
export const removeNode: (source: JaxsElement) => ChangeInstruction;
|
|
551
|
+
export const insertNode: (target: JaxsElement, data: InsertNodeData) => ChangeInstruction;
|
|
552
|
+
export const changeValue: (source: JaxsInput, target: JaxsInput, data: AttributeInstructionData) => ChangeInstruction;
|
|
553
|
+
export const instructionsSorter: (left: ChangeInstruction, right: ChangeInstruction) => 0 | 1 | -1;
|
|
554
|
+
}
|
|
555
|
+
declare module "rendering/update/instructions/id-map" {
|
|
556
|
+
import type { JaxsNode, JaxsNodes, JsxChangeId } from "types";
|
|
557
|
+
export class IdMap {
|
|
558
|
+
map: Record<string, JsxChangeId[]>;
|
|
559
|
+
constructor();
|
|
560
|
+
populate(list: JaxsNodes): void;
|
|
561
|
+
pullMatch(element: JaxsNode): JsxChangeId;
|
|
562
|
+
clear(element: JaxsNode): void;
|
|
563
|
+
check(element: JaxsNode): boolean;
|
|
564
|
+
remaining(): JsxChangeId[];
|
|
565
|
+
}
|
|
566
|
+
export const createIdMap: (list: JaxsNodes) => IdMap;
|
|
567
|
+
}
|
|
568
|
+
declare module "rendering/update/instructions/nodes/element/attributes" {
|
|
569
|
+
import type { JaxsElement, ChangeInstructions } from "types";
|
|
570
|
+
export const compileForAttributes: (source: JaxsElement, target: JaxsElement, isSvg?: boolean) => ChangeInstructions;
|
|
571
|
+
}
|
|
572
|
+
declare module "rendering/update/instructions/nodes/element/events" {
|
|
573
|
+
import type { JaxsElement, ChangeInstructions } from "types";
|
|
574
|
+
export const compileForEvents: (source: JaxsElement, target: JaxsElement) => ChangeInstructions;
|
|
575
|
+
}
|
|
576
|
+
declare module "rendering/update/instructions/nodes/input" {
|
|
577
|
+
import { ChangeInstructions, JaxsElement } from "types";
|
|
578
|
+
export const compileForInputValue: (sourceElement: JaxsElement, targetElement: JaxsElement) => ChangeInstructions;
|
|
579
|
+
}
|
|
580
|
+
declare module "rendering/update/instructions/nodes/element" {
|
|
581
|
+
import type { JaxsElement } from "types";
|
|
582
|
+
export const compileForElement: (source: JaxsElement, target: JaxsElement) => import("types").ChangeInstruction[];
|
|
583
|
+
}
|
|
584
|
+
declare module "rendering/update/instructions/nodes/svg" {
|
|
585
|
+
import { JaxsElement } from "types";
|
|
586
|
+
export const compileForSvg: (source: JaxsElement, target: JaxsElement) => import("types").ChangeInstructions;
|
|
587
|
+
}
|
|
588
|
+
declare module "rendering/update/instructions/nodes/text" {
|
|
589
|
+
import type { ChangeInstructions } from "types";
|
|
590
|
+
export const compileForText: (source: Text, target: Text) => ChangeInstructions;
|
|
591
|
+
}
|
|
592
|
+
declare module "rendering/update/instructions/node" {
|
|
593
|
+
import type { JaxsNode, ChangeInstructions, CompileChildren } from "types";
|
|
594
|
+
export const compileForNode: (source: JaxsNode, target: JaxsNode, compileChildren: CompileChildren) => ChangeInstructions;
|
|
595
|
+
}
|
|
596
|
+
declare module "rendering/update/instructions/collection" {
|
|
597
|
+
import type { JaxsElement, JaxsNodes } from "types";
|
|
598
|
+
export const compileCollection: (sourceList: JaxsNodes, targetList: JaxsNodes, parent: JaxsElement) => import("types").ChangeInstruction[];
|
|
599
|
+
}
|
|
600
|
+
declare module "rendering/update/perform-change" {
|
|
601
|
+
import type { JaxsElement, JaxsNodes } from "types";
|
|
602
|
+
export const performChange: (source: JaxsNodes, target: JaxsNodes, parent: JaxsElement) => void;
|
|
603
|
+
}
|
|
604
|
+
declare module "rendering/templates/bound" {
|
|
605
|
+
import { JaxsElement, JaxsNodes, Props, Template, RenderKit, ViewModel, BindParams, BindSubscriptionList } from "types";
|
|
606
|
+
export class Bound<ATTRIBUTES, STATE_MAP> {
|
|
607
|
+
Template: Template<ATTRIBUTES>;
|
|
608
|
+
viewModel: ViewModel<ATTRIBUTES, STATE_MAP>;
|
|
609
|
+
attributes: Partial<Props<ATTRIBUTES>>;
|
|
610
|
+
subscriptions: BindSubscriptionList;
|
|
611
|
+
dom: JaxsNodes;
|
|
612
|
+
parentElement: JaxsElement | null;
|
|
613
|
+
renderKit?: RenderKit;
|
|
614
|
+
constructor({ Template, subscriptions, attributes, viewModel }: {
|
|
615
|
+
Template: any;
|
|
616
|
+
subscriptions: any;
|
|
617
|
+
attributes: any;
|
|
618
|
+
viewModel: any;
|
|
619
|
+
});
|
|
620
|
+
render(renderKit: RenderKit): import("types").JaxsNode[];
|
|
621
|
+
generateDom(renderKit: RenderKit): import("types").JaxsNode[];
|
|
622
|
+
rerender(): void;
|
|
623
|
+
subscribeForRerender(): void;
|
|
624
|
+
eventName(storeName: string): string;
|
|
625
|
+
}
|
|
626
|
+
export const bind: <ATTRIBUTES, STATE_MAP>({ Template, viewModel, subscriptions, }: BindParams<ATTRIBUTES, STATE_MAP>) => (attributes: Partial<Props<ATTRIBUTES>>) => Bound<unknown, unknown>;
|
|
627
|
+
}
|
|
628
|
+
declare module "navigation/index" {
|
|
629
|
+
import * as events from "navigation/events";
|
|
630
|
+
import { extractQueryParams } from "navigation/extract-query-params";
|
|
631
|
+
import { findHref } from "navigation/find-href";
|
|
632
|
+
import { navigate } from "navigation/navigate";
|
|
633
|
+
import { onLinkClick } from "navigation/on-link-click";
|
|
634
|
+
import { onLocationChange } from "navigation/on-location-change";
|
|
635
|
+
import { createRouteState } from "navigation/route-state";
|
|
636
|
+
import * as start from "navigation/start";
|
|
637
|
+
export { events, extractQueryParams, findHref, navigate, onLinkClick, onLocationChange, createRouteState, start, };
|
|
638
|
+
}
|
|
639
|
+
declare module "jaxs" {
|
|
640
|
+
export { jsx } from "rendering/jsx";
|
|
641
|
+
export { createApp } from "app/builder";
|
|
642
|
+
export { bind } from "rendering/templates/bound";
|
|
643
|
+
export * as JaxsTypes from "types";
|
|
644
|
+
export * as navigation from "navigation/index";
|
|
645
|
+
export * as appBuilding from "app/index";
|
|
646
|
+
export * as messageBus from "bus/index";
|
|
647
|
+
export * as state from "state/index";
|
|
648
|
+
}
|