-
Notifications
You must be signed in to change notification settings - Fork 0
feat: added support for granular template editor #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5f18b67
added support for granular tempalte editor
ILLIA-KHOMENKO c761006
lint
ILLIA-KHOMENKO 52356bd
extracted shared logic into helpers and utils
ILLIA-KHOMENKO 4dc4cf8
lint
ILLIA-KHOMENKO cb7b48f
passing tempalte editor features with tempalte editor
ILLIA-KHOMENKO c8c3b53
embedType QP and pr comments
ILLIA-KHOMENKO b16ec2f
changed embedType to navigation query param
ILLIA-KHOMENKO 0aba2a0
type cleanup
ILLIA-KHOMENKO ce7b53c
addressed pr comments
ILLIA-KHOMENKO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import type {BadgeSdk} from "../sdk.ts"; | ||
| import type {AppearanceConfig, FontSource} from "../helpers/appearance.ts"; | ||
| import {createEmbedIframe} from "../helpers/iframe.ts"; | ||
| import {validatePermissions} from "../helpers/permissions.ts"; | ||
| import {parseTokenPayload} from "../helpers/token.ts"; | ||
| import {type SdkPermission} from "../helpers/permissions.ts"; | ||
| import { | ||
| type TemplateEditorFeature, | ||
| type TemplateEditorFeatures, | ||
| } from "../helpers/embedFeatures.ts"; | ||
|
|
||
| export interface EmbedTemplateEditorPageOptions { | ||
| /** | ||
| * id of the template to show | ||
| */ | ||
| templateId: string; | ||
| features?: TemplateEditorFeatures | undefined; | ||
| fonts?: FontSource[] | undefined; | ||
| appearance?: AppearanceConfig | undefined; | ||
| } | ||
|
|
||
| /** | ||
| * requires template:write | ||
| */ | ||
| export function embedTemplateEditorPage( | ||
| sdk: BadgeSdk, | ||
| element: HTMLElement, | ||
| {templateId, features, fonts, appearance}: EmbedTemplateEditorPageOptions, | ||
ILLIA-KHOMENKO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ): void { | ||
| const {workspaceHandle, permissions} = parseTokenPayload(sdk.token); | ||
|
|
||
| validatePermissions(permissions, REQUIRED_PERMISSIONS); | ||
|
|
||
| const iframe = createEmbedIframe({ | ||
| token: sdk.token, | ||
| path: sdk.path, | ||
| pathHash: `/${workspaceHandle}/templates/${templateId}/edit`, | ||
| navigation: "bottom", | ||
| config: { | ||
| features: { | ||
| templateEditor: | ||
| Object.keys(features ?? {}).length > 0 | ||
| ? {...TEMPLATE_EDITOR_FEATURES_NONE, ...features} | ||
| : TEMPLATE_EDITOR_FEATURES_DEFAULT, | ||
| }, | ||
| fonts, | ||
| appearance, | ||
| }, | ||
| }); | ||
|
|
||
| element.replaceChildren(iframe); | ||
| } | ||
|
|
||
| const REQUIRED_PERMISSIONS: SdkPermission[][] = [ | ||
| ["workspace:read", "workspace:write"], | ||
| ["user:read", "user:write"], | ||
| ["template:write", "template:read"], | ||
| ]; | ||
|
|
||
| export const TEMPLATE_EDITOR_FEATURES_DEFAULT = { | ||
| logo: true, | ||
| icon: true, | ||
| heading: true, | ||
| colors: true, | ||
| coverImage: true, | ||
| headerField: true, | ||
| secondaryFields: true, | ||
| barcodeType: false, | ||
| barcodeData: false, | ||
| barcodeText: false, | ||
| description: false, | ||
| backFields: true, | ||
| locationMessages: true, | ||
| appLinks: true, | ||
| expiry: false, | ||
| } satisfies Required<TemplateEditorFeatures>; | ||
|
|
||
| export const TEMPLATE_EDITOR_FEATURES_NONE = Object.fromEntries( | ||
| Object.keys(TEMPLATE_EDITOR_FEATURES_DEFAULT).map((key) => [key, false]), | ||
| ) as Record<TemplateEditorFeature, false>; | ||
|
|
||
| export const TEMPLATE_EDITOR_FEATURES_ALL = Object.fromEntries( | ||
| Object.keys(TEMPLATE_EDITOR_FEATURES_DEFAULT).map((key) => [key, true]), | ||
| ) as Record<TemplateEditorFeature, true>; | ||
ILLIA-KHOMENKO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const TEMPLATE_EDITOR_FEATURES_ENABLE_BARCODE = { | ||
| barcodeType: true, | ||
| barcodeData: true, | ||
| barcodeText: true, | ||
| } satisfies Pick< | ||
| Record<TemplateEditorFeature, true>, | ||
| "barcodeType" | "barcodeData" | "barcodeText" | ||
| >; | ||
ILLIA-KHOMENKO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.