This repository was archived by the owner on Apr 11, 2024. It is now read-only.
feat(ids): Support custom IDs for Sketch library sync#67
Open
macintoshhelper wants to merge 6 commits into
Open
feat(ids): Support custom IDs for Sketch library sync#67macintoshhelper wants to merge 6 commits into
macintoshhelper wants to merge 6 commits into
Conversation
…li into feat/custom-ids
|
@macintoshhelper This PR seems to be just what I need 🙏 But I’m a little bit confused by |
mathieudutour
suggested changes
May 15, 2019
| const { sketchId } = parentNode.dataset; | ||
|
|
||
| if (sketchId) { | ||
| layer.setObjectID(`text:${sketchId}`); |
There was a problem hiding this comment.
please don't use arbitrary strings as ObjectId, it's going to break Sketch in very subtle ways. Sketch expect IDs to be UUID.
You can generate a fixed UUID from a seed if you want:
import * as seedrandom from 'seedrandom';
const lut = [];
for (let i = 0; i < 256; i += 1) {
lut[i] = (i < 16 ? '0' : '') + i.toString(16);
}
// Hack (http://stackoverflow.com/a/21963136)
function e7(seed?: ?string) {
const random = seed ? seedrandom(`${seed}0`) : Math.random;
const d0 = (random() * 0xffffffff) | 0;
const d1 = (random() * 0xffffffff) | 0;
const d2 = (random() * 0xffffffff) | 0;
const d3 = (random() * 0xffffffff) | 0;
return `${lut[d0 & 0xff] +
lut[(d0 >> 8) & 0xff] +
lut[(d0 >> 16) & 0xff] +
lut[(d0 >> 24) & 0xff]}-${lut[d1 & 0xff]}${lut[(d1 >> 8) & 0xff]}-${
lut[((d1 >> 16) & 0x0f) | 0x40]
}${lut[(d1 >> 24) & 0xff]}-${lut[(d2 & 0x3f) | 0x80]}${lut[(d2 >> 8) & 0xff]}-${
lut[(d2 >> 16) & 0xff]
}${lut[(d2 >> 24) & 0xff]}${lut[d3 & 0xff]}${lut[(d3 >> 8) & 0xff]}${lut[(d3 >> 16) & 0xff]}${
lut[(d3 >> 24) & 0xff]
}`;
}
// Keep track of previous seeds
const previousSeeds = {};
export function generateID(seed) {
let _seed;
if (seed) {
if (!previousSeeds[seed]) {
previousSeeds[seed] = 0;
}
previousSeeds[seed] += 1;
_seed = `${seed}${previousSeeds[seed]}`;
}
return e7(_seed);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a document/page name option in the config together with a
customIdsopt-in option that uses permanent IDs for shared styles inhtml-sketchappif you know all IDs (data-sketch-text) are unique and will not change.This PR should fix library sync between updates (symbols can have a permanent ID).
Documentation should probably be added to the
README.mdor a new file for setting symbol IDs:I've added documentation to the README for text middleware.
New config options:
#18