mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 23:02:55 +01:00
Compare commits
5 Commits
fix/close-
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4ef346d25 | ||
|
|
6205d08451 | ||
|
|
14786b2144 | ||
|
|
e25155556f | ||
|
|
016837f466 |
@@ -8,6 +8,7 @@ import { ipcRenderer } from 'electron';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { platform } from '@noodl/platform';
|
||||
|
||||
import { Keybindings } from '@noodl-constants/Keybindings';
|
||||
import { App } from '@noodl-models/app';
|
||||
import { AppRegistry } from '@noodl-models/app_registry';
|
||||
import { CloudService } from '@noodl-models/CloudServices';
|
||||
@@ -156,7 +157,7 @@ export function EditorPage({ route }: EditorPageProps) {
|
||||
useKeyboardCommands(() => [
|
||||
{
|
||||
handler: () => SidebarModel.instance.switch('search'),
|
||||
keybinding: KeyMod.CtrlCmd | KeyCode.KEY_F
|
||||
keybinding: Keybindings.SEARCH.hash
|
||||
},
|
||||
{
|
||||
handler: () => EventDispatcher.instance.emit('viewer-open-devtools'),
|
||||
|
||||
@@ -5,9 +5,9 @@ import { useSidePanelKeyboardCommands } from '@noodl-hooks/useKeyboardCommands';
|
||||
import classNames from 'classnames';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { Keybindings } from '@noodl-constants/Keybindings';
|
||||
import { ComponentModel } from '@noodl-models/componentmodel';
|
||||
import { NodeGraphNode } from '@noodl-models/nodegraphmodel';
|
||||
import { KeyCode, KeyMod } from '@noodl-utils/keyboard/KeyCode';
|
||||
import { performSearch } from '@noodl-utils/universal-search';
|
||||
|
||||
import { SearchInput } from '@noodl-core-ui/components/inputs/SearchInput';
|
||||
@@ -40,7 +40,7 @@ export function SearchPanel() {
|
||||
inputRef.current.focus();
|
||||
inputRef.current.select();
|
||||
},
|
||||
keybinding: KeyMod.CtrlCmd | KeyCode.KEY_F
|
||||
keybinding: Keybindings.SEARCH.hash
|
||||
}
|
||||
],
|
||||
'search'
|
||||
|
||||
@@ -263,7 +263,9 @@ class CloudStore {
|
||||
* @param {{
|
||||
* objectId: string;
|
||||
* collection: string;
|
||||
* keys?: string[] | string;
|
||||
* include?: string[] | string;
|
||||
* excludeKeys?: string[] | string;
|
||||
* success: (data: unknown) => void;
|
||||
* error: (error: unknown) => void;
|
||||
* }} options
|
||||
@@ -275,6 +277,16 @@ class CloudStore {
|
||||
args.push('include=' + (Array.isArray(options.include) ? options.include.join(',') : options.include));
|
||||
}
|
||||
|
||||
if (options.keys) {
|
||||
args.push('keys=' + (Array.isArray(options.keys) ? options.keys.join(',') : options.keys));
|
||||
}
|
||||
|
||||
if (options.excludeKeys) {
|
||||
args.push(
|
||||
'excludeKeys=' + (Array.isArray(options.excludeKeys) ? options.excludeKeys.join(',') : options.excludeKeys)
|
||||
);
|
||||
}
|
||||
|
||||
this._makeRequest(
|
||||
'/classes/' + options.collection + '/' + options.objectId + (args.length > 0 ? '?' + args.join('&') : ''),
|
||||
{
|
||||
|
||||
@@ -112,7 +112,9 @@ function createRecordsAPI(modelScope) {
|
||||
* @param {string | { getId(): string; }} objectOrId
|
||||
* @param {{
|
||||
* className: string;
|
||||
* keys?: string[] | string;
|
||||
* include?: string[] | string;
|
||||
* excludeKeys?: string[] | string;
|
||||
* }} options
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
@@ -129,7 +131,9 @@ function createRecordsAPI(modelScope) {
|
||||
cloudstore().fetch({
|
||||
collection: className,
|
||||
objectId: objectOrId,
|
||||
include: options ? options.include : undefined,
|
||||
keys: options?.keys,
|
||||
include: options?.include,
|
||||
excludeKeys: options?.excludeKeys,
|
||||
success: function (response) {
|
||||
const record = cloudstore()._fromJSON(response, className);
|
||||
resolve(record);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Model = require("./model");
|
||||
var Model = require('./model');
|
||||
|
||||
// Get and set proxy
|
||||
/*const proxies = {}
|
||||
@@ -221,48 +221,48 @@ Collection.prototype.toJSON = function() {
|
||||
}*/
|
||||
|
||||
// ----
|
||||
Object.defineProperty(Array.prototype, "items", {
|
||||
Object.defineProperty(Array.prototype, 'items', {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this;
|
||||
},
|
||||
set(data) {
|
||||
this.set(data);
|
||||
},
|
||||
}
|
||||
});
|
||||
Object.defineProperty(Array.prototype, "each", {
|
||||
Object.defineProperty(Array.prototype, 'each', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: Array.prototype.forEach,
|
||||
value: Array.prototype.forEach
|
||||
});
|
||||
Object.defineProperty(Array.prototype, "size", {
|
||||
Object.defineProperty(Array.prototype, 'size', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function () {
|
||||
return this.length;
|
||||
},
|
||||
}
|
||||
});
|
||||
Object.defineProperty(Array.prototype, "get", {
|
||||
Object.defineProperty(Array.prototype, 'get', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function (index) {
|
||||
return this[index];
|
||||
},
|
||||
}
|
||||
});
|
||||
Object.defineProperty(Array.prototype, "getId", {
|
||||
Object.defineProperty(Array.prototype, 'getId', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function () {
|
||||
return this._id;
|
||||
},
|
||||
}
|
||||
});
|
||||
Object.defineProperty(Array.prototype, "id", {
|
||||
Object.defineProperty(Array.prototype, 'id', {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this.getId();
|
||||
},
|
||||
}
|
||||
});
|
||||
Object.defineProperty(Array.prototype, "set", {
|
||||
Object.defineProperty(Array.prototype, 'set', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function (src) {
|
||||
@@ -323,10 +323,10 @@ Object.defineProperty(Array.prototype, "set", {
|
||||
for (i = aItems.length; i < bItems.length; i++) {
|
||||
this.add(bItems[i]);
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "notify", {
|
||||
Object.defineProperty(Array.prototype, 'notify', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: async function (event, args) {
|
||||
@@ -337,80 +337,80 @@ Object.defineProperty(Array.prototype, "notify", {
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
await l[i](args);
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "contains", {
|
||||
Object.defineProperty(Array.prototype, 'contains', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function (item) {
|
||||
return this.indexOf(item) !== -1;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "add", {
|
||||
Object.defineProperty(Array.prototype, 'add', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: async function (item) {
|
||||
if (this.contains(item)) return; // Already contains item
|
||||
|
||||
this.items.push(item);
|
||||
await this.notify("add", { item: item, index: this.items.length - 1 });
|
||||
await this.notify("change");
|
||||
await item.notify("add", { collection: this });
|
||||
},
|
||||
await this.notify('add', { item: item, index: this.items.length - 1 });
|
||||
await this.notify('change');
|
||||
await item.notify('add', { collection: this });
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "remove", {
|
||||
Object.defineProperty(Array.prototype, 'remove', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function (item) {
|
||||
var idx = this.items.indexOf(item);
|
||||
if (idx !== -1) this.removeAtIndex(idx);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "addAtIndex", {
|
||||
Object.defineProperty(Array.prototype, 'addAtIndex', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: async function (item, index) {
|
||||
if (this.contains(item)) return; // Already contains item
|
||||
|
||||
this.items.splice(index, 0, item);
|
||||
await this.notify("add", { item: item, index: index });
|
||||
await this.notify("change");
|
||||
await item.notify("add", { collection: this, index: index });
|
||||
},
|
||||
await this.notify('add', { item: item, index: index });
|
||||
await this.notify('change');
|
||||
await item.notify('add', { collection: this, index: index });
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "removeAtIndex", {
|
||||
Object.defineProperty(Array.prototype, 'removeAtIndex', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: async function (idx) {
|
||||
var item = this.items[idx];
|
||||
this.items.splice(idx, 1);
|
||||
await this.notify("remove", { item: item, index: idx });
|
||||
await this.notify("change");
|
||||
await item.notify("remove", { collection: this });
|
||||
},
|
||||
await this.notify('remove', { item: item, index: idx });
|
||||
await this.notify('change');
|
||||
await item.notify('remove', { collection: this });
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "on", {
|
||||
Object.defineProperty(Array.prototype, 'on', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function (event, listener) {
|
||||
if (!this._listeners)
|
||||
Object.defineProperty(this, "_listeners", {
|
||||
Object.defineProperty(this, '_listeners', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: {},
|
||||
value: {}
|
||||
});
|
||||
if (!this._listeners[event]) this._listeners[event] = [];
|
||||
this._listeners[event].push(listener);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Array.prototype, "off", {
|
||||
Object.defineProperty(Array.prototype, 'off', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function (event, listener) {
|
||||
@@ -418,20 +418,20 @@ Object.defineProperty(Array.prototype, "off", {
|
||||
if (!this._listeners[event]) return;
|
||||
var idx = this._listeners[event].indexOf(listener);
|
||||
if (idx !== -1) this._listeners[event].splice(idx, 1);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
class Collection extends Array {}
|
||||
|
||||
var collections = (Collection._collections = {});
|
||||
const collections = (Collection._collections = {});
|
||||
|
||||
Collection.create = function (items) {
|
||||
const name = Model.guid();
|
||||
collections[name] = new Collection();
|
||||
Object.defineProperty(collections[name], "_id", {
|
||||
Object.defineProperty(collections[name], '_id', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: name,
|
||||
value: name
|
||||
});
|
||||
if (items) {
|
||||
collections[name].set(items);
|
||||
@@ -439,14 +439,18 @@ Collection.create = function (items) {
|
||||
return collections[name];
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {Collection}
|
||||
*/
|
||||
Collection.get = function (name) {
|
||||
if (name === undefined) name = Model.guid();
|
||||
if (!collections[name]) {
|
||||
collections[name] = new Collection();
|
||||
Object.defineProperty(collections[name], "_id", {
|
||||
Object.defineProperty(collections[name], '_id', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: name,
|
||||
value: name
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ const _modelProxyHandler = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} id
|
||||
* @returns {Model}
|
||||
*/
|
||||
Model.get = function (id) {
|
||||
if (id === undefined) id = Model.guid();
|
||||
if (!models[id]) {
|
||||
@@ -122,13 +127,22 @@ Model.prototype.fill = function (value = null) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {unknown} value
|
||||
* @param {{
|
||||
* resolve?: boolean;
|
||||
* forceChange?: boolean;
|
||||
* silent?: boolean;
|
||||
* }} args
|
||||
*/
|
||||
Model.prototype.set = function (name, value, args) {
|
||||
if (args && args.resolve && name.indexOf('.') !== -1) {
|
||||
// We should resolve path references
|
||||
var path = name.split('.');
|
||||
var model = this;
|
||||
for (var i = 0; i < path.length - 1; i++) {
|
||||
var v = model.get(path[i]);
|
||||
const path = name.split('.');
|
||||
let model = this;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
const v = model.get(path[i]);
|
||||
if (Model.instanceOf(v)) model = v;
|
||||
else return; // Path resolve failed
|
||||
}
|
||||
@@ -138,24 +152,35 @@ Model.prototype.set = function (name, value, args) {
|
||||
|
||||
const forceChange = args && args.forceChange;
|
||||
|
||||
var oldValue = this.data[name];
|
||||
const oldValue = this.data[name];
|
||||
this.data[name] = value;
|
||||
(forceChange || oldValue !== value) &&
|
||||
(!args || !args.silent) &&
|
||||
|
||||
if ((forceChange || oldValue !== value) && (!args || !args.silent)) {
|
||||
this.notify('change', { name: name, value: value, old: oldValue });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
Model.prototype.getId = function () {
|
||||
return this.id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {{
|
||||
* resolve?: boolean;
|
||||
* }} args
|
||||
* @returns {unknown}
|
||||
*/
|
||||
Model.prototype.get = function (name, args) {
|
||||
if (args && args.resolve && name.indexOf('.') !== -1) {
|
||||
// We should resolve path references
|
||||
var path = name.split('.');
|
||||
var model = this;
|
||||
for (var i = 0; i < path.length - 1; i++) {
|
||||
var v = model.get(path[i]);
|
||||
const path = name.split('.');
|
||||
let model = this;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
const v = model.get(path[i]);
|
||||
if (Model.instanceOf(v)) model = v;
|
||||
else return; // Path resolve failed
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ NodeContext.prototype.deregisterComponentModel = function (componentModel) {
|
||||
|
||||
NodeContext.prototype.fetchComponentBundle = async function (name) {
|
||||
const fetchBundle = async (name) => {
|
||||
let baseUrl = Noodl.Env["BaseUrl"] || '/';
|
||||
let baseUrl = Noodl.Env['BaseUrl'] || '/';
|
||||
let bundleUrl = `${baseUrl}noodl_bundles/${name}.json`;
|
||||
|
||||
const response = await fetch(bundleUrl);
|
||||
@@ -455,6 +455,15 @@ NodeContext.prototype.setPopupCallbacks = function ({ onShow, onClose }) {
|
||||
this.onClosePopup = onClose;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} popupComponent
|
||||
* @param {Record<string, unknown>} params
|
||||
* @param {{
|
||||
* senderNode?: unknown;
|
||||
* onClosePopup?: (action?: string, results: object) => void;
|
||||
* }} args
|
||||
* @returns
|
||||
*/
|
||||
NodeContext.prototype.showPopup = async function (popupComponent, params, args) {
|
||||
if (!this.onShowPopup) return;
|
||||
|
||||
|
||||
@@ -227,6 +227,9 @@ declare namespace Noodl {
|
||||
objectOrId: string | { getId(): string; },
|
||||
options?: {
|
||||
className?: RecordClassName;
|
||||
keys?: string[] | string;
|
||||
include?: string[] | string;
|
||||
excludeKeys?: string[] | string;
|
||||
}
|
||||
): Promise<any>;
|
||||
|
||||
|
||||
@@ -2,17 +2,18 @@ const { RouterHandler } = require('../nodes/navigation/router-handler');
|
||||
const NoodlRuntime = require('@noodl/runtime');
|
||||
|
||||
const navigation = {
|
||||
/**
|
||||
* This is set by "packages/noodl-viewer-react/src/noodl-js-api.js"
|
||||
* @type {NoodlRuntime}
|
||||
*/
|
||||
_noodlRuntime: undefined,
|
||||
|
||||
async showPopup(componentPath, params) {
|
||||
return new Promise((resolve) => {
|
||||
navigation._noodlRuntime.context.showPopup(componentPath, params, {
|
||||
senderNode: this.nodeScope.componentOwner,
|
||||
/**
|
||||
* @param {string | undefined} action
|
||||
* @param {*} results
|
||||
*/
|
||||
onClosePopup: (action, results) => {
|
||||
resolve({
|
||||
action: (action || '').replace('closeAction-', ''),
|
||||
action: action?.replace('closeAction-', ''),
|
||||
parameters: results
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ const ClosePopupNode = {
|
||||
this._internal.closeCallback = cb;
|
||||
},
|
||||
scheduleClose: function () {
|
||||
var _this = this;
|
||||
var internal = this._internal;
|
||||
const _this = this;
|
||||
const internal = this._internal;
|
||||
if (!internal.hasScheduledClose) {
|
||||
internal.hasScheduledClose = true;
|
||||
this.scheduleAfterInputsHaveUpdated(function () {
|
||||
@@ -113,9 +113,8 @@ module.exports = {
|
||||
var closeActions = node.parameters['closeActions'];
|
||||
if (closeActions) {
|
||||
closeActions = closeActions ? closeActions.split(',') : undefined;
|
||||
for (var i in closeActions) {
|
||||
var p = closeActions[i];
|
||||
|
||||
for (const i in closeActions) {
|
||||
const p = closeActions[i];
|
||||
ports.push({
|
||||
type: 'signal',
|
||||
plug: 'input',
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const { Node } = require('@noodl/runtime');
|
||||
|
||||
const Model = require('@noodl/runtime/src/model');
|
||||
const Collection = require('@noodl/runtime/src/collection');
|
||||
|
||||
var SetVariableNodeDefinition = {
|
||||
const SetVariableNodeDefinition = {
|
||||
name: 'Set Variable',
|
||||
docs: 'https://docs.noodl.net/nodes/data/variable/set-variable',
|
||||
category: 'Data',
|
||||
usePortAsLabel: 'name',
|
||||
color: 'data',
|
||||
initialize: function () {
|
||||
var internal = this._internal;
|
||||
|
||||
const internal = this._internal;
|
||||
internal.variablesModel = Model.get('--ndl--global-variables');
|
||||
},
|
||||
getInspectInfo() {
|
||||
if (this._internal.name) {
|
||||
return this._internal.variablesModel.get(this._internal.name);
|
||||
}
|
||||
|
||||
return '[No value set]';
|
||||
},
|
||||
outputs: {
|
||||
done: {
|
||||
type: 'signal',
|
||||
@@ -74,17 +78,22 @@ var SetVariableNodeDefinition = {
|
||||
if (this.hasScheduledStore) return;
|
||||
this.hasScheduledStore = true;
|
||||
|
||||
var internal = this._internal;
|
||||
const internal = this._internal;
|
||||
this.scheduleAfterInputsHaveUpdated(function () {
|
||||
this.hasScheduledStore = false;
|
||||
|
||||
var value = internal.setWith === 'emptyString' ? '' : internal.value;
|
||||
let value = internal.setWith === 'emptyString' ? '' : internal.value;
|
||||
|
||||
// Can set arrays with "id" or array
|
||||
if (internal.setWith === 'object' && typeof value === 'string') value = Model.get(value);
|
||||
|
||||
// Can set arrays with "id" or array
|
||||
if (internal.setWith === 'array' && typeof value === 'string') value = Collection.get(value);
|
||||
|
||||
if (internal.setWith === 'object' && typeof value === 'string') value = Model.get(value); // Can set arrays with "id" or array
|
||||
if (internal.setWith === 'array' && typeof value === 'string') value = Collection.get(value); // Can set arrays with "id" or array
|
||||
if (internal.setWith === 'boolean') value = !!value;
|
||||
|
||||
//use forceChange to always trigger Variable nodes to send the value on their output, even if it's the same value twice
|
||||
// use forceChange to always trigger Variable nodes to send the value on
|
||||
// their output, even if it's the same value twice
|
||||
internal.variablesModel.set(internal.name, value, {
|
||||
forceChange: true
|
||||
});
|
||||
@@ -96,10 +105,11 @@ var SetVariableNodeDefinition = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name === 'value')
|
||||
if (name === 'value') {
|
||||
this.registerInput(name, {
|
||||
set: this.setValue.bind(this)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -274,6 +274,9 @@ declare namespace Noodl {
|
||||
objectOrId: string | { getId(): string; },
|
||||
options?: {
|
||||
className?: RecordClassName;
|
||||
keys?: string[] | string;
|
||||
include?: string[] | string;
|
||||
excludeKeys?: string[] | string;
|
||||
}
|
||||
): Promise<any>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user