@pexip-engage-public/plugin-react 2.0.0-canary-20231023080955 → 2.0.0

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 CHANGED
@@ -1,16 +1,43 @@
1
1
  # @pexip-engage-public/plugin-react
2
2
 
3
- ## 2.0.0-canary-20231023080955
3
+ ## 2.0.0
4
4
 
5
5
  ### Major Changes
6
6
 
7
- - f94a30b50: feat: switch plugin packages to native node esm only
7
+ - 7412230be: feat: This package is ESM only starting from this release.
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - Updated dependencies [f94a30b50]
12
- - @pexip-engage-public/plugin-configuration-parser@2.0.0-canary-20231023080955
13
- - @pexip-engage-public/plugin-instance@2.0.0-canary-20231023080955
11
+ - Updated dependencies [7412230be]
12
+ - @pexip-engage-public/plugin@1.0.0
13
+
14
+ ## 1.1.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 93c2a834b: (minor) prepare for legacy switch
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [93c2a834b]
23
+ - @pexip-engage-public/plugin-configuration-parser@1.3.0
24
+ - @pexip-engage-public/plugin-instance@1.2.0
25
+
26
+ ## 1.0.57
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [0321f449c]
31
+ - @pexip-engage-public/plugin-configuration-parser@1.2.2
32
+ - @pexip-engage-public/plugin-instance@1.1.5
33
+
34
+ ## 1.0.56
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [c49c5a4aa]
39
+ - @pexip-engage-public/plugin-instance@1.1.4
40
+ - @pexip-engage-public/plugin-configuration-parser@1.2.1
14
41
 
15
42
  ## 1.0.55
16
43
 
