@univerjs/ui-adapter-web-component 1.0.0-alpha.0 → 1.0.0-alpha.2

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/README.md CHANGED
@@ -30,9 +30,20 @@ import { UniverWebComponentAdapterPlugin } from '@univerjs/ui-adapter-web-compon
30
30
  univer.registerPlugin(UniverWebComponentAdapterPlugin);
31
31
  ```
32
32
 
33
+ Register custom elements with the `web-component` framework option. Runtime props are assigned to the created element as DOM properties, which supports object values such as `data` and `extraProps`.
34
+
35
+ ```ts
36
+ class MyPopup extends HTMLElement {
37
+ set data(value) {
38
+ this.textContent = value?.label ?? '';
39
+ }
40
+ }
41
+
42
+ univerAPI.registerComponent('my-popup', MyPopup, { framework: 'web-component' });
43
+ ```
44
+
33
45
  ## Resources
34
46
 
35
47
  - [Documentation](https://docs.univer.ai)
36
48
  - [NPM package](https://npmjs.com/package/@univerjs/ui-adapter-web-component)
37
49
  - [GitHub repository](https://github.com/dream-num/univer)
38
-
package/lib/cjs/index.js CHANGED
@@ -2,9 +2,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _univerjs_core = require("@univerjs/core");
3
3
  let _univerjs_ui = require("@univerjs/ui");
4
4
 
5
+ //#region src/config/config.ts
6
+ /**
7
+ * Copyright 2023-present DreamNum Co., Ltd.
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY = "ui-adapter-web-component.config";
22
+ const configSymbol = Symbol(UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY);
23
+ const defaultPluginConfig = {};
24
+
25
+ //#endregion
5
26
  //#region package.json
6
27
  var name = "@univerjs/ui-adapter-web-component";
7
- var version = "1.0.0-alpha.0";
28
+ var version = "1.0.0-alpha.2";
8
29
 
9
30
  //#endregion
10
31
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
@@ -68,18 +89,24 @@ function _defineProperty(e, r, t) {
68
89
  //#endregion
69
90
  //#region src/plugin.ts
70
91
  let UniverWebComponentAdapterPlugin = class UniverWebComponentAdapterPlugin extends _univerjs_core.Plugin {
71
- constructor(_config = {}, _injector, _componentManager) {
92
+ constructor(_config = defaultPluginConfig, _injector, _configService, _componentManager) {
72
93
  super();
73
94
  this._config = _config;
74
95
  this._injector = _injector;
96
+ this._configService = _configService;
75
97
  this._componentManager = _componentManager;
98
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
99
+ this._configService.setConfig(UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY, rest);
76
100
  }
77
101
  onStarting() {
78
102
  const { createElement, useEffect, useRef } = this._componentManager.reactUtils;
79
103
  this._componentManager.setHandler("web-component", (component, name) => {
80
- return () => createElement(WebComponentComponentWrapper, {
104
+ return (props) => createElement(WebComponentComponentWrapper, {
81
105
  component,
82
- props: { name },
106
+ props: {
107
+ name,
108
+ componentProps: props
109
+ },
83
110
  reactUtils: {
84
111
  createElement,
85
112
  useEffect,
@@ -95,11 +122,12 @@ _defineProperty(UniverWebComponentAdapterPlugin, "version", version);
95
122
  UniverWebComponentAdapterPlugin = __decorate([
96
123
  (0, _univerjs_core.DependentOn)(_univerjs_ui.UniverUIPlugin),
97
124
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
98
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
125
+ __decorateParam(2, _univerjs_core.IConfigService),
126
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
99
127
  ], UniverWebComponentAdapterPlugin);
100
128
  function WebComponentComponentWrapper(options) {
101
129
  const { component, props, reactUtils } = options;
102
- const { name } = props !== null && props !== void 0 ? props : {};
130
+ const { name, componentProps = {} } = props !== null && props !== void 0 ? props : {};
103
131
  const { createElement, useEffect, useRef } = reactUtils;
104
132
  if (!name) throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");
105
133
  if (!customElements.get(name)) customElements.define(name, component);
@@ -107,16 +135,21 @@ function WebComponentComponentWrapper(options) {
107
135
  useEffect(() => {
108
136
  if (!domRef.current) return;
109
137
  const webComponent = document.createElement(name);
138
+ const webComponentWithProps = webComponent;
139
+ Object.entries(componentProps).forEach(([key, value]) => {
140
+ if (key !== "key") webComponentWithProps[key] = value;
141
+ });
110
142
  domRef.current.appendChild(webComponent);
111
143
  return () => {
112
144
  var _domRef$current;
113
145
  (_domRef$current = domRef.current) === null || _domRef$current === void 0 || _domRef$current.removeChild(webComponent);
114
146
  };
115
- }, []);
147
+ }, [componentProps]);
116
148
  return createElement("div", { ref: domRef });
117
149
  }
118
150
 
119
151
  //#endregion
152
+ exports.UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY = UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY;
120
153
  Object.defineProperty(exports, 'UniverWebComponentAdapterPlugin', {
121
154
  enumerable: true,
122
155
  get: function () {
package/lib/es/index.js CHANGED
@@ -1,9 +1,30 @@
1
- import { DependentOn, Inject, Injector, Plugin } from "@univerjs/core";
1
+ import { DependentOn, IConfigService, Inject, Injector, Plugin, merge } from "@univerjs/core";
2
2
  import { ComponentManager, UniverUIPlugin } from "@univerjs/ui";
3
3
 
4
+ //#region src/config/config.ts
5
+ /**
6
+ * Copyright 2023-present DreamNum Co., Ltd.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ const UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY = "ui-adapter-web-component.config";
21
+ const configSymbol = Symbol(UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY);
22
+ const defaultPluginConfig = {};
23
+
24
+ //#endregion
4
25
  //#region package.json
5
26
  var name = "@univerjs/ui-adapter-web-component";
6
- var version = "1.0.0-alpha.0";
27
+ var version = "1.0.0-alpha.2";
7
28
 
8
29
  //#endregion
9
30
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
@@ -67,18 +88,24 @@ function _defineProperty(e, r, t) {
67
88
  //#endregion
68
89
  //#region src/plugin.ts
69
90
  let UniverWebComponentAdapterPlugin = class UniverWebComponentAdapterPlugin extends Plugin {
70
- constructor(_config = {}, _injector, _componentManager) {
91
+ constructor(_config = defaultPluginConfig, _injector, _configService, _componentManager) {
71
92
  super();
72
93
  this._config = _config;
73
94
  this._injector = _injector;
95
+ this._configService = _configService;
74
96
  this._componentManager = _componentManager;
97
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
98
+ this._configService.setConfig(UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY, rest);
75
99
  }
76
100
  onStarting() {
77
101
  const { createElement, useEffect, useRef } = this._componentManager.reactUtils;
78
102
  this._componentManager.setHandler("web-component", (component, name) => {
79
- return () => createElement(WebComponentComponentWrapper, {
103
+ return (props) => createElement(WebComponentComponentWrapper, {
80
104
  component,
81
- props: { name },
105
+ props: {
106
+ name,
107
+ componentProps: props
108
+ },
82
109
  reactUtils: {
83
110
  createElement,
84
111
  useEffect,
@@ -94,11 +121,12 @@ _defineProperty(UniverWebComponentAdapterPlugin, "version", version);
94
121
  UniverWebComponentAdapterPlugin = __decorate([
95
122
  DependentOn(UniverUIPlugin),
96
123
  __decorateParam(1, Inject(Injector)),
97
- __decorateParam(2, Inject(ComponentManager))
124
+ __decorateParam(2, IConfigService),
125
+ __decorateParam(3, Inject(ComponentManager))
98
126
  ], UniverWebComponentAdapterPlugin);
99
127
  function WebComponentComponentWrapper(options) {
100
128
  const { component, props, reactUtils } = options;
101
- const { name } = props !== null && props !== void 0 ? props : {};
129
+ const { name, componentProps = {} } = props !== null && props !== void 0 ? props : {};
102
130
  const { createElement, useEffect, useRef } = reactUtils;
103
131
  if (!name) throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");
104
132
  if (!customElements.get(name)) customElements.define(name, component);
@@ -106,14 +134,18 @@ function WebComponentComponentWrapper(options) {
106
134
  useEffect(() => {
107
135
  if (!domRef.current) return;
108
136
  const webComponent = document.createElement(name);
137
+ const webComponentWithProps = webComponent;
138
+ Object.entries(componentProps).forEach(([key, value]) => {
139
+ if (key !== "key") webComponentWithProps[key] = value;
140
+ });
109
141
  domRef.current.appendChild(webComponent);
110
142
  return () => {
111
143
  var _domRef$current;
112
144
  (_domRef$current = domRef.current) === null || _domRef$current === void 0 || _domRef$current.removeChild(webComponent);
113
145
  };
114
- }, []);
146
+ }, [componentProps]);
115
147
  return createElement("div", { ref: domRef });
116
148
  }
117
149
 
118
150
  //#endregion
119
- export { UniverWebComponentAdapterPlugin };
151
+ export { UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY, UniverWebComponentAdapterPlugin };
package/lib/index.js CHANGED
@@ -1,9 +1,30 @@
1
- import { DependentOn, Inject, Injector, Plugin } from "@univerjs/core";
1
+ import { DependentOn, IConfigService, Inject, Injector, Plugin, merge } from "@univerjs/core";
2
2
  import { ComponentManager, UniverUIPlugin } from "@univerjs/ui";
3
3
 
4
+ //#region src/config/config.ts
5
+ /**
6
+ * Copyright 2023-present DreamNum Co., Ltd.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ const UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY = "ui-adapter-web-component.config";
21
+ const configSymbol = Symbol(UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY);
22
+ const defaultPluginConfig = {};
23
+
24
+ //#endregion
4
25
  //#region package.json
5
26
  var name = "@univerjs/ui-adapter-web-component";
6
- var version = "1.0.0-alpha.0";
27
+ var version = "1.0.0-alpha.2";
7
28
 
8
29
  //#endregion
9
30
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
@@ -67,18 +88,24 @@ function _defineProperty(e, r, t) {
67
88
  //#endregion
68
89
  //#region src/plugin.ts
69
90
  let UniverWebComponentAdapterPlugin = class UniverWebComponentAdapterPlugin extends Plugin {
70
- constructor(_config = {}, _injector, _componentManager) {
91
+ constructor(_config = defaultPluginConfig, _injector, _configService, _componentManager) {
71
92
  super();
72
93
  this._config = _config;
73
94
  this._injector = _injector;
95
+ this._configService = _configService;
74
96
  this._componentManager = _componentManager;
97
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
98
+ this._configService.setConfig(UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY, rest);
75
99
  }
76
100
  onStarting() {
77
101
  const { createElement, useEffect, useRef } = this._componentManager.reactUtils;
78
102
  this._componentManager.setHandler("web-component", (component, name) => {
79
- return () => createElement(WebComponentComponentWrapper, {
103
+ return (props) => createElement(WebComponentComponentWrapper, {
80
104
  component,
81
- props: { name },
105
+ props: {
106
+ name,
107
+ componentProps: props
108
+ },
82
109
  reactUtils: {
83
110
  createElement,
84
111
  useEffect,
@@ -94,11 +121,12 @@ _defineProperty(UniverWebComponentAdapterPlugin, "version", version);
94
121
  UniverWebComponentAdapterPlugin = __decorate([
95
122
  DependentOn(UniverUIPlugin),
96
123
  __decorateParam(1, Inject(Injector)),
97
- __decorateParam(2, Inject(ComponentManager))
124
+ __decorateParam(2, IConfigService),
125
+ __decorateParam(3, Inject(ComponentManager))
98
126
  ], UniverWebComponentAdapterPlugin);
99
127
  function WebComponentComponentWrapper(options) {
100
128
  const { component, props, reactUtils } = options;
101
- const { name } = props !== null && props !== void 0 ? props : {};
129
+ const { name, componentProps = {} } = props !== null && props !== void 0 ? props : {};
102
130
  const { createElement, useEffect, useRef } = reactUtils;
103
131
  if (!name) throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");
104
132
  if (!customElements.get(name)) customElements.define(name, component);
@@ -106,14 +134,18 @@ function WebComponentComponentWrapper(options) {
106
134
  useEffect(() => {
107
135
  if (!domRef.current) return;
108
136
  const webComponent = document.createElement(name);
137
+ const webComponentWithProps = webComponent;
138
+ Object.entries(componentProps).forEach(([key, value]) => {
139
+ if (key !== "key") webComponentWithProps[key] = value;
140
+ });
109
141
  domRef.current.appendChild(webComponent);
110
142
  return () => {
111
143
  var _domRef$current;
112
144
  (_domRef$current = domRef.current) === null || _domRef$current === void 0 || _domRef$current.removeChild(webComponent);
113
145
  };
114
- }, []);
146
+ }, [componentProps]);
115
147
  return createElement("div", { ref: domRef });
116
148
  }
117
149
 
118
150
  //#endregion
119
- export { UniverWebComponentAdapterPlugin };
151
+ export { UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY, UniverWebComponentAdapterPlugin };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export declare const UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY = "ui-adapter-web-component.config";
17
+ export declare const configSymbol: unique symbol;
18
+ export interface IUniverWebComponentAdapterConfig {
19
+ }
20
+ export declare const defaultPluginConfig: IUniverWebComponentAdapterConfig;
@@ -13,4 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ export { UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY } from './config/config';
17
+ export type { IUniverWebComponentAdapterConfig } from './config/config';
16
18
  export { UniverWebComponentAdapterPlugin } from './plugin';
@@ -13,7 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Injector, Plugin } from '@univerjs/core';
16
+ import type { IUniverWebComponentAdapterConfig } from './config/config';
17
+ import { IConfigService, Injector, Plugin } from '@univerjs/core';
17
18
  import { ComponentManager } from '@univerjs/ui';
18
19
  /**
19
20
  * The plugin that allows Univer to use web components as UI components.
@@ -21,17 +22,19 @@ import { ComponentManager } from '@univerjs/ui';
21
22
  export declare class UniverWebComponentAdapterPlugin extends Plugin {
22
23
  private readonly _config;
23
24
  protected readonly _injector: Injector;
25
+ private readonly _configService;
24
26
  protected readonly _componentManager: ComponentManager;
25
27
  static pluginName: string;
26
28
  static packageName: string;
27
29
  static version: string;
28
- constructor(_config: {} | undefined, _injector: Injector, _componentManager: ComponentManager);
30
+ constructor(_config: Partial<IUniverWebComponentAdapterConfig> | undefined, _injector: Injector, _configService: IConfigService, _componentManager: ComponentManager);
29
31
  onStarting(): void;
30
32
  }
31
33
  export declare function WebComponentComponentWrapper(options: {
32
34
  component: CustomElementConstructor;
33
35
  props?: {
34
36
  name?: string;
37
+ componentProps?: Record<string, unknown>;
35
38
  };
36
39
  reactUtils: typeof ComponentManager.prototype.reactUtils;
37
40
  }): import("react").DetailedReactHTMLElement<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverUiAdapterWebComponent={},e.UniverCore,e.UniverUi))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=`@univerjs/ui-adapter-web-component`,i=`1.0.0-alpha.0`;function a(e,t){return function(n,r){t(n,r,e)}}function o(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let d=class extends t.Plugin{constructor(e={},t,n){super(),this._config=e,this._injector=t,this._componentManager=n}onStarting(){let{createElement:e,useEffect:t,useRef:n}=this._componentManager.reactUtils;this._componentManager.setHandler(`web-component`,(r,i)=>()=>e(f,{component:r,props:{name:i},reactUtils:{createElement:e,useEffect:t,useRef:n}}))}};u(d,`pluginName`,`UNIVER_UI_ADAPTER_WEB_COMPONENT_PLUGIN`),u(d,`packageName`,r),u(d,`version`,i),d=o([(0,t.DependentOn)(n.UniverUIPlugin),a(1,(0,t.Inject)(t.Injector)),a(2,(0,t.Inject)(n.ComponentManager))],d);function f(e){let{component:t,props:n,reactUtils:r}=e,{name:i}=n==null?{}:n,{createElement:a,useEffect:o,useRef:s}=r;if(!i)throw Error(`WebComponentComponentWrapper requires a name prop to define the custom element.`);customElements.get(i)||customElements.define(i,t);let c=s(null);return o(()=>{if(!c.current)return;let e=document.createElement(i);return c.current.appendChild(e),()=>{var t;(t=c.current)==null||t.removeChild(e)}},[]),a(`div`,{ref:c})}Object.defineProperty(e,"UniverWebComponentAdapterPlugin",{enumerable:!0,get:function(){return d}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverUiAdapterWebComponent={},e.UniverCore,e.UniverUi))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let r=`ui-adapter-web-component.config`,i={};var a=`@univerjs/ui-adapter-web-component`,o=`1.0.0-alpha.2`;function s(e,t){return function(n,r){t(n,r,e)}}function c(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function l(e){"@babel/helpers - typeof";return l=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let p=class extends t.Plugin{constructor(e=i,n,a,o){super(),this._config=e,this._injector=n,this._configService=a,this._componentManager=o;let{...s}=(0,t.merge)({},i,this._config);this._configService.setConfig(r,s)}onStarting(){let{createElement:e,useEffect:t,useRef:n}=this._componentManager.reactUtils;this._componentManager.setHandler(`web-component`,(r,i)=>a=>e(m,{component:r,props:{name:i,componentProps:a},reactUtils:{createElement:e,useEffect:t,useRef:n}}))}};f(p,`pluginName`,`UNIVER_UI_ADAPTER_WEB_COMPONENT_PLUGIN`),f(p,`packageName`,a),f(p,`version`,o),p=c([(0,t.DependentOn)(n.UniverUIPlugin),s(1,(0,t.Inject)(t.Injector)),s(2,t.IConfigService),s(3,(0,t.Inject)(n.ComponentManager))],p);function m(e){let{component:t,props:n,reactUtils:r}=e,{name:i,componentProps:a={}}=n==null?{}:n,{createElement:o,useEffect:s,useRef:c}=r;if(!i)throw Error(`WebComponentComponentWrapper requires a name prop to define the custom element.`);customElements.get(i)||customElements.define(i,t);let l=c(null);return s(()=>{if(!l.current)return;let e=document.createElement(i),t=e;return Object.entries(a).forEach(([e,n])=>{e!==`key`&&(t[e]=n)}),l.current.appendChild(e),()=>{var t;(t=l.current)==null||t.removeChild(e)}},[a]),o(`div`,{ref:l})}e.UI_ADAPTER_WEB_COMPONENT_PLUGIN_CONFIG_KEY=r,Object.defineProperty(e,"UniverWebComponentAdapterPlugin",{enumerable:!0,get:function(){return p}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/ui-adapter-web-component",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
4
  "private": false,
5
5
  "description": "Web Component adapter for Univer UI services.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -49,13 +49,13 @@
49
49
  "lib"
50
50
  ],
51
51
  "dependencies": {
52
- "@univerjs/core": "1.0.0-alpha.0",
53
- "@univerjs/ui": "1.0.0-alpha.0"
52
+ "@univerjs/core": "1.0.0-alpha.2",
53
+ "@univerjs/ui": "1.0.0-alpha.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "typescript": "^6.0.3",
57
57
  "vitest": "^4.1.9",
58
- "@univerjs-infra/shared": "1.0.0-alpha.0"
58
+ "@univerjs-infra/shared": "1.0.0-alpha.2"
59
59
  },
60
60
  "scripts": {
61
61
  "test": "vitest run",