@pechynho/stimulus-typescript 0.0.13 → 0.0.14

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default as PortalController } from './portal-controller';
2
2
  export { Typed, Target, TypedObject, TypedArray } from './typed';
3
- export { isActionEvent, getController, getControllerAsync, addStimulusAction, removeStimulusAction } from './utils';
3
+ export { isActionEvent, getController, getControllerAsync, addStimulusAction, removeStimulusAction, addStimulusOutlet, removeStimulusOutlet } from './utils';
4
4
  export { Resolvable } from './resolvable';
5
5
  export { Portals } from './portal';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Export the main components
2
2
  export { default as PortalController } from './portal-controller';
3
3
  export { Typed, Target, TypedObject, TypedArray } from './typed';
4
- export { isActionEvent, getController, getControllerAsync, addStimulusAction, removeStimulusAction } from './utils';
4
+ export { isActionEvent, getController, getControllerAsync, addStimulusAction, removeStimulusAction, addStimulusOutlet, removeStimulusOutlet } from './utils';
5
5
  export { Resolvable } from './resolvable';
6
6
  export { Portals } from './portal';
package/dist/utils.d.ts CHANGED
@@ -3,6 +3,8 @@ export declare const camelCase: (value: string) => string;
3
3
  export declare const capitalize: (value: string) => string;
4
4
  export declare function addStimulusAction(element: HTMLElement, identifier: string, method: string, event?: string, params?: Record<string, object | string | number | boolean>): void;
5
5
  export declare function removeStimulusAction(element: HTMLElement, identifier: string, method: string, event?: string, removeParams?: boolean | string[]): void;
6
+ export declare function addStimulusOutlet(element: HTMLElement, identifier: string, outlet: string, selector: string): void;
7
+ export declare function removeStimulusOutlet(element: HTMLElement, identifier: string, outlet?: string): void;
6
8
  export declare const isActionEvent: (value: any) => value is ActionEvent;
7
9
  export declare const getController: <T extends Controller>(app: Application, element: HTMLElement, identifier: string) => T | null;
8
10
  export declare const getControllerAsync: <T extends Controller>(app: Application, element: HTMLElement, identifier: string, timeout?: number, poll?: number) => Promise<T | null>;
package/dist/utils.js CHANGED
@@ -56,6 +56,21 @@ export function removeStimulusAction(element, identifier, method, event, removeP
56
56
  }
57
57
  }
58
58
  }
59
+ export function addStimulusOutlet(element, identifier, outlet, selector) {
60
+ element.dataset[`${camelCase(identifier)}${capitalize(camelCase(outlet))}Outlet`] = selector;
61
+ }
62
+ export function removeStimulusOutlet(element, identifier, outlet) {
63
+ if (outlet !== undefined) {
64
+ delete element.dataset[`${camelCase(identifier)}${capitalize(camelCase(outlet))}Outlet`];
65
+ return;
66
+ }
67
+ const prefix = camelCase(identifier);
68
+ for (const key of Object.keys(element.dataset)) {
69
+ if (key.startsWith(prefix) && key.endsWith('Outlet')) {
70
+ delete element.dataset[key];
71
+ }
72
+ }
73
+ }
59
74
  export const isActionEvent = (value) => {
60
75
  return value instanceof Event && 'params' in value && typeof value.params === 'object';
61
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pechynho/stimulus-typescript",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Set of TypeScript utilities for Stimulus controllers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Export the main components
2
2
  export {default as PortalController} from './portal-controller';
3
3
  export {Typed, Target, TypedObject, TypedArray} from './typed';
4
- export {isActionEvent, getController, getControllerAsync, addStimulusAction, removeStimulusAction} from './utils';
4
+ export {isActionEvent, getController, getControllerAsync, addStimulusAction, removeStimulusAction, addStimulusOutlet, removeStimulusOutlet} from './utils';
5
5
  export {Resolvable} from './resolvable';
6
6
  export {Portals} from './portal';
package/src/utils.ts CHANGED
@@ -72,6 +72,32 @@ export function removeStimulusAction(
72
72
  }
73
73
  }
74
74
 
75
+ export function addStimulusOutlet(
76
+ element: HTMLElement,
77
+ identifier: string,
78
+ outlet: string,
79
+ selector: string,
80
+ ): void {
81
+ element.dataset[`${camelCase(identifier)}${capitalize(camelCase(outlet))}Outlet`] = selector;
82
+ }
83
+
84
+ export function removeStimulusOutlet(
85
+ element: HTMLElement,
86
+ identifier: string,
87
+ outlet?: string,
88
+ ): void {
89
+ if (outlet !== undefined) {
90
+ delete element.dataset[`${camelCase(identifier)}${capitalize(camelCase(outlet))}Outlet`];
91
+ return;
92
+ }
93
+ const prefix = camelCase(identifier);
94
+ for (const key of Object.keys(element.dataset)) {
95
+ if (key.startsWith(prefix) && key.endsWith('Outlet')) {
96
+ delete element.dataset[key];
97
+ }
98
+ }
99
+ }
100
+
75
101
  export const isActionEvent = (value: any): value is ActionEvent => {
76
102
  return value instanceof Event && 'params' in value && typeof value.params === 'object';
77
103
  }