@@ -1,4 +1,4 @@
1
- import type { JSConfig } from "@pexip-engage-public/plugin-configuration-parser";
1
+ import type { JSConfig } from "@pexip-engage-public/plugin/configuration-parser";
2
2
  export interface PexipEngagePluginContextProps extends NonNullable<JSConfig["config"]> {
3
3
  /**
4
4
  * The plugin entry point URL.
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext } from "react";
2
- const PexipEngagePluginContext = createContext({});
2
+ const PexipEngagePluginContext = createContext({ version: "1.0.0" });
3
3
  export function usePluginContext() {
4
4
  const ctx = useContext(PexipEngagePluginContext);
5
5
  return ctx;
@@ -1,4 +1,4 @@
1
- import type { PluginInstance } from "@pexip-engage-public/plugin-instance";
1
+ import type { PluginInstance } from "@pexip-engage-public/plugin/instance";
2
2
  import { type PexipEngagePluginContextProps } from "./PexipEngageContext.js";
3
3
  interface PexipEngagePluginProps extends PexipEngagePluginContextProps {
4
4
  onInstanceChange?: (instance: PluginInstance | null) => unknown;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,6 @@ export type { PexipEngagePluginContextProps } from "./PexipEngageContext.js";
2
2
  export { PexipEngagePluginProvider } from "./PexipEngageContext.js";
3
3
  export { PexipEngagePlugin } from "./PexipEngagePlugin.js";
4
4
  export { usePexipEngagePlugin } from "./usePexipEngagePlugin.js";
5
- export type { PluginInstance } from "@pexip-engage-public/plugin-instance";
6
- export { PEXIP_ENGAGE_PLUGIN_EVENT } from "@pexip-engage-public/plugin-instance";
5
+ export type { PluginInstance } from "@pexip-engage-public/plugin/instance";
6
+ export { PEXIP_ENGAGE_PLUGIN_EVENT } from "@pexip-engage-public/plugin/instance";
7
7
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { PexipEngagePluginProvider } from "./PexipEngageContext.js";
2
2
  export { PexipEngagePlugin } from "./PexipEngagePlugin.js";
3
3
  export { usePexipEngagePlugin } from "./usePexipEngagePlugin.js";
4
- export { PEXIP_ENGAGE_PLUGIN_EVENT } from "@pexip-engage-public/plugin-instance";
4
+ export { PEXIP_ENGAGE_PLUGIN_EVENT } from "@pexip-engage-public/plugin/instance";
@@ -1,4 +1,4 @@
1
- import { PluginStatic } from "@pexip-engage-public/plugin-instance";
1
+ import { PluginStatic } from "@pexip-engage-public/plugin/instance";
2
2
  interface UsePluginResult {
3
3
  Plugin: typeof PluginStatic | null;
4
4
  status: "pending" | "success" | "failed";
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useReducer } from "react";
2
- import { PEXIP_ENGAGE_PLUGIN_EVENT, PluginStatic, } from "@pexip-engage-public/plugin-instance";
2
+ import { PEXIP_ENGAGE_PLUGIN_EVENT, PluginStatic, } from "@pexip-engage-public/plugin/instance";
3
3
  import { usePluginContext } from "./PexipEngageContext.js";
4
4
  function createPlugin({ onError, src }) {
5
5
  const scriptEl = document.getElementById(src);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pexip-engage-public/plugin-react",
3
- "version": "2.0.0-canary-20231023080955",
3
+ "version": "2.0.0",
4
4
  "description": "React wrapper component for the Pexip Engage Plugin",
5
5
  "homepage": "https://github.com/skedify/frontend-mono/tree/develop/apps/plugin-remix/packages/plugin-react#readme",
6
6
  "bugs": {
@@ -20,9 +20,7 @@
20
20
  "sideEffects": false,
21
21
  "type": "module",
22
22
  "exports": {
23
- ".": {
24
- "import": "./dist/index.js"
25
- },
23
+ ".": "./dist/index.js",
26
24
  "./src/index.tsx": {
27
25
  "import": "./src/index.tsx"
28
26
  }
@@ -34,13 +32,12 @@
34
32
  ],
35
33
  "dependencies": {
36
34
  "deepmerge": "^4.3.1",
37
- "@pexip-engage-public/plugin-instance": "2.0.0-canary-20231023080955",
38
- "@pexip-engage-public/plugin-configuration-parser": "2.0.0-canary-20231023080955"
35
+ "@pexip-engage-public/plugin": "1.0.0"
39
36
  },
40
37
  "devDependencies": {
41
38
  "@eslint/eslintrc": "^2.1.2",
42
- "@pexip-engage/tsconfig": "0.0.10-canary-20231023080955",
43
- "eslint-config-pexip-engage": "0.0.40"
39
+ "@pexip-engage/tsconfig": "0.1.0",
40
+ "eslint-config-pexip-engage": "0.1.0"
44
41
  },
45
42
  "peerDependencies": {
46
43
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext } from "react";
2
- import type { JSConfig } from "@pexip-engage-public/plugin-configuration-parser";
2
+ import type { JSConfig } from "@pexip-engage-public/plugin/configuration-parser";
3
3
 
4
4
  export interface PexipEngagePluginContextProps extends NonNullable<JSConfig["config"]> {
5
5
  /**
@@ -9,7 +9,7 @@ export interface PexipEngagePluginContextProps extends NonNullable<JSConfig["con
9
9
  scriptSrc?: string;
10
10
  }
11
11
 
12
- const PexipEngagePluginContext = createContext<PexipEngagePluginContextProps>({});
12
+ const PexipEngagePluginContext = createContext<PexipEngagePluginContextProps>({ version: "1.0.0" });
13
13
 
14
14
  export function usePluginContext() {
15
15
  const ctx = useContext(PexipEngagePluginContext);
@@ -1,5 +1,5 @@
1
1
  import { isValidElement, useEffect, useRef, useState } from "react";
2
- import type { PluginInstance } from "@pexip-engage-public/plugin-instance";
2
+ import type { PluginInstance } from "@pexip-engage-public/plugin/instance";
3
3
 
4
4
  import { type PexipEngagePluginContextProps } from "./PexipEngageContext.js";
5
5
  import { usePexipEngagePlugin } from "./usePexipEngagePlugin.js";
package/src/index.tsx CHANGED
@@ -2,5 +2,5 @@ export type { PexipEngagePluginContextProps } from "./PexipEngageContext.js";
2
2
  export { PexipEngagePluginProvider } from "./PexipEngageContext.js";
3
3
  export { PexipEngagePlugin } from "./PexipEngagePlugin.js";
4
4
  export { usePexipEngagePlugin } from "./usePexipEngagePlugin.js";
5
- export type { PluginInstance } from "@pexip-engage-public/plugin-instance";
6
- export { PEXIP_ENGAGE_PLUGIN_EVENT } from "@pexip-engage-public/plugin-instance";
5
+ export type { PluginInstance } from "@pexip-engage-public/plugin/instance";
6
+ export { PEXIP_ENGAGE_PLUGIN_EVENT } from "@pexip-engage-public/plugin/instance";
@@ -3,7 +3,7 @@ import {
3
3
  PEXIP_ENGAGE_PLUGIN_EVENT,
4
4
  type PluginCustomEvent,
5
5
  PluginStatic,
6
- } from "@pexip-engage-public/plugin-instance";
6
+ } from "@pexip-engage-public/plugin/instance";
7
7
 
8
8
  import { usePluginContext } from "./PexipEngageContext.js";
9
9
 
package/dist/index.mjs DELETED
@@ -1,193 +0,0 @@
1
- // src/PexipEngageContext.ts
2
- import { createContext, useContext } from "react";
3
- var PexipEngagePluginContext = createContext({});
4
- function usePluginContext() {
5
- const ctx = useContext(PexipEngagePluginContext);
6
- return ctx;
7
- }
8
- var PexipEngagePluginProvider = PexipEngagePluginContext.Provider;
9
-
10
- // src/PexipEngagePlugin.tsx
11
- import { isValidElement, useEffect as useEffect3, useRef as useRef2, useState } from "react";
12
-
13
- // src/usePexipEngagePlugin.ts
14
- import { useEffect, useReducer } from "react";
15
- import {
16
- PEXIP_ENGAGE_PLUGIN_EVENT
17
- } from "@pexip-engage-public/plugin-instance";
18
- function createPlugin({ onError, src }) {
19
- const scriptEl = document.getElementById(src);
20
- if (!scriptEl) {
21
- const script = document.createElement("script");
22
- script.src = src;
23
- script.async = true;
24
- script.defer = true;
25
- script.id = src;
26
- script.onerror = () => {
27
- script.setAttribute("data-status", "error");
28
- onError();
29
- };
30
- document.body.appendChild(script);
31
- } else if (scriptEl.getAttribute("data-status") === "error") {
32
- onError();
33
- }
34
- }
35
- var initialState = { Plugin: null, status: "pending" };
36
- function reducer(state, action) {
37
- switch (action.type) {
38
- case "success":
39
- return { Plugin: action.instance, status: "success" };
40
- case "failed":
41
- return { Plugin: null, status: "failed" };
42
- default:
43
- throw new Error();
44
- }
45
- }
46
- function usePexipEngagePlugin(scriptSrc) {
47
- const ctx = usePluginContext();
48
- const [state, dispatch] = useReducer(reducer, initialState);
49
- const src = scriptSrc ?? ctx.scriptSrc;
50
- useEffect(() => {
51
- if (!src) {
52
- console.warn(
53
- "No scriptSrc was provided to PexipEngagePluginContext, or as prop to <PexipEngagePlugin />, skipping plugin initialization..."
54
- );
55
- dispatch({ type: "failed" });
56
- return;
57
- }
58
- if (window && document) {
59
- if (window.PexipEngage?.Plugin) {
60
- dispatch({ type: "success", instance: window.PexipEngage.Plugin });
61
- } else {
62
- let listener2 = function(event) {
63
- const pluginEvent = event;
64
- if (!window.PexipEngage)
65
- return;
66
- if (pluginEvent.detail.type === window.PexipEngage.Plugin.EVENT_INIT) {
67
- dispatch({ type: "success", instance: window.PexipEngage.Plugin });
68
- } else if (pluginEvent.detail.type === window.PexipEngage?.Plugin.EVENT_MISCONFIGURED) {
69
- dispatch({ type: "failed" });
70
- } else if (pluginEvent.detail.type === window.PexipEngage?.Plugin.EVENT_ERROR) {
71
- dispatch({ type: "failed" });
72
- }
73
- };
74
- var listener = listener2;
75
- document.addEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener2);
76
- createPlugin({ src, onError: () => dispatch({ type: "failed" }) });
77
- return () => document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener2);
78
- }
79
- }
80
- }, [src]);
81
- return state;
82
- }
83
-
84
- // src/usePluginConfiguration.ts
85
- import { useEffect as useEffect2, useRef } from "react";
86
- import deepmerge from "deepmerge";
87
- function usePluginConfiguration(overrideConfiguration) {
88
- const defaultConfiguration = usePluginContext();
89
- const resolvedConfiguration = deepmerge(defaultConfiguration, overrideConfiguration);
90
- return useMemoizedObject(resolvedConfiguration);
91
- }
92
- function useMemoizedObject(currentObj) {
93
- const prevResult = useRef(currentObj);
94
- const memoizedObj = replaceEqualDeep(prevResult.current, currentObj);
95
- useEffect2(() => {
96
- prevResult.current = memoizedObj;
97
- });
98
- return memoizedObj;
99
- }
100
- function replaceEqualDeep(a, b) {
101
- if (a === b) {
102
- return a;
103
- }
104
- const array = Array.isArray(a) && Array.isArray(b);
105
- if (array || isPlainObject(a) && isPlainObject(b)) {
106
- const aSize = array ? a.length : Object.keys(a).length;
107
- const bItems = array ? b : Object.keys(b);
108
- const bSize = bItems.length;
109
- const copy = array ? [] : {};
110
- let equalItems = 0;
111
- for (let i = 0; i < bSize; i++) {
112
- const key = array ? i : bItems[i];
113
- copy[key] = replaceEqualDeep(a[key], b[key]);
114
- if (copy[key] === a[key]) {
115
- equalItems++;
116
- }
117
- }
118
- return aSize === bSize && equalItems === aSize ? a : copy;
119
- }
120
- return b;
121
- }
122
- function isPlainObject(o) {
123
- if (!hasObjectPrototype(o)) {
124
- return false;
125
- }
126
- const ctor = o.constructor;
127
- if (typeof ctor === "undefined") {
128
- return true;
129
- }
130
- const prot = ctor.prototype;
131
- if (!hasObjectPrototype(prot)) {
132
- return false;
133
- }
134
- if (!prot.hasOwnProperty("isPrototypeOf")) {
135
- return false;
136
- }
137
- return true;
138
- }
139
- function hasObjectPrototype(o) {
140
- return Object.prototype.toString.call(o) === "[object Object]";
141
- }
142
-
143
- // src/PexipEngagePlugin.tsx
144
- import { jsx } from "react/jsx-runtime";
145
- function PexipEngagePlugin({
146
- className,
147
- fallback,
148
- id,
149
- onInstanceChange,
150
- scriptSrc,
151
- style,
152
- ...config
153
- }) {
154
- const { Plugin, status } = usePexipEngagePlugin(scriptSrc);
155
- const options = usePluginConfiguration(config);
156
- const containerRef = useRef2(null);
157
- const [instance, setInstance] = useState(null);
158
- useEffect3(() => {
159
- if (Plugin && containerRef.current) {
160
- const instance2 = new Plugin(containerRef.current, { config: options });
161
- setInstance(instance2);
162
- return () => {
163
- instance2.dispose();
164
- setInstance(null);
165
- };
166
- }
167
- }, [Plugin, options]);
168
- useEffect3(() => {
169
- onInstanceChange && onInstanceChange(instance);
170
- }, [instance, onInstanceChange]);
171
- if (status === "failed" && isValidElement(fallback)) {
172
- return fallback;
173
- }
174
- return /* @__PURE__ */ jsx(
175
- "div",
176
- {
177
- className,
178
- "data-pexip-auto-init": "false",
179
- id,
180
- ref: containerRef,
181
- style
182
- }
183
- );
184
- }
185
-
186
- // src/index.tsx
187
- import { PEXIP_ENGAGE_PLUGIN_EVENT as PEXIP_ENGAGE_PLUGIN_EVENT2 } from "@pexip-engage-public/plugin-instance";
188
- export {
189
- PEXIP_ENGAGE_PLUGIN_EVENT2 as PEXIP_ENGAGE_PLUGIN_EVENT,
190
- PexipEngagePlugin,
191
- PexipEngagePluginProvider,
192
- usePexipEngagePlugin
193
- };