@embeddable.com/sdk-react 0.0.14 → 0.0.16
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/lib/{embedEditor.d.ts → embedControl.d.ts} +1 -1
- package/lib/index.cjs.js +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +2 -2
- package/lib/index.umd.js +2 -2
- package/package.json +6 -1
- package/scripts/generate.js +4 -34
- package/.turbo/turbo-build.log +0 -13
- package/CHANGELOG.md +0 -97
- package/rollup.config.mjs +0 -36
- package/src/embedComponent.tsx +0 -40
- package/src/embedEditor.tsx +0 -57
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -20
|
@@ -9,7 +9,7 @@ export type EmbeddableEvent<T> = {
|
|
|
9
9
|
value: T;
|
|
10
10
|
};
|
|
11
11
|
type Setter<T> = (value: T) => void;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function embedControl<T>(InnerComponent: React.ComponentType, config: Config<T>): {
|
|
13
13
|
({ editorId, initialValue }: {
|
|
14
14
|
editorId: any;
|
|
15
15
|
initialValue: any;
|
package/lib/index.cjs.js
CHANGED
|
@@ -88,7 +88,7 @@ function embedComponent(InnerComponent, config) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
var EVENT_NAME = "embeddable:editor:changed";
|
|
91
|
-
function
|
|
91
|
+
function embedControl(InnerComponent, config) {
|
|
92
92
|
var _a;
|
|
93
93
|
function EmbeddableWrapper(_a) {
|
|
94
94
|
var editorId = _a.editorId, initialValue = _a.initialValue;
|
|
@@ -124,4 +124,4 @@ function embedEditor(InnerComponent, config) {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
exports.embedComponent = embedComponent;
|
|
127
|
-
exports.
|
|
127
|
+
exports.embedControl = embedControl;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { embedComponent } from './embedComponent';
|
|
2
|
-
export {
|
|
2
|
+
export { embedControl } from './embedControl';
|
package/lib/index.esm.js
CHANGED
|
@@ -67,7 +67,7 @@ function embedComponent(InnerComponent, config) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
var EVENT_NAME = "embeddable:editor:changed";
|
|
70
|
-
function
|
|
70
|
+
function embedControl(InnerComponent, config) {
|
|
71
71
|
var _a;
|
|
72
72
|
function EmbeddableWrapper(_a) {
|
|
73
73
|
var editorId = _a.editorId, initialValue = _a.initialValue;
|
|
@@ -102,4 +102,4 @@ function embedEditor(InnerComponent, config) {
|
|
|
102
102
|
return EmbeddableWrapper;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export { embedComponent,
|
|
105
|
+
export { embedComponent, embedControl };
|
package/lib/index.umd.js
CHANGED
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
var EVENT_NAME = "embeddable:editor:changed";
|
|
111
|
-
function
|
|
111
|
+
function embedControl(InnerComponent, config) {
|
|
112
112
|
var _a;
|
|
113
113
|
function EmbeddableWrapper(_a) {
|
|
114
114
|
var editorId = _a.editorId, initialValue = _a.initialValue;
|
|
@@ -144,6 +144,6 @@
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
exports.embedComponent = embedComponent;
|
|
147
|
-
exports.
|
|
147
|
+
exports.embedControl = embedControl;
|
|
148
148
|
|
|
149
149
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/sdk-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Embeddable SDK React plugin/module responsible for React components bundling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"embeddable",
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"embeddable-react": "bin/embeddable-react"
|
|
24
24
|
},
|
|
25
25
|
"author": "Oleg Kapustin <oleg@trevor.io>",
|
|
26
|
+
"files": [
|
|
27
|
+
"lib/",
|
|
28
|
+
"scripts/",
|
|
29
|
+
"templates/"
|
|
30
|
+
],
|
|
26
31
|
"license": "MIT",
|
|
27
32
|
"peerDependencies": {
|
|
28
33
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
package/scripts/generate.js
CHANGED
|
@@ -2,7 +2,7 @@ const fs = require("fs/promises");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const vite = require("vite");
|
|
4
4
|
const viteReactPlugin = require('@vitejs/plugin-react');
|
|
5
|
-
const core = require("@embeddable.com/sdk-core/scripts
|
|
5
|
+
const core = require("@embeddable.com/sdk-core/scripts");
|
|
6
6
|
|
|
7
7
|
process.on('message', async ({ ctx }) => {
|
|
8
8
|
await generate(ctx);
|
|
@@ -10,8 +10,10 @@ process.on('message', async ({ ctx }) => {
|
|
|
10
10
|
process.exit();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
const EMB_FILE_REGEX = /^(.*)\.emb\.[jt]s$/;
|
|
14
|
+
|
|
13
15
|
async function generate(ctx) {
|
|
14
|
-
const filesList = await findEmbFiles(ctx.client.srcDir);
|
|
16
|
+
const filesList = await core.findEmbFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
15
17
|
|
|
16
18
|
await injectImports(ctx, filesList);
|
|
17
19
|
|
|
@@ -65,35 +67,3 @@ async function injectImports(ctx, filesList) {
|
|
|
65
67
|
content.replace(REPLACE_TOKEN, imports)
|
|
66
68
|
);
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const EMB_FILE_REGEX = /^(.*)\.emb\.(j|t)s$/;
|
|
71
|
-
|
|
72
|
-
async function findEmbFiles (initialSrcDir) {
|
|
73
|
-
const filesList = [];
|
|
74
|
-
|
|
75
|
-
async function findEmbFilesRec(srcDir) {
|
|
76
|
-
const allFiles = await fs.readdir(srcDir);
|
|
77
|
-
|
|
78
|
-
for (const file of allFiles) {
|
|
79
|
-
const filePath = path.join(srcDir, file)
|
|
80
|
-
|
|
81
|
-
const status = await fs.lstat(filePath);
|
|
82
|
-
|
|
83
|
-
if (status.isDirectory()) {
|
|
84
|
-
await findEmbFilesRec(filePath)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const fileName = file.match(EMB_FILE_REGEX);
|
|
88
|
-
|
|
89
|
-
if (fileName) {
|
|
90
|
-
filesList.push([fileName[1], filePath]);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
await findEmbFilesRec(initialSrcDir);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return filesList;
|
|
99
|
-
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @embeddable.com/sdk-react@0.0.14 build
|
|
3
|
-
> rollup -c
|
|
4
|
-
|
|
5
|
-
(node:1891) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
|
|
6
|
-
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
7
|
-
(node:1891) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
|
|
8
|
-
[36m
|
|
9
|
-
[1m./src/index.ts[22m → [1mlib/index.umd.js[22m...[39m
|
|
10
|
-
[32mcreated [1mlib/index.umd.js[22m in [1m2.4s[22m[39m
|
|
11
|
-
[36m
|
|
12
|
-
[1m./src/index.ts[22m → [1mlib/index.cjs.js, lib/index.esm.js[22m...[39m
|
|
13
|
-
[32mcreated [1mlib/index.cjs.js, lib/index.esm.js[22m in [1m1.3s[22m[39m
|
package/CHANGELOG.md
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# @embeddable.com/sdk-react
|
|
2
|
-
|
|
3
|
-
## 0.0.14
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 7f5bd51: Fix dependencies.
|
|
8
|
-
- Updated dependencies [7f5bd51]
|
|
9
|
-
- @embeddable.com/sdk-core@0.0.13
|
|
10
|
-
|
|
11
|
-
## 0.0.13
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- 1137dbd: Fix import.
|
|
16
|
-
|
|
17
|
-
## 0.0.12
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- c8791d9: Improve publishing.
|
|
22
|
-
- Updated dependencies [c8791d9]
|
|
23
|
-
- @embeddable.com/sdk-core@0.0.10
|
|
24
|
-
|
|
25
|
-
## 0.0.11
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- 9d238b4: Fix loadData.
|
|
30
|
-
- Updated dependencies [9d238b4]
|
|
31
|
-
- @embeddable.com/sdk-core@0.0.7
|
|
32
|
-
|
|
33
|
-
## 0.0.10
|
|
34
|
-
|
|
35
|
-
### Patch Changes
|
|
36
|
-
|
|
37
|
-
- 46f8ccb: Fix import.
|
|
38
|
-
- Updated dependencies [46f8ccb]
|
|
39
|
-
- @embeddable.com/sdk-core@0.0.6
|
|
40
|
-
|
|
41
|
-
## 0.0.9
|
|
42
|
-
|
|
43
|
-
### Patch Changes
|
|
44
|
-
|
|
45
|
-
- 124ff74: Move loadData to core. Add axios.
|
|
46
|
-
- Updated dependencies [124ff74]
|
|
47
|
-
- @embeddable.com/sdk-core@0.0.5
|
|
48
|
-
|
|
49
|
-
## 0.0.8
|
|
50
|
-
|
|
51
|
-
### Patch Changes
|
|
52
|
-
|
|
53
|
-
- ce832b1: Add package description and keywords.
|
|
54
|
-
- Updated dependencies [ce832b1]
|
|
55
|
-
- @embeddable.com/sdk-core@0.0.3
|
|
56
|
-
|
|
57
|
-
## 0.0.7
|
|
58
|
-
|
|
59
|
-
### Patch Changes
|
|
60
|
-
|
|
61
|
-
- 8a627a6: Adjust cli messages.
|
|
62
|
-
|
|
63
|
-
## 0.0.6
|
|
64
|
-
|
|
65
|
-
### Patch Changes
|
|
66
|
-
|
|
67
|
-
- Move generate back to child process.
|
|
68
|
-
|
|
69
|
-
## 0.0.5
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- Fix core import.
|
|
74
|
-
|
|
75
|
-
## 0.0.4
|
|
76
|
-
|
|
77
|
-
### Patch Changes
|
|
78
|
-
|
|
79
|
-
- Run generate in the main thread.
|
|
80
|
-
|
|
81
|
-
## 0.0.3
|
|
82
|
-
|
|
83
|
-
### Patch Changes
|
|
84
|
-
|
|
85
|
-
- Add child process error log.
|
|
86
|
-
|
|
87
|
-
## 0.0.2
|
|
88
|
-
|
|
89
|
-
### Patch Changes
|
|
90
|
-
|
|
91
|
-
- Fix sdk-core dependency.
|
|
92
|
-
|
|
93
|
-
## 0.0.1
|
|
94
|
-
|
|
95
|
-
### Patch Changes
|
|
96
|
-
|
|
97
|
-
- First publish attempt.
|
package/rollup.config.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import typescript from '@rollup/plugin-typescript';
|
|
2
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
-
import replace from '@rollup/plugin-replace';
|
|
5
|
-
import pkg from './package.json' assert { type: 'json' };
|
|
6
|
-
|
|
7
|
-
export default [
|
|
8
|
-
{
|
|
9
|
-
input: './src/index.ts',
|
|
10
|
-
output: {
|
|
11
|
-
name: 'embeddableSdkReact',
|
|
12
|
-
file: pkg.browser,
|
|
13
|
-
format: 'umd'
|
|
14
|
-
},
|
|
15
|
-
plugins: [
|
|
16
|
-
replace({
|
|
17
|
-
preventAssignment: true,
|
|
18
|
-
values: {
|
|
19
|
-
'process.env.NODE_ENV': JSON.stringify('production')
|
|
20
|
-
}
|
|
21
|
-
}),
|
|
22
|
-
resolve(),
|
|
23
|
-
commonjs(),
|
|
24
|
-
typescript()
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
input: './src/index.ts',
|
|
29
|
-
external: Object.keys(pkg.peerDependencies),
|
|
30
|
-
output: [
|
|
31
|
-
{ file: pkg.main, format: 'cjs' },
|
|
32
|
-
{ file: pkg.module, format: 'es' }
|
|
33
|
-
],
|
|
34
|
-
plugins: [typescript()]
|
|
35
|
-
}
|
|
36
|
-
]
|
package/src/embedComponent.tsx
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
type WrapperProps = {
|
|
4
|
-
propsUpdateListener: HTMLElement
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const EVENT_NAME = 'embeddable-event:update-props';
|
|
8
|
-
|
|
9
|
-
// TODO: define config type.
|
|
10
|
-
export type Config = {
|
|
11
|
-
extendedProps?: (props: any) => any
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function embedComponent(InnerComponent: React.ComponentType, config: Config) {
|
|
15
|
-
function EmbeddableWrapper({propsUpdateListener, ...props}: WrapperProps) {
|
|
16
|
-
const [propsProxy, setProps] = React.useState(props);
|
|
17
|
-
|
|
18
|
-
const propsUpdateEventHandler = ({ detail }: CustomEvent<typeof propsProxy>) => setProps(detail);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
React.useEffect(() => {
|
|
22
|
-
propsUpdateListener.addEventListener(EVENT_NAME, propsUpdateEventHandler);
|
|
23
|
-
|
|
24
|
-
return () => propsUpdateListener.removeEventListener(EVENT_NAME, propsUpdateEventHandler);
|
|
25
|
-
}, []);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const extendedProps = React.useMemo(
|
|
29
|
-
() => config?.extendedProps?.(propsProxy),
|
|
30
|
-
[propsProxy, config?.extendedProps]
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
return <InnerComponent {...propsProxy} {...extendedProps}/>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
EmbeddableWrapper.displayName = `embedded(${InnerComponent.displayName ?? 'Component'})`;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return EmbeddableWrapper;
|
|
40
|
-
}
|
package/src/embedEditor.tsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
export type Config<T> = {
|
|
4
|
-
inputs: any;
|
|
5
|
-
events: Record<string, EmbeddableEventHandler<T>>
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type EmbeddableEventHandler<T> = (value: T, setter: Setter<T>) => void;
|
|
9
|
-
|
|
10
|
-
export type EmbeddableEvent<T> = {
|
|
11
|
-
editorId: string;
|
|
12
|
-
value: T;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type Setter<T> = (value: T) => void;
|
|
16
|
-
|
|
17
|
-
const EVENT_NAME = "embeddable:editor:changed";
|
|
18
|
-
|
|
19
|
-
export function embedEditor<T>(InnerComponent: React.ComponentType, config: Config<T>) {
|
|
20
|
-
|
|
21
|
-
function EmbeddableWrapper({editorId, initialValue}) {
|
|
22
|
-
|
|
23
|
-
const [componentState, setComponentState] = React.useState(initialValue);
|
|
24
|
-
|
|
25
|
-
const createEvent = (value: T) => {
|
|
26
|
-
|
|
27
|
-
const event = new CustomEvent<EmbeddableEvent<T>>(EVENT_NAME, {
|
|
28
|
-
bubbles: false,
|
|
29
|
-
detail: {
|
|
30
|
-
editorId,
|
|
31
|
-
value
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
window.dispatchEvent(event);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const events = config.events;
|
|
38
|
-
const eventProps: Record<string, (value: T) => void> = {};
|
|
39
|
-
|
|
40
|
-
for (const event in events) {
|
|
41
|
-
if (events.hasOwnProperty(event)) {
|
|
42
|
-
let eventFunction = events[event];
|
|
43
|
-
eventProps[event] = (value: T) => {
|
|
44
|
-
eventFunction(value, setComponentState)
|
|
45
|
-
createEvent(value)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return <InnerComponent {...eventProps} {...config.inputs(componentState)} />;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
EmbeddableWrapper.displayName = `embedded(${InnerComponent.displayName ?? 'Editor'})`;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return EmbeddableWrapper;
|
|
57
|
-
}
|
package/src/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src/**/*"],
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"target": "es5",
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"jsx": "react",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"outDir": "lib",
|
|
10
|
-
"lib": [
|
|
11
|
-
"DOM",
|
|
12
|
-
"DOM.Iterable",
|
|
13
|
-
"ESNext"
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
"exclude": [
|
|
17
|
-
"node_modules",
|
|
18
|
-
"lib"
|
|
19
|
-
]
|
|
20
|
-
}
|