feat(web): extract ui-services package
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import { ComponentAction } from '@standardnotes/features'
|
||||
import { MessageData } from './MessageData'
|
||||
|
||||
export type ActionObserver = (action: ComponentAction, messageData: MessageData) => void
|
||||
@@ -0,0 +1,3 @@
|
||||
import { ComponentViewerEvent } from './ComponentViewerEvent'
|
||||
|
||||
export type ComponentEventObserver = (event: ComponentViewerEvent) => void
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ComponentAction } from '@standardnotes/features'
|
||||
import { MessageData } from './MessageData'
|
||||
|
||||
export type ComponentMessage = {
|
||||
action: ComponentAction
|
||||
sessionKey?: string
|
||||
componentData?: Record<string, unknown>
|
||||
data: MessageData
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export enum ComponentViewerEvent {
|
||||
FeatureStatusUpdated = 'FeatureStatusUpdated',
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { DecryptedTransferPayload } from '../TransferPayload/Interfaces/DecryptedTransferPayload'
|
||||
|
||||
export type IncomingComponentItemPayload = DecryptedTransferPayload & {
|
||||
clientData: Record<string, unknown>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum KeyboardModifier {
|
||||
Shift = 'Shift',
|
||||
Ctrl = 'Control',
|
||||
Meta = 'Meta',
|
||||
}
|
||||
31
packages/models/src/Domain/Abstract/Component/MessageData.ts
Normal file
31
packages/models/src/Domain/Abstract/Component/MessageData.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ContentType, Uuid } from '@standardnotes/common'
|
||||
import { ComponentPermission } from '@standardnotes/features'
|
||||
|
||||
import { IncomingComponentItemPayload } from './IncomingComponentItemPayload'
|
||||
import { KeyboardModifier } from './KeyboardModifier'
|
||||
|
||||
export type MessageData = Partial<{
|
||||
/** Related to the stream-item-context action */
|
||||
item?: IncomingComponentItemPayload
|
||||
/** Related to the stream-items action */
|
||||
content_types?: ContentType[]
|
||||
items?: IncomingComponentItemPayload[]
|
||||
/** Related to the request-permission action */
|
||||
permissions?: ComponentPermission[]
|
||||
/** Related to the component-registered action */
|
||||
componentData?: Record<string, unknown>
|
||||
uuid?: Uuid
|
||||
environment?: string
|
||||
platform?: string
|
||||
activeThemeUrls?: string[]
|
||||
/** Related to set-size action */
|
||||
width?: string | number
|
||||
height?: string | number
|
||||
type?: string
|
||||
/** Related to themes action */
|
||||
themes?: string[]
|
||||
/** Related to clear-selection action */
|
||||
content_type?: ContentType
|
||||
/** Related to key-pressed action */
|
||||
keyboardModifier?: KeyboardModifier
|
||||
}>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ComponentPermission } from '@standardnotes/features'
|
||||
import { SNComponent } from '../../Syncable/Component'
|
||||
|
||||
export type PermissionDialog = {
|
||||
component: SNComponent
|
||||
permissions: ComponentPermission[]
|
||||
permissionsString: string
|
||||
actionBlock: (approved: boolean) => void
|
||||
callback: (approved: boolean) => void
|
||||
}
|
||||
@@ -1,60 +1,10 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
import { ContextPayload } from './ContextPayload'
|
||||
import { ItemContent } from '../Content/ItemContent'
|
||||
import { DecryptedTransferPayload, EncryptedTransferPayload } from '../TransferPayload'
|
||||
import { AnyKeyParamsContent, ProtocolVersion } from '@standardnotes/common'
|
||||
import { BackupFileDecryptedContextualPayload } from './BackupFileDecryptedContextualPayload'
|
||||
import { BackupFileEncryptedContextualPayload } from './BackupFileEncryptedContextualPayload'
|
||||
|
||||
export interface BackupFileEncryptedContextualPayload extends ContextPayload {
|
||||
auth_hash?: string
|
||||
content: string
|
||||
created_at_timestamp: number
|
||||
created_at: Date
|
||||
duplicate_of?: Uuid
|
||||
enc_item_key: string
|
||||
items_key_id: string | undefined
|
||||
updated_at: Date
|
||||
updated_at_timestamp: number
|
||||
}
|
||||
|
||||
export interface BackupFileDecryptedContextualPayload<C extends ItemContent = ItemContent> extends ContextPayload {
|
||||
content: C
|
||||
created_at_timestamp: number
|
||||
created_at: Date
|
||||
duplicate_of?: Uuid
|
||||
updated_at: Date
|
||||
updated_at_timestamp: number
|
||||
}
|
||||
|
||||
export function CreateEncryptedBackupFileContextPayload(
|
||||
fromPayload: EncryptedTransferPayload,
|
||||
): BackupFileEncryptedContextualPayload {
|
||||
return {
|
||||
auth_hash: fromPayload.auth_hash,
|
||||
content_type: fromPayload.content_type,
|
||||
content: fromPayload.content,
|
||||
created_at_timestamp: fromPayload.created_at_timestamp,
|
||||
created_at: fromPayload.created_at,
|
||||
deleted: false,
|
||||
duplicate_of: fromPayload.duplicate_of,
|
||||
enc_item_key: fromPayload.enc_item_key,
|
||||
items_key_id: fromPayload.items_key_id,
|
||||
updated_at_timestamp: fromPayload.updated_at_timestamp,
|
||||
updated_at: fromPayload.updated_at,
|
||||
uuid: fromPayload.uuid,
|
||||
}
|
||||
}
|
||||
|
||||
export function CreateDecryptedBackupFileContextPayload(
|
||||
fromPayload: DecryptedTransferPayload,
|
||||
): BackupFileDecryptedContextualPayload {
|
||||
return {
|
||||
content_type: fromPayload.content_type,
|
||||
content: fromPayload.content,
|
||||
created_at_timestamp: fromPayload.created_at_timestamp,
|
||||
created_at: fromPayload.created_at,
|
||||
deleted: false,
|
||||
duplicate_of: fromPayload.duplicate_of,
|
||||
updated_at_timestamp: fromPayload.updated_at_timestamp,
|
||||
updated_at: fromPayload.updated_at,
|
||||
uuid: fromPayload.uuid,
|
||||
}
|
||||
export type BackupFile = {
|
||||
version?: ProtocolVersion
|
||||
keyParams?: AnyKeyParamsContent
|
||||
auth_params?: AnyKeyParamsContent
|
||||
items: (BackupFileDecryptedContextualPayload | BackupFileEncryptedContextualPayload)[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
import { ItemContent } from '../Content/ItemContent'
|
||||
import { ContextPayload } from './ContextPayload'
|
||||
|
||||
export interface BackupFileDecryptedContextualPayload<C extends ItemContent = ItemContent> extends ContextPayload {
|
||||
content: C
|
||||
created_at_timestamp: number
|
||||
created_at: Date
|
||||
duplicate_of?: Uuid
|
||||
updated_at: Date
|
||||
updated_at_timestamp: number
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
import { ContextPayload } from './ContextPayload'
|
||||
|
||||
export interface BackupFileEncryptedContextualPayload extends ContextPayload {
|
||||
auth_hash?: string
|
||||
content: string
|
||||
created_at_timestamp: number
|
||||
created_at: Date
|
||||
duplicate_of?: Uuid
|
||||
enc_item_key: string
|
||||
items_key_id: string | undefined
|
||||
updated_at: Date
|
||||
updated_at_timestamp: number
|
||||
}
|
||||
39
packages/models/src/Domain/Abstract/Contextual/Functions.ts
Normal file
39
packages/models/src/Domain/Abstract/Contextual/Functions.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { DecryptedTransferPayload, EncryptedTransferPayload } from '../TransferPayload'
|
||||
|
||||
import { BackupFileDecryptedContextualPayload } from './BackupFileDecryptedContextualPayload'
|
||||
import { BackupFileEncryptedContextualPayload } from './BackupFileEncryptedContextualPayload'
|
||||
|
||||
export function CreateEncryptedBackupFileContextPayload(
|
||||
fromPayload: EncryptedTransferPayload,
|
||||
): BackupFileEncryptedContextualPayload {
|
||||
return {
|
||||
auth_hash: fromPayload.auth_hash,
|
||||
content_type: fromPayload.content_type,
|
||||
content: fromPayload.content,
|
||||
created_at_timestamp: fromPayload.created_at_timestamp,
|
||||
created_at: fromPayload.created_at,
|
||||
deleted: false,
|
||||
duplicate_of: fromPayload.duplicate_of,
|
||||
enc_item_key: fromPayload.enc_item_key,
|
||||
items_key_id: fromPayload.items_key_id,
|
||||
updated_at_timestamp: fromPayload.updated_at_timestamp,
|
||||
updated_at: fromPayload.updated_at,
|
||||
uuid: fromPayload.uuid,
|
||||
}
|
||||
}
|
||||
|
||||
export function CreateDecryptedBackupFileContextPayload(
|
||||
fromPayload: DecryptedTransferPayload,
|
||||
): BackupFileDecryptedContextualPayload {
|
||||
return {
|
||||
content_type: fromPayload.content_type,
|
||||
content: fromPayload.content,
|
||||
created_at_timestamp: fromPayload.created_at_timestamp,
|
||||
created_at: fromPayload.created_at,
|
||||
deleted: false,
|
||||
duplicate_of: fromPayload.duplicate_of,
|
||||
updated_at_timestamp: fromPayload.updated_at_timestamp,
|
||||
updated_at: fromPayload.updated_at,
|
||||
uuid: fromPayload.uuid,
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
export * from './ComponentCreate'
|
||||
export * from './ComponentRetrieved'
|
||||
export * from './BackupFile'
|
||||
export * from './LocalStorage'
|
||||
export * from './OfflineSyncPush'
|
||||
export * from './OfflineSyncSaved'
|
||||
export * from './ServerSyncPush'
|
||||
export * from './SessionHistory'
|
||||
export * from './ServerSyncSaved'
|
||||
export * from './FilteredServerItem'
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
|
||||
import { MutationType } from '../Types/MutationType'
|
||||
|
||||
import { ItemMutator } from './ItemMutator'
|
||||
|
||||
export type TransactionalMutation = {
|
||||
itemUuid: Uuid
|
||||
mutate: (mutator: ItemMutator) => void
|
||||
mutationType?: MutationType
|
||||
}
|
||||
11
packages/models/src/Domain/Abstract/Item/Types/ItemStream.ts
Normal file
11
packages/models/src/Domain/Abstract/Item/Types/ItemStream.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { PayloadEmitSource } from '../../Payload'
|
||||
import { DecryptedItemInterface } from '../Interfaces/DecryptedItem'
|
||||
import { DeletedItemInterface } from '../Interfaces/DeletedItem'
|
||||
import { EncryptedItemInterface } from '../Interfaces/EncryptedItem'
|
||||
|
||||
export type ItemStream<I extends DecryptedItemInterface> = (data: {
|
||||
changed: I[]
|
||||
inserted: I[]
|
||||
removed: (DeletedItemInterface | EncryptedItemInterface)[]
|
||||
source: PayloadEmitSource
|
||||
}) => void
|
||||
@@ -20,10 +20,10 @@ export * from './Interfaces/TypeCheck'
|
||||
export * from './Mutator/DecryptedItemMutator'
|
||||
export * from './Mutator/DeleteMutator'
|
||||
export * from './Mutator/ItemMutator'
|
||||
export * from './Types/AppDataField'
|
||||
export * from './Mutator/TransactionalMutation'
|
||||
export * from './Types/AppDataField'
|
||||
export * from './Types/ConflictStrategy'
|
||||
export * from './Types/DefaultAppDomain'
|
||||
export * from './Types/DefaultAppDomain'
|
||||
export * from './Types/ItemStream'
|
||||
export * from './Types/MutationType'
|
||||
export * from './Types/SingletonStrategy'
|
||||
|
||||
Reference in New Issue
Block a user