Skip to content

Commit 6d59382

Browse files
committed
[Live] Fixed idiomorph id child handling & JavaScript cleanup
1 parent 9e086b1 commit 6d59382

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1081
-974
lines changed

src/LiveComponent/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# CHANGELOG
22

3+
## 2.15.0
4+
5+
- [BC BREAK] The `data-live-id` attribute was changed to `id`.
6+
37
## 2.14.1
48

59
- Fixed a regression in the testing tools related to the default HTTP
610
method change
711

812
## 2.14.0
913

14+
- [BC BREAK] DOM morphing changed from `morphdom` to `idiomorph`. As this is
15+
a different morphing library, there may be some edge cases where the
16+
morphing behavior is different.
1017
- Add support for URL binding in `LiveProp`
11-
- DOM morphing changed from `morphdom` to `idiomorph`
1218
- Allow multiple `LiveListener` attributes on a single method
1319
- Requests to LiveComponent are sent as POST by default
1420
- Add method prop to AsLiveComponent to still allow GET requests, usage: `#[AsLiveComponent(method: 'get')]`

src/LiveComponent/assets/dist/Component/ElementDriver.d.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1+
import LiveControllerDefault from '../live_controller';
12
export interface ElementDriver {
23
getModelName(element: HTMLElement): string | null;
3-
getComponentProps(rootElement: HTMLElement): any;
4-
findChildComponentElement(id: string, element: HTMLElement): HTMLElement | null;
5-
getKeyFromElement(element: HTMLElement): string | null;
6-
getEventsToEmit(element: HTMLElement): Array<{
4+
getComponentProps(): any;
5+
getEventsToEmit(): Array<{
76
event: string;
87
data: any;
98
target: string | null;
109
componentName: string | null;
1110
}>;
12-
getBrowserEventsToDispatch(element: HTMLElement): Array<{
11+
getBrowserEventsToDispatch(): Array<{
1312
event: string;
1413
payload: any;
1514
}>;
1615
}
17-
export declare class StandardElementDriver implements ElementDriver {
16+
export declare class StimulusElementDriver implements ElementDriver {
17+
private readonly controller;
18+
constructor(controller: LiveControllerDefault);
1819
getModelName(element: HTMLElement): string | null;
19-
getComponentProps(rootElement: HTMLElement): any;
20-
findChildComponentElement(id: string, element: HTMLElement): HTMLElement | null;
21-
getKeyFromElement(element: HTMLElement): string | null;
22-
getEventsToEmit(element: HTMLElement): Array<{
20+
getComponentProps(): any;
21+
getEventsToEmit(): Array<{
2322
event: string;
2423
data: any;
2524
target: string | null;
2625
componentName: string | null;
2726
}>;
28-
getBrowserEventsToDispatch(element: HTMLElement): Array<{
27+
getBrowserEventsToDispatch(): Array<{
2928
event: string;
3029
payload: any;
3130
}>;

src/LiveComponent/assets/dist/Component/index.d.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import ValueStore from './ValueStore';
33
import { ElementDriver } from './ElementDriver';
44
import { PluginInterface } from './plugins/PluginInterface';
55
import BackendResponse from '../Backend/BackendResponse';
6-
import { ModelBinding } from '../Directive/get_model_binding';
7-
export type ComponentFinder = (currentComponent: Component, onlyParents: boolean, onlyMatchName: string | null) => Component[];
86
export default class Component {
97
readonly element: HTMLElement;
108
readonly name: string;
119
readonly listeners: Map<string, string[]>;
12-
private readonly componentFinder;
1310
private backend;
14-
private readonly elementDriver;
11+
readonly elementDriver: ElementDriver;
1512
id: string | null;
16-
fingerprint: string | null;
13+
fingerprint: string;
1714
readonly valueStore: ValueStore;
1815
private readonly unsyncedInputsTracker;
1916
private hooks;
@@ -25,14 +22,11 @@ export default class Component {
2522
private requestDebounceTimeout;
2623
private nextRequestPromise;
2724
private nextRequestPromiseResolve;
28-
private children;
29-
private parent;
3025
private externalMutationTracker;
3126
constructor(element: HTMLElement, name: string, props: any, listeners: Array<{
3227
event: string;
3328
action: string;
34-
}>, componentFinder: ComponentFinder, fingerprint: string | null, id: string | null, backend: BackendInterface, elementDriver: ElementDriver);
35-
_swapBackend(backend: BackendInterface): void;
29+
}>, id: string | null, backend: BackendInterface, elementDriver: ElementDriver);
3630
addPlugin(plugin: PluginInterface): void;
3731
connect(): void;
3832
disconnect(): void;
@@ -44,17 +38,11 @@ export default class Component {
4438
files(key: string, input: HTMLInputElement): void;
4539
render(): Promise<BackendResponse>;
4640
getUnsyncedModels(): string[];
47-
addChild(child: Component, modelBindings?: ModelBinding[]): void;
48-
removeChild(child: Component): void;
49-
getParent(): Component | null;
50-
getChildren(): Map<string, Component>;
5141
emit(name: string, data: any, onlyMatchingComponentsNamed?: string | null): void;
5242
emitUp(name: string, data: any, onlyMatchingComponentsNamed?: string | null): void;
5343
emitSelf(name: string, data: any): void;
5444
private performEmit;
5545
private doEmit;
56-
updateFromNewElementFromParentRender(toEl: HTMLElement): boolean;
57-
onChildComponentModelUpdate(modelName: string, value: any, childComponent: Component): void;
5846
private isTurboEnabled;
5947
private tryStartingRequest;
6048
private performRequest;
@@ -63,7 +51,7 @@ export default class Component {
6351
private clearRequestDebounceTimeout;
6452
private debouncedStartRequest;
6553
private renderError;
66-
private getChildrenFingerprints;
6754
private resetPromise;
55+
_updateFromParentProps(props: any): void;
6856
}
6957
export declare function proxifyComponent(component: Component): Component;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Component from '../../Component';
2+
import { PluginInterface } from './PluginInterface';
3+
export default class implements PluginInterface {
4+
private readonly component;
5+
private parentModelBindings;
6+
constructor(component: Component);
7+
attachToComponent(component: Component): void;
8+
private getChildrenFingerprints;
9+
private notifyParentModelChange;
10+
private getChildren;
11+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import Component from './Component';
2-
export default class {
3-
private componentMapByElement;
4-
private componentMapByComponent;
5-
registerComponent(element: HTMLElement, component: Component): void;
6-
unregisterComponent(component: Component): void;
7-
getComponent(element: HTMLElement): Promise<Component>;
8-
findComponents(currentComponent: Component, onlyParents: boolean, onlyMatchName: string | null): Component[];
9-
}
2+
export declare const resetRegistry: () => void;
3+
export declare const registerComponent: (component: Component) => void;
4+
export declare const unregisterComponent: (component: Component) => void;
5+
export declare const getComponent: (element: HTMLElement) => Promise<Component>;
6+
export declare const findComponents: (currentComponent: Component, onlyParents: boolean, onlyMatchName: string | null) => Component[];
7+
export declare const findChildren: (currentComponent: Component) => Component[];
8+
export declare const findParent: (currentComponent: Component) => Component | null;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function getElementAsTagText(element: HTMLElement): string;

src/LiveComponent/assets/dist/dom_utils.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ export declare function getModelDirectiveFromElement(element: HTMLElement, throw
88
export declare function elementBelongsToThisComponent(element: Element, component: Component): boolean;
99
export declare function cloneHTMLElement(element: HTMLElement): HTMLElement;
1010
export declare function htmlToElement(html: string): HTMLElement;
11-
export declare function getElementAsTagText(element: HTMLElement): string;

src/LiveComponent/assets/dist/live_controller.d.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Controller } from '@hotwired/stimulus';
22
import Component from './Component';
3-
import ComponentRegistry from './ComponentRegistry';
3+
import { BackendInterface } from './Backend/Backend';
44
export { Component };
5-
export declare const getComponent: (element: HTMLElement) => Promise<Component>;
5+
export { getComponent } from './ComponentRegistry';
66
export interface LiveEvent extends CustomEvent {
77
detail: {
88
controller: LiveController;
@@ -17,17 +17,31 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
1717
static values: {
1818
name: StringConstructor;
1919
url: StringConstructor;
20-
props: ObjectConstructor;
20+
props: {
21+
type: ObjectConstructor;
22+
default: {};
23+
};
24+
propsUpdatedFromParent: {
25+
type: ObjectConstructor;
26+
default: {};
27+
};
2128
csrf: StringConstructor;
2229
listeners: {
2330
type: ArrayConstructor;
2431
default: never[];
2532
};
33+
eventsToEmit: {
34+
type: ArrayConstructor;
35+
default: never[];
36+
};
37+
eventsToDispatch: {
38+
type: ArrayConstructor;
39+
default: never[];
40+
};
2641
debounce: {
2742
type: NumberConstructor;
2843
default: number;
2944
};
30-
id: StringConstructor;
3145
fingerprint: {
3246
type: StringConstructor;
3347
default: string;
@@ -44,11 +58,22 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
4458
readonly nameValue: string;
4559
readonly urlValue: string;
4660
readonly propsValue: any;
61+
propsUpdatedFromParentValue: any;
4762
readonly csrfValue: string;
4863
readonly listenersValue: Array<{
4964
event: string;
5065
action: string;
5166
}>;
67+
readonly eventsToEmitValue: Array<{
68+
event: string;
69+
data: any;
70+
target: string | null;
71+
componentName: string | null;
72+
}>;
73+
readonly eventsToDispatchValue: Array<{
74+
event: string;
75+
payload: any;
76+
}>;
5277
readonly hasDebounceValue: boolean;
5378
readonly debounceValue: number;
5479
readonly fingerprintValue: string;
@@ -59,26 +84,31 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
5984
};
6085
};
6186
private proxiedComponent;
87+
private mutationObserver;
6288
component: Component;
6389
pendingActionTriggerModelElement: HTMLElement | null;
6490
private elementEventListeners;
6591
private pendingFiles;
66-
static componentRegistry: ComponentRegistry;
92+
static backendFactory: (controller: LiveControllerDefault) => BackendInterface;
6793
initialize(): void;
6894
connect(): void;
6995
disconnect(): void;
7096
update(event: any): void;
7197
action(event: any): void;
72-
$render(): Promise<import("./Backend/BackendResponse").default>;
7398
emit(event: Event): void;
7499
emitUp(event: Event): void;
75100
emitSelf(event: Event): void;
76-
private getEmitDirectives;
101+
$render(): Promise<import("./Backend/BackendResponse").default>;
77102
$updateModel(model: string, value: any, shouldRender?: boolean, debounce?: number | boolean): Promise<import("./Backend/BackendResponse").default>;
103+
propsUpdatedFromParentValueChanged(): void;
104+
fingerprintValueChanged(): void;
105+
private getEmitDirectives;
106+
private createComponent;
107+
private connectComponent;
108+
private disconnectComponent;
78109
private handleInputEvent;
79110
private handleChangeEvent;
80111
private updateModelFromElementEvent;
81-
handleConnectedControllerEvent(event: LiveEvent): void;
82-
handleDisconnectedChildControllerEvent(event: LiveEvent): void;
83112
private dispatchEvent;
113+
private onMutations;
84114
}

0 commit comments

Comments
 (0)