@sebgroup/green-core 1.0.0-beta.10

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.
Files changed (35) hide show
  1. package/README.md +151 -0
  2. package/components/dropdown/dropdown.d.ts +72 -0
  3. package/components/dropdown/dropdown.styles.d.ts +2 -0
  4. package/components/dropdown/dropdown.trans.styles.d.ts +2 -0
  5. package/components/form-control.d.ts +36 -0
  6. package/components/index.d.ts +2 -0
  7. package/generated/locale-codes.d.ts +13 -0
  8. package/generated/locales/sv.d.ts +5 -0
  9. package/index.d.ts +2 -0
  10. package/index.js +1065 -0
  11. package/localization.d.ts +1 -0
  12. package/localization.js +44 -0
  13. package/package.json +43 -0
  14. package/primitives/listbox/index.d.ts +2 -0
  15. package/primitives/listbox/listbox.d.ts +53 -0
  16. package/primitives/listbox/listbox.styles.d.ts +2 -0
  17. package/primitives/listbox/listbox.trans.styles.d.ts +2 -0
  18. package/primitives/listbox/option.d.ts +59 -0
  19. package/primitives/listbox/option.styles.d.ts +2 -0
  20. package/primitives/popover/index.d.ts +1 -0
  21. package/primitives/popover/popover.d.ts +31 -0
  22. package/primitives/popover/popover.styles.d.ts +2 -0
  23. package/primitives/popover/popover.trans.styles.d.ts +2 -0
  24. package/transitional-styles.d.ts +1 -0
  25. package/transitional-styles.js +5711 -0
  26. package/utils/decorators/index.d.ts +2 -0
  27. package/utils/decorators/observe-light-dom.d.ts +7 -0
  28. package/utils/decorators/watch.d.ts +23 -0
  29. package/utils/helpers/constrain-slots.d.ts +17 -0
  30. package/utils/helpers/custom-element-scoping.d.ts +97 -0
  31. package/utils/helpers/id.d.ts +4 -0
  32. package/utils/helpers/index.d.ts +2 -0
  33. package/utils/helpers/transitional-styles.d.ts +12 -0
  34. package/utils/localization.d.ts +5 -0
  35. package/utils/testing/index.d.ts +30 -0
