Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

gohabereg
Copy link
Member

No description provided.

* @private
*/
public insertInlineFragments(data: Pick<SavedData, 'data'>, fragmentsDict: InlineFragmentsDict): Pick<SavedData, 'data'> {
const insertToString = (str: string, fragments: InlineFragment[]): string => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be moved to the utility method

startOffset = fragment.range[0] - offset;
}

if (!endNode && offset + node.textContent.length >= fragment.range[1]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated code fragment, could be moved to the function

return template.innerHTML;
};

const insert = (dataToProcess: Record<string, unknown>, fragments: InlineFragmentsDict): Pick<SavedData, 'data'> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be moved to the utility method

return;
}

if (typeof value === 'object') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use our internal isObject method

if (typeof value === 'string') {
dataToProcess[key] = insertToString(value, fragments[key] as InlineFragment[]);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if value is another type? number, function, promise etc?

return Tools.blockTools.get(name).sanitizeConfig;
});
const withFragments = sanitizedData.map(savedData => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment needed. Maybe could be moved to the separate method

case Node.ELEMENT_NODE: {
const length = node.textContent.length;
const fragment: InlineFragment = {
range: [offset, offset + length],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment needed

* @private
*/
private extractInlineFragments(data: Pick<SavedData, 'data'>): InlineFragmentsDict {
const extractFromString = (str: string): InlineFragment[] => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utility?

attributes: Object.fromEntries(Array.from((node as HTMLElement).attributes).map(attr => ([attr.nodeName, attr.nodeValue]))),
};

fragments.push(fragment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a fragment contains its own children with fragments?

@@ -0,0 +1,9 @@
export interface InlineFragment {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

descriptions missed

@gohabereg
Copy link
Member Author

gohabereg commented Jul 14, 2022

Todo list:

  • Connect fragments container to each input in block + recalculate on inputs update
  • Decide on output format and implement saving
  • Implement rendering from JSON input
  • Solve a problem with two-step tools like inline link
  • Implement different options on fragment insertion: append, replace, merge
  • Refactoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants