0.1.33 • Published 7 days ago

@difizen/libro-core v0.1.33

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

libro-core

Token/API

LibroService

LibroService 管理 libro 实例,libro view 创建、活跃 libro view 的监听等能力。

// 组件内引入
const service = useInject(LibroService);

// 属性引入
@inject(LibroService) service:LibroService;

// 事件监听
service.getOrCreateView(options);
service.onActiveChanged(callback);
service.onFocusChanged(callback);
service.onNotebookViewCreated(callback);

扩展点

单元格扩展

使用单元格扩展可以增加自定义的单元格类型,内置的单元格类型也均基于该扩展定义实现。

单元格定义分为 model 和 view 两部分,model 定义单元格的数据结构,view 定义单元格的渲染方式和提供交互能力。每种单元格都需要对创建时接收到的参数返回优先级,按照最高优先级的单元格类型创建单元格。

export interface CellModelContribution {
  cellMeta: CellMeta;
  canHandle: (options: CellOptions, libroType?: string) => number;
  createModel: (options: CellOptions) => MaybePromise<CellModel>;
  getDefaultCellOption?: () => CellOptions;
}
export interface CellViewContribution {
  canHandle: (options: CellOptions) => number;
  view: Newable<CellView>;
}

输出扩展

使用输出扩展可以增加自定义的输出类型,内置的输出类型也均基于该扩展定义实现。在 jupyter 场景下,用户一般不需要增加输出类型的扩展,而仅需要增加 mime 渲染器,mime 渲染器扩展由 output 实现。

export interface OutputContribution {
  canHandle: (output: IOutput) => number;
  factory: OutputModelFactory;
}

内容加载扩展

用户有时候从自定义存储中读取 notebook 数据,可以通过内容加载扩展来实现,这里要求用户的返回数据符合 notebook 的数据结构。

export interface ContentContribution {
  canHandle: (options: Record<string, any>, model: any) => number;
  loadContent: (options: Record<string, any>, model: any) => Promise<INotebookContent>;
}

视图插槽

如果希望在编辑器内部增加一些自定义的渲染像,除了可以覆盖内置的渲染器外,还可以通过视图插槽的方式来实现。

内置插槽位置如下:

  • container
  • content
  • list
  • right
export interface LibroExtensionSlotContribution {
  factory: LibroExtensionSlotFactory;
  slot: LibroSlot;
  viewOpenOption?: {
    order?: string;
    reveal?: boolean;
  };
}

命令 & 快捷键

文档命令

命令快捷键命令模式说明
document:savectrlcmd+s保存文档
document:setting打开配置

kernel 命令

命令快捷键命令模式说明
notebook:change-kernelChange Kernel
notebook:get-kernelGet Kernel
notebook:interrupt-kernelInterrupt Kernel
notebook:reconnect-to-kernelReconnect to Kernel
notebook:restart-kernelRestart Kernel
notebook:shutdown-kernelShutdown Kernel

notebook 命令

