@contember/react-client 1.1.0 → 1.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/ContemberClient.js +14 -29
- package/dist/development/ContemberClient.js.map +1 -1
- package/dist/development/apiRequest/useApiRequest.js +1 -0
- package/dist/development/apiRequest/useApiRequest.js.map +1 -1
- package/dist/development/auth/SessionTokenContext.js +5 -1
- package/dist/development/auth/SessionTokenContext.js.map +1 -1
- package/dist/development/auth/useSessionToken.js +4 -2
- package/dist/development/auth/useSessionToken.js.map +1 -1
- package/dist/development/components/RichTextRenderer/ElementRenderer.js +2 -6
- package/dist/development/components/RichTextRenderer/ElementRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/LeafRenderer.js +2 -6
- package/dist/development/components/RichTextRenderer/LeafRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js +21 -94
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js +11 -47
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js +5 -20
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/renderChildren.js +5 -17
- package/dist/development/components/RichTextRenderer/renderChildren.js.map +1 -1
- package/dist/development/components/RichTextRenderer/resolveRichTextElementMetadata.js.map +1 -1
- package/dist/development/index.js +2 -1
- package/dist/development/upload/fileUploadReducer.js +1 -0
- package/dist/development/upload/fileUploadReducer.js.map +1 -1
- package/dist/development/upload/useFileUpload.js.map +1 -1
- package/dist/production/ContemberClient.js +13 -4
- package/dist/production/ContemberClient.js.map +1 -1
- package/dist/production/apiRequest/useApiRequest.js +1 -0
- package/dist/production/apiRequest/useApiRequest.js.map +1 -1
- package/dist/production/auth/SessionTokenContext.js +5 -1
- package/dist/production/auth/SessionTokenContext.js.map +1 -1
- package/dist/production/auth/useSessionToken.js +4 -2
- package/dist/production/auth/useSessionToken.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/resolveRichTextElementMetadata.js.map +1 -1
- package/dist/production/index.js +2 -1
- package/dist/production/upload/fileUploadReducer.js +1 -0
- package/dist/production/upload/fileUploadReducer.js.map +1 -1
- package/dist/production/upload/useFileUpload.js.map +1 -1
- package/dist/types/ContemberClient.d.ts +3 -1
- package/dist/types/ContemberClient.d.ts.map +1 -1
- package/dist/types/auth/SessionTokenContext.d.ts +6 -2
- package/dist/types/auth/SessionTokenContext.d.ts.map +1 -1
- package/dist/types/auth/SetSessionTokenContext.d.ts +0 -1
- package/dist/types/auth/SetSessionTokenContext.d.ts.map +1 -1
- package/dist/types/auth/useSessionToken.d.ts +1 -0
- package/dist/types/auth/useSessionToken.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/RenderLeafFallback.d.ts +0 -1
- package/dist/types/components/RichTextRenderer/RenderLeafFallback.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderMetadataContext.d.ts +0 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderMetadataContext.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts +3 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts.map +1 -1
- package/dist/types/config/ApiBaseUrlContext.d.ts +0 -1
- package/dist/types/config/ApiBaseUrlContext.d.ts.map +1 -1
- package/dist/types/config/LoginTokenContext.d.ts +0 -1
- package/dist/types/config/LoginTokenContext.d.ts.map +1 -1
- package/dist/types/project/ProjectSlugContext.d.ts +0 -1
- package/dist/types/project/ProjectSlugContext.d.ts.map +1 -1
- package/dist/types/project/StageSlugContext.d.ts +0 -1
- package/dist/types/project/StageSlugContext.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/ContemberClient.tsx +28 -13
- package/src/auth/SessionTokenContext.ts +11 -1
- package/src/auth/useSessionToken.ts +2 -1
- package/src/components/RichTextRenderer/RichTextRenderer.tsx +3 -0
- package/src/ambient.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextRenderer.js","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { defaultDeserialize } from './defaultDeserialize'\nimport type { RenderElement } from './ElementRenderer'\nimport type { RenderLeaf } from './LeafRenderer'\nimport type { NormalizedRichTextBlock } from './NormalizedRichTextBlock'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport { renderChildren } from './renderChildren'\nimport type { RichTextBlock } from './RichTextBlock'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { RichTextRenderMetadataContext } from './RichTextRenderMetadataContext'\nimport type { RootEditorNode } from './RootEditorNode'\n\nexport interface RichTextRendererFieldProps {\n\tsource: string | null\n}\n\nexport interface RichTextRendererBlockProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\tblocks: RichTextBlock[]\n\treferenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>\n\tsourceField?: string\n\treferencesField?: string\n\treferenceDiscriminationField?: string\n}\n\nexport type RichTextRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> = {\n\tdeserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n\trenderBlock?: ComponentType<{ block: unknown, children?: ReactNode }>\n} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>)\n\nexport const RichTextRenderer = memo(function RichTextRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({\n\tdeserialize = defaultDeserialize,\n\trenderElement,\n\trenderLeaf,\n\trenderBlock = ({ children }) => <>{children}</>,\n\tattributeNamePrefix,\n\t...sourceProps\n}: RichTextRendererProps<CustomElements, CustomLeaves>) {\n\tconst normalizedSource = useMemo<NormalizedRichTextBlock<CustomElements, CustomLeaves>[]>(() => {\n\t\tif ('source' in sourceProps && !('blocks' in sourceProps)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontent: sourceProps.source\n\t\t\t\t\t\t? deserialize(sourceProps.source)\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tformatVersion: 0,\n\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t },\n\t\t\t\t\tid: undefined,\n\t\t\t\t\treferencesField: undefined,\n\t\t\t\t\treferenceDiscriminationField: undefined,\n\t\t\t\t\treferenceRenderers: {},\n\t\t\t\t\treferences: undefined,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t\tif (!('source' in sourceProps)) {\n\t\t\tconst sourceField = sourceProps.sourceField ?? 'source'\n\t\t\tconst referencesField = sourceProps.referencesField ?? 'references'\n\t\t\tconst referenceDiscriminationField = sourceProps.referenceDiscriminationField ?? 'type'\n\n\t\t\treturn sourceProps.blocks.map(block => {\n\t\t\t\tif (!(sourceField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`Found a block without a '${sourceField}' field. ` +\n\t\t\t\t\t\t\t(sourceProps.sourceField === undefined\n\t\t\t\t\t\t\t\t? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`\n\t\t\t\t\t\t\t\t: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +\n\t\t\t\t\t\t\t\t `or the data supplied is invalid.`),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst source = block[sourceField]\n\t\t\t\tif (typeof source !== 'string') {\n\t\t\t\t\tthrow new RichTextRendererError(`Found a block whose source is not a string.`)\n\t\t\t\t}\n\n\t\t\t\tif (sourceProps.referencesField !== undefined && !(referencesField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`The 'referencesField' prop is set to '${referencesField}' but a block without such field ` +\n\t\t\t\t\t\t\t`has been encountered. Unless this is just a typo, ` +\n\t\t\t\t\t\t\t`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst references = block[referencesField]\n\n\t\t\t\tlet normalizedReferences: Map<string, RichTextReference> | undefined = undefined\n\t\t\t\tif (references) {\n\t\t\t\t\tif (typeof Object(references)[Symbol.iterator] !== 'function') {\n\t\t\t\t\t\tthrow new RichTextRendererError(`The set of references must be an iterable!`)\n\t\t\t\t\t}\n\n\t\t\t\t\tnormalizedReferences = new Map()\n\t\t\t\t\tfor (const reference of references as Iterable<RichTextReference>) {\n\t\t\t\t\t\tif (!('id' in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(`Found a reference without an id field.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!(referenceDiscriminationField in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t\t\t`Found a reference without a '${referenceDiscriminationField}' field. ` +\n\t\t\t\t\t\t\t\t\t(sourceProps.referenceDiscriminationField === undefined\n\t\t\t\t\t\t\t\t\t\t? `The 'referenceDiscriminationField' prop has not been supplied, ` +\n\t\t\t\t\t\t\t\t\t\t `and so '${referenceDiscriminationField}' was used as a default.`\n\t\t\t\t\t\t\t\t\t\t: `That is what the 'referenceDiscriminationField' prop has been set to, ` +\n\t\t\t\t\t\t\t\t\t\t `and so either this is a typo, or the data supplied is invalid.`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnormalizedReferences.set(reference.id, reference)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tid: typeof block.id === 'string' ? block.id : undefined,\n\t\t\t\t\tcontent: deserialize(source),\n\t\t\t\t\treferenceDiscriminationField,\n\t\t\t\t\treferenceRenderers: sourceProps.referenceRenderers ?? {},\n\t\t\t\t\treferencesField,\n\t\t\t\t\treferences: normalizedReferences,\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t\tthrow new RichTextRendererError(`RichTextRenderer: invalid data supplied.`)\n\t}, [deserialize, sourceProps])\n\n\treturn (\n\t\t<>\n\t\t\t{normalizedSource.map((block, i) => (\n\t\t\t\t<RichTextRenderMetadataContext.Provider\n\t\t\t\t\tkey={block.id ?? i}\n\t\t\t\t\tvalue={{\n\t\t\t\t\t\tformatVersion: block.content.formatVersion,\n\t\t\t\t\t\treferenceRenderers: block.referenceRenderers,\n\t\t\t\t\t\treferencesField: block.referencesField,\n\t\t\t\t\t\treferenceDiscriminationField: block.referenceDiscriminationField,\n\t\t\t\t\t\treferences: block.references,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{createElement(\n\t\t\t\t\t\trenderBlock, {\n\t\t\t\t\t\t\tblock,\n\t\t\t\t\t\t}, renderChildren(block.content.children, {\n\t\t\t\t\t\t\trenderLeaf,\n\t\t\t\t\t\t\trenderElement,\n\t\t\t\t\t\t\tattributeNamePrefix,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)}\n\t\t\t\t</RichTextRenderMetadataContext.Provider>\n\t\t\t))}\n\t\t</>\n\t)\n}) as <CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never>(\n\tprops: RichTextRendererProps<CustomElements, CustomLeaves>,\n) => ReactElement\n"],"names":["RichTextRenderer"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"RichTextRenderer.js","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { defaultDeserialize } from './defaultDeserialize'\nimport type { RenderElement } from './ElementRenderer'\nimport type { RenderLeaf } from './LeafRenderer'\nimport type { NormalizedRichTextBlock } from './NormalizedRichTextBlock'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport { renderChildren } from './renderChildren'\nimport type { RichTextBlock } from './RichTextBlock'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { RichTextRenderMetadataContext } from './RichTextRenderMetadataContext'\nimport type { RootEditorNode } from './RootEditorNode'\n\nexport interface RichTextRendererFieldProps {\n\tsource: string | null\n}\n\nexport interface RichTextRendererBlockProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\tblocks: RichTextBlock[]\n\treferenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>\n\tsourceField?: string\n\treferencesField?: string\n\treferenceDiscriminationField?: string\n}\n\nexport type RichTextRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> = {\n\tdeserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n\trenderBlock?: ComponentType<{ block: unknown, children?: ReactNode }>\n} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>)\n\n/**\n * @group Content rendering\n */\nexport const RichTextRenderer = memo(function RichTextRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({\n\tdeserialize = defaultDeserialize,\n\trenderElement,\n\trenderLeaf,\n\trenderBlock = ({ children }) => <>{children}</>,\n\tattributeNamePrefix,\n\t...sourceProps\n}: RichTextRendererProps<CustomElements, CustomLeaves>) {\n\tconst normalizedSource = useMemo<NormalizedRichTextBlock<CustomElements, CustomLeaves>[]>(() => {\n\t\tif ('source' in sourceProps && !('blocks' in sourceProps)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontent: sourceProps.source\n\t\t\t\t\t\t? deserialize(sourceProps.source)\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tformatVersion: 0,\n\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t },\n\t\t\t\t\tid: undefined,\n\t\t\t\t\treferencesField: undefined,\n\t\t\t\t\treferenceDiscriminationField: undefined,\n\t\t\t\t\treferenceRenderers: {},\n\t\t\t\t\treferences: undefined,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t\tif (!('source' in sourceProps)) {\n\t\t\tconst sourceField = sourceProps.sourceField ?? 'source'\n\t\t\tconst referencesField = sourceProps.referencesField ?? 'references'\n\t\t\tconst referenceDiscriminationField = sourceProps.referenceDiscriminationField ?? 'type'\n\n\t\t\treturn sourceProps.blocks.map(block => {\n\t\t\t\tif (!(sourceField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`Found a block without a '${sourceField}' field. ` +\n\t\t\t\t\t\t\t(sourceProps.sourceField === undefined\n\t\t\t\t\t\t\t\t? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`\n\t\t\t\t\t\t\t\t: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +\n\t\t\t\t\t\t\t\t `or the data supplied is invalid.`),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst source = block[sourceField]\n\t\t\t\tif (typeof source !== 'string') {\n\t\t\t\t\tthrow new RichTextRendererError(`Found a block whose source is not a string.`)\n\t\t\t\t}\n\n\t\t\t\tif (sourceProps.referencesField !== undefined && !(referencesField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`The 'referencesField' prop is set to '${referencesField}' but a block without such field ` +\n\t\t\t\t\t\t\t`has been encountered. Unless this is just a typo, ` +\n\t\t\t\t\t\t\t`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst references = block[referencesField]\n\n\t\t\t\tlet normalizedReferences: Map<string, RichTextReference> | undefined = undefined\n\t\t\t\tif (references) {\n\t\t\t\t\tif (typeof Object(references)[Symbol.iterator] !== 'function') {\n\t\t\t\t\t\tthrow new RichTextRendererError(`The set of references must be an iterable!`)\n\t\t\t\t\t}\n\n\t\t\t\t\tnormalizedReferences = new Map()\n\t\t\t\t\tfor (const reference of references as Iterable<RichTextReference>) {\n\t\t\t\t\t\tif (!('id' in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(`Found a reference without an id field.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!(referenceDiscriminationField in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t\t\t`Found a reference without a '${referenceDiscriminationField}' field. ` +\n\t\t\t\t\t\t\t\t\t(sourceProps.referenceDiscriminationField === undefined\n\t\t\t\t\t\t\t\t\t\t? `The 'referenceDiscriminationField' prop has not been supplied, ` +\n\t\t\t\t\t\t\t\t\t\t `and so '${referenceDiscriminationField}' was used as a default.`\n\t\t\t\t\t\t\t\t\t\t: `That is what the 'referenceDiscriminationField' prop has been set to, ` +\n\t\t\t\t\t\t\t\t\t\t `and so either this is a typo, or the data supplied is invalid.`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnormalizedReferences.set(reference.id, reference)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tid: typeof block.id === 'string' ? block.id : undefined,\n\t\t\t\t\tcontent: deserialize(source),\n\t\t\t\t\treferenceDiscriminationField,\n\t\t\t\t\treferenceRenderers: sourceProps.referenceRenderers ?? {},\n\t\t\t\t\treferencesField,\n\t\t\t\t\treferences: normalizedReferences,\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t\tthrow new RichTextRendererError(`RichTextRenderer: invalid data supplied.`)\n\t}, [deserialize, sourceProps])\n\n\treturn (\n\t\t<>\n\t\t\t{normalizedSource.map((block, i) => (\n\t\t\t\t<RichTextRenderMetadataContext.Provider\n\t\t\t\t\tkey={block.id ?? i}\n\t\t\t\t\tvalue={{\n\t\t\t\t\t\tformatVersion: block.content.formatVersion,\n\t\t\t\t\t\treferenceRenderers: block.referenceRenderers,\n\t\t\t\t\t\treferencesField: block.referencesField,\n\t\t\t\t\t\treferenceDiscriminationField: block.referenceDiscriminationField,\n\t\t\t\t\t\treferences: block.references,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{createElement(\n\t\t\t\t\t\trenderBlock, {\n\t\t\t\t\t\t\tblock,\n\t\t\t\t\t\t}, renderChildren(block.content.children, {\n\t\t\t\t\t\t\trenderLeaf,\n\t\t\t\t\t\t\trenderElement,\n\t\t\t\t\t\t\tattributeNamePrefix,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)}\n\t\t\t\t</RichTextRenderMetadataContext.Provider>\n\t\t\t))}\n\t\t</>\n\t)\n}) as <CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never>(\n\tprops: RichTextRendererProps<CustomElements, CustomLeaves>,\n) => ReactElement\n"],"names":["RichTextRenderer"],"mappings":";;;;;;AA4Ca,MAAA,mBAAmB,KAAK,SAASA,kBAG5C;AAAA,EACD,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,cAAc,CAAC,EAAE,SAAS,sCAAS,UAAS;AAAA,EAC5C;AAAA,EACA,GAAG;AACJ,GAAwD;AACjD,QAAA,mBAAmB,QAAiE,MAAM;AAC/F,QAAI,YAAY,eAAe,EAAE,YAAY,cAAc;AACnD,aAAA;AAAA,QACN;AAAA,UACC,SAAS,YAAY,SAClB,YAAY,YAAY,MAAM,IAC9B;AAAA,YACA,eAAe;AAAA,YACf,UAAU,CAAC;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AO,WAAW,MAAM,KAAK;AAAA,UAC9C,SAAS,YAAY,MAAM;AAAA,UAC3B;AAAA,UACA,oBAAoB,YAAY,sBAAsB,CAAC;AAAA,UACvD;AAAA,UACA,YAAY;AAAA,QAAA;AAAA,MACb,CACA;AAAA,IACF;AACM,UAAA,IAAI,sBAAsB,0CAA0C;AAAA,EAAA,GACxE,CAAC,aAAa,WAAW,CAAC;AAE7B,SAEG,oBAAA,UAAA,EAAA,UAAA,iBAAiB,IAAI,CAAC,OAAO,MAC7B;AAAA,IAAC,8BAA8B;AAAA,IAA9B;AAAA,MAEA,OAAO;AAAA,QACN,eAAe,MAAM,QAAQ;AAAA,QAC7B,oBAAoB,MAAM;AAAA,QAC1B,iBAAiB,MAAM;AAAA,QACvB,8BAA8B,MAAM;AAAA,QACpC,YAAY,MAAM;AAAA,MACnB;AAAA,MAEC,UAAA;AAAA,QACA;AAAA,QAAa;AAAA,UACZ;AAAA,QACD;AAAA,QAAG,eAAe,MAAM,QAAQ,UAAU;AAAA,UACzC;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA;AAAA,IAjBK,MAAM,MAAM;AAAA,EAmBlB,CAAA,EACF,CAAA;AAEF,CAAC;"}
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { ElementRenderer } from "./ElementRenderer.js";
|
|
3
3
|
import { LeafRenderer } from "./LeafRenderer.js";
|
|
4
4
|
const renderChildren = (children, options) => {
|
|
5
5
|
if (!Array.isArray(children)) {
|
|
6
6
|
children = [children];
|
|
7
7
|
}
|
|
8
|
-
return /* @__PURE__ */
|
|
8
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children.map((child, i) => {
|
|
9
9
|
if ("text" in child) {
|
|
10
|
-
return /* @__PURE__ */
|
|
11
|
-
fileName: "/__w/interface/interface/packages/react-client/src/components/RichTextRenderer/renderChildren.tsx",
|
|
12
|
-
lineNumber: 37,
|
|
13
|
-
columnNumber: 13
|
|
14
|
-
}, globalThis);
|
|
10
|
+
return /* @__PURE__ */ jsx(LeafRenderer, { leaf: child, renderLeaf: options.renderLeaf }, i);
|
|
15
11
|
}
|
|
16
12
|
if ("children" in child) {
|
|
17
|
-
return /* @__PURE__ */
|
|
18
|
-
fileName: "/__w/interface/interface/packages/react-client/src/components/RichTextRenderer/renderChildren.tsx",
|
|
19
|
-
lineNumber: 41,
|
|
20
|
-
columnNumber: 7
|
|
21
|
-
}, globalThis);
|
|
13
|
+
return /* @__PURE__ */ jsx(ElementRenderer, { element: child, options, children: renderChildren(child.children, options) }, i);
|
|
22
14
|
}
|
|
23
15
|
return null;
|
|
24
|
-
}) }
|
|
25
|
-
fileName: "/__w/interface/interface/packages/react-client/src/components/RichTextRenderer/renderChildren.tsx",
|
|
26
|
-
lineNumber: 34,
|
|
27
|
-
columnNumber: 3
|
|
28
|
-
}, globalThis);
|
|
16
|
+
}) });
|
|
29
17
|
};
|
|
30
18
|
export {
|
|
31
19
|
renderChildren
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderChildren.js","sources":["../../../../src/components/RichTextRenderer/renderChildren.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport type { BuiltinElements } from './BuiltinElements'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\nimport { ElementRenderer, RenderElement } from './ElementRenderer'\nimport { LeafRenderer, RenderLeaf } from './LeafRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\n\nexport interface RenderChildrenOptions<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n}\n\nexport const renderChildren = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\tchildren:\n\t\t| CustomElements\n\t\t| BuiltinElements<CustomElements, CustomLeaves>\n\t\t| CustomLeaves\n\t\t| BuiltinLeaves\n\t\t| Array<CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves>,\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>,\n): ReactElement => {\n\tif (!Array.isArray(children)) {\n\t\tchildren = [children]\n\t}\n\treturn (\n\t\t<>\n\t\t\t{children.map((child, i) => {\n\t\t\t\tif ('text' in child) {\n\t\t\t\t\treturn <LeafRenderer<CustomLeaves> key={i} leaf={child} renderLeaf={options.renderLeaf} />\n\t\t\t\t}\n\t\t\t\tif ('children' in child) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ElementRenderer<CustomElements, CustomLeaves> key={i} element={child} options={options}>\n\t\t\t\t\t\t\t{renderChildren<CustomElements, CustomLeaves>(child.children as typeof children, options)}\n\t\t\t\t\t\t</ElementRenderer>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn null // Throw?\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"renderChildren.js","sources":["../../../../src/components/RichTextRenderer/renderChildren.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport type { BuiltinElements } from './BuiltinElements'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\nimport { ElementRenderer, RenderElement } from './ElementRenderer'\nimport { LeafRenderer, RenderLeaf } from './LeafRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\n\nexport interface RenderChildrenOptions<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n}\n\nexport const renderChildren = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\tchildren:\n\t\t| CustomElements\n\t\t| BuiltinElements<CustomElements, CustomLeaves>\n\t\t| CustomLeaves\n\t\t| BuiltinLeaves\n\t\t| Array<CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves>,\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>,\n): ReactElement => {\n\tif (!Array.isArray(children)) {\n\t\tchildren = [children]\n\t}\n\treturn (\n\t\t<>\n\t\t\t{children.map((child, i) => {\n\t\t\t\tif ('text' in child) {\n\t\t\t\t\treturn <LeafRenderer<CustomLeaves> key={i} leaf={child} renderLeaf={options.renderLeaf} />\n\t\t\t\t}\n\t\t\t\tif ('children' in child) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ElementRenderer<CustomElements, CustomLeaves> key={i} element={child} options={options}>\n\t\t\t\t\t\t\t{renderChildren<CustomElements, CustomLeaves>(child.children as typeof children, options)}\n\t\t\t\t\t\t</ElementRenderer>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn null // Throw?\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":";;;AAiBa,MAAA,iBAAiB,CAI7B,UAMA,YACkB;AAClB,MAAI,CAAC,MAAM,QAAQ,QAAQ,GAAG;AAC7B,eAAW,CAAC,QAAQ;AAAA,EACrB;AACA,SAEG,oBAAA,UAAA,EAAA,UAAA,SAAS,IAAI,CAAC,OAAO,MAAM;AAC3B,QAAI,UAAU,OAAO;AACpB,iCAAQ,cAAmC,EAAA,MAAM,OAAO,YAAY,QAAQ,cAApC,CAAgD;AAAA,IACzF;AACA,QAAI,cAAc,OAAO;AAEvB,aAAA,oBAAC,iBAAsD,EAAA,SAAS,OAAO,SACrE,yBAA6C,MAAM,UAA6B,OAAO,EAAA,GADrC,CAEpD;AAAA,IAEF;AACO,WAAA;AAAA,EACP,CAAA,EACF,CAAA;AAEF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRichTextElementMetadata.js","sources":["../../../../src/components/RichTextRenderer/resolveRichTextElementMetadata.ts"],"sourcesContent":["import type { BuiltinElements } from './BuiltinElements'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextElementMetadata } from './RichTextElementMetadata'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport type { RichTextRenderMetadata } from './RichTextRenderMetadata'\n\nexport const resolveRichTextElementMetadata = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n\tReference extends RichTextReference = RichTextReference,\n>(\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>,\n\tmetadata: RichTextRenderMetadata<CustomElements, CustomLeaves, Reference>,\n): RichTextElementMetadata<CustomElements, CustomLeaves, Reference> => {\n\tlet reference: Reference | undefined = undefined\n\n\tif ('referenceId' in element && typeof element['referenceId'] === 'string') {\n\t\tconst resolved = metadata.references?.get(element['referenceId'])\n\n\t\tif (resolved === undefined) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`Cannot find reference id '${element['referenceId']}'` +\n\t\t\t\t\t(metadata.references === undefined\n\t\t\t\t\t\t? ` because its containing block's lacks the '${metadata.referencesField}' field. `\n\t\t\t\t\t\t: `.`),\n\t\t\t)\n\t\t}\n\t\treference = resolved as Reference\n\t}\n\n\tlet referenceRenderer: ReferenceRenderer<Reference, CustomElements, CustomLeaves> | undefined = undefined\n\tlet referenceType: string | undefined = undefined\n\n\tif (reference && metadata.referenceDiscriminationField) {\n\t\treferenceType = (reference as Reference & Record<typeof metadata.referenceDiscriminationField, string>)[\n\t\t\tmetadata.referenceDiscriminationField\n\t\t]\n\t\treferenceRenderer = metadata.referenceRenderers[referenceType]\n\t}\n\n\treturn {\n\t\tformatVersion: metadata.formatVersion,\n\t\treference,\n\t\treferenceType,\n\t\treferenceRenderer,\n\t}\n}\n"],"names":[],"mappings":";AASa,MAAA,iCAAiC,CAK7C,SACA,aACsE;AACtE,MAAI,YAAmC;AAEvC,MAAI,iBAAiB,WAAW,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"resolveRichTextElementMetadata.js","sources":["../../../../src/components/RichTextRenderer/resolveRichTextElementMetadata.ts"],"sourcesContent":["import type { BuiltinElements } from './BuiltinElements'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextElementMetadata } from './RichTextElementMetadata'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport type { RichTextRenderMetadata } from './RichTextRenderMetadata'\n\nexport const resolveRichTextElementMetadata = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n\tReference extends RichTextReference = RichTextReference,\n>(\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>,\n\tmetadata: RichTextRenderMetadata<CustomElements, CustomLeaves, Reference>,\n): RichTextElementMetadata<CustomElements, CustomLeaves, Reference> => {\n\tlet reference: Reference | undefined = undefined\n\n\tif ('referenceId' in element && typeof element['referenceId'] === 'string') {\n\t\tconst resolved = metadata.references?.get(element['referenceId'])\n\n\t\tif (resolved === undefined) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`Cannot find reference id '${element['referenceId']}'` +\n\t\t\t\t\t(metadata.references === undefined\n\t\t\t\t\t\t? ` because its containing block's lacks the '${metadata.referencesField}' field. `\n\t\t\t\t\t\t: `.`),\n\t\t\t)\n\t\t}\n\t\treference = resolved as Reference\n\t}\n\n\tlet referenceRenderer: ReferenceRenderer<Reference, CustomElements, CustomLeaves> | undefined = undefined\n\tlet referenceType: string | undefined = undefined\n\n\tif (reference && metadata.referenceDiscriminationField) {\n\t\treferenceType = (reference as Reference & Record<typeof metadata.referenceDiscriminationField, string>)[\n\t\t\tmetadata.referenceDiscriminationField\n\t\t]\n\t\treferenceRenderer = metadata.referenceRenderers[referenceType]\n\t}\n\n\treturn {\n\t\tformatVersion: metadata.formatVersion,\n\t\treference,\n\t\treferenceType,\n\t\treferenceRenderer,\n\t}\n}\n"],"names":[],"mappings":";AASa,MAAA,iCAAiC,CAK7C,SACA,aACsE;AACtE,MAAI,YAAmC;AAEvC,MAAI,iBAAiB,WAAW,OAAO,QAAQ,aAAa,MAAM,UAAU;AAC3E,UAAM,WAAW,SAAS,YAAY,IAAI,QAAQ,aAAa,CAAC;AAEhE,QAAI,aAAa,QAAW;AAC3B,YAAM,IAAI;AAAA,QACT,6BAA6B,QAAQ,aAAa,QAChD,SAAS,eAAe,SACtB,8CAA8C,SAAS,6BACvD;AAAA,MAAA;AAAA,IAEN;AACY,gBAAA;AAAA,EACb;AAEA,MAAI,oBAA4F;AAChG,MAAI,gBAAoC;AAEpC,MAAA,aAAa,SAAS,8BAA8B;AACtC,oBAAA,UAChB,SAAS,4BACV;AACoB,wBAAA,SAAS,mBAAmB,aAAa;AAAA,EAC9D;AAEO,SAAA;AAAA,IACN,eAAe,SAAS;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
|
@@ -6,7 +6,7 @@ import { apiRequestReducer } from "./apiRequest/apiRequestReducer.js";
|
|
|
6
6
|
import { useApiRequest } from "./apiRequest/useApiRequest.js";
|
|
7
7
|
import { SessionTokenContext } from "./auth/SessionTokenContext.js";
|
|
8
8
|
import { SetSessionTokenContext } from "./auth/SetSessionTokenContext.js";
|
|
9
|
-
import { useSessionToken } from "./auth/useSessionToken.js";
|
|
9
|
+
import { useSessionToken, useSessionTokenWithMeta } from "./auth/useSessionToken.js";
|
|
10
10
|
import { useSetSessionToken } from "./auth/useSetSessionToken.js";
|
|
11
11
|
import { RichTextRenderer } from "./components/RichTextRenderer/RichTextRenderer.js";
|
|
12
12
|
import { RichTextRendererError } from "./components/RichTextRenderer/RichTextRendererError.js";
|
|
@@ -50,6 +50,7 @@ export {
|
|
|
50
50
|
useLoginToken,
|
|
51
51
|
useProjectSlug,
|
|
52
52
|
useSessionToken,
|
|
53
|
+
useSessionTokenWithMeta,
|
|
53
54
|
useSetSessionToken,
|
|
54
55
|
useStageSlug,
|
|
55
56
|
useSystemApiRequest,
|
|
@@ -32,6 +32,7 @@ const fileUploadReducer = (previousState, action) => {
|
|
|
32
32
|
abortController: fileState.abortController,
|
|
33
33
|
file: fileState.file,
|
|
34
34
|
metadata: metadata.metadata,
|
|
35
|
+
// If the user didn't supply the metadata, then that's on them.
|
|
35
36
|
previewUrl: fileState.previewUrl,
|
|
36
37
|
progress: void 0,
|
|
37
38
|
uploader: metadata.uploader
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<Result, Metadata> => ({\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tstate: new Map(),\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tlet newState: undefined | FileUploadMultiTemporalState<Result, Metadata>['state'] = undefined\n\n\tswitch (action.type) {\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\t// Deliberately mutating\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\t;(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'purge': {\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tURL.revokeObjectURL(fileState.previewUrl)\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).delete(fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst roundedProgress = Math.floor(progress) // throttling\n\t\t\t\tif (roundedProgress === previousFileState.progress) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress: roundedProgress,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tdefault:\n\t\t\tassertNever(action)\n\t}\n\tif (newState === undefined) {\n\t\treturn previousState\n\t}\n\treturn { ...previousState, state: newState }\n}\n"],"names":[],"mappings":";;;AAOO,MAAM,4BAA4B,OAA+F;AAAA,EACvI,kCAAkB,QAAsB;AAAA,EACxC,2BAAW,IAAI;AAChB;AAEa,MAAA,oBAAoB,CAChC,eACA,WACoD;AACpD,MAAI,WAAgF;AAEpF,UAAQ,OAAO,MAAM;AAAA,IACpB,KAAK,cAAc;AAClB,iBAAW,CAAC,QAAQ,QAAQ,KAAK,OAAO,OAAO;AAE9C,SAAC,wBAAa,IAAI,IAAI,cAAc,KAAK,IAA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,KAAK,IAAG,OAAO,MAAM;AAAA,MAC1D;AACA;AAAA,IACD;AAAA,IACA,KAAK,wBAAwB;AAC5B,iBAAW,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,UAAU;AACjD,cAAA,SAAS,SAAS,eAAe,QAAQ;AAC/C,cAAM,qBAAqB,YAAY,cAAc,OAAO,IAAI,MAAM;AACtE,YAAI,aAAa,UAAa,sBAAsB,UAAa,kBAAkB,eAAe,aAAa;AAC9G;AAAA,QACD;AACM,cAAA,kBAAkB,KAAK,MAAM,QAAQ;AACvC,YAAA,oBAAoB,kBAAkB,UAAU;AACnD;AAAA,QACD;AACA,SAAC,wBAAa,IAAI,IAAI,cAAc,KAAK,IAAG,IAAI,QAAQ;AAAA,UACvD,YAAY;AAAA,UACZ,MAAM,kBAAkB;AAAA,UACxB,UAAU,kBAAkB;AAAA,UAC5B,iBAAiB,kBAAkB;AAAA,UACnC,YAAY,kBAAkB;AAAA,UAC9B,UAAU,kBAAkB;AAAA,UAC5B,UAAU;AAAA,QAAA,CACV;AAAA,MACF;AACA;AAAA,IACD;AAAA,IACA;AACC,kBAAkB;AAAA,EACpB;AACA,MAAI,aAAa,QAAW;AACpB,WAAA;AAAA,EACR;AACA,SAAO,EAAE,GAAG,eAAe,OAAO,SAAS;AAC5C;"}
|
|
1
|
+
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<Result, Metadata> => ({\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tstate: new Map(),\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tlet newState: undefined | FileUploadMultiTemporalState<Result, Metadata>['state'] = undefined\n\n\tswitch (action.type) {\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\t// Deliberately mutating\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\t;(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'purge': {\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tURL.revokeObjectURL(fileState.previewUrl)\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).delete(fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst roundedProgress = Math.floor(progress) // throttling\n\t\t\t\tif (roundedProgress === previousFileState.progress) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress: roundedProgress,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tdefault:\n\t\t\tassertNever(action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3,"file":"useFileUpload.js","sources":["../../../src/upload/useFileUpload.ts"],"sourcesContent":["import { FileUploader, S3FileUploader, UploadedFileMetadata } from '@contember/client'\nimport { Reducer, useCallback, useEffect, useMemo, useReducer, useRef } from 'react'\nimport { useCurrentContentGraphQlClient } from '../content'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadCompoundState } from './FileUploadCompoundState'\nimport type { FileUploadMetadata } from './FileUploadMetadata'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport type {\n\tPurgeUpload,\n\tFileUploadOperations,\n\tInitializeUpload,\n\tStartUpload,\n\tStartUploadFileOptions,\n\tFailUpload,\n} from './FileUploadOperations'\nimport { fileUploadReducer, initializeFileUploadState } from './fileUploadReducer'\nimport type { FileWithMetadata } from './FileWithMetadata'\n\nexport type FileUpload<Result = unknown, Metadata = undefined> = [\n\tFileUploadCompoundState<Result, Metadata>,\n\tFileUploadOperations<Metadata>,\n]\n\nexport interface FileUploadOptions {\n}\n\nexport const useFileUpload = <Result = unknown, Metadata = undefined>({}: FileUploadOptions = {}): FileUpload<Result, Metadata> => {\n\tconst contentApiClient = useCurrentContentGraphQlClient()\n\n\tconst fileIdSeedRef = useRef(1)\n\n\tconst [internalState, dispatch] = useReducer<\n\t\tReducer<FileUploadMultiTemporalState<Result, Metadata>, FileUploadAction<Result, Metadata>>,\n\t\tundefined\n\t>(fileUploadReducer, undefined, initializeFileUploadState)\n\n\tconst defaultUploader = useMemo(() => new S3FileUploader(), [])\n\n\tconst purgeUpload = useCallback<PurgeUpload>(files => {\n\t\tdispatch({\n\t\t\ttype: 'purge',\n\t\t\tfiles,\n\t\t})\n\t}, [])\n\tconst failUpload = useCallback<FailUpload>(error => {\n\t\tdispatch({\n\t\t\ttype: 'finishWithError',\n\t\t\terror,\n\t\t})\n\t}, [])\n\n\tconst previewUrls = useRef(new Set<string>())\n\tconst fileIds = useRef(new WeakMap<File, FileId>())\n\tconst filesWithMetadataById = useRef(new Map<FileId, WeakRef<FileWithMetadata>>)\n\n\tconst initializeUpload = useCallback<InitializeUpload>(\n\t\tfiles => {\n\t\t\tconst newFileIds = new Set<FileId>()\n\t\t\tconst fileWithMetadataByFileConfig = new Map<FileId, FileWithMetadata>()\n\n\t\t\tfor (const fileMaybeWithId of files) {\n\t\t\t\tconst abortController = new AbortController()\n\n\t\t\t\tlet fileId: FileId\n\t\t\t\tlet file: File\n\n\t\t\t\tif (fileMaybeWithId instanceof File) {\n\t\t\t\t\tfileId = `__contember__file-${fileIdSeedRef.current++}`\n\t\t\t\t\tfile = fileMaybeWithId\n\t\t\t\t} else {\n\t\t\t\t\tfileId = fileMaybeWithId[0]\n\t\t\t\t\tfile = fileMaybeWithId[1]\n\t\t\t\t}\n\n\t\t\t\tabortController.signal.addEventListener('abort', () => {\n\t\t\t\t\tpurgeUpload([fileId])\n\t\t\t\t})\n\n\t\t\t\tconst previewUrl = URL.createObjectURL(file)\n\t\t\t\tconst fileWithMetadata: FileWithMetadata = {\n\t\t\t\t\tpreviewUrl: previewUrl,\n\t\t\t\t\tabortController,\n\t\t\t\t\tfile,\n\t\t\t\t\tfileId,\n\t\t\t\t}\n\t\t\t\tfileWithMetadataByFileConfig.set(fileId, fileWithMetadata)\n\n\t\t\t\tnewFileIds.add(fileId)\n\n\t\t\t\tpreviewUrls.current.add(previewUrl)\n\t\t\t\tfileIds.current.set(file, fileId)\n\t\t\t\tfilesWithMetadataById.current.set(fileId, new WeakRef(fileWithMetadata))\n\t\t\t}\n\t\t\tif (fileWithMetadataByFileConfig.size === 0) {\n\t\t\t\treturn fileWithMetadataByFileConfig\n\t\t\t}\n\n\t\t\tif (newFileIds.size) {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: 'purge',\n\t\t\t\t\tfiles: newFileIds,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tdispatch({\n\t\t\t\ttype: 'initialize',\n\t\t\t\tfiles: fileWithMetadataByFileConfig,\n\t\t\t})\n\n\t\t\treturn fileWithMetadataByFileConfig\n\t\t},\n\t\t[purgeUpload],\n\t)\n\tconst startUpload = useCallback<StartUpload<Metadata>>(\n\t\tfiles => {\n\t\t\tconst filesById = new Map<FileId, FileUploadMetadata<Metadata>>()\n\t\t\tconst groupedByUploader: Map<FileUploader, Map<File, UploadedFileMetadata>> = new Map()\n\n\t\t\tfor (const fileOrIdMaybeWithOptions of files) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet options: StartUploadFileOptions<Metadata>\n\n\t\t\t\tif (Array.isArray(fileOrIdMaybeWithOptions)) {\n\t\t\t\t\tfileOrId = fileOrIdMaybeWithOptions[0]\n\t\t\t\t\toptions = fileOrIdMaybeWithOptions[1]\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = fileOrIdMaybeWithOptions\n\t\t\t\t\toptions = {}\n\t\t\t\t}\n\t\t\t\tconst { uploader = defaultUploader, metadata } = options\n\n\t\t\t\tconst fileId = fileOrId instanceof File ? fileIds.current.get(fileOrId) : fileOrId\n\t\t\t\tconst fileState = fileId ? filesWithMetadataById.current.get(fileId)?.deref() : undefined\n\n\t\t\t\tif (fileId === undefined || fileState === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Trying to startUpload a file that hasn't been previously initialized. ` +\n\t\t\t\t\t\t\t`This will be possible in future, but isn't yet.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\n\t\t\t\tfilesById.set(fileId, {\n\t\t\t\t\tuploader,\n\t\t\t\t\tmetadata,\n\t\t\t\t})\n\n\t\t\t\tlet filesWithSameUploader = groupedByUploader.get(uploader)\n\t\t\t\tif (filesWithSameUploader === undefined) {\n\t\t\t\t\tgroupedByUploader.set(uploader, (filesWithSameUploader = new Map()))\n\t\t\t\t}\n\t\t\t\tfilesWithSameUploader.set(fileState.file, {\n\t\t\t\t\tabortSignal: fileState.abortController.signal,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tdispatch({\n\t\t\t\ttype: 'startUploading',\n\t\t\t\tfiles: filesById,\n\t\t\t})\n\n\t\t\tfor (const [uploader, filesForUpload] of groupedByUploader) {\n\t\t\t\ttry {\n\t\t\t\t\tuploader.upload(filesForUpload, {\n\t\t\t\t\t\tonProgress: progress => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'updateUploadProgress',\n\t\t\t\t\t\t\t\tprogress,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonSuccess: result => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'finishSuccessfully',\n\t\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError: error => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'finishWithError',\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcontentApiClient,\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'finishWithError',\n\t\t\t\t\t\terror: Array.from(filesForUpload).map(([file]) => [file, error]),\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[contentApiClient, defaultUploader],\n\t)\n\n\tconst operations = useMemo<FileUploadOperations<Metadata>>(\n\t\t() => ({\n\t\t\tfailUpload,\n\t\t\tinitializeUpload,\n\t\t\tpurgeUpload,\n\t\t\tstartUpload,\n\t\t}),\n\t\t[failUpload, initializeUpload, purgeUpload, startUpload],\n\t)\n\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tfor (const previewUrl of Array.from(previewUrls.current)) {\n\t\t\t\tURL.revokeObjectURL(previewUrl)\n\t\t\t}\n\t\t},\n\t\t[],\n\t)\n\n\treturn [internalState.state, operations]\n}\n"],"names":[],"mappings":";;;;AA2BO,MAAM,gBAAgB,CAAyC,CAAC,IAAuB,OAAqC;AAClI,QAAM,mBAAmB;AAEnB,QAAA,gBAAgB,OAAO,CAAC;AAE9B,QAAM,CAAC,eAAe,QAAQ,IAAI,WAGhC,mBAAmB,QAAW,yBAAyB;AAEzD,QAAM,kBAAkB,QAAQ,MAAM,IAAI,eAAe,GAAG,CAAE,CAAA;AAExD,QAAA,cAAc,YAAyB,CAAS,UAAA;AAC5C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AACC,QAAA,aAAa,YAAwB,CAAS,UAAA;AAC1C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AAEL,QAAM,cAAc,OAAW,oBAAA,IAAa,CAAA;AAC5C,QAAM,UAAU,OAAW,oBAAA,QAAuB,CAAA;AAC5C,QAAA,wBAAwB,OAAO,oBAAI,IAAsC,CAAA;AAE/E,QAAM,mBAAmB;AAAA,IACxB,CAAS,UAAA;AACF,YAAA,iCAAiB;AACjB,YAAA,mDAAmC;AAEzC,iBAAW,mBAAmB,OAAO;AAC9B,cAAA,kBAAkB,IAAI;AAExB,YAAA;AACA,YAAA;AAEJ,YAAI,2BAA2B,MAAM;AACpC,mBAAS,qBAAqB,cAAc;AACrC,iBAAA;AAAA,QAAA,OACD;AACN,mBAAS,gBAAgB;
|
|
1
|
+
{"version":3,"file":"useFileUpload.js","sources":["../../../src/upload/useFileUpload.ts"],"sourcesContent":["import { FileUploader, S3FileUploader, UploadedFileMetadata } from '@contember/client'\nimport { Reducer, useCallback, useEffect, useMemo, useReducer, useRef } from 'react'\nimport { useCurrentContentGraphQlClient } from '../content'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadCompoundState } from './FileUploadCompoundState'\nimport type { FileUploadMetadata } from './FileUploadMetadata'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport type {\n\tPurgeUpload,\n\tFileUploadOperations,\n\tInitializeUpload,\n\tStartUpload,\n\tStartUploadFileOptions,\n\tFailUpload,\n} from './FileUploadOperations'\nimport { fileUploadReducer, initializeFileUploadState } from './fileUploadReducer'\nimport type { FileWithMetadata } from './FileWithMetadata'\n\nexport type FileUpload<Result = unknown, Metadata = undefined> = [\n\tFileUploadCompoundState<Result, Metadata>,\n\tFileUploadOperations<Metadata>,\n]\n\nexport interface FileUploadOptions {\n}\n\nexport const useFileUpload = <Result = unknown, Metadata = undefined>({}: FileUploadOptions = {}): FileUpload<Result, Metadata> => {\n\tconst contentApiClient = useCurrentContentGraphQlClient()\n\n\tconst fileIdSeedRef = useRef(1)\n\n\tconst [internalState, dispatch] = useReducer<\n\t\tReducer<FileUploadMultiTemporalState<Result, Metadata>, FileUploadAction<Result, Metadata>>,\n\t\tundefined\n\t>(fileUploadReducer, undefined, initializeFileUploadState)\n\n\tconst defaultUploader = useMemo(() => new S3FileUploader(), [])\n\n\tconst purgeUpload = useCallback<PurgeUpload>(files => {\n\t\tdispatch({\n\t\t\ttype: 'purge',\n\t\t\tfiles,\n\t\t})\n\t}, [])\n\tconst failUpload = useCallback<FailUpload>(error => {\n\t\tdispatch({\n\t\t\ttype: 'finishWithError',\n\t\t\terror,\n\t\t})\n\t}, [])\n\n\tconst previewUrls = useRef(new Set<string>())\n\tconst fileIds = useRef(new WeakMap<File, FileId>())\n\tconst filesWithMetadataById = useRef(new Map<FileId, WeakRef<FileWithMetadata>>)\n\n\tconst initializeUpload = useCallback<InitializeUpload>(\n\t\tfiles => {\n\t\t\tconst newFileIds = new Set<FileId>()\n\t\t\tconst fileWithMetadataByFileConfig = new Map<FileId, FileWithMetadata>()\n\n\t\t\tfor (const fileMaybeWithId of files) {\n\t\t\t\tconst abortController = new AbortController()\n\n\t\t\t\tlet fileId: FileId\n\t\t\t\tlet file: File\n\n\t\t\t\tif (fileMaybeWithId instanceof File) {\n\t\t\t\t\tfileId = `__contember__file-${fileIdSeedRef.current++}`\n\t\t\t\t\tfile = fileMaybeWithId\n\t\t\t\t} else {\n\t\t\t\t\tfileId = fileMaybeWithId[0]\n\t\t\t\t\tfile = fileMaybeWithId[1]\n\t\t\t\t}\n\n\t\t\t\tabortController.signal.addEventListener('abort', () => {\n\t\t\t\t\tpurgeUpload([fileId])\n\t\t\t\t})\n\n\t\t\t\tconst previewUrl = URL.createObjectURL(file)\n\t\t\t\tconst fileWithMetadata: FileWithMetadata = {\n\t\t\t\t\tpreviewUrl: previewUrl,\n\t\t\t\t\tabortController,\n\t\t\t\t\tfile,\n\t\t\t\t\tfileId,\n\t\t\t\t}\n\t\t\t\tfileWithMetadataByFileConfig.set(fileId, fileWithMetadata)\n\n\t\t\t\tnewFileIds.add(fileId)\n\n\t\t\t\tpreviewUrls.current.add(previewUrl)\n\t\t\t\tfileIds.current.set(file, fileId)\n\t\t\t\tfilesWithMetadataById.current.set(fileId, new WeakRef(fileWithMetadata))\n\t\t\t}\n\t\t\tif (fileWithMetadataByFileConfig.size === 0) {\n\t\t\t\treturn fileWithMetadataByFileConfig\n\t\t\t}\n\n\t\t\tif (newFileIds.size) {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: 'purge',\n\t\t\t\t\tfiles: newFileIds,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tdispatch({\n\t\t\t\ttype: 'initialize',\n\t\t\t\tfiles: fileWithMetadataByFileConfig,\n\t\t\t})\n\n\t\t\treturn fileWithMetadataByFileConfig\n\t\t},\n\t\t[purgeUpload],\n\t)\n\tconst startUpload = useCallback<StartUpload<Metadata>>(\n\t\tfiles => {\n\t\t\tconst filesById = new Map<FileId, FileUploadMetadata<Metadata>>()\n\t\t\tconst groupedByUploader: Map<FileUploader, Map<File, UploadedFileMetadata>> = new Map()\n\n\t\t\tfor (const fileOrIdMaybeWithOptions of files) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet options: StartUploadFileOptions<Metadata>\n\n\t\t\t\tif (Array.isArray(fileOrIdMaybeWithOptions)) {\n\t\t\t\t\tfileOrId = fileOrIdMaybeWithOptions[0]\n\t\t\t\t\toptions = fileOrIdMaybeWithOptions[1]\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = fileOrIdMaybeWithOptions\n\t\t\t\t\toptions = {}\n\t\t\t\t}\n\t\t\t\tconst { uploader = defaultUploader, metadata } = options\n\n\t\t\t\tconst fileId = fileOrId instanceof File ? fileIds.current.get(fileOrId) : fileOrId\n\t\t\t\tconst fileState = fileId ? filesWithMetadataById.current.get(fileId)?.deref() : undefined\n\n\t\t\t\tif (fileId === undefined || fileState === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Trying to startUpload a file that hasn't been previously initialized. ` +\n\t\t\t\t\t\t\t`This will be possible in future, but isn't yet.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\n\t\t\t\tfilesById.set(fileId, {\n\t\t\t\t\tuploader,\n\t\t\t\t\tmetadata,\n\t\t\t\t})\n\n\t\t\t\tlet filesWithSameUploader = groupedByUploader.get(uploader)\n\t\t\t\tif (filesWithSameUploader === undefined) {\n\t\t\t\t\tgroupedByUploader.set(uploader, (filesWithSameUploader = new Map()))\n\t\t\t\t}\n\t\t\t\tfilesWithSameUploader.set(fileState.file, {\n\t\t\t\t\tabortSignal: fileState.abortController.signal,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tdispatch({\n\t\t\t\ttype: 'startUploading',\n\t\t\t\tfiles: filesById,\n\t\t\t})\n\n\t\t\tfor (const [uploader, filesForUpload] of groupedByUploader) {\n\t\t\t\ttry {\n\t\t\t\t\tuploader.upload(filesForUpload, {\n\t\t\t\t\t\tonProgress: progress => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'updateUploadProgress',\n\t\t\t\t\t\t\t\tprogress,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonSuccess: result => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'finishSuccessfully',\n\t\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError: error => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'finishWithError',\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcontentApiClient,\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'finishWithError',\n\t\t\t\t\t\terror: Array.from(filesForUpload).map(([file]) => [file, error]),\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[contentApiClient, defaultUploader],\n\t)\n\n\tconst operations = useMemo<FileUploadOperations<Metadata>>(\n\t\t() => ({\n\t\t\tfailUpload,\n\t\t\tinitializeUpload,\n\t\t\tpurgeUpload,\n\t\t\tstartUpload,\n\t\t}),\n\t\t[failUpload, initializeUpload, purgeUpload, startUpload],\n\t)\n\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tfor (const previewUrl of Array.from(previewUrls.current)) {\n\t\t\t\tURL.revokeObjectURL(previewUrl)\n\t\t\t}\n\t\t},\n\t\t[],\n\t)\n\n\treturn [internalState.state, operations]\n}\n"],"names":[],"mappings":";;;;AA2BO,MAAM,gBAAgB,CAAyC,CAAC,IAAuB,OAAqC;AAClI,QAAM,mBAAmB;AAEnB,QAAA,gBAAgB,OAAO,CAAC;AAE9B,QAAM,CAAC,eAAe,QAAQ,IAAI,WAGhC,mBAAmB,QAAW,yBAAyB;AAEzD,QAAM,kBAAkB,QAAQ,MAAM,IAAI,eAAe,GAAG,CAAE,CAAA;AAExD,QAAA,cAAc,YAAyB,CAAS,UAAA;AAC5C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AACC,QAAA,aAAa,YAAwB,CAAS,UAAA;AAC1C,aAAA;AAAA,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AAA,gBACN;AAAA,cAAA,CACA;AAAA,YACF;AAAA,YACA;AAAA,UAAA,CACA;AAAA,iBACO;AACC,mBAAA;AAAA,YACR,MAAM;AAAA,YACN,OAAO,MAAM,KAAK,cAAc,EAAE,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;AAAA,UAAA,CAC/D;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,kBAAkB,eAAe;AAAA,EAAA;AAGnC,QAAM,aAAa;AAAA,IAClB,OAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAED,CAAC,YAAY,kBAAkB,aAAa,WAAW;AAAA,EAAA;AAIxD;AAAA,IACC,MAAM,MAAM;AACX,iBAAW,cAAc,MAAM,KAAK,YAAY,OAAO,GAAG;AACzD,YAAI,gBAAgB,UAAU;AAAA,MAC/B;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EAAA;AAGK,SAAA,CAAC,cAAc,OAAO,UAAU;AACxC;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useState, useCallback } from "react";
|
|
2
|
+
import { memo, useMemo, useState, useCallback } from "react";
|
|
3
3
|
import { ApiBaseUrlContext } from "./config/ApiBaseUrlContext.js";
|
|
4
4
|
import { LoginTokenContext } from "./config/LoginTokenContext.js";
|
|
5
5
|
import { SetSessionTokenContext } from "./auth/SetSessionTokenContext.js";
|
|
@@ -15,7 +15,16 @@ const ContemberClient = memo(function ContemberClient2({
|
|
|
15
15
|
sessionToken,
|
|
16
16
|
stage
|
|
17
17
|
}) {
|
|
18
|
-
const [
|
|
18
|
+
const [localStorageSessionToken, setLocalStorageSessionToken] = useLocalStorageSessionToken();
|
|
19
|
+
const sessionTokenContextValue = useMemo(() => ({
|
|
20
|
+
propsToken: sessionToken,
|
|
21
|
+
token: localStorageSessionToken ?? sessionToken,
|
|
22
|
+
source: localStorageSessionToken ? "localstorage" : sessionToken ? "props" : void 0
|
|
23
|
+
}), [localStorageSessionToken, sessionToken]);
|
|
24
|
+
return /* @__PURE__ */ jsx(ApiBaseUrlContext.Provider, { value: apiBaseUrl, children: /* @__PURE__ */ jsx(LoginTokenContext.Provider, { value: loginToken, children: /* @__PURE__ */ jsx(SetSessionTokenContext.Provider, { value: setLocalStorageSessionToken, children: /* @__PURE__ */ jsx(SessionTokenContext.Provider, { value: sessionTokenContextValue, children: /* @__PURE__ */ jsx(ProjectSlugContext.Provider, { value: project, children: /* @__PURE__ */ jsx(StageSlugContext.Provider, { value: stage, children }) }) }) }) }) });
|
|
25
|
+
});
|
|
26
|
+
const useLocalStorageSessionToken = () => {
|
|
27
|
+
const [sessionTokenInner, setSessionTokenInner] = useState(() => localStorage.getItem(sessionTokenKey) ?? void 0);
|
|
19
28
|
const setSessionToken = useCallback((token) => {
|
|
20
29
|
if (token !== void 0) {
|
|
21
30
|
localStorage.setItem(sessionTokenKey, token);
|
|
@@ -24,8 +33,8 @@ const ContemberClient = memo(function ContemberClient2({
|
|
|
24
33
|
}
|
|
25
34
|
setSessionTokenInner(token);
|
|
26
35
|
}, []);
|
|
27
|
-
return
|
|
28
|
-
}
|
|
36
|
+
return [sessionTokenInner, setSessionToken];
|
|
37
|
+
};
|
|
29
38
|
export {
|
|
30
39
|
ContemberClient
|
|
31
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContemberClient.js","sources":["../../src/ContemberClient.tsx"],"sourcesContent":["import { memo, useCallback,
|
|
1
|
+
{"version":3,"file":"ContemberClient.js","sources":["../../src/ContemberClient.tsx"],"sourcesContent":["import { memo, useCallback, useMemo, useState } from 'react'\nimport { SessionTokenContext, SessionTokenContextValue, SetSessionTokenContext } from './auth'\nimport { ApiBaseUrlContext, LoginTokenContext } from './config'\nimport { ProjectSlugContext, StageSlugContext } from './project'\n\nexport interface ContemberClientProps {\n\tapiBaseUrl: string\n\tsessionToken?: string\n\tloginToken?: string\n\tproject?: string\n\tstage?: string\n}\n\nconst sessionTokenKey = 'contember_session_token'\n\n/**\n * @group Entrypoints\n */\nexport const ContemberClient = memo<ContemberClientProps & { children: React.ReactNode }>(function ContemberClient({\n\tapiBaseUrl,\n\tchildren,\n\tloginToken,\n\tproject,\n\tsessionToken,\n\tstage,\n}) {\n\tconst [localStorageSessionToken, setLocalStorageSessionToken] = useLocalStorageSessionToken()\n\n\tconst sessionTokenContextValue = useMemo((): SessionTokenContextValue => ({\n\t\tpropsToken: sessionToken,\n\t\ttoken: localStorageSessionToken ?? sessionToken,\n\t\tsource: localStorageSessionToken ? 'localstorage' : (sessionToken ? 'props' : undefined),\n\t}), [localStorageSessionToken, sessionToken])\n\n\treturn (\n\t\t<ApiBaseUrlContext.Provider value={apiBaseUrl}>\n\t\t\t<LoginTokenContext.Provider value={loginToken}>\n\t\t\t\t<SetSessionTokenContext.Provider value={setLocalStorageSessionToken}>\n\t\t\t\t\t<SessionTokenContext.Provider value={sessionTokenContextValue}>\n\t\t\t\t\t\t<ProjectSlugContext.Provider value={project}>\n\t\t\t\t\t\t\t<StageSlugContext.Provider value={stage}>{children}</StageSlugContext.Provider>\n\t\t\t\t\t\t</ProjectSlugContext.Provider>\n\t\t\t\t\t</SessionTokenContext.Provider>\n\t\t\t\t</SetSessionTokenContext.Provider>\n\t\t\t</LoginTokenContext.Provider>\n\t\t</ApiBaseUrlContext.Provider>\n\t)\n})\n\nconst useLocalStorageSessionToken = (): [value: string | undefined, set: (token: string | undefined) => void] => {\n\tconst [sessionTokenInner, setSessionTokenInner] = useState(() => localStorage.getItem(sessionTokenKey) ?? undefined)\n\n\tconst setSessionToken = useCallback((token: string | undefined) => {\n\t\tif (token !== undefined) {\n\t\t\tlocalStorage.setItem(sessionTokenKey, token)\n\t\t} else {\n\t\t\tlocalStorage.removeItem(sessionTokenKey)\n\t\t}\n\t\tsetSessionTokenInner(token)\n\t}, [])\n\n\treturn [sessionTokenInner, setSessionToken]\n}\n"],"names":["ContemberClient"],"mappings":";;;;;;;;AAaA,MAAM,kBAAkB;AAKX,MAAA,kBAAkB,KAA2D,SAASA,iBAAgB;AAAA,EAClH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAG;AACF,QAAM,CAAC,0BAA0B,2BAA2B,IAAI,4BAA4B;AAEtF,QAAA,2BAA2B,QAAQ,OAAiC;AAAA,IACzE,YAAY;AAAA,IACZ,OAAO,4BAA4B;AAAA,IACnC,QAAQ,2BAA2B,iBAAkB,eAAe,UAAU;AAAA,EAC3E,IAAA,CAAC,0BAA0B,YAAY,CAAC;AAE5C,6BACE,kBAAkB,UAAlB,EAA2B,OAAO,YAClC,8BAAC,kBAAkB,UAAlB,EAA2B,OAAO,YAClC,UAAC,oBAAA,uBAAuB,UAAvB,EAAgC,OAAO,6BACvC,UAAC,oBAAA,oBAAoB,UAApB,EAA6B,OAAO,0BACpC,UAAA,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACnC,UAAA,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,OAAQ,SAAS,CAAA,GACpD,EACD,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF,CAAC;AAED,MAAM,8BAA8B,MAA6E;AAC1G,QAAA,CAAC,mBAAmB,oBAAoB,IAAI,SAAS,MAAM,aAAa,QAAQ,eAAe,KAAK,MAAS;AAE7G,QAAA,kBAAkB,YAAY,CAAC,UAA8B;AAClE,QAAI,UAAU,QAAW;AACX,mBAAA,QAAQ,iBAAiB,KAAK;AAAA,IAAA,OACrC;AACN,mBAAa,WAAW,eAAe;AAAA,IACxC;AACA,yBAAqB,KAAK;AAAA,EAC3B,GAAG,CAAE,CAAA;AAEE,SAAA,CAAC,mBAAmB,eAAe;AAC3C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useApiRequest.js","sources":["../../../src/apiRequest/useApiRequest.ts"],"sourcesContent":["import type {\n\tGraphQlClient,\n\tGraphQlClientFailedRequestMetadata,\n\tGraphQlClientRequestOptions,\n\tGraphQlClientVariables,\n} from '@contember/client'\nimport { useCallback, useEffect, useReducer, useRef } from 'react'\nimport { ApiRequestReducer, apiRequestReducer } from './apiRequestReducer'\nimport type { ApiRequestState } from './ApiRequestState'\n\nconst initialState: ApiRequestState<any> = {\n\tisLoading: false,\n\tisFinished: false,\n\treadyState: 'uninitialized',\n}\n\nexport type UseApiRequestResult<SuccessData> = [\n\tApiRequestState<SuccessData>,\n\t(\n\t\tquery: string,\n\t\tvariables?: GraphQlClientVariables,\n\t\toptions?: Omit<GraphQlClientRequestOptions, 'variables'>,\n\t) => Promise<SuccessData>,\n]\n\nexport const useApiRequest = <SuccessData>(client: GraphQlClient): UseApiRequestResult<SuccessData> => {\n\tconst [state, dispatch] = useReducer(apiRequestReducer as ApiRequestReducer<SuccessData>, initialState)\n\n\tconst isUnmountedRef = useRef(false)\n\tconst sendRequest = useCallback(\n\t\tasync (\n\t\t\tquery: string,\n\t\t\tvariables: GraphQlClientVariables = {},\n\t\t\toptions?: Omit<GraphQlClientRequestOptions, 'variables'>,\n\t\t): Promise<SuccessData> => {\n\t\t\tif (isUnmountedRef.current) {\n\t\t\t\treturn Promise.reject()\n\t\t\t}\n\t\t\tdispatch({\n\t\t\t\ttype: 'initialize',\n\t\t\t})\n\t\t\treturn client\n\t\t\t\t.sendRequest<SuccessData>(query, {\n\t\t\t\t\t...options,\n\t\t\t\t\tvariables,\n\t\t\t\t})\n\t\t\t\t.then(data => {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'resolveSuccessfully',\n\t\t\t\t\t\tdata,\n\t\t\t\t\t})\n\t\t\t\t\treturn Promise.resolve(data)\n\t\t\t\t})\n\t\t\t\t.catch((error: GraphQlClientFailedRequestMetadata) => {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'resolveWithError',\n\t\t\t\t\t\terror,\n\t\t\t\t\t})\n\t\t\t\t\treturn Promise.reject(error)\n\t\t\t\t})\n\t\t},\n\t\t[client],\n\t)\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tisUnmountedRef.current = true\n\t\t},\n\t\t[], // This empty array is crucial! Otherwise it will first \"unmount\" before second render no matter what.\n\t)\n\n\treturn [state, sendRequest]\n}\n"],"names":[],"mappings":";;AAUA,MAAM,eAAqC;AAAA,EAC1C,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACb;AAWa,MAAA,gBAAgB,CAAc,WAA4D;AACtG,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,mBAAqD,YAAY;AAEhG,QAAA,iBAAiB,OAAO,KAAK;AACnC,QAAM,cAAc;AAAA,IACnB,OACC,OACA,YAAoC,IACpC,YAC0B;AAC1B,UAAI,eAAe,SAAS;AAC3B,eAAO,QAAQ;MAChB;AACS,eAAA;AAAA,QACR,MAAM;AAAA,MAAA,CACN;AACM,aAAA,OACL,YAAyB,OAAO;AAAA,QAChC,GAAG;AAAA,QACH;AAAA,MAAA,CACA,EACA,KAAK,CAAQ,SAAA;AACJ,iBAAA;AAAA,UACR,MAAM;AAAA,UACN;AAAA,QAAA,CACA;AACM,eAAA,QAAQ,QAAQ,IAAI;AAAA,MAAA,CAC3B,EACA,MAAM,CAAC,UAA8C;AAC5C,iBAAA;AAAA,UACR,MAAM;AAAA,UACN;AAAA,QAAA,CACA;AACM,eAAA,QAAQ,OAAO,KAAK;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGR;AAAA,IACC,MAAM,MAAM;AACX,qBAAe,UAAU;AAAA,IAC1B;AAAA,IACA,CAAC;AAAA,EAAA;AAGK,SAAA,CAAC,OAAO,WAAW;AAC3B;"}
|
|
1
|
+
{"version":3,"file":"useApiRequest.js","sources":["../../../src/apiRequest/useApiRequest.ts"],"sourcesContent":["import type {\n\tGraphQlClient,\n\tGraphQlClientFailedRequestMetadata,\n\tGraphQlClientRequestOptions,\n\tGraphQlClientVariables,\n} from '@contember/client'\nimport { useCallback, useEffect, useReducer, useRef } from 'react'\nimport { ApiRequestReducer, apiRequestReducer } from './apiRequestReducer'\nimport type { ApiRequestState } from './ApiRequestState'\n\nconst initialState: ApiRequestState<any> = {\n\tisLoading: false,\n\tisFinished: false,\n\treadyState: 'uninitialized',\n}\n\nexport type UseApiRequestResult<SuccessData> = [\n\tApiRequestState<SuccessData>,\n\t(\n\t\tquery: string,\n\t\tvariables?: GraphQlClientVariables,\n\t\toptions?: Omit<GraphQlClientRequestOptions, 'variables'>,\n\t) => Promise<SuccessData>,\n]\n\nexport const useApiRequest = <SuccessData>(client: GraphQlClient): UseApiRequestResult<SuccessData> => {\n\tconst [state, dispatch] = useReducer(apiRequestReducer as ApiRequestReducer<SuccessData>, initialState)\n\n\tconst isUnmountedRef = useRef(false)\n\tconst sendRequest = useCallback(\n\t\tasync (\n\t\t\tquery: string,\n\t\t\tvariables: GraphQlClientVariables = {},\n\t\t\toptions?: Omit<GraphQlClientRequestOptions, 'variables'>,\n\t\t): Promise<SuccessData> => {\n\t\t\tif (isUnmountedRef.current) {\n\t\t\t\treturn Promise.reject()\n\t\t\t}\n\t\t\tdispatch({\n\t\t\t\ttype: 'initialize',\n\t\t\t})\n\t\t\treturn client\n\t\t\t\t.sendRequest<SuccessData>(query, {\n\t\t\t\t\t...options,\n\t\t\t\t\tvariables,\n\t\t\t\t})\n\t\t\t\t.then(data => {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'resolveSuccessfully',\n\t\t\t\t\t\tdata,\n\t\t\t\t\t})\n\t\t\t\t\treturn Promise.resolve(data)\n\t\t\t\t})\n\t\t\t\t.catch((error: GraphQlClientFailedRequestMetadata) => {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'resolveWithError',\n\t\t\t\t\t\terror,\n\t\t\t\t\t})\n\t\t\t\t\treturn Promise.reject(error)\n\t\t\t\t})\n\t\t},\n\t\t[client],\n\t)\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tisUnmountedRef.current = true\n\t\t},\n\t\t[], // This empty array is crucial! Otherwise it will first \"unmount\" before second render no matter what.\n\t)\n\n\treturn [state, sendRequest]\n}\n"],"names":[],"mappings":";;AAUA,MAAM,eAAqC;AAAA,EAC1C,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACb;AAWa,MAAA,gBAAgB,CAAc,WAA4D;AACtG,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,mBAAqD,YAAY;AAEhG,QAAA,iBAAiB,OAAO,KAAK;AACnC,QAAM,cAAc;AAAA,IACnB,OACC,OACA,YAAoC,IACpC,YAC0B;AAC1B,UAAI,eAAe,SAAS;AAC3B,eAAO,QAAQ;MAChB;AACS,eAAA;AAAA,QACR,MAAM;AAAA,MAAA,CACN;AACM,aAAA,OACL,YAAyB,OAAO;AAAA,QAChC,GAAG;AAAA,QACH;AAAA,MAAA,CACA,EACA,KAAK,CAAQ,SAAA;AACJ,iBAAA;AAAA,UACR,MAAM;AAAA,UACN;AAAA,QAAA,CACA;AACM,eAAA,QAAQ,QAAQ,IAAI;AAAA,MAAA,CAC3B,EACA,MAAM,CAAC,UAA8C;AAC5C,iBAAA;AAAA,UACR,MAAM;AAAA,UACN;AAAA,QAAA,CACA;AACM,eAAA,QAAQ,OAAO,KAAK;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGR;AAAA,IACC,MAAM,MAAM;AACX,qBAAe,UAAU;AAAA,IAC1B;AAAA,IACA,CAAC;AAAA;AAAA,EAAA;AAGK,SAAA,CAAC,OAAO,WAAW;AAC3B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionTokenContext.js","sources":["../../../src/auth/SessionTokenContext.ts"],"sourcesContent":["import { createContext } from 'react'\n\nexport const SessionTokenContext = createContext<
|
|
1
|
+
{"version":3,"file":"SessionTokenContext.js","sources":["../../../src/auth/SessionTokenContext.ts"],"sourcesContent":["import { createContext } from 'react'\n\nexport interface SessionTokenContextValue {\n\tpropsToken: string | undefined\n\tsource: 'props' | 'localstorage' | undefined\n\ttoken: string | undefined\n}\n\nexport const SessionTokenContext = createContext<SessionTokenContextValue>({\n\tpropsToken: undefined,\n\tsource: undefined,\n\ttoken: undefined,\n})\n"],"names":[],"mappings":";AAQO,MAAM,sBAAsB,cAAwC;AAAA,EAC1E,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { SessionTokenContext } from "./SessionTokenContext.js";
|
|
3
|
-
const useSessionToken = () => useContext(SessionTokenContext);
|
|
3
|
+
const useSessionToken = () => useContext(SessionTokenContext).token;
|
|
4
|
+
const useSessionTokenWithMeta = () => useContext(SessionTokenContext);
|
|
4
5
|
export {
|
|
5
|
-
useSessionToken
|
|
6
|
+
useSessionToken,
|
|
7
|
+
useSessionTokenWithMeta
|
|
6
8
|
};
|
|
7
9
|
//# sourceMappingURL=useSessionToken.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionToken.js","sources":["../../../src/auth/useSessionToken.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { SessionTokenContext } from './SessionTokenContext'\n\nexport const useSessionToken = () => useContext(SessionTokenContext)\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useSessionToken.js","sources":["../../../src/auth/useSessionToken.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { SessionTokenContext } from './SessionTokenContext'\n\nexport const useSessionToken = () => useContext(SessionTokenContext).token\nexport const useSessionTokenWithMeta = () => useContext(SessionTokenContext)\n"],"names":[],"mappings":";;AAGO,MAAM,kBAAkB,MAAM,WAAW,mBAAmB,EAAE;AACxD,MAAA,0BAA0B,MAAM,WAAW,mBAAmB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderElementFallback.js","sources":["../../../../src/components/RichTextRenderer/RenderElementFallback.tsx"],"sourcesContent":["import { createElement, ReactElement } from 'react'\nimport type { BuiltinElements, RichTextReferenceElement, RichTextTableRowElement } from './BuiltinElements'\nimport { renderChildren, RenderChildrenOptions } from './renderChildren'\nimport { resolveRichTextElementMetadata } from './resolveRichTextElementMetadata'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { useRichTextRenderMetadata } from './RichTextRenderMetadataContext'\n\nexport interface RenderElementFallbackProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\telement: BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>\n}\n\nconst getElementDataAttributes = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\telement: RichTextElement<CustomElements, CustomLeaves>,\n\tattributeNamePrefix: string = 'contember-',\n): {\n\t[dataAttribute: string]: string | number | boolean\n} => {\n\tconst { children, referenceId, ...extendedSpecifics } = element\n\n\treturn Object.fromEntries(\n\t\tObject.entries(extendedSpecifics)\n\t\t\t.filter(([, value]) => {\n\t\t\t\tconst t = typeof value\n\t\t\t\treturn t === 'string' || t === 'number' || t === 'boolean'\n\t\t\t})\n\t\t\t.map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value]),\n\t)\n}\n\nexport function RenderElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children, options }: RenderElementFallbackProps<CustomElements, CustomLeaves>) {\n\tconst attributes = getElementDataAttributes(element, options.attributeNamePrefix)\n\n\tswitch (element.type) {\n\t\tcase 'anchor':\n\t\t\treturn (\n\t\t\t\t<a {...attributes} href={element.href}>\n\t\t\t\t\t{children}\n\t\t\t\t</a>\n\t\t\t)\n\t\tcase 'heading':\n\t\t\treturn createElement(`h${element.level}`, attributes, children) // TODO numbered\n\t\tcase 'horizontalRule':\n\t\t\treturn <hr {...attributes} />\n\t\tcase 'listItem':\n\t\t\treturn <li {...attributes}>{children}</li>\n\t\tcase 'orderedList':\n\t\t\treturn <ol {...attributes}>{children}</ol>\n\t\tcase 'paragraph':\n\t\t\treturn <p {...attributes}>{children}</p>\n\t\tcase 'reference': {\n\t\t\treturn <ReferenceElementFallback element={element} children={children} />\n\t\t}\n\t\tcase 'scrollTarget':\n\t\t\treturn (\n\t\t\t\t<span {...attributes} id={element.identifier}>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t)\n\t\tcase 'table': {\n\t\t\tconst firstRow = element.children[0] as RichTextTableRowElement<CustomElements, CustomLeaves> | undefined\n\t\t\tif (!firstRow || firstRow.headerScope !== 'table') {\n\t\t\t\treturn (\n\t\t\t\t\t<table {...attributes}>\n\t\t\t\t\t\t<tbody>{children}</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn (\n\t\t\t\t<table {...attributes}>\n\t\t\t\t\t<thead>{renderChildren<CustomElements, CustomLeaves>([firstRow], options)}</thead>\n\t\t\t\t\t<tbody>{renderChildren<CustomElements, CustomLeaves>(element.children.slice(1) as any, options)}</tbody>\n\t\t\t\t</table>\n\t\t\t)\n\t\t}\n\t\tcase 'tableRow':\n\t\t\treturn <tr {...attributes}>{children}</tr>\n\t\tcase 'tableCell': {\n\t\t\tif (element.headerScope) {\n\t\t\t\treturn (\n\t\t\t\t\t<th {...attributes} scope={element.headerScope}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</th>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn <td {...attributes}>{children}</td>\n\t\t}\n\t\tcase 'unorderedList':\n\t\t\treturn <ul {...attributes}>{children}</ul>\n\t\tdefault: {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: unknown element of type '${(element as { type: string }).type}'.`,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\treturn children // At least render the text contents\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction ReferenceElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children }: { element: RichTextReferenceElement<CustomElements, CustomLeaves>; children: ReactElement }) {\n\tconst metadata = useRichTextRenderMetadata<CustomElements, CustomLeaves>()\n\tconst elementMetadata = resolveRichTextElementMetadata<CustomElements, CustomLeaves>(element, metadata)\n\n\tif (\n\t\telementMetadata.referenceRenderer === undefined ||\n\t\telementMetadata.referenceType === undefined ||\n\t\telementMetadata.reference === undefined\n\t) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`RichTextRenderer: cannot render reference of type '${elementMetadata.referenceType}'.`,\n\t\t\t)\n\t\t} else {\n\t\t\treturn children // At least render the text contents\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{elementMetadata.referenceRenderer?.({\n\t\t\t\treferenceType: elementMetadata.referenceType,\n\t\t\t\treferenceRenderer: elementMetadata.referenceRenderer,\n\t\t\t\treference: elementMetadata.reference,\n\t\t\t\tformatVersion: elementMetadata.formatVersion,\n\t\t\t\telement,\n\t\t\t\tchildren,\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,2BAA2B,CAIhC,SACA,sBAA8B,iBAG1B;AACJ,QAAM,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"RenderElementFallback.js","sources":["../../../../src/components/RichTextRenderer/RenderElementFallback.tsx"],"sourcesContent":["import { createElement, ReactElement } from 'react'\nimport type { BuiltinElements, RichTextReferenceElement, RichTextTableRowElement } from './BuiltinElements'\nimport { renderChildren, RenderChildrenOptions } from './renderChildren'\nimport { resolveRichTextElementMetadata } from './resolveRichTextElementMetadata'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { useRichTextRenderMetadata } from './RichTextRenderMetadataContext'\n\nexport interface RenderElementFallbackProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\telement: BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>\n}\n\nconst getElementDataAttributes = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\telement: RichTextElement<CustomElements, CustomLeaves>,\n\tattributeNamePrefix: string = 'contember-',\n): {\n\t[dataAttribute: string]: string | number | boolean\n} => {\n\tconst { children, referenceId, ...extendedSpecifics } = element\n\n\treturn Object.fromEntries(\n\t\tObject.entries(extendedSpecifics)\n\t\t\t.filter(([, value]) => {\n\t\t\t\tconst t = typeof value\n\t\t\t\treturn t === 'string' || t === 'number' || t === 'boolean'\n\t\t\t})\n\t\t\t.map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value]),\n\t)\n}\n\nexport function RenderElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children, options }: RenderElementFallbackProps<CustomElements, CustomLeaves>) {\n\tconst attributes = getElementDataAttributes(element, options.attributeNamePrefix)\n\n\tswitch (element.type) {\n\t\tcase 'anchor':\n\t\t\treturn (\n\t\t\t\t<a {...attributes} href={element.href}>\n\t\t\t\t\t{children}\n\t\t\t\t</a>\n\t\t\t)\n\t\tcase 'heading':\n\t\t\treturn createElement(`h${element.level}`, attributes, children) // TODO numbered\n\t\tcase 'horizontalRule':\n\t\t\treturn <hr {...attributes} />\n\t\tcase 'listItem':\n\t\t\treturn <li {...attributes}>{children}</li>\n\t\tcase 'orderedList':\n\t\t\treturn <ol {...attributes}>{children}</ol>\n\t\tcase 'paragraph':\n\t\t\treturn <p {...attributes}>{children}</p>\n\t\tcase 'reference': {\n\t\t\treturn <ReferenceElementFallback element={element} children={children} />\n\t\t}\n\t\tcase 'scrollTarget':\n\t\t\treturn (\n\t\t\t\t<span {...attributes} id={element.identifier}>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t)\n\t\tcase 'table': {\n\t\t\tconst firstRow = element.children[0] as RichTextTableRowElement<CustomElements, CustomLeaves> | undefined\n\t\t\tif (!firstRow || firstRow.headerScope !== 'table') {\n\t\t\t\treturn (\n\t\t\t\t\t<table {...attributes}>\n\t\t\t\t\t\t<tbody>{children}</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn (\n\t\t\t\t<table {...attributes}>\n\t\t\t\t\t<thead>{renderChildren<CustomElements, CustomLeaves>([firstRow], options)}</thead>\n\t\t\t\t\t<tbody>{renderChildren<CustomElements, CustomLeaves>(element.children.slice(1) as any, options)}</tbody>\n\t\t\t\t</table>\n\t\t\t)\n\t\t}\n\t\tcase 'tableRow':\n\t\t\treturn <tr {...attributes}>{children}</tr>\n\t\tcase 'tableCell': {\n\t\t\tif (element.headerScope) {\n\t\t\t\treturn (\n\t\t\t\t\t<th {...attributes} scope={element.headerScope}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</th>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn <td {...attributes}>{children}</td>\n\t\t}\n\t\tcase 'unorderedList':\n\t\t\treturn <ul {...attributes}>{children}</ul>\n\t\tdefault: {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: unknown element of type '${(element as { type: string }).type}'.`,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\treturn children // At least render the text contents\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction ReferenceElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children }: { element: RichTextReferenceElement<CustomElements, CustomLeaves>; children: ReactElement }) {\n\tconst metadata = useRichTextRenderMetadata<CustomElements, CustomLeaves>()\n\tconst elementMetadata = resolveRichTextElementMetadata<CustomElements, CustomLeaves>(element, metadata)\n\n\tif (\n\t\telementMetadata.referenceRenderer === undefined ||\n\t\telementMetadata.referenceType === undefined ||\n\t\telementMetadata.reference === undefined\n\t) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`RichTextRenderer: cannot render reference of type '${elementMetadata.referenceType}'.`,\n\t\t\t)\n\t\t} else {\n\t\t\treturn children // At least render the text contents\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{elementMetadata.referenceRenderer?.({\n\t\t\t\treferenceType: elementMetadata.referenceType,\n\t\t\t\treferenceRenderer: elementMetadata.referenceRenderer,\n\t\t\t\treference: elementMetadata.reference,\n\t\t\t\tformatVersion: elementMetadata.formatVersion,\n\t\t\t\telement,\n\t\t\t\tchildren,\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,2BAA2B,CAIhC,SACA,sBAA8B,iBAG1B;AACJ,QAAM,EAAE,UAAU,aAAa,GAAG,sBAAsB;AAExD,SAAO,OAAO;AAAA,IACb,OAAO,QAAQ,iBAAiB,EAC9B,OAAO,CAAC,CAAG,EAAA,KAAK,MAAM;AACtB,YAAM,IAAI,OAAO;AACjB,aAAO,MAAM,YAAY,MAAM,YAAY,MAAM;AAAA,IACjD,CAAA,EACA,IAAI,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,QAAQ,sBAAsB,UAAU,YAAY,KAAK,KAAK,CAAC;AAAA,EAAA;AAEhG;AAEO,SAAS,sBAGd,EAAE,SAAS,UAAU,WAAqE;AAC3F,QAAM,aAAa,yBAAyB,SAAS,QAAQ,mBAAmB;AAEhF,UAAQ,QAAQ,MAAM;AAAA,IACrB,KAAK;AACJ,iCACE,KAAG,EAAA,GAAG,YAAY,MAAM,QAAQ,MAC/B,SACF,CAAA;AAAA,IAEF,KAAK;AACJ,aAAO,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AACJ,aAAQ,oBAAA,MAAA,EAAI,GAAG,YAAa,SAAS,CAAA;AAAA,IACtC,SAAS;AAKD;AACC,eAAA;AAAA,MACR;AAAA,IACD;AAAA,EACD;AACD;AAEA,SAAS,yBAGP,EAAE,SAAS,YAAyG;AACrH,QAAM,WAAW;AACX,QAAA,kBAAkB,+BAA6D,SAAS,QAAQ;AAGrG,MAAA,gBAAgB,sBAAsB,UACtC,gBAAgB,kBAAkB,UAClC,gBAAgB,cAAc,QAC7B;AAKM;AACC,aAAA;AAAA,IACR;AAAA,EACD;AAGC,SAAA,oBAAA,UAAA,EACE,0BAAgB,oBAAoB;AAAA,IACpC,eAAe,gBAAgB;AAAA,IAC/B,mBAAmB,gBAAgB;AAAA,IACnC,WAAW,gBAAgB;AAAA,IAC3B,eAAe,gBAAgB;AAAA,IAC/B;AAAA,IACA;AAAA,EACA,CAAA,EACF,CAAA;AAEF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextRenderer.js","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { defaultDeserialize } from './defaultDeserialize'\nimport type { RenderElement } from './ElementRenderer'\nimport type { RenderLeaf } from './LeafRenderer'\nimport type { NormalizedRichTextBlock } from './NormalizedRichTextBlock'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport { renderChildren } from './renderChildren'\nimport type { RichTextBlock } from './RichTextBlock'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { RichTextRenderMetadataContext } from './RichTextRenderMetadataContext'\nimport type { RootEditorNode } from './RootEditorNode'\n\nexport interface RichTextRendererFieldProps {\n\tsource: string | null\n}\n\nexport interface RichTextRendererBlockProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\tblocks: RichTextBlock[]\n\treferenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>\n\tsourceField?: string\n\treferencesField?: string\n\treferenceDiscriminationField?: string\n}\n\nexport type RichTextRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> = {\n\tdeserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n\trenderBlock?: ComponentType<{ block: unknown, children?: ReactNode }>\n} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>)\n\nexport const RichTextRenderer = memo(function RichTextRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({\n\tdeserialize = defaultDeserialize,\n\trenderElement,\n\trenderLeaf,\n\trenderBlock = ({ children }) => <>{children}</>,\n\tattributeNamePrefix,\n\t...sourceProps\n}: RichTextRendererProps<CustomElements, CustomLeaves>) {\n\tconst normalizedSource = useMemo<NormalizedRichTextBlock<CustomElements, CustomLeaves>[]>(() => {\n\t\tif ('source' in sourceProps && !('blocks' in sourceProps)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontent: sourceProps.source\n\t\t\t\t\t\t? deserialize(sourceProps.source)\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tformatVersion: 0,\n\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t },\n\t\t\t\t\tid: undefined,\n\t\t\t\t\treferencesField: undefined,\n\t\t\t\t\treferenceDiscriminationField: undefined,\n\t\t\t\t\treferenceRenderers: {},\n\t\t\t\t\treferences: undefined,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t\tif (!('source' in sourceProps)) {\n\t\t\tconst sourceField = sourceProps.sourceField ?? 'source'\n\t\t\tconst referencesField = sourceProps.referencesField ?? 'references'\n\t\t\tconst referenceDiscriminationField = sourceProps.referenceDiscriminationField ?? 'type'\n\n\t\t\treturn sourceProps.blocks.map(block => {\n\t\t\t\tif (!(sourceField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`Found a block without a '${sourceField}' field. ` +\n\t\t\t\t\t\t\t(sourceProps.sourceField === undefined\n\t\t\t\t\t\t\t\t? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`\n\t\t\t\t\t\t\t\t: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +\n\t\t\t\t\t\t\t\t `or the data supplied is invalid.`),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst source = block[sourceField]\n\t\t\t\tif (typeof source !== 'string') {\n\t\t\t\t\tthrow new RichTextRendererError(`Found a block whose source is not a string.`)\n\t\t\t\t}\n\n\t\t\t\tif (sourceProps.referencesField !== undefined && !(referencesField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`The 'referencesField' prop is set to '${referencesField}' but a block without such field ` +\n\t\t\t\t\t\t\t`has been encountered. Unless this is just a typo, ` +\n\t\t\t\t\t\t\t`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst references = block[referencesField]\n\n\t\t\t\tlet normalizedReferences: Map<string, RichTextReference> | undefined = undefined\n\t\t\t\tif (references) {\n\t\t\t\t\tif (typeof Object(references)[Symbol.iterator] !== 'function') {\n\t\t\t\t\t\tthrow new RichTextRendererError(`The set of references must be an iterable!`)\n\t\t\t\t\t}\n\n\t\t\t\t\tnormalizedReferences = new Map()\n\t\t\t\t\tfor (const reference of references as Iterable<RichTextReference>) {\n\t\t\t\t\t\tif (!('id' in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(`Found a reference without an id field.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!(referenceDiscriminationField in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t\t\t`Found a reference without a '${referenceDiscriminationField}' field. ` +\n\t\t\t\t\t\t\t\t\t(sourceProps.referenceDiscriminationField === undefined\n\t\t\t\t\t\t\t\t\t\t? `The 'referenceDiscriminationField' prop has not been supplied, ` +\n\t\t\t\t\t\t\t\t\t\t `and so '${referenceDiscriminationField}' was used as a default.`\n\t\t\t\t\t\t\t\t\t\t: `That is what the 'referenceDiscriminationField' prop has been set to, ` +\n\t\t\t\t\t\t\t\t\t\t `and so either this is a typo, or the data supplied is invalid.`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnormalizedReferences.set(reference.id, reference)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tid: typeof block.id === 'string' ? block.id : undefined,\n\t\t\t\t\tcontent: deserialize(source),\n\t\t\t\t\treferenceDiscriminationField,\n\t\t\t\t\treferenceRenderers: sourceProps.referenceRenderers ?? {},\n\t\t\t\t\treferencesField,\n\t\t\t\t\treferences: normalizedReferences,\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t\tthrow new RichTextRendererError(`RichTextRenderer: invalid data supplied.`)\n\t}, [deserialize, sourceProps])\n\n\treturn (\n\t\t<>\n\t\t\t{normalizedSource.map((block, i) => (\n\t\t\t\t<RichTextRenderMetadataContext.Provider\n\t\t\t\t\tkey={block.id ?? i}\n\t\t\t\t\tvalue={{\n\t\t\t\t\t\tformatVersion: block.content.formatVersion,\n\t\t\t\t\t\treferenceRenderers: block.referenceRenderers,\n\t\t\t\t\t\treferencesField: block.referencesField,\n\t\t\t\t\t\treferenceDiscriminationField: block.referenceDiscriminationField,\n\t\t\t\t\t\treferences: block.references,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{createElement(\n\t\t\t\t\t\trenderBlock, {\n\t\t\t\t\t\t\tblock,\n\t\t\t\t\t\t}, renderChildren(block.content.children, {\n\t\t\t\t\t\t\trenderLeaf,\n\t\t\t\t\t\t\trenderElement,\n\t\t\t\t\t\t\tattributeNamePrefix,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)}\n\t\t\t\t</RichTextRenderMetadataContext.Provider>\n\t\t\t))}\n\t\t</>\n\t)\n}) as <CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never>(\n\tprops: RichTextRendererProps<CustomElements, CustomLeaves>,\n) => ReactElement\n"],"names":["RichTextRenderer"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"RichTextRenderer.js","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { defaultDeserialize } from './defaultDeserialize'\nimport type { RenderElement } from './ElementRenderer'\nimport type { RenderLeaf } from './LeafRenderer'\nimport type { NormalizedRichTextBlock } from './NormalizedRichTextBlock'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport { renderChildren } from './renderChildren'\nimport type { RichTextBlock } from './RichTextBlock'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { RichTextRenderMetadataContext } from './RichTextRenderMetadataContext'\nimport type { RootEditorNode } from './RootEditorNode'\n\nexport interface RichTextRendererFieldProps {\n\tsource: string | null\n}\n\nexport interface RichTextRendererBlockProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\tblocks: RichTextBlock[]\n\treferenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>\n\tsourceField?: string\n\treferencesField?: string\n\treferenceDiscriminationField?: string\n}\n\nexport type RichTextRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> = {\n\tdeserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n\trenderBlock?: ComponentType<{ block: unknown, children?: ReactNode }>\n} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>)\n\n/**\n * @group Content rendering\n */\nexport const RichTextRenderer = memo(function RichTextRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({\n\tdeserialize = defaultDeserialize,\n\trenderElement,\n\trenderLeaf,\n\trenderBlock = ({ children }) => <>{children}</>,\n\tattributeNamePrefix,\n\t...sourceProps\n}: RichTextRendererProps<CustomElements, CustomLeaves>) {\n\tconst normalizedSource = useMemo<NormalizedRichTextBlock<CustomElements, CustomLeaves>[]>(() => {\n\t\tif ('source' in sourceProps && !('blocks' in sourceProps)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontent: sourceProps.source\n\t\t\t\t\t\t? deserialize(sourceProps.source)\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tformatVersion: 0,\n\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t },\n\t\t\t\t\tid: undefined,\n\t\t\t\t\treferencesField: undefined,\n\t\t\t\t\treferenceDiscriminationField: undefined,\n\t\t\t\t\treferenceRenderers: {},\n\t\t\t\t\treferences: undefined,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t\tif (!('source' in sourceProps)) {\n\t\t\tconst sourceField = sourceProps.sourceField ?? 'source'\n\t\t\tconst referencesField = sourceProps.referencesField ?? 'references'\n\t\t\tconst referenceDiscriminationField = sourceProps.referenceDiscriminationField ?? 'type'\n\n\t\t\treturn sourceProps.blocks.map(block => {\n\t\t\t\tif (!(sourceField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`Found a block without a '${sourceField}' field. ` +\n\t\t\t\t\t\t\t(sourceProps.sourceField === undefined\n\t\t\t\t\t\t\t\t? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`\n\t\t\t\t\t\t\t\t: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +\n\t\t\t\t\t\t\t\t `or the data supplied is invalid.`),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst source = block[sourceField]\n\t\t\t\tif (typeof source !== 'string') {\n\t\t\t\t\tthrow new RichTextRendererError(`Found a block whose source is not a string.`)\n\t\t\t\t}\n\n\t\t\t\tif (sourceProps.referencesField !== undefined && !(referencesField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`The 'referencesField' prop is set to '${referencesField}' but a block without such field ` +\n\t\t\t\t\t\t\t`has been encountered. Unless this is just a typo, ` +\n\t\t\t\t\t\t\t`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst references = block[referencesField]\n\n\t\t\t\tlet normalizedReferences: Map<string, RichTextReference> | undefined = undefined\n\t\t\t\tif (references) {\n\t\t\t\t\tif (typeof Object(references)[Symbol.iterator] !== 'function') {\n\t\t\t\t\t\tthrow new RichTextRendererError(`The set of references must be an iterable!`)\n\t\t\t\t\t}\n\n\t\t\t\t\tnormalizedReferences = new Map()\n\t\t\t\t\tfor (const reference of references as Iterable<RichTextReference>) {\n\t\t\t\t\t\tif (!('id' in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(`Found a reference without an id field.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!(referenceDiscriminationField in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t\t\t`Found a reference without a '${referenceDiscriminationField}' field. ` +\n\t\t\t\t\t\t\t\t\t(sourceProps.referenceDiscriminationField === undefined\n\t\t\t\t\t\t\t\t\t\t? `The 'referenceDiscriminationField' prop has not been supplied, ` +\n\t\t\t\t\t\t\t\t\t\t `and so '${referenceDiscriminationField}' was used as a default.`\n\t\t\t\t\t\t\t\t\t\t: `That is what the 'referenceDiscriminationField' prop has been set to, ` +\n\t\t\t\t\t\t\t\t\t\t `and so either this is a typo, or the data supplied is invalid.`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnormalizedReferences.set(reference.id, reference)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tid: typeof block.id === 'string' ? block.id : undefined,\n\t\t\t\t\tcontent: deserialize(source),\n\t\t\t\t\treferenceDiscriminationField,\n\t\t\t\t\treferenceRenderers: sourceProps.referenceRenderers ?? {},\n\t\t\t\t\treferencesField,\n\t\t\t\t\treferences: normalizedReferences,\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t\tthrow new RichTextRendererError(`RichTextRenderer: invalid data supplied.`)\n\t}, [deserialize, sourceProps])\n\n\treturn (\n\t\t<>\n\t\t\t{normalizedSource.map((block, i) => (\n\t\t\t\t<RichTextRenderMetadataContext.Provider\n\t\t\t\t\tkey={block.id ?? i}\n\t\t\t\t\tvalue={{\n\t\t\t\t\t\tformatVersion: block.content.formatVersion,\n\t\t\t\t\t\treferenceRenderers: block.referenceRenderers,\n\t\t\t\t\t\treferencesField: block.referencesField,\n\t\t\t\t\t\treferenceDiscriminationField: block.referenceDiscriminationField,\n\t\t\t\t\t\treferences: block.references,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{createElement(\n\t\t\t\t\t\trenderBlock, {\n\t\t\t\t\t\t\tblock,\n\t\t\t\t\t\t}, renderChildren(block.content.children, {\n\t\t\t\t\t\t\trenderLeaf,\n\t\t\t\t\t\t\trenderElement,\n\t\t\t\t\t\t\tattributeNamePrefix,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)}\n\t\t\t\t</RichTextRenderMetadataContext.Provider>\n\t\t\t))}\n\t\t</>\n\t)\n}) as <CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never>(\n\tprops: RichTextRendererProps<CustomElements, CustomLeaves>,\n) => ReactElement\n"],"names":["Rich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src/components/RichTextRenderer/resolveRichTextElementMetadata.ts"],"sourcesContent":["import type { BuiltinElements } from './BuiltinElements'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextElementMetadata } from './RichTextElementMetadata'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport type { RichTextRenderMetadata } from './RichTextRenderMetadata'\n\nexport const resolveRichTextElementMetadata = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n\tReference extends RichTextReference = RichTextReference,\n>(\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>,\n\tmetadata: RichTextRenderMetadata<CustomElements, CustomLeaves, Reference>,\n): RichTextElementMetadata<CustomElements, CustomLeaves, Reference> => {\n\tlet reference: Reference | undefined = undefined\n\n\tif ('referenceId' in element && typeof element['referenceId'] === 'string') {\n\t\tconst resolved = metadata.references?.get(element['referenceId'])\n\n\t\tif (resolved === undefined) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`Cannot find reference id '${element['referenceId']}'` +\n\t\t\t\t\t(metadata.references === undefined\n\t\t\t\t\t\t? ` because its containing block's lacks the '${metadata.referencesField}' field. `\n\t\t\t\t\t\t: `.`),\n\t\t\t)\n\t\t}\n\t\treference = resolved as Reference\n\t}\n\n\tlet referenceRenderer: ReferenceRenderer<Reference, CustomElements, CustomLeaves> | undefined = undefined\n\tlet referenceType: string | undefined = undefined\n\n\tif (reference && metadata.referenceDiscriminationField) {\n\t\treferenceType = (reference as Reference & Record<typeof metadata.referenceDiscriminationField, string>)[\n\t\t\tmetadata.referenceDiscriminationField\n\t\t]\n\t\treferenceRenderer = metadata.referenceRenderers[referenceType]\n\t}\n\n\treturn {\n\t\tformatVersion: metadata.formatVersion,\n\t\treference,\n\t\treferenceType,\n\t\treferenceRenderer,\n\t}\n}\n"],"names":[],"mappings":";AASa,MAAA,iCAAiC,CAK7C,SACA,aACsE;AACtE,MAAI,YAAmC;AAEvC,MAAI,iBAAiB,WAAW,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"resolveRichTextElementMetadata.js","sources":["../../../../src/components/RichTextRenderer/resolveRichTextElementMetadata.ts"],"sourcesContent":["import type { BuiltinElements } from './BuiltinElements'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextElementMetadata } from './RichTextElementMetadata'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport type { RichTextRenderMetadata } from './RichTextRenderMetadata'\n\nexport const resolveRichTextElementMetadata = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n\tReference extends RichTextReference = RichTextReference,\n>(\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>,\n\tmetadata: RichTextRenderMetadata<CustomElements, CustomLeaves, Reference>,\n): RichTextElementMetadata<CustomElements, CustomLeaves, Reference> => {\n\tlet reference: Reference | undefined = undefined\n\n\tif ('referenceId' in element && typeof element['referenceId'] === 'string') {\n\t\tconst resolved = metadata.references?.get(element['referenceId'])\n\n\t\tif (resolved === undefined) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`Cannot find reference id '${element['referenceId']}'` +\n\t\t\t\t\t(metadata.references === undefined\n\t\t\t\t\t\t? ` because its containing block's lacks the '${metadata.referencesField}' field. `\n\t\t\t\t\t\t: `.`),\n\t\t\t)\n\t\t}\n\t\treference = resolved as Reference\n\t}\n\n\tlet referenceRenderer: ReferenceRenderer<Reference, CustomElements, CustomLeaves> | undefined = undefined\n\tlet referenceType: string | undefined = undefined\n\n\tif (reference && metadata.referenceDiscriminationField) {\n\t\treferenceType = (reference as Reference & Record<typeof metadata.referenceDiscriminationField, string>)[\n\t\t\tmetadata.referenceDiscriminationField\n\t\t]\n\t\treferenceRenderer = metadata.referenceRenderers[referenceType]\n\t}\n\n\treturn {\n\t\tformatVersion: metadata.formatVersion,\n\t\treference,\n\t\treferenceType,\n\t\treferenceRenderer,\n\t}\n}\n"],"names":[],"mappings":";AASa,MAAA,iCAAiC,CAK7C,SACA,aACsE;AACtE,MAAI,YAAmC;AAEvC,MAAI,iBAAiB,WAAW,OAAO,QAAQ,aAAa,MAAM,UAAU;AAC3E,UAAM,WAAW,SAAS,YAAY,IAAI,QAAQ,aAAa,CAAC;AAEhE,QAAI,aAAa,QAAW;AAC3B,YAAM,IAAI;AAAA,QACT,6BAA6B,QAAQ,aAAa,QAChD,SAAS,eAAe,SACtB,8CAA8C,SAAS,6BACvD;AAAA,MAAA;AAAA,IAEN;AACY,gBAAA;AAAA,EACb;AAEA,MAAI,oBAA4F;AAChG,MAAI,gBAAoC;AAEpC,MAAA,aAAa,SAAS,8BAA8B;AACtC,oBAAA,UAChB,SAAS,4BACV;AACoB,wBAAA,SAAS,mBAAmB,aAAa;AAAA,EAC9D;AAEO,SAAA;AAAA,IACN,eAAe,SAAS;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
package/dist/production/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { apiRequestReducer } from "./apiRequest/apiRequestReducer.js";
|
|
|
6
6
|
import { useApiRequest } from "./apiRequest/useApiRequest.js";
|
|
7
7
|
import { SessionTokenContext } from "./auth/SessionTokenContext.js";
|
|
8
8
|
import { SetSessionTokenContext } from "./auth/SetSessionTokenContext.js";
|
|
9
|
-
import { useSessionToken } from "./auth/useSessionToken.js";
|
|
9
|
+
import { useSessionToken, useSessionTokenWithMeta } from "./auth/useSessionToken.js";
|
|
10
10
|
import { useSetSessionToken } from "./auth/useSetSessionToken.js";
|
|
11
11
|
import { RichTextRenderer } from "./components/RichTextRenderer/RichTextRenderer.js";
|
|
12
12
|
import { RichTextRendererError } from "./components/RichTextRenderer/RichTextRendererError.js";
|
|
@@ -50,6 +50,7 @@ export {
|
|
|
50
50
|
useLoginToken,
|
|
51
51
|
useProjectSlug,
|
|
52
52
|
useSessionToken,
|
|
53
|
+
useSessionTokenWithMeta,
|
|
53
54
|
useSetSessionToken,
|
|
54
55
|
useStageSlug,
|
|
55
56
|
useSystemApiRequest,
|
|
@@ -32,6 +32,7 @@ const fileUploadReducer = (previousState, action) => {
|
|
|
32
32
|
abortController: fileState.abortController,
|
|
33
33
|
file: fileState.file,
|
|
34
34
|
metadata: metadata.metadata,
|
|
35
|
+
// If the user didn't supply the metadata, then that's on them.
|
|
35
36
|
previewUrl: fileState.previewUrl,
|
|
36
37
|
progress: void 0,
|
|
37
38
|
uploader: metadata.uploader
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<Result, Metadata> => ({\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tstate: new Map(),\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tlet newState: undefined | FileUploadMultiTemporalState<Result, Metadata>['state'] = undefined\n\n\tswitch (action.type) {\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\t// Deliberately mutating\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\t;(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'purge': {\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tURL.revokeObjectURL(fileState.previewUrl)\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).delete(fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst roundedProgress = Math.floor(progress) // throttling\n\t\t\t\tif (roundedProgress === previousFileState.progress) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress: roundedProgress,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tdefault:\n\t\t\tassertNever(action)\n\t}\n\tif (newState === undefined) {\n\t\treturn previousState\n\t}\n\treturn { ...previousState, state: newState }\n}\n"],"names":[],"mappings":";;;AAOO,MAAM,4BAA4B,OAA+F;AAAA,EACvI,kCAAkB,QAAsB;AAAA,EACxC,2BAAW,IAAI;AAChB;AAEa,MAAA,oBAAoB,CAChC,eACA,WACoD;AACpD,MAAI,WAAgF;AAEpF,UAAQ,OAAO,MAAM;AAAA,IACpB,KAAK,cAAc;AAClB,iBAAW,CAAC,QAAQ,QAAQ,KAAK,OAAO,OAAO;AAE9C,SAAC,wBAAa,IAAI,IA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a,IAAI,IAAI,cAAc,KAAK,IAAG,OAAO,MAAM;AAAA,MAC1D;AACA;AAAA,IACD;AAAA,IACA,KAAK,wBAAwB;AAC5B,iBAAW,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,UAAU;AACjD,cAAA,SAAS,SAAS,eAAe,QAAQ;AAC/C,cAAM,qBAAqB,YAAY,cAAc,OAAO,IAAI,MAAM;AACtE,YAAI,aAAa,UAAa,sBAAsB,UAAa,kBAAkB,eAAe,aAAa;AAC9G;AAAA,QACD;AACM,cAAA,kBAAkB,KAAK,MAAM,QAAQ;AACvC,YAAA,oBAAoB,kBAAkB,UAAU;AACnD;AAAA,QACD;AACA,SAAC,wBAAa,IAAI,IAAI,cAAc,KAAK,IAAG,IAAI,QAAQ;AAAA,UACvD,YAAY;AAAA,UACZ,MAAM,kBAAkB;AAAA,UACxB,UAAU,kBAAkB;AAAA,UAC5B,iBAAiB,kBAAkB;AAAA,UACnC,YAAY,kBAAkB;AAAA,UAC9B,UAAU,kBAAkB;AAAA,UAC5B,UAAU;AAAA,QAAA,CACV;AAAA,MACF;AACA;AAAA,IACD;AAAA,IACA;AACC,kBAAkB;AAAA,EACpB;AACA,MAAI,aAAa,QAAW;AACpB,WAAA;AAAA,EACR;AACA,SAAO,EAAE,GAAG,eAAe,OAAO,SAAS;AAC5C;"}
|
|
1
|
+
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<Result, Metadata> => ({\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tstate: new Map(),\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tlet newState: undefined | FileUploadMultiTemporalState<Result, Metadata>['state'] = undefined\n\n\tswitch (action.type) {\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\t// Deliberately mutating\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\t;(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'purge': {\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = (newState ?? previousState.state).get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tURL.revokeObjectURL(fileState.previewUrl)\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).delete(fileId)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = (newState ?? previousState.state).get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst roundedProgress = Math.floor(progress) // throttling\n\t\t\t\tif (roundedProgress === previousFileState.progress) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t(newState ??= new Map(previousState.state)).set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress: roundedProgress,\n\t\t\t\t})\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tdefault:\n\t\t\tassertNever(action)\n\t}\n\tif (newState === undefined) {\n\t\treturn previousState\n\t}\n\treturn { ...previousState, state: newState }\n}\n"],"names":[],"mappings":";;;AAOO,MAAM,4BAA4B,OAA+F;AAAA,EACvI,kCAAkB,QAAsB;AAAA,EACxC,2BAAW,IAAI;AAChB;AAEa,MAAA,oBAAoB,CAChC,eACA,WACoD;AACpD,MAAI,WAAgF;AAEpF,UAAQ,OAAO,MAAM;AAAA,IACpB,KAAK,cAAc;AAClB,iBAAW,CAAC,QAAQ,QAAQ,KAAK,OAAO,OAAO;AAE9C,SAAC,wBAAa,IAAI,IAAI,cAAc,KAAK,IAAG,IAAI,QAAQ;AAAA,UACvD,YAAY;AAAA,UACZ,iBAAiB,SAAS;AAAA,UAC1B,YAAY,SAAS;AAAA,UACrB,MAAM,SAAS;AAAA,QAAA,CACf;AAED,sBAAc,aAAa,IAAI,SAAS,MAAM,MAAM;AAAA,MACrD;AACA;AAAA,IACD;AAAA,IACA,KAAK,kBAAkB;AACtB,iBAAW,CAAC,UAAU,QAAQ,KAAK,OAAO,OAAO;AAC1C,cAAA,SAAS,SAAS,eAAe,QAAQ;AAC/C,cAAM,aAAa,YAAY,cAAc,OAAO,IAAI,MAAM;AAE9D,YAAI,cAAc,UAAa,UAAU,eAAe,gBAAgB;AACvE;AAAA,QACD;AAEA,SAAC,wBAAa,IAAI,IAAI,cAAc,KAAK,IAAG,IAAI,QAAQ;AAAA,UACvD,YAAY;AAAA,UACZ,iBAAiB,UAAU;AAAA,UAC3B,MAAM,UAAU;AAAA,UAChB,UAAU,SAAS;AAAA;AAAA,UACnB,YAAY,UAAU;AAAA,UACtB,UAAU;AAAA,UACV,UAAU,SAAS;AAAA,QAAA,CACnB;AAAA,MACF;AACA;AAAA,IACD;AAAA,IACA,KAAK,sBAAsB;AAC1B,iBAAW,CAAC,UAAU,MAAM,KAAK,OAAO,QAAQ;AACzC,cAAA,SAAS,SAAS,eAAe,QAAQ;AAC/C,cAAM,qBAAqB,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