prevwong / craft.js

🚀 A React Framework for building extensible drag and drop page editors
https://craft.js.org
MIT License
7.63k stars 743 forks source link

About NodeId generate rule. #518

Open tal007 opened 1 year ago

tal007 commented 1 year ago

Is your feature request related to a problem? Please describe. I what to change the NodeId generate rule. At image

import { nanoid } from 'nanoid';

// By default nanoid generate an ID with 21 characters. To reduce the footprint, we default to 10 characters.
// We have a higher probability for collisions, though

/**
 * Generate a random ID. That ID can for example be used as a node ID.
 *
 * @param size The number of characters that are generated for the ID. Defaults to `10`
 * @returns A random id
 */
export const getRandomId = (size: number = 10) => nanoid(size);

default use 10, but i cannot setting the characters map. Such as i don't what the id has '-'. Or just includes number and a-z.

Describe the solution you'd like

import { customAlphabet } from 'nanoid';

// By default nanoid generate an ID with 21 characters. To reduce the footprint, we default to 10 characters.
// We have a higher probability for collisions, though

/**
 * Generate a random ID. That ID can for example be used as a node ID.
 *
 * @param size The number of characters that are generated for the ID. Defaults to `10`
 * @returns A random id
 */
let urlAlphabet =
  "useandom26T198340PX75pxJACKVERYMINDBUSHWOLFGQZbfghjklqvwyzrict";
export const getRandomId = (size: number = 10) => customAlphabet(urlAlphabet, size)();

Additional context Add any other context or screenshots about the feature request here.

DenysVuika commented 8 months ago

@prevwong is it possible to make the ID generator pluggable? so that custom ones could be introduced? thanks

hugominas commented 8 months ago

@DenysVuika did you try import { getRandomId } from "@craftjs/utils";

https://github.com/prevwong/craft.js/issues/209

DenysVuika commented 8 months ago

thanks @hugominas, I am more interested to use custom id generator when serializing... the current one produces invalid values in terms of html node id format, i.e. "-8x...", which is not correct.