命令快捷键命令模式说明
notebook:interruptInterrupt
notebook:change-cell-to
notebook:change-cell-to-codeYChange to Code Cell Type
notebook:change-cell-to-heading-11Change to Heading 1
notebook:change-cell-to-heading-22Change to Heading 2
notebook:change-cell-to-heading-33Change to Heading 3
notebook:change-cell-to-heading-44Change to Heading 4
notebook:change-cell-to-heading-55Change to Heading 5
notebook:change-cell-to-heading-66Change to Heading 6
notebook:change-cell-to-markdownMChange to Markdown Cell Type
notebook:change-cell-to-rawRChange to Raw Cell Type
notebook:clear-all-cell-outputsClear Outputs of All Cells
notebook:clear-cell-outputsClear Cell Output
notebook:close-and-shutdownClose editor and shut down kernel
notebook:collapse-all-headingsctrlcmd+shift+leftCollapse All Headings
notebook:copy-cellCCopy Cells
notebook:cut-cellXCut Cells
notebook:delete-cellD DDelete Cells
notebook:deselect-allDeselect All Cells
notebook:disable-output-scrollingDisable Scrolling for Outputs
notebook:duplicate-belowDuplicate Cells Below
notebook:enable-output-scrollingEnable Scrolling for Outputs
notebook:enter-command-modeescEnter Command Mode
notebook:enter-edit-modeenterEnter Edit Mode
notebook:expand-all-headingsctrlcmd+shift+rightExpand All Headings
notebook:export-to-formatSave and Export Notebook to the given format
notebook:extend-marked-cells-aboveshift+up shift+KExtend Selection Above
notebook:extend-marked-cells-belowshift+down shift+JExtend Selection Below
notebook:extend-marked-cells-bottomshift+endExtend Selection to Bottom
notebook:extend-marked-cells-topshift+homeExtend Selection to Top
notebook:hide-all-cell
notebook:hide-all-cell-codeCollapse All Code
notebook:hide-all-cell-outputCollapse All Outputs
notebook:hide-cell-codeCollapse Selected Code
notebook:hide-or-show-cell-codectrlcmd+'Hide or show Selected Code
notebook:hide-cell-outputsCollapse Selected Outputs
notebook:hide-or-show-outputsctrlcmd+oHide or show Selected outputs
notebook:insert-cell-aboveAInsert Cell Above
notebook:insert-cell-belowBInsert Cell Below
notebook:insert-heading-aboveshift+AInsert Heading Above Current Heading
notebook:insert-heading-belowshift+BInsert Heading Below Current Heading
notebook:merge-cell-abovectrlcmd+backspaceMerge Cell Above
notebook:merge-cell-belowctrlcmd+shift+MMerge Cell Below
notebook:merge-cellsshift+MMerge Selected Cells
notebook:move-cell-downctrlcmd+shift+downMove Cells Down
notebook:move-cell-upctrlcmd+shift+upMove Cells Up
notebook:move-cursor-downdown JSelect Cell Below
notebook:move-cursor-upup KSelect Cell Up
notebook:move-cursor-heading-above-or-collapseleftSelect Heading Above or Collapse Heading
notebook:move-cursor-heading-below-or-expandrightSelect Heading Below or Collapse Heading
notebook:paste-and-replace-cellPaste Cells and Replace
notebook:paste-cell-abovePaste Cells Above
notebook:paste-cell-belowVPaste Cells Below
notebook:redoRedo
notebook:redo-cell-actionshift+ZRedo Cell Operation
notebook:render-all-markdownRender All Markdown Cells
notebook:replace-selectionReplace Selection in Notebook Cell
notebook:restart-and-run-to-selectedRestart and Run up to Selected Cell
notebook:restart-clear-outputRestart and Clear Outputs of All Cells
notebook:restart-run-allRestart and Run All Cells
notebook:run-all-aboveRun All Above Selected Cell
notebook:run-all-belowRun All Below Selected Cell
notebook:run-all-cellsRun All Cells
notebook:run-cellctrlcmd+enterRun Selected Cells and Don't Advance
notebook:run-cell-and-insert-belowalt+enterRun Selected Cells and Insert Below
notebook:run-cell-and-select-nextshift+enterRun Selected Cells and Select Below
notebook:run-in-consoleRun Selected Text or Current Line in Console
notebook:select-allctrlcmd+ASelect All Cells
notebook:select-last-run-cellSelect current running or last run cell
notebook:set-side-by-side-ratioSet Side by Side Ratio
notebook:show-all-cellExpand All Cell
notebook:show-all-cell-codeExpand All Code
notebook:show-all-cell-outputsExpand All Outputs
notebook:show-cell-codeExpand Selected Code
notebook:show-cell-outputsExpand Selected Outputs
notebook:split-cell-at-cursorctrlcmd+shift+-Split Cell
notebook:toggle-all-cell-line-numbersshift+LShow Line Numbers
notebook:toggle-autoclosing-bracketsAuto Close Brackets for All Notebook Cell Types
notebook:toggle-heading-collapseToggle Collapse Notebook Heading
notebook:toggle-render-side-by-side-currentshift+RRender Side-by-Side
notebook:trustTrust Notebook
notebook:undoUndo
notebook:undo-cell-actionZUndo Cell Operation
notebook:insert-cell-bottom

配置 & 主题

libro 内置了一些配置项和主题设置,用户可以是用 mana 的配置模块和主题模块来消费或变更。

