refactor: Rename prop scrollToCenter and setScrollToCenter to scrollToContent and setScrollToContent respectively (#3261)

* refactor: Rename prop scrollToCenter and setScrollToCenter to scrollToContent and setScrollToContent respectively

* fix

* update changelog/readme

* fix
This commit is contained in:
Aakansha Doshi 2021-03-16 23:02:17 +05:30 committed by GitHub
parent e90e56452f
commit 052b73d95b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 14 deletions

View File

@ -271,7 +271,7 @@ export type ExcalidrawImperativeAPI = {
history: { history: {
clear: InstanceType<typeof App>["resetHistory"]; clear: InstanceType<typeof App>["resetHistory"];
}; };
setScrollToCenter: InstanceType<typeof App>["setScrollToCenter"]; setScrollToContent: InstanceType<typeof App>["setScrollToContent"];
getSceneElements: InstanceType<typeof App>["getSceneElements"]; getSceneElements: InstanceType<typeof App>["getSceneElements"];
getAppState: () => InstanceType<typeof App>["state"]; getAppState: () => InstanceType<typeof App>["state"];
readyPromise: ResolvablePromise<ExcalidrawImperativeAPI>; readyPromise: ResolvablePromise<ExcalidrawImperativeAPI>;
@ -330,7 +330,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
history: { history: {
clear: this.resetHistory, clear: this.resetHistory,
}, },
setScrollToCenter: this.setScrollToCenter, setScrollToContent: this.setScrollToContent,
getSceneElements: this.getSceneElements, getSceneElements: this.getSceneElements,
getAppState: () => this.state, getAppState: () => this.state,
} as const; } as const;
@ -685,7 +685,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
...scene.appState, ...scene.appState,
isLoading: false, isLoading: false,
}; };
if (initialData?.scrollToCenter) { if (initialData?.scrollToContent) {
scene.appState = { scene.appState = {
...scene.appState, ...scene.appState,
...calculateScrollCenter( ...calculateScrollCenter(
@ -1281,7 +1281,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
this.actionManager.executeAction(actionToggleStats); this.actionManager.executeAction(actionToggleStats);
}; };
setScrollToCenter = (remoteElements: readonly ExcalidrawElement[]) => { setScrollToContent = (remoteElements: readonly ExcalidrawElement[]) => {
this.setState({ this.setState({
...calculateScrollCenter( ...calculateScrollCenter(
getNonDeletedElements(remoteElements), getNonDeletedElements(remoteElements),

View File

@ -15,7 +15,7 @@ export interface ImportedDataState {
source?: string; source?: string;
elements?: DataState["elements"] | null; elements?: DataState["elements"] | null;
appState?: Partial<DataState["appState"]> | null; appState?: Partial<DataState["appState"]> | null;
scrollToCenter?: boolean; scrollToContent?: boolean;
} }
export interface LibraryData { export interface LibraryData {

View File

@ -259,7 +259,7 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
if (elements) { if (elements) {
scenePromise.resolve({ scenePromise.resolve({
elements, elements,
scrollToCenter: true, scrollToContent: true,
}); });
} }
} catch (error) { } catch (error) {
@ -313,7 +313,7 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
// noop if already resolved via init from firebase // noop if already resolved via init from firebase
scenePromise.resolve({ scenePromise.resolve({
elements: reconciledElements, elements: reconciledElements,
scrollToCenter: true, scrollToContent: true,
}); });
} }
break; break;
@ -454,7 +454,7 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
}: { init?: boolean; initFromSnapshot?: boolean } = {}, }: { init?: boolean; initFromSnapshot?: boolean } = {},
) => { ) => {
if (init || initFromSnapshot) { if (init || initFromSnapshot) {
this.excalidrawAPI.setScrollToCenter(elements); this.excalidrawAPI.setScrollToContent(elements);
} }
this.excalidrawAPI.updateScene({ this.excalidrawAPI.updateScene({

View File

@ -77,7 +77,7 @@ const initializeScene = async (opts: {
const initialData = importFromLocalStorage(); const initialData = importFromLocalStorage();
let scene: DataState & { scrollToCenter?: boolean } = await loadScene( let scene: DataState & { scrollToContent?: boolean } = await loadScene(
null, null,
null, null,
initialData, initialData,
@ -104,7 +104,7 @@ const initializeScene = async (opts: {
initialData, initialData,
); );
} }
scene.scrollToCenter = true; scene.scrollToContent = true;
if (!roomLinkData) { if (!roomLinkData) {
window.history.replaceState({}, APP_NAME, window.location.origin); window.history.replaceState({}, APP_NAME, window.location.origin);
} }

View File

@ -24,6 +24,8 @@ Please add the latest change on the top under the correct section.
### Refactor ### Refactor
- #### BREAKING CHANGE
- Rename prop `initialData.scrollToCenter` and `setScrollToCenter` API exposed via ref to `initialData.scrollToContent` and `setScrollToContent` respectively[#3261](https://github.com/excalidraw/excalidraw/pull/3261).
- Rename appearance to theme [#3237](https://github.com/excalidraw/excalidraw/pull/3237). - Rename appearance to theme [#3237](https://github.com/excalidraw/excalidraw/pull/3237).
#### BREAKING CHANGE #### BREAKING CHANGE
- Since `appState.appearance` is renamed to `appState.theme` so wherever `appState.appearance` including `initialData.appState.appearance` should be renamed to `appState.theme` and `initialData.appState.theme` respectively. If the `appearance` was persisted earlier, now it needs to passed as `theme`. - Since `appState.appearance` is renamed to `appState.theme` so wherever `appState.appearance` including `initialData.appState.appearance` should be renamed to `appState.theme` and `initialData.appState.theme` respectively. If the `appearance` was persisted earlier, now it needs to passed as `theme`.

View File

@ -417,7 +417,7 @@ This helps to load Excalidraw with `initialData`. It must be an object or a [pro
| --- | --- | --- | | --- | --- | --- |
| `elements` | [ExcalidrawElement[]](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78) | The elements with which Excalidraw should be mounted. | | `elements` | [ExcalidrawElement[]](https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78) | The elements with which Excalidraw should be mounted. |
| `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37) | The App state with which Excalidraw should be mounted. | | `appState` | [AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37) | The App state with which Excalidraw should be mounted. |
| `scrollToCenter` | boolean | This attribute implies whether to scroll to the nearest element to center once Excalidraw is mounted. By default, it will not scroll the nearest element to the center. Make sure you pass `initialData.appState.scrollX` and `initialData.appState.scrollY` when `scrollToCenter` is false so that scroll positions are retained | | `scrollToContent` | boolean | This attribute implies whether to scroll to the nearest element to center once Excalidraw is mounted. By default, it will not scroll the nearest element to the center. Make sure you pass `initialData.appState.scrollX` and `initialData.appState.scrollY` when `scrollToContent` is false so that scroll positions are retained |
```json ```json
{ {
@ -464,7 +464,7 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
| getSceneElements | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a></pre> | Returns all the elements excluding the deleted in the scene | | getSceneElements | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a></pre> | Returns all the elements excluding the deleted in the scene |
| getAppState | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37">AppState</a></pre> | Returns current appState | | getAppState | <pre> () => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37">AppState</a></pre> | Returns current appState |
| history | `{ clear: () => void }` | This is the history API. `history.clear()` will clear the history | | history | `{ clear: () => void }` | This is the history API. `history.clear()` will clear the history |
| setScrollToCenter | <pre> (<a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>) => void </pre> | sets the elements to center | | setScrollToContent | <pre> (<a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>) => void </pre> | Scroll to the nearest element to center |
#### `readyPromise` #### `readyPromise`

View File

@ -6,7 +6,7 @@ import { API } from "./helpers/api";
const { h } = window; const { h } = window;
describe("appState", () => { describe("appState", () => {
it("scroll-to-center on init works with non-zero offsets", async () => { it("scroll-to-content on init works with non-zero offsets", async () => {
const WIDTH = 600; const WIDTH = 600;
const HEIGHT = 700; const HEIGHT = 700;
const OFFSET_LEFT = 200; const OFFSET_LEFT = 200;
@ -30,7 +30,7 @@ describe("appState", () => {
height: ELEM_HEIGHT, height: ELEM_HEIGHT,
}), }),
], ],
scrollToCenter: true, scrollToContent: true,
}} }}
/>, />,
); );