mohamed yahia
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
33 additions and
2 deletions
-
packages/core/src/common/index.ts
-
packages/core/src/pages/index.ts
-
packages/core/src/pages/model/Pages.ts
|
|
|
@ -24,7 +24,7 @@ export type UndoOptions = { fromUndo?: boolean }; |
|
|
|
|
|
|
|
export type WithHTMLParserOptions = { parserOptions?: HTMLParserOptions }; |
|
|
|
|
|
|
|
export type RemoveOptions = Backbone.Silenceable & UndoOptions & { dangerously?: boolean }; |
|
|
|
export type RemoveOptions = Backbone.Silenceable & UndoOptions & { dangerously?: boolean; temporary?: boolean }; |
|
|
|
|
|
|
|
export type EventHandler = Backbone.EventHandler; |
|
|
|
|
|
|
|
|
|
|
|
@ -159,6 +159,37 @@ export default class PageManager extends ItemManagerModule<PageManagerConfig, Pa |
|
|
|
return !opts.abort && rm(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Move a page to a specific index in the pages collection. |
|
|
|
* If the index is out of bounds, an error will be logged and the page will not be moved. |
|
|
|
* |
|
|
|
* @param {string} pageId - The ID of the page to move. |
|
|
|
* @param {number} index - The target index where the page should be moved. |
|
|
|
* @returns {Page | undefined} - The moved page, or `undefined` if the page does not exist or the index is out of bounds. |
|
|
|
* @example |
|
|
|
* // Move a page to index 2
|
|
|
|
* const movedPage = pageManager.move('page-id', 2); |
|
|
|
* if (movedPage) { |
|
|
|
* console.log('Page moved successfully:', movedPage); |
|
|
|
* } else { |
|
|
|
* console.log('Page could not be moved.'); |
|
|
|
* } |
|
|
|
*/ |
|
|
|
move(pageId: string, index: number): Page | undefined { |
|
|
|
const page = this.get(pageId); |
|
|
|
|
|
|
|
if (!page) return; |
|
|
|
|
|
|
|
if (index < 0 || index >= this.pages.length) { |
|
|
|
this.em.logError('Index out of bounds'); |
|
|
|
} |
|
|
|
|
|
|
|
this.remove(page, { temporary: true }); |
|
|
|
this.pages.add(page, { at: index }); |
|
|
|
|
|
|
|
return page; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get page by id |
|
|
|
* @param {String} id Page id |
|
|
|
|
|
|
|
@ -20,7 +20,7 @@ export default class Pages extends Collection<Page> { |
|
|
|
|
|
|
|
onRemove(removed?: Page, _p?: this, opts: RemoveOptions = {}) { |
|
|
|
// Avoid removing frames if triggered from undo #6142
|
|
|
|
if (opts.fromUndo) return; |
|
|
|
if (opts.fromUndo || opts.temporary) return; |
|
|
|
removed?.onRemove(); |
|
|
|
} |
|
|
|
} |
|
|
|
|