chore: Updating hooks docs for v3
This commit is contained in:
parent
098d23c3b7
commit
2c12227ea8
14 changed files with 288 additions and 47 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
<Note>
|
||||
```js
|
||||
null hook(Pattern pattern)
|
||||
```
|
||||
|
||||
The `postDraft` hook is rarely used.
|
||||
## Example
|
||||
|
||||
</Note>
|
||||
```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.
|
||||
|
|
23
markdown/dev/reference/api/hooks/postinit/en.md
Normal file
23
markdown/dev/reference/api/hooks/postinit/en.md
Normal file
|
@ -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.
|
24
markdown/dev/reference/api/hooks/postlayout/en.md
Normal file
24
markdown/dev/reference/api/hooks/postlayout/en.md
Normal file
|
@ -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.
|
27
markdown/dev/reference/api/hooks/postpartdraft/en.md
Normal file
27
markdown/dev/reference/api/hooks/postpartdraft/en.md
Normal file
|
@ -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.
|
|
@ -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
|
||||
|
||||
<Note>
|
||||
```js
|
||||
null hook(Svg svg)
|
||||
```
|
||||
|
||||
The `postRender` hooks is rarely used.
|
||||
## Notes
|
||||
|
||||
</Note>
|
||||
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.
|
||||
|
|
|
@ -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
|
||||
|
||||
<Note>
|
||||
|
||||
The `postSample` hook is rarely used.
|
||||
|
||||
</Note>
|
||||
|
|
24
markdown/dev/reference/api/hooks/postsetdraft/en.md
Normal file
24
markdown/dev/reference/api/hooks/postsetdraft/en.md
Normal file
|
@ -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.
|
|
@ -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
|
||||
|
||||
<Note>
|
||||
```js
|
||||
null hook(Pattern pattern)
|
||||
```
|
||||
|
||||
The `preDraft` hook is rarely used.
|
||||
## Example
|
||||
|
||||
</Note>
|
||||
```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.
|
||||
|
|
23
markdown/dev/reference/api/hooks/preinit/en.md
Normal file
23
markdown/dev/reference/api/hooks/preinit/en.md
Normal file
|
@ -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.
|
27
markdown/dev/reference/api/hooks/prepartdraft/en.md
Normal file
27
markdown/dev/reference/api/hooks/prepartdraft/en.md
Normal file
|
@ -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.
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
||||
<Note>
|
||||
|
||||
The `preSample` hook is rarely used.
|
||||
|
||||
</Note>
|
||||
|
|
24
markdown/dev/reference/api/hooks/presetdraft/en.md
Normal file
24
markdown/dev/reference/api/hooks/presetdraft/en.md
Normal file
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue