@patternfly/pfe-core 2.0.0-next.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/LICENSE.txt +19 -0
- package/README.md +34 -0
- package/context.d.ts +53 -0
- package/context.js +2 -0
- package/context.js.map +7 -0
- package/controllers/cascade-controller.d.ts +43 -0
- package/controllers/cascade-controller.js +2 -0
- package/controllers/cascade-controller.js.map +7 -0
- package/controllers/color-context-controller.d.ts +41 -0
- package/controllers/color-context-controller.js +55 -0
- package/controllers/color-context-controller.js.map +7 -0
- package/controllers/color-context-controller.scss +43 -0
- package/controllers/css-variable-controller.d.ts +9 -0
- package/controllers/css-variable-controller.js +2 -0
- package/controllers/css-variable-controller.js.map +7 -0
- package/controllers/light-dom-controller.d.ts +20 -0
- package/controllers/light-dom-controller.js +2 -0
- package/controllers/light-dom-controller.js.map +7 -0
- package/controllers/logger.d.ts +52 -0
- package/controllers/logger.js +2 -0
- package/controllers/logger.js.map +7 -0
- package/controllers/perf-controller.d.ts +9 -0
- package/controllers/perf-controller.js +2 -0
- package/controllers/perf-controller.js.map +7 -0
- package/controllers/property-observer-controller.d.ts +20 -0
- package/controllers/property-observer-controller.js +2 -0
- package/controllers/property-observer-controller.js.map +7 -0
- package/controllers/slot-controller.d.ts +77 -0
- package/controllers/slot-controller.js +2 -0
- package/controllers/slot-controller.js.map +7 -0
- package/controllers/style-controller.d.ts +21 -0
- package/controllers/style-controller.js +2 -0
- package/controllers/style-controller.js.map +7 -0
- package/core.d.ts +38 -0
- package/core.js +2 -0
- package/core.js.map +7 -0
- package/custom-elements.json +5 -0
- package/decorators/bound.d.ts +13 -0
- package/decorators/bound.js +2 -0
- package/decorators/bound.js.map +7 -0
- package/decorators/cascades.d.ts +5 -0
- package/decorators/cascades.js +2 -0
- package/decorators/cascades.js.map +7 -0
- package/decorators/initializer.d.ts +10 -0
- package/decorators/initializer.js +2 -0
- package/decorators/initializer.js.map +7 -0
- package/decorators/observed.d.ts +33 -0
- package/decorators/observed.js +2 -0
- package/decorators/observed.js.map +7 -0
- package/decorators/pfelement.d.ts +6 -0
- package/decorators/pfelement.js +2 -0
- package/decorators/pfelement.js.map +7 -0
- package/decorators/time.d.ts +4 -0
- package/decorators/time.js +2 -0
- package/decorators/time.js.map +7 -0
- package/decorators/trace.d.ts +2 -0
- package/decorators/trace.js +2 -0
- package/decorators/trace.js.map +7 -0
- package/decorators.d.ts +7 -0
- package/decorators.js +2 -0
- package/decorators.js.map +7 -0
- package/functions/debounce.d.ts +9 -0
- package/functions/debounce.js +2 -0
- package/functions/debounce.js.map +7 -0
- package/functions/deprecatedCustomEvent.d.ts +5 -0
- package/functions/deprecatedCustomEvent.js +2 -0
- package/functions/deprecatedCustomEvent.js.map +7 -0
- package/functions/random.d.ts +6 -0
- package/functions/random.js +2 -0
- package/functions/random.js.map +7 -0
- package/package.json +90 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveElement } from 'lit';
|
|
2
|
+
interface AnonymousSlot {
|
|
3
|
+
hasContent: boolean;
|
|
4
|
+
elements: Element[];
|
|
5
|
+
slot: HTMLSlotElement | null;
|
|
6
|
+
}
|
|
7
|
+
interface NamedSlot extends AnonymousSlot {
|
|
8
|
+
name: string;
|
|
9
|
+
initialized: true;
|
|
10
|
+
}
|
|
11
|
+
export declare type Slot = NamedSlot | AnonymousSlot;
|
|
12
|
+
export interface SlotsConfig {
|
|
13
|
+
slots: (string | null)[];
|
|
14
|
+
/**
|
|
15
|
+
* Object mapping new slot name keys to deprecated slot name values
|
|
16
|
+
* @example `pfe-modal--header` is deprecated in favour of `header`
|
|
17
|
+
* ```js
|
|
18
|
+
* new SlotController(this, {
|
|
19
|
+
* slots: ['header'],
|
|
20
|
+
* deprecations: {
|
|
21
|
+
* 'header': 'pfe-modal--header'
|
|
22
|
+
* }
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
deprecations?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export declare class SlotController implements ReactiveController {
|
|
29
|
+
host: ReactiveElement;
|
|
30
|
+
static anonymous: symbol;
|
|
31
|
+
private nodes;
|
|
32
|
+
private logger;
|
|
33
|
+
private firstUpdated;
|
|
34
|
+
private mo;
|
|
35
|
+
private slotNames;
|
|
36
|
+
private deprecations;
|
|
37
|
+
constructor(host: ReactiveElement, ...config: ([SlotsConfig] | (string | null)[]));
|
|
38
|
+
hostConnected(): void;
|
|
39
|
+
hostUpdated(): void;
|
|
40
|
+
hostDisconnected(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a boolean statement of whether or not any of those slots exists in the light DOM.
|
|
43
|
+
*
|
|
44
|
+
* @param {String|Array} name The slot name.
|
|
45
|
+
* @example this.hasSlotted("header");
|
|
46
|
+
*/
|
|
47
|
+
hasSlotted(...names: string[]): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Given a slot name or slot names, returns elements assigned to the requested slots as an array.
|
|
50
|
+
* If no value is provided, it returns all children not assigned to a slot (without a slot attribute).
|
|
51
|
+
*
|
|
52
|
+
* @example Get header-slotted elements
|
|
53
|
+
* ```js
|
|
54
|
+
* this.getSlotted('header')
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example Get header- and footer-slotted elements
|
|
58
|
+
* ```js
|
|
59
|
+
* this.getSlotted('header', 'footer')
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example Get default-slotted elements
|
|
63
|
+
* ```js
|
|
64
|
+
* this.getSlotted();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
getSlotted<T extends Element = Element>(...slotNames: string[]): T[];
|
|
68
|
+
private onSlotChange;
|
|
69
|
+
private onMutation;
|
|
70
|
+
private getChildrenForSlot;
|
|
71
|
+
private initSlot;
|
|
72
|
+
/**
|
|
73
|
+
* Maps the defined slots into an object that is easier to query
|
|
74
|
+
*/
|
|
75
|
+
private init;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var a=(i,t,e,o)=>{for(var s=o>1?void 0:o?m(t,e):t,n=i.length-1,r;n>=0;n--)(r=i[n])&&(s=(o?r(t,e,s):r(s))||s);return o&&s&&c(t,e,s),s};import{bound as h}from"../decorators/bound.js";import{Logger as g}from"./logger.js";function u(i){return i.length===1&&i[0]!==null}var p=i=>t=>i===l.anonymous?!t.hasAttribute("slot"):t.getAttribute("slot")===i,d=class{constructor(t,...e){this.host=t;this.nodes=new Map;this.firstUpdated=!1;this.mo=new MutationObserver(this.onMutation);this.deprecations={};if(this.logger=new g(this.host),u(e)){let[{slots:o,deprecations:s}]=e;this.slotNames=o,this.deprecations=s??{}}else e.length>1?(this.slotNames=e,this.deprecations={}):this.slotNames=[null];t.addController(this)}hostConnected(){this.host.addEventListener("slotchange",this.onSlotChange),this.firstUpdated=!1,this.mo.observe(this.host,{childList:!0}),this.init()}hostUpdated(){this.firstUpdated||(this.slotNames.forEach(this.initSlot),this.firstUpdated=!0)}hostDisconnected(){this.mo.disconnect()}hasSlotted(...t){return t.length?t.some(e=>this.nodes.get(e)?.hasContent??!1):(this.logger.warn("Please provide at least one slot name for which to search."),!1)}getSlotted(...t){return t.length?t.flatMap(e=>this.nodes.get(e)?.elements??[]):this.nodes.get(d.anonymous)?.elements??[]}onSlotChange(t){let e=t.target.name;this.initSlot(e),this.host.requestUpdate()}async onMutation(t){let e=[];for(let{addedNodes:o,removedNodes:s}of t)for(let n of[...o,...s])n instanceof HTMLElement&&n.slot&&(this.initSlot(n.slot),e.push(n.slot));e.length&&this.host.requestUpdate()}getChildrenForSlot(t){return Array.from(this.host.children).filter(p(t))}initSlot(t){let e=t||d.anonymous,o=this.nodes.get(e)?.slot?.assignedElements?.()??this.getChildrenForSlot(e),s=t?`slot[name="${t}"]`:"slot:not([name])",n=this.host.shadowRoot?.querySelector?.(s)??null,r=!!o.length;this.nodes.set(e,{elements:o,name:t??"",hasContent:r,slot:n}),this.logger.log(t,r)}init(){this.nodes.clear(),this.slotNames.forEach(this.initSlot),Object.values(this.deprecations).forEach(this.initSlot),this.host.requestUpdate()}},l=d;l.anonymous=Symbol("anonymous slot"),a([h],l.prototype,"onSlotChange",1),a([h],l.prototype,"onMutation",1),a([h],l.prototype,"initSlot",1),a([h],l.prototype,"init",1);export{l as SlotController};
|
|
2
|
+
//# sourceMappingURL=slot-controller.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["slot-controller.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { bound } from '../decorators/bound.js';\nimport { Logger } from './logger.js';\n\ninterface AnonymousSlot {\n hasContent: boolean;\n elements: Element[];\n slot: HTMLSlotElement|null;\n}\n\ninterface NamedSlot extends AnonymousSlot {\n name: string;\n initialized: true;\n}\n\nexport type Slot = NamedSlot|AnonymousSlot;\n\nexport interface SlotsConfig {\n slots: (string|null)[];\n /**\n * Object mapping new slot name keys to deprecated slot name values\n * @example `pfe-modal--header` is deprecated in favour of `header`\n * ```js\n * new SlotController(this, {\n * slots: ['header'],\n * deprecations: {\n * 'header': 'pfe-modal--header'\n * }\n * })\n * ```\n */\n deprecations?: Record<string, string>;\n}\n\nfunction isObjectConfigSpread(config: ([SlotsConfig]|(string|null)[])): config is [SlotsConfig] {\n return config.length === 1 && config[0] !== null;\n}\n\n/**\n * If it's a named slot, return its children,\n * for the default slot, look for direct children not assigned to a slot\n */\nconst isSlot =\n <T extends Element = Element>(n: string|typeof SlotController.anonymous) =>\n (child: Element): child is T =>\n n === SlotController.anonymous ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static anonymous = Symbol('anonymous slot');\n\n private nodes = new Map<string|typeof SlotController.anonymous, Slot>();\n\n private logger: Logger;\n\n private firstUpdated = false;\n\n private mo = new MutationObserver(this.onMutation);\n\n private slotNames: (string|null)[];\n\n private deprecations: Record<string, string> = {};\n\n constructor(public host: ReactiveElement, ...config: ([SlotsConfig]|(string|null)[])) {\n this.logger = new Logger(this.host);\n\n if (isObjectConfigSpread(config)) {\n const [{ slots, deprecations }] = config;\n this.slotNames = slots;\n this.deprecations = deprecations ?? {};\n } else if (config.length > 1) {\n this.slotNames = config;\n this.deprecations = {};\n } else {\n this.slotNames = [null];\n }\n\n\n host.addController(this);\n }\n\n hostConnected() {\n this.host.addEventListener('slotchange', this.onSlotChange as EventListener);\n this.firstUpdated = false;\n this.mo.observe(this.host, { childList: true });\n this.init();\n }\n\n hostUpdated() {\n if (!this.firstUpdated) {\n this.slotNames.forEach(this.initSlot);\n this.firstUpdated = true;\n }\n }\n\n hostDisconnected() {\n this.mo.disconnect();\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n *\n * @param {String|Array} name The slot name.\n * @example this.hasSlotted(\"header\");\n */\n hasSlotted(...names: string[]): boolean {\n if (!names.length) {\n this.logger.warn(`Please provide at least one slot name for which to search.`);\n return false;\n } else {\n return names.some(x =>\n this.nodes.get(x)?.hasContent ?? false);\n }\n }\n\n /**\n * Given a slot name or slot names, returns elements assigned to the requested slots as an array.\n * If no value is provided, it returns all children not assigned to a slot (without a slot attribute).\n *\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n *\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\n *\n * @example Get default-slotted elements\n * ```js\n * this.getSlotted();\n * ```\n */\n getSlotted<T extends Element = Element>(...slotNames: string[]): T[] {\n if (!slotNames.length) {\n return (this.nodes.get(SlotController.anonymous)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.nodes.get(slotName)?.elements ?? []) as T[];\n }\n }\n\n @bound private onSlotChange(event: Event & { target: HTMLSlotElement }) {\n const slotName = event.target.name;\n this.initSlot(slotName);\n this.host.requestUpdate();\n }\n\n @bound private async onMutation(records: MutationRecord[]) {\n const changed = [];\n for (const { addedNodes, removedNodes } of records) {\n for (const node of [...addedNodes, ...removedNodes]) {\n if (node instanceof HTMLElement && node.slot) {\n this.initSlot(node.slot);\n changed.push(node.slot);\n }\n }\n }\n if (changed.length) {\n this.host.requestUpdate();\n }\n }\n\n private getChildrenForSlot<T extends Element = Element>(name: string|typeof SlotController.anonymous): T[] {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\n }\n\n @bound private initSlot(slotName: string|null) {\n const name = slotName || SlotController.anonymous;\n const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? this.getChildrenForSlot(name);\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;\n const hasContent = !!elements.length;\n this.nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });\n this.logger.log(slotName, hasContent);\n }\n\n /**\n * Maps the defined slots into an object that is easier to query\n */\n @bound private init() {\n this.nodes.clear();\n // Loop over the properties provided by the schema\n this.slotNames.forEach(this.initSlot);\n Object.values(this.deprecations).forEach(this.initSlot);\n this.host.requestUpdate();\n }\n}\n"],
|
|
5
|
+
"mappings": "wMAEA,+CACA,qCAgCA,WAA8B,EAAkE,CAC9F,MAAO,GAAO,SAAW,GAAK,EAAO,KAAO,KAO9C,GAAM,GACJ,AAA8B,GAC5B,AAAC,GACG,IAAM,EAAe,UAAY,CAAC,EAAM,aAAa,QACrD,EAAM,aAAa,UAAY,EAEhC,OAAmD,CAexD,YAAmB,KAA0B,EAAyC,CAAnE,YAZX,WAAQ,GAAI,KAIZ,kBAAe,GAEf,QAAK,GAAI,kBAAiB,KAAK,YAI/B,kBAAuC,GAK7C,GAFA,KAAK,OAAS,GAAI,GAAO,KAAK,MAE1B,EAAqB,GAAS,CAChC,GAAM,CAAC,CAAE,QAAO,iBAAkB,EAClC,KAAK,UAAY,EACjB,KAAK,aAAe,GAAgB,OAC/B,AAAI,GAAO,OAAS,EACzB,MAAK,UAAY,EACjB,KAAK,aAAe,IAEpB,KAAK,UAAY,CAAC,MAIpB,EAAK,cAAc,MAGrB,eAAgB,CACd,KAAK,KAAK,iBAAiB,aAAc,KAAK,cAC9C,KAAK,aAAe,GACpB,KAAK,GAAG,QAAQ,KAAK,KAAM,CAAE,UAAW,KACxC,KAAK,OAGP,aAAc,CACZ,AAAK,KAAK,cACR,MAAK,UAAU,QAAQ,KAAK,UAC5B,KAAK,aAAe,IAIxB,kBAAmB,CACjB,KAAK,GAAG,aASV,cAAc,EAA0B,CACtC,MAAK,GAAM,OAIF,EAAM,KAAK,GAChB,KAAK,MAAM,IAAI,IAAI,YAAc,IAJnC,MAAK,OAAO,KAAK,8DACV,IA0BX,cAA2C,EAA0B,CACnE,MAAK,GAAU,OAGN,EAAU,QAAQ,GACvB,KAAK,MAAM,IAAI,IAAW,UAAY,IAHhC,KAAK,MAAM,IAAI,EAAe,YAAY,UAAY,GAOnD,aAAa,EAA4C,CACtE,GAAM,GAAW,EAAM,OAAO,KAC9B,KAAK,SAAS,GACd,KAAK,KAAK,qBAGS,YAAW,EAA2B,CACzD,GAAM,GAAU,GAChB,OAAW,CAAE,aAAY,iBAAkB,GACzC,OAAW,KAAQ,CAAC,GAAG,EAAY,GAAG,GACpC,AAAI,YAAgB,cAAe,EAAK,MACtC,MAAK,SAAS,EAAK,MACnB,EAAQ,KAAK,EAAK,OAIxB,AAAI,EAAQ,QACV,KAAK,KAAK,gBAIN,mBAAgD,EAAmD,CAEzG,MAAO,AADU,OAAM,KAAK,KAAK,KAAK,UACtB,OAAO,EAAO,IAGjB,SAAS,EAAuB,CAC7C,GAAM,GAAO,GAAY,EAAe,UAClC,EAAW,KAAK,MAAM,IAAI,IAAO,MAAM,sBAAwB,KAAK,mBAAmB,GACvF,EAAW,EAAW,cAAc,MAAe,mBACnD,EAAO,KAAK,KAAK,YAAY,gBAAiC,IAAa,KAC3E,EAAa,CAAC,CAAC,EAAS,OAC9B,KAAK,MAAM,IAAI,EAAM,CAAE,WAAU,KAAM,GAAY,GAAI,aAAY,SACnE,KAAK,OAAO,IAAI,EAAU,GAMb,MAAO,CACpB,KAAK,MAAM,QAEX,KAAK,UAAU,QAAQ,KAAK,UAC5B,OAAO,OAAO,KAAK,cAAc,QAAQ,KAAK,UAC9C,KAAK,KAAK,kBA3IP,IACS,AADT,EACS,UAAY,OAAO,kBA8FlB,GAAd,GAAc,AA/FV,EA+FU,4BAMM,GAApB,GAAoB,AArGhB,EAqGgB,0BAoBN,GAAd,GAAc,AAzHV,EAyHU,wBAaA,GAAd,GAAc,AAtIV,EAsIU",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveElement, CSSResultGroup } from 'lit';
|
|
2
|
+
declare global {
|
|
3
|
+
interface ShadowRoot {
|
|
4
|
+
adoptedStyleSheets: CSSStyleSheet[];
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Controller which adds styles to it's host element.
|
|
9
|
+
* Like `static styles = []`, except a controller.
|
|
10
|
+
* Should typically only be used within other controllers.
|
|
11
|
+
*/
|
|
12
|
+
export declare class StyleController implements ReactiveController {
|
|
13
|
+
private host;
|
|
14
|
+
/** These styles will be applied to the host element */
|
|
15
|
+
private styles;
|
|
16
|
+
private stylesAdopted;
|
|
17
|
+
constructor(host: ReactiveElement,
|
|
18
|
+
/** These styles will be applied to the host element */
|
|
19
|
+
styles: CSSResultGroup);
|
|
20
|
+
hostConnected(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getCompatibleStyle as l,supportsAdoptingStyleSheets as r}from"lit";var n=class{constructor(t,e){this.host=t;this.styles=e;this.stylesAdopted=!1;t.addController(this)}hostConnected(){if(this.stylesAdopted||!(this.host.renderRoot instanceof ShadowRoot))return;let t=[this.styles].flatMap(e=>l(e)).filter(e=>!!e);r?this.host.renderRoot.adoptedStyleSheets=[...this.host.renderRoot.adoptedStyleSheets??[],...t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet)]:t.forEach(e=>{let o=document.createElement("style"),s=window.litNonce;s!==void 0&&o.setAttribute("nonce",s),o.textContent=e.cssText,this.host.renderRoot.appendChild(o)}),this.stylesAdopted=!0}};export{n as StyleController};
|
|
2
|
+
//# sourceMappingURL=style-controller.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["style-controller.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveController, ReactiveElement, CSSResultGroup, CSSResultOrNative, CSSResult } from 'lit';\nimport { getCompatibleStyle, supportsAdoptingStyleSheets } from 'lit';\n\ndeclare global {\n interface ShadowRoot {\n adoptedStyleSheets: CSSStyleSheet[];\n }\n}\n\n/**\n * Controller which adds styles to it's host element.\n * Like `static styles = []`, except a controller.\n * Should typically only be used within other controllers.\n */\nexport class StyleController implements ReactiveController {\n private stylesAdopted = false;\n\n constructor(\n private host: ReactiveElement,\n /** These styles will be applied to the host element */\n private styles: CSSResultGroup,\n ) {\n host.addController(this);\n }\n\n hostConnected(): void {\n if (this.stylesAdopted || !(this.host.renderRoot instanceof ShadowRoot)) {\n return;\n }\n\n const styles = [this.styles].flatMap(x => getCompatibleStyle(x as CSSResultOrNative)).filter(x => !!x);\n\n if (supportsAdoptingStyleSheets) {\n this.host.renderRoot.adoptedStyleSheets = [\n ...this.host.renderRoot.adoptedStyleSheets ?? [],\n ...styles.map(x => x instanceof CSSStyleSheet ? x : x.styleSheet as CSSStyleSheet),\n ];\n } else {\n styles.forEach(s => {\n const style = document.createElement('style');\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nonce = (window as any)['litNonce'];\n if (nonce !== undefined) {\n style.setAttribute('nonce', nonce);\n }\n style.textContent = (s as CSSResult).cssText;\n this.host.renderRoot.appendChild(style);\n });\n }\n\n this.stylesAdopted = true;\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,0EAaO,WAAoD,CAGzD,YACU,EAEA,EACR,CAHQ,YAEA,cALF,mBAAgB,GAOtB,EAAK,cAAc,MAGrB,eAAsB,CACpB,GAAI,KAAK,eAAiB,CAAE,MAAK,KAAK,qBAAsB,aAC1D,OAGF,GAAM,GAAS,CAAC,KAAK,QAAQ,QAAQ,GAAK,EAAmB,IAAyB,OAAO,GAAK,CAAC,CAAC,GAEpG,AAAI,EACF,KAAK,KAAK,WAAW,mBAAqB,CACxC,GAAG,KAAK,KAAK,WAAW,oBAAsB,GAC9C,GAAG,EAAO,IAAI,GAAK,YAAa,eAAgB,EAAI,EAAE,aAGxD,EAAO,QAAQ,GAAK,CAClB,GAAM,GAAQ,SAAS,cAAc,SAE/B,EAAS,OAAe,SAC9B,AAAI,IAAU,QACZ,EAAM,aAAa,QAAS,GAE9B,EAAM,YAAe,EAAgB,QACrC,KAAK,KAAK,WAAW,YAAY,KAIrC,KAAK,cAAgB",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/core.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ComplexAttributeConverter } from 'lit';
|
|
2
|
+
/** PatternFly Elements global config object */
|
|
3
|
+
export interface PfeConfig {
|
|
4
|
+
/** Set to false to disable client-side page load performance tracking */
|
|
5
|
+
trackPerformance?: boolean;
|
|
6
|
+
/** Set to false to disable various debug logs */
|
|
7
|
+
log?: boolean;
|
|
8
|
+
/** Set to false to disable automatically removing `unresolved` attr from body */
|
|
9
|
+
autoReveal?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare type ColorTheme = ('base' | 'accent' | 'complement' | 'lighter' | 'lightest' | 'darker' | 'darkest');
|
|
12
|
+
export declare type ContextTheme = ('dark' | 'light' | 'saturated');
|
|
13
|
+
declare const noPref: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* A boolean value that indicates if the performance should be tracked.
|
|
16
|
+
* For use in a JS file or script tag; can also be added in the constructor of a component during development.
|
|
17
|
+
* @example trackPerformance(true);
|
|
18
|
+
*/
|
|
19
|
+
export declare function trackPerformance(preference?: boolean | typeof noPref): boolean | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* A LitElement property converter which represents a list of numbers as a comma separated string
|
|
22
|
+
* @see https://lit.dev/docs/components/properties/#conversion-converter
|
|
23
|
+
*/
|
|
24
|
+
export declare const NumberListConverter: ComplexAttributeConverter<null | number[]>;
|
|
25
|
+
/**
|
|
26
|
+
* A composed, bubbling event for UI interactions
|
|
27
|
+
* e.g. when an accordion panel opens.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ComposedEvent extends Event {
|
|
30
|
+
constructor(type: string, init?: EventInit);
|
|
31
|
+
}
|
|
32
|
+
declare global {
|
|
33
|
+
interface Window {
|
|
34
|
+
/** Global configuration settings for PatternFly Elements */
|
|
35
|
+
PfeConfig: PfeConfig;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export {};
|
package/core.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Symbol();function r(e){return document.head.querySelector(`meta[name="${e}"]`)?.content}function f(e=o){return e!==o&&(window.PfeConfig.trackPerformance=!!e),window.PfeConfig.trackPerformance}var l={fromAttribute(e){return typeof e!="string"?null:e.split(",").map(t=>t.trim()).map(t=>parseInt(t,10))},toAttribute(e){return e.join(",")}},i=class extends Event{constructor(t,a){super(t,{bubbles:!0,composed:!0,...a})}},n=document.body.hasAttribute("no-auto-reveal");window.PfeConfig=Object.assign(window.PfeConfig??{},{trackPerformance:window.PfeConfig?.trackPerformance??r("pfe-track-performance")==="true",autoReveal:window.PfeConfig?.autoReveal??n?!n:r("pfe-auto-reveal")==="true",get log(){return!!localStorage.pfeLog},set log(e){e?localStorage.setItem("pfeLog",`${!0}`):localStorage.removeItem("pfeLog")}});export{i as ComposedEvent,l as NumberListConverter,f as trackPerformance};
|
|
2
|
+
//# sourceMappingURL=core.js.map
|
package/core.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["core.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ComplexAttributeConverter } from 'lit';\n\n/** PatternFly Elements global config object */\nexport interface PfeConfig {\n /** Set to false to disable client-side page load performance tracking */\n trackPerformance?: boolean;\n /** Set to false to disable various debug logs */\n log?: boolean;\n /** Set to false to disable automatically removing `unresolved` attr from body */\n autoReveal?: boolean;\n}\n\nexport type ColorTheme = (\n | 'base'\n | 'accent'\n | 'complement'\n | 'lighter'\n | 'lightest'\n | 'darker'\n | 'darkest'\n);\n\nexport type ContextTheme = (\n | 'dark'\n | 'light'\n | 'saturated'\n);\n\nconst noPref = Symbol();\n\n/** Retrieve an HTML metadata item */\nfunction getMeta(name: string): string|undefined {\n return document.head.querySelector<HTMLMetaElement>(`meta[name=\"${name}\"]`)?.content;\n}\n\n/**\n * A boolean value that indicates if the performance should be tracked.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example trackPerformance(true);\n */\nexport function trackPerformance(preference: boolean | typeof noPref = noPref) {\n if (preference !== noPref) {\n window.PfeConfig.trackPerformance = !!preference;\n }\n return window.PfeConfig.trackPerformance;\n}\n\n/**\n * A LitElement property converter which represents a list of numbers as a comma separated string\n * @see https://lit.dev/docs/components/properties/#conversion-converter\n */\nexport const NumberListConverter: ComplexAttributeConverter<null|number[]> = {\n fromAttribute(value: string) {\n if (typeof value !== 'string') {\n return null;\n } else {\n return value.split(',').map(x => x.trim()).map(x => parseInt(x, 10));\n }\n },\n toAttribute(value: number[]) {\n return value.join(',');\n },\n};\n\n/**\n * A composed, bubbling event for UI interactions\n * e.g. when an accordion panel opens.\n */\nexport class ComposedEvent extends Event {\n constructor(type: string, init?: EventInit) {\n super(type, {\n bubbles: true,\n composed: true,\n ...init\n });\n }\n}\n\n// \uD83D\uDC47 SIDE EFFECTS \uD83D\uDC47\n\ndeclare global {\n interface Window {\n /** Global configuration settings for PatternFly Elements */\n PfeConfig: PfeConfig;\n }\n}\n\nconst bodyNoAutoReveal = document.body.hasAttribute('no-auto-reveal');\n\n/** Global patternfly elements config */\nwindow.PfeConfig = Object.assign(window.PfeConfig ?? {}, {\n trackPerformance: window.PfeConfig?.trackPerformance ?? getMeta('pfe-track-performance') === 'true',\n autoReveal: window.PfeConfig?.autoReveal ?? bodyNoAutoReveal ? !bodyNoAutoReveal : getMeta('pfe-auto-reveal') === 'true',\n get log() {\n return !!localStorage.pfeLog;\n },\n set log(v: boolean) {\n if (v) {\n localStorage.setItem('pfeLog', `${true}`);\n } else {\n localStorage.removeItem('pfeLog');\n }\n },\n});\n"],
|
|
5
|
+
"mappings": "AA4BA,GAAM,GAAS,SAGf,WAAiB,EAAgC,CAC/C,MAAO,UAAS,KAAK,cAA+B,cAAc,QAAW,QAQxE,WAA0B,EAAsC,EAAQ,CAC7E,MAAI,KAAe,GACjB,QAAO,UAAU,iBAAmB,CAAC,CAAC,GAEjC,OAAO,UAAU,iBAOnB,GAAM,GAAgE,CAC3E,cAAc,EAAe,CAC3B,MAAI,OAAO,IAAU,SACZ,KAEA,EAAM,MAAM,KAAK,IAAI,GAAK,EAAE,QAAQ,IAAI,GAAK,SAAS,EAAG,MAGpE,YAAY,EAAiB,CAC3B,MAAO,GAAM,KAAK,OAQf,eAA4B,MAAM,CACvC,YAAY,EAAc,EAAkB,CAC1C,MAAM,EAAM,CACV,QAAS,GACT,SAAU,MACP,MAcH,EAAmB,SAAS,KAAK,aAAa,kBAGpD,OAAO,UAAY,OAAO,OAAO,OAAO,WAAa,GAAI,CACvD,iBAAkB,OAAO,WAAW,kBAAoB,EAAQ,2BAA6B,OAC7F,WAAY,OAAO,WAAW,YAAc,EAAmB,CAAC,EAAmB,EAAQ,qBAAuB,UAC9G,MAAM,CACR,MAAO,CAAC,CAAC,aAAa,WAEpB,KAAI,EAAY,CAClB,AAAI,EACF,aAAa,QAAQ,SAAU,GAAG,MAElC,aAAa,WAAW",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binds a class method to the instance
|
|
3
|
+
*
|
|
4
|
+
* @example Binding an event listener
|
|
5
|
+
* ```ts
|
|
6
|
+
* private mo = new MutationObserver(this.onMutation);
|
|
7
|
+
*
|
|
8
|
+
* @bound onMutation(records: MutationRecord[]) {
|
|
9
|
+
* this.count = this.children.length;
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function bound(_: unknown, key: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function o(n,e,t){if(typeof t?.value!="function")throw new TypeError(`Only methods can be decorated with @bound. <${e??n.name}> is not a method!`);return{configurable:!0,get(){let r=t.value.bind(this);return Object.defineProperty(this,e,{value:r,configurable:!0,writable:!0}),r}}}export{o as bound};
|
|
2
|
+
//# sourceMappingURL=bound.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["bound.ts"],
|
|
4
|
+
"sourcesContent": ["const configurable = true;\n\n/**\n * Binds a class method to the instance\n *\n * @example Binding an event listener\n * ```ts\n * private mo = new MutationObserver(this.onMutation);\n *\n * @bound onMutation(records: MutationRecord[]) {\n * this.count = this.children.length;\n * }\n * ```\n */\nexport function bound(_: unknown, key: string, descriptor: PropertyDescriptor): PropertyDescriptor {\n if (typeof descriptor?.value !== 'function') {\n throw new TypeError(`Only methods can be decorated with @bound. <${key ?? (_ as () => void).name}> is not a method!`);\n } /* c8 ignore next */\n return {\n configurable,\n get() {\n const value = descriptor.value.bind(this);\n Object.defineProperty(this, key, { value, configurable, writable: true });\n return value;\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAcO,WAAe,EAAY,EAAa,EAAoD,CACjG,GAAI,MAAO,IAAY,OAAU,WAC/B,KAAM,IAAI,WAAU,+CAA+C,GAAQ,EAAiB,0BAE9F,MAAO,CACL,gBACA,KAAM,CACJ,GAAM,GAAQ,EAAW,MAAM,KAAK,MACpC,cAAO,eAAe,KAAM,EAAK,CAAE,QAAO,gBAAc,SAAU,KAC3D",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{CascadeController as t}from"../controllers/cascade-controller.js";function s(...n){return function(r,i){r.constructor.addInitializer(o=>{let e=o;t.instances.has(e)||t.instances.set(e,new t(e)),t.instances.get(e)?.initProp(i,n)})}}export{s as cascades};
|
|
2
|
+
//# sourceMappingURL=cascades.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["cascades.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveElement } from 'lit';\n\nimport { CascadeController } from '../controllers/cascade-controller.js';\n\n/**\n * Cascades the decorated attribute to children\n */\nexport function cascades<T extends ReactiveElement>(...items: string[]): PropertyDecorator {\n return function(proto: T, key: string & keyof T) {\n (proto.constructor as typeof ReactiveElement).addInitializer(x => {\n const instance = x as ReactiveElement;\n // You can have multiple `@cascades` decorators on an element\n // and it will only get one CascadeController for all of them\n if (!CascadeController.instances.has(instance)) {\n CascadeController.instances.set(instance, new CascadeController(instance));\n }\n\n CascadeController.instances.get(instance)?.initProp(key, items);\n });\n } as PropertyDecorator;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,yEAKO,cAAgD,EAAoC,CACzF,MAAO,UAAS,EAAU,EAAuB,CAC/C,AAAC,EAAM,YAAuC,eAAe,GAAK,CAChE,GAAM,GAAW,EAGjB,AAAK,EAAkB,UAAU,IAAI,IACnC,EAAkB,UAAU,IAAI,EAAU,GAAI,GAAkB,IAGlE,EAAkB,UAAU,IAAI,IAAW,SAAS,EAAK",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactiveElement } from 'lit';
|
|
2
|
+
import type { Options } from '../controllers/light-dom-controller.js';
|
|
3
|
+
/**
|
|
4
|
+
* Runs the decorated method in `connectedCallback`,
|
|
5
|
+
* provided the element has light children, and sets
|
|
6
|
+
* up a mutation observer to re-run the callback,
|
|
7
|
+
* unless opted-out with `{ observe: false }`
|
|
8
|
+
* @param options Set `observe` to `false` to skip mutation observer setup, or pass a MutationObserverInit as options
|
|
9
|
+
*/
|
|
10
|
+
export declare function initializer<T extends ReactiveElement>(options?: Options): (proto: T, key: string) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["initializer.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveElement } from 'lit';\nimport type { Options } from '../controllers/light-dom-controller.js';\n\nimport { LightDOMController } from '../controllers/light-dom-controller.js';\n\n/**\n * Runs the decorated method in `connectedCallback`,\n * provided the element has light children, and sets\n * up a mutation observer to re-run the callback,\n * unless opted-out with `{ observe: false }`\n * @param options Set `observe` to `false` to skip mutation observer setup, or pass a MutationObserverInit as options\n */\nexport function initializer<T extends ReactiveElement>(options?: Options) {\n return function(proto: T, key: string) {\n // @TODO: allow multiple initializers\n (proto.constructor as typeof ReactiveElement).addInitializer(instance => {\n const initializer = proto[key as keyof T] as unknown as () => void;\n const controller = new LightDOMController(instance as ReactiveElement, initializer, options);\n if (instance.isConnected) {\n controller.hostConnected();\n }\n });\n };\n}\n"],
|
|
5
|
+
"mappings": "AAGA,4EASO,WAAgD,EAAmB,CACxE,MAAO,UAAS,EAAU,EAAa,CAErC,AAAC,EAAM,YAAuC,eAAe,GAAY,CACvE,GAAM,GAAc,EAAM,GACpB,EAAa,GAAI,GAAmB,EAA6B,EAAa,GACpF,AAAI,EAAS,aACX,EAAW",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactiveElement } from 'lit';
|
|
2
|
+
import type { ChangeCallback } from '../controllers/property-observer-controller.js';
|
|
3
|
+
declare type TypedFieldDecorator<T> = (proto: T, key: string | keyof T) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Calls a _fooChanged method on the instance when the value changes.
|
|
6
|
+
* Works on any class field. When using on lit observed properties,
|
|
7
|
+
* Make sure `@observed` is to the left (i.e. called after) the `@property`
|
|
8
|
+
* or `@state` decorator.
|
|
9
|
+
*
|
|
10
|
+
* @example observing a lit property
|
|
11
|
+
* ```ts
|
|
12
|
+
* @observed @property() foo = 'bar';
|
|
13
|
+
*
|
|
14
|
+
* protected _fooChanged(oldValue?: string, newValue?: string) {}
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example using a custom callback
|
|
18
|
+
* ```ts
|
|
19
|
+
* @observed('_myCallback') size = 'lg';
|
|
20
|
+
*
|
|
21
|
+
* _myCallback(_, size) {...}
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example using an arrow function
|
|
25
|
+
* ```ts
|
|
26
|
+
* @observed((oldVal, newVal) => console.log(`Size changed from ${oldVal} to ${newVal}`))
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function observed<T extends ReactiveElement>(methodName: string): TypedFieldDecorator<T>;
|
|
30
|
+
export declare function observed<T extends ReactiveElement>(cb: ChangeCallback<T>): TypedFieldDecorator<T>;
|
|
31
|
+
export declare function observed<T extends ReactiveElement>(proto: T, key: string): void;
|
|
32
|
+
export declare function observeProperty<T extends ReactiveElement>(proto: T, key: string | keyof T, callbackOrMethod?: ChangeCallback<T>): void;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{observedController as l,PropertyObserverController as a}from"../controllers/property-observer-controller.js";function p(...o){if(o.length===1){let[e]=o;return function(t,r){t.constructor.addInitializer(n=>new a(n)),c(t,r,e)}}else{let[e,t]=o;e.constructor.addInitializer(r=>new a(r)),c(e,t)}}function c(o,e,t){let r=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(o,e,{...r,configurable:!0,set(n){let i=this[e];if(r?.set?.call(this,n),typeof t=="function")t.call(this,i,n);else{let s=t||`_${e}Changed`;this.hasUpdated?this[s]?.(i,n):this[l].cache(e,s,i,n)}}})}export{c as observeProperty,p as observed};
|
|
2
|
+
//# sourceMappingURL=observed.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observed.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveElement } from 'lit';\nimport type {\n ChangeCallback,\n ChangeCallbackName,\n PropertyObserverHost,\n} from '../controllers/property-observer-controller.js';\n\nimport {\n observedController,\n PropertyObserverController,\n} from '../controllers/property-observer-controller.js';\n\ntype TypedFieldDecorator<T> = (proto: T, key: string | keyof T) => void ;\n\n/**\n * Calls a _fooChanged method on the instance when the value changes.\n * Works on any class field. When using on lit observed properties,\n * Make sure `@observed` is to the left (i.e. called after) the `@property`\n * or `@state` decorator.\n *\n * @example observing a lit property\n * ```ts\n * @observed @property() foo = 'bar';\n *\n * protected _fooChanged(oldValue?: string, newValue?: string) {}\n * ```\n *\n * @example using a custom callback\n * ```ts\n * @observed('_myCallback') size = 'lg';\n *\n * _myCallback(_, size) {...}\n * ```\n *\n * @example using an arrow function\n * ```ts\n * @observed((oldVal, newVal) => console.log(`Size changed from ${oldVal} to ${newVal}`))\n * ```\n */\nexport function observed<T extends ReactiveElement>(methodName: string): TypedFieldDecorator<T>\nexport function observed<T extends ReactiveElement>(cb: ChangeCallback<T>): TypedFieldDecorator<T>\nexport function observed<T extends ReactiveElement>(proto: T, key: string): void\nexport function observed<T extends ReactiveElement>(...as: any[]): void|TypedFieldDecorator<T> {\n /** @observed('_myCustomChangeCallback') */\n if (as.length === 1) {\n const [methodNameOrCallback] = as;\n return function(proto, key) {\n (proto.constructor as typeof ReactiveElement)\n .addInitializer(x => new PropertyObserverController(x));\n observeProperty(proto, key, methodNameOrCallback);\n };\n } else {\n const [proto, key] = as;\n (proto.constructor as typeof ReactiveElement)\n .addInitializer(x => new PropertyObserverController(x));\n observeProperty(proto, key);\n }\n}\n\nexport function observeProperty<T extends ReactiveElement>(\n proto: T,\n key: string | keyof T,\n callbackOrMethod?: ChangeCallback<T>\n) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, key);\n Object.defineProperty(proto, key, {\n ...descriptor,\n configurable: true,\n set(this: PropertyObserverHost<T>, newVal: T[keyof T]) {\n const oldVal = this[key as keyof T];\n // first, call any pre-existing setters, e.g. `@property`\n descriptor?.set?.call(this, newVal);\n\n // if the user passed a callback, call it\n // e.g. `@observed((_, newVal) => console.log(newVal))`\n // safe to call before connectedCallback, because it's impossible to get a `this` ref.\n if (typeof callbackOrMethod === 'function') {\n callbackOrMethod.call(this, oldVal, newVal);\n } else {\n // if the user passed a string method name, call it on `this`\n // e.g. `@observed('_renderOptions')`\n // otherwise, use a default method name e.g. `_fooChanged`\n const actualMethodName = callbackOrMethod || `_${key}Changed`;\n\n // if the component has already connected to the DOM, run the callback\n // otherwise, If the component has not yet connected to the DOM,\n // cache the old and new values. See PropertyObserverController above\n if (this.hasUpdated) {\n this[actualMethodName as ChangeCallbackName]?.(oldVal, newVal);\n } else {\n this[observedController].cache(key as string, actualMethodName, oldVal, newVal);\n }\n }\n },\n });\n}\n"],
|
|
5
|
+
"mappings": "AAOA,oHAmCO,cAAgD,EAAwC,CAE7F,GAAI,EAAG,SAAW,EAAG,CACnB,GAAM,CAAC,GAAwB,EAC/B,MAAO,UAAS,EAAO,EAAK,CAC1B,AAAC,EAAM,YACJ,eAAe,GAAK,GAAI,GAA2B,IACtD,EAAgB,EAAO,EAAK,QAEzB,CACL,GAAM,CAAC,EAAO,GAAO,EACrB,AAAC,EAAM,YACJ,eAAe,GAAK,GAAI,GAA2B,IACtD,EAAgB,EAAO,IAIpB,WACL,EACA,EACA,EACA,CACA,GAAM,GAAa,OAAO,yBAAyB,EAAO,GAC1D,OAAO,eAAe,EAAO,EAAK,IAC7B,EACH,aAAc,GACd,IAAmC,EAAoB,CACrD,GAAM,GAAS,KAAK,GAOpB,GALA,GAAY,KAAK,KAAK,KAAM,GAKxB,MAAO,IAAqB,WAC9B,EAAiB,KAAK,KAAM,EAAQ,OAC/B,CAIL,GAAM,GAAmB,GAAoB,IAAI,WAKjD,AAAI,KAAK,WACP,KAAK,KAA0C,EAAQ,GAEvD,KAAK,GAAoB,MAAM,EAAe,EAAkB,EAAQ",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds pfelement APIs to the decorated custom-element class
|
|
3
|
+
* 1. Adds readonly `version` field to the element constructor (class)
|
|
4
|
+
* 2. Adds `[pfelement]` attr and `.PFElement` class in connectedCallback
|
|
5
|
+
*/
|
|
6
|
+
export declare function pfelement(): ClassDecorator;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{trackPerformance as i}from"../core.js";import{ColorContextController as l}from"../controllers/color-context-controller.js";import{PerfController as a}from"../controllers/perf-controller.js";function m(t){return typeof t.addInitializer=="function"}var r=!1,o=new Set;async function f(t){if(o.add(t),!r){for(r=!0;o.size;){let e=[];for(let n of o)e.push(n.updateComplete),o.delete(n);await Promise.all(e)}document.body.removeAttribute("unresolved")}}function d(){return function(t){if(!m(t))throw new Error(`@pfelement may only decorate ReactiveElements. ${t.name} is does not implement ReactiveElement.`);t.addInitializer(e=>{window.PfeConfig.autoReveal&&f(e),e.addController({hostConnected(){e.setAttribute("pfelement",""),e.classList.add("PFElement")}}),new l(e),i()&&new a(e)})}}export{d as pfelement};
|
|
2
|
+
//# sourceMappingURL=pfelement.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["pfelement.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveElement } from 'lit';\n\nimport { trackPerformance } from '../core.js';\n\nimport { ColorContextController } from '../controllers/color-context-controller.js';\nimport { PerfController } from '../controllers/perf-controller.js';\n\nfunction isReactiveElementClass(\n klass: Function // eslint-disable-line @typescript-eslint/ban-types\n): klass is typeof ReactiveElement {\n return typeof klass['addInitializer' as keyof typeof klass] === 'function';\n}\n\nlet waiting = false;\nconst queue = new Set<ReactiveElement>();\n\nasync function enqueue(instance: ReactiveElement) {\n queue.add(instance);\n\n // only the first call kicks off the 'timer'\n // but because of the while loop, subsequent calls will still cause an `await`\n if (!waiting) {\n waiting = true;\n while (queue.size) {\n const enqueued: Promise<boolean>[] = [];\n for (const instance of queue) {\n enqueued.push(instance.updateComplete);\n queue.delete(instance);\n }\n await Promise.all(enqueued);\n }\n document.body.removeAttribute('unresolved');\n }\n}\n\n/**\n * Adds pfelement APIs to the decorated custom-element class\n * 1. Adds readonly `version` field to the element constructor (class)\n * 2. Adds `[pfelement]` attr and `.PFElement` class in connectedCallback\n */\nexport function pfelement(): ClassDecorator {\n return function(klass) {\n if (!isReactiveElementClass(klass)) {\n throw new Error(`@pfelement may only decorate ReactiveElements. ${klass.name} is does not implement ReactiveElement.`);\n }\n\n klass.addInitializer(instance => {\n if (window.PfeConfig.autoReveal) {\n enqueue(instance);\n }\n\n // Set some global host DOM when it connects\n // by way of an ad-hoc controller\n instance.addController({\n hostConnected() {\n instance.setAttribute('pfelement', '');\n instance.classList.add('PFElement');\n },\n });\n\n // look mah, no instance property\n new ColorContextController(instance);\n\n if (trackPerformance()) {\n new PerfController(instance);\n }\n });\n };\n}\n"],
|
|
5
|
+
"mappings": "AAEA,8CAEA,oFACA,mEAEA,WACE,EACiC,CACjC,MAAO,OAAO,GAAM,gBAA4C,WAGlE,GAAI,GAAU,GACR,EAAQ,GAAI,KAElB,iBAAuB,EAA2B,CAKhD,GAJA,EAAM,IAAI,GAIN,CAAC,EAAS,CAEZ,IADA,EAAU,GACH,EAAM,MAAM,CACjB,GAAM,GAA+B,GACrC,OAAW,KAAY,GACrB,EAAS,KAAK,EAAS,gBACvB,EAAM,OAAO,GAEf,KAAM,SAAQ,IAAI,GAEpB,SAAS,KAAK,gBAAgB,eAS3B,YAAqC,CAC1C,MAAO,UAAS,EAAO,CACrB,GAAI,CAAC,EAAuB,GAC1B,KAAM,IAAI,OAAM,kDAAkD,EAAM,+CAG1E,EAAM,eAAe,GAAY,CAC/B,AAAI,OAAO,UAAU,YACnB,EAAQ,GAKV,EAAS,cAAc,CACrB,eAAgB,CACd,EAAS,aAAa,YAAa,IACnC,EAAS,UAAU,IAAI,gBAK3B,GAAI,GAAuB,GAEvB,KACF,GAAI,GAAe",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function u(f){return function(m,i,e){let{value:o}=e??{};if(typeof o!="function")throw new Error("@time() may only decorate class methods");e.value=function(...s){let n=f??`${this.constructor.name}-${i}`,t=`start-${n}`,c=`end-${n}`;window.PfeConfig.trackPerformance&&performance.mark(t);let r=o.call(this,...s),a=()=>(window.PfeConfig.trackPerformance&&(performance.mark(c),performance.measure(n,t,c),console.log(Array.from(performance.getEntriesByName(n)).pop())),r);return r instanceof Promise?r.then(a):a()}}}export{u as time};
|
|
2
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["time.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Tracks the time a method takes to complete using the [performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)\n */\nexport function time(tag?: string) {\n return function(_: unknown, key: string, descriptor: PropertyDescriptor) {\n const { value: f } = descriptor ?? {};\n\n if (!(typeof f === 'function')) {\n throw new Error('@time() may only decorate class methods');\n }\n\n descriptor.value = function(...args: any[]) {\n const TAG = tag ?? `${this.constructor.name}-${key}`;\n const START_TAG = `start-${TAG}`;\n const END_TAG = `end-${TAG}`;\n\n if (window.PfeConfig.trackPerformance) {\n performance.mark(START_TAG);\n }\n\n const x = f.call(this, ...args);\n\n const ret = () => {\n if (window.PfeConfig.trackPerformance) {\n performance.mark(END_TAG);\n performance.measure(TAG, START_TAG, END_TAG);\n // eslint-disable-next-line no-console\n console.log(Array.from(performance.getEntriesByName(TAG)).pop());\n }\n return x;\n };\n\n if (x instanceof Promise) {\n return x.then(ret);\n } else {\n return ret();\n }\n };\n };\n}\n"],
|
|
5
|
+
"mappings": "AAGO,WAAc,EAAc,CACjC,MAAO,UAAS,EAAY,EAAa,EAAgC,CACvE,GAAM,CAAE,MAAO,GAAM,GAAc,GAEnC,GAAM,MAAO,IAAM,WACjB,KAAM,IAAI,OAAM,2CAGlB,EAAW,MAAQ,YAAY,EAAa,CAC1C,GAAM,GAAM,GAAO,GAAG,KAAK,YAAY,QAAQ,IACzC,EAAY,SAAS,IACrB,EAAU,OAAO,IAEvB,AAAI,OAAO,UAAU,kBACnB,YAAY,KAAK,GAGnB,GAAM,GAAI,EAAE,KAAK,KAAM,GAAG,GAEpB,EAAM,IACN,QAAO,UAAU,kBACnB,aAAY,KAAK,GACjB,YAAY,QAAQ,EAAK,EAAW,GAEpC,QAAQ,IAAI,MAAM,KAAK,YAAY,iBAAiB,IAAM,QAErD,GAGT,MAAI,aAAa,SACR,EAAE,KAAK,GAEP",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["trace.ts"],
|
|
4
|
+
"sourcesContent": ["/** Logs the result of a class method */\nexport function trace(tag?: string) {\n return function(_: unknown, key: string, descriptor: PropertyDescriptor) {\n const { value: f } = descriptor;\n descriptor.value = function(...args: any[]) {\n const x = f.call(this, ...args);\n\n const ret = () => {\n // eslint-disable-next-line no-console\n console.log(tag ?? key, x);\n return x;\n };\n\n if (x instanceof Promise) {\n return x.then(ret);\n } else {\n return ret();\n }\n };\n };\n}\n"],
|
|
5
|
+
"mappings": "AACO,WAAe,EAAc,CAClC,MAAO,UAAS,EAAY,EAAa,EAAgC,CACvE,GAAM,CAAE,MAAO,GAAM,EACrB,EAAW,MAAQ,YAAY,EAAa,CAC1C,GAAM,GAAI,EAAE,KAAK,KAAM,GAAG,GAEpB,EAAM,IAEV,SAAQ,IAAI,GAAO,EAAK,GACjB,GAGT,MAAI,aAAa,SACR,EAAE,KAAK,GAEP",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/decorators.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './decorators/bound.js';
|
|
2
|
+
export * from './decorators/cascades.js';
|
|
3
|
+
export * from './decorators/initializer.js';
|
|
4
|
+
export * from './decorators/observed.js';
|
|
5
|
+
export * from './decorators/pfelement.js';
|
|
6
|
+
export * from './decorators/time.js';
|
|
7
|
+
export * from './decorators/trace.js';
|
package/decorators.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export*from"./decorators/bound.js";export*from"./decorators/cascades.js";export*from"./decorators/initializer.js";export*from"./decorators/observed.js";export*from"./decorators/pfelement.js";export*from"./decorators/time.js";export*from"./decorators/trace.js";
|
|
2
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["decorators.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './decorators/bound.js';\nexport * from './decorators/cascades.js';\nexport * from './decorators/initializer.js';\nexport * from './decorators/observed.js';\nexport * from './decorators/pfelement.js';\nexport * from './decorators/time.js';\nexport * from './decorators/trace.js';\n"],
|
|
5
|
+
"mappings": "AAAA,mCACA,sCACA,yCACA,sCACA,uCACA,kCACA",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounce helper function
|
|
3
|
+
* @see https://davidwalsh.name/javascript-debounce-function
|
|
4
|
+
*
|
|
5
|
+
* @param func Function to be debounced
|
|
6
|
+
* @param delay How long until it will be run
|
|
7
|
+
* @param immediate Whether it should be run at the start instead of the end of the debounce
|
|
8
|
+
*/
|
|
9
|
+
export declare function debounce(func: (...args: any[]) => unknown, delay: number, immediate?: boolean): (this: unknown, ...args: any[]) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["debounce.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Debounce helper function\n * @see https://davidwalsh.name/javascript-debounce-function\n *\n * @param func Function to be debounced\n * @param delay How long until it will be run\n * @param immediate Whether it should be run at the start instead of the end of the debounce\n */\nexport function debounce(\n func: (...args: any[]) => unknown,\n delay: number,\n immediate = false\n) {\n let timeout: number|null;\n return function(this: unknown, ...args: any[]) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const context = this;\n const later = function() {\n timeout = null;\n if (!immediate) {\n func.apply(context, args);\n }\n };\n const callNow = immediate && !timeout;\n clearTimeout(timeout as number);\n timeout = window.setTimeout(later, delay);\n if (callNow) {\n func.apply(context, args);\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "AAQO,WACL,EACA,EACA,EAAY,GACZ,CACA,GAAI,GACJ,MAAO,aAA2B,EAAa,CAE7C,GAAM,GAAU,KACV,EAAQ,UAAW,CACvB,EAAU,KACL,GACH,EAAK,MAAM,EAAS,IAGlB,EAAU,GAAa,CAAC,EAC9B,aAAa,GACb,EAAU,OAAO,WAAW,EAAO,GAC/B,GACF,EAAK,MAAM,EAAS",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["deprecatedCustomEvent.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Construct a CustomEvent with the given name and detail.\n * The event bubbles and is composed.\n */\nexport function deprecatedCustomEvent<T>(name: string, detail?: T): CustomEvent<T> {\n return new CustomEvent(name, {\n bubbles: true,\n composed: true,\n detail,\n });\n}\n"],
|
|
5
|
+
"mappings": "AAIO,WAAkC,EAAc,EAA4B,CACjF,MAAO,IAAI,aAAY,EAAM,CAC3B,QAAS,GACT,SAAU,GACV",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["random.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A quick way to fetch a random ID value.\n * _Note:_ All values are prefixed automatically to ensure an ID-safe value is returned.\n * @param prefix id-safe string prefix\n */\nexport function getRandomId(prefix = 'pfe') {\n return `${prefix}-${Math.random().toString(36).substr(2, 9)}`;\n}\n"],
|
|
5
|
+
"mappings": "AAKO,WAAqB,EAAS,MAAO,CAC1C,MAAO,GAAG,KAAU,KAAK,SAAS,SAAS,IAAI,OAAO,EAAG",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@patternfly/pfe-core",
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "PatternFly Elements Core Library",
|
|
6
|
+
"customElements": "custom-elements.json",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./core.js",
|
|
9
|
+
"module": "./core.js",
|
|
10
|
+
"types": "./core.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"esbuild": "./core.ts",
|
|
14
|
+
"default": "./core.js"
|
|
15
|
+
},
|
|
16
|
+
"./*": {
|
|
17
|
+
"esbuild": "./*.ts",
|
|
18
|
+
"default": "./*.js"
|
|
19
|
+
},
|
|
20
|
+
"./controllers/*": {
|
|
21
|
+
"esbuild": "./controllers/*.ts",
|
|
22
|
+
"default": "./controllers/*.js"
|
|
23
|
+
},
|
|
24
|
+
"./decorators/*": {
|
|
25
|
+
"esbuild": "./decorators/*.ts",
|
|
26
|
+
"default": "./decorators/*.js"
|
|
27
|
+
},
|
|
28
|
+
"./directives/*": {
|
|
29
|
+
"esbuild": "./directives/*.ts",
|
|
30
|
+
"default": "./directives/*.js"
|
|
31
|
+
},
|
|
32
|
+
"./functions/*": {
|
|
33
|
+
"esbuild": "./functions/*.ts",
|
|
34
|
+
"default": "./functions/*.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"⚙️-----UTIL-------⚙️": "❓ Manages the repo",
|
|
43
|
+
"clean": "git clean -fX -e node_modules -e tsconfig.tsbuildinfo",
|
|
44
|
+
"🚚-----DIST-------🚚": "❓ Publish packages",
|
|
45
|
+
"prepublishOnly": "npm run build",
|
|
46
|
+
"👷♀️-----BUILD------👷♀️": "❓ Prepare dist artifacts",
|
|
47
|
+
"analyze": "cem analyze",
|
|
48
|
+
"build": "run-s build:*",
|
|
49
|
+
"build:clean": "npm run clean",
|
|
50
|
+
"build:esbuild": "node ../../scripts/build.js --include pfe-core --workspace core",
|
|
51
|
+
"build:analyze": "npm run analyze",
|
|
52
|
+
"build:types": "tsc -b .",
|
|
53
|
+
"🧑🔬-----TEST-------🧑🔬": "❓ Test packages",
|
|
54
|
+
"test": "wtr --files './test/*.spec.ts' --config ../../web-test-runner.config.js",
|
|
55
|
+
"👷♀️-----DEV--------👷♀️": "❓ Development aids",
|
|
56
|
+
"test:watch": "npm test -- --watch",
|
|
57
|
+
"watch:analyze": "npm run analyze -- --watch",
|
|
58
|
+
"watch:types": "tsc -w"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"lit": "^2.1.2"
|
|
62
|
+
},
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "github:patternfly/patternfly-elements",
|
|
66
|
+
"directory": "core/pfe-core"
|
|
67
|
+
},
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/patternfly/patternfly-elements/issues"
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"**/*.LEGAL.txt",
|
|
73
|
+
"**/*.scss",
|
|
74
|
+
"**/*.css",
|
|
75
|
+
"!*.ts",
|
|
76
|
+
"**/*.d.ts",
|
|
77
|
+
"**/*.js",
|
|
78
|
+
"**/*.js.map",
|
|
79
|
+
"!custom-elements-manifest.config.js",
|
|
80
|
+
"custom-elements.json",
|
|
81
|
+
"!demo/*",
|
|
82
|
+
"!docs/*",
|
|
83
|
+
"!test/*"
|
|
84
|
+
],
|
|
85
|
+
"keywords": [
|
|
86
|
+
"patternfly",
|
|
87
|
+
"custom elements",
|
|
88
|
+
"web components"
|
|
89
|
+
]
|
|
90
|
+
}
|