@frontify/guideline-blocks-settings 0.31.4 → 0.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontify/guideline-blocks-settings",
3
- "version": "0.31.4",
3
+ "version": "0.32.0",
4
4
  "description": "Provides types and helpers for the guideline block development",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.umd.js",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "exports": {
18
18
  ".": {
19
+ "types": "./dist/index.d.ts",
19
20
  "import": "./dist/index.es.js",
20
21
  "require": "./dist/index.umd.js"
21
22
  },
@@ -65,9 +65,15 @@ export const LinkInput = ({
65
65
  <div className="tw-mt-3">
66
66
  <LinkSelector
67
67
  url={url}
68
- appBridge={appBridge}
69
68
  onUrlChange={onUrlChange}
70
69
  buttonSize={buttonSize ?? ButtonSize.Medium}
70
+ getAllDocuments={() => appBridge.getAllDocuments()}
71
+ getDocumentPagesByDocumentId={(documentId) =>
72
+ appBridge.getDocumentPagesByDocumentId(documentId)
73
+ }
74
+ getDocumentSectionsByDocumentPageId={(documentPageId) =>
75
+ appBridge.getDocumentSectionsByDocumentPageId(documentPageId)
76
+ }
71
77
  />
72
78
  </div>
73
79
  )}
@@ -1,6 +1,6 @@
1
1
  /* (c) Copyright Frontify Ltd., all rights reserved. */
2
2
 
3
- import type { AppBridgeBlock, AppBridgeTheme } from '@frontify/app-bridge';
3
+ import type { DocumentPage, DocumentSection } from '@frontify/app-bridge';
4
4
  import { useEffect, useState } from 'react';
5
5
  import { PageLinks } from './PageLinks';
6
6
  import { IconColorFan16, merge } from '@frontify/fondue';
@@ -12,18 +12,20 @@ type DocumentLinkProps = {
12
12
  title: string;
13
13
  permanentLink: string;
14
14
  };
15
- appBridge: AppBridgeBlock | AppBridgeTheme;
16
15
  selectedUrl: string;
17
16
  onSelectUrl: (url: string) => void;
18
17
  itemsToExpandInitially: InitiallyExpandedItems;
18
+ getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;
19
+ getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;
19
20
  };
20
21
 
