{
  "version": 3,
  "sources": ["../../card/add_card_actions.ts"],
  "sourcesContent": ["import {ui_actions, ui_state} from \"../state/index\"\nimport model_actions from \"../state/model_actions\"\nimport {\n    Note,\n    Link,\n    GetUploadBlobURLRequest,\n    GetUploadBlobURLResponse,\n    Blob,\n    File as FileModel,\n    Board,\n    Card,\n    ImageCardDisplay,\n    is_image,\n    CardColor,\n    ImageCardDisplayKind,\n} from \"@cling/lib.shared.model\"\nimport {\n    cancel_uploads,\n    let_user_select_files,\n    upload_files,\n    check_blob_quota_limits,\n    add_provisional_thumbnail_for_uploaded_file,\n} from \"../upload/upload\"\nimport {call_function} from \"@cling/lib.shared.faas\"\nimport {board_resource} from \"@cling/lib.web.resources\"\nimport {Snackbar} from \"@cling/lib.web.mdc\"\nimport {i18n} from \"@cling/lib.web.i18n\"\nimport type {InsertPos} from \"../state/types\"\nimport {runInAction} from \"mobx\"\nimport {not_null} from \"@cling/lib.shared.utils\"\nimport {sanitize_file_name} from \"@cling/lib.shared.utils/file_name\"\n\nexport class AddCardActions {\n    constructor(\n        private readonly board: Board,\n        private readonly insert_pos_provider: () => InsertPos,\n    ) {}\n\n    add_note = (opts?: {special_editor?: \"title\" | \"audio\" | \"video\" | \"photo\"}) => {\n        this._add_note_or_link({note: new Note({})}, opts)\n    }\n\n    add_link = () => {\n        this._add_note_or_link({link: new Link({})})\n    }\n\n    paste = () => {\n        model_actions.paste_card(this.board, this.insert_pos_provider())\n    }\n\n    add_file = async () => {\n        const files = await let_user_select_files({multiple: true})\n        return this.add_files(files.map((x) => ({file: x})))\n    }\n\n    add_files = async (\n        files: {file: File; file_name?: string; title?: string; card_color?: CardColor}[],\n    ) => {\n        let {board} = this\n        const insert_pos = this.insert_pos_provider()\n        ui_actions.hide_global_backdrop()\n        if (files.length === 0) {\n            return\n        }\n        if (!check_blob_quota_limits(files.map((x) => x.file))) {\n            return\n        }\n        upload_files({\n            files,\n            get_upload_url: async (o: {mime_type: string; md5_base64: string; size: number}) =>\n                call_function(new GetUploadBlobURLRequest(o), GetUploadBlobURLResponse),\n            on_progress: () => {\n                try {\n                    board.card(insert_pos.target_card_uid)\n                } catch {\n                    // Target card has been removed from board.\n                    cancel_uploads()\n                    Snackbar.show_message(i18n.upload_canceled)\n                }\n            },\n            on_file_uploaded: async ({blob_uid, file, mime_type, md5_base64}) => {\n                if (mime_type.startsWith(\"image/\") && !mime_type.includes(\"svg\")) {\n                    await add_provisional_thumbnail_for_uploaded_file({file: file.file, blob_uid})\n                }\n                const blob = new Blob({\n                    uid: blob_uid,\n                    size: file.file.size,\n                    mime_type,\n                    md5_base64,\n                })\n                // Make sure we use the latest board version\n                board = not_null(board_resource.read(board.uid))\n                const new_card_uid = model_actions.add_file_card(\n                    board,\n                    insert_pos,\n                    new FileModel({\n                        blob,\n                        file_name:\n                            sanitize_file_name(file.file_name || file.file.name) || \"unknown.bin\",\n                        title: file.title,\n                        display: new ImageCardDisplay({\n                            kind: is_image(blob)\n                                ? ImageCardDisplayKind.cinema\n                                : ImageCardDisplayKind.condensed,\n                        }),\n                    }),\n                    file.card_color,\n                )\n                if (new_card_uid) {\n                    // Make sure we use the patched board.\n                    board = not_null(board_resource.read(board.uid))\n                    const parent = board.card(new_card_uid).parent\n                    if (parent.column) {\n                        // Ok, we added a column, now put the next cards\n                        // beneath the newly created card.\n                        insert_pos.target_card_uid = parent.uid\n                    }\n                    insert_pos.target_pos += 1\n                } else {\n                    // Target card has been removed from board.\n                    cancel_uploads()\n                    Snackbar.show_message(i18n.upload_canceled)\n                }\n            },\n        })\n    }\n\n    private _add_note_or_link(\n        value: {note: Note} | {note?: never; link: Link},\n        opts?: {special_editor?: \"title\" | \"audio\" | \"video\" | \"photo\"},\n    ) {\n        const {board} = this\n        runInAction(() => {\n            const card_uid = model_actions.add_card_locally(\n                board,\n                this.insert_pos_provider(),\n                value,\n            )\n            if (card_uid !== \"quota_exceeded\") {\n                ui_actions.start_editing_card(board.uid, card_uid, opts)\n            }\n        })\n    }\n}\n\nexport function below_card_insert_pos(\n    card: Card,\n    {has_visible_children}: {has_visible_children: boolean},\n): InsertPos {\n    return has_visible_children && !ui_state.is_children_collapsed(card)\n        ? {target_card_uid: card.uid, target_pos: 0}\n        : {target_card_uid: card.parent.uid, target_pos: card.parent_pos + 1}\n}\n\nexport function above_card_insert_pos(card: Card): InsertPos {\n    return {target_card_uid: card.parent.uid, target_pos: card.parent_pos}\n}\n"],
  "mappings": "+bAgCO,IAAMA,EAAN,MAAMA,CAAe,CACxB,YACqBC,EACAC,EACnB,CAFmB,WAAAD,EACA,yBAAAC,EAGrBC,EAAA,gBAAWC,EAACC,GAAoE,CAC5E,KAAK,kBAAkB,CAAC,KAAM,IAAIC,EAAK,CAAC,CAAC,CAAC,EAAGD,CAAI,CACrD,EAFW,aAIXF,EAAA,gBAAWC,EAAA,IAAM,CACb,KAAK,kBAAkB,CAAC,KAAM,IAAIG,EAAK,CAAC,CAAC,CAAC,CAAC,CAC/C,EAFW,aAIXJ,EAAA,aAAQC,EAAA,IAAM,CACVI,EAAc,WAAW,KAAK,MAAO,KAAK,oBAAoB,CAAC,CACnE,EAFQ,UAIRL,EAAA,gBAAWC,EAAA,SAAY,CACnB,IAAMK,EAAQ,MAAMC,EAAsB,CAAC,SAAU,EAAI,CAAC,EAC1D,OAAO,KAAK,UAAUD,EAAM,IAAKE,IAAO,CAAC,KAAMA,CAAC,EAAE,CAAC,CACvD,EAHW,aAKXR,EAAA,iBAAYC,EAAA,MACRK,GACC,CACD,GAAI,CAAC,MAAAR,CAAK,EAAI,KACRW,EAAa,KAAK,oBAAoB,EAC5CC,EAAW,qBAAqB,EAC5BJ,EAAM,SAAW,GAGhBK,EAAwBL,EAAM,IAAKE,GAAMA,EAAE,IAAI,CAAC,GAGrDI,EAAa,CACT,MAAAN,EACA,eAAgBL,EAAA,MAAOY,GACnBC,EAAc,IAAIC,EAAwBF,CAAC,EAAGG,CAAwB,EAD1D,kBAEhB,YAAaf,EAAA,IAAM,CACf,GAAI,CACAH,EAAM,KA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AI,CAE/D,CAAC,CACL,CACJ,EA/G4BD,EAAAJ,EAAA,kBAArB,IAAMyC,EAANzC,EAiHA,SAAS0C,EACZC,EACA,CAAC,qBAAAC,CAAoB,EACZ,CACT,OAAOA,GAAwB,CAACC,EAAS,sBAAsBF,CAAI,EAC7D,CAAC,gBAAiBA,EAAK,IAAK,WAAY,CAAC,EACzC,CAAC,gBAAiBA,EAAK,OAAO,IAAK,WAAYA,EAAK,WAAa,CAAC,CAC5E,CAPgBvC,EAAAsC,EAAA,yBAST,SAASI,GAAsBH,EAAuB,CACzD,MAAO,CAAC,gBAAiBA,EAAK,OAAO,IAAK,WAAYA,EAAK,UAAU,CACzE,CAFgBvC,EAAA0C,GAAA",
  "names": ["_AddCardActions", "board", "insert_pos_provider", "__publicField", "__name", "opts", "Note", "Link", "model_actions_default", "files", "let_user_select_files", "x", "insert_pos", "ui_actions", "check_blob_quota_limits", "upload_files", "o", "call_function", "GetUploadBlobURLRequest", "GetUploadBlobURLResponse", "cancel_uploads", "Snackbar", "i18n", "blob_uid", "file", "mime_type", "md5_base64", "add_provisional_thumbnail_for_uploaded_file", "blob", "Blob", "not_null", "board_resource", "new_card_uid", "File", "sanitize_file_name", "ImageCardDisplay", "is_image", "parent", "value", "runInAction", "card_uid", "AddCardActions", "below_card_insert_pos", "card", "has_visible_children", "ui_state", "above_card_insert_pos"]
}