@@ -0,0 +1,2 @@
1
+ export * from './watch';
2
+ export * from './observe-light-dom';
@@ -0,0 +1,7 @@
1
+ import type { LitElement } from 'lit';
2
+ declare type Handler = () => void;
3
+ /**
4
+ * Runs when the light DOM children of the component changes.
5
+ */
6
+ export declare function observeLightDOM(): <ElemClass extends LitElement>(proto: ElemClass, _propertyKey: string, descriptor: TypedPropertyDescriptor<Handler>) => void;
7
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { LitElement } from 'lit';
2
+ declare type UpdateHandler = (prev?: unknown, next?: unknown) => void;
3
+ interface WatchOptions {
4
+ /**
5
+ * If true, will only start watching after the initial update/render
6
+ */
7
+ waitUntilFirstUpdate?: boolean;
8
+ }
9
+ /**
10
+ * Runs when observed properties change, e.g. @property or @state, but before the component updates. To wait for an
11
+ * update to complete after a change occurs, use `await this.updateComplete` in the handler. To start watching after the
12
+ * initial update/render, use `{ waitUntilFirstUpdate: true }` or `this.hasUpdated` in the handler.
13
+ *
14
+ * Usage:
15
+ * ```javascript
16
+ * \@watch('propName')
17
+ * handlePropChange(oldValue, newValue) {
18
+ * ...
19
+ * }
20
+ * ```
21
+ */
22
+ export declare function watch(propertyName: string | string[], options?: WatchOptions): <ElemClass extends LitElement>(proto: ElemClass, propertyKey: string, descriptor: TypedPropertyDescriptor<UpdateHandler>) => void;
23
+ export {};
@@ -0,0 +1,17 @@
1
+ import { LitElement } from 'lit';
2
+ /**
3
+ * This function is used to constrain the slots of a component to only allow
4
+ * certain types of slotted elements. Add the `gds-allow` attribute to the slot
5
+ * element and specify the allowed elements as a space-separated list. Slots
6
+ * without the `gds-allow` attribute will not be constrained.
7
+ *
8
+ * Example:
9
+ * ```html
10
+ * <slot gds-allow="span p"></slot>
11
+ * ```
12
+ * This will only allow `span` and `p` elements to be slotted into this slot. Any other
13
+ * elements will be removed from the shadow DOM.
14
+ *
15
+ * @param self The element to apply the slot constraints to
16
+ */
17
+ export declare function constrainSlots(self: LitElement): void;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * # Custom element scoping
3
+ *
4
+ * One problem with the current state of the Custom Elements standard is that there is
5
+ * only a single, global, `CustomElementRegistry`. This means that if you have two different
6
+ * libraries, or two different versions of the same library, that both define a custom
7
+ * element with the same name, only one of them will be registered, and the other will
8
+ * throw an error.
9
+ *
10
+ * This is a problem for Green, because we need it to work well in a microfrontend
11
+ * architecture, where multiple apps can be loaded on the same page, and each app can
12
+ * potentially have its own version of Green.
13
+ *
14
+ * There is a (proposal)[https://github.com/WICG/webcomponents/blob/gh-pages/proposals/Scoped-Custom-Element-Registries.md]
15
+ * for enabling user instantiated CustomElementRegistry scoped to a ShodowRoot, but as of
16
+ * mid 2023 this is still only available in Chrome canary behind experimental flags.
17
+ *
18
+ * ## Solution
19
+ *
20
+ * To get around the problem we define our own scoping mechanism. It will works like this:
21
+ *
22
+ * * Green Core has its own lookup table of custom elements, and a suffix is added to the
23
+ * name of each custom element. For example, `gds-popover` becomes `gds-popover-<versionstring>`.
24
+ * The version string is deterministically generated based on the version of the Green
25
+ * Core package.
26
+ *
27
+ * * We also define a new `customElement` decorator that will be used to register custom
28
+ * elements. `@gdsCustomElement` will automatically add the version suffix to the name of
29
+ * the custom element, and register it in the lookup table. If the custom element is already
30
+ * registered, it will abort silently, with the assumption that the custom element was
31
+ * already registered by the same version of Green Core and is therefor compatible.
32
+ *
33
+ * * There is also a custom `html` template tag that will automatically rewrite all custom
34
+ * element names from the lookup table to include the version suffix, before passing the
35
+ * template on to the Lit `html` tag. Alternatively, a templte tag factory can be used
36
+ * to create a custom `html` tag, if Lit is not used by the consumer
37
+ *
38
+ * ## Caveats
39
+ *
40
+ * Consumers using top-level components from Green Core will have to add the version suffix
41
+ * in some way. The React and Angular wrappers takes care of this automatically. Another way
42
+ * is to use the `html` template tag or template tag factory from Green Core, but it will only
43
+ * work if the consumer is using javascript template literals.
44
+ *
45
+ * If the consumer is using hard coded HTML, or a templating language that does not support
46
+ * template tags, the consumer will have to manually add the version suffix to the custom
47
+ * element names, which would be cumbersome. In this edge-case, the scoping feature can be disabled,
48
+ * and the consumer will have to make sure that only a single version of Green Core is used
49
+ * on the page.
50
+ *
51
+ * The recommendation is to only consume Green Core though the React or Angular wrappers, or to
52
+ * use the `html` template tag or template tag factory from Green Core.
53
+ *
54
+ * At some point in the future, when the scoped custom element registry proposal has been
55
+ * implemented in all major browsers, we might remove this custom scoping mechanism and
56
+ * switch to using native scoped registries instead.
57
+ */
58
+ /**
59
+ * Class decorator factory that defines the decorated class as a custom element, and registers
60
+ * it with the custom element registry under a versioned name.
61
+ *
62
+ * ```js
63
+ * @gdsCustomElement('my-element')
64
+ * class MyElement extends LitElement {
65
+ * render() {
66
+ * return html``;
67
+ * }
68
+ * }
69
+ * ```
70
+ * @category Decorator
71
+ * @param tagName The tag name of the custom element to define.
72
+ */
73
+ export declare const gdsCustomElement: (tagName: string) => (classOrDescriptor: {
74
+ prototype: HTMLElement;
75
+ } | import("@lit/reactive-element/decorators/base").ClassDescriptor) => any;
76
+ /**
77
+ * Template tag factory that creates a new template tag, which rewrites all custom element names from the
78
+ * lookup table to include the version suffix, and then passes the template on to the provided template tag.
79
+ */
80
+ export declare function htmlTemplateTagFactory(extendedTag: (strings: TemplateStringsArray, ...values: any[]) => any): (strings: TemplateStringsArray, ...values: any[]) => any;
81
+ /**
82
+ * Template tag that rewrites all custom element names from the lookup table to include the
83
+ * version suffix, before passing the template on to the Lit `html` tag.
84
+ */
85
+ export declare const html: (strings: TemplateStringsArray, ...values: any[]) => any;
86
+ /**
87
+ * Returns the correctly scoped tag name for the given tag.
88
+ * @param tagName The tag name to scope
89
+ */
90
+ export declare function getScopedTagName(tagName: string): string;
91
+ /**
92
+ * Returns the unscoped tag name for the given scoped tag.
93
+ * @param tagName The scoped tag name to unscope
94
+ */
95
+ export declare function getUnscopedTagName(tagName: string): string | undefined;
96
+ declare const _default: {};
97
+ export default _default;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Generate a random id with `gds-` prefix
3
+ */
4
+ export declare const randomId: () => string;
@@ -0,0 +1,2 @@
1
+ export * from './constrain-slots';
2
+ export * from './id';
@@ -0,0 +1,12 @@
1
+ export declare const registerTransitionalStyles: () => void;
2
+ declare global {
3
+ var __gdsTransitionalStyles: TransitionalStyles;
4
+ }
5
+ export declare class TransitionalStyles {
6
+ static get instance(): TransitionalStyles;
7
+ private sheets;
8
+ private elements;
9
+ apply(element: HTMLElement, styleKey: string): void;
10
+ applyToElement(styleKey: string, sheet: CSSStyleSheet): void;
11
+ register(name: string, styles: string): void;
12
+ }
@@ -0,0 +1,5 @@
1
+ export declare const getLocale: (() => string) & {
2
+ _LIT_LOCALIZE_GET_LOCALE_?: undefined;
3
+ }, setLocale: ((newLocale: string) => Promise<void>) & {
4
+ _LIT_LOCALIZE_SET_LOCALE_?: undefined;
5
+ };
@@ -0,0 +1,30 @@
1
+ /** A testing utility that measures an element's position and clicks on it. */
2
+ export declare function clickOnElement(
3
+ /** The element to click */
4
+ el: Element,
5
+ /** The location of the element to click */
6
+ position?: 'top' | 'right' | 'bottom' | 'left' | 'center',
7
+ /** The horizontal offset to apply to the position when clicking */
8
+ offsetX?: number,
9
+ /** The vertical offset to apply to the position when clicking */
10
+ offsetY?: number): Promise<void>;
11
+ /** A testing utility that moves the mouse onto an element. */
12
+ export declare function moveMouseOnElement(
13
+ /** The element to click */
14
+ el: Element,
15
+ /** The location of the element to click */
16
+ position?: 'top' | 'right' | 'bottom' | 'left' | 'center',
17
+ /** The horizontal offset to apply to the position when clicking */
18
+ offsetX?: number,
19
+ /** The vertical offset to apply to the position when clicking */
20
+ offsetY?: number): Promise<void>;
21
+ /** A testing utility that drags an element with the mouse. */
22
+ export declare function dragElement(
23
+ /** The element to drag */
24
+ el: Element,
25
+ /** The horizontal distance to drag in pixels */
26
+ deltaX?: number,
27
+ /** The vertical distance to drag in pixels */
28
+ deltaY?: number): Promise<void>;
29
+ /** A testing utility that waits for a specified amount of time. */
30
+ export declare function timeout(ms: number): Promise<unknown>;