web-component-wrapper 0.0.599 → 0.0.601

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/type.d.ts ADDED
@@ -0,0 +1,100 @@
1
+ import { Mapping, TemplateFunction, UTILITY_SCOPE, ValueOf } from 'clientnode';
2
+ import PropertyTypes, { ValidationMap } from 'clientnode/property-types';
3
+ import React, { ComponentType as ReactComponentType, HTMLAttributes, ReactElement } from 'react';
4
+ import Web from './Web';
5
+ export interface RenderState {
6
+ promise: Promise<string>;
7
+ pending: boolean;
8
+ resolve: (reason: string) => void;
9
+ }
10
+ export interface CompilerOptions {
11
+ filter?: (domNode: Node) => boolean;
12
+ ignoreComponents?: boolean;
13
+ ignoreNestedComponents?: boolean;
14
+ unsafe?: boolean;
15
+ }
16
+ export interface CompiledDomNodeTemplateItem {
17
+ domNode: Node;
18
+ children: Array<CompiledDomNodeTemplateItem>;
19
+ error?: null | string;
20
+ scopeNames?: Array<string>;
21
+ template?: string;
22
+ templateFunction?: TemplateFunction;
23
+ }
24
+ export type DomNodeToCompiledTemplateMap<NodeType = Node> = Map<NodeType, CompiledDomNodeTemplateItem>;
25
+ export type EventCallbackMapping = Map<string, () => void>;
26
+ export type EventMapping<ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>> = (null | [
27
+ Partial<ExternalProperties>,
28
+ Partial<InternalProperties>
29
+ ] | Partial<ExternalProperties>);
30
+ export 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> | Promise<EventMapping<E, I>>;
31
+ export 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>>;
32
+ export type PropertyType = string | ValueOf<typeof PropertyTypes>;
33
+ export type PropertyConfiguration = PropertyType;
34
+ export type ValidationMapping = ValidationMap<ValueOf<typeof PropertyTypes>>;
35
+ export type PropertiesValidationMap = Mapping<ValueOf<typeof PropertyTypes>>;
36
+ export type PropertiesConfiguration = Mapping | PropertiesValidationMap;
37
+ export type NormalizedAttributesReflectionConfiguration = Map<string, PropertyConfiguration>;
38
+ export type AttributesReflectionConfiguration = (string | Array<string> | PropertiesConfiguration | NormalizedAttributesReflectionConfiguration);
39
+ export type ReadonlyScope = typeof UTILITY_SCOPE;
40
+ export type Scope = {
41
+ -readonly [key in keyof ReadonlyScope]: ReadonlyScope[key];
42
+ };
43
+ export type CallbackScope<Type = unknown> = Scope & {
44
+ data: Type;
45
+ event: Type;
46
+ firstArgument: Type;
47
+ firstParameter: Type;
48
+ options: Type;
49
+ parameters: Type;
50
+ scope: CallbackScope<Type>;
51
+ };
52
+ export type ScopeDeclaration = Array<string> | Mapping<unknown>;
53
+ export interface PreCompiledItem {
54
+ originalScopeNames: Array<string>;
55
+ templateFunction: TemplateFunction;
56
+ }
57
+ export type ReactComponentBaseProperties<TElement = HTMLElement> = Mapping<unknown> & {
58
+ children?: Array<React.ReactNode> | React.ReactNode;
59
+ dangerouslySetInnerHTML?: HTMLAttributes<TElement>['dangerouslySetInnerHTML'];
60
+ key?: string;
61
+ ref?: (null | {
62
+ current?: ComponentAdapter;
63
+ } | ((reference: ComponentAdapter) => void));
64
+ };
65
+ export type ReactRenderBaseItemFactory = (scope: Mapping<unknown>) => ReactRenderBaseItem;
66
+ export type ReactRenderItemFactory = (scope: Mapping<unknown>) => ReactRenderItem;
67
+ export type ReactRenderItemsFactory = Array<ReactRenderItemFactory> | ReactRenderItemFactory;
68
+ export type ReactRenderBaseItem = ReactElement | string | null;
69
+ export type ReactRenderItem = ((...parameters: Array<unknown>) => ReactRenderBaseItem) | ReactRenderBaseItem;
70
+ export type ReactRenderItems = Array<ReactRenderItem> | ReactRenderItem;
71
+ export interface WebComponentConfiguration<ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>, EventParameters extends Array<unknown> = Array<unknown>> {
72
+ attachWebComponentAdapterIfNotExists?: boolean;
73
+ controllableProperties?: Array<string>;
74
+ eventToPropertyMapping?: (EventToPropertyMapping<ExternalProperties, InternalProperties, EventParameters> | null);
75
+ internalProperties?: InternalProperties;
76
+ propertiesToReflectAsAttributes?: AttributesReflectionConfiguration;
77
+ propertyAliases?: Mapping;
78
+ propTypes?: PropertiesConfiguration;
79
+ renderProperties?: Array<string>;
80
+ unmountOnDisconnect?: boolean;
81
+ }
82
+ export interface StaticWebComponent<ComponentType = unknown, ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>, EventParameters extends Array<unknown> = Array<unknown>> extends WebComponentConfiguration<ExternalProperties, InternalProperties, EventParameters> {
83
+ webComponentAdapterWrapped?: string;
84
+ wrapped?: ComponentType;
85
+ _name?: string;
86
+ ___types?: {
87
+ name?: {
88
+ name?: string;
89
+ };
90
+ };
91
+ }
92
+ export type ComponentType<PropertyTypes = Mapping<unknown>> = Omit<ReactComponentType<PropertyTypes>, 'propTypes'> & StaticWebComponent;
93
+ export interface ComponentAdapter<Properties = Mapping<unknown>, State = Mapping<unknown>> {
94
+ properties?: Properties;
95
+ state?: State;
96
+ }
97
+ export interface WebComponentAPI<TElement = HTMLElement, ExternalProperties extends Mapping<unknown> = Mapping<unknown>, InternalProperties extends Mapping<unknown> = Mapping<unknown>, Type extends typeof Web<TElement, ExternalProperties, InternalProperties> = typeof Web<TElement, ExternalProperties, InternalProperties>> {
98
+ component: Type;
99
+ register: (tagName?: string) => void;
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-wrapper",
3
- "version": "0.0.599",
3
+ "version": "0.0.601",
4
4
  "description": "Generic web-component base class and framework specific wrapper.",
5
5
  "keywords": [
6
6
  "component",
@@ -24,8 +24,23 @@
24
24
  "url": "https://torben.website"
25
25
  },
26
26
  "main": "dist/index.js",
27
+ "exports": {
28
+ ".": "./dist/index.js",
29
+ "./decorator": "./dist/decorator.js",
30
+ "./ReactWeb": "./dist/ReactWeb.js",
31
+ "./Web": "./dist/Web.js",
32
+ "./type": "./dist/type.js"
33
+ },
34
+ "typesVersions": {
35
+ "*": {
36
+ "type": [
37
+ "./dist/type.d.ts"
38
+ ]
39
+ }
40
+ },
27
41
  "files": [
28
- "dist"
42
+ "dist",
43
+ "polyfill.html.ejs"
29
44
  ],
30
45
  "repository": {
31
46
  "type": "git",
@@ -68,7 +83,7 @@
68
83
  "@typescript-eslint/eslint-plugin": "^8.61.0",
69
84
  "@typescript-eslint/parser": "^8.61.0",
70
85
  "@webcomponents/webcomponentsjs": "^2.8.0",
71
- "clientnode": "^4.0.1422",
86
+ "clientnode": "^4.0.1423",
72
87
  "eslint": "^10.5.0",
73
88
  "eslint-config-google": "^0.14.0",
74
89
  "eslint-plugin-jsdoc": "^63.0.2",
@@ -78,7 +93,7 @@
78
93
  "react": "^19.2.7",
79
94
  "react-dom": "^19.2.7",
80
95
  "typescript-eslint": "^8.61.0",
81
- "web-documentation": "^1.0.37",
96
+ "web-documentation": "^1.0.39",
82
97
  "weboptimizer": "^3.0.24",
83
98
  "webpack-dev-server": "^5.2.5"
84
99
  },
@@ -0,0 +1,74 @@
1
+ <!--
2
+ Promise: React uses for rendering.
3
+
4
+ NOTE: "Array.from", "Object.assign" and "Promise" will be polyfilled by the
5
+ webcomponent polyfill.
6
+ -->
7
+ <%_
8
+ const features = new Set([
9
+ // Most polyfills are determined via "create-polyfill-service-url".
10
+ 'Array.from',
11
+ 'Array.isArray',
12
+ 'Array.prototype.entries',
13
+ 'Array.prototype.filter',
14
+ // Is used by "Object.entries" polyfill.
15
+ 'Array.prototype.flat',
16
+ // clientnode - Usage.
17
+ 'Array.prototype.includes',
18
+ 'Array.prototype.keys',
19
+ 'Array.prototype.map',
20
+ 'Array.prototype.values',
21
+ // Usual array interaction.
22
+ 'Array.prototype.@@iterator',
23
+ 'ArrayBuffer',
24
+ 'console',
25
+ 'CustomEvent',
26
+ 'DataView',
27
+ 'document',
28
+ // Usual dom interactions.
29
+ 'DOMTokenList.prototype.@@iterator',
30
+ 'Function.prototype.bind',
31
+ 'JSON',
32
+ 'Map',
33
+ // Usual dom interactions.
34
+ 'NodeList.prototype.@@iterator',
35
+ 'Object.defineProperty',
36
+ // Iterating over mapping objects everywhere.
37
+ 'Object.entries',
38
+ // Applying a scope object during template function call.
39
+ 'Object.keys',
40
+ 'Object.values',
41
+ 'Promise',
42
+ 'Set',
43
+ // Many usages e.g. in clientnode.
44
+ 'String.prototype.endsWith',
45
+ 'String.prototype.includes',
46
+ 'String.prototype.startsWith',
47
+ 'String.prototype.trim',
48
+ // Used by react to identify its own entities.
49
+ 'Symbol',
50
+ 'Symbol.for',
51
+ 'Symbol.iterator',
52
+ 'Symbol.toStringTag',
53
+ 'WeakMap',
54
+ 'WeakSet'
55
+ ].concat(
56
+ typeof _.additionalFeatures === 'undefined' ? [] : _.additionalFeatures
57
+ ))
58
+ _%>
59
+ <script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?version=4.8.0&features=<%- encodeURIComponent(Array.from(features).sort().join(',')) %>"></script>
60
+
61
+ <%_ if (typeof _.webComponents === 'undefined' || _.webComponents) { _%>
62
+ <script>
63
+ /*
64
+ Only provide the shadow dom polyfill and avoid to patch a lot of
65
+ dom apis.
66
+ */
67
+ window.ShadyDOM = {noPatch: true}
68
+ </script>
69
+ <script src="/@webcomponents/webcomponentsjs/webcomponents-bundle.js">
70
+ </script>
71
+ <script
72
+ src="/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"
73
+ ></script>
74
+ <%_ } _%>
package/readme.md CHANGED
@@ -127,11 +127,37 @@ export class MyWebComponent<
127
127
  customElements.define('my-web-component', MyWebComponent)
128
128
  ```
129
129
 
130
+ <!--showExample:hidden-->
131
+
132
+ ```HTML
133
+ <script
134
+ src="https://unpkg.com/web-component-wrapper@latest/dist/bundle/Web.js"
135
+ ></script>
136
+ <script
137
+ src="https://unpkg.com/web-component-wrapper@latest/dist/bundle/decorator.js"
138
+ ></script>
139
+ ```
140
+
141
+ <!--showExample:JavaScript-->
142
+
143
+ ```JavaScript
144
+ class MyGreeting extends webComponentWrapper.Web {
145
+ static doRender: true
146
+ static evaluateSlots: true
147
+ static observedAttributes = ['name']
148
+ static content = '<div>Hello ${name}</div>'
149
+
150
+ @property()
151
+ name = 'string'
152
+ };
153
+
154
+ customElements.define('my-greeting', MyGreeting)
155
+ ```
156
+
130
157
  <!--showExample-->
131
158
 
132
159
  ```HTML
133
- <script src="https://unpkg.com/web-component-wrapper@latest/bundle/Web.js">
134
- </script>
160
+ <my-greeting name="World"></my-greeting>
135
161
  ```
136
162
 
137
163
  ## Data-Flow