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
feat: Add unique ids for each block #1493
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,14 @@ function BlockAPI( | |||||
block: Block | ||||||
): void { | ||||||
const blockAPI: BlockAPIInterface = { | ||||||
/** | ||||||
* Tool id | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* @returns {string} | ||||||
*/ | ||||||
get id(): string { | ||||||
return block.id; | ||||||
}, | ||||||
/** | ||||||
* Tool name | ||||||
* | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,11 @@ import SelectionUtils from '../selection'; | |||||
* Interface describes Block class constructor argument | ||||||
*/ | ||||||
interface BlockConstructorOptions { | ||||||
/** | ||||||
* Tool's id | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
id: string; | ||||||
|
||||||
/** | ||||||
* Tool's name | ||||||
*/ | ||||||
|
@@ -107,6 +112,11 @@ export default class Block { | |||||
}; | ||||||
} | ||||||
|
||||||
/** | ||||||
* unique identifier | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
public id: string; | ||||||
|
||||||
/** | ||||||
* Block Tool`s name | ||||||
*/ | ||||||
|
@@ -199,6 +209,7 @@ export default class Block { | |||||
|
||||||
/** | ||||||
* @param {object} options - block constructor options | ||||||
* @param {string} options.id - Tool's unique id | ||||||
* @param {string} options.name - Tool name that passed on initialization | ||||||
* @param {BlockToolData} options.data - Tool's initial data | ||||||
* @param {BlockToolConstructable} options.Tool — Tool's class | ||||||
|
@@ -207,13 +218,15 @@ export default class Block { | |||||
* @param {boolean} options.readOnly - Read-Only flag | ||||||
*/ | ||||||
constructor({ | ||||||
id, | ||||||
name, | ||||||
data, | ||||||
Tool, | ||||||
settings, | ||||||
api, | ||||||
readOnly, | ||||||
}: BlockConstructorOptions) { | ||||||
this.id = id; | ||||||
this.name = name; | ||||||
this.class = Tool; | ||||||
this.settings = settings; | ||||||
|
@@ -550,6 +563,7 @@ export default class Block { | |||||
measuringEnd = window.performance.now(); | ||||||
|
||||||
return { | ||||||
id: this.id, | ||||||
tool: this.name, | ||||||
data: finishedExtraction, | ||||||
time: measuringEnd - measuringStart, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -759,7 +759,7 @@ export default class Paste extends Module { | |||||
* | ||||||
* @returns {void} | ||||||
*/ | ||||||
private insertEditorJSData(blocks: Array<Pick<SavedData, 'data' | 'tool'>>): void { | ||||||
private insertEditorJSData(blocks: Array<Pick<SavedData, 'id' | 'data' | 'tool'>>): void { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const { BlockManager, Sanitizer, Tools } = this.Editor; | ||||||
const sanitizedBlocks = Sanitizer.sanitizeBlocks(blocks); | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,6 +607,21 @@ export function getValidUrl(url: string): string { | |
} | ||
} | ||
|
||
/** | ||
* Creates a UUID v4 version | ||
* | ||
* @returns {string} | ||
*/ | ||
export function generateUuidv4(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to name this method just as export function generateId(): string {
return uuidv4();
}
function uuidv4(): string {
// your code
} so that we could change the id generator algorithm |
||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { | ||
// tslint:disable: no-bitwise | ||
// tslint:disable-next-line: triple-equals | ||
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); | ||
|
||
return v.toString(16); | ||
}); | ||
} | ||
|
||
/** | ||
* Opens new Tab with passed URL | ||
* | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,11 @@ import {SavedData} from '../data-formats'; | |||||
* @interface BlockAPI Describes Block API methods and properties | ||||||
*/ | ||||||
export interface BlockAPI { | ||||||
/** | ||||||
* Tool name | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
readonly id: string; | ||||||
|
||||||
/** | ||||||
* Tool name | ||||||
*/ | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This supposed to be here?