]> BookStack Code Mirror - bookstack/blobdiff - resources/js/services/components.ts
Comments: Addressed a range of edge cases and ux issues for references
[bookstack] / resources / js / services / components.ts
index c19939e92a9b874aa61da08943012c6cbd9aa505..0e13cd0a09fca78429a117a50b2aa875f18012e3 100644 (file)
@@ -139,8 +139,8 @@ export class ComponentStore {
     /**
      * Get all the components of the given name.
      */
-    public get(name: string): Component[] {
-        return this.components[name] || [];
+    public get<T extends Component>(name: string): T[] {
+        return (this.components[name] || []) as T[];
     }
 
     /**
@@ -150,4 +150,9 @@ export class ComponentStore {
         const elComponents = this.elementComponentMap.get(element) || {};
         return elComponents[name] || null;
     }
+
+    public allWithinElement<T extends Component>(element: HTMLElement, name: string): T[] {
+        const components = this.get<T>(name);
+        return components.filter(c => element.contains(c.$el));
+    }
 }