chore: Port FreeSewing.dev to docusaurus
The replaces the NextJS site powering FreeSewing.dev with a Docusaurus setup. It's part of my efforts to simplify FreeSewing's setup so we can focus on our core value proposition.
This commit is contained in:
parent
497633d1d3
commit
ab3204f9f1
692 changed files with 11037 additions and 20674 deletions
55
sites/dev/docs/reference/hooks/inserttext/readme.mdx
Normal file
55
sites/dev/docs/reference/hooks/inserttext/readme.mdx
Normal file
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
title: insertText
|
||||
---
|
||||
|
||||
The `insertText` lifecycle hook is called when text is about to be inserted
|
||||
during rendering.
|
||||
|
||||
It is typically used for translation, as is the case
|
||||
in [our i18n plugin](/reference/plugins/i18n/).
|
||||
|
||||
## 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 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
|
||||
.addText("seamAllowance")
|
||||
.addText(": 1 cm")
|
||||
```
|
||||
|
||||
For the example point above, the `insertText` hook will end up being called 3 times:
|
||||
|
||||
- First it will pass `seamAllowance` to the plugin
|
||||
- Then it will pass `: 1 cm` to the plugin
|
||||
- Finally it will pass `seamAllowance : 1 cm` to the plugin
|
||||
|
||||
Having the `insertText` hook only run once with `Seam allowance: 1 cm` would be problematic because
|
||||
the seam allowance may differ, or perhaps we're using imperial units, and so on.
|
||||
|
||||
Instead, you can (and should) divide your text into chunks that need translating, and chunks that do not.
|
||||
|
||||
This is also why we're not inserting **Seam allowance** but rather **seamAllowance**;
|
||||
It is merely a key to indicate what translation we want to replace this text with.
|
23
sites/dev/docs/reference/hooks/postdraft/readme.mdx
Normal file
23
sites/dev/docs/reference/hooks/postdraft/readme.mdx
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: postDraft
|
||||
---
|
||||
|
||||
The `postDraft` lifecycle hook runs just after your pattern is drafted.
|
||||
|
||||
## Signature
|
||||
|
||||
```js
|
||||
null hook(Pattern pattern)
|
||||
```
|
||||
|
||||
## 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.
|
23
sites/dev/docs/reference/hooks/postinit/readme.mdx
Normal file
23
sites/dev/docs/reference/hooks/postinit/readme.mdx
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
sites/dev/docs/reference/hooks/postlayout/readme.mdx
Normal file
24
sites/dev/docs/reference/hooks/postlayout/readme.mdx
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
sites/dev/docs/reference/hooks/postpartdraft/readme.mdx
Normal file
27
sites/dev/docs/reference/hooks/postpartdraft/readme.mdx
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.
|
19
sites/dev/docs/reference/hooks/postrender/readme.mdx
Normal file
19
sites/dev/docs/reference/hooks/postrender/readme.mdx
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
title: postRender
|
||||
---
|
||||
|
||||
The `postRender` lifecycle hook is triggered after the SVG is rendered.
|
||||
It will only fire when `Pattern.render()` is called.
|
||||
|
||||
## Signature
|
||||
|
||||
```js
|
||||
null hook(Svg svg)
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
The `postRender` hook is rarely used, but it's there if you need it.
|
||||
|
||||
Like the `preRender` hook, it receives [the SVG object](/reference/api/svg) as its first
|
||||
parameter.
|
30
sites/dev/docs/reference/hooks/postsample/readme.mdx
Normal file
30
sites/dev/docs/reference/hooks/postsample/readme.mdx
Normal file
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
title: postSample
|
||||
---
|
||||
|
||||
The `postSample` hook runs just after your pattern is sampled.
|
||||
|
||||
## 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:
|
||||
|
||||
- the [Pattern.sampleOption()](/reference/api/pattern/sampleoption) method
|
||||
- the [Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement) method
|
||||
- the [Pattern.sampleModels()](/reference/api/pattern/samplemodels) method
|
||||
|
24
sites/dev/docs/reference/hooks/postsetdraft/readme.mdx
Normal file
24
sites/dev/docs/reference/hooks/postsetdraft/readme.mdx
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.
|
26
sites/dev/docs/reference/hooks/predraft/readme.mdx
Normal file
26
sites/dev/docs/reference/hooks/predraft/readme.mdx
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: preDraft
|
||||
---
|
||||
|
||||
The `preDraft` lifecycle hook runs just before your pattern is drafted.
|
||||
|
||||
## Signature
|
||||
|
||||
```js
|
||||
null hook(Pattern pattern)
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
pattern.on('preDraft', pattern => {
|
||||
// Mutate the pattern object here
|
||||
}
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
The `preDraft` hook fires once for all the sets in the pattern.
|
||||
While typically, there is only one set, there might be more.
|
||||
In that case, the [`preSetDraft` lifecycle hook](/reference/hooks/presetdraft) is
|
||||
the per-set equivalent of this hook.
|
23
sites/dev/docs/reference/hooks/preinit/readme.mdx
Normal file
23
sites/dev/docs/reference/hooks/preinit/readme.mdx
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.
|
26
sites/dev/docs/reference/hooks/prelayout/readme.mdx
Normal file
26
sites/dev/docs/reference/hooks/prelayout/readme.mdx
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: preLayout
|
||||
---
|
||||
|
||||
The `preLayout` lifecycle hook runs just before the pattern layout is
|
||||
calculated.
|
||||
|
||||
This is a good place to do any business that might change the layout but relies on all the parts having been drafted
|
||||
|
||||
## Signature
|
||||
|
||||
```js
|
||||
null hook(Pattern pattern)
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
pattern.on('preLayout', pattern => {
|
||||
// Mutate the pattern object here
|
||||
}
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
The `postLayout` hook is rarely used, but it's there if you need it.
|
27
sites/dev/docs/reference/hooks/prepartdraft/readme.mdx
Normal file
27
sites/dev/docs/reference/hooks/prepartdraft/readme.mdx
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.
|
20
sites/dev/docs/reference/hooks/prerender/readme.mdx
Normal file
20
sites/dev/docs/reference/hooks/prerender/readme.mdx
Normal file
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
title: preRender
|
||||
---
|
||||
|
||||
The `preRender` lifecycle hook is triggered just before your pattern is
|
||||
rendered to SVG.
|
||||
|
||||
## Signature
|
||||
|
||||
```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](/reference/api/svg) as its first
|
||||
parameter.
|
30
sites/dev/docs/reference/hooks/presample/readme.mdx
Normal file
30
sites/dev/docs/reference/hooks/presample/readme.mdx
Normal file
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
title: preSample
|
||||
---
|
||||
|
||||
The `preSample` hook runs just before your pattern is sampled.
|
||||
|
||||
## 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
|
||||
|
35
sites/dev/docs/reference/hooks/presetdraft/readme.mdx
Normal file
35
sites/dev/docs/reference/hooks/presetdraft/readme.mdx
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
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` fires once for each set in the pattern.
|
||||
|
||||
The pattern tracks the active set on the `activeSet` property.
|
||||
So if you are using this hook and would like to get access to teh active set, you can do so like this:
|
||||
|
||||
```js
|
||||
pattern.on('preSetDraft', ({ settings, activeSet }) => {
|
||||
const set = settings[Number(activeSet)]
|
||||
|
||||
// Now set holds the active set of settings
|
||||
}
|
||||
```
|
19
sites/dev/docs/reference/hooks/readme.mdx
Normal file
19
sites/dev/docs/reference/hooks/readme.mdx
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
title: Lifecycle hooks
|
||||
---
|
||||
|
||||
FreeSewing has **lifecycle hooks** that allow you extend its functionality by
|
||||
hooking into a lifecycle event.
|
||||
|
||||
Through the [use of a plugin](/guides/plugins#hook-methods), you can register a method
|
||||
for a hook. When the hook is triggered, your method will be called. It will
|
||||
receive two parameters:
|
||||
|
||||
- An object relevant to the hook (see the specific hook for details)
|
||||
- Data passed when the hook was registered (optional)
|
||||
|
||||
Below is a list of all available lifecycle hooks:
|
||||
|
||||
<ReadMore />
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue