@univerjs/ui-adapter-web-component 0.8.3-nightly.202507010644

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 ADDED
@@ -0,0 +1 @@
1
+ # @univerjs/ui-adapter-web-component
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),p=require("@univerjs/ui"),u=require("react");var l=Object.defineProperty,s=Object.getOwnPropertyDescriptor,d=(r,e,n)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,_=(r,e,n,t)=>{for(var o=t>1?void 0:t?s(e,n):e,i=r.length-1,c;i>=0;i--)(c=r[i])&&(o=c(o)||o);return o},m=(r,e)=>(n,t)=>e(n,t,r),f=(r,e,n)=>d(r,e+"",n);exports.UniverWebComponentAdapterPlugin=class extends a.Plugin{constructor(e={},n,t){super(),this._config=e,this._injector=n,this._componentManager=t}onStarting(){this._componentManager.setHandler("web-component",(e,n)=>()=>u.cloneElement(u.createElement(g,{component:e,props:{name:n}})))}};f(exports.UniverWebComponentAdapterPlugin,"pluginName","UNIVER_UI_ADAPTER_WEB_COMPONENT_PLUGIN");exports.UniverWebComponentAdapterPlugin=_([a.DependentOn(p.UniverUIPlugin),m(1,a.Inject(a.Injector)),m(2,a.Inject(p.ComponentManager))],exports.UniverWebComponentAdapterPlugin);function g(r){const{component:e,props:n}=r,{name:t}=n!=null?n:{};if(!t)throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");customElements.get(t)||customElements.define(t,e);const o=u.useRef(null);return u.useEffect(()=>{if(!o.current)return;const i=document.createElement(t);return o.current.appendChild(i),()=>{var c;(c=o.current)==null||c.removeChild(i)}},[]),u.createElement("div",{ref:o})}
@@ -0,0 +1,47 @@
1
+ import { DependentOn as l, Inject as a, Injector as s, Plugin as f } from "@univerjs/core";
2
+ import { UniverUIPlugin as _, ComponentManager as d } from "@univerjs/ui";
3
+ import { cloneElement as g, createElement as u, useRef as v, useEffect as P } from "react";
4
+ var C = Object.defineProperty, E = Object.getOwnPropertyDescriptor, b = (e, n, r) => n in e ? C(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r, h = (e, n, r, t) => {
5
+ for (var o = t > 1 ? void 0 : t ? E(n, r) : n, m = e.length - 1, p; m >= 0; m--)
6
+ (p = e[m]) && (o = p(o) || o);
7
+ return o;
8
+ }, i = (e, n) => (r, t) => n(r, t, e), w = (e, n, r) => b(e, n + "", r);
9
+ let c = class extends f {
10
+ constructor(e = {}, n, r) {
11
+ super(), this._config = e, this._injector = n, this._componentManager = r;
12
+ }
13
+ onStarting() {
14
+ this._componentManager.setHandler("web-component", (e, n) => () => g(
15
+ u(O, {
16
+ component: e,
17
+ props: {
18
+ name: n
19
+ }
20
+ })
21
+ ));
22
+ }
23
+ };
24
+ w(c, "pluginName", "UNIVER_UI_ADAPTER_WEB_COMPONENT_PLUGIN");
25
+ c = h([
26
+ l(_),
27
+ i(1, a(s)),
28
+ i(2, a(d))
29
+ ], c);
30
+ function O(e) {
31
+ const { component: n, props: r } = e, { name: t } = r != null ? r : {};
32
+ if (!t)
33
+ throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");
34
+ customElements.get(t) || customElements.define(t, n);
35
+ const o = v(null);
36
+ return P(() => {
37
+ if (!o.current) return;
38
+ const m = document.createElement(t);
39
+ return o.current.appendChild(m), () => {
40
+ var p;
41
+ (p = o.current) == null || p.removeChild(m);
42
+ };
43
+ }, []), u("div", { ref: o });
44
+ }
45
+ export {
46
+ c as UniverWebComponentAdapterPlugin
47
+ };
package/lib/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import { DependentOn as l, Inject as a, Injector as s, Plugin as f } from "@univerjs/core";
2
+ import { UniverUIPlugin as _, ComponentManager as d } from "@univerjs/ui";
3
+ import { cloneElement as g, createElement as u, useRef as v, useEffect as P } from "react";
4
+ var C = Object.defineProperty, E = Object.getOwnPropertyDescriptor, b = (e, n, r) => n in e ? C(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r, h = (e, n, r, t) => {
5
+ for (var o = t > 1 ? void 0 : t ? E(n, r) : n, m = e.length - 1, p; m >= 0; m--)
6
+ (p = e[m]) && (o = p(o) || o);
7
+ return o;
8
+ }, i = (e, n) => (r, t) => n(r, t, e), w = (e, n, r) => b(e, n + "", r);
9
+ let c = class extends f {
10
+ constructor(e = {}, n, r) {
11
+ super(), this._config = e, this._injector = n, this._componentManager = r;
12
+ }
13
+ onStarting() {
14
+ this._componentManager.setHandler("web-component", (e, n) => () => g(
15
+ u(O, {
16
+ component: e,
17
+ props: {
18
+ name: n
19
+ }
20
+ })
21
+ ));
22
+ }
23
+ };
24
+ w(c, "pluginName", "UNIVER_UI_ADAPTER_WEB_COMPONENT_PLUGIN");
25
+ c = h([
26
+ l(_),
27
+ i(1, a(s)),
28
+ i(2, a(d))
29
+ ], c);
30
+ function O(e) {
31
+ const { component: n, props: r } = e, { name: t } = r != null ? r : {};
32
+ if (!t)
33
+ throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");
34
+ customElements.get(t) || customElements.define(t, n);
35
+ const o = v(null);
36
+ return P(() => {
37
+ if (!o.current) return;
38
+ const m = document.createElement(t);
39
+ return o.current.appendChild(m), () => {
40
+ var p;
41
+ (p = o.current) == null || p.removeChild(m);
42
+ };
43
+ }, []), u("div", { ref: o });
44
+ }
45
+ export {
46
+ c as UniverWebComponentAdapterPlugin
47
+ };
@@ -0,0 +1,16 @@
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 { UniverWebComponentAdapterPlugin } from './plugin';
@@ -0,0 +1,17 @@
1
+ import { Injector, Plugin } from '@univerjs/core';
2
+ import { ComponentManager } from '@univerjs/ui';
3
+ /**
4
+ * The plugin that allows Univer to use web components as UI components.
5
+ */
6
+ export declare class UniverWebComponentAdapterPlugin extends Plugin {
7
+ private readonly _config;
8
+ protected readonly _injector: Injector;
9
+ protected readonly _componentManager: ComponentManager;
10
+ static pluginName: string;
11
+ constructor(_config: {} | undefined, _injector: Injector, _componentManager: ComponentManager);
12
+ onStarting(): void;
13
+ }
14
+ export declare function WebComponentComponentWrapper(options: {
15
+ component: CustomElementConstructor;
16
+ props?: Record<string, any>;
17
+ }): import('react').DetailedReactHTMLElement<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
@@ -0,0 +1 @@
1
+ (function(r,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/ui"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","react"],i):(r=typeof globalThis<"u"?globalThis:r||self,i(r.UniverUiAdapterWebComponent={},r.UniverCore,r.UniverUi,r.React))})(this,function(r,i,a,m){"use strict";var d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,l=(t,e,n)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,v=(t,e,n,o)=>{for(var u=o>1?void 0:o?f(e,n):e,p=t.length-1,c;p>=0;p--)(c=t[p])&&(u=c(u)||u);return u},s=(t,e)=>(n,o)=>e(n,o,t),_=(t,e,n)=>l(t,e+"",n);r.UniverWebComponentAdapterPlugin=class extends i.Plugin{constructor(e={},n,o){super(),this._config=e,this._injector=n,this._componentManager=o}onStarting(){this._componentManager.setHandler("web-component",(e,n)=>()=>m.cloneElement(m.createElement(C,{component:e,props:{name:n}})))}},_(r.UniverWebComponentAdapterPlugin,"pluginName","UNIVER_UI_ADAPTER_WEB_COMPONENT_PLUGIN"),r.UniverWebComponentAdapterPlugin=v([i.DependentOn(a.UniverUIPlugin),s(1,i.Inject(i.Injector)),s(2,i.Inject(a.ComponentManager))],r.UniverWebComponentAdapterPlugin);function C(t){const{component:e,props:n}=t,{name:o}=n!=null?n:{};if(!o)throw new Error("WebComponentComponentWrapper requires a name prop to define the custom element.");customElements.get(o)||customElements.define(o,e);const u=m.useRef(null);return m.useEffect(()=>{if(!u.current)return;const p=document.createElement(o);return u.current.appendChild(p),()=>{var c;(c=u.current)==null||c.removeChild(p)}},[]),m.createElement("div",{ref:u})}Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@univerjs/ui-adapter-web-component",
3
+ "version": "0.8.3-nightly.202507010644",
4
+ "private": false,
5
+ "description": "Web component adapter for Univer UI",
6
+ "author": "DreamNum <developer@univer.ai>",
7
+ "license": "Apache-2.0",
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/univer"
11
+ },
12
+ "homepage": "https://univer.ai",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/dream-num/univer"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/dream-num/univer/issues"
19
+ },
20
+ "keywords": [
21
+ "univer"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "import": "./lib/es/index.js",
26
+ "require": "./lib/cjs/index.js",
27
+ "types": "./lib/types/index.d.ts"
28
+ },
29
+ "./*": {
30
+ "import": "./lib/es/*",
31
+ "require": "./lib/cjs/*",
32
+ "types": "./lib/types/index.d.ts"
33
+ },
34
+ "./lib/*": "./lib/*"
35
+ },
36
+ "main": "./lib/es/index.js",
37
+ "types": "./lib/types/index.d.ts",
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "directories": {
42
+ "lib": "lib"
43
+ },
44
+ "files": [
45
+ "lib"
46
+ ],
47
+ "peerDependencies": {
48
+ "react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
49
+ },
50
+ "dependencies": {
51
+ "@univerjs/core": "0.8.3-nightly.202507010644",
52
+ "@univerjs/ui": "0.8.3-nightly.202507010644"
53
+ },
54
+ "devDependencies": {
55
+ "react": "18.3.1",
56
+ "typescript": "^5.8.3",
57
+ "vite": "^6.3.5",
58
+ "vitest": "^3.2.4",
59
+ "@univerjs-infra/shared": "0.8.3"
60
+ },
61
+ "scripts": {
62
+ "test": "vitest run",
63
+ "test:watch": "vitest",
64
+ "coverage": "vitest run --coverage",
65
+ "lint:types": "tsc --noEmit",
66
+ "build": "univer-cli build"
67
+ },
68
+ "module": "./lib/es/index.js"
69
+ }