@frontify/guideline-blocks-settings 0.31.5 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @frontify/guideline-blocks-settings
2
2
 
3
+ ## 0.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#736](https://github.com/Frontify/brand-sdk/pull/736) [`2f7f30f`](https://github.com/Frontify/brand-sdk/commit/2f7f30f902f3c8ed3bacf5fa378014e148bb20aa) Thanks [@ragi96](https://github.com/ragi96)! - refactor(LinkSelector): Removed `appBridge` prop in favor of directly passing document handling functions: `getAllDocuments`, `getDocumentPagesByDocumentId`, and `getDocumentSectionsByDocumentPageId` for clearer API and enhanced modularity
8
+
9
+ Replace this:
10
+
11
+ ```jsx
12
+ <LinkSelector
13
+ url={url}
14
+ appBridge={appBridge}
15
+ onUrlChange={onUrlChange}
16
+ buttonSize={buttonSize ?? ButtonSize.Medium}
17
+ />
18
+ ```
19
+
20
+ with:
21
+
22
+ ```jsx
23
+ <LinkSelector
24
+ url={url}
25
+ onUrlChange={onUrlChange}
26
+ buttonSize={buttonSize ?? ButtonSize.Medium}
27
+ getAllDocuments={() => appBridge.getAllDocuments()}
28
+ getDocumentPagesByDocumentId={(documentId) =>
29
+ appBridge.getDocumentPagesByDocumentId(documentId)
30
+ }
31
+ getDocumentSectionsByDocumentPageId={(documentPageId) =>
32
+ appBridge.getDocumentSectionsByDocumentPageId(documentPageId)
33
+ }
34
+ />
35
+ ```
36
+
3
37
  ## 0.31.5
4
38
 
5
39
  ### Patch Changes
