@defra/forms-model 3.0.503 → 3.0.505

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.
@@ -24,6 +24,16 @@ export function isConditionalType(type) {
24
24
  return !!type && allowedTypes.includes(type);
25
25
  }
26
26
 
27
+ /**
28
+ * Check if the component type is supported for conditional reveal.
29
+ * As of today this is just content types, but we're providing this as a wrapper
30
+ * function for clarity.
31
+ * @param type - Component type to check
32
+ */
33
+ export function isConditionalRevealType(type) {
34
+ return isContentType(type);
35
+ }
36
+
27
37
  /**
28
38
  * Filter known components with content (textarea or list)
29
39
  */
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":["ComponentTypes","ComponentType","getComponentDefaults","component","defaults","find","type","Error","structuredClone","hasConditionSupport","isConditionalType","allowedTypes","AutocompleteField","RadiosField","CheckboxesField","DatePartsField","EmailAddressField","MultilineTextField","TelephoneNumberField","NumberField","SelectField","TextField","YesNoField","includes","hasContent","isContentType","hasContentField","deniedTypes","List","Details","Html","Markdown","InsetText","hasFormField","isFormType","hasListField","isListType","hasInputField","hasSelectionFields","hasTitle","hasHint"],"sources":["../../../src/components/helpers.ts"],"sourcesContent":["import { ComponentTypes } from '~/src/components/component-types.js'\nimport { ComponentType } from '~/src/components/enums.js'\nimport {\n type ComponentDef,\n type ConditionalComponentType,\n type ConditionalComponentsDef,\n type ContentComponentsDef,\n type FormComponentsDef,\n type HtmlComponent,\n type InputFieldsComponentsDef,\n type InsetTextComponent,\n type ListComponent,\n type ListComponentsDef,\n type MarkdownComponent,\n type SelectionComponentsDef\n} from '~/src/components/types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getComponentDefaults<FieldType extends ComponentDef>(\n component?: Pick<FieldType, 'type'>\n) {\n const defaults = ComponentTypes.find(({ type }) => type === component?.type)\n\n if (!defaults) {\n throw new Error(\n `Defaults not found for component type '${component?.type}'`\n )\n }\n\n return structuredClone(defaults) as FieldType\n}\n\n/**\n * Filter known components with support for conditions\n */\nexport function hasConditionSupport(\n component?: Partial<ComponentDef>\n): component is ConditionalComponentsDef {\n return isConditionalType(component?.type)\n}\n\nexport function isConditionalType(\n type?: ComponentType\n): type is ConditionalComponentType {\n const allowedTypes = [\n ComponentType.AutocompleteField,\n ComponentType.RadiosField,\n ComponentType.CheckboxesField,\n ComponentType.DatePartsField,\n ComponentType.EmailAddressField,\n ComponentType.MultilineTextField,\n ComponentType.TelephoneNumberField,\n ComponentType.NumberField,\n ComponentType.SelectField,\n ComponentType.TextField,\n ComponentType.YesNoField\n ]\n\n return !!type && allowedTypes.includes(type)\n}\n\n/**\n * Filter known components with content (textarea or list)\n */\nexport function hasContent(\n component?: Partial<ComponentDef>\n): component is ContentComponentsDef {\n return isContentType(component?.type)\n}\n\n/**\n * Filter known components with content textarea\n */\nexport function hasContentField(\n component?: Partial<ComponentDef>\n): component is Exclude<ContentComponentsDef, ListComponent> {\n const deniedTypes = [ComponentType.List]\n return hasContent(component) && !deniedTypes.includes(component.type)\n}\n\nexport function isContentType(\n type?: ComponentType\n): type is ContentComponentsDef['type'] {\n const allowedTypes = [\n ComponentType.Details,\n ComponentType.Html,\n ComponentType.Markdown,\n ComponentType.InsetText,\n ComponentType.List\n ]\n\n return !!type && allowedTypes.includes(type)\n}\n\n/**\n * Filter known components with form fields\n * (includes input fields and selection fields)\n */\nexport function hasFormField(\n component?: Partial<ComponentDef>\n): component is FormComponentsDef {\n return isFormType(component?.type)\n}\n\nexport function isFormType(\n type?: ComponentType\n): type is FormComponentsDef['type'] {\n return !!type && !isContentType(type)\n}\n\n/**\n * Filter known components with lists\n */\nexport function hasListField(\n component?: Partial<ComponentDef>\n): component is ListComponentsDef {\n return isListType(component?.type)\n}\n\nexport function isListType(\n type?: ComponentType\n): type is ListComponentsDef['type'] {\n const allowedTypes = [\n ComponentType.AutocompleteField,\n ComponentType.List,\n ComponentType.RadiosField,\n ComponentType.SelectField,\n ComponentType.CheckboxesField\n ]\n\n return !!type && allowedTypes.includes(type)\n}\n\n/**\n * Filter known form components with input fields\n * (excludes content and selection fields)\n */\nexport function hasInputField(\n component?: Partial<ComponentDef>\n): component is InputFieldsComponentsDef {\n return hasFormField(component) && !hasSelectionFields(component)\n}\n\n/**\n * Filter known form components with selection fields\n * (excludes content and input fields)\n */\nexport function hasSelectionFields(\n component?: Partial<ComponentDef>\n): component is SelectionComponentsDef {\n const allowedTypes = [\n ComponentType.AutocompleteField,\n ComponentType.CheckboxesField,\n ComponentType.RadiosField,\n ComponentType.SelectField,\n ComponentType.YesNoField\n ]\n\n return !!component?.type && allowedTypes.includes(component.type)\n}\n\n/**\n * Filter known components with titles\n */\nexport function hasTitle(\n component?: Partial<ComponentDef>\n): component is Exclude<\n ComponentDef,\n InsetTextComponent | HtmlComponent | MarkdownComponent\n> {\n const deniedTypes = [\n ComponentType.InsetText,\n ComponentType.Html,\n ComponentType.Markdown\n ]\n return !!component?.type && !deniedTypes.includes(component.type)\n}\n\n/**\n * Filter known components with hint text\n */\nexport function hasHint(\n component?: Partial<ComponentDef>\n): component is FormComponentsDef | ListComponent {\n return isFormType(component?.type) || component?.type === ComponentType.List\n}\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SAASC,aAAa;AAgBtB;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClCC,SAAmC,EACnC;EACA,MAAMC,QAAQ,GAAGJ,cAAc,CAACK,IAAI,CAAC,CAAC;IAAEC;EAAK,CAAC,KAAKA,IAAI,KAAKH,SAAS,EAAEG,IAAI,CAAC;EAE5E,IAAI,CAACF,QAAQ,EAAE;IACb,MAAM,IAAIG,KAAK,CACb,0CAA0CJ,SAAS,EAAEG,IAAI,GAC3D,CAAC;EACH;EAEA,OAAOE,eAAe,CAACJ,QAAQ,CAAC;AAClC;;AAEA;AACA;AACA;AACA,OAAO,SAASK,mBAAmBA,CACjCN,SAAiC,EACM;EACvC,OAAOO,iBAAiB,CAACP,SAAS,EAAEG,IAAI,CAAC;AAC3C;AAEA,OAAO,SAASI,i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,CAAC8B,QAAQ,CACvB;EACD,OAAO,CAAC,CAAC5B,SAAS,EAAEG,IAAI,IAAI,CAACqB,WAAW,CAACJ,QAAQ,CAACpB,SAAS,CAACG,IAAI,CAAC;AACnE;;AAEA;AACA;AACA;AACA,OAAO,SAASkC,OAAOA,CACrBrC,SAAiC,EACe;EAChD,OAAO+B,UAAU,CAAC/B,SAAS,EAAEG,IAAI,CAAC,IAAIH,SAAS,EAAEG,IAAI,KAAKL,aAAa,CAAC2B,IAAI;AAC9E","ignoreList":[]}
1
+ {"version":3,"file":"helpers.js","names":["ComponentTypes","ComponentType","getComponentDefaults","component","defaults","find","type","Error","structuredClone","hasConditionSupport","isConditionalType","allowedTypes","AutocompleteField","RadiosField","CheckboxesField","DatePartsField","EmailAddressField","MultilineTextField","TelephoneNumberField","NumberField","SelectField","TextField","YesNoField","includes","isConditionalRevealType","isContentType","hasContent","hasContentField","deniedTypes","List","Details","Html","Markdown","InsetText","hasFormField","isFormType","hasListField","isListType","hasInputField","hasSelectionFields","hasTitle","hasHint"],"sources":["../../../src/components/helpers.ts"],"sourcesContent":["import { ComponentTypes } from '~/src/components/component-types.js'\nimport { ComponentType } from '~/src/components/enums.js'\nimport {\n type ComponentDef,\n type ConditionalComponentType,\n type ConditionalComponentsDef,\n type ContentComponentsDef,\n type FormComponentsDef,\n type HtmlComponent,\n type InputFieldsComponentsDef,\n type InsetTextComponent,\n type ListComponent,\n type ListComponentsDef,\n type MarkdownComponent,\n type SelectionComponentsDef\n} from '~/src/components/types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getComponentDefaults<FieldType extends ComponentDef>(\n component?: Pick<FieldType, 'type'>\n) {\n const defaults = ComponentTypes.find(({ type }) => type === component?.type)\n\n if (!defaults) {\n throw new Error(\n `Defaults not found for component type '${component?.type}'`\n )\n }\n\n return structuredClone(defaults) as FieldType\n}\n\n/**\n * Filter known components with support for conditions\n */\nexport function hasConditionSupport(\n component?: Partial<ComponentDef>\n): component is ConditionalComponentsDef {\n return isConditionalType(component?.type)\n}\n\nexport function isConditionalType(\n type?: ComponentType\n): type is ConditionalComponentType {\n const allowedTypes = [\n ComponentType.AutocompleteField,\n ComponentType.RadiosField,\n ComponentType.CheckboxesField,\n ComponentType.DatePartsField,\n ComponentType.EmailAddressField,\n ComponentType.MultilineTextField,\n ComponentType.TelephoneNumberField,\n ComponentType.NumberField,\n ComponentType.SelectField,\n ComponentType.TextField,\n ComponentType.YesNoField\n ]\n\n return !!type && allowedTypes.includes(type)\n}\n\n/**\n * Check if the component type is supported for conditional reveal.\n * As of today this is just content types, but we're providing this as a wrapper\n * function for clarity.\n * @param type - Component type to check\n */\nexport function isConditionalRevealType(type: ComponentType) {\n return isContentType(type)\n}\n\n/**\n * Filter known components with content (textarea or list)\n */\nexport function hasContent(\n component?: Partial<ComponentDef>\n): component is ContentComponentsDef {\n return isContentType(component?.type)\n}\n\n/**\n * Filter known components with content textarea\n */\nexport function hasContentField(\n component?: Partial<ComponentDef>\n): component is Exclude<ContentComponentsDef, ListComponent> {\n const deniedTypes = [ComponentType.List]\n return hasContent(component) && !deniedTypes.includes(component.type)\n}\n\nexport function isContentType(\n type?: ComponentType\n): type is ContentComponentsDef['type'] {\n const allowedTypes = [\n ComponentType.Details,\n ComponentType.Html,\n ComponentType.Markdown,\n ComponentType.InsetText,\n ComponentType.List\n ]\n\n return !!type && allowedTypes.includes(type)\n}\n\n/**\n * Filter known components with form fields\n * (includes input fields and selection fields)\n */\nexport function hasFormField(\n component?: Partial<ComponentDef>\n): component is FormComponentsDef {\n return isFormType(component?.type)\n}\n\nexport function isFormType(\n type?: ComponentType\n): type is FormComponentsDef['type'] {\n return !!type && !isContentType(type)\n}\n\n/**\n * Filter known components with lists\n */\nexport function hasListField(\n component?: Partial<ComponentDef>\n): component is ListComponentsDef {\n return isListType(component?.type)\n}\n\nexport function isListType(\n type?: ComponentType\n): type is ListComponentsDef['type'] {\n const allowedTypes = [\n ComponentType.AutocompleteField,\n ComponentType.List,\n ComponentType.RadiosField,\n ComponentType.SelectField,\n ComponentType.CheckboxesField\n ]\n\n return !!type && allowedTypes.includes(type)\n}\n\n/**\n * Filter known form components with input fields\n * (excludes content and selection fields)\n */\nexport function hasInputField(\n component?: Partial<ComponentDef>\n): component is InputFieldsComponentsDef {\n return hasFormField(component) && !hasSelectionFields(component)\n}\n\n/**\n * Filter known form components with selection fields\n * (excludes content and input fields)\n */\nexport function hasSelectionFields(\n component?: Partial<ComponentDef>\n): component is SelectionComponentsDef {\n const allowedTypes = [\n ComponentType.AutocompleteField,\n ComponentType.CheckboxesField,\n ComponentType.RadiosField,\n ComponentType.SelectField,\n ComponentType.YesNoField\n ]\n\n return !!component?.type && allowedTypes.includes(component.type)\n}\n\n/**\n * Filter known components with titles\n */\nexport function hasTitle(\n component?: Partial<ComponentDef>\n): component is Exclude<\n ComponentDef,\n InsetTextComponent | HtmlComponent | MarkdownComponent\n> {\n const deniedTypes = [\n ComponentType.InsetText,\n ComponentType.Html,\n ComponentType.Markdown\n ]\n return !!component?.type && !deniedTypes.includes(component.type)\n}\n\n/**\n * Filter known components with hint text\n */\nexport function hasHint(\n component?: Partial<ComponentDef>\n): component is FormComponentsDef | ListComponent {\n return isFormType(component?.type) || component?.type === ComponentType.List\n}\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SAASC,aAAa;AAgBtB;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClCC,SAAmC,EACnC;EACA,MAAMC,QAAQ,GAAGJ,cAAc,CAACK,IAAI,CAAC,CAAC;IAAEC;EAAK,CAAC,KAAKA,IAAI,KAAKH,SAAS,EAAEG,IAAI,CAAC;EAE5E,IAAI,CAACF,QAAQ,EAAE;IACb,MAAM,IAAIG,KAAK,CACb,0CAA0CJ,SAAS,EAAEG,IAAI,GAC3D,CAAC;EACH;EAEA,OAAOE,eAAe,CAACJ,QAAQ,CAAC;AAClC;;AAEA;AACA;AACA;AACA,OAAO,SAASK,mBAAmBA,CACjCN,SAAiC,EACM;EACvC,OAAO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AAS,CAACG,IAAI,CAAC;AACnE;;AAEA;AACA;AACA;AACA,OAAO,SAASkC,QAAQA,CACtBrC,SAAiC,EAIjC;EACA,MAAMyB,WAAW,GAAG,CAClB3B,aAAa,CAACgC,SAAS,EACvBhC,aAAa,CAAC8B,IAAI,EAClB9B,aAAa,CAAC+B,QAAQ,CACvB;EACD,OAAO,CAAC,CAAC7B,SAAS,EAAEG,IAAI,IAAI,CAACsB,WAAW,CAACL,QAAQ,CAACpB,SAAS,CAACG,IAAI,CAAC;AACnE;;AAEA;AACA;AACA;AACA,OAAO,SAASmC,OAAOA,CACrBtC,SAAiC,EACe;EAChD,OAAOgC,UAAU,CAAChC,SAAS,EAAEG,IAAI,CAAC,IAAIH,SAAS,EAAEG,IAAI,KAAKL,aAAa,CAAC4B,IAAI;AAC9E","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  export { ComponentTypes } from "./component-types.js";
2
- export { getComponentDefaults, hasConditionSupport, hasContent, hasContentField, hasFormField, hasHint, hasInputField, hasListField, hasSelectionFields, hasTitle, isConditionalType, isContentType, isFormType, isListType } from "./helpers.js";
2
+ export { ComponentType } from "./enums.js";
3
3
  export { allDocumentTypes, allImageTypes, allTabularDataTypes } from "./file-types.js";
4
+ export { getComponentDefaults, hasConditionSupport, hasContent, hasContentField, hasFormField, hasHint, hasInputField, hasListField, hasSelectionFields, hasTitle, isConditionalRevealType, isConditionalType, isContentType, isFormType, isListType } from "./helpers.js";
4
5
  export { getYesNoList, yesNoListId, yesNoListName, yesNoListNoItemId, yesNoListYesItemId } from "./yes-no-helper.js";
5
- export { ComponentType } from "./enums.js";
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ComponentTypes","getComponentDefaults","hasConditionSupport","hasContent","hasContentField","hasFormField","hasHint","hasInputField","hasListField","hasSelectionFields","hasTitle","isConditionalType","isContentType","isFormType","isListType","allDocumentTypes","allImageTypes","allTabularDataTypes","getYesNoList","yesNoListId","yesNoListName","yesNoListNoItemId","yesNoListYesItemId","ComponentType"],"sources":["../../../src/components/index.ts"],"sourcesContent":["export { ComponentTypes } from '~/src/components/component-types.js'\nexport {\n getComponentDefaults,\n hasConditionSupport,\n hasContent,\n hasContentField,\n hasFormField,\n hasHint,\n hasInputField,\n hasListField,\n hasSelectionFields,\n hasTitle,\n isConditionalType,\n isContentType,\n isFormType,\n isListType\n} from '~/src/components/helpers.js'\nexport {\n allDocumentTypes,\n allImageTypes,\n allTabularDataTypes\n} from '~/src/components/file-types.js'\nexport {\n getYesNoList,\n yesNoListId,\n yesNoListName,\n yesNoListNoItemId,\n yesNoListYesItemId\n} from '~/src/components/yes-no-helper.js'\nexport { ComponentType } from '~/src/components/enums.js'\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SACEC,oBAAoB,EACpBC,mBAAmB,EACnBC,UAAU,EACVC,eAAe,EACfC,YAAY,EACZC,OAAO,EACPC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,QAAQ,EACRC,iBAAiB,EACjBC,aAAa,EACbC,UAAU,EACVC,UAAU;AAEZ,SACEC,gBAAgB,EAChBC,aAAa,EACbC,mBAAmB;AAErB,SACEC,YAAY,EACZC,WAAW,EACXC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB;AAEpB,SAASC,aAAa","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["ComponentTypes","ComponentType","allDocumentTypes","allImageTypes","allTabularDataTypes","getComponentDefaults","hasConditionSupport","hasContent","hasContentField","hasFormField","hasHint","hasInputField","hasListField","hasSelectionFields","hasTitle","isConditionalRevealType","isConditionalType","isContentType","isFormType","isListType","getYesNoList","yesNoListId","yesNoListName","yesNoListNoItemId","yesNoListYesItemId"],"sources":["../../../src/components/index.ts"],"sourcesContent":["export { ComponentTypes } from '~/src/components/component-types.js'\nexport { ComponentType } from '~/src/components/enums.js'\nexport {\n allDocumentTypes,\n allImageTypes,\n allTabularDataTypes\n} from '~/src/components/file-types.js'\nexport {\n getComponentDefaults,\n hasConditionSupport,\n hasContent,\n hasContentField,\n hasFormField,\n hasHint,\n hasInputField,\n hasListField,\n hasSelectionFields,\n hasTitle,\n isConditionalRevealType,\n isConditionalType,\n isContentType,\n isFormType,\n isListType\n} from '~/src/components/helpers.js'\nexport {\n getYesNoList,\n yesNoListId,\n yesNoListName,\n yesNoListNoItemId,\n yesNoListYesItemId\n} from '~/src/components/yes-no-helper.js'\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SAASC,aAAa;AACtB,SACEC,gBAAgB,EAChBC,aAAa,EACbC,mBAAmB;AAErB,SACEC,oBAAoB,EACpBC,mBAAmB,EACnBC,UAAU,EACVC,eAAe,EACfC,YAAY,EACZC,OAAO,EACPC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,QAAQ,EACRC,uBAAuB,EACvBC,iBAAiB,EACjBC,aAAa,EACbC,UAAU,EACVC,UAAU;AAEZ,SACEC,YAAY,EACZC,WAAW,EACXC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { Marked } from 'marked';
1
+ import { Marked, Renderer } from 'marked';
2
2
 
3
3
  /**
4
4
  * Marked instance (avoids global option/extension scope)
@@ -7,17 +7,37 @@ export const marked = new Marked({
7
7
  breaks: true,
8
8
  gfm: true
9
9
  });
10
+ function renderLink(href, text, baseUrl) {
11
+ let isLocalLink = true;
12
+ if (baseUrl) {
13
+ isLocalLink = href.startsWith(baseUrl) || href.startsWith('mailto:');
14
+ }
15
+ const attrs = [`class="govuk-link"`, `href="${href}"`];
16
+ if (!isLocalLink) {
17
+ attrs.push(`target="_blank" rel="noreferrer noopener"`);
18
+ }
19
+ const label = !isLocalLink ? `${text} (opens in new tab)` : text;
20
+ return `<a ${attrs.join(' ')}>${label}</a>`;
21
+ }
10
22
 
11
23
  /**
12
24
  * Convert markdown to HTML, escaping any HTML tags first
13
25
  */
14
- export function markdownToHtml(markdown) {
26
+ export function markdownToHtml(markdown, baseUrl) {
15
27
  if (markdown === undefined || markdown === null) {
16
28
  return '';
17
29
  }
18
30
  const escaped = markdown.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
31
+ const renderer = new Renderer();
32
+ renderer.link = ({
33
+ href,
34
+ text
35
+ }) => {
36
+ return renderLink(href, text, baseUrl);
37
+ };
19
38
  return marked.parse(escaped, {
20
- async: false
39
+ async: false,
40
+ renderer
21
41
  });
22
42
  }
23
43
  //# sourceMappingURL=markdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","names":["Marked","marked","breaks","gfm","markdownToHtml","markdown","undefined","escaped","replace","parse","async"],"sources":["../../../src/utils/markdown.ts"],"sourcesContent":["import { Marked } from 'marked'\n\n/**\n * Marked instance (avoids global option/extension scope)\n */\nexport const marked = new Marked({\n breaks: true,\n gfm: true\n})\n\n/**\n * Convert markdown to HTML, escaping any HTML tags first\n */\nexport function markdownToHtml(markdown?: string | null) {\n if (markdown === undefined || markdown === null) {\n return ''\n }\n\n const escaped = markdown\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;')\n\n return marked.parse(escaped, { async: false })\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,QAAQ;;AAE/B;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAG,IAAID,MAAM,CAAC;EAC/BE,MAAM,EAAE,IAAI;EACZC,GAAG,EAAE;AACP,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,QAAwB,EAAE;EACvD,IAAIA,QAAQ,KAAKC,SAAS,IAAID,QAAQ,KAAK,IAAI,EAAE;IAC/C,OAAO,EAAE;EACX;EAEA,MAAME,OAAO,GAAGF,QAAQ,CACrBG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CACtBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CACrBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CACrBA,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CACvBA,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;EAEzB,OAAOP,MAAM,CAACQ,KAAK,CAACF,OAAO,EAAE;IAAEG,KAAK,EAAE;EAAM,CAAC,CAAC;AAChD","ignoreList":[]}
1
+ {"version":3,"file":"markdown.js","names":["Marked","Renderer","marked","breaks","gfm","renderLink","href","text","baseUrl","isLocalLink","startsWith","attrs","push","label","join","markdownToHtml","markdown","undefined","escaped","replace","renderer","link","parse","async"],"sources":["../../../src/utils/markdown.ts"],"sourcesContent":["import { Marked, Renderer, type Tokens } from 'marked'\n\n/**\n * Marked instance (avoids global option/extension scope)\n */\nexport const marked = new Marked({\n breaks: true,\n gfm: true\n})\n\nfunction renderLink(href: string, text: string, baseUrl?: string) {\n let isLocalLink = true\n\n if (baseUrl) {\n isLocalLink = href.startsWith(baseUrl) || href.startsWith('mailto:')\n }\n\n const attrs = [`class=\"govuk-link\"`, `href=\"${href}\"`]\n\n if (!isLocalLink) {\n attrs.push(`target=\"_blank\" rel=\"noreferrer noopener\"`)\n }\n\n const label = !isLocalLink ? `${text} (opens in new tab)` : text\n\n return `<a ${attrs.join(' ')}>${label}</a>`\n}\n\n/**\n * Convert markdown to HTML, escaping any HTML tags first\n */\nexport function markdownToHtml(\n markdown: string | null | undefined,\n baseUrl?: string // optional in some contexts, e.g. from the designer where it might not make sense\n) {\n if (markdown === undefined || markdown === null) {\n return ''\n }\n\n const escaped = markdown\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;')\n\n const renderer = new Renderer()\n renderer.link = ({ href, text }: Tokens.Link): string => {\n return renderLink(href, text, baseUrl)\n }\n\n return marked.parse(escaped, { async: false, renderer })\n}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC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AAC,KAAa;IACvD,OAAOF,UAAU,CAACC,IAAI,EAAEC,IAAI,EAAEC,OAAO,CAAC;EACxC,CAAC;EAED,OAAON,MAAM,CAACoB,KAAK,CAACJ,OAAO,EAAE;IAAEK,KAAK,EAAE,KAAK;IAAEH;EAAS,CAAC,CAAC;AAC1D","ignoreList":[]}
@@ -9,6 +9,13 @@ export declare function getComponentDefaults<FieldType extends ComponentDef>(com
9
9
  */
10
10
  export declare function hasConditionSupport(component?: Partial<ComponentDef>): component is ConditionalComponentsDef;
11
11
  export declare function isConditionalType(type?: ComponentType): type is ConditionalComponentType;
12
+ /**
13
+ * Check if the component type is supported for conditional reveal.
14
+ * As of today this is just content types, but we're providing this as a wrapper
15
+ * function for clarity.
16
+ * @param type - Component type to check
17
+ */
18
+ export declare function isConditionalRevealType(type: ComponentType): type is ComponentType.Html | ComponentType.InsetText | ComponentType.Details | ComponentType.List | ComponentType.Markdown;
12
19
  /**
13
20
  * Filter known components with content (textarea or list)
14
21
  */
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC5B,MAAM,2BAA2B,CAAA;AAElC;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,SAAS,YAAY,EACjE,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAUC,SAAS,CAC9C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,CAAC,EAAE,OA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AY,CAAC,GAChC,SAAS,IAAI,OAAO,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAG3D;AAED,wBAAgB,aAAa,CAC3B,IAAI,CAAC,EAAE,aAAa,GACnB,IAAI,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAUtC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,SAAS,IAAI,iBAAiB,CAEhC;AAED,wBAAgB,UAAU,CACxB,IAAI,CAAC,EAAE,aAAa,GACnB,IAAI,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAEnC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,SAAS,IAAI,iBAAiB,CAEhC;AAED,wBAAgB,UAAU,CACxB,IAAI,CAAC,EAAE,aAAa,GACnB,IAAI,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAUnC;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,SAAS,IAAI,wBAAwB,CAEvC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,SAAS,IAAI,sBAAsB,CAUrC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,SAAS,IAAI,OAAO,CACrB,YAAY,EACZ,kBAAkB,GAAG,aAAa,GAAG,iBAAiB,CACvD,CAOA;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,SAAS,IAAI,iBAAiB,GAAG,aAAa,CAEhD"}
@@ -1,6 +1,6 @@
1
1
  export { ComponentTypes } from '../components/component-types.js';
2
- export { getComponentDefaults, hasConditionSupport, hasContent, hasContentField, hasFormField, hasHint, hasInputField, hasListField, hasSelectionFields, hasTitle, isConditionalType, isContentType, isFormType, isListType } from '../components/helpers.js';
2
+ export { ComponentType } from '../components/enums.js';
3
3
  export { allDocumentTypes, allImageTypes, allTabularDataTypes } from '../components/file-types.js';
4
+ export { getComponentDefaults, hasConditionSupport, hasContent, hasContentField, hasFormField, hasHint, hasInputField, hasListField, hasSelectionFields, hasTitle, isConditionalRevealType, isConditionalType, isContentType, isFormType, isListType } from '../components/helpers.js';
4
5
  export { getYesNoList, yesNoListId, yesNoListName, yesNoListNoItemId, yesNoListYesItemId } from '../components/yes-no-helper.js';
5
- export { ComponentType } from '../components/enums.js';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,OAAO,EACP,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACpB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACpB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,OAAO,EACP,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,mCAAmC,CAAA"}
@@ -6,5 +6,5 @@ export declare const marked: Marked;
6
6
  /**
7
7
  * Convert markdown to HTML, escaping any HTML tags first
8
8
  */
9
- export declare function markdownToHtml(markdown?: string | null): string;
9
+ export declare function markdownToHtml(markdown: string | null | undefined, baseUrl?: string): string;
10
10
  //# sourceMappingURL=markdown.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/utils/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B;;GAEG;AACH,eAAO,MAAM,MAAM,QAGjB,CAAA;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,UAatD"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/utils/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAyB,MAAM,QAAQ,CAAA;AAEtD;;GAEG;AACH,eAAO,MAAM,MAAM,QAGjB,CAAA;AAoBF;;GAEG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,OAAO,CAAC,EAAE,MAAM,UAmBjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-model",
3
- "version": "3.0.503",
3
+ "version": "3.0.505",
4
4
  "description": "A hapi plugin providing the model for Defra forms",
5
5
  "homepage": "https://github.com/DEFRA/forms-designer/tree/main/model#readme",
6
6
  "types": "dist/types/index.d.ts",
@@ -61,6 +61,16 @@ export function isConditionalType(
61
61
  return !!type && allowedTypes.includes(type)
62
62
  }
63
63
 
64
+ /**
65
+ * Check if the component type is supported for conditional reveal.
66
+ * As of today this is just content types, but we're providing this as a wrapper
67
+ * function for clarity.
68
+ * @param type - Component type to check
69
+ */
70
+ export function isConditionalRevealType(type: ComponentType) {
71
+ return isContentType(type)
72
+ }
73
+
64
74
  /**
65
75
  * Filter known components with content (textarea or list)
66
76
  */
@@ -1,4 +1,10 @@
1
1
  export { ComponentTypes } from '~/src/components/component-types.js'
2
+ export { ComponentType } from '~/src/components/enums.js'
3
+ export {
4
+ allDocumentTypes,
5
+ allImageTypes,
6
+ allTabularDataTypes
7
+ } from '~/src/components/file-types.js'
2
8
  export {
3
9
  getComponentDefaults,
4
10
  hasConditionSupport,
@@ -10,16 +16,12 @@ export {
10
16
  hasListField,
11
17
  hasSelectionFields,
12
18
  hasTitle,
19
+ isConditionalRevealType,
13
20
  isConditionalType,
14
21
  isContentType,
15
22
  isFormType,
16
23
  isListType
17
24
  } from '~/src/components/helpers.js'
18
- export {
19
- allDocumentTypes,
20
- allImageTypes,
21
- allTabularDataTypes
22
- } from '~/src/components/file-types.js'
23
25
  export {
24
26
  getYesNoList,
25
27
  yesNoListId,
@@ -27,4 +29,3 @@ export {
27
29
  yesNoListNoItemId,
28
30
  yesNoListYesItemId
29
31
  } from '~/src/components/yes-no-helper.js'
30
- export { ComponentType } from '~/src/components/enums.js'
@@ -1,4 +1,4 @@
1
- import { Marked } from 'marked'
1
+ import { Marked, Renderer, type Tokens } from 'marked'
2
2
 
3
3
  /**
4
4
  * Marked instance (avoids global option/extension scope)
@@ -8,10 +8,31 @@ export const marked = new Marked({
8
8
  gfm: true
9
9
  })
10
10
 
11
+ function renderLink(href: string, text: string, baseUrl?: string) {
12
+ let isLocalLink = true
13
+
14
+ if (baseUrl) {
15
+ isLocalLink = href.startsWith(baseUrl) || href.startsWith('mailto:')
16
+ }
17
+
18
+ const attrs = [`class="govuk-link"`, `href="${href}"`]
19
+
20
+ if (!isLocalLink) {
21
+ attrs.push(`target="_blank" rel="noreferrer noopener"`)
22
+ }
23
+
24
+ const label = !isLocalLink ? `${text} (opens in new tab)` : text
25
+
26
+ return `<a ${attrs.join(' ')}>${label}</a>`
27
+ }
28
+
11
29
  /**
12
30
  * Convert markdown to HTML, escaping any HTML tags first
13
31
  */
14
- export function markdownToHtml(markdown?: string | null) {
32
+ export function markdownToHtml(
33
+ markdown: string | null | undefined,
34
+ baseUrl?: string // optional in some contexts, e.g. from the designer where it might not make sense
35
+ ) {
15
36
  if (markdown === undefined || markdown === null) {
16
37
  return ''
17
38
  }
@@ -23,5 +44,10 @@ export function markdownToHtml(markdown?: string | null) {
23
44
  .replace(/"/g, '&quot;')
24
45
  .replace(/'/g, '&#39;')
25
46
 
26
- return marked.parse(escaped, { async: false })
47
+ const renderer = new Renderer()
48
+ renderer.link = ({ href, text }: Tokens.Link): string => {
49
+ return renderLink(href, text, baseUrl)
50
+ }
51
+
52
+ return marked.parse(escaped, { async: false, renderer })
27
53
  }