21
22
  export const DocumentLink = ({
22
23
  document,
23
- appBridge,
24
24
  selectedUrl,
25
25
  onSelectUrl,
26
26
  itemsToExpandInitially,
27
+ getDocumentSectionsByDocumentPageId,
28
+ getDocumentPagesByDocumentId,
27
29
  }: DocumentLinkProps) => {
28
30
  const [isExpanded, setIsExpanded] = useState(document.id === itemsToExpandInitially.documentId);
29
31
  const isActive = document.permanentLink === selectedUrl;
@@ -66,11 +68,12 @@ export const DocumentLink = ({
66
68
  </button>
67
69
  {isExpanded && (
68
70
  <PageLinks
69
- appBridge={appBridge}
70
71
  documentId={document.id}
71
72
  selectedUrl={selectedUrl}
72
73
  onSelectUrl={onSelectUrl}
73
74
  itemsToExpandInitially={itemsToExpandInitially}
75
+ getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}
76
+ getDocumentPagesByDocumentId={getDocumentPagesByDocumentId}
74
77
  />
75
78
  )}
76
79
  </>
@@ -1,18 +1,26 @@
1
1
  /* (c) Copyright Frontify Ltd., all rights reserved. */
2
2
 
3
- import type { AppBridgeBlock, AppBridgeTheme, Document } from '@frontify/app-bridge';
3
+ import type { Document, DocumentPage, DocumentSection } from '@frontify/app-bridge';
4
4
  import { ReactElement, useEffect, useState } from 'react';
5
5
  import { DocumentLink } from './DocumentLink';
6
6
  import { LoadingIndicator } from './LoadingIndicator';
7
7
  import { InitiallyExpandedItems } from '../';
8
8
 
9
9
  type DocumentLinksProps = {
10
- appBridge: AppBridgeBlock | AppBridgeTheme;
11
10
  selectedUrl: string;
12
11
  onSelectUrl: (url: string) => void;
12
+ getAllDocuments: () => Promise<Document[]>;
13
+ getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;
14
+ getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;
13
15
  };
14
16
 
15
- export const DocumentLinks = ({ appBridge, selectedUrl, onSelectUrl }: DocumentLinksProps): ReactElement => {
17
+ export const DocumentLinks = ({
18
+ selectedUrl,
19
+ onSelectUrl,
20
+ getAllDocuments,
21
+ getDocumentPagesByDocumentId,
22
+ getDocumentSectionsByDocumentPageId,
23
+ }: DocumentLinksProps): ReactElement => {
16
24
  const [isLoading, setIsLoading] = useState(true);
17
25
  const [documents, setDocuments] = useState<Document[]>([]);
18
26
  const [itemsToExpandInitially, setItemsToExpandInitially] = useState<InitiallyExpandedItems>({
@@ -32,8 +40,7 @@ export const DocumentLinks = ({ appBridge, selectedUrl, onSelectUrl }: DocumentL
32
40
  }, [documentArray.length]);
33
41
 
34
42
  useEffect(() => {
35
- appBridge
36
- .getAllDocuments()
43
+ getAllDocuments()
37
44
  .then((_documents) => {
38
45
  setDocuments(_documents);
39
46
  })
@@ -52,8 +59,7 @@ export const DocumentLinks = ({ appBridge, selectedUrl, onSelectUrl }: DocumentL
52
59
  return itemsToExpand;
53
60
  }
54
61
  for (const document of documentArray) {
55
- const pages = await appBridge.getDocumentPagesByDocumentId(document.id);
56
- appBridge.getAllDocuments();
62
+ const pages = await getDocumentPagesByDocumentId(document.id);
57
63
  const pagesArray = [...pages.values()];
58
64
  const selectedUrlIsPage = !!pagesArray.find((page) => page.permanentLink === selectedUrl);
59
65
  if (selectedUrlIsPage) {
@@ -61,7 +67,7 @@ export const DocumentLinks = ({ appBridge, selectedUrl, onSelectUrl }: DocumentL
61
67
  return itemsToExpand;
62
68
  }
63
69
  for (const page of pagesArray) {
64
- const sections = await appBridge.getDocumentSectionsByDocumentPageId(page.id);
70
+ const sections = await getDocumentSectionsByDocumentPageId(page.id);
65
71
  const sectionsArray = [...sections.values()];
66
72
  const selectedUrlIsSection = !!sectionsArray.find((section) => section.permanentLink === selectedUrl);
67
73
  if (selectedUrlIsSection) {
@@ -83,10 +89,11 @@ export const DocumentLinks = ({ appBridge, selectedUrl, onSelectUrl }: DocumentL
83
89
  <DocumentLink
84
90
  key={document.id}
85
91
  document={document}
86
- appBridge={appBridge}
87
92
  selectedUrl={selectedUrl}
88
93
  onSelectUrl={onSelectUrl}
89
94
  itemsToExpandInitially={itemsToExpandInitially}
95
+ getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}
96
+ getDocumentPagesByDocumentId={getDocumentPagesByDocumentId}
90
97
  />
91
98
  );
92
99
  })}
@@ -5,7 +5,6 @@ import {
5
5
  DocumentPageApiDummy,
6
6
  DocumentSectionApiDummy,
7
7
  getAppBridgeBlockStub,
8
- withAppBridgeBlockStubs,
9
8
  } from '@frontify/app-bridge';
10
9
  import { mount } from 'cypress/react18';
11
10
  import { LinkSelector } from './LinkSelector';
@@ -37,8 +36,16 @@ const apiSections = [
37
36
 
38
37
  describe('Link Selector', () => {
39
38
  it('renders the link selector button', () => {
40
- const [LinkSelectorWithStubs] = withAppBridgeBlockStubs(LinkSelector, {});
41
- mount(<LinkSelectorWithStubs url="" onUrlChange={cy.stub()} />);
39
+ const appBridge = getAppBridgeBlockStub();
40
+ mount(
41
+ <LinkSelector
42
+ getAllDocuments={appBridge.getAllDocuments}
43
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
44
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
45
+ url=""
46
+ onUrlChange={cy.stub()}
47
+ />,
48
+ );
42
49
  cy.get(LinkSelectorSelector).should('exist');
43
50
  });
44
51
 
@@ -50,7 +57,15 @@ describe('Link Selector', () => {
50
57
  (appBridge.getDocumentGroups as SinonStub) = cy.stub().returns([]);
51
58
  (appBridge.getAllDocuments as SinonStub) = cy.stub().returns(Promise.resolve(apiDocuments));
52
59
 
53
- mount(<LinkSelector appBridge={appBridge} url="" onUrlChange={cy.stub()} />);
60
+ mount(
61
+ <LinkSelector
62
+ getAllDocuments={appBridge.getAllDocuments}
63
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
64
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
65
+ url=""
66
+ onUrlChange={cy.stub()}
67
+ />,
68
+ );
54
69
  cy.get(LinkSelectorButtonSelector).click();
55
70
  cy.get(LinkSelectorModalSelector).should('exist');
56
71
  });
@@ -62,7 +77,15 @@ describe('Link Selector', () => {
62
77
  (appBridge.getDocumentGroups as SinonStub) = cy.stub().returns([]);
63
78
  (appBridge.getAllDocuments as SinonStub) = cy.stub().returns(Promise.resolve(apiDocuments));
64
79
 
65
- mount(<LinkSelector appBridge={appBridge} url="" onUrlChange={cy.stub()} />);
80
+ mount(
81
+ <LinkSelector
82
+ getAllDocuments={appBridge.getAllDocuments}
83
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
84
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
85
+ url=""
86
+ onUrlChange={cy.stub()}
87
+ />,
88
+ );
66
89
  cy.get(LinkSelectorButtonSelector).click();
67
90
  cy.get(DocumentLinkSelector).should('have.length', 2);
68
91
  });
@@ -77,7 +100,15 @@ describe('Link Selector', () => {
77
100
  (appBridge.getDocumentPagesByDocumentId as SinonStub) = cy.stub().returns(Promise.resolve(apiPages));
78
101
  (appBridge.getDocumentSectionsByDocumentPageId as SinonStub) = cy.stub().returns(Promise.resolve(apiSections));
79
102
 
80
- mount(<LinkSelector appBridge={appBridge} url="" onUrlChange={cy.stub()} />);
103
+ mount(
104
+ <LinkSelector
105
+ getAllDocuments={appBridge.getAllDocuments}
106
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
107
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
108
+ url=""
109
+ onUrlChange={cy.stub()}
110
+ />,
111
+ );
81
112
  cy.get(LinkSelectorButtonSelector).click();
82
113
  cy.get(DocumentLinkSelector).eq(0).find(DocumentTreeItemToggleSelector).click();
83
114
  cy.get(PageLinkSelector).should('have.length', 3);
@@ -92,7 +123,15 @@ describe('Link Selector', () => {
92
123
  (appBridge.getDocumentPagesByDocumentId as SinonStub) = cy.stub().returns(Promise.resolve(apiPages));
93
124
  (appBridge.getDocumentSectionsByDocumentPageId as SinonStub) = cy.stub().returns(Promise.resolve(apiSections));
94
125
 
95
- mount(<LinkSelector appBridge={appBridge} url="" onUrlChange={cy.stub()} />);
126
+ mount(
127
+ <LinkSelector
128
+ getAllDocuments={appBridge.getAllDocuments}
129
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
130
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
131
+ url=""
132
+ onUrlChange={cy.stub()}
133
+ />,
134
+ );
96
135
  cy.get(LinkSelectorButtonSelector).click();
97
136
  cy.get(DocumentLinkSelector).eq(0).find(DocumentTreeItemToggleSelector).click();
98
137
  cy.get(PageLinkSelector).eq(0).find('button').click();
@@ -108,7 +147,15 @@ describe('Link Selector', () => {
108
147
  (appBridge.getDocumentPagesByDocumentId as SinonStub) = cy.stub().returns(Promise.resolve(apiPages));
109
148
  (appBridge.getDocumentSectionsByDocumentPageId as SinonStub) = cy.stub().returns(Promise.resolve(apiSections));
110
149
 
111
- mount(<LinkSelector appBridge={appBridge} url="/7" onUrlChange={cy.stub()} />);
150
+ mount(
151
+ <LinkSelector
152
+ getAllDocuments={appBridge.getAllDocuments}
153
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
154
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
155
+ url="/7"
156
+ onUrlChange={cy.stub().as('urlChange')}
157
+ />,
158
+ );
112
159
  cy.get(LinkSelectorButtonSelector).click();
113
160
  cy.get(SectionLinkSelector).should('have.length', 4);
114
161
  });
@@ -122,7 +169,15 @@ describe('Link Selector', () => {
122
169
  (appBridge.getDocumentPagesByDocumentId as SinonStub) = cy.stub().returns(Promise.resolve(apiPages));
123
170
  (appBridge.getDocumentSectionsByDocumentPageId as SinonStub) = cy.stub().returns(Promise.resolve(apiSections));
124
171
 
125
- mount(<LinkSelector appBridge={appBridge} url="" onUrlChange={cy.stub().as('urlChange')} />);
172
+ mount(
173
+ <LinkSelector
174
+ getAllDocuments={appBridge.getAllDocuments}
175
+ getDocumentPagesByDocumentId={appBridge.getDocumentPagesByDocumentId}
176
+ getDocumentSectionsByDocumentPageId={appBridge.getDocumentSectionsByDocumentPageId}
177
+ url=""
178
+ onUrlChange={cy.stub().as('urlChange')}
179
+ />,
180
+ );
126
181
  cy.get(LinkSelectorButtonSelector).click();
127
182
  cy.get(DocumentLinkSelector).should('have.length', 2);
128
183
  cy.realPress('Tab');
@@ -1,23 +1,27 @@
1
1
  /* (c) Copyright Frontify Ltd., all rights reserved. */
2
2
 
3
- import type { AppBridgeBlock, AppBridgeTheme } from '@frontify/app-bridge';
3
+ import type { Document, DocumentPage, DocumentSection } from '@frontify/app-bridge';
4
4
  import { Button, ButtonEmphasis, ButtonSize, ButtonStyle, ButtonType, IconLink, Modal } from '@frontify/fondue';
5
5
  import { useOverlayTriggerState } from '@react-stately/overlays';
6
6
  import { KeyboardEvent, ReactElement, useEffect, useState } from 'react';
7
7
  import { DocumentLinks } from './DocumentLinks';
8
8
 
9
9
  type LinkSelectorProps = {
10
- appBridge: AppBridgeBlock | AppBridgeTheme;
11
10
  url: string;
12
11
  onUrlChange?: (value: string) => void;
13
12
  buttonSize?: ButtonSize;
13
+ getAllDocuments: () => Promise<Document[]>;
14
+ getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;
15
+ getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;
14
16
  };
15
17
 
16
18
  export const LinkSelector = ({
17
- appBridge,
18
19
  url,
19
20
  onUrlChange,
20
21
  buttonSize = ButtonSize.Medium,
22
+ getAllDocuments,
23
+ getDocumentPagesByDocumentId,
24
+ getDocumentSectionsByDocumentPageId,
21
25
  }: LinkSelectorProps): ReactElement => {
22
26
  const { open: openLinkTree, isOpen: isLinkTreeOpen, close: closeLinkTree } = useOverlayTriggerState({});
23
27
  const [selectedUrl, setSelectedUrl] = useState<string>(url);
@@ -58,7 +62,13 @@ export const LinkSelector = ({
58
62
  <Modal zIndex={1001} onClose={() => closeLinkTree()} isOpen={isLinkTreeOpen} isDismissable>
59
63
  <Modal.Header title="Select internal link" />
60
64
  <Modal.Body>
61
- <DocumentLinks appBridge={appBridge} selectedUrl={selectedUrl} onSelectUrl={onSelectUrl} />
65
+ <DocumentLinks
66
+ selectedUrl={selectedUrl}
67
+ onSelectUrl={onSelectUrl}
68
+ getAllDocuments={getAllDocuments}
69
+ getDocumentPagesByDocumentId={getDocumentPagesByDocumentId}
70
+ getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}
71
+ />
62
72
  </Modal.Body>
63
73
  <Modal.Footer
64
74
  buttons={[
@@ -1,12 +1,12 @@
1
1
  /* (c) Copyright Frontify Ltd., all rights reserved. */
2
2
 
3
- import { AppBridgeBlock, AppBridgeTheme, useDocumentSection } from '@frontify/app-bridge';
3
+ import { type DocumentSection } from '@frontify/app-bridge';
4
4
  import { merge } from '@frontify/fondue';
5
5
  import { useEffect, useState } from 'react';
6
6
  import { InitiallyExpandedItems } from '../';
7
7
  import { SectionLink } from './SectionLink';
8
8
 
9
- type DocumentLinkProps = {
9
+ type PageLinkProps = {
10
10
  page: {
11
11
  id: number;
12
12
  title: string;
@@ -14,16 +14,29 @@ type DocumentLinkProps = {
14
14
  };
15
15
  selectedUrl: string;
16
16
  onSelectUrl: (url: string) => void;
17
- appBridge: AppBridgeBlock | AppBridgeTheme;
18
17
  itemsToExpandInitially: InitiallyExpandedItems;
18
+ getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;
19
19
  };
20
20
 
21
- export const PageLink = ({ page, selectedUrl, onSelectUrl, itemsToExpandInitially, appBridge }: DocumentLinkProps) => {
21
+ export const PageLink = ({
22
+ page,
23
+ selectedUrl,
24
+ onSelectUrl,
25
+ itemsToExpandInitially,
26
+ getDocumentSectionsByDocumentPageId,
27
+ }: PageLinkProps) => {
22
28
  const [isExpanded, setIsExpanded] = useState(page.id === itemsToExpandInitially.documentId);
29
+ const [documentSections, setDocumentSections] = useState<DocumentSection[]>([]);
23
30
  const isActive = page.permanentLink === selectedUrl;
24
- const { documentSections } = useDocumentSection(appBridge, page.id);
25
- const sectionsArray = [...documentSections.values()];
26
- const hasSections = sectionsArray.length > 0;
31
+
32
+ useEffect(() => {
33
+ const fetchDocumentSections = async () => {
34
+ const sections = await getDocumentSectionsByDocumentPageId(page.id);
35
+ setDocumentSections(sections);
36
+ };
37
+
38
+ fetchDocumentSections();
39
+ }, [page.id, getDocumentSectionsByDocumentPageId]);
27
40
 
28
41
  useEffect(() => {
29
42
  if (page.id === itemsToExpandInitially.pageId) {
@@ -31,6 +44,9 @@ export const PageLink = ({ page, selectedUrl, onSelectUrl, itemsToExpandInitiall
31
44
  }
32
45
  }, [itemsToExpandInitially, page.id]);
33
46
 
47
+ const sectionsArray = [...documentSections.values()];
48
+ const hasSections = sectionsArray.length > 0;
49
+
34
50
  return (
35
51
  <>
36
52
  <button
@@ -1,25 +1,27 @@
1
1
  /* (c) Copyright Frontify Ltd., all rights reserved. */
2
2
 
3
- import type { AppBridgeBlock, AppBridgeTheme, DocumentPage } from '@frontify/app-bridge';
3
+ import type { DocumentPage, DocumentSection } from '@frontify/app-bridge';
4
4
  import { ReactElement, useEffect, useState } from 'react';
5
5
  import { InitiallyExpandedItems } from '../';
6
6
  import { PageLink } from './PageLink';
7
7
  import { LoadingIndicator } from './LoadingIndicator';
8
8
 
9
9
  type PageLinksProps = {
10
- appBridge: AppBridgeBlock | AppBridgeTheme;
11
10
  documentId: number;
12
11
  selectedUrl: string;
13
12
  onSelectUrl: (url: string) => void;
14
13
  itemsToExpandInitially: InitiallyExpandedItems;
14
+ getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;
15
+ getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;
15
16
  };
16
17
 
17
18
  export const PageLinks = ({
18
- appBridge,
19
19
  documentId,
20
20
  selectedUrl,
21
21
  onSelectUrl,
22
22
  itemsToExpandInitially,
23
+ getDocumentSectionsByDocumentPageId,
24
+ getDocumentPagesByDocumentId,
23
25
  }: PageLinksProps): ReactElement => {
24
26
  const [pages, setPages] = useState<DocumentPage[]>([]);
25
27
  const [isLoading, setIsLoading] = useState(true);
@@ -27,8 +29,7 @@ export const PageLinks = ({
27
29
  const hasPages = !isLoading && pagesArray.length > 0;
28
30
 
29
31
  useEffect(() => {
30
- appBridge
31
- .getDocumentPagesByDocumentId(documentId)
32
+ getDocumentPagesByDocumentId(documentId)
32
33
  .then((_pages) => {
33
34
  const pagesWithCategories = _pages
34
35
  .filter((page) => !!page.category)
@@ -54,10 +55,10 @@ export const PageLinks = ({
54
55
  <PageLink
55
56
  key={page.id}
56
57
  page={page}
57
- appBridge={appBridge}
58
58
  selectedUrl={selectedUrl}
59
59
  onSelectUrl={onSelectUrl}
60
60
  itemsToExpandInitially={itemsToExpandInitially}
61
+ getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}
61
62
  />
62
63
  );
63
64
  })}