feat(core): Better support for macro removal an node id tracking
This commit is contained in:
parent
7939c1bc45
commit
cb106578b3
24 changed files with 327 additions and 223 deletions
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the bannner macro
|
||||
*/
|
||||
|
@ -15,12 +13,8 @@ const macroDefaults = {
|
|||
/*
|
||||
* The rmbanner macro
|
||||
*/
|
||||
const rmbanner = function (id = macroDefaults.id, { paths, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'banner', 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
}
|
||||
const rmbanner = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'banner', part)
|
||||
|
||||
const banner = function (config, { part, paths, store, complete }) {
|
||||
/*
|
||||
|
@ -36,7 +30,7 @@ const banner = function (config, { part, paths, store, complete }) {
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['banner'], mc.id, 'banner')
|
||||
const ids = store.generateMacroIds(['banner'], mc.id)
|
||||
|
||||
/*
|
||||
* Prepare the path to hold the banner text
|
||||
|
@ -57,9 +51,12 @@ const banner = function (config, { part, paths, store, complete }) {
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmbanner
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'banner', 'ids', mc.id, 'paths'], ids)
|
||||
store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return store.getMacroIds(config.id, 'banner')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the bannerbox macro
|
||||
*/
|
||||
|
@ -20,12 +18,9 @@ const macroDefaults = {
|
|||
* Removing all this is easy as all IDs are available in the store
|
||||
* and all we need to remove are paths.
|
||||
*/
|
||||
const rmbannerbox = function (id = macroDefaults.id, { paths, store, part, macro }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'bannerbox', 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
const rmbannerbox = (id = macroDefaults.id, { macro, store, part }) => {
|
||||
macro('rmbanner', id)
|
||||
return store.removeMacroNodes(id, 'bannerbox', part)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,7 +59,7 @@ const bannerbox = function (config, { Point, paths, Path, part, macro, log, stor
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['box'], mc.id, 'bannerbox')
|
||||
const ids = store.generateMacroIds(['box'], mc.id)
|
||||
|
||||
/*
|
||||
* Calculate the offset from the bounding box
|
||||
|
@ -99,9 +94,12 @@ const bannerbox = function (config, { Point, paths, Path, part, macro, log, stor
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmtitle
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'bannerbox', 'ids', mc.id, 'paths'], ids)
|
||||
store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return store.getMacroIds(mc.id, 'bannerbox')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
export const bannerboxMacros = { bannerbox, rmbannerbox }
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the bartack macro
|
||||
*/
|
||||
|
@ -122,26 +120,25 @@ function createBartack(config, props) {
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['stitches'], mc.id, name)
|
||||
const ids = props.store.generateMacroIds(['stitches'], mc.id)
|
||||
paths[ids.stitches] = bartackPath(guide, mc, props).attr('class', mc.classes)
|
||||
|
||||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rm[name]
|
||||
*/
|
||||
props.store.set(['parts', props.part.name, 'macros', name, 'ids', mc.id, 'paths'], ids)
|
||||
props.store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return props.store.getMacroIds(mc.id, name)
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return props.store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
/*
|
||||
* The method that will remove all macros
|
||||
*/
|
||||
const removeBartack = function (name = 'bartack', id = macroDefaults.id, { paths, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', name, 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
}
|
||||
const removeBartack = (name = 'bartack', id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, name, part)
|
||||
|
||||
/*
|
||||
* The rmbartackalong and rmbartackfractionalong macros just call rmbartack with the correct name
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the title macro
|
||||
*/
|
||||
|
@ -17,14 +15,8 @@ const macroDefaults = {
|
|||
/*
|
||||
* The rmcrossbox macro
|
||||
*/
|
||||
const rmcrossbox = function (id = macroDefaults.id, { paths, points, store, part }) {
|
||||
const both = store.get(['parts', part.name, 'macros', 'title', 'ids', id], {
|
||||
paths: {},
|
||||
points: {},
|
||||
})
|
||||
for (const pid of Object.values(both.points)) delete points[pid]
|
||||
for (const pid of Object.values(both.paths)) delete paths[pid]
|
||||
}
|
||||
const rmcrossbox = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'crossbox', part)
|
||||
|
||||
/*
|
||||
* The crossbox macro
|
||||
|
@ -62,7 +54,7 @@ const crossbox = function (config, { points, Point, paths, Path, complete, store
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const flatIds = getIds(['box', 'cross', 'text'], mc.id, 'crossbox')
|
||||
const flatIds = store.generateMacroIds(['box', 'cross', 'text'], mc.id)
|
||||
const ids = {
|
||||
paths: {
|
||||
box: flatIds.box,
|
||||
|
@ -118,9 +110,12 @@ const crossbox = function (config, { points, Point, paths, Path, complete, store
|
|||
* Store all IDs in the store so we can remove this macro with rmtitle
|
||||
* Just make sure to keep points and paths apart
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'title', 'ids', mc.id], ids)
|
||||
store.storeMacroIds(mc.id, ids)
|
||||
|
||||
return store.getMacroIds(mc.id, 'crossbox')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the cutonfold macro
|
||||
*/
|
||||
|
@ -36,12 +34,8 @@ export const cutonfoldDefs = [
|
|||
/*
|
||||
* The rmcutonfold macro
|
||||
*/
|
||||
const rmcutonfold = function (id = macroDefaults.id, { paths, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'cutonfold', 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
}
|
||||
const rmcutonfold = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'cutonfold', part)
|
||||
|
||||
/*
|
||||
* The cutonfold macro
|
||||
|
@ -86,7 +80,7 @@ const cutonfold = function (config, { paths, Path, complete, store, scale, log,
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['line'], mc.id, 'cutonfold')
|
||||
const ids = store.generateMacroIds(['line'], mc.id)
|
||||
|
||||
/*
|
||||
* Draw the path
|
||||
|
@ -106,9 +100,12 @@ const cutonfold = function (config, { paths, Path, complete, store, scale, log,
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmcutonfold
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'cutonfold', 'ids', mc.id, 'paths'], ids)
|
||||
store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return store.getMacroIds(mc.id, 'cutonfold')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
// Export defs
|
||||
export const dimensionsDefs = [
|
||||
{
|
||||
|
@ -122,7 +120,7 @@ const addDimension = (config, props, type) => {
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['line', 'from', 'to'], mc.id, type)
|
||||
const ids = props.store.generateMacroIds(['line', 'from', 'to'], mc.id)
|
||||
|
||||
/*
|
||||
* Draw the dimension
|
||||
|
@ -150,28 +148,28 @@ const addDimension = (config, props, type) => {
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rm variants
|
||||
*/
|
||||
props.store.set(['parts', props.part.name, 'macros', type, 'ids', mc.id, 'paths'], ids)
|
||||
props.store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return props.store.getMacroIds(mc.id, type)
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return props.store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
/*
|
||||
* This method handles the 'remove' part for all macros
|
||||
*/
|
||||
const removeDimension = function (id = macroDefaults.id, { paths, store, part }, type) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', type, 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
const removeDimension = function (id = macroDefaults.id, { store, part }, type) {
|
||||
return store.removeMacroNodes(id, type, part)
|
||||
}
|
||||
|
||||
/*
|
||||
* This method removes all dimensions of a given type
|
||||
*/
|
||||
const removeDimensionType = function ({ paths, store, part }, type) {
|
||||
for (const ids of Object.values(store.get(['parts', part.name, 'macros', type, 'ids'], {}))) {
|
||||
for (const pid of Object.values(ids.paths)) delete paths[pid]
|
||||
}
|
||||
// Get all macro IDs of the given type
|
||||
const ids = store.get(['parts', part.name, 'macros', type, 'ids'], {})
|
||||
for (const id in ids) store.removeMacroNodes(id, type, part)
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the grainline macro
|
||||
*/
|
||||
|
@ -34,12 +32,8 @@ export const grainlineDefs = [
|
|||
/*
|
||||
* The rmgrainline macro
|
||||
*/
|
||||
const rmgrainline = function (id = macroDefaults.id, { paths, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'grainline', 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
}
|
||||
const rmgrainline = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'grainline', part)
|
||||
|
||||
/*
|
||||
* The grainline macro
|
||||
|
@ -80,7 +74,7 @@ const grainline = function (config = {}, { paths, Path, Point, complete, store,
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['line'], mc.id, 'grainline')
|
||||
const ids = store.generateMacroIds(['line'], mc.id)
|
||||
|
||||
/*
|
||||
* Draw the path
|
||||
|
@ -98,9 +92,12 @@ const grainline = function (config = {}, { paths, Path, Point, complete, store,
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmgrainline
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'grainline', 'ids', mc.id, 'paths'], ids)
|
||||
store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return store.getMacroIds(mc.id, 'grainline')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -21,7 +21,6 @@ import { pleatMacros, pleatDefs } from './pleat.mjs'
|
|||
import { sewtogetherMacros, sewtogetherDefs } from './sewtogether.mjs'
|
||||
// Only stores
|
||||
import { flagStores } from './flag.mjs'
|
||||
import { utilsStores } from './utils.mjs'
|
||||
|
||||
export const plugin = {
|
||||
name,
|
||||
|
@ -62,7 +61,7 @@ export const plugin = {
|
|||
...sewtogetherMacros,
|
||||
...titleMacros,
|
||||
},
|
||||
store: [...cutlistStores, ...flagStores, ...utilsStores],
|
||||
store: [...cutlistStores, ...flagStores],
|
||||
}
|
||||
|
||||
export const annotationsPlugin = plugin
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the pleat macro
|
||||
*/
|
||||
|
@ -29,12 +27,8 @@ export const pleatDefs = [
|
|||
/*
|
||||
* The rmpleat macro
|
||||
*/
|
||||
const rmpleat = function (id = macroDefaults.id, { paths, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'pleat', 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
}
|
||||
const rmpleat = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'rmpleat', part)
|
||||
|
||||
/*
|
||||
* The pleat macro
|
||||
|
@ -71,7 +65,7 @@ const pleat = function (config, { paths, Path, log, Point, complete, scale, stor
|
|||
* Get the list of IDs
|
||||
* Initialize the verticle cadence
|
||||
*/
|
||||
const ids = getIds(['from', 'to', 'arrow'], mc.id, 'pleat')
|
||||
const ids = store.generateMacroIds(['from', 'to', 'arrow'], mc.id)
|
||||
|
||||
const toIn = mc.to.shift(mc.from.shiftTowards(mc.to, 0.1).angle(mc.to) + 90, mc.margin * scale)
|
||||
const fromIn = mc.from.shift(
|
||||
|
@ -109,9 +103,12 @@ const pleat = function (config, { paths, Path, log, Point, complete, scale, stor
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmpleat
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'pleat', 'ids', mc.id, 'paths'], ids)
|
||||
store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return store.getMacroIds(mc.id, 'pleat')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the title macro
|
||||
*/
|
||||
|
@ -65,9 +63,7 @@ const sizes = {
|
|||
*/
|
||||
const removeScaleAnnotation = function (id = false, { paths, points, store, part }, type) {
|
||||
if (!id) id = type
|
||||
const both = store.get(['parts', part.name, 'macros', type, 'ids', id], { paths: {}, points: {} })
|
||||
for (const pid of Object.values(both.points)) delete points[pid]
|
||||
for (const pid of Object.values(both.paths)) delete paths[pid]
|
||||
return store.removeMacroNodes(id, type, part)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -114,7 +110,7 @@ const scalebox = function (
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(
|
||||
const ids = store.generateMacroIds(
|
||||
[
|
||||
'metric',
|
||||
'imperial',
|
||||
|
@ -125,8 +121,7 @@ const scalebox = function (
|
|||
'textText',
|
||||
'textLink',
|
||||
],
|
||||
mc.id,
|
||||
'scalebox'
|
||||
mc.id
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -245,7 +240,7 @@ const scalebox = function (
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmscaleboc
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'scalebox', 'ids', mc.id], {
|
||||
store.storeMacroIds(mc.id, {
|
||||
points: {
|
||||
textLead: ids.textLead,
|
||||
textMetric: ids.textMetric,
|
||||
|
@ -260,7 +255,10 @@ const scalebox = function (
|
|||
},
|
||||
})
|
||||
|
||||
return store.getMacroIds(mc.id, 'scalebox')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -306,7 +304,7 @@ const miniscale = function (
|
|||
/*
|
||||
* Get the list of IDs
|
||||
*/
|
||||
const ids = getIds(['metric', 'imperial', 'textMetric', 'textImperial'], mc.id, 'miniscale')
|
||||
const ids = store.generateMacroIds(['metric', 'imperial', 'textMetric', 'textImperial'], mc.id)
|
||||
|
||||
/*
|
||||
* Box points (no need to add these to the part)
|
||||
|
@ -384,7 +382,7 @@ const miniscale = function (
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmscaleboc
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'miniscale', 'ids', mc.id], {
|
||||
store.storeMacroIds(mc.id, {
|
||||
points: {
|
||||
textMetric: ids.textMetric,
|
||||
textImperial: ids.textImperial,
|
||||
|
@ -394,6 +392,11 @@ const miniscale = function (
|
|||
imperial: ids.imperial,
|
||||
},
|
||||
})
|
||||
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the sewtogether macro
|
||||
*/
|
||||
|
@ -42,12 +40,8 @@ export const sewtogetherDefs = [
|
|||
/*
|
||||
* The rmsewtogether macro
|
||||
*/
|
||||
const rmsewtogether = function (id = macroDefaults.id, { paths, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'sewtogether', 'ids', id, 'paths'], {})
|
||||
))
|
||||
delete paths[pid]
|
||||
}
|
||||
const rmsewtogether = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'sewtogether', part)
|
||||
|
||||
/*
|
||||
* The sewtogether macro
|
||||
|
@ -89,7 +83,7 @@ const sewtogether = function (config, { paths, Path, log, Point, complete, sa, s
|
|||
* Get the list of IDs
|
||||
* Initialize the verticle cadence
|
||||
*/
|
||||
const ids = getIds(['curve', 'hinge'], mc.id, 'sewtogether')
|
||||
const ids = store.generateMacroIds(['curve', 'hinge'], mc.id)
|
||||
|
||||
/*
|
||||
* Draw the curve
|
||||
|
@ -124,9 +118,12 @@ const sewtogether = function (config, { paths, Path, log, Point, complete, sa, s
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmsewtogether
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'sewtogether', 'ids', mc.id, 'paths'], ids)
|
||||
store.storeMacroIds(mc.id, { paths: ids })
|
||||
|
||||
return store.getMacroIds(mc.id, 'sewtogether')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { getIds } from './utils.mjs'
|
||||
|
||||
/*
|
||||
* Defaults for the title macro
|
||||
*/
|
||||
|
@ -24,24 +22,10 @@ const macroDefaults = {
|
|||
},
|
||||
}
|
||||
|
||||
/*
|
||||
* Removing all this is easy as all IDs are available in the store
|
||||
* and all we need to remove are points.
|
||||
*/
|
||||
const removeTitleMacro = function (id = macroDefaults.id, { points, store, part }) {
|
||||
for (const pid of Object.values(
|
||||
store.get(['parts', part.name, 'macros', 'title', 'ids', id, 'points'], {})
|
||||
))
|
||||
delete points[pid]
|
||||
}
|
||||
|
||||
/*
|
||||
* The title macro
|
||||
*/
|
||||
const addTitleMacro = function (
|
||||
config,
|
||||
{ Point, points, scale, locale, store, part, log, complete }
|
||||
) {
|
||||
const title = function (config, { Point, points, scale, locale, store, part, log, complete }) {
|
||||
/*
|
||||
* Don't add a title when complete is false, unless force is true
|
||||
*/
|
||||
|
@ -92,7 +76,7 @@ const addTitleMacro = function (
|
|||
* Get the list of IDs
|
||||
* Initialize the verticle cadence
|
||||
*/
|
||||
const ids = getIds(['cutlist', 'date', 'for', 'name', 'nr', 'title'], mc.id, 'title')
|
||||
const ids = store.generateMacroIds(['cutlist', 'date', 'for', 'name', 'nr', 'title'], mc.id)
|
||||
|
||||
let shift = mc.dy
|
||||
|
||||
|
@ -229,13 +213,16 @@ const addTitleMacro = function (
|
|||
/*
|
||||
* Store all IDs in the store so we can remove this macro with rmtitle
|
||||
*/
|
||||
store.set(['parts', part.name, 'macros', 'title', 'ids', mc.id, 'points'], ids)
|
||||
store.storeMacroIds(mc.id, { points: ids })
|
||||
|
||||
return store.getMacroIds(mc.id, 'title')
|
||||
/*
|
||||
* Returning ids is a best practice for FreeSewing macros
|
||||
*/
|
||||
return store.getMacroIds(mc.id)
|
||||
}
|
||||
|
||||
// Export macros
|
||||
export const titleMacros = {
|
||||
title: addTitleMacro,
|
||||
rmtitle: removeTitleMacro,
|
||||
title,
|
||||
rmtitle: (id = macroDefaults.id, { store, part }) => store.removeMacroNodes(id, 'title', part),
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Helper method to get the various IDs for a macro
|
||||
*/
|
||||
export const getIds = (keys, id, macroName) => {
|
||||
const ids = {}
|
||||
for (const key of keys) ids[key] = `__macro_${macroName}_${id}_${key}`
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper method to get an existing macro id
|
||||
*/
|
||||
const getIdsFromStore = (store, id, macroName, partName = false) => {
|
||||
if (!partName) partName = store.activePart
|
||||
const data = store.get(['parts', partName, 'macros', macroName, 'ids', id])
|
||||
|
||||
return data ? data : false
|
||||
}
|
||||
|
||||
/*
|
||||
* Add these to the store
|
||||
*/
|
||||
export const utilsStores = [
|
||||
['createMacroIds', (store, keys, id, macroName) => getIds(keys, id, macroName)],
|
||||
['getMacroIds', getIdsFromStore],
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue