web-component-wrapper 0.0.336 → 0.0.340

Sign up to get free protection for your applications and to get access to all the features.
package/React.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Mapping } from 'clientnode/type';
2
- import React from 'react';
2
+ import React, { HTMLAttributes } from 'react';
3
3
  import Web from './Web';
4
- import { ComponentType, ReactRenderItemFactory, ReactRenderItemsFactory, ReactRenderItems, WebComponentAPI } from './type';
4
+ import { ComponentAdapter, ComponentType, ReactRenderItemFactory, ReactRenderItemsFactory, ReactRenderItems, WebComponentAPI } from './type';
5
5
  /**
6
6
  * Adapter for exposing a react component as web-component.
7
7
  * @property static:attachWebComponentAdapterIfNotExists - Indicates whether to
@@ -18,14 +18,21 @@ import { ComponentType, ReactRenderItemFactory, ReactRenderItemsFactory, ReactRe
18
18
  * reacts memorizing wrapper to cache component render results.
19
19
  * @property isWrapped - Indicates whether react component is wrapped already.
20
20
  */
21
- export declare class ReactWeb<TElement = HTMLElement> extends Web<TElement> {
21
+ export declare class ReactWeb<TElement = HTMLElement, ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> & {
22
+ children?: Array<React.ReactNode> | React.ReactNode;
23
+ dangerouslySetInnerHTML?: HTMLAttributes<TElement>['dangerouslySetInnerHTML'];
24
+ key?: string;
25
+ ref?: null | {
26
+ current?: ComponentAdapter;
27
+ };
28
+ } = Mapping<unknown>> extends Web<TElement, ExternalProperties, InternalProperties> {
22
29
  static attachWebComponentAdapterIfNotExists: boolean;
23
30
  static content: ComponentType | string;
24
31
  static react: typeof React;
25
32
  static _name: string;
26
- compiledSlots: Mapping<ReactRenderItemsFactory> & {
33
+ compiledSlots: (Mapping<ReactRenderItemsFactory> & {
27
34
  children?: ReactRenderItemsFactory;
28
- };
35
+ });
29
36
  preparedSlots: Mapping<ReactRenderItems> & {
30
37
  children?: ReactRenderItems;
31
38
  };
@@ -51,7 +58,7 @@ export declare class ReactWeb<TElement = HTMLElement> extends Web<TElement> {
51
58
  *
52
59
  * @returns Nothing.
53
60
  */
54
- reflectExternalProperties(properties: Mapping<unknown>): void;
61
+ reflectExternalProperties(properties: Partial<ExternalProperties>): void;
55
62
  /**
56
63
  * Method which does the rendering job. Should be called when ever state
57
64
  * changes should be projected to the hosts dom content.
@@ -167,7 +174,7 @@ export declare class ReactWeb<TElement = HTMLElement> extends Web<TElement> {
167
174
  *
168
175
  * @returns Nothing.
169
176
  */
170
- prepareProperties(properties: Mapping<unknown>): void;
177
+ prepareProperties(properties: InternalProperties): void;
171
178
  /**
172
179
  * Updates current component instance and reflects newly determined
173
180
  * properties.
package/Web.d.ts CHANGED
@@ -96,7 +96,7 @@ import { AttributesReflectionConfiguration, CompiledDomNodeTemplate, ComponentAd
96
96
  *
97
97
  * @property slots - Grabbed slots which where present in the connecting phase.
98
98
  */
99
- export declare class Web<TElement = HTMLElement> extends HTMLElement {
99
+ export declare class Web<TElement = HTMLElement, ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>> extends HTMLElement {
100
100
  static applyRootBinding: boolean;
101
101
  static content: unknown;
102
102
  static determineRootBinding: boolean;
@@ -130,15 +130,15 @@ export declare class Web<TElement = HTMLElement> extends HTMLElement {
130
130
  scope: Mapping<unknown>;
131
131
  domNodeEventBindings: Map<Node, EventCallbackMapping>;
132
132
  domNodeTemplateCache: CompiledDomNodeTemplate;
133
- externalProperties: Mapping<unknown>;
133
+ externalProperties: ExternalProperties;
134
134
  ignoreAttributeUpdateObservations: boolean;
135
- internalProperties: Mapping<unknown>;
135
+ internalProperties: InternalProperties;
136
136
  outputEventNames: Set<string>;
137
137
  instance: null | {
138
138
  current?: ComponentAdapter;
139
139
  };
140
140
  isRoot: boolean;
141
- root: ShadowRoot | Web<TElement>;
141
+ root: ShadowRoot | Web<TElement, ExternalProperties, InternalProperties>;
142
142
  runDomConnectionAndRenderingInSameEventQueue: boolean;
143
143
  readonly self: typeof Web;
144
144
  slots: Mapping<HTMLElement> & {
@@ -417,7 +417,7 @@ export declare class Web<TElement = HTMLElement> extends HTMLElement {
417
417
  *
418
418
  * @returns Nothing.
419
419
  */
420
- reflectExternalProperties(properties: Mapping<unknown>): void;
420
+ reflectExternalProperties(properties: Partial<ExternalProperties>): void;
421
421
  /**
422
422
  * Reflects wrapped component state back to web-component's attributes and
423
423
  * properties.
@@ -425,7 +425,7 @@ export declare class Web<TElement = HTMLElement> extends HTMLElement {
425
425
  *
426
426
  * @returns Nothing.
427
427
  */
428
- reflectProperties(properties: Mapping<unknown>): void;
428
+ reflectProperties(properties: Partial<ExternalProperties>): void;
429
429
  /**
430
430
  * Triggers a new rendering cycle by respecting batch configuration.
431
431
  * @param reason - A description why rendering should be triggered.
@@ -441,7 +441,7 @@ export declare class Web<TElement = HTMLElement> extends HTMLElement {
441
441
  *
442
442
  * @returns Mapped properties or null if nothing could be mapped.
443
443
  */
444
- reflectEventToProperties(name: string, parameters: Array<unknown>): Mapping<unknown> | null;
444
+ reflectEventToProperties(name: string, parameters: Array<unknown>): Partial<ExternalProperties> | null;
445
445
  /**
446
446
  * Evaluates given property value depending on its type specification and
447
447
  * registers in properties mapping object.
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Mapping } from 'clientnode/type';
1
2
  import ReactWebImport from './React';
2
3
  import WebImport from './Web';
3
4
  import { ComponentType, WebComponentAPI, WebComponentConfiguration } from './type';
@@ -14,5 +15,5 @@ export declare const Web: typeof WebImport;
14
15
  *
15
16
  * @returns Generated object to register and retrieve generated web component.
16
17
  */
17
- export declare const wrapAsWebComponent: <Type extends ComponentType = ComponentType>(component: Type, nameHint?: string, configuration?: WebComponentConfiguration) => WebComponentAPI;
18
+ export declare const wrapAsWebComponent: <Type extends ComponentType = ComponentType, ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>, EventParameters extends unknown[] = unknown[]>(component: Type, nameHint?: string, configuration?: WebComponentConfiguration<ExternalProperties, InternalProperties, EventParameters>) => WebComponentAPI;
18
19
  export default wrapAsWebComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-wrapper",
3
- "version": "0.0.336",
3
+ "version": "0.0.340",
4
4
  "description": "Generic web-component base class and framework specific wrapper.",
5
5
  "keywords": [
6
6
  "component",
package/type.d.ts CHANGED
@@ -11,9 +11,12 @@ export declare type CompiledDomNodeTemplateItem = {
11
11
  };
12
12
  export declare type CompiledDomNodeTemplate<NodeType = Node> = Map<NodeType, CompiledDomNodeTemplateItem>;
13
13
  export declare type EventCallbackMapping = Map<string, () => void>;
14
- export declare type EventMapping<ExternalPropertiesType = Mapping<unknown>, InternalPropertiesType = Mapping<unknown>> = [ExternalPropertiesType, InternalPropertiesType] | ExternalPropertiesType;
15
- export declare type EventMapper = (..._parameter: Array<unknown>) => EventMapping;
16
- export declare type EventToPropertyMapping = Mapping<true | EventMapper>;
14
+ export declare type EventMapping<ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>> = ([
15
+ Partial<ExternalProperties>,
16
+ Partial<InternalProperties>
17
+ ] | Partial<ExternalProperties>);
18
+ export declare type EventMapper<E extends Mapping<unknown> = Mapping<unknown>, I extends Mapping<unknown> = Mapping<unknown>, P extends Array<unknown> = Array<unknown>> = (..._parameters: P) => EventMapping<E, I>;
19
+ export declare type EventToPropertyMapping<E extends Mapping<unknown> = Mapping<unknown>, I extends Mapping<unknown> = Mapping<unknown>, P extends Array<unknown> = Array<unknown>> = Mapping<true | EventMapper<E, I, P>>;
17
20
  export declare type AttributesReflectionConfiguration = Array<string> | Map<string, string | ValueOf<typeof PropertyTypes>> | string | Mapping<ValueOf<typeof PropertyTypes> | string>;
18
21
  export declare type ScopeDeclaration = Array<string> | Mapping<unknown>;
19
22
  export declare type PreCompiledItem = {
@@ -26,11 +29,11 @@ export declare type ReactRenderItemsFactory = Array<ReactRenderItemFactory> | Re
26
29
  export declare type ReactRenderBaseItem = ReactElement | string | null;
27
30
  export declare type ReactRenderItem = ((..._parameters: Array<unknown>) => ReactRenderBaseItem) | ReactRenderBaseItem;
28
31
  export declare type ReactRenderItems = Array<ReactRenderItem> | ReactRenderItem;
29
- export interface WebComponentConfiguration {
32
+ export interface WebComponentConfiguration<ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>, EventParameters extends Array<unknown> = Array<unknown>> {
30
33
  attachWebComponentAdapterIfNotExists?: boolean;
31
34
  controllableProperties?: Array<string>;
32
- eventToPropertyMapping?: EventToPropertyMapping;
33
- internalProperties?: Mapping<unknown>;
35
+ eventToPropertyMapping?: EventToPropertyMapping<ExternalProperties, InternalProperties, EventParameters>;
36
+ internalProperties?: InternalProperties;
34
37
  propertiesToReflectAsAttributes?: AttributesReflectionConfiguration;
35
38
  propertyAliases?: Mapping;
36
39
  propTypes?: Mapping<ValueOf<typeof PropertyTypes>>;