@forge/react 10.8.0 → 10.9.0-next.1
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 +17 -0
- package/out/__test__/components/utils/replaceUnsupportedDocumentNodes.test.d.ts +2 -0
- package/out/__test__/components/utils/replaceUnsupportedDocumentNodes.test.d.ts.map +1 -0
- package/out/__test__/components/utils/replaceUnsupportedDocumentNodes.test.js +367 -0
- package/out/components/adf-renderer.d.ts +8 -0
- package/out/components/adf-renderer.d.ts.map +1 -0
- package/out/components/adf-renderer.js +12 -0
- package/out/components/index.d.ts +1 -6
- package/out/components/index.d.ts.map +1 -1
- package/out/components/index.js +3 -8
- package/out/components/ui-kit-components.d.ts +0 -1
- package/out/components/ui-kit-components.d.ts.map +1 -1
- package/out/components/utils/replaceUnsupportedDocumentNodes.d.ts +4 -0
- package/out/components/utils/replaceUnsupportedDocumentNodes.d.ts.map +1 -0
- package/out/components/utils/replaceUnsupportedDocumentNodes.js +45 -0
- package/out/index.d.ts +1 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -1
- package/package.json +5 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/out/__test__/createFrame.test.d.ts +0 -2
- package/out/__test__/createFrame.test.d.ts.map +0 -1
- package/out/__test__/createFrame.test.js +0 -33
- package/out/components/createFrame.d.ts +0 -5
- package/out/components/createFrame.d.ts.map +0 -1
- package/out/components/createFrame.js +0 -56
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFrame.test.d.ts","sourceRoot":"","sources":["../../src/__test__/createFrame.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
jest.mock('@forge/bridge', () => ({
|
|
6
|
-
events: {
|
|
7
|
-
emit: jest.fn(),
|
|
8
|
-
on: jest.fn()
|
|
9
|
-
}
|
|
10
|
-
}));
|
|
11
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
12
|
-
const components_1 = require("../components");
|
|
13
|
-
const reconcilerTestRenderer_1 = tslib_1.__importDefault(require("./reconcilerTestRenderer"));
|
|
14
|
-
const testUtils_1 = require("./testUtils");
|
|
15
|
-
describe('createFrame', () => {
|
|
16
|
-
let bridgeCalls = [];
|
|
17
|
-
beforeAll(async () => {
|
|
18
|
-
bridgeCalls = (0, testUtils_1.setupBridge)();
|
|
19
|
-
});
|
|
20
|
-
it('renders correct Frame ForgeDoc', async () => {
|
|
21
|
-
const TestFrame = (0, components_1.createFrame)('test-frame');
|
|
22
|
-
const Test = () => {
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: (0, jsx_runtime_1.jsx)(TestFrame, { propA: "hello" }) }));
|
|
24
|
-
};
|
|
25
|
-
await reconcilerTestRenderer_1.default.create((0, jsx_runtime_1.jsx)(Test, {}));
|
|
26
|
-
const forgeDoc = (0, testUtils_1.getLastBridgeCallForgeDoc)(bridgeCalls);
|
|
27
|
-
expect(forgeDoc).toHaveProperty('type', 'Root');
|
|
28
|
-
expect(forgeDoc).toHaveProperty('children[0].type', 'Frame');
|
|
29
|
-
expect(forgeDoc).toHaveProperty('children[0].props.resource', 'test-frame');
|
|
30
|
-
expect(forgeDoc).toHaveProperty('children[0].props.frameId', expect.any(String));
|
|
31
|
-
expect(forgeDoc).not.toHaveProperty('children[0].props.propA', expect.any(String));
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare type TArePropsEqual<TFrameProps extends Record<string, unknown>> = (prevProps: TFrameProps, nextProps: TFrameProps) => boolean;
|
|
3
|
-
declare const createFrame: <TFrameProps extends Record<string, unknown>>(resource: string, arePropsEqual?: TArePropsEqual<TFrameProps>) => React.FC<TFrameProps>;
|
|
4
|
-
export { createFrame };
|
|
5
|
-
//# sourceMappingURL=createFrame.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFrame.d.ts","sourceRoot":"","sources":["../../src/components/createFrame.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAYjD,aAAK,cAAc,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CACjE,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,WAAW,KACnB,OAAO,CAAC;AA2Bb,QAAA,MAAM,WAAW,0DACL,MAAM,uEA4BjB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createFrame = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
|
-
const bridge_1 = require("@forge/bridge");
|
|
8
|
-
const _1 = require(".");
|
|
9
|
-
const useFrameId = () => {
|
|
10
|
-
const frameId = (0, react_1.useRef)((0, uuid_1.v4)());
|
|
11
|
-
return frameId.current;
|
|
12
|
-
};
|
|
13
|
-
const frameEventKey = (eventKey, frameId) => `frame:${eventKey}:${frameId}`;
|
|
14
|
-
const EVENT_KEY_FRAME_PROPS = 'props';
|
|
15
|
-
const EVENT_KEY_FRAME_LOADED = 'loaded';
|
|
16
|
-
const arePropsEqualWithShallowCheck = (prevProps, nextProps) => {
|
|
17
|
-
// Checks if props have the same reference (for the case of initial render).
|
|
18
|
-
if (prevProps === nextProps) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
const prevKeys = Object.keys(prevProps);
|
|
22
|
-
const nextKeys = Object.keys(nextProps);
|
|
23
|
-
if (prevKeys.length !== nextKeys.length) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
for (const key of prevKeys) {
|
|
27
|
-
if (!Object.hasOwn(nextProps, key) || prevProps[key] !== nextProps[key]) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
};
|
|
33
|
-
const createFrame = (resource, arePropsEqual = arePropsEqualWithShallowCheck) => {
|
|
34
|
-
return (props) => {
|
|
35
|
-
const frameId = useFrameId();
|
|
36
|
-
const propsRef = (0, react_1.useRef)(props);
|
|
37
|
-
(0, react_1.useEffect)(() => {
|
|
38
|
-
const sub = bridge_1.events.on(frameEventKey(EVENT_KEY_FRAME_LOADED, frameId), ({ loaded }) => {
|
|
39
|
-
if (loaded) {
|
|
40
|
-
void bridge_1.events.emit(frameEventKey(EVENT_KEY_FRAME_PROPS, frameId), propsRef.current);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return () => {
|
|
44
|
-
void sub.then((s) => s.unsubscribe());
|
|
45
|
-
};
|
|
46
|
-
}, []);
|
|
47
|
-
(0, react_1.useEffect)(() => {
|
|
48
|
-
if (!arePropsEqual(propsRef.current, props)) {
|
|
49
|
-
propsRef.current = props;
|
|
50
|
-
void bridge_1.events.emit(frameEventKey(EVENT_KEY_FRAME_PROPS, frameId), props);
|
|
51
|
-
}
|
|
52
|
-
}, [props]);
|
|
53
|
-
return (0, jsx_runtime_1.jsx)(_1.Frame, { resource: resource, frameId: frameId });
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.createFrame = createFrame;
|