@pexip-engage-public/plugin-react 0.0.7
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/CHANGELOG.md +44 -0
- package/README.md +44 -0
- package/dist/index.js +171 -0
- package/dist/index.mjs +137 -0
- package/package.json +68 -0
- package/src/SkedifyPlugin.tsx +35 -0
- package/src/SkedifyPluginContext.ts +16 -0
- package/src/index.tsx +3 -0
- package/src/types.ts +296 -0
- package/src/usePluginOptions.ts +91 -0
- package/src/useSkedifyPlugin.ts +66 -0
- package/typings/SkedifyPlugin.d.ts +8 -0
- package/typings/SkedifyPlugin.d.ts.map +1 -0
- package/typings/SkedifyPluginContext.d.ts +12 -0
- package/typings/SkedifyPluginContext.d.ts.map +1 -0
- package/typings/index.d.ts +4 -0
- package/typings/index.d.ts.map +1 -0
- package/typings/tsconfig.tsbuildinfo +1 -0
- package/typings/types.d.ts +284 -0
- package/typings/types.d.ts.map +1 -0
- package/typings/usePluginOptions.d.ts +3 -0
- package/typings/usePluginOptions.d.ts.map +1 -0
- package/typings/useSkedifyPlugin.d.ts +5 -0
- package/typings/useSkedifyPlugin.d.ts.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @pexip-engage-public/plugin-react
|
|
2
|
+
|
|
3
|
+
## 0.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a17130f3: chore: fix publishing setup
|
|
8
|
+
|
|
9
|
+
## 0.0.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 48abc995: chore: cleanup monorepo setup
|
|
14
|
+
- 1681e3ed: chore: update "author" & "license" fields in package.json
|
|
15
|
+
|
|
16
|
+
## 0.0.5
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 1e2b0577: chore(deps): update react monorepo to v18 (major)
|
|
21
|
+
|
|
22
|
+
## 0.0.4
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- c36e435a: dependencies: update non-major dependencies
|
|
27
|
+
|
|
28
|
+
## 0.0.3
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 75f459a4: chore: BVB - Make bundle compatible for CRA4 consumption
|
|
33
|
+
|
|
34
|
+
## 0.0.2
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 09cf3c2a: fix public npm publishes
|
|
39
|
+
|
|
40
|
+
## 0.0.1
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- 16586c8b: feature: Implement react component for skedify-plugin integration in react apps
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @pexip-engage-public/plugin-react
|
|
2
|
+
|
|
3
|
+
Wrapper around the Skedify Plugin, to integrate it more conveniently inside React Applications.
|
|
4
|
+
|
|
5
|
+
There are 2 exports:
|
|
6
|
+
|
|
7
|
+
- `<SkedifyPlugin configuration={configuration} />`:
|
|
8
|
+
React Component that renders the plugin inside a `div`. You can pass plugin options to it using the `configuration` prop. All other props are passed through to the underlying `div` element.
|
|
9
|
+
|
|
10
|
+
- `<SkedifyPluginProvider value={configuration}>`:
|
|
11
|
+
This is a React Context Provider, that allows you to set certain default values. The interface is the same as the `configuration` prop.
|
|
12
|
+
|
|
13
|
+
This component is **not** required, but can be useful to populate some shared configuration for each plugin instance, eg:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
const defaultConfig = {
|
|
17
|
+
scriptSrc: "https://plugin.skedify.io/{ENTERPRISE_NAME}/skedify-plugin.js",
|
|
18
|
+
language: "nl-be",
|
|
19
|
+
flow: "S'TQC",
|
|
20
|
+
meeting_types: "video",
|
|
21
|
+
timezone: "Europe/Brussels",
|
|
22
|
+
oauth: {
|
|
23
|
+
client: "XXX",
|
|
24
|
+
},
|
|
25
|
+
appointment: {
|
|
26
|
+
office_id: "1",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function App() {
|
|
31
|
+
return (
|
|
32
|
+
<SkedifyPluginProvider value={defaultConfig}>
|
|
33
|
+
{/* All <SkedifyPlugin /> components will now merge their own passed configuration with the defaultConfig value */}
|
|
34
|
+
<SkedifyPlugin configuration={{ appointment: { subject_id: "1" } }}>
|
|
35
|
+
</SkedifyPluginProvider>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The `SkedifyPlugin` reads the current context value, and merges it with its own passed props.
|
|
41
|
+
|
|
42
|
+
Required props:
|
|
43
|
+
|
|
44
|
+
- `scriptSrc`: The plugin entry point URL. eg: `https://plugin.skedify.io/{ENTERPRISE_NAME}/skedify-plugin.js`
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// src/index.tsx
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
SkedifyPlugin: () => SkedifyPlugin,
|
|
30
|
+
SkedifyPluginProvider: () => SkedifyPluginProvider
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(src_exports);
|
|
33
|
+
|
|
34
|
+
// src/SkedifyPlugin.tsx
|
|
35
|
+
var import_react4 = __toESM(require("react"));
|
|
36
|
+
|
|
37
|
+
// src/usePluginOptions.ts
|
|
38
|
+
var import_react2 = __toESM(require("react"));
|
|
39
|
+
var import_deepmerge = __toESM(require("deepmerge"));
|
|
40
|
+
|
|
41
|
+
// src/SkedifyPluginContext.ts
|
|
42
|
+
var import_react = __toESM(require("react"));
|
|
43
|
+
var SkedifyPluginContext = import_react.default.createContext({});
|
|
44
|
+
var SkedifyPluginProvider = SkedifyPluginContext.Provider;
|
|
45
|
+
|
|
46
|
+
// src/usePluginOptions.ts
|
|
47
|
+
function usePluginConfiguration(overrideConfiguration) {
|
|
48
|
+
const defaultConfiguration = import_react2.default.useContext(SkedifyPluginContext);
|
|
49
|
+
const resolvedConfiguration = (0, import_deepmerge.default)(defaultConfiguration, overrideConfiguration);
|
|
50
|
+
return useMemoizedObject(resolvedConfiguration);
|
|
51
|
+
}
|
|
52
|
+
function useMemoizedObject(currentObj) {
|
|
53
|
+
const prevResult = import_react2.default.useRef(currentObj);
|
|
54
|
+
const memoizedObj = replaceEqualDeep(prevResult.current, currentObj);
|
|
55
|
+
import_react2.default.useEffect(() => {
|
|
56
|
+
prevResult.current = memoizedObj;
|
|
57
|
+
});
|
|
58
|
+
return memoizedObj;
|
|
59
|
+
}
|
|
60
|
+
function replaceEqualDeep(a, b) {
|
|
61
|
+
if (a === b) {
|
|
62
|
+
return a;
|
|
63
|
+
}
|
|
64
|
+
const array = Array.isArray(a) && Array.isArray(b);
|
|
65
|
+
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
66
|
+
const aSize = array ? a.length : Object.keys(a).length;
|
|
67
|
+
const bItems = array ? b : Object.keys(b);
|
|
68
|
+
const bSize = bItems.length;
|
|
69
|
+
const copy = array ? [] : {};
|
|
70
|
+
let equalItems = 0;
|
|
71
|
+
for (let i = 0; i < bSize; i++) {
|
|
72
|
+
const key = array ? i : bItems[i];
|
|
73
|
+
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
74
|
+
if (copy[key] === a[key]) {
|
|
75
|
+
equalItems++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
79
|
+
}
|
|
80
|
+
return b;
|
|
81
|
+
}
|
|
82
|
+
function isPlainObject(o) {
|
|
83
|
+
if (!hasObjectPrototype(o)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const ctor = o.constructor;
|
|
87
|
+
if (typeof ctor === "undefined") {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
const prot = ctor.prototype;
|
|
91
|
+
if (!hasObjectPrototype(prot)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
function hasObjectPrototype(o) {
|
|
100
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/useSkedifyPlugin.ts
|
|
104
|
+
var import_react3 = __toESM(require("react"));
|
|
105
|
+
function useSkedifyPlugin(scriptSrc, scriptId) {
|
|
106
|
+
const ctx = import_react3.default.useContext(SkedifyPluginContext);
|
|
107
|
+
const [pluginInstance, setPlugin] = import_react3.default.useState({
|
|
108
|
+
Plugin: null
|
|
109
|
+
});
|
|
110
|
+
const src = scriptSrc ?? ctx.scriptSrc;
|
|
111
|
+
import_react3.default.useEffect(() => {
|
|
112
|
+
if (!src) {
|
|
113
|
+
console.warn(
|
|
114
|
+
"No scriptSrc was provided to SkedifyPluginProvider, or as prop to <SkedifyPlugin />, skipping plugin initialization..."
|
|
115
|
+
);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (window && document) {
|
|
119
|
+
const id = scriptId ?? src;
|
|
120
|
+
if (!document.getElementById(id)) {
|
|
121
|
+
const script = document.createElement("script");
|
|
122
|
+
script.src = src;
|
|
123
|
+
script.async = true;
|
|
124
|
+
script.defer = true;
|
|
125
|
+
script.id = id;
|
|
126
|
+
window.document.body.appendChild(script);
|
|
127
|
+
}
|
|
128
|
+
if (window.Skedify && window.Skedify.Plugin) {
|
|
129
|
+
setPlugin({ Plugin: window.Skedify.Plugin });
|
|
130
|
+
} else {
|
|
131
|
+
const intervalId = window.setInterval(() => {
|
|
132
|
+
if (window.Skedify && window.Skedify.Plugin) {
|
|
133
|
+
window.clearInterval(intervalId);
|
|
134
|
+
setPlugin({ Plugin: window.Skedify.Plugin });
|
|
135
|
+
}
|
|
136
|
+
}, 200);
|
|
137
|
+
return () => window.clearInterval(intervalId);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}, [src, scriptId]);
|
|
141
|
+
return pluginInstance;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/SkedifyPlugin.tsx
|
|
145
|
+
function SkedifyPlugin({ configuration, ...props }) {
|
|
146
|
+
const { Plugin } = useSkedifyPlugin(configuration == null ? void 0 : configuration.scriptSrc);
|
|
147
|
+
const options = usePluginConfiguration(configuration);
|
|
148
|
+
const containerRef = import_react4.default.useRef(null);
|
|
149
|
+
import_react4.default.useEffect(() => {
|
|
150
|
+
if (Plugin && containerRef.current) {
|
|
151
|
+
const instance = new Plugin(containerRef.current, options);
|
|
152
|
+
return () => instance.dispose();
|
|
153
|
+
}
|
|
154
|
+
}, [Plugin, options]);
|
|
155
|
+
const className = import_react4.default.useMemo(() => {
|
|
156
|
+
var _a;
|
|
157
|
+
const preInitClassName = (_a = props.className) == null ? void 0 : _a.replace("skedify-plugin", "").trim();
|
|
158
|
+
const postInitClassName = `${preInitClassName ?? ""} skedify-plugin`.trim();
|
|
159
|
+
return Plugin ? postInitClassName : preInitClassName;
|
|
160
|
+
}, [Plugin, props.className]);
|
|
161
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
162
|
+
...props,
|
|
163
|
+
className,
|
|
164
|
+
ref: containerRef
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {
|
|
169
|
+
SkedifyPlugin,
|
|
170
|
+
SkedifyPluginProvider
|
|
171
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// src/SkedifyPlugin.tsx
|
|
2
|
+
import React4 from "react";
|
|
3
|
+
|
|
4
|
+
// src/usePluginOptions.ts
|
|
5
|
+
import React2 from "react";
|
|
6
|
+
import deepmerge from "deepmerge";
|
|
7
|
+
|
|
8
|
+
// src/SkedifyPluginContext.ts
|
|
9
|
+
import React from "react";
|
|
10
|
+
var SkedifyPluginContext = React.createContext({});
|
|
11
|
+
var SkedifyPluginProvider = SkedifyPluginContext.Provider;
|
|
12
|
+
|
|
13
|
+
// src/usePluginOptions.ts
|
|
14
|
+
function usePluginConfiguration(overrideConfiguration) {
|
|
15
|
+
const defaultConfiguration = React2.useContext(SkedifyPluginContext);
|
|
16
|
+
const resolvedConfiguration = deepmerge(defaultConfiguration, overrideConfiguration);
|
|
17
|
+
return useMemoizedObject(resolvedConfiguration);
|
|
18
|
+
}
|
|
19
|
+
function useMemoizedObject(currentObj) {
|
|
20
|
+
const prevResult = React2.useRef(currentObj);
|
|
21
|
+
const memoizedObj = replaceEqualDeep(prevResult.current, currentObj);
|
|
22
|
+
React2.useEffect(() => {
|
|
23
|
+
prevResult.current = memoizedObj;
|
|
24
|
+
});
|
|
25
|
+
return memoizedObj;
|
|
26
|
+
}
|
|
27
|
+
function replaceEqualDeep(a, b) {
|
|
28
|
+
if (a === b) {
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
const array = Array.isArray(a) && Array.isArray(b);
|
|
32
|
+
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
33
|
+
const aSize = array ? a.length : Object.keys(a).length;
|
|
34
|
+
const bItems = array ? b : Object.keys(b);
|
|
35
|
+
const bSize = bItems.length;
|
|
36
|
+
const copy = array ? [] : {};
|
|
37
|
+
let equalItems = 0;
|
|
38
|
+
for (let i = 0; i < bSize; i++) {
|
|
39
|
+
const key = array ? i : bItems[i];
|
|
40
|
+
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
41
|
+
if (copy[key] === a[key]) {
|
|
42
|
+
equalItems++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
46
|
+
}
|
|
47
|
+
return b;
|
|
48
|
+
}
|
|
49
|
+
function isPlainObject(o) {
|
|
50
|
+
if (!hasObjectPrototype(o)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const ctor = o.constructor;
|
|
54
|
+
if (typeof ctor === "undefined") {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const prot = ctor.prototype;
|
|
58
|
+
if (!hasObjectPrototype(prot)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function hasObjectPrototype(o) {
|
|
67
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/useSkedifyPlugin.ts
|
|
71
|
+
import React3 from "react";
|
|
72
|
+
function useSkedifyPlugin(scriptSrc, scriptId) {
|
|
73
|
+
const ctx = React3.useContext(SkedifyPluginContext);
|
|
74
|
+
const [pluginInstance, setPlugin] = React3.useState({
|
|
75
|
+
Plugin: null
|
|
76
|
+
});
|
|
77
|
+
const src = scriptSrc ?? ctx.scriptSrc;
|
|
78
|
+
React3.useEffect(() => {
|
|
79
|
+
if (!src) {
|
|
80
|
+
console.warn(
|
|
81
|
+
"No scriptSrc was provided to SkedifyPluginProvider, or as prop to <SkedifyPlugin />, skipping plugin initialization..."
|
|
82
|
+
);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (window && document) {
|
|
86
|
+
const id = scriptId ?? src;
|
|
87
|
+
if (!document.getElementById(id)) {
|
|
88
|
+
const script = document.createElement("script");
|
|
89
|
+
script.src = src;
|
|
90
|
+
script.async = true;
|
|
91
|
+
script.defer = true;
|
|
92
|
+
script.id = id;
|
|
93
|
+
window.document.body.appendChild(script);
|
|
94
|
+
}
|
|
95
|
+
if (window.Skedify && window.Skedify.Plugin) {
|
|
96
|
+
setPlugin({ Plugin: window.Skedify.Plugin });
|
|
97
|
+
} else {
|
|
98
|
+
const intervalId = window.setInterval(() => {
|
|
99
|
+
if (window.Skedify && window.Skedify.Plugin) {
|
|
100
|
+
window.clearInterval(intervalId);
|
|
101
|
+
setPlugin({ Plugin: window.Skedify.Plugin });
|
|
102
|
+
}
|
|
103
|
+
}, 200);
|
|
104
|
+
return () => window.clearInterval(intervalId);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, [src, scriptId]);
|
|
108
|
+
return pluginInstance;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/SkedifyPlugin.tsx
|
|
112
|
+
function SkedifyPlugin({ configuration, ...props }) {
|
|
113
|
+
const { Plugin } = useSkedifyPlugin(configuration == null ? void 0 : configuration.scriptSrc);
|
|
114
|
+
const options = usePluginConfiguration(configuration);
|
|
115
|
+
const containerRef = React4.useRef(null);
|
|
116
|
+
React4.useEffect(() => {
|
|
117
|
+
if (Plugin && containerRef.current) {
|
|
118
|
+
const instance = new Plugin(containerRef.current, options);
|
|
119
|
+
return () => instance.dispose();
|
|
120
|
+
}
|
|
121
|
+
}, [Plugin, options]);
|
|
122
|
+
const className = React4.useMemo(() => {
|
|
123
|
+
var _a;
|
|
124
|
+
const preInitClassName = (_a = props.className) == null ? void 0 : _a.replace("skedify-plugin", "").trim();
|
|
125
|
+
const postInitClassName = `${preInitClassName ?? ""} skedify-plugin`.trim();
|
|
126
|
+
return Plugin ? postInitClassName : preInitClassName;
|
|
127
|
+
}, [Plugin, props.className]);
|
|
128
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
129
|
+
...props,
|
|
130
|
+
className,
|
|
131
|
+
ref: containerRef
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
SkedifyPlugin,
|
|
136
|
+
SkedifyPluginProvider
|
|
137
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pexip-engage-public/plugin-react",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "React wrapper component for the Skedify Plugin",
|
|
5
|
+
"homepage": "https://github.com/skedify/frontend-mono/tree/develop/packages/plugin-react#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/skedify/frontend-mono/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/skedify/frontend-mono.git",
|
|
12
|
+
"directory": "packages/plugin-react"
|
|
13
|
+
},
|
|
14
|
+
"license": "UNLICENSED",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Pexip Engage",
|
|
17
|
+
"email": "info@pexip.com",
|
|
18
|
+
"url": "https://engage.pexip.com"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./src/index.tsx": {
|
|
27
|
+
"import": "./src/index.tsx"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./typings/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"CHANGELOG.md",
|
|
36
|
+
"typings",
|
|
37
|
+
"src"
|
|
38
|
+
],
|
|
39
|
+
"jest": {
|
|
40
|
+
"preset": "@pexip-engage/scripts/jest/node"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"deepmerge": "4.2.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@pexip-engage/scripts": "0.0.17",
|
|
47
|
+
"@pexip-engage/tsconfig": "0.0.5"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
51
|
+
},
|
|
52
|
+
"volta": {
|
|
53
|
+
"extends": "../../package.json"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"registry": "https://registry.npmjs.org"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"clean": "rm -rf .turbo node_modules dist typings",
|
|
62
|
+
"dev": "concurrently \"tsc -w\" \"tsup --watch\"",
|
|
63
|
+
"lint": "cross-env TIMING=1 eslint .",
|
|
64
|
+
"lint:fix": "pnpm lint --fix",
|
|
65
|
+
"test": "jest --passWithNoTests",
|
|
66
|
+
"typecheck": "tsc"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// TODO: Use `import React` always! (CRA4 support) Undo these changes when we drop CRA 4 support
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import { SkedifyPluginContextProps } from "./SkedifyPluginContext";
|
|
5
|
+
import { usePluginConfiguration } from "./usePluginOptions";
|
|
6
|
+
import { useSkedifyPlugin } from "./useSkedifyPlugin";
|
|
7
|
+
|
|
8
|
+
interface SkedifyPluginProps
|
|
9
|
+
extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
10
|
+
configuration: SkedifyPluginContextProps;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function SkedifyPlugin({ configuration, ...props }: SkedifyPluginProps) {
|
|
14
|
+
const { Plugin } = useSkedifyPlugin(configuration?.scriptSrc);
|
|
15
|
+
const options = usePluginConfiguration(configuration);
|
|
16
|
+
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
17
|
+
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (Plugin && containerRef.current) {
|
|
20
|
+
// plugin initialized
|
|
21
|
+
const instance = new Plugin(containerRef.current, options);
|
|
22
|
+
|
|
23
|
+
return () => instance.dispose();
|
|
24
|
+
}
|
|
25
|
+
}, [Plugin, options]);
|
|
26
|
+
|
|
27
|
+
const className = React.useMemo(() => {
|
|
28
|
+
const preInitClassName = props.className?.replace("skedify-plugin", "").trim();
|
|
29
|
+
const postInitClassName = `${preInitClassName ?? ""} skedify-plugin`.trim();
|
|
30
|
+
|
|
31
|
+
return Plugin ? postInitClassName : preInitClassName;
|
|
32
|
+
}, [Plugin, props.className]);
|
|
33
|
+
|
|
34
|
+
return <div {...props} className={className} ref={containerRef} />;
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// TODO: Use `import React` always! (CRA4 support) Undo these changes when we drop CRA 4 support
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import type { SkedifyPluginConfiguration } from "./types";
|
|
5
|
+
|
|
6
|
+
export interface SkedifyPluginContextProps extends SkedifyPluginConfiguration {
|
|
7
|
+
/**
|
|
8
|
+
* The plugin entry point URL.
|
|
9
|
+
* eg: `https://plugin.skedify.io/{ENTERPRISE_NAME}/skedify-plugin.js`
|
|
10
|
+
*/
|
|
11
|
+
scriptSrc?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SkedifyPluginContext = React.createContext<SkedifyPluginContextProps>({});
|
|
15
|
+
|
|
16
|
+
export const SkedifyPluginProvider = SkedifyPluginContext.Provider;
|
package/src/index.tsx
ADDED