配置项说明默认值
libro.header.toolbar是否显示 libro 顶部工具栏true
libro.cell.top-toolbar是否显示单元格顶部工具栏true
libro.cell.side-toolbar是否显示单元格侧边工具栏true
libro.command.insert-cell-below没有单元格时是否默认创建单元格true
libro.command.enter-edit-mode-when-add-cell增加单元格操作默认进入编辑态true
libro.command.collapser-active点击左侧长条是否可以隐藏与显示单元格true
libro.command.multiselection-when-shift-click按住 shift 键并点击拖拽区域可以进行多选true
libro.right.content.fixedlibro view 的右边栏是否相对固定false
颜色css 变量暗色主题亮色主题高对比主题说明
libro.warning.background#A9611466#FFFBE6
libro.drag.hover.line.color#467DB0#BFE0FF
libro.background#1F2022#FFFFFF
libro.popover.background.color#2F3032#FFFFFF
libro.menu.hover.color#515359#EBF6FF
libro.dropdown.icon.color#FFFFFF4D#00000033
libro.input.background#19191B#F4F6FB
libro.text.default.color#E3E4E6#000000
libro.text.tertiary.color#BDC0C4#B8BABA
libro.output.background#292A2D#FFFFFF
libro.toptoolbar.border.color#FFFFFF1A#0000001A
libro.toptoolbar.icon.color#BFBFBF#7B7B7B
libro.toptoolbar.disabled.icon.color#FFFFFF4D#00000040
libro.toptoolbar.text.color#F5F5F5#000000
libro.bottom.btn.background.color#FFFFFF0A#FFFFFF
libro.bottom.btn.border.color#505559#000A1A29
libro.bottom.btn.icon.color#505559#525964D9
libro.bottom.btn.text.color#E3E4E6#000A1AAD
libro.default.btn.background.color#FFFFFF1A#FFFFFF
libro.default.btn.text.color#E3E4E6#000A1AAD
libro.primary.btn.background.color#2A97FD#1890FF
libro.default.btn.border.color#BDC0C4#D6D8DA
libro.toolbar.menu.label.color#BDC0C4#000000A6
libro.toolbar.menu.disabled.label.color#878C93#00000040
libro.toolbar.menu.keybind.color#878C93#00000073
libro.sidetoolbar.icon.color#BFBFBF#6982A9
libro.sidetoolbar.border.color#FFFFFF14#0000001A
libro.close.color#FFFFFF73#00000073
libro.modal.title.color#EDEEEF#000000D9
libro.modal.content.color#E3E4E6#000A1A
libro.btn.primary.background.color#2A97FD#1890FF
libro.execution.count.color#8694A9#6A83AA
libro.tip.font.color#D6D8DA#00000080
libro.execution.tip.success.color#48A918#0DC54E
libro.link.color#177DDC#1890FF
libro.error.color#CF4C52#ED1345
libro.cell.border.color#3B3C42#D6DEE6
libro.cell.active.border.color#378EDF#3490ED
libro.cell.active.border.shadow.color#49A2FA40#3592EE40
libro.cell.header.content#E3E4E6#545B66
libro.cell.header.title#D6D8DA#000A1A
libro.code.border.color#353638#DCE4EC
libro.input.border.color#505559#00000026
libro.input.background.color#FFFFFF0A#FFFFFF
libro.input.group.btn.background.color#00000005#00000005
libro.table.innner.border.color#1AFFFF#E5EBF1
libro.table.bottom.border.color#424242#E2E7EC
libro.editor.keyword.color#109B67#098658
libro.editor.number.color#109B67#098658
libro.editor.variable.2.color#5DA4EA#2060A0
libro.editor.punctuation.color#5DA4EA#2060A0
libro.editor.property.color#5DA4EA#2060A0
libro.editor.operator.color#E12EE1#C700C7
libro.editor.meta.color#E12EE1#C700C7
libro.editor.builtin.color#109B67#098658
libro.editor.variable.color#E3E4E6#212121
libro.editor.def.color#187DFF#003CFF
libro.editor.comment.color#618961#406040
libro.editor.string.color#FF5B48#C03030
libro.editor.activeline.color#E5E8F01A#E5E8F080
libro.editor.selectionMatch.color#99FF7780#DDE6FF
libro.editor.selection.color#B4CEFF#B4CEFF
libro.editor.gutter.number.color#A8EABF#A4AECB
libro.editor.line.color#565C6D#A4AECB
libro.editor.cursor.color#FFFFFF#000000
libro.editor.indent.marker.bg.color#42444D#D6DBEB
libro.editor.indent.marker.active.bg.color#788491#9f9f9f
0.1.32

8 days ago

0.1.33

7 days ago

0.1.31

19 days ago

0.1.30

20 days ago

0.1.29

20 days ago

0.1.28

1 month ago

0.1.27

1 month ago

0.1.26

1 month ago

0.1.24

2 months ago

0.1.23

2 months ago

0.1.22

2 months ago

0.2.0

2 months ago

0.1.20

2 months ago

0.1.21

2 months ago

0.1.19

3 months ago

0.1.18

3 months ago

0.1.15

3 months ago

0.1.16

3 months ago

0.1.17

3 months ago

0.1.14

4 months ago

0.1.13

4 months ago

0.1.12

4 months ago

0.1.11

4 months ago

0.1.10

4 months ago

0.1.9

4 months ago

0.1.8

4 months ago

0.1.7

4 months ago

0.1.6

4 months ago

0.1.4

5 months ago

0.1.5

5 months ago

0.1.2

5 months ago

0.1.3

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago

0.0.2-alpha.0

7 months ago