@@ -1,61 +1,63 @@
1
- import { jsxs as b, jsx as t } from "react/jsx-runtime";
2
- import { CheckboxState as l, FormControl as w, TooltipPosition as C, TextInput as S, ButtonSize as f, Checkbox as L } from "@frontify/fondue";
3
- import { isValidUrlOrEmpty as N } from "./utils/url.es.js";
4
- import { LinkSelector as O } from "./LinkSelector/LinkSelector.es.js";
5
- const z = ({
6
- onUrlChange: i,
1
+ import { jsxs as k, jsx as t } from "react/jsx-runtime";
2
+ import { CheckboxState as m, FormControl as b, TooltipPosition as w, TextInput as S, ButtonSize as I, Checkbox as P } from "@frontify/fondue";
3
+ import { isValidUrlOrEmpty as y } from "./utils/url.es.js";
4
+ import { LinkSelector as C } from "./LinkSelector/LinkSelector.es.js";
5
+ const O = ({
6
+ onUrlChange: c,
7
7
  onToggleTab: a,
8
- isValidUrlOrEmpty: o,
9
- appBridge: r,
10
- clearable: c,
8
+ isValidUrlOrEmpty: i,
9
+ appBridge: o,
10
+ clearable: s,
11
11
  placeholder: d,
12
- newTab: s,
13
- openInNewTab: m,
12
+ newTab: r,
13
+ openInNewTab: u,
14
14
  url: e = "",
15
- required: p,
16
- info: n,
17
- label: h,
18
- buttonSize: u,
15
+ required: h,
16
+ info: l,
17
+ label: p,
18
+ buttonSize: g,
19
19
  hideInternalLinkButton: x
20
20
  }) => {
21
- const v = o ? o(e) : N(e), k = s ?? (m ? l.Checked : l.Unchecked);
22
- return /* @__PURE__ */ b("div", { "data-test-id": "link-input", children: [
21
+ const D = i ? i(e) : y(e), v = r ?? (u ? m.Checked : m.Unchecked);
22
+ return /* @__PURE__ */ k("div", { "data-test-id": "link-input", children: [
23
23
  /* @__PURE__ */ t(
24
- w,
24
+ b,
25
25
  {
26
26
  label: {
27
- children: h,
27
+ children: p,
28
28
  htmlFor: "url",
29
- required: p,
30
- tooltip: n ? { content: n, position: C.Top } : void 0
29
+ required: h,
30
+ tooltip: l ? { content: l, position: w.Top } : void 0
31
31
  },
32
32
  children: /* @__PURE__ */ t(
33
33
  S,
34
34
  {
35
35
  id: "url",
36
36
  value: e,
37
- clearable: c,
38
- onChange: i,
37
+ clearable: s,
38
+ onChange: c,
39
39
  placeholder: d ?? "https://example.com",
40
40
  focusOnMount: !0
41
41
  }
42
42
  )
43
43
  }
44
44
  ),
45
- !v && /* @__PURE__ */ t("div", { className: "tw-text-text-negative tw-mt-1 tw-text-s", children: "Please enter a valid URL." }),
45
+ !D && /* @__PURE__ */ t("div", { className: "tw-text-text-negative tw-mt-1 tw-text-s", children: "Please enter a valid URL." }),
46
46
  !x && /* @__PURE__ */ t("div", { className: "tw-mt-3", children: /* @__PURE__ */ t(
47
- O,
47
+ C,
48
48
  {
49
49
  url: e,
50
- appBridge: r,
51
- onUrlChange: i,
52
- buttonSize: u ?? f.Medium
50
+ onUrlChange: c,
51
+ buttonSize: g ?? I.Medium,
52
+ getAllDocuments: () => o.getAllDocuments(),
53
+ getDocumentPagesByDocumentId: (n) => o.getDocumentPagesByDocumentId(n),
54
+ getDocumentSectionsByDocumentPageId: (n) => o.getDocumentSectionsByDocumentPageId(n)
53
55
  }
54
56
  ) }),
55
- /* @__PURE__ */ t("div", { className: "tw-mt-3", children: /* @__PURE__ */ t(L, { value: "new-tab", label: "Open in new tab", state: k, onChange: a }) })
57
+ /* @__PURE__ */ t("div", { className: "tw-mt-3", children: /* @__PURE__ */ t(P, { value: "new-tab", label: "Open in new tab", state: v, onChange: a }) })
56
58
  ] });
57
59
  };
58
60
  export {
59
- z as LinkInput
61
+ O as LinkInput
60
62
  };
61
63
  //# sourceMappingURL=LinkInput.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LinkInput.es.js","sources":["../../../src/components/Link/LinkInput.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { AppBridgeBlock, AppBridgeTheme } from '@frontify/app-bridge';\nimport { ButtonSize, Checkbox, CheckboxState, FormControl, TextInput, TooltipPosition } from '@frontify/fondue';\nimport { LinkSelector } from './LinkSelector';\nimport { isValidUrlOrEmpty as internalIsValidUrlOrEmpty } from './utils';\n\ntype LinkInputProps = {\n url?: string;\n info?: string;\n label?: string;\n required?: boolean;\n newTab?: CheckboxState;\n openInNewTab?: boolean;\n onUrlChange?: (value: string) => void;\n onToggleTab?: (checked: boolean) => void;\n isValidUrlOrEmpty?: (url: string) => boolean;\n appBridge: AppBridgeBlock | AppBridgeTheme;\n clearable?: boolean;\n placeholder?: string;\n buttonSize?: ButtonSize;\n hideInternalLinkButton?: boolean;\n};\n\nexport const LinkInput = ({\n onUrlChange,\n onToggleTab,\n isValidUrlOrEmpty,\n appBridge,\n clearable,\n placeholder,\n newTab,\n openInNewTab,\n url = '',\n required,\n info,\n label,\n buttonSize,\n hideInternalLinkButton,\n}: LinkInputProps) => {\n const isUrlValid = isValidUrlOrEmpty ? isValidUrlOrEmpty(url) : internalIsValidUrlOrEmpty(url);\n const checkedState = newTab ?? (openInNewTab ? CheckboxState.Checked : CheckboxState.Unchecked);\n return (\n <div data-test-id=\"link-input\">\n <FormControl\n label={{\n children: label,\n htmlFor: 'url',\n required,\n tooltip: info ? { content: info, position: TooltipPosition.Top } : undefined,\n }}\n >\n <TextInput\n id=\"url\"\n value={url}\n clearable={clearable}\n onChange={onUrlChange}\n placeholder={placeholder ?? 'https://example.com'}\n focusOnMount\n />\n </FormControl>\n {!isUrlValid && <div className=\"tw-text-text-negative tw-mt-1 tw-text-s\">Please enter a valid URL.</div>}\n\n {!hideInternalLinkButton && (\n <div className=\"tw-mt-3\">\n <LinkSelector\n url={url}\n appBridge={appBridge}\n onUrlChange={onUrlChange}\n buttonSize={buttonSize ?? ButtonSize.Medium}\n />\n </div>\n )}\n\n <div className=\"tw-mt-3\">\n <Checkbox value=\"new-tab\" label=\"Open in new tab\" state={checkedState} onChange={onToggleTab} />\n </div>\n </div>\n );\n};\n"],"names":["LinkInput","onUrlChange","onToggleTab","isValidUrlOrEmpty","appBridge","clearable","placeholder","newTab","openInNewTab","url","required","info","label","buttonSize","hideInternalLinkButton","isUrlValid","internalIsValidUrlOrEmpty","checkedState","CheckboxState","jsxs","jsx","FormControl","TooltipPosition","TextInput","LinkSelector","ButtonSize","Checkbox"],"mappings":";;;;AAwBO,MAAMA,IAAY,CAAC;AAAA,EACtB,aAAAC;AAAA,EACA,aAAAC;AAAA,EAAA,mBACAC;AAAAA,EACA,WAAAC;AAAA,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AER;"}
1
+ {"version":3,"file":"LinkInput.es.js","sources":["../../../src/components/Link/LinkInput.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { AppBridgeBlock, AppBridgeTheme } from '@frontify/app-bridge';\nimport { ButtonSize, Checkbox, CheckboxState, FormControl, TextInput, TooltipPosition } from '@frontify/fondue';\nimport { LinkSelector } from './LinkSelector';\nimport { isValidUrlOrEmpty as internalIsValidUrlOrEmpty } from './utils';\n\ntype LinkInputProps = {\n url?: string;\n info?: string;\n label?: string;\n required?: boolean;\n newTab?: CheckboxState;\n openInNewTab?: boolean;\n onUrlChange?: (value: string) => void;\n onToggleTab?: (checked: boolean) => void;\n isValidUrlOrEmpty?: (url: string) => boolean;\n appBridge: AppBridgeBlock | AppBridgeTheme;\n clearable?: boolean;\n placeholder?: string;\n buttonSize?: ButtonSize;\n hideInternalLinkButton?: boolean;\n};\n\nexport const LinkInput = ({\n onUrlChange,\n onToggleTab,\n isValidUrlOrEmpty,\n appBridge,\n clearable,\n placeholder,\n newTab,\n openInNewTab,\n url = '',\n required,\n info,\n label,\n buttonSize,\n hideInternalLinkButton,\n}: LinkInputProps) => {\n const isUrlValid = isValidUrlOrEmpty ? isValidUrlOrEmpty(url) : internalIsValidUrlOrEmpty(url);\n const checkedState = newTab ?? (openInNewTab ? CheckboxState.Checked : CheckboxState.Unchecked);\n return (\n <div data-test-id=\"link-input\">\n <FormControl\n label={{\n children: label,\n htmlFor: 'url',\n required,\n tooltip: info ? { content: info, position: TooltipPosition.Top } : undefined,\n }}\n >\n <TextInput\n id=\"url\"\n value={url}\n clearable={clearable}\n onChange={onUrlChange}\n placeholder={placeholder ?? 'https://example.com'}\n focusOnMount\n />\n </FormControl>\n {!isUrlValid && <div className=\"tw-text-text-negative tw-mt-1 tw-text-s\">Please enter a valid URL.</div>}\n\n {!hideInternalLinkButton && (\n <div className=\"tw-mt-3\">\n <LinkSelector\n url={url}\n onUrlChange={onUrlChange}\n buttonSize={buttonSize ?? ButtonSize.Medium}\n getAllDocuments={() => appBridge.getAllDocuments()}\n getDocumentPagesByDocumentId={(documentId) =>\n appBridge.getDocumentPagesByDocumentId(documentId)\n }\n getDocumentSectionsByDocumentPageId={(documentPageId) =>\n appBridge.getDocumentSectionsByDocumentPageId(documentPageId)\n }\n />\n </div>\n )}\n\n <div className=\"tw-mt-3\">\n <Checkbox value=\"new-tab\" label=\"Open in new tab\" state={checkedState} onChange={onToggleTab} />\n </div>\n </div>\n );\n};\n"],"names":["LinkInput","onUrlChange","onToggleTab","isValidUrlOrEmpty","appBridge","clearable","placeholder","newTab","openInNewTab","url","required","info","label","buttonSize","hideInternalLinkButton","isUrlValid","internalIsValidUrlOrEmpty","checkedState","CheckboxState","jsxs","jsx","FormControl","TooltipPosition","TextInput","LinkSelector","ButtonSize","documentId","documentPageId","Checkbox"],"mappings":";;;;AAwBO,MAAMA,IAAY,CAAC;AAAA,EACtB,aAAAC;AAAA,EACA,aAAAC;AAAA,EAAA,mBACAC;AAAAA,EACA,WAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC;AAAA,EACA,KAAAC,IAAM;AAAA,EACN,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,wBAAAC;AACJ,MAAsB;AAClB,QAAMC,IAAaZ,IAAoBA,EAAkBM,CAAG,IAAIO,EAA0BP,CAAG,GACvFQ,IAAeV,MAAWC,IAAeU,EAAc,UAAUA,EAAc;AAEjF,SAAA,gBAAAC,EAAC,OAAI,EAAA,gBAAa,cACd,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAACC;AAAA,MAAA;AAAA,QACG,OAAO;AAAA,UACH,UAAUT;AAAA,UACV,SAAS;AAAA,UACT,UAAAF;AAAA,UACA,SAASC,IAAO,EAAE,SAASA,GAAM,UAAUW,EAAgB,IAAQ,IAAA;AAAA,QACvE;AAAA,QAEA,UAAA,gBAAAF;AAAA,UAACG;AAAA,UAAA;AAAA,YACG,IAAG;AAAA,YACH,OAAOd;AAAA,YACP,WAAAJ;AAAA,YACA,UAAUJ;AAAA,YACV,aAAaK,KAAe;AAAA,YAC5B,cAAY;AAAA,UAAA;AAAA,QAChB;AAAA,MAAA;AAAA,IACJ;AAAA,IACC,CAACS,KAAc,gBAAAK,EAAC,OAAI,EAAA,WAAU,2CAA0C,UAAyB,6BAAA;AAAA,IAEjG,CAACN,KACG,gBAAAM,EAAA,OAAA,EAAI,WAAU,WACX,UAAA,gBAAAA;AAAA,MAACI;AAAA,MAAA;AAAA,QACG,KAAAf;AAAA,QACA,aAAAR;AAAA,QACA,YAAYY,KAAcY,EAAW;AAAA,QACrC,iBAAiB,MAAMrB,EAAU,gBAAgB;AAAA,QACjD,8BAA8B,CAACsB,MAC3BtB,EAAU,6BAA6BsB,CAAU;AAAA,QAErD,qCAAqC,CAACC,MAClCvB,EAAU,oCAAoCuB,CAAc;AAAA,MAAA;AAAA,IAAA,GAGxE;AAAA,IAGH,gBAAAP,EAAA,OAAA,EAAI,WAAU,WACX,4BAACQ,GAAS,EAAA,OAAM,WAAU,OAAM,mBAAkB,OAAOX,GAAc,UAAUf,EAAa,CAAA,GAClG;AAAA,EACJ,EAAA,CAAA;AAER;"}
@@ -1,25 +1,26 @@
1
- import { jsxs as a, Fragment as l, jsx as e } from "react/jsx-runtime";
2
- import { useState as b, useEffect as x } from "react";
3
- import { PageLinks as m } from "./PageLinks.es.js";
4
- import { merge as i, IconColorFan16 as p } from "@frontify/fondue";
5
- const u = ({
1
+ import { jsxs as a, Fragment as b, jsx as e } from "react/jsx-runtime";
2
+ import { useState as x, useEffect as m } from "react";
3
+ import { PageLinks as p } from "./PageLinks.es.js";
4
+ import { merge as i, IconColorFan16 as h } from "@frontify/fondue";
5
+ const k = ({
6
6
  document: t,
7
- appBridge: c,
8
7
  selectedUrl: n,
9
8
  onSelectUrl: s,
10
- itemsToExpandInitially: r
9
+ itemsToExpandInitially: r,
10
+ getDocumentSectionsByDocumentPageId: c,
11
+ getDocumentPagesByDocumentId: d
11
12
  }) => {
12
- const [o, w] = b(t.id === r.documentId), d = t.permanentLink === n;
13
- return x(() => {
13
+ const [o, w] = x(t.id === r.documentId), l = t.permanentLink === n;
14
+ return m(() => {
14
15
  t.id === r.documentId && w(!0);
15
- }, [r, t.id]), /* @__PURE__ */ a(l, { children: [
16
+ }, [r, t.id]), /* @__PURE__ */ a(b, { children: [
16
17
  /* @__PURE__ */ a(
17
18
  "button",
18
19
  {
19
20
  "data-test-id": "internal-link-selector-document-link",
20
21
  className: i([
21
22
  "tw-flex tw-flex-1 tw-space-x-2 tw-items-center tw-py-2 tw-pr-2.5 tw-leading-5 tw-cursor-pointer tw-w-full",
22
- d ? "tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover" : "hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover"
23
+ l ? "tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover" : "hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover"
23
24
  ]),
24
25
  onClick: () => s(t.permanentLink),
25
26
  children: [
@@ -42,25 +43,26 @@ const u = ({
42
43
  )
43
44
  }
44
45
  ),
45
- /* @__PURE__ */ e(p, {}),
46
+ /* @__PURE__ */ e(h, {}),
46
47
  /* @__PURE__ */ e("span", { className: "tw-text-s", children: t.title }),
47
48
  /* @__PURE__ */ e("span", { className: "tw-flex-auto tw-font-sans tw-text-xs tw-text-right", children: "Document" })
48
49
  ]
49
50
  }
50
51
  ),
51
52
  o && /* @__PURE__ */ e(
52
- m,
53
+ p,
53
54
  {
54
- appBridge: c,
55
55
  documentId: t.id,
56
56
  selectedUrl: n,
57
57
  onSelectUrl: s,
58
- itemsToExpandInitially: r
58
+ itemsToExpandInitially: r,
59
+ getDocumentSectionsByDocumentPageId: c,
60
+ getDocumentPagesByDocumentId: d
59
61
  }
60
62
  )
61
63
  ] });
62
64
  };
63
65
  export {
64
- u as DocumentLink
66
+ k as DocumentLink
65
67
  };
66
68
  //# sourceMappingURL=DocumentLink.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentLink.es.js","sources":["../../../../src/components/Link/LinkSelector/DocumentLink.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { AppBridgeBlock, AppBridgeTheme } from '@frontify/app-bridge';\nimport { useEffect, useState } from 'react';\nimport { PageLinks } from './PageLinks';\nimport { IconColorFan16, merge } from '@frontify/fondue';\nimport { InitiallyExpandedItems } from '../';\n\ntype DocumentLinkProps = {\n document: {\n id: number;\n title: string;\n permanentLink: string;\n };\n appBridge: AppBridgeBlock | AppBridgeTheme;\n selectedUrl: string;\n onSelectUrl: (url: string) => void;\n itemsToExpandInitially: InitiallyExpandedItems;\n};\n\nexport const DocumentLink = ({\n document,\n appBridge,\n selectedUrl,\n onSelectUrl,\n itemsToExpandInitially,\n}: DocumentLinkProps) => {\n const [isExpanded, setIsExpanded] = useState(document.id === itemsToExpandInitially.documentId);\n const isActive = document.permanentLink === selectedUrl;\n\n useEffect(() => {\n if (document.id === itemsToExpandInitially.documentId) {\n setIsExpanded(true);\n }\n }, [itemsToExpandInitially, document.id]);\n\n return (\n <>\n <button\n data-test-id=\"internal-link-selector-document-link\"\n className={merge([\n 'tw-flex tw-flex-1 tw-space-x-2 tw-items-center tw-py-2 tw-pr-2.5 tw-leading-5 tw-cursor-pointer tw-w-full',\n isActive\n ? 'tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover'\n : 'hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover',\n ])}\n onClick={() => onSelectUrl(document.permanentLink)}\n >\n <button\n role=\"button\"\n tabIndex={0}\n data-test-id=\"tree-item-toggle\"\n className=\"tw-flex tw-items-center tw-justify-center -tw-mr-2 tw-pr-3.5 tw-pt-1.5 tw-pb-1.5 tw-pl-3.5 tw-cursor-pointer\"\n onClick={() => setIsExpanded(!isExpanded)}\n >\n <div\n className={merge([\n 'tw-transition-transform tw-w-0 tw-h-0 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong',\n isExpanded ? 'tw-rotate-90' : '',\n ])}\n ></div>\n </button>\n <IconColorFan16 />\n <span className=\"tw-text-s\">{document.title}</span>\n <span className=\"tw-flex-auto tw-font-sans tw-text-xs tw-text-right\">Document</span>\n </button>\n {isExpanded && (\n <PageLinks\n appBridge={appBridge}\n documentId={document.id}\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n itemsToExpandInitially={itemsToExpandInitially}\n />\n )}\n </>\n );\n};\n"],"names":["DocumentLink","document","appBridge","selectedUrl","onSelectUrl","itemsToExpandInitially","isExpanded","setIsExpanded","useState","isActive","useEffect","jsxs","Fragment","merge","jsx","IconColorFan16","PageLinks"],"mappings":";;;;AAoBO,MAAMA,IAAe,CAAC;AAAA,EACzB,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,wBAAAC;AACJ,MAAyB;AACf,QAAA,CAACC,GAAYC,CAAa,IAAIC,EAASP,EAAS,OAAOI,EAAuB,UAAU,GACxFI,IAAWR,EAAS,kBAAkBE;AAE5C,SAAAO,EAAU,MAAM;AACR,IAAAT,EAAS,OAAOI,EAAuB,cACvCE,EAAc,EAAI;AAAA,EAEvB,GAAA,CAACF,GAAwBJ,EAAS,EAAE,CAAC,GAIhC,gBAAAU,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAD;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,gBAAa;AAAA,QACb,WAAWE,EAAM;AAAA,UACb;AAAA,UACAJ,IACM,oKACA;AAAA,QAAA,CACT;AAAA,QACD,SAAS,MAAML,EAAYH,EAAS,aAAa;AAAA,QAEjD,UAAA;AAAA,UAAA,gBAAAa;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,MAAK;AAAA,cACL,UAAU;AAAA,cACV,gBAAa;AAAA,cACb,WAAU;AAAA,cACV,SAAS,MAAMP,EAAc,CAACD,CAAU;AAAA,cAExC,UAAA,gBAAAQ;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACG,WAAWD,EAAM;AAAA,oBACb;AAAA,oBACAP,IAAa,iBAAiB;AAAA,kBAAA,CACjC;AAAA,gBAAA;AAAA,cACJ;AAAA,YAAA;AAAA,UACL;AAAA,4BACCS,GAAe,EAAA;AAAA,UACf,gBAAAD,EAAA,QAAA,EAAK,WAAU,aAAa,YAAS,OAAM;AAAA,UAC3C,gBAAAA,EAAA,QAAA,EAAK,WAAU,sDAAqD,UAAQ,YAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACjF;AAAA,IACCR,KACG,gBAAAQ;AAAA,MAACE;AAAA,MAAA;AAAA,QACG,WAAAd;AAAA,QACA,YAAYD,EAAS;AAAA,QACrB,aAAAE;AAAA,QACA,aAAAC;AAAA,QACA,wBAAAC;AAAA,MAAA;AAAA,IACJ;AAAA,EAER,EAAA,CAAA;AAER;"}
1
+ {"version":3,"file":"DocumentLink.es.js","sources":["../../../../src/components/Link/LinkSelector/DocumentLink.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { DocumentPage, DocumentSection } from '@frontify/app-bridge';\nimport { useEffect, useState } from 'react';\nimport { PageLinks } from './PageLinks';\nimport { IconColorFan16, merge } from '@frontify/fondue';\nimport { InitiallyExpandedItems } from '../';\n\ntype DocumentLinkProps = {\n document: {\n id: number;\n title: string;\n permanentLink: string;\n };\n selectedUrl: string;\n onSelectUrl: (url: string) => void;\n itemsToExpandInitially: InitiallyExpandedItems;\n getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;\n getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;\n};\n\nexport const DocumentLink = ({\n document,\n selectedUrl,\n onSelectUrl,\n itemsToExpandInitially,\n getDocumentSectionsByDocumentPageId,\n getDocumentPagesByDocumentId,\n}: DocumentLinkProps) => {\n const [isExpanded, setIsExpanded] = useState(document.id === itemsToExpandInitially.documentId);\n const isActive = document.permanentLink === selectedUrl;\n\n useEffect(() => {\n if (document.id === itemsToExpandInitially.documentId) {\n setIsExpanded(true);\n }\n }, [itemsToExpandInitially, document.id]);\n\n return (\n <>\n <button\n data-test-id=\"internal-link-selector-document-link\"\n className={merge([\n 'tw-flex tw-flex-1 tw-space-x-2 tw-items-center tw-py-2 tw-pr-2.5 tw-leading-5 tw-cursor-pointer tw-w-full',\n isActive\n ? 'tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover'\n : 'hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover',\n ])}\n onClick={() => onSelectUrl(document.permanentLink)}\n >\n <button\n role=\"button\"\n tabIndex={0}\n data-test-id=\"tree-item-toggle\"\n className=\"tw-flex tw-items-center tw-justify-center -tw-mr-2 tw-pr-3.5 tw-pt-1.5 tw-pb-1.5 tw-pl-3.5 tw-cursor-pointer\"\n onClick={() => setIsExpanded(!isExpanded)}\n >\n <div\n className={merge([\n 'tw-transition-transform tw-w-0 tw-h-0 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong',\n isExpanded ? 'tw-rotate-90' : '',\n ])}\n ></div>\n </button>\n <IconColorFan16 />\n <span className=\"tw-text-s\">{document.title}</span>\n <span className=\"tw-flex-auto tw-font-sans tw-text-xs tw-text-right\">Document</span>\n </button>\n {isExpanded && (\n <PageLinks\n documentId={document.id}\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n itemsToExpandInitially={itemsToExpandInitially}\n getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}\n getDocumentPagesByDocumentId={getDocumentPagesByDocumentId}\n />\n )}\n </>\n );\n};\n"],"names":["DocumentLink","document","selectedUrl","onSelectUrl","itemsToExpandInitially","getDocumentSectionsByDocumentPageId","getDocumentPagesByDocumentId","isExpanded","setIsExpanded","useState","isActive","useEffect","jsxs","Fragment","merge","jsx","IconColorFan16","PageLinks"],"mappings":";;;;AAqBO,MAAMA,IAAe,CAAC;AAAA,EACzB,UAAAC;AAAA,EACA,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,wBAAAC;AAAA,EACA,qCAAAC;AAAA,EACA,8BAAAC;AACJ,MAAyB;AACf,QAAA,CAACC,GAAYC,CAAa,IAAIC,EAASR,EAAS,OAAOG,EAAuB,UAAU,GACxFM,IAAWT,EAAS,kBAAkBC;AAE5C,SAAAS,EAAU,MAAM;AACR,IAAAV,EAAS,OAAOG,EAAuB,cACvCI,EAAc,EAAI;AAAA,EAEvB,GAAA,CAACJ,GAAwBH,EAAS,EAAE,CAAC,GAIhC,gBAAAW,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAD;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,gBAAa;AAAA,QACb,WAAWE,EAAM;AAAA,UACb;AAAA,UACAJ,IACM,oKACA;AAAA,QAAA,CACT;AAAA,QACD,SAAS,MAAMP,EAAYF,EAAS,aAAa;AAAA,QAEjD,UAAA;AAAA,UAAA,gBAAAc;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,MAAK;AAAA,cACL,UAAU;AAAA,cACV,gBAAa;AAAA,cACb,WAAU;AAAA,cACV,SAAS,MAAMP,EAAc,CAACD,CAAU;AAAA,cAExC,UAAA,gBAAAQ;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACG,WAAWD,EAAM;AAAA,oBACb;AAAA,oBACAP,IAAa,iBAAiB;AAAA,kBAAA,CACjC;AAAA,gBAAA;AAAA,cACJ;AAAA,YAAA;AAAA,UACL;AAAA,4BACCS,GAAe,EAAA;AAAA,UACf,gBAAAD,EAAA,QAAA,EAAK,WAAU,aAAa,YAAS,OAAM;AAAA,UAC3C,gBAAAA,EAAA,QAAA,EAAK,WAAU,sDAAqD,UAAQ,YAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACjF;AAAA,IACCR,KACG,gBAAAQ;AAAA,MAACE;AAAA,MAAA;AAAA,QACG,YAAYhB,EAAS;AAAA,QACrB,aAAAC;AAAA,QACA,aAAAC;AAAA,QACA,wBAAAC;AAAA,QACA,qCAAAC;AAAA,QACA,8BAAAC;AAAA,MAAA;AAAA,IACJ;AAAA,EAER,EAAA,CAAA;AAER;"}
@@ -1,55 +1,60 @@
1
- import { jsx as i, Fragment as v } from "react/jsx-runtime";
2
- import { useState as r, useEffect as d } from "react";
3
- import { DocumentLink as A } from "./DocumentLink.es.js";
4
- import { LoadingIndicator as h } from "./LoadingIndicator.es.js";
5
- const F = ({ appBridge: n, selectedUrl: e, onSelectUrl: m }) => {
6
- const [u, l] = r(!0), [f, I] = r([]), [g, D] = r({
1
+ import { jsx as i, Fragment as k } from "react/jsx-runtime";
2
+ import { useState as r, useEffect as m } from "react";
3
+ import { DocumentLink as x } from "./DocumentLink.es.js";
4
+ import { LoadingIndicator as A } from "./LoadingIndicator.es.js";
5
+ const q = ({
6
+ selectedUrl: t,
7
+ onSelectUrl: f,
8
+ getAllDocuments: l,
9
+ getDocumentPagesByDocumentId: a,
10
+ getDocumentSectionsByDocumentPageId: c
11
+ }) => {
12
+ const [p, u] = r(!0), [I, g] = r([]), [L, v] = r({
7
13
  documentId: void 0,
8
14
  pageId: void 0
9
- }), o = [...f.values()];
10
- d(() => {
11
- e && o.length > 0 && p().then((t) => {
12
- D(t);
15
+ }), e = [...I.values()];
16
+ m(() => {
17
+ t && e.length > 0 && y().then((n) => {
18
+ v(n);
13
19
  });
14
- }, [o.length]), d(() => {
15
- n.getAllDocuments().then((t) => {
16
- I(t);
20
+ }, [e.length]), m(() => {
21
+ l().then((n) => {
22
+ g(n);
17
23
  }).finally(() => {
18
- l(!1);
24
+ u(!1);
19
25
  });
20
26
  }, []);
21
- const p = async () => {
22
- const t = {
27
+ const y = async () => {
28
+ const n = {
23
29
  documentId: void 0,
24
30
  pageId: void 0
25
31
  };
26
- if (o.find((s) => s.permanentLink === e))
27
- return t;
28
- for (const s of o) {
29
- const y = await n.getDocumentPagesByDocumentId(s.id);
30
- n.getAllDocuments();
31
- const a = [...y.values()];
32
- if (!!a.find((c) => c.permanentLink === e))
33
- return t.documentId = s.id, t;
34
- for (const c of a)
35
- if (!![...(await n.getDocumentSectionsByDocumentPageId(c.id)).values()].find((L) => L.permanentLink === e))
36
- return t.documentId = s.id, t.pageId = c.id, t;
32
+ if (e.find((o) => o.permanentLink === t))
33
+ return n;
34
+ for (const o of e) {
35
+ const d = [...(await a(o.id)).values()];
36
+ if (!!d.find((s) => s.permanentLink === t))
37
+ return n.documentId = o.id, n;
38
+ for (const s of d)
39
+ if (!![...(await c(s.id)).values()].find((h) => h.permanentLink === t))
40
+ return n.documentId = o.id, n.pageId = s.id, n;
37
41
  }
38
- return t;
42
+ return n;
39
43
  };
40
- return u ? /* @__PURE__ */ i(h, {}) : /* @__PURE__ */ i(v, { children: o.map((t) => /* @__PURE__ */ i(
41
- A,
44
+ return p ? /* @__PURE__ */ i(A, {}) : /* @__PURE__ */ i(k, { children: e.map((n) => /* @__PURE__ */ i(
45
+ x,
42
46
  {
43
- document: t,
44
- appBridge: n,
45
- selectedUrl: e,
46
- onSelectUrl: m,
47
- itemsToExpandInitially: g
47
+ document: n,
48
+ selectedUrl: t,
49
+ onSelectUrl: f,
50
+ itemsToExpandInitially: L,
51
+ getDocumentSectionsByDocumentPageId: c,
52
+ getDocumentPagesByDocumentId: a
48
53
  },
49
- t.id
54
+ n.id
50
55
  )) });
51
56
  };
52
57
  export {
53
- F as DocumentLinks
58
+ q as DocumentLinks
54
59
  };
55
60
  //# sourceMappingURL=DocumentLinks.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentLinks.es.js","sources":["../../../../src/components/Link/LinkSelector/DocumentLinks.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { AppBridgeBlock, AppBridgeTheme, Document } from '@frontify/app-bridge';\nimport { ReactElement, useEffect, useState } from 'react';\nimport { DocumentLink } from './DocumentLink';\nimport { LoadingIndicator } from './LoadingIndicator';\nimport { InitiallyExpandedItems } from '../';\n\ntype DocumentLinksProps = {\n appBridge: AppBridgeBlock | AppBridgeTheme;\n selectedUrl: string;\n onSelectUrl: (url: string) => void;\n};\n\nexport const DocumentLinks = ({ appBridge, selectedUrl, onSelectUrl }: DocumentLinksProps): ReactElement => {\n const [isLoading, setIsLoading] = useState(true);\n const [documents, setDocuments] = useState<Document[]>([]);\n const [itemsToExpandInitially, setItemsToExpandInitially] = useState<InitiallyExpandedItems>({\n documentId: undefined,\n pageId: undefined,\n });\n\n const documentArray = [...documents.values()];\n\n useEffect(() => {\n if (selectedUrl && documentArray.length > 0) {\n findLocationOfSelectedUrl().then((items) => {\n setItemsToExpandInitially(items);\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [documentArray.length]);\n\n useEffect(() => {\n appBridge\n .getAllDocuments()\n .then((_documents) => {\n setDocuments(_documents);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const findLocationOfSelectedUrl = async () => {\n const itemsToExpand: InitiallyExpandedItems = {\n documentId: undefined,\n pageId: undefined,\n };\n const selectedUrlIsDocument = documentArray.find((document) => document.permanentLink === selectedUrl);\n if (selectedUrlIsDocument) {\n return itemsToExpand;\n }\n for (const document of documentArray) {\n const pages = await appBridge.getDocumentPagesByDocumentId(document.id);\n appBridge.getAllDocuments();\n const pagesArray = [...pages.values()];\n const selectedUrlIsPage = !!pagesArray.find((page) => page.permanentLink === selectedUrl);\n if (selectedUrlIsPage) {\n itemsToExpand.documentId = document.id;\n return itemsToExpand;\n }\n for (const page of pagesArray) {\n const sections = await appBridge.getDocumentSectionsByDocumentPageId(page.id);\n const sectionsArray = [...sections.values()];\n const selectedUrlIsSection = !!sectionsArray.find((section) => section.permanentLink === selectedUrl);\n if (selectedUrlIsSection) {\n itemsToExpand.documentId = document.id;\n itemsToExpand.pageId = page.id;\n return itemsToExpand;\n }\n }\n }\n return itemsToExpand;\n };\n\n return isLoading ? (\n <LoadingIndicator />\n ) : (\n <>\n {documentArray.map((document) => {\n return (\n <DocumentLink\n key={document.id}\n document={document}\n appBridge={appBridge}\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n itemsToExpandInitially={itemsToExpandInitially}\n />\n );\n })}\n </>\n );\n};\n"],"names":["DocumentLinks","appBridge","selectedUrl","onSelectUrl","isLoading","setIsLoading","useState","documents","setDocuments","itemsToExpandInitially","setItemsToExpandInitially","documentArray","useEffect","findLocationOfSelectedUrl","items","_documents","itemsToExpand","document","pages","pagesArray","page","section","LoadingIndicator","jsx","DocumentLink"],"mappings":";;;;AAcO,MAAMA,IAAgB,CAAC,EAAE,WAAAC,GAAW,aAAAC,GAAa,aAAAC,QAAoD;AACxG,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAI,GACzC,CAACC,GAAWC,CAAY,IAAIF,EAAqB,CAAE,CAAA,GACnD,CAACG,GAAwBC,CAAyB,IAAIJ,EAAiC;AAAA,IACzF,YAAY;AAAA,IACZ,QAAQ;AAAA,EAAA,CACX,GAEKK,IAAgB,CAAC,GAAGJ,EAAU,OAAQ,CAAA;AAE5C,EAAAK,EAAU,MAAM;AACR,IAAAV,KAAeS,EAAc,SAAS,KACZE,EAAA,EAAE,KAAK,CAACC,MAAU;AACxC,MAAAJ,EAA0BI,CAAK;AAAA,IAAA,CAClC;AAAA,EACL,GAED,CAACH,EAAc,MAAM,CAAC,GAEzBC,EAAU,MAAM;AACZ,IAAAX,EACK,gBAAgB,EAChB,KAAK,CAACc,MAAe;AAClB,MAAAP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., all rights reserved. */\n\nimport type { Document, DocumentPage, DocumentSection } from '@frontify/app-bridge';\nimport { ReactElement, useEffect, useState } from 'react';\nimport { DocumentLink } from './DocumentLink';\nimport { LoadingIndicator } from './LoadingIndicator';\nimport { InitiallyExpandedItems } from '../';\n\ntype DocumentLinksProps = {\n selectedUrl: string;\n onSelectUrl: (url: string) => void;\n getAllDocuments: () => Promise<Document[]>;\n getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;\n getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;\n};\n\nexport const DocumentLinks = ({\n selectedUrl,\n onSelectUrl,\n getAllDocuments,\n getDocumentPagesByDocumentId,\n getDocumentSectionsByDocumentPageId,\n}: DocumentLinksProps): ReactElement => {\n const [isLoading, setIsLoading] = useState(true);\n const [documents, setDocuments] = useState<Document[]>([]);\n const [itemsToExpandInitially, setItemsToExpandInitially] = useState<InitiallyExpandedItems>({\n documentId: undefined,\n pageId: undefined,\n });\n\n const documentArray = [...documents.values()];\n\n useEffect(() => {\n if (selectedUrl && documentArray.length > 0) {\n findLocationOfSelectedUrl().then((items) => {\n setItemsToExpandInitially(items);\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [documentArray.length]);\n\n useEffect(() => {\n getAllDocuments()\n .then((_documents) => {\n setDocuments(_documents);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const findLocationOfSelectedUrl = async () => {\n const itemsToExpand: InitiallyExpandedItems = {\n documentId: undefined,\n pageId: undefined,\n };\n const selectedUrlIsDocument = documentArray.find((document) => document.permanentLink === selectedUrl);\n if (selectedUrlIsDocument) {\n return itemsToExpand;\n }\n for (const document of documentArray) {\n const pages = await getDocumentPagesByDocumentId(document.id);\n const pagesArray = [...pages.values()];\n const selectedUrlIsPage = !!pagesArray.find((page) => page.permanentLink === selectedUrl);\n if (selectedUrlIsPage) {\n itemsToExpand.documentId = document.id;\n return itemsToExpand;\n }\n for (const page of pagesArray) {\n const sections = await getDocumentSectionsByDocumentPageId(page.id);\n const sectionsArray = [...sections.values()];\n const selectedUrlIsSection = !!sectionsArray.find((section) => section.permanentLink === selectedUrl);\n if (selectedUrlIsSection) {\n itemsToExpand.documentId = document.id;\n itemsToExpand.pageId = page.id;\n return itemsToExpand;\n }\n }\n }\n return itemsToExpand;\n };\n\n return isLoading ? (\n <LoadingIndicator />\n ) : (\n <>\n {documentArray.map((document) => {\n return (\n <DocumentLink\n key={document.id}\n document={document}\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n itemsToExpandInitially={itemsToExpandInitially}\n getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}\n getDocumentPagesByDocumentId={getDocumentPagesByDocumentId}\n />\n );\n })}\n </>\n );\n};\n"],"names":["DocumentLinks","selectedUrl","onSelectUrl","getAllDocuments","getDocumentPagesByDocumentId","getDocumentSectionsByDocumentPageId","isLoading","setIsLoading","useState","documents","setDocuments","itemsToExpandInitially","setItemsToExpandInitially","documentArray","useEffect","findLocationOfSelectedUrl","items","_documents","itemsToExpand","document","pagesArray","page","section","LoadingIndicator","jsx","DocumentLink"],"mappings":";;;;AAgBO,MAAMA,IAAgB,CAAC;AAAA,EAC1B,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,8BAAAC;AAAA,EACA,qCAAAC;AACJ,MAAwC;AACpC,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAI,GACzC,CAACC,GAAWC,CAAY,IAAIF,EAAqB,CAAE,CAAA,GACnD,CAACG,GAAwBC,CAAyB,IAAIJ,EAAiC;AAAA,IACzF,YAAY;AAAA,IACZ,QAAQ;AAAA,EAAA,CACX,GAEKK,IAAgB,CAAC,GAAGJ,EAAU,OAAQ,CAAA;AAE5C,EAAAK,EAAU,MAAM;AACR,IAAAb,KAAeY,EAAc,SAAS,KACZE,EAAA,EAAE,KAAK,CAACC,MAAU;AACxC,MAAAJ,EAA0BI,CAAK;AAAA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import { jsxs as p, jsx as t } from "react/jsx-runtime";
2
- import { Button as S, IconLink as h, ButtonType as B, ButtonStyle as r, ButtonEmphasis as c, Modal as o, ButtonSize as L } from "@frontify/fondue";
3
- import { useOverlayTriggerState as T } from "@react-stately/overlays";
4
- import { useState as x, useEffect as E } from "react";
5
- import { DocumentLinks as O } from "./DocumentLinks.es.js";
6
- const M = ({
7
- appBridge: m,
2
+ import { Button as B, IconLink as L, ButtonType as T, ButtonStyle as r, ButtonEmphasis as c, Modal as o, ButtonSize as x } from "@frontify/fondue";
3
+ import { useOverlayTriggerState as E } from "@react-stately/overlays";
4
+ import { useState as O, useEffect as b } from "react";
5
+ import { DocumentLinks as z } from "./DocumentLinks.es.js";
6
+ const F = ({
8
7
  url: n,
9
8
  onUrlChange: s,
10
- buttonSize: u = L.Medium
9
+ buttonSize: m = x.Medium,
10
+ getAllDocuments: u,
11
+ getDocumentPagesByDocumentId: f,
12
+ getDocumentSectionsByDocumentPageId: k
11
13
  }) => {
12
- const { open: f, isOpen: k, close: l } = T({}), [i, a] = x(n), y = (e) => {
14
+ const { open: y, isOpen: D, close: l } = E({}), [i, a] = O(n), S = (e) => {
13
15
  a(e);
14
- }, D = (e) => {
16
+ }, h = (e) => {
15
17
  e.key === "Enter" && d();
16
18
  };
17
- E(() => {
19
+ b(() => {
18
20
  n && !i && a(n);
19
21
  }, [n, i]);
20
22
  const d = () => {
21
23
  s == null || s(i), l();
22
24
  };
23
- return /* @__PURE__ */ p("div", { "data-test-id": "internal-link-selector", onKeyDown: D, children: [
25
+ return /* @__PURE__ */ p("div", { "data-test-id": "internal-link-selector", onKeyDown: h, children: [
24
26
  /* @__PURE__ */ t(
25
- S,
27
+ B,
26
28
  {
27
- icon: /* @__PURE__ */ t(h, {}),
28
- size: u,
29
- type: B.Button,
29
+ icon: /* @__PURE__ */ t(L, {}),
30
+ size: m,
31
+ type: T.Button,
30
32
  style: r.Default,
31
33
  emphasis: c.Default,
32
- onClick: () => f(),
34
+ onClick: () => y(),
33
35
  children: "Internal link"
34
36
  }
35
37
  ),
36
- /* @__PURE__ */ p(o, { zIndex: 1001, onClose: () => l(), isOpen: k, isDismissable: !0, children: [
38
+ /* @__PURE__ */ p(o, { zIndex: 1001, onClose: () => l(), isOpen: D, isDismissable: !0, children: [
37
39
  /* @__PURE__ */ t(o.Header, { title: "Select internal link" }),
38
- /* @__PURE__ */ t(o.Body, { children: /* @__PURE__ */ t(O, { appBridge: m, selectedUrl: i, onSelectUrl: y }) }),
40
+ /* @__PURE__ */ t(o.Body, { children: /* @__PURE__ */ t(
41
+ z,
42
+ {
43
+ selectedUrl: i,
44
+ onSelectUrl: S,
45
+ getAllDocuments: u,
46
+ getDocumentPagesByDocumentId: f,
47
+ getDocumentSectionsByDocumentPageId: k
48
+ }
49
+ ) }),
39
50
  /* @__PURE__ */ t(
40
51
  o.Footer,
41
52
  {
@@ -62,6 +73,6 @@ const M = ({
62
73
  ] });
63
74
  };
64
75
  export {
65
- M as LinkSelector
76
+ F as LinkSelector
66
77
  };
67
78
  //# sourceMappingURL=LinkSelector.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LinkSelector.es.js","sources":["../../../../src/components/Link/LinkSelector/LinkSelector.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { AppBridgeBlock, AppBridgeTheme } from '@frontify/app-bridge';\nimport { Button, ButtonEmphasis, ButtonSize, ButtonStyle, ButtonType, IconLink, Modal } from '@frontify/fondue';\nimport { useOverlayTriggerState } from '@react-stately/overlays';\nimport { KeyboardEvent, ReactElement, useEffect, useState } from 'react';\nimport { DocumentLinks } from './DocumentLinks';\n\ntype LinkSelectorProps = {\n appBridge: AppBridgeBlock | AppBridgeTheme;\n url: string;\n onUrlChange?: (value: string) => void;\n buttonSize?: ButtonSize;\n};\n\nexport const LinkSelector = ({\n appBridge,\n url,\n onUrlChange,\n buttonSize = ButtonSize.Medium,\n}: LinkSelectorProps): ReactElement => {\n const { open: openLinkTree, isOpen: isLinkTreeOpen, close: closeLinkTree } = useOverlayTriggerState({});\n const [selectedUrl, setSelectedUrl] = useState<string>(url);\n\n const onSelectUrl = (url: string) => {\n setSelectedUrl(url);\n };\n\n const onPressEnter = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Enter') {\n saveLink();\n }\n };\n\n useEffect(() => {\n if (url && !selectedUrl) {\n setSelectedUrl(url);\n }\n }, [url, selectedUrl]);\n\n const saveLink = () => {\n onUrlChange?.(selectedUrl);\n closeLinkTree();\n };\n\n return (\n <div data-test-id=\"internal-link-selector\" onKeyDown={onPressEnter}>\n <Button\n icon={<IconLink />}\n size={buttonSize}\n type={ButtonType.Button}\n style={ButtonStyle.Default}\n emphasis={ButtonEmphasis.Default}\n onClick={() => openLinkTree()}\n >\n Internal link\n </Button>\n <Modal zIndex={1001} onClose={() => closeLinkTree()} isOpen={isLinkTreeOpen} isDismissable>\n <Modal.Header title=\"Select internal link\" />\n <Modal.Body>\n <DocumentLinks appBridge={appBridge} selectedUrl={selectedUrl} onSelectUrl={onSelectUrl} />\n </Modal.Body>\n <Modal.Footer\n buttons={[\n {\n children: 'Cancel',\n onClick: () => closeLinkTree(),\n style: ButtonStyle.Default,\n emphasis: ButtonEmphasis.Default,\n },\n {\n children: 'Choose',\n onClick: (event) => {\n event?.preventDefault();\n saveLink();\n },\n style: ButtonStyle.Default,\n emphasis: ButtonEmphasis.Strong,\n disabled: !selectedUrl,\n },\n ]}\n />\n </Modal>\n </div>\n );\n};\n"],"names":["LinkSelector","appBridge","url","onUrlChange","buttonSize","ButtonSize","openLinkTree","isLinkTreeOpen","closeLinkTree","useOverlayTriggerState","selectedUrl","setSelectedUrl","useState","onSelectUrl","onPressEnter","event","saveLink","useEffect","jsxs","jsx","Button","IconLink","ButtonType","ButtonStyle","ButtonEmphasis","Modal","DocumentLinks"],"mappings":";;;;;AAeO,MAAMA,IAAe,CAAC;AAAA,EACzB,WAAAC;AAAA,EACA,KAAAC;AAAA,EACA,aAAAC;A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AMjB,EAAc;AAAA,cAC7B,OAAOe,EAAY;AAAA,cACnB,UAAUC,EAAe;AAAA,YAC7B;AAAA,YACA;AAAA,cACI,UAAU;AAAA,cACV,SAAS,CAACT,MAAU;AAChB,gBAAAA,KAAA,QAAAA,EAAO,kBACEC;cACb;AAAA,cACA,OAAOO,EAAY;AAAA,cACnB,UAAUC,EAAe;AAAA,cACzB,UAAU,CAACd;AAAA,YACf;AAAA,UACJ;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA,GACJ;AAAA,EACJ,EAAA,CAAA;AAER;"}
1
+ {"version":3,"file":"LinkSelector.es.js","sources":["../../../../src/components/Link/LinkSelector/LinkSelector.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { Document, DocumentPage, DocumentSection } from '@frontify/app-bridge';\nimport { Button, ButtonEmphasis, ButtonSize, ButtonStyle, ButtonType, IconLink, Modal } from '@frontify/fondue';\nimport { useOverlayTriggerState } from '@react-stately/overlays';\nimport { KeyboardEvent, ReactElement, useEffect, useState } from 'react';\nimport { DocumentLinks } from './DocumentLinks';\n\ntype LinkSelectorProps = {\n url: string;\n onUrlChange?: (value: string) => void;\n buttonSize?: ButtonSize;\n getAllDocuments: () => Promise<Document[]>;\n getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;\n getDocumentPagesByDocumentId: (documentId: number) => Promise<DocumentPage[]>;\n};\n\nexport const LinkSelector = ({\n url,\n onUrlChange,\n buttonSize = ButtonSize.Medium,\n getAllDocuments,\n getDocumentPagesByDocumentId,\n getDocumentSectionsByDocumentPageId,\n}: LinkSelectorProps): ReactElement => {\n const { open: openLinkTree, isOpen: isLinkTreeOpen, close: closeLinkTree } = useOverlayTriggerState({});\n const [selectedUrl, setSelectedUrl] = useState<string>(url);\n\n const onSelectUrl = (url: string) => {\n setSelectedUrl(url);\n };\n\n const onPressEnter = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Enter') {\n saveLink();\n }\n };\n\n useEffect(() => {\n if (url && !selectedUrl) {\n setSelectedUrl(url);\n }\n }, [url, selectedUrl]);\n\n const saveLink = () => {\n onUrlChange?.(selectedUrl);\n closeLinkTree();\n };\n\n return (\n <div data-test-id=\"internal-link-selector\" onKeyDown={onPressEnter}>\n <Button\n icon={<IconLink />}\n size={buttonSize}\n type={ButtonType.Button}\n style={ButtonStyle.Default}\n emphasis={ButtonEmphasis.Default}\n onClick={() => openLinkTree()}\n >\n Internal link\n </Button>\n <Modal zIndex={1001} onClose={() => closeLinkTree()} isOpen={isLinkTreeOpen} isDismissable>\n <Modal.Header title=\"Select internal link\" />\n <Modal.Body>\n <DocumentLinks\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n getAllDocuments={getAllDocuments}\n getDocumentPagesByDocumentId={getDocumentPagesByDocumentId}\n getDocumentSectionsByDocumentPageId={getDocumentSectionsByDocumentPageId}\n />\n </Modal.Body>\n <Modal.Footer\n buttons={[\n {\n children: 'Cancel',\n onClick: () => closeLinkTree(),\n style: ButtonStyle.Default,\n emphasis: ButtonEmphasis.Default,\n },\n {\n children: 'Choose',\n onClick: (event) => {\n event?.preventDefault();\n saveLink();\n },\n style: ButtonStyle.Default,\n emphasis: ButtonEmphasis.Strong,\n disabled: !selectedUrl,\n },\n ]}\n />\n </Modal>\n </div>\n );\n};\n"],"names":["LinkSelector","url","onUrlChange","buttonSize","ButtonSize","getAllDocuments","getDocumentPagesByDocumentId","getDocumentSectionsByDocumentPageId","openLinkTree","isLinkTreeOpen","closeLinkTree","useOverlayTriggerState","selectedUrl","setSelectedUrl","useState","onSelectUrl","onPressEnter","event","saveLink","useEffect","jsxs","jsx","Button","IconLink","ButtonType","ButtonStyle","ButtonEmphasis","Modal","DocumentLinks"],"mappings":";;;;;AAiBO,MAAMA,IAAe,CAAC;AAAA,EACzB,KAAAC;AAAA,EACA,aAAAC;AAAA,EACA,YAAAC,IAAaC,EAAW;AAAA,EACxB,iBAAAC;AAAA,EACA,8BA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AAA,QAAN;AAAA,UACG,SAAS;AAAA,YACL;AAAA,cACI,UAAU;AAAA,cACV,SAAS,MAAMjB,EAAc;AAAA,cAC7B,OAAOe,EAAY;AAAA,cACnB,UAAUC,EAAe;AAAA,YAC7B;AAAA,YACA;AAAA,cACI,UAAU;AAAA,cACV,SAAS,CAACT,MAAU;AAChB,gBAAAA,KAAA,QAAAA,EAAO,kBACEC;cACb;AAAA,cACA,OAAOO,EAAY;AAAA,cACnB,UAAUC,EAAe;AAAA,cACzB,UAAU,CAACd;AAAA,YACf;AAAA,UACJ;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA,GACJ;AAAA,EACJ,EAAA,CAAA;AAER;"}
@@ -1,34 +1,46 @@
1
- import { jsxs as l, Fragment as b, jsx as e } from "react/jsx-runtime";
2
- import { useDocumentSection as p } from "@frontify/app-bridge";
3
- import { merge as d } from "@frontify/fondue";
4
- import { useState as u, useEffect as f } from "react";
5
- import { SectionLink as v } from "./SectionLink.es.js";
6
- const j = ({ page: t, selectedUrl: s, onSelectUrl: i, itemsToExpandInitially: r, appBridge: m }) => {
7
- const [n, w] = u(t.id === r.documentId), x = t.permanentLink === s, { documentSections: h } = p(m, t.id), o = [...h.values()], c = o.length > 0;
8
- return f(() => {
9
- t.id === r.pageId && w(!0);
10
- }, [r, t.id]), /* @__PURE__ */ l(b, { children: [
1
+ import { jsxs as d, Fragment as v, jsx as e } from "react/jsx-runtime";
2
+ import { merge as m } from "@frontify/fondue";
3
+ import { useState as h, useEffect as x } from "react";
4
+ import { SectionLink as g } from "./SectionLink.es.js";
5
+ const j = ({
6
+ page: t,
7
+ selectedUrl: i,
8
+ onSelectUrl: w,
9
+ itemsToExpandInitially: r,
10
+ getDocumentSectionsByDocumentPageId: c
11
+ }) => {
12
+ const [n, a] = h(t.id === r.documentId), [b, f] = h([]), u = t.permanentLink === i;
13
+ x(() => {
14
+ (async () => {
15
+ const p = await c(t.id);
16
+ f(p);
17
+ })();
18
+ }, [t.id, c]), x(() => {
19
+ t.id === r.pageId && a(!0);
20
+ }, [r, t.id]);
21
+ const s = [...b.values()], l = s.length > 0;
22
+ return /* @__PURE__ */ d(v, { children: [
11
23
  /* @__PURE__ */ e(
12
24
  "button",
13
25
  {
14
26
  "data-test-id": "internal-link-selector-page-link",
15
- className: d([
27
+ className: m([
16
28
  "tw-py-2 tw-pr-2.5 tw-leading-5 tw-cursor-pointer tw-flex tw-w-full",
17
- c ? "tw-pl-7" : "tw-pl-12",
18
- x ? "tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover" : "hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover"
29
+ l ? "tw-pl-7" : "tw-pl-12",
30
+ u ? "tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover" : "hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover"
19
31
  ]),
20
- onClick: () => i(t.permanentLink),
21
- children: /* @__PURE__ */ l("div", { className: "tw-flex tw-flex-1 tw-space-x-1 tw-items-center tw-h-6", children: [
22
- c && /* @__PURE__ */ e(
32
+ onClick: () => w(t.permanentLink),
33
+ children: /* @__PURE__ */ d("div", { className: "tw-flex tw-flex-1 tw-space-x-1 tw-items-center tw-h-6", children: [
34
+ l && /* @__PURE__ */ e(
23
35
  "button",
24
36
  {
25
37
  "data-test-id": "tree-item-toggle",
26
38
  className: "tw-flex tw-items-center tw-justify-center -tw-mr-2 tw-pr-3.5 tw-pt-1.5 tw-pb-1.5 tw-pl-3.5 tw-cursor-pointer",
27
- onClick: () => w(!n),
39
+ onClick: () => a(!n),
28
40
  children: /* @__PURE__ */ e(
29
41
  "div",
30
42
  {
31
- className: d([
43
+ className: m([
32
44
  "tw-transition-transform tw-w-0 tw-h-0 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong",
33
45
  n ? "tw-rotate-90" : ""
34
46
  ])
@@ -41,14 +53,14 @@ const j = ({ page: t, selectedUrl: s, onSelectUrl: i, itemsToExpandInitially: r,
41
53
  ] }, t.id)
42
54
  }
43
55
  ),
44
- n && o.length > 0 && o.map((a) => /* @__PURE__ */ e(
45
- v,
56
+ n && s.length > 0 && s.map((o) => /* @__PURE__ */ e(
57
+ g,
46
58
  {
47
- section: a,
48
- selectedUrl: s,
49
- onSelectUrl: i
59
+ section: o,
60
+ selectedUrl: i,
61
+ onSelectUrl: w
50
62
  },
51
- a.id
63
+ o.id
52
64
  ))
53
65
  ] });
54
66
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PageLink.es.js","sources":["../../../../src/components/Link/LinkSelector/PageLink.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { AppBridgeBlock, AppBridgeTheme, useDocumentSection } from '@frontify/app-bridge';\nimport { merge } from '@frontify/fondue';\nimport { useEffect, useState } from 'react';\nimport { InitiallyExpandedItems } from '../';\nimport { SectionLink } from './SectionLink';\n\ntype DocumentLinkProps = {\n page: {\n id: number;\n title: string;\n permanentLink: string;\n };\n selectedUrl: string;\n onSelectUrl: (url: string) => void;\n appBridge: AppBridgeBlock | AppBridgeTheme;\n itemsToExpandInitially: InitiallyExpandedItems;\n};\n\nexport const PageLink = ({ page, selectedUrl, onSelectUrl, itemsToExpandInitially, appBridge }: DocumentLinkProps) => {\n const [isExpanded, setIsExpanded] = useState(page.id === itemsToExpandInitially.documentId);\n const isActive = page.permanentLink === selectedUrl;\n const { documentSections } = useDocumentSection(appBridge, page.id);\n const sectionsArray = [...documentSections.values()];\n const hasSections = sectionsArray.length > 0;\n\n useEffect(() => {\n if (page.id === itemsToExpandInitially.pageId) {\n setIsExpanded(true);\n }\n }, [itemsToExpandInitially, page.id]);\n\n return (\n <>\n <button\n data-test-id=\"internal-link-selector-page-link\"\n className={merge([\n 'tw-py-2 tw-pr-2.5 tw-leading-5 tw-cursor-pointer tw-flex tw-w-full',\n hasSections ? 'tw-pl-7' : 'tw-pl-12',\n isActive\n ? 'tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover'\n : 'hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover',\n ])}\n onClick={() => onSelectUrl(page.permanentLink)}\n >\n <div key={page.id} className=\"tw-flex tw-flex-1 tw-space-x-1 tw-items-center tw-h-6\">\n {hasSections && (\n <button\n data-test-id=\"tree-item-toggle\"\n className=\"tw-flex tw-items-center tw-justify-center -tw-mr-2 tw-pr-3.5 tw-pt-1.5 tw-pb-1.5 tw-pl-3.5 tw-cursor-pointer\"\n onClick={() => setIsExpanded(!isExpanded)}\n >\n <div\n className={merge([\n 'tw-transition-transform tw-w-0 tw-h-0 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong',\n isExpanded ? 'tw-rotate-90' : '',\n ])}\n ></div>\n </button>\n )}\n <span className=\"tw-text-s\">{page.title}</span>\n <span className=\"tw-flex-auto tw-font-sans tw-text-xs tw-text-right\">Page</span>\n </div>\n </button>\n {isExpanded &&\n sectionsArray.length > 0 &&\n sectionsArray.map((section) => {\n return (\n <SectionLink\n key={section.id}\n section={section}\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n />\n );\n })}\n </>\n );\n};\n"],"names":["PageLink","page","selectedUrl","onSelectUrl","itemsToExpandInitially","appBridge","isExpanded","setIsExpanded","useState","isActive","documentSections","useDocumentSection","sectionsArray","hasSections","useEffect","jsxs","Fragment","jsx","merge","section","SectionLink"],"mappings":";;;;;AAoBa,MAAAA,IAAW,CAAC,EAAE,MAAAC,GAAM,aAAAC,GAAa,aAAAC,GAAa,wBAAAC,GAAwB,WAAAC,QAAmC;AAC5G,QAAA,CAACC,GAAYC,CAAa,IAAIC,EAASP,EAA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AA,MAAA;AAAA,QAEG,SAAAD;AAAA,QACA,aAAAjB;AAAA,QACA,aAAAC;AAAA,MAAA;AAAA,MAHKgB,EAAQ;AAAA,IAAA,CAMxB;AAAA,EACT,EAAA,CAAA;AAER;"}
1
+ {"version":3,"file":"PageLink.es.js","sources":["../../../../src/components/Link/LinkSelector/PageLink.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { type DocumentSection } from '@frontify/app-bridge';\nimport { merge } from '@frontify/fondue';\nimport { useEffect, useState } from 'react';\nimport { InitiallyExpandedItems } from '../';\nimport { SectionLink } from './SectionLink';\n\ntype PageLinkProps = {\n page: {\n id: number;\n title: string;\n permanentLink: string;\n };\n selectedUrl: string;\n onSelectUrl: (url: string) => void;\n itemsToExpandInitially: InitiallyExpandedItems;\n getDocumentSectionsByDocumentPageId: (documentPageId: number) => Promise<DocumentSection[]>;\n};\n\nexport const PageLink = ({\n page,\n selectedUrl,\n onSelectUrl,\n itemsToExpandInitially,\n getDocumentSectionsByDocumentPageId,\n}: PageLinkProps) => {\n const [isExpanded, setIsExpanded] = useState(page.id === itemsToExpandInitially.documentId);\n const [documentSections, setDocumentSections] = useState<DocumentSection[]>([]);\n const isActive = page.permanentLink === selectedUrl;\n\n useEffect(() => {\n const fetchDocumentSections = async () => {\n const sections = await getDocumentSectionsByDocumentPageId(page.id);\n setDocumentSections(sections);\n };\n\n fetchDocumentSections();\n }, [page.id, getDocumentSectionsByDocumentPageId]);\n\n useEffect(() => {\n if (page.id === itemsToExpandInitially.pageId) {\n setIsExpanded(true);\n }\n }, [itemsToExpandInitially, page.id]);\n\n const sectionsArray = [...documentSections.values()];\n const hasSections = sectionsArray.length > 0;\n\n return (\n <>\n <button\n data-test-id=\"internal-link-selector-page-link\"\n className={merge([\n 'tw-py-2 tw-pr-2.5 tw-leading-5 tw-cursor-pointer tw-flex tw-w-full',\n hasSections ? 'tw-pl-7' : 'tw-pl-12',\n isActive\n ? 'tw-bg-box-selected-strong tw-text-box-selected-strong-inverse hover:tw-bg-box-selected-strong-hover:hover hover:tw-text-box-selected-strong-inverse-hover:hover'\n : 'hover:tw-bg-box-neutral-hover hover:tw-text-box-neutral-inverse-hover',\n ])}\n onClick={() => onSelectUrl(page.permanentLink)}\n >\n <div key={page.id} className=\"tw-flex tw-flex-1 tw-space-x-1 tw-items-center tw-h-6\">\n {hasSections && (\n <button\n data-test-id=\"tree-item-toggle\"\n className=\"tw-flex tw-items-center tw-justify-center -tw-mr-2 tw-pr-3.5 tw-pt-1.5 tw-pb-1.5 tw-pl-3.5 tw-cursor-pointer\"\n onClick={() => setIsExpanded(!isExpanded)}\n >\n <div\n className={merge([\n 'tw-transition-transform tw-w-0 tw-h-0 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong',\n isExpanded ? 'tw-rotate-90' : '',\n ])}\n ></div>\n </button>\n )}\n <span className=\"tw-text-s\">{page.title}</span>\n <span className=\"tw-flex-auto tw-font-sans tw-text-xs tw-text-right\">Page</span>\n </div>\n </button>\n {isExpanded &&\n sectionsArray.length > 0 &&\n sectionsArray.map((section) => {\n return (\n <SectionLink\n key={section.id}\n section={section}\n selectedUrl={selectedUrl}\n onSelectUrl={onSelectUrl}\n />\n );\n })}\n </>\n );\n};\n"],"names":["PageLink","page","selectedUrl","onSelectUrl","itemsToExpandInitially","getDocumentSectionsByDocumentPageId","isExpanded","setIsExpanded","useState","documentSections","setDocumentSections","isActive","useEffect","sections","sectionsArray","hasSections","jsxs","Fragment","jsx","merge","section","SectionLink"],"mappings":";;;;AAoBO,MAAMA,IAAW,CAAC;AAAA,EACrB,MAAAC;AAAA,EACA,aAAAC;AAAA,EACA,aAAAC;AAAA,EACA,wBAAAC;AAAA,EACA,qCAAAC;AACJ,MAAqB;AACX,QAAA,CAACC,GAAYC,CAAa,IAAIC,EAASP,EAAK,OAAOG,EAAuB,UAAU,GACpF,CAACK,GAAkBC,CAAmB,IAAIF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