MCPcopy
hub / github.com/GrapesJS/grapesjs / constructor

Method constructor

packages/core/src/commands/index.ts:145–256  ·  view source on GitHub ↗

* @private

(em: Editor)

Source from the content-addressed store, hash-verified

143 * @private
144 */
145 constructor(em: Editor) {
146 super(em, 'Commands', defConfig());
147 const { config } = this;
148 const ppfx = config.pStylePrefix;
149 const { defaultCommands } = this;
150
151 if (ppfx) {
152 config.stylePrefix = ppfx + config.stylePrefix;
153 }
154
155 // Load commands passed via configuration
156 Object.keys(config.defaults!).forEach((k) => {
157 const obj = config.defaults![k];
158 if (obj.id) this.add(obj.id, obj as CommandDefinitionById<typeof obj.id>);
159 });
160
161 defaultCommands['tlb-delete'] = {
162 run(ed) {
163 return ed.runCommand('core:component-delete');
164 },
165 };
166
167 defaultCommands['tlb-clone'] = {
168 run(ed) {
169 ed.runCommand('core:copy');
170 ed.runCommand('core:paste', { action: 'clone-component' });
171 },
172 };
173
174 defaultCommands['tlb-move'] = {
175 run(ed, s, opts = {}) {
176 let dragger;
177 const em = ed.getModel();
178 const { event } = opts;
179 const trg = opts.target as Component | undefined;
180 const trgs = Array.isArray(trg) ? trg : trg ? [trg] : [...ed.getSelectedAll()];
181 const targets = trgs.map((trg) => trg.delegate?.move?.(trg) || trg).filter(Boolean);
182 const target = targets[targets.length - 1] as Component | undefined;
183 const nativeDrag = event?.type === 'dragstart';
184 const modes = ['absolute', 'translate'];
185
186 if (!target?.get('draggable')) {
187 return em.logWarning('The element is not draggable');
188 }
189
190 const mode = opts.mode || target.get('dmode') || em.get('dmode');
191 const hideTlb = () => em.stopDefault(defComOptions);
192 const altMode = includes(modes, mode);
193 targets.forEach((trg) => trg.trigger('disable', { fromMove: true }));
194
195 // Without setTimeout the ghost image disappears
196 nativeDrag ? setTimeout(hideTlb, 0) : hideTlb();
197
198 const onStart = getOnComponentDragStart(em);
199 const onDrag = getOnComponentDrag(em);
200 const onEnd = getOnComponentDragEnd(em, targets, { altMode });
201
202 if (altMode) {

Callers

nothing calls this directly

Calls 5

addMethod · 0.95
undoMethod · 0.80
redoMethod · 0.80
onMethod · 0.45
triggerMethod · 0.45

Tested by

no test coverage detected