diff --git a/markdown/dev/reference/api/hooks/inserttext/en.md b/markdown/dev/reference/api/hooks/inserttext/en.md index 561f0a19ad6..64834c8d57f 100644 --- a/markdown/dev/reference/api/hooks/inserttext/en.md +++ b/markdown/dev/reference/api/hooks/inserttext/en.md @@ -1,34 +1,43 @@ --- -title: insertText +title: insertText --- -The `insertText` hook is called when text is about to be inserted during rendering. +The `insertText` lifecycle hook is called when text is about to be inserted +during rendering. -Methods attached to the `insertText` hook will receive 2 parameters: - -- `locale` : The language code of the language requested by the user (defaults to `en`) -- `text`: The text to be inserted - -Unlike most hooks that receive an object that you can make changes to, -for this hook you need to return a string. - -This hook is typically used for translation, as is the case +It is typically used for translation, as is the case in [our i18n plugin](/reference/plugins/i18n/). -## Understanding the insertText hook +## Signature + +```js +string hook(string locale='en', string text) +``` + +## Example + +```js +// Let' get LOUD by turning everything into UPPERCASE +pattern.on( + 'insertText', + (locale, text) => text.toUpperCase() +) +``` + +## Notes When we say that _this hook is called when text is about to be inserted_, that is a simplified view. In reality, this hook is called: -- For every value set on data-text +- For every string of text added to a given Point or Path - For the combined result of these values, joined together with spaces Let's use an example to clarify things: ```js points.example - .attr('data-text', "seamAllowance") - .attr('data-text', ": 1cm") + .addText("seamAllowance") + .addText(": 1cm") ``` For the example point above, the `insertText` hook will end up being called 3 times: diff --git a/markdown/dev/reference/api/hooks/postdraft/en.md b/markdown/dev/reference/api/hooks/postdraft/en.md index 0291e148180..d6dab665641 100644 --- a/markdown/dev/reference/api/hooks/postdraft/en.md +++ b/markdown/dev/reference/api/hooks/postdraft/en.md @@ -2,12 +2,22 @@ title: postDraft --- -The `postDraft` hook runs just after your pattern is drafted. +The `postDraft` lifecycle hook runs just after your pattern is drafted. -Your plugin will receive the Pattern object. +## Signature - +```js +null hook(Pattern pattern) +``` -The `postDraft` hook is rarely used. +## Example - +```js +pattern.on('postDraft', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `postDraft` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/postinit/en.md b/markdown/dev/reference/api/hooks/postinit/en.md new file mode 100644 index 00000000000..8d6150d36ad --- /dev/null +++ b/markdown/dev/reference/api/hooks/postinit/en.md @@ -0,0 +1,23 @@ +--- +title: postInit +--- + +The `postInit` lifecycle hook runs just after a pattern is initialized. + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('postInit', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `postInit` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/postlayout/en.md b/markdown/dev/reference/api/hooks/postlayout/en.md new file mode 100644 index 00000000000..d250b7dcf01 --- /dev/null +++ b/markdown/dev/reference/api/hooks/postlayout/en.md @@ -0,0 +1,24 @@ +--- +title: postLayout +--- + +The `postLayout` lifecycle hook runs just after the pattern layout is +calculated. + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('postLayout', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `postLayout` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/postpartdraft/en.md b/markdown/dev/reference/api/hooks/postpartdraft/en.md new file mode 100644 index 00000000000..f53de002abd --- /dev/null +++ b/markdown/dev/reference/api/hooks/postpartdraft/en.md @@ -0,0 +1,27 @@ +--- +title: postPartDraft +--- + +The `postPartDraft` lifecycle hook runs just after a part is drafted. +It will fire once for each part in each set (of settings). + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('postPartDraft', pattern => { + // Mutate the pattern object here + // You can use the pattern.activePart + // and pattern.activeSet properties to + // figure out for which part this hook was fired +} +``` + +## Notes + +The `postPartDraft` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/postrender/en.md b/markdown/dev/reference/api/hooks/postrender/en.md index 9f82c7f6103..6b6556e5579 100644 --- a/markdown/dev/reference/api/hooks/postrender/en.md +++ b/markdown/dev/reference/api/hooks/postrender/en.md @@ -2,12 +2,18 @@ title: postRender --- -The `postRender` hook is triggered after the SVG is rendered. +The `postRender` lifecycle hook is triggered after the SVG is rendered. +It will only fire when `Pattern.render()` is called. -Like the `preRender` hook, it receives [the SVG object](/api/svg) as its first parameter. +## Signature - +```js +null hook(Svg svg) +``` -The `postRender` hooks is rarely used. +## Notes - +The `postRender` hook is rarely used, but it's there if you need it. + +Like the `preRender` hook, it receives [the SVG object](/api/svg) as its first +parameter. diff --git a/markdown/dev/reference/api/hooks/postsample/en.md b/markdown/dev/reference/api/hooks/postsample/en.md index f044640059e..ef79a7b4cdf 100644 --- a/markdown/dev/reference/api/hooks/postsample/en.md +++ b/markdown/dev/reference/api/hooks/postsample/en.md @@ -3,7 +3,24 @@ title: postSample --- The `postSample` hook runs just after your pattern is sampled. -Your plugin will receive the Pattern object. + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('postSample', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `postSample` hook is rarely used, but it's there if you need it. It is triggered just before the end of either: @@ -11,8 +28,3 @@ It is triggered just before the end of either: - the [Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement) method - the [Pattern.sampleModels()](/reference/api/pattern/samplemodels) method - - -The `postSample` hook is rarely used. - - diff --git a/markdown/dev/reference/api/hooks/postsetdraft/en.md b/markdown/dev/reference/api/hooks/postsetdraft/en.md new file mode 100644 index 00000000000..103b6abd434 --- /dev/null +++ b/markdown/dev/reference/api/hooks/postsetdraft/en.md @@ -0,0 +1,24 @@ +--- +title: postSetDraft +--- + +The `postSetDraft` lifecycle hook runs just after a set (of settings) is +drafted. It will fire once for each set when calling `Pattern.draft()`. + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('postSetDraft', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `postSetDraft` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/predraft/en.md b/markdown/dev/reference/api/hooks/predraft/en.md index 25d38faa2c6..471c5af6f3c 100644 --- a/markdown/dev/reference/api/hooks/predraft/en.md +++ b/markdown/dev/reference/api/hooks/predraft/en.md @@ -2,12 +2,22 @@ title: preDraft --- -The `preDraft` hook runs just before your pattern is drafted. +The `preDraft` lifecycle hook runs just before your pattern is drafted. -Your plugin will receive the Pattern object. +## Signature - +```js +null hook(Pattern pattern) +``` -The `preDraft` hook is rarely used. +## Example - +```js +pattern.on('preDraft', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `preDraft` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/preinit/en.md b/markdown/dev/reference/api/hooks/preinit/en.md new file mode 100644 index 00000000000..f2aad996353 --- /dev/null +++ b/markdown/dev/reference/api/hooks/preinit/en.md @@ -0,0 +1,23 @@ +--- +title: preInit +--- + +The `preInit` lifecycle hook runs just before a pattern will be initialized. + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('preInit', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `preInit` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/prepartdraft/en.md b/markdown/dev/reference/api/hooks/prepartdraft/en.md new file mode 100644 index 00000000000..d8f8367fbf4 --- /dev/null +++ b/markdown/dev/reference/api/hooks/prepartdraft/en.md @@ -0,0 +1,27 @@ +--- +title: prePartDraft +--- + +The `prePartDraft` lifecycle hook runs just before a part is drafted. +It will fire once for each part in each set (of settings). + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('prePartDraft', pattern => { + // Mutate the pattern object here + // You can use the pattern.activePart + // and pattern.activeSet properties to + // figure out for which part this hook was fired +} +``` + +## Notes + +The `prePartDraft` hook is rarely used, but it's there if you need it. diff --git a/markdown/dev/reference/api/hooks/prerender/en.md b/markdown/dev/reference/api/hooks/prerender/en.md index 656ed8b9dad..0f11ea85576 100644 --- a/markdown/dev/reference/api/hooks/prerender/en.md +++ b/markdown/dev/reference/api/hooks/prerender/en.md @@ -2,8 +2,19 @@ title: preRender --- -The `preRender` hook is triggered just before your pattern is rendered to SVG. +The `preRender` lifecycle hook is triggered just before your pattern is +rendered to SVG. -Your hook method will receive [the SVG object](/api/svg) as its first parameter. +## Signature -It is typically used to change the result of the render, for example by adding CSS to the SVG output. +```js +null hook(Svg svg) +``` + +## Notes + +The `preRender` hook is typically used to change the result of the render, for +example by adding CSS to the SVG output. + +Like the `postRender` hook, it receives [the SVG object](/api/svg) as its first +parameter. diff --git a/markdown/dev/reference/api/hooks/presample/en.md b/markdown/dev/reference/api/hooks/presample/en.md index 20806820400..7fac1cabf14 100644 --- a/markdown/dev/reference/api/hooks/presample/en.md +++ b/markdown/dev/reference/api/hooks/presample/en.md @@ -4,16 +4,27 @@ title: preSample The `preSample` hook runs just before your pattern is sampled. -It is triggered at the very start of either: +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('preSample', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `preSample` hook is rarely used, but it's there if you need it. + +It is triggered just before the start of either: - the [Pattern.sampleOption()](/reference/api/pattern/sampleoption) method - the [Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement) method - the [Pattern.sampleModels()](/reference/api/pattern/samplemodels) method -Your plugin will receive the Pattern object. - - - -The `preSample` hook is rarely used. - - diff --git a/markdown/dev/reference/api/hooks/presetdraft/en.md b/markdown/dev/reference/api/hooks/presetdraft/en.md new file mode 100644 index 00000000000..0c805941c06 --- /dev/null +++ b/markdown/dev/reference/api/hooks/presetdraft/en.md @@ -0,0 +1,24 @@ +--- +title: preSetDraft +--- + +The `preSetDraft` lifecycle hook runs just before a set (of settings) is +drafted. It will fire once for each set when calling `Pattern.draft()`. + +## Signature + +```js +null hook(Pattern pattern) +``` + +## Example + +```js +pattern.on('preSetDraft', pattern => { + // Mutate the pattern object here +} +``` + +## Notes + +The `preSetDraft` hook is rarely used, but it's there if you need it.